svelte-multistyle-ui 0.0.3-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.
Files changed (77) hide show
  1. package/README.md +1 -1
  2. package/cli/bin.js +90 -0
  3. package/cli/emit.js +228 -0
  4. package/cli/fixtures/sample.expected.svelte +69 -0
  5. package/cli/fixtures/sample.yaml +128 -0
  6. package/cli/generate.js +68 -0
  7. package/cli/registry.js +95 -0
  8. package/cli/schema.js +145 -0
  9. package/dist/components/Button.svelte +3 -1
  10. package/dist/components/Button.svelte.d.ts +2 -0
  11. package/dist/components/DatePicker.svelte +176 -55
  12. package/dist/components/FAB.svelte +3 -1
  13. package/dist/components/FAB.svelte.d.ts +2 -0
  14. package/dist/components/IconButton.svelte +3 -1
  15. package/dist/components/IconButton.svelte.d.ts +2 -0
  16. package/dist/components/Input.svelte +3 -3
  17. package/dist/components/MultiSelect.svelte +19 -2
  18. package/dist/components/Select.svelte +4 -3
  19. package/dist/components/Stepper.svelte +91 -33
  20. package/dist/components/Textarea.svelte +1 -2
  21. package/dist/components/accordion-styles.css +1 -9
  22. package/dist/components/alert-styles.css +1 -4
  23. package/dist/components/avatar-styles.css +1 -4
  24. package/dist/components/breadcrumb-styles.css +1 -7
  25. package/dist/components/button-styles.css +44 -52
  26. package/dist/components/buttongroup-styles.css +1 -5
  27. package/dist/components/card-styles.css +1 -9
  28. package/dist/components/carousel-styles.css +1 -5
  29. package/dist/components/charts/Chart.svelte +63 -3
  30. package/dist/components/charts/chart-config.d.ts +27 -2
  31. package/dist/components/charts/chart-config.js +180 -67
  32. package/dist/components/charts/chart-styles.css +32 -17
  33. package/dist/components/checkbox-styles.css +2 -10
  34. package/dist/components/chip-styles.css +1 -4
  35. package/dist/components/commandpalette-styles.css +0 -4
  36. package/dist/components/datepicker-styles.css +967 -1011
  37. package/dist/components/divider-styles.css +1 -4
  38. package/dist/components/drawer-styles.css +0 -4
  39. package/dist/components/dropdown-styles.css +0 -5
  40. package/dist/components/fab-styles.css +18 -12
  41. package/dist/components/fileupload-styles.css +2 -10
  42. package/dist/components/iconbutton-styles.css +33 -34
  43. package/dist/components/input-styles.css +17 -50
  44. package/dist/components/modal-styles.css +0 -8
  45. package/dist/components/multiselect-styles.css +167 -31
  46. package/dist/components/pagination-styles.css +2 -5
  47. package/dist/components/popover-styles.css +0 -4
  48. package/dist/components/progressbar-styles.css +1 -5
  49. package/dist/components/radio-styles.css +1 -8
  50. package/dist/components/rating-styles.css +1 -4
  51. package/dist/components/select-styles.css +50 -21
  52. package/dist/components/skeleton-styles.css +1 -4
  53. package/dist/components/slider-styles.css +1 -5
  54. package/dist/components/sortablelist-styles.css +0 -13
  55. package/dist/components/spinner-styles.css +1 -4
  56. package/dist/components/stepper-styles.css +59 -8
  57. package/dist/components/table-styles.css +1 -5
  58. package/dist/components/tabs-styles.css +3 -7
  59. package/dist/components/textarea-styles.css +6 -19
  60. package/dist/components/theme-base.css +19 -2
  61. package/dist/components/theme.css +329 -333
  62. package/dist/components/toast-styles.css +1 -4
  63. package/dist/components/toggle-styles.css +1 -11
  64. package/dist/components/tooltip-styles.css +1 -4
  65. package/dist/index.d.ts +1 -0
  66. package/dist/index.js +3 -0
  67. package/dist/themes/color.d.ts +52 -0
  68. package/dist/themes/color.js +91 -0
  69. package/dist/themes/generator.d.ts +41 -0
  70. package/dist/themes/generator.js +174 -0
  71. package/dist/themes/index.d.ts +3 -0
  72. package/dist/themes/index.js +4 -0
  73. package/dist/themes/presets.d.ts +445 -0
  74. package/dist/themes/presets.js +144 -0
  75. package/dist/themes/schema.d.ts +47 -0
  76. package/dist/themes/schema.js +34 -0
  77. package/package.json +19 -4
