foldkit-mixins 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,1171 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
+ import { Stream } from "effect";
3
+ import { inertHtml } from "foldkit/html";
4
+ //#region src/metadataToken.ts
5
+ var metadataToken_exports = /* @__PURE__ */ __exportAll({
6
+ MetadataTokenTypeId: () => MetadataTokenTypeId,
7
+ is: () => is$5,
8
+ make: () => make$6,
9
+ nameOf: () => nameOf
10
+ });
11
+ /**
12
+ * Ported from `effect-atom-jsx/src/MetadataToken.ts`. Kinded name tokens so
13
+ * Event, Attr, Requirement, and Capability share one witness instead of four
14
+ * ad-hoc brands.
15
+ */
16
+ const MetadataTokenTypeId = Symbol.for("foldkit-mixins/MetadataToken");
17
+ const make$6 = (kind, name) => {
18
+ if (name === "") throw new Error(`${kind} name must be non-empty`);
19
+ return {
20
+ [MetadataTokenTypeId]: {
21
+ Kind: void 0,
22
+ Name: void 0
23
+ },
24
+ kind,
25
+ name
26
+ };
27
+ };
28
+ const is$5 = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, MetadataTokenTypeId);
29
+ const nameOf = (value) => is$5(value) ? value.name : value;
30
+ //#endregion
31
+ //#region src/capability.ts
32
+ /**
33
+ * Ported from `effect-atom-jsx/src/Element.ts` `Capability`, without Handle
34
+ * objects. Inheritance is metadata: a behavior that needs Interactive can
35
+ * attach to TextInput. Lookups go through a Map so `__proto__` is a legal name.
36
+ */
37
+ var capability_exports = /* @__PURE__ */ __exportAll({
38
+ Base: () => Base,
39
+ Collection: () => Collection,
40
+ Container: () => Container,
41
+ Draggable: () => Draggable,
42
+ Focusable: () => Focusable,
43
+ Interactive: () => Interactive,
44
+ TextInput: () => TextInput,
45
+ describe: () => describe$5,
46
+ extendsCapability: () => extendsCapability,
47
+ is: () => is$4,
48
+ make: () => make$5,
49
+ names: () => names,
50
+ satisfies: () => satisfies
51
+ });
52
+ const parentsByName = /* @__PURE__ */ new Map();
53
+ const registry = /* @__PURE__ */ new Map();
54
+ const is$4 = (value) => is$5(value) && value.kind === "element.capability";
55
+ const make$5 = (name, options) => {
56
+ if (name === "") throw new Error("Capability name must be non-empty");
57
+ const parents = options?.extends ?? [];
58
+ const parentNames = parents.map((parent) => nameOf(parent));
59
+ const existing = registry.get(name);
60
+ if (existing !== void 0) {
61
+ const existingNames = existing.extends.map((parent) => nameOf(parent));
62
+ if (existingNames.length === parentNames.length && existingNames.every((parentName, index) => parentName === parentNames[index])) return existing;
63
+ throw new Error(`Capability "${name}" is already defined with a different extends list`);
64
+ }
65
+ parentsByName.set(name, parentNames);
66
+ const capability = {
67
+ ...make$6("element.capability", name),
68
+ extends: Object.freeze([...parents])
69
+ };
70
+ registry.set(name, capability);
71
+ return Object.freeze(capability);
72
+ };
73
+ /** True when `value` is `base` or inherits from it. Ported from AF-UI. */
74
+ const extendsCapability = (value, base) => {
75
+ const valueName = nameOf(value);
76
+ const baseName = nameOf(base);
77
+ if (valueName === baseName) return true;
78
+ const visited = /* @__PURE__ */ new Set();
79
+ const stack = [...parentsByName.get(valueName) ?? []];
80
+ while (stack.length > 0) {
81
+ const current = stack.pop();
82
+ if (current === void 0) continue;
83
+ if (current === baseName) return true;
84
+ if (visited.has(current)) continue;
85
+ visited.add(current);
86
+ stack.push(...parentsByName.get(current) ?? []);
87
+ }
88
+ return false;
89
+ };
90
+ const satisfies = (actual, required) => extendsCapability(actual, required);
91
+ const names = (capability) => {
92
+ const seen = /* @__PURE__ */ new Set();
93
+ const walk = (name) => {
94
+ if (seen.has(name)) return;
95
+ seen.add(name);
96
+ for (const parent of parentsByName.get(name) ?? []) walk(parent);
97
+ };
98
+ walk(capability.name);
99
+ return [...seen];
100
+ };
101
+ const describe$5 = (capability) => ({
102
+ name: capability.name,
103
+ extends: capability.extends.map((parent) => nameOf(parent))
104
+ });
105
+ const Base = make$5("Base");
106
+ const Interactive = make$5("Interactive", { extends: [Base] });
107
+ const Container = make$5("Container", { extends: [Interactive] });
108
+ const Focusable = make$5("Focusable", { extends: [Interactive] });
109
+ const TextInput = make$5("TextInput", { extends: [Focusable] });
110
+ const Draggable = make$5("Draggable", { extends: [Interactive] });
111
+ const Collection = make$5("Collection", { extends: [Base] });
112
+ //#endregion
113
+ //#region src/a11y.ts
114
+ /**
115
+ * Structural accessibility validation. A `Pattern` names the Slots a widget
116
+ * must publish, the capabilities those Slots must satisfy, and the events and
117
+ * attributes they must expose. `validate` compares a `Slots` contract against a
118
+ * pattern and reports every mismatch as a `Diagnostic`. It is pure and
119
+ * DOM-independent: it checks the declared contract, not a rendered tree, so it
120
+ * verifies only the contract it is given and does not certify WCAG conformance.
121
+ */
122
+ var a11y_exports = /* @__PURE__ */ __exportAll({
123
+ PatternTypeId: () => PatternTypeId,
124
+ pattern: () => pattern,
125
+ validate: () => validate
126
+ });
127
+ const PatternTypeId = Symbol.for("foldkit-mixins/A11yPattern");
128
+ const pattern = (spec) => {
129
+ const requirements = Object.create(null);
130
+ for (const name of Object.getOwnPropertyNames(spec)) {
131
+ const requirement = spec[name];
132
+ if (requirement === void 0) continue;
133
+ Object.defineProperty(requirements, name, {
134
+ value: Object.freeze({ ...requirement }),
135
+ enumerable: true,
136
+ configurable: false,
137
+ writable: false
138
+ });
139
+ }
140
+ Object.freeze(requirements);
141
+ return Object.freeze({
142
+ [PatternTypeId]: { Requirements: void 0 },
143
+ requirements
144
+ });
145
+ };
146
+ const publishes = (names, required) => {
147
+ const requiredName = nameOf(required);
148
+ return names.some((name) => nameOf(name) === requiredName);
149
+ };
150
+ const diagnostic = (code, message, slot, details) => ({
151
+ source: "a11y",
152
+ code,
153
+ severity: "error",
154
+ message,
155
+ slot,
156
+ ...details === void 0 ? {} : { details }
157
+ });
158
+ const validate = (pattern, slots) => {
159
+ const diagnostics = [];
160
+ for (const name of Object.getOwnPropertyNames(pattern.requirements)) {
161
+ const requirement = pattern.requirements[name];
162
+ if (requirement === void 0) continue;
163
+ if (!Object.hasOwn(slots, name)) {
164
+ if (requirement.optional === true) continue;
165
+ diagnostics.push(diagnostic("a11y:missing-slot", `A11y pattern requires slot "${name}", which the contract does not publish`, name));
166
+ continue;
167
+ }
168
+ const slot = slots[name];
169
+ if (slot === void 0) continue;
170
+ if (slot.hidden) {
171
+ diagnostics.push(diagnostic("a11y:hidden-slot", `A11y pattern requires slot "${name}", which is hidden`, name));
172
+ continue;
173
+ }
174
+ if (requirement.capability !== void 0 && !extendsCapability(slot.capability, requirement.capability)) diagnostics.push(diagnostic("a11y:capability-mismatch", `A11y pattern requires capability "${nameOf(requirement.capability)}" on slot "${name}", which has "${nameOf(slot.capability)}"`, name, {
175
+ required: nameOf(requirement.capability),
176
+ actual: nameOf(slot.capability)
177
+ }));
178
+ for (const event of requirement.events ?? []) {
179
+ const eventName = nameOf(event);
180
+ if (publishes(slot.events, event)) continue;
181
+ diagnostics.push(diagnostic("a11y:missing-event", `A11y pattern requires event "${eventName}" on slot "${name}", which does not publish it`, name, { event: eventName }));
182
+ }
183
+ for (const attribute of requirement.attributes ?? []) {
184
+ const attributeName = nameOf(attribute);
185
+ if (publishes(slot.attributes, attribute)) continue;
186
+ diagnostics.push(diagnostic("a11y:missing-attribute", `A11y pattern requires attribute "${attributeName}" on slot "${name}", which does not publish it`, name, { attribute: attributeName }));
187
+ }
188
+ }
189
+ return diagnostics;
190
+ };
191
+ //#endregion
192
+ //#region src/attr.ts
193
+ /**
194
+ * Slot attribute tokens. Ported from `effect-atom-jsx/src/View.ts` `Attribute`,
195
+ * plus ARIA names the Foldkit plan lists.
196
+ */
197
+ var attr_exports = /* @__PURE__ */ __exportAll({
198
+ AriaDescribedby: () => AriaDescribedby,
199
+ AriaDisabled: () => AriaDisabled,
200
+ AriaExpanded: () => AriaExpanded,
201
+ AriaInvalid: () => AriaInvalid,
202
+ AriaLabel: () => AriaLabel,
203
+ AriaSelected: () => AriaSelected,
204
+ Disabled: () => Disabled,
205
+ Role: () => Role,
206
+ Value: () => Value,
207
+ describe: () => describe$4,
208
+ equals: () => equals$1,
209
+ is: () => is$3,
210
+ make: () => make$4
211
+ });
212
+ const is$3 = (value) => is$5(value) && value.kind === "view.attribute";
213
+ const make$4 = (name) => make$6("view.attribute", name);
214
+ const equals$1 = (left, right) => left.name === right.name;
215
+ const describe$4 = (attr) => ({ name: attr.name });
216
+ const Role = make$4("role");
217
+ const AriaLabel = make$4("aria-label");
218
+ const AriaDescribedby = make$4("aria-describedby");
219
+ const AriaExpanded = make$4("aria-expanded");
220
+ const AriaSelected = make$4("aria-selected");
221
+ const AriaInvalid = make$4("aria-invalid");
222
+ const AriaDisabled = make$4("aria-disabled");
223
+ const Disabled = make$4("disabled");
224
+ const Value = make$4("value");
225
+ //#endregion
226
+ //#region src/diagnostics.ts
227
+ var diagnostics_exports = /* @__PURE__ */ __exportAll({ DiagnosticError: () => DiagnosticError });
228
+ var DiagnosticError = class extends Error {
229
+ diagnostic;
230
+ constructor(diagnostic) {
231
+ super(diagnostic.message);
232
+ this.name = "DiagnosticError";
233
+ this.diagnostic = diagnostic;
234
+ }
235
+ };
236
+ //#endregion
237
+ //#region src/mixin.ts
238
+ var mixin_exports = /* @__PURE__ */ __exportAll({
239
+ compose: () => compose$1,
240
+ contributionsFor: () => contributionsFor,
241
+ dynamic: () => dynamic,
242
+ empty: () => empty$1,
243
+ evaluate: () => evaluate,
244
+ isDynamic: () => isDynamic,
245
+ make: () => make$3
246
+ });
247
+ const isDynamic = (contribution) => typeof contribution === "function";
248
+ const evaluate = (contribution, context) => isDynamic(contribution) ? contribution(context) : contribution;
249
+ const mergeStatic = (left, right) => {
250
+ const css = `${left.css ?? ""}${right.css ?? ""}`;
251
+ const globalCss = `${left.globalCss ?? ""}${right.globalCss ?? ""}`;
252
+ return Object.freeze({
253
+ classes: Object.freeze([...left.classes ?? [], ...right.classes ?? []]),
254
+ style: Object.freeze({
255
+ ...left.style ?? {},
256
+ ...right.style ?? {}
257
+ }),
258
+ attributes: Object.freeze([...left.attributes ?? [], ...right.attributes ?? []]),
259
+ mounts: Object.freeze([...left.mounts ?? [], ...right.mounts ?? []]),
260
+ ...css === "" ? {} : { css },
261
+ ...globalCss === "" ? {} : { globalCss }
262
+ });
263
+ };
264
+ const mergeSlot = (left, right) => {
265
+ if (!isDynamic(left) && !isDynamic(right)) return mergeStatic(left, right);
266
+ return (context) => mergeStatic(evaluate(left, context), evaluate(right, context));
267
+ };
268
+ const make$3 = (name, contributions) => Object.freeze({
269
+ name,
270
+ contributions: Object.freeze({ ...contributions })
271
+ });
272
+ const dynamic = (name, contributions) => Object.freeze({
273
+ name,
274
+ contributions: Object.freeze({ ...contributions })
275
+ });
276
+ const empty$1 = () => make$3("Empty", {});
277
+ const compose$1 = (...mixins) => {
278
+ const merged = Object.create(null);
279
+ for (const mixin of mixins) for (const [slot, contribution] of Object.entries(mixin.contributions)) {
280
+ if (contribution === void 0) continue;
281
+ const normalized = contribution;
282
+ const existing = merged[slot];
283
+ merged[slot] = existing === void 0 ? normalized : mergeSlot(existing, normalized);
284
+ }
285
+ return dynamic(mixins.length === 0 ? "Empty" : mixins.map((mixin) => mixin.name).join("+"), merged);
286
+ };
287
+ const contributionsFor = (mixin, slot) => mixin.contributions[slot];
288
+ //#endregion
289
+ //#region src/pipe.ts
290
+ /** Ported from `effect-atom-jsx/src/View.ts` `pipeSelf`. */
291
+ const pipeSelf = (self, fns) => fns.reduce((acc, fn) => fn(acc), self);
292
+ //#endregion
293
+ //#region src/attribute.ts
294
+ /** The brand `childAttribute.d.ts` stamps; Foldkit's guard is not exported. */
295
+ const CHILD_ATTRIBUTE_BRAND = "__childAttribute";
296
+ const isChildAttribute = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, CHILD_ATTRIBUTE_BRAND);
297
+ const isTagged = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, "_tag") && typeof value._tag === "string";
298
+ /** `Class` carries no Message, so the inert builder is the honest constructor. */
299
+ const classAttribute = (value) => inertHtml.Class(value);
300
+ const styleAttribute = (value) => inertHtml.Style(value);
301
+ /**
302
+ * `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing
303
+ * mount is built directly. The shape is the same tagged value `h.OnMount`
304
+ * produces (`{ _tag: 'OnMount', action }`).
305
+ */
306
+ const mountAttribute = (action) => ({
307
+ _tag: "OnMount",
308
+ action
309
+ });
310
+ //#endregion
311
+ //#region src/resolver.ts
312
+ /**
313
+ * The deterministic resolver. `resolve` is pure: it decomposes the base
314
+ * attributes, applies contributions in attachment order, enforces ownership
315
+ * and protection, then emits one canonical `Class`, one `Style`, and at most
316
+ * one `OnMount`. Conflicts throw a `DiagnosticError` before Foldkit could
317
+ * silently chain or replace.
318
+ */
319
+ var resolver_exports = /* @__PURE__ */ __exportAll({ resolve: () => resolve });
320
+ /** `AriaLabel` -> `arialabel`, `aria-label` -> `arialabel`; tags and tokens agree. */
321
+ const normalizeName = (name) => name.replace(/[^a-z0-9]/gi, "").toLowerCase();
322
+ /** Attribute tags are PascalCase (`OnKeyDown`); event tokens are lowercase. */
323
+ const eventNameOfTag = (tag) => normalizeName(tag.startsWith("On") ? tag.slice(2) : tag);
324
+ const splitClasses = (value) => value.split(/\s+/).filter((token) => token.length > 0);
325
+ /** `Prop`/`Attribute`/`DataAttribute`/`OnCustomEvent` are keyed individually. */
326
+ const ownershipKey = (tag, value) => {
327
+ if (typeof value !== "object" || value === null) return tag;
328
+ const record = value;
329
+ switch (tag) {
330
+ case "Prop":
331
+ case "Attribute":
332
+ case "DataAttribute": return `${tag}:${String(record.key)}`;
333
+ case "OnCustomEvent": return `${tag}:${String(record.name)}`;
334
+ default: return tag;
335
+ }
336
+ };
337
+ const toDiagnostic = (code, message, slot, details) => ({
338
+ source: "mixins",
339
+ code,
340
+ severity: "error",
341
+ message,
342
+ ...slot === void 0 ? {} : { slot },
343
+ details
344
+ });
345
+ const resolve = (base, contributions, options = {}) => {
346
+ const slot = options.slot;
347
+ const protection = options.protected;
348
+ const protectedEvents = new Set((protection?.events ?? []).map((event) => normalizeName(nameOf(event))));
349
+ const protectedAttributes = new Set((protection?.attributes ?? []).map((attr) => normalizeName(nameOf(attr))));
350
+ const protectedStyle = new Set(protection?.style ?? []);
351
+ const classes = [];
352
+ const classSeen = /* @__PURE__ */ new Set();
353
+ const style = /* @__PURE__ */ new Map();
354
+ const mounts = [];
355
+ const mountNames = /* @__PURE__ */ new Map();
356
+ const preserved = [];
357
+ const added = [];
358
+ const ownedEvents = /* @__PURE__ */ new Map();
359
+ const ownedAttributes = /* @__PURE__ */ new Map();
360
+ function fail(code, message, details) {
361
+ throw new DiagnosticError(toDiagnostic(code, message, slot, details));
362
+ }
363
+ const addClass = (token) => {
364
+ if (classSeen.has(token)) return;
365
+ classSeen.add(token);
366
+ classes.push(token);
367
+ };
368
+ const addMount = (action) => {
369
+ const count = (mountNames.get(action.name) ?? 0) + 1;
370
+ mountNames.set(action.name, count);
371
+ if (count > 1) fail("mixins:duplicate-mount-name", `two Mounts are both named "${action.name}"`, { name: action.name });
372
+ mounts.push(action);
373
+ };
374
+ const reserve = (tag, value) => {
375
+ if (tag === "OnMount") return;
376
+ if (tag.startsWith("On") && tag !== "OnCustomEvent") {
377
+ ownedEvents.set(eventNameOfTag(tag), tag);
378
+ return;
379
+ }
380
+ ownedAttributes.set(ownershipKey(tag, value), tag);
381
+ };
382
+ const addBase = (attribute) => {
383
+ if (isChildAttribute(attribute)) {
384
+ const inner = attribute.attribute;
385
+ if (isTagged(inner)) reserve(inner._tag, inner);
386
+ preserved.push(attribute);
387
+ return;
388
+ }
389
+ const tag = attribute._tag;
390
+ switch (tag) {
391
+ case "Class":
392
+ for (const token of splitClasses(attribute.value)) addClass(token);
393
+ return;
394
+ case "Style":
395
+ for (const [property, value] of Object.entries(attribute.value)) style.set(property, value);
396
+ return;
397
+ case "OnMount":
398
+ addMount(attribute.action);
399
+ return;
400
+ default:
401
+ reserve(tag, attribute);
402
+ preserved.push(attribute);
403
+ }
404
+ };
405
+ const applyMixinAttribute = (attribute) => {
406
+ if (isChildAttribute(attribute)) {
407
+ const inner = attribute.attribute;
408
+ if (isTagged(inner)) reserve(inner._tag, inner);
409
+ added.push(attribute);
410
+ return;
411
+ }
412
+ const tag = attribute._tag;
413
+ switch (tag) {
414
+ case "Class":
415
+ for (const token of splitClasses(attribute.value)) addClass(token);
416
+ return;
417
+ case "Style":
418
+ for (const [property, value] of Object.entries(attribute.value)) {
419
+ if (protectedStyle.has(property)) fail("mixins:protected-style-property", `slot "${slot ?? "?"}" protects style property "${property}"`, { property });
420
+ style.set(property, value);
421
+ }
422
+ return;
423
+ case "OnMount":
424
+ addMount(attribute.action);
425
+ return;
426
+ case "Key":
427
+ case "InnerHTML": fail("mixins:structural-override", `a Mixin may not contribute "${tag}"; it is structural ownership`, { tag });
428
+ default:
429
+ if (tag.startsWith("On") && tag !== "OnCustomEvent") {
430
+ const eventName = eventNameOfTag(tag);
431
+ if (protectedEvents.has(eventName)) fail("mixins:protected-event", `slot "${slot ?? "?"}" protects event "${eventName}"`, {
432
+ tag,
433
+ event: eventName
434
+ });
435
+ const owner = ownedEvents.get(eventName);
436
+ if (owner !== void 0) fail("mixins:event-conflict", `two owners for event "${eventName}": "${owner}" already owns it`, {
437
+ tag,
438
+ event: eventName,
439
+ owner
440
+ });
441
+ ownedEvents.set(eventName, tag);
442
+ } else {
443
+ const key = ownershipKey(tag, attribute);
444
+ if (protectedAttributes.has(normalizeName(tag))) fail("mixins:protected-attribute", `slot "${slot ?? "?"}" protects attribute "${tag}"`, { tag });
445
+ const owner = ownedAttributes.get(key);
446
+ if (owner !== void 0) fail("mixins:attribute-conflict", `two owners for "${key}": a ${owner} attribute already occupies it`, {
447
+ tag,
448
+ key,
449
+ owner
450
+ });
451
+ ownedAttributes.set(key, tag);
452
+ }
453
+ added.push(attribute);
454
+ }
455
+ };
456
+ for (const attribute of base ?? []) addBase(attribute);
457
+ for (const contribution of contributions) {
458
+ for (const token of contribution.classes ?? []) addClass(token);
459
+ for (const [property, value] of Object.entries(contribution.style ?? {})) {
460
+ if (protectedStyle.has(property)) fail("mixins:protected-style-property", `slot "${slot ?? "?"}" protects style property "${property}"`, { property });
461
+ style.set(property, value);
462
+ }
463
+ for (const attribute of contribution.attributes ?? []) applyMixinAttribute(attribute);
464
+ for (const mount of contribution.mounts ?? []) addMount(mount);
465
+ }
466
+ const emitted = [];
467
+ if (classes.length > 0) emitted.push(classAttribute(classes.join(" ")));
468
+ if (style.size > 0) emitted.push(styleAttribute(Object.fromEntries(style)));
469
+ emitted.push(...preserved, ...added);
470
+ const composed = composeMounts(mounts, slot);
471
+ if (composed !== void 0) emitted.push(composed);
472
+ return emitted;
473
+ };
474
+ const composeMounts = (mounts, slot) => {
475
+ const first = mounts[0];
476
+ if (first === void 0) return void 0;
477
+ if (mounts.length === 1) return mountAttribute(first);
478
+ const name = `Mixins[${slot ?? "slot"}](${mounts.map((mount) => mount.name).join(",")})`;
479
+ return mountAttribute({
480
+ name,
481
+ args: {
482
+ slot: slot ?? null,
483
+ actions: mounts.map((mount) => ({
484
+ name: mount.name,
485
+ args: mount.args
486
+ }))
487
+ },
488
+ f: (element, viewStateChanges) => Stream.mergeAll(mounts.map((mount) => mount.f(element, viewStateChanges)), { concurrency: "unbounded" })
489
+ });
490
+ };
491
+ //#endregion
492
+ //#region src/slotView.ts
493
+ var slotView_exports = /* @__PURE__ */ __exportAll({
494
+ attach: () => attach$2,
495
+ buildersFor: () => buildersFor,
496
+ define: () => define$2
497
+ });
498
+ /** Build one `attrs` resolver per published slot, evaluating Mixins lazily. */
499
+ const buildersFor = (slots, mixins, context) => {
500
+ const source = slots;
501
+ const builders = Object.create(null);
502
+ for (const name of Object.getOwnPropertyNames(source)) {
503
+ const slot = source[name];
504
+ if (slot === void 0) continue;
505
+ const protection = slot.protected;
506
+ builders[name] = { attrs: (base) => {
507
+ const contributions = [];
508
+ for (const mixin of mixins) {
509
+ const contribution = mixin.contributions[name];
510
+ if (contribution !== void 0) contributions.push(evaluate(contribution, {
511
+ input: context.input,
512
+ h: context.h
513
+ }));
514
+ }
515
+ return resolve(base, contributions, {
516
+ slot: name,
517
+ protected: protection
518
+ });
519
+ } };
520
+ }
521
+ return builders;
522
+ };
523
+ const makeView = (name, slots, mixins, render) => {
524
+ const view = (input, h) => render(input, buildersFor(slots, mixins, {
525
+ input,
526
+ h
527
+ }), h);
528
+ if (name !== void 0) Object.defineProperty(view, "name", {
529
+ value: name,
530
+ configurable: true
531
+ });
532
+ return Object.assign(view, {
533
+ slots,
534
+ mixins,
535
+ render,
536
+ pipe: (...fns) => pipeSelf(view, fns)
537
+ });
538
+ };
539
+ const define$2 = (slots, render, options) => makeView(options?.name, slots, [], render);
540
+ function attach$2(mixin) {
541
+ return (view) => makeView(view.name, view.slots, [...view.mixins, mixin], view.render);
542
+ }
543
+ //#endregion
544
+ //#region src/behavior.ts
545
+ var behavior_exports = /* @__PURE__ */ __exportAll({
546
+ Behavior: () => Behavior,
547
+ attach: () => attach$1,
548
+ forSlots: () => forSlots$1,
549
+ slot: () => slot
550
+ });
551
+ /** Identity helper; `forSlots` supplies the contextual `Input`/`Message`. */
552
+ const slot = (options) => options;
553
+ function fail(code, message, slotName, details) {
554
+ throw new DiagnosticError({
555
+ source: "mixins",
556
+ code,
557
+ severity: "error",
558
+ message,
559
+ slot: slotName,
560
+ ...details === void 0 ? {} : { details }
561
+ });
562
+ }
563
+ const validateRequirements = (name, slot, requirements) => {
564
+ if (requirements.capability !== void 0 && !extendsCapability(slot.capability, requirements.capability)) fail("mixins:capability-mismatch", `Behavior requires capability "${nameOf(requirements.capability)}" on slot "${name}", which has "${nameOf(slot.capability)}"`, name, { required: nameOf(requirements.capability) });
565
+ for (const event of requirements.events ?? []) {
566
+ const eventName = nameOf(event);
567
+ if (!slot.events.some((allowed) => nameOf(allowed) === eventName)) fail("mixins:unsupported-event", `Behavior requires event "${eventName}" on slot "${name}", which does not publish it`, name, { event: eventName });
568
+ }
569
+ for (const attribute of requirements.attributes ?? []) {
570
+ const attributeName = nameOf(attribute);
571
+ if (!slot.attributes.some((allowed) => nameOf(allowed) === attributeName)) fail("mixins:unsupported-attribute", `Behavior requires attribute "${attributeName}" on slot "${name}", which does not publish it`, name, { attribute: attributeName });
572
+ }
573
+ };
574
+ const forSlots$1 = (slots) => (spec, options) => {
575
+ const source = slots;
576
+ const contributions = Object.create(null);
577
+ for (const [name, slotOptions] of Object.entries(spec)) {
578
+ const target = source[name];
579
+ if (target === void 0) fail("mixins:unknown-slot", `Behavior targets unknown slot "${name}"`, name);
580
+ if (target.hidden) fail("mixins:hidden-slot", `Behavior targets hidden slot "${name}"`, name);
581
+ if (slotOptions?.requires !== void 0) validateRequirements(name, target, slotOptions.requires);
582
+ const attributes = slotOptions?.attributes;
583
+ const mount = slotOptions?.mount;
584
+ if (attributes === void 0 && mount === void 0) continue;
585
+ contributions[name] = (context) => ({
586
+ ...attributes === void 0 ? {} : { attributes: attributes({
587
+ input: context.input,
588
+ h: context.h
589
+ }) },
590
+ ...mount === void 0 ? {} : { mounts: [mount(context.input)] }
591
+ });
592
+ }
593
+ return Object.freeze({
594
+ ...options?.name === void 0 ? {} : { name: options.name },
595
+ spec,
596
+ mixin: dynamic(options?.name ?? "Behavior", contributions)
597
+ });
598
+ };
599
+ const attach$1 = (behavior) => (view) => attach$2(behavior.mixin)(view);
600
+ const Behavior = {
601
+ slot,
602
+ forSlots: forSlots$1,
603
+ attach: attach$1
604
+ };
605
+ //#endregion
606
+ //#region src/event.ts
607
+ /**
608
+ * Slot event tokens. Ported from `effect-atom-jsx/src/View.ts` `Event`, plus
609
+ * the extra names the Foldkit plan lists.
610
+ */
611
+ var event_exports = /* @__PURE__ */ __exportAll({
612
+ Blur: () => Blur,
613
+ Cancel: () => Cancel,
614
+ Change: () => Change,
615
+ Click: () => Click,
616
+ Focus: () => Focus,
617
+ Hover: () => Hover,
618
+ Input: () => Input,
619
+ KeyDown: () => KeyDown,
620
+ PointerDown: () => PointerDown,
621
+ PointerUp: () => PointerUp,
622
+ Press: () => Press,
623
+ Submit: () => Submit,
624
+ describe: () => describe$3,
625
+ equals: () => equals,
626
+ is: () => is$2,
627
+ make: () => make$2
628
+ });
629
+ const is$2 = (value) => is$5(value) && value.kind === "view.event";
630
+ const make$2 = (name) => make$6("view.event", name);
631
+ const equals = (left, right) => left.name === right.name;
632
+ const describe$3 = (event) => ({ name: event.name });
633
+ const Press = make$2("press");
634
+ const Click = make$2("click");
635
+ const Cancel = make$2("cancel");
636
+ const Input = make$2("input");
637
+ const Change = make$2("change");
638
+ const Focus = make$2("focus");
639
+ const Blur = make$2("blur");
640
+ const KeyDown = make$2("keydown");
641
+ const PointerDown = make$2("pointerdown");
642
+ const PointerUp = make$2("pointerup");
643
+ const Hover = make$2("hover");
644
+ const Submit = make$2("submit");
645
+ //#endregion
646
+ //#region src/requirement.ts
647
+ /**
648
+ * Platform requirement tokens. Ported from `effect-atom-jsx/src/View.ts`
649
+ * `Requirement`.
650
+ */
651
+ var requirement_exports = /* @__PURE__ */ __exportAll({
652
+ Clipboard: () => Clipboard,
653
+ Keyboard: () => Keyboard,
654
+ Pointer: () => Pointer,
655
+ describe: () => describe$2,
656
+ is: () => is$1,
657
+ make: () => make$1
658
+ });
659
+ const is$1 = (value) => is$5(value) && value.kind === "view.requirement";
660
+ const make$1 = (name) => make$6("view.requirement", name);
661
+ const describe$2 = (requirement) => ({ name: requirement.name });
662
+ const Keyboard = make$1("keyboard");
663
+ const Pointer = make$1("pointer");
664
+ const Clipboard = make$1("clipboard");
665
+ //#endregion
666
+ //#region src/slot.ts
667
+ var slot_exports = /* @__PURE__ */ __exportAll({
668
+ SlotTypeId: () => SlotTypeId,
669
+ attributes: () => attributes,
670
+ capability: () => capability,
671
+ describe: () => describe$1,
672
+ events: () => events,
673
+ hide: () => hide,
674
+ is: () => is,
675
+ make: () => make,
676
+ requires: () => requires
677
+ });
678
+ const SlotTypeId = Symbol.for("foldkit-mixins/Slot");
679
+ const is = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, SlotTypeId);
680
+ const emptyProtection = Object.freeze({
681
+ events: Object.freeze([]),
682
+ attributes: Object.freeze([]),
683
+ style: Object.freeze([])
684
+ });
685
+ const protectionOf = (options) => {
686
+ const specified = options?.protected;
687
+ if (specified === void 0) return emptyProtection;
688
+ return Object.freeze({
689
+ events: Object.freeze([...specified.events ?? []]),
690
+ attributes: Object.freeze([...specified.attributes ?? []]),
691
+ style: Object.freeze([...specified.style ?? []])
692
+ });
693
+ };
694
+ const createSlot = (name, options) => {
695
+ const capability = options?.capability ?? Base;
696
+ const events = options?.events ?? options?.allowedEvents ?? [];
697
+ const attributes = options?.attributes ?? options?.allowedAttributes ?? [];
698
+ const requirements = options?.requirements ?? options?.platformRequirements ?? [];
699
+ const hidden = options?.hidden ?? false;
700
+ const protection = protectionOf(options);
701
+ const metadata = {
702
+ name,
703
+ capability,
704
+ allowedEvents: events,
705
+ allowedAttributes: attributes,
706
+ platformRequirements: requirements,
707
+ hidden,
708
+ protected: protection
709
+ };
710
+ const out = {
711
+ [SlotTypeId]: {
712
+ Name: void 0,
713
+ Capability: void 0,
714
+ Events: void 0,
715
+ Attributes: void 0,
716
+ Requirements: void 0,
717
+ Hidden: void 0
718
+ },
719
+ name,
720
+ capability,
721
+ events,
722
+ attributes,
723
+ requirements,
724
+ hidden,
725
+ protected: protection,
726
+ metadata
727
+ };
728
+ return Object.assign(out, { pipe: (...fns) => pipeSelf(out, fns) });
729
+ };
730
+ function make(nameOrOptions, options) {
731
+ if (typeof nameOrOptions === "string") return createSlot(nameOrOptions, options);
732
+ const { name: _dropped, ...rest } = createSlot("", nameOrOptions);
733
+ return rest;
734
+ }
735
+ /** Pipeable transform replacing a named slot's capability. */
736
+ const capability = (capability) => (slot) => createSlot(slot.name, {
737
+ capability,
738
+ events: slot.events,
739
+ attributes: slot.attributes,
740
+ requirements: slot.requirements,
741
+ hidden: slot.hidden,
742
+ protected: slot.protected
743
+ });
744
+ /** Pipeable transform replacing a named slot's allowed events. */
745
+ const events = (...next) => (slot) => createSlot(slot.name, {
746
+ capability: slot.capability,
747
+ events: next,
748
+ attributes: slot.attributes,
749
+ requirements: slot.requirements,
750
+ hidden: slot.hidden,
751
+ protected: slot.protected
752
+ });
753
+ /** Pipeable transform replacing a named slot's allowed attributes. */
754
+ const attributes = (...next) => (slot) => createSlot(slot.name, {
755
+ capability: slot.capability,
756
+ events: slot.events,
757
+ attributes: next,
758
+ requirements: slot.requirements,
759
+ hidden: slot.hidden,
760
+ protected: slot.protected
761
+ });
762
+ /** Pipeable transform replacing a named slot's platform requirements. */
763
+ const requires = (...next) => (slot) => createSlot(slot.name, {
764
+ capability: slot.capability,
765
+ events: slot.events,
766
+ attributes: slot.attributes,
767
+ requirements: next,
768
+ hidden: slot.hidden,
769
+ protected: slot.protected
770
+ });
771
+ /** Pipeable transform marking a named slot hidden from public attachment. */
772
+ const hide = (slot) => createSlot(slot.name, {
773
+ capability: slot.capability,
774
+ events: slot.events,
775
+ attributes: slot.attributes,
776
+ requirements: slot.requirements,
777
+ hidden: true,
778
+ protected: slot.protected
779
+ });
780
+ const describe$1 = (slot) => {
781
+ return {
782
+ ...slot.name !== void 0 && slot.name !== "" ? { name: slot.name } : {},
783
+ capability: nameOf(slot.capability),
784
+ events: slot.events.map((event) => nameOf(event)),
785
+ attributes: slot.attributes.map((attr) => nameOf(attr)),
786
+ requirements: slot.requirements.map((requirement) => nameOf(requirement)),
787
+ hidden: slot.hidden,
788
+ protected: {
789
+ events: slot.protected.events.map((event) => nameOf(event)),
790
+ attributes: slot.protected.attributes.map((attr) => nameOf(attr)),
791
+ style: slot.protected.style
792
+ }
793
+ };
794
+ };
795
+ //#endregion
796
+ //#region src/slots.ts
797
+ /**
798
+ * Slot contracts. Ported from `effect-atom-jsx/src/View.ts` `Slots.define`,
799
+ * without minting element Handles. Names come from keys. Entries may be
800
+ * `Slot.make({...})` or AF-UI option objects `{ capability, allowedEvents }`.
801
+ */
802
+ var slots_exports = /* @__PURE__ */ __exportAll({
803
+ SlotsTypeId: () => SlotsTypeId,
804
+ define: () => define$1,
805
+ describe: () => describe,
806
+ withCapability: () => withCapability
807
+ });
808
+ const SlotsTypeId = Symbol.for("foldkit-mixins/Slots");
809
+ const toUnnamed = (value, key) => {
810
+ if (is(value)) return value;
811
+ if (typeof value === "object" && value !== null && Object.hasOwn(value, "capability")) return make(value);
812
+ throw new Error(`Slots.define: "${key}" is not a Slot or slot options object`);
813
+ };
814
+ const define$1 = (spec) => {
815
+ const proto = Object.getPrototypeOf(spec);
816
+ if (proto !== Object.prototype && proto !== null) throw new Error("Slots.define: pass a plain object; quote [\"__proto__\"] to use that as a slot name");
817
+ const contract = Object.create(null);
818
+ for (const key of Object.getOwnPropertyNames(spec)) {
819
+ const unnamed = toUnnamed(spec[key], key);
820
+ Object.defineProperty(contract, key, {
821
+ value: make(key, {
822
+ capability: unnamed.capability,
823
+ events: unnamed.events,
824
+ attributes: unnamed.attributes,
825
+ requirements: unnamed.requirements,
826
+ hidden: unnamed.hidden,
827
+ protected: unnamed.protected
828
+ }),
829
+ enumerable: true,
830
+ configurable: false,
831
+ writable: false
832
+ });
833
+ }
834
+ Object.freeze(contract);
835
+ return contract;
836
+ };
837
+ const describe = (contract) => {
838
+ const slots = Object.create(null);
839
+ for (const key of Object.getOwnPropertyNames(contract)) {
840
+ const slot = contract[key];
841
+ if (slot === void 0 || !is(slot)) continue;
842
+ slots[key] = {
843
+ ...describe$1(slot),
844
+ name: slot.name !== void 0 && slot.name !== "" ? slot.name : key
845
+ };
846
+ }
847
+ return { slots };
848
+ };
849
+ const withCapability = (contract, capability) => {
850
+ const out = Object.create(null);
851
+ for (const key of Object.getOwnPropertyNames(contract)) {
852
+ const slot = contract[key];
853
+ if (slot === void 0 || !is(slot)) continue;
854
+ if (extendsCapability(slot.capability, capability)) out[key] = slot;
855
+ }
856
+ return out;
857
+ };
858
+ //#endregion
859
+ //#region src/styleRules.ts
860
+ const rule = (selector, declarations, at) => Object.freeze({
861
+ selector,
862
+ declarations: Object.freeze({ ...declarations }),
863
+ ...at === void 0 ? {} : { at }
864
+ });
865
+ const pseudo$1 = (suffix, declarations) => rule(`&${suffix}`, declarations);
866
+ const media$1 = (query, declarations) => rule("&", declarations, `@media ${query}`);
867
+ const supports$1 = (condition, declarations) => rule("&", declarations, `@supports ${condition}`);
868
+ const container$1 = (condition, declarations) => rule("&", declarations, `@container ${condition}`);
869
+ /** A nested selector relative to the class, e.g. `> span` or `[data-open] &`. */
870
+ const nest$1 = (selector, declarations) => rule(`& ${selector}`, declarations);
871
+ /** `gridTemplateColumns` -> `grid-template-columns`; custom properties pass through. */
872
+ const kebab = (property) => property.startsWith("--") ? property : property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
873
+ const declarationsText = (declarations) => Object.keys(declarations).sort().map((property) => `${kebab(property)}:${declarations[property]}`).join(";");
874
+ /** Canonical, declaration-sorted, authored-rule-order text for a rule list. */
875
+ const canonical = (rules) => rules.map((entry) => {
876
+ const body = `{${declarationsText(entry.declarations)}}`;
877
+ return entry.at === void 0 ? `${entry.selector}${body}` : `${entry.at}{${entry.selector}${body}}`;
878
+ }).join("");
879
+ const hash = (value) => {
880
+ let state = 2166136261;
881
+ for (let index = 0; index < value.length; index++) {
882
+ state ^= value.charCodeAt(index);
883
+ state = Math.imul(state, 16777619);
884
+ }
885
+ return (state >>> 0).toString(36);
886
+ };
887
+ /** Deterministic `@keyframes`: step order is authored, declarations sorted. */
888
+ const keyframes$1 = (frames) => {
889
+ const body = Object.entries(frames).map(([step, declarations]) => `${step}{${declarationsText(declarations)}}`).join("");
890
+ const name = `kf-${hash(body)}`;
891
+ return Object.freeze({
892
+ name,
893
+ css: `@keyframes ${name}{${body}}`
894
+ });
895
+ };
896
+ const className = (rules) => `style-${hash(canonical(rules))}`;
897
+ const selectorFor = (generated, selector) => selector.includes("&") ? selector.replace(/&/g, `.${generated}`) : `.${generated} ${selector}`;
898
+ const css = (generated, rules) => rules.map((entry) => {
899
+ const body = `{${declarationsText(entry.declarations)}}`;
900
+ const selector = `${selectorFor(generated, entry.selector)}${body}`;
901
+ return entry.at === void 0 ? selector : `${entry.at}{${selector}}`;
902
+ }).join("");
903
+ //#endregion
904
+ //#region src/style.ts
905
+ const tokens = (value) => value.split(/\s+/).filter((token) => token.length > 0);
906
+ const empty = Object.freeze({
907
+ classes: Object.freeze([]),
908
+ style: Object.freeze({})
909
+ });
910
+ const classPiece = (value) => Object.freeze({
911
+ classes: Object.freeze(tokens(value)),
912
+ style: empty.style
913
+ });
914
+ const inline = (value) => Object.freeze({
915
+ classes: empty.classes,
916
+ style: Object.freeze({ ...value })
917
+ });
918
+ /** Concatenate classes; later inline declarations win per property. */
919
+ const compose = (...pieces) => {
920
+ const conditions = pieces.flatMap((piece) => piece.conditions ?? []);
921
+ const rules = pieces.flatMap((piece) => piece.rules ?? []);
922
+ const globalCss = pieces.flatMap((piece) => piece.globalCss ?? []);
923
+ return Object.freeze({
924
+ classes: Object.freeze(pieces.flatMap((piece) => piece.classes)),
925
+ style: Object.freeze(Object.assign(Object.create(null), ...pieces.map((piece) => piece.style))),
926
+ ...conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) },
927
+ ...rules.length === 0 ? {} : { rules: Object.freeze(rules) },
928
+ ...globalCss.length === 0 ? {} : { globalCss: Object.freeze(globalCss) }
929
+ });
930
+ };
931
+ /** A pseudo-class/element rule, e.g. `Style.pseudo(':hover', { color: 'red' })`. */
932
+ const pseudo = (suffix, declarations) => Object.freeze({
933
+ classes: empty.classes,
934
+ style: empty.style,
935
+ rules: Object.freeze([pseudo$1(suffix, declarations)])
936
+ });
937
+ /** An at-rule, e.g. `Style.media('(min-width: 40rem)', { color: 'red' })`. */
938
+ const media = (query, declarations) => Object.freeze({
939
+ classes: empty.classes,
940
+ style: empty.style,
941
+ rules: Object.freeze([media$1(query, declarations)])
942
+ });
943
+ /** An at-rule, e.g. `Style.supports('(display: grid)', { display: 'grid' })`. */
944
+ const supports = (condition, declarations) => Object.freeze({
945
+ classes: empty.classes,
946
+ style: empty.style,
947
+ rules: Object.freeze([supports$1(condition, declarations)])
948
+ });
949
+ /** A container query, e.g. `Style.container('(min-width: 30rem)', {...})`. */
950
+ const container = (condition, declarations) => Object.freeze({
951
+ classes: empty.classes,
952
+ style: empty.style,
953
+ rules: Object.freeze([container$1(condition, declarations)])
954
+ });
955
+ /** A nested selector relative to the generated class, e.g. `Style.nest('> span', {...})`. */
956
+ const nest = (selector, declarations) => Object.freeze({
957
+ classes: empty.classes,
958
+ style: empty.style,
959
+ rules: Object.freeze([nest$1(selector, declarations)])
960
+ });
961
+ /**
962
+ * A deterministic `@keyframes` block. Compose `style` where the animation is
963
+ * declared and reference `name` in an `animation` declaration.
964
+ */
965
+ const keyframes = (frames) => {
966
+ const compiled = keyframes$1(frames);
967
+ return Object.freeze({
968
+ name: compiled.name,
969
+ style: Object.freeze({
970
+ classes: empty.classes,
971
+ style: empty.style,
972
+ globalCss: Object.freeze([compiled.css])
973
+ })
974
+ });
975
+ };
976
+ /** Raw class-independent CSS (a layer, a global rule). Prefer typed helpers. */
977
+ const global = (css) => Object.freeze({
978
+ classes: empty.classes,
979
+ style: empty.style,
980
+ globalCss: Object.freeze([css])
981
+ });
982
+ /** A boolean known at authoring time. */
983
+ const when = (condition, piece) => condition ? piece : empty;
984
+ /** A condition read from the view input at render time. The piece applies when
985
+ * `predicate` returns true for the input the view was rendered with. */
986
+ const whenInput = (predicate, piece) => Object.freeze({
987
+ classes: empty.classes,
988
+ style: empty.style,
989
+ conditions: Object.freeze([{
990
+ predicate: (input) => predicate(input),
991
+ piece
992
+ }])
993
+ });
994
+ /** Fold every active condition (recursively) into a condition-free style. */
995
+ const resolveStyle = (style, input) => {
996
+ const active = (style.conditions ?? []).filter((condition) => condition.predicate(input)).map((condition) => resolveStyle(condition.piece, input));
997
+ return Object.freeze({
998
+ classes: Object.freeze([...style.classes, ...active.flatMap((piece) => piece.classes)]),
999
+ style: Object.freeze(Object.assign(Object.create(null), style.style, ...active.map((piece) => piece.style)))
1000
+ });
1001
+ };
1002
+ const hasConditionalRules = (style) => (style.conditions ?? []).some((condition) => (condition.piece.rules ?? []).length > 0 || hasConditionalRules(condition.piece));
1003
+ /** Global CSS is emitted whether or not its condition is active. */
1004
+ const collectGlobalCss = (style) => [...style.globalCss ?? [], ...(style.conditions ?? []).flatMap((condition) => collectGlobalCss(condition.piece))];
1005
+ /** A rule-bearing style gets one deterministic class and its CSS text. */
1006
+ const compileStyle = (style) => {
1007
+ const rules = style.rules ?? [];
1008
+ const globalRules = collectGlobalCss(style);
1009
+ const generated = rules.length === 0 ? void 0 : className(rules);
1010
+ return {
1011
+ classes: generated === void 0 ? style.classes : Object.freeze([...style.classes, generated]),
1012
+ style: style.style,
1013
+ ...generated === void 0 ? {} : {
1014
+ css: css(generated, rules),
1015
+ ruleClass: generated
1016
+ },
1017
+ ...globalRules.length === 0 ? {} : { globalRules }
1018
+ };
1019
+ };
1020
+ /** A rule's class is static while a `whenInput` condition is not, so they cannot combine. */
1021
+ const assertRulesSupported = (style) => {
1022
+ if (!hasConditionalRules(style)) return;
1023
+ throw new DiagnosticError({
1024
+ source: "mixins",
1025
+ code: "style:conditional-rules-unsupported",
1026
+ severity: "error",
1027
+ message: "Style.pseudo/media may not appear inside Style.whenInput"
1028
+ });
1029
+ };
1030
+ /**
1031
+ * A static style stays static data; a style with input conditions compiles to a
1032
+ * message-free `InputContribution`, so it still attaches to any view.
1033
+ */
1034
+ const contributionFrom = (style, compiled) => {
1035
+ const globalCss = compiled.globalRules?.join("");
1036
+ const attributes = {
1037
+ classes: compiled.classes,
1038
+ style: compiled.style,
1039
+ ...compiled.css === void 0 ? {} : { css: compiled.css },
1040
+ ...globalCss === void 0 ? {} : { globalCss }
1041
+ };
1042
+ if ((style.conditions ?? []).length === 0) return Object.freeze(attributes);
1043
+ const contribution = (context) => {
1044
+ const resolved = resolveStyle({
1045
+ ...style,
1046
+ classes: compiled.classes
1047
+ }, context.input);
1048
+ return Object.freeze({
1049
+ classes: resolved.classes,
1050
+ style: resolved.style,
1051
+ ...compiled.css === void 0 ? {} : { css: compiled.css },
1052
+ ...globalCss === void 0 ? {} : { globalCss }
1053
+ });
1054
+ };
1055
+ return contribution;
1056
+ };
1057
+ const forSlots = (slots) => (pieces, options) => {
1058
+ const known = slots;
1059
+ const contributions = Object.create(null);
1060
+ const rules = [];
1061
+ const globalRules = [];
1062
+ let css = "";
1063
+ let globalCss = "";
1064
+ for (const [key, piece] of Object.entries(pieces)) {
1065
+ if (!Object.hasOwn(known, key)) throw new DiagnosticError({
1066
+ source: "mixins",
1067
+ code: "mixins:unknown-slot",
1068
+ severity: "error",
1069
+ message: `Style targets unknown slot "${key}"`,
1070
+ slot: key
1071
+ });
1072
+ if (known[key]?.hidden === true) throw new DiagnosticError({
1073
+ source: "mixins",
1074
+ code: "mixins:hidden-slot",
1075
+ severity: "error",
1076
+ message: `Style targets hidden slot "${key}"`,
1077
+ slot: key
1078
+ });
1079
+ if (piece !== void 0) {
1080
+ assertRulesSupported(piece);
1081
+ const compiled = compileStyle(piece);
1082
+ contributions[key] = contributionFrom(piece, compiled);
1083
+ if (compiled.ruleClass !== void 0 && compiled.css !== void 0) {
1084
+ rules.push({
1085
+ className: compiled.ruleClass,
1086
+ css: compiled.css
1087
+ });
1088
+ css += compiled.css;
1089
+ }
1090
+ if (compiled.globalRules !== void 0) {
1091
+ globalRules.push(...compiled.globalRules);
1092
+ globalCss += compiled.globalRules.join("");
1093
+ }
1094
+ }
1095
+ }
1096
+ return Object.freeze({
1097
+ ...options?.name === void 0 ? {} : { name: options.name },
1098
+ pieces,
1099
+ mixin: dynamic(options?.name ?? "Style", contributions),
1100
+ css,
1101
+ globalCss,
1102
+ rules: Object.freeze(rules),
1103
+ globalRules: Object.freeze(globalRules)
1104
+ });
1105
+ };
1106
+ /** Deduplicated global then scoped CSS for one `<style>` block, first seen wins. */
1107
+ const stylesheet = (...styles) => {
1108
+ const scoped = /* @__PURE__ */ new Map();
1109
+ const global = /* @__PURE__ */ new Set();
1110
+ for (const style of styles) {
1111
+ for (const rule of style.rules) if (!scoped.has(rule.className)) scoped.set(rule.className, rule.css);
1112
+ for (const rule of style.globalRules) global.add(rule);
1113
+ }
1114
+ return [...global, ...scoped.values()].join("");
1115
+ };
1116
+ const attach = (style) => (view) => attach$2(style.mixin)(view);
1117
+ /** A recipe is just Style data: base, one piece per selected variant, then any
1118
+ * matching compound. `compound.when` is keyed by the recipe's variants, so a
1119
+ * typo is a compile error rather than a silently dead combination. */
1120
+ const recipe = (def) => (selection) => {
1121
+ const pieces = [];
1122
+ if (def.base !== void 0) pieces.push(def.base);
1123
+ const effective = {};
1124
+ for (const [variant, values] of Object.entries(def.variants)) {
1125
+ const chosen = selection[variant] ?? def.defaults?.[variant];
1126
+ if (chosen === void 0) continue;
1127
+ effective[variant] = chosen;
1128
+ const piece = values[chosen];
1129
+ if (piece !== void 0) pieces.push(piece);
1130
+ }
1131
+ for (const compound of def.compound ?? []) if (Object.entries(compound.when).every(([variant, value]) => effective[variant] === value)) pieces.push(compound.style);
1132
+ return compose(...pieces);
1133
+ };
1134
+ const Style = {
1135
+ class: classPiece,
1136
+ inline,
1137
+ compose,
1138
+ when,
1139
+ whenInput,
1140
+ pseudo,
1141
+ media,
1142
+ supports,
1143
+ container,
1144
+ nest,
1145
+ keyframes,
1146
+ global,
1147
+ empty,
1148
+ forSlots,
1149
+ attach,
1150
+ recipe,
1151
+ stylesheet
1152
+ };
1153
+ //#endregion
1154
+ //#region src/theme.ts
1155
+ const VAR_PREFIX = "--fk";
1156
+ const define = (tokens) => Object.freeze(Object.fromEntries(Object.entries(tokens).map(([group, names]) => [group, Object.freeze({ ...names })])));
1157
+ const variable = (_theme, group, name) => `var(${VAR_PREFIX}-${group}-${name})`;
1158
+ const variables = (theme) => {
1159
+ const style = {};
1160
+ for (const [group, names] of Object.entries(theme)) for (const [name, value] of Object.entries(names)) style[`${VAR_PREFIX}-${group}-${name}`] = value;
1161
+ return inline(style);
1162
+ };
1163
+ const Theme = {
1164
+ define,
1165
+ variable,
1166
+ variables
1167
+ };
1168
+ //#endregion
1169
+ export { a11y_exports as A11y, attr_exports as Attr, behavior_exports as Behavior, capability_exports as Capability, diagnostics_exports as Diagnostics, event_exports as Event, metadataToken_exports as MetadataToken, mixin_exports as Mixin, requirement_exports as Requirement, resolver_exports as Resolver, slot_exports as Slot, slotView_exports as SlotView, slots_exports as Slots, Style, Theme };
1170
+
1171
+ //# sourceMappingURL=index.mjs.map