@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,409 @@
1
+ import type { DaisyComponentDefinition, DaisyVNode } from "../types.ts";
2
+ import { valueClass } from "./value-class.ts";
3
+
4
+ const tones = [
5
+ "neutral",
6
+ "primary",
7
+ "secondary",
8
+ "accent",
9
+ "info",
10
+ "success",
11
+ "warning",
12
+ "error",
13
+ ] as const;
14
+ const sizes = ["xs", "sm", "md", "lg", "xl"] as const;
15
+ const map = (prefix: string, values: readonly string[]) =>
16
+ Object.fromEntries(values.map((value) => [value, `${prefix}-${value}`]));
17
+ const clamp = (value: unknown, min: number, max: number, fallback: number) => {
18
+ const number = Number(value);
19
+ return Number.isFinite(number) ? Math.min(max, Math.max(min, number)) : fallback;
20
+ };
21
+
22
+ export const LOADING: DaisyComponentDefinition = {
23
+ id: "loading",
24
+ label: "Loading",
25
+ category: "Feedback",
26
+ tag: "span",
27
+ rootClass: "loading",
28
+ fields: [
29
+ {
30
+ key: "style",
31
+ label: "Animation",
32
+ kind: "select",
33
+ default: "spinner",
34
+ options: ["spinner", "dots", "ring", "ball", "bars", "infinity"],
35
+ classMap: map("loading", ["spinner", "dots", "ring", "ball", "bars", "infinity"]),
36
+ },
37
+ {
38
+ key: "size",
39
+ label: "Size",
40
+ kind: "select",
41
+ default: "md",
42
+ options: sizes,
43
+ classMap: map("loading", sizes),
44
+ },
45
+ {
46
+ key: "label",
47
+ label: "Accessible label",
48
+ kind: "text",
49
+ default: "Loading",
50
+ attribute: "aria-label",
51
+ },
52
+ ],
53
+ role: "status",
54
+ };
55
+ export const SKELETON: DaisyComponentDefinition = {
56
+ id: "skeleton",
57
+ label: "Skeleton",
58
+ category: "Feedback",
59
+ tag: "div",
60
+ rootClass: "skeleton",
61
+ fields: [
62
+ {
63
+ key: "text",
64
+ label: "Text placeholder",
65
+ kind: "boolean",
66
+ default: false,
67
+ classMap: { true: "skeleton-text", false: "" },
68
+ },
69
+ {
70
+ // A skeleton has no size of its own; without one it is zero high.
71
+ key: "size",
72
+ label: "Height",
73
+ kind: "select",
74
+ default: "md",
75
+ options: ["sm", "md", "lg"],
76
+ // The base-content tint keeps the block visible on the dark canvas, where the default
77
+ // base-300 fill is almost the page colour.
78
+ classMap: {
79
+ sm: "h-8 w-full bg-base-content/15",
80
+ md: "h-16 w-full bg-base-content/15",
81
+ lg: "h-32 w-full bg-base-content/15",
82
+ },
83
+ },
84
+ {
85
+ key: "label",
86
+ label: "Accessible label",
87
+ kind: "text",
88
+ default: "Loading content",
89
+ attribute: "aria-label",
90
+ },
91
+ ],
92
+ };
93
+ export const RADIAL_PROGRESS: DaisyComponentDefinition = {
94
+ id: "radial-progress",
95
+ label: "Radial progress",
96
+ category: "Feedback",
97
+ tag: "div",
98
+ rootClass: "radial-progress",
99
+ role: "progressbar",
100
+ fields: [
101
+ { key: "value", label: "Value", kind: "number", default: 70 },
102
+ { key: "label", label: "Label", kind: "text", default: "70%", textContent: true },
103
+ {
104
+ key: "tone",
105
+ label: "Color",
106
+ kind: "select",
107
+ default: "primary",
108
+ options: tones,
109
+ // Neutral is the theme's own text colour, which is designed to contrast its base surface.
110
+ classMap: { ...map("text", tones), neutral: "text-base-content" },
111
+ },
112
+ ],
113
+ build: (node, classes) => {
114
+ const value = clamp(node.props.value, 0, 100, 0);
115
+ return {
116
+ tag: "div",
117
+ attrs: {
118
+ // size-24!: daisyUI's own radial rule sizes the ring from --size and wins over a plain
119
+ // utility in the editor canvas; the important flag makes this size stick.
120
+ class: [...classes, valueClass(value), "size-24!"].join(" "),
121
+ role: "progressbar",
122
+ "aria-valuemin": "0",
123
+ "aria-valuemax": "100",
124
+ "aria-valuenow": String(value),
125
+ },
126
+ children: [String(node.props.label || `${value}%`)],
127
+ };
128
+ },
129
+ };
130
+ export const TOAST: DaisyComponentDefinition = {
131
+ id: "toast",
132
+ label: "Toast",
133
+ category: "Feedback",
134
+ tag: "div",
135
+ rootClass: "toast",
136
+ container: true,
137
+ fields: [
138
+ {
139
+ key: "horizontal",
140
+ label: "Horizontal",
141
+ kind: "select",
142
+ default: "end",
143
+ options: ["start", "center", "end"],
144
+ classMap: map("toast", ["start", "center", "end"]),
145
+ },
146
+ {
147
+ key: "vertical",
148
+ label: "Vertical",
149
+ kind: "select",
150
+ default: "bottom",
151
+ options: ["top", "middle", "bottom"],
152
+ classMap: map("toast", ["top", "middle", "bottom"]),
153
+ },
154
+ { key: "message", label: "Message", kind: "text", default: "Notification" },
155
+ ],
156
+ build: (node, classes, children) => ({
157
+ tag: "div",
158
+ attrs: { class: classes.join(" "), role: "status", "aria-live": "polite" },
159
+ children: children.length
160
+ ? children
161
+ : [{ tag: "div", attrs: { class: "alert" }, children: [String(node.props.message)] }],
162
+ }),
163
+ };
164
+ export const LABEL: DaisyComponentDefinition = {
165
+ id: "label",
166
+ label: "Label",
167
+ category: "Actions",
168
+ tag: "label",
169
+ rootClass: "label",
170
+ fields: [
171
+ { key: "text", label: "Text", kind: "text", default: "Label", textContent: true },
172
+ { key: "for", label: "Control ID", kind: "text", default: "", attribute: "for" },
173
+ ],
174
+ };
175
+ export const FIELDSET: DaisyComponentDefinition = {
176
+ id: "fieldset",
177
+ label: "Fieldset",
178
+ category: "Actions",
179
+ tag: "fieldset",
180
+ rootClass: "fieldset",
181
+ container: true,
182
+ fields: [{ key: "legend", label: "Legend", kind: "text", default: "Details" }],
183
+ build: (node, classes, children) => ({
184
+ tag: "fieldset",
185
+ attrs: { class: classes.join(" ") },
186
+ children: [
187
+ { tag: "legend", attrs: { class: "fieldset-legend" }, children: [String(node.props.legend)] },
188
+ ...children,
189
+ ],
190
+ }),
191
+ };
192
+ export const KBD: DaisyComponentDefinition = {
193
+ id: "kbd",
194
+ label: "Kbd",
195
+ category: "Data display",
196
+ tag: "kbd",
197
+ rootClass: "kbd",
198
+ fields: [
199
+ { key: "text", label: "Key", kind: "text", default: "Ctrl", textContent: true },
200
+ {
201
+ key: "size",
202
+ label: "Size",
203
+ kind: "select",
204
+ default: "md",
205
+ options: sizes,
206
+ classMap: map("kbd", sizes),
207
+ },
208
+ ],
209
+ };
210
+ export const LINK: DaisyComponentDefinition = {
211
+ id: "link",
212
+ label: "Link",
213
+ category: "Navigation",
214
+ tag: "a",
215
+ rootClass: "link",
216
+ fields: [
217
+ { key: "label", label: "Label", kind: "text", default: "Link", textContent: true },
218
+ { key: "href", label: "URL", kind: "href", default: "#" },
219
+ {
220
+ key: "tone",
221
+ label: "Color",
222
+ kind: "select",
223
+ default: "primary",
224
+ options: tones,
225
+ // Neutral is the theme's own text colour, which is designed to contrast its base surface.
226
+ classMap: { ...map("link", tones), neutral: "text-base-content" },
227
+ },
228
+ {
229
+ key: "hover",
230
+ label: "Underline on hover",
231
+ kind: "boolean",
232
+ default: false,
233
+ classMap: { true: "link-hover", false: "" },
234
+ },
235
+ ],
236
+ build: (node, classes) => ({
237
+ tag: "a",
238
+ attrs: { class: classes.join(" "), href: safeHref(node.props.href) },
239
+ children: [String(node.props.label)],
240
+ }),
241
+ };
242
+ const safeHref = (value: unknown) => {
243
+ const href = String(value ?? "").trim();
244
+ if (
245
+ (href.startsWith("/") && !href.startsWith("//")) ||
246
+ href.startsWith("#") ||
247
+ href.startsWith("mailto:") ||
248
+ href.startsWith("tel:")
249
+ )
250
+ return href;
251
+ try {
252
+ const url = new URL(href);
253
+ return ["http:", "https:"].includes(url.protocol) ? href : "#";
254
+ } catch {
255
+ return "#";
256
+ }
257
+ };
258
+ export const WINDOW_MOCKUP: DaisyComponentDefinition = {
259
+ id: "window-mockup",
260
+ label: "Window mockup",
261
+ category: "Layout",
262
+ tag: "div",
263
+ rootClass: "mockup-window",
264
+ container: true,
265
+ fields: [
266
+ { key: "title", label: "Accessible title", kind: "text", default: "Application window" },
267
+ ],
268
+ build: (node, classes, children) => ({
269
+ tag: "div",
270
+ attrs: { class: classes.join(" "), role: "region", "aria-label": String(node.props.title) },
271
+ children,
272
+ }),
273
+ };
274
+ export const THEME_CONTROLLER: DaisyComponentDefinition = {
275
+ id: "theme-controller",
276
+ label: "Theme Controller",
277
+ category: "Actions",
278
+ tag: "input",
279
+ rootClass: "theme-controller",
280
+ fields: [
281
+ {
282
+ key: "theme",
283
+ label: "Theme",
284
+ kind: "select",
285
+ default: "light",
286
+ options: ["light", "dark", "corporate", "business", "cupcake"],
287
+ },
288
+ { key: "label", label: "Accessible label", kind: "text", default: "Change theme" },
289
+ ],
290
+ build: (node, classes) => ({
291
+ tag: "input",
292
+ attrs: {
293
+ type: "checkbox",
294
+ class: classes.join(" "),
295
+ value: String(node.props.theme),
296
+ "aria-label": String(node.props.label),
297
+ },
298
+ children: [],
299
+ }),
300
+ };
301
+ export const VALIDATOR: DaisyComponentDefinition = {
302
+ id: "validator",
303
+ label: "Validator",
304
+ category: "Actions",
305
+ tag: "div",
306
+ rootClass: "validator",
307
+ fields: [
308
+ {
309
+ key: "type",
310
+ label: "Input type",
311
+ kind: "select",
312
+ default: "email",
313
+ options: ["text", "email", "password", "url"],
314
+ },
315
+ { key: "placeholder", label: "Placeholder", kind: "text", default: "mail@site.com" },
316
+ { key: "hint", label: "Invalid hint", kind: "text", default: "Enter a valid value" },
317
+ { key: "required", label: "Required", kind: "boolean", default: true },
318
+ ],
319
+ build: (node) => ({
320
+ tag: "div",
321
+ attrs: { class: "fieldset" },
322
+ children: [
323
+ {
324
+ tag: "input",
325
+ attrs: {
326
+ class: "input validator",
327
+ type: String(node.props.type),
328
+ placeholder: String(node.props.placeholder),
329
+ ...(node.props.required ? { required: "required" } : {}),
330
+ },
331
+ children: [],
332
+ },
333
+ { tag: "p", attrs: { class: "validator-hint" }, children: [String(node.props.hint)] },
334
+ ],
335
+ }),
336
+ };
337
+ export const DIFF: DaisyComponentDefinition = {
338
+ id: "diff",
339
+ label: "Diff",
340
+ category: "Data display",
341
+ tag: "div",
342
+ rootClass: "diff",
343
+ fields: [
344
+ { key: "before", label: "Before text", kind: "text", default: "Before" },
345
+ { key: "after", label: "After text", kind: "text", default: "After" },
346
+ ],
347
+ build: (node, classes) => ({
348
+ tag: "div",
349
+ attrs: { class: classes.join(" "), tabindex: "0" },
350
+ children: [
351
+ // Both slots fill the same grid cell. Pin each label to its own side so they cannot stack.
352
+ {
353
+ tag: "div",
354
+ attrs: { class: "diff-item-1 text-start p-4" },
355
+ children: [String(node.props.before)],
356
+ },
357
+ {
358
+ tag: "div",
359
+ attrs: { class: "diff-item-2 text-end p-4" },
360
+ children: [String(node.props.after)],
361
+ },
362
+ { tag: "div", attrs: { class: "diff-resizer" }, children: [] },
363
+ ],
364
+ }),
365
+ };
366
+ export const FILTER: DaisyComponentDefinition = {
367
+ id: "filter",
368
+ label: "Filter",
369
+ category: "Actions",
370
+ tag: "form",
371
+ rootClass: "filter",
372
+ fields: [
373
+ { key: "name", label: "Group name", kind: "text", default: "filter" },
374
+ { key: "items", label: "Items", kind: "textarea", default: "All\nActive\nArchived" },
375
+ ],
376
+ build: (node, classes) => ({
377
+ tag: "form",
378
+ attrs: { class: classes.join(" ") },
379
+ children: String(node.props.items)
380
+ .split(/\r?\n/)
381
+ .filter(Boolean)
382
+ .map((label, index): DaisyVNode => ({
383
+ tag: "input",
384
+ attrs: {
385
+ class: "btn btn-square",
386
+ type: "radio",
387
+ name: String(node.props.name),
388
+ "aria-label": label,
389
+ ...(index === 0 ? { checked: "checked" } : {}),
390
+ },
391
+ children: [],
392
+ })),
393
+ }),
394
+ };
395
+ export const MISSING_PRIMITIVE_COMPONENTS = [
396
+ LOADING,
397
+ SKELETON,
398
+ RADIAL_PROGRESS,
399
+ TOAST,
400
+ LABEL,
401
+ FIELDSET,
402
+ KBD,
403
+ LINK,
404
+ WINDOW_MOCKUP,
405
+ THEME_CONTROLLER,
406
+ VALIDATOR,
407
+ DIFF,
408
+ FILTER,
409
+ ] as const;