foldkit-mixins 0.2.0 → 0.4.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/README.md +472 -123
- package/dist/core-B86QnDhB.d.mts +40 -0
- package/dist/core-B86QnDhB.d.mts.map +1 -0
- package/dist/core-izIY2GSX.mjs +53 -0
- package/dist/core-izIY2GSX.mjs.map +1 -0
- package/dist/defaults.d.mts +27 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/defaults.mjs +71 -0
- package/dist/defaults.mjs.map +1 -0
- package/dist/diagnostics-YJ7991-A.mjs +15 -0
- package/dist/diagnostics-YJ7991-A.mjs.map +1 -0
- package/dist/index.d.mts +264 -86
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +533 -247
- package/dist/index.mjs.map +1 -1
- package/dist/layers-CJS5d1i7.mjs +197 -0
- package/dist/layers-CJS5d1i7.mjs.map +1 -0
- package/dist/layers.d.mts +47 -0
- package/dist/layers.d.mts.map +1 -0
- package/dist/layers.mjs +2 -0
- package/dist/layout.d.mts +114 -0
- package/dist/layout.d.mts.map +1 -0
- package/dist/layout.mjs +154 -0
- package/dist/layout.mjs.map +1 -0
- package/dist/prose.d.mts +24 -0
- package/dist/prose.d.mts.map +1 -0
- package/dist/prose.mjs +57 -0
- package/dist/prose.mjs.map +1 -0
- package/dist/styleValue--iQMTcPn.mjs +242 -0
- package/dist/styleValue--iQMTcPn.mjs.map +1 -0
- package/dist/styleValue-C9vAKt7A.d.mts +77 -0
- package/dist/styleValue-C9vAKt7A.d.mts.map +1 -0
- package/dist/theme.d.mts +412 -0
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +278 -0
- package/dist/theme.mjs.map +1 -0
- package/package.json +32 -7
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { n as diagnostics_exports, t as DiagnosticError } from "./diagnostics-YJ7991-A.mjs";
|
|
3
|
+
import { a as isUnordered, i as declaredNames, o as layerOf, s as topLevelBlocks, t as Layers } from "./layers-CJS5d1i7.mjs";
|
|
4
|
+
import { _ as supports, a as empty$1, b as className, c as grid, d as media, f as nest, g as states, h as self, i as container, l as inline, m as responsive, n as classPiece, o as enter, p as pseudo, r as compose$1, s as global, t as allowDiscrete, u as keyframes, v as vars, x as css, y as viewTransitionName } from "./styleValue--iQMTcPn.mjs";
|
|
5
|
+
import { t as Theme } from "./core-izIY2GSX.mjs";
|
|
3
6
|
import { inertHtml } from "foldkit/html";
|
|
7
|
+
import { Option, Stream } from "effect";
|
|
4
8
|
//#region src/metadataToken.ts
|
|
5
9
|
var metadataToken_exports = /* @__PURE__ */ __exportAll({
|
|
6
10
|
MetadataTokenTypeId: () => MetadataTokenTypeId,
|
|
7
|
-
is: () => is$
|
|
11
|
+
is: () => is$6,
|
|
8
12
|
make: () => make$6,
|
|
9
13
|
nameOf: () => nameOf
|
|
10
14
|
});
|
|
@@ -25,8 +29,8 @@ const make$6 = (kind, name) => {
|
|
|
25
29
|
name
|
|
26
30
|
};
|
|
27
31
|
};
|
|
28
|
-
const is$
|
|
29
|
-
const nameOf = (value) => is$
|
|
32
|
+
const is$6 = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, MetadataTokenTypeId);
|
|
33
|
+
const nameOf = (value) => is$6(value) ? value.name : value;
|
|
30
34
|
//#endregion
|
|
31
35
|
//#region src/capability.ts
|
|
32
36
|
/**
|
|
@@ -44,14 +48,14 @@ var capability_exports = /* @__PURE__ */ __exportAll({
|
|
|
44
48
|
TextInput: () => TextInput,
|
|
45
49
|
describe: () => describe$5,
|
|
46
50
|
extendsCapability: () => extendsCapability,
|
|
47
|
-
is: () => is$
|
|
51
|
+
is: () => is$5,
|
|
48
52
|
make: () => make$5,
|
|
49
53
|
names: () => names,
|
|
50
54
|
satisfies: () => satisfies
|
|
51
55
|
});
|
|
52
56
|
const parentsByName = /* @__PURE__ */ new Map();
|
|
53
57
|
const registry = /* @__PURE__ */ new Map();
|
|
54
|
-
const is$
|
|
58
|
+
const is$5 = (value) => is$6(value) && value.kind === "element.capability";
|
|
55
59
|
const make$5 = (name, options) => {
|
|
56
60
|
if (name === "") throw new Error("Capability name must be non-empty");
|
|
57
61
|
const parents = options?.extends ?? [];
|
|
@@ -206,10 +210,10 @@ var attr_exports = /* @__PURE__ */ __exportAll({
|
|
|
206
210
|
Value: () => Value,
|
|
207
211
|
describe: () => describe$4,
|
|
208
212
|
equals: () => equals$1,
|
|
209
|
-
is: () => is$
|
|
213
|
+
is: () => is$4,
|
|
210
214
|
make: () => make$4
|
|
211
215
|
});
|
|
212
|
-
const is$
|
|
216
|
+
const is$4 = (value) => is$6(value) && value.kind === "view.attribute";
|
|
213
217
|
const make$4 = (name) => make$6("view.attribute", name);
|
|
214
218
|
const equals$1 = (left, right) => left.name === right.name;
|
|
215
219
|
const describe$4 = (attr) => ({ name: attr.name });
|
|
@@ -223,23 +227,44 @@ const AriaDisabled = make$4("aria-disabled");
|
|
|
223
227
|
const Disabled = make$4("disabled");
|
|
224
228
|
const Value = make$4("value");
|
|
225
229
|
//#endregion
|
|
226
|
-
//#region src/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
//#region src/attribute.ts
|
|
231
|
+
/** The brand `childAttribute.d.ts` stamps; Foldkit's guard is not exported. */
|
|
232
|
+
const CHILD_ATTRIBUTE_BRAND = "__childAttribute";
|
|
233
|
+
const isChildAttribute = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, CHILD_ATTRIBUTE_BRAND);
|
|
234
|
+
const isTagged = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, "_tag") && typeof value._tag === "string";
|
|
235
|
+
/** `Class` carries no Message, so the inert builder is the honest constructor. */
|
|
236
|
+
const classAttribute = (value) => inertHtml.Class(value);
|
|
237
|
+
const styleAttribute = (value) => inertHtml.Style(value);
|
|
238
|
+
/**
|
|
239
|
+
* `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing
|
|
240
|
+
* mount is built directly. The shape is the same tagged value `h.OnMount`
|
|
241
|
+
* produces (`{ _tag: 'OnMount', action }`).
|
|
242
|
+
*/
|
|
243
|
+
const mountAttribute = (action) => ({
|
|
244
|
+
_tag: "OnMount",
|
|
245
|
+
action
|
|
246
|
+
});
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/attributes.ts
|
|
249
|
+
var attributes_exports = /* @__PURE__ */ __exportAll({
|
|
250
|
+
filter: () => filter,
|
|
251
|
+
find: () => find,
|
|
252
|
+
tagOf: () => tagOf
|
|
253
|
+
});
|
|
254
|
+
/** The tag of one bundle entry; `undefined` for an opaque `ChildAttribute`. */
|
|
255
|
+
const tagOf = (attribute) => isTagged(attribute) ? attribute._tag : void 0;
|
|
256
|
+
const hasTag = (tag) => (attribute) => tagOf(attribute) === tag;
|
|
257
|
+
/** The first attribute with `tag`, typed as that variant. */
|
|
258
|
+
const find = (attributes, tag) => attributes.find(hasTag(tag));
|
|
259
|
+
/** Every attribute with `tag`, in bundle order. */
|
|
260
|
+
const filter = (attributes, tag) => attributes.filter(hasTag(tag));
|
|
236
261
|
//#endregion
|
|
237
262
|
//#region src/mixin.ts
|
|
238
263
|
var mixin_exports = /* @__PURE__ */ __exportAll({
|
|
239
|
-
compose: () => compose
|
|
264
|
+
compose: () => compose,
|
|
240
265
|
contributionsFor: () => contributionsFor,
|
|
241
266
|
dynamic: () => dynamic,
|
|
242
|
-
empty: () => empty
|
|
267
|
+
empty: () => empty,
|
|
243
268
|
evaluate: () => evaluate,
|
|
244
269
|
isDynamic: () => isDynamic,
|
|
245
270
|
make: () => make$3
|
|
@@ -273,8 +298,8 @@ const dynamic = (name, contributions) => Object.freeze({
|
|
|
273
298
|
name,
|
|
274
299
|
contributions: Object.freeze({ ...contributions })
|
|
275
300
|
});
|
|
276
|
-
const empty
|
|
277
|
-
const compose
|
|
301
|
+
const empty = () => make$3("Empty", {});
|
|
302
|
+
const compose = (...mixins) => {
|
|
278
303
|
const merged = Object.create(null);
|
|
279
304
|
for (const mixin of mixins) for (const [slot, contribution] of Object.entries(mixin.contributions)) {
|
|
280
305
|
if (contribution === void 0) continue;
|
|
@@ -290,24 +315,6 @@ const contributionsFor = (mixin, slot) => mixin.contributions[slot];
|
|
|
290
315
|
/** Ported from `effect-atom-jsx/src/View.ts` `pipeSelf`. */
|
|
291
316
|
const pipeSelf = (self, fns) => fns.reduce((acc, fn) => fn(acc), self);
|
|
292
317
|
//#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
318
|
//#region src/resolver.ts
|
|
312
319
|
/**
|
|
313
320
|
* The deterministic resolver. `resolve` is pure: it decomposes the base
|
|
@@ -351,6 +358,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
351
358
|
const classes = [];
|
|
352
359
|
const classSeen = /* @__PURE__ */ new Set();
|
|
353
360
|
const style = /* @__PURE__ */ new Map();
|
|
361
|
+
const styleOwners = /* @__PURE__ */ new Map();
|
|
354
362
|
const mounts = [];
|
|
355
363
|
const mountNames = /* @__PURE__ */ new Map();
|
|
356
364
|
const preserved = [];
|
|
@@ -365,6 +373,17 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
365
373
|
classSeen.add(token);
|
|
366
374
|
classes.push(token);
|
|
367
375
|
};
|
|
376
|
+
const writeStyle = (property, value, writer) => {
|
|
377
|
+
if (writer !== "base" && protectedStyle.has(property)) fail("mixins:protected-style-property", `slot "${slot ?? "?"}" protects style property "${property}"`, { property });
|
|
378
|
+
const owner = styleOwners.get(property);
|
|
379
|
+
if (writer === "behavior" && owner !== void 0 || writer === "style" && owner === "behavior") fail("mixins:style-property-conflict", `two owners for style property "${property}": ${owner === "base" ? "the view" : owner === "style" ? "a Style" : "a Behavior"} already sets it`, {
|
|
380
|
+
property,
|
|
381
|
+
owner,
|
|
382
|
+
writer
|
|
383
|
+
});
|
|
384
|
+
if (owner === void 0 || writer === "behavior") styleOwners.set(property, writer);
|
|
385
|
+
style.set(property, value);
|
|
386
|
+
};
|
|
368
387
|
const addMount = (action) => {
|
|
369
388
|
const count = (mountNames.get(action.name) ?? 0) + 1;
|
|
370
389
|
mountNames.set(action.name, count);
|
|
@@ -392,7 +411,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
392
411
|
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
393
412
|
return;
|
|
394
413
|
case "Style":
|
|
395
|
-
for (const [property, value] of Object.entries(attribute.value))
|
|
414
|
+
for (const [property, value] of Object.entries(attribute.value)) writeStyle(property, value, "base");
|
|
396
415
|
return;
|
|
397
416
|
case "OnMount":
|
|
398
417
|
addMount(attribute.action);
|
|
@@ -415,10 +434,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
415
434
|
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
416
435
|
return;
|
|
417
436
|
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
|
-
}
|
|
437
|
+
for (const [property, value] of Object.entries(attribute.value)) writeStyle(property, value, "behavior");
|
|
422
438
|
return;
|
|
423
439
|
case "OnMount":
|
|
424
440
|
addMount(attribute.action);
|
|
@@ -456,10 +472,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
456
472
|
for (const attribute of base ?? []) addBase(attribute);
|
|
457
473
|
for (const contribution of contributions) {
|
|
458
474
|
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
|
-
}
|
|
475
|
+
for (const [property, value] of Object.entries(contribution.style ?? {})) writeStyle(property, value, "style");
|
|
463
476
|
for (const attribute of contribution.attributes ?? []) applyMixinAttribute(attribute);
|
|
464
477
|
for (const mount of contribution.mounts ?? []) addMount(mount);
|
|
465
478
|
}
|
|
@@ -490,11 +503,19 @@ const composeMounts = (mounts, slot) => {
|
|
|
490
503
|
};
|
|
491
504
|
//#endregion
|
|
492
505
|
//#region src/slotView.ts
|
|
506
|
+
/**
|
|
507
|
+
* `SlotView` is the structural equivalent of a Surface: a pure Foldkit view
|
|
508
|
+
* that publishes typed Slots and lets Mixins attach without forking it. It
|
|
509
|
+
* owns no state and runs no Effects. Attached Mixins are resolved into
|
|
510
|
+
* ordinary Foldkit attributes per slot, using the view's own `h` so Message
|
|
511
|
+
* capability masking is preserved.
|
|
512
|
+
*/
|
|
493
513
|
var slotView_exports = /* @__PURE__ */ __exportAll({
|
|
494
514
|
attach: () => attach$2,
|
|
495
515
|
buildersFor: () => buildersFor,
|
|
496
|
-
define: () => define$
|
|
497
|
-
forMessages: () => forMessages
|
|
516
|
+
define: () => define$1,
|
|
517
|
+
forMessages: () => forMessages,
|
|
518
|
+
inertBuilder: () => inertBuilder
|
|
498
519
|
});
|
|
499
520
|
/** Build one `attrs` resolver per published slot, evaluating Mixins lazily. */
|
|
500
521
|
const buildersFor = (slots, mixins, context) => {
|
|
@@ -504,13 +525,14 @@ const buildersFor = (slots, mixins, context) => {
|
|
|
504
525
|
const slot = source[name];
|
|
505
526
|
if (slot === void 0) continue;
|
|
506
527
|
const protection = slot.protected;
|
|
507
|
-
builders[name] = { attrs: (base) => {
|
|
528
|
+
builders[name] = { attrs: (base, item) => {
|
|
508
529
|
const contributions = [];
|
|
509
530
|
for (const mixin of mixins) {
|
|
510
531
|
const contribution = mixin.contributions[name];
|
|
511
532
|
if (contribution !== void 0) contributions.push(evaluate(contribution, {
|
|
512
533
|
input: context.input,
|
|
513
|
-
h: context.h
|
|
534
|
+
h: context.h,
|
|
535
|
+
...item === void 0 ? {} : { item }
|
|
514
536
|
}));
|
|
515
537
|
}
|
|
516
538
|
return resolve(base, contributions, {
|
|
@@ -547,7 +569,14 @@ const makeView = (name, slots, mixins, render) => {
|
|
|
547
569
|
* does not name the missing annotation. `forMessages<Message>()` fixes the
|
|
548
570
|
* Message universe up front instead, and leaves `h` contextually typed.
|
|
549
571
|
*/
|
|
550
|
-
const define$
|
|
572
|
+
const define$1 = (slots, render, options) => makeView(options?.name, slots, [], render);
|
|
573
|
+
/**
|
|
574
|
+
* Foldkit's `inertHtml` typed for a Message universe, for rendering a view
|
|
575
|
+
* outside a runtime (tests, demos, static description). `inertHtml` is
|
|
576
|
+
* `HtmlBuilder<never>`, and the builder is invariant in `Message`, so this is
|
|
577
|
+
* the one cast: sound because inert handlers are never dispatched.
|
|
578
|
+
*/
|
|
579
|
+
const inertBuilder = () => inertHtml;
|
|
551
580
|
/**
|
|
552
581
|
* Binds the view constructors to one Message universe, so the render callback
|
|
553
582
|
* no longer has to annotate `h` to pin it. `Input` is still inferred from the
|
|
@@ -562,7 +591,7 @@ const define$2 = (slots, render, options) => makeView(options?.name, slots, [],
|
|
|
562
591
|
* )
|
|
563
592
|
* ```
|
|
564
593
|
*/
|
|
565
|
-
const forMessages = () => ({ define: define$
|
|
594
|
+
const forMessages = () => ({ define: define$1 });
|
|
566
595
|
function attach$2(mixin) {
|
|
567
596
|
return (view) => makeView(view.name, view.slots, [...view.mixins, mixin], view.render);
|
|
568
597
|
}
|
|
@@ -611,9 +640,10 @@ const forSlots$1 = (slots) => (spec, options) => {
|
|
|
611
640
|
contributions[name] = (context) => ({
|
|
612
641
|
...attributes === void 0 ? {} : { attributes: attributes({
|
|
613
642
|
input: context.input,
|
|
614
|
-
h: context.h
|
|
643
|
+
h: context.h,
|
|
644
|
+
...context.item === void 0 ? {} : { item: context.item }
|
|
615
645
|
}) },
|
|
616
|
-
...mount === void 0 ? {} : { mounts: [mount(context.input)] }
|
|
646
|
+
...mount === void 0 ? {} : { mounts: [mount(context.input, context.item)] }
|
|
617
647
|
});
|
|
618
648
|
}
|
|
619
649
|
return Object.freeze({
|
|
@@ -636,6 +666,185 @@ const Behavior = {
|
|
|
636
666
|
attach: attach$1
|
|
637
667
|
};
|
|
638
668
|
//#endregion
|
|
669
|
+
//#region src/behaviors/collection.ts
|
|
670
|
+
var collection_exports = /* @__PURE__ */ __exportAll({
|
|
671
|
+
behavior: () => behavior$4,
|
|
672
|
+
of: () => of
|
|
673
|
+
});
|
|
674
|
+
/** Describes `items` once. Two items with one id are refused, since an id is what
|
|
675
|
+
* `aria-activedescendant`, `aria-controls`, and a keyed row rely on. */
|
|
676
|
+
const of = (items, describe) => {
|
|
677
|
+
const ids = [];
|
|
678
|
+
const indexById = /* @__PURE__ */ new Map();
|
|
679
|
+
const disabled = [];
|
|
680
|
+
const enabled = [];
|
|
681
|
+
items.forEach((item, index) => {
|
|
682
|
+
const id = describe.id(item, index);
|
|
683
|
+
const seen = indexById.get(id);
|
|
684
|
+
if (seen !== void 0) throw new DiagnosticError({
|
|
685
|
+
source: "mixins",
|
|
686
|
+
code: "mixins:duplicate-item-id",
|
|
687
|
+
severity: "error",
|
|
688
|
+
message: `Collection items ${seen} and ${index} share the id "${id}"`,
|
|
689
|
+
details: {
|
|
690
|
+
id,
|
|
691
|
+
indices: [seen, index]
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
indexById.set(id, index);
|
|
695
|
+
ids.push(id);
|
|
696
|
+
const isDisabled = describe.disabled?.(item, index) ?? false;
|
|
697
|
+
disabled.push(isDisabled);
|
|
698
|
+
if (!isDisabled) enabled.push(index);
|
|
699
|
+
});
|
|
700
|
+
const size = items.length;
|
|
701
|
+
return Object.freeze({
|
|
702
|
+
size,
|
|
703
|
+
ids: Object.freeze(ids),
|
|
704
|
+
at: (index) => items[index],
|
|
705
|
+
indexOf: (id) => indexById.get(id) ?? -1,
|
|
706
|
+
isDisabled: (index) => disabled[index] ?? false,
|
|
707
|
+
enabled: Object.freeze(enabled),
|
|
708
|
+
slotItem: (index) => ({
|
|
709
|
+
index,
|
|
710
|
+
id: ids[index] ?? String(index),
|
|
711
|
+
count: size
|
|
712
|
+
})
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Writes each item's identity and position: `id` from the described id,
|
|
717
|
+
* `aria-disabled` for a disabled item, and `aria-posinset` and `aria-setsize`
|
|
718
|
+
* on request. Reads the item context the view passes to `attrs`; with none it
|
|
719
|
+
* contributes nothing, so a slot rendered once is left alone.
|
|
720
|
+
*/
|
|
721
|
+
const behavior$4 = (slots) => (options) => forSlots$1(slots)({ [options.item]: slot({ attributes: ({ input, h, item }) => {
|
|
722
|
+
if (item === void 0) return [];
|
|
723
|
+
const items = options.items(input);
|
|
724
|
+
const id = item.id ?? items.ids[item.index];
|
|
725
|
+
return [
|
|
726
|
+
...options.ids === false || id === void 0 ? [] : [h.Id(id)],
|
|
727
|
+
...items.isDisabled(item.index) ? [h.AriaDisabled(true)] : [],
|
|
728
|
+
...options.posInSet === true ? [h.AriaPosinset(item.index + 1), h.AriaSetsize(item.count ?? items.size)] : []
|
|
729
|
+
];
|
|
730
|
+
} }) }, { name: "Collection" });
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/behaviors/disclosure.ts
|
|
733
|
+
var disclosure_exports = /* @__PURE__ */ __exportAll({ behavior: () => behavior$3 });
|
|
734
|
+
const behavior$3 = (slots) => (options) => forSlots$1(slots)({
|
|
735
|
+
[options.trigger]: slot({
|
|
736
|
+
requires: { capability: Interactive },
|
|
737
|
+
attributes: ({ input, h }) => [h.AriaExpanded(options.open(input)), h.AriaControls(options.id(input))]
|
|
738
|
+
}),
|
|
739
|
+
[options.content]: slot({
|
|
740
|
+
requires: { capability: Container },
|
|
741
|
+
attributes: ({ input, h }) => [h.Id(options.id(input)), h.Hidden(!options.open(input))]
|
|
742
|
+
})
|
|
743
|
+
}, { name: "Disclosure" });
|
|
744
|
+
//#endregion
|
|
745
|
+
//#region src/behaviors/field-association.ts
|
|
746
|
+
var field_association_exports = /* @__PURE__ */ __exportAll({
|
|
747
|
+
behavior: () => behavior$2,
|
|
748
|
+
ids: () => ids
|
|
749
|
+
});
|
|
750
|
+
/** The ids one base id yields, for a view that renders these elements itself. */
|
|
751
|
+
const ids = (id) => ({
|
|
752
|
+
control: id,
|
|
753
|
+
label: `${id}-label`,
|
|
754
|
+
description: `${id}-description`,
|
|
755
|
+
error: `${id}-error`
|
|
756
|
+
});
|
|
757
|
+
const behavior$2 = (slots) => (options) => forSlots$1(slots)({
|
|
758
|
+
[options.control]: slot({
|
|
759
|
+
requires: { capability: Interactive },
|
|
760
|
+
attributes: ({ input, h }) => {
|
|
761
|
+
const names = ids(options.id(input));
|
|
762
|
+
const invalid = options.invalid?.(input) === true;
|
|
763
|
+
const describedBy = [...options.description === void 0 ? [] : [names.description], ...options.error !== void 0 && invalid ? [names.error] : []];
|
|
764
|
+
return [
|
|
765
|
+
h.Id(names.control),
|
|
766
|
+
h.AriaLabelledBy(names.label),
|
|
767
|
+
...describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(" "))],
|
|
768
|
+
...invalid ? [h.AriaInvalid(true)] : [],
|
|
769
|
+
...options.required?.(input) === true ? [h.AriaRequired(true)] : []
|
|
770
|
+
];
|
|
771
|
+
}
|
|
772
|
+
}),
|
|
773
|
+
[options.label]: slot({ attributes: ({ input, h }) => {
|
|
774
|
+
const names = ids(options.id(input));
|
|
775
|
+
return [h.Id(names.label), h.For(names.control)];
|
|
776
|
+
} }),
|
|
777
|
+
...options.description === void 0 ? {} : { [options.description]: slot({ attributes: ({ input, h }) => [h.Id(ids(options.id(input)).description)] }) },
|
|
778
|
+
...options.error === void 0 ? {} : { [options.error]: slot({ attributes: ({ input, h }) => [h.Id(ids(options.id(input)).error)] }) }
|
|
779
|
+
}, { name: "FieldAssociation" });
|
|
780
|
+
//#endregion
|
|
781
|
+
//#region src/behaviors/spin-value.ts
|
|
782
|
+
/**
|
|
783
|
+
* A number stepped by keys: ArrowUp and ArrowDown by `step`, PageUp and
|
|
784
|
+
* PageDown by `page`, Home and End to the bounds, each clamped, each
|
|
785
|
+
* default-prevented. The value is the parent's; a key yields the Message the
|
|
786
|
+
* caller builds from the next value. Writes the spinbutton role and its
|
|
787
|
+
* `aria-value*`. The floor is `<input type="number">`; a press-and-hold
|
|
788
|
+
* repeat and a wheel are not handled, since Foldkit's wheel attribute carries
|
|
789
|
+
* no delta and a repeat is a timer the Model would have to own.
|
|
790
|
+
*/
|
|
791
|
+
var spin_value_exports = /* @__PURE__ */ __exportAll({
|
|
792
|
+
behavior: () => behavior$1,
|
|
793
|
+
spin: () => spin
|
|
794
|
+
});
|
|
795
|
+
const clamp = (value, bounds) => Math.min(bounds.max ?? Number.POSITIVE_INFINITY, Math.max(bounds.min ?? Number.NEGATIVE_INFINITY, value));
|
|
796
|
+
/** The value the key moves to, or `undefined` when the key is not a spin key or a chord. */
|
|
797
|
+
const spin = (value, key, modifiers, bounds) => {
|
|
798
|
+
if (modifiers.ctrlKey || modifiers.altKey || modifiers.metaKey) return void 0;
|
|
799
|
+
const step = bounds.step ?? 1;
|
|
800
|
+
const page = bounds.page ?? step * 10;
|
|
801
|
+
switch (key) {
|
|
802
|
+
case "ArrowUp": return clamp(value + step, bounds);
|
|
803
|
+
case "ArrowDown": return clamp(value - step, bounds);
|
|
804
|
+
case "PageUp": return clamp(value + page, bounds);
|
|
805
|
+
case "PageDown": return clamp(value - page, bounds);
|
|
806
|
+
case "Home": return bounds.min;
|
|
807
|
+
case "End": return bounds.max;
|
|
808
|
+
default: return;
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
const behavior$1 = (slots) => (options) => forSlots$1(slots)({ [options.control]: slot({
|
|
812
|
+
requires: { capability: Focusable },
|
|
813
|
+
attributes: ({ input, h }) => {
|
|
814
|
+
const value = options.value(input);
|
|
815
|
+
return [
|
|
816
|
+
h.Role("spinbutton"),
|
|
817
|
+
h.AriaValuenow(value),
|
|
818
|
+
...options.min === void 0 ? [] : [h.AriaValuemin(options.min)],
|
|
819
|
+
...options.max === void 0 ? [] : [h.AriaValuemax(options.max)],
|
|
820
|
+
...options.text === void 0 ? [] : [h.AriaValuetext(options.text(input))],
|
|
821
|
+
h.OnKeyDownPreventDefault((key, modifiers) => {
|
|
822
|
+
const next = spin(value, key, modifiers, options);
|
|
823
|
+
return next === void 0 || next === value ? Option.none() : Option.some(options.onChange(next));
|
|
824
|
+
})
|
|
825
|
+
];
|
|
826
|
+
}
|
|
827
|
+
}) }, { name: "SpinValue" });
|
|
828
|
+
//#endregion
|
|
829
|
+
//#region src/behaviors/toggle-state.ts
|
|
830
|
+
var toggle_state_exports = /* @__PURE__ */ __exportAll({ behavior: () => behavior });
|
|
831
|
+
const behavior = (slots) => (options) => forSlots$1(slots)({ [options.control]: slot({
|
|
832
|
+
requires: { capability: Interactive },
|
|
833
|
+
attributes: ({ input, h }) => {
|
|
834
|
+
const state = options.state(input);
|
|
835
|
+
return options.as === "checked" ? [h.AriaChecked(state)] : [h.AriaPressed(state === "mixed" ? "mixed" : state ? "true" : "false")];
|
|
836
|
+
}
|
|
837
|
+
}) }, { name: "ToggleState" });
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/behaviors/index.ts
|
|
840
|
+
var behaviors_exports = /* @__PURE__ */ __exportAll({
|
|
841
|
+
Collection: () => collection_exports,
|
|
842
|
+
Disclosure: () => disclosure_exports,
|
|
843
|
+
FieldAssociation: () => field_association_exports,
|
|
844
|
+
SpinValue: () => spin_value_exports,
|
|
845
|
+
ToggleState: () => toggle_state_exports
|
|
846
|
+
});
|
|
847
|
+
//#endregion
|
|
639
848
|
//#region src/event.ts
|
|
640
849
|
/**
|
|
641
850
|
* Slot event tokens. Ported from `effect-atom-jsx/src/View.ts` `Event`, plus
|
|
@@ -656,10 +865,10 @@ var event_exports = /* @__PURE__ */ __exportAll({
|
|
|
656
865
|
Submit: () => Submit,
|
|
657
866
|
describe: () => describe$3,
|
|
658
867
|
equals: () => equals,
|
|
659
|
-
is: () => is$
|
|
868
|
+
is: () => is$3,
|
|
660
869
|
make: () => make$2
|
|
661
870
|
});
|
|
662
|
-
const is$
|
|
871
|
+
const is$3 = (value) => is$6(value) && value.kind === "view.event";
|
|
663
872
|
const make$2 = (name) => make$6("view.event", name);
|
|
664
873
|
const equals = (left, right) => left.name === right.name;
|
|
665
874
|
const describe$3 = (event) => ({ name: event.name });
|
|
@@ -686,16 +895,46 @@ var requirement_exports = /* @__PURE__ */ __exportAll({
|
|
|
686
895
|
Keyboard: () => Keyboard,
|
|
687
896
|
Pointer: () => Pointer,
|
|
688
897
|
describe: () => describe$2,
|
|
689
|
-
is: () => is$
|
|
898
|
+
is: () => is$2,
|
|
690
899
|
make: () => make$1
|
|
691
900
|
});
|
|
692
|
-
const is$
|
|
901
|
+
const is$2 = (value) => is$6(value) && value.kind === "view.requirement";
|
|
693
902
|
const make$1 = (name) => make$6("view.requirement", name);
|
|
694
903
|
const describe$2 = (requirement) => ({ name: requirement.name });
|
|
695
904
|
const Keyboard = make$1("keyboard");
|
|
696
905
|
const Pointer = make$1("pointer");
|
|
697
906
|
const Clipboard = make$1("clipboard");
|
|
698
907
|
//#endregion
|
|
908
|
+
//#region src/selector.ts
|
|
909
|
+
var selector_exports = /* @__PURE__ */ __exportAll({
|
|
910
|
+
attr: () => attr,
|
|
911
|
+
child: () => child,
|
|
912
|
+
descendant: () => descendant,
|
|
913
|
+
is: () => is$1,
|
|
914
|
+
not: () => not,
|
|
915
|
+
sibling: () => sibling,
|
|
916
|
+
siblings: () => siblings
|
|
917
|
+
});
|
|
918
|
+
/**
|
|
919
|
+
* Typed builders for the selector strings `Style.pseudo` and `Style.nest`
|
|
920
|
+
* take, relative to the generated class (`&`). They exist so a recipe does
|
|
921
|
+
* not hand-type `&:not([aria-disabled="true"])` in every entry.
|
|
922
|
+
*/
|
|
923
|
+
/** `&[name]` or `&[name="value"]`. */
|
|
924
|
+
const attr = (name, value) => value === void 0 ? `[${name}]` : `[${name}="${value.replace(/["\\]/g, "\\$&")}"]`;
|
|
925
|
+
/** `&:not(selector)`, for `Style.pseudo`. */
|
|
926
|
+
const not = (selector) => `:not(${selector})`;
|
|
927
|
+
/** `&:is(a, b)`, for `Style.pseudo`. */
|
|
928
|
+
const is$1 = (...selectors) => `:is(${selectors.join(", ")})`;
|
|
929
|
+
/** A direct child, for `Style.nest`. */
|
|
930
|
+
const child = (selector) => `> ${selector}`;
|
|
931
|
+
/** Any descendant, for `Style.nest`. */
|
|
932
|
+
const descendant = (selector) => selector;
|
|
933
|
+
/** The next sibling, for `Style.nest`. */
|
|
934
|
+
const sibling = (selector) => `+ ${selector}`;
|
|
935
|
+
/** Any later sibling, for `Style.nest`. */
|
|
936
|
+
const siblings = (selector) => `~ ${selector}`;
|
|
937
|
+
//#endregion
|
|
699
938
|
//#region src/slot.ts
|
|
700
939
|
var slot_exports = /* @__PURE__ */ __exportAll({
|
|
701
940
|
SlotTypeId: () => SlotTypeId,
|
|
@@ -834,7 +1073,7 @@ const describe$1 = (slot) => {
|
|
|
834
1073
|
*/
|
|
835
1074
|
var slots_exports = /* @__PURE__ */ __exportAll({
|
|
836
1075
|
SlotsTypeId: () => SlotsTypeId,
|
|
837
|
-
define: () => define
|
|
1076
|
+
define: () => define,
|
|
838
1077
|
describe: () => describe,
|
|
839
1078
|
withCapability: () => withCapability
|
|
840
1079
|
});
|
|
@@ -844,7 +1083,7 @@ const toUnnamed = (value, key) => {
|
|
|
844
1083
|
if (typeof value === "object" && value !== null && Object.hasOwn(value, "capability")) return make(value);
|
|
845
1084
|
throw new Error(`Slots.define: "${key}" is not a Slot or slot options object`);
|
|
846
1085
|
};
|
|
847
|
-
const define
|
|
1086
|
+
const define = (spec) => {
|
|
848
1087
|
const proto = Object.getPrototypeOf(spec);
|
|
849
1088
|
if (proto !== Object.prototype && proto !== null) throw new Error("Slots.define: pass a plain object; quote [\"__proto__\"] to use that as a slot name");
|
|
850
1089
|
const contract = Object.create(null);
|
|
@@ -889,177 +1128,95 @@ const withCapability = (contract, capability) => {
|
|
|
889
1128
|
return out;
|
|
890
1129
|
};
|
|
891
1130
|
//#endregion
|
|
892
|
-
//#region src/styleRules.ts
|
|
893
|
-
const rule = (selector, declarations, at) => Object.freeze({
|
|
894
|
-
selector,
|
|
895
|
-
declarations: Object.freeze({ ...declarations }),
|
|
896
|
-
...at === void 0 ? {} : { at }
|
|
897
|
-
});
|
|
898
|
-
const pseudo$1 = (suffix, declarations) => rule(`&${suffix}`, declarations);
|
|
899
|
-
const media$1 = (query, declarations) => rule("&", declarations, `@media ${query}`);
|
|
900
|
-
const supports$1 = (condition, declarations) => rule("&", declarations, `@supports ${condition}`);
|
|
901
|
-
const container$1 = (condition, declarations) => rule("&", declarations, `@container ${condition}`);
|
|
902
|
-
/** A nested selector relative to the class, e.g. `> span` or `[data-open] &`. */
|
|
903
|
-
const nest$1 = (selector, declarations) => rule(`& ${selector}`, declarations);
|
|
904
|
-
/** `gridTemplateColumns` -> `grid-template-columns`; custom properties pass through. */
|
|
905
|
-
const kebab = (property) => property.startsWith("--") ? property : property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
906
|
-
const declarationsText = (declarations) => Object.keys(declarations).sort().map((property) => `${kebab(property)}:${declarations[property]}`).join(";");
|
|
907
|
-
/** Canonical, declaration-sorted, authored-rule-order text for a rule list. */
|
|
908
|
-
const canonical = (rules) => rules.map((entry) => {
|
|
909
|
-
const body = `{${declarationsText(entry.declarations)}}`;
|
|
910
|
-
return entry.at === void 0 ? `${entry.selector}${body}` : `${entry.at}{${entry.selector}${body}}`;
|
|
911
|
-
}).join("");
|
|
912
|
-
const hash = (value) => {
|
|
913
|
-
let state = 2166136261;
|
|
914
|
-
for (let index = 0; index < value.length; index++) {
|
|
915
|
-
state ^= value.charCodeAt(index);
|
|
916
|
-
state = Math.imul(state, 16777619);
|
|
917
|
-
}
|
|
918
|
-
return (state >>> 0).toString(36);
|
|
919
|
-
};
|
|
920
|
-
/** Deterministic `@keyframes`: step order is authored, declarations sorted. */
|
|
921
|
-
const keyframes$1 = (frames) => {
|
|
922
|
-
const body = Object.entries(frames).map(([step, declarations]) => `${step}{${declarationsText(declarations)}}`).join("");
|
|
923
|
-
const name = `kf-${hash(body)}`;
|
|
924
|
-
return Object.freeze({
|
|
925
|
-
name,
|
|
926
|
-
css: `@keyframes ${name}{${body}}`
|
|
927
|
-
});
|
|
928
|
-
};
|
|
929
|
-
const className = (rules) => `style-${hash(canonical(rules))}`;
|
|
930
|
-
const selectorFor = (generated, selector) => selector.includes("&") ? selector.replace(/&/g, `.${generated}`) : `.${generated} ${selector}`;
|
|
931
|
-
const css = (generated, rules) => rules.map((entry) => {
|
|
932
|
-
const body = `{${declarationsText(entry.declarations)}}`;
|
|
933
|
-
const selector = `${selectorFor(generated, entry.selector)}${body}`;
|
|
934
|
-
return entry.at === void 0 ? selector : `${entry.at}{${selector}}`;
|
|
935
|
-
}).join("");
|
|
936
|
-
//#endregion
|
|
937
1131
|
//#region src/style.ts
|
|
938
|
-
const tokens = (value) => value.split(/\s+/).filter((token) => token.length > 0);
|
|
939
|
-
const empty = Object.freeze({
|
|
940
|
-
classes: Object.freeze([]),
|
|
941
|
-
style: Object.freeze({})
|
|
942
|
-
});
|
|
943
|
-
const classPiece = (value) => Object.freeze({
|
|
944
|
-
classes: Object.freeze(tokens(value)),
|
|
945
|
-
style: empty.style
|
|
946
|
-
});
|
|
947
|
-
const inline = (value) => Object.freeze({
|
|
948
|
-
classes: empty.classes,
|
|
949
|
-
style: Object.freeze({ ...value })
|
|
950
|
-
});
|
|
951
|
-
/** Concatenate classes; later inline declarations win per property. */
|
|
952
|
-
const compose = (...pieces) => {
|
|
953
|
-
const conditions = pieces.flatMap((piece) => piece.conditions ?? []);
|
|
954
|
-
const rules = pieces.flatMap((piece) => piece.rules ?? []);
|
|
955
|
-
const globalCss = pieces.flatMap((piece) => piece.globalCss ?? []);
|
|
956
|
-
return Object.freeze({
|
|
957
|
-
classes: Object.freeze(pieces.flatMap((piece) => piece.classes)),
|
|
958
|
-
style: Object.freeze(Object.assign(Object.create(null), ...pieces.map((piece) => piece.style))),
|
|
959
|
-
...conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) },
|
|
960
|
-
...rules.length === 0 ? {} : { rules: Object.freeze(rules) },
|
|
961
|
-
...globalCss.length === 0 ? {} : { globalCss: Object.freeze(globalCss) }
|
|
962
|
-
});
|
|
963
|
-
};
|
|
964
|
-
/** A pseudo-class/element rule, e.g. `Style.pseudo(':hover', { color: 'red' })`. */
|
|
965
|
-
const pseudo = (suffix, declarations) => Object.freeze({
|
|
966
|
-
classes: empty.classes,
|
|
967
|
-
style: empty.style,
|
|
968
|
-
rules: Object.freeze([pseudo$1(suffix, declarations)])
|
|
969
|
-
});
|
|
970
|
-
/** An at-rule, e.g. `Style.media('(min-width: 40rem)', { color: 'red' })`. */
|
|
971
|
-
const media = (query, declarations) => Object.freeze({
|
|
972
|
-
classes: empty.classes,
|
|
973
|
-
style: empty.style,
|
|
974
|
-
rules: Object.freeze([media$1(query, declarations)])
|
|
975
|
-
});
|
|
976
|
-
/** An at-rule, e.g. `Style.supports('(display: grid)', { display: 'grid' })`. */
|
|
977
|
-
const supports = (condition, declarations) => Object.freeze({
|
|
978
|
-
classes: empty.classes,
|
|
979
|
-
style: empty.style,
|
|
980
|
-
rules: Object.freeze([supports$1(condition, declarations)])
|
|
981
|
-
});
|
|
982
|
-
/** A container query, e.g. `Style.container('(min-width: 30rem)', {...})`. */
|
|
983
|
-
const container = (condition, declarations) => Object.freeze({
|
|
984
|
-
classes: empty.classes,
|
|
985
|
-
style: empty.style,
|
|
986
|
-
rules: Object.freeze([container$1(condition, declarations)])
|
|
987
|
-
});
|
|
988
|
-
/** A nested selector relative to the generated class, e.g. `Style.nest('> span', {...})`. */
|
|
989
|
-
const nest = (selector, declarations) => Object.freeze({
|
|
990
|
-
classes: empty.classes,
|
|
991
|
-
style: empty.style,
|
|
992
|
-
rules: Object.freeze([nest$1(selector, declarations)])
|
|
993
|
-
});
|
|
994
1132
|
/**
|
|
995
|
-
*
|
|
996
|
-
*
|
|
1133
|
+
* `Style` is pure data: class tokens and inline declarations that compile to a
|
|
1134
|
+
* `SlotContribution`. It never touches the DOM and never mutates state.
|
|
1135
|
+
* `forSlots` validates piece keys against the published contract at definition
|
|
1136
|
+
* time, so a typo fails loudly. The builders themselves live in
|
|
1137
|
+
* `styleValue.ts`; this module joins them to slots.
|
|
997
1138
|
*/
|
|
998
|
-
const keyframes = (frames) => {
|
|
999
|
-
const compiled = keyframes$1(frames);
|
|
1000
|
-
return Object.freeze({
|
|
1001
|
-
name: compiled.name,
|
|
1002
|
-
style: Object.freeze({
|
|
1003
|
-
classes: empty.classes,
|
|
1004
|
-
style: empty.style,
|
|
1005
|
-
globalCss: Object.freeze([compiled.css])
|
|
1006
|
-
})
|
|
1007
|
-
});
|
|
1008
|
-
};
|
|
1009
|
-
/** Raw class-independent CSS (a layer, a global rule). Prefer typed helpers. */
|
|
1010
|
-
const global = (css) => Object.freeze({
|
|
1011
|
-
classes: empty.classes,
|
|
1012
|
-
style: empty.style,
|
|
1013
|
-
globalCss: Object.freeze([css])
|
|
1014
|
-
});
|
|
1015
1139
|
/** A boolean known at authoring time. */
|
|
1016
|
-
const when = (condition, piece) => condition ? piece : empty;
|
|
1140
|
+
const when = (condition, piece) => condition ? piece : empty$1;
|
|
1017
1141
|
/** A condition read from the view input at render time. The piece applies when
|
|
1018
1142
|
* `predicate` returns true for the input the view was rendered with. */
|
|
1019
1143
|
const whenInput = (predicate, piece) => Object.freeze({
|
|
1020
|
-
classes: empty.classes,
|
|
1021
|
-
style: empty.style,
|
|
1144
|
+
classes: empty$1.classes,
|
|
1145
|
+
style: empty$1.style,
|
|
1022
1146
|
conditions: Object.freeze([{
|
|
1023
1147
|
predicate: (input) => predicate(input),
|
|
1024
1148
|
piece
|
|
1025
1149
|
}])
|
|
1026
1150
|
});
|
|
1027
|
-
/**
|
|
1028
|
-
|
|
1029
|
-
|
|
1151
|
+
/**
|
|
1152
|
+
* A piece computed from the item the slot is rendered for, when the view
|
|
1153
|
+
* passes one to `attrs(base, item)`; nothing for a slot rendered once.
|
|
1154
|
+
*/
|
|
1155
|
+
const perItem = (piece) => Object.freeze({
|
|
1156
|
+
classes: empty$1.classes,
|
|
1157
|
+
style: empty$1.style,
|
|
1158
|
+
items: Object.freeze([(item) => item === void 0 ? empty$1 : piece(item)])
|
|
1159
|
+
});
|
|
1160
|
+
/**
|
|
1161
|
+
* A per-item delay for an entrance: writes `--fk-index` and
|
|
1162
|
+
* `transition-delay: calc(var(--fk-index) * <step>)` (or `animation-delay`),
|
|
1163
|
+
* so a list staggers with no timer. Pass the item to `attrs` for each row.
|
|
1164
|
+
*/
|
|
1165
|
+
const stagger = (options) => perItem((item) => inline({
|
|
1166
|
+
"--fk-index": String(item.index),
|
|
1167
|
+
[options.property ?? "transitionDelay"]: `calc(var(--fk-index) * ${options.stepMs}ms)`
|
|
1168
|
+
}));
|
|
1169
|
+
/** Fold every active condition and item piece (recursively) into a plain style. */
|
|
1170
|
+
const resolveStyle = (style, input, item) => {
|
|
1171
|
+
const active = [...(style.conditions ?? []).filter((condition) => condition.predicate(input)).map((condition) => condition.piece), ...(style.items ?? []).map((piece) => piece(item))].map((piece) => resolveStyle(piece, input, item));
|
|
1030
1172
|
return Object.freeze({
|
|
1031
1173
|
classes: Object.freeze([...style.classes, ...active.flatMap((piece) => piece.classes)]),
|
|
1032
1174
|
style: Object.freeze(Object.assign(Object.create(null), style.style, ...active.map((piece) => piece.style)))
|
|
1033
1175
|
});
|
|
1034
1176
|
};
|
|
1035
|
-
const hasConditionalRules = (style) => (style.conditions ?? []).some((condition) => (condition.piece.rules ?? []).length > 0 || hasConditionalRules(condition.piece));
|
|
1036
1177
|
/** Global CSS is emitted whether or not its condition is active. */
|
|
1037
1178
|
const collectGlobalCss = (style) => [...style.globalCss ?? [], ...(style.conditions ?? []).flatMap((condition) => collectGlobalCss(condition.piece))];
|
|
1038
|
-
/**
|
|
1039
|
-
|
|
1179
|
+
/**
|
|
1180
|
+
* Compiles every rule-bearing node in the tree to its class: the node's
|
|
1181
|
+
* classes gain the generated one, and the CSS is collected. A conditional
|
|
1182
|
+
* piece's rules are compiled the same way, so the class is static and only
|
|
1183
|
+
* its presence follows the input.
|
|
1184
|
+
*/
|
|
1185
|
+
const compileTree = (style, collected) => {
|
|
1040
1186
|
const rules = style.rules ?? [];
|
|
1041
|
-
const globalRules = collectGlobalCss(style);
|
|
1042
1187
|
const generated = rules.length === 0 ? void 0 : className(rules);
|
|
1043
|
-
|
|
1188
|
+
if (generated !== void 0) collected.push({
|
|
1189
|
+
className: generated,
|
|
1190
|
+
css: css(generated, rules)
|
|
1191
|
+
});
|
|
1192
|
+
const conditions = (style.conditions ?? []).map((condition) => ({
|
|
1193
|
+
predicate: condition.predicate,
|
|
1194
|
+
piece: compileTree(condition.piece, collected)
|
|
1195
|
+
}));
|
|
1196
|
+
return Object.freeze({
|
|
1197
|
+
...style,
|
|
1044
1198
|
classes: generated === void 0 ? style.classes : Object.freeze([...style.classes, generated]),
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1199
|
+
...conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) }
|
|
1200
|
+
});
|
|
1201
|
+
};
|
|
1202
|
+
/** A style with every rule in it compiled: the tree with classes, plus the CSS. */
|
|
1203
|
+
const compileStyle = (style) => {
|
|
1204
|
+
const collected = [];
|
|
1205
|
+
const tree = compileTree(style, collected);
|
|
1206
|
+
const globalRules = collectGlobalCss(style);
|
|
1207
|
+
const first = collected[0];
|
|
1208
|
+
return {
|
|
1209
|
+
tree,
|
|
1210
|
+
classes: tree.classes,
|
|
1211
|
+
style: tree.style,
|
|
1212
|
+
...first === void 0 ? {} : {
|
|
1213
|
+
css: collected.map((entry) => entry.css).join(""),
|
|
1214
|
+
ruleClass: first.className
|
|
1049
1215
|
},
|
|
1050
|
-
...globalRules.length === 0 ? {} : { globalRules }
|
|
1216
|
+
...globalRules.length === 0 ? {} : { globalRules },
|
|
1217
|
+
compiled: collected
|
|
1051
1218
|
};
|
|
1052
1219
|
};
|
|
1053
|
-
/** A rule's class is static while a `whenInput` condition is not, so they cannot combine. */
|
|
1054
|
-
const assertRulesSupported = (style) => {
|
|
1055
|
-
if (!hasConditionalRules(style)) return;
|
|
1056
|
-
throw new DiagnosticError({
|
|
1057
|
-
source: "mixins",
|
|
1058
|
-
code: "style:conditional-rules-unsupported",
|
|
1059
|
-
severity: "error",
|
|
1060
|
-
message: "Style.pseudo/media may not appear inside Style.whenInput"
|
|
1061
|
-
});
|
|
1062
|
-
};
|
|
1063
1220
|
/**
|
|
1064
1221
|
* A static style stays static data; a style with input conditions compiles to a
|
|
1065
1222
|
* message-free `InputContribution`, so it still attaches to any view.
|
|
@@ -1072,12 +1229,9 @@ const contributionFrom = (style, compiled) => {
|
|
|
1072
1229
|
...compiled.css === void 0 ? {} : { css: compiled.css },
|
|
1073
1230
|
...globalCss === void 0 ? {} : { globalCss }
|
|
1074
1231
|
};
|
|
1075
|
-
if ((style.conditions ?? []).length === 0) return Object.freeze(attributes);
|
|
1232
|
+
if ((style.conditions ?? []).length === 0 && (style.items ?? []).length === 0) return Object.freeze(attributes);
|
|
1076
1233
|
const contribution = (context) => {
|
|
1077
|
-
const resolved = resolveStyle(
|
|
1078
|
-
...style,
|
|
1079
|
-
classes: compiled.classes
|
|
1080
|
-
}, context.input);
|
|
1234
|
+
const resolved = resolveStyle(compiled.tree, context.input, context.item);
|
|
1081
1235
|
return Object.freeze({
|
|
1082
1236
|
classes: resolved.classes,
|
|
1083
1237
|
style: resolved.style,
|
|
@@ -1090,6 +1244,7 @@ const contributionFrom = (style, compiled) => {
|
|
|
1090
1244
|
const forSlots = (slots) => (pieces, options) => {
|
|
1091
1245
|
const known = slots;
|
|
1092
1246
|
const contributions = Object.create(null);
|
|
1247
|
+
const compiledPieces = {};
|
|
1093
1248
|
const rules = [];
|
|
1094
1249
|
const globalRules = [];
|
|
1095
1250
|
let css = "";
|
|
@@ -1110,15 +1265,13 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1110
1265
|
slot: key
|
|
1111
1266
|
});
|
|
1112
1267
|
if (piece !== void 0) {
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
});
|
|
1121
|
-
css += compiled.css;
|
|
1268
|
+
const placed = options?.layer === void 0 ? piece : options.layer.place(piece);
|
|
1269
|
+
compiledPieces[key] = placed;
|
|
1270
|
+
const compiled = compileStyle(placed);
|
|
1271
|
+
contributions[key] = contributionFrom(placed, compiled);
|
|
1272
|
+
for (const entry of compiled.compiled) {
|
|
1273
|
+
rules.push(entry);
|
|
1274
|
+
css += entry.css;
|
|
1122
1275
|
}
|
|
1123
1276
|
if (compiled.globalRules !== void 0) {
|
|
1124
1277
|
globalRules.push(...compiled.globalRules);
|
|
@@ -1128,7 +1281,7 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1128
1281
|
}
|
|
1129
1282
|
return Object.freeze({
|
|
1130
1283
|
...options?.name === void 0 ? {} : { name: options.name },
|
|
1131
|
-
pieces,
|
|
1284
|
+
pieces: options?.layer === void 0 ? pieces : compiledPieces,
|
|
1132
1285
|
mixin: dynamic(options?.name ?? "Style", contributions),
|
|
1133
1286
|
css,
|
|
1134
1287
|
globalCss,
|
|
@@ -1136,15 +1289,72 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1136
1289
|
globalRules: Object.freeze(globalRules)
|
|
1137
1290
|
});
|
|
1138
1291
|
};
|
|
1139
|
-
|
|
1292
|
+
const isStylesheetSource = (value) => "globalRules" in value;
|
|
1293
|
+
const LAYER_STATEMENT = /^@layer [^{}]+;$/;
|
|
1294
|
+
const sourceOf = (style) => {
|
|
1295
|
+
const compiled = compileStyle(style);
|
|
1296
|
+
return {
|
|
1297
|
+
rules: compiled.compiled,
|
|
1298
|
+
globalRules: compiled.globalRules ?? []
|
|
1299
|
+
};
|
|
1300
|
+
};
|
|
1301
|
+
/**
|
|
1302
|
+
* An unlayered rule beats every layer, `app` included, so once a sheet
|
|
1303
|
+
* declares an order, a rule outside it, or in a layer the order does not
|
|
1304
|
+
* name (which would sort after the last one), is a mistake. Keyframes, font
|
|
1305
|
+
* faces, and registered properties are not ordered by the cascade and pass.
|
|
1306
|
+
*/
|
|
1307
|
+
const refuseUnlayered = (css, names, where, className) => {
|
|
1308
|
+
for (const block of topLevelBlocks(css)) {
|
|
1309
|
+
if (isUnordered(block)) continue;
|
|
1310
|
+
const layer = layerOf(block);
|
|
1311
|
+
if (layer !== void 0 && names.includes(layer)) continue;
|
|
1312
|
+
throw new DiagnosticError({
|
|
1313
|
+
source: "style",
|
|
1314
|
+
code: "style:unlayered-rule",
|
|
1315
|
+
severity: "error",
|
|
1316
|
+
message: layer === void 0 ? `Style.stylesheet declares a layer order, but ${where} has a rule outside it, which would beat every layer; place its piece with L.in(name, …)` : `${where} is in layer "${layer}", which the declared order (${names.join(", ")}) does not name, so it would sort after "${names.at(-1)}"; place it with L.in(name, …)`,
|
|
1317
|
+
details: {
|
|
1318
|
+
...className === void 0 ? {} : { className },
|
|
1319
|
+
...layer === void 0 ? {} : { layer }
|
|
1320
|
+
}
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* One `<style>` block: the `@layer …;` statement first (one order per
|
|
1326
|
+
* sheet), then the other global chunks, then the scoped classes, each
|
|
1327
|
+
* deduplicated with the first seen winning. A bare `StyleValue` (a theme
|
|
1328
|
+
* root, a layered reset, a layout) compiles like a piece of a `NamedStyle`.
|
|
1329
|
+
* With an order declared, every rule must sit in one of its layers
|
|
1330
|
+
* (`style:unlayered-rule`); without one, unlayered rules are allowed.
|
|
1331
|
+
*/
|
|
1140
1332
|
const stylesheet = (...styles) => {
|
|
1141
1333
|
const scoped = /* @__PURE__ */ new Map();
|
|
1142
1334
|
const global = /* @__PURE__ */ new Set();
|
|
1335
|
+
let order;
|
|
1143
1336
|
for (const style of styles) {
|
|
1144
|
-
|
|
1145
|
-
for (const rule of
|
|
1337
|
+
const source = isStylesheetSource(style) ? style : sourceOf(style);
|
|
1338
|
+
for (const rule of source.rules) if (!scoped.has(rule.className)) scoped.set(rule.className, rule.css);
|
|
1339
|
+
for (const rule of source.globalRules) if (!LAYER_STATEMENT.test(rule)) global.add(rule);
|
|
1340
|
+
else if (order === void 0) order = rule;
|
|
1341
|
+
else if (order !== rule) throw new DiagnosticError({
|
|
1342
|
+
source: "style",
|
|
1343
|
+
code: "style:conflicting-layer-order",
|
|
1344
|
+
severity: "error",
|
|
1345
|
+
message: `Style.stylesheet was given two layer orders: "${order}" and "${rule}"`
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
if (order !== void 0) {
|
|
1349
|
+
const names = declaredNames(order);
|
|
1350
|
+
for (const chunk of global) refuseUnlayered(chunk, names, `global CSS "${chunk.slice(0, 60)}"`);
|
|
1351
|
+
for (const [className, css] of scoped) refuseUnlayered(css, names, `class "${className}"`, className);
|
|
1146
1352
|
}
|
|
1147
|
-
return [
|
|
1353
|
+
return [
|
|
1354
|
+
...order === void 0 ? [] : [order],
|
|
1355
|
+
...global,
|
|
1356
|
+
...scoped.values()
|
|
1357
|
+
].join("");
|
|
1148
1358
|
};
|
|
1149
1359
|
const attach = (style) => (view) => attach$2(style.mixin)(view);
|
|
1150
1360
|
/** A recipe is just Style data: base, one piece per selected variant, then any
|
|
@@ -1162,43 +1372,119 @@ const recipe = (def) => (selection) => {
|
|
|
1162
1372
|
if (piece !== void 0) pieces.push(piece);
|
|
1163
1373
|
}
|
|
1164
1374
|
for (const compound of def.compound ?? []) if (Object.entries(compound.when).every(([variant, value]) => effective[variant] === value)) pieces.push(compound.style);
|
|
1165
|
-
return compose(...pieces);
|
|
1375
|
+
return compose$1(...pieces);
|
|
1376
|
+
};
|
|
1377
|
+
const mergePieces = (left, right) => {
|
|
1378
|
+
const merged = {};
|
|
1379
|
+
for (const source of [left, right]) for (const [slot, piece] of Object.entries(source ?? {})) {
|
|
1380
|
+
const existing = merged[slot];
|
|
1381
|
+
merged[slot] = existing === void 0 ? piece : compose$1(existing, piece);
|
|
1382
|
+
}
|
|
1383
|
+
return merged;
|
|
1384
|
+
};
|
|
1385
|
+
const assertKnownSlots = (slots, pieces, where) => {
|
|
1386
|
+
const known = slots;
|
|
1387
|
+
for (const slot of Object.keys(pieces ?? {})) if (!Object.hasOwn(known, slot)) throw new DiagnosticError({
|
|
1388
|
+
source: "mixins",
|
|
1389
|
+
code: "mixins:unknown-slot",
|
|
1390
|
+
severity: "error",
|
|
1391
|
+
message: `Recipe ${where} targets unknown slot "${slot}"`,
|
|
1392
|
+
slot
|
|
1393
|
+
});
|
|
1394
|
+
};
|
|
1395
|
+
/**
|
|
1396
|
+
* A recipe over every slot of a contract: `base` pieces per slot, `variants`
|
|
1397
|
+
* per axis and value, `defaults`, and `compound` matches. The result of a
|
|
1398
|
+
* selection is a `StylePieces` for `Style.forSlots`. A design system ships
|
|
1399
|
+
* the recipe; an application adjusts it with `extend` instead of forking.
|
|
1400
|
+
*/
|
|
1401
|
+
const recipeFor = (slots) => (def) => {
|
|
1402
|
+
assertKnownSlots(slots, def.base, "base");
|
|
1403
|
+
for (const [axis, values] of Object.entries(def.variants)) for (const [value, pieces] of Object.entries(values)) assertKnownSlots(slots, pieces, `variants.${axis}.${value}`);
|
|
1404
|
+
for (const entry of def.compound ?? []) assertKnownSlots(slots, entry.style, "compound");
|
|
1405
|
+
const select = (selection = {}) => {
|
|
1406
|
+
let pieces = def.base ?? {};
|
|
1407
|
+
const effective = {};
|
|
1408
|
+
for (const [axis, values] of Object.entries(def.variants)) {
|
|
1409
|
+
const picked = selection[axis];
|
|
1410
|
+
const chosen = picked === null ? void 0 : picked ?? def.defaults?.[axis];
|
|
1411
|
+
if (chosen === void 0) continue;
|
|
1412
|
+
effective[axis] = chosen;
|
|
1413
|
+
const piece = values[chosen];
|
|
1414
|
+
if (piece !== void 0) pieces = mergePieces(pieces, piece);
|
|
1415
|
+
}
|
|
1416
|
+
for (const entry of def.compound ?? []) if (Object.entries(entry.when).every(([axis, value]) => effective[axis] === value)) pieces = mergePieces(pieces, entry.style);
|
|
1417
|
+
return pieces;
|
|
1418
|
+
};
|
|
1419
|
+
const extend = (patch) => {
|
|
1420
|
+
const variants = {};
|
|
1421
|
+
for (const [axis, values] of Object.entries(def.variants)) variants[axis] = { ...values };
|
|
1422
|
+
for (const [axis, values] of Object.entries(patch.variants ?? {})) {
|
|
1423
|
+
const target = variants[axis] ?? {};
|
|
1424
|
+
for (const [value, pieces] of Object.entries(values ?? {})) target[value] = mergePieces(target[value], pieces);
|
|
1425
|
+
variants[axis] = target;
|
|
1426
|
+
}
|
|
1427
|
+
return recipeFor(slots)({
|
|
1428
|
+
base: mergePieces(def.base, patch.base),
|
|
1429
|
+
variants,
|
|
1430
|
+
defaults: {
|
|
1431
|
+
...def.defaults,
|
|
1432
|
+
...patch.defaults
|
|
1433
|
+
},
|
|
1434
|
+
compound: [...def.compound ?? [], ...patch.compound ?? []]
|
|
1435
|
+
});
|
|
1436
|
+
};
|
|
1437
|
+
return Object.assign(select, {
|
|
1438
|
+
def,
|
|
1439
|
+
extend
|
|
1440
|
+
});
|
|
1441
|
+
};
|
|
1442
|
+
/**
|
|
1443
|
+
* One piece for every public slot whose capability satisfies `capability`:
|
|
1444
|
+
* a focus ring for every `Focusable`, a disabled treatment for every
|
|
1445
|
+
* `Interactive`, in one line.
|
|
1446
|
+
*/
|
|
1447
|
+
const forCapability = (slots) => (capability, piece, options) => {
|
|
1448
|
+
const source = slots;
|
|
1449
|
+
const pieces = {};
|
|
1450
|
+
for (const [name, slot] of Object.entries(source)) {
|
|
1451
|
+
if (slot.hidden) continue;
|
|
1452
|
+
if (extendsCapability(slot.capability, capability)) pieces[name] = piece;
|
|
1453
|
+
}
|
|
1454
|
+
return forSlots(slots)(pieces, options);
|
|
1166
1455
|
};
|
|
1167
1456
|
const Style = {
|
|
1168
1457
|
class: classPiece,
|
|
1169
1458
|
inline,
|
|
1170
|
-
compose,
|
|
1459
|
+
compose: compose$1,
|
|
1171
1460
|
when,
|
|
1172
1461
|
whenInput,
|
|
1173
1462
|
pseudo,
|
|
1463
|
+
self,
|
|
1174
1464
|
media,
|
|
1175
1465
|
supports,
|
|
1176
1466
|
container,
|
|
1177
1467
|
nest,
|
|
1468
|
+
states,
|
|
1469
|
+
responsive,
|
|
1470
|
+
vars,
|
|
1471
|
+
enter,
|
|
1472
|
+
allowDiscrete,
|
|
1473
|
+
viewTransitionName,
|
|
1474
|
+
grid,
|
|
1178
1475
|
keyframes,
|
|
1179
1476
|
global,
|
|
1180
|
-
empty,
|
|
1477
|
+
empty: empty$1,
|
|
1478
|
+
perItem,
|
|
1479
|
+
stagger,
|
|
1181
1480
|
forSlots,
|
|
1481
|
+
forCapability,
|
|
1182
1482
|
attach,
|
|
1183
1483
|
recipe,
|
|
1484
|
+
recipeFor,
|
|
1184
1485
|
stylesheet
|
|
1185
1486
|
};
|
|
1186
1487
|
//#endregion
|
|
1187
|
-
|
|
1188
|
-
const VAR_PREFIX = "--fk";
|
|
1189
|
-
const define = (tokens) => Object.freeze(Object.fromEntries(Object.entries(tokens).map(([group, names]) => [group, Object.freeze({ ...names })])));
|
|
1190
|
-
const variable = (_theme, group, name) => `var(${VAR_PREFIX}-${group}-${name})`;
|
|
1191
|
-
const variables = (theme) => {
|
|
1192
|
-
const style = {};
|
|
1193
|
-
for (const [group, names] of Object.entries(theme)) for (const [name, value] of Object.entries(names)) style[`${VAR_PREFIX}-${group}-${name}`] = value;
|
|
1194
|
-
return inline(style);
|
|
1195
|
-
};
|
|
1196
|
-
const Theme = {
|
|
1197
|
-
define,
|
|
1198
|
-
variable,
|
|
1199
|
-
variables
|
|
1200
|
-
};
|
|
1201
|
-
//#endregion
|
|
1202
|
-
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 };
|
|
1488
|
+
export { a11y_exports as A11y, attr_exports as Attr, attributes_exports as Attributes, behavior_exports as Behavior, behaviors_exports as Behaviors, capability_exports as Capability, diagnostics_exports as Diagnostics, event_exports as Event, Layers, metadataToken_exports as MetadataToken, mixin_exports as Mixin, requirement_exports as Requirement, resolver_exports as Resolver, selector_exports as Selector, slot_exports as Slot, slotView_exports as SlotView, slots_exports as Slots, Style, Theme };
|
|
1203
1489
|
|
|
1204
1490
|
//# sourceMappingURL=index.mjs.map
|