@narumitw/pi-starship 0.55.0 → 0.55.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +21 -36
  2. package/dist/chunks/{chunk-UX6PBXVK.js → chunk-JO5PH6FN.js} +28 -110
  3. package/dist/chunks/chunk-JO5PH6FN.js.map +7 -0
  4. package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
  5. package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
  6. package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
  7. package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
  8. package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
  9. package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
  10. package/dist/chunks/{commands-53ZO2JUK.js → commands-ATILSUVK.js} +13 -42
  11. package/dist/chunks/commands-ATILSUVK.js.map +7 -0
  12. package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
  13. package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
  14. package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
  15. package/dist/chunks/development-OUYXDPBS.js.map +7 -0
  16. package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
  17. package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
  18. package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
  19. package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
  20. package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
  21. package/dist/chunks/package-YXRZQAOV.js.map +7 -0
  22. package/dist/index.ts +38 -53
  23. package/dist/index.ts.map +2 -2
  24. package/package.json +60 -61
  25. package/skills/configuring-pi-starship/references/runtime-and-security.md +5 -1
  26. package/skills/configuring-pi-starship/scripts/apply.mjs +43 -47
  27. package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
  28. package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
  29. package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
  30. package/src/command-configuration.ts +267 -286
  31. package/src/command-contract.ts +6 -6
  32. package/src/command-inspector.ts +27 -27
  33. package/src/command-preset-picker.ts +45 -50
  34. package/src/command-preview.ts +153 -166
  35. package/src/commands.ts +588 -618
  36. package/src/config.ts +580 -660
  37. package/src/effective-config.ts +46 -48
  38. package/src/format/formatter.ts +211 -227
  39. package/src/format/style.ts +205 -216
  40. package/src/modules/activity.ts +74 -74
  41. package/src/modules/brand.ts +9 -9
  42. package/src/modules/cache.ts +18 -18
  43. package/src/modules/catalog.ts +79 -83
  44. package/src/modules/cloud.ts +54 -54
  45. package/src/modules/context.ts +27 -27
  46. package/src/modules/cost.ts +23 -23
  47. package/src/modules/deployment.ts +45 -45
  48. package/src/modules/development.ts +80 -81
  49. package/src/modules/directory.ts +89 -113
  50. package/src/modules/display.ts +9 -9
  51. package/src/modules/execution.ts +62 -69
  52. package/src/modules/extension-status.ts +59 -64
  53. package/src/modules/fill.ts +10 -10
  54. package/src/modules/git/branch.ts +26 -26
  55. package/src/modules/git/commit.ts +21 -23
  56. package/src/modules/git/metrics.ts +22 -22
  57. package/src/modules/git/runtime.ts +299 -334
  58. package/src/modules/git/state.ts +17 -17
  59. package/src/modules/git/status.ts +77 -79
  60. package/src/modules/git/worktree.ts +10 -12
  61. package/src/modules/github-pr.ts +20 -20
  62. package/src/modules/helpers.ts +3 -3
  63. package/src/modules/index.ts +21 -21
  64. package/src/modules/inspection.ts +101 -108
  65. package/src/modules/languages.ts +52 -59
  66. package/src/modules/model.ts +57 -67
  67. package/src/modules/package.ts +12 -12
  68. package/src/modules/provider.ts +22 -24
  69. package/src/modules/render.ts +124 -140
  70. package/src/modules/thinking.ts +27 -26
  71. package/src/modules/time.ts +10 -13
  72. package/src/modules/tokens.ts +13 -13
  73. package/src/modules/truncation.ts +14 -17
  74. package/src/modules/turn.ts +9 -9
  75. package/src/modules/types.ts +125 -132
  76. package/src/modules/workspace-helpers.ts +4 -7
  77. package/src/pi-starship.ts +567 -571
  78. package/src/presets/catalog.ts +113 -113
  79. package/src/runtime/cloud.ts +122 -150
  80. package/src/runtime/command.ts +106 -108
  81. package/src/runtime/deployment.ts +150 -179
  82. package/src/runtime/development.ts +107 -124
  83. package/src/runtime/execution.ts +110 -124
  84. package/src/runtime/github-pr.ts +223 -252
  85. package/src/runtime/helpers.ts +186 -199
  86. package/src/runtime/languages.ts +149 -180
  87. package/src/runtime/package.ts +74 -87
  88. package/src/runtime/refresh-controller.ts +82 -86
  89. package/src/runtime/types.ts +38 -38
  90. package/src/runtime/workspace.ts +108 -116
  91. package/src/usage.ts +40 -40
  92. package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
  93. package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
  94. package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
  95. package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
  96. package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
  97. package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
  98. package/dist/chunks/development-BERD42HW.js.map +0 -7
  99. package/dist/chunks/execution-42JTEY3N.js.map +0 -7
  100. package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
  101. package/dist/chunks/package-LG5H7BBM.js.map +0 -7
