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.
- package/CHANGELOG.md +199 -0
- package/LICENSE.txt +1 -1
- package/MIGRATION.md +402 -0
- package/README.md +137 -143
- package/dist/esm/anim/Tween.js +404 -0
- package/dist/esm/basic/Line.js +252 -0
- package/dist/esm/basic/Matrix.js +603 -0
- package/dist/esm/basic/Point.js +738 -0
- package/dist/esm/basic/Rectangle.js +788 -0
- package/dist/esm/basic/Size.js +368 -0
- package/dist/esm/boolean/graph.js +950 -0
- package/dist/esm/boolean/index.js +143 -0
- package/dist/esm/boolean/operations.js +94 -0
- package/dist/esm/boolean/split.js +89 -0
- package/dist/esm/canvas/blendModes.js +115 -0
- package/dist/esm/canvas/canvasProvider.js +102 -0
- package/dist/esm/constants.js +130 -0
- package/dist/esm/core/Base.js +52 -0
- package/dist/esm/core/Emitter.js +215 -0
- package/dist/esm/core/features.js +53 -0
- package/dist/esm/core/serialization.js +174 -0
- package/dist/esm/core.js +15 -0
- package/dist/esm/dom/domElement.js +112 -0
- package/dist/esm/dom/domEvent.js +106 -0
- package/dist/esm/env.js +66 -0
- package/dist/esm/event/DrawEvent.js +38 -0
- package/dist/esm/event/Event.js +79 -0
- package/dist/esm/event/Key.js +236 -0
- package/dist/esm/event/KeyEvent.js +39 -0
- package/dist/esm/event/MouseEvent.js +91 -0
- package/dist/esm/hosted/HostItem.js +60 -0
- package/dist/esm/hosted/Hosting.js +1061 -0
- package/dist/esm/hosted/index.js +20 -0
- package/dist/esm/index.js +38 -0
- package/dist/esm/internal.js +115 -0
- package/dist/esm/item/Effect.js +256 -0
- package/dist/esm/item/EffectInstance.js +184 -0
- package/dist/esm/item/Group.js +293 -0
- package/dist/esm/item/HitResult.js +126 -0
- package/dist/esm/item/Item.js +3339 -0
- package/dist/esm/item/ItemDefinition.js +95 -0
- package/dist/esm/item/Layer.js +69 -0
- package/dist/esm/item/Project.js +1013 -0
- package/dist/esm/item/Raster.js +722 -0
- package/dist/esm/item/Shape.js +355 -0
- package/dist/esm/item/SymbolDefinition.js +68 -0
- package/dist/esm/item/SymbolItem.js +131 -0
- package/dist/esm/item/bounds.js +324 -0
- package/dist/esm/item/draw.js +525 -0
- package/dist/esm/item/effects.js +124 -0
- package/dist/esm/item/expand.js +87 -0
- package/dist/esm/item/hitTest.js +203 -0
- package/dist/esm/item/hosting.js +12 -0
- package/dist/esm/item/props.js +12 -0
- package/dist/esm/item/query.js +139 -0
- package/dist/esm/item/sampling.js +67 -0
- package/dist/esm/item/transform.js +128 -0
- package/dist/esm/net/http.js +26 -0
- package/dist/esm/node/CanvasAdapter.js +137 -0
- package/dist/esm/node/index.js +150 -0
- package/dist/esm/node/peers.js +27 -0
- package/dist/esm/offset/curves.js +866 -0
- package/dist/esm/offset/index.js +70 -0
- package/dist/esm/offset/offset.js +178 -0
- package/dist/esm/offset/outline.js +91 -0
- package/dist/esm/offset/pen.js +298 -0
- package/dist/esm/offset/profile.js +772 -0
- package/dist/esm/offset/round.js +213 -0
- package/dist/esm/offset/sweep.js +100 -0
- package/dist/esm/paperscript/PaperScript.js +832 -0
- package/dist/esm/paperscript/autoload.js +27 -0
- package/dist/esm/paperscript/index.js +17 -0
- package/dist/esm/path/CompoundPath.js +367 -0
- package/dist/esm/path/Curve.js +996 -0
- package/dist/esm/path/CurveLocation.js +462 -0
- package/dist/esm/path/Path.js +1761 -0
- package/dist/esm/path/PathFlattener.js +186 -0
- package/dist/esm/path/PathItem.js +757 -0
- package/dist/esm/path/Segment.js +640 -0
- package/dist/esm/path/SegmentPoint.js +106 -0
- package/dist/esm/path/StrokeProfile.js +387 -0
- package/dist/esm/path/StrokeProfileStop.js +207 -0
- package/dist/esm/path/boolean.js +284 -0
- package/dist/esm/path/bounds.js +257 -0
- package/dist/esm/path/crossing.js +114 -0
- package/dist/esm/path/draw.js +161 -0
- package/dist/esm/path/hitTest.js +259 -0
- package/dist/esm/path/offset.js +152 -0
- package/dist/esm/path/shapes.js +231 -0
- package/dist/esm/path/smooth.js +84 -0
- package/dist/esm/path/values.js +40 -0
- package/dist/esm/scope/PaperScope.js +288 -0
- package/dist/esm/scope/PaperScopeItem.js +74 -0
- package/dist/esm/smoothing/index.js +71 -0
- package/dist/esm/style/Color.js +917 -0
- package/dist/esm/style/Gradient.js +191 -0
- package/dist/esm/style/GradientStop.js +168 -0
- package/dist/esm/style/PatternDefinition.js +383 -0
- package/dist/esm/style/Style.js +503 -0
- package/dist/esm/svg/index.js +27 -0
- package/dist/esm/svg/svgElement.js +97 -0
- package/dist/esm/svg/svgExport.js +847 -0
- package/dist/esm/svg/svgImport.js +1101 -0
- package/dist/esm/svg/svgStyles.js +96 -0
- package/dist/esm/text/AreaText.js +190 -0
- package/dist/esm/text/PathText.js +111 -0
- package/dist/esm/text/PointText.js +92 -0
- package/dist/esm/text/TextItem.js +538 -0
- package/dist/esm/text/TextRange.js +169 -0
- package/dist/esm/text/TextStory.js +394 -0
- package/dist/esm/text/areaLayout.js +439 -0
- package/dist/esm/text/layout.js +265 -0
- package/dist/esm/text/measure.js +57 -0
- package/dist/esm/text/pathLayout.js +93 -0
- package/dist/esm/tool/Tool.js +284 -0
- package/dist/esm/tool/ToolEvent.js +232 -0
- package/dist/esm/util/Formatter.js +57 -0
- package/dist/esm/util/collisions.js +216 -0
- package/dist/esm/util/list.js +110 -0
- package/dist/esm/util/numerical.js +656 -0
- package/dist/esm/util/object.js +81 -0
- package/dist/esm/util/string.js +29 -0
- package/dist/esm/util/uid.js +31 -0
- package/dist/esm/values/arcs.js +243 -0
- package/dist/esm/values/curve.js +975 -0
- package/dist/esm/values/fit.js +290 -0
- package/dist/esm/values/index.js +23 -0
- package/dist/esm/values/intersections.js +869 -0
- package/dist/esm/values/matrix.js +114 -0
- package/dist/esm/values/path.js +174 -0
- package/dist/esm/values/profile.js +221 -0
- package/dist/esm/values/region.js +63 -0
- package/dist/esm/values/smooth.js +248 -0
- package/dist/esm/values/svg.js +287 -0
- package/dist/esm/view/CanvasView.js +106 -0
- package/dist/esm/view/View.js +775 -0
- package/dist/esm/view/input.js +527 -0
- package/dist/paper-full.js +32941 -26371
- package/dist/paper-full.min.js +36 -31
- package/dist/paper-hosted.js +33623 -27236
- package/dist/paper-hosted.min.js +37 -0
- package/dist/paper-slim.js +28581 -0
- package/dist/paper-slim.min.js +17 -0
- package/dist/types/anim/Tween.d.ts +164 -0
- package/dist/types/basic/Line.d.ts +136 -0
- package/dist/types/basic/Matrix.d.ts +387 -0
- package/dist/types/basic/Point.d.ts +781 -0
- package/dist/types/basic/Rectangle.d.ts +550 -0
- package/dist/types/basic/Size.d.ts +457 -0
- package/dist/types/boolean/graph.d.ts +123 -0
- package/dist/types/boolean/index.d.ts +74 -0
- package/dist/types/boolean/operations.d.ts +9 -0
- package/dist/types/boolean/split.d.ts +19 -0
- package/dist/types/canvas/blendModes.d.ts +18 -0
- package/dist/types/canvas/canvasProvider.d.ts +32 -0
- package/dist/types/constants.d.ts +112 -0
- package/dist/types/core/Base.d.ts +50 -0
- package/dist/types/core/Emitter.d.ts +49 -0
- package/dist/types/core/features.d.ts +41 -0
- package/dist/types/core/serialization.d.ts +44 -0
- package/dist/types/core.d.ts +18 -0
- package/dist/types/dom/domElement.d.ts +33 -0
- package/dist/types/dom/domEvent.d.ts +29 -0
- package/dist/types/env.d.ts +26 -0
- package/dist/types/event/DrawEvent.d.ts +27 -0
- package/dist/types/event/Event.d.ts +47 -0
- package/dist/types/event/Key.d.ts +82 -0
- package/dist/types/event/KeyEvent.d.ts +35 -0
- package/dist/types/event/MouseEvent.d.ts +78 -0
- package/dist/types/hosted/HostItem.d.ts +26 -0
- package/dist/types/hosted/Hosting.d.ts +273 -0
- package/dist/types/hosted/index.d.ts +10 -0
- package/dist/types/index.d.ts +64 -0
- package/dist/types/internal.d.ts +101 -0
- package/dist/types/item/Effect.d.ts +128 -0
- package/dist/types/item/EffectInstance.d.ts +81 -0
- package/dist/types/item/Group.d.ts +225 -0
- package/dist/types/item/HitResult.d.ts +94 -0
- package/dist/types/item/Item.d.ts +2927 -0
- package/dist/types/item/ItemDefinition.d.ts +25 -0
- package/dist/types/item/Layer.d.ts +80 -0
- package/dist/types/item/Project.d.ts +748 -0
- package/dist/types/item/Raster.d.ts +431 -0
- package/dist/types/item/Shape.d.ts +219 -0
- package/dist/types/item/SymbolDefinition.d.ts +98 -0
- package/dist/types/item/SymbolItem.d.ts +92 -0
- package/dist/types/item/bounds.d.ts +56 -0
- package/dist/types/item/draw.d.ts +23 -0
- package/dist/types/item/effects.d.ts +22 -0
- package/dist/types/item/expand.d.ts +7 -0
- package/dist/types/item/hitTest.d.ts +10 -0
- package/dist/types/item/hosting.d.ts +20 -0
- package/dist/types/item/props.d.ts +35 -0
- package/dist/types/item/query.d.ts +14 -0
- package/dist/types/item/sampling.d.ts +5 -0
- package/dist/types/item/transform.d.ts +3 -0
- package/dist/types/net/http.d.ts +6 -0
- package/dist/types/node/CanvasAdapter.d.ts +19 -0
- package/dist/types/node/index.d.ts +60 -0
- package/dist/types/node/peers.d.ts +2 -0
- package/dist/types/offset/curves.d.ts +22 -0
- package/dist/types/offset/index.d.ts +65 -0
- package/dist/types/offset/offset.d.ts +18 -0
- package/dist/types/offset/outline.d.ts +14 -0
- package/dist/types/offset/pen.d.ts +36 -0
- package/dist/types/offset/profile.d.ts +37 -0
- package/dist/types/offset/round.d.ts +18 -0
- package/dist/types/offset/sweep.d.ts +44 -0
- package/dist/types/paperscript/PaperScript.d.ts +114 -0
- package/dist/types/paperscript/autoload.d.ts +1 -0
- package/dist/types/paperscript/index.d.ts +7 -0
- package/dist/types/path/CompoundPath.d.ts +183 -0
- package/dist/types/path/Curve.d.ts +567 -0
- package/dist/types/path/CurveLocation.d.ts +164 -0
- package/dist/types/path/Path.d.ts +1361 -0
- package/dist/types/path/PathFlattener.d.ts +48 -0
- package/dist/types/path/PathItem.d.ts +1190 -0
- package/dist/types/path/Segment.d.ts +335 -0
- package/dist/types/path/SegmentPoint.d.ts +1 -0
- package/dist/types/path/StrokeProfile.d.ts +74 -0
- package/dist/types/path/StrokeProfileStop.d.ts +110 -0
- package/dist/types/path/boolean.d.ts +24 -0
- package/dist/types/path/bounds.d.ts +24 -0
- package/dist/types/path/crossing.d.ts +2 -0
- package/dist/types/path/draw.d.ts +6 -0
- package/dist/types/path/hitTest.d.ts +8 -0
- package/dist/types/path/offset.d.ts +14 -0
- package/dist/types/path/shapes.d.ts +20 -0
- package/dist/types/path/smooth.d.ts +18 -0
- package/dist/types/path/values.d.ts +8 -0
- package/dist/types/scope/PaperScope.d.ts +182 -0
- package/dist/types/scope/PaperScopeItem.d.ts +26 -0
- package/dist/types/smoothing/index.d.ts +26 -0
- package/dist/types/style/Color.d.ts +829 -0
- package/dist/types/style/Gradient.d.ts +130 -0
- package/dist/types/style/GradientStop.d.ts +126 -0
- package/dist/types/style/PatternDefinition.d.ts +185 -0
- package/dist/types/style/Style.d.ts +757 -0
- package/dist/types/svg/index.d.ts +14 -0
- package/dist/types/svg/svgElement.d.ts +32 -0
- package/dist/types/svg/svgExport.d.ts +19 -0
- package/dist/types/svg/svgImport.d.ts +13 -0
- package/dist/types/svg/svgStyles.d.ts +20 -0
- package/dist/types/text/AreaText.d.ts +104 -0
- package/dist/types/text/PathText.d.ts +78 -0
- package/dist/types/text/PointText.d.ts +50 -0
- package/dist/types/text/TextItem.d.ts +163 -0
- package/dist/types/text/TextRange.d.ts +98 -0
- package/dist/types/text/TextStory.d.ts +119 -0
- package/dist/types/text/areaLayout.d.ts +3 -0
- package/dist/types/text/layout.d.ts +43 -0
- package/dist/types/text/measure.d.ts +7 -0
- package/dist/types/text/pathLayout.d.ts +3 -0
- package/dist/types/tool/Tool.d.ts +356 -0
- package/dist/types/tool/ToolEvent.d.ts +134 -0
- package/dist/types/util/Formatter.d.ts +34 -0
- package/dist/types/util/collisions.d.ts +77 -0
- package/dist/types/util/list.d.ts +23 -0
- package/dist/types/util/numerical.d.ts +196 -0
- package/dist/types/util/object.d.ts +19 -0
- package/dist/types/util/string.d.ts +12 -0
- package/dist/types/util/uid.d.ts +7 -0
- package/dist/types/values/arcs.d.ts +10 -0
- package/dist/types/values/curve.d.ts +42 -0
- package/dist/types/values/fit.d.ts +26 -0
- package/dist/types/values/index.d.ts +10 -0
- package/dist/types/values/intersections.d.ts +11 -0
- package/dist/types/values/matrix.d.ts +19 -0
- package/dist/types/values/path.d.ts +26 -0
- package/dist/types/values/profile.d.ts +41 -0
- package/dist/types/values/region.d.ts +13 -0
- package/dist/types/values/smooth.d.ts +39 -0
- package/dist/types/values/svg.d.ts +47 -0
- package/dist/types/view/CanvasView.d.ts +37 -0
- package/dist/types/view/View.d.ts +700 -0
- package/dist/types/view/input.d.ts +28 -0
- package/package.json +89 -59
- package/dist/docs/assets/css/docs.css +0 -414
- package/dist/docs/assets/js/codemirror.js +0 -4
- package/dist/docs/assets/js/docs.js +0 -493
- package/dist/docs/assets/js/jquery.js +0 -6
- package/dist/docs/assets/js/paper.js +0 -27591
- package/dist/docs/classes/AreaText.html +0 -9186
- package/dist/docs/classes/ChangeFlag.html +0 -385
- package/dist/docs/classes/Color.html +0 -2402
- package/dist/docs/classes/CompoundPath.html +0 -10018
- package/dist/docs/classes/Curve.html +0 -2326
- package/dist/docs/classes/CurveLocation.html +0 -673
- package/dist/docs/classes/DrawEvent.html +0 -69
- package/dist/docs/classes/Effect.html +0 -434
- package/dist/docs/classes/EffectInstance.html +0 -304
- package/dist/docs/classes/Event.html +0 -177
- package/dist/docs/classes/Gradient.html +0 -241
- package/dist/docs/classes/GradientStop.html +0 -274
- package/dist/docs/classes/Group.html +0 -7688
- package/dist/docs/classes/HitResult.html +0 -241
- package/dist/docs/classes/HostItem.html +0 -7314
- package/dist/docs/classes/Item.html +0 -7427
- package/dist/docs/classes/Key.html +0 -140
- package/dist/docs/classes/KeyEvent.html +0 -309
- package/dist/docs/classes/Layer.html +0 -7671
- package/dist/docs/classes/Matrix.html +0 -1745
- package/dist/docs/classes/MouseEvent.html +0 -356
- package/dist/docs/classes/PaperScope.html +0 -548
- package/dist/docs/classes/PaperScript.html +0 -204
- package/dist/docs/classes/Path.html +0 -13007
- package/dist/docs/classes/PathItem.html +0 -9780
- package/dist/docs/classes/PathText.html +0 -9056
- package/dist/docs/classes/PatternDefinition.html +0 -367
- package/dist/docs/classes/Point.html +0 -2860
- package/dist/docs/classes/PointText.html +0 -8967
- package/dist/docs/classes/Project.html +0 -1774
- package/dist/docs/classes/Raster.html +0 -8547
- package/dist/docs/classes/Rectangle.html +0 -1698
- package/dist/docs/classes/Segment.html +0 -1017
- package/dist/docs/classes/Shape.html +0 -8048
- package/dist/docs/classes/Size.html +0 -1915
- package/dist/docs/classes/StrokeProfileStop.html +0 -346
- package/dist/docs/classes/Style.html +0 -1765
- package/dist/docs/classes/SymbolDefinition.html +0 -338
- package/dist/docs/classes/SymbolItem.html +0 -7477
- package/dist/docs/classes/TextItem.html +0 -8810
- package/dist/docs/classes/TextRange.html +0 -186
- package/dist/docs/classes/TextStory.html +0 -355
- package/dist/docs/classes/Tool.html +0 -888
- package/dist/docs/classes/ToolEvent.html +0 -525
- package/dist/docs/classes/Tween.html +0 -390
- package/dist/docs/classes/View.html +0 -2108
- package/dist/docs/classes/global.html +0 -426
- package/dist/docs/classes/index.html +0 -88
- package/dist/docs/index.html +0 -11
- package/dist/node/browser.js +0 -15
- package/dist/node/canvas.js +0 -68
- package/dist/node/extend.js +0 -156
- package/dist/node/self.js +0 -67
- package/dist/paper-core.d.ts +0 -1
- package/dist/paper-core.js +0 -25636
- package/dist/paper-core.min.js +0 -32
- package/dist/paper.d.ts +0 -10481
- package/examples/Animated/AnimatedStar.html +0 -53
- package/examples/Animated/BooleanOperations.html +0 -115
- package/examples/Animated/CandyCrash.html +0 -151
- package/examples/Animated/Extruded.html +0 -50
- package/examples/Animated/Lines.html +0 -53
- package/examples/Animated/Smoothing.html +0 -70
- package/examples/Animated/Space.html +0 -86
- package/examples/Animated/SpaceUsingShapes.html +0 -79
- package/examples/Games/Paperoids.html +0 -569
- package/examples/JSON/Circle Testing.html +0 -34
- package/examples/JSON/Compound Path.html +0 -25
- package/examples/JSON/Empty Path Testing.html +0 -31
- package/examples/JSON/Gradients.html +0 -34
- package/examples/JSON/Group Transform.html +0 -28
- package/examples/JSON/Line Testing.html +0 -44
- package/examples/JSON/Random Path Testing.html +0 -42
- package/examples/JSON/Raster.html +0 -29
- package/examples/JSON/Rect and Attribute Testing.html +0 -56
- package/examples/JSON/Rotated Primitives.html +0 -55
- package/examples/JSON/Selection.html +0 -43
- package/examples/JSON/Shapes.html +0 -54
- package/examples/JSON/Symbols.html +0 -30
- package/examples/JSON/Text Testing.html +0 -38
- package/examples/JSON/Tiger.html +0 -19
- package/examples/JSON/Transform Test 1.html +0 -32
- package/examples/JSON/Transform Test 2.html +0 -30
- package/examples/Node.js/AnimatedStar.js +0 -52
- package/examples/Node.js/BooleanOperations.js +0 -36
- package/examples/Node.js/JSONtoPDF.js +0 -20
- package/examples/Node.js/Raster.js +0 -32
- package/examples/Node.js/RasterRemote.js +0 -33
- package/examples/Node.js/SvgExport.js +0 -52
- package/examples/Node.js/SvgImport.js +0 -23
- package/examples/Node.js/Tadpoles.js +0 -16
- package/examples/Node.js/Tadpoles.pjs +0 -278
- package/examples/Node.js/in.json +0 -1
- package/examples/Node.js/in.svg +0 -16
- package/examples/Paperjs.org/BooleanOperattions.html +0 -115
- package/examples/Paperjs.org/BouncingBalls.html +0 -103
- package/examples/Paperjs.org/Chain.html +0 -54
- package/examples/Paperjs.org/DivisionRaster.html +0 -72
- package/examples/Paperjs.org/FutureSplash.html +0 -122
- package/examples/Paperjs.org/HitTesting.html +0 -103
- package/examples/Paperjs.org/InteractiveTiger.html +0 -777
- package/examples/Paperjs.org/LiveEffects.html +0 -366
- package/examples/Paperjs.org/MetaBalls.html +0 -132
- package/examples/Paperjs.org/NyanRainbow.html +0 -202
- package/examples/Paperjs.org/Offsetting.html +0 -379
- package/examples/Paperjs.org/PathIntersections.html +0 -76
- package/examples/Paperjs.org/Qbertify.html +0 -146
- package/examples/Paperjs.org/RadialRainbows.html +0 -80
- package/examples/Paperjs.org/RoundedRectangles.html +0 -41
- package/examples/Paperjs.org/SatieLikedToDraw.html +0 -140
- package/examples/Paperjs.org/Simplify.html +0 -63
- package/examples/Paperjs.org/SpiralRaster.html +0 -120
- package/examples/Paperjs.org/StrokeProfiles.html +0 -706
- package/examples/Paperjs.org/Tadpoles.html +0 -283
- package/examples/Paperjs.org/Voronoi.html +0 -134
- package/examples/Rasters/PhyllotaxisRaster.html +0 -96
- package/examples/Rasters/Raster.html +0 -34
- package/examples/Rasters/RotationRaster.html +0 -44
- package/examples/Rasters/Smoothing.html +0 -36
- package/examples/SVG Export/Circle Testing.html +0 -32
- package/examples/SVG Export/Clipping.html +0 -17
- package/examples/SVG Export/Compound Path.html +0 -22
- package/examples/SVG Export/Empty Path Testing.html +0 -28
- package/examples/SVG Export/Gradients.html +0 -52
- package/examples/SVG Export/Group Transform.html +0 -25
- package/examples/SVG Export/Line Testing.html +0 -41
- package/examples/SVG Export/Random Path Testing.html +0 -39
- package/examples/SVG Export/Raster.html +0 -21
- package/examples/SVG Export/Rect and Attribute Testing.html +0 -53
- package/examples/SVG Export/Rotated Primitives.html +0 -80
- package/examples/SVG Export/Shapes.html +0 -58
- package/examples/SVG Export/Symbols.html +0 -27
- package/examples/SVG Export/Text Testing.html +0 -45
- package/examples/SVG Export/Tiger.html +0 -23
- package/examples/SVG Export/Transform Test 1.html +0 -29
- package/examples/SVG Export/Transform Test 2.html +0 -27
- package/examples/SVG Import/Arcs.html +0 -78
- package/examples/SVG Import/Butterfly.html +0 -223
- package/examples/SVG Import/Circle and Ellipse Testing.html +0 -26
- package/examples/SVG Import/Clipping.html +0 -100
- package/examples/SVG Import/From File.html +0 -30
- package/examples/SVG Import/Gradient.html +0 -138
- package/examples/SVG Import/Gradients.html +0 -30
- package/examples/SVG Import/Inkscape Pivot.html +0 -52
- package/examples/SVG Import/Inkscape.html +0 -88
- package/examples/SVG Import/Line Testing.html +0 -24
- package/examples/SVG Import/MoreGradients.html +0 -107
- package/examples/SVG Import/Multiple Paths Test 1.html +0 -42
- package/examples/SVG Import/Multiple Paths Test 2.html +0 -33
- package/examples/SVG Import/Nested Groups Test.html +0 -78
- package/examples/SVG Import/Polybezier.html +0 -43
- package/examples/SVG Import/Rect Testing.html +0 -25
- package/examples/SVG Import/Symbols.html +0 -24
- package/examples/SVG Import/Testing.html +0 -40
- package/examples/SVG Import/Text Testing.html +0 -19
- package/examples/SVG Import/Tiger.html +0 -742
- package/examples/SVG Import/Transform Testing.html +0 -22
- package/examples/SVG Import/Viewbox.html +0 -38
- package/examples/Scripts/Arcs.html +0 -39
- package/examples/Scripts/AreaText.html +0 -65
- package/examples/Scripts/BlendModes.html +0 -77
- package/examples/Scripts/BooleanOperations.html +0 -937
- package/examples/Scripts/CompoundPath.html +0 -19
- package/examples/Scripts/CurveTimeParameterization.html +0 -61
- package/examples/Scripts/HslColor.html +0 -53
- package/examples/Scripts/PathStructure.html +0 -82
- package/examples/Scripts/PathTangents.html +0 -73
- package/examples/Scripts/PathText.html +0 -48
- package/examples/Scripts/Patterns.html +0 -57
- package/examples/Scripts/Resize.html +0 -42
- package/examples/Scripts/RoundRectangle.html +0 -28
- package/examples/Scripts/Shapes.html +0 -54
- package/examples/Scripts/StrokeBounds.html +0 -101
- package/examples/Scripts/StrokeScaling.html +0 -65
- package/examples/Scripts/TextRanges.html +0 -51
- package/examples/Tools/BezierTool.html +0 -90
- package/examples/Tools/Circles.html +0 -28
- package/examples/Tools/Clouds.html +0 -35
- package/examples/Tools/DrippingBrush.html +0 -73
- package/examples/Tools/FancyBrush.html +0 -82
- package/examples/Tools/Grid.html +0 -44
- package/examples/Tools/MultiLines.html +0 -44
- package/examples/Tools/MultipleTools.html +0 -44
- package/examples/Tools/PathEditing.html +0 -95
- package/examples/Tools/SquareRounded.html +0 -76
- package/examples/Tools/Stars.html +0 -38
- package/examples/Tools/Vektor.html +0 -200
- package/examples/Tools/Wave.html +0 -50
- package/examples/Tools/WormFarm.html +0 -88
- package/examples/Worker/Main.html +0 -53
- package/examples/Worker/Worker.js +0 -14
- package/examples/css/style.css +0 -12
|
@@ -0,0 +1,161 @@
|
|
|
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 { SegmentSelection, paintItem } from "../internal.js";
|
|
13
|
+
export function drawPath(path, ctx, param, viewMatrix, strokeMatrix) {
|
|
14
|
+
ctx.beginPath();
|
|
15
|
+
if (path.hasFill() || path.hasStroke()) {
|
|
16
|
+
drawPathGeometry(path, ctx, strokeMatrix);
|
|
17
|
+
}
|
|
18
|
+
paintItem(path, ctx, param, viewMatrix, strokeMatrix);
|
|
19
|
+
}
|
|
20
|
+
// NOTE: See Item#_drawGeometry()
|
|
21
|
+
export function drawPathGeometry(path, ctx, matrix) {
|
|
22
|
+
drawSegments(ctx, path, matrix);
|
|
23
|
+
if (path._closed) {
|
|
24
|
+
ctx.closePath();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function drawPathSelection(path, ctx, matrix) {
|
|
28
|
+
ctx.beginPath();
|
|
29
|
+
drawSegments(ctx, path, matrix);
|
|
30
|
+
// Now stroke it and draw its handles:
|
|
31
|
+
ctx.stroke();
|
|
32
|
+
const { handleSize, segmentSize } = path._project._scope.settings;
|
|
33
|
+
// segmentSize is null by default, which falls back on handleSize:
|
|
34
|
+
drawHandles(ctx, path._segments, matrix, handleSize, segmentSize != null ? segmentSize : handleSize);
|
|
35
|
+
}
|
|
36
|
+
// Note that in the drawing code below we're often accessing _x and _y on
|
|
37
|
+
// point objects that were read from segments. This is because the
|
|
38
|
+
// SegmentPoint class overrides the plain x / y properties with getter /
|
|
39
|
+
// setters and stores the values in these private properties internally. To
|
|
40
|
+
// avoid calling of getter functions all the time we directly access these
|
|
41
|
+
// private properties here. The distinction between normal Point objects and
|
|
42
|
+
// SegmentPoint objects maybe seem a bit tedious but is worth the benefit in
|
|
43
|
+
// performance.
|
|
44
|
+
function drawHandles(ctx, segments, matrix, handleSize, segmentSize) {
|
|
45
|
+
// Only draw the handles and segments whose size is positive.
|
|
46
|
+
const handleHalf = handleSize / 2;
|
|
47
|
+
const half = segmentSize / 2;
|
|
48
|
+
const miniSize = segmentSize - 2;
|
|
49
|
+
const miniHalf = half - 1;
|
|
50
|
+
const coords = new Array(6);
|
|
51
|
+
let pX;
|
|
52
|
+
let pY;
|
|
53
|
+
function drawHandle(index) {
|
|
54
|
+
const hX = coords[index];
|
|
55
|
+
const hY = coords[index + 1];
|
|
56
|
+
if (handleSize > 0 && (pX !== hX || pY !== hY)) {
|
|
57
|
+
ctx.beginPath();
|
|
58
|
+
ctx.moveTo(pX, pY);
|
|
59
|
+
ctx.lineTo(hX, hY);
|
|
60
|
+
ctx.stroke();
|
|
61
|
+
ctx.beginPath();
|
|
62
|
+
ctx.arc(hX, hY, handleHalf, 0, Math.PI * 2, true);
|
|
63
|
+
ctx.fill();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (let i = 0, l = segments.length; i < l; i++) {
|
|
67
|
+
const segment = segments[i];
|
|
68
|
+
const selection = segment._selection;
|
|
69
|
+
segment._transformCoordinates(matrix, coords);
|
|
70
|
+
pX = coords[0];
|
|
71
|
+
pY = coords[1];
|
|
72
|
+
if (selection & SegmentSelection.HANDLE_IN) {
|
|
73
|
+
drawHandle(2);
|
|
74
|
+
}
|
|
75
|
+
if (selection & SegmentSelection.HANDLE_OUT) {
|
|
76
|
+
drawHandle(4);
|
|
77
|
+
}
|
|
78
|
+
if (segmentSize > 0) {
|
|
79
|
+
// Draw a rectangle at segment.point:
|
|
80
|
+
ctx.fillRect(pX - half, pY - half, segmentSize, segmentSize);
|
|
81
|
+
// If the point is not selected, draw a white square that is 1px
|
|
82
|
+
// smaller on all sides, but only draw it if size is big enough.
|
|
83
|
+
if (miniSize > 0 && !(selection & SegmentSelection.POINT)) {
|
|
84
|
+
const { fillStyle } = ctx;
|
|
85
|
+
ctx.fillStyle = '#ffffff';
|
|
86
|
+
ctx.fillRect(pX - miniHalf, pY - miniHalf, miniSize, miniSize);
|
|
87
|
+
ctx.fillStyle = fillStyle;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function drawSegments(ctx, path, matrix) {
|
|
93
|
+
const segments = path._segments;
|
|
94
|
+
const { length } = segments;
|
|
95
|
+
const coords = new Array(6);
|
|
96
|
+
let first = true;
|
|
97
|
+
let curX;
|
|
98
|
+
let curY;
|
|
99
|
+
let prevX;
|
|
100
|
+
let prevY;
|
|
101
|
+
let inX;
|
|
102
|
+
let inY;
|
|
103
|
+
let outX;
|
|
104
|
+
let outY;
|
|
105
|
+
function drawSegment(segment) {
|
|
106
|
+
let handle;
|
|
107
|
+
// Optimise code when no matrix is provided by accessing segment
|
|
108
|
+
// points hand handles directly, since this is the default when
|
|
109
|
+
// drawing paths. Matrix is only used for drawing selections and
|
|
110
|
+
// when #strokeScaling is false.
|
|
111
|
+
if (matrix) {
|
|
112
|
+
segment._transformCoordinates(matrix, coords);
|
|
113
|
+
curX = coords[0];
|
|
114
|
+
curY = coords[1];
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const point = segment._point;
|
|
118
|
+
curX = point._x;
|
|
119
|
+
curY = point._y;
|
|
120
|
+
}
|
|
121
|
+
if (first) {
|
|
122
|
+
ctx.moveTo(curX, curY);
|
|
123
|
+
first = false;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
if (matrix) {
|
|
127
|
+
inX = coords[2];
|
|
128
|
+
inY = coords[3];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
handle = segment._handleIn;
|
|
132
|
+
inX = curX + handle._x;
|
|
133
|
+
inY = curY + handle._y;
|
|
134
|
+
}
|
|
135
|
+
if (inX === curX && inY === curY && outX === prevX && outY === prevY) {
|
|
136
|
+
ctx.lineTo(curX, curY);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
ctx.bezierCurveTo(outX, outY, inX, inY, curX, curY);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
prevX = curX;
|
|
143
|
+
prevY = curY;
|
|
144
|
+
if (matrix) {
|
|
145
|
+
outX = coords[4];
|
|
146
|
+
outY = coords[5];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
handle = segment._handleOut;
|
|
150
|
+
outX = prevX + handle._x;
|
|
151
|
+
outY = prevY + handle._y;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (let i = 0; i < length; i++) {
|
|
155
|
+
drawSegment(segments[i]);
|
|
156
|
+
}
|
|
157
|
+
// Close path by drawing first segment again
|
|
158
|
+
if (path._closed && length > 0) {
|
|
159
|
+
drawSegment(segments[0]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
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, CurveLocation, EPSILON, HitResult, Matrix, Path, Point, Segment, Size, addBevelJoin, addSquareCap, getCurvePoint, getCurveValues, getNearestCurveTime } from "../internal.js";
|
|
13
|
+
/**
|
|
14
|
+
* Hit-tests the path, see Item#hitTest().
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export function hitTestPath(path, point, options, viewMatrix, strokeMatrix) {
|
|
19
|
+
let i;
|
|
20
|
+
let l;
|
|
21
|
+
const { style } = path;
|
|
22
|
+
// HitResult.getOptions() and Item#_hitTest() set these:
|
|
23
|
+
const tolerance = options.tolerance;
|
|
24
|
+
const segments = path._segments;
|
|
25
|
+
const numSegments = segments.length;
|
|
26
|
+
const closed = path._closed;
|
|
27
|
+
// Measure where the stroke is drawn with a round pen: for
|
|
28
|
+
// non-scaling strokes in the view's coordinates, through the
|
|
29
|
+
// inverted strokeMatrix that Item#_hitTest() passes, otherwise in
|
|
30
|
+
// the item's own. Curve times are the same in both (#2334):
|
|
31
|
+
const strokeSpace = strokeMatrix?.inverted();
|
|
32
|
+
const strokePoint = point.transform(strokeSpace);
|
|
33
|
+
// The tolerance padding in that space, see Item#_hitTest(): for
|
|
34
|
+
// non-scaling strokes, the tolerance of the project in the view's
|
|
35
|
+
// coordinates. The stroke padding is added on top of it below.
|
|
36
|
+
const tolerancePadding = strokeSpace
|
|
37
|
+
? new Size(Matrix._getCircleExtents(Math.max(tolerance, EPSILON), path.view._matrix._shiftless()))
|
|
38
|
+
: options._tolerancePadding;
|
|
39
|
+
let strokePadding = tolerancePadding;
|
|
40
|
+
// Round, unless the stroke has its own:
|
|
41
|
+
let join = 'round';
|
|
42
|
+
let cap = 'round';
|
|
43
|
+
let miterLimit = 0;
|
|
44
|
+
let loc = null;
|
|
45
|
+
let res;
|
|
46
|
+
// When collecting all hits for hitTestAll(), we report every
|
|
47
|
+
// segment and handle in range, not just the first one:
|
|
48
|
+
const hits = options.all ? [] : null;
|
|
49
|
+
const hitStroke = options.stroke && style.hasStroke();
|
|
50
|
+
// Transparent fills are hit too, only no fill isn't, as in SVG
|
|
51
|
+
// (#1157):
|
|
52
|
+
const hitFill = options.fill && !!style.fillColor;
|
|
53
|
+
const hitCurves = options.curves;
|
|
54
|
+
const strokeRadius = hitStroke
|
|
55
|
+
? style.strokeWidth / 2
|
|
56
|
+
: // Set radius to 0 when we're hit-testing fills with
|
|
57
|
+
// tolerance, to handle tolerance through stroke hit-test
|
|
58
|
+
// functionality. Also use 0 when hit-testing curves.
|
|
59
|
+
hitFill && tolerance > 0 || hitCurves
|
|
60
|
+
? 0
|
|
61
|
+
: null;
|
|
62
|
+
if (strokeRadius !== null) {
|
|
63
|
+
if (strokeRadius > 0) {
|
|
64
|
+
join = style.strokeJoin;
|
|
65
|
+
cap = style.strokeCap;
|
|
66
|
+
miterLimit = style.miterLimit;
|
|
67
|
+
// Add the stroke radius to tolerance padding, which is round
|
|
68
|
+
// where the stroke is measured:
|
|
69
|
+
strokePadding = strokePadding.add(strokeRadius);
|
|
70
|
+
}
|
|
71
|
+
// Using tolerance padding for fill tests will also work if there is
|
|
72
|
+
// no stroke, in which case radius = 0 and we will test for stroke
|
|
73
|
+
// locations to extend the fill area by tolerance.
|
|
74
|
+
}
|
|
75
|
+
// Checks a point where the stroke is measured, see strokeSpace:
|
|
76
|
+
function isCloseEnough(pt, padding) {
|
|
77
|
+
return strokePoint.subtract(pt).divide(padding).length <= 1;
|
|
78
|
+
}
|
|
79
|
+
function checkSegmentPoint(seg, pt, name) {
|
|
80
|
+
if (!options.selected || pt.selected) {
|
|
81
|
+
// Handles are relative to their anchor:
|
|
82
|
+
const anchor = seg._point;
|
|
83
|
+
const point = pt === anchor ? pt : pt.add(anchor);
|
|
84
|
+
if (isCloseEnough(point.transform(strokeSpace), strokePadding)) {
|
|
85
|
+
const hit = new HitResult(name, path, { segment: seg, point });
|
|
86
|
+
if (!hits)
|
|
87
|
+
return hit;
|
|
88
|
+
hits.push(hit);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function checkSegmentPoints(seg, ends) {
|
|
93
|
+
// Note, when checking for ends, we don't also check for handles,
|
|
94
|
+
// since this will happen afterwards in a separate loop, see below.
|
|
95
|
+
return (((ends || options.segments) &&
|
|
96
|
+
checkSegmentPoint(seg, seg._point, 'segment')) || (!ends &&
|
|
97
|
+
options.handles && (checkSegmentPoint(seg, seg._handleIn, 'handle-in') ||
|
|
98
|
+
checkSegmentPoint(seg, seg._handleOut, 'handle-out'))));
|
|
99
|
+
}
|
|
100
|
+
// Code to check stroke join / cap areas
|
|
101
|
+
// Returns the tangent where the curve meets the segment, looking past
|
|
102
|
+
// curves without length, which have no direction:
|
|
103
|
+
function getJoinTangent(curve, forward) {
|
|
104
|
+
for (let i = 0; curve && i < numSegments; i++) {
|
|
105
|
+
if (curve.hasLength())
|
|
106
|
+
return curve.getTangentAtTime(forward ? 0 : 1);
|
|
107
|
+
curve = forward ? curve.next : curve.previous;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function isFlatJoin(segment) {
|
|
111
|
+
// Joins lie between two curves:
|
|
112
|
+
const curve = segment.curve;
|
|
113
|
+
const tangent1 = getJoinTangent(curve.previous, false);
|
|
114
|
+
const tangent2 = getJoinTangent(curve, true);
|
|
115
|
+
return (tangent1 &&
|
|
116
|
+
tangent2 &&
|
|
117
|
+
tangent1.isCollinear(tangent2) &&
|
|
118
|
+
tangent1.dot(tangent2) > 0);
|
|
119
|
+
}
|
|
120
|
+
function checkSegmentStroke(segment, radius) {
|
|
121
|
+
// Handle joins / caps that are not round specifically, by
|
|
122
|
+
// hit-testing their polygon areas.
|
|
123
|
+
const isJoin = (closed ||
|
|
124
|
+
segment._index > 0 && segment._index < numSegments - 1);
|
|
125
|
+
// Smooth segments are always joined round, as in addJoin() in
|
|
126
|
+
// getSegmentStrokeBounds(), and so are segments where the curves meet
|
|
127
|
+
// in the same direction, such as a line running into a curve, as the
|
|
128
|
+
// join adds nothing there:
|
|
129
|
+
if (isJoin && (segment.isSmooth() || isFlatJoin(segment)) ||
|
|
130
|
+
(isJoin ? join : cap) === 'round') {
|
|
131
|
+
// Round join / cap is easy to handle.
|
|
132
|
+
return isCloseEnough(segment._point.transform(strokeSpace), strokePadding);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// Create an 'internal' path without id and outside the scene
|
|
136
|
+
// graph to run the hit-test on it, where the stroke is
|
|
137
|
+
// measured.
|
|
138
|
+
const area = new Path({ internal: true, closed: true });
|
|
139
|
+
const addToArea = (point) => area.add(point);
|
|
140
|
+
if (isJoin) {
|
|
141
|
+
// addBevelJoin() handles both 'bevel' and 'miter'.
|
|
142
|
+
addBevelJoin(segment, join, radius, miterLimit, strokeSpace, null, addToArea, true);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
// addSquareCap() handles both 'square' and 'butt' caps.
|
|
146
|
+
addSquareCap(segment, cap, radius, strokeSpace, null, addToArea, true);
|
|
147
|
+
}
|
|
148
|
+
// See if the above produced an area to check for
|
|
149
|
+
if (!area.isEmpty()) {
|
|
150
|
+
// Also use stroke check with tolerancePadding if the point
|
|
151
|
+
// is not inside the area itself, to use test caps and joins
|
|
152
|
+
// with same tolerance.
|
|
153
|
+
let loc;
|
|
154
|
+
return (area.contains(strokePoint) || ((loc = area.getNearestLocation(strokePoint)) &&
|
|
155
|
+
isCloseEnough(loc.point, tolerancePadding)));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// If we're asked to query for segments, ends or handles, do all that
|
|
160
|
+
// before stroke or fill.
|
|
161
|
+
if (options.ends && !options.segments && !closed) {
|
|
162
|
+
if ((res = (checkSegmentPoints(segments[0], true) ||
|
|
163
|
+
checkSegmentPoints(segments[numSegments - 1], true))))
|
|
164
|
+
return res;
|
|
165
|
+
}
|
|
166
|
+
else if (options.segments || options.handles) {
|
|
167
|
+
for (i = 0; i < numSegments; i++) {
|
|
168
|
+
if ((res = checkSegmentPoints(segments[i])))
|
|
169
|
+
return res;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// If we're querying for stroke, perform that before fill
|
|
173
|
+
if (strokeRadius !== null) {
|
|
174
|
+
// Find the nearest location where the stroke is measured, as
|
|
175
|
+
// PathItem#getNearestLocation() does in the item's coordinates:
|
|
176
|
+
const { curves } = path;
|
|
177
|
+
let minDistance = Infinity;
|
|
178
|
+
// Set along with loc:
|
|
179
|
+
let nearest;
|
|
180
|
+
for (i = 0, l = curves.length; i < l; i++) {
|
|
181
|
+
const { _segment1, _segment2 } = curves[i];
|
|
182
|
+
const values = getCurveValues(_segment1, _segment2, strokeSpace);
|
|
183
|
+
const t = getNearestCurveTime(values, strokePoint);
|
|
184
|
+
const pt = getCurvePoint(values, t);
|
|
185
|
+
const distance = pt.getDistance(strokePoint);
|
|
186
|
+
if (distance < minDistance) {
|
|
187
|
+
minDistance = distance;
|
|
188
|
+
loc = new CurveLocation(curves[i], t);
|
|
189
|
+
nearest = pt;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Note that paths need at least two segments to have an actual
|
|
193
|
+
// stroke. But we still check for segments with the radius fallback
|
|
194
|
+
// check if there is only one segment.
|
|
195
|
+
// Stroke profiles are hit within the outline of their stroke:
|
|
196
|
+
const outline = (hitStroke &&
|
|
197
|
+
path._hasStrokeProfile() &&
|
|
198
|
+
path._getStrokeOutline());
|
|
199
|
+
if (loc && outline) {
|
|
200
|
+
if (!outline.contains(strokePoint) &&
|
|
201
|
+
// The outline of a path with curves has curves too:
|
|
202
|
+
!isCloseEnough(outline.getNearestPoint(strokePoint), tolerancePadding)) {
|
|
203
|
+
loc = null;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (loc) {
|
|
207
|
+
// Now see if we're on a segment, and if so, check for its
|
|
208
|
+
// stroke join / cap first. If not, do a normal radius check
|
|
209
|
+
// for round strokes.
|
|
210
|
+
const { time } = loc;
|
|
211
|
+
if (time === 0 || time === 1 && numSegments > 1) {
|
|
212
|
+
if (!checkSegmentStroke(loc.segment, strokeRadius)) {
|
|
213
|
+
loc = null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else if (!isCloseEnough(nearest, strokePadding)) {
|
|
217
|
+
loc = null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// If we have miter joins, we may not be done yet, since they can be
|
|
221
|
+
// longer than the radius. Check for each segment within reach now.
|
|
222
|
+
if (!loc && !outline && join === 'miter' && numSegments > 1) {
|
|
223
|
+
for (i = 0; i < numSegments; i++) {
|
|
224
|
+
const segment = segments[i];
|
|
225
|
+
if ((strokePoint.getDistance(segment._point.transform(strokeSpace)) <=
|
|
226
|
+
miterLimit * strokeRadius) &&
|
|
227
|
+
checkSegmentStroke(segment, strokeRadius)) {
|
|
228
|
+
loc = segment.location;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Don't process loc yet, as we also need to query for stroke after fill
|
|
235
|
+
// in some cases. Simply skip fill query if we already have a matching
|
|
236
|
+
// stroke. If we have a loc and no stroke then it's a result for fill.
|
|
237
|
+
res =
|
|
238
|
+
(!loc && hitFill && path._contains(point) ||
|
|
239
|
+
loc && !hitStroke && !hitCurves)
|
|
240
|
+
? new HitResult('fill', path)
|
|
241
|
+
: loc
|
|
242
|
+
? new HitResult(hitStroke ? 'stroke' : 'curve', path, {
|
|
243
|
+
location: loc,
|
|
244
|
+
// It's fine performance wise to read the point
|
|
245
|
+
// again since it was already calculated before.
|
|
246
|
+
point: loc.point
|
|
247
|
+
})
|
|
248
|
+
: null;
|
|
249
|
+
if (hits) {
|
|
250
|
+
// Report the closest segments and handles first, then the rest. They
|
|
251
|
+
// have their points:
|
|
252
|
+
hits.sort((hit1, hit2) => (hit1.point.getDistance(point) - hit2.point.getDistance(point)));
|
|
253
|
+
if (res) {
|
|
254
|
+
hits.push(res);
|
|
255
|
+
}
|
|
256
|
+
return hits;
|
|
257
|
+
}
|
|
258
|
+
return res;
|
|
259
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
// The offsets and stroke outlines of path items, through the outlines of
|
|
13
|
+
// strokes on plain paths, see outlineStroke().
|
|
14
|
+
import { Group, Path, Point, createPathItem, getAppliedCopy, getFeature, getLocalCopy, getPathValues, getRegion, getStrokeProfileEntries, placeResult } from "../internal.js";
|
|
15
|
+
const { abs } = Math;
|
|
16
|
+
export function offsetPathItem(item, distance, options) {
|
|
17
|
+
const { offsetRegion, offsetPath } = getFeature('offset');
|
|
18
|
+
const path = getAppliedCopy(item);
|
|
19
|
+
const paths = path._getPaths();
|
|
20
|
+
// The offset lies at the distance all along, whatever the stroke profiles
|
|
21
|
+
// of the paths, and takes over their stops:
|
|
22
|
+
const stops = distance ? takeProfileStops(paths) : [];
|
|
23
|
+
let result;
|
|
24
|
+
if (!distance) {
|
|
25
|
+
result = path;
|
|
26
|
+
}
|
|
27
|
+
else if (item._children || item._closed) {
|
|
28
|
+
// Closed and compound paths grow or shrink by the distance:
|
|
29
|
+
result = createPathItem(offsetRegion(getRegion(path), distance, options ?? {})).reduce();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Open paths move to the side of their normals:
|
|
33
|
+
result = createPathItem({
|
|
34
|
+
paths: offsetPath(getPathValues(paths[0]), distance, options ?? {}),
|
|
35
|
+
fillRule: path.fillRule
|
|
36
|
+
}).reduce();
|
|
37
|
+
}
|
|
38
|
+
if (stops.length) {
|
|
39
|
+
setOffsetProfiles(result, stops, abs(distance));
|
|
40
|
+
}
|
|
41
|
+
return placeResult(item, result, options);
|
|
42
|
+
}
|
|
43
|
+
export function outlinePathItem(item, options) {
|
|
44
|
+
const { width, join, cap, miterLimit, dashArray, dashOffset } = options ?? {};
|
|
45
|
+
// Strokes that scale are outlined in the item's own coordinates and
|
|
46
|
+
// transformed by its matrix, as they are drawn, also where it scales
|
|
47
|
+
// unevenly. Non-scaling strokes keep their width on the baked geometry:
|
|
48
|
+
const isScaling = item.strokeScaling;
|
|
49
|
+
let result;
|
|
50
|
+
if (!item._children &&
|
|
51
|
+
(isScaling || item._matrix.isIdentity()) &&
|
|
52
|
+
width == null &&
|
|
53
|
+
join == null &&
|
|
54
|
+
cap == null &&
|
|
55
|
+
miterLimit == null &&
|
|
56
|
+
dashArray == null &&
|
|
57
|
+
dashOffset == null) {
|
|
58
|
+
// Paths keep the outline of their own stroke, see
|
|
59
|
+
// Path#_getStrokeOutline():
|
|
60
|
+
result = item._getStrokeOutline().clone({ insert: false });
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const { style } = item;
|
|
64
|
+
result = outlinePaths(isScaling
|
|
65
|
+
? getLocalCopy(item)
|
|
66
|
+
: getAppliedCopy(item), {
|
|
67
|
+
strokeWidth: width ?? style.strokeWidth,
|
|
68
|
+
strokeJoin: join ?? style.strokeJoin,
|
|
69
|
+
strokeCap: cap ?? style.strokeCap,
|
|
70
|
+
miterLimit: miterLimit ?? style.miterLimit,
|
|
71
|
+
dashArray: dashArray ?? style.dashArray,
|
|
72
|
+
dashOffset: dashOffset ?? style.dashOffset
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (isScaling) {
|
|
76
|
+
result.transform(item._matrix);
|
|
77
|
+
}
|
|
78
|
+
result = placeResult(item, result, options);
|
|
79
|
+
result.fillColor = item.strokeColor;
|
|
80
|
+
result.strokeColor = null;
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
// Returns the path with its stroke outlined next to its fill, as filled areas
|
|
84
|
+
// following its stroke profile, see the outline effect and Item#expand():
|
|
85
|
+
export function expandStroke(path) {
|
|
86
|
+
if (!path.hasStroke()) {
|
|
87
|
+
return path;
|
|
88
|
+
}
|
|
89
|
+
const outline = path.outline({ insert: false });
|
|
90
|
+
if (!path.hasFill()) {
|
|
91
|
+
return outline;
|
|
92
|
+
}
|
|
93
|
+
path.strokeColor = null;
|
|
94
|
+
return new Group({ children: [path, outline], insert: false });
|
|
95
|
+
}
|
|
96
|
+
export function getStrokeOutline(item) {
|
|
97
|
+
// The style of the compound path, for its children:
|
|
98
|
+
return outlinePaths(getLocalCopy(item), item.style);
|
|
99
|
+
}
|
|
100
|
+
// Outlines the strokes of the paths of the path item, a copy, with the style,
|
|
101
|
+
// cut into their dashes first, see outline() of paper/offset:
|
|
102
|
+
function outlinePaths(item, style) {
|
|
103
|
+
const region = getFeature('offset').outline(item._getPaths().map(path => ({
|
|
104
|
+
...getPathValues(path),
|
|
105
|
+
profile: path._strokeProfile ? getStrokeProfileEntries(path) : undefined
|
|
106
|
+
})), {
|
|
107
|
+
width: style.strokeWidth,
|
|
108
|
+
join: style.strokeJoin,
|
|
109
|
+
cap: style.strokeCap,
|
|
110
|
+
miterLimit: style.miterLimit,
|
|
111
|
+
dashArray: style.dashArray,
|
|
112
|
+
dashOffset: style.dashOffset
|
|
113
|
+
});
|
|
114
|
+
return (region.paths.length ? createPathItem(region) : new Path({ insert: false })).reduce();
|
|
115
|
+
}
|
|
116
|
+
// Takes the stroke profiles off the paths, as their stops with the points
|
|
117
|
+
// and normals of the paths there:
|
|
118
|
+
function takeProfileStops(paths) {
|
|
119
|
+
const stops = [];
|
|
120
|
+
for (const path of paths) {
|
|
121
|
+
for (const stop of path.strokeProfile ?? []) {
|
|
122
|
+
// The stops lie on the path:
|
|
123
|
+
const { point, normal } = path.getLocationAt(stop.offset);
|
|
124
|
+
stops.push({ stop: stop.clone(), point, normal: normal });
|
|
125
|
+
}
|
|
126
|
+
path.strokeProfile = null;
|
|
127
|
+
}
|
|
128
|
+
return stops;
|
|
129
|
+
}
|
|
130
|
+
// Sets the stroke profiles of the paths of an offset at the distance, from
|
|
131
|
+
// the stops of the paths that were offset: each along its normal, on either
|
|
132
|
+
// side, as closed paths are offset to the side that they are oriented to,
|
|
133
|
+
// at the nearest point of the offset. That is also where the stops of
|
|
134
|
+
// stretches end up that the offset leaves out, and those at corners:
|
|
135
|
+
function setOffsetProfiles(result, stops, distance) {
|
|
136
|
+
const profiles = {};
|
|
137
|
+
for (const { stop, point, normal } of stops) {
|
|
138
|
+
const vector = normal.multiply(distance);
|
|
139
|
+
const loc1 = result.getNearestLocation(point.add(vector));
|
|
140
|
+
const loc2 = result.getNearestLocation(point.subtract(vector));
|
|
141
|
+
const loc = (loc1?.distance ?? Infinity) < (loc2?.distance ?? Infinity)
|
|
142
|
+
? loc1
|
|
143
|
+
: loc2 ?? loc1;
|
|
144
|
+
if (loc) {
|
|
145
|
+
stop.offset = loc.offset;
|
|
146
|
+
(profiles[loc.path.id] ??= []).push(stop);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const path of result._getPaths()) {
|
|
150
|
+
path.strokeProfile = profiles[path.id] ?? null;
|
|
151
|
+
}
|
|
152
|
+
}
|