@unpunnyfuns/swatchbook-blocks 0.12.0 → 0.13.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/index.mjs CHANGED
@@ -5,6 +5,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { addons } from "storybook/preview-api";
6
6
  import { axes, css, cssVarPrefix, defaultTheme, diagnostics, presets, themes, themesResolved } from "virtual:swatchbook/tokens";
7
7
  import cx from "clsx";
8
+ import { analyzeAxisVariance } from "@unpunnyfuns/swatchbook-core/variance";
8
9
  //#region src/format-color.ts
9
10
  const COLOR_FORMATS = [
10
11
  "hex",
@@ -2136,7 +2137,13 @@ function AxisVariance({ path }) {
2136
2137
  const tokenType = token?.$type;
2137
2138
  const isColor = tokenType === "color";
2138
2139
  const formatFn = (t) => valueFor(t, tokenType, colorFormat);
2139
- const variance = useMemo(() => analyzeVariance(path, axes, themes, themesResolved), [
2140
+ const variance = useMemo(() => {
2141
+ const result = analyzeAxisVariance(path, axes, themes, themesResolved);
2142
+ return {
2143
+ kind: result.kind === "constant" ? "constant" : result.kind === "single" ? "one-axis" : "multi-axis",
2144
+ varyingAxes: result.varyingAxes
2145
+ };
2146
+ }, [
2140
2147
  path,
2141
2148
  axes,
2142
2149
  themes,
@@ -2298,54 +2305,12 @@ function valueFor(token, $type, format) {
2298
2305
  if (!token) return "—";
2299
2306
  return formatTokenValue(token.$value, $type, format);
2300
2307
  }
2301
- /**
2302
- * Stable key for variance detection — compares structural equality across
2303
- * themes, not a display string. We pin `raw` so color representation
2304
- * changes (the toolbar's format dropdown) don't artificially make axes
2305
- * look like they vary.
2306
- */
2307
- function varianceKey(themesResolved, themeName, path) {
2308
- const t = themesResolved[themeName]?.[path];
2309
- if (!t) return "";
2310
- return JSON.stringify(t.$value);
2311
- }
2312
2308
  function tupleName(themes, tuple) {
2313
2309
  return themes.find((t) => {
2314
2310
  const input = t.input;
2315
2311
  return Object.keys(input).every((k) => input[k] === tuple[k]);
2316
2312
  })?.name;
2317
2313
  }
2318
- function analyzeVariance(path, axes, themes, themesResolved) {
2319
- const varyingAxes = [];
2320
- for (const axis of axes) {
2321
- const byOthers = /* @__PURE__ */ new Map();
2322
- for (const theme of themes) {
2323
- const others = axes.filter((a) => a.name !== axis.name).map((a) => `${a.name}=${theme.input[a.name] ?? ""}`).join("|");
2324
- const ctx = theme.input[axis.name] ?? "";
2325
- const bucket = byOthers.get(others) ?? /* @__PURE__ */ new Map();
2326
- bucket.set(ctx, varianceKey(themesResolved, theme.name, path));
2327
- byOthers.set(others, bucket);
2328
- }
2329
- let varies = false;
2330
- for (const bucket of byOthers.values()) if (new Set(bucket.values()).size > 1) {
2331
- varies = true;
2332
- break;
2333
- }
2334
- if (varies) varyingAxes.push(axis.name);
2335
- }
2336
- if (varyingAxes.length === 0) return {
2337
- kind: "constant",
2338
- varyingAxes
2339
- };
2340
- if (varyingAxes.length === 1) return {
2341
- kind: "one-axis",
2342
- varyingAxes
2343
- };
2344
- return {
2345
- kind: "multi-axis",
2346
- varyingAxes
2347
- };
2348
- }
2349
2314
  //#endregion
2350
2315
  //#region src/token-detail/CompositeBreakdown.tsx
2351
2316
  function CompositeBreakdown({ path }) {