paper 0.17.0 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/LICENSE.txt +1 -1
  3. package/MIGRATION.md +402 -0
  4. package/README.md +137 -143
  5. package/dist/esm/anim/Tween.js +404 -0
  6. package/dist/esm/basic/Line.js +252 -0
  7. package/dist/esm/basic/Matrix.js +603 -0
  8. package/dist/esm/basic/Point.js +738 -0
  9. package/dist/esm/basic/Rectangle.js +788 -0
  10. package/dist/esm/basic/Size.js +368 -0
  11. package/dist/esm/boolean/graph.js +950 -0
  12. package/dist/esm/boolean/index.js +143 -0
  13. package/dist/esm/boolean/operations.js +94 -0
  14. package/dist/esm/boolean/split.js +89 -0
  15. package/dist/esm/canvas/blendModes.js +115 -0
  16. package/dist/esm/canvas/canvasProvider.js +102 -0
  17. package/dist/esm/constants.js +130 -0
  18. package/dist/esm/core/Base.js +52 -0
  19. package/dist/esm/core/Emitter.js +215 -0
  20. package/dist/esm/core/features.js +53 -0
  21. package/dist/esm/core/serialization.js +174 -0
  22. package/dist/esm/core.js +15 -0
  23. package/dist/esm/dom/domElement.js +112 -0
  24. package/dist/esm/dom/domEvent.js +106 -0
  25. package/dist/esm/env.js +66 -0
  26. package/dist/esm/event/DrawEvent.js +38 -0
  27. package/dist/esm/event/Event.js +79 -0
  28. package/dist/esm/event/Key.js +236 -0
  29. package/dist/esm/event/KeyEvent.js +39 -0
  30. package/dist/esm/event/MouseEvent.js +91 -0
  31. package/dist/esm/hosted/HostItem.js +60 -0
  32. package/dist/esm/hosted/Hosting.js +1061 -0
  33. package/dist/esm/hosted/index.js +20 -0
  34. package/dist/esm/index.js +38 -0
  35. package/dist/esm/internal.js +115 -0
  36. package/dist/esm/item/Effect.js +256 -0
  37. package/dist/esm/item/EffectInstance.js +184 -0
  38. package/dist/esm/item/Group.js +293 -0
  39. package/dist/esm/item/HitResult.js +126 -0
  40. package/dist/esm/item/Item.js +3339 -0
  41. package/dist/esm/item/ItemDefinition.js +95 -0
  42. package/dist/esm/item/Layer.js +69 -0
  43. package/dist/esm/item/Project.js +1013 -0
  44. package/dist/esm/item/Raster.js +722 -0
  45. package/dist/esm/item/Shape.js +355 -0
  46. package/dist/esm/item/SymbolDefinition.js +68 -0
  47. package/dist/esm/item/SymbolItem.js +131 -0
  48. package/dist/esm/item/bounds.js +324 -0
  49. package/dist/esm/item/draw.js +525 -0
  50. package/dist/esm/item/effects.js +124 -0
  51. package/dist/esm/item/expand.js +87 -0
  52. package/dist/esm/item/hitTest.js +203 -0
  53. package/dist/esm/item/hosting.js +12 -0
  54. package/dist/esm/item/props.js +12 -0
  55. package/dist/esm/item/query.js +139 -0
  56. package/dist/esm/item/sampling.js +67 -0
  57. package/dist/esm/item/transform.js +128 -0
  58. package/dist/esm/net/http.js +26 -0
  59. package/dist/esm/node/CanvasAdapter.js +137 -0
  60. package/dist/esm/node/index.js +150 -0
  61. package/dist/esm/node/peers.js +27 -0
  62. package/dist/esm/offset/curves.js +866 -0
  63. package/dist/esm/offset/index.js +70 -0
  64. package/dist/esm/offset/offset.js +178 -0
  65. package/dist/esm/offset/outline.js +91 -0
  66. package/dist/esm/offset/pen.js +298 -0
  67. package/dist/esm/offset/profile.js +772 -0
  68. package/dist/esm/offset/round.js +213 -0
  69. package/dist/esm/offset/sweep.js +100 -0
  70. package/dist/esm/paperscript/PaperScript.js +832 -0
  71. package/dist/esm/paperscript/autoload.js +27 -0
  72. package/dist/esm/paperscript/index.js +17 -0
  73. package/dist/esm/path/CompoundPath.js +367 -0
  74. package/dist/esm/path/Curve.js +996 -0
  75. package/dist/esm/path/CurveLocation.js +462 -0
  76. package/dist/esm/path/Path.js +1761 -0
  77. package/dist/esm/path/PathFlattener.js +186 -0
  78. package/dist/esm/path/PathItem.js +757 -0
  79. package/dist/esm/path/Segment.js +640 -0
  80. package/dist/esm/path/SegmentPoint.js +106 -0
  81. package/dist/esm/path/StrokeProfile.js +387 -0
  82. package/dist/esm/path/StrokeProfileStop.js +207 -0
  83. package/dist/esm/path/boolean.js +284 -0
  84. package/dist/esm/path/bounds.js +257 -0
  85. package/dist/esm/path/crossing.js +114 -0
  86. package/dist/esm/path/draw.js +161 -0
  87. package/dist/esm/path/hitTest.js +259 -0
  88. package/dist/esm/path/offset.js +152 -0
  89. package/dist/esm/path/shapes.js +231 -0
  90. package/dist/esm/path/smooth.js +84 -0
  91. package/dist/esm/path/values.js +40 -0
  92. package/dist/esm/scope/PaperScope.js +288 -0
  93. package/dist/esm/scope/PaperScopeItem.js +74 -0
  94. package/dist/esm/smoothing/index.js +71 -0
  95. package/dist/esm/style/Color.js +917 -0
  96. package/dist/esm/style/Gradient.js +191 -0
  97. package/dist/esm/style/GradientStop.js +168 -0
  98. package/dist/esm/style/PatternDefinition.js +383 -0
  99. package/dist/esm/style/Style.js +503 -0
  100. package/dist/esm/svg/index.js +27 -0
  101. package/dist/esm/svg/svgElement.js +97 -0
  102. package/dist/esm/svg/svgExport.js +847 -0
  103. package/dist/esm/svg/svgImport.js +1101 -0
  104. package/dist/esm/svg/svgStyles.js +96 -0
  105. package/dist/esm/text/AreaText.js +190 -0
  106. package/dist/esm/text/PathText.js +111 -0
  107. package/dist/esm/text/PointText.js +92 -0
  108. package/dist/esm/text/TextItem.js +538 -0
  109. package/dist/esm/text/TextRange.js +169 -0
  110. package/dist/esm/text/TextStory.js +394 -0
  111. package/dist/esm/text/areaLayout.js +439 -0
  112. package/dist/esm/text/layout.js +265 -0
  113. package/dist/esm/text/measure.js +57 -0
  114. package/dist/esm/text/pathLayout.js +93 -0
  115. package/dist/esm/tool/Tool.js +284 -0
  116. package/dist/esm/tool/ToolEvent.js +232 -0
  117. package/dist/esm/util/Formatter.js +57 -0
  118. package/dist/esm/util/collisions.js +216 -0
  119. package/dist/esm/util/list.js +110 -0
  120. package/dist/esm/util/numerical.js +656 -0
  121. package/dist/esm/util/object.js +81 -0
  122. package/dist/esm/util/string.js +29 -0
  123. package/dist/esm/util/uid.js +31 -0
  124. package/dist/esm/values/arcs.js +243 -0
  125. package/dist/esm/values/curve.js +975 -0
  126. package/dist/esm/values/fit.js +290 -0
  127. package/dist/esm/values/index.js +23 -0
  128. package/dist/esm/values/intersections.js +869 -0
  129. package/dist/esm/values/matrix.js +114 -0
  130. package/dist/esm/values/path.js +174 -0
  131. package/dist/esm/values/profile.js +221 -0
  132. package/dist/esm/values/region.js +63 -0
  133. package/dist/esm/values/smooth.js +248 -0
  134. package/dist/esm/values/svg.js +287 -0
  135. package/dist/esm/view/CanvasView.js +106 -0
  136. package/dist/esm/view/View.js +775 -0
  137. package/dist/esm/view/input.js +527 -0
  138. package/dist/paper-full.js +32941 -26371
  139. package/dist/paper-full.min.js +36 -31
  140. package/dist/paper-hosted.js +33623 -27236
  141. package/dist/paper-hosted.min.js +37 -0
  142. package/dist/paper-slim.js +28581 -0
  143. package/dist/paper-slim.min.js +17 -0
  144. package/dist/types/anim/Tween.d.ts +164 -0
  145. package/dist/types/basic/Line.d.ts +136 -0
  146. package/dist/types/basic/Matrix.d.ts +387 -0
  147. package/dist/types/basic/Point.d.ts +781 -0
  148. package/dist/types/basic/Rectangle.d.ts +550 -0
  149. package/dist/types/basic/Size.d.ts +457 -0
  150. package/dist/types/boolean/graph.d.ts +123 -0
  151. package/dist/types/boolean/index.d.ts +74 -0
  152. package/dist/types/boolean/operations.d.ts +9 -0
  153. package/dist/types/boolean/split.d.ts +19 -0
  154. package/dist/types/canvas/blendModes.d.ts +18 -0
  155. package/dist/types/canvas/canvasProvider.d.ts +32 -0
  156. package/dist/types/constants.d.ts +112 -0
  157. package/dist/types/core/Base.d.ts +50 -0
  158. package/dist/types/core/Emitter.d.ts +49 -0
  159. package/dist/types/core/features.d.ts +41 -0
  160. package/dist/types/core/serialization.d.ts +44 -0
  161. package/dist/types/core.d.ts +18 -0
  162. package/dist/types/dom/domElement.d.ts +33 -0
  163. package/dist/types/dom/domEvent.d.ts +29 -0
  164. package/dist/types/env.d.ts +26 -0
  165. package/dist/types/event/DrawEvent.d.ts +27 -0
  166. package/dist/types/event/Event.d.ts +47 -0
  167. package/dist/types/event/Key.d.ts +82 -0
  168. package/dist/types/event/KeyEvent.d.ts +35 -0
  169. package/dist/types/event/MouseEvent.d.ts +78 -0
  170. package/dist/types/hosted/HostItem.d.ts +26 -0
  171. package/dist/types/hosted/Hosting.d.ts +273 -0
  172. package/dist/types/hosted/index.d.ts +10 -0
  173. package/dist/types/index.d.ts +64 -0
  174. package/dist/types/internal.d.ts +101 -0
  175. package/dist/types/item/Effect.d.ts +128 -0
  176. package/dist/types/item/EffectInstance.d.ts +81 -0
  177. package/dist/types/item/Group.d.ts +225 -0
  178. package/dist/types/item/HitResult.d.ts +94 -0
  179. package/dist/types/item/Item.d.ts +2927 -0
  180. package/dist/types/item/ItemDefinition.d.ts +25 -0
  181. package/dist/types/item/Layer.d.ts +80 -0
  182. package/dist/types/item/Project.d.ts +748 -0
  183. package/dist/types/item/Raster.d.ts +431 -0
  184. package/dist/types/item/Shape.d.ts +219 -0
  185. package/dist/types/item/SymbolDefinition.d.ts +98 -0
  186. package/dist/types/item/SymbolItem.d.ts +92 -0
  187. package/dist/types/item/bounds.d.ts +56 -0
  188. package/dist/types/item/draw.d.ts +23 -0
  189. package/dist/types/item/effects.d.ts +22 -0
  190. package/dist/types/item/expand.d.ts +7 -0
  191. package/dist/types/item/hitTest.d.ts +10 -0
  192. package/dist/types/item/hosting.d.ts +20 -0
  193. package/dist/types/item/props.d.ts +35 -0
  194. package/dist/types/item/query.d.ts +14 -0
  195. package/dist/types/item/sampling.d.ts +5 -0
  196. package/dist/types/item/transform.d.ts +3 -0
  197. package/dist/types/net/http.d.ts +6 -0
  198. package/dist/types/node/CanvasAdapter.d.ts +19 -0
  199. package/dist/types/node/index.d.ts +60 -0
  200. package/dist/types/node/peers.d.ts +2 -0
  201. package/dist/types/offset/curves.d.ts +22 -0
  202. package/dist/types/offset/index.d.ts +65 -0
  203. package/dist/types/offset/offset.d.ts +18 -0
  204. package/dist/types/offset/outline.d.ts +14 -0
  205. package/dist/types/offset/pen.d.ts +36 -0
  206. package/dist/types/offset/profile.d.ts +37 -0
  207. package/dist/types/offset/round.d.ts +18 -0
  208. package/dist/types/offset/sweep.d.ts +44 -0
  209. package/dist/types/paperscript/PaperScript.d.ts +114 -0
  210. package/dist/types/paperscript/autoload.d.ts +1 -0
  211. package/dist/types/paperscript/index.d.ts +7 -0
  212. package/dist/types/path/CompoundPath.d.ts +183 -0
  213. package/dist/types/path/Curve.d.ts +567 -0
  214. package/dist/types/path/CurveLocation.d.ts +164 -0
  215. package/dist/types/path/Path.d.ts +1361 -0
  216. package/dist/types/path/PathFlattener.d.ts +48 -0
  217. package/dist/types/path/PathItem.d.ts +1190 -0
  218. package/dist/types/path/Segment.d.ts +335 -0
  219. package/dist/types/path/SegmentPoint.d.ts +1 -0
  220. package/dist/types/path/StrokeProfile.d.ts +74 -0
  221. package/dist/types/path/StrokeProfileStop.d.ts +110 -0
  222. package/dist/types/path/boolean.d.ts +24 -0
  223. package/dist/types/path/bounds.d.ts +24 -0
  224. package/dist/types/path/crossing.d.ts +2 -0
  225. package/dist/types/path/draw.d.ts +6 -0
  226. package/dist/types/path/hitTest.d.ts +8 -0
  227. package/dist/types/path/offset.d.ts +14 -0
  228. package/dist/types/path/shapes.d.ts +20 -0
  229. package/dist/types/path/smooth.d.ts +18 -0
  230. package/dist/types/path/values.d.ts +8 -0
  231. package/dist/types/scope/PaperScope.d.ts +182 -0
  232. package/dist/types/scope/PaperScopeItem.d.ts +26 -0
  233. package/dist/types/smoothing/index.d.ts +26 -0
  234. package/dist/types/style/Color.d.ts +829 -0
  235. package/dist/types/style/Gradient.d.ts +130 -0
  236. package/dist/types/style/GradientStop.d.ts +126 -0
  237. package/dist/types/style/PatternDefinition.d.ts +185 -0
  238. package/dist/types/style/Style.d.ts +757 -0
  239. package/dist/types/svg/index.d.ts +14 -0
  240. package/dist/types/svg/svgElement.d.ts +32 -0
  241. package/dist/types/svg/svgExport.d.ts +19 -0
  242. package/dist/types/svg/svgImport.d.ts +13 -0
  243. package/dist/types/svg/svgStyles.d.ts +20 -0
  244. package/dist/types/text/AreaText.d.ts +104 -0
  245. package/dist/types/text/PathText.d.ts +78 -0
  246. package/dist/types/text/PointText.d.ts +50 -0
  247. package/dist/types/text/TextItem.d.ts +163 -0
  248. package/dist/types/text/TextRange.d.ts +98 -0
  249. package/dist/types/text/TextStory.d.ts +119 -0
  250. package/dist/types/text/areaLayout.d.ts +3 -0
  251. package/dist/types/text/layout.d.ts +43 -0
  252. package/dist/types/text/measure.d.ts +7 -0
  253. package/dist/types/text/pathLayout.d.ts +3 -0
  254. package/dist/types/tool/Tool.d.ts +356 -0
  255. package/dist/types/tool/ToolEvent.d.ts +134 -0
  256. package/dist/types/util/Formatter.d.ts +34 -0
  257. package/dist/types/util/collisions.d.ts +77 -0
  258. package/dist/types/util/list.d.ts +23 -0
  259. package/dist/types/util/numerical.d.ts +196 -0
  260. package/dist/types/util/object.d.ts +19 -0
  261. package/dist/types/util/string.d.ts +12 -0
  262. package/dist/types/util/uid.d.ts +7 -0
  263. package/dist/types/values/arcs.d.ts +10 -0
  264. package/dist/types/values/curve.d.ts +42 -0
  265. package/dist/types/values/fit.d.ts +26 -0
  266. package/dist/types/values/index.d.ts +10 -0
  267. package/dist/types/values/intersections.d.ts +11 -0
  268. package/dist/types/values/matrix.d.ts +19 -0
  269. package/dist/types/values/path.d.ts +26 -0
  270. package/dist/types/values/profile.d.ts +41 -0
  271. package/dist/types/values/region.d.ts +13 -0
  272. package/dist/types/values/smooth.d.ts +39 -0
  273. package/dist/types/values/svg.d.ts +47 -0
  274. package/dist/types/view/CanvasView.d.ts +37 -0
  275. package/dist/types/view/View.d.ts +700 -0
  276. package/dist/types/view/input.d.ts +28 -0
  277. package/package.json +89 -59
  278. package/dist/docs/assets/css/docs.css +0 -414
  279. package/dist/docs/assets/js/codemirror.js +0 -4
  280. package/dist/docs/assets/js/docs.js +0 -493
  281. package/dist/docs/assets/js/jquery.js +0 -6
  282. package/dist/docs/assets/js/paper.js +0 -27591
  283. package/dist/docs/classes/AreaText.html +0 -9186
  284. package/dist/docs/classes/ChangeFlag.html +0 -385
  285. package/dist/docs/classes/Color.html +0 -2402
  286. package/dist/docs/classes/CompoundPath.html +0 -10018
  287. package/dist/docs/classes/Curve.html +0 -2326
  288. package/dist/docs/classes/CurveLocation.html +0 -673
  289. package/dist/docs/classes/DrawEvent.html +0 -69
  290. package/dist/docs/classes/Effect.html +0 -434
  291. package/dist/docs/classes/EffectInstance.html +0 -304
  292. package/dist/docs/classes/Event.html +0 -177
  293. package/dist/docs/classes/Gradient.html +0 -241
  294. package/dist/docs/classes/GradientStop.html +0 -274
  295. package/dist/docs/classes/Group.html +0 -7688
  296. package/dist/docs/classes/HitResult.html +0 -241
  297. package/dist/docs/classes/HostItem.html +0 -7314
  298. package/dist/docs/classes/Item.html +0 -7427
  299. package/dist/docs/classes/Key.html +0 -140
  300. package/dist/docs/classes/KeyEvent.html +0 -309
  301. package/dist/docs/classes/Layer.html +0 -7671
  302. package/dist/docs/classes/Matrix.html +0 -1745
  303. package/dist/docs/classes/MouseEvent.html +0 -356
  304. package/dist/docs/classes/PaperScope.html +0 -548
  305. package/dist/docs/classes/PaperScript.html +0 -204
  306. package/dist/docs/classes/Path.html +0 -13007
  307. package/dist/docs/classes/PathItem.html +0 -9780
  308. package/dist/docs/classes/PathText.html +0 -9056
  309. package/dist/docs/classes/PatternDefinition.html +0 -367
  310. package/dist/docs/classes/Point.html +0 -2860
  311. package/dist/docs/classes/PointText.html +0 -8967
  312. package/dist/docs/classes/Project.html +0 -1774
  313. package/dist/docs/classes/Raster.html +0 -8547
  314. package/dist/docs/classes/Rectangle.html +0 -1698
  315. package/dist/docs/classes/Segment.html +0 -1017
  316. package/dist/docs/classes/Shape.html +0 -8048
  317. package/dist/docs/classes/Size.html +0 -1915
  318. package/dist/docs/classes/StrokeProfileStop.html +0 -346
  319. package/dist/docs/classes/Style.html +0 -1765
  320. package/dist/docs/classes/SymbolDefinition.html +0 -338
  321. package/dist/docs/classes/SymbolItem.html +0 -7477
  322. package/dist/docs/classes/TextItem.html +0 -8810
  323. package/dist/docs/classes/TextRange.html +0 -186
  324. package/dist/docs/classes/TextStory.html +0 -355
  325. package/dist/docs/classes/Tool.html +0 -888
  326. package/dist/docs/classes/ToolEvent.html +0 -525
  327. package/dist/docs/classes/Tween.html +0 -390
  328. package/dist/docs/classes/View.html +0 -2108
  329. package/dist/docs/classes/global.html +0 -426
  330. package/dist/docs/classes/index.html +0 -88
  331. package/dist/docs/index.html +0 -11
  332. package/dist/node/browser.js +0 -15
  333. package/dist/node/canvas.js +0 -68
  334. package/dist/node/extend.js +0 -156
  335. package/dist/node/self.js +0 -67
  336. package/dist/paper-core.d.ts +0 -1
  337. package/dist/paper-core.js +0 -25636
  338. package/dist/paper-core.min.js +0 -32
  339. package/dist/paper.d.ts +0 -10481
  340. package/examples/Animated/AnimatedStar.html +0 -53
  341. package/examples/Animated/BooleanOperations.html +0 -115
  342. package/examples/Animated/CandyCrash.html +0 -151
  343. package/examples/Animated/Extruded.html +0 -50
  344. package/examples/Animated/Lines.html +0 -53
  345. package/examples/Animated/Smoothing.html +0 -70
  346. package/examples/Animated/Space.html +0 -86
  347. package/examples/Animated/SpaceUsingShapes.html +0 -79
  348. package/examples/Games/Paperoids.html +0 -569
  349. package/examples/JSON/Circle Testing.html +0 -34
  350. package/examples/JSON/Compound Path.html +0 -25
  351. package/examples/JSON/Empty Path Testing.html +0 -31
  352. package/examples/JSON/Gradients.html +0 -34
  353. package/examples/JSON/Group Transform.html +0 -28
  354. package/examples/JSON/Line Testing.html +0 -44
  355. package/examples/JSON/Random Path Testing.html +0 -42
  356. package/examples/JSON/Raster.html +0 -29
  357. package/examples/JSON/Rect and Attribute Testing.html +0 -56
  358. package/examples/JSON/Rotated Primitives.html +0 -55
  359. package/examples/JSON/Selection.html +0 -43
  360. package/examples/JSON/Shapes.html +0 -54
  361. package/examples/JSON/Symbols.html +0 -30
  362. package/examples/JSON/Text Testing.html +0 -38
  363. package/examples/JSON/Tiger.html +0 -19
  364. package/examples/JSON/Transform Test 1.html +0 -32
  365. package/examples/JSON/Transform Test 2.html +0 -30
  366. package/examples/Node.js/AnimatedStar.js +0 -52
  367. package/examples/Node.js/BooleanOperations.js +0 -36
  368. package/examples/Node.js/JSONtoPDF.js +0 -20
  369. package/examples/Node.js/Raster.js +0 -32
  370. package/examples/Node.js/RasterRemote.js +0 -33
  371. package/examples/Node.js/SvgExport.js +0 -52
  372. package/examples/Node.js/SvgImport.js +0 -23
  373. package/examples/Node.js/Tadpoles.js +0 -16
  374. package/examples/Node.js/Tadpoles.pjs +0 -278
  375. package/examples/Node.js/in.json +0 -1
  376. package/examples/Node.js/in.svg +0 -16
  377. package/examples/Paperjs.org/BooleanOperattions.html +0 -115
  378. package/examples/Paperjs.org/BouncingBalls.html +0 -103
  379. package/examples/Paperjs.org/Chain.html +0 -54
  380. package/examples/Paperjs.org/DivisionRaster.html +0 -72
  381. package/examples/Paperjs.org/FutureSplash.html +0 -122
  382. package/examples/Paperjs.org/HitTesting.html +0 -103
  383. package/examples/Paperjs.org/InteractiveTiger.html +0 -777
  384. package/examples/Paperjs.org/LiveEffects.html +0 -366
  385. package/examples/Paperjs.org/MetaBalls.html +0 -132
  386. package/examples/Paperjs.org/NyanRainbow.html +0 -202
  387. package/examples/Paperjs.org/Offsetting.html +0 -379
  388. package/examples/Paperjs.org/PathIntersections.html +0 -76
  389. package/examples/Paperjs.org/Qbertify.html +0 -146
  390. package/examples/Paperjs.org/RadialRainbows.html +0 -80
  391. package/examples/Paperjs.org/RoundedRectangles.html +0 -41
  392. package/examples/Paperjs.org/SatieLikedToDraw.html +0 -140
  393. package/examples/Paperjs.org/Simplify.html +0 -63
  394. package/examples/Paperjs.org/SpiralRaster.html +0 -120
  395. package/examples/Paperjs.org/StrokeProfiles.html +0 -706
  396. package/examples/Paperjs.org/Tadpoles.html +0 -283
  397. package/examples/Paperjs.org/Voronoi.html +0 -134
  398. package/examples/Rasters/PhyllotaxisRaster.html +0 -96
  399. package/examples/Rasters/Raster.html +0 -34
  400. package/examples/Rasters/RotationRaster.html +0 -44
  401. package/examples/Rasters/Smoothing.html +0 -36
  402. package/examples/SVG Export/Circle Testing.html +0 -32
  403. package/examples/SVG Export/Clipping.html +0 -17
  404. package/examples/SVG Export/Compound Path.html +0 -22
  405. package/examples/SVG Export/Empty Path Testing.html +0 -28
  406. package/examples/SVG Export/Gradients.html +0 -52
  407. package/examples/SVG Export/Group Transform.html +0 -25
  408. package/examples/SVG Export/Line Testing.html +0 -41
  409. package/examples/SVG Export/Random Path Testing.html +0 -39
  410. package/examples/SVG Export/Raster.html +0 -21
  411. package/examples/SVG Export/Rect and Attribute Testing.html +0 -53
  412. package/examples/SVG Export/Rotated Primitives.html +0 -80
  413. package/examples/SVG Export/Shapes.html +0 -58
  414. package/examples/SVG Export/Symbols.html +0 -27
  415. package/examples/SVG Export/Text Testing.html +0 -45
  416. package/examples/SVG Export/Tiger.html +0 -23
  417. package/examples/SVG Export/Transform Test 1.html +0 -29
  418. package/examples/SVG Export/Transform Test 2.html +0 -27
  419. package/examples/SVG Import/Arcs.html +0 -78
  420. package/examples/SVG Import/Butterfly.html +0 -223
  421. package/examples/SVG Import/Circle and Ellipse Testing.html +0 -26
  422. package/examples/SVG Import/Clipping.html +0 -100
  423. package/examples/SVG Import/From File.html +0 -30
  424. package/examples/SVG Import/Gradient.html +0 -138
  425. package/examples/SVG Import/Gradients.html +0 -30
  426. package/examples/SVG Import/Inkscape Pivot.html +0 -52
  427. package/examples/SVG Import/Inkscape.html +0 -88
  428. package/examples/SVG Import/Line Testing.html +0 -24
  429. package/examples/SVG Import/MoreGradients.html +0 -107
  430. package/examples/SVG Import/Multiple Paths Test 1.html +0 -42
  431. package/examples/SVG Import/Multiple Paths Test 2.html +0 -33
  432. package/examples/SVG Import/Nested Groups Test.html +0 -78
  433. package/examples/SVG Import/Polybezier.html +0 -43
  434. package/examples/SVG Import/Rect Testing.html +0 -25
  435. package/examples/SVG Import/Symbols.html +0 -24
  436. package/examples/SVG Import/Testing.html +0 -40
  437. package/examples/SVG Import/Text Testing.html +0 -19
  438. package/examples/SVG Import/Tiger.html +0 -742
  439. package/examples/SVG Import/Transform Testing.html +0 -22
  440. package/examples/SVG Import/Viewbox.html +0 -38
  441. package/examples/Scripts/Arcs.html +0 -39
  442. package/examples/Scripts/AreaText.html +0 -65
  443. package/examples/Scripts/BlendModes.html +0 -77
  444. package/examples/Scripts/BooleanOperations.html +0 -937
  445. package/examples/Scripts/CompoundPath.html +0 -19
  446. package/examples/Scripts/CurveTimeParameterization.html +0 -61
  447. package/examples/Scripts/HslColor.html +0 -53
  448. package/examples/Scripts/PathStructure.html +0 -82
  449. package/examples/Scripts/PathTangents.html +0 -73
  450. package/examples/Scripts/PathText.html +0 -48
  451. package/examples/Scripts/Patterns.html +0 -57
  452. package/examples/Scripts/Resize.html +0 -42
  453. package/examples/Scripts/RoundRectangle.html +0 -28
  454. package/examples/Scripts/Shapes.html +0 -54
  455. package/examples/Scripts/StrokeBounds.html +0 -101
  456. package/examples/Scripts/StrokeScaling.html +0 -65
  457. package/examples/Scripts/TextRanges.html +0 -51
  458. package/examples/Tools/BezierTool.html +0 -90
  459. package/examples/Tools/Circles.html +0 -28
  460. package/examples/Tools/Clouds.html +0 -35
  461. package/examples/Tools/DrippingBrush.html +0 -73
  462. package/examples/Tools/FancyBrush.html +0 -82
  463. package/examples/Tools/Grid.html +0 -44
  464. package/examples/Tools/MultiLines.html +0 -44
  465. package/examples/Tools/MultipleTools.html +0 -44
  466. package/examples/Tools/PathEditing.html +0 -95
  467. package/examples/Tools/SquareRounded.html +0 -76
  468. package/examples/Tools/Stars.html +0 -38
  469. package/examples/Tools/Vektor.html +0 -200
  470. package/examples/Tools/Wave.html +0 -50
  471. package/examples/Tools/WormFarm.html +0 -88
  472. package/examples/Worker/Main.html +0 -53
  473. package/examples/Worker/Worker.js +0 -14
  474. package/examples/css/style.css +0 -12
