@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,433 @@
1
+ import type { DaisyComponentDefinition, DaisyVNode } from "../types.ts";
2
+
3
+ const sizes = ["xs", "sm", "md", "lg", "xl"] as const;
4
+ const tones = [
5
+ "neutral",
6
+ "primary",
7
+ "secondary",
8
+ "accent",
9
+ "info",
10
+ "success",
11
+ "warning",
12
+ "error",
13
+ ] as const;
14
+ const variants = ["default", "ghost"] as const;
15
+ const sizeMap = (prefix: string) =>
16
+ Object.fromEntries(sizes.map((size) => [size, `${prefix}-${size}`]));
17
+ const toneMap = (prefix: string) =>
18
+ Object.fromEntries(tones.map((tone) => [tone, `${prefix}-${tone}`]));
19
+ const variantMap = (prefix: string) => ({ default: "", ghost: `${prefix}-ghost` });
20
+
21
+ // Placement classes that belong on a labelled control's wrapper, not on the control itself.
22
+ const PLACEMENT_CLASSES = new Set(["mx-auto", "my-4", "w-fit"]);
23
+
24
+ function formControl(
25
+ tag: string,
26
+ rootClass: string,
27
+ fields: DaisyComponentDefinition["fields"],
28
+ ): DaisyComponentDefinition {
29
+ return {
30
+ id: rootClass,
31
+ label: rootClass.replace(/\b\w/g, (c) => c.toUpperCase()),
32
+ category: "Actions",
33
+ tag,
34
+ rootClass,
35
+ fields,
36
+ };
37
+ }
38
+ const commonInputFields = (prefix: string) =>
39
+ [
40
+ { key: "name", label: "Name", kind: "text", default: "field", attribute: "name" },
41
+ {
42
+ key: "label",
43
+ label: "Accessible label",
44
+ kind: "text",
45
+ default: "Field",
46
+ attribute: "aria-label",
47
+ },
48
+ { key: "disabled", label: "Disabled", kind: "boolean", default: false, attribute: "disabled" },
49
+ { key: "required", label: "Required", kind: "boolean", default: false, attribute: "required" },
50
+ {
51
+ key: "size",
52
+ label: "Size",
53
+ kind: "select",
54
+ default: "md",
55
+ options: sizes,
56
+ classMap: sizeMap(prefix),
57
+ },
58
+ {
59
+ key: "tone",
60
+ label: "Color",
61
+ kind: "select",
62
+ default: "neutral",
63
+ options: tones,
64
+ classMap: toneMap(prefix),
65
+ },
66
+ {
67
+ key: "variant",
68
+ label: "Variant",
69
+ kind: "select",
70
+ default: "default",
71
+ options: variants,
72
+ classMap: variantMap(prefix),
73
+ },
74
+ ] as const;
75
+
76
+ export const INPUT: DaisyComponentDefinition = formControl("input", "input", [
77
+ {
78
+ key: "type",
79
+ label: "Type",
80
+ kind: "select",
81
+ default: "text",
82
+ options: ["text", "email", "password", "url", "search", "tel", "number"],
83
+ attribute: "type",
84
+ },
85
+ {
86
+ key: "placeholder",
87
+ label: "Placeholder",
88
+ kind: "text",
89
+ default: "Type here",
90
+ attribute: "placeholder",
91
+ },
92
+ { key: "value", label: "Default value", kind: "text", default: "", attribute: "value" },
93
+ ...commonInputFields("input"),
94
+ ]);
95
+
96
+ export const TEXTAREA: DaisyComponentDefinition = formControl("textarea", "textarea", [
97
+ {
98
+ key: "placeholder",
99
+ label: "Placeholder",
100
+ kind: "text",
101
+ default: "Write here",
102
+ attribute: "placeholder",
103
+ },
104
+ { key: "value", label: "Default value", kind: "textarea", default: "", textContent: true },
105
+ { key: "rows", label: "Rows", kind: "number", default: 4, attribute: "rows" },
106
+ ...commonInputFields("textarea"),
107
+ ]);
108
+
109
+ export const SELECT: DaisyComponentDefinition = {
110
+ ...formControl("select", "select", commonInputFields("select")),
111
+ fields: [
112
+ {
113
+ key: "options",
114
+ label: "Options, one per line",
115
+ kind: "textarea",
116
+ default: "First option\nSecond option\nThird option",
117
+ },
118
+ { key: "selected", label: "Selected option", kind: "text", default: "First option" },
119
+ ...commonInputFields("select"),
120
+ ],
121
+ build(node, classes) {
122
+ const selected = String(node.props.selected ?? "");
123
+ const values = String(node.props.options ?? "")
124
+ .split(/\r?\n/)
125
+ .map((value) => value.trim())
126
+ .filter(Boolean);
127
+ return {
128
+ tag: "select",
129
+ attrs: {
130
+ class: classes.join(" "),
131
+ name: String(node.props.name),
132
+ "aria-label": String(node.props.label),
133
+ ...(node.props.disabled ? { disabled: "disabled" } : {}),
134
+ ...(node.props.required ? { required: "required" } : {}),
135
+ },
136
+ children: values.map((value) => ({
137
+ tag: "option",
138
+ attrs: { value, ...(value === selected ? { selected: "selected" } : {}) },
139
+ children: [value],
140
+ })),
141
+ };
142
+ },
143
+ };
144
+
145
+ function checkDefinition(
146
+ id: "checkbox" | "radio" | "toggle",
147
+ label: string,
148
+ ): DaisyComponentDefinition {
149
+ return {
150
+ id,
151
+ label,
152
+ category: "Actions",
153
+ tag: "input",
154
+ rootClass: id,
155
+ fields: [
156
+ { key: "name", label: "Name", kind: "text", default: id, attribute: "name" },
157
+ { key: "value", label: "Value", kind: "text", default: "on", attribute: "value" },
158
+ {
159
+ key: "label",
160
+ label: "Accessible label",
161
+ kind: "text",
162
+ default: label,
163
+ attribute: "aria-label",
164
+ },
165
+ { key: "checked", label: "Checked", kind: "boolean", default: false, attribute: "checked" },
166
+ {
167
+ key: "disabled",
168
+ label: "Disabled",
169
+ kind: "boolean",
170
+ default: false,
171
+ attribute: "disabled",
172
+ },
173
+ {
174
+ key: "size",
175
+ label: "Size",
176
+ kind: "select",
177
+ default: "md",
178
+ options: sizes,
179
+ classMap: sizeMap(id),
180
+ },
181
+ {
182
+ key: "tone",
183
+ label: "Color",
184
+ kind: "select",
185
+ default: "primary",
186
+ options: tones,
187
+ classMap: toneMap(id),
188
+ },
189
+ ],
190
+ build(node, classes) {
191
+ // The visible text sits beside the control, so a visitor knows what it does. The wrapper
192
+ // takes the placement classes (centred, spaced); the control keeps its own.
193
+ const wrapper = classes.filter((c) => PLACEMENT_CLASSES.has(c));
194
+ const control = classes.filter((c) => !PLACEMENT_CLASSES.has(c));
195
+ return {
196
+ tag: "label",
197
+ attrs: { class: [...wrapper, "flex items-center gap-2 cursor-pointer"].join(" ") },
198
+ children: [
199
+ {
200
+ tag: "input",
201
+ attrs: {
202
+ type: id === "toggle" ? "checkbox" : id,
203
+ class: control.join(" "),
204
+ name: String(node.props.name),
205
+ value: String(node.props.value),
206
+ ...(node.props.checked ? { checked: "checked" } : {}),
207
+ ...(node.props.disabled ? { disabled: "disabled" } : {}),
208
+ },
209
+ children: [],
210
+ },
211
+ { tag: "span", attrs: {}, children: [String(node.props.label)] },
212
+ ],
213
+ };
214
+ },
215
+ };
216
+ }
217
+ export const CHECKBOX = checkDefinition("checkbox", "Checkbox");
218
+ export const RADIO = checkDefinition("radio", "Radio");
219
+ export const TOGGLE = checkDefinition("toggle", "Toggle");
220
+
221
+ export const FILE_INPUT: DaisyComponentDefinition = formControl("input", "file-input", [
222
+ { key: "name", label: "Name", kind: "text", default: "upload", attribute: "name" },
223
+ {
224
+ key: "label",
225
+ label: "Accessible label",
226
+ kind: "text",
227
+ default: "Choose file",
228
+ attribute: "aria-label",
229
+ },
230
+ {
231
+ key: "accept",
232
+ label: "Accepted file types",
233
+ kind: "text",
234
+ default: "image/*",
235
+ attribute: "accept",
236
+ },
237
+ { key: "multiple", label: "Multiple", kind: "boolean", default: false, attribute: "multiple" },
238
+ { key: "disabled", label: "Disabled", kind: "boolean", default: false, attribute: "disabled" },
239
+ {
240
+ key: "size",
241
+ label: "Size",
242
+ kind: "select",
243
+ default: "md",
244
+ options: sizes,
245
+ classMap: sizeMap("file-input"),
246
+ },
247
+ {
248
+ key: "tone",
249
+ label: "Color",
250
+ kind: "select",
251
+ default: "neutral",
252
+ options: tones,
253
+ classMap: toneMap("file-input"),
254
+ },
255
+ {
256
+ key: "variant",
257
+ label: "Variant",
258
+ kind: "select",
259
+ default: "solid",
260
+ options: ["solid", "ghost"],
261
+ classMap: { solid: "", ghost: "file-input-ghost" },
262
+ },
263
+ ]);
264
+ FILE_INPUT.build = (node, classes) => ({
265
+ tag: "input",
266
+ attrs: {
267
+ type: "file",
268
+ class: classes.join(" "),
269
+ name: String(node.props.name),
270
+ "aria-label": String(node.props.label),
271
+ accept: String(node.props.accept),
272
+ ...(node.props.multiple ? { multiple: "multiple" } : {}),
273
+ ...(node.props.disabled ? { disabled: "disabled" } : {}),
274
+ },
275
+ children: [],
276
+ });
277
+
278
+ export const RANGE: DaisyComponentDefinition = {
279
+ id: "range",
280
+ label: "Range",
281
+ category: "Actions",
282
+ tag: "input",
283
+ rootClass: "range",
284
+ fields: [
285
+ { key: "name", label: "Name", kind: "text", default: "range", attribute: "name" },
286
+ {
287
+ key: "label",
288
+ label: "Accessible label",
289
+ kind: "text",
290
+ default: "Range",
291
+ attribute: "aria-label",
292
+ },
293
+ { key: "min", label: "Minimum", kind: "number", default: 0, attribute: "min" },
294
+ { key: "max", label: "Maximum", kind: "number", default: 100, attribute: "max" },
295
+ { key: "step", label: "Step", kind: "number", default: 1, attribute: "step" },
296
+ { key: "value", label: "Value", kind: "number", default: 50, attribute: "value" },
297
+ {
298
+ key: "size",
299
+ label: "Size",
300
+ kind: "select",
301
+ default: "md",
302
+ options: sizes,
303
+ classMap: sizeMap("range"),
304
+ },
305
+ {
306
+ key: "tone",
307
+ label: "Color",
308
+ kind: "select",
309
+ default: "primary",
310
+ options: tones,
311
+ classMap: toneMap("range"),
312
+ },
313
+ {
314
+ key: "direction",
315
+ label: "Direction",
316
+ kind: "select",
317
+ default: "horizontal",
318
+ options: ["horizontal", "vertical"],
319
+ classMap: { horizontal: "", vertical: "range-vertical" },
320
+ },
321
+ ],
322
+ build(node, classes) {
323
+ const min = Number(node.props.min),
324
+ max = Number(node.props.max),
325
+ value = Math.min(max, Math.max(min, Number(node.props.value)));
326
+ return {
327
+ tag: "input",
328
+ attrs: {
329
+ type: "range",
330
+ class: classes.join(" "),
331
+ name: String(node.props.name),
332
+ "aria-label": String(node.props.label),
333
+ min: String(min),
334
+ max: String(max),
335
+ step: String(node.props.step),
336
+ value: String(value),
337
+ },
338
+ children: [],
339
+ };
340
+ },
341
+ };
342
+
343
+ export const RATING: DaisyComponentDefinition = {
344
+ id: "rating",
345
+ label: "Rating",
346
+ category: "Actions",
347
+ tag: "div",
348
+ rootClass: "rating",
349
+ fields: [
350
+ { key: "name", label: "Name", kind: "text", default: "rating" },
351
+ { key: "label", label: "Accessible label", kind: "text", default: "Rating" },
352
+ { key: "max", label: "Maximum", kind: "number", default: 5 },
353
+ { key: "value", label: "Selected", kind: "number", default: 3 },
354
+ {
355
+ key: "size",
356
+ label: "Size",
357
+ kind: "select",
358
+ default: "md",
359
+ options: sizes,
360
+ classMap: sizeMap("rating"),
361
+ },
362
+ {
363
+ key: "half",
364
+ label: "Half stars",
365
+ kind: "boolean",
366
+ default: false,
367
+ classMap: { true: "rating-half", false: "" },
368
+ },
369
+ {
370
+ // daisyUI hides the first radio, so a visitor can clear the rating.
371
+ key: "clearable",
372
+ label: "Allow clearing",
373
+ kind: "boolean",
374
+ default: false,
375
+ },
376
+ ],
377
+ build(node, classes) {
378
+ const max = Math.min(10, Math.max(1, Number(node.props.max)));
379
+ const selected = Math.min(max, Math.max(0, Number(node.props.value)));
380
+ const name = String(node.props.name);
381
+ const half = node.props.half === true;
382
+ const children: DaisyVNode[] = [];
383
+ if (node.props.clearable === true)
384
+ children.push({
385
+ tag: "input",
386
+ attrs: { type: "radio", name, value: "0", class: "rating-hidden" },
387
+ children: [],
388
+ });
389
+ for (let i = 1; i <= max; i++) {
390
+ // A half rating has two inputs per star: the left half is the lower value.
391
+ const parts = half
392
+ ? [
393
+ { value: i - 0.5, cls: "mask mask-star-2 mask-half-1 bg-orange-400" },
394
+ { value: i, cls: "mask mask-star-2 mask-half-2 bg-orange-400" },
395
+ ]
396
+ : [{ value: i, cls: "mask mask-star-2 bg-orange-400" }];
397
+ for (const part of parts)
398
+ children.push({
399
+ tag: "input",
400
+ attrs: {
401
+ type: "radio",
402
+ name,
403
+ value: String(part.value),
404
+ class: part.cls,
405
+ "aria-label": `${node.props.label} ${part.value} of ${max}`,
406
+ ...(part.value === selected ? { checked: "checked" } : {}),
407
+ },
408
+ children: [],
409
+ });
410
+ }
411
+ return {
412
+ tag: "div",
413
+ attrs: {
414
+ class: classes.join(" "),
415
+ role: "radiogroup",
416
+ "aria-label": String(node.props.label),
417
+ },
418
+ children,
419
+ };
420
+ },
421
+ };
422
+
423
+ export const FORM_DAISY_COMPONENTS = [
424
+ INPUT,
425
+ TEXTAREA,
426
+ SELECT,
427
+ CHECKBOX,
428
+ RADIO,
429
+ TOGGLE,
430
+ FILE_INPUT,
431
+ RANGE,
432
+ RATING,
433
+ ] as const;
@@ -0,0 +1,77 @@
1
+ export * from "./missing-complex.ts";
2
+ export * from "./missing-primitives.ts";
3
+ export { BASIC_DAISY_COMPONENTS, BUTTON, BADGE, ALERT, CARD, PROGRESS, STATS } from "./basic.ts";
4
+ export {
5
+ FORM_DAISY_COMPONENTS,
6
+ INPUT,
7
+ TEXTAREA,
8
+ SELECT,
9
+ CHECKBOX,
10
+ RADIO,
11
+ TOGGLE,
12
+ FILE_INPUT,
13
+ RANGE,
14
+ RATING,
15
+ } from "./forms.ts";
16
+ export {
17
+ NAVIGATION_DAISY_COMPONENTS,
18
+ NAVBAR,
19
+ MENU,
20
+ BREADCRUMBS,
21
+ PAGINATION,
22
+ STEPS,
23
+ DOCK,
24
+ FOOTER,
25
+ } from "./navigation.ts";
26
+ export {
27
+ INTERACTIVE_DAISY_COMPONENTS,
28
+ TABS,
29
+ ACCORDION,
30
+ DROPDOWN,
31
+ MODAL,
32
+ DRAWER,
33
+ CAROUSEL,
34
+ COLLAPSE,
35
+ SWAP,
36
+ } from "./interactive.ts";
37
+ export {
38
+ DATA_DISPLAY_DAISY_COMPONENTS,
39
+ TABLE,
40
+ TIMELINE,
41
+ AVATAR,
42
+ CHAT_BUBBLE,
43
+ LIST,
44
+ STATUS,
45
+ TOOLTIP,
46
+ COUNTDOWN,
47
+ } from "./data-display.ts";
48
+ export {
49
+ LAYOUT_MARKETING_DAISY_COMPONENTS,
50
+ HERO,
51
+ STACK,
52
+ DIVIDER,
53
+ JOIN,
54
+ INDICATOR,
55
+ MASK,
56
+ BROWSER_MOCKUP,
57
+ PHONE_MOCKUP,
58
+ CODE_MOCKUP,
59
+ } from "./layout-marketing.ts";
60
+ import { BASIC_DAISY_COMPONENTS } from "./basic.ts";
61
+ import { FORM_DAISY_COMPONENTS } from "./forms.ts";
62
+ import { NAVIGATION_DAISY_COMPONENTS } from "./navigation.ts";
63
+ import { INTERACTIVE_DAISY_COMPONENTS } from "./interactive.ts";
64
+ import { DATA_DISPLAY_DAISY_COMPONENTS } from "./data-display.ts";
65
+ import { LAYOUT_MARKETING_DAISY_COMPONENTS } from "./layout-marketing.ts";
66
+ import { MISSING_PRIMITIVE_COMPONENTS } from "./missing-primitives.ts";
67
+ import { MISSING_COMPLEX_COMPONENTS } from "./missing-complex.ts";
68
+ export const DAISY_COMPONENT_CATALOG = [
69
+ ...BASIC_DAISY_COMPONENTS,
70
+ ...FORM_DAISY_COMPONENTS,
71
+ ...NAVIGATION_DAISY_COMPONENTS,
72
+ ...INTERACTIVE_DAISY_COMPONENTS,
73
+ ...DATA_DISPLAY_DAISY_COMPONENTS,
74
+ ...LAYOUT_MARKETING_DAISY_COMPONENTS,
75
+ ...MISSING_PRIMITIVE_COMPONENTS,
76
+ ...MISSING_COMPLEX_COMPONENTS,
77
+ ] as const;