| 24 | |
| 25 | @nodeName('Txt') |
| 26 | export class Txt extends Shape { |
| 27 | public readonly [TXT_TYPE] = true; |
| 28 | |
| 29 | /** |
| 30 | * Create a bold text node. |
| 31 | * |
| 32 | * @remarks |
| 33 | * This is a shortcut for |
| 34 | * ```tsx |
| 35 | * <Txt fontWeight={700} /> |
| 36 | * ``` |
| 37 | * |
| 38 | * @param props - Additional text properties. |
| 39 | */ |
| 40 | public static b(props: TxtProps) { |
| 41 | return new Txt({...props, fontWeight: 700}); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Create an italic text node. |
| 46 | * |
| 47 | * @remarks |
| 48 | * This is a shortcut for |
| 49 | * ```tsx |
| 50 | * <Txt fontStyle={'italic'} /> |
| 51 | * ``` |
| 52 | * |
| 53 | * @param props - Additional text properties. |
| 54 | */ |
| 55 | public static i(props: TxtProps) { |
| 56 | return new Txt({...props, fontStyle: 'italic'}); |
| 57 | } |
| 58 | |
| 59 | @initial('') |
| 60 | @signal() |
| 61 | public declare readonly text: SimpleSignal<string, this>; |
| 62 | |
| 63 | protected getText(): string { |
| 64 | return this.innerText(); |
| 65 | } |
| 66 | |
| 67 | protected setText(value: SignalValue<string>) { |
| 68 | const children = this.children(); |
| 69 | let leaf: TxtLeaf | null = null; |
| 70 | for (let i = 0; i < children.length; i++) { |
| 71 | const child = children[i]; |
| 72 | if (leaf === null && child instanceof TxtLeaf) { |
| 73 | leaf = child; |
| 74 | } else { |
| 75 | child.parent(null); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (leaf === null) { |
| 80 | leaf = new TxtLeaf({text: value}); |
| 81 | leaf.parent(this); |
| 82 | } else { |
| 83 | leaf.text(value); |
nothing calls this directly
no test coverage detected