js-draw 0.25.1 → 1.0.1

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 (750) hide show
  1. package/README.md +80 -26
  2. package/build-config.json +22 -21
  3. package/dist/Editor.css +1281 -0
  4. package/dist/bundle.js +3 -3
  5. package/dist/bundledStyles.js +1 -1
  6. package/dist/cjs/Editor.d.ts +91 -12
  7. package/dist/cjs/Editor.js +619 -590
  8. package/dist/cjs/EditorImage.d.ts +5 -2
  9. package/dist/cjs/EditorImage.js +258 -297
  10. package/dist/cjs/EventDispatcher.js +17 -19
  11. package/dist/cjs/Pointer.d.ts +3 -1
  12. package/dist/cjs/Pointer.js +41 -44
  13. package/dist/cjs/SVGLoader.d.ts +7 -1
  14. package/dist/cjs/SVGLoader.js +373 -474
  15. package/dist/cjs/UndoRedoHistory.js +28 -40
  16. package/dist/cjs/Viewport.d.ts +1 -4
  17. package/dist/cjs/Viewport.js +150 -193
  18. package/dist/cjs/bundle/bundled.js +4 -1
  19. package/dist/cjs/commands/Command.js +22 -49
  20. package/dist/cjs/commands/Duplicate.js +28 -44
  21. package/dist/cjs/commands/Erase.js +36 -54
  22. package/dist/cjs/commands/SerializableCommand.js +20 -35
  23. package/dist/cjs/commands/UnresolvedCommand.js +14 -29
  24. package/dist/cjs/commands/invertCommand.js +29 -51
  25. package/dist/cjs/commands/lib.js +9 -6
  26. package/dist/cjs/commands/localization.d.ts +1 -1
  27. package/dist/cjs/commands/localization.js +9 -9
  28. package/dist/cjs/commands/uniteCommands.js +57 -87
  29. package/dist/cjs/components/AbstractComponent.d.ts +11 -3
  30. package/dist/cjs/components/AbstractComponent.js +141 -169
  31. package/dist/cjs/components/BackgroundComponent.d.ts +3 -6
  32. package/dist/cjs/components/BackgroundComponent.js +124 -149
  33. package/dist/cjs/components/ImageComponent.d.ts +3 -5
  34. package/dist/cjs/components/ImageComponent.js +95 -175
  35. package/dist/cjs/components/RestylableComponent.d.ts +1 -1
  36. package/dist/cjs/components/RestylableComponent.js +41 -56
  37. package/dist/cjs/components/SVGGlobalAttributesObject.d.ts +1 -3
  38. package/dist/cjs/components/SVGGlobalAttributesObject.js +34 -51
  39. package/dist/cjs/components/Stroke.d.ts +4 -6
  40. package/dist/cjs/components/Stroke.js +95 -121
  41. package/dist/cjs/components/TextComponent.d.ts +2 -4
  42. package/dist/cjs/components/TextComponent.js +189 -234
  43. package/dist/cjs/components/UnknownSVGObject.d.ts +1 -3
  44. package/dist/cjs/components/UnknownSVGObject.js +30 -43
  45. package/dist/cjs/components/builders/ArrowBuilder.d.ts +1 -1
  46. package/dist/cjs/components/builders/ArrowBuilder.js +43 -42
  47. package/dist/cjs/components/builders/CircleBuilder.js +43 -43
  48. package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +3 -2
  49. package/dist/cjs/components/builders/FreehandLineBuilder.js +73 -86
  50. package/dist/cjs/components/builders/LineBuilder.d.ts +1 -1
  51. package/dist/cjs/components/builders/LineBuilder.js +38 -36
  52. package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
  53. package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +131 -139
  54. package/dist/cjs/components/builders/RectangleBuilder.d.ts +1 -1
  55. package/dist/cjs/components/builders/RectangleBuilder.js +31 -31
  56. package/dist/cjs/components/builders/types.d.ts +1 -1
  57. package/dist/cjs/components/lib.d.ts +3 -1
  58. package/dist/cjs/components/lib.js +10 -7
  59. package/dist/cjs/components/localization.js +4 -4
  60. package/dist/cjs/components/util/StrokeSmoother.d.ts +1 -2
  61. package/dist/cjs/components/util/StrokeSmoother.js +67 -72
  62. package/dist/cjs/components/util/describeComponentList.d.ts +1 -1
  63. package/dist/cjs/components/util/describeComponentList.js +4 -5
  64. package/dist/cjs/dialogs/makeAboutDialog.d.ts +15 -0
  65. package/dist/cjs/dialogs/makeAboutDialog.js +54 -0
  66. package/dist/cjs/inputEvents.d.ts +84 -0
  67. package/dist/cjs/inputEvents.js +40 -0
  68. package/dist/cjs/lib.d.ts +29 -13
  69. package/dist/cjs/lib.js +38 -23
  70. package/dist/cjs/localization.js +19 -18
  71. package/dist/cjs/localizations/de.js +117 -13
  72. package/dist/cjs/localizations/en.js +4 -13
  73. package/dist/cjs/localizations/es.js +62 -23
  74. package/dist/cjs/localizations/getLocalizationTable.js +15 -13
  75. package/dist/cjs/rendering/Display.d.ts +1 -2
  76. package/dist/cjs/rendering/Display.js +70 -83
  77. package/dist/cjs/rendering/RenderablePathSpec.d.ts +15 -0
  78. package/dist/cjs/rendering/RenderablePathSpec.js +70 -0
  79. package/dist/cjs/rendering/RenderingStyle.d.ts +4 -4
  80. package/dist/cjs/rendering/RenderingStyle.js +18 -28
  81. package/dist/cjs/rendering/TextRenderingStyle.d.ts +10 -10
  82. package/dist/cjs/rendering/TextRenderingStyle.js +13 -18
  83. package/dist/cjs/rendering/caching/CacheRecord.d.ts +1 -2
  84. package/dist/cjs/rendering/caching/CacheRecord.js +20 -22
  85. package/dist/cjs/rendering/caching/CacheRecordManager.d.ts +1 -1
  86. package/dist/cjs/rendering/caching/CacheRecordManager.js +17 -15
  87. package/dist/cjs/rendering/caching/RenderingCache.js +19 -19
  88. package/dist/cjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
  89. package/dist/cjs/rendering/caching/RenderingCacheNode.js +98 -118
  90. package/dist/cjs/rendering/caching/testUtils.js +24 -23
  91. package/dist/cjs/rendering/caching/types.d.ts +3 -3
  92. package/dist/cjs/rendering/lib.js +8 -5
  93. package/dist/cjs/rendering/localization.js +5 -5
  94. package/dist/cjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
  95. package/dist/cjs/rendering/renderers/AbstractRenderer.js +53 -57
  96. package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
  97. package/dist/cjs/rendering/renderers/CanvasRenderer.js +91 -106
  98. package/dist/cjs/rendering/renderers/DummyRenderer.d.ts +1 -4
  99. package/dist/cjs/rendering/renderers/DummyRenderer.js +56 -76
  100. package/dist/cjs/rendering/renderers/SVGRenderer.d.ts +5 -5
  101. package/dist/cjs/rendering/renderers/SVGRenderer.js +194 -176
  102. package/dist/cjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
  103. package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +47 -72
  104. package/dist/cjs/shortcuts/KeyBinding.d.ts +5 -0
  105. package/dist/cjs/shortcuts/KeyBinding.js +94 -70
  106. package/dist/cjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
  107. package/dist/cjs/shortcuts/KeyboardShortcutManager.js +36 -45
  108. package/dist/cjs/shortcuts/lib.js +5 -2
  109. package/dist/cjs/testing/createEditor.js +7 -4
  110. package/dist/cjs/testing/getUniquePointerId.js +4 -5
  111. package/dist/cjs/testing/lib.js +5 -2
  112. package/dist/cjs/testing/sendPenEvent.d.ts +2 -2
  113. package/dist/cjs/testing/sendPenEvent.js +10 -7
  114. package/dist/cjs/testing/sendTouchEvent.d.ts +2 -2
  115. package/dist/cjs/testing/sendTouchEvent.js +34 -16
  116. package/dist/cjs/toolbar/AbstractToolbar.d.ts +166 -0
  117. package/dist/cjs/toolbar/AbstractToolbar.js +410 -0
  118. package/dist/cjs/toolbar/DropdownToolbar.d.ts +43 -0
  119. package/dist/cjs/toolbar/DropdownToolbar.js +176 -0
  120. package/dist/cjs/toolbar/EdgeToolbar.d.ts +47 -0
  121. package/dist/cjs/toolbar/EdgeToolbar.js +422 -0
  122. package/dist/cjs/toolbar/IconProvider.d.ts +54 -30
  123. package/dist/cjs/toolbar/IconProvider.js +652 -224
  124. package/dist/cjs/toolbar/constants.d.ts +1 -0
  125. package/dist/cjs/toolbar/constants.js +4 -0
  126. package/dist/cjs/toolbar/lib.d.ts +4 -2
  127. package/dist/cjs/toolbar/lib.js +10 -3
  128. package/dist/cjs/toolbar/localization.d.ts +9 -2
  129. package/dist/cjs/toolbar/localization.js +26 -19
  130. package/dist/cjs/toolbar/types.d.ts +7 -0
  131. package/dist/cjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
  132. package/dist/cjs/toolbar/widgets/ActionButtonWidget.js +23 -39
  133. package/dist/cjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
  134. package/dist/cjs/toolbar/widgets/BaseToolWidget.js +35 -37
  135. package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +60 -5
  136. package/dist/cjs/toolbar/widgets/BaseWidget.js +232 -177
  137. package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +130 -117
  138. package/dist/cjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
  139. package/dist/cjs/toolbar/widgets/EraserToolWidget.js +45 -73
  140. package/dist/cjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
  141. package/dist/cjs/toolbar/widgets/HandToolWidget.js +126 -141
  142. package/dist/cjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
  143. package/dist/cjs/toolbar/widgets/InsertImageWidget.js +147 -212
  144. package/dist/cjs/toolbar/widgets/OverflowWidget.js +33 -61
  145. package/dist/cjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
  146. package/dist/cjs/toolbar/widgets/PenToolWidget.js +162 -234
  147. package/dist/cjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
  148. package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +105 -177
  149. package/dist/cjs/toolbar/widgets/TextToolWidget.js +64 -87
  150. package/dist/cjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
  151. package/dist/cjs/toolbar/{makeColorInput.js → widgets/components/makeColorInput.js} +57 -34
  152. package/dist/cjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
  153. package/dist/cjs/toolbar/widgets/components/makeFileInput.js +111 -0
  154. package/dist/cjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
  155. package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +127 -0
  156. package/dist/cjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
  157. package/dist/cjs/toolbar/widgets/components/makeSeparator.js +16 -0
  158. package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
  159. package/dist/cjs/toolbar/widgets/components/makeThicknessSlider.js +47 -0
  160. package/dist/cjs/toolbar/widgets/keybindings.js +8 -5
  161. package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
  162. package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +199 -0
  163. package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
  164. package/dist/cjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.js +60 -0
  165. package/dist/cjs/toolbar/widgets/layout/types.d.ts +63 -0
  166. package/dist/cjs/toolbar/widgets/layout/types.js +2 -0
  167. package/dist/cjs/toolbar/widgets/lib.d.ts +1 -1
  168. package/dist/cjs/toolbar/widgets/lib.js +15 -11
  169. package/dist/cjs/tools/BaseTool.d.ts +28 -9
  170. package/dist/cjs/tools/BaseTool.js +128 -51
  171. package/dist/cjs/tools/Eraser.d.ts +8 -1
  172. package/dist/cjs/tools/Eraser.js +82 -92
  173. package/dist/cjs/tools/FindTool.d.ts +1 -1
  174. package/dist/cjs/tools/FindTool.js +61 -77
  175. package/dist/cjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
  176. package/dist/cjs/tools/InputFilter/FunctionMapper.js +21 -0
  177. package/dist/cjs/tools/InputFilter/InputMapper.d.ts +23 -0
  178. package/dist/cjs/tools/InputFilter/InputMapper.js +38 -0
  179. package/dist/cjs/tools/InputFilter/InputPipeline.d.ts +15 -0
  180. package/dist/cjs/tools/InputFilter/InputPipeline.js +54 -0
  181. package/dist/cjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
  182. package/dist/cjs/tools/InputFilter/InputStabilizer.js +181 -0
  183. package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
  184. package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +84 -0
  185. package/dist/cjs/tools/PanZoom.d.ts +4 -2
  186. package/dist/cjs/tools/PanZoom.js +186 -248
  187. package/dist/cjs/tools/PasteHandler.d.ts +1 -1
  188. package/dist/cjs/tools/PasteHandler.js +49 -148
  189. package/dist/cjs/tools/Pen.d.ts +12 -11
  190. package/dist/cjs/tools/Pen.js +123 -158
  191. package/dist/cjs/tools/PipetteTool.d.ts +11 -2
  192. package/dist/cjs/tools/PipetteTool.js +51 -48
  193. package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
  194. package/dist/cjs/tools/SelectionTool/SelectAllShortcutHandler.js +15 -30
  195. package/dist/cjs/tools/SelectionTool/Selection.d.ts +5 -5
  196. package/dist/cjs/tools/SelectionTool/Selection.js +308 -415
  197. package/dist/cjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
  198. package/dist/cjs/tools/SelectionTool/SelectionHandle.js +63 -37
  199. package/dist/cjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
  200. package/dist/cjs/tools/SelectionTool/SelectionTool.js +164 -187
  201. package/dist/cjs/tools/SelectionTool/TransformMode.d.ts +1 -1
  202. package/dist/cjs/tools/SelectionTool/TransformMode.js +65 -66
  203. package/dist/cjs/tools/SoundUITool.d.ts +2 -1
  204. package/dist/cjs/tools/SoundUITool.js +70 -84
  205. package/dist/cjs/tools/TextTool.d.ts +5 -3
  206. package/dist/cjs/tools/TextTool.js +169 -173
  207. package/dist/cjs/tools/ToolController.d.ts +16 -2
  208. package/dist/cjs/tools/ToolController.js +124 -100
  209. package/dist/cjs/tools/ToolEnabledGroup.js +6 -9
  210. package/dist/cjs/tools/ToolSwitcherShortcut.d.ts +1 -1
  211. package/dist/cjs/tools/ToolSwitcherShortcut.js +16 -32
  212. package/dist/cjs/tools/ToolbarShortcutHandler.d.ts +1 -1
  213. package/dist/cjs/tools/ToolbarShortcutHandler.js +17 -33
  214. package/dist/cjs/tools/UndoRedoShortcut.d.ts +1 -1
  215. package/dist/cjs/tools/UndoRedoShortcut.js +12 -27
  216. package/dist/cjs/tools/keybindings.js +21 -18
  217. package/dist/cjs/tools/lib.js +17 -14
  218. package/dist/cjs/tools/localization.d.ts +2 -1
  219. package/dist/cjs/tools/localization.js +8 -7
  220. package/dist/cjs/types.d.ts +22 -80
  221. package/dist/cjs/types.js +8 -16
  222. package/dist/cjs/util/ReactiveValue.d.ts +65 -0
  223. package/dist/cjs/util/ReactiveValue.js +166 -0
  224. package/dist/cjs/util/assertions.js +5 -8
  225. package/dist/cjs/util/fileToBase64.js +6 -6
  226. package/dist/cjs/util/guessKeyCodeFromKey.d.ts +9 -0
  227. package/dist/cjs/util/guessKeyCodeFromKey.js +32 -0
  228. package/dist/cjs/util/listPrefixMatch.d.ts +6 -0
  229. package/dist/cjs/util/listPrefixMatch.js +17 -0
  230. package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
  231. package/dist/cjs/util/stopPropagationOfScrollingWheelEvents.js +17 -0
  232. package/dist/cjs/util/untilNextAnimationFrame.js +3 -3
  233. package/dist/cjs/util/waitForAll.js +3 -3
  234. package/dist/cjs/util/waitForTimeout.js +3 -3
  235. package/dist/cjs/version.d.ts +4 -0
  236. package/dist/cjs/version.js +5 -0
  237. package/dist/mjs/Editor.d.ts +91 -12
  238. package/dist/mjs/Editor.mjs +565 -563
  239. package/dist/mjs/EditorImage.d.ts +5 -2
  240. package/dist/mjs/EditorImage.mjs +248 -291
  241. package/dist/mjs/EventDispatcher.mjs +17 -20
  242. package/dist/mjs/Pointer.d.ts +3 -1
  243. package/dist/mjs/Pointer.mjs +40 -44
  244. package/dist/mjs/SVGLoader.d.ts +7 -1
  245. package/dist/mjs/SVGLoader.mjs +338 -466
  246. package/dist/mjs/UndoRedoHistory.mjs +27 -39
  247. package/dist/mjs/Viewport.d.ts +1 -4
  248. package/dist/mjs/Viewport.mjs +139 -187
  249. package/dist/mjs/commands/Command.mjs +21 -49
  250. package/dist/mjs/commands/Duplicate.mjs +22 -41
  251. package/dist/mjs/commands/Erase.mjs +30 -51
  252. package/dist/mjs/commands/SerializableCommand.mjs +16 -34
  253. package/dist/mjs/commands/UnresolvedCommand.mjs +10 -29
  254. package/dist/mjs/commands/invertCommand.mjs +24 -49
  255. package/dist/mjs/commands/localization.d.ts +1 -1
  256. package/dist/mjs/commands/localization.mjs +10 -10
  257. package/dist/mjs/commands/uniteCommands.mjs +52 -85
  258. package/dist/mjs/components/AbstractComponent.d.ts +11 -3
  259. package/dist/mjs/components/AbstractComponent.mjs +135 -166
  260. package/dist/mjs/components/BackgroundComponent.d.ts +3 -6
  261. package/dist/mjs/components/BackgroundComponent.mjs +107 -136
  262. package/dist/mjs/components/ImageComponent.d.ts +3 -5
  263. package/dist/mjs/components/ImageComponent.mjs +90 -174
  264. package/dist/mjs/components/RestylableComponent.d.ts +1 -1
  265. package/dist/mjs/components/RestylableComponent.mjs +35 -53
  266. package/dist/mjs/components/SVGGlobalAttributesObject.d.ts +1 -3
  267. package/dist/mjs/components/SVGGlobalAttributesObject.mjs +29 -50
  268. package/dist/mjs/components/Stroke.d.ts +4 -6
  269. package/dist/mjs/components/Stroke.mjs +89 -119
  270. package/dist/mjs/components/TextComponent.d.ts +2 -4
  271. package/dist/mjs/components/TextComponent.mjs +180 -228
  272. package/dist/mjs/components/UnknownSVGObject.d.ts +1 -3
  273. package/dist/mjs/components/UnknownSVGObject.mjs +26 -43
  274. package/dist/mjs/components/builders/ArrowBuilder.d.ts +1 -1
  275. package/dist/mjs/components/builders/ArrowBuilder.mjs +32 -35
  276. package/dist/mjs/components/builders/CircleBuilder.mjs +35 -38
  277. package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +3 -2
  278. package/dist/mjs/components/builders/FreehandLineBuilder.mjs +52 -69
  279. package/dist/mjs/components/builders/LineBuilder.d.ts +1 -1
  280. package/dist/mjs/components/builders/LineBuilder.mjs +30 -32
  281. package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +1 -1
  282. package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +103 -115
  283. package/dist/mjs/components/builders/RectangleBuilder.d.ts +1 -1
  284. package/dist/mjs/components/builders/RectangleBuilder.mjs +27 -31
  285. package/dist/mjs/components/builders/types.d.ts +1 -1
  286. package/dist/mjs/components/lib.d.ts +3 -1
  287. package/dist/mjs/components/lib.mjs +1 -1
  288. package/dist/mjs/components/localization.mjs +5 -5
  289. package/dist/mjs/components/util/StrokeSmoother.d.ts +1 -2
  290. package/dist/mjs/components/util/StrokeSmoother.mjs +63 -69
  291. package/dist/mjs/components/util/describeComponentList.d.ts +1 -1
  292. package/dist/mjs/components/util/describeComponentList.mjs +4 -5
  293. package/dist/mjs/dialogs/makeAboutDialog.d.ts +15 -0
  294. package/dist/mjs/dialogs/makeAboutDialog.mjs +52 -0
  295. package/dist/mjs/inputEvents.d.ts +84 -0
  296. package/dist/mjs/inputEvents.mjs +34 -0
  297. package/dist/mjs/lib.d.ts +29 -13
  298. package/dist/mjs/lib.mjs +30 -13
  299. package/dist/mjs/localization.mjs +14 -13
  300. package/dist/mjs/localizations/de.mjs +116 -12
  301. package/dist/mjs/localizations/en.mjs +3 -12
  302. package/dist/mjs/localizations/es.mjs +61 -22
  303. package/dist/mjs/localizations/getLocalizationTable.mjs +12 -13
  304. package/dist/mjs/rendering/Display.d.ts +1 -2
  305. package/dist/mjs/rendering/Display.mjs +62 -79
  306. package/dist/mjs/rendering/RenderablePathSpec.d.ts +15 -0
  307. package/dist/mjs/rendering/RenderablePathSpec.mjs +64 -0
  308. package/dist/mjs/rendering/RenderingStyle.d.ts +4 -4
  309. package/dist/mjs/rendering/RenderingStyle.mjs +16 -26
  310. package/dist/mjs/rendering/TextRenderingStyle.d.ts +10 -10
  311. package/dist/mjs/rendering/TextRenderingStyle.mjs +12 -17
  312. package/dist/mjs/rendering/caching/CacheRecord.d.ts +1 -2
  313. package/dist/mjs/rendering/caching/CacheRecord.mjs +20 -23
  314. package/dist/mjs/rendering/caching/CacheRecordManager.d.ts +1 -1
  315. package/dist/mjs/rendering/caching/CacheRecordManager.mjs +13 -15
  316. package/dist/mjs/rendering/caching/RenderingCache.mjs +13 -17
  317. package/dist/mjs/rendering/caching/RenderingCacheNode.d.ts +1 -1
  318. package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +94 -115
  319. package/dist/mjs/rendering/caching/testUtils.mjs +19 -21
  320. package/dist/mjs/rendering/caching/types.d.ts +3 -3
  321. package/dist/mjs/rendering/localization.mjs +6 -6
  322. package/dist/mjs/rendering/renderers/AbstractRenderer.d.ts +2 -11
  323. package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +47 -52
  324. package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +3 -5
  325. package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +84 -103
  326. package/dist/mjs/rendering/renderers/DummyRenderer.d.ts +1 -4
  327. package/dist/mjs/rendering/renderers/DummyRenderer.mjs +51 -75
  328. package/dist/mjs/rendering/renderers/SVGRenderer.d.ts +5 -5
  329. package/dist/mjs/rendering/renderers/SVGRenderer.mjs +185 -171
  330. package/dist/mjs/rendering/renderers/TextOnlyRenderer.d.ts +1 -3
  331. package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +43 -72
  332. package/dist/mjs/shortcuts/KeyBinding.d.ts +5 -0
  333. package/dist/mjs/shortcuts/KeyBinding.mjs +94 -71
  334. package/dist/mjs/shortcuts/KeyboardShortcutManager.d.ts +1 -1
  335. package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +32 -44
  336. package/dist/mjs/testing/createEditor.mjs +2 -2
  337. package/dist/mjs/testing/getUniquePointerId.mjs +4 -5
  338. package/dist/mjs/testing/sendPenEvent.d.ts +2 -2
  339. package/dist/mjs/testing/sendPenEvent.mjs +5 -5
  340. package/dist/mjs/testing/sendTouchEvent.d.ts +2 -2
  341. package/dist/mjs/testing/sendTouchEvent.mjs +8 -16
  342. package/dist/mjs/toolbar/AbstractToolbar.d.ts +166 -0
  343. package/dist/mjs/toolbar/AbstractToolbar.mjs +405 -0
  344. package/dist/mjs/toolbar/DropdownToolbar.d.ts +43 -0
  345. package/dist/mjs/toolbar/DropdownToolbar.mjs +168 -0
  346. package/dist/mjs/toolbar/EdgeToolbar.d.ts +47 -0
  347. package/dist/mjs/toolbar/EdgeToolbar.mjs +414 -0
  348. package/dist/mjs/toolbar/IconProvider.d.ts +54 -30
  349. package/dist/mjs/toolbar/IconProvider.mjs +644 -219
  350. package/dist/mjs/toolbar/constants.d.ts +1 -0
  351. package/dist/mjs/toolbar/constants.mjs +1 -0
  352. package/dist/mjs/toolbar/lib.d.ts +4 -2
  353. package/dist/mjs/toolbar/lib.mjs +3 -1
  354. package/dist/mjs/toolbar/localization.d.ts +9 -2
  355. package/dist/mjs/toolbar/localization.mjs +27 -20
  356. package/dist/mjs/toolbar/types.d.ts +7 -0
  357. package/dist/mjs/toolbar/widgets/ActionButtonWidget.d.ts +1 -1
  358. package/dist/mjs/toolbar/widgets/ActionButtonWidget.mjs +19 -39
  359. package/dist/mjs/toolbar/widgets/BaseToolWidget.d.ts +1 -1
  360. package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +30 -36
  361. package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +60 -5
  362. package/dist/mjs/toolbar/widgets/BaseWidget.mjs +227 -176
  363. package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +98 -111
  364. package/dist/mjs/toolbar/widgets/EraserToolWidget.d.ts +1 -3
  365. package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +41 -73
  366. package/dist/mjs/toolbar/widgets/HandToolWidget.d.ts +1 -0
  367. package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +94 -136
  368. package/dist/mjs/toolbar/widgets/InsertImageWidget.d.ts +9 -7
  369. package/dist/mjs/toolbar/widgets/InsertImageWidget.mjs +140 -208
  370. package/dist/mjs/toolbar/widgets/OverflowWidget.mjs +30 -62
  371. package/dist/mjs/toolbar/widgets/PenToolWidget.d.ts +8 -1
  372. package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +150 -225
  373. package/dist/mjs/toolbar/widgets/SelectionToolWidget.d.ts +3 -1
  374. package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +97 -173
  375. package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +59 -85
  376. package/dist/mjs/toolbar/widgets/components/makeColorInput.d.ts +10 -0
  377. package/dist/mjs/toolbar/{makeColorInput.mjs → widgets/components/makeColorInput.mjs} +53 -33
  378. package/dist/mjs/toolbar/widgets/components/makeFileInput.d.ts +12 -0
  379. package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +106 -0
  380. package/dist/mjs/toolbar/widgets/components/makeGridSelector.d.ts +24 -0
  381. package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +122 -0
  382. package/dist/mjs/toolbar/widgets/components/makeSeparator.d.ts +7 -0
  383. package/dist/mjs/toolbar/widgets/components/makeSeparator.mjs +14 -0
  384. package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.d.ts +8 -0
  385. package/dist/mjs/toolbar/widgets/components/makeThicknessSlider.mjs +45 -0
  386. package/dist/mjs/toolbar/widgets/keybindings.mjs +5 -5
  387. package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.d.ts +21 -0
  388. package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +193 -0
  389. package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.d.ts +14 -0
  390. package/dist/mjs/toolbar/widgets/layout/EdgeToolbarLayoutManager.mjs +57 -0
  391. package/dist/mjs/toolbar/widgets/layout/types.d.ts +63 -0
  392. package/dist/mjs/toolbar/widgets/lib.d.ts +1 -1
  393. package/dist/mjs/toolbar/widgets/lib.mjs +1 -1
  394. package/dist/mjs/tools/BaseTool.d.ts +28 -9
  395. package/dist/mjs/tools/BaseTool.mjs +127 -50
  396. package/dist/mjs/tools/Eraser.d.ts +8 -1
  397. package/dist/mjs/tools/Eraser.mjs +72 -86
  398. package/dist/mjs/tools/FindTool.d.ts +1 -1
  399. package/dist/mjs/tools/FindTool.mjs +55 -75
  400. package/dist/mjs/tools/InputFilter/FunctionMapper.d.ts +12 -0
  401. package/dist/mjs/tools/InputFilter/FunctionMapper.mjs +15 -0
  402. package/dist/mjs/tools/InputFilter/InputMapper.d.ts +23 -0
  403. package/dist/mjs/tools/InputFilter/InputMapper.mjs +36 -0
  404. package/dist/mjs/tools/InputFilter/InputPipeline.d.ts +15 -0
  405. package/dist/mjs/tools/InputFilter/InputPipeline.mjs +49 -0
  406. package/dist/mjs/tools/InputFilter/InputStabilizer.d.ts +29 -0
  407. package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +175 -0
  408. package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.d.ts +21 -0
  409. package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +78 -0
  410. package/dist/mjs/tools/PanZoom.d.ts +4 -2
  411. package/dist/mjs/tools/PanZoom.mjs +169 -235
  412. package/dist/mjs/tools/PasteHandler.d.ts +1 -1
  413. package/dist/mjs/tools/PasteHandler.mjs +42 -145
  414. package/dist/mjs/tools/Pen.d.ts +12 -11
  415. package/dist/mjs/tools/Pen.mjs +115 -154
  416. package/dist/mjs/tools/PipetteTool.d.ts +11 -2
  417. package/dist/mjs/tools/PipetteTool.mjs +47 -48
  418. package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.d.ts +1 -1
  419. package/dist/mjs/tools/SelectionTool/SelectAllShortcutHandler.mjs +9 -28
  420. package/dist/mjs/tools/SelectionTool/Selection.d.ts +5 -5
  421. package/dist/mjs/tools/SelectionTool/Selection.mjs +268 -401
  422. package/dist/mjs/tools/SelectionTool/SelectionHandle.d.ts +15 -5
  423. package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +62 -37
  424. package/dist/mjs/tools/SelectionTool/SelectionTool.d.ts +4 -4
  425. package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +153 -179
  426. package/dist/mjs/tools/SelectionTool/TransformMode.d.ts +1 -1
  427. package/dist/mjs/tools/SelectionTool/TransformMode.mjs +52 -59
  428. package/dist/mjs/tools/SoundUITool.d.ts +2 -1
  429. package/dist/mjs/tools/SoundUITool.mjs +66 -84
  430. package/dist/mjs/tools/TextTool.d.ts +5 -3
  431. package/dist/mjs/tools/TextTool.mjs +155 -163
  432. package/dist/mjs/tools/ToolController.d.ts +16 -2
  433. package/dist/mjs/tools/ToolController.mjs +81 -84
  434. package/dist/mjs/tools/ToolEnabledGroup.mjs +6 -10
  435. package/dist/mjs/tools/ToolSwitcherShortcut.d.ts +1 -1
  436. package/dist/mjs/tools/ToolSwitcherShortcut.mjs +12 -32
  437. package/dist/mjs/tools/ToolbarShortcutHandler.d.ts +1 -1
  438. package/dist/mjs/tools/ToolbarShortcutHandler.mjs +13 -33
  439. package/dist/mjs/tools/UndoRedoShortcut.d.ts +1 -1
  440. package/dist/mjs/tools/UndoRedoShortcut.mjs +7 -26
  441. package/dist/mjs/tools/keybindings.mjs +34 -34
  442. package/dist/mjs/tools/localization.d.ts +2 -1
  443. package/dist/mjs/tools/localization.mjs +9 -8
  444. package/dist/mjs/types.d.ts +22 -80
  445. package/dist/mjs/types.mjs +7 -15
  446. package/dist/mjs/util/ReactiveValue.d.ts +65 -0
  447. package/dist/mjs/util/ReactiveValue.mjs +161 -0
  448. package/dist/mjs/util/assertions.mjs +5 -8
  449. package/dist/mjs/util/fileToBase64.mjs +6 -6
  450. package/dist/mjs/util/guessKeyCodeFromKey.d.ts +9 -0
  451. package/dist/mjs/util/guessKeyCodeFromKey.mjs +30 -0
  452. package/dist/mjs/util/listPrefixMatch.d.ts +6 -0
  453. package/dist/mjs/util/listPrefixMatch.mjs +15 -0
  454. package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.d.ts +2 -0
  455. package/dist/mjs/util/stopPropagationOfScrollingWheelEvents.mjs +15 -0
  456. package/dist/mjs/util/untilNextAnimationFrame.mjs +3 -3
  457. package/dist/mjs/util/waitForAll.mjs +3 -3
  458. package/dist/mjs/util/waitForTimeout.mjs +3 -3
  459. package/dist/mjs/version.d.ts +4 -0
  460. package/dist/mjs/version.mjs +3 -0
  461. package/dist-test/test_imports/package.json +1 -1
  462. package/dist-test/test_imports/test-imports.js +5 -11
  463. package/dist-test/test_imports/test-require.cjs +6 -11
  464. package/package.json +11 -22
  465. package/src/Coloris.css +8 -8
  466. package/src/Editor.loadFrom.test.ts +1 -1
  467. package/src/Editor.scss +148 -0
  468. package/src/Editor.test.ts +107 -0
  469. package/src/Editor.toSVG.test.ts +184 -1
  470. package/src/Editor.ts +325 -53
  471. package/src/EditorImage.test.ts +4 -7
  472. package/src/EditorImage.ts +10 -4
  473. package/src/Pointer.ts +18 -5
  474. package/src/SVGLoader.ts +77 -15
  475. package/src/UndoRedoHistory.test.ts +2 -1
  476. package/src/Viewport.ts +1 -4
  477. package/src/commands/Erase.ts +1 -0
  478. package/src/commands/localization.ts +1 -1
  479. package/src/commands/uniteCommands.test.ts +3 -3
  480. package/src/components/AbstractComponent.transformBy.test.ts +2 -1
  481. package/src/components/AbstractComponent.ts +12 -3
  482. package/src/components/BackgroundComponent.test.ts +1 -2
  483. package/src/components/BackgroundComponent.ts +3 -8
  484. package/src/components/ImageComponent.ts +1 -3
  485. package/src/components/RestylableComponent.ts +1 -1
  486. package/src/components/SVGGlobalAttributesObject.ts +1 -3
  487. package/src/components/Stroke.test.ts +4 -6
  488. package/src/components/Stroke.ts +5 -7
  489. package/src/components/TextComponent.test.ts +1 -3
  490. package/src/components/TextComponent.ts +1 -4
  491. package/src/components/UnknownSVGObject.ts +3 -3
  492. package/src/components/builders/ArrowBuilder.ts +1 -2
  493. package/src/components/builders/CircleBuilder.ts +3 -5
  494. package/src/components/builders/FreehandLineBuilder.test.ts +2 -3
  495. package/src/components/builders/FreehandLineBuilder.ts +3 -5
  496. package/src/components/builders/LineBuilder.ts +3 -3
  497. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +3 -4
  498. package/src/components/builders/RectangleBuilder.ts +3 -4
  499. package/src/components/builders/types.ts +1 -1
  500. package/src/components/lib.ts +1 -1
  501. package/src/components/util/StrokeSmoother.ts +7 -7
  502. package/src/dialogs/dialogs.scss +36 -0
  503. package/src/dialogs/makeAboutDialog.scss +41 -0
  504. package/src/dialogs/makeAboutDialog.ts +82 -0
  505. package/src/inputEvents.ts +143 -0
  506. package/src/lib.ts +35 -13
  507. package/src/localizations/de.ts +2 -2
  508. package/src/localizations/es.ts +5 -5
  509. package/src/rendering/Display.ts +1 -2
  510. package/src/rendering/RenderablePathSpec.ts +88 -0
  511. package/src/rendering/RenderingStyle.test.ts +1 -1
  512. package/src/rendering/RenderingStyle.ts +1 -1
  513. package/src/rendering/caching/CacheRecord.test.ts +1 -2
  514. package/src/rendering/caching/CacheRecord.ts +1 -2
  515. package/src/rendering/caching/CacheRecordManager.ts +1 -1
  516. package/src/rendering/caching/RenderingCache.test.ts +3 -4
  517. package/src/rendering/caching/RenderingCache.ts +1 -1
  518. package/src/rendering/caching/RenderingCacheNode.ts +1 -2
  519. package/src/rendering/caching/testUtils.ts +1 -1
  520. package/src/rendering/caching/types.ts +3 -3
  521. package/src/rendering/renderers/AbstractRenderer.ts +4 -14
  522. package/src/rendering/renderers/CanvasRenderer.ts +17 -12
  523. package/src/rendering/renderers/DummyRenderer.test.ts +1 -2
  524. package/src/rendering/renderers/DummyRenderer.ts +1 -4
  525. package/src/rendering/renderers/SVGRenderer.ts +68 -11
  526. package/src/rendering/renderers/TextOnlyRenderer.ts +1 -4
  527. package/src/shortcuts/KeyBinding.test.ts +10 -0
  528. package/src/shortcuts/KeyBinding.ts +74 -35
  529. package/src/shortcuts/KeyboardShortcutManager.test.ts +1 -1
  530. package/src/styles.js +1 -1
  531. package/src/testing/sendPenEvent.ts +2 -2
  532. package/src/testing/sendTouchEvent.ts +2 -2
  533. package/src/toolbar/{toolbar.css → AbstractToolbar.scss} +47 -85
  534. package/src/toolbar/AbstractToolbar.ts +542 -0
  535. package/src/toolbar/DropdownToolbar.scss +46 -0
  536. package/src/toolbar/DropdownToolbar.ts +220 -0
  537. package/src/toolbar/EdgeToolbar.scss +511 -0
  538. package/src/toolbar/EdgeToolbar.test.ts +54 -0
  539. package/src/toolbar/EdgeToolbar.ts +543 -0
  540. package/src/toolbar/IconProvider.ts +189 -133
  541. package/src/toolbar/constants.ts +1 -0
  542. package/src/toolbar/lib.ts +4 -2
  543. package/src/toolbar/localization.ts +39 -17
  544. package/src/toolbar/toolbar.scss +11 -0
  545. package/src/toolbar/types.ts +8 -0
  546. package/src/toolbar/widgets/ActionButtonWidget.ts +2 -2
  547. package/src/toolbar/widgets/BaseToolWidget.ts +17 -1
  548. package/src/toolbar/widgets/BaseWidget.ts +179 -112
  549. package/src/toolbar/widgets/DocumentPropertiesWidget.scss +7 -0
  550. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +26 -10
  551. package/src/toolbar/widgets/EraserToolWidget.ts +21 -22
  552. package/src/toolbar/widgets/HandToolWidget.scss +14 -0
  553. package/src/toolbar/widgets/HandToolWidget.ts +21 -32
  554. package/src/toolbar/widgets/InsertImageWidget.scss +41 -0
  555. package/src/toolbar/widgets/InsertImageWidget.ts +90 -65
  556. package/src/toolbar/widgets/PenToolWidget.css +0 -51
  557. package/src/toolbar/widgets/PenToolWidget.ts +106 -146
  558. package/src/toolbar/widgets/SelectionToolWidget.scss +6 -0
  559. package/src/toolbar/widgets/SelectionToolWidget.ts +83 -85
  560. package/src/toolbar/widgets/TextToolWidget.ts +9 -5
  561. package/src/toolbar/widgets/components/components.scss +5 -0
  562. package/src/toolbar/widgets/components/makeColorInput.scss +82 -0
  563. package/src/toolbar/{makeColorInput.ts → widgets/components/makeColorInput.ts} +39 -14
  564. package/src/toolbar/widgets/components/makeFileInput.scss +77 -0
  565. package/src/toolbar/widgets/components/makeFileInput.ts +128 -0
  566. package/src/toolbar/widgets/components/makeGridSelector.scss +60 -0
  567. package/src/toolbar/widgets/components/makeGridSelector.ts +179 -0
  568. package/src/toolbar/widgets/components/makeSeparator.scss +14 -0
  569. package/src/toolbar/widgets/components/makeSeparator.ts +17 -0
  570. package/src/toolbar/widgets/components/makeThicknessSlider.scss +9 -0
  571. package/src/toolbar/widgets/components/makeThicknessSlider.ts +62 -0
  572. package/src/toolbar/widgets/keybindings.ts +1 -3
  573. package/src/toolbar/widgets/layout/DropdownLayoutManager.ts +262 -0
  574. package/src/toolbar/widgets/layout/EdgeToolbarLayoutManager.ts +71 -0
  575. package/src/toolbar/widgets/layout/types.ts +74 -0
  576. package/src/toolbar/widgets/lib.ts +2 -2
  577. package/src/tools/BaseTool.ts +102 -30
  578. package/src/tools/Eraser.test.ts +2 -2
  579. package/src/tools/Eraser.ts +24 -11
  580. package/src/tools/FindTool.css +3 -3
  581. package/src/tools/FindTool.test.ts +67 -0
  582. package/src/tools/FindTool.ts +3 -3
  583. package/src/tools/InputFilter/FunctionMapper.ts +17 -0
  584. package/src/tools/InputFilter/InputMapper.ts +41 -0
  585. package/src/tools/InputFilter/InputPipeline.test.ts +41 -0
  586. package/src/tools/InputFilter/InputPipeline.ts +34 -0
  587. package/src/tools/InputFilter/InputStabilizer.ts +254 -0
  588. package/src/tools/InputFilter/StrokeKeyboardControl.ts +104 -0
  589. package/src/tools/PanZoom.test.ts +3 -13
  590. package/src/tools/PanZoom.ts +33 -10
  591. package/src/tools/PasteHandler.ts +2 -3
  592. package/src/tools/Pen.test.ts +2 -4
  593. package/src/tools/Pen.ts +54 -70
  594. package/src/tools/PipetteTool.ts +31 -2
  595. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +1 -1
  596. package/src/tools/SelectionTool/Selection.ts +52 -16
  597. package/src/tools/SelectionTool/SelectionHandle.ts +46 -12
  598. package/src/tools/SelectionTool/SelectionTool.css +23 -11
  599. package/src/tools/SelectionTool/SelectionTool.test.ts +130 -21
  600. package/src/tools/SelectionTool/SelectionTool.ts +62 -48
  601. package/src/tools/SelectionTool/TransformMode.ts +1 -3
  602. package/src/tools/SoundUITool.ts +13 -4
  603. package/src/tools/TextTool.ts +29 -30
  604. package/src/tools/ToolController.ts +60 -36
  605. package/src/tools/ToolSwitcherShortcut.ts +1 -1
  606. package/src/tools/ToolbarShortcutHandler.ts +1 -1
  607. package/src/tools/UndoRedoShortcut.test.ts +10 -4
  608. package/src/tools/UndoRedoShortcut.ts +1 -1
  609. package/src/tools/keybindings.ts +17 -17
  610. package/src/tools/localization.ts +4 -2
  611. package/src/tools/tools.scss +4 -0
  612. package/src/types.ts +25 -113
  613. package/src/util/ReactiveValue.test.ts +168 -0
  614. package/src/util/ReactiveValue.ts +241 -0
  615. package/src/util/guessKeyCodeFromKey.ts +36 -0
  616. package/src/util/listPrefixMatch.ts +19 -0
  617. package/src/util/stopPropagationOfScrollingWheelEvents.ts +20 -0
  618. package/src/version.test.ts +12 -0
  619. package/src/version.ts +3 -0
  620. package/tsconfig.json +1 -1
  621. package/typedoc.json +4 -0
  622. package/dist/cjs/Color4.d.ts +0 -69
  623. package/dist/cjs/Color4.js +0 -263
  624. package/dist/cjs/math/Mat33.d.ts +0 -123
  625. package/dist/cjs/math/Mat33.js +0 -340
  626. package/dist/cjs/math/Vec2.d.ts +0 -33
  627. package/dist/cjs/math/Vec2.js +0 -37
  628. package/dist/cjs/math/Vec3.d.ts +0 -106
  629. package/dist/cjs/math/Vec3.js +0 -183
  630. package/dist/cjs/math/lib.d.ts +0 -7
  631. package/dist/cjs/math/lib.js +0 -15
  632. package/dist/cjs/math/polynomial/solveQuadratic.d.ts +0 -9
  633. package/dist/cjs/math/polynomial/solveQuadratic.js +0 -39
  634. package/dist/cjs/math/rounding.d.ts +0 -4
  635. package/dist/cjs/math/rounding.js +0 -140
  636. package/dist/cjs/math/shapes/Abstract2DShape.d.ts +0 -49
  637. package/dist/cjs/math/shapes/Abstract2DShape.js +0 -42
  638. package/dist/cjs/math/shapes/BezierJSWrapper.d.ts +0 -36
  639. package/dist/cjs/math/shapes/BezierJSWrapper.js +0 -109
  640. package/dist/cjs/math/shapes/CubicBezier.d.ts +0 -17
  641. package/dist/cjs/math/shapes/CubicBezier.js +0 -50
  642. package/dist/cjs/math/shapes/LineSegment2.d.ts +0 -70
  643. package/dist/cjs/math/shapes/LineSegment2.js +0 -204
  644. package/dist/cjs/math/shapes/Path.d.ts +0 -93
  645. package/dist/cjs/math/shapes/Path.js +0 -865
  646. package/dist/cjs/math/shapes/PointShape2D.d.ts +0 -18
  647. package/dist/cjs/math/shapes/PointShape2D.js +0 -46
  648. package/dist/cjs/math/shapes/QuadraticBezier.d.ts +0 -34
  649. package/dist/cjs/math/shapes/QuadraticBezier.js +0 -133
  650. package/dist/cjs/math/shapes/Rect2.d.ts +0 -57
  651. package/dist/cjs/math/shapes/Rect2.js +0 -311
  652. package/dist/cjs/math/shapes/Triangle.d.ts +0 -46
  653. package/dist/cjs/math/shapes/Triangle.js +0 -148
  654. package/dist/cjs/toolbar/HTMLToolbar.d.ts +0 -105
  655. package/dist/cjs/toolbar/HTMLToolbar.js +0 -465
  656. package/dist/cjs/toolbar/makeColorInput.d.ts +0 -6
  657. package/dist/mjs/Color4.d.ts +0 -69
  658. package/dist/mjs/Color4.mjs +0 -260
  659. package/dist/mjs/Color4.test.d.ts +0 -1
  660. package/dist/mjs/math/Mat33.d.ts +0 -123
  661. package/dist/mjs/math/Mat33.mjs +0 -338
  662. package/dist/mjs/math/Mat33.test.d.ts +0 -1
  663. package/dist/mjs/math/Vec2.d.ts +0 -33
  664. package/dist/mjs/math/Vec2.mjs +0 -34
  665. package/dist/mjs/math/Vec2.test.d.ts +0 -1
  666. package/dist/mjs/math/Vec3.d.ts +0 -106
  667. package/dist/mjs/math/Vec3.mjs +0 -181
  668. package/dist/mjs/math/Vec3.test.d.ts +0 -1
  669. package/dist/mjs/math/lib.d.ts +0 -7
  670. package/dist/mjs/math/lib.mjs +0 -7
  671. package/dist/mjs/math/polynomial/solveQuadratic.d.ts +0 -9
  672. package/dist/mjs/math/polynomial/solveQuadratic.mjs +0 -37
  673. package/dist/mjs/math/polynomial/solveQuadratic.test.d.ts +0 -1
  674. package/dist/mjs/math/rounding.d.ts +0 -4
  675. package/dist/mjs/math/rounding.mjs +0 -133
  676. package/dist/mjs/math/rounding.test.d.ts +0 -1
  677. package/dist/mjs/math/shapes/Abstract2DShape.d.ts +0 -49
  678. package/dist/mjs/math/shapes/Abstract2DShape.mjs +0 -40
  679. package/dist/mjs/math/shapes/BezierJSWrapper.d.ts +0 -36
  680. package/dist/mjs/math/shapes/BezierJSWrapper.mjs +0 -107
  681. package/dist/mjs/math/shapes/CubicBezier.d.ts +0 -17
  682. package/dist/mjs/math/shapes/CubicBezier.mjs +0 -48
  683. package/dist/mjs/math/shapes/LineSegment2.d.ts +0 -70
  684. package/dist/mjs/math/shapes/LineSegment2.mjs +0 -202
  685. package/dist/mjs/math/shapes/LineSegment2.test.d.ts +0 -1
  686. package/dist/mjs/math/shapes/Path.d.ts +0 -93
  687. package/dist/mjs/math/shapes/Path.fromString.test.d.ts +0 -1
  688. package/dist/mjs/math/shapes/Path.mjs +0 -862
  689. package/dist/mjs/math/shapes/Path.test.d.ts +0 -1
  690. package/dist/mjs/math/shapes/Path.toString.test.d.ts +0 -1
  691. package/dist/mjs/math/shapes/PointShape2D.d.ts +0 -18
  692. package/dist/mjs/math/shapes/PointShape2D.mjs +0 -44
  693. package/dist/mjs/math/shapes/QuadraticBezier.d.ts +0 -34
  694. package/dist/mjs/math/shapes/QuadraticBezier.mjs +0 -131
  695. package/dist/mjs/math/shapes/QuadraticBezier.test.d.ts +0 -1
  696. package/dist/mjs/math/shapes/Rect2.d.ts +0 -57
  697. package/dist/mjs/math/shapes/Rect2.mjs +0 -309
  698. package/dist/mjs/math/shapes/Rect2.test.d.ts +0 -1
  699. package/dist/mjs/math/shapes/Triangle.d.ts +0 -46
  700. package/dist/mjs/math/shapes/Triangle.mjs +0 -146
  701. package/dist/mjs/math/shapes/Triangle.test.d.ts +0 -1
  702. package/dist/mjs/toolbar/HTMLToolbar.d.ts +0 -105
  703. package/dist/mjs/toolbar/HTMLToolbar.mjs +0 -462
  704. package/dist/mjs/toolbar/makeColorInput.d.ts +0 -6
  705. package/src/Color4.test.ts +0 -47
  706. package/src/Color4.ts +0 -304
  707. package/src/Editor.css +0 -98
  708. package/src/math/Mat33.test.ts +0 -244
  709. package/src/math/Mat33.ts +0 -442
  710. package/src/math/Vec2.test.ts +0 -30
  711. package/src/math/Vec2.ts +0 -40
  712. package/src/math/Vec3.test.ts +0 -44
  713. package/src/math/Vec3.ts +0 -218
  714. package/src/math/lib.ts +0 -15
  715. package/src/math/polynomial/solveQuadratic.test.ts +0 -39
  716. package/src/math/polynomial/solveQuadratic.ts +0 -43
  717. package/src/math/rounding.test.ts +0 -65
  718. package/src/math/rounding.ts +0 -156
  719. package/src/math/shapes/Abstract2DShape.ts +0 -63
  720. package/src/math/shapes/BezierJSWrapper.ts +0 -93
  721. package/src/math/shapes/CubicBezier.ts +0 -35
  722. package/src/math/shapes/LineSegment2.test.ts +0 -99
  723. package/src/math/shapes/LineSegment2.ts +0 -231
  724. package/src/math/shapes/Path.fromString.test.ts +0 -223
  725. package/src/math/shapes/Path.test.ts +0 -309
  726. package/src/math/shapes/Path.toString.test.ts +0 -77
  727. package/src/math/shapes/Path.ts +0 -1027
  728. package/src/math/shapes/PointShape2D.ts +0 -33
  729. package/src/math/shapes/QuadraticBezier.test.ts +0 -31
  730. package/src/math/shapes/QuadraticBezier.ts +0 -141
  731. package/src/math/shapes/Rect2.test.ts +0 -209
  732. package/src/math/shapes/Rect2.ts +0 -344
  733. package/src/math/shapes/Triangle.test.ts +0 -61
  734. package/src/math/shapes/Triangle.ts +0 -139
  735. package/src/toolbar/HTMLToolbar.ts +0 -567
  736. package/src/toolbar/widgets/InsertImageWidget.css +0 -44
  737. package/src/tools/tools.css +0 -4
  738. /package/dist/cjs/{Color4.test.d.ts → Editor.test.d.ts} +0 -0
  739. /package/dist/cjs/{math/Mat33.test.d.ts → toolbar/EdgeToolbar.test.d.ts} +0 -0
  740. /package/dist/cjs/{math/Vec2.test.d.ts → tools/FindTool.test.d.ts} +0 -0
  741. /package/dist/cjs/{math/Vec3.test.d.ts → tools/InputFilter/InputPipeline.test.d.ts} +0 -0
  742. /package/dist/cjs/{math/polynomial/solveQuadratic.test.d.ts → util/ReactiveValue.test.d.ts} +0 -0
  743. /package/dist/cjs/{math/rounding.test.d.ts → version.test.d.ts} +0 -0
  744. /package/dist/{cjs/math/shapes/LineSegment2.test.d.ts → mjs/Editor.test.d.ts} +0 -0
  745. /package/dist/{cjs/math/shapes/Path.fromString.test.d.ts → mjs/toolbar/EdgeToolbar.test.d.ts} +0 -0
  746. /package/dist/{cjs/math/shapes/Path.test.d.ts → mjs/toolbar/widgets/layout/types.mjs} +0 -0
  747. /package/dist/{cjs/math/shapes/Path.toString.test.d.ts → mjs/tools/FindTool.test.d.ts} +0 -0
  748. /package/dist/{cjs/math/shapes/QuadraticBezier.test.d.ts → mjs/tools/InputFilter/InputPipeline.test.d.ts} +0 -0
  749. /package/dist/{cjs/math/shapes/Rect2.test.d.ts → mjs/util/ReactiveValue.test.d.ts} +0 -0
  750. /package/dist/{cjs/math/shapes/Triangle.test.d.ts → mjs/version.test.d.ts} +0 -0
