Package Exports
- transformersjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (transformersjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
transformers
Lightweight zero-dependency transformation matrix utilities
Why
Perform transformation matrix calculation in a 2D plane. Use this library to:
- Create a transformation matrix and manipulate it via translation, rotation, scale, shear, skew
- Parse a transformation in string format,
translate(10 20) rotate(30)
- Obtain a point after applying transformation
- Obtain matrix in string format to be used in CSS or SVG
Install
npm install transformersjs
Usage
Initialize a matrix
var transformers = require('transformers');
var mat = transformers();
//OR
var mat = transformers({ a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 });
mat.matrix; // { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
Parse transformation in string
var transformers = require('transformers');
var mat = transformers('translate(10, 15) rotate(30)');
//OR
var mat = transformers().translate(10, 15).rotate(30);
mat.matrix; //{ a: 1, b: 0, c: 0, d: 1, e: 10, f: 15 }
Obtain a point after applying transformations
var transformers = require('transformers');
var mat = transformers('translate(10, 15)');
mat.pointTo(8, 5); // { x: 18, y: 20 }
Convert matrix to string to be used in CSS or SVG
var transformers = require('transformers');
var mat = transformers('translate(10, 15)');
mat.render(); // matrix(1,0,0,1,10,15)
API
transformers : object
Initializer to create a matrix instance
Kind: global namespace
Param | Type | Description |
---|---|---|
[input] | string | object | array |
Can be a transformation in string, object, array notation |
- transformers :
object
transformers.multiply(matrix) ⇒ transformers
Perform matrix multiplication
Kind: static method of transformers
Param | Type | Description |
---|---|---|
matrix | object | array | transformers |
matrix to be multiplied |
transformers.parse(str) ⇒ transformers
Parse a valid string containing various transformations
Kind: static method of transformers
Param | Type |
---|---|
str | string |
transformers.translate(x, [y]) ⇒ transformers
Perform translation
Kind: static method of transformers
Param | Type | Default | Description |
---|---|---|---|
x | number |
translation along x-axis | |
[y] | number |
0 |
translation along y-axis |
transformers.rotate(angle, [x], [y]) ⇒ transformers
Perform rotation
Kind: static method of transformers
Param | Type | Description |
---|---|---|
angle | number |
angle in degree |
[x] | number |
rotation along a point in x-axis |
[y] | number |
rotation along a point in y-axis |
transformers.scale(x, [y]) ⇒ transformers
Perform scaling
Kind: static method of transformers
Param | Type | Default | Description |
---|---|---|---|
x | number |
scaling along x-axis | |
[y] | number |
x |
scaling along y-axis |
transformers.shear(x, y) ⇒ transformers
Perform shear
Kind: static method of transformers
Param | Type | Description |
---|---|---|
x | number |
shear along x-axis |
y | number |
shear along y-axis |
transformers.skew(x, y) ⇒ transformers
Perform skew
Kind: static method of transformers
Param | Type | Description |
---|---|---|
x | number |
skew along x-axis |
y | number |
skew along y-axis |
transformers.inverse() ⇒ transformers
Inverse current matrix
Kind: static method of transformers
transformers.pointTo([x], [y]) ⇒ Object
Obtain a point after applying transformation
Kind: static method of transformers
Param | Type | Default |
---|---|---|
[x] | number |
0 |
[y] | number |
0 |
transformers.render() ⇒ string
Converts current matrix to string format to be used in CSS or SVG
Kind: static method of transformers