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