@tamagui/core 1.0.2 → 1.0.4

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 (117) hide show
  1. package/dist/cjs/config.js +1 -1
  2. package/dist/cjs/config.js.map +2 -2
  3. package/dist/cjs/createComponent.js +51 -95
  4. package/dist/cjs/createComponent.js.map +2 -2
  5. package/dist/cjs/createTamagui.js +7 -4
  6. package/dist/cjs/createTamagui.js.map +2 -2
  7. package/dist/cjs/createVariable.js +1 -1
  8. package/dist/cjs/createVariable.js.map +2 -2
  9. package/dist/cjs/createVariables.js +12 -3
  10. package/dist/cjs/createVariables.js.map +2 -2
  11. package/dist/cjs/helpers/ThemeManager.js +12 -2
  12. package/dist/cjs/helpers/ThemeManager.js.map +2 -2
  13. package/dist/cjs/helpers/getSize.js +9 -5
  14. package/dist/cjs/helpers/getSize.js.map +2 -2
  15. package/dist/cjs/helpers/getSplitStyles.js +39 -45
  16. package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
  17. package/dist/cjs/helpers/getStylesAtomic.js +32 -26
  18. package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
  19. package/dist/cjs/helpers/getStylesAtomic.native.js +6 -2
  20. package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
  21. package/dist/cjs/helpers/insertStyleRule.js +12 -1
  22. package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
  23. package/dist/cjs/helpers/normalizeColor.js +8 -7
  24. package/dist/cjs/helpers/normalizeColor.js.map +2 -2
  25. package/dist/cjs/hooks/useMedia.js +37 -36
  26. package/dist/cjs/hooks/useMedia.js.map +2 -2
  27. package/dist/cjs/hooks/useTheme.js +28 -42
  28. package/dist/cjs/hooks/useTheme.js.map +3 -3
  29. package/dist/cjs/index.js +0 -1
  30. package/dist/cjs/index.js.map +2 -2
  31. package/dist/cjs/styled.js +4 -1
  32. package/dist/cjs/styled.js.map +2 -2
  33. package/dist/cjs/types.js.map +1 -1
  34. package/dist/cjs/views/Slot.js +1 -33
  35. package/dist/cjs/views/Slot.js.map +3 -3
  36. package/dist/cjs/views/Stack.test.js +4 -6
  37. package/dist/cjs/views/Stack.test.js.map +2 -2
  38. package/dist/cjs/views/Theme.js +45 -41
  39. package/dist/cjs/views/Theme.js.map +2 -2
  40. package/dist/cjs/views/ThemeProvider.js +1 -1
  41. package/dist/cjs/views/ThemeProvider.js.map +2 -2
  42. package/dist/esm/config.js +1 -1
  43. package/dist/esm/config.js.map +2 -2
  44. package/dist/esm/createComponent.js +53 -97
  45. package/dist/esm/createComponent.js.map +2 -2
  46. package/dist/esm/createTamagui.js +8 -5
  47. package/dist/esm/createTamagui.js.map +2 -2
  48. package/dist/esm/createVariable.js +1 -1
  49. package/dist/esm/createVariable.js.map +2 -2
  50. package/dist/esm/createVariables.js +10 -2
  51. package/dist/esm/createVariables.js.map +2 -2
  52. package/dist/esm/helpers/ThemeManager.js +13 -3
  53. package/dist/esm/helpers/ThemeManager.js.map +2 -2
  54. package/dist/esm/helpers/getSize.js +9 -5
  55. package/dist/esm/helpers/getSize.js.map +2 -2
  56. package/dist/esm/helpers/getSplitStyles.js +39 -45
  57. package/dist/esm/helpers/getSplitStyles.js.map +2 -2
  58. package/dist/esm/helpers/getStylesAtomic.js +31 -26
  59. package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
  60. package/dist/esm/helpers/getStylesAtomic.native.js +4 -1
  61. package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
  62. package/dist/esm/helpers/insertStyleRule.js +12 -1
  63. package/dist/esm/helpers/insertStyleRule.js.map +2 -2
  64. package/dist/esm/helpers/normalizeColor.js +8 -7
  65. package/dist/esm/helpers/normalizeColor.js.map +2 -2
  66. package/dist/esm/hooks/useMedia.js +37 -37
  67. package/dist/esm/hooks/useMedia.js.map +2 -2
  68. package/dist/esm/hooks/useTheme.js +25 -39
  69. package/dist/esm/hooks/useTheme.js.map +3 -3
  70. package/dist/esm/index.js +0 -1
  71. package/dist/esm/index.js.map +2 -2
  72. package/dist/esm/styled.js +4 -1
  73. package/dist/esm/styled.js.map +2 -2
  74. package/dist/esm/views/Slot.js +1 -33
  75. package/dist/esm/views/Slot.js.map +3 -3
  76. package/dist/esm/views/Stack.test.js +1 -3
  77. package/dist/esm/views/Stack.test.js.map +2 -2
  78. package/dist/esm/views/Theme.js +44 -40
  79. package/dist/esm/views/Theme.js.map +2 -2
  80. package/dist/esm/views/ThemeProvider.js +1 -1
  81. package/dist/esm/views/ThemeProvider.js.map +2 -2
  82. package/package.json +11 -11
  83. package/reset.css +4 -0
  84. package/src/__snapshots__/createTokens.test.ts.snap +90 -195
  85. package/src/config.ts +1 -1
  86. package/src/createComponent.tsx +72 -152
  87. package/src/createTamagui.ts +8 -5
  88. package/src/createVariable.ts +2 -1
  89. package/src/createVariables.ts +14 -1
  90. package/src/helpers/ThemeManager.tsx +13 -3
  91. package/src/helpers/getSplitStyles.tsx +43 -53
  92. package/src/helpers/getStylesAtomic.native.ts +2 -0
  93. package/src/helpers/getStylesAtomic.ts +36 -31
  94. package/src/helpers/insertStyleRule.tsx +12 -2
  95. package/src/helpers/normalizeColor.ts +8 -7
  96. package/src/hooks/useMedia.tsx +53 -48
  97. package/src/hooks/useTheme.tsx +37 -56
  98. package/src/index.ts +0 -1
  99. package/src/styled.tsx +4 -1
  100. package/src/types.tsx +7 -3
  101. package/src/views/Slot.tsx +3 -59
  102. package/src/views/Stack.test.tsx +1 -4
  103. package/src/views/Theme.tsx +60 -54
  104. package/src/views/ThemeProvider.tsx +1 -1
  105. package/types/createVariables.d.ts +1 -0
  106. package/types/helpers/ThemeManager.d.ts +1 -1
  107. package/types/helpers/getSplitStyles.d.ts +2 -3
  108. package/types/helpers/getStylesAtomic.d.ts +1 -0
  109. package/types/helpers/getStylesAtomic.native.d.ts +1 -0
  110. package/types/hooks/useMedia.d.ts +8 -4
  111. package/types/hooks/useTheme.d.ts +16 -2
  112. package/types/index.d.ts +0 -1
  113. package/types/types.d.ts +3 -2
  114. package/types/views/Slot.d.ts +5 -4
  115. package/types/views/Theme.d.ts +5 -2
  116. package/src/helpers/cache.ts +0 -13
  117. package/src/helpers/getSize.ts +0 -23
@@ -1,9 +1,9 @@
1
- import { useEffect, useMemo, useSyncExternalStore } from "react";
1
+ import { startTransition, useEffect, useMemo, useSyncExternalStore } from "react";
2
2
  import { getConfig } from "../config";
3
3
  import { createProxy } from "../helpers/createProxy";
