@tamagui/core 1.0.1-beta.136 → 1.0.1-beta.139

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.
Files changed (152) hide show
  1. package/dist/cjs/addTheme.js +74 -0
  2. package/dist/cjs/addTheme.js.map +7 -0
  3. package/dist/cjs/contexts/TextAncestorContext.js +44 -0
  4. package/dist/cjs/contexts/TextAncestorContext.js.map +7 -0
  5. package/dist/cjs/contexts/ThemeContext.js +30 -0
  6. package/dist/cjs/contexts/ThemeContext.js.map +7 -0
  7. package/dist/cjs/createComponent.js +10 -17
  8. package/dist/cjs/createComponent.js.map +2 -2
  9. package/dist/cjs/createTamagui.js +18 -118
  10. package/dist/cjs/createTamagui.js.map +2 -2
  11. package/dist/cjs/createTheme.js +2 -5
  12. package/dist/cjs/createTheme.js.map +2 -2
  13. package/dist/cjs/ensureThemeVariable.js +152 -0
  14. package/dist/cjs/ensureThemeVariable.js.map +7 -0
  15. package/dist/cjs/helpers/ThemeManager.js +209 -0
  16. package/dist/cjs/helpers/ThemeManager.js.map +7 -0
  17. package/dist/cjs/helpers/assignNativePropsToWeb.js +1 -0
  18. package/dist/cjs/helpers/assignNativePropsToWeb.js.map +2 -2
  19. package/dist/cjs/helpers/createPropMapper.js +2 -3
  20. package/dist/cjs/helpers/createPropMapper.js.map +2 -2
  21. package/dist/cjs/helpers/createTamaguiProvider.js +3 -1
  22. package/dist/cjs/helpers/createTamaguiProvider.js.map +2 -2
  23. package/dist/cjs/helpers/ensureThemeVariable.js +152 -0
  24. package/dist/cjs/helpers/ensureThemeVariable.js.map +7 -0
  25. package/dist/cjs/helpers/getSplitStyles.js +11 -2
  26. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  27. package/dist/cjs/helpers/getThemeCSSRules.js +98 -0
  28. package/dist/cjs/helpers/getThemeCSSRules.js.map +7 -0
  29. package/dist/cjs/helpers/getThemeCSSRules.native.js +31 -0
  30. package/dist/cjs/helpers/getThemeCSSRules.native.js.map +7 -0
  31. package/dist/cjs/helpers/getVariantExtras.js +6 -6
  32. package/dist/cjs/helpers/getVariantExtras.js.map +2 -2
  33. package/dist/cjs/helpers/insertStyleRule.js +6 -1
  34. package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
  35. package/dist/cjs/helpers/mergeProps.js +18 -14
  36. package/dist/cjs/helpers/mergeProps.js.map +2 -2
  37. package/dist/cjs/helpers/themes.js +79 -0
  38. package/dist/cjs/helpers/themes.js.map +7 -0
  39. package/dist/cjs/hooks/useId.js +2 -32
  40. package/dist/cjs/hooks/useId.js.map +2 -2
  41. package/dist/cjs/hooks/useMedia.js +75 -92
  42. package/dist/cjs/hooks/useMedia.js.map +2 -2
  43. package/dist/cjs/hooks/useSafeRef.js +60 -0
  44. package/dist/cjs/hooks/useSafeRef.js.map +7 -0
  45. package/dist/cjs/hooks/useTheme.js +20 -11
  46. package/dist/cjs/hooks/useTheme.js.map +2 -2
  47. package/dist/cjs/index.js +23 -4
  48. package/dist/cjs/index.js.map +2 -2
  49. package/dist/cjs/loadTheme.js +64 -0
  50. package/dist/cjs/loadTheme.js.map +7 -0
  51. package/dist/cjs/types.js.map +1 -1
  52. package/dist/cjs/updateTheme.js +44 -0
  53. package/dist/cjs/updateTheme.js.map +7 -0
  54. package/dist/cjs/vendor/Pressability.js +32 -0
  55. package/dist/cjs/vendor/Pressability.js.map +7 -0
  56. package/dist/cjs/vendor/Pressability.native.js +32 -0
  57. package/dist/cjs/vendor/Pressability.native.js.map +7 -0
  58. package/dist/cjs/views/Slot.js +2 -2
  59. package/dist/cjs/views/Slot.js.map +2 -2
  60. package/dist/cjs/views/Theme.js +1 -1
  61. package/dist/cjs/views/Theme.js.map +2 -2
  62. package/dist/cjs/views/ThemeProvider.js +1 -1
  63. package/dist/cjs/views/ThemeProvider.js.map +1 -1
  64. package/dist/cjs/views/ThemeReset.js +1 -1
  65. package/dist/cjs/views/ThemeReset.js.map +1 -1
  66. package/dist/esm/addTheme.js +50 -0
  67. package/dist/esm/addTheme.js.map +7 -0
  68. package/dist/esm/contexts/TextAncestorContext.js +15 -0
  69. package/dist/esm/contexts/TextAncestorContext.js.map +7 -0
  70. package/dist/esm/contexts/ThemeContext.js +6 -0
  71. package/dist/esm/contexts/ThemeContext.js.map +7 -0
  72. package/dist/esm/createComponent.js +10 -17
  73. package/dist/esm/createComponent.js.map +2 -2
  74. package/dist/esm/createTamagui.js +17 -117
  75. package/dist/esm/createTamagui.js.map +2 -2
  76. package/dist/esm/createTheme.js +1 -3
  77. package/dist/esm/createTheme.js.map +2 -2
  78. package/dist/esm/ensureThemeVariable.js +125 -0
  79. package/dist/esm/ensureThemeVariable.js.map +7 -0
  80. package/dist/esm/helpers/ThemeManager.js +183 -0
  81. package/dist/esm/helpers/ThemeManager.js.map +7 -0
  82. package/dist/esm/helpers/assignNativePropsToWeb.js +1 -0
  83. package/dist/esm/helpers/assignNativePropsToWeb.js.map +2 -2
  84. package/dist/esm/helpers/createPropMapper.js +2 -3
  85. package/dist/esm/helpers/createPropMapper.js.map +2 -2
  86. package/dist/esm/helpers/createTamaguiProvider.js +3 -1
  87. package/dist/esm/helpers/createTamaguiProvider.js.map +2 -2
  88. package/dist/esm/helpers/ensureThemeVariable.js +125 -0
  89. package/dist/esm/helpers/ensureThemeVariable.js.map +7 -0
  90. package/dist/esm/helpers/getSplitStyles.js +11 -2
  91. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  92. package/dist/esm/helpers/getThemeCSSRules.js +74 -0
  93. package/dist/esm/helpers/getThemeCSSRules.js.map +7 -0
  94. package/dist/esm/helpers/getThemeCSSRules.native.js +7 -0
  95. package/dist/esm/helpers/getThemeCSSRules.native.js.map +7 -0
  96. package/dist/esm/helpers/getVariantExtras.js +6 -6
  97. package/dist/esm/helpers/getVariantExtras.js.map +2 -2
  98. package/dist/esm/helpers/insertStyleRule.js +6 -1
  99. package/dist/esm/helpers/insertStyleRule.js.map +2 -2
  100. package/dist/esm/helpers/mergeProps.js +18 -14
  101. package/dist/esm/helpers/mergeProps.js.map +2 -2
  102. package/dist/esm/helpers/themes.js +54 -0
  103. package/dist/esm/helpers/themes.js.map +7 -0
  104. package/dist/esm/hooks/useId.js +1 -28
  105. package/dist/esm/hooks/useId.js.map +2 -2
  106. package/dist/esm/hooks/useMedia.js +74 -92
  107. package/dist/esm/hooks/useMedia.js.map +2 -2
  108. package/dist/esm/hooks/useSafeRef.js +36 -0
  109. package/dist/esm/hooks/useSafeRef.js.map +7 -0
  110. package/dist/esm/hooks/useTheme.js +23 -11
  111. package/dist/esm/hooks/useTheme.js.map +2 -2
  112. package/dist/esm/index.js +23 -3
  113. package/dist/esm/index.js.map +2 -2
  114. package/dist/esm/loadTheme.js +40 -0
  115. package/dist/esm/loadTheme.js.map +7 -0
  116. package/dist/esm/updateTheme.js +20 -0
  117. package/dist/esm/updateTheme.js.map +7 -0
  118. package/dist/esm/vendor/Pressability.js +7 -0
  119. package/dist/esm/vendor/Pressability.js.map +7 -0
  120. package/dist/esm/vendor/Pressability.native.js +7 -0
  121. package/dist/esm/vendor/Pressability.native.js.map +7 -0
  122. package/dist/esm/views/Slot.js +2 -2
  123. package/dist/esm/views/Slot.js.map +2 -2
  124. package/dist/esm/views/Theme.js +1 -1
  125. package/dist/esm/views/Theme.js.map +1 -1
  126. package/dist/esm/views/ThemeProvider.js +1 -1
  127. package/dist/esm/views/ThemeProvider.js.map +1 -1
  128. package/dist/esm/views/ThemeReset.js +1 -1
  129. package/dist/esm/views/ThemeReset.js.map +1 -1
  130. package/package.json +8 -8
  131. package/types/addTheme.d.ts +11 -0
  132. package/types/{views → contexts}/TextAncestorContext.d.ts +0 -0
  133. package/types/{ThemeContext.d.ts → contexts/ThemeContext.d.ts} +1 -1
  134. package/types/createTheme.d.ts +0 -1
  135. package/types/{ThemeManager.d.ts → helpers/ThemeManager.d.ts} +5 -5
  136. package/types/helpers/getSplitStyles.d.ts +1 -0
  137. package/types/helpers/getThemeCSSRules.d.ts +8 -0
  138. package/types/helpers/getThemeCSSRules.native.d.ts +2 -0
  139. package/types/helpers/mergeProps.d.ts +3 -1
  140. package/types/helpers/themes.d.ts +4 -0
  141. package/types/hooks/useId.d.ts +1 -8
  142. package/types/hooks/useMedia.d.ts +2 -1
  143. package/types/hooks/useSafeRef.d.ts +4 -0
  144. package/types/hooks/useTheme.d.ts +2 -1
  145. package/types/index.d.ts +5 -2
  146. package/types/types.d.ts +2 -2
  147. package/types/updateTheme.d.ts +9 -0
  148. package/types/{Pressability.d.ts → vendor/Pressability.d.ts} +0 -0
  149. package/types/{Pressability.native.d.ts → vendor/Pressability.native.d.ts} +0 -0
  150. package/types/views/Theme.d.ts +1 -1
  151. package/types/defaultComponentState.d.ts +0 -1
  152. package/types/helpers/nativeGestureHandler.native.d.ts +0 -2
