@unpunnyfuns/swatchbook-blocks 0.6.1 → 0.6.2
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 +134 -54
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +25 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -615,21 +615,13 @@ function formatDimension$2(raw) {
|
|
|
615
615
|
}
|
|
616
616
|
return JSON.stringify(raw);
|
|
617
617
|
}
|
|
618
|
-
function
|
|
618
|
+
function formatSubColor$1(raw, format) {
|
|
619
619
|
if (raw == null) return "—";
|
|
620
|
-
|
|
621
|
-
if (typeof raw === "object") {
|
|
622
|
-
const v = raw;
|
|
623
|
-
if (Array.isArray(v.components) && typeof v.colorSpace === "string") {
|
|
624
|
-
const parts = v.components.map((c) => typeof c === "number" ? c.toFixed(3) : String(c));
|
|
625
|
-
const alpha = typeof v.alpha === "number" && v.alpha !== 1 ? `, ${v.alpha}` : "";
|
|
626
|
-
return `${v.colorSpace}(${parts.join(" ")}${alpha})`;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return JSON.stringify(raw);
|
|
620
|
+
return formatColor(raw, format).value;
|
|
630
621
|
}
|
|
631
622
|
function BorderPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
632
623
|
const { resolved, activeTheme, cssVarPrefix } = useProject();
|
|
624
|
+
const colorFormat = useColorFormat();
|
|
633
625
|
const rows = useMemo(() => {
|
|
634
626
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
635
627
|
if (token.$type !== "border") return false;
|
|
@@ -696,7 +688,7 @@ function BorderPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
|
696
688
|
className: "sb-border-preview__breakdown-key",
|
|
697
689
|
children: "color"
|
|
698
690
|
}),
|
|
699
|
-
/* @__PURE__ */ jsx("span", { children:
|
|
691
|
+
/* @__PURE__ */ jsx("span", { children: formatSubColor$1(row.value.color, colorFormat) })
|
|
700
692
|
]
|
|
701
693
|
})
|
|
702
694
|
]
|
|
@@ -1337,6 +1329,7 @@ function stopKey(path, stop, fallback) {
|
|
|
1337
1329
|
}
|
|
1338
1330
|
function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
1339
1331
|
const { resolved, activeTheme, cssVarPrefix } = useProject();
|
|
1332
|
+
const colorFormat = useColorFormat();
|
|
1340
1333
|
const rows = useMemo(() => {
|
|
1341
1334
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1342
1335
|
if (token.$type !== "gradient") return false;
|
|
@@ -1397,7 +1390,7 @@ function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" })
|
|
|
1397
1390
|
style: { background: stopCssColor(stop) },
|
|
1398
1391
|
"aria-hidden": true
|
|
1399
1392
|
}),
|
|
1400
|
-
/* @__PURE__ */ jsx("span", { children:
|
|
1393
|
+
/* @__PURE__ */ jsx("span", { children: formatColor(stop.color, colorFormat).value }),
|
|
1401
1394
|
/* @__PURE__ */ jsxs("span", {
|
|
1402
1395
|
className: "sb-gradient-palette__stop-position",
|
|
1403
1396
|
children: [
|
|
@@ -1742,18 +1735,9 @@ function formatDimension(raw) {
|
|
|
1742
1735
|
}
|
|
1743
1736
|
return JSON.stringify(raw);
|
|
1744
1737
|
}
|
|
1745
|
-
function
|
|
1738
|
+
function formatSubColor(raw, format) {
|
|
1746
1739
|
if (raw == null) return "—";
|
|
1747
|
-
|
|
1748
|
-
if (typeof raw === "object") {
|
|
1749
|
-
const v = raw;
|
|
1750
|
-
if (Array.isArray(v.components) && typeof v.colorSpace === "string") {
|
|
1751
|
-
const parts = v.components.map((c) => typeof c === "number" ? c.toFixed(3) : String(c));
|
|
1752
|
-
const alpha = typeof v.alpha === "number" && v.alpha !== 1 ? `, ${v.alpha}` : "";
|
|
1753
|
-
return `${v.colorSpace}(${parts.join(" ")}${alpha})`;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return JSON.stringify(raw);
|
|
1740
|
+
return formatColor(raw, format).value;
|
|
1757
1741
|
}
|
|
1758
1742
|
function asLayers(raw) {
|
|
1759
1743
|
if (Array.isArray(raw)) return raw;
|
|
@@ -1765,6 +1749,7 @@ function layerKey(path, layer, fallback) {
|
|
|
1765
1749
|
}
|
|
1766
1750
|
function ShadowPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
1767
1751
|
const { resolved, activeTheme, cssVarPrefix } = useProject();
|
|
1752
|
+
const colorFormat = useColorFormat();
|
|
1768
1753
|
const rows = useMemo(() => {
|
|
1769
1754
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1770
1755
|
if (token.$type !== "shadow") return false;
|
|
@@ -1816,23 +1801,24 @@ function ShadowPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
|
1816
1801
|
}),
|
|
1817
1802
|
/* @__PURE__ */ jsx("div", {
|
|
1818
1803
|
className: "sb-shadow-preview__breakdown",
|
|
1819
|
-
children: row.layers.length === 1 ? renderLayer(row.layers[0]) : row.layers.map((layer, i) => /* @__PURE__ */ jsx(Layer, {
|
|
1804
|
+
children: row.layers.length === 1 ? renderLayer(row.layers[0], colorFormat) : row.layers.map((layer, i) => /* @__PURE__ */ jsx(Layer, {
|
|
1820
1805
|
layer,
|
|
1821
1806
|
index: i,
|
|
1822
|
-
total: row.layers.length
|
|
1807
|
+
total: row.layers.length,
|
|
1808
|
+
colorFormat
|
|
1823
1809
|
}, layerKey(row.path, layer, i)))
|
|
1824
1810
|
})
|
|
1825
1811
|
]
|
|
1826
1812
|
}, row.path))]
|
|
1827
1813
|
});
|
|
1828
1814
|
}
|
|
1829
|
-
function renderLayer(layer) {
|
|
1815
|
+
function renderLayer(layer, format) {
|
|
1830
1816
|
if (!layer) return [];
|
|
1831
1817
|
const entries = [
|
|
1832
1818
|
["offset", `${formatDimension(layer.offsetX)} ${formatDimension(layer.offsetY)}`],
|
|
1833
1819
|
["blur", formatDimension(layer.blur)],
|
|
1834
1820
|
["spread", formatDimension(layer.spread)],
|
|
1835
|
-
["color",
|
|
1821
|
+
["color", formatSubColor(layer.color, format)]
|
|
1836
1822
|
];
|
|
1837
1823
|
if (layer.inset) entries.push(["inset", String(layer.inset)]);
|
|
1838
1824
|
return entries.flatMap(([k, v]) => [/* @__PURE__ */ jsx("span", {
|
|
@@ -1840,7 +1826,7 @@ function renderLayer(layer) {
|
|
|
1840
1826
|
children: k
|
|
1841
1827
|
}, `k-${k}`), /* @__PURE__ */ jsx("span", { children: v }, `v-${k}`)]);
|
|
1842
1828
|
}
|
|
1843
|
-
function Layer({ layer, index, total }) {
|
|
1829
|
+
function Layer({ layer, index, total, colorFormat }) {
|
|
1844
1830
|
return /* @__PURE__ */ jsxs("div", {
|
|
1845
1831
|
className: "sb-shadow-preview__layer",
|
|
1846
1832
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
@@ -1853,7 +1839,7 @@ function Layer({ layer, index, total }) {
|
|
|
1853
1839
|
]
|
|
1854
1840
|
}), /* @__PURE__ */ jsx("div", {
|
|
1855
1841
|
className: cx("sb-shadow-preview__breakdown", "sb-shadow-preview__layer-breakdown"),
|
|
1856
|
-
children: renderLayer(layer)
|
|
1842
|
+
children: renderLayer(layer, colorFormat)
|
|
1857
1843
|
})]
|
|
1858
1844
|
});
|
|
1859
1845
|
}
|
|
@@ -2294,46 +2280,96 @@ function analyzeVariance(path, axes, themes, themesResolved) {
|
|
|
2294
2280
|
//#endregion
|
|
2295
2281
|
//#region src/token-detail/CompositeBreakdown.tsx
|
|
2296
2282
|
function CompositeBreakdown({ path }) {
|
|
2297
|
-
const { token } = useTokenDetailData(path);
|
|
2283
|
+
const { token, resolved } = useTokenDetailData(path);
|
|
2298
2284
|
const colorFormat = useColorFormat();
|
|
2299
2285
|
if (!token) return null;
|
|
2300
2286
|
return /* @__PURE__ */ jsx(CompositeBreakdownContent, {
|
|
2301
2287
|
type: token.$type,
|
|
2302
2288
|
rawValue: token.$value,
|
|
2289
|
+
partialAliasOf: token.partialAliasOf,
|
|
2290
|
+
resolved,
|
|
2303
2291
|
colorFormat
|
|
2304
2292
|
});
|
|
2305
2293
|
}
|
|
2306
|
-
function CompositeBreakdownContent({ type, rawValue, colorFormat }) {
|
|
2294
|
+
function CompositeBreakdownContent({ type, rawValue, partialAliasOf, resolved, colorFormat }) {
|
|
2307
2295
|
if (!rawValue || typeof rawValue !== "object") return null;
|
|
2296
|
+
const objectAliases = pickObjectAliases(partialAliasOf);
|
|
2297
|
+
const arrayAliases = pickArrayAliases(partialAliasOf);
|
|
2298
|
+
const aliasFor = (key) => subValueChain(objectAliases?.[key], resolved);
|
|
2308
2299
|
if (type === "typography") {
|
|
2309
2300
|
const v = rawValue;
|
|
2310
2301
|
return renderKeyValueList([
|
|
2311
|
-
[
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2302
|
+
[
|
|
2303
|
+
"fontFamily",
|
|
2304
|
+
formatFontFamily(v["fontFamily"]),
|
|
2305
|
+
aliasFor("fontFamily")
|
|
2306
|
+
],
|
|
2307
|
+
[
|
|
2308
|
+
"fontSize",
|
|
2309
|
+
formatDimensionValue(v["fontSize"]),
|
|
2310
|
+
aliasFor("fontSize")
|
|
2311
|
+
],
|
|
2312
|
+
[
|
|
2313
|
+
"fontWeight",
|
|
2314
|
+
formatPrimitive(v["fontWeight"]),
|
|
2315
|
+
aliasFor("fontWeight")
|
|
2316
|
+
],
|
|
2317
|
+
[
|
|
2318
|
+
"lineHeight",
|
|
2319
|
+
formatPrimitive(v["lineHeight"]),
|
|
2320
|
+
aliasFor("lineHeight")
|
|
2321
|
+
],
|
|
2322
|
+
[
|
|
2323
|
+
"letterSpacing",
|
|
2324
|
+
formatDimensionValue(v["letterSpacing"]),
|
|
2325
|
+
aliasFor("letterSpacing")
|
|
2326
|
+
]
|
|
2316
2327
|
]);
|
|
2317
2328
|
}
|
|
2318
2329
|
if (type === "border") {
|
|
2319
2330
|
const v = rawValue;
|
|
2320
2331
|
return renderKeyValueList([
|
|
2321
|
-
[
|
|
2322
|
-
|
|
2323
|
-
|
|
2332
|
+
[
|
|
2333
|
+
"color",
|
|
2334
|
+
formatColorSubValue(v["color"], colorFormat),
|
|
2335
|
+
aliasFor("color")
|
|
2336
|
+
],
|
|
2337
|
+
[
|
|
2338
|
+
"width",
|
|
2339
|
+
formatDimensionValue(v["width"]),
|
|
2340
|
+
aliasFor("width")
|
|
2341
|
+
],
|
|
2342
|
+
[
|
|
2343
|
+
"style",
|
|
2344
|
+
formatPrimitive(v["style"]),
|
|
2345
|
+
aliasFor("style")
|
|
2346
|
+
]
|
|
2324
2347
|
]);
|
|
2325
2348
|
}
|
|
2326
2349
|
if (type === "transition") {
|
|
2327
2350
|
const v = rawValue;
|
|
2328
2351
|
return renderKeyValueList([
|
|
2329
|
-
[
|
|
2330
|
-
|
|
2331
|
-
|
|
2352
|
+
[
|
|
2353
|
+
"duration",
|
|
2354
|
+
formatDimensionValue(v["duration"]),
|
|
2355
|
+
aliasFor("duration")
|
|
2356
|
+
],
|
|
2357
|
+
[
|
|
2358
|
+
"timingFunction",
|
|
2359
|
+
formatPrimitive(v["timingFunction"]),
|
|
2360
|
+
aliasFor("timingFunction")
|
|
2361
|
+
],
|
|
2362
|
+
[
|
|
2363
|
+
"delay",
|
|
2364
|
+
formatDimensionValue(v["delay"]),
|
|
2365
|
+
aliasFor("delay")
|
|
2366
|
+
]
|
|
2332
2367
|
]);
|
|
2333
2368
|
}
|
|
2334
2369
|
if (type === "shadow") {
|
|
2335
2370
|
const layers = Array.isArray(rawValue) ? rawValue : [rawValue];
|
|
2336
2371
|
const multi = layers.length > 1;
|
|
2372
|
+
const layerAliasFor = (i, key) => subValueChain(arrayAliases?.[i]?.[key], resolved);
|
|
2337
2373
|
return /* @__PURE__ */ jsx("div", {
|
|
2338
2374
|
className: "sb-token-detail__breakdown-section",
|
|
2339
2375
|
children: layers.map((layer, i) => {
|
|
@@ -2347,27 +2383,33 @@ function CompositeBreakdownContent({ type, rawValue, colorFormat }) {
|
|
|
2347
2383
|
}),
|
|
2348
2384
|
/* @__PURE__ */ jsx(KeyValueRow, {
|
|
2349
2385
|
label: "color",
|
|
2350
|
-
value: formatColorSubValue(v["color"], colorFormat)
|
|
2386
|
+
value: formatColorSubValue(v["color"], colorFormat),
|
|
2387
|
+
alias: layerAliasFor(i, "color")
|
|
2351
2388
|
}),
|
|
2352
2389
|
/* @__PURE__ */ jsx(KeyValueRow, {
|
|
2353
2390
|
label: "offsetX",
|
|
2354
|
-
value: formatDimensionValue(v["offsetX"])
|
|
2391
|
+
value: formatDimensionValue(v["offsetX"]),
|
|
2392
|
+
alias: layerAliasFor(i, "offsetX")
|
|
2355
2393
|
}),
|
|
2356
2394
|
/* @__PURE__ */ jsx(KeyValueRow, {
|
|
2357
2395
|
label: "offsetY",
|
|
2358
|
-
value: formatDimensionValue(v["offsetY"])
|
|
2396
|
+
value: formatDimensionValue(v["offsetY"]),
|
|
2397
|
+
alias: layerAliasFor(i, "offsetY")
|
|
2359
2398
|
}),
|
|
2360
2399
|
/* @__PURE__ */ jsx(KeyValueRow, {
|
|
2361
2400
|
label: "blur",
|
|
2362
|
-
value: formatDimensionValue(v["blur"])
|
|
2401
|
+
value: formatDimensionValue(v["blur"]),
|
|
2402
|
+
alias: layerAliasFor(i, "blur")
|
|
2363
2403
|
}),
|
|
2364
2404
|
/* @__PURE__ */ jsx(KeyValueRow, {
|
|
2365
2405
|
label: "spread",
|
|
2366
|
-
value: formatDimensionValue(v["spread"])
|
|
2406
|
+
value: formatDimensionValue(v["spread"]),
|
|
2407
|
+
alias: layerAliasFor(i, "spread")
|
|
2367
2408
|
}),
|
|
2368
2409
|
"inset" in v && /* @__PURE__ */ jsx(KeyValueRow, {
|
|
2369
2410
|
label: "inset",
|
|
2370
|
-
value: formatPrimitive(v["inset"])
|
|
2411
|
+
value: formatPrimitive(v["inset"]),
|
|
2412
|
+
alias: void 0
|
|
2371
2413
|
})
|
|
2372
2414
|
]
|
|
2373
2415
|
}, shadowLayerKey(v, i));
|
|
@@ -2377,13 +2419,15 @@ function CompositeBreakdownContent({ type, rawValue, colorFormat }) {
|
|
|
2377
2419
|
if (type === "gradient") {
|
|
2378
2420
|
const stops = Array.isArray(rawValue) ? rawValue : [];
|
|
2379
2421
|
if (stops.length === 0) return null;
|
|
2422
|
+
const stopAliasFor = (i) => subValueChain(arrayAliases?.[i]?.["color"], resolved);
|
|
2380
2423
|
return /* @__PURE__ */ jsx("div", {
|
|
2381
2424
|
className: "sb-token-detail__breakdown-section",
|
|
2382
2425
|
children: stops.map((stop, i) => {
|
|
2383
2426
|
const v = stop;
|
|
2384
2427
|
return /* @__PURE__ */ jsx(KeyValueRow, {
|
|
2385
2428
|
label: `${((typeof v["position"] === "number" ? v["position"] : 0) * 100).toFixed(0)}%`,
|
|
2386
|
-
value: formatColorSubValue(v["color"], colorFormat)
|
|
2429
|
+
value: formatColorSubValue(v["color"], colorFormat),
|
|
2430
|
+
alias: stopAliasFor(i)
|
|
2387
2431
|
}, gradientStopKey(v, i));
|
|
2388
2432
|
})
|
|
2389
2433
|
});
|
|
@@ -2393,17 +2437,35 @@ function CompositeBreakdownContent({ type, rawValue, colorFormat }) {
|
|
|
2393
2437
|
function renderKeyValueList(rows) {
|
|
2394
2438
|
return /* @__PURE__ */ jsx("div", {
|
|
2395
2439
|
className: "sb-token-detail__breakdown-section",
|
|
2396
|
-
children: rows.filter(([, v]) => v !== null).map(([k, v]) => /* @__PURE__ */ jsx(KeyValueRow, {
|
|
2440
|
+
children: rows.filter(([, v, alias]) => v !== null || alias && alias.length > 0).map(([k, v, alias]) => /* @__PURE__ */ jsx(KeyValueRow, {
|
|
2397
2441
|
label: k,
|
|
2398
|
-
value: v ?? ""
|
|
2442
|
+
value: v ?? "",
|
|
2443
|
+
alias
|
|
2399
2444
|
}, k))
|
|
2400
2445
|
});
|
|
2401
2446
|
}
|
|
2402
|
-
function KeyValueRow({ label, value }) {
|
|
2447
|
+
function KeyValueRow({ label, value, alias }) {
|
|
2448
|
+
const hasAlias = alias && alias.length > 0;
|
|
2403
2449
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
2404
2450
|
className: "sb-token-detail__breakdown-key",
|
|
2405
2451
|
children: label
|
|
2406
|
-
}), /* @__PURE__ */
|
|
2452
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
2453
|
+
className: "sb-token-detail__breakdown-value",
|
|
2454
|
+
children: [/* @__PURE__ */ jsx("span", { children: value ?? "—" }), hasAlias && /* @__PURE__ */ jsx("span", {
|
|
2455
|
+
className: "sb-token-detail__breakdown-alias",
|
|
2456
|
+
"data-testid": "breakdown-alias",
|
|
2457
|
+
children: alias.map((p, i) => /* @__PURE__ */ jsxs("span", {
|
|
2458
|
+
className: "sb-token-detail__breakdown-alias-step",
|
|
2459
|
+
children: [i > 0 && /* @__PURE__ */ jsx("span", {
|
|
2460
|
+
className: "sb-token-detail__arrow",
|
|
2461
|
+
children: "→"
|
|
2462
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
2463
|
+
className: "sb-token-detail__chain-node",
|
|
2464
|
+
children: p
|
|
2465
|
+
})]
|
|
2466
|
+
}, p))
|
|
2467
|
+
})]
|
|
2468
|
+
})] });
|
|
2407
2469
|
}
|
|
2408
2470
|
function formatPrimitive(v) {
|
|
2409
2471
|
if (v == null) return null;
|
|
@@ -2435,6 +2497,24 @@ function formatColorSubValue(v, format) {
|
|
|
2435
2497
|
if (v == null) return null;
|
|
2436
2498
|
return formatColor(v, format).value;
|
|
2437
2499
|
}
|
|
2500
|
+
function pickObjectAliases(v) {
|
|
2501
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return void 0;
|
|
2502
|
+
return v;
|
|
2503
|
+
}
|
|
2504
|
+
function pickArrayAliases(v) {
|
|
2505
|
+
if (!Array.isArray(v)) return void 0;
|
|
2506
|
+
return v;
|
|
2507
|
+
}
|
|
2508
|
+
/**
|
|
2509
|
+
* Walk the alias chain starting from an immediate sub-value alias target.
|
|
2510
|
+
* `aliasTarget` is the path the sub-value directly references; the target
|
|
2511
|
+
* token's own `aliasChain` continues the walk to the primitive.
|
|
2512
|
+
*/
|
|
2513
|
+
function subValueChain(aliasTarget, resolved) {
|
|
2514
|
+
if (!aliasTarget) return void 0;
|
|
2515
|
+
const tail = (resolved?.[aliasTarget])?.aliasChain;
|
|
2516
|
+
return tail && tail.length > 0 ? [aliasTarget, ...tail] : [aliasTarget];
|
|
2517
|
+
}
|
|
2438
2518
|
function shadowLayerKey(layer, fallback) {
|
|
2439
2519
|
return `shadow|${[
|
|
2440
2520
|
layer["color"],
|