Creates a Stroke from the given parts. All parts should have the
same color.
OptionalinitialZIndex: numberProtectedcontentBBoxThe bounding box of this component.
getBBox, by default, returns contentBBox.
This must be set by components.
If this changes, EditorImage.queueRerenderOf should be called for this object (provided that this object has been added to the editor.)
Note: This value is ignored if getSizingMode returns FillScreen
or FillImage.
ProtectedlastThe timestamp (milliseconds) at which the component was last changed (i.e. created/translated).
ProtectedapplyAttach data that can be used while exporting the component (e.g. to SVG).
This is intended for use by an ImageLoader.
Returns a copy of this component.
ProtectedcreateComponent-specific implementation of clone.
Set the style of this component in a way that can't be undone/redone (does not create a command).
Prefer updateStyle(style).apply(editor).
A list of the parts that make up this path. Many paths only have one part.
Each part (a RenderablePathSpec) contains information about the style and geometry
of that part of the stroke. Use the .path property to do collision detection and other
operations involving the stroke's geometry.
Note that many of Path's methods (e.g. Path.intersection) take a
strokeWidth parameter that can be gotten from RenderablePathSpec.style .stroke.width.
the Path.union of all paths that make up this stroke.
Returns information about how this component should be displayed (e.g. fill the screen or get its size from getBBox).
EditorImage.queueRerenderOf must be called to apply changes to the output of this method if this component has already been added to an EditorImage.
a partial representation of this component's style.
true if lineSegment intersects this component.
true if this component intersects rect -- it is entirely contained
within the rectangle or one of the rectangle's edges intersects this component.
The default implementation assumes that this.getExactBBox() returns a tight bounding box
-- that any horiziontal/vertical line that intersects this' boounding box also
intersects a point in this component. If this is not the case, components must override
this function.
Called when this component is added to the given image.
Renders this component onto the given canvas.
If visibleRect is given, it should be the region of canvas that is visible --
rendering anything outside of visibleRect should have no visible effect on the
resultant image.
For optimal performance, implementers should call canvas.startObject and canvas.endObject
before and after rendering.
OptionalvisibleRect: Rect2Convert the component to an object that can be passed to
JSON.stringify.
Do not rely on the output of this function to take a particular form — this function's output can change form without a major version increase.
ProtectedserializeReturns a command that updates this component's z-index.
Returns a command that, when applied, transforms this by [affineTransfm] and updates the editor.
The transformed component is also moved to the top (use AbstractComponent#setZIndexAndTransformBy to avoid this behavior).
Returns a Command that updates portions of this component's style
to the given style.
StaticdeserializeConvert a string or an object produced by JSON.parse into an AbstractComponent.
StaticfromStaticfromCreates a new Stroke from a Path and style. Strokes created
with this method have transparent fill.
Example:
import { Editor, Stroke, Color4 } from 'js-draw';
const editor = new Editor(document.body);
---visible---
const stroke = Stroke.fromStroked('m0,0 l10,10', { width: 10, color: Color4.red });
editor.dispatch(editor.image.addComponent(stroke));
Notice that path can be a string that specifies an SVG path
StaticregisterStore the deserialization callback (or lack of it) for [componentKind]. If components are registered multiple times (as may be done in automated tests), the most recent deserialization callback is used.
Represents an AbstractComponent made up of one or more Paths.
Example
For some Editor editor and
Strokestroke,Restyling:
Transforming:
Adding:
import { Editor, EditorImage, Stroke, Path, Color4, } from 'js-draw'; const editor = new Editor(document.body); const stroke = Stroke.fromFilled( Path.fromString('m0,0 l100,100 l0,-10 z'), Color4.red, ); editor.dispatch(EditorImage.addComponent(stroke));