Note: this is a work in progress.
A polyfill for the DOM Geometry Interfaces Level 1 for JavaScript runtimes that don’t include them.
domgeom is available as an npm package:
npm install --save domgeomimport {
DOMMatrix,
DOMMatrixReadOnly,
DOMPoint,
DOMPointReadOnly,
DOMRect,
DOMRectReadOnly,
DOMQuad
} from 'domgeom';
Object.assign(globalThis, {
DOMMatrix,
DOMMatrixReadOnly,
DOMPoint,
DOMPointReadOnly,
DOMRect,
DOMRectReadOnly,
DOMQuad
});DOMMatrixReadOnly.prototype.toString()throws anErrorinstead of an"InvalidStateError" DOMException.- The read-only interfaces are not actually read only (it just seemed tedious to implement).
- Strings get parsed according to the
<transform-list>CSS syntax in theDOMMatrix()andDOMMatrixReadOnly(), as well as inDOMMatrix.prototype.setMatrixValue(), instead of throwing. However, the parser is looser than its browser counterpart, and ignores most<length>units (e.g.10pxis interpreted as10). Percentages are always resolved tovalue/100.
Also note that due to numerical errors there may be slight differences in the matrix values compared to browser environments. In tests, rounding the values before comparisons is recommended.
- CSS Transforms Level 2: Mathematical Description of Transform Functions
- CSS tokenization code is taken from Selery.