@@ -0,0 +1,74 @@
1
+ import { THEME_CLASSNAME_PREFIX } from "../constants/constants";
2
+ import { tokensValueToVariable } from "./registerCSSVariable";
3
+ function getThemeCSSRules({
4
+ config,
5
+ themeName,
6
+ theme,
7
+ names
8
+ }) {
9
+ const cssRuleSets = [];
10
+ const hasDarkLight = "light" in config.themes && "dark" in config.themes;
11
+ const CNP = `.${THEME_CLASSNAME_PREFIX}`;
12
+ let vars = "";
13
+ for (const themeKey in theme) {
14
+ const variable = theme[themeKey];
15
+ let value = null;
16
+ if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {
17
+ value = variable.val;
18
+ } else {
19
+ value = tokensValueToVariable.get(variable.val).variable;
20
+ }
21
+ vars += `--${themeKey}:${value};`;
22
+ }
23
+ const isDarkOrLightBase = themeName === "dark" || themeName === "light";
24
+ const selectors = names.map((name) => {
25
+ return `${CNP}${name}`;
26
+ });
27
+ if (hasDarkLight) {
28
+ for (const subName of names) {
29
+ const isDark = isDarkOrLightBase || subName.startsWith("dark_");
30
+ const max = config.maxDarkLightNesting ?? 3;
31
+ if (!isDark && !subName.startsWith("light_")) {
32
+ selectors.push(`:root:root ${CNP}${subName}`);
33
+ continue;
34
+ }
35
+ const childSelector = `${CNP}${subName.replace(isDark ? "dark_" : "light_", "")}`;
36
+ const order = isDark ? ["dark", "light"] : ["light", "dark"];
37
+ if (isDarkOrLightBase) {
38
+ order.reverse();
39
+ }
40
+ const [stronger, weaker] = order;
41
+ const numSelectors = Math.round(max * 1.5);
42
+ for (let pi = 0; pi < numSelectors; pi++) {
43
+ const isOdd = pi % 2 === 1;
44
+ if (isOdd && pi < 3)
45
+ continue;
46
+ const parents = new Array(pi + 1).fill(void 0).map((_, psi) => {
47
+ return `${CNP}${psi % 2 === 0 ? stronger : weaker}`;
48
+ });
49
+ let parentSelectors = parents.length > 1 ? parents.slice(1) : parents;
50
+ if (isOdd) {
51
+ const [_first, second, ...rest] = parentSelectors;
52
+ parentSelectors = [second, ...rest, second];
53
+ }
54
+ const lastParentSelector = parentSelectors[parentSelectors.length - 1];
55
+ selectors.push(`${parentSelectors.join(" ")} ${childSelector === lastParentSelector ? "" : childSelector}`);
56
+ }
57
+ }
58
+ }
59
+ const rootSep = config.themeClassNameOnRoot ? "" : " ";
60
+ const css = `${selectors.map((x) => `:root${rootSep}${x}`).join(", ")} {${vars}}`;
61
+ cssRuleSets.push(css);
62
+ if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {
63
+ const isDark = themeName.startsWith("dark");
64
+ cssRuleSets.push(`@media(prefers-color-scheme: ${isDark ? "dark" : "light"}) {
65
+ body { background:${theme.background}; color: ${theme.color} }
66
+ :root {${vars} }
67
+ }`);
68
+ }
69
+ return cssRuleSets;
70
+ }
71
+ export {
72
+ getThemeCSSRules
73
+ };
74
+ //# sourceMappingURL=getThemeCSSRules.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/getThemeCSSRules.ts"],
4
+ "sourcesContent": ["import { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { Variable } from '../createVariable'\nimport { CreateTamaguiProps, ThemeObject } from '../types'\nimport { tokensValueToVariable } from './registerCSSVariable'\n\nexport function getThemeCSSRules({\n config,\n themeName,\n theme,\n names,\n}: {\n config: CreateTamaguiProps\n themeName: string\n theme: ThemeObject\n names: string[]\n}) {\n const cssRuleSets: string[] = []\n\n // special case for SSR\n const hasDarkLight = 'light' in config.themes && 'dark' in config.themes\n const CNP = `.${THEME_CLASSNAME_PREFIX}`\n let vars = ''\n\n // themeToVariableToValueMap.set(theme, {})\n // const varToValMap = themeToVariableToValueMap.get(theme)\n for (const themeKey in theme) {\n const variable = theme[themeKey] as Variable\n let value: any = null\n // if (varToValMap) {\n // varToValMap[variable.variable] = variable.val\n // }\n if (variable.isFloating || !tokensValueToVariable.has(variable.val)) {\n value = variable.val\n } else {\n value = tokensValueToVariable.get(variable.val)!.variable\n }\n vars += `--${themeKey}:${value};`\n }\n\n const isDarkOrLightBase = themeName === 'dark' || themeName === 'light'\n const selectors = names.map((name) => {\n return `${CNP}${name}`\n })\n\n // since we dont specify dark/light in classnames we have to do an awkward specificity war\n // use config.maxDarkLightNesting to determine how deep you can nest until it breaks\n if (hasDarkLight) {\n for (const subName of names) {\n const isDark = isDarkOrLightBase || subName.startsWith('dark_')\n const max = config.maxDarkLightNesting ?? 3\n\n if (!isDark && !subName.startsWith('light_')) {\n // neither light nor dark subtheme, just generate one selector with :root:root which\n // will override all :root light/dark selectors generated below\n selectors.push(`:root:root ${CNP}${subName}`)\n continue\n }\n\n const childSelector = `${CNP}${subName.replace(isDark ? 'dark_' : 'light_', '')}`\n const order = isDark ? ['dark', 'light'] : ['light', 'dark']\n if (isDarkOrLightBase) {\n order.reverse()\n }\n const [stronger, weaker] = order\n const numSelectors = Math.round(max * 1.5)\n\n for (let pi = 0; pi < numSelectors; pi++) {\n const isOdd = pi % 2 === 1\n if (isOdd && pi < 3) continue\n const parents = new Array(pi + 1).fill(undefined).map((_, psi) => {\n return `${CNP}${psi % 2 === 0 ? stronger : weaker}`\n })\n let parentSelectors = parents.length > 1 ? parents.slice(1) : parents\n if (isOdd) {\n const [_first, second, ...rest] = parentSelectors\n parentSelectors = [second, ...rest, second]\n }\n // avoid .t_light .t_light at the end (make sure child is unique from last parent)\n const lastParentSelector = parentSelectors[parentSelectors.length - 1]\n selectors.push(\n `${parentSelectors.join(' ')} ${\n childSelector === lastParentSelector ? '' : childSelector\n }`\n )\n }\n }\n }\n\n const rootSep = config.themeClassNameOnRoot ? '' : ' '\n const css = `${selectors.map((x) => `:root${rootSep}${x}`).join(', ')} {${vars}}`\n cssRuleSets.push(css)\n\n if (config.shouldAddPrefersColorThemes && isDarkOrLightBase) {\n // add media prefers for dark/light base\n const isDark = themeName.startsWith('dark')\n cssRuleSets.push(\n `@media(prefers-color-scheme: ${isDark ? 'dark' : 'light'}) {\nbody { background:${theme.background}; color: ${theme.color} }\n:root {${vars} } \n}`\n )\n }\n\n return cssRuleSets\n}\n"],
5
+ "mappings": "AAAA;AAGA;AAEO,0BAA0B;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAMC;AACD,QAAM,cAAwB,CAAC;AAG/B,QAAM,eAAe,WAAW,OAAO,UAAU,UAAU,OAAO;AAClE,QAAM,MAAM,IAAI;AAChB,MAAI,OAAO;AAIX,aAAW,YAAY,OAAO;AAC5B,UAAM,WAAW,MAAM;AACvB,QAAI,QAAa;AAIjB,QAAI,SAAS,cAAc,CAAC,sBAAsB,IAAI,SAAS,GAAG,GAAG;AACnE,cAAQ,SAAS;AAAA,IACnB,OAAO;AACL,cAAQ,sBAAsB,IAAI,SAAS,GAAG,EAAG;AAAA,IACnD;AACA,YAAQ,KAAK,YAAY;AAAA,EAC3B;AAEA,QAAM,oBAAoB,cAAc,UAAU,cAAc;AAChE,QAAM,YAAY,MAAM,IAAI,CAAC,SAAS;AACpC,WAAO,GAAG,MAAM;AAAA,EAClB,CAAC;AAID,MAAI,cAAc;AAChB,eAAW,WAAW,OAAO;AAC3B,YAAM,SAAS,qBAAqB,QAAQ,WAAW,OAAO;AAC9D,YAAM,MAAM,OAAO,uBAAuB;AAE1C,UAAI,CAA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;AAAA,oBACpC,MAAM,sBAAsB,MAAM;AAAA,SAC7C;AAAA,EAEL;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ function getThemeCSSRules() {
2
+ return [];
3
+ }
4
+ export {
5
+ getThemeCSSRules
6
+ };
7
+ //# sourceMappingURL=getThemeCSSRules.native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/getThemeCSSRules.native.ts"],
4
+ "sourcesContent": ["export function getThemeCSSRules() {\n return []\n}\n"],
5
+ "mappings": "AAAO,4BAA4B;AACjC,SAAO,CAAC;AACV;",
6
+ "names": []
7
+ }
@@ -12,20 +12,20 @@ function getVariantExtras(props, languageContext, theme, defaultProps, avoidDefa
12
12
  theme,
13
13
  props: avoidDefaultProps ? props : new Proxy(props, {
14
14
  get(target, key) {
15
- if (Reflect.has(target, key)) {
16
- return Reflect.get(target, key);
17
- }
18
15
  const shorthand = conf.inverseShorthands[key];
19
16
  if (shorthand && Reflect.has(target, shorthand)) {
20
17
  return Reflect.get(target, shorthand);
21
18
  }
19
+ if (Reflect.has(target, key)) {
20
+ return Reflect.get(target, key);
21
+ }
22
22
  if (defaultProps) {
23
- if (Reflect.has(defaultProps, key)) {
24
- return Reflect.get(defaultProps, key);
25
- }
26
23
  if (shorthand && Reflect.has(defaultProps, shorthand)) {
27
24
  return Reflect.get(defaultProps, shorthand);
28
25
  }
26
+ if (Reflect.has(defaultProps, key)) {
27
+ return Reflect.get(defaultProps, key);
28
+ }
29
29
  }
30
30
  }
31
31
  })
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/getVariantExtras.tsx"],
4
- "sourcesContent": ["import { getConfig } from '../conf'\nimport { GenericFonts } from '../types'\nimport { LanguageContextType } from '../views/FontLanguage.types'\n\nconst extrasCache = new WeakMap()\n\nexport function getVariantExtras(\n props: any,\n languageContext?: LanguageContextType,\n theme?: any,\n defaultProps?: any,\n avoidDefaultProps = false\n) {\n const conf = getConfig()\n\n if (extrasCache.has(props)) {\n return extrasCache.get(props)\n }\n\n const fonts = languageContext\n ? getFontsForLanguage(conf.fontsParsed, languageContext)\n : conf.fontsParsed\n\n const next = {\n fonts,\n tokens: conf.tokensParsed,\n theme,\n // TODO do this in splitstlye\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n props: avoidDefaultProps\n ? props\n : new Proxy(props, {\n // handles shorthands\n get(target, key) {\n if (Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n const shorthand = conf.inverseShorthands[key as any]\n if (shorthand && Reflect.has(target, shorthand)) {\n return Reflect.get(target, shorthand)\n }\n // these props may be extracted into classNames, but we still want to access them\n // at runtime, so we proxy back to defaultProps but don't pass them\n if (defaultProps) {\n if (Reflect.has(defaultProps, key)) {\n return Reflect.get(defaultProps, key)\n }\n if (shorthand && Reflect.has(defaultProps, shorthand)) {\n return Reflect.get(defaultProps, shorthand)\n }\n }\n },\n }),\n }\n\n extrasCache.set(props, next)\n\n return next\n}\n\nconst fontLanguageCache = new WeakMap()\n\nexport function getFontsForLanguage(fonts: GenericFonts, language: LanguageContextType) {\n if (fontLanguageCache.has(language)) {\n return fontLanguageCache.get(language)\n }\n const next = {\n ...fonts,\n ...Object.fromEntries(\n Object.entries(language).map(([name, lang]) => {\n if (lang === 'default') {\n return []\n }\n const langKey = `$${name}_${lang}`\n return [`$${name}`, fonts[langKey]]\n })\n ),\n }\n fontLanguageCache.set(language, next)\n return next\n}\n"],
5
- "mappings": "AAAA;AAIA,MAAM,cAAc,oBAAI,QAAQ;AAEzB,0BACL,OACA,iBACA,OACA,cACA,oBAAoB,OACpB;AACA,QAAM,OAAO,UAAU;AAEvB,MAAI,YAAY,IAAI,KAAK,GAAG;AAC1B,WAAO,YAAY,IAAI,KAAK;AAAA,EAC9B;AAEA,QAAM,QAAQ,kBACV,oBAAoB,KAAK,aAAa,eAAe,IACrD,KAAK;AAET,QA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ontLanguage.types'\n\nconst extrasCache = new WeakMap()\n\nexport function getVariantExtras(\n props: any,\n languageContext?: LanguageContextType,\n theme?: any,\n defaultProps?: any,\n avoidDefaultProps = false\n) {\n const conf = getConfig()\n\n if (extrasCache.has(props)) {\n return extrasCache.get(props)\n }\n\n const fonts = languageContext\n ? getFontsForLanguage(conf.fontsParsed, languageContext)\n : conf.fontsParsed\n\n const next = {\n fonts,\n tokens: conf.tokensParsed,\n theme,\n // TODO do this in splitstlye\n // we avoid passing in default props for media queries because that would confuse things like SizableText.size:\n props: avoidDefaultProps\n ? props\n : new Proxy(props, {\n // handles shorthands\n get(target, key) {\n const shorthand = conf.inverseShorthands[key as any]\n // shorthands before longhand because a styled() with longhand combined with inline shorthand\n // shorthand will always be the overriding key\n if (shorthand && Reflect.has(target, shorthand)) {\n return Reflect.get(target, shorthand)\n }\n if (Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n // these props may be extracted into classNames, but we still want to access them\n // at runtime, so we proxy back to defaultProps but don't pass them\n if (defaultProps) {\n if (shorthand && Reflect.has(defaultProps, shorthand)) {\n return Reflect.get(defaultProps, shorthand)\n }\n if (Reflect.has(defaultProps, key)) {\n return Reflect.get(defaultProps, key)\n }\n }\n },\n }),\n }\n\n extrasCache.set(props, next)\n\n return next\n}\n\nconst fontLanguageCache = new WeakMap()\n\nexport function getFontsForLanguage(fonts: GenericFonts, language: LanguageContextType) {\n if (fontLanguageCache.has(language)) {\n return fontLanguageCache.get(language)\n }\n const next = {\n ...fonts,\n ...Object.fromEntries(\n Object.entries(language).map(([name, lang]) => {\n if (lang === 'default') {\n return []\n }\n const langKey = `$${name}_${lang}`\n return [`$${name}`, fonts[langKey]]\n })\n ),\n }\n fontLanguageCache.set(language, next)\n return next\n}\n"],
5
+ "mappings": "AAAA;AAIA,MAAM,cAAc,oBAAI,QAAQ;AAEzB,0BACL,OACA,iBACA,OACA,cACA,oBAAoB,OACpB;AACA,QAAM,OAAO,UAAU;AAEvB,MAAI,YAAY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AAA,EACF;AACA,oBAAkB,IAAI,UAAU,IAAI;AACpC,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -44,7 +44,12 @@ function updateInserted() {
44
44
  const sheet2 = sheets[i];
