foldkit-mixins 0.7.0 → 0.8.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 +7 -0
- package/dist/app.mjs +6 -6
- package/dist/{core-Bxj0UQDF.mjs → core-IMVYU8JN.mjs} +2 -2
- package/dist/{core-Bxj0UQDF.mjs.map → core-IMVYU8JN.mjs.map} +1 -1
- package/dist/defaults.d.mts.map +1 -1
- package/dist/defaults.mjs +2 -2
- package/dist/defaults.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/{layers-B31M0tDi.mjs → layers-keV38soP.mjs} +2 -2
- package/dist/{layers-B31M0tDi.mjs.map → layers-keV38soP.mjs.map} +1 -1
- package/dist/layers.mjs +1 -1
- package/dist/layout.mjs +1 -1
- package/dist/oklch-FOemcYSv.d.mts.map +1 -1
- package/dist/prose.mjs +1 -1
- package/dist/{root-C1u12YMD.mjs → root-BBi88KYx.mjs} +3 -3
- package/dist/{root-C1u12YMD.mjs.map → root-BBi88KYx.mjs.map} +1 -1
- package/dist/{slotMark-Rdsjb7XI.mjs → slotMark-DK75y0GJ.mjs} +2 -2
- package/dist/{slotMark-Rdsjb7XI.mjs.map → slotMark-DK75y0GJ.mjs.map} +1 -1
- package/dist/{style-CKjLee4e.mjs → style-CmHD4Ul3.mjs} +4 -4
- package/dist/{style-CKjLee4e.mjs.map → style-CmHD4Ul3.mjs.map} +1 -1
- package/dist/styleValue-BavTe9MZ.d.mts.map +1 -1
- package/dist/{styleValue-_G9jwb17.mjs → styleValue-Cj4YjgVB.mjs} +60 -2
- package/dist/styleValue-Cj4YjgVB.mjs.map +1 -0
- package/dist/testing.mjs +1 -1
- package/dist/theme.mjs +15 -13
- package/dist/theme.mjs.map +1 -1
- package/dist/{tokens-O8S8QH_R.mjs → tokens-BkWHtxjY.mjs} +3 -3
- package/dist/{tokens-O8S8QH_R.mjs.map → tokens-BkWHtxjY.mjs.map} +1 -1
- package/dist/utilities.mjs +3 -3
- package/package.json +1 -1
- package/dist/styleValue-_G9jwb17.mjs.map +0 -1
|
@@ -114,6 +114,62 @@ const toStyleValue = (value) => {
|
|
|
114
114
|
};
|
|
115
115
|
const classPiece = (value) => make({ classes: Object.freeze(tokens(value)) });
|
|
116
116
|
const inline = (value) => make({ style: Object.freeze({ ...value }) });
|
|
117
|
+
/** Shorthands whose longhands are named after them: `border` and `borderColor`. */
|
|
118
|
+
const shorthands = [
|
|
119
|
+
"animation",
|
|
120
|
+
"background",
|
|
121
|
+
"border",
|
|
122
|
+
"borderBlock",
|
|
123
|
+
"borderBottom",
|
|
124
|
+
"borderInline",
|
|
125
|
+
"borderLeft",
|
|
126
|
+
"borderRadius",
|
|
127
|
+
"borderRight",
|
|
128
|
+
"borderTop",
|
|
129
|
+
"font",
|
|
130
|
+
"inset",
|
|
131
|
+
"listStyle",
|
|
132
|
+
"margin",
|
|
133
|
+
"mask",
|
|
134
|
+
"outline",
|
|
135
|
+
"overflow",
|
|
136
|
+
"padding",
|
|
137
|
+
"textDecoration",
|
|
138
|
+
"transition"
|
|
139
|
+
];
|
|
140
|
+
/**
|
|
141
|
+
* Properties named like a longhand that the shorthand does not set: a border's
|
|
142
|
+
* radius, image, collapse and spacing, an outline's offset, overflow's wrap
|
|
143
|
+
* and anchor, and the font settings the `font` shorthand leaves alone.
|
|
144
|
+
*/
|
|
145
|
+
const notLonghands = /^border\w*(Radius|Image|Collapse|Spacing)|^outlineOffset$|^overflow(Wrap|Anchor)$|^font(Feature|Variation)Settings$|^textDecorationSkipInk$/;
|
|
146
|
+
const isLonghandOf = (shorthand, property) => property.length > shorthand.length && property.startsWith(shorthand) && /[A-Z]/.test(property[shorthand.length]) && !notLonghands.test(property);
|
|
147
|
+
/**
|
|
148
|
+
* Refuses an inline shorthand beside a longhand of it that comes and goes
|
|
149
|
+
* with a condition, in either order. The renderer drops a property by
|
|
150
|
+
* clearing it, and clearing `borderColor` clears the color `border` set too,
|
|
151
|
+
* while `border`, unchanged, is not written again: a pill that was once
|
|
152
|
+
* selected kept a `currentColor` border. Write the state as a rule
|
|
153
|
+
* (`Style.nest('&[aria-selected="true"]', …)`) or set the longhand always.
|
|
154
|
+
*/
|
|
155
|
+
const checkInlineShorthands = (style, conditions) => {
|
|
156
|
+
const always = Object.keys(style);
|
|
157
|
+
for (const condition of conditions) for (const sometimes of Object.keys(condition.piece.style)) for (const property of always) {
|
|
158
|
+
const shorthand = shorthands.includes(property) && isLonghandOf(property, sometimes);
|
|
159
|
+
const longhand = shorthands.includes(sometimes) && isLonghandOf(sometimes, property);
|
|
160
|
+
if (!shorthand && !longhand) continue;
|
|
161
|
+
throw new DiagnosticError({
|
|
162
|
+
source: "mixins",
|
|
163
|
+
code: "mixins:inline-shorthand-conflict",
|
|
164
|
+
severity: "error",
|
|
165
|
+
message: `An inline \`${shorthand ? property : sometimes}\` beside a conditional \`${shorthand ? sometimes : property}\`: when the condition stops holding, the renderer clears \`${sometimes}\` and takes the shorthand's part with it. Write the state as a rule, or set the longhand unconditionally.`,
|
|
166
|
+
details: {
|
|
167
|
+
always: property,
|
|
168
|
+
conditional: sometimes
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
117
173
|
/** Concatenate classes; later inline declarations win per property. */
|
|
118
174
|
const compose = (...written) => {
|
|
119
175
|
const pieces = written.map(toStyleValue);
|
|
@@ -121,9 +177,11 @@ const compose = (...written) => {
|
|
|
121
177
|
const items = pieces.flatMap((piece) => piece.items ?? []);
|
|
122
178
|
const rules = pieces.flatMap((piece) => piece.rules ?? []);
|
|
123
179
|
const globalCss = pieces.flatMap((piece) => piece.globalCss ?? []);
|
|
180
|
+
const style = Object.assign(Object.create(null), ...pieces.map((piece) => piece.style));
|
|
181
|
+
checkInlineShorthands(style, conditions);
|
|
124
182
|
return make({
|
|
125
183
|
classes: Object.freeze(pieces.flatMap((piece) => piece.classes)),
|
|
126
|
-
style: Object.freeze(
|
|
184
|
+
style: Object.freeze(style),
|
|
127
185
|
...conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) },
|
|
128
186
|
...items.length === 0 ? {} : { items: Object.freeze(items) },
|
|
129
187
|
...rules.length === 0 ? {} : { rules: Object.freeze(rules) },
|
|
@@ -245,4 +303,4 @@ const viewTransitionName = (name) => inline({ viewTransitionName: name });
|
|
|
245
303
|
//#endregion
|
|
246
304
|
export { className as C, diagnostics_exports as E, viewTransitionName as S, DiagnosticError as T, self as _, container as a, toStyleValue as b, global as c, keyframes as d, make as f, responsive as g, pseudo as h, compose as i, grid as l, nest as m, at as n, empty as o, media as p, classPiece as r, enter as s, allowDiscrete as t, inline as u, states as v, css as w, vars as x, supports as y };
|
|
247
305
|
|
|
248
|
-
//# sourceMappingURL=styleValue-
|
|
306
|
+
//# sourceMappingURL=styleValue-Cj4YjgVB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleValue-Cj4YjgVB.mjs","names":["pseudo","media","supports","container","nest","keyframes","Rules.pseudo","Rules.rule","Rules.media","Rules.supports","Rules.container","Rules.nest","Rules.keyframes"],"sources":["../src/diagnostics.ts","../src/styleRules.ts","../src/styleValue.ts"],"sourcesContent":["/**\n * Structured diagnostics for attachment conflicts. Codes are stable so tests,\n * DevTools, and editor tooling can share them. Resolution failures are\n * programming errors (a definition attaches something a slot does not allow),\n * so `resolve` throws a `DiagnosticError` carrying one.\n */\nexport type DiagnosticCode =\n | 'mixins:unknown-slot'\n | 'mixins:hidden-slot'\n | 'mixins:capability-mismatch'\n | 'mixins:unsupported-event'\n | 'mixins:unsupported-attribute'\n | 'mixins:protected-event'\n | 'mixins:protected-attribute'\n | 'mixins:protected-style-property'\n | 'mixins:style-property-conflict'\n | 'mixins:event-conflict'\n | 'mixins:attribute-conflict'\n | 'mixins:structural-override'\n | 'mixins:duplicate-mount-name'\n | 'mixins:duplicate-item-id'\n | 'mixins:ragged-grid-areas'\n | 'mixins:inline-shorthand-conflict'\n | 'style:duplicate-layer'\n | 'style:conflicting-layer-order'\n | 'style:unlayered-rule'\n | 'style:relayered'\n | 'theme:unparseable-breakpoint'\n | 'a11y:missing-slot'\n | 'a11y:hidden-slot'\n | 'a11y:capability-mismatch'\n | 'a11y:missing-event'\n | 'a11y:missing-attribute'\n\nexport interface Diagnostic {\n readonly source: 'mixins' | 'a11y' | 'style' | 'theme'\n readonly code: DiagnosticCode\n readonly severity: 'error'\n readonly message: string\n readonly slot?: string\n readonly details?: Readonly<Record<string, unknown>>\n}\n\nexport class DiagnosticError extends Error {\n readonly diagnostic: Diagnostic\n\n constructor(diagnostic: Diagnostic) {\n super(diagnostic.message)\n this.name = 'DiagnosticError'\n this.diagnostic = diagnostic\n }\n}\n","/**\n * Deterministic compilation of rule-based Style. A rule selector is written\n * relative to the generated class with `&` (`&:hover`). The class name is an\n * FNV-1a hash of the canonical rule text, so equal rules share a class and the\n * server and the browser derive the same name. Pure data in, CSS text out: no\n * registry, no DOM, no `Date.now`.\n */\nexport interface StyleRule {\n readonly selector: string\n readonly at?: string\n /** The cascade layer the rule is emitted in; none means the unlayered cascade. */\n readonly layer?: string\n readonly declarations: Readonly<Record<string, string>>\n}\n\nexport const rule = (\n selector: string,\n declarations: Readonly<Record<string, string>>,\n at?: string,\n): StyleRule =>\n Object.freeze({\n selector,\n declarations: Object.freeze({ ...declarations }),\n ...(at === undefined ? {} : { at }),\n })\n\n/**\n * The top-level selectors of a list: split on commas outside `()`, `[]` and\n * strings, so `:is(a, b)` and `[title=\"a, b\"]` stay whole.\n */\nexport const selectorList = (selector: string): ReadonlyArray<string> => {\n const parts: Array<string> = []\n let depth = 0\n let quote: string | undefined\n let start = 0\n for (let index = 0; index < selector.length; index++) {\n const char = selector[index]\n if (quote !== undefined) {\n if (char === '\\\\') index++\n else if (char === quote) quote = undefined\n } else if (char === '\"' || char === \"'\") quote = char\n else if (char === '(' || char === '[') depth++\n else if (char === ')' || char === ']') depth--\n else if (char === ',' && depth === 0) {\n parts.push(selector.slice(start, index).trim())\n start = index + 1\n }\n }\n parts.push(selector.slice(start).trim())\n return parts\n}\n\n/** Each selector of a list relative to the class: `&` kept where written, else `prefix` added. */\nconst relative = (selector: string, prefix: (part: string) => string): string =>\n selectorList(selector)\n .map(part => (part.includes('&') ? part : prefix(part)))\n .join(', ')\n\n/** `:hover, :focus-visible` is `&:hover, &:focus-visible`. */\nexport const pseudo = (suffix: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule(\n relative(suffix, part => `&${part}`),\n declarations,\n )\n\nexport const media = (query: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule('&', declarations, `@media ${query}`)\n\nexport const supports = (\n condition: string,\n declarations: Readonly<Record<string, string>>,\n): StyleRule => rule('&', declarations, `@supports ${condition}`)\n\nexport const container = (\n condition: string,\n declarations: Readonly<Record<string, string>>,\n): StyleRule => rule('&', declarations, `@container ${condition}`)\n\n/**\n * A nested selector relative to the class, e.g. `> span`, or `[data-open] &`\n * where `&` places the class. Every selector of a list is scoped.\n */\nexport const nest = (selector: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule(\n relative(selector, part => `& ${part}`),\n declarations,\n )\n\n/** `gridTemplateColumns` -> `grid-template-columns`; custom properties pass through. */\nconst kebab = (property: string): string =>\n property.startsWith('--')\n ? property\n : property.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)\n\nconst declarationsText = (declarations: Readonly<Record<string, string>>): string =>\n Object.keys(declarations)\n .sort()\n .map(property => `${kebab(property)}:${declarations[property]}`)\n .join(';')\n\n/** Canonical, declaration-sorted, authored-rule-order text for a rule list. */\nconst inLayerText = (layer: string | undefined, text: string): string =>\n layer === undefined ? text : `@layer ${layer}{${text}}`\n\nexport const canonical = (rules: ReadonlyArray<StyleRule>): string =>\n rules\n .map(entry => {\n const body = `{${declarationsText(entry.declarations)}}`\n return inLayerText(\n entry.layer,\n entry.at === undefined\n ? `${entry.selector}${body}`\n : `${entry.at}{${entry.selector}${body}}`,\n )\n })\n .join('')\n\nconst hash = (value: string): string => {\n let state = 2166136261\n for (let index = 0; index < value.length; index++) {\n state ^= value.charCodeAt(index)\n state = Math.imul(state, 16777619)\n }\n return (state >>> 0).toString(36)\n}\n\nexport interface Keyframes {\n readonly name: string\n readonly css: string\n}\n\n/** Deterministic `@keyframes`: step order is authored, declarations sorted. */\nexport const keyframes = (\n frames: Readonly<Record<string, Readonly<Record<string, string>>>>,\n): Keyframes => {\n const body = Object.entries(frames)\n .map(([step, declarations]) => `${step}{${declarationsText(declarations)}}`)\n .join('')\n const name = `kf-${hash(body)}`\n return Object.freeze({ name, css: `@keyframes ${name}{${body}}` })\n}\n\nexport const className = (rules: ReadonlyArray<StyleRule>): string =>\n `style-${hash(canonical(rules))}`\n\nconst selectorFor = (generated: string, selector: string): string =>\n selectorList(selector)\n .map(part =>\n part.includes('&') ? part.replace(/&/g, `.${generated}`) : `.${generated} ${part}`,\n )\n .join(', ')\n\nexport const css = (generated: string, rules: ReadonlyArray<StyleRule>): string =>\n rules\n .map(entry => {\n const body = `{${declarationsText(entry.declarations)}}`\n const selector = `${selectorFor(generated, entry.selector)}${body}`\n return inLayerText(\n entry.layer,\n entry.at === undefined ? selector : `${entry.at}{${selector}}`,\n )\n })\n .join('')\n","/**\n * The Style kernel: `StyleValue` and the pure builders that make one. A\n * value is class tokens, inline declarations, rule pieces that compile to a\n * deterministic class, and class-independent CSS. Nothing here knows what a\n * slot is; `style.ts` joins this to slots, and the `/theme`, `/layers`,\n * `/layout`, `/defaults`, and `/prose` subpaths build on it alone.\n */\nimport type { Properties } from 'csstype'\nimport { DiagnosticError } from './diagnostics.js'\nimport type { SlotItem } from './slotItem.js'\nimport * as Rules from './styleRules.js'\nimport type { StyleRule } from './styleRules.js'\n\n/**\n * The declarations a piece accepts: camelCase CSS properties, each a string,\n * plus custom properties. A misspelled or kebab-case property is a type error;\n * the compiler writes the kebab-case name. Values stay strings, so `var(...)`,\n * `calc(...)`, and `light-dark(...)` pass through.\n */\nexport type Declarations = { readonly [K in keyof Properties]?: string } & {\n readonly [K: `--${string}`]: string\n}\n\n/** Marks a `StyleValue`, so a piece is told from a declarations object without guessing. */\nexport const StyleValueTypeId: unique symbol = Symbol.for('foldkit-mixins/StyleValue')\n\nexport interface StyleValue {\n readonly [StyleValueTypeId]: true\n readonly classes: ReadonlyArray<string>\n readonly style: Readonly<Record<string, string>>\n /** Input-driven pieces resolved at render time; empty for a static style. */\n readonly conditions?: ReadonlyArray<StyleCondition>\n /** Pieces that depend on which repetition of a slot is rendered. */\n readonly items?: ReadonlyArray<(item: SlotItem | undefined) => StyleValue>\n /** Rule-based appearance compiled to a deterministic class plus CSS. */\n readonly rules?: ReadonlyArray<StyleRule>\n /** Class-independent CSS (keyframes, layers, global rules). */\n readonly globalCss?: ReadonlyArray<string>\n}\n\nexport interface StyleCondition {\n readonly predicate: (input: unknown) => boolean\n readonly piece: StyleValue\n}\n\nconst tokens = (value: string): ReadonlyArray<string> =>\n value.split(/\\s+/).filter(token => token.length > 0)\n\nconst noClasses: ReadonlyArray<string> = Object.freeze([])\nconst noStyle: Readonly<Record<string, string>> = Object.freeze({})\n\n/** A frozen `StyleValue` from its parts; absent classes and style are empty. */\nexport const make = (parts: Partial<Omit<StyleValue, typeof StyleValueTypeId>>): StyleValue => {\n const value: StyleValue = {\n [StyleValueTypeId]: true,\n ...parts,\n classes: parts.classes ?? noClasses,\n style: parts.style ?? noStyle,\n }\n return Object.freeze(value)\n}\n\nexport const isStyleValue = (value: unknown): value is StyleValue =>\n typeof value === 'object' && value !== null && Object.hasOwn(value, StyleValueTypeId)\n\nexport const empty: StyleValue = make({})\n\n/**\n * A piece as written: a `StyleValue`; a declarations object, which means\n * `Style.self(declarations)`; or pieces composed in order.\n */\nexport type Piece =\n | StyleValue\n // Without `classes`, so an object shaped like a StyleValue is not taken for declarations.\n | (Declarations & { readonly classes?: never })\n | ReadonlyArray<Piece>\n\nconst isPieceList = (value: Piece): value is ReadonlyArray<Piece> => Array.isArray(value)\n\n/** The `StyleValue` a written piece stands for. */\nexport const toStyleValue = (value: Piece): StyleValue => {\n if (isStyleValue(value)) return value\n if (isPieceList(value)) return compose(...value)\n return Object.keys(value).length === 0 ? empty : self(value)\n}\n\nexport const classPiece = (value: string): StyleValue =>\n make({ classes: Object.freeze(tokens(value)) })\n\nexport const inline = (value: Declarations): StyleValue =>\n make({ style: Object.freeze({ ...value }) })\n\n/** Shorthands whose longhands are named after them: `border` and `borderColor`. */\nconst shorthands = [\n 'animation',\n 'background',\n 'border',\n 'borderBlock',\n 'borderBottom',\n 'borderInline',\n 'borderLeft',\n 'borderRadius',\n 'borderRight',\n 'borderTop',\n 'font',\n 'inset',\n 'listStyle',\n 'margin',\n 'mask',\n 'outline',\n 'overflow',\n 'padding',\n 'textDecoration',\n 'transition',\n]\n/**\n * Properties named like a longhand that the shorthand does not set: a border's\n * radius, image, collapse and spacing, an outline's offset, overflow's wrap\n * and anchor, and the font settings the `font` shorthand leaves alone.\n */\nconst notLonghands =\n /^border\\w*(Radius|Image|Collapse|Spacing)|^outlineOffset$|^overflow(Wrap|Anchor)$|^font(Feature|Variation)Settings$|^textDecorationSkipInk$/\nconst isLonghandOf = (shorthand: string, property: string) =>\n property.length > shorthand.length &&\n property.startsWith(shorthand) &&\n /[A-Z]/.test(property[shorthand.length]!) &&\n !notLonghands.test(property)\n\n/**\n * Refuses an inline shorthand beside a longhand of it that comes and goes\n * with a condition, in either order. The renderer drops a property by\n * clearing it, and clearing `borderColor` clears the color `border` set too,\n * while `border`, unchanged, is not written again: a pill that was once\n * selected kept a `currentColor` border. Write the state as a rule\n * (`Style.nest('&[aria-selected=\"true\"]', …)`) or set the longhand always.\n */\nconst checkInlineShorthands = (\n style: Readonly<Record<string, unknown>>,\n conditions: ReadonlyArray<{ readonly piece: StyleValue }>,\n): void => {\n const always = Object.keys(style)\n for (const condition of conditions) {\n for (const sometimes of Object.keys(condition.piece.style)) {\n for (const property of always) {\n const shorthand = shorthands.includes(property) && isLonghandOf(property, sometimes)\n const longhand = shorthands.includes(sometimes) && isLonghandOf(sometimes, property)\n if (!shorthand && !longhand) continue\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:inline-shorthand-conflict',\n severity: 'error',\n message: `An inline \\`${shorthand ? property : sometimes}\\` beside a conditional \\`${shorthand ? sometimes : property}\\`: when the condition stops holding, the renderer clears \\`${sometimes}\\` and takes the shorthand's part with it. Write the state as a rule, or set the longhand unconditionally.`,\n details: { always: property, conditional: sometimes },\n })\n }\n }\n }\n}\n\n/** Concatenate classes; later inline declarations win per property. */\nexport const compose = (...written: ReadonlyArray<Piece>): StyleValue => {\n const pieces = written.map(toStyleValue)\n const conditions = pieces.flatMap(piece => piece.conditions ?? [])\n const items = pieces.flatMap(piece => piece.items ?? [])\n const rules = pieces.flatMap(piece => piece.rules ?? [])\n const globalCss = pieces.flatMap(piece => piece.globalCss ?? [])\n const style = Object.assign(Object.create(null), ...pieces.map(piece => piece.style))\n checkInlineShorthands(style, conditions)\n return make({\n classes: Object.freeze(pieces.flatMap(piece => piece.classes)),\n style: Object.freeze(style),\n ...(conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) }),\n ...(items.length === 0 ? {} : { items: Object.freeze(items) }),\n ...(rules.length === 0 ? {} : { rules: Object.freeze(rules) }),\n ...(globalCss.length === 0 ? {} : { globalCss: Object.freeze(globalCss) }),\n })\n}\n\n/** A pseudo-class/element rule, e.g. `Style.pseudo(':hover', { color: 'red' })`. */\nexport const pseudo = (suffix: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.pseudo(suffix, declarations)]),\n })\n\n/**\n * Declarations on the element itself, as a rule on its generated class\n * (`&{…}`) rather than inline, so `Layers.in` can place them in a layer and a\n * later layer can override them. Inline declarations sit outside every layer.\n */\nexport const self = (declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.rule('&', declarations)]),\n })\n\n/** An at-rule, e.g. `Style.media('(min-width: 40rem)', { color: 'red' })`. */\nexport const media = (query: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.media(query, declarations)]),\n })\n\n/** An at-rule, e.g. `Style.supports('(display: grid)', { display: 'grid' })`. */\nexport const supports = (condition: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.supports(condition, declarations)]),\n })\n\n/** A container query, e.g. `Style.container('(min-width: 30rem)', {...})`. */\nexport const container = (condition: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.container(condition, declarations)]),\n })\n\n/**\n * A piece's rules inside an at-rule, where one constructor alone cannot put\n * them: `Style.at('@container builder (max-width: 40rem)',\n * Style.pseudo('[data-open=\"false\"]', { display: 'none' }))`. Its inline\n * declarations become a rule on the element. A class, a condition, a\n * per-item piece, global CSS or a rule already inside an at-rule cannot be\n * put inside one, and throws here.\n */\nexport const at = (prelude: string, piece: StyleValue): StyleValue => {\n const refuse = (what: string): never => {\n throw new Error(`Style.at: ${what} cannot go inside \"${prelude}\"`)\n }\n if (!prelude.startsWith('@')) refuse('anything but an at-rule prelude')\n if (piece.classes.length > 0) refuse('a class')\n if ((piece.conditions ?? []).length > 0 || (piece.items ?? []).length > 0)\n refuse('a piece chosen when drawn')\n if ((piece.globalCss ?? []).length > 0) refuse('global CSS')\n const own = Object.keys(piece.style).length === 0 ? [] : [Rules.rule('&', piece.style)]\n return make({\n rules: Object.freeze(\n [...own, ...(piece.rules ?? [])].map(rule =>\n rule.at === undefined\n ? Object.freeze({ ...rule, at: prelude })\n : refuse(`a rule inside \"${rule.at}\"`),\n ),\n ),\n })\n}\n\n/** A nested selector relative to the generated class, e.g. `Style.nest('> span', {...})`. */\nexport const nest = (selector: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.nest(selector, declarations)]),\n })\n\n/**\n * A deterministic `@keyframes` block. Compose `style` where the animation is\n * declared and reference `name` in an `animation` declaration.\n */\nexport const keyframes = (\n frames: Readonly<Record<string, Declarations>>,\n): { readonly name: string; readonly style: StyleValue } => {\n const compiled = Rules.keyframes(frames)\n return Object.freeze({\n name: compiled.name,\n style: make({\n globalCss: Object.freeze([compiled.css]),\n }),\n })\n}\n\n/** Raw class-independent CSS (a layer, a global rule). Prefer typed helpers. */\nexport const global = (css: string): StyleValue =>\n make({\n globalCss: Object.freeze([css]),\n })\n\n/**\n * Appearance per `data-state` value, e.g. `Style.states({ open: { opacity: '1' } })`\n * compiles to `&[data-state=\"open\"]`. Pairs with Behaviors that write\n * `data-state`, so state is styled with no JavaScript and no `whenInput`:\n * `whenInput` when the view knows, `states` when the DOM does.\n */\nexport const states = (\n map: Readonly<Record<string, Declarations>>,\n attribute = 'data-state',\n): StyleValue =>\n make({\n rules: Object.freeze(\n Object.entries(map).map(([state, declarations]) =>\n Rules.pseudo(`[${attribute}=\"${state}\"]`, declarations),\n ),\n ),\n })\n\n/**\n * Declarations per named breakpoint, e.g.\n * `Style.responsive({ md: '(min-width: 48rem)' }, { md: { display: 'flex' } })`.\n * The breakpoint names come from the record you pass, typically a theme's, so\n * a misspelled one is a type error. A breakpoint is a media query, or a whole\n * at-rule: `'@container page (min-width: 48rem)'` measures the container named\n * `page` rather than the window (`Theme.inContainer` writes these).\n */\nexport const responsive = <Breakpoints extends Readonly<Record<string, string>>>(\n breakpoints: Breakpoints,\n map: Partial<Readonly<Record<keyof Breakpoints & string, Declarations>>>,\n): StyleValue =>\n make({\n rules: Object.freeze(\n Object.entries(map).flatMap(([name, declarations]) => {\n const query = breakpoints[name]\n if (query === undefined || declarations === undefined) return []\n return [\n query.startsWith('@')\n ? Rules.rule('&', declarations, query)\n : Rules.media(query, declarations),\n ]\n }),\n ),\n })\n\n/** Custom properties on the slot: `Style.vars({ '--gap': '1rem' })`. */\nexport const vars = (values: Readonly<Record<`--${string}`, string>>): StyleValue => inline(values)\n\nexport interface GridConfig<Area extends string> {\n /** Rows of area names; `'.'` is an empty cell. Every row has the same length. */\n readonly areas: ReadonlyArray<ReadonlyArray<Area>>\n readonly columns?: string\n readonly rows?: string\n readonly gap?: string\n}\n\nexport interface Grid<Area extends string> {\n /** The container's declarations: `display: grid` and the template. */\n readonly style: StyleValue\n /** A child's `grid-area`; only the names the template declares are accepted. */\n readonly area: (name: Area) => StyleValue\n /** The declared names, in first-appearance order. */\n readonly areas: ReadonlyArray<Area>\n}\n\n/**\n * A grid template with typed areas, so a child cannot name an area the\n * parent lacks: `const Page = Style.grid({ areas: [['header', 'header'],\n * ['nav', 'main']] })`, then `Page.area('main')` on the child and\n * `Page.area('footer')` is a type error. A ragged template raises\n * `mixins:ragged-grid-areas`.\n */\nexport const grid = <const Area extends string>(\n config: GridConfig<Area>,\n): Grid<Exclude<Area, '.'>> => {\n const width = config.areas[0]?.length ?? 0\n if (config.areas.some(row => row.length !== width)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:ragged-grid-areas',\n severity: 'error',\n message: `Style.grid areas must be rectangular; rows have lengths ${config.areas.map(row => row.length).join(', ')}`,\n })\n }\n const names: Array<Exclude<Area, '.'>> = []\n for (const row of config.areas) {\n for (const cell of row) {\n if (cell !== '.' && !names.includes(cell as Exclude<Area, '.'>)) {\n names.push(cell as Exclude<Area, '.'>)\n }\n }\n }\n return Object.freeze({\n // Rules, not inline declarations, so a later layer can override the template.\n style: self({\n display: 'grid',\n gridTemplateAreas: config.areas.map(row => `\"${row.join(' ')}\"`).join(' '),\n ...(config.columns === undefined ? {} : { gridTemplateColumns: config.columns }),\n ...(config.rows === undefined ? {} : { gridTemplateRows: config.rows }),\n ...(config.gap === undefined ? {} : { gap: config.gap }),\n }),\n area: (name: Exclude<Area, '.'>) => self({ gridArea: name }),\n areas: Object.freeze(names),\n })\n}\n\n/**\n * The declarations an element starts from when it enters, as a\n * `@starting-style` rule. With a `transition` on the base, the browser\n * animates from these; pair with `allowDiscrete` when `display` takes part.\n */\nexport const enter = (declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.rule('&', declarations, '@starting-style')]),\n })\n\n/** `transition-behavior: allow-discrete`, so `display` and `overlay` transition too. */\nexport const allowDiscrete: StyleValue = inline({ transitionBehavior: 'allow-discrete' })\n\n/** Opts the slot into Foldkit's view transitions under `name`. */\nexport const viewTransitionName = (name: string): StyleValue => inline({ viewTransitionName: name })\n"],"mappings":";;;AA2CA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CAEA,YAAY,YAAwB;EAClC,MAAM,WAAW,OAAO;EACxB,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;;ACpCA,MAAa,QACX,UACA,cACA,OAEA,OAAO,OAAO;CACZ;CACA,cAAc,OAAO,OAAO,EAAE,GAAG,aAAa,CAAC;CAC/C,GAAI,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,GAAG;AACnC,CAAC;;;;;AAMH,MAAa,gBAAgB,aAA4C;CACvE,MAAM,QAAuB,CAAC;CAC9B,IAAI,QAAQ;CACZ,IAAI;CACJ,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;EACpD,MAAM,OAAO,SAAS;EACtB,IAAI,UAAU,KAAA,GAAW;GACvB,IAAI,SAAS,MAAM;QACd,IAAI,SAAS,OAAO,QAAQ,KAAA;EACnC,OAAO,IAAI,SAAS,QAAO,SAAS,KAAK,QAAQ;OAC5C,IAAI,SAAS,OAAO,SAAS,KAAK;OAClC,IAAI,SAAS,OAAO,SAAS,KAAK;OAClC,IAAI,SAAS,OAAO,UAAU,GAAG;GACpC,MAAM,KAAK,SAAS,MAAM,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC;GAC9C,QAAQ,QAAQ;EAClB;CACF;CACA,MAAM,KAAK,SAAS,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC;CACvC,OAAO;AACT;;AAGA,MAAM,YAAY,UAAkB,WAClC,aAAa,QAAQ,CAAC,CACnB,KAAI,SAAS,KAAK,SAAS,GAAG,IAAI,OAAO,OAAO,IAAI,CAAE,CAAC,CACvD,KAAK,IAAI;;AAGd,MAAaA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OAAO,OAAO,OAAO;EAEnB,OAAO,KAAK;GACV,SAAS;GACT,mBAAmB,OAAO,MAAM,KAAI,QAAO,IAAI,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG;GACzE,GAAI,OAAO,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,qBAAqB,OAAO,QAAQ;GAC9E,GAAI,OAAO,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,kBAAkB,OAAO,KAAK;GACrE,GAAI,OAAO,QAAQ,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK,OAAO,IAAI;EACxD,CAAC;EACD,OAAO,SAA6B,KAAK,EAAE,UAAU,KAAK,CAAC;EAC3D,OAAO,OAAO,OAAO,KAAK;CAC5B,CAAC;AACH;;;;;;AAOA,MAAa,SAAS,iBACpB,KAAK,EACH,OAAO,OAAO,OAAO,CAACD,KAAW,KAAK,cAAc,iBAAiB,CAAC,CAAC,EACzE,CAAC;;AAGH,MAAa,gBAA4B,OAAO,EAAE,oBAAoB,iBAAiB,CAAC;;AAGxF,MAAa,sBAAsB,SAA6B,OAAO,EAAE,oBAAoB,KAAK,CAAC"}
|
package/dist/testing.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as drawMarked, o as usedIn, t as SLOT_MARK } from "./slotMark-
|
|
1
|
+
import { n as drawMarked, o as usedIn, t as SLOT_MARK } from "./slotMark-DK75y0GJ.mjs";
|
|
2
2
|
import { Option } from "effect";
|
|
3
3
|
import { given, scene, tap } from "foldkit/scene";
|
|
4
4
|
//#region src/testing.ts
|
package/dist/theme.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as lightDark, i as define, n as VAR_PREFIX, o as ref, r as compose, s as variables, t as Theme$1 } from "./core-
|
|
2
|
-
import { n as scoped, t as root } from "./root-
|
|
3
|
-
import { n as inContainer, r as tokens, t as breakpointWidths } from "./tokens-
|
|
1
|
+
import { a as lightDark, i as define, n as VAR_PREFIX, o as ref, r as compose, s as variables, t as Theme$1 } from "./core-IMVYU8JN.mjs";
|
|
2
|
+
import { n as scoped, t as root } from "./root-BBi88KYx.mjs";
|
|
3
|
+
import { n as inContainer, r as tokens, t as breakpointWidths } from "./tokens-BkWHtxjY.mjs";
|
|
4
4
|
//#region src/theme/oklch.ts
|
|
5
5
|
/**
|
|
6
6
|
* A whole palette from a few knobs, as css-tags derives it: every value
|
|
@@ -25,10 +25,12 @@ const rehue = (color, hue) => `oklch(from ${color} l c ${hue})`;
|
|
|
25
25
|
const contrast = (color) => `oklch(from ${color} clamp(0.1, (0.65 / l - 1) * 999, 0.98) min(c, 0.08) h)`;
|
|
26
26
|
/** `color` as text on the base surface: dark in a light scheme, light in a dark one. */
|
|
27
27
|
const ink = (color) => ld(from(color, "0.5", "c"), from(color, "0.8", "c"));
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
/**
|
|
29
|
+
* `color` tinted onto the base surface, the same in both schemes. Mixed in
|
|
30
|
+
* OKLab, not OKLCH: OKLCH interpolates hue, so a mix mostly of the base keeps
|
|
31
|
+
* the base's hue, and a green tinted onto a blue-grey base came out blue.
|
|
32
|
+
*/
|
|
33
|
+
const tint = (color, percent) => `color-mix(in oklab, ${v("surface", "base")} ${percent}%, ${color})`;
|
|
32
34
|
const neutral = v("hue", "neutral");
|
|
33
35
|
const base = v("surface", "base");
|
|
34
36
|
const surfaceC = v("knob", "surface-c");
|
|
@@ -94,9 +96,9 @@ const oklch = (knobs) => {
|
|
|
94
96
|
},
|
|
95
97
|
surface: {
|
|
96
98
|
base: ld(`oklch(${v("knob", "base-l")} calc(${surfaceC} * 0.9) ${neutral})`, `oklch(${v("knob", "base-l-dark")} calc(${surfaceCDark} * 0.9) ${neutral})`),
|
|
97
|
-
muted: surfaceStep([-.04, .
|
|
98
|
-
subtle: surfaceStep([-.025, 1.
|
|
99
|
-
default: surfaceStep([-.055, 1.
|
|
99
|
+
muted: surfaceStep([-.04, 1.2], [-.03, 1.05]),
|
|
100
|
+
subtle: surfaceStep([-.025, 1.15], [-.015, 1.05]),
|
|
101
|
+
default: surfaceStep([-.055, 1.25], [.045, 1.1]),
|
|
100
102
|
overt: surfaceStep([-.31, 2.25], [.125, 1.2]),
|
|
101
103
|
bedrock: ld(`oklch(8% calc(${surfaceC} * 1.2) ${neutral})`, `oklch(98% calc(${surfaceCDark} * 0.7) ${neutral})`)
|
|
102
104
|
},
|
|
@@ -109,9 +111,9 @@ const oklch = (knobs) => {
|
|
|
109
111
|
"link-hover": shift(v("text", "link"), -.1, 0)
|
|
110
112
|
},
|
|
111
113
|
outline: {
|
|
112
|
-
subtle:
|
|
113
|
-
default:
|
|
114
|
-
overt:
|
|
114
|
+
subtle: ld(scale(base, -.07, 1.3), scale(base, .065, 1.25)),
|
|
115
|
+
default: ld(scale(base, -.13, 1.4), scale(base, .12, 1.35)),
|
|
116
|
+
overt: ld(scale(base, -.27, 1.6), scale(base, .23, 1.5)),
|
|
115
117
|
focus: shift(accent, -.1, .1)
|
|
116
118
|
},
|
|
117
119
|
accent: family("accent", ld(`oklch(${v("knob", "accent-l")} ${v("knob", "accent-c")} ${v("hue", "accent")})`, `oklch(${v("knob", "accent-l-dark")} ${v("knob", "accent-c-dark")} ${v("hue", "accent")})`)),
|
package/dist/theme.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.mjs","names":["Core.Theme"],"sources":["../src/theme/oklch.ts","../src/theme.ts"],"sourcesContent":["/**\n * A whole palette from a few knobs, as css-tags derives it: every value\n * except the knobs is a CSS expression over other tokens, so overriding a\n * knob anywhere (a scoped theme, a subtree, an inline style) re-derives the\n * rest in the browser. Where light and dark schemes need different numbers\n * the value is a `light-dark()` pair, so one theme serves both and a user's\n * choice is a `color-scheme` override.\n */\nimport { define } from './core.js'\n\nexport interface OklchKnobs {\n /** The brand color: hue in degrees, chroma 0–0.4, lightness as a percentage. */\n readonly accent: {\n readonly h: number\n readonly c: number\n readonly l: string\n /** Lighter and stronger on dark surfaces; defaults `70%` and `c + 0.03`. */\n readonly dark?: { readonly l?: string; readonly c?: number }\n }\n /** Degrees added to the accent hue for the secondary and tertiary families. */\n readonly secondaryHueShift?: number\n readonly tertiaryHueShift?: number\n /** Chroma of neutral surfaces; 0 is gray. */\n readonly surfaceSaturation?: number\n /** How far apart the surface steps are, 0–100%. */\n readonly surfaceContrast?: string\n /** Multiplies text chroma. */\n readonly contrastFactor?: number\n /** Hues of the feedback families. */\n readonly feedback?: {\n readonly success?: number\n readonly warning?: number\n readonly error?: number\n readonly info?: number\n }\n}\n\nconst v = (group: string, name: string) => `var(--fk-${group}-${name})`\n/** A computed knob without float noise: `0.02`, not `0.019999999999999997`. */\nconst num = (value: number) => String(Number(value.toFixed(4)))\nconst ld = (light: string, dark: string) => `light-dark(${light}, ${dark})`\nconst offset = (amount: number) => `${amount < 0 ? '-' : '+'} ${Math.abs(amount)}`\n/** `oklch(from <color> …)` with the hue kept. */\nconst from = (color: string, l: string, c: string) => `oklch(from ${color} ${l} ${c} h)`\nconst shift = (color: string, dl: number, dc: number) =>\n from(color, `calc(l ${offset(dl)})`, `calc(c ${offset(dc)})`)\nconst scale = (color: string, dl: number, cx: number) =>\n from(color, `calc(l ${offset(dl)})`, `calc(c * ${cx})`)\n/** The same lightness and chroma as `color` on another hue. */\nconst rehue = (color: string, hue: string) => `oklch(from ${color} l c ${hue})`\n/** Near-black or near-white text over `color`. */\nconst contrast = (color: string) =>\n `oklch(from ${color} clamp(0.1, (0.65 / l - 1) * 999, 0.98) min(c, 0.08) h)`\n/** `color` as text on the base surface: dark in a light scheme, light in a dark one. */\nconst ink = (color: string) => ld(from(color, '0.5', 'c'), from(color, '0.8', 'c'))\n/** `color` tinted onto the base surface, the same in both schemes. */\nconst tint = (color: string, percent: number) =>\n `color-mix(in oklch, ${v('surface', 'base')} ${percent}%, ${color})`\n\n/** The default text color at `percent` over the base surface. */\nconst line = (percent: number) =>\n `color-mix(in oklch, ${v('text', 'default')} ${percent}%, ${v('surface', 'base')})`\n\nconst neutral = v('hue', 'neutral')\nconst base = v('surface', 'base')\nconst surfaceC = v('knob', 'surface-c')\nconst surfaceCDark = v('knob', 'surface-c-dark')\nconst contrastFactor = v('knob', 'contrast-factor')\n\ntype Step = readonly [lightness: number, chroma: number]\n\n/** A surface step: the base mixed toward a target by `surface-contrast`. */\nconst surfaceStep = (light: Step, dark: Step) => {\n const amount = v('knob', 'surface-contrast')\n const target = ld(scale(base, light[0], light[1]), scale(base, dark[0], dark[1]))\n return `color-mix(in oklch, ${base} calc(100% - ${amount}), ${target} ${amount})`\n}\n\n/** A text color: fixed lightness, chroma scaled by surface saturation and the contrast factor. */\nconst text = (light: Step, dark: Step) =>\n ld(\n `oklch(${light[0]}% calc(${surfaceC} * ${light[1]} * ${contrastFactor}) ${neutral})`,\n `oklch(${dark[0]}% calc(${surfaceCDark} * ${dark[1]} * ${contrastFactor}) ${neutral})`,\n )\n\nconst family = (name: string, defaultValue: string) => {\n const color = v(name, 'default')\n return {\n default: defaultValue,\n hover: shift(color, -0.06, 0),\n active: shift(color, -0.1, 0.05),\n subtle: tint(color, 85),\n 'on-fill': contrast(color),\n ink: ink(color),\n }\n}\n\nconst feedback = (name: string, l: number, c: number) => {\n const color = v(name, 'default')\n return {\n default: `oklch(${l}% ${c} ${v('knob', `${name}-h`)})`,\n subtle: tint(color, 85),\n 'on-fill': contrast(color),\n ink: ink(color),\n outline: shift(color, -0.05, 0),\n }\n}\n\nexport const oklch = (knobs: OklchKnobs) => {\n const accent = v('accent', 'default')\n const surfaceSaturation = knobs.surfaceSaturation ?? 0.015\n return define({\n knob: {\n 'accent-h': String(knobs.accent.h),\n 'accent-c': String(knobs.accent.c),\n 'accent-l': knobs.accent.l,\n 'accent-c-dark': num(knobs.accent.dark?.c ?? Math.min(0.4, knobs.accent.c + 0.03)),\n 'accent-l-dark': knobs.accent.dark?.l ?? '70%',\n 'secondary-shift': String(knobs.secondaryHueShift ?? 60),\n 'tertiary-shift': String(knobs.tertiaryHueShift ?? -90),\n 'surface-c': String(surfaceSaturation),\n 'surface-c-dark': num(surfaceSaturation * (4 / 3)),\n 'surface-contrast': knobs.surfaceContrast ?? '65%',\n 'contrast-factor': String(knobs.contrastFactor ?? 1),\n 'base-l': '97.5%',\n 'base-l-dark': '22%',\n 'success-h': String(knobs.feedback?.success ?? 145),\n 'warning-h': String(knobs.feedback?.warning ?? 75),\n 'error-h': String(knobs.feedback?.error ?? 25),\n 'info-h': String(knobs.feedback?.info ?? 245),\n },\n hue: {\n accent: v('knob', 'accent-h'),\n secondary: `calc(${v('knob', 'accent-h')} + ${v('knob', 'secondary-shift')})`,\n tertiary: `calc(${v('knob', 'accent-h')} + ${v('knob', 'tertiary-shift')})`,\n neutral: v('hue', 'accent'),\n },\n surface: {\n base: ld(\n `oklch(${v('knob', 'base-l')} calc(${surfaceC} * 0.9) ${neutral})`,\n `oklch(${v('knob', 'base-l-dark')} calc(${surfaceCDark} * 0.9) ${neutral})`,\n ),\n muted: surfaceStep([-0.04, 0.8], [-0.03, 0.5]),\n subtle: surfaceStep([-0.025, 1.05], [-0.015, 0.7]),\n default: surfaceStep([-0.055, 1.2], [0.045, 1]),\n overt: surfaceStep([-0.31, 2.25], [0.125, 1.2]),\n bedrock: ld(\n `oklch(8% calc(${surfaceC} * 1.2) ${neutral})`,\n `oklch(98% calc(${surfaceCDark} * 0.7) ${neutral})`,\n ),\n },\n text: {\n default: text([20, 2], [88, 0.8]),\n muted: text([45, 1.5], [65, 1.2]),\n subtle: text([35, 1.8], [75, 1]),\n overt: text([10, 2.2], [95, 0.6]),\n link: shift(accent, 0.1, 0.05),\n 'link-hover': shift(v('text', 'link'), -0.1, 0),\n },\n // Text mixed into the base: darker than the surface in a light scheme,\n // lighter in a dark one, so a line separates in both from one expression.\n outline: {\n subtle: line(10),\n default: line(18),\n overt: line(35),\n focus: shift(accent, -0.1, 0.1),\n },\n accent: family(\n 'accent',\n ld(\n `oklch(${v('knob', 'accent-l')} ${v('knob', 'accent-c')} ${v('hue', 'accent')})`,\n `oklch(${v('knob', 'accent-l-dark')} ${v('knob', 'accent-c-dark')} ${v('hue', 'accent')})`,\n ),\n ),\n secondary: family('secondary', rehue(accent, v('hue', 'secondary'))),\n tertiary: family('tertiary', rehue(accent, v('hue', 'tertiary'))),\n // A near-black of the neutral hue: faint on a light surface, and denser\n // on a dark one, where a light shadow would read as a glow.\n shadow: {\n color: ld(\n `oklch(25% calc(${surfaceC} * 2) ${neutral} / 0.14)`,\n `oklch(5% calc(${surfaceCDark} * 2) ${neutral} / 0.6)`,\n ),\n },\n success: feedback('success', 55, 0.15),\n warning: feedback('warning', 70, 0.15),\n error: feedback('error', 60, 0.2),\n info: feedback('info', 65, 0.15),\n })\n}\n\nexport type OklchTheme = ReturnType<typeof oklch>\n","/**\n * `foldkit-mixins/theme`: the root export's `Theme` plus the page-level\n * pieces. `root` and `scoped` turn tokens into unlayered `:root` and\n * selector rules for `Style.stylesheet`; `tokens` is the shipped set of\n * non-color scales; `oklch` derives a whole palette from a few knobs.\n */\nimport * as Core from './theme/core.js'\nimport { oklch } from './theme/oklch.js'\nimport { root, scoped } from './theme/root.js'\nimport { breakpointWidths, inContainer, tokens } from './theme/tokens.js'\n\nexport { compose, define, lightDark, ref, variables, VAR_PREFIX } from './theme/core.js'\nexport type { Refs, Theme as ThemeValue, ThemeTokens } from './theme/core.js'\nexport { root, scoped } from './theme/root.js'\nexport type { Overrides, RootOptions } from './theme/root.js'\nexport { breakpointWidths, inContainer, tokens } from './theme/tokens.js'\nexport type { Tokens } from './theme/tokens.js'\nexport { oklch } from './theme/oklch.js'\nexport type { OklchKnobs, OklchTheme } from './theme/oklch.js'\n\nexport const Theme = {\n ...Core.Theme,\n root,\n scoped,\n tokens,\n breakpointWidths,\n inContainer,\n oklch,\n} as const\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAM,KAAK,OAAe,SAAiB,YAAY,MAAM,GAAG,KAAK;;AAErE,MA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AG,GAAG,CAAC,IAAI,GAAG,CAAC;GAChC,QAAQ,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;GAC/B,OAAO,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,EAAG,CAAC;GAChC,MAAM,MAAM,QAAQ,IAAK,GAAI;GAC7B,cAAc,MAAM,EAAE,QAAQ,MAAM,GAAG,KAAM,CAAC;EAChD;EAGA,SAAS;GACP,QAAQ,KAAK,EAAE;GACf,SAAS,KAAK,EAAE;GAChB,OAAO,KAAK,EAAE;GACd,OAAO,MAAM,QAAQ,KAAM,EAAG;EAChC;EACA,QAAQ,OACN,UACA,GACE,SAAS,EAAE,QAAQ,UAAU,EAAE,GAAG,EAAE,QAAQ,UAAU,EAAE,GAAG,EAAE,OAAO,QAAQ,EAAE,IAC9E,SAAS,EAAE,QAAQ,eAAe,EAAE,GAAG,EAAE,QAAQ,eAAe,EAAE,GAAG,EAAE,OAAO,QAAQ,EAAE,EAC1F,CACF;EACA,WAAW,OAAO,aAAa,MAAM,QAAQ,EAAE,OAAO,WAAW,CAAC,CAAC;EACnE,UAAU,OAAO,YAAY,MAAM,QAAQ,EAAE,OAAO,UAAU,CAAC,CAAC;EAGhE,QAAQ,EACN,OAAO,GACL,kBAAkB,SAAS,QAAQ,QAAQ,WAC3C,iBAAiB,aAAa,QAAQ,QAAQ,QAChD,EACF;EACA,SAAS,SAAS,WAAW,IAAI,GAAI;EACrC,SAAS,SAAS,WAAW,IAAI,GAAI;EACrC,OAAO,SAAS,SAAS,IAAI,EAAG;EAChC,MAAM,SAAS,QAAQ,IAAI,GAAI;CACjC,CAAC;AACH;;;;;;;;;ACzKA,MAAa,QAAQ;CACnB,GAAGA;CACH;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
1
|
+
{"version":3,"file":"theme.mjs","names":["Core.Theme"],"sources":["../src/theme/oklch.ts","../src/theme.ts"],"sourcesContent":["/**\n * A whole palette from a few knobs, as css-tags derives it: every value\n * except the knobs is a CSS expression over other tokens, so overriding a\n * knob anywhere (a scoped theme, a subtree, an inline style) re-derives the\n * rest in the browser. Where light and dark schemes need different numbers\n * the value is a `light-dark()` pair, so one theme serves both and a user's\n * choice is a `color-scheme` override.\n */\nimport { define } from './core.js'\n\nexport interface OklchKnobs {\n /** The brand color: hue in degrees, chroma 0–0.4, lightness as a percentage. */\n readonly accent: {\n readonly h: number\n readonly c: number\n readonly l: string\n /** Lighter and stronger on dark surfaces; defaults `70%` and `c + 0.03`. */\n readonly dark?: { readonly l?: string; readonly c?: number }\n }\n /** Degrees added to the accent hue for the secondary and tertiary families. */\n readonly secondaryHueShift?: number\n readonly tertiaryHueShift?: number\n /** Chroma of neutral surfaces; 0 is gray. */\n readonly surfaceSaturation?: number\n /** How far apart the surface steps are, 0–100%. */\n readonly surfaceContrast?: string\n /** Multiplies text chroma. */\n readonly contrastFactor?: number\n /** Hues of the feedback families. */\n readonly feedback?: {\n readonly success?: number\n readonly warning?: number\n readonly error?: number\n readonly info?: number\n }\n}\n\nconst v = (group: string, name: string) => `var(--fk-${group}-${name})`\n/** A computed knob without float noise: `0.02`, not `0.019999999999999997`. */\nconst num = (value: number) => String(Number(value.toFixed(4)))\nconst ld = (light: string, dark: string) => `light-dark(${light}, ${dark})`\nconst offset = (amount: number) => `${amount < 0 ? '-' : '+'} ${Math.abs(amount)}`\n/** `oklch(from <color> …)` with the hue kept. */\nconst from = (color: string, l: string, c: string) => `oklch(from ${color} ${l} ${c} h)`\nconst shift = (color: string, dl: number, dc: number) =>\n from(color, `calc(l ${offset(dl)})`, `calc(c ${offset(dc)})`)\nconst scale = (color: string, dl: number, cx: number) =>\n from(color, `calc(l ${offset(dl)})`, `calc(c * ${cx})`)\n/** The same lightness and chroma as `color` on another hue. */\nconst rehue = (color: string, hue: string) => `oklch(from ${color} l c ${hue})`\n/** Near-black or near-white text over `color`. */\nconst contrast = (color: string) =>\n `oklch(from ${color} clamp(0.1, (0.65 / l - 1) * 999, 0.98) min(c, 0.08) h)`\n/** `color` as text on the base surface: dark in a light scheme, light in a dark one. */\nconst ink = (color: string) => ld(from(color, '0.5', 'c'), from(color, '0.8', 'c'))\n/**\n * `color` tinted onto the base surface, the same in both schemes. Mixed in\n * OKLab, not OKLCH: OKLCH interpolates hue, so a mix mostly of the base keeps\n * the base's hue, and a green tinted onto a blue-grey base came out blue.\n */\nconst tint = (color: string, percent: number) =>\n `color-mix(in oklab, ${v('surface', 'base')} ${percent}%, ${color})`\n\nconst neutral = v('hue', 'neutral')\nconst base = v('surface', 'base')\nconst surfaceC = v('knob', 'surface-c')\nconst surfaceCDark = v('knob', 'surface-c-dark')\nconst contrastFactor = v('knob', 'contrast-factor')\n\ntype Step = readonly [lightness: number, chroma: number]\n\n/** A surface step: the base mixed toward a target by `surface-contrast`. */\nconst surfaceStep = (light: Step, dark: Step) => {\n const amount = v('knob', 'surface-contrast')\n const target = ld(scale(base, light[0], light[1]), scale(base, dark[0], dark[1]))\n return `color-mix(in oklch, ${base} calc(100% - ${amount}), ${target} ${amount})`\n}\n\n/** A text color: fixed lightness, chroma scaled by surface saturation and the contrast factor. */\nconst text = (light: Step, dark: Step) =>\n ld(\n `oklch(${light[0]}% calc(${surfaceC} * ${light[1]} * ${contrastFactor}) ${neutral})`,\n `oklch(${dark[0]}% calc(${surfaceCDark} * ${dark[1]} * ${contrastFactor}) ${neutral})`,\n )\n\nconst family = (name: string, defaultValue: string) => {\n const color = v(name, 'default')\n return {\n default: defaultValue,\n hover: shift(color, -0.06, 0),\n active: shift(color, -0.1, 0.05),\n subtle: tint(color, 85),\n 'on-fill': contrast(color),\n ink: ink(color),\n }\n}\n\nconst feedback = (name: string, l: number, c: number) => {\n const color = v(name, 'default')\n return {\n default: `oklch(${l}% ${c} ${v('knob', `${name}-h`)})`,\n subtle: tint(color, 85),\n 'on-fill': contrast(color),\n ink: ink(color),\n outline: shift(color, -0.05, 0),\n }\n}\n\nexport const oklch = (knobs: OklchKnobs) => {\n const accent = v('accent', 'default')\n const surfaceSaturation = knobs.surfaceSaturation ?? 0.015\n return define({\n knob: {\n 'accent-h': String(knobs.accent.h),\n 'accent-c': String(knobs.accent.c),\n 'accent-l': knobs.accent.l,\n 'accent-c-dark': num(knobs.accent.dark?.c ?? Math.min(0.4, knobs.accent.c + 0.03)),\n 'accent-l-dark': knobs.accent.dark?.l ?? '70%',\n 'secondary-shift': String(knobs.secondaryHueShift ?? 60),\n 'tertiary-shift': String(knobs.tertiaryHueShift ?? -90),\n 'surface-c': String(surfaceSaturation),\n 'surface-c-dark': num(surfaceSaturation * (4 / 3)),\n 'surface-contrast': knobs.surfaceContrast ?? '65%',\n 'contrast-factor': String(knobs.contrastFactor ?? 1),\n 'base-l': '97.5%',\n 'base-l-dark': '22%',\n 'success-h': String(knobs.feedback?.success ?? 145),\n 'warning-h': String(knobs.feedback?.warning ?? 75),\n 'error-h': String(knobs.feedback?.error ?? 25),\n 'info-h': String(knobs.feedback?.info ?? 245),\n },\n hue: {\n accent: v('knob', 'accent-h'),\n secondary: `calc(${v('knob', 'accent-h')} + ${v('knob', 'secondary-shift')})`,\n tertiary: `calc(${v('knob', 'accent-h')} + ${v('knob', 'tertiary-shift')})`,\n neutral: v('hue', 'accent'),\n },\n surface: {\n base: ld(\n `oklch(${v('knob', 'base-l')} calc(${surfaceC} * 0.9) ${neutral})`,\n `oklch(${v('knob', 'base-l-dark')} calc(${surfaceCDark} * 0.9) ${neutral})`,\n ),\n // Each step keeps about the base's chroma, so a sidebar, a panel and\n // the page read as one color at a few lightnesses: one with less reads\n // grey on the page, one with more reads as another, bluer color.\n muted: surfaceStep([-0.04, 1.2], [-0.03, 1.05]),\n subtle: surfaceStep([-0.025, 1.15], [-0.015, 1.05]),\n default: surfaceStep([-0.055, 1.25], [0.045, 1.1]),\n overt: surfaceStep([-0.31, 2.25], [0.125, 1.2]),\n bedrock: ld(\n `oklch(8% calc(${surfaceC} * 1.2) ${neutral})`,\n `oklch(98% calc(${surfaceCDark} * 0.7) ${neutral})`,\n ),\n },\n text: {\n default: text([20, 2], [88, 0.8]),\n muted: text([45, 1.5], [65, 1.2]),\n subtle: text([35, 1.8], [75, 1]),\n overt: text([10, 2.2], [95, 0.6]),\n link: shift(accent, 0.1, 0.05),\n 'link-hover': shift(v('text', 'link'), -0.1, 0),\n },\n // Steps from the base, as the surfaces are: darker in a light scheme,\n // lighter in a dark one, and in the base's own hue with a little more of\n // its chroma, which a thin line needs to read as the page's color. Text mixed into the base, as they were, came out grey on a\n // tinted page: the text is near-neutral, so the mix lost the tint.\n outline: {\n subtle: ld(scale(base, -0.07, 1.3), scale(base, 0.065, 1.25)),\n default: ld(scale(base, -0.13, 1.4), scale(base, 0.12, 1.35)),\n overt: ld(scale(base, -0.27, 1.6), scale(base, 0.23, 1.5)),\n focus: shift(accent, -0.1, 0.1),\n },\n accent: family(\n 'accent',\n ld(\n `oklch(${v('knob', 'accent-l')} ${v('knob', 'accent-c')} ${v('hue', 'accent')})`,\n `oklch(${v('knob', 'accent-l-dark')} ${v('knob', 'accent-c-dark')} ${v('hue', 'accent')})`,\n ),\n ),\n secondary: family('secondary', rehue(accent, v('hue', 'secondary'))),\n tertiary: family('tertiary', rehue(accent, v('hue', 'tertiary'))),\n // A near-black of the neutral hue: faint on a light surface, and denser\n // on a dark one, where a light shadow would read as a glow.\n shadow: {\n color: ld(\n `oklch(25% calc(${surfaceC} * 2) ${neutral} / 0.14)`,\n `oklch(5% calc(${surfaceCDark} * 2) ${neutral} / 0.6)`,\n ),\n },\n success: feedback('success', 55, 0.15),\n warning: feedback('warning', 70, 0.15),\n error: feedback('error', 60, 0.2),\n info: feedback('info', 65, 0.15),\n })\n}\n\nexport type OklchTheme = ReturnType<typeof oklch>\n","/**\n * `foldkit-mixins/theme`: the root export's `Theme` plus the page-level\n * pieces. `root` and `scoped` turn tokens into unlayered `:root` and\n * selector rules for `Style.stylesheet`; `tokens` is the shipped set of\n * non-color scales; `oklch` derives a whole palette from a few knobs.\n */\nimport * as Core from './theme/core.js'\nimport { oklch } from './theme/oklch.js'\nimport { root, scoped } from './theme/root.js'\nimport { breakpointWidths, inContainer, tokens } from './theme/tokens.js'\n\nexport { compose, define, lightDark, ref, variables, VAR_PREFIX } from './theme/core.js'\nexport type { Refs, Theme as ThemeValue, ThemeTokens } from './theme/core.js'\nexport { root, scoped } from './theme/root.js'\nexport type { Overrides, RootOptions } from './theme/root.js'\nexport { breakpointWidths, inContainer, tokens } from './theme/tokens.js'\nexport type { Tokens } from './theme/tokens.js'\nexport { oklch } from './theme/oklch.js'\nexport type { OklchKnobs, OklchTheme } from './theme/oklch.js'\n\nexport const Theme = {\n ...Core.Theme,\n root,\n scoped,\n tokens,\n breakpointWidths,\n inContainer,\n oklch,\n} as const\n"],"mappings":";;;;;;;;;;;;AAqCA,MAAM,KAAK,OAAe,SAAiB,YAAY,MAAM,GAAG,KAAK;;AAErE,MAAM,OAAO,UAAkB,OAAO,OAAO,MAAM,QAAQ,CAAC,CAAC,CAAC;AAC9D,MAAM,MAAM,OAAe,SAAiB,cAAc,MAAM,IAAI,KAAK;AACzE,MAAM,UAAU,WAAmB,GAAG,SAAS,IAAI,MAAM,IAAI,GAAG,KAAK,IAAI,MAAM;;AAE/E,MAAM,QAAQ,OAAe,GAAW,MAAc,cAAc,MAAM,GAAG,EAAE,GAAG,EAAE;AACpF,MAAM,SAAS,OAAe,IAAY,OACxC,KAAK,OAAO,UAAU,OAAO,EAAE,EAAE,IAAI,UAAU,OAAO,EAAE,EAAE,EAAE;AAC9D,MAAM,SAAS,OAAe,IAAY,OACxC,KAAK,OAAO,UAAU,OAAO,EAAE,EAAE,IAAI,YAAY,GAAG,EAAE;;AAExD,MAAM,SAAS,OAAe,QAAgB,cAAc,MAAM,OAAO,IAAI;;AAE7E,MAAM,YAAY,UAChB,cAAc,MAAM;;AAEtB,MAAM,OAAO,UAAkB,GAAG,KAAK,OAAO,OAAO,GAAG,GAAG,KAAK,OAAO,OAAO,GAAG,CAAC;;;;;;AAMlF,MAAM,QAAQ,OA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EACA,WAAW,OAAO,aAAa,MAAM,QAAQ,EAAE,OAAO,WAAW,CAAC,CAAC;EACnE,UAAU,OAAO,YAAY,MAAM,QAAQ,EAAE,OAAO,UAAU,CAAC,CAAC;EAGhE,QAAQ,EACN,OAAO,GACL,kBAAkB,SAAS,QAAQ,QAAQ,WAC3C,iBAAiB,aAAa,QAAQ,QAAQ,QAChD,EACF;EACA,SAAS,SAAS,WAAW,IAAI,GAAI;EACrC,SAAS,SAAS,WAAW,IAAI,GAAI;EACrC,OAAO,SAAS,SAAS,IAAI,EAAG;EAChC,MAAM,SAAS,QAAQ,IAAI,GAAI;CACjC,CAAC;AACH;;;;;;;;;AC9KA,MAAa,QAAQ;CACnB,GAAGA;CACH;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as DiagnosticError } from "./styleValue-
|
|
2
|
-
import { i as define } from "./core-
|
|
1
|
+
import { T as DiagnosticError } from "./styleValue-Cj4YjgVB.mjs";
|
|
2
|
+
import { i as define } from "./core-IMVYU8JN.mjs";
|
|
3
3
|
//#region src/theme/tokens.ts
|
|
4
4
|
/**
|
|
5
5
|
* The non-color scales a design system shares across themes. Space and
|
|
@@ -126,4 +126,4 @@ const inContainer = (name, breakpoints) => Object.freeze(Object.fromEntries(Obje
|
|
|
126
126
|
//#endregion
|
|
127
127
|
export { inContainer as n, tokens as r, breakpointWidths as t };
|
|
128
128
|
|
|
129
|
-
//# sourceMappingURL=tokens-
|
|
129
|
+
//# sourceMappingURL=tokens-BkWHtxjY.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens-
|
|
1
|
+
{"version":3,"file":"tokens-BkWHtxjY.mjs","names":[],"sources":["../src/theme/tokens.ts"],"sourcesContent":["/**\n * The non-color scales a design system shares across themes. Space and\n * radius multiply by the `density` and `radius-factor` knobs, so a compact\n * or a rounder theme is one override. `shadow` is drawn in `shadow.color`,\n * which a palette sets (`Theme.oklch` does, stronger in a dark scheme, where\n * a shadow mixed from the text would glow); alone it falls back to black. `breakpoint` is the record\n * `Style.responsive` takes; `breakpointWidths` gives the same names as pixel\n * thresholds for `foldkit-primitives/media` Breakpoints.\n */\nimport { DiagnosticError } from '../diagnostics.js'\nimport { define } from './core.js'\n\nconst space = (rem: number) => `calc(${rem}rem * var(--fk-knob-density))`\nconst radius = (px: number) => `calc(${px}px * var(--fk-knob-radius-factor))`\nconst shade = 'var(--fk-shadow-color, oklch(0% 0 0 / 0.12))'\nconst shadow = (...layers: ReadonlyArray<string>) =>\n layers.map(layer => `${layer} ${shade}`).join(', ')\n\nexport const tokens = define({\n knob: { density: '1', 'radius-factor': '1' },\n space: {\n '3xs': space(0.125),\n '2xs': space(0.25),\n xs: space(0.5),\n sm: space(0.75),\n md: space(1),\n lg: space(1.5),\n xl: space(2),\n '2xl': space(3),\n '3xl': space(4),\n },\n radius: {\n xs: radius(2),\n sm: radius(3),\n md: radius(6),\n lg: radius(8),\n xl: radius(12),\n full: '9999px',\n },\n font: { body: 'system-ui, sans-serif', heading: 'inherit', mono: 'ui-monospace, monospace' },\n size: {\n xs: '0.75rem',\n sm: '0.875rem',\n md: '1rem',\n lg: '1.125rem',\n xl: '1.25rem',\n '2xl': '1.5rem',\n '3xl': '1.875rem',\n '4xl': '2.25rem',\n },\n leading: { tight: '1.2', snug: '1.375', normal: '1.5', relaxed: '1.6' },\n weight: { normal: '400', medium: '500', semibold: '600', bold: '700' },\n motion: { fast: '150ms', normal: '250ms', ease: 'ease-out' },\n border: { thin: '1px', thick: '2px', heavy: '3px' },\n // Raised a little to a lot: a pressed control, a lifted cell, a menu, a dialog.\n shadow: {\n xs: shadow('0 1px 2px 0'),\n sm: shadow('0 1px 3px 0', '0 1px 2px -1px'),\n md: shadow('0 4px 6px -1px', '0 2px 4px -2px'),\n lg: shadow('0 10px 15px -3px', '0 4px 6px -4px'),\n xl: shadow('0 20px 25px -5px', '0 8px 10px -6px'),\n inset: shadow('inset 0 2px 4px 0'),\n },\n breakpoint: {\n sm: '(min-width: 40rem)',\n md: '(min-width: 48rem)',\n lg: '(min-width: 64rem)',\n xl: '(min-width: 80rem)',\n },\n})\n\nexport type Tokens = typeof tokens\n\n// A plain `min-width`, of the window or of a named container.\nconst MIN_WIDTH = /^(?:@container\\s+[\\w-]+\\s+)?\\(min-width:\\s*(\\d+(?:\\.\\d+)?)(rem|px)\\)$/\n\n/**\n * Each breakpoint query's `min-width` in pixels (rem at 16), so CSS and the\n * Model agree on what `md` means. A query that is not a plain `min-width`\n * is refused: it has no single threshold. A container's is its container's.\n */\nexport const breakpointWidths = (theme: {\n readonly breakpoint: { readonly [name: string]: string }\n}): Readonly<Record<string, number>> => {\n const widths: Record<string, number> = {}\n for (const [name, query] of Object.entries(theme.breakpoint)) {\n const match = MIN_WIDTH.exec(query)\n if (match === null) {\n throw new DiagnosticError({\n source: 'theme',\n code: 'theme:unparseable-breakpoint',\n severity: 'error',\n message: `Breakpoint \"${name}\" is \"${query}\", not a \"(min-width: <rem|px>)\" query`,\n details: { name, query },\n })\n }\n const amount = Number(match[1])\n widths[name] = match[2] === 'rem' ? amount * 16 : amount\n }\n return Object.freeze(widths)\n}\n\n/**\n * The same breakpoints measured on a named container rather than the window:\n * `Theme.inContainer('page', Theme.tokens.breakpoint)` gives `md` as\n * `'@container page (min-width: 48rem)'`, for `Style.responsive` and a\n * responsive look. An element must be that container (`container: page /\n * inline-size`) for them to match.\n */\nexport const inContainer = <Breakpoints extends Readonly<Record<string, string>>>(\n name: string,\n breakpoints: Breakpoints,\n): { readonly [K in keyof Breakpoints]: string } =>\n Object.freeze(\n Object.fromEntries(\n Object.entries(breakpoints).map(([at, query]) => [at, `@container ${name} ${query}`]),\n ),\n ) as { readonly [K in keyof Breakpoints]: string }\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,SAAS,QAAgB,QAAQ,IAAI;AAC3C,MAAM,UAAU,OAAe,QAAQ,GAAG;AAC1C,MAAM,QAAQ;AACd,MAAM,UAA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AAM,YAAY;;;;;;AAOlB,MAAa,oBAAoB,UAEO;CACtC,MAAM,SAAiC,CAAC;CACxC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,MAAM,UAAU,GAAG;EAC5D,MAAM,QAAQ,UAAU,KAAK,KAAK;EAClC,IAAI,UAAU,MACZ,MAAM,IAAI,gBAAgB;GACxB,QAAQ;GACR,MAAM;GACN,UAAU;GACV,SAAS,eAAe,KAAK,QAAQ,MAAM;GAC3C,SAAS;IAAE;IAAM;GAAM;EACzB,CAAC;EAEH,MAAM,SAAS,OAAO,MAAM,EAAE;EAC9B,OAAO,QAAQ,MAAM,OAAO,QAAQ,SAAS,KAAK;CACpD;CACA,OAAO,OAAO,OAAO,MAAM;AAC7B;;;;;;;;AASA,MAAa,eACX,MACA,gBAEA,OAAO,OACL,OAAO,YACL,OAAO,QAAQ,WAAW,CAAC,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,IAAI,cAAc,KAAK,GAAG,OAAO,CAAC,CACtF,CACF"}
|
package/dist/utilities.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as self } from "./styleValue-
|
|
2
|
-
import { n as VAR_PREFIX, o as ref } from "./core-
|
|
3
|
-
import { r as tokens } from "./tokens-
|
|
1
|
+
import { _ as self } from "./styleValue-Cj4YjgVB.mjs";
|
|
2
|
+
import { n as VAR_PREFIX, o as ref } from "./core-IMVYU8JN.mjs";
|
|
3
|
+
import { r as tokens } from "./tokens-BkWHtxjY.mjs";
|
|
4
4
|
//#region src/utilities.ts
|
|
5
5
|
/**
|
|
6
6
|
* `foldkit-mixins/utilities`: one-idea pieces over the shipped scales, so
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"styleValue-_G9jwb17.mjs","names":["pseudo","media","supports","container","nest","keyframes","Rules.pseudo","Rules.rule","Rules.media","Rules.supports","Rules.container","Rules.nest","Rules.keyframes"],"sources":["../src/diagnostics.ts","../src/styleRules.ts","../src/styleValue.ts"],"sourcesContent":["/**\n * Structured diagnostics for attachment conflicts. Codes are stable so tests,\n * DevTools, and editor tooling can share them. Resolution failures are\n * programming errors (a definition attaches something a slot does not allow),\n * so `resolve` throws a `DiagnosticError` carrying one.\n */\nexport type DiagnosticCode =\n | 'mixins:unknown-slot'\n | 'mixins:hidden-slot'\n | 'mixins:capability-mismatch'\n | 'mixins:unsupported-event'\n | 'mixins:unsupported-attribute'\n | 'mixins:protected-event'\n | 'mixins:protected-attribute'\n | 'mixins:protected-style-property'\n | 'mixins:style-property-conflict'\n | 'mixins:event-conflict'\n | 'mixins:attribute-conflict'\n | 'mixins:structural-override'\n | 'mixins:duplicate-mount-name'\n | 'mixins:duplicate-item-id'\n | 'mixins:ragged-grid-areas'\n | 'style:duplicate-layer'\n | 'style:conflicting-layer-order'\n | 'style:unlayered-rule'\n | 'style:relayered'\n | 'theme:unparseable-breakpoint'\n | 'a11y:missing-slot'\n | 'a11y:hidden-slot'\n | 'a11y:capability-mismatch'\n | 'a11y:missing-event'\n | 'a11y:missing-attribute'\n\nexport interface Diagnostic {\n readonly source: 'mixins' | 'a11y' | 'style' | 'theme'\n readonly code: DiagnosticCode\n readonly severity: 'error'\n readonly message: string\n readonly slot?: string\n readonly details?: Readonly<Record<string, unknown>>\n}\n\nexport class DiagnosticError extends Error {\n readonly diagnostic: Diagnostic\n\n constructor(diagnostic: Diagnostic) {\n super(diagnostic.message)\n this.name = 'DiagnosticError'\n this.diagnostic = diagnostic\n }\n}\n","/**\n * Deterministic compilation of rule-based Style. A rule selector is written\n * relative to the generated class with `&` (`&:hover`). The class name is an\n * FNV-1a hash of the canonical rule text, so equal rules share a class and the\n * server and the browser derive the same name. Pure data in, CSS text out: no\n * registry, no DOM, no `Date.now`.\n */\nexport interface StyleRule {\n readonly selector: string\n readonly at?: string\n /** The cascade layer the rule is emitted in; none means the unlayered cascade. */\n readonly layer?: string\n readonly declarations: Readonly<Record<string, string>>\n}\n\nexport const rule = (\n selector: string,\n declarations: Readonly<Record<string, string>>,\n at?: string,\n): StyleRule =>\n Object.freeze({\n selector,\n declarations: Object.freeze({ ...declarations }),\n ...(at === undefined ? {} : { at }),\n })\n\n/**\n * The top-level selectors of a list: split on commas outside `()`, `[]` and\n * strings, so `:is(a, b)` and `[title=\"a, b\"]` stay whole.\n */\nexport const selectorList = (selector: string): ReadonlyArray<string> => {\n const parts: Array<string> = []\n let depth = 0\n let quote: string | undefined\n let start = 0\n for (let index = 0; index < selector.length; index++) {\n const char = selector[index]\n if (quote !== undefined) {\n if (char === '\\\\') index++\n else if (char === quote) quote = undefined\n } else if (char === '\"' || char === \"'\") quote = char\n else if (char === '(' || char === '[') depth++\n else if (char === ')' || char === ']') depth--\n else if (char === ',' && depth === 0) {\n parts.push(selector.slice(start, index).trim())\n start = index + 1\n }\n }\n parts.push(selector.slice(start).trim())\n return parts\n}\n\n/** Each selector of a list relative to the class: `&` kept where written, else `prefix` added. */\nconst relative = (selector: string, prefix: (part: string) => string): string =>\n selectorList(selector)\n .map(part => (part.includes('&') ? part : prefix(part)))\n .join(', ')\n\n/** `:hover, :focus-visible` is `&:hover, &:focus-visible`. */\nexport const pseudo = (suffix: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule(\n relative(suffix, part => `&${part}`),\n declarations,\n )\n\nexport const media = (query: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule('&', declarations, `@media ${query}`)\n\nexport const supports = (\n condition: string,\n declarations: Readonly<Record<string, string>>,\n): StyleRule => rule('&', declarations, `@supports ${condition}`)\n\nexport const container = (\n condition: string,\n declarations: Readonly<Record<string, string>>,\n): StyleRule => rule('&', declarations, `@container ${condition}`)\n\n/**\n * A nested selector relative to the class, e.g. `> span`, or `[data-open] &`\n * where `&` places the class. Every selector of a list is scoped.\n */\nexport const nest = (selector: string, declarations: Readonly<Record<string, string>>): StyleRule =>\n rule(\n relative(selector, part => `& ${part}`),\n declarations,\n )\n\n/** `gridTemplateColumns` -> `grid-template-columns`; custom properties pass through. */\nconst kebab = (property: string): string =>\n property.startsWith('--')\n ? property\n : property.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)\n\nconst declarationsText = (declarations: Readonly<Record<string, string>>): string =>\n Object.keys(declarations)\n .sort()\n .map(property => `${kebab(property)}:${declarations[property]}`)\n .join(';')\n\n/** Canonical, declaration-sorted, authored-rule-order text for a rule list. */\nconst inLayerText = (layer: string | undefined, text: string): string =>\n layer === undefined ? text : `@layer ${layer}{${text}}`\n\nexport const canonical = (rules: ReadonlyArray<StyleRule>): string =>\n rules\n .map(entry => {\n const body = `{${declarationsText(entry.declarations)}}`\n return inLayerText(\n entry.layer,\n entry.at === undefined\n ? `${entry.selector}${body}`\n : `${entry.at}{${entry.selector}${body}}`,\n )\n })\n .join('')\n\nconst hash = (value: string): string => {\n let state = 2166136261\n for (let index = 0; index < value.length; index++) {\n state ^= value.charCodeAt(index)\n state = Math.imul(state, 16777619)\n }\n return (state >>> 0).toString(36)\n}\n\nexport interface Keyframes {\n readonly name: string\n readonly css: string\n}\n\n/** Deterministic `@keyframes`: step order is authored, declarations sorted. */\nexport const keyframes = (\n frames: Readonly<Record<string, Readonly<Record<string, string>>>>,\n): Keyframes => {\n const body = Object.entries(frames)\n .map(([step, declarations]) => `${step}{${declarationsText(declarations)}}`)\n .join('')\n const name = `kf-${hash(body)}`\n return Object.freeze({ name, css: `@keyframes ${name}{${body}}` })\n}\n\nexport const className = (rules: ReadonlyArray<StyleRule>): string =>\n `style-${hash(canonical(rules))}`\n\nconst selectorFor = (generated: string, selector: string): string =>\n selectorList(selector)\n .map(part =>\n part.includes('&') ? part.replace(/&/g, `.${generated}`) : `.${generated} ${part}`,\n )\n .join(', ')\n\nexport const css = (generated: string, rules: ReadonlyArray<StyleRule>): string =>\n rules\n .map(entry => {\n const body = `{${declarationsText(entry.declarations)}}`\n const selector = `${selectorFor(generated, entry.selector)}${body}`\n return inLayerText(\n entry.layer,\n entry.at === undefined ? selector : `${entry.at}{${selector}}`,\n )\n })\n .join('')\n","/**\n * The Style kernel: `StyleValue` and the pure builders that make one. A\n * value is class tokens, inline declarations, rule pieces that compile to a\n * deterministic class, and class-independent CSS. Nothing here knows what a\n * slot is; `style.ts` joins this to slots, and the `/theme`, `/layers`,\n * `/layout`, `/defaults`, and `/prose` subpaths build on it alone.\n */\nimport type { Properties } from 'csstype'\nimport { DiagnosticError } from './diagnostics.js'\nimport type { SlotItem } from './slotItem.js'\nimport * as Rules from './styleRules.js'\nimport type { StyleRule } from './styleRules.js'\n\n/**\n * The declarations a piece accepts: camelCase CSS properties, each a string,\n * plus custom properties. A misspelled or kebab-case property is a type error;\n * the compiler writes the kebab-case name. Values stay strings, so `var(...)`,\n * `calc(...)`, and `light-dark(...)` pass through.\n */\nexport type Declarations = { readonly [K in keyof Properties]?: string } & {\n readonly [K: `--${string}`]: string\n}\n\n/** Marks a `StyleValue`, so a piece is told from a declarations object without guessing. */\nexport const StyleValueTypeId: unique symbol = Symbol.for('foldkit-mixins/StyleValue')\n\nexport interface StyleValue {\n readonly [StyleValueTypeId]: true\n readonly classes: ReadonlyArray<string>\n readonly style: Readonly<Record<string, string>>\n /** Input-driven pieces resolved at render time; empty for a static style. */\n readonly conditions?: ReadonlyArray<StyleCondition>\n /** Pieces that depend on which repetition of a slot is rendered. */\n readonly items?: ReadonlyArray<(item: SlotItem | undefined) => StyleValue>\n /** Rule-based appearance compiled to a deterministic class plus CSS. */\n readonly rules?: ReadonlyArray<StyleRule>\n /** Class-independent CSS (keyframes, layers, global rules). */\n readonly globalCss?: ReadonlyArray<string>\n}\n\nexport interface StyleCondition {\n readonly predicate: (input: unknown) => boolean\n readonly piece: StyleValue\n}\n\nconst tokens = (value: string): ReadonlyArray<string> =>\n value.split(/\\s+/).filter(token => token.length > 0)\n\nconst noClasses: ReadonlyArray<string> = Object.freeze([])\nconst noStyle: Readonly<Record<string, string>> = Object.freeze({})\n\n/** A frozen `StyleValue` from its parts; absent classes and style are empty. */\nexport const make = (parts: Partial<Omit<StyleValue, typeof StyleValueTypeId>>): StyleValue => {\n const value: StyleValue = {\n [StyleValueTypeId]: true,\n ...parts,\n classes: parts.classes ?? noClasses,\n style: parts.style ?? noStyle,\n }\n return Object.freeze(value)\n}\n\nexport const isStyleValue = (value: unknown): value is StyleValue =>\n typeof value === 'object' && value !== null && Object.hasOwn(value, StyleValueTypeId)\n\nexport const empty: StyleValue = make({})\n\n/**\n * A piece as written: a `StyleValue`; a declarations object, which means\n * `Style.self(declarations)`; or pieces composed in order.\n */\nexport type Piece =\n | StyleValue\n // Without `classes`, so an object shaped like a StyleValue is not taken for declarations.\n | (Declarations & { readonly classes?: never })\n | ReadonlyArray<Piece>\n\nconst isPieceList = (value: Piece): value is ReadonlyArray<Piece> => Array.isArray(value)\n\n/** The `StyleValue` a written piece stands for. */\nexport const toStyleValue = (value: Piece): StyleValue => {\n if (isStyleValue(value)) return value\n if (isPieceList(value)) return compose(...value)\n return Object.keys(value).length === 0 ? empty : self(value)\n}\n\nexport const classPiece = (value: string): StyleValue =>\n make({ classes: Object.freeze(tokens(value)) })\n\nexport const inline = (value: Declarations): StyleValue =>\n make({ style: Object.freeze({ ...value }) })\n\n/** Concatenate classes; later inline declarations win per property. */\nexport const compose = (...written: ReadonlyArray<Piece>): StyleValue => {\n const pieces = written.map(toStyleValue)\n const conditions = pieces.flatMap(piece => piece.conditions ?? [])\n const items = pieces.flatMap(piece => piece.items ?? [])\n const rules = pieces.flatMap(piece => piece.rules ?? [])\n const globalCss = pieces.flatMap(piece => piece.globalCss ?? [])\n return make({\n classes: Object.freeze(pieces.flatMap(piece => piece.classes)),\n style: Object.freeze(Object.assign(Object.create(null), ...pieces.map(piece => piece.style))),\n ...(conditions.length === 0 ? {} : { conditions: Object.freeze(conditions) }),\n ...(items.length === 0 ? {} : { items: Object.freeze(items) }),\n ...(rules.length === 0 ? {} : { rules: Object.freeze(rules) }),\n ...(globalCss.length === 0 ? {} : { globalCss: Object.freeze(globalCss) }),\n })\n}\n\n/** A pseudo-class/element rule, e.g. `Style.pseudo(':hover', { color: 'red' })`. */\nexport const pseudo = (suffix: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.pseudo(suffix, declarations)]),\n })\n\n/**\n * Declarations on the element itself, as a rule on its generated class\n * (`&{…}`) rather than inline, so `Layers.in` can place them in a layer and a\n * later layer can override them. Inline declarations sit outside every layer.\n */\nexport const self = (declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.rule('&', declarations)]),\n })\n\n/** An at-rule, e.g. `Style.media('(min-width: 40rem)', { color: 'red' })`. */\nexport const media = (query: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.media(query, declarations)]),\n })\n\n/** An at-rule, e.g. `Style.supports('(display: grid)', { display: 'grid' })`. */\nexport const supports = (condition: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.supports(condition, declarations)]),\n })\n\n/** A container query, e.g. `Style.container('(min-width: 30rem)', {...})`. */\nexport const container = (condition: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.container(condition, declarations)]),\n })\n\n/**\n * A piece's rules inside an at-rule, where one constructor alone cannot put\n * them: `Style.at('@container builder (max-width: 40rem)',\n * Style.pseudo('[data-open=\"false\"]', { display: 'none' }))`. Its inline\n * declarations become a rule on the element. A class, a condition, a\n * per-item piece, global CSS or a rule already inside an at-rule cannot be\n * put inside one, and throws here.\n */\nexport const at = (prelude: string, piece: StyleValue): StyleValue => {\n const refuse = (what: string): never => {\n throw new Error(`Style.at: ${what} cannot go inside \"${prelude}\"`)\n }\n if (!prelude.startsWith('@')) refuse('anything but an at-rule prelude')\n if (piece.classes.length > 0) refuse('a class')\n if ((piece.conditions ?? []).length > 0 || (piece.items ?? []).length > 0)\n refuse('a piece chosen when drawn')\n if ((piece.globalCss ?? []).length > 0) refuse('global CSS')\n const own = Object.keys(piece.style).length === 0 ? [] : [Rules.rule('&', piece.style)]\n return make({\n rules: Object.freeze(\n [...own, ...(piece.rules ?? [])].map(rule =>\n rule.at === undefined\n ? Object.freeze({ ...rule, at: prelude })\n : refuse(`a rule inside \"${rule.at}\"`),\n ),\n ),\n })\n}\n\n/** A nested selector relative to the generated class, e.g. `Style.nest('> span', {...})`. */\nexport const nest = (selector: string, declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.nest(selector, declarations)]),\n })\n\n/**\n * A deterministic `@keyframes` block. Compose `style` where the animation is\n * declared and reference `name` in an `animation` declaration.\n */\nexport const keyframes = (\n frames: Readonly<Record<string, Declarations>>,\n): { readonly name: string; readonly style: StyleValue } => {\n const compiled = Rules.keyframes(frames)\n return Object.freeze({\n name: compiled.name,\n style: make({\n globalCss: Object.freeze([compiled.css]),\n }),\n })\n}\n\n/** Raw class-independent CSS (a layer, a global rule). Prefer typed helpers. */\nexport const global = (css: string): StyleValue =>\n make({\n globalCss: Object.freeze([css]),\n })\n\n/**\n * Appearance per `data-state` value, e.g. `Style.states({ open: { opacity: '1' } })`\n * compiles to `&[data-state=\"open\"]`. Pairs with Behaviors that write\n * `data-state`, so state is styled with no JavaScript and no `whenInput`:\n * `whenInput` when the view knows, `states` when the DOM does.\n */\nexport const states = (\n map: Readonly<Record<string, Declarations>>,\n attribute = 'data-state',\n): StyleValue =>\n make({\n rules: Object.freeze(\n Object.entries(map).map(([state, declarations]) =>\n Rules.pseudo(`[${attribute}=\"${state}\"]`, declarations),\n ),\n ),\n })\n\n/**\n * Declarations per named breakpoint, e.g.\n * `Style.responsive({ md: '(min-width: 48rem)' }, { md: { display: 'flex' } })`.\n * The breakpoint names come from the record you pass, typically a theme's, so\n * a misspelled one is a type error. A breakpoint is a media query, or a whole\n * at-rule: `'@container page (min-width: 48rem)'` measures the container named\n * `page` rather than the window (`Theme.inContainer` writes these).\n */\nexport const responsive = <Breakpoints extends Readonly<Record<string, string>>>(\n breakpoints: Breakpoints,\n map: Partial<Readonly<Record<keyof Breakpoints & string, Declarations>>>,\n): StyleValue =>\n make({\n rules: Object.freeze(\n Object.entries(map).flatMap(([name, declarations]) => {\n const query = breakpoints[name]\n if (query === undefined || declarations === undefined) return []\n return [\n query.startsWith('@')\n ? Rules.rule('&', declarations, query)\n : Rules.media(query, declarations),\n ]\n }),\n ),\n })\n\n/** Custom properties on the slot: `Style.vars({ '--gap': '1rem' })`. */\nexport const vars = (values: Readonly<Record<`--${string}`, string>>): StyleValue => inline(values)\n\nexport interface GridConfig<Area extends string> {\n /** Rows of area names; `'.'` is an empty cell. Every row has the same length. */\n readonly areas: ReadonlyArray<ReadonlyArray<Area>>\n readonly columns?: string\n readonly rows?: string\n readonly gap?: string\n}\n\nexport interface Grid<Area extends string> {\n /** The container's declarations: `display: grid` and the template. */\n readonly style: StyleValue\n /** A child's `grid-area`; only the names the template declares are accepted. */\n readonly area: (name: Area) => StyleValue\n /** The declared names, in first-appearance order. */\n readonly areas: ReadonlyArray<Area>\n}\n\n/**\n * A grid template with typed areas, so a child cannot name an area the\n * parent lacks: `const Page = Style.grid({ areas: [['header', 'header'],\n * ['nav', 'main']] })`, then `Page.area('main')` on the child and\n * `Page.area('footer')` is a type error. A ragged template raises\n * `mixins:ragged-grid-areas`.\n */\nexport const grid = <const Area extends string>(\n config: GridConfig<Area>,\n): Grid<Exclude<Area, '.'>> => {\n const width = config.areas[0]?.length ?? 0\n if (config.areas.some(row => row.length !== width)) {\n throw new DiagnosticError({\n source: 'mixins',\n code: 'mixins:ragged-grid-areas',\n severity: 'error',\n message: `Style.grid areas must be rectangular; rows have lengths ${config.areas.map(row => row.length).join(', ')}`,\n })\n }\n const names: Array<Exclude<Area, '.'>> = []\n for (const row of config.areas) {\n for (const cell of row) {\n if (cell !== '.' && !names.includes(cell as Exclude<Area, '.'>)) {\n names.push(cell as Exclude<Area, '.'>)\n }\n }\n }\n return Object.freeze({\n // Rules, not inline declarations, so a later layer can override the template.\n style: self({\n display: 'grid',\n gridTemplateAreas: config.areas.map(row => `\"${row.join(' ')}\"`).join(' '),\n ...(config.columns === undefined ? {} : { gridTemplateColumns: config.columns }),\n ...(config.rows === undefined ? {} : { gridTemplateRows: config.rows }),\n ...(config.gap === undefined ? {} : { gap: config.gap }),\n }),\n area: (name: Exclude<Area, '.'>) => self({ gridArea: name }),\n areas: Object.freeze(names),\n })\n}\n\n/**\n * The declarations an element starts from when it enters, as a\n * `@starting-style` rule. With a `transition` on the base, the browser\n * animates from these; pair with `allowDiscrete` when `display` takes part.\n */\nexport const enter = (declarations: Declarations): StyleValue =>\n make({\n rules: Object.freeze([Rules.rule('&', declarations, '@starting-style')]),\n })\n\n/** `transition-behavior: allow-discrete`, so `display` and `overlay` transition too. */\nexport const allowDiscrete: StyleValue = inline({ transitionBehavior: 'allow-discrete' })\n\n/** Opts the slot into Foldkit's view transitions under `name`. */\nexport const viewTransitionName = (name: string): StyleValue => inline({ viewTransitionName: name })\n"],"mappings":";;;AA0CA,IAAa,kBAAb,cAAqC,MAAM;CACzC;CAEA,YAAY,YAAwB;EAClC,MAAM,WAAW,OAAO;EACxB,KAAK,OAAO;EACZ,KAAK,aAAa;CACpB;AACF;;;ACnCA,MAAa,QACX,UACA,cACA,OAEA,OAAO,OAAO;CACZ;CACA,cAAc,OAAO,OAAO,EAAE,GAAG,aAAa,CAAC;CAC/C,GAAI,OAAO,KAAA,IAAY,CAAC,IAAI,EAAE,GAAG;AACnC,CAAC;;;;;AAMH,MAAa,gBAAgB,aAA4C;CACvE,MAAM,QAAuB,CAAC;CAC9B,IAAI,QAAQ;CACZ,IAAI;CACJ,IAAI,QAAQ;CACZ,KAAK,IAAI,QAAQ,GAAG,QAAQ,SAAS,QAAQ,SAAS;EACpD,MAAM,OAAO,SAAS;EACtB,IAAI,UAAU,KAAA,GAAW;GACvB,IAAI,SAAS,MAAM;QACd,IAAI,SAAS,OAAO,QAAQ,KAAA;EACnC,OAAO,IAAI,SAAS,QAAO,SAAS,KAAK,QAAQ;OAC5C,IAAI,SAAS,OAAO,SAAS,KAAK;OAClC,IAAI,SAAS,OAAO,SAAS,KAAK;OACl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