js-draw 0.17.4 → 0.18.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 (413) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bundle.js +9 -1
  3. package/package.json +35 -33
  4. package/tsconfig.json +3 -2
  5. package/tsconfig.mjs.json +9 -0
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -34
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  8. package/.github/ISSUE_TEMPLATE/translation.yml +0 -902
  9. package/.github/pull_request_template.md +0 -15
  10. package/.github/workflows/firebase-hosting-merge.yml +0 -32
  11. package/.github/workflows/firebase-hosting-pull-request.yml +0 -32
  12. package/.github/workflows/github-pages.yml +0 -56
  13. package/.husky/pre-commit +0 -4
  14. package/build_tools/BundledFile.ts +0 -167
  15. package/build_tools/buildTranslationTemplate.ts +0 -121
  16. package/build_tools/bundle.ts +0 -11
  17. package/dist/build_tools/BundledFile.d.ts +0 -13
  18. package/dist/build_tools/BundledFile.js +0 -157
  19. package/dist/build_tools/buildTranslationTemplate.d.ts +0 -1
  20. package/dist/build_tools/buildTranslationTemplate.js +0 -94
  21. package/dist/build_tools/bundle.d.ts +0 -1
  22. package/dist/build_tools/bundle.js +0 -5
  23. package/dist/src/Color4.d.ts +0 -60
  24. package/dist/src/Color4.js +0 -192
  25. package/dist/src/Editor.d.ts +0 -308
  26. package/dist/src/Editor.js +0 -874
  27. package/dist/src/EditorImage.d.ts +0 -97
  28. package/dist/src/EditorImage.js +0 -477
  29. package/dist/src/EventDispatcher.d.ts +0 -30
  30. package/dist/src/EventDispatcher.js +0 -54
  31. package/dist/src/Pointer.d.ts +0 -24
  32. package/dist/src/Pointer.js +0 -80
  33. package/dist/src/SVGLoader.d.ts +0 -48
  34. package/dist/src/SVGLoader.js +0 -442
  35. package/dist/src/UndoRedoHistory.d.ts +0 -19
  36. package/dist/src/UndoRedoHistory.js +0 -91
  37. package/dist/src/Viewport.d.ts +0 -71
  38. package/dist/src/Viewport.js +0 -256
  39. package/dist/src/bundle/bundled.d.ts +0 -4
  40. package/dist/src/bundle/bundled.js +0 -5
  41. package/dist/src/commands/Command.d.ts +0 -16
  42. package/dist/src/commands/Command.js +0 -30
  43. package/dist/src/commands/Duplicate.d.ts +0 -14
  44. package/dist/src/commands/Duplicate.js +0 -33
  45. package/dist/src/commands/Erase.d.ts +0 -14
  46. package/dist/src/commands/Erase.js +0 -57
  47. package/dist/src/commands/SerializableCommand.d.ts +0 -12
  48. package/dist/src/commands/SerializableCommand.js +0 -36
  49. package/dist/src/commands/UnresolvedCommand.d.ts +0 -14
  50. package/dist/src/commands/UnresolvedCommand.js +0 -22
  51. package/dist/src/commands/invertCommand.d.ts +0 -4
  52. package/dist/src/commands/invertCommand.js +0 -44
  53. package/dist/src/commands/lib.d.ts +0 -7
  54. package/dist/src/commands/lib.js +0 -7
  55. package/dist/src/commands/localization.d.ts +0 -23
  56. package/dist/src/commands/localization.js +0 -21
  57. package/dist/src/commands/uniteCommands.d.ts +0 -4
  58. package/dist/src/commands/uniteCommands.js +0 -116
  59. package/dist/src/components/AbstractComponent.d.ts +0 -73
  60. package/dist/src/components/AbstractComponent.js +0 -252
  61. package/dist/src/components/ImageBackground.d.ts +0 -42
  62. package/dist/src/components/ImageBackground.js +0 -139
  63. package/dist/src/components/ImageComponent.d.ts +0 -31
  64. package/dist/src/components/ImageComponent.js +0 -146
  65. package/dist/src/components/RestylableComponent.d.ts +0 -24
  66. package/dist/src/components/RestylableComponent.js +0 -80
  67. package/dist/src/components/SVGGlobalAttributesObject.d.ts +0 -21
  68. package/dist/src/components/SVGGlobalAttributesObject.js +0 -59
  69. package/dist/src/components/Stroke.d.ts +0 -40
  70. package/dist/src/components/Stroke.js +0 -185
  71. package/dist/src/components/TextComponent.d.ts +0 -53
  72. package/dist/src/components/TextComponent.js +0 -252
  73. package/dist/src/components/UnknownSVGObject.d.ts +0 -18
  74. package/dist/src/components/UnknownSVGObject.js +0 -44
  75. package/dist/src/components/builders/ArrowBuilder.d.ts +0 -19
  76. package/dist/src/components/builders/ArrowBuilder.js +0 -86
  77. package/dist/src/components/builders/FreehandLineBuilder.d.ts +0 -33
  78. package/dist/src/components/builders/FreehandLineBuilder.js +0 -165
  79. package/dist/src/components/builders/LineBuilder.d.ts +0 -18
  80. package/dist/src/components/builders/LineBuilder.js +0 -58
  81. package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +0 -36
  82. package/dist/src/components/builders/PressureSensitiveFreehandLineBuilder.js +0 -339
  83. package/dist/src/components/builders/RectangleBuilder.d.ts +0 -20
  84. package/dist/src/components/builders/RectangleBuilder.js +0 -50
  85. package/dist/src/components/builders/types.d.ts +0 -12
  86. package/dist/src/components/builders/types.js +0 -1
  87. package/dist/src/components/lib.d.ts +0 -12
  88. package/dist/src/components/lib.js +0 -12
  89. package/dist/src/components/localization.d.ts +0 -11
  90. package/dist/src/components/localization.js +0 -10
  91. package/dist/src/components/util/StrokeSmoother.d.ts +0 -35
  92. package/dist/src/components/util/StrokeSmoother.js +0 -210
  93. package/dist/src/components/util/describeComponentList.d.ts +0 -4
  94. package/dist/src/components/util/describeComponentList.js +0 -14
  95. package/dist/src/lib.d.ts +0 -34
  96. package/dist/src/lib.js +0 -34
  97. package/dist/src/localization.d.ts +0 -14
  98. package/dist/src/localization.js +0 -10
  99. package/dist/src/localizations/de.d.ts +0 -3
  100. package/dist/src/localizations/de.js +0 -4
  101. package/dist/src/localizations/en.d.ts +0 -3
  102. package/dist/src/localizations/en.js +0 -4
  103. package/dist/src/localizations/es.d.ts +0 -3
  104. package/dist/src/localizations/es.js +0 -18
  105. package/dist/src/localizations/getLocalizationTable.d.ts +0 -3
  106. package/dist/src/localizations/getLocalizationTable.js +0 -45
  107. package/dist/src/math/LineSegment2.d.ts +0 -24
  108. package/dist/src/math/LineSegment2.js +0 -125
  109. package/dist/src/math/Mat33.d.ts +0 -118
  110. package/dist/src/math/Mat33.js +0 -326
  111. package/dist/src/math/Path.d.ts +0 -71
  112. package/dist/src/math/Path.js +0 -648
  113. package/dist/src/math/Rect2.d.ts +0 -52
  114. package/dist/src/math/Rect2.js +0 -228
  115. package/dist/src/math/Triangle.d.ts +0 -11
  116. package/dist/src/math/Triangle.js +0 -19
  117. package/dist/src/math/Vec2.d.ts +0 -13
  118. package/dist/src/math/Vec2.js +0 -13
  119. package/dist/src/math/Vec3.d.ts +0 -106
  120. package/dist/src/math/Vec3.js +0 -174
  121. package/dist/src/math/lib.d.ts +0 -7
  122. package/dist/src/math/lib.js +0 -7
  123. package/dist/src/math/rounding.d.ts +0 -4
  124. package/dist/src/math/rounding.js +0 -128
  125. package/dist/src/rendering/Display.d.ts +0 -75
  126. package/dist/src/rendering/Display.js +0 -207
  127. package/dist/src/rendering/RenderingStyle.d.ts +0 -31
  128. package/dist/src/rendering/RenderingStyle.js +0 -38
  129. package/dist/src/rendering/TextRenderingStyle.d.ts +0 -36
  130. package/dist/src/rendering/TextRenderingStyle.js +0 -23
  131. package/dist/src/rendering/caching/CacheRecord.d.ts +0 -20
  132. package/dist/src/rendering/caching/CacheRecord.js +0 -55
  133. package/dist/src/rendering/caching/CacheRecordManager.d.ts +0 -12
  134. package/dist/src/rendering/caching/CacheRecordManager.js +0 -43
  135. package/dist/src/rendering/caching/RenderingCache.d.ts +0 -11
  136. package/dist/src/rendering/caching/RenderingCache.js +0 -45
  137. package/dist/src/rendering/caching/RenderingCacheNode.d.ts +0 -29
  138. package/dist/src/rendering/caching/RenderingCacheNode.js +0 -320
  139. package/dist/src/rendering/caching/testUtils.d.ts +0 -9
  140. package/dist/src/rendering/caching/testUtils.js +0 -20
  141. package/dist/src/rendering/caching/types.d.ts +0 -19
  142. package/dist/src/rendering/caching/types.js +0 -1
  143. package/dist/src/rendering/lib.d.ts +0 -5
  144. package/dist/src/rendering/lib.js +0 -5
  145. package/dist/src/rendering/localization.d.ts +0 -10
  146. package/dist/src/rendering/localization.js +0 -9
  147. package/dist/src/rendering/renderers/AbstractRenderer.d.ts +0 -68
  148. package/dist/src/rendering/renderers/AbstractRenderer.js +0 -144
  149. package/dist/src/rendering/renderers/CanvasRenderer.d.ts +0 -63
  150. package/dist/src/rendering/renderers/CanvasRenderer.js +0 -230
  151. package/dist/src/rendering/renderers/DummyRenderer.d.ts +0 -35
  152. package/dist/src/rendering/renderers/DummyRenderer.js +0 -106
  153. package/dist/src/rendering/renderers/SVGRenderer.d.ts +0 -57
  154. package/dist/src/rendering/renderers/SVGRenderer.js +0 -304
  155. package/dist/src/rendering/renderers/TextOnlyRenderer.d.ts +0 -29
  156. package/dist/src/rendering/renderers/TextOnlyRenderer.js +0 -57
  157. package/dist/src/testing/beforeEachFile.d.ts +0 -1
  158. package/dist/src/testing/beforeEachFile.js +0 -7
  159. package/dist/src/testing/createEditor.d.ts +0 -4
  160. package/dist/src/testing/createEditor.js +0 -9
  161. package/dist/src/testing/lib.d.ts +0 -2
  162. package/dist/src/testing/lib.js +0 -2
  163. package/dist/src/testing/loadExpectExtensions.d.ts +0 -2
  164. package/dist/src/testing/loadExpectExtensions.js +0 -24
  165. package/dist/src/testing/sendPenEvent.d.ts +0 -12
  166. package/dist/src/testing/sendPenEvent.js +0 -19
  167. package/dist/src/testing/sendTouchEvent.d.ts +0 -42
  168. package/dist/src/testing/sendTouchEvent.js +0 -62
  169. package/dist/src/toolbar/HTMLToolbar.d.ts +0 -103
  170. package/dist/src/toolbar/HTMLToolbar.js +0 -376
  171. package/dist/src/toolbar/IconProvider.d.ts +0 -62
  172. package/dist/src/toolbar/IconProvider.js +0 -654
  173. package/dist/src/toolbar/lib.d.ts +0 -3
  174. package/dist/src/toolbar/lib.js +0 -3
  175. package/dist/src/toolbar/localization.d.ts +0 -49
  176. package/dist/src/toolbar/localization.js +0 -48
  177. package/dist/src/toolbar/makeColorInput.d.ts +0 -6
  178. package/dist/src/toolbar/makeColorInput.js +0 -113
  179. package/dist/src/toolbar/types.d.ts +0 -4
  180. package/dist/src/toolbar/types.js +0 -1
  181. package/dist/src/toolbar/widgets/ActionButtonWidget.d.ts +0 -15
  182. package/dist/src/toolbar/widgets/ActionButtonWidget.js +0 -25
  183. package/dist/src/toolbar/widgets/BaseToolWidget.d.ts +0 -11
  184. package/dist/src/toolbar/widgets/BaseToolWidget.js +0 -44
  185. package/dist/src/toolbar/widgets/BaseWidget.d.ts +0 -72
  186. package/dist/src/toolbar/widgets/BaseWidget.js +0 -307
  187. package/dist/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +0 -18
  188. package/dist/src/toolbar/widgets/DocumentPropertiesWidget.js +0 -120
  189. package/dist/src/toolbar/widgets/EraserToolWidget.d.ts +0 -17
  190. package/dist/src/toolbar/widgets/EraserToolWidget.js +0 -57
  191. package/dist/src/toolbar/widgets/HandToolWidget.d.ts +0 -17
  192. package/dist/src/toolbar/widgets/HandToolWidget.js +0 -172
  193. package/dist/src/toolbar/widgets/InsertImageWidget.d.ts +0 -19
  194. package/dist/src/toolbar/widgets/InsertImageWidget.js +0 -170
  195. package/dist/src/toolbar/widgets/OverflowWidget.d.ts +0 -25
  196. package/dist/src/toolbar/widgets/OverflowWidget.js +0 -71
  197. package/dist/src/toolbar/widgets/PenToolWidget.d.ts +0 -27
  198. package/dist/src/toolbar/widgets/PenToolWidget.js +0 -220
  199. package/dist/src/toolbar/widgets/SelectionToolWidget.d.ts +0 -13
  200. package/dist/src/toolbar/widgets/SelectionToolWidget.js +0 -147
  201. package/dist/src/toolbar/widgets/TextToolWidget.d.ts +0 -16
  202. package/dist/src/toolbar/widgets/TextToolWidget.js +0 -109
  203. package/dist/src/toolbar/widgets/lib.d.ts +0 -10
  204. package/dist/src/toolbar/widgets/lib.js +0 -10
  205. package/dist/src/tools/BaseTool.d.ts +0 -22
  206. package/dist/src/tools/BaseTool.js +0 -63
  207. package/dist/src/tools/Eraser.d.ts +0 -23
  208. package/dist/src/tools/Eraser.js +0 -106
  209. package/dist/src/tools/FindTool.d.ts +0 -21
  210. package/dist/src/tools/FindTool.js +0 -114
  211. package/dist/src/tools/PanZoom.d.ts +0 -52
  212. package/dist/src/tools/PanZoom.js +0 -414
  213. package/dist/src/tools/PasteHandler.d.ts +0 -23
  214. package/dist/src/tools/PasteHandler.js +0 -93
  215. package/dist/src/tools/Pen.d.ts +0 -39
  216. package/dist/src/tools/Pen.js +0 -173
  217. package/dist/src/tools/PipetteTool.d.ts +0 -18
  218. package/dist/src/tools/PipetteTool.js +0 -39
  219. package/dist/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +0 -8
  220. package/dist/src/tools/SelectionTool/SelectAllShortcutHandler.js +0 -22
  221. package/dist/src/tools/SelectionTool/Selection.d.ts +0 -64
  222. package/dist/src/tools/SelectionTool/Selection.js +0 -459
  223. package/dist/src/tools/SelectionTool/SelectionHandle.d.ts +0 -38
  224. package/dist/src/tools/SelectionTool/SelectionHandle.js +0 -81
  225. package/dist/src/tools/SelectionTool/SelectionTool.d.ts +0 -36
  226. package/dist/src/tools/SelectionTool/SelectionTool.js +0 -398
  227. package/dist/src/tools/SelectionTool/TransformMode.d.ts +0 -34
  228. package/dist/src/tools/SelectionTool/TransformMode.js +0 -98
  229. package/dist/src/tools/SelectionTool/types.d.ts +0 -9
  230. package/dist/src/tools/SelectionTool/types.js +0 -11
  231. package/dist/src/tools/TextTool.d.ts +0 -33
  232. package/dist/src/tools/TextTool.js +0 -256
  233. package/dist/src/tools/ToolController.d.ts +0 -18
  234. package/dist/src/tools/ToolController.js +0 -158
  235. package/dist/src/tools/ToolEnabledGroup.d.ts +0 -6
  236. package/dist/src/tools/ToolEnabledGroup.js +0 -11
  237. package/dist/src/tools/ToolSwitcherShortcut.d.ts +0 -16
  238. package/dist/src/tools/ToolSwitcherShortcut.js +0 -32
  239. package/dist/src/tools/ToolbarShortcutHandler.d.ts +0 -12
  240. package/dist/src/tools/ToolbarShortcutHandler.js +0 -23
  241. package/dist/src/tools/UndoRedoShortcut.d.ts +0 -8
  242. package/dist/src/tools/UndoRedoShortcut.js +0 -22
  243. package/dist/src/tools/lib.d.ts +0 -16
  244. package/dist/src/tools/lib.js +0 -16
  245. package/dist/src/tools/localization.d.ts +0 -28
  246. package/dist/src/tools/localization.js +0 -27
  247. package/dist/src/types.d.ts +0 -151
  248. package/dist/src/types.js +0 -35
  249. package/dist/src/util/assertions.d.ts +0 -23
  250. package/dist/src/util/assertions.js +0 -45
  251. package/dist/src/util/fileToBase64.d.ts +0 -3
  252. package/dist/src/util/fileToBase64.js +0 -13
  253. package/dist/src/util/untilNextAnimationFrame.d.ts +0 -3
  254. package/dist/src/util/untilNextAnimationFrame.js +0 -7
  255. package/dist/src/util/waitForTimeout.d.ts +0 -2
  256. package/dist/src/util/waitForTimeout.js +0 -7
  257. package/src/Color4.test.ts +0 -40
  258. package/src/Color4.ts +0 -234
  259. package/src/Editor.css +0 -86
  260. package/src/Editor.loadFrom.test.ts +0 -24
  261. package/src/Editor.toSVG.test.ts +0 -111
  262. package/src/Editor.ts +0 -1122
  263. package/src/EditorImage.test.ts +0 -120
  264. package/src/EditorImage.ts +0 -603
  265. package/src/EventDispatcher.test.ts +0 -123
  266. package/src/EventDispatcher.ts +0 -71
  267. package/src/Pointer.ts +0 -127
  268. package/src/SVGLoader.test.ts +0 -114
  269. package/src/SVGLoader.ts +0 -511
  270. package/src/UndoRedoHistory.test.ts +0 -33
  271. package/src/UndoRedoHistory.ts +0 -102
  272. package/src/Viewport.ts +0 -319
  273. package/src/bundle/bundled.ts +0 -7
  274. package/src/commands/Command.ts +0 -45
  275. package/src/commands/Duplicate.ts +0 -48
  276. package/src/commands/Erase.ts +0 -74
  277. package/src/commands/SerializableCommand.ts +0 -49
  278. package/src/commands/UnresolvedCommand.ts +0 -37
  279. package/src/commands/invertCommand.ts +0 -51
  280. package/src/commands/lib.ts +0 -16
  281. package/src/commands/localization.ts +0 -47
  282. package/src/commands/uniteCommands.test.ts +0 -23
  283. package/src/commands/uniteCommands.ts +0 -135
  284. package/src/components/AbstractComponent.transformBy.test.ts +0 -22
  285. package/src/components/AbstractComponent.ts +0 -364
  286. package/src/components/ImageBackground.test.ts +0 -35
  287. package/src/components/ImageBackground.ts +0 -176
  288. package/src/components/ImageComponent.ts +0 -171
  289. package/src/components/RestylableComponent.ts +0 -142
  290. package/src/components/SVGGlobalAttributesObject.ts +0 -81
  291. package/src/components/Stroke.test.ts +0 -139
  292. package/src/components/Stroke.ts +0 -245
  293. package/src/components/TextComponent.test.ts +0 -99
  294. package/src/components/TextComponent.ts +0 -315
  295. package/src/components/UnknownSVGObject.test.ts +0 -10
  296. package/src/components/UnknownSVGObject.ts +0 -60
  297. package/src/components/builders/ArrowBuilder.ts +0 -107
  298. package/src/components/builders/FreehandLineBuilder.ts +0 -212
  299. package/src/components/builders/LineBuilder.ts +0 -77
  300. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +0 -454
  301. package/src/components/builders/RectangleBuilder.ts +0 -74
  302. package/src/components/builders/types.ts +0 -15
  303. package/src/components/lib.ts +0 -25
  304. package/src/components/localization.ts +0 -22
  305. package/src/components/util/StrokeSmoother.ts +0 -293
  306. package/src/components/util/describeComponentList.ts +0 -18
  307. package/src/lib.ts +0 -37
  308. package/src/localization.ts +0 -34
  309. package/src/localizations/de.ts +0 -98
  310. package/src/localizations/en.ts +0 -8
  311. package/src/localizations/es.ts +0 -74
  312. package/src/localizations/getLocalizationTable.test.ts +0 -27
  313. package/src/localizations/getLocalizationTable.ts +0 -55
  314. package/src/math/LineSegment2.test.ts +0 -99
  315. package/src/math/LineSegment2.ts +0 -160
  316. package/src/math/Mat33.test.ts +0 -244
  317. package/src/math/Mat33.ts +0 -437
  318. package/src/math/Path.fromString.test.ts +0 -223
  319. package/src/math/Path.test.ts +0 -198
  320. package/src/math/Path.toString.test.ts +0 -77
  321. package/src/math/Path.ts +0 -790
  322. package/src/math/Rect2.test.ts +0 -204
  323. package/src/math/Rect2.ts +0 -315
  324. package/src/math/Triangle.ts +0 -29
  325. package/src/math/Vec2.test.ts +0 -30
  326. package/src/math/Vec2.ts +0 -18
  327. package/src/math/Vec3.test.ts +0 -44
  328. package/src/math/Vec3.ts +0 -218
  329. package/src/math/lib.ts +0 -15
  330. package/src/math/rounding.test.ts +0 -65
  331. package/src/math/rounding.ts +0 -156
  332. package/src/rendering/Display.ts +0 -249
  333. package/src/rendering/RenderingStyle.test.ts +0 -68
  334. package/src/rendering/RenderingStyle.ts +0 -55
  335. package/src/rendering/TextRenderingStyle.ts +0 -45
  336. package/src/rendering/caching/CacheRecord.test.ts +0 -49
  337. package/src/rendering/caching/CacheRecord.ts +0 -77
  338. package/src/rendering/caching/CacheRecordManager.ts +0 -71
  339. package/src/rendering/caching/RenderingCache.test.ts +0 -44
  340. package/src/rendering/caching/RenderingCache.ts +0 -66
  341. package/src/rendering/caching/RenderingCacheNode.ts +0 -405
  342. package/src/rendering/caching/testUtils.ts +0 -35
  343. package/src/rendering/caching/types.ts +0 -34
  344. package/src/rendering/lib.ts +0 -6
  345. package/src/rendering/localization.ts +0 -20
  346. package/src/rendering/renderers/AbstractRenderer.ts +0 -222
  347. package/src/rendering/renderers/CanvasRenderer.ts +0 -296
  348. package/src/rendering/renderers/DummyRenderer.test.ts +0 -42
  349. package/src/rendering/renderers/DummyRenderer.ts +0 -136
  350. package/src/rendering/renderers/SVGRenderer.ts +0 -354
  351. package/src/rendering/renderers/TextOnlyRenderer.ts +0 -70
  352. package/src/styles.js +0 -7
  353. package/src/testing/beforeEachFile.ts +0 -8
  354. package/src/testing/createEditor.ts +0 -11
  355. package/src/testing/global.d.ts +0 -17
  356. package/src/testing/lib.ts +0 -3
  357. package/src/testing/loadExpectExtensions.ts +0 -25
  358. package/src/testing/sendPenEvent.ts +0 -31
  359. package/src/testing/sendTouchEvent.ts +0 -78
  360. package/src/toolbar/HTMLToolbar.ts +0 -492
  361. package/src/toolbar/IconProvider.ts +0 -736
  362. package/src/toolbar/lib.ts +0 -4
  363. package/src/toolbar/localization.ts +0 -106
  364. package/src/toolbar/makeColorInput.ts +0 -145
  365. package/src/toolbar/toolbar.css +0 -213
  366. package/src/toolbar/types.ts +0 -5
  367. package/src/toolbar/widgets/ActionButtonWidget.ts +0 -39
  368. package/src/toolbar/widgets/BaseToolWidget.ts +0 -56
  369. package/src/toolbar/widgets/BaseWidget.ts +0 -377
  370. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +0 -167
  371. package/src/toolbar/widgets/EraserToolWidget.ts +0 -85
  372. package/src/toolbar/widgets/HandToolWidget.ts +0 -250
  373. package/src/toolbar/widgets/InsertImageWidget.css +0 -44
  374. package/src/toolbar/widgets/InsertImageWidget.ts +0 -223
  375. package/src/toolbar/widgets/OverflowWidget.css +0 -27
  376. package/src/toolbar/widgets/OverflowWidget.ts +0 -92
  377. package/src/toolbar/widgets/PenToolWidget.ts +0 -288
  378. package/src/toolbar/widgets/SelectionToolWidget.ts +0 -190
  379. package/src/toolbar/widgets/TextToolWidget.ts +0 -145
  380. package/src/toolbar/widgets/lib.ts +0 -13
  381. package/src/tools/BaseTool.ts +0 -76
  382. package/src/tools/Eraser.test.ts +0 -103
  383. package/src/tools/Eraser.ts +0 -139
  384. package/src/tools/FindTool.css +0 -7
  385. package/src/tools/FindTool.ts +0 -152
  386. package/src/tools/PanZoom.test.ts +0 -310
  387. package/src/tools/PanZoom.ts +0 -520
  388. package/src/tools/PasteHandler.ts +0 -95
  389. package/src/tools/Pen.test.ts +0 -194
  390. package/src/tools/Pen.ts +0 -226
  391. package/src/tools/PipetteTool.ts +0 -55
  392. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +0 -28
  393. package/src/tools/SelectionTool/Selection.ts +0 -607
  394. package/src/tools/SelectionTool/SelectionHandle.ts +0 -108
  395. package/src/tools/SelectionTool/SelectionTool.css +0 -23
  396. package/src/tools/SelectionTool/SelectionTool.test.ts +0 -261
  397. package/src/tools/SelectionTool/SelectionTool.ts +0 -480
  398. package/src/tools/SelectionTool/TransformMode.ts +0 -114
  399. package/src/tools/SelectionTool/types.ts +0 -11
  400. package/src/tools/TextTool.ts +0 -326
  401. package/src/tools/ToolController.ts +0 -178
  402. package/src/tools/ToolEnabledGroup.ts +0 -14
  403. package/src/tools/ToolSwitcherShortcut.ts +0 -39
  404. package/src/tools/ToolbarShortcutHandler.ts +0 -34
  405. package/src/tools/UndoRedoShortcut.test.ts +0 -56
  406. package/src/tools/UndoRedoShortcut.ts +0 -25
  407. package/src/tools/lib.ts +0 -21
  408. package/src/tools/localization.ts +0 -66
  409. package/src/types.ts +0 -234
  410. package/src/util/assertions.ts +0 -55
  411. package/src/util/fileToBase64.ts +0 -18
  412. package/src/util/untilNextAnimationFrame.ts +0 -9
  413. package/src/util/waitForTimeout.ts +0 -9
