js-draw 0.18.2 → 0.19.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 (227) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/bundle.js +2 -2
  3. package/dist/bundledStyles.js +1 -0
  4. package/dist/cjs/src/Color4.d.ts +8 -0
  5. package/dist/cjs/src/Color4.js +67 -0
  6. package/dist/cjs/src/Editor.d.ts +2 -2
  7. package/dist/cjs/src/Editor.js +2 -2
  8. package/dist/cjs/src/SVGLoader.js +8 -5
  9. package/dist/cjs/src/components/AbstractComponent.d.ts +2 -2
  10. package/dist/cjs/src/components/AbstractComponent.js +3 -3
  11. package/dist/cjs/src/components/ImageBackground.js +1 -1
  12. package/dist/cjs/src/components/RestylableComponent.d.ts +21 -2
  13. package/dist/cjs/src/components/Stroke.d.ts +35 -0
  14. package/dist/cjs/src/components/Stroke.js +36 -2
  15. package/dist/cjs/src/components/TextComponent.d.ts +26 -4
  16. package/dist/cjs/src/components/TextComponent.js +22 -0
  17. package/dist/cjs/src/components/lib.d.ts +3 -2
  18. package/dist/cjs/src/lib.d.ts +30 -0
  19. package/dist/cjs/src/lib.js +30 -0
  20. package/dist/cjs/src/rendering/RenderingStyle.d.ts +4 -4
  21. package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  22. package/dist/cjs/src/rendering/lib.d.ts +2 -0
  23. package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  24. package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  25. package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  26. package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  27. package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  28. package/dist/cjs/src/toolbar/IconProvider.d.ts +2 -2
  29. package/dist/cjs/src/toolbar/localization.js +1 -1
  30. package/dist/cjs/src/toolbar/widgets/BaseWidget.js +1 -1
  31. package/dist/cjs/src/tools/SoundUITool.d.ts +24 -0
  32. package/dist/cjs/src/tools/SoundUITool.js +164 -0
  33. package/dist/cjs/src/tools/TextTool.d.ts +2 -2
  34. package/dist/cjs/src/tools/ToolController.js +6 -1
  35. package/dist/cjs/src/tools/lib.d.ts +1 -0
  36. package/dist/cjs/src/tools/lib.js +3 -1
  37. package/dist/cjs/src/tools/localization.d.ts +3 -0
  38. package/dist/cjs/src/tools/localization.js +3 -0
  39. package/dist/mjs/src/Color4.d.ts +8 -0
  40. package/dist/mjs/src/Color4.mjs +64 -0
  41. package/dist/mjs/src/Editor.d.ts +2 -2
  42. package/dist/mjs/src/Editor.mjs +2 -2
  43. package/dist/mjs/src/SVGLoader.mjs +8 -5
  44. package/dist/mjs/src/components/AbstractComponent.d.ts +2 -2
  45. package/dist/mjs/src/components/AbstractComponent.mjs +3 -3
  46. package/dist/mjs/src/components/ImageBackground.mjs +1 -1
  47. package/dist/mjs/src/components/RestylableComponent.d.ts +21 -2
  48. package/dist/mjs/src/components/Stroke.d.ts +35 -0
  49. package/dist/mjs/src/components/Stroke.mjs +36 -2
  50. package/dist/mjs/src/components/TextComponent.d.ts +26 -4
  51. package/dist/mjs/src/components/TextComponent.mjs +22 -0
  52. package/dist/mjs/src/components/lib.d.ts +3 -2
  53. package/dist/mjs/src/lib.d.ts +30 -0
  54. package/dist/mjs/src/lib.mjs +30 -0
  55. package/dist/mjs/src/rendering/RenderingStyle.d.ts +4 -4
  56. package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +10 -10
  57. package/dist/mjs/src/rendering/lib.d.ts +2 -0
  58. package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +2 -2
  59. package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +2 -2
  60. package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +2 -2
  61. package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +2 -2
  62. package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +2 -2
  63. package/dist/mjs/src/toolbar/IconProvider.d.ts +2 -2
  64. package/dist/mjs/src/toolbar/localization.mjs +1 -1
  65. package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +1 -1
  66. package/dist/mjs/src/tools/SoundUITool.d.ts +24 -0
  67. package/dist/mjs/src/tools/SoundUITool.mjs +158 -0
  68. package/dist/mjs/src/tools/TextTool.d.ts +2 -2
  69. package/dist/mjs/src/tools/ToolController.mjs +6 -1
  70. package/dist/mjs/src/tools/lib.d.ts +1 -0
  71. package/dist/mjs/src/tools/lib.mjs +1 -0
  72. package/dist/mjs/src/tools/localization.d.ts +3 -0
  73. package/dist/mjs/src/tools/localization.mjs +3 -0
  74. package/package.json +6 -4
  75. package/src/Editor.css +2 -2
  76. package/src/tools/SoundUITool.css +15 -0
  77. package/src/tools/tools.css +4 -0
  78. package/src/Color4.test.ts +0 -40
  79. package/src/Color4.ts +0 -236
  80. package/src/Editor.loadFrom.test.ts +0 -24
  81. package/src/Editor.toSVG.test.ts +0 -111
  82. package/src/Editor.ts +0 -1122
  83. package/src/EditorImage.test.ts +0 -120
  84. package/src/EditorImage.ts +0 -603
  85. package/src/EventDispatcher.test.ts +0 -123
  86. package/src/EventDispatcher.ts +0 -71
  87. package/src/Pointer.ts +0 -127
  88. package/src/SVGLoader.test.ts +0 -114
  89. package/src/SVGLoader.ts +0 -511
  90. package/src/UndoRedoHistory.test.ts +0 -33
  91. package/src/UndoRedoHistory.ts +0 -102
  92. package/src/Viewport.ts +0 -319
  93. package/src/bundle/bundled.ts +0 -7
  94. package/src/commands/Command.ts +0 -45
  95. package/src/commands/Duplicate.ts +0 -48
  96. package/src/commands/Erase.ts +0 -74
  97. package/src/commands/SerializableCommand.ts +0 -49
  98. package/src/commands/UnresolvedCommand.ts +0 -37
  99. package/src/commands/invertCommand.ts +0 -51
  100. package/src/commands/lib.ts +0 -16
  101. package/src/commands/localization.ts +0 -47
  102. package/src/commands/uniteCommands.test.ts +0 -23
  103. package/src/commands/uniteCommands.ts +0 -135
  104. package/src/components/AbstractComponent.transformBy.test.ts +0 -22
  105. package/src/components/AbstractComponent.ts +0 -364
  106. package/src/components/ImageBackground.test.ts +0 -35
  107. package/src/components/ImageBackground.ts +0 -176
  108. package/src/components/ImageComponent.ts +0 -171
  109. package/src/components/RestylableComponent.ts +0 -142
  110. package/src/components/SVGGlobalAttributesObject.ts +0 -81
  111. package/src/components/Stroke.test.ts +0 -139
  112. package/src/components/Stroke.ts +0 -245
  113. package/src/components/TextComponent.test.ts +0 -99
  114. package/src/components/TextComponent.ts +0 -315
  115. package/src/components/UnknownSVGObject.test.ts +0 -10
  116. package/src/components/UnknownSVGObject.ts +0 -60
  117. package/src/components/builders/ArrowBuilder.ts +0 -107
  118. package/src/components/builders/FreehandLineBuilder.ts +0 -212
  119. package/src/components/builders/LineBuilder.ts +0 -77
  120. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
  121. package/src/components/builders/RectangleBuilder.ts +0 -74
  122. package/src/components/builders/types.ts +0 -15
  123. package/src/components/lib.ts +0 -25
  124. package/src/components/localization.ts +0 -22
  125. package/src/components/util/StrokeSmoother.ts +0 -293
  126. package/src/components/util/describeComponentList.ts +0 -18
  127. package/src/lib.ts +0 -37
  128. package/src/localization.ts +0 -34
  129. package/src/localizations/de.ts +0 -98
  130. package/src/localizations/en.ts +0 -8
  131. package/src/localizations/es.ts +0 -74
  132. package/src/localizations/getLocalizationTable.test.ts +0 -27
  133. package/src/localizations/getLocalizationTable.ts +0 -55
  134. package/src/math/LineSegment2.test.ts +0 -99
  135. package/src/math/LineSegment2.ts +0 -160
  136. package/src/math/Mat33.test.ts +0 -244
  137. package/src/math/Mat33.ts +0 -437
  138. package/src/math/Path.fromString.test.ts +0 -223
  139. package/src/math/Path.test.ts +0 -198
  140. package/src/math/Path.toString.test.ts +0 -77
  141. package/src/math/Path.ts +0 -790
  142. package/src/math/Rect2.test.ts +0 -204
  143. package/src/math/Rect2.ts +0 -315
  144. package/src/math/Triangle.ts +0 -29
  145. package/src/math/Vec2.test.ts +0 -30
  146. package/src/math/Vec2.ts +0 -18
  147. package/src/math/Vec3.test.ts +0 -44
  148. package/src/math/Vec3.ts +0 -218
  149. package/src/math/lib.ts +0 -15
  150. package/src/math/rounding.test.ts +0 -65
  151. package/src/math/rounding.ts +0 -156
  152. package/src/rendering/Display.ts +0 -249
  153. package/src/rendering/RenderingStyle.test.ts +0 -68
  154. package/src/rendering/RenderingStyle.ts +0 -55
  155. package/src/rendering/TextRenderingStyle.ts +0 -45
  156. package/src/rendering/caching/CacheRecord.test.ts +0 -49
  157. package/src/rendering/caching/CacheRecord.ts +0 -77
  158. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  159. package/src/rendering/caching/RenderingCache.test.ts +0 -44
  160. package/src/rendering/caching/RenderingCache.ts +0 -66
  161. package/src/rendering/caching/RenderingCacheNode.ts +0 -405
  162. package/src/rendering/caching/testUtils.ts +0 -35
  163. package/src/rendering/caching/types.ts +0 -34
  164. package/src/rendering/lib.ts +0 -6
  165. package/src/rendering/localization.ts +0 -20
  166. package/src/rendering/renderers/AbstractRenderer.ts +0 -222
  167. package/src/rendering/renderers/CanvasRenderer.ts +0 -296
  168. package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
  169. package/src/rendering/renderers/DummyRenderer.ts +0 -136
  170. package/src/rendering/renderers/SVGRenderer.ts +0 -354
  171. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
  172. package/src/testing/beforeEachFile.ts +0 -8
  173. package/src/testing/createEditor.ts +0 -11
  174. package/src/testing/global.d.ts +0 -17
  175. package/src/testing/lib.ts +0 -3
  176. package/src/testing/loadExpectExtensions.ts +0 -25
  177. package/src/testing/sendPenEvent.ts +0 -31
  178. package/src/testing/sendTouchEvent.ts +0 -78
  179. package/src/toolbar/HTMLToolbar.ts +0 -492
  180. package/src/toolbar/IconProvider.ts +0 -736
  181. package/src/toolbar/lib.ts +0 -4
  182. package/src/toolbar/localization.ts +0 -106
  183. package/src/toolbar/makeColorInput.ts +0 -145
  184. package/src/toolbar/types.ts +0 -5
  185. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  186. package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
  187. package/src/toolbar/widgets/BaseWidget.ts +0 -377
  188. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
  189. package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
  190. package/src/toolbar/widgets/HandToolWidget.ts +0 -250
  191. package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
  192. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  193. package/src/toolbar/widgets/PenToolWidget.ts +0 -288
  194. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
  195. package/src/toolbar/widgets/TextToolWidget.ts +0 -145
  196. package/src/toolbar/widgets/lib.ts +0 -13
  197. package/src/tools/BaseTool.ts +0 -76
  198. package/src/tools/Eraser.test.ts +0 -103
  199. package/src/tools/Eraser.ts +0 -139
  200. package/src/tools/FindTool.ts +0 -152
  201. package/src/tools/PanZoom.test.ts +0 -310
  202. package/src/tools/PanZoom.ts +0 -520
  203. package/src/tools/PasteHandler.ts +0 -95
  204. package/src/tools/Pen.test.ts +0 -194
  205. package/src/tools/Pen.ts +0 -226
  206. package/src/tools/PipetteTool.ts +0 -55
  207. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
  208. package/src/tools/SelectionTool/Selection.ts +0 -607
  209. package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
  210. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
  211. package/src/tools/SelectionTool/SelectionTool.ts +0 -480
  212. package/src/tools/SelectionTool/TransformMode.ts +0 -114
  213. package/src/tools/SelectionTool/types.ts +0 -11
  214. package/src/tools/TextTool.ts +0 -326
  215. package/src/tools/ToolController.ts +0 -178
  216. package/src/tools/ToolEnabledGroup.ts +0 -14
  217. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  218. package/src/tools/ToolbarShortcutHandler.ts +0 -34
  219. package/src/tools/UndoRedoShortcut.test.ts +0 -56
  220. package/src/tools/UndoRedoShortcut.ts +0 -25
  221. package/src/tools/lib.ts +0 -21
  222. package/src/tools/localization.ts +0 -66
  223. package/src/types.ts +0 -234
  224. package/src/util/assertions.ts +0 -55
  225. package/src/util/fileToBase64.ts +0 -18
  226. package/src/util/untilNextAnimationFrame.ts +0 -9
  227. package/src/util/waitForTimeout.ts +0 -9
