package
Parse and compose CSS or SVG 2D transform lists into affine matrices and transform points
npm install unifiedtransformGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
53.8 kB
Includes dependencies.
UnifiedTransform.js is published as unifiedtransform. It parses and composes two-dimensional CSS/SVG transform operations into one affine matrix and can apply that matrix to points.
Use it to flatten nested 2D transforms, combine generated transform fragments, or convert between CSS and matrix layouts. Use DOMMatrix when the target runtime provides it and browser-native integration is desired, or a 3D matrix library for perspective and three-dimensional transforms.
<div style="transform: translate(15px, 400px) scale(0.3);">
<div style="transform: rotate(85deg);">
<div style="transform: translateY(100px) rotate(33deg);">rawr</div>
</div>
</div>Then apply UnifiedTransform.js:
import UnifiedTransform from 'unifiedtransform';
const cm = new UnifiedTransform();
cm.transform('translate(15px, 400px) scale(0.3)');
cm.rotate(85);
cm.transform('translateY(100px) rotate(33deg)');
document.getElementById('newDom').style.transform = cm.toTransformString();Which simplifies the HTML to:
<div id="newDom">rawr</div>Methods are applied in call order and mutate the same UnifiedTransform instance.
import UnifiedTransform from 'unifiedtransform';
const transform = new UnifiedTransform()
.translate(10, 20)
.scale(2);
console.log(transform.eval(1, 1)); // [12, 22]
console.log(transform.toMatrix('CSS')); // [2, 0, 0, 2, 10, 20]
console.log(transform.toTransformString()); // "matrix(2, 0, 0, 2, 10, 20)"Changing the call order changes the result. eval() returns a new two-element array and does not mutate its arguments.
Numeric rotate() arguments are degrees. String rotations accept deg or rad; translations accept pixel strings.
import UnifiedTransform from 'unifiedtransform';
const transform = new UnifiedTransform()
.transform('translate(10px, 20px) rotate(90deg)');
console.log(transform.eval(1, 0).map((value) => +value.toFixed(12)));
// [10, 21]The parser supports matrix, translate, translateX, translateY, scale, rotate, skewX, and skewY. Unsupported functions such as 3D or perspective transforms are ignored.
The optional second and third arguments to rotate() define the rotation center.
import UnifiedTransform from 'unifiedtransform';
const transform = new UnifiedTransform().rotate(90, 5, 5);
console.log(transform.eval(6, 5).map((value) => +value.toFixed(12)));
// [5, 6]All transformation methods mutate and return the receiver for chaining. There is no clone method; create a new instance before building an independent transform.
Parses a transform string and applies each transformation one after the other
Specifies a 2D translation by the vector (tx, ty)
Specifies a 2D scale operation by the (sx, sy) scaling vector described by the 2 parameters. If the second parameter is omitted, the scaling is applied symmetrically.
Specifies a 2D rotation by the angle specified in the parameter about the origin of the element or optionally the given point (x, y)
Specifies a 2D skew transformation along the X axis by the given angle.
Specifies a 2D skew transformation along the Y axis by the given angle.
Specifies a 2D transformation in the form of a transformation matrix. With
order="CSS" (default) a 6 element array [a, b, c, d, x, y] is expectedorder="2D" a 3x3 array is expectedorder="flat" a 9 element array in classic row format is expectedEvaluates a point using the current transformation matrix and returns the new point
Gets the transform matrix of the current homogeneous transformation. With
order="flat" (default) a flat 9 element array in the classic row format is returnedorder="2D" a 3x3 array is returnedorder="CSS" a 6 element array [a, b, c, d, x, y] is returnedGets a CSS transform string to apply the current matrix
You can install UnifiedTransform.js via npm:
npm install unifiedtransformOr with yarn:
yarn add unifiedtransformAlternatively, download or clone the repository:
git clone https://github.com/rawify/UnifiedTransform.jsconst UnifiedTransform = require('unifiedtransform');
const transform = new UnifiedTransform();import UnifiedTransform, { UnifiedTransform as NamedUnifiedTransform } from 'unifiedtransform';
const transform = new UnifiedTransform();<script src="https://cdn.jsdelivr.net/npm/unifiedtransform@0.5.0/dist/unifiedtransform.min.js"></script>
<script>
const transform = new UnifiedTransform();
</script><script type="module">
import UnifiedTransform from 'https://cdn.jsdelivr.net/npm/unifiedtransform@0.5.0/dist/unifiedtransform.mjs';
const transform = new UnifiedTransform();
</script>The package has no runtime dependencies and supports Node.js 20 or newer.
CommonJS consumers can use the direct class export as well as its .default and
.UnifiedTransform aliases. These compatibility paths are covered by the test
suite and are part of the supported API.
The implementation is written in strict TypeScript. The build emits CommonJS, ES modules, a standalone browser bundle, source maps, and format-specific type declarations without modifying source or documentation files.
After cloning the Git repository, run:
npm install
npm run buildTesting the source against the shipped test suite is as easy as
npm run testCopyright (c) 2026, Robert Eisele Licensed under the MIT license.