js-draw 1.20.3 → 1.21.1
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +1 -1
- package/dist/Editor.css +134 -26
- package/dist/bundle.js +2 -2
- package/dist/bundledStyles.js +1 -1
- package/dist/cjs/Editor.d.ts +27 -6
- package/dist/cjs/Editor.js +30 -8
- package/dist/cjs/SVGLoader/SVGLoader.js +2 -2
- package/dist/cjs/Viewport.d.ts +2 -2
- package/dist/cjs/commands/Command.d.ts +5 -0
- package/dist/cjs/commands/Command.js +5 -0
- package/dist/cjs/commands/SerializableCommand.d.ts +7 -0
- package/dist/cjs/commands/SerializableCommand.js +9 -0
- package/dist/cjs/dialogs/makeAboutDialog.d.ts +1 -1
- package/dist/cjs/dialogs/makeAboutDialog.js +10 -25
- package/dist/cjs/dialogs/makeMessageDialog.d.ts +11 -0
- package/dist/cjs/dialogs/makeMessageDialog.js +56 -0
- package/dist/cjs/image/EditorImage.d.ts +15 -1
- package/dist/cjs/image/EditorImage.js +15 -5
- package/dist/cjs/inputEvents.d.ts +10 -2
- package/dist/cjs/inputEvents.js +1 -0
- package/dist/cjs/localizations/es.js +3 -0
- package/dist/cjs/rendering/Display.d.ts +1 -0
- package/dist/cjs/rendering/Display.js +1 -0
- package/dist/cjs/rendering/TextRenderingStyle.d.ts +7 -6
- package/dist/cjs/rendering/TextRenderingStyle.js +1 -0
- package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +12 -3
- package/dist/cjs/rendering/renderers/CanvasRenderer.js +15 -2
- package/dist/cjs/rendering/renderers/DummyRenderer.d.ts +1 -1
- package/dist/cjs/testing/firstElementAncestorOfNode.d.ts +1 -1
- package/dist/cjs/testing/firstElementAncestorOfNode.js +1 -1
- package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/cjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/cjs/toolbar/AbstractToolbar.d.ts +6 -1
- package/dist/cjs/toolbar/AbstractToolbar.js +6 -1
- package/dist/cjs/toolbar/IconProvider.d.ts +1 -1
- package/dist/cjs/toolbar/IconProvider.js +6 -1
- package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +8 -0
- package/dist/cjs/toolbar/widgets/BaseWidget.js +8 -0
- package/dist/cjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/cjs/toolbar/widgets/HandToolWidget.js +1 -0
- package/dist/cjs/toolbar/widgets/PenToolWidget.d.ts +6 -0
- package/dist/cjs/toolbar/widgets/PenToolWidget.js +5 -0
- package/dist/cjs/types.d.ts +5 -0
- package/dist/cjs/types.js +1 -0
- package/dist/cjs/util/ClipboardHandler.d.ts +9 -1
- package/dist/cjs/util/ClipboardHandler.js +82 -24
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/Editor.d.ts +27 -6
- package/dist/mjs/Editor.mjs +31 -9
- package/dist/mjs/SVGLoader/SVGLoader.mjs +2 -2
- package/dist/mjs/Viewport.d.ts +2 -2
- package/dist/mjs/commands/Command.d.ts +5 -0
- package/dist/mjs/commands/Command.mjs +5 -0
- package/dist/mjs/commands/SerializableCommand.d.ts +7 -0
- package/dist/mjs/commands/SerializableCommand.mjs +9 -0
- package/dist/mjs/dialogs/makeAboutDialog.d.ts +1 -1
- package/dist/mjs/dialogs/makeAboutDialog.mjs +7 -25
- package/dist/mjs/dialogs/makeMessageDialog.d.ts +11 -0
- package/dist/mjs/dialogs/makeMessageDialog.mjs +51 -0
- package/dist/mjs/image/EditorImage.d.ts +15 -1
- package/dist/mjs/image/EditorImage.mjs +15 -5
- package/dist/mjs/inputEvents.d.ts +10 -2
- package/dist/mjs/inputEvents.mjs +1 -0
- package/dist/mjs/localizations/es.mjs +3 -0
- package/dist/mjs/rendering/Display.d.ts +1 -0
- package/dist/mjs/rendering/Display.mjs +1 -0
- package/dist/mjs/rendering/TextRenderingStyle.d.ts +7 -6
- package/dist/mjs/rendering/TextRenderingStyle.mjs +1 -0
- package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +12 -3
- package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +15 -2
- package/dist/mjs/rendering/renderers/DummyRenderer.d.ts +1 -1
- package/dist/mjs/testing/firstElementAncestorOfNode.d.ts +1 -1
- package/dist/mjs/testing/firstElementAncestorOfNode.mjs +1 -1
- package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
- package/dist/mjs/testing/sendTouchEvent.d.ts +2 -2
- package/dist/mjs/toolbar/AbstractToolbar.d.ts +6 -1
- package/dist/mjs/toolbar/AbstractToolbar.mjs +6 -1
- package/dist/mjs/toolbar/IconProvider.d.ts +1 -1
- package/dist/mjs/toolbar/IconProvider.mjs +6 -1
- package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +8 -0
- package/dist/mjs/toolbar/widgets/BaseWidget.mjs +8 -0
- package/dist/mjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
- package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +1 -0
- package/dist/mjs/toolbar/widgets/PenToolWidget.d.ts +6 -0
- package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +5 -0
- package/dist/mjs/types.d.ts +5 -0
- package/dist/mjs/types.mjs +1 -0
- package/dist/mjs/util/ClipboardHandler.d.ts +9 -1
- package/dist/mjs/util/ClipboardHandler.mjs +82 -24
- package/dist/mjs/version.mjs +1 -1
- package/package.json +8 -9
- package/src/dialogs/dialogs.scss +9 -21
- package/src/dialogs/makeAboutDialog.scss +13 -33
- package/src/dialogs/makeMessageDialog.scss +46 -0
- package/dist/cjs/tools/BaseTool.d.ts +0 -60
- package/dist/cjs/tools/BaseTool.js +0 -174
- package/dist/cjs/tools/Eraser.d.ts +0 -56
- package/dist/cjs/tools/Eraser.js +0 -295
- package/dist/cjs/tools/Eraser.test.d.ts +0 -1
- package/dist/cjs/tools/FindTool.d.ts +0 -21
- package/dist/cjs/tools/FindTool.js +0 -137
- package/dist/cjs/tools/FindTool.test.d.ts +0 -1
- package/dist/cjs/tools/InputFilter/FunctionMapper.d.ts +0 -12
- package/dist/cjs/tools/InputFilter/FunctionMapper.js +0 -21
- package/dist/cjs/tools/InputFilter/InputMapper.d.ts +0 -23
- package/dist/cjs/tools/InputFilter/InputMapper.js +0 -38
- package/dist/cjs/tools/InputFilter/InputPipeline.d.ts +0 -15
- package/dist/cjs/tools/InputFilter/InputPipeline.js +0 -54
- package/dist/cjs/tools/InputFilter/InputPipeline.test.d.ts +0 -1
- package/dist/cjs/tools/InputFilter/InputStabilizer.d.ts +0 -29
- package/dist/cjs/tools/InputFilter/InputStabilizer.js +0 -181
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +0 -21
- package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +0 -84
- package/dist/cjs/tools/PanZoom.d.ts +0 -119
- package/dist/cjs/tools/PanZoom.js +0 -508
- package/dist/cjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/cjs/tools/PasteHandler.d.ts +0 -23
- package/dist/cjs/tools/PasteHandler.js +0 -109
- package/dist/cjs/tools/Pen.d.ts +0 -53
- package/dist/cjs/tools/Pen.js +0 -318
- package/dist/cjs/tools/Pen.test.d.ts +0 -1
- package/dist/cjs/tools/PipetteTool.d.ts +0 -28
- package/dist/cjs/tools/PipetteTool.js +0 -69
- package/dist/cjs/tools/ScrollbarTool.d.ts +0 -18
- package/dist/cjs/tools/ScrollbarTool.js +0 -85
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -9
- package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +0 -32
- package/dist/cjs/tools/SelectionTool/Selection.d.ts +0 -71
- package/dist/cjs/tools/SelectionTool/Selection.js +0 -620
- package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +0 -62
- package/dist/cjs/tools/SelectionTool/SelectionHandle.js +0 -141
- package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +0 -40
- package/dist/cjs/tools/SelectionTool/SelectionTool.js +0 -494
- package/dist/cjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +0 -1
- package/dist/cjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +0 -23
- package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +0 -83
- package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +0 -42
- package/dist/cjs/tools/SelectionTool/TransformMode.js +0 -155
- package/dist/cjs/tools/SelectionTool/types.d.ts +0 -28
- package/dist/cjs/tools/SelectionTool/types.js +0 -14
- package/dist/cjs/tools/SoundUITool.d.ts +0 -26
- package/dist/cjs/tools/SoundUITool.js +0 -171
- package/dist/cjs/tools/TextTool.d.ts +0 -36
- package/dist/cjs/tools/TextTool.js +0 -285
- package/dist/cjs/tools/TextTool.test.d.ts +0 -1
- package/dist/cjs/tools/ToolController.d.ts +0 -73
- package/dist/cjs/tools/ToolController.js +0 -304
- package/dist/cjs/tools/ToolController.test.d.ts +0 -1
- package/dist/cjs/tools/ToolEnabledGroup.d.ts +0 -6
- package/dist/cjs/tools/ToolEnabledGroup.js +0 -13
- package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +0 -16
- package/dist/cjs/tools/ToolSwitcherShortcut.js +0 -40
- package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +0 -12
- package/dist/cjs/tools/ToolbarShortcutHandler.js +0 -34
- package/dist/cjs/tools/UndoRedoShortcut.d.ts +0 -8
- package/dist/cjs/tools/UndoRedoShortcut.js +0 -27
- package/dist/cjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist/cjs/tools/keybindings.d.ts +0 -18
- package/dist/cjs/tools/keybindings.js +0 -49
- package/dist/cjs/tools/lib.d.ts +0 -14
- package/dist/cjs/tools/lib.js +0 -36
- package/dist/cjs/tools/localization.d.ts +0 -34
- package/dist/cjs/tools/localization.js +0 -36
- package/dist/cjs/tools/util/StationaryPenDetector.d.ts +0 -22
- package/dist/cjs/tools/util/StationaryPenDetector.js +0 -95
- package/dist/mjs/tools/BaseTool.d.ts +0 -60
- package/dist/mjs/tools/BaseTool.mjs +0 -172
- package/dist/mjs/tools/Eraser.d.ts +0 -56
- package/dist/mjs/tools/Eraser.mjs +0 -288
- package/dist/mjs/tools/Eraser.test.d.ts +0 -1
- package/dist/mjs/tools/FindTool.d.ts +0 -21
- package/dist/mjs/tools/FindTool.mjs +0 -131
- package/dist/mjs/tools/FindTool.test.d.ts +0 -1
- package/dist/mjs/tools/InputFilter/FunctionMapper.d.ts +0 -12
- package/dist/mjs/tools/InputFilter/FunctionMapper.mjs +0 -15
- package/dist/mjs/tools/InputFilter/InputMapper.d.ts +0 -23
- package/dist/mjs/tools/InputFilter/InputMapper.mjs +0 -36
- package/dist/mjs/tools/InputFilter/InputPipeline.d.ts +0 -15
- package/dist/mjs/tools/InputFilter/InputPipeline.mjs +0 -49
- package/dist/mjs/tools/InputFilter/InputPipeline.test.d.ts +0 -1
- package/dist/mjs/tools/InputFilter/InputStabilizer.d.ts +0 -29
- package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +0 -175
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +0 -21
- package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +0 -78
- package/dist/mjs/tools/PanZoom.d.ts +0 -119
- package/dist/mjs/tools/PanZoom.mjs +0 -501
- package/dist/mjs/tools/PanZoom.test.d.ts +0 -1
- package/dist/mjs/tools/PasteHandler.d.ts +0 -23
- package/dist/mjs/tools/PasteHandler.mjs +0 -103
- package/dist/mjs/tools/Pen.d.ts +0 -53
- package/dist/mjs/tools/Pen.mjs +0 -312
- package/dist/mjs/tools/Pen.test.d.ts +0 -1
- package/dist/mjs/tools/PipetteTool.d.ts +0 -28
- package/dist/mjs/tools/PipetteTool.mjs +0 -63
- package/dist/mjs/tools/ScrollbarTool.d.ts +0 -18
- package/dist/mjs/tools/ScrollbarTool.mjs +0 -79
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -9
- package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +0 -26
- package/dist/mjs/tools/SelectionTool/Selection.d.ts +0 -71
- package/dist/mjs/tools/SelectionTool/Selection.mjs +0 -592
- package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +0 -62
- package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +0 -137
- package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +0 -40
- package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +0 -488
- package/dist/mjs/tools/SelectionTool/SelectionTool.selecting.test.d.ts +0 -1
- package/dist/mjs/tools/SelectionTool/SelectionTool.test.d.ts +0 -1
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.d.ts +0 -23
- package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +0 -77
- package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +0 -42
- package/dist/mjs/tools/SelectionTool/TransformMode.mjs +0 -146
- package/dist/mjs/tools/SelectionTool/types.d.ts +0 -28
- package/dist/mjs/tools/SelectionTool/types.mjs +0 -11
- package/dist/mjs/tools/SoundUITool.d.ts +0 -26
- package/dist/mjs/tools/SoundUITool.mjs +0 -165
- package/dist/mjs/tools/TextTool.d.ts +0 -36
- package/dist/mjs/tools/TextTool.mjs +0 -279
- package/dist/mjs/tools/TextTool.test.d.ts +0 -1
- package/dist/mjs/tools/ToolController.d.ts +0 -73
- package/dist/mjs/tools/ToolController.mjs +0 -275
- package/dist/mjs/tools/ToolController.test.d.ts +0 -1
- package/dist/mjs/tools/ToolEnabledGroup.d.ts +0 -6
- package/dist/mjs/tools/ToolEnabledGroup.mjs +0 -10
- package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +0 -16
- package/dist/mjs/tools/ToolSwitcherShortcut.mjs +0 -34
- package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +0 -12
- package/dist/mjs/tools/ToolbarShortcutHandler.mjs +0 -28
- package/dist/mjs/tools/UndoRedoShortcut.d.ts +0 -8
- package/dist/mjs/tools/UndoRedoShortcut.mjs +0 -21
- package/dist/mjs/tools/UndoRedoShortcut.test.d.ts +0 -1
- package/dist/mjs/tools/keybindings.d.ts +0 -18
- package/dist/mjs/tools/keybindings.mjs +0 -43
- package/dist/mjs/tools/lib.d.ts +0 -14
- package/dist/mjs/tools/lib.mjs +0 -14
- package/dist/mjs/tools/localization.d.ts +0 -34
- package/dist/mjs/tools/localization.mjs +0 -33
- package/dist/mjs/tools/util/StationaryPenDetector.d.ts +0 -22
- package/dist/mjs/tools/util/StationaryPenDetector.mjs +0 -92
- package/src/tools/FindTool.css +0 -7
- package/src/tools/ScrollbarTool.scss +0 -57
- package/src/tools/SelectionTool/SelectionTool.scss +0 -137
- package/src/tools/SoundUITool.scss +0 -22
- package/src/tools/tools.scss +0 -5
@@ -1,592 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @internal
|
3
|
-
* @packageDocumentation
|
4
|
-
*/
|
5
|
-
var _a;
|
6
|
-
import SerializableCommand from '../../commands/SerializableCommand.mjs';
|
7
|
-
import { Mat33, Rect2, Vec2 } from '@js-draw/math';
|
8
|
-
import SelectionHandle, { HandleAction, handleSize } from './SelectionHandle.mjs';
|
9
|
-
import { cssPrefix } from './SelectionTool.mjs';
|
10
|
-
import Viewport from '../../Viewport.mjs';
|
11
|
-
import Erase from '../../commands/Erase.mjs';
|
12
|
-
import Duplicate from '../../commands/Duplicate.mjs';
|
13
|
-
import { DragTransformer, ResizeTransformer, RotateTransformer } from './TransformMode.mjs';
|
14
|
-
import { ResizeMode } from './types.mjs';
|
15
|
-
import EditorImage from '../../image/EditorImage.mjs';
|
16
|
-
import uniteCommands from '../../commands/uniteCommands.mjs';
|
17
|
-
const updateChunkSize = 100;
|
18
|
-
const maxPreviewElemCount = 500;
|
19
|
-
// @internal
|
20
|
-
class Selection {
|
21
|
-
constructor(startPoint, editor) {
|
22
|
-
this.editor = editor;
|
23
|
-
// The last-computed bounding box of selected content
|
24
|
-
// @see getTightBoundingBox
|
25
|
-
this.selectionTightBoundingBox = null;
|
26
|
-
this.transform = Mat33.identity;
|
27
|
-
// invariant: sorted by increasing z-index
|
28
|
-
this.selectedElems = [];
|
29
|
-
this.hasParent = true;
|
30
|
-
// Maps IDs to whether we removed the component from the image
|
31
|
-
this.removedFromImage = {};
|
32
|
-
this.activeHandle = null;
|
33
|
-
this.backgroundDragging = false;
|
34
|
-
this.selectionDuplicatedAnimationTimeout = null;
|
35
|
-
this.originalRegion = new Rect2(startPoint.x, startPoint.y, 0, 0);
|
36
|
-
this.transformers = {
|
37
|
-
drag: new DragTransformer(editor, this),
|
38
|
-
resize: new ResizeTransformer(editor, this),
|
39
|
-
rotate: new RotateTransformer(editor, this),
|
40
|
-
};
|
41
|
-
// We need two containers for some CSS to apply (the outer container
|
42
|
-
// needs zero height, the inner needs to prevent the selection background
|
43
|
-
// from being visible outside of the editor).
|
44
|
-
this.outerContainer = document.createElement('div');
|
45
|
-
this.outerContainer.classList.add(`${cssPrefix}selection-outer-container`);
|
46
|
-
this.innerContainer = document.createElement('div');
|
47
|
-
this.innerContainer.classList.add(`${cssPrefix}selection-inner-container`);
|
48
|
-
this.backgroundElem = document.createElement('div');
|
49
|
-
this.backgroundElem.classList.add(`${cssPrefix}selection-background`);
|
50
|
-
this.innerContainer.appendChild(this.backgroundElem);
|
51
|
-
this.outerContainer.appendChild(this.innerContainer);
|
52
|
-
const makeResizeHandle = (mode, side) => {
|
53
|
-
const modeToAction = {
|
54
|
-
[ResizeMode.Both]: HandleAction.ResizeXY,
|
55
|
-
[ResizeMode.HorizontalOnly]: HandleAction.ResizeX,
|
56
|
-
[ResizeMode.VerticalOnly]: HandleAction.ResizeY,
|
57
|
-
};
|
58
|
-
return new SelectionHandle({
|
59
|
-
action: modeToAction[mode],
|
60
|
-
side,
|
61
|
-
}, this, this.editor.viewport, (startPoint) => this.transformers.resize.onDragStart(startPoint, mode), (currentPoint) => this.transformers.resize.onDragUpdate(currentPoint), () => this.transformers.resize.onDragEnd());
|
62
|
-
};
|
63
|
-
const resizeHorizontalHandles = [
|
64
|
-
makeResizeHandle(ResizeMode.HorizontalOnly, Vec2.of(0, 0.5)),
|
65
|
-
makeResizeHandle(ResizeMode.HorizontalOnly, Vec2.of(1, 0.5)),
|
66
|
-
];
|
67
|
-
const resizeVerticalHandle = makeResizeHandle(ResizeMode.VerticalOnly, Vec2.of(0.5, 1));
|
68
|
-
const resizeBothHandle = makeResizeHandle(ResizeMode.Both, Vec2.of(1, 1));
|
69
|
-
const rotationHandle = new SelectionHandle({
|
70
|
-
action: HandleAction.Rotate,
|
71
|
-
side: Vec2.of(0.5, 0),
|
72
|
-
icon: this.editor.icons.makeRotateIcon(),
|
73
|
-
}, this, this.editor.viewport, (startPoint) => this.transformers.rotate.onDragStart(startPoint), (currentPoint) => this.transformers.rotate.onDragUpdate(currentPoint), () => this.transformers.rotate.onDragEnd());
|
74
|
-
this.childwidgets = [
|
75
|
-
resizeBothHandle,
|
76
|
-
...resizeHorizontalHandles,
|
77
|
-
resizeVerticalHandle,
|
78
|
-
rotationHandle,
|
79
|
-
];
|
80
|
-
for (const widget of this.childwidgets) {
|
81
|
-
widget.addTo(this.backgroundElem);
|
82
|
-
}
|
83
|
-
this.updateUI();
|
84
|
-
}
|
85
|
-
// @internal Intended for unit tests
|
86
|
-
getBackgroundElem() {
|
87
|
-
return this.backgroundElem;
|
88
|
-
}
|
89
|
-
getTransform() {
|
90
|
-
return this.transform;
|
91
|
-
}
|
92
|
-
get preTransformRegion() {
|
93
|
-
return this.originalRegion;
|
94
|
-
}
|
95
|
-
get region() {
|
96
|
-
// TODO: This currently assumes that the region rotates about its center.
|
97
|
-
// This may not be true.
|
98
|
-
const rotationMatrix = Mat33.zRotation(this.regionRotation, this.originalRegion.center);
|
99
|
-
const scaleAndTranslateMat = this.transform.rightMul(rotationMatrix.inverse());
|
100
|
-
return this.originalRegion.transformedBoundingBox(scaleAndTranslateMat);
|
101
|
-
}
|
102
|
-
/**
|
103
|
-
* Computes and returns the bounding box of the selection without
|
104
|
-
* any additional padding. Computes directly from the elements that are selected.
|
105
|
-
* @internal
|
106
|
-
*/
|
107
|
-
computeTightBoundingBox() {
|
108
|
-
const bbox = this.selectedElems.reduce((accumulator, elem) => {
|
109
|
-
return (accumulator ?? elem.getBBox()).union(elem.getBBox());
|
110
|
-
}, null);
|
111
|
-
return bbox ?? Rect2.empty;
|
112
|
-
}
|
113
|
-
get regionRotation() {
|
114
|
-
return this.transform.transformVec3(Vec2.unitX).angle();
|
115
|
-
}
|
116
|
-
get preTransformedScreenRegion() {
|
117
|
-
const toScreen = (vec) => this.editor.viewport.canvasToScreen(vec);
|
118
|
-
return Rect2.fromCorners(toScreen(this.preTransformRegion.topLeft), toScreen(this.preTransformRegion.bottomRight));
|
119
|
-
}
|
120
|
-
get preTransformedScreenRegionRotation() {
|
121
|
-
return this.editor.viewport.getRotationAngle();
|
122
|
-
}
|
123
|
-
getScreenRegion() {
|
124
|
-
const toScreen = this.editor.viewport.canvasToScreenTransform;
|
125
|
-
const scaleFactor = this.editor.viewport.getScaleFactor();
|
126
|
-
const screenCenter = toScreen.transformVec2(this.region.center);
|
127
|
-
return new Rect2(screenCenter.x, screenCenter.y, scaleFactor * this.region.width, scaleFactor * this.region.height).translatedBy(this.region.size.times(-scaleFactor / 2));
|
128
|
-
}
|
129
|
-
get screenRegionRotation() {
|
130
|
-
return this.regionRotation + this.editor.viewport.getRotationAngle();
|
131
|
-
}
|
132
|
-
// Applies, previews, but doesn't finalize the given transformation.
|
133
|
-
setTransform(transform, preview = true) {
|
134
|
-
this.transform = transform;
|
135
|
-
if (preview && this.hasParent) {
|
136
|
-
this.previewTransformCmds();
|
137
|
-
}
|
138
|
-
}
|
139
|
-
getDeltaZIndexToMoveSelectionToTop() {
|
140
|
-
if (this.selectedElems.length === 0) {
|
141
|
-
return 0;
|
142
|
-
}
|
143
|
-
const selectedBottommostZIndex = this.selectedElems[0].getZIndex();
|
144
|
-
const visibleObjects = this.editor.image.getElementsIntersectingRegion(this.region);
|
145
|
-
const topMostVisibleZIndex = visibleObjects[visibleObjects.length - 1]?.getZIndex() ?? selectedBottommostZIndex;
|
146
|
-
const deltaZIndex = (topMostVisibleZIndex + 1) - selectedBottommostZIndex;
|
147
|
-
return deltaZIndex;
|
148
|
-
}
|
149
|
-
// Applies the current transformation to the selection
|
150
|
-
finalizeTransform() {
|
151
|
-
const fullTransform = this.transform;
|
152
|
-
const selectedElems = this.selectedElems;
|
153
|
-
// Reset for the next drag
|
154
|
-
this.originalRegion = this.originalRegion.transformedBoundingBox(this.transform);
|
155
|
-
this.transform = Mat33.identity;
|
156
|
-
this.scrollTo();
|
157
|
-
let transformPromise = undefined;
|
158
|
-
// Make the commands undo-able.
|
159
|
-
// Don't check for non-empty transforms because this breaks changing the
|
160
|
-
// z-index of the just-transformed commands.
|
161
|
-
if (this.selectedElems.length > 0) {
|
162
|
-
const deltaZIndex = this.getDeltaZIndexToMoveSelectionToTop();
|
163
|
-
transformPromise = this.editor.dispatch(new _a.ApplyTransformationCommand(this, selectedElems, fullTransform, deltaZIndex));
|
164
|
-
}
|
165
|
-
// Clear renderings of any in-progress transformations
|
166
|
-
const wetInkRenderer = this.editor.display.getWetInkRenderer();
|
167
|
-
wetInkRenderer.clear();
|
168
|
-
return transformPromise;
|
169
|
-
}
|
170
|
-
/** Sends all selected elements to the bottom of the visible image. */
|
171
|
-
sendToBack() {
|
172
|
-
const visibleObjects = this.editor.image.getElementsIntersectingRegion(this.editor.viewport.visibleRect);
|
173
|
-
// VisibleObjects and selectedElems should both be sorted by z-index
|
174
|
-
const lowestVisibleZIndex = visibleObjects[0]?.getZIndex() ?? 0;
|
175
|
-
const highestSelectedZIndex = this.selectedElems[this.selectedElems.length - 1]?.getZIndex() ?? 0;
|
176
|
-
const targetHighestZIndex = lowestVisibleZIndex - 1;
|
177
|
-
const deltaZIndex = targetHighestZIndex - highestSelectedZIndex;
|
178
|
-
if (deltaZIndex !== 0) {
|
179
|
-
const commands = this.selectedElems.map(elem => {
|
180
|
-
return elem.setZIndex(elem.getZIndex() + deltaZIndex);
|
181
|
-
});
|
182
|
-
return uniteCommands(commands, updateChunkSize);
|
183
|
-
}
|
184
|
-
return null;
|
185
|
-
}
|
186
|
-
// Preview the effects of the current transformation on the selection
|
187
|
-
previewTransformCmds() {
|
188
|
-
if (this.selectedElems.length === 0) {
|
189
|
-
return;
|
190
|
-
}
|
191
|
-
// Don't render what we're moving if it's likely to be slow.
|
192
|
-
if (this.selectedElems.length > maxPreviewElemCount) {
|
193
|
-
this.updateUI();
|
194
|
-
return;
|
195
|
-
}
|
196
|
-
const wetInkRenderer = this.editor.display.getWetInkRenderer();
|
197
|
-
wetInkRenderer.clear();
|
198
|
-
wetInkRenderer.pushTransform(this.transform);
|
199
|
-
const viewportVisibleRect = this.editor.viewport.visibleRect.union(this.region);
|
200
|
-
const visibleRect = viewportVisibleRect.transformedBoundingBox(this.transform.inverse());
|
201
|
-
for (const elem of this.selectedElems) {
|
202
|
-
elem.render(wetInkRenderer, visibleRect);
|
203
|
-
}
|
204
|
-
wetInkRenderer.popTransform();
|
205
|
-
this.updateUI();
|
206
|
-
}
|
207
|
-
// Find the objects corresponding to this in the document,
|
208
|
-
// select them.
|
209
|
-
// Returns false iff nothing was selected.
|
210
|
-
resolveToObjects() {
|
211
|
-
let singleItemSelectionMode = false;
|
212
|
-
this.transform = Mat33.identity;
|
213
|
-
// Grow the rectangle, if necessary
|
214
|
-
if (this.region.w === 0 || this.region.h === 0) {
|
215
|
-
const padding = this.editor.viewport.visibleRect.maxDimension / 200;
|
216
|
-
this.originalRegion = Rect2.bboxOf(this.region.corners, padding);
|
217
|
-
// Only select one item if the rectangle was very small.
|
218
|
-
singleItemSelectionMode = true;
|
219
|
-
}
|
220
|
-
this.selectedElems = this.editor.image.getElementsIntersectingRegion(this.region).filter(elem => {
|
221
|
-
return elem.intersectsRect(this.region) && elem.isSelectable();
|
222
|
-
});
|
223
|
-
if (singleItemSelectionMode && this.selectedElems.length > 0) {
|
224
|
-
this.selectedElems = [this.selectedElems[this.selectedElems.length - 1]];
|
225
|
-
}
|
226
|
-
// Find the bounding box of all selected elements.
|
227
|
-
if (!this.recomputeRegion()) {
|
228
|
-
return false;
|
229
|
-
}
|
230
|
-
this.updateUI();
|
231
|
-
return true;
|
232
|
-
}
|
233
|
-
// Recompute this' region from the selected elements.
|
234
|
-
// Returns false if the selection is empty.
|
235
|
-
recomputeRegion() {
|
236
|
-
const newRegion = this.computeTightBoundingBox();
|
237
|
-
this.selectionTightBoundingBox = newRegion;
|
238
|
-
if (!newRegion) {
|
239
|
-
this.cancelSelection();
|
240
|
-
return false;
|
241
|
-
}
|
242
|
-
this.originalRegion = newRegion;
|
243
|
-
this.padRegion();
|
244
|
-
return true;
|
245
|
-
}
|
246
|
-
// Applies padding to the current region if it is too small.
|
247
|
-
// @internal
|
248
|
-
padRegion() {
|
249
|
-
const sourceRegion = this.selectionTightBoundingBox ?? this.originalRegion;
|
250
|
-
const minSize = this.getMinCanvasSize();
|
251
|
-
if (sourceRegion.w < minSize || sourceRegion.h < minSize) {
|
252
|
-
// Add padding
|
253
|
-
const padding = minSize / 2;
|
254
|
-
this.originalRegion = Rect2.bboxOf(sourceRegion.corners, padding);
|
255
|
-
this.updateUI();
|
256
|
-
}
|
257
|
-
}
|
258
|
-
getMinCanvasSize() {
|
259
|
-
const canvasHandleSize = handleSize / this.editor.viewport.getScaleFactor();
|
260
|
-
return canvasHandleSize * 2;
|
261
|
-
}
|
262
|
-
getSelectedItemCount() {
|
263
|
-
return this.selectedElems.length;
|
264
|
-
}
|
265
|
-
// @internal
|
266
|
-
updateUI() {
|
267
|
-
// Don't update old selections.
|
268
|
-
if (!this.hasParent) {
|
269
|
-
return;
|
270
|
-
}
|
271
|
-
const screenRegion = this.getScreenRegion();
|
272
|
-
// marginLeft, marginTop: Display relative to the top left of the selection overlay.
|
273
|
-
// left, top don't work for this.
|
274
|
-
this.backgroundElem.style.marginLeft = `${screenRegion.topLeft.x}px`;
|
275
|
-
this.backgroundElem.style.marginTop = `${screenRegion.topLeft.y}px`;
|
276
|
-
this.backgroundElem.style.width = `${screenRegion.width}px`;
|
277
|
-
this.backgroundElem.style.height = `${screenRegion.height}px`;
|
278
|
-
const rotationDeg = this.screenRegionRotation * 180 / Math.PI;
|
279
|
-
this.backgroundElem.style.transform = `rotate(${rotationDeg}deg)`;
|
280
|
-
this.backgroundElem.style.transformOrigin = 'center';
|
281
|
-
// If closer to perpendicular, apply different CSS
|
282
|
-
const perpendicularClassName = `${cssPrefix}rotated-near-perpendicular`;
|
283
|
-
if (Math.abs(Math.sin(this.screenRegionRotation)) > 0.5) {
|
284
|
-
this.innerContainer.classList.add(perpendicularClassName);
|
285
|
-
}
|
286
|
-
else {
|
287
|
-
this.innerContainer.classList.remove(perpendicularClassName);
|
288
|
-
}
|
289
|
-
// Hide handles when empty
|
290
|
-
if (screenRegion.width === 0 && screenRegion.height === 0) {
|
291
|
-
this.innerContainer.classList.add('-empty');
|
292
|
-
}
|
293
|
-
else {
|
294
|
-
this.innerContainer.classList.remove('-empty');
|
295
|
-
}
|
296
|
-
for (const widget of this.childwidgets) {
|
297
|
-
widget.updatePosition(this.getScreenRegion());
|
298
|
-
}
|
299
|
-
}
|
300
|
-
// Add/remove the contents of this seleciton from the editor.
|
301
|
-
// Used to prevent previewed content from looking like duplicate content
|
302
|
-
// while dragging.
|
303
|
-
//
|
304
|
-
// Does nothing if a large number of elements are selected (and so modifying
|
305
|
-
// the editor image is likely to be slow.)
|
306
|
-
//
|
307
|
-
// If removed from the image, selected elements are drawn as wet ink.
|
308
|
-
//
|
309
|
-
// [inImage] should be `true` if the selected elements should be added to the
|
310
|
-
// main image, `false` if they should be removed.
|
311
|
-
addRemoveSelectionFromImage(inImage) {
|
312
|
-
// Don't hide elements if doing so will be slow.
|
313
|
-
if (!inImage && this.selectedElems.length > maxPreviewElemCount) {
|
314
|
-
return;
|
315
|
-
}
|
316
|
-
for (const elem of this.selectedElems) {
|
317
|
-
const parent = this.editor.image.findParent(elem);
|
318
|
-
if (!inImage && parent) {
|
319
|
-
this.removedFromImage[elem.getId()] = true;
|
320
|
-
parent.remove();
|
321
|
-
}
|
322
|
-
// If we're making things visible and the selected object wasn't previously
|
323
|
-
// visible,
|
324
|
-
else if (!parent && this.removedFromImage[elem.getId()]) {
|
325
|
-
EditorImage.addElement(elem).apply(this.editor);
|
326
|
-
this.removedFromImage[elem.getId()] = false;
|
327
|
-
delete this.removedFromImage[elem.getId()];
|
328
|
-
}
|
329
|
-
}
|
330
|
-
// Don't await queueRerender. If we're running in a test, the re-render might never
|
331
|
-
// happen.
|
332
|
-
this.editor.queueRerender().then(() => {
|
333
|
-
if (!inImage) {
|
334
|
-
this.previewTransformCmds();
|
335
|
-
}
|
336
|
-
});
|
337
|
-
}
|
338
|
-
removeDeletedElemsFromSelection() {
|
339
|
-
// Remove any deleted elements from the selection.
|
340
|
-
this.selectedElems = this.selectedElems.filter(elem => {
|
341
|
-
const hasParent = !!this.editor.image.findParent(elem);
|
342
|
-
// If we removed the element and haven't added it back yet, don't remove it
|
343
|
-
// from the selection.
|
344
|
-
const weRemoved = this.removedFromImage[elem.getId()];
|
345
|
-
return hasParent || weRemoved;
|
346
|
-
});
|
347
|
-
}
|
348
|
-
onDragStart(pointer) {
|
349
|
-
// Clear the HTML selection (prevent HTML drag and drop being triggered by this drag)
|
350
|
-
document.getSelection()?.removeAllRanges();
|
351
|
-
this.activeHandle = null;
|
352
|
-
let result = false;
|
353
|
-
this.backgroundDragging = false;
|
354
|
-
if (this.region.containsPoint(pointer.canvasPos)) {
|
355
|
-
this.backgroundDragging = true;
|
356
|
-
result = true;
|
357
|
-
}
|
358
|
-
for (const widget of this.childwidgets) {
|
359
|
-
if (widget.containsPoint(pointer.canvasPos)) {
|
360
|
-
this.activeHandle = widget;
|
361
|
-
this.backgroundDragging = false;
|
362
|
-
result = true;
|
363
|
-
}
|
364
|
-
}
|
365
|
-
if (result) {
|
366
|
-
this.removeDeletedElemsFromSelection();
|
367
|
-
this.addRemoveSelectionFromImage(false);
|
368
|
-
}
|
369
|
-
if (this.activeHandle) {
|
370
|
-
this.activeHandle.handleDragStart(pointer);
|
371
|
-
}
|
372
|
-
if (this.backgroundDragging) {
|
373
|
-
this.transformers.drag.onDragStart(pointer.canvasPos);
|
374
|
-
}
|
375
|
-
return result;
|
376
|
-
}
|
377
|
-
onDragUpdate(pointer) {
|
378
|
-
if (this.backgroundDragging) {
|
379
|
-
this.transformers.drag.onDragUpdate(pointer.canvasPos);
|
380
|
-
}
|
381
|
-
if (this.activeHandle) {
|
382
|
-
this.activeHandle.handleDragUpdate(pointer);
|
383
|
-
}
|
384
|
-
}
|
385
|
-
onDragEnd() {
|
386
|
-
if (this.backgroundDragging) {
|
387
|
-
this.transformers.drag.onDragEnd();
|
388
|
-
}
|
389
|
-
else if (this.activeHandle) {
|
390
|
-
this.activeHandle.handleDragEnd();
|
391
|
-
}
|
392
|
-
this.addRemoveSelectionFromImage(true);
|
393
|
-
this.backgroundDragging = false;
|
394
|
-
this.activeHandle = null;
|
395
|
-
this.updateUI();
|
396
|
-
}
|
397
|
-
onDragCancel() {
|
398
|
-
this.backgroundDragging = false;
|
399
|
-
this.activeHandle = null;
|
400
|
-
this.setTransform(Mat33.identity);
|
401
|
-
this.addRemoveSelectionFromImage(true);
|
402
|
-
this.updateUI();
|
403
|
-
}
|
404
|
-
// Scroll the viewport to this. Does not zoom
|
405
|
-
scrollTo() {
|
406
|
-
if (this.selectedElems.length === 0) {
|
407
|
-
return false;
|
408
|
-
}
|
409
|
-
const screenSize = this.editor.viewport.getScreenRectSize();
|
410
|
-
const screenRect = new Rect2(0, 0, screenSize.x, screenSize.y);
|
411
|
-
const selectionScreenRegion = this.getScreenRegion();
|
412
|
-
if (!screenRect.containsPoint(selectionScreenRegion.center)) {
|
413
|
-
const targetPointScreen = selectionScreenRegion.center;
|
414
|
-
const closestPointScreen = screenRect.getClosestPointOnBoundaryTo(targetPointScreen);
|
415
|
-
const closestPointCanvas = this.editor.viewport.screenToCanvas(closestPointScreen);
|
416
|
-
const targetPointCanvas = this.region.center;
|
417
|
-
const delta = closestPointCanvas.minus(targetPointCanvas);
|
418
|
-
this.editor.dispatchNoAnnounce(Viewport.transformBy(Mat33.translation(delta.times(0.5))), false);
|
419
|
-
this.editor.queueRerender().then(() => {
|
420
|
-
this.previewTransformCmds();
|
421
|
-
});
|
422
|
-
return true;
|
423
|
-
}
|
424
|
-
return false;
|
425
|
-
}
|
426
|
-
deleteSelectedObjects() {
|
427
|
-
if (this.backgroundDragging || this.activeHandle) {
|
428
|
-
this.onDragEnd();
|
429
|
-
}
|
430
|
-
return new Erase(this.selectedElems);
|
431
|
-
}
|
432
|
-
runSelectionDuplicatedAnimation() {
|
433
|
-
if (this.selectionDuplicatedAnimationTimeout) {
|
434
|
-
clearTimeout(this.selectionDuplicatedAnimationTimeout);
|
435
|
-
}
|
436
|
-
const animationDuration = 400; // ms
|
437
|
-
this.backgroundElem.style.animation = `${animationDuration}ms ease selection-duplicated-animation`;
|
438
|
-
this.selectionDuplicatedAnimationTimeout = setTimeout(() => {
|
439
|
-
this.backgroundElem.style.animation = '';
|
440
|
-
this.selectionDuplicatedAnimationTimeout = null;
|
441
|
-
}, animationDuration);
|
442
|
-
}
|
443
|
-
async duplicateSelectedObjects() {
|
444
|
-
const wasTransforming = this.backgroundDragging || this.activeHandle;
|
445
|
-
let tmpApplyCommand = null;
|
446
|
-
if (!wasTransforming) {
|
447
|
-
this.runSelectionDuplicatedAnimation();
|
448
|
-
}
|
449
|
-
if (wasTransforming) {
|
450
|
-
// Don't update the selection's focus when redoing/undoing
|
451
|
-
const selectionToUpdate = null;
|
452
|
-
const deltaZIndex = this.getDeltaZIndexToMoveSelectionToTop();
|
453
|
-
tmpApplyCommand = new _a.ApplyTransformationCommand(selectionToUpdate, this.selectedElems, this.transform, deltaZIndex);
|
454
|
-
// Transform to ensure that the duplicates are in the correct location
|
455
|
-
await tmpApplyCommand.apply(this.editor);
|
456
|
-
// Show items again
|
457
|
-
this.addRemoveSelectionFromImage(true);
|
458
|
-
}
|
459
|
-
const duplicateCommand = new Duplicate(this.selectedElems);
|
460
|
-
if (wasTransforming) {
|
461
|
-
// Move the selected objects back to the correct location.
|
462
|
-
await tmpApplyCommand?.unapply(this.editor);
|
463
|
-
this.addRemoveSelectionFromImage(false);
|
464
|
-
this.previewTransformCmds();
|
465
|
-
this.updateUI();
|
466
|
-
}
|
467
|
-
return duplicateCommand;
|
468
|
-
}
|
469
|
-
addTo(elem) {
|
470
|
-
if (this.outerContainer.parentElement) {
|
471
|
-
this.outerContainer.remove();
|
472
|
-
}
|
473
|
-
elem.appendChild(this.outerContainer);
|
474
|
-
this.hasParent = true;
|
475
|
-
}
|
476
|
-
setToPoint(point) {
|
477
|
-
this.originalRegion = this.originalRegion.grownToPoint(point);
|
478
|
-
this.selectionTightBoundingBox = null;
|
479
|
-
this.updateUI();
|
480
|
-
}
|
481
|
-
cancelSelection() {
|
482
|
-
if (this.outerContainer.parentElement) {
|
483
|
-
this.outerContainer.remove();
|
484
|
-
}
|
485
|
-
this.originalRegion = Rect2.empty;
|
486
|
-
this.selectionTightBoundingBox = null;
|
487
|
-
this.hasParent = false;
|
488
|
-
}
|
489
|
-
setSelectedObjects(objects, bbox) {
|
490
|
-
this.addRemoveSelectionFromImage(true);
|
491
|
-
this.originalRegion = bbox;
|
492
|
-
this.selectionTightBoundingBox = bbox;
|
493
|
-
this.selectedElems = objects.filter(object => object.isSelectable());
|
494
|
-
// Enforce increasing z-index invariant
|
495
|
-
this.selectedElems.sort((a, b) => a.getZIndex() - b.getZIndex());
|
496
|
-
this.padRegion();
|
497
|
-
this.updateUI();
|
498
|
-
}
|
499
|
-
getSelectedObjects() {
|
500
|
-
return [...this.selectedElems];
|
501
|
-
}
|
502
|
-
}
|
503
|
-
_a = Selection;
|
504
|
-
(() => {
|
505
|
-
SerializableCommand.register('selection-tool-transform', (json, _editor) => {
|
506
|
-
// The selection box is lost when serializing/deserializing. No need to store box rotation
|
507
|
-
const fullTransform = new Mat33(...json.transform);
|
508
|
-
const elemIds = (json.elems ?? []);
|
509
|
-
const deltaZIndex = parseInt(json.deltaZIndex ?? 0);
|
510
|
-
return new _a.ApplyTransformationCommand(null, elemIds, fullTransform, deltaZIndex);
|
511
|
-
});
|
512
|
-
})();
|
513
|
-
Selection.ApplyTransformationCommand = class extends SerializableCommand {
|
514
|
-
constructor(selection,
|
515
|
-
// If a `string[]`, selectedElems is a list of element IDs.
|
516
|
-
selectedElems,
|
517
|
-
// Full transformation used to transform elements.
|
518
|
-
fullTransform, deltaZIndex) {
|
519
|
-
super('selection-tool-transform');
|
520
|
-
this.selection = selection;
|
521
|
-
this.fullTransform = fullTransform;
|
522
|
-
this.deltaZIndex = deltaZIndex;
|
523
|
-
const isIDList = (arr) => {
|
524
|
-
return typeof arr[0] === 'string';
|
525
|
-
};
|
526
|
-
// If a list of element IDs,
|
527
|
-
if (isIDList(selectedElems)) {
|
528
|
-
this.selectedElemIds = selectedElems;
|
529
|
-
}
|
530
|
-
else {
|
531
|
-
this.selectedElemIds = selectedElems.map(elem => elem.getId());
|
532
|
-
this.transformCommands = selectedElems.map(elem => {
|
533
|
-
return elem.setZIndexAndTransformBy(this.fullTransform, elem.getZIndex() + deltaZIndex);
|
534
|
-
});
|
535
|
-
}
|
536
|
-
}
|
537
|
-
resolveToElems(editor, isUndoing) {
|
538
|
-
if (this.transformCommands) {
|
539
|
-
return;
|
540
|
-
}
|
541
|
-
this.transformCommands = this.selectedElemIds.map(id => {
|
542
|
-
const elem = editor.image.lookupElement(id);
|
543
|
-
if (!elem) {
|
544
|
-
// There may be valid reasons for an element lookup to fail:
|
545
|
-
// For example, if the element was deleted remotely and the remote deletion
|
546
|
-
// hasn't been undone.
|
547
|
-
console.warn(`Unable to find element with ID, ${id}.`);
|
548
|
-
return null;
|
549
|
-
}
|
550
|
-
let originalZIndex = elem.getZIndex();
|
551
|
-
let targetZIndex = elem.getZIndex() + this.deltaZIndex;
|
552
|
-
// If the command has already been applied, the element should currently
|
553
|
-
// have the target z-index.
|
554
|
-
if (isUndoing) {
|
555
|
-
targetZIndex = elem.getZIndex();
|
556
|
-
originalZIndex = elem.getZIndex() - this.deltaZIndex;
|
557
|
-
}
|
558
|
-
return elem.setZIndexAndTransformBy(this.fullTransform, targetZIndex, originalZIndex);
|
559
|
-
}).filter(// Remove all null commands
|
560
|
-
// Remove all null commands
|
561
|
-
command => command !== null);
|
562
|
-
}
|
563
|
-
async apply(editor) {
|
564
|
-
this.resolveToElems(editor, false);
|
565
|
-
this.selection?.setTransform(this.fullTransform, false);
|
566
|
-
this.selection?.updateUI();
|
567
|
-
await editor.asyncApplyCommands(this.transformCommands, updateChunkSize);
|
568
|
-
this.selection?.setTransform(Mat33.identity, false);
|
569
|
-
this.selection?.recomputeRegion();
|
570
|
-
this.selection?.updateUI();
|
571
|
-
}
|
572
|
-
async unapply(editor) {
|
573
|
-
this.resolveToElems(editor, true);
|
574
|
-
this.selection?.setTransform(this.fullTransform.inverse(), false);
|
575
|
-
this.selection?.updateUI();
|
576
|
-
await editor.asyncUnapplyCommands(this.transformCommands, updateChunkSize, true);
|
577
|
-
this.selection?.setTransform(Mat33.identity, false);
|
578
|
-
this.selection?.recomputeRegion();
|
579
|
-
this.selection?.updateUI();
|
580
|
-
}
|
581
|
-
serializeToJSON() {
|
582
|
-
return {
|
583
|
-
elems: this.selectedElemIds,
|
584
|
-
transform: this.fullTransform.toArray(),
|
585
|
-
deltaZIndex: this.deltaZIndex,
|
586
|
-
};
|
587
|
-
}
|
588
|
-
description(_editor, localizationTable) {
|
589
|
-
return localizationTable.transformedElements(this.selectedElemIds.length);
|
590
|
-
}
|
591
|
-
};
|
592
|
-
export default Selection;
|
@@ -1,62 +0,0 @@
|
|
1
|
-
import { Point2, Vec2 } from '@js-draw/math';
|
2
|
-
import Selection from './Selection';
|
3
|
-
import Pointer from '../../Pointer';
|
4
|
-
import Viewport from '../../Viewport';
|
5
|
-
import { SelectionBoxChild } from './types';
|
6
|
-
export declare enum HandleAction {
|
7
|
-
ResizeXY = "resize-xy",
|
8
|
-
Rotate = "rotate",
|
9
|
-
ResizeX = "resize-x",
|
10
|
-
ResizeY = "resize-y"
|
11
|
-
}
|
12
|
-
export interface HandlePresentation {
|
13
|
-
side: Vec2;
|
14
|
-
icon?: Element;
|
15
|
-
action: HandleAction;
|
16
|
-
}
|
17
|
-
export declare const handleSize = 30;
|
18
|
-
export type DragStartCallback = (startPoint: Point2) => void;
|
19
|
-
export type DragUpdateCallback = (canvasPoint: Point2) => void;
|
20
|
-
export type DragEndCallback = () => Promise<void> | void;
|
21
|
-
export default class SelectionHandle implements SelectionBoxChild {
|
22
|
-
readonly presentation: HandlePresentation;
|
23
|
-
private readonly parent;
|
24
|
-
private readonly viewport;
|
25
|
-
private readonly onDragStart;
|
26
|
-
private readonly onDragUpdate;
|
27
|
-
private readonly onDragEnd;
|
28
|
-
private element;
|
29
|
-
private snapToGrid;
|
30
|
-
private shape;
|
31
|
-
private parentSide;
|
32
|
-
constructor(presentation: HandlePresentation, parent: Selection, viewport: Viewport, onDragStart: DragStartCallback, onDragUpdate: DragUpdateCallback, onDragEnd: DragEndCallback);
|
33
|
-
/**
|
34
|
-
* Adds this to `container`, where `conatiner` should be the background/selection
|
35
|
-
* element visible on the screen.
|
36
|
-
*/
|
37
|
-
addTo(container: HTMLElement): void;
|
38
|
-
/**
|
39
|
-
* Removes this element from its container. Should only be called
|
40
|
-
* after {@link addTo}.
|
41
|
-
*/
|
42
|
-
remove(): void;
|
43
|
-
/**
|
44
|
-
* Returns this handle's bounding box relative to the top left of the
|
45
|
-
* selection box.
|
46
|
-
*/
|
47
|
-
private getBBoxParentCoords;
|
48
|
-
/** @returns this handle's bounding box relative to the canvas. */
|
49
|
-
private getBBoxCanvasCoords;
|
50
|
-
/**
|
51
|
-
* Moves the HTML representation of this to the location matching its internal representation.
|
52
|
-
*/
|
53
|
-
updatePosition(): void;
|
54
|
-
/** @returns true iff `point` (in editor **canvas** coordinates) is in this. */
|
55
|
-
containsPoint(point: Point2): boolean;
|
56
|
-
private dragLastPos;
|
57
|
-
handleDragStart(pointer: Pointer): boolean;
|
58
|
-
handleDragUpdate(pointer: Pointer): void;
|
59
|
-
handleDragEnd(): void | Promise<void>;
|
60
|
-
setSnapToGrid(snap: boolean): void;
|
61
|
-
isSnappingToGrid(): boolean;
|
62
|
-
}
|