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.
- package/CHANGELOG.md +294 -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 +33083 -22681
- package/dist/paper-full.min.js +36 -31
- package/dist/paper-hosted.js +33898 -23223
- 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 +90 -58
- 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 -23759
- package/dist/docs/classes/AreaText.html +0 -8708
- package/dist/docs/classes/ChangeFlag.html +0 -385
- package/dist/docs/classes/Color.html +0 -2205
- package/dist/docs/classes/CompoundPath.html +0 -9168
- package/dist/docs/classes/Curve.html +0 -2326
- package/dist/docs/classes/CurveLocation.html +0 -673
- 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 -7139
- package/dist/docs/classes/HitResult.html +0 -241
- package/dist/docs/classes/HostItem.html +0 -6836
- package/dist/docs/classes/Item.html +0 -6892
- package/dist/docs/classes/Key.html +0 -140
- package/dist/docs/classes/KeyEvent.html +0 -309
- package/dist/docs/classes/Layer.html +0 -7122
- 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 -202
- package/dist/docs/classes/Path.html +0 -12064
- package/dist/docs/classes/PathItem.html +0 -8930
- package/dist/docs/classes/PathText.html +0 -8578
- package/dist/docs/classes/Point.html +0 -2860
- package/dist/docs/classes/PointText.html +0 -8489
- package/dist/docs/classes/Project.html +0 -1604
- package/dist/docs/classes/Raster.html +0 -8069
- package/dist/docs/classes/Rectangle.html +0 -1698
- package/dist/docs/classes/Segment.html +0 -1017
- package/dist/docs/classes/Shape.html +0 -7570
- package/dist/docs/classes/Size.html +0 -1915
- package/dist/docs/classes/Style.html +0 -1765
- package/dist/docs/classes/SymbolDefinition.html +0 -312
- package/dist/docs/classes/SymbolItem.html +0 -6999
- package/dist/docs/classes/TextItem.html +0 -8332
- 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/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 -21834
- package/dist/paper-core.min.js +0 -32
- package/dist/paper.d.ts +0 -9630
- 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/MetaBalls.html +0 -132
- package/examples/Paperjs.org/NyanRainbow.html +0 -202
- 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/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/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,231 @@
|
|
|
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 { Item, KAPPA, Line, Path, Point, Rectangle, Segment, Shape, Size, createEllipse, createRectangle, getScope, isPlainObject, isRectangle, isZero, readEllipse, readRectangle } from "../internal.js";
|
|
13
|
+
export function createLinePath(...args) {
|
|
14
|
+
const { from, to, ...props } = getNamedArguments(args, ['from', 'to']);
|
|
15
|
+
return createPath([new Segment(from), new Segment(to)], false, props);
|
|
16
|
+
}
|
|
17
|
+
export function createCirclePath(...args) {
|
|
18
|
+
const { center, radius, ...props } = getNamedArguments(args, [
|
|
19
|
+
'center',
|
|
20
|
+
'radius'
|
|
21
|
+
]);
|
|
22
|
+
return createEllipsePath({ center, radius: Size.coerce(radius), ...props });
|
|
23
|
+
}
|
|
24
|
+
export function createRectanglePath(arg0, arg1) {
|
|
25
|
+
// The named form, or a rectangle followed by the corner radius, or the
|
|
26
|
+
// point and the size, or the two points that describe it:
|
|
27
|
+
const { radius: corner, ...object } = arg1 === undefined
|
|
28
|
+
? isPlainObject(arg0)
|
|
29
|
+
? arg0
|
|
30
|
+
: { rectangle: arg0 }
|
|
31
|
+
: isRectangle(arg0)
|
|
32
|
+
? { rectangle: arg0, radius: arg1 }
|
|
33
|
+
: { rectangle: new Rectangle(arg0, arg1) };
|
|
34
|
+
const [rect, props] = readRectangle(object);
|
|
35
|
+
const radius = corner ? Size.coerce(corner) : new Size();
|
|
36
|
+
const segments = createRectangle(rect, radius).map(segment => new Segment(...segment));
|
|
37
|
+
return createPath(segments, true, props);
|
|
38
|
+
}
|
|
39
|
+
export function createEllipsePath(rectangle) {
|
|
40
|
+
const object = isPlainObject(rectangle) ? rectangle : { rectangle };
|
|
41
|
+
// Placed by its center and radius, or by the rectangle around it:
|
|
42
|
+
const { center, radius, props } = readEllipse(object);
|
|
43
|
+
const segments = createEllipse(center, radius).map(segment => new Segment(...segment));
|
|
44
|
+
return createPath(segments, true, props);
|
|
45
|
+
}
|
|
46
|
+
export function createArcPath(...args) {
|
|
47
|
+
const { from, through, to, ...props } = getNamedArguments(args, [
|
|
48
|
+
'from',
|
|
49
|
+
'through',
|
|
50
|
+
'to'
|
|
51
|
+
]);
|
|
52
|
+
// Draw the arc on a temporary path, and create the result from its
|
|
53
|
+
// segments like all the other factories:
|
|
54
|
+
const arc = new Path(Item.NO_INSERT);
|
|
55
|
+
arc.moveTo(from);
|
|
56
|
+
arc.arcTo(through, to);
|
|
57
|
+
return createPath(arc._segments, false, props);
|
|
58
|
+
}
|
|
59
|
+
export function createRegularPolygonPath(...args) {
|
|
60
|
+
const { center, sides, radius, ...props } = getNamedArguments(args, [
|
|
61
|
+
'center',
|
|
62
|
+
'sides',
|
|
63
|
+
'radius'
|
|
64
|
+
]);
|
|
65
|
+
const centerPoint = Point.from(center);
|
|
66
|
+
const step = -360 / sides;
|
|
67
|
+
// Start at the top as Illustrator does: at the top vertex, or the right
|
|
68
|
+
// end of the top edge with an even number of sides, counterclockwise:
|
|
69
|
+
const offset = sides % 2 ? 0 : -0.5;
|
|
70
|
+
const vector = new Point(0, -radius);
|
|
71
|
+
const segments = new Array(sides);
|
|
72
|
+
for (let i = 0; i < sides; i++) {
|
|
73
|
+
segments[i] = new Segment(centerPoint.add(vector.rotate((i + offset) * step)));
|
|
74
|
+
}
|
|
75
|
+
return createPath(segments, true, props);
|
|
76
|
+
}
|
|
77
|
+
export function createStarPath(...args) {
|
|
78
|
+
const { center, points, radius1, radius2, ...props } = getNamedArguments(args, ['center', 'points', 'radius1', 'radius2']);
|
|
79
|
+
const centerPoint = Point.from(center);
|
|
80
|
+
const count = points * 2;
|
|
81
|
+
const step = 360 / count;
|
|
82
|
+
const vector = new Point(0, -1);
|
|
83
|
+
const segments = new Array(count);
|
|
84
|
+
for (let i = 0; i < count; i++) {
|
|
85
|
+
segments[i] = new Segment(centerPoint.add(vector.rotate(step * i).multiply(i % 2 ? radius2 : radius1)));
|
|
86
|
+
}
|
|
87
|
+
return createPath(segments, true, props);
|
|
88
|
+
}
|
|
89
|
+
// Read the arguments by their names, from the single plain object of the
|
|
90
|
+
// named form or by their positions:
|
|
91
|
+
function getNamedArguments(args, names) {
|
|
92
|
+
return args.length === 1 && isPlainObject(args[0])
|
|
93
|
+
? args[0]
|
|
94
|
+
: Object.fromEntries(names.map((name, index) => [name, args[index]]));
|
|
95
|
+
}
|
|
96
|
+
function createPath(segments, closed, { insert, project, parent, ...props }) {
|
|
97
|
+
// Let the constructor of Item handle the insertion:
|
|
98
|
+
const path = new Path({ insert, project, parent });
|
|
99
|
+
path._add(segments);
|
|
100
|
+
// No need to use setter for _closed since _add() called _changed().
|
|
101
|
+
path._closed = closed;
|
|
102
|
+
// Set named arguments at the end, since some depend on geometry to be
|
|
103
|
+
// defined (e.g. #clockwise)
|
|
104
|
+
return path.set(props);
|
|
105
|
+
}
|
|
106
|
+
// Creates the shape item that has the path's geometry, or null, see
|
|
107
|
+
// Path#toShape():
|
|
108
|
+
export function createShape(path, insert) {
|
|
109
|
+
if (!path._closed)
|
|
110
|
+
return null;
|
|
111
|
+
const segments = path._segments;
|
|
112
|
+
let create;
|
|
113
|
+
let size;
|
|
114
|
+
let radius;
|
|
115
|
+
// Set along with create:
|
|
116
|
+
let topCenter;
|
|
117
|
+
// The path is closed, so each segment has a previous and next one:
|
|
118
|
+
function isCollinear(i, j) {
|
|
119
|
+
const seg1 = segments[i];
|
|
120
|
+
const seg2 = seg1.next;
|
|
121
|
+
const seg3 = segments[j];
|
|
122
|
+
const seg4 = seg3.next;
|
|
123
|
+
return (seg1._handleOut.isZero() &&
|
|
124
|
+
seg2._handleIn.isZero() &&
|
|
125
|
+
seg3._handleOut.isZero() &&
|
|
126
|
+
seg4._handleIn.isZero() &&
|
|
127
|
+
seg2._point.subtract(seg1._point).isCollinear(seg4._point.subtract(seg3._point)));
|
|
128
|
+
}
|
|
129
|
+
function isOrthogonal(i) {
|
|
130
|
+
const seg2 = segments[i];
|
|
131
|
+
const seg1 = seg2.previous;
|
|
132
|
+
const seg3 = seg2.next;
|
|
133
|
+
return (seg1._handleOut.isZero() &&
|
|
134
|
+
seg2._handleIn.isZero() &&
|
|
135
|
+
seg2._handleOut.isZero() &&
|
|
136
|
+
seg3._handleIn.isZero() &&
|
|
137
|
+
seg2._point.subtract(seg1._point).isOrthogonal(seg3._point.subtract(seg2._point)));
|
|
138
|
+
}
|
|
139
|
+
function isArc(i) {
|
|
140
|
+
const seg1 = segments[i];
|
|
141
|
+
const seg2 = seg1.next;
|
|
142
|
+
const handle1 = seg1._handleOut;
|
|
143
|
+
const handle2 = seg2._handleIn;
|
|
144
|
+
const kappa = KAPPA;
|
|
145
|
+
// Look at handle length and the distance to the imaginary corner
|
|
146
|
+
// point and see if it their relation is kappa.
|
|
147
|
+
if (handle1.isOrthogonal(handle2)) {
|
|
148
|
+
const pt1 = seg1._point;
|
|
149
|
+
const pt2 = seg2._point;
|
|
150
|
+
// Find the corner point by intersecting the lines described
|
|
151
|
+
// by both handles:
|
|
152
|
+
const corner = Line.intersect(pt1.x, pt1.y, handle1.x, handle1.y, pt2.x, pt2.y, handle2.x, handle2.y, true, true, true);
|
|
153
|
+
return (corner &&
|
|
154
|
+
isZero(handle1.length / corner.subtract(pt1).length - kappa) &&
|
|
155
|
+
isZero(handle2.length / corner.subtract(pt2).length - kappa));
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
function getDistance(i, j) {
|
|
160
|
+
return segments[i]._point.getDistance(segments[j]._point);
|
|
161
|
+
}
|
|
162
|
+
// See if actually have any curves in the path. Differentiate
|
|
163
|
+
// between straight objects (line, polyline, rect, and polygon) and
|
|
164
|
+
// objects with curves(circle, ellipse, roundedRectangle).
|
|
165
|
+
if (!path.hasHandles() &&
|
|
166
|
+
segments.length === 4 &&
|
|
167
|
+
isCollinear(0, 2) &&
|
|
168
|
+
isCollinear(1, 3) &&
|
|
169
|
+
isOrthogonal(1)) {
|
|
170
|
+
// From the top left, as Path.rectangle() creates it:
|
|
171
|
+
create = Shape.rectangle;
|
|
172
|
+
size = new Size(getDistance(0, 1), getDistance(0, 3));
|
|
173
|
+
topCenter = segments[0]._point.add(segments[1]._point).divide(2);
|
|
174
|
+
}
|
|
175
|
+
else if (segments.length === 8 &&
|
|
176
|
+
isArc(1) &&
|
|
177
|
+
isArc(3) &&
|
|
178
|
+
isArc(5) &&
|
|
179
|
+
isArc(7) &&
|
|
180
|
+
isCollinear(0, 4) &&
|
|
181
|
+
isCollinear(2, 6)) {
|
|
182
|
+
// It's a rounded rectangle, from the start of its top side.
|
|
183
|
+
create = Shape.rectangle;
|
|
184
|
+
size = new Size(getDistance(7, 2), getDistance(0, 5));
|
|
185
|
+
// Subtract side lengths from total width and divide by 2 to get the
|
|
186
|
+
// corner radius size.
|
|
187
|
+
radius = size
|
|
188
|
+
.subtract(new Size(getDistance(0, 1), getDistance(2, 3)))
|
|
189
|
+
.divide(2);
|
|
190
|
+
topCenter = segments[0]._point.add(segments[1]._point).divide(2);
|
|
191
|
+
}
|
|
192
|
+
else if (segments.length === 4 &&
|
|
193
|
+
isArc(0) &&
|
|
194
|
+
isArc(1) &&
|
|
195
|
+
isArc(2) &&
|
|
196
|
+
isArc(3)) {
|
|
197
|
+
// If the distance between (point0 and point2) and (point1
|
|
198
|
+
// and point3) are equal, then it is a circle
|
|
199
|
+
if (isZero(getDistance(0, 2) - getDistance(1, 3))) {
|
|
200
|
+
create = Shape.circle;
|
|
201
|
+
radius = getDistance(0, 2) / 2;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
create = Shape.ellipse;
|
|
205
|
+
radius = new Size(getDistance(2, 0) / 2, getDistance(3, 1) / 2);
|
|
206
|
+
}
|
|
207
|
+
// From the right, as Path.ellipse() creates it, so the top is the last:
|
|
208
|
+
topCenter = segments[3]._point;
|
|
209
|
+
}
|
|
210
|
+
if (create) {
|
|
211
|
+
// In the path's own coordinates, which the shape takes on through the
|
|
212
|
+
// path's matrix, and not at its pivot:
|
|
213
|
+
const { center } = path.getBounds({ internal: true });
|
|
214
|
+
const shape = create({
|
|
215
|
+
center,
|
|
216
|
+
size,
|
|
217
|
+
radius,
|
|
218
|
+
insert: false
|
|
219
|
+
});
|
|
220
|
+
shape.rotate(topCenter.subtract(center).angle + 90, center);
|
|
221
|
+
shape._matrix.prepend(path._matrix);
|
|
222
|
+
// Pass `true` to exclude the matrix, which the shape has already. Its
|
|
223
|
+
// pivot then lands where the path's is:
|
|
224
|
+
shape.copyAttributes(path, true);
|
|
225
|
+
if (insert !== undefined ? insert : getScope().settings.insertItems) {
|
|
226
|
+
shape.insertAbove(path);
|
|
227
|
+
}
|
|
228
|
+
return shape;
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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, Segment, fitRange, getRange, getSegmentValues, smoothSegments } from "../internal.js";
|
|
13
|
+
// NOTE: Documentation is in PathItem#simplify()
|
|
14
|
+
export function simplifyPath(path, options) {
|
|
15
|
+
const opts = typeof options === 'number' ? { tolerance: options } : options ?? {};
|
|
16
|
+
const segments = path._segments;
|
|
17
|
+
const { length } = segments;
|
|
18
|
+
if (!length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const { fitted, from, to, loop } = fitRange(getSegmentValues(path), path._closed, { tolerance: opts.tolerance, ...getIndices(path, opts) });
|
|
22
|
+
const created = fitted.map(([point, handleIn, handleOut]) => new Segment(point, handleIn, handleOut));
|
|
23
|
+
const first = segments[from < 0 ? from + length : from];
|
|
24
|
+
const last = segments[to];
|
|
25
|
+
if (loop || !first.previous && !last.next) {
|
|
26
|
+
path.segments = created;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const { fullySelected } = path;
|
|
30
|
+
if (from < 0) {
|
|
31
|
+
path.removeSegments(from + length);
|
|
32
|
+
path.removeSegments(0, to + 1);
|
|
33
|
+
path.addSegments(created);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
path.removeSegments(from, to + 1);
|
|
37
|
+
path.insertSegments(from, created);
|
|
38
|
+
}
|
|
39
|
+
if (fullySelected) {
|
|
40
|
+
path.fullySelected = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
// NOTE: Documentation is in PathItem#smooth()
|
|
46
|
+
export function smoothPath(path, options) {
|
|
47
|
+
const opts = options ?? {};
|
|
48
|
+
const segments = path._segments;
|
|
49
|
+
const { length } = segments;
|
|
50
|
+
if (length) {
|
|
51
|
+
const indices = getIndices(path, opts);
|
|
52
|
+
const smoothed = smoothSegments(getSegmentValues(path), path._closed, {
|
|
53
|
+
type: opts.type,
|
|
54
|
+
factor: opts.factor,
|
|
55
|
+
...indices
|
|
56
|
+
});
|
|
57
|
+
const { from, to } = getRange(length, path._closed, indices.from, indices.to);
|
|
58
|
+
for (let i = from; i <= to; i++) {
|
|
59
|
+
const index = i < 0 ? i + length : i;
|
|
60
|
+
const [, handleIn, handleOut] = smoothed[index];
|
|
61
|
+
const segment = segments[index];
|
|
62
|
+
segment.handleIn = handleIn;
|
|
63
|
+
segment.handleOut = handleOut;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Resolves the `from` and `to` options of smoothPath() and simplifyPath()
|
|
68
|
+
// to indices: segments by theirs, and curves by their first segment for
|
|
69
|
+
// `from` and their last one for `to`, so that the range includes them:
|
|
70
|
+
function getIndices(path, { from, to }) {
|
|
71
|
+
const getIndex = (value, isEnd) => {
|
|
72
|
+
const index = value?.index;
|
|
73
|
+
if (index == null) {
|
|
74
|
+
return typeof value === 'number' ? value : undefined;
|
|
75
|
+
}
|
|
76
|
+
// Make sure the segment / curve is not from a wrong path.
|
|
77
|
+
const owner = value.path;
|
|
78
|
+
if (owner && owner !== path) {
|
|
79
|
+
throw new Error(`${value.className} ${index} of ${owner} is not part of ${path}`);
|
|
80
|
+
}
|
|
81
|
+
return isEnd && value instanceof Curve ? index + 1 : index;
|
|
82
|
+
};
|
|
83
|
+
return { from: getIndex(from, false), to: getIndex(to, true) };
|
|
84
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { CompoundPath, Path } from "../internal.js";
|
|
13
|
+
// The plain descriptions of paths and path items that the geometry in
|
|
14
|
+
// src/values, src/boolean and src/offset works on, and the items of those
|
|
15
|
+
// that it returns:
|
|
16
|
+
export function getSegmentValues(path) {
|
|
17
|
+
return path._segments.map(({ _point, _handleIn, _handleOut }) => [
|
|
18
|
+
[_point._x, _point._y],
|
|
19
|
+
[_handleIn._x, _handleIn._y],
|
|
20
|
+
[_handleOut._x, _handleOut._y]
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
export function getPathValues(path) {
|
|
24
|
+
return { closed: path._closed, segments: getSegmentValues(path) };
|
|
25
|
+
}
|
|
26
|
+
export function getRegion(item) {
|
|
27
|
+
return {
|
|
28
|
+
fillRule: item.fillRule,
|
|
29
|
+
paths: item._getPaths().map(getPathValues)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Returns the region as a path item: a path, or a compound path of several:
|
|
33
|
+
export function createPathItem({ paths, fillRule }) {
|
|
34
|
+
const create = ({ segments, closed }) => new Path({ segments, closed, insert: false });
|
|
35
|
+
const item = paths.length === 1
|
|
36
|
+
? create(paths[0])
|
|
37
|
+
: new CompoundPath({ children: paths.map(create), insert: false });
|
|
38
|
+
item.fillRule = fillRule;
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
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 { Base, Project, getCanvas, nativeBlendModes, registerClasses } from "../internal.js";
|
|
13
|
+
const packageJson = { version: '1.0.0-rc.1' };
|
|
14
|
+
/**
|
|
15
|
+
* The currently active scope, which PaperScope#activate() sets.
|
|
16
|
+
*/
|
|
17
|
+
export let paper = null;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the active scope, and creates one on first use if there is none
|
|
20
|
+
* yet, as importing `paper/core` creates none.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
export function getScope() {
|
|
25
|
+
return paper ?? new PaperScope();
|
|
26
|
+
}
|
|
27
|
+
// The agent, as detected once on first use, see getAgent():
|
|
28
|
+
let agent;
|
|
29
|
+
/**
|
|
30
|
+
* The `PaperScope` class represents the scope associated with a Paper
|
|
31
|
+
* context. When working with PaperScript, these scopes are automatically
|
|
32
|
+
* created for us, and through clever scoping the properties and methods of
|
|
33
|
+
* the active scope seem to become part of the global scope.
|
|
34
|
+
*
|
|
35
|
+
* When working with normal JavaScript code, `PaperScope` objects need to be
|
|
36
|
+
* manually created and handled.
|
|
37
|
+
*
|
|
38
|
+
* Paper classes can only be accessed through `PaperScope` objects. Thus in
|
|
39
|
+
* PaperScript they are global, while in JavaScript, they are available on the
|
|
40
|
+
* global {@link paper} object. For JavaScript you can use {@link
|
|
41
|
+
* PaperScope#install(scope) } to install the Paper classes and objects on the
|
|
42
|
+
* global scope. Note that when working with more than one scope, this still
|
|
43
|
+
* works for classes, but not for objects like {@link PaperScope#project}, since
|
|
44
|
+
* they are not updated in the injected scope if scopes are switched.
|
|
45
|
+
*
|
|
46
|
+
* The global {@link paper} object is simply a reference to the currently active
|
|
47
|
+
* `PaperScope`.
|
|
48
|
+
*/
|
|
49
|
+
export class PaperScope extends Base {
|
|
50
|
+
static #scopes = {};
|
|
51
|
+
static #nextId = 0;
|
|
52
|
+
/**
|
|
53
|
+
* The version of Paper.js, as a string.
|
|
54
|
+
*/
|
|
55
|
+
version = packageJson.version;
|
|
56
|
+
/**
|
|
57
|
+
* Gives access to paper's configurable settings.
|
|
58
|
+
*
|
|
59
|
+
* @option [settings.insertItems=true] {Boolean} controls whether newly
|
|
60
|
+
* created items are automatically inserted into the scene graph, by
|
|
61
|
+
* adding them to {@link Project#activeLayer}
|
|
62
|
+
* @option [settings.applyMatrix=true] {Boolean} controls what value newly
|
|
63
|
+
* created items have their {@link Item#applyMatrix} property set to
|
|
64
|
+
* (Note that not all items can set this to `false`)
|
|
65
|
+
* @option [settings.handleSize=4] {Number} the size of the curve handles
|
|
66
|
+
* when drawing selections
|
|
67
|
+
* @option [settings.segmentSize=null] {Number} the size of the segments
|
|
68
|
+
* when drawing selections, or `null` to use `settings.handleSize`, e.g.
|
|
69
|
+
* with `handleSize: 0` to only draw the segments and not their handles
|
|
70
|
+
* @option [settings.hitTolerance=0] {Number} the default tolerance for hit-
|
|
71
|
+
* tests, when no value is specified, and for the mouse events of items
|
|
72
|
+
*/
|
|
73
|
+
settings = {
|
|
74
|
+
applyMatrix: true,
|
|
75
|
+
insertItems: true,
|
|
76
|
+
handleSize: 4,
|
|
77
|
+
segmentSize: null,
|
|
78
|
+
hitTolerance: 0
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The list of all open projects within the current Paper.js context.
|
|
82
|
+
*/
|
|
83
|
+
projects = [];
|
|
84
|
+
// Typed as set, as the scope's current project, view and tool are in the
|
|
85
|
+
// apps that use them, sparing them a check on each use:
|
|
86
|
+
/**
|
|
87
|
+
* The reference to the active tool.
|
|
88
|
+
*/
|
|
89
|
+
tool = null;
|
|
90
|
+
/**
|
|
91
|
+
* The list of available tools.
|
|
92
|
+
*/
|
|
93
|
+
tools = [];
|
|
94
|
+
#project = null;
|
|
95
|
+
// Assign a unique id to each scope.
|
|
96
|
+
_id = PaperScope.#nextId++;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a PaperScope object.
|
|
99
|
+
*/
|
|
100
|
+
constructor() {
|
|
101
|
+
super();
|
|
102
|
+
PaperScope.#scopes[this._id] = this;
|
|
103
|
+
// Whenever a PaperScope is created, it becomes the active one.
|
|
104
|
+
this.activate();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The currently active project.
|
|
108
|
+
*/
|
|
109
|
+
get project() {
|
|
110
|
+
// Typed as set, as the tool above:
|
|
111
|
+
return this.#project;
|
|
112
|
+
}
|
|
113
|
+
set project(project) {
|
|
114
|
+
this.#project = project;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The reference to the active project's view.
|
|
118
|
+
*/
|
|
119
|
+
get view() {
|
|
120
|
+
// Typed as set, as the tool above:
|
|
121
|
+
return this.#project?._view;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A reference to the local scope. This is required, so `paper` will always
|
|
125
|
+
* refer to the local scope, even when calling into it from another scope.
|
|
126
|
+
* `paper.activate();` will have to be called in such a situation.
|
|
127
|
+
*
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
get paper() {
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* An object containing properties that describe the support of various
|
|
135
|
+
* features.
|
|
136
|
+
*/
|
|
137
|
+
get support() {
|
|
138
|
+
return { nativeBlendModes };
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The platform and browser that Paper.js runs in, detected from the user
|
|
142
|
+
* agent, e.g. `{ platform: 'mac', mac: true, name: 'chrome', chrome: true,
|
|
143
|
+
* version: '130.0', versionNumber: 130 }`.
|
|
144
|
+
*/
|
|
145
|
+
get agent() {
|
|
146
|
+
return getAgent();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Injects the paper scope into any other given scope. Can be used for
|
|
150
|
+
* example to inject the currently active PaperScope into the window's
|
|
151
|
+
* global scope, to emulate PaperScript-style globally accessible Paper
|
|
152
|
+
* classes and objects.
|
|
153
|
+
*
|
|
154
|
+
* <b>Please note:</b> Using this method may override native constructors
|
|
155
|
+
* (e.g. Path). This may cause problems when using Paper.js in conjunction
|
|
156
|
+
* with other libraries that rely on these constructors. Keep the library
|
|
157
|
+
* scoped if you encounter issues caused by this.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* paper.install(window);
|
|
161
|
+
*/
|
|
162
|
+
install(scope) {
|
|
163
|
+
// Define project, view and tool as getters that redirect to these values
|
|
164
|
+
// on the PaperScope, so they are kept up to date
|
|
165
|
+
for (const key of ['project', 'view', 'tool']) {
|
|
166
|
+
Object.defineProperty(scope, key, {
|
|
167
|
+
configurable: true,
|
|
168
|
+
get: () => this[key]
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// Copy over all fields from this scope to the destination, except the
|
|
172
|
+
// hidden ones and the names that the destination has already, such as the
|
|
173
|
+
// native Event, MouseEvent and Symbol (#1832). Use for…in, since we also
|
|
174
|
+
// want to enumerate over fields on PaperScope.prototype, e.g. all classes:
|
|
175
|
+
for (const key in this) {
|
|
176
|
+
if (!/^_/.test(key) && this[key] && !(key in scope)) {
|
|
177
|
+
scope[key] = this[key];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sets up an empty project for us. If a canvas is provided, it also creates
|
|
183
|
+
* a {@link View} for it, both linked to this scope.
|
|
184
|
+
*
|
|
185
|
+
* @param element the HTML canvas element this scope should be associated
|
|
186
|
+
* with, or an ID string by which to find the element, or the size of the
|
|
187
|
+
* canvas to be created for usage in a web worker.
|
|
188
|
+
*/
|
|
189
|
+
setup(element) {
|
|
190
|
+
// Make sure this is the active scope, so the created project and view are
|
|
191
|
+
// automatically associated with it.
|
|
192
|
+
this.activate();
|
|
193
|
+
// Create an empty project for the scope.
|
|
194
|
+
this.project = new Project(element);
|
|
195
|
+
// This is needed in PaperScript.load().
|
|
196
|
+
return this;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Creates a canvas of the given size, or reuses one that was released
|
|
200
|
+
* internally.
|
|
201
|
+
*
|
|
202
|
+
* @param width the width of the canvas
|
|
203
|
+
* @param height the height of the canvas
|
|
204
|
+
* @return the canvas
|
|
205
|
+
*/
|
|
206
|
+
createCanvas(width, height) {
|
|
207
|
+
return getCanvas({ width, height });
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Activates this PaperScope, so all newly created items will be placed
|
|
211
|
+
* in its active project.
|
|
212
|
+
*/
|
|
213
|
+
activate() {
|
|
214
|
+
paper = this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Removes all projects, views and tools of this scope, along with their
|
|
218
|
+
* installed event handlers.
|
|
219
|
+
*/
|
|
220
|
+
clear() {
|
|
221
|
+
for (const project of [...this.projects].reverse()) {
|
|
222
|
+
project.remove();
|
|
223
|
+
}
|
|
224
|
+
for (const tool of [...this.tools].reverse()) {
|
|
225
|
+
tool.remove();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Clears this scope and removes it from the list of scopes.
|
|
230
|
+
*/
|
|
231
|
+
remove() {
|
|
232
|
+
this.clear();
|
|
233
|
+
delete PaperScope.#scopes[this._id];
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Retrieves a PaperScope object with the given scope id.
|
|
237
|
+
*
|
|
238
|
+
* @param id
|
|
239
|
+
* @return the scope, or `null` if there is none with the id
|
|
240
|
+
*/
|
|
241
|
+
static get(id) {
|
|
242
|
+
return PaperScope.#scopes[id] ?? null;
|
|
243
|
+
}
|
|
244
|
+
static {
|
|
245
|
+
registerClasses({ PaperScope: this });
|
|
246
|
+
// Enumerate the accessors, since #install() and PaperScript take what a
|
|
247
|
+
// scope holds through for…in:
|
|
248
|
+
for (const key of ['project', 'view', 'paper', 'support', 'agent']) {
|
|
249
|
+
Object.defineProperty(this.prototype, key, { enumerable: true });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns the platform and browser that Paper.js runs in, see
|
|
255
|
+
* {@link PaperScope#agent}, detected once on first use.
|
|
256
|
+
*
|
|
257
|
+
* @private
|
|
258
|
+
*/
|
|
259
|
+
export function getAgent() {
|
|
260
|
+
if (!agent) {
|
|
261
|
+
const user = (globalThis.navigator?.userAgent || '').toLowerCase();
|
|
262
|
+
// Detect basic platforms, only mac internally required for now.
|
|
263
|
+
const os = (/(darwin|win|mac|linux|freebsd|sunos)/.exec(user) ?? [])[0];
|
|
264
|
+
const platform = os === 'darwin' ? 'mac' : os;
|
|
265
|
+
agent = { platform };
|
|
266
|
+
if (platform) {
|
|
267
|
+
agent[platform] = true;
|
|
268
|
+
}
|
|
269
|
+
// Use replace() to get all matches, and deal with Chrome/Webkit
|
|
270
|
+
// overlap:
|
|
271
|
+
user.replace(/(chrome|safari|webkit|firefox|node|jsdom)\/?\s*([.\d]+)(?:.*rv:v?([.\d]+))?/g, (match, name, version1, revision) => {
|
|
272
|
+
// Do not set additional browsers once chrome is detected.
|
|
273
|
+
if (!agent.chrome) {
|
|
274
|
+
const version = name === 'node' ? revision : version1;
|
|
275
|
+
agent.version = version;
|
|
276
|
+
agent.versionNumber = parseFloat(version);
|
|
277
|
+
name = name === 'jsdom' ? 'node' : name;
|
|
278
|
+
agent.name = name;
|
|
279
|
+
agent[name] = true;
|
|
280
|
+
}
|
|
281
|
+
return match;
|
|
282
|
+
});
|
|
283
|
+
if (agent.chrome) {
|
|
284
|
+
delete agent.webkit;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return agent;
|
|
288
|
+
}
|