@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.
- package/LICENSE +21 -0
- package/README.md +106 -2
- package/licenses/daisyui-MIT.txt +3 -0
- package/package.json +55 -4
- package/src/catalog/basic.ts +407 -0
- package/src/catalog/class-names.ts +623 -0
- package/src/catalog/countdown.ts +392 -0
- package/src/catalog/data-display.ts +563 -0
- package/src/catalog/forms.ts +433 -0
- package/src/catalog/index.ts +77 -0
- package/src/catalog/interactive.ts +567 -0
- package/src/catalog/layout-marketing.ts +641 -0
- package/src/catalog/missing-complex.ts +430 -0
- package/src/catalog/missing-primitives.ts +409 -0
- package/src/catalog/navigation.ts +438 -0
- package/src/catalog/value-class.ts +20 -0
- package/src/compatibility/index.ts +104 -0
- package/src/compound/editor.ts +299 -0
- package/src/compound/index.ts +157 -0
- package/src/conformance/cli.ts +9 -0
- package/src/conformance/compile.ts +77 -0
- package/src/conformance/index.ts +4 -0
- package/src/conformance/manifest.ts +39 -0
- package/src/conformance/official-inventory.ts +135 -0
- package/src/conformance/report-cli.ts +5 -0
- package/src/conformance/report.ts +59 -0
- package/src/conformance/verify-css.ts +22 -0
- package/src/extension/class-token.ts +11 -0
- package/src/extension/classes.ts +636 -0
- package/src/extension/collect-classes.ts +73 -0
- package/src/extension/content.ts +93 -0
- package/src/extension/daisy.css +12441 -0
- package/src/extension/daisy.js +1 -0
- package/src/extension/elements.ts +262 -0
- package/src/extension/index.ts +39 -0
- package/src/extension/to-output.ts +113 -0
- package/src/generator/artifacts.ts +81 -0
- package/src/generator/class-names.ts +35 -0
- package/src/generator/cli.ts +21 -0
- package/src/generator/generate.ts +122 -0
- package/src/generator/index.ts +2 -0
- package/src/generator/write-class-names.ts +10 -0
- package/src/index.ts +12 -0
- package/src/render/classes.ts +48 -0
- package/src/render/href.ts +19 -0
- package/src/render/index.ts +3 -0
- package/src/render/provider.ts +37 -0
- package/src/renderer.ts +6 -0
- package/src/runtime/browser.ts +11 -0
- package/src/runtime/index.ts +41 -0
- package/src/test-support.ts +13 -0
- package/src/themes/index.ts +72 -0
- package/src/types.ts +116 -0
- package/src/validation/index.ts +153 -0
- package/src/verified/primitives.ts +62 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { daisyRenderer } from "../renderer.ts";
|
|
2
|
+
import type { DaisyComponentNode, DaisyFieldDefinition } from "../types.ts";
|
|
3
|
+
import { isCompoundPart } from "../compound/index.ts";
|
|
4
|
+
import { validateCompoundTree } from "../compound/editor.ts";
|
|
5
|
+
|
|
6
|
+
export type DaisyValidationCode =
|
|
7
|
+
| "unknown-component"
|
|
8
|
+
| "unknown-property"
|
|
9
|
+
| "invalid-option"
|
|
10
|
+
| "invalid-value"
|
|
11
|
+
| "missing-label"
|
|
12
|
+
| "invalid-nesting"
|
|
13
|
+
| "duplicate-id";
|
|
14
|
+
export interface DaisyValidationIssue {
|
|
15
|
+
code: DaisyValidationCode;
|
|
16
|
+
nodeId: string;
|
|
17
|
+
path: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const INTERACTIVE_LABELS = new Set([
|
|
22
|
+
"button",
|
|
23
|
+
"input",
|
|
24
|
+
"textarea",
|
|
25
|
+
"select",
|
|
26
|
+
"checkbox",
|
|
27
|
+
"radio",
|
|
28
|
+
"toggle",
|
|
29
|
+
"file-input",
|
|
30
|
+
"range",
|
|
31
|
+
"rating",
|
|
32
|
+
]);
|
|
33
|
+
const CONTAINER_ONLY = new Set([
|
|
34
|
+
"card",
|
|
35
|
+
"navbar",
|
|
36
|
+
"menu",
|
|
37
|
+
"footer",
|
|
38
|
+
"hero",
|
|
39
|
+
"stack",
|
|
40
|
+
"join",
|
|
41
|
+
"indicator",
|
|
42
|
+
"browser-mockup",
|
|
43
|
+
"phone-mockup",
|
|
44
|
+
"code-mockup",
|
|
45
|
+
"drawer",
|
|
46
|
+
"modal",
|
|
47
|
+
"carousel",
|
|
48
|
+
"tabs",
|
|
49
|
+
"accordion",
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
function validField(field: DaisyFieldDefinition, value: unknown): boolean {
|
|
53
|
+
if (field.kind === "boolean") return typeof value === "boolean";
|
|
54
|
+
if (field.kind === "number") return typeof value === "number" && Number.isFinite(value);
|
|
55
|
+
return typeof value === "string";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function validateDaisyTree(nodes: readonly DaisyComponentNode[]): DaisyValidationIssue[] {
|
|
59
|
+
const issues: DaisyValidationIssue[] = [];
|
|
60
|
+
const ids = new Set<string>();
|
|
61
|
+
const walk = (node: DaisyComponentNode, path: string) => {
|
|
62
|
+
if (ids.has(node.id))
|
|
63
|
+
issues.push({
|
|
64
|
+
code: "duplicate-id",
|
|
65
|
+
nodeId: node.id,
|
|
66
|
+
path,
|
|
67
|
+
message: `Duplicate node id ${node.id}.`,
|
|
68
|
+
});
|
|
69
|
+
ids.add(node.id);
|
|
70
|
+
const generated = daisyRenderer.components.get(node.component);
|
|
71
|
+
if (!generated) {
|
|
72
|
+
if (isCompoundPart(node.component)) {
|
|
73
|
+
node.children?.forEach((child, index) => walk(child, `${path}.children[${index}]`));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
issues.push({
|
|
77
|
+
code: "unknown-component",
|
|
78
|
+
nodeId: node.id,
|
|
79
|
+
path,
|
|
80
|
+
message: `Unknown daisyUI component ${node.component}.`,
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const fields = new Map(generated.definition.fields.map((field) => [field.key, field]));
|
|
85
|
+
for (const [key, value] of Object.entries(node.props)) {
|
|
86
|
+
if (key === "theme") continue;
|
|
87
|
+
const field = fields.get(key);
|
|
88
|
+
if (!field)
|
|
89
|
+
issues.push({
|
|
90
|
+
code: "unknown-property",
|
|
91
|
+
nodeId: node.id,
|
|
92
|
+
path: `${path}.props.${key}`,
|
|
93
|
+
message: `${key} is not supported by ${node.component}.`,
|
|
94
|
+
});
|
|
95
|
+
else if (!validField(field, value))
|
|
96
|
+
issues.push({
|
|
97
|
+
code: "invalid-value",
|
|
98
|
+
nodeId: node.id,
|
|
99
|
+
path: `${path}.props.${key}`,
|
|
100
|
+
message: `${key} has the wrong value type.`,
|
|
101
|
+
});
|
|
102
|
+
else if (field.options && !field.options.includes(String(value)))
|
|
103
|
+
issues.push({
|
|
104
|
+
code: "invalid-option",
|
|
105
|
+
nodeId: node.id,
|
|
106
|
+
path: `${path}.props.${key}`,
|
|
107
|
+
message: `${String(value)} is not an allowed ${key} value.`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (INTERACTIVE_LABELS.has(node.component)) {
|
|
111
|
+
const label = node.props.label ?? node.props.text ?? node.props.alt;
|
|
112
|
+
if (typeof label !== "string" || !label.trim())
|
|
113
|
+
issues.push({
|
|
114
|
+
code: "missing-label",
|
|
115
|
+
nodeId: node.id,
|
|
116
|
+
path,
|
|
117
|
+
message: `${node.component} requires a non-empty accessible label.`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (
|
|
121
|
+
(node.children?.length ?? 0) > 0 &&
|
|
122
|
+
!generated.definition.container &&
|
|
123
|
+
!CONTAINER_ONLY.has(node.component)
|
|
124
|
+
) {
|
|
125
|
+
issues.push({
|
|
126
|
+
code: "invalid-nesting",
|
|
127
|
+
nodeId: node.id,
|
|
128
|
+
path,
|
|
129
|
+
message: `${node.component} does not accept child components.`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
node.children?.forEach((child, index) => walk(child, `${path}.children[${index}]`));
|
|
133
|
+
};
|
|
134
|
+
nodes.forEach((node, index) => walk(node, `[${index}]`));
|
|
135
|
+
const collectCompound = (node: DaisyComponentNode): void => {
|
|
136
|
+
for (const issue of validateCompoundTree(node))
|
|
137
|
+
issues.push({
|
|
138
|
+
code: "invalid-nesting",
|
|
139
|
+
nodeId: issue.nodeId,
|
|
140
|
+
path: node.id,
|
|
141
|
+
message: issue.message,
|
|
142
|
+
});
|
|
143
|
+
node.children?.forEach(collectCompound);
|
|
144
|
+
};
|
|
145
|
+
nodes.forEach(collectCompound);
|
|
146
|
+
return issues;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const assertValidDaisyTree = (nodes: readonly DaisyComponentNode[]): void => {
|
|
150
|
+
const issues = validateDaisyTree(nodes);
|
|
151
|
+
if (issues.length)
|
|
152
|
+
throw new Error(issues.map((issue) => `${issue.path}: ${issue.message}`).join("\n"));
|
|
153
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { DaisyComponentNode, DaisyVNode } from "../types.ts";
|
|
2
|
+
import { daisyRenderer } from "../renderer.ts";
|
|
3
|
+
|
|
4
|
+
export const VERIFIED_PRIMITIVE_IDS = [
|
|
5
|
+
"button",
|
|
6
|
+
"badge",
|
|
7
|
+
"alert",
|
|
8
|
+
"card",
|
|
9
|
+
"input",
|
|
10
|
+
"textarea",
|
|
11
|
+
"select",
|
|
12
|
+
"checkbox",
|
|
13
|
+
"toggle",
|
|
14
|
+
"progress",
|
|
15
|
+
] as const;
|
|
16
|
+
|
|
17
|
+
export interface PrimitiveAuditIssue {
|
|
18
|
+
nodeId: string;
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function auditVerifiedPrimitive(node: DaisyComponentNode): PrimitiveAuditIssue[] {
|
|
24
|
+
const issues: PrimitiveAuditIssue[] = [];
|
|
25
|
+
if (!(VERIFIED_PRIMITIVE_IDS as readonly string[]).includes(node.component)) return issues;
|
|
26
|
+
const text = (key: string) => String(node.props[key] ?? "").trim();
|
|
27
|
+
if (
|
|
28
|
+
["button", "input", "textarea", "select", "checkbox", "toggle"].includes(node.component) &&
|
|
29
|
+
!text("label")
|
|
30
|
+
)
|
|
31
|
+
issues.push({
|
|
32
|
+
nodeId: node.id,
|
|
33
|
+
code: "accessible-name",
|
|
34
|
+
message: `${node.component} requires a non-empty label.`,
|
|
35
|
+
});
|
|
36
|
+
if (node.component === "progress") {
|
|
37
|
+
const value = Number(node.props.value);
|
|
38
|
+
const max = Number(node.props.max);
|
|
39
|
+
if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0 || value < 0 || value > max)
|
|
40
|
+
issues.push({
|
|
41
|
+
nodeId: node.id,
|
|
42
|
+
code: "progress-range",
|
|
43
|
+
message: "Progress value must be between zero and max.",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return issues;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function renderVerifiedPrimitive(node: DaisyComponentNode): DaisyVNode {
|
|
50
|
+
if (!(VERIFIED_PRIMITIVE_IDS as readonly string[]).includes(node.component))
|
|
51
|
+
throw new Error(`${node.component} is not a verified primitive.`);
|
|
52
|
+
return daisyRenderer.render(node);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Stable structural signatures derived from official daisyUI v5 examples. */
|
|
56
|
+
export function primitiveSignature(vnode: DaisyVNode): string {
|
|
57
|
+
const visit = (value: DaisyVNode | string): string =>
|
|
58
|
+
typeof value === "string"
|
|
59
|
+
? "#text"
|
|
60
|
+
: `${value.tag}.${(value.attrs.class ?? "").split(/\s+/).filter(Boolean).join(".")}[${value.children.map(visit).join(",")}]`;
|
|
61
|
+
return visit(vnode);
|
|
62
|
+
}
|