@@ -0,0 +1,95 @@
1
+ // Component registry for the YAML -> Svelte page generator.
2
+ // Keyed by the export name from src/lib/index.js. Every shipped component has
3
+ // exactly one entry. If a new component is exported from index.js, add a matching
4
+ // entry here and run `pnpm gen:sample` to verify the registry-completeness check.
5
+ //
6
+ // Entry shape:
7
+ // importName JS identifier emitted in the import statement (= key)
8
+ // kind "leaf" (no children) | "children" (implicit children snippet)
9
+ // | "container" (layout box wrapping children) | "multi-snippet"
10
+ // bindable prop names that are $bindable(...) in the component
11
+ // primaryBindable the prop used by the `bind: varName` shorthand
12
+ // listProps props whose YAML value is a sequence (documentation/validation)
13
+ // objectProps props whose YAML value is a map (documentation/validation)
14
+ // snippets named snippet props for multi-snippet kind
15
+ // chart forwards chart data/series/labels/options to the Chart base
16
+ //
17
+ // Note: emit.js treats ANY array prop as an inline JS array literal and ANY object
18
+ // prop as an inline JS object literal, so listProps/objectProps are advisory unless
19
+ // future validation needs them. They are kept for clarity and future strict checks.
20
+
21
+ /** @type {Record<string, any>} */
22
+ const registry = {
23
+ // ---------------- Form ----------------
24
+ Input: { importName: "Input", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
25
+ Textarea: { importName: "Textarea", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
26
+ Select: { importName: "Select", kind: "leaf", bindable: ["value"], primaryBindable: "value", listProps: ["options"] },
27
+ MultiSelect: { importName: "MultiSelect", kind: "leaf", bindable: ["selected"], primaryBindable: "selected", listProps: ["options"] },
28
+ Checkbox: { importName: "Checkbox", kind: "leaf", bindable: ["checked"], primaryBindable: "checked" },
29
+ Radio: { importName: "Radio", kind: "leaf", bindable: ["group"], primaryBindable: "group" },
30
+ Toggle: { importName: "Toggle", kind: "leaf", bindable: ["checked"], primaryBindable: "checked" },
31
+ Slider: { importName: "Slider", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
32
+ FileUpload: { importName: "FileUpload", kind: "leaf" },
33
+ DatePicker: { importName: "DatePicker", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
34
+ ButtonGroup: { importName: "ButtonGroup", kind: "leaf", bindable: ["value"], primaryBindable: "value", listProps: ["items"] },
35
+ SortableList: { importName: "SortableList", kind: "children", bindable: ["items"], primaryBindable: "items", listProps: ["items"] },
36
+
37
+ // ---------------- Buttons ----------------
38
+ Button: { importName: "Button", kind: "children" }, // onclick is a passthrough scalar prop, NOT bindable
39
+ IconButton: { importName: "IconButton", kind: "children" },
40
+ FAB: { importName: "FAB", kind: "children" },
41
+
42
+ // ---------------- Layout ----------------
43
+ Card: { importName: "Card", kind: "container" },
44
+ Row: { importName: "Row", kind: "container" },
45
+ Column: { importName: "Column", kind: "container" },
46
+ Grid: { importName: "Grid", kind: "container" },
47
+ Divider: { importName: "Divider", kind: "leaf" },
48
+ Accordion: { importName: "Accordion", kind: "leaf", listProps: ["items"] },
49
+ DropdownMenu: { importName: "DropdownMenu", kind: "children", listProps: ["items"] },
50
+
51
+ // ---------------- Navigation ----------------
52
+ Tabs: { importName: "Tabs", kind: "leaf", bindable: ["active"], primaryBindable: "active", listProps: ["tabs"] },
53
+ Breadcrumb: { importName: "Breadcrumb", kind: "leaf", listProps: ["items"] },
54
+ Pagination: { importName: "Pagination", kind: "leaf", bindable: ["current"], primaryBindable: "current" },
55
+ Stepper: { importName: "Stepper", kind: "leaf", listProps: ["steps"] },
56
+
57
+ // ---------------- Data Display ----------------
58
+ Avatar: { importName: "Avatar", kind: "leaf" },
59
+ Chip: { importName: "Chip", kind: "children" },
60
+ Tooltip: { importName: "Tooltip", kind: "children" },
61
+ ProgressBar: { importName: "ProgressBar", kind: "leaf" },
62
+ Table: { importName: "Table", kind: "leaf", listProps: ["data"] }, // columns derived at runtime from data[0]
63
+ Spinner: { importName: "Spinner", kind: "leaf" },
64
+ Skeleton: { importName: "Skeleton", kind: "leaf" },
65
+
66
+ // ---------------- Feedback ----------------
67
+ Alert: { importName: "Alert", kind: "children" },
68
+ Rating: { importName: "Rating", kind: "leaf", bindable: ["value"], primaryBindable: "value" },
69
+ Toast: { importName: "Toast", kind: "leaf", bindable: ["toasts"], primaryBindable: "toasts", listProps: ["toasts"] },
70
+
71
+ // ---------------- Overlays ----------------
72
+ Modal: { importName: "Modal", kind: "children", bindable: ["open"], primaryBindable: "open" },
73
+ Drawer: { importName: "Drawer", kind: "children", bindable: ["open"], primaryBindable: "open" },
74
+ CommandPalette:{ importName: "CommandPalette",kind: "leaf", bindable: ["open"], primaryBindable: "open", listProps: ["groups"] },
75
+ Popover: { importName: "Popover", kind: "multi-snippet", snippets: ["children", "content"], bindable: ["open"], primaryBindable: "open" },
76
+
77
+ // ---------------- Charts (all forward to Chart base) ----------------
78
+ BarChart: { importName: "BarChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
79
+ LineChart: { importName: "LineChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
80
+ PieChart: { importName: "PieChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
81
+ DoughnutChart: { importName: "DoughnutChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
82
+ RadarChart: { importName: "RadarChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
83
+ PolarAreaChart: { importName: "PolarAreaChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
84
+ ScatterChart: { importName: "ScatterChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
85
+ BubbleChart: { importName: "BubbleChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
86
+ StackedBarChart: { importName: "StackedBarChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
87
+ StackedLineChart:{ importName: "StackedLineChart",kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
88
+ ComboChart: { importName: "ComboChart", kind: "leaf", chart: true, listProps: ["data", "series", "labels"], objectProps: ["options"] },
89
+ };
90
+
91
+ // Exported component names — used by the registry-completeness check to diff
92
+ // against src/lib/index.js. Keep in sync with index.js when adding components.
93
+ export const registryKeys = Object.keys(registry);
94
+
95
+ export { registry };
package/cli/schema.js ADDED
@@ -0,0 +1,145 @@
1
+ // Lightweight YAML page-schema validation. Plain asserts, no zod.
2
+ // Returns { errors, warnings }. Errors stop generation; warnings go to stderr.
3
+ import { registry } from "./registry.js";
4
+
5
+ const TOP_KEYS = new Set(["style", "theme", "mode", "state", "body", "onMount", "imports"]);
6
+ const VALID_MODES = new Set(["system", "light", "dark"]);
7
+ const VALID_TYPES = new Set(["string", "number", "bool", "boolean", "array", "object"]);
8
+
9
+ /**
10
+ * @param {any} doc parsed YAML
11
+ * @returns {{errors:string[], warnings:string[], stateNames:Set<string>}}
12
+ */
13
+ export function validate(doc) {
14
+ const errors = [];
15
+ const warnings = [];
16
+ const stateNames = new Set();
17
+
18
+ if (doc == null || typeof doc !== "object" || Array.isArray(doc)) {
19
+ errors.push("Top-level YAML must be a mapping (object).");
20
+ return { errors, warnings, stateNames };
21
+ }
22
+
23
+ for (const k of Object.keys(doc)) {
24
+ if (!TOP_KEYS.has(k)) warnings.push(`Unknown top-level key "${k}" (ignored).`);
25
+ }
26
+
27
+ if (doc.mode != null && !VALID_MODES.has(doc.mode)) {
28
+ errors.push(`mode must be one of system | light | dark, got "${doc.mode}".`);
29
+ }
30
+
31
+ // state ---------------------------------------------------------------
32
+ if (doc.state != null) {
33
+ if (!Array.isArray(doc.state)) {
34
+ errors.push("state must be a list of { name, type, default? }.");
35
+ } else {
36
+ for (const entry of doc.state) {
37
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
38
+ errors.push("state entry must be a mapping.");
39
+ continue;
40
+ }
41
+ if (!entry.name || typeof entry.name !== "string") {
42
+ errors.push('state entry missing string "name".');
43
+ continue;
44
+ }
45
+ if (!/^[A-Za-z_$][\w$]*$/.test(entry.name)) {
46
+ errors.push(`state name "${entry.name}" is not a valid JS identifier.`);
47
+ continue;
48
+ }
49
+ if (stateNames.has(entry.name)) errors.push(`Duplicate state name "${entry.name}".`);
50
+ stateNames.add(entry.name);
51
+ if (entry.type != null && !VALID_TYPES.has(entry.type)) {
52
+ warnings.push(`state "${entry.name}" has unknown type "${entry.type}"; defaulting to string.`);
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ // body ----------------------------------------------------------------
59
+ if (doc.body == null) {
60
+ warnings.push("No body key — generated page will have an empty markup tree.");
61
+ } else if (!Array.isArray(doc.body)) {
62
+ errors.push("body must be a list of component nodes.");
63
+ } else {
64
+ walkBody(doc.body, stateNames, errors, warnings, 0);
65
+ }
66
+
67
+ return { errors, warnings, stateNames };
68
+ }
69
+
70
+ function walkBody(nodes, stateNames, errors, warnings, depth) {
71
+ if (depth > 10) {
72
+ warnings.push("Body nesting deeper than 10 levels (likely a schema mistake); skipping deeper checks.");
73
+ return;
74
+ }
75
+ for (const node of nodes) walkNode(node, stateNames, errors, warnings, depth);
76
+ }
77
+
78
+ function walkNode(node, stateNames, errors, warnings, depth) {
79
+ if (node == null) return;
80
+ if (typeof node === "string") return; // literal text
81
+ if (typeof node !== "object" || Array.isArray(node)) {
82
+ errors.push("Body node must be a mapping or string.");
83
+ return;
84
+ }
85
+ if (typeof node.text === "string") return; // { text: "..." }
86
+
87
+ if (!node.component) {
88
+ errors.push('Body node missing required "component" key.');
89
+ return;
90
+ }
91
+ if (typeof node.component !== "string") {
92
+ errors.push(`Component name must be a string, got ${typeof node.component}.`);
93
+ return;
94
+ }
95
+ const entry = registry[node.component];
96
+ if (!entry) {
97
+ errors.push(`Unknown component "${node.component}". Available: ${Object.keys(registry).join(", ")}.`);
98
+ return;
99
+ }
100
+
101
+ validateBind(node, entry, stateNames, errors);
102
+
103
+ if ((node.children != null || node.text != null) && entry.kind === "leaf") {
104
+ warnings.push(`Component "${node.component}" takes no children; ignoring.`);
105
+ }
106
+
107
+ if (entry.kind === "multi-snippet") {
108
+ const provided = node.snippets && typeof node.snippets === "object" ? Object.keys(node.snippets) : [];
109
+ for (const sn of provided) {
110
+ if (!(entry.snippets || []).includes(sn)) {
111
+ warnings.push(`Component "${node.component}" has no snippet "${sn}".`);
112
+ } else if (Array.isArray(node.snippets[sn])) {
113
+ walkBody(node.snippets[sn], stateNames, errors, warnings, depth + 1);
114
+ }
115
+ }
116
+ }
117
+
118
+ if (Array.isArray(node.children)) walkBody(node.children, stateNames, errors, warnings, depth + 1);
119
+ }
120
+
121
+ function validateBind(node, entry, stateNames, errors) {
122
+ const bind = node.bind;
123
+ if (bind == null) return;
124
+ if (typeof bind === "string") {
125
+ if (!entry.primaryBindable) {
126
+ errors.push(`Component "${node.component}" has no primary bindable prop; use "bind: { prop: var }" explicitly or remove bind.`);
127
+ } else if (!stateNames.has(bind)) {
128
+ errors.push(`Bind target "${bind}" is not declared in state:. Add it under state: first.`);
129
+ }
130
+ return;
131
+ }
132
+ if (typeof bind === "object" && !Array.isArray(bind)) {
133
+ for (const [prop, refName] of Object.entries(bind)) {
134
+ if (typeof refName !== "string") {
135
+ errors.push(`bind.${prop} must be a variable name string.`);
136
+ continue;
137
+ }
138
+ if (!stateNames.has(refName)) {
139
+ errors.push(`Bind target "${refName}" (for prop "${prop}") is not declared in state:.`);
140
+ }
141
+ }
142
+ return;
143
+ }
144
+ errors.push(`bind must be a variable name string or a mapping of { prop: var }, got ${typeof bind}.`);
145
+ }
@@ -6,6 +6,7 @@
6
6
  style: styleProp,
7
7
  theme: themeProp,
8
8
  variant = "filled",
9
+ preset = "primary",
9
10
  size = "md",
10
11
  disabled = false,
11
12
  icon,
@@ -20,11 +21,12 @@
20
21
  const styleClass = $derived(`s-button-${style}`);
21
22
  const themeClass = $derived(`theme-${theme}`);
22
23
  const variantClass = $derived(`btn-${variant}`);
24
+ const presetClass = $derived(`btn-${preset}`);
23
25
  const sizeClass = $derived(`btn-${size}`);
24
26
  </script>
25
27
 
26
28
  <button
27
- class="s-button {styleClass} {themeClass} {variantClass} {sizeClass}"
29
+ class="s-button {styleClass} {themeClass} {variantClass} {presetClass} {sizeClass}"
28
30
  {disabled}
29
31
  {onclick}
30
32
  {...rest}
@@ -7,6 +7,7 @@ declare const Button: import("svelte").Component<{
7
7
  style: any;
8
8
  theme: any;
9
9
  variant?: string;
10
+ preset?: string;
10
11
  size?: string;
11
12
  disabled?: boolean;
12
13
  icon: any;
@@ -17,6 +18,7 @@ type $$ComponentProps = {
17
18
  style: any;
18
19
  theme: any;
19
20
  variant?: string;
21
+ preset?: string;
20
22
  size?: string;
21
23
  disabled?: boolean;
22
24
  icon: any;