Visualize Your Ideas With Code
fix(2d): textDirection property for RTL/LTR text (#404)
Mohsin Hijazeef240b1bd140a
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.tsindex 00820668..5cf788ae 100644--- a/packages/2d/src/components/Layout.ts+++ b/packages/2d/src/components/Layout.ts@@ -94,6 +94,7 @@ export interface LayoutProps extends NodeProps {lineHeight?: SignalValue<Length>;letterSpacing?: SignalValue<number>;textWrap?: SignalValue<TextWrap>;+ textDirection?: SignalValue<CanvasDirection>;size?: SignalValue<PossibleVector2<Length>>;offsetX?: SignalValue<number>;@@ -196,6 +197,9 @@ export class Layout extends Node {})@signal()public declare readonly textWrap: SimpleSignal<TextWrap, this>;+ @initial('inherit')+ @signal()+ public declare readonly textDirection: SimpleSignal<CanvasDirection, this>;@cloneable(false)@inspectable(false)diff --git a/packages/2d/src/components/Shape.ts b/packages/2d/src/components/Shape.tsindex 64209581..cb1df395 100644--- a/packages/2d/src/components/Shape.ts+++ b/packages/2d/src/components/Shape.ts@@ -65,6 +65,11 @@ export abstract class Shape extends Layout {super(props);}+ protected applyText(context: CanvasRenderingContext2D) {+ context.direction = this.textDirection();+ this.element.dir = this.textDirection();+ }+protected applyStyle(context: CanvasRenderingContext2D) {context.fillStyle = resolveCanvasStyle(this.fill(), context);context.strokeStyle = resolveCanvasStyle(this.stroke(), context);diff --git a/packages/2d/src/components/Text.ts b/packages/2d/src/components/Text.tsindex 34a0a965..c83a7741 100644--- a/packages/2d/src/components/Text.ts+++ b/packages/2d/src/components/Text.ts@@ -43,6 +43,7 @@ export class Text extends Shape {protected override draw(context: CanvasRenderingContext2D) {this.requestFontUpdate();this.applyStyle(context);+ this.applyText(context);context.font = this.styles.font;const parentRect = this.element.getBoundingClientRect();