foldkit-mixins 0.3.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 +244 -10
- 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 +232 -76
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +486 -229
- 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 { 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";
|
|
2
6
|
import { inertHtml } from "foldkit/html";
|
|
3
|
-
import { Stream } from "effect";
|
|
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 });
|
|
@@ -255,23 +259,12 @@ const find = (attributes, tag) => attributes.find(hasTag(tag));
|
|
|
255
259
|
/** Every attribute with `tag`, in bundle order. */
|
|
256
260
|
const filter = (attributes, tag) => attributes.filter(hasTag(tag));
|
|
257
261
|
//#endregion
|
|
258
|
-
//#region src/diagnostics.ts
|
|
259
|
-
var diagnostics_exports = /* @__PURE__ */ __exportAll({ DiagnosticError: () => DiagnosticError });
|
|
260
|
-
var DiagnosticError = class extends Error {
|
|
261
|
-
diagnostic;
|
|
262
|
-
constructor(diagnostic) {
|
|
263
|
-
super(diagnostic.message);
|
|
264
|
-
this.name = "DiagnosticError";
|
|
265
|
-
this.diagnostic = diagnostic;
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
//#endregion
|
|
269
262
|
//#region src/mixin.ts
|
|
270
263
|
var mixin_exports = /* @__PURE__ */ __exportAll({
|
|
271
|
-
compose: () => compose
|
|
264
|
+
compose: () => compose,
|
|
272
265
|
contributionsFor: () => contributionsFor,
|
|
273
266
|
dynamic: () => dynamic,
|
|
274
|
-
empty: () => empty
|
|
267
|
+
empty: () => empty,
|
|
275
268
|
evaluate: () => evaluate,
|
|
276
269
|
isDynamic: () => isDynamic,
|
|
277
270
|
make: () => make$3
|
|
@@ -305,8 +298,8 @@ const dynamic = (name, contributions) => Object.freeze({
|
|
|
305
298
|
name,
|
|
306
299
|
contributions: Object.freeze({ ...contributions })
|
|
307
300
|
});
|
|
308
|
-
const empty
|
|
309
|
-
const compose
|
|
301
|
+
const empty = () => make$3("Empty", {});
|
|
302
|
+
const compose = (...mixins) => {
|
|
310
303
|
const merged = Object.create(null);
|
|
311
304
|
for (const mixin of mixins) for (const [slot, contribution] of Object.entries(mixin.contributions)) {
|
|
312
305
|
if (contribution === void 0) continue;
|
|
@@ -365,6 +358,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
365
358
|
const classes = [];
|
|
366
359
|
const classSeen = /* @__PURE__ */ new Set();
|
|
367
360
|
const style = /* @__PURE__ */ new Map();
|
|
361
|
+
const styleOwners = /* @__PURE__ */ new Map();
|
|
368
362
|
const mounts = [];
|
|
369
363
|
const mountNames = /* @__PURE__ */ new Map();
|
|
370
364
|
const preserved = [];
|
|
@@ -379,6 +373,17 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
379
373
|
classSeen.add(token);
|
|
380
374
|
classes.push(token);
|
|
381
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
|
+
};
|
|
382
387
|
const addMount = (action) => {
|
|
383
388
|
const count = (mountNames.get(action.name) ?? 0) + 1;
|
|
384
389
|
mountNames.set(action.name, count);
|
|
@@ -406,7 +411,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
406
411
|
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
407
412
|
return;
|
|
408
413
|
case "Style":
|
|
409
|
-
for (const [property, value] of Object.entries(attribute.value))
|
|
414
|
+
for (const [property, value] of Object.entries(attribute.value)) writeStyle(property, value, "base");
|
|
410
415
|
return;
|
|
411
416
|
case "OnMount":
|
|
412
417
|
addMount(attribute.action);
|
|
@@ -429,10 +434,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
429
434
|
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
430
435
|
return;
|
|
431
436
|
case "Style":
|
|
432
|
-
for (const [property, value] of Object.entries(attribute.value))
|
|
433
|
-
if (protectedStyle.has(property)) fail("mixins:protected-style-property", `slot "${slot ?? "?"}" protects style property "${property}"`, { property });
|
|
434
|
-
style.set(property, value);
|
|
435
|
-
}
|
|
437
|
+
for (const [property, value] of Object.entries(attribute.value)) writeStyle(property, value, "behavior");
|
|
436
438
|
return;
|
|
437
439
|
case "OnMount":
|
|
438
440
|
addMount(attribute.action);
|
|
@@ -470,10 +472,7 @@ const resolve = (base, contributions, options = {}) => {
|
|
|
470
472
|
for (const attribute of base ?? []) addBase(attribute);
|
|
471
473
|
for (const contribution of contributions) {
|
|
472
474
|
for (const token of contribution.classes ?? []) addClass(token);
|
|
473
|
-
for (const [property, value] of Object.entries(contribution.style ?? {}))
|
|
474
|
-
if (protectedStyle.has(property)) fail("mixins:protected-style-property", `slot "${slot ?? "?"}" protects style property "${property}"`, { property });
|
|
475
|
-
style.set(property, value);
|
|
476
|
-
}
|
|
475
|
+
for (const [property, value] of Object.entries(contribution.style ?? {})) writeStyle(property, value, "style");
|
|
477
476
|
for (const attribute of contribution.attributes ?? []) applyMixinAttribute(attribute);
|
|
478
477
|
for (const mount of contribution.mounts ?? []) addMount(mount);
|
|
479
478
|
}
|
|
@@ -514,7 +513,7 @@ const composeMounts = (mounts, slot) => {
|
|
|
514
513
|
var slotView_exports = /* @__PURE__ */ __exportAll({
|
|
515
514
|
attach: () => attach$2,
|
|
516
515
|
buildersFor: () => buildersFor,
|
|
517
|
-
define: () => define$
|
|
516
|
+
define: () => define$1,
|
|
518
517
|
forMessages: () => forMessages,
|
|
519
518
|
inertBuilder: () => inertBuilder
|
|
520
519
|
});
|
|
@@ -526,13 +525,14 @@ const buildersFor = (slots, mixins, context) => {
|
|
|
526
525
|
const slot = source[name];
|
|
527
526
|
if (slot === void 0) continue;
|
|
528
527
|
const protection = slot.protected;
|
|
529
|
-
builders[name] = { attrs: (base) => {
|
|
528
|
+
builders[name] = { attrs: (base, item) => {
|
|
530
529
|
const contributions = [];
|
|
531
530
|
for (const mixin of mixins) {
|
|
532
531
|
const contribution = mixin.contributions[name];
|
|
533
532
|
if (contribution !== void 0) contributions.push(evaluate(contribution, {
|
|
534
533
|
input: context.input,
|
|
535
|
-
h: context.h
|
|
534
|
+
h: context.h,
|
|
535
|
+
...item === void 0 ? {} : { item }
|
|
536
536
|
}));
|
|
537
537
|
}
|
|
538
538
|
return resolve(base, contributions, {
|
|
@@ -569,7 +569,7 @@ const makeView = (name, slots, mixins, render) => {
|
|
|
569
569
|
* does not name the missing annotation. `forMessages<Message>()` fixes the
|
|
570
570
|
* Message universe up front instead, and leaves `h` contextually typed.
|
|
571
571
|
*/
|
|
572
|
-
const define$
|
|
572
|
+
const define$1 = (slots, render, options) => makeView(options?.name, slots, [], render);
|
|
573
573
|
/**
|
|
574
574
|
* Foldkit's `inertHtml` typed for a Message universe, for rendering a view
|
|
575
575
|
* outside a runtime (tests, demos, static description). `inertHtml` is
|
|
@@ -591,7 +591,7 @@ const inertBuilder = () => inertHtml;
|
|
|
591
591
|
* )
|
|
592
592
|
* ```
|
|
593
593
|
*/
|
|
594
|
-
const forMessages = () => ({ define: define$
|
|
594
|
+
const forMessages = () => ({ define: define$1 });
|
|
595
595
|
function attach$2(mixin) {
|
|
596
596
|
return (view) => makeView(view.name, view.slots, [...view.mixins, mixin], view.render);
|
|
597
597
|
}
|
|
@@ -640,9 +640,10 @@ const forSlots$1 = (slots) => (spec, options) => {
|
|
|
640
640
|
contributions[name] = (context) => ({
|
|
641
641
|
...attributes === void 0 ? {} : { attributes: attributes({
|
|
642
642
|
input: context.input,
|
|
643
|
-
h: context.h
|
|
643
|
+
h: context.h,
|
|
644
|
+
...context.item === void 0 ? {} : { item: context.item }
|
|
644
645
|
}) },
|
|
645
|
-
...mount === void 0 ? {} : { mounts: [mount(context.input)] }
|
|
646
|
+
...mount === void 0 ? {} : { mounts: [mount(context.input, context.item)] }
|
|
646
647
|
});
|
|
647
648
|
}
|
|
648
649
|
return Object.freeze({
|
|
@@ -665,6 +666,185 @@ const Behavior = {
|
|
|
665
666
|
attach: attach$1
|
|
666
667
|
};
|
|
667
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
|
|
668
848
|
//#region src/event.ts
|
|
669
849
|
/**
|
|
670
850
|
* Slot event tokens. Ported from `effect-atom-jsx/src/View.ts` `Event`, plus
|
|
@@ -685,10 +865,10 @@ var event_exports = /* @__PURE__ */ __exportAll({
|
|
|
685
865
|
Submit: () => Submit,
|
|
686
866
|
describe: () => describe$3,
|
|
687
867
|
equals: () => equals,
|
|
688
|
-
is: () => is$
|
|
868
|
+
is: () => is$3,
|
|
689
869
|
make: () => make$2
|
|
690
870
|
});
|
|
691
|
-
const is$
|
|
871
|
+
const is$3 = (value) => is$6(value) && value.kind === "view.event";
|
|
692
872
|
const make$2 = (name) => make$6("view.event", name);
|
|
693
873
|
const equals = (left, right) => left.name === right.name;
|
|
694
874
|
const describe$3 = (event) => ({ name: event.name });
|
|
@@ -715,16 +895,46 @@ var requirement_exports = /* @__PURE__ */ __exportAll({
|
|
|
715
895
|
Keyboard: () => Keyboard,
|
|
716
896
|
Pointer: () => Pointer,
|
|
717
897
|
describe: () => describe$2,
|
|
718
|
-
is: () => is$
|
|
898
|
+
is: () => is$2,
|
|
719
899
|
make: () => make$1
|
|
720
900
|
});
|
|
721
|
-
const is$
|
|
901
|
+
const is$2 = (value) => is$6(value) && value.kind === "view.requirement";
|
|
722
902
|
const make$1 = (name) => make$6("view.requirement", name);
|
|
723
903
|
const describe$2 = (requirement) => ({ name: requirement.name });
|
|
724
904
|
const Keyboard = make$1("keyboard");
|
|
725
905
|
const Pointer = make$1("pointer");
|
|
726
906
|
const Clipboard = make$1("clipboard");
|
|
727
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
|
|
728
938
|
//#region src/slot.ts
|
|
729
939
|
var slot_exports = /* @__PURE__ */ __exportAll({
|
|
730
940
|
SlotTypeId: () => SlotTypeId,
|
|
@@ -863,7 +1073,7 @@ const describe$1 = (slot) => {
|
|
|
863
1073
|
*/
|
|
864
1074
|
var slots_exports = /* @__PURE__ */ __exportAll({
|
|
865
1075
|
SlotsTypeId: () => SlotsTypeId,
|
|
866
|
-
define: () => define
|
|
1076
|
+
define: () => define,
|
|
867
1077
|
describe: () => describe,
|
|
868
1078
|
withCapability: () => withCapability
|
|
869
1079
|
});
|
|
@@ -873,7 +1083,7 @@ const toUnnamed = (value, key) => {
|
|
|
873
1083
|
if (typeof value === "object" && value !== null && Object.hasOwn(value, "capability")) return make(value);
|
|
874
1084
|
throw new Error(`Slots.define: "${key}" is not a Slot or slot options object`);
|
|
875
1085
|
};
|
|
876
|
-
const define
|
|
1086
|
+
const define = (spec) => {
|
|
877
1087
|
const proto = Object.getPrototypeOf(spec);
|
|
878
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");
|
|
879
1089
|
const contract = Object.create(null);
|
|
@@ -918,177 +1128,95 @@ const withCapability = (contract, capability) => {
|
|
|
918
1128
|
return out;
|
|
919
1129
|
};
|
|
920
1130
|
//#endregion
|
|
921
|
-
//#region src/styleRules.ts
|
|
922
|
-
const rule = (selector, declarations, at) => Object.freeze({
|
|
923
|
-
selector,
|
|
924
|
-
declarations: Object.freeze({ ...declarations }),
|
|
925
|
-
...at === void 0 ? {} : { at }
|
|
926
|
-
});
|
|
927
|
-
const pseudo$1 = (suffix, declarations) => rule(`&${suffix}`, declarations);
|
|
928
|
-
const media$1 = (query, declarations) => rule("&", declarations, `@media ${query}`);
|
|
929
|
-
const supports$1 = (condition, declarations) => rule("&", declarations, `@supports ${condition}`);
|
|
930
|
-
const container$1 = (condition, declarations) => rule("&", declarations, `@container ${condition}`);
|
|
931
|
-
/** A nested selector relative to the class, e.g. `> span` or `[data-open] &`. */
|
|
932
|
-
const nest$1 = (selector, declarations) => rule(`& ${selector}`, declarations);
|
|
933
|
-
/** `gridTemplateColumns` -> `grid-template-columns`; custom properties pass through. */
|
|
934
|
-
const kebab = (property) => property.startsWith("--") ? property : property.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
935
|
-
const declarationsText = (declarations) => Object.keys(declarations).sort().map((property) => `${kebab(property)}:${declarations[property]}`).join(";");
|
|
936
|
-
/** Canonical, declaration-sorted, authored-rule-order text for a rule list. */
|
|
937
|
-
const canonical = (rules) => rules.map((entry) => {
|
|
938
|
-
const body = `{${declarationsText(entry.declarations)}}`;
|
|
939
|
-
return entry.at === void 0 ? `${entry.selector}${body}` : `${entry.at}{${entry.selector}${body}}`;
|
|
940
|
-
}).join("");
|
|
941
|
-
const hash = (value) => {
|
|
942
|
-
let state = 2166136261;
|
|
943
|
-
for (let index = 0; index < value.length; index++) {
|
|
944
|
-
state ^= value.charCodeAt(index);
|
|
945
|
-
state = Math.imul(state, 16777619);
|
|
946
|
-
}
|
|
947
|
-
return (state >>> 0).toString(36);
|
|
948
|
-
};
|
|
949
|
-
/** Deterministic `@keyframes`: step order is authored, declarations sorted. */
|
|
950
|
-
const keyframes$1 = (frames) => {
|
|
951
|
-
const body = Object.entries(frames).map(([step, declarations]) => `${step}{${declarationsText(declarations)}}`).join("");
|
|
952
|
-
const name = `kf-${hash(body)}`;
|
|
953
|
-
return Object.freeze({
|
|
954
|
-
name,
|
|
955
|
-
css: `@keyframes ${name}{${body}}`
|
|
956
|
-
});
|
|
957
|
-
};
|
|
958
|
-
const className = (rules) => `style-${hash(canonical(rules))}`;
|
|
959
|
-
const selectorFor = (generated, selector) => selector.includes("&") ? selector.replace(/&/g, `.${generated}`) : `.${generated} ${selector}`;
|
|
960
|
-
const css = (generated, rules) => rules.map((entry) => {
|
|
961
|
-
const body = `{${declarationsText(entry.declarations)}}`;
|
|
962
|
-
const selector = `${selectorFor(generated, entry.selector)}${body}`;
|
|
963
|
-
return entry.at === void 0 ? selector : `${entry.at}{${selector}}`;
|
|
964
|
-
}).join("");
|
|
965
|
-
//#endregion
|
|
966
1131
|
//#region src/style.ts
|
|
967
|
-
const tokens = (value) => value.split(/\s+/).filter((token) => token.length > 0);
|
|
968
|
-
const empty = Object.freeze({
|
|
969
|
-
classes: Object.freeze([]),
|
|
970
|
-
style: Object.freeze({})
|
|
971
|
-
});
|
|
972
|
-
const classPiece = (value) => Object.freeze({
|
|
973
|
-
classes: Object.freeze(tokens(value)),
|
|
974
|
-
style: empty.style
|
|
975
|
-
});
|
|
976
|
-
const inline = (value) => Object.freeze({
|
|
977
|
-
classes: empty.classes,
|
|
978
|
-
style: Object.freeze({ ...value })
|
|
979
|
-
});
|
|
980
|
-
/** Concatenate classes; later inline declarations win per property. */
|
|
981
|
-
const compose = (...pieces) => {
|
|
982
|
-
const conditions = pieces.flatMap((piece) => piece.conditions ?? []);
|
|
983
|
-
const rules = pieces.flatMap((piece) => piece.rules ?? []);
|
|
984
|
-
const globalCss = pieces.flatMap((piece) => piece.globalCss ?? []);
|
|
985
|
-
return Object.freeze({
|
|
986
|
-
classes: Object.freeze(pieces.flatMap((piece) => piece.classes)),
|
|
987
|
-
style: Object.freeze(Object.assign(Object.create(null), ...pieces.map((piece) => piece.style))),
|
|
988
|
-
...conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) },
|
|
989
|
-
...rules.length === 0 ? {} : { rules: Object.freeze(rules) },
|
|
990
|
-
...globalCss.length === 0 ? {} : { globalCss: Object.freeze(globalCss) }
|
|
991
|
-
});
|
|
992
|
-
};
|
|
993
|
-
/** A pseudo-class/element rule, e.g. `Style.pseudo(':hover', { color: 'red' })`. */
|
|
994
|
-
const pseudo = (suffix, declarations) => Object.freeze({
|
|
995
|
-
classes: empty.classes,
|
|
996
|
-
style: empty.style,
|
|
997
|
-
rules: Object.freeze([pseudo$1(suffix, declarations)])
|
|
998
|
-
});
|
|
999
|
-
/** An at-rule, e.g. `Style.media('(min-width: 40rem)', { color: 'red' })`. */
|
|
1000
|
-
const media = (query, declarations) => Object.freeze({
|
|
1001
|
-
classes: empty.classes,
|
|
1002
|
-
style: empty.style,
|
|
1003
|
-
rules: Object.freeze([media$1(query, declarations)])
|
|
1004
|
-
});
|
|
1005
|
-
/** An at-rule, e.g. `Style.supports('(display: grid)', { display: 'grid' })`. */
|
|
1006
|
-
const supports = (condition, declarations) => Object.freeze({
|
|
1007
|
-
classes: empty.classes,
|
|
1008
|
-
style: empty.style,
|
|
1009
|
-
rules: Object.freeze([supports$1(condition, declarations)])
|
|
1010
|
-
});
|
|
1011
|
-
/** A container query, e.g. `Style.container('(min-width: 30rem)', {...})`. */
|
|
1012
|
-
const container = (condition, declarations) => Object.freeze({
|
|
1013
|
-
classes: empty.classes,
|
|
1014
|
-
style: empty.style,
|
|
1015
|
-
rules: Object.freeze([container$1(condition, declarations)])
|
|
1016
|
-
});
|
|
1017
|
-
/** A nested selector relative to the generated class, e.g. `Style.nest('> span', {...})`. */
|
|
1018
|
-
const nest = (selector, declarations) => Object.freeze({
|
|
1019
|
-
classes: empty.classes,
|
|
1020
|
-
style: empty.style,
|
|
1021
|
-
rules: Object.freeze([nest$1(selector, declarations)])
|
|
1022
|
-
});
|
|
1023
1132
|
/**
|
|
1024
|
-
*
|
|
1025
|
-
*
|
|
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.
|
|
1026
1138
|
*/
|
|
1027
|
-
const keyframes = (frames) => {
|
|
1028
|
-
const compiled = keyframes$1(frames);
|
|
1029
|
-
return Object.freeze({
|
|
1030
|
-
name: compiled.name,
|
|
1031
|
-
style: Object.freeze({
|
|
1032
|
-
classes: empty.classes,
|
|
1033
|
-
style: empty.style,
|
|
1034
|
-
globalCss: Object.freeze([compiled.css])
|
|
1035
|
-
})
|
|
1036
|
-
});
|
|
1037
|
-
};
|
|
1038
|
-
/** Raw class-independent CSS (a layer, a global rule). Prefer typed helpers. */
|
|
1039
|
-
const global = (css) => Object.freeze({
|
|
1040
|
-
classes: empty.classes,
|
|
1041
|
-
style: empty.style,
|
|
1042
|
-
globalCss: Object.freeze([css])
|
|
1043
|
-
});
|
|
1044
1139
|
/** A boolean known at authoring time. */
|
|
1045
|
-
const when = (condition, piece) => condition ? piece : empty;
|
|
1140
|
+
const when = (condition, piece) => condition ? piece : empty$1;
|
|
1046
1141
|
/** A condition read from the view input at render time. The piece applies when
|
|
1047
1142
|
* `predicate` returns true for the input the view was rendered with. */
|
|
1048
1143
|
const whenInput = (predicate, piece) => Object.freeze({
|
|
1049
|
-
classes: empty.classes,
|
|
1050
|
-
style: empty.style,
|
|
1144
|
+
classes: empty$1.classes,
|
|
1145
|
+
style: empty$1.style,
|
|
1051
1146
|
conditions: Object.freeze([{
|
|
1052
1147
|
predicate: (input) => predicate(input),
|
|
1053
1148
|
piece
|
|
1054
1149
|
}])
|
|
1055
1150
|
});
|
|
1056
|
-
/**
|
|
1057
|
-
|
|
1058
|
-
|
|
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));
|
|
1059
1172
|
return Object.freeze({
|
|
1060
1173
|
classes: Object.freeze([...style.classes, ...active.flatMap((piece) => piece.classes)]),
|
|
1061
1174
|
style: Object.freeze(Object.assign(Object.create(null), style.style, ...active.map((piece) => piece.style)))
|
|
1062
1175
|
});
|
|
1063
1176
|
};
|
|
1064
|
-
const hasConditionalRules = (style) => (style.conditions ?? []).some((condition) => (condition.piece.rules ?? []).length > 0 || hasConditionalRules(condition.piece));
|
|
1065
1177
|
/** Global CSS is emitted whether or not its condition is active. */
|
|
1066
1178
|
const collectGlobalCss = (style) => [...style.globalCss ?? [], ...(style.conditions ?? []).flatMap((condition) => collectGlobalCss(condition.piece))];
|
|
1067
|
-
/**
|
|
1068
|
-
|
|
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) => {
|
|
1069
1186
|
const rules = style.rules ?? [];
|
|
1070
|
-
const globalRules = collectGlobalCss(style);
|
|
1071
1187
|
const generated = rules.length === 0 ? void 0 : className(rules);
|
|
1072
|
-
|
|
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,
|
|
1073
1198
|
classes: generated === void 0 ? style.classes : Object.freeze([...style.classes, generated]),
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
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
|
|
1078
1215
|
},
|
|
1079
|
-
...globalRules.length === 0 ? {} : { globalRules }
|
|
1216
|
+
...globalRules.length === 0 ? {} : { globalRules },
|
|
1217
|
+
compiled: collected
|
|
1080
1218
|
};
|
|
1081
1219
|
};
|
|
1082
|
-
/** A rule's class is static while a `whenInput` condition is not, so they cannot combine. */
|
|
1083
|
-
const assertRulesSupported = (style) => {
|
|
1084
|
-
if (!hasConditionalRules(style)) return;
|
|
1085
|
-
throw new DiagnosticError({
|
|
1086
|
-
source: "mixins",
|
|
1087
|
-
code: "style:conditional-rules-unsupported",
|
|
1088
|
-
severity: "error",
|
|
1089
|
-
message: "Style.pseudo/media may not appear inside Style.whenInput"
|
|
1090
|
-
});
|
|
1091
|
-
};
|
|
1092
1220
|
/**
|
|
1093
1221
|
* A static style stays static data; a style with input conditions compiles to a
|
|
1094
1222
|
* message-free `InputContribution`, so it still attaches to any view.
|
|
@@ -1101,12 +1229,9 @@ const contributionFrom = (style, compiled) => {
|
|
|
1101
1229
|
...compiled.css === void 0 ? {} : { css: compiled.css },
|
|
1102
1230
|
...globalCss === void 0 ? {} : { globalCss }
|
|
1103
1231
|
};
|
|
1104
|
-
if ((style.conditions ?? []).length === 0) return Object.freeze(attributes);
|
|
1232
|
+
if ((style.conditions ?? []).length === 0 && (style.items ?? []).length === 0) return Object.freeze(attributes);
|
|
1105
1233
|
const contribution = (context) => {
|
|
1106
|
-
const resolved = resolveStyle(
|
|
1107
|
-
...style,
|
|
1108
|
-
classes: compiled.classes
|
|
1109
|
-
}, context.input);
|
|
1234
|
+
const resolved = resolveStyle(compiled.tree, context.input, context.item);
|
|
1110
1235
|
return Object.freeze({
|
|
1111
1236
|
classes: resolved.classes,
|
|
1112
1237
|
style: resolved.style,
|
|
@@ -1119,6 +1244,7 @@ const contributionFrom = (style, compiled) => {
|
|
|
1119
1244
|
const forSlots = (slots) => (pieces, options) => {
|
|
1120
1245
|
const known = slots;
|
|
1121
1246
|
const contributions = Object.create(null);
|
|
1247
|
+
const compiledPieces = {};
|
|
1122
1248
|
const rules = [];
|
|
1123
1249
|
const globalRules = [];
|
|
1124
1250
|
let css = "";
|
|
@@ -1139,15 +1265,13 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1139
1265
|
slot: key
|
|
1140
1266
|
});
|
|
1141
1267
|
if (piece !== void 0) {
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
});
|
|
1150
|
-
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;
|
|
1151
1275
|
}
|
|
1152
1276
|
if (compiled.globalRules !== void 0) {
|
|
1153
1277
|
globalRules.push(...compiled.globalRules);
|
|
@@ -1157,7 +1281,7 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1157
1281
|
}
|
|
1158
1282
|
return Object.freeze({
|
|
1159
1283
|
...options?.name === void 0 ? {} : { name: options.name },
|
|
1160
|
-
pieces,
|
|
1284
|
+
pieces: options?.layer === void 0 ? pieces : compiledPieces,
|
|
1161
1285
|
mixin: dynamic(options?.name ?? "Style", contributions),
|
|
1162
1286
|
css,
|
|
1163
1287
|
globalCss,
|
|
@@ -1165,15 +1289,72 @@ const forSlots = (slots) => (pieces, options) => {
|
|
|
1165
1289
|
globalRules: Object.freeze(globalRules)
|
|
1166
1290
|
});
|
|
1167
1291
|
};
|
|
1168
|
-
|
|
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
|
+
*/
|
|
1169
1332
|
const stylesheet = (...styles) => {
|
|
1170
1333
|
const scoped = /* @__PURE__ */ new Map();
|
|
1171
1334
|
const global = /* @__PURE__ */ new Set();
|
|
1335
|
+
let order;
|
|
1172
1336
|
for (const style of styles) {
|
|
1173
|
-
|
|
1174
|
-
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);
|
|
1175
1352
|
}
|
|
1176
|
-
return [
|
|
1353
|
+
return [
|
|
1354
|
+
...order === void 0 ? [] : [order],
|
|
1355
|
+
...global,
|
|
1356
|
+
...scoped.values()
|
|
1357
|
+
].join("");
|
|
1177
1358
|
};
|
|
1178
1359
|
const attach = (style) => (view) => attach$2(style.mixin)(view);
|
|
1179
1360
|
/** A recipe is just Style data: base, one piece per selected variant, then any
|
|
@@ -1191,43 +1372,119 @@ const recipe = (def) => (selection) => {
|
|
|
1191
1372
|
if (piece !== void 0) pieces.push(piece);
|
|
1192
1373
|
}
|
|
1193
1374
|
for (const compound of def.compound ?? []) if (Object.entries(compound.when).every(([variant, value]) => effective[variant] === value)) pieces.push(compound.style);
|
|
1194
|
-
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);
|
|
1195
1455
|
};
|
|
1196
1456
|
const Style = {
|
|
1197
1457
|
class: classPiece,
|
|
1198
1458
|
inline,
|
|
1199
|
-
compose,
|
|
1459
|
+
compose: compose$1,
|
|
1200
1460
|
when,
|
|
1201
1461
|
whenInput,
|
|
1202
1462
|
pseudo,
|
|
1463
|
+
self,
|
|
1203
1464
|
media,
|
|
1204
1465
|
supports,
|
|
1205
1466
|
container,
|
|
1206
1467
|
nest,
|
|
1468
|
+
states,
|
|
1469
|
+
responsive,
|
|
1470
|
+
vars,
|
|
1471
|
+
enter,
|
|
1472
|
+
allowDiscrete,
|
|
1473
|
+
viewTransitionName,
|
|
1474
|
+
grid,
|
|
1207
1475
|
keyframes,
|
|
1208
1476
|
global,
|
|
1209
|
-
empty,
|
|
1477
|
+
empty: empty$1,
|
|
1478
|
+
perItem,
|
|
1479
|
+
stagger,
|
|
1210
1480
|
forSlots,
|
|
1481
|
+
forCapability,
|
|
1211
1482
|
attach,
|
|
1212
1483
|
recipe,
|
|
1484
|
+
recipeFor,
|
|
1213
1485
|
stylesheet
|
|
1214
1486
|
};
|
|
1215
1487
|
//#endregion
|
|
1216
|
-
|
|
1217
|
-
const VAR_PREFIX = "--fk";
|
|
1218
|
-
const define = (tokens) => Object.freeze(Object.fromEntries(Object.entries(tokens).map(([group, names]) => [group, Object.freeze({ ...names })])));
|
|
1219
|
-
const variable = (_theme, group, name) => `var(${VAR_PREFIX}-${group}-${name})`;
|
|
1220
|
-
const variables = (theme) => {
|
|
1221
|
-
const style = {};
|
|
1222
|
-
for (const [group, names] of Object.entries(theme)) for (const [name, value] of Object.entries(names)) style[`${VAR_PREFIX}-${group}-${name}`] = value;
|
|
1223
|
-
return inline(style);
|
|
1224
|
-
};
|
|
1225
|
-
const Theme = {
|
|
1226
|
-
define,
|
|
1227
|
-
variable,
|
|
1228
|
-
variables
|
|
1229
|
-
};
|
|
1230
|
-
//#endregion
|
|
1231
|
-
export { a11y_exports as A11y, attr_exports as Attr, attributes_exports as Attributes, 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 };
|
|
1232
1489
|
|
|
1233
1490
|
//# sourceMappingURL=index.mjs.map
|