@weasel-js/theme 1.5.2 → 1.6.1

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/dist/engine.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { OklchDeg, oklchDegToHex } from '@weasel-js/paint';
2
- import { f as ThemeDefinition, L as Lookup, F as FlatTokens, R as RawToken, S as Selection, B as BakedTheme, T as Theme } from './theme-DAZcQi_L.js';
3
- export { C as CategoricalRampDef, l as ContrastRule, m as LightnessRampDef, n as LiteralRule, N as NumberParam, O as OffsetRule, P as PinObject, e as PinValue, o as RampDef, p as RefRule, q as ScaleDef, r as SemanticRule, t as StepRule, u as bake, v as bakeChain, x as mergeChain } from './theme-DAZcQi_L.js';
2
+ import { T as ThemeDefinition, L as Lookup, F as FlatTokens, R as RawToken, S as Selection, B as BakedTheme, A as AxisDefs, a as Theme } from './definition-DLdTdFWs.js';
3
+ export { C as CategoricalRampDef, b as ContrastRule, c as LightnessRampDef, d as LiteralRule, N as NumberParam, O as OffsetRule, P as PinObject, e as PinValue, f as RampDef, g as RefRule, h as ScaleDef, i as SemanticRule, j as StepRule, k as bake, l as bakeChain, m as mergeChain } from './definition-DLdTdFWs.js';
4
4
 
5
5
  /** A color in OKLCH: lightness 0–1, chroma, hue in degrees. paint's own type,
6
6
  * under the name this engine has always called it. */
