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,527 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
3
|
+
* http://paperjs.org/
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2011 - 2026, Jürg Lehni & Jonathan Puckey
|
|
6
|
+
* http://juerglehni.com/ & https://puckey.studio/
|
|
7
|
+
*
|
|
8
|
+
* Distributed under the MIT license. See LICENSE file for details.
|
|
9
|
+
*
|
|
10
|
+
* All rights reserved.
|
|
11
|
+
*/
|
|
12
|
+
import { Item, Key, KeyEvent, MouseEvent, Point, Size, View, addEvents, defineEvents, getDocument, getInsets, getSize, getWindow, installKeyEvents } from "../internal.js";
|
|
13
|
+
// The time in milliseconds and the distance within which a second click is a
|
|
14
|
+
// double-click. Firefox uses 300ms as the max time difference:
|
|
15
|
+
const doubleClickTime = 300;
|
|
16
|
+
const doubleClickDistance = 3;
|
|
17
|
+
// The input of a view: the state of the pointer on it, and the handling of
|
|
18
|
+
// its mouse and key events, from the DOM or from View#dispatchMouseEvent()
|
|
19
|
+
// and View#dispatchKeyEvent() for hosts without a DOM, which it delegates to
|
|
20
|
+
// items, the view and the tool. The views share the keyboard's focus:
|
|
21
|
+
export class ViewInput {
|
|
22
|
+
#view;
|
|
23
|
+
// Count the installed native and virtual item events, see
|
|
24
|
+
// countItemEvent():
|
|
25
|
+
itemEvents = { native: {}, virtual: {} };
|
|
26
|
+
// Whether a press started on the view, whether it had its default
|
|
27
|
+
// prevented, see viewEvents.touchstart(), and the last point:
|
|
28
|
+
dragging = false;
|
|
29
|
+
isPrevented = false;
|
|
30
|
+
lastPoint = null;
|
|
31
|
+
#called = false;
|
|
32
|
+
#prevented = false;
|
|
33
|
+
#wasInView = false;
|
|
34
|
+
#downPoint = null;
|
|
35
|
+
#downItem = null;
|
|
36
|
+
#overItem = null;
|
|
37
|
+
#dragItem = null;
|
|
38
|
+
#clickItem = null;
|
|
39
|
+
#clickTime = null;
|
|
40
|
+
#dblClick = false;
|
|
41
|
+
constructor(view) {
|
|
42
|
+
this.#view = view;
|
|
43
|
+
}
|
|
44
|
+
// Handles mouse events, and delegates them to items and tools:
|
|
45
|
+
handleMouseEvent(type, event, point, dispatched) {
|
|
46
|
+
const { itemEvents } = this;
|
|
47
|
+
// Look up hitItems, which tells us whether a given native mouse
|
|
48
|
+
// event requires an item hit-test or not, before changing type
|
|
49
|
+
// to the virtual value (e.g. mousemove -> mousedrag):
|
|
50
|
+
const hitItems = itemEvents.native[type];
|
|
51
|
+
const nativeMove = type === 'mousemove';
|
|
52
|
+
const { tool } = this.#view.scope;
|
|
53
|
+
const responds = (type) => (itemEvents.virtual[type] ||
|
|
54
|
+
this.#view.responds(type) ||
|
|
55
|
+
tool?.responds(type));
|
|
56
|
+
// Whether the press needs its default prevented for the events
|
|
57
|
+
// that follow it: the view's or the tool's mouseup, or those of the
|
|
58
|
+
// hit item and its ancestors. Presses elsewhere are left to the
|
|
59
|
+
// browser, so touches can scroll the page (#1930):
|
|
60
|
+
const needsUp = (hitItem) => {
|
|
61
|
+
if (this.#view.responds('mouseup') || tool?.responds('mouseup')) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
for (let item = hitItem; item; item = item._parent) {
|
|
65
|
+
for (const key in itemEventsMap.mouseup) {
|
|
66
|
+
if (item.responds(key)) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
73
|
+
// DOM events know the state of the modifier keys, also of those
|
|
74
|
+
// pressed or released while the page didn't have the focus, so no
|
|
75
|
+
// key event told us about them (#1140):
|
|
76
|
+
if (event.shiftKey !== undefined) {
|
|
77
|
+
Object.assign(Key.modifiers, {
|
|
78
|
+
shift: event.shiftKey,
|
|
79
|
+
control: event.ctrlKey,
|
|
80
|
+
alt: event.altKey,
|
|
81
|
+
meta: event.metaKey
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// If it's a native mousemove event but the mouse is down, and at
|
|
85
|
+
// least one of the events responds to mousedrag, convert to it.
|
|
86
|
+
// NOTE: #emitMouseEvent(), as well as Tool#_handleMouseEvent() fall
|
|
87
|
+
// back to mousemove if the objects don't respond to mousedrag.
|
|
88
|
+
if (nativeMove && this.dragging && responds('mousedrag')) {
|
|
89
|
+
type = 'mousedrag';
|
|
90
|
+
}
|
|
91
|
+
// A pointer that is locked to the view's element stands still, and
|
|
92
|
+
// reports how far it would have moved instead. Move its last point by
|
|
93
|
+
// that, wherever this takes it, as it can't leave the view (#1802):
|
|
94
|
+
const isLocked = (!dispatched &&
|
|
95
|
+
!!this.lastPoint &&
|
|
96
|
+
getDocument().pointerLockElement === this.#view._element);
|
|
97
|
+
point ??= isLocked
|
|
98
|
+
? this.lastPoint.add(getOffsetPoint(this.#view, new Point(event.movementX, event.movementY)).subtract(getOffsetPoint(this.#view, new Point())))
|
|
99
|
+
: this.#view.getEventPoint(event);
|
|
100
|
+
// The view only receives the moves of pointers over it and of those
|
|
101
|
+
// that it captured, which are still dragging outside of it. The last
|
|
102
|
+
// one as the pointer leaves it is outside too, also where another
|
|
103
|
+
// element covers the view there, such as a menu (#992):
|
|
104
|
+
const inView = (dispatched ||
|
|
105
|
+
isLocked ||
|
|
106
|
+
event.type !== 'pointerleave' && this.#view.bounds.contains(point));
|
|
107
|
+
// Run the hit-test on items first, but only if we're required
|
|
108
|
+
// to do so for this given mouse event, see hitItems and
|
|
109
|
+
// #countItemEvent():
|
|
110
|
+
const hit = hitItems && inView
|
|
111
|
+
? // Removed views receive no events:
|
|
112
|
+
this.#view._project.hitTest(point, {
|
|
113
|
+
tolerance: this.#view.scope.settings.hitTolerance,
|
|
114
|
+
fill: true,
|
|
115
|
+
stroke: true
|
|
116
|
+
})
|
|
117
|
+
: null;
|
|
118
|
+
const hitItem = hit?.item ?? null;
|
|
119
|
+
// Keep track if view event should be handled, so we can use it
|
|
120
|
+
// to decide if tool._handleMouseEvent() shall be called after.
|
|
121
|
+
let handle = false;
|
|
122
|
+
// Create a simple lookup object to quickly check for different
|
|
123
|
+
// mouse event types.
|
|
124
|
+
const mouse = { [type.slice(5)]: true };
|
|
125
|
+
// Handle mouseenter / leave between items and views first.
|
|
126
|
+
if (hitItems && hitItem !== this.#overItem) {
|
|
127
|
+
if (this.#overItem) {
|
|
128
|
+
this.#emitMouseEvent(this.#overItem, null, 'mouseleave', event, point);
|
|
129
|
+
}
|
|
130
|
+
if (hitItem) {
|
|
131
|
+
this.#emitMouseEvent(hitItem, null, 'mouseenter', event, point);
|
|
132
|
+
}
|
|
133
|
+
this.#overItem = hitItem;
|
|
134
|
+
}
|
|
135
|
+
// Handle mouseenter / leave on the view.
|
|
136
|
+
const hasCrossed = this.#wasInView !== inView;
|
|
137
|
+
if (hasCrossed) {
|
|
138
|
+
this.#emitMouseEvent(this.#view, null, inView ? 'mouseenter' : 'mouseleave', event, point);
|
|
139
|
+
handle = true; // To include the leaving move.
|
|
140
|
+
}
|
|
141
|
+
// Now handle the mousemove / mousedrag event.
|
|
142
|
+
// Always call the view's mouse handlers first, as required by
|
|
143
|
+
// CanvasView, and then handle the active tool after, if any.
|
|
144
|
+
// mousedrag is allowed to leave the view and still triggers events,
|
|
145
|
+
// but do not trigger two subsequent even with the same location.
|
|
146
|
+
if ((inView || mouse.drag) && !point.equals(this.lastPoint)) {
|
|
147
|
+
// Handle mousemove even if this is not actually a mousemove
|
|
148
|
+
// event but the mouse has moved since the last event.
|
|
149
|
+
this.#emitMouseEvents(hitItem, nativeMove ? type : 'mousemove', event, point, this.lastPoint);
|
|
150
|
+
handle = true;
|
|
151
|
+
}
|
|
152
|
+
this.#wasInView = inView;
|
|
153
|
+
// Now handle mousedown / mouseup
|
|
154
|
+
// We emit mousedown only when in the view, and mouseup regardless,
|
|
155
|
+
// as long as the mousedown event was inside.
|
|
156
|
+
if (mouse.down && inView || mouse.up && this.#downPoint) {
|
|
157
|
+
this.#emitMouseEvents(hitItem, type, event, point, this.#downPoint);
|
|
158
|
+
if (mouse.down) {
|
|
159
|
+
// See if we're clicking again on the same item, within the
|
|
160
|
+
// double-click time and distance, measured from mousedown
|
|
161
|
+
// to mousedown like native dblclick events, but not for a
|
|
162
|
+
// third click:
|
|
163
|
+
const time = Date.now();
|
|
164
|
+
this.#dblClick = (!this.#dblClick &&
|
|
165
|
+
hitItem === this.#clickItem &&
|
|
166
|
+
time - this.#clickTime < doubleClickTime &&
|
|
167
|
+
point.getDistance(this.#downPoint) < doubleClickDistance);
|
|
168
|
+
this.#downItem = this.#clickItem = hitItem;
|
|
169
|
+
this.#clickTime = time;
|
|
170
|
+
// Only start dragging if the mousedown event has not
|
|
171
|
+
// prevented the default, and if the hitItem or any of its
|
|
172
|
+
// parents actually respond to mousedrag events.
|
|
173
|
+
if (!this.#prevented && hitItem) {
|
|
174
|
+
let item = hitItem;
|
|
175
|
+
while (item && !item.responds('mousedrag')) {
|
|
176
|
+
item = item._parent;
|
|
177
|
+
}
|
|
178
|
+
if (item) {
|
|
179
|
+
this.#dragItem = hitItem;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
this.#downPoint = point;
|
|
183
|
+
}
|
|
184
|
+
else if (mouse.up) {
|
|
185
|
+
// Emulate click / doubleclick, but only on the hit-item,
|
|
186
|
+
// not the view.
|
|
187
|
+
if (!this.#prevented && hitItem === this.#downItem) {
|
|
188
|
+
this.#emitMouseEvents(hitItem, this.#dblClick ? 'doubleclick' : 'click', event, point, this.#downPoint);
|
|
189
|
+
}
|
|
190
|
+
this.#downItem = this.#dragItem = null;
|
|
191
|
+
}
|
|
192
|
+
handle = true;
|
|
193
|
+
}
|
|
194
|
+
this.lastPoint = point;
|
|
195
|
+
// Now finally call the tool events, but filter mouse move events
|
|
196
|
+
// to only be fired if we're inside the view or if we just left it.
|
|
197
|
+
// Prevent default if at least one handler was called, and none of
|
|
198
|
+
// them enforces default, to prevent scrolling on touch devices.
|
|
199
|
+
if (handle && tool) {
|
|
200
|
+
// The tool enters the view before its move there, and leaves it after
|
|
201
|
+
// the move that left:
|
|
202
|
+
if (hasCrossed && inView) {
|
|
203
|
+
tool._handleMouseEvent('mouseenter', event, point, { enter: true });
|
|
204
|
+
}
|
|
205
|
+
this.#called = (tool._handleMouseEvent(type, event, point, mouse) ||
|
|
206
|
+
this.#called);
|
|
207
|
+
if (hasCrossed && !inView) {
|
|
208
|
+
tool._handleMouseEvent('mouseleave', event, point, { leave: true });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Now call `preventDefault()`, if any of these conditions are met:
|
|
212
|
+
// - If any of the handlers were called, except for mousemove events
|
|
213
|
+
// which can call `preventDefault()` explicitly or return `false`.
|
|
214
|
+
// - If this is a unhandled mousedown event, but what follows needs
|
|
215
|
+
// it, see needsUp().
|
|
216
|
+
//
|
|
217
|
+
// Some events are not cancelable anyway (like during a scroll
|
|
218
|
+
// inertia on mobile) so trying to prevent default in those case
|
|
219
|
+
// would result in no effect and an error.
|
|
220
|
+
if (event.cancelable !== false &&
|
|
221
|
+
(this.#called && !mouse.move || mouse.down && needsUp(hitItem))) {
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Emit the event on the object and its parents, and return whether it was
|
|
226
|
+
// stopped:
|
|
227
|
+
#emitMouseEvent(obj, target, type, event, point, prevPoint, stopItem) {
|
|
228
|
+
let stopped = false;
|
|
229
|
+
let mouseEvent;
|
|
230
|
+
// Returns true if the event was stopped, false otherwise.
|
|
231
|
+
const emit = (obj, type) => {
|
|
232
|
+
if (obj.responds(type)) {
|
|
233
|
+
// Only produce the event object if we really need it, and then
|
|
234
|
+
// reuse it if we're bubbling.
|
|
235
|
+
mouseEvent ??= new MouseEvent(type, event, point, target || obj,
|
|
236
|
+
// Calculate delta if prevPoint was passed
|
|
237
|
+
prevPoint ? point.subtract(prevPoint) : null);
|
|
238
|
+
if (obj.emit(type, mouseEvent)) {
|
|
239
|
+
this.#called = true;
|
|
240
|
+
if (mouseEvent.prevented) {
|
|
241
|
+
this.#prevented = true;
|
|
242
|
+
}
|
|
243
|
+
// Bail out if propagation is stopped
|
|
244
|
+
if (mouseEvent.stopped) {
|
|
245
|
+
return (stopped = true);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
const fallback = fallbacks[type];
|
|
251
|
+
if (fallback) {
|
|
252
|
+
return emit(obj, fallback);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
};
|
|
257
|
+
// Bubble up the parents and emit this event until we're told to stop.
|
|
258
|
+
while (obj && obj !== stopItem) {
|
|
259
|
+
if (emit(obj, type)) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
obj = obj._parent;
|
|
263
|
+
}
|
|
264
|
+
return stopped;
|
|
265
|
+
}
|
|
266
|
+
// Emit the event on the drag item, the hit item and the view, and return
|
|
267
|
+
// whether it was stopped:
|
|
268
|
+
#emitMouseEvents(hitItem, type, event, point, prevPoint) {
|
|
269
|
+
// Before handling events, process removeOn() calls for cleanup.
|
|
270
|
+
// NOTE: As soon as there is one event handler receiving mousedrag
|
|
271
|
+
// events, non of the removeOnMove() items will be removed while the
|
|
272
|
+
// user is dragging.
|
|
273
|
+
this.#view._project.removeOn(type);
|
|
274
|
+
// Set called and prevented to false, so they will reflect if the
|
|
275
|
+
// following calls to #emitMouseEvent() have called a handler, and if
|
|
276
|
+
// and of the handlers called event.preventDefault()
|
|
277
|
+
this.#prevented = this.#called = false;
|
|
278
|
+
// First handle the drag-item and its parents, through bubbling.
|
|
279
|
+
return ((this.#dragItem &&
|
|
280
|
+
this.#emitMouseEvent(this.#dragItem, null, type, event, point, prevPoint)) ||
|
|
281
|
+
// Next handle the hit-item, if it's different from the drag-item
|
|
282
|
+
// and not a descendant of it (in which case it would already have
|
|
283
|
+
// received an event in the call above). Translate mousedrag to
|
|
284
|
+
// mousemove, since drag is handled above.
|
|
285
|
+
(hitItem &&
|
|
286
|
+
hitItem !== this.#dragItem &&
|
|
287
|
+
!hitItem.isDescendant(this.#dragItem) &&
|
|
288
|
+
this.#emitMouseEvent(hitItem, null, type === 'mousedrag' ? 'mousemove' : type, event, point, prevPoint, this.#dragItem)) ||
|
|
289
|
+
// Lastly handle the mouse events on the view, if we're still here.
|
|
290
|
+
this.#emitMouseEvent(this.#view, this.#dragItem || hitItem || this.#view, type, event, point, prevPoint));
|
|
291
|
+
}
|
|
292
|
+
handleKeyEvent(type, event, key, character) {
|
|
293
|
+
const { scope } = this.#view;
|
|
294
|
+
const { tool } = scope;
|
|
295
|
+
let keyEvent;
|
|
296
|
+
const emit = (obj) => {
|
|
297
|
+
if (obj.responds(type)) {
|
|
298
|
+
// Update global reference to this scope.
|
|
299
|
+
scope.activate();
|
|
300
|
+
// Only produce the event object if we really need it.
|
|
301
|
+
keyEvent ??= new KeyEvent(type, event, key, character);
|
|
302
|
+
obj.emit(type, keyEvent);
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
// Call the onKeyDown or onKeyUp handler if present
|
|
306
|
+
emit(this.#view);
|
|
307
|
+
if (tool?.responds(type)) {
|
|
308
|
+
emit(tool);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
countItemEvent(type, sign) {
|
|
312
|
+
// If the view requires counting of installed mouse events,
|
|
313
|
+
// change the event counters now according to itemEventsMap
|
|
314
|
+
// (defined in the code further below).
|
|
315
|
+
const { native, virtual } = this.itemEvents;
|
|
316
|
+
for (const key in itemEventsMap) {
|
|
317
|
+
native[key] = (native[key] || 0) + (itemEventsMap[key][type] || 0) * sign;
|
|
318
|
+
}
|
|
319
|
+
// Also update the count of virtual events installed.
|
|
320
|
+
virtual[type] = (virtual[type] || 0) + sign;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
// Returns the point in project coordinates at the offset from the top left
|
|
324
|
+
// of the view's element on screen:
|
|
325
|
+
export function getOffsetPoint(view, offset) {
|
|
326
|
+
// Only views with elements receive the events of pointers:
|
|
327
|
+
const element = view._element;
|
|
328
|
+
const size = getSize(element);
|
|
329
|
+
// Map the offset on screen, with CSS sizes and transforms applied, to
|
|
330
|
+
// the content box in view coordinates (#549, #1729). Elements that
|
|
331
|
+
// aren't rendered have no size to map from:
|
|
332
|
+
if (!size.isZero()) {
|
|
333
|
+
const cssSize = new Size(element.offsetWidth, element.offsetHeight);
|
|
334
|
+
offset = offset
|
|
335
|
+
.multiply(cssSize.divide(size))
|
|
336
|
+
.subtract(getInsets(element, true))
|
|
337
|
+
.multiply(view.viewSize.divide(cssSize.subtract(getInsets(element))));
|
|
338
|
+
}
|
|
339
|
+
return view.viewToProject(offset);
|
|
340
|
+
}
|
|
341
|
+
// Keep track of views internally, and of their elements, to find them from
|
|
342
|
+
// the DOM's events:
|
|
343
|
+
export const views = [];
|
|
344
|
+
export const viewsByElement = new WeakMap();
|
|
345
|
+
// Whether installEvents() has defined the events, and added the DOM's
|
|
346
|
+
// listeners for input, which the views that handle it share:
|
|
347
|
+
let isInstalled = false;
|
|
348
|
+
let hasInputEvents = false;
|
|
349
|
+
// The DOM's events, which installEvents() sets up, on the elements of the
|
|
350
|
+
// views that handle input:
|
|
351
|
+
export let viewEvents = {};
|
|
352
|
+
let prevFocus;
|
|
353
|
+
let tempFocus;
|
|
354
|
+
// Higher level event handling, hit-testing, and emitting of normal mouse
|
|
355
|
+
// events along with "virtual" events such as mouseenter, mouseleave,
|
|
356
|
+
// mousedrag, click, doubleclick, on both the hit-test item and the view,
|
|
357
|
+
// with support for bubbling (event-propagation).
|
|
358
|
+
// Event fallbacks for "virutal" events, e.g. if an item doesn't respond
|
|
359
|
+
// to doubleclick, fall back to click:
|
|
360
|
+
const fallbacks = {
|
|
361
|
+
doubleclick: 'click',
|
|
362
|
+
mousedrag: 'mousemove'
|
|
363
|
+
};
|
|
364
|
+
// Lookup defining which native events are required by which item events.
|
|
365
|
+
// Required by code that is counting the amount of required natives events.
|
|
366
|
+
// The mapping is native -> virtual.
|
|
367
|
+
const itemEventsMap = {
|
|
368
|
+
// mouseup too, as the press needs the item for needsUp():
|
|
369
|
+
mousedown: {
|
|
370
|
+
mousedown: 1,
|
|
371
|
+
mouseup: 1,
|
|
372
|
+
mousedrag: 1,
|
|
373
|
+
click: 1,
|
|
374
|
+
doubleclick: 1
|
|
375
|
+
},
|
|
376
|
+
mouseup: {
|
|
377
|
+
mouseup: 1,
|
|
378
|
+
mousedrag: 1,
|
|
379
|
+
click: 1,
|
|
380
|
+
doubleclick: 1
|
|
381
|
+
},
|
|
382
|
+
mousemove: {
|
|
383
|
+
mousedrag: 1,
|
|
384
|
+
mousemove: 1,
|
|
385
|
+
mouseenter: 1,
|
|
386
|
+
mouseleave: 1
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
// Declare the item events of views, which come from Item, and the listeners
|
|
390
|
+
// for the DOM's events, once, with the first view. Install the ones that all
|
|
391
|
+
// views share with the first one that handles input:
|
|
392
|
+
export function installEvents(hasInput) {
|
|
393
|
+
if (!isInstalled) {
|
|
394
|
+
isInstalled = true;
|
|
395
|
+
defineEvents(View, Object.fromEntries(Item._itemHandlers.map(name => [name, {}])));
|
|
396
|
+
// Pointer events cover mice, touches and pens alike. They are installed
|
|
397
|
+
// on the elements of the views, as defined by viewEvents, and only the
|
|
398
|
+
// primary pointer is handled: the mouse, a pen, or the first touch.
|
|
399
|
+
viewEvents = {
|
|
400
|
+
'pointerdown'(event) {
|
|
401
|
+
if (event.isPrimary && !View._focused?._input.dragging) {
|
|
402
|
+
// Get the view from the event, and store a reference to the view
|
|
403
|
+
// that should receive keyboard input.
|
|
404
|
+
const view = (View._focused = getView(event));
|
|
405
|
+
view._input.dragging = true;
|
|
406
|
+
// Capture the pointer, to receive its moves and the end of the
|
|
407
|
+
// drag outside of the view too. Events that scripts dispatch
|
|
408
|
+
// have no pointer to capture:
|
|
409
|
+
if (event.isTrusted) {
|
|
410
|
+
view._element.setPointerCapture(event.pointerId);
|
|
411
|
+
}
|
|
412
|
+
view._input.handleMouseEvent('mousedown', event);
|
|
413
|
+
view._input.isPrevented = event.defaultPrevented;
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
'pointermove'(event) {
|
|
417
|
+
if (event.isPrimary) {
|
|
418
|
+
const view = getView(event);
|
|
419
|
+
if (View._focused?._input.dragging) {
|
|
420
|
+
View._focused._input.handleMouseEvent('mousemove', event);
|
|
421
|
+
}
|
|
422
|
+
else if (!event.buttons || view === View._focused) {
|
|
423
|
+
// Presses that started elsewhere don't switch views as they
|
|
424
|
+
// move over this one.
|
|
425
|
+
if (view !== View._focused) {
|
|
426
|
+
// Temporarily focus this view without making it sticky,
|
|
427
|
+
// so Key events are handled too during the mouse over.
|
|
428
|
+
prevFocus ??= View._focused;
|
|
429
|
+
View._focused = tempFocus = view;
|
|
430
|
+
}
|
|
431
|
+
view._input.handleMouseEvent('mousemove', event);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
'pointerleave'(event) {
|
|
436
|
+
if (event.isPrimary && !View._focused?._input.dragging) {
|
|
437
|
+
// When the pointer leaves the view, handle one last move, to
|
|
438
|
+
// give items the chance to receive a mouseleave, etc. Touches
|
|
439
|
+
// leave by ending, where they were last:
|
|
440
|
+
const view = getView(event);
|
|
441
|
+
view._input.handleMouseEvent('mousemove', event, event.pointerType === 'touch' ? view._input.lastPoint : undefined);
|
|
442
|
+
if (tempFocus === view) {
|
|
443
|
+
// Clear temporary focus again and switch back to previous
|
|
444
|
+
// focus but only if it is still valid (still in the DOM).
|
|
445
|
+
View._focused = prevFocus?.isInserted() ? prevFocus : null;
|
|
446
|
+
prevFocus = null;
|
|
447
|
+
updateFocus();
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
'pointerup pointercancel'(event) {
|
|
452
|
+
const view = View._focused;
|
|
453
|
+
if (event.isPrimary && view?._input.dragging) {
|
|
454
|
+
// Pointers that are cancelled, such as touches that browsers
|
|
455
|
+
// take over to scroll the page, report no position:
|
|
456
|
+
view._input.handleMouseEvent('mouseup', event, event.type === 'pointercancel' ? view._input.lastPoint : undefined);
|
|
457
|
+
view._input.dragging = false;
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
// Browsers decide whether a touch scrolls the page before they send
|
|
461
|
+
// its pointer events, unless its touchstart is prevented, which
|
|
462
|
+
// comes after the pointerdown. Do so where the press was (#1930):
|
|
463
|
+
'touchstart'(event) {
|
|
464
|
+
if (View._focused?._input.isPrevented && event.cancelable) {
|
|
465
|
+
event.preventDefault();
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (hasInput && !hasInputEvents) {
|
|
471
|
+
hasInputEvents = true;
|
|
472
|
+
installKeyEvents();
|
|
473
|
+
addEvents(getDocument(), {
|
|
474
|
+
scroll: updateFocus
|
|
475
|
+
});
|
|
476
|
+
addEvents(getWindow(), {
|
|
477
|
+
load: updateFocus
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function getView(event) {
|
|
482
|
+
// The events are installed on the elements of views, see viewEvents:
|
|
483
|
+
return viewsByElement.get(event.currentTarget);
|
|
484
|
+
}
|
|
485
|
+
export function updateFocus() {
|
|
486
|
+
let view = View._focused;
|
|
487
|
+
if (!view || !view.isVisible()) {
|
|
488
|
+
// Find the first visible view that handles input
|
|
489
|
+
for (view of views) {
|
|
490
|
+
if (view._hasInput && view.isVisible()) {
|
|
491
|
+
View._focused = tempFocus = view;
|
|
492
|
+
break;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
// Stands in for the DOM event in View#dispatchMouseEvent() and
|
|
498
|
+
// View#dispatchKeyEvent(), with what the handling reads from it. Hosts can
|
|
499
|
+
// pass the state of the modifier keys, see Key.modifiers:
|
|
500
|
+
export function createEvent(type, options, view) {
|
|
501
|
+
if (options.modifiers) {
|
|
502
|
+
Object.assign(Key.modifiers, options.modifiers);
|
|
503
|
+
}
|
|
504
|
+
// The main button is down from the press to the release, as the DOM's
|
|
505
|
+
// pointer events report it:
|
|
506
|
+
const buttons = (options.buttons ?? (type === 'mousedown' || type === 'mousemove' && view._input.dragging
|
|
507
|
+
? 1
|
|
508
|
+
: 0));
|
|
509
|
+
return {
|
|
510
|
+
type,
|
|
511
|
+
timeStamp: options.time != null ? options.time * 1000 : Date.now(),
|
|
512
|
+
button: options.button || 0,
|
|
513
|
+
buttons,
|
|
514
|
+
pointerType: options.pointerType || 'mouse',
|
|
515
|
+
pressure: options.pressure ?? (buttons ? 0.5 : 0),
|
|
516
|
+
cancelable: true,
|
|
517
|
+
defaultPrevented: false,
|
|
518
|
+
preventDefault() {
|
|
519
|
+
this.defaultPrevented = true;
|
|
520
|
+
},
|
|
521
|
+
stopPropagation() { }
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
// Clears the focus that the views share, see View._resetState():
|
|
525
|
+
export function resetFocus() {
|
|
526
|
+
View._focused = prevFocus = tempFocus = null;
|
|
527
|
+
}
|