paper 0.12.19 → 0.13.0

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +250 -0
  2. package/README.md +34 -27
  3. package/dist/docs/assets/js/paper.js +791 -366
  4. package/dist/docs/classes/Color.html +63 -47
  5. package/dist/docs/classes/CompoundPath.html +162 -59
  6. package/dist/docs/classes/Curve.html +9 -7
  7. package/dist/docs/classes/CurveLocation.html +1 -1
  8. package/dist/docs/classes/Event.html +1 -1
  9. package/dist/docs/classes/Gradient.html +1 -1
  10. package/dist/docs/classes/GradientStop.html +1 -1
  11. package/dist/docs/classes/Group.html +63 -24
  12. package/dist/docs/classes/HitResult.html +1 -1
  13. package/dist/docs/classes/Item.html +63 -24
  14. package/dist/docs/classes/Key.html +1 -1
  15. package/dist/docs/classes/KeyEvent.html +1 -1
  16. package/dist/docs/classes/Layer.html +63 -24
  17. package/dist/docs/classes/Matrix.html +1 -1
  18. package/dist/docs/classes/MouseEvent.html +1 -1
  19. package/dist/docs/classes/PaperScope.html +87 -1
  20. package/dist/docs/classes/PaperScript.html +1 -1
  21. package/dist/docs/classes/Path.html +174 -68
  22. package/dist/docs/classes/PathItem.html +280 -177
  23. package/dist/docs/classes/Point.html +143 -21
  24. package/dist/docs/classes/PointText.html +94 -24
  25. package/dist/docs/classes/Project.html +14 -8
  26. package/dist/docs/classes/Raster.html +93 -35
  27. package/dist/docs/classes/Rectangle.html +12 -11
  28. package/dist/docs/classes/Segment.html +1 -1
  29. package/dist/docs/classes/Shape.html +63 -24
  30. package/dist/docs/classes/Size.html +81 -21
  31. package/dist/docs/classes/Style.html +34 -2
  32. package/dist/docs/classes/SymbolDefinition.html +1 -1
  33. package/dist/docs/classes/SymbolItem.html +64 -25
  34. package/dist/docs/classes/TextItem.html +94 -24
  35. package/dist/docs/classes/Tool.html +2 -1
  36. package/dist/docs/classes/ToolEvent.html +27 -1
  37. package/dist/docs/classes/Tween.html +1 -1
  38. package/dist/docs/classes/View.html +203 -10
  39. package/dist/docs/classes/global.html +1 -1
  40. package/dist/docs/classes/index.html +2 -2
  41. package/dist/docs/index.html +1 -1
  42. package/dist/node/canvas.js +10 -8
  43. package/dist/node/self.js +13 -4
  44. package/dist/paper-core.js +772 -355
  45. package/dist/paper-core.min.js +3 -3
  46. package/dist/paper-full.js +791 -366
  47. package/dist/paper-full.min.js +3 -3
  48. package/dist/paper.d.ts +324 -73
  49. package/examples/Rasters/Smoothing.html +1 -1
  50. package/package.json +5 -11
  51. package/dist/node/xml.js +0 -40
package/dist/paper.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Paper.js v0.12.19 - The Swiss Army Knife of Vector Graphics Scripting.
2
+ * Paper.js v0.13.0 - The Swiss Army Knife of Vector Graphics Scripting.
3
3
  * http://paperjs.org/
4
4
  *
5
5
  * Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * All rights reserved.
11
11
  *
12
- * Date: Sun Oct 18 13:05:31 2026 +0200
12
+ * Date: Mon Oct 19 15:31:53 2026 +0200
13
13
  *
14
14
  * This is an auto-generated type definition.
15
15
  */
