js-draw 1.0.1 → 1.0.2

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 (182) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bundle.js +1 -1
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/mjs/version.mjs +1 -1
  5. package/docs/img/readme-images/js-draw.jpg +0 -0
  6. package/docs/img/readme-images/unsupported-elements--in-editor.png +0 -0
  7. package/package.json +5 -4
  8. package/dist-test/test_imports/package-lock.json +0 -13
  9. package/dist-test/test_imports/package.json +0 -12
  10. package/dist-test/test_imports/test-imports.js +0 -11
  11. package/dist-test/test_imports/test-require.cjs +0 -14
  12. package/src/Editor.loadFrom.test.ts +0 -24
  13. package/src/Editor.test.ts +0 -107
  14. package/src/Editor.toSVG.test.ts +0 -294
  15. package/src/Editor.ts +0 -1443
  16. package/src/EditorImage.test.ts +0 -117
  17. package/src/EditorImage.ts +0 -609
  18. package/src/EventDispatcher.test.ts +0 -123
  19. package/src/EventDispatcher.ts +0 -72
  20. package/src/Pointer.ts +0 -183
  21. package/src/SVGLoader.test.ts +0 -114
  22. package/src/SVGLoader.ts +0 -672
  23. package/src/UndoRedoHistory.test.ts +0 -34
  24. package/src/UndoRedoHistory.ts +0 -102
  25. package/src/Viewport.ts +0 -322
  26. package/src/bundle/bundled.ts +0 -7
  27. package/src/commands/Command.ts +0 -45
  28. package/src/commands/Duplicate.ts +0 -75
  29. package/src/commands/Erase.ts +0 -95
  30. package/src/commands/SerializableCommand.ts +0 -49
  31. package/src/commands/UnresolvedCommand.ts +0 -37
  32. package/src/commands/invertCommand.ts +0 -58
  33. package/src/commands/lib.ts +0 -16
  34. package/src/commands/localization.ts +0 -47
  35. package/src/commands/uniteCommands.test.ts +0 -23
  36. package/src/commands/uniteCommands.ts +0 -140
  37. package/src/components/AbstractComponent.transformBy.test.ts +0 -23
  38. package/src/components/AbstractComponent.ts +0 -383
  39. package/src/components/BackgroundComponent.test.ts +0 -44
  40. package/src/components/BackgroundComponent.ts +0 -348
  41. package/src/components/ImageComponent.ts +0 -176
  42. package/src/components/RestylableComponent.ts +0 -161
  43. package/src/components/SVGGlobalAttributesObject.ts +0 -79
  44. package/src/components/Stroke.test.ts +0 -137
  45. package/src/components/Stroke.ts +0 -294
  46. package/src/components/TextComponent.test.ts +0 -202
  47. package/src/components/TextComponent.ts +0 -429
  48. package/src/components/UnknownSVGObject.test.ts +0 -10
  49. package/src/components/UnknownSVGObject.ts +0 -60
  50. package/src/components/builders/ArrowBuilder.ts +0 -106
  51. package/src/components/builders/CircleBuilder.ts +0 -100
  52. package/src/components/builders/FreehandLineBuilder.test.ts +0 -24
  53. package/src/components/builders/FreehandLineBuilder.ts +0 -210
  54. package/src/components/builders/LineBuilder.ts +0 -77
  55. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -453
  56. package/src/components/builders/RectangleBuilder.ts +0 -73
  57. package/src/components/builders/types.ts +0 -15
  58. package/src/components/lib.ts +0 -31
  59. package/src/components/localization.ts +0 -24
  60. package/src/components/util/StrokeSmoother.ts +0 -302
  61. package/src/components/util/describeComponentList.ts +0 -18
  62. package/src/dialogs/makeAboutDialog.ts +0 -82
  63. package/src/inputEvents.ts +0 -143
  64. package/src/lib.ts +0 -91
  65. package/src/localization.ts +0 -34
  66. package/src/localizations/de.ts +0 -146
  67. package/src/localizations/en.ts +0 -8
  68. package/src/localizations/es.ts +0 -74
  69. package/src/localizations/getLocalizationTable.test.ts +0 -27
  70. package/src/localizations/getLocalizationTable.ts +0 -74
  71. package/src/rendering/Display.ts +0 -247
  72. package/src/rendering/RenderablePathSpec.ts +0 -88
  73. package/src/rendering/RenderingStyle.test.ts +0 -68
  74. package/src/rendering/RenderingStyle.ts +0 -55
  75. package/src/rendering/TextRenderingStyle.ts +0 -55
  76. package/src/rendering/caching/CacheRecord.test.ts +0 -48
  77. package/src/rendering/caching/CacheRecord.ts +0 -76
  78. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  79. package/src/rendering/caching/RenderingCache.test.ts +0 -43
  80. package/src/rendering/caching/RenderingCache.ts +0 -66
  81. package/src/rendering/caching/RenderingCacheNode.ts +0 -404
  82. package/src/rendering/caching/testUtils.ts +0 -35
  83. package/src/rendering/caching/types.ts +0 -34
  84. package/src/rendering/lib.ts +0 -8
  85. package/src/rendering/localization.ts +0 -20
  86. package/src/rendering/renderers/AbstractRenderer.ts +0 -232
  87. package/src/rendering/renderers/CanvasRenderer.ts +0 -312
  88. package/src/rendering/renderers/DummyRenderer.test.ts +0 -41
  89. package/src/rendering/renderers/DummyRenderer.ts +0 -142
  90. package/src/rendering/renderers/SVGRenderer.ts +0 -434
  91. package/src/rendering/renderers/TextOnlyRenderer.test.ts +0 -34
  92. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -68
  93. package/src/shortcuts/KeyBinding.test.ts +0 -61
  94. package/src/shortcuts/KeyBinding.ts +0 -257
  95. package/src/shortcuts/KeyboardShortcutManager.test.ts +0 -95
  96. package/src/shortcuts/KeyboardShortcutManager.ts +0 -163
  97. package/src/shortcuts/lib.ts +0 -3
  98. package/src/testing/createEditor.ts +0 -11
  99. package/src/testing/getUniquePointerId.ts +0 -18
  100. package/src/testing/lib.ts +0 -3
  101. package/src/testing/sendPenEvent.ts +0 -36
  102. package/src/testing/sendTouchEvent.ts +0 -71
  103. package/src/toolbar/AbstractToolbar.ts +0 -542
  104. package/src/toolbar/DropdownToolbar.ts +0 -220
  105. package/src/toolbar/EdgeToolbar.test.ts +0 -54
  106. package/src/toolbar/EdgeToolbar.ts +0 -543
  107. package/src/toolbar/IconProvider.ts +0 -861
  108. package/src/toolbar/constants.ts +0 -1
  109. package/src/toolbar/lib.ts +0 -6
  110. package/src/toolbar/localization.ts +0 -136
  111. package/src/toolbar/types.ts +0 -13
  112. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  113. package/src/toolbar/widgets/BaseToolWidget.ts +0 -81
  114. package/src/toolbar/widgets/BaseWidget.ts +0 -495
  115. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -250
  116. package/src/toolbar/widgets/EraserToolWidget.ts +0 -84
  117. package/src/toolbar/widgets/HandToolWidget.ts +0 -239
  118. package/src/toolbar/widgets/InsertImageWidget.ts +0 -248
  119. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  120. package/src/toolbar/widgets/PenToolWidget.ts +0 -369
  121. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -195
  122. package/src/toolbar/widgets/TextToolWidget.ts +0 -149
  123. package/src/toolbar/widgets/components/makeColorInput.ts +0 -184
  124. package/src/toolbar/widgets/components/makeFileInput.ts +0 -128
  125. package/src/toolbar/widgets/components/makeGridSelector.ts +0 -179
  126. package/src/toolbar/widgets/components/makeSeparator.ts +0 -17
  127. package/src/toolbar/widgets/components/makeThicknessSlider.ts +0 -62
  128. package/src/toolbar/widgets/keybindings.ts +0 -19
  129. package/src/toolbar/widgets/layout/DropdownLayoutManager.ts +0 -262
  130. package/src/toolbar/widgets/layout/EdgeToolbarLayoutManager.ts +0 -71
  131. package/src/toolbar/widgets/layout/types.ts +0 -74
  132. package/src/toolbar/widgets/lib.ts +0 -13
  133. package/src/tools/BaseTool.ts +0 -169
  134. package/src/tools/Eraser.test.ts +0 -103
  135. package/src/tools/Eraser.ts +0 -173
  136. package/src/tools/FindTool.test.ts +0 -67
  137. package/src/tools/FindTool.ts +0 -153
  138. package/src/tools/InputFilter/FunctionMapper.ts +0 -17
  139. package/src/tools/InputFilter/InputMapper.ts +0 -41
  140. package/src/tools/InputFilter/InputPipeline.test.ts +0 -41
  141. package/src/tools/InputFilter/InputPipeline.ts +0 -34
  142. package/src/tools/InputFilter/InputStabilizer.ts +0 -254
  143. package/src/tools/InputFilter/StrokeKeyboardControl.ts +0 -104
  144. package/src/tools/PanZoom.test.ts +0 -339
  145. package/src/tools/PanZoom.ts +0 -525
  146. package/src/tools/PasteHandler.ts +0 -94
  147. package/src/tools/Pen.test.ts +0 -260
  148. package/src/tools/Pen.ts +0 -284
  149. package/src/tools/PipetteTool.ts +0 -84
  150. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -29
  151. package/src/tools/SelectionTool/Selection.ts +0 -647
  152. package/src/tools/SelectionTool/SelectionHandle.ts +0 -142
  153. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -370
  154. package/src/tools/SelectionTool/SelectionTool.ts +0 -510
  155. package/src/tools/SelectionTool/TransformMode.ts +0 -112
  156. package/src/tools/SelectionTool/types.ts +0 -11
  157. package/src/tools/SoundUITool.ts +0 -221
  158. package/src/tools/TextTool.ts +0 -339
  159. package/src/tools/ToolController.ts +0 -224
  160. package/src/tools/ToolEnabledGroup.ts +0 -14
  161. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  162. package/src/tools/ToolbarShortcutHandler.ts +0 -39
  163. package/src/tools/UndoRedoShortcut.test.ts +0 -62
  164. package/src/tools/UndoRedoShortcut.ts +0 -24
  165. package/src/tools/keybindings.ts +0 -85
  166. package/src/tools/lib.ts +0 -22
  167. package/src/tools/localization.ts +0 -76
  168. package/src/types.ts +0 -151
  169. package/src/util/ReactiveValue.test.ts +0 -168
  170. package/src/util/ReactiveValue.ts +0 -241
  171. package/src/util/assertions.ts +0 -55
  172. package/src/util/fileToBase64.ts +0 -18
  173. package/src/util/guessKeyCodeFromKey.ts +0 -36
  174. package/src/util/listPrefixMatch.ts +0 -19
  175. package/src/util/stopPropagationOfScrollingWheelEvents.ts +0 -20
  176. package/src/util/untilNextAnimationFrame.ts +0 -9
  177. package/src/util/waitForAll.ts +0 -18
  178. package/src/util/waitForTimeout.ts +0 -9
  179. package/src/version.test.ts +0 -12
  180. package/src/version.ts +0 -3
  181. package/tools/allLocales.js +0 -4
  182. package/tools/copyREADME.ts +0 -62
