@unpunnyfuns/swatchbook-blocks 0.56.0 → 0.57.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/README.md +2 -2
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +117 -157
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import './style.css';
|
|
2
2
|
import Color from "colorjs.io";
|
|
3
|
-
import {
|
|
4
|
-
import { Fragment
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { buildResolveAt } from "@unpunnyfuns/swatchbook-core/resolve-at";
|
|
6
6
|
import { makeCssVar } from "@unpunnyfuns/swatchbook-core/css-var";
|
|
7
|
+
import { SWATCHBOOK_STYLE_ELEMENT_ID, ensureStyleElement } from "@unpunnyfuns/swatchbook-core/style-element";
|
|
8
|
+
import { tupleToName } from "@unpunnyfuns/swatchbook-core/themes";
|
|
7
9
|
import { addons } from "storybook/preview-api";
|
|
8
10
|
import { axes, cells, css, cssVarPrefix, defaultTuple, diagnostics, jointOverrides, listing, presets, varianceByPath } from "virtual:swatchbook/tokens";
|
|
9
11
|
import { dataAttr } from "@unpunnyfuns/swatchbook-core/data-attr";
|
|
12
|
+
import { matchPath } from "@unpunnyfuns/swatchbook-core/match-path";
|
|
10
13
|
import { fuzzyFilter } from "@unpunnyfuns/swatchbook-core/fuzzy";
|
|
11
14
|
import cx from "clsx";
|
|
12
15
|
//#region src/format-color.ts
|
|
@@ -282,13 +285,13 @@ function useOptionalSwatchbookData() {
|
|
|
282
285
|
* `useGlobals` so the same hook works in autodocs / MDX renders where the
|
|
283
286
|
* preview-hooks context isn't available.
|
|
284
287
|
*/
|
|
285
|
-
const
|
|
286
|
-
function
|
|
287
|
-
return useContext(
|
|
288
|
+
const ThemeContext = createContext("");
|
|
289
|
+
function useActiveTheme() {
|
|
290
|
+
return useContext(ThemeContext);
|
|
288
291
|
}
|
|
289
292
|
/**
|
|
290
293
|
* Active axis tuple for the current story/docs render — `Record<axisName,
|
|
291
|
-
* contextName>`. Derived from the same input as {@link
|
|
294
|
+
* contextName>`. Derived from the same input as {@link ThemeContext}; split
|
|
292
295
|
* out so consumers needing per-axis info (toolbar, panel, tuple-aware
|
|
293
296
|
* blocks) don't have to reparse the composed permutation ID.
|
|
294
297
|
*/
|
|
@@ -383,16 +386,8 @@ function useTokenSnapshot() {
|
|
|
383
386
|
}
|
|
384
387
|
//#endregion
|
|
385
388
|
//#region src/internal/use-project.ts
|
|
386
|
-
const STYLE_ELEMENT_ID = "swatchbook-tokens";
|
|
387
389
|
function ensureStylesheet(css) {
|
|
388
|
-
|
|
389
|
-
let style = document.getElementById(STYLE_ELEMENT_ID);
|
|
390
|
-
if (!style) {
|
|
391
|
-
style = document.createElement("style");
|
|
392
|
-
style.id = STYLE_ELEMENT_ID;
|
|
393
|
-
document.head.appendChild(style);
|
|
394
|
-
}
|
|
395
|
-
if (style.textContent !== css) style.textContent = css;
|
|
390
|
+
ensureStyleElement(SWATCHBOOK_STYLE_ELEMENT_ID, css);
|
|
396
391
|
}
|
|
397
392
|
function defaultTuple$1(axes) {
|
|
398
393
|
const out = {};
|
|
@@ -400,15 +395,6 @@ function defaultTuple$1(axes) {
|
|
|
400
395
|
return out;
|
|
401
396
|
}
|
|
402
397
|
/**
|
|
403
|
-
* Synthesize a permutation name from a tuple — same form
|
|
404
|
-
* `permutationID` produces server-side (axis values joined by ` · `).
|
|
405
|
-
* Used by the AxisVariance grid for `data-<prefix>-theme` attribution
|
|
406
|
-
* and similar display-only callers.
|
|
407
|
-
*/
|
|
408
|
-
function tupleToName(axes, tuple) {
|
|
409
|
-
return axes.map((a) => tuple[a.name] ?? a.default).join(" · ");
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
398
|
* Reconstruct a `resolveAt` accessor from snapshot data. Both `cells`
|
|
413
399
|
* and `jointOverrides` ship as plain JSON in the same shape core uses
|
|
414
400
|
* internally — no Map reconstruction at the boundary. Stable identity
|
|
@@ -454,7 +440,7 @@ function useProject() {
|
|
|
454
440
|
const jointOverrides = snapshot?.jointOverrides;
|
|
455
441
|
const dataDefaultTuple = snapshot?.defaultTuple;
|
|
456
442
|
const activeAxes = snapshot?.activeAxes;
|
|
457
|
-
const
|
|
443
|
+
const activeTheme = snapshot?.activeTheme;
|
|
458
444
|
const diagnostics = snapshot?.diagnostics;
|
|
459
445
|
const cssVarPrefix = snapshot?.cssVarPrefix;
|
|
460
446
|
const listing = snapshot?.listing;
|
|
@@ -467,12 +453,12 @@ function useProject() {
|
|
|
467
453
|
cells,
|
|
468
454
|
jointOverrides,
|
|
469
455
|
dataDefaultTuple,
|
|
470
|
-
|
|
456
|
+
activeTheme
|
|
471
457
|
]);
|
|
472
458
|
const providerData = useMemo(() => {
|
|
473
459
|
if (!snapshot || !resolveAt || !axes || !activeAxes) return null;
|
|
474
460
|
return {
|
|
475
|
-
|
|
461
|
+
activeTheme: activeTheme ?? "",
|
|
476
462
|
activeAxes,
|
|
477
463
|
axes,
|
|
478
464
|
resolved: resolveAt(activeAxes),
|
|
@@ -481,7 +467,7 @@ function useProject() {
|
|
|
481
467
|
listing: listing ?? {},
|
|
482
468
|
varianceByPath: varianceByPath ?? {},
|
|
483
469
|
resolveAt,
|
|
484
|
-
|
|
470
|
+
themeNameForTuple: (tuple) => tupleToName(axes, tuple)
|
|
485
471
|
};
|
|
486
472
|
}, [
|
|
487
473
|
snapshot,
|
|
@@ -490,7 +476,7 @@ function useProject() {
|
|
|
490
476
|
cells,
|
|
491
477
|
jointOverrides,
|
|
492
478
|
dataDefaultTuple,
|
|
493
|
-
|
|
479
|
+
activeTheme,
|
|
494
480
|
activeAxes,
|
|
495
481
|
diagnostics,
|
|
496
482
|
cssVarPrefix,
|
|
@@ -501,7 +487,7 @@ function useProject() {
|
|
|
501
487
|
return providerData ?? fallback;
|
|
502
488
|
}
|
|
503
489
|
function useVirtualModuleFallback(enabled) {
|
|
504
|
-
const contextPermutation =
|
|
490
|
+
const contextPermutation = useActiveTheme();
|
|
505
491
|
const contextAxes = useActiveAxes();
|
|
506
492
|
const channelGlobals = useChannelGlobals();
|
|
507
493
|
/**
|
|
@@ -523,7 +509,7 @@ function useVirtualModuleFallback(enabled) {
|
|
|
523
509
|
channelGlobals.axes,
|
|
524
510
|
tokens.axes
|
|
525
511
|
]);
|
|
526
|
-
const
|
|
512
|
+
const activeTheme = contextPermutation || tupleToName(tokens.axes, activeAxes);
|
|
527
513
|
const resolveAt = useMemo(() => makeResolveAt({
|
|
528
514
|
axes: tokens.axes,
|
|
529
515
|
cells: tokens.cells,
|
|
@@ -536,7 +522,7 @@ function useVirtualModuleFallback(enabled) {
|
|
|
536
522
|
tokens.defaultTuple
|
|
537
523
|
]);
|
|
538
524
|
return useMemo(() => ({
|
|
539
|
-
|
|
525
|
+
activeTheme,
|
|
540
526
|
activeAxes,
|
|
541
527
|
axes: tokens.axes,
|
|
542
528
|
resolved: resolveAt(activeAxes),
|
|
@@ -545,9 +531,9 @@ function useVirtualModuleFallback(enabled) {
|
|
|
545
531
|
listing: tokens.listing,
|
|
546
532
|
varianceByPath: tokens.varianceByPath,
|
|
547
533
|
resolveAt,
|
|
548
|
-
|
|
534
|
+
themeNameForTuple: (tuple) => tupleToName(tokens.axes, tuple)
|
|
549
535
|
}), [
|
|
550
|
-
|
|
536
|
+
activeTheme,
|
|
551
537
|
activeAxes,
|
|
552
538
|
tokens.axes,
|
|
553
539
|
tokens.diagnostics,
|
|
@@ -592,31 +578,6 @@ function resolveColorValue(path, raw, colorFormat, project) {
|
|
|
592
578
|
}
|
|
593
579
|
return formatColor(raw, colorFormat);
|
|
594
580
|
}
|
|
595
|
-
/**
|
|
596
|
-
* Match a dot-separated DTCG token path against a block `filter` prop.
|
|
597
|
-
*
|
|
598
|
-
* **Supported shapes** (the narrow subset we need — DTCG paths don't have
|
|
599
|
-
* directories, brace expansion, or regex, so we skip a full glob engine):
|
|
600
|
-
*
|
|
601
|
-
* | Pattern | Matches |
|
|
602
|
-
* | ------------------ | --------------------------------------------------- |
|
|
603
|
-
* | `undefined` / `''` | everything |
|
|
604
|
-
* | `*` or `**` | everything |
|
|
605
|
-
* | `color` | exact path `color`, or any descendant `color.*` |
|
|
606
|
-
* | `color.*` | any path whose fixed prefix is `color.` |
|
|
607
|
-
* | `color**` | any path starting with `color` |
|
|
608
|
-
*
|
|
609
|
-
* Not supported (all pass through as literal segment matchers): brace
|
|
610
|
-
* expansion (`{a,b}`), mid-path globs (`color.*.bg`), negation (`!foo`),
|
|
611
|
-
* character classes (`[sys]`). If you hit those, pre-filter by hand.
|
|
612
|
-
*/
|
|
613
|
-
function globMatch(path, glob) {
|
|
614
|
-
if (!glob) return true;
|
|
615
|
-
if (glob === "*" || glob === "**") return true;
|
|
616
|
-
if (glob.endsWith(".*")) return path.startsWith(`${glob.slice(0, -2)}.`);
|
|
617
|
-
if (glob.endsWith("**")) return path.startsWith(glob.slice(0, -2));
|
|
618
|
-
return path === glob || path.startsWith(`${glob}.`);
|
|
619
|
-
}
|
|
620
581
|
//#endregion
|
|
621
582
|
//#region src/border-preview/BorderSample.tsx
|
|
622
583
|
const sampleStyle$1 = {
|
|
@@ -814,12 +775,12 @@ function formatSubColor$1(raw, format) {
|
|
|
814
775
|
}
|
|
815
776
|
function BorderPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
816
777
|
const project = useProject();
|
|
817
|
-
const { resolved,
|
|
778
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
818
779
|
const colorFormat = useColorFormat();
|
|
819
780
|
const rows = useMemo(() => {
|
|
820
781
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
821
782
|
if (token.$type !== "border") return false;
|
|
822
|
-
return
|
|
783
|
+
return matchPath(path, filter);
|
|
823
784
|
}), {
|
|
824
785
|
by: sortBy,
|
|
825
786
|
dir: sortDir
|
|
@@ -835,16 +796,16 @@ function BorderPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
|
835
796
|
sortBy,
|
|
836
797
|
sortDir
|
|
837
798
|
]);
|
|
838
|
-
const captionText = caption ?? `${rows.length} border${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
799
|
+
const captionText = caption ?? `${rows.length} border${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
839
800
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
840
|
-
...themeAttrs(cssVarPrefix,
|
|
801
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
841
802
|
children: /* @__PURE__ */ jsx("div", {
|
|
842
803
|
className: "sb-block__empty",
|
|
843
804
|
children: "No border tokens match this filter."
|
|
844
805
|
})
|
|
845
806
|
});
|
|
846
807
|
return /* @__PURE__ */ jsxs("div", {
|
|
847
|
-
...themeAttrs(cssVarPrefix,
|
|
808
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
848
809
|
children: [/* @__PURE__ */ jsx("div", {
|
|
849
810
|
className: "sb-block__caption",
|
|
850
811
|
children: captionText
|
|
@@ -907,12 +868,12 @@ function fixedPrefixLength(filter) {
|
|
|
907
868
|
}
|
|
908
869
|
function ColorPalette({ filter, groupBy, caption, sortBy = "path", sortDir = "asc" }) {
|
|
909
870
|
const project = useProject();
|
|
910
|
-
const { resolved,
|
|
871
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
911
872
|
const colorFormat = useColorFormat();
|
|
912
873
|
const groups = useMemo(() => {
|
|
913
874
|
const entries = sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
914
875
|
if (token.$type !== "color") return false;
|
|
915
|
-
return
|
|
876
|
+
return matchPath(path, filter);
|
|
916
877
|
}), {
|
|
917
878
|
by: sortBy,
|
|
918
879
|
dir: sortDir
|
|
@@ -946,16 +907,16 @@ function ColorPalette({ filter, groupBy, caption, sortBy = "path", sortDir = "as
|
|
|
946
907
|
sortDir
|
|
947
908
|
]);
|
|
948
909
|
const totalCount = groups.reduce((acc, [, swatches]) => acc + swatches.length, 0);
|
|
949
|
-
const captionText = caption ?? `${totalCount} color${totalCount === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
910
|
+
const captionText = caption ?? `${totalCount} color${totalCount === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
950
911
|
if (totalCount === 0) return /* @__PURE__ */ jsx("div", {
|
|
951
|
-
...themeAttrs(cssVarPrefix,
|
|
912
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
952
913
|
children: /* @__PURE__ */ jsx("div", {
|
|
953
914
|
className: "sb-block__empty",
|
|
954
915
|
children: "No color tokens match this filter."
|
|
955
916
|
})
|
|
956
917
|
});
|
|
957
918
|
return /* @__PURE__ */ jsxs("div", {
|
|
958
|
-
...themeAttrs(cssVarPrefix,
|
|
919
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
959
920
|
children: [/* @__PURE__ */ jsx("div", {
|
|
960
921
|
className: "sb-block__caption",
|
|
961
922
|
children: captionText
|
|
@@ -1042,7 +1003,7 @@ const BASE_LABEL = "base";
|
|
|
1042
1003
|
const COLUMN_COUNT = 6;
|
|
1043
1004
|
function ColorTable({ filter, caption, sortBy = "path", sortDir = "asc", searchable = true, onSelect, variants }) {
|
|
1044
1005
|
const project = useProject();
|
|
1045
|
-
const { resolved,
|
|
1006
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
1046
1007
|
const colorFormat = useColorFormat();
|
|
1047
1008
|
const [query, setQuery] = useState("");
|
|
1048
1009
|
const [selectedByBase, setSelectedByBase] = useState({});
|
|
@@ -1051,7 +1012,7 @@ function ColorTable({ filter, caption, sortBy = "path", sortDir = "asc", searcha
|
|
|
1051
1012
|
const groups = useMemo(() => {
|
|
1052
1013
|
const sorted = sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1053
1014
|
if (token.$type !== "color") return false;
|
|
1054
|
-
return
|
|
1015
|
+
return matchPath(path, filter);
|
|
1055
1016
|
}), {
|
|
1056
1017
|
by: sortBy,
|
|
1057
1018
|
dir: sortDir
|
|
@@ -1129,16 +1090,16 @@ function ColorTable({ filter, caption, sortBy = "path", sortDir = "asc", searcha
|
|
|
1129
1090
|
}));
|
|
1130
1091
|
}, []);
|
|
1131
1092
|
const matchSuffix = searchable && query.trim() !== "" ? ` · ${visibleGroups.length} matching "${query.trim()}"` : "";
|
|
1132
|
-
const captionText = caption ?? `${totalTokens} color${totalTokens === 1 ? "" : "s"} across ${groups.length} group${groups.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""}${matchSuffix} · ${
|
|
1093
|
+
const captionText = caption ?? `${totalTokens} color${totalTokens === 1 ? "" : "s"} across ${groups.length} group${groups.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""}${matchSuffix} · ${activeTheme}`;
|
|
1133
1094
|
if (groups.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
1134
|
-
...themeAttrs(cssVarPrefix,
|
|
1095
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1135
1096
|
children: /* @__PURE__ */ jsx("div", {
|
|
1136
1097
|
className: "sb-block__empty",
|
|
1137
1098
|
children: "No color tokens match this filter."
|
|
1138
1099
|
})
|
|
1139
1100
|
});
|
|
1140
1101
|
return /* @__PURE__ */ jsxs("div", {
|
|
1141
|
-
...themeAttrs(cssVarPrefix,
|
|
1102
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1142
1103
|
children: [searchable && /* @__PURE__ */ jsx("div", {
|
|
1143
1104
|
className: "sb-color-table__search",
|
|
1144
1105
|
children: /* @__PURE__ */ jsx("input", {
|
|
@@ -1560,12 +1521,12 @@ function summaryVariant(diagnostics) {
|
|
|
1560
1521
|
* on their own MDX pages.
|
|
1561
1522
|
*/
|
|
1562
1523
|
function Diagnostics({ caption } = {}) {
|
|
1563
|
-
const {
|
|
1524
|
+
const { activeTheme, cssVarPrefix, diagnostics } = useProject();
|
|
1564
1525
|
const hasErrorsOrWarnings = diagnostics.some((d) => d.severity === "error" || d.severity === "warn");
|
|
1565
1526
|
const headingText = caption ?? `Diagnostics · ${summaryText(diagnostics)}`;
|
|
1566
1527
|
const variant = summaryVariant(diagnostics);
|
|
1567
1528
|
return /* @__PURE__ */ jsx("div", {
|
|
1568
|
-
...themeAttrs(cssVarPrefix,
|
|
1529
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1569
1530
|
"data-testid": "diagnostics",
|
|
1570
1531
|
children: /* @__PURE__ */ jsxs("details", {
|
|
1571
1532
|
open: hasErrorsOrWarnings,
|
|
@@ -1782,11 +1743,11 @@ function toPixels(raw) {
|
|
|
1782
1743
|
}
|
|
1783
1744
|
function DimensionScale({ filter, kind = "length", caption, sortBy = "value", sortDir = "asc" }) {
|
|
1784
1745
|
const project = useProject();
|
|
1785
|
-
const { resolved,
|
|
1746
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
1786
1747
|
const rows = useMemo(() => {
|
|
1787
1748
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1788
1749
|
if (token.$type !== "dimension") return false;
|
|
1789
|
-
return
|
|
1750
|
+
return matchPath(path, filter);
|
|
1790
1751
|
}), {
|
|
1791
1752
|
by: sortBy,
|
|
1792
1753
|
dir: sortDir
|
|
@@ -1807,16 +1768,16 @@ function DimensionScale({ filter, kind = "length", caption, sortBy = "value", so
|
|
|
1807
1768
|
sortBy,
|
|
1808
1769
|
sortDir
|
|
1809
1770
|
]);
|
|
1810
|
-
const captionText = caption ?? `${rows.length} dimension${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
1771
|
+
const captionText = caption ?? `${rows.length} dimension${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
1811
1772
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
1812
|
-
...themeAttrs(cssVarPrefix,
|
|
1773
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1813
1774
|
children: /* @__PURE__ */ jsx("div", {
|
|
1814
1775
|
className: "sb-block__empty",
|
|
1815
1776
|
children: "No dimension tokens match this filter."
|
|
1816
1777
|
})
|
|
1817
1778
|
});
|
|
1818
1779
|
return /* @__PURE__ */ jsxs("div", {
|
|
1819
|
-
...themeAttrs(cssVarPrefix,
|
|
1780
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1820
1781
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1821
1782
|
className: "sb-block__caption",
|
|
1822
1783
|
children: captionText
|
|
@@ -1864,11 +1825,11 @@ function stackString(raw) {
|
|
|
1864
1825
|
}
|
|
1865
1826
|
function FontFamilySample({ filter, sample = "The quick brown fox jumps over the lazy dog.", caption, sortBy = "path", sortDir = "asc" }) {
|
|
1866
1827
|
const project = useProject();
|
|
1867
|
-
const { resolved,
|
|
1828
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
1868
1829
|
const rows = useMemo(() => {
|
|
1869
1830
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1870
1831
|
if (token.$type !== "fontFamily") return false;
|
|
1871
|
-
return
|
|
1832
|
+
return matchPath(path, filter);
|
|
1872
1833
|
}), {
|
|
1873
1834
|
by: sortBy,
|
|
1874
1835
|
dir: sortDir
|
|
@@ -1884,16 +1845,16 @@ function FontFamilySample({ filter, sample = "The quick brown fox jumps over the
|
|
|
1884
1845
|
sortBy,
|
|
1885
1846
|
sortDir
|
|
1886
1847
|
]);
|
|
1887
|
-
const captionText = caption ?? `${rows.length} fontFamily token${rows.length === 1 ? "" : "s"}${filter && filter !== "fontFamily" ? ` matching \`${filter}\`` : ""} · ${
|
|
1848
|
+
const captionText = caption ?? `${rows.length} fontFamily token${rows.length === 1 ? "" : "s"}${filter && filter !== "fontFamily" ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
1888
1849
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
1889
|
-
...themeAttrs(cssVarPrefix,
|
|
1850
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1890
1851
|
children: /* @__PURE__ */ jsx("div", {
|
|
1891
1852
|
className: "sb-block__empty",
|
|
1892
1853
|
children: "No fontFamily tokens match this filter."
|
|
1893
1854
|
})
|
|
1894
1855
|
});
|
|
1895
1856
|
return /* @__PURE__ */ jsxs("div", {
|
|
1896
|
-
...themeAttrs(cssVarPrefix,
|
|
1857
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1897
1858
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1898
1859
|
className: "sb-block__caption",
|
|
1899
1860
|
children: captionText
|
|
@@ -1950,11 +1911,11 @@ function toWeight(raw) {
|
|
|
1950
1911
|
}
|
|
1951
1912
|
function FontWeightScale({ filter, sample = "Aa", caption, sortBy = "value", sortDir = "asc" }) {
|
|
1952
1913
|
const project = useProject();
|
|
1953
|
-
const { resolved,
|
|
1914
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
1954
1915
|
const rows = useMemo(() => {
|
|
1955
1916
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
1956
1917
|
if (token.$type !== "fontWeight") return false;
|
|
1957
|
-
return
|
|
1918
|
+
return matchPath(path, filter);
|
|
1958
1919
|
}), {
|
|
1959
1920
|
by: sortBy,
|
|
1960
1921
|
dir: sortDir
|
|
@@ -1971,16 +1932,16 @@ function FontWeightScale({ filter, sample = "Aa", caption, sortBy = "value", sor
|
|
|
1971
1932
|
sortBy,
|
|
1972
1933
|
sortDir
|
|
1973
1934
|
]);
|
|
1974
|
-
const captionText = caption ?? `${rows.length} fontWeight token${rows.length === 1 ? "" : "s"}${filter && filter !== "fontWeight" ? ` matching \`${filter}\`` : ""} · ${
|
|
1935
|
+
const captionText = caption ?? `${rows.length} fontWeight token${rows.length === 1 ? "" : "s"}${filter && filter !== "fontWeight" ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
1975
1936
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
1976
|
-
...themeAttrs(cssVarPrefix,
|
|
1937
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1977
1938
|
children: /* @__PURE__ */ jsx("div", {
|
|
1978
1939
|
className: "sb-block__empty",
|
|
1979
1940
|
children: "No fontWeight tokens match this filter."
|
|
1980
1941
|
})
|
|
1981
1942
|
});
|
|
1982
1943
|
return /* @__PURE__ */ jsxs("div", {
|
|
1983
|
-
...themeAttrs(cssVarPrefix,
|
|
1944
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
1984
1945
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1985
1946
|
className: "sb-block__caption",
|
|
1986
1947
|
children: captionText
|
|
@@ -2030,12 +1991,12 @@ function stopKey(path, stop, fallback) {
|
|
|
2030
1991
|
}
|
|
2031
1992
|
function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
2032
1993
|
const project = useProject();
|
|
2033
|
-
const { resolved,
|
|
1994
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2034
1995
|
const colorFormat = useColorFormat();
|
|
2035
1996
|
const rows = useMemo(() => {
|
|
2036
1997
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
2037
1998
|
if (token.$type !== "gradient") return false;
|
|
2038
|
-
return
|
|
1999
|
+
return matchPath(path, filter);
|
|
2039
2000
|
}), {
|
|
2040
2001
|
by: sortBy,
|
|
2041
2002
|
dir: sortDir
|
|
@@ -2051,16 +2012,16 @@ function GradientPalette({ filter, caption, sortBy = "path", sortDir = "asc" })
|
|
|
2051
2012
|
sortBy,
|
|
2052
2013
|
sortDir
|
|
2053
2014
|
]);
|
|
2054
|
-
const captionText = caption ?? `${rows.length} gradient${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
2015
|
+
const captionText = caption ?? `${rows.length} gradient${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2055
2016
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2056
|
-
...themeAttrs(cssVarPrefix,
|
|
2017
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2057
2018
|
children: /* @__PURE__ */ jsx("div", {
|
|
2058
2019
|
className: "sb-block__empty",
|
|
2059
2020
|
children: "No gradient tokens match this filter."
|
|
2060
2021
|
})
|
|
2061
2022
|
});
|
|
2062
2023
|
return /* @__PURE__ */ jsxs("div", {
|
|
2063
|
-
...themeAttrs(cssVarPrefix,
|
|
2024
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2064
2025
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2065
2026
|
className: "sb-block__caption",
|
|
2066
2027
|
children: captionText
|
|
@@ -2297,14 +2258,14 @@ function formatSpec(row) {
|
|
|
2297
2258
|
}
|
|
2298
2259
|
function MotionPreview({ filter, caption }) {
|
|
2299
2260
|
const project = useProject();
|
|
2300
|
-
const { resolved,
|
|
2261
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2301
2262
|
const [speed, setSpeed] = useState(1);
|
|
2302
2263
|
const [run, setRun] = useState(0);
|
|
2303
2264
|
const reducedMotion = usePrefersReducedMotion();
|
|
2304
2265
|
const rows = useMemo(() => {
|
|
2305
2266
|
const collected = [];
|
|
2306
2267
|
for (const [path, token] of Object.entries(resolved)) {
|
|
2307
|
-
if (filter && !
|
|
2268
|
+
if (filter && !matchPath(path, filter)) continue;
|
|
2308
2269
|
if (!filter && ![
|
|
2309
2270
|
"transition",
|
|
2310
2271
|
"duration",
|
|
@@ -2332,16 +2293,16 @@ function MotionPreview({ filter, caption }) {
|
|
|
2332
2293
|
filter,
|
|
2333
2294
|
project
|
|
2334
2295
|
]);
|
|
2335
|
-
const captionText = caption ?? `${rows.length} motion token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
2296
|
+
const captionText = caption ?? `${rows.length} motion token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2336
2297
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2337
|
-
...themeAttrs(cssVarPrefix,
|
|
2298
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2338
2299
|
children: /* @__PURE__ */ jsx("div", {
|
|
2339
2300
|
className: "sb-block__empty",
|
|
2340
2301
|
children: "No motion tokens match this filter."
|
|
2341
2302
|
})
|
|
2342
2303
|
});
|
|
2343
2304
|
return /* @__PURE__ */ jsxs("div", {
|
|
2344
|
-
...themeAttrs(cssVarPrefix,
|
|
2305
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2345
2306
|
children: [
|
|
2346
2307
|
/* @__PURE__ */ jsx("div", {
|
|
2347
2308
|
className: "sb-block__caption",
|
|
@@ -2415,13 +2376,13 @@ function toOpacity(raw) {
|
|
|
2415
2376
|
*/
|
|
2416
2377
|
function OpacityScale({ filter, type = "number", sampleColor = "color.accent.bg", caption, sortBy = "value", sortDir = "asc" }) {
|
|
2417
2378
|
const project = useProject();
|
|
2418
|
-
const { resolved,
|
|
2379
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2419
2380
|
const rows = useMemo(() => {
|
|
2420
2381
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
2421
2382
|
if (token.$type !== type) return false;
|
|
2422
2383
|
const v = toOpacity(token.$value);
|
|
2423
2384
|
if (!Number.isFinite(v) || v < 0 || v > 1) return false;
|
|
2424
|
-
return
|
|
2385
|
+
return matchPath(path, filter);
|
|
2425
2386
|
}), {
|
|
2426
2387
|
by: sortBy,
|
|
2427
2388
|
dir: sortDir
|
|
@@ -2442,9 +2403,9 @@ function OpacityScale({ filter, type = "number", sampleColor = "color.accent.bg"
|
|
|
2442
2403
|
sortBy,
|
|
2443
2404
|
sortDir
|
|
2444
2405
|
]);
|
|
2445
|
-
const captionText = caption ?? `${rows.length} opacity token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
2406
|
+
const captionText = caption ?? `${rows.length} opacity token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2446
2407
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2447
|
-
...themeAttrs(cssVarPrefix,
|
|
2408
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2448
2409
|
children: /* @__PURE__ */ jsx("div", {
|
|
2449
2410
|
className: "sb-block__empty",
|
|
2450
2411
|
children: "No opacity tokens match this filter."
|
|
@@ -2452,7 +2413,7 @@ function OpacityScale({ filter, type = "number", sampleColor = "color.accent.bg"
|
|
|
2452
2413
|
});
|
|
2453
2414
|
const sampleColorVar = resolveCssVar(sampleColor, project);
|
|
2454
2415
|
return /* @__PURE__ */ jsxs("div", {
|
|
2455
|
-
...themeAttrs(cssVarPrefix,
|
|
2416
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2456
2417
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2457
2418
|
className: "sb-block__caption",
|
|
2458
2419
|
children: captionText
|
|
@@ -2560,12 +2521,12 @@ function layerKey(path, layer, fallback) {
|
|
|
2560
2521
|
}
|
|
2561
2522
|
function ShadowPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
2562
2523
|
const project = useProject();
|
|
2563
|
-
const { resolved,
|
|
2524
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2564
2525
|
const colorFormat = useColorFormat();
|
|
2565
2526
|
const rows = useMemo(() => {
|
|
2566
2527
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
2567
2528
|
if (token.$type !== "shadow") return false;
|
|
2568
|
-
return
|
|
2529
|
+
return matchPath(path, filter);
|
|
2569
2530
|
}), {
|
|
2570
2531
|
by: sortBy,
|
|
2571
2532
|
dir: sortDir
|
|
@@ -2581,16 +2542,16 @@ function ShadowPreview({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
|
2581
2542
|
sortBy,
|
|
2582
2543
|
sortDir
|
|
2583
2544
|
]);
|
|
2584
|
-
const captionText = caption ?? `${rows.length} shadow${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${
|
|
2545
|
+
const captionText = caption ?? `${rows.length} shadow${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2585
2546
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2586
|
-
...themeAttrs(cssVarPrefix,
|
|
2547
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2587
2548
|
children: /* @__PURE__ */ jsx("div", {
|
|
2588
2549
|
className: "sb-block__empty",
|
|
2589
2550
|
children: "No shadow tokens match this filter."
|
|
2590
2551
|
})
|
|
2591
2552
|
});
|
|
2592
2553
|
return /* @__PURE__ */ jsxs("div", {
|
|
2593
|
-
...themeAttrs(cssVarPrefix,
|
|
2554
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2594
2555
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2595
2556
|
className: "sb-block__caption",
|
|
2596
2557
|
children: captionText
|
|
@@ -2673,11 +2634,11 @@ function extractCssStyle(value) {
|
|
|
2673
2634
|
}
|
|
2674
2635
|
function StrokeStyleSample({ filter, caption, sortBy = "path", sortDir = "asc" }) {
|
|
2675
2636
|
const project = useProject();
|
|
2676
|
-
const { resolved,
|
|
2637
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
2677
2638
|
const rows = useMemo(() => {
|
|
2678
2639
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
2679
2640
|
if (token.$type !== "strokeStyle") return false;
|
|
2680
|
-
return
|
|
2641
|
+
return matchPath(path, filter);
|
|
2681
2642
|
}), {
|
|
2682
2643
|
by: sortBy,
|
|
2683
2644
|
dir: sortDir
|
|
@@ -2694,16 +2655,16 @@ function StrokeStyleSample({ filter, caption, sortBy = "path", sortDir = "asc" }
|
|
|
2694
2655
|
sortBy,
|
|
2695
2656
|
sortDir
|
|
2696
2657
|
]);
|
|
2697
|
-
const captionText = caption ?? `${rows.length} strokeStyle token${rows.length === 1 ? "" : "s"}${filter && filter !== "strokeStyle" ? ` matching \`${filter}\`` : ""} · ${
|
|
2658
|
+
const captionText = caption ?? `${rows.length} strokeStyle token${rows.length === 1 ? "" : "s"}${filter && filter !== "strokeStyle" ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
2698
2659
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
2699
|
-
...themeAttrs(cssVarPrefix,
|
|
2660
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2700
2661
|
children: /* @__PURE__ */ jsx("div", {
|
|
2701
2662
|
className: "sb-block__empty",
|
|
2702
2663
|
children: "No strokeStyle tokens match this filter."
|
|
2703
2664
|
})
|
|
2704
2665
|
});
|
|
2705
2666
|
return /* @__PURE__ */ jsxs("div", {
|
|
2706
|
-
...themeAttrs(cssVarPrefix,
|
|
2667
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
2707
2668
|
children: [/* @__PURE__ */ jsx("div", {
|
|
2708
2669
|
className: "sb-block__caption",
|
|
2709
2670
|
children: captionText
|
|
@@ -2740,19 +2701,19 @@ function StrokeStyleSample({ filter, caption, sortBy = "path", sortDir = "asc" }
|
|
|
2740
2701
|
//#region src/token-detail/internal.ts
|
|
2741
2702
|
function useTokenDetailData(path) {
|
|
2742
2703
|
const project = useProject();
|
|
2743
|
-
const {
|
|
2704
|
+
const { activeTheme, activeAxes, axes, resolved, cssVarPrefix, varianceByPath, resolveAt, themeNameForTuple } = project;
|
|
2744
2705
|
const typedResolved = resolved;
|
|
2745
2706
|
return {
|
|
2746
2707
|
token: typedResolved[path],
|
|
2747
2708
|
cssVar: resolveCssVar(path, project),
|
|
2748
|
-
|
|
2709
|
+
activeTheme,
|
|
2749
2710
|
activeAxes,
|
|
2750
2711
|
axes,
|
|
2751
2712
|
resolved: typedResolved,
|
|
2752
2713
|
cssVarPrefix,
|
|
2753
2714
|
varianceByPath,
|
|
2754
2715
|
resolveAt,
|
|
2755
|
-
|
|
2716
|
+
themeNameForTuple
|
|
2756
2717
|
};
|
|
2757
2718
|
}
|
|
2758
2719
|
//#endregion
|
|
@@ -2766,7 +2727,7 @@ function AliasChain({ path }) {
|
|
|
2766
2727
|
return [path];
|
|
2767
2728
|
}, [token, path]);
|
|
2768
2729
|
if (chain.length <= 1) return null;
|
|
2769
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
2730
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
2770
2731
|
className: "sb-token-detail__section-header",
|
|
2771
2732
|
children: "Alias chain"
|
|
2772
2733
|
}), /* @__PURE__ */ jsx("div", {
|
|
@@ -2795,7 +2756,7 @@ function AliasedBy({ path }) {
|
|
|
2795
2756
|
const tree = useMemo(() => buildAliasedByTree(path, resolved), [path, resolved]);
|
|
2796
2757
|
const truncated = useMemo(() => treeHasTruncation(tree), [tree]);
|
|
2797
2758
|
if (tree.length === 0) return null;
|
|
2798
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
2759
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2799
2760
|
/* @__PURE__ */ jsx("div", {
|
|
2800
2761
|
className: "sb-token-detail__section-header",
|
|
2801
2762
|
children: "Aliased by"
|
|
@@ -2877,7 +2838,7 @@ function treeHasTruncation(nodes) {
|
|
|
2877
2838
|
//#endregion
|
|
2878
2839
|
//#region src/token-detail/AxisVariance.tsx
|
|
2879
2840
|
function AxisVariance({ path }) {
|
|
2880
|
-
const { token, cssVar, axes, activeAxes, cssVarPrefix, varianceByPath, resolveAt,
|
|
2841
|
+
const { token, cssVar, axes, activeAxes, cssVarPrefix, varianceByPath, resolveAt, themeNameForTuple } = useTokenDetailData(path);
|
|
2881
2842
|
const colorFormat = useColorFormat();
|
|
2882
2843
|
const tokenType = token?.$type;
|
|
2883
2844
|
const isColor = tokenType === "color";
|
|
@@ -2898,10 +2859,10 @@ function AxisVariance({ path }) {
|
|
|
2898
2859
|
};
|
|
2899
2860
|
}
|
|
2900
2861
|
}, [path, varianceByPath]);
|
|
2901
|
-
if (axes.length === 0) return /* @__PURE__ */ jsx(Fragment
|
|
2862
|
+
if (axes.length === 0) return /* @__PURE__ */ jsx(Fragment, {});
|
|
2902
2863
|
if (variance.kind === "constant") {
|
|
2903
2864
|
const value = formatFn(resolveAt(activeAxes)[path]);
|
|
2904
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
2865
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
2905
2866
|
className: "sb-token-detail__section-header",
|
|
2906
2867
|
children: "Values across axes"
|
|
2907
2868
|
}), /* @__PURE__ */ jsx("table", {
|
|
@@ -2934,7 +2895,7 @@ function AxisVariance({ path }) {
|
|
|
2934
2895
|
if (variance.kind === "one-axis") {
|
|
2935
2896
|
const axisName = variance.axis;
|
|
2936
2897
|
const axis = axes.find((a) => a.name === axisName);
|
|
2937
|
-
if (!axis) return /* @__PURE__ */ jsx(Fragment
|
|
2898
|
+
if (!axis) return /* @__PURE__ */ jsx(Fragment, {});
|
|
2938
2899
|
const contextValues = axis.contexts.map((ctx) => {
|
|
2939
2900
|
const target = {
|
|
2940
2901
|
...activeAxes,
|
|
@@ -2942,11 +2903,11 @@ function AxisVariance({ path }) {
|
|
|
2942
2903
|
};
|
|
2943
2904
|
return {
|
|
2944
2905
|
ctx,
|
|
2945
|
-
themeName:
|
|
2906
|
+
themeName: themeNameForTuple(target) ?? "",
|
|
2946
2907
|
value: formatFn(resolveAt(target)[path])
|
|
2947
2908
|
};
|
|
2948
2909
|
});
|
|
2949
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
2910
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
2950
2911
|
className: "sb-token-detail__section-header",
|
|
2951
2912
|
children: ["Varies with ", axisName]
|
|
2952
2913
|
}), /* @__PURE__ */ jsx("table", {
|
|
@@ -2973,8 +2934,8 @@ function AxisVariance({ path }) {
|
|
|
2973
2934
|
})] });
|
|
2974
2935
|
}
|
|
2975
2936
|
const [rowAxis, colAxis, ...extra] = variance.varyingAxes.map((name) => axes.find((a) => a.name === name)).filter((a) => Boolean(a)).toSorted((a, b) => b.contexts.length - a.contexts.length);
|
|
2976
|
-
if (!rowAxis || !colAxis) return /* @__PURE__ */ jsx(Fragment
|
|
2977
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
2937
|
+
if (!rowAxis || !colAxis) return /* @__PURE__ */ jsx(Fragment, {});
|
|
2938
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2978
2939
|
/* @__PURE__ */ jsxs("div", {
|
|
2979
2940
|
className: "sb-token-detail__section-header",
|
|
2980
2941
|
children: ["Varies with ", variance.varyingAxes.join(" × ")]
|
|
@@ -3014,7 +2975,7 @@ function AxisVariance({ path }) {
|
|
|
3014
2975
|
[rowAxis.name]: row,
|
|
3015
2976
|
[colAxis.name]: col
|
|
3016
2977
|
};
|
|
3017
|
-
const name =
|
|
2978
|
+
const name = themeNameForTuple(target);
|
|
3018
2979
|
const value = formatFn(resolveAt(target)[path]);
|
|
3019
2980
|
return /* @__PURE__ */ jsxs("td", {
|
|
3020
2981
|
className: "sb-token-detail__theme-cell",
|
|
@@ -3214,7 +3175,7 @@ function renderKeyValueList(rows) {
|
|
|
3214
3175
|
}
|
|
3215
3176
|
function KeyValueRow({ label, value, alias }) {
|
|
3216
3177
|
const hasAlias = alias && alias.length > 0;
|
|
3217
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
3178
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
3218
3179
|
className: "sb-token-detail__breakdown-key",
|
|
3219
3180
|
children: label
|
|
3220
3181
|
}), /* @__PURE__ */ jsxs("span", {
|
|
@@ -3473,7 +3434,7 @@ function ConsumerOutput({ path }) {
|
|
|
3473
3434
|
const tupleLabel = Object.entries(activeAxes).map(([k, v]) => `${k}=${v}`).join(", ");
|
|
3474
3435
|
const names = listing[path]?.names ?? {};
|
|
3475
3436
|
const extraPlatforms = Object.keys(names).filter((platform) => platform !== "css" && names[platform]).toSorted();
|
|
3476
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
3437
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3477
3438
|
/* @__PURE__ */ jsx("div", {
|
|
3478
3439
|
className: "sb-token-detail__section-header",
|
|
3479
3440
|
children: "Consumer output"
|
|
@@ -3551,18 +3512,18 @@ async function copyToClipboard(text) {
|
|
|
3551
3512
|
//#endregion
|
|
3552
3513
|
//#region src/token-detail/TokenHeader.tsx
|
|
3553
3514
|
function TokenHeader({ path, heading }) {
|
|
3554
|
-
const { token, cssVar,
|
|
3515
|
+
const { token, cssVar, activeTheme } = useTokenDetailData(path);
|
|
3555
3516
|
if (!token) return /* @__PURE__ */ jsxs("div", {
|
|
3556
3517
|
className: "sb-token-detail__missing",
|
|
3557
3518
|
children: [
|
|
3558
3519
|
"Token ",
|
|
3559
3520
|
/* @__PURE__ */ jsx("code", { children: path }),
|
|
3560
3521
|
" not found in theme ",
|
|
3561
|
-
/* @__PURE__ */ jsx("strong", { children:
|
|
3522
|
+
/* @__PURE__ */ jsx("strong", { children: activeTheme }),
|
|
3562
3523
|
"."
|
|
3563
3524
|
]
|
|
3564
3525
|
});
|
|
3565
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
3526
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3566
3527
|
/* @__PURE__ */ jsx("h3", {
|
|
3567
3528
|
className: "sb-token-detail__heading",
|
|
3568
3529
|
children: heading ?? path
|
|
@@ -3586,7 +3547,7 @@ function TokenUsageSnippet({ path }) {
|
|
|
3586
3547
|
const { token, cssVar } = useTokenDetailData(path);
|
|
3587
3548
|
if (!token) return null;
|
|
3588
3549
|
const snippet = `color: ${cssVar};`;
|
|
3589
|
-
return /* @__PURE__ */ jsxs(Fragment
|
|
3550
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
3590
3551
|
className: "sb-token-detail__section-header",
|
|
3591
3552
|
children: "Usage"
|
|
3592
3553
|
}), /* @__PURE__ */ jsxs("div", {
|
|
@@ -3603,9 +3564,9 @@ function TokenUsageSnippet({ path }) {
|
|
|
3603
3564
|
//#endregion
|
|
3604
3565
|
//#region src/TokenDetail.tsx
|
|
3605
3566
|
function TokenDetail({ path, heading }) {
|
|
3606
|
-
const { token, cssVar,
|
|
3567
|
+
const { token, cssVar, activeTheme, cssVarPrefix } = useTokenDetailData(path);
|
|
3607
3568
|
const colorFormat = useColorFormat();
|
|
3608
|
-
const theme = themeAttrs(cssVarPrefix,
|
|
3569
|
+
const theme = themeAttrs(cssVarPrefix, activeTheme);
|
|
3609
3570
|
if (!token) return /* @__PURE__ */ jsx("div", {
|
|
3610
3571
|
...theme,
|
|
3611
3572
|
className: cx(theme["className"], "sb-token-detail"),
|
|
@@ -3615,7 +3576,7 @@ function TokenDetail({ path, heading }) {
|
|
|
3615
3576
|
"Token ",
|
|
3616
3577
|
/* @__PURE__ */ jsx("code", { children: path }),
|
|
3617
3578
|
" not found in theme ",
|
|
3618
|
-
/* @__PURE__ */ jsx("strong", { children:
|
|
3579
|
+
/* @__PURE__ */ jsx("strong", { children: activeTheme }),
|
|
3619
3580
|
"."
|
|
3620
3581
|
]
|
|
3621
3582
|
})
|
|
@@ -3635,7 +3596,7 @@ function TokenDetail({ path, heading }) {
|
|
|
3635
3596
|
}),
|
|
3636
3597
|
/* @__PURE__ */ jsxs("div", {
|
|
3637
3598
|
className: "sb-token-detail__section-header",
|
|
3638
|
-
children: ["Resolved value · ",
|
|
3599
|
+
children: ["Resolved value · ", activeTheme]
|
|
3639
3600
|
}),
|
|
3640
3601
|
/* @__PURE__ */ jsx(CompositePreview, { path }),
|
|
3641
3602
|
/* @__PURE__ */ jsx(CompositeBreakdown, { path }),
|
|
@@ -3864,7 +3825,7 @@ function pruneTreeForMatches(nodes, matches, expandOut) {
|
|
|
3864
3825
|
return out;
|
|
3865
3826
|
}
|
|
3866
3827
|
function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true, onSelect }) {
|
|
3867
|
-
const { resolved,
|
|
3828
|
+
const { resolved, activeTheme, cssVarPrefix } = useProject();
|
|
3868
3829
|
const typeFilter = useMemo(() => {
|
|
3869
3830
|
if (type === void 0) return void 0;
|
|
3870
3831
|
return new Set(Array.isArray(type) ? type : [type]);
|
|
@@ -4049,11 +4010,11 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
|
|
|
4049
4010
|
return n;
|
|
4050
4011
|
}, [visibleTree, searchExpanded]);
|
|
4051
4012
|
if (tree.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
4052
|
-
...themeAttrs(cssVarPrefix,
|
|
4013
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4053
4014
|
children: /* @__PURE__ */ jsx(EmptyState, { children: root ? `No tokens under "${root}"${typeFilter ? ` matching ${typeLabel.slice(3)}` : ""}.` : typeFilter ? `No tokens matching ${typeLabel.slice(3)} in the active theme.` : "No tokens in the active theme." })
|
|
4054
4015
|
});
|
|
4055
4016
|
return /* @__PURE__ */ jsxs("div", {
|
|
4056
|
-
...themeAttrs(cssVarPrefix,
|
|
4017
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4057
4018
|
children: [
|
|
4058
4019
|
searchable && /* @__PURE__ */ jsx("div", {
|
|
4059
4020
|
className: "sb-token-navigator__search",
|
|
@@ -4073,9 +4034,8 @@ function TokenNavigator({ root, type, initiallyExpanded = 1, searchable = true,
|
|
|
4073
4034
|
root ? `Tokens under ${root}` : "Token graph",
|
|
4074
4035
|
typeLabel,
|
|
4075
4036
|
trimmedQuery !== "" ? ` · ${matchCount} matching "${trimmedQuery}"` : "",
|
|
4076
|
-
" ·",
|
|
4077
|
-
|
|
4078
|
-
activePermutation
|
|
4037
|
+
" · ",
|
|
4038
|
+
activeTheme
|
|
4079
4039
|
]
|
|
4080
4040
|
}),
|
|
4081
4041
|
visibleTree.length === 0 ? /* @__PURE__ */ jsxs("div", {
|
|
@@ -4263,13 +4223,13 @@ function LeafPreview({ path, token }) {
|
|
|
4263
4223
|
//#region src/TokenTable.tsx
|
|
4264
4224
|
function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", searchable = true, onSelect }) {
|
|
4265
4225
|
const project = useProject();
|
|
4266
|
-
const { resolved,
|
|
4226
|
+
const { resolved, activeTheme, cssVarPrefix } = project;
|
|
4267
4227
|
const colorFormat = useColorFormat();
|
|
4268
4228
|
const [selectedPath, setSelectedPath] = useState(null);
|
|
4269
4229
|
const [query, setQuery] = useState("");
|
|
4270
4230
|
const rows = useMemo(() => {
|
|
4271
4231
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
4272
|
-
if (!
|
|
4232
|
+
if (!matchPath(path, filter)) return false;
|
|
4273
4233
|
if (type && token.$type !== type) return false;
|
|
4274
4234
|
return true;
|
|
4275
4235
|
}), {
|
|
@@ -4309,16 +4269,16 @@ function TokenTable({ filter, type, caption, sortBy = "path", sortDir = "asc", s
|
|
|
4309
4269
|
else setSelectedPath(path);
|
|
4310
4270
|
}, [onSelect]);
|
|
4311
4271
|
const matchSuffix = searchable && query.trim() !== "" ? ` · ${visibleRows.length} matching "${query.trim()}"` : "";
|
|
4312
|
-
const captionText = caption ?? `${rows.length} token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""}${type ? ` · $type=${type}` : ""}${matchSuffix} · ${
|
|
4272
|
+
const captionText = caption ?? `${rows.length} token${rows.length === 1 ? "" : "s"}${filter ? ` matching \`${filter}\`` : ""}${type ? ` · $type=${type}` : ""}${matchSuffix} · ${activeTheme}`;
|
|
4313
4273
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
4314
|
-
...themeAttrs(cssVarPrefix,
|
|
4274
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4315
4275
|
children: /* @__PURE__ */ jsx("div", {
|
|
4316
4276
|
className: "sb-block__empty",
|
|
4317
4277
|
children: "No tokens match this filter."
|
|
4318
4278
|
})
|
|
4319
4279
|
});
|
|
4320
4280
|
return /* @__PURE__ */ jsxs("div", {
|
|
4321
|
-
...themeAttrs(cssVarPrefix,
|
|
4281
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4322
4282
|
children: [
|
|
4323
4283
|
searchable && /* @__PURE__ */ jsx("div", {
|
|
4324
4284
|
className: "sb-token-table__search",
|
|
@@ -4458,11 +4418,11 @@ function buildRow(path, composite) {
|
|
|
4458
4418
|
};
|
|
4459
4419
|
}
|
|
4460
4420
|
function TypographyScale({ filter, sample = "The quick brown fox jumps over the lazy dog.", caption, sortBy = "path", sortDir = "asc" }) {
|
|
4461
|
-
const { resolved,
|
|
4421
|
+
const { resolved, activeTheme, cssVarPrefix } = useProject();
|
|
4462
4422
|
const rows = useMemo(() => {
|
|
4463
4423
|
return sortTokens(Object.entries(resolved).filter(([path, token]) => {
|
|
4464
4424
|
if (token.$type !== "typography") return false;
|
|
4465
|
-
return
|
|
4425
|
+
return matchPath(path, filter);
|
|
4466
4426
|
}), {
|
|
4467
4427
|
by: sortBy,
|
|
4468
4428
|
dir: sortDir
|
|
@@ -4481,16 +4441,16 @@ function TypographyScale({ filter, sample = "The quick brown fox jumps over the
|
|
|
4481
4441
|
sortBy,
|
|
4482
4442
|
sortDir
|
|
4483
4443
|
]);
|
|
4484
|
-
const captionText = caption ?? `${rows.length} typography token${rows.length === 1 ? "" : "s"}${filter && filter !== "typography" ? ` matching \`${filter}\`` : ""} · ${
|
|
4444
|
+
const captionText = caption ?? `${rows.length} typography token${rows.length === 1 ? "" : "s"}${filter && filter !== "typography" ? ` matching \`${filter}\`` : ""} · ${activeTheme}`;
|
|
4485
4445
|
if (rows.length === 0) return /* @__PURE__ */ jsx("div", {
|
|
4486
|
-
...themeAttrs(cssVarPrefix,
|
|
4446
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4487
4447
|
children: /* @__PURE__ */ jsx("div", {
|
|
4488
4448
|
className: "sb-block__empty",
|
|
4489
4449
|
children: "No typography tokens match this filter."
|
|
4490
4450
|
})
|
|
4491
4451
|
});
|
|
4492
4452
|
return /* @__PURE__ */ jsxs("div", {
|
|
4493
|
-
...themeAttrs(cssVarPrefix,
|
|
4453
|
+
...themeAttrs(cssVarPrefix, activeTheme),
|
|
4494
4454
|
children: [/* @__PURE__ */ jsx("div", {
|
|
4495
4455
|
className: "sb-block__caption",
|
|
4496
4456
|
children: captionText
|
|
@@ -4513,6 +4473,6 @@ function TypographyScale({ filter, sample = "The quick brown fox jumps over the
|
|
|
4513
4473
|
});
|
|
4514
4474
|
}
|
|
4515
4475
|
//#endregion
|
|
4516
|
-
export { AliasChain, AliasedBy, AxesContext, AxisVariance, BorderPreview, BorderSample, COLOR_FORMATS, ColorFormatContext, ColorPalette, ColorTable, CompositeBreakdown, CompositePreview, ConsumerOutput, Diagnostics, DimensionBar, DimensionScale, FontFamilySample, FontWeightScale, GradientPalette, MotionPreview, MotionSample, OpacityScale,
|
|
4476
|
+
export { AliasChain, AliasedBy, AxesContext, AxisVariance, BorderPreview, BorderSample, COLOR_FORMATS, ColorFormatContext, ColorPalette, ColorTable, CompositeBreakdown, CompositePreview, ConsumerOutput, Diagnostics, DimensionBar, DimensionScale, FontFamilySample, FontWeightScale, GradientPalette, MotionPreview, MotionSample, OpacityScale, ShadowPreview, ShadowSample, StrokeStyleSample, SwatchbookContext, SwatchbookProvider, ThemeContext, TokenDetail, TokenHeader, TokenNavigator, TokenTable, TokenUsageSnippet, TypographyScale, formatColor, useActiveAxes, useActiveTheme, useColorFormat, useOptionalSwatchbookData, useSwatchbookData };
|
|
4517
4477
|
|
|
4518
4478
|
//# sourceMappingURL=index.mjs.map
|