@menapo/vicss 1.0.0 → 1.1.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.
@@ -22,6 +22,40 @@ const merge = (args) => {
22
22
  }
23
23
  return [names, kept];
24
24
  };
25
+ /**
26
+ * The class attribute: the classes kept as they are, then one class per id
27
+ * in id order (S3), so folded, server and client output agree. The ids sort
28
+ * alone: sorting `[id, class]` entries would join each into a string per
29
+ * comparison, five times the cost.
30
+ */
31
+ const join = ([names, kept]) => [...names, ...[...kept.keys()].sort().map((id) => kept.get(id))].join(" ");
32
+ const cache = /* @__PURE__ */ new Map();
33
+ let nodes = 0;
34
+ let vars;
35
+ /**
36
+ * One argument: the trie node below `node` for it, or 0 once the call cannot
37
+ * be cached. Falsy arguments contribute nothing, so they add no level.
38
+ */
39
+ const walk = (node, arg) => {
40
+ if (!arg) return node;
41
+ const known = node && node.get(arg);
42
+ if (known) return known;
43
+ if (arg.map) return arg.reduce(walk, 0);
44
+ if (arg.$c) {
45
+ Object.assign(vars, arg.$s);
46
+ return walk(node, arg.$c);
47
+ }
48
+ return node && (nodes++, node.set(arg, /* @__PURE__ */ new Map()).get(arg));
49
+ };
50
+ /** The merged class attribute, cached per argument identity; `style` collects the custom properties. */
51
+ const classes = (args, style) => {
52
+ if (nodes >> 10) {
53
+ cache.clear();
54
+ nodes = 0;
55
+ }
56
+ vars = style;
57
+ return (args.reduce(walk, cache) || {}).r ??= join(merge(args));
58
+ };
25
59
  //#endregion
26
60
  //#region src/core/hash.ts
27
61
  /**
@@ -258,41 +292,6 @@ function compareStrings(a, b) {
258
292
  return a < b ? -1 : a > b ? 1 : 0;
259
293
  }
260
294
  //#endregion
261
- //#region src/core/types.ts
262
- /**
263
- * What marks a VicssError, shared by every copy of this module in a process:
264
- * the config entry bundles its own copy, and Vite's `runnerImport` gives a
265
- * config another instance even of the workspace's source, so an error a
266
- * preset's utility or `dtcg()` throws is of another class than the one the
267
- * compiler catches.
268
- */
269
- const BRAND = Symbol.for("@menapo/vicss/error");
270
- /** Thrown for anything vicss refuses; carries enough to print a code frame. */
271
- var VicssError = class VicssError extends Error {
272
- code;
273
- loc;
274
- hint;
275
- /**
276
- * `instanceof VicssError` holds for a VicssError of any copy of vicss.
277
- * Subclasses (`ScanConflict`) keep the ordinary prototype check.
278
- */
279
- static [Symbol.hasInstance](value) {
280
- if (this !== VicssError) return Function.prototype[Symbol.hasInstance].call(this, value);
281
- return typeof value === "object" && value !== null && BRAND in value;
282
- }
283
- constructor(code, message, options = {}) {
284
- const limit = Error.stackTraceLimit;
285
- Error.stackTraceLimit = 0;
286
- super(message);
287
- Error.stackTraceLimit = limit;
288
- this.name = "VicssError";
289
- this.code = code;
290
- this.loc = options.loc;
291
- this.hint = options.hint;
292
- Object.defineProperty(this, BRAND, { value: true });
293
- }
294
- };
295
- //#endregion
296
295
  //#region src/core/css-value.ts
