@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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useMedia.tsx"],
4
- "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport { useEffect, useRef } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n ConfigureMediaQueryOptions,\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n} from '../types'\nimport { useConstant } from './useConstant'\n\nexport const mediaState: MediaQueryState = {} as any\nconst mediaQueryListeners: { [key: string]: Set<Function> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: any) {\n mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()\n mediaQueryListeners[key].add(cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: any) {\n mediaQueryListeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => {\n return mediaState\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = ({\n queries,\n defaultActive = ['sm', 'xs'],\n}: ConfigureMediaQueryOptions = {}) => {\n if (!queries) return\n // support hot reload\n if (mediaQueryConfig) {\n if (JSON.stringify(queries) === JSON.stringify(mediaQueryConfig)) {\n // hmr avoid update\n return\n }\n dispose.forEach((cb) => cb())\n dispose.clear()\n }\n\n Object.assign(mediaQueryConfig, queries)\n\n // setup\n for (const key in queries) {\n const str = mediaObjectToString(queries[key])\n const propKey = `$${key}`\n try {\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match || typeof match.addListener !== 'function') {\n // caught below\n throw new Error('\u26A0\uFE0F No match (seeing this in RN sometimes)')\n }\n mediaState[propKey] = !!match.matches\n // note this deprecated api works with polyfills we use now\n match.addListener(update)\n dispose.add(() => match.removeListener(update))\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[propKey]) return\n mediaState[propKey] = next\n const listeners = mediaQueryListeners[propKey]\n if (listeners?.size) {\n for (const cb of [...listeners]) {\n cb()\n }\n }\n }\n\n update()\n } catch (err: any) {\n console.error('Error running media query', str, err.message, err.stack)\n const isDefaultActive = defaultActive?.includes(key as any) ?? true\n mediaState[propKey] = isDefaultActive\n }\n }\n}\n\ntype UseMediaState = {\n selections: { [key: string]: boolean }\n nextSelections: { [key: string]: boolean }\n isRendering: boolean\n isUnmounted: boolean\n}\n\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const forceUpdate = useForceUpdate()\n const state = useRef() as React.MutableRefObject<UseMediaState>\n if (!state.current) {\n state.current = {\n selections: {},\n nextSelections: {},\n isUnmounted: false,\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n // delete old\n for (const key in st.selections) {\n if (!(key in st.nextSelections)) {\n removeMediaQueryListener(key, forceUpdate)\n }\n }\n // add new\n for (const key in st.nextSelections) {\n if (!(key in st.selections)) {\n addMediaQueryListener(key, forceUpdate)\n }\n }\n })\n\n // unmount\n useEffect(() => {\n return () => {\n const st = state.current\n st.isUnmounted = true\n const allKeys = {\n ...st.selections,\n ...st.nextSelections,\n }\n for (const key in allKeys) {\n removeMediaQueryListener(key, forceUpdate)\n }\n }\n }, [])\n\n return useConstant(() => {\n const st = state.current\n return new Proxy(mediaState, {\n get(target, key: string) {\n if (key[0] !== '$') {\n key = `$${key}`\n }\n if (!(key in mediaState)) {\n return Reflect.get(target, key)\n }\n if (!st.isUnmounted) {\n if (st.isRendering) {\n st.nextSelections[key] = true\n }\n }\n if (key in mediaState) {\n return mediaState[key]\n }\n return Reflect.get(mediaState, key)\n },\n })\n })\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join(' and ')\n}\n"],
5
- "mappings": "AAAA;AACA;AAEA;AACA;AAQA;AAEO,MAAM,aAA8B,CAAC;AAC5C,MAAM,sBAAwD,CAAC;AAExD,+BAA+B,KAAoB,IAAS;AACjE,sBAAoB,OAAO,oBAAoB,QAAQ,oBAAI,IAAI;AAC/D,sBAAoB,KAAK,IAAI,EAAE;AACjC;AAEO,kCAAkC,KAAoB,IAAS;AAtBtE;AAuBE,4BAAoB,SAApB,mBAA0B,OAAO;AACnC;AAEO,MAAM,mBAAiC,CAAC;AAExC,MAAM,WAAW,MAAM;AAC5B,SAAO;AACT;AAEA,MAAM,UAAU,oBAAI,IAAc;AAE3B,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA,gBAAgB,CAAC,MAAM,IAAI;AAAA,IACG,CAAC,MAAM;AACrC,MAAI,CAAC;AAAS;AAEd,MAAI,kBAAkB;AACpB,QAAI,KAAK,UAAU,OAAO,MAAM,KAAK,UAAU,gBAAgB,GAAG;AAEhE;AAAA,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AC,CAAC,SAAS,WAAW;AACzB,cAAU,cAAc,OAAO;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY;AAAA,IACzB;AACA,QAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,OAAO,GAAG;AAChE,cAAQ,GAAG;AAAA,IACb;AACA,WAAO,IAAI,YAAY;AAAA,EACzB,CAAC,EACA,KAAK,OAAO;AACjB;",
4
+ "sourcesContent": ["import { useMemo, useState } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n ConfigureMediaQueryOptions,\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState = {} as any\nconst mediaQueryListeners: { [key: string]: Set<Function> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: any) {\n mediaQueryListeners[key] = mediaQueryListeners[key] || new Set()\n mediaQueryListeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: any) {\n mediaQueryListeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => {\n return mediaState\n}\n\nconst dispose = new Set<Function>()\n\n// for SSR capture it at time of startup\nlet initialMediaState: MediaQueryState | null\n\nexport const configureMedia = ({\n queries,\n defaultActive = {},\n}: ConfigureMediaQueryOptions = {}) => {\n if (!queries) return\n\n // support hot reload\n if (initialMediaState) {\n if (process.env.NODE_ENV === 'development') {\n if (JSON.stringify(queries) === JSON.stringify(mediaQueryConfig)) {\n // hmr avoid update\n return\n }\n }\n setupMediaListeners()\n }\n\n Object.assign(mediaQueryConfig, queries)\n // start in the initial state\n for (const key in queries) {\n mediaState[key] = defaultActive[key] || false\n }\n initialMediaState = { ...mediaState }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\nfunction setupMediaListeners() {\n // hmr, undo existing before re-binding\n unlisten()\n\n for (const key in mediaQueryConfig) {\n const str = mediaObjectToString(mediaQueryConfig[key])\n const getMatch = () => matchMedia(str)\n const match = getMatch()\n if (!match) {\n throw new Error('\u26A0\uFE0F No match')\n }\n // react native needs these deprecated apis for now\n match.addListener(update)\n dispose.add(() => match.removeListener(update))\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n const listeners = mediaQueryListeners[key]\n if (listeners?.size) {\n for (const cb of [...listeners]) {\n cb()\n }\n }\n }\n }\n}\n\nexport function useMediaQueryListeners() {\n useIsomorphicLayoutEffect(() => {\n setupMediaListeners()\n return unlisten\n }, [])\n}\n\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const [state, setState] = useState(initialMediaState!)\n const keys = useSafeRef({} as Record<string, boolean>)\n\n function updateState() {\n setState((prev) => {\n for (const key in keys.current) {\n if (prev[key] !== mediaState[key]) {\n return { ...mediaState }\n }\n }\n return prev\n })\n }\n\n useIsomorphicLayoutEffect(() => {\n const listeners: Function[] = []\n for (const key in keys.current) {\n listeners.push(addMediaQueryListener(key, updateState))\n }\n updateState()\n return () => {\n listeners.forEach((cb) => cb())\n }\n })\n\n return useMemo(\n () =>\n new Proxy(state, {\n get(_, key: string) {\n if (!keys.current[key]) {\n keys.current = { ...keys.current, [key]: true }\n }\n return Reflect.get(state, key)\n },\n }),\n [state, keys]\n )\n}\n\nfunction camelToHyphen(str: string) {\n return str.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`).toLowerCase()\n}\n\nexport function mediaObjectToString(query: string | MediaQueryObject) {\n if (typeof query === 'string') {\n return query\n }\n return Object.entries(query)\n .map(([feature, value]) => {\n feature = camelToHyphen(feature)\n if (typeof value === 'string') {\n return `(${feature}: ${value})`\n }\n if (typeof value === 'number' && /[height|width]$/.test(feature)) {\n value = `${value}px`\n }\n return `(${feature}: ${value})`\n })\n .join('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A,uBAAuB,KAAa;AAClC,SAAO,IAAI,QAAQ,UAAU,CAAC,MAAM,IAAI,EAAE,YAAY,GAAG,EAAE,YAAY;AACzE;AAEO,6BAA6B,OAAkC;AACpE,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,KAAK,EACxB,IAAI,CAAC,CAAC,SAAS,WAAW;AACzB,cAAU,cAAc,OAAO;AAC/B,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,IAAI,YAAY;AAAA,IACzB;AACA,QAAI,OAAO,UAAU,YAAY,kBAAkB,KAAK,OAAO,GAAG;AAChE,cAAQ,GAAG;AAAA,IACb;AACA,WAAO,IAAI,YAAY;AAAA,EACzB,CAAC,EACA,KAAK,OAAO;AACjB;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,36 @@
1
+ import { useRef } from "react";
2
+ import { useIsomorphicLayoutEffect } from "../constants/platform";
3
+ const useSafeRef = (initialValue) => {
4
+ const rawRef = useRef();
5
+ const raw = rawRef.current ?? (rawRef.current = {
6
+ isRendering: true,
7
+ comittedValue: initialValue,
8
+ currentValue: initialValue,
9
+ ref: {
10
+ get current() {
11
+ if (raw.isRendering) {
12
+ return raw.currentValue;
13
+ } else {
14
+ return raw.comittedValue;
15
+ }
16
+ },
17
+ set current(v) {
18
+ if (!raw.isRendering) {
19
+ raw.comittedValue = v;
20
+ }
21
+ raw.currentValue = v;
22
+ }
23
+ }
24
+ });
25
+ raw.isRendering = true;
26
+ Promise.resolve().then(() => raw.isRendering = false);
27
+ raw.currentValue = raw.comittedValue;
28
+ useIsomorphicLayoutEffect(() => {
29
+ raw.comittedValue = raw.currentValue;
30
+ });
31
+ return raw.ref;
32
+ };
33
+ export {
34
+ useSafeRef
35
+ };
36
+ //# sourceMappingURL=useSafeRef.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useSafeRef.ts"],
4
+ "sourcesContent": ["import { useRef } from 'react'\n\nimport { useIsomorphicLayoutEffect } from '../constants/platform'\n\n// dai-shi \uD83D\uDE4F\n// https://dev.to/uhyo_/a-concurrent-mode-safe-version-of-useref-1325\n\ntype Raw<T> = {\n isRendering: boolean\n comittedValue: T\n currentValue: T\n ref: { current: T }\n}\n\nexport const useSafeRef = <T>(initialValue: T) => {\n const rawRef = useRef<Raw<T>>()\n\n const raw: Raw<T> =\n rawRef.current ??\n (rawRef.current = {\n isRendering: true,\n comittedValue: initialValue,\n currentValue: initialValue,\n ref: {\n get current() {\n if (raw.isRendering) {\n return raw.currentValue\n } else {\n return raw.comittedValue\n }\n },\n set current(v) {\n if (!raw.isRendering) {\n raw.comittedValue = v\n }\n raw.currentValue = v\n },\n },\n })\n\n raw.isRendering = true\n Promise.resolve().then(() => (raw.isRendering = false))\n raw.currentValue = raw.comittedValue\n\n useIsomorphicLayoutEffect(() => {\n raw.comittedValue = raw.currentValue\n })\n\n return raw.ref\n}\n"],
5
+ "mappings": "AAAA;AAEA;AAYO,MAAM,aAAa,CAAI,iBAAoB;AAChD,QAAM,SAAS,OAAe;AAE9B,QAAM,MACJ,OAAO,WACN,QAAO,UAAU;AAAA,IAChB,aAAa;AAAA,IACb,eAAe;AAAA,IACf,cAAc;AAAA,IACd,KAAK;AAAA,MACH,IAAI,UAAU;AACZ,YAAI,IAAI,aAAa;AACnB,iBAAO,IAAI;AAAA,QACb,OAAO;AACL,iBAAO,IAAI;AAAA,QACb;AAAA,MACF;AAAA,MACA,IAAI,QAAQ,GAAG;AACb,YAAI,CAAC,IAAI,aAAa;AACpB,cAAI,gBAAgB;AAAA,QACtB;AACA,YAAI,eAAe;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEF,MAAI,cAAc;AAClB,UAAQ,QAAQ,EAAE,KAAK,MAAO,IAAI,cAAc,KAAM;AACtD,MAAI,eAAe,IAAI;AAEvB,4BAA0B,MAAM;AAC9B,QAAI,gBAAgB,IAAI;AAAA,EAC1B,CAAC;AAED,SAAO,IAAI;AACb;",
6
+ "names": []
7
+ }
@@ -2,9 +2,13 @@ import { useForceUpdate } from "@tamagui/use-force-update";
2
2
  import { useContext, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { getConfig } from "../conf";
4
4
  import { isWeb, useIsomorphicLayoutEffect } from "../constants/platform";
5
+ import { ThemeContext } from "../contexts/ThemeContext";
5
6
  import { areEqualSets } from "../helpers/areEqualSets";
6
- import { ThemeContext } from "../ThemeContext";
7
- import { ThemeManager, ThemeManagerContext, emptyManager } from "../ThemeManager";
7
+ import {
8
+ ThemeManager,
9
+ ThemeManagerContext,
10
+ emptyManager
11
+ } from "../helpers/ThemeManager";
8
12
  import { GetThemeUnwrapped } from "./getThemeUnwrapped";
9
13
  import { useConstant } from "./useConstant";
10
14
  const useTheme = (themeName, componentName, props, forceUpdate) => {
@@ -31,13 +35,14 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
31
35
  themeManager == null ? void 0 : themeManager.track(st.uuid, st.keys);
32
36
  }
33
37
  });