@@ -4,63 +4,61 @@ import { MODULE_DEFINITIONS } from "./modules/catalog.js";
4
4
  import type { ModuleOptionValue } from "./modules/types.js";
5
5
 
6
6
  export function projectEffectiveConfig(config: StarshipConfig): TomlTable {
7
- const projected: TomlTable = {
8
- format: config.format,
9
- };
10
- if (config.palette !== undefined) projected.palette = config.palette;
11
- projected.palettes = Object.fromEntries(
12
- sortedEntries(config.palettes).map(([name, colors]) => [name, sortedRecord(colors)]),
13
- );
14
- for (const definition of MODULE_DEFINITIONS) {
15
- const module = config.modules[definition.name];
16
- const table: TomlTable = {
17
- format: module.format,
18
- symbol: module.symbol,
19
- };
20
- if (definition.styleDefaults) {
21
- if (definition.fallbackStyle) table.style = module.style;
22
- for (const field of Object.keys(definition.styleDefaults)) {
23
- table[field] = module.styles[field] ?? "";
24
- }
25
- } else if (!definition.displayDefaults) {
26
- table.style = module.style;
27
- }
28
- if (definition.displayDefaults) {
29
- table.display = module.display.map((entry) => ({ ...entry }));
30
- }
31
- table.disabled = module.disabled;
32
- for (const key of Object.keys(definition.options ?? {})) {
33
- table[key] = cloneOptionValue(module.options[key]);
34
- }
35
- if (definition.name === "extension_status") {
36
- table.separator = config.extensionStatus.separator;
37
- table.max_statuses = config.extensionStatus.maxStatuses;
38
- table.icons = sortedRecord(config.extensionStatus.icons);
39
- }
40
- projected[definition.name] = table;
41
- }
42
- return projected;
7
+ const projected: TomlTable = {
8
+ format: config.format,
9
+ };
10
+ if (config.palette !== undefined) projected.palette = config.palette;
11
+ projected.palettes = Object.fromEntries(
12
+ sortedEntries(config.palettes).map(([name, colors]) => [name, sortedRecord(colors)]),
13
+ );
14
+ for (const definition of MODULE_DEFINITIONS) {
15
+ const module = config.modules[definition.name];
16
+ const table: TomlTable = {
17
+ format: module.format,
18
+ symbol: module.symbol,
19
+ };
20
+ if (definition.styleDefaults) {
21
+ if (definition.fallbackStyle) table.style = module.style;
22
+ for (const field of Object.keys(definition.styleDefaults)) {
23
+ table[field] = module.styles[field] ?? "";
24
+ }
25
+ } else if (!definition.displayDefaults) {
26
+ table.style = module.style;
27
+ }
28
+ if (definition.displayDefaults) {
29
+ table.display = module.display.map((entry) => ({ ...entry }));
30
+ }
31
+ table.disabled = module.disabled;
32
+ for (const key of Object.keys(definition.options ?? {})) {
33
+ table[key] = cloneOptionValue(module.options[key]);
34
+ }
35
+ if (definition.name === "extension_status") {
36
+ table.separator = config.extensionStatus.separator;
37
+ table.max_statuses = config.extensionStatus.maxStatuses;
38
+ table.icons = sortedRecord(config.extensionStatus.icons);
39
+ }
40
+ projected[definition.name] = table;
41
+ }
42
+ return projected;
43
43
  }