45
45
  if (!sheet2)
46
46
  continue;
47
- const rules = sheet2.cssRules;
47
+ let rules;
48
+ try {
49
+ rules = sheet2.cssRules;
50
+ } catch {
51
+ continue;
52
+ }
48
53
  const len = rules.length;
49
54
  const lastScanned = scannedNum.get(sheet2) ?? 0;
50
55
  if (lastScanned === len) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/insertStyleRule.tsx"],
4
- "sourcesContent": ["// this needs to check if its inserted already? 99% of the time it is\n// this should avoid re-inserts, but need to test the perf trade-offs\n// i tested with the site itself and the initial insert was trivial\n\nimport { StyleObject } from '@tamagui/helpers'\n\nconst allSelectors = {}\nconst allRules = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n // sometimes getting empty style rules from webpack... :/ only in dev\n if (css.indexOf('{ }')) {\n console.log('wah wah')\n return false\n }\n console.groupCollapsed(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n console.log('rule:', rule)\n console.trace()\n console.groupEnd()\n } else {\n console.warn(`Missing transform`, identifier, css, rule)\n }\n return false\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n if (!insertedTransforms[identifier]) {\n insertedTransforms[identifier] = value\n return true\n }\n return false\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\nconst scannedNum = new WeakMap<CSSStyleSheet, number>()\n\nexport function updateInserted() {\n if (process.env.NODE_ENV === 'test') return\n if (!isClient) return\n const sheets = document.styleSheets\n if (!sheets) return\n for (let i = 0; i < sheets.length; i++) {\n const sheet = sheets[i]\n if (!sheet) continue\n const rules = sheet.cssRules\n const len = rules.length\n const lastScanned = scannedNum.get(sheet) ?? 0\n if (lastScanned === len) {\n continue\n }\n for (let i = lastScanned; i < len; i++) {\n const rule = rules[i]\n const response = getTamaguiSelector(rule)\n if (!response) {\n continue\n }\n const [identifier, cssRule] = response\n if (!allSelectors[identifier]) {\n const isTransform = identifier.startsWith('_transform')\n const shouldInsert = isTransform ? addTransform(identifier, cssRule.cssText, cssRule) : true\n if (shouldInsert) {\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? cssRule.cssText : true\n }\n }\n }\n scannedNum.set(sheet, i)\n }\n}\n\nfunction getTamaguiSelector(rule: CSSRule | null): readonly [string, CSSStyleRule] | null {\n if (rule instanceof CSSStyleRule) {\n if (rule.selectorText.startsWith('._')) {\n return [rule.selectorText.slice(1), rule]\n }\n if (rule.selectorText.startsWith(':root') && rule.selectorText.includes('._')) {\n return [getIdentifierFromTamaguiSelector(rule.selectorText), rule]\n }\n } else if (rule instanceof CSSMediaRule) {\n // tamagui only ever inserts 1 rule per media\n if (rule.cssRules.length > 1) return null\n return getTamaguiSelector(rule.cssRules[0])\n }\n return null\n}\n\nconst getIdentifierFromTamaguiSelector = (selector: string) =>\n selector\n .replace(/(:root)+\\s+/, '')\n .replace(/:[a-z]+$/, '')\n .slice(1)\n\n// move this to probably inside createTamagui\nupdateInserted()\n\nconst sheet = isClient ? document.head.appendChild(document.createElement('style')).sheet : null\n\nexport function updateRules(identifier: string, rules: string[]) {\n if (allRules[identifier]) return false\n allRules[identifier] = rules\n if (identifier.startsWith('_transform')) {\n return addTransform(identifier, rules[0])\n }\n return true\n}\n\n// [property, identifier, rules]\nexport type PartialStyleObject = Pick<StyleObject, 'identifier' | 'property' | 'rules'>\nexport type RulesToInsert = PartialStyleObject[]\n\nexport function insertStyleRules(rulesToInsert: RulesToInsert) {\n // // pointerevents can have more than one, others could to needs some refactor\n for (const { identifier, rules } of rulesToInsert) {\n if (allSelectors[identifier] || !sheet) return\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? rules : true\n updateRules(identifier, rules)\n for (const rule of rules) {\n sheet.insertRule(rule, sheet.cssRules.length)\n }\n }\n}\n\nexport function shouldInsertStyleRules(styleObject: PartialStyleObject) {\n return !allSelectors[styleObject.identifier]\n}\n"],
5
- "mappings": "AAMA,MAAM,eAAe,CAAC;AACtB,MAAM,WAAW,CAAC;AACX,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,MAAM;AAC9B,MAAM,cAAc,MAAM,OAAO,OAAO,QAAQ;AAChD,MAAM,mBAAmB,MAAM;AAGtC,sBAAsB,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,UAAI,IAAI,QAAQ,KAAK,GAAG;AACtB,gBAAQ,IAAI,SAAS;AACrB,eAAO;AAAA,MACT;AACA,cAAQ,eAAe,0DAAqD,YAAY;AACxF,cAAQ,IAAI,SAAS,IAAI;AACzB,cAAQ,MAAM;AACd,cAAQ,SAAS;AAAA,IACnB,OAAO;AACL,cAAQ,KAAK,qBAAqB,YAAY,KAAK,IAAI;AAAA,IACzD;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,OAAO,IAAI,QAAQ,GAAG;AAC5B,QAAM,QAAQ,IAAI,MAAM,QAAQ,IAAI;AACpC,MAAI,CAAC,mBAAmB,aAAa;AACnC,uBAAmB,cAAc;AACjC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,MAAM,WAAW,OAAO,aAAa;AAQrC,MAAM,aAAa,oBAAI,QAA+B;AAE/C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SAAO;AACT;AAEA,MAAM,mCAAmC,CAAC,aACxC,SACG,QAAQ,eAAe,EAAE,EACzB,QAAQ,YAAY,EAAE,EACtB,MAAM,CAAC;AAGZ,eAAe;AAEf,MAAM,QAAQ,WAAW,SAAS,KAAK,YAAY,SAAS,cAAc,OAAO,CAAC,EAAE,QAAQ;AAErF,qBAAqB,YAAoB,OAAiB;AAC/D,MAAI,SAAS;AAAa,WAAO;AACjC,WAAS,cAAc;AACvB,MAAI,WAAW,WAAW,YAAY,GAAG;AACvC,WAAO,aAAa,YAAY,MAAM,EAAE;AAAA,EAC1C;AACA,SAAO;AACT;AAMO,0BAA0B,eAA8B;AAE7D,aAAW,EAAE,YAAY,WAAW,eAAe;AACjD,QAAI,aAAa,eAAe,CAAC;AAAO;AACxC,iBAAa,cAAc,QAAQ,IAAI,aAAa,gBAAgB,QAAQ;AAC5E,gBAAY,YAAY,KAAK;AAC7B,eAAW,QAAQ,OAAO;AACxB,YAAM,WAAW,MAAM,MAAM,SAAS,MAAM;AAAA,IAC9C;AAAA,EACF;AACF;AAEO,gCAAgC,aAAiC;AACtE,SAAO,CAAC,aAAa,YAAY;AACnC;",
4
+ "sourcesContent": ["// this needs to check if its inserted already? 99% of the time it is\n// this should avoid re-inserts, but need to test the perf trade-offs\n// i tested with the site itself and the initial insert was trivial\n\nimport { StyleObject } from '@tamagui/helpers'\n\nconst allSelectors = {}\nconst allRules = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n // sometimes getting empty style rules from webpack... :/ only in dev\n if (css.indexOf('{ }')) {\n console.log('wah wah')\n return false\n }\n console.groupCollapsed(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n console.log('rule:', rule)\n console.trace()\n console.groupEnd()\n } else {\n console.warn(`Missing transform`, identifier, css, rule)\n }\n return false\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n if (!insertedTransforms[identifier]) {\n insertedTransforms[identifier] = value\n return true\n }\n return false\n}\n\nconst isClient = typeof document !== 'undefined'\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\nconst scannedNum = new WeakMap<CSSStyleSheet, number>()\n\nexport function updateInserted() {\n if (process.env.NODE_ENV === 'test') return\n if (!isClient) return\n const sheets = document.styleSheets\n if (!sheets) return\n for (let i = 0; i < sheets.length; i++) {\n const sheet = sheets[i]\n if (!sheet) continue\n\n // avoid errors on cross origin sheets\n // https://stackoverflow.com/questions/49993633/uncaught-domexception-failed-to-read-the-cssrules-property\n let rules: CSSRuleList\n try {\n rules = sheet.cssRules\n } catch {\n continue\n }\n\n const len = rules.length\n const lastScanned = scannedNum.get(sheet) ?? 0\n if (lastScanned === len) {\n continue\n }\n for (let i = lastScanned; i < len; i++) {\n const rule = rules[i]\n const response = getTamaguiSelector(rule)\n if (!response) {\n continue\n }\n const [identifier, cssRule] = response\n if (!allSelectors[identifier]) {\n const isTransform = identifier.startsWith('_transform')\n const shouldInsert = isTransform ? addTransform(identifier, cssRule.cssText, cssRule) : true\n if (shouldInsert) {\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? cssRule.cssText : true\n }\n }\n }\n scannedNum.set(sheet, i)\n }\n}\n\nfunction getTamaguiSelector(rule: CSSRule | null): readonly [string, CSSStyleRule] | null {\n if (rule instanceof CSSStyleRule) {\n if (rule.selectorText.startsWith('._')) {\n return [rule.selectorText.slice(1), rule]\n }\n if (rule.selectorText.startsWith(':root') && rule.selectorText.includes('._')) {\n return [getIdentifierFromTamaguiSelector(rule.selectorText), rule]\n }\n } else if (rule instanceof CSSMediaRule) {\n // tamagui only ever inserts 1 rule per media\n if (rule.cssRules.length > 1) return null\n return getTamaguiSelector(rule.cssRules[0])\n }\n return null\n}\n\nconst getIdentifierFromTamaguiSelector = (selector: string) =>\n selector\n .replace(/(:root)+\\s+/, '')\n .replace(/:[a-z]+$/, '')\n .slice(1)\n\n// move this to probably inside createTamagui\nupdateInserted()\n\nconst sheet = isClient ? document.head.appendChild(document.createElement('style')).sheet : null\n\nexport function updateRules(identifier: string, rules: string[]) {\n if (allRules[identifier]) return false\n allRules[identifier] = rules\n if (identifier.startsWith('_transform')) {\n return addTransform(identifier, rules[0])\n }\n return true\n}\n\n// [property, identifier, rules]\nexport type PartialStyleObject = Pick<StyleObject, 'identifier' | 'property' | 'rules'>\nexport type RulesToInsert = PartialStyleObject[]\n\nexport function insertStyleRules(rulesToInsert: RulesToInsert) {\n // // pointerevents can have more than one, others could to needs some refactor\n for (const { identifier, rules } of rulesToInsert) {\n if (allSelectors[identifier] || !sheet) return\n allSelectors[identifier] = process.env.NODE_ENV === 'development' ? rules : true\n updateRules(identifier, rules)\n for (const rule of rules) {\n sheet.insertRule(rule, sheet.cssRules.length)\n }\n }\n}\n\nexport function shouldInsertStyleRules(styleObject: PartialStyleObject) {\n return !allSelectors[styleObject.identifier]\n}\n"],
5
+ "mappings": "AAMA,MAAM,eAAe,CAAC;AACtB,MAAM,WAAW,CAAC;AACX,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,MAAM;AAC9B,MAAM,cAAc,MAAM,OAAO,OAAO,QAAQ;AAChD,MAAM,mBAAmB,MAAM;AAGtC,sBAAsB,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,UAAI,IAAI,QAAQ,KAAK,GAAG;AACtB,gBAAQ,IAAI,SAAS;AACrB,eAAO;AAAA,MACT;AACA,cAAQ,eAAe,0DAAqD,YAAY;AACxF,cAAQ,IA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
- const mergeProps = (a, b, leaveOutClassNames = false) => {
2
- var _a, _b;
1
+ const mergeProps = (a, b, leaveOutClassNames = false, inverseShorthands) => {
3
2
  const out = {};
4
3
  const outCns = leaveOutClassNames ? {} : null;
5
4
  for (const key in a) {
6
- if (!(key in b)) {
7
- if (leaveOutClassNames && ((_a = a[key]) == null ? void 0 : _a[0]) === "_") {
8
- outCns[key] = a[key];
9
- } else {
10
- out[key] = a[key];
11
- }
12
- }
5
+ mergeProp(out, outCns, a, b, key, leaveOutClassNames, inverseShorthands);
13
6
  }
14
7
  for (const key in b) {
15
- if (leaveOutClassNames && ((_b = b[key]) == null ? void 0 : _b[0]) === "_") {
16
- outCns[key] = b[key];
17
- } else {
18
- out[key] = b[key];
19
- }
8
+ mergeProp(out, outCns, b, void 0, key, leaveOutClassNames, inverseShorthands);
20
9
  }
21
10
  return [out, outCns];
22
11
  };
12
+ function mergeProp(out, outCns, a, b, key, leaveOutClassNames, inverseShorthands) {
13
+ const val = a[key];
14
+ const shorthand = inverseShorthands ? inverseShorthands[key] : null;
15
+ if (b && (key in b || shorthand && shorthand in b)) {
16
+ return;
17
+ }
18
+ if (shorthand) {
19
+ key = shorthand;
20
+ }
21
+ if (leaveOutClassNames && (val == null ? void 0 : val[0]) === "_") {
22
+ outCns[key] = val;
23
+ } else {
24
+ out[key] = val;
25
+ }
26
+ }
23
27
  export {
24
28
  mergeProps
25
29
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/mergeProps.ts"],
4
- "sourcesContent": ["/**\n * Preserves prop ordering, so that the order most closely matches the last spread objects\n * Useful for having { ...defaultProps, ...props } that ensure props ordering is always kept\n *\n * Given:\n * mergeProps({ a: 1, b: 2 }, { b: 1, a: 2 })\n * The final key order will be:\n * b, a\n */\n\nexport const mergeProps = (a: Object, b: Object, leaveOutClassNames = false) => {\n const out: Record<string, string> = {}\n const outCns: Record<string, string> = leaveOutClassNames ? {} : (null as any)\n\n for (const key in a) {\n if (!(key in b)) {\n if (leaveOutClassNames && a[key]?.[0] === '_') {\n outCns[key] = a[key]\n } else {\n out[key] = a[key]\n }\n }\n }\n\n for (const key in b) {\n if (leaveOutClassNames && b[key]?.[0] === '_') {\n outCns[key] = b[key]\n } else {\n out[key] = b[key]\n }\n }\n\n return [out, outCns] as const\n}\n"],
5
- "mappings": "AAUO,MAAM,aAAa,CAAC,GAAW,GAAW,qBAAqB,UAAU;AAVhF;AAWE,QAAM,MAA8B,CAAC;AACrC,QAAM,SAAiC,qBAAqB,CAAC,IAAK;AAElE,aAAW,OAAO,GAAG;AACnB,QAAI,CAAE,QAAO,IAAI;AACf,UAAI,sBAAsB,SAAE,SAAF,mBAAS,QAAO,KAAK;AAC7C,eAAO,OAAO,EAAE;AAAA,MAClB,OAAO;AACL,YAAI,OAAO,EAAE;AAAA,MACf;AAAA,IACF;AAAA,EACF;AAEA,aAAW,OAAO,GAAG;AACnB,QAAI,sBAAsB,SAAE,SAAF,mBAAS,QAAO,KAAK;AAC7C,aAAO,OAAO,EAAE;AAAA,IAClB,OAAO;AACL,UAAI,OAAO,EAAE;AAAA,IACf;AAAA,EACF;AAEA,SAAO,CAAC,KAAK,MAAM;AACrB;",
4
+ "sourcesContent": ["/**\n * Preserves prop ordering, so that the order most closely matches the last spread objects\n * Useful for having { ...defaultProps, ...props } that ensure props ordering is always kept\n *\n * Given:\n * mergeProps({ a: 1, b: 2 }, { b: 1, a: 2 })\n * The final key order will be:\n * b, a\n *\n * Handles a couple special tamagui cases\n * - classNames can be extracted out separately\n * - shorthands can be expanded before merging\n */\n\ntype StringRecord = Record<string, string>\n\nexport const mergeProps = (\n a: Object,\n b: Object,\n leaveOutClassNames = false,\n inverseShorthands?: StringRecord\n) => {\n const out: StringRecord = {}\n const outCns: StringRecord = leaveOutClassNames ? {} : (null as any)\n for (const key in a) {\n mergeProp(out, outCns, a, b, key, leaveOutClassNames, inverseShorthands)\n }\n for (const key in b) {\n mergeProp(out, outCns, b, undefined, key, leaveOutClassNames, inverseShorthands)\n }\n return [out, outCns] as const\n}\n\nfunction mergeProp(\n out: StringRecord,\n outCns: StringRecord,\n a: Object,\n b: Object | undefined,\n key: string,\n leaveOutClassNames: boolean,\n inverseShorthands?: StringRecord\n) {\n const val = a[key]\n const shorthand = inverseShorthands ? inverseShorthands[key] : null\n if (b && (key in b || (shorthand && shorthand in b))) {\n return\n }\n if (shorthand) {\n key = shorthand\n }\n if (leaveOutClassNames && val?.[0] === '_') {\n outCns[key] = val\n } else {\n out[key] = val\n }\n}\n"],
5
+ "mappings": "AAgBO,MAAM,aAAa,CACxB,GACA,GACA,qBAAqB,OACrB,sBACG;AACH,QAAM,MAAoB,CAAC;AAC3B,QAAM,SAAuB,qBAAqB,CAAC,IAAK;AACxD,aAAW,OAAO,GAAG;AACnB,cAAU,KAAK,QAAQ,GAAG,GAAG,KAAK,oBAAoB,iBAAiB;AAAA,EACzE;AACA,aAAW,OAAO,GAAG;AACnB,cAAU,KAAK,QAAQ,GAAG,QAAW,KAAK,oBAAoB,iBAAiB;AAAA,EACjF;AACA,SAAO,CAAC,KAAK,MAAM;AACrB;AAEA,mBACE,KACA,QACA,GACA,GACA,KACA,oBACA,mBACA;AACA,QAAM,MAAM,EAAE;AACd,QAAM,YAAY,oBAAoB,kBAAkB,OAAO;AAC/D,MAAI,KAAM,QAAO,KAAM,aAAa,aAAa,IAAK;AACpD;AAAA,EACF;AACA,MAAI,WAAW;AACb,UAAM;AAAA,EACR;AACA,MAAI,sBAAsB,4BAAM,QAAO,KAAK;AAC1C,WAAO,OAAO;AAAA,EAChB,OAAO;AACL,QAAI,OAAO;AAAA,EACb;AACF;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,54 @@
1
+ import { createVariable, isVariable } from "../createVariable";
2
+ import { GetThemeUnwrapped } from "../hooks/getThemeUnwrapped";
3
+ function ensureThemeVariable(theme, key) {
4
+ const val = theme[key];
5
+ const themeKey = key;
6
+ if (!isVariable(val)) {
7
+ theme[key] = createVariable({
8
+ key: themeKey,
9
+ name: themeKey,
10
+ val
11
+ });
12
+ } else {
13
+ if (val.name !== themeKey) {
14
+ theme[key] = createVariable({
15
+ key: val.name,
16
+ name: themeKey,
17
+ val: val.val
18
+ });
19
+ }
20
+ }
21
+ }
22
+ function proxyThemeToParents(themeName, theme, themes) {
23
+ const cur = [];
24
+ const parents = themeName.split("_").slice(0, -1).map((part) => {
25
+ cur.push(part);
26
+ return cur.join("_");
27
+ });
28
+ const hasParents = parents.length;
29
+ return new Proxy(theme, {
30
+ get(target, key) {
31
+ if (key === GetThemeUnwrapped) {
32
+ return theme;
33
+ }
34
+ if (!hasParents || Reflect.has(target, key)) {
35
+ return Reflect.get(target, key);
36
+ }
37
+ for (let i = parents.length - 1; i >= 0; i--) {
38
+ const parent = themes[parents[i]];
39
+ if (!parent) {
40
+ continue;
41
+ }
42
+ if (Reflect.has(parent, key)) {
43
+ return Reflect.get(parent, key);
44
+ }
45
+ }
46
+ return Reflect.get(target, key);
47
+ }
48
+ });
49
+ }
50
+ export {
51
+ ensureThemeVariable,
52
+ proxyThemeToParents
53
+ };
54
+ //# sourceMappingURL=themes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/themes.ts"],
4
+ "sourcesContent": ["import { createVariable, isVariable } from '../createVariable'\nimport { GetThemeUnwrapped } from '../hooks/getThemeUnwrapped'\nimport { CreateTamaguiProps } from '../types'\n\n// mutates, freeze after\n// shared by createTamagui so extracted here\nexport function ensureThemeVariable(theme: any, key: string) {\n const val = theme[key]\n const themeKey = key\n if (!isVariable(val)) {\n theme[key] = createVariable({\n key: themeKey,\n name: themeKey,\n val,\n })\n } else {\n if (val.name !== themeKey) {\n // rename to theme name\n theme[key] = createVariable({\n key: val.name,\n name: themeKey,\n val: val.val,\n })\n }\n }\n}\n\nexport function proxyThemeToParents(\n themeName: string,\n theme: any,\n themes: CreateTamaguiProps['themes']\n) {\n // we could test if this is better as just a straight object spread or fancier proxy\n const cur: string[] = []\n // if theme is dark_blue_alt1_Button\n // this will be the parent names in order: ['dark', 'dark_blue', 'dark_blue_alt1\"]\n const parents = themeName\n .split('_')\n .slice(0, -1)\n .map((part) => {\n cur.push(part)\n return cur.join('_')\n })\n\n const hasParents = parents.length\n\n // proxy fallback values to parent theme values\n return new Proxy(theme, {\n get(target, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (!hasParents || Reflect.has(target, key)) {\n return Reflect.get(target, key)\n }\n // check parents\n for (let i = parents.length - 1; i >= 0; i--) {\n const parent = themes[parents[i]]\n if (!parent) {\n continue\n }\n if (Reflect.has(parent, key)) {\n return Reflect.get(parent, key)\n }\n }\n return Reflect.get(target, key)\n },\n })\n}\n"],
5
+ "mappings": "AAAA;AACA;AAKO,6BAA6B,OAAY,KAAa;AAC3D,QAAM,MAAM,MAAM;AAClB,QAAM,WAAW;AACjB,MAAI,CAAC,WAAW,GAAG,GAAG;AACpB,UAAM,OAAO,eAAe;AAAA,MAC1B,KAAK;AAAA,MACL,MAAM;AAAA,MACN;AAAA,IACF,CAAC;AAAA,EACH,OAAO;AACL,QAAI,IAAI,SAAS,UAAU;AAEzB,YAAM,OAAO,eAAe;AAAA,QAC1B,KAAK,IAAI;AAAA,QACT,MAAM;AAAA,QACN,KAAK,IAAI;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,6BACL,WACA,OACA,QACA;AAEA,QAAM,MAAgB,CAAC;AAGvB,QAAM,UAAU,UACb,MAAM,GAAG,EACT,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,QAAI,KAAK,IAAI;AACb,WAAO,IAAI,KAAK,GAAG;AAAA,EACrB,CAAC;AAEH,QAAM,aAAa,QAAQ;AAG3B,SAAO,IAAI,MAAM,OAAO;AAAA,IACtB,IAAI,QAAQ,KAAK;AACf,UAAI,QAAQ,mBAAmB;AAC7B,eAAO;AAAA,MACT;AACA,UAAI,CAAC,cAAc,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC3C,eAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,MAChC;AAEA,eAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC5C,cAAM,SAAS,OAAO,QAAQ;AAC9B,YAAI,CAAC,QAAQ;AACX;AAAA,QACF;AACA,YAAI,QAAQ,IAAI,QAAQ,GAAG,GAAG;AAC5B,iBAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,QAChC;AAAA,MACF;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF,CAAC;AACH;",
6
+ "names": []
7
+ }
@@ -1,31 +1,4 @@
1
- import * as React from "react";
2
- import { isWeb, useIsomorphicLayoutEffect } from "../constants/platform";
3
- let serverHandoffComplete = false;
4
- let id = 0;
5
- function genId() {
6
- return ++id;
7
- }
8
- function useId(providedId) {
9
- if (isWeb) {
10
- if (typeof React.useId === "function") {
11
- let id3 = React.useId();
12
- return providedId != null ? providedId : id3;
13
- }
14
- }
15
- let initialId = providedId ?? (serverHandoffComplete ? genId() : null);
16
- let [id2, setId] = React.useState(initialId);
17
- useIsomorphicLayoutEffect(() => {
18
- if (id2 === null) {
19
- setId(genId());
20
- }
21
- }, []);
22
- React.useEffect(() => {
23
- if (serverHandoffComplete === false) {
24
- serverHandoffComplete = true;
25
- }
26
- }, []);
27
- return providedId ?? id2 ?? void 0;
28
- }
1
+ import { useId } from "react";
29
2
  export {
30
3
  useId
31
4
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useId.tsx"],
4
- "sourcesContent": ["/*\n * Welcome to @reach/auto-id!\n\n * Let's see if we can make sense of why this hook exists and its\n * implementation.\n *\n * Some background:\n * 1. Accessibility APIs rely heavily on element IDs\n * 2. Requiring developers to put IDs on every element in Reach UI is both\n * cumbersome and error-prone\n * 3. With a component model, we can generate IDs for them!\n *\n * Solution 1: Generate random IDs.\n *\n * This works great as long as you don't server render your app. When React (in\n * the client) tries to reuse the markup from the server, the IDs won't match\n * and React will then recreate the entire DOM tree.\n *\n * Solution 2: Increment an integer\n *\n * This sounds great. Since we're rendering the exact same tree on the server\n * and client, we can increment a counter and get a deterministic result between\n * client and server. Also, JS integers can go up to nine-quadrillion. I'm\n * pretty sure the tab will be closed before an app never needs\n * 10 quadrillion IDs!\n *\n * Problem solved, right?\n *\n * Ah, but there's a catch! React's concurrent rendering makes this approach\n * non-deterministic. While the client and server will end up with the same\n * elements in the end, depending on suspense boundaries (and possibly some user\n * input during the initial render) the incrementing integers won't always match\n * up.\n *\n * Solution 3: Don't use IDs at all on the server; patch after first render.\n *\n * What we've done here is solution 2 with some tricks. With this approach, the\n * ID returned is an empty string on the first render. This way the server and\n * client have the same markup no matter how wild the concurrent rendering may\n * have gotten.\n *\n * After the render, we patch up the components with an incremented ID. This\n * causes a double render on any components with `useId`. Shouldn't be a problem\n * since the components using this hook should be small, and we're only updating\n * the ID attribute on the DOM, nothing big is happening.\n *\n * It doesn't have to be an incremented number, though--we could do generate\n * random strings instead, but incrementing a number is probably the cheapest\n * thing we can do.\n *\n * Additionally, we only do this patchup on the very first client render ever.\n * Any calls to `useId` that happen dynamically in the client will be\n * populated immediately with a value. So, we only get the double render after\n * server hydration and never again, SO BACK OFF ALRIGHT?\n */\n\nimport * as React from 'react'\n\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\n\nlet serverHandoffComplete = false\nlet id = 0\nfunction genId() {\n return ++id\n}\n\n/* eslint-disable react-hooks/rules-of-hooks */\n\n/**\n * useId\n *\n * Autogenerate IDs to facilitate WAI-ARIA and server rendering.\n *\n * Note: The returned ID will initially be `null` and will update after a\n * component mounts. Users may need to supply their own ID if they need\n * consistent values for SSR.\n *\n * @see Docs https://reach.tech/auto-id\n */\nfunction useId(idFromProps: string): string\nfunction useId(idFromProps: number): number\nfunction useId(idFromProps: string | number): string | number\nfunction useId(idFromProps: string | undefined | null): string | undefined\nfunction useId(idFromProps: number | undefined | null): number | undefined\nfunction useId(idFromProps: string | number | undefined | null): string | number | undefined\nfunction useId(): string | undefined\n\nfunction useId(providedId?: number | string | undefined | null) {\n // TODO: Remove error flag when updating internal deps to React 18. None of\n // our tricks will play well with concurrent rendering anyway.\n\n // native doesn't support until next react-native version, need to remove eventually\n if (isWeb) {\n if (typeof React.useId === 'function') {\n let id = React.useId()\n return providedId != null ? providedId : id\n }\n }\n\n // If this instance isn't part of the initial render, we don't have to do the\n // double render/patch-up dance. We can just generate the ID and return it.\n let initialId = providedId ?? (serverHandoffComplete ? genId() : null)\n let [id, setId] = React.useState(initialId)\n\n useIsomorphicLayoutEffect(() => {\n if (id === null) {\n // Patch the ID after render. We do this in `useLayoutEffect` to avoid any\n // rendering flicker, though it'll make the first render slower (unlikely\n // to matter, but you're welcome to measure your app and let us know if\n // it's a problem).\n setId(genId())\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n React.useEffect(() => {\n if (serverHandoffComplete === false) {\n // Flag all future uses of `useId` to skip the update dance. This is in\n // `useEffect` because it goes after `useLayoutEffect`, ensuring we don't\n // accidentally bail out of the patch-up dance prematurely.\n serverHandoffComplete = true\n }\n }, [])\n\n return providedId ?? id ?? undefined\n}\n\nexport { useId }\n"],
5
- "mappings": "AAwDA;AAEA;AAEA,IAAI,wBAAwB;AAC5B,IAAI,KAAK;AACT,iBAAiB;AACf,SAAO,EAAE;AACX;AAuBA,eAAe,YAAiD;AAK9D,MAAI,OAAO;AACT,QAAI,OAAO,MAAM,UAAU,YAAY;AACrC,UAAI,MAAK,MAAM,MAAM;AACrB,aAAO,cAAc,OAAO,aAAa;AAAA,IAC3C;AAAA,EACF;AAIA,MAAI,YAAY,cAAe,yBAAwB,MAAM,IAAI;AACjE,MAAI,CAAC,KAAI,SAAS,MAAM,SAAS,SAAS;AAE1C,4BAA0B,MAAM;AAC9B,QAAI,QAAO,MAAM;AAKf,YAAM,MAAM,CAAC;AAAA,IACf;AAAA,EAEF,GAAG,CAAC,CAAC;AAEL,QAAM,UAAU,MAAM;AACpB,QAAI,0BAA0B,OAAO;AAInC,8BAAwB;AAAA,IAC1B;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,cAAc,OAAM;AAC7B;",
4
+ "sourcesContent": ["export { useId } from 'react'\n"],
5
+ "mappings": "AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,13 +1,13 @@
1
- import { useForceUpdate } from "@tamagui/use-force-update";
2
- import { useEffect, useRef } from "react";
1
+ import { useMemo, useState } from "react";
3
2
  import { useIsomorphicLayoutEffect } from "../constants/platform";
4
3
  import { matchMedia } from "../helpers/matchMedia";
5
- import { useConstant } from "./useConstant";
4
+ import { useSafeRef } from "./useSafeRef";
6
5
  const mediaState = {};
7
6
  const mediaQueryListeners = {};
8
7
  function addMediaQueryListener(key, cb) {
9
8
  mediaQueryListeners[key] = mediaQueryListeners[key] || /* @__PURE__ */ new Set();
10
9
  mediaQueryListeners[key].add(cb);
10
+ return () => removeMediaQueryListener(key, cb);
11
11
  }
12
12
  function removeMediaQueryListener(key, cb) {
13
13
  var _a;
@@ -18,114 +18,95 @@ const getMedia = () => {
18
18
  return mediaState;
19
19
  };
20
20
  const dispose = /* @__PURE__ */ new Set();
21
+ let initialMediaState;
21
22
  const configureMedia = ({
22
23
  queries,
23
- defaultActive = ["sm", "xs"]
24
+ defaultActive = {}
24
25
  } = {}) => {
25
26
  if (!queries)
26
27
  return;
27
- if (mediaQueryConfig) {
28
- if (JSON.stringify(queries) === JSON.stringify(mediaQueryConfig)) {
29
- return;
28
+ if (initialMediaState) {
29
+ if (process.env.NODE_ENV === "development") {
30
+ if (JSON.stringify(queries) === JSON.stringify(mediaQueryConfig)) {
31
+ return;
32
+ }
30
33
  }
31
- dispose.forEach((cb) => cb());
32
- dispose.clear();
34
+ setupMediaListeners();
33
35
  }
34
36
  Object.assign(mediaQueryConfig, queries);
35
37
  for (const key in queries) {
36
- const str = mediaObjectToString(queries[key]);
37
- const propKey = `$${key}`;
38
- try {
39
- let update2 = function() {
40
- const next = !!getMatch().matches;
41
- if (next === mediaState[propKey])
42
- return;
43
- mediaState[propKey] = next;
44
- const listeners = mediaQueryListeners[propKey];
45
- if (listeners == null ? void 0 : listeners.size) {
46
- for (const cb of [...listeners]) {
47
- cb();
48
- }
38
+ mediaState[key] = defaultActive[key] || false;
39
+ }
40
+ initialMediaState = { ...mediaState };
41
+ };
42
+ function unlisten() {
43
+ dispose.forEach((cb) => cb());
44
+ dispose.clear();
45
+ }
46
+ function setupMediaListeners() {
47
+ unlisten();
48
+ for (const key in mediaQueryConfig) {
49
+ let update2 = function() {
50
+ const next = !!getMatch().matches;
51
+ if (next === mediaState[key])
52
+ return;
53
+ mediaState[key] = next;
54
+ const listeners = mediaQueryListeners[key];
55
+ if (listeners == null ? void 0 : listeners.size) {
56
+ for (const cb of [...listeners]) {
57
+ cb();
49
58
  }
50
- };
51
- var update = update2;
52
- const getMatch = () => matchMedia(str);
53
- const match = getMatch();
54
- if (!match || typeof match.addListener !== "function") {
55
- throw new Error("\u26A0\uFE0F No match (seeing this in RN sometimes)");
56
59
  }
57
- mediaState[propKey] = !!match.matches;
58
- match.addListener(update2);
59
- dispose.add(() => match.removeListener(update2));
60
- update2();
61
- } catch (err) {
62
- console.error("Error running media query", str, err.message, err.stack);
63
- const isDefaultActive = (defaultActive == null ? void 0 : defaultActive.includes(key)) ?? true;
64
- mediaState[propKey] = isDefaultActive;
60
+ };
61
+ var update = update2;
62
+ const str = mediaObjectToString(mediaQueryConfig[key]);
63
+ const getMatch = () => matchMedia(str);
64
+ const match = getMatch();
65
+ if (!match) {
66
+ throw new Error("\u26A0\uFE0F No match");
65
67
  }
68
+ match.addListener(update2);
69
+ dispose.add(() => match.removeListener(update2));
70
+ update2();
66
71
  }
67
- };
72
+ }
73
+ function useMediaQueryListeners() {
74
+ useIsomorphicLayoutEffect(() => {
75
+ setupMediaListeners();
76
+ return unlisten;
77
+ }, []);
78
+ }
68
79
  function useMedia() {
69
- const forceUpdate = useForceUpdate();
70
- const state = useRef();
71
- if (!state.current) {
72
- state.current = {
73
- selections: {},
74
- nextSelections: {},
75
- isUnmounted: false,
76
- isRendering: true
77
- };
80
+ const [state, setState] = useState(initialMediaState);
81
+ const keys = useSafeRef({});
82
+ function updateState() {
83
+ setState((prev) => {
84
+ for (const key in keys.current) {
85
+ if (prev[key] !== mediaState[key]) {
86
+ return { ...mediaState };
87
+ }
88
+ }
89
+ return prev;
90
+ });
78
91
  }
79
- state.current.isRendering = true;
80
92
  useIsomorphicLayoutEffect(() => {
81
- const st = state.current;
82
- st.isRendering = false;
83
- for (const key in st.selections) {
84
- if (!(key in st.nextSelections)) {
85
- removeMediaQueryListener(key, forceUpdate);
86
- }
87
- }
88
- for (const key in st.nextSelections) {
89
- if (!(key in st.selections)) {
90
- addMediaQueryListener(key, forceUpdate);
91
- }
93
+ const listeners = [];
94
+ for (const key in keys.current) {
95
+ listeners.push(addMediaQueryListener(key, updateState));
92
96
  }
93
- });
94
- useEffect(() => {
97
+ updateState();
95
98
  return () => {
96
- const st = state.current;
97
- st.isUnmounted = true;
98
- const allKeys = {
99
- ...st.selections,
100
- ...st.nextSelections
101
- };
102
- for (const key in allKeys) {
103
- removeMediaQueryListener(key, forceUpdate);
104
- }
99
+ listeners.forEach((cb) => cb());
105
100
  };
106
- }, []);
107
- return useConstant(() => {
108
- const st = state.current;
109
- return new Proxy(mediaState, {
110
- get(target, key) {
111
- if (key[0] !== "$") {
112
- key = `$${key}`;
113
- }
114
- if (!(key in mediaState)) {
115
- return Reflect.get(target, key);
116
- }
117
- if (!st.isUnmounted) {
118
- if (st.isRendering) {
119
- st.nextSelections[key] = true;
120
- }
121
- }
122
- if (key in mediaState) {
123
- return mediaState[key];
124
- }
125
- return Reflect.get(mediaState, key);
126
- }
127
- });
128
101
  });
102
+ return useMemo(() => new Proxy(state, {
103
+ get(_, key) {
104
+ if (!keys.current[key]) {
105
+ keys.current = { ...keys.current, [key]: true };
106
+ }
107
+ return Reflect.get(state, key);
108
+ }
109
+ }), [state, keys]);
129
110
  }
130
111
  function camelToHyphen(str) {
131
112
  return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase();
@@ -153,6 +134,7 @@ export {
153
134
  mediaQueryConfig,
154
135
  mediaState,
155
136
  removeMediaQueryListener,
156
- useMedia
137
+ useMedia,
138
+ useMediaQueryListeners
157
139
  };
158
140
  //# sourceMappingURL=useMedia.js.map