svelte-multistyle-ui 0.0.4-alpha → 0.0.5-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 +1 -1
- package/cli/bin.js +90 -0
- package/cli/emit.js +228 -0
- package/cli/fixtures/sample.expected.svelte +69 -0
- package/cli/fixtures/sample.yaml +128 -0
- package/cli/generate.js +68 -0
- package/cli/registry.js +95 -0
- package/cli/schema.js +145 -0
- package/dist/components/Button.svelte +3 -1
- package/dist/components/Button.svelte.d.ts +2 -0
- package/dist/components/DatePicker.svelte +47 -12
- package/dist/components/FAB.svelte +3 -1
- package/dist/components/FAB.svelte.d.ts +2 -0
- package/dist/components/IconButton.svelte +3 -1
- package/dist/components/IconButton.svelte.d.ts +2 -0
- package/dist/components/Input.svelte +0 -1
- package/dist/components/MultiSelect.svelte +0 -1
- package/dist/components/Select.svelte +0 -1
- package/dist/components/Stepper.svelte +91 -33
- package/dist/components/Textarea.svelte +0 -1
- package/dist/components/accordion-styles.css +1 -9
- package/dist/components/alert-styles.css +1 -4
- package/dist/components/avatar-styles.css +1 -4
- package/dist/components/breadcrumb-styles.css +1 -7
- package/dist/components/button-styles.css +44 -52
- package/dist/components/buttongroup-styles.css +1 -5
- package/dist/components/card-styles.css +1 -9
- package/dist/components/carousel-styles.css +1 -5
- package/dist/components/charts/Chart.svelte +63 -3
- package/dist/components/charts/chart-config.d.ts +27 -2
- package/dist/components/charts/chart-config.js +180 -67
- package/dist/components/charts/chart-styles.css +32 -17
- package/dist/components/checkbox-styles.css +2 -10
- package/dist/components/chip-styles.css +1 -4
- package/dist/components/commandpalette-styles.css +0 -4
- package/dist/components/datepicker-styles.css +967 -1027
- package/dist/components/divider-styles.css +1 -4
- package/dist/components/drawer-styles.css +0 -4
- package/dist/components/dropdown-styles.css +0 -5
- package/dist/components/fab-styles.css +18 -12
- package/dist/components/fileupload-styles.css +2 -10
- package/dist/components/iconbutton-styles.css +33 -34
- package/dist/components/input-styles.css +5 -37
- package/dist/components/modal-styles.css +0 -8
- package/dist/components/multiselect-styles.css +5 -32
- package/dist/components/pagination-styles.css +2 -5
- package/dist/components/popover-styles.css +0 -4
- package/dist/components/progressbar-styles.css +1 -5
- package/dist/components/radio-styles.css +1 -8
- package/dist/components/rating-styles.css +1 -4
- package/dist/components/select-styles.css +5 -18
- package/dist/components/skeleton-styles.css +1 -4
- package/dist/components/slider-styles.css +1 -5
- package/dist/components/sortablelist-styles.css +0 -13
- package/dist/components/spinner-styles.css +1 -4
- package/dist/components/stepper-styles.css +59 -8
- package/dist/components/table-styles.css +1 -5
- package/dist/components/tabs-styles.css +3 -7
- package/dist/components/textarea-styles.css +5 -18
- package/dist/components/theme-base.css +19 -2
- package/dist/components/theme.css +329 -333
- package/dist/components/toast-styles.css +1 -4
- package/dist/components/toggle-styles.css +1 -11
- package/dist/components/tooltip-styles.css +1 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/themes/color.d.ts +52 -0
- package/dist/themes/color.js +91 -0
- package/dist/themes/generator.d.ts +41 -0
- package/dist/themes/generator.js +174 -0
- package/dist/themes/index.d.ts +3 -0
- package/dist/themes/index.js +4 -0
- package/dist/themes/presets.d.ts +445 -0
- package/dist/themes/presets.js +144 -0
- package/dist/themes/schema.d.ts +47 -0
- package/dist/themes/schema.js +34 -0
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A multi-style, multi-theme **Svelte 5** component library. Every component can r
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
9
9
|
- **Svelte 5 native** — uses runes (`$props`, `$state`, `$derived`, `$effect`) and snippets (`{@render children?.()}`).
|
|
10
|
-
- **
|
|
10
|
+
- **12 visual styles** — material, material3, fluent, brutalist, pixel, neon, metro, bootstrap, cartoon, illustration, carbon, liquid-glass.
|
|
11
11
|
- **10 color themes** — default, ocean, forest, rose, midnight, gold, slate, candy, storm, royal.
|
|
12
12
|
- **CSS custom-property based theming** — easy to override or build custom themes without forking.
|
|
13
13
|
- **Tailwind CSS v4** friendly — no `tailwind.config.js` required; just import the theme CSS.
|
package/cli/bin.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// svelte-multistyle-ui CLI — YAML -> Svelte 5 route page generator.
|
|
3
|
+
// Usage: npx svelte-multistyle-ui generate --input page.yaml --output ./src/routes/demo.svelte
|
|
4
|
+
import { generate } from "./generate.js";
|
|
5
|
+
|
|
6
|
+
const VERSION = "0.0.4-alpha";
|
|
7
|
+
|
|
8
|
+
function parseArgs(argv) {
|
|
9
|
+
const positional = [];
|
|
10
|
+
const flags = {};
|
|
11
|
+
for (let i = 0; i < argv.length; i++) {
|
|
12
|
+
const a = argv[i];
|
|
13
|
+
if (a === "-h" || a === "--help") { flags.help = true; continue; }
|
|
14
|
+
if (a === "-v" || a === "--version") { flags.version = true; continue; }
|
|
15
|
+
if (a === "--dry-run") { flags.dryRun = true; continue; }
|
|
16
|
+
if (a === "-w" || a === "--watch") { flags.watch = true; continue; }
|
|
17
|
+
if (a.startsWith("--")) {
|
|
18
|
+
const key = a.slice(2);
|
|
19
|
+
const next = argv[i + 1];
|
|
20
|
+
if (next === undefined || next.startsWith("-")) {
|
|
21
|
+
flags[key] = true;
|
|
22
|
+
} else {
|
|
23
|
+
flags[key] = next;
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
positional.push(a);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return { positional, flags };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function showHelp() {
|
|
34
|
+
process.stdout.write(`svelte-multistyle-ui — UI code generator
|
|
35
|
+
|
|
36
|
+
Usage:
|
|
37
|
+
npx svelte-multistyle-ui generate --input <file.yaml> --output <path.svelte> [options]
|
|
38
|
+
|
|
39
|
+
Subcommands:
|
|
40
|
+
generate Convert a YAML file into a Svelte 5 route page.
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
--input <path> YAML source file (required)
|
|
44
|
+
--output <path> Output .svelte path (required unless --dry-run prints to stdout)
|
|
45
|
+
--style <name> Override YAML style (material, fluent, brutalist, ...)
|
|
46
|
+
--theme <name> Override YAML theme (default, ocean, ...)
|
|
47
|
+
--mode <mode> Override YAML mode: system | light | dark
|
|
48
|
+
--dry-run Print generated Svelte to stdout, do not write a file
|
|
49
|
+
--watch, -w Re-generate when the input YAML changes
|
|
50
|
+
--help, -h Show this help
|
|
51
|
+
--version, -v Show version
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function main() {
|
|
56
|
+
const { positional, flags } = parseArgs(process.argv.slice(2));
|
|
57
|
+
if (flags.help) { showHelp(); return; }
|
|
58
|
+
if (flags.version) { process.stdout.write(VERSION + "\n"); return; }
|
|
59
|
+
|
|
60
|
+
const sub = positional[0];
|
|
61
|
+
if (sub !== "generate") {
|
|
62
|
+
console.error(`Unknown subcommand "${sub || ""}". Run with --help.`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
if (!flags.input) {
|
|
66
|
+
console.error("Missing required flag: --input <file.yaml>");
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
if (!flags.output && !flags.dryRun) {
|
|
70
|
+
console.error('Missing required flag: --output <path.svelte> (or use --dry-run to print to stdout).');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
await generate({
|
|
76
|
+
input: flags.input,
|
|
77
|
+
output: flags.output,
|
|
78
|
+
style: flags.style,
|
|
79
|
+
theme: flags.theme,
|
|
80
|
+
mode: flags.mode,
|
|
81
|
+
dryRun: Boolean(flags.dryRun),
|
|
82
|
+
watch: Boolean(flags.watch),
|
|
83
|
+
});
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error(`✗ ${err.message}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
main();
|
package/cli/emit.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
emitDarkEffect(cfg.mode),
|
|
26
|
+
emitOnMount(),
|
|
27
|
+
].filter((s) => s.length);
|
|
28
|
+
|
|
29
|
+
const scriptBody = sections.map((s) => s.join("\n")).join("\n\n");
|
|
30
|
+
const out = `<script>\n${scriptBody}\n</script>\n` + (bodyMarkup ? `\n${bodyMarkup}\n` : "\n");
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// <script> sections (each returns an array of lines, no trailing newline)
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
function emitImports(used) {
|
|
39
|
+
const components = [...used].sort();
|
|
40
|
+
const lines = ['import { onMount } from "svelte";'];
|
|
41
|
+
if (components.length) {
|
|
42
|
+
lines.push(`import { ${components.join(", ")} } from "svelte-multistyle-ui";`);
|
|
43
|
+
}
|
|
44
|
+
// initMultistyleUI is intentionally NOT imported here — the consuming app
|
|
45
|
+
// sets global style/theme/mode once in its layout, not per-page.
|
|
46
|
+
return lines;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function emitState(state) {
|
|
50
|
+
const lines = [];
|
|
51
|
+
for (const entry of state) {
|
|
52
|
+
if (!entry?.name) continue;
|
|
53
|
+
lines.push(` let ${entry.name} = $state(${defaultLiteral(entry)});`);
|
|
54
|
+
}
|
|
55
|
+
return lines;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function emitDarkEffect(mode) {
|
|
59
|
+
// Self-contained dark/light handling. Reads OS preference only when mode==="system".
|
|
60
|
+
// Independent of the library's internal `defaults` (not re-exported from the package root).
|
|
61
|
+
const m = JSON.stringify(mode);
|
|
62
|
+
return [
|
|
63
|
+
` const MODE = ${m};`,
|
|
64
|
+
` let systemDark = $state(false);`,
|
|
65
|
+
``,
|
|
66
|
+
` $effect(() => {`,
|
|
67
|
+
` if (MODE !== "system") return;`,
|
|
68
|
+
` const mq = window.matchMedia("(prefers-color-scheme: dark)");`,
|
|
69
|
+
` systemDark = mq.matches;`,
|
|
70
|
+
` const handler = (e) => (systemDark = e.matches);`,
|
|
71
|
+
` mq.addEventListener("change", handler);`,
|
|
72
|
+
` return () => mq.removeEventListener("change", handler);`,
|
|
73
|
+
` });`,
|
|
74
|
+
``,
|
|
75
|
+
` const isDarkMode = $derived(MODE === "dark" || (MODE === "system" && systemDark));`,
|
|
76
|
+
``,
|
|
77
|
+
` $effect(() => {`,
|
|
78
|
+
` const root = document.documentElement;`,
|
|
79
|
+
` root.classList.toggle("dark", isDarkMode);`,
|
|
80
|
+
` root.classList.toggle("light", !isDarkMode);`,
|
|
81
|
+
` });`,
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function emitOnMount() {
|
|
86
|
+
// Empty stub. initMultistyleUI belongs in the app layout, not the generated page.
|
|
87
|
+
return [
|
|
88
|
+
` onMount(() => {`,
|
|
89
|
+
` // TODO: add setup logic here`,
|
|
90
|
+
` });`,
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// Markup tree
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
/** @param {any[]} nodes @param {number} depth @param {Set<string>} used */
|
|
99
|
+
function emitBody(nodes, depth, used) {
|
|
100
|
+
return nodes.map((n) => emitNode(n, depth, used)).filter(Boolean).join("\n");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** @returns {string|null} */
|
|
104
|
+
function emitNode(node, depth, used) {
|
|
105
|
+
const indent = IND.repeat(depth);
|
|
106
|
+
// Plain string node => literal text.
|
|
107
|
+
if (typeof node === "string") return indent + node;
|
|
108
|
+
if (!node || typeof node !== "object") return null;
|
|
109
|
+
// { text: "..." } leaf text node.
|
|
110
|
+
if (typeof node.text === "string") return indent + node.text;
|
|
111
|
+
|
|
112
|
+
const name = node.component;
|
|
113
|
+
const entry = registry[name];
|
|
114
|
+
if (!entry) return null; // schema should have caught this already
|
|
115
|
+
used.add(name);
|
|
116
|
+
|
|
117
|
+
const attrs = emitAttrs(node, entry);
|
|
118
|
+
const attrStr = attrs ? ` ${attrs}` : "";
|
|
119
|
+
const open = `${indent}<${name}${attrStr}`;
|
|
120
|
+
|
|
121
|
+
switch (entry.kind) {
|
|
122
|
+
case "leaf":
|
|
123
|
+
return `${open} />`;
|
|
124
|
+
|
|
125
|
+
case "children":
|
|
126
|
+
case "container": {
|
|
127
|
+
const children = node.children;
|
|
128
|
+
if (children == null) return `${open} />`;
|
|
129
|
+
if (typeof children === "string") return `${open}>${children}</${name}>`;
|
|
130
|
+
if (Array.isArray(children)) {
|
|
131
|
+
const inner = emitBody(children, depth + 1, used);
|
|
132
|
+
if (!inner) return `${open} />`;
|
|
133
|
+
return `${open}>\n${inner}\n${indent}</${name}>`;
|
|
134
|
+
}
|
|
135
|
+
return `${open} />`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
case "multi-snippet": {
|
|
139
|
+
const snippets = entry.snippets || [];
|
|
140
|
+
const blocks = snippets.map((sn) => {
|
|
141
|
+
const content = node.snippets?.[sn];
|
|
142
|
+
let inner = "";
|
|
143
|
+
if (typeof content === "string") inner = `${IND.repeat(depth + 2)}${content}`;
|
|
144
|
+
else if (Array.isArray(content)) inner = emitBody(content, depth + 2, used);
|
|
145
|
+
return `${indent}${IND}{#snippet ${sn}()}\n${inner}\n${indent}${IND}{/snippet}`;
|
|
146
|
+
});
|
|
147
|
+
return `${open}>\n${blocks.join("\n")}\n${indent}</${name}>`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
default:
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Build the attribute string (props + bind:) for a component node. */
|
|
156
|
+
function emitAttrs(node, entry) {
|
|
157
|
+
const parts = [];
|
|
158
|
+
if (node.props && typeof node.props === "object") {
|
|
159
|
+
for (const [k, v] of Object.entries(node.props)) {
|
|
160
|
+
const attr = emitProp(k, v);
|
|
161
|
+
if (attr) parts.push(attr);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (node.bind != null) {
|
|
165
|
+
if (typeof node.bind === "string") {
|
|
166
|
+
const prop = entry.primaryBindable;
|
|
167
|
+
if (prop) parts.push(`bind:${prop}={${node.bind}}`);
|
|
168
|
+
} else if (typeof node.bind === "object") {
|
|
169
|
+
for (const [prop, refName] of Object.entries(node.bind)) {
|
|
170
|
+
if (typeof refName === "string") parts.push(`bind:${prop}={${refName}}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return parts.join(" ");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** @returns {string|null} one Svelte attribute, e.g. `label="Hi"`, `value={count}`, `options={[...]}` */
|
|
178
|
+
function emitProp(key, value) {
|
|
179
|
+
if (value === null || value === undefined) return null;
|
|
180
|
+
if (typeof value === "string") {
|
|
181
|
+
const ref = value.match(/^\{([A-Za-z_$][\w$]*)\}$/);
|
|
182
|
+
if (ref) return `${key}={${ref[1]}}`; // reactive ref to a state var
|
|
183
|
+
return `${key}=${JSON.stringify(value)}`; // plain string literal
|
|
184
|
+
}
|
|
185
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
186
|
+
return `${key}={${JSON.stringify(value)}}`;
|
|
187
|
+
}
|
|
188
|
+
if (Array.isArray(value)) return `${key}={${jsValue(value)}}`;
|
|
189
|
+
if (typeof value === "object") return `${key}={${jsValue(value)}}`;
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// JS literal coercion (for arrays / objects / scalars inside {})
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
|
|
197
|
+
/** @returns {string} a JS expression string equivalent to the parsed YAML value */
|
|
198
|
+
function jsValue(v) {
|
|
199
|
+
if (v === null || v === undefined) return "null";
|
|
200
|
+
if (typeof v === "string") return JSON.stringify(v);
|
|
201
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
202
|
+
if (Array.isArray(v)) return `[${v.map(jsValue).join(",")}]`;
|
|
203
|
+
if (typeof v === "object") {
|
|
204
|
+
const entries = Object.entries(v).map(([k, val]) => `${jsKey(k)}:${jsValue(val)}`);
|
|
205
|
+
return `{${entries.join(",")}}`;
|
|
206
|
+
}
|
|
207
|
+
return "null";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function jsKey(k) {
|
|
211
|
+
return /^[A-Za-z_$][\w$]*$/.test(k) ? k : JSON.stringify(k);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
// state default coercion
|
|
216
|
+
// ---------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
function defaultLiteral(entry) {
|
|
219
|
+
if (entry.default !== undefined) return jsValue(entry.default);
|
|
220
|
+
switch (entry.type) {
|
|
221
|
+
case "number": return "0";
|
|
222
|
+
case "bool":
|
|
223
|
+
case "boolean": return "false";
|
|
224
|
+
case "array": return "[]";
|
|
225
|
+
case "object": return "{}";
|
|
226
|
+
default: return '""'; // string / unknown
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import { BarChart, Breadcrumb, Button, Card, Checkbox, Input, Modal, MultiSelect, Popover, Rating, Row, Select, Stepper, Table, Tabs, Textarea } from "svelte-multistyle-ui";
|
|
4
|
+
|
|
5
|
+
let username = $state("");
|
|
6
|
+
let bio = $state("Hello");
|
|
7
|
+
let count = $state(0);
|
|
8
|
+
let rating = $state(3);
|
|
9
|
+
let agreed = $state(false);
|
|
10
|
+
let tags = $state([]);
|
|
11
|
+
let selectedFruit = $state("");
|
|
12
|
+
let selectedTags = $state([]);
|
|
13
|
+
let activeTab = $state(0);
|
|
14
|
+
let modalOpen = $state(false);
|
|
15
|
+
let popoverOpen = $state(false);
|
|
16
|
+
|
|
17
|
+
const MODE = "system";
|
|
18
|
+
let systemDark = $state(false);
|
|
19
|
+
|
|
20
|
+
$effect(() => {
|
|
21
|
+
if (MODE !== "system") return;
|
|
22
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
23
|
+
systemDark = mq.matches;
|
|
24
|
+
const handler = (e) => (systemDark = e.matches);
|
|
25
|
+
mq.addEventListener("change", handler);
|
|
26
|
+
return () => mq.removeEventListener("change", handler);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const isDarkMode = $derived(MODE === "dark" || (MODE === "system" && systemDark));
|
|
30
|
+
|
|
31
|
+
$effect(() => {
|
|
32
|
+
const root = document.documentElement;
|
|
33
|
+
root.classList.toggle("dark", isDarkMode);
|
|
34
|
+
root.classList.toggle("light", !isDarkMode);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
onMount(() => {
|
|
38
|
+
// TODO: add setup logic here
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<Card padding="md" elevated={true} class="space-y-3">
|
|
43
|
+
<Row gap="16px">
|
|
44
|
+
<Input label="Username" placeholder="Enter name" bind:value={username} />
|
|
45
|
+
<Button preset="primary" icon="save">Save</Button>
|
|
46
|
+
</Row>
|
|
47
|
+
<Select label="Pick a fruit" options={[{value:"apple",label:"Apple"},{value:"banana",label:"Banana"},{value:"cherry",label:"Cherry"}]} bind:value={selectedFruit} />
|
|
48
|
+
<MultiSelect label="Tags" options={[{value:"svelte",label:"Svelte"},{value:"ts",label:"TypeScript"},{value:"css",label:"CSS"}]} bind:selected={selectedTags} />
|
|
49
|
+
<Rating bind:value={rating} />
|
|
50
|
+
<Checkbox label="I agree to the terms" bind:checked={agreed} />
|
|
51
|
+
<Textarea label="Bio" placeholder="Tell us about yourself" bind:value={bio} />
|
|
52
|
+
<Tabs tabs={[{id:0,label:"Profile"},{id:1,label:"Settings"}]} bind:active={activeTab} />
|
|
53
|
+
<BarChart title="Quarterly Revenue" xAxisLabel="Quarter" yAxisLabel="Revenue" downloadable={true} data={[{label:"q1",value:12},{label:"q2",value:19},{label:"q3",value:8},{label:"q4",value:15}]} />
|
|
54
|
+
<Table data={[{id:1,name:"Alice",role:"Admin"},{id:2,name:"Bob",role:"User"},{id:3,name:"Cara",role:"Editor"}]} />
|
|
55
|
+
<Stepper steps={[{label:"Account"},{label:"Profile"},{label:"Confirm"}]} />
|
|
56
|
+
<Breadcrumb items={[{label:"Home",href:"/"},{label:"Demo",href:"/demo"}]} />
|
|
57
|
+
<Button preset="primary">Open modal</Button>
|
|
58
|
+
<Modal title="Hello there" bind:open={modalOpen}>
|
|
59
|
+
Modal body content goes here.
|
|
60
|
+
</Modal>
|
|
61
|
+
<Popover position="top" bind:open={popoverOpen}>
|
|
62
|
+
{#snippet children()}
|
|
63
|
+
<Button variant="outlined">Hover me</Button>
|
|
64
|
+
{/snippet}
|
|
65
|
+
{#snippet content()}
|
|
66
|
+
Popover body text
|
|
67
|
+
{/snippet}
|
|
68
|
+
</Popover>
|
|
69
|
+
</Card>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
style: material
|
|
2
|
+
theme: default
|
|
3
|
+
mode: system
|
|
4
|
+
|
|
5
|
+
state:
|
|
6
|
+
- { name: username, type: string, default: "" }
|
|
7
|
+
- { name: bio, type: string, default: "Hello" }
|
|
8
|
+
- { name: count, type: number, default: 0 }
|
|
9
|
+
- { name: rating, type: number, default: 3 }
|
|
10
|
+
- { name: agreed, type: bool, default: false }
|
|
11
|
+
- { name: tags, type: array, default: [] }
|
|
12
|
+
- { name: selectedFruit, type: string, default: "" }
|
|
13
|
+
- { name: selectedTags, type: array, default: [] }
|
|
14
|
+
- { name: activeTab, type: number, default: 0 }
|
|
15
|
+
- { name: modalOpen, type: bool, default: false }
|
|
16
|
+
- { name: popoverOpen, type: bool, default: false }
|
|
17
|
+
|
|
18
|
+
# The page body — a tree of component nodes.
|
|
19
|
+
# - `bind: varName` shorthand: binds the component's primary bindable to a state var
|
|
20
|
+
# - `bind: { prop: var }` explicit named bindable
|
|
21
|
+
# - `props: { k: v }` scalars become attributes; "{var}" is a reactive ref;
|
|
22
|
+
# a YAML sequence becomes an inline JS array literal
|
|
23
|
+
# - `children: [...]` nested nodes (kind: children | container)
|
|
24
|
+
# - `snippets:` named snippets (kind: multi-snippet, e.g. Popover)
|
|
25
|
+
body:
|
|
26
|
+
- component: Card
|
|
27
|
+
props: { padding: md, elevated: true, class: space-y-3 }
|
|
28
|
+
children:
|
|
29
|
+
- component: Row
|
|
30
|
+
props: { gap: 16px }
|
|
31
|
+
children:
|
|
32
|
+
- component: Input
|
|
33
|
+
bind: username
|
|
34
|
+
props: { label: Username, placeholder: Enter name }
|
|
35
|
+
- component: Button
|
|
36
|
+
props: { preset: primary, icon: save }
|
|
37
|
+
children: Save
|
|
38
|
+
|
|
39
|
+
- component: Select
|
|
40
|
+
bind: selectedFruit
|
|
41
|
+
props:
|
|
42
|
+
label: Pick a fruit
|
|
43
|
+
options:
|
|
44
|
+
- { value: apple, label: Apple }
|
|
45
|
+
- { value: banana, label: Banana }
|
|
46
|
+
- { value: cherry, label: Cherry }
|
|
47
|
+
|
|
48
|
+
- component: MultiSelect
|
|
49
|
+
bind: { selected: selectedTags }
|
|
50
|
+
props:
|
|
51
|
+
label: Tags
|
|
52
|
+
options:
|
|
53
|
+
- { value: svelte, label: Svelte }
|
|
54
|
+
- { value: ts, label: TypeScript }
|
|
55
|
+
- { value: css, label: CSS }
|
|
56
|
+
|
|
57
|
+
- component: Rating
|
|
58
|
+
bind: rating
|
|
59
|
+
|
|
60
|
+
- component: Checkbox
|
|
61
|
+
bind: agreed
|
|
62
|
+
props: { label: I agree to the terms }
|
|
63
|
+
|
|
64
|
+
- component: Textarea
|
|
65
|
+
bind: bio
|
|
66
|
+
props: { label: Bio, placeholder: Tell us about yourself }
|
|
67
|
+
|
|
68
|
+
- component: Tabs
|
|
69
|
+
bind: activeTab
|
|
70
|
+
props:
|
|
71
|
+
tabs:
|
|
72
|
+
- { id: 0, label: Profile }
|
|
73
|
+
- { id: 1, label: Settings }
|
|
74
|
+
|
|
75
|
+
- component: BarChart
|
|
76
|
+
props:
|
|
77
|
+
title: Quarterly Revenue
|
|
78
|
+
xAxisLabel: Quarter
|
|
79
|
+
yAxisLabel: Revenue
|
|
80
|
+
downloadable: true
|
|
81
|
+
data:
|
|
82
|
+
- { label: q1, value: 12 }
|
|
83
|
+
- { label: q2, value: 19 }
|
|
84
|
+
- { label: q3, value: 8 }
|
|
85
|
+
- { label: q4, value: 15 }
|
|
86
|
+
|
|
87
|
+
- component: Table
|
|
88
|
+
props:
|
|
89
|
+
data:
|
|
90
|
+
- { id: 1, name: Alice, role: Admin }
|
|
91
|
+
- { id: 2, name: Bob, role: User }
|
|
92
|
+
- { id: 3, name: Cara, role: Editor }
|
|
93
|
+
|
|
94
|
+
- component: Stepper
|
|
95
|
+
props:
|
|
96
|
+
steps:
|
|
97
|
+
- { label: Account }
|
|
98
|
+
- { label: Profile }
|
|
99
|
+
- { label: Confirm }
|
|
100
|
+
|
|
101
|
+
- component: Breadcrumb
|
|
102
|
+
props:
|
|
103
|
+
items:
|
|
104
|
+
- { label: Home, href: "/" }
|
|
105
|
+
- { label: Demo, href: "/demo" }
|
|
106
|
+
|
|
107
|
+
- component: Button
|
|
108
|
+
props: { preset: primary }
|
|
109
|
+
# v1 limitation: event handlers like onclick are not expressible in YAML.
|
|
110
|
+
# Add onclick={() => modalOpen = true} by hand after generation.
|
|
111
|
+
children: Open modal
|
|
112
|
+
|
|
113
|
+
- component: Modal
|
|
114
|
+
bind: { open: modalOpen }
|
|
115
|
+
props: { title: Hello there }
|
|
116
|
+
children:
|
|
117
|
+
- text: "Modal body content goes here."
|
|
118
|
+
|
|
119
|
+
- component: Popover
|
|
120
|
+
bind: { open: popoverOpen }
|
|
121
|
+
props: { position: top }
|
|
122
|
+
snippets:
|
|
123
|
+
children:
|
|
124
|
+
- component: Button
|
|
125
|
+
props: { variant: outlined }
|
|
126
|
+
children: Hover me
|
|
127
|
+
content:
|
|
128
|
+
- text: "Popover body text"
|
package/cli/generate.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Orchestrator: parse YAML -> validate -> emit Svelte -> write file (or stdout).
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import yaml from "js-yaml";
|
|
5
|
+
import { validate } from "./schema.js";
|
|
6
|
+
import { emitPage } from "./emit.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} opts
|
|
10
|
+
* @param {string} opts.input
|
|
11
|
+
* @param {string} [opts.output]
|
|
12
|
+
* @param {string} [opts.style]
|
|
13
|
+
* @param {string} [opts.theme]
|
|
14
|
+
* @param {string} [opts.mode]
|
|
15
|
+
* @param {boolean} [opts.dryRun]
|
|
16
|
+
* @param {boolean} [opts.watch]
|
|
17
|
+
*/
|
|
18
|
+
export async function generate(opts) {
|
|
19
|
+
const { input, output, style, theme, mode, dryRun, watch } = opts;
|
|
20
|
+
|
|
21
|
+
const runOnce = () => {
|
|
22
|
+
const src = fs.readFileSync(input, "utf8");
|
|
23
|
+
let doc;
|
|
24
|
+
try {
|
|
25
|
+
doc = yaml.load(src);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
throw new Error(`YAML parse error in ${input}:\n${e.message}`);
|
|
28
|
+
}
|
|
29
|
+
const { errors, warnings } = validate(doc);
|
|
30
|
+
for (const w of warnings) console.error(`! ${w}`);
|
|
31
|
+
if (errors.length) {
|
|
32
|
+
throw new Error("Validation failed:\n" + errors.map((e) => " - " + e).join("\n"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const cfg = {
|
|
36
|
+
style: style || doc?.style || "material",
|
|
37
|
+
theme: theme || doc?.theme || "default",
|
|
38
|
+
mode: mode || doc?.mode || "system",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const code = emitPage(doc, cfg);
|
|
42
|
+
|
|
43
|
+
if (dryRun) {
|
|
44
|
+
process.stdout.write(code);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
fs.mkdirSync(path.dirname(output), { recursive: true });
|
|
48
|
+
fs.writeFileSync(output, code, "utf8");
|
|
49
|
+
console.error(`✓ Wrote ${output} (${code.length} bytes)`);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
runOnce();
|
|
53
|
+
|
|
54
|
+
if (watch) {
|
|
55
|
+
let timer = null;
|
|
56
|
+
fs.watch(input, () => {
|
|
57
|
+
clearTimeout(timer);
|
|
58
|
+
timer = setTimeout(() => {
|
|
59
|
+
try {
|
|
60
|
+
runOnce();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(`✗ ${e.message}`);
|
|
63
|
+
}
|
|
64
|
+
}, 250);
|
|
65
|
+
});
|
|
66
|
+
console.error(`↻ Watching ${input} for changes (Ctrl+C to stop)`);
|
|
67
|
+
}
|
|
68
|
+
}
|