js-draw 1.21.3 → 1.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (331) hide show
  1. package/README.md +104 -76
  2. package/build-config.json +2 -2
  3. package/dist/Editor.css +29 -16
  4. package/dist/bundle.js +2 -2
  5. package/dist/bundledStyles.js +1 -1
  6. package/dist/cjs/Editor.d.ts +1 -3
  7. package/dist/cjs/Editor.js +38 -26
  8. package/dist/cjs/EventDispatcher.js +1 -1
  9. package/dist/cjs/Pointer.js +3 -3
  10. package/dist/cjs/SVGLoader/SVGLoader.js +15 -6
  11. package/dist/cjs/UndoRedoHistory.js +1 -1
  12. package/dist/cjs/Viewport.d.ts +1 -1
  13. package/dist/cjs/Viewport.js +5 -3
  14. package/dist/cjs/commands/Command.js +7 -5
  15. package/dist/cjs/commands/Duplicate.js +2 -2
  16. package/dist/cjs/commands/Erase.js +3 -4
  17. package/dist/cjs/commands/invertCommand.js +4 -4
  18. package/dist/cjs/commands/lib.d.ts +1 -1
  19. package/dist/cjs/commands/uniteCommands.js +4 -4
  20. package/dist/cjs/components/AbstractComponent.d.ts +2 -2
  21. package/dist/cjs/components/AbstractComponent.js +4 -4
  22. package/dist/cjs/components/BackgroundComponent.js +8 -6
  23. package/dist/cjs/components/ImageComponent.js +12 -5
  24. package/dist/cjs/components/RestylableComponent.js +1 -1
  25. package/dist/cjs/components/SVGGlobalAttributesObject.js +1 -2
  26. package/dist/cjs/components/Stroke.js +37 -24
  27. package/dist/cjs/components/TextComponent.js +13 -10
  28. package/dist/cjs/components/UnknownSVGObject.js +2 -3
  29. package/dist/cjs/components/builders/ArrowBuilder.d.ts +6 -0
  30. package/dist/cjs/components/builders/ArrowBuilder.js +9 -3
  31. package/dist/cjs/components/builders/CircleBuilder.d.ts +6 -0
  32. package/dist/cjs/components/builders/CircleBuilder.js +11 -4
  33. package/dist/cjs/components/builders/FreehandLineBuilder.d.ts +6 -0
  34. package/dist/cjs/components/builders/FreehandLineBuilder.js +10 -4
  35. package/dist/cjs/components/builders/LineBuilder.d.ts +6 -0
  36. package/dist/cjs/components/builders/LineBuilder.js +8 -4
  37. package/dist/cjs/components/builders/PolylineBuilder.d.ts +4 -1
  38. package/dist/cjs/components/builders/PolylineBuilder.js +9 -5
  39. package/dist/cjs/components/builders/PressureSensitiveFreehandLineBuilder.js +16 -10
  40. package/dist/cjs/components/builders/RectangleBuilder.d.ts +12 -0
  41. package/dist/cjs/components/builders/RectangleBuilder.js +17 -3
  42. package/dist/cjs/components/builders/autocorrect/makeShapeFitAutocorrect.js +5 -8
  43. package/dist/cjs/components/builders/autocorrect/makeSnapToGridAutocorrect.js +1 -1
  44. package/dist/cjs/components/builders/lib.d.ts +7 -0
  45. package/dist/cjs/components/builders/lib.js +18 -0
  46. package/dist/cjs/components/lib.d.ts +1 -4
  47. package/dist/cjs/components/lib.js +2 -9
  48. package/dist/cjs/components/util/StrokeSmoother.js +5 -6
  49. package/dist/cjs/dialogs/makeAboutDialog.js +1 -1
  50. package/dist/cjs/dialogs/makeMessageDialog.js +2 -2
  51. package/dist/cjs/image/EditorImage.d.ts +30 -7
  52. package/dist/cjs/image/EditorImage.js +43 -22
  53. package/dist/cjs/image/export/editorImageToSVG.js +1 -1
  54. package/dist/cjs/inputEvents.js +3 -3
  55. package/dist/cjs/lib.d.ts +2 -2
  56. package/dist/cjs/localizations/de.js +2 -2
  57. package/dist/cjs/localizations/es.js +7 -3
  58. package/dist/cjs/rendering/Display.js +7 -3
  59. package/dist/cjs/rendering/RenderablePathSpec.js +26 -11
  60. package/dist/cjs/rendering/RenderingStyle.js +22 -15
  61. package/dist/cjs/rendering/TextRenderingStyle.js +1 -1
  62. package/dist/cjs/rendering/caching/CacheRecord.js +1 -1
  63. package/dist/cjs/rendering/caching/CacheRecordManager.js +1 -1
  64. package/dist/cjs/rendering/caching/RenderingCache.js +1 -1
  65. package/dist/cjs/rendering/caching/RenderingCacheNode.js +26 -15
  66. package/dist/cjs/rendering/caching/testUtils.js +2 -2
  67. package/dist/cjs/rendering/renderers/AbstractRenderer.js +3 -1
  68. package/dist/cjs/rendering/renderers/CanvasRenderer.d.ts +2 -25
  69. package/dist/cjs/rendering/renderers/CanvasRenderer.js +6 -28
  70. package/dist/cjs/rendering/renderers/DummyRenderer.js +1 -1
  71. package/dist/cjs/rendering/renderers/SVGRenderer.js +39 -21
  72. package/dist/cjs/rendering/renderers/TextOnlyRenderer.js +13 -15
  73. package/dist/cjs/shortcuts/KeyBinding.js +6 -12
  74. package/dist/cjs/shortcuts/KeyboardShortcutManager.js +2 -2
  75. package/dist/cjs/testing/createEditor.js +6 -1
  76. package/dist/cjs/testing/findNodeWithText.d.ts +4 -1
  77. package/dist/cjs/testing/findNodeWithText.js +12 -3
  78. package/dist/cjs/testing/getUniquePointerId.js +1 -1
  79. package/dist/cjs/testing/sendHtmlSwipe.js +7 -3
  80. package/dist/cjs/testing/sendPenEvent.js +1 -3
  81. package/dist/cjs/testing/sendTouchEvent.js +1 -4
  82. package/dist/cjs/testing/startPinchGesture.js +3 -1
  83. package/dist/cjs/toolbar/AbstractToolbar.d.ts +19 -0
  84. package/dist/cjs/toolbar/AbstractToolbar.js +26 -11
  85. package/dist/cjs/toolbar/EdgeToolbar.js +11 -15
  86. package/dist/cjs/toolbar/IconProvider.d.ts +5 -1
  87. package/dist/cjs/toolbar/IconProvider.js +117 -149
  88. package/dist/cjs/toolbar/localization.js +5 -5
  89. package/dist/cjs/toolbar/utils/HelpDisplay.js +8 -6
  90. package/dist/cjs/toolbar/utils/makeDraggable.js +4 -7
  91. package/dist/cjs/toolbar/widgets/BaseToolWidget.js +3 -2
  92. package/dist/cjs/toolbar/widgets/BaseWidget.d.ts +1 -1
  93. package/dist/cjs/toolbar/widgets/BaseWidget.js +8 -8
  94. package/dist/cjs/toolbar/widgets/DocumentPropertiesWidget.js +2 -2
  95. package/dist/cjs/toolbar/widgets/EraserToolWidget.js +5 -3
  96. package/dist/cjs/toolbar/widgets/HandToolWidget.js +8 -6
  97. package/dist/cjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.js +9 -10
  98. package/dist/cjs/toolbar/widgets/PenToolWidget.js +22 -13
  99. package/dist/cjs/toolbar/widgets/SelectionToolWidget.js +2 -2
  100. package/dist/cjs/toolbar/widgets/TextToolWidget.js +5 -5
  101. package/dist/cjs/toolbar/widgets/components/makeFileInput.js +7 -7
  102. package/dist/cjs/toolbar/widgets/components/makeGridSelector.js +5 -5
  103. package/dist/cjs/toolbar/widgets/components/makeSnappedList.js +9 -5
  104. package/dist/cjs/toolbar/widgets/keybindings.js +2 -2
  105. package/dist/cjs/toolbar/widgets/layout/DropdownLayoutManager.js +6 -6
  106. package/dist/cjs/tools/BaseTool.js +5 -3
  107. package/dist/cjs/tools/Eraser.js +25 -20
  108. package/dist/cjs/tools/FindTool.js +2 -2
  109. package/dist/cjs/tools/InputFilter/ContextMenuRecognizer.js +1 -3
  110. package/dist/cjs/tools/InputFilter/InputMapper.js +1 -1
  111. package/dist/cjs/tools/InputFilter/InputPipeline.js +1 -1
  112. package/dist/cjs/tools/InputFilter/InputStabilizer.js +12 -5
  113. package/dist/cjs/tools/InputFilter/StrokeKeyboardControl.js +7 -4
  114. package/dist/cjs/tools/PanZoom.d.ts +1 -1
  115. package/dist/cjs/tools/PanZoom.js +18 -13
  116. package/dist/cjs/tools/PasteHandler.js +8 -2
  117. package/dist/cjs/tools/Pen.d.ts +13 -0
  118. package/dist/cjs/tools/Pen.js +30 -9
  119. package/dist/cjs/tools/ScrollbarTool.js +8 -7
  120. package/dist/cjs/tools/SelectionTool/Selection.js +16 -12
  121. package/dist/cjs/tools/SelectionTool/SelectionHandle.js +5 -2
  122. package/dist/cjs/tools/SelectionTool/SelectionMenuShortcut.js +3 -1
  123. package/dist/cjs/tools/SelectionTool/SelectionTool.js +25 -16
  124. package/dist/cjs/tools/SelectionTool/ToPointerAutoscroller.js +1 -1
  125. package/dist/cjs/tools/SelectionTool/TransformMode.js +6 -7
  126. package/dist/cjs/tools/SelectionTool/util/makeClipboardErrorHandlers.js +23 -2
  127. package/dist/cjs/tools/SelectionTool/util/showSelectionContextMenu.js +29 -20
  128. package/dist/cjs/tools/SoundUITool.js +5 -3
  129. package/dist/cjs/tools/TextTool.js +8 -6
  130. package/dist/cjs/tools/ToolController.js +16 -10
  131. package/dist/cjs/tools/lib.d.ts +1 -0
  132. package/dist/cjs/tools/lib.js +3 -1
  133. package/dist/cjs/tools/localization.d.ts +2 -0
  134. package/dist/cjs/tools/localization.js +3 -1
  135. package/dist/cjs/tools/util/StationaryPenDetector.js +3 -3
  136. package/dist/cjs/tools/util/createMenuOverlay.js +2 -2
  137. package/dist/cjs/util/ClipboardHandler.d.ts +1 -1
  138. package/dist/cjs/util/ClipboardHandler.js +19 -18
  139. package/dist/cjs/util/ReactiveValue.js +16 -12
  140. package/dist/cjs/util/adjustEditorThemeForContrast.js +6 -2
  141. package/dist/cjs/util/cloneElementWithStyles.js +1 -1
  142. package/dist/cjs/util/createElement.d.ts +62 -0
  143. package/dist/cjs/util/createElement.js +53 -0
  144. package/dist/cjs/util/guessKeyCodeFromKey.js +1 -1
  145. package/dist/cjs/util/listenForKeyboardEventsFrom.js +8 -6
  146. package/dist/cjs/util/waitForAll.js +3 -3
  147. package/dist/cjs/util/waitForImageLoaded.js +3 -3
  148. package/dist/cjs/util/waitForTimeout.js +1 -1
  149. package/dist/cjs/version.js +1 -1
  150. package/dist/mjs/Editor.d.ts +1 -3
  151. package/dist/mjs/Editor.mjs +39 -27
  152. package/dist/mjs/EventDispatcher.mjs +1 -1
  153. package/dist/mjs/Pointer.mjs +3 -3
  154. package/dist/mjs/SVGLoader/SVGLoader.mjs +16 -7
  155. package/dist/mjs/UndoRedoHistory.mjs +1 -1
  156. package/dist/mjs/Viewport.d.ts +1 -1
  157. package/dist/mjs/Viewport.mjs +5 -3
  158. package/dist/mjs/commands/Command.mjs +7 -5
  159. package/dist/mjs/commands/Duplicate.mjs +2 -2
  160. package/dist/mjs/commands/Erase.mjs +3 -4
  161. package/dist/mjs/commands/invertCommand.mjs +4 -4
  162. package/dist/mjs/commands/lib.d.ts +1 -1
  163. package/dist/mjs/commands/lib.mjs +1 -1
  164. package/dist/mjs/commands/uniteCommands.mjs +4 -4
  165. package/dist/mjs/components/AbstractComponent.d.ts +2 -2
  166. package/dist/mjs/components/AbstractComponent.mjs +4 -4
  167. package/dist/mjs/components/BackgroundComponent.mjs +10 -8
  168. package/dist/mjs/components/ImageComponent.mjs +12 -5
  169. package/dist/mjs/components/RestylableComponent.mjs +2 -2
  170. package/dist/mjs/components/SVGGlobalAttributesObject.mjs +1 -2
  171. package/dist/mjs/components/Stroke.mjs +40 -27
  172. package/dist/mjs/components/TextComponent.mjs +15 -12
  173. package/dist/mjs/components/UnknownSVGObject.mjs +2 -3
  174. package/dist/mjs/components/builders/ArrowBuilder.d.ts +6 -0
  175. package/dist/mjs/components/builders/ArrowBuilder.mjs +9 -3
  176. package/dist/mjs/components/builders/CircleBuilder.d.ts +6 -0
  177. package/dist/mjs/components/builders/CircleBuilder.mjs +11 -4
  178. package/dist/mjs/components/builders/FreehandLineBuilder.d.ts +6 -0
  179. package/dist/mjs/components/builders/FreehandLineBuilder.mjs +10 -4
  180. package/dist/mjs/components/builders/LineBuilder.d.ts +6 -0
  181. package/dist/mjs/components/builders/LineBuilder.mjs +8 -4
  182. package/dist/mjs/components/builders/PolylineBuilder.d.ts +4 -1
  183. package/dist/mjs/components/builders/PolylineBuilder.mjs +10 -6
  184. package/dist/mjs/components/builders/PressureSensitiveFreehandLineBuilder.mjs +17 -11
  185. package/dist/mjs/components/builders/RectangleBuilder.d.ts +12 -0
  186. package/dist/mjs/components/builders/RectangleBuilder.mjs +17 -3
  187. package/dist/mjs/components/builders/autocorrect/makeShapeFitAutocorrect.mjs +5 -8
  188. package/dist/mjs/components/builders/autocorrect/makeSnapToGridAutocorrect.mjs +1 -1
  189. package/dist/mjs/components/builders/lib.d.ts +7 -0
  190. package/dist/mjs/components/builders/lib.mjs +7 -0
  191. package/dist/mjs/components/lib.d.ts +1 -4
  192. package/dist/mjs/components/lib.mjs +2 -5
  193. package/dist/mjs/components/util/StrokeSmoother.mjs +5 -6
  194. package/dist/mjs/dialogs/makeAboutDialog.mjs +1 -1
  195. package/dist/mjs/dialogs/makeMessageDialog.mjs +2 -2
  196. package/dist/mjs/image/EditorImage.d.ts +30 -7
  197. package/dist/mjs/image/EditorImage.mjs +43 -22
  198. package/dist/mjs/image/export/editorImageToSVG.mjs +1 -1
  199. package/dist/mjs/inputEvents.mjs +3 -3
  200. package/dist/mjs/lib.d.ts +2 -2
  201. package/dist/mjs/lib.mjs +2 -2
  202. package/dist/mjs/localization.mjs +2 -2
  203. package/dist/mjs/localizations/de.mjs +2 -2
  204. package/dist/mjs/localizations/es.mjs +7 -3
  205. package/dist/mjs/rendering/Display.mjs +7 -3
  206. package/dist/mjs/rendering/RenderablePathSpec.mjs +26 -11
  207. package/dist/mjs/rendering/RenderingStyle.mjs +22 -15
  208. package/dist/mjs/rendering/TextRenderingStyle.mjs +1 -1
  209. package/dist/mjs/rendering/caching/CacheRecord.mjs +1 -1
  210. package/dist/mjs/rendering/caching/CacheRecordManager.mjs +1 -1
  211. package/dist/mjs/rendering/caching/RenderingCache.mjs +1 -1
  212. package/dist/mjs/rendering/caching/RenderingCacheNode.mjs +26 -15
  213. package/dist/mjs/rendering/caching/testUtils.mjs +2 -2
  214. package/dist/mjs/rendering/renderers/AbstractRenderer.mjs +3 -1
  215. package/dist/mjs/rendering/renderers/CanvasRenderer.d.ts +2 -25
  216. package/dist/mjs/rendering/renderers/CanvasRenderer.mjs +6 -28
  217. package/dist/mjs/rendering/renderers/DummyRenderer.mjs +1 -1
  218. package/dist/mjs/rendering/renderers/SVGRenderer.mjs +40 -22
  219. package/dist/mjs/rendering/renderers/TextOnlyRenderer.mjs +13 -15
  220. package/dist/mjs/shortcuts/KeyBinding.mjs +6 -12
  221. package/dist/mjs/shortcuts/KeyboardShortcutManager.mjs +2 -2
  222. package/dist/mjs/testing/createEditor.mjs +6 -1
  223. package/dist/mjs/testing/findNodeWithText.d.ts +4 -1
  224. package/dist/mjs/testing/findNodeWithText.mjs +12 -3
  225. package/dist/mjs/testing/getUniquePointerId.mjs +1 -1
  226. package/dist/mjs/testing/sendHtmlSwipe.mjs +7 -3
  227. package/dist/mjs/testing/sendPenEvent.mjs +1 -3
  228. package/dist/mjs/testing/sendTouchEvent.mjs +1 -4
  229. package/dist/mjs/testing/startPinchGesture.mjs +3 -1
  230. package/dist/mjs/toolbar/AbstractToolbar.d.ts +19 -0
  231. package/dist/mjs/toolbar/AbstractToolbar.mjs +26 -11
  232. package/dist/mjs/toolbar/EdgeToolbar.mjs +11 -15
  233. package/dist/mjs/toolbar/IconProvider.d.ts +5 -1
  234. package/dist/mjs/toolbar/IconProvider.mjs +117 -149
  235. package/dist/mjs/toolbar/localization.mjs +5 -5
  236. package/dist/mjs/toolbar/utils/HelpDisplay.mjs +8 -6
  237. package/dist/mjs/toolbar/utils/makeDraggable.mjs +4 -7
  238. package/dist/mjs/toolbar/widgets/BaseToolWidget.mjs +3 -2
  239. package/dist/mjs/toolbar/widgets/BaseWidget.d.ts +1 -1
  240. package/dist/mjs/toolbar/widgets/BaseWidget.mjs +9 -9
  241. package/dist/mjs/toolbar/widgets/DocumentPropertiesWidget.mjs +2 -2
  242. package/dist/mjs/toolbar/widgets/EraserToolWidget.mjs +5 -3
  243. package/dist/mjs/toolbar/widgets/HandToolWidget.mjs +8 -6
  244. package/dist/mjs/toolbar/widgets/InsertImageWidget/InsertImageWidget.mjs +9 -10
  245. package/dist/mjs/toolbar/widgets/PenToolWidget.mjs +23 -14
  246. package/dist/mjs/toolbar/widgets/SelectionToolWidget.mjs +2 -2
  247. package/dist/mjs/toolbar/widgets/TextToolWidget.mjs +5 -5
  248. package/dist/mjs/toolbar/widgets/components/makeFileInput.mjs +7 -7
  249. package/dist/mjs/toolbar/widgets/components/makeGridSelector.mjs +5 -5
  250. package/dist/mjs/toolbar/widgets/components/makeSnappedList.mjs +9 -5
  251. package/dist/mjs/toolbar/widgets/keybindings.mjs +2 -2
  252. package/dist/mjs/toolbar/widgets/layout/DropdownLayoutManager.mjs +6 -6
  253. package/dist/mjs/tools/BaseTool.mjs +6 -4
  254. package/dist/mjs/tools/Eraser.mjs +25 -20
  255. package/dist/mjs/tools/FindTool.mjs +2 -2
  256. package/dist/mjs/tools/InputFilter/ContextMenuRecognizer.mjs +2 -4
  257. package/dist/mjs/tools/InputFilter/InputMapper.mjs +1 -1
  258. package/dist/mjs/tools/InputFilter/InputPipeline.mjs +1 -1
  259. package/dist/mjs/tools/InputFilter/InputStabilizer.mjs +13 -6
  260. package/dist/mjs/tools/InputFilter/StrokeKeyboardControl.mjs +7 -4
  261. package/dist/mjs/tools/PanZoom.d.ts +1 -1
  262. package/dist/mjs/tools/PanZoom.mjs +19 -14
  263. package/dist/mjs/tools/PasteHandler.mjs +8 -2
  264. package/dist/mjs/tools/Pen.d.ts +13 -0
  265. package/dist/mjs/tools/Pen.mjs +31 -10
  266. package/dist/mjs/tools/ScrollbarTool.mjs +8 -7
  267. package/dist/mjs/tools/SelectionTool/Selection.mjs +16 -12
  268. package/dist/mjs/tools/SelectionTool/SelectionHandle.mjs +5 -2
  269. package/dist/mjs/tools/SelectionTool/SelectionMenuShortcut.mjs +3 -1
  270. package/dist/mjs/tools/SelectionTool/SelectionTool.mjs +26 -17
  271. package/dist/mjs/tools/SelectionTool/ToPointerAutoscroller.mjs +1 -1
  272. package/dist/mjs/tools/SelectionTool/TransformMode.mjs +6 -7
  273. package/dist/mjs/tools/SelectionTool/util/makeClipboardErrorHandlers.mjs +23 -2
  274. package/dist/mjs/tools/SelectionTool/util/showSelectionContextMenu.mjs +29 -20
  275. package/dist/mjs/tools/SoundUITool.mjs +5 -3
  276. package/dist/mjs/tools/TextTool.mjs +8 -6
  277. package/dist/mjs/tools/ToolController.mjs +16 -10
  278. package/dist/mjs/tools/lib.d.ts +1 -0
  279. package/dist/mjs/tools/lib.mjs +1 -0
  280. package/dist/mjs/tools/localization.d.ts +2 -0
  281. package/dist/mjs/tools/localization.mjs +3 -1
  282. package/dist/mjs/tools/util/StationaryPenDetector.mjs +3 -3
  283. package/dist/mjs/tools/util/createMenuOverlay.mjs +2 -2
  284. package/dist/mjs/util/ClipboardHandler.d.ts +1 -1
  285. package/dist/mjs/util/ClipboardHandler.mjs +19 -18
  286. package/dist/mjs/util/ReactiveValue.mjs +16 -12
  287. package/dist/mjs/util/adjustEditorThemeForContrast.mjs +6 -2
  288. package/dist/mjs/util/cloneElementWithStyles.mjs +1 -1
  289. package/dist/mjs/util/createElement.d.ts +62 -0
  290. package/dist/mjs/util/createElement.mjs +47 -0
  291. package/dist/mjs/util/guessKeyCodeFromKey.mjs +1 -1
  292. package/dist/mjs/util/listenForKeyboardEventsFrom.mjs +8 -6
  293. package/dist/mjs/util/waitForAll.mjs +3 -3
  294. package/dist/mjs/util/waitForImageLoaded.mjs +3 -3
  295. package/dist/mjs/util/waitForTimeout.mjs +1 -1
  296. package/dist/mjs/version.mjs +1 -1
  297. package/package.json +88 -88
  298. package/src/Coloris.css +6 -6
  299. package/src/Editor.scss +7 -5
  300. package/src/dialogs/dialogs.scss +3 -4
  301. package/src/dialogs/makeAboutDialog.scss +2 -2
  302. package/src/dialogs/makeMessageDialog.scss +11 -7
  303. package/src/styles.js +1 -1
  304. package/src/toolbar/AbstractToolbar.scss +20 -12
  305. package/src/toolbar/DropdownToolbar.scss +5 -4
  306. package/src/toolbar/EdgeToolbar.scss +65 -31
  307. package/src/toolbar/toolbar.scss +5 -5
  308. package/src/toolbar/utils/HelpDisplay.scss +48 -25
  309. package/src/toolbar/utils/labelVisibleOnHover.scss +39 -16
  310. package/src/toolbar/widgets/DocumentPropertiesWidget.scss +0 -1
  311. package/src/toolbar/widgets/HandToolWidget.scss +0 -1
  312. package/src/toolbar/widgets/InsertImageWidget/InsertImageWidget.scss +2 -3
  313. package/src/toolbar/widgets/OverflowWidget.css +1 -2
  314. package/src/toolbar/widgets/PenToolWidget.scss +0 -2
  315. package/src/toolbar/widgets/SelectionToolWidget.scss +1 -2
  316. package/src/toolbar/widgets/components/components.scss +6 -6
  317. package/src/toolbar/widgets/components/makeColorInput.scss +0 -2
  318. package/src/toolbar/widgets/components/makeFileInput.scss +5 -7
  319. package/src/toolbar/widgets/components/makeGridSelector.scss +6 -9
  320. package/src/toolbar/widgets/components/makeSnappedList.scss +3 -4
  321. package/src/toolbar/widgets/components/makeThicknessSlider.scss +1 -2
  322. package/src/toolbar/widgets/widgets.scss +7 -7
  323. package/src/tools/FindTool.css +1 -2
  324. package/src/tools/ScrollbarTool.scss +9 -5
  325. package/src/tools/SelectionTool/SelectionTool.scss +15 -7
  326. package/src/tools/SelectionTool/util/makeClipboardErrorHandlers.scss +1 -2
  327. package/src/tools/SoundUITool.scss +4 -4
  328. package/src/tools/tools.scss +5 -6
  329. package/src/tools/util/createMenuOverlay.scss +10 -4
  330. package/tsconfig.json +1 -3
  331. package/typedoc.json +1 -1