297
296
  /**
298
297
  * Well-formedness of the text vicss prints into the one global sheet. A value
@@ -389,6 +388,41 @@ function unquotedUrl(text, start) {
389
388
  return "a url() is missing its `)`";
390
389
  }
391
390
  //#endregion
391
+ //#region src/core/types.ts
392
+ /**
393
+ * What marks a VicssError, shared by every copy of this module in a process:
394
+ * the config entry bundles its own copy, and Vite's `runnerImport` gives a
395
+ * config another instance even of the workspace's source, so an error a
396
+ * preset's utility or `dtcg()` throws is of another class than the one the
397
+ * compiler catches.
398
+ */
399
+ const BRAND = Symbol.for("@menapo/vicss/error");
400
+ /** Thrown for anything vicss refuses; carries enough to print a code frame. */
401
+ var VicssError = class VicssError extends Error {
402
+ code;
403
+ loc;
404
+ hint;
405
+ /**
406
+ * `instanceof VicssError` holds for a VicssError of any copy of vicss.
407
+ * Subclasses (`ScanConflict`) keep the ordinary prototype check.
408
+ */
409
+ static [Symbol.hasInstance](value) {
410
+ if (this !== VicssError) return Function.prototype[Symbol.hasInstance].call(this, value);
411
+ return typeof value === "object" && value !== null && BRAND in value;
412
+ }
413
+ constructor(code, message, options = {}) {
414
+ const limit = Error.stackTraceLimit;
415
+ Error.stackTraceLimit = 0;
416
+ super(message);
417
+ Error.stackTraceLimit = limit;
418
+ this.name = "VicssError";
419
+ this.code = code;
420
+ this.loc = options.loc;
421
+ this.hint = options.hint;
422
+ Object.defineProperty(this, BRAND, { value: true });
423
+ }
424
+ };
425
+ //#endregion
392
426
  //#region src/core/tokens.ts
