js-draw 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -6
- package/dist/bundle.js +1 -1
- package/dist/cjs/Editor.js +1 -1
- package/dist/cjs/Editor.loadFrom.test.d.ts +1 -0
- package/dist/cjs/Editor.test.d.ts +1 -0
- package/dist/cjs/Editor.toSVG.test.d.ts +1 -0
- package/dist/cjs/EditorImage.test.d.ts +1 -0
- package/dist/cjs/EventDispatcher.test.d.ts +1 -0
- package/dist/cjs/SVGLoader.test.d.ts +1 -0
- package/dist/cjs/UndoRedoHistory.test.d.ts +1 -0
- package/dist/cjs/commands/uniteCommands.test.d.ts +1 -0
- package/dist/cjs/components/AbstractComponent.transformBy.test.d.ts +1 -0
- package/dist/cjs/components/BackgroundComponent.test.d.ts +1 -0
- package/dist/cjs/components/Stroke.test.d.ts +1 -0
- package/dist/cjs/components/TextComponent.test.d.ts +1 -0
- package/dist/cjs/components/UnknownSVGObject.test.d.ts +1 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.test.d.ts +1 -0
- package/dist/cjs/localizations/getLocalizationTable.test.d.ts +1 -0
- package/dist/cjs/rendering/RenderingStyle.test.d.ts +1 -0
- package/dist/cjs/rendering/caching/CacheRecord.test.d.ts +1 -0
- package/dist/cjs/rendering/caching/RenderingCache.test.d.ts +1 -0
- package/dist/cjs/rendering/renderers/DummyRenderer.test.d.ts +1 -0
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.test.d.ts +1 -0
- package/dist/cjs/shortcuts/KeyBinding.test.d.ts +1 -0
- package/dist/cjs/shortcuts/KeyboardShortcutManager.test.d.ts +1 -0
- package/dist/cjs/toolbar/EdgeToolbar.test.d.ts +1 -0
- package/dist/cjs/tools/Eraser.test.d.ts +1 -0
- package/dist/cjs/tools/FindTool.test.d.ts +1 -0
- package/dist/cjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/cjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/cjs/tools/Pen.test.d.ts +1 -0
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/cjs/util/ReactiveValue.test.d.ts +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.test.d.ts +1 -0
- package/dist/mjs/Editor.loadFrom.test.d.ts +1 -0
- package/dist/mjs/Editor.mjs +1 -1
- package/dist/mjs/Editor.test.d.ts +1 -0
- package/dist/mjs/Editor.toSVG.test.d.ts +1 -0
- package/dist/mjs/EditorImage.test.d.ts +1 -0
- package/dist/mjs/EventDispatcher.test.d.ts +1 -0
- package/dist/mjs/SVGLoader.test.d.ts +1 -0
- package/dist/mjs/UndoRedoHistory.test.d.ts +1 -0
- package/dist/mjs/commands/uniteCommands.test.d.ts +1 -0
- package/dist/mjs/components/AbstractComponent.transformBy.test.d.ts +1 -0
- package/dist/mjs/components/BackgroundComponent.test.d.ts +1 -0
- package/dist/mjs/components/Stroke.test.d.ts +1 -0
- package/dist/mjs/components/TextComponent.test.d.ts +1 -0
- package/dist/mjs/components/UnknownSVGObject.test.d.ts +1 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.test.d.ts +1 -0
- package/dist/mjs/localizations/getLocalizationTable.test.d.ts +1 -0
- package/dist/mjs/rendering/RenderingStyle.test.d.ts +1 -0
- package/dist/mjs/rendering/caching/CacheRecord.test.d.ts +1 -0
- package/dist/mjs/rendering/caching/RenderingCache.test.d.ts +1 -0
- package/dist/mjs/rendering/renderers/DummyRenderer.test.d.ts +1 -0
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.test.d.ts +1 -0
- package/dist/mjs/shortcuts/KeyBinding.test.d.ts +1 -0
- package/dist/mjs/shortcuts/KeyboardShortcutManager.test.d.ts +1 -0
- package/dist/mjs/toolbar/EdgeToolbar.test.d.ts +1 -0
- package/dist/mjs/tools/Eraser.test.d.ts +1 -0
- package/dist/mjs/tools/FindTool.test.d.ts +1 -0
- package/dist/mjs/tools/InputFilter/InputPipeline.test.d.ts +1 -0
- package/dist/mjs/tools/PanZoom.test.d.ts +1 -0
- package/dist/mjs/tools/Pen.test.d.ts +1 -0
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +1 -0
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +1 -0
- package/dist/mjs/util/ReactiveValue.test.d.ts +1 -0
- package/dist/mjs/version.mjs +1 -1
- package/dist/mjs/version.test.d.ts +1 -0
- package/dist-test/test_imports/package-lock.json +13 -0
- package/dist-test/test_imports/package.json +12 -0
- package/dist-test/test_imports/test-imports.js +11 -0
- package/dist-test/test_imports/test-require.cjs +14 -0
- package/package.json +2 -2
- package/src/Editor.loadFrom.test.ts +24 -0
- package/src/Editor.test.ts +107 -0
- package/src/Editor.toSVG.test.ts +294 -0
- package/src/Editor.ts +1443 -0
- package/src/EditorImage.test.ts +117 -0
- package/src/EditorImage.ts +609 -0
- package/src/EventDispatcher.test.ts +123 -0
- package/src/EventDispatcher.ts +72 -0
- package/src/Pointer.ts +183 -0
- package/src/SVGLoader.test.ts +114 -0
- package/src/SVGLoader.ts +672 -0
- package/src/UndoRedoHistory.test.ts +34 -0
- package/src/UndoRedoHistory.ts +102 -0
- package/src/Viewport.ts +322 -0
- package/src/bundle/bundled.ts +7 -0
- package/src/commands/Command.ts +45 -0
- package/src/commands/Duplicate.ts +75 -0
- package/src/commands/Erase.ts +95 -0
- package/src/commands/SerializableCommand.ts +49 -0
- package/src/commands/UnresolvedCommand.ts +37 -0
- package/src/commands/invertCommand.ts +58 -0
- package/src/commands/lib.ts +16 -0
- package/src/commands/localization.ts +47 -0
- package/src/commands/uniteCommands.test.ts +23 -0
- package/src/commands/uniteCommands.ts +140 -0
- package/src/components/AbstractComponent.transformBy.test.ts +23 -0
- package/src/components/AbstractComponent.ts +383 -0
- package/src/components/BackgroundComponent.test.ts +44 -0
- package/src/components/BackgroundComponent.ts +348 -0
- package/src/components/ImageComponent.ts +176 -0
- package/src/components/RestylableComponent.ts +161 -0
- package/src/components/SVGGlobalAttributesObject.ts +79 -0
- package/src/components/Stroke.test.ts +137 -0
- package/src/components/Stroke.ts +294 -0
- package/src/components/TextComponent.test.ts +202 -0
- package/src/components/TextComponent.ts +429 -0
- package/src/components/UnknownSVGObject.test.ts +10 -0
- package/src/components/UnknownSVGObject.ts +60 -0
- package/src/components/builders/ArrowBuilder.ts +106 -0
- package/src/components/builders/CircleBuilder.ts +100 -0
- package/src/components/builders/FreehandLineBuilder.test.ts +24 -0
- package/src/components/builders/FreehandLineBuilder.ts +210 -0
- package/src/components/builders/LineBuilder.ts +77 -0
- package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +453 -0
- package/src/components/builders/RectangleBuilder.ts +73 -0
- package/src/components/builders/types.ts +15 -0
- package/src/components/lib.ts +31 -0
- package/src/components/localization.ts +24 -0
- package/src/components/util/StrokeSmoother.ts +302 -0
- package/src/components/util/describeComponentList.ts +18 -0
- package/src/dialogs/makeAboutDialog.ts +82 -0
- package/src/inputEvents.ts +143 -0
- package/src/lib.ts +91 -0
- package/src/localization.ts +34 -0
- package/src/localizations/de.ts +146 -0
- package/src/localizations/en.ts +8 -0
- package/src/localizations/es.ts +74 -0
- package/src/localizations/getLocalizationTable.test.ts +27 -0
- package/src/localizations/getLocalizationTable.ts +74 -0
- package/src/rendering/Display.ts +247 -0
- package/src/rendering/RenderablePathSpec.ts +88 -0
- package/src/rendering/RenderingStyle.test.ts +68 -0
- package/src/rendering/RenderingStyle.ts +55 -0
- package/src/rendering/TextRenderingStyle.ts +55 -0
- package/src/rendering/caching/CacheRecord.test.ts +48 -0
- package/src/rendering/caching/CacheRecord.ts +76 -0
- package/src/rendering/caching/CacheRecordManager.ts +71 -0
- package/src/rendering/caching/RenderingCache.test.ts +43 -0
- package/src/rendering/caching/RenderingCache.ts +66 -0
- package/src/rendering/caching/RenderingCacheNode.ts +404 -0
- package/src/rendering/caching/testUtils.ts +35 -0
- package/src/rendering/caching/types.ts +34 -0
- package/src/rendering/lib.ts +8 -0
- package/src/rendering/localization.ts +20 -0
- package/src/rendering/renderers/AbstractRenderer.ts +232 -0
- package/src/rendering/renderers/CanvasRenderer.ts +312 -0
- package/src/rendering/renderers/DummyRenderer.test.ts +41 -0
- package/src/rendering/renderers/DummyRenderer.ts +142 -0
- package/src/rendering/renderers/SVGRenderer.ts +434 -0
- package/src/rendering/renderers/TextOnlyRenderer.test.ts +34 -0
- package/src/rendering/renderers/TextOnlyRenderer.ts +68 -0
- package/src/shortcuts/KeyBinding.test.ts +61 -0
- package/src/shortcuts/KeyBinding.ts +257 -0
- package/src/shortcuts/KeyboardShortcutManager.test.ts +95 -0
- package/src/shortcuts/KeyboardShortcutManager.ts +163 -0
- package/src/shortcuts/lib.ts +3 -0
- package/src/testing/createEditor.ts +11 -0
- package/src/testing/getUniquePointerId.ts +18 -0
- package/src/testing/lib.ts +3 -0
- package/src/testing/sendPenEvent.ts +36 -0
- package/src/testing/sendTouchEvent.ts +71 -0
- package/src/toolbar/AbstractToolbar.ts +542 -0
- package/src/toolbar/DropdownToolbar.ts +220 -0
- package/src/toolbar/EdgeToolbar.test.ts +54 -0
- package/src/toolbar/EdgeToolbar.ts +543 -0
- package/src/toolbar/IconProvider.ts +861 -0
- package/src/toolbar/constants.ts +1 -0
- package/src/toolbar/lib.ts +6 -0
- package/src/toolbar/localization.ts +136 -0
- package/src/toolbar/types.ts +13 -0
- package/src/toolbar/widgets/ActionButtonWidget.ts +39 -0
- package/src/toolbar/widgets/BaseToolWidget.ts +81 -0
- package/src/toolbar/widgets/BaseWidget.ts +495 -0
- package/src/toolbar/widgets/DocumentPropertiesWidget.ts +250 -0
- package/src/toolbar/widgets/EraserToolWidget.ts +84 -0
- package/src/toolbar/widgets/HandToolWidget.ts +239 -0
- package/src/toolbar/widgets/InsertImageWidget.ts +248 -0
- package/src/toolbar/widgets/OverflowWidget.ts +92 -0
- package/src/toolbar/widgets/PenToolWidget.ts +369 -0
- package/src/toolbar/widgets/SelectionToolWidget.ts +195 -0
- package/src/toolbar/widgets/TextToolWidget.ts +149 -0
- package/src/toolbar/widgets/components/makeColorInput.ts +184 -0
- package/src/toolbar/widgets/components/makeFileInput.ts +128 -0
- package/src/toolbar/widgets/components/makeGridSelector.ts +179 -0
- package/src/toolbar/widgets/components/makeSeparator.ts +17 -0
- package/src/toolbar/widgets/components/makeThicknessSlider.ts +62 -0
- package/src/toolbar/widgets/keybindings.ts +19 -0
- package/src/toolbar/widgets/layout/DropdownLayoutManager.ts +262 -0
- package/src/toolbar/widgets/layout/EdgeToolbarLayoutManager.ts +71 -0
- package/src/toolbar/widgets/layout/types.ts +74 -0
- package/src/toolbar/widgets/lib.ts +13 -0
- package/src/tools/BaseTool.ts +169 -0
- package/src/tools/Eraser.test.ts +103 -0
- package/src/tools/Eraser.ts +173 -0
- package/src/tools/FindTool.test.ts +67 -0
- package/src/tools/FindTool.ts +153 -0
- package/src/tools/InputFilter/FunctionMapper.ts +17 -0
- package/src/tools/InputFilter/InputMapper.ts +41 -0
- package/src/tools/InputFilter/InputPipeline.test.ts +41 -0
- package/src/tools/InputFilter/InputPipeline.ts +34 -0
- package/src/tools/InputFilter/InputStabilizer.ts +254 -0
- package/src/tools/InputFilter/StrokeKeyboardControl.ts +104 -0
- package/src/tools/PanZoom.test.ts +339 -0
- package/src/tools/PanZoom.ts +525 -0
- package/src/tools/PasteHandler.ts +94 -0
- package/src/tools/Pen.test.ts +260 -0
- package/src/tools/Pen.ts +284 -0
- package/src/tools/PipetteTool.ts +84 -0
- package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +29 -0
- package/src/tools/SelectionTool/Selection.ts +647 -0
- package/src/tools/SelectionTool/SelectionHandle.ts +142 -0
- package/src/tools/SelectionTool/SelectionTool.test.ts +370 -0
- package/src/tools/SelectionTool/SelectionTool.ts +510 -0
- package/src/tools/SelectionTool/TransformMode.ts +112 -0
- package/src/tools/SelectionTool/types.ts +11 -0
- package/src/tools/SoundUITool.ts +221 -0
- package/src/tools/TextTool.ts +339 -0
- package/src/tools/ToolController.ts +224 -0
- package/src/tools/ToolEnabledGroup.ts +14 -0
- package/src/tools/ToolSwitcherShortcut.ts +39 -0
- package/src/tools/ToolbarShortcutHandler.ts +39 -0
- package/src/tools/UndoRedoShortcut.test.ts +62 -0
- package/src/tools/UndoRedoShortcut.ts +24 -0
- package/src/tools/keybindings.ts +85 -0
- package/src/tools/lib.ts +22 -0
- package/src/tools/localization.ts +76 -0
- package/src/types.ts +151 -0
- package/src/util/ReactiveValue.test.ts +168 -0
- package/src/util/ReactiveValue.ts +241 -0
- package/src/util/assertions.ts +55 -0
- package/src/util/fileToBase64.ts +18 -0
- package/src/util/guessKeyCodeFromKey.ts +36 -0
- package/src/util/listPrefixMatch.ts +19 -0
- package/src/util/stopPropagationOfScrollingWheelEvents.ts +20 -0
- package/src/util/untilNextAnimationFrame.ts +9 -0
- package/src/util/waitForAll.ts +18 -0
- package/src/util/waitForTimeout.ts +9 -0
- package/src/version.test.ts +12 -0
- package/src/version.ts +3 -0
package/dist/cjs/Editor.js
CHANGED
@@ -1047,7 +1047,7 @@ class Editor {
|
|
1047
1047
|
const iconLicenseText = this.icons.licenseInfo();
|
1048
1048
|
const notices = [];
|
1049
1049
|
notices.push({
|
1050
|
-
heading:
|
1050
|
+
heading: 'js-draw',
|
1051
1051
|
text: [
|
1052
1052
|
`v${version_1.default.number}`,
|
1053
1053
|
'',
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/cjs/version.js
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/mjs/Editor.mjs
CHANGED
@@ -1018,7 +1018,7 @@ export class Editor {
|
|
1018
1018
|
const iconLicenseText = this.icons.licenseInfo();
|
1019
1019
|
const notices = [];
|
1020
1020
|
notices.push({
|
1021
|
-
heading:
|
1021
|
+
heading: 'js-draw',
|
1022
1022
|
text: [
|
1023
1023
|
`v${version.number}`,
|
1024
1024
|
'',
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/dist/mjs/version.mjs
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"name": "js-draw-test-imports",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "Test module and CommonJS imports",
|
5
|
+
"author": "Henry Heino",
|
6
|
+
"license": "MIT",
|
7
|
+
"private": true,
|
8
|
+
"type": "module",
|
9
|
+
"scripts": {
|
10
|
+
"test": "node test-imports.js && node test-require.cjs"
|
11
|
+
}
|
12
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
console.log('Testing imports...');
|
2
|
+
|
3
|
+
import { TextComponent, StrokeComponent } from 'js-draw/components';
|
4
|
+
|
5
|
+
if (!TextComponent.fromLines) {
|
6
|
+
throw new Error('Failed to import module TextComponent');
|
7
|
+
}
|
8
|
+
|
9
|
+
if (!StrokeComponent.deserializeFromJSON) {
|
10
|
+
throw new Error('Failed to import StrokeComponent');
|
11
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
console.log('Testing require()...');
|
2
|
+
|
3
|
+
// TODO: Test require('js-draw') (requires removing Coloris because
|
4
|
+
// Coloris depends on the DOM when first loaded).
|
5
|
+
|
6
|
+
const { TextComponent, StrokeComponent } = require('js-draw/components');
|
7
|
+
|
8
|
+
if (!TextComponent.fromLines) {
|
9
|
+
throw new Error('Failed to import module TextComponent');
|
10
|
+
}
|
11
|
+
|
12
|
+
if (!StrokeComponent.deserializeFromJSON) {
|
13
|
+
throw new Error('Failed to import StrokeComponent');
|
14
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "js-draw",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.1",
|
4
4
|
"description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
|
5
5
|
"types": "./dist/mjs/lib.d.ts",
|
6
6
|
"main": "./dist/cjs/lib.js",
|
@@ -64,7 +64,7 @@
|
|
64
64
|
"postpack": "ts-node tools/copyREADME.ts revert"
|
65
65
|
},
|
66
66
|
"dependencies": {
|
67
|
-
"@js-draw/math": "1.0.0",
|
67
|
+
"@js-draw/math": "^1.0.0",
|
68
68
|
"@melloware/coloris": "0.21.0"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Color4 } from '@js-draw/math';
|
2
|
+
import { imageBackgroundCSSClassName } from './components/BackgroundComponent';
|
3
|
+
import { RestyleableComponent } from './lib';
|
4
|
+
import SVGLoader from './SVGLoader';
|
5
|
+
import createEditor from './testing/createEditor';
|
6
|
+
|
7
|
+
describe('Editor.loadFrom', () => {
|
8
|
+
it('should remove existing BackgroundComponents when loading new BackgroundComponents', async () => {
|
9
|
+
const editor = createEditor();
|
10
|
+
await editor.dispatch(editor.setBackgroundColor(Color4.red));
|
11
|
+
|
12
|
+
let backgroundComponents = editor.image.getBackgroundComponents();
|
13
|
+
expect(backgroundComponents).toHaveLength(1);
|
14
|
+
expect((backgroundComponents[0] as RestyleableComponent).getStyle().color).objEq(Color4.red);
|
15
|
+
|
16
|
+
await editor.loadFrom(SVGLoader.fromString(`<svg viewBox='0 0 100 100'>
|
17
|
+
<path class='${imageBackgroundCSSClassName}' d='m0,0 L100,0 L100,100 L0,100 z' fill='#000'/>
|
18
|
+
</svg>`, true));
|
19
|
+
|
20
|
+
backgroundComponents = editor.image.getBackgroundComponents();
|
21
|
+
expect(backgroundComponents).toHaveLength(1);
|
22
|
+
expect((backgroundComponents[0] as RestyleableComponent).getStyle().color).objEq(Color4.black);
|
23
|
+
});
|
24
|
+
});
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { BaseTool, InputEvtType } from './lib';
|
2
|
+
import createEditor from './testing/createEditor';
|
3
|
+
|
4
|
+
describe('Editor', () => {
|
5
|
+
it('should fire keyup events when the editor loses focus', () => {
|
6
|
+
const editor = createEditor();
|
7
|
+
const rootElem = editor.getRootElement();
|
8
|
+
|
9
|
+
const inputArea = rootElem.querySelector('textarea')! as HTMLTextAreaElement;
|
10
|
+
|
11
|
+
// Set the only tool to a tool that reports which keys are pressed.
|
12
|
+
const keyPressMock = jest.fn(() => true);
|
13
|
+
const keyReleaseMock = jest.fn();
|
14
|
+
editor.toolController.setTools([
|
15
|
+
new (class extends BaseTool {
|
16
|
+
public constructor() {
|
17
|
+
super(editor.notifier, 'test');
|
18
|
+
}
|
19
|
+
|
20
|
+
public override onKeyPress = keyPressMock;
|
21
|
+
public override onKeyUp = keyReleaseMock;
|
22
|
+
})()
|
23
|
+
]);
|
24
|
+
|
25
|
+
inputArea.focus();
|
26
|
+
|
27
|
+
// Sends a keyboard event to the editor
|
28
|
+
const dispatchKeyEvent = (kind: 'keydown'|'keyup', code: string, key: string) => {
|
29
|
+
const event = new KeyboardEvent(kind, {
|
30
|
+
bubbles: true,
|
31
|
+
key,
|
32
|
+
code,
|
33
|
+
shiftKey: false,
|
34
|
+
ctrlKey: false,
|
35
|
+
metaKey: false,
|
36
|
+
});
|
37
|
+
inputArea.dispatchEvent(event);
|
38
|
+
};
|
39
|
+
|
40
|
+
// Press the A key
|
41
|
+
dispatchKeyEvent('keydown', 'KeyA', 'a');
|
42
|
+
|
43
|
+
const keyAEvent = {
|
44
|
+
kind: InputEvtType.KeyPressEvent,
|
45
|
+
key: 'a',
|
46
|
+
code: 'KeyA',
|
47
|
+
ctrlKey: false,
|
48
|
+
altKey: false,
|
49
|
+
shiftKey: false,
|
50
|
+
};
|
51
|
+
expect(keyPressMock).toHaveBeenLastCalledWith(keyAEvent);
|
52
|
+
expect(keyPressMock).toHaveBeenCalledTimes(1);
|
53
|
+
|
54
|
+
// Press it again
|
55
|
+
dispatchKeyEvent('keydown', 'KeyA', 'a');
|
56
|
+
|
57
|
+
expect(keyPressMock).toHaveBeenLastCalledWith(keyAEvent);
|
58
|
+
expect(keyPressMock).toHaveBeenCalledTimes(2);
|
59
|
+
|
60
|
+
// Pressing a different key should send a different keydownb event to the toolbar
|
61
|
+
dispatchKeyEvent('keydown', 'KeyB', 'b');
|
62
|
+
|
63
|
+
expect(keyPressMock).not.toHaveBeenLastCalledWith(keyAEvent);
|
64
|
+
expect(keyPressMock).toHaveBeenCalledTimes(3);
|
65
|
+
|
66
|
+
// Press yet another key (and multiple times) -- if this key is still down when the
|
67
|
+
// editor is blured, a keyup event should only be fired once.
|
68
|
+
dispatchKeyEvent('keydown', 'KeyF', 'f');
|
69
|
+
expect(keyPressMock).toHaveBeenCalledTimes(4);
|
70
|
+
|
71
|
+
dispatchKeyEvent('keydown', 'KeyF', 'f');
|
72
|
+
expect(keyPressMock).toHaveBeenCalledTimes(5);
|
73
|
+
|
74
|
+
dispatchKeyEvent('keyup', 'KeyA', 'a');
|
75
|
+
expect(keyPressMock).toHaveBeenCalledTimes(5);
|
76
|
+
expect(keyReleaseMock).toHaveBeenCalledTimes(1);
|
77
|
+
expect(keyReleaseMock).toHaveBeenLastCalledWith({
|
78
|
+
...keyAEvent,
|
79
|
+
kind: InputEvtType.KeyUpEvent
|
80
|
+
});
|
81
|
+
|
82
|
+
// Defocus the input --- this should fire a key up event for the keys still down
|
83
|
+
inputArea.blur();
|
84
|
+
inputArea.dispatchEvent(new Event('blur', { bubbles: true }));
|
85
|
+
|
86
|
+
const focusable = document.createElement('button');
|
87
|
+
document.body.appendChild(focusable);
|
88
|
+
focusable.focus();
|
89
|
+
|
90
|
+
expect(keyReleaseMock).toHaveBeenCalledTimes(3);
|
91
|
+
|
92
|
+
// Events for both keys that were still down should have been fired:
|
93
|
+
const secondToLastCall = keyReleaseMock.mock.calls[keyReleaseMock.mock.calls.length - 2];
|
94
|
+
const lastCall = keyReleaseMock.mock.lastCall;
|
95
|
+
|
96
|
+
expect(secondToLastCall).toMatchObject([{
|
97
|
+
kind: InputEvtType.KeyUpEvent,
|
98
|
+
key: 'b',
|
99
|
+
code: 'KeyB',
|
100
|
+
}]);
|
101
|
+
expect(lastCall).toMatchObject([{
|
102
|
+
kind: InputEvtType.KeyUpEvent,
|
103
|
+
key: 'f',
|
104
|
+
code: 'KeyF',
|
105
|
+
}]);
|
106
|
+
});
|
107
|
+
});
|