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