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.
Files changed (91) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bundle.js +1 -1
  3. package/dist/src/Color4.d.ts +13 -0
  4. package/dist/src/Color4.js +17 -0
  5. package/dist/src/Editor.d.ts +33 -18
  6. package/dist/src/Editor.js +26 -24
  7. package/dist/src/EditorImage.d.ts +12 -0
  8. package/dist/src/EditorImage.js +12 -0
  9. package/dist/src/Pointer.d.ts +1 -0
  10. package/dist/src/Pointer.js +8 -0
  11. package/dist/src/SVGLoader.d.ts +5 -0
  12. package/dist/src/SVGLoader.js +49 -36
  13. package/dist/src/Viewport.d.ts +30 -1
  14. package/dist/src/Viewport.js +39 -9
  15. package/dist/src/commands/invertCommand.js +1 -1
  16. package/dist/src/components/AbstractComponent.d.ts +20 -0
  17. package/dist/src/components/AbstractComponent.js +32 -2
  18. package/dist/src/lib.d.ts +6 -3
  19. package/dist/src/lib.js +4 -1
  20. package/dist/src/math/Mat33.d.ts +1 -1
  21. package/dist/src/math/Mat33.js +1 -1
  22. package/dist/src/rendering/Display.d.ts +9 -11
  23. package/dist/src/rendering/Display.js +12 -14
  24. package/dist/src/rendering/lib.d.ts +3 -0
  25. package/dist/src/rendering/lib.js +3 -0
  26. package/dist/src/rendering/renderers/DummyRenderer.js +2 -2
  27. package/dist/src/rendering/renderers/SVGRenderer.js +4 -0
  28. package/dist/src/toolbar/HTMLToolbar.d.ts +51 -0
  29. package/dist/src/toolbar/HTMLToolbar.js +63 -5
  30. package/dist/src/toolbar/IconProvider.d.ts +2 -2
  31. package/dist/src/toolbar/IconProvider.js +123 -35
  32. package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +8 -1
  33. package/dist/src/toolbar/widgets/EraserToolWidget.js +45 -4
  34. package/dist/src/toolbar/widgets/PenToolWidget.js +2 -2
  35. package/dist/src/toolbar/widgets/SelectionToolWidget.js +12 -3
  36. package/dist/src/tools/Eraser.d.ts +10 -1
  37. package/dist/src/tools/Eraser.js +65 -13
  38. package/dist/src/tools/PanZoom.js +1 -1
  39. package/dist/src/tools/PasteHandler.d.ts +11 -4
  40. package/dist/src/tools/PasteHandler.js +12 -5
  41. package/dist/src/tools/Pen.d.ts +7 -2
  42. package/dist/src/tools/Pen.js +39 -6
  43. package/dist/src/tools/SelectionTool/Selection.d.ts +4 -1
  44. package/dist/src/tools/SelectionTool/Selection.js +64 -27
  45. package/dist/src/tools/SelectionTool/SelectionHandle.d.ts +3 -0
  46. package/dist/src/tools/SelectionTool/SelectionHandle.js +6 -0
  47. package/dist/src/tools/SelectionTool/SelectionTool.d.ts +3 -1
  48. package/dist/src/tools/SelectionTool/SelectionTool.js +56 -16
  49. package/dist/src/tools/TextTool.js +10 -6
  50. package/dist/src/tools/ToolSwitcherShortcut.d.ts +8 -0
  51. package/dist/src/tools/ToolSwitcherShortcut.js +9 -3
  52. package/dist/src/tools/UndoRedoShortcut.js +2 -4
  53. package/dist/src/types.d.ts +2 -2
  54. package/package.json +2 -2
  55. package/src/Color4.test.ts +11 -0
  56. package/src/Color4.ts +23 -0
  57. package/src/Editor.ts +39 -26
  58. package/src/EditorImage.ts +12 -0
  59. package/src/Pointer.ts +19 -0
  60. package/src/SVGLoader.ts +20 -15
  61. package/src/Viewport.ts +50 -11
  62. package/src/commands/invertCommand.ts +1 -1
  63. package/src/components/AbstractComponent.ts +52 -2
  64. package/src/lib.ts +6 -3
  65. package/src/math/Mat33.ts +1 -1
  66. package/src/rendering/Display.ts +12 -15
  67. package/src/rendering/RenderingStyle.ts +1 -1
  68. package/src/rendering/lib.ts +4 -0
  69. package/src/rendering/renderers/DummyRenderer.ts +2 -3
  70. package/src/rendering/renderers/SVGRenderer.ts +4 -0
  71. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -1
  72. package/src/toolbar/HTMLToolbar.ts +81 -5
  73. package/src/toolbar/IconProvider.ts +132 -37
  74. package/src/toolbar/widgets/EraserToolWidget.ts +64 -5
  75. package/src/toolbar/widgets/PenToolWidget.ts +2 -2
  76. package/src/toolbar/widgets/SelectionToolWidget.ts +2 -2
  77. package/src/tools/Eraser.test.ts +79 -0
  78. package/src/tools/Eraser.ts +81 -17
  79. package/src/tools/PanZoom.ts +1 -1
  80. package/src/tools/PasteHandler.ts +12 -6
  81. package/src/tools/Pen.test.ts +44 -1
  82. package/src/tools/Pen.ts +53 -8
  83. package/src/tools/SelectionTool/Selection.ts +73 -23
  84. package/src/tools/SelectionTool/SelectionHandle.ts +9 -0
  85. package/src/tools/SelectionTool/SelectionTool.test.ts +138 -21
  86. package/src/tools/SelectionTool/SelectionTool.ts +70 -16
  87. package/src/tools/TextTool.ts +14 -8
  88. package/src/tools/ToolSwitcherShortcut.ts +10 -5
  89. package/src/tools/UndoRedoShortcut.ts +2 -5
  90. package/src/types.ts +2 -2
  91. package/typedoc.json +2 -2
@@ -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
- this.textInputElem.remove();
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
- } else {
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
- setTimeout(() => input?.remove(), 0);
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
- // {@inheritDoc ToolSwitcherShortcut!}
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
- // {@inheritDoc UndoRedoShortcut!}
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
- // Activate undo/redo
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.
package/typedoc.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "entryPoints": [
3
- "./src/"
3
+ "./src/lib.ts", "./src/bundle/bundled.ts"
4
4
  ],
5
5
  "exclude": [
6
6
  "**/*.test.ts",
@@ -21,4 +21,4 @@
21
21
  "invalidLink": true,
22
22
  "notDocumented": false
23
23
  }
24
- }
24
+ }