js-draw 0.12.0 → 0.13.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/CHANGELOG.md +14 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Color4.d.ts +12 -0
- package/dist/src/Color4.js +16 -0
- package/dist/src/Editor.d.ts +33 -18
- package/dist/src/Editor.js +22 -19
- package/dist/src/EditorImage.d.ts +12 -0
- package/dist/src/EditorImage.js +12 -0
- package/dist/src/Pointer.d.ts +1 -0
- package/dist/src/Pointer.js +8 -0
- package/dist/src/SVGLoader.d.ts +5 -0
- package/dist/src/SVGLoader.js +6 -1
- package/dist/src/Viewport.d.ts +30 -1
- package/dist/src/Viewport.js +39 -9
- package/dist/src/commands/invertCommand.js +1 -1
- package/dist/src/components/AbstractComponent.d.ts +19 -0
- package/dist/src/components/AbstractComponent.js +17 -2
- package/dist/src/lib.d.ts +6 -3
- package/dist/src/lib.js +4 -1
- package/dist/src/math/Mat33.d.ts +1 -1
- package/dist/src/math/Mat33.js +1 -1
- package/dist/src/rendering/Display.d.ts +9 -11
- package/dist/src/rendering/Display.js +12 -14
- package/dist/src/rendering/lib.d.ts +3 -0
- package/dist/src/rendering/lib.js +3 -0
- package/dist/src/rendering/renderers/DummyRenderer.js +2 -2
- package/dist/src/rendering/renderers/SVGRenderer.js +4 -0
- package/dist/src/toolbar/IconProvider.d.ts +1 -1
- package/dist/src/toolbar/IconProvider.js +90 -29
- package/dist/src/toolbar/makeColorInput.js +8 -1
- package/dist/src/tools/PanZoom.d.ts +3 -1
- package/dist/src/tools/PanZoom.js +31 -6
- package/dist/src/tools/PasteHandler.d.ts +11 -4
- package/dist/src/tools/PasteHandler.js +12 -5
- package/dist/src/tools/Pen.d.ts +7 -2
- package/dist/src/tools/Pen.js +39 -6
- package/dist/src/tools/SelectionTool/SelectionHandle.d.ts +3 -0
- package/dist/src/tools/SelectionTool/SelectionHandle.js +6 -0
- package/dist/src/tools/SelectionTool/SelectionTool.d.ts +3 -1
- package/dist/src/tools/SelectionTool/SelectionTool.js +53 -15
- package/dist/src/tools/ToolSwitcherShortcut.d.ts +8 -0
- package/dist/src/tools/ToolSwitcherShortcut.js +9 -3
- package/dist/src/tools/UndoRedoShortcut.js +2 -4
- package/package.json +2 -2
- package/src/Color4.test.ts +11 -0
- package/src/Color4.ts +22 -0
- package/src/Editor.ts +36 -22
- package/src/EditorImage.ts +12 -0
- package/src/Pointer.ts +19 -0
- package/src/SVGLoader.ts +6 -1
- package/src/Viewport.ts +50 -11
- package/src/commands/invertCommand.ts +1 -1
- package/src/components/AbstractComponent.ts +33 -2
- package/src/lib.ts +6 -3
- package/src/math/Mat33.ts +1 -1
- package/src/rendering/Display.ts +12 -15
- package/src/rendering/RenderingStyle.ts +1 -1
- package/src/rendering/lib.ts +4 -0
- package/src/rendering/renderers/DummyRenderer.ts +2 -3
- package/src/rendering/renderers/SVGRenderer.ts +4 -0
- package/src/rendering/renderers/TextOnlyRenderer.ts +0 -1
- package/src/toolbar/HTMLToolbar.ts +1 -1
- package/src/toolbar/IconProvider.ts +98 -31
- package/src/toolbar/makeColorInput.ts +9 -1
- package/src/tools/PanZoom.ts +37 -7
- package/src/tools/PasteHandler.ts +12 -6
- package/src/tools/Pen.test.ts +44 -1
- package/src/tools/Pen.ts +53 -8
- package/src/tools/SelectionTool/SelectionHandle.ts +9 -0
- package/src/tools/SelectionTool/SelectionTool.ts +67 -15
- package/src/tools/ToolSwitcherShortcut.ts +10 -5
- package/src/tools/UndoRedoShortcut.ts +2 -5
- package/typedoc.json +2 -2
@@ -1,7 +1,3 @@
|
|
1
|
-
// Allows users to select/transform portions of the `EditorImage`.
|
2
|
-
// With respect to `extend`ing, `SelectionTool` is not stable.
|
3
|
-
// @packageDocumentation
|
4
|
-
|
5
1
|
import AbstractComponent from '../../components/AbstractComponent';
|
6
2
|
import Editor from '../../Editor';
|
7
3
|
import Mat33 from '../../math/Mat33';
|
@@ -16,7 +12,8 @@ import TextComponent from '../../components/TextComponent';
|
|
16
12
|
|
17
13
|
export const cssPrefix = 'selection-tool-';
|
18
14
|
|
19
|
-
//
|
15
|
+
// Allows users to select/transform portions of the `EditorImage`.
|
16
|
+
// With respect to `extend`ing, `SelectionTool` is not stable.
|
20
17
|
export default class SelectionTool extends BaseTool {
|
21
18
|
private handleOverlay: HTMLElement;
|
22
19
|
private prevSelectionBox: Selection|null;
|
@@ -25,6 +22,7 @@ export default class SelectionTool extends BaseTool {
|
|
25
22
|
|
26
23
|
private expandingSelectionBox: boolean = false;
|
27
24
|
private shiftKeyPressed: boolean = false;
|
25
|
+
private ctrlKeyPressed: boolean = false;
|
28
26
|
|
29
27
|
public constructor(private editor: Editor, description: string) {
|
30
28
|
super(editor.notifier, description);
|
@@ -61,17 +59,47 @@ export default class SelectionTool extends BaseTool {
|
|
61
59
|
this.selectionBox.addTo(this.handleOverlay);
|
62
60
|
}
|
63
61
|
|
62
|
+
private snapSelectionToGrid() {
|
63
|
+
if (!this.selectionBox) throw new Error('No selection to snap!');
|
64
|
+
|
65
|
+
const topLeftOfBBox = this.selectionBox.region.topLeft;
|
66
|
+
const snapDistance =
|
67
|
+
this.editor.viewport.snapToGrid(topLeftOfBBox).minus(topLeftOfBBox);
|
68
|
+
|
69
|
+
const oldTransform = this.selectionBox.getTransform();
|
70
|
+
this.selectionBox.setTransform(oldTransform.rightMul(Mat33.translation(snapDistance)));
|
71
|
+
this.selectionBox.finalizeTransform();
|
72
|
+
}
|
73
|
+
|
64
74
|
private selectionBoxHandlingEvt: boolean = false;
|
65
|
-
public onPointerDown(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
75
|
+
public onPointerDown({ allPointers, current }: PointerEvt): boolean {
|
76
|
+
const snapToGrid = this.ctrlKeyPressed;
|
77
|
+
if (snapToGrid) {
|
78
|
+
current = current.snappedToGrid(this.editor.viewport);
|
79
|
+
}
|
80
|
+
|
81
|
+
if (allPointers.length === 1 && current.isPrimary) {
|
82
|
+
let transforming = false;
|
83
|
+
|
84
|
+
if (this.lastEvtTarget && this.selectionBox) {
|
85
|
+
if (snapToGrid) {
|
86
|
+
this.snapSelectionToGrid();
|
87
|
+
}
|
88
|
+
|
89
|
+
const dragStartResult = this.selectionBox.onDragStart(current, this.lastEvtTarget);
|
90
|
+
|
91
|
+
if (dragStartResult) {
|
92
|
+
transforming = true;
|
93
|
+
|
94
|
+
this.selectionBoxHandlingEvt = true;
|
95
|
+
this.expandingSelectionBox = false;
|
96
|
+
}
|
70
97
|
}
|
71
|
-
|
98
|
+
|
99
|
+
if (!transforming) {
|
72
100
|
// Shift key: Combine the new and old selection boxes at the end of the gesture.
|
73
101
|
this.expandingSelectionBox = this.shiftKeyPressed;
|
74
|
-
this.makeSelectionBox(
|
102
|
+
this.makeSelectionBox(current.canvasPos);
|
75
103
|
}
|
76
104
|
|
77
105
|
return true;
|
@@ -82,10 +110,15 @@ export default class SelectionTool extends BaseTool {
|
|
82
110
|
public onPointerMove(event: PointerEvt): void {
|
83
111
|
if (!this.selectionBox) return;
|
84
112
|
|
113
|
+
let currentPointer = event.current;
|
114
|
+
if (this.ctrlKeyPressed) {
|
115
|
+
currentPointer = currentPointer.snappedToGrid(this.editor.viewport);
|
116
|
+
}
|
117
|
+
|
85
118
|
if (this.selectionBoxHandlingEvt) {
|
86
|
-
this.selectionBox.onDragUpdate(
|
119
|
+
this.selectionBox.onDragUpdate(currentPointer);
|
87
120
|
} else {
|
88
|
-
this.selectionBox!.setToPoint(
|
121
|
+
this.selectionBox!.setToPoint(currentPointer.canvasPos);
|
89
122
|
}
|
90
123
|
}
|
91
124
|
|
@@ -137,7 +170,12 @@ export default class SelectionTool extends BaseTool {
|
|
137
170
|
public onPointerUp(event: PointerEvt): void {
|
138
171
|
if (!this.selectionBox) return;
|
139
172
|
|
140
|
-
|
173
|
+
let currentPointer = event.current;
|
174
|
+
if (this.ctrlKeyPressed) {
|
175
|
+
currentPointer = currentPointer.snappedToGrid(this.editor.viewport);
|
176
|
+
}
|
177
|
+
|
178
|
+
this.selectionBox.setToPoint(currentPointer.canvasPos);
|
141
179
|
|
142
180
|
// Were we expanding the previous selection?
|
143
181
|
if (this.expandingSelectionBox && this.prevSelectionBox) {
|
@@ -173,8 +211,14 @@ export default class SelectionTool extends BaseTool {
|
|
173
211
|
'e', 'j', 'ArrowDown',
|
174
212
|
'r', 'R',
|
175
213
|
'i', 'I', 'o', 'O',
|
214
|
+
'Control',
|
176
215
|
];
|
177
216
|
public onKeyPress(event: KeyPressEvent): boolean {
|
217
|
+
if (event.key === 'Control') {
|
218
|
+
this.ctrlKeyPressed = true;
|
219
|
+
return true;
|
220
|
+
}
|
221
|
+
|
178
222
|
if (this.selectionBox && event.ctrlKey && event.key === 'd') {
|
179
223
|
// Handle duplication on key up — we don't want to accidentally duplicate
|
180
224
|
// many times.
|
@@ -290,6 +334,11 @@ export default class SelectionTool extends BaseTool {
|
|
290
334
|
}
|
291
335
|
|
292
336
|
public onKeyUp(evt: KeyUpEvent) {
|
337
|
+
if (evt.key === 'Control') {
|
338
|
+
this.ctrlKeyPressed = false;
|
339
|
+
return true;
|
340
|
+
}
|
341
|
+
|
293
342
|
if (evt.key === 'Shift') {
|
294
343
|
this.shiftKeyPressed = false;
|
295
344
|
return true;
|
@@ -358,6 +407,9 @@ export default class SelectionTool extends BaseTool {
|
|
358
407
|
this.handleOverlay.replaceChildren();
|
359
408
|
this.selectionBox = null;
|
360
409
|
|
410
|
+
this.shiftKeyPressed = false;
|
411
|
+
this.ctrlKeyPressed = false;
|
412
|
+
|
361
413
|
this.handleOverlay.style.display = enabled ? 'block' : 'none';
|
362
414
|
|
363
415
|
if (enabled) {
|
@@ -1,16 +1,21 @@
|
|
1
|
-
// Handles ctrl+1, ctrl+2, ctrl+3, ..., shortcuts for switching tools.
|
2
|
-
// @packageDocumentation
|
3
|
-
|
4
1
|
import Editor from '../Editor';
|
5
2
|
import { KeyPressEvent } from '../types';
|
6
3
|
import BaseTool from './BaseTool';
|
7
4
|
|
8
|
-
|
5
|
+
/**
|
6
|
+
* Handles keyboard events used, by default, to select tools. By default,
|
7
|
+
* 1 maps to the first primary tool, 2 to the second primary tool, ... .
|
8
|
+
*
|
9
|
+
* This is in the default set of {@link ToolController} tools.
|
10
|
+
*
|
11
|
+
* @deprecated This may be replaced in the future.
|
12
|
+
*/
|
9
13
|
export default class ToolSwitcherShortcut extends BaseTool {
|
10
14
|
public constructor(private editor: Editor) {
|
11
15
|
super(editor.notifier, editor.localization.changeTool);
|
12
16
|
}
|
13
|
-
|
17
|
+
|
18
|
+
// @internal
|
14
19
|
public onKeyPress({ key }: KeyPressEvent): boolean {
|
15
20
|
const toolController = this.editor.toolController;
|
16
21
|
const primaryTools = toolController.getPrimaryTools();
|
@@ -1,17 +1,14 @@
|
|
1
|
-
// Handles ctrl+Z, ctrl+Shift+Z keyboard shortcuts.
|
2
|
-
// @packageDocumentation
|
3
|
-
|
4
1
|
import Editor from '../Editor';
|
5
2
|
import { KeyPressEvent } from '../types';
|
6
3
|
import BaseTool from './BaseTool';
|
7
4
|
|
8
|
-
//
|
5
|
+
// Handles ctrl+Z, ctrl+Shift+Z keyboard shortcuts.
|
9
6
|
export default class UndoRedoShortcut extends BaseTool {
|
10
7
|
public constructor(private editor: Editor) {
|
11
8
|
super(editor.notifier, editor.localization.undoRedoTool);
|
12
9
|
}
|
13
10
|
|
14
|
-
//
|
11
|
+
// @internal
|
15
12
|
public onKeyPress({ key, ctrlKey }: KeyPressEvent): boolean {
|
16
13
|
if (ctrlKey) {
|
17
14
|
if (key === 'z') {
|