@tamagui/core 1.0.1-beta.216 → 1.0.1-beta.218

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 (50) hide show
  1. package/dist/cjs/createComponent.js +43 -90
  2. package/dist/cjs/createComponent.js.map +2 -2
  3. package/dist/cjs/createTamagui.js +2 -2
  4. package/dist/cjs/createTamagui.js.map +1 -1
  5. package/dist/cjs/helpers/getSplitStyles.js +48 -38
  6. package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
  7. package/dist/cjs/helpers/getStylesAtomic.js +2 -4
  8. package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
  9. package/dist/cjs/helpers/mergeProps.js.map +2 -2
  10. package/dist/cjs/helpers/normalizeValueWithProperty.js +7 -2
  11. package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
  12. package/dist/cjs/helpers/useShallowSetState.js.map +2 -2
  13. package/dist/cjs/hooks/useMedia.js +35 -38
  14. package/dist/cjs/hooks/useMedia.js.map +2 -2
  15. package/dist/cjs/hooks/useTheme.js +28 -12
  16. package/dist/cjs/hooks/useTheme.js.map +2 -2
  17. package/dist/cjs/views/ThemeInverse.js +1 -2
  18. package/dist/cjs/views/ThemeInverse.js.map +2 -2
  19. package/dist/esm/createComponent.js +45 -96
  20. package/dist/esm/createComponent.js.map +2 -2
  21. package/dist/esm/createTamagui.js +2 -2
  22. package/dist/esm/createTamagui.js.map +1 -1
  23. package/dist/esm/helpers/getSplitStyles.js +48 -38
  24. package/dist/esm/helpers/getSplitStyles.js.map +3 -3
  25. package/dist/esm/helpers/getStylesAtomic.js +2 -4
  26. package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
  27. package/dist/esm/helpers/mergeProps.js.map +2 -2
  28. package/dist/esm/helpers/normalizeValueWithProperty.js +7 -2
  29. package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
  30. package/dist/esm/helpers/useShallowSetState.js.map +2 -2
  31. package/dist/esm/hooks/useMedia.js +36 -39
  32. package/dist/esm/hooks/useMedia.js.map +2 -2
  33. package/dist/esm/hooks/useTheme.js +28 -12
  34. package/dist/esm/hooks/useTheme.js.map +2 -2
  35. package/dist/esm/views/ThemeInverse.js +1 -2
  36. package/dist/esm/views/ThemeInverse.js.map +2 -2
  37. package/package.json +16 -16
  38. package/src/createComponent.tsx +58 -115
  39. package/src/createTamagui.ts +2 -2
  40. package/src/helpers/getSplitStyles.tsx +47 -37
  41. package/src/helpers/getStylesAtomic.ts +2 -4
  42. package/src/helpers/mergeProps.ts +7 -7
  43. package/src/helpers/normalizeValueWithProperty.ts +9 -2
  44. package/src/helpers/useShallowSetState.tsx +3 -1
  45. package/src/hooks/useMedia.tsx +42 -42
  46. package/src/hooks/useTheme.tsx +35 -20
  47. package/src/views/ThemeInverse.tsx +1 -2
  48. package/types/helpers/mergeProps.d.ts +2 -2
  49. package/types/helpers/useShallowSetState.d.ts +2 -1
  50. package/types/hooks/useTheme.d.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/helpers/useShallowSetState.tsx"],