@@ -262,7 +262,7 @@ declare namespace paper {
262
262
  static random(): Color
263
263
 
264
264
  /**
265
- * Returns the addition of the supplied value to both coordinates of
265
+ * Returns the addition of the supplied value to all components of
266
266
  * the color as a new color.
267
267
  * The object itself is not modified!
268
268
  *
@@ -285,7 +285,7 @@ declare namespace paper {
285
285
  add(color: Color): Color
286
286
 
287
287
  /**
288
- * Returns the subtraction of the supplied value to both coordinates of
288
+ * Returns the subtraction of the supplied value to all components of
289
289
  * the color as a new color.
290
290
  * The object itself is not modified!
291
291
  *
@@ -308,7 +308,7 @@ declare namespace paper {
308
308
  subtract(color: Color): Color
309
309
 
310
310
  /**
311
- * Returns the multiplication of the supplied value to both coordinates
311
+ * Returns the multiplication of the supplied value to all components
312
312
  * of the color as a new color.
313
313
  * The object itself is not modified!
314
314
  *
@@ -331,7 +331,7 @@ declare namespace paper {
331
331
  multiply(color: Color): Color
332
332
 
333
333
  /**
334
- * Returns the division of the supplied value to both coordinates of
334
+ * Returns the division of the supplied value to all components of
335
335
  * the color as a new color.
336
336
  * The object itself is not modified!
337
337
  *
@@ -551,7 +551,7 @@ declare namespace paper {
551
551
  /**
552
552
  * The bounding rectangle of the curve including handles.
553
553
  */
554
- handleBounds: Rectangle
554
+ readonly handleBounds: Rectangle
555
555
 
556
556
 
557
557
  /**
@@ -761,7 +761,8 @@ declare namespace paper {
761
761
  isVertical(): boolean
762
762
 
763
763
  /**
764
- * Calculates the curve location at the specified offset on the curve.
764
+ * Calculates the curve location at the specified offset on the curve, or
765
+ * `null` if the offset exceeds the length of the curve.
765
766
  *
766
767
  * @param offset - the offset on the curve
767
768
  *
@@ -771,7 +772,7 @@ declare namespace paper {
771
772
 
772
773
  /**
773
774
  * Calculates the curve location at the specified curve-time parameter on
774
- * the curve.
775
+ * the curve, or `null` if the parameter lies outside of `0..1`.
775
776
  *
776
777
  * @param time - the curve-time parameter on the curve
777
778
  *
@@ -791,7 +792,8 @@ declare namespace paper {
791
792
  * @param start - the curve-time in relation to which the offset is
792
793
  * determined
793
794
  *
794
- * @return the curve-time parameter at the specified location
795
+ * @return the curve-time parameter at the specified location, or
796
+ * `null` if the offset exceeds the length of the curve
795
797
  */
796
798
  getTimeAt(offset: number, start?: number): number
797
799
 
@@ -824,7 +826,7 @@ declare namespace paper {
824
826
  *
825
827
  * @return the curve location of the specified point
826
828
  */
827
- getLocationOf(point: PointLike): CurveLocation
829
+ getLocationOf(point: PointLike): CurveLocation | null
828
830
 
829
831
  /**
830
832
  * Returns the length of the path from its beginning up to up to the
@@ -834,7 +836,7 @@ declare namespace paper {
834
836
  *
835
837
  * @return the length of the path up to the specified point
836
838
  */
837
- getOffsetOf(point: PointLike): number
839
+ getOffsetOf(point: PointLike): number | null
838
840
 
839
841
  /**
840
842
  * Returns the curve-time parameter of the specified point if it lies on the
@@ -846,7 +848,7 @@ declare namespace paper {
846
848
  *
847
849
  * @return the curve-time parameter of the specified point
848
850
  */
849
- getTimeOf(point: PointLike): number
851
+ getTimeOf(point: PointLike): number | null
850
852
 
851
853
  /**
852
854
  * Returns the nearest location on the curve to the specified point.
@@ -1369,6 +1371,10 @@ declare namespace paper {
1369
1371
 
1370
1372
  /**
1371
1373
  * The path style of the item.
1374
+ *
1375
+ * Styles set on a {@link Group} or {@link Layer} are applied to the
1376
+ * children that it contains at that moment. Items added to it later do not
1377
+ * receive them.
1372
1378
  */
1373
1379
  style: Style
1374
1380
 
@@ -1397,6 +1403,14 @@ declare namespace paper {
1397
1403
  */
1398
1404
  opacity: number
1399
1405
 
1406
+ /**
1407
+ * Specifies whether the item functions as a guide. When set to `true`, the
1408
+ * item is drawn as usual, but left out of hit-tests and mouse
1409
+ * interactions. Hit-tests only find guides when `options.guides` is set,
1410
+ * and then only them, see {@link #hitTest}.
1411
+ */
1412
+ guide: boolean
1413
+
1400
1414
  /**
1401
1415
  * Specifies whether the item is selected. This will also return `true` for
1402
1416
  * {@link Group} items if they are partially selected, e.g. groups
@@ -1539,6 +1553,11 @@ declare namespace paper {
1539
1553
  * The children items contained within this item. Items that define a
1540
1554
  * {@link #name} can also be accessed by name.
1541
1555
  *
1556
+ * Only {@link Group}, {@link Layer} and {@link CompoundPath} items can have
1557
+ * children. On all other items, such as {@link Path}, {@link Shape},
1558
+ * {@link Raster}, {@link SymbolItem} and {@link PointText}, `children` is
1559
+ * `undefined`.
1560
+ *
1542
1561
  * <b>Please note:</b> The children array should not be modified directly
1543
1562
  * using array functions. To remove single items from the children list, use
1544
1563
  * {@link Item#remove}, to remove all items from the children list, use
@@ -1854,11 +1873,13 @@ declare namespace paper {
1854
1873
  * Group} or {@link Layer}) at the location of the specified point,
1855
1874
  * returning the first found hit.
1856
1875
  *
1857
- * The options object allows you to control the specifics of the hit-
1858
- * test and may contain a combination of the following values:
1876
+ * The options object allows you to control the specifics of the hit-test.
1877
+ * Without options, `fill`, `stroke` and `segments` are hit-tested. As soon
1878
+ * as an options object is passed, only the hit-tests that it sets to `true`
1879
+ * are performed. It may contain a combination of the following values:
1859
1880
  *
1860
1881
  * @option [options.tolerance={@link PaperScope#settings}.hitTolerance]
1861
- * {Number} the tolerance of the hit-test
1882
+ * {Number} the tolerance of the hit-test, in project coordinates
1862
1883
  * @option options.class {Function} only hit-test against a specific item
1863
1884
  * class, or any of its sub-classes, by providing the constructor
1864
1885
  * function against which an `instanceof` check is performed:
@@ -1867,11 +1888,11 @@ declare namespace paper {
1867
1888
  * @option options.match {Function} a match function to be called for each
1868
1889
  * found hit result: Return `true` to return the result, `false` to keep
1869
1890
  * searching
1870
- * @option [options.fill=true] {Boolean} hit-test the fill of items
1871
- * @option [options.stroke=true] {Boolean} hit-test the stroke of path
1872
- * items, taking into account the setting of stroke color and width
1873
- * @option [options.segments=true] {Boolean} hit-test for {@link
1874
- * Segment#point} of {@link Path} items
1891
+ * @option options.fill {Boolean} hit-test the fill of items
1892
+ * @option options.stroke {Boolean} hit-test the stroke of path items,
1893
+ * taking into account the setting of stroke color and width
1894
+ * @option options.segments {Boolean} hit-test for {@link Segment#point} of
1895
+ * {@link Path} items
1875
1896
  * @option options.curves {Boolean} hit-test the curves of path items,
1876
1897
  * without taking the stroke color or width into account
1877
1898
  * @option options.handles {Boolean} hit-test for the handles ({@link
@@ -1884,7 +1905,7 @@ declare namespace paper {
1884
1905
  * the bounding rectangle of items ({@link Item#bounds})
1885
1906
  * @option options.bounds {Boolean} hit-test the corners and side-centers of
1886
1907
  * the bounding rectangle of items ({@link Item#bounds})
1887
- * @option options.guides {Boolean} hit-test items that have {@link
1908
+ * @option options.guides {Boolean} only hit-test items that have {@link
1888
1909
  * Item#guide} set to `true`
1889
1910
  * @option options.selected {Boolean} only hit selected items
1890
1911
  *
@@ -1984,7 +2005,9 @@ declare namespace paper {
1984
2005
  *
1985
2006
  * @param options - the criteria to match against
1986
2007
  *
1987
- * @return the list of matching descendant items
2008
+ * @return the list of matching descendant items, in their
2009
+ * stacking order from bottom to top, with each item listed before its
2010
+ * own descendants
1988
2011
  */
1989
2012
  getItems(options: object | Function): Item[]
1990
2013
 
@@ -2054,6 +2077,12 @@ declare namespace paper {
2054
2077
  * @option [options.embedImages=true] {Boolean} whether raster images should
2055
2078
  * be embedded as base64 data inlined in the xlink:href attribute, or
2056
2079
  * kept as a link to their external URL.
2080
+ * @option [options.reuseImages=false] {Boolean} whether raster images with
2081
+ * the same content should only be exported once into the `<defs>`
2082
+ * element, and placed through `<use>` elements referencing it
2083
+ * @option [options.idPrefix=''] {String} a prefix for the ids generated
2084
+ * for definitions such as gradients, clip paths and symbols, to keep
2085
+ * them unique when several exported SVGs are placed in one document
2057
2086
  * @option [options.reduceAttributes=true] {Boolean} wether to only include
2058
2087
  * style attributes in the SVG output that differ from their parents,
2059
2088
  * or to always include them (much faster but leading to redundancies).
@@ -2070,8 +2099,15 @@ declare namespace paper {
2070
2099
  * the this item's children list. Note that the item is not cleared first.
2071
2100
  * You can call {@link Item#removeChildren} to do so.
2072
2101
  *
2102
+ * `<symbol>` elements are imported as {@link SymbolDefinition} items, and
2103
+ * the `<use>` elements that place them as {@link SymbolItem} items. The
2104
+ * styles that `<use>` elements inherit don't reach the symbols' content.
2105
+ *
2073
2106
  * @option [options.expandShapes=false] {Boolean} whether imported shape
2074
2107
  * items should be expanded to path items
2108
+ * @option [options.crossOrigin] {String} the {@link Raster#crossOrigin}
2109
+ * value of the rasters created for `<image>` elements, to load their
2110
+ * images with CORS
2075
2111
  * @option options.onLoad {Function} the callback function to call once the
2076
2112
  * SVG content is loaded from the given URL receiving two arguments: the
2077
2113
  * converted `item` and the original `svg` data as a string. Only
@@ -2212,9 +2248,12 @@ declare namespace paper {
2212
2248
  * the child-item is moved outside and the parent is erased. Otherwise, the
2213
2249
  * item itself is returned unmodified.
2214
2250
  *
2251
+ * @param options - the options passed on to {@link
2252
+ * Path#reduce(options)}
2253
+ *
2215
2254
  * @return the reduced item
2216
2255
  */
2217
- reduce(options: any): Item
2256
+ reduce(options?: object): Item
2218
2257
 
2219
2258
  /**
2220
2259
  * Removes the item and all its children from the project. The item is not
@@ -2306,7 +2345,8 @@ declare namespace paper {
2306
2345
 
2307
2346
  /**
2308
2347
  * Checks if this item is above the specified item in the stacking order
2309
- * of the project.
2348
+ * of the project. If one item is a descendant of the other, neither is
2349
+ * above the other and `false` is returned.
2310
2350
  *
2311
2351
  * @param item - the item to check against
2312
2352
  *
@@ -2316,7 +2356,8 @@ declare namespace paper {
2316
2356
 
2317
2357
  /**
2318
2358
  * Checks if the item is below the specified item in the stacking order of
2319
- * the project.
2359
+ * the project. If one item is a descendant of the other, neither is below
2360
+ * the other and `false` is returned.
2320
2361
  *
2321
2362
  * @param item - the item to check against
2322
2363
  *
@@ -2502,10 +2543,16 @@ declare namespace paper {
2502
2543
  localToParent(point: PointLike): Point
2503
2544
 
2504
2545
  /**
2505
- * Transform the item so that its {@link #bounds} fit within the specified
2506
- * rectangle, without changing its aspect ratio.
2546
+ * Transform the item so that its {@link #bounds} are centered in the
2547
+ * specified rectangle and fitted to it as described by `fit`.
2548
+ *
2549
+ * @param fit - how to fit the item, as in CSS's
2550
+ * `object-fit`: `'contain'` fits all of it within the rectangle, `'cover'`
2551
+ * makes it cover the whole rectangle, and `'fill'` stretches it to the
2552
+ * rectangle, changing its aspect ratio. The deprecated `true` and `false`
2553
+ * stand for `'cover'` and `'contain'`.
2507
2554
  */
2508
- fitBounds(rectangle: RectangleLike, fill?: boolean): void
2555
+ fitBounds(rectangle: RectangleLike, fit?: string | boolean): void
2509
2556
 
2510
2557
  /**
2511
2558
  * Attaches an event handler to the item.
@@ -2623,7 +2670,9 @@ declare namespace paper {
2623
2670
  * of the easing: {@values 'linear' 'easeInQuad' 'easeOutQuad'
2624
2671
  * 'easeInOutQuad' 'easeInCubic' 'easeOutCubic' 'easeInOutCubic'
2625
2672
  * 'easeInQuart' 'easeOutQuart' 'easeInOutQuart' 'easeInQuint'
2626
- * 'easeOutQuint' 'easeInOutQuint'}
2673
+ * 'easeOutQuint' 'easeInOutQuint' 'easeInSine' 'easeOutSine'
2674
+ * 'easeInOutSine' 'easeInExpo' 'easeOutExpo' 'easeInOutExpo'
2675
+ * 'easeInCirc' 'easeOutCirc' 'easeInOutCirc'}
2627
2676
  * @option [options.start=true] {Boolean} whether to start tweening automatically
2628
2677
  *
2629
2678
  * @param from - the state at the start of the tweening
@@ -3368,12 +3417,34 @@ declare namespace paper {
3368
3417
  */
3369
3418
  setup(element: HTMLCanvasElement | string | SizeLike): void
3370
3419
 
3420
+ /**
3421
+ * Creates a canvas of the given size, or reuses one that was released
3422
+ * internally.
3423
+ *
3424
+ * @param width - the width of the canvas
3425
+ * @param height - the height of the canvas
3426
+ *
3427
+ * @return the canvas
3428
+ */
3429
+ createCanvas(width: number, height: number): HTMLCanvasElement
3430
+
3371
3431
  /**
3372
3432
  * Activates this PaperScope, so all newly created items will be placed
3373
3433
  * in its active project.
3374
3434
  */
3375
3435
  activate(): void
3376
3436
 
3437
+ /**
3438
+ * Removes all projects, views and tools of this scope, along with their
3439
+ * installed event handlers.
3440
+ */
3441
+ clear(): void
3442
+
3443
+ /**
3444
+ * Clears this scope and removes it from the list of scopes.
3445
+ */
3446
+ remove(): void
3447
+
3377
3448
  /**
3378
3449
  * Retrieves a PaperScope object with the given scope id.
3379
3450
  */
@@ -3508,7 +3579,10 @@ declare namespace paper {
3508
3579
 
3509
3580
  /**
3510
3581
  * Creates a new path item from SVG path-data and places it at the top of
3511
- * the active layer.
3582
+ * the active layer. A path holds a single sub-path: further `M` commands
3583
+ * are ignored, and the commands that follow them continue the same path.
3584
+ * Use {@link CompoundPath} or {@link PathItem.create} to create
3585
+ * items with multiple sub-paths.
3512
3586
  *
3513
3587
  * @param pathData - the SVG path-data that describes the geometry
3514
3588
  * of this path
@@ -3591,12 +3665,15 @@ declare namespace paper {
3591
3665
 
3592
3666
  /**
3593
3667
  * Removes the segments from the specified `from` index to the `to` index
3594
- * from the path's {@link #segments} array.
3668
+ * from the path's {@link #segments} array. On closed paths, `from` can be
3669
+ * bigger than `to`, to remove the segments from `from` to the end and then
3670
+ * from the beginning up to `to`, wrapping around the closing curve.
3595
3671
  *
3596
3672
  * @param from - the beginning index, inclusive
3597
3673
  * @param to - the ending index, exclusive
3598
3674
  *
3599
- * @return an array containing the removed segments
3675
+ * @return an array containing the removed segments, in the
3676
+ * order in which they appeared along the path
3600
3677
  */
3601
3678
  removeSegments(from: number, to?: number): Segment[]
3602
3679
 
@@ -3640,7 +3717,7 @@ declare namespace paper {
3640
3717
  *
3641
3718
  * @return the newly created path after splitting, if any
3642
3719
  */
3643
- splitAt(location: number | CurveLocation): Path
3720
+ splitAt(location: number | CurveLocation): Path | null
3644
3721
 
3645
3722
  /**
3646
3723
  * Joins the path with the other specified path, which will be removed in
@@ -3659,12 +3736,19 @@ declare namespace paper {
3659
3736
  join(path: Path, tolerance?: number): void
3660
3737
 
3661
3738
  /**
3662
- * Reduces the path by removing curves that have a length of 0,
3663
- * and unnecessary segments between two collinear flat curves.
3739
+ * Reduces the path by removing straight curves that have a length of 0.
3740
+ * With `options.simplify`, it also removes straight curves that are almost
3741
+ * 0 in length, and unnecessary segments between two collinear straight
3742
+ * curves.
3743
+ *
3744
+ * @option [options.simplify=false] {Boolean} also remove almost zero-length
3745
+ * curves and segments between collinear straight curves
3746
+ *
3747
+ * @param options - the reduce options
3664
3748
  *
3665
3749
  * @return the reduced path
3666
3750
  */
3667
- reduce(options: any): Path
3751
+ reduce(options?: object): Path
3668
3752
 
3669
3753
  /**
3670
3754
  * Attempts to create a new shape item with same geometry as this path item,
@@ -3689,7 +3773,7 @@ declare namespace paper {
3689
3773
  *
3690
3774
  * @return the curve location of the specified point
3691
3775
  */
3692
- getLocationOf(point: PointLike): CurveLocation
3776
+ getLocationOf(point: PointLike): CurveLocation | null
3693
3777
 
3694
3778
  /**
3695
3779
  * Returns the length of the path from its beginning up to up to the
@@ -3699,10 +3783,11 @@ declare namespace paper {
3699
3783
  *
3700
3784
  * @return the length of the path up to the specified point
3701
3785
  */
3702
- getOffsetOf(point: PointLike): number
3786
+ getOffsetOf(point: PointLike): number | null
3703
3787
 
3704
3788
  /**
3705
- * Returns the curve location of the specified offset on the path.
3789
+ * Returns the curve location of the specified offset on the path, or
3790
+ * `null` if the offset exceeds the length of the path.
3706
3791
  *
3707
3792
  * @param offset - the offset on the path, where `0` is at
3708
3793
  * the beginning of the path and {@link Path#length} at the end
@@ -4141,7 +4226,7 @@ declare namespace paper {
4141
4226
  * @return the locations of all intersection between the
4142
4227
  * paths
4143
4228
  */
4144
- getIntersections(path: PathItem, include?: Function): CurveLocation[]
4229
+ getIntersections(path?: PathItem, include?: Function): CurveLocation[]
4145
4230
 
4146
4231
  /**
4147
4232
  * Returns all crossings between two {@link PathItem} items as an array of
@@ -4779,6 +4864,15 @@ declare namespace paper {
4779
4864
  */
4780
4865
  modulo(point: PointLike): Point
4781
4866
 
4867
+ /**
4868
+ * Returns a new point with both coordinates negated.
4869
+ * PaperScript uses it for the unary minus operator.
4870
+ * The object itself is not modified!
4871
+ *
4872
+ * @return the negation of the point as a new point
4873
+ */
4874
+ negate(): Point
4875
+
4782
4876
  /**
4783
4877
  * Checks whether the point is inside the boundaries of the rectangle.
4784
4878
  *
@@ -4894,6 +4988,18 @@ declare namespace paper {
4894
4988
  */
4895
4989
  abs(): Point
4896
4990
 
4991
+ /**
4992
+ * Returns a new point with the {@link #x} and {@link #y} values clamped to
4993
+ * the range between the given minimum and maximum points. The object
4994
+ * itself is not modified!
4995
+ *
4996
+ * @param min - the point with the smallest values
4997
+ * @param max - the point with the largest values
4998
+ *
4999
+ * @return the clamped point as a new point
5000
+ */
5001
+ clamp(min: PointLike, max: PointLike): Point
5002
+
4897
5003
  /**
4898
5004
  * Returns a new point object with the smallest {@link #x} and
4899
5005
  * {@link #y} of the supplied points.
@@ -5079,11 +5185,13 @@ declare namespace paper {
5079
5185
  * Performs a hit-test on the items contained within the project at the
5080
5186
  * location of the specified point.
5081
5187
  *
5082
- * The options object allows you to control the specifics of the hit-test
5083
- * and may contain a combination of the following values:
5188
+ * The options object allows you to control the specifics of the hit-test.
5189
+ * Without options, `fill`, `stroke` and `segments` are hit-tested. As soon
5190
+ * as an options object is passed, only the hit-tests that it sets to `true`
5191
+ * are performed. It may contain a combination of the following values:
5084
5192
  *
5085
5193
  * @option [options.tolerance={@link PaperScope#settings}.hitTolerance]
5086
- * {Number} the tolerance of the hit-test
5194
+ * {Number} the tolerance of the hit-test, in project coordinates
5087
5195
  * @option options.class {Function} only hit-test against a specific item
5088
5196
  * class, or any of its sub-classes, by providing the constructor
5089
5197
  * function against which an `instanceof` check is performed:
@@ -5092,11 +5200,11 @@ declare namespace paper {
5092
5200
  * @option options.match {Function} a match function to be called for each
5093
5201
  * found hit result: Return `true` to return the result, `false` to keep
5094
5202
  * searching
5095
- * @option [options.fill=true] {Boolean} hit-test the fill of items
5096
- * @option [options.stroke=true] {Boolean} hit-test the stroke of path
5097
- * items, taking into account the setting of stroke color and width
5098
- * @option [options.segments=true] {Boolean} hit-test for {@link
5099
- * Segment#point} of {@link Path} items
5203
+ * @option options.fill {Boolean} hit-test the fill of items
5204
+ * @option options.stroke {Boolean} hit-test the stroke of path items,
5205
+ * taking into account the setting of stroke color and width
5206
+ * @option options.segments {Boolean} hit-test for {@link Segment#point} of
5207
+ * {@link Path} items
5100
5208
  * @option options.curves {Boolean} hit-test the curves of path items,
5101
5209
  * without taking the stroke color or width into account
5102
5210
  * @option options.handles {Boolean} hit-test for the handles ({@link
@@ -5109,7 +5217,7 @@ declare namespace paper {
5109
5217
  * the bounding rectangle of items ({@link Item#bounds})
5110
5218
  * @option options.bounds {Boolean} hit-test the corners and side-centers of
5111
5219
  * the bounding rectangle of items ({@link Item#bounds})
5112
- * @option options.guides {Boolean} hit-test items that have {@link
5220
+ * @option options.guides {Boolean} only hit-test items that have {@link
5113
5221
  * Item#guide} set to `true`
5114
5222
  * @option options.selected {Boolean} only hit selected items
5115
5223
  *
@@ -5170,7 +5278,9 @@ declare namespace paper {
5170
5278
  *
5171
5279
  * @param options - the criteria to match against
5172
5280
  *
5173
- * @return the list of matching items contained in the project
5281
+ * @return the list of matching items contained in the project, in
5282
+ * their stacking order from bottom to top, with each item listed
5283
+ * before its own descendants
5174
5284
  */
5175
5285
  getItems(options: object | Function): Item[]
5176
5286
 
@@ -5239,6 +5349,12 @@ declare namespace paper {
5239
5349
  * @option [options.embedImages=true] {Boolean} whether raster images should
5240
5350
  * be embedded as base64 data inlined in the xlink:href attribute, or
5241
5351
  * kept as a link to their external URL.
5352
+ * @option [options.reuseImages=false] {Boolean} whether raster images with
5353
+ * the same content should only be exported once into the `<defs>`
5354
+ * element, and placed through `<use>` elements referencing it
5355
+ * @option [options.idPrefix=''] {String} a prefix for the ids generated
5356
+ * for definitions such as gradients, clip paths and symbols, to keep
5357
+ * them unique when several exported SVGs are placed in one document
5242
5358
  * @option [options.reduceAttributes=true] {Boolean} wether to only include
5243
5359
  * style attributes in the SVG output that differ from their parents,
5244
5360
  * or to always include them (much faster but leading to redundancies).
@@ -5256,8 +5372,15 @@ declare namespace paper {
5256
5372
  * Note that the project is not cleared first. You can call
5257
5373
  * {@link Project#clear} to do so.
5258
5374
  *
5375
+ * `<symbol>` elements are imported as {@link SymbolDefinition} items, and
5376
+ * the `<use>` elements that place them as {@link SymbolItem} items. The
5377
+ * styles that `<use>` elements inherit don't reach the symbols' content.
5378
+ *
5259
5379
  * @option [options.expandShapes=false] {Boolean} whether imported shape
5260
5380
  * items should be expanded to path items
5381
+ * @option [options.crossOrigin] {String} the {@link Raster#crossOrigin}
5382
+ * value of the rasters created for `<image>` elements, to load their
5383
+ * images with CORS
5261
5384
  * @option options.onLoad {Function} the callback function to call once the
5262
5385
  * SVG content is loaded from the given URL receiving two arguments: the
5263
5386
  * converted `item` and the original `svg` data as a string. Only
@@ -5353,15 +5476,16 @@ declare namespace paper {
5353
5476
  context: CanvasRenderingContext2D
5354
5477
 
5355
5478
  /**
5356
- * The source of the raster, which can be set using a DOM Image, a Canvas,
5357
- * a data url, a string describing the URL to load the image from, or the
5358
- * ID of a DOM element to get the image from (either a DOM Image or a
5359
- * Canvas). Reading this property will return the url of the source image or
5360
- * a data-url.
5479
+ * The source of the raster, which can be set using a string describing the
5480
+ * URL to load the image from, or a data url. Reading this property will
5481
+ * return the url of the source image or a data-url.
5482
+ * To set the raster to a DOM Image or a Canvas, use {@link #image} or
5483
+ * {@link #canvas} instead. The ID of a DOM Image or Canvas element is only
5484
+ * accepted by the constructor.
5361
5485
  * Note that for consistency, a {@link #onLoad} event will be triggered on
5362
5486
  * the raster even if the image has already finished loading before.
5363
5487
  */
5364
- source: HTMLImageElement | HTMLCanvasElement | string
5488
+ source: string
5365
5489
 
5366
5490
  /**
5367
5491
  * The crossOrigin value to be used when loading the image resource, in
@@ -5459,8 +5583,21 @@ declare namespace paper {
5459
5583
 
5460
5584
  /**
5461
5585
  * Returns a Base 64 encoded `data:` URL representation of the raster.
5586
+ * If the raster shows an image that was loaded from a `data:` URL, that
5587
+ * URL is returned unchanged. Otherwise, the arguments are passed on to
5588
+ * `HTMLCanvasElement#toDataURL()` of the raster's {@link #canvas}.
5589
+ * In web-workers, where the canvas is an `OffscreenCanvas`, this is not
5590
+ * supported, and neither are {@link #source} and exporting the raster to
5591
+ * JSON, which rely on it. Use the canvas' asynchronous `convertToBlob()`
5592
+ * there instead.
5593
+ *
5594
+ * @param type - the image format to encode
5595
+ * @param quality - the image quality between `0` and `1`, for
5596
+ * formats that use lossy compression, such as `'image/jpeg'`
5597
+ *
5598
+ * @return the `data:` URL of the raster
5462
5599
  */
5463
- toDataURL(): string
5600
+ toDataURL(type?: string, quality?: number): string
5464
5601
 
5465
5602
  /**
5466
5603
  * Draws an image on the raster.
@@ -5526,8 +5663,16 @@ declare namespace paper {
5526
5663
 
5527
5664
  createImageData(size: SizeLike): ImageData
5528
5665
 
5529
-
5530
- getImageData(rect: RectangleLike): ImageData
5666
+ /**
5667
+ * Returns the image data of the pixels within the specified rectangle, or
5668
+ * of the whole raster if no rectangle or an empty one is passed.
5669
+ *
5670
+ * @param rect - the area of the raster to get the image data
5671
+ * of, in pixel coordinates
5672
+ *
5673
+ * @return the image data of the specified area
5674
+ */
5675
+ getImageData(rect?: RectangleLike): ImageData
5531
5676
 
5532
5677
 
5533
5678
  putImageData(data: ImageData, point: PointLike): void
@@ -5564,7 +5709,8 @@ declare namespace paper {
5564
5709
  height: number
5565
5710
 
5566
5711
  /**
5567
- * The top-left point of the rectangle
5712
+ * The top-left point of the rectangle. Setting it moves the whole
5713
+ * rectangle, unlike {@link #topLeft}.
5568
5714
  */
5569
5715
  point: Point
5570
5716
 
@@ -5598,47 +5744,59 @@ declare namespace paper {
5598
5744
  bottom: number
5599
5745
 
5600
5746
  /**
5601
- * The center point of the rectangle.
5747
+ * The center point of the rectangle. Setting it moves the whole rectangle.
5602
5748
  */
5603
5749
  center: Point
5604
5750
 
5605
5751
  /**
5606
- * The top-left point of the rectangle.
5752
+ * The top-left point of the rectangle. Note that this doesn't move the
5753
+ * whole rectangle; the bottom-right corner stays where it was.
5607
5754
  */
5608
5755
  topLeft: Point
5609
5756
 
5610
5757
  /**
5611
- * The top-right point of the rectangle.
5758
+ * The top-right point of the rectangle. Note that this doesn't move the
5759
+ * whole rectangle; the bottom-left corner stays where it was.
5612
5760
  */
5613
5761
  topRight: Point
5614
5762
 
5615
5763
  /**
5616
- * The bottom-left point of the rectangle.
5764
+ * The bottom-left point of the rectangle. Note that this doesn't move the
5765
+ * whole rectangle; the top-right corner stays where it was.
5617
5766
  */
5618
5767
  bottomLeft: Point
5619
5768
 
5620
5769
  /**
5621
- * The bottom-right point of the rectangle.
5770
+ * The bottom-right point of the rectangle. Note that this doesn't move the
5771
+ * whole rectangle; the top-left corner stays where it was.
5622
5772
  */
5623
5773
  bottomRight: Point
5624
5774
 
5625
5775
  /**
5626
- * The left-center point of the rectangle.
5776
+ * The left-center point of the rectangle. Setting it moves the left hand
5777
+ * side while the right hand side stays where it was, and moves the whole
5778
+ * rectangle vertically.
5627
5779
  */
5628
5780
  leftCenter: Point
5629
5781
 
5630
5782
  /**
5631
- * The top-center point of the rectangle.
5783
+ * The top-center point of the rectangle. Setting it moves the top while
5784
+ * the bottom stays where it was, and moves the whole rectangle
5785
+ * horizontally.
5632
5786
  */
5633
5787
  topCenter: Point
5634
5788
 
5635
5789
  /**
5636
- * The right-center point of the rectangle.
5790
+ * The right-center point of the rectangle. Setting it moves the right
5791
+ * hand side while the left hand side stays where it was, and moves the
5792
+ * whole rectangle vertically.
5637
5793
  */
5638
5794
  rightCenter: Point
5639
5795
 
5640
5796
  /**
5641
- * The bottom-center point of the rectangle.
5797
+ * The bottom-center point of the rectangle. Setting it moves the bottom
5798
+ * while the top stays where it was, and moves the whole rectangle
5799
+ * horizontally.
5642
5800
  */
5643
5801
  bottomCenter: Point
5644
5802
 
@@ -5652,6 +5810,11 @@ declare namespace paper {
5652
5810
  *
5653
5811
  * Paper.js draws the bounds of items with selected bounds on top of
5654
5812
  * your project. This is very useful when debugging.
5813
+ *
5814
+ * This property is only available on the rectangle returned by
5815
+ * {@link Item#bounds}, and the selection always shows these bounds.
5816
+ * Rectangles returned by other getters such as {@link
5817
+ * Item#strokeBounds} don't have it.
5655
5818
  */
5656
5819
  selected: boolean
5657
5820
 
@@ -6353,6 +6516,15 @@ declare namespace paper {
6353
6516
  */
6354
6517
  modulo(size: SizeLike): Size
6355
6518
 
6519
+ /**
6520
+ * Returns a new size with both dimensions negated.
6521
+ * PaperScript uses it for the unary minus operator.
6522
+ * The object itself is not modified!
6523
+ *
6524
+ * @return the negation of the size as a new size
6525
+ */
6526
+ negate(): Size
6527
+
6356
6528
  /**
6357
6529
  * Checks if this size has both the width and height set to 0.
6358
6530
  *
@@ -6428,6 +6600,9 @@ declare namespace paper {
6428
6600
  * All properties of Style are also reflected directly in {@link Item},
6429
6601
  * i.e.: {@link Item#fillColor}.
6430
6602
  *
6603
+ * Styles set on a {@link Group} or {@link Layer} are applied to the children
6604
+ * that it contains at that moment. Items added to it later do not receive them.
6605
+ *
6431
6606
  * To set multiple style properties in one go, you can pass an object to
6432
6607
  * {@link Item#style}. This is a convenient way to define a style once and
6433
6608
  * apply it to a series of items:
@@ -6539,6 +6714,13 @@ declare namespace paper {
6539
6714
  */
6540
6715
  leading: number | string
6541
6716
 
6717
+ /**
6718
+ * The tracking of text content: the space added after each character, in
6719
+ * thousandths of an em, as in Adobe Illustrator and InDesign. A tracking of
6720
+ * 100 adds a tenth of the font size.
6721
+ */
6722
+ tracking: number
6723
+
6542
6724
  /**
6543
6725
  * The justification of text paragraphs.
6544
6726
  */
@@ -6604,7 +6786,9 @@ declare namespace paper {
6604
6786
 
6605
6787
  /**
6606
6788
  * A symbol item represents an instance of a symbol which has been
6607
- * placed in a Paper.js project.
6789
+ * placed in a Paper.js project. All instances share the symbol's definition,
6790
+ * which they draw as it is: styles set on a symbol item don't reach the items
6791
+ * of the definition, unlike `<use>` elements in SVG.
6608
6792
  */
6609
6793
  class SymbolItem extends Item {
6610
6794
  /**
@@ -6658,6 +6842,13 @@ declare namespace paper {
6658
6842
  */
6659
6843
  leading: number | string
6660
6844
 
6845
+ /**
6846
+ * The tracking of text content: the space added after each character, in
6847
+ * thousandths of an em, as in Adobe Illustrator and InDesign. A tracking of
6848
+ * 100 adds a tenth of the font size.
6849
+ */
6850
+ tracking: number
6851
+
6661
6852
  /**
6662
6853
  * The justification of text paragraphs.
6663
6854
  */
@@ -6711,6 +6902,9 @@ declare namespace paper {
6711
6902
  * The function to be called the mouse moves within the project view. The
6712
6903
  * function receives a {@link ToolEvent} object which contains information
6713
6904
  * about the tool event.
6905
+ *
6906
+ * While the mouse button is held down, the tool calls {@link #onMouseDrag}
6907
+ * instead, if it defines one, and `onMouseMove` only otherwise.
6714
6908
  */
6715
6909
  onMouseMove: Function | null
6716
6910
 
@@ -6838,6 +7032,11 @@ declare namespace paper {
6838
7032
  */
6839
7033
  type: string
6840
7034
 
7035
+ /**
7036
+ * The tool that fired the event.
7037
+ */
7038
+ tool: Tool
7039
+
6841
7040
  /**
6842
7041
  * The position of the mouse in project coordinates when the event was
6843
7042
  * fired.
@@ -6953,6 +7152,13 @@ declare namespace paper {
6953
7152
  * view, find the currently visible bounds in project coordinates, or the
6954
7153
  * center, both useful for constructing artwork that should appear centered on
6955
7154
  * screen.
7155
+ *
7156
+ * If the canvas element has a `resize` or `data-paper-resize` attribute, the
7157
+ * view adjusts its size to the size of the element whenever the window is
7158
+ * resized. The element itself needs to be sized through CSS, e.g. with
7159
+ * `html, body { height: 100%; }` and `canvas[resize] { width: 100%; height:
7160
+ * 100%; }` for a canvas that fills the window. Without such CSS, the view does
7161
+ * not follow the window, and on HiDPI screens it grows with each resize.
6956
7162
  */
6957
7163
  class View {
6958
7164
  /**
@@ -6969,6 +7175,11 @@ declare namespace paper {
6969
7175
  */
6970
7176
  readonly element: HTMLCanvasElement
6971
7177
 
7178
+ /**
7179
+ * The project that this view displays.
7180
+ */
7181
+ readonly project: Project
7182
+
6972
7183
  /**
6973
7184
  * The ratio between physical pixels and device-independent pixels (DIPs)
6974
7185
  * of the underlying canvas / device.
@@ -7007,6 +7218,7 @@ declare namespace paper {
7007
7218
 
7008
7219
  /**
7009
7220
  * The view's zoom factor by which the project coordinates are magnified.
7221
+ * Setting it to a value that isn't a positive number has no effect.
7010
7222
  *
7011
7223
  * @see #scaling
7012
7224
  */
@@ -7147,6 +7359,28 @@ declare namespace paper {
7147
7359
  */
7148
7360
  onMouseLeave: Function | null
7149
7361
 
7362
+ /**
7363
+ * The function to be called when the user presses a key on the keyboard.
7364
+ * The function receives a {@link KeyEvent} object which contains
7365
+ * information about the keyboard event.
7366
+ *
7367
+ * If the function returns `false`, the keyboard event will be prevented
7368
+ * from bubbling up. This can be used for example to stop the window from
7369
+ * scrolling, when you need the user to interact with arrow keys.
7370
+ */
7371
+ onKeyDown: Function | null
7372
+
7373
+ /**
7374
+ * The function to be called when the user releases a key on the keyboard.
7375
+ * The function receives a {@link KeyEvent} object which contains
7376
+ * information about the keyboard event.
7377
+ *
7378
+ * If the function returns `false`, the keyboard event will be prevented
7379
+ * from bubbling up. This can be used for example to stop the window from
7380
+ * scrolling, when you need the user to interact with arrow keys.
7381
+ */
7382
+ onKeyUp: Function | null
7383
+
7150
7384
 
7151
7385
  /**
7152
7386
  * Removes this view from the project and frees the associated element.
@@ -7155,12 +7389,16 @@ declare namespace paper {
7155
7389
 
7156
7390
  /**
7157
7391
  * Updates the view if there are changes. Note that when using built-in
7158
- * event hanlders for interaction, animation and load events, this method is
7392
+ * event handlers for interaction, animation and load events, this method is
7159
7393
  * invoked for you automatically at the end.
7160
7394
  *
7395
+ * @param force - whether to redraw the view even if nothing
7396
+ * has changed, e.g. after a web font used by text items has finished
7397
+ * loading
7398
+ *
7161
7399
  * @return true if the view was updated
7162
7400
  */
7163
- update(): boolean
7401
+ update(force?: boolean): boolean
7164
7402
 
7165
7403
  /**
7166
7404
  * Requests an update of the view if there are changes through the browser's
@@ -7281,6 +7519,19 @@ declare namespace paper {
7281
7519
  */
7282
7520
  transform(matrix: Matrix): void
7283
7521
 
7522
+ /**
7523
+ * Transform the view so that the specified rectangle is centered in it
7524
+ * and fitted to it as described by `fit`, keeping the view's rotation and
7525
+ * mirroring.
7526
+ *
7527
+ * @param rectangle - the rectangle to fit, in project
7528
+ * coordinates
7529
+ * @param fit - how to fit the rectangle, as in CSS's
7530
+ * `object-fit`: `'contain'` shows all of it, and `'cover'` fills the
7531
+ * whole view with it, cropping the parts that don't fit
7532
+ */
7533
+ fitBounds(rectangle: RectangleLike, fit?: string): void
7534
+
7284
7535
  /**
7285
7536
  * Converts the passed point from project coordinate space to view
7286
7537
  * coordinate space, which is measured in browser pixels in relation to the