44
44
 
45
45
  export function serializeEffectiveConfig(config: StarshipConfig): string {
46
- return stringify(projectEffectiveConfig(config));
46
+ return stringify(projectEffectiveConfig(config));
47
47
  }
48
48
 
49
49
  function cloneOptionValue(value: ModuleOptionValue | undefined): TomlValue {
50
- if (value === undefined) throw new Error("Missing normalized module option");
51
- if (Array.isArray(value)) return [...(value as readonly string[])];
52
- if (typeof value === "object") {
53
- return sortedRecord(value as Readonly<Record<string, string>>);
54
- }
55
- return value;
50
+ if (value === undefined) throw new Error("Missing normalized module option");
51
+ if (Array.isArray(value)) return [...(value as readonly string[])];
52
+ if (typeof value === "object") {
53
+ return sortedRecord(value as Readonly<Record<string, string>>);
54
+ }
55
+ return value;
56
56
  }
57
57
 
58
58
  function sortedRecord(values: Readonly<Record<string, string>>): Record<string, string> {
59
- return Object.fromEntries(sortedEntries(values));
59
+ return Object.fromEntries(sortedEntries(values));
60
60
  }
61
61
 
62
- function sortedEntries<Value>(values: Readonly<Record<string, Value>>): Array<[string, Value]> {
63
- return Object.entries(values).sort(([left], [right]) =>
64
- left < right ? -1 : left > right ? 1 : 0,
65
- );
62
+ function sortedEntries<Value>(values: Readonly<Record<string, Value>>): [string, Value][] {
63
+ return Object.entries(values).sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));
66
64
  }
@@ -1,275 +1,259 @@
1
- import {
2
- type ColorPalette,
3
- isFillChunk,
4
- type LayoutChunk,
5
- parseStyle,
6
- type TextStyle,
7
- } from "./style.js";
1
+ import { type ColorPalette, isFillChunk, type LayoutChunk, parseStyle, type TextStyle } from "./style.js";
8
2
 
9
3
  export type FormatNode =
10
- | { type: "text"; value: string }
11
- | { type: "variable"; name: string }
12
- | { type: "group"; children: FormatNode[]; style: StyleNode[] }
13
- | { type: "conditional"; children: FormatNode[] };
4
+ | { type: "text"; value: string }
5
+ | { type: "variable"; name: string }
6
+ | { type: "group"; children: FormatNode[]; style: StyleNode[] }
7
+ | { type: "conditional"; children: FormatNode[] };
14
8
 
15
9
  export type StyleNode = { type: "text"; value: string } | { type: "variable"; name: string };
16
10
  export type FormatValue = string | readonly LayoutChunk[] | undefined;
17
11
 
18
12
  export interface RenderFormatOptions {
19
- variables: Readonly<Record<string, FormatValue>>;
20
- styleVariables?: Readonly<Record<string, string | undefined>>;
21
- palette?: ColorPalette;
13
+ variables: Readonly<Record<string, FormatValue>>;
14
+ styleVariables?: Readonly<Record<string, string | undefined>>;
15
+ palette?: ColorPalette;
22
16
  }
23
17
 
24
18
  export class FormatSyntaxError extends Error {
25
- readonly offset: number;
19
+ readonly offset: number;
26
20
 
27
- constructor(message: string, offset: number) {
28
- super(`${message} at offset ${offset}`);
29
- this.name = "FormatSyntaxError";
30
- this.offset = offset;
31
- }
21
+ constructor(message: string, offset: number) {
22
+ super(`${message} at offset ${offset}`);
23
+ this.name = "FormatSyntaxError";
24
+ this.offset = offset;
25
+ }
32
26
  }
33
27
 
34
28
  const FUNCTIONAL = new Set(["[", "]", "(", ")", "\\", "$"]);
35
29
 
