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