34
- return useMemo(() => {
35
- if (!theme) {
36
- if (process.env.NODE_ENV === "development") {
37
- console.warn("No theme", { themeName, theme, componentName, className });
38
- }
39
- return themes[getConfig().defaultTheme || "light"];
38
+ const debugProp = props && props["debug"];
39
+ if (!theme) {
40
+ if (process.env.NODE_ENV === "development") {
41
+ console.warn("No theme with name", themeName);
40
42
  }
43
+ return themes[getConfig().defaultTheme || "light"];
44
+ }
45
+ return useMemo(() => {
41
46
  return new Proxy(theme, {
42
47
  has(_, key) {
43
48
  if (typeof key === "string") {
@@ -72,14 +77,14 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
72
77
  }
73
78
  if (state.current.isRendering && !state.current.keys.has(key)) {
74
79
  state.current.keys.add(key);
75
- if (process.env.NODE_ENV === "development" && (props == null ? void 0 : props["debug"]) === "verbose") {
80
+ if (process.env.NODE_ENV === "development" && debugProp === "verbose") {
76
81
  console.log(" \u{1F538} tracking theme", key);
77
82
  }
78
83
  }
79
84
  return themeManager.getValue(key);
80
85
  }
81
86
  });
82
- }, [name, theme, className]);
87
+ }, [name, theme, componentName, className, debugProp]);
83
88
  };
84
89
  const GetThemeManager = Symbol();
85
90
  const getThemeManager = (theme) => {
@@ -106,6 +111,7 @@ const useDefaultThemeName = () => {
106
111
  var _a;
107
112
  return (_a = useContext(ThemeContext)) == null ? void 0 : _a.defaultTheme;
108
113
  };
114
+ const activeThemeManagers = /* @__PURE__ */ new Set();
109
115
  const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
110
116
  const debug = props && props["debug"];
111
117
  const parentManager = useContext(ThemeManagerContext) || emptyManager;
@@ -123,10 +129,11 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
123
129
  useLayoutEffect(() => {
124
130
  if (!themeManager)
125
131
  return;
132
+ activeThemeManagers.add(themeManager);
126
133
  if (next == null ? void 0 : next.name) {
127
134
  themeManager.update(next);
128
135
  }
129
- return parentManager.onChangeTheme(() => {
136
+ const disposeParentOnChange = parentManager.onChangeTheme(() => {
130
137
  const next2 = parentManager.getNextTheme(getThemeProps, debug);
131
138
  if (!next2)
132
139
  return;
@@ -134,6 +141,10 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
134
141
  forceUpdate();
135
142
  }
136
143
  });
144
+ return () => {
145
+ activeThemeManagers.delete(themeManager);
146
+ disposeParentOnChange();
147
+ };
137
148
  }, [themes, name, componentName, debug, next == null ? void 0 : next.name]);
138
149
  }
139
150
  return {
@@ -147,6 +158,7 @@ const useChangeThemeEffect = (name, componentName, props, forceUpdateProp) => {
147
158
  };
148
159
  };
149
160
  export {
161
+ activeThemeManagers,
150
162
  getThemeManager,
151
163
  useChangeThemeEffect,
152
164
  useDefaultThemeName,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useTheme.tsx"],
4
- "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../conf'\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport { ThemeContext } from '../ThemeContext'\nimport { GetNextThemeProps, ThemeManager, ThemeManagerContext, emptyManager } from '../ThemeManager'\nimport { ThemeName, ThemeObject } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\n\nexport type ThemeProps = {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeObject => {\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n console.log(' \uD83D\uDD39 useTheme', { themeName, componentName, name, className })\n }\n }\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n return useMemo(() => {\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme', { themeName, theme, componentName, className })\n }\n return themes[getConfig().defaultTheme || 'light' || Object.keys(themes)[0]]\n }\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') {\n key = key.slice(1)\n }\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (key === GetThemeManager) {\n return themeManager\n }\n if (key === 'name') {\n return name\n }\n if (key === 'className') {\n return className\n }\n if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n if (!themeManager) {\n console.error('No themeManager')\n return\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (state.current.isRendering && !state.current.keys.has(key)) {\n state.current.keys.add(key)\n if (process.env.NODE_ENV === 'development' && props?.['debug'] === 'verbose') {\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n return themeManager.getValue(key)\n },\n })\n }, [name, theme, className])\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent?.name || '')\n\n useIsomorphicLayoutEffect(() => {\n if (!parent) return\n return parent.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [parent])\n\n return name\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)?.defaultTheme\n}\n\nexport const useChangeThemeEffect = (\n name?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdateProp?: any\n) => {\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const { themes } = useContext(ThemeContext)!\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = { name, componentName, themes, reset }\n const next = parentManager.getNextTheme(getThemeProps, debug)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forceUpdate = forceUpdateProp || useForceUpdate()\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!next) return null\n return new ThemeManager(next.name, next.theme, parentManager, reset)\n })\n\n if (!isWeb || typeof document !== 'undefined') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n if (!themeManager) return\n if (next?.name) {\n themeManager.update(next)\n }\n return parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n forceUpdate()\n }\n })\n }, [themes, name, componentName, debug, next?.name])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n themes,\n themeManager,\n }\n}\n"],
5
- "mappings": "AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAkBO,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAChB,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,cAAc,qBACvD,WACA,eACA,OACA,WACF;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,gCAAO,WAAU,WAAW;AAC9B,cAAQ,IAAI,wBAAiB,EAAE,WAAW,eAAe,MAAM,UAAU,CAAC;AAAA,IAC5E;AAAA,EACF;AAEA,QAAM,QAAQ,OAAO;AACrB,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AACA,QAAM,QAAQ,cAAc;AAG5B,4BAA0B,MAAM;AAC9B,UAAM,KAAK,MAAM;AACjB,OAAG,cAAc;AACjB,UAAM,MAAM,6CAAc,KAAK,IAAI,GAAG;AACtC,QAAI,CAAC,OAAO,CAAC,aAAa,GAAG,MAAM,GAAG,GAAG;AACvC,mDAAc,MAAM,GAAG,MAAM,GAAG;AAAA,IAClC;AAAA,EACF,CAAC;AAED,SAAO,QAAQ,MAAM;AACnB,QAAI,CAAC,OAAO;AACV,UAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,gBAAQ,KAAK,YAAY,EAAE,WAAW,OAAO,eAAe,UAAU,CAAC;AAAA,MACzE;AACA,aAAO,OAAO,UAAU,EAAE,gBAAgB;AAAA,IAC5C;AACA,WAAO,IAA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AAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../conf'\nimport { isWeb, useIsomorphicLayoutEffect } from '../constants/platform'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeObject } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useConstant } from './useConstant'\n\nexport type ThemeProps = {\n className?: string\n disableThemeClass?: boolean\n name: Exclude<ThemeName, number> | null\n componentName?: string\n children?: any\n reset?: boolean\n debug?: boolean | 'verbose'\n}\n\ntype UseThemeState = {\n uuid: Object\n keys: Set<string>\n isRendering: boolean\n}\n\nexport const useTheme = (\n themeName?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdate?: any\n): ThemeObject => {\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD39 useTheme', { themeName, componentName, name, className })\n }\n }\n\n const state = useRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n state.current.isRendering = true\n\n // track usage\n useIsomorphicLayoutEffect(() => {\n const st = state.current\n st.isRendering = false\n const cur = themeManager?.keys.get(st.uuid)\n if (!cur || !areEqualSets(st.keys, cur)) {\n themeManager?.track(st.uuid, st.keys)\n }\n })\n\n const debugProp = props && props['debug']\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.warn('No theme with name', themeName)\n }\n return themes[getConfig().defaultTheme || 'light']\n }\n\n return useMemo(() => {\n return new Proxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') {\n key = key.slice(1)\n }\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (key === GetThemeManager) {\n return themeManager\n }\n if (key === 'name') {\n return name\n }\n if (key === 'className') {\n return className\n }\n if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n if (!themeManager) {\n console.error('No themeManager')\n return\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (state.current.isRendering && !state.current.keys.has(key)) {\n state.current.keys.add(key)\n if (process.env.NODE_ENV === 'development' && debugProp === 'verbose') {\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n return themeManager.getValue(key)\n },\n })\n }, [name, theme, componentName, className, debugProp])\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport const useThemeName = (opts?: { parent?: true }) => {\n const parent = useContext(ThemeManagerContext)\n const [name, setName] = useState(parent?.name || '')\n\n useIsomorphicLayoutEffect(() => {\n if (!parent) return\n return parent.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [parent])\n\n return name\n}\n\nexport const useDefaultThemeName = () => {\n return useContext(ThemeContext)?.defaultTheme\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n name?: string | null,\n componentName?: string,\n props?: ThemeProps,\n forceUpdateProp?: any\n) => {\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const { themes } = useContext(ThemeContext)!\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = { name, componentName, themes, reset }\n const next = parentManager.getNextTheme(getThemeProps, debug)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const forceUpdate = forceUpdateProp || useForceUpdate()\n\n const themeManager = useConstant<ThemeManager | null>(() => {\n if (!next) return null\n return new ThemeManager(next.name, next.theme, parentManager, reset)\n })\n\n // if not SSR\n if (!isWeb || typeof document !== 'undefined') {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n if (next?.name) {\n themeManager.update(next)\n }\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n forceUpdate()\n }\n })\n\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeParentOnChange()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [themes, name, componentName, debug, next?.name])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n themes,\n themeManager,\n }\n}\n"],
5
+ "mappings": "AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAOA;AACA;AAkBO,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAChB,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,cAAc,qBACvD,WACA,eACA,OACA,WACF;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,gCAAO,WAAU,WAAW;AAE9B,cAAQ,IAAI,wBAAiB,EAAE,WAAW,eAAe,MAAM,UAAU,CAAC;AAAA,IAC5E;AAAA,EACF;AAEA,QAAM,QAAQ,OAAO;AACrB,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AA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AAmB,eAAe;AAEtD,QAAM,eAAe,YAAiC,MAAM;AAC1D,QAAI,CAAC;AAAM,aAAO;AAClB,WAAO,IAAI,aAAa,KAAK,MAAM,KAAK,OAAO,eAAe,KAAK;AAAA,EACrE,CAAC;AAGD,MAAI,CAAC,SAAS,OAAO,aAAa,aAAa;AAE7C,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AAEnB,0BAAoB,IAAI,YAAY;AAEpC,UAAI,6BAAM,MAAM;AACd,qBAAa,OAAO,IAAI;AAAA,MAC1B;AAEA,YAAM,wBAAwB,cAAc,cAAc,MAAM;AAC9D,cAAM,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAAC;AAAM;AACX,YAAI,aAAa,OAAO,KAAI,GAAG;AAC7B,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,QAAQ,MAAM,eAAe,OAAO,6BAAM,IAAI,CAAC;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -8,6 +8,8 @@ export * from "./createTokens";
8
8
  export * from "./createVariable";
9
9
  export * from "./createVariables";
10
10
  export * from "./insertFont";
11
+ export * from "./addTheme";
12
+ export * from "./updateTheme";
11
13
  export * from "./styled";
12
14
  export * from "./types";
13
15
  import { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from "./conf";
@@ -38,15 +40,25 @@ export * from "./hooks/useConstant";
38
40
  export * from "./hooks/useId";
39
41
  export * from "./hooks/useIsMounted";
40
42
  export * from "./hooks/useIsTouchDevice";
41
- export * from "./hooks/useMedia";
43
+ import {
44
+ configureMedia,
45
+ getMedia,
46
+ mediaState,
47
+ useMedia,
48
+ mediaObjectToString,
49
+ addMediaQueryListener,
50
+ removeMediaQueryListener,
51
+ mediaQueryConfig
52
+ } from "./hooks/useMedia";
42
53
  export * from "./hooks/usePressable";
43
54
  export * from "./hooks/useTheme";
44
55
  export * from "./hooks/useIsSSR";
45
56
  export * from "./hooks/useUnmountEffect";
57
+ export * from "./hooks/useSafeRef";
46
58
  export * from "./views/Slot";
47
59
  export * from "./views/Stack";
48
60
  export * from "./views/Text";
49
- import { TextAncestorProvider, TextAncestorContext } from "./views/TextAncestorContext";
61
+ import { TextAncestorProvider, TextAncestorContext } from "./contexts/TextAncestorContext";
50
62
  export * from "./views/Theme";
51
63
  export * from "./views/ThemeInverse";
52
64
  export * from "./views/ThemeProvider";
@@ -58,11 +70,19 @@ export * from "@tamagui/helpers";
58
70
  export {
59
71
  TextAncestorContext,
60
72
  TextAncestorProvider,
73
+ addMediaQueryListener,
74
+ configureMedia,
61
75
  createDOMProps,
62
76
  getConfig,
63
77
  getHasConfigured,
78
+ getMedia,
64
79
  getThemes,
65
80
  getTokens,
66
- onConfiguredOnce
81
+ mediaObjectToString,
82
+ mediaQueryConfig,
83
+ mediaState,
84
+ onConfiguredOnce,
85
+ removeMediaQueryListener,
86
+ useMedia
67
87
  };
68
88
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './styled'\nexport * from './types'\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport { createDOMProps } from '@tamagui/rnw'\n\nexport * from './helpers/calc'\nexport * from './helpers/createShallowUpdate'\nexport * from './helpers/getStackSize'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/getFont'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/startTransition'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useId'\nexport * from './hooks/useIsMounted'\nexport * from './hooks/useIsTouchDevice'\nexport * from './hooks/useMedia'\nexport * from './hooks/usePressable'\nexport * from './hooks/useTheme'\nexport * from './hooks/useIsSSR'\nexport * from './hooks/useUnmountEffect'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport { TextAncestorProvider, TextAncestorContext } from './views/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/ThemeReset'\nexport * from './views/FontLanguage'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/helpers'\n"],
5
- "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;",
4
+ "sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getHasConfigured, getConfig, getThemes, getTokens, onConfiguredOnce } from './conf'\n\nexport * from './constants/constants'\nexport * from './constants/platform'\nexport { createDOMProps } from '@tamagui/rnw'\n\nexport * from './helpers/calc'\nexport * from './helpers/createShallowUpdate'\nexport * from './helpers/getStackSize'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/getFont'\nexport * from './helpers/isObj'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/startTransition'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonInsideButtonContext'\n\nexport * from './hooks/useConstant'\nexport * from './hooks/useId'\nexport * from './hooks/useIsMounted'\nexport * from './hooks/useIsTouchDevice'\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n mediaObjectToString,\n addMediaQueryListener,\n removeMediaQueryListener,\n mediaQueryConfig,\n} from './hooks/useMedia'\nexport * from './hooks/usePressable'\nexport * from './hooks/useTheme'\nexport * from './hooks/useIsSSR'\nexport * from './hooks/useUnmountEffect'\nexport * from './hooks/useSafeRef'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport { TextAncestorProvider, TextAncestorContext } from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeInverse'\nexport * from './views/ThemeProvider'\nexport * from './views/ThemeReset'\nexport * from './views/FontLanguage'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/helpers'\n"],
5
+ "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,40 @@
1
+ import { getConfig } from "./conf";
2
+ import { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from "./helpers/themes";
3
+ const loadTheme = ({
4
+ name: themeName,
5
+ theme: themeIn,
6
+ insertCSS
7
+ }) => {
8
+ const config = getConfig();
9
+ if (!config) {
10
+ throw new Error(`Must run createTamagui once before loading theme`);
11
+ }
12
+ if (config.themes[themeName]) {
13
+ throw new Error(`Already defined theme "${themeName}", use updateTheme to change values`);
14
+ }
15
+ const theme = { ...themeIn };
16
+ for (const key in theme) {
17
+ ensureThemeVariable(theme, key);
18
+ }
19
+ const cssRules = getThemeCSSRules({
20
+ config,
21
+ themeName,
22
+ names: [themeName],
23
+ theme
24
+ });
25
+ const themeProxied = proxyThemeToParents(themeName, theme, config.themes);
26
+ config.themes[themeName] = themeProxied;
27
+ if (insertCSS && typeof document !== "undefined") {
28
+ const style = document.createElement("style");
29
+ style.appendChild(document.createTextNode(cssRules.join("\n")));
30
+ document.head.appendChild(style);
31
+ }
32
+ return {
33
+ theme: themeProxied,
34
+ cssRules
35
+ };
36
+ };
37
+ export {
38
+ loadTheme
39
+ };
40
+ //# sourceMappingURL=loadTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/loadTheme.ts"],
4
+ "sourcesContent": ["import { getConfig } from './conf'\nimport { ensureThemeVariable, getThemeCSSRules, proxyThemeToParents } from './helpers/themes'\nimport { ThemeObject } from './types'\n\nexport const loadTheme = ({\n name: themeName,\n theme: themeIn,\n insertCSS,\n}: {\n name: string\n theme: ThemeObject\n insertCSS?: boolean\n}) => {\n const config = getConfig()\n if (!config) {\n throw new Error(`Must run createTamagui once before loading theme`)\n }\n if (config.themes[themeName]) {\n throw new Error(`Already defined theme \"${themeName}\", use updateTheme to change values`)\n }\n const theme = { ...themeIn }\n for (const key in theme) {\n ensureThemeVariable(theme, key)\n }\n const cssRules = getThemeCSSRules({\n config,\n themeName,\n names: [themeName],\n theme,\n })\n const themeProxied = proxyThemeToParents(themeName, theme, config.themes)\n config.themes[themeName] = themeProxied\n\n if (insertCSS && typeof document !== 'undefined') {\n const style = document.createElement('style')\n style.appendChild(document.createTextNode(cssRules.join('\\n')))\n document.head.appendChild(style)\n }\n\n return {\n theme: themeProxied,\n cssRules,\n }\n}\n"],
5
+ "mappings": "AAAA;AACA;AAGO,MAAM,YAAY,CAAC;AAAA,EACxB,MAAM;AAAA,EACN,OAAO;AAAA,EACP;AAAA,MAKI;AACJ,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AACA,MAAI,OAAO,OAAO,YAAY;AAC5B,UAAM,IAAI,MAAM,0BAA0B,8CAA8C;AAAA,EAC1F;AACA,QAAM,QAAQ,EAAE,GAAG,QAAQ;AAC3B,aAAW,OAAO,OAAO;AACvB,wBAAoB,OAAO,GAAG;AAAA,EAChC;AACA,QAAM,WAAW,iBAAiB;AAAA,IAChC;AAAA,IACA;AAAA,IACA,OAAO,CAAC,SAAS;AAAA,IACjB;AAAA,EACF,CAAC;AACD,QAAM,eAAe,oBAAoB,WAAW,OAAO,OAAO,MAAM;AACxE,SAAO,OAAO,aAAa;AAE3B,MAAI,aAAa,OAAO,aAAa,aAAa;AAChD,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,YAAY,SAAS,eAAe,SAAS,KAAK,IAAI,CAAC,CAAC;AAC9D,aAAS,KAAK,YAAY,KAAK;AAAA,EACjC;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ import { addTheme } from "./addTheme";
2
+ import { activeThemeManagers } from "./hooks/useTheme";
3
+ function updateTheme({ name, theme }) {
4
+ const next = addTheme({ name, theme, insertCSS: true, update: true });
5
+ if (process.env.TAMAGUI_TARGET === "native") {
6
+ activeThemeManagers.forEach((manager) => {
7
+ if (manager.name === name) {
8
+ manager.update({
9
+ name,
10
+ theme: next.theme
11
+ }, true);
12
+ }
13
+ });
14
+ }
15
+ return next;
16
+ }
17
+ export {
18
+ updateTheme
19
+ };
20
+ //# sourceMappingURL=updateTheme.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/updateTheme.ts"],
4
+ "sourcesContent": ["import { addTheme } from './addTheme'\nimport { activeThemeManagers } from './hooks/useTheme'\nimport { ThemeObject } from './types'\n\nexport function updateTheme({ name, theme }: { name: string; theme: ThemeObject }) {\n const next = addTheme({ name, theme, insertCSS: true, update: true })\n\n if (process.env.TAMAGUI_TARGET === 'native') {\n activeThemeManagers.forEach((manager) => {\n if (manager.name === name) {\n manager.update(\n {\n name,\n theme: next.theme,\n },\n true\n )\n }\n })\n }\n\n return next\n}\n"],
5
+ "mappings": "AAAA;AACA;AAGO,qBAAqB,EAAE,MAAM,SAA+C;AACjF,QAAM,OAAO,SAAS,EAAE,MAAM,OAAO,WAAW,MAAM,QAAQ,KAAK,CAAC;AAEpE,MAAI,QAAQ,IAAI,mBAAmB,UAAU;AAC3C,wBAAoB,QAAQ,CAAC,YAAY;AACvC,UAAI,QAAQ,SAAS,MAAM;AACzB,gBAAQ,OACN;AAAA,UACE;AAAA,UACA,OAAO,KAAK;AAAA,QACd,GACA,IACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ const Pressability = {};
2
+ const usePressability = {};
3
+ export {
4
+ Pressability,
5
+ usePressability
6
+ };
7
+ //# sourceMappingURL=Pressability.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/vendor/Pressability.tsx"],
4
+ "sourcesContent": ["export const Pressability = {} as any\nexport const usePressability = {} as Function\n"],
5
+ "mappings": "AAAO,MAAM,eAAe,CAAC;AACtB,MAAM,kBAAkB,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ const Pressability = require("react-native/Libraries/Pressability/Pressability").default;
2
+ const usePressability = require("react-native/Libraries/Pressability/usePressability").default;
3
+ export {
4
+ Pressability,
5
+ usePressability
6
+ };
7
+ //# sourceMappingURL=Pressability.native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/vendor/Pressability.native.tsx"],
4
+ "sourcesContent": ["export const Pressability = require('react-native/Libraries/Pressability/Pressability').default\nexport const usePressability =\n require('react-native/Libraries/Pressability/usePressability').default\n"],
5
+ "mappings": "AAAO,MAAM,eAAe,QAAQ,kDAAkD,EAAE;AACjF,MAAM,kBACX,QAAQ,qDAAqD,EAAE;",
6
+ "names": []
7
+ }
@@ -31,7 +31,7 @@ const SlotClone = React.forwardRef((props, forwardedRef) => {
31
31
  const { children, ...slotProps } = props;
32
32
  if (React.isValidElement(children)) {
33
33
  const childProps = {
34
- ...mergeProps(children, slotProps),
34
+ ...mergeSlotProps(children, slotProps),
35
35
  ref: composeRefs(forwardedRef, children.ref)
36
36
  };
37
37
  return React.cloneElement(children, childProps);
@@ -50,7 +50,7 @@ const pressMap = isWeb ? {
50
50
  onPressOut: "onMouseUp",
51
51
  onPressIn: "onMouseDown"
52
52
  } : {};
53
- function mergeProps(child, slotProps) {
53
+ function mergeSlotProps(child, slotProps) {
54
54
  const childProps = child.props;
55
55
  const overrideProps = { ...childProps };
56
56
  const isHTMLChild = typeof child.type === "string";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/Slot.tsx"],
4
- "sourcesContent": ["// via radix\n\nimport { composeRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\nimport { isWeb } from '../constants/platform'\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type SlotProps = {\n children?: React.ReactNode\n}\n\nexport const Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n const childrenArray = React.Children.toArray(children)\n const slottable = childrenArray.find(isSlottable)\n\n if (slottable) {\n // the new element to render is the one passed as a child of `Slottable`\n const newElement = slottable.props.children as React.ReactNode\n\n const newChildren = childrenArray.map((child) => {\n if (child === slottable) {\n // because the new element will be the one rendered, we are only interested\n // in grabbing its children (`newElement.props.children`)\n if (React.Children.count(newElement) > 1) return React.Children.only(null)\n return React.isValidElement(newElement)\n ? (newElement.props.children as React.ReactNode)\n : null\n } else {\n return child\n }\n })\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {React.isValidElement(newElement)\n ? React.cloneElement(newElement, undefined, newChildren)\n : null}\n </SlotClone>\n )\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n )\n})\n\nSlot.displayName = 'Slot'\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n\n if (React.isValidElement(children)) {\n const childProps = {\n ...mergeProps(children, slotProps),\n ref: composeRefs(forwardedRef, (children as any).ref),\n }\n return React.cloneElement(children, childProps)\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null\n})\n\nSlotClone.displayName = 'SlotClone'\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable\n}\n\nconst pressMap = isWeb\n ? {\n onPress: 'onClick',\n onPressOut: 'onMouseUp',\n onPressIn: 'onMouseDown',\n }\n : {}\n\nfunction mergeProps(child: any, slotProps: AnyProps) {\n const childProps = child.props\n\n // all child props should override\n const overrideProps = { ...childProps }\n const isHTMLChild = typeof child.type === 'string'\n\n if (isHTMLChild) {\n for (const key in pressMap) {\n if (key in slotProps) {\n slotProps[pressMap[key]] = slotProps[key]\n delete slotProps[key]\n }\n }\n }\n\n for (let propName in childProps) {\n const slotPropValue = slotProps[propName]\n const childPropValue = childProps[propName]\n\n if (isHTMLChild && pressMap[propName]) {\n propName = pressMap[propName]\n delete overrideProps[propName]\n }\n\n const isHandler = handleRegex.test(propName)\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = mergeEvent(childPropValue, slotPropValue)\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue }\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ')\n }\n }\n\n return { ...slotProps, ...overrideProps }\n}\n\nconst handleRegex = /^on[A-Z]/\n\nexport function mergeEvent(a?: Function, b?: Function) {\n return (...args: unknown[]) => {\n a?.(...args)\n b?.(...args)\n }\n}\n"],
5
- "mappings": "AAEA;AACA;AAEA;AAUO,MAAM,OAAO,MAA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;AAEA,MAAM,WAAW,QACb;AAAA,EACE,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,WAAW;AACb,IACA,CAAC;AAEL,oBAAoB,OAAY,WAAqB;AACnD,QAAM,aAAa,MAAM;AAGzB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,QAAM,cAAc,OAAO,MAAM,SAAS;AAE1C,MAAI,aAAa;AACf,eAAW,OAAO,UAAU;AAC1B,UAAI,OAAO,WAAW;AACpB,kBAAU,SAAS,QAAQ,UAAU;AACrC,eAAO,UAAU;AAAA,MACnB;AAAA,IACF;AAAA,EACF;AAEA,WAAS,YAAY,YAAY;AAC/B,UAAM,gBAAgB,UAAU;AAChC,UAAM,iBAAiB,WAAW;AAElC,QAAI,eAAe,SAAS,WAAW;AACrC,iBAAW,SAAS;AACpB,aAAO,cAAc;AAAA,IACvB;AAEA,UAAM,YAAY,YAAY,KAAK,QAAQ;AAE3C,QAAI,WAAW;AACb,oBAAc,YAAY,WAAW,gBAAgB,aAAa;AAAA,IACpE,WAES,aAAa,SAAS;AAC7B,oBAAc,YAAY,EAAE,GAAG,eAAe,GAAG,eAAe;AAAA,IAClE,WAAW,aAAa,aAAa;AACnC,oBAAc,YAAY,CAAC,eAAe,cAAc,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,IACpF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,WAAW,GAAG,cAAc;AAC1C;AAEA,MAAM,cAAc;AAEb,oBAAoB,GAAc,GAAc;AACrD,SAAO,IAAI,SAAoB;AAC7B,2BAAI,GAAG;AACP,2BAAI,GAAG;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["// via radix\n\nimport { composeRefs } from '@tamagui/compose-refs'\nimport * as React from 'react'\n\nimport { isWeb } from '../constants/platform'\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type SlotProps = {\n children?: React.ReactNode\n}\n\nexport const Slot = React.forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n const childrenArray = React.Children.toArray(children)\n const slottable = childrenArray.find(isSlottable)\n\n if (slottable) {\n // the new element to render is the one passed as a child of `Slottable`\n const newElement = slottable.props.children as React.ReactNode\n\n const newChildren = childrenArray.map((child) => {\n if (child === slottable) {\n // because the new element will be the one rendered, we are only interested\n // in grabbing its children (`newElement.props.children`)\n if (React.Children.count(newElement) > 1) return React.Children.only(null)\n return React.isValidElement(newElement)\n ? (newElement.props.children as React.ReactNode)\n : null\n } else {\n return child\n }\n })\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {React.isValidElement(newElement)\n ? React.cloneElement(newElement, undefined, newChildren)\n : null}\n </SlotClone>\n )\n }\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {children}\n </SlotClone>\n )\n})\n\nSlot.displayName = 'Slot'\n\n/* -------------------------------------------------------------------------------------------------\n * SlotClone\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotCloneProps {\n children: React.ReactNode\n}\n\nconst SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n\n if (React.isValidElement(children)) {\n const childProps = {\n ...mergeSlotProps(children, slotProps),\n ref: composeRefs(forwardedRef, (children as any).ref),\n }\n return React.cloneElement(children, childProps)\n }\n\n return React.Children.count(children) > 1 ? React.Children.only(null) : null\n})\n\nSlotClone.displayName = 'SlotClone'\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Slottable = ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>\n\nfunction isSlottable(child: React.ReactNode): child is React.ReactElement {\n return React.isValidElement(child) && child.type === Slottable\n}\n\nconst pressMap = isWeb\n ? {\n onPress: 'onClick',\n onPressOut: 'onMouseUp',\n onPressIn: 'onMouseDown',\n }\n : {}\n\nfunction mergeSlotProps(child: any, slotProps: AnyProps) {\n const childProps = child.props\n\n // all child props should override\n const overrideProps = { ...childProps }\n const isHTMLChild = typeof child.type === 'string'\n\n if (isHTMLChild) {\n for (const key in pressMap) {\n if (key in slotProps) {\n slotProps[pressMap[key]] = slotProps[key]\n delete slotProps[key]\n }\n }\n }\n\n for (let propName in childProps) {\n const slotPropValue = slotProps[propName]\n const childPropValue = childProps[propName]\n\n if (isHTMLChild && pressMap[propName]) {\n propName = pressMap[propName]\n delete overrideProps[propName]\n }\n\n const isHandler = handleRegex.test(propName)\n // if it's a handler, modify the override by composing the base handler\n if (isHandler) {\n overrideProps[propName] = mergeEvent(childPropValue, slotPropValue)\n }\n // if it's `style`, we merge them\n else if (propName === 'style') {\n overrideProps[propName] = { ...slotPropValue, ...childPropValue }\n } else if (propName === 'className') {\n overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(' ')\n }\n }\n\n return { ...slotProps, ...overrideProps }\n}\n\nconst handleRegex = /^on[A-Z]/\n\nexport function mergeEvent(a?: Function, b?: Function) {\n return (...args: unknown[]) => {\n a?.(...args)\n b?.(...args)\n }\n}\n"],
5
+ "mappings": "AAEA;AACA;AAEA;AAUO,MAAM,OAAO,MAAM,WAAmC,CAAC,OAAO,iBAAiB;AACpF,QAAM,EAAE,aAAa,cAAc;AACnC,QAAM,gBAAgB,MAAM,SAAS,QAAQ,QAAQ;AACrD,QAAM,YAAY,cAAc,KAAK,WAAW;AAEhD,MAAI,WAAW;AAEb,UAAM,aAAa,UAAU,MAAM;AAEnC,UAAM,cAAc,cAAc,IAAI,CAAC,UAAU;AAC/C,UAAI,UAAU,WAAW;AAGvB,YAAI,MAAM,SAAS,MAAM,UAAU,IAAI;AAAG,iBAAO,MAAM,SAAS,KAAK,IAAI;AACzE,eAAO,MAAM,eAAe,UAAU,IACjC,WAAW,MAAM,WAClB;AAAA,MACN,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,WACE,oCAAC;AAAA,MAAW,GA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C,iBAAW,SAAS;AACpB,aAAO,cAAc;AAAA,IACvB;AAEA,UAAM,YAAY,YAAY,KAAK,QAAQ;AAE3C,QAAI,WAAW;AACb,oBAAc,YAAY,WAAW,gBAAgB,aAAa;AAAA,IACpE,WAES,aAAa,SAAS;AAC7B,oBAAc,YAAY,EAAE,GAAG,eAAe,GAAG,eAAe;AAAA,IAClE,WAAW,aAAa,aAAa;AACnC,oBAAc,YAAY,CAAC,eAAe,cAAc,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,IACpF;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,WAAW,GAAG,cAAc;AAC1C;AAEA,MAAM,cAAc;AAEb,oBAAoB,GAAc,GAAc;AACrD,SAAO,IAAI,SAAoB;AAC7B,2BAAI,GAAG;AACP,2BAAI,GAAG;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import React, { memo, useMemo } from "react";
2
2
  import { isWeb } from "../constants/platform";
3
+ import { ThemeManagerContext } from "../helpers/ThemeManager";
3
4
  import { useChangeThemeEffect } from "../hooks/useTheme";
4
- import { ThemeManagerContext } from "../ThemeManager";
5
5
  React["createElement"];
6
6
  const Theme = memo(function Theme2(props) {
7
7
  var _a, _b;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/Theme.tsx"],
4
- "sourcesContent": ["import React, { memo, useMemo } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeProps, useChangeThemeEffect } from '../hooks/useTheme'\nimport { ThemeManager, ThemeManagerContext } from '../ThemeManager'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport const Theme = memo(function Theme(props: ThemeProps) {\n const { name, theme, themeManager, themes, className } = useChangeThemeEffect(\n props.name,\n props.componentName,\n props\n )\n\n const missingTheme = !themes || !name || !theme\n\n // memo here, changing theme without re-rendering all children is a critical optimization\n // may require some effort of end user to memoize but without this memo they'd have no option\n const contents = useMemo(\n () => (missingTheme ? null : wrapThemeManagerContext(props.children, themeManager)),\n [props.children, themeManager]\n )\n\n if (missingTheme) {\n if (name && !theme && process.env.NODE_ENV === 'development') {\n console.warn(`No theme found by name ${name}`)\n }\n return props.children\n }\n\n if (isWeb) {\n return (\n <span\n className={(!props.disableThemeClass\n ? [props.className, className].filter(Boolean)\n : []\n ).join(' ')}\n style={{\n display: 'contents',\n // in order to provide currentColor, set color by default\n color: themes[name]?.color?.toString(),\n }}\n >\n {contents}\n </span>\n )\n }\n\n return contents\n})\n\nexport function wrapThemeManagerContext(\n children: any,\n themeManager?: ThemeManager | null,\n shouldSetChildrenThemeToParent?: boolean\n) {\n return themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {shouldSetChildrenThemeToParent ? (\n <Theme name={themeManager.parentName}>{children}</Theme>\n ) : (\n children\n )}\n </ThemeManagerContext.Provider>\n ) : (\n children\n )\n}\n"],
4
+ "sourcesContent": ["import React, { memo, useMemo } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManager, ThemeManagerContext } from '../helpers/ThemeManager'\nimport { ThemeProps, useChangeThemeEffect } from '../hooks/useTheme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport const Theme = memo(function Theme(props: ThemeProps) {\n const { name, theme, themeManager, themes, className } = useChangeThemeEffect(\n props.name,\n props.componentName,\n props\n )\n\n const missingTheme = !themes || !name || !theme\n\n // memo here, changing theme without re-rendering all children is a critical optimization\n // may require some effort of end user to memoize but without this memo they'd have no option\n const contents = useMemo(\n () => (missingTheme ? null : wrapThemeManagerContext(props.children, themeManager)),\n [props.children, themeManager]\n )\n\n if (missingTheme) {\n if (name && !theme && process.env.NODE_ENV === 'development') {\n console.warn(`No theme found by name ${name}`)\n }\n return props.children\n }\n\n if (isWeb) {\n return (\n <span\n className={(!props.disableThemeClass\n ? [props.className, className].filter(Boolean)\n : []\n ).join(' ')}\n style={{\n display: 'contents',\n // in order to provide currentColor, set color by default\n color: themes[name]?.color?.toString(),\n }}\n >\n {contents}\n </span>\n )\n }\n\n return contents\n})\n\nexport function wrapThemeManagerContext(\n children: any,\n themeManager?: ThemeManager | null,\n shouldSetChildrenThemeToParent?: boolean\n) {\n return themeManager ? (\n <ThemeManagerContext.Provider value={themeManager}>\n {shouldSetChildrenThemeToParent ? (\n <Theme name={themeManager.parentName}>{children}</Theme>\n ) : (\n children\n )}\n </ThemeManagerContext.Provider>\n ) : (\n children\n )\n}\n"],
5
5
  "mappings": "AAAA;AAEA;AACA;AACA;AAGA,MAAM;AAEC,MAAM,QAAQ,KAAK,gBAAe,OAAmB;AAT5D;AAUE,QAAM,EAAE,MAAM,OAAO,cAAc,QAAQ,cAAc,qBACvD,MAAM,MACN,MAAM,eACN,KACF;AAEA,QAAM,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC;AAI1C,QAAM,WAAW,QACf,MAAO,eAAe,OAAO,wBAAwB,MAAM,UAAU,YAAY,GACjF,CAAC,MAAM,UAAU,YAAY,CAC/B;AAEA,MAAI,cAAc;AAChB,QAAI,QAAQ,CAAC,SAAS,QAAQ,IAAI,aAAa,eAAe;AAC5D,cAAQ,KAAK,0BAA0B,MAAM;AAAA,IAC/C;AACA,WAAO,MAAM;AAAA,EACf;AAEA,MAAI,OAAO;AACT,WACE,oCAAC;AAAA,MACC,WAAY,EAAC,MAAM,oBACf,CAAC,MAAM,WAAW,SAAS,EAAE,OAAO,OAAO,IAC3C,CAAC,GACH,KAAK,GAAG;AAAA,MACV,OAAO;AAAA,QACL,SAAS;AAAA,QAET,OAAO,mBAAO,UAAP,mBAAc,UAAd,mBAAqB;AAAA,MAC9B;AAAA,OAEC,QACH;AAAA,EAEJ;AAEA,SAAO;AACT,CAAC;AAEM,iCACL,UACA,cACA,gCACA;AACA,SAAO,eACL,oCAAC,oBAAoB,UAApB;AAAA,IAA6B,OAAO;AAAA,KAClC,iCACC,oCAAC;AAAA,IAAM,MAAM,aAAa;AAAA,KAAa,QAAS,IAEhD,QAEJ,IAEA;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  import React, { useLayoutEffect, useMemo } from "react";
2
2
  import { getHasConfigured } from "../conf";
3
3
  import { THEME_CLASSNAME_PREFIX } from "../constants/constants";
4
- import { ThemeContext } from "../ThemeContext";
4
+ import { ThemeContext } from "../contexts/ThemeContext";
5
5
  import { Theme } from "./Theme";
6
6
  React["createElement"];
7
7
  const ThemeProvider = (props) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeProvider.tsx"],
4
- "sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
4
+ "sourcesContent": ["import React, { useLayoutEffect, useMemo } from 'react'\n\nimport { getHasConfigured } from '../conf'\nimport { THEME_CLASSNAME_PREFIX } from '../constants/constants'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\nexport type ThemeProviderProps = {\n className?: string\n themes: any\n defaultTheme: string\n disableRootThemeClass?: boolean\n themeClassNameOnRoot?: boolean\n children?: any\n reset?: boolean\n}\n\nexport const ThemeProvider = (props: ThemeProviderProps) => {\n if (!getHasConfigured()) {\n throw new Error(`Missing configureThemes() call, add to your root file`)\n }\n\n // ensure theme is attached to root body node as well to work with modals by default\n if (typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (props.disableRootThemeClass) {\n return\n }\n const cn = `${THEME_CLASSNAME_PREFIX}${props.defaultTheme}`\n const target = props.themeClassNameOnRoot ? document.documentElement : document.body\n target.classList.add(cn)\n return () => {\n target.classList.remove(cn)\n }\n }, [props.defaultTheme, props.disableRootThemeClass])\n }\n\n const themeContext = useMemo(() => {\n return {\n themes: props.themes,\n defaultTheme: props.defaultTheme,\n }\n }, [props.themes])\n\n return (\n <ThemeContext.Provider value={themeContext}>\n <Theme\n className={props.className}\n name={props.defaultTheme}\n disableThemeClass={props.disableRootThemeClass}\n >\n {props.children}\n </Theme>\n </ThemeContext.Provider>\n )\n}\n"],
5
5
  "mappings": "AAAA;AAEA;AACA;AACA;AACA;AAGA,MAAM;AAYC,MAAM,gBAAgB,CAAC,UAA8B;AAC1D,MAAI,CAAC,iBAAiB,GAAG;AACvB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAGA,MAAI,OAAO,aAAa,aAAa;AACnC,oBAAgB,MAAM;AACpB,UAAI,MAAM,uBAAuB;AAC/B;AAAA,MACF;AACA,YAAM,KAAK,GAAG,yBAAyB,MAAM;AAC7C,YAAM,SAAS,MAAM,uBAAuB,SAAS,kBAAkB,SAAS;AAChF,aAAO,UAAU,IAAI,EAAE;AACvB,aAAO,MAAM;AACX,eAAO,UAAU,OAAO,EAAE;AAAA,MAC5B;AAAA,IACF,GAAG,CAAC,MAAM,cAAc,MAAM,qBAAqB,CAAC;AAAA,EACtD;AAEA,QAAM,eAAe,QAAQ,MAAM;AACjC,WAAO;AAAA,MACL,QAAQ,MAAM;AAAA,MACd,cAAc,MAAM;AAAA,IACtB;AAAA,EACF,GAAG,CAAC,MAAM,MAAM,CAAC;AAEjB,SACE,oCAAC,aAAa,UAAb;AAAA,IAAsB,OAAO;AAAA,KAC5B,oCAAC;AAAA,IACC,WAAW,MAAM;AAAA,IACjB,MAAM,MAAM;AAAA,IACZ,mBAAmB,MAAM;AAAA,KAExB,MAAM,QACT,CACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import React, { useContext, useLayoutEffect, useState } from "react";
2
2
  import { isWeb } from "../constants/platform";
3
- import { ThemeManagerContext } from "../ThemeManager";
3
+ import { ThemeManagerContext } from "../helpers/ThemeManager";
4
4
  import { Theme } from "./Theme";
5
5
  React["createElement"];
6
6
  const ThemeReset = (props) => {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeReset.tsx"],
4
- "sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
4
+ "sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../helpers/ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
5
5
  "mappings": "AAAA;AAEA;AACA;AACA;AAGA,MAAM;AAGC,MAAM,aAAa,CAAC,UAA8B;AACvD,QAAM,eAAe,WAAW,mBAAmB;AACnD,QAAM,CAAC,MAAM,WAAW,SAAwB,IAAI;AAKpD,MAAI,CAAC,SAAS,OAAO,aAAa,aAAa;AAC7C,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,UAAI,SAAS,aAAa,YAAY;AACpC,gBAAQ,aAAa,UAAU;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,6CAAc,UAAU,CAAC;AAE7B,oBAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,aAAO,aAAa,cAAc,MAAM;AACtC,gBAAQ,aAAa,UAAU;AAAA,MACjC,CAAC;AAAA,IACH,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,MAAI,CAAC,gBAAgB,CAAC,MAAM,UAAU;AACpC,WAAO,MAAM,YAAY;AAAA,EAC3B;AAEA,SACE,oCAAC;AAAA,IAAM,WAAU;AAAA,IAAkB,OAAK;AAAA,IAAC;AAAA,KACtC,MAAM,QACT;AAEJ;",
6
6
  "names": []
7
7
  }