36
30
  export function parseFormat(format: string): FormatNode[] {
37
- const parser = new FormatParser(format);
38
- const nodes = parser.parseNodes();
39
- if (!parser.done()) throw new FormatSyntaxError("Unexpected character", parser.offset());
40
- return nodes;
31
+ const parser = new FormatParser(format);
32
+ const nodes = parser.parseNodes();
33
+ if (!parser.done()) throw new FormatSyntaxError("Unexpected character", parser.offset());
34
+ return nodes;
41
35
  }
42
36
 
43
37
  class FormatParser {
44
- private index = 0;
38
+ private index = 0;
45
39
 
46
- constructor(private readonly input: string) {}
40
+ constructor(private readonly input: string) {}
47
41
 
48
- offset() {
49
- return this.index;
50
- }
42
+ offset() {
43
+ return this.index;
44
+ }
51
45
 
52
- done() {
53
- return this.index === this.input.length;
54
- }
46
+ done() {
47
+ return this.index === this.input.length;
48
+ }
55
49
 
56
- parseNodes(end?: "]" | ")"): FormatNode[] {
57
- const nodes: FormatNode[] = [];
58
- let text = "";
59
- const flushText = () => {
60
- if (!text) return;
61
- nodes.push({ type: "text", value: text });
62
- text = "";
63
- };
50
+ parseNodes(end?: "]" | ")"): FormatNode[] {
51
+ const nodes: FormatNode[] = [];
52
+ let text = "";
53
+ const flushText = () => {
54
+ if (!text) return;
55
+ nodes.push({ type: "text", value: text });
56
+ text = "";
57
+ };
64
58
 
65
- while (!this.done()) {
66
- const current = this.input[this.index];
67
- if (current === end) {
68
- flushText();
69
- this.index += 1;
70
- return nodes;
71
- }
72
- if (current === "\\") {
73
- const escaped = this.input[this.index + 1];
74
- if (!escaped || !FUNCTIONAL.has(escaped)) {
75
- throw new FormatSyntaxError("Invalid escape", this.index);
76
- }
77
- text += escaped;
78
- this.index += 2;
79
- continue;
80
- }
81
- if (current === "$") {
82
- flushText();
83
- nodes.push({ type: "variable", name: this.parseVariable() });
84
- continue;
85
- }
86
- if (current === "[") {
87
- flushText();
88
- this.index += 1;
89
- const children = this.parseNodes("]");
90
- if (this.input[this.index] !== "(") {
91
- throw new FormatSyntaxError("Text group requires a style", this.index);
92
- }
93
- this.index += 1;
94
- nodes.push({ type: "group", children, style: this.parseStyleNodes() });
95
- continue;
96
- }
97
- if (current === "(") {
98
- flushText();
99
- this.index += 1;
100
- nodes.push({ type: "conditional", children: this.parseNodes(")") });
101
- continue;
102
- }
103
- if (current === "]" || current === ")") {
104
- throw new FormatSyntaxError(`Unexpected ${current}`, this.index);
105
- }
106
- text += current;
107
- this.index += 1;
108
- }
59
+ while (!this.done()) {
60
+ const current = this.input[this.index];
61
+ if (current === end) {
62
+ flushText();
63
+ this.index += 1;
64
+ return nodes;
65
+ }
66
+ if (current === "\\") {
67
+ const escaped = this.input[this.index + 1];
68
+ if (!escaped || !FUNCTIONAL.has(escaped)) {
69
+ throw new FormatSyntaxError("Invalid escape", this.index);
70
+ }
71
+ text += escaped;
72
+ this.index += 2;
73
+ continue;
74
+ }
75
+ if (current === "$") {
76
+ flushText();
77
+ nodes.push({ type: "variable", name: this.parseVariable() });
78
+ continue;
79
+ }
80
+ if (current === "[") {
81
+ flushText();
82
+ this.index += 1;
83
+ const children = this.parseNodes("]");
84
+ if (this.input[this.index] !== "(") {
85
+ throw new FormatSyntaxError("Text group requires a style", this.index);
86
+ }
87
+ this.index += 1;
88
+ nodes.push({ type: "group", children, style: this.parseStyleNodes() });
89
+ continue;
90
+ }
91
+ if (current === "(") {
92
+ flushText();
93
+ this.index += 1;
94
+ nodes.push({ type: "conditional", children: this.parseNodes(")") });
95
+ continue;
96
+ }
97
+ if (current === "]" || current === ")") {
98
+ throw new FormatSyntaxError(`Unexpected ${current}`, this.index);
99
+ }
100
+ text += current;
101
+ this.index += 1;
102
+ }
109
103
 
110
- if (end) throw new FormatSyntaxError(`Missing ${end}`, this.index);
111
- flushText();
112
- return nodes;
113
- }
104
+ if (end) throw new FormatSyntaxError(`Missing ${end}`, this.index);
105
+ flushText();
106
+ return nodes;
107
+ }
114
108
 
115
- private parseVariable(): string {
116
- const start = this.index;
117
- this.index += 1;
118
- if (this.input[this.index] === "{") {
119
- this.index += 1;
120
- const nameStart = this.index;
121
- while (!this.done() && this.input[this.index] !== "}") {
122
- const current = this.input[this.index];
123
- if (!current || FUNCTIONAL.has(current) || current === "{") {
124
- throw new FormatSyntaxError("Invalid scoped variable", this.index);
125
- }
126
- this.index += 1;
127
- }
128
- if (this.done() || this.index === nameStart) {
129
- throw new FormatSyntaxError("Unclosed scoped variable", start);
130
- }
131
- const name = this.input.slice(nameStart, this.index);
132
- this.index += 1;
133
- return name;
134
- }
135
- const match = /^[A-Za-z_][A-Za-z0-9_]*/u.exec(this.input.slice(this.index));
136
- if (!match) throw new FormatSyntaxError("Invalid variable", start);
137
- this.index += match[0].length;
138
- return match[0];
139
- }
109
+ private parseVariable(): string {
110
+ const start = this.index;
111
+ this.index += 1;
112
+ if (this.input[this.index] === "{") {
113
+ this.index += 1;
114
+ const nameStart = this.index;
115
+ while (!this.done() && this.input[this.index] !== "}") {
116
+ const current = this.input[this.index];
117
+ if (!current || FUNCTIONAL.has(current) || current === "{") {
118
+ throw new FormatSyntaxError("Invalid scoped variable", this.index);
119
+ }
120
+ this.index += 1;
121
+ }
122
+ if (this.done() || this.index === nameStart) {
123
+ throw new FormatSyntaxError("Unclosed scoped variable", start);
124
+ }
125
+ const name = this.input.slice(nameStart, this.index);
126
+ this.index += 1;
127
+ return name;
128
+ }
129
+ const match = /^[A-Za-z_][A-Za-z0-9_]*/u.exec(this.input.slice(this.index));
130
+ if (!match) throw new FormatSyntaxError("Invalid variable", start);
131
+ this.index += match[0].length;
132
+ return match[0];
133
+ }
140
134
 
141
- private parseStyleNodes(): StyleNode[] {
142
- const nodes: StyleNode[] = [];
143
- let text = "";
144
- const flushText = () => {
145
- if (!text) return;
146
- nodes.push({ type: "text", value: text });
147
- text = "";
148
- };
149
- while (!this.done()) {
150
- const current = this.input[this.index];
151
- if (current === ")") {
152
- flushText();
153
- this.index += 1;
154
- return nodes;
155
- }
156
- if (current === "$") {
157
- flushText();
158
- nodes.push({ type: "variable", name: this.parseVariable() });
159
- continue;
160
- }
161
- if (current === "(" || current === "[" || current === "]" || current === "\\") {
162
- throw new FormatSyntaxError("Invalid style character", this.index);
163
- }
164
- text += current;
165
- this.index += 1;
166
- }
167
- throw new FormatSyntaxError("Missing )", this.index);
168
- }
135
+ private parseStyleNodes(): StyleNode[] {
136
+ const nodes: StyleNode[] = [];
137
+ let text = "";
138
+ const flushText = () => {
139
+ if (!text) return;
140
+ nodes.push({ type: "text", value: text });
141
+ text = "";
142
+ };
143
+ while (!this.done()) {
144
+ const current = this.input[this.index];
145
+ if (current === ")") {
146
+ flushText();
147
+ this.index += 1;
148
+ return nodes;
149
+ }
150
+ if (current === "$") {
151
+ flushText();
152
+ nodes.push({ type: "variable", name: this.parseVariable() });
153
+ continue;
154
+ }
155
+ if (current === "(" || current === "[" || current === "]" || current === "\\") {
156
+ throw new FormatSyntaxError("Invalid style character", this.index);
157
+ }
158
+ text += current;
159
+ this.index += 1;
160
+ }
161
+ throw new FormatSyntaxError("Missing )", this.index);
162
+ }
169
163
  }