393
427
  /**
394
428
  * Token resolution (PLAN §4.1, §5.9): token trees and semantic tokens flatten
@@ -5090,4 +5124,4 @@ function printPaletteResets(system, usage, names = READABLE) {
5090
5124
  return blocks.join("\n");
5091
5125
  }
5092
5126
  //#endregion
5093
- export { keepAtom as $, getProperty as A, splitClasses as At, isRootScope as B, canonicalChain as C, makeClassName as Ct, layerName as D, parseClassName as Dt, flatLayerName as E, mergeIdOf as Et, markerId as F, stableStringify as Ft, minLengthWarning as G, hasPlaceholders as H, markerLabel as I, merge as It, renameClasses as J, placeholder as K, markerSites as L, numberKind as M, toRecord as Mt, scaleNumberKind as N, valueLabel as Nt, layerStatement as O, propertyKey as Ot, MarkerValue as P, hash as Pt, isPaletteAtom as Q, markerStates as R, globToRegExp as S, isArbitrary as St, compareChains as T, mergeClassNames as Tt, isRelating as U, createNamer as V, minLengthOf as W, PALETTE_STYLE_KEY as X, PALETTE_GROUP as Y, isAnyPalette as Z, BUILT_IN_UTILITIES as _, VicssError as _t, modeVar as a, SPACING_STEP as at, hasPrivateAccess as b, escapeClassName as bt, printAtoms as c, cssVarName as ct, printTokens as d, isScaleName as dt, paletteKeyOf as et, scopedModes as f, lookupToken as ft, normalizeStyle as g, malformed as gt, compileKeyframes as h, suggestTokens as ht, modeFlag as i, SCALE_NAMESPACES as it, longhandsOf as j, styleLiteral as jt, PROPERTIES as k, readableClass as kt, printBase as l, didYouMean as lt, FRAME_STYLE as m, scaleTokens as mt, classicValue as n, typedPaletteNames as nt, outerLayers as o, closestNames as ot, switchingTokens as p, resolveReferences as pt, placeholdersIn as q, exclusive as r, SCALES as rt, paletteProblem as s, configError as st, baseTokens as t, paletteTarget as tt, printSheet as u, isPlainObject as ut, FLAG_RESETS as v, classAttribute as vt, checkAtoms as w, mergeAtoms as wt, privateTokenError as x, fromRecord as xt, resolveSystem as y, compareStrings as yt, isCompound as z };
5127
+ export { isPaletteAtom as $, PROPERTIES as A, readableClass as At, isCompound as B, globToRegExp as C, isArbitrary as Ct, flatLayerName as D, mergeIdOf as Dt, compareChains as E, mergeClassNames as Et, MarkerValue as F, hash as Ft, minLengthOf as G, createNamer as H, markerId as I, stableStringify as It, placeholdersIn as J, minLengthWarning as K, markerLabel as L, classes as Lt, longhandsOf as M, styleLiteral as Mt, numberKind as N, toRecord as Nt, layerName as O, parseClassName as Ot, scaleNumberKind as P, valueLabel as Pt, isAnyPalette as Q, markerSites as R, merge as Rt, privateTokenError as S, fromRecord as St, checkAtoms as T, mergeAtoms as Tt, hasPlaceholders as U, isRootScope as V, isRelating as W, PALETTE_GROUP as X, renameClasses as Y, PALETTE_STYLE_KEY as Z, normalizeStyle as _, VicssError as _t, modeFlag as a, SCALE_NAMESPACES as at, resolveSystem as b, compareStrings as bt, paletteProblem as c, configError as ct, printSheet as d, isPlainObject as dt, keepAtom as et, printTokens as f, isScaleName as ft, compileKeyframes as g, suggestTokens as gt, FRAME_STYLE as h, scaleTokens as ht, exclusive as i, SCALES as it, getProperty as j, splitClasses as jt, layerStatement as k, propertyKey as kt, printAtoms as l, cssVarName as lt, switchingTokens as m, resolveReferences as mt, chainSelectors as n, paletteTarget as nt, modeVar as o, SPACING_STEP as ot, scopedModes as p, lookupToken as pt, placeholder as q, classicValue as r, typedPaletteNames as rt, outerLayers as s, closestNames as st, baseTokens as t, paletteKeyOf as tt, printBase as u, didYouMean as ut, BUILT_IN_UTILITIES as v, malformed as vt, canonicalChain as w, makeClassName as wt, hasPrivateAccess as x, escapeClassName as xt, FLAG_RESETS as y, classAttribute as yt, markerStates as z };
@@ -1,4 +1,4 @@
1
- import { _ as BUILT_IN_UTILITIES, _t as VicssError, dt as isScaleName, ut as isPlainObject, y as resolveSystem } from "./print-Ds6fkgio.js";
1
+ import { _t as VicssError, b as resolveSystem, dt as isPlainObject, ft as isScaleName, v as BUILT_IN_UTILITIES } from "./print-B_mn7wBu.js";
2
2
  //#region src/core/snapshot.ts
3
3
  /**
4
4
  * The lint snapshot, `vicss.lint.json`: what the lint rules (src/lint) need
@@ -1,4 +1,4 @@
1
- import { B as isRootScope, C as canonicalChain, Ct as makeClassName, Dt as parseClassName, Ft as stableStringify, It as merge, Mt as toRecord, Ot as propertyKey, Pt as hash, Q as isPaletteAtom, T as compareChains, Tt as mergeClassNames, _t as VicssError, a as modeVar, bt as escapeClassName, c as printAtoms, dt as isScaleName, f as scopedModes, ft as lookupToken, gt as malformed, ht as suggestTokens, i as modeFlag, j as longhandsOf, jt as styleLiteral, k as PROPERTIES, lt as didYouMean, n as classicValue, ot as closestNames, p as switchingTokens, pt as resolveReferences, r as exclusive, rt as SCALES, ut as isPlainObject, yt as compareStrings, z as isCompound } from "./print-Ds6fkgio.js";
1
+ import { $ as isPaletteAtom, A as PROPERTIES, B as isCompound, E as compareChains, Et as mergeClassNames, Ft as hash, It as stableStringify, Lt as classes, M as longhandsOf, Mt as styleLiteral, Nt as toRecord, Ot as parseClassName, Rt as merge, V as isRootScope, _t as VicssError, a as modeFlag, bt as compareStrings, dt as isPlainObject, ft as isScaleName, gt as suggestTokens, i as exclusive, it as SCALES, kt as propertyKey, l as printAtoms, m as switchingTokens, mt as resolveReferences, o as modeVar, p as scopedModes, pt as lookupToken, r as classicValue, st as closestNames, ut as didYouMean, vt as malformed, w as canonicalChain, wt as makeClassName, xt as escapeClassName } from "./print-B_mn7wBu.js";
2
2
  //#region src/core/location.ts
3
3
  /**
4
4
  * Offsets to line and column, for diagnostics and source maps. Lines end at
@@ -741,6 +741,29 @@ function shadowedByEarlier(args, atomsOf) {
741
741
  } : void 0;
742
742
  }
743
743
  //#endregion
744
+ //#region src/runtime/style.ts
745
+ /**
746
+ * One compiled style as a class (PLAN §5.6, §5.16): `class={card}`,
747
+ * `className={card}` and `${card}` read it as its class attribute. A
748
+ * compiled style keeps its shape, merge id → class, so `sx()` still merges
749
+ * it; the string comes from the prototype every compiled style shares. A
750
+ * class method is not enumerable, so the merge's `for…in`, `Object.keys`
751
+ * and a spread never see it, and a constant carries no function of its own.
752
+ */
753
+ var Styled = class {
754
+ /**
755
+ * The class attribute `sx(style)` sets, by `sx()`'s own merge and cache:
756
+ * the same string by construction, a cache hit after the first render,
757
+ * and 31 B less than a merge of its own beside `sx()`, which nearly every
758
+ * app ships (PLAN §6).
759
+ */
760
+ toString() {
761
+ return classes([this], {});
762
+ }
763
+ };
764
+ /** What the compiler wraps a compiled style literal in (`__vxStyled({…})`). */
765
+ const styled = (record) => Object.setPrototypeOf(record, Styled.prototype);
766
+ //#endregion
744
767
  //#region src/runtime/recipe.ts
