praxis-kit 1.1.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.
- package/LICENSE +21 -0
- package/dist/chunk-KDUNVQK2.js +2059 -0
- package/dist/codemod/index.d.ts +21 -0
- package/dist/codemod/index.js +241955 -0
- package/dist/eslint/index.d.ts +84 -0
- package/dist/eslint/index.js +1068 -0
- package/dist/lit/index.d.ts +304 -0
- package/dist/lit/index.js +1887 -0
- package/dist/merge-refs-CfBqh1UO.d.ts +374 -0
- package/dist/preact/index.d.ts +292 -0
- package/dist/preact/index.js +2062 -0
- package/dist/react/index.d.ts +27 -0
- package/dist/react/index.js +197 -0
- package/dist/react/legacy.d.ts +21 -0
- package/dist/react/legacy.js +209 -0
- package/dist/solid/index.d.ts +287 -0
- package/dist/solid/index.js +1837 -0
- package/dist/svelte/index.d.ts +343 -0
- package/dist/svelte/index.js +1723 -0
- package/dist/tailwind/index.d.ts +138 -0
- package/dist/tailwind/index.js +508 -0
- package/dist/ts-plugin/index.cjs +191 -0
- package/dist/ts-plugin/index.d.cts +10 -0
- package/dist/vite-plugin/index.d.ts +395 -0
- package/dist/vite-plugin/index.js +1329 -0
- package/dist/vue/index.d.ts +309 -0
- package/dist/vue/index.js +1922 -0
- package/dist/web/index.d.ts +302 -0
- package/dist/web/index.js +1858 -0
- package/package.json +176 -0
|
@@ -0,0 +1,1858 @@
|
|
|
1
|
+
// ../../lib/adapter-utils/src/apply-filter.ts
|
|
2
|
+
function applyFilter(props, filterProps, variantKeys) {
|
|
3
|
+
const out = {};
|
|
4
|
+
for (const k in props) {
|
|
5
|
+
if (!Object.hasOwn(props, k)) continue;
|
|
6
|
+
if (filterProps(k, variantKeys)) continue;
|
|
7
|
+
out[k] = props[k];
|
|
8
|
+
}
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// ../core/dist/chunk-US6MPMDF.js
|
|
13
|
+
function makeResolveTag(defaultTag) {
|
|
14
|
+
return function tag(as) {
|
|
15
|
+
return as ?? defaultTag;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function assertNever(value) {
|
|
19
|
+
throw new Error(`Unexpected value: ${String(value)}`);
|
|
20
|
+
}
|
|
21
|
+
function r(e) {
|
|
22
|
+
var t, f, n = "";
|
|
23
|
+
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
24
|
+
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
25
|
+
var o = e.length;
|
|
26
|
+
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
27
|
+
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
function clsx() {
|
|
31
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
32
|
+
return n;
|
|
33
|
+
}
|
|
34
|
+
function cn(...inputs) {
|
|
35
|
+
return clsx(...inputs);
|
|
36
|
+
}
|
|
37
|
+
function mergeProps(defaultProps, props) {
|
|
38
|
+
return {
|
|
39
|
+
...defaultProps ?? {},
|
|
40
|
+
...props
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function isNull(value) {
|
|
44
|
+
return value === null;
|
|
45
|
+
}
|
|
46
|
+
function isObject(value) {
|
|
47
|
+
return !isNull(value) && typeof value === "object";
|
|
48
|
+
}
|
|
49
|
+
function isString(value) {
|
|
50
|
+
return typeof value === "string";
|
|
51
|
+
}
|
|
52
|
+
function isNumber(value) {
|
|
53
|
+
return typeof value === "number";
|
|
54
|
+
}
|
|
55
|
+
var EMPTY_VARIANT_KEYS = /* @__PURE__ */ new Set();
|
|
56
|
+
function composeNormalizers(normalizers, fn) {
|
|
57
|
+
if (!normalizers?.length) return fn;
|
|
58
|
+
return ((props) => {
|
|
59
|
+
const patched = normalizers.reduce(
|
|
60
|
+
(acc, normalizer) => ({ ...acc, ...normalizer(acc) }),
|
|
61
|
+
props
|
|
62
|
+
);
|
|
63
|
+
return fn ? fn(patched) : patched;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function whenDefined(key, value) {
|
|
67
|
+
return value === void 0 ? {} : { [key]: value };
|
|
68
|
+
}
|
|
69
|
+
function resolveFactoryOptions(options = {}) {
|
|
70
|
+
const { styling, enforcement } = options;
|
|
71
|
+
const composedNormalizeFn = composeNormalizers(enforcement?.props, options.normalize);
|
|
72
|
+
const variantKeys = styling?.variants === void 0 ? EMPTY_VARIANT_KEYS : new Set(Object.keys(styling.variants));
|
|
73
|
+
return Object.freeze({
|
|
74
|
+
defaultTag: options.tag ?? "div",
|
|
75
|
+
strict: enforcement?.strict ?? false,
|
|
76
|
+
variantKeys,
|
|
77
|
+
...whenDefined("displayName", options.name),
|
|
78
|
+
...whenDefined("defaultProps", options.defaults),
|
|
79
|
+
...whenDefined("baseClassName", styling?.base),
|
|
80
|
+
...whenDefined("tagMap", styling?.tags),
|
|
81
|
+
...whenDefined("presetMap", styling?.presets),
|
|
82
|
+
...whenDefined("variants", styling?.variants),
|
|
83
|
+
...whenDefined("defaultVariants", styling?.defaults),
|
|
84
|
+
...whenDefined("compoundVariants", styling?.compounds),
|
|
85
|
+
...whenDefined("normalizeFn", composedNormalizeFn),
|
|
86
|
+
...whenDefined("ariaRules", enforcement?.aria),
|
|
87
|
+
...whenDefined("childRules", enforcement?.children),
|
|
88
|
+
...whenDefined("allowedAs", enforcement?.allowedAs),
|
|
89
|
+
...whenDefined("precomputedClasses", styling?.precomputedClasses)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function report(strict, message) {
|
|
93
|
+
if (strict === false) return;
|
|
94
|
+
const mode = strict === true ? "throw" : strict;
|
|
95
|
+
if (mode === "throw") throw new Error(message);
|
|
96
|
+
console.warn(message);
|
|
97
|
+
}
|
|
98
|
+
function validateFactoryOptions(resolved) {
|
|
99
|
+
const { strict } = resolved;
|
|
100
|
+
if (strict === false) return;
|
|
101
|
+
const name = resolved.displayName ?? "Component";
|
|
102
|
+
const { variants } = resolved;
|
|
103
|
+
const checkSelection = (label2, selection) => {
|
|
104
|
+
const record = selection;
|
|
105
|
+
for (const dim in record) {
|
|
106
|
+
const value = record[dim];
|
|
107
|
+
if (value === void 0 || value === null) continue;
|
|
108
|
+
if (!variants || !Object.hasOwn(variants, dim)) {
|
|
109
|
+
report(strict, `${name}: ${label2} references unknown variant "${dim}".`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const states = variants[dim];
|
|
113
|
+
const stateKey = String(value);
|
|
114
|
+
if (!Object.hasOwn(states, stateKey)) {
|
|
115
|
+
report(
|
|
116
|
+
strict,
|
|
117
|
+
`${name}: ${label2} sets "${dim}" to unknown value "${stateKey}" (valid: ${Object.keys(states).join(", ")}).`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const { presetMap } = resolved;
|
|
123
|
+
if (presetMap) {
|
|
124
|
+
for (const presetKey in presetMap) {
|
|
125
|
+
checkSelection(`preset "${presetKey}"`, presetMap[presetKey]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (resolved.defaultVariants) checkSelection("defaults", resolved.defaultVariants);
|
|
129
|
+
}
|
|
130
|
+
var warned = /* @__PURE__ */ new Set();
|
|
131
|
+
var pendingAsyncWarns = /* @__PURE__ */ new Set();
|
|
132
|
+
var asyncWarnScheduled = false;
|
|
133
|
+
function flushAsyncWarns() {
|
|
134
|
+
asyncWarnScheduled = false;
|
|
135
|
+
const messages = [...pendingAsyncWarns];
|
|
136
|
+
pendingAsyncWarns.clear();
|
|
137
|
+
for (const msg of messages) {
|
|
138
|
+
console.warn(msg);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function report2(strict, message) {
|
|
142
|
+
if (!strict) return;
|
|
143
|
+
const mode = strict === true ? "throw" : strict;
|
|
144
|
+
if (mode === "throw") throw new Error(message);
|
|
145
|
+
if (mode === "async-warn") {
|
|
146
|
+
if (pendingAsyncWarns.has(message)) return;
|
|
147
|
+
pendingAsyncWarns.add(message);
|
|
148
|
+
if (!asyncWarnScheduled) {
|
|
149
|
+
asyncWarnScheduled = true;
|
|
150
|
+
queueMicrotask(flushAsyncWarns);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (warned.has(message)) return;
|
|
155
|
+
warned.add(message);
|
|
156
|
+
console.warn(message);
|
|
157
|
+
}
|
|
158
|
+
function label(name) {
|
|
159
|
+
return name ? `[${name}]` : "[createContractComponent]";
|
|
160
|
+
}
|
|
161
|
+
function validateRenderProps(options, props, presetKey) {
|
|
162
|
+
const { strict, presetMap, variants, displayName } = options;
|
|
163
|
+
if (!strict) return;
|
|
164
|
+
const tag = label(displayName);
|
|
165
|
+
if (presetKey !== void 0 && (!presetMap || !Object.hasOwn(presetMap, presetKey))) {
|
|
166
|
+
report2(strict, `${tag} Unknown presetKey "${presetKey}" \u2014 no preset with that name exists.`);
|
|
167
|
+
}
|
|
168
|
+
if (variants) {
|
|
169
|
+
for (const key in variants) {
|
|
170
|
+
if (!Object.hasOwn(props, key)) continue;
|
|
171
|
+
const value = props[key];
|
|
172
|
+
if (value === void 0 || value === null) continue;
|
|
173
|
+
const dim = variants[key];
|
|
174
|
+
if (dim && !Object.hasOwn(dim, String(value))) {
|
|
175
|
+
report2(
|
|
176
|
+
strict,
|
|
177
|
+
`${tag} Variant "${key}=${String(value)}" is not a defined value for the "${key}" dimension.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function panic(message) {
|
|
184
|
+
throw new Error(message);
|
|
185
|
+
}
|
|
186
|
+
function describe(value) {
|
|
187
|
+
if (value === null) return "null";
|
|
188
|
+
if (Array.isArray(value)) return "array";
|
|
189
|
+
return typeof value;
|
|
190
|
+
}
|
|
191
|
+
function assertPluginShape(result) {
|
|
192
|
+
if (result === null || typeof result !== "object")
|
|
193
|
+
panic(
|
|
194
|
+
`[praxis-kit] Plugin factory must return an object with a 'pipeline' function. Got: ${result === null ? "null" : typeof result}.`
|
|
195
|
+
);
|
|
196
|
+
const plugin = result;
|
|
197
|
+
if (typeof plugin.pipeline !== "function")
|
|
198
|
+
panic(
|
|
199
|
+
`[praxis-kit] Plugin factory return value is missing a 'pipeline' function. Got pipeline: ${typeof plugin.pipeline}.`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
function guardPipeline(pipeline) {
|
|
203
|
+
if (process.env.NODE_ENV === "production") return pipeline;
|
|
204
|
+
return function guardedPipeline(tag, props, className, variantKey) {
|
|
205
|
+
const result = pipeline(tag, props, className, variantKey);
|
|
206
|
+
if (typeof result !== "string")
|
|
207
|
+
panic(`[praxis-kit] Plugin pipeline must return a string. Got: ${describe(result)}.`);
|
|
208
|
+
return result;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
var NOOP_CLASS_PIPELINE = (_tag, _props, className) => Array.isArray(className) ? className.join(" ") : className ?? "";
|
|
212
|
+
function resolveClassPipeline(options, resolved, strict, capabilities) {
|
|
213
|
+
const factory = options.styling?.plugin;
|
|
214
|
+
if (!factory) {
|
|
215
|
+
const createClassPipeline2 = capabilities?.createClassPipeline;
|
|
216
|
+
const classPipeline2 = createClassPipeline2 ? createClassPipeline2(resolved) : NOOP_CLASS_PIPELINE;
|
|
217
|
+
return { pluginResult: void 0, classPipeline: classPipeline2 };
|
|
218
|
+
}
|
|
219
|
+
const pluginResult = factory(resolved, strict);
|
|
220
|
+
assertPluginShape(pluginResult);
|
|
221
|
+
const classPipeline = guardPipeline(pluginResult.pipeline);
|
|
222
|
+
return { pluginResult, classPipeline };
|
|
223
|
+
}
|
|
224
|
+
function createRuntimeMethods(resolved, classPipeline, engine) {
|
|
225
|
+
return {
|
|
226
|
+
resolveTag: makeResolveTag(resolved.defaultTag),
|
|
227
|
+
resolveProps(props) {
|
|
228
|
+
return mergeProps(resolved.defaultProps, props);
|
|
229
|
+
},
|
|
230
|
+
resolveClasses(tag, props, className, variantKey) {
|
|
231
|
+
if (process.env.NODE_ENV !== "production") {
|
|
232
|
+
validateRenderProps(resolved, props, variantKey);
|
|
233
|
+
}
|
|
234
|
+
return classPipeline(tag, props, className, variantKey);
|
|
235
|
+
},
|
|
236
|
+
resolveAria(tag, props) {
|
|
237
|
+
if (!engine) return { props };
|
|
238
|
+
const result = engine.validate(tag, props);
|
|
239
|
+
return { props: result.props };
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
function createRuntimeObject(methods, resolved, pluginResult) {
|
|
244
|
+
return pluginResult ? { ...methods, options: resolved, hasStyling: true, classPlugin: pluginResult } : { ...methods, options: resolved };
|
|
245
|
+
}
|
|
246
|
+
function createPolymorphic(options = {}, capabilities) {
|
|
247
|
+
const resolved = resolveFactoryOptions(options);
|
|
248
|
+
if (process.env.NODE_ENV !== "production") validateFactoryOptions(resolved);
|
|
249
|
+
const { pluginResult, classPipeline } = resolveClassPipeline(
|
|
250
|
+
options,
|
|
251
|
+
resolved,
|
|
252
|
+
resolved.strict,
|
|
253
|
+
capabilities
|
|
254
|
+
);
|
|
255
|
+
const engine = options.enforcement !== void 0 && capabilities?.AriaEngine ? new capabilities.AriaEngine(
|
|
256
|
+
resolved.strict,
|
|
257
|
+
resolved.ariaRules?.length ? { rules: resolved.ariaRules } : void 0
|
|
258
|
+
) : null;
|
|
259
|
+
const methods = createRuntimeMethods(resolved, classPipeline, engine);
|
|
260
|
+
return createRuntimeObject(
|
|
261
|
+
methods,
|
|
262
|
+
resolved,
|
|
263
|
+
pluginResult
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
var KNOWN_ARIA_ROLES = [
|
|
267
|
+
"alert",
|
|
268
|
+
"alertdialog",
|
|
269
|
+
"application",
|
|
270
|
+
"article",
|
|
271
|
+
"banner",
|
|
272
|
+
"blockquote",
|
|
273
|
+
"button",
|
|
274
|
+
"caption",
|
|
275
|
+
"cell",
|
|
276
|
+
"checkbox",
|
|
277
|
+
"code",
|
|
278
|
+
"columnheader",
|
|
279
|
+
"combobox",
|
|
280
|
+
"complementary",
|
|
281
|
+
"contentinfo",
|
|
282
|
+
"definition",
|
|
283
|
+
"deletion",
|
|
284
|
+
"dialog",
|
|
285
|
+
"document",
|
|
286
|
+
"emphasis",
|
|
287
|
+
"feed",
|
|
288
|
+
"figure",
|
|
289
|
+
"form",
|
|
290
|
+
"generic",
|
|
291
|
+
"grid",
|
|
292
|
+
"gridcell",
|
|
293
|
+
"group",
|
|
294
|
+
"heading",
|
|
295
|
+
"img",
|
|
296
|
+
"insertion",
|
|
297
|
+
"link",
|
|
298
|
+
"list",
|
|
299
|
+
"listbox",
|
|
300
|
+
"listitem",
|
|
301
|
+
"log",
|
|
302
|
+
"main",
|
|
303
|
+
"marquee",
|
|
304
|
+
"math",
|
|
305
|
+
"menu",
|
|
306
|
+
"menubar",
|
|
307
|
+
"menuitem",
|
|
308
|
+
"menuitemcheckbox",
|
|
309
|
+
"menuitemradio",
|
|
310
|
+
"meter",
|
|
311
|
+
"navigation",
|
|
312
|
+
"none",
|
|
313
|
+
"note",
|
|
314
|
+
"option",
|
|
315
|
+
"paragraph",
|
|
316
|
+
"presentation",
|
|
317
|
+
"progressbar",
|
|
318
|
+
"radio",
|
|
319
|
+
"radiogroup",
|
|
320
|
+
"region",
|
|
321
|
+
"row",
|
|
322
|
+
"rowgroup",
|
|
323
|
+
"rowheader",
|
|
324
|
+
"scrollbar",
|
|
325
|
+
"search",
|
|
326
|
+
"searchbox",
|
|
327
|
+
"separator",
|
|
328
|
+
"slider",
|
|
329
|
+
"spinbutton",
|
|
330
|
+
"status",
|
|
331
|
+
"strong",
|
|
332
|
+
"subscript",
|
|
333
|
+
"superscript",
|
|
334
|
+
"switch",
|
|
335
|
+
"tab",
|
|
336
|
+
"table",
|
|
337
|
+
"tablist",
|
|
338
|
+
"tabpanel",
|
|
339
|
+
"term",
|
|
340
|
+
"textbox",
|
|
341
|
+
"time",
|
|
342
|
+
"timer",
|
|
343
|
+
"toolbar",
|
|
344
|
+
"tooltip",
|
|
345
|
+
"tree",
|
|
346
|
+
"treegrid",
|
|
347
|
+
"treeitem"
|
|
348
|
+
];
|
|
349
|
+
var KNOWN_ARIA_ROLES_SET = new Set(KNOWN_ARIA_ROLES);
|
|
350
|
+
var GLOBAL_ARIA_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
351
|
+
"aria-atomic",
|
|
352
|
+
"aria-busy",
|
|
353
|
+
"aria-controls",
|
|
354
|
+
"aria-current",
|
|
355
|
+
"aria-describedby",
|
|
356
|
+
"aria-details",
|
|
357
|
+
"aria-disabled",
|
|
358
|
+
"aria-errormessage",
|
|
359
|
+
"aria-flowto",
|
|
360
|
+
"aria-hidden",
|
|
361
|
+
"aria-keyshortcuts",
|
|
362
|
+
"aria-label",
|
|
363
|
+
"aria-labelledby",
|
|
364
|
+
"aria-live",
|
|
365
|
+
"aria-owns",
|
|
366
|
+
"aria-relevant",
|
|
367
|
+
"aria-roledescription"
|
|
368
|
+
]);
|
|
369
|
+
var IMPLICIT_ROLE_RECORD = {
|
|
370
|
+
article: "article",
|
|
371
|
+
aside: "complementary",
|
|
372
|
+
footer: "contentinfo",
|
|
373
|
+
header: "banner",
|
|
374
|
+
main: "main",
|
|
375
|
+
nav: "navigation",
|
|
376
|
+
button: "button",
|
|
377
|
+
a: "link",
|
|
378
|
+
select: "listbox",
|
|
379
|
+
h1: "heading",
|
|
380
|
+
h2: "heading",
|
|
381
|
+
h3: "heading",
|
|
382
|
+
h4: "heading",
|
|
383
|
+
h5: "heading",
|
|
384
|
+
h6: "heading",
|
|
385
|
+
ul: "list",
|
|
386
|
+
ol: "list",
|
|
387
|
+
li: "listitem",
|
|
388
|
+
table: "table",
|
|
389
|
+
tr: "row",
|
|
390
|
+
td: "cell",
|
|
391
|
+
th: "columnheader"
|
|
392
|
+
};
|
|
393
|
+
var STRONG_ROLES = [
|
|
394
|
+
"main",
|
|
395
|
+
"navigation",
|
|
396
|
+
"complementary",
|
|
397
|
+
"contentinfo",
|
|
398
|
+
"banner"
|
|
399
|
+
];
|
|
400
|
+
var STANDALONE_ROLES = ["article"];
|
|
401
|
+
var STRONG_ROLES_SET = new Set(STRONG_ROLES);
|
|
402
|
+
var STANDALONE_ROLES_SET = new Set(STANDALONE_ROLES);
|
|
403
|
+
var ROLE_RESTRICTED_ATTRIBUTES = /* @__PURE__ */ new Map([
|
|
404
|
+
[
|
|
405
|
+
"aria-activedescendant",
|
|
406
|
+
/* @__PURE__ */ new Set([
|
|
407
|
+
"application",
|
|
408
|
+
"combobox",
|
|
409
|
+
"grid",
|
|
410
|
+
"group",
|
|
411
|
+
"listbox",
|
|
412
|
+
"menu",
|
|
413
|
+
"menubar",
|
|
414
|
+
"radiogroup",
|
|
415
|
+
"spinbutton",
|
|
416
|
+
"tablist",
|
|
417
|
+
"toolbar",
|
|
418
|
+
"textbox",
|
|
419
|
+
"tree",
|
|
420
|
+
"treegrid"
|
|
421
|
+
])
|
|
422
|
+
],
|
|
423
|
+
["aria-autocomplete", /* @__PURE__ */ new Set(["combobox", "searchbox", "textbox"])],
|
|
424
|
+
[
|
|
425
|
+
"aria-checked",
|
|
426
|
+
/* @__PURE__ */ new Set(["checkbox", "menuitemcheckbox", "option", "radio", "switch", "treeitem"])
|
|
427
|
+
],
|
|
428
|
+
["aria-colcount", /* @__PURE__ */ new Set(["grid", "table", "treegrid"])],
|
|
429
|
+
["aria-colindex", /* @__PURE__ */ new Set(["cell", "columnheader", "gridcell", "row", "rowheader"])],
|
|
430
|
+
["aria-colspan", /* @__PURE__ */ new Set(["cell", "columnheader", "gridcell", "rowheader"])],
|
|
431
|
+
[
|
|
432
|
+
"aria-expanded",
|
|
433
|
+
/* @__PURE__ */ new Set([
|
|
434
|
+
"button",
|
|
435
|
+
"combobox",
|
|
436
|
+
"gridcell",
|
|
437
|
+
"listbox",
|
|
438
|
+
"menuitem",
|
|
439
|
+
"menuitemcheckbox",
|
|
440
|
+
"menuitemradio",
|
|
441
|
+
"row",
|
|
442
|
+
"rowheader",
|
|
443
|
+
"tab",
|
|
444
|
+
"treeitem"
|
|
445
|
+
])
|
|
446
|
+
],
|
|
447
|
+
[
|
|
448
|
+
"aria-haspopup",
|
|
449
|
+
/* @__PURE__ */ new Set([
|
|
450
|
+
"button",
|
|
451
|
+
"combobox",
|
|
452
|
+
"gridcell",
|
|
453
|
+
"listbox",
|
|
454
|
+
"menuitem",
|
|
455
|
+
"menuitemcheckbox",
|
|
456
|
+
"menuitemradio",
|
|
457
|
+
"tab",
|
|
458
|
+
"treeitem"
|
|
459
|
+
])
|
|
460
|
+
],
|
|
461
|
+
["aria-level", /* @__PURE__ */ new Set(["heading", "listitem", "row", "treeitem"])],
|
|
462
|
+
["aria-modal", /* @__PURE__ */ new Set(["alertdialog", "dialog"])],
|
|
463
|
+
["aria-multiline", /* @__PURE__ */ new Set(["textbox"])],
|
|
464
|
+
["aria-multiselectable", /* @__PURE__ */ new Set(["grid", "listbox", "tablist", "tree", "treegrid"])],
|
|
465
|
+
[
|
|
466
|
+
"aria-orientation",
|
|
467
|
+
/* @__PURE__ */ new Set(["scrollbar", "select", "separator", "slider", "tablist", "toolbar", "tree"])
|
|
468
|
+
],
|
|
469
|
+
["aria-placeholder", /* @__PURE__ */ new Set(["searchbox", "textbox"])],
|
|
470
|
+
[
|
|
471
|
+
"aria-posinset",
|
|
472
|
+
/* @__PURE__ */ new Set([
|
|
473
|
+
"article",
|
|
474
|
+
"listitem",
|
|
475
|
+
"menuitem",
|
|
476
|
+
"menuitemcheckbox",
|
|
477
|
+
"menuitemradio",
|
|
478
|
+
"option",
|
|
479
|
+
"radio",
|
|
480
|
+
"row",
|
|
481
|
+
"tab"
|
|
482
|
+
])
|
|
483
|
+
],
|
|
484
|
+
["aria-pressed", /* @__PURE__ */ new Set(["button"])],
|
|
485
|
+
[
|
|
486
|
+
"aria-readonly",
|
|
487
|
+
/* @__PURE__ */ new Set([
|
|
488
|
+
"combobox",
|
|
489
|
+
"grid",
|
|
490
|
+
"gridcell",
|
|
491
|
+
"listbox",
|
|
492
|
+
"radiogroup",
|
|
493
|
+
"slider",
|
|
494
|
+
"spinbutton",
|
|
495
|
+
"textbox",
|
|
496
|
+
"tree",
|
|
497
|
+
"treegrid"
|
|
498
|
+
])
|
|
499
|
+
],
|
|
500
|
+
[
|
|
501
|
+
"aria-required",
|
|
502
|
+
/* @__PURE__ */ new Set([
|
|
503
|
+
"combobox",
|
|
504
|
+
"gridcell",
|
|
505
|
+
"listbox",
|
|
506
|
+
"radiogroup",
|
|
507
|
+
"spinbutton",
|
|
508
|
+
"textbox",
|
|
509
|
+
"tree",
|
|
510
|
+
"treegrid"
|
|
511
|
+
])
|
|
512
|
+
],
|
|
513
|
+
["aria-rowcount", /* @__PURE__ */ new Set(["grid", "table", "treegrid"])],
|
|
514
|
+
["aria-rowindex", /* @__PURE__ */ new Set(["cell", "columnheader", "gridcell", "row", "rowheader"])],
|
|
515
|
+
["aria-rowspan", /* @__PURE__ */ new Set(["cell", "columnheader", "gridcell", "rowheader"])],
|
|
516
|
+
[
|
|
517
|
+
"aria-selected",
|
|
518
|
+
/* @__PURE__ */ new Set(["columnheader", "gridcell", "option", "row", "rowheader", "tab", "treeitem"])
|
|
519
|
+
],
|
|
520
|
+
[
|
|
521
|
+
"aria-setsize",
|
|
522
|
+
/* @__PURE__ */ new Set([
|
|
523
|
+
"article",
|
|
524
|
+
"listitem",
|
|
525
|
+
"menuitem",
|
|
526
|
+
"menuitemcheckbox",
|
|
527
|
+
"menuitemradio",
|
|
528
|
+
"option",
|
|
529
|
+
"radio",
|
|
530
|
+
"row",
|
|
531
|
+
"tab"
|
|
532
|
+
])
|
|
533
|
+
],
|
|
534
|
+
["aria-sort", /* @__PURE__ */ new Set(["columnheader", "rowheader"])],
|
|
535
|
+
[
|
|
536
|
+
"aria-valuemax",
|
|
537
|
+
/* @__PURE__ */ new Set(["meter", "progressbar", "scrollbar", "separator", "slider", "spinbutton"])
|
|
538
|
+
],
|
|
539
|
+
[
|
|
540
|
+
"aria-valuemin",
|
|
541
|
+
/* @__PURE__ */ new Set(["meter", "progressbar", "scrollbar", "separator", "slider", "spinbutton"])
|
|
542
|
+
],
|
|
543
|
+
[
|
|
544
|
+
"aria-valuenow",
|
|
545
|
+
/* @__PURE__ */ new Set(["meter", "progressbar", "scrollbar", "separator", "slider", "spinbutton"])
|
|
546
|
+
],
|
|
547
|
+
[
|
|
548
|
+
"aria-valuetext",
|
|
549
|
+
/* @__PURE__ */ new Set(["meter", "progressbar", "scrollbar", "separator", "slider", "spinbutton"])
|
|
550
|
+
]
|
|
551
|
+
]);
|
|
552
|
+
function isUndefined(value) {
|
|
553
|
+
return value === void 0;
|
|
554
|
+
}
|
|
555
|
+
function isGlobalAriaAttribute(attr) {
|
|
556
|
+
return GLOBAL_ARIA_ATTRIBUTES.has(attr);
|
|
557
|
+
}
|
|
558
|
+
function isAriaAttributeValidForRole(attr, role) {
|
|
559
|
+
const allowedRoles = ROLE_RESTRICTED_ATTRIBUTES.get(attr);
|
|
560
|
+
if (isUndefined(allowedRoles)) return true;
|
|
561
|
+
if (isUndefined(role)) return false;
|
|
562
|
+
return allowedRoles.has(role);
|
|
563
|
+
}
|
|
564
|
+
function isStrongImplicitRole(tag) {
|
|
565
|
+
if (!(tag in IMPLICIT_ROLE_RECORD)) return false;
|
|
566
|
+
return STRONG_ROLES_SET.has(IMPLICIT_ROLE_RECORD[tag]);
|
|
567
|
+
}
|
|
568
|
+
function isStandaloneTag(tag) {
|
|
569
|
+
if (!(tag in IMPLICIT_ROLE_RECORD)) return false;
|
|
570
|
+
return STANDALONE_ROLES_SET.has(IMPLICIT_ROLE_RECORD[tag]);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// ../core/dist/chunk-7YNORQXK.js
|
|
574
|
+
var COMPONENT_DEFAULT_TAG = /* @__PURE__ */ Symbol("praxis.component-default-tag");
|
|
575
|
+
function resolveChildTag(child) {
|
|
576
|
+
if (!isObject(child) || !("type" in child)) return void 0;
|
|
577
|
+
const t = child.type;
|
|
578
|
+
if (isString(t)) return t;
|
|
579
|
+
if (isObject(t) && COMPONENT_DEFAULT_TAG in t) {
|
|
580
|
+
const defaultTag = t[COMPONENT_DEFAULT_TAG];
|
|
581
|
+
if (!isString(defaultTag)) return void 0;
|
|
582
|
+
const props = child.props;
|
|
583
|
+
const as = isObject(props) && "as" in props ? props.as : void 0;
|
|
584
|
+
return isString(as) ? as : defaultTag;
|
|
585
|
+
}
|
|
586
|
+
return void 0;
|
|
587
|
+
}
|
|
588
|
+
function isTag(...tags) {
|
|
589
|
+
const set = new Set(tags);
|
|
590
|
+
return (child) => {
|
|
591
|
+
const tag = resolveChildTag(child);
|
|
592
|
+
return tag !== void 0 && set.has(tag);
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
function isOpenContent(...blockedTags) {
|
|
596
|
+
const set = new Set(blockedTags);
|
|
597
|
+
return (child) => isObject(child) && "type" in child && (!isString(child.type) || !set.has(child.type));
|
|
598
|
+
}
|
|
599
|
+
var METADATA_TAGS = ["script", "template"];
|
|
600
|
+
var metadataMatch = isTag(...METADATA_TAGS);
|
|
601
|
+
function metadata(name = "metadata") {
|
|
602
|
+
return { name, match: metadataMatch };
|
|
603
|
+
}
|
|
604
|
+
function firstOptional(name, tag) {
|
|
605
|
+
return { name, match: isTag(tag), cardinality: { max: 1 }, position: "first" };
|
|
606
|
+
}
|
|
607
|
+
function contract(children) {
|
|
608
|
+
return { strict: "warn", children };
|
|
609
|
+
}
|
|
610
|
+
function ariaContract(aria) {
|
|
611
|
+
return { strict: "warn", aria };
|
|
612
|
+
}
|
|
613
|
+
function firstChildContract(name, tag) {
|
|
614
|
+
return contract([firstOptional(name, tag), { name: "content", match: isOpenContent(tag) }]);
|
|
615
|
+
}
|
|
616
|
+
var VOID_TAGS = [
|
|
617
|
+
"area",
|
|
618
|
+
"base",
|
|
619
|
+
"br",
|
|
620
|
+
"col",
|
|
621
|
+
"embed",
|
|
622
|
+
"hr",
|
|
623
|
+
"img",
|
|
624
|
+
"input",
|
|
625
|
+
"link",
|
|
626
|
+
"meta",
|
|
627
|
+
"param",
|
|
628
|
+
"source",
|
|
629
|
+
"track",
|
|
630
|
+
"wbr"
|
|
631
|
+
];
|
|
632
|
+
var TEXT_ONLY_TAGS = ["option", "script", "style", "textarea", "title"];
|
|
633
|
+
var LANDMARK_TAGS = ["article", "aside", "footer", "header", "main", "nav"];
|
|
634
|
+
var listContract = contract([{ name: "list-item", match: isTag("li", ...METADATA_TAGS) }]);
|
|
635
|
+
var tableContract = contract([
|
|
636
|
+
firstOptional("caption", "caption"),
|
|
637
|
+
{ name: "colgroup", match: isTag("colgroup") },
|
|
638
|
+
{ name: "thead", match: isTag("thead"), cardinality: { max: 1 } },
|
|
639
|
+
{ name: "tbody", match: isTag("tbody") },
|
|
640
|
+
{ name: "tfoot", match: isTag("tfoot"), cardinality: { max: 1 } },
|
|
641
|
+
{ name: "table-row", match: isTag("tr", ...METADATA_TAGS) }
|
|
642
|
+
]);
|
|
643
|
+
var tableBodyContract = contract([
|
|
644
|
+
{ name: "table-row", match: isTag("tr", ...METADATA_TAGS) }
|
|
645
|
+
]);
|
|
646
|
+
var tableRowContract = contract([
|
|
647
|
+
{ name: "table-cell", match: isTag("td", "th", ...METADATA_TAGS) }
|
|
648
|
+
]);
|
|
649
|
+
var colgroupContract = contract([{ name: "column", match: isTag("col", "template") }]);
|
|
650
|
+
var dlContract = contract([
|
|
651
|
+
{ name: "term", match: isTag("dt") },
|
|
652
|
+
{ name: "description", match: isTag("dd") },
|
|
653
|
+
{ name: "group", match: isTag("div") },
|
|
654
|
+
metadata()
|
|
655
|
+
]);
|
|
656
|
+
var selectContract = contract([
|
|
657
|
+
{ name: "option", match: isTag("option", "optgroup", "hr", ...METADATA_TAGS) }
|
|
658
|
+
]);
|
|
659
|
+
var optgroupContract = contract([
|
|
660
|
+
{ name: "option", match: isTag("option", ...METADATA_TAGS) }
|
|
661
|
+
]);
|
|
662
|
+
var datalistContract = contract([
|
|
663
|
+
{ name: "option", match: isTag("option", ...METADATA_TAGS) }
|
|
664
|
+
]);
|
|
665
|
+
var pictureContract = contract([
|
|
666
|
+
{ name: "source", match: isTag("source", ...METADATA_TAGS) },
|
|
667
|
+
{ name: "image", match: isTag("img"), cardinality: { min: 1, max: 1 }, position: "last" }
|
|
668
|
+
]);
|
|
669
|
+
var figureContract = contract([
|
|
670
|
+
{ name: "caption", match: isTag("figcaption"), cardinality: { max: 1 } },
|
|
671
|
+
{ name: "content", match: isOpenContent("figcaption") }
|
|
672
|
+
]);
|
|
673
|
+
var detailsContract = firstChildContract("summary", "summary");
|
|
674
|
+
var fieldsetContract = firstChildContract("legend", "legend");
|
|
675
|
+
var mediaContract = contract([
|
|
676
|
+
{ name: "source", match: isTag("source") },
|
|
677
|
+
{ name: "track", match: isTag("track") },
|
|
678
|
+
metadata(),
|
|
679
|
+
{ name: "content", match: isOpenContent("source", "track", ...METADATA_TAGS) }
|
|
680
|
+
]);
|
|
681
|
+
var headContract = contract([
|
|
682
|
+
{
|
|
683
|
+
name: "metadata",
|
|
684
|
+
match: isTag("base", "link", "meta", "noscript", "script", "style", "template", "title")
|
|
685
|
+
}
|
|
686
|
+
]);
|
|
687
|
+
var htmlContract = contract([
|
|
688
|
+
{ name: "head", match: isTag("head"), cardinality: { min: 1, max: 1 }, position: "first" },
|
|
689
|
+
{ name: "body", match: isTag("body"), cardinality: { min: 1, max: 1 } }
|
|
690
|
+
]);
|
|
691
|
+
var voidContract = contract([]);
|
|
692
|
+
var textOnlyContract = contract([
|
|
693
|
+
{
|
|
694
|
+
name: "text",
|
|
695
|
+
match: (child) => isString(child) || isNumber(child)
|
|
696
|
+
}
|
|
697
|
+
]);
|
|
698
|
+
var LANDMARK_TAG_SET = new Set(LANDMARK_TAGS);
|
|
699
|
+
var removeLandmarkRoleOverride = {
|
|
700
|
+
kind: "removeRole",
|
|
701
|
+
apply: ({ props }) => {
|
|
702
|
+
if (!("role" in props)) return { applied: false, next: props };
|
|
703
|
+
const { role: _r, ...rest } = props;
|
|
704
|
+
return { applied: true, next: rest, previous: props };
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
function landmarkRoleRule({ tag, props, implicitRole }) {
|
|
708
|
+
if (!LANDMARK_TAG_SET.has(tag) || !implicitRole) return [];
|
|
709
|
+
const role = props.role;
|
|
710
|
+
if (!role || role === implicitRole) return [];
|
|
711
|
+
return [
|
|
712
|
+
{
|
|
713
|
+
valid: false,
|
|
714
|
+
fixable: true,
|
|
715
|
+
severity: "error",
|
|
716
|
+
fix: removeLandmarkRoleOverride,
|
|
717
|
+
message: `<${tag}> has a fixed landmark role="${implicitRole}". role="${role}" overrides it and confuses assistive technology. The override has been removed.`
|
|
718
|
+
}
|
|
719
|
+
];
|
|
720
|
+
}
|
|
721
|
+
var landmarkContract = ariaContract([landmarkRoleRule]);
|
|
722
|
+
var CONTRACT_GROUPS = [
|
|
723
|
+
[VOID_TAGS, voidContract],
|
|
724
|
+
[TEXT_ONLY_TAGS, textOnlyContract],
|
|
725
|
+
[LANDMARK_TAGS, landmarkContract],
|
|
726
|
+
[["ul", "ol", "menu"], listContract],
|
|
727
|
+
[["audio", "video"], mediaContract],
|
|
728
|
+
[["thead", "tbody", "tfoot"], tableBodyContract]
|
|
729
|
+
];
|
|
730
|
+
function contractMap(groups) {
|
|
731
|
+
return Object.fromEntries(
|
|
732
|
+
groups.flatMap(([tags, enforcement]) => tags.map((tag) => [tag, enforcement]))
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
var htmlContracts = {
|
|
736
|
+
...contractMap(CONTRACT_GROUPS),
|
|
737
|
+
table: tableContract,
|
|
738
|
+
tr: tableRowContract,
|
|
739
|
+
colgroup: colgroupContract,
|
|
740
|
+
dl: dlContract,
|
|
741
|
+
select: selectContract,
|
|
742
|
+
optgroup: optgroupContract,
|
|
743
|
+
datalist: datalistContract,
|
|
744
|
+
picture: pictureContract,
|
|
745
|
+
figure: figureContract,
|
|
746
|
+
details: detailsContract,
|
|
747
|
+
fieldset: fieldsetContract,
|
|
748
|
+
head: headContract,
|
|
749
|
+
html: htmlContract
|
|
750
|
+
};
|
|
751
|
+
var IMPLICIT_ROLE_RECORD2 = {
|
|
752
|
+
article: "article",
|
|
753
|
+
aside: "complementary",
|
|
754
|
+
footer: "contentinfo",
|
|
755
|
+
header: "banner",
|
|
756
|
+
main: "main",
|
|
757
|
+
nav: "navigation",
|
|
758
|
+
button: "button",
|
|
759
|
+
a: "link",
|
|
760
|
+
select: "listbox",
|
|
761
|
+
h1: "heading",
|
|
762
|
+
h2: "heading",
|
|
763
|
+
h3: "heading",
|
|
764
|
+
h4: "heading",
|
|
765
|
+
h5: "heading",
|
|
766
|
+
h6: "heading",
|
|
767
|
+
ul: "list",
|
|
768
|
+
ol: "list",
|
|
769
|
+
li: "listitem",
|
|
770
|
+
table: "table",
|
|
771
|
+
tr: "row",
|
|
772
|
+
td: "cell",
|
|
773
|
+
th: "columnheader"
|
|
774
|
+
};
|
|
775
|
+
function getImplicitRole(tag) {
|
|
776
|
+
if (tag in IMPLICIT_ROLE_RECORD2) return IMPLICIT_ROLE_RECORD2[tag];
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
var pendingAsyncWarns2 = /* @__PURE__ */ new Set();
|
|
780
|
+
var asyncWarnScheduled2 = false;
|
|
781
|
+
function flushAsyncWarns2() {
|
|
782
|
+
asyncWarnScheduled2 = false;
|
|
783
|
+
const messages = [...pendingAsyncWarns2];
|
|
784
|
+
pendingAsyncWarns2.clear();
|
|
785
|
+
for (const msg of messages) {
|
|
786
|
+
console.warn(msg);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function scheduleAsyncWarn(message) {
|
|
790
|
+
if (pendingAsyncWarns2.has(message)) return;
|
|
791
|
+
pendingAsyncWarns2.add(message);
|
|
792
|
+
if (!asyncWarnScheduled2) {
|
|
793
|
+
asyncWarnScheduled2 = true;
|
|
794
|
+
queueMicrotask(flushAsyncWarns2);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
var StrictBase = class {
|
|
798
|
+
strict;
|
|
799
|
+
constructor(strict) {
|
|
800
|
+
this.strict = strict;
|
|
801
|
+
}
|
|
802
|
+
violate(message) {
|
|
803
|
+
if (this.strict === true || this.strict === "throw") {
|
|
804
|
+
throw new Error(message);
|
|
805
|
+
}
|
|
806
|
+
this.warn(message);
|
|
807
|
+
}
|
|
808
|
+
// Always caps at console.warn — never throws. ARIA 'warning' violations route here
|
|
809
|
+
// so they surface even in strict='throw' mode without aborting a render.
|
|
810
|
+
warn(message) {
|
|
811
|
+
if (!this.strict) return;
|
|
812
|
+
if (this.strict === "async-warn") {
|
|
813
|
+
scheduleAsyncWarn(message);
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
console.warn(message);
|
|
817
|
+
}
|
|
818
|
+
invariant(condition, message) {
|
|
819
|
+
if (!condition) {
|
|
820
|
+
this.violate(message);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
function isNull2(value) {
|
|
825
|
+
return value === null;
|
|
826
|
+
}
|
|
827
|
+
var VALID = [{ valid: true }];
|
|
828
|
+
function isIntrinsicTag(tag) {
|
|
829
|
+
return isString(tag);
|
|
830
|
+
}
|
|
831
|
+
function omitProp(obj, key) {
|
|
832
|
+
const { [key]: _, ...rest } = obj;
|
|
833
|
+
return rest;
|
|
834
|
+
}
|
|
835
|
+
var AriaPolicyEngine = class _AriaPolicyEngine extends StrictBase {
|
|
836
|
+
#extraRules;
|
|
837
|
+
#planCache = /* @__PURE__ */ new Map();
|
|
838
|
+
static #MAX_CACHE = 100;
|
|
839
|
+
// Memoized AriaFix objects keyed by attribute name — the ARIA attribute set is
|
|
840
|
+
// finite so this Map is bounded and avoids recreating closures on every cache miss.
|
|
841
|
+
static #removeAttributeFixCache = /* @__PURE__ */ new Map();
|
|
842
|
+
constructor(strict = "warn", options) {
|
|
843
|
+
super(strict);
|
|
844
|
+
this.#extraRules = options?.rules ?? [];
|
|
845
|
+
}
|
|
846
|
+
static #normalizeEmptyRole(tag, props) {
|
|
847
|
+
if (props.role !== "") return { normalized: false };
|
|
848
|
+
return {
|
|
849
|
+
normalized: true,
|
|
850
|
+
result: {
|
|
851
|
+
props: omitProp(props, "role"),
|
|
852
|
+
violations: [
|
|
853
|
+
{
|
|
854
|
+
message: `<${tag}> has an explicit empty role="". Omit the attribute instead.`,
|
|
855
|
+
tag,
|
|
856
|
+
role: "",
|
|
857
|
+
attribute: void 0,
|
|
858
|
+
severity: "warning",
|
|
859
|
+
phase: "evaluate"
|
|
860
|
+
}
|
|
861
|
+
]
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
static #deriveContext(tag, props) {
|
|
866
|
+
if (!isIntrinsicTag(tag)) return { proceed: false, result: { props, violations: [] } };
|
|
867
|
+
const implicitRole = getImplicitRole(tag);
|
|
868
|
+
const hasExplicitLiveRole = !implicitRole && _AriaPolicyEngine.#LIVE_REGION_ROLES.has(props.role ?? "");
|
|
869
|
+
if (!implicitRole && !hasExplicitLiveRole)
|
|
870
|
+
return { proceed: false, result: { props, violations: [] } };
|
|
871
|
+
const normalized = _AriaPolicyEngine.#normalizeEmptyRole(tag, props);
|
|
872
|
+
if (normalized.normalized) return { proceed: false, result: normalized.result };
|
|
873
|
+
const effectiveRole = props.role ?? implicitRole;
|
|
874
|
+
return {
|
|
875
|
+
proceed: true,
|
|
876
|
+
tag,
|
|
877
|
+
implicitRole,
|
|
878
|
+
effectiveRole,
|
|
879
|
+
context: { tag, props, implicitRole, effectiveRole }
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
static #runRules(rules, context) {
|
|
883
|
+
const violations = [];
|
|
884
|
+
const fixes = [];
|
|
885
|
+
for (const rule of rules) {
|
|
886
|
+
for (const result of rule(context)) {
|
|
887
|
+
if (!result.valid) {
|
|
888
|
+
violations.push({
|
|
889
|
+
message: result.message ?? `Invalid role "${context.props.role}" on <${context.tag}>`,
|
|
890
|
+
tag: context.tag,
|
|
891
|
+
role: context.props.role,
|
|
892
|
+
attribute: result.attribute,
|
|
893
|
+
severity: result.severity,
|
|
894
|
+
phase: "evaluate"
|
|
895
|
+
});
|
|
896
|
+
if (result.fixable) fixes.push(result.fix);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return { violations, fixes };
|
|
901
|
+
}
|
|
902
|
+
static #getRules(context) {
|
|
903
|
+
return _AriaPolicyEngine.#hasRole(context.props) ? _AriaPolicyEngine.#pipeline : [_AriaPolicyEngine.#checkInvalidAriaAttributes];
|
|
904
|
+
}
|
|
905
|
+
static evaluate(tag, props) {
|
|
906
|
+
const derived = _AriaPolicyEngine.#deriveContext(tag, props);
|
|
907
|
+
if (!derived.proceed) return derived.result;
|
|
908
|
+
const { tag: narrowedTag, implicitRole, context } = derived;
|
|
909
|
+
const { violations, fixes } = _AriaPolicyEngine.#runRules(
|
|
910
|
+
_AriaPolicyEngine.#getRules(context),
|
|
911
|
+
context
|
|
912
|
+
);
|
|
913
|
+
const next = _AriaPolicyEngine.#applyFixes(narrowedTag, implicitRole, props, fixes);
|
|
914
|
+
return { props: next, violations };
|
|
915
|
+
}
|
|
916
|
+
static #evaluateWithRules(tag, props, extraRules) {
|
|
917
|
+
const derived = _AriaPolicyEngine.#deriveContext(tag, props);
|
|
918
|
+
if (!derived.proceed) return derived.result;
|
|
919
|
+
const { tag: narrowedTag, implicitRole, context } = derived;
|
|
920
|
+
const { violations, fixes } = _AriaPolicyEngine.#runRules(
|
|
921
|
+
[..._AriaPolicyEngine.#getRules(context), ...extraRules],
|
|
922
|
+
context
|
|
923
|
+
);
|
|
924
|
+
const next = _AriaPolicyEngine.#applyFixes(narrowedTag, implicitRole, props, fixes);
|
|
925
|
+
return { props: next, violations };
|
|
926
|
+
}
|
|
927
|
+
report(violations) {
|
|
928
|
+
for (const v of violations) {
|
|
929
|
+
if (v.severity === "error") this.violate(v.message);
|
|
930
|
+
else this.warn(v.message);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
// Cache key covers only the aria-relevant subset of props (tag + role + aria-* attrs).
|
|
934
|
+
// Non-aria props (className, onClick, etc.) do not affect ARIA decisions and are excluded
|
|
935
|
+
// so cache hits survive re-renders that only change non-aria props.
|
|
936
|
+
// Note: #extraRules are NOT included in the key — each engine instance has its own Map,
|
|
937
|
+
// so two engines with different rules never share cache entries. If caching ever becomes
|
|
938
|
+
// static/shared, rule identity would need to be folded into the key.
|
|
939
|
+
static #createPlanKey(tag, props) {
|
|
940
|
+
if (!isIntrinsicTag(tag)) return null;
|
|
941
|
+
const parts = [tag];
|
|
942
|
+
if (typeof props.role === "string") parts.push(`role:${props.role}`);
|
|
943
|
+
const ariaEntries = [];
|
|
944
|
+
for (const k in props) {
|
|
945
|
+
if (!Object.hasOwn(props, k) || !k.startsWith("aria-")) continue;
|
|
946
|
+
const v = props[k];
|
|
947
|
+
if (!isString(v) && !isNumber(v) && typeof v !== "boolean") continue;
|
|
948
|
+
ariaEntries.push(`${k}:${String(v)}`);
|
|
949
|
+
}
|
|
950
|
+
if (ariaEntries.length > 0) parts.push(...ariaEntries.sort());
|
|
951
|
+
return parts.join("|");
|
|
952
|
+
}
|
|
953
|
+
static #computePlan(inputProps, resultProps) {
|
|
954
|
+
const removals = /* @__PURE__ */ new Set();
|
|
955
|
+
const updates = {};
|
|
956
|
+
for (const key in inputProps) {
|
|
957
|
+
if (Object.hasOwn(inputProps, key) && !(key in resultProps)) removals.add(key);
|
|
958
|
+
}
|
|
959
|
+
for (const key in resultProps) {
|
|
960
|
+
if (!Object.hasOwn(resultProps, key)) continue;
|
|
961
|
+
const resultVal = resultProps[key];
|
|
962
|
+
if (inputProps[key] !== resultVal) updates[key] = resultVal;
|
|
963
|
+
}
|
|
964
|
+
return { removals, updates };
|
|
965
|
+
}
|
|
966
|
+
static #applyPlan(props, removals, updates) {
|
|
967
|
+
const hasRemovals = removals.size > 0;
|
|
968
|
+
const hasUpdates = Object.keys(updates).length > 0;
|
|
969
|
+
if (!hasRemovals && !hasUpdates) return props;
|
|
970
|
+
const next = {};
|
|
971
|
+
for (const k in props) {
|
|
972
|
+
if (Object.hasOwn(props, k) && !removals.has(k)) next[k] = props[k];
|
|
973
|
+
}
|
|
974
|
+
Object.assign(next, updates);
|
|
975
|
+
return next;
|
|
976
|
+
}
|
|
977
|
+
validate(tag, props) {
|
|
978
|
+
const key = _AriaPolicyEngine.#createPlanKey(tag, props);
|
|
979
|
+
if (!isNull2(key)) {
|
|
980
|
+
const cached = this.#planCache.get(key);
|
|
981
|
+
if (cached !== void 0) {
|
|
982
|
+
this.#planCache.delete(key);
|
|
983
|
+
this.#planCache.set(key, cached);
|
|
984
|
+
if (cached.violations.length > 0) this.report(cached.violations);
|
|
985
|
+
return {
|
|
986
|
+
props: _AriaPolicyEngine.#applyPlan(props, cached.removals, cached.updates),
|
|
987
|
+
violations: cached.violations
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const result = this.#extraRules.length ? _AriaPolicyEngine.#evaluateWithRules(tag, props, this.#extraRules) : _AriaPolicyEngine.evaluate(tag, props);
|
|
992
|
+
if (result.violations.length > 0) this.report(result.violations);
|
|
993
|
+
if (!isNull2(key)) {
|
|
994
|
+
const { removals, updates } = _AriaPolicyEngine.#computePlan(
|
|
995
|
+
props,
|
|
996
|
+
result.props
|
|
997
|
+
);
|
|
998
|
+
const plan = { removals, updates, violations: result.violations };
|
|
999
|
+
this.#planCache.set(key, plan);
|
|
1000
|
+
if (this.#planCache.size > _AriaPolicyEngine.#MAX_CACHE) {
|
|
1001
|
+
const lru = this.#planCache.keys().next().value;
|
|
1002
|
+
if (lru !== void 0) this.#planCache.delete(lru);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return result;
|
|
1006
|
+
}
|
|
1007
|
+
static #hasRole(props) {
|
|
1008
|
+
return isString(props.role) && props.role.length > 0;
|
|
1009
|
+
}
|
|
1010
|
+
static #applyFixes(tag, implicitRole, props, fixes) {
|
|
1011
|
+
if (fixes.length === 0) return props;
|
|
1012
|
+
const sorted = [...fixes].sort((a, b) => (a.priority ?? Infinity) - (b.priority ?? Infinity));
|
|
1013
|
+
let next = props;
|
|
1014
|
+
for (const { apply } of sorted) {
|
|
1015
|
+
const effectiveRole = next.role ?? implicitRole;
|
|
1016
|
+
const fixContext = { tag, implicitRole, effectiveRole, props: next };
|
|
1017
|
+
const fixResult = apply(fixContext);
|
|
1018
|
+
if (fixResult.applied) next = fixResult.next;
|
|
1019
|
+
}
|
|
1020
|
+
return next;
|
|
1021
|
+
}
|
|
1022
|
+
static #removeRole = {
|
|
1023
|
+
kind: "removeRole",
|
|
1024
|
+
apply: ({ props }) => {
|
|
1025
|
+
if (!("role" in props)) return { applied: false, next: props };
|
|
1026
|
+
return { applied: true, next: omitProp(props, "role"), previous: props };
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
static #makeRemoveAttributeFix(attr) {
|
|
1030
|
+
const cached = _AriaPolicyEngine.#removeAttributeFixCache.get(attr);
|
|
1031
|
+
if (cached) return cached;
|
|
1032
|
+
const fix = {
|
|
1033
|
+
kind: `removeAttribute:${attr}`,
|
|
1034
|
+
apply: ({ props }) => {
|
|
1035
|
+
if (!(attr in props)) return { applied: false, next: props };
|
|
1036
|
+
return { applied: true, next: omitProp(props, attr), previous: props };
|
|
1037
|
+
}
|
|
1038
|
+
};
|
|
1039
|
+
_AriaPolicyEngine.#removeAttributeFixCache.set(attr, fix);
|
|
1040
|
+
return fix;
|
|
1041
|
+
}
|
|
1042
|
+
// Snapshot diagnostic model: all rules evaluate against the same (tag, props, implicitRole) snapshot.
|
|
1043
|
+
static #pipeline = [
|
|
1044
|
+
_AriaPolicyEngine.#checkInvalidRoleOverride,
|
|
1045
|
+
_AriaPolicyEngine.#checkRedundantRole,
|
|
1046
|
+
_AriaPolicyEngine.#checkStandaloneRegion,
|
|
1047
|
+
_AriaPolicyEngine.#checkInvalidAriaAttributes,
|
|
1048
|
+
_AriaPolicyEngine.#checkMissingLiveRegion,
|
|
1049
|
+
_AriaPolicyEngine.#checkMissingAtomic,
|
|
1050
|
+
_AriaPolicyEngine.#checkInvalidAriaRelevant
|
|
1051
|
+
];
|
|
1052
|
+
static #checkInvalidRoleOverride({
|
|
1053
|
+
tag,
|
|
1054
|
+
props,
|
|
1055
|
+
implicitRole
|
|
1056
|
+
}) {
|
|
1057
|
+
const role = props.role;
|
|
1058
|
+
if (!implicitRole || !role || role === implicitRole) return VALID;
|
|
1059
|
+
if (isStrongImplicitRole(tag) && role === "region") {
|
|
1060
|
+
return [
|
|
1061
|
+
{
|
|
1062
|
+
valid: false,
|
|
1063
|
+
fixable: true,
|
|
1064
|
+
severity: "error",
|
|
1065
|
+
fix: _AriaPolicyEngine.#removeRole,
|
|
1066
|
+
message: `<${tag}> should not override its implicit role="${implicitRole}" with role="${role}".`
|
|
1067
|
+
}
|
|
1068
|
+
];
|
|
1069
|
+
}
|
|
1070
|
+
return VALID;
|
|
1071
|
+
}
|
|
1072
|
+
static #checkRedundantRole({ tag, props, implicitRole }) {
|
|
1073
|
+
const role = props.role;
|
|
1074
|
+
if (!implicitRole || !role || role !== implicitRole) return VALID;
|
|
1075
|
+
return [
|
|
1076
|
+
{
|
|
1077
|
+
valid: false,
|
|
1078
|
+
fixable: true,
|
|
1079
|
+
severity: "warning",
|
|
1080
|
+
fix: _AriaPolicyEngine.#removeRole,
|
|
1081
|
+
message: `<${tag}> already has implicit role="${implicitRole}". Avoid redundant role assignment.`
|
|
1082
|
+
}
|
|
1083
|
+
];
|
|
1084
|
+
}
|
|
1085
|
+
static #checkStandaloneRegion({ tag, props, implicitRole }) {
|
|
1086
|
+
const role = props.role;
|
|
1087
|
+
if (role !== "region") return VALID;
|
|
1088
|
+
if (!isStandaloneTag(tag)) return VALID;
|
|
1089
|
+
return [
|
|
1090
|
+
{
|
|
1091
|
+
valid: false,
|
|
1092
|
+
fixable: true,
|
|
1093
|
+
severity: "error",
|
|
1094
|
+
fix: _AriaPolicyEngine.#removeRole,
|
|
1095
|
+
message: `<${tag}> is a self-contained element with implicit role="${implicitRole}". Assigning role="region" has been removed.`
|
|
1096
|
+
}
|
|
1097
|
+
];
|
|
1098
|
+
}
|
|
1099
|
+
static #checkInvalidAriaAttributes({
|
|
1100
|
+
tag,
|
|
1101
|
+
props,
|
|
1102
|
+
effectiveRole
|
|
1103
|
+
}) {
|
|
1104
|
+
const results = [];
|
|
1105
|
+
for (const key in props) {
|
|
1106
|
+
if (!Object.hasOwn(props, key)) continue;
|
|
1107
|
+
if (!key.startsWith("aria-")) continue;
|
|
1108
|
+
if (isGlobalAriaAttribute(key)) continue;
|
|
1109
|
+
if (isAriaAttributeValidForRole(key, effectiveRole)) continue;
|
|
1110
|
+
results.push({
|
|
1111
|
+
valid: false,
|
|
1112
|
+
severity: "warning",
|
|
1113
|
+
fixable: true,
|
|
1114
|
+
attribute: key,
|
|
1115
|
+
message: `"${key}" is not valid on role="${effectiveRole ?? tag}". It will be removed.`,
|
|
1116
|
+
fix: _AriaPolicyEngine.#makeRemoveAttributeFix(key)
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
return results;
|
|
1120
|
+
}
|
|
1121
|
+
// WAI-ARIA live region roles and their implied aria-live politeness values.
|
|
1122
|
+
static #LIVE_REGION_ROLES = /* @__PURE__ */ new Map([
|
|
1123
|
+
["alert", "assertive"],
|
|
1124
|
+
["status", "polite"],
|
|
1125
|
+
["log", "polite"],
|
|
1126
|
+
["timer", "off"]
|
|
1127
|
+
]);
|
|
1128
|
+
static #checkMissingLiveRegion({ effectiveRole, props }) {
|
|
1129
|
+
if (!effectiveRole) return VALID;
|
|
1130
|
+
const impliedLive = _AriaPolicyEngine.#LIVE_REGION_ROLES.get(effectiveRole);
|
|
1131
|
+
if (!impliedLive) return VALID;
|
|
1132
|
+
if ("aria-live" in props) return VALID;
|
|
1133
|
+
const injectLive = {
|
|
1134
|
+
kind: `injectLive:${effectiveRole}`,
|
|
1135
|
+
apply: (ctx) => ({
|
|
1136
|
+
applied: true,
|
|
1137
|
+
next: { ...ctx.props, "aria-live": impliedLive },
|
|
1138
|
+
previous: ctx.props
|
|
1139
|
+
})
|
|
1140
|
+
};
|
|
1141
|
+
return [
|
|
1142
|
+
{
|
|
1143
|
+
valid: false,
|
|
1144
|
+
fixable: true,
|
|
1145
|
+
severity: "warning",
|
|
1146
|
+
fix: injectLive,
|
|
1147
|
+
message: `role="${effectiveRole}" implies aria-live="${impliedLive}" but it is missing. It has been injected.`
|
|
1148
|
+
}
|
|
1149
|
+
];
|
|
1150
|
+
}
|
|
1151
|
+
static #checkMissingAtomic({ effectiveRole, props }) {
|
|
1152
|
+
if (!effectiveRole || !_AriaPolicyEngine.#LIVE_REGION_ROLES.has(effectiveRole)) return VALID;
|
|
1153
|
+
if ("aria-atomic" in props) return VALID;
|
|
1154
|
+
return [
|
|
1155
|
+
{
|
|
1156
|
+
valid: false,
|
|
1157
|
+
fixable: false,
|
|
1158
|
+
severity: "warning",
|
|
1159
|
+
message: `role="${effectiveRole}" is a live region. Consider setting aria-atomic="true" if the full region should be announced as a unit, or aria-atomic="false" if only changed nodes should be read.`
|
|
1160
|
+
}
|
|
1161
|
+
];
|
|
1162
|
+
}
|
|
1163
|
+
static #VALID_RELEVANT_TOKENS = /* @__PURE__ */ new Set(["additions", "removals", "text", "all"]);
|
|
1164
|
+
// Custom fix rules passed via `options.rules` must be pure functions of (tag, props) — the cache
|
|
1165
|
+
// replays stored fixes against new prop objects, so fixes that close over external state will
|
|
1166
|
+
// produce inconsistent results on cache hits.
|
|
1167
|
+
static #normalizeRelevantAllFix = {
|
|
1168
|
+
kind: "normalizeRelevantAll",
|
|
1169
|
+
apply: ({ props: p }) => ({
|
|
1170
|
+
applied: true,
|
|
1171
|
+
next: { ...p, "aria-relevant": "all" },
|
|
1172
|
+
previous: p
|
|
1173
|
+
})
|
|
1174
|
+
};
|
|
1175
|
+
static #checkInvalidAriaRelevant({ props }) {
|
|
1176
|
+
const relevant = props["aria-relevant"];
|
|
1177
|
+
if (relevant === void 0) return VALID;
|
|
1178
|
+
if (typeof relevant !== "string") return VALID;
|
|
1179
|
+
const tokens = relevant.trim().split(/\s+/);
|
|
1180
|
+
const invalid = tokens.filter((t) => !_AriaPolicyEngine.#VALID_RELEVANT_TOKENS.has(t));
|
|
1181
|
+
if (invalid.length > 0) {
|
|
1182
|
+
return [
|
|
1183
|
+
{
|
|
1184
|
+
valid: false,
|
|
1185
|
+
fixable: true,
|
|
1186
|
+
severity: "warning",
|
|
1187
|
+
attribute: "aria-relevant",
|
|
1188
|
+
message: `aria-relevant contains invalid token(s): ${invalid.map((t) => `"${t}"`).join(", ")}. Valid tokens are: additions, removals, text, all.`,
|
|
1189
|
+
fix: _AriaPolicyEngine.#makeRemoveAttributeFix("aria-relevant")
|
|
1190
|
+
}
|
|
1191
|
+
];
|
|
1192
|
+
}
|
|
1193
|
+
if (tokens.includes("all") && tokens.length > 1) {
|
|
1194
|
+
return [
|
|
1195
|
+
{
|
|
1196
|
+
valid: false,
|
|
1197
|
+
fixable: true,
|
|
1198
|
+
severity: "warning",
|
|
1199
|
+
attribute: "aria-relevant",
|
|
1200
|
+
message: `aria-relevant includes "all" alongside other tokens. "all" supersedes additions, removals, and text \u2014 use aria-relevant="all" alone.`,
|
|
1201
|
+
fix: _AriaPolicyEngine.#normalizeRelevantAllFix
|
|
1202
|
+
}
|
|
1203
|
+
];
|
|
1204
|
+
}
|
|
1205
|
+
return VALID;
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
function getTypeName(value) {
|
|
1209
|
+
if (value === null) return "null";
|
|
1210
|
+
if (value === void 0) return "undefined";
|
|
1211
|
+
const primitive = typeof value;
|
|
1212
|
+
if (primitive !== "object") {
|
|
1213
|
+
return primitive;
|
|
1214
|
+
}
|
|
1215
|
+
const name = value.constructor?.name;
|
|
1216
|
+
return typeof name === "string" && name !== "Object" ? name : "object";
|
|
1217
|
+
}
|
|
1218
|
+
var MatchValidationErrorBuilder = class {
|
|
1219
|
+
#prefix;
|
|
1220
|
+
constructor(ctx = "") {
|
|
1221
|
+
this.#prefix = ctx ? `${ctx}:
|
|
1222
|
+
` : "";
|
|
1223
|
+
}
|
|
1224
|
+
#template(typeName, index, prefix = "", suffix = "") {
|
|
1225
|
+
const leadingStr = prefix ? `${prefix} ` : "";
|
|
1226
|
+
const followingStr = suffix ? ` ${suffix}` : "";
|
|
1227
|
+
return `${leadingStr}child "${typeName}" at index ${index}${followingStr}.`;
|
|
1228
|
+
}
|
|
1229
|
+
unexpectedChild(typeName, index) {
|
|
1230
|
+
return this.#template(typeName, index, "unexpected");
|
|
1231
|
+
}
|
|
1232
|
+
multipleMatches(typeName, index, ruleNames) {
|
|
1233
|
+
const quoted = ruleNames.map((n) => `"${n}"`);
|
|
1234
|
+
return this.#template(
|
|
1235
|
+
typeName,
|
|
1236
|
+
index,
|
|
1237
|
+
"",
|
|
1238
|
+
`matches multiple child rules: ${quoted.join(" and ")}`
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
#format(errors) {
|
|
1242
|
+
return this.#prefix + errors.join("\n");
|
|
1243
|
+
}
|
|
1244
|
+
toError(errors) {
|
|
1245
|
+
if (errors.length === 0) {
|
|
1246
|
+
return new Error(this.#prefix + "Unknown validation error.");
|
|
1247
|
+
}
|
|
1248
|
+
return new Error(this.#format(errors));
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
function normalizeCardinality(input, impliesSingleton) {
|
|
1252
|
+
const min = input?.min ?? 0;
|
|
1253
|
+
const max = input?.max ?? (impliesSingleton ? 1 : Infinity);
|
|
1254
|
+
if (min === 0 && max === Infinity) {
|
|
1255
|
+
return { kind: "unbounded" };
|
|
1256
|
+
}
|
|
1257
|
+
if (min > max) {
|
|
1258
|
+
throw new RangeError(`normalizeChildRule: min (${min}) cannot exceed max (${max})`);
|
|
1259
|
+
}
|
|
1260
|
+
return {
|
|
1261
|
+
kind: "bounded",
|
|
1262
|
+
min,
|
|
1263
|
+
max
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
function normalizeChildRule(rule) {
|
|
1267
|
+
const position = rule.position ?? "any";
|
|
1268
|
+
const impliesSingleton = position === "first" || position === "last";
|
|
1269
|
+
return {
|
|
1270
|
+
...rule,
|
|
1271
|
+
position,
|
|
1272
|
+
cardinality: normalizeCardinality(rule.cardinality, impliesSingleton)
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
function getChildType(child) {
|
|
1276
|
+
if (!isObject(child) || !("type" in child)) return void 0;
|
|
1277
|
+
return child.type;
|
|
1278
|
+
}
|
|
1279
|
+
function buildPartialIndex(rules) {
|
|
1280
|
+
const typeIndex = /* @__PURE__ */ new Map();
|
|
1281
|
+
const duplicateTypes = /* @__PURE__ */ new Set();
|
|
1282
|
+
const untypedIndices = [];
|
|
1283
|
+
for (let ri = 0; ri < rules.length; ri++) {
|
|
1284
|
+
const t = rules[ri].type;
|
|
1285
|
+
if (t === void 0) {
|
|
1286
|
+
untypedIndices.push(ri);
|
|
1287
|
+
} else if (typeIndex.has(t)) {
|
|
1288
|
+
duplicateTypes.add(t);
|
|
1289
|
+
} else {
|
|
1290
|
+
typeIndex.set(t, ri);
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
if (duplicateTypes.size > 0) {
|
|
1294
|
+
for (const t of duplicateTypes) typeIndex.delete(t);
|
|
1295
|
+
for (let ri = 0; ri < rules.length; ri++) {
|
|
1296
|
+
if (duplicateTypes.has(rules[ri].type)) untypedIndices.push(ri);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return { typeIndex, untypedIndices };
|
|
1300
|
+
}
|
|
1301
|
+
var RuleMatcher = class {
|
|
1302
|
+
#rules;
|
|
1303
|
+
#typeIndex;
|
|
1304
|
+
#untypedIndices;
|
|
1305
|
+
constructor(rules) {
|
|
1306
|
+
this.#rules = rules;
|
|
1307
|
+
const { typeIndex, untypedIndices } = buildPartialIndex(rules);
|
|
1308
|
+
this.#typeIndex = typeIndex;
|
|
1309
|
+
this.#untypedIndices = untypedIndices;
|
|
1310
|
+
}
|
|
1311
|
+
match(children) {
|
|
1312
|
+
const forward = /* @__PURE__ */ new Map();
|
|
1313
|
+
const reverse = /* @__PURE__ */ new Map();
|
|
1314
|
+
const unexpectedIndices = /* @__PURE__ */ new Set();
|
|
1315
|
+
const ambiguousIndices = /* @__PURE__ */ new Set();
|
|
1316
|
+
for (let ri = 0; ri < this.#rules.length; ri++) {
|
|
1317
|
+
reverse.set(ri, /* @__PURE__ */ new Set());
|
|
1318
|
+
}
|
|
1319
|
+
for (const [ci, child] of children.entries()) {
|
|
1320
|
+
const t = getChildType(child);
|
|
1321
|
+
if (t !== void 0) {
|
|
1322
|
+
const ri = this.#typeIndex.get(t);
|
|
1323
|
+
if (ri !== void 0) {
|
|
1324
|
+
let childEntry = forward.get(ci);
|
|
1325
|
+
if (!childEntry) {
|
|
1326
|
+
childEntry = /* @__PURE__ */ new Set();
|
|
1327
|
+
forward.set(ci, childEntry);
|
|
1328
|
+
}
|
|
1329
|
+
childEntry.add(ri);
|
|
1330
|
+
reverse.get(ri).add(ci);
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
for (const ri of this.#untypedIndices) {
|
|
1334
|
+
if (!this.#rules[ri].match(child)) continue;
|
|
1335
|
+
let childEntry = forward.get(ci);
|
|
1336
|
+
if (!childEntry) {
|
|
1337
|
+
childEntry = /* @__PURE__ */ new Set();
|
|
1338
|
+
forward.set(ci, childEntry);
|
|
1339
|
+
}
|
|
1340
|
+
childEntry.add(ri);
|
|
1341
|
+
reverse.get(ri).add(ci);
|
|
1342
|
+
}
|
|
1343
|
+
const entry = forward.get(ci);
|
|
1344
|
+
if (!entry) {
|
|
1345
|
+
unexpectedIndices.add(ci);
|
|
1346
|
+
} else if (entry.size > 1) {
|
|
1347
|
+
ambiguousIndices.add(ci);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
return { matrix: { childToRules: { forward, reverse } }, unexpectedIndices, ambiguousIndices };
|
|
1351
|
+
}
|
|
1352
|
+
};
|
|
1353
|
+
var RuleValidator = class _RuleValidator extends StrictBase {
|
|
1354
|
+
#context;
|
|
1355
|
+
constructor(context, strict) {
|
|
1356
|
+
super(strict);
|
|
1357
|
+
this.#context = context;
|
|
1358
|
+
}
|
|
1359
|
+
validate(rules, matrix, childCount) {
|
|
1360
|
+
const firstIndex = 0;
|
|
1361
|
+
const lastIndex = childCount - 1;
|
|
1362
|
+
for (const [ri, rule] of rules.entries()) {
|
|
1363
|
+
const matches = matrix.childToRules.reverse.get(ri);
|
|
1364
|
+
const matchCount = matches.size;
|
|
1365
|
+
this.#validateCardinality(rule, matchCount);
|
|
1366
|
+
if (matchCount === 0) continue;
|
|
1367
|
+
this.#validatePositions(rule, matches, firstIndex, lastIndex);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
#validateCardinality(rule, matchCount) {
|
|
1371
|
+
const { cardinality, name } = rule;
|
|
1372
|
+
if (cardinality.kind !== "bounded") {
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
const { min, max } = cardinality;
|
|
1376
|
+
if (matchCount < min) {
|
|
1377
|
+
this.violate(`${this.#context}: "${name}" requires at least ${min}.`);
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
if (matchCount > max) {
|
|
1381
|
+
this.violate(`${this.#context}: "${name}" allows at most ${max}.`);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
#validatePositions(rule, matches, firstIndex, lastIndex) {
|
|
1385
|
+
const { name, position } = rule;
|
|
1386
|
+
for (const index of matches) {
|
|
1387
|
+
if (_RuleValidator.#isValidPosition(index, position, firstIndex, lastIndex)) {
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1390
|
+
this.violate(`${this.#context}: "${name}" must be ${position}, got index ${index}`);
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
static #isValidPosition(matchIndex, position, firstIndex, lastIndex) {
|
|
1394
|
+
switch (position) {
|
|
1395
|
+
case "first":
|
|
1396
|
+
return matchIndex === firstIndex;
|
|
1397
|
+
case "last":
|
|
1398
|
+
return matchIndex === lastIndex;
|
|
1399
|
+
case "any":
|
|
1400
|
+
return true;
|
|
1401
|
+
default:
|
|
1402
|
+
return assertNever(position);
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
var ChildrenEvaluator = class extends StrictBase {
|
|
1407
|
+
#rules;
|
|
1408
|
+
#ruleNames;
|
|
1409
|
+
#matcher;
|
|
1410
|
+
#ruleValidator;
|
|
1411
|
+
#matchBuilder;
|
|
1412
|
+
constructor(rules, strict = "warn", context = "Component") {
|
|
1413
|
+
super(strict);
|
|
1414
|
+
this.#rules = rules.map((r2) => normalizeChildRule(r2));
|
|
1415
|
+
this.#ruleNames = this.#rules.map((r2) => r2.name);
|
|
1416
|
+
for (const rule of this.#rules) {
|
|
1417
|
+
const { name, position, cardinality } = rule;
|
|
1418
|
+
if ((position === "first" || position === "last") && (cardinality.kind === "unbounded" || cardinality.max > 1)) {
|
|
1419
|
+
throw new RangeError(
|
|
1420
|
+
`ChildrenEvaluator [${context}]: rule "${name}" sets position="${position}" with an unbound or >1 max. position="first|last" implies max=1.`
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
this.#matcher = new RuleMatcher(this.#rules);
|
|
1425
|
+
this.#ruleValidator = new RuleValidator(context, strict);
|
|
1426
|
+
this.#matchBuilder = new MatchValidationErrorBuilder(context);
|
|
1427
|
+
}
|
|
1428
|
+
evaluate(children) {
|
|
1429
|
+
if (!this.strict) return;
|
|
1430
|
+
const { matrix, unexpectedIndices, ambiguousIndices } = this.#matcher.match(children);
|
|
1431
|
+
this.#ruleValidator.validate(this.#rules, matrix, children.length);
|
|
1432
|
+
if (unexpectedIndices.size === 0 && ambiguousIndices.size === 0) return;
|
|
1433
|
+
const errors = [];
|
|
1434
|
+
const violating = [...unexpectedIndices, ...ambiguousIndices].sort((a, b) => a - b);
|
|
1435
|
+
for (const ci of violating) {
|
|
1436
|
+
const typeName = getTypeName(children[ci]);
|
|
1437
|
+
if (unexpectedIndices.has(ci)) {
|
|
1438
|
+
errors.push(this.#matchBuilder.unexpectedChild(typeName, ci));
|
|
1439
|
+
} else {
|
|
1440
|
+
const matches = matrix.childToRules.forward.get(ci);
|
|
1441
|
+
const names = [...matches].map((ri) => this.#ruleNames[ri] ?? `#${ri}`);
|
|
1442
|
+
errors.push(this.#matchBuilder.multipleMatches(typeName, ci, names));
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
this.invariant(errors.length === 0, this.#matchBuilder.toError(errors).message);
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
// ../core/dist/chunk-RHOMAG5Q.js
|
|
1450
|
+
var falsyToString = (value) => typeof value === "boolean" ? `${value}` : value === 0 ? "0" : value;
|
|
1451
|
+
var cx = clsx;
|
|
1452
|
+
var cva = (base, config) => (props) => {
|
|
1453
|
+
var _config_compoundVariants;
|
|
1454
|
+
if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
1455
|
+
const { variants, defaultVariants } = config;
|
|
1456
|
+
const getVariantClassNames = Object.keys(variants).map((variant) => {
|
|
1457
|
+
const variantProp = props === null || props === void 0 ? void 0 : props[variant];
|
|
1458
|
+
const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
|
|
1459
|
+
if (variantProp === null) return null;
|
|
1460
|
+
const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
|
|
1461
|
+
return variants[variant][variantKey];
|
|
1462
|
+
});
|
|
1463
|
+
const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
|
|
1464
|
+
let [key, value] = param;
|
|
1465
|
+
if (value === void 0) {
|
|
1466
|
+
return acc;
|
|
1467
|
+
}
|
|
1468
|
+
acc[key] = value;
|
|
1469
|
+
return acc;
|
|
1470
|
+
}, {});
|
|
1471
|
+
const getCompoundVariantClassNames = config === null || config === void 0 ? void 0 : (_config_compoundVariants = config.compoundVariants) === null || _config_compoundVariants === void 0 ? void 0 : _config_compoundVariants.reduce((acc, param) => {
|
|
1472
|
+
let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param;
|
|
1473
|
+
return Object.entries(compoundVariantOptions).every((param2) => {
|
|
1474
|
+
let [key, value] = param2;
|
|
1475
|
+
return Array.isArray(value) ? value.includes({
|
|
1476
|
+
...defaultVariants,
|
|
1477
|
+
...propsWithoutUndefined
|
|
1478
|
+
}[key]) : {
|
|
1479
|
+
...defaultVariants,
|
|
1480
|
+
...propsWithoutUndefined
|
|
1481
|
+
}[key] === value;
|
|
1482
|
+
}) ? [
|
|
1483
|
+
...acc,
|
|
1484
|
+
cvClass,
|
|
1485
|
+
cvClassName
|
|
1486
|
+
] : acc;
|
|
1487
|
+
}, []);
|
|
1488
|
+
return cx(base, getVariantClassNames, getCompoundVariantClassNames, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
|
|
1489
|
+
};
|
|
1490
|
+
function cva2(base, config) {
|
|
1491
|
+
const fn = cva(base, config);
|
|
1492
|
+
return (props) => cn(fn(props));
|
|
1493
|
+
}
|
|
1494
|
+
var StaticClassResolver = class {
|
|
1495
|
+
#baseClass;
|
|
1496
|
+
#cache = /* @__PURE__ */ new Map();
|
|
1497
|
+
#resolveTag;
|
|
1498
|
+
constructor(baseClass, tagMap) {
|
|
1499
|
+
this.#baseClass = Array.isArray(baseClass) ? baseClass.join(" ") : baseClass;
|
|
1500
|
+
this.#resolveTag = tagMap ? (tag) => {
|
|
1501
|
+
const extra = tagMap[tag];
|
|
1502
|
+
if (!extra) return this.#baseClass;
|
|
1503
|
+
const extraStr = Array.isArray(extra) ? extra.join(" ") : extra;
|
|
1504
|
+
return `${this.#baseClass} ${extraStr}`;
|
|
1505
|
+
} : () => this.#baseClass;
|
|
1506
|
+
}
|
|
1507
|
+
resolve(tag, skipTagMap = false) {
|
|
1508
|
+
if (typeof tag !== "string" || skipTagMap) return this.#baseClass;
|
|
1509
|
+
const cached = this.#cache.get(tag);
|
|
1510
|
+
if (cached !== void 0) {
|
|
1511
|
+
this.#cache.delete(tag);
|
|
1512
|
+
this.#cache.set(tag, cached);
|
|
1513
|
+
return cached;
|
|
1514
|
+
}
|
|
1515
|
+
const result = this.#resolveTag(tag);
|
|
1516
|
+
this.#cache.set(tag, result);
|
|
1517
|
+
if (this.#cache.size > 200) {
|
|
1518
|
+
const lru = this.#cache.keys().next().value;
|
|
1519
|
+
if (lru !== void 0) this.#cache.delete(lru);
|
|
1520
|
+
}
|
|
1521
|
+
return result;
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
var VariantClassResolver = class _VariantClassResolver {
|
|
1525
|
+
#cvaFn;
|
|
1526
|
+
#presetMap;
|
|
1527
|
+
#variantKeys;
|
|
1528
|
+
#precomputedClasses;
|
|
1529
|
+
#cache = /* @__PURE__ */ new Map();
|
|
1530
|
+
constructor(cvaFn, presetMap, variantKeys, precomputedClasses) {
|
|
1531
|
+
this.#cvaFn = cvaFn ?? null;
|
|
1532
|
+
this.#presetMap = Object.freeze(presetMap ?? {});
|
|
1533
|
+
this.#variantKeys = variantKeys ?? null;
|
|
1534
|
+
this.#precomputedClasses = precomputedClasses ?? null;
|
|
1535
|
+
}
|
|
1536
|
+
resolve({ props, variantKey }) {
|
|
1537
|
+
const normalizedKey = variantKey ?? "__none__";
|
|
1538
|
+
const cacheKey = this.#createCacheKey(props, normalizedKey);
|
|
1539
|
+
if (this.#precomputedClasses !== null) {
|
|
1540
|
+
const precomputed = this.#precomputedClasses[cacheKey];
|
|
1541
|
+
if (precomputed !== void 0) return precomputed;
|
|
1542
|
+
}
|
|
1543
|
+
const cached = this.#cache.get(cacheKey);
|
|
1544
|
+
if (cached !== void 0) {
|
|
1545
|
+
this.#cache.delete(cacheKey);
|
|
1546
|
+
this.#cache.set(cacheKey, cached);
|
|
1547
|
+
return cached;
|
|
1548
|
+
}
|
|
1549
|
+
const result = this.#compute(props, variantKey);
|
|
1550
|
+
this.#cache.set(cacheKey, result);
|
|
1551
|
+
if (this.#cache.size > 1e3) {
|
|
1552
|
+
const lru = this.#cache.keys().next().value;
|
|
1553
|
+
if (lru !== void 0) this.#cache.delete(lru);
|
|
1554
|
+
}
|
|
1555
|
+
return result;
|
|
1556
|
+
}
|
|
1557
|
+
#compute(props, variantKey) {
|
|
1558
|
+
if (!this.#cvaFn) return "";
|
|
1559
|
+
if (!variantKey) return this.#cvaFn(props);
|
|
1560
|
+
const preset = this.#presetMap[variantKey];
|
|
1561
|
+
if (!preset) return this.#cvaFn(props);
|
|
1562
|
+
return this.#cvaFn({ ...preset, ...props });
|
|
1563
|
+
}
|
|
1564
|
+
// When variantKeys is provided, only those keys are included in the cache key — non-variant
|
|
1565
|
+
// props (className, id, etc.) produce identical CVA output and must not fragment the cache.
|
|
1566
|
+
// Iterating #variantKeys directly (fixed Set insertion order) avoids Object.keys + filter + sort.
|
|
1567
|
+
// String is built incrementally to avoid a parts[] array allocation on every render.
|
|
1568
|
+
#createCacheKey(props, variantKey) {
|
|
1569
|
+
if (this.#variantKeys !== null) {
|
|
1570
|
+
let key2 = variantKey;
|
|
1571
|
+
for (const k of this.#variantKeys) {
|
|
1572
|
+
if (k in props) key2 += `|${k}:${_VariantClassResolver.#serializeValue(props[k])}`;
|
|
1573
|
+
}
|
|
1574
|
+
return key2;
|
|
1575
|
+
}
|
|
1576
|
+
let key = variantKey;
|
|
1577
|
+
for (const k of Object.keys(props).sort()) {
|
|
1578
|
+
key += `|${k}:${_VariantClassResolver.#serializeValue(props[k])}`;
|
|
1579
|
+
}
|
|
1580
|
+
return key;
|
|
1581
|
+
}
|
|
1582
|
+
static #serializeValue(value) {
|
|
1583
|
+
if (value === void 0) return "u";
|
|
1584
|
+
if (value === null) return "n";
|
|
1585
|
+
if (typeof value === "boolean") return `b:${value}`;
|
|
1586
|
+
if (typeof value === "string") return `s:${value}`;
|
|
1587
|
+
return `x:${String(value)}`;
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
function createClassPipeline(resolved) {
|
|
1591
|
+
const baseClass = resolved.baseClassName ?? "";
|
|
1592
|
+
const cvaFn = resolved.variants ? cva2("", {
|
|
1593
|
+
variants: resolved.variants,
|
|
1594
|
+
defaultVariants: resolved.defaultVariants,
|
|
1595
|
+
compoundVariants: resolved.compoundVariants
|
|
1596
|
+
}) : null;
|
|
1597
|
+
const variantKeys = resolved.variants ? new Set(Object.keys(resolved.variants)) : void 0;
|
|
1598
|
+
const staticResolver = new StaticClassResolver(baseClass, resolved.tagMap);
|
|
1599
|
+
const variantResolver = new VariantClassResolver(
|
|
1600
|
+
cvaFn,
|
|
1601
|
+
resolved.presetMap,
|
|
1602
|
+
variantKeys,
|
|
1603
|
+
resolved.precomputedClasses
|
|
1604
|
+
);
|
|
1605
|
+
return function resolveClasses(tag, props, className, variantKey) {
|
|
1606
|
+
const staticClasses = staticResolver.resolve(tag, variantKey !== void 0);
|
|
1607
|
+
const variantClasses = variantResolver.resolve({ props, variantKey });
|
|
1608
|
+
if (!className)
|
|
1609
|
+
return staticClasses && variantClasses ? `${staticClasses} ${variantClasses}` : staticClasses || variantClasses;
|
|
1610
|
+
return cn(staticClasses, variantClasses, className);
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// ../core/dist/index.js
|
|
1615
|
+
var FULL_CAPABILITIES = { createClassPipeline, AriaEngine: AriaPolicyEngine };
|
|
1616
|
+
function createPolymorphic2(options = {}) {
|
|
1617
|
+
return createPolymorphic(options, FULL_CAPABILITIES);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
// ../../lib/adapter-utils/src/build-core-runtime.ts
|
|
1621
|
+
var EMPTY_SET = /* @__PURE__ */ new Set();
|
|
1622
|
+
function buildCoreRuntime(normalized) {
|
|
1623
|
+
const runtime = createPolymorphic2(normalized);
|
|
1624
|
+
const ownedKeys = "classPlugin" in runtime ? runtime.classPlugin.ownedKeys ?? EMPTY_SET : EMPTY_SET;
|
|
1625
|
+
return { runtime, ownedKeys };
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// ../../lib/adapter-utils/src/build-engines.ts
|
|
1629
|
+
function buildEngines(strict, childRules, context) {
|
|
1630
|
+
return childRules?.length ? { childrenEvaluator: new ChildrenEvaluator(childRules, strict, context) } : {};
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// ../../lib/adapter-utils/src/compose-filter.ts
|
|
1634
|
+
function composeFilter(ownedKeys, filterProps) {
|
|
1635
|
+
const defaultFilter = (key, variantKeys) => variantKeys.has(key) || ownedKeys.has(key);
|
|
1636
|
+
if (!filterProps) {
|
|
1637
|
+
return defaultFilter;
|
|
1638
|
+
}
|
|
1639
|
+
return (key, variantKeys) => defaultFilter(key, variantKeys) || filterProps(key, variantKeys);
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
// ../../lib/adapter-utils/src/resolve-adapter-common-options.ts
|
|
1643
|
+
function resolveAdapterCommonOptions(options, defaultName = "PolymorphicComponent", defaultStrict = "throw") {
|
|
1644
|
+
return {
|
|
1645
|
+
name: options.name ?? defaultName,
|
|
1646
|
+
strict: options.enforcement?.strict ?? defaultStrict
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
// ../../adapters/web/src/build-runtime.ts
|
|
1651
|
+
function buildRuntime(options) {
|
|
1652
|
+
const normalized = {
|
|
1653
|
+
...options,
|
|
1654
|
+
...resolveAdapterCommonOptions(options, "PolymorphicElement", false)
|
|
1655
|
+
};
|
|
1656
|
+
const { filterProps: customFilter, enforcement } = normalized;
|
|
1657
|
+
const { runtime, ownedKeys } = buildCoreRuntime(normalized);
|
|
1658
|
+
const { childrenEvaluator } = buildEngines(
|
|
1659
|
+
normalized.strict,
|
|
1660
|
+
enforcement?.children,
|
|
1661
|
+
normalized.name
|
|
1662
|
+
);
|
|
1663
|
+
const filterProps = composeFilter(ownedKeys, customFilter);
|
|
1664
|
+
return {
|
|
1665
|
+
runtime,
|
|
1666
|
+
filterProps,
|
|
1667
|
+
strict: normalized.strict,
|
|
1668
|
+
...childrenEvaluator !== void 0 && { childrenEvaluator }
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
|
|
1672
|
+
// ../../adapters/web/src/render-to-string.ts
|
|
1673
|
+
var ssrRegistry = /* @__PURE__ */ new WeakMap();
|
|
1674
|
+
function registerForSsr(cls, bundle) {
|
|
1675
|
+
ssrRegistry.set(cls, { bundle });
|
|
1676
|
+
}
|
|
1677
|
+
function escapeAttr(value) {
|
|
1678
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
1679
|
+
}
|
|
1680
|
+
function buildAttrString(attributes) {
|
|
1681
|
+
const parts = [];
|
|
1682
|
+
for (const key in attributes) {
|
|
1683
|
+
if (!Object.hasOwn(attributes, key)) continue;
|
|
1684
|
+
const value = attributes[key];
|
|
1685
|
+
if (value === false || value === null || value === void 0) continue;
|
|
1686
|
+
if (value === true) {
|
|
1687
|
+
parts.push(key);
|
|
1688
|
+
} else {
|
|
1689
|
+
parts.push(`${key}="${escapeAttr(String(value))}"`);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return parts.length > 0 ? " " + parts.join(" ") : "";
|
|
1693
|
+
}
|
|
1694
|
+
function renderToString(component, props = {}, innerHTML = "") {
|
|
1695
|
+
const entry = ssrRegistry.get(component);
|
|
1696
|
+
if (!entry) {
|
|
1697
|
+
const name = component.name ?? "AnonymousComponent";
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
`[renderToString] ${name} was not registered for SSR. Ensure it was created with createContractComponent from @praxis-kit/web.`
|
|
1700
|
+
);
|
|
1701
|
+
}
|
|
1702
|
+
const { bundle } = entry;
|
|
1703
|
+
const { as, className, variantKey, class: classAttr, ...rest } = props;
|
|
1704
|
+
const tag = bundle.runtime.resolveTag(as);
|
|
1705
|
+
const mergedProps = bundle.runtime.resolveProps(rest);
|
|
1706
|
+
const resolvedClass = bundle.runtime.resolveClasses(
|
|
1707
|
+
tag,
|
|
1708
|
+
mergedProps,
|
|
1709
|
+
className ?? classAttr,
|
|
1710
|
+
variantKey
|
|
1711
|
+
);
|
|
1712
|
+
const ariaResult = bundle.runtime.resolveAria(tag, mergedProps);
|
|
1713
|
+
const filtered = applyFilter(
|
|
1714
|
+
ariaResult.props,
|
|
1715
|
+
bundle.filterProps,
|
|
1716
|
+
bundle.runtime.options.variantKeys
|
|
1717
|
+
);
|
|
1718
|
+
const attrs = { ...filtered, class: resolvedClass || void 0 };
|
|
1719
|
+
const attrStr = buildAttrString(attrs);
|
|
1720
|
+
return `<${tag}${attrStr}>${innerHTML}</${tag}>`;
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
// ../../adapters/web/src/create-contract-component.ts
|
|
1724
|
+
function isObject2(value) {
|
|
1725
|
+
return typeof value === "object" && value !== null;
|
|
1726
|
+
}
|
|
1727
|
+
function isLooseBundle(arg) {
|
|
1728
|
+
if (!isObject2(arg)) return false;
|
|
1729
|
+
const { runtime, filterProps, childrenEvaluator } = arg;
|
|
1730
|
+
if (!isObject2(runtime)) return false;
|
|
1731
|
+
if (!isObject2(runtime["options"])) return false;
|
|
1732
|
+
if (typeof runtime["resolveTag"] !== "function" || typeof runtime["resolveProps"] !== "function" || typeof runtime["resolveClasses"] !== "function" || typeof runtime["resolveAria"] !== "function")
|
|
1733
|
+
return false;
|
|
1734
|
+
if (typeof filterProps !== "function") return false;
|
|
1735
|
+
if (childrenEvaluator !== void 0 && (!isObject2(childrenEvaluator) || typeof childrenEvaluator["evaluate"] !== "function"))
|
|
1736
|
+
return false;
|
|
1737
|
+
return true;
|
|
1738
|
+
}
|
|
1739
|
+
function toLooseBundle(bundle) {
|
|
1740
|
+
if (!isLooseBundle(bundle)) {
|
|
1741
|
+
throw new Error("[createContractComponent] buildRuntime returned an unexpected shape.");
|
|
1742
|
+
}
|
|
1743
|
+
return bundle;
|
|
1744
|
+
}
|
|
1745
|
+
function resolveHostState(bundle, props) {
|
|
1746
|
+
const { as, className, variantKey, ...rest } = props;
|
|
1747
|
+
const tag = bundle.runtime.resolveTag(as);
|
|
1748
|
+
const mergedProps = bundle.runtime.resolveProps(rest);
|
|
1749
|
+
const resolvedClass = bundle.runtime.resolveClasses(
|
|
1750
|
+
tag,
|
|
1751
|
+
mergedProps,
|
|
1752
|
+
className,
|
|
1753
|
+
variantKey
|
|
1754
|
+
);
|
|
1755
|
+
const ariaResult = bundle.runtime.resolveAria(tag, mergedProps);
|
|
1756
|
+
const attributes = applyFilter(
|
|
1757
|
+
ariaResult.props,
|
|
1758
|
+
bundle.filterProps,
|
|
1759
|
+
bundle.runtime.options.variantKeys
|
|
1760
|
+
);
|
|
1761
|
+
return { className: resolvedClass, attributes };
|
|
1762
|
+
}
|
|
1763
|
+
function applyHostState(host, state, prevPipelineAttrs, incomingProps) {
|
|
1764
|
+
host.className = state.className;
|
|
1765
|
+
for (const key of prevPipelineAttrs) {
|
|
1766
|
+
if (!Object.hasOwn(state.attributes, key)) host.removeAttribute(key);
|
|
1767
|
+
}
|
|
1768
|
+
prevPipelineAttrs.clear();
|
|
1769
|
+
for (const key in incomingProps) {
|
|
1770
|
+
if (!Object.hasOwn(incomingProps, key)) continue;
|
|
1771
|
+
if (!key.startsWith("aria-") && key !== "role") continue;
|
|
1772
|
+
if (!Object.hasOwn(state.attributes, key)) host.removeAttribute(key);
|
|
1773
|
+
}
|
|
1774
|
+
for (const key in state.attributes) {
|
|
1775
|
+
if (!Object.hasOwn(state.attributes, key)) continue;
|
|
1776
|
+
const value = state.attributes[key];
|
|
1777
|
+
if (value === void 0 || value === null || value === false) {
|
|
1778
|
+
host.removeAttribute(key);
|
|
1779
|
+
} else if (value === true) {
|
|
1780
|
+
host.setAttribute(key, "");
|
|
1781
|
+
prevPipelineAttrs.add(key);
|
|
1782
|
+
} else {
|
|
1783
|
+
host.setAttribute(key, String(value));
|
|
1784
|
+
prevPipelineAttrs.add(key);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
function createContractComponent(options) {
|
|
1789
|
+
const bundle = buildRuntime(options);
|
|
1790
|
+
const looseBundle = toLooseBundle(bundle);
|
|
1791
|
+
const variantKeys = options.styling?.variants ? Object.keys(options.styling.variants) : [];
|
|
1792
|
+
const observedAttrNames = ["as", "variant-key", "praxis-class", ...variantKeys];
|
|
1793
|
+
const BaseElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
1794
|
+
};
|
|
1795
|
+
class PolymorphicWebElement extends BaseElement {
|
|
1796
|
+
// Tracks keys set by the pipeline last run so stale ones are removed.
|
|
1797
|
+
_pipelineAttrs = /* @__PURE__ */ new Set();
|
|
1798
|
+
static get observedAttributes() {
|
|
1799
|
+
return observedAttrNames;
|
|
1800
|
+
}
|
|
1801
|
+
connectedCallback() {
|
|
1802
|
+
this._applyPraxis();
|
|
1803
|
+
}
|
|
1804
|
+
// Fires synchronously for every observed attribute change — no microtask
|
|
1805
|
+
// scheduling needed. The guard is implicit: this only fires for
|
|
1806
|
+
// observedAttributes, all of which are praxis-owned.
|
|
1807
|
+
attributeChangedCallback(_name, _old, _next) {
|
|
1808
|
+
if (this.isConnected) {
|
|
1809
|
+
this._applyPraxis();
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
/** Re-runs the pipeline. Call after setting non-reactive attributes (aria-*, role, data-*). */
|
|
1813
|
+
update() {
|
|
1814
|
+
this._applyPraxis();
|
|
1815
|
+
}
|
|
1816
|
+
get _self() {
|
|
1817
|
+
return this;
|
|
1818
|
+
}
|
|
1819
|
+
_applyPraxis() {
|
|
1820
|
+
const self = this._self;
|
|
1821
|
+
if (bundle.childrenEvaluator) {
|
|
1822
|
+
bundle.childrenEvaluator.evaluate(Array.from(this.childNodes));
|
|
1823
|
+
}
|
|
1824
|
+
const observedSet = new Set(
|
|
1825
|
+
this.constructor.observedAttributes ?? []
|
|
1826
|
+
);
|
|
1827
|
+
const props = {};
|
|
1828
|
+
for (const attr of Array.from(this.attributes)) {
|
|
1829
|
+
if (attr.name === "class" || observedSet.has(attr.name)) continue;
|
|
1830
|
+
props[attr.name] = attr.value;
|
|
1831
|
+
}
|
|
1832
|
+
props["as"] = self.as ?? this.getAttribute("as") ?? void 0;
|
|
1833
|
+
props["variantKey"] = self.variantKey ?? this.getAttribute("variant-key") ?? void 0;
|
|
1834
|
+
props["className"] = self.praxisClass ?? this.getAttribute("praxis-class") ?? void 0;
|
|
1835
|
+
for (const key of variantKeys) {
|
|
1836
|
+
const val = self[key] ?? this.getAttribute(key);
|
|
1837
|
+
if (val != null) props[key] = val;
|
|
1838
|
+
}
|
|
1839
|
+
applyHostState(this, resolveHostState(looseBundle, props), this._pipelineAttrs, props);
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
if (options.name) {
|
|
1843
|
+
Object.defineProperty(PolymorphicWebElement, "name", { value: options.name });
|
|
1844
|
+
}
|
|
1845
|
+
Object.defineProperty(PolymorphicWebElement, "strict", { value: bundle.strict });
|
|
1846
|
+
registerForSsr(PolymorphicWebElement, looseBundle);
|
|
1847
|
+
return PolymorphicWebElement;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
// ../../adapters/web/src/define-contract-component.ts
|
|
1851
|
+
function defineContractComponent(options) {
|
|
1852
|
+
return (factory) => factory(options);
|
|
1853
|
+
}
|
|
1854
|
+
export {
|
|
1855
|
+
createContractComponent,
|
|
1856
|
+
defineContractComponent,
|
|
1857
|
+
renderToString
|
|
1858
|
+
};
|