170
164
 
171
165
  export function formatVariables(nodes: readonly FormatNode[]): Set<string> {
172
- const variables = new Set<string>();
173
- for (const node of nodes) {
174
- if (node.type === "variable") variables.add(node.name);
175
- else if (node.type === "group" || node.type === "conditional") {
176
- for (const variable of formatVariables(node.children)) variables.add(variable);
177
- }
178
- }
179
- return variables;
166
+ const variables = new Set<string>();
167
+ for (const node of nodes) {
168
+ if (node.type === "variable") variables.add(node.name);
169
+ else if (node.type === "group" || node.type === "conditional") {
170
+ for (const variable of formatVariables(node.children)) variables.add(variable);
171
+ }
172
+ }
173
+ return variables;
180
174
  }
181
175
 
182
176
  export function styleVariables(nodes: readonly FormatNode[]): Set<string> {
183
- const variables = new Set<string>();
184
- for (const node of nodes) {
185
- if (node.type === "group") {
186
- for (const part of node.style) {
187
- if (part.type === "variable") variables.add(part.name);
188
- }
189
- }
190
- if (node.type === "group" || node.type === "conditional") {
191
- for (const variable of styleVariables(node.children)) variables.add(variable);
192
- }
193
- }
194
- return variables;
177
+ const variables = new Set<string>();
178
+ for (const node of nodes) {
179
+ if (node.type === "group") {
180
+ for (const part of node.style) {
181
+ if (part.type === "variable") variables.add(part.name);
182
+ }
183
+ }
184
+ if (node.type === "group" || node.type === "conditional") {
185
+ for (const variable of styleVariables(node.children)) variables.add(variable);
186
+ }
187
+ }
188
+ return variables;
195
189
  }