@@ -4,4 +4,4 @@ import Erase from './Erase.mjs';
4
4
  import invertCommand from './invertCommand.mjs';
5
5
  import SerializableCommand from './SerializableCommand.mjs';
6
6
  import uniteCommands from './uniteCommands.mjs';
7
- export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands, };
7
+ export { Command, Duplicate, Erase, SerializableCommand, invertCommand, uniteCommands };
@@ -10,7 +10,7 @@ class NonSerializableUnion extends Command {
10
10
  }
11
11
  apply(editor) {
12
12
  if (this.applyChunkSize === undefined) {
13
- const results = this.commands.map(cmd => cmd.apply(editor));
13
+ const results = this.commands.map((cmd) => cmd.apply(editor));
14
14
  return waitForAll(results);
15
15
  }
16
16
  else {
@@ -21,7 +21,7 @@ class NonSerializableUnion extends Command {
21
21
  const commands = [...this.commands];
22
22
  commands.reverse();
23
23
  if (this.applyChunkSize === undefined) {
24
- const results = commands.map(cmd => cmd.unapply(editor));
24
+ const results = commands.map((cmd) => cmd.unapply(editor));
25
25
  return waitForAll(results);
26
26
  }
27
27
  else {
@@ -29,7 +29,7 @@ class NonSerializableUnion extends Command {
29
29
  }
30
30
  }
31
31
  onDrop(editor) {
32
- this.commands.forEach(command => command.onDrop(editor));
32
+ this.commands.forEach((command) => command.onDrop(editor));
33
33
  }
34
34
  description(editor, localizationTable) {
35
35
  if (this.descriptionOverride) {
@@ -81,7 +81,7 @@ class SerializableUnion extends SerializableCommand {
81
81
  }
82
82
  return {
83
83
  applyChunkSize: this.applyChunkSize,
84
- data: this.commands.map(command => command.serialize()),
84
+ data: this.commands.map((command) => command.serialize()),
85
85
  description: this.descriptionOverride,
86
86
  };
87
87
  }
@@ -4,7 +4,7 @@ import { LineSegment2, Mat33, Path, Rect2 } from '@js-draw/math';
4
4
  import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
5
5
  import { ImageComponentLocalization } from './localization';
6
6
  import Viewport from '../Viewport';
7
- export type LoadSaveData = (string[] | Record<symbol, string | number>);
7
+ export type LoadSaveData = string[] | Record<symbol, string | number>;
8
8
  export type LoadSaveDataTable = Record<string, Array<LoadSaveData>>;
9
9
  export type DeserializeCallback = (data: string) => AbstractComponent;
10
10
  export declare enum ComponentSizingMode {
@@ -122,7 +122,7 @@ export default abstract class AbstractComponent {
122
122
  * updates the editor.
123
123
  *
124
124
  * The transformed component is also moved to the top (use
125
- * {@link AbstractComponent.setZIndexAndTransformBy} to avoid this behavior).
125
+ * {@link AbstractComponent#setZIndexAndTransformBy} to avoid this behavior).
126
126
  */
127
127
  transformBy(affineTransfm: Mat33): SerializableCommand;
128
128
  setZIndex(newZIndex: number): SerializableCommand;
@@ -36,7 +36,7 @@ class AbstractComponent {
36
36
  this.componentKind = componentKind;
37
37
  // Stores data attached by a loader.
38
38
  this.loadSaveData = {};
39
- this.lastChangedTime = (new Date()).getTime();
39
+ this.lastChangedTime = new Date().getTime();
40
40
  if (initialZIndex !== undefined) {
41
41
  this.zIndex = initialZIndex;
42
42
  }
@@ -134,7 +134,7 @@ class AbstractComponent {
134
134
  }
135
135
  // Otherwise check if it intersects one of the rectangle's edges.
136
136
  const testLines = rect.getEdges();
137
- return testLines.some(edge => this.intersects(edge));
137
+ return testLines.some((edge) => this.intersects(edge));
138
138
  }
139
139
  // @returns true iff this component can be selected (e.g. by the selection tool.)
140
140
  isSelectable() {
@@ -156,7 +156,7 @@ class AbstractComponent {
156
156
  * updates the editor.
157
157
  *
158
158
  * The transformed component is also moved to the top (use
159
- * {@link AbstractComponent.setZIndexAndTransformBy} to avoid this behavior).
159
+ * {@link AbstractComponent#setZIndexAndTransformBy} to avoid this behavior).
160
160
  */
161
161
  transformBy(affineTransfm) {
162
162
  return new AbstractComponent.TransformElementCommand(affineTransfm, this.getId(), this);
@@ -284,7 +284,7 @@ AbstractComponent.TransformElementCommand = (_a = class extends UnresolvedSerial
284
284
  }
285
285
  this.component.applyTransformation(newTransfm);
286
286
  this.component.zIndex = targetZIndex;
287
- this.component.lastChangedTime = (new Date()).getTime();
287
+ this.component.lastChangedTime = new Date().getTime();
288
288
  // Ensure that new components are automatically drawn above the current component.
289
289
  if (targetZIndex >= AbstractComponent.zIndexCounter) {
290
290
  AbstractComponent.zIndexCounter = targetZIndex + 1;
@@ -1,7 +1,7 @@
1
1
  import { EditorImageEventType } from '../image/EditorImage.mjs';
2
- import { Rect2, Color4, toRoundedString, Path, PathCommandType, Vec2 } from '@js-draw/math';
2
+ import { Rect2, Color4, toRoundedString, Path, PathCommandType, Vec2, } from '@js-draw/math';
3
3
  import AbstractComponent, { ComponentSizingMode } from './AbstractComponent.mjs';
4
- import { createRestyleComponentCommand } from './RestylableComponent.mjs';
4
+ import { createRestyleComponentCommand, } from './RestylableComponent.mjs';
5
5
  import Viewport from '../Viewport.mjs';
6
6
  import { pathToRenderable } from '../rendering/RenderablePathSpec.mjs';
7
7
  export var BackgroundType;
@@ -178,7 +178,7 @@ export default class BackgroundComponent extends AbstractComponent {
178
178
  });
179
179
  result.push({
180
180
  kind: PathCommandType.LineTo,
181
- point: Vec2.of(x, targetRect.y + targetRect.h)
181
+ point: Vec2.of(x, targetRect.y + targetRect.h),
182
182
  });
183
183
  }
184
184
  return new Path(startPoint, result);
@@ -206,7 +206,8 @@ export default class BackgroundComponent extends AbstractComponent {
206
206
  const clip = this.backgroundType === BackgroundType.Grid;
207
207
  const contentBBox = this.getFullBoundingBox(visibleRect);
208
208
  canvas.startObject(contentBBox, clip);
209
- if (this.backgroundType === BackgroundType.SolidColor || this.backgroundType === BackgroundType.Grid) {
209
+ if (this.backgroundType === BackgroundType.SolidColor ||
210
+ this.backgroundType === BackgroundType.Grid) {
210
211
  // If the rectangle for this region contains the visible rect,
211
212
  // we can fill the entire visible rectangle (which may be more efficient than
212
213
  // filling the entire region for this.)
@@ -228,7 +229,7 @@ export default class BackgroundComponent extends AbstractComponent {
228
229
  }
229
230
  const style = {
230
231
  fill: Color4.transparent,
231
- stroke: { width: this.gridStrokeWidth, color: gridColor }
232
+ stroke: { width: this.gridStrokeWidth, color: gridColor },
232
233
  };
233
234
  canvas.drawPath(pathToRenderable(this.generateGridPath(visibleRect), style));
234
235
  }
@@ -245,7 +246,7 @@ export default class BackgroundComponent extends AbstractComponent {
245
246
  canvas.endObject(this.getLoadSaveData(), classNames);
246
247
  }
247
248
  intersects(lineSegment) {
248
- return this.contentBBox.getEdges().some(edge => edge.intersects(lineSegment));
249
+ return this.contentBBox.getEdges().some((edge) => edge.intersects(lineSegment));
249
250
  }
250
251
  isSelectable() {
251
252
  return false;
@@ -296,8 +297,9 @@ export default class BackgroundComponent extends AbstractComponent {
296
297
  }
297
298
  let backgroundType;
298
299
  const jsonBackgroundType = json.backgroundType;
299
- if (jsonBackgroundType === BackgroundType.None || jsonBackgroundType === BackgroundType.Grid
300
- || jsonBackgroundType === BackgroundType.SolidColor) {
300
+ if (jsonBackgroundType === BackgroundType.None ||
301
+ jsonBackgroundType === BackgroundType.Grid ||
302
+ jsonBackgroundType === BackgroundType.SolidColor) {
301
303
  backgroundType = jsonBackgroundType;
302
304
  }
303
305
  else {
@@ -13,7 +13,10 @@ export default class ImageComponent extends AbstractComponent {
13
13
  super('image-component');
14
14
  this.image = {
15
15
  ...image,
16
- label: image.label ?? image.image.getAttribute('alt') ?? image.image.getAttribute('aria-label') ?? undefined,
16
+ label: image.label ??
17
+ image.image.getAttribute('alt') ??
18
+ image.image.getAttribute('aria-label') ??
19
+ undefined,
17
20
  };
18
21
  const isHTMLImageElem = (elem) => {
19
22
  return elem.getAttribute('src') !== undefined;
@@ -39,8 +42,10 @@ export default class ImageComponent extends AbstractComponent {
39
42
  static async fromImage(elem, transform) {
40
43
  await waitForImageLoaded(elem);
41
44
  let width, height;
42
- if (typeof elem.width === 'number' && typeof elem.height === 'number'
43
- && elem.width !== 0 && elem.height !== 0) {
45
+ if (typeof elem.width === 'number' &&
46
+ typeof elem.height === 'number' &&
47
+ elem.width !== 0 &&
48
+ elem.height !== 0) {
44
49
  width = elem.width;
45
50
  height = elem.height;
46
51
  }
@@ -86,7 +91,7 @@ export default class ImageComponent extends AbstractComponent {
86
91
  }
87
92
  intersects(lineSegment) {
88
93
  const rect = this.getImageRect();
89
- const edges = rect.getEdges().map(edge => edge.transformedBy(this.image.transform));
94
+ const edges = rect.getEdges().map((edge) => edge.transformedBy(this.image.transform));
90
95
  for (const edge of edges) {
91
96
  if (edge.intersects(lineSegment)) {
92
97
  return true;
@@ -99,7 +104,9 @@ export default class ImageComponent extends AbstractComponent {
99
104
  this.recomputeBBox();
100
105
  }
101
106
  description(localizationTable) {
102
- return this.image.label ? localizationTable.imageNode(this.image.label) : localizationTable.unlabeledImageNode;
107
+ return this.image.label
108
+ ? localizationTable.imageNode(this.image.label)
109
+ : localizationTable.unlabeledImageNode;
103
110
  }
104
111
  getAltText() {
105
112
  return this.image.label;
@@ -1,7 +1,7 @@
1
1
  import { Color4 } from '@js-draw/math';
2
2
  import SerializableCommand from '../commands/SerializableCommand.mjs';
3
3
  import UnresolvedSerializableCommand from '../commands/UnresolvedCommand.mjs';
4
- import { textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle.mjs';
4
+ import { textStyleFromJSON, textStyleToJSON, } from '../rendering/TextRenderingStyle.mjs';
5
5
  const serializeComponentStyle = (style) => {
6
6
  const result = {};
7
7
  if (style.color) {
@@ -73,7 +73,7 @@ class DefaultRestyleComponentCommand extends UnresolvedSerializableCommand {
73
73
  const newStyle = deserializeComponentStyle(json.newStyle);
74
74
  const id = json.id;
75
75
  if (typeof json.id !== 'string') {
76
- throw new Error(`json.id is of type ${(typeof json.id)}, not string.`);
76
+ throw new Error(`json.id is of type ${typeof json.id}, not string.`);
77
77
  }
78
78
  return new DefaultRestyleComponentCommand(origStyle, newStyle, id);
79
79
  });
@@ -33,8 +33,7 @@ export default class SVGGlobalAttributesObject extends AbstractComponent {
33
33
  intersects(_lineSegment) {
34
34
  return false;
35
35
  }
36
- applyTransformation(_affineTransfm) {
37
- }
36
+ applyTransformation(_affineTransfm) { }
38
37
  isSelectable() {
39
38
  return false;
40
39
  }
@@ -1,8 +1,8 @@
1
- import { Path, Rect2, PathCommandType, comparePathIndices, stepPathIndexBy } from '@js-draw/math';
1
+ import { Path, Rect2, PathCommandType, comparePathIndices, stepPathIndexBy, } from '@js-draw/math';
2
2
  import { styleFromJSON, styleToJSON } from '../rendering/RenderingStyle.mjs';
3
3
  import AbstractComponent from './AbstractComponent.mjs';
4
- import { createRestyleComponentCommand } from './RestylableComponent.mjs';
5
- import { pathFromRenderable, pathToRenderable, simplifyPathToFullScreenOrEmpty } from '../rendering/RenderablePathSpec.mjs';
4
+ import { createRestyleComponentCommand, } from './RestylableComponent.mjs';
5
+ import { pathFromRenderable, pathToRenderable, simplifyPathToFullScreenOrEmpty, } from '../rendering/RenderablePathSpec.mjs';
6
6
  /**
7
7
  * Represents an {@link AbstractComponent} made up of one or more {@link Path}s.
8
8
  *
@@ -74,8 +74,7 @@ export default class Stroke extends AbstractComponent {
74
74
  return {};
75
75
  }
76
76
  const firstPart = this.parts[0];
77
- if (firstPart.style.stroke === undefined
78
- || firstPart.style.stroke.width === 0) {
77
+ if (firstPart.style.stroke === undefined || firstPart.style.stroke.width === 0) {
79
78
  return {
80
79
  color: firstPart.style.fill,
81
80
  };
@@ -94,9 +93,11 @@ export default class Stroke extends AbstractComponent {
94
93
  this.parts = this.parts.map((part) => {
95
94
  const newStyle = {
96
95
  ...part.style,
97
- stroke: part.style.stroke ? {
98
- ...part.style.stroke,
99
- } : undefined,
96
+ stroke: part.style.stroke
97
+ ? {
98
+ ...part.style.stroke,
99
+ }
100
+ : undefined,
100
101
  };
101
102
  // Change the stroke color if a stroked shape. Else,
102
103
  // change the fill.
@@ -131,7 +132,8 @@ export default class Stroke extends AbstractComponent {
131
132
  const makeStroke = (path) => {
132
133
  if (part.style.fill.a > 0) {
133
134
  // Remove visually empty paths.
134
- if (path.parts.length < 1 || (path.parts.length === 1 && path.parts[0].kind === PathCommandType.LineTo)) {
135
+ if (path.parts.length < 1 ||
136
+ (path.parts.length === 1 && path.parts[0].kind === PathCommandType.LineTo)) {
135
137
  // TODO: If this isn't present, a very large number of strokes are created while erasing.
136
138
  return null;
137
139
  }
@@ -164,10 +166,10 @@ export default class Stroke extends AbstractComponent {
164
166
  // 2. If zoomed in significantly, it's unlikely that the user wants to erase a large
165
167
  // part of the stroke.
166
168
  let isErasingFromEdge = false;
167
- if (intersectionPoints.length === 0
168
- && part.style.stroke
169
- && part.style.stroke.width > eraserPath.bbox.minDimension * 0.3
170
- && part.style.stroke.width < eraserPath.bbox.maxDimension * 30) {
169
+ if (intersectionPoints.length === 0 &&
170
+ part.style.stroke &&
171
+ part.style.stroke.width > eraserPath.bbox.minDimension * 0.3 &&
172
+ part.style.stroke.width < eraserPath.bbox.maxDimension * 30) {
171
173
  for (const segment of polyline) {
172
174
  intersectionPoints.push(...path.intersection(segment, part.style.stroke.width / 2));
173
175
  }
@@ -181,7 +183,7 @@ export default class Stroke extends AbstractComponent {
181
183
  }
182
184
  // The eraser may not be near the center of the curve -- approximate.
183
185
  if (isErasingFromEdge) {
184
- return intersectionPoints[0].curveIndex === 0 && intersectionPoints[0].parameterValue <= 0;
186
+ return (intersectionPoints[0].curveIndex === 0 && intersectionPoints[0].parameterValue <= 0);
185
187
  }
186
188
  const justBeforeFirstIntersection = stepPathIndexBy(intersectionPoints[0], -1e-10);
187
189
  return isPointInsideEraser(path.at(justBeforeFirstIntersection));
@@ -198,24 +200,30 @@ export default class Stroke extends AbstractComponent {
198
200
  // (including https://github.com/Pomax/bezierjs/issues/179).
199
201
  // Even if not all intersections are returned correctly, we still want
200
202
  // isInside to be roughly correct.
201
- if (knownToBeInside === undefined && !isInside && eraserPath.closedContainsPoint(path.getExactBBox().center)) {
203
+ if (knownToBeInside === undefined &&
204
+ !isInside &&
205
+ eraserPath.closedContainsPoint(path.getExactBBox().center)) {
202
206
  isInside = !isInside;
203
207
  }
204
208
  if (!component) {
205
209
  return;
206
210
  }
207
211
  // Assertion: Avoid deleting sections that are much larger than the eraser.
208
- failedAssertions ||= isInside && path.getExactBBox().maxDimension > eraserPath.getExactBBox().maxDimension * 2;
212
+ failedAssertions ||=
213
+ isInside && path.getExactBBox().maxDimension > eraserPath.getExactBBox().maxDimension * 2;
209
214
  if (!isInside) {
210
215
  newStrokes.push(component);
211
216
  }
212
217
  };
213
- if (part.style.fill.a === 0) { // Not filled?
218
+ if (part.style.fill.a === 0) {
219
+ // Not filled?
214
220
  // An additional case where we erase completely -- without the padding of the stroke,
215
221
  // the path is smaller than the eraser (allows us to erase dots completely).
216
222
  const shouldEraseCompletely = eraserPath.getExactBBox().maxDimension / 10 > path.getExactBBox().maxDimension;
217
223
  if (!shouldEraseCompletely) {
218
- const split = path.splitAt(intersectionPoints, { mapNewPoint: p => viewport.roundPoint(p) });
224
+ const split = path.splitAt(intersectionPoints, {
225
+ mapNewPoint: (p) => viewport.roundPoint(p),
226
+ });
219
227
  for (const splitPart of split) {
220
228
  addNewPath(splitPart);
221
229
  }
@@ -257,7 +265,9 @@ export default class Stroke extends AbstractComponent {
257
265
  //
258
266
  // The difficulty here is correctly pairing edges to create the the output
259
267
  // strokes, particularly because we don't know the order of intersection points.
260
- const parts = path.splitAt(intersectionPoints, { mapNewPoint: p => viewport.roundPoint(p) });
268
+ const parts = path.splitAt(intersectionPoints, {
269
+ mapNewPoint: (p) => viewport.roundPoint(p),
270
+ });
261
271
  for (let i = 0; i < Math.floor(parts.length / 2); i++) {
262
272
  addNewPath(parts[i].union(parts[parts.length - i - 1]).asClosed());
263
273
  }
@@ -333,12 +343,12 @@ export default class Stroke extends AbstractComponent {
333
343
  let occludes = false;
334
344
  let skipSimplification = false;
335
345
  for (const part of this.parts) {
336
- if (skipSimplification
346
+ if (skipSimplification ||
337
347
  // Simplification currently only works for stroked paths
338
- || !part.style.stroke
348
+ !part.style.stroke ||
339
349
  // One of the main purposes of this is to check for occlusion.
340
350
  // We can't occlude things if the stroke is partially transparent.
341
- || part.style.stroke.color.a < 0.99) {
351
+ part.style.stroke.color.a < 0.99) {
342
352
  simplifiedParts.push(part);
343
353
  continue;
344
354
  }
@@ -388,7 +398,8 @@ export default class Stroke extends AbstractComponent {
388
398
  continue;
389
399
  }
390
400
  const muchBiggerThanVisible = bbox.size.x > visibleRect.size.x * 3 || bbox.size.y > visibleRect.size.y * 3;
391
- if (muchBiggerThanVisible && !part.path.roughlyIntersects(visibleRect, part.style.stroke?.width ?? 0)) {
401
+ if (muchBiggerThanVisible &&
402
+ !part.path.roughlyIntersects(visibleRect, part.style.stroke?.width ?? 0)) {
392
403
  continue;
393
404
  }
394
405
  }
@@ -424,9 +435,11 @@ export default class Stroke extends AbstractComponent {
424
435
  const newPath = part.path.transformedBy(affineTransfm);
425
436
  const newStyle = {
426
437
  ...part.style,
427
- stroke: part.style.stroke ? {
428
- ...part.style.stroke,
429
- } : undefined,
438
+ stroke: part.style.stroke
439
+ ? {
440
+ ...part.style.stroke,
441
+ }
442
+ : undefined,
430
443
  };
431
444
  // Approximate the scale factor.
432
445
  if (newStyle.stroke) {
@@ -484,7 +497,7 @@ export default class Stroke extends AbstractComponent {
484
497
  return new Stroke(this.parts);
485
498
  }
486
499
  serializeToJSON() {
487
- return this.parts.map(part => {
500
+ return this.parts.map((part) => {
488
501
  return {
489
502
  style: styleToJSON(part.style),
490
503
  path: part.path.serialize(),
@@ -1,7 +1,7 @@
1
1
  import { Vec2, Rect2, Mat33, Color4 } from '@js-draw/math';
2
- import { cloneTextStyle, textStyleFromJSON, textStyleToJSON } from '../rendering/TextRenderingStyle.mjs';
2
+ import { cloneTextStyle, textStyleFromJSON, textStyleToJSON, } from '../rendering/TextRenderingStyle.mjs';
3
3
  import AbstractComponent from './AbstractComponent.mjs';
4
- import { createRestyleComponentCommand } from './RestylableComponent.mjs';
4
+ import { createRestyleComponentCommand, } from './RestylableComponent.mjs';
5
5
  const componentTypeId = 'text';
6
6
  export var TextTransformMode;
7
7
  (function (TextTransformMode) {
@@ -15,7 +15,9 @@ export var TextTransformMode;
15
15
  TextTransformMode[TextTransformMode["RELATIVE_Y_ABSOLUTE_X"] = 3] = "RELATIVE_Y_ABSOLUTE_X";
16
16
  })(TextTransformMode || (TextTransformMode = {}));
17
17
  const defaultTextStyle = {
18
- fontFamily: 'sans', size: 12, renderingStyle: { fill: Color4.purple },
18
+ fontFamily: 'sans',
19
+ size: 12,
20
+ renderingStyle: { fill: Color4.purple },
19
21
  };
20
22
  /**
21
23
  * Displays text.
@@ -76,7 +78,7 @@ class TextComponent extends AbstractComponent {
76
78
  this.recomputeBBox();
77
79
  // If this has no direct children, choose a style representative of this' content
78
80
  // (useful for estimating the style of the TextComponent).
79
- const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
81
+ const hasDirectContent = textObjects.some((obj) => typeof obj === 'string');
80
82
  if (!hasDirectContent && textObjects.length > 0) {
81
83
  this.style = textObjects[0].getTextStyle();
82
84
  }
@@ -90,7 +92,7 @@ class TextComponent extends AbstractComponent {
90
92
  style.fontStyle ?? '',
91
93
  style.fontWeight ?? '',
92
94
  (style.size ?? 12) + 'px',
93
- `${fontFamily}`
95
+ `${fontFamily}`,
94
96
  ].join(' ');
95
97
  // TODO: Support RTL
96
98
  ctx.textAlign = 'left';
@@ -101,7 +103,7 @@ class TextComponent extends AbstractComponent {
101
103
  const heightEst = style.size;
102
104
  // Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
103
105
  // be above (0, 0).
104
- return new Rect2(0, -heightEst * 2 / 3, widthEst, heightEst);
106
+ return new Rect2(0, (-heightEst * 2) / 3, widthEst, heightEst);
105
107
  }
106
108
  // Returns a set of TextMetrics for the given text, if a canvas is available.
107
109
  static getTextMetrics(text, style) {
@@ -181,7 +183,7 @@ class TextComponent extends AbstractComponent {
181
183
  const textBBox = TextComponent.getTextDimens(subObject, this.style);
182
184
  // TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
183
185
  // use pixel-testing to check for intersection with its contour.
184
- if (textBBox.getEdges().some(edge => transformedLine.intersection(edge) !== null)) {
186
+ if (textBBox.getEdges().some((edge) => transformedLine.intersection(edge) !== null)) {
185
187
  return true;
186
188
  }
187
189
  }
@@ -249,7 +251,7 @@ class TextComponent extends AbstractComponent {
249
251
  this.recomputeBBox();
250
252
  }
251
253
  createClone() {
252
- const clonedTextObjects = this.textObjects.map(obj => {
254
+ const clonedTextObjects = this.textObjects.map((obj) => {
253
255
  if (typeof obj === 'string') {
254
256
  return obj;
255
257
  }
@@ -277,7 +279,7 @@ class TextComponent extends AbstractComponent {
277
279
  // Do not rely on the output of `serializeToJSON` taking any particular format.
278
280
  serializeToJSON() {
279
281
  const serializableStyle = textStyleToJSON(this.style);
280
- const serializedTextObjects = this.textObjects.map(text => {
282
+ const serializedTextObjects = this.textObjects.map((text) => {
281
283
  if (typeof text === 'string') {
282
284
  return {
283
285
  text,
@@ -363,7 +365,7 @@ TextComponent.TextCursor = class {
363
365
  let elementTransform = Mat33.identity;
364
366
  let elemInternalTransform = Mat33.identity;
365
367
  let textSize;
366
- if (typeof (elem) === 'string') {
368
+ if (typeof elem === 'string') {
367
369
  textSize = TextComponent.getTextDimens(elem, this.parentStyle);
368
370
  }
369
371
  else {
@@ -372,12 +374,13 @@ TextComponent.TextCursor = class {
372
374
  elemInternalTransform = elem.transform;
373
375
  textSize = elem.getBBox();
374
376
  }
375
- const positioning = typeof (elem) === 'string' ? TextTransformMode.RELATIVE_XY : elem.transformMode;
377
+ const positioning = typeof elem === 'string' ? TextTransformMode.RELATIVE_XY : elem.transformMode;
376
378
  if (positioning === TextTransformMode.RELATIVE_XY) {
377
379
  // Position relative to the previous element's transform.
378
380
  elementTransform = this.transform.rightMul(elementTransform);
379
381
  }
380
- else if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y || positioning === TextTransformMode.RELATIVE_Y_ABSOLUTE_X) {
382
+ else if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y ||
383
+ positioning === TextTransformMode.RELATIVE_Y_ABSOLUTE_X) {
381
384
  // Zero the absolute component of this.transform's translation
382
385
  const transform = this.transform.mapEntries((component, [row, col]) => {
383
386
  if (positioning === TextTransformMode.RELATIVE_X_ABSOLUTE_Y) {
@@ -23,10 +23,9 @@ export default class UnknownSVGObject extends AbstractComponent {
23
23
  canvas.endObject(this.getLoadSaveData());
24
24
  }
25
25
  intersects(lineSegment) {
26
- return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
27
- }
28
- applyTransformation(_affineTransfm) {
26
+ return this.contentBBox.getEdges().some((edge) => edge.intersection(lineSegment) !== null);
29
27
  }
28
+ applyTransformation(_affineTransfm) { }
30
29
  isSelectable() {
31
30
  return false;
32
31
  }
@@ -4,6 +4,12 @@ import { StrokeDataPoint } from '../../types';
4
4
  import Viewport from '../../Viewport';
5
5
  import AbstractComponent from '../AbstractComponent';
6
6
  import { ComponentBuilder, ComponentBuilderFactory } from './types';
7
+ /**
8
+ * Creates a stroke builder that generates arrows.
9
+ *
10
+ * Example:
11
+ * [[include:doc-pages/inline-examples/changing-pen-types.md]]
12
+ */
7
13
  export declare const makeArrowBuilder: ComponentBuilderFactory;
8
14
  export default class ArrowBuilder implements ComponentBuilder {
9
15
  private readonly startPoint;
@@ -1,6 +1,12 @@
1
1
  import { Path, PathCommandType } from '@js-draw/math';
2
2
  import Stroke from '../Stroke.mjs';
3
3
  import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
4
+ /**
5
+ * Creates a stroke builder that generates arrows.
6
+ *
7
+ * Example:
8
+ * [[include:doc-pages/inline-examples/changing-pen-types.md]]
9
+ */
4
10
  export const makeArrowBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
5
11
  return new ArrowBuilder(initialPoint, viewport);
6
12
  });
@@ -63,15 +69,15 @@ export default class ArrowBuilder {
63
69
  point: arrowTipBase.minus(scaledBaseNormal),
64
70
  },
65
71
  // Round all points in the arrow (to remove unnecessary decimal places)
66
- ]).mapPoints(point => this.viewport.roundPoint(point));
72
+ ]).mapPoints((point) => this.viewport.roundPoint(point));
67
73
  const preview = new Stroke([
68
74
  {
69
75
  startPoint: path.startPoint,
70
76
  commands: path.parts,
71
77
  style: {
72
78
  fill: this.startPoint.color,
73
- }
74
- }
79
+ },
80
+ },
75
81
  ]);
76
82
  return preview;
77
83
  }
@@ -1,2 +1,8 @@
1
1
  import { ComponentBuilderFactory } from './types';
2
+ /**
3
+ * Creates a stroke builder that generates outlined circles.
4
+ *
5
+ * Example:
6
+ * [[include:doc-pages/inline-examples/changing-pen-types.md]]
7
+ */
2
8
  export declare const makeOutlinedCircleBuilder: ComponentBuilderFactory;
@@ -3,6 +3,12 @@ import { pathToRenderable } from '../../rendering/RenderablePathSpec.mjs';
3
3
  import Viewport from '../../Viewport.mjs';
4
4
  import Stroke from '../Stroke.mjs';
5
5
  import makeSnapToGridAutocorrect from './autocorrect/makeSnapToGridAutocorrect.mjs';
6
+ /**
7
+ * Creates a stroke builder that generates outlined circles.
8
+ *
9
+ * Example:
10
+ * [[include:doc-pages/inline-examples/changing-pen-types.md]]
11
+ */
6
12
  export const makeOutlinedCircleBuilder = makeSnapToGridAutocorrect((initialPoint, viewport) => {
7
13
  return new CircleBuilder(initialPoint, viewport);
8
14
  });
@@ -20,7 +26,7 @@ class CircleBuilder {
20
26
  buildPreview() {
21
27
  const pathCommands = [];
22
28
  const numDivisions = 6;
23
- const stepSize = Math.PI * 2 / numDivisions;
29
+ const stepSize = (Math.PI * 2) / numDivisions;
24
30
  // Round the stroke width so that when exported it doesn't have unnecessary trailing decimals.
25
31
  const strokeWidth = Viewport.roundPoint(this.endPoint.width, 5 / this.viewport.getScaleFactor());
26
32
  const center = this.startPoint.pos.lerp(this.endPoint.pos, 0.5);
@@ -32,7 +38,9 @@ class CircleBuilder {
32
38
  // controlPointRadiusScale is selected to make the circles appear circular and
33
39
  // **does** depend on stepSize.
34
40
  const controlPointRadiusScale = 1.141;
35
- const controlPoint = Vec2.of(Math.cos(t - stepSize / 2), -Math.sin(t - stepSize / 2)).times(radius * controlPointRadiusScale).plus(center);
41
+ const controlPoint = Vec2.of(Math.cos(t - stepSize / 2), -Math.sin(t - stepSize / 2))
42
+ .times(radius * controlPointRadiusScale)
43
+ .plus(center);
36
44
  pathCommands.push({
37
45
  kind: PathCommandType.QuadraticBezierTo,
38
46
  controlPoint,
@@ -43,8 +51,7 @@ class CircleBuilder {
43
51
  kind: PathCommandType.LineTo,
44
52
  point: startPoint,
45
53
  });
46
- const path = new Path(startPoint, pathCommands)
47
- .mapPoints(point => this.viewport.roundPoint(point));
54
+ const path = new Path(startPoint, pathCommands).mapPoints((point) => this.viewport.roundPoint(point));
48
55
  const preview = new Stroke([
49
56
  pathToRenderable(path, {
50
57
  fill: Color4.transparent,
@@ -6,6 +6,12 @@ import Viewport from '../../Viewport';
6
6
  import { StrokeDataPoint } from '../../types';
7
7
  import { ComponentBuilder, ComponentBuilderFactory } from './types';
8
8
  import RenderingStyle from '../../rendering/RenderingStyle';
9
+ /**
10
+ * Creates a stroke builder that draws freehand lines.
11
+ *
12
+ * Example:
13
+ * [[include:doc-pages/inline-examples/changing-pen-types.md]]
14
+ */
9
15
  export declare const makeFreehandLineBuilder: ComponentBuilderFactory;
10
16
  export default class FreehandLineBuilder implements ComponentBuilder {
11
17
  private startPoint;