@tamagui/core 1.124.4 → 1.124.5

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.
package/dist/native.js CHANGED
@@ -6209,20 +6209,23 @@ var require_useThemeState_native = __commonJS({
6209
6209
  hasThemeUpdatingProps: function() {
6210
6210
  return hasThemeUpdatingProps;
6211
6211
  },
6212
+ keysToId: function() {
6213
+ return keysToId;
6214
+ },
6212
6215
  useThemeState: function() {
6213
6216
  return useThemeState;
6214
6217
  }
6215
6218
  });
6216
6219
  module2.exports = __toCommonJS2(useThemeState_exports);
6217
- var import_constants2 = require_index_native2(), import_react3 = require("react"), import_config = require_config_native(), ThemeStateContext = (0, import_react3.createContext)(""), allListeners = /* @__PURE__ */ new Map(), listenersByParent = {}, states = /* @__PURE__ */ new Map(), forceUpdateThemes2 = function() {
6218
- allListeners.forEach(function(cb) {
6220
+ var import_constants2 = require_index_native2(), import_react3 = require("react"), import_config = require_config_native(), ThemeStateContext = (0, import_react3.createContext)(""), keysToId = /* @__PURE__ */ new WeakMap(), allListeners = /* @__PURE__ */ new Map(), listenersByParent = {}, hasRenderedOnce = /* @__PURE__ */ new WeakMap(), pendingUpdate = /* @__PURE__ */ new Map(), states = /* @__PURE__ */ new Map(), shouldForce = !1, forceUpdateThemes2 = function() {
6221
+ cacheVersion++, shouldForce = !0, allListeners.forEach(function(cb) {
6219
6222
  return cb();
6220
6223
  });
6221
6224
  }, getThemeState = function(id) {
6222
6225
  return states.get(id);
6223
- }, rootThemeState = null, getRootThemeState = function() {
6226
+ }, cache2 = /* @__PURE__ */ new Map(), cacheVersion = 0, themes = null, rootThemeState = null, getRootThemeState = function() {
6224
6227
  return rootThemeState;
6225
- }, HasRenderedOnce = /* @__PURE__ */ new WeakMap(), useThemeState = function(props) {
6228
+ }, useThemeState = function(props) {
6226
6229
  var isRoot = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1, keys = arguments.length > 2 ? arguments[2] : void 0, { disable } = props, parentId = (0, import_react3.useContext)(ThemeStateContext);
6227
6230
  if (disable) return states.get(parentId) || {
6228
6231
  id: "",
@@ -6232,24 +6235,28 @@ var require_useThemeState_native = __commonJS({
6232
6235
  };
6233
6236
  var id = (0, import_react3.useId)(), subscribe = (0, import_react3.useCallback)(function(cb) {
6234
6237
  var _listenersByParent, _parentId;
6235
- return (_listenersByParent = listenersByParent)[_parentId = parentId] || (_listenersByParent[_parentId] = /* @__PURE__ */ new Set()), listenersByParent[parentId].add(id), allListeners.set(id, cb), function() {
6238
+ return (_listenersByParent = listenersByParent)[_parentId = parentId] || (_listenersByParent[_parentId] = /* @__PURE__ */ new Set()), listenersByParent[parentId].add(id), allListeners.set(id, function() {
6239
+ pendingUpdate.set(id, shouldForce ? "force" : !0), cb();
6240
+ }), function() {
6236
6241
  allListeners.delete(id), listenersByParent[parentId].delete(id);
6237
6242
  };
6238
6243
  }, [
6239
6244
  id,
6240
- parentId,
6241
- keys
6245
+ parentId
6242
6246
  ]), propsKey = getPropsKey(props), getSnapshot = function() {
6243
- return getSnapshotFrom(props, propsKey, isRoot, id, parentId, keys);
6247
+ var _keys_current, _props_needsUpdate, last = states.get(id), needsUpdate = props.name === "light" || props.name === "dark" ? !0 : hasRenderedOnce.get(keys) ? !(keys == null || (_keys_current = keys.current) === null || _keys_current === void 0) && _keys_current.size ? !0 : (_props_needsUpdate = props.needsUpdate) === null || _props_needsUpdate === void 0 ? void 0 : _props_needsUpdate.call(props) : !0, parentState = states.get(parentId), cacheKey = `${cacheVersion}${id}${propsKey}${(parentState == null ? void 0 : parentState.name) || ""}${isRoot}`;
6248
+ if (!needsUpdate && cache2.has(cacheKey)) return cache2.get(cacheKey);
6249
+ var next = getSnapshotFrom(last, props, propsKey, isRoot, id, parentId, needsUpdate, pendingUpdate.get(id));
6250
+ return last !== next && (pendingUpdate.delete(id), states.set(id, next), cache2.set(id, next), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.warn(` \xB7 useTheme(${id}) UPDATE from`, last, "to", next)), next;
6244
6251
  };
6245
6252
  process.env.NODE_ENV === "development" && globalThis.time && globalThis.time`theme-prep-uses`;
6246
6253
  var state = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
6247
6254
  return (0, import_constants2.useIsomorphicLayoutEffect)(function() {
6255
+ if (!hasRenderedOnce.get(keys)) {
6256
+ hasRenderedOnce.set(keys, !0);
6257
+ return;
6258
+ }
6248
6259
  if (propsKey) {
6249
- if (!HasRenderedOnce.has(keys)) {
6250
- HasRenderedOnce.set(keys, !0);
6251
- return;
6252
- }
6253
6260
  if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
6254
6261
  var _states_get;
6255
6262
  console.warn(` \xB7 useTheme(${id}) scheduleUpdate`, propsKey, (_states_get = states.get(id)) === null || _states_get === void 0 ? void 0 : _states_get.name);
@@ -6259,29 +6266,30 @@ var require_useThemeState_native = __commonJS({
6259
6266
  }, [
6260
6267
  keys,
6261
6268
  propsKey
6262
- ]), process.env.NODE_ENV === "development" && props.debug && (console.groupCollapsed(` \xB7 useTheme(${id}) =>`, state.name, id === state.id ? "\u{1F389}" : "\u23ED\uFE0F"), console.info({
6263
- state,
6264
- parentId,
6265
- props,
6266
- propsKey,
6267
- id,
6268
- parentState: states.get(parentId)
6269
- }), console.groupEnd()), state.id === id ? {
6269
+ ]), state.id === id ? {
6270
6270
  ...state,
6271
6271
  isNew: !0
6272
6272
  } : state;
6273
- }, themes = null, getSnapshotFrom = function(props, propsKey) {
6274
- var isRoot = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1, id = arguments.length > 3 ? arguments[3] : void 0, parentId = arguments.length > 4 ? arguments[4] : void 0, keys = arguments.length > 5 ? arguments[5] : void 0, _keys_current, _props_needsUpdate, needsUpdate = (keys == null || (_keys_current = keys.current) === null || _keys_current === void 0 ? void 0 : _keys_current.size) || ((_props_needsUpdate = props.needsUpdate) === null || _props_needsUpdate === void 0 ? void 0 : _props_needsUpdate.call(props)), parentState = states.get(parentId);
6273
+ }, getSnapshotFrom = function(lastState, props, propsKey) {
6274
+ var isRoot = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, id = arguments.length > 4 ? arguments[4] : void 0, parentId = arguments.length > 5 ? arguments[5] : void 0, needsUpdate = arguments.length > 6 ? arguments[6] : void 0, pendingUpdate2 = arguments.length > 7 ? arguments[7] : void 0, parentState = states.get(parentId);
6275
6275
  themes || (themes = (0, import_config.getConfig)().themes);
6276
- var lastState = states.get(id), name = propsKey ? getNewThemeName(parentState == null ? void 0 : parentState.name, props, !!needsUpdate) : null;
6276
+ var name = !propsKey && pendingUpdate2 !== "force" ? null : getNewThemeName(parentState == null ? void 0 : parentState.name, props, pendingUpdate2 === "force" ? !0 : !!needsUpdate), isSameAsParent = !!(!name && propsKey);
6277
6277
  if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
6278
6278
  var message = ` \xB7 useTheme(${id}) snapshot ${name}, parent ${parentState == null ? void 0 : parentState.id} needsUpdate ${needsUpdate}`;
6279
6279
  console.info(message);
6280
6280
  }
6281
- var isSameAsParent = !name && propsKey;
6282
6281
  if (parentState && isSameAsParent) return parentState;
6283
- if (!name) return lastState && !needsUpdate ? lastState : (states.set(id, parentState), parentState);
6284
- if (lastState && lastState.name === name) return lastState;
6282
+ if (!name) {
6283
+ var next = lastState ?? parentState;
6284
+ if (needsUpdate && pendingUpdate2) {
6285
+ var updated = {
6286
+ ...parentState || lastState
6287
+ };
6288
+ return updated;
6289
+ }
6290
+ return next;
6291
+ }
6292
+ if (pendingUpdate2 !== "force" && lastState && lastState.name === name) return lastState;
6285
6293
  var scheme = getScheme(name), _parentState_inverses, parentInverses = (_parentState_inverses = parentState == null ? void 0 : parentState.inverses) !== null && _parentState_inverses !== void 0 ? _parentState_inverses : 0, isInverse = parentState && scheme !== parentState.scheme, inverses = parentInverses + (isInverse ? 1 : 0), nextState = {
6286
6294
  id,
6287
6295
  name,
@@ -6292,7 +6300,7 @@ var require_useThemeState_native = __commonJS({
6292
6300
  inverses,
6293
6301
  isInverse
6294
6302
  };
6295
- return process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && (console.groupCollapsed(` \xB7 useTheme(${id}) \u23ED\uFE0F ${name}`), console.info("state", nextState), console.groupEnd()), states.set(id, nextState), isRoot && (rootThemeState = nextState), nextState;
6303
+ return process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && (console.groupCollapsed(` \xB7 useTheme(${id}) \u23ED\uFE0F2 ${name}`), console.info("state", nextState), console.groupEnd()), isRoot && (rootThemeState = nextState), pendingUpdate2 !== "force" && lastState && !needsUpdate ? (Object.assign(lastState, nextState), lastState) : nextState;
6296
6304
  };
6297
6305
  function scheduleUpdate(id) {
6298
6306
  for (var queue = [
@@ -6330,7 +6338,7 @@ var require_useThemeState_native = __commonJS({
6330
6338
  return validSchemes[name.split("_")[0]];
6331
6339
  }
6332
6340
  function getNewThemeName() {
6333
- var parentName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", { name, reset, componentName, inverse } = arguments.length > 1 ? arguments[1] : void 0, forceUpdate = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
6341
+ var parentName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", { name, reset, componentName, inverse, debug } = arguments.length > 1 ? arguments[1] : void 0, forceUpdate = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !1;
6334
6342
  if (name && reset) throw new Error(process.env.NODE_ENV === "production" ? "\u274C004" : "Cannot reset and set a new name at the same time.");
6335
6343
  if (reset) {
6336
6344
  if (!parentName) throw new Error("\u203C\uFE0F");
@@ -6364,7 +6372,8 @@ var require_useThemeState_native = __commonJS({
6364
6372
  }
6365
6373
  if (found) break;
6366
6374
  }
6367
- if (found && inverse) {
6375
+ if (inverse) {
6376
+ found || (found = parentName);
6368
6377
  var scheme = found.split("_")[0];
6369
6378
  found = found.replace(new RegExp(`^${scheme}`), scheme === "light" ? "dark" : "light");
6370
6379
  }
@@ -6475,41 +6484,45 @@ var require_getThemeProxied_native = __commonJS({
6475
6484
  }
6476
6485
  });
6477
6486
  module2.exports = __toCommonJS2(getThemeProxied_exports);
6478
- var import_constants2 = require_index_native2(), import_config = require_config_native(), import_createVariable = require_createVariable_native(), import_doesRootSchemeMatchSystem = require_doesRootSchemeMatchSystem_native(), cache2 = /* @__PURE__ */ new Map(), curKeys, curProps, emptyObject = {};
6479
- function getThemeProxied(_props, state, _keys) {
6480
- var theme = state == null ? void 0 : state.theme;
6481
- if (!theme) return emptyObject;
6482
- if (curKeys = _keys, curProps = _props, cache2.has(theme)) {
6483
- var proxied = cache2.get(theme);
6487
+ var import_constants2 = require_index_native2(), import_config = require_config_native(), import_createVariable = require_createVariable_native(), import_doesRootSchemeMatchSystem = require_doesRootSchemeMatchSystem_native(), import_useThemeState = require_useThemeState_native(), cache2 = /* @__PURE__ */ new Map(), curKeys, curProps, curState, emptyObject = {};
6488
+ function getThemeProxied(_props, _state, _keys) {
6489
+ if (!(_state != null && _state.theme)) return emptyObject;
6490
+ if (curKeys = _keys, curProps = _props, curState = _state, cache2.has(curState.theme)) {
6491
+ var proxied = cache2.get(curState.theme);
6484
6492
  return proxied;
6485
6493
  }
6486
- var { name, scheme } = state, config = (0, import_config.getConfig)();
6494
+ var config = (0, import_config.getConfig)();
6487
6495
  function track(key) {
6488
- curKeys && (curKeys.current || (curKeys.current = /* @__PURE__ */ new Set()), curKeys.current.add(key), process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
6496
+ if (curKeys && (curKeys.current || (curKeys.current = /* @__PURE__ */ new Set()), curKeys.current.add(key), process.env.NODE_ENV === "development" && curProps.debug)) {
6497
+ var _globalThis_states, realId = import_useThemeState.keysToId.get(curKeys);
6498
+ console.info(` \u{1F3A8} useTheme(${realId}) tracking new key: ${key}`, curKeys, (_globalThis_states = globalThis.states) === null || _globalThis_states === void 0 ? void 0 : _globalThis_states.get(realId + 1));
6499
+ }
6489
6500
  }
6490
- var proxied1 = Object.fromEntries(Object.entries(theme).flatMap(function(param) {
6501
+ var proxied1 = Object.fromEntries(Object.entries(_state.theme).flatMap(function(param) {
6491
6502
  var [key, value] = param, proxied2 = {
6492
6503
  ...value,
6493
6504
  get val() {
6494
6505
  return globalThis.tamaguiAvoidTracking || track(key), value.val;
6495
6506
  },
6496
6507
  get(platform) {
6497
- var outVal = (0, import_createVariable.getVariable)(value), shouldOptimize = scheme && platform !== "web" && import_constants2.isIos && !curProps.deopt && (0, import_config.getSetting)("fastSchemeChange") && state.inverses === 0 && (0, import_doesRootSchemeMatchSystem.doesRootSchemeMatchSystem)();
6498
- if (shouldOptimize) {
6499
- var _config_themes_name, _config_themes_oppositeName, oppositeScheme = scheme === "dark" ? "light" : "dark", oppositeName = name.replace(scheme, oppositeScheme), color = (0, import_createVariable.getVariable)((_config_themes_name = config.themes[name]) === null || _config_themes_name === void 0 ? void 0 : _config_themes_name[key]), oppositeColor = (0, import_createVariable.getVariable)((_config_themes_oppositeName = config.themes[oppositeName]) === null || _config_themes_oppositeName === void 0 ? void 0 : _config_themes_oppositeName[key]), dynamicVal = {
6500
- dynamic: {
6501
- [scheme]: color,
6502
- [oppositeScheme]: oppositeColor
6503
- }
6504
- };
6505
- return dynamicVal;
6506
- }
6507
- return process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key because of:
6508
+ if (curState) {
6509
+ var outVal = (0, import_createVariable.getVariable)(value), { name, scheme, inverses } = curState, shouldOptimize = scheme && platform !== "web" && import_constants2.isIos && !curProps.deopt && (0, import_config.getSetting)("fastSchemeChange") && inverses === 0 && (0, import_doesRootSchemeMatchSystem.doesRootSchemeMatchSystem)();
6510
+ if (shouldOptimize) {
6511
+ var _config_themes_name, _config_themes_oppositeName, oppositeScheme = scheme === "dark" ? "light" : "dark", oppositeName = name.replace(scheme, oppositeScheme), color = (0, import_createVariable.getVariable)((_config_themes_name = config.themes[name]) === null || _config_themes_name === void 0 ? void 0 : _config_themes_name[key]), oppositeColor = (0, import_createVariable.getVariable)((_config_themes_oppositeName = config.themes[oppositeName]) === null || _config_themes_oppositeName === void 0 ? void 0 : _config_themes_oppositeName[key]), dynamicVal = {
6512
+ dynamic: {
6513
+ [scheme]: color,
6514
+ [oppositeScheme]: oppositeColor
6515
+ }
6516
+ };
6517
+ return dynamicVal;
6518
+ }
6519
+ return process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key because of:
6508
6520
  not web: ${platform !== "web"}
6509
6521
  isIOS: ${import_constants2.isIos}
6510
6522
  deopt: ${curProps.deopt}
6511
6523
  fastScheme: ${(0, import_config.getSetting)("fastSchemeChange")}
6512
6524
  `), track(key), outVal;
6525
+ }
6513
6526
  }
6514
6527
  };
6515
6528
  return [
@@ -6523,7 +6536,7 @@ var require_getThemeProxied_native = __commonJS({
6523
6536
  ]
6524
6537
  ];
6525
6538
  }));
6526
- return cache2.set(theme, proxied1), proxied1;
6539
+ return cache2.set(_state.theme, proxied1), proxied1;
6527
6540
  }
6528
6541
  }
6529
6542
  });