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,220 +0,0 @@
1
- import Editor from '../Editor';
2
- import { defaultToolbarLocalization, ToolbarLocalization } from './localization';
3
- import BaseWidget from './widgets/BaseWidget';
4
- import OverflowWidget from './widgets/OverflowWidget';
5
- import AbstractToolbar, { SpacerOptions } from './AbstractToolbar';
6
- import { toolbarCSSPrefix } from './constants';
7
-
8
- export const makeDropdownToolbar = (editor: Editor): AbstractToolbar => {
9
- return new DropdownToolbar(editor, editor.getRootElement());
10
- };
11
-
12
- export default class DropdownToolbar extends AbstractToolbar {
13
- protected container: HTMLElement;
14
- private resizeObserver: ResizeObserver;
15
-
16
- // Flex-order of the next widget to be added.
17
- private widgetOrderCounter: number = 0;
18
-
19
- // Widget to toggle overflow menu.
20
- private overflowWidget: OverflowWidget|null = null;
21
-
22
- /** @internal */
23
- public constructor(
24
- editor: Editor, parent: HTMLElement,
25
- localizationTable: ToolbarLocalization = defaultToolbarLocalization,
26
- ) {
27
- super(editor, localizationTable);
28
-
29
- this.container = document.createElement('div');
30
- this.container.classList.add(`${toolbarCSSPrefix}root`);
31
- this.container.classList.add(`${toolbarCSSPrefix}element`);
32
- this.container.classList.add(`${toolbarCSSPrefix}dropdown-toolbar`);
33
- this.container.setAttribute('role', 'toolbar');
34
- parent.appendChild(this.container);
35
-
36
- if ('ResizeObserver' in window) {
37
- this.resizeObserver = new ResizeObserver((_entries) => {
38
- this.reLayout();
39
- });
40
- this.resizeObserver.observe(this.container);
41
- } else {
42
- console.warn('ResizeObserver not supported. Toolbar will not resize.');
43
- }
44
- }
45
-
46
- private reLayoutQueued: boolean = false;
47
- private queueReLayout() {
48
- if (!this.reLayoutQueued) {
49
- this.reLayoutQueued = true;
50
- requestAnimationFrame(() => this.reLayout());
51
- }
52
- }
53
-
54
- private reLayout() {
55
- this.reLayoutQueued = false;
56
-
57
- if (!this.overflowWidget) {
58
- return;
59
- }
60
-
61
- const getTotalWidth = (widgetList: Array<BaseWidget>) => {
62
- let totalWidth = 0;
63
- for (const widget of widgetList) {
64
- if (!widget.isHidden()) {
65
- totalWidth += widget.getButtonWidth();
66
- }
67
- }
68
-
69
- return totalWidth;
70
- };
71
-
72
- // Returns true if there is enough empty space to move the first child
73
- // from the overflow menu to the main menu.
74
- const canRemoveFirstChildFromOverflow = (freeSpaceInMainMenu: number) => {
75
- const overflowChildren = this.overflowWidget?.getChildWidgets() ?? [];
76
-
77
- if (overflowChildren.length === 0) {
78
- return false;
79
- }
80
-
81
- return overflowChildren[0].getButtonWidth() <= freeSpaceInMainMenu;
82
- };
83
-
84
- const allWidgets = this.getAllWidgets();
85
-
86
- let overflowWidgetsWidth = getTotalWidth(this.overflowWidget.getChildWidgets());
87
- let shownWidgetWidth = getTotalWidth(allWidgets) - overflowWidgetsWidth;
88
- let availableWidth = this.container.clientWidth * 0.87;
89
-
90
- // If on a device that has enough vertical space, allow
91
- // showing two rows of buttons.
92
- // TODO: Fix magic numbers
93
- if (window.innerHeight > availableWidth * 1.75) {
94
- availableWidth *= 1.75;
95
- }
96
-
97
- let updatedChildren = false;
98
-
99
- // If we can remove at least one child from the overflow menu,
100
- if (canRemoveFirstChildFromOverflow(availableWidth - shownWidgetWidth)) {
101
- // Move widgets to the main menu.
102
- const overflowChildren = this.overflowWidget.clearChildren();
103
-
104
- for (const child of overflowChildren) {
105
- child.addTo(this.container);
106
- child.setIsToplevel(true);
107
-
108
- if (!child.isHidden()) {
109
- shownWidgetWidth += child.getButtonWidth();
110
- }
111
- }
112
-
113
- overflowWidgetsWidth = 0;
114
- updatedChildren = true;
115
- }
116
-
117
- if (shownWidgetWidth >= availableWidth) {
118
- // Move widgets to the overflow menu.
119
-
120
- // Start with the rightmost widget, move to the leftmost
121
- for (
122
- let i = allWidgets.length - 1;
123
- i >= 0 && shownWidgetWidth >= availableWidth;
124
- i--
125
- ) {
126
- const child = allWidgets[i];
127
-
128
- if (this.overflowWidget.hasAsChild(child)) {
129
- continue;
130
- }
131
-
132
- if (child.canBeInOverflowMenu()) {
133
- shownWidgetWidth -= child.getButtonWidth();
134
- this.overflowWidget.addToOverflow(child);
135
- }
136
- }
137
-
138
- updatedChildren = true;
139
- }
140
-
141
- // Hide/show the overflow widget.
142
- this.overflowWidget.setHidden(this.overflowWidget.getChildWidgets().length === 0);
143
-
144
- if (updatedChildren) {
145
- this.setupColorPickers();
146
- }
147
- }
148
-
149
- protected override addWidgetInternal(widget: BaseWidget) {
150
- const container = widget.addTo(this.container);
151
-
152
- // Ensure that the widget gets displayed in the correct
153
- // place in the toolbar, even if it's removed and re-added.
154
- container.style.order = `${this.widgetOrderCounter++}`;
155
-
156
- this.queueReLayout();
157
- }
158
-
159
- protected override removeWidgetInternal(widget: BaseWidget): void {
160
- widget.remove();
161
- this.queueReLayout();
162
- }
163
-
164
- public override addSpacer(options: Partial<SpacerOptions> = {}) {
165
- const spacer = document.createElement('div');
166
- spacer.classList.add(`${toolbarCSSPrefix}spacer`);
167
-
168
- if (options.grow) {
169
- spacer.style.flexGrow = `${options.grow}`;
170
- }
171
-
172
- if (options.minSize) {
173
- spacer.style.minWidth = options.minSize;
174
- }
175
-
176
- if (options.maxSize) {
177
- spacer.style.maxWidth = options.maxSize;
178
- }
179
-
180
- spacer.style.order = `${this.widgetOrderCounter++}`;
181
- this.container.appendChild(spacer);
182
- }
183
-
184
- /**
185
- * Adds a widget that toggles the overflow menu. Call `addOverflowWidget` to ensure
186
- * that this widget is in the correct space (if shown).
187
- *
188
- * @example
189
- * ```ts
190
- * toolbar.addDefaultToolWidgets();
191
- * toolbar.addOverflowWidget();
192
- * toolbar.addDefaultActionButtons();
193
- * ```
194
- * shows the overflow widget between the default tool widgets and the default action buttons,
195
- * if shown.
196
- */
197
- public addOverflowWidget() {
198
- this.overflowWidget = new OverflowWidget(this.editor, this.localizationTable);
199
- this.addWidget(this.overflowWidget);
200
- }
201
-
202
- /**
203
- * Adds both the default tool widgets and action buttons. Equivalent to
204
- * ```ts
205
- * toolbar.addDefaultToolWidgets();
206
- * toolbar.addOverflowWidget();
207
- * toolbar.addDefaultActionButtons();
208
- * ```
209
- */
210
- public addDefaults() {
211
- this.addDefaultToolWidgets();
212
- this.addOverflowWidget();
213
- this.addDefaultActionButtons();
214
- }
215
-
216
- protected override onRemove() {
217
- this.container.remove();
218
- this.resizeObserver.disconnect();
219
- }
220
- }
@@ -1,54 +0,0 @@
1
- import createEditor from '../testing/createEditor';
2
- import { makeEdgeToolbar } from './EdgeToolbar';
3
-
4
- describe('EdgeToolbar', () => {
5
- it('should add widgets when calling .addDefaults', () => {
6
- const editor = createEditor();
7
- const toolbar = makeEdgeToolbar(editor);
8
-
9
- // Before calling .addDefaults, the toolbar should exist, but have no
10
- // widgets.
11
- const editorRoot = editor.getRootElement();
12
- expect(editorRoot.querySelectorAll('.toolbar-edge-toolbar')).toHaveLength(1);
13
- expect(editorRoot.querySelectorAll('.toolbar-edge-toolbar .toolbar-button')).toHaveLength(0);
14
-
15
- toolbar.addDefaults();
16
-
17
- // After, should have widgets.
18
- expect(
19
- editorRoot.querySelectorAll('.toolbar-edge-toolbar .toolbar-button').length
20
- ).toBeGreaterThan(0);
21
- });
22
-
23
- it('clicking on a tool button should open the associated menu', () => {
24
- const editor = createEditor();
25
- const toolbar = makeEdgeToolbar(editor);
26
- toolbar.addDefaultToolWidgets();
27
-
28
- const editorRoot = editor.getRootElement();
29
- const toolButtons = editorRoot.querySelectorAll('.toolbar-edge-toolbar .toolbar-button');
30
- const edgemenuContainer = editorRoot.querySelector('.toolbar-edgemenu-container')! as HTMLElement;
31
-
32
- expect(edgemenuContainer).toBeTruthy();
33
- expect(toolButtons.length).toBeGreaterThan(3);
34
-
35
- // Before clicking a button, the edgemenu container should have display set to none
36
- expect(getComputedStyle(edgemenuContainer).display).toBe('none');
37
-
38
- const firstButton = toolButtons[0] as HTMLElement;
39
- firstButton.click();
40
-
41
- // After clicking, should have non-none visibility
42
- expect(getComputedStyle(edgemenuContainer).display).not.toBe('none');
43
- expect(getComputedStyle(edgemenuContainer).opacity).not.toBe('0'); // Should be fading in
44
-
45
- // The focused button should close the toolbar when clicked (and be within the menu container).
46
- const closeButton = edgemenuContainer.querySelector(':focus')! as HTMLElement;
47
- expect(closeButton).toBeTruthy();
48
-
49
- closeButton.click();
50
-
51
- // The edge menu should be fading out.
52
- expect(getComputedStyle(edgemenuContainer).opacity).toBe('0');
53
- });
54
- });