js-draw 1.21.3 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +103 -75
- package/build-config.json +2 -2
- package/dist/Editor.css +29 -16
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.js +36 -22
- package/dist/cjs/EventDispatcher.js +1 -1
- package/dist/cjs/Pointer.js +3 -3
- package/dist/cjs/SVGLoader/SVGLoader.js +13 -6
- package/dist/cjs/UndoRedoHistory.js +1 -1
- package/dist/cjs/Viewport.js +4 -2
- package/dist/cjs/commands/Command.js +7 -5
- package/dist/cjs/commands/Duplicate.js +2 -2
- package/dist/cjs/commands/Erase.js +3 -4
- package/dist/cjs/commands/invertCommand.js +4 -4
- package/dist/cjs/commands/lib.d.ts +1 -1
- package/dist/cjs/commands/uniteCommands.js +4 -4
- package/dist/cjs/components/AbstractComponent.d.ts +1 -1
- package/dist/cjs/components/AbstractComponent.js +3 -3
- package/dist/cjs/components/BackgroundComponent.js +8 -6
- package/dist/cjs/components/ImageComponent.js +12 -5
- package/dist/cjs/components/RestylableComponent.js +1 -1
- package/dist/cjs/components/SVGGlobalAttributesObject.js +1 -2
- package/dist/cjs/components/Stroke.js +37 -24
- package/dist/cjs/components/TextComponent.js +13 -10
- package/dist/cjs/components/UnknownSVGObject.js +2 -3
- package/dist/cjs/components/builders/ArrowBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/ArrowBuilder.js +9 -3
- package/dist/cjs/components/builders/CircleBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/CircleBuilder.js +11 -4
- package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/FreehandLineBuilder.js +10 -4
- package/dist/cjs/components/builders/LineBuilder.d.ts +6 -0
- package/dist/cjs/components/builders/LineBuilder.js +8 -4
- package/dist/cjs/components/builders/PolylineBuilder.d.ts +4 -1
- package/dist/cjs/components/builders/PolylineBuilder.js +9 -5
- package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +16 -10
- package/dist/cjs/components/builders/RectangleBuilder.d.ts +12 -0
- package/dist/cjs/components/builders/RectangleBuilder.js +17 -3
- package/dist/cjs/components/builders/autocorrect/makeShapeFitAutocorrect.js +5 -8
- package/dist/cjs/components/builders/autocorrect/makeSnapToGridAutocorrect.js +1 -1
- package/dist/cjs/components/builders/lib.d.ts +7 -0
- package/dist/cjs/components/builders/lib.js +18 -0
- package/dist/cjs/components/lib.d.ts +1 -4
- package/dist/cjs/components/lib.js +2 -9
- package/dist/cjs/components/util/StrokeSmoother.js +5 -6
- package/dist/cjs/dialogs/makeAboutDialog.js +1 -1
- package/dist/cjs/dialogs/makeMessageDialog.js +2 -2
- package/dist/cjs/image/EditorImage.js +13 -15
- package/dist/cjs/image/export/editorImageToSVG.js +1 -1
- package/dist/cjs/inputEvents.js +3 -3
- package/dist/cjs/lib.d.ts +2 -2
- package/dist/cjs/localizations/de.js +2 -2
- package/dist/cjs/localizations/es.js +7 -3
- package/dist/cjs/rendering/Display.js +7 -3
- package/dist/cjs/rendering/RenderablePathSpec.js +26 -11
- package/dist/cjs/rendering/RenderingStyle.js +22 -15
- package/dist/cjs/rendering/TextRenderingStyle.js +1 -1
- package/dist/cjs/rendering/caching/CacheRecord.js +1 -1
- package/dist/cjs/rendering/caching/CacheRecordManager.js +1 -1
- package/dist/cjs/rendering/caching/RenderingCache.js +1 -1
- package/dist/cjs/rendering/caching/RenderingCacheNode.js +26 -15
- package/dist/cjs/rendering/caching/testUtils.js +2 -2
- package/dist/cjs/rendering/renderers/AbstractRenderer.js +3 -1
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +4 -3
- package/dist/cjs/rendering/renderers/DummyRenderer.js +1 -1
- package/dist/cjs/rendering/renderers/SVGRenderer.js +37 -19
- package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +13 -15
- package/dist/cjs/shortcuts/KeyBinding.js +6 -12
- package/dist/cjs/shortcuts/KeyboardShortcutManager.js +2 -2
- package/dist/cjs/testing/createEditor.js +6 -1
- package/dist/cjs/testing/findNodeWithText.d.ts +4 -1
- package/dist/cjs/testing/findNodeWithText.js +12 -3
- package/dist/cjs/testing/getUniquePointerId.js +1 -1
- package/dist/cjs/testing/sendHtmlSwipe.js +7 -3
- package/dist/cjs/testing/sendPenEvent.js +1 -3
- package/dist/cjs/testing/sendTouchEvent.js +1 -4
- package/dist/cjs/testing/startPinchGesture.js +3 -1
- package/dist/cjs/toolbar/AbstractToolbar.js +7 -11
- package/dist/cjs/toolbar/EdgeToolbar.js +11 -15
- package/dist/cjs/toolbar/IconProvider.js +5 -3
- package/dist/cjs/toolbar/localization.js +3 -3
- package/dist/cjs/toolbar/utils/HelpDisplay.js +8 -6
- package/dist/cjs/toolbar/utils/makeDraggable.js +4 -7
- package/dist/cjs/toolbar/widgets/BaseToolWidget.js +3 -2
- package/dist/cjs/toolbar/widgets/BaseWidget.js +7 -7
- package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +2 -2
- package/dist/cjs/toolbar/widgets/EraserToolWidget.js +5 -3
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +8 -6
- package/dist/cjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.js +9 -10
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +22 -13
- package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +2 -2
- package/dist/cjs/toolbar/widgets/TextToolWidget.js +5 -5
- package/dist/cjs/toolbar/widgets/components/makeFileInput.js +7 -7
- package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +5 -5
- package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +9 -5
- package/dist/cjs/toolbar/widgets/keybindings.js +2 -2
- package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +6 -6
- package/dist/cjs/tools/BaseTool.js +5 -3
- package/dist/cjs/tools/Eraser.js +25 -20
- package/dist/cjs/tools/FindTool.js +2 -2
- package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +1 -3
- package/dist/cjs/tools/InputFilter/InputMapper.js +1 -1
- package/dist/cjs/tools/InputFilter/InputPipeline.js +1 -1
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +12 -5
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +7 -4
- package/dist/cjs/tools/PanZoom.d.ts +1 -1
- package/dist/cjs/tools/PanZoom.js +17 -12
- package/dist/cjs/tools/PasteHandler.js +8 -2
- package/dist/cjs/tools/Pen.js +17 -9
- package/dist/cjs/tools/ScrollbarTool.js +8 -7
- package/dist/cjs/tools/SelectionTool/Selection.js +16 -12
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +5 -2
- package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +3 -1
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +25 -16
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +1 -1
- package/dist/cjs/tools/SelectionTool/TransformMode.js +6 -7
- package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +23 -2
- package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.js +29 -20
- package/dist/cjs/tools/SoundUITool.js +5 -3
- package/dist/cjs/tools/TextTool.js +8 -6
- package/dist/cjs/tools/ToolController.js +16 -10
- package/dist/cjs/tools/localization.d.ts +2 -0
- package/dist/cjs/tools/localization.js +3 -1
- package/dist/cjs/tools/util/StationaryPenDetector.js +3 -3
- package/dist/cjs/tools/util/createMenuOverlay.js +2 -2
- package/dist/cjs/util/ClipboardHandler.d.ts +1 -1
- package/dist/cjs/util/ClipboardHandler.js +19 -18
- package/dist/cjs/util/ReactiveValue.js +16 -12
- package/dist/cjs/util/adjustEditorThemeForContrast.js +6 -2
- package/dist/cjs/util/guessKeyCodeFromKey.js +1 -1
- package/dist/cjs/util/listenForKeyboardEventsFrom.js +8 -6
- package/dist/cjs/util/waitForAll.js +3 -3
- package/dist/cjs/util/waitForImageLoaded.js +3 -3
- package/dist/cjs/util/waitForTimeout.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.mjs +37 -23
- package/dist/mjs/EventDispatcher.mjs +1 -1
- package/dist/mjs/Pointer.mjs +3 -3
- package/dist/mjs/SVGLoader/SVGLoader.mjs +14 -7
- package/dist/mjs/UndoRedoHistory.mjs +1 -1
- package/dist/mjs/Viewport.mjs +4 -2
- package/dist/mjs/commands/Command.mjs +7 -5
- package/dist/mjs/commands/Duplicate.mjs +2 -2
- package/dist/mjs/commands/Erase.mjs +3 -4
- package/dist/mjs/commands/invertCommand.mjs +4 -4
- package/dist/mjs/commands/lib.d.ts +1 -1
- package/dist/mjs/commands/lib.mjs +1 -1
- package/dist/mjs/commands/uniteCommands.mjs +4 -4
- package/dist/mjs/components/AbstractComponent.d.ts +1 -1
- package/dist/mjs/components/AbstractComponent.mjs +3 -3
- package/dist/mjs/components/BackgroundComponent.mjs +10 -8
- package/dist/mjs/components/ImageComponent.mjs +12 -5
- package/dist/mjs/components/RestylableComponent.mjs +2 -2
- package/dist/mjs/components/SVGGlobalAttributesObject.mjs +1 -2
- package/dist/mjs/components/Stroke.mjs +40 -27
- package/dist/mjs/components/TextComponent.mjs +15 -12
- package/dist/mjs/components/UnknownSVGObject.mjs +2 -3
- package/dist/mjs/components/builders/ArrowBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/ArrowBuilder.mjs +9 -3
- package/dist/mjs/components/builders/CircleBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/CircleBuilder.mjs +11 -4
- package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/FreehandLineBuilder.mjs +10 -4
- package/dist/mjs/components/builders/LineBuilder.d.ts +6 -0
- package/dist/mjs/components/builders/LineBuilder.mjs +8 -4
- package/dist/mjs/components/builders/PolylineBuilder.d.ts +4 -1
- package/dist/mjs/components/builders/PolylineBuilder.mjs +10 -6
- package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +17 -11
- package/dist/mjs/components/builders/RectangleBuilder.d.ts +12 -0
- package/dist/mjs/components/builders/RectangleBuilder.mjs +17 -3
- package/dist/mjs/components/builders/autocorrect/makeShapeFitAutocorrect.mjs +5 -8
- package/dist/mjs/components/builders/autocorrect/makeSnapToGridAutocorrect.mjs +1 -1
- package/dist/mjs/components/builders/lib.d.ts +7 -0
- package/dist/mjs/components/builders/lib.mjs +7 -0
- package/dist/mjs/components/lib.d.ts +1 -4
- package/dist/mjs/components/lib.mjs +2 -5
- package/dist/mjs/components/util/StrokeSmoother.mjs +5 -6
- package/dist/mjs/dialogs/makeAboutDialog.mjs +1 -1
- package/dist/mjs/dialogs/makeMessageDialog.mjs +2 -2
- package/dist/mjs/image/EditorImage.mjs +13 -15
- package/dist/mjs/image/export/editorImageToSVG.mjs +1 -1
- package/dist/mjs/inputEvents.mjs +3 -3
- package/dist/mjs/lib.d.ts +2 -2
- package/dist/mjs/lib.mjs +2 -2
- package/dist/mjs/localization.mjs +2 -2
- package/dist/mjs/localizations/de.mjs +2 -2
- package/dist/mjs/localizations/es.mjs +7 -3
- package/dist/mjs/rendering/Display.mjs +7 -3
- package/dist/mjs/rendering/RenderablePathSpec.mjs +26 -11
- package/dist/mjs/rendering/RenderingStyle.mjs +22 -15
- package/dist/mjs/rendering/TextRenderingStyle.mjs +1 -1
- package/dist/mjs/rendering/caching/CacheRecord.mjs +1 -1
- package/dist/mjs/rendering/caching/CacheRecordManager.mjs +1 -1
- package/dist/mjs/rendering/caching/RenderingCache.mjs +1 -1
- package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +26 -15
- package/dist/mjs/rendering/caching/testUtils.mjs +2 -2
- package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +3 -1
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +4 -3
- package/dist/mjs/rendering/renderers/DummyRenderer.mjs +1 -1
- package/dist/mjs/rendering/renderers/SVGRenderer.mjs +38 -20
- package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +13 -15
- package/dist/mjs/shortcuts/KeyBinding.mjs +6 -12
- package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +2 -2
- package/dist/mjs/testing/createEditor.mjs +6 -1
- package/dist/mjs/testing/findNodeWithText.d.ts +4 -1
- package/dist/mjs/testing/findNodeWithText.mjs +12 -3
- package/dist/mjs/testing/getUniquePointerId.mjs +1 -1
- package/dist/mjs/testing/sendHtmlSwipe.mjs +7 -3
- package/dist/mjs/testing/sendPenEvent.mjs +1 -3
- package/dist/mjs/testing/sendTouchEvent.mjs +1 -4
- package/dist/mjs/testing/startPinchGesture.mjs +3 -1
- package/dist/mjs/toolbar/AbstractToolbar.mjs +7 -11
- package/dist/mjs/toolbar/EdgeToolbar.mjs +11 -15
- package/dist/mjs/toolbar/IconProvider.mjs +5 -3
- package/dist/mjs/toolbar/localization.mjs +3 -3
- package/dist/mjs/toolbar/utils/HelpDisplay.mjs +8 -6
- package/dist/mjs/toolbar/utils/makeDraggable.mjs +4 -7
- package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +3 -2
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +8 -8
- package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +2 -2
- package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +5 -3
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +8 -6
- package/dist/mjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.mjs +9 -10
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +23 -14
- package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +2 -2
- package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +5 -5
- package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +7 -7
- package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +5 -5
- package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +9 -5
- package/dist/mjs/toolbar/widgets/keybindings.mjs +2 -2
- package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +6 -6
- package/dist/mjs/tools/BaseTool.mjs +6 -4
- package/dist/mjs/tools/Eraser.mjs +25 -20
- package/dist/mjs/tools/FindTool.mjs +2 -2
- package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.mjs +2 -4
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +1 -1
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +1 -1
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +13 -6
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +7 -4
- package/dist/mjs/tools/PanZoom.d.ts +1 -1
- package/dist/mjs/tools/PanZoom.mjs +18 -13
- package/dist/mjs/tools/PasteHandler.mjs +8 -2
- package/dist/mjs/tools/Pen.mjs +18 -10
- package/dist/mjs/tools/ScrollbarTool.mjs +8 -7
- package/dist/mjs/tools/SelectionTool/Selection.mjs +16 -12
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +5 -2
- package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +3 -1
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +26 -17
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +1 -1
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +6 -7
- package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +23 -2
- package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.mjs +29 -20
- package/dist/mjs/tools/SoundUITool.mjs +5 -3
- package/dist/mjs/tools/TextTool.mjs +8 -6
- package/dist/mjs/tools/ToolController.mjs +16 -10
- package/dist/mjs/tools/localization.d.ts +2 -0
- package/dist/mjs/tools/localization.mjs +3 -1
- package/dist/mjs/tools/util/StationaryPenDetector.mjs +3 -3
- package/dist/mjs/tools/util/createMenuOverlay.mjs +2 -2
- package/dist/mjs/util/ClipboardHandler.d.ts +1 -1
- package/dist/mjs/util/ClipboardHandler.mjs +19 -18
- package/dist/mjs/util/ReactiveValue.mjs +16 -12
- package/dist/mjs/util/adjustEditorThemeForContrast.mjs +6 -2
- package/dist/mjs/util/guessKeyCodeFromKey.mjs +1 -1
- package/dist/mjs/util/listenForKeyboardEventsFrom.mjs +8 -6
- package/dist/mjs/util/waitForAll.mjs +3 -3
- package/dist/mjs/util/waitForImageLoaded.mjs +3 -3
- package/dist/mjs/util/waitForTimeout.mjs +1 -1
- package/dist/mjs/version.mjs +1 -1
- package/package.json +88 -88
- package/src/Coloris.css +6 -6
- package/src/Editor.scss +7 -5
- package/src/dialogs/dialogs.scss +3 -4
- package/src/dialogs/makeAboutDialog.scss +2 -2
- package/src/dialogs/makeMessageDialog.scss +11 -7
- package/src/styles.js +1 -1
- package/src/toolbar/AbstractToolbar.scss +20 -12
- package/src/toolbar/DropdownToolbar.scss +5 -4
- package/src/toolbar/EdgeToolbar.scss +65 -31
- package/src/toolbar/toolbar.scss +5 -5
- package/src/toolbar/utils/HelpDisplay.scss +48 -25
- package/src/toolbar/utils/labelVisibleOnHover.scss +39 -16
- package/src/toolbar/widgets/DocumentPropertiesWidget.scss +0 -1
- package/src/toolbar/widgets/HandToolWidget.scss +0 -1
- package/src/toolbar/widgets/InsertImageWidget/InsertImageWidget.scss +2 -3
- package/src/toolbar/widgets/OverflowWidget.css +1 -2
- package/src/toolbar/widgets/PenToolWidget.scss +0 -2
- package/src/toolbar/widgets/SelectionToolWidget.scss +1 -2
- package/src/toolbar/widgets/components/components.scss +6 -6
- package/src/toolbar/widgets/components/makeColorInput.scss +0 -2
- package/src/toolbar/widgets/components/makeFileInput.scss +5 -7
- package/src/toolbar/widgets/components/makeGridSelector.scss +6 -9
- package/src/toolbar/widgets/components/makeSnappedList.scss +3 -4
- package/src/toolbar/widgets/components/makeThicknessSlider.scss +1 -2
- package/src/toolbar/widgets/widgets.scss +7 -7
- package/src/tools/FindTool.css +1 -2
- package/src/tools/ScrollbarTool.scss +9 -5
- package/src/tools/SelectionTool/SelectionTool.scss +15 -7
- package/src/tools/SelectionTool/util/makeClipboardErrorHandlers.scss +1 -2
- package/src/tools/SoundUITool.scss +4 -4
- package/src/tools/tools.scss +5 -6
- package/src/tools/util/createMenuOverlay.scss +10 -4
- package/tsconfig.json +1 -3
- package/typedoc.json +1 -1
package/dist/mjs/Editor.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import EditorImage from './image/EditorImage.mjs';
|
2
2
|
import ToolController from './tools/ToolController.mjs';
|
3
3
|
import { EditorEventType } from './types.mjs';
|
4
|
-
import { InputEvtType, keyUpEventFromHTMLEvent, keyPressEventFromHTMLEvent } from './inputEvents.mjs';
|
4
|
+
import { InputEvtType, keyUpEventFromHTMLEvent, keyPressEventFromHTMLEvent, } from './inputEvents.mjs';
|
5
5
|
import UndoRedoHistory from './UndoRedoHistory.mjs';
|
6
6
|
import Viewport from './Viewport.mjs';
|
7
7
|
import EventDispatcher from './EventDispatcher.mjs';
|
@@ -112,7 +112,7 @@ export class Editor {
|
|
112
112
|
appInfo: settings.appInfo ? { ...settings.appInfo } : null,
|
113
113
|
pens: {
|
114
114
|
additionalPenTypes: settings.pens?.additionalPenTypes ?? [],
|
115
|
-
filterPenTypes: settings.pens?.filterPenTypes ?? (() => true)
|
115
|
+
filterPenTypes: settings.pens?.filterPenTypes ?? (() => true),
|
116
116
|
},
|
117
117
|
text: {
|
118
118
|
fonts: settings.text?.fonts ?? ['sans-serif', 'serif', 'monospace'],
|
@@ -172,7 +172,7 @@ export class Editor {
|
|
172
172
|
this.queueRerender();
|
173
173
|
this.hideLoadingWarning();
|
174
174
|
// Enforce zoom limits.
|
175
|
-
this.notifier.on(EditorEventType.ViewportChanged, evt => {
|
175
|
+
this.notifier.on(EditorEventType.ViewportChanged, (evt) => {
|
176
176
|
if (evt.kind !== EditorEventType.ViewportChanged)
|
177
177
|
return;
|
178
178
|
const getZoom = (mat) => mat.transformVec3(Vec2.unitX).length();
|
@@ -281,16 +281,16 @@ export class Editor {
|
|
281
281
|
this.loadingWarning,
|
282
282
|
];
|
283
283
|
for (const element of preventSelectionOf) {
|
284
|
-
element.addEventListener('drag', event => {
|
284
|
+
element.addEventListener('drag', (event) => {
|
285
285
|
event.preventDefault();
|
286
286
|
return false;
|
287
287
|
});
|
288
|
-
element.addEventListener('dragstart', event => {
|
288
|
+
element.addEventListener('dragstart', (event) => {
|
289
289
|
event.preventDefault();
|
290
290
|
return false;
|
291
291
|
});
|
292
292
|
}
|
293
|
-
this.container.addEventListener('wheel', evt => {
|
293
|
+
this.container.addEventListener('wheel', (evt) => {
|
294
294
|
this.handleHTMLWheelEvent(evt);
|
295
295
|
});
|
296
296
|
const handleResize = () => {
|
@@ -316,7 +316,7 @@ export class Editor {
|
|
316
316
|
}
|
317
317
|
copyHandler.copy(evt);
|
318
318
|
});
|
319
|
-
document.addEventListener('paste', evt => {
|
319
|
+
document.addEventListener('paste', (evt) => {
|
320
320
|
this.handlePaste(evt);
|
321
321
|
});
|
322
322
|
}
|
@@ -371,7 +371,7 @@ export class Editor {
|
|
371
371
|
const res = [];
|
372
372
|
for (const id in this.pointers) {
|
373
373
|
const maxUnupdatedTime = 2000; // Maximum time without a pointer update (ms)
|
374
|
-
if (this.pointers[id] &&
|
374
|
+
if (this.pointers[id] && nowTime - this.pointers[id].timeStamp < maxUnupdatedTime) {
|
375
375
|
res.push(this.pointers[id]);
|
376
376
|
}
|
377
377
|
}
|
@@ -526,10 +526,15 @@ export class Editor {
|
|
526
526
|
evt.preventDefault();
|
527
527
|
};
|
528
528
|
const listeners = {
|
529
|
-
|
530
|
-
|
529
|
+
touchstart: touchstartListener,
|
530
|
+
contextmenu: contextmenuListener,
|
531
531
|
};
|
532
|
-
const eventNames = [
|
532
|
+
const eventNames = [
|
533
|
+
'pointerdown',
|
534
|
+
'pointermove',
|
535
|
+
'pointerup',
|
536
|
+
'pointercancel',
|
537
|
+
];
|
533
538
|
for (const eventName of eventNames) {
|
534
539
|
listeners[eventName] = (evt) => {
|
535
540
|
// This listener will only be called in the context of PointerEvents.
|
@@ -614,8 +619,9 @@ export class Editor {
|
|
614
619
|
// Otherwise, if we received a pointerup/pointercancel without flushing all pointerevents from the
|
615
620
|
// buffer, the gesture wasn't recognised as a stroke. Thus, the editor isn't expecting a pointerup/
|
616
621
|
// pointercancel event.
|
617
|
-
else if ((eventName === 'pointerup' || eventName === 'pointercancel')
|
618
|
-
|
622
|
+
else if ((eventName === 'pointerup' || eventName === 'pointercancel') &&
|
623
|
+
gestureData[pointerId] &&
|
624
|
+
gestureData[pointerId].eventBuffer.length > 0) {
|
619
625
|
this.releasePointerCapture(elem, event.pointerId);
|
620
626
|
// Don't send to the editor.
|
621
627
|
sendToEditor = false;
|
@@ -675,10 +681,10 @@ export class Editor {
|
|
675
681
|
},
|
676
682
|
});
|
677
683
|
// Allow drop.
|
678
|
-
elem.ondragover = evt => {
|
684
|
+
elem.ondragover = (evt) => {
|
679
685
|
evt.preventDefault();
|
680
686
|
};
|
681
|
-
elem.ondrop = evt => {
|
687
|
+
elem.ondrop = (evt) => {
|
682
688
|
this.handleDrop(evt);
|
683
689
|
};
|
684
690
|
this.eventListenerTargets.push(elem);
|
@@ -760,7 +766,7 @@ export class Editor {
|
|
760
766
|
}
|
761
767
|
// Re-render to show progress, but only if we're not done.
|
762
768
|
if (i + updateChunkSize < commands.length) {
|
763
|
-
await new Promise(resolve => {
|
769
|
+
await new Promise((resolve) => {
|
764
770
|
this.rerender();
|
765
771
|
requestAnimationFrame(resolve);
|
766
772
|
});
|
@@ -803,7 +809,7 @@ export class Editor {
|
|
803
809
|
}
|
804
810
|
});
|
805
811
|
}
|
806
|
-
return new Promise(resolve => {
|
812
|
+
return new Promise((resolve) => {
|
807
813
|
this.nextRerenderListeners.push(() => resolve());
|
808
814
|
});
|
809
815
|
}
|
@@ -831,7 +837,7 @@ export class Editor {
|
|
831
837
|
renderer.drawRect(this.getImportExportRect(), exportRectStrokeWidth, exportRectFill);
|
832
838
|
}
|
833
839
|
this.rerenderQueued = false;
|
834
|
-
this.nextRerenderListeners.forEach(listener => listener());
|
840
|
+
this.nextRerenderListeners.forEach((listener) => listener());
|
835
841
|
this.nextRerenderListeners = [];
|
836
842
|
}
|
837
843
|
/**
|
@@ -873,6 +879,7 @@ export class Editor {
|
|
873
879
|
* (e.g. a selection box).
|
874
880
|
*/
|
875
881
|
createHTMLOverlay(overlay) {
|
882
|
+
// TODO(v2): Fix conflict with toolbars that have been added to the editor.
|
876
883
|
overlay.classList.add('overlay', 'js-draw-editor-overlay');
|
877
884
|
this.container.appendChild(overlay);
|
878
885
|
return {
|
@@ -951,7 +958,8 @@ export class Editor {
|
|
951
958
|
const scaleRatioX = visibleRect.width / bbox.width;
|
952
959
|
const scaleRatioY = visibleRect.height / bbox.height;
|
953
960
|
let scaleRatio = scaleRatioX;
|
954
|
-
if (bbox.width * scaleRatio > visibleRect.width ||
|
961
|
+
if (bbox.width * scaleRatio > visibleRect.width ||
|
962
|
+
bbox.height * scaleRatio > visibleRect.height) {
|
955
963
|
scaleRatio = scaleRatioY;
|
956
964
|
}
|
957
965
|
scaleRatio *= 2 / 3;
|
@@ -1106,7 +1114,9 @@ export class Editor {
|
|
1106
1114
|
const originalType = originalBackground?.getBackgroundType?.() ?? BackgroundType.None;
|
1107
1115
|
const originalColor = originalBackground?.getStyle?.().color ?? Color4.transparent;
|
1108
1116
|
const originalFillsScreen = this.image.getAutoresizeEnabled();
|
1109
|
-
const defaultType =
|
1117
|
+
const defaultType = style.color && originalType === BackgroundType.None
|
1118
|
+
? BackgroundType.SolidColor
|
1119
|
+
: originalType;
|
1110
1120
|
const backgroundType = style.type ?? defaultType;
|
1111
1121
|
const backgroundColor = style.color ?? originalColor;
|
1112
1122
|
const fillsScreen = style.autoresize ?? originalFillsScreen;
|
@@ -1134,7 +1144,9 @@ export class Editor {
|
|
1134
1144
|
setBackgroundColor(color) {
|
1135
1145
|
let background = this.getTopmostBackgroundComponent();
|
1136
1146
|
if (!background) {
|
1137
|
-
const backgroundType = color.eq(Color4.transparent)
|
1147
|
+
const backgroundType = color.eq(Color4.transparent)
|
1148
|
+
? BackgroundType.None
|
1149
|
+
: BackgroundType.SolidColor;
|
1138
1150
|
background = new BackgroundComponent(backgroundType, color);
|
1139
1151
|
return this.image.addElement(background);
|
1140
1152
|
}
|
@@ -1221,14 +1233,16 @@ export class Editor {
|
|
1221
1233
|
heading: this.localization.developerInformation,
|
1222
1234
|
text: [
|
1223
1235
|
'Image debug information (from when this dialog was opened):',
|
1224
|
-
` ${this.viewport.getScaleFactor()}x zoom, ${180 / Math.PI * this.viewport.getRotationAngle()}° rotation`,
|
1236
|
+
` ${this.viewport.getScaleFactor()}x zoom, ${(180 / Math.PI) * this.viewport.getRotationAngle()}° rotation`,
|
1225
1237
|
` ${this.image.estimateNumElements()} components`,
|
1226
1238
|
` auto-resize: ${this.image.getAutoresizeEnabled() ? 'enabled' : 'disabled'}`,
|
1227
1239
|
` image size: ${this.getImportExportRect().w}x${this.getImportExportRect().h}`,
|
1228
1240
|
` screen size: ${screenSize.x}x${screenSize.y}`,
|
1229
1241
|
` device pixel ratio: ${this.display.getDevicePixelRatio()}`,
|
1230
1242
|
' cache:',
|
1231
|
-
` ${this.display
|
1243
|
+
` ${this.display
|
1244
|
+
.getCache()
|
1245
|
+
.getDebugInfo()
|
1232
1246
|
// Indent
|
1233
1247
|
.replace(/([\n])/g, '\n ')}`,
|
1234
1248
|
].join('\n'),
|
@@ -49,6 +49,6 @@ export default class EventDispatcher {
|
|
49
49
|
// Replace the current list of listeners with a new, shortened list.
|
50
50
|
// This allows any iterators over this.listeners to continue iterating
|
51
51
|
// without skipping elements.
|
52
|
-
this.listeners[eventName] = listeners.filter(otherCallback => otherCallback !== callback);
|
52
|
+
this.listeners[eventName] = listeners.filter((otherCallback) => otherCallback !== callback);
|
53
53
|
}
|
54
54
|
}
|
package/dist/mjs/Pointer.mjs
CHANGED
@@ -86,9 +86,9 @@ export default class Pointer {
|
|
86
86
|
screenPos = screenPos.minus(Vec2.of(bbox.left, bbox.top));
|
87
87
|
}
|
88
88
|
const pointerTypeToDevice = {
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
mouse: PointerDevice.PrimaryButtonMouse,
|
90
|
+
pen: PointerDevice.Pen,
|
91
|
+
touch: PointerDevice.Touch,
|
92
92
|
};
|
93
93
|
let device = pointerTypeToDevice[evt.pointerType] ?? PointerDevice.Other;
|
94
94
|
const eraserButtonMask = 0x20;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Color4, Mat33, Path, Rect2, Vec2 } from '@js-draw/math';
|
2
|
-
import BackgroundComponent, { BackgroundType, backgroundTypeToClassNameMap, imageBackgroundCSSClassName, imageBackgroundGridSizeCSSPrefix, imageBackgroundNonAutomaticSecondaryColorCSSClassName } from '../components/BackgroundComponent.mjs';
|
2
|
+
import BackgroundComponent, { BackgroundType, backgroundTypeToClassNameMap, imageBackgroundCSSClassName, imageBackgroundGridSizeCSSPrefix, imageBackgroundNonAutomaticSecondaryColorCSSClassName, } from '../components/BackgroundComponent.mjs';
|
3
3
|
import ImageComponent from '../components/ImageComponent.mjs';
|
4
4
|
import Stroke from '../components/Stroke.mjs';
|
5
5
|
import SVGGlobalAttributesObject from '../components/SVGGlobalAttributesObject.mjs';
|
@@ -59,7 +59,10 @@ export default class SVGLoader {
|
|
59
59
|
}
|
60
60
|
}
|
61
61
|
const strokeAttribute = node.getAttribute('stroke') ?? computedStyles?.stroke ?? node.style?.stroke ?? '';
|
62
|
-
const strokeWidthAttr = node.getAttribute('stroke-width') ??
|
62
|
+
const strokeWidthAttr = node.getAttribute('stroke-width') ??
|
63
|
+
computedStyles?.strokeWidth ??
|
64
|
+
node.style?.strokeWidth ??
|
65
|
+
'';
|
63
66
|
if (strokeAttribute && strokeWidthAttr) {
|
64
67
|
try {
|
65
68
|
let width = parseFloat(strokeWidthAttr ?? '1');
|
@@ -114,7 +117,10 @@ export default class SVGLoader {
|
|
114
117
|
if (supportedAttrs.has(attr) || (attr === 'style' && supportedStyleAttrs)) {
|
115
118
|
continue;
|
116
119
|
}
|
117
|
-
elem.attachLoadSaveData(svgAttributesDataKey, [
|
120
|
+
elem.attachLoadSaveData(svgAttributesDataKey, [
|
121
|
+
attr,
|
122
|
+
node.getAttribute(attr),
|
123
|
+
]);
|
118
124
|
}
|
119
125
|
if (supportedStyleAttrs && node.style) {
|
120
126
|
// Use a for loop instead of an iterator: js-dom seems to not
|
@@ -131,7 +137,7 @@ export default class SVGLoader {
|
|
131
137
|
elem.attachLoadSaveData(svgStyleAttributesDataKey, {
|
132
138
|
key: attr,
|
133
139
|
value: node.style.getPropertyValue(attr),
|
134
|
-
priority: node.style.getPropertyPriority(attr)
|
140
|
+
priority: node.style.getPropertyPriority(attr),
|
135
141
|
});
|
136
142
|
}
|
137
143
|
}
|
@@ -492,7 +498,7 @@ export default class SVGLoader {
|
|
492
498
|
}
|
493
499
|
// Get SVG element attributes (e.g. xlink=...)
|
494
500
|
getSourceAttrs(node) {
|
495
|
-
return node.getAttributeNames().map(attr => {
|
501
|
+
return node.getAttributeNames().map((attr) => {
|
496
502
|
return [attr, node.getAttribute(attr)];
|
497
503
|
});
|
498
504
|
}
|
@@ -533,7 +539,7 @@ export default class SVGLoader {
|
|
533
539
|
// allow-same-origin is necessary for how we interact with the sandbox. As such,
|
534
540
|
// DO NOT ENABLE ALLOW-SCRIPTS.
|
535
541
|
sandbox.setAttribute('sandbox', 'allow-same-origin');
|
536
|
-
sandbox.setAttribute('csp',
|
542
|
+
sandbox.setAttribute('csp', "default-src 'about:blank'");
|
537
543
|
sandbox.style.display = 'none';
|
538
544
|
// Required to access the frame's DOM. See https://stackoverflow.com/a/17777943/17055750
|
539
545
|
document.body.appendChild(sandbox);
|
@@ -603,7 +609,8 @@ export default class SVGLoader {
|
|
603
609
|
disableUnknownObjectWarnings = options.disableUnknownObjectWarnings ?? false;
|
604
610
|
}
|
605
611
|
return new SVGLoader(svgElem, cleanUp, {
|
606
|
-
sanitize,
|
612
|
+
sanitize,
|
613
|
+
disableUnknownObjectWarnings,
|
607
614
|
});
|
608
615
|
}
|
609
616
|
}
|
@@ -45,7 +45,7 @@ class UndoRedoHistory {
|
|
45
45
|
if (__classPrivateFieldGet(this, _UndoRedoHistory_undoStack, "f").length > this.maxUndoRedoStackSize) {
|
46
46
|
const removeAtOnceCount = Math.ceil(this.maxUndoRedoStackSize / 100);
|
47
47
|
const removedElements = __classPrivateFieldGet(this, _UndoRedoHistory_undoStack, "f").splice(0, removeAtOnceCount);
|
48
|
-
removedElements.forEach(elem => elem.onDrop(this.editor));
|
48
|
+
removedElements.forEach((elem) => elem.onDrop(this.editor));
|
49
49
|
}
|
50
50
|
this.fireUpdateEvent(UndoEventType.CommandDone, command);
|
51
51
|
this.editor.notifier.dispatch(EditorEventType.CommandDone, {
|
package/dist/mjs/Viewport.mjs
CHANGED
@@ -151,7 +151,9 @@ export class Viewport {
|
|
151
151
|
// Represent as k 10ⁿ for some n, k ∈ ℤ.
|
152
152
|
const decimalComponent = 10 ** Math.floor(Math.log10(Math.abs(scaleRatio)));
|
153
153
|
const roundAmountFactor = 2 ** roundAmount;
|
154
|
-
scaleRatio =
|
154
|
+
scaleRatio =
|
155
|
+
(Math.round((scaleRatio / decimalComponent) * roundAmountFactor) / roundAmountFactor) *
|
156
|
+
decimalComponent;
|
155
157
|
return scaleRatio;
|
156
158
|
}
|
157
159
|
// Computes and returns an affine transformation that makes `toMakeVisible` visible and roughly centered on the screen.
|
@@ -240,7 +242,7 @@ Viewport.ViewportTransform = (_a = class extends ViewportTransform {
|
|
240
242
|
const linearTransformedVec = this.transform.transformVec3(Vec2.unitX);
|
241
243
|
const affineTransformedVec = this.transform.transformVec2(origVec);
|
242
244
|
const scale = linearTransformedVec.magnitude();
|
243
|
-
const rotation = 180 / Math.PI * linearTransformedVec.angle();
|
245
|
+
const rotation = (180 / Math.PI) * linearTransformedVec.angle();
|
244
246
|
const translation = affineTransformedVec.minus(origVec);
|
245
247
|
if (scale > 1.2) {
|
246
248
|
result.push(localizationTable.zoomedIn);
|
@@ -8,7 +8,7 @@ export class Command {
|
|
8
8
|
onDrop(_editor) { }
|
9
9
|
/** @deprecated Use {@link uniteCommands} */
|
10
10
|
static union(a, b) {
|
11
|
-
return new class extends Command {
|
11
|
+
return new (class extends Command {
|
12
12
|
apply(editor) {
|
13
13
|
a.apply(editor);
|
14
14
|
b.apply(editor);
|
@@ -25,12 +25,14 @@ export class Command {
|
|
25
25
|
}
|
26
26
|
return `${aDescription}, ${bDescription}`;
|
27
27
|
}
|
28
|
-
};
|
28
|
+
})();
|
29
29
|
}
|
30
30
|
}
|
31
|
-
Command.empty = new class extends Command {
|
32
|
-
description(_editor, _localizationTable) {
|
31
|
+
Command.empty = new (class extends Command {
|
32
|
+
description(_editor, _localizationTable) {
|
33
|
+
return '';
|
34
|
+
}
|
33
35
|
apply(_editor) { }
|
34
36
|
unapply(_editor) { }
|
35
|
-
};
|
37
|
+
})();
|
36
38
|
export default Command;
|
@@ -28,7 +28,7 @@ class Duplicate extends SerializableCommand {
|
|
28
28
|
constructor(toDuplicate) {
|
29
29
|
super('duplicate');
|
30
30
|
this.toDuplicate = toDuplicate;
|
31
|
-
this.duplicates = toDuplicate.map(elem => elem.clone());
|
31
|
+
this.duplicates = toDuplicate.map((elem) => elem.clone());
|
32
32
|
this.reverse = new Erase(this.duplicates);
|
33
33
|
}
|
34
34
|
apply(editor) {
|
@@ -47,7 +47,7 @@ class Duplicate extends SerializableCommand {
|
|
47
47
|
return localizationTable.duplicateAction(describeComponentList(localizationTable, this.duplicates) ?? localizationTable.elements, this.duplicates.length);
|
48
48
|
}
|
49
49
|
serializeToJSON() {
|
50
|
-
return this.toDuplicate.map(elem => elem.getId());
|
50
|
+
return this.toDuplicate.map((elem) => elem.getId());
|
51
51
|
}
|
52
52
|
}
|
53
53
|
(() => {
|
@@ -46,7 +46,7 @@ class Erase extends SerializableCommand {
|
|
46
46
|
constructor(toRemove) {
|
47
47
|
super('erase');
|
48
48
|
// Clone the list
|
49
|
-
this.toRemove = toRemove.map(elem => elem);
|
49
|
+
this.toRemove = toRemove.map((elem) => elem);
|
50
50
|
this.applied = false;
|
51
51
|
}
|
52
52
|
apply(editor) {
|
@@ -86,7 +86,7 @@ class Erase extends SerializableCommand {
|
|
86
86
|
serializeToJSON() {
|
87
87
|
// If applied, the elements can't be fetched from the image because they're
|
88
88
|
// erased. Serialize and return the elements themselves.
|
89
|
-
const elems = this.toRemove.map(elem => elem.serialize());
|
89
|
+
const elems = this.toRemove.map((elem) => elem.serialize());
|
90
90
|
return elems;
|
91
91
|
}
|
92
92
|
}
|
@@ -95,8 +95,7 @@ class Erase extends SerializableCommand {
|
|
95
95
|
if (!Array.isArray(json)) {
|
96
96
|
throw new Error('seralized erase data must be an array');
|
97
97
|
}
|
98
|
-
const elems = json
|
99
|
-
.map((elemData) => {
|
98
|
+
const elems = json.map((elemData) => {
|
100
99
|
const componentId = typeof elemData === 'string' ? elemData : `${elemData.id}`;
|
101
100
|
const component = editor.image.lookupElement(componentId) ?? AbstractComponent.deserialize(elemData);
|
102
101
|
return component;
|
@@ -5,7 +5,7 @@ import SerializableCommand from './SerializableCommand.mjs';
|
|
5
5
|
const invertCommand = (command) => {
|
6
6
|
if (command instanceof SerializableCommand) {
|
7
7
|
// SerializableCommand that does the inverse of [command]
|
8
|
-
return new class extends SerializableCommand {
|
8
|
+
return new (class extends SerializableCommand {
|
9
9
|
constructor() {
|
10
10
|
super(...arguments);
|
11
11
|
// For debugging
|
@@ -26,11 +26,11 @@ const invertCommand = (command) => {
|
|
26
26
|
description(editor, localizationTable) {
|
27
27
|
return localizationTable.inverseOf(command.description(editor, localizationTable));
|
28
28
|
}
|
29
|
-
}('inverse');
|
29
|
+
})('inverse');
|
30
30
|
}
|
31
31
|
else {
|
32
32
|
// Command that does the inverse of [command].
|
33
|
-
const result = new class extends Command {
|
33
|
+
const result = new (class extends Command {
|
34
34
|
apply(editor) {
|
35
35
|
command.unapply(editor);
|
36
36
|
}
|
@@ -43,7 +43,7 @@ const invertCommand = (command) => {
|
|
43
43
|
description(editor, localizationTable) {
|
44
44
|
return localizationTable.inverseOf(command.description(editor, localizationTable));
|
45
45
|
}
|
46
|
-
};
|
46
|
+
})();
|
47
47
|
// We know that T does not extend SerializableCommand, and thus returning a Command
|
48
48
|
// is appropriate.
|
49
49
|
return result;
|
@@ -4,4 +4,4 @@ import Erase from './Erase';
|
|
4
4
|
import invertCommand from './invertCommand';
|
5
5
|
import SerializableCommand from './SerializableCommand';
|
6
6
|
import uniteCommands from './uniteCommands';
|
7
|
-
export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands
|
7
|
+
export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands };
|
@@ -4,4 +4,4 @@ import Erase from './Erase.mjs';
|
|
4
4
|
import invertCommand from './invertCommand.mjs';
|
5
5
|
import SerializableCommand from './SerializableCommand.mjs';
|
6
6
|
import uniteCommands from './uniteCommands.mjs';
|
7
|
-
export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands
|
7
|
+
export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands };
|
@@ -10,7 +10,7 @@ class NonSerializableUnion extends Command {
|
|
10
10
|
}
|
11
11
|
apply(editor) {
|
12
12
|
if (this.applyChunkSize === undefined) {
|
13
|
-
const results = this.commands.map(cmd => cmd.apply(editor));
|
13
|
+
const results = this.commands.map((cmd) => cmd.apply(editor));
|
14
14
|
return waitForAll(results);
|
15
15
|
}
|
16
16
|
else {
|
@@ -21,7 +21,7 @@ class NonSerializableUnion extends Command {
|
|
21
21
|
const commands = [...this.commands];
|
22
22
|
commands.reverse();
|
23
23
|
if (this.applyChunkSize === undefined) {
|
24
|
-
const results = commands.map(cmd => cmd.unapply(editor));
|
24
|
+
const results = commands.map((cmd) => cmd.unapply(editor));
|
25
25
|
return waitForAll(results);
|
26
26
|
}
|
27
27
|
else {
|
@@ -29,7 +29,7 @@ class NonSerializableUnion extends Command {
|
|
29
29
|
}
|
30
30
|
}
|
31
31
|
onDrop(editor) {
|
32
|
-
this.commands.forEach(command => command.onDrop(editor));
|
32
|
+
this.commands.forEach((command) => command.onDrop(editor));
|
33
33
|
}
|
34
34
|
description(editor, localizationTable) {
|
35
35
|
if (this.descriptionOverride) {
|
@@ -81,7 +81,7 @@ class SerializableUnion extends SerializableCommand {
|
|
81
81
|
}
|
82
82
|
return {
|
83
83
|
applyChunkSize: this.applyChunkSize,
|
84
|
-
data: this.commands.map(command => command.serialize()),
|
84
|
+
data: this.commands.map((command) => command.serialize()),
|
85
85
|
description: this.descriptionOverride,
|
86
86
|
};
|
87
87
|
}
|
@@ -4,7 +4,7 @@ import { LineSegment2, Mat33, Path, Rect2 } from '@js-draw/math';
|
|
4
4
|
import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
|
5
5
|
import { ImageComponentLocalization } from './localization';
|
6
6
|
import Viewport from '../Viewport';
|
7
|
-
export type LoadSaveData =
|
7
|
+
export type LoadSaveData = string[] | Record<symbol, string | number>;
|
8
8
|
export type LoadSaveDataTable = Record<string, Array<LoadSaveData>>;
|
9
9
|
export type DeserializeCallback = (data: string) => AbstractComponent;
|
10
10
|
export declare enum ComponentSizingMode {
|
@@ -36,7 +36,7 @@ class AbstractComponent {
|
|
36
36
|
this.componentKind = componentKind;
|
37
37
|
// Stores data attached by a loader.
|
38
38
|
this.loadSaveData = {};
|
39
|
-
this.lastChangedTime =
|
39
|
+
this.lastChangedTime = new Date().getTime();
|
40
40
|
if (initialZIndex !== undefined) {
|
41
41
|
this.zIndex = initialZIndex;
|
42
42
|
}
|
@@ -134,7 +134,7 @@ class AbstractComponent {
|
|
134
134
|
}
|
135
135
|
// Otherwise check if it intersects one of the rectangle's edges.
|
136
136
|
const testLines = rect.getEdges();
|
137
|
-
return testLines.some(edge => this.intersects(edge));
|
137
|
+
return testLines.some((edge) => this.intersects(edge));
|
138
138
|
}
|
139
139
|
// @returns true iff this component can be selected (e.g. by the selection tool.)
|
140
140
|
isSelectable() {
|
@@ -284,7 +284,7 @@ AbstractComponent.TransformElementCommand = (_a = class extends UnresolvedSerial
|
|
284
284
|
}
|
285
285
|
this.component.applyTransformation(newTransfm);
|
286
286
|
this.component.zIndex = targetZIndex;
|
287
|
-
this.component.lastChangedTime =
|
287
|
+
this.component.lastChangedTime = new Date().getTime();
|
288
288
|
// Ensure that new components are automatically drawn above the current component.
|
289
289
|
if (targetZIndex >= AbstractComponent.zIndexCounter) {
|
290
290
|
AbstractComponent.zIndexCounter = targetZIndex + 1;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { EditorImageEventType } from '../image/EditorImage.mjs';
|
2
|
-
import { Rect2, Color4, toRoundedString, Path, PathCommandType, Vec2 } from '@js-draw/math';
|
2
|
+
import { Rect2, Color4, toRoundedString, Path, PathCommandType, Vec2, } from '@js-draw/math';
|
3
3
|
import AbstractComponent, { ComponentSizingMode } from './AbstractComponent.mjs';
|
4
|
-
import { createRestyleComponentCommand } from './RestylableComponent.mjs';
|
4
|
+
import { createRestyleComponentCommand, } from './RestylableComponent.mjs';
|
5
5
|
import Viewport from '../Viewport.mjs';
|
6
6
|
import { pathToRenderable } from '../rendering/RenderablePathSpec.mjs';
|
7
7
|
export var BackgroundType;
|
@@ -178,7 +178,7 @@ export default class BackgroundComponent extends AbstractComponent {
|
|
178
178
|
});
|
179
179
|
result.push({
|
180
180
|
kind: PathCommandType.LineTo,
|
181
|
-
point: Vec2.of(x, targetRect.y + targetRect.h)
|
181
|
+
point: Vec2.of(x, targetRect.y + targetRect.h),
|
182
182
|
});
|
183
183
|
}
|
184
184
|
return new Path(startPoint, result);
|
@@ -206,7 +206,8 @@ export default class BackgroundComponent extends AbstractComponent {
|
|
206
206
|
const clip = this.backgroundType === BackgroundType.Grid;
|
207
207
|
const contentBBox = this.getFullBoundingBox(visibleRect);
|
208
208
|
canvas.startObject(contentBBox, clip);
|
209
|
-
if (this.backgroundType === BackgroundType.SolidColor ||
|
209
|
+
if (this.backgroundType === BackgroundType.SolidColor ||
|
210
|
+
this.backgroundType === BackgroundType.Grid) {
|
210
211
|
// If the rectangle for this region contains the visible rect,
|
211
212
|
// we can fill the entire visible rectangle (which may be more efficient than
|
212
213
|
// filling the entire region for this.)
|
@@ -228,7 +229,7 @@ export default class BackgroundComponent extends AbstractComponent {
|
|
228
229
|
}
|
229
230
|
const style = {
|
230
231
|
fill: Color4.transparent,
|
231
|
-
stroke: { width: this.gridStrokeWidth, color: gridColor }
|
232
|
+
stroke: { width: this.gridStrokeWidth, color: gridColor },
|
232
233
|
};
|
233
234
|
canvas.drawPath(pathToRenderable(this.generateGridPath(visibleRect), style));
|
234
235
|
}
|
@@ -245,7 +246,7 @@ export default class BackgroundComponent extends AbstractComponent {
|
|
245
246
|
canvas.endObject(this.getLoadSaveData(), classNames);
|
246
247
|
}
|
247
248
|
intersects(lineSegment) {
|
248
|
-
return this.contentBBox.getEdges().some(edge => edge.intersects(lineSegment));
|
249
|
+
return this.contentBBox.getEdges().some((edge) => edge.intersects(lineSegment));
|
249
250
|
}
|
250
251
|
isSelectable() {
|
251
252
|
return false;
|
@@ -296,8 +297,9 @@ export default class BackgroundComponent extends AbstractComponent {
|
|
296
297
|
}
|
297
298
|
let backgroundType;
|
298
299
|
const jsonBackgroundType = json.backgroundType;
|
299
|
-
if (jsonBackgroundType === BackgroundType.None ||
|
300
|
-
|
300
|
+
if (jsonBackgroundType === BackgroundType.None ||
|
301
|
+
jsonBackgroundType === BackgroundType.Grid ||
|
302
|
+
jsonBackgroundType === BackgroundType.SolidColor) {
|
301
303
|
backgroundType = jsonBackgroundType;
|
302
304
|
}
|
303
305
|
else {
|
@@ -13,7 +13,10 @@ export default class ImageComponent extends AbstractComponent {
|
|
13
13
|
super('image-component');
|
14
14
|
this.image = {
|
15
15
|
...image,
|
16
|
-
label: image.label ??
|
16
|
+
label: image.label ??
|
17
|
+
image.image.getAttribute('alt') ??
|
18
|
+
image.image.getAttribute('aria-label') ??
|
19
|
+
undefined,
|
17
20
|
};
|
18
21
|
const isHTMLImageElem = (elem) => {
|
19
22
|
return elem.getAttribute('src') !== undefined;
|
@@ -39,8 +42,10 @@ export default class ImageComponent extends AbstractComponent {
|
|
39
42
|
static async fromImage(elem, transform) {
|
40
43
|
await waitForImageLoaded(elem);
|
41
44
|
let width, height;
|
42
|
-
if (typeof elem.width === 'number' &&
|
43
|
-
|
45
|
+
if (typeof elem.width === 'number' &&
|
46
|
+
typeof elem.height === 'number' &&
|
47
|
+
elem.width !== 0 &&
|
48
|
+
elem.height !== 0) {
|
44
49
|
width = elem.width;
|
45
50
|
height = elem.height;
|
46
51
|
}
|
@@ -86,7 +91,7 @@ export default class ImageComponent extends AbstractComponent {
|
|
86
91
|
}
|
87
92
|
intersects(lineSegment) {
|
88
93
|
const rect = this.getImageRect();
|
89
|
-
const edges = rect.getEdges().map(edge => edge.transformedBy(this.image.transform));
|
94
|
+
const edges = rect.getEdges().map((edge) => edge.transformedBy(this.image.transform));
|
90
95
|
for (const edge of edges) {
|
91
96
|
if (edge.intersects(lineSegment)) {
|
92
97
|
return true;
|
@@ -99,7 +104,9 @@ export default class ImageComponent extends AbstractComponent {
|
|
99
104
|
this.recomputeBBox();
|
100
105
|
}
|
101
106
|
description(localizationTable) {
|
102
|
-
return this.image.label
|
107
|
+
return this.image.label
|
108
|
+
? localizationTable.imageNode(this.image.label)
|
109
|
+
: localizationTable.unlabeledImageNode;
|
103
110
|
}
|
104
111
|
getAltText() {
|
105
112
|
return this.image.label;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Color4 } from '@js-draw/math';
|
2
2
|
import SerializableCommand from '../commands/SerializableCommand.mjs';
|
3
3
|
import UnresolvedSerializableCommand from '../commands/UnresolvedCommand.mjs';
|
4
|
-
import { textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle.mjs';
|
4
|
+
import { textStyleFromJSON, textStyleToJSON, } from '../rendering/TextRenderingStyle.mjs';
|
5
5
|
const serializeComponentStyle = (style) => {
|
6
6
|
const result = {};
|
7
7
|
if (style.color) {
|
@@ -73,7 +73,7 @@ class DefaultRestyleComponentCommand extends UnresolvedSerializableCommand {
|
|
73
73
|
const newStyle = deserializeComponentStyle(json.newStyle);
|
74
74
|
const id = json.id;
|
75
75
|
if (typeof json.id !== 'string') {
|
76
|
-
throw new Error(`json.id is of type ${
|
76
|
+
throw new Error(`json.id is of type ${typeof json.id}, not string.`);
|
77
77
|
}
|
78
78
|
return new DefaultRestyleComponentCommand(origStyle, newStyle, id);
|
79
79
|
});
|