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,503 @@
|
|
|
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, Change, Color, Point, equals, getPixelSize, getScope, inject, registerClasses } from "../internal.js";
|
|
13
|
+
// Defaults for items without text-styles (PathItem, Shape, Raster, ...):
|
|
14
|
+
export const itemStyleDefaults = {
|
|
15
|
+
// Paths
|
|
16
|
+
fillColor: null,
|
|
17
|
+
fillRule: 'nonzero',
|
|
18
|
+
strokeColor: null,
|
|
19
|
+
strokeWidth: 1,
|
|
20
|
+
strokeCap: 'butt',
|
|
21
|
+
strokeJoin: 'miter',
|
|
22
|
+
strokeScaling: true,
|
|
23
|
+
miterLimit: 10,
|
|
24
|
+
dashOffset: 0,
|
|
25
|
+
dashArray: [],
|
|
26
|
+
paintOrder: 'fill',
|
|
27
|
+
// Shadows
|
|
28
|
+
shadowColor: null,
|
|
29
|
+
shadowBlur: 0,
|
|
30
|
+
shadowOffset: new Point(),
|
|
31
|
+
// Selection
|
|
32
|
+
selectedColor: null
|
|
33
|
+
};
|
|
34
|
+
// Defaults for Group, Layer and Project (anything item that allows nesting
|
|
35
|
+
// needs to be able to pass down text styles as well):
|
|
36
|
+
export const groupStyleDefaults = {
|
|
37
|
+
...itemStyleDefaults,
|
|
38
|
+
// Characters
|
|
39
|
+
fontFamily: 'sans-serif',
|
|
40
|
+
fontWeight: 'normal',
|
|
41
|
+
fontStyle: 'normal',
|
|
42
|
+
fontSize: 12,
|
|
43
|
+
fontVariations: null,
|
|
44
|
+
lineHeight: 'auto',
|
|
45
|
+
letterTracking: 0,
|
|
46
|
+
letterKerning: null,
|
|
47
|
+
baselineShift: 0,
|
|
48
|
+
baselinePosition: 'normal',
|
|
49
|
+
letterScaling: 1,
|
|
50
|
+
letterRotation: 0,
|
|
51
|
+
letterCase: 'normal',
|
|
52
|
+
underline: false,
|
|
53
|
+
strikethrough: false,
|
|
54
|
+
fontFeatures: null,
|
|
55
|
+
// Paragraphs
|
|
56
|
+
justification: 'start',
|
|
57
|
+
justificationLast: 'start',
|
|
58
|
+
justificationRanges: null,
|
|
59
|
+
indentStart: 0,
|
|
60
|
+
indentEnd: 0,
|
|
61
|
+
indentFirstLine: 0,
|
|
62
|
+
spaceBefore: 0,
|
|
63
|
+
spaceAfter: 0,
|
|
64
|
+
hyphenation: 'manual',
|
|
65
|
+
lineWrap: 'normal',
|
|
66
|
+
tabStops: null,
|
|
67
|
+
direction: 'ltr'
|
|
68
|
+
};
|
|
69
|
+
// Defaults for TextItem (override default fillColor to black):
|
|
70
|
+
export const textStyleDefaults = {
|
|
71
|
+
...groupStyleDefaults,
|
|
72
|
+
fillColor: new Color() // black
|
|
73
|
+
};
|
|
74
|
+
// The size of the letters in each baseline position, and how far they move up
|
|
75
|
+
// or down, of the font size, with Illustrator's and InDesign's defaults:
|
|
76
|
+
export const baselinePositions = {
|
|
77
|
+
normal: { size: 1, position: 0 },
|
|
78
|
+
superscript: { size: 0.583, position: 0.333 },
|
|
79
|
+
subscript: { size: 0.583, position: 0.333 }
|
|
80
|
+
};
|
|
81
|
+
// The automatic line height, of the font size:
|
|
82
|
+
const autoLineHeight = 1.2;
|
|
83
|
+
const flags = {
|
|
84
|
+
strokeWidth: Change.STROKE,
|
|
85
|
+
strokeCap: Change.STROKE,
|
|
86
|
+
strokeJoin: Change.STROKE,
|
|
87
|
+
// The dashes of strokes are their geometry too, see PathItem#dash():
|
|
88
|
+
dashArray: Change.STROKE,
|
|
89
|
+
dashOffset: Change.STROKE,
|
|
90
|
+
// strokeScaling can change the coordinates of cached path items
|
|
91
|
+
strokeScaling: Change.STROKE | Change.GEOMETRY,
|
|
92
|
+
miterLimit: Change.STROKE,
|
|
93
|
+
// Shadows change the bounds as strokes do, see Item#previewBounds:
|
|
94
|
+
shadowColor: Change.STROKE,
|
|
95
|
+
shadowBlur: Change.STROKE,
|
|
96
|
+
shadowOffset: Change.STROKE
|
|
97
|
+
};
|
|
98
|
+
for (const key in groupStyleDefaults) {
|
|
99
|
+
// All text properties but the decorations change the layout:
|
|
100
|
+
if (!(key in itemStyleDefaults) &&
|
|
101
|
+
key !== 'underline' &&
|
|
102
|
+
key !== 'strikethrough') {
|
|
103
|
+
flags[key] = Change.GEOMETRY;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Inject style getters and setters into the Item class, which redirect calls
|
|
107
|
+
// to the linked style object.
|
|
108
|
+
export function defineStyleAccessors(ctor) {
|
|
109
|
+
for (const key of Style.keys) {
|
|
110
|
+
inject(ctor.prototype, {
|
|
111
|
+
get [key]() {
|
|
112
|
+
return this._style._get(key);
|
|
113
|
+
},
|
|
114
|
+
set [key](value) {
|
|
115
|
+
this._style._set(key, value);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// The styles of the symbol items that are being drawn, measured or hit-tested,
|
|
121
|
+
// the innermost last. They provide the values that the content of their
|
|
122
|
+
// definitions leaves unset, as the <use> elements of SVG do, see SymbolItem:
|
|
123
|
+
const inheritedStyles = [];
|
|
124
|
+
/**
|
|
125
|
+
* Calls the callback with the style providing the values that the styles read
|
|
126
|
+
* meanwhile leave unset, and returns its result.
|
|
127
|
+
*
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
export function withInheritedStyle(style, callback) {
|
|
131
|
+
inheritedStyles.push(style);
|
|
132
|
+
try {
|
|
133
|
+
return callback();
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
inheritedStyles.pop();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns whether styles read now take unset values from a symbol item, see
|
|
141
|
+
* {@link withInheritedStyle()}.
|
|
142
|
+
*
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
export function isInheritingStyle() {
|
|
146
|
+
return inheritedStyles.length > 0;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Style is used for changing the visual styles of items
|
|
150
|
+
* contained within a Paper.js project and is returned by
|
|
151
|
+
* {@link Item#style} and {@link Project#currentStyle}.
|
|
152
|
+
*
|
|
153
|
+
* All properties of Style are also reflected directly in {@link Item},
|
|
154
|
+
* i.e.: {@link Item#fillColor}.
|
|
155
|
+
*
|
|
156
|
+
* Styles set on a {@link Group} or {@link Layer} are applied to the children
|
|
157
|
+
* that it contains at that moment. Items added to it later do not receive them.
|
|
158
|
+
*
|
|
159
|
+
* To set multiple style properties in one go, you can pass an object to
|
|
160
|
+
* {@link Item#style}. This is a convenient way to define a style once and
|
|
161
|
+
* apply it to a series of items:
|
|
162
|
+
*
|
|
163
|
+
* @classexample {@paperscript} // Styling paths
|
|
164
|
+
*
|
|
165
|
+
* var path = Path.circle(new Point(80, 50), 30);
|
|
166
|
+
* path.style = {
|
|
167
|
+
* fillColor: new Color(1, 0, 0),
|
|
168
|
+
* strokeColor: 'black',
|
|
169
|
+
* strokeWidth: 5
|
|
170
|
+
* };
|
|
171
|
+
*
|
|
172
|
+
* @classexample {@paperscript} // Styling text items
|
|
173
|
+
* var text = new PointText(view.center);
|
|
174
|
+
* text.content = 'Hello world.';
|
|
175
|
+
* text.style = {
|
|
176
|
+
* fontFamily: 'Courier New',
|
|
177
|
+
* fontWeight: 'bold',
|
|
178
|
+
* fontSize: 20,
|
|
179
|
+
* fillColor: 'red',
|
|
180
|
+
* justification: 'center'
|
|
181
|
+
* };
|
|
182
|
+
*
|
|
183
|
+
* @classexample {@paperscript} // Styling groups
|
|
184
|
+
* var path1 = Path.circle({
|
|
185
|
+
* center: [100, 50],
|
|
186
|
+
* radius: 30
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* var path2 = Path.rectangle({
|
|
190
|
+
* from: [170, 20],
|
|
191
|
+
* to: [230, 80]
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* var group = new Group(path1, path2);
|
|
195
|
+
*
|
|
196
|
+
* // All styles set on a group are automatically
|
|
197
|
+
* // set on the current children of the group:
|
|
198
|
+
* group.style = {
|
|
199
|
+
* strokeColor: 'black',
|
|
200
|
+
* dashArray: [4, 10],
|
|
201
|
+
* strokeWidth: 4,
|
|
202
|
+
* strokeCap: 'round'
|
|
203
|
+
* };
|
|
204
|
+
*/
|
|
205
|
+
export class Style extends Base {
|
|
206
|
+
/**
|
|
207
|
+
* The names of all style properties.
|
|
208
|
+
*
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
static keys = Object.keys(groupStyleDefaults);
|
|
212
|
+
// We keep values in a separate object that we can iterate over.
|
|
213
|
+
_values = {};
|
|
214
|
+
_defaults;
|
|
215
|
+
#owner;
|
|
216
|
+
#project;
|
|
217
|
+
/**
|
|
218
|
+
* Style objects don't need to be created directly. Just pass an object to
|
|
219
|
+
* {@link Item#style} or {@link Project#currentStyle}, it will be converted
|
|
220
|
+
* to a Style object internally.
|
|
221
|
+
*
|
|
222
|
+
* @param style
|
|
223
|
+
*/
|
|
224
|
+
constructor(style, _owner, _project) {
|
|
225
|
+
super();
|
|
226
|
+
this.#owner = _owner;
|
|
227
|
+
this.#project = _owner?._project ?? _project ?? getScope().project;
|
|
228
|
+
// The owner knows its defaults, and styles without one can be applied
|
|
229
|
+
// to groups, e.g. a project's current style:
|
|
230
|
+
this._defaults = _owner?._getStyleDefaults() ?? groupStyleDefaults;
|
|
231
|
+
if (style) {
|
|
232
|
+
this.set(style);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// The value that all styles share for key, or undefined if they differ:
|
|
236
|
+
static merge(styles, key) {
|
|
237
|
+
let value;
|
|
238
|
+
for (let i = 0; i < styles.length; i++) {
|
|
239
|
+
const other = styles[i][key];
|
|
240
|
+
if (!i) {
|
|
241
|
+
value = other;
|
|
242
|
+
}
|
|
243
|
+
else if (!equals(value, other)) {
|
|
244
|
+
return undefined;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
249
|
+
set(style) {
|
|
250
|
+
// If the passed style object is also a Style, clone its cloneable fields
|
|
251
|
+
// rather than simply copying them.
|
|
252
|
+
const isStyle = style instanceof Style;
|
|
253
|
+
// Use the other style's _values object for iteration
|
|
254
|
+
const values = isStyle ? style._values : style;
|
|
255
|
+
if (values) {
|
|
256
|
+
for (const key in values) {
|
|
257
|
+
if (key in this._defaults) {
|
|
258
|
+
const value = values[key];
|
|
259
|
+
this[key] =
|
|
260
|
+
value && isStyle && value.clone ? value.clone() : value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
// Style values are handled like this:
|
|
267
|
+
// - They are all stored in _values, which starts empty, with a fallback on
|
|
268
|
+
// _defaults in _get().
|
|
269
|
+
// - Only the styles that are explicitly set on the object get defined in
|
|
270
|
+
// _values.
|
|
271
|
+
// - Color values are not stored as converted colors immediately. The raw
|
|
272
|
+
// value is stored, and conversion only happens in _get().
|
|
273
|
+
_set(key, value) {
|
|
274
|
+
const owner = this.#owner;
|
|
275
|
+
// The styles the owner stands for, as a Group its children's:
|
|
276
|
+
const styles = owner?._getStyles(this, key, true);
|
|
277
|
+
if (styles) {
|
|
278
|
+
for (const style of styles) {
|
|
279
|
+
;
|
|
280
|
+
style[key] = value;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// Always store selectedColor in item _values to make sure that group
|
|
284
|
+
// selected bounds and position color is coherent whether it has children
|
|
285
|
+
// or not when the value is set.
|
|
286
|
+
if ((key === 'selectedColor' || !styles) && key in this._defaults) {
|
|
287
|
+
const old = this._values[key];
|
|
288
|
+
if (old !== value) {
|
|
289
|
+
if (/Color$/.test(key)) {
|
|
290
|
+
// The old value may be a native string or other color description
|
|
291
|
+
// that wasn't coerced to a color object yet
|
|
292
|
+
if (old instanceof Color) {
|
|
293
|
+
Color._setOwner(old, null);
|
|
294
|
+
old._canvasStyle = null;
|
|
295
|
+
}
|
|
296
|
+
if (value instanceof Color) {
|
|
297
|
+
// NOTE: If value is not a Color, it is only converted and cloned
|
|
298
|
+
// in _get() further down.
|
|
299
|
+
value = Color._setOwner(value, owner,
|
|
300
|
+
// Only provide a key for the owner to set the color again if the
|
|
301
|
+
// style is to be applied to the children:
|
|
302
|
+
styles && key);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// NOTE: We do not convert the values to Colors here. This only happens
|
|
306
|
+
// once _get() is called.
|
|
307
|
+
this._values[key] = value;
|
|
308
|
+
// Notify the owner of the style change. STYLE is always set,
|
|
309
|
+
// additional flags come from flags, as used for STROKE:
|
|
310
|
+
owner?._changed(flags[key] || Change.STYLE);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
_get(key, dontMerge) {
|
|
315
|
+
let value;
|
|
316
|
+
const owner = this.#owner;
|
|
317
|
+
const styles = owner?._getStyles(this, key);
|
|
318
|
+
const isColor = /Color$/.test(key);
|
|
319
|
+
// If true is passed for dontMerge, don't merge children styles.
|
|
320
|
+
if (styles && !dontMerge) {
|
|
321
|
+
value = Style.merge(styles, key);
|
|
322
|
+
}
|
|
323
|
+
else if (key in this._defaults) {
|
|
324
|
+
value = this._values[key];
|
|
325
|
+
if (value === undefined) {
|
|
326
|
+
// An unset value comes from the symbol items around the style, if
|
|
327
|
+
// one of them sets it, as their own:
|
|
328
|
+
for (let i = inheritedStyles.length - 1; i >= 0; i--) {
|
|
329
|
+
const style = inheritedStyles[i];
|
|
330
|
+
if (style._values[key] !== undefined) {
|
|
331
|
+
return style._get(key);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
value = this._defaults[key];
|
|
335
|
+
// Clone defaults if available:
|
|
336
|
+
if (value && value.clone) {
|
|
337
|
+
value = value.clone();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
const ctor = isColor ? Color : key === 'shadowOffset' ? Point : null;
|
|
342
|
+
if (ctor && value != null && value.constructor !== ctor) {
|
|
343
|
+
// Convert to a Color / Point, and store the result of the
|
|
344
|
+
// conversion.
|
|
345
|
+
this._values[key] = value = new ctor(value);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (value && isColor) {
|
|
350
|
+
// Color._setOwner() may clone the color if it already has a different
|
|
351
|
+
// owner (e.g. resulting from `childValue` above). Only provide a key for
|
|
352
|
+
// the owner to set the color again if the style is to be applied to the
|
|
353
|
+
// children:
|
|
354
|
+
value = Color._setOwner(value, owner, styles && key);
|
|
355
|
+
}
|
|
356
|
+
return value;
|
|
357
|
+
}
|
|
358
|
+
// Transforms the gradients and patterns among the style's own fill and
|
|
359
|
+
// stroke colors, see Item#transform():
|
|
360
|
+
_transformColors(matrix, options) {
|
|
361
|
+
for (const key of ['fillColor', 'strokeColor']) {
|
|
362
|
+
const value = this._values[key];
|
|
363
|
+
// Colors are stored as they are set, owned by the style's item, and
|
|
364
|
+
// descriptions of them become colors in #_get():
|
|
365
|
+
const color = value instanceof Color ? value : value && this._get(key, true);
|
|
366
|
+
const type = color?.type;
|
|
367
|
+
if (type === 'gradient' && options?.gradients !== false ||
|
|
368
|
+
type === 'pattern' && options?.patterns !== false) {
|
|
369
|
+
color.transform(matrix);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
equals(style) {
|
|
374
|
+
// Since we're dealing with defaults, loop through style values in both
|
|
375
|
+
// objects and compare with default fall-back. But in the secondary pass
|
|
376
|
+
// only check against keys that weren't already in the first object:
|
|
377
|
+
function compare(style1, style2, secondary) {
|
|
378
|
+
const values1 = style1._values;
|
|
379
|
+
const values2 = style2._values;
|
|
380
|
+
const defaults2 = style2._defaults;
|
|
381
|
+
for (const key in values1) {
|
|
382
|
+
const value1 = values1[key];
|
|
383
|
+
const value2 = values2[key];
|
|
384
|
+
if (!(secondary && key in values2) &&
|
|
385
|
+
!equals(value1, value2 === undefined ? defaults2[key] : value2)) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return true;
|
|
390
|
+
}
|
|
391
|
+
return (style === this || (style instanceof Style &&
|
|
392
|
+
compare(this, style) &&
|
|
393
|
+
compare(style, this, true)));
|
|
394
|
+
}
|
|
395
|
+
_dispose() {
|
|
396
|
+
for (const color of [this.fillColor, this.strokeColor, this.shadowColor]) {
|
|
397
|
+
if (color) {
|
|
398
|
+
color._canvasStyle = null;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Checks whether the style has a visible fill: a fill color that isn't
|
|
404
|
+
* fully transparent.
|
|
405
|
+
*
|
|
406
|
+
* @return {@true if the style has a visible fill}
|
|
407
|
+
*/
|
|
408
|
+
hasFill() {
|
|
409
|
+
const color = this.fillColor;
|
|
410
|
+
return !!color && color.alpha > 0;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Checks whether the style has a visible stroke: a stroke color that isn't
|
|
414
|
+
* fully transparent, and a stroke width above 0.
|
|
415
|
+
*
|
|
416
|
+
* @return {@true if the style has a visible stroke}
|
|
417
|
+
*/
|
|
418
|
+
hasStroke() {
|
|
419
|
+
const color = this.strokeColor;
|
|
420
|
+
return !!color && color.alpha > 0 && this.strokeWidth > 0;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Checks whether the style has a visible shadow: a shadow color that isn't
|
|
424
|
+
* fully transparent, with a blur or an offset.
|
|
425
|
+
*
|
|
426
|
+
* @return {@true if the style has a visible shadow}
|
|
427
|
+
*/
|
|
428
|
+
hasShadow() {
|
|
429
|
+
const color = this.shadowColor;
|
|
430
|
+
// In order to draw a shadow, we need either a shadow blur or an offset, or
|
|
431
|
+
// both.
|
|
432
|
+
return (!!color &&
|
|
433
|
+
color.alpha > 0 &&
|
|
434
|
+
(this.shadowBlur > 0 || !this.shadowOffset.isZero()));
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* The view that this style belongs to.
|
|
438
|
+
*/
|
|
439
|
+
get view() {
|
|
440
|
+
return this.#project.view;
|
|
441
|
+
}
|
|
442
|
+
// The font as canvas takes it:
|
|
443
|
+
_getCanvasFont() {
|
|
444
|
+
let fontSize = this.fontSize;
|
|
445
|
+
const { fontStyle } = this;
|
|
446
|
+
// CSS reads unquoted families only as identifiers, which can't start with
|
|
447
|
+
// digits, so quote all but single words and the ones that are quoted
|
|
448
|
+
// already:
|
|
449
|
+
const families = this.fontFamily.split(',').map((family) => {
|
|
450
|
+
family = family.trim();
|
|
451
|
+
return /^(["'].*|[a-z-]+)$/i.test(family)
|
|
452
|
+
? family
|
|
453
|
+
: `"${family.replace(/["\\]/g, '\\$&')}"`;
|
|
454
|
+
});
|
|
455
|
+
// Superscripts and subscripts are set smaller, unless the size has a unit:
|
|
456
|
+
if (!isNaN(fontSize)) {
|
|
457
|
+
fontSize *= baselinePositions[this.baselinePosition].size;
|
|
458
|
+
}
|
|
459
|
+
return ((fontStyle !== 'normal' ? fontStyle + ' ' : '') +
|
|
460
|
+
(this.letterCase === 'small-caps' ? 'small-caps ' : '') +
|
|
461
|
+
this.fontWeight +
|
|
462
|
+
' ' +
|
|
463
|
+
fontSize +
|
|
464
|
+
(/[a-z]/i.test(fontSize + '') ? ' ' : 'px ') +
|
|
465
|
+
families.join(', '));
|
|
466
|
+
}
|
|
467
|
+
// The letter tracking as canvas takes it: in thousandths of an em, which
|
|
468
|
+
// canvas resolves through the font of the context:
|
|
469
|
+
_getCanvasLetterSpacing() {
|
|
470
|
+
return `${this.letterTracking / 1000}em`;
|
|
471
|
+
}
|
|
472
|
+
// The font size in pixels, which it can be given in other units:
|
|
473
|
+
_getFontSize() {
|
|
474
|
+
const fontSize = this.fontSize;
|
|
475
|
+
return /pt|em|%|px/.test(fontSize)
|
|
476
|
+
? getPixelSize(this.view, fontSize)
|
|
477
|
+
: fontSize;
|
|
478
|
+
}
|
|
479
|
+
// The line height in pixels: automatic ('auto', 1.2, or another factor) of
|
|
480
|
+
// the font size, or fixed, with units as the font size takes them:
|
|
481
|
+
_getLineHeight() {
|
|
482
|
+
const { lineHeight } = this;
|
|
483
|
+
return lineHeight === 'auto'
|
|
484
|
+
? autoLineHeight * this._getFontSize()
|
|
485
|
+
: typeof lineHeight === 'string'
|
|
486
|
+
? getPixelSize(this.view, lineHeight)
|
|
487
|
+
: lineHeight * this._getFontSize();
|
|
488
|
+
}
|
|
489
|
+
static {
|
|
490
|
+
registerClasses({ Style: this });
|
|
491
|
+
// Iterate over all style properties to inject their getters and setters:
|
|
492
|
+
for (const key of Style.keys) {
|
|
493
|
+
inject(this.prototype, {
|
|
494
|
+
get [key]() {
|
|
495
|
+
return this._get(key);
|
|
496
|
+
},
|
|
497
|
+
set [key](value) {
|
|
498
|
+
this._set(key, value);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 entry of SVG import and export, for `use(svg)` with `paper/core`, see
|
|
13
|
+
// the `use()` function there. The `paper` entry has it already.
|
|
14
|
+
import { exportItemSVG, exportProjectSVG, importSVG, loadSVG } from "../internal.js";
|
|
15
|
+
/**
|
|
16
|
+
* The import and export of SVG, for `use(svg)` with `paper/core`, see the
|
|
17
|
+
* `use()` function there.
|
|
18
|
+
*/
|
|
19
|
+
export const svg = {
|
|
20
|
+
feature: {
|
|
21
|
+
name: 'svg',
|
|
22
|
+
exportItemSVG,
|
|
23
|
+
exportProjectSVG,
|
|
24
|
+
importSVG,
|
|
25
|
+
loadSVG
|
|
26
|
+
}
|
|
27
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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 { getDocument } from "../internal.js";
|
|
13
|
+
// SVG related namespaces
|
|
14
|
+
export const svgNamespace = 'http://www.w3.org/2000/svg';
|
|
15
|
+
const xmlnsNamespace = 'http://www.w3.org/2000/xmlns';
|
|
16
|
+
export const xlinkNamespace = 'http://www.w3.org/1999/xlink';
|
|
17
|
+
// Mapping of attribute names to required namespaces:
|
|
18
|
+
const attributeNamespace = {
|
|
19
|
+
'href': xlinkNamespace,
|
|
20
|
+
'xlink': xmlnsNamespace,
|
|
21
|
+
// Only the xmlns attribute needs the trailing slash. See #984
|
|
22
|
+
'xmlns': xmlnsNamespace + '/',
|
|
23
|
+
// IE needs the xmlns namespace when setting 'xmlns:xlink'. See #984
|
|
24
|
+
'xmlns:xlink': xmlnsNamespace + '/'
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Creates an SVG element with the tag and the attributes, with their numbers
|
|
28
|
+
* formatted by the formatter.
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
export function createSvgElement(tag, attributes, formatter) {
|
|
33
|
+
return setSvgAttributes(getDocument().createElementNS(svgNamespace, tag), attributes ?? {}, formatter);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the value of the node's attribute, read in its namespace if it has
|
|
37
|
+
* one.
|
|
38
|
+
*
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
export function getSvgAttribute(node, name) {
|
|
42
|
+
// SVG 2 replaces xlink:href with plain href, which takes precedence:
|
|
43
|
+
const namespace = attributeNamespace[name];
|
|
44
|
+
const value = namespace
|
|
45
|
+
? node.getAttribute(name) || node.getAttributeNS(namespace, name)
|
|
46
|
+
: node.getAttribute(name);
|
|
47
|
+
return value === 'null' ? null : value;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sets the attributes on the node, in their namespaces if they have one, with
|
|
51
|
+
* their numbers formatted by the formatter.
|
|
52
|
+
*
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
export function setSvgAttributes(node, attributes, formatter) {
|
|
56
|
+
for (const name in attributes) {
|
|
57
|
+
let value = attributes[name];
|
|
58
|
+
const namespace = attributeNamespace[name];
|
|
59
|
+
if (typeof value === 'number' && formatter) {
|
|
60
|
+
value = formatter.number(value);
|
|
61
|
+
}
|
|
62
|
+
if (namespace) {
|
|
63
|
+
node.setAttributeNS(namespace, name, value);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
node.setAttribute(name, value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return node;
|
|
70
|
+
}
|
|
71
|
+
// The attributes that hold the geometry of the elements that svgExport writes:
|
|
72
|
+
const geometryAttributes = [
|
|
73
|
+
'd', 'points', 'transform', 'x', 'y', 'width', 'height', 'cx', 'cy', 'r',
|
|
74
|
+
'rx', 'ry', 'x1', 'y1', 'x2', 'y2'
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Returns a hash of the geometry of the element and its descendants, which
|
|
78
|
+
* tells svgImport whether another editor changed what svgExport wrote for an
|
|
79
|
+
* item that it restores, see `data-paper-item`.
|
|
80
|
+
*
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
export function getGeometryHash(node) {
|
|
84
|
+
// FNV-1a, over the geometry attributes of the elements in document order:
|
|
85
|
+
let hash = 0x811c9dc5;
|
|
86
|
+
for (const element of [node, ...node.querySelectorAll('*')]) {
|
|
87
|
+
for (const name of geometryAttributes) {
|
|
88
|
+
const value = element.getAttribute(name);
|
|
89
|
+
if (value != null) {
|
|
90
|
+
for (const char of `${name}=${value};`) {
|
|
91
|
+
hash = Math.imul(hash ^ char.charCodeAt(0), 0x01000193);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
97
|
+
}
|