196
190
 
197
- export function renderFormat(
198
- nodes: readonly FormatNode[],
199
- options: RenderFormatOptions,
200
- ): LayoutChunk[] {
201
- return renderNodes(nodes, options, undefined);
191
+ export function renderFormat(nodes: readonly FormatNode[], options: RenderFormatOptions): LayoutChunk[] {
192
+ return renderNodes(nodes, options, undefined);
202
193
  }
203
194
 
204
195
  function renderNodes(
205
- nodes: readonly FormatNode[],
206
- options: RenderFormatOptions,
207
- inheritedStyle: TextStyle | undefined,
196
+ nodes: readonly FormatNode[],
197
+ options: RenderFormatOptions,
198
+ inheritedStyle: TextStyle | undefined,
208
199
  ): LayoutChunk[] {
209
- const chunks: LayoutChunk[] = [];
210
- for (const node of nodes) {
211
- switch (node.type) {
212
- case "text":
213
- chunks.push({ text: node.value, style: inheritedStyle });
214
- break;
215
- case "variable":
216
- chunks.push(...chunksForValue(ownValue(options.variables, node.name), inheritedStyle));
217
- break;
218
- case "conditional":
219
- if (conditionalVisible(node.children, options.variables)) {
220
- chunks.push(...renderNodes(node.children, options, inheritedStyle));
221
- }
222
- break;
223
- case "group": {
224
- const styleString = node.style
225
- .map((part) =>
226
- part.type === "text" ? part.value : (ownValue(options.styleVariables, part.name) ?? ""),
227
- )
228
- .join("");
229
- const style = parseStyle(styleString, options.palette);
230
- const rendered = renderNodes(node.children, options, style);
231
- if (node.children.length === 0) chunks.push({ text: "", style });
232
- else chunks.push(...rendered);
233
- break;
234
- }
235
- }
236
- }
237
- return chunks;
200
+ const chunks: LayoutChunk[] = [];
201
+ for (const node of nodes) {
202
+ switch (node.type) {
203
+ case "text":
204
+ chunks.push({ text: node.value, style: inheritedStyle });
205
+ break;
206
+ case "variable":
207
+ chunks.push(...chunksForValue(ownValue(options.variables, node.name), inheritedStyle));
208
+ break;
209
+ case "conditional":
210
+ if (conditionalVisible(node.children, options.variables)) {
211
+ chunks.push(...renderNodes(node.children, options, inheritedStyle));
212
+ }
213
+ break;
214
+ case "group": {
215
+ const styleString = node.style
216
+ .map((part) => (part.type === "text" ? part.value : (ownValue(options.styleVariables, part.name) ?? "")))
217
+ .join("");
218
+ const style = parseStyle(styleString, options.palette);
219
+ const rendered = renderNodes(node.children, options, style);
220
+ if (node.children.length === 0) chunks.push({ text: "", style });
221
+ else chunks.push(...rendered);
222
+ break;
223
+ }
224
+ }
225
+ }
226
+ return chunks;
238
227
  }
239
228
 
240
229
  function ownValue<T>(record: Readonly<Record<string, T>> | undefined, key: string): T | undefined {
241
- return record && Object.hasOwn(record, key) ? record[key] : undefined;
230
+ return record && Object.hasOwn(record, key) ? record[key] : undefined;
242
231
  }
243
232
 
244
233
  function chunksForValue(value: FormatValue, inheritedStyle: TextStyle | undefined): LayoutChunk[] {
245
- if (value === undefined) return [];
246
- if (typeof value === "string") return [{ text: value, style: inheritedStyle }];
247
- return value.map((chunk) =>
248
- isFillChunk(chunk)
249
- ? {
250
- type: "fill" as const,
251
- pattern: chunk.pattern.map((part) => ({
252
- ...part,
253
- style: part.style ?? inheritedStyle,
254
- })),
255
- }
256
- : { ...chunk, style: chunk.style ?? inheritedStyle },
257
- );
234
+ if (value === undefined) return [];
235
+ if (typeof value === "string") return [{ text: value, style: inheritedStyle }];
236
+ return value.map((chunk) =>
237
+ isFillChunk(chunk)
238
+ ? {
239
+ type: "fill" as const,
240
+ pattern: chunk.pattern.map((part) => ({
241
+ ...part,
242
+ style: part.style ?? inheritedStyle,
243
+ })),
244
+ }
245
+ : { ...chunk, style: chunk.style ?? inheritedStyle },
246
+ );
258
247
  }
259
248
 
260
- function conditionalVisible(
261
- nodes: readonly FormatNode[],
262
- variables: Readonly<Record<string, FormatValue>>,
263
- ): boolean {
264
- for (const variable of formatVariables(nodes)) {
265
- const value = ownValue(variables, variable);
266
- if (
267
- typeof value === "string"
268
- ? value.length > 0
269
- : value?.some((chunk) => isFillChunk(chunk) || chunk.text.length > 0)
270
- ) {
271
- return true;
272
- }
273
- }
274
- return false;
249
+ function conditionalVisible(nodes: readonly FormatNode[], variables: Readonly<Record<string, FormatValue>>): boolean {
250
+ for (const variable of formatVariables(nodes)) {
251
+ const value = ownValue(variables, variable);
252
+ if (
253
+ typeof value === "string" ? value.length > 0 : value?.some((chunk) => isFillChunk(chunk) || chunk.text.length > 0)
254
+ ) {
255
+ return true;
256
+ }
257
+ }
258
+ return false;
275
259
  }