@sanity/ui 3.1.12 → 3.1.13

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/theme.mjs CHANGED
@@ -1786,7 +1786,28 @@ function v0_v2(v0) {
1786
1786
  };
1787
1787
  return cache$2.set(v0, v2), v2;
1788
1788
  }
1789
- const cache$1 = /* @__PURE__ */ new WeakMap();
1789
+ function defineLazyProperty(obj, key, factory) {
1790
+ Object.defineProperty(obj, key, {
1791
+ get() {
1792
+ const value = factory();
1793
+ return Object.defineProperty(obj, key, {
1794
+ value,
1795
+ enumerable: !0,
1796
+ writable: !1,
1797
+ configurable: !1
1798
+ }), value;
1799
+ },
1800
+ enumerable: !0,
1801
+ configurable: !0
1802
+ });
1803
+ }
1804
+ const cache$1 = /* @__PURE__ */ new WeakMap(), V0_TONES = ["transparent", "default", "primary", "positive", "caution", "critical"];
1805
+ function lazyV0Scheme(schemeKey, color2) {
1806
+ const scheme = {};
1807
+ for (const tone of V0_TONES)
1808
+ defineLazyProperty(scheme, tone, () => themeColor_v2_v0(color2[schemeKey][tone]));
1809
+ return scheme;
1810
+ }
1790
1811
  function v2_v0(v2) {
1791
1812
  const cachedTheme = cache$1.get(v2);
1792
1813
  if (cachedTheme) return cachedTheme;
@@ -1802,30 +1823,14 @@ function v2_v0(v2) {
1802
1823
  shadow: shadows,
1803
1824
  space,
1804
1825
  style: styles
1805
- } = v2;
1806
- return {
1826
+ } = v2, v0Color = {};
1827
+ defineLazyProperty(v0Color, "light", () => lazyV0Scheme("light", color2)), defineLazyProperty(v0Color, "dark", () => lazyV0Scheme("dark", color2));
1828
+ const theme = {
1807
1829
  _version: 0,
1808
1830
  avatar,
1809
1831
  button,
1810
1832
  container,
1811
- color: {
1812
- light: {
1813
- transparent: themeColor_v2_v0(color2.light.transparent),
1814
- default: themeColor_v2_v0(color2.light.default),
1815
- primary: themeColor_v2_v0(color2.light.primary),
1816
- positive: themeColor_v2_v0(color2.light.positive),
1817
- caution: themeColor_v2_v0(color2.light.caution),
1818
- critical: themeColor_v2_v0(color2.light.critical)
1819
- },
1820
- dark: {
1821
- transparent: themeColor_v2_v0(color2.dark.transparent),
1822
- default: themeColor_v2_v0(color2.dark.default),
1823
- primary: themeColor_v2_v0(color2.dark.primary),
1824
- positive: themeColor_v2_v0(color2.dark.positive),
1825
- caution: themeColor_v2_v0(color2.dark.caution),
1826
- critical: themeColor_v2_v0(color2.dark.critical)
1827
- }
1828
- },
1833
+ color: v0Color,
1829
1834
  focusRing: input.text.focusRing,
1830
1835
  fonts,
1831
1836
  input,
@@ -1836,6 +1841,7 @@ function v2_v0(v2) {
1836
1841
  styles,
1837
1842
  v2
1838
1843
  };
1844
+ return cache$1.set(v2, theme), theme;
1839
1845
  }
1840
1846
  function themeColor_v2_v0(color_v2) {
1841
1847
  return {
@@ -2905,25 +2911,22 @@ function resolveSelectableStateColorTokens(inputTokens, tone, state) {
2905
2911
  function buildColorTheme(config) {
2906
2912
  const resolvedConfig = {
2907
2913
  color: resolveColorTokens(config?.color)
2908
- };
2909
- return {
2910
- light: buildColorScheme({
2911
- scheme: "light"
2912
- }, resolvedConfig),
2913
- dark: buildColorScheme({
2914
- scheme: "dark"
2915
- }, resolvedConfig)
2916
- };
2914
+ }, schemes = {};
2915
+ return defineLazyProperty(schemes, "light", () => buildColorScheme({
2916
+ scheme: "light"
2917
+ }, resolvedConfig)), defineLazyProperty(schemes, "dark", () => buildColorScheme({
2918
+ scheme: "dark"
2919
+ }, resolvedConfig)), schemes;
2917
2920
  }
2918
2921
  function buildColorScheme(options, config) {
2919
2922
  const {
2920
2923
  scheme
2921
2924
  } = options, colorScheme = {};
2922
2925
  for (const tone of THEME_COLOR_CARD_TONES)
2923
- colorScheme[tone] = buildCardColorTheme({
2926
+ defineLazyProperty(colorScheme, tone, () => buildCardColorTheme({
2924
2927
  scheme,
2925
2928
  tone
2926
- }, config);
2929
+ }, config));
2927
2930
  return colorScheme;
2928
2931
  }
2929
2932
  function buildCardColorTheme(options, config) {
@@ -3590,24 +3593,29 @@ function renderColorHex(color2) {
3590
3593
  return typeof color2 == "string" ? color2 : color2.hex;
3591
3594
  }
3592
3595
  function renderThemeColorSchemes(value, config) {
3593
- const colorPalette = config?.palette ?? defaultColorPalette;
3594
- return {
3595
- light: renderThemeColorScheme(colorPalette, value.light),
3596
- dark: renderThemeColorScheme(colorPalette, value.dark)
3597
- };
3596
+ const colorPalette = config?.palette ?? defaultColorPalette, schemes = {};
3597
+ return defineLazyProperty(schemes, "light", () => renderThemeColorScheme(colorPalette, value.light)), defineLazyProperty(schemes, "dark", () => renderThemeColorScheme(colorPalette, value.dark)), schemes;
3598
3598
  }
3599
3599
  function renderThemeColorScheme(colorPalette, value) {
3600
- const toneEntries = Object.entries(value), [, transparentTone] = toneEntries.find(([k]) => k === "transparent"), [, defaultTone] = toneEntries.find(([k]) => k === "default"), renderedTransparentTone = renderThemeColor(transparentTone, {
3601
- colorPalette
3602
- }), renderedDefaultTone = renderThemeColor(defaultTone, {
3600
+ const renderedDefaultTone = renderThemeColor(value.default, {
3603
3601
  colorPalette
3604
3602
  }), bg = renderedDefaultTone.bg;
3605
3603
  if (bg === "white")
3606
3604
  throw new Error("Cannot blend with white background");
3607
- return Object.fromEntries([["transparent", renderedTransparentTone], ["default", renderedDefaultTone], ...toneEntries.filter(([k]) => k !== "default" && k !== "transparent").map(([k, v]) => [k, renderThemeColor(v, {
3608
- bg,
3609
- colorPalette
3610
- })])]);
3605
+ const scheme = {
3606
+ default: renderedDefaultTone
3607
+ };
3608
+ for (const tone of THEME_COLOR_CARD_TONES) {
3609
+ if (tone === "default") continue;
3610
+ const opts = tone === "transparent" ? {
3611
+ colorPalette
3612
+ } : {
3613
+ bg,
3614
+ colorPalette
3615
+ };
3616
+ defineLazyProperty(scheme, tone, () => renderThemeColor(value[tone], opts));
3617
+ }
3618
+ return scheme;
3611
3619
  }
3612
3620
  function renderThemeColor(value, options) {
3613
3621
  const {
@@ -4029,19 +4037,26 @@ const cache = /* @__PURE__ */ new Map();
4029
4037
  function getScopedTheme(themeProp, scheme, tone) {
4030
4038
  const cachedTheme = _getCachedTheme(themeProp, scheme, tone);
4031
4039
  if (cachedTheme) return cachedTheme;
4032
- const v0 = is_v2(themeProp) ? v2_v0(themeProp) : themeProp, v2 = is_v2(themeProp) ? themeProp : v0_v2(themeProp), colorScheme_v0 = v0.color[scheme] || v0.color.light, color_v0 = colorScheme_v0[tone] || colorScheme_v0.default, layer_v0 = v0.layer || defaultThemeConfig.layer, colorScheme_v2 = v2.color[scheme] || v2.color.light, color_v2 = colorScheme_v2[tone] || colorScheme_v2.default, color_v2_9 = themeColor_v0_v2_9(color_v2), layer_v2 = v2.layer || defaultThemeConfig.layer, theme = {
4033
- sanity: {
4034
- ...v0,
4035
- color: color_v0,
4036
- layer: layer_v0,
4037
- v2: {
4038
- ...v2,
4039
- _resolved: !0,
4040
- color: color_v2_9,
4041
- layer: layer_v2
4042
- }
4040
+ const v0 = is_v2(themeProp) ? v2_v0(themeProp) : themeProp, v2 = is_v2(themeProp) ? themeProp : v0_v2(themeProp), layer_v0 = v0.layer || defaultThemeConfig.layer, colorScheme_v2 = v2.color[scheme] || v2.color.light, color_v2 = colorScheme_v2[tone] || colorScheme_v2.default, color_v2_9 = themeColor_v0_v2_9(color_v2), layer_v2 = v2.layer || defaultThemeConfig.layer, {
4041
+ color: _v0Color,
4042
+ ...v0Rest
4043
+ } = v0, sanity = {
4044
+ ...v0Rest,
4045
+ layer: layer_v0,
4046
+ v2: {
4047
+ ...v2,
4048
+ _resolved: !0,
4049
+ color: color_v2_9,
4050
+ layer: layer_v2
4043
4051
  }
4044
4052
  };
4053
+ defineLazyProperty(sanity, "color", () => {
4054
+ const colorScheme_v0 = v0.color[scheme] || v0.color.light;
4055
+ return colorScheme_v0[tone] || colorScheme_v0.default;
4056
+ });
4057
+ const theme = {
4058
+ sanity
4059
+ };
4045
4060
  return _setCachedTheme(themeProp, scheme, tone, theme), theme;
4046
4061
  }
4047
4062
  function _getCachedTheme(rootTheme, scheme, tone) {