@antdv-next/cssinjs 1.0.0-rc.2 → 1.0.0-rc.3

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.
@@ -10,7 +10,7 @@ const effectMap = /* @__PURE__ */ new Map();
10
10
  * 用于解决 Vue Transition 动画期间样式被过早移除的问题
11
11
  */
12
12
  const REMOVE_STYLE_DELAY = 500;
13
- const delayedRemoveTimers = /* @__PURE__ */ new Map();
13
+ const delayedRemoveInfo = /* @__PURE__ */ new Map();
14
14
  /**
15
15
  * Global cache for CSS-in-JS styles
16
16
  *
@@ -33,29 +33,45 @@ function useGlobalCache(prefix, keyPath, cacheFn, onCacheRemove, onCacheEffect)
33
33
  const isServerSide = () => styleContext.value.mock !== void 0 ? styleContext.value.mock === "server" : !isClientSide;
34
34
  const clearCache = (pathStr, immediate = false) => {
35
35
  if (isServerSide()) return;
36
- const existingTimer = delayedRemoveTimers.get(pathStr);
37
- if (existingTimer) {
38
- clearTimeout(existingTimer);
39
- delayedRemoveTimers.delete(pathStr);
40
- }
41
- const doCleanup = () => {
36
+ const doSingleDecrement = () => {
42
37
  globalCache().opUpdate(pathStr, (prevCache) => {
43
38
  const [times = 0, cache] = prevCache || [];
44
- if (times - 1 === 0) {
39
+ const nextCount = times - 1;
40
+ if (nextCount === 0) {
45
41
  onCacheRemove?.(cache, false);
46
42
  effectMap.delete(pathStr);
47
43
  return null;
48
44
  }
49
- return [times - 1, cache];
45
+ return [nextCount, cache];
50
46
  });
51
47
  };
52
- if (immediate || !isClientSide) doCleanup();
48
+ const doAllPendingDecrements = (count) => {
49
+ for (let i = 0; i < count; i++) doSingleDecrement();
50
+ };
51
+ if (immediate || !isClientSide) doSingleDecrement();
53
52
  else {
54
- const timer = setTimeout(() => {
55
- delayedRemoveTimers.delete(pathStr);
56
- doCleanup();
57
- }, REMOVE_STYLE_DELAY);
58
- delayedRemoveTimers.set(pathStr, timer);
53
+ const existingInfo = delayedRemoveInfo.get(pathStr);
54
+ if (existingInfo) {
55
+ clearTimeout(existingInfo.timer);
56
+ const newPendingDecrements = existingInfo.pendingDecrements + 1;
57
+ const timer = setTimeout(() => {
58
+ delayedRemoveInfo.delete(pathStr);
59
+ doAllPendingDecrements(newPendingDecrements);
60
+ }, REMOVE_STYLE_DELAY);
61
+ delayedRemoveInfo.set(pathStr, {
62
+ timer,
63
+ pendingDecrements: newPendingDecrements
64
+ });
65
+ } else {
66
+ const timer = setTimeout(() => {
67
+ delayedRemoveInfo.delete(pathStr);
68
+ doSingleDecrement();
69
+ }, REMOVE_STYLE_DELAY);
70
+ delayedRemoveInfo.set(pathStr, {
71
+ timer,
72
+ pendingDecrements: 1
73
+ });
74
+ }
59
75
  }
60
76
  };
61
77
  const cacheContent = computed(() => {
@@ -72,12 +88,33 @@ function useGlobalCache(prefix, keyPath, cacheFn, onCacheRemove, onCacheEffect)
72
88
  watch(fullPathStr, (newPath, oldPath) => {
73
89
  if (oldPath) clearCache(oldPath, true);
74
90
  currentPathRef.value = newPath;
75
- const existingTimer = delayedRemoveTimers.get(newPath);
76
- if (existingTimer) {
77
- clearTimeout(existingTimer);
78
- delayedRemoveTimers.delete(newPath);
79
- }
80
- globalCache().opUpdate(newPath, (prevCache) => {
91
+ const existingInfo = delayedRemoveInfo.get(newPath);
92
+ if (existingInfo) {
93
+ const newPendingDecrements = existingInfo.pendingDecrements - 1;
94
+ if (newPendingDecrements <= 0) {
95
+ clearTimeout(existingInfo.timer);
96
+ delayedRemoveInfo.delete(newPath);
97
+ } else {
98
+ clearTimeout(existingInfo.timer);
99
+ const timer = setTimeout(() => {
100
+ delayedRemoveInfo.delete(newPath);
101
+ for (let i = 0; i < newPendingDecrements; i++) globalCache().opUpdate(newPath, (prevCache) => {
102
+ const [times = 0, cache] = prevCache || [];
103
+ const nextCount = times - 1;
104
+ if (nextCount === 0) {
105
+ onCacheRemove?.(cache, false);
106
+ effectMap.delete(newPath);
107
+ return null;
108
+ }
109
+ return [nextCount, cache];
110
+ });
111
+ }, REMOVE_STYLE_DELAY);
112
+ delayedRemoveInfo.set(newPath, {
113
+ timer,
114
+ pendingDecrements: newPendingDecrements
115
+ });
116
+ }
117
+ } else globalCache().opUpdate(newPath, (prevCache) => {
81
118
  const [times = 0, cache] = prevCache || [void 0, void 0];
82
119
  const mergedCache = cache || cacheFn();
83
120
  return [times + 1, mergedCache];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@antdv-next/cssinjs",
3
3
  "type": "module",
4
- "version": "1.0.0-rc.2",
4
+ "version": "1.0.0-rc.3",
5
5
  "description": "cssinjs solution for ant-design-vue",
6
6
  "exports": {
7
7
  ".": {