@weasel-js/theme 1.12.0 → 1.13.0-rc.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 +1 -1
- package/dist/{chunk-GE2WCTOV.js → chunk-EJBP2YIO.js} +19 -23
- package/dist/chunk-EJBP2YIO.js.map +1 -0
- package/dist/{chunk-JX2OC444.js → chunk-R2SSGWGZ.js} +104 -174
- package/dist/chunk-R2SSGWGZ.js.map +1 -0
- package/dist/{chunk-QGOGBCYW.js → chunk-R7OXPHZJ.js} +19 -19
- package/dist/{chunk-QGOGBCYW.js.map → chunk-R7OXPHZJ.js.map} +1 -1
- package/dist/{definition-CSeERbSL.d.ts → definition-wsEi-XBr.d.ts} +78 -108
- package/dist/engine.d.ts +2 -2
- package/dist/engine.js +21 -15
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +33 -14
- package/dist/index.js +31 -12
- package/dist/index.js.map +1 -1
- package/dist/prefs.d.ts +1 -1
- package/dist/prefs.js +2 -2
- package/dist/react.d.ts +12 -12
- package/dist/react.js +13 -13
- package/dist/react.js.map +1 -1
- package/dist/themes/platinum.d.ts +2 -2
- package/dist/themes/platinum.js +18 -7
- package/dist/themes/platinum.js.map +1 -1
- package/dist/themes/win9x.d.ts +2 -2
- package/dist/themes/win9x.js +18 -7
- package/dist/themes/win9x.js.map +1 -1
- package/dist/tokens.css +12 -23
- package/package.json +4 -4
- package/dist/chunk-GE2WCTOV.js.map +0 -1
- package/dist/chunk-JX2OC444.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { generate, DEFAULT_CONSTRAINTS } from './chunk-S7MJPFDP.js';
|
|
2
2
|
import { readCssNumber } from './chunk-M3R5MV7Q.js';
|
|
3
3
|
import { themeAxes, resolveTheme, atAlpha, withAlpha, themeChain } from './chunk-32JKTYS2.js';
|
|
4
|
-
import { weaselTheme } from './chunk-
|
|
4
|
+
import { weaselTheme } from './chunk-R2SSGWGZ.js';
|
|
5
5
|
import { fullSelection } from './chunk-P5F3GZV6.js';
|
|
6
6
|
import { resolvePaletteColor, colorLiteralToCss, parseColor, interpolateSrgb, rgbaToHex, cssColorLiteral } from '@weasel-js/paint';
|
|
7
7
|
|
|
@@ -199,8 +199,8 @@ function rampSteps(theme, ramp) {
|
|
|
199
199
|
if (!steps) throw new Error(`Theme "${theme.name}" has no ramp "${ramp}"`);
|
|
200
200
|
return steps;
|
|
201
201
|
}
|
|
202
|
-
function
|
|
203
|
-
for (const t of themeChain(theme).reverse()) if (t.
|
|
202
|
+
function themeTints(theme) {
|
|
203
|
+
for (const t of themeChain(theme).reverse()) if (t.tints) return t.tints;
|
|
204
204
|
return { ramp: "swatch" };
|
|
205
205
|
}
|
|
206
206
|
var fallback;
|
|
@@ -222,9 +222,9 @@ function colorCount(list, ctx = defaultContext()) {
|
|
|
222
222
|
if ("ramp" in list) return rampSteps(ctx.theme, list.ramp).length;
|
|
223
223
|
return "generate" in list ? list.generate.count : list.length;
|
|
224
224
|
}
|
|
225
|
-
var
|
|
225
|
+
var TINT_REF = "tint";
|
|
226
226
|
var NO_PALETTE = { entries: [] };
|
|
227
|
-
var
|
|
227
|
+
var tintsOf = (ctx) => ctx.tints ?? themeTints(ctx.theme);
|
|
228
228
|
function parsed(css) {
|
|
229
229
|
try {
|
|
230
230
|
return cssColorLiteral(css);
|
|
@@ -248,14 +248,14 @@ function tokenLiteral(property, ctx) {
|
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
var isRef = (source) => typeof source !== "function" && "ref" in source;
|
|
251
|
-
function
|
|
252
|
-
const
|
|
253
|
-
if (isRamp(
|
|
254
|
-
const item = colorItemAt(
|
|
251
|
+
function tintSource(index, ctx) {
|
|
252
|
+
const tints = tintsOf(ctx);
|
|
253
|
+
if (isRamp(tints)) return tokenLiteral(rampProperty(tints, index, ctx.theme), ctx);
|
|
254
|
+
const item = colorItemAt(tints, index);
|
|
255
255
|
return typeof item === "string" ? parsed(item) : item;
|
|
256
256
|
}
|
|
257
257
|
function themeSource(ref, ctx) {
|
|
258
|
-
if (ref.ref ===
|
|
258
|
+
if (ref.ref === TINT_REF) return tintSource(ref.index ?? 0, ctx);
|
|
259
259
|
const property = propertyOf(ref, ctx);
|
|
260
260
|
return property === null ? null : tokenLiteral(property, ctx);
|
|
261
261
|
}
|
|
@@ -266,16 +266,16 @@ function literalCss(source, ctx) {
|
|
|
266
266
|
const literal = colorSourceLiteral(source, ctx);
|
|
267
267
|
return literal && colorLiteralToCss(literal);
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
const
|
|
269
|
+
function tintCss(source, ctx) {
|
|
270
|
+
const tints = tintsOf(ctx);
|
|
271
271
|
const index = source.index ?? 0;
|
|
272
|
-
if (isRamp(
|
|
273
|
-
const item = colorItemAt(
|
|
272
|
+
if (isRamp(tints)) return `var(${rampProperty(tints, index, ctx.theme)})`;
|
|
273
|
+
const item = colorItemAt(tints, index);
|
|
274
274
|
if (typeof item === "string") return item;
|
|
275
|
-
return isRef(item) && item.ref !==
|
|
275
|
+
return isRef(item) && item.ref !== TINT_REF ? colorSourceCss(item, ctx) : literalCss(source, ctx);
|
|
276
276
|
}
|
|
277
277
|
function themeRefCss(ref, ctx) {
|
|
278
|
-
if (ref.ref ===
|
|
278
|
+
if (ref.ref === TINT_REF) return tintCss(ref, ctx);
|
|
279
279
|
const property = propertyOf(ref, ctx);
|
|
280
280
|
if (property === null) return null;
|
|
281
281
|
return ref.ref.startsWith("--") || tokenLiteral(property, ctx) ? `var(${property})` : null;
|
|
@@ -334,6 +334,6 @@ function colorCssAt(list, i, ctx = defaultContext()) {
|
|
|
334
334
|
return typeof item === "string" ? item : answered(colorSourceCss(item, ctx), i);
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
export {
|
|
338
|
-
//# sourceMappingURL=chunk-
|
|
339
|
-
//# sourceMappingURL=chunk-
|
|
337
|
+
export { TINT_REF, applyTheme, blendTheme, colorAt, colorCount, colorCssAt, colorSourceCss, colorSourceLiteral, isColorModePreference, rampSteps, resolveCurrentColor, themeTints };
|
|
338
|
+
//# sourceMappingURL=chunk-R7OXPHZJ.js.map
|
|
339
|
+
//# sourceMappingURL=chunk-R7OXPHZJ.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blendTheme.ts","../src/themeSheet.ts","../src/applyTheme.ts","../src/currentColor.ts","../src/colorMode.ts","../src/colorListItems.ts","../src/colorSource.ts","../src/colorList.ts"],"names":["colorLiteralToCss"],"mappings":";;;;;;;AAcA,IAAM,QAAA,GAAW,CAAC,OAAA,KAAyC,OAAA,CAAQ,OAAO,CAAC,IAAA,EAAM,CAAA,KAAO,CAAA,CAAE,MAAA,GAAS,IAAA,CAAK,MAAA,GAAS,CAAA,GAAI,IAAK,CAAA,CAAE,GAAA;AAE5H,SAAS,aAAa,OAAA,EAAkD;AACtE,EAAA,IAAI,GAAA,GAAM,CAAA;AACV,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,IAAI,IAAA;AACJ,EAAA,KAAA,MAAW,EAAE,GAAA,EAAK,MAAA,EAAO,IAAK,OAAA,EAAS;AACrC,IAAA,MAAM,IAAA,GAAO,cAAc,GAAG,CAAA;AAC9B,IAAA,IAAI,CAAC,IAAA,IAAS,IAAA,KAAS,UAAa,IAAA,CAAK,IAAA,KAAS,MAAO,OAAO,MAAA;AAChE,IAAA,IAAA,GAAO,IAAA,CAAK,IAAA;AACZ,IAAA,GAAA,IAAO,KAAK,KAAA,GAAQ,MAAA;AACpB,IAAA,KAAA,IAAS,MAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAA,EAAG,QAAQ,GAAA,GAAM,KAAA,EAAO,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAG,IAAI,CAAA,CAAA;AACnD;AAEA,SAAS,YAAY,OAAA,EAAkD;AACrE,EAAA,IAAI,KAAA;AACJ,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,KAAA,MAAW,EAA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AG,OAAO,CAAA,IAAA,EAAO,aAAa,IAAA,EAAM,CAAA,EAAG,GAAA,CAAI,KAAK,CAAC,CAAA,CAAA,CAAA;AAChE,EAAA,MAAM,IAAA,GAAO,WAAA,CAAY,IAAA,EAAM,CAAC,CAAA;AAChC,EAAA,OAAO,OAAO,SAAS,QAAA,GAAW,IAAA,GAAO,SAAS,cAAA,CAAe,IAAA,EAAM,GAAG,CAAA,EAAG,CAAC,CAAA;AAChF","file":"chunk-QGOGBCYW.js","sourcesContent":["import { interpolateSrgb, parseColor, rgbaToHex } from '@weasel-js/paint';\nimport { fullSelection, type Selection } from './axes.ts';\nimport { readCssNumber } from './cssNumber.ts';\nimport { resolveTheme, themeAxes, type ResolvedTheme } from './resolveTheme.ts';\nimport type { Theme } from './theme.ts';\n\n/** A weight for each value of each axis a blend is made along. A value left out weighs nothing. */\nexport type AxisWeights = Readonly<Record<string, Readonly<Record<string, number>>>>;\n\ninterface Weighted {\n readonly css: string;\n readonly weight: number;\n}\n\nconst heaviest = (members: readonly Weighted[]): string => members.reduce((most, m) => (m.weight > most.weight ? m : most)).css;\n\nfunction blendNumbers(members: readonly Weighted[]): string | undefined {\n let sum = 0;\n let total = 0;\n let unit: string | undefined;\n for (const { css, weight } of members) {\n const read = readCssNumber(css);\n if (!read || (unit !== undefined && read.unit !== unit)) return undefined;\n unit = read.unit;\n sum += read.value * weight;\n total += weight;\n }\n return `${Number((sum / total).toFixed(4))}${unit}`;\n}\n\nfunction blendColors(members: readonly Weighted[]): string | undefined {\n let mixed: [number, number, number, number] | undefined;\n let total = 0;\n for (const { css, weight } of members) {\n let next: readonly [number, number, number, number];\n try {\n next = parseColor(css);\n } catch {\n return undefined;\n }\n total += weight;\n if (!mixed) {\n mixed = [...next];\n continue;\n }\n const t = weight / total;\n const [r, g, b] = interpolateSrgb([mixed[0], mixed[1], mixed[2]], [next[0], next[1], next[2]], t, 'oklch');\n mixed = [r, g, b, mixed[3] + (next[3] - mixed[3]) * t];\n }\n return rgbaToHex(mixed!);\n}\n\nfunction blend(members: readonly Weighted[]): string {\n if (members.every((m) => m.css === members[0]!.css)) return members[0]!.css;\n return blendNumbers(members) ?? blendColors(members) ?? heaviest(members);\n}\n\n/**\n * `theme` partway between values of its axes: resolved at every selection\n * `weights` gives a share to, and each token folded from what it resolved to\n * there. A color mixes in OKLCH and a number with one unit throughout mixes\n * linearly; any other value is the heaviest selection's, the first on a tie.\n * It is the resolved values that mix, never the rules behind them, so a token\n * that is an alias in one mode and a literal in the other blends like any\n * other. An axis `weights` leaves out stays at `selection`.\n */\nexport function blendTheme(theme: Theme, weights: AxisWeights, selection: Selection = {}): ResolvedTheme {\n const axes = themeAxes(theme);\n let at: { selection: Selection; weight: number }[] = [{ selection: fullSelection(axes, selection), weight: 1 }];\n for (const [axis, shares] of Object.entries(weights)) {\n if (!Object.hasOwn(axes, axis)) continue;\n const given = Object.entries(shares).filter(([value, share]) => share > 0 && Object.hasOwn(axes[axis]!.values, value));\n if (given.length === 0) continue;\n at = at.flatMap((one) => given.map(([value, share]) => ({ selection: { ...one.selection, [axis]: value }, weight: one.weight * share })));\n }\n const resolved = at.map((one) => ({ tokens: resolveTheme(theme, one.selection) as Record<string, string>, weight: one.weight }));\n if (resolved.length === 1) return resolved[0]!.tokens as ResolvedTheme;\n\n const out: Record<string, string> = {};\n const names = new Set(resolved.flatMap((one) => Object.keys(one.tokens)));\n for (const name of names) {\n out[name] = blend(resolved.filter((one) => one.tokens[name] !== undefined).map((one) => ({ css: one.tokens[name]!, weight: one.weight })));\n }\n return out as ResolvedTheme;\n}\n","/**\n * The stylesheet a document or a shadow root holds its themes' rules in, and\n * the count of what still uses each one.\n *\n * A rule lives where its elements do: a popout window's document and a shadow\n * root each get a sheet of their own, since a rule in the opener's document\n * styles nothing in either. A rule nobody holds any more leaves its sheet, so\n * a page that mints a theme per instance holds only the live ones.\n */\n\n/** Where an element's styles come from. */\nexport type StyleRoot = Document | ShadowRoot;\n\nconst STYLE_ID = 'wzl-themes';\n\ninterface Variant {\n /** 0 is the definition that has the bare selector; a second, different\n * definition held at once under the same name and selection gets its own. */\n id: number;\n body: string;\n holds: number;\n}\n\ninterface RootSheet {\n /** `selector` → the definitions held under it. */\n rules: Map<string, Variant[]>;\n sheet: CSSStyleSheet | null;\n styleEl: HTMLStyleElement | null;\n}\n\nlet sheets = new WeakMap<StyleRoot, RootSheet>();\n\n/** Test seam: forgets every sheet, so each case starts clean. */\nexport function __resetThemeSheet(): void {\n sheets = new WeakMap();\n}\n\n/** The root `el`'s styles come from: its shadow root, else its document. */\nexport function styleRootOf(el: Element): StyleRoot {\n const root = el.getRootNode();\n return root instanceof (el.ownerDocument.defaultView?.ShadowRoot ?? ShadowRoot) ? (root as ShadowRoot) : el.ownerDocument;\n}\n\nconst documentOf = (root: StyleRoot): Document => ('host' in root ? root.ownerDocument : root);\n\n/** The selector suffix that keeps a variant's rule off the other definitions' elements, at no cost in specificity. */\nconst only = (id: number): string => (id === 0 ? '' : `:where([data-wzl-variant='${id}'])`);\n\nfunction write(root: StyleRoot, held: RootSheet): void {\n const css = [...held.rules]\n .flatMap(([selector, variants]) =>\n // The bare rule first: it matches a variant's elements too, and the variant's has to win the tie.\n [...variants].sort((a, b) => a.id - b.id).map((v) => `${selector}${only(v.id)} { ${v.body} }`))\n .join('\\n');\n // Not `@weasel-js/react`'s `adoptCss`: this entry loads without React.\n const win = documentOf(root).defaultView;\n const Sheet = win?.CSSStyleSheet;\n if (Sheet && 'replaceSync' in Sheet.prototype && Array.isArray(root.adoptedStyleSheets)) {\n if (!held.sheet) {\n // From the root's own window: a constructed sheet cannot be adopted across documents.\n held.sheet = new Sheet();\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, held.sheet];\n }\n held.sheet.replaceSync(css);\n return;\n }\n if (!held.styleEl) {\n held.styleEl = documentOf(root).createElement('style');\n held.styleEl.id = STYLE_ID;\n ('host' in root ? root : root.head).appendChild(held.styleEl);\n }\n held.styleEl.textContent = css;\n}\n\n/**\n * Hold the rule `selector { body }` in `root`'s sheet. Returns the variant id\n * the holder's element is to carry (0 for none) and the release, which takes\n * the rule out of the sheet once nothing else holds it.\n */\nexport function holdRule(root: StyleRoot, selector: string, body: string): { variant: number; release: () => void } {\n let held = sheets.get(root);\n if (!held) sheets.set(root, (held = { rules: new Map(), sheet: null, styleEl: null }));\n const variants = held.rules.get(selector) ?? [];\n let variant = variants.find((v) => v.body === body);\n if (variant) {\n variant.holds++;\n } else {\n let id = 0;\n while (variants.some((v) => v.id === id)) id++;\n variant = { id, body, holds: 1 };\n held.rules.set(selector, [...variants, variant]);\n write(root, held);\n }\n const mine = variant;\n const sheet = held;\n let released = false;\n return {\n variant: mine.id,\n release: () => {\n if (released) return;\n released = true;\n if (--mine.holds > 0) return;\n const left = (sheet.rules.get(selector) ?? []).filter((v) => v !== mine);\n if (left.length > 0) sheet.rules.set(selector, left);\n else sheet.rules.delete(selector);\n write(root, sheet);\n },\n };\n}\n","import { fullSelection, type Selection } from './axes';\nimport { blendTheme, type AxisWeights } from './blendTheme';\nimport { resolveTheme, themeAxes } from './resolveTheme';\nimport type { Theme } from './theme';\nimport { holdRule, styleRootOf } from './themeSheet';\n\nexport { __resetThemeSheet } from './themeSheet';\n\n/** What an element holds from its last `applyTheme`, so the next one, or its release, can let go of it. */\nconst holds = new WeakMap<HTMLElement, () => void>();\n\n/**\n * Apply `theme` at `selection` to `el`'s subtree, and return the release.\n *\n * Stamps `data-wzl-theme` and one `data-wzl-<axis>` per axis, and holds a\n * matching rule block in the stylesheet of the document or shadow root `el`\n * lives in. Deliberately not inline properties: the cascade then does the\n * work, per-subtree overrides are just a different theme name, and no\n * `!important` is ever needed. No-op outside a DOM.\n *\n * An element holds one application: applying again replaces what it held, so\n * a caller restyling one root never has to release. The release is for a\n * subtree that goes away. It takes the attributes back off and lets go of the\n * rule, which leaves the sheet once no element holds it; a release whose\n * element has since been given something else does nothing.\n *\n * With `weights`, the rule holds the theme blended along the axes they name\n * (see `blendTheme`), under the same attributes: applying again with the next\n * weights is one step of a transition between two selections.\n *\n * Two different themes may share a name. The second held at once has its rule\n * kept to its own elements by a `data-wzl-variant` attribute, matched inside\n * `:where()` so the rule's specificity is the first's.\n */\nexport function applyTheme(el: HTMLElement, theme: Theme, selection: Selection = {}, options: { weights?: AxisWeights } = {}): () => void {\n if (typeof document === 'undefined') return () => {};\n\n const axes = themeAxes(theme);\n const sel = fullSelection(axes, selection);\n const body = Object.entries(options.weights ? blendTheme(theme, options.weights, sel) : resolveTheme(theme, sel))\n .map(([name, value]) => `${name}: ${value};`)\n .join(' ');\n const names = Object.keys(axes);\n const selector = `[data-wzl-theme='${theme.name}']${names.map((a) => `[data-wzl-${a}='${sel[a]}']`).join('')}`;\n // Held before the last one is let go, so re-applying the same rule rewrites nothing.\n const { variant, release: releaseRule } = holdRule(styleRootOf(el), selector, body);\n holds.get(el)?.();\n\n el.setAttribute('data-wzl-theme', theme.name);\n for (const a of names) el.setAttribute(`data-wzl-${a}`, sel[a]);\n if (variant === 0) el.removeAttribute('data-wzl-variant');\n else el.setAttribute('data-wzl-variant', String(variant));\n\n // The attributes go only through `release`: a hold replaced by the next application leaves them to it.\n const letGo = (): void => {\n holds.delete(el);\n releaseRule();\n };\n holds.set(el, letGo);\n return () => {\n if (holds.get(el) !== letGo) return;\n letGo();\n for (const a of ['theme', 'variant', ...names]) el.removeAttribute(`data-wzl-${a}`);\n };\n}\n","import { atAlpha, withAlpha } from './dtcg/color.ts';\n\nconst NUMBER = String.raw`(\\d*\\.?\\d+)(%?)`;\nconst RELATIVE = new RegExp(String.raw`^rgb\\(\\s*from\\s+currentcolor\\s+r\\s+g\\s+b\\s*/\\s*${NUMBER}\\s*\\)$`, 'i');\nconst MIX = new RegExp(String.raw`^color-mix\\(\\s*in\\s+[\\w-]+\\s*,\\s*currentcolor\\s+${NUMBER}\\s*,\\s*transparent\\s*\\)$`, 'i');\n\nconst fraction = (n: string, pct: string) => Number(n) / (pct ? 100 : 1);\n\n/**\n * A resolved token value with `currentColor` taken to be `current`, for a surface drawn without the\n * cascade — a canvas reading a resolved theme — where `currentColor` has nothing to resolve against.\n * Pass the color of the text the value is drawn beside, usually `--wzl-fg`. A value that never\n * mentions `currentColor` comes back unchanged.\n *\n * Flattens the forms the kit's themes write: bare `currentColor`, `rgb(from currentColor r g b / a)`\n * and `color-mix(in <space>, currentColor p%, transparent)`. Throws on any other use of it.\n */\nexport function resolveCurrentColor(value: string, current: string): string {\n const v = value.trim();\n if (!/currentcolor/i.test(v)) return value;\n if (/^currentcolor$/i.test(v)) return current;\n const rel = RELATIVE.exec(v);\n if (rel) return atAlpha(current, fraction(rel[1], rel[2]));\n const mix = MIX.exec(v);\n if (mix && mix[2] === '%') return withAlpha(current, fraction(mix[1], mix[2]));\n throw new Error(`resolveCurrentColor: cannot flatten \"${value}\"`);\n}\n","/** A color mode the theme's `mode` axis resolves. */\nexport type ColorMode = 'light' | 'dark';\n\n/**\n * What a user chose: a mode, or `'auto'` — follow the OS, live. `'auto'` is\n * not a mode; resolve it with `useResolvedColorMode` before handing it to a\n * `ThemeProvider` selection.\n */\nexport type ColorModePreference = 'auto' | ColorMode;\n\n/** Whether a value — say, one read back from storage — is a preference. */\nexport function isColorModePreference(v: unknown): v is ColorModePreference {\n return v === 'auto' || v === 'light' || v === 'dark';\n}\n","import type { ColorLiteral, ColorRef, ColorSource, Palette } from '@weasel-js/paint';\nimport type { CategoricalRampDef } from './definition.ts';\nimport { DEFAULT_CONSTRAINTS, generate, type Constraints } from './engine/color/generate.ts';\nimport { resolveTheme, themeChain, type ResolvedTheme } from './resolveTheme.ts';\nimport { weaselTheme, type Theme } from './theme.ts';\n\n/** The categorical generator the swatch ramp uses, asked for `count` colors. */\nexport interface GeneratedColors {\n readonly generate: { readonly count: number; readonly gates?: CategoricalRampDef['gates'] };\n}\n\n/** A ramp of the active theme, by name — `{ ramp: 'swatch' }` walks its steps in order. */\nexport interface RampColors {\n readonly ramp: string;\n}\n\n/** One color of a list: a CSS color string, or a `ColorSource` resolved when it is read. */\nexport type ColorListItem = string | ColorSource;\n\n/** The forms a theme definition can hold: everything but a function. */\nexport type SerializableColorList = readonly (string | ColorLiteral | ColorRef)[] | GeneratedColors | RampColors;\n\n/**\n * Several colors, read by index with `colorAt`, wrapping. Items, each a CSS\n * string or a `ColorSource`; the swatch ramp's generator; a ramp of the active\n * theme, which follows the mode; or a function of the index.\n */\nexport type ColorList = readonly ColorListItem[] | GeneratedColors | RampColors | ((i: number) => ColorListItem);\n\n/** What a `ColorList` resolves against. `useTheme()`'s value is one. */\nexport interface ColorContext {\n readonly theme: Theme;\n readonly resolved: ResolvedTheme;\n}\n\n/** What a `ColorSource` resolves against under a theme. `useTones()`'s value is one. */\nexport interface ColorSourceContext extends ColorContext {\n /** The list `{ ref: 'tone' }` indexes. Absent: the theme's own. */\n readonly tones?: ColorList;\n /** Names answered before the theme's. */\n readonly palette?: Palette;\n}\n\nconst wrap = (i: number, n: number) => ((Math.trunc(i) % n) + n) % n;\n\nconst generated = new Map<string, readonly string[]>();\n\nfunction generatedColors({ generate: g }: GeneratedColors): readonly string[] {\n const key = JSON.stringify([g.count, g.gates ?? {}]);\n let colors = generated.get(key);\n if (!colors) {\n const palette = generate({ ...DEFAULT_CONSTRAINTS, ...(g.gates as Partial<Constraints>), count: g.count, anchors: [] });\n colors = palette.swatches.map((s) => s.hex.toLowerCase());\n generated.set(key, colors);\n }\n return colors;\n}\n\n/** `rampSteps`, answering `undefined` for a ramp the chain lacks. */\nexport function findRampSteps(theme: Theme, ramp: string): readonly string[] | undefined {\n for (const t of themeChain(theme).reverse()) {\n const steps = t.ramps?.[ramp];\n if (steps) return steps;\n }\n return undefined;\n}\n\n/** A ramp's step names, from the nearest theme in the chain that declares it. */\nexport function rampSteps(theme: Theme, ramp: string): readonly string[] {\n const steps = findRampSteps(theme, ramp);\n if (!steps) throw new Error(`Theme \"${theme.name}\" has no ramp \"${ramp}\"`);\n return steps;\n}\n\n/** The tone list a theme declares, from the nearest theme in its chain that has one. */\nexport function themeTones(theme: Theme): ColorList {\n for (const t of themeChain(theme).reverse()) if (t.tones) return t.tones;\n return { ramp: 'swatch' };\n}\n\nlet fallback: ColorContext | undefined;\nexport const defaultContext = () => (fallback ??= { theme: weaselTheme, resolved: resolveTheme(weaselTheme) });\n\nconst pickStep = (list: RampColors, i: number, theme: Theme): string => {\n const steps = rampSteps(theme, list.ramp);\n return steps[wrap(i, steps.length)];\n};\n\n/** The custom property behind the `i`th step of a ramp list, wrapping. */\nexport const rampProperty = (list: RampColors, i: number, theme: Theme): string =>\n `--wzl-${list.ramp}-${pickStep(list, i, theme)}`;\n\nexport const isRamp = (list: ColorList): list is RampColors => typeof list !== 'function' && 'ramp' in list;\n\n/** The `i`th item of a list that is not a ramp, wrapping, as it was written. */\nexport function colorItemAt(list: Exclude<ColorList, RampColors>, i: number): ColorListItem {\n if (typeof list === 'function') return list(i);\n const colors = 'generate' in list ? generatedColors(list) : list;\n if (colors.length === 0) throw new Error('colorAt: empty color list');\n return colors[wrap(i, colors.length)];\n}\n\n/** How many distinct colors `list` holds before it wraps; `undefined` for a function, which never does. */\nexport function colorCount(list: ColorList, ctx: ColorContext = defaultContext()): number | undefined {\n if (typeof list === 'function') return undefined;\n if ('ramp' in list) return rampSteps(ctx.theme, list.ramp).length;\n return 'generate' in list ? list.generate.count : list.length;\n}\n","import {\n colorLiteralToCss,\n cssColorLiteral,\n resolvePaletteColor,\n type ColorFnContext,\n type ColorLiteral,\n type ColorRef,\n type ColorSource,\n type Palette,\n} from '@weasel-js/paint';\nimport {\n colorItemAt,\n defaultContext,\n findRampSteps,\n isRamp,\n rampProperty,\n themeTones,\n type ColorList,\n type ColorSourceContext,\n} from './colorListItems.ts';\nimport { resolveCurrentColor } from './currentColor.ts';\n\n/** The name the tone list answers to: `{ ref: 'tone', index: 2 }` is the third tone, wrapping. */\nexport const TONE_REF = 'tone';\n\nexport type { ColorSourceContext };\n\nconst NO_PALETTE: Palette = { entries: [] };\n\nconst tonesOf = (ctx: ColorSourceContext): ColorList => ctx.tones ?? themeTones(ctx.theme);\n\nfunction parsed(css: string): ColorLiteral | null {\n try {\n return cssColorLiteral(css);\n } catch {\n return null;\n }\n}\n\n/** The custom property a theme ref names: itself when spelled as one, a token by name, or a ramp step by index. */\nfunction propertyOf(ref: ColorRef, ctx: ColorSourceContext): string | null {\n if (ref.ref.startsWith('--')) return ref.index === undefined ? ref.ref : null;\n if (ref.index === undefined) return `--wzl-${ref.ref}`;\n const step = findRampSteps(ctx.theme, ref.ref)?.[ref.index];\n return step === undefined ? null : `--wzl-${ref.ref}-${step}`;\n}\n\nfunction tokenLiteral(property: string, ctx: ColorSourceContext): ColorLiteral | null {\n const value = (ctx.resolved as Readonly<Record<string, string>>)[property];\n if (value === undefined) return null;\n try {\n return parsed(resolveCurrentColor(value, ctx.resolved['--wzl-fg']));\n } catch {\n return null;\n }\n}\n\nconst isRef = (source: ColorSource): source is ColorRef => typeof source !== 'function' && 'ref' in source;\n\nfunction toneSource(index: number, ctx: ColorSourceContext): ColorSource | null {\n const tones = tonesOf(ctx);\n if (isRamp(tones)) return tokenLiteral(rampProperty(tones, index, ctx.theme), ctx);\n const item = colorItemAt(tones, index);\n return typeof item === 'string' ? parsed(item) : item;\n}\n\nfunction themeSource(ref: ColorRef, ctx: ColorSourceContext): ColorSource | null {\n if (ref.ref === TONE_REF) return toneSource(ref.index ?? 0, ctx);\n const property = propertyOf(ref, ctx);\n return property === null ? null : tokenLiteral(property, ctx);\n}\n\n/**\n * Resolve `source` to a literal, for a surface drawn without the cascade. A ref\n * names an entry of the context's palette first, then the theme: `tone` with an\n * index into the tone list, a token by its name without the `--wzl-` prefix, a\n * ramp by its name with the index of a step, or a custom property spelled out.\n * `null` for a name nothing answers, a token that is not a color, and a custom\n * property the theme does not define.\n */\nexport function colorSourceLiteral(source: ColorSource, ctx: ColorSourceContext = defaultContext()): ColorLiteral | null {\n return resolvePaletteColor(ctx.palette ?? NO_PALETTE, source, (ref) => themeSource(ref, ctx));\n}\n\nfunction literalCss(source: ColorSource, ctx: ColorSourceContext): string | null {\n const literal = colorSourceLiteral(source, ctx);\n return literal && colorLiteralToCss(literal);\n}\n\nfunction toneCss(source: ColorRef, ctx: ColorSourceContext): string | null {\n const tones = tonesOf(ctx);\n const index = source.index ?? 0;\n if (isRamp(tones)) return `var(${rampProperty(tones, index, ctx.theme)})`;\n const item = colorItemAt(tones, index);\n if (typeof item === 'string') return item;\n return isRef(item) && item.ref !== TONE_REF ? colorSourceCss(item, ctx) : literalCss(source, ctx);\n}\n\nfunction themeRefCss(ref: ColorRef, ctx: ColorSourceContext): string | null {\n if (ref.ref === TONE_REF) return toneCss(ref, ctx);\n const property = propertyOf(ref, ctx);\n if (property === null) return null;\n return ref.ref.startsWith('--') || tokenLiteral(property, ctx) ? `var(${property})` : null;\n}\n\nfunction nth<T>(items: Iterable<T>, n: number): T | undefined {\n let i = 0;\n for (const item of items) if (i++ === n) return item;\n return undefined;\n}\n\n/**\n * The theme ref `source` comes down to when followed by name alone, through\n * palette entries and functions that only name another color. `null` when it\n * ends anywhere else, or when a function read a color to compute its own.\n */\nfunction namedThemeRef(source: ColorSource, ctx: ColorSourceContext): ColorRef | null {\n const entries = ctx.palette?.entries ?? [];\n const seen = new Set<string>();\n let read = false;\n const fnCtx: ColorFnContext = {\n resolve: (s) => {\n read = true;\n return colorSourceLiteral(s, ctx);\n },\n };\n let at: ColorSource | null | undefined = source;\n while (at != null && !read) {\n if (typeof at === 'function') {\n at = at(fnCtx);\n continue;\n }\n if (!isRef(at)) return null;\n const { ref, index = 0 } = at;\n const entry = entries.find((e) => e.name === ref);\n if (!entry) return at;\n const key = `${index}:${ref}`;\n if (seen.has(key)) return null;\n seen.add(key);\n if ('color' in entry) at = index === 0 ? entry.color : null;\n else at = nth(entry.colors(fnCtx), index);\n }\n return null;\n}\n\n/**\n * `source` as a CSS color, naming what `colorSourceLiteral` resolves. A source\n * that comes down to a ref the theme answers, directly or through palette\n * entries and functions that only name another color, is written as that\n * ref's custom property: it follows the cascade with no re-render, and a\n * property spelled out need not be the theme's. Everything else is written as\n * the literal it resolves to in `ctx`, which includes a function that reads a\n * color through `resolve` to compute its own.\n */\nexport function colorSourceCss(source: ColorSource, ctx: ColorSourceContext = defaultContext()): string | null {\n const named = namedThemeRef(source, ctx);\n return named ? themeRefCss(named, ctx) : literalCss(source, ctx);\n}\n","import { colorLiteralToCss } from '@weasel-js/paint';\nimport { colorItemAt, defaultContext, isRamp, rampProperty, type ColorList, type ColorSourceContext } from './colorListItems.ts';\nimport { colorSourceCss, colorSourceLiteral } from './colorSource.ts';\nimport type { ResolvedTheme } from './resolveTheme.ts';\n\nexport {\n colorCount,\n findRampSteps,\n rampSteps,\n themeTones,\n type ColorContext,\n type ColorList,\n type ColorListItem,\n type GeneratedColors,\n type RampColors,\n type SerializableColorList,\n} from './colorListItems.ts';\n\nfunction answered(css: string | null, i: number): string {\n if (css === null) throw new Error(`colorAt: nothing answers item ${i} of the color list`);\n return css;\n}\n\n/**\n * The `i`th color of `list`, wrapping. A ramp list reads the resolved theme, so\n * the answer follows its mode; a `ColorSource` item resolves against the\n * context's palette, then its theme. Throws on an item nothing answers.\n */\nexport function colorAt(list: ColorList, i: number, ctx: ColorSourceContext = defaultContext()): string {\n if (isRamp(list)) return ctx.resolved[rampProperty(list, i, ctx.theme) as keyof ResolvedTheme];\n const item = colorItemAt(list, i);\n if (typeof item === 'string') return item;\n const literal = colorSourceLiteral(item, ctx);\n return answered(literal && colorLiteralToCss(literal), i);\n}\n\n/**\n * As `colorAt`, but a ramp list, and an item that names the theme, answers\n * with its custom property (`var(--wzl-swatch-sky)`), so a color written into\n * CSS follows a mode change without re-rendering, provider or not.\n */\nexport function colorCssAt(list: ColorList, i: number, ctx: ColorSourceContext = defaultContext()): string {\n if (isRamp(list)) return `var(${rampProperty(list, i, ctx.theme)})`;\n const item = colorItemAt(list, i);\n return typeof item === 'string' ? item : answered(colorSourceCss(item, ctx), i);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/blendTheme.ts","../src/themeSheet.ts","../src/applyTheme.ts","../src/currentColor.ts","../src/colorMode.ts","../src/colorListItems.ts","../src/colorSource.ts","../src/colorList.ts"],"names":["colorLiteralToCss"],"mappings":";;;;;;;AAcA,IAAM,QAAA,GAAW,CAAC,OAAA,KAAyC,OAAA,CAAQ,OAAO,CAAC,IAAA,EAAM,CAAA,KAAO,CAAA,CAAE,MAAA,GAAS,IAAA,CAAK,MAAA,GAAS,CAAA,GAAI,IAAK,CAAA,CAAE,GAAA;AAE5H,SAAS,aAAa,OAAA,EAAkD;AACtE,EAAA,IAAI,GAAA,GAAM,CAAA;AACV,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,IAAI,IAAA;AACJ,EAAA,KAAA,MAAW,EAAE,GAAA,EAAK,MAAA,EAAO,IAAK,OAAA,EAAS;AACrC,IAAA,MAAM,IAAA,GAAO,cAAc,GAAG,CAAA;AAC9B,IAAA,IAAI,CAAC,IAAA,IAAS,IAAA,KAAS,UAAa,IAAA,CAAK,IAAA,KAAS,MAAO,OAAO,MAAA;AAChE,IAAA,IAAA,GAAO,IAAA,CAAK,IAAA;AACZ,IAAA,GAAA,IAAO,KAAK,KAAA,GAAQ,MAAA;AACpB,IAAA,KAAA,IAAS,MAAA;AAAA,EACX;AACA,EAAA,OAAO,CAAA,EAAG,QAAQ,GAAA,GAAM,KAAA,EAAO,QAAQ,CAAC,CAAC,CAAC,CAAA,EAAG,IAAI,CAAA,CAAA;AACnD;AAEA,SAAS,YAAY,OAAA,EAAkD;AACrE,EAAA,IAAI,KAAA;AACJ,EAAA,IAAI,KAAA,GAAQ,CAAA;AACZ,EAAA,KAAA,MAAW,EAAE,GAAA,EAAK,MAAA,EAAO,IAAK,OAAA,EAAS;AACrC,IAAA,IAAI,IAAA;AACJ,IAAA,IAAI;AACF,MAAA,IAAA,GAAO,WAAW,GAAG,CAAA;AAAA,IACvB,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,MAAA;AAAA,IACT;AACA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QAAA,GAAW,IAAA,GAAO,SAAS,cAAA,CAAe,IAAA,EAAM,GAAG,CAAA,EAAG,CAAC,CAAA;AAChF","file":"chunk-R7OXPHZJ.js","sourcesContent":["import { interpolateSrgb, parseColor, rgbaToHex } from '@weasel-js/paint';\nimport { fullSelection, type Selection } from './axes.ts';\nimport { readCssNumber } from './cssNumber.ts';\nimport { resolveTheme, themeAxes, type ResolvedTheme } from './resolveTheme.ts';\nimport type { Theme } from './theme.ts';\n\n/** A weight for each value of each axis a blend is made along. A value left out weighs nothing. */\nexport type AxisWeights = Readonly<Record<string, Readonly<Record<string, number>>>>;\n\ninterface Weighted {\n readonly css: string;\n readonly weight: number;\n}\n\nconst heaviest = (members: readonly Weighted[]): string => members.reduce((most, m) => (m.weight > most.weight ? m : most)).css;\n\nfunction blendNumbers(members: readonly Weighted[]): string | undefined {\n let sum = 0;\n let total = 0;\n let unit: string | undefined;\n for (const { css, weight } of members) {\n const read = readCssNumber(css);\n if (!read || (unit !== undefined && read.unit !== unit)) return undefined;\n unit = read.unit;\n sum += read.value * weight;\n total += weight;\n }\n return `${Number((sum / total).toFixed(4))}${unit}`;\n}\n\nfunction blendColors(members: readonly Weighted[]): string | undefined {\n let mixed: [number, number, number, number] | undefined;\n let total = 0;\n for (const { css, weight } of members) {\n let next: readonly [number, number, number, number];\n try {\n next = parseColor(css);\n } catch {\n return undefined;\n }\n total += weight;\n if (!mixed) {\n mixed = [...next];\n continue;\n }\n const t = weight / total;\n const [r, g, b] = interpolateSrgb([mixed[0], mixed[1], mixed[2]], [next[0], next[1], next[2]], t, 'oklch');\n mixed = [r, g, b, mixed[3] + (next[3] - mixed[3]) * t];\n }\n return rgbaToHex(mixed!);\n}\n\nfunction blend(members: readonly Weighted[]): string {\n if (members.every((m) => m.css === members[0]!.css)) return members[0]!.css;\n return blendNumbers(members) ?? blendColors(members) ?? heaviest(members);\n}\n\n/**\n * `theme` partway between values of its axes: resolved at every selection\n * `weights` gives a share to, and each token folded from what it resolved to\n * there. A color mixes in OKLCH and a number with one unit throughout mixes\n * linearly; any other value is the heaviest selection's, the first on a tie.\n * It is the resolved values that mix, never the rules behind them, so a token\n * that is an alias in one mode and a literal in the other blends like any\n * other. An axis `weights` leaves out stays at `selection`.\n */\nexport function blendTheme(theme: Theme, weights: AxisWeights, selection: Selection = {}): ResolvedTheme {\n const axes = themeAxes(theme);\n let at: { selection: Selection; weight: number }[] = [{ selection: fullSelection(axes, selection), weight: 1 }];\n for (const [axis, shares] of Object.entries(weights)) {\n if (!Object.hasOwn(axes, axis)) continue;\n const given = Object.entries(shares).filter(([value, share]) => share > 0 && Object.hasOwn(axes[axis]!.values, value));\n if (given.length === 0) continue;\n at = at.flatMap((one) => given.map(([value, share]) => ({ selection: { ...one.selection, [axis]: value }, weight: one.weight * share })));\n }\n const resolved = at.map((one) => ({ tokens: resolveTheme(theme, one.selection) as Record<string, string>, weight: one.weight }));\n if (resolved.length === 1) return resolved[0]!.tokens as ResolvedTheme;\n\n const out: Record<string, string> = {};\n const names = new Set(resolved.flatMap((one) => Object.keys(one.tokens)));\n for (const name of names) {\n out[name] = blend(resolved.filter((one) => one.tokens[name] !== undefined).map((one) => ({ css: one.tokens[name]!, weight: one.weight })));\n }\n return out as ResolvedTheme;\n}\n","/**\n * The stylesheet a document or a shadow root holds its themes' rules in, and\n * the count of what still uses each one.\n *\n * A rule lives where its elements do: a popout window's document and a shadow\n * root each get a sheet of their own, since a rule in the opener's document\n * styles nothing in either. A rule nobody holds any more leaves its sheet, so\n * a page that mints a theme per instance holds only the live ones.\n */\n\n/** Where an element's styles come from. */\nexport type StyleRoot = Document | ShadowRoot;\n\nconst STYLE_ID = 'wzl-themes';\n\ninterface Variant {\n /** 0 is the definition that has the bare selector; a second, different\n * definition held at once under the same name and selection gets its own. */\n id: number;\n body: string;\n holds: number;\n}\n\ninterface RootSheet {\n /** `selector` → the definitions held under it. */\n rules: Map<string, Variant[]>;\n sheet: CSSStyleSheet | null;\n styleEl: HTMLStyleElement | null;\n}\n\nlet sheets = new WeakMap<StyleRoot, RootSheet>();\n\n/** Test seam: forgets every sheet, so each case starts clean. */\nexport function __resetThemeSheet(): void {\n sheets = new WeakMap();\n}\n\n/** The root `el`'s styles come from: its shadow root, else its document. */\nexport function styleRootOf(el: Element): StyleRoot {\n const root = el.getRootNode();\n return root instanceof (el.ownerDocument.defaultView?.ShadowRoot ?? ShadowRoot) ? (root as ShadowRoot) : el.ownerDocument;\n}\n\nconst documentOf = (root: StyleRoot): Document => ('host' in root ? root.ownerDocument : root);\n\n/** The selector suffix that keeps a variant's rule off the other definitions' elements, at no cost in specificity. */\nconst only = (id: number): string => (id === 0 ? '' : `:where([data-wzl-variant='${id}'])`);\n\nfunction write(root: StyleRoot, held: RootSheet): void {\n const css = [...held.rules]\n .flatMap(([selector, variants]) =>\n // The bare rule first: it matches a variant's elements too, and the variant's has to win the tie.\n [...variants].sort((a, b) => a.id - b.id).map((v) => `${selector}${only(v.id)} { ${v.body} }`))\n .join('\\n');\n // Not `@weasel-js/react`'s `adoptCss`: this entry loads without React.\n const win = documentOf(root).defaultView;\n const Sheet = win?.CSSStyleSheet;\n if (Sheet && 'replaceSync' in Sheet.prototype && Array.isArray(root.adoptedStyleSheets)) {\n if (!held.sheet) {\n // From the root's own window: a constructed sheet cannot be adopted across documents.\n held.sheet = new Sheet();\n root.adoptedStyleSheets = [...root.adoptedStyleSheets, held.sheet];\n }\n held.sheet.replaceSync(css);\n return;\n }\n if (!held.styleEl) {\n held.styleEl = documentOf(root).createElement('style');\n held.styleEl.id = STYLE_ID;\n ('host' in root ? root : root.head).appendChild(held.styleEl);\n }\n held.styleEl.textContent = css;\n}\n\n/**\n * Hold the rule `selector { body }` in `root`'s sheet. Returns the variant id\n * the holder's element is to carry (0 for none) and the release, which takes\n * the rule out of the sheet once nothing else holds it.\n */\nexport function holdRule(root: StyleRoot, selector: string, body: string): { variant: number; release: () => void } {\n let held = sheets.get(root);\n if (!held) sheets.set(root, (held = { rules: new Map(), sheet: null, styleEl: null }));\n const variants = held.rules.get(selector) ?? [];\n let variant = variants.find((v) => v.body === body);\n if (variant) {\n variant.holds++;\n } else {\n let id = 0;\n while (variants.some((v) => v.id === id)) id++;\n variant = { id, body, holds: 1 };\n held.rules.set(selector, [...variants, variant]);\n write(root, held);\n }\n const mine = variant;\n const sheet = held;\n let released = false;\n return {\n variant: mine.id,\n release: () => {\n if (released) return;\n released = true;\n if (--mine.holds > 0) return;\n const left = (sheet.rules.get(selector) ?? []).filter((v) => v !== mine);\n if (left.length > 0) sheet.rules.set(selector, left);\n else sheet.rules.delete(selector);\n write(root, sheet);\n },\n };\n}\n","import { fullSelection, type Selection } from './axes';\nimport { blendTheme, type AxisWeights } from './blendTheme';\nimport { resolveTheme, themeAxes } from './resolveTheme';\nimport type { Theme } from './theme';\nimport { holdRule, styleRootOf } from './themeSheet';\n\nexport { __resetThemeSheet } from './themeSheet';\n\n/** What an element holds from its last `applyTheme`, so the next one, or its release, can let go of it. */\nconst holds = new WeakMap<HTMLElement, () => void>();\n\n/**\n * Apply `theme` at `selection` to `el`'s subtree, and return the release.\n *\n * Stamps `data-wzl-theme` and one `data-wzl-<axis>` per axis, and holds a\n * matching rule block in the stylesheet of the document or shadow root `el`\n * lives in. Deliberately not inline properties: the cascade then does the\n * work, per-subtree overrides are just a different theme name, and no\n * `!important` is ever needed. No-op outside a DOM.\n *\n * An element holds one application: applying again replaces what it held, so\n * a caller restyling one root never has to release. The release is for a\n * subtree that goes away. It takes the attributes back off and lets go of the\n * rule, which leaves the sheet once no element holds it; a release whose\n * element has since been given something else does nothing.\n *\n * With `weights`, the rule holds the theme blended along the axes they name\n * (see `blendTheme`), under the same attributes: applying again with the next\n * weights is one step of a transition between two selections.\n *\n * Two different themes may share a name. The second held at once has its rule\n * kept to its own elements by a `data-wzl-variant` attribute, matched inside\n * `:where()` so the rule's specificity is the first's.\n */\nexport function applyTheme(el: HTMLElement, theme: Theme, selection: Selection = {}, options: { weights?: AxisWeights } = {}): () => void {\n if (typeof document === 'undefined') return () => {};\n\n const axes = themeAxes(theme);\n const sel = fullSelection(axes, selection);\n const body = Object.entries(options.weights ? blendTheme(theme, options.weights, sel) : resolveTheme(theme, sel))\n .map(([name, value]) => `${name}: ${value};`)\n .join(' ');\n const names = Object.keys(axes);\n const selector = `[data-wzl-theme='${theme.name}']${names.map((a) => `[data-wzl-${a}='${sel[a]}']`).join('')}`;\n // Held before the last one is let go, so re-applying the same rule rewrites nothing.\n const { variant, release: releaseRule } = holdRule(styleRootOf(el), selector, body);\n holds.get(el)?.();\n\n el.setAttribute('data-wzl-theme', theme.name);\n for (const a of names) el.setAttribute(`data-wzl-${a}`, sel[a]);\n if (variant === 0) el.removeAttribute('data-wzl-variant');\n else el.setAttribute('data-wzl-variant', String(variant));\n\n // The attributes go only through `release`: a hold replaced by the next application leaves them to it.\n const letGo = (): void => {\n holds.delete(el);\n releaseRule();\n };\n holds.set(el, letGo);\n return () => {\n if (holds.get(el) !== letGo) return;\n letGo();\n for (const a of ['theme', 'variant', ...names]) el.removeAttribute(`data-wzl-${a}`);\n };\n}\n","import { atAlpha, withAlpha } from './dtcg/color.ts';\n\nconst NUMBER = String.raw`(\\d*\\.?\\d+)(%?)`;\nconst RELATIVE = new RegExp(String.raw`^rgb\\(\\s*from\\s+currentcolor\\s+r\\s+g\\s+b\\s*/\\s*${NUMBER}\\s*\\)$`, 'i');\nconst MIX = new RegExp(String.raw`^color-mix\\(\\s*in\\s+[\\w-]+\\s*,\\s*currentcolor\\s+${NUMBER}\\s*,\\s*transparent\\s*\\)$`, 'i');\n\nconst fraction = (n: string, pct: string) => Number(n) / (pct ? 100 : 1);\n\n/**\n * A resolved token value with `currentColor` taken to be `current`, for a surface drawn without the\n * cascade — a canvas reading a resolved theme — where `currentColor` has nothing to resolve against.\n * Pass the color of the text the value is drawn beside, usually `--wzl-fg`. A value that never\n * mentions `currentColor` comes back unchanged.\n *\n * Flattens the forms the kit's themes write: bare `currentColor`, `rgb(from currentColor r g b / a)`\n * and `color-mix(in <space>, currentColor p%, transparent)`. Throws on any other use of it.\n */\nexport function resolveCurrentColor(value: string, current: string): string {\n const v = value.trim();\n if (!/currentcolor/i.test(v)) return value;\n if (/^currentcolor$/i.test(v)) return current;\n const rel = RELATIVE.exec(v);\n if (rel) return atAlpha(current, fraction(rel[1], rel[2]));\n const mix = MIX.exec(v);\n if (mix && mix[2] === '%') return withAlpha(current, fraction(mix[1], mix[2]));\n throw new Error(`resolveCurrentColor: cannot flatten \"${value}\"`);\n}\n","/** A color mode the theme's `mode` axis resolves. */\nexport type ColorMode = 'light' | 'dark';\n\n/**\n * What a user chose: a mode, or `'auto'` — follow the OS, live. `'auto'` is\n * not a mode; resolve it with `useResolvedColorMode` before handing it to a\n * `ThemeProvider` selection.\n */\nexport type ColorModePreference = 'auto' | ColorMode;\n\n/** Whether a value — say, one read back from storage — is a preference. */\nexport function isColorModePreference(v: unknown): v is ColorModePreference {\n return v === 'auto' || v === 'light' || v === 'dark';\n}\n","import type { ColorLiteral, ColorRef, ColorSource, Palette } from '@weasel-js/paint';\nimport type { CategoricalRampDef } from './definition.ts';\nimport { DEFAULT_CONSTRAINTS, generate, type Constraints } from './engine/color/generate.ts';\nimport { resolveTheme, themeChain, type ResolvedTheme } from './resolveTheme.ts';\nimport { weaselTheme, type Theme } from './theme.ts';\n\n/** The categorical generator the swatch ramp uses, asked for `count` colors. */\nexport interface GeneratedColors {\n readonly generate: { readonly count: number; readonly gates?: CategoricalRampDef['gates'] };\n}\n\n/** A ramp of the active theme, by name — `{ ramp: 'swatch' }` walks its steps in order. */\nexport interface RampColors {\n readonly ramp: string;\n}\n\n/** One color of a list: a CSS color string, or a `ColorSource` resolved when it is read. */\nexport type ColorListItem = string | ColorSource;\n\n/** The forms a theme definition can hold: everything but a function. */\nexport type SerializableColorList = readonly (string | ColorLiteral | ColorRef)[] | GeneratedColors | RampColors;\n\n/**\n * Several colors, read by index with `colorAt`, wrapping. Items, each a CSS\n * string or a `ColorSource`; the swatch ramp's generator; a ramp of the active\n * theme, which follows the mode; or a function of the index.\n */\nexport type ColorList = readonly ColorListItem[] | GeneratedColors | RampColors | ((i: number) => ColorListItem);\n\n/** What a `ColorList` resolves against. `useTheme()`'s value is one. */\nexport interface ColorContext {\n readonly theme: Theme;\n readonly resolved: ResolvedTheme;\n}\n\n/** What a `ColorSource` resolves against under a theme. `useTints()`'s value is one. */\nexport interface ColorSourceContext extends ColorContext {\n /** The list `{ ref: 'tint' }` indexes. Absent: the theme's own. */\n readonly tints?: ColorList;\n /** Names answered before the theme's. */\n readonly palette?: Palette;\n}\n\nconst wrap = (i: number, n: number) => ((Math.trunc(i) % n) + n) % n;\n\nconst generated = new Map<string, readonly string[]>();\n\nfunction generatedColors({ generate: g }: GeneratedColors): readonly string[] {\n const key = JSON.stringify([g.count, g.gates ?? {}]);\n let colors = generated.get(key);\n if (!colors) {\n const palette = generate({ ...DEFAULT_CONSTRAINTS, ...(g.gates as Partial<Constraints>), count: g.count, anchors: [] });\n colors = palette.swatches.map((s) => s.hex.toLowerCase());\n generated.set(key, colors);\n }\n return colors;\n}\n\n/** `rampSteps`, answering `undefined` for a ramp the chain lacks. */\nexport function findRampSteps(theme: Theme, ramp: string): readonly string[] | undefined {\n for (const t of themeChain(theme).reverse()) {\n const steps = t.ramps?.[ramp];\n if (steps) return steps;\n }\n return undefined;\n}\n\n/** A ramp's step names, from the nearest theme in the chain that declares it. */\nexport function rampSteps(theme: Theme, ramp: string): readonly string[] {\n const steps = findRampSteps(theme, ramp);\n if (!steps) throw new Error(`Theme \"${theme.name}\" has no ramp \"${ramp}\"`);\n return steps;\n}\n\n/** The tint list a theme declares, from the nearest theme in its chain that has one. */\nexport function themeTints(theme: Theme): ColorList {\n for (const t of themeChain(theme).reverse()) if (t.tints) return t.tints;\n return { ramp: 'swatch' };\n}\n\nlet fallback: ColorContext | undefined;\nexport const defaultContext = () => (fallback ??= { theme: weaselTheme, resolved: resolveTheme(weaselTheme) });\n\nconst pickStep = (list: RampColors, i: number, theme: Theme): string => {\n const steps = rampSteps(theme, list.ramp);\n return steps[wrap(i, steps.length)];\n};\n\n/** The custom property behind the `i`th step of a ramp list, wrapping. */\nexport const rampProperty = (list: RampColors, i: number, theme: Theme): string =>\n `--wzl-${list.ramp}-${pickStep(list, i, theme)}`;\n\nexport const isRamp = (list: ColorList): list is RampColors => typeof list !== 'function' && 'ramp' in list;\n\n/** The `i`th item of a list that is not a ramp, wrapping, as it was written. */\nexport function colorItemAt(list: Exclude<ColorList, RampColors>, i: number): ColorListItem {\n if (typeof list === 'function') return list(i);\n const colors = 'generate' in list ? generatedColors(list) : list;\n if (colors.length === 0) throw new Error('colorAt: empty color list');\n return colors[wrap(i, colors.length)];\n}\n\n/** How many distinct colors `list` holds before it wraps; `undefined` for a function, which never does. */\nexport function colorCount(list: ColorList, ctx: ColorContext = defaultContext()): number | undefined {\n if (typeof list === 'function') return undefined;\n if ('ramp' in list) return rampSteps(ctx.theme, list.ramp).length;\n return 'generate' in list ? list.generate.count : list.length;\n}\n","import {\n colorLiteralToCss,\n cssColorLiteral,\n resolvePaletteColor,\n type ColorFnContext,\n type ColorLiteral,\n type ColorRef,\n type ColorSource,\n type Palette,\n} from '@weasel-js/paint';\nimport {\n colorItemAt,\n defaultContext,\n findRampSteps,\n isRamp,\n rampProperty,\n themeTints,\n type ColorList,\n type ColorSourceContext,\n} from './colorListItems.ts';\nimport { resolveCurrentColor } from './currentColor.ts';\n\n/** The name the tint list answers to: `{ ref: 'tint', index: 2 }` is the third tint, wrapping. */\nexport const TINT_REF = 'tint';\n\nexport type { ColorSourceContext };\n\nconst NO_PALETTE: Palette = { entries: [] };\n\nconst tintsOf = (ctx: ColorSourceContext): ColorList => ctx.tints ?? themeTints(ctx.theme);\n\nfunction parsed(css: string): ColorLiteral | null {\n try {\n return cssColorLiteral(css);\n } catch {\n return null;\n }\n}\n\n/** The custom property a theme ref names: itself when spelled as one, a token by name, or a ramp step by index. */\nfunction propertyOf(ref: ColorRef, ctx: ColorSourceContext): string | null {\n if (ref.ref.startsWith('--')) return ref.index === undefined ? ref.ref : null;\n if (ref.index === undefined) return `--wzl-${ref.ref}`;\n const step = findRampSteps(ctx.theme, ref.ref)?.[ref.index];\n return step === undefined ? null : `--wzl-${ref.ref}-${step}`;\n}\n\nfunction tokenLiteral(property: string, ctx: ColorSourceContext): ColorLiteral | null {\n const value = (ctx.resolved as Readonly<Record<string, string>>)[property];\n if (value === undefined) return null;\n try {\n return parsed(resolveCurrentColor(value, ctx.resolved['--wzl-fg']));\n } catch {\n return null;\n }\n}\n\nconst isRef = (source: ColorSource): source is ColorRef => typeof source !== 'function' && 'ref' in source;\n\nfunction tintSource(index: number, ctx: ColorSourceContext): ColorSource | null {\n const tints = tintsOf(ctx);\n if (isRamp(tints)) return tokenLiteral(rampProperty(tints, index, ctx.theme), ctx);\n const item = colorItemAt(tints, index);\n return typeof item === 'string' ? parsed(item) : item;\n}\n\nfunction themeSource(ref: ColorRef, ctx: ColorSourceContext): ColorSource | null {\n if (ref.ref === TINT_REF) return tintSource(ref.index ?? 0, ctx);\n const property = propertyOf(ref, ctx);\n return property === null ? null : tokenLiteral(property, ctx);\n}\n\n/**\n * Resolve `source` to a literal, for a surface drawn without the cascade. A ref\n * names an entry of the context's palette first, then the theme: `tint` with an\n * index into the tint list, a token by its name without the `--wzl-` prefix, a\n * ramp by its name with the index of a step, or a custom property spelled out.\n * `null` for a name nothing answers, a token that is not a color, and a custom\n * property the theme does not define.\n */\nexport function colorSourceLiteral(source: ColorSource, ctx: ColorSourceContext = defaultContext()): ColorLiteral | null {\n return resolvePaletteColor(ctx.palette ?? NO_PALETTE, source, (ref) => themeSource(ref, ctx));\n}\n\nfunction literalCss(source: ColorSource, ctx: ColorSourceContext): string | null {\n const literal = colorSourceLiteral(source, ctx);\n return literal && colorLiteralToCss(literal);\n}\n\nfunction tintCss(source: ColorRef, ctx: ColorSourceContext): string | null {\n const tints = tintsOf(ctx);\n const index = source.index ?? 0;\n if (isRamp(tints)) return `var(${rampProperty(tints, index, ctx.theme)})`;\n const item = colorItemAt(tints, index);\n if (typeof item === 'string') return item;\n return isRef(item) && item.ref !== TINT_REF ? colorSourceCss(item, ctx) : literalCss(source, ctx);\n}\n\nfunction themeRefCss(ref: ColorRef, ctx: ColorSourceContext): string | null {\n if (ref.ref === TINT_REF) return tintCss(ref, ctx);\n const property = propertyOf(ref, ctx);\n if (property === null) return null;\n return ref.ref.startsWith('--') || tokenLiteral(property, ctx) ? `var(${property})` : null;\n}\n\nfunction nth<T>(items: Iterable<T>, n: number): T | undefined {\n let i = 0;\n for (const item of items) if (i++ === n) return item;\n return undefined;\n}\n\n/**\n * The theme ref `source` comes down to when followed by name alone, through\n * palette entries and functions that only name another color. `null` when it\n * ends anywhere else, or when a function read a color to compute its own.\n */\nfunction namedThemeRef(source: ColorSource, ctx: ColorSourceContext): ColorRef | null {\n const entries = ctx.palette?.entries ?? [];\n const seen = new Set<string>();\n let read = false;\n const fnCtx: ColorFnContext = {\n resolve: (s) => {\n read = true;\n return colorSourceLiteral(s, ctx);\n },\n };\n let at: ColorSource | null | undefined = source;\n while (at != null && !read) {\n if (typeof at === 'function') {\n at = at(fnCtx);\n continue;\n }\n if (!isRef(at)) return null;\n const { ref, index = 0 } = at;\n const entry = entries.find((e) => e.name === ref);\n if (!entry) return at;\n const key = `${index}:${ref}`;\n if (seen.has(key)) return null;\n seen.add(key);\n if ('color' in entry) at = index === 0 ? entry.color : null;\n else at = nth(entry.colors(fnCtx), index);\n }\n return null;\n}\n\n/**\n * `source` as a CSS color, naming what `colorSourceLiteral` resolves. A source\n * that comes down to a ref the theme answers, directly or through palette\n * entries and functions that only name another color, is written as that\n * ref's custom property: it follows the cascade with no re-render, and a\n * property spelled out need not be the theme's. Everything else is written as\n * the literal it resolves to in `ctx`, which includes a function that reads a\n * color through `resolve` to compute its own.\n */\nexport function colorSourceCss(source: ColorSource, ctx: ColorSourceContext = defaultContext()): string | null {\n const named = namedThemeRef(source, ctx);\n return named ? themeRefCss(named, ctx) : literalCss(source, ctx);\n}\n","import { colorLiteralToCss } from '@weasel-js/paint';\nimport { colorItemAt, defaultContext, isRamp, rampProperty, type ColorList, type ColorSourceContext } from './colorListItems.ts';\nimport { colorSourceCss, colorSourceLiteral } from './colorSource.ts';\nimport type { ResolvedTheme } from './resolveTheme.ts';\n\nexport {\n colorCount,\n findRampSteps,\n rampSteps,\n themeTints,\n type ColorContext,\n type ColorList,\n type ColorListItem,\n type GeneratedColors,\n type RampColors,\n type SerializableColorList,\n} from './colorListItems.ts';\n\nfunction answered(css: string | null, i: number): string {\n if (css === null) throw new Error(`colorAt: nothing answers item ${i} of the color list`);\n return css;\n}\n\n/**\n * The `i`th color of `list`, wrapping. A ramp list reads the resolved theme, so\n * the answer follows its mode; a `ColorSource` item resolves against the\n * context's palette, then its theme. Throws on an item nothing answers.\n */\nexport function colorAt(list: ColorList, i: number, ctx: ColorSourceContext = defaultContext()): string {\n if (isRamp(list)) return ctx.resolved[rampProperty(list, i, ctx.theme) as keyof ResolvedTheme];\n const item = colorItemAt(list, i);\n if (typeof item === 'string') return item;\n const literal = colorSourceLiteral(item, ctx);\n return answered(literal && colorLiteralToCss(literal), i);\n}\n\n/**\n * As `colorAt`, but a ramp list, and an item that names the theme, answers\n * with its custom property (`var(--wzl-swatch-sky)`), so a color written into\n * CSS follows a mode change without re-rendering, provider or not.\n */\nexport function colorCssAt(list: ColorList, i: number, ctx: ColorSourceContext = defaultContext()): string {\n if (isRamp(list)) return `var(${rampProperty(list, i, ctx.theme)})`;\n const item = colorItemAt(list, i);\n return typeof item === 'string' ? item : answered(colorSourceCss(item, ctx), i);\n}\n"]}
|