paper 0.16.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 (464) hide show
  1. package/CHANGELOG.md +294 -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 +33083 -22681
  139. package/dist/paper-full.min.js +36 -31
  140. package/dist/paper-hosted.js +33898 -23223
  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 +90 -58
  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 -23759
  283. package/dist/docs/classes/AreaText.html +0 -8708
  284. package/dist/docs/classes/ChangeFlag.html +0 -385
  285. package/dist/docs/classes/Color.html +0 -2205
  286. package/dist/docs/classes/CompoundPath.html +0 -9168
  287. package/dist/docs/classes/Curve.html +0 -2326
  288. package/dist/docs/classes/CurveLocation.html +0 -673
  289. package/dist/docs/classes/Event.html +0 -177
  290. package/dist/docs/classes/Gradient.html +0 -241
  291. package/dist/docs/classes/GradientStop.html +0 -274
  292. package/dist/docs/classes/Group.html +0 -7139
  293. package/dist/docs/classes/HitResult.html +0 -241
  294. package/dist/docs/classes/HostItem.html +0 -6836
  295. package/dist/docs/classes/Item.html +0 -6892
  296. package/dist/docs/classes/Key.html +0 -140
  297. package/dist/docs/classes/KeyEvent.html +0 -309
  298. package/dist/docs/classes/Layer.html +0 -7122
  299. package/dist/docs/classes/Matrix.html +0 -1745
  300. package/dist/docs/classes/MouseEvent.html +0 -356
  301. package/dist/docs/classes/PaperScope.html +0 -548
  302. package/dist/docs/classes/PaperScript.html +0 -202
  303. package/dist/docs/classes/Path.html +0 -12064
  304. package/dist/docs/classes/PathItem.html +0 -8930
  305. package/dist/docs/classes/PathText.html +0 -8578
  306. package/dist/docs/classes/Point.html +0 -2860
  307. package/dist/docs/classes/PointText.html +0 -8489
  308. package/dist/docs/classes/Project.html +0 -1604
  309. package/dist/docs/classes/Raster.html +0 -8069
  310. package/dist/docs/classes/Rectangle.html +0 -1698
  311. package/dist/docs/classes/Segment.html +0 -1017
  312. package/dist/docs/classes/Shape.html +0 -7570
  313. package/dist/docs/classes/Size.html +0 -1915
  314. package/dist/docs/classes/Style.html +0 -1765
  315. package/dist/docs/classes/SymbolDefinition.html +0 -312
  316. package/dist/docs/classes/SymbolItem.html +0 -6999
  317. package/dist/docs/classes/TextItem.html +0 -8332
  318. package/dist/docs/classes/TextRange.html +0 -186
  319. package/dist/docs/classes/TextStory.html +0 -355
  320. package/dist/docs/classes/Tool.html +0 -888
  321. package/dist/docs/classes/ToolEvent.html +0 -525
  322. package/dist/docs/classes/Tween.html +0 -390
  323. package/dist/docs/classes/View.html +0 -2108
  324. package/dist/docs/classes/global.html +0 -426
  325. package/dist/docs/classes/index.html +0 -88
  326. package/dist/docs/index.html +0 -11
  327. package/dist/node/canvas.js +0 -68
  328. package/dist/node/extend.js +0 -156
  329. package/dist/node/self.js +0 -67
  330. package/dist/paper-core.d.ts +0 -1
  331. package/dist/paper-core.js +0 -21834
  332. package/dist/paper-core.min.js +0 -32
  333. package/dist/paper.d.ts +0 -9630
  334. package/examples/Animated/AnimatedStar.html +0 -53
  335. package/examples/Animated/BooleanOperations.html +0 -115
  336. package/examples/Animated/CandyCrash.html +0 -151
  337. package/examples/Animated/Extruded.html +0 -50
  338. package/examples/Animated/Lines.html +0 -53
  339. package/examples/Animated/Smoothing.html +0 -70
  340. package/examples/Animated/Space.html +0 -86
  341. package/examples/Animated/SpaceUsingShapes.html +0 -79
  342. package/examples/Games/Paperoids.html +0 -569
  343. package/examples/JSON/Circle Testing.html +0 -34
  344. package/examples/JSON/Compound Path.html +0 -25
  345. package/examples/JSON/Empty Path Testing.html +0 -31
  346. package/examples/JSON/Gradients.html +0 -34
  347. package/examples/JSON/Group Transform.html +0 -28
  348. package/examples/JSON/Line Testing.html +0 -44
  349. package/examples/JSON/Random Path Testing.html +0 -42
  350. package/examples/JSON/Raster.html +0 -29
  351. package/examples/JSON/Rect and Attribute Testing.html +0 -56
  352. package/examples/JSON/Rotated Primitives.html +0 -55
  353. package/examples/JSON/Selection.html +0 -43
  354. package/examples/JSON/Shapes.html +0 -54
  355. package/examples/JSON/Symbols.html +0 -30
  356. package/examples/JSON/Text Testing.html +0 -38
  357. package/examples/JSON/Tiger.html +0 -19
  358. package/examples/JSON/Transform Test 1.html +0 -32
  359. package/examples/JSON/Transform Test 2.html +0 -30
  360. package/examples/Node.js/AnimatedStar.js +0 -52
  361. package/examples/Node.js/BooleanOperations.js +0 -36
  362. package/examples/Node.js/JSONtoPDF.js +0 -20
  363. package/examples/Node.js/Raster.js +0 -32
  364. package/examples/Node.js/RasterRemote.js +0 -33
  365. package/examples/Node.js/SvgExport.js +0 -52
  366. package/examples/Node.js/SvgImport.js +0 -23
  367. package/examples/Node.js/Tadpoles.js +0 -16
  368. package/examples/Node.js/Tadpoles.pjs +0 -278
  369. package/examples/Node.js/in.json +0 -1
  370. package/examples/Node.js/in.svg +0 -16
  371. package/examples/Paperjs.org/BooleanOperattions.html +0 -115
  372. package/examples/Paperjs.org/BouncingBalls.html +0 -103
  373. package/examples/Paperjs.org/Chain.html +0 -54
  374. package/examples/Paperjs.org/DivisionRaster.html +0 -72
  375. package/examples/Paperjs.org/FutureSplash.html +0 -122
  376. package/examples/Paperjs.org/HitTesting.html +0 -103
  377. package/examples/Paperjs.org/InteractiveTiger.html +0 -777
  378. package/examples/Paperjs.org/MetaBalls.html +0 -132
  379. package/examples/Paperjs.org/NyanRainbow.html +0 -202
  380. package/examples/Paperjs.org/PathIntersections.html +0 -76
  381. package/examples/Paperjs.org/Qbertify.html +0 -146
  382. package/examples/Paperjs.org/RadialRainbows.html +0 -80
  383. package/examples/Paperjs.org/RoundedRectangles.html +0 -41
  384. package/examples/Paperjs.org/SatieLikedToDraw.html +0 -140
  385. package/examples/Paperjs.org/Simplify.html +0 -63
  386. package/examples/Paperjs.org/SpiralRaster.html +0 -120
  387. package/examples/Paperjs.org/Tadpoles.html +0 -283
  388. package/examples/Paperjs.org/Voronoi.html +0 -134
  389. package/examples/Rasters/PhyllotaxisRaster.html +0 -96
  390. package/examples/Rasters/Raster.html +0 -34
  391. package/examples/Rasters/RotationRaster.html +0 -44
  392. package/examples/Rasters/Smoothing.html +0 -36
  393. package/examples/SVG Export/Circle Testing.html +0 -32
  394. package/examples/SVG Export/Clipping.html +0 -17
  395. package/examples/SVG Export/Compound Path.html +0 -22
  396. package/examples/SVG Export/Empty Path Testing.html +0 -28
  397. package/examples/SVG Export/Gradients.html +0 -52
  398. package/examples/SVG Export/Group Transform.html +0 -25
  399. package/examples/SVG Export/Line Testing.html +0 -41
  400. package/examples/SVG Export/Random Path Testing.html +0 -39
  401. package/examples/SVG Export/Raster.html +0 -21
  402. package/examples/SVG Export/Rect and Attribute Testing.html +0 -53
  403. package/examples/SVG Export/Rotated Primitives.html +0 -80
  404. package/examples/SVG Export/Shapes.html +0 -58
  405. package/examples/SVG Export/Symbols.html +0 -27
  406. package/examples/SVG Export/Text Testing.html +0 -45
  407. package/examples/SVG Export/Tiger.html +0 -23
  408. package/examples/SVG Export/Transform Test 1.html +0 -29
  409. package/examples/SVG Export/Transform Test 2.html +0 -27
  410. package/examples/SVG Import/Arcs.html +0 -78
  411. package/examples/SVG Import/Butterfly.html +0 -223
  412. package/examples/SVG Import/Circle and Ellipse Testing.html +0 -26
  413. package/examples/SVG Import/Clipping.html +0 -100
  414. package/examples/SVG Import/From File.html +0 -30
  415. package/examples/SVG Import/Gradient.html +0 -138
  416. package/examples/SVG Import/Gradients.html +0 -30
  417. package/examples/SVG Import/Inkscape Pivot.html +0 -52
  418. package/examples/SVG Import/Inkscape.html +0 -88
  419. package/examples/SVG Import/Line Testing.html +0 -24
  420. package/examples/SVG Import/MoreGradients.html +0 -107
  421. package/examples/SVG Import/Multiple Paths Test 1.html +0 -42
  422. package/examples/SVG Import/Multiple Paths Test 2.html +0 -33
  423. package/examples/SVG Import/Nested Groups Test.html +0 -78
  424. package/examples/SVG Import/Polybezier.html +0 -43
  425. package/examples/SVG Import/Rect Testing.html +0 -25
  426. package/examples/SVG Import/Symbols.html +0 -24
  427. package/examples/SVG Import/Testing.html +0 -40
  428. package/examples/SVG Import/Text Testing.html +0 -19
  429. package/examples/SVG Import/Tiger.html +0 -742
  430. package/examples/SVG Import/Transform Testing.html +0 -22
  431. package/examples/SVG Import/Viewbox.html +0 -38
  432. package/examples/Scripts/Arcs.html +0 -39
  433. package/examples/Scripts/AreaText.html +0 -65
  434. package/examples/Scripts/BlendModes.html +0 -77
  435. package/examples/Scripts/BooleanOperations.html +0 -937
  436. package/examples/Scripts/CompoundPath.html +0 -19
  437. package/examples/Scripts/CurveTimeParameterization.html +0 -61
  438. package/examples/Scripts/HslColor.html +0 -53
  439. package/examples/Scripts/PathStructure.html +0 -82
  440. package/examples/Scripts/PathTangents.html +0 -73
  441. package/examples/Scripts/PathText.html +0 -48
  442. package/examples/Scripts/Resize.html +0 -42
  443. package/examples/Scripts/RoundRectangle.html +0 -28
  444. package/examples/Scripts/Shapes.html +0 -54
  445. package/examples/Scripts/StrokeBounds.html +0 -101
  446. package/examples/Scripts/StrokeScaling.html +0 -65
  447. package/examples/Scripts/TextRanges.html +0 -51
  448. package/examples/Tools/BezierTool.html +0 -90
  449. package/examples/Tools/Circles.html +0 -28
  450. package/examples/Tools/Clouds.html +0 -35
  451. package/examples/Tools/DrippingBrush.html +0 -73
  452. package/examples/Tools/FancyBrush.html +0 -82
  453. package/examples/Tools/Grid.html +0 -44
  454. package/examples/Tools/MultiLines.html +0 -44
  455. package/examples/Tools/MultipleTools.html +0 -44
  456. package/examples/Tools/PathEditing.html +0 -95
  457. package/examples/Tools/SquareRounded.html +0 -76
  458. package/examples/Tools/Stars.html +0 -38
  459. package/examples/Tools/Vektor.html +0 -200
  460. package/examples/Tools/Wave.html +0 -50
  461. package/examples/Tools/WormFarm.html +0 -88
  462. package/examples/Worker/Main.html +0 -53
  463. package/examples/Worker/Worker.js +0 -14
  464. package/examples/css/style.css +0 -12