745
768
  /**
746
769
  * The recipe resolver (PLAN §4.4, §5.7): what a compiled `recipe()` becomes,
@@ -803,7 +826,7 @@ const __vxRecipe = (t, x) => {
803
826
  const add = x?.(t, props, values, cells);
804
827
  for (const compound of t.c) if (add) add(compound);
805
828
  else if (Object.keys(compound[0]).every((key) => compound[0][key].includes(values[key]))) cells.push(compound[1]);
806
- const slot = (name) => Object.fromEntries(merge(cells.map((cell) => typeof cell == "object" && (name ? cell[name] : cell)))[1]);
829
+ const slot = (name) => styled(Object.fromEntries(merge(cells.map((cell) => typeof cell == "object" && (name ? cell[name] : cell)))[1]));
807
830
  result = t.s ? Object.fromEntries(t.s.map((name) => [name, slot(name)])) : slot();
808
831
  if (process.env.NODE_ENV != "production") Object.freeze(result);
809
832
  if (memo.size >> 10) memo.clear();
@@ -1,7 +1,7 @@
1
- import { $ as keepAtom, N as scaleNumberKind, Q as isPaletteAtom, R as markerStates, S as globToRegExp, U as isRelating, Z as isAnyPalette, _t as VicssError, at as SPACING_STEP, b as hasPrivateAccess, ct as cssVarName, dt as isScaleName, et as paletteKeyOf, ft as lookupToken, it as SCALE_NAMESPACES, k as PROPERTIES, mt as scaleTokens, q as placeholdersIn, rt as SCALES, tt as paletteTarget, v as FLAG_RESETS, w as checkAtoms, yt as compareStrings } from "./print-Ds6fkgio.js";
2
- import { d as baseRule, f as checkBases, l as responsiveConditions, n as compileTheme, u as baseAtoms } from "./theme-C-0LpsJx.js";
3
- import { _ as isSfc, h as extractScripts, n as WorkerLost, u as resolvesAlike, x as SourceEdits } from "./pool-BGXMhLfL.js";
4
- import { t as SNAPSHOT_FILE } from "./snapshot-BQb8ZmSV.js";
1
+ import { $ as isPaletteAtom, A as PROPERTIES, C as globToRegExp, J as placeholdersIn, P as scaleNumberKind, Q as isAnyPalette, T as checkAtoms, W as isRelating, _t as VicssError, at as SCALE_NAMESPACES, bt as compareStrings, et as keepAtom, ft as isScaleName, ht as scaleTokens, it as SCALES, lt as cssVarName, nt as paletteTarget, ot as SPACING_STEP, pt as lookupToken, tt as paletteKeyOf, x as hasPrivateAccess, y as FLAG_RESETS, z as markerStates } from "./print-B_mn7wBu.js";
2
+ import { _ as isSfc, h as extractScripts, n as WorkerLost, u as resolvesAlike, x as SourceEdits } from "./pool-F3qb30Fy.js";
3
+ import { d as baseRule, f as checkBases, l as responsiveConditions, n as compileTheme, u as baseAtoms } from "./theme-zBcr5DHi.js";
4
+ import { t as SNAPSHOT_FILE } from "./snapshot-DAJ8FLU4.js";
5
5
  import { createRequire } from "node:module";
6
6
  import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, writeFileSync } from "node:fs";
7
7
  import { glob, mkdir, readFile, readdir, rename, writeFile } from "node:fs/promises";
@@ -485,7 +485,7 @@ var CompileCache = class {
485
485
  #entries = /* @__PURE__ */ new Map();