@@ -218,6 +218,10 @@ interface LightnessParams {
218
218
  /**
219
219
  * Step name → hex. Lightness walks from `lightness[0]` to `lightness[1]`, `curve` blending an even walk toward a
220
220
  * smoothstep; chroma is `peak` scaled by the envelope `sin(πt) + lightBias·(1−t) + darkBias·t` normalized to a maximum of 1.
221
+ *
222
+ * An anchored step emits its anchor exactly, and the anchor replaces `hue` and `peak`: its OKLCH hue becomes the hue and
223
+ * its chroma becomes the peak, unscaled by the envelope. With several anchors, both blend linearly by step between
224
+ * consecutive anchors, hue along the shorter arc; steps before the first anchor or after the last take that anchor's.
221
225
  */
222
226
  declare function lightnessRamp(p: LightnessParams): Record<string, string>;
223
227
  declare function categoricalRamp(steps: readonly string[], gates: Partial<Constraints>, anchors: readonly Anchor[]): {
@@ -243,6 +247,28 @@ interface EmitInput {
243
247
  declare function cssValue(name: string, token: RawToken): string;
244
248
  declare function emitCss(themes: readonly EmitInput[]): string;
245
249
 
250
+ /** The `$extensions` key on a DTCG export's root that carries every axis besides mode. */
251
+ declare const AXES_EXT = "com.weasel.axes";
252
+ /** The token groups of one layer: plain values, and values per mode. */
253
+ interface DtcgLayer {
254
+ readonly primitives: Record<string, Record<string, unknown>>;
255
+ readonly modes: Record<string, Record<string, Record<string, unknown>>>;
256
+ }
257
+ /**
258
+ * What `toDTCG` writes under `$extensions["com.weasel.axes"]`.
259
+ *
260
+ * - `axes`: every axis the theme resolves with, mode included.
261
+ * - `varies`: token name → the non-mode axes its value depends on.
262
+ * - `overrides`: a layer per combination of non-default values, keyed like
263
+ * `selectionKey` but naming only the axes off their default
264
+ * (`density=compact`, `contrast=high,density=roomy` in axis order).
265
+ */
266
+ interface DtcgAxesExtension {
267
+ readonly axes: AxisDefs;
268
+ readonly varies: Record<string, readonly string[]>;
269
+ readonly overrides: Record<string, DtcgLayer>;
270
+ }
271
+
246
272
  type Group = Record<string, unknown> & {
247
273
  $type: string;
248
274
  };
@@ -251,17 +277,21 @@ interface DtcgExport {
251
277
  readonly defaultMode?: string;
252
278
  readonly primitives: Record<string, Group>;
253
279
  readonly modes: Record<string, Record<string, Group>>;
280
+ readonly $extensions?: {
281
+ readonly [AXES_EXT]?: DtcgAxesExtension;
282
+ };
254
283
  }
255
284
  /**
256
285
  * A theme's own tokens as a DTCG document `loadDTCG` reads back. `extends` is
257
286
  * not carried; pass it to `loadDTCG`. Every mode the chain declares is written,
258
287
  * so a token that leaves one out still falls through to the parent on the way back.
259
288
  *
260
- * DTCG has one variant dimension and no standard way to name a second, so mode
261
- * is the only axis exported: a token varying by any other axis is written at
262
- * that axis's default value and its other branches are dropped. Round-tripping
263
- * a theme through DTCG therefore flattens it to the default selection of every
264
- * non-mode axis.
289
+ * DTCG has one variant dimension, so the plain groups hold mode, with every
290
+ * other axis at its default value: what a tool that ignores extensions reads.
291
+ * The other values travel under `$extensions["com.weasel.axes"]` (see
292
+ * `DtcgAxesExtension`), one override layer per combination of non-default values
293
+ * some token actually varies by — axes that vary independently cost one layer
294
+ * per value, not their cross-product.
265
295
  */
266
296
  declare function toDTCG(theme: Theme): DtcgExport;
267
297
 
@@ -290,4 +320,42 @@ type GeneratedTokens = {
290
320
  /** Every generated token file for a set of definitions, the one that extends nothing being the default. Any derive issue refuses the whole set. */
291
321
  declare function generateTokens(definitions: readonly ThemeDefinition[]): GeneratedTokens;
292
322
 
293
- export { type Anchor, type AxisDependency, BakedTheme, CHROMA_WEIGHT, type Constraints, DEFAULT_CONSTRAINTS, type DeriveResult, type DtcgExport, type EmitInput, type GeneratedTokens, type Issue, type Layer, type Lch, type LightnessParams, Lookup, type Palette, type Provenance, type ScaleParams, type Stats, type Swatch, ThemeDefinition, type ThemesInput, anchorFromHex, axisDependencies, categoricalRamp, chromaCap, contrast, cssValue, declaredSteps, deltaE, derive, emitCss, emitManifest, emitThemes, floorDegrees, generate, generateTokens, hexToRgb, hueGap, hueName, lightnessRamp, luminance, scale, toDTCG, toHex, toHexPreview, toLab, toLch, vividAt };
323
+ /** A theme definition file as a theme store serves it: the dev-server endpoint at `__theme/<name>`. */
324
+ interface StoredTheme {
325
+ readonly name: string;
326
+ /** sha-256 of the file's bytes: what a save sends back to prove it saw the file as it is. */
327
+ readonly hash: string;
328
+ /** Saving it regenerates `packages/theme/src/generated/`. */
329
+ readonly emits: boolean;
330
+ readonly definition: ThemeDefinition;
331
+ }
332
+ interface IssueReport {
333
+ readonly selection: Selection;
334
+ readonly issue: Issue;
335
+ }
336
+ type PutResult = {
337
+ readonly status: 'saved';
338
+ readonly hash: string;
339
+ readonly issues: readonly IssueReport[];
340
+ readonly regenerated: boolean;
341
+ /** Why the generated files were left alone, when the definition emits and they were. */
342
+ readonly problems: readonly string[];
343
+ } | {
344
+ readonly status: 'conflict';
345
+ readonly hash: string | null;
346
+ } | {
347
+ readonly status: 'invalid';
348
+ readonly message: string;
349
+ };
350
+ /** Record order is emission order, so keys are never sorted. */
351
+ declare const serializeDefinition: (definition: ThemeDefinition) => string;
352
+ interface ThemeApi {
353
+ list(): Promise<StoredTheme[]>;
354
+ get(name: string): Promise<StoredTheme>;
355
+ put(name: string, definition: ThemeDefinition, baseHash: string | null): Promise<PutResult>;
356
+ }
357
+ type Fetch = (input: string, init?: RequestInit) => Promise<Response>;
358
+ /** The dev server's theme store, addressed relative to the page so the app's base path carries over. */
359
+ declare function httpThemeApi(base?: string, fetchImpl?: Fetch): ThemeApi;
360
+
361
+ export { type Anchor, type AxisDependency, BakedTheme, CHROMA_WEIGHT, type Constraints, DEFAULT_CONSTRAINTS, type DeriveResult, type DtcgExport, type EmitInput, type GeneratedTokens, type Issue, type IssueReport, type Layer, type Lch, type LightnessParams, Lookup, type Palette, type Provenance, type PutResult, type ScaleParams, type Stats, type StoredTheme, type Swatch, type ThemeApi, ThemeDefinition, type ThemesInput, anchorFromHex, axisDependencies, categoricalRamp, chromaCap, contrast, cssValue, declaredSteps, deltaE, derive, emitCss, emitManifest, emitThemes, floorDegrees, generate, generateTokens, hexToRgb, httpThemeApi, hueGap, hueName, lightnessRamp, luminance, scale, serializeDefinition, toDTCG, toHex, toHexPreview, toLab, toLch, vividAt };