@tamagui/core 1.112.8 → 1.112.10

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
@@ -1027,9 +1027,10 @@ var require_index_native2 = __commonJS({
1027
1027
  }
1028
1028
  });
1029
1029
  module2.exports = __toCommonJS2(src_exports2);
1030
- var cache2 = /* @__PURE__ */ new Map(), simpleHash = function(str) {
1030
+ var cache2 = /* @__PURE__ */ new Map(), cacheSize = 0, simpleHash = function(strIn) {
1031
1031
  var hashMin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 10;
1032
- if (cache2.has(str)) return cache2.get(str);
1032
+ if (cache2.has(strIn)) return cache2.get(strIn);
1033
+ var str = strIn;
1033
1034
  str[0] === "v" && str.startsWith("var(") && (str = str.slice(6, str.length - 1));
1034
1035
  for (var hash = 0, valids = "", added = 0, len = str.length, i = 0; i < len; i++) {
1035
1036
  if (hashMin !== "strict" && added <= hashMin) {
@@ -1046,7 +1047,7 @@ var require_index_native2 = __commonJS({
1046
1047
  hash = hashChar(hash, str[i]);
1047
1048
  }
1048
1049
  var res = valids + (hash ? Math.abs(hash) : "");
1049
- return cache2.size > 1e4 && cache2.clear(), cache2.set(str, res), res;
1050
+ return cacheSize > 1e4 && (cache2.clear(), cacheSize = 0), cache2.set(strIn, res), cacheSize++, res;
1050
1051
  }, hashChar = function(hash, c) {
1051
1052
  return Math.imul(31, hash) + c.charCodeAt(0) | 0;
1052
1053
  };
@@ -3223,7 +3224,7 @@ var require_ThemeManager_native = __commonJS({
3223
3224
  "use strict";
3224
3225
  function ThemeManager2() {
3225
3226
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, parentManager = arguments.length > 1 ? arguments[1] : void 0;
3226
- if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3227
+ if (_class_call_check(this, ThemeManager2), _define_property(this, "props", void 0), _define_property(this, "id", void 0), _define_property(this, "themeListeners", void 0), _define_property(this, "parentManager", void 0), _define_property(this, "state", void 0), _define_property(this, "_allKeys", void 0), _define_property(this, "_selfListener", void 0), this.props = props, this.id = 0, this.themeListeners = /* @__PURE__ */ new Set(), this.parentManager = null, this.state = emptyState, this._allKeys = null, uid = (uid + 1) % Number.MAX_VALUE, this.id = uid, parentManager === "root") {
3227
3228
  this.updateStateFromProps(props, !1);
3228
3229
  return;
3229
3230
  }
@@ -3243,11 +3244,22 @@ var require_ThemeManager_native = __commonJS({
3243
3244
  {
3244
3245
  key: "updateState",
3245
3246
  value: function(nextState) {
3246
- var _this = this, shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3247
- this.state = nextState, this._allKeys = null, shouldNotify && this.notify();
3247
+ var shouldNotify = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
3248
+ this.state = nextState, this._allKeys = null;
3248
3249
  }
3249
3250
  },
3250
3251
  {
3252
+ // if (shouldNotify) {
3253
+ // if (process.env.TAMAGUI_TARGET === 'native') {
3254
+ // // native is way slower with queueMicrotask
3255
+ // this.notify()
3256
+ // } else {
3257
+ // // web is way faster this way
3258
+ // queueMicrotask(() => {
3259
+ // this.notify()
3260
+ // })
3261
+ // }
3262
+ // }
3251
3263
  key: "getStateIfChanged",
3252
3264
  value: function() {
3253
3265
  var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : this.props, state = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.state, parentManager = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : this.parentManager, _ = this.getState(props, parentManager);
@@ -3291,6 +3303,13 @@ var require_ThemeManager_native = __commonJS({
3291
3303
  }
3292
3304
  }
3293
3305
  },
3306
+ {
3307
+ key: "selfUpdate",
3308
+ value: function() {
3309
+ var _this__selfListener, _this;
3310
+ (_this__selfListener = (_this = this)._selfListener) === null || _this__selfListener === void 0 || _this__selfListener.call(_this, this.state.name, this, "self");
3311
+ }
3312
+ },
3294
3313
  {
3295
3314
  key: "onChangeTheme",
3296
3315
  value: function(cb, debugId) {
@@ -3299,7 +3318,7 @@ var require_ThemeManager_native = __commonJS({
3299
3318
  var _this__listeningIds;
3300
3319
  (_this__listeningIds = this._listeningIds) !== null && _this__listeningIds !== void 0 || (this._listeningIds = /* @__PURE__ */ new Set()), this._listeningIds.add(debugId);
3301
3320
  }
3302
- return this.themeListeners.add(cb), function() {
3321
+ return debugId === !0 && (this._selfListener = cb), this.themeListeners.add(cb), function() {
3303
3322
  _this.themeListeners.delete(cb);
3304
3323
  };
3305
3324
  }
@@ -3658,7 +3677,7 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3658
3677
  if (!theme) return {};
3659
3678
  var config = (0, import_config.getConfig)();
3660
3679
  function track(key) {
3661
- keys && !keys.includes(key) && (keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
3680
+ keys && !keys.includes(key) && (keys.length || themeManager == null || themeManager.selfUpdate(), keys.push(key), process.env.NODE_ENV === "development" && debug && console.info(` \u{1F3A8} useTheme() tracking new key: ${key}`));
3662
3681
  }
3663
3682
  return new Proxy(theme, {
3664
3683
  has(_, key) {
@@ -3734,15 +3753,19 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3734
3753
  state: parentManager == null ? void 0 : parentManager.state,
3735
3754
  themeManager: parentManager
3736
3755
  };
3737
- var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3756
+ var [themeState, setThemeState] = import_react3.default.useState(createState), { state, mounted, isNewTheme, themeManager, inversed, prevState } = themeState, isInversingOnMount = !!(!themeState.mounted && props.inverse);
3738
3757
  function getShouldUpdateTheme() {
3739
- var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3758
+ var manager = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : themeManager, nextState = arguments.length > 1 ? arguments[1] : void 0, prevState2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : state, forceShouldChange = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : !1, forceUpdate = shouldUpdate == null ? void 0 : shouldUpdate();
3740
3759
  if (!(!manager || !forceShouldChange && forceUpdate === !1)) {
3741
3760
  var next = nextState || manager.getState(props, parentManager);
3742
- if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState))) return next;
3761
+ if (forceShouldChange || next && !(forceUpdate !== !0 && !manager.getStateShouldChange(next, prevState2))) return next;
3743
3762
  }
3744
3763
  }
3745
- if (import_constants2.isServer || (import_react3.default.useEffect(function() {
3764
+ if (import_constants2.isServer || (import_react3.default.useLayoutEffect(function() {
3765
+ themeManager && state && prevState && state !== prevState && themeManager.notify();
3766
+ }, [
3767
+ state
3768
+ ]), import_react3.default.useEffect(function() {
3746
3769
  if (themeManager) {
3747
3770
  if (props.inverse && !mounted) {
3748
3771
  setThemeState(function(prev) {
@@ -3755,10 +3778,11 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3755
3778
  }
3756
3779
  (isNewTheme || getShouldUpdateTheme(themeManager)) && (activeThemeManagers.add(themeManager), setThemeState(createState));
3757
3780
  var selfListenerDispose = themeManager.onChangeTheme(function(_a, _b, forced) {
3758
- forced && (console.error = preventWarnSetState, setThemeState(function(prev) {
3759
- return createState(prev, !0);
3760
- }), console.error = ogLog);
3761
- }), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3781
+ forced && setThemeState(function(prev) {
3782
+ var next = createState(prev, forced !== "self");
3783
+ return next;
3784
+ });
3785
+ }, !0), disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(function(name, manager, forced) {
3762
3786
  var force = forced || (shouldUpdate == null ? void 0 : shouldUpdate()) || props.deopt || props["disable-child-theme"], shouldTryUpdate = force ?? !!(keys != null && keys.length || isNewTheme);
3763
3787
  process.env.NODE_ENV === "development" && props.debug === "verbose" && console.info(" \u{1F538} onChange", themeManager.id, {
3764
3788
  force,
@@ -3767,9 +3791,9 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3767
3791
  name,
3768
3792
  manager,
3769
3793
  keys
3770
- }), shouldTryUpdate && (console.error = preventWarnSetState, setThemeState(function(prev) {
3794
+ }), shouldTryUpdate && setThemeState(function(prev) {
3771
3795
  return createState(prev, force);
3772
- }), console.error = ogLog);
3796
+ });
3773
3797
  }, themeManager.id);
3774
3798
  return function() {
3775
3799
  selfListenerDispose(), disposeChangeListener == null || disposeChangeListener(), isNewTheme && activeThemeManagers.delete(themeManager);
@@ -3836,7 +3860,7 @@ If this is intended and you are using Tamagui without any themes, you can disabl
3836
3860
  (0, import_createShallowSetState.isEqualShallow)(prev, response) && // ... and then compare just the state, because we make a new state obj but is likely the same
3837
3861
  (0, import_createShallowSetState.isEqualShallow)(prev.state, state2);
3838
3862
  if (prev && shouldReturnPrev) return prev;
3839
- if (response.state = state2, process.env.NODE_ENV === "development" && props.debug && import_constants2.isClient) {
3863
+ if (response.state = state2, response.prevState = prev == null ? void 0 : prev.state, process.env.NODE_ENV === "development" && props.debug && import_constants2.isClient) {
3840
3864
  console.groupCollapsed(`\u{1F537} [${themeManager2.id}] useChangeThemeEffect createState`);
3841
3865
  var parentState = {
3842
3866
  ...parentManager == null ? void 0 : parentManager.state