@@ -1,224 +0,0 @@
1
- import { EditorEventType } from '../types';
2
- import { Color4 } from '@js-draw/math';
3
- import Editor from '../Editor';
4
- import BaseTool from './BaseTool';
5
- import PanZoom, { PanZoomMode } from './PanZoom';
6
- import Pen from './Pen';
7
- import ToolEnabledGroup from './ToolEnabledGroup';
8
- import Eraser from './Eraser';
9
- import SelectionTool from './SelectionTool/SelectionTool';
10
- import { ToolLocalization } from './localization';
11
- import UndoRedoShortcut from './UndoRedoShortcut';
12
- import TextTool from './TextTool';
13
- import PipetteTool from './PipetteTool';
14
- import ToolSwitcherShortcut from './ToolSwitcherShortcut';
15
- import PasteHandler from './PasteHandler';
16
- import ToolbarShortcutHandler from './ToolbarShortcutHandler';
17
- import { makePressureSensitiveFreehandLineBuilder } from '../components/builders/PressureSensitiveFreehandLineBuilder';
18
- import FindTool from './FindTool';
19
- import SelectAllShortcutHandler from './SelectionTool/SelectAllShortcutHandler';
20
- import SoundUITool from './SoundUITool';
21
- import InputMapper, { InputEventListener } from './InputFilter/InputMapper';
22
- import { InputEvt, InputEvtType } from '../inputEvents';
23
- import InputPipeline from './InputFilter/InputPipeline';
24
- import InputStabilizer from './InputFilter/InputStabilizer';
25
-
26
- export default class ToolController implements InputEventListener {
27
- private tools: BaseTool[];
28
- private activeTool: BaseTool|null = null;
29
- private primaryToolGroup: ToolEnabledGroup;
30
-
31
- // Form a pipeline that allows filtering/mapping input events.
32
- private inputPipeline: InputPipeline;
33
-
34
- /** @internal */
35
- public constructor(editor: Editor, localization: ToolLocalization) {
36
- this.inputPipeline = new InputPipeline();
37
- this.inputPipeline.setEmitListener(event => this.onEventInternal(event));
38
-
39
- const primaryToolGroup = new ToolEnabledGroup();
40
- this.primaryToolGroup = primaryToolGroup;
41
-
42
- const panZoomTool = new PanZoom(editor, PanZoomMode.TwoFingerTouchGestures | PanZoomMode.RightClickDrags, localization.touchPanTool);
43
- const keyboardPanZoomTool = new PanZoom(editor, PanZoomMode.Keyboard, localization.keyboardPanZoom);
44
- const primaryPenTool = new Pen(editor, localization.penTool(1), { color: Color4.purple, thickness: 8 });
45
- const secondaryPenTool = new Pen(editor, localization.penTool(2), { color: Color4.clay, thickness: 4 });
46
-
47
- // Stabilize the secondary pen tool.
48
- secondaryPenTool.setInputMapper(new InputStabilizer(editor.viewport));
49
-
50
- const primaryTools = [
51
- // Three pens
52
- primaryPenTool,
53
- secondaryPenTool,
54
-
55
- // Highlighter-like pen with width=40
56
- new Pen(
57
- editor,
58
- localization.penTool(3),
59
- {
60
- color: Color4.ofRGBA(1, 1, 0, 0.5),
61
- thickness: 40,
62
- factory: makePressureSensitiveFreehandLineBuilder
63
- }
64
- ),
65
-
66
- new Eraser(editor, localization.eraserTool),
67
- new SelectionTool(editor, localization.selectionTool),
68
- new TextTool(editor, localization.textTool, localization),
69
- new PanZoom(editor, PanZoomMode.SinglePointerGestures, localization.anyDevicePanning),
70
- ];
71
-
72
- // Accessibility tools
73
- const soundExplorer = new SoundUITool(editor, localization.soundExplorer);
74
- soundExplorer.setEnabled(false);
75
-
76
- this.tools = [
77
- new PipetteTool(editor, localization.pipetteTool),
78
- soundExplorer,
79
- panZoomTool,
80
- ...primaryTools,
81
- keyboardPanZoomTool,
82
- new UndoRedoShortcut(editor),
83
- new ToolbarShortcutHandler(editor),
84
- new ToolSwitcherShortcut(editor),
85
- new FindTool(editor),
86
- new PasteHandler(editor),
87
- new SelectAllShortcutHandler(editor),
88
- ];
89
- primaryTools.forEach(tool => tool.setToolGroup(primaryToolGroup));
90
- panZoomTool.setEnabled(true);
91
- primaryPenTool.setEnabled(true);
92
-
93
- editor.notifier.on(EditorEventType.ToolEnabled, event => {
94
- if (event.kind === EditorEventType.ToolEnabled) {
95
- editor.announceForAccessibility(localization.toolEnabledAnnouncement(event.tool.description));
96
- }
97
- });
98
- editor.notifier.on(EditorEventType.ToolDisabled, event => {
99
- if (event.kind === EditorEventType.ToolDisabled) {
100
- editor.announceForAccessibility(localization.toolDisabledAnnouncement(event.tool.description));
101
- }
102
- });
103
-
104
- this.activeTool = null;
105
- }
106
-
107
- // Replaces the current set of tools with `tools`. This should only be done before
108
- // the creation of the app's toolbar (if using `AbstractToolbar`).
109
- public setTools(tools: BaseTool[], primaryToolGroup?: ToolEnabledGroup) {
110
- this.tools = tools;
111
- this.primaryToolGroup = primaryToolGroup ?? new ToolEnabledGroup();
112
- }
113
-
114
- // Add a tool that acts like one of the primary tools (only one primary tool can be enabled at a time).
115
- // This should be called before creating the app's toolbar.
116
- public addPrimaryTool(tool: BaseTool) {
117
- tool.setToolGroup(this.primaryToolGroup);
118
- if (tool.isEnabled()) {
119
- this.primaryToolGroup.notifyEnabled(tool);
120
- }
121
-
122
- this.addTool(tool);
123
- }
124
-
125
- public getPrimaryTools(): BaseTool[] {
126
- return this.tools.filter(tool => {
127
- return tool.getToolGroup() === this.primaryToolGroup;
128
- });
129
- }
130
-
131
- // Add a tool to the end of this' tool list (the added tool receives events after tools already added to this).
132
- // This should be called before creating the app's toolbar.
133
- public addTool(tool: BaseTool) {
134
- this.tools.push(tool);
135
- }
136
-
137
- // @internal use `dispatchEvent` rather than calling `onEvent` directly.
138
- private onEventInternal(event: InputEvt): boolean {
139
- let handled = false;
140
- if (event.kind === InputEvtType.PointerDownEvt) {
141
- let canOnlySendToActiveTool = false;
142
- if (this.activeTool && !this.activeTool.eventCanBeDeliveredToNonActiveTool(event)) {
143
- canOnlySendToActiveTool = true;
144
- }
145
-
146
- for (const tool of this.tools) {
147
- if (canOnlySendToActiveTool && tool !== this.activeTool) {
148
- continue;
149
- }
150
-
151
- if (tool.isEnabled() && tool.onEvent(event)) {
152
- if (this.activeTool !== tool) {
153
- this.activeTool?.onEvent({ kind: InputEvtType.GestureCancelEvt });
154
- }
155
-
156
- this.activeTool = tool;
157
- handled = true;
158
- break;
159
- }
160
- }
161
- } else if (event.kind === InputEvtType.PointerUpEvt) {
162
- const upResult = this.activeTool?.onEvent(event);
163
- const continueHandlingEvents = upResult && event.allPointers.length > 1;
164
-
165
- // Should the active tool continue handling events (without an additional pointer down?)
166
- if (!continueHandlingEvents) {
167
- // No -- Remove the current tool
168
- this.activeTool = null;
169
- }
170
- handled = true;
171
- } else if (event.kind === InputEvtType.PointerMoveEvt) {
172
- if (this.activeTool !== null) {
173
- this.activeTool.onEvent(event);
174
- handled = true;
175
- }
176
- } else if (event.kind === InputEvtType.GestureCancelEvt) {
177
- if (this.activeTool !== null) {
178
- this.activeTool.onEvent(event);
179
- this.activeTool = null;
180
- }
181
- } else {
182
- for (const tool of this.tools) {
183
- if (!tool.isEnabled()) {
184
- continue;
185
- }
186
-
187
- handled = tool.onEvent(event);
188
- if (handled) {
189
- break;
190
- }
191
- }
192
- }
193
-
194
- return handled;
195
- }
196
-
197
- /** Alias for {@link dispatchInputEvent}. */
198
- public onEvent(event: InputEvt) {
199
- return this.dispatchInputEvent(event);
200
- }
201
-
202
- // Returns true if the event was handled.
203
- public dispatchInputEvent(event: InputEvt): boolean {
204
- // Feed the event through the input pipeline
205
- return this.inputPipeline.onEvent(event);
206
- }
207
-
208
- /**
209
- * Adds a new `InputMapper` to this' input pipeline.
210
- *
211
- * A `mapper` is really a relation that maps each event to no, one,
212
- * or many other events.
213
- *
214
- * @see {@link InputMapper}.
215
- */
216
- public addInputMapper(mapper: InputMapper) {
217
- this.inputPipeline.addToTail(mapper);
218
- }
219
-
220
- public getMatchingTools<Type extends BaseTool>(type: new (...args: any[])=>Type): Type[] {
221
- return this.tools.filter(tool => tool instanceof type) as Type[];
222
- }
223
- }
224
-
@@ -1,14 +0,0 @@
1
- import BaseTool from './BaseTool';
2
-
3
- // Connects a group of tools -- at most one tool in the group can be enabled.
4
- export default class ToolEnabledGroup {
5
- private activeTool: BaseTool|null;
6
- public constructor() { }
7
-
8
- public notifyEnabled(tool: BaseTool) {
9
- if (tool !== this.activeTool) {
10
- this.activeTool?.setEnabled(false);
11
- this.activeTool = tool;
12
- }
13
- }
14
- }
@@ -1,39 +0,0 @@
1
- import Editor from '../Editor';
2
- import { KeyPressEvent } from '../inputEvents';
3
- import BaseTool from './BaseTool';
4
-
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
- */
13
- export default class ToolSwitcherShortcut extends BaseTool {
14
- public constructor(private editor: Editor) {
15
- super(editor.notifier, editor.localization.changeTool);
16
- }
17
-
18
- // @internal
19
- public override onKeyPress({ key }: KeyPressEvent): boolean {
20
- const toolController = this.editor.toolController;
21
- const primaryTools = toolController.getPrimaryTools();
22
-
23
- // Map keys 0-9 to primary tools.
24
- const keyMatch = /^[0-9]$/.exec(key);
25
-
26
- let targetTool: BaseTool|undefined;
27
- if (keyMatch) {
28
- const targetIdx = parseInt(keyMatch[0], 10) - 1;
29
- targetTool = primaryTools[targetIdx];
30
- }
31
-
32
- if (targetTool) {
33
- targetTool.setEnabled(true);
34
- return true;
35
- }
36
-
37
- return false;
38
- }
39
- }
@@ -1,39 +0,0 @@
1
- // Allows the toolbar to register keyboard events.
2
- // @packageDocumentation
3
-
4
- import Editor from '../Editor';
5
- import { KeyPressEvent } from '../inputEvents';
6
- import BaseTool from './BaseTool';
7
-
8
- // Returns true if the event was handled, false otherwise.
9
- type KeyPressListener = (event: KeyPressEvent)=>boolean;
10
-
11
- export default class ToolbarShortcutHandler extends BaseTool {
12
- private listeners: Set<KeyPressListener> = new Set([]);
13
- public constructor(editor: Editor) {
14
- super(editor.notifier, editor.localization.changeTool);
15
- }
16
-
17
- public registerListener(listener: KeyPressListener) {
18
- this.listeners.add(listener);
19
- }
20
-
21
- public removeListener(listener: KeyPressListener) {
22
- this.listeners.delete(listener);
23
- }
24
-
25
- public override onKeyPress(event: KeyPressEvent): boolean {
26
- // TypeScript seems to automatically convert for of loops into for(init;check;update)
27
- // loops (even with target set to es6). Thus, we cannot iterate directly through the
28
- // set here.
29
- // See https://stackoverflow.com/q/48886500
30
- const listeners = Array.from(this.listeners.values());
31
- for (const listener of listeners) {
32
- if (listener(event)) {
33
- return true;
34
- }
35
- }
36
-
37
- return false;
38
- }
39
- }
@@ -1,62 +0,0 @@
1
- /* @jest-environment jsdom */
2
-
3
- import Stroke from '../components/Stroke';
4
- import EditorImage from '../EditorImage';
5
- import { Path, Color4 } from '@js-draw/math';
6
- import createEditor from '../testing/createEditor';
7
- import { InputEvtType } from '../inputEvents';
8
- import { pathToRenderable } from '../rendering/RenderablePathSpec';
9
-
10
- describe('UndoRedoShortcut', () => {
11
- const testStroke = new Stroke([pathToRenderable(Path.fromString('M0,0L10,10'), { fill: Color4.red })]);
12
- const addTestStrokeCommand = EditorImage.addElement(testStroke);
13
-
14
- it('ctrl+z should undo', () => {
15
- const editor = createEditor();
16
- editor.dispatch(addTestStrokeCommand);
17
- expect(editor.history.undoStackSize).toBe(1);
18
-
19
- editor.toolController.dispatchInputEvent({
20
- kind: InputEvtType.KeyPressEvent,
21
- ctrlKey: true,
22
- altKey: false,
23
- shiftKey: false,
24
- key: 'z',
25
- code: 'KeyZ',
26
- });
27
-
28
- expect(editor.history.undoStackSize).toBe(0);
29
- expect(editor.history.redoStackSize).toBe(1);
30
- });
31
-
32
- it('ctrl+shift+Z should re-do', () => {
33
- const editor = createEditor();
34
- editor.dispatch(addTestStrokeCommand);
35
- editor.dispatch(addTestStrokeCommand);
36
- expect(editor.history.undoStackSize).toBe(2);
37
-
38
- editor.toolController.dispatchInputEvent({
39
- kind: InputEvtType.KeyPressEvent,
40
- ctrlKey: true,
41
- altKey: false,
42
- shiftKey: false,
43
- key: 'z',
44
- code: 'KeyZ',
45
- });
46
-
47
- expect(editor.history.undoStackSize).toBe(1);
48
- expect(editor.history.redoStackSize).toBe(1);
49
-
50
- editor.toolController.dispatchInputEvent({
51
- kind: InputEvtType.KeyPressEvent,
52
- ctrlKey: true,
53
- altKey: false,
54
- shiftKey: true,
55
- key: 'Z',
56
- code: 'KeyZ',
57
- });
58
-
59
- expect(editor.history.undoStackSize).toBe(2);
60
- expect(editor.history.redoStackSize).toBe(0);
61
- });
62
- });
@@ -1,24 +0,0 @@
1
- import Editor from '../Editor';
2
- import { KeyPressEvent } from '../inputEvents';
3
- import BaseTool from './BaseTool';
4
- import { redoKeyboardShortcutId, undoKeyboardShortcutId } from './keybindings';
5
-
6
- // Handles ctrl+Z, ctrl+Shift+Z keyboard shortcuts.
7
- export default class UndoRedoShortcut extends BaseTool {
8
- public constructor(private editor: Editor) {
9
- super(editor.notifier, editor.localization.undoRedoTool);
10
- }
11
-
12
- // @internal
13
- public override onKeyPress(event: KeyPressEvent): boolean {
14
- if (this.editor.shortcuts.matchesShortcut(undoKeyboardShortcutId, event)) {
15
- this.editor.history.undo();
16
- return true;
17
- } else if (this.editor.shortcuts.matchesShortcut(redoKeyboardShortcutId, event)) {
18
- this.editor.history.redo();
19
- return true;
20
- }
21
-
22
- return false;
23
- }
24
- }
@@ -1,85 +0,0 @@
1
- import KeyboardShortcutManager from '../shortcuts/KeyboardShortcutManager';
2
-
3
- // This file contains user-overridable tool-realted keybindings.
4
-
5
- // Undo/redo
6
- export const undoKeyboardShortcutId = 'jsdraw.tools.undo';
7
- export const redoKeyboardShortcutId = 'jsdaw.tools.redo';
8
-
9
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
10
- undoKeyboardShortcutId, [ 'CtrlOrMeta+KeyZ' ], 'Undo'
11
- );
12
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
13
- redoKeyboardShortcutId, [ 'CtrlOrMeta+Shift+KeyZ', 'CtrlOrMeta+KeyY' ], 'Redo'
14
- );
15
-
16
- // Pen/eraser/selection keybindings
17
- export const increaseSizeKeyboardShortcutId = 'jsdraw.tools.increaseSize';
18
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
19
- increaseSizeKeyboardShortcutId, [ 'Equal', 'Shift+Equal' ], 'Increase pen/eraser size'
20
- );
21
- export const decreaseSizeKeyboardShortcutId = 'jsdraw.tools.decreaseSize';
22
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
23
- decreaseSizeKeyboardShortcutId, [ 'Minus', 'Shift+Minus' ], 'Decrease pen/eraser size'
24
- );
25
- export const snapToGridKeyboardShortcutId = 'jsdraw.tools.snapToGrid';
26
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
27
- snapToGridKeyboardShortcutId, [ 'Control', 'Meta' ], 'Snap to grid (press and hold)'
28
- );
29
- export const lineLockKeyboardShortcutId = 'jsdraw.tools.lockToLine';
30
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
31
- lineLockKeyboardShortcutId, [ 'Shift' ], 'Snap to XY axes (press and hold)'
32
- );
33
-
34
- // Find tool
35
- export const toggleFindVisibleShortcutId = 'js-draw.tools.FindTool.toggleVisible';
36
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
37
- toggleFindVisibleShortcutId,
38
- [ 'CtrlOrMeta+KeyF' ],
39
- 'Shows/hides the find tool'
40
- );
41
-
42
- // Pan/zoom
43
- export const moveLeftKeyboardShortcutId = 'jsdraw.tools.PanZoom.moveLeft';
44
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
45
- moveLeftKeyboardShortcutId, [ 'ArrowLeft', 'KeyH', 'KeyA' ], 'Pan left'
46
- );
47
- export const moveRightKeyboardShortcutId = 'jsdraw.tools.PanZoom.moveRight';
48
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
49
- moveRightKeyboardShortcutId, [ 'ArrowRight', 'KeyL', 'KeyD' ], 'Pan right'
50
- );
51
- export const moveUpKeyboardShortcutId = 'jsdraw.tools.PanZoom.moveUp';
52
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
53
- moveUpKeyboardShortcutId, [ 'ArrowUp', 'KeyK', 'KeyQ' ], 'Pan up'
54
- );
55
- export const moveDownKeyboardShortcutId = 'jsdraw.tools.PanZoom.moveDown';
56
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
57
- moveDownKeyboardShortcutId, [ 'ArrowDown', 'KeyJ', 'KeyE' ], 'Pan down'
58
- );
59
- export const rotateClockwiseKeyboardShortcutId = 'jsdraw.tools.PanZoom.rotateViewClockwise';
60
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
61
- rotateClockwiseKeyboardShortcutId, [ 'Shift+KeyR' ], 'Rotate viewport clockwise'
62
- );
63
- export const rotateCounterClockwiseKeyboardShortcutId = 'jsdraw.tools.PanZoom.rotateViewCounterClockwise';
64
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
65
- rotateCounterClockwiseKeyboardShortcutId, [ 'KeyR' ], 'Rotate viewport counter-clockwise'
66
- );
67
- export const zoomInKeyboardShortcutId = 'jsdraw.tools.PanZoom.zoomIn';
68
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
69
- zoomInKeyboardShortcutId, [ 'KeyW' ], 'Zoom in'
70
- );
71
- export const zoomOutKeyboardShortcutId = 'jsdraw.tools.PanZoom.zoomOut';
72
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
73
- zoomOutKeyboardShortcutId, [ 'KeyS' ], 'Zoom out'
74
- );
75
-
76
- // Selection
77
- export const selectAllKeyboardShortcut = 'jsdraw.tools.SelectionTool.selectAll';
78
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
79
- selectAllKeyboardShortcut, [ 'CtrlOrMeta+KeyA' ], 'Select all'
80
- );
81
- export const duplicateSelectionShortcut = 'jsdraw.tools.SelectionTool.duplicateSelection';
82
- KeyboardShortcutManager.registerDefaultKeyboardShortcut(
83
- duplicateSelectionShortcut, [ 'CtrlOrMeta+KeyD' ], 'Duplicate selection'
84
- );
85
-
package/src/tools/lib.ts DELETED
@@ -1,22 +0,0 @@
1
-
2
- /**
3
- * @packageDocumentation
4
- */
5
-
6
- export { default as BaseTool } from './BaseTool';
7
- export { default as ToolController } from './ToolController';
8
- export { default as ToolEnabledGroup } from './ToolEnabledGroup';
9
-
10
- export { default as UndoRedoShortcut } from './UndoRedoShortcut';
11
- export { default as ToolSwitcherShortcut } from './ToolSwitcherShortcut';
12
- export { default as PanZoomTool, PanZoomMode } from './PanZoom';
13
-
14
- export { default as PenTool, PenStyle } from './Pen';
15
- export { default as TextTool } from './TextTool';
16
- export { default as SelectionTool } from './SelectionTool/SelectionTool';
17
- export { default as SelectAllShortcutHandler } from './SelectionTool/SelectAllShortcutHandler';
18
- export { default as EraserTool } from './Eraser';
19
- export { default as PasteHandler } from './PasteHandler';
20
- export { default as SoundUITool } from './SoundUITool';
21
-
22
- export { default as ToolbarShortcutHandler } from './ToolbarShortcutHandler';
@@ -1,76 +0,0 @@
1
-
2
- export interface ToolLocalization {
3
- keyboardPanZoom: string;
4
- penTool: (penId: number)=>string;
5
- selectionTool: string;
6
- selectAllTool: string;
7
- eraserTool: string;
8
- touchPanTool: string;
9
- twoFingerPanZoomTool: string;
10
- undoRedoTool: string;
11
- pipetteTool: string;
12
- rightClickDragPanTool: string;
13
-
14
- textTool: string;
15
- enterTextToInsert: string;
16
- changeTool: string;
17
- pasteHandler: string;
18
-
19
- soundExplorer: string;
20
- disableAccessibilityExploreTool: string;
21
- enableAccessibilityExploreTool: string;
22
- soundExplorerUsageAnnouncement: string;
23
-
24
- findLabel: string;
25
- toNextMatch: string;
26
- closeDialog: string;
27
- findDialogShown: string;
28
- findDialogHidden: string;
29
- focusedFoundText: (currentMatchNumber: number, totalMatches: number)=> string;
30
-
31
- anyDevicePanning: string;
32
-
33
- copied: (count: number, description: string) => string;
34
- pasted: (count: number, description: string) => string;
35
-
36
- toolEnabledAnnouncement: (toolName: string) => string;
37
- toolDisabledAnnouncement: (toolName: string) => string;
38
- }
39
-
40
- export const defaultToolLocalization: ToolLocalization = {
41
- penTool: (penId) => `Pen ${penId}`,
42
- selectionTool: 'Selection',
43
- selectAllTool: 'Select all shortcut',
44
- eraserTool: 'Eraser',
45
- touchPanTool: 'Touch panning',
46
- twoFingerPanZoomTool: 'Panning and zooming',
47
- undoRedoTool: 'Undo/Redo',
48
- rightClickDragPanTool: 'Right-click drag',
49
- pipetteTool: 'Pick color from screen',
50
- keyboardPanZoom: 'Keyboard pan/zoom shortcuts',
51
-
52
- textTool: 'Text',
53
- enterTextToInsert: 'Text to insert',
54
- changeTool: 'Change tool',
55
- pasteHandler: 'Copy paste handler',
56
-
57
- soundExplorer: 'Sound-based image exploration',
58
- disableAccessibilityExploreTool: 'Disable sound-based exploration',
59
- enableAccessibilityExploreTool: 'Enable sound-based exploration',
60
- soundExplorerUsageAnnouncement: 'Sound-based image exploration enabled: Click/drag the screen to play a sound representation of different parts of the image.',
61
-
62
- findLabel: 'Find',
63
- toNextMatch: 'Next',
64
- closeDialog: 'Close',
65
- findDialogShown: 'Find dialog shown',
66
- findDialogHidden: 'Find dialog hidden',
67
- focusedFoundText: (matchIdx: number, totalMatches: number) => `Viewing match ${matchIdx} of ${totalMatches}`,
68
-
69
- anyDevicePanning: 'Any device panning',
70
-
71
- copied: (count: number, description: string) => `Copied ${count} ${description}`,
72
- pasted: (count: number, description: string) => `Pasted ${count} ${description}`,
73
-
74
- toolEnabledAnnouncement: (toolName) => `${toolName} enabled`,
75
- toolDisabledAnnouncement: (toolName) => `${toolName} disabled`,
76
- };