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,439 @@
|
|
|
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 { GEOMETRIC_EPSILON, Group, Path, PathItem, Rectangle, getTextWidth, indentRoom, measureLine, placeLine } from "../internal.js";
|
|
13
|
+
// The precisions that lines are balanced and vertically aligned to:
|
|
14
|
+
const balancePrecision = 0.5;
|
|
15
|
+
const alignPrecision = 0.01;
|
|
16
|
+
// The layout of the story's part that fits the area, see measureLine(): its
|
|
17
|
+
// lines, broken between words to fit the area's width where each sits,
|
|
18
|
+
// filling the regions of its rows and columns one after the other, each
|
|
19
|
+
// line moving down by its own line height and the space between
|
|
20
|
+
// paragraphs, aligned by its paragraph's justification and indents, and
|
|
21
|
+
// evened out by its lineWrap:
|
|
22
|
+
export function layOutArea(areaText) {
|
|
23
|
+
const story = areaText._story;
|
|
24
|
+
const content = story._content;
|
|
25
|
+
const regions = getRegions(areaText);
|
|
26
|
+
const wraps = getTextWraps(areaText);
|
|
27
|
+
// How far each region's first line moves down, to align its lines
|
|
28
|
+
// vertically:
|
|
29
|
+
const offsets = regions.map(() => 0);
|
|
30
|
+
let state;
|
|
31
|
+
// Lays out the paragraph from `state`, each line's room narrowed by
|
|
32
|
+
// `getCut(index)` to break it, see #_breakLine():
|
|
33
|
+
const lay = (getCut) => {
|
|
34
|
+
let { pos, region, y } = state;
|
|
35
|
+
const paragraph = story._getParagraph(pos);
|
|
36
|
+
const { style } = paragraph;
|
|
37
|
+
// The space between paragraphs, once, unless at the top:
|
|
38
|
+
let space = pos === paragraph.start && y !== null
|
|
39
|
+
? Math.max(state.spaceAfter, style.spaceBefore)
|
|
40
|
+
: 0;
|
|
41
|
+
const result = [];
|
|
42
|
+
let isComplete = false;
|
|
43
|
+
while (regions[region]) {
|
|
44
|
+
const bounds = regions[region];
|
|
45
|
+
// The extent of what comes next, to find room:
|
|
46
|
+
const next = measureLine(areaText, pos, Math.min(pos + 1, paragraph.end), style.direction);
|
|
47
|
+
const baseline = y === null
|
|
48
|
+
? bounds.top + offsets[region] + next.ascent
|
|
49
|
+
: y + next.lineHeight + space;
|
|
50
|
+
// Nothing without a height fits anywhere:
|
|
51
|
+
if (!next.lineHeight || next.lineHeight < 0)
|
|
52
|
+
break;
|
|
53
|
+
if (baseline + next.descent > bounds.bottom) {
|
|
54
|
+
// The region is full: on to the next one.
|
|
55
|
+
region++;
|
|
56
|
+
y = null;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
// Fill the spans at areaText height in reading order, each as far as it
|
|
60
|
+
// goes, then go on further down:
|
|
61
|
+
const spans = getSpans(areaText, bounds, baseline, next, wraps);
|
|
62
|
+
if (style.direction === 'rtl') {
|
|
63
|
+
spans.reverse();
|
|
64
|
+
}
|
|
65
|
+
for (let i = 0, l = spans.length; i < l && !isComplete; i++) {
|
|
66
|
+
const span = spans[i];
|
|
67
|
+
const line = breakLine(areaText, pos, paragraph, pos === paragraph.start, span, getCut?.(result.length) ?? 0,
|
|
68
|
+
// A word too wide for any line takes one of its own where
|
|
69
|
+
// nothing narrows the region:
|
|
70
|
+
span[1] - span[0] >= bounds.width - GEOMETRIC_EPSILON);
|
|
71
|
+
if (line) {
|
|
72
|
+
line.y = baseline;
|
|
73
|
+
line.region = region;
|
|
74
|
+
result.push(line);
|
|
75
|
+
pos = line.end;
|
|
76
|
+
isComplete = pos === paragraph.end;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
y = baseline;
|
|
80
|
+
space = 0;
|
|
81
|
+
if (isComplete)
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
lines: result,
|
|
86
|
+
paragraph: style,
|
|
87
|
+
isComplete,
|
|
88
|
+
state: {
|
|
89
|
+
pos,
|
|
90
|
+
region,
|
|
91
|
+
y,
|
|
92
|
+
spaceAfter: style.spaceAfter
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
// Finds where `isAbove(value)` turns true for values from 0 to `high`,
|
|
97
|
+
// as the values on either side of it, to `precision`:
|
|
98
|
+
const search = (high, precision, isAbove) => {
|
|
99
|
+
let low = 0;
|
|
100
|
+
while (high - low > precision) {
|
|
101
|
+
const value = (low + high) / 2;
|
|
102
|
+
if (isAbove(value)) {
|
|
103
|
+
high = value;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
low = value;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [low, high];
|
|
110
|
+
};
|
|
111
|
+
// Narrower lines change nothing as long as they keep the paragraph
|
|
112
|
+
// whole, and its number of lines:
|
|
113
|
+
const keeps = (attempt, count) => attempt.isComplete && attempt.lines.length === count;
|
|
114
|
+
// Narrows the lines from index `from` on as far as they keep the
|
|
115
|
+
// paragraph, which evens them out:
|
|
116
|
+
const balance = (count, from) => {
|
|
117
|
+
const cutFrom = (cut) => (index) => index >= from ? cut : 0;
|
|
118
|
+
const widest = regions.reduce((width, bounds) => Math.max(width, bounds.width), 0);
|
|
119
|
+
const [cut] = search(widest, balancePrecision, cut => !keeps(lay(cutFrom(cut)), count));
|
|
120
|
+
return cut > 0 && lay(cutFrom(cut));
|
|
121
|
+
};
|
|
122
|
+
// Lays out all the paragraphs, one after the other, from where the text
|
|
123
|
+
// starts:
|
|
124
|
+
const layAll = () => {
|
|
125
|
+
const layout = [];
|
|
126
|
+
let match;
|
|
127
|
+
state = {
|
|
128
|
+
pos: areaText._getStart(),
|
|
129
|
+
region: 0,
|
|
130
|
+
y: null,
|
|
131
|
+
spaceAfter: 0
|
|
132
|
+
};
|
|
133
|
+
do {
|
|
134
|
+
let result = lay();
|
|
135
|
+
const { lines } = result;
|
|
136
|
+
const count = lines.length;
|
|
137
|
+
const wrap = result.paragraph.lineWrap;
|
|
138
|
+
if (result.isComplete && count > 1) {
|
|
139
|
+
if (wrap === 'balance') {
|
|
140
|
+
result = balance(count, 0) || result;
|
|
141
|
+
}
|
|
142
|
+
else if (wrap === 'paragraph' &&
|
|
143
|
+
lines[count - 1].width < lines[count - 2].width / 3) {
|
|
144
|
+
// Balance the last four lines, if the last one is short:
|
|
145
|
+
result = balance(count, Math.max(0, count - 4)) || result;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
layout.push(...result.lines);
|
|
149
|
+
state = result.state;
|
|
150
|
+
// On to the next paragraph, after its line break:
|
|
151
|
+
match = (result.isComplete &&
|
|
152
|
+
/^(\r\n|\n|\r)/.exec(content.slice(state.pos)));
|
|
153
|
+
if (match) {
|
|
154
|
+
state.pos += match[0].length;
|
|
155
|
+
}
|
|
156
|
+
} while (match);
|
|
157
|
+
return layout;
|
|
158
|
+
};
|
|
159
|
+
// The region's last line, and the room below it:
|
|
160
|
+
const getLast = (layout, region) => {
|
|
161
|
+
for (let i = layout.length - 1; i >= 0; i--) {
|
|
162
|
+
const line = layout[i];
|
|
163
|
+
if (line.region === region) {
|
|
164
|
+
return {
|
|
165
|
+
line,
|
|
166
|
+
free: regions[region].bottom - line.y - line.descent
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return null;
|
|
171
|
+
};
|
|
172
|
+
let layout = layAll();
|
|
173
|
+
const align = areaText._verticalAlign;
|
|
174
|
+
if (align !== 'top') {
|
|
175
|
+
// Align each region's lines by laying them out again from lower down,
|
|
176
|
+
// as far as they keep what the region shows, and, to center them, as
|
|
177
|
+
// much room above them as below:
|
|
178
|
+
for (let r = 0, l = regions.length; r < l; r++) {
|
|
179
|
+
const last = getLast(layout, r);
|
|
180
|
+
if (last && last.free > 0) {
|
|
181
|
+
const { end } = last.line;
|
|
182
|
+
// The room below the lines laid out from `offset` down, beyond
|
|
183
|
+
// what's wanted, or null if the region then shows less:
|
|
184
|
+
const getExcess = (offset) => {
|
|
185
|
+
offsets[r] = offset;
|
|
186
|
+
const moved = getLast(layAll(), r);
|
|
187
|
+
return moved?.line.end === end
|
|
188
|
+
? moved.free - (align === 'center' ? offset : 0)
|
|
189
|
+
: null;
|
|
190
|
+
};
|
|
191
|
+
// A rectangle aligns in one step, other shapes by searching:
|
|
192
|
+
const excess = getExcess(align === 'center' ? last.free / 2 : last.free);
|
|
193
|
+
if (excess === null || Math.abs(excess) > alignPrecision) {
|
|
194
|
+
offsets[r] = search(last.free, alignPrecision, offset => {
|
|
195
|
+
const excess = getExcess(offset);
|
|
196
|
+
return excess === null || excess < 0;
|
|
197
|
+
})[0];
|
|
198
|
+
}
|
|
199
|
+
layout = layAll();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
areaText._visibleEnd = state.pos;
|
|
204
|
+
return layout;
|
|
205
|
+
}
|
|
206
|
+
// The regions that the area is divided into by its inset, rows and
|
|
207
|
+
// columns, in the order the text fills them:
|
|
208
|
+
function getRegions(areaText) {
|
|
209
|
+
const path = areaText.textPath;
|
|
210
|
+
const regions = [];
|
|
211
|
+
if (path) {
|
|
212
|
+
const bounds = path.bounds.expand(-2 * areaText._inset);
|
|
213
|
+
const gutter = areaText._gutter;
|
|
214
|
+
const rows = Math.max(1, areaText._rows);
|
|
215
|
+
const columns = Math.max(1, areaText._columns);
|
|
216
|
+
const width = (bounds.width - gutter * (columns - 1)) / columns;
|
|
217
|
+
const height = (bounds.height - gutter * (rows - 1)) / rows;
|
|
218
|
+
for (let row = 0; row < rows; row++) {
|
|
219
|
+
for (let column = 0; column < columns; column++) {
|
|
220
|
+
regions.push(new Rectangle(bounds.x + column * (width + gutter), bounds.y + row * (height + gutter), width, height));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return regions;
|
|
225
|
+
}
|
|
226
|
+
// The spans of the line at `baseline` in the region, from left to right:
|
|
227
|
+
// where the area holds all of the line's band, from its ascent to its
|
|
228
|
+
// descent, without the text wraps, or only within them when inverted:
|
|
229
|
+
function getSpans(areaText, region, baseline, line, wraps) {
|
|
230
|
+
const top = baseline - line.ascent;
|
|
231
|
+
const bottom = baseline + line.descent;
|
|
232
|
+
const middle = (top + bottom) / 2;
|
|
233
|
+
const unite = (stretches1, stretches2) => {
|
|
234
|
+
const all = stretches1.concat(stretches2).sort((a, b) => a[0] - b[0]);
|
|
235
|
+
const result = [];
|
|
236
|
+
for (let i = 0, l = all.length; i < l; i++) {
|
|
237
|
+
const last = result.at(-1);
|
|
238
|
+
const stretch = all[i];
|
|
239
|
+
if (last && stretch[0] <= last[1]) {
|
|
240
|
+
last[1] = Math.max(last[1], stretch[1]);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
result.push(stretch.slice());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return result;
|
|
247
|
+
};
|
|
248
|
+
const intersect = (stretches1, stretches2) => {
|
|
249
|
+
const result = [];
|
|
250
|
+
for (let i = 0, l = stretches1.length; i < l; i++) {
|
|
251
|
+
for (let j = 0, m = stretches2.length; j < m; j++) {
|
|
252
|
+
const left = Math.max(stretches1[i][0], stretches2[j][0]);
|
|
253
|
+
const right = Math.min(stretches1[i][1], stretches2[j][1]);
|
|
254
|
+
if (right > left) {
|
|
255
|
+
result.push([left, right]);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return result;
|
|
260
|
+
};
|
|
261
|
+
const subtract = (stretches1, stretches2) => intersect(stretches1, stretches2.reduce(
|
|
262
|
+
// What's outside the stretches, from left to right:
|
|
263
|
+
(outside, stretch) => {
|
|
264
|
+
const last = outside.pop();
|
|
265
|
+
return outside.concat([
|
|
266
|
+
[last[0], stretch[0]],
|
|
267
|
+
[stretch[1], last[1]]
|
|
268
|
+
]);
|
|
269
|
+
}, [[-Infinity, Infinity]]));
|
|
270
|
+
// The stretches inside the paths along the horizontal at `y`, pairing the
|
|
271
|
+
// crossings of each:
|
|
272
|
+
const inside = (paths, y) => {
|
|
273
|
+
const stretches = [];
|
|
274
|
+
for (let i = 0, l = paths.length; i < l; i++) {
|
|
275
|
+
const path = paths[i];
|
|
276
|
+
const { bounds } = path;
|
|
277
|
+
const xs = path
|
|
278
|
+
.getIntersections(Path.line({
|
|
279
|
+
from: [bounds.left - 1, y],
|
|
280
|
+
to: [bounds.right + 1, y],
|
|
281
|
+
insert: false
|
|
282
|
+
}))
|
|
283
|
+
.map(location => location.point.x)
|
|
284
|
+
.sort((a, b) => a - b);
|
|
285
|
+
for (let j = 0; j + 1 < xs.length; j += 2) {
|
|
286
|
+
stretches.push([xs[j], xs[j + 1]]);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return unite(stretches, []);
|
|
290
|
+
};
|
|
291
|
+
// The area must hold all of the band:
|
|
292
|
+
let spans = [top, middle, bottom].reduce(
|
|
293
|
+
// Only area texts with paths lay out:
|
|
294
|
+
(spans, y) => intersect(spans, inside([areaText.textPath], y)), [[region.left, region.right]]);
|
|
295
|
+
for (let i = 0, l = wraps.length; i < l; i++) {
|
|
296
|
+
// A text wrap keeps its offset all around, so look at it from as far
|
|
297
|
+
// above and below the band, and widen or narrow it as much:
|
|
298
|
+
const { offset, invert, paths } = wraps[i];
|
|
299
|
+
const ys = [top - offset, top, middle, bottom, bottom + offset];
|
|
300
|
+
const covered = ys
|
|
301
|
+
.reduce((covered, y) => {
|
|
302
|
+
const stretches = inside(paths, y);
|
|
303
|
+
return covered
|
|
304
|
+
? invert
|
|
305
|
+
? intersect(covered, stretches)
|
|
306
|
+
: unite(covered, stretches)
|
|
307
|
+
: stretches;
|
|
308
|
+
}, null)
|
|
309
|
+
.map((stretch) => invert
|
|
310
|
+
? [stretch[0] + offset, stretch[1] - offset]
|
|
311
|
+
: [stretch[0] - offset, stretch[1] + offset]);
|
|
312
|
+
spans = invert
|
|
313
|
+
? intersect(spans, covered)
|
|
314
|
+
: subtract(spans, unite(covered, []));
|
|
315
|
+
}
|
|
316
|
+
return spans;
|
|
317
|
+
}
|
|
318
|
+
// The items above the text in its layer that push it aside, see
|
|
319
|
+
// Item#textWrap, each with its options and its outline as paths in the
|
|
320
|
+
// text's coordinates: a path's own, a group's children's, or a clip
|
|
321
|
+
// group's clip path, and the bounds of anything else:
|
|
322
|
+
function getTextWraps(areaText) {
|
|
323
|
+
const { layer } = areaText;
|
|
324
|
+
const items = layer?._textWrapItems;
|
|
325
|
+
// Texts scaled to nothing show nothing to wrap:
|
|
326
|
+
const toText = areaText._getGlobalMatrix(true).inverted();
|
|
327
|
+
const wraps = [];
|
|
328
|
+
const isShown = (item) => {
|
|
329
|
+
for (; item && item !== layer; item = item._parent) {
|
|
330
|
+
if (!item._visible)
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
return true;
|
|
334
|
+
};
|
|
335
|
+
const getOutline = (item, paths) => {
|
|
336
|
+
// The wraps are in the text's layer, below it:
|
|
337
|
+
const matrix = toText.appended(item._parent._getGlobalMatrix(true));
|
|
338
|
+
if (item instanceof PathItem) {
|
|
339
|
+
const path = item.clone({ insert: false, deep: true });
|
|
340
|
+
path.transform(matrix);
|
|
341
|
+
paths.push(path);
|
|
342
|
+
}
|
|
343
|
+
else if (item instanceof Group) {
|
|
344
|
+
const clipItem = item._getClipItem();
|
|
345
|
+
const children = clipItem ? [clipItem] : item._children;
|
|
346
|
+
for (let i = 0, l = children.length; i < l; i++) {
|
|
347
|
+
if (children[i]._visible) {
|
|
348
|
+
getOutline(children[i], paths);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
paths.push(Path.rectangle({
|
|
354
|
+
rectangle: item.getBounds(matrix),
|
|
355
|
+
insert: false
|
|
356
|
+
}));
|
|
357
|
+
}
|
|
358
|
+
return paths;
|
|
359
|
+
};
|
|
360
|
+
for (const id in items) {
|
|
361
|
+
const item = items[id];
|
|
362
|
+
if (item !== areaText && item.isAbove(areaText) && isShown(item)) {
|
|
363
|
+
wraps.push({ paths: getOutline(item, []), ...item._textWrap });
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return wraps;
|
|
367
|
+
}
|
|
368
|
+
// Breaks the line from `start` at the last word, or soft hyphen, that fits
|
|
369
|
+
// the room, and places it by the paragraph's justification and indents.
|
|
370
|
+
// Spaces at its end hang outside the room. If not even the first word
|
|
371
|
+
// fits, it takes the line alone if `canForce`, else there's no line:
|
|
372
|
+
function breakLine(areaText, start, paragraph, isFirst, room, cut, canForce) {
|
|
373
|
+
const content = areaText._story._content;
|
|
374
|
+
const { style } = paragraph;
|
|
375
|
+
const { direction } = style;
|
|
376
|
+
const indented = indentRoom(style, isFirst, room[0], room[1]);
|
|
377
|
+
// Soft hyphens are breaks, unless hyphenation is 'none':
|
|
378
|
+
const words = style.hyphenation === 'none'
|
|
379
|
+
? /\S+\s*|\s+/g
|
|
380
|
+
: /[^\s\u00ad]*\u00ad|\S+\s*|\s+/g;
|
|
381
|
+
const text = content.slice(start, paragraph.end);
|
|
382
|
+
const ends = [];
|
|
383
|
+
let match;
|
|
384
|
+
// The line up to `end` without its trailing spaces, with a hyphen where
|
|
385
|
+
// it ends at a soft hyphen, in the font of the letter before:
|
|
386
|
+
const measure = (end) => {
|
|
387
|
+
const line = measureLine(areaText, start, start + content.slice(start, end).replace(/\s+$/, '').length, direction);
|
|
388
|
+
if (content[end - 1] === '\u00ad') {
|
|
389
|
+
// The line holds the letter before the soft hyphen:
|
|
390
|
+
const last = line.pieces.at(-1);
|
|
391
|
+
const width = (getTextWidth(areaText.view, last.font, '-', last.tracking, direction) *
|
|
392
|
+
last.scale.x);
|
|
393
|
+
line.pieces.push({
|
|
394
|
+
...last,
|
|
395
|
+
content: '-',
|
|
396
|
+
start: end,
|
|
397
|
+
end,
|
|
398
|
+
x: last.x + last.width,
|
|
399
|
+
width
|
|
400
|
+
});
|
|
401
|
+
line.width += width;
|
|
402
|
+
}
|
|
403
|
+
return line;
|
|
404
|
+
};
|
|
405
|
+
while ((match = words.exec(text))) {
|
|
406
|
+
ends.push(start + match.index + match[0].length);
|
|
407
|
+
}
|
|
408
|
+
// Search for the last end that fits, as the lines only get wider: first
|
|
409
|
+
// by doubling steps, so nothing much longer than the line is measured,
|
|
410
|
+
// then by halving them between the last two:
|
|
411
|
+
const width = indented[1] - indented[0] - cut;
|
|
412
|
+
const fits = (index) => measure(ends[index]).width <= width;
|
|
413
|
+
let low = -1;
|
|
414
|
+
let high = 0;
|
|
415
|
+
while (high < ends.length && fits(high)) {
|
|
416
|
+
low = high;
|
|
417
|
+
high = 2 * high + 1;
|
|
418
|
+
}
|
|
419
|
+
high = Math.min(high, ends.length);
|
|
420
|
+
while (high - low > 1) {
|
|
421
|
+
const middle = (low + high) >> 1;
|
|
422
|
+
if (fits(middle)) {
|
|
423
|
+
low = middle;
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
high = middle;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
let end = low >= 0 ? ends[low] : start;
|
|
430
|
+
if (end === start && ends.length) {
|
|
431
|
+
if (!canForce)
|
|
432
|
+
return null;
|
|
433
|
+
end = ends[0];
|
|
434
|
+
}
|
|
435
|
+
const line = measure(end);
|
|
436
|
+
placeLine(areaText, line, style, end === paragraph.end, indented);
|
|
437
|
+
line.end = end;
|
|
438
|
+
return line;
|
|
439
|
+
}
|