@@ -1,736 +0,0 @@
1
- import Color4 from '../Color4';
2
- import { ComponentBuilderFactory } from '../components/builders/types';
3
- import { Vec2 } from '../math/Vec2';
4
- import SVGRenderer from '../rendering/renderers/SVGRenderer';
5
- import TextStyle from '../rendering/TextRenderingStyle';
6
- import Pen from '../tools/Pen';
7
- import { StrokeDataPoint } from '../types';
8
- import Viewport from '../Viewport';
9
-
10
- export type IconType = HTMLImageElement|SVGElement;
11
-
12
- const svgNamespace = 'http://www.w3.org/2000/svg';
13
- const iconColorFill = `
14
- style='fill: var(--icon-color);'
15
- `;
16
- const iconColorStrokeFill = `
17
- style='fill: var(--icon-color); stroke: var(--icon-color);'
18
- `;
19
- const checkerboardPatternDef = `
20
- <pattern
21
- id='checkerboard'
22
- viewBox='0,0,10,10'
23
- width='20%'
24
- height='20%'
25
- patternUnits='userSpaceOnUse'
26
- >
27
- <rect x=0 y=0 width=10 height=10 fill='white'/>
28
- <rect x=0 y=0 width=5 height=5 fill='gray'/>
29
- <rect x=5 y=5 width=5 height=5 fill='gray'/>
30
- </pattern>
31
- `;
32
- const checkerboardPatternRef = 'url(#checkerboard)';
33
-
34
- /**
35
- * Provides icons that can be used in the toolbar, etc.
36
- * Extend this class and override methods to customize icons.
37
- *
38
- * @example
39
- * ```ts
40
- * class CustomIconProvider extends jsdraw.IconProvider {
41
- * // Use '☺' instead of the default dropdown symbol.
42
- * public makeDropdownIcon() {
43
- * const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
44
- * icon.innerHTML = `
45
- * <text x='5' y='55' style='fill: var(--icon-color); font-size: 50pt;'>☺</text>
46
- * `;
47
- * icon.setAttribute('viewBox', '0 0 100 100');
48
- * return icon;
49
- * }
50
- * }
51
- *
52
- * const icons = new CustomIconProvider();
53
- * const editor = new jsdraw.Editor(document.body, {
54
- * iconProvider: icons,
55
- * });
56
- *
57
- * // Add a toolbar that uses these icons
58
- * editor.addToolbar();
59
- * ```
60
- */
61
- export default class IconProvider {
62
-
63
- public makeUndoIcon(): IconType {
64
- return this.makeRedoIcon(true);
65
- }
66
-
67
- // @param mirror - reflect across the x-axis. This parameter is internal.
68
- // @returns a redo icon.
69
- public makeRedoIcon(mirror: boolean = false): IconType {
70
- const icon = document.createElementNS(svgNamespace, 'svg');
71
- icon.innerHTML = `
72
- <style>
73
- .toolbar-svg-undo-redo-icon {
74
- stroke: var(--icon-color);
75
- stroke-width: 12;
76
- stroke-linejoin: round;
77
- stroke-linecap: round;
78
- fill: none;
79
-
80
- transform-origin: center;
81
- }
82
- </style>
83
- <path
84
- d='M20,20 A15,15 0 0 1 70,80 L80,90 L60,70 L65,90 L87,90 L65,80'
85
- class='toolbar-svg-undo-redo-icon'
86
- style='${mirror ? 'transform: scale(-1, 1);' : ''}'/>
87
- `;
88
- icon.setAttribute('viewBox', '0 0 100 100');
89
- return icon;
90
- }
91
-
92
- public makeDropdownIcon(): IconType {
93
- const icon = document.createElementNS(svgNamespace, 'svg');
94
- icon.innerHTML = `
95
- <g>
96
- <path
97
- d='M5,10 L50,90 L95,10 Z'
98
- ${iconColorFill}
99
- />
100
- </g>
101
- `;
102
- icon.setAttribute('viewBox', '0 0 100 100');
103
- return icon;
104
- }
105
-
106
- public makeEraserIcon(eraserSize?: number): IconType {
107
- const icon = document.createElementNS(svgNamespace, 'svg');
108
- eraserSize ??= 10;
109
-
110
- const scaledSize = eraserSize / 4;
111
- const eraserColor = '#ff70af';
112
-
113
- // Draw an eraser-like shape. Created with Inkscape
114
- icon.innerHTML = `
115
- <g>
116
- <path
117
- style="fill:${eraserColor}"
118
- stroke="black"
119
- transform="rotate(41.35)"
120
- d="M 52.5 27
121
- C 50 28.9 48.9 31.7 48.9 34.8
122
- L 48.9 39.8
123
- C 48.9 45.3 53.4 49.8 58.9 49.8
124
- L 103.9 49.8
125
- C 105.8 49.8 107.6 49.2 109.1 48.3
126
- L 110.2 ${scaledSize + 49.5} L 159.7 ${scaledSize + 5}
127
- L 157.7 ${-scaledSize + 5.2} L 112.4 ${49.5 - scaledSize}
128
- C 113.4 43.5 113.9 41.7 113.9 39.8
129
- L 113.9 34.8
130
- C 113.9 29.3 109.4 24.8 103.9 24.8
131
- L 58.9 24.8
132
- C 56.5 24.8 54.3 25.7 52.5 27
133
- z "
134
- id="path438" />
135
-
136
- <rect
137
- stroke="#cc8077"
138
- ${iconColorFill}
139
- id="rect218"
140
- width="65"
141
- height="75"
142
- x="48.9"
143
- y="-38.7"
144
- transform="rotate(41.35)" />
145
- </g>
146
- `;
147
- icon.setAttribute('viewBox', '0 0 120 120');
148
- return icon;
149
- }
150
-
151
- public makeSelectionIcon(): IconType {
152
- const icon = document.createElementNS(svgNamespace, 'svg');
153
-
154
- // Draw a cursor-like shape
155
- icon.innerHTML = `
156
- <g>
157
- <rect x=10 y=10 width=70 height=70 fill='pink' stroke='black'/>
158
- <rect x=75 y=75 width=10 height=10 fill='white' stroke='black'/>
159
- </g>
160
- `;
161
- icon.setAttribute('viewBox', '0 0 100 100');
162
-
163
- return icon;
164
- }
165
-
166
- /**
167
- * @param pathData - SVG path data (e.g. `m10,10l30,30z`)
168
- * @param fill - A valid CSS color (e.g. `var(--icon-color)` or `#f0f`). This can be `none`.
169
- */
170
- protected makeIconFromPath(
171
- pathData: string,
172
- fill: string = 'var(--icon-color)',
173
- strokeColor: string = 'none',
174
- strokeWidth: string = '0px',
175
- ): IconType {
176
- const icon = document.createElementNS(svgNamespace, 'svg');
177
- const path = document.createElementNS(svgNamespace, 'path');
178
- path.setAttribute('d', pathData);
179
- path.style.fill = fill;
180
- path.style.stroke = strokeColor;
181
- path.style.strokeWidth = strokeWidth;
182
- icon.appendChild(path);
183
- icon.setAttribute('viewBox', '0 0 100 100');
184
-
185
- return icon;
186
- }
187
-
188
- public makeHandToolIcon(): IconType {
189
- const fill = 'none';
190
- const strokeColor = 'var(--icon-color)';
191
- const strokeWidth = '3';
192
-
193
- // Draw a cursor-like shape
194
- return this.makeIconFromPath(`
195
- m 10,60
196
- 5,30
197
- H 90
198
- V 30
199
- C 90,20 75,20 75,30
200
- V 60
201
- 20
202
- C 75,10 60,10 60,20
203
- V 60
204
- 15
205
- C 60,5 45,5 45,15
206
- V 60
207
- 25
208
- C 45,15 30,15 30,25
209
- V 60
210
- 75
211
- L 25,60
212
- C 20,45 10,50 10,60
213
- Z
214
- `, fill, strokeColor, strokeWidth);
215
- }
216
-
217
- public makeTouchPanningIcon(): IconType {
218
- const fill = 'none';
219
- const strokeColor = 'var(--icon-color)';
220
- const strokeWidth = '3';
221
-
222
- return this.makeIconFromPath(`
223
- M 5,5.5
224
- V 17.2
225
- L 16.25,5.46
226
- Z
227
-
228
- m 33.75,0
229
- L 50,17
230
- V 5.5
231
- Z
232
-
233
- M 5,40.7
234
- v 11.7
235
- h 11.25
236
- z
237
-
238
- M 26,19
239
- C 19.8,19.4 17.65,30.4 21.9,34.8
240
- L 50,70
241
- H 27.5
242
- c -11.25,0 -11.25,17.6 0,17.6
243
- H 61.25
244
- C 94.9,87.8 95,87.6 95,40.7 78.125,23 67,29 55.6,46.5
245
- L 33.1,23
246
- C 30.3125,20.128192 27.9,19 25.830078,19.119756
247
- Z
248
- `, fill, strokeColor, strokeWidth);
249
- }
250
-
251
- public makeAllDevicePanningIcon(): IconType {
252
- const fill = 'none';
253
- const strokeColor = 'var(--icon-color)';
254
- const strokeWidth = '3';
255
- return this.makeIconFromPath(`
256
- M 5 5
257
- L 5 17.5
258
- 17.5 5
259
- 5 5
260
- z
261
-
262
- M 42.5 5
263
- L 55 17.5
264
- 55 5
265
- 42.5 5
266
- z
267
-
268
- M 70 10
269
- L 70 21
270
- 61 15
271
- 55.5 23
272
- 66 30
273
- 56 37
274
- 61 45
275
- 70 39
276
- 70 50
277
- 80 50
278
- 80 39
279
- 89 45
280
- 95 36
281
- 84 30
282
- 95 23
283
- 89 15
284
- 80 21
285
- 80 10
286
- 70 10
287
- z
288
-
289
- M 27.5 26.25
290
- L 27.5 91.25
291
- L 43.75 83.125
292
- L 52 99
293
- L 68 91
294
- L 60 75
295
- L 76.25 66.875
296
- L 27.5 26.25
297
- z
298
-
299
- M 5 42.5
300
- L 5 55
301
- L 17.5 55
302
- L 5 42.5
303
- z
304
- `, fill, strokeColor, strokeWidth);
305
- }
306
-
307
- public makeZoomIcon(): IconType {
308
- const icon = document.createElementNS(svgNamespace, 'svg');
309
- icon.setAttribute('viewBox', '0 0 100 100');
310
-
311
- const addTextNode = (text: string, x: number, y: number) => {
312
- const textNode = document.createElementNS(svgNamespace, 'text');
313
- textNode.appendChild(document.createTextNode(text));
314
- textNode.setAttribute('x', x.toString());
315
- textNode.setAttribute('y', y.toString());
316
- textNode.style.textAlign = 'center';
317
- textNode.style.textAnchor = 'middle';
318
- textNode.style.fontSize = '55px';
319
- textNode.style.fill = 'var(--icon-color)';
320
- textNode.style.fontFamily = 'monospace';
321
-
322
- icon.appendChild(textNode);
323
- };
324
-
325
- addTextNode('+', 40, 45);
326
- addTextNode('-', 70, 75);
327
-
328
- return icon;
329
- }
330
-
331
- public makeRotationLockIcon(): IconType {
332
- const icon = this.makeIconFromPath(`
333
- M 40.1 25.1
334
- C 32.5 25 27.9 34.1 27.9 34.1
335
- L 25.7 30
336
- L 28 44.7
337
- L 36.6 40.3
338
- L 32.3 38.3
339
- C 33.6 28 38.1 25.2 45.1 31.8
340
- L 49.4 29.6
341
- C 45.9 26.3 42.8 25.1 40.1 25.1
342
- z
343
-
344
- M 51.7 34.2
345
- L 43.5 39.1
346
- L 48 40.8
347
- C 47.4 51.1 43.1 54.3 35.7 48.2
348
- L 31.6 50.7
349
- C 45.5 62.1 52.6 44.6 52.6 44.6
350
- L 55.1 48.6
351
- L 51.7 34.2
352
- z
353
-
354
- M 56.9 49.9
355
- C 49.8 49.9 49.2 57.3 49.3 60.9
356
- L 47.6 60.9
357
- L 47.6 73.7
358
- L 66.1 73.7
359
- L 66.1 60.9
360
- L 64.4 60.9
361
- C 64.5 57.3 63.9 49.9 56.9 49.9
362
- z
363
-
364
- M 56.9 53.5
365
- C 60.8 53.5 61 58.2 60.8 60.9
366
- L 52.9 60.9
367
- C 52.7 58.2 52.9 53.5 56.9 53.5
368
- z
369
- `);
370
-
371
- icon.setAttribute('viewBox', '10 10 70 70');
372
-
373
- return icon;
374
- }
375
-
376
- public makeInsertImageIcon(): IconType {
377
- return this.makeIconFromPath(`
378
- M 5 10 L 5 90 L 95 90 L 95 10 L 5 10 z
379
- M 10 15 L 90 15 L 90 50 L 70 75 L 40 50 L 10 75 L 10 15 z
380
- 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
381
- `);
382
- }
383
-
384
- public makeTextIcon(textStyle: TextStyle): IconType {
385
- const icon = document.createElementNS(svgNamespace, 'svg');
386
- icon.setAttribute('viewBox', '0 0 100 100');
387
-
388
- const textNode = document.createElementNS(svgNamespace, 'text');
389
- textNode.appendChild(document.createTextNode('T'));
390
-
391
- textNode.style.fontFamily = textStyle.fontFamily;
392
- textNode.style.fontWeight = textStyle.fontWeight ?? '';
393
- textNode.style.fontVariant = textStyle.fontVariant ?? '';
394
- textNode.style.fill = textStyle.renderingStyle.fill.toHexString();
395
-
396
- textNode.style.textAnchor = 'middle';
397
- textNode.setAttribute('x', '50');
398
- textNode.setAttribute('y', '75');
399
- textNode.style.fontSize = '65px';
400
- textNode.style.filter = 'drop-shadow(0px 0px 10px var(--primary-shadow-color))';
401
-
402
- icon.appendChild(textNode);
403
-
404
- return icon;
405
- }
406
-
407
- public makePenIcon(strokeSize: number, color: string|Color4, rounded?: boolean): IconType {
408
- if (color instanceof Color4) {
409
- color = color.toHexString();
410
- }
411
-
412
- const icon = document.createElementNS(svgNamespace, 'svg');
413
- icon.setAttribute('viewBox', '0 0 100 100');
414
- const tipThickness = strokeSize / 2;
415
-
416
- const inkTipPath = `
417
- M ${15 - tipThickness},${80 - tipThickness}
418
- ${15 - tipThickness},${80 + tipThickness}
419
- 30,83
420
- 15,65
421
- Z
422
- `;
423
- const trailStartEndY = 80 + tipThickness;
424
- const inkTrailPath = `
425
- m ${15 - tipThickness * 1.1},${trailStartEndY}
426
- c 35,10 55,15 60,30
427
- l ${35 + tipThickness * 1.2},${-10 - tipThickness}
428
- C 80.47,98.32 50.5,${90 + tipThickness} 20,${trailStartEndY} Z
429
- `;
430
-
431
- const colorBubblePath = `
432
- M 72.45,35.67
433
- 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
434
- Z
435
- `;
436
-
437
- 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';
438
- let gripShadow1Path = 'M 25,35 H 35 L 90,-15 85,-25 Z';
439
- let gripShadow2Path = 'M 60,75 65,65 H 55 l 55,-55 10,5 z';
440
-
441
- if (rounded) {
442
- gripMainPath = 'M 85,-25 25,35 c 15,0 40,30 35,40 l 60,-60 z';
443
- gripShadow1Path = 'm 25,35 c 3.92361,0.384473 7.644275,0.980572 10,3 l 55,-53 -5,-10 z';
444
- gripShadow2Path = 'M 60,75 C 61,66 59,65 56,59 l 54,-54 10,10 z';
445
- }
446
-
447
- const penTipPath = `M 25,35 ${10 - tipThickness / 4},${70 - tipThickness / 2} 20,75 25,85 60,75 70,55 45,25 Z`;
448
-
449
- const pencilTipColor = Color4.fromHex('#f4d7d7');
450
- const tipColor = pencilTipColor.mix(
451
- Color4.fromString(color), tipThickness / 40 - 0.1
452
- ).toHexString();
453
-
454
- const ink = `
455
- <path
456
- fill="${checkerboardPatternRef}"
457
- d="${inkTipPath}"
458
- />
459
- <path
460
- fill="${checkerboardPatternRef}"
461
- d="${inkTrailPath}"
462
- />
463
- <path
464
- fill="${color}"
465
- d="${inkTipPath}"
466
- />
467
- <path
468
- fill="${color}"
469
- d="${inkTrailPath}"
470
- />
471
- `;
472
-
473
- const penTip = `
474
- <path
475
- fill="${checkerboardPatternRef}"
476
- d="${penTipPath}"
477
- />
478
- <path
479
- fill="${tipColor}"
480
- stroke="${color}"
481
- d="${penTipPath}"
482
- />
483
- `;
484
-
485
- const grip = `
486
- <path
487
- ${iconColorStrokeFill}
488
- d="${gripMainPath}"
489
- />
490
-
491
- <!-- shadows -->
492
- <path
493
- fill="rgba(150, 150, 150, 0.3)"
494
- d="${gripShadow1Path}"
495
- />
496
- <path
497
- fill="rgba(100, 100, 100, 0.2)"
498
- d="${gripShadow2Path}"
499
- />
500
-
501
- <!-- color bubble -->
502
- <path
503
- fill="${checkerboardPatternRef}"
504
- d="${colorBubblePath}"
505
- />
506
- <path
507
- fill="${color}"
508
- d="${colorBubblePath}"
509
- />
510
- `;
511
-
512
- icon.innerHTML = `
513
- <defs>
514
- ${checkerboardPatternDef}
515
- </defs>
516
- <g>
517
- ${ink}
518
- ${penTip}
519
- ${grip}
520
- </g>
521
- `;
522
- return icon;
523
- }
524
-
525
- public makeIconFromFactory(pen: Pen, factory: ComponentBuilderFactory): IconType {
526
- // Increase the thickness we use to generate the icon less with larger actual thicknesses.
527
- // We want the icon to be recognisable with a large range of thicknesses.
528
- const thickness = Math.sqrt(pen.getThickness()) * 3;
529
-
530
- const nowTime = (new Date()).getTime();
531
- const startPoint: StrokeDataPoint = {
532
- pos: Vec2.of(10, 10),
533
- width: thickness,
534
- color: pen.getColor(),
535
- time: nowTime - 100,
536
- };
537
- const endPoint: StrokeDataPoint = {
538
- pos: Vec2.of(90, 90),
539
- width: thickness,
540
- color: pen.getColor(),
541
- time: nowTime,
542
- };
543
-
544
- const viewport = new Viewport(() => {});
545
- const builder = factory(startPoint, viewport);
546
- builder.addPoint(endPoint);
547
-
548
- const icon = document.createElementNS(svgNamespace, 'svg');
549
- icon.setAttribute('viewBox', '0 0 100 100');
550
- viewport.updateScreenSize(Vec2.of(100, 100));
551
-
552
- const renderer = new SVGRenderer(icon, viewport);
553
- builder.preview(renderer);
554
-
555
- return icon;
556
- }
557
-
558
- public makePipetteIcon(color?: Color4): IconType {
559
- const icon = document.createElementNS(svgNamespace, 'svg');
560
- const pipette = document.createElementNS(svgNamespace, 'path');
561
-
562
- pipette.setAttribute('d', `
563
- M 47,6
564
- C 35,5 25,15 35,30
565
- c -9.2,1.3 -15,0 -15,3
566
- 0,2 5,5 15,7
567
- V 81
568
- L 40,90
569
- h 6
570
- L 40,80
571
- V 40
572
- h 15
573
- v 40
574
- l -6,10
575
- h 6
576
- l 5,-9.2
577
- V 40
578
- C 70,38 75,35 75,33
579
- 75,30 69.2,31.2 60,30
580
- 65,15 65,5 47,6
581
- Z
582
- `);
583
- pipette.style.fill = 'var(--icon-color)';
584
-
585
- if (color) {
586
- const defs = document.createElementNS(svgNamespace, 'defs');
587
- defs.innerHTML = checkerboardPatternDef;
588
- icon.appendChild(defs);
589
-
590
- const fluidBackground = document.createElementNS(svgNamespace, 'path');
591
- const fluid = document.createElementNS(svgNamespace, 'path');
592
-
593
- const fluidPathData = `
594
- m 40,50 c 5,5 10,0 15,-5 V 80 L 50,90 H 45 L 40,80 Z
595
- `;
596
-
597
- fluid.setAttribute('d', fluidPathData);
598
- fluidBackground.setAttribute('d', fluidPathData);
599
-
600
- fluid.style.fill = color.toHexString();
601
- fluidBackground.style.fill = checkerboardPatternRef;
602
-
603
- icon.appendChild(fluidBackground);
604
- icon.appendChild(fluid);
605
- }
606
- icon.appendChild(pipette);
607
-
608
- icon.setAttribute('viewBox', '0 0 100 100');
609
- return icon;
610
- }
611
-
612
- public makeFormatSelectionIcon(): IconType {
613
- return this.makeIconFromPath(`
614
- M 5 10
615
- 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
616
- 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
617
- M 60 25 L 55 25 L 50 30 L 60 25 z
618
- M 10 55 L 10 90 L 41 90 L 41 86 L 45 86 L 45 55 L 10 55 z
619
- M 42 87 L 42 93 L 48 93 L 48 87 L 42 87 z
620
- `);
621
- }
622
-
623
- public makeResizeViewportIcon(): IconType {
624
- return this.makeIconFromPath(`
625
- M 75 5 75 10 90 10 90 25 95 25 95 5 75 5 z
626
- M 15 15 15 30 20 30 20 20 30 20 30 15 15 15 z
627
- M 84 15 82 17 81 16 81 20 85 20 84 19 86 17 84 15 z
628
- M 26 24 24 26 26 28 25 29 29 29 29 25 28 26 26 24 z
629
- M 25 71 26 72 24 74 26 76 28 74 29 75 29 71 25 71 z
630
- M 15 75 15 85 25 85 25 80 20 80 20 75 15 75 z
631
- M 90 75 90 90 75 90 75 95 95 95 95 75 90 75 z
632
- M 81 81 81 85 82 84 84 86 86 84 84 82 85 81 81 81 z
633
- `);
634
- }
635
-
636
- public makeDuplicateSelectionIcon(): IconType {
637
- return this.makeIconFromPath(`
638
- M 45,10 45,55 90,55 90,10 45,10 z
639
- M 10,25 10,90 70,90 70,60 40,60 40,25 10,25 z
640
- `);
641
- }
642
-
643
- public makePasteIcon(): IconType {
644
- const icon = this.makeIconFromPath(`
645
- 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
646
- 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
647
- M 25 35 L 90 35 L 90 40 L 25 40 L 25 35 z
648
- M 25 45 L 90 45 L 90 50 L 25 50 L 25 45 z
649
- M 25 55 L 85 55 L 85 60 L 25 60 L 25 55 z
650
- M 25 65 L 90 65 L 90 70 L 25 70 L 25 65 z
651
- `);
652
- icon.setAttribute('viewBox', '0 0 120 120');
653
- return icon;
654
- }
655
-
656
- public makeDeleteSelectionIcon(): IconType {
657
- const strokeWidth = '5px';
658
- const strokeColor = 'var(--icon-color)';
659
- const fillColor = 'none';
660
-
661
- return this.makeIconFromPath(`
662
- M 10,10 90,90
663
- M 10,90 90,10
664
- `, fillColor, strokeColor, strokeWidth);
665
- }
666
-
667
- public makeSaveIcon(): IconType {
668
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
669
- svg.innerHTML = `
670
- <style>
671
- .toolbar-save-icon {
672
- stroke: var(--icon-color);
673
- stroke-width: 10;
674
- stroke-linejoin: round;
675
- stroke-linecap: round;
676
- fill: none;
677
- }
678
- </style>
679
- <path
680
- d='
681
- M 15,55 30,70 85,20
682
- '
683
- class='toolbar-save-icon'
684
- />
685
- `;
686
- svg.setAttribute('viewBox', '0 0 100 100');
687
- return svg;
688
- }
689
-
690
- public makeConfigureDocumentIcon(): IconType {
691
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
692
- svg.innerHTML = `
693
- <path
694
- d='
695
- M 5,5 V 95 H 95 V 5 Z m 5,5 H 90 V 90 H 10 Z
696
- m 5,10 V 30 H 50 V 25 H 20 v -5 z
697
- m 40,0 V 50 H 85 V 20 Z
698
- m 2,2 H 83 V 39 L 77,28 70,42 64,35 57,45 Z
699
- 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
700
- M 15,40 v 5 h 35 v -5 z
701
- m 0,15 v 5 h 70 v -5 z
702
- m 0,15 v 5 h 70 v -5 z
703
- '
704
- style='fill: var(--icon-color);'
705
- />
706
- `;
707
- svg.setAttribute('viewBox', '0 0 100 100');
708
- return svg;
709
- }
710
-
711
- public makeOverflowIcon(): IconType {
712
- return this.makeIconFromPath(`
713
- M 15 40
714
- A 12.5 12.5 0 0 0 2.5 52.5
715
- A 12.5 12.5 0 0 0 15 65
716
- A 12.5 12.5 0 0 0 27.5 52.5
717
- A 12.5 12.5 0 0 0 15 40
718
- z
719
-
720
- M 50 40
721
- A 12.5 12.5 0 0 0 37.5 52.5
722
- A 12.5 12.5 0 0 0 50 65
723
- A 12.5 12.5 0 0 0 62.5 52.5
724
- A 12.5 12.5 0 0 0 50 40
725
- z
726
-
727
- M 85 40
728
- A 12.5 12.5 0 0 0 72.5 52.5
729
- A 12.5 12.5 0 0 0 85 65
730
- A 12.5 12.5 0 0 0 97.5 52.5
731
- A 12.5 12.5 0 0 0 85 40
732
- z
733
- `);
734
- }
735
-
736
- }