js-draw 1.0.1 → 1.1.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 (197) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Editor.css +1 -0
  3. package/dist/bundle.js +1 -1
  4. package/dist/bundledStyles.js +1 -1
  5. package/dist/cjs/toolbar/AbstractToolbar.d.ts +9 -13
  6. package/dist/cjs/toolbar/AbstractToolbar.js +14 -19
  7. package/dist/cjs/toolbar/widgets/SaveActionWidget.d.ts +10 -0
  8. package/dist/cjs/toolbar/widgets/SaveActionWidget.js +26 -0
  9. package/dist/cjs/toolbar/widgets/keybindings.d.ts +1 -0
  10. package/dist/cjs/toolbar/widgets/keybindings.js +4 -1
  11. package/dist/cjs/version.js +1 -1
  12. package/dist/mjs/toolbar/AbstractToolbar.d.ts +9 -13
  13. package/dist/mjs/toolbar/AbstractToolbar.mjs +14 -19
  14. package/dist/mjs/toolbar/widgets/SaveActionWidget.d.ts +10 -0
  15. package/dist/mjs/toolbar/widgets/SaveActionWidget.mjs +21 -0
  16. package/dist/mjs/toolbar/widgets/keybindings.d.ts +1 -0
  17. package/dist/mjs/toolbar/widgets/keybindings.mjs +3 -0
  18. package/dist/mjs/version.mjs +1 -1
  19. package/docs/img/readme-images/js-draw.jpg +0 -0
  20. package/docs/img/readme-images/unsupported-elements--in-editor.png +0 -0
  21. package/package.json +5 -4
  22. package/src/toolbar/EdgeToolbar.scss +1 -0
  23. package/dist-test/test_imports/package-lock.json +0 -13
  24. package/dist-test/test_imports/package.json +0 -12
  25. package/dist-test/test_imports/test-imports.js +0 -11
  26. package/dist-test/test_imports/test-require.cjs +0 -14
  27. package/src/Editor.loadFrom.test.ts +0 -24
  28. package/src/Editor.test.ts +0 -107
  29. package/src/Editor.toSVG.test.ts +0 -294
  30. package/src/Editor.ts +0 -1443
  31. package/src/EditorImage.test.ts +0 -117
  32. package/src/EditorImage.ts +0 -609
  33. package/src/EventDispatcher.test.ts +0 -123
  34. package/src/EventDispatcher.ts +0 -72
  35. package/src/Pointer.ts +0 -183
  36. package/src/SVGLoader.test.ts +0 -114
  37. package/src/SVGLoader.ts +0 -672
  38. package/src/UndoRedoHistory.test.ts +0 -34
  39. package/src/UndoRedoHistory.ts +0 -102
  40. package/src/Viewport.ts +0 -322
  41. package/src/bundle/bundled.ts +0 -7
  42. package/src/commands/Command.ts +0 -45
  43. package/src/commands/Duplicate.ts +0 -75
  44. package/src/commands/Erase.ts +0 -95
  45. package/src/commands/SerializableCommand.ts +0 -49
  46. package/src/commands/UnresolvedCommand.ts +0 -37
  47. package/src/commands/invertCommand.ts +0 -58
  48. package/src/commands/lib.ts +0 -16
  49. package/src/commands/localization.ts +0 -47
  50. package/src/commands/uniteCommands.test.ts +0 -23
  51. package/src/commands/uniteCommands.ts +0 -140
  52. package/src/components/AbstractComponent.transformBy.test.ts +0 -23
  53. package/src/components/AbstractComponent.ts +0 -383
  54. package/src/components/BackgroundComponent.test.ts +0 -44
  55. package/src/components/BackgroundComponent.ts +0 -348
  56. package/src/components/ImageComponent.ts +0 -176
  57. package/src/components/RestylableComponent.ts +0 -161
  58. package/src/components/SVGGlobalAttributesObject.ts +0 -79
  59. package/src/components/Stroke.test.ts +0 -137
  60. package/src/components/Stroke.ts +0 -294
  61. package/src/components/TextComponent.test.ts +0 -202
  62. package/src/components/TextComponent.ts +0 -429
  63. package/src/components/UnknownSVGObject.test.ts +0 -10
  64. package/src/components/UnknownSVGObject.ts +0 -60
  65. package/src/components/builders/ArrowBuilder.ts +0 -106
  66. package/src/components/builders/CircleBuilder.ts +0 -100
  67. package/src/components/builders/FreehandLineBuilder.test.ts +0 -24
  68. package/src/components/builders/FreehandLineBuilder.ts +0 -210
  69. package/src/components/builders/LineBuilder.ts +0 -77
  70. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -453
  71. package/src/components/builders/RectangleBuilder.ts +0 -73
  72. package/src/components/builders/types.ts +0 -15
  73. package/src/components/lib.ts +0 -31
  74. package/src/components/localization.ts +0 -24
  75. package/src/components/util/StrokeSmoother.ts +0 -302
  76. package/src/components/util/describeComponentList.ts +0 -18
  77. package/src/dialogs/makeAboutDialog.ts +0 -82
  78. package/src/inputEvents.ts +0 -143
  79. package/src/lib.ts +0 -91
  80. package/src/localization.ts +0 -34
  81. package/src/localizations/de.ts +0 -146
  82. package/src/localizations/en.ts +0 -8
  83. package/src/localizations/es.ts +0 -74
  84. package/src/localizations/getLocalizationTable.test.ts +0 -27
  85. package/src/localizations/getLocalizationTable.ts +0 -74
  86. package/src/rendering/Display.ts +0 -247
  87. package/src/rendering/RenderablePathSpec.ts +0 -88
  88. package/src/rendering/RenderingStyle.test.ts +0 -68
  89. package/src/rendering/RenderingStyle.ts +0 -55
  90. package/src/rendering/TextRenderingStyle.ts +0 -55
  91. package/src/rendering/caching/CacheRecord.test.ts +0 -48
  92. package/src/rendering/caching/CacheRecord.ts +0 -76
  93. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  94. package/src/rendering/caching/RenderingCache.test.ts +0 -43
  95. package/src/rendering/caching/RenderingCache.ts +0 -66
  96. package/src/rendering/caching/RenderingCacheNode.ts +0 -404
  97. package/src/rendering/caching/testUtils.ts +0 -35
  98. package/src/rendering/caching/types.ts +0 -34
  99. package/src/rendering/lib.ts +0 -8
  100. package/src/rendering/localization.ts +0 -20
  101. package/src/rendering/renderers/AbstractRenderer.ts +0 -232
  102. package/src/rendering/renderers/CanvasRenderer.ts +0 -312
  103. package/src/rendering/renderers/DummyRenderer.test.ts +0 -41
  104. package/src/rendering/renderers/DummyRenderer.ts +0 -142
  105. package/src/rendering/renderers/SVGRenderer.ts +0 -434
  106. package/src/rendering/renderers/TextOnlyRenderer.test.ts +0 -34
  107. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -68
  108. package/src/shortcuts/KeyBinding.test.ts +0 -61
  109. package/src/shortcuts/KeyBinding.ts +0 -257
  110. package/src/shortcuts/KeyboardShortcutManager.test.ts +0 -95
  111. package/src/shortcuts/KeyboardShortcutManager.ts +0 -163
  112. package/src/shortcuts/lib.ts +0 -3
  113. package/src/testing/createEditor.ts +0 -11
  114. package/src/testing/getUniquePointerId.ts +0 -18
  115. package/src/testing/lib.ts +0 -3
  116. package/src/testing/sendPenEvent.ts +0 -36
  117. package/src/testing/sendTouchEvent.ts +0 -71
  118. package/src/toolbar/AbstractToolbar.ts +0 -542
  119. package/src/toolbar/DropdownToolbar.ts +0 -220
  120. package/src/toolbar/EdgeToolbar.test.ts +0 -54
  121. package/src/toolbar/EdgeToolbar.ts +0 -543
  122. package/src/toolbar/IconProvider.ts +0 -861
  123. package/src/toolbar/constants.ts +0 -1
  124. package/src/toolbar/lib.ts +0 -6
  125. package/src/toolbar/localization.ts +0 -136
  126. package/src/toolbar/types.ts +0 -13
  127. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  128. package/src/toolbar/widgets/BaseToolWidget.ts +0 -81
  129. package/src/toolbar/widgets/BaseWidget.ts +0 -495
  130. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -250
  131. package/src/toolbar/widgets/EraserToolWidget.ts +0 -84
  132. package/src/toolbar/widgets/HandToolWidget.ts +0 -239
  133. package/src/toolbar/widgets/InsertImageWidget.ts +0 -248
  134. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  135. package/src/toolbar/widgets/PenToolWidget.ts +0 -369
  136. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -195
  137. package/src/toolbar/widgets/TextToolWidget.ts +0 -149
  138. package/src/toolbar/widgets/components/makeColorInput.ts +0 -184
  139. package/src/toolbar/widgets/components/makeFileInput.ts +0 -128
  140. package/src/toolbar/widgets/components/makeGridSelector.ts +0 -179
  141. package/src/toolbar/widgets/components/makeSeparator.ts +0 -17
  142. package/src/toolbar/widgets/components/makeThicknessSlider.ts +0 -62
  143. package/src/toolbar/widgets/keybindings.ts +0 -19
  144. package/src/toolbar/widgets/layout/DropdownLayoutManager.ts +0 -262
  145. package/src/toolbar/widgets/layout/EdgeToolbarLayoutManager.ts +0 -71
  146. package/src/toolbar/widgets/layout/types.ts +0 -74
  147. package/src/toolbar/widgets/lib.ts +0 -13
  148. package/src/tools/BaseTool.ts +0 -169
  149. package/src/tools/Eraser.test.ts +0 -103
  150. package/src/tools/Eraser.ts +0 -173
  151. package/src/tools/FindTool.test.ts +0 -67
  152. package/src/tools/FindTool.ts +0 -153
  153. package/src/tools/InputFilter/FunctionMapper.ts +0 -17
  154. package/src/tools/InputFilter/InputMapper.ts +0 -41
  155. package/src/tools/InputFilter/InputPipeline.test.ts +0 -41
  156. package/src/tools/InputFilter/InputPipeline.ts +0 -34
  157. package/src/tools/InputFilter/InputStabilizer.ts +0 -254
  158. package/src/tools/InputFilter/StrokeKeyboardControl.ts +0 -104
  159. package/src/tools/PanZoom.test.ts +0 -339
  160. package/src/tools/PanZoom.ts +0 -525
  161. package/src/tools/PasteHandler.ts +0 -94
  162. package/src/tools/Pen.test.ts +0 -260
  163. package/src/tools/Pen.ts +0 -284
  164. package/src/tools/PipetteTool.ts +0 -84
  165. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -29
  166. package/src/tools/SelectionTool/Selection.ts +0 -647
  167. package/src/tools/SelectionTool/SelectionHandle.ts +0 -142
  168. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -370
  169. package/src/tools/SelectionTool/SelectionTool.ts +0 -510
  170. package/src/tools/SelectionTool/TransformMode.ts +0 -112
  171. package/src/tools/SelectionTool/types.ts +0 -11
  172. package/src/tools/SoundUITool.ts +0 -221
  173. package/src/tools/TextTool.ts +0 -339
  174. package/src/tools/ToolController.ts +0 -224
  175. package/src/tools/ToolEnabledGroup.ts +0 -14
  176. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  177. package/src/tools/ToolbarShortcutHandler.ts +0 -39
  178. package/src/tools/UndoRedoShortcut.test.ts +0 -62
  179. package/src/tools/UndoRedoShortcut.ts +0 -24
  180. package/src/tools/keybindings.ts +0 -85
  181. package/src/tools/lib.ts +0 -22
  182. package/src/tools/localization.ts +0 -76
  183. package/src/types.ts +0 -151
  184. package/src/util/ReactiveValue.test.ts +0 -168
  185. package/src/util/ReactiveValue.ts +0 -241
  186. package/src/util/assertions.ts +0 -55
  187. package/src/util/fileToBase64.ts +0 -18
  188. package/src/util/guessKeyCodeFromKey.ts +0 -36
  189. package/src/util/listPrefixMatch.ts +0 -19
  190. package/src/util/stopPropagationOfScrollingWheelEvents.ts +0 -20
  191. package/src/util/untilNextAnimationFrame.ts +0 -9
  192. package/src/util/waitForAll.ts +0 -18
  193. package/src/util/waitForTimeout.ts +0 -9
  194. package/src/version.test.ts +0 -12
  195. package/src/version.ts +0 -3
  196. package/tools/allLocales.js +0 -4
  197. package/tools/copyREADME.ts +0 -62
