Skip to content

Commit

Permalink
Add custom inspect for DOMMatrix
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Feb 19, 2024
1 parent 28b1283 commit 611f8e1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-sloths-move.md
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Add custom inspect for `DOMMatrix`
12 changes: 12 additions & 0 deletions packages/runtime/src/dommatrix.ts
Expand Up @@ -2,6 +2,7 @@
// Ref: https://github.com/Automattic/node-canvas/blob/master/lib/DOMMatrix.js
import { $ } from './$';
import { def, proto, stub } from './utils';
import { inspect } from './inspect';
import { DOMPoint, type DOMPointInit } from './dompoint';

const DEGREE_PER_RAD = 180 / Math.PI;
Expand Down Expand Up @@ -237,6 +238,17 @@ export class DOMMatrixReadOnly implements globalThis.DOMMatrixReadOnly {
$.dommatrixROInitClass(DOMMatrixReadOnly);
def(DOMMatrixReadOnly);

Object.defineProperty(DOMMatrixReadOnly.prototype, inspect.custom, {
enumerable: false,
value(this: DOMMatrixReadOnly) {
const v = this.toJSON();
Object.defineProperty(v, 'constructor', {
value: this.constructor,
});
return v;
},
});

export class DOMMatrix
extends DOMMatrixReadOnly
implements globalThis.DOMMatrix
Expand Down

0 comments on commit 611f8e1

Please sign in to comment.