@@ -1,120 +0,0 @@
1
- import EditorImage from './EditorImage';
2
- import Stroke from './components/Stroke';
3
- import { Vec2 } from './math/Vec2';
4
- import Path, { PathCommandType } from './math/Path';
5
- import Color4 from './Color4';
6
- import DummyRenderer from './rendering/renderers/DummyRenderer';
7
- import createEditor from './testing/createEditor';
8
- import RenderingStyle from './rendering/RenderingStyle';
9
- import Rect2 from './math/Rect2';
10
- import Mat33 from './math/Mat33';
11
- import { SerializableCommand } from './lib';
12
-
13
- describe('EditorImage', () => {
14
- const testStroke = new Stroke([
15
- {
16
- startPoint: Vec2.of(0, 0),
17
- commands: [
18
- {
19
- kind: PathCommandType.MoveTo,
20
- point: Vec2.of(3, 3),
21
- },
22
- ],
23
- style: {
24
- fill: Color4.red,
25
- },
26
- },
27
- ]);
28
- const testFill: RenderingStyle = { fill: Color4.black };
29
- const addTestStrokeCommand = EditorImage.addElement(testStroke);
30
-
31
- it('elements added to the image should be findable', () => {
32
- const editor = createEditor();
33
- const image = editor.image;
34
-
35
- // We haven't activated the command, so testStroke's parent should be null.
36
- expect(image.findParent(testStroke)).toBeNull();
37
- addTestStrokeCommand.apply(editor);
38
- expect(image.findParent(testStroke)).not.toBeNull();
39
- });
40
-
41
- it('should render an element added to the image', () => {
42
- const editor = createEditor();
43
- const renderer = editor.display.getDryInkRenderer();
44
- if (!(renderer instanceof DummyRenderer)) {
45
- throw new Error('Wrong display type!');
46
- }
47
-
48
- const emptyDocumentPathCount = renderer.renderedPathCount;
49
- expect(renderer.objectNestingLevel).toBe(0);
50
- editor.dispatch(addTestStrokeCommand);
51
- editor.rerender();
52
- expect(renderer.renderedPathCount - emptyDocumentPathCount).toBeGreaterThanOrEqual(1);
53
-
54
- // Should not be within objects after finished rendering
55
- expect(renderer.objectNestingLevel).toBe(0);
56
- });
57
-
58
- it('should have a 1-deep tree if two non-overlapping strokes are added', () => {
59
- const editor = createEditor();
60
- const image = editor.image;
61
-
62
- const leftmostStroke = new Stroke([
63
- Path.fromString('M0,0L1,1L0,1').toRenderable(testFill),
64
- ]);
65
-
66
- // Lowercase ls: lineTo(Δx, Δy) instead of lineTo(x, y)
67
- const rightmostStroke = new Stroke([
68
- Path.fromString('M-10,0 l1,1 l0,-1').toRenderable(testFill),
69
- ]);
70
-
71
- expect(!leftmostStroke.getBBox().intersects(rightmostStroke.getBBox()));
72
-
73
- (EditorImage.addElement(leftmostStroke)).apply(editor);
74
-
75
- // The first node should be at the image's root.
76
- let firstParent = image.findParent(leftmostStroke);
77
- expect(firstParent).not.toBe(null);
78
- expect(firstParent?.getParent()).toBe(null);
79
- expect(firstParent?.getBBox()?.corners).toMatchObject(leftmostStroke.getBBox()?.corners);
80
-
81
- (EditorImage.addElement(rightmostStroke)).apply(editor);
82
-
83
- firstParent = image.findParent(leftmostStroke);
84
- const secondParent = image.findParent(rightmostStroke);
85
-
86
- expect(firstParent).not.toStrictEqual(secondParent);
87
- expect(firstParent?.getParent()).toStrictEqual(secondParent?.getParent());
88
- expect(firstParent?.getParent()?.getParent()).toBeNull();
89
- });
90
-
91
- it('setImportExportRect should return a serializable command', () => {
92
- const editor = createEditor();
93
- const image = editor.image;
94
-
95
- const originalRect = editor.getImportExportRect();
96
- const newRect = new Rect2(3, 4, 5, 6);
97
- const command = image.setImportExportRect(newRect);
98
- expect(command.serialize().data).toMatchObject({
99
- originalSize: originalRect.size.xy,
100
- originalTransform: Mat33.identity.toArray(),
101
- newRegion: {
102
- x: 3,
103
- y: 4,
104
- w: 5,
105
- h: 6,
106
- },
107
- });
108
-
109
- expect(editor.getImportExportRect()).objEq(originalRect);
110
- command.apply(editor);
111
- expect(editor.getImportExportRect()).objEq(newRect);
112
-
113
- const deserializedCommand = SerializableCommand.deserialize(command.serialize(), editor);
114
-
115
- deserializedCommand.unapply(editor);
116
- expect(editor.getImportExportRect()).objEq(originalRect);
117
- deserializedCommand.apply(editor);
118
- expect(editor.getImportExportRect()).objEq(newRect);
119
- });
120
- });
@@ -1,603 +0,0 @@
1
- import Editor from './Editor';
2
- import AbstractRenderer from './rendering/renderers/AbstractRenderer';
3
- import Viewport from './Viewport';
4
- import AbstractComponent from './components/AbstractComponent';
5
- import Rect2 from './math/Rect2';
6
- import { EditorLocalization } from './localization';
7
- import RenderingCache from './rendering/caching/RenderingCache';
8
- import SerializableCommand from './commands/SerializableCommand';
9
- import EventDispatcher from './EventDispatcher';
10
- import { Vec2 } from './math/Vec2';
11
- import Mat33, { Mat33Array } from './math/Mat33';
12
- import { assertIsNumber, assertIsNumberArray } from './util/assertions';
13
-
14
- // @internal Sort by z-index, low to high
15
- export const sortLeavesByZIndex = (leaves: Array<ImageNode>) => {
16
- leaves.sort((a, b) => a.getContent()!.getZIndex() - b.getContent()!.getZIndex());
17
- };
18
-
19
- export enum EditorImageEventType {
20
- ExportViewportChanged
21
- }
22
-
23
- export type EditorImageNotifier = EventDispatcher<EditorImageEventType, { image: EditorImage }>;
24
-
25
- // Handles lookup/storage of elements in the image
26
- export default class EditorImage {
27
- private root: ImageNode;
28
- private background: ImageNode;
29
- private componentsById: Record<string, AbstractComponent>;
30
-
31
- /** Viewport for the exported/imported image. */
32
- private importExportViewport: Viewport;
33
-
34
- // @internal
35
- public readonly notifier: EditorImageNotifier;
36
-
37
- // @internal
38
- public constructor() {
39
- this.root = new ImageNode();
40
- this.background = new ImageNode();
41
- this.componentsById = {};
42
-
43
- this.notifier = new EventDispatcher();
44
- this.importExportViewport = new Viewport(() => {
45
- this.notifier.dispatch(EditorImageEventType.ExportViewportChanged, {
46
- image: this,
47
- });
48
- });
49
-
50
- // Default to a 500x500 image
51
- this.importExportViewport.updateScreenSize(Vec2.of(500, 500));
52
- }
53
-
54
- // Returns all components that make up the background of this image. These
55
- // components are rendered below all other components.
56
- public getBackgroundComponents(): AbstractComponent[] {
57
- const result = [];
58
-
59
- const leaves = this.background.getLeaves();
60
- sortLeavesByZIndex(leaves);
61
-
62
- for (const leaf of leaves) {
63
- const content = leaf.getContent();
64
-
65
- if (content) {
66
- result.push(content);
67
- }
68
- }
69
- return result;
70
- }
71
-
72
- // Returns the parent of the given element, if it exists.
73
- public findParent(elem: AbstractComponent): ImageNode|null {
74
- return this.background.getChildWithContent(elem) ?? this.root.getChildWithContent(elem);
75
- }
76
-
77
- // Forces a re-render of `elem` when the image is next re-rendered as a whole.
78
- // Does nothing if `elem` is not in this.
79
- public queueRerenderOf(elem: AbstractComponent) {
80
- // TODO: Make more efficient (e.g. increase IDs of all parents,
81
- // make cache take into account last modified time instead of IDs, etc.)
82
- const parent = this.findParent(elem);
83
-
84
- if (parent) {
85
- parent.remove();
86
- this.addElementDirectly(elem);
87
- }
88
- }
89
-
90
- /** @internal */
91
- public renderWithCache(screenRenderer: AbstractRenderer, cache: RenderingCache, viewport: Viewport) {
92
- this.background.render(screenRenderer, viewport.visibleRect);
93
- cache.render(screenRenderer, this.root, viewport);
94
- }
95
-
96
- /**
97
- * Renders all nodes visible from `viewport` (or all nodes if `viewport = null`).
98
- *
99
- * `viewport` is used to improve rendering performance. If given, it must match
100
- * the viewport used by the `renderer` (if any).
101
- */
102
- public render(renderer: AbstractRenderer, viewport: Viewport|null) {
103
- this.background.render(renderer, viewport?.visibleRect);
104
- this.root.render(renderer, viewport?.visibleRect);
105
- }
106
-
107
- /** Renders all nodes, even ones not within the viewport. @internal */
108
- public renderAll(renderer: AbstractRenderer) {
109
- this.render(renderer, null);
110
- }
111
-
112
- /** @returns all elements in the image, sorted by z-index. This can be slow for large images. */
113
- public getAllElements() {
114
- const leaves = this.root.getLeaves();
115
- sortLeavesByZIndex(leaves);
116
-
117
- return leaves.map(leaf => leaf.getContent()!);
118
- }
119
-
120
- /** @returns a list of `AbstractComponent`s intersecting `region`, sorted by z-index. */
121
- public getElementsIntersectingRegion(region: Rect2): AbstractComponent[] {
122
- const leaves = this.root.getLeavesIntersectingRegion(region);
123
- sortLeavesByZIndex(leaves);
124
-
125
- return leaves.map(leaf => leaf.getContent()!);
126
- }
127
-
128
- /** @internal */
129
- public onDestroyElement(elem: AbstractComponent) {
130
- delete this.componentsById[elem.getId()];
131
- }
132
-
133
- /**
134
- * @returns the AbstractComponent with `id`, if it exists.
135
- *
136
- * @see {@link AbstractComponent.getId}
137
- */
138
- public lookupElement(id: string): AbstractComponent|null {
139
- return this.componentsById[id] ?? null;
140
- }
141
-
142
- private addElementDirectly(elem: AbstractComponent): ImageNode {
143
- elem.onAddToImage(this);
144
-
145
- this.componentsById[elem.getId()] = elem;
146
-
147
- // If a background component, add to the background. Else,
148
- // add to the normal component tree.
149
- const parentTree = elem.isBackground() ? this.background : this.root;
150
- return parentTree.addLeaf(elem);
151
- }
152
-
153
- private removeElementDirectly(element: AbstractComponent) {
154
- const container = this.findParent(element);
155
- container?.remove();
156
-
157
- if (container) {
158
- this.onDestroyElement(element);
159
- return true;
160
- }
161
-
162
- return false;
163
- }
164
-
165
- /**
166
- * Returns a command that adds the given element to the `EditorImage`.
167
- * If `applyByFlattening` is true, the content of the wet ink renderer is
168
- * rendered onto the main rendering canvas instead of doing a full re-render.
169
- *
170
- * @see {@link Display.flatten}
171
- */
172
- public static addElement(elem: AbstractComponent, applyByFlattening: boolean = false): SerializableCommand {
173
- return new EditorImage.AddElementCommand(elem, applyByFlattening);
174
- }
175
-
176
- /** @see EditorImage.addElement */
177
- public addElement(elem: AbstractComponent, applyByFlattening?: boolean) {
178
- return EditorImage.addElement(elem, applyByFlattening);
179
- }
180
-
181
- // A Command that can access private [EditorImage] functionality
182
- private static AddElementCommand = class extends SerializableCommand {
183
- private serializedElem: any|null = null;
184
-
185
- // If [applyByFlattening], then the rendered content of this element
186
- // is present on the display's wet ink canvas. As such, no re-render is necessary
187
- // the first time this command is applied (the surfaces are joined instead).
188
- public constructor(
189
- private element: AbstractComponent,
190
- private applyByFlattening: boolean = false
191
- ) {
192
- super('add-element');
193
-
194
- // FIXME: The serialized version of this command may be inaccurate if this is
195
- // serialized when this command is not on the top of the undo stack.
196
- //
197
- // Caching the element's serialized data leads to additional memory usage *and*
198
- // sometimes incorrect behavior in collaborative editing.
199
- this.serializedElem = null;
200
-
201
- if (isNaN(element.getBBox().area)) {
202
- throw new Error('Elements in the image cannot have NaN bounding boxes');
203
- }
204
- }
205
-
206
- public apply(editor: Editor) {
207
- editor.image.addElementDirectly(this.element);
208
-
209
- if (!this.applyByFlattening) {
210
- editor.queueRerender();
211
- } else {
212
- this.applyByFlattening = false;
213
- editor.display.flatten();
214
- }
215
- }
216
-
217
- public unapply(editor: Editor) {
218
- editor.image.removeElementDirectly(this.element);
219
- editor.queueRerender();
220
- }
221
-
222
- public description(_editor: Editor, localization: EditorLocalization) {
223
- return localization.addElementAction(this.element.description(localization));
224
- }
225
-
226
- protected serializeToJSON() {
227
- return {
228
- elemData: this.serializedElem ?? this.element.serialize(),
229
- };
230
- }
231
-
232
- static {
233
- SerializableCommand.register('add-element', (json: any, editor: Editor) => {
234
- const id = json.elemData.id;
235
- const foundElem = editor.image.lookupElement(id);
236
- const elem = foundElem ?? AbstractComponent.deserialize(json.elemData);
237
- const result = new EditorImage.AddElementCommand(elem);
238
- result.serializedElem = json.elemData;
239
- return result;
240
- });
241
- }
242
- };
243
-
244
-
245
-
246
- /**
247
- * @returns a `Viewport` for rendering the image when importing/exporting.
248
- */
249
- public getImportExportViewport() {
250
- return this.importExportViewport;
251
- }
252
-
253
- public setImportExportRect(imageRect: Rect2): SerializableCommand {
254
- const importExportViewport = this.getImportExportViewport();
255
- const origSize = importExportViewport.visibleRect.size;
256
- const origTransform = importExportViewport.canvasToScreenTransform;
257
-
258
- return new EditorImage.SetImportExportRectCommand(origSize, origTransform, imageRect);
259
- }
260
-
261
- // Handles resizing the background import/export region of the image.
262
- private static SetImportExportRectCommand = class extends SerializableCommand {
263
- private static commandId = 'set-import-export-rect';
264
-
265
- public constructor(
266
- private originalSize: Vec2,
267
- private originalTransform: Mat33,
268
- private finalRect: Rect2,
269
- ) {
270
- super(EditorImage.SetImportExportRectCommand.commandId);
271
- }
272
-
273
- public apply(editor: Editor) {
274
- const viewport = editor.image.getImportExportViewport();
275
- viewport.updateScreenSize(this.finalRect.size);
276
- viewport.resetTransform(Mat33.translation(this.finalRect.topLeft.times(-1)));
277
- editor.queueRerender();
278
- }
279
-
280
- public unapply(editor: Editor) {
281
- const viewport = editor.image.getImportExportViewport();
282
- viewport.updateScreenSize(this.originalSize);
283
- viewport.resetTransform(this.originalTransform);
284
- editor.queueRerender();
285
- }
286
-
287
- public description(_editor: Editor, localization: EditorLocalization) {
288
- return localization.resizeOutputCommand(this.finalRect);
289
- }
290
-
291
- protected serializeToJSON() {
292
- return {
293
- originalSize: this.originalSize.xy,
294
- originalTransform: this.originalTransform.toArray(),
295
- newRegion: {
296
- x: this.finalRect.x,
297
- y: this.finalRect.y,
298
- w: this.finalRect.w,
299
- h: this.finalRect.h,
300
- },
301
- };
302
- }
303
-
304
- static {
305
- const commandId = this.commandId;
306
- SerializableCommand.register(commandId, (json: any, _editor: Editor) => {
307
- assertIsNumber(json.originalSize.x);
308
- assertIsNumber(json.originalSize.y);
309
- assertIsNumberArray(json.originalTransform);
310
- assertIsNumberArray([
311
- json.newRegion.x,
312
- json.newRegion.y,
313
- json.newRegion.w,
314
- json.newRegion.h,
315
- ]);
316
-
317
- const originalSize = Vec2.ofXY(json.originalSize);
318
- const originalTransform = new Mat33(...(json.originalTransform as Mat33Array));
319
- const finalRect = new Rect2(
320
- json.newRegion.x, json.newRegion.y, json.newRegion.w, json.newRegion.h
321
- );
322
- return new EditorImage.SetImportExportRectCommand(
323
- originalSize, originalTransform, finalRect
324
- );
325
- });
326
- }
327
- };
328
- }
329
-
330
- type TooSmallToRenderCheck = (rect: Rect2)=> boolean;
331
-
332
- /** Part of the Editor's image. @internal */
333
- export class ImageNode {
334
- private content: AbstractComponent|null;
335
- private bbox: Rect2;
336
- private children: ImageNode[];
337
- private targetChildCount: number = 30;
338
-
339
- private id: number;
340
- private static idCounter: number = 0;
341
-
342
- public constructor(
343
- private parent: ImageNode|null = null
344
- ) {
345
- this.children = [];
346
- this.bbox = Rect2.empty;
347
- this.content = null;
348
-
349
- this.id = ImageNode.idCounter++;
350
- }
351
-
352
- public getId() {
353
- return this.id;
354
- }
355
-
356
- public onContentChange() {
357
- this.id = ImageNode.idCounter++;
358
- }
359
-
360
- public getContent(): AbstractComponent|null {
361
- return this.content;
362
- }
363
-
364
- public getParent(): ImageNode|null {
365
- return this.parent;
366
- }
367
-
368
- private getChildrenIntersectingRegion(region: Rect2): ImageNode[] {
369
- return this.children.filter(child => {
370
- return child.getBBox().intersects(region);
371
- });
372
- }
373
-
374
- public getChildrenOrSelfIntersectingRegion(region: Rect2): ImageNode[] {
375
- if (this.content) {
376
- return [this];
377
- }
378
- return this.getChildrenIntersectingRegion(region);
379
- }
380
-
381
- // Returns a list of `ImageNode`s with content (and thus no children).
382
- public getLeavesIntersectingRegion(region: Rect2, isTooSmall?: TooSmallToRenderCheck): ImageNode[] {
383
- const result: ImageNode[] = [];
384
- let current: ImageNode|undefined;
385
- const workList: ImageNode[] = [];
386
-
387
- workList.push(this);
388
- const toNext = () => {
389
- current = undefined;
390
-
391
- const next = workList.pop();
392
- if (next && !isTooSmall?.(next.bbox)) {
393
- current = next;
394
-
395
- if (current.content !== null && current.getBBox().intersection(region)) {
396
- result.push(current);
397
- }
398
-
399
- workList.push(
400
- ...current.getChildrenIntersectingRegion(region)
401
- );
402
- }
403
- };
404
-
405
- while (workList.length > 0) {
406
- toNext();
407
- }
408
-
409
- return result;
410
- }
411
-
412
- // Returns the child of this with the target content or `null` if no
413
- // such child exists.
414
- public getChildWithContent(target: AbstractComponent): ImageNode|null {
415
- const candidates = this.getLeavesIntersectingRegion(target.getBBox());
416
- for (const candidate of candidates) {
417
- if (candidate.getContent() === target) {
418
- return candidate;
419
- }
420
- }
421
-
422
- return null;
423
- }
424
-
425
- // Returns a list of leaves with this as an ancestor.
426
- // Like getLeavesInRegion, but does not check whether ancestors are in a given rectangle
427
- public getLeaves(): ImageNode[] {
428
- if (this.content) {
429
- return [this];
430
- }
431
-
432
- const result: ImageNode[] = [];
433
- for (const child of this.children) {
434
- result.push(...child.getLeaves());
435
- }
436
-
437
- return result;
438
- }
439
-
440
- public addLeaf(leaf: AbstractComponent): ImageNode {
441
- this.onContentChange();
442
-
443
- if (this.content === null && this.children.length === 0) {
444
- this.content = leaf;
445
- this.recomputeBBox(true);
446
-
447
- return this;
448
- }
449
-
450
- if (this.content !== null) {
451
- console.assert(this.children.length === 0);
452
-
453
- const contentNode = new ImageNode(this);
454
- contentNode.content = this.content;
455
- this.content = null;
456
- this.children.push(contentNode);
457
- contentNode.recomputeBBox(false);
458
- }
459
-
460
- // If this node is contained within the leaf, make this and the leaf
461
- // share a parent.
462
- const leafBBox = leaf.getBBox();
463
- if (leafBBox.containsRect(this.getBBox())) {
464
- const nodeForNewLeaf = new ImageNode(this);
465
-
466
- if (this.children.length < this.targetChildCount) {
467
- this.children.push(nodeForNewLeaf);
468
- } else {
469
- const nodeForChildren = new ImageNode(this);
470
-
471
- nodeForChildren.children = this.children;
472
- this.children = [nodeForNewLeaf, nodeForChildren];
473
- nodeForChildren.recomputeBBox(true);
474
- nodeForChildren.updateParents();
475
- }
476
- return nodeForNewLeaf.addLeaf(leaf);
477
- }
478
-
479
- const containingNodes = this.children.filter(
480
- child => child.getBBox().containsRect(leafBBox)
481
- );
482
-
483
- // Does the leaf already fit within one of the children?
484
- if (containingNodes.length > 0 && this.children.length >= this.targetChildCount) {
485
- // Sort the containers in ascending order by area
486
- containingNodes.sort((a, b) => a.getBBox().area - b.getBBox().area);
487
-
488
- // Choose the smallest child that contains the new element.
489
- const result = containingNodes[0].addLeaf(leaf);
490
- result.rebalance();
491
- return result;
492
- }
493
-
494
-
495
- const newNode = new ImageNode(this);
496
- this.children.push(newNode);
497
- newNode.content = leaf;
498
- newNode.recomputeBBox(true);
499
-
500
- return newNode;
501
- }
502
-
503
- public getBBox(): Rect2 {
504
- return this.bbox;
505
- }
506
-
507
- // Recomputes this' bounding box. If [bubbleUp], also recompute
508
- // this' ancestors bounding boxes. This also re-computes this' bounding box
509
- // in the z-direction (z-indicies).
510
- public recomputeBBox(bubbleUp: boolean) {
511
- const oldBBox = this.bbox;
512
- if (this.content !== null) {
513
- this.bbox = this.content.getBBox();
514
- } else {
515
- this.bbox = Rect2.union(...this.children.map(child => child.getBBox()));
516
- }
517
-
518
- if (bubbleUp && !oldBBox.eq(this.bbox)) {
519
- this.parent?.recomputeBBox(true);
520
- }
521
- }
522
-
523
- private updateParents(recursive: boolean = false) {
524
- for (const child of this.children) {
525
- child.parent = this;
526
-
527
- if (recursive) {
528
- child.updateParents(recursive);
529
- }
530
- }
531
- }
532
-
533
- private rebalance() {
534
- // If the current node is its parent's only child,
535
- if (this.parent && this.parent.children.length === 1) {
536
- console.assert(this.parent.content === null);
537
- console.assert(this.parent.children[0] === this);
538
-
539
- // Remove this' parent, if this' parent isn't the root.
540
- const oldParent = this.parent;
541
- if (oldParent.parent !== null) {
542
- oldParent.children = [];
543
- this.parent = oldParent.parent;
544
- this.parent.children.push(this);
545
- oldParent.parent = null;
546
- this.parent.recomputeBBox(false);
547
- } else if (this.content === null) {
548
- // Remove this and transfer this' children to the parent.
549
- this.parent.children = this.children;
550
- this.parent.updateParents();
551
- this.parent = null;
552
- }
553
- }
554
- }
555
-
556
- // Remove this node and all of its children
557
- public remove() {
558
- this.content?.onRemoveFromImage();
559
-
560
- if (!this.parent) {
561
- this.content = null;
562
- this.children = [];
563
-
564
- return;
565
- }
566
-
567
- const oldChildCount = this.parent.children.length;
568
- this.parent.children = this.parent.children.filter(node => {
569
- return node !== this;
570
- });
571
-
572
- console.assert(
573
- this.parent.children.length === oldChildCount - 1,
574
- `${oldChildCount - 1} ≠ ${this.parent.children.length} after removing all nodes equal to ${this}. Nodes should only be removed once.`
575
- );
576
-
577
- this.parent.children.forEach(child => {
578
- child.rebalance();
579
- });
580
-
581
- this.parent.recomputeBBox(true);
582
-
583
- // Invalidate/disconnect this.
584
- this.content = null;
585
- this.parent = null;
586
- this.children = [];
587
- }
588
-
589
- public render(renderer: AbstractRenderer, visibleRect?: Rect2) {
590
- let leaves;
591
- if (visibleRect) {
592
- leaves = this.getLeavesIntersectingRegion(visibleRect, rect => renderer.isTooSmallToRender(rect));
593
- } else {
594
- leaves = this.getLeaves();
595
- }
596
- sortLeavesByZIndex(leaves);
597
-
598
- for (const leaf of leaves) {
599
- // Leaves by definition have content
600
- leaf.getContent()!.render(renderer, visibleRect);
601
- }
602
- }
603
- }