Visualize Your Ideas With Code
feat(2d): add skew property (#803)
Jacobeff7c7be0c01
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.tsindex 33eb0113..5f6329eb 100644--- a/packages/2d/src/components/Layout.ts+++ b/packages/2d/src/components/Layout.ts@@ -679,12 +679,7 @@ export class Layout extends Node {}public override localToParent(): DOMMatrix {- const matrix = new DOMMatrix();-- matrix.translateSelf(this.x(), this.y());- matrix.rotateSelf(0, 0, this.rotation());- matrix.scaleSelf(this.scale.x(), this.scale.y());-+ const matrix = super.localToParent();const offset = this.offset();if (!offset.exactlyEquals(Vector2.zero)) {const translate = this.size().mul(offset).scale(-0.5);diff --git a/packages/2d/src/components/Node.ts b/packages/2d/src/components/Node.tsindex 55a2492d..6db9a05a 100644--- a/packages/2d/src/components/Node.ts+++ b/packages/2d/src/components/Node.ts@@ -65,6 +65,9 @@ export interface NodeProps {scaleX?: SignalValue<number>;scaleY?: SignalValue<number>;scale?: SignalValue<PossibleVector2>;+ skewX?: SignalValue<number>;+ skewY?: SignalValue<number>;+ skew?: SignalValue<PossibleVector2>;zIndex?: SignalValue<number>;opacity?: SignalValue<number>;@@ -225,6 +228,40 @@ export class Node implements Promisable<Node> {@vector2Signal('scale')public declare readonly scale: Vector2Signal<this>;+ /**+ * Represents the skew of this node in local space of its parent.+ *+ * @example+ * Initializing the skew:+ * ```tsx+ * // with a possible vector:+ * <Node skew={[40, 20]} />+ * // with individual components:+ * <Node skewX={40} skewY={20} />+ * ```+ *+ * Accessing the skew:+ * ```tsx+ * // retrieving the vector:+ * const skew = node.skew();+ * // retrieving an individual component:+ * const skewX = node.skew.x();+ * ```+ *+ * Setting the skew:+ * ```tsx+ * // with a possible vector:+ * node.skew([40, 20]);+ * node.skew(() => [40, 20]);+ * // with individual components:+ * node.skew.x(40);+ * node.skew.x(() => 40);+ * ```+ */+ @initial(Vector2.zero)+ @vector2Signal('skew')+ public declare readonly skew: Vector2Signal<this>;+/*** A helper signal for operating on the scale in world space.*@@ -490,9 +527,11 @@ export class Node implements Promisable<Node> {@computed()public localToParent(): DOMMatrix {const matrix = new DOMMatrix();- matrix.translateSelf(this.position.x(), this.position.y());+ matrix.translateSelf(this.x(), this.y());matrix.rotateSelf(0, 0, this.rotation());matrix.scaleSelf(this.scale.x(), this.scale.y());+ matrix.skewXSelf(this.skew.x());+ matrix.skewYSelf(this.skew.y());return matrix;}