svelte-multistyle-ui 0.0.14-alpha → 0.0.16-alpha
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.
- package/README.md +116 -7
- package/cli/bin.js +94 -92
- package/cli/emit.js +237 -225
- package/cli/generate.js +504 -499
- package/cli/registry.js +105 -97
- package/dist/actions/dialog.d.ts +11 -0
- package/dist/actions/dialog.js +108 -0
- package/dist/components/Accordion.svelte +4 -1
- package/dist/components/Accordion.svelte.d.ts +8 -12
- package/dist/components/Alert.svelte +5 -2
- package/dist/components/Alert.svelte.d.ts +8 -16
- package/dist/components/Avatar.svelte +7 -0
- package/dist/components/Avatar.svelte.d.ts +8 -14
- package/dist/components/Breadcrumb.svelte +3 -0
- package/dist/components/Breadcrumb.svelte.d.ts +8 -8
- package/dist/components/Button.svelte +5 -0
- package/dist/components/Button.svelte.d.ts +8 -20
- package/dist/components/ButtonGroup.svelte +4 -1
- package/dist/components/ButtonGroup.svelte.d.ts +8 -16
- package/dist/components/Card.svelte +3 -0
- package/dist/components/Card.svelte.d.ts +8 -12
- package/dist/components/Carousel.svelte +11 -6
- package/dist/components/Carousel.svelte.d.ts +8 -16
- package/dist/components/Checkbox.svelte +4 -1
- package/dist/components/Checkbox.svelte.d.ts +8 -14
- package/dist/components/Chip.svelte +4 -1
- package/dist/components/Chip.svelte.d.ts +8 -20
- package/dist/components/CodeEditor.svelte +133 -129
- package/dist/components/CodeEditor.svelte.d.ts +8 -16
- package/dist/components/Column.svelte +41 -38
- package/dist/components/Column.svelte.d.ts +8 -12
- package/dist/components/CommandPalette.svelte +8 -2
- package/dist/components/CommandPalette.svelte.d.ts +8 -12
- package/dist/components/CrudView.svelte +1564 -0
- package/dist/components/CrudView.svelte.d.ts +17 -0
- package/dist/components/DatePicker.svelte +25 -7
- package/dist/components/DatePicker.svelte.d.ts +8 -24
- package/dist/components/Divider.svelte +3 -0
- package/dist/components/Divider.svelte.d.ts +8 -10
- package/dist/components/Drawer.svelte +5 -0
- package/dist/components/Drawer.svelte.d.ts +8 -14
- package/dist/components/DropdownMenu.svelte +26 -2
- package/dist/components/DropdownMenu.svelte.d.ts +8 -18
- package/dist/components/FAB.svelte +4 -1
- package/dist/components/FAB.svelte.d.ts +8 -14
- package/dist/components/FileUpload.svelte +30 -4
- package/dist/components/FileUpload.svelte.d.ts +8 -14
- package/dist/components/FilterBar.svelte +758 -0
- package/dist/components/FilterBar.svelte.d.ts +17 -0
- package/dist/components/GraphEditor.svelte +724 -0
- package/dist/components/GraphEditor.svelte.d.ts +28 -0
- package/dist/components/Grid.svelte +54 -51
- package/dist/components/Grid.svelte.d.ts +8 -18
- package/dist/components/IconButton.svelte +6 -1
- package/dist/components/IconButton.svelte.d.ts +8 -22
- package/dist/components/InlineEdit.svelte +142 -0
- package/dist/components/InlineEdit.svelte.d.ts +28 -0
- package/dist/components/Input.svelte +5 -1
- package/dist/components/Input.svelte.d.ts +8 -62
- package/dist/components/Modal.svelte +6 -1
- package/dist/components/Modal.svelte.d.ts +8 -16
- package/dist/components/MultiSelect.svelte +22 -190
- package/dist/components/MultiSelect.svelte.d.ts +8 -16
- package/dist/components/Pagination.svelte +8 -1
- package/dist/components/Pagination.svelte.d.ts +8 -12
- package/dist/components/Popover.svelte +3 -0
- package/dist/components/Popover.svelte.d.ts +8 -16
- package/dist/components/ProgressBar.svelte +76 -73
- package/dist/components/ProgressBar.svelte.d.ts +8 -14
- package/dist/components/Radio.svelte +4 -1
- package/dist/components/Radio.svelte.d.ts +8 -14
- package/dist/components/Rating.svelte +22 -2
- package/dist/components/Rating.svelte.d.ts +8 -18
- package/dist/components/Row.svelte +42 -39
- package/dist/components/Row.svelte.d.ts +8 -14
- package/dist/components/Select.svelte +258 -33
- package/dist/components/Select.svelte.d.ts +8 -16
- package/dist/components/Skeleton.svelte +3 -0
- package/dist/components/Skeleton.svelte.d.ts +8 -12
- package/dist/components/Slider.svelte +7 -3
- package/dist/components/Slider.svelte.d.ts +8 -18
- package/dist/components/SortableList.svelte +133 -130
- package/dist/components/SortableList.svelte.d.ts +6 -14
- package/dist/components/Spinner.svelte +3 -0
- package/dist/components/Spinner.svelte.d.ts +8 -8
- package/dist/components/Stepper.svelte +96 -93
- package/dist/components/Stepper.svelte.d.ts +8 -10
- package/dist/components/Table.svelte +3 -0
- package/dist/components/Table.svelte.d.ts +8 -12
- package/dist/components/Tabs.svelte +22 -2
- package/dist/components/Tabs.svelte.d.ts +8 -10
- package/dist/components/TextEditor.svelte +188 -187
- package/dist/components/TextEditor.svelte.d.ts +8 -18
- package/dist/components/Textarea.svelte +4 -1
- package/dist/components/Textarea.svelte.d.ts +8 -24
- package/dist/components/Toast.svelte +44 -11
- package/dist/components/Toast.svelte.d.ts +8 -12
- package/dist/components/Toggle.svelte +4 -1
- package/dist/components/Toggle.svelte.d.ts +8 -14
- package/dist/components/Tooltip.svelte +3 -0
- package/dist/components/Tooltip.svelte.d.ts +8 -12
- package/dist/components/charts/BarChart.svelte +7 -5
- package/dist/components/charts/BarChart.svelte.d.ts +8 -22
- package/dist/components/charts/BubbleChart.svelte +7 -5
- package/dist/components/charts/BubbleChart.svelte.d.ts +8 -22
- package/dist/components/charts/Chart.svelte +262 -248
- package/dist/components/charts/Chart.svelte.d.ts +8 -30
- package/dist/components/charts/ComboChart.svelte +7 -5
- package/dist/components/charts/ComboChart.svelte.d.ts +8 -22
- package/dist/components/charts/DoughnutChart.svelte +7 -5
- package/dist/components/charts/DoughnutChart.svelte.d.ts +8 -22
- package/dist/components/charts/LineChart.svelte +7 -5
- package/dist/components/charts/LineChart.svelte.d.ts +8 -22
- package/dist/components/charts/MermaidChart.svelte +96 -0
- package/dist/components/charts/MermaidChart.svelte.d.ts +20 -0
- package/dist/components/charts/PieChart.svelte +7 -5
- package/dist/components/charts/PieChart.svelte.d.ts +8 -22
- package/dist/components/charts/PolarAreaChart.svelte +7 -5
- package/dist/components/charts/PolarAreaChart.svelte.d.ts +8 -22
- package/dist/components/charts/RadarChart.svelte +7 -5
- package/dist/components/charts/RadarChart.svelte.d.ts +8 -22
- package/dist/components/charts/ScatterChart.svelte +7 -5
- package/dist/components/charts/ScatterChart.svelte.d.ts +8 -22
- package/dist/components/charts/StackedBarChart.svelte +20 -18
- package/dist/components/charts/StackedBarChart.svelte.d.ts +8 -22
- package/dist/components/charts/StackedLineChart.svelte +23 -21
- package/dist/components/charts/StackedLineChart.svelte.d.ts +8 -22
- package/dist/components/charts/chart-config.d.ts +2 -2
- package/dist/components/charts/chart-config.js +714 -733
- package/dist/components/charts/mermaid-chart-styles.css +27 -0
- package/dist/components/checkbox-styles.css +122 -117
- package/dist/components/crudview-styles.css +1057 -0
- package/dist/components/fileupload-styles.css +121 -117
- package/dist/components/filterbar-styles.css +655 -0
- package/dist/components/graph/FlowNode.svelte +82 -0
- package/dist/components/graph/FlowNode.svelte.d.ts +17 -0
- package/dist/components/graph/GraphNode.svelte +72 -0
- package/dist/components/graph/GraphNode.svelte.d.ts +17 -0
- package/dist/components/graph-editor-styles.css +439 -0
- package/dist/components/inline-edit-styles.css +113 -0
- package/dist/components/input-styles.css +17 -34
- package/dist/components/liquid-glass-field.css +29 -0
- package/dist/components/prism-manual.d.ts +0 -0
- package/dist/components/prism-manual.js +4 -0
- package/dist/components/radio-styles.css +118 -113
- package/dist/components/rating-styles.css +70 -65
- package/dist/components/select-styles.css +239 -11
- package/dist/components/slider-styles.css +85 -81
- package/dist/components/text-editor-core/dom-utils.d.ts +1 -1
- package/dist/components/text-editor-core/editor-core.d.ts +9 -9
- package/dist/components/text-editor-core/editor-core.js +854 -808
- package/dist/components/text-editor-core/sanitizer.d.ts +4 -1
- package/dist/components/text-editor-core/sanitizer.js +228 -161
- package/dist/components/text-editor-core/selection-engine.d.ts +3 -3
- package/dist/components/textarea-styles.css +14 -14
- package/dist/components/toggle-styles.css +126 -121
- package/dist/config.svelte.d.ts +5 -4
- package/dist/config.svelte.js +114 -81
- package/dist/graph/flow-routing.d.ts +10 -0
- package/dist/graph/flow-routing.js +113 -0
- package/dist/graph/geometry.d.ts +48 -0
- package/dist/graph/geometry.js +154 -0
- package/dist/graph/index.d.ts +111 -0
- package/dist/graph/index.js +230 -0
- package/dist/graph/node-types.d.ts +24 -0
- package/dist/graph/node-types.js +82 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +13 -1
- package/dist/themes/generator.js +175 -173
- package/dist/themes/presets.d.ts +21 -21
- package/dist/utils/dbmr.d.ts +27 -0
- package/dist/utils/dbmr.js +381 -0
- package/dist/utils/filter.d.ts +103 -0
- package/dist/utils/filter.js +617 -0
- package/package.json +106 -81
- package/dist/components/multiselect-styles.css +0 -364
package/cli/emit.js
CHANGED
|
@@ -1,226 +1,238 @@
|
|
|
1
|
-
// Pure string builders for the YAML -> Svelte page generator. No I/O here.
|
|
2
|
-
// All functions take already-parsed JS data (from js-yaml) and return strings.
|
|
3
|
-
import { registry } from "./registry.js";
|
|
4
|
-
|
|
5
|
-
const IND = " "; // 2-space indent per depth level
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
// Top-level page
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {any} doc parsed YAML object
|
|
13
|
-
* @param {{style:string, theme:string, mode:string}} cfg resolved page config
|
|
14
|
-
* @returns {string} full .svelte file content
|
|
15
|
-
*/
|
|
16
|
-
export function emitPage(doc, cfg) {
|
|
17
|
-
const used = new Set();
|
|
18
|
-
const body = Array.isArray(doc?.body) ? doc.body : [];
|
|
19
|
-
const bodyMarkup = emitBody(body, 0, used);
|
|
20
|
-
const state = Array.isArray(doc?.state) ? doc.state : [];
|
|
21
|
-
|
|
22
|
-
const sections = [
|
|
23
|
-
emitImports(used),
|
|
24
|
-
emitState(state),
|
|
25
|
-
emitOnMount(),
|
|
26
|
-
].filter((s) => s.length);
|
|
27
|
-
|
|
28
|
-
const scriptBody = sections.map((s) => s.join("\n")).join("\n\n");
|
|
29
|
-
const out = `<script>\n${scriptBody}\n</script>\n` + (bodyMarkup ? `\n${bodyMarkup}\n` : "\n");
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// <script> sections (each returns an array of lines, no trailing newline)
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
function emitImports(used) {
|
|
38
|
-
const components = [...used].sort();
|
|
39
|
-
const lines = [];
|
|
40
|
-
if (components.length) {
|
|
41
|
-
lines.push(`import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`
|
|
65
|
-
`
|
|
66
|
-
`
|
|
67
|
-
` systemDark =
|
|
68
|
-
`
|
|
69
|
-
` mq.
|
|
70
|
-
`
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`
|
|
76
|
-
`
|
|
77
|
-
` root.classList.toggle("
|
|
78
|
-
`
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
`
|
|
87
|
-
`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
if (typeof value === "
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
if (typeof
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
1
|
+
// Pure string builders for the YAML -> Svelte page generator. No I/O here.
|
|
2
|
+
// All functions take already-parsed JS data (from js-yaml) and return strings.
|
|
3
|
+
import { registry } from "./registry.js";
|
|
4
|
+
|
|
5
|
+
const IND = " "; // 2-space indent per depth level
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Top-level page
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {any} doc parsed YAML object
|
|
13
|
+
* @param {{style:string, theme:string, mode:string}} cfg resolved page config
|
|
14
|
+
* @returns {string} full .svelte file content
|
|
15
|
+
*/
|
|
16
|
+
export function emitPage(doc, cfg) {
|
|
17
|
+
const used = new Set();
|
|
18
|
+
const body = Array.isArray(doc?.body) ? doc.body : [];
|
|
19
|
+
const bodyMarkup = emitBody(body, 0, used);
|
|
20
|
+
const state = Array.isArray(doc?.state) ? doc.state : [];
|
|
21
|
+
|
|
22
|
+
const sections = [
|
|
23
|
+
emitImports(used),
|
|
24
|
+
emitState(state),
|
|
25
|
+
emitOnMount(),
|
|
26
|
+
].filter((s) => s.length);
|
|
27
|
+
|
|
28
|
+
const scriptBody = sections.map((s) => s.join("\n")).join("\n\n");
|
|
29
|
+
const out = `<script>\n${scriptBody}\n</script>\n` + (bodyMarkup ? `\n${bodyMarkup}\n` : "\n");
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// <script> sections (each returns an array of lines, no trailing newline)
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
function emitImports(used) {
|
|
38
|
+
const components = [...used].sort();
|
|
39
|
+
const lines = [`import { onMount } from "svelte";`];
|
|
40
|
+
if (components.length) {
|
|
41
|
+
lines.push(`import { ${components.join(", ")} } from "svelte-multistyle-ui";`);
|
|
42
|
+
}
|
|
43
|
+
return lines;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function emitState(state) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
for (const entry of state) {
|
|
49
|
+
if (!entry?.name) continue;
|
|
50
|
+
lines.push(` let ${entry.name} = $state(${defaultLiteral(entry)});`);
|
|
51
|
+
}
|
|
52
|
+
return lines;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function emitDarkEffect(mode) {
|
|
56
|
+
// Self-contained dark/light handling. Reads OS preference only when mode==="system".
|
|
57
|
+
// Independent of the library's internal `defaults` (not re-exported from the package root).
|
|
58
|
+
const m = JSON.stringify(mode);
|
|
59
|
+
return [
|
|
60
|
+
` const MODE = ${m};`,
|
|
61
|
+
` let systemDark = $state(false);`,
|
|
62
|
+
``,
|
|
63
|
+
` $effect(() => {`,
|
|
64
|
+
` if (MODE !== "system") return;`,
|
|
65
|
+
` const mq = window.matchMedia("(prefers-color-scheme: dark)");`,
|
|
66
|
+
` systemDark = mq.matches;`,
|
|
67
|
+
` const handler = (e) => (systemDark = e.matches);`,
|
|
68
|
+
` mq.addEventListener("change", handler);`,
|
|
69
|
+
` return () => mq.removeEventListener("change", handler);`,
|
|
70
|
+
` });`,
|
|
71
|
+
``,
|
|
72
|
+
` const isDarkMode = $derived(MODE === "dark" || (MODE === "system" && systemDark));`,
|
|
73
|
+
``,
|
|
74
|
+
` $effect(() => {`,
|
|
75
|
+
` const root = document.documentElement;`,
|
|
76
|
+
` root.classList.toggle("dark", isDarkMode);`,
|
|
77
|
+
` root.classList.toggle("light", !isDarkMode);`,
|
|
78
|
+
` });`,
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function emitOnMount() {
|
|
83
|
+
// Empty stub. initMultistyleUI belongs in the app layout, not the generated page.
|
|
84
|
+
return [
|
|
85
|
+
` onMount(() => {`,
|
|
86
|
+
` // TODO: add setup logic here`,
|
|
87
|
+
` });`,
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Markup tree
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
/** @param {any[]} nodes @param {number} depth @param {Set<string>} used */
|
|
96
|
+
function emitBody(nodes, depth, used) {
|
|
97
|
+
return nodes.map((n) => emitNode(n, depth, used)).filter(Boolean).join("\n");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Escape literal text so Svelte never interprets `{expr}` or raw HTML tags. */
|
|
101
|
+
function escapeSvelteText(str) {
|
|
102
|
+
return String(str)
|
|
103
|
+
.replace(/&/g, "&")
|
|
104
|
+
.replace(/</g, "<")
|
|
105
|
+
.replace(/>/g, ">")
|
|
106
|
+
.replace(/\{/g, "{")
|
|
107
|
+
.replace(/\}/g, "}");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @returns {string|null} */
|
|
111
|
+
function emitNode(node, depth, used) {
|
|
112
|
+
const indent = IND.repeat(depth);
|
|
113
|
+
// Plain string node => literal text.
|
|
114
|
+
if (typeof node === "string") return indent + escapeSvelteText(node);
|
|
115
|
+
if (!node || typeof node !== "object") return null;
|
|
116
|
+
// { text: "..." } leaf text node.
|
|
117
|
+
if (typeof node.text === "string") return indent + escapeSvelteText(node.text);
|
|
118
|
+
|
|
119
|
+
const name = node.component;
|
|
120
|
+
const entry = registry[name];
|
|
121
|
+
if (!entry) return null; // schema should have caught this already
|
|
122
|
+
used.add(name);
|
|
123
|
+
|
|
124
|
+
const attrs = emitAttrs(node, entry);
|
|
125
|
+
const attrStr = attrs ? ` ${attrs}` : "";
|
|
126
|
+
const open = `${indent}<${name}${attrStr}`;
|
|
127
|
+
|
|
128
|
+
switch (entry.kind) {
|
|
129
|
+
case "leaf":
|
|
130
|
+
return `${open} />`;
|
|
131
|
+
|
|
132
|
+
case "children":
|
|
133
|
+
case "container": {
|
|
134
|
+
const children = node.children;
|
|
135
|
+
if (children == null) return `${open} />`;
|
|
136
|
+
if (typeof children === "string") return `${open}>${escapeSvelteText(children)}</${name}>`;
|
|
137
|
+
if (Array.isArray(children)) {
|
|
138
|
+
const inner = emitBody(children, depth + 1, used);
|
|
139
|
+
if (!inner) return `${open} />`;
|
|
140
|
+
return `${open}>\n${inner}\n${indent}</${name}>`;
|
|
141
|
+
}
|
|
142
|
+
return `${open} />`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
case "multi-snippet": {
|
|
146
|
+
const snippets = entry.snippets || [];
|
|
147
|
+
const blocks = snippets.map((sn) => {
|
|
148
|
+
const content = node.snippets?.[sn];
|
|
149
|
+
let inner = "";
|
|
150
|
+
if (typeof content === "string") inner = `${IND.repeat(depth + 2)}${escapeSvelteText(content)}`;
|
|
151
|
+
else if (Array.isArray(content)) inner = emitBody(content, depth + 2, used);
|
|
152
|
+
return `${indent}${IND}{#snippet ${sn}()}\n${inner ? inner + "\n" : ""}${indent}${IND}{/snippet}`;
|
|
153
|
+
});
|
|
154
|
+
return `${open}>\n${blocks.join("\n")}\n${indent}</${name}>`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
default:
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Build the attribute string (props + bind:) for a component node. */
|
|
163
|
+
function emitAttrs(node, entry) {
|
|
164
|
+
const parts = [];
|
|
165
|
+
if (node.props && typeof node.props === "object") {
|
|
166
|
+
for (const [k, v] of Object.entries(node.props)) {
|
|
167
|
+
const attr = emitProp(k, v);
|
|
168
|
+
if (attr) parts.push(attr);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (node.bind != null) {
|
|
172
|
+
if (typeof node.bind === "string") {
|
|
173
|
+
const prop = entry.primaryBindable;
|
|
174
|
+
if (prop) parts.push(`bind:${prop}={${node.bind}}`);
|
|
175
|
+
} else if (typeof node.bind === "object") {
|
|
176
|
+
for (const [prop, refName] of Object.entries(node.bind)) {
|
|
177
|
+
if (typeof refName === "string") parts.push(`bind:${prop}={${refName}}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return parts.join(" ");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** @returns {string|null} one Svelte attribute, e.g. `label="Hi"`, `value={count}`, `options={[...]}` */
|
|
185
|
+
function emitProp(key, value) {
|
|
186
|
+
if (value === null || value === undefined) return null;
|
|
187
|
+
if (typeof value === "string") {
|
|
188
|
+
const ref = value.match(/^\{([A-Za-z_$][\w$]*)\}$/);
|
|
189
|
+
if (ref) return `${key}={${ref[1]}}`; // reactive ref to a state var
|
|
190
|
+
if (value.includes("{") || value.includes("}")) {
|
|
191
|
+
return `${key}={${JSON.stringify(value)}}`; // prevent Svelte from evaluating {expr} inside quoted attrs
|
|
192
|
+
}
|
|
193
|
+
return `${key}=${JSON.stringify(value)}`; // plain string literal
|
|
194
|
+
}
|
|
195
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
196
|
+
return `${key}={${JSON.stringify(value)}}`;
|
|
197
|
+
}
|
|
198
|
+
if (Array.isArray(value)) return `${key}={${jsValue(value)}}`;
|
|
199
|
+
if (typeof value === "object") return `${key}={${jsValue(value)}}`;
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------------------------------------------------------------------------
|
|
204
|
+
// JS literal coercion (for arrays / objects / scalars inside {})
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
|
|
207
|
+
/** @returns {string} a JS expression string equivalent to the parsed YAML value */
|
|
208
|
+
function jsValue(v) {
|
|
209
|
+
if (v === null || v === undefined) return "null";
|
|
210
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
211
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
212
|
+
if (Array.isArray(v)) return `[${v.map(jsValue).join(",")}]`;
|
|
213
|
+
if (typeof v === "object") {
|
|
214
|
+
const entries = Object.entries(v).map(([k, val]) => `${jsKey(k)}:${jsValue(val)}`);
|
|
215
|
+
return `{${entries.join(",")}}`;
|
|
216
|
+
}
|
|
217
|
+
return "null";
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function jsKey(k) {
|
|
221
|
+
return /^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// ---------------------------------------------------------------------------
|
|
225
|
+
// state default coercion
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
|
|
228
|
+
function defaultLiteral(entry) {
|
|
229
|
+
if (entry.default !== undefined) return jsValue(entry.default);
|
|
230
|
+
switch (entry.type) {
|
|
231
|
+
case "number": return "0";
|
|
232
|
+
case "bool":
|
|
233
|
+
case "boolean": return "false";
|
|
234
|
+
case "array": return "[]";
|
|
235
|
+
case "object": return "{}";
|
|
236
|
+
default: return '""'; // string / unknown
|
|
237
|
+
}
|
|
226
238
|
}
|