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,603 @@
|
|
|
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
|
+
// Based on goog.graphics.AffineTransform, as part of the Closure Library.
|
|
13
|
+
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
|
|
14
|
+
//
|
|
15
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
import { Formatter } from "../util/Formatter.js";
|
|
17
|
+
import { registerClasses, serialize } from "../core/serialization.js";
|
|
18
|
+
import { Base } from "../core/Base.js";
|
|
19
|
+
import { Point } from "./Point.js";
|
|
20
|
+
import { Rectangle } from "./Rectangle.js";
|
|
21
|
+
import { appendMatrix, createMatrix, inverseTransformPoint, prependMatrix, resetMatrix, rotateMatrix, scaleMatrix, setMatrix, transformPoint, translateMatrix } from "../values/matrix.js";
|
|
22
|
+
/**
|
|
23
|
+
* An affine transformation matrix performs a linear mapping from 2D
|
|
24
|
+
* coordinates to other 2D coordinates that preserves the "straightness" and
|
|
25
|
+
* "parallelness" of lines.
|
|
26
|
+
*
|
|
27
|
+
* Such a coordinate transformation can be represented by a 3 row by 3
|
|
28
|
+
* column matrix with an implied last row of `[ 0 0 1 ]`. This matrix
|
|
29
|
+
* transforms source coordinates `(x, y)` into destination coordinates `(x',y')`
|
|
30
|
+
* by considering them to be a column vector and multiplying the coordinate
|
|
31
|
+
* vector by the matrix according to the following process:
|
|
32
|
+
*
|
|
33
|
+
* [ x ] [ a c tx ] [ x ] [ a * x + c * y + tx ]
|
|
34
|
+
* [ y ] = [ b d ty ] [ y ] = [ b * x + d * y + ty ]
|
|
35
|
+
* [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
|
|
36
|
+
*
|
|
37
|
+
* Note the locations of b and c.
|
|
38
|
+
*
|
|
39
|
+
* This class is optimized for speed and minimizes calculations based on its
|
|
40
|
+
* knowledge of the underlying matrix (as opposed to say simply performing
|
|
41
|
+
* matrix multiplication).
|
|
42
|
+
*/
|
|
43
|
+
export class Matrix extends Base {
|
|
44
|
+
constructor(a, b, c, d, tx, ty) {
|
|
45
|
+
super();
|
|
46
|
+
// Most matrices are created without values, or with all six: Create
|
|
47
|
+
// their array as it is, where set() would write it a second time:
|
|
48
|
+
if (typeof a === 'number' && ty !== undefined) {
|
|
49
|
+
this._values = [a, b, c, d, tx, ty];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this._values = createMatrix();
|
|
53
|
+
if (a !== undefined) {
|
|
54
|
+
this.set(a, b, c, d, tx, ty);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Sets the matrix to the passed values. Note that any sequence of
|
|
60
|
+
* parameters that is supported by the various {@link Matrix()} constructors
|
|
61
|
+
* also work for calls of `set()`.
|
|
62
|
+
*
|
|
63
|
+
* @param a the matrix or its values to copy, or its `a` value, followed
|
|
64
|
+
* by `b`, `c`, `d`, `tx` and `ty`
|
|
65
|
+
*/
|
|
66
|
+
set(a, b, c, d, tx, ty) {
|
|
67
|
+
if (typeof a === 'number' && ty !== undefined) {
|
|
68
|
+
this._set(a, b, c, d, tx, ty);
|
|
69
|
+
}
|
|
70
|
+
else if (a === undefined) {
|
|
71
|
+
this.reset();
|
|
72
|
+
}
|
|
73
|
+
else if (a instanceof Matrix) {
|
|
74
|
+
const v = a._values;
|
|
75
|
+
this._set(v[0], v[1], v[2], v[3], v[4], v[5]);
|
|
76
|
+
}
|
|
77
|
+
else if (Array.isArray(a)) {
|
|
78
|
+
this._set(a[0], a[1], a[2], a[3], a[4], a[5]);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
throw new Error('Unsupported matrix parameters');
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
// See Point#_set() for an explanation of _set():
|
|
86
|
+
_set(a, b, c, d, tx, ty) {
|
|
87
|
+
setMatrix(this._values, a, b, c, d, tx, ty);
|
|
88
|
+
this.#changed();
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
_serialize(options, dictionary) {
|
|
92
|
+
return serialize(this.values, options, true, dictionary);
|
|
93
|
+
}
|
|
94
|
+
#changed() {
|
|
95
|
+
this._owner?._matrixChanged();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @return a copy of this transform
|
|
99
|
+
*/
|
|
100
|
+
clone() {
|
|
101
|
+
const v = this._values;
|
|
102
|
+
return new Matrix(v[0], v[1], v[2], v[3], v[4], v[5]);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Checks whether the two matrices describe the same transformation.
|
|
106
|
+
*
|
|
107
|
+
* @param matrix the matrix to compare this matrix to
|
|
108
|
+
* @return {@true if the matrices are equal}
|
|
109
|
+
*/
|
|
110
|
+
equals(matrix) {
|
|
111
|
+
const v = this._values;
|
|
112
|
+
const m = matrix?._values;
|
|
113
|
+
return !!(matrix === this || (m &&
|
|
114
|
+
v[0] === m[0] &&
|
|
115
|
+
v[1] === m[1] &&
|
|
116
|
+
v[2] === m[2] &&
|
|
117
|
+
v[3] === m[3] &&
|
|
118
|
+
v[4] === m[4] &&
|
|
119
|
+
v[5] === m[5]));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @return a string representation of this transform
|
|
123
|
+
*/
|
|
124
|
+
toString() {
|
|
125
|
+
const { instance } = Formatter;
|
|
126
|
+
const format = (...values) => values.map(value => instance.number(value)).join(', ');
|
|
127
|
+
const v = this._values;
|
|
128
|
+
return `[[${format(v[0], v[2], v[4])}], [${format(v[1], v[3], v[5])}]]`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Resets the matrix by setting its values to the ones of the identity
|
|
132
|
+
* matrix that results in no transformation.
|
|
133
|
+
*/
|
|
134
|
+
reset() {
|
|
135
|
+
resetMatrix(this._values);
|
|
136
|
+
this.#changed();
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Attempts to apply the matrix to the content of item that it belongs to,
|
|
141
|
+
* meaning its transformation is baked into the item's content or children.
|
|
142
|
+
*
|
|
143
|
+
* @param recursively controls whether to apply
|
|
144
|
+
* transformations recursively on children
|
|
145
|
+
* @return {@true if the matrix was applied}
|
|
146
|
+
*/
|
|
147
|
+
apply(recursively = true, _setApplyMatrix) {
|
|
148
|
+
return !!this._owner?._bakeMatrix?.(recursively, _setApplyMatrix);
|
|
149
|
+
}
|
|
150
|
+
translate(arg0, arg1) {
|
|
151
|
+
const { x, y } = Point.coerce(arg0, arg1);
|
|
152
|
+
translateMatrix(this._values, x, y);
|
|
153
|
+
this.#changed();
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
scale(arg0, arg1, arg2) {
|
|
157
|
+
const hasVer = typeof arg1 === 'number';
|
|
158
|
+
const scale = Point.coerce(arg0, hasVer ? arg1 : undefined);
|
|
159
|
+
const origin = hasVer ? arg2 : arg1;
|
|
160
|
+
const center = origin ? Point.from(origin) : null;
|
|
161
|
+
if (center) {
|
|
162
|
+
translateMatrix(this._values, center.x, center.y);
|
|
163
|
+
}
|
|
164
|
+
scaleMatrix(this._values, scale.x, scale.y);
|
|
165
|
+
if (center) {
|
|
166
|
+
translateMatrix(this._values, -center.x, -center.y);
|
|
167
|
+
}
|
|
168
|
+
this.#changed();
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Concatenates this matrix with a rotation transformation around an
|
|
173
|
+
* anchor point.
|
|
174
|
+
*
|
|
175
|
+
* @param angle the angle of rotation measured in degrees
|
|
176
|
+
* @param center the anchor point to rotate around
|
|
177
|
+
* @return this affine transform
|
|
178
|
+
*/
|
|
179
|
+
rotate(angle, center) {
|
|
180
|
+
const { x, y } = Point.from(center);
|
|
181
|
+
rotateMatrix(this._values, angle, x, y);
|
|
182
|
+
this.#changed();
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
shear(arg0, arg1, arg2) {
|
|
186
|
+
const hasVer = typeof arg1 === 'number';
|
|
187
|
+
const shear = Point.coerce(arg0, hasVer ? arg1 : undefined);
|
|
188
|
+
const origin = hasVer ? arg2 : arg1;
|
|
189
|
+
const center = origin ? Point.from(origin) : null;
|
|
190
|
+
const v = this._values;
|
|
191
|
+
if (center) {
|
|
192
|
+
translateMatrix(v, center.x, center.y);
|
|
193
|
+
}
|
|
194
|
+
const a = v[0];
|
|
195
|
+
const b = v[1];
|
|
196
|
+
v[0] += shear.y * v[2];
|
|
197
|
+
v[1] += shear.y * v[3];
|
|
198
|
+
v[2] += shear.x * a;
|
|
199
|
+
v[3] += shear.x * b;
|
|
200
|
+
if (center) {
|
|
201
|
+
translateMatrix(v, -center.x, -center.y);
|
|
202
|
+
}
|
|
203
|
+
this.#changed();
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
skew(arg0, arg1, arg2) {
|
|
207
|
+
const hasVer = typeof arg1 === 'number';
|
|
208
|
+
const skew = Point.coerce(arg0, hasVer ? arg1 : undefined);
|
|
209
|
+
const center = hasVer ? arg2 : arg1;
|
|
210
|
+
const toRadians = Math.PI / 180;
|
|
211
|
+
const shear = new Point(Math.tan(skew.x * toRadians), Math.tan(skew.y * toRadians));
|
|
212
|
+
return this.shear(shear, center);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Appends the specified matrix to this matrix. This is the equivalent of
|
|
216
|
+
* multiplying `(this matrix) * (specified matrix)`.
|
|
217
|
+
*
|
|
218
|
+
* @param matrix the matrix to append
|
|
219
|
+
* @return this matrix, modified
|
|
220
|
+
*/
|
|
221
|
+
append(matrix) {
|
|
222
|
+
if (matrix) {
|
|
223
|
+
appendMatrix(this._values, matrix._values);
|
|
224
|
+
this.#changed();
|
|
225
|
+
}
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Prepends the specified matrix to this matrix. This is the equivalent of
|
|
230
|
+
* multiplying `(specified matrix) * (this matrix)`.
|
|
231
|
+
*
|
|
232
|
+
* @param matrix the matrix to prepend
|
|
233
|
+
* @return this matrix, modified
|
|
234
|
+
*/
|
|
235
|
+
prepend(matrix) {
|
|
236
|
+
if (matrix) {
|
|
237
|
+
prependMatrix(this._values, matrix._values);
|
|
238
|
+
this.#changed();
|
|
239
|
+
}
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns a new matrix as the result of appending the specified matrix to
|
|
244
|
+
* this matrix. This is the equivalent of multiplying
|
|
245
|
+
* `(this matrix) * (specified matrix)`.
|
|
246
|
+
*
|
|
247
|
+
* @param matrix the matrix to append
|
|
248
|
+
* @return the newly created matrix
|
|
249
|
+
*/
|
|
250
|
+
appended(matrix) {
|
|
251
|
+
return this.clone().append(matrix);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns a new matrix as the result of prepending the specified matrix
|
|
255
|
+
* to this matrix. This is the equivalent of multiplying
|
|
256
|
+
* `(specified matrix) * (this matrix)`.
|
|
257
|
+
*
|
|
258
|
+
* @param matrix the matrix to prepend
|
|
259
|
+
* @return the newly created matrix
|
|
260
|
+
*/
|
|
261
|
+
prepended(matrix) {
|
|
262
|
+
return this.clone().prepend(matrix);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Inverts the matrix, causing it to perform the opposite transformation.
|
|
266
|
+
* If the matrix is not invertible (in which case {@link #isSingular()}
|
|
267
|
+
* returns true), `null` is returned.
|
|
268
|
+
*
|
|
269
|
+
* @return this matrix, or `null`, if the matrix is singular.
|
|
270
|
+
*/
|
|
271
|
+
invert() {
|
|
272
|
+
let res = null;
|
|
273
|
+
if (this.isInvertible()) {
|
|
274
|
+
const v = this._values;
|
|
275
|
+
const a = v[0];
|
|
276
|
+
const b = v[1];
|
|
277
|
+
const c = v[2];
|
|
278
|
+
const d = v[3];
|
|
279
|
+
const tx = v[4];
|
|
280
|
+
const ty = v[5];
|
|
281
|
+
const det = a * d - b * c;
|
|
282
|
+
v[0] = d / det;
|
|
283
|
+
v[1] = -b / det;
|
|
284
|
+
v[2] = -c / det;
|
|
285
|
+
v[3] = a / det;
|
|
286
|
+
v[4] = (c * ty - d * tx) / det;
|
|
287
|
+
v[5] = (b * tx - a * ty) / det;
|
|
288
|
+
res = this;
|
|
289
|
+
this.#changed();
|
|
290
|
+
}
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Creates a new matrix that is the inversion of this matrix, causing it to
|
|
295
|
+
* perform the opposite transformation. If the matrix is not invertible (in
|
|
296
|
+
* which case {@link #isSingular()} returns true), `null` is returned.
|
|
297
|
+
*
|
|
298
|
+
* @return the inverted matrix, or `null`, if the matrix is singular
|
|
299
|
+
*/
|
|
300
|
+
inverted() {
|
|
301
|
+
return this.clone().invert();
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* A private helper function to create a clone of this matrix, without the
|
|
305
|
+
* translation factored in.
|
|
306
|
+
*
|
|
307
|
+
* @return a clone of this matrix, with {@link #tx} and {@link #ty}
|
|
308
|
+
* set to `0`.
|
|
309
|
+
*/
|
|
310
|
+
_shiftless() {
|
|
311
|
+
const v = this._values;
|
|
312
|
+
return new Matrix(v[0], v[1], v[2], v[3], 0, 0);
|
|
313
|
+
}
|
|
314
|
+
_orNullIfIdentity() {
|
|
315
|
+
return this.isIdentity() ? null : this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* @return whether this matrix is the identity matrix
|
|
319
|
+
*/
|
|
320
|
+
isIdentity() {
|
|
321
|
+
const v = this._values;
|
|
322
|
+
return (v[0] === 1 &&
|
|
323
|
+
v[1] === 0 &&
|
|
324
|
+
v[2] === 0 &&
|
|
325
|
+
v[3] === 1 &&
|
|
326
|
+
v[4] === 0 &&
|
|
327
|
+
v[5] === 0);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Checks whether the matrix is invertible. A matrix is not invertible if
|
|
331
|
+
* the determinant is 0 or any value is infinite or NaN.
|
|
332
|
+
*
|
|
333
|
+
* @return whether the matrix is invertible
|
|
334
|
+
*/
|
|
335
|
+
isInvertible() {
|
|
336
|
+
const v = this._values;
|
|
337
|
+
const det = v[0] * v[3] - v[2] * v[1];
|
|
338
|
+
return !!det && !isNaN(det) && isFinite(v[4]) && isFinite(v[5]);
|
|
339
|
+
}
|
|
340
|
+
// The geometric mean of the scale factors, as used for strokes:
|
|
341
|
+
_getMeanScale() {
|
|
342
|
+
const v = this._values;
|
|
343
|
+
return Math.sqrt(Math.abs(v[0] * v[3] - v[1] * v[2]));
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Checks whether the matrix is singular or not. Singular matrices cannot be
|
|
347
|
+
* inverted.
|
|
348
|
+
*
|
|
349
|
+
* @return whether the matrix is singular
|
|
350
|
+
*/
|
|
351
|
+
isSingular() {
|
|
352
|
+
return !this.isInvertible();
|
|
353
|
+
}
|
|
354
|
+
transform(src, dst, count) {
|
|
355
|
+
return count === undefined
|
|
356
|
+
? this._transformPoint(Point.from(src, dst))
|
|
357
|
+
: this._transformCoordinates(src, dst, count);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* A faster version of transform that only takes one point and does not
|
|
361
|
+
* attempt to convert it.
|
|
362
|
+
*/
|
|
363
|
+
_transformPoint(point, dest) {
|
|
364
|
+
return transformPoint(this._values, point, dest);
|
|
365
|
+
}
|
|
366
|
+
_transformCoordinates(src, dst, count) {
|
|
367
|
+
const v = this._values;
|
|
368
|
+
for (let i = 0, max = 2 * count; i < max; i += 2) {
|
|
369
|
+
const x = src[i];
|
|
370
|
+
const y = src[i + 1];
|
|
371
|
+
dst[i] = x * v[0] + y * v[2] + v[4];
|
|
372
|
+
dst[i + 1] = x * v[1] + y * v[3] + v[5];
|
|
373
|
+
}
|
|
374
|
+
return dst;
|
|
375
|
+
}
|
|
376
|
+
_transformCorners(rect) {
|
|
377
|
+
const x1 = rect.x;
|
|
378
|
+
const y1 = rect.y;
|
|
379
|
+
const x2 = x1 + rect.width;
|
|
380
|
+
const y2 = y1 + rect.height;
|
|
381
|
+
const coords = [x1, y1, x2, y1, x2, y2, x1, y2];
|
|
382
|
+
return this._transformCoordinates(coords, coords, 4);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Returns the 'transformed' bounds rectangle by transforming each corner
|
|
386
|
+
* point and finding the new bounding box to these points. This is not
|
|
387
|
+
* really the transformed rectangle!
|
|
388
|
+
*/
|
|
389
|
+
_transformBounds(bounds, dest) {
|
|
390
|
+
const coords = this._transformCorners(bounds);
|
|
391
|
+
const min = coords.slice(0, 2);
|
|
392
|
+
const max = min.slice();
|
|
393
|
+
for (let i = 2; i < 8; i++) {
|
|
394
|
+
const val = coords[i];
|
|
395
|
+
const j = i & 1;
|
|
396
|
+
if (val < min[j]) {
|
|
397
|
+
min[j] = val;
|
|
398
|
+
}
|
|
399
|
+
else if (val > max[j]) {
|
|
400
|
+
max[j] = val;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return (dest ?? new Rectangle())._set(min[0], min[1], max[0] - min[0], max[1] - min[1]);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Inverse transforms a point and returns the result.
|
|
407
|
+
*
|
|
408
|
+
* @param point the point to be transformed
|
|
409
|
+
*/
|
|
410
|
+
inverseTransform(point, y) {
|
|
411
|
+
return this._inverseTransform(Point.from(point, y));
|
|
412
|
+
}
|
|
413
|
+
_inverseTransform(point) {
|
|
414
|
+
return this.isInvertible()
|
|
415
|
+
? inverseTransformPoint(this._values, point)
|
|
416
|
+
: null;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Decomposes the affine transformation described by this matrix into
|
|
420
|
+
* `scaling`, `rotation` and `skewing`, and returns an object with
|
|
421
|
+
* these properties.
|
|
422
|
+
*
|
|
423
|
+
* @return the decomposed matrix
|
|
424
|
+
*/
|
|
425
|
+
decompose() {
|
|
426
|
+
// http://dev.w3.org/csswg/css3-2d-transforms/#matrix-decomposition
|
|
427
|
+
// http://www.maths-informatique-jeux.com/blog/frederic/?post/2013/12/01/Decomposition-of-2D-transform-matrices
|
|
428
|
+
// https://github.com/wisec/DOMinator/blob/master/layout/style/nsStyleAnimation.cpp#L946
|
|
429
|
+
const v = this._values;
|
|
430
|
+
const a = v[0];
|
|
431
|
+
const b = v[1];
|
|
432
|
+
const c = v[2];
|
|
433
|
+
const d = v[3];
|
|
434
|
+
const det = a * d - b * c;
|
|
435
|
+
const { sqrt, atan2 } = Math;
|
|
436
|
+
const degrees = 180 / Math.PI;
|
|
437
|
+
let rotate;
|
|
438
|
+
let scale;
|
|
439
|
+
let skew;
|
|
440
|
+
if (a !== 0 || b !== 0) {
|
|
441
|
+
const r = sqrt(a * a + b * b);
|
|
442
|
+
rotate = Math.acos(a / r) * (b > 0 ? 1 : -1);
|
|
443
|
+
scale = [r, det / r];
|
|
444
|
+
skew = [atan2(a * c + b * d, r * r), 0];
|
|
445
|
+
}
|
|
446
|
+
else if (c !== 0 || d !== 0) {
|
|
447
|
+
const s = sqrt(c * c + d * d);
|
|
448
|
+
rotate = Math.asin(c / s) * (d > 0 ? 1 : -1);
|
|
449
|
+
scale = [det / s, s];
|
|
450
|
+
skew = [0, atan2(a * c + b * d, s * s)];
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
// a = b = c = d = 0
|
|
454
|
+
rotate = 0;
|
|
455
|
+
skew = scale = [0, 0];
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
translation: this.translation,
|
|
459
|
+
rotation: rotate * degrees,
|
|
460
|
+
scaling: new Point(scale),
|
|
461
|
+
skewing: new Point(skew[0] * degrees, skew[1] * degrees)
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* The matrix values as an array, in the same sequence as they are passed
|
|
466
|
+
* to {@link Matrix()}.
|
|
467
|
+
*/
|
|
468
|
+
get values() {
|
|
469
|
+
return [...this._values];
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* The translation of the matrix as a vector.
|
|
473
|
+
*/
|
|
474
|
+
get translation() {
|
|
475
|
+
// No decomposition is required to extract translation.
|
|
476
|
+
const v = this._values;
|
|
477
|
+
return new Point(v[4], v[5]);
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* The scaling values of the matrix, if it can be decomposed.
|
|
481
|
+
*
|
|
482
|
+
* @see #decompose()
|
|
483
|
+
*/
|
|
484
|
+
get scaling() {
|
|
485
|
+
return this.decompose().scaling;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* The rotation angle of the matrix, if it can be decomposed.
|
|
489
|
+
*
|
|
490
|
+
* @see #decompose()
|
|
491
|
+
*/
|
|
492
|
+
get rotation() {
|
|
493
|
+
return this.decompose().rotation;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Applies this matrix to the specified Canvas Context.
|
|
497
|
+
*
|
|
498
|
+
* @param ctx
|
|
499
|
+
*/
|
|
500
|
+
applyToContext(ctx) {
|
|
501
|
+
if (!this.isIdentity()) {
|
|
502
|
+
const v = this._values;
|
|
503
|
+
ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Returns the horizontal and vertical half-extents of a circle of the
|
|
508
|
+
* given radius, transformed by the matrix, if any.
|
|
509
|
+
*/
|
|
510
|
+
static _getCircleExtents(radius, matrix) {
|
|
511
|
+
if (!matrix)
|
|
512
|
+
return [radius, radius];
|
|
513
|
+
// x = radius * (a * cos(t) + c * sin(t)) is at most
|
|
514
|
+
// radius * sqrt(a² + c²), and y the same with b and d:
|
|
515
|
+
const v = matrix._values;
|
|
516
|
+
const a = v[0];
|
|
517
|
+
const b = v[1];
|
|
518
|
+
const c = v[2];
|
|
519
|
+
const d = v[3];
|
|
520
|
+
return [
|
|
521
|
+
radius * Math.sqrt(a * a + c * c),
|
|
522
|
+
radius * Math.sqrt(b * b + d * d)
|
|
523
|
+
];
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* The value that affects the transformation along the x axis when scaling
|
|
527
|
+
* or rotating, positioned at (0, 0) in the transformation matrix.
|
|
528
|
+
*/
|
|
529
|
+
get a() {
|
|
530
|
+
return this._values[0];
|
|
531
|
+
}
|
|
532
|
+
set a(a) {
|
|
533
|
+
this._values[0] = a;
|
|
534
|
+
this.#changed();
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* The value that affects the transformation along the y axis when rotating
|
|
538
|
+
* or skewing, positioned at (1, 0) in the transformation matrix.
|
|
539
|
+
*/
|
|
540
|
+
get b() {
|
|
541
|
+
return this._values[1];
|
|
542
|
+
}
|
|
543
|
+
set b(b) {
|
|
544
|
+
this._values[1] = b;
|
|
545
|
+
this.#changed();
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* The value that affects the transformation along the x axis when rotating
|
|
549
|
+
* or skewing, positioned at (0, 1) in the transformation matrix.
|
|
550
|
+
*/
|
|
551
|
+
get c() {
|
|
552
|
+
return this._values[2];
|
|
553
|
+
}
|
|
554
|
+
set c(c) {
|
|
555
|
+
this._values[2] = c;
|
|
556
|
+
this.#changed();
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* The value that affects the transformation along the y axis when scaling
|
|
560
|
+
* or rotating, positioned at (1, 1) in the transformation matrix.
|
|
561
|
+
*/
|
|
562
|
+
get d() {
|
|
563
|
+
return this._values[3];
|
|
564
|
+
}
|
|
565
|
+
set d(d) {
|
|
566
|
+
this._values[3] = d;
|
|
567
|
+
this.#changed();
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* The distance by which to translate along the x axis, positioned at (2, 0)
|
|
571
|
+
* in the transformation matrix.
|
|
572
|
+
*/
|
|
573
|
+
get tx() {
|
|
574
|
+
return this._values[4];
|
|
575
|
+
}
|
|
576
|
+
set tx(tx) {
|
|
577
|
+
this._values[4] = tx;
|
|
578
|
+
this.#changed();
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* The distance by which to translate along the y axis, positioned at (2, 1)
|
|
582
|
+
* in the transformation matrix.
|
|
583
|
+
*/
|
|
584
|
+
get ty() {
|
|
585
|
+
return this._values[5];
|
|
586
|
+
}
|
|
587
|
+
set ty(ty) {
|
|
588
|
+
this._values[5] = ty;
|
|
589
|
+
this.#changed();
|
|
590
|
+
}
|
|
591
|
+
static {
|
|
592
|
+
registerClasses({ Matrix: this });
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
// Returns a new matrix, scaled, sheared or skewed around the center, or else
|
|
596
|
+
// the origin. The methods also take their two factors as numbers:
|
|
597
|
+
export function createTransform(key, value, ver, center, origin) {
|
|
598
|
+
const matrix = new Matrix();
|
|
599
|
+
const method = matrix[key];
|
|
600
|
+
return typeof ver === 'number'
|
|
601
|
+
? method.call(matrix, value, ver, center ?? origin)
|
|
602
|
+
: method.call(matrix, value, ver ?? origin);
|
|
603
|
+
}
|