@@ -1,861 +0,0 @@
1
- import { Vec2, Color4 } from '@js-draw/math';
2
- import SVGRenderer from '../rendering/renderers/SVGRenderer';
3
- import TextRenderingStyle from '../rendering/TextRenderingStyle';
4
- import { PenStyle } from '../tools/Pen';
5
- import { StrokeDataPoint } from '../types';
6
- import Viewport from '../Viewport';
7
- import { makeFreehandLineBuilder } from '../components/builders/FreehandLineBuilder';
8
-
9
- export type IconElemType = HTMLImageElement|SVGElement;
10
-
11
- const svgNamespace = 'http://www.w3.org/2000/svg';
12
- const iconColorFill = `
13
- style='fill: var(--icon-color);'
14
- `;
15
- const iconColorStrokeFill = `
16
- style='fill: var(--icon-color); stroke: var(--icon-color);'
17
- `;
18
-
19
- let checkerboardIdCounter = 0;
20
- const makeCheckerboardPattern = () => {
21
- const id = `checkerboard-${checkerboardIdCounter++}`;
22
- const patternDef = `
23
- <pattern
24
- id='${id}'
25
- viewBox='0,0,10,10'
26
- width='20%'
27
- height='20%'
28
- patternUnits='userSpaceOnUse'
29
- >
30
- <rect x='0' y='0' width='10' height='10' fill='white'/>
31
- <rect x='0' y='0' width='5' height='5' fill='gray'/>
32
- <rect x='5' y='5' width='5' height='5' fill='gray'/>
33
- </pattern>
34
- `;
35
- const patternRef = `url(#${id})`;
36
-
37
- return { patternDef, patternRef };
38
- };
39
-
40
- const makeRedoIcon = (mirror: boolean) => {
41
- const icon = document.createElementNS(svgNamespace, 'svg');
42
- icon.innerHTML = `
43
- <style>
44
- .toolbar-svg-undo-redo-icon {
45
- stroke: var(--icon-color);
46
- stroke-width: 12;
47
- stroke-linejoin: round;
48
- stroke-linecap: round;
49
- fill: none;
50
-
51
- transform-origin: center;
52
- }
53
- </style>
54
- <path
55
- d='M20,20 A15,15 0 0 1 70,80 L80,90 L60,70 L65,90 L87,90 L65,80'
56
- class='toolbar-svg-undo-redo-icon'
57
- style='${mirror ? 'transform: scale(-1, 1);' : ''}'/>
58
- `;
59
- icon.setAttribute('viewBox', '0 0 100 100');
60
- return icon;
61
- };
62
-
63
-
64
- /**
65
- * Provides icons that can be used in the toolbar, etc.
66
- * Extend this class and override methods to customize icons.
67
- *
68
- * @example
69
- * ```ts,runnable
70
- * import * as jsdraw from 'js-draw';
71
- *
72
- * class CustomIconProvider extends jsdraw.IconProvider {
73
- * // Use '☺' instead of the default dropdown symbol.
74
- * public makeDropdownIcon() {
75
- * const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
76
- * icon.innerHTML = `
77
- * <text x='5' y='55' style='fill: var(--icon-color); font-size: 50pt;'>☺</text>
78
- * `;
79
- * icon.setAttribute('viewBox', '0 0 100 100');
80
- * return icon;
81
- * }
82
- * }
83
- *
84
- * const icons = new CustomIconProvider();
85
- * const editor = new jsdraw.Editor(document.body, {
86
- * iconProvider: icons,
87
- * });
88
- *
89
- * // Add a toolbar that uses these icons
90
- * jsdraw.makeDropdownToolbar(editor).addDefaults();
91
- * ```
92
- */
93
- export default class IconProvider {
94
- public makeUndoIcon(): IconElemType {
95
- return makeRedoIcon(true);
96
- }
97
-
98
- // @param mirror - reflect across the x-axis. This parameter is internal.
99
- // @returns a redo icon.
100
- public makeRedoIcon(): IconElemType {
101
- return makeRedoIcon(false);
102
- }
103
-
104
- public makeDropdownIcon(): IconElemType {
105
- const icon = document.createElementNS(svgNamespace, 'svg');
106
- icon.innerHTML = `
107
- <g>
108
- <path
109
- d='M5,10 L50,90 L95,10 Z'
110
- ${iconColorFill}
111
- />
112
- </g>
113
- `;
114
- icon.setAttribute('viewBox', '-10 -10 110 110');
115
- return icon;
116
- }
117
-
118
- public makeEraserIcon(eraserSize?: number): IconElemType {
119
- const icon = document.createElementNS(svgNamespace, 'svg');
120
- eraserSize ??= 10;
121
-
122
- const scaledSize = eraserSize / 4;
123
- const eraserColor = '#ff70af';
124
-
125
- // Draw an eraser-like shape. Created with Inkscape
126
- icon.innerHTML = `
127
- <g>
128
- <path
129
- style="fill:${eraserColor}"
130
- stroke="black"
131
- transform="rotate(41.35)"
132
- d="M 52.5 27
133
- C 50 28.9 48.9 31.7 48.9 34.8
134
- L 48.9 39.8
135
- C 48.9 45.3 53.4 49.8 58.9 49.8
136
- L 103.9 49.8
137
- C 105.8 49.8 107.6 49.2 109.1 48.3
138
- L 110.2 ${scaledSize + 49.5} L 159.7 ${scaledSize + 5}
139
- L 157.7 ${-scaledSize + 5.2} L 112.4 ${49.5 - scaledSize}
140
- C 113.4 43.5 113.9 41.7 113.9 39.8
141
- L 113.9 34.8
142
- C 113.9 29.3 109.4 24.8 103.9 24.8
143
- L 58.9 24.8
144
- C 56.5 24.8 54.3 25.7 52.5 27
145
- z "
146
- id="path438" />
147
-
148
- <rect
149
- stroke="#cc8077"
150
- ${iconColorFill}
151
- id="rect218"
152
- width="65"
153
- height="75"
154
- x="48.9"
155
- y="-38.7"
156
- transform="rotate(41.35)" />
157
- </g>
158
- `;
159
- icon.setAttribute('viewBox', '0 0 120 120');
160
- return icon;
161
- }
162
-
163
- public makeSelectionIcon(): IconElemType {
164
- const icon = document.createElementNS(svgNamespace, 'svg');
165
-
166
- // Draw a cursor-like shape
167
- icon.innerHTML = `
168
- <g>
169
- <rect x=10 y=10 width=70 height=70 fill='pink' stroke='black'/>
170
- <rect x=75 y=75 width=10 height=10 fill='white' stroke='black'/>
171
- </g>
172
- `;
173
- icon.setAttribute('viewBox', '0 0 100 100');
174
-
175
- return icon;
176
- }
177
-
178
- public makeHandToolIcon(): IconElemType {
179
- const fill = 'none';
180
- const strokeColor = 'var(--icon-color)';
181
- const strokeWidth = '3';
182
-
183
- // Draw a cursor-like shape
184
- return this.makeIconFromPath(`
185
- m 10,60
186
- 5,30
187
- H 90
188
- V 30
189
- C 90,20 75,20 75,30
190
- V 60
191
- 20
192
- C 75,10 60,10 60,20
193
- V 60
194
- 15
195
- C 60,5 45,5 45,15
196
- V 60
197
- 25
198
- C 45,15 30,15 30,25
199
- V 60
200
- 75
201
- L 25,60
202
- C 20,45 10,50 10,60
203
- Z
204
- `, fill, strokeColor, strokeWidth);
205
- }
206
-
207
- public makeTouchPanningIcon(): IconElemType {
208
- const fill = 'none';
209
- const strokeColor = 'var(--icon-color)';
210
- const strokeWidth = '3';
211
-
212
- return this.makeIconFromPath(`
213
- M 5,5.5
214
- V 17.2
215
- L 16.25,5.46
216
- Z
217
-
218
- m 33.75,0
219
- L 50,17
220
- V 5.5
221
- Z
222
-
223
- M 5,40.7
224
- v 11.7
225
- h 11.25
226
- z
227
-
228
- M 26,19
229
- C 19.8,19.4 17.65,30.4 21.9,34.8
230
- L 50,70
231
- H 27.5
232
- c -11.25,0 -11.25,17.6 0,17.6
233
- H 61.25
234
- C 94.9,87.8 95,87.6 95,40.7 78.125,23 67,29 55.6,46.5
235
- L 33.1,23
236
- C 30.3125,20.128192 27.9,19 25.830078,19.119756
237
- Z
238
- `, fill, strokeColor, strokeWidth);
239
- }
240
-
241
- /** Unused by js-draw. @deprecated */
242
- public makeAllDevicePanningIcon(): IconElemType {
243
- const fill = 'none';
244
- const strokeColor = 'var(--icon-color)';
245
- const strokeWidth = '3';
246
- return this.makeIconFromPath(`
247
- M 5 5
248
- L 5 17.5
249
- 17.5 5
250
- 5 5
251
- z
252
-
253
- M 42.5 5
254
- L 55 17.5
255
- 55 5
256
- 42.5 5
257
- z
258
-
259
- M 70 10
260
- L 70 21
261
- 61 15
262
- 55.5 23
263
- 66 30
264
- 56 37
265
- 61 45
266
- 70 39
267
- 70 50
268
- 80 50
269
- 80 39
270
- 89 45
271
- 95 36
272
- 84 30
273
- 95 23
274
- 89 15
275
- 80 21
276
- 80 10
277
- 70 10
278
- z
279
-
280
- M 27.5 26.25
281
- L 27.5 91.25
282
- L 43.75 83.125
283
- L 52 99
284
- L 68 91
285
- L 60 75
286
- L 76.25 66.875
287
- L 27.5 26.25
288
- z
289
-
290
- M 5 42.5
291
- L 5 55
292
- L 17.5 55
293
- L 5 42.5
294
- z
295
- `, fill, strokeColor, strokeWidth);
296
- }
297
-
298
- public makeZoomIcon(): IconElemType {
299
- const icon = document.createElementNS(svgNamespace, 'svg');
300
- icon.setAttribute('viewBox', '0 0 100 100');
301
-
302
- const addTextNode = (text: string, x: number, y: number) => {
303
- const textNode = document.createElementNS(svgNamespace, 'text');
304
- textNode.appendChild(document.createTextNode(text));
305
- textNode.setAttribute('x', x.toString());
306
- textNode.setAttribute('y', y.toString());
307
- textNode.style.textAlign = 'center';
308
- textNode.style.textAnchor = 'middle';
309
- textNode.style.fontSize = '55px';
310
- textNode.style.fill = 'var(--icon-color)';
311
- textNode.style.fontFamily = 'monospace';
312
-
313
- icon.appendChild(textNode);
314
- };
315
-
316
- addTextNode('+', 40, 45);
317
- addTextNode('-', 70, 75);
318
-
319
- return icon;
320
- }
321
-
322
- public makeRotationLockIcon(): IconElemType {
323
- const icon = this.makeIconFromPath(`
324
- M 40.1 25.1
325
- C 32.5 25 27.9 34.1 27.9 34.1
326
- L 25.7 30
327
- L 28 44.7
328
- L 36.6 40.3
329
- L 32.3 38.3
330
- C 33.6 28 38.1 25.2 45.1 31.8
331
- L 49.4 29.6
332
- C 45.9 26.3 42.8 25.1 40.1 25.1
333
- z
334
-
335
- M 51.7 34.2
336
- L 43.5 39.1
337
- L 48 40.8
338
- C 47.4 51.1 43.1 54.3 35.7 48.2
339
- L 31.6 50.7
340
- C 45.5 62.1 52.6 44.6 52.6 44.6
341
- L 55.1 48.6
342
- L 51.7 34.2
343
- z
344
-
345
- M 56.9 49.9
346
- C 49.8 49.9 49.2 57.3 49.3 60.9
347
- L 47.6 60.9
348
- L 47.6 73.7
349
- L 66.1 73.7
350
- L 66.1 60.9
351
- L 64.4 60.9
352
- C 64.5 57.3 63.9 49.9 56.9 49.9
353
- z
354
-
355
- M 56.9 53.5
356
- C 60.8 53.5 61 58.2 60.8 60.9
357
- L 52.9 60.9
358
- C 52.7 58.2 52.9 53.5 56.9 53.5
359
- z
360
- `);
361
-
362
- icon.setAttribute('viewBox', '10 10 70 70');
363
-
364
- return icon;
365
- }
366
-
367
- public makeInsertImageIcon(): IconElemType {
368
- return this.makeIconFromPath(`
369
- M 5 10 L 5 90 L 95 90 L 95 10 L 5 10 z
370
- M 10 15 L 90 15 L 90 50 L 70 75 L 40 50 L 10 75 L 10 15 z
371
- M 22.5 25 A 7.5 7.5 0 0 0 15 32.5 A 7.5 7.5 0 0 0 22.5 40 A 7.5 7.5 0 0 0 30 32.5 A 7.5 7.5 0 0 0 22.5 25 z
372
- `);
373
- }
374
-
375
- public makeUploadFileIcon(): IconElemType {
376
- return this.makeIconFromPath(`
377
- M 48,10 32,34 43,33 42,68
378
- H 54
379
- L 53,33 64,34 Z
380
-
381
- M 8,66 V 86 H 88 V 66 H 78 V 76 H 18 V 66 Z
382
- `);
383
- }
384
-
385
- public makeTextIcon(textStyle: TextRenderingStyle): IconElemType {
386
- const icon = document.createElementNS(svgNamespace, 'svg');
387
- icon.setAttribute('viewBox', '0 0 100 100');
388
-
389
- const textNode = document.createElementNS(svgNamespace, 'text');
390
- textNode.appendChild(document.createTextNode('T'));
391
-
392
- textNode.style.fontFamily = textStyle.fontFamily;
393
- textNode.style.fontWeight = textStyle.fontWeight ?? '';
394
- textNode.style.fontVariant = textStyle.fontVariant ?? '';
395
- textNode.style.fill = textStyle.renderingStyle.fill.toHexString();
396
-
397
- textNode.style.textAnchor = 'middle';
398
- textNode.setAttribute('x', '50');
399
- textNode.setAttribute('y', '75');
400
- textNode.style.fontSize = '65px';
401
- textNode.style.filter = 'drop-shadow(0px 0px 10px var(--shadow-color))';
402
-
403
- icon.appendChild(textNode);
404
-
405
- return icon;
406
- }
407
-
408
- public makePenIcon(penStyle: PenStyle): IconElemType {
409
- // Use a square-root scale to prevent the pen's tip from overflowing.
410
- const strokeSize = Math.round(Math.sqrt(penStyle.thickness) * 4);
411
- const color = penStyle.color;
412
- const rounded = this.isRoundedTipPen(penStyle);
413
-
414
- const icon = document.createElementNS(svgNamespace, 'svg');
415
- icon.setAttribute('viewBox', '0 0 100 100');
416
- const tipThickness = strokeSize / 2;
417
-
418
- const inkTipPath = `
419
- M ${15 - tipThickness},${80 - tipThickness}
420
- ${15 - tipThickness},${80 + tipThickness}
421
- 30,83
422
- 15,65
423
- Z
424
- `;
425
- const trailStartEndY = 80 + tipThickness;
426
- const inkTrailPath = `
427
- m ${15 - tipThickness * 1.1},${trailStartEndY}
428
- c 35,10 55,15 60,30
429
- l ${35 + tipThickness * 1.2},${-10 - tipThickness}
430
- C 80.47,98.32 50.5,${90 + tipThickness} 20,${trailStartEndY} Z
431
- `;
432
-
433
- const colorBubblePath = `
434
- M 72.45,35.67
435
- A 10,15 41.8 0 1 55,40.2 10,15 41.8 0 1 57.55,22.3 10,15 41.8 0 1 75,17.8 10,15 41.8 0 1 72.5,35.67
436
- Z
437
- `;
438
-
439
- let gripMainPath = 'M 85,-25 25,35 h 10 v 10 h 10 v 10 h 10 v 10 h 10 l -5,10 60,-60 z';
440
- let gripShadow1Path = 'M 25,35 H 35 L 90,-15 85,-25 Z';
441
- let gripShadow2Path = 'M 60,75 65,65 H 55 l 55,-55 10,5 z';
442
-
443
- if (rounded) {
444
- gripMainPath = 'M 85,-25 25,35 c 15,0 40,30 35,40 l 60,-60 z';
445
- gripShadow1Path = 'm 25,35 c 3.92361,0.384473 7.644275,0.980572 10,3 l 55,-53 -5,-10 z';
446
- gripShadow2Path = 'M 60,75 C 61,66 59,65 56,59 l 54,-54 10,10 z';
447
- }
448
-
449
- const penTipPath = `M 25,35 ${10 - tipThickness / 4},${70 - tipThickness / 2} 20,75 25,85 60,75 70,55 45,25 Z`;
450
-
451
- const pencilTipColor = Color4.fromHex('#f4d7d7');
452
- const tipColor = pencilTipColor.mix(
453
- color, tipThickness / 40 - 0.1
454
- ).toHexString();
455
-
456
- const checkerboardPattern = makeCheckerboardPattern();
457
-
458
- const ink = `
459
- <path
460
- fill="${checkerboardPattern.patternRef}"
461
- d="${inkTipPath}"
462
- />
463
- <path
464
- fill="${checkerboardPattern.patternRef}"
465
- d="${inkTrailPath}"
466
- />
467
- <path
468
- fill="${color}"
469
- d="${inkTipPath}"
470
- />
471
- <path
472
- fill="${color}"
473
- d="${inkTrailPath}"
474
- />
475
- `;
476
-
477
- const penTip = `
478
- <path
479
- fill="${checkerboardPattern.patternRef}"
480
- d="${penTipPath}"
481
- />
482
- <path
483
- fill="${tipColor}"
484
- stroke="${color}"
485
- d="${penTipPath}"
486
- />
487
- `;
488
-
489
- const grip = `
490
- <path
491
- ${iconColorStrokeFill}
492
- d="${gripMainPath}"
493
- />
494
-
495
- <!-- shadows -->
496
- <path
497
- fill="rgba(150, 150, 150, 0.3)"
498
- d="${gripShadow1Path}"
499
- />
500
- <path
501
- fill="rgba(100, 100, 100, 0.2)"
502
- d="${gripShadow2Path}"
503
- />
504
-
505
- <!-- color bubble -->
506
- <path
507
- fill="${checkerboardPattern.patternRef}"
508
- d="${colorBubblePath}"
509
- />
510
- <path
511
- fill="${color}"
512
- d="${colorBubblePath}"
513
- />
514
- `;
515
-
516
- icon.innerHTML = `
517
- <defs>
518
- ${checkerboardPattern.patternDef}
519
- </defs>
520
- <g>
521
- ${ink}
522
- ${penTip}
523
- ${grip}
524
- </g>
525
- `;
526
- return icon;
527
- }
528
-
529
- public makeIconFromFactory(
530
- penStyle: PenStyle,
531
- ): IconElemType {
532
- // Increase the thickness we use to generate the icon less with larger actual thicknesses.
533
- // We want the icon to be recognisable with a large range of thicknesses.
534
- const thickness = Math.sqrt(penStyle.thickness) * 3;
535
-
536
- const nowTime = performance.now();
537
- const startPoint: StrokeDataPoint = {
538
- pos: Vec2.of(10, 10),
539
- width: thickness,
540
- color: penStyle.color,
541
- time: nowTime - 100,
542
- };
543
- const endPoint: StrokeDataPoint = {
544
- pos: Vec2.of(90, 90),
545
- width: thickness,
546
- color: penStyle.color,
547
- time: nowTime,
548
- };
549
-
550
- const viewport = new Viewport(() => {});
551
- const builder = penStyle.factory(startPoint, viewport);
552
- builder.addPoint(endPoint);
553
-
554
- const icon = document.createElementNS(svgNamespace, 'svg');
555
- icon.setAttribute('viewBox', '0 0 100 100');
556
- viewport.updateScreenSize(Vec2.of(100, 100));
557
-
558
- let renderer;
559
-
560
- // Any transparency? Include a checkerboard grid.
561
- const includeTransparencyGrid = penStyle.color.a < 1;
562
- if (includeTransparencyGrid) {
563
- const checkerboardPattern = makeCheckerboardPattern();
564
-
565
- const defs = document.createElementNS(svgNamespace, 'defs');
566
- defs.innerHTML = checkerboardPattern.patternDef;
567
- icon.appendChild(defs);
568
-
569
- const background = document.createElementNS(svgNamespace, 'g');
570
- icon.appendChild(background);
571
-
572
- renderer = new class extends SVGRenderer {
573
- public constructor() {
574
- super(icon, viewport);
575
- }
576
-
577
- protected override addPathToSVG() {
578
- const addedPath = super.addPathToSVG();
579
-
580
- if (addedPath) {
581
- // Add a copy of the path on the background
582
- const copy = addedPath.cloneNode(true) as SVGPathElement;
583
- copy.style.zIndex = '-1';
584
-
585
- if (copy.hasAttribute('stroke')) {
586
- copy.setAttribute('stroke', checkerboardPattern.patternRef);
587
- }
588
- // Note: Assumes that the component wouldn't normally be both stroked
589
- // and filled.
590
- else if (copy.hasAttribute('fill')) {
591
- copy.setAttribute('fill', checkerboardPattern.patternRef);
592
- }
593
-
594
- background.appendChild(copy);
595
- }
596
-
597
- return addedPath;
598
- }
599
- }();
600
- } else {
601
- renderer = new SVGRenderer(icon, viewport);
602
- }
603
- builder.preview(renderer);
604
-
605
- // If only a single path was rendered, try to give it a checkerboard background to
606
- // emphasize transparency. TODO: This is very fragile
607
-
608
-
609
- const bbox = builder.getBBox();
610
- icon.setAttribute('viewBox', `${bbox.x} ${bbox.y} ${bbox.w} ${bbox.h}`);
611
-
612
- return icon;
613
- }
614
-
615
- public makePipetteIcon(color?: Color4): IconElemType {
616
- const icon = document.createElementNS(svgNamespace, 'svg');
617
-
618
- const mainGroup = document.createElementNS(svgNamespace, 'g');
619
- mainGroup.style.rotate = '45deg';
620
- mainGroup.style.transformOrigin = 'center';
621
-
622
- const pipette = document.createElementNS(svgNamespace, 'g');
623
- pipette.innerHTML = `
624
- <path
625
- style="fill: var(--icon-color); stroke-linecap:round; stroke-linejoin:round;"
626
- d="
627
- m 32,12 v 68
628
- c 0,1 0.5,2 1.33,2.5 1.67,1.15 3.67,2.1 5.17,3.2 1.4,1.1 2.3,2.1 2.5,3.1 0.6,2.1 1,4.6 1,6.2 0,3.7 5.45,4.1 6,0.4 l 0.9,-6.8
629
- c 0.3,-0.9 1.1,-1.9 2.6,-2.9 1.5,-1.1 3.4,-2 5.1,-3.2
630
- C 57.5,82 58,81 58,80
631
- V 12 Z m 20,25 v 41.3
632
- c 0,1.7 -2.5,1.6 -4,2.7 -1,0.76 -2.1,1.5 -3,2.6
633
- C 44,82.5 43.02,81.75 42,81 40.51,79.92 38,80 38,78.34
634
- V 51 Z
635
- "
636
- />
637
- <rect
638
- style="fill: var(--icon-color);"
639
- width="32"
640
- height="9"
641
- x="29"
642
- y="2"
643
- ry="4.5"
644
- />
645
- <path
646
- style="fill: var(--icon-color);"
647
- d="m 45,-25 c -5.54,0 -11,4.26 -11,9 V 0 h 22 v -16 c 0,-4.74 -5.46,-9 -11,-9 z"
648
- />
649
- `;
650
-
651
- if (color) {
652
- const checkerboardPattern = makeCheckerboardPattern();
653
-
654
- const defs = document.createElementNS(svgNamespace, 'defs');
655
- defs.innerHTML = checkerboardPattern.patternDef;
656
- icon.appendChild(defs);
657
-
658
- const fluidBackground = document.createElementNS(svgNamespace, 'path');
659
- const fluid = document.createElementNS(svgNamespace, 'path');
660
-
661
- const fluidPathData = `
662
- M 35,36 H 55 V 78.678012 83 L 45,87 35,83 Z
663
- `;
664
-
665
- fluid.setAttribute('d', fluidPathData);
666
- fluidBackground.setAttribute('d', fluidPathData);
667
-
668
- fluid.style.fill = color.toHexString();
669
- fluidBackground.style.fill = checkerboardPattern.patternRef;
670
-
671
- mainGroup.appendChild(fluidBackground);
672
- mainGroup.appendChild(fluid);
673
- }
674
-
675
- mainGroup.appendChild(pipette);
676
- icon.appendChild(mainGroup);
677
-
678
- icon.setAttribute('viewBox', '5 -40 140 140');
679
- return icon;
680
- }
681
-
682
- /** Unused. @deprecated */
683
- public makeFormatSelectionIcon(): IconElemType {
684
- return this.makeIconFromPath(`
685
- M 5 10
686
- L 5 20 L 10 20 L 10 15 L 20 15 L 20 40 L 15 40 L 15 45 L 35 45 L 35 40 L 30 40 L 30 15 L 40 15 L 40 20 L 45 20 L 45 15 L 45 10 L 5 10 z
687
- M 90 10 C 90 10 86.5 13.8 86 14 C 86 14 76.2 24.8 76 25 L 60 25 L 60 65 C 75 70 85 70 90 65 L 90 25 L 80 25 L 76.7 25 L 90 10 z
688
- M 60 25 L 55 25 L 50 30 L 60 25 z
689
- M 10 55 L 10 90 L 41 90 L 41 86 L 45 86 L 45 55 L 10 55 z
690
- M 42 87 L 42 93 L 48 93 L 48 87 L 42 87 z
691
- `);
692
- }
693
-
694
- public makeResizeImageToSelectionIcon(): IconElemType {
695
- return this.makeIconFromPath(`
696
- M 75 5 75 10 90 10 90 25 95 25 95 5 75 5 z
697
- M 15 15 15 30 20 30 20 20 30 20 30 15 15 15 z
698
- M 84 15 82 17 81 16 81 20 85 20 84 19 86 17 84 15 z
699
- M 26 24 24 26 26 28 25 29 29 29 29 25 28 26 26 24 z
700
- M 25 71 26 72 24 74 26 76 28 74 29 75 29 71 25 71 z
701
- M 15 75 15 85 25 85 25 80 20 80 20 75 15 75 z
702
- M 90 75 90 90 75 90 75 95 95 95 95 75 90 75 z
703
- M 81 81 81 85 82 84 84 86 86 84 84 82 85 81 81 81 z
704
- `);
705
- }
706
-
707
- /** Renamed to {@link makeResizeImageToSelectionIcon} @deprecated */
708
- public makeResizeViewportIcon(): IconElemType {
709
- return this.makeResizeImageToSelectionIcon();
710
- }
711
-
712
- public makeDuplicateSelectionIcon(): IconElemType {
713
- return this.makeIconFromPath(`
714
- M 45,10 45,55 90,55 90,10 45,10 z
715
- M 10,25 10,90 70,90 70,60 40,60 40,25 10,25 z
716
- `);
717
- }
718
-
719
- /** Unused. @deprecated */
720
- public makePasteIcon(): IconElemType {
721
- const icon = this.makeIconFromPath(`
722
- M 50 0 L 50 5 L 35 5 L 40 24.75 L 20 25 L 20 100 L 85 100 L 100 90 L 100 24 L 75.1 24.3 L 80 5 L 65 5 L 65 0 L 50 0 z
723
- M 10 15 L 10 115 L 110 115 L 110 15 L 85 15 L 83 20 L 105 20 L 105 110 L 15 110 L 15 20 L 32 20 L 30 15 L 10 15 z
724
- M 25 35 L 90 35 L 90 40 L 25 40 L 25 35 z
725
- M 25 45 L 90 45 L 90 50 L 25 50 L 25 45 z
726
- M 25 55 L 85 55 L 85 60 L 25 60 L 25 55 z
727
- M 25 65 L 90 65 L 90 70 L 25 70 L 25 65 z
728
- `);
729
- icon.setAttribute('viewBox', '0 0 120 120');
730
- return icon;
731
- }
732
-
733
- #makeXIcon(): IconElemType {
734
- const strokeWidth = '6px';
735
- const strokeColor = 'var(--icon-color)';
736
- const fillColor = 'none';
737
-
738
- return this.makeIconFromPath(`
739
- M 15,15 85,85
740
- M 15,85 85,15
741
- `, fillColor, strokeColor, strokeWidth);
742
- }
743
-
744
- public makeDeleteSelectionIcon(): IconElemType {
745
- return this.#makeXIcon();
746
- }
747
-
748
- public makeCloseIcon(): IconElemType {
749
- return this.#makeXIcon();
750
- }
751
-
752
- public makeSaveIcon(): IconElemType {
753
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
754
- svg.innerHTML = `
755
- <style>
756
- .toolbar-save-icon {
757
- stroke: var(--icon-color);
758
- stroke-width: 6;
759
- stroke-linejoin: round;
760
- stroke-linecap: round;
761
- fill: none;
762
- }
763
- </style>
764
- <path
765
- d='
766
- M 15,55 30,70 85,20
767
- '
768
- class='toolbar-save-icon'
769
- />
770
- `;
771
- svg.setAttribute('viewBox', '0 0 100 100');
772
- return svg;
773
- }
774
-
775
- public makeConfigureDocumentIcon(): IconElemType {
776
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
777
- svg.innerHTML = `
778
- <path
779
- d='
780
- M 5,5 V 95 H 95 V 5 Z m 5,5 H 90 V 90 H 10 Z
781
- m 5,10 V 30 H 50 V 25 H 20 v -5 z
782
- m 40,0 V 50 H 85 V 20 Z
783
- m 2,2 H 83 V 39 L 77,28 70,42 64,35 57,45 Z
784
- m 8.5,5 C 64.67,27 64,27.67 64,28.5 64,29.33 64.67,30 65.5,30 66.33,30 67,29.33 67,28.5 67,27.67 66.33,27 65.5,27 Z
785
- M 15,40 v 5 h 35 v -5 z
786
- m 0,15 v 5 h 70 v -5 z
787
- m 0,15 v 5 h 70 v -5 z
788
- '
789
- style='fill: var(--icon-color);'
790
- />
791
- `;
792
- svg.setAttribute('viewBox', '0 0 100 100');
793
- return svg;
794
- }
795
-
796
- public makeOverflowIcon(): IconElemType {
797
- return this.makeIconFromPath(`
798
- M 15 40
799
- A 12.5 12.5 0 0 0 2.5 52.5
800
- A 12.5 12.5 0 0 0 15 65
801
- A 12.5 12.5 0 0 0 27.5 52.5
802
- A 12.5 12.5 0 0 0 15 40
803
- z
804
-
805
- M 50 40
806
- A 12.5 12.5 0 0 0 37.5 52.5
807
- A 12.5 12.5 0 0 0 50 65
808
- A 12.5 12.5 0 0 0 62.5 52.5
809
- A 12.5 12.5 0 0 0 50 40
810
- z
811
-
812
- M 85 40
813
- A 12.5 12.5 0 0 0 72.5 52.5
814
- A 12.5 12.5 0 0 0 85 65
815
- A 12.5 12.5 0 0 0 97.5 52.5
816
- A 12.5 12.5 0 0 0 85 40
817
- z
818
- `);
819
- }
820
-
821
- /**
822
- * @param pathData - SVG path data (e.g. `m10,10l30,30z`)
823
- * @param fill - A valid CSS color (e.g. `var(--icon-color)` or `#f0f`). This can be `none`.
824
- */
825
- protected makeIconFromPath(
826
- pathData: string,
827
- fill: string = 'var(--icon-color)',
828
- strokeColor: string = 'none',
829
- strokeWidth: string = '0px',
830
- ): IconElemType {
831
- const icon = document.createElementNS(svgNamespace, 'svg');
832
- const path = document.createElementNS(svgNamespace, 'path');
833
- path.setAttribute('d', pathData);
834
- path.style.fill = fill;
835
- path.style.stroke = strokeColor;
836
- path.style.strokeWidth = strokeWidth;
837
- icon.appendChild(path);
838
- icon.setAttribute('viewBox', '0 0 100 100');
839
-
840
- return icon;
841
- }
842
-
843
- /**
844
- * @returns An object with both the definition of a checkerboard pattern and the syntax to
845
- * reference that pattern. The defs provided by this function should be wrapped within a
846
- * `<defs></defs>` element.
847
- */
848
- protected makeCheckerboardPattern() {
849
- return makeCheckerboardPattern();
850
- }
851
-
852
- /**
853
- * @returns true if the given `penStyle` is known to match a rounded tip type of pen.
854
- */
855
- protected isRoundedTipPen(penStyle: PenStyle) {
856
- return penStyle.factory === makeFreehandLineBuilder;
857
- }
858
-
859
- /** Must be overridden by icon packs that need attribution. */
860
- public licenseInfo(): string|null { return null; }
861
- }