js-draw 0.18.1 → 0.18.2

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 (627) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/cjs/src/Color4.d.ts +61 -0
  3. package/dist/cjs/src/Color4.js +197 -0
  4. package/dist/cjs/src/Editor.d.ts +308 -0
  5. package/dist/cjs/src/Editor.js +904 -0
  6. package/dist/cjs/src/EditorImage.d.ts +97 -0
  7. package/dist/cjs/src/EditorImage.js +486 -0
  8. package/dist/cjs/src/EventDispatcher.d.ts +30 -0
  9. package/dist/cjs/src/EventDispatcher.js +57 -0
  10. package/dist/cjs/src/Pointer.d.ts +24 -0
  11. package/dist/cjs/src/Pointer.js +84 -0
  12. package/dist/cjs/src/SVGLoader.d.ts +48 -0
  13. package/dist/cjs/src/SVGLoader.js +472 -0
  14. package/dist/cjs/src/UndoRedoHistory.d.ts +19 -0
  15. package/dist/cjs/src/UndoRedoHistory.js +93 -0
  16. package/dist/cjs/src/Viewport.d.ts +71 -0
  17. package/dist/cjs/src/Viewport.js +264 -0
  18. package/dist/cjs/src/bundle/bundled.d.ts +4 -0
  19. package/dist/cjs/src/bundle/bundled.js +24 -0
  20. package/dist/cjs/src/commands/Command.d.ts +16 -0
  21. package/dist/cjs/src/commands/Command.js +34 -0
  22. package/dist/cjs/src/commands/Duplicate.d.ts +14 -0
  23. package/dist/cjs/src/commands/Duplicate.js +39 -0
  24. package/dist/cjs/src/commands/Erase.d.ts +14 -0
  25. package/dist/cjs/src/commands/Erase.js +63 -0
  26. package/dist/cjs/src/commands/SerializableCommand.d.ts +12 -0
  27. package/dist/cjs/src/commands/SerializableCommand.js +42 -0
  28. package/dist/cjs/src/commands/UnresolvedCommand.d.ts +14 -0
  29. package/dist/cjs/src/commands/UnresolvedCommand.js +28 -0
  30. package/dist/cjs/src/commands/invertCommand.d.ts +4 -0
  31. package/dist/cjs/src/commands/invertCommand.js +49 -0
  32. package/dist/cjs/src/commands/lib.d.ts +7 -0
  33. package/dist/cjs/src/commands/lib.js +18 -0
  34. package/dist/cjs/src/commands/localization.d.ts +23 -0
  35. package/dist/cjs/src/commands/localization.js +24 -0
  36. package/dist/cjs/src/commands/uniteCommands.d.ts +4 -0
  37. package/dist/cjs/src/commands/uniteCommands.js +121 -0
  38. package/dist/cjs/src/components/AbstractComponent.d.ts +73 -0
  39. package/dist/cjs/src/components/AbstractComponent.js +258 -0
  40. package/dist/cjs/src/components/ImageBackground.d.ts +42 -0
  41. package/dist/cjs/src/components/ImageBackground.js +146 -0
  42. package/dist/cjs/src/components/ImageComponent.d.ts +31 -0
  43. package/dist/cjs/src/components/ImageComponent.js +152 -0
  44. package/dist/cjs/src/components/RestylableComponent.d.ts +24 -0
  45. package/dist/cjs/src/components/RestylableComponent.js +88 -0
  46. package/dist/cjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
  47. package/dist/cjs/src/components/SVGGlobalAttributesObject.js +65 -0
  48. package/dist/cjs/src/components/Stroke.d.ts +40 -0
  49. package/dist/cjs/src/components/Stroke.js +191 -0
  50. package/dist/cjs/src/components/TextComponent.d.ts +53 -0
  51. package/dist/cjs/src/components/TextComponent.js +258 -0
  52. package/dist/cjs/src/components/UnknownSVGObject.d.ts +18 -0
  53. package/dist/cjs/src/components/UnknownSVGObject.js +50 -0
  54. package/dist/cjs/src/components/builders/ArrowBuilder.d.ts +19 -0
  55. package/dist/cjs/src/components/builders/ArrowBuilder.js +117 -0
  56. package/dist/cjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
  57. package/dist/cjs/src/components/builders/FreehandLineBuilder.js +173 -0
  58. package/dist/cjs/src/components/builders/LineBuilder.d.ts +18 -0
  59. package/dist/cjs/src/components/builders/LineBuilder.js +89 -0
  60. package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
  61. package/dist/cjs/src/components/builders/PressureSensitiveFreehandLineBuilder.js +347 -0
  62. package/dist/cjs/src/components/builders/RectangleBuilder.d.ts +20 -0
  63. package/dist/cjs/src/components/builders/RectangleBuilder.js +59 -0
  64. package/dist/cjs/src/components/builders/types.d.ts +12 -0
  65. package/dist/cjs/src/components/builders/types.js +2 -0
  66. package/dist/cjs/src/components/lib.d.ts +12 -0
  67. package/dist/cjs/src/components/lib.js +43 -0
  68. package/dist/cjs/src/components/localization.d.ts +11 -0
  69. package/dist/cjs/src/components/localization.js +13 -0
  70. package/dist/cjs/src/components/util/StrokeSmoother.d.ts +35 -0
  71. package/dist/cjs/src/components/util/StrokeSmoother.js +217 -0
  72. package/dist/cjs/src/components/util/describeComponentList.d.ts +4 -0
  73. package/dist/cjs/src/components/util/describeComponentList.js +16 -0
  74. package/dist/cjs/src/lib.d.ts +34 -0
  75. package/dist/cjs/src/lib.js +63 -0
  76. package/dist/cjs/src/localization.d.ts +14 -0
  77. package/dist/cjs/src/localization.js +13 -0
  78. package/dist/cjs/src/localizations/de.d.ts +3 -0
  79. package/dist/cjs/src/localizations/de.js +6 -0
  80. package/dist/cjs/src/localizations/en.d.ts +3 -0
  81. package/dist/cjs/src/localizations/en.js +6 -0
  82. package/dist/cjs/src/localizations/es.d.ts +3 -0
  83. package/dist/cjs/src/localizations/es.js +20 -0
  84. package/dist/cjs/src/localizations/getLocalizationTable.d.ts +3 -0
  85. package/dist/cjs/src/localizations/getLocalizationTable.js +50 -0
  86. package/dist/cjs/src/math/LineSegment2.d.ts +24 -0
  87. package/dist/cjs/src/math/LineSegment2.js +131 -0
  88. package/dist/cjs/src/math/Mat33.d.ts +118 -0
  89. package/dist/cjs/src/math/Mat33.js +332 -0
  90. package/dist/cjs/src/math/Path.d.ts +71 -0
  91. package/dist/cjs/src/math/Path.js +655 -0
  92. package/dist/cjs/src/math/Rect2.d.ts +52 -0
  93. package/dist/cjs/src/math/Rect2.js +234 -0
  94. package/dist/cjs/src/math/Triangle.d.ts +11 -0
  95. package/dist/cjs/src/math/Triangle.js +22 -0
  96. package/dist/cjs/src/math/Vec2.d.ts +13 -0
  97. package/dist/cjs/src/math/Vec2.js +19 -0
  98. package/dist/cjs/src/math/Vec3.d.ts +106 -0
  99. package/dist/cjs/src/math/Vec3.js +177 -0
  100. package/dist/cjs/src/math/lib.d.ts +7 -0
  101. package/dist/cjs/src/math/lib.js +18 -0
  102. package/dist/cjs/src/math/rounding.d.ts +4 -0
  103. package/dist/cjs/src/math/rounding.js +135 -0
  104. package/dist/cjs/src/rendering/Display.d.ts +75 -0
  105. package/dist/cjs/src/rendering/Display.js +214 -0
  106. package/dist/cjs/src/rendering/RenderingStyle.d.ts +31 -0
  107. package/dist/cjs/src/rendering/RenderingStyle.js +48 -0
  108. package/dist/cjs/src/rendering/TextRenderingStyle.d.ts +36 -0
  109. package/dist/cjs/src/rendering/TextRenderingStyle.js +29 -0
  110. package/dist/cjs/src/rendering/caching/CacheRecord.d.ts +20 -0
  111. package/dist/cjs/src/rendering/caching/CacheRecord.js +61 -0
  112. package/dist/cjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
  113. package/dist/cjs/src/rendering/caching/CacheRecordManager.js +50 -0
  114. package/dist/cjs/src/rendering/caching/RenderingCache.d.ts +11 -0
  115. package/dist/cjs/src/rendering/caching/RenderingCache.js +51 -0
  116. package/dist/cjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
  117. package/dist/cjs/src/rendering/caching/RenderingCacheNode.js +326 -0
  118. package/dist/cjs/src/rendering/caching/testUtils.d.ts +9 -0
  119. package/dist/cjs/src/rendering/caching/testUtils.js +27 -0
  120. package/dist/cjs/src/rendering/caching/types.d.ts +19 -0
  121. package/dist/cjs/src/rendering/caching/types.js +2 -0
  122. package/dist/cjs/src/rendering/lib.d.ts +5 -0
  123. package/dist/cjs/src/rendering/lib.js +17 -0
  124. package/dist/cjs/src/rendering/localization.d.ts +10 -0
  125. package/dist/cjs/src/rendering/localization.js +12 -0
  126. package/dist/cjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
  127. package/dist/cjs/src/rendering/renderers/AbstractRenderer.js +170 -0
  128. package/dist/cjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
  129. package/dist/cjs/src/rendering/renderers/CanvasRenderer.js +236 -0
  130. package/dist/cjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
  131. package/dist/cjs/src/rendering/renderers/DummyRenderer.js +112 -0
  132. package/dist/cjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
  133. package/dist/cjs/src/rendering/renderers/SVGRenderer.js +311 -0
  134. package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
  135. package/dist/cjs/src/rendering/renderers/TextOnlyRenderer.js +63 -0
  136. package/dist/cjs/src/testing/beforeEachFile.d.ts +1 -0
  137. package/dist/cjs/src/testing/beforeEachFile.js +12 -0
  138. package/dist/cjs/src/testing/createEditor.d.ts +4 -0
  139. package/dist/cjs/src/testing/createEditor.js +14 -0
  140. package/dist/cjs/src/testing/lib.d.ts +2 -0
  141. package/dist/cjs/src/testing/lib.js +10 -0
  142. package/dist/cjs/src/testing/loadExpectExtensions.d.ts +2 -0
  143. package/dist/cjs/src/testing/loadExpectExtensions.js +28 -0
  144. package/dist/cjs/src/testing/sendPenEvent.d.ts +12 -0
  145. package/dist/cjs/src/testing/sendPenEvent.js +24 -0
  146. package/dist/cjs/src/testing/sendTouchEvent.d.ts +42 -0
  147. package/dist/cjs/src/testing/sendTouchEvent.js +87 -0
  148. package/dist/cjs/src/toolbar/HTMLToolbar.d.ts +103 -0
  149. package/dist/cjs/src/toolbar/HTMLToolbar.js +383 -0
  150. package/dist/cjs/src/toolbar/IconProvider.d.ts +62 -0
  151. package/dist/cjs/src/toolbar/IconProvider.js +660 -0
  152. package/dist/cjs/src/toolbar/lib.d.ts +3 -0
  153. package/dist/cjs/src/toolbar/lib.js +24 -0
  154. package/dist/cjs/src/toolbar/localization.d.ts +49 -0
  155. package/dist/cjs/src/toolbar/localization.js +51 -0
  156. package/dist/cjs/src/toolbar/makeColorInput.d.ts +6 -0
  157. package/dist/cjs/src/toolbar/makeColorInput.js +120 -0
  158. package/dist/cjs/src/toolbar/types.d.ts +4 -0
  159. package/dist/cjs/src/toolbar/types.js +2 -0
  160. package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
  161. package/dist/cjs/src/toolbar/widgets/ActionButtonWidget.js +31 -0
  162. package/dist/cjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
  163. package/dist/cjs/src/toolbar/widgets/BaseToolWidget.js +50 -0
  164. package/dist/cjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
  165. package/dist/cjs/src/toolbar/widgets/BaseWidget.js +313 -0
  166. package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
  167. package/dist/cjs/src/toolbar/widgets/DocumentPropertiesWidget.js +126 -0
  168. package/dist/cjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
  169. package/dist/cjs/src/toolbar/widgets/EraserToolWidget.js +63 -0
  170. package/dist/cjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
  171. package/dist/cjs/src/toolbar/widgets/HandToolWidget.js +201 -0
  172. package/dist/cjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
  173. package/dist/cjs/src/toolbar/widgets/InsertImageWidget.js +176 -0
  174. package/dist/cjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
  175. package/dist/cjs/src/toolbar/widgets/OverflowWidget.js +77 -0
  176. package/dist/cjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
  177. package/dist/cjs/src/toolbar/widgets/PenToolWidget.js +226 -0
  178. package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
  179. package/dist/cjs/src/toolbar/widgets/SelectionToolWidget.js +153 -0
  180. package/dist/cjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
  181. package/dist/cjs/src/toolbar/widgets/TextToolWidget.js +115 -0
  182. package/dist/cjs/src/toolbar/widgets/lib.d.ts +10 -0
  183. package/dist/cjs/src/toolbar/widgets/lib.js +26 -0
  184. package/dist/cjs/src/tools/BaseTool.d.ts +22 -0
  185. package/dist/cjs/src/tools/BaseTool.js +66 -0
  186. package/dist/cjs/src/tools/Eraser.d.ts +23 -0
  187. package/dist/cjs/src/tools/Eraser.js +112 -0
  188. package/dist/cjs/src/tools/FindTool.d.ts +21 -0
  189. package/dist/cjs/src/tools/FindTool.js +121 -0
  190. package/dist/cjs/src/tools/PanZoom.d.ts +52 -0
  191. package/dist/cjs/src/tools/PanZoom.js +421 -0
  192. package/dist/cjs/src/tools/PasteHandler.d.ts +23 -0
  193. package/dist/cjs/src/tools/PasteHandler.js +99 -0
  194. package/dist/cjs/src/tools/Pen.d.ts +39 -0
  195. package/dist/cjs/src/tools/Pen.js +179 -0
  196. package/dist/cjs/src/tools/PipetteTool.d.ts +18 -0
  197. package/dist/cjs/src/tools/PipetteTool.js +45 -0
  198. package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
  199. package/dist/cjs/src/tools/SelectionTool/SelectAllShortcutHandler.js +28 -0
  200. package/dist/cjs/src/tools/SelectionTool/Selection.d.ts +64 -0
  201. package/dist/cjs/src/tools/SelectionTool/Selection.js +488 -0
  202. package/dist/cjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
  203. package/dist/cjs/src/tools/SelectionTool/SelectionHandle.js +85 -0
  204. package/dist/cjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
  205. package/dist/cjs/src/tools/SelectionTool/SelectionTool.js +405 -0
  206. package/dist/cjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
  207. package/dist/cjs/src/tools/SelectionTool/TransformMode.js +107 -0
  208. package/dist/cjs/src/tools/SelectionTool/types.d.ts +9 -0
  209. package/dist/cjs/src/tools/SelectionTool/types.js +14 -0
  210. package/dist/cjs/src/tools/TextTool.d.ts +33 -0
  211. package/dist/cjs/src/tools/TextTool.js +262 -0
  212. package/dist/cjs/src/tools/ToolController.d.ts +18 -0
  213. package/dist/cjs/src/tools/ToolController.js +187 -0
  214. package/dist/cjs/src/tools/ToolEnabledGroup.d.ts +6 -0
  215. package/dist/cjs/src/tools/ToolEnabledGroup.js +14 -0
  216. package/dist/cjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
  217. package/dist/cjs/src/tools/ToolSwitcherShortcut.js +38 -0
  218. package/dist/cjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
  219. package/dist/cjs/src/tools/ToolbarShortcutHandler.js +29 -0
  220. package/dist/cjs/src/tools/UndoRedoShortcut.d.ts +8 -0
  221. package/dist/cjs/src/tools/UndoRedoShortcut.js +28 -0
  222. package/dist/cjs/src/tools/lib.d.ts +16 -0
  223. package/dist/cjs/src/tools/lib.js +36 -0
  224. package/dist/cjs/src/tools/localization.d.ts +28 -0
  225. package/dist/cjs/src/tools/localization.js +30 -0
  226. package/dist/cjs/src/types.d.ts +151 -0
  227. package/dist/cjs/src/types.js +38 -0
  228. package/dist/cjs/src/util/assertions.d.ts +23 -0
  229. package/dist/cjs/src/util/assertions.js +51 -0
  230. package/dist/cjs/src/util/fileToBase64.d.ts +3 -0
  231. package/dist/cjs/src/util/fileToBase64.js +15 -0
  232. package/dist/cjs/src/util/untilNextAnimationFrame.d.ts +3 -0
  233. package/dist/cjs/src/util/untilNextAnimationFrame.js +9 -0
  234. package/dist/cjs/src/util/waitForTimeout.d.ts +2 -0
  235. package/dist/cjs/src/util/waitForTimeout.js +9 -0
  236. package/dist/mjs/src/Color4.d.ts +61 -0
  237. package/dist/mjs/src/Color4.mjs +193 -0
  238. package/dist/mjs/src/Editor.d.ts +308 -0
  239. package/dist/mjs/src/Editor.mjs +874 -0
  240. package/dist/mjs/src/EditorImage.d.ts +97 -0
  241. package/dist/mjs/src/EditorImage.mjs +477 -0
  242. package/dist/mjs/src/EventDispatcher.d.ts +30 -0
  243. package/dist/mjs/src/EventDispatcher.mjs +54 -0
  244. package/dist/mjs/src/Pointer.d.ts +24 -0
  245. package/dist/mjs/src/Pointer.mjs +80 -0
  246. package/dist/mjs/src/SVGLoader.d.ts +48 -0
  247. package/dist/mjs/src/SVGLoader.mjs +442 -0
  248. package/dist/mjs/src/UndoRedoHistory.d.ts +19 -0
  249. package/dist/mjs/src/UndoRedoHistory.mjs +91 -0
  250. package/dist/mjs/src/Viewport.d.ts +71 -0
  251. package/dist/mjs/src/Viewport.mjs +256 -0
  252. package/dist/mjs/src/bundle/bundled.d.ts +4 -0
  253. package/dist/mjs/src/bundle/bundled.mjs +5 -0
  254. package/dist/mjs/src/commands/Command.d.ts +16 -0
  255. package/dist/mjs/src/commands/Command.mjs +30 -0
  256. package/dist/mjs/src/commands/Duplicate.d.ts +14 -0
  257. package/dist/mjs/src/commands/Duplicate.mjs +33 -0
  258. package/dist/mjs/src/commands/Erase.d.ts +14 -0
  259. package/dist/mjs/src/commands/Erase.mjs +57 -0
  260. package/dist/mjs/src/commands/SerializableCommand.d.ts +12 -0
  261. package/dist/mjs/src/commands/SerializableCommand.mjs +36 -0
  262. package/dist/mjs/src/commands/UnresolvedCommand.d.ts +14 -0
  263. package/dist/mjs/src/commands/UnresolvedCommand.mjs +22 -0
  264. package/dist/mjs/src/commands/invertCommand.d.ts +4 -0
  265. package/dist/mjs/src/commands/invertCommand.mjs +44 -0
  266. package/dist/mjs/src/commands/lib.d.ts +7 -0
  267. package/dist/mjs/src/commands/lib.mjs +7 -0
  268. package/dist/mjs/src/commands/localization.d.ts +23 -0
  269. package/dist/mjs/src/commands/localization.mjs +21 -0
  270. package/dist/mjs/src/commands/uniteCommands.d.ts +4 -0
  271. package/dist/mjs/src/commands/uniteCommands.mjs +116 -0
  272. package/dist/mjs/src/components/AbstractComponent.d.ts +73 -0
  273. package/dist/mjs/src/components/AbstractComponent.mjs +252 -0
  274. package/dist/mjs/src/components/ImageBackground.d.ts +42 -0
  275. package/dist/mjs/src/components/ImageBackground.mjs +139 -0
  276. package/dist/mjs/src/components/ImageComponent.d.ts +31 -0
  277. package/dist/mjs/src/components/ImageComponent.mjs +146 -0
  278. package/dist/mjs/src/components/RestylableComponent.d.ts +24 -0
  279. package/dist/mjs/src/components/RestylableComponent.mjs +80 -0
  280. package/dist/mjs/src/components/SVGGlobalAttributesObject.d.ts +21 -0
  281. package/dist/mjs/src/components/SVGGlobalAttributesObject.mjs +59 -0
  282. package/dist/mjs/src/components/Stroke.d.ts +40 -0
  283. package/dist/mjs/src/components/Stroke.mjs +185 -0
  284. package/dist/mjs/src/components/TextComponent.d.ts +53 -0
  285. package/dist/mjs/src/components/TextComponent.mjs +252 -0
  286. package/dist/mjs/src/components/UnknownSVGObject.d.ts +18 -0
  287. package/dist/mjs/src/components/UnknownSVGObject.mjs +44 -0
  288. package/dist/mjs/src/components/builders/ArrowBuilder.d.ts +19 -0
  289. package/dist/mjs/src/components/builders/ArrowBuilder.mjs +86 -0
  290. package/dist/mjs/src/components/builders/FreehandLineBuilder.d.ts +33 -0
  291. package/dist/mjs/src/components/builders/FreehandLineBuilder.mjs +165 -0
  292. package/dist/mjs/src/components/builders/LineBuilder.d.ts +18 -0
  293. package/dist/mjs/src/components/builders/LineBuilder.mjs +58 -0
  294. package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.d.ts +36 -0
  295. package/dist/mjs/src/components/builders/PressureSensitiveFreehandLineBuilder.mjs +339 -0
  296. package/dist/mjs/src/components/builders/RectangleBuilder.d.ts +20 -0
  297. package/dist/mjs/src/components/builders/RectangleBuilder.mjs +50 -0
  298. package/dist/mjs/src/components/builders/types.d.ts +12 -0
  299. package/dist/mjs/src/components/builders/types.mjs +1 -0
  300. package/dist/mjs/src/components/lib.d.ts +12 -0
  301. package/dist/mjs/src/components/lib.mjs +12 -0
  302. package/dist/mjs/src/components/localization.d.ts +11 -0
  303. package/dist/mjs/src/components/localization.mjs +10 -0
  304. package/dist/mjs/src/components/util/StrokeSmoother.d.ts +35 -0
  305. package/dist/mjs/src/components/util/StrokeSmoother.mjs +210 -0
  306. package/dist/mjs/src/components/util/describeComponentList.d.ts +4 -0
  307. package/dist/mjs/src/components/util/describeComponentList.mjs +14 -0
  308. package/dist/mjs/src/lib.d.ts +34 -0
  309. package/dist/mjs/src/lib.mjs +34 -0
  310. package/dist/mjs/src/localization.d.ts +14 -0
  311. package/dist/mjs/src/localization.mjs +10 -0
  312. package/dist/mjs/src/localizations/de.d.ts +3 -0
  313. package/dist/mjs/src/localizations/de.mjs +4 -0
  314. package/dist/mjs/src/localizations/en.d.ts +3 -0
  315. package/dist/mjs/src/localizations/en.mjs +4 -0
  316. package/dist/mjs/src/localizations/es.d.ts +3 -0
  317. package/dist/mjs/src/localizations/es.mjs +18 -0
  318. package/dist/mjs/src/localizations/getLocalizationTable.d.ts +3 -0
  319. package/dist/mjs/src/localizations/getLocalizationTable.mjs +45 -0
  320. package/dist/mjs/src/math/LineSegment2.d.ts +24 -0
  321. package/dist/mjs/src/math/LineSegment2.mjs +125 -0
  322. package/dist/mjs/src/math/Mat33.d.ts +118 -0
  323. package/dist/mjs/src/math/Mat33.mjs +326 -0
  324. package/dist/mjs/src/math/Path.d.ts +71 -0
  325. package/dist/mjs/src/math/Path.mjs +648 -0
  326. package/dist/mjs/src/math/Rect2.d.ts +52 -0
  327. package/dist/mjs/src/math/Rect2.mjs +228 -0
  328. package/dist/mjs/src/math/Triangle.d.ts +11 -0
  329. package/dist/mjs/src/math/Triangle.mjs +19 -0
  330. package/dist/mjs/src/math/Vec2.d.ts +13 -0
  331. package/dist/mjs/src/math/Vec2.mjs +13 -0
  332. package/dist/mjs/src/math/Vec3.d.ts +106 -0
  333. package/dist/mjs/src/math/Vec3.mjs +174 -0
  334. package/dist/mjs/src/math/lib.d.ts +7 -0
  335. package/dist/mjs/src/math/lib.mjs +7 -0
  336. package/dist/mjs/src/math/rounding.d.ts +4 -0
  337. package/dist/mjs/src/math/rounding.mjs +128 -0
  338. package/dist/mjs/src/rendering/Display.d.ts +75 -0
  339. package/dist/mjs/src/rendering/Display.mjs +207 -0
  340. package/dist/mjs/src/rendering/RenderingStyle.d.ts +31 -0
  341. package/dist/mjs/src/rendering/RenderingStyle.mjs +38 -0
  342. package/dist/mjs/src/rendering/TextRenderingStyle.d.ts +36 -0
  343. package/dist/mjs/src/rendering/TextRenderingStyle.mjs +23 -0
  344. package/dist/mjs/src/rendering/caching/CacheRecord.d.ts +20 -0
  345. package/dist/mjs/src/rendering/caching/CacheRecord.mjs +55 -0
  346. package/dist/mjs/src/rendering/caching/CacheRecordManager.d.ts +12 -0
  347. package/dist/mjs/src/rendering/caching/CacheRecordManager.mjs +43 -0
  348. package/dist/mjs/src/rendering/caching/RenderingCache.d.ts +11 -0
  349. package/dist/mjs/src/rendering/caching/RenderingCache.mjs +45 -0
  350. package/dist/mjs/src/rendering/caching/RenderingCacheNode.d.ts +29 -0
  351. package/dist/mjs/src/rendering/caching/RenderingCacheNode.mjs +320 -0
  352. package/dist/mjs/src/rendering/caching/testUtils.d.ts +9 -0
  353. package/dist/mjs/src/rendering/caching/testUtils.mjs +20 -0
  354. package/dist/mjs/src/rendering/caching/types.d.ts +19 -0
  355. package/dist/mjs/src/rendering/caching/types.mjs +1 -0
  356. package/dist/mjs/src/rendering/lib.d.ts +5 -0
  357. package/dist/mjs/src/rendering/lib.mjs +5 -0
  358. package/dist/mjs/src/rendering/localization.d.ts +10 -0
  359. package/dist/mjs/src/rendering/localization.mjs +9 -0
  360. package/dist/mjs/src/rendering/renderers/AbstractRenderer.d.ts +68 -0
  361. package/dist/mjs/src/rendering/renderers/AbstractRenderer.mjs +144 -0
  362. package/dist/mjs/src/rendering/renderers/CanvasRenderer.d.ts +63 -0
  363. package/dist/mjs/src/rendering/renderers/CanvasRenderer.mjs +230 -0
  364. package/dist/mjs/src/rendering/renderers/DummyRenderer.d.ts +35 -0
  365. package/dist/mjs/src/rendering/renderers/DummyRenderer.mjs +106 -0
  366. package/dist/mjs/src/rendering/renderers/SVGRenderer.d.ts +57 -0
  367. package/dist/mjs/src/rendering/renderers/SVGRenderer.mjs +304 -0
  368. package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.d.ts +29 -0
  369. package/dist/mjs/src/rendering/renderers/TextOnlyRenderer.mjs +57 -0
  370. package/dist/mjs/src/testing/beforeEachFile.d.ts +1 -0
  371. package/dist/mjs/src/testing/beforeEachFile.mjs +7 -0
  372. package/dist/mjs/src/testing/createEditor.d.ts +4 -0
  373. package/dist/mjs/src/testing/createEditor.mjs +9 -0
  374. package/dist/mjs/src/testing/lib.d.ts +2 -0
  375. package/dist/mjs/src/testing/lib.mjs +2 -0
  376. package/dist/mjs/src/testing/loadExpectExtensions.d.ts +2 -0
  377. package/dist/mjs/src/testing/loadExpectExtensions.mjs +24 -0
  378. package/dist/mjs/src/testing/sendPenEvent.d.ts +12 -0
  379. package/dist/mjs/src/testing/sendPenEvent.mjs +19 -0
  380. package/dist/mjs/src/testing/sendTouchEvent.d.ts +42 -0
  381. package/dist/mjs/src/testing/sendTouchEvent.mjs +62 -0
  382. package/dist/mjs/src/toolbar/HTMLToolbar.d.ts +103 -0
  383. package/dist/mjs/src/toolbar/HTMLToolbar.mjs +376 -0
  384. package/dist/mjs/src/toolbar/IconProvider.d.ts +62 -0
  385. package/dist/mjs/src/toolbar/IconProvider.mjs +654 -0
  386. package/dist/mjs/src/toolbar/lib.d.ts +3 -0
  387. package/dist/mjs/src/toolbar/lib.mjs +3 -0
  388. package/dist/mjs/src/toolbar/localization.d.ts +49 -0
  389. package/dist/mjs/src/toolbar/localization.mjs +48 -0
  390. package/dist/mjs/src/toolbar/makeColorInput.d.ts +6 -0
  391. package/dist/mjs/src/toolbar/makeColorInput.mjs +113 -0
  392. package/dist/mjs/src/toolbar/types.d.ts +4 -0
  393. package/dist/mjs/src/toolbar/types.mjs +1 -0
  394. package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.d.ts +15 -0
  395. package/dist/mjs/src/toolbar/widgets/ActionButtonWidget.mjs +25 -0
  396. package/dist/mjs/src/toolbar/widgets/BaseToolWidget.d.ts +11 -0
  397. package/dist/mjs/src/toolbar/widgets/BaseToolWidget.mjs +44 -0
  398. package/dist/mjs/src/toolbar/widgets/BaseWidget.d.ts +72 -0
  399. package/dist/mjs/src/toolbar/widgets/BaseWidget.mjs +307 -0
  400. package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.d.ts +18 -0
  401. package/dist/mjs/src/toolbar/widgets/DocumentPropertiesWidget.mjs +120 -0
  402. package/dist/mjs/src/toolbar/widgets/EraserToolWidget.d.ts +17 -0
  403. package/dist/mjs/src/toolbar/widgets/EraserToolWidget.mjs +57 -0
  404. package/dist/mjs/src/toolbar/widgets/HandToolWidget.d.ts +17 -0
  405. package/dist/mjs/src/toolbar/widgets/HandToolWidget.mjs +172 -0
  406. package/dist/mjs/src/toolbar/widgets/InsertImageWidget.d.ts +19 -0
  407. package/dist/mjs/src/toolbar/widgets/InsertImageWidget.mjs +170 -0
  408. package/dist/mjs/src/toolbar/widgets/OverflowWidget.d.ts +25 -0
  409. package/dist/mjs/src/toolbar/widgets/OverflowWidget.mjs +71 -0
  410. package/dist/mjs/src/toolbar/widgets/PenToolWidget.d.ts +27 -0
  411. package/dist/mjs/src/toolbar/widgets/PenToolWidget.mjs +220 -0
  412. package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.d.ts +13 -0
  413. package/dist/mjs/src/toolbar/widgets/SelectionToolWidget.mjs +147 -0
  414. package/dist/mjs/src/toolbar/widgets/TextToolWidget.d.ts +16 -0
  415. package/dist/mjs/src/toolbar/widgets/TextToolWidget.mjs +109 -0
  416. package/dist/mjs/src/toolbar/widgets/lib.d.ts +10 -0
  417. package/dist/mjs/src/toolbar/widgets/lib.mjs +10 -0
  418. package/dist/mjs/src/tools/BaseTool.d.ts +22 -0
  419. package/dist/mjs/src/tools/BaseTool.mjs +63 -0
  420. package/dist/mjs/src/tools/Eraser.d.ts +23 -0
  421. package/dist/mjs/src/tools/Eraser.mjs +106 -0
  422. package/dist/mjs/src/tools/FindTool.d.ts +21 -0
  423. package/dist/mjs/src/tools/FindTool.mjs +114 -0
  424. package/dist/mjs/src/tools/PanZoom.d.ts +52 -0
  425. package/dist/mjs/src/tools/PanZoom.mjs +414 -0
  426. package/dist/mjs/src/tools/PasteHandler.d.ts +23 -0
  427. package/dist/mjs/src/tools/PasteHandler.mjs +93 -0
  428. package/dist/mjs/src/tools/Pen.d.ts +39 -0
  429. package/dist/mjs/src/tools/Pen.mjs +173 -0
  430. package/dist/mjs/src/tools/PipetteTool.d.ts +18 -0
  431. package/dist/mjs/src/tools/PipetteTool.mjs +39 -0
  432. package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.d.ts +8 -0
  433. package/dist/mjs/src/tools/SelectionTool/SelectAllShortcutHandler.mjs +22 -0
  434. package/dist/mjs/src/tools/SelectionTool/Selection.d.ts +64 -0
  435. package/dist/mjs/src/tools/SelectionTool/Selection.mjs +459 -0
  436. package/dist/mjs/src/tools/SelectionTool/SelectionHandle.d.ts +38 -0
  437. package/dist/mjs/src/tools/SelectionTool/SelectionHandle.mjs +81 -0
  438. package/dist/mjs/src/tools/SelectionTool/SelectionTool.d.ts +36 -0
  439. package/dist/mjs/src/tools/SelectionTool/SelectionTool.mjs +398 -0
  440. package/dist/mjs/src/tools/SelectionTool/TransformMode.d.ts +34 -0
  441. package/dist/mjs/src/tools/SelectionTool/TransformMode.mjs +98 -0
  442. package/dist/mjs/src/tools/SelectionTool/types.d.ts +9 -0
  443. package/dist/mjs/src/tools/SelectionTool/types.mjs +11 -0
  444. package/dist/mjs/src/tools/TextTool.d.ts +33 -0
  445. package/dist/mjs/src/tools/TextTool.mjs +256 -0
  446. package/dist/mjs/src/tools/ToolController.d.ts +18 -0
  447. package/dist/mjs/src/tools/ToolController.mjs +158 -0
  448. package/dist/mjs/src/tools/ToolEnabledGroup.d.ts +6 -0
  449. package/dist/mjs/src/tools/ToolEnabledGroup.mjs +11 -0
  450. package/dist/mjs/src/tools/ToolSwitcherShortcut.d.ts +16 -0
  451. package/dist/mjs/src/tools/ToolSwitcherShortcut.mjs +32 -0
  452. package/dist/mjs/src/tools/ToolbarShortcutHandler.d.ts +12 -0
  453. package/dist/mjs/src/tools/ToolbarShortcutHandler.mjs +23 -0
  454. package/dist/mjs/src/tools/UndoRedoShortcut.d.ts +8 -0
  455. package/dist/mjs/src/tools/UndoRedoShortcut.mjs +22 -0
  456. package/dist/mjs/src/tools/lib.d.ts +16 -0
  457. package/dist/mjs/src/tools/lib.mjs +16 -0
  458. package/dist/mjs/src/tools/localization.d.ts +28 -0
  459. package/dist/mjs/src/tools/localization.mjs +27 -0
  460. package/dist/mjs/src/types.d.ts +151 -0
  461. package/dist/mjs/src/types.mjs +35 -0
  462. package/dist/mjs/src/util/assertions.d.ts +23 -0
  463. package/dist/mjs/src/util/assertions.mjs +45 -0
  464. package/dist/mjs/src/util/fileToBase64.d.ts +3 -0
  465. package/dist/mjs/src/util/fileToBase64.mjs +13 -0
  466. package/dist/mjs/src/util/untilNextAnimationFrame.d.ts +3 -0
  467. package/dist/mjs/src/util/untilNextAnimationFrame.mjs +7 -0
  468. package/dist/mjs/src/util/waitForTimeout.d.ts +2 -0
  469. package/dist/mjs/src/util/waitForTimeout.mjs +7 -0
  470. package/package.json +1 -1
  471. package/src/Color4.test.ts +40 -0
  472. package/src/Color4.ts +236 -0
  473. package/src/Editor.css +86 -0
  474. package/src/Editor.loadFrom.test.ts +24 -0
  475. package/src/Editor.toSVG.test.ts +111 -0
  476. package/src/Editor.ts +1122 -0
  477. package/src/EditorImage.test.ts +120 -0
  478. package/src/EditorImage.ts +603 -0
  479. package/src/EventDispatcher.test.ts +123 -0
  480. package/src/EventDispatcher.ts +71 -0
  481. package/src/Pointer.ts +127 -0
  482. package/src/SVGLoader.test.ts +114 -0
  483. package/src/SVGLoader.ts +511 -0
  484. package/src/UndoRedoHistory.test.ts +33 -0
  485. package/src/UndoRedoHistory.ts +102 -0
  486. package/src/Viewport.ts +319 -0
  487. package/src/bundle/bundled.ts +7 -0
  488. package/src/commands/Command.ts +45 -0
  489. package/src/commands/Duplicate.ts +48 -0
  490. package/src/commands/Erase.ts +74 -0
  491. package/src/commands/SerializableCommand.ts +49 -0
  492. package/src/commands/UnresolvedCommand.ts +37 -0
  493. package/src/commands/invertCommand.ts +51 -0
  494. package/src/commands/lib.ts +16 -0
  495. package/src/commands/localization.ts +47 -0
  496. package/src/commands/uniteCommands.test.ts +23 -0
  497. package/src/commands/uniteCommands.ts +135 -0
  498. package/src/components/AbstractComponent.transformBy.test.ts +22 -0
  499. package/src/components/AbstractComponent.ts +364 -0
  500. package/src/components/ImageBackground.test.ts +35 -0
  501. package/src/components/ImageBackground.ts +176 -0
  502. package/src/components/ImageComponent.ts +171 -0
  503. package/src/components/RestylableComponent.ts +142 -0
  504. package/src/components/SVGGlobalAttributesObject.ts +81 -0
  505. package/src/components/Stroke.test.ts +139 -0
  506. package/src/components/Stroke.ts +245 -0
  507. package/src/components/TextComponent.test.ts +99 -0
  508. package/src/components/TextComponent.ts +315 -0
  509. package/src/components/UnknownSVGObject.test.ts +10 -0
  510. package/src/components/UnknownSVGObject.ts +60 -0
  511. package/src/components/builders/ArrowBuilder.ts +107 -0
  512. package/src/components/builders/FreehandLineBuilder.ts +212 -0
  513. package/src/components/builders/LineBuilder.ts +77 -0
  514. package/src/components/builders/PressureSensitiveFreehandLineBuilder.ts +454 -0
  515. package/src/components/builders/RectangleBuilder.ts +74 -0
  516. package/src/components/builders/types.ts +15 -0
  517. package/src/components/lib.ts +25 -0
  518. package/src/components/localization.ts +22 -0
  519. package/src/components/util/StrokeSmoother.ts +293 -0
  520. package/src/components/util/describeComponentList.ts +18 -0
  521. package/src/lib.ts +37 -0
  522. package/src/localization.ts +34 -0
  523. package/src/localizations/de.ts +98 -0
  524. package/src/localizations/en.ts +8 -0
  525. package/src/localizations/es.ts +74 -0
  526. package/src/localizations/getLocalizationTable.test.ts +27 -0
  527. package/src/localizations/getLocalizationTable.ts +55 -0
  528. package/src/math/LineSegment2.test.ts +99 -0
  529. package/src/math/LineSegment2.ts +160 -0
  530. package/src/math/Mat33.test.ts +244 -0
  531. package/src/math/Mat33.ts +437 -0
  532. package/src/math/Path.fromString.test.ts +223 -0
  533. package/src/math/Path.test.ts +198 -0
  534. package/src/math/Path.toString.test.ts +77 -0
  535. package/src/math/Path.ts +790 -0
  536. package/src/math/Rect2.test.ts +204 -0
  537. package/src/math/Rect2.ts +315 -0
  538. package/src/math/Triangle.ts +29 -0
  539. package/src/math/Vec2.test.ts +30 -0
  540. package/src/math/Vec2.ts +18 -0
  541. package/src/math/Vec3.test.ts +44 -0
  542. package/src/math/Vec3.ts +218 -0
  543. package/src/math/lib.ts +15 -0
  544. package/src/math/rounding.test.ts +65 -0
  545. package/src/math/rounding.ts +156 -0
  546. package/src/rendering/Display.ts +249 -0
  547. package/src/rendering/RenderingStyle.test.ts +68 -0
  548. package/src/rendering/RenderingStyle.ts +55 -0
  549. package/src/rendering/TextRenderingStyle.ts +45 -0
  550. package/src/rendering/caching/CacheRecord.test.ts +49 -0
  551. package/src/rendering/caching/CacheRecord.ts +77 -0
  552. package/src/rendering/caching/CacheRecordManager.ts +71 -0
  553. package/src/rendering/caching/RenderingCache.test.ts +44 -0
  554. package/src/rendering/caching/RenderingCache.ts +66 -0
  555. package/src/rendering/caching/RenderingCacheNode.ts +405 -0
  556. package/src/rendering/caching/testUtils.ts +35 -0
  557. package/src/rendering/caching/types.ts +34 -0
  558. package/src/rendering/lib.ts +6 -0
  559. package/src/rendering/localization.ts +20 -0
  560. package/src/rendering/renderers/AbstractRenderer.ts +222 -0
  561. package/src/rendering/renderers/CanvasRenderer.ts +296 -0
  562. package/src/rendering/renderers/DummyRenderer.test.ts +42 -0
  563. package/src/rendering/renderers/DummyRenderer.ts +136 -0
  564. package/src/rendering/renderers/SVGRenderer.ts +354 -0
  565. package/src/rendering/renderers/TextOnlyRenderer.ts +70 -0
  566. package/src/styles.js +7 -0
  567. package/src/testing/beforeEachFile.ts +8 -0
  568. package/src/testing/createEditor.ts +11 -0
  569. package/src/testing/global.d.ts +17 -0
  570. package/src/testing/lib.ts +3 -0
  571. package/src/testing/loadExpectExtensions.ts +25 -0
  572. package/src/testing/sendPenEvent.ts +31 -0
  573. package/src/testing/sendTouchEvent.ts +78 -0
  574. package/src/toolbar/HTMLToolbar.ts +492 -0
  575. package/src/toolbar/IconProvider.ts +736 -0
  576. package/src/toolbar/lib.ts +4 -0
  577. package/src/toolbar/localization.ts +106 -0
  578. package/src/toolbar/makeColorInput.ts +145 -0
  579. package/src/toolbar/toolbar.css +213 -0
  580. package/src/toolbar/types.ts +5 -0
  581. package/src/toolbar/widgets/ActionButtonWidget.ts +39 -0
  582. package/src/toolbar/widgets/BaseToolWidget.ts +56 -0
  583. package/src/toolbar/widgets/BaseWidget.ts +377 -0
  584. package/src/toolbar/widgets/DocumentPropertiesWidget.ts +167 -0
  585. package/src/toolbar/widgets/EraserToolWidget.ts +85 -0
  586. package/src/toolbar/widgets/HandToolWidget.ts +250 -0
  587. package/src/toolbar/widgets/InsertImageWidget.css +44 -0
  588. package/src/toolbar/widgets/InsertImageWidget.ts +223 -0
  589. package/src/toolbar/widgets/OverflowWidget.css +27 -0
  590. package/src/toolbar/widgets/OverflowWidget.ts +92 -0
  591. package/src/toolbar/widgets/PenToolWidget.ts +288 -0
  592. package/src/toolbar/widgets/SelectionToolWidget.ts +190 -0
  593. package/src/toolbar/widgets/TextToolWidget.ts +145 -0
  594. package/src/toolbar/widgets/lib.ts +13 -0
  595. package/src/tools/BaseTool.ts +76 -0
  596. package/src/tools/Eraser.test.ts +103 -0
  597. package/src/tools/Eraser.ts +139 -0
  598. package/src/tools/FindTool.css +7 -0
  599. package/src/tools/FindTool.ts +152 -0
  600. package/src/tools/PanZoom.test.ts +310 -0
  601. package/src/tools/PanZoom.ts +520 -0
  602. package/src/tools/PasteHandler.ts +95 -0
  603. package/src/tools/Pen.test.ts +194 -0
  604. package/src/tools/Pen.ts +226 -0
  605. package/src/tools/PipetteTool.ts +55 -0
  606. package/src/tools/SelectionTool/SelectAllShortcutHandler.ts +28 -0
  607. package/src/tools/SelectionTool/Selection.ts +607 -0
  608. package/src/tools/SelectionTool/SelectionHandle.ts +108 -0
  609. package/src/tools/SelectionTool/SelectionTool.css +23 -0
  610. package/src/tools/SelectionTool/SelectionTool.test.ts +261 -0
  611. package/src/tools/SelectionTool/SelectionTool.ts +480 -0
  612. package/src/tools/SelectionTool/TransformMode.ts +114 -0
  613. package/src/tools/SelectionTool/types.ts +11 -0
  614. package/src/tools/TextTool.ts +326 -0
  615. package/src/tools/ToolController.ts +178 -0
  616. package/src/tools/ToolEnabledGroup.ts +14 -0
  617. package/src/tools/ToolSwitcherShortcut.ts +39 -0
  618. package/src/tools/ToolbarShortcutHandler.ts +34 -0
  619. package/src/tools/UndoRedoShortcut.test.ts +56 -0
  620. package/src/tools/UndoRedoShortcut.ts +25 -0
  621. package/src/tools/lib.ts +21 -0
  622. package/src/tools/localization.ts +66 -0
  623. package/src/types.ts +234 -0
  624. package/src/util/assertions.ts +55 -0
  625. package/src/util/fileToBase64.ts +18 -0
  626. package/src/util/untilNextAnimationFrame.ts +9 -0
  627. package/src/util/waitForTimeout.ts +9 -0
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const LineSegment2_1 = __importDefault(require("../math/LineSegment2"));
7
+ const Mat33_1 = __importDefault(require("../math/Mat33"));
8
+ const Rect2_1 = __importDefault(require("../math/Rect2"));
9
+ const Vec2_1 = require("../math/Vec2");
10
+ const TextRenderingStyle_1 = require("../rendering/TextRenderingStyle");
11
+ const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
12
+ const RestylableComponent_1 = require("./RestylableComponent");
13
+ const componentTypeId = 'text';
14
+ class TextComponent extends AbstractComponent_1.default {
15
+ constructor(textObjects, transform, style) {
16
+ super(componentTypeId);
17
+ this.textObjects = textObjects;
18
+ this.transform = transform;
19
+ this.style = style;
20
+ // eslint-disable-next-line @typescript-eslint/prefer-as-const
21
+ this.isRestylableComponent = true;
22
+ this.recomputeBBox();
23
+ // If this has no direct children, choose a style representative of this' content
24
+ // (useful for estimating the style of the TextComponent).
25
+ const hasDirectContent = textObjects.some(obj => typeof obj === 'string');
26
+ if (!hasDirectContent && textObjects.length > 0) {
27
+ this.style = textObjects[0].getTextStyle();
28
+ }
29
+ }
30
+ static applyTextStyles(ctx, style) {
31
+ var _a, _b;
32
+ // Quote the font family if necessary.
33
+ const fontFamily = style.fontFamily.match(/\s/) ? style.fontFamily.replace(/["]/g, '\\"') : style.fontFamily;
34
+ ctx.font = [
35
+ ((_a = style.size) !== null && _a !== void 0 ? _a : 12) + 'px',
36
+ (_b = style.fontWeight) !== null && _b !== void 0 ? _b : '',
37
+ `${fontFamily}`,
38
+ style.fontWeight
39
+ ].join(' ');
40
+ ctx.textAlign = 'left';
41
+ }
42
+ // Roughly estimate the bounding box of `text`. Use if no CanvasRenderingContext2D is available.
43
+ static estimateTextDimens(text, style) {
44
+ const widthEst = text.length * style.size;
45
+ const heightEst = style.size;
46
+ // Text is drawn with (0, 0) as its baseline. As such, the majority of the text's height should
47
+ // be above (0, 0).
48
+ return new Rect2_1.default(0, -heightEst * 2 / 3, widthEst, heightEst);
49
+ }
50
+ // Returns the bounding box of `text`. This is approximate if no Canvas is available.
51
+ static getTextDimens(text, style) {
52
+ var _a, _b;
53
+ (_a = TextComponent.textMeasuringCtx) !== null && _a !== void 0 ? _a : (TextComponent.textMeasuringCtx = (_b = document.createElement('canvas').getContext('2d')) !== null && _b !== void 0 ? _b : null);
54
+ if (!TextComponent.textMeasuringCtx) {
55
+ return this.estimateTextDimens(text, style);
56
+ }
57
+ const ctx = TextComponent.textMeasuringCtx;
58
+ TextComponent.applyTextStyles(ctx, style);
59
+ const measure = ctx.measureText(text);
60
+ // Text is drawn with (0,0) at the bottom left of the baseline.
61
+ const textY = -measure.actualBoundingBoxAscent;
62
+ const textHeight = measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent;
63
+ return new Rect2_1.default(0, textY, measure.width, textHeight);
64
+ }
65
+ computeBBoxOfPart(part) {
66
+ if (typeof part === 'string') {
67
+ const textBBox = TextComponent.getTextDimens(part, this.style);
68
+ return textBBox.transformedBoundingBox(this.transform);
69
+ }
70
+ else {
71
+ const bbox = part.contentBBox.transformedBoundingBox(this.transform);
72
+ return bbox;
73
+ }
74
+ }
75
+ recomputeBBox() {
76
+ let bbox = null;
77
+ for (const textObject of this.textObjects) {
78
+ const currentBBox = this.computeBBoxOfPart(textObject);
79
+ bbox !== null && bbox !== void 0 ? bbox : (bbox = currentBBox);
80
+ bbox = bbox.union(currentBBox);
81
+ }
82
+ this.contentBBox = bbox !== null && bbox !== void 0 ? bbox : Rect2_1.default.empty;
83
+ }
84
+ renderInternal(canvas) {
85
+ const cursor = this.transform;
86
+ for (const textObject of this.textObjects) {
87
+ if (typeof textObject === 'string') {
88
+ canvas.drawText(textObject, cursor, this.style);
89
+ }
90
+ else {
91
+ canvas.pushTransform(cursor);
92
+ textObject.renderInternal(canvas);
93
+ canvas.popTransform();
94
+ }
95
+ }
96
+ }
97
+ render(canvas, _visibleRect) {
98
+ canvas.startObject(this.contentBBox);
99
+ this.renderInternal(canvas);
100
+ canvas.endObject(this.getLoadSaveData());
101
+ }
102
+ getProportionalRenderingTime() {
103
+ return this.textObjects.length;
104
+ }
105
+ intersects(lineSegment) {
106
+ // Convert canvas space to internal space.
107
+ const invTransform = this.transform.inverse();
108
+ const p1InThisSpace = invTransform.transformVec2(lineSegment.p1);
109
+ const p2InThisSpace = invTransform.transformVec2(lineSegment.p2);
110
+ lineSegment = new LineSegment2_1.default(p1InThisSpace, p2InThisSpace);
111
+ for (const subObject of this.textObjects) {
112
+ if (typeof subObject === 'string') {
113
+ const textBBox = TextComponent.getTextDimens(subObject, this.style);
114
+ // TODO: Use a better intersection check. Perhaps draw the text onto a CanvasElement and
115
+ // use pixel-testing to check for intersection with its contour.
116
+ if (textBBox.getEdges().some(edge => lineSegment.intersection(edge) !== null)) {
117
+ return true;
118
+ }
119
+ }
120
+ else {
121
+ if (subObject.intersects(lineSegment)) {
122
+ return true;
123
+ }
124
+ }
125
+ }
126
+ return false;
127
+ }
128
+ getStyle() {
129
+ return {
130
+ color: this.style.renderingStyle.fill,
131
+ // Make a copy
132
+ textStyle: Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign({}, this.style.renderingStyle) }),
133
+ };
134
+ }
135
+ updateStyle(style) {
136
+ return (0, RestylableComponent_1.createRestyleComponentCommand)(this.getStyle(), style, this);
137
+ }
138
+ forceStyle(style, editor) {
139
+ if (style.textStyle) {
140
+ this.style = (0, TextRenderingStyle_1.cloneTextStyle)(style.textStyle);
141
+ }
142
+ else if (style.color) {
143
+ this.style = Object.assign(Object.assign({}, this.style), { renderingStyle: Object.assign(Object.assign({}, this.style.renderingStyle), { fill: style.color }) });
144
+ }
145
+ else {
146
+ return;
147
+ }
148
+ for (const child of this.textObjects) {
149
+ if (child instanceof TextComponent) {
150
+ child.forceStyle(style, editor);
151
+ }
152
+ }
153
+ if (editor) {
154
+ editor.image.queueRerenderOf(this);
155
+ editor.queueRerender();
156
+ }
157
+ }
158
+ // See this.getStyle
159
+ getTextStyle() {
160
+ return (0, TextRenderingStyle_1.cloneTextStyle)(this.style);
161
+ }
162
+ getBaselinePos() {
163
+ return this.transform.transformVec2(Vec2_1.Vec2.zero);
164
+ }
165
+ getTransform() {
166
+ return this.transform;
167
+ }
168
+ applyTransformation(affineTransfm) {
169
+ this.transform = affineTransfm.rightMul(this.transform);
170
+ this.recomputeBBox();
171
+ }
172
+ createClone() {
173
+ const clonedTextObjects = this.textObjects.map(obj => {
174
+ if (typeof obj === 'string') {
175
+ return obj;
176
+ }
177
+ else {
178
+ return obj.createClone();
179
+ }
180
+ });
181
+ return new TextComponent(clonedTextObjects, this.transform, this.style);
182
+ }
183
+ getText() {
184
+ const result = [];
185
+ for (const textObject of this.textObjects) {
186
+ if (typeof textObject === 'string') {
187
+ result.push(textObject);
188
+ }
189
+ else {
190
+ result.push(textObject.getText());
191
+ }
192
+ }
193
+ return result.join('\n');
194
+ }
195
+ description(localizationTable) {
196
+ return localizationTable.text(this.getText());
197
+ }
198
+ // Do not rely on the output of `serializeToJSON` taking any particular format.
199
+ serializeToJSON() {
200
+ const serializableStyle = (0, TextRenderingStyle_1.textStyleToJSON)(this.style);
201
+ const serializedTextObjects = this.textObjects.map(text => {
202
+ if (typeof text === 'string') {
203
+ return {
204
+ text,
205
+ };
206
+ }
207
+ else {
208
+ return {
209
+ json: text.serializeToJSON(),
210
+ };
211
+ }
212
+ });
213
+ return {
214
+ textObjects: serializedTextObjects,
215
+ transform: this.transform.toArray(),
216
+ style: serializableStyle,
217
+ };
218
+ }
219
+ // @internal
220
+ static deserializeFromString(json) {
221
+ if (typeof json === 'string') {
222
+ json = JSON.parse(json);
223
+ }
224
+ const style = (0, TextRenderingStyle_1.textStyleFromJSON)(json.style);
225
+ const textObjects = json.textObjects.map((data) => {
226
+ var _a;
227
+ if (((_a = data.text) !== null && _a !== void 0 ? _a : null) !== null) {
228
+ return data.text;
229
+ }
230
+ return TextComponent.deserializeFromString(data.json);
231
+ });
232
+ json.transform = json.transform.filter((elem) => typeof elem === 'number');
233
+ if (json.transform.length !== 9) {
234
+ throw new Error(`Unable to deserialize transform, ${json.transform}.`);
235
+ }
236
+ const transformData = json.transform;
237
+ const transform = new Mat33_1.default(...transformData);
238
+ return new TextComponent(textObjects, transform, style);
239
+ }
240
+ static fromLines(lines, transform, style) {
241
+ let lastComponent = null;
242
+ const components = [];
243
+ for (const line of lines) {
244
+ let position = Vec2_1.Vec2.zero;
245
+ if (lastComponent) {
246
+ const lineMargin = Math.floor(style.size);
247
+ position = lastComponent.getBBox().bottomLeft.plus(Vec2_1.Vec2.unitY.times(lineMargin));
248
+ }
249
+ const component = new TextComponent([line], Mat33_1.default.translation(position), style);
250
+ components.push(component);
251
+ lastComponent = component;
252
+ }
253
+ return new TextComponent(components, transform, style);
254
+ }
255
+ }
256
+ exports.default = TextComponent;
257
+ TextComponent.textMeasuringCtx = null;
258
+ AbstractComponent_1.default.registerComponent(componentTypeId, (data) => TextComponent.deserializeFromString(data));
@@ -0,0 +1,18 @@
1
+ import LineSegment2 from '../math/LineSegment2';
2
+ import Mat33 from '../math/Mat33';
3
+ import Rect2 from '../math/Rect2';
4
+ import AbstractRenderer from '../rendering/renderers/AbstractRenderer';
5
+ import AbstractComponent from './AbstractComponent';
6
+ import { ImageComponentLocalization } from './localization';
7
+ export default class UnknownSVGObject extends AbstractComponent {
8
+ private svgObject;
9
+ protected contentBBox: Rect2;
10
+ constructor(svgObject: SVGElement);
11
+ render(canvas: AbstractRenderer, _visibleRect?: Rect2): void;
12
+ intersects(lineSegment: LineSegment2): boolean;
13
+ protected applyTransformation(_affineTransfm: Mat33): void;
14
+ isSelectable(): boolean;
15
+ protected createClone(): AbstractComponent;
16
+ description(localization: ImageComponentLocalization): string;
17
+ protected serializeToJSON(): string | null;
18
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ //
3
+ // Stores objects loaded from an SVG that aren't recognised by the editor.
4
+ // @internal
5
+ // @packageDocumentation
6
+ //
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const Rect2_1 = __importDefault(require("../math/Rect2"));
12
+ const SVGRenderer_1 = __importDefault(require("../rendering/renderers/SVGRenderer"));
13
+ const AbstractComponent_1 = __importDefault(require("./AbstractComponent"));
14
+ const componentId = 'unknown-svg-object';
15
+ class UnknownSVGObject extends AbstractComponent_1.default {
16
+ constructor(svgObject) {
17
+ super(componentId);
18
+ this.svgObject = svgObject;
19
+ this.contentBBox = Rect2_1.default.of(svgObject.getBoundingClientRect());
20
+ }
21
+ render(canvas, _visibleRect) {
22
+ if (!(canvas instanceof SVGRenderer_1.default)) {
23
+ // Don't draw unrenderable objects if we can't
24
+ return;
25
+ }
26
+ canvas.drawSVGElem(this.svgObject);
27
+ }
28
+ intersects(lineSegment) {
29
+ return this.contentBBox.getEdges().some(edge => edge.intersection(lineSegment) !== null);
30
+ }
31
+ applyTransformation(_affineTransfm) {
32
+ }
33
+ isSelectable() {
34
+ return false;
35
+ }
36
+ createClone() {
37
+ return new UnknownSVGObject(this.svgObject.cloneNode(true));
38
+ }
39
+ description(localization) {
40
+ return localization.svgObject;
41
+ }
42
+ serializeToJSON() {
43
+ return JSON.stringify({
44
+ html: this.svgObject.outerHTML,
45
+ });
46
+ }
47
+ }
48
+ exports.default = UnknownSVGObject;
49
+ // null: Do not deserialize UnknownSVGObjects.
50
+ AbstractComponent_1.default.registerComponent(componentId, null);
@@ -0,0 +1,19 @@
1
+ import Rect2 from '../../math/Rect2';
2
+ import AbstractRenderer from '../../rendering/renderers/AbstractRenderer';
3
+ import { StrokeDataPoint } from '../../types';
4
+ import Viewport from '../../Viewport';
5
+ import AbstractComponent from '../AbstractComponent';
6
+ import { ComponentBuilder, ComponentBuilderFactory } from './types';
7
+ export declare const makeArrowBuilder: ComponentBuilderFactory;
8
+ export default class ArrowBuilder implements ComponentBuilder {
9
+ private readonly startPoint;
10
+ private readonly viewport;
11
+ private endPoint;
12
+ constructor(startPoint: StrokeDataPoint, viewport: Viewport);
13
+ private getLineWidth;
14
+ getBBox(): Rect2;
15
+ private buildPreview;
16
+ build(): AbstractComponent;
17
+ preview(renderer: AbstractRenderer): void;
18
+ addPoint(point: StrokeDataPoint): void;
19
+ }
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.makeArrowBuilder = void 0;
30
+ const Path_1 = __importStar(require("../../math/Path"));
31
+ const Stroke_1 = __importDefault(require("../Stroke"));
32
+ const makeArrowBuilder = (initialPoint, viewport) => {
33
+ return new ArrowBuilder(initialPoint, viewport);
34
+ };
35
+ exports.makeArrowBuilder = makeArrowBuilder;
36
+ class ArrowBuilder {
37
+ constructor(startPoint, viewport) {
38
+ this.startPoint = startPoint;
39
+ this.viewport = viewport;
40
+ this.endPoint = startPoint;
41
+ }
42
+ getLineWidth() {
43
+ return Math.max(this.endPoint.width, this.startPoint.width);
44
+ }
45
+ getBBox() {
46
+ const preview = this.buildPreview();
47
+ return preview.getBBox();
48
+ }
49
+ buildPreview() {
50
+ const lineStartPoint = this.startPoint.pos;
51
+ const endPoint = this.endPoint.pos;
52
+ const toEnd = endPoint.minus(lineStartPoint).normalized();
53
+ const arrowLength = endPoint.minus(lineStartPoint).length();
54
+ // Ensure that the arrow tip is smaller than the arrow.
55
+ const arrowTipSize = Math.min(this.getLineWidth(), arrowLength / 2);
56
+ const startSize = this.startPoint.width / 2;
57
+ const endSize = this.endPoint.width / 2;
58
+ const arrowTipBase = endPoint.minus(toEnd.times(arrowTipSize));
59
+ // Scaled normal vectors.
60
+ const lineNormal = toEnd.orthog();
61
+ const scaledStartNormal = lineNormal.times(startSize);
62
+ const scaledBaseNormal = lineNormal.times(endSize);
63
+ const path = new Path_1.default(arrowTipBase.minus(scaledBaseNormal), [
64
+ // Stem
65
+ {
66
+ kind: Path_1.PathCommandType.LineTo,
67
+ point: lineStartPoint.minus(scaledStartNormal),
68
+ },
69
+ {
70
+ kind: Path_1.PathCommandType.LineTo,
71
+ point: lineStartPoint.plus(scaledStartNormal),
72
+ },
73
+ {
74
+ kind: Path_1.PathCommandType.LineTo,
75
+ point: arrowTipBase.plus(scaledBaseNormal),
76
+ },
77
+ // Head
78
+ {
79
+ kind: Path_1.PathCommandType.LineTo,
80
+ point: arrowTipBase.plus(lineNormal.times(arrowTipSize).plus(scaledBaseNormal)),
81
+ },
82
+ {
83
+ kind: Path_1.PathCommandType.LineTo,
84
+ point: endPoint.plus(toEnd.times(endSize)),
85
+ },
86
+ {
87
+ kind: Path_1.PathCommandType.LineTo,
88
+ point: arrowTipBase.plus(lineNormal.times(-arrowTipSize).minus(scaledBaseNormal)),
89
+ },
90
+ {
91
+ kind: Path_1.PathCommandType.LineTo,
92
+ point: arrowTipBase.minus(scaledBaseNormal),
93
+ },
94
+ // Round all points in the arrow (to remove unnecessary decimal places)
95
+ ]).mapPoints(point => this.viewport.roundPoint(point));
96
+ const preview = new Stroke_1.default([
97
+ {
98
+ startPoint: path.startPoint,
99
+ commands: path.parts,
100
+ style: {
101
+ fill: this.startPoint.color,
102
+ }
103
+ }
104
+ ]);
105
+ return preview;
106
+ }
107
+ build() {
108
+ return this.buildPreview();
109
+ }
110
+ preview(renderer) {
111
+ this.buildPreview().render(renderer);
112
+ }
113
+ addPoint(point) {
114
+ this.endPoint = point;
115
+ }
116
+ }
117
+ exports.default = ArrowBuilder;
@@ -0,0 +1,33 @@
1
+ import AbstractRenderer, { RenderablePathSpec } from '../../rendering/renderers/AbstractRenderer';
2
+ import Rect2 from '../../math/Rect2';
3
+ import Stroke from '../Stroke';
4
+ import Viewport from '../../Viewport';
5
+ import { StrokeDataPoint } from '../../types';
6
+ import { ComponentBuilder, ComponentBuilderFactory } from './types';
7
+ import RenderingStyle from '../../rendering/RenderingStyle';
8
+ export declare const makeFreehandLineBuilder: ComponentBuilderFactory;
9
+ export default class FreehandLineBuilder implements ComponentBuilder {
10
+ private startPoint;
11
+ private minFitAllowed;
12
+ private viewport;
13
+ private isFirstSegment;
14
+ private parts;
15
+ private curveFitter;
16
+ private bbox;
17
+ private averageWidth;
18
+ private widthAverageNumSamples;
19
+ constructor(startPoint: StrokeDataPoint, minFitAllowed: number, maxFitAllowed: number, viewport: Viewport);
20
+ getBBox(): Rect2;
21
+ protected getRenderingStyle(): RenderingStyle;
22
+ protected previewCurrentPath(): RenderablePathSpec | null;
23
+ protected previewFullPath(): RenderablePathSpec[] | null;
24
+ private previewStroke;
25
+ preview(renderer: AbstractRenderer): void;
26
+ build(): Stroke;
27
+ private getMinFit;
28
+ private roundPoint;
29
+ private roundDistance;
30
+ private curveToPathCommands;
31
+ private addCurve;
32
+ addPoint(newPoint: StrokeDataPoint): void;
33
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.makeFreehandLineBuilder = void 0;
7
+ const Vec2_1 = require("../../math/Vec2");
8
+ const Rect2_1 = __importDefault(require("../../math/Rect2"));
9
+ const Path_1 = require("../../math/Path");
10
+ const Stroke_1 = __importDefault(require("../Stroke"));
11
+ const Viewport_1 = __importDefault(require("../../Viewport"));
12
+ const StrokeSmoother_1 = require("../util/StrokeSmoother");
13
+ const Color4_1 = __importDefault(require("../../Color4"));
14
+ const makeFreehandLineBuilder = (initialPoint, viewport) => {
15
+ // Don't smooth if input is more than ± 3 pixels from the true curve, do smooth if
16
+ // less than ±1 px from the curve.
17
+ const maxSmoothingDist = viewport.getSizeOfPixelOnCanvas() * 3;
18
+ const minSmoothingDist = viewport.getSizeOfPixelOnCanvas();
19
+ return new FreehandLineBuilder(initialPoint, minSmoothingDist, maxSmoothingDist, viewport);
20
+ };
21
+ exports.makeFreehandLineBuilder = makeFreehandLineBuilder;
22
+ // Handles stroke smoothing and creates Strokes from user/stylus input.
23
+ class FreehandLineBuilder {
24
+ constructor(startPoint, minFitAllowed, maxFitAllowed, viewport) {
25
+ this.startPoint = startPoint;
26
+ this.minFitAllowed = minFitAllowed;
27
+ this.viewport = viewport;
28
+ this.isFirstSegment = true;
29
+ this.parts = [];
30
+ this.widthAverageNumSamples = 1;
31
+ this.curveFitter = new StrokeSmoother_1.StrokeSmoother(startPoint, minFitAllowed, maxFitAllowed, (curve) => this.addCurve(curve));
32
+ this.averageWidth = startPoint.width;
33
+ this.bbox = new Rect2_1.default(this.startPoint.pos.x, this.startPoint.pos.y, 0, 0);
34
+ }
35
+ getBBox() {
36
+ return this.bbox;
37
+ }
38
+ getRenderingStyle() {
39
+ return {
40
+ fill: Color4_1.default.transparent,
41
+ stroke: {
42
+ color: this.startPoint.color,
43
+ width: this.roundDistance(this.averageWidth),
44
+ }
45
+ };
46
+ }
47
+ previewCurrentPath() {
48
+ const path = this.parts.slice();
49
+ const commands = [...path, ...this.curveToPathCommands(this.curveFitter.preview())];
50
+ const startPoint = this.startPoint.pos;
51
+ return {
52
+ startPoint,
53
+ commands,
54
+ style: this.getRenderingStyle(),
55
+ };
56
+ }
57
+ previewFullPath() {
58
+ const preview = this.previewCurrentPath();
59
+ if (preview) {
60
+ return [preview];
61
+ }
62
+ return null;
63
+ }
64
+ previewStroke() {
65
+ const pathPreview = this.previewFullPath();
66
+ if (pathPreview) {
67
+ return new Stroke_1.default(pathPreview);
68
+ }
69
+ return null;
70
+ }
71
+ preview(renderer) {
72
+ const paths = this.previewFullPath();
73
+ if (paths) {
74
+ const approxBBox = this.viewport.visibleRect;
75
+ renderer.startObject(approxBBox);
76
+ for (const path of paths) {
77
+ renderer.drawPath(path);
78
+ }
79
+ renderer.endObject();
80
+ }
81
+ }
82
+ build() {
83
+ this.curveFitter.finalizeCurrentCurve();
84
+ return this.previewStroke();
85
+ }
86
+ getMinFit() {
87
+ let minFit = Math.min(this.minFitAllowed, this.averageWidth / 3);
88
+ if (minFit < 1e-10) {
89
+ minFit = this.minFitAllowed;
90
+ }
91
+ return minFit;
92
+ }
93
+ roundPoint(point) {
94
+ const minFit = this.getMinFit();
95
+ return Viewport_1.default.roundPoint(point, minFit);
96
+ }
97
+ roundDistance(dist) {
98
+ const minFit = this.getMinFit();
99
+ return Viewport_1.default.roundPoint(dist, minFit);
100
+ }
101
+ curveToPathCommands(curve) {
102
+ // Case where no points have been added
103
+ if (!curve) {
104
+ // Don't create a circle around the initial point if the stroke has more than one point.
105
+ if (!this.isFirstSegment) {
106
+ return [];
107
+ }
108
+ // Make the circle small -- because of the stroke style, we'll be drawing a stroke around it.
109
+ const width = Viewport_1.default.roundPoint(this.averageWidth / 10, Math.min(this.minFitAllowed, this.averageWidth / 10));
110
+ const center = this.roundPoint(this.startPoint.pos);
111
+ // Start on the right, cycle clockwise:
112
+ // |
113
+ // ----- ←
114
+ // |
115
+ // Draw a circle-ish shape around the start point
116
+ return [
117
+ {
118
+ kind: Path_1.PathCommandType.QuadraticBezierTo,
119
+ controlPoint: center.plus(Vec2_1.Vec2.of(width, width)),
120
+ // Bottom of the circle
121
+ // |
122
+ // -----
123
+ // |
124
+ // ↑
125
+ endPoint: center.plus(Vec2_1.Vec2.of(0, width)),
126
+ },
127
+ {
128
+ kind: Path_1.PathCommandType.QuadraticBezierTo,
129
+ controlPoint: center.plus(Vec2_1.Vec2.of(-width, width)),
130
+ endPoint: center.plus(Vec2_1.Vec2.of(-width, 0)),
131
+ },
132
+ {
133
+ kind: Path_1.PathCommandType.QuadraticBezierTo,
134
+ controlPoint: center.plus(Vec2_1.Vec2.of(-width, -width)),
135
+ endPoint: center.plus(Vec2_1.Vec2.of(0, -width)),
136
+ },
137
+ {
138
+ kind: Path_1.PathCommandType.QuadraticBezierTo,
139
+ controlPoint: center.plus(Vec2_1.Vec2.of(width, -width)),
140
+ endPoint: center.plus(Vec2_1.Vec2.of(width, 0)),
141
+ }
142
+ ];
143
+ }
144
+ const result = [];
145
+ if (this.isFirstSegment) {
146
+ result.push({
147
+ kind: Path_1.PathCommandType.MoveTo,
148
+ point: this.roundPoint(curve.startPoint),
149
+ });
150
+ }
151
+ result.push({
152
+ kind: Path_1.PathCommandType.QuadraticBezierTo,
153
+ controlPoint: this.roundPoint(curve.controlPoint),
154
+ endPoint: this.roundPoint(curve.endPoint),
155
+ });
156
+ return result;
157
+ }
158
+ addCurve(curve) {
159
+ const parts = this.curveToPathCommands(curve);
160
+ this.parts.push(...parts);
161
+ if (this.isFirstSegment) {
162
+ this.isFirstSegment = false;
163
+ }
164
+ }
165
+ addPoint(newPoint) {
166
+ this.curveFitter.addPoint(newPoint);
167
+ this.widthAverageNumSamples++;
168
+ this.averageWidth =
169
+ this.averageWidth * (this.widthAverageNumSamples - 1) / this.widthAverageNumSamples
170
+ + newPoint.width / this.widthAverageNumSamples;
171
+ }
172
+ }
173
+ exports.default = FreehandLineBuilder;