@theweekendprojects/emvb-daisyui 0.0.0-stage → 0.2.0

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 +12397 -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,93 @@
1
+ /**
2
+ * Turn the text fields of an extension element into daisyUI children.
3
+ *
4
+ * Extension elements cannot hold child blocks (extensionApi 1.x has no slots), so containers take
5
+ * a `content` text field and compound roots take an `items` text field instead. Each line of
6
+ * `content` is a paragraph, or a link when the whole line is `[label](href)`. Each line of `items`
7
+ * is `Label|text` (for a table, `cell|cell|...` per row).
8
+ */
9
+ import { safeHref } from "../render/href.ts";
10
+ import type { DaisyComponentNode, DaisyVNode } from "../types.ts";
11
+
12
+ /** Most lines or items read from one field. Longer text is cut, so one field cannot bloat a page. */
13
+ export const MAX_LINES = 40;
14
+ /** Most characters kept from one line or cell. */
15
+ export const MAX_TEXT = 500;
16
+
17
+ /** Classes the content helpers themselves put on markup, so the class allowlist covers them. */
18
+ // `object-cover` is on photo tags only, which the class sample never renders, so it is listed here.
19
+ export const CONTENT_CLASSES = ["link", "object-cover"] as const;
20
+
21
+ const LINK_LINE = /^\[([^\]]{1,80})\]\(([^)\s]{1,300})\)$/;
22
+
23
+ function lines(text: string, limit = MAX_LINES): string[] {
24
+ return text
25
+ .split("\n")
26
+ .map((line) => line.trim())
27
+ .filter((line) => line.length > 0)
28
+ .slice(0, limit);
29
+ }
30
+
31
+ /** The text of a `content` field as paragraphs and links. */
32
+ export function contentChildren(text: string): DaisyVNode[] {
33
+ return lines(text).map((line) => {
34
+ const link = LINK_LINE.exec(line);
35
+ if (link) {
36
+ return {
37
+ tag: "a",
38
+ attrs: { href: safeHref(link[2]), class: "link" },
39
+ children: [(link[1] ?? "").slice(0, MAX_TEXT)],
40
+ };
41
+ }
42
+ return { tag: "p", attrs: {}, children: [line.slice(0, MAX_TEXT)] };
43
+ });
44
+ }
45
+
46
+ /** One parsed item of an `items` field: a label and the body text after the first `|`. */
47
+ export type Item = { label: string; body: string };
48
+
49
+ /** The `Label|text` lines of an `items` field. A line without `|` is a label with no body. */
50
+ export function parseItems(text: string): Item[] {
51
+ return lines(text).map((line) => {
52
+ const bar = line.indexOf("|");
53
+ const label = (bar < 0 ? line : line.slice(0, bar)).trim().slice(0, MAX_TEXT);
54
+ const body = bar < 0 ? "" : line.slice(bar + 1).trim().slice(0, MAX_TEXT);
55
+ return { label: label || "Item", body };
56
+ });
57
+ }
58
+
59
+ /** The cells of one `items` table line: `cell|cell|...`, each cut to MAX_TEXT. */
60
+ export function parseCells(line: string): string[] {
61
+ return line.split("|").map((cell) => cell.trim().slice(0, MAX_TEXT));
62
+ }
63
+
64
+ /**
65
+ * A stable id for one element's props. Extension render gets no stored node id, so two elements
66
+ * with different props get different ids (tab and collapse groups use the id in their names).
67
+ */
68
+ export function idFor(props: Record<string, unknown>): string {
69
+ const text = JSON.stringify(props);
70
+ let hash = 0x811c9dc5;
71
+ for (let i = 0; i < text.length; i += 1) {
72
+ hash ^= text.charCodeAt(i);
73
+ hash = Math.imul(hash, 0x01000193) >>> 0;
74
+ }
75
+ return `daisy-${hash.toString(16).padStart(8, "0")}`;
76
+ }
77
+
78
+ /** A component node with the given props, ready for the daisyUI renderer. */
79
+ export function nodeFor(
80
+ component: string,
81
+ props: Record<string, string | number | boolean>,
82
+ children: DaisyComponentNode[] = [],
83
+ id = "daisy-node",
84
+ ): DaisyComponentNode {
85
+ return {
86
+ id,
87
+ type: "provider",
88
+ provider: "daisyui",
89
+ component,
90
+ props,
91
+ children,
92
+ };
93
+ }