@tamagui/web 2.3.2 → 2.3.3-1782462397214

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 (79) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/cjs/createComponent.cjs +16 -6
  3. package/dist/cjs/createComponent.native.js +17 -7
  4. package/dist/cjs/createComponent.native.js.map +1 -1
  5. package/dist/cjs/helpers/getSplitStyles.cjs +5 -0
  6. package/dist/cjs/helpers/getSplitStyles.native.js +9 -0
  7. package/dist/cjs/helpers/getSplitStyles.native.js.map +1 -1
  8. package/dist/cjs/helpers/pointerEvents.native.js +26 -20
  9. package/dist/cjs/helpers/pointerEvents.native.js.map +1 -1
  10. package/dist/cjs/hooks/useMedia.cjs +107 -42
  11. package/dist/cjs/hooks/useMedia.native.js +149 -60
  12. package/dist/cjs/hooks/useMedia.native.js.map +1 -1
  13. package/dist/cjs/hooks/useTheme.cjs +17 -4
  14. package/dist/cjs/hooks/useTheme.native.js +18 -4
  15. package/dist/cjs/hooks/useTheme.native.js.map +1 -1
  16. package/dist/cjs/hooks/useThemeState.cjs +129 -63
  17. package/dist/cjs/hooks/useThemeState.native.js +142 -66
  18. package/dist/cjs/hooks/useThemeState.native.js.map +1 -1
  19. package/dist/cjs/index.cjs +2 -0
  20. package/dist/cjs/index.native.js +2 -0
  21. package/dist/cjs/index.native.js.map +1 -1
  22. package/dist/cjs/views/Theme.cjs +1 -1
  23. package/dist/cjs/views/Theme.native.js +1 -1
  24. package/dist/cjs/views/Theme.native.js.map +1 -1
  25. package/dist/esm/createComponent.mjs +16 -6
  26. package/dist/esm/createComponent.mjs.map +1 -1
  27. package/dist/esm/createComponent.native.js +19 -9
  28. package/dist/esm/createComponent.native.js.map +1 -1
  29. package/dist/esm/helpers/getSplitStyles.mjs +5 -0
  30. package/dist/esm/helpers/getSplitStyles.mjs.map +1 -1
  31. package/dist/esm/helpers/getSplitStyles.native.js +9 -0
  32. package/dist/esm/helpers/getSplitStyles.native.js.map +1 -1
  33. package/dist/esm/helpers/pointerEvents.native.js +26 -20
  34. package/dist/esm/helpers/pointerEvents.native.js.map +1 -1
  35. package/dist/esm/hooks/useMedia.mjs +108 -43
  36. package/dist/esm/hooks/useMedia.mjs.map +1 -1
  37. package/dist/esm/hooks/useMedia.native.js +150 -61
  38. package/dist/esm/hooks/useMedia.native.js.map +1 -1
  39. package/dist/esm/hooks/useTheme.mjs +17 -4
  40. package/dist/esm/hooks/useTheme.mjs.map +1 -1
  41. package/dist/esm/hooks/useTheme.native.js +18 -4
  42. package/dist/esm/hooks/useTheme.native.js.map +1 -1
  43. package/dist/esm/hooks/useThemeState.mjs +130 -64
  44. package/dist/esm/hooks/useThemeState.mjs.map +1 -1
  45. package/dist/esm/hooks/useThemeState.native.js +143 -67
  46. package/dist/esm/hooks/useThemeState.native.js.map +1 -1
  47. package/dist/esm/index.js +3 -3
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/index.mjs +3 -3
  50. package/dist/esm/index.mjs.map +1 -1
  51. package/dist/esm/index.native.js +3 -3
  52. package/dist/esm/index.native.js.map +1 -1
  53. package/dist/esm/views/Theme.mjs +1 -1
  54. package/dist/esm/views/Theme.mjs.map +1 -1
  55. package/dist/esm/views/Theme.native.js +1 -1
  56. package/dist/esm/views/Theme.native.js.map +1 -1
  57. package/package.json +13 -13
  58. package/src/createComponent.tsx +48 -5
  59. package/src/helpers/getSplitStyles.tsx +33 -0
  60. package/src/helpers/pointerEvents.native.ts +26 -19
  61. package/src/hooks/useMedia.tsx +147 -42
  62. package/src/hooks/useTheme.tsx +27 -5
  63. package/src/hooks/useThemeState.ts +255 -127
  64. package/src/index.ts +7 -1
  65. package/src/types.tsx +49 -5
  66. package/src/views/Theme.tsx +4 -1
  67. package/types/createComponent.d.ts.map +1 -1
  68. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  69. package/types/helpers/pointerEvents.native.d.ts.map +1 -1
  70. package/types/hooks/useMedia.d.ts.map +1 -1
  71. package/types/hooks/useTheme.d.ts +1 -1
  72. package/types/hooks/useTheme.d.ts.map +1 -1
  73. package/types/hooks/useThemeState.d.ts +1 -1
  74. package/types/hooks/useThemeState.d.ts.map +1 -1
  75. package/types/index.d.ts +2 -2
  76. package/types/index.d.ts.map +1 -1
  77. package/types/types.d.ts +2 -1
  78. package/types/types.d.ts.map +1 -1
  79. package/types/views/Theme.d.ts.map +1 -1
