A Clip is a collection of items, similar to a Group. But instead of automatically passing on transformations to its children by calling Item#applyMatrix(), the transformations are stored in the internal matrix.
The type of the item as a string.
The name of the item. If the item has a name, it can be accessed by name through its parent's children list.
Example
Specifies whether the item is visible. When set to false, the item won't be drawn.
Example — Hiding an item:
The blend mode of the item.
Example — Setting an item's blend mode:
The opacity of the item as a value between 0 and 1.
Example — Making an item 50% transparent:
Specifies whether an item is selected and will also return true if the item is partially selected (groups with some 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 also: project.selectedItems, segment.selected, point.selected
Example — Selecting an item:
Specifies whether the item defines a clip mask. This can only be set on paths, compound paths, and text frame objects, and only if the item is already contained within a clipping group.
A plain javascript object which can be used to store arbitrary data on the item.
Example
var path = new Path(); path.data.remember = 'milk';
Example
var path = new Path(); path.data.malcolm = new Point(20, 30); console.log(path.data.malcolm.x); // 20
Example
var path = new Path(); path.data = { home: 'Omicron Theta', found: 2338, pets: ['Spot'] }; console.log(path.data.pets.length); // 1
Example
var path = new Path({ data: { home: 'Omicron Theta', found: 2338, pets: ['Spot'] } }); console.log(path.data.pets.length); // 1
The item's position within the project. This is the rectangle.center of the item's bounds rectangle.
Example — Changing the position of a path:
Example — Changing the x coordinate of an item's position:
The bounding rectangle of the item including stroke width.
The bounding rectangle of the item including handles.
The item that this item is contained within.
Example
var path = new Path(); // New items are placed in the active layer: console.log(path.parent == project.activeLayer); // true var group = new Group(); group.addChild(path); // Now the parent of the path has become the group: console.log(path.parent == group); // true
Example — Setting the parent of the item to another item
var path = new Path(); // New items are placed in the active layer: console.log(path.parent == project.activeLayer); // true var group = new Group(); group.parent = path; // Now the parent of the path has become the group: console.log(path.parent == group); // true // The path is now contained in the children list of group: console.log(group.children[0] == path); // true
Example — Setting the parent of an item in the constructor
var group = new Group(); var path = new Path({ parent: group }); // The parent of the path is the group: console.log(path.parent == group); // true // The path is contained in the children list of group: console.log(group.children[0] == path); // true
The children items contained within this item. Items that define a name can also be accessed by name.
Please note: The children array should not be modified directly using array functions. To remove single items from the children list, use item.remove(), to remove all items from the children list, use item.removeChildren(). To add items to the children list, use item.addChild(item) or item.insertChild(index, item).
Example — Accessing items in the children array:
Example — Accessing children by name:
Example — Passing an array of items to item.children:
The first item contained within this item. This is a shortcut for accessing item.children[0].
The next item on the same level as this item.
The previous item on the same level as this item.
The width of the stroke.
Example — Setting an item's stroke width:
The shape to be used at the corners of paths when they have a stroke.
Example — A look at the different stroke joins:
The dash offset of the stroke.
Specifies an array containing the dash and gap lengths of the stroke.
Example
The miter limit of the stroke.
When two line segments meet at a sharp angle and miter joins have been specified for item.strokeJoin, it is possible for the miter to extend far beyond the item.strokeWidth of the path. The miterLimit imposes a limit on the ratio of the miter length to the item.strokeWidth.
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:
event.count: the number of times the frame event was fired.
event.time: the total amount of time passed since the first frame event in seconds.
event.delta: the time passed in seconds since the last frame event.
See also: view.onFrame
Example — Creating an animation:
The function to be called when the mouse button is pushed down on the item. The function receives a MouseEvent object which contains information about the mouse event.
Example — Press the mouse button down on the circle shaped path, to make it red:
Example — Press the mouse on the circle shaped paths to remove them:
The function to be called when the mouse button is released over the item.
The function receives a MouseEvent object which contains information about the mouse event.
Example — Release the mouse button over the circle shaped path, to make it red:
The function to be called when the mouse clicks on the item. The function receives a MouseEvent object which contains information about the mouse event.
Example — Click on the circle shaped path, to make it red:
Example — Click on the circle shaped paths to remove them:
The function to be called when the mouse double clicks on the item. The function receives a MouseEvent object which contains information about the mouse event.
Example — Double click on the circle shaped path, to make it red:
Example — Double click on the circle shaped paths to remove them:
The function to be called repeatedly when the mouse moves on top of the item. The function receives a MouseEvent object which contains information about the mouse event.
Example — Move over the circle shaped path, to change its opacity:
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 MouseEvent object which contains information about the mouse event.
Example — When you move the mouse over the item, its fill color is set to red. When you move the mouse outside again, its fill color is set back to black.
Example — When you click the mouse, you create new circle shaped items. When you move the mouse over the item, its fill color is set to red. When you move the mouse outside again, its fill color is set back to black.
The function to be called when the mouse moves out of the item.
The function receives a MouseEvent object which contains information about the mouse event.
Example — Move the mouse over the circle shaped path and then move it out of it again to set its fill color to red:
Sets those 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).
Example — Setting properties through an object literal
Checks whether the item and all its parents are inserted into the DOM or not.
When passed a project, copies the item to the project, or duplicates it within the same project. When passed an item, copies the item into the specified item.
Rasterizes the item into a newly created Raster object. The item itself is not removed after rasterization.
Example — Rasterizing an item:
Checks wether the item's geometry contains the given point.
Example — Click within and outside the star below Create a star shaped path:
Perform a hit test on the item (and its children, if it is a Group or Layer) at the location of the specified point.
The optional options object allows you to control the specifics of the hit test and may contain a combination of the following values:
tolerance: Number - The tolerance of the hit test in points.
options.type: Only hit test again a certain item type: PathItem, Raster, TextItem, etc.
options.fill: Boolean - Hit test the fill of items.
options.stroke: Boolean - Hit test the curves of path items, taking into account stroke width.
options.segment: Boolean - Hit test for segment.point of Path items.
options.handles: Boolean - Hit test for the handles (segment.handleIn / segment.handleOut) of path segments.
options.ends: Boolean - Only hit test for the first or last segment points of open path items.
options.bounds: Boolean - Hit test the corners and side-centers of the bounding rectangle of items (item.bounds).
options.center: Boolean - Hit test the rectangle.center of the bounding rectangle of items (item.bounds).
options.guides: Boolean - Hit test items that have Item#guide set to true.
options.selected: Boolean - Only hit selected items.
Adds the specified item as a child of this item at the end of the its children list. You can use this function for groups, compound paths and layers.
Adds the specified items as children of this item at the end of the its children list. You can use this function for groups, compound paths and layers.
Inserts this item above the specified item.
Inserts this item below the specified item.
Sends this item to the back of all other items within the same parent.
Brings this item to the front of all other items within the same parent.
Inserts the specified item as a child of this item by appending it to the list of children and moving it below all other children. You can use this function for groups, compound paths and layers.
Removes the item from the project. If the item has children, they are also removed.
Removes the children from the specified from index to the to index from the parent's children array.
Reverses the order of the item's children
Checks if the item contains any children items.
Checks if this item is above the specified item in the stacking order of the project.
Checks if the item is below the specified item in the stacking order of the project.
Checks whether the specified item is the parent of the item.
Checks whether the specified item is a child of the item.
Checks if the item is contained within the specified item.
Checks if the item is an ancestor of the specified item.
Checks whether the item is grouped with the specified item.
Scales the item by the given value from its center point, or optionally from a supplied point.
Example — Scaling an item from its center point:
Example — Scaling an item from a specific point:
Scales the item by the given values from its center point, or optionally from a supplied point.
Example — Scaling an item horizontally by 300%:
Translates (moves) the item by the given offset point.
Rotates the item by a given angle around the given point.
Angles are oriented clockwise and measured in degrees.
See also: matrix.rotate
Example — Rotating an item:
Example — Rotating an item around a specific point:
Shears the item by the given value from its center point, or optionally by a supplied point.
See also: matrix.shear
Shears the item by the given values from its center point, or optionally by a supplied point.
See also: matrix.shear
Transform the item.
Transform the item so that its bounds fit within the specified rectangle, without changing its aspect ratio.
Example — Fitting an item to the bounding rectangle of another item's bounding rectangle:
Example — Fitting an item to the bounding rectangle of another item's bounding rectangle with the fill parameter set to true:
Example — Fitting an item to the bounding rectangle of the view
Attach an event handler to the item.
Example — Change the fill color of the path to red when the mouse enters its shape and back to black again, when it leaves its shape.
Attach one or more event handlers to the item.
Example — Change the fill color of the path to red when the mouse enters its shape and back to black again, when it leaves its shape.
Example — When you click the mouse, you create new circle shaped items. When you move the mouse over the item, its fill color is set to red. When you move the mouse outside again, its fill color is set black.
Detach an event handler from the item.
Detach one or more event handlers to the item.
Fire an event on the item.
Check if the item has one or more event handlers of the specified type.
Removes the item when the events specified in the passed object literal occur.
The object literal can contain the following values:
Remove the item when the next tool.onMouseMove event is fired: object.move = true
Remove the item when the next tool.onMouseDrag event is fired: object.drag = true
Remove the item when the next tool.onMouseDown event is fired: object.down = true
Remove the item when the next tool.onMouseUp event is fired: object.up = true
Example — Click and drag below:
Removes the item when the next tool.onMouseMove event is fired.
Example — Move your mouse below:
Removes the item when the next tool.onMouseDown event is fired.
Example — Click a few times below:
Removes the item when the next tool.onMouseUp event is fired.
Example — Click a few times below:
Exports the item and all its children as an SVG DOM, all contained in one top level SVG node.
Converts the passed node node into a Paper.js item and adds it to the children of this item.
Creates a new Group item and places it at the top of the active layer.
Example — Create a group containing two paths:
Example — Click in the view to add a path to the group, which in turn is rotated every frame:
Creates a new Group item and places it at the top of the active layer.
Example
Copyright © 2011 Jürg Lehni & Jonathan Puckey. All Rights Reserved.