4
- "sourcesContent": ["import React, { useCallback } from 'react'\n\nexport function useShallowSetState<State extends Object>(\n setter: React.Dispatch<React.SetStateAction<State>>,\n debug?: boolean | 'verbose',\n debugName?: string\n) {\n return useCallback(\n (next: Partial<State>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n if (process.env.NODE_ENV === 'development') {\n if (debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log(` \u25B2 setState ${debugName}`, next)\n }\n }\n return { ...prev, ...next }\n }\n }\n return prev\n })\n },\n [setter]\n )\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AAE5B,SAAS,mBACd,QACA,OACA,WACA;AACA,aAAO;AAAA,IACL,CAAC,SAAyB;AACxB,aAAO,CAAC,SAAS;AACf,mBAAW,OAAO,MAAM;AACtB,cAAI,KAAK,SAAS,KAAK,MAAM;AAC3B,gBAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,kBAAI,UAAU,WAAW;AAEvB,wBAAQ,IAAI,oBAAe,aAAa,IAAI;AAAA,cAC9C;AAAA,YACF;AACA,mBAAO,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,UAC5B;AAAA,QACF;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;",
4
+ "sourcesContent": ["import React, { useCallback } from 'react'\n\nimport { DebugProp } from '../types'\n\nexport function useShallowSetState<State extends Object>(\n setter: React.Dispatch<React.SetStateAction<State>>,\n debug?: DebugProp,\n debugName?: string\n) {\n return useCallback(\n (next: Partial<State>) => {\n setter((prev) => {\n for (const key in next) {\n if (prev[key] !== next[key]) {\n if (process.env.NODE_ENV === 'development') {\n if (debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.log(` \u25B2 setState ${debugName}`, next)\n }\n }\n return { ...prev, ...next }\n }\n }\n return prev\n })\n },\n [setter]\n )\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAmC;AAI5B,SAAS,mBACd,QACA,OACA,WACA;AACA,aAAO;AAAA,IACL,CAAC,SAAyB;AACxB,aAAO,CAAC,SAAS;AACf,mBAAW,OAAO,MAAM;AACtB,cAAI,KAAK,SAAS,KAAK,MAAM;AAC3B,gBAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,kBAAI,UAAU,WAAW;AAEvB,wBAAQ,IAAI,oBAAe,aAAa,IAAI;AAAA,cAC9C;AAAA,YACF;AACA,mBAAO,EAAE,GAAG,MAAM,GAAG,KAAK;AAAA,UAC5B;AAAA,QACF;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACF;",
6
6
  "names": []
7
7
  }
@@ -33,7 +33,6 @@ __export(useMedia_exports, {
33
33
  useMediaPropsActive: () => useMediaPropsActive
34
34
  });
35
35
  module.exports = __toCommonJS(useMedia_exports);
36
- var import_constants = require("@tamagui/constants");
37
36
  var import_react = require("react");
38
37
  var import_config = require("../config");
39
38
  var import_createProxy = require("../helpers/createProxy");
@@ -64,13 +63,10 @@ function removeMediaQueryListener(key, cb) {
64
63
  (_a = listeners[key]) == null ? void 0 : _a.delete(cb);
65
64
  }
66
65
  const mediaQueryConfig = {};
67
- const getMedia = () => {
68
- return mediaState;
69
- };
70
- let curState;
66
+ const getMedia = () => mediaState;
71
67
  let initState;
72
68
  const getInitialMediaState = () => {
73
- return ((0, import_config.getConfig)().disableSSR ? curState : initState) || {};
69
+ return ((0, import_config.getConfig)().disableSSR ? mediaState : initState) || {};
74
70
  };
75
71
  let mediaKeysOrdered;
76
72
  const getMediaKeyImportance = (key) => mediaKeysOrdered.indexOf(key[0] === "$" ? key.slice(1) : key) + 2;
@@ -83,8 +79,8 @@ const configureMedia = (config) => {
83
79
  mediaState[key] = (mediaQueryDefaultActive == null ? void 0 : mediaQueryDefaultActive[key]) || false;
84
80
  }
85
81
  Object.assign(mediaQueryConfig, media);
86
- curState = { ...mediaState };
87
- initState = curState;
82
+ initState = { ...mediaState };
83
+ updateCurrentState();
88
84
  mediaKeysOrdered = Object.keys(media);
89
85
  if (config.disableSSR) {
90
86
  setupMediaListeners();
@@ -108,7 +104,7 @@ function setupMediaListeners() {
108
104
  if (next === mediaState[key])
109
105
  return;
110
106
  mediaState[key] = next;
111
- curState = { ...mediaState };
107
+ updateCurrentState();
112
108
  const cur = listeners[key];
113
109
  if (cur == null ? void 0 : cur.size) {
114
110
  cur.forEach((cb) => cb(next));
@@ -134,39 +130,40 @@ function useMediaListeners(config) {
134
130
  return unlisten;
135
131
  }, []);
136
132
  }
133
+ const currentStateListeners = /* @__PURE__ */ new Set();
134
+ function updateCurrentState() {
135
+ currentStateListeners.forEach((cb) => cb(mediaState));
136
+ }
137
+ function subscribe(subscriber) {
138
+ currentStateListeners.add(subscriber);
139
+ return () => currentStateListeners.delete(subscriber);
140
+ }
137
141
  function useMedia() {
138
- const keys = (0, import_useSafeRef.useSafeRef)({});
139
- const [state, setState] = (0, import_react.useState)(() => getMediaState(initState || {}, keys));
140
- function updateState() {
141
- setState((prev) => {
142
- for (const key in keys.current) {
143
- if (prev[key] !== mediaState[key]) {
144
- return getMediaState({ ...mediaState }, keys);
145
- }
142
+ const keys = (0, import_useSafeRef.useSafeRef)({ prev: initState });
143
+ const state = (0, import_react.useSyncExternalStore)(
144
+ subscribe,
145
+ () => {
146
+ const { prev, ...curKeys } = keys.current;
147
+ const shouldUpdate = !prev || Object.keys(curKeys).some((k) => mediaState[k] !== prev[k]);
148
+ if (shouldUpdate) {
149
+ const next = { ...mediaState };
150
+ keys.current.prev = next;
151
+ return next;
146
152
  }
147
153
  return prev;
148
- });
149
- }
150
- (0, import_constants.useIsomorphicLayoutEffect)(() => {
151
- updateState();
152
- const disposers = Object.keys(keys.current).map(
153
- (key) => addMediaQueryListener(key, updateState)
154
- );
155
- return () => {
156
- disposers.forEach((cb) => cb());
157
- };
158
- }, [keys.current]);
159
- return state;
160
- }
161
- function getMediaState(state, keys) {
162
- return new Proxy(state, {
163
- get(_, key) {
164
- if (!keys.current[key]) {
165
- keys.current[key] = true;
154
+ },
155
+ () => initState
156
+ );
157
+ return (0, import_react.useMemo)(() => {
158
+ return new Proxy(state, {
159
+ get(_, key) {
160
+ if (!keys.current[key]) {
161
+ keys.current[key] = true;
162
+ }
163
+ return Reflect.get(state, key);
166
164
  }
167
- return Reflect.get(state, key);
168
- }
169
- });
165
+ });
166
+ }, [state]);
170
167
  }
171
168
  function useMediaPropsActive(props) {
172
169
  const media = useMedia();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useMedia.tsx"],
4
- "sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { MutableRefObject, useEffect, useMemo, useState } 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 time 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\ntype MediaListener = (next: boolean) => void\n\nconst listeners: { [key: string]: Set<MediaListener> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n // eslint-disable-next-line no-console\n console.warn(`Warning, listening to media queries shouldn't use the \"$\" prefix`)\n }\n listeners[key] = listeners[key] || new Set()\n listeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n listeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => {\n return mediaState\n}\n\n// for SSR capture it at time of startup\nlet curState: MediaQueryState\nlet initState: MediaQueryState\nexport const getInitialMediaState = () => {\n return (getConfig().disableSSR ? curState : initState) || {}\n}\n\nlet mediaKeysOrdered: string[]\nexport const getMediaKeyImportance = (key: string) =>\n // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n mediaKeysOrdered.indexOf(key[0] === '$' ? key.slice(1) : key) + 2\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 }\n Object.assign(mediaQueryConfig, media)\n curState = { ...mediaState }\n initState = curState\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) {\n return\n }\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(() => match.removeListener(update))\n\n update()\n\n function update() {\n const next = !!getMatch().matches\n if (next === mediaState[key]) return\n mediaState[key] = next\n curState = { ...mediaState }\n const cur = listeners[key]\n if (cur?.size) {\n cur.forEach((cb) => cb(next))\n }\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n return unlisten\n }, [])\n}\n\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const keys = useSafeRef({} as Record<string, boolean>)\n const [state, setState] = useState<MediaQueryState>(() => getMediaState(initState || {}, keys))\n\n function updateState() {\n setState((prev) => {\n for (const key in keys.current) {\n if (prev[key] !== mediaState[key]) {\n return getMediaState({ ...mediaState }, keys)\n }\n }\n return prev\n })\n }\n\n useIsomorphicLayoutEffect(() => {\n updateState()\n const disposers = Object.keys(keys.current).map((key) =>\n addMediaQueryListener(key, updateState)\n )\n return () => {\n disposers.forEach((cb) => cb())\n }\n }, [keys.current])\n\n return state\n}\n\nfunction getMediaState(state: MediaQueryState, keys: MutableRefObject<Record<string, boolean>>) {\n return new Proxy(state, {\n get(_, key: string) {\n if (!keys.current[key]) {\n keys.current[key] = true\n }\n return Reflect.get(state, key)\n },\n })\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 if (!media[key.slice(1)]) {\n continue\n }\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, 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 function mergeMediaByImportance(\n onto: Record<string, any>,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaKeyImportance(key)\n if (importancesUsed[key] > importance) {\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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AClC,gBAAM,UAAU,OAAO,KAAK,GAAG;AAC/B,mBAAS,IAAI,QAAQ,QAAQ,KAAK,KAAK,GAAG;AACxC,kBAAM,SAAS,QAAQ;AACvB,mCAAuB,MAAM,QAAQ,IAAI,SAAS,eAAe;AAAA,UACnE;AAAA,QACF;AAAA,MACF,OAAO;AACL,+BAAuB,MAAM,KAAK,KAAK,eAAe;AAAA,MACxD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,OAAO,KAAK,CAAC;AACnB;AAEO,SAAS,uBACd,MACA,KACA,OACA,iBACA;AACA,QAAM,aAAa,sBAAsB,GAAG;AAC5C,MAAI,gBAAgB,OAAO,YAAY;AACrC,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;",
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 time 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\ntype MediaListener = (next: boolean) => void\n\nconst listeners: { [key: string]: Set<MediaListener> } = {}\n\nexport function addMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n if (process.env.NODE_ENV === 'development' && key[0] === '$') {\n // eslint-disable-next-line no-console\n console.warn(`Warning, listening to media queries shouldn't use the \"$\" prefix`)\n }\n listeners[key] = listeners[key] || new Set()\n listeners[key].add(cb)\n return () => removeMediaQueryListener(key, cb)\n}\n\nexport function removeMediaQueryListener(key: MediaQueryKey, cb: MediaListener) {\n listeners[key]?.delete(cb)\n}\n\nexport const mediaQueryConfig: MediaQueries = {}\n\nexport const getMedia = () => mediaState\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 // + 2 because we set base usedKeys=1 in getSplitStyles and all media go above 1\n mediaKeysOrdered.indexOf(key[0] === '$' ? key.slice(1) : key) + 2\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 }\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) {\n return\n }\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(() => match.removeListener(update))\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 const cur = listeners[key]\n if (cur?.size) {\n cur.forEach((cb) => cb(next))\n }\n }\n }\n}\n\nexport function useMediaListeners(config: TamaguiInternalConfig) {\n if (config.disableSSR) return\n useEffect(() => {\n setupMediaListeners()\n return unlisten\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\nexport function useMedia(): {\n [key in MediaQueryKey]: boolean\n} {\n const keys = useSafeRef<MediaKeysState>({ prev: initState })\n\n const state = useSyncExternalStore<MediaQueryState>(\n subscribe,\n () => {\n const { prev, ...curKeys } = keys.current\n const shouldUpdate = !prev || Object.keys(curKeys).some((k) => mediaState[k] !== prev[k])\n if (shouldUpdate) {\n const next = { ...mediaState }\n keys.current.prev = next\n return next\n }\n return prev\n },\n () => initState\n )\n\n return useMemo(() => {\n return new Proxy(state, {\n get(_, key: string) {\n if (!keys.current[key]) {\n keys.current[key] = true\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 if (!media[key.slice(1)]) {\n continue\n }\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, 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 function mergeMediaByImportance(\n onto: Record<string, any>,\n key: string,\n value: any,\n importancesUsed: Record<string, number>\n) {\n const importance = getMediaKeyImportance(key)\n if (importancesUsed[key] > importance) {\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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyD;AAEzD,oBAA0B;AAC1B,yBAA4B;AAC5B,wBAA2B;AAQ3B,wBAA2B;AAEpB,MAAM,aAEX,QAAQ,IAAI,a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,MAAM,KAAK,KAAK,eAAe;AAAA,MACxD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,OAAO,KAAK,CAAC;AACnB;AAEO,SAAS,uBACd,MACA,KACA,OACA,iBACA;AACA,QAAM,aAAa,sBAAsB,GAAG;AAC5C,MAAI,gBAAgB,OAAO,YAAY;AACrC,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
  }
@@ -37,7 +37,7 @@ var import_createProxy = require("../helpers/createProxy");
37
37
  var import_ThemeManager = require("../helpers/ThemeManager");
38
38
  var import_getThemeUnwrapped = require("./getThemeUnwrapped");
39
39
  var import_useServerHooks = require("./useServerHooks");
40
- const useTheme = (themeName, componentName, props, forceUpdate) => {
40
+ const useTheme = (themeName, componentName, props, forceUpdate, disableTracking) => {
41
41
  if (import_constants.isRSC) {
42
42
  const config = (0, import_config.getConfig)();
43
43
  return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme);
@@ -84,10 +84,33 @@ const useTheme = (themeName, componentName, props, forceUpdate) => {
84
84
  return themes[Object.keys(themes)[0]];
85
85
  }
86
86
  return (0, import_react.useMemo)(() => {
87
- return getThemeProxied(theme, name, className, themeManager, state, debugProp);
88
- }, [theme, name, className, themeManager, state, debugProp]);
87
+ return getThemeProxied({
88
+ theme,
89
+ name,
90
+ className,
91
+ themeManager,
92
+ onStringKeyAccess(key) {
93
+ if (disableTracking)
94
+ return;
95
+ if (state) {
96
+ if (state.current.isRendering && !state.current.keys.has(key)) {
97
+ state.current.keys.add(key);
98
+ if (process.env.NODE_ENV === "development" && debugProp === "verbose") {
99
+ console.log(" \u{1F538} tracking theme", key);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ });
105
+ }, [theme, name, className, themeManager, debugProp, disableTracking]);
89
106
  };
90
- function getThemeProxied(theme, name, className, themeManager, state, debugProp) {
107
+ function getThemeProxied({
108
+ theme,
109
+ name,
110
+ className,
111
+ themeManager,
112
+ onStringKeyAccess
113
+ }) {
91
114
  return (0, import_createProxy.createProxy)(theme, {
92
115
  has(_, key) {
93
116
  if (typeof key === "string" && key[0] === "$") {
@@ -117,14 +140,7 @@ function getThemeProxied(theme, name, className, themeManager, state, debugProp)
117
140
  if (!themeManager) {
118
141
  return theme[key];
119
142
  }
120
- if (state) {
121
- if (state.current.isRendering && !state.current.keys.has(key)) {
122
- state.current.keys.add(key);
123
- if (process.env.NODE_ENV === "development" && debugProp === "verbose") {
124
- console.log(" \u{1F538} tracking theme", key);
125
- }
126
- }
127
- }
143
+ onStringKeyAccess == null ? void 0 : onStringKeyAccess(key);
128
144
  return themeManager.getValue(key);
129
145
  }
130
146
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/useTheme.tsx"],
4
- "sourcesContent": ["import { isRSC, isServer, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeParsed } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport interface 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\ninterface 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): ThemeParsed => {\n // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\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[Object.keys(themes)[0]]\n }\n\n return useMemo(() => {\n return getThemeProxied(theme, name, className, themeManager, state, debugProp)\n }, [theme, name, className, themeManager, state, debugProp])\n}\n\nfunction getThemeProxied(\n theme: any,\n name: string,\n className?: string,\n themeManager?: ThemeManager | null,\n state?: React.MutableRefObject<UseThemeState>,\n debugProp?: boolean | 'verbose'\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string' && key[0] === '$') {\n key = key.slice(1)\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 // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (!themeManager) {\n return theme[key]\n }\n if (state) {\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 // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n }\n return themeManager.getValue(key)\n },\n })\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport function useThemeName(opts?: { parent?: true }): ThemeName {\n if (isRSC) {\n const config = getConfig()\n return config.themes[Object.keys(config.themes)[0]] as any\n }\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 uuid?: Object\n): {\n themes: Record<string, ThemeParsed>\n themeManager: ThemeManager | null\n name: string\n theme: ThemeParsed | null\n className?: string\n} => {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error(\n `Missing tamagui config, you either have a duplicate config, or haven't set it up. Be sure createTamagui is called before rendering.`\n )\n }\n }\n\n const { themes } = config\n\n if (isRSC) {\n // we need context working for this to work well\n const parentManager = new ThemeManager('light', 'light', themes.light)\n const next = parentManager.getNextTheme({\n name,\n componentName,\n themes,\n reset: props?.reset,\n })\n return {\n ...next,\n themes,\n themeManager: null,\n }\n }\n\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = {\n name,\n componentName,\n themes,\n reset,\n }\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 = useMemo(() => {\n return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n // not concurrent safe but fixes native (but breaks SSR and not needed on web (i think) so leave only on native)\n let didChange = false\n if (process.env.TAMAGUI_TARGET === 'native') {\n didChange = Boolean(\n next?.name !== themeManager.name || next?.className !== themeManager.className\n )\n if (didChange) {\n themeManager.update(next, false, false)\n }\n }\n\n if (!isServer) {\n useLayoutEffect(() => {\n themeManager.update(next, didChange)\n activeThemeManagers.add(themeManager)\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n if (uuid && !themeManager.isTracking(uuid)) {\n // no need to re-render if not tracking any keys\n return\n }\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('Changed theme', componentName, next, { props })\n }\n forceUpdate()\n }\n })\n\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeParentOnChange()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [didChange, themes, next?.name, next?.className, componentName, debug])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n className: next.className === parentManager.className ? undefined : next.className,\n themes,\n themeManager,\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA2D;AAC3D,8BAA+B;AAC/B,mBAA8E;AAE9E,oBAA0B;AAC1B,wBAA2B;AAC3B,0BAA6B;AAC7B,0BAA6B;AAC7B,yBAA4B;AAC5B,0BAKO;AAEP,+BAAkC;AAClC,4BAA6B;AAkBtB,MAAM,WAAW,CACtB,WACA,eACA,OACA,gBACgB;AAEhB,MAAI,wBAAO;AACT,UAAM,aAAS,yBAAU;AAEzB,WAAO,gBAAgB,OAAO,OAAO,OAAO,eAAe,OAAO,YAAY;AAAA,EAChF;AAEA,QAAM,YAAQ,oCAAa;AAC3B,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,UAAU,IAAI;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,SAAI,+BAAO,WAAU,WAAW;AAE9B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,WAAW,eAAe,MAAM,WAAW,GAAI,gCAAc,EAAE,MAAM,EAAG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YAAM,wBAAwB,cAAc,cAAc,MAAM;AAC9D,cAAMA,QAAO,cAAc,aAAa,eAAe,KAAK;AAC5D,YAAI,CAACA;AAAM;AACX,YAAI,aAAa,OAAOA,KAAI,GAAG;AAC7B,cAAI,QAAQ,CAAC,aAAa,WAAW,IAAI,GAAG;AAE1C;AAAA,UACF;AACA,cAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO;AAEnD,oBAAQ,IAAI,iBAAiB,eAAeA,OAAM,EAAE,MAAM,CAAC;AAAA,UAC7D;AACA,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,WAAW,QAAQ,6BAAM,MAAM,6BAAM,WAAW,eAAe,KAAK,CAAC;AAAA,EAC3E;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,WAAW,KAAK,cAAc,cAAc,YAAY,SAAY,KAAK;AAAA,IACzE;AAAA,IACA;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { isRSC, isServer, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useForceUpdate } from '@tamagui/use-force-update'\nimport React, { useContext, useLayoutEffect, useMemo, useRef, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { ThemeContext } from '../contexts/ThemeContext'\nimport { areEqualSets } from '../helpers/areEqualSets'\nimport { createProxy } from '../helpers/createProxy'\nimport {\n GetNextThemeProps,\n ThemeManager,\n ThemeManagerContext,\n emptyManager,\n} from '../helpers/ThemeManager'\nimport { ThemeName, ThemeParsed } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\nimport { useServerRef } from './useServerHooks'\n\nexport interface 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\ninterface 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 disableTracking?: boolean\n): ThemeParsed => {\n // TODO this can use useChangeThemeEffect almost ready\n if (isRSC) {\n const config = getConfig()\n // @ts-ignore\n return getThemeProxied(config.themes[config.defaultTheme], config.defaultTheme)\n }\n\n const state = useServerRef() as React.MutableRefObject<UseThemeState>\n if (!state.current) {\n state.current = {\n uuid: {},\n keys: new Set(),\n isRendering: true,\n }\n }\n\n const { name, theme, themes, themeManager, className } = useChangeThemeEffect(\n themeName,\n componentName,\n props,\n forceUpdate,\n state.current.uuid\n )\n\n if (process.env.NODE_ENV === 'development') {\n if (props?.debug === 'verbose') {\n // eslint-disable-next-line no-console\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { themeName, componentName, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n // eslint-disable-next-line no-console\n console.log(' ', key, logs[key])\n }\n // eslint-disable-next-line no-console\n console.groupEnd()\n }\n }\n\n // track usage\n state.current.isRendering = true\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[Object.keys(themes)[0]]\n }\n\n return useMemo(() => {\n return getThemeProxied({\n theme,\n name,\n className,\n themeManager,\n onStringKeyAccess(key) {\n if (disableTracking) return\n if (state) {\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 // eslint-disable-next-line no-console\n console.log(' \uD83D\uDD38 tracking theme', key)\n }\n }\n }\n },\n })\n }, [theme, name, className, themeManager, debugProp, disableTracking])\n}\n\nfunction getThemeProxied({\n theme,\n name,\n className,\n themeManager,\n onStringKeyAccess,\n}: {\n theme: any\n name: string\n onStringKeyAccess?: (cb: string) => void\n className?: string\n themeManager?: ThemeManager | null\n}) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string' && key[0] === '$') {\n key = key.slice(1)\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 // auto convert variables to plain\n if (key[0] === '$') {\n key = key.slice(1)\n }\n if (!themeManager) {\n return theme[key]\n }\n onStringKeyAccess?.(key)\n return themeManager.getValue(key)\n },\n })\n}\n\nconst GetThemeManager = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => {\n if (!theme) return\n return theme[GetThemeManager]\n}\n\nexport function useThemeName(opts?: { parent?: true }): ThemeName {\n if (isRSC) {\n const config = getConfig()\n return config.themes[Object.keys(config.themes)[0]] as any\n }\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 uuid?: Object\n): {\n themes: Record<string, ThemeParsed>\n themeManager: ThemeManager | null\n name: string\n theme: ThemeParsed | null\n className?: string\n} => {\n const config = getConfig()\n\n if (process.env.NODE_ENV === 'development') {\n if (!config) {\n throw new Error(\n `Missing tamagui config, you either have a duplicate config, or haven't set it up. Be sure createTamagui is called before rendering.`\n )\n }\n }\n\n const { themes } = config\n\n if (isRSC) {\n // we need context working for this to work well\n const parentManager = new ThemeManager('light', 'light', themes.light)\n const next = parentManager.getNextTheme({\n name,\n componentName,\n themes,\n reset: props?.reset,\n })\n return {\n ...next,\n themes,\n themeManager: null,\n }\n }\n\n const debug = props && props['debug']\n const parentManager = useContext(ThemeManagerContext) || emptyManager\n const reset = props?.reset || false\n const getThemeProps: GetNextThemeProps = {\n name,\n componentName,\n themes,\n reset,\n }\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 = useMemo(() => {\n return new ThemeManager(next.name, next.className, next.theme, parentManager, reset)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n // not concurrent safe but fixes native (but breaks SSR and not needed on web (i think) so leave only on native)\n let didChange = false\n if (process.env.TAMAGUI_TARGET === 'native') {\n didChange = Boolean(\n next?.name !== themeManager.name || next?.className !== themeManager.className\n )\n if (didChange) {\n themeManager.update(next, false, false)\n }\n }\n\n if (!isServer) {\n useLayoutEffect(() => {\n themeManager.update(next, didChange)\n activeThemeManagers.add(themeManager)\n\n const disposeParentOnChange = parentManager.onChangeTheme(() => {\n const next = parentManager.getNextTheme(getThemeProps, debug)\n if (!next) return\n if (themeManager.update(next)) {\n if (uuid && !themeManager.isTracking(uuid)) {\n // no need to re-render if not tracking any keys\n return\n }\n if (process.env.NODE_ENV === 'development' && debug) {\n // eslint-disable-next-line no-console\n console.log('Changed theme', componentName, next, { props })\n }\n forceUpdate()\n }\n })\n\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeParentOnChange()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [didChange, themes, next?.name, next?.className, componentName, debug])\n }\n\n return {\n ...(parentManager && {\n name: parentManager.name,\n theme: parentManager.theme,\n }),\n ...next,\n className: next.className === parentManager.className ? undefined : next.className,\n themes,\n themeManager,\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA2D;AAC3D,8BAA+B;AAC/B,mBAA8E;AAE9E,oBAA0B;AAC1B,wBAA2B;AAC3B,0BAA6B;AAC7B,0BAA6B;AAC7B,yBAA4B;AAC5B,0BAKO;AAEP,+BAAkC;AAClC,4BAA6B;AAkBtB,MAAM,WAAW,CACtB,WACA,eACA,OACA,aACA,oBACgB;AAEhB,MAAI,wBAAO;AACT,UAAM,aAAS,yBAAU;AAEzB,WAAO,gBAAgB,OAAO,OAAO,OAAO,eAAe,OAAO,YAAY;AAAA,EAChF;AAEA,QAAM,YAAQ,oCAAa;AAC3B,MAAI,CAAC,MAAM,SAAS;AAClB,UAAM,UAAU;AAAA,MACd,MAAM,CAAC;AAAA,MACP,MAAM,oBAAI,IAAI;AAAA,MACd,aAAa;AAAA,IACf;AAAA,EACF;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,UAAU,IAAI;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,QAAQ;AAAA,EAChB;AAEA,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,SAAI,+BAAO,WAAU,WAAW;AAE9B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,WAAW,eAAe,MAAM,WAAW,GAAI,gCAAc,EAAE,MAAM,EAAG;AACvF,iBAAW,OAAO,MAAM;AAEtB,gBAAQ,IAAI,MAAM,KAAK,KAAK,IAAI;AAAA,MAClC;AAEA,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAGA,QAAM,QAAQ,cAAc;AAC5B,kDAA0B,MAAM;AAC9B,UAAM,KAAK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aAAa,eAAe,KAAK;AAC5D,YAAI,CAACA;AAAM;AACX,YAAI,aAAa,OAAOA,KAAI,GAAG;AAC7B,cAAI,QAAQ,CAAC,aAAa,WAAW,IAAI,GAAG;AAE1C;AAAA,UACF;AACA,cAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO;AAEnD,oBAAQ,IAAI,iBAAiB,eAAeA,OAAM,EAAE,MAAM,CAAC;AAAA,UAC7D;AACA,sBAAY;AAAA,QACd;AAAA,MACF,CAAC;AAED,aAAO,MAAM;AACX,4BAAoB,OAAO,YAAY;AACvC,8BAAsB;AAAA,MACxB;AAAA,IAEF,GAAG,CAAC,WAAW,QAAQ,6BAAM,MAAM,6BAAM,WAAW,eAAe,KAAK,CAAC;AAAA,EAC3E;AAEA,SAAO;AAAA,IACL,GAAI,iBAAiB;AAAA,MACnB,MAAM,cAAc;AAAA,MACpB,OAAO,cAAc;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,WAAW,KAAK,cAAc,cAAc,YAAY,SAAY,KAAK;AAAA,IACzE;AAAA,IACA;AAAA,EACF;AACF;",
6
6
  "names": ["name", "parentManager", "next"]
7
7
  }
@@ -36,8 +36,7 @@ const ThemeInverse = ({
36
36
  (0, import_constants.useIsomorphicLayoutEffect)(() => {
37
37
  if (themeName.startsWith("dark")) {
38
38
  setName("light");
39
- }
40
- if (themeName.startsWith("light")) {
39
+ } else if (themeName.startsWith("light")) {
41
40
  setName("dark");
42
41
  }
43
42
  }, [defaultTheme, themeName]);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/views/ThemeInverse.tsx"],
4
- "sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n }\n if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BS;AA/BT,uBAA0C;AAC1C,mBAAgC;AAEhC,sBAAkD;AAClD,mBAAsB;AAEf,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAGM;AACJ,QAAM,gBAAY,8BAAa;AAC/B,QAAM,mBAAe,qCAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAwB,IAAI;AAGpD,kDAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB;AACA,QAAI,UAAU,WAAW,OAAO,GAAG;AACjC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,4CAAC;AAAA,IAAM;AAAA,IAAa;AAAA,GAAS;AACtC;",
4
+ "sourcesContent": ["import { useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport React, { useState } from 'react'\n\nimport { useDefaultThemeName, useThemeName } from '../hooks/useTheme'\nimport { Theme } from './Theme'\n\nexport const ThemeInverse = ({\n children,\n disable,\n}: {\n children: React.ReactNode\n disable?: boolean\n}) => {\n const themeName = useThemeName()\n const defaultTheme = useDefaultThemeName()\n const [name, setName] = useState<null | string>(null)\n\n // ssr\n useIsomorphicLayoutEffect(() => {\n if (themeName.startsWith('dark')) {\n setName('light')\n } else if (themeName.startsWith('light')) {\n setName('dark')\n }\n }, [defaultTheme, themeName])\n\n if (disable) {\n return children as JSX.Element\n }\n\n return <Theme name={name}>{children}</Theme>\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BS;AA9BT,uBAA0C;AAC1C,mBAAgC;AAEhC,sBAAkD;AAClD,mBAAsB;AAEf,MAAM,eAAe,CAAC;AAAA,EAC3B;AAAA,EACA;AACF,MAGM;AACJ,QAAM,gBAAY,8BAAa;AAC/B,QAAM,mBAAe,qCAAoB;AACzC,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAwB,IAAI;AAGpD,kDAA0B,MAAM;AAC9B,QAAI,UAAU,WAAW,MAAM,GAAG;AAChC,cAAQ,OAAO;AAAA,IACjB,WAAW,UAAU,WAAW,OAAO,GAAG;AACxC,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,MAAI,SAAS;AACX,WAAO;AAAA,EACT;AAEA,SAAO,4CAAC;AAAA,IAAM;AAAA,IAAa;AAAA,GAAS;AACtC;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useComposedRefs } from "@tamagui/compose-refs";
3
- import { isClient, isRSC, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
+ import { isClient, isRSC, isServer, isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
4
  import {
5
5
  composeEventHandlers,
6
6
  stylePropsTransform,
@@ -26,16 +26,11 @@ import { stackDefaultStyles } from "./constants/constants";
26
26
  import { FontLanguageContext } from "./contexts/FontLanguageContext";
27
27
  import { TextAncestorContext } from "./contexts/TextAncestorContext";
28
28
  import { extendStaticConfig, parseStaticConfig } from "./helpers/extendStaticConfig";
29
- import {
30
- getSubStyle,
31
- insertSplitStyles,
32
- useSplitStyles
33
- } from "./helpers/getSplitStyles";
29
+ import { getSubStyle, useSplitStyles } from "./helpers/getSplitStyles";
34
30
  import { getAllSelectors } from "./helpers/insertStyleRule";
35
31
  import { mergeProps } from "./helpers/mergeProps";
36
32
  import { mergeTransform } from "./helpers/mergeTransform";
37
33
  import { proxyThemeVariables } from "./helpers/proxyThemeVariables";
38
- import { pseudoDescriptors } from "./helpers/pseudoDescriptors";
39
34
  import { useShallowSetState } from "./helpers/useShallowSetState";
40
35
  import { getRect, measureLayout, useElementLayout } from "./hooks/useElementLayout";
41
36
  import { addMediaQueryListener, getInitialMediaState } from "./hooks/useMedia";
@@ -88,7 +83,6 @@ function createComponent(configIn, ParentComponent) {
88
83
  let defaultNativeStyle;
89
84
  let tamaguiDefaultProps;
90
85
  let defaultTag;
91
- let initialSplitStyles;
92
86
  const component = forwardRef((propsIn, forwardedRef) => {
93
87
  var _a, _b, _c, _d, _e, _f, _g;
94
88
  let props;
@@ -122,17 +116,26 @@ function createComponent(configIn, ParentComponent) {
122
116
  staticConfig.isReactNative || isAnimated && tamaguiConfig.animations.isReactNative
123
117
  );
124
118
  if (process.env.NODE_ENV === "development") {
125
- if (props["debug"]) {
119
+ if (debugProp) {
126
120
  const name = `${componentName || (Component == null ? void 0 : Component.displayName) || (Component == null ? void 0 : Component.name) || "[Unnamed Component]"}`;
127
121
  const type = isReactNative ? "(rnw)" : "";
128
122
  const dataIs = propsIn["data-is"] || "";
129
123
  const banner = `${name}${dataIs ? ` ${dataIs}` : ""} ${type}`;
130
124
  console.group(`%c ${banner}`, "background: yellow;");
131
- console.log(`state`, state);
125
+ if (!isServer) {
126
+ console.log(`state`, state);
127
+ console.groupCollapsed("props");
128
+ console.log(props);
129
+ console.log("order", Object.keys(props));
130
+ console.groupEnd();
131
+ }
132
132
  }
133
133
  }
134
+ const shouldAvoidClasses = !isWeb || !!(props.animation && avoidClassesWhileAnimating) || !staticConfig.acceptsClassName;
135
+ const shouldForcePseudo = !!propsIn.forceStyle;
136
+ const noClassNames = shouldAvoidClasses || shouldForcePseudo;
134
137
  const forceUpdate = useForceUpdate();
135
- const theme = useTheme(props.theme, componentName, props, forceUpdate);
138
+ const theme = useTheme(props.theme, componentName, props, forceUpdate, !noClassNames);
136
139
  const shouldSetMounted = needsMount && state.unmounted;
137
140
  const setMounted = shouldSetMounted ? () => {
138
141
  setTimeout(
@@ -144,10 +147,7 @@ function createComponent(configIn, ParentComponent) {
144
147
  isWeb ? 10 : 0
145
148
  );
146
149
  } : void 0;
147
- const shouldAvoidClasses = !isWeb || !!(props.animation && avoidClassesWhileAnimating) || !staticConfig.acceptsClassName;
148
- const shouldForcePseudo = !!propsIn.forceStyle;
149
150
  const hasTextAncestor = !!(isWeb && isText ? useContext(TextAncestorContext) : false);
150
- const noClassNames = shouldAvoidClasses || shouldForcePseudo;
151
151
  const languageContext = isRSC ? null : useContext(FontLanguageContext);
152
152
  const isDisabled = props.disabled ?? ((_b = props.accessibilityState) == null ? void 0 : _b.disabled);
153
153
  const isTaggable = !Component || typeof Component === "string";
@@ -157,19 +157,18 @@ function createComponent(configIn, ParentComponent) {
157
157
  let elementType = isText ? (isAnimated ? AnimatedText : null) || BaseTextComponent : (isAnimated ? AnimatedView : null) || BaseViewComponent;
158
158
  elementType = Component || elementType;
159
159
  const isStringElement = typeof elementType === "string";
160
- const splitStyleState = {
161
- ...state,
162
- noClassNames,
163
- dynamicStylesInline: noClassNames,
164
- hasTextAncestor,
165
- resolveVariablesAs: "value"
166
- };
167
160
  const splitStyles = useSplitStyles(
168
161
  props,
169
162
  staticConfig,
170
163
  theme,
171
- splitStyleState,
172
- props.asChild ? null : initialSplitStyles,
164
+ {
165
+ ...state,
166
+ noClassNames,
167
+ dynamicStylesInline: noClassNames,
168
+ hasTextAncestor,
169
+ resolveVariablesAs: "value"
170
+ },
171
+ null,
173
172
  languageContext || void 0,
174
173
  elementType,
175
174
  debugProp
@@ -412,11 +411,7 @@ function createComponent(configIn, ParentComponent) {
412
411
  styles = [isWeb ? null : defaultNativeStyle, animationStyles ?? splitStylesStyle, medias];
413
412
  if (shouldForcePseudo) {
414
413
  const next = {};
415
- for (const style of styles) {
416
- if (style) {
417
- Object.assign(next, style);
418
- }
419
- }
414
+ styles.forEach((style) => Object.assign(next, style));
420
415
  Object.assign(splitStyles.style, next);
421
416
  }
422
417
  }
@@ -475,6 +470,8 @@ function createComponent(configIn, ParentComponent) {
475
470
  for (const style2 of styles) {
476
471
  if (style2 == null ? void 0 : style2.fontFamily) {
477
472
  style2.fontFamily = overrideFace;
473
+ delete style2.fontWeight;
474
+ delete style2.fontStyle;
478
475
  }
479
476
  }
480
477
  }
@@ -482,15 +479,13 @@ function createComponent(configIn, ParentComponent) {
482
479
  }
483
480
  viewProps.style = styles;
484
481
  }
485
- const initialPseudos = initialSplitStyles == null ? void 0 : initialSplitStyles.pseudos;
486
- const runtimePressStyle = noClassNames && ((pseudos == null ? void 0 : pseudos.pressStyle) || (initialPseudos == null ? void 0 : initialPseudos.pressStyle));
482
+ const runtimePressStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.pressStyle);
487
483
  const attachPress = !!(runtimePressStyle || onPress || onPressOut || onPressIn || onClick);
488
- const isHoverable = isWeb;
489
- const runtimeHoverStyle = noClassNames && ((pseudos == null ? void 0 : pseudos.hoverStyle) || initialPseudos.hoverStyle);
490
- const attachHover = isHoverable && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
484
+ const runtimeHoverStyle = !disabled && noClassNames && (pseudos == null ? void 0 : pseudos.hoverStyle);
485
+ const isHoverable = isWeb && !!(runtimeHoverStyle || onHoverIn || onHoverOut || onMouseEnter || onMouseLeave);
491
486
  const handlesPressEvents = !isWeb && !asChild;
492
487
  const shouldAttach = asChild ? false : Boolean(
493
- attachPress || attachHover || "pressStyle" in props || "onPress" in props || "onPressIn" in props || "onPressOut" in props || isWeb && ("hoverStyle" in props || "onHoverIn" in props || "onHoverOut" in props || "onMouseEnter" in props || "onMouseLeave" in props)
488
+ attachPress || isHoverable || "pressStyle" in props || "onPress" in props || "onPressIn" in props || "onPressOut" in props || isWeb && ("hoverStyle" in props || "onHoverIn" in props || "onHoverOut" in props || "onMouseEnter" in props || "onMouseLeave" in props)
494
489
  );
495
490
  const events = shouldAttach && !isRSC && !isDisabled ? {
496
491
  onPressOut: attachPress ? (e) => {
@@ -498,25 +493,25 @@ function createComponent(configIn, ParentComponent) {
498
493
  onPressOut == null ? void 0 : onPressOut(e);
499
494
  onMouseUp == null ? void 0 : onMouseUp(e);
500
495
  } : void 0,
501
- ...attachHover && {
502
- onMouseEnter: attachHover ? (e) => {
496
+ ...isHoverable && {
497
+ onMouseEnter: isHoverable ? (e) => {
503
498
  const next = {};
504
- if (attachHover) {
499
+ if (isHoverable) {
505
500
  next.hover = true;
506
501
  }
507
502
  if (state.pressIn) {
508
503
  next.press = true;
509
504
  }
510
- if (attachHover || state.pressIn) {
505
+ if (isHoverable || state.pressIn) {
511
506
  setStateShallow(next);
512
507
  }
513
508
  onHoverIn == null ? void 0 : onHoverIn(e);
514
509
  onMouseEnter == null ? void 0 : onMouseEnter(e);
515
510
  } : void 0,
516
- onMouseLeave: attachHover ? (e) => {
511
+ onMouseLeave: isHoverable ? (e) => {
517
512
  const next = {};
518
513
  mouseUps.add(unPress);
519
- if (attachHover) {
514
+ if (isHoverable) {
520
515
  next.hover = false;
521
516
  }
522
517
  if (state.pressIn) {
@@ -593,7 +588,7 @@ function createComponent(configIn, ParentComponent) {
593
588
  };
594
589
  }
595
590
  if (process.env.TAMAGUI_TARGET === "native") {
596
- const attachFocus = !!(pseudos.focusStyle || initialPseudos && initialPseudos.focusStyle);
591
+ const attachFocus = !!pseudos.focusStyle;
597
592
  if (attachFocus) {
598
593
  viewProps.onFocus = mergeEvent(viewProps.onFocus, () => {
599
594
  setStateShallow({ focus: true });
@@ -639,7 +634,7 @@ function createComponent(configIn, ParentComponent) {
639
634
  console.log("children", content);
640
635
  console.groupEnd();
641
636
  if (typeof window !== "undefined") {
642
- console.log({ state, shouldProvideThemeManager, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: (_f = props.className) == null ? void 0 : _f.split(" "), classNamesOut: (_g = viewProps.className) == null ? void 0 : _g.split(" "), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, defaultNativeStyle, initialSplitStyles, ...typeof window !== "undefined" ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null });
637
+ console.log({ state, shouldProvideThemeManager, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: (_f = props.className) == null ? void 0 : _f.split(" "), classNamesOut: (_g = viewProps.className) == null ? void 0 : _g.split(" "), events, shouldAttach, styles, pseudos, content, childEls, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, defaultNativeStyle, ...typeof window !== "undefined" ? { theme, themeClassName: theme.className, staticConfig, tamaguiConfig, events, shouldAvoidClasses, shouldForcePseudo, classNames: Object.fromEntries(Object.entries(classNames).map(([k, v]) => [v, getAllSelectors()[v]])) } : null });
643
638
  }
644
639
  console.groupEnd();
645
640
  }
@@ -693,38 +688,16 @@ function createComponent(configIn, ParentComponent) {
693
688
  );
694
689
  }
695
690
  const debug = defaultPropsIn["debug"];
696
- const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {}, true);
691
+ const [ourProps, ourClassNames] = mergeProps(defaultPropsIn, {});
697
692
  if (ourProps.tag) {
698
693
  defaultTag = ourProps.tag;
699
694
  }
700
695
  const noClassNames = !staticConfig.acceptsClassName;
701
- initialSplitStyles = insertSplitStyles(
702
- ourProps,
703
- staticConfig,
704
- initialTheme,
705
- {
706
- unmounted: false,
707
- hover: false,
708
- press: false,
709
- pressIn: false,
710
- focus: false,
711
- resolveVariablesAs: "both",
712
- noClassNames
713
- },
714
- void 0,
715
- void 0,
716
- debug
717
- );
718
- const [defaults, defaultsClassnames] = mergeProps(
719
- component.defaultProps,
720
- isWeb ? { ...initialSplitStyles.pseudos, ...initialSplitStyles.viewProps } : initialSplitStyles.viewProps,
721
- true
722
- );
723
- initialSplitStyles.classNames = {
724
- ...defaultsClassnames,
725
- ...initialSplitStyles.classNames,
726
- ...ourClassNames
727
- };
696
+ const { name, variants, defaultVariants, ...restProps } = ourProps;
697
+ const [defaults, defaultsClassnames] = mergeProps(component.defaultProps, {
698
+ ...defaultVariants,
699
+ ...restProps
700
+ });
728
701
  defaultNativeStyle = {};
729
702
  const validStyles2 = staticConfig.validStyles || stylePropsView;
730
703
  if (!isWeb) {
@@ -739,34 +712,10 @@ function createComponent(configIn, ParentComponent) {
739
712
  }
740
713
  }
741
714
  }
742
- if (Object.keys(defaults).length) {
743
- tamaguiDefaultProps = defaults;
744
- if (!isWeb) {
745
- Object.keys(pseudoDescriptors).forEach((k) => {
746
- if (ourProps[k]) {
747
- initialSplitStyles.pseudos[k] = null;
748
- tamaguiDefaultProps[k] = ourProps[k];
749
- }
750
- });
751
- }
752
- }
715
+ tamaguiDefaultProps = defaults;
753
716
  if (process.env.NODE_ENV === "development" && debug) {
754
717
  if (process.env.IS_STATIC !== "is_static") {
755
- console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, {
756
- staticConfig,
757
- initialSplitStyles,
758
- tamaguiDefaultProps,
759
- defaultNativeStyle,
760
- defaults,
761
- defaultPropsIn,
762
- defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps),
763
- defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]),
764
- ourProps,
765
- ourClassNames,
766
- defaultsClassnames,
767
- defaultTag,
768
- noClassNames
769
- });
718
+ console.log(`\u{1F41B} [${staticConfig.componentName || "Component"}]`, { staticConfig, tamaguiDefaultProps, defaultNativeStyle, defaults, defaultPropsIn, defaultPropsKeyOrder: Object.keys(staticConfig.defaultProps), defaultPropsInKeyOrder: Object.keys(defaultPropsIn).map((k) => [k, defaultPropsIn[k]]), ourProps, ourClassNames, defaultsClassnames, defaultTag, noClassNames });
770
719
  }
771
720
  }
772
721
  });