tamagui 1.124.4 → 1.124.6

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
@@ -2012,13 +2012,11 @@ var require_useControllableState_native = __commonJS({
2012
2012
  };
2013
2013
  function useControllableState(param) {
2014
2014
  var { prop, defaultProp, onChange, strategy = "prop-wins", preventUpdate, transition } = param, [state, setState] = React4.useState(prop ?? defaultProp), previous = React4.useRef(state), propWins = strategy === "prop-wins" && prop !== void 0, value = propWins ? prop : state, onChangeCb = (0, import_use_event.useEvent)(onChange || idFn), transitionFn = transition ? import_start_transition.startTransition : emptyCallbackFn;
2015
- React4.useEffect(function() {
2016
- prop !== void 0 && (previous.current = prop, transitionFn(function() {
2017
- setState(prop);
2018
- }));
2019
- }, [
2020
- prop
2021
- ]), React4.useEffect(function() {
2015
+ prop !== state && transitionFn(function() {
2016
+ setState(function(prev) {
2017
+ if (prev !== prop) return previous.current = prop, prop;
2018
+ });
2019
+ }), React4.useEffect(function() {
2022
2020
  propWins || state !== previous.current && (previous.current = state, onChangeCb(state));
2023
2021
  }, [
2024
2022
  onChangeCb,
@@ -7308,20 +7306,23 @@ var require_useThemeState_native = __commonJS({
7308
7306
  hasThemeUpdatingProps: function() {
7309
7307
  return hasThemeUpdatingProps;
7310
7308
  },
7309
+ keysToId: function() {
7310
+ return keysToId;
7311
+ },
7311
7312
  useThemeState: function() {
7312
7313
  return useThemeState;
7313
7314
  }
7314
7315
  });
7315
7316
  module2.exports = __toCommonJS2(useThemeState_exports);
7316
- var import_constants4 = require_index_native6(), 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() {
7317
- allListeners.forEach(function(cb) {
7317
+ var import_constants4 = require_index_native6(), 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() {
7318
+ cacheVersion++, shouldForce = !0, allListeners.forEach(function(cb) {
7318
7319
  return cb();
7319
7320
  });
7320
7321
  }, getThemeState = function(id) {
7321
7322
  return states.get(id);
7322
- }, rootThemeState = null, getRootThemeState = function() {
7323
+ }, cache = /* @__PURE__ */ new Map(), cacheVersion = 0, themes = null, rootThemeState = null, getRootThemeState = function() {
7323
7324
  return rootThemeState;
7324
- }, HasRenderedOnce = /* @__PURE__ */ new WeakMap(), useThemeState = function(props) {
7325
+ }, useThemeState = function(props) {
7325
7326
  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);
7326
7327
  if (disable) return states.get(parentId) || {
7327
7328
  id: "",
@@ -7331,24 +7332,28 @@ var require_useThemeState_native = __commonJS({
7331
7332
  };
7332
7333
  var id = (0, import_react3.useId)(), subscribe = (0, import_react3.useCallback)(function(cb) {
7333
7334
  var _listenersByParent, _parentId;
7334
- return (_listenersByParent = listenersByParent)[_parentId = parentId] || (_listenersByParent[_parentId] = /* @__PURE__ */ new Set()), listenersByParent[parentId].add(id), allListeners.set(id, cb), function() {
7335
+ return (_listenersByParent = listenersByParent)[_parentId = parentId] || (_listenersByParent[_parentId] = /* @__PURE__ */ new Set()), listenersByParent[parentId].add(id), allListeners.set(id, function() {
7336
+ pendingUpdate.set(id, shouldForce ? "force" : !0), cb();
7337
+ }), function() {
7335
7338
  allListeners.delete(id), listenersByParent[parentId].delete(id);
7336
7339
  };
7337
7340
  }, [
7338
7341
  id,
7339
- parentId,
7340
- keys
7342
+ parentId
7341
7343
  ]), propsKey = getPropsKey(props), getSnapshot = function() {
7342
- return getSnapshotFrom(props, propsKey, isRoot, id, parentId, keys);
7344
+ 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}`;
7345
+ if (!needsUpdate && cache.has(cacheKey)) return cache.get(cacheKey);
7346
+ var next = getSnapshotFrom(last, props, propsKey, isRoot, id, parentId, needsUpdate, pendingUpdate.get(id));
7347
+ return last !== next && (pendingUpdate.delete(id), states.set(id, next), cache.set(id, next), process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile" && console.warn(` \xB7 useTheme(${id}) UPDATE from`, last, "to", next)), next;
7343
7348
  };
7344
7349
  process.env.NODE_ENV === "development" && globalThis.time && globalThis.time`theme-prep-uses`;
7345
7350
  var state = (0, import_react3.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
7346
7351
  return (0, import_constants4.useIsomorphicLayoutEffect)(function() {
7352
+ if (!hasRenderedOnce.get(keys)) {
7353
+ hasRenderedOnce.set(keys, !0);
7354
+ return;
7355
+ }
7347
7356
  if (propsKey) {
7348
- if (!HasRenderedOnce.has(keys)) {
7349
- HasRenderedOnce.set(keys, !0);
7350
- return;
7351
- }
7352
7357
  if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
7353
7358
  var _states_get;
7354
7359
  console.warn(` \xB7 useTheme(${id}) scheduleUpdate`, propsKey, (_states_get = states.get(id)) === null || _states_get === void 0 ? void 0 : _states_get.name);
@@ -7358,29 +7363,30 @@ var require_useThemeState_native = __commonJS({
7358
7363
  }, [
7359
7364
  keys,
7360
7365
  propsKey
7361
- ]), process.env.NODE_ENV === "development" && props.debug && (console.groupCollapsed(` \xB7 useTheme(${id}) =>`, state.name, id === state.id ? "\u{1F389}" : "\u23ED\uFE0F"), console.info({
7362
- state,
7363
- parentId,
7364
- props,
7365
- propsKey,
7366
- id,
7367
- parentState: states.get(parentId)
7368
- }), console.groupEnd()), state.id === id ? {
7366
+ ]), state.id === id ? {
7369
7367
  ...state,
7370
7368
  isNew: !0
7371
7369
  } : state;
7372
- }, themes = null, getSnapshotFrom = function(props, propsKey) {
7373
- 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);
7370
+ }, getSnapshotFrom = function(lastState, props, propsKey) {
7371
+ 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);
7374
7372
  themes || (themes = (0, import_config.getConfig)().themes);
7375
- var lastState = states.get(id), name = propsKey ? getNewThemeName(parentState == null ? void 0 : parentState.name, props, !!needsUpdate) : null;
7373
+ var name = !propsKey && pendingUpdate2 !== "force" ? null : getNewThemeName(parentState == null ? void 0 : parentState.name, props, pendingUpdate2 === "force" ? !0 : !!needsUpdate), isSameAsParent = !!(!name && propsKey);
7376
7374
  if (process.env.NODE_ENV === "development" && props.debug && props.debug !== "profile") {
7377
7375
  var message = ` \xB7 useTheme(${id}) snapshot ${name}, parent ${parentState == null ? void 0 : parentState.id} needsUpdate ${needsUpdate}`;
7378
7376
  console.info(message);
7379
7377
  }
7380
- var isSameAsParent = !name && propsKey;
7381
7378
  if (parentState && isSameAsParent) return parentState;
7382
- if (!name) return lastState && !needsUpdate ? lastState : (states.set(id, parentState), parentState);
7383
- if (lastState && lastState.name === name) return lastState;
7379
+ if (!name) {
7380
+ var next = lastState ?? parentState;
7381
+ if (needsUpdate && pendingUpdate2) {
7382
+ var updated = {
7383
+ ...parentState || lastState
7384
+ };
7385
+ return updated;
7386
+ }
7387
+ return next;
7388
+ }
7389
+ if (pendingUpdate2 !== "force" && lastState && lastState.name === name) return lastState;
7384
7390
  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 = {
7385
7391
  id,
7386
7392
  name,
@@ -7391,7 +7397,7 @@ var require_useThemeState_native = __commonJS({
7391
7397
  inverses,
7392
7398
  isInverse
7393
7399
  };
7394
- 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;
7400
+ 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;
7395
7401
  };
7396
7402
  function scheduleUpdate(id) {
7397
7403
  for (var queue = [
@@ -7429,7 +7435,7 @@ var require_useThemeState_native = __commonJS({
7429
7435
  return validSchemes[name.split("_")[0]];
7430
7436
  }
7431
7437
  function getNewThemeName() {
7432
- 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;
7438
+ 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;
7433
7439
  if (name && reset) throw new Error(process.env.NODE_ENV === "production" ? "\u274C004" : "Cannot reset and set a new name at the same time.");
7434
7440
  if (reset) {
7435
7441
  if (!parentName) throw new Error("\u203C\uFE0F");
@@ -7463,7 +7469,8 @@ var require_useThemeState_native = __commonJS({
7463
7469
  }
7464
7470
  if (found) break;
7465
7471
  }
7466
- if (found && inverse) {
7472
+ if (inverse) {
7473
+ found || (found = parentName);
7467
7474
  var scheme = found.split("_")[0];
7468
7475
  found = found.replace(new RegExp(`^${scheme}`), scheme === "light" ? "dark" : "light");
7469
7476
  }
@@ -7574,41 +7581,45 @@ var require_getThemeProxied_native = __commonJS({
7574
7581
  }
7575
7582
  });
7576
7583
  module2.exports = __toCommonJS2(getThemeProxied_exports);
7577
- var import_constants4 = require_index_native6(), import_config = require_config_native(), import_createVariable = require_createVariable_native(), import_doesRootSchemeMatchSystem = require_doesRootSchemeMatchSystem_native(), cache = /* @__PURE__ */ new Map(), curKeys, curProps, emptyObject = {};
7578
- function getThemeProxied(_props, state, _keys) {
7579
- var theme = state == null ? void 0 : state.theme;
7580
- if (!theme) return emptyObject;
7581
- if (curKeys = _keys, curProps = _props, cache.has(theme)) {
7582
- var proxied = cache.get(theme);
7584
+ var import_constants4 = require_index_native6(), import_config = require_config_native(), import_createVariable = require_createVariable_native(), import_doesRootSchemeMatchSystem = require_doesRootSchemeMatchSystem_native(), import_useThemeState = require_useThemeState_native(), cache = /* @__PURE__ */ new Map(), curKeys, curProps, curState, emptyObject = {};
7585
+ function getThemeProxied(_props, _state, _keys) {
7586
+ if (!(_state != null && _state.theme)) return emptyObject;
7587
+ if (curKeys = _keys, curProps = _props, curState = _state, cache.has(curState.theme)) {
7588
+ var proxied = cache.get(curState.theme);
7583
7589
  return proxied;
7584
7590
  }
7585
- var { name, scheme } = state, config = (0, import_config.getConfig)();
7591
+ var config = (0, import_config.getConfig)();
7586
7592
  function track(key) {
7587
- 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}`));
7593
+ if (curKeys && (curKeys.current || (curKeys.current = /* @__PURE__ */ new Set()), curKeys.current.add(key), process.env.NODE_ENV === "development" && curProps.debug)) {
7594
+ var _globalThis_states, realId = import_useThemeState.keysToId.get(curKeys);
7595
+ 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));
7596
+ }
7588
7597
  }
7589
- var proxied1 = Object.fromEntries(Object.entries(theme).flatMap(function(param) {
7598
+ var proxied1 = Object.fromEntries(Object.entries(_state.theme).flatMap(function(param) {
7590
7599
  var [key, value] = param, proxied2 = {
7591
7600
  ...value,
7592
7601
  get val() {
7593
7602
  return globalThis.tamaguiAvoidTracking || track(key), value.val;
7594
7603
  },
7595
7604
  get(platform2) {
7596
- var outVal = (0, import_createVariable.getVariable)(value), shouldOptimize = scheme && platform2 !== "web" && import_constants4.isIos && !curProps.deopt && (0, import_config.getSetting)("fastSchemeChange") && state.inverses === 0 && (0, import_doesRootSchemeMatchSystem.doesRootSchemeMatchSystem)();
7597
- if (shouldOptimize) {
7598
- 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 = {
7599
- dynamic: {
7600
- [scheme]: color,
7601
- [oppositeScheme]: oppositeColor
7602
- }
7603
- };
7604
- return dynamicVal;
7605
- }
7606
- return process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key because of:
7605
+ if (curState) {
7606
+ var outVal = (0, import_createVariable.getVariable)(value), { name, scheme, inverses } = curState, shouldOptimize = scheme && platform2 !== "web" && import_constants4.isIos && !curProps.deopt && (0, import_config.getSetting)("fastSchemeChange") && inverses === 0 && (0, import_doesRootSchemeMatchSystem.doesRootSchemeMatchSystem)();
7607
+ if (shouldOptimize) {
7608
+ 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 = {
7609
+ dynamic: {
7610
+ [scheme]: color,
7611
+ [oppositeScheme]: oppositeColor
7612
+ }
7613
+ };
7614
+ return dynamicVal;
7615
+ }
7616
+ return process.env.NODE_ENV === "development" && curProps.debug && console.info(` \u{1F3A8} useTheme() tracking new key because of:
7607
7617
  not web: ${platform2 !== "web"}
7608
7618
  isIOS: ${import_constants4.isIos}
7609
7619
  deopt: ${curProps.deopt}
7610
7620
  fastScheme: ${(0, import_config.getSetting)("fastSchemeChange")}
7611
7621
  `), track(key), outVal;
7622
+ }
7612
7623
  }
7613
7624
  };
7614
7625
  return [
@@ -7622,7 +7633,7 @@ var require_getThemeProxied_native = __commonJS({
7622
7633
  ]
7623
7634
  ];
7624
7635
  }));
7625
- return cache.set(theme, proxied1), proxied1;
7636
+ return cache.set(_state.theme, proxied1), proxied1;
7626
7637
  }
7627
7638
  }
7628
7639
  });
@@ -30002,8 +30013,9 @@ var require_mutateTheme_native = __commonJS({
30002
30013
  return (0, import_start_transition.startTransition)(function() {
30003
30014
  for (var themeName in allThemesProxied) {
30004
30015
  var theme2 = allThemesProxied[themeName];
30005
- updateThemeConfig(themeName, theme2), updateThemeStates(themeName, theme2);
30016
+ updateThemeConfig(themeName, theme2);
30006
30017
  }
30018
+ updateThemeStates();
30007
30019
  }), {
30008
30020
  themes: allThemesProxied,
30009
30021
  themesRaw: allThemesRaw,
@@ -30033,13 +30045,13 @@ var require_mutateTheme_native = __commonJS({
30033
30045
  };
30034
30046
  return props.avoidUpdate || (insertCSS && (response.cssRules = insertThemeCSS({
30035
30047
  [themeName]: theme1
30036
- })), updateThemeConfig(themeName, themeProxied), updateThemeStates(themeName, themeProxied)), response;
30048
+ })), updateThemeConfig(themeName, themeProxied), updateThemeStates()), response;
30037
30049
  }
30038
30050
  function updateThemeConfig(themeName, theme) {
30039
30051
  var config = (0, import_web.getConfig)();
30040
30052
  config.themes[themeName] = theme, (0, import_web.updateConfig)("themes", config.themes);
30041
30053
  }
30042
- function updateThemeStates(themeName, theme) {
30054
+ function updateThemeStates() {
30043
30055
  (0, import_web.forceUpdateThemes)();
30044
30056
  }
30045
30057
  function insertThemeCSS(themes) {