@@ -1,5 +1,5 @@
1
1
  import { useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { createContext, useCallback, useContext, useId, useSyncExternalStore } from "react";
2
+ import { createContext, useContext, useEffect, useReducer, useRef } from "react";
3
3
  import { getConfig } from "../config.mjs";
4
4
  import { MISSING_THEME_MESSAGE } from "../constants/constants.mjs";
5
5
  const ThemeStateContext = createContext("");
@@ -24,7 +24,10 @@ let themeNameCacheVer = -1;
24
24
  let themes = null;
25
25
  let rootThemeState = null;
26
26
  const getRootThemeState = () => rootThemeState;
27
- const useThemeState = (props, isRoot = false, keys, schemeKeys) => {
27
+ let themeStateIdCounter = 0;
28
+ const nextThemeStateId = () => `t${++themeStateIdCounter}`;
29
+ const incReducer = c => c + 1;
30
+ const useThemeState = (props, isRoot = false, keys, schemeKeys, cascadeOnChange = false) => {
28
31
  "use no memo";
29
32
 
30
33
  const {
@@ -39,70 +42,69 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
39
42
  name: "light",
40
43
  theme: getConfig().themes.light
41
44
  };
42
- const id = useId();
43
- const subscribe = useCallback(cb => {
44
- listenersByParent[parentId] = listenersByParent[parentId] || /* @__PURE__ */new Set();
45
- listenersByParent[parentId].add(id);
46
- allListeners.set(id, () => {
47
- PendingUpdate.set(id, shouldForce ? "force" : true);
48
- cb();
49
- });
50
- return () => {
51
- allListeners.delete(id);
52
- listenersByParent[parentId].delete(id);
53
- localStates.delete(id);
54
- states.delete(id);
55
- PendingUpdate.delete(id);
56
- };
57
- }, [id, parentId]);
58
45
  const propsKey = getPropsKey(props);
59
- const getSnapshot = () => {
60
- let local = localStates.get(id);
61
- const parentState = states.get(parentId);
62
- if (local && !PendingUpdate.has(id)) {
63
- if (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;
64
- }
65
- const isSchemeOnlyChange = false;
66
- const keysSize = keys?.current?.size ?? 0;
67
- const allKeysSchemeOptimized = (schemeKeys?.current?.size ?? 0) === keysSize && keysSize > 0;
68
- const canSkipForSchemeChange = isSchemeOnlyChange;
69
- const needsUpdate = props.passThrough ? false : isRoot || props.name === "light" || props.name === "dark" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : keys?.current?.size ? true : props.needsUpdate?.();
70
- const [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));
71
- PendingUpdate.delete(id);
72
- if (!local || rerender) {
73
- local = {
74
- ...next
75
- };
76
- localStates.set(id, local);
77
- }
78
- if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
79
- console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
80
- console.info({
81
- props,
82
- propsKey,
83
- isRoot,
84
- parentId,
85
- local,
86
- next,
87
- needsUpdate,
88
- isSchemeOnlyChange,
89
- allKeysSchemeOptimized,
90
- canSkipForSchemeChange
91
- });
92
- console.groupEnd();
93
- }
94
- if (next !== local) {
95
- Object.assign(local, next);
96
- local.id = id;
97
- }
98
- local._parentName = parentState?.name;
99
- local._propsKey = propsKey;
100
- states.set(id, next);
101
- return local;
102
- };
46
+ const ref = useRef(null);
47
+ if (!ref.current) ref.current = {
48
+ id: nextThemeStateId(),
49
+ parentId,
50
+ props,
51
+ propsKey,
52
+ isRoot,
53
+ keys,
54
+ schemeKeys,
55
+ renderVersion: 0
56
+ };else {
57
+ ref.current.props = props;
58
+ ref.current.propsKey = propsKey;
59
+ ref.current.isRoot = isRoot;
60
+ ref.current.keys = keys;
61
+ ref.current.schemeKeys = schemeKeys;
62
+ ref.current.parentId = parentId;
63
+ }
64
+ ref.current.renderVersion++;
103
65
  if (process.env.NODE_ENV === "development" && globalThis.time) globalThis.time`theme-prep-uses`;
104
- const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
105
- useIsomorphicLayoutEffect(() => {
66
+ const [, forceUpdate] = useReducer(incReducer, 0);
67
+ const state = getSnapshotImpl(ref.current);
68
+ ref.current.lastSnap = state;
69
+ useEffect(() => {
70
+ const r = ref.current;
71
+ const renderVersion = r.renderVersion;
72
+ if (r.unsubscribe && r.subscribedParentId !== r.parentId) cleanupThemeSubscription(r);
73
+ if (shouldSubscribeToTheme(r, cascadeOnChange)) {
74
+ if (!r.unsubscribe) {
75
+ const pid = r.parentId;
76
+ const sid = r.id;
77
+ const cb = () => {
78
+ const next = getSnapshotImpl(r);
79
+ if (next !== r.lastSnap) {
80
+ r.lastSnap = next;
81
+ forceUpdate();
82
+ }
83
+ };
84
+ listenersByParent[pid] = listenersByParent[pid] || /* @__PURE__ */new Set();
85
+ listenersByParent[pid].add(sid);
86
+ allListeners.set(sid, () => {
87
+ PendingUpdate.set(sid, shouldForce ? "force" : true);
88
+ cb();
89
+ });
90
+ r.subscribedParentId = pid;
91
+ r.unsubscribe = () => {
92
+ allListeners.delete(sid);
93
+ listenersByParent[pid]?.delete(sid);
94
+ localStates.delete(sid);
95
+ states.delete(sid);
96
+ PendingUpdate.delete(sid);
97
+ r.unsubscribe = void 0;
98
+ r.subscribedParentId = void 0;
99
+ };
100
+ }
101
+ } else if (r.unsubscribe) cleanupThemeSubscription(r);
102
+ return () => {
103
+ if (r.renderVersion === renderVersion) cleanupThemeState(r);
104
+ };
105
+ });
106
+ const id = ref.current.id;
107
+ if (cascadeOnChange) useIsomorphicLayoutEffect(() => {
106
108
  if (!HasRenderedOnce.get(keys)) {
107
109
  HasRenderedOnce.set(keys, true);
108
110
  return;
@@ -118,6 +120,70 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
118
120
  }, [keys, propsKey]);
119
121
  return state;
120
122
  };
123
+ const shouldSubscribeToTheme = (r, cascadeOnChange) => r.isRoot || cascadeOnChange || hasThemeUpdatingProps(r.props) || !!r.keys.current?.size || !!r.props.needsUpdate?.();
124
+ function cleanupThemeSubscription(r) {
125
+ r.unsubscribe?.();
126
+ }
127
+ function cleanupThemeState(r) {
128
+ if (r.unsubscribe) cleanupThemeSubscription(r);else {
129
+ localStates.delete(r.id);
130
+ states.delete(r.id);
131
+ PendingUpdate.delete(r.id);
132
+ }
133
+ }
134
+ const getSnapshotImpl = r => {
135
+ const {
136
+ id,
137
+ parentId,
138
+ props,
139
+ propsKey,
140
+ isRoot,
141
+ keys,
142
+ schemeKeys
143
+ } = r;
144
+ let local = localStates.get(id);
145
+ const parentState = states.get(parentId);
146
+ if (local && !PendingUpdate.has(id)) {
147
+ if (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;
148
+ }
149
+ const isSchemeOnlyChange = false;
150
+ const keysSize = keys?.current?.size ?? 0;
151
+ const allKeysSchemeOptimized = (schemeKeys?.current?.size ?? 0) === keysSize && keysSize > 0;
152
+ const canSkipForSchemeChange = isSchemeOnlyChange;
153
+ const needsUpdate = props.passThrough ? false : isRoot || props.name === "light" || props.name === "dark" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : keys?.current?.size ? true : props.needsUpdate?.();
154
+ const [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));
155
+ PendingUpdate.delete(id);
156
+ if (!local || rerender) {
157
+ local = {
158
+ ...next
159
+ };
160
+ localStates.set(id, local);
161
+ }
162
+ if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
163
+ console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
164
+ console.info({
165
+ props,
166
+ propsKey,
167
+ isRoot,
168
+ parentId,
169
+ local,
170
+ next,
171
+ needsUpdate,
172
+ isSchemeOnlyChange,
173
+ allKeysSchemeOptimized,
174
+ canSkipForSchemeChange
175
+ });
176
+ console.groupEnd();
177
+ }
178
+ if (next !== local) {
179
+ Object.assign(local, next);
180
+ local.id = id;
181
+ }
182
+ local._parentName = parentState?.name;
183
+ local._propsKey = propsKey;
184
+ states.set(id, next);
185
+ return local;
186
+ };
121
187
  const getNextState = (lastState, props, propsKey, isRoot = false, id, parentId, needsUpdate, pendingUpdate) => {
122
188
  const {
123
189
  debug
@@ -1 +1 @@
1
- {"version":3,"names":["useIsomorphicLayoutEffect","createContext","useCallback","useContext","useId","useSyncExternalStore","getConfig","MISSING_THEME_MESSAGE","ThemeStateContext","allListeners","Map","listenersByParent","HasRenderedOnce","WeakMap","HadTheme","PendingUpdate","states","localStates","shouldForce","forceUpdateThemes","cacheVersion","forEach","cb","getThemeState","id","get","themeNameCache","themeNameCacheVer","themes","rootThemeState","getRootThemeState","useThemeState","props","isRoot","keys","schemeKeys","disable","parentId","Error","process","env","NODE_ENV","name","componentName","theme","light","subscribe","Set","add","set","delete","propsKey","getPropsKey","getSnapshot","local","parentState","has","_parentName","_propsKey","isSchemeOnlyChange","keysSize","current","size","allKeysSchemeOptimized","canSkipForSchemeChange","needsUpdate","passThrough","rerender","next","getNextState","debug","console","groupCollapsed","info","groupEnd","Object","assign","globalThis","time","state","scheduleUpdate","warn","lastState","pendingUpdate","isNew","getNewThemeName","isSameAsParent","shouldRerender","Boolean","message","trace","scheme","getScheme","isInverse","nextState","parentName","shouldAvoidRerender","queue","visited","length","children","shift","childId","push","validSchemes","dark","split","forceUpdate","reset","unstyled","cacheKey","clear","cached","themes2","result2","lastPartIndex","lastIndexOf","name2","slice","result","parentParts","lastName","toLowerCase","pop","subNames","filter","found","nameHasScheme","subName","potentialBases","i","join","outer","base","candidates","potential","max","forceClassName","hasThemeUpdatingProps"],"sources":["useThemeState.mjs"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createContext, useCallback, useContext, useId, useSyncExternalStore } from \"react\";\nimport { getConfig } from \"../config\";\nimport { MISSING_THEME_MESSAGE } from \"../constants/constants\";\n\nconst ThemeStateContext = createContext(\"\");\nconst allListeners = /* @__PURE__ */ new Map();\nconst listenersByParent = {};\nconst HasRenderedOnce = /* @__PURE__ */ new WeakMap();\nconst HadTheme = /* @__PURE__ */ new WeakMap();\nconst PendingUpdate = /* @__PURE__ */ new Map();\nconst states = /* @__PURE__ */ new Map();\nconst localStates = /* @__PURE__ */ new Map();\nlet shouldForce = false;\nconst forceUpdateThemes = () => {\n\tcacheVersion++;\n\tshouldForce = true;\n\tallListeners.forEach((cb) => cb());\n\tshouldForce = false;\n};\nconst getThemeState = (id) => states.get(id);\nlet cacheVersion = 0;\nconst themeNameCache = /* @__PURE__ */ new Map();\nlet themeNameCacheVer = -1;\nlet themes = null;\nlet rootThemeState = null;\nconst getRootThemeState = () => rootThemeState;\nconst useThemeState = (props, isRoot = false, keys, schemeKeys) => {\n\t\"use no memo\";\n\tconst { disable } = props;\n\tconst parentId = useContext(ThemeStateContext);\n\tif (!parentId && !isRoot) throw new Error(process.env.NODE_ENV === \"development\" ? `${MISSING_THEME_MESSAGE}\n\nLooked for theme${props.name ? ` \"${props.name}\"` : \"\"}${props.componentName ? ` (component: ${props.componentName})` : \"\"}, but no parent theme context was found (parentId: ${parentId}).` : MISSING_THEME_MESSAGE);\n\tif (disable) return states.get(parentId) || {\n\t\tid: \"\",\n\t\tname: \"light\",\n\t\ttheme: getConfig().themes.light\n\t};\n\tconst id = useId();\n\tconst subscribe = useCallback((cb) => {\n\t\tlistenersByParent[parentId] = listenersByParent[parentId] || /* @__PURE__ */ new Set();\n\t\tlistenersByParent[parentId].add(id);\n\t\tallListeners.set(id, () => {\n\t\t\tPendingUpdate.set(id, shouldForce ? \"force\" : true);\n\t\t\tcb();\n\t\t});\n\t\treturn () => {\n\t\t\tallListeners.delete(id);\n\t\t\tlistenersByParent[parentId].delete(id);\n\t\t\tlocalStates.delete(id);\n\t\t\tstates.delete(id);\n\t\t\tPendingUpdate.delete(id);\n\t\t};\n\t}, [id, parentId]);\n\tconst propsKey = getPropsKey(props);\n\tconst getSnapshot = () => {\n\t\tlet local = localStates.get(id);\n\t\tconst parentState = states.get(parentId);\n\t\tif (local && !PendingUpdate.has(id)) {\n\t\t\tif (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;\n\t\t}\n\t\tconst isSchemeOnlyChange = false;\n\t\tconst keysSize = keys?.current?.size ?? 0;\n\t\tconst allKeysSchemeOptimized = (schemeKeys?.current?.size ?? 0) === keysSize && keysSize > 0;\n\t\tconst canSkipForSchemeChange = isSchemeOnlyChange;\n\t\tconst needsUpdate = props.passThrough ? false : isRoot || props.name === \"light\" || props.name === \"dark\" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : keys?.current?.size ? true : props.needsUpdate?.();\n\t\tconst [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));\n\t\tPendingUpdate.delete(id);\n\t\tif (!local || rerender) {\n\t\t\tlocal = { ...next };\n\t\t\tlocalStates.set(id, local);\n\t\t}\n\t\tif (process.env.NODE_ENV === \"development\" && props.debug === \"verbose\") {\n\t\t\tconsole.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, \">\", next.name);\n\t\t\tconsole.info({\n\t\t\t\tprops,\n\t\t\t\tpropsKey,\n\t\t\t\tisRoot,\n\t\t\t\tparentId,\n\t\t\t\tlocal,\n\t\t\t\tnext,\n\t\t\t\tneedsUpdate,\n\t\t\t\tisSchemeOnlyChange,\n\t\t\t\tallKeysSchemeOptimized,\n\t\t\t\tcanSkipForSchemeChange\n\t\t\t});\n\t\t\tconsole.groupEnd();\n\t\t}\n\t\tif (next !== local) {\n\t\t\tObject.assign(local, next);\n\t\t\tlocal.id = id;\n\t\t}\n\t\tlocal._parentName = parentState?.name;\n\t\tlocal._propsKey = propsKey;\n\t\tstates.set(id, next);\n\t\treturn local;\n\t};\n\tif (process.env.NODE_ENV === \"development\" && globalThis.time) globalThis.time`theme-prep-uses`;\n\tconst state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!HasRenderedOnce.get(keys)) {\n\t\t\tHasRenderedOnce.set(keys, true);\n\t\t\treturn;\n\t\t}\n\t\tif (!propsKey) {\n\t\t\tif (HadTheme.get(keys)) scheduleUpdate(id);\n\t\t\tHadTheme.set(keys, false);\n\t\t\treturn;\n\t\t}\n\t\tif (process.env.NODE_ENV === \"development\" && props.debug === \"verbose\") console.warn(` \\xB7 useTheme(${id}) scheduleUpdate`, propsKey, states.get(id)?.name);\n\t\tscheduleUpdate(id);\n\t\tHadTheme.set(keys, true);\n\t}, [keys, propsKey]);\n\treturn state;\n};\nconst getNextState = (lastState, props, propsKey, isRoot = false, id, parentId, needsUpdate, pendingUpdate) => {\n\tconst { debug } = props;\n\tconst parentState = states.get(parentId);\n\tif (props.passThrough) return [false, lastState || parentState || { name: \"\" }];\n\tif (!themes) themes = getConfig().themes;\n\tconst name = !propsKey && (!lastState || !lastState?.isNew) ? null : getNewThemeName(parentState?.name, props, pendingUpdate === \"force\" ? true : !!needsUpdate);\n\tconst isSameAsParent = parentState && (!name || name === parentState.name);\n\tconst shouldRerender = Boolean(pendingUpdate === \"force\" || needsUpdate && (pendingUpdate || lastState?.name !== parentState?.name));\n\tif (process.env.NODE_ENV === \"development\" && debug === \"verbose\") {\n\t\tconst message = ` \\xB7 useTheme(${id}) getNextState => ${name} needsUpdate ${needsUpdate} shouldRerender ${shouldRerender}`;\n\t\tconsole.groupCollapsed(message);\n\t\tconsole.trace({\n\t\t\tname,\n\t\t\tlastState,\n\t\t\tparentState,\n\t\t\tprops,\n\t\t\tpropsKey,\n\t\t\tid,\n\t\t\tisSameAsParent\n\t\t});\n\t\tconsole.groupEnd();\n\t}\n\tif (isSameAsParent) {\n\t\tif (!shouldRerender && lastState && lastState.name === parentState.name) return [false, lastState];\n\t\treturn [shouldRerender, {\n\t\t\t...parentState,\n\t\t\tisNew: false\n\t\t}];\n\t}\n\tif (!name) {\n\t\tconst next = lastState ?? parentState;\n\t\tif (!next) throw new Error(process.env.NODE_ENV === \"development\" ? `${MISSING_THEME_MESSAGE}\n\nLooked for theme${props.name ? ` \"${props.name}\"` : \"\"}${props.componentName ? ` (component: ${props.componentName})` : \"\"}, but no theme state was resolved (parentId: ${parentId}, id: ${id}).` : MISSING_THEME_MESSAGE);\n\t\tif (shouldRerender) return [true, { ...parentState || lastState }];\n\t\treturn [false, next];\n\t}\n\tconst scheme = getScheme(name);\n\tconst isInverse = parentState && scheme !== parentState.scheme;\n\tconst nextState = {\n\t\tid,\n\t\tname,\n\t\ttheme: themes[name],\n\t\tscheme,\n\t\tparentId,\n\t\tparentName: parentState?.name,\n\t\tisInverse,\n\t\tisNew: true\n\t};\n\tif (isRoot) rootThemeState = nextState;\n\tif (pendingUpdate !== \"force\" && lastState && lastState.name === name) return [false, nextState];\n\tconst shouldAvoidRerender = pendingUpdate !== \"force\" && lastState && !needsUpdate && nextState.name === lastState.name;\n\tif (process.env.NODE_ENV === \"development\" && debug === \"verbose\") {\n\t\tconsole.groupCollapsed(` \\xB7 useTheme(${id}) \\u23ED\\uFE0F ${name} shouldAvoidRerender: ${shouldAvoidRerender}`);\n\t\tconsole.info({\n\t\t\tlastState,\n\t\t\tneedsUpdate,\n\t\t\tnextState,\n\t\t\tpendingUpdate\n\t\t});\n\t\tconsole.groupEnd();\n\t}\n\tif (shouldAvoidRerender) return [false, nextState];\n\treturn [true, nextState];\n};\nfunction scheduleUpdate(id) {\n\tconst queue = [id];\n\tconst visited = /* @__PURE__ */ new Set();\n\twhile (queue.length) {\n\t\tconst children = listenersByParent[queue.shift()];\n\t\tif (children) {\n\t\t\tfor (const childId of children) if (!visited.has(childId)) {\n\t\t\t\tvisited.add(childId);\n\t\t\t\tqueue.push(childId);\n\t\t\t}\n\t\t}\n\t}\n\tvisited.forEach((childId) => {\n\t\tallListeners.get(childId)?.();\n\t});\n}\nconst validSchemes = {\n\tlight: \"light\",\n\tdark: \"dark\"\n};\nfunction getScheme(name) {\n\treturn validSchemes[name.split(\"_\")[0]];\n}\nfunction getNewThemeName(parentName = \"\", props, forceUpdate = false) {\n\tconst { name, reset } = props;\n\tconst componentName = props.unstyled ? void 0 : props.componentName;\n\tif (name && reset) throw new Error(process.env.NODE_ENV === \"production\" ? `\\u274C004` : \"Cannot reset and set a new name at the same time.\");\n\tconst cacheKey = `${parentName}|${name || \"\"}|${componentName || \"\"}|${reset ? 1 : 0}|${forceUpdate ? 1 : 0}`;\n\tif (themeNameCacheVer !== cacheVersion) {\n\t\tthemeNameCache.clear();\n\t\tthemeNameCacheVer = cacheVersion;\n\t} else {\n\t\tconst cached = themeNameCache.get(cacheKey);\n\t\tif (cached !== void 0) return cached;\n\t}\n\tconst { themes: themes2 } = getConfig();\n\tif (reset) {\n\t\tif (parentName === \"light\" || parentName === \"dark\") {\n\t\t\tconst result2 = parentName === \"light\" ? \"dark\" : \"light\";\n\t\t\tthemeNameCache.set(cacheKey, result2);\n\t\t\treturn result2;\n\t\t}\n\t\tconst lastPartIndex = parentName.lastIndexOf(\"_\");\n\t\tconst name2 = lastPartIndex <= 0 ? parentName : parentName.slice(lastPartIndex);\n\t\tconst scheme = parentName.slice(0, lastPartIndex);\n\t\tconst result = themes2[name2] ? name2 : scheme;\n\t\tthemeNameCache.set(cacheKey, result);\n\t\treturn result;\n\t}\n\tconst parentParts = parentName.split(\"_\");\n\tconst lastName = parentParts[parentParts.length - 1];\n\tif (lastName && lastName[0].toLowerCase() !== lastName[0]) parentParts.pop();\n\tconst subNames = [\n\t\tname && componentName ? `${name}_${componentName}` : void 0,\n\t\tname,\n\t\tcomponentName\n\t].filter(Boolean);\n\tlet found = null;\n\tif (name) {\n\t\tconst nameHasScheme = getScheme(name);\n\t\tif (nameHasScheme) {\n\t\t\tfor (const subName of subNames) if (subName in themes2) {\n\t\t\t\tfound = subName;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!found && !nameHasScheme) {\n\t\t\tif (getScheme(parentName)) {\n\t\t\t\tconst potentialBases = [];\n\t\t\t\tfor (let i = parentParts.length; i >= 1; i--) potentialBases.push(parentParts.slice(0, i).join(\"_\"));\n\t\t\t\touter: for (const base of potentialBases) {\n\t\t\t\t\tconst candidates = [componentName ? `${base}_${name}_${componentName}` : void 0, `${base}_${name}`].filter(Boolean);\n\t\t\t\t\tfor (const potential of candidates) if (potential in themes2) {\n\t\t\t\t\t\tfound = potential;\n\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (!found) if (!name && componentName) {\n\t\tconst potential = `${parentParts.join(\"_\")}_${componentName}`;\n\t\tif (potential in themes2) found = potential;\n\t} else {\n\t\tconst max = parentParts.length;\n\t\tfor (let i = 0; i <= max; i++) {\n\t\t\tconst base = (i === 0 ? parentParts : parentParts.slice(0, -i)).join(\"_\");\n\t\t\tfor (const subName of subNames) {\n\t\t\t\tconst potential = base ? `${base}_${subName}` : subName;\n\t\t\t\tif (potential in themes2) {\n\t\t\t\t\tfound = potential;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (found) break;\n\t\t}\n\t}\n\tif (!forceUpdate && found === parentName && !validSchemes[found]) {\n\t\tthemeNameCache.set(cacheKey, null);\n\t\treturn null;\n\t}\n\tthemeNameCache.set(cacheKey, found);\n\treturn found;\n}\nconst getPropsKey = ({ name, reset, forceClassName, componentName }) => `${name || \"\"}${reset || \"\"}${forceClassName || \"\"}${componentName || \"\"}`;\nconst hasThemeUpdatingProps = (props) => \"name\" in props || \"reset\" in props || \"forceClassName\" in props;\n\nexport { ThemeStateContext, forceUpdateThemes, getRootThemeState, getThemeState, hasThemeUpdatingProps, useThemeState };"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,oBAAoB;AAC9D,SAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,oBAAoB,QAAQ,OAAO;AAC3F,SAASC,SAAS,QAAQ,eAAW;AACrC,SA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AS,GAAGF,IAAI,GAAG,GAAGA,IAAI,IAAIL,OAAO,EAAE,GAAGA,OAAO;QACvD,IAAIO,SAAS,IAAItB,OAAO,EAAE;UACzBa,KAAK,GAAGS,SAAS;UACjB;QACD;MACD;MACA,IAAIT,KAAK,EAAE;IACZ;EACD;EACA,IAAI,CAACnB,WAAW,IAAImB,KAAK,KAAK/B,UAAU,IAAI,CAACS,YAAY,CAACsB,KAAK,CAAC,EAAE;IACjEpG,cAAc,CAACuB,GAAG,CAAC6D,QAAQ,EAAE,IAAI,CAAC;IAClC,OAAO,IAAI;EACZ;EACApF,cAAc,CAACuB,GAAG,CAAC6D,QAAQ,EAAEgB,KAAK,CAAC;EACnC,OAAOA,KAAK;AACb;AACA,MAAM1E,WAAW,GAAGA,CAAC;EAAEV,IAAI;EAAEkE,KAAK;EAAE6B,cAAc;EAAE9F;AAAc,CAAC,KAAK,GAAGD,IAAI,IAAI,EAAE,GAAGkE,KAAK,IAAI,EAAE,GAAG6B,cAAc,IAAI,EAAE,GAAG9F,aAAa,IAAI,EAAE,EAAE;AAClJ,MAAM+F,qBAAqB,GAAI1G,KAAK,IAAK,MAAM,IAAIA,KAAK,IAAI,OAAO,IAAIA,KAAK,IAAI,gBAAgB,IAAIA,KAAK;AAEzG,SAASxB,iBAAiB,EAAEW,iBAAiB,EAAEW,iBAAiB,EAAEP,aAAa,EAAEmH,qBAAqB,EAAE3G,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["useIsomorphicLayoutEffect","createContext","useContext","useEffect","useReducer","useRef","getConfig","MISSING_THEME_MESSAGE","ThemeStateContext","allListeners","Map","listenersByParent","HasRenderedOnce","WeakMap","HadTheme","PendingUpdate","states","localStates","shouldForce","forceUpdateThemes","cacheVersion","forEach","cb","getThemeState","id","get","themeNameCache","themeNameCacheVer","themes","rootThemeState","getRootThemeState","themeStateIdCounter","nextThemeStateId","incReducer","c","useThemeState","props","isRoot","keys","schemeKeys","cascadeOnChange","disable","parentId","Error","process","env","NODE_ENV","name","componentName","theme","light","propsKey","getPropsKey","ref","current","renderVersion","globalThis","time","forceUpdate","state","getSnapshotImpl","lastSnap","r","unsubscribe","subscribedParentId","cleanupThemeSubscription","shouldSubscribeToTheme","pid","sid","next","Set","add","set","delete","cleanupThemeState","scheduleUpdate","debug","console","warn","hasThemeUpdatingProps","size","needsUpdate","local","parentState","has","_parentName","_propsKey","isSchemeOnlyChange","keysSize","allKeysSchemeOptimized","canSkipForSchemeChange","passThrough","rerender","getNextState","groupCollapsed","info","groupEnd","Object","assign","lastState","pendingUpdate","isNew","getNewThemeName","isSameAsParent","shouldRerender","Boolean","message","trace","scheme","getScheme","isInverse","nextState","parentName","shouldAvoidRerender","queue","visited","length","children","shift","childId","push","validSchemes","dark","split","reset","unstyled","cacheKey","clear","cached","themes2","result2","lastPartIndex","lastIndexOf","name2","slice","result","parentParts","lastName","toLowerCase","pop","subNames","filter","found","nameHasScheme","subName","potentialBases","i","join","outer","base","candidates","potential","max","forceClassName"],"sources":["useThemeState.mjs"],"sourcesContent":["import { useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createContext, useContext, useEffect, useReducer, useRef } from \"react\";\nimport { getConfig } from \"../config\";\nimport { MISSING_THEME_MESSAGE } from \"../constants/constants\";\n\nconst ThemeStateContext = createContext(\"\");\nconst allListeners = /* @__PURE__ */ new Map();\nconst listenersByParent = {};\nconst HasRenderedOnce = /* @__PURE__ */ new WeakMap();\nconst HadTheme = /* @__PURE__ */ new WeakMap();\nconst PendingUpdate = /* @__PURE__ */ new Map();\nconst states = /* @__PURE__ */ new Map();\nconst localStates = /* @__PURE__ */ new Map();\nlet shouldForce = false;\nconst forceUpdateThemes = () => {\n\tcacheVersion++;\n\tshouldForce = true;\n\tallListeners.forEach((cb) => cb());\n\tshouldForce = false;\n};\nconst getThemeState = (id) => states.get(id);\nlet cacheVersion = 0;\nconst themeNameCache = /* @__PURE__ */ new Map();\nlet themeNameCacheVer = -1;\nlet themes = null;\nlet rootThemeState = null;\nconst getRootThemeState = () => rootThemeState;\nlet themeStateIdCounter = 0;\nconst nextThemeStateId = () => `t${++themeStateIdCounter}`;\nconst incReducer = (c) => c + 1;\nconst useThemeState = (props, isRoot = false, keys, schemeKeys, cascadeOnChange = false) => {\n\t\"use no memo\";\n\tconst { disable } = props;\n\tconst parentId = useContext(ThemeStateContext);\n\tif (!parentId && !isRoot) throw new Error(process.env.NODE_ENV === \"development\" ? `${MISSING_THEME_MESSAGE}\n\nLooked for theme${props.name ? ` \"${props.name}\"` : \"\"}${props.componentName ? ` (component: ${props.componentName})` : \"\"}, but no parent theme context was found (parentId: ${parentId}).` : MISSING_THEME_MESSAGE);\n\tif (disable) return states.get(parentId) || {\n\t\tid: \"\",\n\t\tname: \"light\",\n\t\ttheme: getConfig().themes.light\n\t};\n\tconst propsKey = getPropsKey(props);\n\tconst ref = useRef(null);\n\tif (!ref.current) ref.current = {\n\t\tid: nextThemeStateId(),\n\t\tparentId,\n\t\tprops,\n\t\tpropsKey,\n\t\tisRoot,\n\t\tkeys,\n\t\tschemeKeys,\n\t\trenderVersion: 0\n\t};\n\telse {\n\t\tref.current.props = props;\n\t\tref.current.propsKey = propsKey;\n\t\tref.current.isRoot = isRoot;\n\t\tref.current.keys = keys;\n\t\tref.current.schemeKeys = schemeKeys;\n\t\tref.current.parentId = parentId;\n\t}\n\tref.current.renderVersion++;\n\tif (process.env.NODE_ENV === \"development\" && globalThis.time) globalThis.time`theme-prep-uses`;\n\tconst [, forceUpdate] = useReducer(incReducer, 0);\n\tconst state = getSnapshotImpl(ref.current);\n\tref.current.lastSnap = state;\n\tuseEffect(() => {\n\t\tconst r = ref.current;\n\t\tconst renderVersion = r.renderVersion;\n\t\tif (r.unsubscribe && r.subscribedParentId !== r.parentId) cleanupThemeSubscription(r);\n\t\tif (shouldSubscribeToTheme(r, cascadeOnChange)) {\n\t\t\tif (!r.unsubscribe) {\n\t\t\t\tconst pid = r.parentId;\n\t\t\t\tconst sid = r.id;\n\t\t\t\tconst cb = () => {\n\t\t\t\t\tconst next = getSnapshotImpl(r);\n\t\t\t\t\tif (next !== r.lastSnap) {\n\t\t\t\t\t\tr.lastSnap = next;\n\t\t\t\t\t\tforceUpdate();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tlistenersByParent[pid] = listenersByParent[pid] || /* @__PURE__ */ new Set();\n\t\t\t\tlistenersByParent[pid].add(sid);\n\t\t\t\tallListeners.set(sid, () => {\n\t\t\t\t\tPendingUpdate.set(sid, shouldForce ? \"force\" : true);\n\t\t\t\t\tcb();\n\t\t\t\t});\n\t\t\t\tr.subscribedParentId = pid;\n\t\t\t\tr.unsubscribe = () => {\n\t\t\t\t\tallListeners.delete(sid);\n\t\t\t\t\tlistenersByParent[pid]?.delete(sid);\n\t\t\t\t\tlocalStates.delete(sid);\n\t\t\t\t\tstates.delete(sid);\n\t\t\t\t\tPendingUpdate.delete(sid);\n\t\t\t\t\tr.unsubscribe = void 0;\n\t\t\t\t\tr.subscribedParentId = void 0;\n\t\t\t\t};\n\t\t\t}\n\t\t} else if (r.unsubscribe) cleanupThemeSubscription(r);\n\t\treturn () => {\n\t\t\tif (r.renderVersion === renderVersion) cleanupThemeState(r);\n\t\t};\n\t});\n\tconst id = ref.current.id;\n\tif (cascadeOnChange) useIsomorphicLayoutEffect(() => {\n\t\tif (!HasRenderedOnce.get(keys)) {\n\t\t\tHasRenderedOnce.set(keys, true);\n\t\t\treturn;\n\t\t}\n\t\tif (!propsKey) {\n\t\t\tif (HadTheme.get(keys)) scheduleUpdate(id);\n\t\t\tHadTheme.set(keys, false);\n\t\t\treturn;\n\t\t}\n\t\tif (process.env.NODE_ENV === \"development\" && props.debug === \"verbose\") console.warn(` \\xB7 useTheme(${id}) scheduleUpdate`, propsKey, states.get(id)?.name);\n\t\tscheduleUpdate(id);\n\t\tHadTheme.set(keys, true);\n\t}, [keys, propsKey]);\n\treturn state;\n};\nconst shouldSubscribeToTheme = (r, cascadeOnChange) => r.isRoot || cascadeOnChange || hasThemeUpdatingProps(r.props) || !!r.keys.current?.size || !!r.props.needsUpdate?.();\nfunction cleanupThemeSubscription(r) {\n\tr.unsubscribe?.();\n}\nfunction cleanupThemeState(r) {\n\tif (r.unsubscribe) cleanupThemeSubscription(r);\n\telse {\n\t\tlocalStates.delete(r.id);\n\t\tstates.delete(r.id);\n\t\tPendingUpdate.delete(r.id);\n\t}\n}\nconst getSnapshotImpl = (r) => {\n\tconst { id, parentId, props, propsKey, isRoot, keys, schemeKeys } = r;\n\tlet local = localStates.get(id);\n\tconst parentState = states.get(parentId);\n\tif (local && !PendingUpdate.has(id)) {\n\t\tif (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;\n\t}\n\tconst isSchemeOnlyChange = false;\n\tconst keysSize = keys?.current?.size ?? 0;\n\tconst allKeysSchemeOptimized = (schemeKeys?.current?.size ?? 0) === keysSize && keysSize > 0;\n\tconst canSkipForSchemeChange = isSchemeOnlyChange;\n\tconst needsUpdate = props.passThrough ? false : isRoot || props.name === \"light\" || props.name === \"dark\" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : keys?.current?.size ? true : props.needsUpdate?.();\n\tconst [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));\n\tPendingUpdate.delete(id);\n\tif (!local || rerender) {\n\t\tlocal = { ...next };\n\t\tlocalStates.set(id, local);\n\t}\n\tif (process.env.NODE_ENV === \"development\" && props.debug === \"verbose\") {\n\t\tconsole.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, \">\", next.name);\n\t\tconsole.info({\n\t\t\tprops,\n\t\t\tpropsKey,\n\t\t\tisRoot,\n\t\t\tparentId,\n\t\t\tlocal,\n\t\t\tnext,\n\t\t\tneedsUpdate,\n\t\t\tisSchemeOnlyChange,\n\t\t\tallKeysSchemeOptimized,\n\t\t\tcanSkipForSchemeChange\n\t\t});\n\t\tconsole.groupEnd();\n\t}\n\tif (next !== local) {\n\t\tObject.assign(local, next);\n\t\tlocal.id = id;\n\t}\n\tlocal._parentName = parentState?.name;\n\tlocal._propsKey = propsKey;\n\tstates.set(id, next);\n\treturn local;\n};\nconst getNextState = (lastState, props, propsKey, isRoot = false, id, parentId, needsUpdate, pendingUpdate) => {\n\tconst { debug } = props;\n\tconst parentState = states.get(parentId);\n\tif (props.passThrough) return [false, lastState || parentState || { name: \"\" }];\n\tif (!themes) themes = getConfig().themes;\n\tconst name = !propsKey && (!lastState || !lastState?.isNew) ? null : getNewThemeName(parentState?.name, props, pendingUpdate === \"force\" ? true : !!needsUpdate);\n\tconst isSameAsParent = parentState && (!name || name === parentState.name);\n\tconst shouldRerender = Boolean(pendingUpdate === \"force\" || needsUpdate && (pendingUpdate || lastState?.name !== parentState?.name));\n\tif (process.env.NODE_ENV === \"development\" && debug === \"verbose\") {\n\t\tconst message = ` \\xB7 useTheme(${id}) getNextState => ${name} needsUpdate ${needsUpdate} shouldRerender ${shouldRerender}`;\n\t\tconsole.groupCollapsed(message);\n\t\tconsole.trace({\n\t\t\tname,\n\t\t\tlastState,\n\t\t\tparentState,\n\t\t\tprops,\n\t\t\tpropsKey,\n\t\t\tid,\n\t\t\tisSameAsParent\n\t\t});\n\t\tconsole.groupEnd();\n\t}\n\tif (isSameAsParent) {\n\t\tif (!shouldRerender && lastState && lastState.name === parentState.name) return [false, lastState];\n\t\treturn [shouldRerender, {\n\t\t\t...parentState,\n\t\t\tisNew: false\n\t\t}];\n\t}\n\tif (!name) {\n\t\tconst next = lastState ?? parentState;\n\t\tif (!next) throw new Error(process.env.NODE_ENV === \"development\" ? `${MISSING_THEME_MESSAGE}\n\nLooked for theme${props.name ? ` \"${props.name}\"` : \"\"}${props.componentName ? ` (component: ${props.componentName})` : \"\"}, but no theme state was resolved (parentId: ${parentId}, id: ${id}).` : MISSING_THEME_MESSAGE);\n\t\tif (shouldRerender) return [true, { ...parentState || lastState }];\n\t\treturn [false, next];\n\t}\n\tconst scheme = getScheme(name);\n\tconst isInverse = parentState && scheme !== parentState.scheme;\n\tconst nextState = {\n\t\tid,\n\t\tname,\n\t\ttheme: themes[name],\n\t\tscheme,\n\t\tparentId,\n\t\tparentName: parentState?.name,\n\t\tisInverse,\n\t\tisNew: true\n\t};\n\tif (isRoot) rootThemeState = nextState;\n\tif (pendingUpdate !== \"force\" && lastState && lastState.name === name) return [false, nextState];\n\tconst shouldAvoidRerender = pendingUpdate !== \"force\" && lastState && !needsUpdate && nextState.name === lastState.name;\n\tif (process.env.NODE_ENV === \"development\" && debug === \"verbose\") {\n\t\tconsole.groupCollapsed(` \\xB7 useTheme(${id}) \\u23ED\\uFE0F ${name} shouldAvoidRerender: ${shouldAvoidRerender}`);\n\t\tconsole.info({\n\t\t\tlastState,\n\t\t\tneedsUpdate,\n\t\t\tnextState,\n\t\t\tpendingUpdate\n\t\t});\n\t\tconsole.groupEnd();\n\t}\n\tif (shouldAvoidRerender) return [false, nextState];\n\treturn [true, nextState];\n};\nfunction scheduleUpdate(id) {\n\tconst queue = [id];\n\tconst visited = /* @__PURE__ */ new Set();\n\twhile (queue.length) {\n\t\tconst children = listenersByParent[queue.shift()];\n\t\tif (children) {\n\t\t\tfor (const childId of children) if (!visited.has(childId)) {\n\t\t\t\tvisited.add(childId);\n\t\t\t\tqueue.push(childId);\n\t\t\t}\n\t\t}\n\t}\n\tvisited.forEach((childId) => {\n\t\tallListeners.get(childId)?.();\n\t});\n}\nconst validSchemes = {\n\tlight: \"light\",\n\tdark: \"dark\"\n};\nfunction getScheme(name) {\n\treturn validSchemes[name.split(\"_\")[0]];\n}\nfunction getNewThemeName(parentName = \"\", props, forceUpdate = false) {\n\tconst { name, reset } = props;\n\tconst componentName = props.unstyled ? void 0 : props.componentName;\n\tif (name && reset) throw new Error(process.env.NODE_ENV === \"production\" ? `\\u274C004` : \"Cannot reset and set a new name at the same time.\");\n\tconst cacheKey = `${parentName}|${name || \"\"}|${componentName || \"\"}|${reset ? 1 : 0}|${forceUpdate ? 1 : 0}`;\n\tif (themeNameCacheVer !== cacheVersion) {\n\t\tthemeNameCache.clear();\n\t\tthemeNameCacheVer = cacheVersion;\n\t} else {\n\t\tconst cached = themeNameCache.get(cacheKey);\n\t\tif (cached !== void 0) return cached;\n\t}\n\tconst { themes: themes2 } = getConfig();\n\tif (reset) {\n\t\tif (parentName === \"light\" || parentName === \"dark\") {\n\t\t\tconst result2 = parentName === \"light\" ? \"dark\" : \"light\";\n\t\t\tthemeNameCache.set(cacheKey, result2);\n\t\t\treturn result2;\n\t\t}\n\t\tconst lastPartIndex = parentName.lastIndexOf(\"_\");\n\t\tconst name2 = lastPartIndex <= 0 ? parentName : parentName.slice(lastPartIndex);\n\t\tconst scheme = parentName.slice(0, lastPartIndex);\n\t\tconst result = themes2[name2] ? name2 : scheme;\n\t\tthemeNameCache.set(cacheKey, result);\n\t\treturn result;\n\t}\n\tconst parentParts = parentName.split(\"_\");\n\tconst lastName = parentParts[parentParts.length - 1];\n\tif (lastName && lastName[0].toLowerCase() !== lastName[0]) parentParts.pop();\n\tconst subNames = [\n\t\tname && componentName ? `${name}_${componentName}` : void 0,\n\t\tname,\n\t\tcomponentName\n\t].filter(Boolean);\n\tlet found = null;\n\tif (name) {\n\t\tconst nameHasScheme = getScheme(name);\n\t\tif (nameHasScheme) {\n\t\t\tfor (const subName of subNames) if (subName in themes2) {\n\t\t\t\tfound = subName;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!found && !nameHasScheme) {\n\t\t\tif (getScheme(parentName)) {\n\t\t\t\tconst potentialBases = [];\n\t\t\t\tfor (let i = parentParts.length; i >= 1; i--) potentialBases.push(parentParts.slice(0, i).join(\"_\"));\n\t\t\t\touter: for (const base of potentialBases) {\n\t\t\t\t\tconst candidates = [componentName ? `${base}_${name}_${componentName}` : void 0, `${base}_${name}`].filter(Boolean);\n\t\t\t\t\tfor (const potential of candidates) if (potential in themes2) {\n\t\t\t\t\t\tfound = potential;\n\t\t\t\t\t\tbreak outer;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (!found) if (!name && componentName) {\n\t\tconst potential = `${parentParts.join(\"_\")}_${componentName}`;\n\t\tif (potential in themes2) found = potential;\n\t} else {\n\t\tconst max = parentParts.length;\n\t\tfor (let i = 0; i <= max; i++) {\n\t\t\tconst base = (i === 0 ? parentParts : parentParts.slice(0, -i)).join(\"_\");\n\t\t\tfor (const subName of subNames) {\n\t\t\t\tconst potential = base ? `${base}_${subName}` : subName;\n\t\t\t\tif (potential in themes2) {\n\t\t\t\t\tfound = potential;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (found) break;\n\t\t}\n\t}\n\tif (!forceUpdate && found === parentName && !validSchemes[found]) {\n\t\tthemeNameCache.set(cacheKey, null);\n\t\treturn null;\n\t}\n\tthemeNameCache.set(cacheKey, found);\n\treturn found;\n}\nconst getPropsKey = ({ name, reset, forceClassName, componentName }) => `${name || \"\"}${reset || \"\"}${forceClassName || \"\"}${componentName || \"\"}`;\nconst hasThemeUpdatingProps = (props) => \"name\" in props || \"reset\" in props || \"forceClassName\" in props;\n\nexport { ThemeStateContext, forceUpdateThemes, getRootThemeState, getThemeState, hasThemeUpdatingProps, useThemeState };"],"mappings":"AAAA,SAASA,yBAAyB,QAAQ,oBAAoB;AAC9D,SAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AAChF,SAASC,SAAS,QAAQ,eAAW;AACrC,SAASC,qBAAqB,QAAQ,4BAAwB;AAE9D,MAAMC,iBAAiB,GAAGP,aAAa,CAAC,EAAE,CAAC;AAC3C,MAAMQ,YAAY,GAAG,eAAgB,IAAIC,GAAG,CAAC,CAAC;AAC9C,MAAMC,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAMC,eAAe,GAAG,eAAgB,IAAIC,OAAO,CAAC,CAAC;AACrD,MAAMC,QAAQ,GAAG,eAAgB,IAAID,OAAO,CAAC,CAAC;AAC9C,MAAME,aAAa,GAAG,eAAg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O,EAAE,GAAGA,OAAO;QACvD,IAAIO,SAAS,IAAItB,OAAO,EAAE;UACzBa,KAAK,GAAGS,SAAS;UACjB;QACD;MACD;MACA,IAAIT,KAAK,EAAE;IACZ;EACD;EACA,IAAI,CAACpF,WAAW,IAAIoF,KAAK,KAAK9B,UAAU,IAAI,CAACS,YAAY,CAACqB,KAAK,CAAC,EAAE;IACjEpH,cAAc,CAAC8C,GAAG,CAACsD,QAAQ,EAAE,IAAI,CAAC;IAClC,OAAO,IAAI;EACZ;EACApG,cAAc,CAAC8C,GAAG,CAACsD,QAAQ,EAAEgB,KAAK,CAAC;EACnC,OAAOA,KAAK;AACb;AACA,MAAM1F,WAAW,GAAGA,CAAC;EAAEL,IAAI;EAAE6E,KAAK;EAAE6B,cAAc;EAAEzG;AAAc,CAAC,KAAK,GAAGD,IAAI,IAAI,EAAE,GAAG6E,KAAK,IAAI,EAAE,GAAG6B,cAAc,IAAI,EAAE,GAAGzG,aAAa,IAAI,EAAE,EAAE;AAClJ,MAAM+B,qBAAqB,GAAI3C,KAAK,IAAK,MAAM,IAAIA,KAAK,IAAI,OAAO,IAAIA,KAAK,IAAI,gBAAgB,IAAIA,KAAK;AAEzG,SAAS5B,iBAAiB,EAAEW,iBAAiB,EAAEW,iBAAiB,EAAEP,aAAa,EAAEwD,qBAAqB,EAAE5C,aAAa","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  import { supportsDynamicColorIOS, useIsomorphicLayoutEffect } from "@tamagui/constants";
2
- import { createContext, useCallback, useContext, useId, useSyncExternalStore } from "react";
2
+ import { createContext, useContext, useEffect, useReducer, useRef } from "react";
3
3
  import { getConfig, getSetting } from "../config.native.js";
4
4
  import { MISSING_THEME_MESSAGE } from "../constants/constants.native.js";
5
5
  var ThemeStateContext = createContext("");
@@ -33,12 +33,20 @@ var getRootThemeState = function () {
33
33
  var getThemeBaseName = function (name) {
34
34
  return name.replace(/^(light|dark)_/, "");
35
35
  };
36
+ var themeStateIdCounter = 0;
37
+ var nextThemeStateId = function () {
38
+ return `t${++themeStateIdCounter}`;
39
+ };
40
+ var incReducer = function (c) {
41
+ return c + 1;
42
+ };
36
43
  var useThemeState = function (props) {
37
44
  "use no memo";
38
45
 
39
46
  var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false,
40
47
  keys = arguments.length > 2 ? arguments[2] : void 0,
41
- schemeKeys = arguments.length > 3 ? arguments[3] : void 0;
48
+ schemeKeys = arguments.length > 3 ? arguments[3] : void 0,
49
+ cascadeOnChange = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : false;
42
50
  var {
43
51
  disable
44
52
  } = props;
@@ -51,73 +59,70 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
51
59
  name: "light",
52
60
  theme: getConfig().themes.light
53
61
  };
54
- var id = useId();
55
- var subscribe = useCallback(function (cb) {
56
- listenersByParent[parentId] = listenersByParent[parentId] || /* @__PURE__ */new Set();
57
- listenersByParent[parentId].add(id);
58
- allListeners.set(id, function () {
59
- PendingUpdate.set(id, shouldForce ? "force" : true);
60
- cb();
61
- });
62
- return function () {
63
- allListeners.delete(id);
64
- listenersByParent[parentId].delete(id);
65
- localStates.delete(id);
66
- states.delete(id);
67
- PendingUpdate.delete(id);
68
- };
69
- }, [id, parentId]);
70
62
  var propsKey = getPropsKey(props);
71
- var getSnapshot = function () {
72
- var _keys_current, _schemeKeys_current, _keys_current1, _props_needsUpdate;
73
- var local = localStates.get(id);
74
- var parentState = states.get(parentId);
75
- if (local && !PendingUpdate.has(id)) {
76
- if (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;
77
- }
78
- var isSchemeOnlyChange = supportsDynamicColorIOS && getSetting("fastSchemeChange") && local && parentState && local.scheme !== parentState.scheme && getThemeBaseName(local.name) === getThemeBaseName(parentState.name);
79
- var _keys_current_size;
80
- var keysSize = (_keys_current_size = keys === null || keys === void 0 ? void 0 : (_keys_current = keys.current) === null || _keys_current === void 0 ? void 0 : _keys_current.size) !== null && _keys_current_size !== void 0 ? _keys_current_size : 0;
81
- var _schemeKeys_current_size;
82
- var allKeysSchemeOptimized = ((_schemeKeys_current_size = schemeKeys === null || schemeKeys === void 0 ? void 0 : (_schemeKeys_current = schemeKeys.current) === null || _schemeKeys_current === void 0 ? void 0 : _schemeKeys_current.size) !== null && _schemeKeys_current_size !== void 0 ? _schemeKeys_current_size : 0) === keysSize && keysSize > 0;
83
- var canSkipForSchemeChange = isSchemeOnlyChange && allKeysSchemeOptimized;
84
- var needsUpdate = props.passThrough ? false : isRoot || props.name === "light" || props.name === "dark" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : canSkipForSchemeChange ? false : (keys === null || keys === void 0 ? void 0 : (_keys_current1 = keys.current) === null || _keys_current1 === void 0 ? void 0 : _keys_current1.size) ? true : (_props_needsUpdate = props.needsUpdate) === null || _props_needsUpdate === void 0 ? void 0 : _props_needsUpdate.call(props);
85
- var [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));
86
- PendingUpdate.delete(id);
87
- if (!local || rerender) {
88
- local = {
89
- ...next
90
- };
91
- localStates.set(id, local);
92
- }
93
- if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
94
- console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
95
- console.info({
96
- props,
97
- propsKey,
98
- isRoot,
99
- parentId,
100
- local,
101
- next,
102
- needsUpdate,
103
- isSchemeOnlyChange,
104
- allKeysSchemeOptimized,
105
- canSkipForSchemeChange
106
- });
107
- console.groupEnd();
108
- }
109
- if (next !== local) {
110
- Object.assign(local, next);
111
- local.id = id;
112
- }
113
- local._parentName = parentState === null || parentState === void 0 ? void 0 : parentState.name;
114
- local._propsKey = propsKey;
115
- states.set(id, next);
116
- return local;
117
- };
63
+ var ref = useRef(null);
64
+ if (!ref.current) ref.current = {
65
+ id: nextThemeStateId(),
66
+ parentId,
67
+ props,
68
+ propsKey,
69
+ isRoot,
70
+ keys,
71
+ schemeKeys,
72
+ renderVersion: 0
73
+ };else {
74
+ ref.current.props = props;
75
+ ref.current.propsKey = propsKey;
76
+ ref.current.isRoot = isRoot;
77
+ ref.current.keys = keys;
78
+ ref.current.schemeKeys = schemeKeys;
79
+ ref.current.parentId = parentId;
80
+ }
81
+ ref.current.renderVersion++;
118
82
  if (process.env.NODE_ENV === "development" && globalThis.time) globalThis.time`theme-prep-uses`;
119
- var state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
120
- useIsomorphicLayoutEffect(function () {
83
+ var [, forceUpdate] = useReducer(incReducer, 0);
84
+ var state = getSnapshotImpl(ref.current);
85
+ ref.current.lastSnap = state;
86
+ useEffect(function () {
87
+ var r = ref.current;
88
+ var renderVersion = r.renderVersion;
89
+ if (r.unsubscribe && r.subscribedParentId !== r.parentId) cleanupThemeSubscription(r);
90
+ if (shouldSubscribeToTheme(r, cascadeOnChange)) {
91
+ if (!r.unsubscribe) {
92
+ var pid = r.parentId;
93
+ var sid = r.id;
94
+ var cb = function () {
95
+ var next = getSnapshotImpl(r);
96
+ if (next !== r.lastSnap) {
97
+ r.lastSnap = next;
98
+ forceUpdate();
99
+ }
100
+ };
101
+ listenersByParent[pid] = listenersByParent[pid] || /* @__PURE__ */new Set();
102
+ listenersByParent[pid].add(sid);
103
+ allListeners.set(sid, function () {
104
+ PendingUpdate.set(sid, shouldForce ? "force" : true);
105
+ cb();
106
+ });
107
+ r.subscribedParentId = pid;
108
+ r.unsubscribe = function () {
109
+ var _listenersByParent_pid;
110
+ allListeners.delete(sid);
111
+ (_listenersByParent_pid = listenersByParent[pid]) === null || _listenersByParent_pid === void 0 || _listenersByParent_pid.delete(sid);
112
+ localStates.delete(sid);
113
+ states.delete(sid);
114
+ PendingUpdate.delete(sid);
115
+ r.unsubscribe = void 0;
116
+ r.subscribedParentId = void 0;
117
+ };
118
+ }
119
+ } else if (r.unsubscribe) cleanupThemeSubscription(r);
120
+ return function () {
121
+ if (r.renderVersion === renderVersion) cleanupThemeState(r);
122
+ };
123
+ });
124
+ var id = ref.current.id;
125
+ if (cascadeOnChange) useIsomorphicLayoutEffect(function () {
121
126
  if (!HasRenderedOnce.get(keys)) {
122
127
  HasRenderedOnce.set(keys, true);
123
128
  return;
@@ -136,6 +141,77 @@ Looked for theme${props.name ? ` "${props.name}"` : ""}${props.componentName ? `
136
141
  }, [keys, propsKey]);
137
142
  return state;
138
143
  };
144
+ var shouldSubscribeToTheme = function (r, cascadeOnChange) {
145
+ var _r_keys_current, _r_props_needsUpdate, _r_props;
146
+ return r.isRoot || cascadeOnChange || hasThemeUpdatingProps(r.props) || !!((_r_keys_current = r.keys.current) === null || _r_keys_current === void 0 ? void 0 : _r_keys_current.size) || !!((_r_props_needsUpdate = (_r_props = r.props).needsUpdate) === null || _r_props_needsUpdate === void 0 ? void 0 : _r_props_needsUpdate.call(_r_props));
147
+ };
148
+ function cleanupThemeSubscription(r) {
149
+ var _r_unsubscribe;
150
+ (_r_unsubscribe = r.unsubscribe) === null || _r_unsubscribe === void 0 || _r_unsubscribe.call(r);
151
+ }
152
+ function cleanupThemeState(r) {
153
+ if (r.unsubscribe) cleanupThemeSubscription(r);else {
154
+ localStates.delete(r.id);
155
+ states.delete(r.id);
156
+ PendingUpdate.delete(r.id);
157
+ }
158
+ }
159
+ var getSnapshotImpl = function (r) {
160
+ var _keys_current, _schemeKeys_current, _keys_current1, _props_needsUpdate;
161
+ var {
162
+ id,
163
+ parentId,
164
+ props,
165
+ propsKey,
166
+ isRoot,
167
+ keys,
168
+ schemeKeys
169
+ } = r;
170
+ var local = localStates.get(id);
171
+ var parentState = states.get(parentId);
172
+ if (local && !PendingUpdate.has(id)) {
173
+ if (parentState && local._parentName === parentState.name && local._propsKey === propsKey) return local;
174
+ }
175
+ var isSchemeOnlyChange = supportsDynamicColorIOS && getSetting("fastSchemeChange") && local && parentState && local.scheme !== parentState.scheme && getThemeBaseName(local.name) === getThemeBaseName(parentState.name);
176
+ var _keys_current_size;
177
+ var keysSize = (_keys_current_size = keys === null || keys === void 0 ? void 0 : (_keys_current = keys.current) === null || _keys_current === void 0 ? void 0 : _keys_current.size) !== null && _keys_current_size !== void 0 ? _keys_current_size : 0;
178
+ var _schemeKeys_current_size;
179
+ var allKeysSchemeOptimized = ((_schemeKeys_current_size = schemeKeys === null || schemeKeys === void 0 ? void 0 : (_schemeKeys_current = schemeKeys.current) === null || _schemeKeys_current === void 0 ? void 0 : _schemeKeys_current.size) !== null && _schemeKeys_current_size !== void 0 ? _schemeKeys_current_size : 0) === keysSize && keysSize > 0;
180
+ var canSkipForSchemeChange = isSchemeOnlyChange && allKeysSchemeOptimized;
181
+ var needsUpdate = props.passThrough ? false : isRoot || props.name === "light" || props.name === "dark" || props.name === null ? true : !HasRenderedOnce.get(keys) ? true : canSkipForSchemeChange ? false : (keys === null || keys === void 0 ? void 0 : (_keys_current1 = keys.current) === null || _keys_current1 === void 0 ? void 0 : _keys_current1.size) ? true : (_props_needsUpdate = props.needsUpdate) === null || _props_needsUpdate === void 0 ? void 0 : _props_needsUpdate.call(props);
182
+ var [rerender, next] = getNextState(local, props, propsKey, isRoot, id, parentId, needsUpdate, PendingUpdate.get(id));
183
+ PendingUpdate.delete(id);
184
+ if (!local || rerender) {
185
+ local = {
186
+ ...next
187
+ };
188
+ localStates.set(id, local);
189
+ }
190
+ if (process.env.NODE_ENV === "development" && props.debug === "verbose") {
191
+ console.groupCollapsed(` ${id} getSnapshot ${rerender}`, local.name, ">", next.name);
192
+ console.info({
193
+ props,
194
+ propsKey,
195
+ isRoot,
196
+ parentId,
197
+ local,
198
+ next,
199
+ needsUpdate,
200
+ isSchemeOnlyChange,
201
+ allKeysSchemeOptimized,
202
+ canSkipForSchemeChange
203
+ });
204
+ console.groupEnd();
205
+ }
206
+ if (next !== local) {
207
+ Object.assign(local, next);
208
+ local.id = id;
209
+ }
210
+ local._parentName = parentState === null || parentState === void 0 ? void 0 : parentState.name;
211
+ local._propsKey = propsKey;
212
+ states.set(id, next);
213
+ return local;
214
+ };
139
215
  var getNextState = function (lastState, props, propsKey) {
140
216
  var isRoot = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false,
141
217
  id = arguments.length > 4 ? arguments[4] : void 0,