This library will parse the matrix transformation of the element into the following properties: scale, translate, rotate, skew. Interface allows to change these properties and generate a matrix from them that will update the transform property. The library also parses and allows you to change the transform-origin property using a special interface.
Has the following constructor signature:
new Transform(node, options?)
node [HTMLElement|SVGElement] element with which transformations will be performed. Required parameter.
options [Object] described in options. Optional parameter.
npm install @hooked74/transform
import Transform from "@hooked/transform";
// Use Transformation for HTMLElement
const transform = new Transform(htmlElement);
transform.origin = { x: 1, y: 0.5 };
transform.scaleX = 2;
// Use Transformation for SVGElement
const transform = new Transform(svgElement);
transform.originX = 0.5;
transform.y = 100;
import Transform from "@hooked/transform";
class Entity extends Transform {
constructor(node) {
super(node);
}
// ...
}
const entity = new Entity(htmlElement);
entity.origin = { x: 0.5, y: 0.5 };
entity.angle = 10;
Transform has the following options:
This option provides the ability to generate a matrix that will be composed of properties in a given order. By default this order:
["skew", "scale", "rotate", "translate"]
This order was selected empirically.
Available orders:
[
["rotate", "scale", "translate", "skew"],
["rotate", "scale", "skew", "translate"],
["rotate", "skew", "scale", "translate"],
["rotate", "skew", "translate", "scale"],
["rotate", "translate", "skew", "scale"],
["rotate", "translate", "scale", "skew"],
["scale", "rotate", "translate", "skew"],
["scale", "rotate", "skew", "translate"],
["scale", "skew", "rotate", "translate"],
["scale", "skew", "translate", "rotate"],
["scale", "translate", "skew", "rotate"],
["scale", "translate", "rotate", "skew"],
["skew", "rotate", "scale", "translate"],
["skew", "rotate", "translate", "scale"],
["skew", "scale", "rotate", "translate"],
["skew", "scale", "translate", "rotate"],
["skew", "translate", "rotate", "scale"],
["skew", "translate", "scale", "rotate"],
["translate", "rotate", "scale", "skew"],
["translate", "rotate", "skew", "scale"],
["translate", "skew", "rotate", "scale"],
["translate", "skew", "scale", "rotate"],
["translate", "scale", "skew", "rotate"],
["translate", "scale", "rotate", "skew"]
]
Allow to change the width of the element. Return the width of the element in pixels.
Allow to change the height of the element. Return the height of the element in pixels.
Allow to change the transformation property of the element. Return value in transformation matrix format.
Allow to change transform-origin of the element. Return the value of transform-origin in the format Xpx Ypx.
Change the state of rotate. The main property of the state is the angle of rotation. Return rotate state.
Element rotation angle. Limited to values from 0 to 360.
Change the state of scale. The main properties of the state is the scale x and scale y. Return scale state.
Element scaling by X. Limited to values from 0 to 1 where 1 is 100%.
Element scaling by Y. Limited to values from 0 to 1 where 1 is 100%.
Change the state of skew. The main properties of the state is the skew x and skew y. Return skew state.
Element skewing by X. Value in degrees.
Element skewing by Y. Value in degrees.
Change the state of translate. The main properties of the state is the translate x and translate y. Return translate state.
Element offset by X.
Element offset by Y.
Change the state of origin. The main properties of the state is the origin x and origin y. Return origin state.
Set the X coordinate relative to which the element will be transformed.
Set the Y coordinate relative to which the element will be transformed.
Get element style property.
Set element style property.
Force update transformation. Itβs not worth using without need, since it is called automatically when the class properties change. If isOrigin is true then updates transform-origin otherwise transform.
You can run some built-in commands:
Builds the app for production. Your app is ready to be deployed.
Runs the test watcher in an interactive mode. By default, runs tests related to files changed since the last commit.