@theweekendprojects/emvb-daisyui 0.0.0-stage → 0.2.1

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 (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +106 -2
  3. package/licenses/daisyui-MIT.txt +3 -0
  4. package/package.json +55 -4
  5. package/src/catalog/basic.ts +407 -0
  6. package/src/catalog/class-names.ts +623 -0
  7. package/src/catalog/countdown.ts +392 -0
  8. package/src/catalog/data-display.ts +563 -0
  9. package/src/catalog/forms.ts +433 -0
  10. package/src/catalog/index.ts +77 -0
  11. package/src/catalog/interactive.ts +567 -0
  12. package/src/catalog/layout-marketing.ts +641 -0
  13. package/src/catalog/missing-complex.ts +430 -0
  14. package/src/catalog/missing-primitives.ts +409 -0
  15. package/src/catalog/navigation.ts +438 -0
  16. package/src/catalog/value-class.ts +20 -0
  17. package/src/compatibility/index.ts +104 -0
  18. package/src/compound/editor.ts +299 -0
  19. package/src/compound/index.ts +157 -0
  20. package/src/conformance/cli.ts +9 -0
  21. package/src/conformance/compile.ts +77 -0
  22. package/src/conformance/index.ts +4 -0
  23. package/src/conformance/manifest.ts +39 -0
  24. package/src/conformance/official-inventory.ts +135 -0
  25. package/src/conformance/report-cli.ts +5 -0
  26. package/src/conformance/report.ts +59 -0
  27. package/src/conformance/verify-css.ts +22 -0
  28. package/src/extension/class-token.ts +11 -0
  29. package/src/extension/classes.ts +636 -0
  30. package/src/extension/collect-classes.ts +73 -0
  31. package/src/extension/content.ts +93 -0
  32. package/src/extension/daisy.css +12441 -0
  33. package/src/extension/daisy.js +1 -0
  34. package/src/extension/elements.ts +262 -0
  35. package/src/extension/index.ts +39 -0
  36. package/src/extension/to-output.ts +113 -0
  37. package/src/generator/artifacts.ts +81 -0
  38. package/src/generator/class-names.ts +35 -0
  39. package/src/generator/cli.ts +21 -0
  40. package/src/generator/generate.ts +122 -0
  41. package/src/generator/index.ts +2 -0
  42. package/src/generator/write-class-names.ts +10 -0
  43. package/src/index.ts +12 -0
  44. package/src/render/classes.ts +48 -0
  45. package/src/render/href.ts +19 -0
  46. package/src/render/index.ts +3 -0
  47. package/src/render/provider.ts +37 -0
  48. package/src/renderer.ts +6 -0
  49. package/src/runtime/browser.ts +11 -0
  50. package/src/runtime/index.ts +41 -0
  51. package/src/test-support.ts +13 -0
  52. package/src/themes/index.ts +72 -0
  53. package/src/types.ts +116 -0
  54. package/src/validation/index.ts +153 -0
  55. package/src/verified/primitives.ts +62 -0
@@ -0,0 +1,438 @@
1
+ import type { DaisyComponentDefinition, DaisyVNode } from "../types.ts";
2
+ import { safeHref } from "../render/href.ts";
3
+
4
+ const sizes = ["xs", "sm", "md", "lg", "xl"] as const;
5
+ const sizeMap = (prefix: string) =>
6
+ Object.fromEntries(sizes.map((size) => [size, `${prefix}-${size}`]));
7
+ const lines = (value: unknown) =>
8
+ String(value ?? "")
9
+ .split(/\r?\n/)
10
+ .map((item) => item.trim())
11
+ .filter(Boolean);
12
+ const navItem = (label: string, href = "#"): DaisyVNode => ({
13
+ tag: "li",
14
+ attrs: {},
15
+ children: [{ tag: "a", attrs: { href: safeHref(href) }, children: [label] }],
16
+ });
17
+
18
+ export const NAVBAR: DaisyComponentDefinition = {
19
+ id: "navbar",
20
+ label: "Navbar",
21
+ category: "Navigation",
22
+ tag: "nav",
23
+ rootClass: "navbar",
24
+ role: "navigation",
25
+ container: true,
26
+ fields: [
27
+ {
28
+ key: "ariaLabel",
29
+ label: "Navigation label",
30
+ kind: "text",
31
+ default: "Primary navigation",
32
+ attribute: "aria-label",
33
+ },
34
+ { key: "brand", label: "Brand", kind: "text", default: "EmDash" },
35
+ { key: "brandHref", label: "Brand link", kind: "href", default: "/" },
36
+ {
37
+ key: "items",
38
+ label: "Items, Label|URL per line",
39
+ kind: "textarea",
40
+ default: "Home|/\nAbout|/about\nContact|/contact",
41
+ },
42
+ {
43
+ key: "position",
44
+ label: "Position",
45
+ kind: "select",
46
+ default: "static",
47
+ options: ["static", "sticky"],
48
+ classMap: { static: "", sticky: "sticky top-0 z-50" },
49
+ },
50
+ ],
51
+ build(node, classes, children) {
52
+ const items = lines(node.props.items).map((entry) => {
53
+ const [label, href = "#"] = entry.split("|");
54
+ return navItem(label || "Link", href || "#");
55
+ });
56
+ return {
57
+ tag: "nav",
58
+ attrs: {
59
+ class: classes.filter(Boolean).join(" "),
60
+ "aria-label": String(node.props.ariaLabel),
61
+ },
62
+ children: [
63
+ {
64
+ tag: "div",
65
+ attrs: { class: "navbar-start" },
66
+ children: [
67
+ {
68
+ tag: "a",
69
+ attrs: { class: "btn btn-ghost text-xl", href: safeHref(node.props.brandHref) },
70
+ children: [String(node.props.brand)],
71
+ },
72
+ ],
73
+ },
74
+ {
75
+ tag: "div",
76
+ attrs: { class: "navbar-center hidden lg:flex" },
77
+ children: [{ tag: "ul", attrs: { class: "menu menu-horizontal px-1" }, children: items }],
78
+ },
79
+ { tag: "div", attrs: { class: "navbar-end" }, children },
80
+ ],
81
+ };
82
+ },
83
+ };
84
+
85
+ export const MENU: DaisyComponentDefinition = {
86
+ id: "menu",
87
+ label: "Menu",
88
+ category: "Navigation",
89
+ tag: "ul",
90
+ rootClass: "menu",
91
+ role: "navigation",
92
+ fields: [
93
+ {
94
+ key: "ariaLabel",
95
+ label: "Menu label",
96
+ kind: "text",
97
+ default: "Menu",
98
+ attribute: "aria-label",
99
+ },
100
+ {
101
+ key: "items",
102
+ label: "Items, Label|URL per line",
103
+ kind: "textarea",
104
+ default: "Dashboard|/dashboard\nSettings|/settings",
105
+ },
106
+ {
107
+ key: "direction",
108
+ label: "Direction",
109
+ kind: "select",
110
+ default: "vertical",
111
+ options: ["vertical", "horizontal"],
112
+ classMap: { vertical: "menu-vertical", horizontal: "menu-horizontal" },
113
+ },
114
+ {
115
+ key: "size",
116
+ label: "Size",
117
+ kind: "select",
118
+ default: "md",
119
+ options: sizes,
120
+ classMap: sizeMap("menu"),
121
+ },
122
+ ],
123
+ build(node, classes) {
124
+ return {
125
+ tag: "ul",
126
+ attrs: { class: classes.join(" "), "aria-label": String(node.props.ariaLabel) },
127
+ children: lines(node.props.items).map((entry) => {
128
+ const [label, href = "#"] = entry.split("|");
129
+ return navItem(label || "Link", href || "#");
130
+ }),
131
+ };
132
+ },
133
+ };
134
+
135
+ export const BREADCRUMBS: DaisyComponentDefinition = {
136
+ id: "breadcrumbs",
137
+ label: "Breadcrumbs",
138
+ category: "Navigation",
139
+ tag: "nav",
140
+ rootClass: "breadcrumbs",
141
+ role: "navigation",
142
+ fields: [
143
+ {
144
+ key: "ariaLabel",
145
+ label: "Breadcrumb label",
146
+ kind: "text",
147
+ default: "Breadcrumb",
148
+ attribute: "aria-label",
149
+ },
150
+ {
151
+ key: "items",
152
+ label: "Items, Label|URL per line",
153
+ kind: "textarea",
154
+ default: "Home|/\nDocuments|/documents\nCurrent|",
155
+ },
156
+ ],
157
+ build(node, classes) {
158
+ const items = lines(node.props.items);
159
+ return {
160
+ tag: "nav",
161
+ attrs: { class: classes.join(" "), "aria-label": String(node.props.ariaLabel) },
162
+ children: [
163
+ {
164
+ tag: "ul",
165
+ attrs: {},
166
+ children: items.map((entry, index) => {
167
+ const [label, href = ""] = entry.split("|");
168
+ return {
169
+ tag: "li",
170
+ attrs: index === items.length - 1 ? { "aria-current": "page" } : {},
171
+ children: href
172
+ ? [{ tag: "a", attrs: { href: safeHref(href) }, children: [label || "Page"] }]
173
+ : [label || "Page"],
174
+ };
175
+ }),
176
+ },
177
+ ],
178
+ };
179
+ },
180
+ };
181
+
182
+ export const PAGINATION: DaisyComponentDefinition = {
183
+ id: "pagination",
184
+ label: "Pagination",
185
+ category: "Navigation",
186
+ tag: "nav",
187
+ rootClass: "join",
188
+ role: "navigation",
189
+ fields: [
190
+ {
191
+ key: "ariaLabel",
192
+ label: "Pagination label",
193
+ kind: "text",
194
+ default: "Pagination",
195
+ attribute: "aria-label",
196
+ },
197
+ { key: "pages", label: "Page count", kind: "number", default: 5 },
198
+ { key: "current", label: "Current page", kind: "number", default: 1 },
199
+ { key: "baseHref", label: "Base URL", kind: "href", default: "?page=" },
200
+ {
201
+ key: "size",
202
+ label: "Size",
203
+ kind: "select",
204
+ default: "md",
205
+ options: sizes,
206
+ },
207
+ {
208
+ key: "direction",
209
+ label: "Direction",
210
+ kind: "select",
211
+ default: "horizontal",
212
+ options: ["horizontal", "vertical"],
213
+ classMap: { horizontal: "join-horizontal", vertical: "join-vertical" },
214
+ },
215
+ ],
216
+ build(node, classes) {
217
+ const pages = Math.min(20, Math.max(1, Number(node.props.pages)));
218
+ const current = Math.min(pages, Math.max(1, Number(node.props.current)));
219
+ // daisyUI has no size classes for a join; the size belongs on each page button (btn-xs ... btn-xl).
220
+ const size = `btn-${String(node.props.size ?? "md")}`;
221
+ const children: DaisyVNode[] = [];
222
+ for (let page = 1; page <= pages; page++)
223
+ children.push({
224
+ tag: "a",
225
+ attrs: {
226
+ // w-auto!: keeps each page button natural width; see componentClasses for why.
227
+ class: `join-item btn ${size}${page === current ? " btn-active" : ""} w-auto!`,
228
+ href: safeHref(`${node.props.baseHref}${page}`),
229
+ ...(page === current ? { "aria-current": "page" } : {}),
230
+ },
231
+ children: [String(page)],
232
+ });
233
+ return {
234
+ tag: "nav",
235
+ attrs: { class: classes.join(" "), "aria-label": String(node.props.ariaLabel) },
236
+ children,
237
+ };
238
+ },
239
+ };
240
+
241
+ const STEP_TONES = new Set([
242
+ "neutral",
243
+ "primary",
244
+ "secondary",
245
+ "accent",
246
+ "info",
247
+ "success",
248
+ "warning",
249
+ "error",
250
+ ]);
251
+
252
+ export const STEPS: DaisyComponentDefinition = {
253
+ id: "steps",
254
+ label: "Steps",
255
+ category: "Navigation",
256
+ tag: "ol",
257
+ rootClass: "steps",
258
+ fields: [
259
+ {
260
+ key: "items",
261
+ label: "Steps, Label or Label|colour per line",
262
+ kind: "textarea",
263
+ default: "Register\nChoose plan\nPurchase\nReceive product",
264
+ },
265
+ { key: "current", label: "Current step", kind: "number", default: 2 },
266
+ {
267
+ key: "direction",
268
+ label: "Direction",
269
+ kind: "select",
270
+ default: "horizontal",
271
+ options: ["horizontal", "vertical"],
272
+ classMap: { horizontal: "steps-horizontal", vertical: "steps-vertical" },
273
+ },
274
+ {
275
+ // Colours the completed steps; daisyUI puts the colour on each step, not on the list.
276
+ key: "tone",
277
+ label: "Completed colour",
278
+ kind: "select",
279
+ default: "primary",
280
+ options: ["neutral", "primary", "secondary", "accent", "info", "success", "warning", "error"],
281
+ },
282
+ ],
283
+ build(node, classes) {
284
+ const items = lines(node.props.items);
285
+ const tone = String(node.props.tone ?? "primary");
286
+ const current = Math.min(items.length, Math.max(0, Number(node.props.current)));
287
+ return {
288
+ tag: "ol",
289
+ attrs: { class: classes.join(" "), "aria-label": "Progress" },
290
+ children: items.map((entry, index) => {
291
+ // "Label|colour" sets one step's colour; otherwise completed steps take the shared tone.
292
+ const [label = "", own = ""] = entry.split("|");
293
+ const colour = STEP_TONES.has(own.trim()) ? own.trim() : index < current ? tone : "";
294
+ return {
295
+ tag: "li",
296
+ attrs: {
297
+ class: colour ? `step step-${colour}` : "step",
298
+ ...(index + 1 === current ? { "aria-current": "step" } : {}),
299
+ },
300
+ children: [label.trim()],
301
+ };
302
+ }),
303
+ };
304
+ },
305
+ };
306
+
307
+ export const DOCK: DaisyComponentDefinition = {
308
+ id: "dock",
309
+ label: "Dock",
310
+ category: "Navigation",
311
+ tag: "nav",
312
+ rootClass: "dock",
313
+ role: "navigation",
314
+ fields: [
315
+ {
316
+ key: "ariaLabel",
317
+ label: "Dock label",
318
+ kind: "text",
319
+ default: "Mobile navigation",
320
+ attribute: "aria-label",
321
+ },
322
+ {
323
+ key: "items",
324
+ label: "Items, Label|URL per line",
325
+ kind: "textarea",
326
+ default: "Home|/\nSearch|/search\nProfile|/profile",
327
+ },
328
+ { key: "active", label: "Active label", kind: "text", default: "Home" },
329
+ {
330
+ key: "size",
331
+ label: "Size",
332
+ kind: "select",
333
+ default: "md",
334
+ options: sizes,
335
+ classMap: sizeMap("dock"),
336
+ },
337
+ ],
338
+ build(node, classes) {
339
+ return {
340
+ tag: "nav",
341
+ // daisyUI pins the dock to the viewport bottom, where it covers the page in the editor
342
+ // canvas and every block under it. In flow it sits where it is placed, like the other blocks.
343
+ attrs: {
344
+ class: `${classes.join(" ")} relative`,
345
+ "aria-label": String(node.props.ariaLabel),
346
+ },
347
+ children: lines(node.props.items).map((entry) => {
348
+ const [label, href = "#"] = entry.split("|");
349
+ return {
350
+ tag: "a",
351
+ attrs: {
352
+ href: safeHref(href),
353
+ class: label === String(node.props.active) ? "dock-active" : "",
354
+ ...(label === String(node.props.active) ? { "aria-current": "page" } : {}),
355
+ },
356
+ children: [{ tag: "span", attrs: { class: "dock-label" }, children: [label || "Link"] }],
357
+ };
358
+ }),
359
+ };
360
+ },
361
+ };
362
+
363
+ export const FOOTER: DaisyComponentDefinition = {
364
+ id: "footer",
365
+ label: "Footer",
366
+ category: "Navigation",
367
+ tag: "footer",
368
+ rootClass: "footer",
369
+ role: "contentinfo",
370
+ container: true,
371
+ fields: [
372
+ { key: "brand", label: "Brand", kind: "text", default: "EmDash" },
373
+ {
374
+ key: "description",
375
+ label: "Description",
376
+ kind: "textarea",
377
+ default: "Visual publishing for modern teams.",
378
+ },
379
+ {
380
+ key: "links",
381
+ label: "Links, Label|URL per line",
382
+ kind: "textarea",
383
+ default: "About|/about\nContact|/contact\nPrivacy|/privacy",
384
+ },
385
+ {
386
+ key: "layout",
387
+ label: "Layout",
388
+ kind: "select",
389
+ default: "horizontal",
390
+ options: ["horizontal", "vertical", "center"],
391
+ classMap: {
392
+ horizontal: "sm:footer-horizontal",
393
+ vertical: "footer-vertical",
394
+ // daisyUI switches the footer to columns from the small breakpoint up; keep brand and links stacked.
395
+ center: "footer-center grid-flow-row",
396
+ },
397
+ },
398
+ ],
399
+ build(node, classes, children) {
400
+ return {
401
+ tag: "footer",
402
+ attrs: { class: classes.join(" "), role: "contentinfo" },
403
+ children: [
404
+ {
405
+ tag: "aside",
406
+ attrs: {},
407
+ children: [
408
+ { tag: "strong", attrs: {}, children: [String(node.props.brand)] },
409
+ { tag: "p", attrs: {}, children: [String(node.props.description)] },
410
+ ],
411
+ },
412
+ {
413
+ tag: "nav",
414
+ attrs: { "aria-label": "Footer links" },
415
+ children: lines(node.props.links).map((entry) => {
416
+ const [label, href = "#"] = entry.split("|");
417
+ return {
418
+ tag: "a",
419
+ attrs: { class: "link link-hover", href: safeHref(href) },
420
+ children: [label || "Link"],
421
+ };
422
+ }),
423
+ },
424
+ ...children,
425
+ ],
426
+ };
427
+ },
428
+ };
429
+
430
+ export const NAVIGATION_DAISY_COMPONENTS = [
431
+ NAVBAR,
432
+ MENU,
433
+ BREADCRUMBS,
434
+ PAGINATION,
435
+ STEPS,
436
+ DOCK,
437
+ FOOTER,
438
+ ] as const;
@@ -0,0 +1,20 @@
1
+ // Countdown and radial progress need a per-instance CSS variable (`--value`). Inline `style` is
2
+ // refused by the public allowlist (W-091), so the first paint carries the value as an
3
+ // arbitrary-property class. Tailwind only generates classes it finds as literals, so every value up
4
+ // to VALUE_MAX is listed in `class-names.ts` (written by `classes:write`).
5
+ // ponytail: classes stop at 100. Countdown values above that are set by the runtime script
6
+ // (`data-daisy-value` / `data-daisy-unit`), which is not limited. Raising VALUE_MAX costs ~30 bytes
7
+ // of CSS per step.
8
+ const VALUE_MAX = 100;
9
+
10
+ /** Two-digit display for a countdown unit (`--digits`), written out for the scanner. */
11
+ export const DIGITS_2_CLASS = "[--digits:2]";
12
+
13
+ export function valueClass(value: number): string {
14
+ const whole = Number.isFinite(value) ? Math.round(Math.min(VALUE_MAX, Math.max(0, value))) : 0;
15
+ return `[--value:${whole}]`;
16
+ }
17
+
18
+ export const VALUE_CLASS_NAMES: readonly string[] = Array.from({ length: VALUE_MAX + 1 }, (_, n) =>
19
+ valueClass(n),
20
+ );
@@ -0,0 +1,104 @@
1
+ import { DAISY_COMPONENT_CATALOG } from "../catalog/index.ts";
2
+ import type { DaisyComponentNode } from "../types.ts";
3
+ import { DAISYUI_CONFORMANCE, isVerifiedDaisyComponent } from "../conformance/index.ts";
4
+
5
+ export const DAISY_CATALOG_VERSION = DAISYUI_CONFORMANCE.catalogVersion;
6
+ export const SUPPORTED_DAISYUI_RANGE = DAISYUI_CONFORMANCE.daisyuiVersion;
7
+ export const SUPPORTED_TAILWIND_RANGE = DAISYUI_CONFORMANCE.tailwindcssVersion;
8
+
9
+ export interface DaisyLayoutEnvelope {
10
+ catalogVersion: number;
11
+ nodes: DaisyComponentNode[];
12
+ }
13
+ export interface MigrationNotice {
14
+ nodeId: string;
15
+ message: string;
16
+ }
17
+ export interface CompatibilityReport {
18
+ compatible: boolean;
19
+ errors: string[];
20
+ warnings: string[];
21
+ componentCount: number;
22
+ verifiedComponentCount: number;
23
+ experimentalComponentCount: number;
24
+ classCount: number;
25
+ }
26
+
27
+ const RENAMED_PROPS: Record<string, Record<string, string>> = {
28
+ button: { text: "label" },
29
+ badge: { text: "label" },
30
+ alert: { text: "message" },
31
+ };
32
+
33
+ export function migrateDaisyLayout(input: DaisyLayoutEnvelope): {
34
+ layout: DaisyLayoutEnvelope;
35
+ notices: MigrationNotice[];
36
+ } {
37
+ if (input.catalogVersion > DAISY_CATALOG_VERSION)
38
+ throw new Error(
39
+ `Catalog version ${input.catalogVersion} is newer than supported version ${DAISY_CATALOG_VERSION}.`,
40
+ );
41
+ const notices: MigrationNotice[] = [];
42
+ const migrateNode = (node: DaisyComponentNode): DaisyComponentNode => {
43
+ const renamed = RENAMED_PROPS[node.component] ?? {};
44
+ const props = { ...node.props };
45
+ for (const [oldKey, newKey] of Object.entries(renamed)) {
46
+ if (oldKey in props && !(newKey in props)) {
47
+ props[newKey] = props[oldKey];
48
+ delete props[oldKey];
49
+ notices.push({
50
+ nodeId: node.id,
51
+ message: `Renamed ${node.component}.${oldKey} to ${newKey}.`,
52
+ });
53
+ }
54
+ }
55
+ return {
56
+ ...node,
57
+ props,
58
+ ...(node.children ? { children: node.children.map(migrateNode) } : {}),
59
+ };
60
+ };
61
+ return {
62
+ layout: { catalogVersion: DAISY_CATALOG_VERSION, nodes: input.nodes.map(migrateNode) },
63
+ notices,
64
+ };
65
+ }
66
+
67
+ export function compatibilityReport(): CompatibilityReport {
68
+ const errors: string[] = [];
69
+ const warnings: string[] = [];
70
+ const ids = new Set<string>();
71
+ const classes = new Set<string>();
72
+ for (const definition of DAISY_COMPONENT_CATALOG) {
73
+ if (ids.has(definition.id)) errors.push(`Duplicate component id: ${definition.id}`);
74
+ ids.add(definition.id);
75
+ if (!definition.rootClass.trim()) errors.push(`${definition.id} has no root class.`);
76
+ for (const token of definition.rootClass.split(/\s+/)) if (token) classes.add(token);
77
+ for (const field of definition.fields) {
78
+ if (field.options && field.classMap) {
79
+ for (const option of field.options)
80
+ if (!(option in field.classMap))
81
+ errors.push(`${definition.id}.${field.key} has no class for ${option}.`);
82
+ }
83
+ for (const mapped of Object.values(field.classMap ?? {}))
84
+ for (const token of mapped.split(/\s+/)) if (token) classes.add(token);
85
+ }
86
+ }
87
+ if (ids.size < 40)
88
+ warnings.push(`Catalog contains only ${ids.size} components; expected the WP9 catalog.`);
89
+ const verifiedComponentCount = [...ids].filter(isVerifiedDaisyComponent).length;
90
+ const experimentalComponentCount = ids.size - verifiedComponentCount;
91
+ if (experimentalComponentCount > 0)
92
+ warnings.push(
93
+ `${experimentalComponentCount} catalog components are experimental and have not passed official conformance gates.`,
94
+ );
95
+ return {
96
+ compatible: errors.length === 0,
97
+ errors,
98
+ warnings,
99
+ componentCount: ids.size,
100
+ verifiedComponentCount,
101
+ experimentalComponentCount,
102
+ classCount: classes.size,
103
+ };
104
+ }