foldkit-mixins 0.22.0 → 0.23.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 +44 -0
- package/dist/inject.d.ts +7 -0
- package/dist/inject.d.ts.map +1 -1
- package/dist/inject.js +90 -6
- package/dist/inject.js.map +1 -1
- package/dist/slotView.d.ts.map +1 -1
- package/dist/slotView.js +20 -11
- package/dist/slotView.js.map +1 -1
- package/dist/style.d.ts +2 -1
- package/dist/style.js +3 -2
- package/dist/style.js.map +1 -1
- package/dist/theme/knobs.js +1 -1
- package/dist/theme/knobs.js.map +1 -1
- package/dist/vite.d.ts +8 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +139 -0
- package/dist/vite.js.map +1 -0
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -1118,6 +1118,50 @@ runs from. `loadFoundations(options)` is the same compile without the plugin,
|
|
|
1118
1118
|
returning the text for a caller that writes it itself. The subpath is node-only:
|
|
1119
1119
|
a page that imports it fails fast naming `vite`.
|
|
1120
1120
|
|
|
1121
|
+
## The stylesheet as a file
|
|
1122
|
+
|
|
1123
|
+
Written into every page, the stylesheet is sent again with each response and
|
|
1124
|
+
parsed again by the server's checks of the page. `foldkit-mixins/vite` writes
|
|
1125
|
+
it once, as a hashed file in the browser build, and gives the server its
|
|
1126
|
+
address; the page links it:
|
|
1127
|
+
|
|
1128
|
+
```ts
|
|
1129
|
+
// vite.config.ts
|
|
1130
|
+
import { styles } from 'foldkit-mixins/vite'
|
|
1131
|
+
|
|
1132
|
+
export default defineConfig({
|
|
1133
|
+
plugins: [styles({ sheet: '/src/style.ts' })],
|
|
1134
|
+
})
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
```ts
|
|
1138
|
+
// the server entry: a link in the document's head, so the first paint waits for it
|
|
1139
|
+
import { href } from 'virtual:foldkit-styles'
|
|
1140
|
+
|
|
1141
|
+
const head = `<link rel="stylesheet" href="${href}" data-foldkit-styles-href>`
|
|
1142
|
+
```
|
|
1143
|
+
|
|
1144
|
+
`sheet` is a module that exports the stylesheet text as `stylesheet`
|
|
1145
|
+
(`Style.stylesheet(...)`, or an `AppStyle.make` result). The file is that
|
|
1146
|
+
sheet followed by `Style.complete(sheet)`'s addition: every class and global
|
|
1147
|
+
rule the process compiled that the sheet does not hold. The plugin bundles the
|
|
1148
|
+
sheet module (every module it imports is kept, since compiling a Style is a
|
|
1149
|
+
side effect), so import the application's styled modules from it. Declare the
|
|
1150
|
+
virtual module for TypeScript (`declare module 'virtual:foldkit-styles' { export const href: string }`).
|
|
1151
|
+
|
|
1152
|
+
- **Build.** `assets/styles-<hash>.css` is written by the `client` build, named
|
|
1153
|
+
by its content; `href` carries Vite's `base`, which must be absolute. A
|
|
1154
|
+
`?url` import in the sheet (a font) is the address the browser build gives it.
|
|
1155
|
+
- **Dev.** `href` is `/__foldkit-styles.css`, served by the dev server from the
|
|
1156
|
+
modules it has loaded and read again after an edit, so the server entry has
|
|
1157
|
+
one code path.
|
|
1158
|
+
- **Browser.** The `data-foldkit-styles-href` mark tells the injector the link
|
|
1159
|
+
is a stylesheet: once it loads, the injector reads its rules and skips every
|
|
1160
|
+
class and global rule it holds; a class drawn before it loads waits for it. A
|
|
1161
|
+
sheet the browser withholds (cross-origin without CORS) counts as empty, so
|
|
1162
|
+
its classes are injected again rather than lost.
|
|
1163
|
+
- **Without the plugin**, `Style.usedIn(html)` still writes what one page uses.
|
|
1164
|
+
|
|
1121
1165
|
## `@foldkit/ui`
|
|
1122
1166
|
|
|
1123
1167
|
`foldkit-mixins-ui` adapts `@foldkit/ui` components that expose attribute bundles or a consumer
|
package/dist/inject.d.ts
CHANGED
|
@@ -12,6 +12,13 @@ export declare const register: (className: string, css: string, globalCss: strin
|
|
|
12
12
|
* nothing twice.
|
|
13
13
|
*/
|
|
14
14
|
export declare const usedIn: (html: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* `sheet` followed by every compiled class and global rule it does not hold:
|
|
17
|
+
* a build's complete stylesheet, where `usedIn` finds the classes of one
|
|
18
|
+
* page at request time. Which classes exist is whatever the process has
|
|
19
|
+
* compiled, so load the application's styled modules first.
|
|
20
|
+
*/
|
|
21
|
+
export declare const complete: (sheet: string) => string;
|
|
15
22
|
/**
|
|
16
23
|
* Queues the CSS of each registered class a contribution draws that the page
|
|
17
24
|
* does not carry yet, and its global CSS (keyframes, a theme root) once.
|
package/dist/inject.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.d.ts","names":[],"sources":["../src/inject.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"inject.d.ts","names":[],"sources":["../src/inject.ts"],"mappings":";;;;;qBAqCa,WAAQ,mBAAqB,aAAa;;;;;;;;qBA4B1C,SAAM;;;;;;;qBAoBN,WAAQ;;;;;;qBAuJR,SAAM;WACR,UAAU;WACV"}
|
package/dist/inject.js
CHANGED
|
@@ -11,7 +11,10 @@ import { standard } from "./layers.js";
|
|
|
11
11
|
* later (after the patch, before the browser paints) appended to a single
|
|
12
12
|
* `<style data-foldkit-styles>` element, unless a stylesheet on the page
|
|
13
13
|
* already carries the class: a static sheet and injection never repeat each
|
|
14
|
-
* other.
|
|
14
|
+
* other. A sheet is a `<style>` or a `<link data-foldkit-styles-href>`, the
|
|
15
|
+
* mark a build's linked sheet carries (`foldkit-mixins/vite`); a link's classes
|
|
16
|
+
* are read from its parsed rules, and a draw that comes before it loads waits
|
|
17
|
+
* for it rather than injecting what it is about to bring.
|
|
15
18
|
*
|
|
16
19
|
* The registry holds every class compiled in the process and never lets one
|
|
17
20
|
* go, which is bounded by the code when Styles are defined once, as they are
|
|
@@ -64,6 +67,51 @@ const usedIn = (html) => {
|
|
|
64
67
|
...[...globals].map(withoutOrder)
|
|
65
68
|
].join("");
|
|
66
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* `sheet` followed by every compiled class and global rule it does not hold:
|
|
72
|
+
* a build's complete stylesheet, where `usedIn` finds the classes of one
|
|
73
|
+
* page at request time. Which classes exist is whatever the process has
|
|
74
|
+
* compiled, so load the application's styled modules first.
|
|
75
|
+
*/
|
|
76
|
+
const complete = (sheet) => {
|
|
77
|
+
const held = new Set(Array.from(sheet.matchAll(COMPILED_CLASS), ([, name]) => name));
|
|
78
|
+
const rules = [];
|
|
79
|
+
const globals = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const [className, entry] of registry) {
|
|
81
|
+
if (!held.has(className)) rules.push(entry.css);
|
|
82
|
+
for (const css of entry.globals) globals.add(withoutOrder(css));
|
|
83
|
+
}
|
|
84
|
+
return [
|
|
85
|
+
sheet,
|
|
86
|
+
...[...globals].filter((css) => css !== "" && !sheet.includes(css)),
|
|
87
|
+
...rules
|
|
88
|
+
].join("");
|
|
89
|
+
};
|
|
90
|
+
/** The mark on a `<link>` to a stylesheet the page's build wrote. */
|
|
91
|
+
const LINKED = "link[data-foldkit-styles-href]";
|
|
92
|
+
/** Links that failed to load: counted as holding nothing, so a draw stops waiting. */
|
|
93
|
+
const failed = /* @__PURE__ */ new WeakSet();
|
|
94
|
+
/**
|
|
95
|
+
* The rules of a linked sheet, or none where the browser withholds them (a
|
|
96
|
+
* cross-origin sheet): its classes are then injected, which repeats rules
|
|
97
|
+
* rather than losing them.
|
|
98
|
+
*/
|
|
99
|
+
const rulesOf = (sheet) => {
|
|
100
|
+
try {
|
|
101
|
+
return Array.from(sheet.cssRules);
|
|
102
|
+
} catch {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
/** Every compiled class a rule, or a rule nested in it (a layer, a media query), selects. */
|
|
107
|
+
const classesIn = (rules, into) => {
|
|
108
|
+
for (const rule of rules) {
|
|
109
|
+
if ("selectorText" in rule && typeof rule.selectorText === "string") {
|
|
110
|
+
for (const [, className] of rule.selectorText.matchAll(COMPILED_CLASS)) if (className !== void 0) into.add(className);
|
|
111
|
+
}
|
|
112
|
+
if ("cssRules" in rule) classesIn(Array.from(rule.cssRules), into);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
67
115
|
let page;
|
|
68
116
|
let pending = [];
|
|
69
117
|
let scheduled = false;
|
|
@@ -73,11 +121,14 @@ let scheduled = false;
|
|
|
73
121
|
* replacing the head).
|
|
74
122
|
*/
|
|
75
123
|
const current = () => {
|
|
76
|
-
if (page !== void 0 && (page.element === void 0 || page.element.isConnected) && page.counted.every((sheet) => sheet.isConnected)) return page;
|
|
124
|
+
if (page !== void 0 && (page.element === void 0 || page.element.isConnected) && page.counted.every((sheet) => sheet.isConnected) && page.waiting.every((link) => link.sheet === null && !failed.has(link))) return page;
|
|
77
125
|
const present = /* @__PURE__ */ new Set();
|
|
78
126
|
let order;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
127
|
+
const links = Array.from(document.querySelectorAll(LINKED));
|
|
128
|
+
const linked = links.flatMap((link) => link.sheet === null ? [] : [link.sheet]);
|
|
129
|
+
for (const sheet of linked) classesIn(rulesOf(sheet), present);
|
|
130
|
+
const counted = [...document.querySelectorAll("style"), ...links];
|
|
131
|
+
const texts = counted.map((sheet) => (sheet instanceof HTMLStyleElement ? sheet.textContent : "") ?? "");
|
|
81
132
|
for (const text of texts) {
|
|
82
133
|
for (const [, className] of text.matchAll(COMPILED_CLASS)) if (className !== void 0) present.add(className);
|
|
83
134
|
order ??= text.match(LAYER_STATEMENT)?.[0];
|
|
@@ -88,7 +139,10 @@ const current = () => {
|
|
|
88
139
|
text: texts.join(""),
|
|
89
140
|
handled: /* @__PURE__ */ new WeakSet(),
|
|
90
141
|
order,
|
|
142
|
+
linked,
|
|
143
|
+
waiting: links.filter((link) => link.sheet === null && !failed.has(link)),
|
|
91
144
|
counted,
|
|
145
|
+
linkedRules: void 0,
|
|
92
146
|
element: void 0
|
|
93
147
|
};
|
|
94
148
|
return page;
|
|
@@ -107,6 +161,19 @@ const flush = () => {
|
|
|
107
161
|
into.element.appendChild(document.createTextNode(pending.join("")));
|
|
108
162
|
pending = [];
|
|
109
163
|
};
|
|
164
|
+
/** Contributions drawn while a linked sheet was loading, drawn again once it has. */
|
|
165
|
+
const deferred = [];
|
|
166
|
+
const watched = /* @__PURE__ */ new WeakSet();
|
|
167
|
+
/** Whether the linked sheets hold every top-level rule of `css`, as the browser writes them. */
|
|
168
|
+
const linkedHolds = (into, css) => {
|
|
169
|
+
if (into.linked.length === 0 || typeof CSSStyleSheet === "undefined") return false;
|
|
170
|
+
const probe = new CSSStyleSheet();
|
|
171
|
+
probe.replaceSync(css);
|
|
172
|
+
const rules = Array.from(probe.cssRules);
|
|
173
|
+
into.linkedRules ??= new Set(into.linked.flatMap((sheet) => rulesOf(sheet).map((rule) => rule.cssText)));
|
|
174
|
+
const held = into.linkedRules;
|
|
175
|
+
return rules.length > 0 && rules.every((rule) => held.has(rule.cssText));
|
|
176
|
+
};
|
|
110
177
|
/**
|
|
111
178
|
* Queues the CSS of each registered class a contribution draws that the page
|
|
112
179
|
* does not carry yet, and its global CSS (keyframes, a theme root) once.
|
|
@@ -115,6 +182,23 @@ const flush = () => {
|
|
|
115
182
|
const ensure = (contribution) => {
|
|
116
183
|
if (typeof document === "undefined") return;
|
|
117
184
|
const into = current();
|
|
185
|
+
if (into.waiting.length > 0) {
|
|
186
|
+
deferred.push(contribution);
|
|
187
|
+
for (const link of into.waiting) {
|
|
188
|
+
if (watched.has(link)) continue;
|
|
189
|
+
watched.add(link);
|
|
190
|
+
const retry = () => {
|
|
191
|
+
page = void 0;
|
|
192
|
+
for (const waiting of deferred.splice(0)) ensure(waiting);
|
|
193
|
+
};
|
|
194
|
+
link.addEventListener("load", retry, { once: true });
|
|
195
|
+
link.addEventListener("error", () => {
|
|
196
|
+
failed.add(link);
|
|
197
|
+
retry();
|
|
198
|
+
}, { once: true });
|
|
199
|
+
}
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
118
202
|
if (into.handled.has(contribution)) return;
|
|
119
203
|
for (const className of contribution.classes ?? []) {
|
|
120
204
|
if (into.present.has(className)) continue;
|
|
@@ -127,7 +211,7 @@ const ensure = (contribution) => {
|
|
|
127
211
|
if (globalCss !== void 0 && globalCss !== "" && !into.globals.has(globalCss)) {
|
|
128
212
|
into.globals.add(globalCss);
|
|
129
213
|
const css = withoutOrder(globalCss);
|
|
130
|
-
if (!into.text.includes(css)) pending.push(css);
|
|
214
|
+
if (!into.text.includes(css) && !linkedHolds(into, css)) pending.push(css);
|
|
131
215
|
}
|
|
132
216
|
if (Object.isFrozen(contribution)) into.handled.add(contribution);
|
|
133
217
|
if (pending.length > 0 && !scheduled) {
|
|
@@ -135,6 +219,6 @@ const ensure = (contribution) => {
|
|
|
135
219
|
queueMicrotask(flush);
|
|
136
220
|
}
|
|
137
221
|
};
|
|
138
|
-
export { ensure, register, usedIn };
|
|
222
|
+
export { complete, ensure, register, usedIn };
|
|
139
223
|
|
|
140
224
|
//# sourceMappingURL=inject.js.map
|
package/dist/inject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject.js","names":[],"sources":["../src/inject.ts"],"sourcesContent":["/**\n * Styles that arrive with what uses them. Compiling a Style registers each\n * class it produces with that class's CSS, and with the Style's global rules\n * (keyframes, `raise`'s depth rules) that the class does not work without;\n * the name is a hash of the CSS, so the registry is the same on the server\n * and in the browser, and holds no DOM.\n *\n * When a Slot draws a class in a browser, the CSS is queued, and one microtask\n * later (after the patch, before the browser paints) appended to a single\n * `<style data-foldkit-styles>` element, unless a stylesheet on the page\n * already carries the class: a static sheet and injection never repeat each\n * other.\n *\n * The registry holds every class compiled in the process and never lets one\n * go, which is bounded by the code when Styles are defined once, as they are\n * meant to be. A Style compiled during a render from data (a width from the\n * Model) would register a class per value; such a value belongs in an inline\n * custom property read by a rule instead.\n */\nimport { standard } from './layers.js'\n\ninterface Registered {\n readonly css: string\n /** The global CSS of every Style that compiled to this class. */\n readonly globals: Set<string>\n}\n\nconst registry = new Map<string, Registered>()\n\n/**\n * Records the CSS a compiled class stands for, and the global CSS of the\n * Style it came from: the same text the Style's contribution carries, so the\n * browser's injection recognizes what a server wrote. Called by the compiler.\n */\nexport const register = (className: string, css: string, globalCss: string): void => {\n let entry = registry.get(className)\n if (entry === undefined) {\n entry = { css, globals: new Set() }\n registry.set(className, entry)\n }\n if (globalCss !== '') entry.globals.add(globalCss)\n}\n\n/** A compiled class in CSS text: `.style-` and its hash. */\nconst COMPILED_CLASS = /\\.(style-[0-9a-z]+)/g\n\n/** An `@layer` order statement, as opposed to a layer block. */\nconst LAYER_STATEMENT = /@layer [^{};]+;/g\n\n/** The standard layer order, as one `@layer` statement. */\nconst layerOrder = (): string => standard.declare.globalCss?.join('') ?? ''\n\n/** A Style's global CSS without its layer order, which is the page's to declare. */\nconst withoutOrder = (globalCss: string): string => globalCss.replace(LAYER_STATEMENT, '')\n\n/**\n * The CSS for every compiled class that `html` carries, and once each the\n * global CSS of the Styles those classes came from, after the standard layer\n * order: what a server puts in a page's head, so it is styled before any\n * script runs. The browser's injection then finds these present and adds\n * nothing twice.\n */\nexport const usedIn = (html: string): string => {\n const found = new Map<string, Registered>()\n for (const [className] of html.matchAll(/style-[0-9a-z]+/g)) {\n const entry = registry.get(className)\n if (entry !== undefined) found.set(className, entry)\n }\n const globals = new Set([...found.values()].flatMap(entry => [...entry.globals]))\n return [\n layerOrder(),\n ...[...found.values()].map(entry => entry.css),\n ...[...globals].map(withoutOrder),\n ].join('')\n}\n\n/** What the page carries: counted from its sheets once, then kept as CSS is queued. */\ninterface Page {\n readonly present: Set<string>\n readonly globals: Set<string>\n /** The text of the sheets counted, where a server may have written a global already. */\n readonly text: string\n /** Contributions already handled whole: a Style's are the same object every render. */\n readonly handled: WeakSet<object>\n /** The layer order a sheet on the page declares, which the injected sheet repeats. */\n readonly order: string | undefined\n /** The sheets counted, so a removed one means counting again. */\n readonly counted: ReadonlyArray<HTMLStyleElement>\n element: HTMLStyleElement | undefined\n}\n\nlet page: Page | undefined\nlet pending: Array<string> = []\nlet scheduled = false\n\n/**\n * The page as injection knows it, counted afresh when a sheet it counted or its\n * own element has been removed (by a test's cleanup, or an application\n * replacing the head).\n */\nconst current = (): Page => {\n if (\n page !== undefined &&\n (page.element === undefined || page.element.isConnected) &&\n page.counted.every(sheet => sheet.isConnected)\n )\n return page\n const present = new Set<string>()\n let order: string | undefined\n const counted = Array.from(document.querySelectorAll('style'))\n const texts = counted.map(sheet => sheet.textContent ?? '')\n for (const text of texts) {\n for (const [, className] of text.matchAll(COMPILED_CLASS))\n if (className !== undefined) present.add(className)\n order ??= text.match(LAYER_STATEMENT)?.[0]\n }\n page = {\n present,\n globals: new Set(),\n text: texts.join(''),\n handled: new WeakSet(),\n order,\n counted,\n element: undefined,\n }\n return page\n}\n\nconst flush = (): void => {\n scheduled = false\n if (pending.length === 0) return\n const into = current()\n if (into.element === undefined) {\n const element = document.createElement('style')\n element.setAttribute('data-foldkit-styles', '')\n // A layer order first: the page's own, or the standard one where it has\n // none. Layers are ordered by where they are first named, so an injected\n // `@layer components { … }` that came to stand ahead of the page's order\n // (a test's sheet, or an application's, put in after it) would otherwise\n // make `components` the first layer, under the reset.\n element.textContent = into.order ?? layerOrder()\n document.head.appendChild(element)\n into.element = element\n }\n into.element.appendChild(document.createTextNode(pending.join('')))\n pending = []\n}\n\n/**\n * Queues the CSS of each registered class a contribution draws that the page\n * does not carry yet, and its global CSS (keyframes, a theme root) once.\n * Outside a browser it does nothing: a server extracts what it rendered instead.\n */\nexport const ensure = (contribution: {\n readonly classes?: ReadonlyArray<string>\n readonly globalCss?: string\n}): void => {\n if (typeof document === 'undefined') return\n const into = current()\n if (into.handled.has(contribution)) return\n for (const className of contribution.classes ?? []) {\n if (into.present.has(className)) continue\n const entry = registry.get(className)\n if (entry === undefined) continue\n into.present.add(className)\n pending.push(entry.css)\n }\n const globalCss = contribution.globalCss\n if (globalCss !== undefined && globalCss !== '' && !into.globals.has(globalCss)) {\n into.globals.add(globalCss)\n const css = withoutOrder(globalCss)\n // A server's `usedIn` writes the same text, so a page it rendered has it.\n if (!into.text.includes(css)) pending.push(css)\n }\n // Frozen, a contribution cannot draw other classes next time it is drawn.\n if (Object.isFrozen(contribution)) into.handled.add(contribution)\n if (pending.length > 0 && !scheduled) {\n scheduled = true\n queueMicrotask(flush)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,2BAAW,IAAI,IAAwB;;;;;;AAO7C,MAAa,YAAY,WAAmB,KAAa,cAA4B;CACnF,IAAI,QAAQ,SAAS,IAAI,SAAS;CAClC,IAAI,UAAU,KAAA,GAAW;EACvB,QAAQ;GAAE;GAAK,yBAAS,IAAI,IAAI;EAAE;EAClC,SAAS,IAAI,WAAW,KAAK;CAC/B;CACA,IAAI,cAAc,IAAI,MAAM,QAAQ,IAAI,SAAS;AACnD;;AAGA,MAAM,iBAAiB;;AAGvB,MAAM,kBAAkB;;AAGxB,MAAM,mBAA2B,SAAS,QAAQ,WAAW,KAAK,EAAE,KAAK;;AAGzE,MAAM,gBAAgB,cAA8B,UAAU,QAAQ,iBAAiB,EAAE;;;;;;;;AASzF,MAAa,UAAU,SAAyB;CAC9C,MAAM,wBAAQ,IAAI,IAAwB;CAC1C,KAAK,MAAM,CAAC,cAAc,KAAK,SAAS,kBAAkB,GAAG;EAC3D,MAAM,QAAQ,SAAS,IAAI,SAAS;EACpC,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,WAAW,KAAK;CACrD;CACA,MAAM,UAAU,IAAI,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,SAAQ,UAAS,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC;CAChF,OAAO;EACL,WAAW;EACX,GAAG,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,KAAI,UAAS,MAAM,GAAG;EAC7C,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,YAAY;CAClC,CAAC,CAAC,KAAK,EAAE;AACX;AAiBA,IAAI;AACJ,IAAI,UAAyB,CAAC;AAC9B,IAAI,YAAY;;;;;;AAOhB,M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QAAQ,SAAS,IAAI,SAAS;EACpC,IAAI,UAAU,KAAA,GAAW;EACzB,KAAK,QAAQ,IAAI,SAAS;EAC1B,QAAQ,KAAK,MAAM,GAAG;CACxB;CACA,MAAM,YAAY,aAAa;CAC/B,IAAI,cAAc,KAAA,KAAa,cAAc,MAAM,CAAC,KAAK,QAAQ,IAAI,SAAS,GAAG;EAC/E,KAAK,QAAQ,IAAI,SAAS;EAC1B,MAAM,MAAM,aAAa,SAAS;EAElC,IAAI,CAAC,KAAK,KAAK,SAAS,GAAG,GAAG,QAAQ,KAAK,GAAG;CAChD;CAEA,IAAI,OAAO,SAAS,YAAY,GAAG,KAAK,QAAQ,IAAI,YAAY;CAChE,IAAI,QAAQ,SAAS,KAAK,CAAC,WAAW;EACpC,YAAY;EACZ,eAAe,KAAK;CACtB;AACF"}
|
|
1
|
+
{"version":3,"file":"inject.js","names":[],"sources":["../src/inject.ts"],"sourcesContent":["/**\n * Styles that arrive with what uses them. Compiling a Style registers each\n * class it produces with that class's CSS, and with the Style's global rules\n * (keyframes, `raise`'s depth rules) that the class does not work without;\n * the name is a hash of the CSS, so the registry is the same on the server\n * and in the browser, and holds no DOM.\n *\n * When a Slot draws a class in a browser, the CSS is queued, and one microtask\n * later (after the patch, before the browser paints) appended to a single\n * `<style data-foldkit-styles>` element, unless a stylesheet on the page\n * already carries the class: a static sheet and injection never repeat each\n * other. A sheet is a `<style>` or a `<link data-foldkit-styles-href>`, the\n * mark a build's linked sheet carries (`foldkit-mixins/vite`); a link's classes\n * are read from its parsed rules, and a draw that comes before it loads waits\n * for it rather than injecting what it is about to bring.\n *\n * The registry holds every class compiled in the process and never lets one\n * go, which is bounded by the code when Styles are defined once, as they are\n * meant to be. A Style compiled during a render from data (a width from the\n * Model) would register a class per value; such a value belongs in an inline\n * custom property read by a rule instead.\n */\nimport { standard } from './layers.js'\n\ninterface Registered {\n readonly css: string\n /** The global CSS of every Style that compiled to this class. */\n readonly globals: Set<string>\n}\n\nconst registry = new Map<string, Registered>()\n\n/**\n * Records the CSS a compiled class stands for, and the global CSS of the\n * Style it came from: the same text the Style's contribution carries, so the\n * browser's injection recognizes what a server wrote. Called by the compiler.\n */\nexport const register = (className: string, css: string, globalCss: string): void => {\n let entry = registry.get(className)\n if (entry === undefined) {\n entry = { css, globals: new Set() }\n registry.set(className, entry)\n }\n if (globalCss !== '') entry.globals.add(globalCss)\n}\n\n/** A compiled class in CSS text: `.style-` and its hash. */\nconst COMPILED_CLASS = /\\.(style-[0-9a-z]+)/g\n\n/** An `@layer` order statement, as opposed to a layer block. */\nconst LAYER_STATEMENT = /@layer [^{};]+;/g\n\n/** The standard layer order, as one `@layer` statement. */\nconst layerOrder = (): string => standard.declare.globalCss?.join('') ?? ''\n\n/** A Style's global CSS without its layer order, which is the page's to declare. */\nconst withoutOrder = (globalCss: string): string => globalCss.replace(LAYER_STATEMENT, '')\n\n/**\n * The CSS for every compiled class that `html` carries, and once each the\n * global CSS of the Styles those classes came from, after the standard layer\n * order: what a server puts in a page's head, so it is styled before any\n * script runs. The browser's injection then finds these present and adds\n * nothing twice.\n */\nexport const usedIn = (html: string): string => {\n const found = new Map<string, Registered>()\n for (const [className] of html.matchAll(/style-[0-9a-z]+/g)) {\n const entry = registry.get(className)\n if (entry !== undefined) found.set(className, entry)\n }\n const globals = new Set([...found.values()].flatMap(entry => [...entry.globals]))\n return [\n layerOrder(),\n ...[...found.values()].map(entry => entry.css),\n ...[...globals].map(withoutOrder),\n ].join('')\n}\n\n/**\n * `sheet` followed by every compiled class and global rule it does not hold:\n * a build's complete stylesheet, where `usedIn` finds the classes of one\n * page at request time. Which classes exist is whatever the process has\n * compiled, so load the application's styled modules first.\n */\nexport const complete = (sheet: string): string => {\n const held = new Set(Array.from(sheet.matchAll(COMPILED_CLASS), ([, name]) => name))\n const rules: Array<string> = []\n const globals = new Set<string>()\n for (const [className, entry] of registry) {\n if (!held.has(className)) rules.push(entry.css)\n for (const css of entry.globals) globals.add(withoutOrder(css))\n }\n const missing = [...globals].filter(css => css !== '' && !sheet.includes(css))\n return [sheet, ...missing, ...rules].join('')\n}\n\n/** The mark on a `<link>` to a stylesheet the page's build wrote. */\nconst LINKED = 'link[data-foldkit-styles-href]'\n\n/** Links that failed to load: counted as holding nothing, so a draw stops waiting. */\nconst failed = new WeakSet<Element>()\n\n/**\n * The rules of a linked sheet, or none where the browser withholds them (a\n * cross-origin sheet): its classes are then injected, which repeats rules\n * rather than losing them.\n */\nconst rulesOf = (sheet: CSSStyleSheet): ReadonlyArray<CSSRule> => {\n try {\n return Array.from(sheet.cssRules)\n } catch {\n return []\n }\n}\n\n/** Every compiled class a rule, or a rule nested in it (a layer, a media query), selects. */\nconst classesIn = (rules: ReadonlyArray<CSSRule>, into: Set<string>): void => {\n for (const rule of rules) {\n if ('selectorText' in rule && typeof rule.selectorText === 'string') {\n for (const [, className] of rule.selectorText.matchAll(COMPILED_CLASS))\n if (className !== undefined) into.add(className)\n }\n if ('cssRules' in rule) classesIn(Array.from(rule.cssRules as CSSRuleList), into)\n }\n}\n\n/** What the page carries: counted from its sheets once, then kept as CSS is queued. */\ninterface Page {\n readonly present: Set<string>\n readonly globals: Set<string>\n /** The text of the sheets counted, where a server may have written a global already. */\n readonly text: string\n /** Contributions already handled whole: a Style's are the same object every render. */\n readonly handled: WeakSet<object>\n /** The layer order a sheet on the page declares, which the injected sheet repeats. */\n readonly order: string | undefined\n /** The parsed sheets of the linked stylesheets that have loaded. */\n readonly linked: ReadonlyArray<CSSStyleSheet>\n /** Linked stylesheets still loading, which a draw waits for. */\n readonly waiting: ReadonlyArray<HTMLLinkElement>\n /** The sheets counted, so a removed one means counting again. */\n readonly counted: ReadonlyArray<Element>\n /** The serialized top-level rules of `linked`, read once a global needs them. */\n linkedRules: Set<string> | undefined\n element: HTMLStyleElement | undefined\n}\n\nlet page: Page | undefined\nlet pending: Array<string> = []\nlet scheduled = false\n\n/**\n * The page as injection knows it, counted afresh when a sheet it counted or its\n * own element has been removed (by a test's cleanup, or an application\n * replacing the head).\n */\nconst current = (): Page => {\n if (\n page !== undefined &&\n (page.element === undefined || page.element.isConnected) &&\n page.counted.every(sheet => sheet.isConnected) &&\n page.waiting.every(link => link.sheet === null && !failed.has(link))\n )\n return page\n const present = new Set<string>()\n let order: string | undefined\n const links = Array.from(document.querySelectorAll<HTMLLinkElement>(LINKED))\n const linked = links.flatMap(link => (link.sheet === null ? [] : [link.sheet]))\n for (const sheet of linked) classesIn(rulesOf(sheet), present)\n const counted = [...document.querySelectorAll('style'), ...links]\n const texts = counted.map(\n sheet => (sheet instanceof HTMLStyleElement ? sheet.textContent : '') ?? '',\n )\n for (const text of texts) {\n for (const [, className] of text.matchAll(COMPILED_CLASS))\n if (className !== undefined) present.add(className)\n order ??= text.match(LAYER_STATEMENT)?.[0]\n }\n page = {\n present,\n globals: new Set(),\n text: texts.join(''),\n handled: new WeakSet(),\n order,\n linked,\n waiting: links.filter(link => link.sheet === null && !failed.has(link)),\n counted,\n linkedRules: undefined,\n element: undefined,\n }\n return page\n}\n\nconst flush = (): void => {\n scheduled = false\n if (pending.length === 0) return\n const into = current()\n if (into.element === undefined) {\n const element = document.createElement('style')\n element.setAttribute('data-foldkit-styles', '')\n // A layer order first: the page's own, or the standard one where it has\n // none. Layers are ordered by where they are first named, so an injected\n // `@layer components { … }` that came to stand ahead of the page's order\n // (a test's sheet, or an application's, put in after it) would otherwise\n // make `components` the first layer, under the reset.\n element.textContent = into.order ?? layerOrder()\n document.head.appendChild(element)\n into.element = element\n }\n into.element.appendChild(document.createTextNode(pending.join('')))\n pending = []\n}\n\n/** Contributions drawn while a linked sheet was loading, drawn again once it has. */\nconst deferred: Array<Parameters<typeof ensure>[0]> = []\nconst watched = new WeakSet<Element>()\n\n/** Whether the linked sheets hold every top-level rule of `css`, as the browser writes them. */\nconst linkedHolds = (into: Page, css: string): boolean => {\n if (into.linked.length === 0 || typeof CSSStyleSheet === 'undefined') return false\n const probe = new CSSStyleSheet()\n probe.replaceSync(css)\n const rules = Array.from(probe.cssRules)\n into.linkedRules ??= new Set(\n into.linked.flatMap(sheet => rulesOf(sheet).map(rule => rule.cssText)),\n )\n const held = into.linkedRules\n return rules.length > 0 && rules.every(rule => held.has(rule.cssText))\n}\n\n/**\n * Queues the CSS of each registered class a contribution draws that the page\n * does not carry yet, and its global CSS (keyframes, a theme root) once.\n * Outside a browser it does nothing: a server extracts what it rendered instead.\n */\nexport const ensure = (contribution: {\n readonly classes?: ReadonlyArray<string>\n readonly globalCss?: string\n}): void => {\n if (typeof document === 'undefined') return\n const into = current()\n if (into.waiting.length > 0) {\n deferred.push(contribution)\n for (const link of into.waiting) {\n if (watched.has(link)) continue\n watched.add(link)\n const retry = () => {\n page = undefined\n for (const waiting of deferred.splice(0)) ensure(waiting)\n }\n link.addEventListener('load', retry, { once: true })\n link.addEventListener(\n 'error',\n () => {\n failed.add(link)\n retry()\n },\n { once: true },\n )\n }\n return\n }\n if (into.handled.has(contribution)) return\n for (const className of contribution.classes ?? []) {\n if (into.present.has(className)) continue\n const entry = registry.get(className)\n if (entry === undefined) continue\n into.present.add(className)\n pending.push(entry.css)\n }\n const globalCss = contribution.globalCss\n if (globalCss !== undefined && globalCss !== '' && !into.globals.has(globalCss)) {\n into.globals.add(globalCss)\n const css = withoutOrder(globalCss)\n // A server's `usedIn` writes the same text, so a page it rendered has it.\n if (!into.text.includes(css) && !linkedHolds(into, css)) pending.push(css)\n }\n // Frozen, a contribution cannot draw other classes next time it is drawn.\n if (Object.isFrozen(contribution)) into.handled.add(contribution)\n if (pending.length > 0 && !scheduled) {\n scheduled = true\n queueMicrotask(flush)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAM,2BAAW,IAAI,IAAwB;;;;;;AAO7C,MAAa,YAAY,WAAmB,KAAa,cAA4B;CACnF,IAAI,QAAQ,SAAS,IAAI,SAAS;CAClC,IAAI,UAAU,KAAA,GAAW;EACvB,QAAQ;GAAE;GAAK,yBAAS,IAAI,IAAI;EAAE;EAClC,S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,WAAW;EACpC,YAAY;EACZ,eAAe,KAAK;CACtB;AACF"}
|
package/dist/slotView.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slotView.d.ts","names":[],"sources":["../src/slotView.ts"],"mappings":";;;;;;YAyBY,YAAY,SAAS;;;;;;;WAOtB,QAAQ,aAAa,eAAe,wBAC3C,OAAO,MACP,OAAO,aACJ,cAAc,eAAe,qBAAqB;;;;;;;;;;WAU9C,aAAa,aAAa,SAAS,0BAC1C,MAAM,UACN,OAAO,OAAO,aAAa,OAAO,UAAU,GAAG,YAAY,UAAU,MAAM,SAAS,MACpF,MAAM,SACH;;YAGK,aAAa,OAAO,uBACpB,WAAW,QAAQ,YAAY,SAAS;YAGxC,eAAe,OAAO,OAAO,YACvC,OAAO,OACP,OAAO,aAAa,OAAO,UAC3B,GAAG,YAAY,aACZ;iBAEY,SAAS,OAAO,OAAO,iBAAiB,SAAS,SAAS,OAAO,OAAO;GACtF,OAAO,OAAO,GAAG,YAAY,WAAW;WAChC;WACA,OAAO;WACP,QAAQ,cAAc,SAAS;WAC/B,QAAQ,eAAe,OAAO,OAAO;;;
|
|
1
|
+
{"version":3,"file":"slotView.d.ts","names":[],"sources":["../src/slotView.ts"],"mappings":";;;;;;YAyBY,YAAY,SAAS;;;;;;;WAOtB,QAAQ,aAAa,eAAe,wBAC3C,OAAO,MACP,OAAO,aACJ,cAAc,eAAe,qBAAqB;;;;;;;;;;WAU9C,aAAa,aAAa,SAAS,0BAC1C,MAAM,UACN,OAAO,OAAO,aAAa,OAAO,UAAU,GAAG,YAAY,UAAU,MAAM,SAAS,MACpF,MAAM,SACH;;YAGK,aAAa,OAAO,uBACpB,WAAW,QAAQ,YAAY,SAAS;YAGxC,eAAe,OAAO,OAAO,YACvC,OAAO,OACP,OAAO,aAAa,OAAO,UAC3B,GAAG,YAAY,aACZ;iBAEY,SAAS,OAAO,OAAO,iBAAiB,SAAS,SAAS,OAAO,OAAO;GACtF,OAAO,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AAO,aAAa,OAAO,UAC3B,GAAG,YAAY,aACZ,SACF,KAAK,OAAO,OAAO;;;;;WAKf,WACP,QAAQ,eAAe,OAAO,OAAO,UACrC;aAAqB;QAClB,SAAS,OAAO,OAAO;;;;;;;;;;;;;;qBAyDjB,QACV,OAAK,OAAS,WACd,OAAO,cAAY,MAAM,OAAO,OAAO;;;;;;;iBAoCzB,MAAM,MAAM;;WAElB,cAAc,cAAc;WAC5B,OAAO,MAAM,SAAS;;;YAIrB,OAAO,MAAM,OAAO,YAC9B,MAAM,MACN,OAAO,aAAa,OAAO,UAC3B,GAAG,YAAY,aACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4BQ,SAAU,MAAM,OAAO,OAAO,SAAO,OACzC,MAAM,MAAM,QAAM,OAClB,OAAO,OAAO,OAAO,aAAa,OAAO,UAAU,GAAG,YAAY,aAAa,SACrF,OAAO,MAAM,OAAO"}
|
package/dist/slotView.js
CHANGED
|
@@ -72,7 +72,8 @@ const itemMemoOf = (draw) => {
|
|
|
72
72
|
used: /* @__PURE__ */ new Map(),
|
|
73
73
|
given: /* @__PURE__ */ new Map(),
|
|
74
74
|
drawn: /* @__PURE__ */ new Set(),
|
|
75
|
-
before: /* @__PURE__ */ new Set()
|
|
75
|
+
before: /* @__PURE__ */ new Set(),
|
|
76
|
+
open: false
|
|
76
77
|
};
|
|
77
78
|
itemMemos.set(draw, made);
|
|
78
79
|
return made;
|
|
@@ -80,23 +81,31 @@ const itemMemoOf = (draw) => {
|
|
|
80
81
|
/**
|
|
81
82
|
* Notes `key` drawn. Foldkit's keyed memo keeps every key for the page's life,
|
|
82
83
|
* so a list keyed by search results or scrolled through 100,000 rows would
|
|
83
|
-
* hold a drawing of each.
|
|
84
|
-
*
|
|
85
|
-
*
|
|
84
|
+
* hold a drawing of each. Foldkit draws a view tree synchronously in one
|
|
85
|
+
* frame, so the first key noted after the last pass closed begins a new one;
|
|
86
|
+
* the microtask that follows the render closes it and forgets what neither it
|
|
87
|
+
* nor the pass before drew (two passes, so two views sharing a `draw` keep
|
|
88
|
+
* each other's). Keys that never repeat, as successive windows of a virtual
|
|
89
|
+
* list, are still forgotten.
|
|
86
90
|
*/
|
|
87
91
|
const remember = (memo, key) => {
|
|
88
|
-
if (memo.
|
|
89
|
-
|
|
90
|
-
if (memo.drawn.has(known) || memo.before.has(known)) continue;
|
|
91
|
-
memo.lazies.delete(known);
|
|
92
|
-
memo.used.delete(known);
|
|
93
|
-
memo.given.delete(known);
|
|
94
|
-
}
|
|
92
|
+
if (!memo.open) {
|
|
93
|
+
memo.open = true;
|
|
95
94
|
memo.before = memo.drawn;
|
|
96
95
|
memo.drawn = /* @__PURE__ */ new Set();
|
|
96
|
+
queueMicrotask(() => closePass(memo));
|
|
97
97
|
}
|
|
98
98
|
memo.drawn.add(key);
|
|
99
99
|
};
|
|
100
|
+
const closePass = (memo) => {
|
|
101
|
+
memo.open = false;
|
|
102
|
+
for (const known of /* @__PURE__ */ new Set([...memo.lazies.keys(), ...memo.used.keys()])) {
|
|
103
|
+
if (memo.drawn.has(known) || memo.before.has(known)) continue;
|
|
104
|
+
memo.lazies.delete(known);
|
|
105
|
+
memo.used.delete(known);
|
|
106
|
+
memo.given.delete(known);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
100
109
|
const lazyFor = (memo, key) => {
|
|
101
110
|
const known = memo.lazies.get(key);
|
|
102
111
|
if (known !== void 0) return known;
|
package/dist/slotView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slotView.js","names":[],"sources":["../src/slotView.ts"],"sourcesContent":["/**\n * `SlotView` is the structural equivalent of a Surface: a pure Foldkit view\n * that publishes typed Slots and lets Mixins attach without forking it. It\n * owns no state and runs no Effects. Attached Mixins are resolved into\n * ordinary Foldkit attributes per slot, using the view's own `h` so Message\n * capability masking is preserved.\n */\nimport { createLazy, inertHtml, type Html, type HtmlBuilder } from 'foldkit/html'\nimport { Projection } from 'foldkit-surface'\nimport type { NamedBehavior } from './behavior.js'\nimport type { SlotContribution, SlotItem } from './contribution.js'\nimport { ensure } from './inject.js'\nimport { SLOT_MARK, isMarking } from './slotMark.js'\nimport {\n evaluate,\n isDynamic,\n type AnyMixin,\n type Mixin,\n type MixinFor,\n type StaticMixin,\n} from './mixin.js'\nimport { pipeSelf, type Pipeable } from './pipe.js'\nimport { resolve, type ContributedAttribute, type SlotAttributes } from './resolver.js'\nimport type { Any as AnySlot, SlotProtection } from './slot.js'\n\nexport type SlotBuilder<Message, Slots = unknown> = {\n /**\n * The view's base attributes plus every resolved contribution. Pass `item`\n * when the slot is rendered once per item, so a Behavior can decorate each\n * repetition differently. Typed as the base was, plus what a Mixin adds\n * (never `InnerHTML`), so a base fit for `h.textarea` stays fit for it.\n */\n readonly attrs: <Base extends SlotAttributes<Message> = readonly []>(\n base?: Base,\n item?: SlotItem,\n ) => ReadonlyArray<Base[number] | ContributedAttribute<Message>>\n /**\n * One item's drawing, drawn again only when a value in `args` changed by\n * identity or what the Mixins gave the Slots it used for this item changed\n * in value (a static Style by identity). `draw` must read nothing but its\n * arguments, so pass a function defined once, not a closure made per\n * render. Keyed by `item.id`, else its index, and remembered per `draw`:\n * two views drawing one key with one `draw` share its memo, and miss it\n * whenever what they give it differs.\n */\n readonly lazy: <const Args extends Readonly<Record<string, unknown>>>(\n item: SlotItem,\n draw: (slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>, args: Args) => Html,\n args: Args,\n ) => Html\n}\n\nexport type SlotBuilders<Slots, Message> = {\n readonly [K in keyof Slots]: SlotBuilder<Message, Slots>\n}\n\nexport type SlotViewRender<Slots, Input, Message> = (\n input: Input,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n) => Html\n\nexport interface SlotView<Slots, Input, Message> extends Pipeable<SlotView<Slots, Input, Message>> {\n (input: Input, h: HtmlBuilder<Message>): Html\n readonly name?: string\n readonly slots: Slots\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n readonly render: SlotViewRender<Slots, Input, Message>\n}\n\n/** Mixins resolved against one input: a part's own against its selection, the view's against the whole. */\ninterface MixinGroup<Message> {\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n readonly input: unknown\n}\n\n// The view's Mixins behind each builders record `buildersFor` makes, so an\n// assembly's parts resolve the same ones; the array itself, so a memo can compare it.\nconst mixinsOf = new WeakMap<object, ReadonlyArray<MixinFor<any>>>()\n\n/** Like `buildersFor`, with each group of Mixins resolved against its own input, in order. */\nconst buildersOver = <Slots, Message>(\n slots: Slots,\n groups: ReadonlyArray<MixinGroup<Message>>,\n h: HtmlBuilder<Message>,\n): SlotBuilders<Slots, Message> => {\n const source = slots as unknown as Record<string, AnySlot>\n const builders: Record<string, SlotBuilder<Message>> = Object.create(null)\n for (const name of Object.getOwnPropertyNames(source)) {\n const slot = source[name]\n if (slot === undefined) continue\n const protection: SlotProtection = slot.protected\n builders[name] = {\n attrs: <Base extends SlotAttributes<Message> = readonly []>(\n base?: Base,\n item?: SlotItem,\n ): ReadonlyArray<Base[number] | ContributedAttribute<Message>> => {\n using?.add(name)\n const contributions = []\n for (const { mixins, input } of groups) {\n for (const mixin of mixins) {\n const contribution = mixin.contributions[name]\n if (contribution !== undefined) {\n const evaluated = evaluate(contribution as SlotContribution<Message>, {\n input,\n h,\n ...(item === undefined ? {} : { item }),\n })\n // What this Slot draws brings its CSS, whether or not a stylesheet listed it.\n ensure(evaluated)\n contributions.push(evaluated)\n }\n }\n }\n // The base's own attributes and what Mixins added, of which the resolver\n // refuses `InnerHTML` (`mixins:structural-override`).\n const resolved = resolve(base, contributions, {\n slot: name,\n protected: protection,\n }) as ReadonlyArray<Base[number] | ContributedAttribute<Message>>\n // Only while a test draws with `Inert.draw`: never for a real render.\n return isMarking() ? [...resolved, h.DataAttribute(SLOT_MARK, name)] : resolved\n },\n lazy: (item, draw, args) =>\n drawItem(item, draw, args, {\n builders: builders as SlotBuilders<Slots, Message>,\n h,\n given: used =>\n used.flatMap(slot =>\n groups.flatMap(({ mixins, input }) =>\n mixins.flatMap(mixin => {\n // As `attrs` reads it: a `Mixin<never>` only ever gives message-free data.\n const contribution = mixin.contributions[slot] as\n | SlotContribution<Message>\n | undefined\n // A static one as it is: two views apart only by a Style draw rows apart.\n return contribution === undefined\n ? []\n : [isDynamic(contribution) ? contribution({ input, h, item }) : contribution]\n }),\n ),\n ),\n first: name,\n }),\n }\n }\n return builders as SlotBuilders<Slots, Message>\n}\n\n// The Slots the per-item drawing now running has used, if one is, and whether\n// it drew another inside it.\nconst NESTED = Symbol('nested')\nlet using: Set<string | typeof NESTED> | undefined\n\n/**\n * One `draw`'s items: a memo per key, the Slots each used, what those were\n * given, and the keys drawn in this pass and the one before, so a key no\n * longer drawn is forgotten.\n */\ninterface ItemMemo {\n readonly lazies: Map<PropertyKey, ReturnType<typeof createLazy>>\n readonly used: Map<PropertyKey, ReadonlyArray<string | typeof NESTED>>\n readonly given: Map<PropertyKey, unknown>\n drawn: Set<PropertyKey>\n before: Set<PropertyKey>\n}\nconst itemMemos = new WeakMap<object, ItemMemo>()\nconst itemMemoOf = (draw: object): ItemMemo => {\n const known = itemMemos.get(draw)\n if (known !== undefined) return known\n const made: ItemMemo = {\n lazies: new Map(),\n used: new Map(),\n given: new Map(),\n drawn: new Set(),\n before: new Set(),\n }\n itemMemos.set(draw, made)\n return made\n}\n\n/**\n * Notes `key` drawn. Foldkit's keyed memo keeps every key for the page's life,\n * so a list keyed by search results or scrolled through 100,000 rows would\n * hold a drawing of each. A key is drawn once per pass, so one drawn again\n * means a new pass began: what neither that pass nor the one before drew is\n * forgotten (two passes, so two views sharing a `draw` keep each other's).\n */\nconst remember = (memo: ItemMemo, key: PropertyKey): void => {\n if (memo.drawn.has(key)) {\n for (const known of new Set([...memo.lazies.keys(), ...memo.used.keys()])) {\n if (memo.drawn.has(known) || memo.before.has(known)) continue\n memo.lazies.delete(known)\n memo.used.delete(known)\n memo.given.delete(known)\n }\n memo.before = memo.drawn\n memo.drawn = new Set()\n }\n memo.drawn.add(key)\n}\n\nconst lazyFor = (memo: ItemMemo, key: PropertyKey): ReturnType<typeof createLazy> => {\n const known = memo.lazies.get(key)\n if (known !== undefined) return known\n const made = createLazy()\n memo.lazies.set(key, made)\n return made\n}\n\n// The drawing a missed item runs: set just before the memo is asked, so the\n// memo sees one function whose arguments are all it compares.\nlet pending: (() => Html) | undefined\nconst runPending = (..._compared: ReadonlyArray<unknown>): Html => pending!()\n\n// How many memoized drawings have started. Foldkit's lazy slot throws before\n// it calls the drawing when there is no runtime frame, so a throw with this\n// unchanged is that, and a throw after it moved is the drawing's own error.\nlet started = 0\n\n/**\n * Set by `foldkit-ssr` while it renders a page on the server, under a\n * registered symbol so it crosses bundles. Each of its passes is drawn\n * whole: a drawing kept from another pass or another request would carry\n * that render's resume markers and none of this one's bindings.\n */\nconst SERVER_RENDER = Symbol.for('foldkit-plus.serverRender')\n\n/**\n * `memoized()` under a lazy slot, or `plain()` where there is no runtime frame\n * to memoize under (a test, a server's first pass) or a server renders a page. An error from the drawing\n * itself is thrown as it is, not drawn a second time.\n */\nconst memoizedOr = (memoized: () => Html, plain: () => Html): Html => {\n if ((globalThis as Record<symbol, unknown>)[SERVER_RENDER] === true) return plain()\n const before = started\n try {\n return memoized()\n } catch (error) {\n if (started !== before) throw error\n return plain()\n }\n}\n\nconst isPlain = (value: object): boolean => {\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null || Array.isArray(value)\n}\n\n/**\n * Whether two evaluated contributions hold the same data: arrays and plain\n * objects (Foldkit's attributes and Messages are) by value, anything else by\n * identity, since a `Map` or a `Date` keeps its contents where `Object.keys`\n * does not see them. A handler made per render is never the same, so an item\n * a Mixin gives one is drawn again every time: correct, not cached.\n */\nconst sameData = (left: unknown, right: unknown, depth = 0): boolean => {\n if (Object.is(left, right)) return true\n if (depth > 8) return false\n if (typeof left !== 'object' || typeof right !== 'object' || left === null || right === null)\n return false\n if (!isPlain(left) || Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) return false\n const keys = Object.keys(left)\n if (keys.length !== Object.keys(right).length) return false\n return keys.every(\n key =>\n Object.hasOwn(right, key) &&\n sameData(\n (left as Record<string, unknown>)[key],\n (right as Record<string, unknown>)[key],\n depth + 1,\n ),\n )\n}\n\nconst drawItem = <Slots, Message, Args extends Readonly<Record<string, unknown>>>(\n item: SlotItem,\n draw: (slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>, args: Args) => Html,\n args: Args,\n context: {\n readonly builders: SlotBuilders<Slots, Message>\n readonly h: HtmlBuilder<Message>\n readonly given: (used: ReadonlyArray<string>) => ReadonlyArray<unknown>\n readonly first: string\n },\n): Html => {\n // Inside another item's drawing, drawn in place, and the outer one is not\n // cached: its key would read this one's Slots with the outer item.\n if (using !== undefined) {\n using.add(NESTED)\n return draw(context.builders, context.h, args)\n }\n const memo = itemMemoOf(draw)\n const key = item.id ?? item.index\n // What an item used and was given is kept only under a runtime frame, where a\n // memo can use it: a server drawing page after page keeps nothing.\n const run = (kept: boolean): Html => {\n started++\n using = new Set()\n try {\n const html = draw(context.builders, context.h, args)\n if (kept) memo.used.set(key, [...using])\n return html\n } finally {\n using = undefined\n }\n }\n const used = memo.used.get(key) ?? [context.first]\n if (used.includes(NESTED)) {\n remember(memo, key)\n return run(true)\n }\n const now = context.given(used.filter(slot => slot !== NESTED))\n const before = memo.given.get(key)\n // The same data keeps the value last compared, so the memo sees it unchanged.\n const given = before !== undefined && sameData(before, now) ? before : now\n pending = () => run(true)\n try {\n // The record is new every render; its keys and values are what stay the same.\n const compared = [draw, given, ...Object.keys(args), ...Object.values(args)]\n return memoizedOr(\n () => {\n const html = lazyFor(memo, key)(runPending, compared)\n remember(memo, key)\n memo.given.set(key, given)\n return html\n },\n // No frame (a test, a server's pages): nothing is kept, not even the empty memo.\n () => {\n memo.lazies.delete(key)\n return run(false)\n },\n )\n } finally {\n pending = undefined\n }\n}\n\n/** Build one `attrs` resolver per published slot, evaluating Mixins lazily. */\nexport const buildersFor = <Slots, Message, Input>(\n slots: Slots,\n mixins: ReadonlyArray<MixinFor<Message>>,\n context: { readonly input: Input; readonly h: HtmlBuilder<Message> },\n): SlotBuilders<Slots, Message> => {\n const builders = buildersOver(slots, [{ mixins, input: context.input }], context.h)\n mixinsOf.set(builders, mixins)\n return builders\n}\n\nconst makeView = <Slots, Input, Message>(\n name: string | undefined,\n slots: Slots,\n mixins: ReadonlyArray<MixinFor<Message>>,\n render: SlotViewRender<Slots, Input, Message>,\n): SlotView<Slots, Input, Message> => {\n const view = (input: Input, h: HtmlBuilder<Message>): Html =>\n render(input, buildersFor(slots, mixins, { input, h }), h)\n // A function's own `name` is read-only; define it rather than assigning.\n if (name !== undefined) {\n Object.defineProperty(view, 'name', { value: name, configurable: true })\n }\n return Object.assign(view, {\n slots,\n mixins,\n render,\n pipe: (...fns: ReadonlyArray<(self: unknown) => unknown>) => pipeSelf(view, fns),\n }) as unknown as SlotView<Slots, Input, Message>\n}\n\n/**\n * Defines a view over published Slots.\n *\n * `Message` has no anchor but the render callback's builder, so it is inferred\n * from an explicit `h: HtmlBuilder<Message>` annotation on that parameter.\n * Without one it resolves to `unknown`, and the first error appears later and\n * elsewhere — an invariance mismatch at `Style.attach`/`Behavior.attach` that\n * does not name the missing annotation. `forMessages<Message>()` fixes the\n * Message universe up front instead, and leaves `h` contextually typed.\n */\nexport const define = <Slots, Input, Message>(\n slots: Slots,\n render: SlotViewRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n): SlotView<Slots, Input, Message> => makeView(options?.name, slots, [], render)\n\n/**\n * Foldkit's `inertHtml` typed for a Message universe, for rendering a view\n * outside a runtime (tests, demos, static description). `inertHtml` is\n * `HtmlBuilder<never>`, and the builder is invariant in `Message`, so this is\n * the one cast: sound outside a runtime render, where no handler is ever\n * dispatched. Inside one it is the same builder every view is given, so its\n * handlers would reach the frame's `update`: use the view's own `h` there.\n */\nexport const inertBuilder = <Message>(): HtmlBuilder<Message> =>\n inertHtml as unknown as HtmlBuilder<Message>\n\n/** The `SlotView` constructors with `Message` already fixed. */\nexport interface MessageSlotView<Message> {\n readonly define: <Slots, Input>(\n slots: Slots,\n render: SlotViewRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n ) => SlotView<Slots, Input, Message>\n}\n\n/**\n * Binds the view constructors to one Message universe, so the render callback\n * no longer has to annotate `h` to pin it. `Input` is still inferred from the\n * callback's own `input` annotation.\n *\n * @example\n * ```ts\n * const Field = SlotView.forMessages<Message>().define(\n * FieldSlots,\n * (input: FieldInput, slots, h) =>\n * h.input(slots.input.attrs([h.OnInput(value => Message.ChangedValue({ value }))])),\n * )\n * ```\n */\nexport const forMessages = <Message>(): MessageSlotView<Message> => ({ define })\n\n/** A transform on any view, used by Message-free static mixins such as Style. */\nexport type SlotViewTransform = <Slots, Input, Message>(\n view: SlotView<Slots, Input, Message>,\n) => SlotView<Slots, Input, Message>\n\n/** A transform restricted to one Message universe, for Behavior mixins. */\nexport type SlotViewTransformFor<Message> = <Slots, Input>(\n view: SlotView<Slots, Input, Message>,\n) => SlotView<Slots, Input, Message>\n\n/** Attach one Mixin. Returns a new view; the original is unchanged. */\nexport function attach(mixin: StaticMixin<never> | Mixin<never>): SlotViewTransform\nexport function attach<MixinMessage>(mixin: Mixin<MixinMessage>): SlotViewTransformFor<MixinMessage>\nexport function attach(mixin: AnyMixin | Mixin<never>): any {\n return (view: SlotView<any, any, any>) =>\n makeView(view.name, view.slots, [...view.mixins, mixin], view.render)\n}\n\n/**\n * One piece of an assembled view, drawn from its own selection of the view's\n * input: the keys it names in `reads`, and nothing else. It is drawn again\n * only when one of those values changed, by identity.\n */\nexport interface Part<Slots, Input, Message> {\n readonly name: string\n readonly reads: ReadonlyArray<keyof Input>\n /** The Behaviors declared with the part, resolved against its selection. */\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n // `any`: the part's own selection, which `Parts.part` typed from `reads`.\n readonly render: (\n input: any,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n ) => Html\n}\n\n/** An assembly's own drawing: the parts it places, by `draw`, and anything else around them. */\nexport type AssemblyRender<Slots, Input, Message> = (\n input: Input,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n draw: (part: Part<Slots, Input, Message>) => Html,\n) => Html\n\nexport interface Parts<Slots, Input, Message> {\n /**\n * A part reading `reads` of the input. `behaviors` are declared over that\n * selection, so they cannot read what the part does not redraw for.\n */\n readonly part: <const Reads extends ReadonlyArray<keyof Input>>(\n name: string,\n options: {\n readonly reads: Reads\n readonly behaviors?: ReadonlyArray<NamedBehavior<Slots, Pick<Input, Reads[number]>, Message>>\n },\n render: (\n input: Pick<Input, Reads[number]>,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n ) => Html,\n ) => Part<Slots, Input, Message>\n /**\n * A SlotView that draws its parts where `render` places them. Styles and\n * Behaviors attach to it as to any SlotView and reach every part's Slots.\n */\n readonly assemble: (\n render: AssemblyRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n ) => SlotView<Slots, Input, Message>\n}\n\n// A part's memo. A part drawn twice in one render is the same drawing twice,\n// which Foldkit copies for the second place.\nconst lazies = new WeakMap<object, ReturnType<typeof createLazy>>()\nconst lazyOf = (part: object): ReturnType<typeof createLazy> => {\n const known = lazies.get(part)\n if (known !== undefined) return known\n const made = createLazy()\n lazies.set(part, made)\n return made\n}\n\n// Whether any of these Mixins reads the input: a function contribution may.\nconst readsInput = new WeakMap<ReadonlyArray<MixinFor<any>>, boolean>()\nconst anyDynamic = (mixins: ReadonlyArray<MixinFor<any>>): boolean => {\n const known = readsInput.get(mixins)\n if (known !== undefined) return known\n const found = mixins.some(mixin => Object.values(mixin.contributions).some(isDynamic))\n readsInput.set(mixins, found)\n return found\n}\n\n/**\n * One part, from its arguments alone, so the memo sees one function: the\n * whole input only when a view-wide Mixin reads it, and the part's read values.\n */\nconst drawPart = <Slots, Input, Message>(\n part: Part<Slots, Input, Message>,\n slots: Slots,\n h: HtmlBuilder<Message>,\n mixins: ReadonlyArray<MixinFor<Message>>,\n whole: unknown,\n ...values: Array<unknown>\n): Html => {\n started++\n const selection = Object.fromEntries(part.reads.map((key, at) => [key, values[at]]))\n const groups = [\n { mixins: part.mixins, input: selection },\n { mixins, input: whole },\n ]\n return part.render(selection, buildersOver(slots, groups, h), h)\n}\n\n/**\n * Parts over one set of Slots and one input, and the assembly that places them.\n *\n * @example\n * ```ts\n * const Parts = SlotView.parts(PanelSlots)<PanelInput, Message>()\n * const Title = Parts.part('Title', { reads: ['title'] }, (input, slots, h) =>\n * h.h2(slots.title.attrs(), [input.title]),\n * )\n * const Panel = Parts.assemble((input, slots, h, draw) => h.section(slots.root.attrs(), [draw(Title)]))\n * ```\n */\nexport const parts =\n <Slots>(slots: Slots) =>\n <Input, Message>(): Parts<Slots, Input, Message> => ({\n part: (name, options, render) => ({\n name,\n reads: options.reads,\n mixins: (options.behaviors ?? []).map(behavior => behavior.mixin),\n render,\n }),\n assemble: (render, options) =>\n makeView<Slots, Input, Message>(options?.name, slots, [], (input, builders, h) => {\n const mixins: ReadonlyArray<MixinFor<Message>> = mixinsOf.get(builders) ?? []\n // A Mixin attached to the whole view that reads the input is resolved\n // against all of it, so a part it reaches redraws whenever the input changes.\n const whole = anyDynamic(mixins) ? input : undefined\n return render(input, builders, h, part => {\n const args: Parameters<typeof drawPart<Slots, Input, Message>> = [\n part,\n slots,\n h,\n mixins,\n whole,\n ...part.reads.map(key => input[key]),\n ]\n return memoizedOr(\n () => lazyOf(part)(drawPart<Slots, Input, Message>, args),\n () => drawPart(...args),\n )\n })\n }),\n })\n\n/**\n * What a region reads: the Model paths it depends on and how its value is\n * read from the root. A `foldkit-surface` `Projection` is one, as built from\n * the application's field references (`Projection.struct({ cart:\n * App.model.cart })`), so the paths are the ones the references declare.\n */\nexport interface Reads<Root, Value> {\n /** Paths from the root, each a list of property names. */\n readonly dependencies: ReadonlyArray<ReadonlyArray<string>>\n readonly read: (root: Root) => Value\n}\n\n/** A region of a SlotView's drawing, drawn again only when what it reads changed. */\nexport type Region<Root, Slots, Message> = (\n root: Root,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n) => Html\n\n/**\n * A region: part of a SlotView's drawing that is given only what `reads`\n * reads, and drawn again only when that changed. While every path `reads`\n * depends on holds the value it held, the region does not read at all and\n * Foldkit reuses its last drawing without diffing it; when one changed and\n * the read gives the same fields as before, it is reused too. What reads no\n * path of its own (a Remote read, alone or in a `Projection.struct`) is read\n * on every render, and the region drawn again when that gives other fields.\n * Like a Slot's `lazy` item, it is drawn again when a Mixin gives the Slots\n * it used something different, and drawn afresh where there is no runtime\n * frame.\n *\n * `draw` reads only its value, so the region cannot read what it is not\n * drawn again for. A region drawn inside another region or item is drawn in\n * place, and the outer one every time.\n *\n * @example\n * ```ts\n * const Header = SlotView.region(\n * Projection.struct({ cart: App.model.cart }),\n * ({ cart }, slots: SlotView.SlotBuilders<typeof Page.slots, Message>, h: HtmlBuilder<Message>) =>\n * h.header(slots.header.attrs(), [`${cart.length} in the cart`]),\n * )\n * // In the page's render: Header(model, slots, h)\n * ```\n */\nexport const region = <Root, Value, Slots, Message>(\n reads: Reads<Root, Value>,\n draw: (value: Value, slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>) => Html,\n): Region<Root, Slots, Message> => {\n // Worked out again by the same rule a derivation is, and drawn again by the\n // lazy slot only when that gives a new value.\n const derived = Projection.derive([reads], reads.read)\n const drawRegion = (\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n args: { readonly value: Value },\n ): Html => draw(args.value, slots, h)\n return (root, slots, h) => {\n const builder = Object.values(slots)[0] as SlotBuilder<Message, Slots> | undefined\n if (builder === undefined) throw new Error('SlotView.region: the view publishes no Slots')\n return builder.lazy({ index: 0 }, drawRegion, { value: derived.read(root) })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8EA,MAAM,2BAAW,IAAI,QAA8C;;AAGnE,MAAM,gBACJ,OACA,QACA,MACiC;CACj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M,SAA2C,SAAS,IAAI,QAAQ,KAAK,CAAC;EAG5E,MAAM,QAAQ,WAAW,MAAM,IAAI,QAAQ,KAAA;EAC3C,OAAO,OAAO,OAAO,UAAU,IAAG,SAAQ;GACxC,MAAM,OAA2D;IAC/D;IACA;IACA;IACA;IACA;IACA,GAAG,KAAK,MAAM,KAAI,QAAO,MAAM,IAAI;GACrC;GACA,OAAO,iBACC,OAAO,IAAI,CAAC,CAAC,UAAiC,IAAI,SAClD,SAAS,GAAG,IAAI,CACxB;EACF,CAAC;CACH,CAAC;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CF,MAAa,UACX,OACA,SACiC;CAGjC,MAAM,UAAU,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,IAAI;CACrD,MAAM,cACJ,OACA,GACA,SACS,KAAK,KAAK,OAAO,OAAO,CAAC;CACpC,QAAQ,MAAM,OAAO,MAAM;EACzB,MAAM,UAAU,OAAO,OAAO,KAAK,CAAC,CAAC;EACrC,IAAI,YAAY,KAAA,GAAW,MAAM,IAAI,MAAM,8CAA8C;EACzF,OAAO,QAAQ,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,OAAO,QAAQ,KAAK,IAAI,EAAE,CAAC;CAC7E;AACF"}
|
|
1
|
+
{"version":3,"file":"slotView.js","names":[],"sources":["../src/slotView.ts"],"sourcesContent":["/**\n * `SlotView` is the structural equivalent of a Surface: a pure Foldkit view\n * that publishes typed Slots and lets Mixins attach without forking it. It\n * owns no state and runs no Effects. Attached Mixins are resolved into\n * ordinary Foldkit attributes per slot, using the view's own `h` so Message\n * capability masking is preserved.\n */\nimport { createLazy, inertHtml, type Html, type HtmlBuilder } from 'foldkit/html'\nimport { Projection } from 'foldkit-surface'\nimport type { NamedBehavior } from './behavior.js'\nimport type { SlotContribution, SlotItem } from './contribution.js'\nimport { ensure } from './inject.js'\nimport { SLOT_MARK, isMarking } from './slotMark.js'\nimport {\n evaluate,\n isDynamic,\n type AnyMixin,\n type Mixin,\n type MixinFor,\n type StaticMixin,\n} from './mixin.js'\nimport { pipeSelf, type Pipeable } from './pipe.js'\nimport { resolve, type ContributedAttribute, type SlotAttributes } from './resolver.js'\nimport type { Any as AnySlot, SlotProtection } from './slot.js'\n\nexport type SlotBuilder<Message, Slots = unknown> = {\n /**\n * The view's base attributes plus every resolved contribution. Pass `item`\n * when the slot is rendered once per item, so a Behavior can decorate each\n * repetition differently. Typed as the base was, plus what a Mixin adds\n * (never `InnerHTML`), so a base fit for `h.textarea` stays fit for it.\n */\n readonly attrs: <Base extends SlotAttributes<Message> = readonly []>(\n base?: Base,\n item?: SlotItem,\n ) => ReadonlyArray<Base[number] | ContributedAttribute<Message>>\n /**\n * One item's drawing, drawn again only when a value in `args` changed by\n * identity or what the Mixins gave the Slots it used for this item changed\n * in value (a static Style by identity). `draw` must read nothing but its\n * arguments, so pass a function defined once, not a closure made per\n * render. Keyed by `item.id`, else its index, and remembered per `draw`:\n * two views drawing one key with one `draw` share its memo, and miss it\n * whenever what they give it differs.\n */\n readonly lazy: <const Args extends Readonly<Record<string, unknown>>>(\n item: SlotItem,\n draw: (slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>, args: Args) => Html,\n args: Args,\n ) => Html\n}\n\nexport type SlotBuilders<Slots, Message> = {\n readonly [K in keyof Slots]: SlotBuilder<Message, Slots>\n}\n\nexport type SlotViewRender<Slots, Input, Message> = (\n input: Input,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n) => Html\n\nexport interface SlotView<Slots, Input, Message> extends Pipeable<SlotView<Slots, Input, Message>> {\n (input: Input, h: HtmlBuilder<Message>): Html\n readonly name?: string\n readonly slots: Slots\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n readonly render: SlotViewRender<Slots, Input, Message>\n}\n\n/** Mixins resolved against one input: a part's own against its selection, the view's against the whole. */\ninterface MixinGroup<Message> {\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n readonly input: unknown\n}\n\n// The view's Mixins behind each builders record `buildersFor` makes, so an\n// assembly's parts resolve the same ones; the array itself, so a memo can compare it.\nconst mixinsOf = new WeakMap<object, ReadonlyArray<MixinFor<any>>>()\n\n/** Like `buildersFor`, with each group of Mixins resolved against its own input, in order. */\nconst buildersOver = <Slots, Message>(\n slots: Slots,\n groups: ReadonlyArray<MixinGroup<Message>>,\n h: HtmlBuilder<Message>,\n): SlotBuilders<Slots, Message> => {\n const source = slots as unknown as Record<string, AnySlot>\n const builders: Record<string, SlotBuilder<Message>> = Object.create(null)\n for (const name of Object.getOwnPropertyNames(source)) {\n const slot = source[name]\n if (slot === undefined) continue\n const protection: SlotProtection = slot.protected\n builders[name] = {\n attrs: <Base extends SlotAttributes<Message> = readonly []>(\n base?: Base,\n item?: SlotItem,\n ): ReadonlyArray<Base[number] | ContributedAttribute<Message>> => {\n using?.add(name)\n const contributions = []\n for (const { mixins, input } of groups) {\n for (const mixin of mixins) {\n const contribution = mixin.contributions[name]\n if (contribution !== undefined) {\n const evaluated = evaluate(contribution as SlotContribution<Message>, {\n input,\n h,\n ...(item === undefined ? {} : { item }),\n })\n // What this Slot draws brings its CSS, whether or not a stylesheet listed it.\n ensure(evaluated)\n contributions.push(evaluated)\n }\n }\n }\n // The base's own attributes and what Mixins added, of which the resolver\n // refuses `InnerHTML` (`mixins:structural-override`).\n const resolved = resolve(base, contributions, {\n slot: name,\n protected: protection,\n }) as ReadonlyArray<Base[number] | ContributedAttribute<Message>>\n // Only while a test draws with `Inert.draw`: never for a real render.\n return isMarking() ? [...resolved, h.DataAttribute(SLOT_MARK, name)] : resolved\n },\n lazy: (item, draw, args) =>\n drawItem(item, draw, args, {\n builders: builders as SlotBuilders<Slots, Message>,\n h,\n given: used =>\n used.flatMap(slot =>\n groups.flatMap(({ mixins, input }) =>\n mixins.flatMap(mixin => {\n // As `attrs` reads it: a `Mixin<never>` only ever gives message-free data.\n const contribution = mixin.contributions[slot] as\n | SlotContribution<Message>\n | undefined\n // A static one as it is: two views apart only by a Style draw rows apart.\n return contribution === undefined\n ? []\n : [isDynamic(contribution) ? contribution({ input, h, item }) : contribution]\n }),\n ),\n ),\n first: name,\n }),\n }\n }\n return builders as SlotBuilders<Slots, Message>\n}\n\n// The Slots the per-item drawing now running has used, if one is, and whether\n// it drew another inside it.\nconst NESTED = Symbol('nested')\nlet using: Set<string | typeof NESTED> | undefined\n\n/**\n * One `draw`'s items: a memo per key, the Slots each used, what those were\n * given, and the keys drawn in this pass and the one before, so a key no\n * longer drawn is forgotten. `open` while a pass has begun and its closing\n * microtask has not run.\n */\ninterface ItemMemo {\n readonly lazies: Map<PropertyKey, ReturnType<typeof createLazy>>\n readonly used: Map<PropertyKey, ReadonlyArray<string | typeof NESTED>>\n readonly given: Map<PropertyKey, unknown>\n drawn: Set<PropertyKey>\n before: Set<PropertyKey>\n open: boolean\n}\nconst itemMemos = new WeakMap<object, ItemMemo>()\nconst itemMemoOf = (draw: object): ItemMemo => {\n const known = itemMemos.get(draw)\n if (known !== undefined) return known\n const made: ItemMemo = {\n lazies: new Map(),\n used: new Map(),\n given: new Map(),\n drawn: new Set(),\n before: new Set(),\n open: false,\n }\n itemMemos.set(draw, made)\n return made\n}\n\n/**\n * Notes `key` drawn. Foldkit's keyed memo keeps every key for the page's life,\n * so a list keyed by search results or scrolled through 100,000 rows would\n * hold a drawing of each. Foldkit draws a view tree synchronously in one\n * frame, so the first key noted after the last pass closed begins a new one;\n * the microtask that follows the render closes it and forgets what neither it\n * nor the pass before drew (two passes, so two views sharing a `draw` keep\n * each other's). Keys that never repeat, as successive windows of a virtual\n * list, are still forgotten.\n */\nconst remember = (memo: ItemMemo, key: PropertyKey): void => {\n if (!memo.open) {\n memo.open = true\n memo.before = memo.drawn\n memo.drawn = new Set()\n queueMicrotask(() => closePass(memo))\n }\n memo.drawn.add(key)\n}\n\nconst closePass = (memo: ItemMemo): void => {\n memo.open = false\n for (const known of new Set([...memo.lazies.keys(), ...memo.used.keys()])) {\n if (memo.drawn.has(known) || memo.before.has(known)) continue\n memo.lazies.delete(known)\n memo.used.delete(known)\n memo.given.delete(known)\n }\n}\n\nconst lazyFor = (memo: ItemMemo, key: PropertyKey): ReturnType<typeof createLazy> => {\n const known = memo.lazies.get(key)\n if (known !== undefined) return known\n const made = createLazy()\n memo.lazies.set(key, made)\n return made\n}\n\n// The drawing a missed item runs: set just before the memo is asked, so the\n// memo sees one function whose arguments are all it compares.\nlet pending: (() => Html) | undefined\nconst runPending = (..._compared: ReadonlyArray<unknown>): Html => pending!()\n\n// How many memoized drawings have started. Foldkit's lazy slot throws before\n// it calls the drawing when there is no runtime frame, so a throw with this\n// unchanged is that, and a throw after it moved is the drawing's own error.\nlet started = 0\n\n/**\n * Set by `foldkit-ssr` while it renders a page on the server, under a\n * registered symbol so it crosses bundles. Each of its passes is drawn\n * whole: a drawing kept from another pass or another request would carry\n * that render's resume markers and none of this one's bindings.\n */\nconst SERVER_RENDER = Symbol.for('foldkit-plus.serverRender')\n\n/**\n * `memoized()` under a lazy slot, or `plain()` where there is no runtime frame\n * to memoize under (a test, a server's first pass) or a server renders a page. An error from the drawing\n * itself is thrown as it is, not drawn a second time.\n */\nconst memoizedOr = (memoized: () => Html, plain: () => Html): Html => {\n if ((globalThis as Record<symbol, unknown>)[SERVER_RENDER] === true) return plain()\n const before = started\n try {\n return memoized()\n } catch (error) {\n if (started !== before) throw error\n return plain()\n }\n}\n\nconst isPlain = (value: object): boolean => {\n const prototype = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null || Array.isArray(value)\n}\n\n/**\n * Whether two evaluated contributions hold the same data: arrays and plain\n * objects (Foldkit's attributes and Messages are) by value, anything else by\n * identity, since a `Map` or a `Date` keeps its contents where `Object.keys`\n * does not see them. A handler made per render is never the same, so an item\n * a Mixin gives one is drawn again every time: correct, not cached.\n */\nconst sameData = (left: unknown, right: unknown, depth = 0): boolean => {\n if (Object.is(left, right)) return true\n if (depth > 8) return false\n if (typeof left !== 'object' || typeof right !== 'object' || left === null || right === null)\n return false\n if (!isPlain(left) || Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) return false\n const keys = Object.keys(left)\n if (keys.length !== Object.keys(right).length) return false\n return keys.every(\n key =>\n Object.hasOwn(right, key) &&\n sameData(\n (left as Record<string, unknown>)[key],\n (right as Record<string, unknown>)[key],\n depth + 1,\n ),\n )\n}\n\nconst drawItem = <Slots, Message, Args extends Readonly<Record<string, unknown>>>(\n item: SlotItem,\n draw: (slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>, args: Args) => Html,\n args: Args,\n context: {\n readonly builders: SlotBuilders<Slots, Message>\n readonly h: HtmlBuilder<Message>\n readonly given: (used: ReadonlyArray<string>) => ReadonlyArray<unknown>\n readonly first: string\n },\n): Html => {\n // Inside another item's drawing, drawn in place, and the outer one is not\n // cached: its key would read this one's Slots with the outer item.\n if (using !== undefined) {\n using.add(NESTED)\n return draw(context.builders, context.h, args)\n }\n const memo = itemMemoOf(draw)\n const key = item.id ?? item.index\n // What an item used and was given is kept only under a runtime frame, where a\n // memo can use it: a server drawing page after page keeps nothing.\n const run = (kept: boolean): Html => {\n started++\n using = new Set()\n try {\n const html = draw(context.builders, context.h, args)\n if (kept) memo.used.set(key, [...using])\n return html\n } finally {\n using = undefined\n }\n }\n const used = memo.used.get(key) ?? [context.first]\n if (used.includes(NESTED)) {\n remember(memo, key)\n return run(true)\n }\n const now = context.given(used.filter(slot => slot !== NESTED))\n const before = memo.given.get(key)\n // The same data keeps the value last compared, so the memo sees it unchanged.\n const given = before !== undefined && sameData(before, now) ? before : now\n pending = () => run(true)\n try {\n // The record is new every render; its keys and values are what stay the same.\n const compared = [draw, given, ...Object.keys(args), ...Object.values(args)]\n return memoizedOr(\n () => {\n const html = lazyFor(memo, key)(runPending, compared)\n remember(memo, key)\n memo.given.set(key, given)\n return html\n },\n // No frame (a test, a server's pages): nothing is kept, not even the empty memo.\n () => {\n memo.lazies.delete(key)\n return run(false)\n },\n )\n } finally {\n pending = undefined\n }\n}\n\n/** Build one `attrs` resolver per published slot, evaluating Mixins lazily. */\nexport const buildersFor = <Slots, Message, Input>(\n slots: Slots,\n mixins: ReadonlyArray<MixinFor<Message>>,\n context: { readonly input: Input; readonly h: HtmlBuilder<Message> },\n): SlotBuilders<Slots, Message> => {\n const builders = buildersOver(slots, [{ mixins, input: context.input }], context.h)\n mixinsOf.set(builders, mixins)\n return builders\n}\n\nconst makeView = <Slots, Input, Message>(\n name: string | undefined,\n slots: Slots,\n mixins: ReadonlyArray<MixinFor<Message>>,\n render: SlotViewRender<Slots, Input, Message>,\n): SlotView<Slots, Input, Message> => {\n const view = (input: Input, h: HtmlBuilder<Message>): Html =>\n render(input, buildersFor(slots, mixins, { input, h }), h)\n // A function's own `name` is read-only; define it rather than assigning.\n if (name !== undefined) {\n Object.defineProperty(view, 'name', { value: name, configurable: true })\n }\n return Object.assign(view, {\n slots,\n mixins,\n render,\n pipe: (...fns: ReadonlyArray<(self: unknown) => unknown>) => pipeSelf(view, fns),\n }) as unknown as SlotView<Slots, Input, Message>\n}\n\n/**\n * Defines a view over published Slots.\n *\n * `Message` has no anchor but the render callback's builder, so it is inferred\n * from an explicit `h: HtmlBuilder<Message>` annotation on that parameter.\n * Without one it resolves to `unknown`, and the first error appears later and\n * elsewhere — an invariance mismatch at `Style.attach`/`Behavior.attach` that\n * does not name the missing annotation. `forMessages<Message>()` fixes the\n * Message universe up front instead, and leaves `h` contextually typed.\n */\nexport const define = <Slots, Input, Message>(\n slots: Slots,\n render: SlotViewRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n): SlotView<Slots, Input, Message> => makeView(options?.name, slots, [], render)\n\n/**\n * Foldkit's `inertHtml` typed for a Message universe, for rendering a view\n * outside a runtime (tests, demos, static description). `inertHtml` is\n * `HtmlBuilder<never>`, and the builder is invariant in `Message`, so this is\n * the one cast: sound outside a runtime render, where no handler is ever\n * dispatched. Inside one it is the same builder every view is given, so its\n * handlers would reach the frame's `update`: use the view's own `h` there.\n */\nexport const inertBuilder = <Message>(): HtmlBuilder<Message> =>\n inertHtml as unknown as HtmlBuilder<Message>\n\n/** The `SlotView` constructors with `Message` already fixed. */\nexport interface MessageSlotView<Message> {\n readonly define: <Slots, Input>(\n slots: Slots,\n render: SlotViewRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n ) => SlotView<Slots, Input, Message>\n}\n\n/**\n * Binds the view constructors to one Message universe, so the render callback\n * no longer has to annotate `h` to pin it. `Input` is still inferred from the\n * callback's own `input` annotation.\n *\n * @example\n * ```ts\n * const Field = SlotView.forMessages<Message>().define(\n * FieldSlots,\n * (input: FieldInput, slots, h) =>\n * h.input(slots.input.attrs([h.OnInput(value => Message.ChangedValue({ value }))])),\n * )\n * ```\n */\nexport const forMessages = <Message>(): MessageSlotView<Message> => ({ define })\n\n/** A transform on any view, used by Message-free static mixins such as Style. */\nexport type SlotViewTransform = <Slots, Input, Message>(\n view: SlotView<Slots, Input, Message>,\n) => SlotView<Slots, Input, Message>\n\n/** A transform restricted to one Message universe, for Behavior mixins. */\nexport type SlotViewTransformFor<Message> = <Slots, Input>(\n view: SlotView<Slots, Input, Message>,\n) => SlotView<Slots, Input, Message>\n\n/** Attach one Mixin. Returns a new view; the original is unchanged. */\nexport function attach(mixin: StaticMixin<never> | Mixin<never>): SlotViewTransform\nexport function attach<MixinMessage>(mixin: Mixin<MixinMessage>): SlotViewTransformFor<MixinMessage>\nexport function attach(mixin: AnyMixin | Mixin<never>): any {\n return (view: SlotView<any, any, any>) =>\n makeView(view.name, view.slots, [...view.mixins, mixin], view.render)\n}\n\n/**\n * One piece of an assembled view, drawn from its own selection of the view's\n * input: the keys it names in `reads`, and nothing else. It is drawn again\n * only when one of those values changed, by identity.\n */\nexport interface Part<Slots, Input, Message> {\n readonly name: string\n readonly reads: ReadonlyArray<keyof Input>\n /** The Behaviors declared with the part, resolved against its selection. */\n readonly mixins: ReadonlyArray<MixinFor<Message>>\n // `any`: the part's own selection, which `Parts.part` typed from `reads`.\n readonly render: (\n input: any,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n ) => Html\n}\n\n/** An assembly's own drawing: the parts it places, by `draw`, and anything else around them. */\nexport type AssemblyRender<Slots, Input, Message> = (\n input: Input,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n draw: (part: Part<Slots, Input, Message>) => Html,\n) => Html\n\nexport interface Parts<Slots, Input, Message> {\n /**\n * A part reading `reads` of the input. `behaviors` are declared over that\n * selection, so they cannot read what the part does not redraw for.\n */\n readonly part: <const Reads extends ReadonlyArray<keyof Input>>(\n name: string,\n options: {\n readonly reads: Reads\n readonly behaviors?: ReadonlyArray<NamedBehavior<Slots, Pick<Input, Reads[number]>, Message>>\n },\n render: (\n input: Pick<Input, Reads[number]>,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n ) => Html,\n ) => Part<Slots, Input, Message>\n /**\n * A SlotView that draws its parts where `render` places them. Styles and\n * Behaviors attach to it as to any SlotView and reach every part's Slots.\n */\n readonly assemble: (\n render: AssemblyRender<Slots, Input, Message>,\n options?: { readonly name?: string },\n ) => SlotView<Slots, Input, Message>\n}\n\n// A part's memo. A part drawn twice in one render is the same drawing twice,\n// which Foldkit copies for the second place.\nconst lazies = new WeakMap<object, ReturnType<typeof createLazy>>()\nconst lazyOf = (part: object): ReturnType<typeof createLazy> => {\n const known = lazies.get(part)\n if (known !== undefined) return known\n const made = createLazy()\n lazies.set(part, made)\n return made\n}\n\n// Whether any of these Mixins reads the input: a function contribution may.\nconst readsInput = new WeakMap<ReadonlyArray<MixinFor<any>>, boolean>()\nconst anyDynamic = (mixins: ReadonlyArray<MixinFor<any>>): boolean => {\n const known = readsInput.get(mixins)\n if (known !== undefined) return known\n const found = mixins.some(mixin => Object.values(mixin.contributions).some(isDynamic))\n readsInput.set(mixins, found)\n return found\n}\n\n/**\n * One part, from its arguments alone, so the memo sees one function: the\n * whole input only when a view-wide Mixin reads it, and the part's read values.\n */\nconst drawPart = <Slots, Input, Message>(\n part: Part<Slots, Input, Message>,\n slots: Slots,\n h: HtmlBuilder<Message>,\n mixins: ReadonlyArray<MixinFor<Message>>,\n whole: unknown,\n ...values: Array<unknown>\n): Html => {\n started++\n const selection = Object.fromEntries(part.reads.map((key, at) => [key, values[at]]))\n const groups = [\n { mixins: part.mixins, input: selection },\n { mixins, input: whole },\n ]\n return part.render(selection, buildersOver(slots, groups, h), h)\n}\n\n/**\n * Parts over one set of Slots and one input, and the assembly that places them.\n *\n * @example\n * ```ts\n * const Parts = SlotView.parts(PanelSlots)<PanelInput, Message>()\n * const Title = Parts.part('Title', { reads: ['title'] }, (input, slots, h) =>\n * h.h2(slots.title.attrs(), [input.title]),\n * )\n * const Panel = Parts.assemble((input, slots, h, draw) => h.section(slots.root.attrs(), [draw(Title)]))\n * ```\n */\nexport const parts =\n <Slots>(slots: Slots) =>\n <Input, Message>(): Parts<Slots, Input, Message> => ({\n part: (name, options, render) => ({\n name,\n reads: options.reads,\n mixins: (options.behaviors ?? []).map(behavior => behavior.mixin),\n render,\n }),\n assemble: (render, options) =>\n makeView<Slots, Input, Message>(options?.name, slots, [], (input, builders, h) => {\n const mixins: ReadonlyArray<MixinFor<Message>> = mixinsOf.get(builders) ?? []\n // A Mixin attached to the whole view that reads the input is resolved\n // against all of it, so a part it reaches redraws whenever the input changes.\n const whole = anyDynamic(mixins) ? input : undefined\n return render(input, builders, h, part => {\n const args: Parameters<typeof drawPart<Slots, Input, Message>> = [\n part,\n slots,\n h,\n mixins,\n whole,\n ...part.reads.map(key => input[key]),\n ]\n return memoizedOr(\n () => lazyOf(part)(drawPart<Slots, Input, Message>, args),\n () => drawPart(...args),\n )\n })\n }),\n })\n\n/**\n * What a region reads: the Model paths it depends on and how its value is\n * read from the root. A `foldkit-surface` `Projection` is one, as built from\n * the application's field references (`Projection.struct({ cart:\n * App.model.cart })`), so the paths are the ones the references declare.\n */\nexport interface Reads<Root, Value> {\n /** Paths from the root, each a list of property names. */\n readonly dependencies: ReadonlyArray<ReadonlyArray<string>>\n readonly read: (root: Root) => Value\n}\n\n/** A region of a SlotView's drawing, drawn again only when what it reads changed. */\nexport type Region<Root, Slots, Message> = (\n root: Root,\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n) => Html\n\n/**\n * A region: part of a SlotView's drawing that is given only what `reads`\n * reads, and drawn again only when that changed. While every path `reads`\n * depends on holds the value it held, the region does not read at all and\n * Foldkit reuses its last drawing without diffing it; when one changed and\n * the read gives the same fields as before, it is reused too. What reads no\n * path of its own (a Remote read, alone or in a `Projection.struct`) is read\n * on every render, and the region drawn again when that gives other fields.\n * Like a Slot's `lazy` item, it is drawn again when a Mixin gives the Slots\n * it used something different, and drawn afresh where there is no runtime\n * frame.\n *\n * `draw` reads only its value, so the region cannot read what it is not\n * drawn again for. A region drawn inside another region or item is drawn in\n * place, and the outer one every time.\n *\n * @example\n * ```ts\n * const Header = SlotView.region(\n * Projection.struct({ cart: App.model.cart }),\n * ({ cart }, slots: SlotView.SlotBuilders<typeof Page.slots, Message>, h: HtmlBuilder<Message>) =>\n * h.header(slots.header.attrs(), [`${cart.length} in the cart`]),\n * )\n * // In the page's render: Header(model, slots, h)\n * ```\n */\nexport const region = <Root, Value, Slots, Message>(\n reads: Reads<Root, Value>,\n draw: (value: Value, slots: SlotBuilders<Slots, Message>, h: HtmlBuilder<Message>) => Html,\n): Region<Root, Slots, Message> => {\n // Worked out again by the same rule a derivation is, and drawn again by the\n // lazy slot only when that gives a new value.\n const derived = Projection.derive([reads], reads.read)\n const drawRegion = (\n slots: SlotBuilders<Slots, Message>,\n h: HtmlBuilder<Message>,\n args: { readonly value: Value },\n ): Html => draw(args.value, slots, h)\n return (root, slots, h) => {\n const builder = Object.values(slots)[0] as SlotBuilder<Message, Slots> | undefined\n if (builder === undefined) throw new Error('SlotView.region: the view publishes no Slots')\n return builder.lazy({ index: 0 }, drawRegion, { value: derived.read(root) })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AA8EA,MAAM,2BAAW,IAAI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AAQ,aAAa,CAAC,EAAA,CAAG,KAAI,aAAY,SAAS,KAAK;EAChE;CACF;CACA,WAAW,QAAQ,YACjB,SAAgC,SAAS,MAAM,OAAO,CAAC,IAAI,OAAO,UAAU,MAAM;EAChF,MAAM,SAA2C,SAAS,IAAI,QAAQ,KAAK,CAAC;EAG5E,MAAM,QAAQ,WAAW,MAAM,IAAI,QAAQ,KAAA;EAC3C,OAAO,OAAO,OAAO,UAAU,IAAG,SAAQ;GACxC,MAAM,OAA2D;IAC/D;IACA;IACA;IACA;IACA;IACA,GAAG,KAAK,MAAM,KAAI,QAAO,MAAM,IAAI;GACrC;GACA,OAAO,iBACC,OAAO,IAAI,CAAC,CAAC,UAAiC,IAAI,SAClD,SAAS,GAAG,IAAI,CACxB;EACF,CAAC;CACH,CAAC;AACL;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CF,MAAa,UACX,OACA,SACiC;CAGjC,MAAM,UAAU,WAAW,OAAO,CAAC,KAAK,GAAG,MAAM,IAAI;CACrD,MAAM,cACJ,OACA,GACA,SACS,KAAK,KAAK,OAAO,OAAO,CAAC;CACpC,QAAQ,MAAM,OAAO,MAAM;EACzB,MAAM,UAAU,OAAO,OAAO,KAAK,CAAC,CAAC;EACrC,IAAI,YAAY,KAAA,GAAW,MAAM,IAAI,MAAM,8CAA8C;EACzF,OAAO,QAAQ,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,OAAO,QAAQ,KAAK,IAAI,EAAE,CAAC;CAC7E;AACF"}
|
package/dist/style.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Mixin } from "./mixin.js";
|
|
|
5
5
|
import * as SlotView from "./slotView.js";
|
|
6
6
|
import { AttributeName, EventName, HiddenOf, MakeOptions, RequirementName, SlotCapability, UnnamedSlot } from "./slot.js";
|
|
7
7
|
import { Contract } from "./slots.js";
|
|
8
|
-
import { usedIn } from "./inject.js";
|
|
8
|
+
import { complete, usedIn } from "./inject.js";
|
|
9
9
|
import { SlotItem } from "./slotItem.js";
|
|
10
10
|
/** A hidden slot is internal: it is neither styleable nor behavior-targetable. */
|
|
11
11
|
export type StylePieces<Slots> = PublicPieces<Slots, Piece$1>;
|
|
@@ -219,6 +219,7 @@ export declare const Style: {
|
|
|
219
219
|
readonly stylesheet: typeof stylesheet;
|
|
220
220
|
readonly install: typeof install;
|
|
221
221
|
readonly usedIn: typeof usedIn;
|
|
222
|
+
readonly complete: typeof complete;
|
|
222
223
|
};
|
|
223
224
|
export type { Piece, StyleCondition, StyleValue };
|
|
224
225
|
//# sourceMappingURL=style.d.ts.map
|
package/dist/style.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as SlotModule from "./slot.js";
|
|
|
7
7
|
import { define } from "./slots.js";
|
|
8
8
|
import { declaredNames, isUnordered, layerOf, topLevelBlocks } from "./cssBlocks.js";
|
|
9
9
|
import * as Rules from "./styleRules.js";
|
|
10
|
-
import { register, usedIn } from "./inject.js";
|
|
10
|
+
import { complete, register, usedIn } from "./inject.js";
|
|
11
11
|
import { own } from "./record.js";
|
|
12
12
|
// src/style.ts
|
|
13
13
|
/**
|
|
@@ -414,7 +414,8 @@ const Style = {
|
|
|
414
414
|
recipeFor,
|
|
415
415
|
stylesheet,
|
|
416
416
|
install,
|
|
417
|
-
usedIn
|
|
417
|
+
usedIn,
|
|
418
|
+
complete
|
|
418
419
|
};
|
|
419
420
|
export { SlotPieceTypeId, Style, attach, forCapability, forSlots, install, perItem, recipe, recipeFor, slot, slots, stagger, stylesheet, when, whenInput };
|
|
420
421
|
|
package/dist/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","names":["Mixin","defineSlots"],"sources":["../src/style.ts"],"sourcesContent":["/**\n * `Style` is pure data: class tokens and inline declarations that compile to a\n * `SlotContribution`. It never touches the DOM and never mutates state.\n * `forSlots` validates piece keys against the published contract at definition\n * time, so a typo fails loudly. The builders themselves live in\n * `styleValue.ts`; this module joins them to slots.\n */\nimport * as Capability from './capability.js'\nimport { declaredNames, isUnordered, layerOf, topLevelBlocks } from './cssBlocks.js'\nimport type { InputContribution, SlotContribution } from './contribution.js'\nimport { DiagnosticError } from './diagnostics.js'\nimport { own } from './record.js'\nimport * as Mixin from './mixin.js'\nimport type { Mixin as MixinValue } from './mixin.js'\nimport * as SlotModule from './slot.js'\nimport type {\n Any as AnySlot,\n AttributeName,\n EventName,\n HiddenOf,\n MakeOptions,\n RequirementName,\n SlotCapability,\n UnnamedSlot,\n} from './slot.js'\nimport { define as defineSlots, type Contract as SlotsContract } from './slots.js'\nimport type { Placement } from './layers.js'\nimport type { SlotItem } from './slotItem.js'\nimport * as SlotView from './slotView.js'\nimport { register, usedIn } from './inject.js'\nimport * as Rules from './styleRules.js'\nimport {\n allowDiscrete,\n classPiece,\n compose,\n at,\n container,\n empty,\n enter,\n global,\n grid,\n inline,\n keyframes,\n media,\n nest,\n pseudo,\n responsive,\n self,\n states,\n supports,\n vars,\n viewTransitionName,\n make,\n toStyleValue,\n type Piece,\n type StyleValue,\n} from './styleValue.js'\n\nexport type { Piece, StyleCondition, StyleValue } from './styleValue.js'\n\n/** A hidden slot is internal: it is neither styleable nor behavior-targetable. */\nexport type StylePieces<Slots> = PublicPieces<Slots, Piece>\n\ntype PublicPieces<Slots, Value> = {\n readonly [K in keyof Slots as HiddenOf<Slots[K]> extends true ? never : K]?: Value\n}\n\n/** `StylePieces` with every piece a `StyleValue`, as a recipe or a `NamedStyle` gives them. */\nexport type StyleValues<Slots> = PublicPieces<Slots, StyleValue>\n\nexport interface NamedStyle<Slots> {\n readonly name?: string\n /** Each piece as compiled, placed in the `layer` when one was given. */\n readonly pieces: StyleValues<Slots>\n readonly mixin: MixinValue<never>\n /** Concatenated rule CSS for every static piece. */\n readonly css: string\n /** Concatenated class-independent CSS (keyframes, layers, global rules). */\n readonly globalCss: string\n /** One entry per generated class, for a deduplicating stylesheet. */\n readonly rules: ReadonlyArray<{ readonly className: string; readonly css: string }>\n /** Class-independent rule chunks, for a deduplicating stylesheet. */\n readonly globalRules: ReadonlyArray<string>\n}\n\nexport interface StyleOptions {\n readonly name?: string\n /**\n * The layer every piece is placed in before compiling, e.g.\n * `Layers.standard.layer('app')`. A rule already in a layer keeps it.\n */\n readonly layer?: Placement\n}\n\n/** A boolean known at authoring time. */\nexport const when = (condition: boolean, piece: Piece): StyleValue =>\n condition ? toStyleValue(piece) : empty\n\n/** A condition read from the view input at render time. The piece applies when\n * `predicate` returns true for the input the view was rendered with. */\nexport const whenInput = <Input>(predicate: (input: Input) => boolean, piece: Piece): StyleValue =>\n make({\n conditions: Object.freeze([\n { predicate: (input: unknown) => predicate(input as Input), piece: toStyleValue(piece) },\n ]),\n })\n\n/**\n * A piece computed from the item the slot is rendered for, when the view\n * passes one to `attrs(base, item)`; nothing for a slot rendered once.\n */\nexport const perItem = (piece: (item: SlotItem) => Piece): StyleValue =>\n make({\n items: Object.freeze([\n (item: SlotItem | undefined) => (item === undefined ? empty : toStyleValue(piece(item))),\n ]),\n })\n\n/**\n * A per-item delay for an entrance: writes `--fk-index` and\n * `transition-delay: calc(var(--fk-index) * <step>)` (or `animation-delay`),\n * so a list staggers with no timer. Pass the item to `attrs` for each row.\n */\nexport const stagger = (options: {\n readonly stepMs: number\n readonly property?: 'transitionDelay' | 'animationDelay'\n}): StyleValue =>\n compose(\n // The delay is a rule; only the index is the item's own, inline.\n self({\n [options.property ?? 'transitionDelay']: `calc(var(--fk-index) * ${options.stepMs}ms)`,\n }),\n perItem(item => inline({ '--fk-index': String(item.index) })),\n )\n\n/** Fold every active condition and item piece (recursively) into a plain style. */\nconst resolveStyle = (style: StyleValue, input: unknown, item?: SlotItem): StyleValue => {\n const active = [\n ...(style.conditions ?? [])\n .filter(condition => condition.predicate(input))\n .map(condition => condition.piece),\n ...(style.items ?? []).map(piece => piece(item)),\n ].map(piece => resolveStyle(piece, input, item))\n return make({\n classes: Object.freeze([...style.classes, ...active.flatMap(piece => piece.classes)]),\n style: Object.freeze(\n Object.assign(Object.create(null), style.style, ...active.map(piece => piece.style)),\n ),\n })\n}\n\ninterface CompiledStyle {\n readonly classes: ReadonlyArray<string>\n readonly style: Readonly<Record<string, string>>\n readonly css?: string\n readonly ruleClass?: string\n readonly globalRules?: ReadonlyArray<string>\n /** Every class the tree compiled to, with its CSS, static or conditional. */\n readonly compiled: ReadonlyArray<{ readonly className: string; readonly css: string }>\n}\n\n/** Global CSS is emitted whether or not its condition is active. */\nconst collectGlobalCss = (style: StyleValue): ReadonlyArray<string> => [\n ...(style.globalCss ?? []),\n ...(style.conditions ?? []).flatMap(condition => collectGlobalCss(condition.piece)),\n]\n\n/**\n * Compiles every rule-bearing node in the tree to its class: the node's\n * classes gain the generated one, and the CSS is collected. A conditional\n * piece's rules are compiled the same way, so the class is static and only\n * its presence follows the input.\n */\nconst compileTree = (\n style: StyleValue,\n globalCss: string,\n collected: Array<{ readonly className: string; readonly css: string }>,\n): StyleValue => {\n const rules = style.rules ?? []\n const generated = rules.length === 0 ? undefined : Rules.className(rules)\n if (generated !== undefined) {\n const css = Rules.css(generated, rules)\n register(generated, css, globalCss)\n collected.push({ className: generated, css })\n }\n const conditions = (style.conditions ?? []).map(condition => ({\n predicate: condition.predicate,\n piece: compileTree(condition.piece, globalCss, collected),\n }))\n return Object.freeze({\n ...style,\n classes: generated === undefined ? style.classes : Object.freeze([...style.classes, generated]),\n ...(conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) }),\n })\n}\n\n/** A style with every rule in it compiled: the tree with classes, plus the CSS. */\nconst compileStyle = (style: StyleValue): CompiledStyle & { readonly tree: StyleValue } => {\n const collected: Array<{ readonly className: string; readonly css: string }> = []\n const globalRules = collectGlobalCss(style)\n // Every class the Style compiles to carries its globals, so a server that\n // finds any one of them in markup writes what the Style needs.\n const tree = compileTree(style, globalRules.join(''), collected)\n const first = collected[0]\n return {\n tree,\n classes: tree.classes,\n style: tree.style,\n ...(first === undefined\n ? {}\n : { css: collected.map(entry => entry.css).join(''), ruleClass: first.className }),\n ...(globalRules.length === 0 ? {} : { globalRules }),\n compiled: collected,\n }\n}\n\n/**\n * A static style stays static data; a style with input conditions compiles to a\n * message-free `InputContribution`, so it still attaches to any view.\n */\nconst contributionFrom = (\n style: StyleValue,\n compiled: CompiledStyle & { readonly tree: StyleValue },\n): SlotContribution<never> => {\n const globalCss = compiled.globalRules?.join('')\n const attributes = {\n classes: compiled.classes,\n style: compiled.style,\n ...(compiled.css === undefined ? {} : { css: compiled.css }),\n ...(globalCss === undefined ? {} : { globalCss }),\n }\n if ((style.conditions ?? []).length === 0 && (style.items ?? []).length === 0) {\n return Object.freeze(attributes)\n }\n const contribution: InputContribution<never> = context => {\n const resolved = resolveStyle(compiled.tree, context.input, context.item)\n return Object.freeze({\n classes: resolved.classes,\n style: resolved.style,\n ...(compiled.css === undefined ? {} : { css: compiled.css }),\n ...(globalCss === undefined ? {} : { globalCss }),\n })\n }\n return contribution\n}\n\nexport const forSlots =\n <Slots>(slots: Slots) =>\n (pieces: StylePieces<Slots>, options?: StyleOptions): NamedStyle<Slots> => {\n const known = slots as unknown as Record<string, unknown>\n const contributions: Record<string, SlotContribution<never>> = Object.create(null)\n // What was compiled, so `pieces` recomposed elsewhere keeps the layer too.\n const compiledPieces: Record<string, StyleValue> = Object.create(null)\n const rules: Array<{ className: string; css: string }> = []\n const globalRules: Array<string> = []\n let css = ''\n let globalCss = ''\n for (const [key, piece] of Object.entries(pieces as Record<string, Piece | undefined>)) {\n if (!Object.hasOwn(known, key)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:unknown-slot',\n severity: 'error',\n message: `Style targets unknown slot \"${key}\"`,\n slot: key,\n })\n }\n if ((known[key] as { readonly hidden?: boolean } | undefined)?.hidden === true) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:hidden-slot',\n severity: 'error',\n message: `Style targets hidden slot \"${key}\"`,\n slot: key,\n })\n }\n if (piece !== undefined) {\n const value = toStyleValue(piece)\n const placed = options?.layer === undefined ? value : options.layer.place(value)\n compiledPieces[key] = placed\n // Rule and global CSS are static even when the contribution is deferred,\n // so compile once, then build the contribution and gather the CSS.\n const compiled = compileStyle(placed)\n contributions[key] = contributionFrom(placed, compiled)\n for (const entry of compiled.compiled) {\n rules.push(entry)\n css += entry.css\n }\n if (compiled.globalRules !== undefined) {\n globalRules.push(...compiled.globalRules)\n globalCss += compiled.globalRules.join('')\n }\n }\n }\n return Object.freeze({\n ...(options?.name === undefined ? {} : { name: options.name }),\n pieces: compiledPieces,\n mixin: Mixin.dynamic<never>(options?.name ?? 'Style', contributions),\n css,\n globalCss,\n rules: Object.freeze(rules),\n globalRules: Object.freeze(globalRules),\n })\n }\n\nexport interface StylesheetSource {\n readonly rules: ReadonlyArray<{ readonly className: string; readonly css: string }>\n readonly globalRules: ReadonlyArray<string>\n}\n\nconst isStylesheetSource = (value: StyleValue | StylesheetSource): value is StylesheetSource =>\n 'globalRules' in value\n\nconst LAYER_STATEMENT = /^@layer [^{}]+;$/\n\nconst sourceOf = (style: StyleValue): StylesheetSource => {\n const compiled = compileStyle(style)\n return { rules: compiled.compiled, globalRules: compiled.globalRules ?? [] }\n}\n\n/**\n * An unlayered rule beats every layer, `app` included, so once a sheet\n * declares an order, a rule outside it, or in a layer the order does not\n * name (which would sort after the last one), is a mistake. Keyframes, font\n * faces, and registered properties are not ordered by the cascade and pass.\n */\nconst refuseUnlayered = (\n css: string,\n names: ReadonlyArray<string>,\n where: string,\n className?: string,\n): void => {\n for (const block of topLevelBlocks(css)) {\n if (isUnordered(block)) continue\n const layer = layerOf(block)\n if (layer !== undefined && names.includes(layer)) continue\n throw new DiagnosticError({\n source: 'style',\n code: 'style:unlayered-rule',\n severity: 'error',\n message:\n layer === undefined\n ? `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, …)`\n : `${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, …)`,\n details: {\n ...(className === undefined ? {} : { className }),\n ...(layer === undefined ? {} : { layer }),\n },\n })\n }\n}\n\n/**\n * One `<style>` block: the `@layer …;` statement first (one order per\n * sheet), then the other global chunks, then the scoped classes, each\n * deduplicated with the first seen winning. A bare `StyleValue` (a theme\n * root, a layered reset, a layout) compiles like a piece of a `NamedStyle`.\n * With an order declared, every rule must sit in one of its layers\n * (`style:unlayered-rule`); without one, unlayered rules are allowed.\n */\nexport const stylesheet = (...styles: ReadonlyArray<StyleValue | StylesheetSource>): string => {\n const scoped = new Map<string, string>()\n const global = new Set<string>()\n let order: string | undefined\n for (const style of styles) {\n const source = isStylesheetSource(style) ? style : sourceOf(style)\n for (const rule of source.rules) {\n if (!scoped.has(rule.className)) scoped.set(rule.className, rule.css)\n }\n for (const rule of source.globalRules) {\n if (!LAYER_STATEMENT.test(rule)) {\n global.add(rule)\n } else if (order === undefined) {\n order = rule\n } else if (order !== rule) {\n throw new DiagnosticError({\n source: 'style',\n code: 'style:conflicting-layer-order',\n severity: 'error',\n message: `Style.stylesheet was given two layer orders: \"${order}\" and \"${rule}\"`,\n })\n }\n }\n }\n if (order !== undefined) {\n const names = declaredNames(order)\n for (const chunk of global) refuseUnlayered(chunk, names, `global CSS \"${chunk.slice(0, 60)}\"`)\n for (const [className, css] of scoped) {\n refuseUnlayered(css, names, `class \"${className}\"`, className)\n }\n }\n return [...(order === undefined ? [] : [order]), ...global, ...scoped.values()].join('')\n}\n\nexport const attach =\n <Slots>(style: NamedStyle<Slots>) =>\n <ViewSlots, Input, Message>(\n view: SlotView.SlotView<ViewSlots, Input, Message>,\n ): SlotView.SlotView<ViewSlots, Input, Message> =>\n SlotView.attach(style.mixin)(view)\n\nexport type RecipeVariantDef = Readonly<Record<string, StyleValue>>\n\n/** A combination style applied when every `when` entry matches the selection. */\nexport interface RecipeCompound<Variants extends Readonly<Record<string, RecipeVariantDef>>> {\n readonly when: Partial<{ readonly [K in keyof Variants]: keyof Variants[K] & string }>\n readonly style: StyleValue\n}\n\nexport interface RecipeDef<Variants extends Readonly<Record<string, RecipeVariantDef>>> {\n readonly base?: StyleValue\n /** Absent for a recipe that is only its base. */\n readonly variants?: Variants\n readonly defaults?: { readonly [K in keyof Variants]?: keyof Variants[K] & string }\n readonly compound?: ReadonlyArray<RecipeCompound<Variants>>\n}\n\nexport type AnyRecipeDef = RecipeDef<Record<string, RecipeVariantDef>>\n\n/**\n * The selection of a recipe with no axes. An empty mapped type is `{}`, and\n * TypeScript checks no excess keys against `{}`, so `{ tone: 'quiet' }`\n * compiled and did nothing.\n */\ntype NoAxes = { readonly [key: string]: never }\n\nexport type RecipeSelection<D extends AnyRecipeDef> = [keyof NonNullable<D['variants']>] extends [\n never,\n]\n ? NoAxes\n : {\n readonly [K in keyof NonNullable<D['variants']>]?: keyof NonNullable<D['variants']>[K] &\n string\n }\n\n/** A recipe is just Style data: base, one piece per selected variant, then any\n * matching compound. `compound.when` is keyed by the recipe's variants, so a\n * typo is a compile error rather than a silently dead combination. */\nexport const recipe =\n <Variants extends Readonly<Record<string, RecipeVariantDef>> = {}>(def: RecipeDef<Variants>) =>\n (selection: RecipeSelection<RecipeDef<Variants>>): StyleValue => {\n const pieces: Array<StyleValue> = []\n if (def.base !== undefined) pieces.push(def.base)\n const effective: Record<string, string> = Object.create(null)\n for (const [variant, values] of Object.entries(def.variants ?? {})) {\n const chosen =\n own(selection as Record<string, string | undefined>, variant) ??\n (def.defaults as Record<string, string | undefined> | undefined)?.[variant]\n if (chosen === undefined) continue\n effective[variant] = chosen\n const piece = (values as Record<string, StyleValue>)[chosen]\n if (piece !== undefined) pieces.push(piece)\n }\n for (const compound of def.compound ?? []) {\n if (Object.entries(compound.when).every(([variant, value]) => effective[variant] === value)) {\n pieces.push(compound.style)\n }\n }\n return compose(...pieces)\n }\n\nexport type SlotRecipeVariants<Slots> = Readonly<\n Record<string, Readonly<Record<string, StylePieces<Slots>>>>\n>\n\nexport interface SlotRecipeDef<Slots, Variants extends SlotRecipeVariants<Slots>> {\n readonly base?: StylePieces<Slots>\n /** Absent for a recipe that is only its base. */\n readonly variants?: Variants\n readonly defaults?: { readonly [K in keyof Variants]?: keyof Variants[K] & string }\n readonly compound?: ReadonlyArray<{\n readonly when: Partial<{ readonly [K in keyof Variants]: keyof Variants[K] & string }>\n readonly style: StylePieces<Slots>\n }>\n}\n\n/** A selection; `null` unsets an axis that has a default. */\nexport type SlotRecipeSelection<Variants> = [keyof Variants] extends [never]\n ? NoAxes\n : { readonly [K in keyof Variants]?: (keyof Variants[K] & string) | null }\n\nexport interface SlotRecipePatch<Slots, Variants extends SlotRecipeVariants<Slots>> {\n readonly base?: StylePieces<Slots>\n readonly variants?: {\n readonly [K in keyof Variants]?: { readonly [V in keyof Variants[K]]?: StylePieces<Slots> }\n }\n readonly defaults?: SlotRecipeDef<Slots, Variants>['defaults']\n readonly compound?: SlotRecipeDef<Slots, Variants>['compound']\n}\n\nexport interface SlotRecipe<Slots, Variants extends SlotRecipeVariants<Slots>> {\n (selection?: SlotRecipeSelection<Variants>): StyleValues<Slots>\n /** The definition, with `variants` present (`{}` when none was given). */\n readonly def: SlotRecipeDef<Slots, Variants> & { readonly variants: Variants }\n /**\n * The same recipe with `patch` merged in: base pieces compose per slot, a\n * variant's pieces compose over the base recipe's, compounds append,\n * defaults override. A slot the contract lacks is refused at once.\n */\n readonly extend: (patch: SlotRecipePatch<Slots, Variants>) => SlotRecipe<Slots, Variants>\n}\n\nconst mergePieces = <Slots>(\n left: StylePieces<Slots> | undefined,\n right: StylePieces<Slots> | undefined,\n): StyleValues<Slots> => {\n const merged: Record<string, StyleValue> = Object.create(null)\n for (const source of [left, right]) {\n for (const [slot, piece] of Object.entries((source ?? {}) as Record<string, Piece>)) {\n const existing = merged[slot]\n merged[slot] = existing === undefined ? toStyleValue(piece) : compose(existing, piece)\n }\n }\n return merged as StyleValues<Slots>\n}\n\nconst assertKnownSlots = <Slots>(\n slots: Slots,\n pieces: StylePieces<Slots> | undefined,\n where: string,\n): void => {\n const known = slots as unknown as Record<string, unknown>\n for (const slot of Object.keys((pieces ?? {}) as Record<string, unknown>)) {\n if (!Object.hasOwn(known, slot)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:unknown-slot',\n severity: 'error',\n message: `Recipe ${where} targets unknown slot \"${slot}\"`,\n slot,\n })\n }\n }\n}\n\n/**\n * A recipe over every slot of a contract: `base` pieces per slot, `variants`\n * per axis and value, `defaults`, and `compound` matches. The result of a\n * selection is a `StylePieces` for `Style.forSlots`. A design system ships\n * the recipe; an application adjusts it with `extend` instead of forking.\n */\nexport const recipeFor =\n <Slots>(slots: Slots) =>\n <Variants extends SlotRecipeVariants<Slots> = {}>(\n def: SlotRecipeDef<Slots, Variants>,\n ): SlotRecipe<Slots, Variants> => {\n // Absent variants are none; `{}` is what the default type argument names.\n const full = { ...def, variants: def.variants ?? ({} as Variants) }\n const axes: SlotRecipeVariants<Slots> = full.variants\n assertKnownSlots(slots, def.base, 'base')\n for (const [axis, values] of Object.entries(axes)) {\n for (const [value, pieces] of Object.entries(values)) {\n assertKnownSlots(slots, pieces as StylePieces<Slots>, `variants.${axis}.${value}`)\n }\n }\n for (const entry of def.compound ?? []) assertKnownSlots(slots, entry.style, 'compound')\n const select = (selection: SlotRecipeSelection<Variants> = {}): StyleValues<Slots> => {\n let pieces = mergePieces(def.base, undefined)\n const effective: Record<string, string> = Object.create(null)\n for (const [axis, values] of Object.entries(axes)) {\n const picked = own(selection as Record<string, string | null | undefined>, axis)\n const chosen =\n picked === null\n ? undefined\n : (picked ?? (def.defaults as Record<string, string | undefined> | undefined)?.[axis])\n if (chosen === undefined) continue\n effective[axis] = chosen\n const piece = (values as Record<string, StylePieces<Slots>>)[chosen]\n if (piece !== undefined) pieces = mergePieces(pieces, piece)\n }\n for (const entry of def.compound ?? []) {\n if (Object.entries(entry.when).every(([axis, value]) => effective[axis] === value)) {\n pieces = mergePieces(pieces, entry.style)\n }\n }\n return pieces\n }\n const extend = (patch: SlotRecipePatch<Slots, Variants>): SlotRecipe<Slots, Variants> => {\n const variants: Record<string, Record<string, StylePieces<Slots>>> = Object.create(null)\n for (const [axis, values] of Object.entries(axes)) {\n variants[axis] = { ...(values as Record<string, StylePieces<Slots>>) }\n }\n for (const [axis, values] of Object.entries(patch.variants ?? {})) {\n const target = variants[axis] ?? {}\n for (const [value, pieces] of Object.entries(\n (values ?? {}) as Record<string, StylePieces<Slots>>,\n )) {\n target[value] = mergePieces(target[value], pieces)\n }\n variants[axis] = target\n }\n return recipeFor(slots)({\n base: mergePieces(def.base, patch.base),\n variants: variants as unknown as Variants,\n defaults: { ...def.defaults, ...patch.defaults } as NonNullable<\n SlotRecipeDef<Slots, Variants>['defaults']\n >,\n compound: [...(def.compound ?? []), ...(patch.compound ?? [])],\n })\n }\n return Object.assign(select, { def: full, extend })\n }\n\n/**\n * One piece for every public slot whose capability satisfies `capability`:\n * a focus ring for every `Focusable`, a disabled treatment for every\n * `Interactive`, in one line.\n */\nexport const forCapability =\n <Slots>(slots: Slots) =>\n (\n capability: string | Capability.Any,\n piece: Piece,\n options?: StyleOptions,\n ): NamedStyle<Slots> => {\n const source = slots as unknown as Record<string, AnySlot>\n const value = toStyleValue(piece)\n const pieces: Record<string, StyleValue> = Object.create(null)\n for (const [name, slot] of Object.entries(source)) {\n if (slot.hidden) continue\n if (Capability.extendsCapability(slot.capability, capability)) pieces[name] = value\n }\n return forSlots(slots)(pieces as StylePieces<Slots>, options)\n }\n\nexport const SlotPieceTypeId: unique symbol = Symbol.for('foldkit-mixins/SlotPiece')\n\n/** A key of `Style.slots` that declares more than a Container: its slot, and its piece. */\nexport interface SlotPiece<S = UnnamedSlot> {\n readonly [SlotPieceTypeId]: S\n readonly piece: Piece\n}\n\nconst isSlotPiece = (value: unknown): value is SlotPiece =>\n typeof value === 'object' && value !== null && Object.hasOwn(value, SlotPieceTypeId)\n\n/** What `Style.slots` declares for a key given only a piece. */\nexport type ContainerSlot = UnnamedSlot<\n typeof Capability.Container,\n readonly [],\n readonly [],\n readonly [],\n false\n>\n\nconst containerSlot: ContainerSlot = SlotModule.make({ capability: Capability.Container })\n\n/**\n * A key of `Style.slots` with slot options: `form: Style.slot({ events:\n * [Event.Submit] }, piece)`. The capability defaults to `Container`; a slot\n * declared here is the application's own, so it cannot be hidden.\n */\nexport const slot = <\n const C extends SlotCapability = typeof Capability.Container,\n const Events extends ReadonlyArray<EventName> = readonly [],\n const Attributes extends ReadonlyArray<AttributeName> = readonly [],\n const Requirements extends ReadonlyArray<RequirementName> = readonly [],\n>(\n options: Pick<\n MakeOptions<C, Events, Attributes, Requirements, false>,\n 'capability' | 'events' | 'attributes' | 'requirements' | 'protected'\n >,\n piece: Piece = empty,\n): SlotPiece<UnnamedSlot<C, Events, Attributes, Requirements, false>> =>\n Object.freeze({\n [SlotPieceTypeId]: SlotModule.make({\n capability: Capability.Container,\n ...options,\n }) as UnnamedSlot<C, Events, Attributes, Requirements, false>,\n piece,\n })\n\n/** What `Style.slots` takes: per key a piece, or a `Style.slot(options, piece)`. */\nexport type DeclaredPieces<S> = { readonly [K in keyof S]: Piece | SlotPiece<S[K]> }\n\n/** The contract `Style.slots` declares: a Container for a piece, the given slot for a `Style.slot`. */\nexport type DeclaredSlots<S> = SlotsContract<{\n readonly [K in keyof S]: S[K] extends UnnamedSlot ? S[K] : ContainerSlot\n}>\n\n/** A contract and the style that declared it. */\nexport interface Declared<S> {\n readonly slots: DeclaredSlots<S>\n readonly style: NamedStyle<DeclaredSlots<S>>\n}\n\n/**\n * An application's own Slots declared by their style: each key is a\n * `Container` slot with that piece, or a `Style.slot(options, piece)`.\n * `slots` is the contract a `SlotView` draws and `style` the `NamedStyle`\n * it attaches. To style a contract someone else published (`ButtonSlots`),\n * use `forSlots` instead.\n */\nexport const slots = <S>(pieces: DeclaredPieces<S>, options?: StyleOptions): Declared<S> => {\n const entries = Object.entries(pieces as Record<string, Piece | SlotPiece>)\n const contract = defineSlots(\n Object.fromEntries(\n entries.map(([key, value]) => [\n key,\n isSlotPiece(value) ? value[SlotPieceTypeId] : containerSlot,\n ]),\n ),\n ) as unknown as DeclaredSlots<S>\n const style = forSlots(contract)(\n Object.fromEntries(\n entries.map(([key, value]) => [key, isSlotPiece(value) ? value.piece : value]),\n ) as StylePieces<DeclaredSlots<S>>,\n options,\n )\n return Object.freeze({ slots: contract, style })\n}\n\n/**\n * Puts `css` (typically `Style.stylesheet(…)`) in the page's head as one\n * `<style>`, unless a `<style>` there already holds exactly this text (a page\n * rendered with it on the server, a second call). Returns that element, for\n * a caller that removes it. Browser only: throws where there is no `document`.\n */\nexport const install = (css: string): HTMLStyleElement => {\n if (typeof document === 'undefined') {\n throw new Error(\n 'Style.install needs a browser document; a server writes the sheet into the page',\n )\n }\n const present = Array.from(document.head.querySelectorAll('style')).find(\n element => element.textContent === css,\n )\n if (present !== undefined) return present\n const element = document.createElement('style')\n element.textContent = css\n document.head.append(element)\n return element\n}\n\nexport const Style = {\n class: classPiece,\n inline,\n compose,\n when,\n whenInput,\n pseudo,\n self,\n media,\n supports,\n at,\n container,\n nest,\n states,\n responsive,\n vars,\n enter,\n allowDiscrete,\n viewTransitionName,\n grid,\n keyframes,\n global,\n empty,\n perItem,\n stagger,\n forSlots,\n forCapability,\n slot,\n slots,\n attach,\n recipe,\n recipeFor,\n stylesheet,\n install,\n usedIn,\n} as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+FA,MAAa,QAAQ,WAAoB,UACvC,YAAY,aAAa,KAAK,IAAI;;;AAIpC,MAAa,aAAoB,WAAsC,UACrE,KAAK,EACH,YAAY,OAAO,OAAO,CACxB;CAAE,YAAY,UAAmB,UAAU,KAAc;CAAG,OAAO,aAAa,KAAK;AAAE,CACzF,CAAC,EACH,CAAC;;;;;AAMH,MAAa,WAAW,UACtB,KAAK,EACH,OAAO,OAAO,OAAO,EAClB,SAAgC,SAAS,KAAA,IAAY,QAAQ,aAAa,MAAM,IAAI,CAAC,CACxF,CAAC,EACH,CAAC;;;;;;AAOH,MAAa,WAAW,YAItB,QAEE,KAAK,GACF,QAAQ,YAA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AAiB,OAAO,CAAC,CAAC,CAAC,MAClE,YAAW,QAAQ,gBAAgB,GACrC;CACA,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,MAAM,UAAU,SAAS,cAAc,OAAO;CAC9C,QAAQ,cAAc;CACtB,SAAS,KAAK,OAAO,OAAO;CAC5B,OAAO;AACT;AAEA,MAAa,QAAQ;CACnB,OAAO;CACP;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"style.js","names":["Mixin","defineSlots"],"sources":["../src/style.ts"],"sourcesContent":["/**\n * `Style` is pure data: class tokens and inline declarations that compile to a\n * `SlotContribution`. It never touches the DOM and never mutates state.\n * `forSlots` validates piece keys against the published contract at definition\n * time, so a typo fails loudly. The builders themselves live in\n * `styleValue.ts`; this module joins them to slots.\n */\nimport * as Capability from './capability.js'\nimport { declaredNames, isUnordered, layerOf, topLevelBlocks } from './cssBlocks.js'\nimport type { InputContribution, SlotContribution } from './contribution.js'\nimport { DiagnosticError } from './diagnostics.js'\nimport { own } from './record.js'\nimport * as Mixin from './mixin.js'\nimport type { Mixin as MixinValue } from './mixin.js'\nimport * as SlotModule from './slot.js'\nimport type {\n Any as AnySlot,\n AttributeName,\n EventName,\n HiddenOf,\n MakeOptions,\n RequirementName,\n SlotCapability,\n UnnamedSlot,\n} from './slot.js'\nimport { define as defineSlots, type Contract as SlotsContract } from './slots.js'\nimport type { Placement } from './layers.js'\nimport type { SlotItem } from './slotItem.js'\nimport * as SlotView from './slotView.js'\nimport { complete, register, usedIn } from './inject.js'\nimport * as Rules from './styleRules.js'\nimport {\n allowDiscrete,\n classPiece,\n compose,\n at,\n container,\n empty,\n enter,\n global,\n grid,\n inline,\n keyframes,\n media,\n nest,\n pseudo,\n responsive,\n self,\n states,\n supports,\n vars,\n viewTransitionName,\n make,\n toStyleValue,\n type Piece,\n type StyleValue,\n} from './styleValue.js'\n\nexport type { Piece, StyleCondition, StyleValue } from './styleValue.js'\n\n/** A hidden slot is internal: it is neither styleable nor behavior-targetable. */\nexport type StylePieces<Slots> = PublicPieces<Slots, Piece>\n\ntype PublicPieces<Slots, Value> = {\n readonly [K in keyof Slots as HiddenOf<Slots[K]> extends true ? never : K]?: Value\n}\n\n/** `StylePieces` with every piece a `StyleValue`, as a recipe or a `NamedStyle` gives them. */\nexport type StyleValues<Slots> = PublicPieces<Slots, StyleValue>\n\nexport interface NamedStyle<Slots> {\n readonly name?: string\n /** Each piece as compiled, placed in the `layer` when one was given. */\n readonly pieces: StyleValues<Slots>\n readonly mixin: MixinValue<never>\n /** Concatenated rule CSS for every static piece. */\n readonly css: string\n /** Concatenated class-independent CSS (keyframes, layers, global rules). */\n readonly globalCss: string\n /** One entry per generated class, for a deduplicating stylesheet. */\n readonly rules: ReadonlyArray<{ readonly className: string; readonly css: string }>\n /** Class-independent rule chunks, for a deduplicating stylesheet. */\n readonly globalRules: ReadonlyArray<string>\n}\n\nexport interface StyleOptions {\n readonly name?: string\n /**\n * The layer every piece is placed in before compiling, e.g.\n * `Layers.standard.layer('app')`. A rule already in a layer keeps it.\n */\n readonly layer?: Placement\n}\n\n/** A boolean known at authoring time. */\nexport const when = (condition: boolean, piece: Piece): StyleValue =>\n condition ? toStyleValue(piece) : empty\n\n/** A condition read from the view input at render time. The piece applies when\n * `predicate` returns true for the input the view was rendered with. */\nexport const whenInput = <Input>(predicate: (input: Input) => boolean, piece: Piece): StyleValue =>\n make({\n conditions: Object.freeze([\n { predicate: (input: unknown) => predicate(input as Input), piece: toStyleValue(piece) },\n ]),\n })\n\n/**\n * A piece computed from the item the slot is rendered for, when the view\n * passes one to `attrs(base, item)`; nothing for a slot rendered once.\n */\nexport const perItem = (piece: (item: SlotItem) => Piece): StyleValue =>\n make({\n items: Object.freeze([\n (item: SlotItem | undefined) => (item === undefined ? empty : toStyleValue(piece(item))),\n ]),\n })\n\n/**\n * A per-item delay for an entrance: writes `--fk-index` and\n * `transition-delay: calc(var(--fk-index) * <step>)` (or `animation-delay`),\n * so a list staggers with no timer. Pass the item to `attrs` for each row.\n */\nexport const stagger = (options: {\n readonly stepMs: number\n readonly property?: 'transitionDelay' | 'animationDelay'\n}): StyleValue =>\n compose(\n // The delay is a rule; only the index is the item's own, inline.\n self({\n [options.property ?? 'transitionDelay']: `calc(var(--fk-index) * ${options.stepMs}ms)`,\n }),\n perItem(item => inline({ '--fk-index': String(item.index) })),\n )\n\n/** Fold every active condition and item piece (recursively) into a plain style. */\nconst resolveStyle = (style: StyleValue, input: unknown, item?: SlotItem): StyleValue => {\n const active = [\n ...(style.conditions ?? [])\n .filter(condition => condition.predicate(input))\n .map(condition => condition.piece),\n ...(style.items ?? []).map(piece => piece(item)),\n ].map(piece => resolveStyle(piece, input, item))\n return make({\n classes: Object.freeze([...style.classes, ...active.flatMap(piece => piece.classes)]),\n style: Object.freeze(\n Object.assign(Object.create(null), style.style, ...active.map(piece => piece.style)),\n ),\n })\n}\n\ninterface CompiledStyle {\n readonly classes: ReadonlyArray<string>\n readonly style: Readonly<Record<string, string>>\n readonly css?: string\n readonly ruleClass?: string\n readonly globalRules?: ReadonlyArray<string>\n /** Every class the tree compiled to, with its CSS, static or conditional. */\n readonly compiled: ReadonlyArray<{ readonly className: string; readonly css: string }>\n}\n\n/** Global CSS is emitted whether or not its condition is active. */\nconst collectGlobalCss = (style: StyleValue): ReadonlyArray<string> => [\n ...(style.globalCss ?? []),\n ...(style.conditions ?? []).flatMap(condition => collectGlobalCss(condition.piece)),\n]\n\n/**\n * Compiles every rule-bearing node in the tree to its class: the node's\n * classes gain the generated one, and the CSS is collected. A conditional\n * piece's rules are compiled the same way, so the class is static and only\n * its presence follows the input.\n */\nconst compileTree = (\n style: StyleValue,\n globalCss: string,\n collected: Array<{ readonly className: string; readonly css: string }>,\n): StyleValue => {\n const rules = style.rules ?? []\n const generated = rules.length === 0 ? undefined : Rules.className(rules)\n if (generated !== undefined) {\n const css = Rules.css(generated, rules)\n register(generated, css, globalCss)\n collected.push({ className: generated, css })\n }\n const conditions = (style.conditions ?? []).map(condition => ({\n predicate: condition.predicate,\n piece: compileTree(condition.piece, globalCss, collected),\n }))\n return Object.freeze({\n ...style,\n classes: generated === undefined ? style.classes : Object.freeze([...style.classes, generated]),\n ...(conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) }),\n })\n}\n\n/** A style with every rule in it compiled: the tree with classes, plus the CSS. */\nconst compileStyle = (style: StyleValue): CompiledStyle & { readonly tree: StyleValue } => {\n const collected: Array<{ readonly className: string; readonly css: string }> = []\n const globalRules = collectGlobalCss(style)\n // Every class the Style compiles to carries its globals, so a server that\n // finds any one of them in markup writes what the Style needs.\n const tree = compileTree(style, globalRules.join(''), collected)\n const first = collected[0]\n return {\n tree,\n classes: tree.classes,\n style: tree.style,\n ...(first === undefined\n ? {}\n : { css: collected.map(entry => entry.css).join(''), ruleClass: first.className }),\n ...(globalRules.length === 0 ? {} : { globalRules }),\n compiled: collected,\n }\n}\n\n/**\n * A static style stays static data; a style with input conditions compiles to a\n * message-free `InputContribution`, so it still attaches to any view.\n */\nconst contributionFrom = (\n style: StyleValue,\n compiled: CompiledStyle & { readonly tree: StyleValue },\n): SlotContribution<never> => {\n const globalCss = compiled.globalRules?.join('')\n const attributes = {\n classes: compiled.classes,\n style: compiled.style,\n ...(compiled.css === undefined ? {} : { css: compiled.css }),\n ...(globalCss === undefined ? {} : { globalCss }),\n }\n if ((style.conditions ?? []).length === 0 && (style.items ?? []).length === 0) {\n return Object.freeze(attributes)\n }\n const contribution: InputContribution<never> = context => {\n const resolved = resolveStyle(compiled.tree, context.input, context.item)\n return Object.freeze({\n classes: resolved.classes,\n style: resolved.style,\n ...(compiled.css === undefined ? {} : { css: compiled.css }),\n ...(globalCss === undefined ? {} : { globalCss }),\n })\n }\n return contribution\n}\n\nexport const forSlots =\n <Slots>(slots: Slots) =>\n (pieces: StylePieces<Slots>, options?: StyleOptions): NamedStyle<Slots> => {\n const known = slots as unknown as Record<string, unknown>\n const contributions: Record<string, SlotContribution<never>> = Object.create(null)\n // What was compiled, so `pieces` recomposed elsewhere keeps the layer too.\n const compiledPieces: Record<string, StyleValue> = Object.create(null)\n const rules: Array<{ className: string; css: string }> = []\n const globalRules: Array<string> = []\n let css = ''\n let globalCss = ''\n for (const [key, piece] of Object.entries(pieces as Record<string, Piece | undefined>)) {\n if (!Object.hasOwn(known, key)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:unknown-slot',\n severity: 'error',\n message: `Style targets unknown slot \"${key}\"`,\n slot: key,\n })\n }\n if ((known[key] as { readonly hidden?: boolean } | undefined)?.hidden === true) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:hidden-slot',\n severity: 'error',\n message: `Style targets hidden slot \"${key}\"`,\n slot: key,\n })\n }\n if (piece !== undefined) {\n const value = toStyleValue(piece)\n const placed = options?.layer === undefined ? value : options.layer.place(value)\n compiledPieces[key] = placed\n // Rule and global CSS are static even when the contribution is deferred,\n // so compile once, then build the contribution and gather the CSS.\n const compiled = compileStyle(placed)\n contributions[key] = contributionFrom(placed, compiled)\n for (const entry of compiled.compiled) {\n rules.push(entry)\n css += entry.css\n }\n if (compiled.globalRules !== undefined) {\n globalRules.push(...compiled.globalRules)\n globalCss += compiled.globalRules.join('')\n }\n }\n }\n return Object.freeze({\n ...(options?.name === undefined ? {} : { name: options.name }),\n pieces: compiledPieces,\n mixin: Mixin.dynamic<never>(options?.name ?? 'Style', contributions),\n css,\n globalCss,\n rules: Object.freeze(rules),\n globalRules: Object.freeze(globalRules),\n })\n }\n\nexport interface StylesheetSource {\n readonly rules: ReadonlyArray<{ readonly className: string; readonly css: string }>\n readonly globalRules: ReadonlyArray<string>\n}\n\nconst isStylesheetSource = (value: StyleValue | StylesheetSource): value is StylesheetSource =>\n 'globalRules' in value\n\nconst LAYER_STATEMENT = /^@layer [^{}]+;$/\n\nconst sourceOf = (style: StyleValue): StylesheetSource => {\n const compiled = compileStyle(style)\n return { rules: compiled.compiled, globalRules: compiled.globalRules ?? [] }\n}\n\n/**\n * An unlayered rule beats every layer, `app` included, so once a sheet\n * declares an order, a rule outside it, or in a layer the order does not\n * name (which would sort after the last one), is a mistake. Keyframes, font\n * faces, and registered properties are not ordered by the cascade and pass.\n */\nconst refuseUnlayered = (\n css: string,\n names: ReadonlyArray<string>,\n where: string,\n className?: string,\n): void => {\n for (const block of topLevelBlocks(css)) {\n if (isUnordered(block)) continue\n const layer = layerOf(block)\n if (layer !== undefined && names.includes(layer)) continue\n throw new DiagnosticError({\n source: 'style',\n code: 'style:unlayered-rule',\n severity: 'error',\n message:\n layer === undefined\n ? `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, …)`\n : `${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, …)`,\n details: {\n ...(className === undefined ? {} : { className }),\n ...(layer === undefined ? {} : { layer }),\n },\n })\n }\n}\n\n/**\n * One `<style>` block: the `@layer …;` statement first (one order per\n * sheet), then the other global chunks, then the scoped classes, each\n * deduplicated with the first seen winning. A bare `StyleValue` (a theme\n * root, a layered reset, a layout) compiles like a piece of a `NamedStyle`.\n * With an order declared, every rule must sit in one of its layers\n * (`style:unlayered-rule`); without one, unlayered rules are allowed.\n */\nexport const stylesheet = (...styles: ReadonlyArray<StyleValue | StylesheetSource>): string => {\n const scoped = new Map<string, string>()\n const global = new Set<string>()\n let order: string | undefined\n for (const style of styles) {\n const source = isStylesheetSource(style) ? style : sourceOf(style)\n for (const rule of source.rules) {\n if (!scoped.has(rule.className)) scoped.set(rule.className, rule.css)\n }\n for (const rule of source.globalRules) {\n if (!LAYER_STATEMENT.test(rule)) {\n global.add(rule)\n } else if (order === undefined) {\n order = rule\n } else if (order !== rule) {\n throw new DiagnosticError({\n source: 'style',\n code: 'style:conflicting-layer-order',\n severity: 'error',\n message: `Style.stylesheet was given two layer orders: \"${order}\" and \"${rule}\"`,\n })\n }\n }\n }\n if (order !== undefined) {\n const names = declaredNames(order)\n for (const chunk of global) refuseUnlayered(chunk, names, `global CSS \"${chunk.slice(0, 60)}\"`)\n for (const [className, css] of scoped) {\n refuseUnlayered(css, names, `class \"${className}\"`, className)\n }\n }\n return [...(order === undefined ? [] : [order]), ...global, ...scoped.values()].join('')\n}\n\nexport const attach =\n <Slots>(style: NamedStyle<Slots>) =>\n <ViewSlots, Input, Message>(\n view: SlotView.SlotView<ViewSlots, Input, Message>,\n ): SlotView.SlotView<ViewSlots, Input, Message> =>\n SlotView.attach(style.mixin)(view)\n\nexport type RecipeVariantDef = Readonly<Record<string, StyleValue>>\n\n/** A combination style applied when every `when` entry matches the selection. */\nexport interface RecipeCompound<Variants extends Readonly<Record<string, RecipeVariantDef>>> {\n readonly when: Partial<{ readonly [K in keyof Variants]: keyof Variants[K] & string }>\n readonly style: StyleValue\n}\n\nexport interface RecipeDef<Variants extends Readonly<Record<string, RecipeVariantDef>>> {\n readonly base?: StyleValue\n /** Absent for a recipe that is only its base. */\n readonly variants?: Variants\n readonly defaults?: { readonly [K in keyof Variants]?: keyof Variants[K] & string }\n readonly compound?: ReadonlyArray<RecipeCompound<Variants>>\n}\n\nexport type AnyRecipeDef = RecipeDef<Record<string, RecipeVariantDef>>\n\n/**\n * The selection of a recipe with no axes. An empty mapped type is `{}`, and\n * TypeScript checks no excess keys against `{}`, so `{ tone: 'quiet' }`\n * compiled and did nothing.\n */\ntype NoAxes = { readonly [key: string]: never }\n\nexport type RecipeSelection<D extends AnyRecipeDef> = [keyof NonNullable<D['variants']>] extends [\n never,\n]\n ? NoAxes\n : {\n readonly [K in keyof NonNullable<D['variants']>]?: keyof NonNullable<D['variants']>[K] &\n string\n }\n\n/** A recipe is just Style data: base, one piece per selected variant, then any\n * matching compound. `compound.when` is keyed by the recipe's variants, so a\n * typo is a compile error rather than a silently dead combination. */\nexport const recipe =\n <Variants extends Readonly<Record<string, RecipeVariantDef>> = {}>(def: RecipeDef<Variants>) =>\n (selection: RecipeSelection<RecipeDef<Variants>>): StyleValue => {\n const pieces: Array<StyleValue> = []\n if (def.base !== undefined) pieces.push(def.base)\n const effective: Record<string, string> = Object.create(null)\n for (const [variant, values] of Object.entries(def.variants ?? {})) {\n const chosen =\n own(selection as Record<string, string | undefined>, variant) ??\n (def.defaults as Record<string, string | undefined> | undefined)?.[variant]\n if (chosen === undefined) continue\n effective[variant] = chosen\n const piece = (values as Record<string, StyleValue>)[chosen]\n if (piece !== undefined) pieces.push(piece)\n }\n for (const compound of def.compound ?? []) {\n if (Object.entries(compound.when).every(([variant, value]) => effective[variant] === value)) {\n pieces.push(compound.style)\n }\n }\n return compose(...pieces)\n }\n\nexport type SlotRecipeVariants<Slots> = Readonly<\n Record<string, Readonly<Record<string, StylePieces<Slots>>>>\n>\n\nexport interface SlotRecipeDef<Slots, Variants extends SlotRecipeVariants<Slots>> {\n readonly base?: StylePieces<Slots>\n /** Absent for a recipe that is only its base. */\n readonly variants?: Variants\n readonly defaults?: { readonly [K in keyof Variants]?: keyof Variants[K] & string }\n readonly compound?: ReadonlyArray<{\n readonly when: Partial<{ readonly [K in keyof Variants]: keyof Variants[K] & string }>\n readonly style: StylePieces<Slots>\n }>\n}\n\n/** A selection; `null` unsets an axis that has a default. */\nexport type SlotRecipeSelection<Variants> = [keyof Variants] extends [never]\n ? NoAxes\n : { readonly [K in keyof Variants]?: (keyof Variants[K] & string) | null }\n\nexport interface SlotRecipePatch<Slots, Variants extends SlotRecipeVariants<Slots>> {\n readonly base?: StylePieces<Slots>\n readonly variants?: {\n readonly [K in keyof Variants]?: { readonly [V in keyof Variants[K]]?: StylePieces<Slots> }\n }\n readonly defaults?: SlotRecipeDef<Slots, Variants>['defaults']\n readonly compound?: SlotRecipeDef<Slots, Variants>['compound']\n}\n\nexport interface SlotRecipe<Slots, Variants extends SlotRecipeVariants<Slots>> {\n (selection?: SlotRecipeSelection<Variants>): StyleValues<Slots>\n /** The definition, with `variants` present (`{}` when none was given). */\n readonly def: SlotRecipeDef<Slots, Variants> & { readonly variants: Variants }\n /**\n * The same recipe with `patch` merged in: base pieces compose per slot, a\n * variant's pieces compose over the base recipe's, compounds append,\n * defaults override. A slot the contract lacks is refused at once.\n */\n readonly extend: (patch: SlotRecipePatch<Slots, Variants>) => SlotRecipe<Slots, Variants>\n}\n\nconst mergePieces = <Slots>(\n left: StylePieces<Slots> | undefined,\n right: StylePieces<Slots> | undefined,\n): StyleValues<Slots> => {\n const merged: Record<string, StyleValue> = Object.create(null)\n for (const source of [left, right]) {\n for (const [slot, piece] of Object.entries((source ?? {}) as Record<string, Piece>)) {\n const existing = merged[slot]\n merged[slot] = existing === undefined ? toStyleValue(piece) : compose(existing, piece)\n }\n }\n return merged as StyleValues<Slots>\n}\n\nconst assertKnownSlots = <Slots>(\n slots: Slots,\n pieces: StylePieces<Slots> | undefined,\n where: string,\n): void => {\n const known = slots as unknown as Record<string, unknown>\n for (const slot of Object.keys((pieces ?? {}) as Record<string, unknown>)) {\n if (!Object.hasOwn(known, slot)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:unknown-slot',\n severity: 'error',\n message: `Recipe ${where} targets unknown slot \"${slot}\"`,\n slot,\n })\n }\n }\n}\n\n/**\n * A recipe over every slot of a contract: `base` pieces per slot, `variants`\n * per axis and value, `defaults`, and `compound` matches. The result of a\n * selection is a `StylePieces` for `Style.forSlots`. A design system ships\n * the recipe; an application adjusts it with `extend` instead of forking.\n */\nexport const recipeFor =\n <Slots>(slots: Slots) =>\n <Variants extends SlotRecipeVariants<Slots> = {}>(\n def: SlotRecipeDef<Slots, Variants>,\n ): SlotRecipe<Slots, Variants> => {\n // Absent variants are none; `{}` is what the default type argument names.\n const full = { ...def, variants: def.variants ?? ({} as Variants) }\n const axes: SlotRecipeVariants<Slots> = full.variants\n assertKnownSlots(slots, def.base, 'base')\n for (const [axis, values] of Object.entries(axes)) {\n for (const [value, pieces] of Object.entries(values)) {\n assertKnownSlots(slots, pieces as StylePieces<Slots>, `variants.${axis}.${value}`)\n }\n }\n for (const entry of def.compound ?? []) assertKnownSlots(slots, entry.style, 'compound')\n const select = (selection: SlotRecipeSelection<Variants> = {}): StyleValues<Slots> => {\n let pieces = mergePieces(def.base, undefined)\n const effective: Record<string, string> = Object.create(null)\n for (const [axis, values] of Object.entries(axes)) {\n const picked = own(selection as Record<string, string | null | undefined>, axis)\n const chosen =\n picked === null\n ? undefined\n : (picked ?? (def.defaults as Record<string, string | undefined> | undefined)?.[axis])\n if (chosen === undefined) continue\n effective[axis] = chosen\n const piece = (values as Record<string, StylePieces<Slots>>)[chosen]\n if (piece !== undefined) pieces = mergePieces(pieces, piece)\n }\n for (const entry of def.compound ?? []) {\n if (Object.entries(entry.when).every(([axis, value]) => effective[axis] === value)) {\n pieces = mergePieces(pieces, entry.style)\n }\n }\n return pieces\n }\n const extend = (patch: SlotRecipePatch<Slots, Variants>): SlotRecipe<Slots, Variants> => {\n const variants: Record<string, Record<string, StylePieces<Slots>>> = Object.create(null)\n for (const [axis, values] of Object.entries(axes)) {\n variants[axis] = { ...(values as Record<string, StylePieces<Slots>>) }\n }\n for (const [axis, values] of Object.entries(patch.variants ?? {})) {\n const target = variants[axis] ?? {}\n for (const [value, pieces] of Object.entries(\n (values ?? {}) as Record<string, StylePieces<Slots>>,\n )) {\n target[value] = mergePieces(target[value], pieces)\n }\n variants[axis] = target\n }\n return recipeFor(slots)({\n base: mergePieces(def.base, patch.base),\n variants: variants as unknown as Variants,\n defaults: { ...def.defaults, ...patch.defaults } as NonNullable<\n SlotRecipeDef<Slots, Variants>['defaults']\n >,\n compound: [...(def.compound ?? []), ...(patch.compound ?? [])],\n })\n }\n return Object.assign(select, { def: full, extend })\n }\n\n/**\n * One piece for every public slot whose capability satisfies `capability`:\n * a focus ring for every `Focusable`, a disabled treatment for every\n * `Interactive`, in one line.\n */\nexport const forCapability =\n <Slots>(slots: Slots) =>\n (\n capability: string | Capability.Any,\n piece: Piece,\n options?: StyleOptions,\n ): NamedStyle<Slots> => {\n const source = slots as unknown as Record<string, AnySlot>\n const value = toStyleValue(piece)\n const pieces: Record<string, StyleValue> = Object.create(null)\n for (const [name, slot] of Object.entries(source)) {\n if (slot.hidden) continue\n if (Capability.extendsCapability(slot.capability, capability)) pieces[name] = value\n }\n return forSlots(slots)(pieces as StylePieces<Slots>, options)\n }\n\nexport const SlotPieceTypeId: unique symbol = Symbol.for('foldkit-mixins/SlotPiece')\n\n/** A key of `Style.slots` that declares more than a Container: its slot, and its piece. */\nexport interface SlotPiece<S = UnnamedSlot> {\n readonly [SlotPieceTypeId]: S\n readonly piece: Piece\n}\n\nconst isSlotPiece = (value: unknown): value is SlotPiece =>\n typeof value === 'object' && value !== null && Object.hasOwn(value, SlotPieceTypeId)\n\n/** What `Style.slots` declares for a key given only a piece. */\nexport type ContainerSlot = UnnamedSlot<\n typeof Capability.Container,\n readonly [],\n readonly [],\n readonly [],\n false\n>\n\nconst containerSlot: ContainerSlot = SlotModule.make({ capability: Capability.Container })\n\n/**\n * A key of `Style.slots` with slot options: `form: Style.slot({ events:\n * [Event.Submit] }, piece)`. The capability defaults to `Container`; a slot\n * declared here is the application's own, so it cannot be hidden.\n */\nexport const slot = <\n const C extends SlotCapability = typeof Capability.Container,\n const Events extends ReadonlyArray<EventName> = readonly [],\n const Attributes extends ReadonlyArray<AttributeName> = readonly [],\n const Requirements extends ReadonlyArray<RequirementName> = readonly [],\n>(\n options: Pick<\n MakeOptions<C, Events, Attributes, Requirements, false>,\n 'capability' | 'events' | 'attributes' | 'requirements' | 'protected'\n >,\n piece: Piece = empty,\n): SlotPiece<UnnamedSlot<C, Events, Attributes, Requirements, false>> =>\n Object.freeze({\n [SlotPieceTypeId]: SlotModule.make({\n capability: Capability.Container,\n ...options,\n }) as UnnamedSlot<C, Events, Attributes, Requirements, false>,\n piece,\n })\n\n/** What `Style.slots` takes: per key a piece, or a `Style.slot(options, piece)`. */\nexport type DeclaredPieces<S> = { readonly [K in keyof S]: Piece | SlotPiece<S[K]> }\n\n/** The contract `Style.slots` declares: a Container for a piece, the given slot for a `Style.slot`. */\nexport type DeclaredSlots<S> = SlotsContract<{\n readonly [K in keyof S]: S[K] extends UnnamedSlot ? S[K] : ContainerSlot\n}>\n\n/** A contract and the style that declared it. */\nexport interface Declared<S> {\n readonly slots: DeclaredSlots<S>\n readonly style: NamedStyle<DeclaredSlots<S>>\n}\n\n/**\n * An application's own Slots declared by their style: each key is a\n * `Container` slot with that piece, or a `Style.slot(options, piece)`.\n * `slots` is the contract a `SlotView` draws and `style` the `NamedStyle`\n * it attaches. To style a contract someone else published (`ButtonSlots`),\n * use `forSlots` instead.\n */\nexport const slots = <S>(pieces: DeclaredPieces<S>, options?: StyleOptions): Declared<S> => {\n const entries = Object.entries(pieces as Record<string, Piece | SlotPiece>)\n const contract = defineSlots(\n Object.fromEntries(\n entries.map(([key, value]) => [\n key,\n isSlotPiece(value) ? value[SlotPieceTypeId] : containerSlot,\n ]),\n ),\n ) as unknown as DeclaredSlots<S>\n const style = forSlots(contract)(\n Object.fromEntries(\n entries.map(([key, value]) => [key, isSlotPiece(value) ? value.piece : value]),\n ) as StylePieces<DeclaredSlots<S>>,\n options,\n )\n return Object.freeze({ slots: contract, style })\n}\n\n/**\n * Puts `css` (typically `Style.stylesheet(…)`) in the page's head as one\n * `<style>`, unless a `<style>` there already holds exactly this text (a page\n * rendered with it on the server, a second call). Returns that element, for\n * a caller that removes it. Browser only: throws where there is no `document`.\n */\nexport const install = (css: string): HTMLStyleElement => {\n if (typeof document === 'undefined') {\n throw new Error(\n 'Style.install needs a browser document; a server writes the sheet into the page',\n )\n }\n const present = Array.from(document.head.querySelectorAll('style')).find(\n element => element.textContent === css,\n )\n if (present !== undefined) return present\n const element = document.createElement('style')\n element.textContent = css\n document.head.append(element)\n return element\n}\n\nexport const Style = {\n class: classPiece,\n inline,\n compose,\n when,\n whenInput,\n pseudo,\n self,\n media,\n supports,\n at,\n container,\n nest,\n states,\n responsive,\n vars,\n enter,\n allowDiscrete,\n viewTransitionName,\n grid,\n keyframes,\n global,\n empty,\n perItem,\n stagger,\n forSlots,\n forCapability,\n slot,\n slots,\n attach,\n recipe,\n recipeFor,\n stylesheet,\n install,\n usedIn,\n complete,\n} as const\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+FA,MAAa,QAAQ,WAAoB,UACvC,YAAY,aAAa,KAAK,IAAI;;;AAIpC,MAAa,aAAoB,WAAsC,UACrE,KAAK,EACH,YAAY,OAAO,OAAO,CACxB;CAAE,YAAY,UAAmB,UAAU,KAAc;CAAG,OAAO,aAAa,KAAK;AAAE,CACzF,CAAC,EACH,CAAC;;;;;AAMH,MAAa,WAAW,UACtB,KAAK,EACH,OAAO,OAAO,OAAO,EAClB,SAAgC,SAAS,KAAA,IAAY,QAAQ,aAAa,MAAM,IAAI,CAAC,CACxF,CAAC,EACH,CAAC;;;;;;AAOH,MAAa,WAAW,YAItB,QAEE,KAAK,GACF,QAAQ,YAAY,oBAAoB,0BAA0B,QAAQ,OAAO,KACpF,CAAC,GACD,SAAQ,SAAQ,OAAO,EAAE,cAAc,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAC9D;;AAGF,MAAM,gBAAgB,OAAmB,OAAgB,SAAgC;CACvF,MAAM,SAAS,CACb,IAAI,MAAM,cAAc,CAAC,EAAA,CACtB,QAAO,cAAa,UAAU,UAAU,KAAK,CAAC,CAAC,CAC/C,KAAI,cAAa,UAAU,KAAK,GACnC,IAAI,MAAM,SAAS,CAAC,EAAA,CAAG,KAAI,UAAS,MAAM,IAAI,CAAC,CACjD,CAAC,CAAC,KAAI,UAAS,aAAa,OAAO,OAAO,IAAI,CAAC;CAC/C,OAAO,KAAK;EACV,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,SAAS,GAAG,OAAO,SAAQ,UAAS,MAAM,OAAO,CAAC,CAAC;EACpF,OAAO,OAAO,OACZ,OAAO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AO,OAAO;EACX,kBAAkB,WAAW,KAAK;EACjC,YAAY,WAAW;EACvB,GAAG;CACL,CAAC;CACD;AACF,CAAC;;;;;;;;AAuBH,MAAa,SAAY,QAA2B,YAAwC;CAC1F,MAAM,UAAU,OAAO,QAAQ,MAA2C;CAC1E,MAAM,WAAWC,OACf,OAAO,YACL,QAAQ,KAAK,CAAC,KAAK,WAAW,CAC5B,KACA,YAAY,KAAK,IAAI,MAAM,mBAAmB,aAChD,CAAC,CACH,CACF;CACA,MAAM,QAAQ,SAAS,QAAQ,CAAC,CAC9B,OAAO,YACL,QAAQ,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY,KAAK,IAAI,MAAM,QAAQ,KAAK,CAAC,CAC/E,GACA,OACF;CACA,OAAO,OAAO,OAAO;EAAE,OAAO;EAAU;CAAM,CAAC;AACjD;;;;;;;AAQA,MAAa,WAAW,QAAkC;CACxD,IAAI,OAAO,aAAa,aACtB,MAAM,IAAI,MACR,iFACF;CAEF,MAAM,UAAU,MAAM,KAAK,SAAS,KAAK,iBAAiB,OAAO,CAAC,CAAC,CAAC,MAClE,YAAW,QAAQ,gBAAgB,GACrC;CACA,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,MAAM,UAAU,SAAS,cAAc,OAAO;CAC9C,QAAQ,cAAc;CACtB,SAAS,KAAK,OAAO,OAAO;CAC5B,OAAO;AACT;AAEA,MAAa,QAAQ;CACnB,OAAO;CACP;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
package/dist/theme/knobs.js
CHANGED
package/dist/theme/knobs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knobs.js","names":["hue","ref"],"sources":["../../src/theme/knobs.ts"],"sourcesContent":["/**\n * The standard knobs, and a theme as a typed set of their values.\n *\n * `Knobs.standard` is every knob the shipped tokens and palette read, grouped\n * by concern. A theme (`Theme.make`) holds the values it sets and nothing\n * else; `Theme.variables` writes them, every knob it leaves unset holding its\n * default or the expression it follows (`docs/theme-knobs.md`).\n */\nimport { Cause, Exit, Option, Schema } from 'effect'\nimport { DiagnosticError } from '../diagnostics.js'\nimport { pipeSelf, type Pipeable } from '../pipe.js'\nimport { own } from '../record.js'\nimport { define } from './core.js'\nimport { boundaryVariables } from './gamut.js'\nimport * as Knob from './knob.js'\nimport { asVariables, elevation, reliefs } from './shadows.js'\n\n/** Knobs grouped one level deep: `{ shape: { radius: Knob.number(...) } }`. */\nexport type KnobSet = {\n readonly [group: string]: { readonly [name: string]: Knob.Knob<unknown> }\n}\n\n/** The value a theme writes to `K`. */\nexport type ValueOf<K> = K extends Knob.Knob<infer V> ? V : never\n\n/** Values for some of `S`'s knobs, by group and name. */\nexport type Values<S extends KnobSet> = {\n readonly [G in keyof S]?: { readonly [N in keyof S[G]]?: ValueOf<S[G][N]> }\n}\n\nconst hue = <const Name extends string>(\n variable: Name,\n value: number,\n title: string,\n description: string,\n) => Knob.angle({ variable, default: value, min: 0, max: 360, title, description })\nconst ref = (group: string, name: string) => `var(--fk-${group}-${name})`\n\nexport const standard = {\n accent: {\n hue: Knob.angle({\n title: 'Hue',\n variable: 'accent-h',\n default: 235,\n min: 0,\n max: 360,\n description:\n 'The accent’s place on the color wheel, in degrees: about 25 is red, 145 green, 264 blue. Buttons, links, focus rings and selections take it.',\n }),\n chroma: Knob.schemed(\n Knob.number({\n title: 'Chroma',\n variable: 'accent-c',\n default: 0.225,\n min: 0,\n max: 0.4,\n step: 0.005,\n description:\n 'How vivid the accent is. 0 is grey; around 0.2 is as vivid as most screens show.',\n }),\n Knob.number({\n title: 'Chroma, dark',\n variable: 'accent-c-dark',\n default: 0.255,\n // A little stronger on a dark page, where the same chroma reads duller.\n follows: `min(0.4, calc(${ref('knob', 'accent-c')} + 0.03))`,\n min: 0,\n max: 0.4,\n step: 0.005,\n description: 'How vivid the accent is in the dark scheme.',\n }),\n ),\n lightness: Knob.schemed(\n Knob.percent({\n title: 'Lightness',\n variable: 'accent-l',\n default: 55,\n min: 5,\n max: 98,\n step: 1,\n description:\n 'How light the accent is in the light scheme: near 10 a black accent, as shadcn’s.',\n }),\n Knob.percent({\n title: 'Lightness, dark',\n variable: 'accent-l-dark',\n default: 70,\n min: 5,\n max: 98,\n step: 1,\n description: 'How light the accent is in the dark scheme.',\n }),\n ),\n secondaryShift: Knob.angle({\n title: 'Secondary hue shift',\n variable: 'secondary-shift',\n default: 60,\n description: 'Degrees from the accent’s hue to the secondary family’s.',\n }),\n tertiaryShift: Knob.angle({\n title: 'Tertiary hue shift',\n variable: 'tertiary-shift',\n default: -90,\n description: 'Degrees from the accent’s hue to the tertiary family’s.',\n }),\n },\n surface: {\n hue: Knob.angle({\n title: 'Neutral hue',\n variable: 'neutral-h',\n default: 235,\n follows: ref('hue', 'accent'),\n min: 0,\n max: 360,\n description:\n 'The hue the neutrals are mixed from: the page, text and borders. Unset, the accent’s own.',\n }),\n saturation: Knob.schemed(\n Knob.number({\n title: 'Surface tint',\n variable: 'surface-c',\n default: 0,\n min: 0,\n max: 0.04,\n step: 0.001,\n description: 'How much the page, cards and borders lean toward their hue. 0 is pure grey.',\n }),\n Knob.number({\n title: 'Surface tint, dark',\n variable: 'surface-c-dark',\n default: 0,\n follows: `calc(${ref('knob', 'surface-c')} * 4 / 3)`,\n min: 0,\n max: 0.04,\n step: 0.001,\n description: 'How much the dark scheme’s surfaces lean toward their hue.',\n }),\n ),\n lightness: Knob.schemed(\n Knob.percent({\n title: 'Page lightness',\n variable: 'base-l',\n default: 100,\n min: 75,\n max: 100,\n step: 0.5,\n description:\n 'How light the page is in the light scheme. Cards, fields and hovers step from it.',\n }),\n Knob.percent({\n title: 'Page lightness, dark',\n variable: 'base-l-dark',\n default: 24.5,\n min: 6,\n max: 36,\n step: 0.5,\n description:\n 'How light the page is in the dark scheme. Cards, fields and hovers step from it.',\n }),\n ),\n contrast: Knob.percent({\n title: 'Surface contrast',\n variable: 'surface-contrast',\n default: 80,\n min: 0,\n max: 100,\n step: 1,\n description:\n 'How far apart the surface steps are: the page, a card on it, a field, a hover. Low is flat; high sets each apart.',\n }),\n textContrast: Knob.number({\n title: 'Text contrast',\n variable: 'contrast-factor',\n default: 1,\n min: 0,\n max: 2,\n step: 0.05,\n description: 'Multiplies the text’s chroma.',\n }),\n hover: Knob.choice({\n title: 'Hover',\n default: 'surface',\n options: {\n surface: { 'surface-ink': '1', 'state-ink': 'currentColor' },\n neutral: { 'surface-ink': '0', 'state-ink': 'currentColor' },\n accent: { 'surface-ink': '1', 'state-ink': ref('accent', 'ink') },\n },\n description:\n 'What a hovered row or button is tinted with: a step of the surface, a plain grey, or the accent.',\n }),\n hoverStrength: Knob.percent({\n title: 'Hover strength',\n variable: 'state-hover',\n default: 12,\n min: 4,\n max: 24,\n step: 1,\n description:\n 'How strongly a hovered row or button is tinted, a fluid highlight with it, and a press more.',\n }),\n },\n state: {\n disabledOpacity: Knob.number({\n title: 'Disabled',\n variable: 'state-disabled',\n default: 0.5,\n min: 0.3,\n max: 0.7,\n step: 0.05,\n description: 'How far a disabled control fades: 0.5 is half, 1 draws it as any other.',\n }),\n },\n shape: {\n radius: Knob.number({\n title: 'Radius',\n variable: 'radius-factor',\n default: 0.45,\n min: 0,\n max: 2.5,\n step: 0.05,\n description:\n 'Multiplies every corner. 0 is square. A control inside a card keeps inside the card’s corner.',\n }),\n density: Knob.number({\n title: 'Density',\n variable: 'density',\n default: 1.1,\n min: 0.75,\n max: 1.3,\n step: 0.05,\n description:\n 'Multiplies spacing: padding, gaps and margins. Below 1 is tighter, above 1 roomier.',\n }),\n size: Knob.choice({\n title: 'Size',\n default: 'default',\n options: { default: { step: '0' }, compact: { step: '1' } },\n description: 'How tall controls are: 36px, or a compact 28px.',\n }),\n controls: Knob.choice({\n title: 'Buttons',\n default: 'rounded',\n options: { rounded: { 'control-round': '0' }, pill: { 'control-round': '1' } },\n description: 'The corners of buttons: the radius’s, or fully round pills.',\n }),\n border: Knob.length('px')({\n title: 'Border',\n variable: 'border-width',\n default: 1,\n min: 1,\n max: 3,\n step: 1,\n description: 'The thinnest border’s width; the thicker ones step up from it.',\n }),\n // How much of the text's own ink the outlines take over the palette's\n // lines, at three strengths for subtle, default and overt.\n outlines: Knob.choice({\n title: 'Outlines',\n default: 'soft',\n options: {\n soft: {\n 'outline-ink': '0',\n 'outline-ink-subtle': '0%',\n 'outline-ink-default': '0%',\n 'outline-ink-overt': '0%',\n },\n strong: {\n 'outline-ink': '1',\n 'outline-ink-subtle': '22%',\n 'outline-ink-default': '48%',\n 'outline-ink-overt': '72%',\n },\n ink: {\n 'outline-ink': '1',\n 'outline-ink-subtle': '45%',\n 'outline-ink-default': '88%',\n 'outline-ink-overt': '100%',\n },\n },\n description:\n 'How much borders show: the palette’s soft lines, darker ones, or lines in the text’s own ink.',\n }),\n },\n type: {\n body: Knob.font({\n title: 'Font',\n variable: 'font-body',\n default: 'system-ui, sans-serif',\n description: 'The typeface for body text and controls.',\n }),\n heading: Knob.font({\n title: 'Heading font',\n variable: 'font-heading',\n default: 'inherit',\n description: 'The typeface for headings. `inherit` is the body’s.',\n }),\n headingWeight: Knob.number({\n title: 'Heading weight',\n variable: 'heading-weight',\n default: 700,\n min: 100,\n max: 900,\n step: 100,\n description: 'How bold headings are, from 300 (light) to 900 (black).',\n }),\n headingTracking: Knob.length('em')({\n title: 'Heading tracking',\n variable: 'heading-tracking',\n default: -0.025,\n min: -0.05,\n max: 0.05,\n step: 0.005,\n description:\n 'Headings’ letter spacing, in em: negative draws letters together, positive spreads them.',\n }),\n scale: Knob.number({\n title: 'Text size',\n variable: 'text-scale',\n default: 1.025,\n min: 0.8,\n max: 1.3,\n step: 0.025,\n description: 'Multiplies every text size, headings and body alike.',\n }),\n headingScale: Knob.number({\n title: 'Heading scale',\n variable: 'heading-scale',\n default: 1.2,\n min: 0.4,\n max: 1.8,\n step: 0.05,\n description:\n 'How far headings stand above body text: below 1 nearer its size, above 1 larger.',\n }),\n leading: Knob.number({\n title: 'Line height',\n variable: 'leading',\n default: 1.05,\n min: 0.85,\n max: 1.3,\n step: 0.05,\n description: 'Multiplies line height, the space each line of text takes.',\n }),\n fluid: Knob.number({\n title: 'Fluid type',\n variable: 'fluid',\n default: 1,\n min: 0,\n max: 1,\n step: 0.05,\n description:\n 'How much larger type grows between the small and large viewport. 0 keeps one size; 1 uses the whole range.',\n }),\n viewportMin: Knob.length('px')({\n title: 'Small viewport',\n variable: 'fluid-viewport-min',\n default: 320,\n min: 240,\n max: 800,\n step: 10,\n description: 'The viewport where every fluid size is its smallest, in px.',\n }),\n viewportMax: Knob.length('px')({\n title: 'Large viewport',\n variable: 'fluid-viewport-max',\n default: 1440,\n min: 900,\n max: 2560,\n step: 10,\n description: 'The viewport where every fluid size is its largest, in px.',\n }),\n },\n reading: {\n measure: Knob.length('ch')({\n title: 'Reading measure',\n variable: 'measure',\n default: 68,\n min: 30,\n max: 100,\n step: 1,\n description:\n 'The widest a line of reading text may run, in ch. Around 65 is a book’s measure; wider is harder to track back from.',\n }),\n headingWrap: Knob.choice({\n title: 'Heading wrap',\n default: 'balance',\n options: {\n balance: { 'heading-wrap': 'balance' },\n pretty: { 'heading-wrap': 'pretty' },\n wrap: { 'heading-wrap': 'wrap' },\n },\n description:\n 'How a heading breaks across lines: balanced lines, a prettier last line, or the browser’s ordinary wrap.',\n }),\n bodyWrap: Knob.choice({\n title: 'Body wrap',\n default: 'pretty',\n options: {\n pretty: { 'body-wrap': 'pretty' },\n wrap: { 'body-wrap': 'wrap' },\n balance: { 'body-wrap': 'balance' },\n },\n description:\n 'How body copy breaks: a prettier last line, the browser’s ordinary wrap, or balanced lines.',\n }),\n align: Knob.choice({\n title: 'Reading alignment',\n default: 'start',\n options: {\n start: { 'reading-align': 'start' },\n center: { 'reading-align': 'center' },\n end: { 'reading-align': 'end' },\n justify: { 'reading-align': 'justify' },\n },\n description:\n 'The alignment of reading text: start, centered, end, or justified. Start follows the writing direction.',\n }),\n },\n icon: {\n size: Knob.number({\n title: 'Icon size',\n variable: 'icon-scale',\n default: 1,\n min: 0.75,\n max: 1.5,\n step: 0.05,\n description:\n 'Multiplies every icon a component draws, beside its words: 1 is 16px, or 14px compact.',\n }),\n stroke: Knob.length('px')({\n title: 'Glyph stroke',\n variable: 'glyph-width',\n default: 2,\n min: 1,\n max: 3,\n step: 0.25,\n description:\n 'The width of the strokes components draw themselves: checks, chevrons, a tree’s guides. An icon pack keeps its own.',\n }),\n },\n motion: {\n scale: Knob.number({\n title: 'Motion',\n variable: 'motion',\n default: 0.5,\n min: 0,\n max: 2,\n step: 0.1,\n description: 'Multiplies how long every transition takes. 0 stills them; 2 is twice as slow.',\n }),\n easing: Knob.choice({\n title: 'Easing',\n default: 'spring',\n options: { ease: { ease: 'ease-out' }, spring: { ease: ref('motion', 'spring') } },\n description: 'How transitions move: along an easing curve, or on a spring that settles.',\n }),\n },\n shadow: {\n style: Knob.choice({\n title: 'Shadows',\n default: 'soft',\n options: {\n soft: asVariables('shadow', elevation.soft),\n hard: asVariables('shadow', elevation.hard),\n },\n description: 'Shadows that diffuse softly, or hard, solid offset copies.',\n }),\n relief: Knob.choice({\n title: 'Controls',\n default: 'flat',\n options: {\n flat: asVariables('relief', reliefs.flat),\n soft: asVariables('relief', reliefs.soft),\n hard: asVariables('relief', reliefs.hard),\n bevel: asVariables('relief', reliefs.bevel),\n },\n description:\n 'How buttons stand off the page and fields sink into it: flat, or a soft, hard or bevelled edge.',\n }),\n strength: Knob.percent({\n title: 'Shadow',\n variable: 'shadow-strength',\n default: 0,\n min: 0,\n max: 100,\n step: 1,\n description: 'How strong shadows are. 0 removes them.',\n }),\n hue: Knob.angle({\n title: 'Shadow hue',\n variable: 'shadow-h',\n default: 235,\n follows: ref('hue', 'neutral'),\n min: 0,\n max: 360,\n description: 'The hue every shadow is tinted with. Unset, the neutrals’.',\n }),\n chroma: Knob.number({\n title: 'Shadow tint',\n variable: 'shadow-c',\n default: 0,\n follows: `calc(${ref('knob', 'surface-c')} * 2)`,\n min: 0,\n max: 0.1,\n step: 0.005,\n description: 'How tinted every shadow is. Unset, twice the surfaces’ saturation.',\n }),\n },\n menu: {\n highlight: Knob.choice({\n title: 'Menu accent',\n default: 'subtle',\n options: { subtle: { 'popup-bold': '0' }, bold: { 'popup-bold': '1' } },\n description:\n 'How the highlighted row of a menu shows: a subtle tint, or filled with the accent.',\n }),\n panel: Knob.choice({\n title: 'Menu color',\n default: 'inverted',\n options: {\n default: { 'popup-invert': '0', 'popup-alpha': '1', 'popup-blur': '0px' },\n inverted: { 'popup-invert': '1', 'popup-alpha': '1', 'popup-blur': '0px' },\n translucent: { 'popup-invert': '0', 'popup-alpha': '0.8', 'popup-blur': '12px' },\n 'inverted-translucent': { 'popup-invert': '1', 'popup-alpha': '0.8', 'popup-blur': '12px' },\n },\n description:\n 'The background of menus and popovers: the page’s, inverted (dark on a light page), or translucent, the page blurred behind it.',\n }),\n },\n feedback: {\n success: hue('success-h', 145, 'Success', 'The hue of success: a saved form, a passing check.'),\n warning: hue('warning-h', 75, 'Warning', 'The hue of a warning.'),\n error: hue('error-h', 25, 'Error', 'The hue of an error: a refused field, a failed save.'),\n info: hue('info-h', 245, 'Info', 'The hue of a neutral notice.'),\n },\n code: {\n chroma: Knob.number({\n title: 'Code chroma',\n variable: 'syntax-c',\n default: 0.14,\n min: 0,\n max: 0.4,\n step: 0.01,\n description: 'How vivid code’s colors are.',\n }),\n },\n chart: {\n hue: hue(\n 'chart-h',\n 255,\n 'Chart hue',\n 'The first chart series’ hue; the other four keep their places around it.',\n ),\n },\n scales: {\n chroma: Knob.number({\n title: 'Scale vividness',\n variable: 'scale-c',\n default: 1.1,\n min: 0,\n max: 1.5,\n step: 0.05,\n description:\n 'How vivid the seven color scales are, as a share of each step’s own. 0 turns them grey.',\n }),\n red: hue('red-h', 25, 'Red', 'The red scale’s hue.'),\n orange: hue('orange-h', 55, 'Orange', 'The orange scale’s hue.'),\n yellow: hue('yellow-h', 90, 'Yellow', 'The yellow scale’s hue.'),\n green: hue('green-h', 145, 'Green', 'The green scale’s hue.'),\n teal: hue('teal-h', 185, 'Teal', 'The teal scale’s hue.'),\n blue: hue('blue-h', 255, 'Blue', 'The blue scale’s hue.'),\n purple: hue('purple-h', 300, 'Purple', 'The purple scale’s hue.'),\n },\n} as const satisfies KnobSet\n\nexport type Standard = typeof standard\n\n/** A theme: the knobs it may set, the values it sets, and what it is called in a list. */\nexport interface KnobTheme<S extends KnobSet = Standard> extends Pipeable<KnobTheme<S>> {\n readonly knobs: S\n readonly values: Values<S>\n readonly title: Option.Option<string>\n readonly description: Option.Option<string>\n}\n\nconst theme = <S extends KnobSet>(\n knobs: S,\n values: Values<S>,\n title: Option.Option<string>,\n description: Option.Option<string>,\n): KnobTheme<S> => ({\n knobs,\n values,\n title,\n description,\n pipe(...fns: ReadonlyArray<(self: KnobTheme<S>) => KnobTheme<S>>) {\n return pipeSelf(this, fns) as KnobTheme<S>\n },\n})\n\n/** The call a refusal names: a theme is usually built at module load, where a stack names only the module. */\ntype Caller = 'Theme.make' | 'Theme.set' | 'Knobs.withValue'\n\nconst unknownKnob = (caller: Caller, knob: string): DiagnosticError =>\n new DiagnosticError({\n source: 'theme',\n code: 'theme:unknown-knob',\n severity: 'error',\n message: `${caller}: no knob \"${knob}\".`,\n details: { knob },\n })\n\n/** Throws, naming the knob and the call, when `knob` refuses `value`. */\nconst checkValue = (caller: Caller, path: string, knob: Knob.Knob<unknown>, value: unknown) => {\n const decoded = Schema.decodeUnknownExit(knob.schema)(value)\n if (Exit.isSuccess(decoded)) return\n throw new DiagnosticError({\n source: 'theme',\n code: 'theme:knob-value',\n severity: 'error',\n message: `${caller}: ${path} refuses its value: ${Cause.pretty(decoded.cause)}`,\n details: { knob: path, value },\n })\n}\n\n/** Each value checked against its knob: an unknown group or knob, or a value out of range, throws. */\nconst checked = <S extends KnobSet>(caller: Caller, knobs: S, values: Values<S>): Values<S> => {\n for (const [group, names] of Object.entries(values)) {\n if (!Object.hasOwn(knobs, group)) throw unknownKnob(caller, group)\n for (const [name, value] of Object.entries(names ?? {})) {\n const path = `${group}.${name}`\n if (!Object.hasOwn(knobs[group]!, name)) throw unknownKnob(caller, path)\n checkValue(caller, path, knobs[group]![name]!, value)\n }\n }\n return values\n}\n\n/** What `values` set the knob `group.name` to, read from their own keys alone. */\nconst setIn = (values: object, group: string, name: string): unknown =>\n own(own(values as Readonly<Record<string, Readonly<Record<string, unknown>>>>, group), name)\n\nconst valueOf = <S extends KnobSet>(\n knobs: S,\n values: Values<S>,\n group: string,\n name: string,\n): unknown => {\n const set = (values[group] as Readonly<Record<string, unknown>> | undefined)?.[name]\n return (\n set ??\n (knobs[group] as Readonly<Record<string, Knob.Knob<unknown>>> | undefined)?.[name]?.default\n )\n}\n\n/**\n * A cross-knob rule each knob's schema cannot state: the fluid range's two\n * halves must not cross. Read from the merged values, each unset half from its\n * knob's default, so `Theme.set` and `Theme.make` both refuse an inverted range.\n */\nconst validate = <S extends KnobSet>(knobs: S, values: Values<S>): void => {\n const group = knobs['type'] as Readonly<Record<string, Knob.Knob<unknown>>> | undefined\n if (\n group === undefined ||\n !Object.hasOwn(group, 'viewportMin') ||\n !Object.hasOwn(group, 'viewportMax')\n )\n return\n const min = valueOf(knobs, values, 'type', 'viewportMin')\n const max = valueOf(knobs, values, 'type', 'viewportMax')\n if (typeof min !== 'number' || typeof max !== 'number' || min < max) return\n throw new DiagnosticError({\n source: 'theme',\n code: 'theme:fluid-range',\n severity: 'error',\n message: `Theme: type.viewportMin (${min}px) must be less than type.viewportMax (${max}px).`,\n details: { min, max },\n })\n}\n\n/**\n * A theme of the standard knobs, or of `knobs`: the values it sets, checked,\n * every other knob keeping its default. A misspelt knob or a choice outside\n * its options is a type error; a number out of its range throws here.\n */\nexport function make(values: Values<Standard>): KnobTheme<Standard>\nexport function make<S extends KnobSet>(knobs: S, values: Values<NoInfer<S>>): KnobTheme<S>\nexport function make(...args: [Values<Standard>] | [KnobSet, Values<KnobSet>]): KnobTheme<KnobSet> {\n const [knobs, values] = args.length === 1 ? [standard, args[0]] : args\n const checkedValues = checked('Theme.make', knobs, values)\n validate(knobs, checkedValues)\n return theme(knobs, checkedValues, Option.none(), Option.none())\n}\n\n/** `theme` with `values` over its own, group by group. */\nexport const set =\n <S extends KnobSet>(values: Values<NoInfer<S>>) =>\n (self: KnobTheme<S>): KnobTheme<S> => {\n const merged: Record<string, Record<string, unknown>> = Object.create(null)\n for (const source of [self.values, checked('Theme.set', self.knobs, values)])\n for (const [group, names] of Object.entries(source))\n merged[group] = { ...merged[group], ...names }\n validate(self.knobs, merged as Values<S>)\n return theme(self.knobs, merged as Values<S>, self.title, self.description)\n }\n\n/** A title and a description for a list of themes; neither is the theme's identity. */\nexport const describe =\n (meta: { readonly title?: string; readonly description?: string }) =>\n <S extends KnobSet>(self: KnobTheme<S>): KnobTheme<S> =>\n theme(\n self.knobs,\n self.values,\n meta.title === undefined ? self.title : Option.some(meta.title),\n meta.description === undefined ? self.description : Option.some(meta.description),\n )\n\n/**\n * Every knob variable `self` declares: the values it sets, every other knob's\n * unset value, and the sRGB boundary of each palette hue they place.\n */\nexport const variables = <S extends KnobSet>(self: KnobTheme<S>): Knob.Variables => {\n const declared: Record<string, string> = {}\n for (const [group, knobs] of Object.entries(self.knobs))\n for (const [name, knob] of Object.entries(knobs)) {\n const value = setIn(self.values, group, name)\n Object.assign(declared, knob.unset, value === undefined ? {} : knob.write(value))\n }\n return Object.assign(declared, boundaryVariables(declared))\n}\n\ntype Intersected<U> = (U extends unknown ? (union: U) => void : never) extends (\n meet: infer I,\n) => void\n ? I\n : never\n\n/** What every knob of `knobs` writes unset, under its variables' own names. */\nexport const unsetOf = <S extends KnobSet>(\n knobs: S,\n): Intersected<{ [G in keyof S]: { [K in keyof S[G]]: S[G][K]['unset'] }[keyof S[G]] }[keyof S]> =>\n Object.assign(\n {},\n ...Object.values(knobs).flatMap(group => Object.values(group).map(knob => knob.unset)),\n )\n\n/** `self`'s knob variables as tokens, for `Theme.root` and `Theme.scoped`. */\nexport const tokensOf = <S extends KnobSet>(self: KnobTheme<S>) => define({ knob: variables(self) })\n\n/**\n * The Schema of a theme's values over `knobs`: each group and knob optional,\n * each value checked by its knob, for a Model field or a decoded URL. Decode\n * with `onExcessProperty: 'error'` where an unknown key must be refused\n * rather than dropped.\n */\nexport const schemaOf = <S extends KnobSet>(knobs: S): Schema.Codec<Values<S>> =>\n // Built from `knobs` group by group, so its type is `Values<S>` by construction.\n Schema.Struct(\n Object.fromEntries(\n Object.entries(knobs).map(([group, names]) => [\n group,\n Schema.optionalKey(\n Schema.Struct(\n Object.fromEntries(\n Object.entries(names).map(([name, knob]) => [name, Schema.optionalKey(knob.schema)]),\n ),\n ),\n ),\n ]),\n ),\n ) as unknown as Schema.Codec<Values<S>>\n\nconst literal = (value: unknown): string =>\n typeof value === 'string'\n ? `'${value.replaceAll('\\\\', '\\\\\\\\').replaceAll(\"'\", \"\\\\'\")}'`\n : typeof value === 'object' && value !== null\n ? `{ ${Object.entries(value)\n .map(([key, each]) => `${key}: ${literal(each)}`)\n .join(', ')} }`\n : String(value)\n\n/**\n * Whether `value` changes nothing the knob writes unset: a bare `0.17` for a\n * schemed knob whose dark half follows is its default, though it is no\n * `{ light, dark }`.\n */\nconst atDefault = (knob: Knob.Knob<unknown>, value: unknown): boolean =>\n Object.entries(knob.write(value)).every(([name, css]) => knob.unset[name] === css)\n\n/**\n * The source of `self` as `Theme.make({ … })`: each knob it sets that writes\n * other than the knob's default does, a group to a line (a knob a line past\n * a hundred characters), so the code an application\n * pastes says only what makes the theme its own.\n */\nexport const print = <S extends KnobSet>(self: KnobTheme<S>): string => {\n const groups = Object.entries(self.knobs).flatMap(([group, knobs]) => {\n const set = Object.entries(knobs).flatMap(([name, knob]) => {\n const value = setIn(self.values, group, name)\n return value === undefined || atDefault(knob, value) ? [] : [`${name}: ${literal(value)}`]\n })\n if (set.length === 0) return []\n const line = ` ${group}: { ${set.join(', ')} },`\n // A group past the width a formatter keeps breaks to a knob a line, as one would.\n return line.length <= 100\n ? [line]\n : [` ${group}: {`, ...set.map(each => ` ${each},`), ' },']\n })\n return groups.length === 0 ? 'Theme.make({})' : ['Theme.make({', ...groups, '})'].join('\\n')\n}\n\n/** One knob of `S`, by its group and name: `shape.radius`. */\nexport type PathOf<S extends KnobSet> = {\n readonly [G in keyof S & string]: `${G}.${keyof S[G] & string}`\n}[keyof S & string]\n\n/** The knob of `S` at `P`. */\nexport type KnobAt<S extends KnobSet, P extends PathOf<S>> = P extends `${infer G}.${infer N}`\n ? G extends keyof S\n ? N extends keyof S[G]\n ? S[G][N]\n : never\n : never\n : never\n\nconst split = (path: string): readonly [string, string] => {\n const dot = path.indexOf('.')\n return [path.slice(0, dot), path.slice(dot + 1)]\n}\n\n/** Every knob's path in `knobs`, in the order they are declared. */\nexport const paths = <S extends KnobSet>(knobs: S): ReadonlyArray<PathOf<S>> =>\n Object.entries(knobs).flatMap(([group, names]) =>\n Object.keys(names).map(name => `${group}.${name}`),\n ) as ReadonlyArray<PathOf<S>>\n\n/** The knob at `path`. */\nexport const at = <S extends KnobSet, P extends PathOf<S>>(knobs: S, path: P): KnobAt<S, P> => {\n const [group, name] = split(path)\n return knobs[group]![name] as KnobAt<S, P>\n}\n\n/** What `values` set the knob at `path` to, or its default. */\nexport const valueAt = <S extends KnobSet, P extends PathOf<S>>(\n knobs: S,\n values: Values<S>,\n path: P,\n): ValueOf<KnobAt<S, P>> => {\n const [group, name] = split(path)\n return (setIn(values, group, name) ?? at(knobs, path).default) as ValueOf<KnobAt<S, P>>\n}\n\n/** `values` with the knob at `path` set to `value`, checked by the knob as `make` checks it. */\nexport const withValue = <S extends KnobSet, P extends PathOf<S>>(\n knobs: S,\n values: Values<S>,\n path: P,\n value: ValueOf<KnobAt<S, P>>,\n): Values<S> => {\n const [group, name] = split(path)\n checkValue('Knobs.withValue', path, at(knobs, path), value)\n const next = { ...values, [group]: { ...values[group], [name]: value } } as Values<S>\n validate(knobs, next)\n return next\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAMA,SACJ,UACA,OACA,OACA,gBACG,KAAK,MAAM;CAAE;CAAU,SAAS;CAAO,KAAK;CAAG,KAAK;CAAK;CAAO;AAAY,CAAC;AAClF,MAAMC,SAAO,OAAe,SAAiB,YAAY,MAAM,GAAG,KAAK;AAEvE,MAAa,WAAW;CACtB,QAAQ;EACN,KAAK,KAAK,MAAM;GACd,OAAO;GACP,UAAU;GACV,SAAS;GACT,KAAK;GACL,KAAK;GACL,aACE;EACJ,CAAC;EACD,QAAQ,KAAK,QACX,KAAK,OAAO;GACV,OAAO;GACP,UAAU;GACV,SAAS;GACT,KAAK;GACL,KAAK;GACL,MAAM;GACN,aACE;EACJ,CAAC,GACD,KAAK,OAAO;GACV,OAAO;GACP,UAAU;GACV,SAAS;GAET,SAAS,iBAAiBA,MAAI,QAAQ,UAAU,EAAE;GAClD,KAAK;GACL,KAAK;GACL,MAAM;GACN,aAAa;EACf,CAAC,CACH;EACA,WAAW,KAAK,QACd,KAAK,QAAQ;GACX,OAAO;GACP,UAAU;GACV,SAAS;GACT,KAAK;GACL,KAAK;GACL,MAAM;GACN,aACE;EACJ,CAAC,GACD,KAAK,QAAQ;GACX,OAAO;GACP,UAAU;GACV,SAAS;GACT,KAAK;GACL,KAAK;GACL,MAAM;GACN,aAAa;EACf,CAAC,CACH;EACA,gBAAgB,KAAK,MAAM;GACzB,OAAO;GACP,UAAU;GACV,SAAS;GACT,aAAa;EACf,CAAC;EACD,eAAe,KAAK,MAAM;GACxB,OAAO;GACP,UAAU;GACV,SAAS;GACT,aAAa;EACf,CAAC;CACH;CACA,SAAS;EACP,KAAK,KAAK,MAAM;GACd,OAAO;GACP,UAAU;GACV,SAAS;GACT,SAASA,MAAI,OAAO,QAAQ;GAC5B,KAAK;GACL,KAAK;GACL,aACE;EACJ,CAAC;EACD,YAAY,KAAK,QACf,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I,KAAI,SAAQ,OAAO,KAAK,EAAE;GAAG;EAAM;CAClE,CAAC;CACD,OAAO,OAAO,WAAW,IAAI,mBAAmB;EAAC;EAAgB,GAAG;EAAQ;CAAI,CAAC,CAAC,KAAK,IAAI;AAC7F;AAgBA,MAAM,SAAS,SAA4C;CACzD,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,OAAO,CAAC,KAAK,MAAM,GAAG,GAAG,GAAG,KAAK,MAAM,MAAM,CAAC,CAAC;AACjD;;AAGA,MAAa,SAA4B,UACvC,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,WACrC,OAAO,KAAK,KAAK,CAAC,CAAC,KAAI,SAAQ,GAAG,MAAM,GAAG,MAAM,CACnD;;AAGF,MAAa,MAA8C,OAAU,SAA0B;CAC7F,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,OAAO,MAAM,MAAM,CAAE;AACvB;;AAGA,MAAa,WACX,OACA,QACA,SAC0B;CAC1B,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,OAAQ,MAAM,QAAQ,OAAO,IAAI,KAAK,GAAG,OAAO,IAAI,CAAC,CAAC;AACxD;;AAGA,MAAa,aACX,OACA,QACA,MACA,UACc;CACd,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,WAAW,mBAAmB,MAAM,GAAG,OAAO,IAAI,GAAG,KAAK;CAC1D,MAAM,OAAO;EAAE,GAAG;GAAS,QAAQ;GAAE,GAAG,OAAO;IAAS,OAAO;EAAM;CAAE;CACvE,SAAS,OAAO,IAAI;CACpB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"knobs.js","names":["hue","ref"],"sources":["../../src/theme/knobs.ts"],"sourcesContent":["/**\n * The standard knobs, and a theme as a typed set of their values.\n *\n * `Knobs.standard` is every knob the shipped tokens and palette read, grouped\n * by concern. A theme (`Theme.make`) holds the values it sets and nothing\n * else; `Theme.variables` writes them, every knob it leaves unset holding its\n * default or the expression it follows (`docs/theme-knobs.md`).\n */\nimport { Cause, Exit, Option, Schema } from 'effect'\nimport { DiagnosticError } from '../diagnostics.js'\nimport { pipeSelf, type Pipeable } from '../pipe.js'\nimport { own } from '../record.js'\nimport { define } from './core.js'\nimport { boundaryVariables } from './gamut.js'\nimport * as Knob from './knob.js'\nimport { asVariables, elevation, reliefs } from './shadows.js'\n\n/** Knobs grouped one level deep: `{ shape: { radius: Knob.number(...) } }`. */\nexport type KnobSet = {\n readonly [group: string]: { readonly [name: string]: Knob.Knob<unknown> }\n}\n\n/** The value a theme writes to `K`. */\nexport type ValueOf<K> = K extends Knob.Knob<infer V> ? V : never\n\n/** Values for some of `S`'s knobs, by group and name. */\nexport type Values<S extends KnobSet> = {\n readonly [G in keyof S]?: { readonly [N in keyof S[G]]?: ValueOf<S[G][N]> }\n}\n\nconst hue = <const Name extends string>(\n variable: Name,\n value: number,\n title: string,\n description: string,\n) => Knob.angle({ variable, default: value, min: 0, max: 360, title, description })\nconst ref = (group: string, name: string) => `var(--fk-${group}-${name})`\n\nexport const standard = {\n accent: {\n hue: Knob.angle({\n title: 'Hue',\n variable: 'accent-h',\n default: 235,\n min: 0,\n max: 360,\n description:\n 'The accent’s place on the color wheel, in degrees: about 25 is red, 145 green, 264 blue. Buttons, links, focus rings and selections take it.',\n }),\n chroma: Knob.schemed(\n Knob.number({\n title: 'Chroma',\n variable: 'accent-c',\n default: 0.225,\n min: 0,\n max: 0.4,\n step: 0.005,\n description:\n 'How vivid the accent is. 0 is grey; around 0.2 is as vivid as most screens show.',\n }),\n Knob.number({\n title: 'Chroma, dark',\n variable: 'accent-c-dark',\n default: 0.255,\n // A little stronger on a dark page, where the same chroma reads duller.\n follows: `min(0.4, calc(${ref('knob', 'accent-c')} + 0.03))`,\n min: 0,\n max: 0.4,\n step: 0.005,\n description: 'How vivid the accent is in the dark scheme.',\n }),\n ),\n lightness: Knob.schemed(\n Knob.percent({\n title: 'Lightness',\n variable: 'accent-l',\n default: 55,\n min: 5,\n max: 98,\n step: 1,\n description:\n 'How light the accent is in the light scheme: near 10 a black accent, as shadcn’s.',\n }),\n Knob.percent({\n title: 'Lightness, dark',\n variable: 'accent-l-dark',\n default: 70,\n min: 5,\n max: 98,\n step: 1,\n description: 'How light the accent is in the dark scheme.',\n }),\n ),\n secondaryShift: Knob.angle({\n title: 'Secondary hue shift',\n variable: 'secondary-shift',\n default: 60,\n description: 'Degrees from the accent’s hue to the secondary family’s.',\n }),\n tertiaryShift: Knob.angle({\n title: 'Tertiary hue shift',\n variable: 'tertiary-shift',\n default: -90,\n description: 'Degrees from the accent’s hue to the tertiary family’s.',\n }),\n },\n surface: {\n hue: Knob.angle({\n title: 'Neutral hue',\n variable: 'neutral-h',\n default: 235,\n follows: ref('hue', 'accent'),\n min: 0,\n max: 360,\n description:\n 'The hue the neutrals are mixed from: the page, text and borders. Unset, the accent’s own.',\n }),\n saturation: Knob.schemed(\n Knob.number({\n title: 'Surface tint',\n variable: 'surface-c',\n default: 0,\n min: 0,\n max: 0.04,\n step: 0.001,\n description: 'How much the page, cards and borders lean toward their hue. 0 is pure grey.',\n }),\n Knob.number({\n title: 'Surface tint, dark',\n variable: 'surface-c-dark',\n default: 0,\n follows: `calc(${ref('knob', 'surface-c')} * 4 / 3)`,\n min: 0,\n max: 0.04,\n step: 0.001,\n description: 'How much the dark scheme’s surfaces lean toward their hue.',\n }),\n ),\n lightness: Knob.schemed(\n Knob.percent({\n title: 'Page lightness',\n variable: 'base-l',\n default: 100,\n min: 75,\n max: 100,\n step: 0.5,\n description:\n 'How light the page is in the light scheme. Cards, fields and hovers step from it.',\n }),\n Knob.percent({\n title: 'Page lightness, dark',\n variable: 'base-l-dark',\n default: 24.5,\n min: 6,\n max: 36,\n step: 0.5,\n description:\n 'How light the page is in the dark scheme. Cards, fields and hovers step from it.',\n }),\n ),\n contrast: Knob.percent({\n title: 'Surface contrast',\n variable: 'surface-contrast',\n default: 70,\n min: 0,\n max: 100,\n step: 1,\n description:\n 'How far apart the surface steps are: the page, a card on it, a field, a hover. Low is flat; high sets each apart.',\n }),\n textContrast: Knob.number({\n title: 'Text contrast',\n variable: 'contrast-factor',\n default: 1,\n min: 0,\n max: 2,\n step: 0.05,\n description: 'Multiplies the text’s chroma.',\n }),\n hover: Knob.choice({\n title: 'Hover',\n default: 'surface',\n options: {\n surface: { 'surface-ink': '1', 'state-ink': 'currentColor' },\n neutral: { 'surface-ink': '0', 'state-ink': 'currentColor' },\n accent: { 'surface-ink': '1', 'state-ink': ref('accent', 'ink') },\n },\n description:\n 'What a hovered row or button is tinted with: a step of the surface, a plain grey, or the accent.',\n }),\n hoverStrength: Knob.percent({\n title: 'Hover strength',\n variable: 'state-hover',\n default: 12,\n min: 4,\n max: 24,\n step: 1,\n description:\n 'How strongly a hovered row or button is tinted, a fluid highlight with it, and a press more.',\n }),\n },\n state: {\n disabledOpacity: Knob.number({\n title: 'Disabled',\n variable: 'state-disabled',\n default: 0.5,\n min: 0.3,\n max: 0.7,\n step: 0.05,\n description: 'How far a disabled control fades: 0.5 is half, 1 draws it as any other.',\n }),\n },\n shape: {\n radius: Knob.number({\n title: 'Radius',\n variable: 'radius-factor',\n default: 0.45,\n min: 0,\n max: 2.5,\n step: 0.05,\n description:\n 'Multiplies every corner. 0 is square. A control inside a card keeps inside the card’s corner.',\n }),\n density: Knob.number({\n title: 'Density',\n variable: 'density',\n default: 1.1,\n min: 0.75,\n max: 1.3,\n step: 0.05,\n description:\n 'Multiplies spacing: padding, gaps and margins. Below 1 is tighter, above 1 roomier.',\n }),\n size: Knob.choice({\n title: 'Size',\n default: 'default',\n options: { default: { step: '0' }, compact: { step: '1' } },\n description: 'How tall controls are: 36px, or a compact 28px.',\n }),\n controls: Knob.choice({\n title: 'Buttons',\n default: 'rounded',\n options: { rounded: { 'control-round': '0' }, pill: { 'control-round': '1' } },\n description: 'The corners of buttons: the radius’s, or fully round pills.',\n }),\n border: Knob.length('px')({\n title: 'Border',\n variable: 'border-width',\n default: 1,\n min: 1,\n max: 3,\n step: 1,\n description: 'The thinnest border’s width; the thicker ones step up from it.',\n }),\n // How much of the text's own ink the outlines take over the palette's\n // lines, at three strengths for subtle, default and overt.\n outlines: Knob.choice({\n title: 'Outlines',\n default: 'soft',\n options: {\n soft: {\n 'outline-ink': '0',\n 'outline-ink-subtle': '0%',\n 'outline-ink-default': '0%',\n 'outline-ink-overt': '0%',\n },\n strong: {\n 'outline-ink': '1',\n 'outline-ink-subtle': '22%',\n 'outline-ink-default': '48%',\n 'outline-ink-overt': '72%',\n },\n ink: {\n 'outline-ink': '1',\n 'outline-ink-subtle': '45%',\n 'outline-ink-default': '88%',\n 'outline-ink-overt': '100%',\n },\n },\n description:\n 'How much borders show: the palette’s soft lines, darker ones, or lines in the text’s own ink.',\n }),\n },\n type: {\n body: Knob.font({\n title: 'Font',\n variable: 'font-body',\n default: 'system-ui, sans-serif',\n description: 'The typeface for body text and controls.',\n }),\n heading: Knob.font({\n title: 'Heading font',\n variable: 'font-heading',\n default: 'inherit',\n description: 'The typeface for headings. `inherit` is the body’s.',\n }),\n headingWeight: Knob.number({\n title: 'Heading weight',\n variable: 'heading-weight',\n default: 700,\n min: 100,\n max: 900,\n step: 100,\n description: 'How bold headings are, from 300 (light) to 900 (black).',\n }),\n headingTracking: Knob.length('em')({\n title: 'Heading tracking',\n variable: 'heading-tracking',\n default: -0.025,\n min: -0.05,\n max: 0.05,\n step: 0.005,\n description:\n 'Headings’ letter spacing, in em: negative draws letters together, positive spreads them.',\n }),\n scale: Knob.number({\n title: 'Text size',\n variable: 'text-scale',\n default: 1.025,\n min: 0.8,\n max: 1.3,\n step: 0.025,\n description: 'Multiplies every text size, headings and body alike.',\n }),\n headingScale: Knob.number({\n title: 'Heading scale',\n variable: 'heading-scale',\n default: 1.2,\n min: 0.4,\n max: 1.8,\n step: 0.05,\n description:\n 'How far headings stand above body text: below 1 nearer its size, above 1 larger.',\n }),\n leading: Knob.number({\n title: 'Line height',\n variable: 'leading',\n default: 1.05,\n min: 0.85,\n max: 1.3,\n step: 0.05,\n description: 'Multiplies line height, the space each line of text takes.',\n }),\n fluid: Knob.number({\n title: 'Fluid type',\n variable: 'fluid',\n default: 1,\n min: 0,\n max: 1,\n step: 0.05,\n description:\n 'How much larger type grows between the small and large viewport. 0 keeps one size; 1 uses the whole range.',\n }),\n viewportMin: Knob.length('px')({\n title: 'Small viewport',\n variable: 'fluid-viewport-min',\n default: 320,\n min: 240,\n max: 800,\n step: 10,\n description: 'The viewport where every fluid size is its smallest, in px.',\n }),\n viewportMax: Knob.length('px')({\n title: 'Large viewport',\n variable: 'fluid-viewport-max',\n default: 1440,\n min: 900,\n max: 2560,\n step: 10,\n description: 'The viewport where every fluid size is its largest, in px.',\n }),\n },\n reading: {\n measure: Knob.length('ch')({\n title: 'Reading measure',\n variable: 'measure',\n default: 68,\n min: 30,\n max: 100,\n step: 1,\n description:\n 'The widest a line of reading text may run, in ch. Around 65 is a book’s measure; wider is harder to track back from.',\n }),\n headingWrap: Knob.choice({\n title: 'Heading wrap',\n default: 'balance',\n options: {\n balance: { 'heading-wrap': 'balance' },\n pretty: { 'heading-wrap': 'pretty' },\n wrap: { 'heading-wrap': 'wrap' },\n },\n description:\n 'How a heading breaks across lines: balanced lines, a prettier last line, or the browser’s ordinary wrap.',\n }),\n bodyWrap: Knob.choice({\n title: 'Body wrap',\n default: 'pretty',\n options: {\n pretty: { 'body-wrap': 'pretty' },\n wrap: { 'body-wrap': 'wrap' },\n balance: { 'body-wrap': 'balance' },\n },\n description:\n 'How body copy breaks: a prettier last line, the browser’s ordinary wrap, or balanced lines.',\n }),\n align: Knob.choice({\n title: 'Reading alignment',\n default: 'start',\n options: {\n start: { 'reading-align': 'start' },\n center: { 'reading-align': 'center' },\n end: { 'reading-align': 'end' },\n justify: { 'reading-align': 'justify' },\n },\n description:\n 'The alignment of reading text: start, centered, end, or justified. Start follows the writing direction.',\n }),\n },\n icon: {\n size: Knob.number({\n title: 'Icon size',\n variable: 'icon-scale',\n default: 1,\n min: 0.75,\n max: 1.5,\n step: 0.05,\n description:\n 'Multiplies every icon a component draws, beside its words: 1 is 16px, or 14px compact.',\n }),\n stroke: Knob.length('px')({\n title: 'Glyph stroke',\n variable: 'glyph-width',\n default: 2,\n min: 1,\n max: 3,\n step: 0.25,\n description:\n 'The width of the strokes components draw themselves: checks, chevrons, a tree’s guides. An icon pack keeps its own.',\n }),\n },\n motion: {\n scale: Knob.number({\n title: 'Motion',\n variable: 'motion',\n default: 0.5,\n min: 0,\n max: 2,\n step: 0.1,\n description: 'Multiplies how long every transition takes. 0 stills them; 2 is twice as slow.',\n }),\n easing: Knob.choice({\n title: 'Easing',\n default: 'spring',\n options: { ease: { ease: 'ease-out' }, spring: { ease: ref('motion', 'spring') } },\n description: 'How transitions move: along an easing curve, or on a spring that settles.',\n }),\n },\n shadow: {\n style: Knob.choice({\n title: 'Shadows',\n default: 'soft',\n options: {\n soft: asVariables('shadow', elevation.soft),\n hard: asVariables('shadow', elevation.hard),\n },\n description: 'Shadows that diffuse softly, or hard, solid offset copies.',\n }),\n relief: Knob.choice({\n title: 'Controls',\n default: 'flat',\n options: {\n flat: asVariables('relief', reliefs.flat),\n soft: asVariables('relief', reliefs.soft),\n hard: asVariables('relief', reliefs.hard),\n bevel: asVariables('relief', reliefs.bevel),\n },\n description:\n 'How buttons stand off the page and fields sink into it: flat, or a soft, hard or bevelled edge.',\n }),\n strength: Knob.percent({\n title: 'Shadow',\n variable: 'shadow-strength',\n default: 0,\n min: 0,\n max: 100,\n step: 1,\n description: 'How strong shadows are. 0 removes them.',\n }),\n hue: Knob.angle({\n title: 'Shadow hue',\n variable: 'shadow-h',\n default: 235,\n follows: ref('hue', 'neutral'),\n min: 0,\n max: 360,\n description: 'The hue every shadow is tinted with. Unset, the neutrals’.',\n }),\n chroma: Knob.number({\n title: 'Shadow tint',\n variable: 'shadow-c',\n default: 0,\n follows: `calc(${ref('knob', 'surface-c')} * 2)`,\n min: 0,\n max: 0.1,\n step: 0.005,\n description: 'How tinted every shadow is. Unset, twice the surfaces’ saturation.',\n }),\n },\n menu: {\n highlight: Knob.choice({\n title: 'Menu accent',\n default: 'subtle',\n options: { subtle: { 'popup-bold': '0' }, bold: { 'popup-bold': '1' } },\n description:\n 'How the highlighted row of a menu shows: a subtle tint, or filled with the accent.',\n }),\n panel: Knob.choice({\n title: 'Menu color',\n default: 'inverted',\n options: {\n default: { 'popup-invert': '0', 'popup-alpha': '1', 'popup-blur': '0px' },\n inverted: { 'popup-invert': '1', 'popup-alpha': '1', 'popup-blur': '0px' },\n translucent: { 'popup-invert': '0', 'popup-alpha': '0.8', 'popup-blur': '12px' },\n 'inverted-translucent': { 'popup-invert': '1', 'popup-alpha': '0.8', 'popup-blur': '12px' },\n },\n description:\n 'The background of menus and popovers: the page’s, inverted (dark on a light page), or translucent, the page blurred behind it.',\n }),\n },\n feedback: {\n success: hue('success-h', 145, 'Success', 'The hue of success: a saved form, a passing check.'),\n warning: hue('warning-h', 75, 'Warning', 'The hue of a warning.'),\n error: hue('error-h', 25, 'Error', 'The hue of an error: a refused field, a failed save.'),\n info: hue('info-h', 245, 'Info', 'The hue of a neutral notice.'),\n },\n code: {\n chroma: Knob.number({\n title: 'Code chroma',\n variable: 'syntax-c',\n default: 0.14,\n min: 0,\n max: 0.4,\n step: 0.01,\n description: 'How vivid code’s colors are.',\n }),\n },\n chart: {\n hue: hue(\n 'chart-h',\n 255,\n 'Chart hue',\n 'The first chart series’ hue; the other four keep their places around it.',\n ),\n },\n scales: {\n chroma: Knob.number({\n title: 'Scale vividness',\n variable: 'scale-c',\n default: 1.1,\n min: 0,\n max: 1.5,\n step: 0.05,\n description:\n 'How vivid the seven color scales are, as a share of each step’s own. 0 turns them grey.',\n }),\n red: hue('red-h', 25, 'Red', 'The red scale’s hue.'),\n orange: hue('orange-h', 55, 'Orange', 'The orange scale’s hue.'),\n yellow: hue('yellow-h', 90, 'Yellow', 'The yellow scale’s hue.'),\n green: hue('green-h', 145, 'Green', 'The green scale’s hue.'),\n teal: hue('teal-h', 185, 'Teal', 'The teal scale’s hue.'),\n blue: hue('blue-h', 255, 'Blue', 'The blue scale’s hue.'),\n purple: hue('purple-h', 300, 'Purple', 'The purple scale’s hue.'),\n },\n} as const satisfies KnobSet\n\nexport type Standard = typeof standard\n\n/** A theme: the knobs it may set, the values it sets, and what it is called in a list. */\nexport interface KnobTheme<S extends KnobSet = Standard> extends Pipeable<KnobTheme<S>> {\n readonly knobs: S\n readonly values: Values<S>\n readonly title: Option.Option<string>\n readonly description: Option.Option<string>\n}\n\nconst theme = <S extends KnobSet>(\n knobs: S,\n values: Values<S>,\n title: Option.Option<string>,\n description: Option.Option<string>,\n): KnobTheme<S> => ({\n knobs,\n values,\n title,\n description,\n pipe(...fns: ReadonlyArray<(self: KnobTheme<S>) => KnobTheme<S>>) {\n return pipeSelf(this, fns) as KnobTheme<S>\n },\n})\n\n/** The call a refusal names: a theme is usually built at module load, where a stack names only the module. */\ntype Caller = 'Theme.make' | 'Theme.set' | 'Knobs.withValue'\n\nconst unknownKnob = (caller: Caller, knob: string): DiagnosticError =>\n new DiagnosticError({\n source: 'theme',\n code: 'theme:unknown-knob',\n severity: 'error',\n message: `${caller}: no knob \"${knob}\".`,\n details: { knob },\n })\n\n/** Throws, naming the knob and the call, when `knob` refuses `value`. */\nconst checkValue = (caller: Caller, path: string, knob: Knob.Knob<unknown>, value: unknown) => {\n const decoded = Schema.decodeUnknownExit(knob.schema)(value)\n if (Exit.isSuccess(decoded)) return\n throw new DiagnosticError({\n source: 'theme',\n code: 'theme:knob-value',\n severity: 'error',\n message: `${caller}: ${path} refuses its value: ${Cause.pretty(decoded.cause)}`,\n details: { knob: path, value },\n })\n}\n\n/** Each value checked against its knob: an unknown group or knob, or a value out of range, throws. */\nconst checked = <S extends KnobSet>(caller: Caller, knobs: S, values: Values<S>): Values<S> => {\n for (const [group, names] of Object.entries(values)) {\n if (!Object.hasOwn(knobs, group)) throw unknownKnob(caller, group)\n for (const [name, value] of Object.entries(names ?? {})) {\n const path = `${group}.${name}`\n if (!Object.hasOwn(knobs[group]!, name)) throw unknownKnob(caller, path)\n checkValue(caller, path, knobs[group]![name]!, value)\n }\n }\n return values\n}\n\n/** What `values` set the knob `group.name` to, read from their own keys alone. */\nconst setIn = (values: object, group: string, name: string): unknown =>\n own(own(values as Readonly<Record<string, Readonly<Record<string, unknown>>>>, group), name)\n\nconst valueOf = <S extends KnobSet>(\n knobs: S,\n values: Values<S>,\n group: string,\n name: string,\n): unknown => {\n const set = (values[group] as Readonly<Record<string, unknown>> | undefined)?.[name]\n return (\n set ??\n (knobs[group] as Readonly<Record<string, Knob.Knob<unknown>>> | undefined)?.[name]?.default\n )\n}\n\n/**\n * A cross-knob rule each knob's schema cannot state: the fluid range's two\n * halves must not cross. Read from the merged values, each unset half from its\n * knob's default, so `Theme.set` and `Theme.make` both refuse an inverted range.\n */\nconst validate = <S extends KnobSet>(knobs: S, values: Values<S>): void => {\n const group = knobs['type'] as Readonly<Record<string, Knob.Knob<unknown>>> | undefined\n if (\n group === undefined ||\n !Object.hasOwn(group, 'viewportMin') ||\n !Object.hasOwn(group, 'viewportMax')\n )\n return\n const min = valueOf(knobs, values, 'type', 'viewportMin')\n const max = valueOf(knobs, values, 'type', 'viewportMax')\n if (typeof min !== 'number' || typeof max !== 'number' || min < max) return\n throw new DiagnosticError({\n source: 'theme',\n code: 'theme:fluid-range',\n severity: 'error',\n message: `Theme: type.viewportMin (${min}px) must be less than type.viewportMax (${max}px).`,\n details: { min, max },\n })\n}\n\n/**\n * A theme of the standard knobs, or of `knobs`: the values it sets, checked,\n * every other knob keeping its default. A misspelt knob or a choice outside\n * its options is a type error; a number out of its range throws here.\n */\nexport function make(values: Values<Standard>): KnobTheme<Standard>\nexport function make<S extends KnobSet>(knobs: S, values: Values<NoInfer<S>>): KnobTheme<S>\nexport function make(...args: [Values<Standard>] | [KnobSet, Values<KnobSet>]): KnobTheme<KnobSet> {\n const [knobs, values] = args.length === 1 ? [standard, args[0]] : args\n const checkedValues = checked('Theme.make', knobs, values)\n validate(knobs, checkedValues)\n return theme(knobs, checkedValues, Option.none(), Option.none())\n}\n\n/** `theme` with `values` over its own, group by group. */\nexport const set =\n <S extends KnobSet>(values: Values<NoInfer<S>>) =>\n (self: KnobTheme<S>): KnobTheme<S> => {\n const merged: Record<string, Record<string, unknown>> = Object.create(null)\n for (const source of [self.values, checked('Theme.set', self.knobs, values)])\n for (const [group, names] of Object.entries(source))\n merged[group] = { ...merged[group], ...names }\n validate(self.knobs, merged as Values<S>)\n return theme(self.knobs, merged as Values<S>, self.title, self.description)\n }\n\n/** A title and a description for a list of themes; neither is the theme's identity. */\nexport const describe =\n (meta: { readonly title?: string; readonly description?: string }) =>\n <S extends KnobSet>(self: KnobTheme<S>): KnobTheme<S> =>\n theme(\n self.knobs,\n self.values,\n meta.title === undefined ? self.title : Option.some(meta.title),\n meta.description === undefined ? self.description : Option.some(meta.description),\n )\n\n/**\n * Every knob variable `self` declares: the values it sets, every other knob's\n * unset value, and the sRGB boundary of each palette hue they place.\n */\nexport const variables = <S extends KnobSet>(self: KnobTheme<S>): Knob.Variables => {\n const declared: Record<string, string> = {}\n for (const [group, knobs] of Object.entries(self.knobs))\n for (const [name, knob] of Object.entries(knobs)) {\n const value = setIn(self.values, group, name)\n Object.assign(declared, knob.unset, value === undefined ? {} : knob.write(value))\n }\n return Object.assign(declared, boundaryVariables(declared))\n}\n\ntype Intersected<U> = (U extends unknown ? (union: U) => void : never) extends (\n meet: infer I,\n) => void\n ? I\n : never\n\n/** What every knob of `knobs` writes unset, under its variables' own names. */\nexport const unsetOf = <S extends KnobSet>(\n knobs: S,\n): Intersected<{ [G in keyof S]: { [K in keyof S[G]]: S[G][K]['unset'] }[keyof S[G]] }[keyof S]> =>\n Object.assign(\n {},\n ...Object.values(knobs).flatMap(group => Object.values(group).map(knob => knob.unset)),\n )\n\n/** `self`'s knob variables as tokens, for `Theme.root` and `Theme.scoped`. */\nexport const tokensOf = <S extends KnobSet>(self: KnobTheme<S>) => define({ knob: variables(self) })\n\n/**\n * The Schema of a theme's values over `knobs`: each group and knob optional,\n * each value checked by its knob, for a Model field or a decoded URL. Decode\n * with `onExcessProperty: 'error'` where an unknown key must be refused\n * rather than dropped.\n */\nexport const schemaOf = <S extends KnobSet>(knobs: S): Schema.Codec<Values<S>> =>\n // Built from `knobs` group by group, so its type is `Values<S>` by construction.\n Schema.Struct(\n Object.fromEntries(\n Object.entries(knobs).map(([group, names]) => [\n group,\n Schema.optionalKey(\n Schema.Struct(\n Object.fromEntries(\n Object.entries(names).map(([name, knob]) => [name, Schema.optionalKey(knob.schema)]),\n ),\n ),\n ),\n ]),\n ),\n ) as unknown as Schema.Codec<Values<S>>\n\nconst literal = (value: unknown): string =>\n typeof value === 'string'\n ? `'${value.replaceAll('\\\\', '\\\\\\\\').replaceAll(\"'\", \"\\\\'\")}'`\n : typeof value === 'object' && value !== null\n ? `{ ${Object.entries(value)\n .map(([key, each]) => `${key}: ${literal(each)}`)\n .join(', ')} }`\n : String(value)\n\n/**\n * Whether `value` changes nothing the knob writes unset: a bare `0.17` for a\n * schemed knob whose dark half follows is its default, though it is no\n * `{ light, dark }`.\n */\nconst atDefault = (knob: Knob.Knob<unknown>, value: unknown): boolean =>\n Object.entries(knob.write(value)).every(([name, css]) => knob.unset[name] === css)\n\n/**\n * The source of `self` as `Theme.make({ … })`: each knob it sets that writes\n * other than the knob's default does, a group to a line (a knob a line past\n * a hundred characters), so the code an application\n * pastes says only what makes the theme its own.\n */\nexport const print = <S extends KnobSet>(self: KnobTheme<S>): string => {\n const groups = Object.entries(self.knobs).flatMap(([group, knobs]) => {\n const set = Object.entries(knobs).flatMap(([name, knob]) => {\n const value = setIn(self.values, group, name)\n return value === undefined || atDefault(knob, value) ? [] : [`${name}: ${literal(value)}`]\n })\n if (set.length === 0) return []\n const line = ` ${group}: { ${set.join(', ')} },`\n // A group past the width a formatter keeps breaks to a knob a line, as one would.\n return line.length <= 100\n ? [line]\n : [` ${group}: {`, ...set.map(each => ` ${each},`), ' },']\n })\n return groups.length === 0 ? 'Theme.make({})' : ['Theme.make({', ...groups, '})'].join('\\n')\n}\n\n/** One knob of `S`, by its group and name: `shape.radius`. */\nexport type PathOf<S extends KnobSet> = {\n readonly [G in keyof S & string]: `${G}.${keyof S[G] & string}`\n}[keyof S & string]\n\n/** The knob of `S` at `P`. */\nexport type KnobAt<S extends KnobSet, P extends PathOf<S>> = P extends `${infer G}.${infer N}`\n ? G extends keyof S\n ? N extends keyof S[G]\n ? S[G][N]\n : never\n : never\n : never\n\nconst split = (path: string): readonly [string, string] => {\n const dot = path.indexOf('.')\n return [path.slice(0, dot), path.slice(dot + 1)]\n}\n\n/** Every knob's path in `knobs`, in the order they are declared. */\nexport const paths = <S extends KnobSet>(knobs: S): ReadonlyArray<PathOf<S>> =>\n Object.entries(knobs).flatMap(([group, names]) =>\n Object.keys(names).map(name => `${group}.${name}`),\n ) as ReadonlyArray<PathOf<S>>\n\n/** The knob at `path`. */\nexport const at = <S extends KnobSet, P extends PathOf<S>>(knobs: S, path: P): KnobAt<S, P> => {\n const [group, name] = split(path)\n return knobs[group]![name] as KnobAt<S, P>\n}\n\n/** What `values` set the knob at `path` to, or its default. */\nexport const valueAt = <S extends KnobSet, P extends PathOf<S>>(\n knobs: S,\n values: Values<S>,\n path: P,\n): ValueOf<KnobAt<S, P>> => {\n const [group, name] = split(path)\n return (setIn(values, group, name) ?? at(knobs, path).default) as ValueOf<KnobAt<S, P>>\n}\n\n/** `values` with the knob at `path` set to `value`, checked by the knob as `make` checks it. */\nexport const withValue = <S extends KnobSet, P extends PathOf<S>>(\n knobs: S,\n values: Values<S>,\n path: P,\n value: ValueOf<KnobAt<S, P>>,\n): Values<S> => {\n const [group, name] = split(path)\n checkValue('Knobs.withValue', path, at(knobs, path), value)\n const next = { ...values, [group]: { ...values[group], [name]: value } } as Values<S>\n validate(knobs, next)\n return next\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAMA,SACJ,UACA,OACA,OACA,gBAC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AAC,CAAC,KAAK,IAAI;AAC7F;AAgBA,MAAM,SAAS,SAA4C;CACzD,MAAM,MAAM,KAAK,QAAQ,GAAG;CAC5B,OAAO,CAAC,KAAK,MAAM,GAAG,GAAG,GAAG,KAAK,MAAM,MAAM,CAAC,CAAC;AACjD;;AAGA,MAAa,SAA4B,UACvC,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,CAAC,OAAO,WACrC,OAAO,KAAK,KAAK,CAAC,CAAC,KAAI,SAAQ,GAAG,MAAM,GAAG,MAAM,CACnD;;AAGF,MAAa,MAA8C,OAAU,SAA0B;CAC7F,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,OAAO,MAAM,MAAM,CAAE;AACvB;;AAGA,MAAa,WACX,OACA,QACA,SAC0B;CAC1B,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,OAAQ,MAAM,QAAQ,OAAO,IAAI,KAAK,GAAG,OAAO,IAAI,CAAC,CAAC;AACxD;;AAGA,MAAa,aACX,OACA,QACA,MACA,UACc;CACd,MAAM,CAAC,OAAO,QAAQ,MAAM,IAAI;CAChC,WAAW,mBAAmB,MAAM,GAAG,OAAO,IAAI,GAAG,KAAK;CAC1D,MAAM,OAAO;EAAE,GAAG;GAAS,QAAQ;GAAE,GAAG,OAAO;IAAS,OAAO;EAAM;CAAE;CACvE,SAAS,OAAO,IAAI;CACpB,OAAO;AACT"}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
export interface StylesOptions {
|
|
3
|
+
/** A module id (as an import would write it) that exports the application's stylesheet text as `stylesheet`. */
|
|
4
|
+
readonly sheet: string;
|
|
5
|
+
}
|
|
6
|
+
/** The plugin: see the module's comment. */
|
|
7
|
+
export declare const styles: (options: StylesOptions) => Plugin;
|
|
8
|
+
//# sourceMappingURL=vite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","names":[],"sources":["../src/vite.ts"],"mappings":";iBAuBiB;;WAEN;;;qBAuEE,SAAM,SAAa,kBAAgB"}
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
// src/vite.ts
|
|
3
|
+
/**
|
|
4
|
+
* `foldkit-mixins/vite`: the application's stylesheet as a file. A server
|
|
5
|
+
* that writes the sheet into every page sends it every time and has its
|
|
6
|
+
* framework parse it again to check the page; a hashed file is fetched once
|
|
7
|
+
* and cached. The plugin builds the sheet module, writes `assets/styles-<hash>.css`
|
|
8
|
+
* into the browser build, and gives the server entry its address:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { href } from 'virtual:foldkit-styles'
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* In dev the same `href` serves the sheet from the dev server, so the server
|
|
15
|
+
* entry has one code path.
|
|
16
|
+
*/
|
|
17
|
+
const VIRTUAL = "virtual:foldkit-styles";
|
|
18
|
+
const SHEET = "virtual:foldkit-styles-sheet";
|
|
19
|
+
const NUL = String.fromCharCode(0);
|
|
20
|
+
const DEV_PATH = "/__foldkit-styles.css";
|
|
21
|
+
/** The module the plugin builds: the sheet, completed with every class its modules compiled. */
|
|
22
|
+
const sheetSource = (sheet) => [
|
|
23
|
+
`import { stylesheet } from ${JSON.stringify(sheet)}`,
|
|
24
|
+
`import { Style } from 'foldkit-mixins'`,
|
|
25
|
+
`export const css = Style.complete(stylesheet)`
|
|
26
|
+
].join("\n");
|
|
27
|
+
const sheetModule = (sheet) => ({
|
|
28
|
+
name: "foldkit-mixins:styles-sheet",
|
|
29
|
+
resolveId: (id) => id === SHEET ? NUL + SHEET : void 0,
|
|
30
|
+
load: (id) => id === NUL + SHEET ? sheetSource(sheet) : void 0
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* The sheet's CSS, from a build of the sheet module on its own that runs here:
|
|
34
|
+
* bundled whole, so an import of a file (`?url`) is the same hashed address the
|
|
35
|
+
* browser build gives it, which the running dev server's address would not be.
|
|
36
|
+
*/
|
|
37
|
+
const buildSheet = async (config, sheet) => {
|
|
38
|
+
const { build } = await import("vite");
|
|
39
|
+
const chunk = [await build({
|
|
40
|
+
configFile: false,
|
|
41
|
+
root: config.root,
|
|
42
|
+
mode: config.mode,
|
|
43
|
+
base: config.base,
|
|
44
|
+
logLevel: "silent",
|
|
45
|
+
resolve: {
|
|
46
|
+
conditions: config.resolve.conditions,
|
|
47
|
+
alias: config.resolve.alias
|
|
48
|
+
},
|
|
49
|
+
ssr: {
|
|
50
|
+
noExternal: true,
|
|
51
|
+
resolve: { conditions: config.ssr.resolve?.conditions ?? config.resolve.conditions }
|
|
52
|
+
},
|
|
53
|
+
plugins: [sheetModule(sheet)],
|
|
54
|
+
build: {
|
|
55
|
+
ssr: true,
|
|
56
|
+
rollupOptions: {
|
|
57
|
+
input: SHEET,
|
|
58
|
+
treeshake: false
|
|
59
|
+
},
|
|
60
|
+
write: false,
|
|
61
|
+
minify: false,
|
|
62
|
+
emptyOutDir: false,
|
|
63
|
+
assetsInlineLimit: config.build.assetsInlineLimit
|
|
64
|
+
}
|
|
65
|
+
})].flat().flatMap((result) => "output" in result ? result.output : [])[0];
|
|
66
|
+
if (chunk === void 0 || chunk.type !== "chunk") throw new Error(`foldkit-mixins/vite: building "${sheet}" produced no module`);
|
|
67
|
+
const loaded = await import(
|
|
68
|
+
/* @vite-ignore */
|
|
69
|
+
`data:text/javascript;base64,${Buffer.from(chunk.code).toString("base64")}`
|
|
70
|
+
);
|
|
71
|
+
const css = typeof loaded === "object" && loaded !== null && "css" in loaded ? loaded.css : void 0;
|
|
72
|
+
if (typeof css !== "string") throw new Error(`foldkit-mixins/vite: "${sheet}" does not export its stylesheet text as \`stylesheet\``);
|
|
73
|
+
return css;
|
|
74
|
+
};
|
|
75
|
+
/** The plugin: see the module's comment. */
|
|
76
|
+
const styles = (options) => {
|
|
77
|
+
let config;
|
|
78
|
+
let dev;
|
|
79
|
+
let devCss;
|
|
80
|
+
let built;
|
|
81
|
+
const build = () => built ??= buildSheet(config, options.sheet).then((css) => {
|
|
82
|
+
const fileName = `assets/styles-${createHash("sha256").update(css).digest("hex").slice(0, 8)}.css`;
|
|
83
|
+
return {
|
|
84
|
+
css,
|
|
85
|
+
fileName,
|
|
86
|
+
href: `${config.base}${fileName}`
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
name: "foldkit-mixins:styles",
|
|
91
|
+
sharedDuringBuild: true,
|
|
92
|
+
configResolved(resolved) {
|
|
93
|
+
config = resolved;
|
|
94
|
+
if (resolved.command === "build" && !/^(\/|https?:\/\/)/.test(resolved.base)) throw new Error(`foldkit-mixins/vite: base "${resolved.base}" is relative, so the sheet's address would depend on the page; give base an absolute path or URL`);
|
|
95
|
+
},
|
|
96
|
+
configureServer(server) {
|
|
97
|
+
dev = server;
|
|
98
|
+
server.watcher.on("change", () => {
|
|
99
|
+
devCss = void 0;
|
|
100
|
+
});
|
|
101
|
+
server.middlewares.use(DEV_PATH, (_request, response, next) => {
|
|
102
|
+
devCss ??= server.ssrLoadModule(SHEET).then((loaded) => String(loaded.css));
|
|
103
|
+
devCss.then((css) => {
|
|
104
|
+
response.setHeader("content-type", "text/css; charset=utf-8");
|
|
105
|
+
response.setHeader("cache-control", "no-cache");
|
|
106
|
+
response.end(css);
|
|
107
|
+
}, (error) => {
|
|
108
|
+
devCss = void 0;
|
|
109
|
+
next(error);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
},
|
|
113
|
+
buildStart() {
|
|
114
|
+
if (this.environment.name === "client") built = void 0;
|
|
115
|
+
},
|
|
116
|
+
resolveId(id) {
|
|
117
|
+
if (id === VIRTUAL) return NUL + VIRTUAL;
|
|
118
|
+
if (id === SHEET && dev !== void 0) return NUL + SHEET;
|
|
119
|
+
},
|
|
120
|
+
async load(id) {
|
|
121
|
+
if (id === NUL + SHEET) return sheetSource(options.sheet);
|
|
122
|
+
if (id !== NUL + VIRTUAL) return void 0;
|
|
123
|
+
const href = dev === void 0 ? (await build()).href : DEV_PATH;
|
|
124
|
+
return `export const href = ${JSON.stringify(href)}`;
|
|
125
|
+
},
|
|
126
|
+
async generateBundle() {
|
|
127
|
+
if (this.environment.name !== "client") return;
|
|
128
|
+
const { css, fileName } = await build();
|
|
129
|
+
this.emitFile({
|
|
130
|
+
type: "asset",
|
|
131
|
+
fileName,
|
|
132
|
+
source: css
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export { styles };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["/**\n * `foldkit-mixins/vite`: the application's stylesheet as a file. A server\n * that writes the sheet into every page sends it every time and has its\n * framework parse it again to check the page; a hashed file is fetched once\n * and cached. The plugin builds the sheet module, writes `assets/styles-<hash>.css`\n * into the browser build, and gives the server entry its address:\n *\n * ```ts\n * import { href } from 'virtual:foldkit-styles'\n * ```\n *\n * In dev the same `href` serves the sheet from the dev server, so the server\n * entry has one code path.\n */\nimport { createHash } from 'node:crypto'\nimport type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'\n\nconst VIRTUAL = 'virtual:foldkit-styles'\nconst SHEET = 'virtual:foldkit-styles-sheet'\n// Rollup's mark for a module no file holds, which other plugins leave alone.\nconst NUL = String.fromCharCode(0)\nconst DEV_PATH = '/__foldkit-styles.css'\n\nexport interface StylesOptions {\n /** A module id (as an import would write it) that exports the application's stylesheet text as `stylesheet`. */\n readonly sheet: string\n}\n\n/** The module the plugin builds: the sheet, completed with every class its modules compiled. */\nconst sheetSource = (sheet: string): string =>\n [\n `import { stylesheet } from ${JSON.stringify(sheet)}`,\n `import { Style } from 'foldkit-mixins'`,\n `export const css = Style.complete(stylesheet)`,\n ].join('\\n')\n\nconst sheetModule = (sheet: string): Plugin => ({\n name: 'foldkit-mixins:styles-sheet',\n resolveId: id => (id === SHEET ? NUL + SHEET : undefined),\n load: id => (id === NUL + SHEET ? sheetSource(sheet) : undefined),\n})\n\n/**\n * The sheet's CSS, from a build of the sheet module on its own that runs here:\n * bundled whole, so an import of a file (`?url`) is the same hashed address the\n * browser build gives it, which the running dev server's address would not be.\n */\nconst buildSheet = async (config: ResolvedConfig, sheet: string): Promise<string> => {\n const { build } = await import('vite')\n const output = await build({\n configFile: false,\n root: config.root,\n mode: config.mode,\n base: config.base,\n logLevel: 'silent',\n resolve: { conditions: config.resolve.conditions, alias: config.resolve.alias },\n ssr: {\n noExternal: true,\n resolve: { conditions: config.ssr.resolve?.conditions ?? config.resolve.conditions },\n },\n plugins: [sheetModule(sheet)],\n build: {\n ssr: true,\n // Compiling a Style registers its class as a side effect, and a module\n // imported only for that has no export in use: treeshaking would drop\n // it (a package's `sideEffects: false`, or an unused call's result)\n // before it ran, and its classes would be missing from the sheet.\n rollupOptions: { input: SHEET, treeshake: false },\n write: false,\n minify: false,\n emptyOutDir: false,\n assetsInlineLimit: config.build.assetsInlineLimit,\n },\n })\n const chunk = [output].flat().flatMap(result => ('output' in result ? result.output : []))[0]\n if (chunk === undefined || chunk.type !== 'chunk')\n throw new Error(`foldkit-mixins/vite: building \"${sheet}\" produced no module`)\n const loaded: unknown = await import(\n /* @vite-ignore */ `data:text/javascript;base64,${Buffer.from(chunk.code).toString('base64')}`\n )\n const css =\n typeof loaded === 'object' && loaded !== null && 'css' in loaded ? loaded.css : undefined\n if (typeof css !== 'string')\n throw new Error(\n `foldkit-mixins/vite: \"${sheet}\" does not export its stylesheet text as \\`stylesheet\\``,\n )\n return css\n}\n\ninterface Built {\n readonly css: string\n readonly fileName: string\n readonly href: string\n}\n\n/** The plugin: see the module's comment. */\nexport const styles = (options: StylesOptions): Plugin => {\n let config: ResolvedConfig\n let dev: ViteDevServer | undefined\n let devCss: Promise<string> | undefined\n let built: Promise<Built> | undefined\n\n const build = (): Promise<Built> =>\n (built ??= buildSheet(config, options.sheet).then(css => {\n const fileName = `assets/styles-${createHash('sha256').update(css).digest('hex').slice(0, 8)}.css`\n return { css, fileName, href: `${config.base}${fileName}` }\n }))\n\n return {\n name: 'foldkit-mixins:styles',\n sharedDuringBuild: true,\n configResolved(resolved) {\n config = resolved\n if (resolved.command === 'build' && !/^(\\/|https?:\\/\\/)/.test(resolved.base)) {\n throw new Error(\n `foldkit-mixins/vite: base \"${resolved.base}\" is relative, so the sheet's address would depend on the page; give base an absolute path or URL`,\n )\n }\n },\n configureServer(server) {\n dev = server\n // The sheet is read from the modules the server has loaded, so an edit means reading it again.\n server.watcher.on('change', () => {\n devCss = undefined\n })\n server.middlewares.use(DEV_PATH, (_request, response, next) => {\n devCss ??= server.ssrLoadModule(SHEET).then(loaded => String(loaded.css))\n devCss.then(\n css => {\n response.setHeader('content-type', 'text/css; charset=utf-8')\n response.setHeader('cache-control', 'no-cache')\n response.end(css)\n },\n error => {\n devCss = undefined\n next(error)\n },\n )\n })\n },\n buildStart() {\n if (this.environment.name === 'client') built = undefined\n },\n resolveId(id) {\n if (id === VIRTUAL) return NUL + VIRTUAL\n // The dev server loads the sheet through this plugin; a build loads it through its own.\n if (id === SHEET && dev !== undefined) return NUL + SHEET\n return undefined\n },\n async load(id) {\n if (id === NUL + SHEET) return sheetSource(options.sheet)\n if (id !== NUL + VIRTUAL) return undefined\n const href = dev === undefined ? (await build()).href : DEV_PATH\n return `export const href = ${JSON.stringify(href)}`\n },\n async generateBundle() {\n // The browser build comes first, and is the one a host serves files from.\n if (this.environment.name !== 'client') return\n const { css, fileName } = await build()\n this.emitFile({ type: 'asset', fileName, source: css })\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAM,UAAU;AAChB,MAAM,QAAQ;AAEd,MAAM,MAAM,OAAO,aAAa,CAAC;AACjC,MAAM,WAAW;;AAQjB,MAAM,eAAe,UAC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ACjC,MAAM,OAAO,QAAQ,KAAA,KAAa,MAAM,MAAM,EAAA,CAAG,OAAO;GACxD,OAAO,uBAAuB,KAAK,UAAU,IAAI;EACnD;EACA,MAAM,iBAAiB;GAErB,IAAI,KAAK,YAAY,SAAS,UAAU;GACxC,MAAM,EAAE,KAAK,aAAa,MAAM,MAAM;GACtC,KAAK,SAAS;IAAE,MAAM;IAAS;IAAU,QAAQ;GAAI,CAAC;EACxD;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-mixins",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "Typed slot contracts and inside-out Style/Behavior attachments for Foldkit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"foldkit",
|
|
@@ -77,6 +77,11 @@
|
|
|
77
77
|
"types": "./dist/foundations.d.ts",
|
|
78
78
|
"import": "./dist/foundations.js"
|
|
79
79
|
},
|
|
80
|
+
"./vite": {
|
|
81
|
+
"foldkit-plus:source": "./src/vite.ts",
|
|
82
|
+
"types": "./dist/vite.d.ts",
|
|
83
|
+
"import": "./dist/vite.js"
|
|
84
|
+
},
|
|
80
85
|
"./package.json": "./package.json"
|
|
81
86
|
},
|
|
82
87
|
"files": [
|
|
@@ -86,7 +91,13 @@
|
|
|
86
91
|
],
|
|
87
92
|
"peerDependencies": {
|
|
88
93
|
"effect": "^4.1.0",
|
|
89
|
-
"foldkit": "^0.170.0"
|
|
94
|
+
"foldkit": "^0.170.0",
|
|
95
|
+
"vite": "^8.0.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"vite": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
90
101
|
},
|
|
91
102
|
"devDependencies": {
|
|
92
103
|
"@effect/platform-browser": "^4.1.1",
|
|
@@ -98,7 +109,7 @@
|
|
|
98
109
|
},
|
|
99
110
|
"dependencies": {
|
|
100
111
|
"csstype": "^3.2.3",
|
|
101
|
-
"foldkit-surface": "0.
|
|
112
|
+
"foldkit-surface": "0.13.0"
|
|
102
113
|
},
|
|
103
114
|
"scripts": {
|
|
104
115
|
"build": "node ../../scripts/declarations.mjs . && tsdown && node ../../scripts/declared-any.mjs .",
|