paper 0.12.20 → 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 +233 -0
  2. package/README.md +29 -13
  3. package/dist/docs/assets/js/paper.js +788 -365
  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 +1 -1
  43. package/dist/node/self.js +4 -3
  44. package/dist/paper-core.js +769 -354
  45. package/dist/paper-core.min.js +3 -3
  46. package/dist/paper-full.js +788 -365
  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 +1 -8
  51. package/dist/node/xml.js +0 -40
package/CHANGELOG.md CHANGED
@@ -1,5 +1,238 @@
1
1
  # Change Log
2
2
 
3
+ ## `0.13.0`
4
+
5
+ ### Added
6
+
7
+ - Add a `force` parameter to `View#update()`, to redraw the view even when
8
+ nothing changed, e.g. after a web font has loaded (#1913).
9
+ - Add `View#fitBounds(rectangle[, fit])`, to fit a rectangle into the view.
10
+ `fit` takes the values of CSS's `object-fit`: `'contain'` and `'cover'`
11
+ (#1688).
12
+ - Add the `reuseImages` option to `#exportSVG()`, to export images shown by
13
+ several rasters only once, and place them with `<use>` elements (#1993).
14
+ - Add `tracking` to the text styles: the space added after each character, in
15
+ thousandths of an em, as in Adobe Illustrator and InDesign. `#exportSVG()` and
16
+ `#importSVG()` write and read it as `letter-spacing` (#2066).
17
+ - Add `easeInSine`, `easeOutSine`, `easeInOutSine`, `easeInExpo`, `easeOutExpo`,
18
+ `easeInOutExpo`, `easeInCirc`, `easeOutCirc` and `easeInOutCirc` to `Tween`
19
+ (#1855).
20
+ - Add the `idPrefix` option to `#exportSVG()`, prepended to the generated ids of
21
+ definitions, so that separately exported SVGs can be placed in one document
22
+ (#1709).
23
+ - Add the `crossOrigin` option to `#importSVG()`, passed on to the rasters of
24
+ `<image>` elements, so that canvases drawing them aren't tainted (#1094).
25
+ - Add `View#project` (#1634).
26
+ - Add `Point#clamp(min, max)`, e.g. to keep a point inside a rectangle with
27
+ `point.clamp(rect.topLeft, rect.bottomRight)`.
28
+ - Use `OffscreenCanvas` in web-workers, so `Item#rasterize()`,
29
+ `new Raster(size)`, items with opacity or blend modes, and CSS color names,
30
+ which resolved to black, work there. `Raster#toDataURL()` remains unsupported
31
+ in web-workers (#1643).
32
+
33
+ ### Changed
34
+
35
+ - Time double-clicks from mousedown to mousedown and only within 3 pixels, as
36
+ native `dblclick` events do, and don't take a third click for another
37
+ double-click (#1451).
38
+ - Make `Rectangle#left`, `#right`, `#top` and `#bottom` move only their own
39
+ side, as documented, and the corner points only their two sides, keeping the
40
+ opposite ones where they are. They used to move the whole rectangle, unless
41
+ another side was set before. This also applies to `Item#bounds`: setting a
42
+ side or corner of an item's bounds now stretches the item. To move items,
43
+ set `bounds.point`, `bounds.center`, `bounds.x` or `bounds.y` (#2024, #1147).
44
+ - Hit-test groups wherever one of their children is hit, as in Illustrator, so
45
+ `hitTestAll()` always returns the groups above the hit items, and
46
+ `hitTest(point, { class: Group })` finds the group under a point. Groups were
47
+ only hit when all their children shared a fill (#2069).
48
+ - Let inline `style` declarations override presentation attributes in
49
+ `#importSVG()`, as in CSS and browsers: `<rect fill="blue" style="fill: red">`
50
+ now imports red (#1962).
51
+ - Keep the pixels of images in `#importSVG()` and scale them to their size in
52
+ the SVG, instead of resampling them to that size, which made them blurry.
53
+ `Raster#size` is now the image's own size, and images without a size are
54
+ shown at it, as in browsers (#1963).
55
+ - Let `Item#clone()`, the boolean operations, `Item#rasterize()`,
56
+ `Path#toShape()` and `Shape#toPath()` follow `settings.insertItems` when no
57
+ `insert` option is passed, instead of always inserting their results. An
58
+ options object without `insert` also inserts the clone by default now, as
59
+ documented, e.g. `clone({ deep: false })` (#1721).
60
+ - Use jsdom's own `XMLSerializer` for `#exportSVG()` on Node.js, instead of a
61
+ shim that returned HTML, so the output is valid XML with escaped attribute
62
+ values, as in browsers. Empty elements are now self-closing (#1922).
63
+ - `Item#fitBounds(rectangle[, fit])` takes the values of CSS's `object-fit` as
64
+ `fit`: `'contain'`, `'cover'` and `'fill'`, which stretches the item to the
65
+ rectangle.
66
+ - Scale and align images in `#importSVG()` as their `preserveAspectRatio`
67
+ describes, fitting them into their box uniformly and centered by default, as
68
+ browsers do, instead of stretching them. `slice` is treated as `meet` (#1129).
69
+ - Let `Path#removeSegments(from, to)` wrap around on closed paths when `from` is
70
+ larger than `to`, instead of removing nothing (#1881).
71
+ - Read the `href` of `<image>` elements in `#importSVG()` always as a URL, no
72
+ longer as the id of a DOM element first.
73
+
74
+ ### Deprecated
75
+
76
+ - The boolean `fill` parameter of `Item#fitBounds()`: use `'cover'` instead of
77
+ `true`.
78
+
79
+ ### Removed
80
+
81
+ - Remove the workaround for wrong `mouseout` coordinates in old versions of
82
+ Chrome on Windows (#1811).
83
+ - Remove the CLA from the contribution guidelines, as it no longer exists
84
+ (#2071).
85
+
86
+ ### Fixed
87
+
88
+ - Fix `require('paper')` in the Node.js REPL (#2019, #1792).
89
+ - Fix loading PaperScript in bundles that leave the top-level `this` undefined,
90
+ as in ES modules (#1480).
91
+ - Prevent source-map-loader from warning about the source map string in
92
+ PaperScript (#1991).
93
+ - Fix replacing style colors that were set as strings, which threw in strict
94
+ mode (#2049).
95
+ - Fix SVG path data with arc flags that aren't separated from the numbers
96
+ after them, as SVGO writes them (#1808, #1885).
97
+ - Fix `#importSVG()` of gradients, fills, clip paths and `<use>` elements that
98
+ reference definitions appearing later in the document (#1146, #1884, #1978).
99
+ - Fix `#importSVG()` of elements with numeric ids (#1754).
100
+ - Fix `#importSVG()` of rounded rectangles with only `rx` or `ry` (#1863).
101
+ - Fix `#exportSVG()` writing `fill-rule="none"`, `font-family="none"` etc. on
102
+ groups with differently styled children (#1732).
103
+ - Fix `Curve#handleBounds`, which threw, to only include the curve's own
104
+ points (#1992).
105
+ - Fix `Curve#getTimesWithTangent()` for curves without a cubic component,
106
+ such as quadratic curves (#1870).
107
+ - Fix `Shape` JSON import with `type` after `radius` (#1820).
108
+ - Fix boolean operations with `trace: false` or `stroke: true` ignoring
109
+ `options.insert` (#2028).
110
+ - Fix gradients drawn with `strokeScaling: false` (#1821, #1822).
111
+ - Fix the selection of items in symbol definitions being drawn (#1577).
112
+ - Fix `View#zoom` of mirrored views, which was 0 (#1411).
113
+ - Fix item mouse handlers that stopped working after removing items whose
114
+ parent was already removed, or after moving items to another project
115
+ (#2079, #1791).
116
+ - Fix key events with Control, Alt and Meta in Firefox and other browsers that
117
+ fire no `keypress` for them (#1997, #1871).
118
+ - Fix the space key staying down after Option + Space on macOS.
119
+ - Fix key events not reaching a view that became visible after the focused one
120
+ was hidden (#1953).
121
+ - Load in DOMs whose canvas has no 2D context, as jsdom without canvas in jest,
122
+ and run there as in workers (#1805).
123
+ - Keep the original error as `cause` when jsdom or canvas fail to load on
124
+ Node.js (#1759).
125
+ - Fix `#getItems()` and `#getItem()` with a match function or without options
126
+ to search recursively, as documented, instead of matching only the top-level
127
+ items.
128
+ - Fix `#importSVG()` of transforms and styles on `<use>` elements that
129
+ reference groups (#978).
130
+ - Fix the `project` and `parent` options of the `Path.*` constructors. With
131
+ `insert: false`, they no longer insert into the parent, as `new Path()`
132
+ doesn't either (#2012).
133
+ - Fix the bounds of transformed circle and ellipse shapes (#1826).
134
+ - Fix `PointText#strokeBounds` to include the stroke, which got cut off when
135
+ drawn with opacity (#1322).
136
+ - Fix the `Item#bounds` setter on items with zero width or height, which made
137
+ their matrix non-invertible (#1794).
138
+ - Fix `#getItems()` with `overlapping`, which never matched shapes, rasters and
139
+ texts, as their matrix was applied twice (#1300).
140
+ - Fix the bounds of items whose matrix cancels out the matrix of their parent
141
+ (#1457).
142
+ - Fix the source URL and source map of PaperScript loaded from script tags,
143
+ which were lost (#1753).
144
+ - Fix stroke hit-tests at the ends of paths with butt caps, which missed even
145
+ the end points (#1460).
146
+ - Fix `Path#splitAt()` with locations that aren't on the path, which split
147
+ the path at its start instead of returning `null`.
148
+ - Fix clipping with groups that are clipped themselves, as imported SVG with a
149
+ `viewBox` is, which clipped with their own clip mask too (#1618).
150
+ - Fix `Item#hitTest()` and `#hitTestAll()` on items inside transformed
151
+ groups, which took the point in their parent's coordinates instead of the
152
+ documented global ones (#1803).
153
+ - Ignore `View#zoom` values that aren't positive numbers, which left the
154
+ view's matrix without an inverse, so that `View#bounds` threw (#1433).
155
+ - Fix the hit-test tolerance of items inside transformed groups and of symbol
156
+ items, which their transformations scaled. It is now in project
157
+ coordinates, as documented (#1278).
158
+ - Limit the temporary canvases of items with opacity or blend modes to the
159
+ visible area, so large groups no longer disappear or make zooming slow
160
+ (#1644, #1920, #1925, #2001, #2029).
161
+ - Support SVG 2's plain `href` attribute in `#importSVG()`, besides
162
+ `xlink:href`, for `<use>`, `<image>` and gradient links.
163
+ - Fix `#exportSVG()` of groups used as clip masks, which were exported as
164
+ groups inside `<clipPath>`, where only shapes are allowed, so browsers
165
+ clipped everything away (#1445, #1590).
166
+ - Keep the lines of multi-line text in `#exportSVG()` and `#importSVG()`, as
167
+ `<tspan>` elements at their own baselines (#988).
168
+ - Fix shadows being cut off on items with a fill, a stroke and an opacity,
169
+ which are drawn through a temporary canvas (#1628).
170
+ - Fix `#importSVG()` of `<use>` elements that place images, which weren't
171
+ positioned and sized, as their rasters were cloned before the image loaded.
172
+ - Fix `Item#fitBounds()` and `View#fitBounds()` with empty rectangles or
173
+ items: empty sides no longer collapse items, produce `NaN` coordinates with
174
+ `'cover'`, or make the view throw; they are left out of the scaling.
175
+ - Fix `#importSVG()` of lengths in `in`, `cm`, `mm`, `pt` and `pc`, which were
176
+ read as pixels (#1919).
177
+ - Fix `#importSVG()` of percentages inside nested `<svg>` elements, which
178
+ referred to the size of the root instead of the nearest `<svg>` (#1404).
179
+ - Fix `#importSVG()` on Node.js of shapes without a fill, which were imported
180
+ without one instead of black, as in browsers (#1229).
181
+ - Fix the quadratic time of `#exportSVG()` for groups with many children
182
+ (#1353).
183
+ - Implement the documented `'pin-light'` blend mode, which drew nothing (#1527).
184
+ - Fix clip masks of items with a matrix and an opacity or blend mode, which
185
+ clipped in the wrong place (#1594).
186
+ - Fix rasters and point texts used as clip masks, which clipped with the path
187
+ drawn before them. They now clip with their rectangle and bounds (#1845).
188
+ - Fix the stroke bounds of sheared, mirrored and non-uniformly scaled paths with
189
+ `applyMatrix: false`. The miter limit is now checked in the path's own
190
+ coordinates, as canvas does (#2065).
191
+ - Fix symbol items overwriting the `globalMatrix` of their definition's item,
192
+ which affected its stroke bounds and selection (#1684).
193
+ - Fix the view size of canvases with padding or border, which grew with each
194
+ setup of a project for them (#1160, #2033).
195
+ - Fix setting `View#rotation` on mirrored views, which rotated the other way,
196
+ and on non-uniformly scaled views, which got skewed (#1893).
197
+ - Fix touches outside of the view taking over its drag (#1875).
198
+ - Fix hit-tests of point texts ignoring the tolerance (#632).
199
+ - Fix removed selected items being kept by their project, which leaked memory
200
+ (#1856).
201
+ - Fix the line width of selections, which used whatever line width the view's
202
+ context was left with.
203
+ - Fix hit-tests of symbol items with `class`, `type` and `match` filters, which
204
+ were applied to the definition's items instead (#1774).
205
+ - Leave `workspaces` and `resolutions` out of the published `package.json`,
206
+ which made Yarn warn when installing paper (#1921).
207
+ - Fix stale `Item#globalMatrix` and `#localToGlobal()` results of items whose
208
+ sibling was asked first after their parent was transformed, and of items
209
+ moved to another parent or removed (#1750).
210
+ - Fix the points of mouse and touch events on canvases with padding or border,
211
+ with a CSS size that differs from the view size, or under CSS transforms that
212
+ scale them, which were offset or scaled (#549, #1729).
213
+ - Fix the sign of `Line#getSignedDistance()` for lines whose direction has
214
+ two negative coordinates (#1880).
215
+ - Fix outdated bounds of nested groups after changes to items two or more
216
+ levels down, and of groups containing placed symbols after changes to the
217
+ symbol definition (#940).
218
+ - Docs: Mark the `path` argument of `PathItem#getIntersections()` as optional.
219
+ - Docs: Add `View#onKeyDown`, `View#onKeyUp`, `Point#negate()`,
220
+ `Size#negate()`, `PaperScope#createCanvas()`, `#clear()` and `#remove()`.
221
+ - Docs: Correct the defaults of the hit-test options, the results of the math
222
+ operator examples, `Raster#source` and `Item#guide`, and document
223
+ `Path#reduce()`'s `simplify` option, nullable location getters, optional
224
+ arguments, `ToolEvent#tool`, which items have children, how group styles,
225
+ `getItems()` ordering, `Rectangle#selected` and `Tool#onMouseMove` work, and
226
+ the `resize` canvas attribute (#2078, #2092, #2030, #1928, #1947, #1907,
227
+ #1900, #2115, #1645, #1697, #1747, #1507, #604, #1330, #662).
228
+ - Docs: Add examples to the boolean path operations (#1007).
229
+ - Docs: Document that `new Path(pathData)` holds a single sub-path (#2057).
230
+ - Docs: Document that styles set on symbol items, or inherited by imported
231
+ `<use>` elements, don't reach the symbol definition's items (#1329).
232
+ - Docs: Document using Paper.js with a bundler in the README (#1695).
233
+ - Docs: Move the documentation of `<symbol>` and `<use>` from
234
+ `Project#importJSON()` to `Project#importSVG()`.
235
+
3
236
  ## `0.12.20`
4
237
 
5
238
  ### Fixed
package/README.md CHANGED
@@ -33,6 +33,35 @@ Upon execution, you will find a `paper` folder inside the project's
33
33
  For more information on how to install Node.js and NPM, read the chapter
34
34
  [Installing Node.js and NPM](#installing-nodejs-and-npm).
35
35
 
36
+ ### Using Paper.js with a Bundler
37
+
38
+ With a bundler such as webpack, Rollup, esbuild or Vite, import Paper.js and
39
+ set it up with a canvas element:
40
+
41
+ ```js
42
+ import paper from 'paper'
43
+ // Or, with CommonJS: const paper = require('paper')
44
+
45
+ paper.setup(document.getElementById('canvas'))
46
+
47
+ const { Path } = paper
48
+ const circle = new Path.Circle({
49
+ center: paper.view.center,
50
+ radius: 30,
51
+ fillColor: 'red'
52
+ })
53
+
54
+ paper.view.onFrame = event => {
55
+ circle.rotate(1)
56
+ }
57
+ ```
58
+
59
+ The module exports the global `paper` scope as its default export, with all
60
+ classes as its properties. Use `paper.view` and `paper.project` after calling
61
+ `paper.setup()`, rather than importing them, as they only exist from then on.
62
+ To use the core version without PaperScript, import `'paper/dist/paper-core'`
63
+ instead. With TypeScript, the default import requires `esModuleInterop`.
64
+
36
65
  ### Which Version to Use
37
66
 
38
67
  The various distributions come with two different pre-build versions of
@@ -277,7 +306,6 @@ of the repository in which you perform development. See
277
306
  We prefer that you send a
278
307
  [pull request on GitHub](https://help.github.com/articles/about-pull-requests/)
279
308
  which will then be merged into the official main line repository.
280
- You need to sign the Paper.js CLA to be able to contribute (see below).
281
309
 
282
310
  Also, in your first contribution, add yourself to the end of `AUTHORS.md` (which
283
311
  of course is optional).
@@ -340,18 +368,6 @@ starting point and reference. If you are fixing an issue, a convenient way to
340
368
  name the branch is to use the issue number as a prefix, like this: `git checkout
341
369
  -tb issue-937-feature-add-text-styling`.
342
370
 
343
- #### Contributor License Agreement
344
-
345
- Before we can accept any contributions to Paper.js, you need to sign this
346
- [CLA](https://en.wikipedia.org/wiki/Contributor_License_Agreement):
347
-
348
- [Contributor License Agreement](https://spreadsheets.google.com/a/paperjs.org/spreadsheet/embeddedform?formkey=dENxd0JBVDY2REo3THVuRmh4YjdWRlE6MQ)
349
-
350
- > The purpose of this agreement is to clearly define the terms under which
351
- > intellectual property has been contributed to Paper.js and thereby allow us to
352
- > defend the project should there be a legal dispute regarding the software at
353
- > some future time.
354
-
355
371
  For a list of authors and contributors, please see
356
372
  [AUTHORS](https://github.com/paperjs/paper.js/blob/main/AUTHORS.md).
357
373