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