import { constructors } from '../core/library.js';
import { mergeOver } from '../core/utilities.js';
import baseMix from '../mixin/base.js';
import shapeMix from '../mixin/shapeBasic.js';A factory for generating shape-based entitys from SVG path Strings
Path-defined entitys represent a diverse range of shapes rendered onto a DOM <canvas> element using the Canvas API’s Path2D interface. They use the shapeBasic and shapePathCalculation (some also use shapeCurve) mixins to define much of their functionality.
All path-defined entitys can be positioned, cloned, filtered etc:
scale instead.A path is a track - straight, or curved, or as complex as required - placed across a container which artefacts can use as a source of their positioning data. We can animate an artifact to move along the path:
useAsPath flag to true.path attribute to the path-defined entity’s name-String (or the entity itself), and set its lockTo Array values to "path".pathPosition attribute to a float Number value between 0.0 - 1.0, with 0 being the start of the path, and 1 being its end.addPathRotation flag to true.delta object, or triggering a Tween to perform the movement.import { constructors } from '../core/library.js';
import { mergeOver } from '../core/utilities.js';
import baseMix from '../mixin/base.js';
import shapeMix from '../mixin/shapeBasic.js';const Shape = function (items = {}) {
this.shapeInit(items);
return this;
};let P = Shape.prototype = Object.create(Object.prototype);
P.type = 'Shape';
P.lib = 'entity';
P.isArtefact = true;
P.isAsset = false;P = baseMix(P);
P = shapeMix(P);No additional attributes defined here.
let defaultAttributes = {};
P.defs = mergeOver(P.defs, defaultAttributes);cleanSpecies - internal helper function - called by prepareStamp
P.cleanSpecies = function () {
this.dirtySpecies = false;
};
P.cleanStampHandlePositionsAdditionalActions = function () {
let box = this.localBox,
stampHandle = this.currentStampHandlePosition;
stampHandle[0] += box[0];
stampHandle[1] += box[1];
};Accepts argument with attributes:
pathDefinition (required) - an SVG d attribute Stringscrawl.makeShape({
name: 'myArrow',
pathDefinition: 'M266.2,703.1 h-178 L375.1,990 l287-286.9 H481.9 C507.4,365,683.4,91.9,911.8,25.5 877,15.4,840.9,10,803.9,10 525.1,10,295.5,313.4,266.2,703.1 z',
startX: 300,
startY: 200,
handleX: '50%',
handleY: '50%',
scale: 0.2,
scaleOutline: false,
fillStyle: 'lightgreen',
method: 'fill',
});
const makeShape = function (items) {
return new Shape(items);
};
constructors.Shape = Shape;export {
makeShape,
};