Visualize Your Ideas With Code
fix(2d): fix letterSpacing (#448)
Jacobbb5ffc48efa8
diff --git a/packages/2d/src/components/Layout.ts b/packages/2d/src/components/Layout.tsindex 52a1c735..a204bb03 100644--- a/packages/2d/src/components/Layout.ts+++ b/packages/2d/src/components/Layout.ts@@ -32,7 +32,6 @@ import {FlexWrap,LayoutMode,DesiredLength,- LetterSpacing,TextWrap,Length,LengthLimit,@@ -183,18 +182,11 @@ export class Layout extends Node {@defaultStyle('line-height', parseFloat)@signal()public declare readonly lineHeight: SimpleSignal<Length, this>;- @defaultStyle('letter-spacing', i => {- if (i === 'normal') {- return 'normal';- }- return parseFloat(i);- })+ @defaultStyle('letter-spacing', i => (i === 'normal' ? 0 : parseFloat(i)))@signal()- public declare readonly letterSpacing: SimpleSignal<LetterSpacing, this>;+ public declare readonly letterSpacing: SimpleSignal<number, this>;- @defaultStyle('white-space', i => {- return i === 'pre' ? 'pre' : i === 'normal';- })+ @defaultStyle('white-space', i => (i === 'pre' ? 'pre' : i === 'normal'))@signal()public declare readonly textWrap: SimpleSignal<TextWrap, this>;@initial('inherit')@@ -799,8 +791,6 @@ export class Layout extends Node {: this.fontWeight().toString();this.element.style.letterSpacing = this.letterSpacing.isInitial()? ''- : this.letterSpacing() === 'normal'- ? 'normal': `${this.letterSpacing()}px`;if (this.textWrap.isInitial()) {diff --git a/packages/2d/src/components/Txt.ts b/packages/2d/src/components/Txt.tsindex 8bfe229f..852c2fbb 100644--- a/packages/2d/src/components/Txt.ts+++ b/packages/2d/src/components/Txt.ts@@ -45,6 +45,9 @@ export class Txt extends Shape {this.applyStyle(context);this.applyText(context);context.font = this.styles.font;+ if ('letterSpacing' in context) {+ context.letterSpacing = `${this.letterSpacing()}px`;+ }const parentRect = this.element.getBoundingClientRect();const {width, height} = this.size();diff --git a/packages/2d/src/partials/types.ts b/packages/2d/src/partials/types.tsindex 7e21275d..5337fe6f 100644--- a/packages/2d/src/partials/types.ts+++ b/packages/2d/src/partials/types.ts@@ -25,8 +25,6 @@ export type FlexContent =export type FlexItems = 'center' | 'start' | 'end' | 'stretch' | 'baseline';-export type LetterSpacing = number | 'normal';-export type TextWrap = boolean | 'pre';export type LayoutMode = boolean | null;