@@ -0,0 +1,284 @@
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
+ /*
13
+ * The boolean operations of path items, through the planar graph on plain
14
+ * regions, see boolean/graph.ts.
15
+ *
16
+ * @author Harikrishnan Gopalakrishnan <hari.exeption@gmail.com>
17
+ * @author Jan Boesenberg <jan.boesenberg@gmail.com>
18
+ * @author Jürg Lehni <juerg@scratchdisk.com>
19
+ */
20
+ import { CompoundPath, EPSILON, Item, Path, createPathItem, getFeature, getPathValues, getRegion, getRegionBounds, getScope, getStrokeProfilePart, setStrokeProfileRuns, transformItem } from "../internal.js";
21
+ const { abs } = Math;
22
+ // Returns a copy of the path item in its own coordinates, without its matrix,
23
+ // and without curves of zero length, which have no directions for joins and
24
+ // caps:
25
+ export function getLocalCopy(item) {
26
+ const copy = item.clone({ insert: false });
27
+ copy.matrix.reset();
28
+ return copy.reduce();
29
+ }
30
+ // Returns a copy of the path item with all its matrices applied to its
31
+ // geometry, and without curves of zero length:
32
+ export function getAppliedCopy(item, options) {
33
+ const copy = item.clone({ insert: false }).reduce(options);
34
+ return transformItem(copy, null, { recursively: true, setApplyMatrix: true });
35
+ }
36
+ /*
37
+ * Closes the open paths of the path item with straight lines, as filling
38
+ * them does.
39
+ */
40
+ export function closePaths(item) {
41
+ const paths = item._getPaths();
42
+ for (let i = 0, l = paths.length; i < l; i++) {
43
+ const path = paths[i];
44
+ if (!path._closed && !path.isEmpty()) {
45
+ // Close with epsilon tolerance, to avoid tiny straight
46
+ // that would cause issues with intersection detection.
47
+ // If the ends meet, this joins them and keeps the curve
48
+ // that ends there. Only a new closing curve is straight
49
+ // (#1929):
50
+ const count = path._segments.length;
51
+ path.closePath(EPSILON);
52
+ if (path._segments.length === count) {
53
+ path.firstSegment.handleIn = [0, 0];
54
+ path.lastSegment.handleOut = [0, 0];
55
+ }
56
+ }
57
+ }
58
+ return item;
59
+ }
60
+ /*
61
+ * Traces the outlines of the areas that the operator includes, see
62
+ * traceGraph(), and returns them as paths. Where any of the operands' paths
63
+ * has a stroke profile, each traced path takes the parts of the profiles of
64
+ * the paths that it runs along.
65
+ */
66
+ export function tracePaths(operands, operator) {
67
+ const sources = operands.map(operand => operand._getPaths());
68
+ const hasProfiles = sources.some(paths => paths.some(path => path._strokeProfile));
69
+ // The profile of each path and the offsets of its curves, once needed:
70
+ const profiles = {};
71
+ const getProfile = (path) => {
72
+ let offset = 0;
73
+ return (profiles[path.id] ??= {
74
+ part: getStrokeProfilePart(path),
75
+ offsets: path.curves.map(curve => {
76
+ const start = offset;
77
+ offset += curve.length;
78
+ return start;
79
+ })
80
+ });
81
+ };
82
+ const { traceGraph } = getFeature('boolean');
83
+ const paths = [];
84
+ for (const traced of traceGraph(operands.map(getRegion), operator)) {
85
+ const path = new Path(Item.NO_INSERT);
86
+ path.segments = traced.segments;
87
+ path.closed = true;
88
+ if (hasProfiles) {
89
+ setStrokeProfileRuns(path, traced.sources.map(({ operand, path, curve, time1, time2 }) => {
90
+ const source = sources[operand][path];
91
+ const { part, offsets } = getProfile(source);
92
+ const reversed = time1 > time2;
93
+ const from = reversed ? time2 : time1;
94
+ const { curves } = source;
95
+ return {
96
+ part,
97
+ start: offsets[curve] + curves[curve].getPartLength(0, from),
98
+ length: curves[curve].getPartLength(from, reversed ? time1 : time2),
99
+ reversed
100
+ };
101
+ }));
102
+ }
103
+ // Only add paths that cover an area to the result.
104
+ if (path.area !== 0) {
105
+ paths.push(path);
106
+ }
107
+ }
108
+ return paths;
109
+ }
110
+ export function createResult(paths, simplify, path1, path2, options) {
111
+ let result = new CompoundPath(Item.NO_INSERT);
112
+ result.addChildren(paths);
113
+ // See if the item can be reduced to just a simple Path.
114
+ result = result.reduce({ simplify });
115
+ return placeResult(path1, result, options, [].concat(path2 ?? []));
116
+ }
117
+ // Inserts the result unless the options say otherwise, above the item or
118
+ // whichever of the others that are its siblings appears furthest up in the
119
+ // stack, with the item's attributes:
120
+ export function placeResult(item, result, options, others = []) {
121
+ const { insert = getScope().settings.insertItems } = options ?? {};
122
+ if (insert) {
123
+ let above = item;
124
+ for (const other of others) {
125
+ // Siblings have indices:
126
+ if (item.isSibling(other) && other.index > above.index) {
127
+ above = other;
128
+ }
129
+ }
130
+ result.insertAbove(above);
131
+ }
132
+ result.copyAttributes(item, true);
133
+ return result;
134
+ }
135
+ export function traceBoolean(path1, path2, operation, options) {
136
+ // Only support subtract and intersect operations when computing stroke
137
+ // based boolean operations (options.split = true).
138
+ if (options &&
139
+ (options.trace === false || options.stroke) &&
140
+ /^(subtract|intersect)$/.test(operation)) {
141
+ return splitBoolean(path1, path2, operation, options);
142
+ }
143
+ const { booleanOperators } = getFeature('boolean');
144
+ // We do not modify the operands themselves, but trace copies of them.
145
+ // NOTE: The result paths might not belong to the same type i.e.
146
+ // subtract(A:Path, B:Path):CompoundPath etc.
147
+ let paths;
148
+ if (operation === 'exclude' && Array.isArray(path2) && path2.length > 1) {
149
+ // Resolved on its own, each path fills where its winding is odd.
150
+ // So together, they fill where an odd number of them do, as one
151
+ // compound path with the even-odd rule:
152
+ const items = [path1].concat(path2);
153
+ const compound = new CompoundPath(Item.NO_INSERT);
154
+ compound.fillRule = 'evenodd';
155
+ for (let i = 0, l = items.length; i < l; i++) {
156
+ compound.addChildren(tracePaths([closePaths(getAppliedCopy(items[i], { simplify: true }))], booleanOperators.unite));
157
+ }
158
+ paths = tracePaths([compound], booleanOperators.unite);
159
+ }
160
+ else {
161
+ paths = tracePaths(getOperands(path1, combinePaths(path2, operation)), booleanOperators[operation]);
162
+ }
163
+ return createResult(paths, true, path1, path2, options);
164
+ }
165
+ /*
166
+ * Combines a list of paths into the one path that path1 is operated on
167
+ * with, see combineBalanced(). To subtract them, we subtract their union.
168
+ */
169
+ function combinePaths(paths, operation) {
170
+ const list = [].concat(paths ?? []);
171
+ const { booleanOperators, combineBalanced, traceRegions } = getFeature('boolean');
172
+ // Besides those, only intersect combines several paths:
173
+ const isUnite = operation === 'unite' || operation === 'subtract';
174
+ const combination = isUnite ? 'unite' : 'intersect';
175
+ return list.length < 2
176
+ ? (list[0] ?? null)
177
+ : list.some(item => item._getPaths().some(path => path._strokeProfile))
178
+ ? // The runs of stroke profiles need the items of each step:
179
+ combineBalanced(list, (path1, path2) => traceBoolean(path1, path2, combination, { insert: false }), isUnite ? (path) => path.bounds : undefined)
180
+ : // Without them, the steps combine regions, and only the result
181
+ // becomes an item:
182
+ createPathItem(combineBalanced(list.map(path => getRegion(closePaths(getAppliedCopy(path, { simplify: true })))), (region1, region2) => traceRegions(region1, region2, booleanOperators[combination]), isUnite ? getRegionBounds : undefined));
183
+ }
184
+ export function splitBoolean(path1, path2, operation, options) {
185
+ const _path1 = getAppliedCopy(path1, { simplify: true });
186
+ // Splitting needs a second path:
187
+ const _path2 = getAppliedCopy(combinePaths(path2, operation), {
188
+ simplify: true
189
+ });
190
+ const sources = _path1._getPaths();
191
+ const parts = {};
192
+ const paths = [];
193
+ const { splitGraph } = getFeature('boolean');
194
+ for (const piece of splitGraph(getRegion(_path1).paths, getRegion(_path2))) {
195
+ if (operation === 'divide' ||
196
+ piece.isInside !== (operation === 'subtract')) {
197
+ const source = sources[piece.source];
198
+ if (piece.isWhole) {
199
+ paths.push(source);
200
+ }
201
+ else {
202
+ const path = new Path({ segments: piece.segments, insert: false });
203
+ // The pieces keep the parts of the profiles of their paths:
204
+ if (source._strokeProfile) {
205
+ setStrokeProfileRuns(path, [
206
+ {
207
+ part: (parts[piece.source] ??= getStrokeProfilePart(source)),
208
+ start: piece.offset,
209
+ length: path.length
210
+ }
211
+ ]);
212
+ }
213
+ paths.push(path);
214
+ }
215
+ }
216
+ }
217
+ return createResult(paths, false, path1, path2, options);
218
+ }
219
+ /*
220
+ * Reorients the paths so that they fill the same area by any fill rule as
221
+ * they do by the given one: The graph traces the outlines of that area, and
222
+ * each path that an outline runs along takes its orientation, or is left out
223
+ * if none does. Outlines that run along several paths, which touch or cross
224
+ * there, or along parts of one, replace them. The outer paths get the given
225
+ * orientation, by default that of the largest path.
226
+ */
227
+ export function reorientPaths(paths, fillRule, clockwise) {
228
+ if (paths.length) {
229
+ clockwise ??= paths.reduce((largest, path) => abs(path.area) > abs(largest.area) ? path : largest).clockwise;
230
+ const outlines = getFeature('boolean').traceGraph([
231
+ {
232
+ fillRule,
233
+ paths: paths.map(path => ({
234
+ ...getPathValues(path),
235
+ closed: true
236
+ }))
237
+ }
238
+ ], inside => inside);
239
+ // How many outlines run along each path:
240
+ const counts = paths.map(() => 0);
241
+ for (const { sources } of outlines) {
242
+ for (const index of new Set(sources.map(source => source.path))) {
243
+ counts[index]++;
244
+ }
245
+ }
246
+ // The paths of the result at the index of the first path that their
247
+ // outline runs along, to keep their order:
248
+ const results = paths.map(() => []);
249
+ for (const { segments, sources } of outlines) {
250
+ const indices = [...new Set(sources.map(source => source.path))];
251
+ const index = Math.min(...indices);
252
+ let path = paths[index];
253
+ if (indices.length === 1 && counts[index] === 1) {
254
+ // The graph traces outer paths clockwise:
255
+ const { time1, time2 } = sources[0];
256
+ if (time1 > time2 === clockwise) {
257
+ path.reverse();
258
+ }
259
+ }
260
+ else {
261
+ path = new Path(Item.NO_INSERT);
262
+ path.segments = segments;
263
+ path.closed = true;
264
+ path.clockwise = path.clockwise === clockwise;
265
+ }
266
+ results[index].push(path);
267
+ }
268
+ return results.flat();
269
+ }
270
+ else {
271
+ return paths;
272
+ }
273
+ }
274
+ /*
275
+ * Prepares the operands of a boolean operation. Without path2, the
276
+ * operation resolves path1 on its own.
277
+ */
278
+ export function getOperands(path1, path2) {
279
+ const operands = [closePaths(getAppliedCopy(path1, { simplify: true }))];
280
+ if (path2) {
281
+ operands.push(closePaths(getAppliedCopy(path2, { simplify: true })));
282
+ }
283
+ return operands;
284
+ }
@@ -0,0 +1,257 @@
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 { Curve, Line, Matrix, Point, Rectangle, Segment, Size, addCurveBounds, getCurveTangent, getStrokeMatrix } from "../internal.js";
13
+ // All bounds functions below have the same first four parameters: segments,
14
+ // closed, path, matrix, so they can be called from Path#_getBounds() and also
15
+ // be used in Curve. But not all of them use all these parameters, and some
16
+ // define additional ones after.
17
+ /**
18
+ * Returns the bounding rectangle of the item excluding stroke width.
19
+ *
20
+ * @private
21
+ */
22
+ export function getSegmentBounds(segments, closed, path, matrix, options, strokePadding) {
23
+ const first = segments[0];
24
+ // If there are no segments, return "empty" rectangle, just like groups,
25
+ // since #bounds is assumed to never return null.
26
+ if (!first)
27
+ return new Rectangle();
28
+ let coords = new Array(6);
29
+ // Make coordinates for first segment available in prevCoords.
30
+ let prevCoords = first._transformCoordinates(matrix, new Array(6));
31
+ const min = prevCoords.slice(0, 2); // Start with values of first point
32
+ const max = min.slice(); // clone
33
+ const roots = new Array(2);
34
+ function processSegment(segment) {
35
+ segment._transformCoordinates(matrix, coords);
36
+ for (let i = 0; i < 2; i++) {
37
+ addCurveBounds(prevCoords[i], // prev.point
38
+ prevCoords[i + 4], // prev.handleOut
39
+ coords[i + 2], // segment.handleIn
40
+ coords[i], // segment.point,
41
+ i, strokePadding?.[i] ?? 0, min, max, roots);
42
+ }
43
+ // Swap coordinate buffers.
44
+ const tmp = prevCoords;
45
+ prevCoords = coords;
46
+ coords = tmp;
47
+ }
48
+ for (let i = 1, l = segments.length; i < l; i++) {
49
+ processSegment(segments[i]);
50
+ }
51
+ if (closed) {
52
+ processSegment(first);
53
+ }
54
+ return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]);
55
+ }
56
+ /**
57
+ * Returns the bounding rectangle of the item including stroke width.
58
+ *
59
+ * @private
60
+ */
61
+ export function getSegmentStrokeBounds(segments, closed, path, matrix, options) {
62
+ const { style } = path;
63
+ const stroke = style.hasStroke();
64
+ const strokeRadius = style.strokeWidth / 2;
65
+ if (!stroke)
66
+ return getSegmentBounds(segments, closed, path, matrix, options);
67
+ const strokeMatrix = getStrokeMatrix(path, matrix, options);
68
+ const strokePadding = Matrix._getCircleExtents(strokeRadius, strokeMatrix);
69
+ // Start with normal path bounds with added stroke padding. Then we
70
+ // only need to look at each segment and handle join / cap / miter.
71
+ let bounds = getSegmentBounds(segments, closed, path, matrix, options, strokePadding);
72
+ const join = style.strokeJoin;
73
+ const cap = style.strokeCap;
74
+ const { miterLimit } = style;
75
+ // Create a rectangle of padding size, used for union with bounds
76
+ // further down
77
+ const joinBounds = new Rectangle(new Size(strokePadding).multiply(2));
78
+ // helper function that is passed to addBevelJoin() and addSquareCap()
79
+ // to handle the point transformations.
80
+ function addPoint(point) {
81
+ bounds = bounds.include(point);
82
+ }
83
+ function addRound(segment) {
84
+ joinBounds.center = segment._point.transform(matrix);
85
+ bounds = bounds.unite(joinBounds);
86
+ }
87
+ function addJoin(segment, join) {
88
+ // When both handles are set in a segment and they are collinear,
89
+ // the join setting is ignored and round is always used.
90
+ if (join === 'round' || segment.isSmooth()) {
91
+ addRound(segment);
92
+ }
93
+ else {
94
+ // addBevelJoin() handles both 'bevel' and 'miter' joins.
95
+ addBevelJoin(segment, join, strokeRadius, miterLimit, matrix, strokeMatrix, addPoint);
96
+ }
97
+ }
98
+ function addCap(segment, cap) {
99
+ if (cap === 'round') {
100
+ addRound(segment);
101
+ }
102
+ else {
103
+ // addSquareCap() handles both 'square' and 'butt' caps.
104
+ addSquareCap(segment, cap, strokeRadius, matrix, strokeMatrix, addPoint);
105
+ }
106
+ }
107
+ const length = segments.length - (closed ? 0 : 1);
108
+ if (length > 0) {
109
+ for (let i = 1; i < length; i++) {
110
+ addJoin(segments[i], join);
111
+ }
112
+ if (closed) {
113
+ // Go back to the beginning
114
+ addJoin(segments[0], join);
115
+ }
116
+ else {
117
+ // Handle caps on open paths
118
+ addCap(segments[0], cap);
119
+ addCap(segments.at(-1), cap);
120
+ }
121
+ }
122
+ return bounds;
123
+ }
124
+ export function addBevelJoin(segment, join, radius, miterLimit, matrix, strokeMatrix, addPoint, isArea) {
125
+ // Handles both 'bevel' and 'miter' joins, as they share a lot of code,
126
+ // using different matrices to transform segment points and stroke
127
+ // vectors to support Style#strokeScaling. The join is constructed
128
+ // where the stroke is drawn, see getStrokeNormal(), and its vectors
129
+ // transformed from there.
130
+ // Joins lie between two curves:
131
+ const curve2 = segment.curve;
132
+ const curve1 = curve2.previous;
133
+ const point = curve2.point1.transform(matrix);
134
+ let normal1 = getStrokeNormal(curve1, 1, radius, matrix, strokeMatrix);
135
+ let normal2 = getStrokeNormal(curve2, 0, radius, matrix, strokeMatrix);
136
+ const angle = normal1.getDirectedAngle(normal2);
137
+ if (angle < 0 || angle >= 180) {
138
+ normal1 = normal1.negate();
139
+ normal2 = normal2.negate();
140
+ }
141
+ if (isArea) {
142
+ addPoint(point);
143
+ }
144
+ addPoint(point.add(normal1.transform(strokeMatrix)));
145
+ if (join === 'miter') {
146
+ // Intersect the two lines
147
+ const corner = Line.intersect(normal1.x, normal1.y, -normal1.y, normal1.x, normal2.x, normal2.y, -normal2.y, normal2.x, true, true, true);
148
+ // See if we actually get a bevel point and if its distance is below
149
+ // the miterLimit. If not, make a normal bevel.
150
+ if (corner && corner.length <= miterLimit * radius) {
151
+ addPoint(point.add(corner.transform(strokeMatrix)));
152
+ }
153
+ }
154
+ // Produce a normal bevel
155
+ addPoint(point.add(normal2.transform(strokeMatrix)));
156
+ }
157
+ export function addSquareCap(segment, cap, radius, matrix, strokeMatrix, addPoint, isArea) {
158
+ // Handles both 'square' and 'butt' caps, as they share a lot of code.
159
+ // Calculate the corner points of butt and square caps, using different
160
+ // matrices to transform segment points and stroke vectors to support
161
+ // Style#strokeScaling.
162
+ let point = segment._point.transform(matrix);
163
+ // Caps lie at the ends of curves:
164
+ const loc = segment.location;
165
+ const { time } = loc;
166
+ // Checking the time for 0 is to see whether this is the first or
167
+ // the last segment of the open path, in order to determine in which
168
+ // direction to flip the normal.
169
+ const vector = getStrokeNormal(loc.curve, time, time === 0 ? radius : -radius, matrix, strokeMatrix);
170
+ const normal = vector.transform(strokeMatrix);
171
+ // For square caps, we need to step away from point in the direction of
172
+ // the tangent, which is the normal rotated before transforming it, as
173
+ // the matrices don't preserve angles (#2065).
174
+ if (cap === 'square') {
175
+ if (isArea) {
176
+ addPoint(point.subtract(normal));
177
+ addPoint(point.add(normal));
178
+ }
179
+ point = point.add(vector.rotate(-90).transform(strokeMatrix));
180
+ }
181
+ addPoint(point.add(normal));
182
+ addPoint(point.subtract(normal));
183
+ }
184
+ /**
185
+ * Returns the bounding rectangle of the item including handles.
186
+ *
187
+ * @private
188
+ */
189
+ export function getSegmentHandleBounds(segments, closed, path, matrix, options) {
190
+ // If there are no segments, return "empty" rectangle, as getBounds().
191
+ if (!segments.length)
192
+ return new Rectangle();
193
+ const { style } = path;
194
+ const stroke = options.stroke && style.hasStroke();
195
+ let strokePadding;
196
+ let joinPadding;
197
+ if (stroke) {
198
+ const strokeMatrix = getStrokeMatrix(path, matrix, options);
199
+ const strokeRadius = style.strokeWidth / 2;
200
+ let joinRadius = strokeRadius;
201
+ if (style.strokeJoin === 'miter') {
202
+ joinRadius = strokeRadius * style.miterLimit;
203
+ }
204
+ if (style.strokeCap === 'square') {
205
+ joinRadius = Math.max(joinRadius, strokeRadius * Math.SQRT2);
206
+ }
207
+ strokePadding = Matrix._getCircleExtents(strokeRadius, strokeMatrix);
208
+ joinPadding = Matrix._getCircleExtents(joinRadius, strokeMatrix);
209
+ }
210
+ const coords = new Array(6);
211
+ let x1 = Infinity;
212
+ let x2 = -x1;
213
+ let y1 = x1;
214
+ let y2 = x2;
215
+ for (let i = 0, l = segments.length; i < l; i++) {
216
+ const segment = segments[i];
217
+ segment._transformCoordinates(matrix, coords);
218
+ for (let j = 0; j < 6; j += 2) {
219
+ // Use different padding for points or handles
220
+ const padding = !j ? joinPadding : strokePadding;
221
+ const paddingX = padding?.[0] ?? 0;
222
+ const paddingY = padding?.[1] ?? 0;
223
+ const x = coords[j];
224
+ const y = coords[j + 1];
225
+ const xn = x - paddingX;
226
+ const xx = x + paddingX;
227
+ const yn = y - paddingY;
228
+ const yx = y + paddingY;
229
+ if (xn < x1) {
230
+ x1 = xn;
231
+ }
232
+ if (xx > x2) {
233
+ x2 = xx;
234
+ }
235
+ if (yn < y1) {
236
+ y1 = yn;
237
+ }
238
+ if (yx > y2) {
239
+ y2 = yx;
240
+ }
241
+ }
242
+ }
243
+ return new Rectangle(x1, y1, x2 - x1, y2 - y1);
244
+ }
245
+ /**
246
+ * Returns the normal of the curve at the given time with the length of the
247
+ * stroke's radius, in the space where the stroke is drawn with a round pen,
248
+ * from the curve's tangent transformed into it, as the matrices don't
249
+ * preserve angles (#2065). For strokes that scale with the matrix, this is
250
+ * the curve's own space.
251
+ */
252
+ function getStrokeNormal(curve, time, radius, matrix, strokeMatrix) {
253
+ const shiftless = matrix?._shiftless() ?? new Matrix();
254
+ const inverse = strokeMatrix?.inverted();
255
+ const tangent = getCurveTangent(curve.values, time).transform(inverse?.append(shiftless) ?? shiftless);
256
+ return new Point(tangent.y, -tangent.x).normalize(radius);
257
+ }
@@ -0,0 +1,114 @@
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 { CURVETIME_EPSILON, classifyCurve, getCurveLength, getCurvePeaks, getCurveTangent } from "../internal.js";
13
+ // The part of a curve's length to step away from an intersection by, where
14
+ // the curve has no loops, cusps, inflections or peaks. By trial & error, 1/32
15
+ // was determined to work well:
16
+ const lengthFraction = 1 / 32;
17
+ // NOTE: Documentation is in CurveLocation#isCrossing()
18
+ export function isCrossing(location) {
19
+ // Implementation loosely based on work by Andy Finnell:
20
+ // http://losingfight.com/blog/2011/07/09/how-to-implement-boolean-operations-on-bezier-paths-part-3/
21
+ // https://bitbucket.org/andyfinnell/vectorboolean
22
+ const inter = location._intersection;
23
+ if (!inter)
24
+ return false;
25
+ const t1 = location.time;
26
+ const t2 = inter.time;
27
+ const tMin = CURVETIME_EPSILON;
28
+ const tMax = 1 - tMin;
29
+ // t*Inside specifies if the found intersection is inside the curve.
30
+ const t1Inside = t1 >= tMin && t1 <= tMax;
31
+ const t2Inside = t2 >= tMin && t2 <= tMax;
32
+ // If the intersection is in the middle of both paths, it is either a
33
+ // tangent or a crossing, no need for the detailed corner check below:
34
+ if (t1Inside && t2Inside)
35
+ return !location.isTouching();
36
+ // Now get the references to the 4 curves involved in the intersection:
37
+ // - c1 & c2 are the curves on the first intersecting path, left and
38
+ // right of the intersection.
39
+ // - c3 & c4 are the same for the second intersecting path.
40
+ // - If the intersection is in the middle of the curve (t*Inside), then
41
+ // both values point to the same curve, and the curve-time is to be
42
+ // handled accordingly further down.
43
+ let c2 = location.curve;
44
+ const c1 = c2 && t1 < tMin ? c2.previous : c2;
45
+ let c4 = inter.curve;
46
+ const c3 = c4 && t2 < tMin ? c4.previous : c4;
47
+ // If t1 / t2 are at the end, then step to the next curve.
48
+ if (t1 > tMax) {
49
+ c2 = c2.next;
50
+ }
51
+ if (t2 > tMax) {
52
+ c4 = c4.next;
53
+ }
54
+ if (!c1 || !c2 || !c3 || !c4)
55
+ return false;
56
+ // Calculate unambiguous angles for all 4 tangents at the intersection:
57
+ // - If the intersection is inside a curve (t1 / t2Inside), the tangent
58
+ // at t1 / t2 is unambiguous, because the curve is continuous.
59
+ // - If the intersection is on a segment, step away at equal offsets on
60
+ // each curve, to calculate unambiguous angles. The vector from the
61
+ // intersection to this new location is used to determine the angle.
62
+ const offsets = [];
63
+ function addOffsets(curve, end) {
64
+ // Find the largest offset of unambiguous direction on the curve,
65
+ // taking their loops, cusps, inflections, and "peaks" into account.
66
+ const v = curve.values;
67
+ const roots = classifyCurve(v).roots ?? getCurvePeaks(v);
68
+ const count = roots.length;
69
+ const offset = getCurveLength(v, end && count ? roots[count - 1] : 0, !end && count ? roots[0] : 1);
70
+ // When no root was found, the full length was calculated. Use a
71
+ // fraction of it:
72
+ offsets.push(count ? offset : offset * lengthFraction);
73
+ }
74
+ function isInRange(angle, min, max) {
75
+ return min < max
76
+ ? angle > min && angle < max
77
+ : // min > max: the range wraps around -180 / 180 degrees
78
+ angle > min || angle < max;
79
+ }
80
+ if (!t1Inside) {
81
+ addOffsets(c1, true);
82
+ addOffsets(c2, false);
83
+ }
84
+ if (!t2Inside) {
85
+ addOffsets(c3, true);
86
+ addOffsets(c4, false);
87
+ }
88
+ const pt = location.point;
89
+ // Determined the shared unambiguous offset by the taking the
90
+ // shortest offsets on all involved curves that are unambiguous.
91
+ const offset = Math.min(...offsets);
92
+ // The offset is within all four curves, so they have points there:
93
+ const v2 = t1Inside
94
+ ? getCurveTangent(c2.values, t1)
95
+ : c2.getPointAt(offset).subtract(pt);
96
+ const v1 = t1Inside ? v2.negate() : c1.getPointAt(-offset).subtract(pt);
97
+ const v4 = t2Inside
98
+ ? getCurveTangent(c4.values, t2)
99
+ : c4.getPointAt(offset).subtract(pt);
100
+ const v3 = t2Inside ? v4.negate() : c3.getPointAt(-offset).subtract(pt);
101
+ const a1 = v1.angle;
102
+ const a2 = v2.angle;
103
+ const a3 = v3.angle;
104
+ const a4 = v4.angle;
105
+ // Count how many times curve2 angles appear between the curve1 angles.
106
+ // If each pair of angles split the other two, then the edges cross.
107
+ // Use t1Inside to decide which angle pair to check against.
108
+ // If t1 is inside the curve, check against a3 & a4, otherwise a1 & a2.
109
+ return !!(t1Inside
110
+ ? (isInRange(a1, a3, a4) !== isInRange(a2, a3, a4)) &&
111
+ (isInRange(a1, a4, a3) !== isInRange(a2, a4, a3))
112
+ : (isInRange(a3, a1, a2) !== isInRange(a4, a1, a2)) &&
113
+ (isInRange(a3, a2, a1) !== isInRange(a4, a2, a1)));
114
+ }