js-draw 0.11.3 → 0.13.0
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 +15 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Color4.d.ts +13 -0
- package/dist/src/Color4.js +17 -0
- package/dist/src/Editor.d.ts +33 -18
- package/dist/src/Editor.js +26 -24
- 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 +49 -36
- 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 +20 -0
- package/dist/src/components/AbstractComponent.js +32 -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/HTMLToolbar.d.ts +51 -0
- package/dist/src/toolbar/HTMLToolbar.js +63 -5
- package/dist/src/toolbar/IconProvider.d.ts +2 -2
- package/dist/src/toolbar/IconProvider.js +123 -35
- package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +8 -1
- package/dist/src/toolbar/widgets/EraserToolWidget.js +45 -4
- package/dist/src/toolbar/widgets/PenToolWidget.js +2 -2
- package/dist/src/toolbar/widgets/SelectionToolWidget.js +12 -3
- package/dist/src/tools/Eraser.d.ts +10 -1
- package/dist/src/tools/Eraser.js +65 -13
- package/dist/src/tools/PanZoom.js +1 -1
- 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/Selection.d.ts +4 -1
- package/dist/src/tools/SelectionTool/Selection.js +64 -27
- 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 +56 -16
- package/dist/src/tools/TextTool.js +10 -6
- 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/dist/src/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/Color4.test.ts +11 -0
- package/src/Color4.ts +23 -0
- package/src/Editor.ts +39 -26
- package/src/EditorImage.ts +12 -0
- package/src/Pointer.ts +19 -0
- package/src/SVGLoader.ts +20 -15
- package/src/Viewport.ts +50 -11
- package/src/commands/invertCommand.ts +1 -1
- package/src/components/AbstractComponent.ts +52 -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 +81 -5
- package/src/toolbar/IconProvider.ts +132 -37
- package/src/toolbar/widgets/EraserToolWidget.ts +64 -5
- package/src/toolbar/widgets/PenToolWidget.ts +2 -2
- package/src/toolbar/widgets/SelectionToolWidget.ts +2 -2
- package/src/tools/Eraser.test.ts +79 -0
- package/src/tools/Eraser.ts +81 -17
- package/src/tools/PanZoom.ts +1 -1
- 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/Selection.ts +73 -23
- package/src/tools/SelectionTool/SelectionHandle.ts +9 -0
- package/src/tools/SelectionTool/SelectionTool.test.ts +138 -21
- package/src/tools/SelectionTool/SelectionTool.ts +70 -16
- package/src/tools/TextTool.ts +14 -8
- package/src/tools/ToolSwitcherShortcut.ts +10 -5
- package/src/tools/UndoRedoShortcut.ts +2 -5
- package/src/types.ts +2 -2
- package/typedoc.json +2 -2
package/src/tools/TextTool.ts
CHANGED
@@ -80,11 +80,14 @@ export default class TextTool extends BaseTool {
|
|
80
80
|
if (this.textInputElem && this.textTargetPosition) {
|
81
81
|
const content = this.textInputElem.value.trimEnd();
|
82
82
|
|
83
|
+
this.textInputElem.value = '';
|
84
|
+
|
83
85
|
if (removeInput) {
|
84
|
-
|
86
|
+
// In some browsers, .remove() triggers a .blur event (synchronously).
|
87
|
+
// Clear this.textInputElem before removal
|
88
|
+
const input = this.textInputElem;
|
85
89
|
this.textInputElem = null;
|
86
|
-
|
87
|
-
this.textInputElem.value = '';
|
90
|
+
input.remove();
|
88
91
|
}
|
89
92
|
|
90
93
|
if (content === '') {
|
@@ -100,14 +103,14 @@ export default class TextTool extends BaseTool {
|
|
100
103
|
).rightMul(
|
101
104
|
Mat33.zRotation(this.textRotation)
|
102
105
|
);
|
103
|
-
|
106
|
+
|
104
107
|
const textComponent = TextComponent.fromLines(content.split('\n'), textTransform, this.textStyle);
|
105
108
|
|
106
109
|
const action = EditorImage.addElement(textComponent);
|
107
110
|
if (this.removeExistingCommand) {
|
108
111
|
// Unapply so that `removeExistingCommand` can be added to the undo stack.
|
109
112
|
this.removeExistingCommand.unapply(this.editor);
|
110
|
-
|
113
|
+
|
111
114
|
this.editor.dispatch(uniteCommands([ this.removeExistingCommand, action ]));
|
112
115
|
this.removeExistingCommand = null;
|
113
116
|
} else {
|
@@ -177,10 +180,13 @@ export default class TextTool extends BaseTool {
|
|
177
180
|
// Delay removing the input -- flushInput may be called within a blur()
|
178
181
|
// event handler
|
179
182
|
const removeInput = false;
|
180
|
-
this.flushInput(removeInput);
|
181
|
-
|
182
183
|
const input = this.textInputElem;
|
183
|
-
|
184
|
+
|
185
|
+
this.flushInput(removeInput);
|
186
|
+
this.textInputElem = null;
|
187
|
+
setTimeout(() => {
|
188
|
+
input?.remove();
|
189
|
+
}, 0);
|
184
190
|
};
|
185
191
|
this.textInputElem.onkeyup = (evt) => {
|
186
192
|
if (evt.key === 'Enter' && !evt.shiftKey) {
|
@@ -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') {
|
package/src/types.ts
CHANGED
@@ -198,9 +198,9 @@ export type EditorEventDataType = EditorToolEvent | EditorObjectEvent
|
|
198
198
|
// Returns null to continue loading without pause.
|
199
199
|
// [totalToProcess] can be an estimate and may change if a better estimate becomes available.
|
200
200
|
export type OnProgressListener =
|
201
|
-
(amountProcessed: number, totalToProcess: number)=> Promise<void>|null;
|
201
|
+
(amountProcessed: number, totalToProcess: number)=> Promise<void>|null|void;
|
202
202
|
|
203
|
-
export type ComponentAddedListener = (component: AbstractComponent)=> void;
|
203
|
+
export type ComponentAddedListener = (component: AbstractComponent)=> Promise<void>|void;
|
204
204
|
|
205
205
|
// Called when a new estimate for the import/export rect has been generated. This can be called multiple times.
|
206
206
|
// Only the last call to this listener must be accurate.
|