@@ -1,72 +1,53 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
36
7
  }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
37
24
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
27
  };
47
28
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.svgStyleAttributesDataKey = exports.svgAttributesDataKey = exports.defaultSVGViewRect = void 0;
49
- var Color4_1 = require("./Color4");
50
- var BackgroundComponent_1 = require("./components/BackgroundComponent");
51
- var ImageComponent_1 = require("./components/ImageComponent");
52
- var Stroke_1 = require("./components/Stroke");
53
- var SVGGlobalAttributesObject_1 = require("./components/SVGGlobalAttributesObject");
54
- var TextComponent_1 = require("./components/TextComponent");
55
- var UnknownSVGObject_1 = require("./components/UnknownSVGObject");
56
- var Mat33_1 = require("./math/Mat33");
57
- var Path_1 = require("./math/shapes/Path");
58
- var Rect2_1 = require("./math/shapes/Rect2");
59
- var Vec2_1 = require("./math/Vec2");
29
+ exports.svgLoaderAttributeContainerID = exports.svgStyleAttributesDataKey = exports.svgAttributesDataKey = exports.defaultSVGViewRect = void 0;
30
+ const math_1 = require("@js-draw/math");
31
+ const BackgroundComponent_1 = __importStar(require("./components/BackgroundComponent"));
32
+ const ImageComponent_1 = __importDefault(require("./components/ImageComponent"));
33
+ const Stroke_1 = __importDefault(require("./components/Stroke"));
34
+ const SVGGlobalAttributesObject_1 = __importDefault(require("./components/SVGGlobalAttributesObject"));
35
+ const TextComponent_1 = __importStar(require("./components/TextComponent"));
36
+ const UnknownSVGObject_1 = __importDefault(require("./components/UnknownSVGObject"));
37
+ const RenderablePathSpec_1 = require("./rendering/RenderablePathSpec");
60
38
  // Size of a loaded image if no size is specified.
