foldkit-mixins 0.3.0 → 0.5.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 +459 -10
- package/dist/app.d.mts +46 -0
- package/dist/app.d.mts.map +1 -0
- package/dist/app.mjs +45 -0
- package/dist/app.mjs.map +1 -0
- package/dist/core-Bxj0UQDF.mjs +53 -0
- package/dist/core-Bxj0UQDF.mjs.map +1 -0
- package/dist/core-CUw_n1Nd.d.mts +40 -0
- package/dist/core-CUw_n1Nd.d.mts.map +1 -0
- package/dist/defaults.d.mts +31 -0
- package/dist/defaults.d.mts.map +1 -0
- package/dist/defaults.mjs +75 -0
- package/dist/defaults.mjs.map +1 -0
- package/dist/foundations.d.mts +30 -0
- package/dist/foundations.d.mts.map +1 -0
- package/dist/foundations.mjs +71 -0
- package/dist/foundations.mjs.map +1 -0
- package/dist/index.d.mts +137 -536
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +261 -1017
- package/dist/index.mjs.map +1 -1
- package/dist/layers-B31M0tDi.mjs +193 -0
- package/dist/layers-B31M0tDi.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/oklch-BxvCD0oi.d.mts +135 -0
- package/dist/oklch-BxvCD0oi.d.mts.map +1 -0
- package/dist/prose.d.mts +30 -0
- package/dist/prose.d.mts.map +1 -0
- package/dist/prose.mjs +61 -0
- package/dist/prose.mjs.map +1 -0
- package/dist/root-C1u12YMD.mjs +37 -0
- package/dist/root-C1u12YMD.mjs.map +1 -0
- package/dist/root-xyWS6geK.d.mts +25 -0
- package/dist/root-xyWS6geK.d.mts.map +1 -0
- package/dist/slotItem-D6_m6IqP.d.mts +18 -0
- package/dist/slotItem-D6_m6IqP.d.mts.map +1 -0
- package/dist/slotMark-Rdsjb7XI.mjs +135 -0
- package/dist/slotMark-Rdsjb7XI.mjs.map +1 -0
- package/dist/slotView-BtIF2pHo.d.mts +476 -0
- package/dist/slotView-BtIF2pHo.d.mts.map +1 -0
- package/dist/style-CKjLee4e.mjs +1266 -0
- package/dist/style-CKjLee4e.mjs.map +1 -0
- package/dist/style-CtCqaL0l.d.mts +182 -0
- package/dist/style-CtCqaL0l.d.mts.map +1 -0
- package/dist/styleValue-BavTe9MZ.d.mts +72 -0
- package/dist/styleValue-BavTe9MZ.d.mts.map +1 -0
- package/dist/styleValue-_G9jwb17.mjs +248 -0
- package/dist/styleValue-_G9jwb17.mjs.map +1 -0
- package/dist/testing.d.mts +30 -0
- package/dist/testing.d.mts.map +1 -0
- package/dist/testing.mjs +167 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/theme.d.mts +193 -0
- package/dist/theme.d.mts.map +1 -0
- package/dist/theme.mjs +146 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/tokens-BR_qxDR7.d.mts +91 -0
- package/dist/tokens-BR_qxDR7.d.mts.map +1 -0
- package/dist/tokens-DteBJVN-.mjs +117 -0
- package/dist/tokens-DteBJVN-.mjs.map +1 -0
- package/dist/utilities.d.mts +73 -0
- package/dist/utilities.d.mts.map +1 -0
- package/dist/utilities.mjs +90 -0
- package/dist/utilities.mjs.map +1 -0
- package/package.json +59 -7
package/dist/index.mjs
CHANGED
|
@@ -1,115 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
is: () => is$5,
|
|
8
|
-
make: () => make$6,
|
|
9
|
-
nameOf: () => nameOf
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Ported from `effect-atom-jsx/src/MetadataToken.ts`. Kinded name tokens so
|
|
13
|
-
* Event, Attr, Requirement, and Capability share one witness instead of four
|
|
14
|
-
* ad-hoc brands.
|
|
15
|
-
*/
|
|
16
|
-
const MetadataTokenTypeId = Symbol.for("foldkit-mixins/MetadataToken");
|
|
17
|
-
const make$6 = (kind, name) => {
|
|
18
|
-
if (name === "") throw new Error(`${kind} name must be non-empty`);
|
|
19
|
-
return {
|
|
20
|
-
[MetadataTokenTypeId]: {
|
|
21
|
-
Kind: void 0,
|
|
22
|
-
Name: void 0
|
|
23
|
-
},
|
|
24
|
-
kind,
|
|
25
|
-
name
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const is$5 = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, MetadataTokenTypeId);
|
|
29
|
-
const nameOf = (value) => is$5(value) ? value.name : value;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/capability.ts
|
|
32
|
-
/**
|
|
33
|
-
* Ported from `effect-atom-jsx/src/Element.ts` `Capability`, without Handle
|
|
34
|
-
* objects. Inheritance is metadata: a behavior that needs Interactive can
|
|
35
|
-
* attach to TextInput. Lookups go through a Map so `__proto__` is a legal name.
|
|
36
|
-
*/
|
|
37
|
-
var capability_exports = /* @__PURE__ */ __exportAll({
|
|
38
|
-
Base: () => Base,
|
|
39
|
-
Collection: () => Collection,
|
|
40
|
-
Container: () => Container,
|
|
41
|
-
Draggable: () => Draggable,
|
|
42
|
-
Focusable: () => Focusable,
|
|
43
|
-
Interactive: () => Interactive,
|
|
44
|
-
TextInput: () => TextInput,
|
|
45
|
-
describe: () => describe$5,
|
|
46
|
-
extendsCapability: () => extendsCapability,
|
|
47
|
-
is: () => is$4,
|
|
48
|
-
make: () => make$5,
|
|
49
|
-
names: () => names,
|
|
50
|
-
satisfies: () => satisfies
|
|
51
|
-
});
|
|
52
|
-
const parentsByName = /* @__PURE__ */ new Map();
|
|
53
|
-
const registry = /* @__PURE__ */ new Map();
|
|
54
|
-
const is$4 = (value) => is$5(value) && value.kind === "element.capability";
|
|
55
|
-
const make$5 = (name, options) => {
|
|
56
|
-
if (name === "") throw new Error("Capability name must be non-empty");
|
|
57
|
-
const parents = options?.extends ?? [];
|
|
58
|
-
const parentNames = parents.map((parent) => nameOf(parent));
|
|
59
|
-
const existing = registry.get(name);
|
|
60
|
-
if (existing !== void 0) {
|
|
61
|
-
const existingNames = existing.extends.map((parent) => nameOf(parent));
|
|
62
|
-
if (existingNames.length === parentNames.length && existingNames.every((parentName, index) => parentName === parentNames[index])) return existing;
|
|
63
|
-
throw new Error(`Capability "${name}" is already defined with a different extends list`);
|
|
64
|
-
}
|
|
65
|
-
parentsByName.set(name, parentNames);
|
|
66
|
-
const capability = {
|
|
67
|
-
...make$6("element.capability", name),
|
|
68
|
-
extends: Object.freeze([...parents])
|
|
69
|
-
};
|
|
70
|
-
registry.set(name, capability);
|
|
71
|
-
return Object.freeze(capability);
|
|
72
|
-
};
|
|
73
|
-
/** True when `value` is `base` or inherits from it. Ported from AF-UI. */
|
|
74
|
-
const extendsCapability = (value, base) => {
|
|
75
|
-
const valueName = nameOf(value);
|
|
76
|
-
const baseName = nameOf(base);
|
|
77
|
-
if (valueName === baseName) return true;
|
|
78
|
-
const visited = /* @__PURE__ */ new Set();
|
|
79
|
-
const stack = [...parentsByName.get(valueName) ?? []];
|
|
80
|
-
while (stack.length > 0) {
|
|
81
|
-
const current = stack.pop();
|
|
82
|
-
if (current === void 0) continue;
|
|
83
|
-
if (current === baseName) return true;
|
|
84
|
-
if (visited.has(current)) continue;
|
|
85
|
-
visited.add(current);
|
|
86
|
-
stack.push(...parentsByName.get(current) ?? []);
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
};
|
|
90
|
-
const satisfies = (actual, required) => extendsCapability(actual, required);
|
|
91
|
-
const names = (capability) => {
|
|
92
|
-
const seen = /* @__PURE__ */ new Set();
|
|
93
|
-
const walk = (name) => {
|
|
94
|
-
if (seen.has(name)) return;
|
|
95
|
-
seen.add(name);
|
|
96
|
-
for (const parent of parentsByName.get(name) ?? []) walk(parent);
|
|
97
|
-
};
|
|
98
|
-
walk(capability.name);
|
|
99
|
-
return [...seen];
|
|
100
|
-
};
|
|
101
|
-
const describe$5 = (capability) => ({
|
|
102
|
-
name: capability.name,
|
|
103
|
-
extends: capability.extends.map((parent) => nameOf(parent))
|
|
104
|
-
});
|
|
105
|
-
const Base = make$5("Base");
|
|
106
|
-
const Interactive = make$5("Interactive", { extends: [Base] });
|
|
107
|
-
const Container = make$5("Container", { extends: [Interactive] });
|
|
108
|
-
const Focusable = make$5("Focusable", { extends: [Interactive] });
|
|
109
|
-
const TextInput = make$5("TextInput", { extends: [Focusable] });
|
|
110
|
-
const Draggable = make$5("Draggable", { extends: [Interactive] });
|
|
111
|
-
const Collection = make$5("Collection", { extends: [Base] });
|
|
112
|
-
//#endregion
|
|
2
|
+
import { _ as extendsCapability, a as slots_exports, b as metadataToken_exports, c as slotView_exports, d as mixin_exports, f as isTagged, g as capability_exports, h as Interactive, l as resolver_exports, m as Focusable, o as slot_exports, p as Container, s as attach$1, t as Style, u as dynamic, v as is$4, x as nameOf, y as make$3 } from "./style-CKjLee4e.mjs";
|
|
3
|
+
import { E as diagnostics_exports, T as DiagnosticError } from "./styleValue-_G9jwb17.mjs";
|
|
4
|
+
import { t as Layers } from "./layers-B31M0tDi.mjs";
|
|
5
|
+
import { t as Theme } from "./core-Bxj0UQDF.mjs";
|
|
6
|
+
import { Option } from "effect";
|
|
113
7
|
//#region src/a11y.ts
|
|
114
8
|
/**
|
|
115
9
|
* Structural accessibility validation. A `Pattern` names the Slots a widget
|
|
@@ -200,46 +94,30 @@ var attr_exports = /* @__PURE__ */ __exportAll({
|
|
|
200
94
|
AriaExpanded: () => AriaExpanded,
|
|
201
95
|
AriaInvalid: () => AriaInvalid,
|
|
202
96
|
AriaLabel: () => AriaLabel,
|
|
97
|
+
AriaPressed: () => AriaPressed,
|
|
203
98
|
AriaSelected: () => AriaSelected,
|
|
204
99
|
Disabled: () => Disabled,
|
|
205
100
|
Role: () => Role,
|
|
206
101
|
Value: () => Value,
|
|
207
|
-
describe: () => describe$
|
|
102
|
+
describe: () => describe$2,
|
|
208
103
|
equals: () => equals$1,
|
|
209
104
|
is: () => is$3,
|
|
210
|
-
make: () => make$
|
|
105
|
+
make: () => make$2
|
|
211
106
|
});
|
|
212
|
-
const is$3 = (value) => is$
|
|
213
|
-
const make$
|
|
107
|
+
const is$3 = (value) => is$4(value) && value.kind === "view.attribute";
|
|
108
|
+
const make$2 = (name) => make$3("view.attribute", name);
|
|
214
109
|
const equals$1 = (left, right) => left.name === right.name;
|
|
215
|
-
const describe$
|
|
216
|
-
const Role = make$
|
|
217
|
-
const AriaLabel = make$
|
|
218
|
-
const AriaDescribedby = make$
|
|
219
|
-
const AriaExpanded = make$
|
|
220
|
-
const AriaSelected = make$
|
|
221
|
-
const AriaInvalid = make$
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
//#region src/attribute.ts
|
|
227
|
-
/** The brand `childAttribute.d.ts` stamps; Foldkit's guard is not exported. */
|
|
228
|
-
const CHILD_ATTRIBUTE_BRAND = "__childAttribute";
|
|
229
|
-
const isChildAttribute = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, CHILD_ATTRIBUTE_BRAND);
|
|
230
|
-
const isTagged = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, "_tag") && typeof value._tag === "string";
|
|
231
|
-
/** `Class` carries no Message, so the inert builder is the honest constructor. */
|
|
232
|
-
const classAttribute = (value) => inertHtml.Class(value);
|
|
233
|
-
const styleAttribute = (value) => inertHtml.Style(value);
|
|
234
|
-
/**
|
|
235
|
-
* `inertHtml.OnMount` only accepts `MountAction<never>`, so a Message-bearing
|
|
236
|
-
* mount is built directly. The shape is the same tagged value `h.OnMount`
|
|
237
|
-
* produces (`{ _tag: 'OnMount', action }`).
|
|
238
|
-
*/
|
|
239
|
-
const mountAttribute = (action) => ({
|
|
240
|
-
_tag: "OnMount",
|
|
241
|
-
action
|
|
242
|
-
});
|
|
110
|
+
const describe$2 = (attr) => ({ name: attr.name });
|
|
111
|
+
const Role = make$2("role");
|
|
112
|
+
const AriaLabel = make$2("aria-label");
|
|
113
|
+
const AriaDescribedby = make$2("aria-describedby");
|
|
114
|
+
const AriaExpanded = make$2("aria-expanded");
|
|
115
|
+
const AriaSelected = make$2("aria-selected");
|
|
116
|
+
const AriaInvalid = make$2("aria-invalid");
|
|
117
|
+
const AriaPressed = make$2("aria-pressed");
|
|
118
|
+
const AriaDisabled = make$2("aria-disabled");
|
|
119
|
+
const Disabled = make$2("disabled");
|
|
120
|
+
const Value = make$2("value");
|
|
243
121
|
//#endregion
|
|
244
122
|
//#region src/attributes.ts
|
|
245
123
|
var attributes_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -255,352 +133,11 @@ const find = (attributes, tag) => attributes.find(hasTag(tag));
|
|
|
255
133
|
/** Every attribute with `tag`, in bundle order. */
|
|
256
134
|
const filter = (attributes, tag) => attributes.filter(hasTag(tag));
|
|
257
135
|
//#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
|
-
//#region src/mixin.ts
|
|
270
|
-
var mixin_exports = /* @__PURE__ */ __exportAll({
|
|
271
|
-
compose: () => compose$1,
|
|
272
|
-
contributionsFor: () => contributionsFor,
|
|
273
|
-
dynamic: () => dynamic,
|
|
274
|
-
empty: () => empty$1,
|
|
275
|
-
evaluate: () => evaluate,
|
|
276
|
-
isDynamic: () => isDynamic,
|
|
277
|
-
make: () => make$3
|
|
278
|
-
});
|
|
279
|
-
const isDynamic = (contribution) => typeof contribution === "function";
|
|
280
|
-
const evaluate = (contribution, context) => isDynamic(contribution) ? contribution(context) : contribution;
|
|
281
|
-
const mergeStatic = (left, right) => {
|
|
282
|
-
const css = `${left.css ?? ""}${right.css ?? ""}`;
|
|
283
|
-
const globalCss = `${left.globalCss ?? ""}${right.globalCss ?? ""}`;
|
|
284
|
-
return Object.freeze({
|
|
285
|
-
classes: Object.freeze([...left.classes ?? [], ...right.classes ?? []]),
|
|
286
|
-
style: Object.freeze({
|
|
287
|
-
...left.style ?? {},
|
|
288
|
-
...right.style ?? {}
|
|
289
|
-
}),
|
|
290
|
-
attributes: Object.freeze([...left.attributes ?? [], ...right.attributes ?? []]),
|
|
291
|
-
mounts: Object.freeze([...left.mounts ?? [], ...right.mounts ?? []]),
|
|
292
|
-
...css === "" ? {} : { css },
|
|
293
|
-
...globalCss === "" ? {} : { globalCss }
|
|
294
|
-
});
|
|
295
|
-
};
|
|
296
|
-
const mergeSlot = (left, right) => {
|
|
297
|
-
if (!isDynamic(left) && !isDynamic(right)) return mergeStatic(left, right);
|
|
298
|
-
return (context) => mergeStatic(evaluate(left, context), evaluate(right, context));
|
|
299
|
-
};
|
|
300
|
-
const make$3 = (name, contributions) => Object.freeze({
|
|
301
|
-
name,
|
|
302
|
-
contributions: Object.freeze({ ...contributions })
|
|
303
|
-
});
|
|
304
|
-
const dynamic = (name, contributions) => Object.freeze({
|
|
305
|
-
name,
|
|
306
|
-
contributions: Object.freeze({ ...contributions })
|
|
307
|
-
});
|
|
308
|
-
const empty$1 = () => make$3("Empty", {});
|
|
309
|
-
const compose$1 = (...mixins) => {
|
|
310
|
-
const merged = Object.create(null);
|
|
311
|
-
for (const mixin of mixins) for (const [slot, contribution] of Object.entries(mixin.contributions)) {
|
|
312
|
-
if (contribution === void 0) continue;
|
|
313
|
-
const normalized = contribution;
|
|
314
|
-
const existing = merged[slot];
|
|
315
|
-
merged[slot] = existing === void 0 ? normalized : mergeSlot(existing, normalized);
|
|
316
|
-
}
|
|
317
|
-
return dynamic(mixins.length === 0 ? "Empty" : mixins.map((mixin) => mixin.name).join("+"), merged);
|
|
318
|
-
};
|
|
319
|
-
const contributionsFor = (mixin, slot) => mixin.contributions[slot];
|
|
320
|
-
//#endregion
|
|
321
|
-
//#region src/pipe.ts
|
|
322
|
-
/** Ported from `effect-atom-jsx/src/View.ts` `pipeSelf`. */
|
|
323
|
-
const pipeSelf = (self, fns) => fns.reduce((acc, fn) => fn(acc), self);
|
|
324
|
-
//#endregion
|
|
325
|
-
//#region src/resolver.ts
|
|
326
|
-
/**
|
|
327
|
-
* The deterministic resolver. `resolve` is pure: it decomposes the base
|
|
328
|
-
* attributes, applies contributions in attachment order, enforces ownership
|
|
329
|
-
* and protection, then emits one canonical `Class`, one `Style`, and at most
|
|
330
|
-
* one `OnMount`. Conflicts throw a `DiagnosticError` before Foldkit could
|
|
331
|
-
* silently chain or replace.
|
|
332
|
-
*/
|
|
333
|
-
var resolver_exports = /* @__PURE__ */ __exportAll({ resolve: () => resolve });
|
|
334
|
-
/** `AriaLabel` -> `arialabel`, `aria-label` -> `arialabel`; tags and tokens agree. */
|
|
335
|
-
const normalizeName = (name) => name.replace(/[^a-z0-9]/gi, "").toLowerCase();
|
|
336
|
-
/** Attribute tags are PascalCase (`OnKeyDown`); event tokens are lowercase. */
|
|
337
|
-
const eventNameOfTag = (tag) => normalizeName(tag.startsWith("On") ? tag.slice(2) : tag);
|
|
338
|
-
const splitClasses = (value) => value.split(/\s+/).filter((token) => token.length > 0);
|
|
339
|
-
/** `Prop`/`Attribute`/`DataAttribute`/`OnCustomEvent` are keyed individually. */
|
|
340
|
-
const ownershipKey = (tag, value) => {
|
|
341
|
-
if (typeof value !== "object" || value === null) return tag;
|
|
342
|
-
const record = value;
|
|
343
|
-
switch (tag) {
|
|
344
|
-
case "Prop":
|
|
345
|
-
case "Attribute":
|
|
346
|
-
case "DataAttribute": return `${tag}:${String(record.key)}`;
|
|
347
|
-
case "OnCustomEvent": return `${tag}:${String(record.name)}`;
|
|
348
|
-
default: return tag;
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
const toDiagnostic = (code, message, slot, details) => ({
|
|
352
|
-
source: "mixins",
|
|
353
|
-
code,
|
|
354
|
-
severity: "error",
|
|
355
|
-
message,
|
|
356
|
-
...slot === void 0 ? {} : { slot },
|
|
357
|
-
details
|
|
358
|
-
});
|
|
359
|
-
const resolve = (base, contributions, options = {}) => {
|
|
360
|
-
const slot = options.slot;
|
|
361
|
-
const protection = options.protected;
|
|
362
|
-
const protectedEvents = new Set((protection?.events ?? []).map((event) => normalizeName(nameOf(event))));
|
|
363
|
-
const protectedAttributes = new Set((protection?.attributes ?? []).map((attr) => normalizeName(nameOf(attr))));
|
|
364
|
-
const protectedStyle = new Set(protection?.style ?? []);
|
|
365
|
-
const classes = [];
|
|
366
|
-
const classSeen = /* @__PURE__ */ new Set();
|
|
367
|
-
const style = /* @__PURE__ */ new Map();
|
|
368
|
-
const mounts = [];
|
|
369
|
-
const mountNames = /* @__PURE__ */ new Map();
|
|
370
|
-
const preserved = [];
|
|
371
|
-
const added = [];
|
|
372
|
-
const ownedEvents = /* @__PURE__ */ new Map();
|
|
373
|
-
const ownedAttributes = /* @__PURE__ */ new Map();
|
|
374
|
-
function fail(code, message, details) {
|
|
375
|
-
throw new DiagnosticError(toDiagnostic(code, message, slot, details));
|
|
376
|
-
}
|
|
377
|
-
const addClass = (token) => {
|
|
378
|
-
if (classSeen.has(token)) return;
|
|
379
|
-
classSeen.add(token);
|
|
380
|
-
classes.push(token);
|
|
381
|
-
};
|
|
382
|
-
const addMount = (action) => {
|
|
383
|
-
const count = (mountNames.get(action.name) ?? 0) + 1;
|
|
384
|
-
mountNames.set(action.name, count);
|
|
385
|
-
if (count > 1) fail("mixins:duplicate-mount-name", `two Mounts are both named "${action.name}"`, { name: action.name });
|
|
386
|
-
mounts.push(action);
|
|
387
|
-
};
|
|
388
|
-
const reserve = (tag, value) => {
|
|
389
|
-
if (tag === "OnMount") return;
|
|
390
|
-
if (tag.startsWith("On") && tag !== "OnCustomEvent") {
|
|
391
|
-
ownedEvents.set(eventNameOfTag(tag), tag);
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
ownedAttributes.set(ownershipKey(tag, value), tag);
|
|
395
|
-
};
|
|
396
|
-
const addBase = (attribute) => {
|
|
397
|
-
if (isChildAttribute(attribute)) {
|
|
398
|
-
const inner = attribute.attribute;
|
|
399
|
-
if (isTagged(inner)) reserve(inner._tag, inner);
|
|
400
|
-
preserved.push(attribute);
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
const tag = attribute._tag;
|
|
404
|
-
switch (tag) {
|
|
405
|
-
case "Class":
|
|
406
|
-
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
407
|
-
return;
|
|
408
|
-
case "Style":
|
|
409
|
-
for (const [property, value] of Object.entries(attribute.value)) style.set(property, value);
|
|
410
|
-
return;
|
|
411
|
-
case "OnMount":
|
|
412
|
-
addMount(attribute.action);
|
|
413
|
-
return;
|
|
414
|
-
default:
|
|
415
|
-
reserve(tag, attribute);
|
|
416
|
-
preserved.push(attribute);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
const applyMixinAttribute = (attribute) => {
|
|
420
|
-
if (isChildAttribute(attribute)) {
|
|
421
|
-
const inner = attribute.attribute;
|
|
422
|
-
if (isTagged(inner)) reserve(inner._tag, inner);
|
|
423
|
-
added.push(attribute);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
const tag = attribute._tag;
|
|
427
|
-
switch (tag) {
|
|
428
|
-
case "Class":
|
|
429
|
-
for (const token of splitClasses(attribute.value)) addClass(token);
|
|
430
|
-
return;
|
|
431
|
-
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
|
-
}
|
|
436
|
-
return;
|
|
437
|
-
case "OnMount":
|
|
438
|
-
addMount(attribute.action);
|
|
439
|
-
return;
|
|
440
|
-
case "Key":
|
|
441
|
-
case "InnerHTML": fail("mixins:structural-override", `a Mixin may not contribute "${tag}"; it is structural ownership`, { tag });
|
|
442
|
-
default:
|
|
443
|
-
if (tag.startsWith("On") && tag !== "OnCustomEvent") {
|
|
444
|
-
const eventName = eventNameOfTag(tag);
|
|
445
|
-
if (protectedEvents.has(eventName)) fail("mixins:protected-event", `slot "${slot ?? "?"}" protects event "${eventName}"`, {
|
|
446
|
-
tag,
|
|
447
|
-
event: eventName
|
|
448
|
-
});
|
|
449
|
-
const owner = ownedEvents.get(eventName);
|
|
450
|
-
if (owner !== void 0) fail("mixins:event-conflict", `two owners for event "${eventName}": "${owner}" already owns it`, {
|
|
451
|
-
tag,
|
|
452
|
-
event: eventName,
|
|
453
|
-
owner
|
|
454
|
-
});
|
|
455
|
-
ownedEvents.set(eventName, tag);
|
|
456
|
-
} else {
|
|
457
|
-
const key = ownershipKey(tag, attribute);
|
|
458
|
-
if (protectedAttributes.has(normalizeName(tag))) fail("mixins:protected-attribute", `slot "${slot ?? "?"}" protects attribute "${tag}"`, { tag });
|
|
459
|
-
const owner = ownedAttributes.get(key);
|
|
460
|
-
if (owner !== void 0) fail("mixins:attribute-conflict", `two owners for "${key}": a ${owner} attribute already occupies it`, {
|
|
461
|
-
tag,
|
|
462
|
-
key,
|
|
463
|
-
owner
|
|
464
|
-
});
|
|
465
|
-
ownedAttributes.set(key, tag);
|
|
466
|
-
}
|
|
467
|
-
added.push(attribute);
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
for (const attribute of base ?? []) addBase(attribute);
|
|
471
|
-
for (const contribution of contributions) {
|
|
472
|
-
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
|
-
}
|
|
477
|
-
for (const attribute of contribution.attributes ?? []) applyMixinAttribute(attribute);
|
|
478
|
-
for (const mount of contribution.mounts ?? []) addMount(mount);
|
|
479
|
-
}
|
|
480
|
-
const emitted = [];
|
|
481
|
-
if (classes.length > 0) emitted.push(classAttribute(classes.join(" ")));
|
|
482
|
-
if (style.size > 0) emitted.push(styleAttribute(Object.fromEntries(style)));
|
|
483
|
-
emitted.push(...preserved, ...added);
|
|
484
|
-
const composed = composeMounts(mounts, slot);
|
|
485
|
-
if (composed !== void 0) emitted.push(composed);
|
|
486
|
-
return emitted;
|
|
487
|
-
};
|
|
488
|
-
const composeMounts = (mounts, slot) => {
|
|
489
|
-
const first = mounts[0];
|
|
490
|
-
if (first === void 0) return void 0;
|
|
491
|
-
if (mounts.length === 1) return mountAttribute(first);
|
|
492
|
-
const name = `Mixins[${slot ?? "slot"}](${mounts.map((mount) => mount.name).join(",")})`;
|
|
493
|
-
return mountAttribute({
|
|
494
|
-
name,
|
|
495
|
-
args: {
|
|
496
|
-
slot: slot ?? null,
|
|
497
|
-
actions: mounts.map((mount) => ({
|
|
498
|
-
name: mount.name,
|
|
499
|
-
args: mount.args
|
|
500
|
-
}))
|
|
501
|
-
},
|
|
502
|
-
f: (element, viewStateChanges) => Stream.mergeAll(mounts.map((mount) => mount.f(element, viewStateChanges)), { concurrency: "unbounded" })
|
|
503
|
-
});
|
|
504
|
-
};
|
|
505
|
-
//#endregion
|
|
506
|
-
//#region src/slotView.ts
|
|
507
|
-
/**
|
|
508
|
-
* `SlotView` is the structural equivalent of a Surface: a pure Foldkit view
|
|
509
|
-
* that publishes typed Slots and lets Mixins attach without forking it. It
|
|
510
|
-
* owns no state and runs no Effects. Attached Mixins are resolved into
|
|
511
|
-
* ordinary Foldkit attributes per slot, using the view's own `h` so Message
|
|
512
|
-
* capability masking is preserved.
|
|
513
|
-
*/
|
|
514
|
-
var slotView_exports = /* @__PURE__ */ __exportAll({
|
|
515
|
-
attach: () => attach$2,
|
|
516
|
-
buildersFor: () => buildersFor,
|
|
517
|
-
define: () => define$2,
|
|
518
|
-
forMessages: () => forMessages,
|
|
519
|
-
inertBuilder: () => inertBuilder
|
|
520
|
-
});
|
|
521
|
-
/** Build one `attrs` resolver per published slot, evaluating Mixins lazily. */
|
|
522
|
-
const buildersFor = (slots, mixins, context) => {
|
|
523
|
-
const source = slots;
|
|
524
|
-
const builders = Object.create(null);
|
|
525
|
-
for (const name of Object.getOwnPropertyNames(source)) {
|
|
526
|
-
const slot = source[name];
|
|
527
|
-
if (slot === void 0) continue;
|
|
528
|
-
const protection = slot.protected;
|
|
529
|
-
builders[name] = { attrs: (base) => {
|
|
530
|
-
const contributions = [];
|
|
531
|
-
for (const mixin of mixins) {
|
|
532
|
-
const contribution = mixin.contributions[name];
|
|
533
|
-
if (contribution !== void 0) contributions.push(evaluate(contribution, {
|
|
534
|
-
input: context.input,
|
|
535
|
-
h: context.h
|
|
536
|
-
}));
|
|
537
|
-
}
|
|
538
|
-
return resolve(base, contributions, {
|
|
539
|
-
slot: name,
|
|
540
|
-
protected: protection
|
|
541
|
-
});
|
|
542
|
-
} };
|
|
543
|
-
}
|
|
544
|
-
return builders;
|
|
545
|
-
};
|
|
546
|
-
const makeView = (name, slots, mixins, render) => {
|
|
547
|
-
const view = (input, h) => render(input, buildersFor(slots, mixins, {
|
|
548
|
-
input,
|
|
549
|
-
h
|
|
550
|
-
}), h);
|
|
551
|
-
if (name !== void 0) Object.defineProperty(view, "name", {
|
|
552
|
-
value: name,
|
|
553
|
-
configurable: true
|
|
554
|
-
});
|
|
555
|
-
return Object.assign(view, {
|
|
556
|
-
slots,
|
|
557
|
-
mixins,
|
|
558
|
-
render,
|
|
559
|
-
pipe: (...fns) => pipeSelf(view, fns)
|
|
560
|
-
});
|
|
561
|
-
};
|
|
562
|
-
/**
|
|
563
|
-
* Defines a view over published Slots.
|
|
564
|
-
*
|
|
565
|
-
* `Message` has no anchor but the render callback's builder, so it is inferred
|
|
566
|
-
* from an explicit `h: HtmlBuilder<Message>` annotation on that parameter.
|
|
567
|
-
* Without one it resolves to `unknown`, and the first error appears later and
|
|
568
|
-
* elsewhere — an invariance mismatch at `Style.attach`/`Behavior.attach` that
|
|
569
|
-
* does not name the missing annotation. `forMessages<Message>()` fixes the
|
|
570
|
-
* Message universe up front instead, and leaves `h` contextually typed.
|
|
571
|
-
*/
|
|
572
|
-
const define$2 = (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;
|
|
580
|
-
/**
|
|
581
|
-
* Binds the view constructors to one Message universe, so the render callback
|
|
582
|
-
* no longer has to annotate `h` to pin it. `Input` is still inferred from the
|
|
583
|
-
* callback's own `input` annotation.
|
|
584
|
-
*
|
|
585
|
-
* @example
|
|
586
|
-
* ```ts
|
|
587
|
-
* const Field = SlotView.forMessages<Message>().define(
|
|
588
|
-
* FieldSlots,
|
|
589
|
-
* (input: FieldInput, slots, h) =>
|
|
590
|
-
* h.input(slots.input.attrs([h.OnInput(value => Message.ChangedValue({ value }))])),
|
|
591
|
-
* )
|
|
592
|
-
* ```
|
|
593
|
-
*/
|
|
594
|
-
const forMessages = () => ({ define: define$2 });
|
|
595
|
-
function attach$2(mixin) {
|
|
596
|
-
return (view) => makeView(view.name, view.slots, [...view.mixins, mixin], view.render);
|
|
597
|
-
}
|
|
598
|
-
//#endregion
|
|
599
136
|
//#region src/behavior.ts
|
|
600
137
|
var behavior_exports = /* @__PURE__ */ __exportAll({
|
|
601
138
|
Behavior: () => Behavior,
|
|
602
|
-
attach: () => attach
|
|
603
|
-
forSlots: () => forSlots
|
|
139
|
+
attach: () => attach,
|
|
140
|
+
forSlots: () => forSlots,
|
|
604
141
|
slot: () => slot
|
|
605
142
|
});
|
|
606
143
|
/** Identity helper; `forSlots` supplies the contextual `Input`/`Message`. */
|
|
@@ -626,7 +163,7 @@ const validateRequirements = (name, slot, requirements) => {
|
|
|
626
163
|
if (!slot.attributes.some((allowed) => nameOf(allowed) === attributeName)) fail("mixins:unsupported-attribute", `Behavior requires attribute "${attributeName}" on slot "${name}", which does not publish it`, name, { attribute: attributeName });
|
|
627
164
|
}
|
|
628
165
|
};
|
|
629
|
-
const forSlots
|
|
166
|
+
const forSlots = (slots) => (spec, options) => {
|
|
630
167
|
const source = slots;
|
|
631
168
|
const contributions = Object.create(null);
|
|
632
169
|
for (const [name, slotOptions] of Object.entries(spec)) {
|
|
@@ -640,9 +177,10 @@ const forSlots$1 = (slots) => (spec, options) => {
|
|
|
640
177
|
contributions[name] = (context) => ({
|
|
641
178
|
...attributes === void 0 ? {} : { attributes: attributes({
|
|
642
179
|
input: context.input,
|
|
643
|
-
h: context.h
|
|
180
|
+
h: context.h,
|
|
181
|
+
...context.item === void 0 ? {} : { item: context.item }
|
|
644
182
|
}) },
|
|
645
|
-
...mount === void 0 ? {} : { mounts: [mount(context.input)] }
|
|
183
|
+
...mount === void 0 ? {} : { mounts: [mount(context.input, context.item)] }
|
|
646
184
|
});
|
|
647
185
|
}
|
|
648
186
|
return Object.freeze({
|
|
@@ -658,13 +196,192 @@ const forSlots$1 = (slots) => (spec, options) => {
|
|
|
658
196
|
* widens what the view must be called with. Declare `Input` as the view's own
|
|
659
197
|
* input type.
|
|
660
198
|
*/
|
|
661
|
-
const attach
|
|
199
|
+
const attach = (behavior) => (view) => attach$1(behavior.mixin)(view);
|
|
662
200
|
const Behavior = {
|
|
663
201
|
slot,
|
|
664
|
-
forSlots
|
|
665
|
-
attach
|
|
202
|
+
forSlots,
|
|
203
|
+
attach
|
|
666
204
|
};
|
|
667
205
|
//#endregion
|
|
206
|
+
//#region src/behaviors/collection.ts
|
|
207
|
+
var collection_exports = /* @__PURE__ */ __exportAll({
|
|
208
|
+
behavior: () => behavior$4,
|
|
209
|
+
of: () => of
|
|
210
|
+
});
|
|
211
|
+
/** Describes `items` once. Two items with one id are refused, since an id is what
|
|
212
|
+
* `aria-activedescendant`, `aria-controls`, and a keyed row rely on. */
|
|
213
|
+
const of = (items, describe) => {
|
|
214
|
+
const ids = [];
|
|
215
|
+
const indexById = /* @__PURE__ */ new Map();
|
|
216
|
+
const disabled = [];
|
|
217
|
+
const enabled = [];
|
|
218
|
+
items.forEach((item, index) => {
|
|
219
|
+
const id = describe.id(item, index);
|
|
220
|
+
const seen = indexById.get(id);
|
|
221
|
+
if (seen !== void 0) throw new DiagnosticError({
|
|
222
|
+
source: "mixins",
|
|
223
|
+
code: "mixins:duplicate-item-id",
|
|
224
|
+
severity: "error",
|
|
225
|
+
message: `Collection items ${seen} and ${index} share the id "${id}"`,
|
|
226
|
+
details: {
|
|
227
|
+
id,
|
|
228
|
+
indices: [seen, index]
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
indexById.set(id, index);
|
|
232
|
+
ids.push(id);
|
|
233
|
+
const isDisabled = describe.disabled?.(item, index) ?? false;
|
|
234
|
+
disabled.push(isDisabled);
|
|
235
|
+
if (!isDisabled) enabled.push(index);
|
|
236
|
+
});
|
|
237
|
+
const size = items.length;
|
|
238
|
+
return Object.freeze({
|
|
239
|
+
size,
|
|
240
|
+
ids: Object.freeze(ids),
|
|
241
|
+
at: (index) => items[index],
|
|
242
|
+
indexOf: (id) => indexById.get(id) ?? -1,
|
|
243
|
+
isDisabled: (index) => disabled[index] ?? false,
|
|
244
|
+
enabled: Object.freeze(enabled),
|
|
245
|
+
slotItem: (index) => ({
|
|
246
|
+
index,
|
|
247
|
+
id: ids[index] ?? String(index),
|
|
248
|
+
count: size
|
|
249
|
+
})
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* Writes each item's identity and position: `id` from the described id,
|
|
254
|
+
* `aria-disabled` for a disabled item, and `aria-posinset` and `aria-setsize`
|
|
255
|
+
* on request. Reads the item context the view passes to `attrs`; with none it
|
|
256
|
+
* contributes nothing, so a slot rendered once is left alone.
|
|
257
|
+
*/
|
|
258
|
+
const behavior$4 = (slots) => (options) => forSlots(slots)({ [options.item]: slot({ attributes: ({ input, h, item }) => {
|
|
259
|
+
if (item === void 0) return [];
|
|
260
|
+
const items = options.items(input);
|
|
261
|
+
const id = item.id ?? items.ids[item.index];
|
|
262
|
+
return [
|
|
263
|
+
...options.ids === false || id === void 0 ? [] : [h.Id(id)],
|
|
264
|
+
...items.isDisabled(item.index) ? [h.AriaDisabled(true)] : [],
|
|
265
|
+
...options.posInSet === true ? [h.AriaPosinset(item.index + 1), h.AriaSetsize(item.count ?? items.size)] : []
|
|
266
|
+
];
|
|
267
|
+
} }) }, { name: "Collection" });
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/behaviors/disclosure.ts
|
|
270
|
+
var disclosure_exports = /* @__PURE__ */ __exportAll({ behavior: () => behavior$3 });
|
|
271
|
+
const behavior$3 = (slots) => (options) => forSlots(slots)({
|
|
272
|
+
[options.trigger]: slot({
|
|
273
|
+
requires: { capability: Interactive },
|
|
274
|
+
attributes: ({ input, h }) => [h.AriaExpanded(options.open(input)), h.AriaControls(options.id(input))]
|
|
275
|
+
}),
|
|
276
|
+
[options.content]: slot({
|
|
277
|
+
requires: { capability: Container },
|
|
278
|
+
attributes: ({ input, h }) => [h.Id(options.id(input)), h.Hidden(!options.open(input))]
|
|
279
|
+
})
|
|
280
|
+
}, { name: "Disclosure" });
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/behaviors/field-association.ts
|
|
283
|
+
var field_association_exports = /* @__PURE__ */ __exportAll({
|
|
284
|
+
behavior: () => behavior$2,
|
|
285
|
+
ids: () => ids
|
|
286
|
+
});
|
|
287
|
+
/** The ids one base id yields, for a view that renders these elements itself. */
|
|
288
|
+
const ids = (id) => ({
|
|
289
|
+
control: id,
|
|
290
|
+
label: `${id}-label`,
|
|
291
|
+
description: `${id}-description`,
|
|
292
|
+
error: `${id}-error`
|
|
293
|
+
});
|
|
294
|
+
const behavior$2 = (slots) => (options) => forSlots(slots)({
|
|
295
|
+
[options.control]: slot({
|
|
296
|
+
requires: { capability: Interactive },
|
|
297
|
+
attributes: ({ input, h }) => {
|
|
298
|
+
const names = ids(options.id(input));
|
|
299
|
+
const invalid = options.invalid?.(input) === true;
|
|
300
|
+
const describedBy = [...options.description === void 0 ? [] : [names.description], ...options.error !== void 0 && invalid ? [names.error] : []];
|
|
301
|
+
return [
|
|
302
|
+
h.Id(names.control),
|
|
303
|
+
h.AriaLabelledBy(names.label),
|
|
304
|
+
...describedBy.length === 0 ? [] : [h.AriaDescribedBy(describedBy.join(" "))],
|
|
305
|
+
...invalid ? [h.AriaInvalid(true)] : [],
|
|
306
|
+
...options.required?.(input) === true ? [h.AriaRequired(true)] : []
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
}),
|
|
310
|
+
[options.label]: slot({ attributes: ({ input, h }) => {
|
|
311
|
+
const names = ids(options.id(input));
|
|
312
|
+
return [h.Id(names.label), h.For(names.control)];
|
|
313
|
+
} }),
|
|
314
|
+
...options.description === void 0 ? {} : { [options.description]: slot({ attributes: ({ input, h }) => [h.Id(ids(options.id(input)).description)] }) },
|
|
315
|
+
...options.error === void 0 ? {} : { [options.error]: slot({ attributes: ({ input, h }) => [h.Id(ids(options.id(input)).error)] }) }
|
|
316
|
+
}, { name: "FieldAssociation" });
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/behaviors/spin-value.ts
|
|
319
|
+
/**
|
|
320
|
+
* A number stepped by keys: ArrowUp and ArrowDown by `step`, PageUp and
|
|
321
|
+
* PageDown by `page`, Home and End to the bounds, each clamped, each
|
|
322
|
+
* default-prevented. The value is the parent's; a key yields the Message the
|
|
323
|
+
* caller builds from the next value. Writes the spinbutton role and its
|
|
324
|
+
* `aria-value*`. The floor is `<input type="number">`; a press-and-hold
|
|
325
|
+
* repeat and a wheel are not handled, since Foldkit's wheel attribute carries
|
|
326
|
+
* no delta and a repeat is a timer the Model would have to own.
|
|
327
|
+
*/
|
|
328
|
+
var spin_value_exports = /* @__PURE__ */ __exportAll({
|
|
329
|
+
behavior: () => behavior$1,
|
|
330
|
+
spin: () => spin
|
|
331
|
+
});
|
|
332
|
+
const clamp = (value, bounds) => Math.min(bounds.max ?? Number.POSITIVE_INFINITY, Math.max(bounds.min ?? Number.NEGATIVE_INFINITY, value));
|
|
333
|
+
/** The value the key moves to, or `undefined` when the key is not a spin key or a chord. */
|
|
334
|
+
const spin = (value, key, modifiers, bounds) => {
|
|
335
|
+
if (modifiers.ctrlKey || modifiers.altKey || modifiers.metaKey) return void 0;
|
|
336
|
+
const step = bounds.step ?? 1;
|
|
337
|
+
const page = bounds.page ?? step * 10;
|
|
338
|
+
switch (key) {
|
|
339
|
+
case "ArrowUp": return clamp(value + step, bounds);
|
|
340
|
+
case "ArrowDown": return clamp(value - step, bounds);
|
|
341
|
+
case "PageUp": return clamp(value + page, bounds);
|
|
342
|
+
case "PageDown": return clamp(value - page, bounds);
|
|
343
|
+
case "Home": return bounds.min;
|
|
344
|
+
case "End": return bounds.max;
|
|
345
|
+
default: return;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
const behavior$1 = (slots) => (options) => forSlots(slots)({ [options.control]: slot({
|
|
349
|
+
requires: { capability: Focusable },
|
|
350
|
+
attributes: ({ input, h }) => {
|
|
351
|
+
const value = options.value(input);
|
|
352
|
+
return [
|
|
353
|
+
h.Role("spinbutton"),
|
|
354
|
+
h.AriaValuenow(value),
|
|
355
|
+
...options.min === void 0 ? [] : [h.AriaValuemin(options.min)],
|
|
356
|
+
...options.max === void 0 ? [] : [h.AriaValuemax(options.max)],
|
|
357
|
+
...options.text === void 0 ? [] : [h.AriaValuetext(options.text(input))],
|
|
358
|
+
h.OnKeyDownPreventDefault((key, modifiers) => {
|
|
359
|
+
const next = spin(value, key, modifiers, options);
|
|
360
|
+
return next === void 0 || next === value ? Option.none() : Option.some(options.onChange(next));
|
|
361
|
+
})
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
}) }, { name: "SpinValue" });
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/behaviors/toggle-state.ts
|
|
367
|
+
var toggle_state_exports = /* @__PURE__ */ __exportAll({ behavior: () => behavior });
|
|
368
|
+
const behavior = (slots) => (options) => forSlots(slots)({ [options.control]: slot({
|
|
369
|
+
requires: { capability: Interactive },
|
|
370
|
+
attributes: ({ input, h }) => {
|
|
371
|
+
const state = options.state(input);
|
|
372
|
+
return options.as === "checked" ? [h.AriaChecked(state)] : [h.AriaPressed(state === "mixed" ? "mixed" : state ? "true" : "false")];
|
|
373
|
+
}
|
|
374
|
+
}) }, { name: "ToggleState" });
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/behaviors/index.ts
|
|
377
|
+
var behaviors_exports = /* @__PURE__ */ __exportAll({
|
|
378
|
+
Collection: () => collection_exports,
|
|
379
|
+
Disclosure: () => disclosure_exports,
|
|
380
|
+
FieldAssociation: () => field_association_exports,
|
|
381
|
+
SpinValue: () => spin_value_exports,
|
|
382
|
+
ToggleState: () => toggle_state_exports
|
|
383
|
+
});
|
|
384
|
+
//#endregion
|
|
668
385
|
//#region src/event.ts
|
|
669
386
|
/**
|
|
670
387
|
* Slot event tokens. Ported from `effect-atom-jsx/src/View.ts` `Event`, plus
|
|
@@ -683,27 +400,27 @@ var event_exports = /* @__PURE__ */ __exportAll({
|
|
|
683
400
|
PointerUp: () => PointerUp,
|
|
684
401
|
Press: () => Press,
|
|
685
402
|
Submit: () => Submit,
|
|
686
|
-
describe: () => describe$
|
|
403
|
+
describe: () => describe$1,
|
|
687
404
|
equals: () => equals,
|
|
688
405
|
is: () => is$2,
|
|
689
|
-
make: () => make$
|
|
406
|
+
make: () => make$1
|
|
690
407
|
});
|
|
691
|
-
const is$2 = (value) => is$
|
|
692
|
-
const make$
|
|
408
|
+
const is$2 = (value) => is$4(value) && value.kind === "view.event";
|
|
409
|
+
const make$1 = (name) => make$3("view.event", name);
|
|
693
410
|
const equals = (left, right) => left.name === right.name;
|
|
694
|
-
const describe$
|
|
695
|
-
const Press = make$
|
|
696
|
-
const Click = make$
|
|
697
|
-
const Cancel = make$
|
|
698
|
-
const Input = make$
|
|
699
|
-
const Change = make$
|
|
700
|
-
const Focus = make$
|
|
701
|
-
const Blur = make$
|
|
702
|
-
const KeyDown = make$
|
|
703
|
-
const PointerDown = make$
|
|
704
|
-
const PointerUp = make$
|
|
705
|
-
const Hover = make$
|
|
706
|
-
const Submit = make$
|
|
411
|
+
const describe$1 = (event) => ({ name: event.name });
|
|
412
|
+
const Press = make$1("press");
|
|
413
|
+
const Click = make$1("click");
|
|
414
|
+
const Cancel = make$1("cancel");
|
|
415
|
+
const Input = make$1("input");
|
|
416
|
+
const Change = make$1("change");
|
|
417
|
+
const Focus = make$1("focus");
|
|
418
|
+
const Blur = make$1("blur");
|
|
419
|
+
const KeyDown = make$1("keydown");
|
|
420
|
+
const PointerDown = make$1("pointerdown");
|
|
421
|
+
const PointerUp = make$1("pointerup");
|
|
422
|
+
const Hover = make$1("hover");
|
|
423
|
+
const Submit = make$1("submit");
|
|
707
424
|
//#endregion
|
|
708
425
|
//#region src/requirement.ts
|
|
709
426
|
/**
|
|
@@ -714,520 +431,47 @@ var requirement_exports = /* @__PURE__ */ __exportAll({
|
|
|
714
431
|
Clipboard: () => Clipboard,
|
|
715
432
|
Keyboard: () => Keyboard,
|
|
716
433
|
Pointer: () => Pointer,
|
|
717
|
-
describe: () => describe
|
|
434
|
+
describe: () => describe,
|
|
718
435
|
is: () => is$1,
|
|
719
|
-
make: () => make
|
|
720
|
-
});
|
|
721
|
-
const is$1 = (value) => is$
|
|
722
|
-
const make
|
|
723
|
-
const describe
|
|
724
|
-
const Keyboard = make
|
|
725
|
-
const Pointer = make
|
|
726
|
-
const Clipboard = make
|
|
436
|
+
make: () => make
|
|
437
|
+
});
|
|
438
|
+
const is$1 = (value) => is$4(value) && value.kind === "view.requirement";
|
|
439
|
+
const make = (name) => make$3("view.requirement", name);
|
|
440
|
+
const describe = (requirement) => ({ name: requirement.name });
|
|
441
|
+
const Keyboard = make("keyboard");
|
|
442
|
+
const Pointer = make("pointer");
|
|
443
|
+
const Clipboard = make("clipboard");
|
|
727
444
|
//#endregion
|
|
728
|
-
//#region src/
|
|
729
|
-
var
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
describe: () => describe$1,
|
|
734
|
-
events: () => events,
|
|
735
|
-
hide: () => hide,
|
|
445
|
+
//#region src/selector.ts
|
|
446
|
+
var selector_exports = /* @__PURE__ */ __exportAll({
|
|
447
|
+
attr: () => attr,
|
|
448
|
+
child: () => child,
|
|
449
|
+
descendant: () => descendant,
|
|
736
450
|
is: () => is,
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
const SlotTypeId = Symbol.for("foldkit-mixins/Slot");
|
|
741
|
-
const is = (value) => typeof value === "object" && value !== null && Object.hasOwn(value, SlotTypeId);
|
|
742
|
-
const emptyProtection = Object.freeze({
|
|
743
|
-
events: Object.freeze([]),
|
|
744
|
-
attributes: Object.freeze([]),
|
|
745
|
-
style: Object.freeze([])
|
|
451
|
+
not: () => not,
|
|
452
|
+
sibling: () => sibling,
|
|
453
|
+
siblings: () => siblings
|
|
746
454
|
});
|
|
747
|
-
const protectionOf = (options) => {
|
|
748
|
-
const specified = options?.protected;
|
|
749
|
-
if (specified === void 0) return emptyProtection;
|
|
750
|
-
return Object.freeze({
|
|
751
|
-
events: Object.freeze([...specified.events ?? []]),
|
|
752
|
-
attributes: Object.freeze([...specified.attributes ?? []]),
|
|
753
|
-
style: Object.freeze([...specified.style ?? []])
|
|
754
|
-
});
|
|
755
|
-
};
|
|
756
|
-
const createSlot = (name, options) => {
|
|
757
|
-
const capability = options?.capability ?? Base;
|
|
758
|
-
const events = options?.events ?? options?.allowedEvents ?? [];
|
|
759
|
-
const attributes = options?.attributes ?? options?.allowedAttributes ?? [];
|
|
760
|
-
const requirements = options?.requirements ?? options?.platformRequirements ?? [];
|
|
761
|
-
const hidden = options?.hidden ?? false;
|
|
762
|
-
const protection = protectionOf(options);
|
|
763
|
-
const metadata = {
|
|
764
|
-
name,
|
|
765
|
-
capability,
|
|
766
|
-
allowedEvents: events,
|
|
767
|
-
allowedAttributes: attributes,
|
|
768
|
-
platformRequirements: requirements,
|
|
769
|
-
hidden,
|
|
770
|
-
protected: protection
|
|
771
|
-
};
|
|
772
|
-
const out = {
|
|
773
|
-
[SlotTypeId]: {
|
|
774
|
-
Name: void 0,
|
|
775
|
-
Capability: void 0,
|
|
776
|
-
Events: void 0,
|
|
777
|
-
Attributes: void 0,
|
|
778
|
-
Requirements: void 0,
|
|
779
|
-
Hidden: void 0
|
|
780
|
-
},
|
|
781
|
-
name,
|
|
782
|
-
capability,
|
|
783
|
-
events,
|
|
784
|
-
attributes,
|
|
785
|
-
requirements,
|
|
786
|
-
hidden,
|
|
787
|
-
protected: protection,
|
|
788
|
-
metadata
|
|
789
|
-
};
|
|
790
|
-
return Object.assign(out, { pipe: (...fns) => pipeSelf(out, fns) });
|
|
791
|
-
};
|
|
792
|
-
function make(nameOrOptions, options) {
|
|
793
|
-
if (typeof nameOrOptions === "string") return createSlot(nameOrOptions, options);
|
|
794
|
-
const { name: _dropped, ...rest } = createSlot("", nameOrOptions);
|
|
795
|
-
return rest;
|
|
796
|
-
}
|
|
797
|
-
/** Pipeable transform replacing a named slot's capability. */
|
|
798
|
-
const capability = (capability) => (slot) => createSlot(slot.name, {
|
|
799
|
-
capability,
|
|
800
|
-
events: slot.events,
|
|
801
|
-
attributes: slot.attributes,
|
|
802
|
-
requirements: slot.requirements,
|
|
803
|
-
hidden: slot.hidden,
|
|
804
|
-
protected: slot.protected
|
|
805
|
-
});
|
|
806
|
-
/** Pipeable transform replacing a named slot's allowed events. */
|
|
807
|
-
const events = (...next) => (slot) => createSlot(slot.name, {
|
|
808
|
-
capability: slot.capability,
|
|
809
|
-
events: next,
|
|
810
|
-
attributes: slot.attributes,
|
|
811
|
-
requirements: slot.requirements,
|
|
812
|
-
hidden: slot.hidden,
|
|
813
|
-
protected: slot.protected
|
|
814
|
-
});
|
|
815
|
-
/** Pipeable transform replacing a named slot's allowed attributes. */
|
|
816
|
-
const attributes = (...next) => (slot) => createSlot(slot.name, {
|
|
817
|
-
capability: slot.capability,
|
|
818
|
-
events: slot.events,
|
|
819
|
-
attributes: next,
|
|
820
|
-
requirements: slot.requirements,
|
|
821
|
-
hidden: slot.hidden,
|
|
822
|
-
protected: slot.protected
|
|
823
|
-
});
|
|
824
|
-
/** Pipeable transform replacing a named slot's platform requirements. */
|
|
825
|
-
const requires = (...next) => (slot) => createSlot(slot.name, {
|
|
826
|
-
capability: slot.capability,
|
|
827
|
-
events: slot.events,
|
|
828
|
-
attributes: slot.attributes,
|
|
829
|
-
requirements: next,
|
|
830
|
-
hidden: slot.hidden,
|
|
831
|
-
protected: slot.protected
|
|
832
|
-
});
|
|
833
|
-
/** Pipeable transform marking a named slot hidden from public attachment. */
|
|
834
|
-
const hide = (slot) => createSlot(slot.name, {
|
|
835
|
-
capability: slot.capability,
|
|
836
|
-
events: slot.events,
|
|
837
|
-
attributes: slot.attributes,
|
|
838
|
-
requirements: slot.requirements,
|
|
839
|
-
hidden: true,
|
|
840
|
-
protected: slot.protected
|
|
841
|
-
});
|
|
842
|
-
const describe$1 = (slot) => {
|
|
843
|
-
return {
|
|
844
|
-
...slot.name !== void 0 && slot.name !== "" ? { name: slot.name } : {},
|
|
845
|
-
capability: nameOf(slot.capability),
|
|
846
|
-
events: slot.events.map((event) => nameOf(event)),
|
|
847
|
-
attributes: slot.attributes.map((attr) => nameOf(attr)),
|
|
848
|
-
requirements: slot.requirements.map((requirement) => nameOf(requirement)),
|
|
849
|
-
hidden: slot.hidden,
|
|
850
|
-
protected: {
|
|
851
|
-
events: slot.protected.events.map((event) => nameOf(event)),
|
|
852
|
-
attributes: slot.protected.attributes.map((attr) => nameOf(attr)),
|
|
853
|
-
style: slot.protected.style
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
};
|
|
857
|
-
//#endregion
|
|
858
|
-
//#region src/slots.ts
|
|
859
455
|
/**
|
|
860
|
-
*
|
|
861
|
-
*
|
|
862
|
-
*
|
|
456
|
+
* Typed builders for the selector strings `Style.pseudo` and `Style.nest`
|
|
457
|
+
* take, relative to the generated class (`&`). They exist so a recipe does
|
|
458
|
+
* not hand-type `&:not([aria-disabled="true"])` in every entry.
|
|
863
459
|
*/
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
})
|
|
870
|
-
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
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
|
-
const contract = Object.create(null);
|
|
880
|
-
for (const key of Object.getOwnPropertyNames(spec)) {
|
|
881
|
-
const unnamed = toUnnamed(spec[key], key);
|
|
882
|
-
Object.defineProperty(contract, key, {
|
|
883
|
-
value: make(key, {
|
|
884
|
-
capability: unnamed.capability,
|
|
885
|
-
events: unnamed.events,
|
|
886
|
-
attributes: unnamed.attributes,
|
|
887
|
-
requirements: unnamed.requirements,
|
|
888
|
-
hidden: unnamed.hidden,
|
|
889
|
-
protected: unnamed.protected
|
|
890
|
-
}),
|
|
891
|
-
enumerable: true,
|
|
892
|
-
configurable: false,
|
|
893
|
-
writable: false
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
Object.freeze(contract);
|
|
897
|
-
return contract;
|
|
898
|
-
};
|
|
899
|
-
const describe = (contract) => {
|
|
900
|
-
const slots = Object.create(null);
|
|
901
|
-
for (const key of Object.getOwnPropertyNames(contract)) {
|
|
902
|
-
const slot = contract[key];
|
|
903
|
-
if (slot === void 0 || !is(slot)) continue;
|
|
904
|
-
slots[key] = {
|
|
905
|
-
...describe$1(slot),
|
|
906
|
-
name: slot.name !== void 0 && slot.name !== "" ? slot.name : key
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
return { slots };
|
|
910
|
-
};
|
|
911
|
-
const withCapability = (contract, capability) => {
|
|
912
|
-
const out = Object.create(null);
|
|
913
|
-
for (const key of Object.getOwnPropertyNames(contract)) {
|
|
914
|
-
const slot = contract[key];
|
|
915
|
-
if (slot === void 0 || !is(slot)) continue;
|
|
916
|
-
if (extendsCapability(slot.capability, capability)) out[key] = slot;
|
|
917
|
-
}
|
|
918
|
-
return out;
|
|
919
|
-
};
|
|
920
|
-
//#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
|
-
//#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
|
-
/**
|
|
1024
|
-
* A deterministic `@keyframes` block. Compose `style` where the animation is
|
|
1025
|
-
* declared and reference `name` in an `animation` declaration.
|
|
1026
|
-
*/
|
|
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
|
-
/** A boolean known at authoring time. */
|
|
1045
|
-
const when = (condition, piece) => condition ? piece : empty;
|
|
1046
|
-
/** A condition read from the view input at render time. The piece applies when
|
|
1047
|
-
* `predicate` returns true for the input the view was rendered with. */
|
|
1048
|
-
const whenInput = (predicate, piece) => Object.freeze({
|
|
1049
|
-
classes: empty.classes,
|
|
1050
|
-
style: empty.style,
|
|
1051
|
-
conditions: Object.freeze([{
|
|
1052
|
-
predicate: (input) => predicate(input),
|
|
1053
|
-
piece
|
|
1054
|
-
}])
|
|
1055
|
-
});
|
|
1056
|
-
/** Fold every active condition (recursively) into a condition-free style. */
|
|
1057
|
-
const resolveStyle = (style, input) => {
|
|
1058
|
-
const active = (style.conditions ?? []).filter((condition) => condition.predicate(input)).map((condition) => resolveStyle(condition.piece, input));
|
|
1059
|
-
return Object.freeze({
|
|
1060
|
-
classes: Object.freeze([...style.classes, ...active.flatMap((piece) => piece.classes)]),
|
|
1061
|
-
style: Object.freeze(Object.assign(Object.create(null), style.style, ...active.map((piece) => piece.style)))
|
|
1062
|
-
});
|
|
1063
|
-
};
|
|
1064
|
-
const hasConditionalRules = (style) => (style.conditions ?? []).some((condition) => (condition.piece.rules ?? []).length > 0 || hasConditionalRules(condition.piece));
|
|
1065
|
-
/** Global CSS is emitted whether or not its condition is active. */
|
|
1066
|
-
const collectGlobalCss = (style) => [...style.globalCss ?? [], ...(style.conditions ?? []).flatMap((condition) => collectGlobalCss(condition.piece))];
|
|
1067
|
-
/** A rule-bearing style gets one deterministic class and its CSS text. */
|
|
1068
|
-
const compileStyle = (style) => {
|
|
1069
|
-
const rules = style.rules ?? [];
|
|
1070
|
-
const globalRules = collectGlobalCss(style);
|
|
1071
|
-
const generated = rules.length === 0 ? void 0 : className(rules);
|
|
1072
|
-
return {
|
|
1073
|
-
classes: generated === void 0 ? style.classes : Object.freeze([...style.classes, generated]),
|
|
1074
|
-
style: style.style,
|
|
1075
|
-
...generated === void 0 ? {} : {
|
|
1076
|
-
css: css(generated, rules),
|
|
1077
|
-
ruleClass: generated
|
|
1078
|
-
},
|
|
1079
|
-
...globalRules.length === 0 ? {} : { globalRules }
|
|
1080
|
-
};
|
|
1081
|
-
};
|
|
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
|
-
/**
|
|
1093
|
-
* A static style stays static data; a style with input conditions compiles to a
|
|
1094
|
-
* message-free `InputContribution`, so it still attaches to any view.
|
|
1095
|
-
*/
|
|
1096
|
-
const contributionFrom = (style, compiled) => {
|
|
1097
|
-
const globalCss = compiled.globalRules?.join("");
|
|
1098
|
-
const attributes = {
|
|
1099
|
-
classes: compiled.classes,
|
|
1100
|
-
style: compiled.style,
|
|
1101
|
-
...compiled.css === void 0 ? {} : { css: compiled.css },
|
|
1102
|
-
...globalCss === void 0 ? {} : { globalCss }
|
|
1103
|
-
};
|
|
1104
|
-
if ((style.conditions ?? []).length === 0) return Object.freeze(attributes);
|
|
1105
|
-
const contribution = (context) => {
|
|
1106
|
-
const resolved = resolveStyle({
|
|
1107
|
-
...style,
|
|
1108
|
-
classes: compiled.classes
|
|
1109
|
-
}, context.input);
|
|
1110
|
-
return Object.freeze({
|
|
1111
|
-
classes: resolved.classes,
|
|
1112
|
-
style: resolved.style,
|
|
1113
|
-
...compiled.css === void 0 ? {} : { css: compiled.css },
|
|
1114
|
-
...globalCss === void 0 ? {} : { globalCss }
|
|
1115
|
-
});
|
|
1116
|
-
};
|
|
1117
|
-
return contribution;
|
|
1118
|
-
};
|
|
1119
|
-
const forSlots = (slots) => (pieces, options) => {
|
|
1120
|
-
const known = slots;
|
|
1121
|
-
const contributions = Object.create(null);
|
|
1122
|
-
const rules = [];
|
|
1123
|
-
const globalRules = [];
|
|
1124
|
-
let css = "";
|
|
1125
|
-
let globalCss = "";
|
|
1126
|
-
for (const [key, piece] of Object.entries(pieces)) {
|
|
1127
|
-
if (!Object.hasOwn(known, key)) throw new DiagnosticError({
|
|
1128
|
-
source: "mixins",
|
|
1129
|
-
code: "mixins:unknown-slot",
|
|
1130
|
-
severity: "error",
|
|
1131
|
-
message: `Style targets unknown slot "${key}"`,
|
|
1132
|
-
slot: key
|
|
1133
|
-
});
|
|
1134
|
-
if (known[key]?.hidden === true) throw new DiagnosticError({
|
|
1135
|
-
source: "mixins",
|
|
1136
|
-
code: "mixins:hidden-slot",
|
|
1137
|
-
severity: "error",
|
|
1138
|
-
message: `Style targets hidden slot "${key}"`,
|
|
1139
|
-
slot: key
|
|
1140
|
-
});
|
|
1141
|
-
if (piece !== void 0) {
|
|
1142
|
-
assertRulesSupported(piece);
|
|
1143
|
-
const compiled = compileStyle(piece);
|
|
1144
|
-
contributions[key] = contributionFrom(piece, compiled);
|
|
1145
|
-
if (compiled.ruleClass !== void 0 && compiled.css !== void 0) {
|
|
1146
|
-
rules.push({
|
|
1147
|
-
className: compiled.ruleClass,
|
|
1148
|
-
css: compiled.css
|
|
1149
|
-
});
|
|
1150
|
-
css += compiled.css;
|
|
1151
|
-
}
|
|
1152
|
-
if (compiled.globalRules !== void 0) {
|
|
1153
|
-
globalRules.push(...compiled.globalRules);
|
|
1154
|
-
globalCss += compiled.globalRules.join("");
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
return Object.freeze({
|
|
1159
|
-
...options?.name === void 0 ? {} : { name: options.name },
|
|
1160
|
-
pieces,
|
|
1161
|
-
mixin: dynamic(options?.name ?? "Style", contributions),
|
|
1162
|
-
css,
|
|
1163
|
-
globalCss,
|
|
1164
|
-
rules: Object.freeze(rules),
|
|
1165
|
-
globalRules: Object.freeze(globalRules)
|
|
1166
|
-
});
|
|
1167
|
-
};
|
|
1168
|
-
/** Deduplicated global then scoped CSS for one `<style>` block, first seen wins. */
|
|
1169
|
-
const stylesheet = (...styles) => {
|
|
1170
|
-
const scoped = /* @__PURE__ */ new Map();
|
|
1171
|
-
const global = /* @__PURE__ */ new Set();
|
|
1172
|
-
for (const style of styles) {
|
|
1173
|
-
for (const rule of style.rules) if (!scoped.has(rule.className)) scoped.set(rule.className, rule.css);
|
|
1174
|
-
for (const rule of style.globalRules) global.add(rule);
|
|
1175
|
-
}
|
|
1176
|
-
return [...global, ...scoped.values()].join("");
|
|
1177
|
-
};
|
|
1178
|
-
const attach = (style) => (view) => attach$2(style.mixin)(view);
|
|
1179
|
-
/** A recipe is just Style data: base, one piece per selected variant, then any
|
|
1180
|
-
* matching compound. `compound.when` is keyed by the recipe's variants, so a
|
|
1181
|
-
* typo is a compile error rather than a silently dead combination. */
|
|
1182
|
-
const recipe = (def) => (selection) => {
|
|
1183
|
-
const pieces = [];
|
|
1184
|
-
if (def.base !== void 0) pieces.push(def.base);
|
|
1185
|
-
const effective = {};
|
|
1186
|
-
for (const [variant, values] of Object.entries(def.variants)) {
|
|
1187
|
-
const chosen = selection[variant] ?? def.defaults?.[variant];
|
|
1188
|
-
if (chosen === void 0) continue;
|
|
1189
|
-
effective[variant] = chosen;
|
|
1190
|
-
const piece = values[chosen];
|
|
1191
|
-
if (piece !== void 0) pieces.push(piece);
|
|
1192
|
-
}
|
|
1193
|
-
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);
|
|
1195
|
-
};
|
|
1196
|
-
const Style = {
|
|
1197
|
-
class: classPiece,
|
|
1198
|
-
inline,
|
|
1199
|
-
compose,
|
|
1200
|
-
when,
|
|
1201
|
-
whenInput,
|
|
1202
|
-
pseudo,
|
|
1203
|
-
media,
|
|
1204
|
-
supports,
|
|
1205
|
-
container,
|
|
1206
|
-
nest,
|
|
1207
|
-
keyframes,
|
|
1208
|
-
global,
|
|
1209
|
-
empty,
|
|
1210
|
-
forSlots,
|
|
1211
|
-
attach,
|
|
1212
|
-
recipe,
|
|
1213
|
-
stylesheet
|
|
1214
|
-
};
|
|
1215
|
-
//#endregion
|
|
1216
|
-
//#region src/theme.ts
|
|
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
|
-
};
|
|
460
|
+
/** `&[name]` or `&[name="value"]`. */
|
|
461
|
+
const attr = (name, value) => value === void 0 ? `[${name}]` : `[${name}="${value.replace(/["\\]/g, "\\$&")}"]`;
|
|
462
|
+
/** `&:not(selector)`, for `Style.pseudo`. */
|
|
463
|
+
const not = (selector) => `:not(${selector})`;
|
|
464
|
+
/** `&:is(a, b)`, for `Style.pseudo`. */
|
|
465
|
+
const is = (...selectors) => `:is(${selectors.join(", ")})`;
|
|
466
|
+
/** A direct child, for `Style.nest`. */
|
|
467
|
+
const child = (selector) => `> ${selector}`;
|
|
468
|
+
/** Any descendant, for `Style.nest`. */
|
|
469
|
+
const descendant = (selector) => selector;
|
|
470
|
+
/** The next sibling, for `Style.nest`. */
|
|
471
|
+
const sibling = (selector) => `+ ${selector}`;
|
|
472
|
+
/** Any later sibling, for `Style.nest`. */
|
|
473
|
+
const siblings = (selector) => `~ ${selector}`;
|
|
1230
474
|
//#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 };
|
|
475
|
+
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
476
|
|
|
1233
477
|
//# sourceMappingURL=index.mjs.map
|