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