486
486
  /** `configHash` covers the design system and the files that define it. */
487
487
  key(code, configHash) {
488
- return `${hashCode(code)}:${configHash}:13:${VERSION}`;
488
+ return `${hashCode(code)}:${configHash}:14:${VERSION}`;
489
489
  }
490
490
  /**
491
491
  * The entry for `id` if it is still valid. `depHash` reads a dependency's
@@ -517,7 +517,7 @@ var CompileCache = class {
517
517
  } catch {
518
518
  return;
519
519
  }
520
- if (!isRecord(data) || data.format !== 13 || !isRecord(data.entries)) return;
520
+ if (!isRecord(data) || data.format !== 14 || !isRecord(data.entries)) return;
521
521
  const table = data.atoms;
522
522
  const rules = data.rules;
523
523
  if (!Array.isArray(table) || !table.every(isAtom)) return;
@@ -563,7 +563,7 @@ var CompileCache = class {
563
563
  await mkdir(path.dirname(file), { recursive: true });
564
564
  const temp = `${file}.${process.pid}.tmp`;
565
565
  const data = {
566
- format: 13,
566
+ format: 14,
567
567
  atoms: atoms.table,
568
568
  rules: rules.table,
569
569
  entries
package/dist/vite.d.ts CHANGED
@@ -242,4 +242,29 @@ interface VicssPluginOptions {
242
242
  }
243
243
  export declare function vicss(options?: VicssPluginOptions): Plugin[];
244
244
  //#endregion
245
- export { type CriticalDirOptions, type CriticalOptions, type CriticalPage, type CriticalPart, type CriticalReport, type VicssPluginOptions, vicss as default };
245
+ //#region src/core/literals.d.ts
246
+ /** One declaration of a class, its values literal. */
247
+ interface Literal {
248
+ /** kebab-case: `padding-inline`, `background-color`. */
249
+ readonly property: string;
250
+ /** Tokens replaced by their base values, transitively; other `var()` (a runtime value's) stays. */
251
+ readonly value: string;
252
+ /** The property's tier: under one condition, a higher tier wins (`padding-top` over `padding`). */
253
+ readonly tier: number;
254
+ /** Condition names it applies under, `[]` for always: `["dark"]`, `["md", "hover"]`. */
255
+ readonly chain: readonly string[];
256
+ /**
257
+ * Where it applies, one entry per alternative of the chain's conditions:
258
+ * a selector with `&` for the element's class, and its at-rules, outermost
259
+ * first. The color-scheme modes (`dark`, `light`) are left out, for the
260
+ * caller to read in `chain`: a mail client needs its own selectors for them.
261
+ */
262
+ readonly rules: ReadonlyArray<{
263
+ readonly selector: string;
264
+ readonly atRules: readonly string[];
265
+ }>;
266
+ /** The value under each mode whose tokens change it: `{ dark: "#f9fafb" }`. */
267
+ readonly modes?: Readonly<Record<string, string>>;
268
+ }
269
+ //#endregion
270
+ export { type CriticalDirOptions, type CriticalOptions, type CriticalPage, type CriticalPart, type CriticalReport, type Literal, type VicssPluginOptions, vicss as default };