News
- Paper.js 1.0 is a rewrite in TypeScript as ES modules, with its own type declarations.
MIGRATION.mdlists the changes that can break existing code, with the old and the new form side by side. paperworks as before: import it, callpaper.setup(canvas)and draw.paper/corehas the classes alone, so bundlers include only what an app uses, e.g. 15 KB forPoint(#1844).paper/boolean,paper/offsetandpaper/smoothingwork on plain path data, without items.paper/noderuns Paper.js on Node.js,paper/paperscriptadds PaperScript, andpaper/hostedlets an application back projects with its own documents, so scripts work on the application's items.- Views handle pointer events, so a mouse, pen or finger works the same everywhere.
- Stroke profiles, outlines and offsets are faster and much more robust.
Added
- Add the entry points
paper/core,paper/boolean,paper/offset,paper/smoothing,paper/nodeandpaper/hosted, and the script filedist/paper-hosted.js. - Add
use(), which adds the features thatpaper/coreleaves out: boolean operations, offsetting, SVG, effects, tweens and rasters. - Add the factories
Path.line(),Path.circle(),Path.rectangle(),Path.ellipse(),Path.arc(),Path.regularPolygon(),Path.star(),Shape.circle(),Shape.rectangle()andShape.ellipse(). - Add
Item#expand(), which turns an item into plain items that draw the same, as Illustrator's Expand does (#953). - Add the options
strokes,gradientsandpatternstoItem#transform(). - Add
Item#loadSVG(),Project#loadSVG()andRaster#load(), which return promises. - Add
new Color(type, ...components), e.g.new Color('hsb', 0, 1, 1). - Make
Linepublic, withnew Line(from, to)and aninfiniteproperty (#1589). - Add
Curve#getPeaks()andNumerical.solveQuartic(). - Keep stroke profiles through boolean operations,
offset()andinterpolate(), and in SVG files written by Paper.js (#2505, #2506). - Let symbol items pass their style on to their definition's content, as SVG's
<use>does (#1329). - Add
button,buttons,pointerTypeandpressureto mouse and tool events (#1354). - Add
Tool#onMouseEnterandTool#onMouseLeave(#1462). - Add the canvas attribute
input="off"for views that ignore the user's input (#1491). - Support current JavaScript syntax in PaperScript.
- Add
Effect#interactive, for effects quick enough to draw while the user interacts. - Return from
View#dispatchKeyEvent()whether a handler prevented the default. - Document how to subclass items (#1050).
- Add
PatternDefinition#pitchandshift, which arrange the tiles as bricks, e.g. withshift: [0.5, 0], or as hexagons, withpitch: [0.75, 1], shift: [0, 0.5]. - Add
PatternDefinition#rightInFrontandbottomInFront, which choose the tiles in front where the item reaches beyond its tile. - Add
Point.coerce()andSize.coerce(), which read a single number as both coordinates, aspoint.multiply(2)anditem.translate(10)do. - Take the coordinates of
cubicCurveTo(),quadraticCurveTo(),cubicCurveBy()andquadraticCurveBy()as numbers, as canvas takes them. - Add the
shadowoption toItem#getBounds(), which includes the shadows of the item and its children.
Changed
- Make the package ES modules only, for Node.js 22.22 or later, and let only its entries and script files be imported (#2035).
- Rename
dist/paper-core.jstodist/paper-slim.js. - Generate the type declarations from the sources, with
nullwhere values can be missing and unions for fixed sets of strings. - Make
Item#name,Segment#name,Item#childrenandTool#minDistanceand its siblingsnullinstead ofundefined. - Return the path from its drawing commands, so calls can be chained (#605).
- Read and write
Item#pivotin the parent's coordinates, aspositionis (#1272). - Return a plain
RectanglefromItem#getBounds()without arguments, and booleans fromItem#replaceWith()andMatrix#isInvertible(). - Read every argument of
Path#add()and#insert()as a segment. - Start rectangles and ellipses where SVG starts them (#601).
- Keep the items of symbol definitions in place instead of centering them (#2435).
- Make
PathItem#reorient()take{ fillRule, clockwise }and use the item's fill rule. - Scale strokes and dashes along when an item applies a matrix it kept.
- Make
offset(),outline()anddash()fall back to the item'swidthanddashArraywhere these arenull, and take amiterLimitof0as given. - Outline stroke profiles three times as fast, and offset and outline paths 10% faster.
- Return a promise from
Tween#then(). - Rename text styles to their names in CSS, e.g.
fontFeatures,letterCaseandlineWrap, and defaultjustificationto'start'. - Rename
TextItem#range()andTextStory#range()togetRange(). - Import the layers of SVG files written by Paper.js as layers again (#483).
- Handle pointer events instead of mouse and touch events;
event.eventis aPointerEvent(#1354, #1959). - Read the characters of key events from
keydownevents. - List
Project#selectedItemsin drawing order. - Parse PaperScript as a module, and load scripts with
srcthroughfetch(). - Run PaperScript through
eval, so a content security policy has to allowunsafe-eval. - Run the page's PaperScripts only from the script files: with
paper/paperscript, callPaperScript.load(). - Return promises from
exportFrames()andexportImage()on Node.js. - Decide from the environment whether views update by themselves: with a DOM of your own on Node.js, set
view.autoUpdate = false. - Stop
paper/hostedfrom changing the core classes when it loads, and rename the host'sgetItem()togetContent(). - Stop clipping the item of a pattern by its tile: parts beyond it lie over the tiles around it, the left and top ones in front by default.
- Replace
PatternDefinition#tilebysize, which defaults to the item's bounds. - Clip the content of patterns by their tiles in SVG import, as SVG draws them, and write each tile that reaches into a pattern's repeat in SVG export.
- Throw an error for a single number where a point or size is expected, instead of reading it as both coordinates, so calls such as
new Segment(10, 20)fail rather than draw in the wrong place. - Leave the
idof canvases alone: views find themselves from their canvases, and no longer write ids such aspaper-view-0into them. - Unite, intersect and subtract several paths at once faster, by about a fifth to a third for 5 to 50 paths without stroke profiles.
- Start the dashes of rounded rectangle and ellipse shapes where those of the same paths start, at the top left, as SVG converts rectangles.
- Create items from their segments, children, path data or other arguments as from the same properties, so that
new Path({ x, y, strokeColor })sets its segment before its other properties, asnew Path({ segments, strokeColor })does. - Type
selectedonly on the points and rectangles that items, segments and curves return, which areSelectablePointandSelectableRectangle, as other points and rectangles can't be selected. - Type the properties of
HitResultthat only some kinds of hits have as optional:name,location,segmentandpoint.
Removed
- Remove the getter and setter methods, such as
item.getPosition(): use the properties. - Remove argument forms that spread numbers, such as
new Segment(x, y), and points given as strings. - Remove the constructors of predefined paths and shapes, such as
new Path.Circle(): use the factories. - Remove
paper.Symbol,paper.PlacedSymboland the other deprecated APIs, listed inMIGRATION.md. - Remove
Item.extend(): useclass extends. - Remove
PaperScope#execute(): usePaperScript.execute(). - Remove loading files from
importSVG(): useloadSVG(). - Remove
settings.scaleStrokes: usetransform(matrix, { strokes: true }). - Remove
paper.DomEvent,paper.DomElement,paper.Httpand the undocumented static methods ofCurve, listed inMIGRATION.md. - Remove support for node-canvas, jsdom and CommonJS, and the
paper-jsdompackages. - Remove the key names of Internet Explorer, such as
Spacebar.
Fixed
- Fix slits, spikes, hairlines and other defects in the outlines of strokes and stroke profiles.
- Fix
offset()of stroke profiles and of paths with tiny handles or no length. - Fix boolean operations losing areas, and
divide()of touching paths. - Fix
getIntersections(),contains()and hit-tests at cusps and where paths turn back. - Fix
arcTo()and its siblings for straight arcs. - Fix object literals for rectangles, and properties left over by the factories.
- Fix gradient stops without an
offset, andGradient#equals(). - Fix
Segment#reverse(),Segment#interpolate()and evaluating curves at locations. - Fix the stroke bounds, hit-tests and
interpolate()of compound paths. - Fix pivots after
toShape(), copies and boolean operations. - Fix
Matrix#scale(),#shear()and#invert()on the matrix of an item. - Fix
raster.width = …, which lost the raster's content. - Fix effects applying the opacity and blend mode of their item twice.
- Fix
new Path([]),Item#addChildren()of several items, andTextStory#replace(). - Fix selected paths drawn with another scope's settings.
- Fix SVG import of
<use>styles (#1329), the styles and rotation of text (#2665, #2784), strokes in transformed groups, and empty polygons. - Fix nested SVG imports and exports, and exporting items scaled to nothing.
- Fix repeated
mouseenterevents, and views sharing their state. - Fix drags with two mouse buttons (#1355) and mouse moves with pointer lock (#1802).
- Fix
event.modifiersand the values of tool events, which changed after the event. - Fix handlers returning
0or''stopping events. - Fix PaperScript reading names in comments and strings as globals.
- Fix the declarations for apps with strict settings.
- Resolve references to the host's definitions, such as
['@pattern/Dots'], inimportJSON()of hosted projects, where they stayed arrays and failed later, e.g. in a current style with a pattern fill. - Name the key in the error when the host of a project has no definition for it, instead of failing on
null. - Include shadows in
Item#previewBounds, so thatItem#rasterize(), pattern tiles and groups with an opacity no longer cut them off. - Keep the matrix of groups and compound paths that
Item#reduce()replaces by their single child, which also misplaced the results of boolean operations,outline()anddash()of such compound paths. - Fix the bounds of transformed items that keep their matrix, which ignored changes to their children.
- Send the events of canvases that share an
id, as in different shadow roots, to their own views.