/*!
* Paper.js v0.17.0 - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
* http://juerglehni.com/ & https://puckey.studio/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*
* Date: Tue Nov 3 20:27:46 2026 +0100
*
* This is an auto-generated type definition.
*/
declare namespace paper {
type PointLike = (
Point
| [ number, number ]
| { x: number, y: number }
| { width: number, height: number }
| { angle: number, length: number }
| { angleInRadians: number, length: number }
)
type SizeLike = (
Size
| [ number, number ]
| { x: number, y: number }
| { width: number, height: number }
)
type RectangleLike = (
Rectangle
| [ number, number, number, number ]
| { x: number, y: number, width: number, height: number }
| { from: PointLike, to: PointLike }
)
type ColorLike = (
Color
| string
| number[]
| { red: number, green: number, blue: number, alpha?: number }
| { gray: number, alpha?: number }
| { hue: number, saturation: number, brightness: number, alpha?: number }
| { hue: number, saturation: number, lightness: number, alpha?: number }
| {
gradient: Gradient | { stops: GradientStopLike[], radial?: boolean },
origin: PointLike,
destination: PointLike,
highlight?: PointLike
}
| {
stops: GradientStopLike[],
radial?: boolean,
origin: PointLike,
destination: PointLike,
highlight?: PointLike
}
| { pattern: PatternDefinition, matrix?: Matrix }
)
type GradientStopLike = GradientStop | ColorLike | [ ColorLike, number ]
/**
* An AreaText item represents text that flows inside an area, its
* {@link #textPath}: any path, with holes too, divided into
* {@link #columns} and {@link #rows}. Its lines break between words to fit
* the area's width where they sit. What doesn't fit flows on into the next
* linked text item.
*/
class AreaText extends TextItem {
/**
* The number of columns that the area is divided into, from left to
* right, which the text fills one after the other.
*/
columns: number
/**
* The number of rows that the area is divided into, from top to bottom,
* each with its columns.
*/
rows: number
/**
* The space between the columns and between the rows.
*/
gutter: number
/**
* The space between the area's edges and the text.
*/
inset: number
/**
* Where the lines sit in each column, from top to bottom.
*/
verticalAlign: string
/**
* Creates a text item that flows inside an area.
*
* @param area - the path that the text flows inside
* @param orientation - the orientation of the text
*/
constructor(area: PathItem, orientation?: string)
/**
* Creates a text item that flows inside a rectangle.
*
* @param rectangle - the rectangle that the text flows inside
* @param orientation - the orientation of the text
*/
constructor(rectangle: RectangleLike, orientation?: string)
/**
* Creates a text item that flows inside an area, from the properties
* described by an object literal.
*
* @param object - an object containing properties describing the
* text's attributes
*/
constructor(object: object)
/**
* Sets the area's height to the smallest that holds all of its text,
* scaling its {@link #textPath} vertically from its top. An area without
* a height, which holds nothing, becomes a rectangle as wide as it.
*
* @return this area text
*/
fitHeight(): AreaText
}
class ChangeFlag {
/**
* Anything affecting the appearance of an item, including GEOMETRY,
* STROKE, STYLE and ATTRIBUTE (except for the invisible ones: locked, name)
*/
static APPEARANCE: number
/**
* A change in the item's children
*/
static CHILDREN: number
/**
* A change of the item's place in the scene graph (removed, inserted,
* moved)
*/
static INSERTION: number
/**
* Item geometry (path, bounds)
*/
static GEOMETRY: number
/**
* The item's matrix has changed
*/
static MATRIX: number
/**
* Only segment(s) have changed, and affected curves have already been
* notified. This is to implement an optimization in _changed() calls
*/
static SEGMENTS: number
/**
* Stroke geometry (excluding color)
*/
static STROKE: number
/**
* Fill style or stroke color / dash
*/
static STYLE: number
/**
* Item attributes: visible, blendMode, locked, name, opacity, clipMask ...
*/
static ATTRIBUTE: number
/**
* Text content
*/
static CONTENT: number
/**
* Raster pixels
*/
static PIXELS: number
/**
* Clipping in one of the child items
*/
static CLIPPING: number
/**
* The view has been transformed
*/
static VIEW: number
}
/**
* All properties and functions that expect color values in the form
* of instances of Color objects, also accept named colors and hex values as
* strings which are then converted to instances of
* {@link Color} internally.
*/
class Color {
/**
* The type of the color as a string.
*/
type: string
/**
* The color components that define the color, including the alpha value
* if defined.
*/
readonly components: number[]
/**
* The color's alpha value as a number between `0` and `1`.
* All colors of the different subclasses support alpha values.
*/
alpha: number
/**
* The amount of red in the color as a value between `0` and `1`.
*/
red: number
/**
* The amount of green in the color as a value between `0` and `1`.
*/
green: number
/**
* The amount of blue in the color as a value between `0` and `1`.
*/
blue: number
/**
* The amount of gray in the color as a value between `0` and `1`.
*/
gray: number
/**
* The hue of the color as a value in degrees between `0` and `360`.
*/
hue: number
/**
* The saturation of the color as a value between `0` and `1`.
*/
saturation: number
/**
* The brightness of the color as a value between `0` and `1`.
*/
brightness: number
/**
* The lightness of the color as a value between `0` and `1`.
*
* Note that all other components are shared with HSB.
*/
lightness: number
/**
* The gradient object describing the type of gradient and the stops.
*/
gradient: Gradient
/**
* The highlight point of the gradient.
*/
get highlight(): Point
set highlight(value: PointLike)
/**
* The aspect of a radial gradient: its radius across the line from
* the origin to the destination, as a factor of its radius along it,
* which makes it an ellipse. Transforming a gradient color sets it, so
* that the gradient stretches, shears and rotates with its item.
*/
aspect: number
/**
* The pattern whose tiles the color repeats.
*/
pattern: PatternDefinition
/**
* The matrix that places the tiles of the pattern in the item's
* coordinates.
*/
matrix: Matrix
/**
* Creates a RGB Color object.
*
* @param red - the amount of red in the color as a value between
* `0` and `1`
* @param green - the amount of green in the color as a value
* between `0` and `1`
* @param blue - the amount of blue in the color as a value
* between `0` and `1`
* @param alpha - the alpha of the color as a value between `0`
* and `1`
*/
constructor(red: number, green: number, blue: number, alpha?: number)
/**
* Creates a gray Color object.
*
* @param gray - the amount of gray in the color as a value
* between `0` and `1`
* @param alpha - the alpha of the color as a value between `0`
* and `1`
*/
constructor(gray: number, alpha?: number)
/**
* Creates a Color object from a CSS string. All common CSS color string
* formats are supported:
* - Named colors (e.g. `'red'`, `'fuchsia'`, …)
* - Hex strings (`'#ffff00'`, `'#ff0'`, …)
* - RGB strings (`'rgb(255, 128, 0)'`, `'rgba(255, 128, 0, 0.5)'`, …)
* - HSL strings (`'hsl(180deg, 20%, 50%)'`,
* `'hsla(3.14rad, 20%, 50%, 0.5)'`, …)
*
* @param color - the color's CSS string representation
*/
constructor(color: string)
/**
* Creates a gradient Color object.
*/
constructor(gradient: Gradient, origin: PointLike, destination: PointLike, highlight?: PointLike, aspect?: number)
/**
* Creates a pattern Color object, which repeats the tiles of the
* pattern, placed by the matrix in the item's coordinates. As with
* gradient colors, the matrix is transformed along with the item.
*/
constructor(pattern: PatternDefinition, matrix?: Matrix)
/**
* Creates a HSB, HSL, gradient or pattern Color object from the
* properties of the provided object:
*
* @option hsb.hue {Number} the hue of the color as a value in degrees
* between `0` and `360`
* @option hsb.saturation {Number} the saturation of the color as a
* value between `0` and `1`
* @option hsb.brightness {Number} the brightness of the color as a
* value between `0` and `1`
* @option hsb.alpha {Number} the alpha of the color as a value between
* `0` and `1`
* @option hsl.hue {Number} the hue of the color as a value in degrees
* between `0` and `360`
* @option hsl.saturation {Number} the saturation of the color as a
* value between `0` and `1`
* @option hsl.lightness {Number} the lightness of the color as a value
* between `0` and `1`
* @option hsl.alpha {Number} the alpha of the color as a value between
* `0` and `1`
* @option gradient.gradient {Gradient} the gradient object that
* describes the color stops and type of gradient to be used
* @option gradient.origin {Point} the origin point of the gradient
* @option gradient.destination {Point} the destination point of the
* gradient
* @option gradient.stops {GradientStop[]} the gradient stops describing
* the gradient, as an alternative to providing a gradient object
* @option gradient.radial {Boolean} controls whether the gradient is
* radial, as an alternative to providing a gradient object
* @option pattern.pattern {PatternDefinition} the pattern whose tiles
* the color repeats
* @option pattern.matrix {Matrix} the matrix that places the tiles in
* the item's coordinates
*
* @param object - an object describing the components and
* properties of the color
*/
constructor(object: object)
/**
* Sets the color to the passed values. Note that any sequence of
* parameters that is supported by the various {@link Color}
* constructors also work for calls of `set()`.
*/
set(...values: any[]): Color
/**
* Converts the color to another type.
*
* @param type - the color type to convert to. Possible values:
* {@values 'rgb', 'gray', 'hsb', 'hsl'}
*
* @return the converted color as a new instance
*/
convert(type: string): Color
/**
* Checks if the color has an alpha value.
*
* @return true if the color has an alpha value
*/
hasAlpha(): boolean
/**
* Checks if the component color values of the color are the
* same as those of the supplied one.
*
* @param color - the color to compare with
*
* @return true if the colors are the same
*/
equals(color: Color): boolean
/**
* @return a copy of the color object
*/
clone(): Color
/**
* @return a string representation of the color
*/
toString(): string
/**
* Returns the color as a CSS string.
*
* @param hex - whether to return the color in hexadecimal
* representation or as a CSS RGB / RGBA string.
*
* @return a CSS string representation of the color
*/
toCSS(hex: boolean): string
/**
* Transform the gradient or pattern color by the specified matrix.
* Radial gradients become ellipses, see {@link #aspect}, and the
* stripes of linear gradients keep running across them, also when the
* matrix scales unevenly or shears. Pattern colors transform their
* {@link #matrix}.
*
* @param matrix - the matrix to transform the color by
*/
transform(matrix: Matrix): void
/**
* Returns a color object with random {@link #red}, {@link #green}
* and {@link #blue} values between `0` and `1`.
*
* @return the newly created color object
*/
static random(): Color
/**
* Returns the addition of the supplied value to all components of
* the color as a new color.
* The object itself is not modified!
*
* @param number - the number to add
*
* @return the addition of the color and the value as a new
* color
*/
add(number: number): Color
/**
* Returns the addition of the supplied color to the color as a new
* color.
* The object itself is not modified!
*
* @param color - the color to add
*
* @return the addition of the two colors as a new color
*/
add(color: Color): Color
/**
* Returns the subtraction of the supplied value to all components of
* the color as a new color.
* The object itself is not modified!
*
* @param number - the number to subtract
*
* @return the subtraction of the color and the value as a new
* color
*/
subtract(number: number): Color
/**
* Returns the subtraction of the supplied color to the color as a new
* color.
* The object itself is not modified!
*
* @param color - the color to subtract
*
* @return the subtraction of the two colors as a new color
*/
subtract(color: Color): Color
/**
* Returns the multiplication of the supplied value to all components
* of the color as a new color.
* The object itself is not modified!
*
* @param number - the number to multiply
*
* @return the multiplication of the color and the value as a
* new color
*/
multiply(number: number): Color
/**
* Returns the multiplication of the supplied color to the color as a
* new color.
* The object itself is not modified!
*
* @param color - the color to multiply
*
* @return the multiplication of the two colors as a new color
*/
multiply(color: Color): Color
/**
* Returns the division of the supplied value to all components of
* the color as a new color.
* The object itself is not modified!
*
* @param number - the number to divide
*
* @return the division of the color and the value as a new
* color
*/
divide(number: number): Color
/**
* Returns the division of the supplied color to the color as a new
* color.
* The object itself is not modified!
*
* @param color - the color to divide
*
* @return the division of the two colors as a new color
*/
divide(color: Color): Color
}
/**
* A compound path is a complex path that is made up of one or more
* simple sub-paths. It can have the `nonzero` fill rule, or the `evenodd` rule
* applied. Both rules use mathematical equations to determine if any region is
* outside or inside the final shape. The `evenodd` rule is more predictable:
* Every other region within a such a compound path is a hole, regardless of
* path direction.
*
* All the paths in a compound path take on the style of the compound path and
* can be accessed through its {@link Item#children} list.
*/
class CompoundPath extends PathItem {
/**
* Specifies whether the compound-path is fully closed, meaning all its
* contained sub-paths are closed path.
*
* @see Path#closed
*/
closed: boolean
/**
* The first Segment contained within the compound-path, a short-cut to
* calling {@link Path#firstSegment} on {@link Item#firstChild}.
*/
readonly firstSegment: Segment
/**
* The last Segment contained within the compound-path, a short-cut to
* calling {@link Path#lastSegment} on {@link Item#lastChild}.
*/
readonly lastSegment: Segment
/**
* All the curves contained within the compound-path, from all its child
* {@link Path} items.
*/
readonly curves: Curve[]
/**
* The first Curve contained within the compound-path, a short-cut to
* calling {@link Path#firstCurve} on {@link Item#firstChild}.
*/
readonly firstCurve: Curve
/**
* The last Curve contained within the compound-path, a short-cut to
* calling {@link Path#lastCurve} on {@link Item#lastChild}.
*/
readonly lastCurve: Curve
/**
* The area that the compound-path's geometry is covering, calculated by
* getting the {@link Path#area} of each sub-path and it adding up.
* Note that self-intersecting paths and sub-paths of different orientation
* can result in areas that cancel each other out.
*/
readonly area: number
/**
* The total length of all sub-paths in this compound-path, calculated by
* getting the {@link Path#length} of each sub-path and it adding up.
*/
readonly length: number
/**
* Creates a new compound path item from SVG path-data and places it at the
* top of the active layer.
*
* @param pathData - the SVG path-data that describes the geometry
* of this path
*/
constructor(pathData: string)
/**
* Creates a new compound path item from an object description and places it
* at the top of the active layer.
*
* @param object - an object containing properties to be set on the
* path
*/
constructor(object: object)
}
/**
* The Curve object represents the parts of a path that are connected by
* two following {@link Segment} objects. The curves of a path can be accessed
* through its {@link Path#curves} array.
*
* While a segment describe the anchor point and its incoming and outgoing
* handles, a Curve object describes the curve passing between two such
* segments. Curves and segments represent two different ways of looking at the
* same thing, but focusing on different aspects. Curves for example offer many
* convenient ways to work with parts of the path, finding lengths, positions or
* tangents at given offsets.
*/
class Curve {
/**
* The first anchor point of the curve.
*/
get point1(): Point
set point1(value: PointLike)
/**
* The second anchor point of the curve.
*/
get point2(): Point
set point2(value: PointLike)
/**
* The handle point that describes the tangent in the first anchor point.
*/
get handle1(): Point
set handle1(value: PointLike)
/**
* The handle point that describes the tangent in the second anchor point.
*/
get handle2(): Point
set handle2(value: PointLike)
/**
* The first segment of the curve.
*/
readonly segment1: Segment
/**
* The second segment of the curve.
*/
readonly segment2: Segment
/**
* The path that the curve belongs to.
*/
readonly path: Path
/**
* The index of the curve in the {@link Path#curves} array.
*/
readonly index: number
/**
* The next curve in the {@link Path#curves} array that the curve
* belongs to.
*/
readonly next: Curve
/**
* The previous curve in the {@link Path#curves} array that the curve
* belongs to.
*/
readonly previous: Curve
/**
* Specifies whether the points and handles of the curve are selected.
*/
selected: boolean
/**
* An array of 8 float values, describing this curve's geometry in four
* absolute x/y pairs (point1, handle1, handle2, point2). This format is
* used internally for efficient processing of curve geometries, e.g. when
* calculating intersections or bounds.
*
* Note that the handles are converted to absolute coordinates.
*/
readonly values: number[]
/**
* An array of 4 point objects, describing this curve's geometry in absolute
* coordinates (point1, handle1, handle2, point2).
*
* Note that the handles are converted to absolute coordinates.
*/
readonly points: Point[]
/**
* The approximated length of the curve.
*/
readonly length: number
/**
* The area that the curve's geometry is covering.
*/
readonly area: number
/**
* The bounding rectangle of the curve excluding stroke width.
*/
get bounds(): Rectangle
set bounds(value: RectangleLike)
/**
* The bounding rectangle of the curve including stroke width.
*/
get strokeBounds(): Rectangle
set strokeBounds(value: RectangleLike)
/**
* The bounding rectangle of the curve including handles.
*/
readonly handleBounds: Rectangle
/**
* Creates a new curve object.
*/
constructor(segment1: Segment, segment2: Segment)
/**
* Creates a new curve object.
*/
constructor(point1: PointLike, handle1: PointLike, handle2: PointLike, point2: PointLike)
/**
* Returns a copy of the curve.
*/
clone(): Curve
/**
* @return a string representation of the curve
*/
toString(): string
/**
* Determines the type of cubic Bézier curve via discriminant
* classification, as well as the curve-time parameters of the associated
* points of inflection, loops, cusps, etc.
*
* @return the curve classification information as an object, see
* options
*/
classify(): object
/**
* Removes the curve from the path that it belongs to, by removing its
* second segment and merging its handle with the first segment.
*
* @return true if the curve was removed
*/
remove(): boolean
/**
* Checks if the this is the first curve in the {@link Path#curves} array.
*
* @return true if this is the first curve
*/
isFirst(): boolean
/**
* Checks if the this is the last curve in the {@link Path#curves} array.
*
* @return true if this is the last curve
*/
isLast(): boolean
/**
* Creates a new curve as a sub-curve from this curve, its range defined by
* the given curve-time parameters. If `from` is larger than `to`, then
* the resulting curve will have its direction reversed.
*
* @param from - the curve-time parameter at which the sub-curve
* starts
* @param to - the curve-time parameter at which the sub-curve
* ends
*
* @return the newly create sub-curve
*/
getPart(from: number, to: number): Curve
/**
* Divides the curve into two curves at the given offset or location. The
* curve itself is modified and becomes the first part, the second part is
* returned as a new curve. If the curve belongs to a path item, a new
* segment is inserted into the path at the given location, and the second
* part becomes a part of the path as well.
*
* @see #divideAtTime(time)
*
* @param location - the offset or location on the
* curve at which to divide
*
* @return the second part of the divided curve if the location is
* valid, {code null} otherwise
*/
divideAt(location: number | CurveLocation): Curve
/**
* Divides the curve into two curves at the given curve-time parameter. The
* curve itself is modified and becomes the first part, the second part is
* returned as a new curve. If the modified curve belongs to a path item,
* the second part is also added to the path.
*
* @see #divideAt(offset)
*
* @param time - the curve-time parameter on the curve at which to
* divide
*
* @return the second part of the divided curve, if the offset is
* within the valid range, {code null} otherwise.
*/
divideAtTime(time: number): Curve
/**
* Splits the path this curve belongs to at the given offset. After
* splitting, the path will be open. If the path was open already, splitting
* will result in two paths.
*
* @see Path#splitAt(offset)
*
* @param location - the offset or location on the
* curve at which to split
*
* @return the newly created path after splitting, if any
*/
splitAt(location: number | CurveLocation): Path
/**
* Splits the path this curve belongs to at the given offset. After
* splitting, the path will be open. If the path was open already, splitting
* will result in two paths.
*
* @see Path#splitAt(offset)
*
* @param time - the curve-time parameter on the curve at which to
* split
*
* @return the newly created path after splitting, if any
*/
splitAtTime(time: number): Path
/**
* @deprecated use use {@link #divideAt} or
* {@link #divideAtTime} instead.
*/
divide(offset?: number, isTime?: boolean): Curve
/**
* @deprecated use use {@link #splitAt} or
* {@link #splitAtTime} instead.
*/
split(offset?: number, isTime?: boolean): Path
/**
* Returns a reversed version of the curve, without modifying the curve
* itself.
*
* @return a reversed version of the curve
*/
reversed(): Curve
/**
* Clears the curve's handles by setting their coordinates to zero,
* turning the curve into a straight line.
*/
clearHandles(): void
/**
* Checks if this curve has any curve handles set. Handles of which both
* coordinates are 0 within a tolerance of 1e-12 count as not set, see
* {@link Point#isZero}.
*
* @see Curve#handle1
* @see Curve#handle2
* @see Segment#hasHandles()
* @see Path#hasHandles()
*
* @return true if the curve has handles set
*/
hasHandles(): boolean
/**
* Checks if this curve has any length.
*
* @param epsilon - the epsilon against which to compare the
* curve's length
*
* @return true if the curve is longer than the given epsilon
*/
hasLength(epsilon?: number): boolean
/**
* Checks if this curve appears as a straight line. This can mean that
* it has no handles defined, or that the handles run collinear with the
* line that connects the curve's start and end point, not falling
* outside of the line.
*
* @return true if the curve is straight
*/
isStraight(): boolean
/**
* Checks if this curve is parametrically linear, meaning that it is
* straight and its handles are positioned at 1/3 and 2/3 of the total
* length of the curve.
*
* @return true if the curve is parametrically linear
*/
isLinear(): boolean
/**
* Checks if the the two curves describe straight lines that are
* collinear, meaning they run in parallel.
*
* @param curve - the other curve to check against
*
* @return true if the two lines are collinear
*/
isCollinear(curve: Curve): boolean
/**
* Checks if the curve is a straight horizontal line.
*
* @return true if the line is horizontal
*/
isHorizontal(): boolean
/**
* Checks if the curve is a straight vertical line.
*
* @return true if the line is vertical
*/
isVertical(): boolean
/**
* Calculates the curve location at the specified offset on the curve, or
* `null` if the offset exceeds the length of the curve.
*
* @param offset - the offset on the curve
*
* @return the curve location at the specified the offset
*/
getLocationAt(offset: number): CurveLocation
/**
* Calculates the curve location at the specified curve-time parameter on
* the curve, or `null` if the parameter lies outside of `0..1`.
*
* @param time - the curve-time parameter on the curve
*
* @return the curve location at the specified the location
*/
getLocationAtTime(time: number): CurveLocation
/**
* Calculates the curve-time parameter of the specified offset on the path,
* relative to the provided start parameter. If offset is a negative value,
* the parameter is searched to the left of the start parameter. If no start
* parameter is provided, a default of `0` for positive values of `offset`
* and `1` for negative values of `offset`.
*
* @param offset - the offset at which to find the curve-time, in
* curve length units
* @param start - the curve-time in relation to which the offset is
* determined
*
* @return the curve-time parameter at the specified location, or
* `null` if the offset exceeds the length of the curve
*/
getTimeAt(offset: number, start?: number): number
/**
* @deprecated use use {@link #getTimeAt} instead.
*/
getParameterAt(offset: number, start?: number): number
/**
* Calculates the curve-time parameters where the curve is tangential to
* provided tangent. Note that tangents at the start or end are included.
*
* @param tangent - the tangent to which the curve must be tangential
*
* @return at most two curve-time parameters, where the curve is
* tangential to the given tangent
*/
getTimesWithTangent(tangent: PointLike): number[]
/**
* Calculates the curve-time parameters where the curve is tangential to
* provided tangent. Note that tangents at the start or end are included.
*
* @param tangent - the tangent to which the curve must be tangential
*
* @return at most two curve-time parameters, where the curve is
* tangential to the given tangent
*/
getTimesWithTangent(x: number, y: number): number[]
/**
* Calculates the curve offset at the specified curve-time parameter on
* the curve.
*
* @param time - the curve-time parameter on the curve
*
* @return the curve offset at the specified the location
*/
getOffsetAtTime(time: number): number
/**
* Returns the curve location of the specified point if it lies on the
* curve, `null` otherwise.
*
* @param point - the point on the curve
*
* @return the curve location of the specified point
*/
getLocationOf(point: PointLike): CurveLocation | null
/**
* Returns the curve location of the specified point if it lies on the
* curve, `null` otherwise.
*
* @param point - the point on the curve
*
* @return the curve location of the specified point
*/
getLocationOf(x: number, y: number): CurveLocation | null
/**
* Returns the length of the path from its beginning up to up to the
* specified point if it lies on the path, `null` otherwise.
*
* @param point - the point on the path
*
* @return the length of the path up to the specified point
*/
getOffsetOf(point: PointLike): number | null
/**
* Returns the length of the path from its beginning up to up to the
* specified point if it lies on the path, `null` otherwise.
*
* @param point - the point on the path
*
* @return the length of the path up to the specified point
*/
getOffsetOf(x: number, y: number): number | null
/**
* Returns the curve-time parameter of the specified point if it lies on the
* curve, `null` otherwise.
* Note that if there is more than one possible solution in a
* self-intersecting curve, the first found result is returned.
*
* @param point - the point on the curve
*
* @return the curve-time parameter of the specified point
*/
getTimeOf(point: PointLike): number | null
/**
* Returns the curve-time parameter of the specified point if it lies on the
* curve, `null` otherwise.
* Note that if there is more than one possible solution in a
* self-intersecting curve, the first found result is returned.
*
* @param point - the point on the curve
*
* @return the curve-time parameter of the specified point
*/
getTimeOf(x: number, y: number): number | null
/**
* @deprecated use use {@link #getTimeOf} instead.
*/
getParameterOf(point: PointLike): number
/**
* @deprecated use use {@link #getTimeOf} instead.
*/
getParameterOf(x: number, y: number): number
/**
* Returns the nearest location on the curve to the specified point.
*
* @param point - the point for which we search the nearest location
*
* @return the location on the curve that's the closest to
* the specified point
*/
getNearestLocation(point: PointLike): CurveLocation
/**
* Returns the nearest location on the curve to the specified point.
*
* @param point - the point for which we search the nearest location
*
* @return the location on the curve that's the closest to
* the specified point
*/
getNearestLocation(x: number, y: number): CurveLocation
/**
* Returns the nearest point on the curve to the specified point.
*
* @param point - the point for which we search the nearest point
*
* @return the point on the curve that's the closest to the
* specified point
*/
getNearestPoint(point: PointLike): Point
/**
* Returns the nearest point on the curve to the specified point.
*
* @param point - the point for which we search the nearest point
*
* @return the point on the curve that's the closest to the
* specified point
*/
getNearestPoint(x: number, y: number): Point
/**
* Calculates the point on the curve at the given location.
*
* @param location - the offset or location on the
* curve
*
* @return the point on the curve at the given location
*/
getPointAt(location: number | CurveLocation): Point
/**
* Calculates the normalized tangent vector of the curve at the given
* location.
*
* @param location - the offset or location on the
* curve
*
* @return the normalized tangent of the curve at the given location
*/
getTangentAt(location: number | CurveLocation): Point
/**
* Calculates the normal vector of the curve at the given location.
*
* @param location - the offset or location on the
* curve
*
* @return the normal of the curve at the given location
*/
getNormalAt(location: number | CurveLocation): Point
/**
* Calculates the weighted tangent vector of the curve at the given
* location, its length reflecting the curve velocity at that location.
*
* @param location - the offset or location on the
* curve
*
* @return the weighted tangent of the curve at the given location
*/
getWeightedTangentAt(location: number | CurveLocation): Point
/**
* Calculates the weighted normal vector of the curve at the given location,
* its length reflecting the curve velocity at that location.
*
* @param location - the offset or location on the
* curve
*
* @return the weighted normal of the curve at the given location
*/
getWeightedNormalAt(location: number | CurveLocation): Point
/**
* Calculates the curvature of the curve at the given location. Curvatures
* indicate how sharply a curve changes direction. A straight line has zero
* curvature, where as a circle has a constant curvature. The curve's radius
* at the given location is the reciprocal value of its curvature.
*
* @param location - the offset or location on the
* curve
*
* @return the curvature of the curve at the given location
*/
getCurvatureAt(location: number | CurveLocation): number
/**
* Calculates the point on the curve at the given location.
*
* @param time - the curve-time parameter on the curve
*
* @return the point on the curve at the given location
*/
getPointAtTime(time: number): Point
/**
* Calculates the normalized tangent vector of the curve at the given
* location.
*
* @param time - the curve-time parameter on the curve
*
* @return the normalized tangent of the curve at the given location
*/
getTangentAtTime(time: number): Point
/**
* Calculates the normal vector of the curve at the given location.
*
* @param time - the curve-time parameter on the curve
*
* @return the normal of the curve at the given location
*/
getNormalAtTime(time: number): Point
/**
* Calculates the weighted tangent vector of the curve at the given
* location, its length reflecting the curve velocity at that location.
*
* @param time - the curve-time parameter on the curve
*
* @return the weighted tangent of the curve at the given location
*/
getWeightedTangentAtTime(time: number): Point
/**
* Calculates the weighted normal vector of the curve at the given location,
* its length reflecting the curve velocity at that location.
*
* @param time - the curve-time parameter on the curve
*
* @return the weighted normal of the curve at the given location
*/
getWeightedNormalAtTime(time: number): Point
/**
* Calculates the curvature of the curve at the given location. Curvatures
* indicate how sharply a curve changes direction. A straight line has zero
* curvature, where as a circle has a constant curvature. The curve's radius
* at the given location is the reciprocal value of its curvature.
*
* @param time - the curve-time parameter on the curve
*
* @return the curvature of the curve at the given location
*/
getCurvatureAtTime(time: number): number
/**
* Returns all intersections between two {@link Curve} objects as an
* array of {@link CurveLocation} objects.
*
* @param curve - the other curve to find the intersections with
* (if the curve itself or `null` is passed, the self intersection
* of the curve is returned, if it exists)
*
* @return the locations of all intersections between
* the curves
*/
getIntersections(curve: Curve): CurveLocation[]
}
/**
* CurveLocation objects describe a location on {@link Curve} objects, as
* defined by the curve-time {@link #time}, a value between `0` (beginning
* of the curve) and `1` (end of the curve). If the curve is part of a
* {@link Path} item, its {@link #index} inside the {@link Path#curves}
* array is also provided.
*
* The class is in use in many places, such as
* {@link Path#getLocationAt},
* {@link Path#getLocationOf},
* {@link PathItem#getNearestLocation},
* {@link PathItem#getIntersections},
* etc.
*/
class CurveLocation {
/**
* The segment of the curve which is closer to the described location.
*/
readonly segment: Segment
/**
* The curve that this location belongs to.
*/
readonly curve: Curve
/**
* The path that this locations is situated on.
*/
readonly path: Path
/**
* The index of the {@link #curve} within the {@link Path#curves} list, if
* it is part of a {@link Path} item.
*/
readonly index: number
/**
* The curve-time parameter, as used by various bezier curve calculations.
* It is value between `0` (beginning of the curve) and `1` (end of the
* curve).
*/
readonly time: number
/**
* @deprecated use {@link #time} instead.
*/
readonly parameter: number
/**
* The point which is defined by the {@link #curve} and
* {@link #time}.
*/
readonly point: Point
/**
* The length of the path from its beginning up to the location described
* by this object. If the curve is not part of a path, then the length
* within the curve is returned instead.
*/
readonly offset: number
/**
* The length of the curve from its beginning up to the location described
* by this object.
*/
readonly curveOffset: number
/**
* The curve location on the intersecting curve, if this location is the
* result of a call to {@link PathItem#getIntersections} /
* {@link Curve#getIntersections}.
*/
readonly intersection: CurveLocation
/**
* The tangential vector to the {@link #curve} at the given location.
*/
readonly tangent: Point
/**
* The normal vector to the {@link #curve} at the given location.
*/
readonly normal: Point
/**
* The curvature of the {@link #curve} at the given location.
*/
readonly curvature: number
/**
* The distance from the queried point to the returned location.
*
* @see Curve#getNearestLocation(point)
* @see PathItem#getNearestLocation(point)
*/
readonly distance: number
/**
* Creates a new CurveLocation object.
*/
constructor(curve: Curve, time: number, point?: PointLike)
/**
* Checks whether tow CurveLocation objects are describing the same location
* on a path, by applying the same tolerances as elsewhere when dealing with
* curve-time parameters.
*
* @return true if the locations are equal
*/
equals(location: CurveLocation): boolean
/**
* @return a string representation of the curve location
*/
toString(): string
/**
* Checks if the location is an intersection with another curve and is
* merely touching the other curve, as opposed to crossing it.
*
* @see #isCrossing()
*
* @return true if the location is an intersection that is
* merely touching another curve
*/
isTouching(): boolean
/**
* Checks if the location is an intersection with another curve and is
* crossing the other curve, as opposed to just touching it.
*
* @see #isTouching()
*
* @return true if the location is an intersection that is
* crossing another curve
*/
isCrossing(): boolean
/**
* Checks if the location is an intersection with another curve and is
* part of an overlap between the two involved paths.
*
* @see #isCrossing()
* @see #isTouching()
*
* @return true if the location is an intersection that is
* part of an overlap between the two involved paths
*/
hasOverlap(): boolean
}
/**
* The DrawEvent object is received by the {@link Item}'s drawing
* handlers {@link Item#onDraw} and {@link Item#onDrawSelection}, which
* describe its fields.
*/
class DrawEvent {
/**
* Skips the item's default drawing, as returning `false` from the handler
* does.
*/
preventDefault(): void
}
/**
* A live effect, which derives what is drawn from an item without
* changing the item itself, as the effects in Illustrator do. Creating one
* registers it under its type, replacing any effect registered there before,
* and items use it by that type, see {@link Item#effects}, each through an
* {@link EffectInstance} with its own parameters.
*/
class Effect {
/**
* The type that the effect is registered under, and that items use it
* by.
*/
readonly type: string
/**
* The label of the effect, for hosts to show to users.
*/
readonly label: string
/**
* The declared parameters of the effect by their names, as objects
* that describe them for hosts to build their settings from, with the
* default as their `value`, e.g.
* `{ label: 'Amount', type: 'number', range: [0, 100], value: 10 }`.
* The instances of the effect have them as properties.
*/
readonly parameters: any
/**
* The function that applies the effect, called with the instance as
* `this`, and returning what the effect makes of the art that it gets,
* which it doesn't change.
*
* @option event.art {Item} the item to apply the effect to, or what
* the effect before it returned
* @option event.item {Item} the item that the instance is part of
*/
onApply: Function | null
/**
* The function that hosts call when the user edits the parameters of
* an instance, with the instance as `this`, to set its properties.
* Paper.js itself doesn't call it.
*/
onEditParameters: Function | null
/**
* Creates an effect and registers it under its type.
*
* @param props - the {@link #type} of the effect, its
* {@link #label} and {@link #parameters}, and {@link #onApply}
* and {@link #onEditParameters}
*/
constructor(props: object)
/**
* Removes the effect from the registered effects.
*
* @return true if the effect was registered
*/
remove(): boolean
/**
* Registers the effect under its type, replacing any effect
* registered there before. Effects register themselves when they
* are created.
*
* @return the effect
*/
static add(effect: Effect): Effect
/**
* Returns the effect registered under the type.
*
* @return the effect, or `null`
*/
static get(type: string): Effect | null
/**
* Returns all registered effects.
*
* @return the effects
*/
static getAll(): Effect[]
/**
* Removes the effect from the registered effects.
*
* @return true if the effect was registered
*/
static remove(effect: Effect): boolean
}
/**
* The use of an {@link Effect} on an item, see {@link Item#effects},
* with its parameters. The parameters that the effect declares are also its
* properties. Instances of effects that aren't registered keep their
* parameters and leave what they get as it is, so that they still round-trip.
*/
class EffectInstance {
/**
* The type of the effect that the instance uses, also when it isn't
* registered.
*/
readonly type: string
/**
* The effect that the instance uses, registered under its {@link #type},
* or `null` if there is none.
*/
readonly effect: Effect | null
/**
* Whether the effect applies. Effects that aren't visible are skipped.
*/
visible: boolean
/**
* The parameters of the instance. Changing them on the returned object
* updates it, as setting them as its properties does. Parameters that it
* doesn't have yet are added by setting them all, as are changes within
* values such as arrays.
*/
parameters: any
/**
* The item that the instance is part of.
*/
readonly item: Item | null
/**
* The index of the instance in the {@link Item#effects} of its item.
*/
readonly index: number | null
/**
* Removes the instance from its item.
*
* @return true if the instance was removed
*/
remove(): boolean
/**
* Checks whether the instance is equal to the supplied one.
*
* @return true if they are equal
*/
equals(instance: EffectInstance): boolean
}
/**
* The Event object is the base class for any of the other event types,
* such as {@link MouseEvent}, {@link ToolEvent} and {@link KeyEvent}.
*/
class Event {
/**
* The time at which the event was created, in seconds, as the times of
* frame events are. Browsers count from the page's time origin, as
* `performance.now()` does, while
* {@link View#dispatchMouseEvent} and
* {@link View#dispatchKeyEvent} use `Date.now()`
* unless the host passes a time, so only compare the times of events from
* the same source.
*/
readonly time: number
/**
* @deprecated use {@link #time} instead, which is in seconds.
*/
readonly timeStamp: number
/**
* The current state of the keyboard modifiers.
*
* @see Key.modifiers
*/
readonly modifiers: any
/**
* Cancels the event if it is cancelable, without stopping further
* propagation of the event.
*/
preventDefault(): void
/**
* Prevents further propagation of the current event.
*/
stopPropagation(): void
/**
* Cancels the event if it is cancelable, and stops stopping further
* propagation of the event. This is has the same effect as calling both
* {@link #stopPropagation} and {@link #preventDefault}.
*
* Any handler can also return `false` to indicate that `stop()` should be
* called right after.
*/
stop(): void
}
/**
* The Gradient object.
*/
class Gradient {
/**
* The gradient stops on the gradient ramp.
*/
stops: GradientStop[]
/**
* Specifies whether the gradient is radial or linear.
*/
radial: boolean
/**
* @return a copy of the gradient
*/
clone(): Gradient
/**
* Checks whether the gradient is equal to the supplied gradient.
*
* @return true if they are equal
*/
equals(gradient: Gradient): boolean
}
/**
* The GradientStop object.
*/
class GradientStop {
/**
* The ramp-point of the gradient stop as a value between `0` and `1`.
*/
offset: number
/**
* @deprecated use {@link #offset} instead.
*/
rampPoint: number
/**
* The color of the gradient stop.
*/
get color(): Color
set color(value: ColorLike)
/**
* Creates a GradientStop object.
*
* @param color - the color of the stop
* @param offset - the position of the stop on the gradient
* ramp as a value between `0` and `1`; `null` or `undefined` for automatic
* assignment.
*/
constructor(color?: Color, offset?: number)
/**
* @return a copy of the gradient-stop
*/
clone(): GradientStop
}
/**
* A Group is a collection of items. When you transform a Group, its
* children are treated as a single unit without changing their relative
* positions.
*/
class Group extends Item {
/**
* Specifies whether the group item is to be clipped. When setting to
* `true`, the first child in the group is automatically defined as the
* clipping mask.
*/
clipped: boolean
/**
* Specifies whether the group is isolated, drawn through a temporary
* canvas, so that the blend modes of its children only apply within it,
* like CSS's `isolation: isolate`. Without it, a compositing mode such as
* `'destination-out'` affects everything drawn below the group, also in
* other layers. Groups with an {@link Item#opacity} below 1 or a
* {@link Item#blendMode} are isolated anyway, and buffered groups always,
* see {@link #buffered}.
*/
isolated: boolean
/**
* Specifies whether the group is buffered: when a view draws it, it draws
* its content into a canvas of its own, which it keeps, and only draws
* into it again when something in the group changes, or the part of it
* that the view shows does, e.g. after zooming or panning. Otherwise, the
* view only composites the buffer, with the group's {@link Item#opacity}
* and {@link Item#blendMode}. This pays off for large groups and layers
* that rarely change, such as a complex background below animated items.
*
* It doesn't pay off when the buffer is drawn again on every frame: while
* the view pans or zooms on every frame, while the group itself is moved
* or transformed, or when an item inside it is animated. Put animated
* items into another group or layer instead.
*
* The buffer costs memory: it covers the part of the group that the view
* shows, at up to `width × height × 4 × pixelRatio²` bytes for a group
* that fills the whole view.
*
* Buffered groups are always {@link #isolated}: the blend modes of their
* children only apply within them, not to the items below them, also in
* other layers.
*
* Hit-testing, SVG export, {@link Item#rasterize} and drawing into other
* canvases than the view's don't use the buffer.
*
* A buffered group keeps one buffer, so inside a {@link SymbolDefinition}
* that is placed several times, it draws into it again for each placement.
* Changes to any symbol definition make all buffers stale, as do forced
* updates through `view.update(true)`.
*/
buffered: boolean
/**
* Creates a new Group item and places it at the top of the active layer.
*
* @param children - An array of children that will be added to the
* newly created group
*/
constructor(children?: Item[])
/**
* Creates a new Group item and places it at the top of the active layer.
*
* @param object - an object containing the properties to be set on
* the group
*/
constructor(object: object)
/**
* Replaces the group with its children, which keep their appearance: the
* group's matrix is applied to them, and its clipping mask is released.
*
* @return the children, or `null` if the group has no parent
*/
ungroup(): Item[]
}
/**
* A HitResult object contains information about the results of a hit
* test. It is returned by {@link Item#hitTest} and
* {@link Project#hitTest}.
*/
class HitResult {
/**
* Describes the type of the hit result. For example, if you hit a segment
* point, the type would be `'segment'`.
*/
type: string
/**
* If the HitResult has a {@link HitResult#type} of `'bounds'`, this
* property describes which corner of the bounding rectangle was hit.
*
* The names refer to the item's own bounding rectangle, transformed by its
* {@link Item#matrix}, which is the rectangle that the item's selection
* draws. On mirrored or rotated items, a handle can therefore appear
* elsewhere on screen than its name says, while its opposite handle and
* the rectangle's axes stay the ones to transform the item by. To choose
* a cursor, use the direction from the rectangle's center to
* {@link HitResult#point}, both in project coordinates.
*/
name: string
/**
* The item that was hit.
*/
item: Item
/**
* If the HitResult has a type of 'curve' or 'stroke', this property gives
* more information about the exact position that was hit on the path.
*/
location: CurveLocation
/**
* If the HitResult has a type of 'pixel', this property refers to the color
* of the pixel on the {@link Raster} that was hit.
*/
get color(): Color | null
set color(value: ColorLike | null)
/**
* If the HitResult has a type of 'stroke', 'segment', 'handle-in' or
* 'handle-out', this property refers to the segment that was hit or that
* is closest to the hitResult.location on the curve.
*/
segment: Segment
/**
* Describes the actual coordinates of the segment, handle or bounding box
* corner that was hit.
*/
get point(): Point
set point(value: PointLike)
}
/**
* A HostItem represents a node of a host document that has no
* counterpart in Paper.js. Its bounds come from the host, it draws nothing,
* and only its matrix and attributes can be changed. Hosts can extend it to
* expose their own node kinds, storing their properties in `_values`, and
* declare `_hasChildren: true` for kinds that contain other items.
*/
class HostItem extends Item {
}
/**
* The Item type allows you to access and modify the items in
* Paper.js projects. Its functionality is inherited by different project
* item types such as {@link Path}, {@link CompoundPath}, {@link Group},
* {@link Layer} and {@link Raster}. They each add a layer of functionality that
* is unique to their type, but share the underlying properties and functions
* that they inherit from Item.
*/
class Item {
/**
* The live effects of the item, in the order in which they apply, as
* the instances of the {@link Effect effects} that they use. They
* derive what is drawn from the item without changing it: drawing
* draws their output, and {@link #previewBounds} measures it, while
* hit testing, {@link #bounds} and {@link #strokeBounds} stay with the
* item itself. It is set to plain objects describing them, `{ type,
* parameters, visible }`, with the `type` of the effect.
* Changing the returned array directly isn't tracked, as with
* {@link Path#segments}.
*
* Paper.js has these effects, and {@link Effect} creates more:
*
* - `offset`: offsets the paths, see {@link PathItem#offset}, with
* the parameters `distance` (`0`), `join` (`'miter'`) and
* `miterLimit` (`10`).
* - `outline`: outlines the strokes of the paths as filled areas next
* to their fills, see {@link PathItem#outline}, following their
* {@link Path#strokeProfile}.
*/
effects: EffectInstance[]
/**
* The bounds of what the item looks like with its effects, in the
* coordinate space of its parent: of their output with its strokes, or of
* its children's with their effects, and its {@link #strokeBounds}
* without them, as Illustrator's "Use Preview Bounds".
*/
readonly previewBounds: Rectangle
/**
* The key of the host's node that the item represents, in a project
* backed by a host document, see {@link Project#host}. It can only be
* set once, on an item created by a script, to register the key that
* the host gave its new node.
*/
key: number
/**
* The unique id of the item.
*/
readonly id: number
/**
* The class name of the item as a string.
*/
className: string
/**
* The name of the item. If the item has a name, it can be accessed by name
* through its parent's children list.
*/
name: string
/**
* The path style of the item.
*
* Styles set on a {@link Group} or {@link Layer} are applied to the
* children that it contains at that moment. Items added to it later do not
* receive them.
*/
style: Style
/**
* Specifies whether the item is locked. When set to `true`, item
* interactions with the mouse are disabled.
*/
locked: boolean
/**
* Specifies whether the item is visible. When set to `false`, the item
* won't be drawn.
*/
visible: boolean
/**
* The blend mode with which the item is composited onto the canvas. Both
* the standard canvas compositing modes, as well as the new CSS blend modes
* are supported. Where the canvas doesn't support a CSS blend mode
* natively, it draws as `'normal'`. Paper.js's own modes `'add'`,
* `'subtract'`, `'average'`, `'pin-light'` and `'negation'` are emulated,
* which can have an impact on performance.
*/
blendMode: string
/**
* The opacity of the item as a value between `0` and `1`.
*/
opacity: number
/**
* Specifies whether the item functions as a guide. When set to `true`, the
* item is drawn as usual, but left out of hit-tests and mouse
* interactions. Hit-tests only find guides when `options.guides` is set,
* and then only them, see {@link #hitTest}.
*/
guide: boolean
/**
* Specifies whether, and how, the item pushes aside the text of the
* {@link AreaText} items below it in its layer: `null`, or an object with
* `offset`, the space kept between them, and `invert`, to let the text
* flow inside it instead. `true` sets the defaults.
*/
textWrap: any
/**
* Specifies whether the item is selected. This will also return `true` for
* {@link Group} items if they are partially selected, e.g. groups
* containing selected or partially selected paths.
*
* Paper.js draws the visual outlines of selected items on top of your
* project. This can be useful for debugging, as it allows you to see the
* construction of paths, position of path curves, individual segment points
* and bounding boxes of symbol and raster items.
*
* @see Project#selectedItems
* @see Segment#selected
* @see Curve#selected
* @see Point#selected
*/
selected: boolean
/**
* Specifies whether the item and all its descendants are selected. Setting
* it selects or deselects them all.
*/
fullySelected: boolean
/**
* Specifies whether the item defines a clip mask. This can only be set on
* paths and compound paths, and only if the item is already contained
* within a clipping group.
*/
clipMask: boolean
/**
* A plain javascript object which can be used to store
* arbitrary data on the item.
*/
data: any
/**
* The item's position within the parent item's coordinate system. By
* default, this is the {@link Rectangle#center} of the item's
* {@link #bounds} rectangle.
*/
get position(): Point
set position(value: PointLike)
/**
* The item's pivot point specified in the item coordinate system, defining
* the point around which all transformations are hinging. This is also the
* reference point for {@link #position}. By default, it is set to `null`,
* meaning the {@link Rectangle#center} of the item's {@link #bounds}
* rectangle is used as pivot.
*/
get pivot(): Point
set pivot(value: PointLike)
/**
* The bounding rectangle of the item excluding stroke width.
*/
get bounds(): Rectangle
set bounds(value: RectangleLike)
/**
* The bounding rectangle of the item including stroke width.
*
* Setting it fits the item's {@link #bounds} into the given rectangle minus
* the extent of the stroke on each side, also where this extent changes
* with the item's proportions, as with miters. A rectangle smaller than the
* stroke itself shrinks the bounds to its center.
*/
get strokeBounds(): Rectangle
set strokeBounds(value: RectangleLike)
/**
* The bounding rectangle of the item including handles.
*/
get handleBounds(): Rectangle
set handleBounds(value: RectangleLike)
/**
* The bounding rectangle of the item without any matrix transformations.
*
* Typical use case would be drawing a frame around the object where you
* want to draw something of the same size, position, rotation, and scaling,
* like a selection frame.
*/
get internalBounds(): Rectangle
set internalBounds(value: RectangleLike)
/**
* The current rotation angle of the item, as described by its
* {@link #matrix}.
* Please note that this only returns meaningful values for items with
* {@link #applyMatrix} set to `false`, meaning they do not directly bake
* transformations into their content.
*/
rotation: number
/**
* The current scale factor of the item, as described by its
* {@link #matrix}.
* Please note that this only returns meaningful values for items with
* {@link #applyMatrix} set to `false`, meaning they do not directly bake
* transformations into their content.
*/
get scaling(): Point
set scaling(value: PointLike)
/**
* The item's transformation matrix, defining position and dimensions in
* relation to its parent item in which it is contained.
*/
matrix: Matrix
/**
* The item's global transformation matrix in relation to the global project
* coordinate space. Note that the view's transformations resulting from
* zooming and panning are not factored in.
*/
readonly globalMatrix: Matrix
/**
* The item's global matrix in relation to the view coordinate space. This
* means that the view's transformations resulting from zooming and panning
* are factored in.
*/
readonly viewMatrix: Matrix
/**
* Controls whether the transformations applied to the item (e.g. through
* {@link #transform}, {@link #rotate},
* {@link #scale}, etc.) are stored in its {@link #matrix} property,
* or whether they are directly applied to its contents or children (passed
* on to the segments in {@link Path} items, the children of {@link Group}
* items, etc.).
*/
applyMatrix: boolean
/**
* @deprecated use {@link #applyMatrix} instead.
*/
transformContent: boolean
/**
* The project that this item belongs to.
*/
readonly project: Project
/**
* The view that this item belongs to.
*/
readonly view: View
/**
* The scope that this item belongs to, through its project.
*/
readonly scope: PaperScope
/**
* The layer that this item is contained within.
*/
readonly layer: Layer
/**
* The item that this item is contained within.
*/
parent: Item
/**
* The children items contained within this item. Items that define a
* {@link #name} can also be accessed by name.
*
* Only {@link Group}, {@link Layer} and {@link CompoundPath} items can have
* children. On all other items, such as {@link Path}, {@link Shape},
* {@link Raster}, {@link SymbolItem} and {@link PointText}, `children` is
* `undefined`.
*
* Please note: The children array should not be modified directly
* using array functions. To remove single items from the children list, use
* {@link Item#remove}, to remove all items from the children list, use
* {@link Item#removeChildren}. To add items to the children list, use
* {@link Item#addChild} or {@link Item#insertChild}.
*/
children: Item[]
/**
* The first item contained within this item. This is a shortcut for
* accessing `item.children[0]`.
*/
readonly firstChild: Item
/**
* The last item contained within this item.This is a shortcut for
* accessing `item.children[item.children.length - 1]`.
*/
readonly lastChild: Item
/**
* The next item on the same level as this item.
*/
readonly nextSibling: Item
/**
* The previous item on the same level as this item.
*/
readonly previousSibling: Item
/**
* The index of this item within the list of its parent's children.
*/
index: number
/**
* The color of the stroke.
*/
get strokeColor(): Color | null
set strokeColor(value: ColorLike | null)
/**
* The width of the stroke.
*/
strokeWidth: number
/**
* The shape to be used at the beginning and end of open {@link Path} items,
* when they have a stroke.
*/
strokeCap: string
/**
* The shape to be used at the segments and corners of {@link Path} items
* when they have a stroke.
*/
strokeJoin: string
/**
* The dash offset of the stroke.
*/
dashOffset: number
/**
* Specifies whether the stroke is to be drawn taking the current affine
* transformation into account (the default behavior), or whether it should
* appear as a non-scaling stroke. On text, non-scaling strokes are exact for
* uniform scaling only, as the glyphs are always stroked through the
* transformation.
*/
strokeScaling: boolean
/**
* Specifies an array containing the dash and gap lengths of the stroke.
*/
dashArray: number[]
/**
* The miter limit of the stroke.
* When two line segments meet at a sharp angle and miter joins have been
* specified for {@link Item#strokeJoin}, it is possible for the miter to
* extend far beyond the {@link Item#strokeWidth} of the path. The
* miterLimit imposes a limit on the ratio of the miter length to the
* {@link Item#strokeWidth}.
*/
miterLimit: number
/**
* The order in which the fill and the stroke are painted, as in SVG's
* `paint-order`, named after what is painted first: `'fill'` paints the
* fill first, `'stroke'` paints the stroke first, so the fill covers its
* inner half.
*/
paintOrder: string
/**
* The fill color of the item.
*/
get fillColor(): Color | null
set fillColor(value: ColorLike | null)
/**
* The fill-rule with which the shape gets filled. Please note that only
* modern browsers support fill-rules other than `'nonzero'`.
*/
fillRule: string
/**
* The shadow color.
*/
get shadowColor(): Color | null
set shadowColor(value: ColorLike | null)
/**
* The shadow's blur radius.
*/
shadowBlur: number
/**
* The shadow's offset.
*/
get shadowOffset(): Point
set shadowOffset(value: PointLike)
/**
* The color the item is highlighted with when selected. If the item does
* not specify its own color, the color defined by its layer is used instead.
*/
get selectedColor(): Color | null
set selectedColor(value: ColorLike | null)
/**
* Item level handler function to be called on each frame of an animation.
* The function receives an event object which contains information about
* the frame event:
*
* @see View#onFrame
*
* @option event.count {Number} the number of times the frame event was
* fired
* @option event.time {Number} the total amount of time passed since the
* first frame event in seconds
* @option event.delta {Number} the time passed in seconds since the last
* frame event
*/
onFrame: Function | null
/**
* The function to be called when the mouse button is pushed down on the
* item. The function receives a {@link MouseEvent} object which contains
* information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseDown
*/
onMouseDown: Function | null
/**
* The function to be called when the mouse position changes while the mouse
* is being dragged over the item. The function receives a {@link
* MouseEvent} object which contains information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseDrag
*/
onMouseDrag: Function | null
/**
* The function to be called when the mouse button is released over the item.
* The function receives a {@link MouseEvent} object which contains
* information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseUp
*/
onMouseUp: Function | null
/**
* The function to be called when the mouse clicks on the item. The function
* receives a {@link MouseEvent} object which contains information about the
* mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onClick
*/
onClick: Function | null
/**
* The function to be called when the mouse double clicks on the item. The
* function receives a {@link MouseEvent} object which contains information
* about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onDoubleClick
*/
onDoubleClick: Function | null
/**
* The function to be called repeatedly while the mouse moves over the item.
* The function receives a {@link MouseEvent} object which contains
* information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseMove
*/
onMouseMove: Function | null
/**
* The function to be called when the mouse moves over the item. This
* function will only be called again, once the mouse moved outside of the
* item first. The function receives a {@link MouseEvent} object which
* contains information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseEnter
*/
onMouseEnter: Function | null
/**
* The function to be called when the mouse moves out of the item.
* The function receives a {@link MouseEvent} object which contains
* information about the mouse event.
* Note that such mouse events bubble up the scene graph hierarchy and will
* reach the view, unless they are stopped with {@link
* Event#stopPropagation()} or by returning `false` from the handler.
*
* @see View#onMouseLeave
*/
onMouseLeave: Function | null
/**
* The function to be called whenever the item is drawn: in views, in
* {@link #rasterize}, and once for each placement of a symbol whose
* definition contains it. It is called right before the item's default
* drawing, and draws with the canvas API beneath it, or replaces it by
* returning `false` or calling `event.preventDefault()`. The function
* receives a {@link DrawEvent} object with these fields:
*
* @option event.item {Item} the item that is drawn
* @option event.context {CanvasRenderingContext2D} the canvas context,
* transformed into the item's coordinates
* @option event.matrix {Matrix} the matrix from the item's coordinates to
* the pixels of the view, without its pixel ratio, for drawing things
* at a size in pixels
* @option event.pixelRatio {Number} the device pixels per pixel: the
* view's pixel ratio, or the resolution divided by 72 in
* {@link #rasterize}
* @option event.view {View} the view drawn into, or `null` in
* {@link #rasterize}
*
* What the handler draws isn't part of the item's hit testing, its bounds
* or its SVG export. In buffered groups, it is only called when the group
* draws its buffer again, see {@link Group#buffered}.
*/
onDraw: Function | null
/**
* The function to be called when the selection of the selected item is
* drawn, over all the content. It is called right before the item's
* default selection drawing, and draws with the canvas API beneath it, or
* replaces it by returning `false` or calling `event.preventDefault()`. The
* function receives a {@link DrawEvent} object with these fields:
*
* @option event.item {Item} the selected item
* @option event.context {CanvasRenderingContext2D} the canvas context, in
* the pixels of the view, with the selection color as its `strokeStyle`
* and `fillStyle`, and a `lineWidth` of 1
* @option event.matrix {Matrix} the matrix from the item's coordinates to
* the pixels of the view
* @option event.size {Number} the size of the handles, see
* {@link PaperScope#settings}
* @option event.color {Color} the selection color, see
* {@link #selectedColor}
* @option event.view {View} the view drawn into
*
* What the handler draws isn't part of the item's hit testing, its bounds
* or its SVG export.
*/
onDrawSelection: Function | null
/**
* The function to be called whenever any item of the class or of its
* subclasses is drawn, as {@link #onDraw} is for a single item, e.g.
* `Path.onDraw` for all paths, including the ones created later. The
* item's own handlers are called first, then the ones of its class and of
* the classes it inherits from, up to `Item`, with `this` set to the item.
* `Path.on('draw', handler)` and `Path.off('draw', handler)` attach and
* detach them too. Only the drawing events can be handled for classes of
* items. Classes are shared by all {@link PaperScope} objects, and so are
* their handlers.
*/
static onDraw: Function | null
/**
* The function to be called when the selection of any selected item of the
* class or of its subclasses is drawn, as {@link #onDrawSelection} is for
* a single item, e.g. `Path.onDrawSelection` for all paths, see
* {@link Item.onDraw}.
*/
static onDrawSelection: Function | null
/**
* Adds an effect at the end of the item's effects.
*
* @param effect - the plain object describing the effect
*
* @return the added instance
*/
addEffect(effect: object): EffectInstance
/**
* Inserts an effect into the item's effects at the given index.
*
* @param index - the index at which to insert the effect
* @param effect - the plain object describing the effect
*
* @return the inserted instance
*/
insertEffect(index: number, effect: object): EffectInstance
/**
* Inserts effects into the item's effects at the given index.
*
* @param index - the index at which to insert the effects
* @param effects - the plain objects describing the effects
*
* @return the inserted instances
*/
insertEffects(index: number, effects: object[]): EffectInstance[]
/**
* Removes the effect at the given index from the item's effects.
*
* @param index - the index of the effect to remove
*
* @return the removed instance, or `null`
*/
removeEffect(index: number): EffectInstance
/**
* Removes the effects from the start index to the end index from the
* item's effects, or all of them.
*
* @param start - the index of the first effect to remove
* @param end - the index after the last one
*
* @return the removed instances
*/
removeEffects(start?: number, end?: number): EffectInstance[]
/**
* Returns what the item's visible effects make of it, in the item's own
* coordinates, outside of the scene graph, or `null` if it has none. It
* is kept until the item, its content, its effects or the registered
* effects change, so changing it isn't tracked.
*
* @return the output of the effects
*/
getEffectOutput(): Item | null
/**
* Sets the properties of the passed object literal on this item to the
* values defined in the object literal, if the item has property of the
* given name (or a setter defined for it).
*
* @return the item itself
*/
set(props: object): this
/**
* Returns the bounds of the given items in project coordinates, as if
* they were grouped, without moving them, e.g. the bounds of the
* selection: `Item.getBounds(project.selectedItems)`. As in groups,
* items that aren't visible or are empty are left out.
*
* @option [options.stroke=false] {Boolean} include the stroke widths,
* as {@link Item#strokeBounds} does
* @option [options.handle=false] {Boolean} include the handles, as
* {@link Item#handleBounds} does
*
* @param items - the items to get the bounds of
* @param options - the kind of bounds
*
* @return the bounds of the items, empty if there are none
*/
static getBounds(items: Item[], options?: { stroke?: boolean, handle?: boolean }): Rectangle
/**
* Clones the item within the same project and places the copy above the
* item.
*
* @option [insert=true] specifies whether the copy should be
* inserted into the scene graph. When set to `true`, it is inserted
* above the original
* @option [deep=true] specifies whether the item's children should also be
* cloned
*
* @return the newly cloned item
*/
clone(options?: object): this
/**
* Copies the content of the specified item over to this item.
*
* @param source - the item to copy the content from
*/
copyContent(source: Item): void
/**
* Copies all attributes of the specified item over to this item. This
* includes its style, visibility, matrix, pivot, blend-mode, opacity,
* selection state, data, name, etc.
*
* @param source - the item to copy the attributes from
* @param excludeMatrix - whether to exclude the transformation
* matrix when copying all attributes
*/
copyAttributes(source: Item, excludeMatrix: boolean): void
/**
* @deprecated use {@link #rasterize} instead.
*/
rasterize(resolution?: number, insert?: boolean): Raster
/**
* Rasterizes the item into a newly created Raster object. The item itself
* is not removed after rasterization.
*
* @option [options.resolution=view.resolution] {Number} the desired
* resolution to be used when rasterizing, in pixels per inch (DPI). If
* not specified, the value of `view.resolution` is used by default.
* @option [options.raster=null] {Raster} specifies a raster to be reused
* when rasterizing. If the raster has the desired size already, then the
* underlying canvas is reused and no new memory needs to be allocated.
* If no raster is provided, a new raster item is created and returned
* instead.
* @option [options.insert=true] {Boolean} specifies whether the raster
* should be inserted into the scene graph. When set to `true`, it is
* inserted above the rasterized item.
*
* @param options - the rasterization options
*
* @return the reused raster or the newly created raster item
*/
rasterize(options?: { resolution?: number, raster?: Raster, insert?: boolean }): Raster
/**
* Checks whether the item's geometry contains the given point.
*
* @param point - the point to check for
*/
contains(point: PointLike): boolean
/**
* Checks whether the item's geometry contains the given point.
*
* @param point - the point to check for
*/
contains(x: number, y: number): boolean
/**
* @param rect - the rectangle to check against
*/
isInside(rect: RectangleLike): boolean
/**
* Checks whether the item overlaps with the given item: whether their
* outlines cross, or one contains the other, as
* {@link Rectangle#intersects} does for rectangles. Items other than
* paths and shapes are checked through their bounds. To only check whether
* outlines cross, use {@link PathItem#getIntersections}.
*
* @param item - the item to check against
*
* @return true if the items overlap
*/
intersects(item: Item): boolean
/**
* Performs a hit-test on the item and its children (if it is a {@link
* Group} or {@link Layer}) at the location of the specified point,
* returning the first found hit.
*
* The options object allows you to control the specifics of the hit-test.
* Without options, `fill`, `stroke` and `segments` are hit-tested. As soon
* as an options object is passed, only the hit-tests that it sets to `true`
* are performed. It may contain a combination of the following values:
*
* @option [options.tolerance={@link PaperScope#settings}.hitTolerance]
* {Number} the tolerance of the hit-test, in project coordinates
* @option options.class {Function} only hit-test against a specific item
* class, or any of its sub-classes, by providing the constructor
* function against which an `instanceof` check is performed:
* {@values Group, Layer, Path, CompoundPath, Shape, Raster,
* SymbolItem, PointText, ...}
* @option options.match {Function} a match function to be called for each
* found hit result: Return `true` to return the result, `false` to keep
* searching
* @option options.fill {Boolean} hit-test the fill of items
* @option options.stroke {Boolean} hit-test the stroke of path items,
* taking into account the setting of stroke color and width
* @option options.segments {Boolean} hit-test for {@link Segment#point} of
* {@link Path} items
* @option options.curves {Boolean} hit-test the curves of path items,
* without taking the stroke color or width into account
* @option options.handles {Boolean} hit-test for the handles ({@link
* Segment#handleIn} / {@link Segment#handleOut}) of path segments.
* @option options.ends {Boolean} only hit-test for the first or last
* segment points of open path items
* @option options.position {Boolean} hit-test the {@link Item#position} of
* of items, which depends on the setting of {@link Item#pivot}
* @option options.center {Boolean} hit-test the {@link Rectangle#center} of
* the bounding rectangle of items ({@link Item#bounds})
* @option options.bounds {Boolean} hit-test the corners and side-centers of
* the bounding rectangle of items ({@link Item#bounds})
* @option options.guides {Boolean} only hit-test items that have {@link
* Item#guide} set to `true`
* @option options.selected {Boolean} only hit selected items
*
* @param point - the point where the hit-test should be performed
* (in global coordinates system).
*
* @return a hit result object describing what exactly was hit
* or `null` if nothing was hit
*/
hitTest(point: PointLike, options?: { tolerance?: number, class?: Function, match?: Function, fill?: boolean, stroke?: boolean, segments?: boolean, curves?: boolean, handles?: boolean, ends?: boolean, position?: boolean, center?: boolean, bounds?: boolean, guides?: boolean, selected?: boolean }): HitResult
/**
* Performs a hit-test on the item and its children (if it is a {@link
* Group} or {@link Layer}) at the location of the specified point,
* returning all found hits.
*
* The options object allows you to control the specifics of the hit-
* test. See {@link #hitTest} for a list of all options.
*
* @see #hitTest(point[, options]);
*
* @param point - the point where the hit-test should be performed
* (in global coordinates system).
*
* @return hit result objects for all hits, describing what
* exactly was hit or `null` if nothing was hit
*/
hitTestAll(point: PointLike, options?: { tolerance?: number, class?: Function, match?: Function, fill?: boolean, stroke?: boolean, segments?: boolean, curves?: boolean, handles?: boolean, ends?: boolean, position?: boolean, center?: boolean, bounds?: boolean, guides?: boolean, selected?: boolean }): HitResult[]
/**
* Checks whether the item matches the criteria described by the given
* object, by iterating over all of its properties and matching against
* their values through {@link #matches}.
*
* See {@link Project#getItems} for a selection of illustrated
* examples.
*
* @see #getItems(options)
*
* @param options - the criteria to match against
*
* @return true if the item matches all the criteria
*/
matches(options: object | Function): boolean
/**
* Checks whether the item matches the given criteria. Extended matching is
* possible by providing a compare function or a regular expression.
* Matching points, colors only work as a comparison of the full object, not
* partial matching (e.g. only providing the x-coordinate to match all
* points with that x-value). Partial matching does work for
* {@link Item#data}.
*
* See {@link Project#getItems} for a selection of illustrated
* examples.
*
* @see #getItems(options)
*
* @param name - the name of the state to match against
* @param compare - the value, function or regular expression to
* compare against
*
* @return true if the item matches the state
*/
matches(name: string, compare: object): boolean
/**
* Fetch the descendants (children or children of children) of this item
* that match the properties in the specified object. Extended matching is
* possible by providing a compare function or regular expression. Matching
* points, colors only work as a comparison of the full object, not partial
* matching (e.g. only providing the x- coordinate to match all points with
* that x-value). Partial matching does work for {@link Item#data}.
*
* Matching items against a rectangular area is also possible, by setting
* either `options.inside` or `options.overlapping` to a rectangle
* describing the area in which the items either have to be fully or partly
* contained.
*
* See {@link Project#getItems} for a selection of illustrated
* examples.
*
* @see #matches(options)
*
* @option [options.recursive=true] {Boolean} whether to loop recursively
* through all children, or stop at the current level
* @option options.match {Function} a match function to be called for each
* item, allowing the definition of more flexible item checks that are
* not bound to properties. If no other match properties are defined,
* this function can also be passed instead of the `options` object
* @option options.class {Function} the constructor function of the item
* type to match against
* @option options.inside {Rectangle} the rectangle in which the items need
* to be fully contained
* @option options.overlapping {Rectangle} the rectangle with which the
* items need to at least partly overlap
*
* @param options - the criteria to match against
*
* @return the list of matching descendant items, in their
* stacking order from bottom to top, with each item listed before its
* own descendants
*/
getItems(options: object | Function): Item[]
/**
* Fetch the first descendant (child or child of child) of this item
* that matches the properties in the specified object.
* Extended matching is possible by providing a compare function or
* regular expression. Matching points, colors only work as a comparison
* of the full object, not partial matching (e.g. only providing the x-
* coordinate to match all points with that x-value). Partial matching
* does work for {@link Item#data}.
* See {@link Project#getItems} for a selection of illustrated
* examples.
*
* @see #getItems(options)
*
* @param options - the criteria to match against
*
* @return the first descendant item matching the given criteria
*/
getItem(options: object | Function): Item
/**
* Exports (serializes) the item with its content and child items to a JSON
* data string.
*
* @option [options.asString=true] {Boolean} whether the JSON is returned as
* a `Object` or a `String`
* @option [options.precision=5] {Number} the amount of fractional digits in
* numbers used in JSON data
*
* @param options - the serialization options
*
* @return the exported JSON data
*/
exportJSON(options?: { asString?: boolean, precision?: number }): string
/**
* Imports (deserializes) the stored JSON data into this item. If the data
* describes an item of the same class or a parent class of the item, the
* data is imported into the item itself. If not, the imported item is added
* to this item's {@link Item#children} list. Note that not all type of
* items can have children.
*
* @param json - the JSON data to import from
*/
importJSON(json: string): Item
/**
* Exports the item with its content and child items as an SVG DOM. With
* `options.bounds` or `options.matrix`, the item is wrapped in an `