4
4
  import { matchMedia } from "../helpers/matchMedia";
5
5
  import { useSafeRef } from "./useSafeRef";
6
- const mediaState = process.env.NODE_ENV === "development" ? createProxy(
6
+ let mediaState = process.env.NODE_ENV === "development" ? createProxy(
7
7
  {},
8
8
  {
9
9
  get(target, key) {
@@ -62,7 +62,7 @@ function setupMediaListeners() {
62
62
  const next = !!getMatch().matches;
63
63
  if (next === mediaState[key])
64
64
  return;
65
- mediaState[key] = next;
65
+ mediaState = { ...mediaState, [key]: next };
66
66
  updateCurrentState();
67
67
  };
68
68
  var update = update2;
@@ -87,56 +87,56 @@ function useMediaListeners(config) {
87
87
  }, []);
88
88
  }
89
89
  const currentStateListeners = /* @__PURE__ */ new Set();
90
+ let isFlushing = false;
90
91
  function updateCurrentState() {
91
- currentStateListeners.forEach((cb) => cb(mediaState));
92
+ if (isFlushing)
93
+ return;
94
+ isFlushing = true;
95
+ setTimeout(() => {
96
+ startTransition(() => {
97
+ currentStateListeners.forEach((cb) => cb(mediaState));
98
+ });
99
+ isFlushing = false;
100
+ }, 0);
101
+ }
102
+ const shouldUpdate = /* @__PURE__ */ new WeakMap();
103
+ function setMediaShouldUpdate(ref, props) {
104
+ return shouldUpdate.set(ref, props);
92
105
  }
93
106
  function subscribe(subscriber) {
94
107
  currentStateListeners.add(subscriber);
95
108
  return () => currentStateListeners.delete(subscriber);
96
109
  }
97
- const shouldUpdate = /* @__PURE__ */ new WeakMap();
98
- function setMediaShouldUpdate(ref, val) {
99
- return shouldUpdate.set(ref, val);
100
- }
101
- const empty = {};
102
- let initialUseState;
103
- function useMedia() {
104
- initialUseState ||= {
105
- prev: initState,
106
- next: empty
107
- };
108
- const keys = useSafeRef(initialUseState);
110
+ function useMedia(uid, debug) {
111
+ const internal = useSafeRef(void 0);
112
+ if (!internal.current) {
113
+ internal.current = {
114
+ prev: initState
115
+ };
116
+ }
109
117
  const state = useSyncExternalStore(
110
118
  subscribe,
111
119
  () => {
112
- const curState = keys.current;
113
- const preventUpdate = arguments[0] && shouldUpdate.get(arguments[0]) !== true;
114
- if (preventUpdate) {
115
- return curState.prev;
116
- }
117
- let didUpdate = false;
118
- const next = {};
119
- for (const key in curState.next) {
120
- const val = mediaState[key];
121
- if (curState.prev[key] !== val) {
122
- didUpdate = true;
123
- }
124
- next[key] = val;
120
+ const { touched, prev } = internal.current;
121
+ const componentState = uid ? shouldUpdate.get(uid) : void 0;
122
+ if ((componentState == null ? void 0 : componentState.enabled) === false) {
123
+ return prev;
125
124
  }
126
- if (!didUpdate) {
127
- return curState.prev;
125
+ const testKeys = (componentState == null ? void 0 : componentState.keys) ?? ((componentState == null ? void 0 : componentState.enabled) && touched ? [...touched] : null);
126
+ if (testKeys == null ? void 0 : testKeys.every((key) => mediaState[key] === prev[key])) {
127
+ return prev;
128
128
  }
129
- keys.current = { next, prev: next };
130
- return next;
129
+ internal.current.prev = mediaState;
130
+ return mediaState;
131
131
  },
132
132
  () => initState
133
133
  );
134
134
  return useMemo(() => {
135
- return new Proxy(state === empty ? initState : state, {
135
+ return new Proxy(state, {
136
136
  get(_, key) {
137
- if (!(key in keys.current.next)) {
138
- keys.current.next[key] = true;
139
- keys.current = { ...keys.current };
137
+ if (typeof key === "string") {
138
+ internal.current.touched ||= /* @__PURE__ */ new Set();
139
+ internal.current.touched.add(key);
140
140
  }
141
141
  return Reflect.get(state, key);
142
142
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useMedia.tsx"],
4
- "sourcesContent": ["import { useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport const mediaState: MediaQueryState =\n // development only safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\nexport const mediaQueryConfig: MediaQueries = {}\nexport const getMedia = () => mediaState\nexport const mediaKeysWithAndWithout$ = new Set<string>()\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) => {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n throw new Error('use short key')\n }\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n return mediaKeysOrdered.indexOf(key) + 2\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n mediaKeysWithAndWithout$.add(key)\n mediaKeysWithAndWithout$.add(`$${key}`)\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) return\n configuredKey = nextKey\n\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(() => {\n match.removeListener(update)\n })\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n updateCurrentState()\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n }, [])\n}\n\nconst currentStateListeners = new Set<any>()\nfunction updateCurrentState() {\n currentStateListeners.forEach((cb) => cb(mediaState))\n}\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\ntype UseMediaState = {\n [key in MediaQueryKey]: boolean\n}\n\nconst shouldUpdate = new WeakMap<any, boolean>()\nexport function setMediaShouldUpdate(ref: any, val: boolean) {\n return shouldUpdate.set(ref, val)\n}\n\ntype UseMediaInternalState = { prev: MediaKeysState; next: MediaKeysState }\nconst empty = {}\nlet initialUseState: UseMediaInternalState\n\nexport function useMedia(): UseMediaState {\n // setup once\n initialUseState ||= {\n prev: initState,\n next: empty,\n }\n\n const keys = useSafeRef<UseMediaInternalState>(initialUseState)\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const curState = keys.current\n const preventUpdate = arguments[0] && shouldUpdate.get(arguments[0]) !== true\n if (preventUpdate) {\n return curState.prev\n }\n\n let didUpdate = false\n\n // ensure we keep the minimal object of only used keys\n const next = {}\n\n for (const key in curState.next) {\n const val = mediaState[key]\n if (curState.prev[key] !== val) {\n didUpdate = true\n }\n next[key] = val\n }\n\n if (!didUpdate) {\n return curState.prev\n }\n\n keys.current = { next, prev: next }\n return next\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state === empty ? initState : state, {\n get(_, key: string) {\n if (!(key in keys.current.next)) {\n keys.current.next[key] = true\n keys.current = { ...keys.current }\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, is will loop props and trigger re-render on all media queries.\n *\n * */\nexport function useMediaPropsActive<A extends Object>(\n props: A\n): {\n // remove all media\n [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key]\n} {\n const media = useMedia()\n\n return useMemo(() => {\n const next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const mediaKey = key.slice(1)\n if (!media[mediaKey]) continue\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, '', key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport const getMediaImportanceIfMoreImportant = (\n mediaKey: string,\n key: string,\n importancesUsed: Record<string, number>\n) => {\n const importance = getMediaKeyImportance(mediaKey)\n return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n mediaKey: string,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)\n if (importance === null) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\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,SAAS,WAAW,SAAS,4BAA4B;AAEzD,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAQ3B,SAAS,kBAAkB;AAEpB,MAAM,aAEX,QAAQ,IAAI,aAAa,gBACrB;AAAA,EACE,CAAC;AAAA,EACD;AAAA,IACE,IAAI,QAAQ,KAAK;AACf,UACE,OAAO,QAAQ,YACf,IAAI,OAAO,OAEX,IAAI,OAAO,KACX;AACA,cAAM,IAAI,MAAM,yCAAyC,KAAK;AAAA,MAChE;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAED,MAAM,mBAAiC,CAAC;AACxC,MAAM,WAAW,MAAM;AACvB,MAAM,2BAA2B,oBAAI,IAAY;AAGxD,IAAI;AACG,MAAM,uBAAuB,MAAM;AACxC,UAAQ,UAAU,EAAE,aAAa,aAAa,cAAc,CAAC;AAC/D;AAEA,IAAI;AACG,MAAM,wBAAwB,CAAC,QAAgB;AACpD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,IAAI,OAAO,KAAK;AAC5D,UAAM,IAAI,MAAM,eAAe;AAAA,EACjC;AAEA,SAAO,iBAAiB,QAAQ,GAAG,IAAI;AACzC;AAEA,MAAM,UAAU,oBAAI,IAAc;AAE3B,MAAM,iBAAiB,CAAC,WAAkC;AAC/D,QAAM,EAAE,OAAO,wBAAwB,IAAI;AAC3C,MAAI,CAAC;AAAO;AACZ,aAAW,OAAO,OAAO;AACvB,eAAW,QAAO,mEAA0B,SAAQ;AACpD,6BAAyB,IAAI,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ACzB,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 { startTransition, useEffect, useMemo, useSyncExternalStore } from 'react'\n\nimport { getConfig } from '../config'\nimport { createProxy } from '../helpers/createProxy'\nimport { matchMedia } from '../helpers/matchMedia'\nimport {\n MediaQueries,\n MediaQueryKey,\n MediaQueryObject,\n MediaQueryState,\n TamaguiInternalConfig,\n} from '../types'\nimport { useSafeRef } from './useSafeRef'\n\nexport let mediaState: MediaQueryState =\n // development only safeguard\n process.env.NODE_ENV === 'development'\n ? createProxy(\n {},\n {\n get(target, key) {\n if (\n typeof key === 'string' &&\n key[0] === '$' &&\n // dont error on $$typeof\n key[1] !== '$'\n ) {\n throw new Error(`Access mediaState should not use \"$\": ${key}`)\n }\n return Reflect.get(target, key)\n },\n }\n )\n : ({} as any)\n\nexport const mediaQueryConfig: MediaQueries = {}\nexport const getMedia = () => mediaState\nexport const mediaKeysWithAndWithout$ = new Set<string>()\n\n// for SSR capture it at time of startup\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? mediaState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) => {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n throw new Error('use short key')\n }\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n return mediaKeysOrdered.indexOf(key) + 2\n}\n\nconst dispose = new Set<Function>()\n\nexport const configureMedia = (config: TamaguiInternalConfig) => {\n const { media, mediaQueryDefaultActive } = config\n if (!media) return\n for (const key in media) {\n mediaState[key] = mediaQueryDefaultActive?.[key] || false\n mediaKeysWithAndWithout$.add(key)\n mediaKeysWithAndWithout$.add(`$${key}`)\n }\n Object.assign(mediaQueryConfig, media)\n initState = { ...mediaState }\n updateCurrentState()\n mediaKeysOrdered = Object.keys(media)\n if (config.disableSSR) {\n setupMediaListeners()\n }\n}\n\nfunction unlisten() {\n dispose.forEach((cb) => cb())\n dispose.clear()\n}\n\n/**\n * Note: This should *not* set the state on the first render!\n * Because to avoid hydration issues SSR must match the server\n * *and then* re-render with the actual media query state.\n */\nlet configuredKey = ''\nfunction setupMediaListeners() {\n // avoid setting up more than once per config\n const nextKey = JSON.stringify(mediaQueryConfig)\n if (nextKey === configuredKey) return\n configuredKey = nextKey\n\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(() => {\n match.removeListener(update)\n })\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState = { ...mediaState, [key]: next }\n updateCurrentState()\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n }, [])\n}\n\nconst currentStateListeners = new Set<any>()\nlet isFlushing = false\n\nfunction updateCurrentState() {\n if (isFlushing) return\n isFlushing = true\n setTimeout(() => {\n startTransition(() => {\n currentStateListeners.forEach((cb) => cb(mediaState))\n })\n isFlushing = false\n }, 0)\n}\n\ntype MediaKeysState = {\n [key: string]: any\n}\n\ntype UseMediaState = {\n [key in MediaQueryKey]: boolean\n}\n\ntype UpdateState = {\n enabled: boolean\n keys: MediaQueryKey[]\n}\n\nconst shouldUpdate = new WeakMap<any, UpdateState>()\n\nexport function setMediaShouldUpdate(ref: any, props: UpdateState) {\n return shouldUpdate.set(ref, props)\n}\n\ntype UseMediaInternalState = {\n prev: MediaKeysState\n touched?: Set<string>\n}\n\nfunction subscribe(subscriber: any) {\n currentStateListeners.add(subscriber)\n return () => currentStateListeners.delete(subscriber)\n}\n\nexport function useMedia(uid?: any, debug?: any): UseMediaState {\n const internal = useSafeRef<UseMediaInternalState>(undefined as any)\n if (!internal.current) {\n internal.current = {\n prev: initState,\n }\n }\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const { touched, prev } = internal.current\n const componentState = uid ? shouldUpdate.get(uid) : undefined\n if (componentState?.enabled === false) {\n return prev\n }\n const testKeys =\n componentState?.keys ?? (componentState?.enabled && touched ? [...touched] : null)\n\n if (testKeys?.every((key) => mediaState[key] === prev[key])) {\n return prev\n }\n\n internal.current.prev = mediaState\n return mediaState\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state, {\n get(_, key) {\n if (typeof key === 'string') {\n internal.current.touched ||= new Set()\n internal.current.touched.add(key)\n }\n return Reflect.get(state, key)\n },\n })\n }, [state])\n}\n\n/**\n * Useful for more complex components that need access to the currently active props,\n * accounting for the currently active media queries.\n *\n * Use sparingly, it will loop props and trigger re-render on all media queries.\n *\n * */\nexport function useMediaPropsActive<A extends Object>(\n props: A\n): {\n // remove all media\n [Key in keyof A extends `$${string}` ? never : keyof A]?: A[Key]\n} {\n const media = useMedia()\n\n return useMemo(() => {\n const next = {} as A\n const importancesUsed = {}\n const propNames = Object.keys(props)\n\n for (let i = propNames.length - 1; i >= 0; i--) {\n const key = propNames[i]\n const val = props[key]\n if (key[0] === '$') {\n const mediaKey = key.slice(1)\n if (!media[mediaKey]) continue\n if (val && typeof val === 'object') {\n const subKeys = Object.keys(val)\n for (let j = subKeys.length; j--; j >= 0) {\n const subKey = subKeys[j]\n mergeMediaByImportance(next, mediaKey, subKey, val[subKey], importancesUsed)\n }\n }\n } else {\n mergeMediaByImportance(next, '', key, val, importancesUsed)\n }\n }\n\n return next\n }, [media, props])\n}\n\nexport const getMediaImportanceIfMoreImportant = (\n mediaKey: string,\n key: string,\n importancesUsed: Record<string, number>\n) => {\n const importance = getMediaKeyImportance(mediaKey)\n return !importancesUsed[key] || importance > importancesUsed[key] ? importance : null\n}\n\nexport function mergeMediaByImportance(\n onto: Record<string, any>,\n mediaKey: string,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaImportanceIfMoreImportant(mediaKey, key, importancesUsed)\n if (importance === null) {\n return false\n }\n importancesUsed[key] = importance\n onto[key] = value\n return true\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,SAAS,iBAAiB,WAAW,SAAS,4BAA4B;AAE1E,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,kBAAkB;AAQ3B,SAAS,kBAAkB;AAEpB,IAAI,aAET,QAAQ,IAAI,aAAa,gBACrB;AAAA,EACE,CAAC;AAAA,EACD;AAAA,IACE,IAAI,QAAQ,KAAK;AACf,UACE,OAAO,QAAQ,YACf,IAAI,OAAO,OAEX,IAAI,OAAO,KACX;AACA,cAAM,IAAI,MAAM,yCAAyC,KAAK;AAAA,MAChE;AACA,aAAO,QAAQ,IAAI,QAAQ,GAAG;AAAA,IAChC;AAAA,EACF;AACF,IACC,CAAC;AAED,MAAM,mBAAiC,CAAC;AACxC,MAAM,WAAW,MAAM;AACvB,MAAM,2BAA2B,oBAAI,IAAY;AAGxD,IAAI;AACG,MAAM,uBAAuB,MAAM;AACxC,UAAQ,UAAU,EAAE,aAAa,aAAa,cAAc,CAAC;AAC/D;AAEA,IAAI;AACG,MAAM,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S,uBACd,MACA,UACA,KACA,OACA,iBACA;AACA,QAAM,aAAa,kCAAkC,UAAU,KAAK,eAAe;AACnF,MAAI,eAAe,MAAM;AACvB,WAAO;AAAA,EACT;AACA,kBAAgB,OAAO;AACvB,OAAK,OAAO;AACZ,SAAO;AACT;AAEA,SAAS,cAAc,KAAa;AAClC,SAAO,IAAI,QAAQ,UAAU,CAAC,MAAM,IAAI,EAAE,YAAY,GAAG,EAAE,YAAY;AACzE;AAEO,SAAS,oBAAoB,OAAkC;AACpE,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AACA,SAAO,OAAO,QAAQ,KAAK,EACxB,IAAI,CAAC,CAAC,SAAS,KAAK,MAAM;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": ["update"]
7
7
  }
@@ -20,10 +20,11 @@ function getDefaultThemeProxied() {
20
20
  });
21
21
  }
22
22
  const useTheme = (props = emptyProps) => {
23
+ var _a;
24
+ return (isRSC ? null : (_a = useThemeWithState(props)) == null ? void 0 : _a.theme) || getDefaultThemeProxied();
25
+ };
26
+ const useThemeWithState = (props) => {
23
27
  var _a, _b;
24
- if (isRSC) {
25
- return getDefaultThemeProxied();
26
- }
27
28
  const state = useServerRef();
28
29
  if (isClient && !state.current) {
29
30
  state.current = {
@@ -31,11 +32,15 @@ const useTheme = (props = emptyProps) => {
31
32
  };
32
33
  }
33
34
  (_a = state.current) == null ? void 0 : _a.keys.clear();
34
- const { name, theme, themeManager, className, isNewTheme } = useChangeThemeEffect(
35
+ const changedTheme = useChangeThemeEffect(
35
36
  props,
36
37
  false,
37
- isClient ? () => state.current.keys.size === 0 : void 0
38
+ isClient ? () => {
39
+ var _a2;
40
+ return ((_a2 = props.shouldUpdate) == null ? void 0 : _a2.call(props)) ?? state.current.keys.size === 0;
41
+ } : void 0
38
42
  );
43
+ const { themeManager, isNewTheme, theme, name, className } = changedTheme;
39
44
  if (process.env.NODE_ENV === "development") {
40
45
  if (isWeb && isNewTheme && className === ((_b = themeManager == null ? void 0 : themeManager.parentManager) == null ? void 0 : _b.state.className)) {
41
46
  console.error("Should always change, duplicating ThemeMananger bug", themeManager);
@@ -49,29 +54,23 @@ const useTheme = (props = emptyProps) => {
49
54
  console.groupEnd();
50
55
  }
51
56
  }
52
- if (!theme) {
57
+ if (!changedTheme.theme) {
53
58
  if (process.env.NODE_ENV === "development") {
54
59
  console.warn("No theme found", name, props, themeManager);
55
60
  }
56
- return getDefaultThemeProxied();
61
+ return null;
57
62
  }
58
- return useMemo(() => {
59
- return getThemeProxied({
60
- isNewTheme,
61
- theme,
62
- name,
63
- className,
64
- themeManager,
65
- state
66
- });
63
+ const proxiedTheme = useMemo(() => {
64
+ return getThemeProxied(changedTheme);
67
65
  }, [theme, isNewTheme, name, className, themeManager]);
66
+ return {
67
+ ...changedTheme,
68
+ theme: proxiedTheme
69
+ };
68
70
  };
69
71
  function getThemeProxied({
70
72
  theme,
71
- name,
72
- className,
73
73
  themeManager,
74
- isNewTheme,
75
74
  state
76
75
  }) {
77
76
  return createProxy(theme, {
@@ -86,21 +85,12 @@ function getThemeProxied({
86
85
  get(_, key) {
87
86
  if (key === GetThemeUnwrapped) {
88
87
  return theme;
89
- } else if (key === GetThemeManager) {
90
- return themeManager;
91
- } else if (key === GetIsNewTheme) {
92
- return isNewTheme;
93
- } else if (key === "name") {
94
- return name;
95
- } else if (key === "className") {
96
- return className;
97
- } else if (!name || key === "__proto__" || typeof key === "symbol" || key === "$typeof") {
88
+ }
89
+ if (key === "undefined" || key === "__proto__" || key === "$typeof" || typeof key !== "string" || !themeManager) {
98
90
  return Reflect.get(_, key);
99
91
  }
100
- if (key[0] === "$")
92
+ if (key[0] === "$") {
101
93
  key = key.slice(1);
102
- if (!themeManager) {
103
- return theme[key];
104
94
  }
105
95
  const val = themeManager.getValue(key);
106
96
  if (val && state) {
@@ -119,10 +109,6 @@ function getThemeProxied({
119
109
  }
120
110
  });
121
111
  }
122
- const GetThemeManager = Symbol();
123
- const GetIsNewTheme = Symbol();
124
- const getThemeManager = (theme) => theme == null ? void 0 : theme[GetThemeManager];
125
- const getThemeIsNewTheme = (theme) => theme == null ? void 0 : theme[GetIsNewTheme];
126
112
  const activeThemeManagers = /* @__PURE__ */ new Set();
127
113
  const useChangeThemeEffect = (props, root = false, disableUpdate) => {
128
114
  if (isRSC) {
@@ -138,7 +124,7 @@ const useChangeThemeEffect = (props, root = false, disableUpdate) => {
138
124
  } = props;
139
125
  if (disable) {
140
126
  if (!parentManager)
141
- throw new Error("Disable topmost");
127
+ throw `\u274C`;
142
128
  return {
143
129
  ...parentManager.state,
144
130
  isNewTheme: false,
@@ -213,9 +199,9 @@ const useChangeThemeEffect = (props, root = false, disableUpdate) => {
213
199
  };
214
200
  export {
215
201
  activeThemeManagers,
216
- getThemeIsNewTheme,
217
- getThemeManager,
202
+ getThemeProxied,
218
203
  useChangeThemeEffect,
219
- useTheme
204
+ useTheme,
205
+ useThemeWithState
220
206
  };
221
207
  //# sourceMappingURL=useTheme.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useTheme.tsx"],
4
- "sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n ThemeManager,\n ThemeManagerState,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport type ChangedThemeResponse = {\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\ninterface UseThemeState {\n keys: Set<string>\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n if (isRSC) {\n return getDefaultThemeProxied()\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (isClient && !state.current) {\n state.current = {\n keys: new Set(),\n }\n }\n state.current?.keys.clear()\n\n const { name, theme, themeManager, className, isNewTheme } = useChangeThemeEffect(\n props,\n false,\n isClient ? () => state.current.keys.size === 0 : undefined\n )\n\n if (process.env.NODE_ENV === 'development') {\n // ensure we aren't creating too many ThemeManagers\n if (\n isWeb &&\n isNewTheme &&\n className === themeManager?.parentManager?.state.className\n ) {\n console.error('Should always change, duplicating ThemeMananger bug', themeManager)\n }\n if (props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n }\n\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return getDefaultThemeProxied()\n }\n\n return useMemo(() => {\n return getThemeProxied({\n isNewTheme,\n theme,\n name,\n className,\n themeManager,\n state,\n })\n }, [theme, isNewTheme, name, className, themeManager])\n}\n\nfunction getThemeProxied({\n theme,\n name,\n className,\n themeManager,\n isNewTheme,\n state,\n}: {\n theme: any\n name: string\n className?: string\n themeManager?: ThemeManager | null\n isNewTheme?: boolean\n state?: React.RefObject<UseThemeState>\n}) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n } else if (key === GetThemeManager) {\n return themeManager\n } else if (key === GetIsNewTheme) {\n return isNewTheme\n } else if (key === 'name') {\n return name\n } else if (key === 'className') {\n return className\n } else if (\n !name ||\n key === '__proto__' ||\n typeof key === 'symbol' ||\n key === '$typeof'\n ) {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') key = key.slice(1)\n if (!themeManager) {\n return theme[key]\n }\n const val = themeManager.getValue(key)\n if (val && state) {\n if (isClient) {\n return new Proxy(val as any, {\n get(_, subkey) {\n if (subkey === 'val') {\n state.current!.keys.add(key as any)\n }\n return Reflect.get(val, subkey)\n },\n })\n }\n }\n return val\n },\n })\n}\n\nconst GetThemeManager = Symbol()\nconst GetIsNewTheme = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined =>\n theme?.[GetThemeManager]\nexport const getThemeIsNewTheme = (theme: any): ThemeManager | undefined =>\n theme?.[GetIsNewTheme]\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n ...createState().state,\n themeManager: null,\n }\n }\n const parentManager = useContext(ThemeManagerContext)\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw new Error('Disable topmost')\n return {\n ...parentManager.state,\n isNewTheme: false,\n themeManager: parentManager,\n }\n }\n\n type State = {\n isNewTheme: boolean\n state: ThemeManagerState\n themeManager: ThemeManager\n mounted?: boolean\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { isNewTheme, state, themeManager, mounted } = themeState\n\n if (!isServer) {\n useEffect(() => {\n if (disable) return\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n activeThemeManagers.add(themeManager)\n // const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n // // console.log('hi', props, state, name, manager)\n // if (state.theme !== manager.state.theme) {\n // console.warn('now update to', manager.state.name)\n // updateState(manager)\n // }\n // })\n return () => {\n activeThemeManagers.delete(themeManager)\n // disposeChangeListener?.()\n }\n }, [disable, state, isNewTheme, debug])\n }\n\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = hasNoThemeUpdatingProps(props) || isInversingOnMount\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('useTheme hasNoThemeUpdatingProps', parentManager.state.name, 'isInversingOnMount', isInversingOnMount)\n return {\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n isNewTheme: false,\n }\n }\n\n // run inline in render\n updateState()\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State) {\n if (prev && disableUpdate?.()) {\n return prev\n }\n // returns previous theme manager if no change\n const _ = new ThemeManager(props, root ? 'root' : parentManager)\n const isNewTheme = _ !== parentManager\n // prettier-ignore\n\n // if (prev?.isNewTheme && _.state.theme !== parentManager?.state.theme) {\n // console.warn('notify')\n // _.notify()\n // }\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n return {\n // ThemeManager returns parentManager if no change\n isNewTheme,\n state: { ..._.state },\n themeManager: _,\n mounted,\n }\n }\n\n function updateState(updatingManager?: ThemeManager) {\n if (disableUpdate?.()) {\n return\n }\n const manager = updatingManager ?? themeManager\n const next = manager.getState(props, parentManager)\n const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null)\n // console.log(`got it`, next, isNewTheme, shouldChange, { ...updatingManager?.state })\n if (shouldChange) {\n setThemeState(createState)\n } else {\n if (!next && parentManager?.state.name !== state.name) {\n // were changing back to parent state\n setThemeState(createState)\n }\n }\n }\n}\n"],
5
- "mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,SAAS,gBAAgB;AAEzD,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAU7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAMO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAxCzE;AAyCE,MAAI,OAAO;AACT,WAAO,uBAAuB;AAAA,EAChC;AAEA,QAAM,QAAQ,aAAa;AAC3B,MAAI,YAAY,CAAC,MAAM,SAAS;AAC9B,UAAM,UAAU;AAAA,MACd,MAAM,oBAAI,IAAI;AAAA,IAChB;AAAA,EACF;AACA,cAAM,YAAN,mBAAe,KAAK;AAEpB,QAAM,EAAE,MAAM,OAAO,cAAc,WAAW,WAAW,IAAI;AAAA,IAC3D;AAAA,IACA;AAAA,IACA,WAAW,MAAM,MAAM,QAAQ,KAAK,SAAS,IAAI;AAAA,EACnD;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,QACE,SACA,cACA,gBAAc,kDAAc,kBAAd,mBAA6B,MAAM,YACjD;AACA,cAAQ,MAAM,uDAAuD,YAAY;AAAA,IACnF;AACA,QAAI,MAAM,UAAU,WAAW;AAC7B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,GA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AAA,IAC3B,OAAO;AACL,UAAI,CAAC,SAAQ,+CAAe,MAAM,UAAS,MAAM,MAAM;AAErD,sBAAc,WAAW;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;",
6
- "names": ["_", "isNewTheme", "mounted"]
4
+ "sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n ThemeManager,\n ThemeManagerState,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport type ChangedThemeResponse = {\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\ninterface UseThemeState {\n keys: Set<string>\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (isClient && !state.current) {\n state.current = {\n keys: new Set(),\n }\n }\n\n // clear at start of every render to track usages\n state.current?.keys.clear()\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? state.current.keys.size === 0\n }\n : undefined\n )\n\n const { themeManager, isNewTheme, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development') {\n // ensure we aren't creating too many ThemeManagers\n // prettier-ignore\n if (isWeb && isNewTheme && className === themeManager?.parentManager?.state.className) {\n console.error('Should always change, duplicating ThemeMananger bug', themeManager)\n }\n if (props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any)\n }, [theme, isNewTheme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied({\n theme,\n themeManager,\n state,\n}: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n state?: React.RefObject<UseThemeState>\n}) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === 'undefined' ||\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n const val = themeManager.getValue(key)\n if (val && state) {\n if (isClient) {\n return new Proxy(val as any, {\n get(_, subkey) {\n if (subkey === 'val') {\n state.current!.keys.add(key as any)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n }\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n ...createState().state,\n themeManager: null,\n }\n }\n const parentManager = useContext(ThemeManagerContext)\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n ...parentManager.state,\n isNewTheme: false,\n themeManager: parentManager,\n }\n }\n\n type State = {\n isNewTheme: boolean\n state: ThemeManagerState\n themeManager: ThemeManager\n mounted?: boolean\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { isNewTheme, state, themeManager, mounted } = themeState\n\n if (!isServer) {\n useEffect(() => {\n if (disable) return\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n activeThemeManagers.add(themeManager)\n // const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n // // console.log('hi', props, state, name, manager)\n // if (state.theme !== manager.state.theme) {\n // console.warn('now update to', manager.state.name)\n // updateState(manager)\n // }\n // })\n return () => {\n activeThemeManagers.delete(themeManager)\n // disposeChangeListener?.()\n }\n }, [disable, state, isNewTheme, debug])\n }\n\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = hasNoThemeUpdatingProps(props) || isInversingOnMount\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') console.log('useTheme hasNoThemeUpdatingProps', parentManager.state.name, 'isInversingOnMount', isInversingOnMount)\n return {\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n isNewTheme: false,\n }\n }\n\n // run inline in render\n updateState()\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State) {\n if (prev && disableUpdate?.()) {\n return prev\n }\n // returns previous theme manager if no change\n const _ = new ThemeManager(props, root ? 'root' : parentManager)\n const isNewTheme = _ !== parentManager\n // prettier-ignore\n\n // if (prev?.isNewTheme && _.state.theme !== parentManager?.state.theme) {\n // console.warn('notify')\n // _.notify()\n // }\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n return {\n // ThemeManager returns parentManager if no change\n isNewTheme,\n state: { ..._.state },\n themeManager: _,\n mounted,\n }\n }\n\n function updateState(updatingManager?: ThemeManager) {\n if (disableUpdate?.()) {\n return\n }\n const manager = updatingManager ?? themeManager\n const next = manager.getState(props, parentManager)\n const shouldChange = manager.getStateShouldChange(next, isNewTheme ? state : null)\n // console.log(`got it`, next, isNewTheme, shouldChange, { ...updatingManager?.state })\n if (shouldChange) {\n setThemeState(createState)\n } else {\n if (!next && parentManager?.state.name !== state.name) {\n // were changing back to parent state\n setThemeState(createState)\n }\n }\n }\n}\n"],
5
+ "mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,SAAS,gBAAgB;AAEzD,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAU7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO;AAAA,IACrB;AAAA,EACF,CAAC;AACH;AAMO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAxCzE;AAyCE,UAAQ,QAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AA5CxD;AA6CE,QAAM,QAAQ,aAAa;AAC3B,MAAI,YAAY,CAAC,MAAM,SAAS;AAC9B,UAAM,UAAU;AAAA,MACd,MAAM,oBAAI,IAAI;AAAA,IAChB;AAAA,EACF;AAGA,cAAM,YAAN,mBAAe,KAAK;AAEpB,QAAM,eA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AQ,qBAAqB,MAAM,aAAa,QAAQ,IAAI;AAEjF,QAAI,cAAc;AAChB,oBAAc,WAAW;AAAA,IAC3B,OAAO;AACL,UAAI,CAAC,SAAQ,+CAAe,MAAM,UAAS,MAAM,MAAM;AAErD,sBAAc,WAAW;AAAA,MAC3B;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["_a", "_", "isNewTheme", "mounted"]
7
7
  }
package/dist/esm/index.js CHANGED
@@ -19,7 +19,6 @@ export * from "./helpers/useShallowSetState";
19
19
  export * from "./helpers/getVariantExtras";
20
20
  export * from "./helpers/getAnimationDriver";
21
21
  export * from "./helpers/getExpandedShorthands";
22
- export * from "./helpers/getSize";
23
22
  export * from "./helpers/getSplitStyles";
24
23
  export * from "./helpers/getStylesAtomic";
25
24
  export * from "./helpers/pseudoDescriptors";
@@ -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 './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config'\n\nexport * from './constants/constants'\n\nexport * from './helpers/useShallowSetState'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getAnimationDriver'\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/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonNestingContext'\n\nexport * from './hooks/useId'\nexport * from './hooks/useIsTouchDevice'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n mediaQueryConfig,\n} from './hooks/useMedia'\nexport * from './hooks/useTheme'\nexport * from './hooks/useThemeName'\nexport * from './hooks/useSafeRef'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeProvider'\nexport * from './views/FontLanguage'\nexport * from './views/TamaguiProvider'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,SAAS,WAAW,WAAW,WAAW,wBAAwB;AAElE,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AAEd,cAAc;AACd,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
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'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config'\n\nexport * from './constants/constants'\n\nexport * from './helpers/useShallowSetState'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getAnimationDriver'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonNestingContext'\n\nexport * from './hooks/useId'\nexport * from './hooks/useIsTouchDevice'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n mediaQueryConfig,\n} from './hooks/useMedia'\nexport * from './hooks/useTheme'\nexport * from './hooks/useThemeName'\nexport * from './hooks/useSafeRef'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeProvider'\nexport * from './views/FontLanguage'\nexport * from './views/TamaguiProvider'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,SAAS,WAAW,WAAW,WAAW,wBAAwB;AAElE,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AAEd,cAAc;AACd,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,10 @@ import { stylePropsAll } from "@tamagui/helpers";
2
2
  import { createComponent } from "./createComponent";
3
3
  import { ReactNativeStaticConfigs } from "./setupReactNative";
4
4
  function styled(Component, options, staticExtractionOptions) {
5
- if (process.env.NODE_ENV === "development") {
5
+ if (process.env.NODE_ENV !== "production") {
6
+ if (!Component) {
7
+ throw new Error(`No component given to styled()`);
8
+ }
6
9
  if (options == null ? void 0 : options.variants) {
7
10
  for (const key in options.variants) {
8
11
  if (key in stylePropsAll) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/styled.tsx"],
4
- "sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\n\nimport { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV === 'development') {\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`\n )\n }\n }\n }\n }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative ||\n staticExtractionOptions?.isReactNative\n )\n const isTamagui = !isReactNative && !!parentStaticConfig\n\n const Comp = isReactNative\n ? parentStaticConfig?.Component || Component\n : (Component as any)\n const nativeConf = (isReactNative && ReactNativeStaticConfigs.get(Comp)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
5
- "mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;AAYA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,mCAAS,UAAU;AACrB,iBAAW,OAAO,QAAQ,UAAU;AAClC,YAAI,OAAO,eAAe;AACxB,kBAAQ;AAAA,YACN,gDAAgD;AAAA,UAClD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBAAqB,MAAM;AAC/B,UAAM,qBACJ,kBAAkB,YAAa,UAAU,eAAgC;AAE3E,QAAI,SAAS;AACX,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,WACf;AAAA,MACL,IAAI;AACJ,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AACA,YAAM,gBAAgB;AAAA,QACpB,yBAAyB,IAAI,SAAS,KACpC,yBAAyB,IAAI,yDAAoB,SAAS,MAC1D,yDAAoB,mBACpB,mEAAyB;AAAA,MAC7B;AACA,YAAM,YAAY,CAAC,iBAAiB,CAAC,CAAC;AAEtC,YAAM,OAAO,iBACT,yDAAoB,cAAa,YAChC;AACL,YAAM,aAAc,iBAAiB,yBAAyB,IAAI,IAAI,KAAM;AAE5E,YAAM,SAAS;AAAA,SACb,mEAAyB,YAAU,yDAAoB;AAAA,MACzD;AACA,YAAM,mBAAmB,yBAAyB,aAAa;AAE/D,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,aAAa;AAAA,UAChB,WAAW;AAAA,QACb;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAGA,UAAI,aAAa,YAAY,CAAC,kBAAkB;AAC9C,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AACA,WAAO,CAAC;AAAA,EACV,GAAG;AAEH,QAAM,YAAY,gBAAgB,mBAAmB,SAAS;AAqC9D,SAAO;AACT;",
4
+ "sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\n\nimport { createComponent } from './createComponent'\nimport { ReactNativeStaticConfigs } from './setupReactNative'\nimport {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\n// can't infer from styled(<YStack />) which would be nice\n// * excessively deep type instantiation\n\ntype GetBaseProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetBaseProps<A['type']> :\n A extends TamaguiComponent<any, any, infer P> ? P : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> =\n // A extends TamaguiReactElement\n // ? GetVariantProps<A['type']>\n // :\n A extends TamaguiComponent<any, any, any, infer V> ? V : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n Component: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // allows passing styled(<H1 bc=\"red\" />)\n // but to get types right would be tricky\n // if (isValidElement(Component) && isTamaguiComponent(Component.type)) {\n // const props = Component.props\n // if (props && typeof props === 'object') {\n // Component = Component.type as any\n // options = options ? ({ ...props, ...options } as any) : props\n // }\n // }\n\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV !== 'production') {\n if (!Component) {\n throw new Error(`No component given to styled()`)\n }\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce implementation complexity.`\n )\n }\n }\n }\n }\n\n const staticConfigProps = (() => {\n const parentStaticConfig =\n 'staticConfig' in Component ? (Component.staticConfig as StaticConfig) : null\n\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative ||\n staticExtractionOptions?.isReactNative\n )\n const isTamagui = !isReactNative && !!parentStaticConfig\n\n const Comp = isReactNative\n ? parentStaticConfig?.Component || Component\n : (Component as any)\n const nativeConf = (isReactNative && ReactNativeStaticConfigs.get(Comp)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName = acceptsClassNameProp ?? (isTamagui || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isTamagui && {\n Component: Comp,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n return {}\n })()\n\n const component = createComponent(staticConfigProps, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
5
+ "mappings": "AAAA,SAAS,qBAAqB;AAE9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAoClC,SAAS,OAId,WAEA,SAOA,yBACA;AAYA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,WAAW;AACd,YAAM,I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
  }
@@ -7,35 +7,7 @@ import {
7
7
  forwardRef,
8
8
  isValidElement
9
9
  } from "react";
10
- const Slot = forwardRef((props, forwardedRef) => {
11
- const { children, ...slotProps } = props;
12
- const childrenArray = Children.toArray(children);
13
- const slottable = childrenArray.find(isSlottable);
14
- if (slottable) {
15
- const newElement = slottable.props.children;
16
- const newChildren = childrenArray.map((child) => {
17
- if (child === slottable) {
18
- if (Children.count(newElement) > 1)
19
- return Children.only(null);
20
- return isValidElement(newElement) ? newElement.props.children : null;
21
- } else {
22
- return child;
23
- }
24
- });
25
- return /* @__PURE__ */ jsx(SlotClone, {
26
- ...slotProps,
27
- ref: forwardedRef,
28
- children: isValidElement(newElement) ? cloneElement(newElement, void 0, newChildren) : null
29
- });
30
- }
31
- return /* @__PURE__ */ jsx(SlotClone, {
32
- ...slotProps,
33
- ref: forwardedRef,
34
- children
35
- });
36
- });
37
- Slot.displayName = "Slot";
38
- const SlotClone = forwardRef((props, forwardedRef) => {
10
+ const Slot = forwardRef(function Slot2(props, forwardedRef) {
39
11
  const { children, ...slotProps } = props;
40
12
  if (isValidElement(children)) {
41
13
  const childProps = {
@@ -46,15 +18,11 @@ const SlotClone = forwardRef((props, forwardedRef) => {
46
18
  }
47
19
  return Children.count(children) > 1 ? Children.only(null) : null;
48
20
  });
49
- SlotClone.displayName = "SlotClone";
50
21
  const Slottable = ({ children }) => {
51
22
  return /* @__PURE__ */ jsx(Fragment, {
52
23
  children
53
24
  });
54
25
  };
55
- function isSlottable(child) {
56
- return isValidElement(child) && child.type === Slottable;
57
- }
58
26
  const pressMap = isWeb ? {
59
27
  onPress: "onClick",
60
28
  onPressOut: "onMouseUp",
@@ -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 { isWeb } from '@tamagui/constants'\nimport {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n forwardRef,\n isValidElement,\n} from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\nexport type SlotProps = {\n children?: ReactNode\n}\n\nexport const Slot = forwardRef<HTMLElement, SlotProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n const childrenArray = 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 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 (Children.count(newElement) > 1) return Children.only(null)\n return isValidElement(newElement)\n ? (newElement.props.children as ReactNode)\n : null\n } else {\n return child\n }\n })\n\n return (\n <SlotClone {...slotProps} ref={forwardedRef}>\n {isValidElement(newElement)\n ? 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: ReactNode\n}\n\nconst SlotClone = forwardRef<any, SlotCloneProps>((props, forwardedRef) => {\n const { children, ...slotProps } = props\n\n if (isValidElement(children)) {\n const childProps = {\n ...mergeSlotProps(children, slotProps),\n ref: composeRefs(forwardedRef, (children as any).ref),\n }\n return cloneElement(children, childProps)\n }\n\n return Children.count(children) > 1 ? Children.only(null) : null\n})\n\nSlotClone.displayName = 'SlotClone'\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Slottable = ({ children }: { children: ReactNode }) => {\n return <>{children}</>\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\ntype AnyProps = Record<string, any>\n\nfunction isSlottable(child: ReactNode): child is ReactElement {\n return 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": "AA4CM,SA8CG,UA9CH;AA1CN,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,MAAM,OAAO,WAAmC,CAAC,OAAO,iBAAiB;AAC9E,QAAM,EAAE,aAAa,UAAU,IAAI;AACnC,QAAM,gBAAgB,SAAS,QAAQ,QAAQ;AAC/C,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,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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,SAAS,WAAW,GAAc,GAAc;AACrD,SAAO,IAAI,SAAoB;AAC7B,2BAAI,GAAG;AACP,2BAAI,GAAG;AAAA,EACT;AACF;",
6
- "names": []
4
+ "sourcesContent": ["// via radix\n\nimport { composeRefs } from '@tamagui/compose-refs'\nimport { isWeb } from '@tamagui/constants'\nimport {\n Children,\n ReactElement,\n ReactNode,\n cloneElement,\n forwardRef,\n isValidElement,\n} from 'react'\n\n/* -------------------------------------------------------------------------------------------------\n * Slot\n * -----------------------------------------------------------------------------------------------*/\n\ninterface SlotProps {\n children: ReactNode\n}\n\nexport const Slot = forwardRef<any, SlotProps>(function Slot(props, forwardedRef) {\n const { children, ...slotProps } = props\n\n if (isValidElement(children)) {\n const childProps = {\n ...mergeSlotProps(children, slotProps),\n ref: composeRefs(forwardedRef, (children as any).ref),\n }\n return cloneElement(children, childProps)\n }\n\n return Children.count(children) > 1 ? Children.only(null) : null\n})\n\n/* -------------------------------------------------------------------------------------------------\n * Slottable\n * -----------------------------------------------------------------------------------------------*/\n\nexport const Slottable = ({ children }: { children: ReactNode }) => {\n return <>{children}</>\n}\n\n/* ---------------------------------------------------------------------------------------------- */\n\nconst pressMap = isWeb\n ? {\n onPress: 'onClick',\n onPressOut: 'onMouseUp',\n onPressIn: 'onMouseDown',\n }\n : {}\n\nfunction mergeSlotProps(child: any, slotProps: Record<string, any>) {\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": "AAwCS;AAtCT,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,MAAM,OAAO,WAA2B,SAASA,MAAK,OAAO,cAAc;AAChF,QAAM,EAAE,aAAa,UAAU,IAAI;AAEnC,MAAI,eAAe,QAAQ,GAAG;AAC5B,UAAM,aAAa;AAAA,MACjB,GAAG,eAAe,UAAU,SAAS;AAAA,MACrC,KAAK,YAAY,cAAe,SAAiB,G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;",
6
+ "names": ["Slot"]
7
7
  }
@@ -3,9 +3,7 @@ process.env.TAMAGUI_TARGET = "web";
3
3
  import { getDefaultTamaguiConfig } from "@tamagui/config-default-node";
4
4
  import { render } from "@testing-library/react";
5
5
  import { describe, expect, test } from "vitest";
6
- import { createTamagui } from "../createTamagui";
7
- import { Stack } from "./Stack";
8
- import { TamaguiProvider } from "./TamaguiProvider";
6
+ import { Stack, TamaguiProvider, createTamagui } from "..";
9
7
  const conf = createTamagui(getDefaultTamaguiConfig());
10
8
  const TestStackRenders = ({
11
9
  renderCount,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/Stack.test.tsx"],
4
- "sourcesContent": ["process.env.TAMAGUI_TARGET = 'web'\n\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport { render } from '@testing-library/react'\nimport { describe, expect, test } from 'vitest'\n\nimport { createTamagui } from '../createTamagui'\nimport { Stack } from './Stack'\nimport { TamaguiProvider } from './TamaguiProvider'\nimport { StackProps, configureMedia } from '..'\n\nconst conf = createTamagui(getDefaultTamaguiConfig())\n\nconst TestStackRenders = ({\n renderCount,\n ...props\n}: StackProps & { renderCount: { current: number } }) => {\n return (\n <TamaguiProvider config={conf} defaultTheme=\"light\">\n <Stack data-test-renders={renderCount} {...props} />\n </TamaguiProvider>\n )\n}\n\ndescribe('Stack', () => {\n test('renders once', async () => {\n const renderCount = { current: 0 }\n render(<TestStackRenders renderCount={renderCount} />)\n expect(renderCount.current).toBe(1)\n })\n\n // test(`doesn't re-render on media query change if CSS`, async () => {\n // const renderCount = { current: 0 }\n\n // render(\n // <TestStackRenders\n // renderCount={renderCount}\n // backgroundColor=\"blue\"\n // $sm={{ backgroundColor: 'red' }}\n // />\n // )\n\n // expect(renderCount.current).toBe(1)\n\n // // re-configuring re-runs the media queries...\n // configureMedia(conf)\n\n // expect(renderCount.current).toBe(1)\n // })\n\n // test(`does re-render on media query change if not CSS`, async () => {\n // const renderCount = { current: 0 }\n\n // render(\n // <TestStackRenders\n // renderCount={renderCount}\n // backgroundColor=\"blue\"\n // // @ts-ignore\n // $sm={{ space: '$2' }}\n // />\n // )\n\n // expect(renderCount.current).toBe(1)\n\n // // re-configuring re-runs the media queries...\n // // configureMedia({\n // // ...conf,\n // // media: {\n // // def\n // // },\n // // })\n // // expect(renderCount.current).toBe(2)\n // })\n})\n"],
5
- "mappings": "AAmBM;AAnBN,QAAQ,IAAI,iBAAiB;AAE7B,SAAS,+BAA+B;AACxC,SAAS,cAAc;AACvB,SAAS,UAAU,QAAQ,YAAY;AAEvC,SAAS,qBAAqB;AAC9B,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAGhC,MAAM,OAAO,cAAc,wBAAwB,CAAC;AAEpD,MAAM,mBAAmB,CAAC;AAAA,EACxB;AAAA,KACG;AACL,MAAyD;AACvD,SACE,oBAAC;AAAA,IAAgB,QAAQ;AAAA,IAAM,cAAa;AAAA,IAC1C,8BAAC;AAAA,MAAM,qBAAmB;AAAA,MAAc,GAAG;AAAA,KAAO;AAAA,GACpD;AAEJ;AAEA,SAAS,SAAS,MAAM;AACtB,OAAK,gBAAgB,YAAY;AAC/B,UAAM,cAAc,EAAE,SAAS,EAAE;AACjC,WAAO,oBAAC;AAAA,MAAiB;AAAA,KAA0B,CAAE;AACrD,WAAO,YAAY,OAAO,EAAE,KAAK,CAAC;AAAA,EACpC,CAAC;AA4CH,CAAC;",
4
+ "sourcesContent": ["process.env.TAMAGUI_TARGET = 'web'\n\nimport { getDefaultTamaguiConfig } from '@tamagui/config-default-node'\nimport { render } from '@testing-library/react'\nimport { describe, expect, test } from 'vitest'\n\nimport { Stack, StackProps, TamaguiProvider, createTamagui } from '..'\n\nconst conf = createTamagui(getDefaultTamaguiConfig())\n\nconst TestStackRenders = ({\n renderCount,\n ...props\n}: StackProps & { renderCount: { current: number } }) => {\n return (\n <TamaguiProvider config={conf} defaultTheme=\"light\">\n <Stack data-test-renders={renderCount} {...props} />\n </TamaguiProvider>\n )\n}\n\ndescribe('Stack', () => {\n test('renders once', async () => {\n const renderCount = { current: 0 }\n render(<TestStackRenders renderCount={renderCount} />)\n expect(renderCount.current).toBe(1)\n })\n\n // test(`doesn't re-render on media query change if CSS`, async () => {\n // const renderCount = { current: 0 }\n\n // render(\n // <TestStackRenders\n // renderCount={renderCount}\n // backgroundColor=\"blue\"\n // $sm={{ backgroundColor: 'red' }}\n // />\n // )\n\n // expect(renderCount.current).toBe(1)\n\n // // re-configuring re-runs the media queries...\n // configureMedia(conf)\n\n // expect(renderCount.current).toBe(1)\n // })\n\n // test(`does re-render on media query change if not CSS`, async () => {\n // const renderCount = { current: 0 }\n\n // render(\n // <TestStackRenders\n // renderCount={renderCount}\n // backgroundColor=\"blue\"\n // // @ts-ignore\n // $sm={{ space: '$2' }}\n // />\n // )\n\n // expect(renderCount.current).toBe(1)\n\n // // re-configuring re-runs the media queries...\n // // configureMedia({\n // // ...conf,\n // // media: {\n // // def\n // // },\n // // })\n // // expect(renderCount.current).toBe(2)\n // })\n})\n"],
5
+ "mappings": "AAgBM;AAhBN,QAAQ,IAAI,iBAAiB;AAE7B,SAAS,+BAA+B;AACxC,SAAS,cAAc;AACvB,SAAS,UAAU,QAAQ,YAAY;AAEvC,SAAS,OAAmB,iBAAiB,qBAAqB;AAElE,MAAM,OAAO,cAAc,wBAAwB,CAAC;AAEpD,MAAM,mBAAmB,CAAC;AAAA,EACxB;AAAA,KACG;AACL,MAAyD;AACvD,SACE,oBAAC;AAAA,IAAgB,QAAQ;AAAA,IAAM,cAAa;AAAA,IAC1C,8BAAC;AAAA,MAAM,qBAAmB;AAAA,MAAc,GAAG;AAAA,KAAO;AAAA,GACpD;AAEJ;AAEA,SAAS,SAAS,MAAM;AACtB,OAAK,gBAAgB,YAAY;AAC/B,UAAM,cAAc,EAAE,SAAS,EAAE;AACjC,WAAO,oBAAC;AAAA,MAAiB;AAAA,KAA0B,CAAE;AACrD,WAAO,YAAY,OAAO,EAAE,KAAK,CAAC;AAAA,EACpC,CAAC;AA4CH,CAAC;",
6
6
  "names": []
7
7
  }