@@ -0,0 +1,404 @@
1
+ import { Emitter, defineEvents, registerClasses } from "../internal.js";
2
+ /**
3
+ * Allows tweening `Object` properties between two states for a given
4
+ * duration. To tween properties on Paper.js {@link Item} instances,
5
+ * {@link Item#tween(from, to, options)} can be used, which returns created
6
+ * tween instance.
7
+ *
8
+ * @see Item#tween(from, to, options)
9
+ * @see Item#tween(to, options)
10
+ * @see Item#tween(options)
11
+ * @see Item#tweenTo(to, options)
12
+ * @see Item#tweenFrom(from, options)
13
+ */
14
+ export class Tween extends Emitter {
15
+ static easings = {
16
+ // no easing, no acceleration
17
+ linear(t) {
18
+ return t;
19
+ },
20
+ // accelerating from zero velocity
21
+ easeInQuad(t) {
22
+ return t * t;
23
+ },
24
+ // decelerating to zero velocity
25
+ easeOutQuad(t) {
26
+ return t * (2 - t);
27
+ },
28
+ // acceleration until halfway, then deceleration
29
+ easeInOutQuad(t) {
30
+ return t < 0.5
31
+ ? 2 * t * t
32
+ : -1 + 2 * (2 - t) * t;
33
+ },
34
+ // accelerating from zero velocity
35
+ easeInCubic(t) {
36
+ return t * t * t;
37
+ },
38
+ // decelerating to zero velocity
39
+ easeOutCubic(t) {
40
+ return --t * t * t + 1;
41
+ },
42
+ // acceleration until halfway, then deceleration
43
+ easeInOutCubic(t) {
44
+ return t < 0.5
45
+ ? 4 * t * t * t
46
+ : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
47
+ },
48
+ // accelerating from zero velocity
49
+ easeInQuart(t) {
50
+ return t * t * t * t;
51
+ },
52
+ // decelerating to zero velocity
53
+ easeOutQuart(t) {
54
+ return 1 - --t * t * t * t;
55
+ },
56
+ // acceleration until halfway, then deceleration
57
+ easeInOutQuart(t) {
58
+ return t < 0.5
59
+ ? 8 * t * t * t * t
60
+ : 1 - 8 * --t * t * t * t;
61
+ },
62
+ // accelerating from zero velocity
63
+ easeInQuint(t) {
64
+ return t * t * t * t * t;
65
+ },
66
+ // decelerating to zero velocity
67
+ easeOutQuint(t) {
68
+ return 1 + --t * t * t * t * t;
69
+ },
70
+ // acceleration until halfway, then deceleration
71
+ easeInOutQuint(t) {
72
+ return t < 0.5
73
+ ? 16 * t * t * t * t * t
74
+ : 1 + 16 * --t * t * t * t * t;
75
+ },
76
+ // accelerating from zero velocity
77
+ easeInSine(t) {
78
+ return 1 - Math.cos(t * Math.PI / 2);
79
+ },
80
+ // decelerating to zero velocity
81
+ easeOutSine(t) {
82
+ return Math.sin(t * Math.PI / 2);
83
+ },
84
+ // acceleration until halfway, then deceleration
85
+ easeInOutSine(t) {
86
+ return (1 - Math.cos(t * Math.PI)) / 2;
87
+ },
88
+ // accelerating from zero velocity
89
+ easeInExpo(t) {
90
+ return t === 0 ? 0 : Math.pow(2, 10 * t - 10);
91
+ },
92
+ // decelerating to zero velocity
93
+ easeOutExpo(t) {
94
+ return t === 1 ? 1 : 1 - Math.pow(2, -10 * t);
95
+ },
96
+ // acceleration until halfway, then deceleration
97
+ easeInOutExpo(t) {
98
+ return t === 0 || t === 1
99
+ ? t
100
+ : t < 0.5
101
+ ? Math.pow(2, 20 * t - 10) / 2
102
+ : 1 - Math.pow(2, 10 - 20 * t) / 2;
103
+ },
104
+ // accelerating from zero velocity
105
+ easeInCirc(t) {
106
+ return 1 - Math.sqrt(1 - t * t);
107
+ },
108
+ // decelerating to zero velocity
109
+ easeOutCirc(t) {
110
+ return Math.sqrt(1 - --t * t);
111
+ },
112
+ // acceleration until halfway, then deceleration
113
+ easeInOutCirc(t) {
114
+ return t < 0.5
115
+ ? (1 - Math.sqrt(1 - 4 * t * t)) / 2
116
+ : (1 + Math.sqrt(1 - 4 * --t * t)) / 2;
117
+ }
118
+ };
119
+ object;
120
+ type;
121
+ easing;
122
+ duration;
123
+ running = false;
124
+ // The functions to call when the tween completes, see then():
125
+ #callbacks = [];
126
+ #completed = false;
127
+ #startTime = null;
128
+ #keys;
129
+ #parsedKeys;
130
+ #from;
131
+ #to;
132
+ /**
133
+ * Creates a new tween.
134
+ *
135
+ * @param object the object to tween the properties on
136
+ * @param from the state at the start of the tweening
137
+ * @param to the state at the end of the tweening
138
+ * @param duration the duration of the tweening
139
+ * @param [easing='linear'] the type of the easing
140
+ * function or the easing function
141
+ * @param [start=true] whether to start tweening automatically
142
+ */
143
+ constructor(object, from, to, duration, easing, start) {
144
+ super();
145
+ this.object = object;
146
+ const isFunction = typeof easing === 'function';
147
+ this.type = isFunction
148
+ ? 'function'
149
+ : typeof easing === 'string'
150
+ ? easing
151
+ : 'linear';
152
+ this.easing = isFunction ? easing : Tween.easings[this.type];
153
+ this.duration = duration;
154
+ const state = from ?? to;
155
+ this.#keys = state ? Object.keys(state) : [];
156
+ this.#parsedKeys = this.#parseKeys(this.#keys);
157
+ this.#from = state && this.#getState(from);
158
+ this.#to = state && this.#getState(to);
159
+ if (start !== false) {
160
+ this.start();
161
+ }
162
+ }
163
+ /**
164
+ * Calls the function when the tween completes, with the tweened object,
165
+ * and returns a promise of its result, so tweens can be awaited and
166
+ * chained. Unlike the callbacks of promises, the function is called right
167
+ * in the frame that completes the tween, before it is drawn, so that the
168
+ * next tween can follow without a gap.
169
+ *
170
+ * @param [callback] the function to call when the tween completes
171
+ * @return a promise of the result of the function, or of the object
172
+ *
173
+ * @example {@paperscript}
174
+ * // Tweens chaining:
175
+ * var circle = Path.circle({
176
+ * center: view.center,
177
+ * radius: 40,
178
+ * fillColor: 'blue'
179
+ * });
180
+ * // Tween color from blue to red.
181
+ * var tween = circle.tweenTo({ fillColor: 'red' }, 2000);
182
+ * // When the first tween completes...
183
+ * tween.then(function() {
184
+ * // ...tween color back to blue.
185
+ * circle.tweenTo({ fillColor: 'blue' }, 2000);
186
+ * });
187
+ */
188
+ then(callback) {
189
+ return new Promise((resolve, reject) => {
190
+ const complete = (object) => {
191
+ try {
192
+ resolve(callback ? callback(object) : object);
193
+ }
194
+ catch (error) {
195
+ reject(error);
196
+ }
197
+ };
198
+ if (this.#completed) {
199
+ complete(this.object);
200
+ }
201
+ else {
202
+ this.#callbacks.push(complete);
203
+ }
204
+ });
205
+ }
206
+ /**
207
+ * Start tweening.
208
+ *
209
+ * @example {@paperscript}
210
+ * // Manually start tweening.
211
+ * var circle = Path.circle({
212
+ * center: view.center,
213
+ * radius: 40,
214
+ * fillColor: 'blue'
215
+ * });
216
+ * var tween = circle.tweenTo(
217
+ * { fillColor: 'red' },
218
+ * { duration: 2000, start: false }
219
+ * );
220
+ * tween.start();
221
+ */
222
+ start() {
223
+ this.#startTime = null;
224
+ this.#completed = false;
225
+ this.running = true;
226
+ return this;
227
+ }
228
+ /**
229
+ * Stop tweening.
230
+ *
231
+ * @example {@paperscript}
232
+ * // Stop a tween before it completes.
233
+ * var circle = Path.circle({
234
+ * center: view.center,
235
+ * radius: 40,
236
+ * fillColor: 'blue'
237
+ * });
238
+ * // Start tweening from blue to red for 2 seconds.
239
+ * var tween = circle.tweenTo({ fillColor: 'red' }, 2000);
240
+ * // After 1 second...
241
+ * setTimeout(function(){
242
+ * // ...stop tweening.
243
+ * tween.stop();
244
+ * }, 1000);
245
+ */
246
+ stop() {
247
+ this.running = false;
248
+ return this;
249
+ }
250
+ /**
251
+ * Sets the tweened properties to their values at the progress, from 0 at
252
+ * the start to 1 at the end, applying the easing, and emits the update
253
+ * event. Progress at or beyond 1 completes the tween. Running tweens call
254
+ * it on each frame; it does nothing on tweens that aren't running.
255
+ *
256
+ * @param progress the progress of the tween, from 0 to 1
257
+ * @return this tween itself, so calls can be chained
258
+ */
259
+ update(progress) {
260
+ if (this.running) {
261
+ if (progress >= 1) {
262
+ // Always finish the animation.
263
+ progress = 1;
264
+ this.running = false;
265
+ this.#completed = true;
266
+ }
267
+ const factor = this.easing(progress);
268
+ const getValue = (value) => typeof value === 'function' ? value(factor, progress) : value;
269
+ for (const key of this.#keys) {
270
+ const from = getValue(this.#from[key]);
271
+ const to = getValue(this.#to[key]);
272
+ // Some paper objects have math functions (e.g.: Point,
273
+ // Color) which can directly be used to do the tweening.
274
+ const value = from && to && from.multiply && to.multiply
275
+ ? to.subtract(from).multiply(factor).add(from)
276
+ : (to - from) * factor + from;
277
+ this.#setProperty(this.#parsedKeys[key], value);
278
+ }
279
+ if (this.responds('update')) {
280
+ this.emit('update', { progress, factor });
281
+ }
282
+ if (this.#completed) {
283
+ const callbacks = this.#callbacks;
284
+ this.#callbacks = [];
285
+ for (const callback of callbacks) {
286
+ callback(this.object);
287
+ }
288
+ }
289
+ }
290
+ return this;
291
+ }
292
+ _handleFrame(time) {
293
+ // The first frame starts the tween, also when its time is 0:
294
+ this.#startTime ??= time;
295
+ this.update((time - this.#startTime) / this.duration);
296
+ }
297
+ #getState(state) {
298
+ const result = {};
299
+ for (const key of this.#keys) {
300
+ const path = this.#parsedKeys[key];
301
+ const current = this.#getProperty(path);
302
+ let value;
303
+ if (state) {
304
+ const resolved = this.#resolveValue(current, state[key]);
305
+ // Temporarily set the resolved value, so we can retrieve the
306
+ // coerced value from paper's internal magic.
307
+ this.#setProperty(path, resolved);
308
+ value = this.#getProperty(path);
309
+ // Clone the value if possible to prevent future changes.
310
+ value = value?.clone ? value.clone() : value;
311
+ this.#setProperty(path, current);
312
+ }
313
+ else {
314
+ // We want to get the current state at the time of the call, so
315
+ // we have to clone if possible to prevent future changes.
316
+ value = current?.clone ? current.clone() : current;
317
+ }
318
+ result[key] = value;
319
+ }
320
+ return result;
321
+ }
322
+ #resolveValue(current, value) {
323
+ if (value) {
324
+ if (Array.isArray(value) && value.length === 2) {
325
+ const operator = value[0];
326
+ return operator?.match?.(/^[+\-*/]=/)
327
+ ? this.#calculate(current, operator[0], value[1])
328
+ : value;
329
+ }
330
+ else if (typeof value === 'string') {
331
+ const match = value.match(/^[+\-*/]=(.*)/);
332
+ if (match) {
333
+ const parsed = JSON.parse(match[1].replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": '));
334
+ return this.#calculate(current, value[0], parsed);
335
+ }
336
+ }
337
+ }
338
+ return value;
339
+ }
340
+ #calculate(left, operator, right) {
341
+ // Use the math functions of objects that have them (e.g.: Point,
342
+ // Color), and the operator itself for numbers.
343
+ const name = {
344
+ '+': 'add',
345
+ '-': 'subtract',
346
+ '*': 'multiply',
347
+ '/': 'divide'
348
+ }[operator];
349
+ if (name && left?.[name]) {
350
+ return left[name](right);
351
+ }
352
+ switch (operator) {
353
+ case '+':
354
+ return left + right;
355
+ case '-':
356
+ return left - right;
357
+ case '*':
358
+ return left * right;
359
+ case '/':
360
+ return left / right;
361
+ }
362
+ }
363
+ #parseKeys(keys) {
364
+ const parsed = {};
365
+ for (const key of keys) {
366
+ const path = key
367
+ // Convert from JS property access notation to JSON pointer:
368
+ .replace(/\.([^.]*)/g, '/$1')
369
+ // Expand array property access notation ([])
370
+ .replace(/\[['"]?([^'"\]]*)['"]?\]/g, '/$1');
371
+ parsed[key] = path.split('/');
372
+ }
373
+ return parsed;
374
+ }
375
+ #getProperty(path, offset = 0) {
376
+ let { object } = this;
377
+ for (let i = 0, l = path.length - offset; i < l && object; i++) {
378
+ object = object[path[i]];
379
+ }
380
+ return object;
381
+ }
382
+ #setProperty(path, value) {
383
+ const destination = this.#getProperty(path, 1);
384
+ if (destination) {
385
+ destination[path[path.length - 1]] = value;
386
+ }
387
+ }
388
+ static {
389
+ registerClasses({ Tween: this });
390
+ defineEvents(this, {
391
+ onUpdate: {}
392
+ });
393
+ }
394
+ }
395
+ /**
396
+ * The tweens of items, for `use(tween)` with `paper/core`, see the `use()`
397
+ * function there.
398
+ */
399
+ export const tween = {
400
+ feature: {
401
+ name: 'tween',
402
+ Tween
403
+ }
404
+ };
@@ -0,0 +1,252 @@
1
+ /*
2
+ * Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
3
+ * http://paperjs.org/
4
+ *
5
+ * Copyright (c) 2011 - 2026, Jürg Lehni & Jonathan Puckey
6
+ * http://juerglehni.com/ & https://puckey.studio/
7
+ *
8
+ * Distributed under the MIT license. See LICENSE file for details.
9
+ *
10
+ * All rights reserved.
11
+ */
12
+ import { EPSILON, clamp, isMachineZero } from "../util/numerical.js";
13
+ import { Base } from "../core/Base.js";
14
+ import { registerClasses } from "../core/serialization.js";
15
+ import { Point } from "./Point.js";
16
+ /**
17
+ * The Line object represents a straight line from a point to a second point,
18
+ * or from a point in the direction of a vector. It ends at its two points,
19
+ * unless it's {@link #infinite}, and then runs on through them in both
20
+ * directions. {@link TextRange#baseline} returns a line.
21
+ *
22
+ * @example
23
+ * var line = new Line([0, 0], [100, 0]);
24
+ * console.log(line.getDistance([50, 20])); // 20
25
+ * console.log(line.getDistance([130, 40])); // 50
26
+ * console.log(line.intersect(new Line([50, -10], [50, 10]))); // { x: 50, y: 0 }
27
+ *
28
+ * var axis = new Line({ point: [0, 0], vector: [1, 0], infinite: true });
29
+ * console.log(axis.getDistance([130, 40])); // 40
30
+ */
31
+ export class Line extends Base {
32
+ static {
33
+ registerClasses({ Line: this });
34
+ }
35
+ #px;
36
+ #py;
37
+ #vx;
38
+ #vy;
39
+ #infinite;
40
+ constructor(arg0, arg1) {
41
+ super();
42
+ const { from, to, point = from, vector, infinite = false } = (arg1 === undefined ? arg0 : { from: arg0, to: arg1 });
43
+ const { x, y } = Point.from(point);
44
+ const { x: vx, y: vy } = vector
45
+ ? Point.from(vector)
46
+ : Point.from(to).subtract(x, y);
47
+ this.#px = x;
48
+ this.#py = y;
49
+ this.#vx = vx;
50
+ this.#vy = vy;
51
+ this.#infinite = infinite;
52
+ }
53
+ /**
54
+ * The line's point, where it starts.
55
+ */
56
+ get point() {
57
+ return new Point(this.#px, this.#py);
58
+ }
59
+ /**
60
+ * The line's vector, from its point to its second point.
61
+ */
62
+ get vector() {
63
+ return new Point(this.#vx, this.#vy);
64
+ }
65
+ /**
66
+ * The length of the line, from its point to its second point.
67
+ */
68
+ get length() {
69
+ return this.vector.length;
70
+ }
71
+ /**
72
+ * Specifies whether the line runs on through its points in both
73
+ * directions, instead of ending at them.
74
+ */
75
+ get infinite() {
76
+ return this.#infinite;
77
+ }
78
+ /**
79
+ * Returns the point where the line intersects the other line, within the
80
+ * ends of each line that isn't infinite.
81
+ *
82
+ * @param line the other line
83
+ * @return the point of intersection, or `undefined` if the lines don't
84
+ * intersect or are collinear
85
+ */
86
+ intersect(line) {
87
+ return Line.intersect(this.#px, this.#py, this.#vx, this.#vy, line.#px, line.#py, line.#vx, line.#vy, true, this.#infinite, line.#infinite);
88
+ }
89
+ /**
90
+ * Returns on which side of the line the point lies, seen along its vector:
91
+ * `1` to the left, `-1` to the right, and `0` on the line. A point beyond
92
+ * the ends of a line that isn't infinite lies on the side of the end it's
93
+ * beyond, `-1` before its point and `1` after its second point.
94
+ *
95
+ * @param point the point to check
96
+ * @return `-1`, `0` or `1`
97
+ */
98
+ getSide(point) {
99
+ const { x, y } = Point.from(point);
100
+ return Line.getSide(this.#px, this.#py, this.#vx, this.#vy, x, y, true, this.#infinite);
101
+ }
102
+ /**
103
+ * Returns the distance of the point from the line, which is the distance
104
+ * from its nearest end for points beyond the ends of a line that isn't
105
+ * infinite.
106
+ *
107
+ * @param point the point to measure the distance of
108
+ * @return the distance of the point from the line
109
+ */
110
+ getDistance(point, y) {
111
+ const other = Point.from(point, y);
112
+ const px = this.#px;
113
+ const py = this.#py;
114
+ const vx = this.#vx;
115
+ const vy = this.#vy;
116
+ if (this.#infinite) {
117
+ return Line.getDistance(px, py, vx, vy, other.x, other.y, true);
118
+ }
119
+ else {
120
+ const dx = other.x - px;
121
+ const dy = other.y - py;
122
+ // The position of the nearest point along the line, held within it:
123
+ const u = clamp((dx * vx + dy * vy) / (vx * vx + vy * vy) || 0, 0, 1);
124
+ return Math.hypot(dx - u * vx, dy - u * vy);
125
+ }
126
+ }
127
+ /**
128
+ * Returns the distance of the point from the line as
129
+ * {@link #getDistance(point)} measures it, positive on the side where
130
+ * {@link #getSide(point)} returns `1` and negative where it returns `-1`.
131
+ *
132
+ * @param point the point to measure the distance of
133
+ * @return the signed distance of the point from the line
134
+ */
135
+ getSignedDistance(point, y) {
136
+ const other = Point.from(point, y);
137
+ return this.#infinite
138
+ ? Line.getSignedDistance(this.#px, this.#py, this.#vx, this.#vy, other.x, other.y, true)
139
+ : this.getSide(other) * this.getDistance(other);
140
+ }
141
+ /**
142
+ * Checks whether the line runs in the same or the opposite direction as
143
+ * the other line, which it then lies on or runs parallel to.
144
+ *
145
+ * @param line the other line
146
+ * @return {@true if the lines are collinear}
147
+ */
148
+ isCollinear(line) {
149
+ return Point.isCollinear(this.#vx, this.#vy, line.#vx, line.#vy);
150
+ }
151
+ /**
152
+ * Checks whether the line is perpendicular to the other line.
153
+ *
154
+ * @param line the other line
155
+ * @return {@true if the lines are orthogonal}
156
+ */
157
+ isOrthogonal(line) {
158
+ return Point.isOrthogonal(this.#vx, this.#vy, line.#vx, line.#vy);
159
+ }
160
+ /**
161
+ * @return a string representation of the line
162
+ */
163
+ toString() {
164
+ return `{ point: ${this.point}, vector: ${this.vector}${this.#infinite ? ', infinite: true' : ''} }`;
165
+ }
166
+ /** @private */
167
+ static intersect(p1x, p1y, v1x, v1y, p2x, p2y, v2x, v2y, asVector, isInfinite1, isInfinite2) {
168
+ // Convert 2nd points to vectors if they are not specified as such.
169
+ if (!asVector) {
170
+ v1x -= p1x;
171
+ v1y -= p1y;
172
+ v2x -= p2x;
173
+ v2y -= p2y;
174
+ }
175
+ const cross = v1x * v2y - v1y * v2x;
176
+ // Avoid divisions by 0, and errors when getting too close to 0
177
+ if (!isMachineZero(cross)) {
178
+ const dx = p1x - p2x;
179
+ const dy = p1y - p2y;
180
+ let u1 = (v2x * dy - v2y * dx) / cross;
181
+ const u2 = (v1x * dy - v1y * dx) / cross;
182
+ // Check the ranges of the u parameters of the lines that don't extend
183
+ // beyond their definition points, but compare with EPSILON tolerance
184
+ // over the [0, 1] bounds.
185
+ const uMin = -EPSILON;
186
+ const uMax = 1 + EPSILON;
187
+ if ((isInfinite1 || uMin < u1 && u1 < uMax) &&
188
+ (isInfinite2 || uMin < u2 && u2 < uMax)) {
189
+ if (!isInfinite1) {
190
+ // Address the tolerance at the bounds by clipping to
191
+ // the actual range.
192
+ u1 = u1 <= 0 ? 0 : u1 >= 1 ? 1 : u1;
193
+ }
194
+ return new Point(p1x + u1 * v1x, p1y + u1 * v1y);
195
+ }
196
+ }
197
+ }
198
+ /** @private */
199
+ static getSide(px, py, vx, vy, x, y, asVector, isInfinite) {
200
+ if (!asVector) {
201
+ vx -= px;
202
+ vy -= py;
203
+ }
204
+ const v2x = x - px;
205
+ const v2y = y - py;
206
+ // ccw = v2.cross(v1);
207
+ let ccw = v2x * vy - v2y * vx;
208
+ if (!isInfinite && isMachineZero(ccw)) {
209
+ // If the point is on the infinite line, check if it's on the
210
+ // finite line too: Project v2 onto v1 and determine ccw based
211
+ // on which side of the finite line the point lies. Calculate
212
+ // the 'u' value of the point on the line, and use it for ccw:
213
+ // u = v2.dot(v1) / v1.dot(v1)
214
+ ccw = (v2x * vx + v2y * vy) / (vx * vx + vy * vy);
215
+ // If the 'u' value is within the line range, set ccw to 0,
216
+ // otherwise its already correct sign is all we need.
217
+ if (ccw >= 0 && ccw <= 1) {
218
+ ccw = 0;
219
+ }
220
+ }
221
+ return ccw < 0 ? -1 : ccw > 0 ? 1 : 0;
222
+ }
223
+ /** @private */
224
+ static getSignedDistance(px, py, vx, vy, x, y, asVector) {
225
+ if (!asVector) {
226
+ vx -= px;
227
+ vy -= py;
228
+ }
229
+ // Based on the error analysis by @iconexperience outlined in #799
230
+ return vx === 0
231
+ ? vy > 0
232
+ ? x - px
233
+ : px - x
234
+ : vy === 0
235
+ ? vx < 0
236
+ ? y - py
237
+ : py - y
238
+ : ((x - px) * vy - (y - py) * vx) /
239
+ // NOTE: Comparing vy > vx rather than their absolute
240
+ // values keeps the results of fat-line clipping in
241
+ // curve intersections unchanged.
242
+ (vy > vx
243
+ ? Math.abs(vy) *
244
+ Math.sqrt(1 + vx * vx / (vy * vy))
245
+ : Math.abs(vx) *
246
+ Math.sqrt(1 + vy * vy / (vx * vx)));
247
+ }
248
+ /** @private */
249
+ static getDistance(px, py, vx, vy, x, y, asVector) {
250
+ return Math.abs(Line.getSignedDistance(px, py, vx, vy, x, y, asVector));
251
+ }
252
+ }