61
- exports.defaultSVGViewRect = new Rect2_1.default(0, 0, 500, 500);
39
+ exports.defaultSVGViewRect = new math_1.Rect2(0, 0, 500, 500);
62
40
  // Key to retrieve unrecognised attributes from an AbstractComponent
63
41
  exports.svgAttributesDataKey = 'svgAttrs';
42
+ // Like {@link svgAttributesDataKey}, but for styles
64
43
  exports.svgStyleAttributesDataKey = 'svgStyleAttrs';
65
- var supportedStrokeFillStyleAttrs = ['stroke', 'fill', 'stroke-width'];
44
+ // Key that specifies the ID of an SVG element that contained a given node when the image
45
+ // was first loaded.
46
+ exports.svgLoaderAttributeContainerID = 'svgContainerID';
47
+ const supportedStrokeFillStyleAttrs = ['stroke', 'fill', 'stroke-width'];
66
48
  // Handles loading images from SVG.
67
- var SVGLoader = /** @class */ (function () {
68
- function SVGLoader(source, onFinish, storeUnknown) {
69
- if (storeUnknown === void 0) { storeUnknown = true; }
49
+ class SVGLoader {
50
+ constructor(source, onFinish, storeUnknown = true) {
70
51
  this.source = source;
71
52
  this.onFinish = onFinish;
72
53
  this.storeUnknown = storeUnknown;
@@ -75,34 +56,35 @@ var SVGLoader = /** @class */ (function () {
75
56
  this.onDetermineExportRect = null;
76
57
  this.processedCount = 0;
77
58
  this.totalToProcess = 0;
59
+ this.containerGroupIDs = [];
60
+ this.encounteredIDs = [];
78
61
  }
79
62
  // If [computedStyles] is given, it is preferred to directly accessing node's style object.
80
- SVGLoader.prototype.getStyle = function (node, computedStyles) {
81
- var _a, _b, _c, _d, _f, _g;
82
- var fill = Color4_1.default.transparent;
83
- var stroke;
63
+ getStyle(node, computedStyles) {
64
+ let fill = math_1.Color4.transparent;
65
+ let stroke;
84
66
  // If possible, use computedStyles (allows property inheritance).
85
- var fillAttribute = (_b = (_a = node.getAttribute('fill')) !== null && _a !== void 0 ? _a : computedStyles === null || computedStyles === void 0 ? void 0 : computedStyles.fill) !== null && _b !== void 0 ? _b : node.style.fill;
67
+ const fillAttribute = node.getAttribute('fill') ?? computedStyles?.fill ?? node.style.fill;
86
68
  if (fillAttribute) {
87
69
  try {
88
- fill = Color4_1.default.fromString(fillAttribute);
70
+ fill = math_1.Color4.fromString(fillAttribute);
89
71
  }
90
72
  catch (e) {
91
73
  console.error('Unknown fill color,', fillAttribute);
92
74
  }
93
75
  }
94
- var strokeAttribute = (_d = (_c = node.getAttribute('stroke')) !== null && _c !== void 0 ? _c : computedStyles === null || computedStyles === void 0 ? void 0 : computedStyles.stroke) !== null && _d !== void 0 ? _d : node.style.stroke;
95
- var strokeWidthAttr = (_g = (_f = node.getAttribute('stroke-width')) !== null && _f !== void 0 ? _f : computedStyles === null || computedStyles === void 0 ? void 0 : computedStyles.strokeWidth) !== null && _g !== void 0 ? _g : node.style.strokeWidth;
76
+ const strokeAttribute = node.getAttribute('stroke') ?? computedStyles?.stroke ?? node.style.stroke;
77
+ const strokeWidthAttr = node.getAttribute('stroke-width') ?? computedStyles?.strokeWidth ?? node.style.strokeWidth;
96
78
  if (strokeAttribute && strokeWidthAttr) {
97
79
  try {
98
- var width = parseFloat(strokeWidthAttr !== null && strokeWidthAttr !== void 0 ? strokeWidthAttr : '1');
80
+ let width = parseFloat(strokeWidthAttr ?? '1');
99
81
  if (!isFinite(width)) {
100
82
  width = 0;
101
83
  }
102
- var strokeColor = Color4_1.default.fromString(strokeAttribute);
84
+ const strokeColor = math_1.Color4.fromString(strokeAttribute);
103
85
  if (strokeColor.a > 0) {
104
86
  stroke = {
105
- width: width,
87
+ width,
106
88
  color: strokeColor,
107
89
  };
108
90
  }
@@ -111,50 +93,49 @@ var SVGLoader = /** @class */ (function () {
111
93
  console.error('Error parsing stroke data:', e);
112
94
  }
113
95
  }
114
- var style = {
115
- fill: fill,
116
- stroke: stroke,
96
+ const style = {
97
+ fill,
98
+ stroke,
117
99
  };
118
100
  return style;
119
- };
120
- SVGLoader.prototype.strokeDataFromElem = function (node) {
121
- var _a;
122
- var result = [];
123
- var pathData = (_a = node.getAttribute('d')) !== null && _a !== void 0 ? _a : '';
124
- var style = this.getStyle(node);
101
+ }
102
+ strokeDataFromElem(node) {
103
+ const result = [];
104
+ const pathData = node.getAttribute('d') ?? '';
105
+ const style = this.getStyle(node);
125
106
  // Break the path into chunks at each moveTo ('M') command:
126
- var parts = pathData.split('M');
127
- var isFirst = true;
128
- for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
129
- var part = parts_1[_i];
107
+ const parts = pathData.split('M');
108
+ let isFirst = true;
109
+ for (const part of parts) {
130
110
  // Skip effective no-ops -- moveTos without additional commands.
131
- var isNoOpMoveTo = /^[0-9., \t\n]+$/.exec(part);
111
+ const isNoOpMoveTo = /^[0-9., \t\n]+$/.exec(part);
132
112
  if (part !== '' && !isNoOpMoveTo) {
133
113
  // We split the path by moveTo commands, so add the 'M' back in
134
114
  // if it was present.
135
- var current = !isFirst ? "M".concat(part) : part;
136
- var path = Path_1.default.fromString(current);
137
- var spec = path.toRenderable(style);
115
+ const current = !isFirst ? `M${part}` : part;
116
+ const path = math_1.Path.fromString(current);
117
+ const spec = (0, RenderablePathSpec_1.pathToRenderable)(path, style);
138
118
  result.push(spec);
139
119
  }
140
120
  isFirst = false;
141
121
  }
142
122
  return result;
143
- };
144
- SVGLoader.prototype.attachUnrecognisedAttrs = function (elem, node, supportedAttrs, supportedStyleAttrs) {
123
+ }
124
+ attachUnrecognisedAttrs(elem, node, supportedAttrs, supportedStyleAttrs) {
145
125
  if (!this.storeUnknown) {
146
126
  return;
147
127
  }
148
- for (var _i = 0, _a = node.getAttributeNames(); _i < _a.length; _i++) {
149
- var attr = _a[_i];
128
+ for (const attr of node.getAttributeNames()) {
150
129
  if (supportedAttrs.has(attr) || (attr === 'style' && supportedStyleAttrs)) {
151
130
  continue;
152
131
  }
153
132
  elem.attachLoadSaveData(exports.svgAttributesDataKey, [attr, node.getAttribute(attr)]);
154
133
  }
155
134
  if (supportedStyleAttrs && node.style) {
156
- for (var _b = 0, _c = node.style; _b < _c.length; _b++) {
157
- var attr = _c[_b];
135
+ // Use a for loop instead of an iterator: js-dom seems to not
136
+ // support using node.style as an iterator.
137
+ for (let i = 0; i < node.style.length; i++) {
138
+ const attr = node.style[i];
158
139
  if (attr === '' || !attr) {
159
140
  continue;
160
141
  }
@@ -169,165 +150,137 @@ var SVGLoader = /** @class */ (function () {
169
150
  });
170
151
  }
171
152
  }
172
- };
153
+ }
173
154
  // Adds a stroke with a single path
174
- SVGLoader.prototype.addPath = function (node) {
175
- var _a;
176
- return __awaiter(this, void 0, void 0, function () {
177
- var elem, strokeData;
178
- return __generator(this, function (_b) {
179
- switch (_b.label) {
180
- case 0:
181
- try {
182
- strokeData = this.strokeDataFromElem(node);
183
- elem = new Stroke_1.default(strokeData);
184
- this.attachUnrecognisedAttrs(elem, node, new Set(__spreadArray(__spreadArray([], supportedStrokeFillStyleAttrs, true), ['d'], false)), new Set(supportedStrokeFillStyleAttrs));
185
- }
186
- catch (e) {
187
- console.error('Invalid path in node', node, '\nError:', e, '\nAdding as an unknown object.');
188
- if (this.storeUnknown) {
189
- elem = new UnknownSVGObject_1.default(node);
190
- }
191
- else {
192
- return [2 /*return*/];
193
- }
194
- }
195
- return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, elem))];
196
- case 1:
197
- _b.sent();
198
- return [2 /*return*/];
155
+ async addPath(node) {
156
+ let elem;
157
+ try {
158
+ const strokeData = this.strokeDataFromElem(node);
159
+ elem = new Stroke_1.default(strokeData);
160
+ this.attachUnrecognisedAttrs(elem, node, new Set([...supportedStrokeFillStyleAttrs, 'd']), new Set(supportedStrokeFillStyleAttrs));
161
+ }
162
+ catch (e) {
163
+ console.error('Invalid path in node', node, '\nError:', e, '\nAdding as an unknown object.');
164
+ if (this.storeUnknown) {
165
+ elem = new UnknownSVGObject_1.default(node);
166
+ }
167
+ else {
168
+ return;
169
+ }
170
+ }
171
+ await this.addComponent(elem);
172
+ }
173
+ async addBackground(node) {
174
+ // If a grid background,
175
+ if (node.classList.contains(BackgroundComponent_1.backgroundTypeToClassNameMap[BackgroundComponent_1.BackgroundType.Grid])) {
176
+ let foregroundStr;
177
+ let backgroundStr;
178
+ let gridStrokeWidthStr;
179
+ // If a group,
180
+ if (node.tagName.toLowerCase() === 'g') {
181
+ // We expect exactly two children. One of these is the solid
182
+ // background of the grid
183
+ if (node.children.length !== 2) {
184
+ await this.addUnknownNode(node);
185
+ return;
199
186
  }
200
- });
201
- });
202
- };
203
- SVGLoader.prototype.addBackground = function (node) {
204
- var _a, _b, _c, _d;
205
- return __awaiter(this, void 0, void 0, function () {
206
- var foregroundStr, backgroundStr, gridStrokeWidthStr, background, grid, gridSize, _i, _f, className, sizeStr, gridStrokeWidth, backgroundColor, foregroundColor, elem, fill, elem;
207
- return __generator(this, function (_g) {
208
- switch (_g.label) {
209
- case 0:
210
- if (!node.classList.contains(BackgroundComponent_1.backgroundTypeToClassNameMap[BackgroundComponent_1.BackgroundType.Grid])) return [3 /*break*/, 8];
211
- foregroundStr = void 0;
212
- backgroundStr = void 0;
213
- gridStrokeWidthStr = void 0;
214
- if (!(node.tagName.toLowerCase() === 'g')) return [3 /*break*/, 3];
215
- if (!(node.children.length !== 2)) return [3 /*break*/, 2];
216
- return [4 /*yield*/, this.addUnknownNode(node)];
217
- case 1:
218
- _g.sent();
219
- return [2 /*return*/];
220
- case 2:
221
- background = node.children[0];
222
- grid = node.children[1];
223
- backgroundStr = background.getAttribute('fill');
224
- foregroundStr = grid.getAttribute('stroke');
225
- gridStrokeWidthStr = grid.getAttribute('stroke-width');
226
- return [3 /*break*/, 4];
227
- case 3:
228
- backgroundStr = node.getAttribute('fill');
229
- foregroundStr = node.getAttribute('stroke');
230
- gridStrokeWidthStr = node.getAttribute('stroke-width');
231
- _g.label = 4;
232
- case 4:
233
- // Default to a transparent background.
234
- backgroundStr !== null && backgroundStr !== void 0 ? backgroundStr : (backgroundStr = Color4_1.default.transparent.toHexString());
235
- if (!!foregroundStr) return [3 /*break*/, 6];
236
- return [4 /*yield*/, this.addUnknownNode(node)];
237
- case 5:
238
- _g.sent();
239
- return [2 /*return*/];
240
- case 6:
241
- gridSize = undefined;
242
- for (_i = 0, _f = node.classList; _i < _f.length; _i++) {
243
- className = _f[_i];
244
- if (className.startsWith(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix)) {
245
- sizeStr = className.substring(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix.length);
246
- gridSize = parseFloat(sizeStr.replace(/p/g, '.'));
247
- }
248
- }
249
- gridStrokeWidth = undefined;
250
- if (gridStrokeWidthStr) {
251
- gridStrokeWidth = parseFloat(gridStrokeWidthStr);
252
- }
253
- backgroundColor = Color4_1.default.fromString(backgroundStr);
254
- foregroundColor = Color4_1.default.fromString(foregroundStr);
255
- // Should the foreground color be determined automatically?
256
- if (!node.classList.contains(BackgroundComponent_1.imageBackgroundNonAutomaticSecondaryColorCSSClassName)) {
257
- foregroundColor = undefined;
258
- }
259
- elem = BackgroundComponent_1.default.ofGrid(backgroundColor, gridSize, foregroundColor, gridStrokeWidth);
260
- return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, elem))];
261
- case 7:
262
- _g.sent();
263
- return [3 /*break*/, 12];
264
- case 8:
265
- if (!(node.tagName.toLowerCase() === 'path')) return [3 /*break*/, 10];
266
- fill = Color4_1.default.fromString((_c = (_b = node.getAttribute('fill')) !== null && _b !== void 0 ? _b : node.style.fill) !== null && _c !== void 0 ? _c : 'black');
267
- elem = new BackgroundComponent_1.default(BackgroundComponent_1.BackgroundType.SolidColor, fill);
268
- return [4 /*yield*/, ((_d = this.onAddComponent) === null || _d === void 0 ? void 0 : _d.call(this, elem))];
269
- case 9:
270
- _g.sent();
271
- return [3 /*break*/, 12];
272
- case 10: return [4 /*yield*/, this.addUnknownNode(node)];
273
- case 11:
274
- _g.sent();
275
- _g.label = 12;
276
- case 12: return [2 /*return*/];
187
+ const background = node.children[0];
188
+ const grid = node.children[1];
189
+ backgroundStr = background.getAttribute('fill');
190
+ foregroundStr = grid.getAttribute('stroke');
191
+ gridStrokeWidthStr = grid.getAttribute('stroke-width');
192
+ }
193
+ else {
194
+ backgroundStr = node.getAttribute('fill');
195
+ foregroundStr = node.getAttribute('stroke');
196
+ gridStrokeWidthStr = node.getAttribute('stroke-width');
197
+ }
198
+ // Default to a transparent background.
199
+ backgroundStr ??= math_1.Color4.transparent.toHexString();
200
+ // A grid must have a foreground color specified.
201
+ if (!foregroundStr) {
202
+ await this.addUnknownNode(node);
203
+ return;
204
+ }
205
+ // Extract the grid size from the class name
206
+ let gridSize = undefined;
207
+ for (const className of node.classList) {
208
+ if (className.startsWith(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix)) {
209
+ const sizeStr = className.substring(BackgroundComponent_1.imageBackgroundGridSizeCSSPrefix.length);
210
+ gridSize = parseFloat(sizeStr.replace(/p/g, '.'));
277
211
  }
278
- });
279
- });
280
- };
212
+ }
213
+ let gridStrokeWidth = undefined;
214
+ if (gridStrokeWidthStr) {
215
+ gridStrokeWidth = parseFloat(gridStrokeWidthStr);
216
+ }
217
+ const backgroundColor = math_1.Color4.fromString(backgroundStr);
218
+ let foregroundColor = math_1.Color4.fromString(foregroundStr);
219
+ // Should the foreground color be determined automatically?
220
+ if (!node.classList.contains(BackgroundComponent_1.imageBackgroundNonAutomaticSecondaryColorCSSClassName)) {
221
+ foregroundColor = undefined;
222
+ }
223
+ const elem = BackgroundComponent_1.default.ofGrid(backgroundColor, gridSize, foregroundColor, gridStrokeWidth);
224
+ await this.addComponent(elem);
225
+ }
226
+ // Otherwise, if just a <path/>, it's a solid color background.
227
+ else if (node.tagName.toLowerCase() === 'path') {
228
+ const fill = math_1.Color4.fromString(node.getAttribute('fill') ?? node.style.fill ?? 'black');
229
+ const elem = new BackgroundComponent_1.default(BackgroundComponent_1.BackgroundType.SolidColor, fill);
230
+ await this.addComponent(elem);
231
+ }
232
+ else {
233
+ await this.addUnknownNode(node);
234
+ }
235
+ }
281
236
  // If given, 'supportedAttrs' will have x, y, etc. attributes that were used in computing the transform added to it,
282
237
  // to prevent storing duplicate transform information when saving the component.
283
- SVGLoader.prototype.getTransform = function (elem, supportedAttrs, computedStyles) {
284
- computedStyles !== null && computedStyles !== void 0 ? computedStyles : (computedStyles = window.getComputedStyle(elem));
285
- var transformProperty = computedStyles.transform;
238
+ getTransform(elem, supportedAttrs, computedStyles) {
239
+ computedStyles ??= window.getComputedStyle(elem);
240
+ let transformProperty = computedStyles.transform;
286
241
  if (transformProperty === '' || transformProperty === 'none') {
287
242
  transformProperty = elem.style.transform || 'none';
288
243
  }
289
244
  // Prefer the actual .style.transform
290
245
  // to the computed stylesheet -- in some browsers, the computedStyles version
291
246
  // can have lower precision.
292
- var transform;
247
+ let transform;
293
248
  try {
294
- transform = Mat33_1.default.fromCSSMatrix(elem.style.transform);
249
+ transform = math_1.Mat33.fromCSSMatrix(elem.style.transform);
295
250
  }
296
251
  catch (_e) {
297
- transform = Mat33_1.default.fromCSSMatrix(transformProperty);
252
+ transform = math_1.Mat33.fromCSSMatrix(transformProperty);
298
253
  }
299
- var elemX = elem.getAttribute('x');
300
- var elemY = elem.getAttribute('y');
254
+ const elemX = elem.getAttribute('x');
255
+ const elemY = elem.getAttribute('y');
301
256
  if (elemX || elemY) {
302
- var x = parseFloat(elemX !== null && elemX !== void 0 ? elemX : '0');
303
- var y = parseFloat(elemY !== null && elemY !== void 0 ? elemY : '0');
257
+ const x = parseFloat(elemX ?? '0');
258
+ const y = parseFloat(elemY ?? '0');
304
259
  if (!isNaN(x) && !isNaN(y)) {
305
- supportedAttrs === null || supportedAttrs === void 0 ? void 0 : supportedAttrs.push('x', 'y');
306
- transform = transform.rightMul(Mat33_1.default.translation(Vec2_1.Vec2.of(x, y)));
260
+ supportedAttrs?.push('x', 'y');
261
+ transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(x, y)));
307
262
  }
308
263
  }
309
264
  return transform;
310
- };
311
- SVGLoader.prototype.makeText = function (elem) {
312
- var _a;
313
- var contentList = [];
314
- for (var _i = 0, _b = elem.childNodes; _i < _b.length; _i++) {
315
- var child = _b[_i];
265
+ }
266
+ makeText(elem) {
267
+ const contentList = [];
268
+ for (const child of elem.childNodes) {
316
269
  if (child.nodeType === Node.TEXT_NODE) {
317
- contentList.push((_a = child.nodeValue) !== null && _a !== void 0 ? _a : '');
270
+ contentList.push(child.nodeValue ?? '');
318
271
  }
319
272
  else if (child.nodeType === Node.ELEMENT_NODE) {
320
- var subElem = child;
273
+ const subElem = child;
321
274
  if (subElem.tagName.toLowerCase() === 'tspan') {
322
275
  // FIXME: tspan's (x, y) components are absolute, not relative to the parent.
323
276
  contentList.push(this.makeText(subElem));
324
277
  }
325
278
  else {
326
- throw new Error("Unrecognized text child element: ".concat(subElem));
279
+ throw new Error(`Unrecognized text child element: ${subElem}`);
327
280
  }
328
281
  }
329
282
  else {
330
- throw new Error("Unrecognized text child node: ".concat(child, "."));
283
+ throw new Error(`Unrecognized text child node: ${child}.`);
331
284
  }
332
285
  }
333
286
  // If no content, the content is an empty string.
@@ -335,11 +288,11 @@ var SVGLoader = /** @class */ (function () {
335
288
  contentList.push('');
336
289
  }
337
290
  // Compute styles.
338
- var computedStyles = window.getComputedStyle(elem);
339
- var fontSizeExp = /^([-0-9.e]+)px/i;
291
+ const computedStyles = window.getComputedStyle(elem);
292
+ const fontSizeExp = /^([-0-9.e]+)px/i;
340
293
  // In some environments, computedStyles.fontSize can be increased by the system.
341
294
  // Thus, to prevent text from growing on load/save, prefer .style.fontSize.
342
- var fontSizeMatch = fontSizeExp.exec(elem.style.fontSize);
295
+ let fontSizeMatch = fontSizeExp.exec(elem.style.fontSize);
343
296
  if (!fontSizeMatch && elem.tagName.toLowerCase() === 'tspan' && elem.parentElement) {
344
297
  // Try to inherit the font size of the parent text element.
345
298
  fontSizeMatch = fontSizeExp.exec(elem.parentElement.style.fontSize);
@@ -349,32 +302,33 @@ var SVGLoader = /** @class */ (function () {
349
302
  if (!fontSizeMatch) {
350
303
  fontSizeMatch = fontSizeExp.exec(computedStyles.fontSize);
351
304
  }
352
- var supportedStyleAttrs = __spreadArray([
305
+ const supportedStyleAttrs = [
353
306
  'fontFamily',
354
- 'transform'
355
- ], supportedStrokeFillStyleAttrs, true);
356
- var fontSize = 12;
307
+ 'transform',
308
+ ...supportedStrokeFillStyleAttrs,
309
+ ];
310
+ let fontSize = 12;
357
311
  if (fontSizeMatch) {
358
312
  supportedStyleAttrs.push('fontSize');
359
313
  fontSize = parseFloat(fontSizeMatch[1]);
360
314
  }
361
- var style = {
315
+ const style = {
362
316
  size: fontSize,
363
317
  fontFamily: computedStyles.fontFamily || elem.style.fontFamily || 'sans-serif',
364
318
  fontWeight: computedStyles.fontWeight || elem.style.fontWeight || undefined,
365
319
  fontStyle: computedStyles.fontStyle || elem.style.fontStyle || undefined,
366
320
  renderingStyle: this.getStyle(elem, computedStyles),
367
321
  };
368
- var supportedAttrs = [];
369
- var transform = this.getTransform(elem, supportedAttrs, computedStyles);
370
- var transformMode = TextComponent_1.TextTransformMode.ABSOLUTE_XY;
371
- var elemDX = elem.getAttribute('dx');
322
+ const supportedAttrs = [];
323
+ let transform = this.getTransform(elem, supportedAttrs, computedStyles);
324
+ let transformMode = TextComponent_1.TextTransformMode.ABSOLUTE_XY;
325
+ const elemDX = elem.getAttribute('dx');
372
326
  if (elemDX) {
373
327
  transformMode = TextComponent_1.TextTransformMode.RELATIVE_X_ABSOLUTE_Y;
374
- transform = transform.rightMul(Mat33_1.default.translation(Vec2_1.Vec2.of(parseFloat(elemDX), 0)));
328
+ transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(parseFloat(elemDX), 0)));
375
329
  supportedAttrs.push('dx');
376
330
  }
377
- var elemDY = elem.getAttribute('dy');
331
+ const elemDY = elem.getAttribute('dy');
378
332
  if (elemDY) {
379
333
  if (transformMode === TextComponent_1.TextTransformMode.RELATIVE_X_ABSOLUTE_Y) {
380
334
  transformMode = TextComponent_1.TextTransformMode.RELATIVE_XY;
@@ -382,249 +336,180 @@ var SVGLoader = /** @class */ (function () {
382
336
  else {
383
337
  transformMode = TextComponent_1.TextTransformMode.RELATIVE_Y_ABSOLUTE_X;
384
338
  }
385
- transform = transform.rightMul(Mat33_1.default.translation(Vec2_1.Vec2.of(0, parseFloat(elemDY))));
339
+ transform = transform.rightMul(math_1.Mat33.translation(math_1.Vec2.of(0, parseFloat(elemDY))));
386
340
  supportedAttrs.push('dy');
387
341
  }
388
- var result = new TextComponent_1.default(contentList, transform, style, transformMode);
342
+ const result = new TextComponent_1.default(contentList, transform, style, transformMode);
389
343
  this.attachUnrecognisedAttrs(result, elem, new Set(supportedAttrs), new Set(supportedStyleAttrs));
390
344
  return result;
391
- };
392
- SVGLoader.prototype.addText = function (elem) {
393
- var _a;
394
- return __awaiter(this, void 0, void 0, function () {
395
- var textElem, e_1;
396
- return __generator(this, function (_b) {
397
- switch (_b.label) {
398
- case 0:
399
- _b.trys.push([0, 2, , 3]);
400
- textElem = this.makeText(elem);
401
- return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, textElem))];
402
- case 1:
403
- _b.sent();
404
- return [3 /*break*/, 3];
405
- case 2:
406
- e_1 = _b.sent();
407
- console.error('Invalid text object in node', elem, '. Continuing.... Error:', e_1);
408
- this.addUnknownNode(elem);
409
- return [3 /*break*/, 3];
410
- case 3: return [2 /*return*/];
411
- }
412
- });
413
- });
414
- };
415
- SVGLoader.prototype.addImage = function (elem) {
416
- var _a, _b, _c;
417
- return __awaiter(this, void 0, void 0, function () {
418
- var image, supportedAttrs, transform, imageElem, e_2;
419
- return __generator(this, function (_d) {
420
- switch (_d.label) {
421
- case 0:
422
- image = new Image();
423
- image.src = (_a = elem.getAttribute('xlink:href')) !== null && _a !== void 0 ? _a : elem.href.baseVal;
424
- image.setAttribute('alt', (_b = elem.getAttribute('aria-label')) !== null && _b !== void 0 ? _b : '');
425
- _d.label = 1;
426
- case 1:
427
- _d.trys.push([1, 4, , 6]);
428
- supportedAttrs = [];
429
- transform = this.getTransform(elem, supportedAttrs);
430
- return [4 /*yield*/, ImageComponent_1.default.fromImage(image, transform)];
431
- case 2:
432
- imageElem = _d.sent();
433
- this.attachUnrecognisedAttrs(imageElem, elem, new Set(supportedAttrs), new Set(['transform']));
434
- return [4 /*yield*/, ((_c = this.onAddComponent) === null || _c === void 0 ? void 0 : _c.call(this, imageElem))];
435
- case 3:
436
- _d.sent();
437
- return [3 /*break*/, 6];
438
- case 4:
439
- e_2 = _d.sent();
440
- console.error('Error loading image:', e_2, '. Element: ', elem, '. Continuing...');
441
- return [4 /*yield*/, this.addUnknownNode(elem)];
442
- case 5:
443
- _d.sent();
444
- return [3 /*break*/, 6];
445
- case 6: return [2 /*return*/];
446
- }
447
- });
448
- });
449
- };
450
- SVGLoader.prototype.addUnknownNode = function (node) {
451
- var _a;
452
- return __awaiter(this, void 0, void 0, function () {
453
- var component;
454
- return __generator(this, function (_b) {
455
- switch (_b.label) {
456
- case 0:
457
- if (!this.storeUnknown) return [3 /*break*/, 2];
458
- component = new UnknownSVGObject_1.default(node);
459
- return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, component))];
460
- case 1:
461
- _b.sent();
462
- _b.label = 2;
463
- case 2: return [2 /*return*/];
464
- }
465
- });
466
- });
467
- };
468
- SVGLoader.prototype.updateViewBox = function (node) {
469
- var _a;
470
- var viewBoxAttr = node.getAttribute('viewBox');
345
+ }
346
+ async addText(elem) {
347
+ try {
348
+ const textElem = this.makeText(elem);
349
+ await this.addComponent(textElem);
350
+ }
351
+ catch (e) {
352
+ console.error('Invalid text object in node', elem, '. Continuing.... Error:', e);
353
+ this.addUnknownNode(elem);
354
+ }
355
+ }
356
+ async addImage(elem) {
357
+ const image = new Image();
358
+ image.src = elem.getAttribute('xlink:href') ?? elem.href.baseVal;
359
+ image.setAttribute('alt', elem.getAttribute('aria-label') ?? '');
360
+ try {
361
+ const supportedAttrs = [];
362
+ const transform = this.getTransform(elem, supportedAttrs);
363
+ const imageElem = await ImageComponent_1.default.fromImage(image, transform);
364
+ this.attachUnrecognisedAttrs(imageElem, elem, new Set(supportedAttrs), new Set(['transform']));
365
+ await this.addComponent(imageElem);
366
+ }
367
+ catch (e) {
368
+ console.error('Error loading image:', e, '. Element: ', elem, '. Continuing...');
369
+ await this.addUnknownNode(elem);
370
+ }
371
+ }
372
+ async addUnknownNode(node) {
373
+ if (this.storeUnknown) {
374
+ const component = new UnknownSVGObject_1.default(node);
375
+ await this.addComponent(component);
376
+ }
377
+ }
378
+ async startGroup(node) {
379
+ node = node.cloneNode(false);
380
+ // Select a unique ID based on the node's ID property (if it exists).
381
+ // Use `||` and not `??` so that empty string IDs are also replaced.
382
+ let id = node.id || `id-${this.encounteredIDs.length}`;
383
+ // Make id unique.
384
+ let idSuffixCounter = 0;
385
+ let suffix = '';
386
+ while (this.encounteredIDs.includes(id + suffix)) {
387
+ idSuffixCounter++;
388
+ suffix = '--' + idSuffixCounter;
389
+ }
390
+ id += suffix;
391
+ // Remove all children from the node -- children will be handled separately
392
+ // (not removing children here could cause duplicates in the result, when rendered).
393
+ node.replaceChildren();
394
+ node.id = id;
395
+ const component = new UnknownSVGObject_1.default(node);
396
+ this.addComponent(component);
397
+ // Add to IDs after -- we don't want the <g> element to be marked
398
+ // as its own container.
399
+ this.containerGroupIDs.push(node.id);
400
+ this.encounteredIDs.push(node.id);
401
+ }
402
+ // Ends the most recent group started by .startGroup
403
+ async endGroup() {
404
+ this.containerGroupIDs.pop();
405
+ }
406
+ async addComponent(component) {
407
+ // Attach the stack of container IDs
408
+ if (this.containerGroupIDs.length > 0) {
409
+ component.attachLoadSaveData(exports.svgLoaderAttributeContainerID, [...this.containerGroupIDs]);
410
+ }
411
+ await this.onAddComponent?.(component);
412
+ }
413
+ updateViewBox(node) {
414
+ const viewBoxAttr = node.getAttribute('viewBox');
471
415
  if (this.rootViewBox || !viewBoxAttr) {
472
416
  return;
473
417
  }
474
- var components = viewBoxAttr.split(/[ \t\n,]+/);
475
- var x = parseFloat(components[0]);
476
- var y = parseFloat(components[1]);
477
- var width = parseFloat(components[2]);
478
- var height = parseFloat(components[3]);
418
+ const components = viewBoxAttr.split(/[ \t\n,]+/);
419
+ const x = parseFloat(components[0]);
420
+ const y = parseFloat(components[1]);
421
+ const width = parseFloat(components[2]);
422
+ const height = parseFloat(components[3]);
479
423
  if (isNaN(x) || isNaN(y) || isNaN(width) || isNaN(height)) {
480
- console.warn("node ".concat(node, " has an unparsable viewbox. Viewbox: ").concat(viewBoxAttr, ". Match: ").concat(components, "."));
424
+ console.warn(`node ${node} has an unparsable viewbox. Viewbox: ${viewBoxAttr}. Match: ${components}.`);
481
425
  return;
482
426
  }
483
- this.rootViewBox = new Rect2_1.default(x, y, width, height);
484
- (_a = this.onDetermineExportRect) === null || _a === void 0 ? void 0 : _a.call(this, this.rootViewBox);
485
- };
486
- SVGLoader.prototype.updateSVGAttrs = function (node) {
487
- var _a;
488
- return __awaiter(this, void 0, void 0, function () {
489
- return __generator(this, function (_b) {
490
- switch (_b.label) {
491
- case 0:
492
- if (!this.storeUnknown) return [3 /*break*/, 2];
493
- return [4 /*yield*/, ((_a = this.onAddComponent) === null || _a === void 0 ? void 0 : _a.call(this, new SVGGlobalAttributesObject_1.default(this.getSourceAttrs(node))))];
494
- case 1:
495
- _b.sent();
496
- _b.label = 2;
497
- case 2: return [2 /*return*/];
427
+ this.rootViewBox = new math_1.Rect2(x, y, width, height);
428
+ this.onDetermineExportRect?.(this.rootViewBox);
429
+ }
430
+ async updateSVGAttrs(node) {
431
+ if (this.storeUnknown) {
432
+ await this.onAddComponent?.(new SVGGlobalAttributesObject_1.default(this.getSourceAttrs(node)));
433
+ }
434
+ }
435
+ async visit(node) {
436
+ this.totalToProcess += node.childElementCount;
437
+ let visitChildren = true;
438
+ switch (node.tagName.toLowerCase()) {
439
+ case 'g':
440
+ if (node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) {
441
+ await this.addBackground(node);
442
+ visitChildren = false;
498
443
  }
499
- });
500
- });
501
- };
502
- SVGLoader.prototype.visit = function (node) {
503
- var _a;
504
- return __awaiter(this, void 0, void 0, function () {
505
- var visitChildren, _b, _i, _c, child;
506
- return __generator(this, function (_d) {
507
- switch (_d.label) {
508
- case 0:
509
- this.totalToProcess += node.childElementCount;
510
- visitChildren = true;
511
- _b = node.tagName.toLowerCase();
512
- switch (_b) {
513
- case 'g': return [3 /*break*/, 1];
514
- case 'path': return [3 /*break*/, 4];
515
- case 'text': return [3 /*break*/, 9];
516
- case 'image': return [3 /*break*/, 11];
517
- case 'svg': return [3 /*break*/, 13];
518
- case 'style': return [3 /*break*/, 14];
519
- }
520
- return [3 /*break*/, 16];
521
- case 1:
522
- if (!node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) return [3 /*break*/, 3];
523
- return [4 /*yield*/, this.addBackground(node)];
524
- case 2:
525
- _d.sent();
526
- visitChildren = false;
527
- _d.label = 3;
528
- case 3:
529
- // Otherwise, continue -- visit the node's children.
530
- return [3 /*break*/, 18];
531
- case 4:
532
- if (!node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) return [3 /*break*/, 6];
533
- return [4 /*yield*/, this.addBackground(node)];
534
- case 5:
535
- _d.sent();
536
- return [3 /*break*/, 8];
537
- case 6: return [4 /*yield*/, this.addPath(node)];
538
- case 7:
539
- _d.sent();
540
- _d.label = 8;
541
- case 8: return [3 /*break*/, 18];
542
- case 9: return [4 /*yield*/, this.addText(node)];
543
- case 10:
544
- _d.sent();
545
- visitChildren = false;
546
- return [3 /*break*/, 18];
547
- case 11: return [4 /*yield*/, this.addImage(node)];
548
- case 12:
549
- _d.sent();
550
- // Images should not have children.
551
- visitChildren = false;
552
- return [3 /*break*/, 18];
553
- case 13:
554
- this.updateViewBox(node);
555
- this.updateSVGAttrs(node);
556
- return [3 /*break*/, 18];
557
- case 14: return [4 /*yield*/, this.addUnknownNode(node)];
558
- case 15:
559
- _d.sent();
560
- return [3 /*break*/, 18];
561
- case 16:
562
- console.warn('Unknown SVG element,', node);
563
- if (!(node instanceof SVGElement)) {
564
- console.warn('Element', node, 'is not an SVGElement!', this.storeUnknown ? 'Continuing anyway.' : 'Skipping.');
565
- }
566
- return [4 /*yield*/, this.addUnknownNode(node)];
567
- case 17:
568
- _d.sent();
569
- return [2 /*return*/];
570
- case 18:
571
- if (!visitChildren) return [3 /*break*/, 22];
572
- _i = 0, _c = node.children;
573
- _d.label = 19;
574
- case 19:
575
- if (!(_i < _c.length)) return [3 /*break*/, 22];
576
- child = _c[_i];
577
- return [4 /*yield*/, this.visit(child)];
578
- case 20:
579
- _d.sent();
580
- _d.label = 21;
581
- case 21:
582
- _i++;
583
- return [3 /*break*/, 19];
584
- case 22:
585
- this.processedCount++;
586
- return [4 /*yield*/, ((_a = this.onProgress) === null || _a === void 0 ? void 0 : _a.call(this, this.processedCount, this.totalToProcess))];
587
- case 23:
588
- _d.sent();
589
- return [2 /*return*/];
444
+ else {
445
+ await this.startGroup(node);
590
446
  }
591
- });
592
- });
593
- };
447
+ // Otherwise, continue -- visit the node's children.
448
+ break;
449
+ case 'path':
450
+ if (node.classList.contains(BackgroundComponent_1.imageBackgroundCSSClassName)) {
451
+ await this.addBackground(node);
452
+ }
453
+ else {
454
+ await this.addPath(node);
455
+ }
456
+ break;
457
+ case 'text':
458
+ await this.addText(node);
459
+ visitChildren = false;
460
+ break;
461
+ case 'image':
462
+ await this.addImage(node);
463
+ // Images should not have children.
464
+ visitChildren = false;
465
+ break;
466
+ case 'svg':
467
+ this.updateViewBox(node);
468
+ this.updateSVGAttrs(node);
469
+ break;
470
+ case 'style':
471
+ await this.addUnknownNode(node);
472
+ break;
473
+ default:
474
+ console.warn('Unknown SVG element,', node, node.tagName);
475
+ if (!(node instanceof SVGElement)) {
476
+ console.warn('Element', node, 'is not an SVGElement!', this.storeUnknown ? 'Continuing anyway.' : 'Skipping.');
477
+ }
478
+ await this.addUnknownNode(node);
479
+ return;
480
+ }
481
+ if (visitChildren) {
482
+ for (const child of node.children) {
483
+ await this.visit(child);
484
+ }
485
+ if (node.tagName.toLowerCase() === 'g') {
486
+ await this.endGroup();
487
+ }
488
+ }
489
+ this.processedCount++;
490
+ await this.onProgress?.(this.processedCount, this.totalToProcess);
491
+ }
594
492
  // Get SVG element attributes (e.g. xlink=...)
595
- SVGLoader.prototype.getSourceAttrs = function (node) {
596
- return node.getAttributeNames().map(function (attr) {
493
+ getSourceAttrs(node) {
494
+ return node.getAttributeNames().map(attr => {
597
495
  return [attr, node.getAttribute(attr)];
598
496
  });
599
- };
600
- SVGLoader.prototype.start = function (onAddComponent, onProgress, onDetermineExportRect) {
601
- var _a, _b;
602
- if (onDetermineExportRect === void 0) { onDetermineExportRect = null; }
603
- return __awaiter(this, void 0, void 0, function () {
604
- var viewBox;
605
- return __generator(this, function (_c) {
606
- switch (_c.label) {
607
- case 0:
608
- this.onAddComponent = onAddComponent;
609
- this.onProgress = onProgress;
610
- this.onDetermineExportRect = onDetermineExportRect;
611
- // Estimate the number of tags to process.
612
- this.totalToProcess = this.source.childElementCount;
613
- this.processedCount = 0;
614
- this.rootViewBox = null;
615
- return [4 /*yield*/, this.visit(this.source)];
616
- case 1:
617
- _c.sent();
618
- viewBox = this.rootViewBox;
619
- if (!viewBox) {
620
- (_a = this.onDetermineExportRect) === null || _a === void 0 ? void 0 : _a.call(this, exports.defaultSVGViewRect);
621
- }
622
- (_b = this.onFinish) === null || _b === void 0 ? void 0 : _b.call(this);
623
- return [2 /*return*/];
624
- }
625
- });
626
- });
627
- };
497
+ }
498
+ async start(onAddComponent, onProgress, onDetermineExportRect = null) {
499
+ this.onAddComponent = onAddComponent;
500
+ this.onProgress = onProgress;
501
+ this.onDetermineExportRect = onDetermineExportRect;
502
+ // Estimate the number of tags to process.
503
+ this.totalToProcess = this.source.childElementCount;
504
+ this.processedCount = 0;
505
+ this.rootViewBox = null;
506
+ await this.visit(this.source);
507
+ const viewBox = this.rootViewBox;
508
+ if (!viewBox) {
509
+ this.onDetermineExportRect?.(exports.defaultSVGViewRect);
510
+ }
511
+ this.onFinish?.();
512
+ }
628
513
  /**
629
514
  * Create an `SVGLoader` from the content of an SVG image. SVGs are loaded within a sandboxed
630
515
  * iframe with `sandbox="allow-same-origin"`
@@ -634,10 +519,8 @@ var SVGLoader = /** @class */ (function () {
634
519
  * @param text - Textual representation of the SVG (e.g. `<svg viewbox='...'>...</svg>`).
635
520
  * @param sanitize - if `true`, don't store unknown attributes.
636
521
  */
637
- SVGLoader.fromString = function (text, sanitize) {
638
- var _a, _b;
639
- if (sanitize === void 0) { sanitize = false; }
640
- var sandbox = document.createElement('iframe');
522
+ static fromString(text, sanitize = false) {
523
+ const sandbox = document.createElement('iframe');
641
524
  sandbox.src = 'about:blank';
642
525
  sandbox.setAttribute('sandbox', 'allow-same-origin');
643
526
  sandbox.setAttribute('csp', 'default-src \'about:blank\'');
@@ -648,20 +531,36 @@ var SVGLoader = /** @class */ (function () {
648
531
  sandbox.remove();
649
532
  throw new Error('SVG loading iframe is not sandboxed.');
650
533
  }
651
- var sandboxDoc = (_b = (_a = sandbox.contentWindow) === null || _a === void 0 ? void 0 : _a.document) !== null && _b !== void 0 ? _b : sandbox.contentDocument;
534
+ const sandboxDoc = sandbox.contentWindow?.document ?? sandbox.contentDocument;
652
535
  if (sandboxDoc == null)
653
536
  throw new Error('Unable to open a sandboxed iframe!');
654
537
  sandboxDoc.open();
655
- sandboxDoc.write("\n\t\t\t<!DOCTYPE html>\n\t\t\t<html>\n\t\t\t\t<head>\n\t\t\t\t\t<title>SVG Loading Sandbox</title>\n\t\t\t\t\t<meta name='viewport' conent='width=device-width,initial-scale=1.0'/>\n\t\t\t\t\t<meta charset='utf-8'/>\n\t\t\t\t</head>\n\t\t\t\t<body style='font-size: 12px;'>\n\t\t\t\t\t<script>\n\t\t\t\t\t\tconsole.error('JavaScript should not be able to run here!');\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t'The SVG sandbox is broken! Please double-check the sandboxing setting.'\n\t\t\t\t\t\t);\n\t\t\t\t\t</script>\n\t\t\t\t</body>\n\t\t\t</html>\n\t\t");
538
+ sandboxDoc.write(`
539
+ <!DOCTYPE html>
540
+ <html>
541
+ <head>
542
+ <title>SVG Loading Sandbox</title>
543
+ <meta name='viewport' conent='width=device-width,initial-scale=1.0'/>
544
+ <meta charset='utf-8'/>
545
+ </head>
546
+ <body style='font-size: 12px;'>
547
+ <script>
548
+ console.error('JavaScript should not be able to run here!');
549
+ throw new Error(
550
+ 'The SVG sandbox is broken! Please double-check the sandboxing setting.'
551
+ );
552
+ </script>
553
+ </body>
554
+ </html>
555
+ `);
656
556
  sandboxDoc.close();
657
- var svgElem = sandboxDoc.createElementNS('http://www.w3.org/2000/svg', 'svg');
557
+ const svgElem = sandboxDoc.createElementNS('http://www.w3.org/2000/svg', 'svg');
658
558
  svgElem.innerHTML = text;
659
559
  sandboxDoc.body.appendChild(svgElem);
660
- return new SVGLoader(svgElem, function () {
560
+ return new SVGLoader(svgElem, () => {
661
561
  svgElem.remove();
662
562
  sandbox.remove();
663
563
  }, !sanitize);
664
- };
665
- return SVGLoader;
666
- }());
564
+ }
565
+ }
667
566
  exports.default = SVGLoader;