@antdv-next/cssinjs 1.0.0-rc.2 → 1.0.0
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/StyleContext.mjs +41 -12
- package/dist/hooks/useGlobalCache.mjs +58 -21
- package/package.json +7 -2
package/dist/StyleContext.mjs
CHANGED
|
@@ -46,6 +46,46 @@ function provideStyleContext(app, props) {
|
|
|
46
46
|
function useStyleContext() {
|
|
47
47
|
return inject(StyleContextKey, ref(defaultStyleContext));
|
|
48
48
|
}
|
|
49
|
+
const styleContextProps = {
|
|
50
|
+
autoClear: {
|
|
51
|
+
type: Boolean,
|
|
52
|
+
default: void 0
|
|
53
|
+
},
|
|
54
|
+
mock: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: void 0
|
|
57
|
+
},
|
|
58
|
+
cache: { type: Object },
|
|
59
|
+
defaultCache: { type: Boolean },
|
|
60
|
+
hashPriority: {
|
|
61
|
+
type: String,
|
|
62
|
+
default: void 0
|
|
63
|
+
},
|
|
64
|
+
container: {
|
|
65
|
+
type: [Object],
|
|
66
|
+
default: void 0
|
|
67
|
+
},
|
|
68
|
+
ssrInline: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: void 0
|
|
71
|
+
},
|
|
72
|
+
transformers: {
|
|
73
|
+
type: Array,
|
|
74
|
+
default: void 0
|
|
75
|
+
},
|
|
76
|
+
linters: {
|
|
77
|
+
type: Array,
|
|
78
|
+
default: void 0
|
|
79
|
+
},
|
|
80
|
+
layer: {
|
|
81
|
+
type: Boolean,
|
|
82
|
+
default: void 0
|
|
83
|
+
},
|
|
84
|
+
autoPrefix: {
|
|
85
|
+
type: Boolean,
|
|
86
|
+
default: void 0
|
|
87
|
+
}
|
|
88
|
+
};
|
|
49
89
|
const StyleProvider = defineComponent((props, { slots }) => {
|
|
50
90
|
const parentContext = useStyleContext();
|
|
51
91
|
useStyleContextProvide(computed(() => {
|
|
@@ -64,18 +104,7 @@ const StyleProvider = defineComponent((props, { slots }) => {
|
|
|
64
104
|
return () => {
|
|
65
105
|
return slots?.default?.();
|
|
66
106
|
};
|
|
67
|
-
}, { props:
|
|
68
|
-
"cache",
|
|
69
|
-
"hashPriority",
|
|
70
|
-
"defaultCache",
|
|
71
|
-
"autoClear",
|
|
72
|
-
"layer",
|
|
73
|
-
"linters",
|
|
74
|
-
"container",
|
|
75
|
-
"mock",
|
|
76
|
-
"ssrInline",
|
|
77
|
-
"transformers"
|
|
78
|
-
] });
|
|
107
|
+
}, { props: styleContextProps });
|
|
79
108
|
|
|
80
109
|
//#endregion
|
|
81
110
|
export { ATTR_CACHE_PATH, ATTR_MARK, ATTR_TOKEN, CSS_IN_JS_INSTANCE, StyleProvider, createCache, provideStyleContext, useStyleContext, useStyleContextProvide };
|
|
@@ -10,7 +10,7 @@ const effectMap = /* @__PURE__ */ new Map();
|
|
|
10
10
|
* 用于解决 Vue Transition 动画期间样式被过早移除的问题
|
|
11
11
|
*/
|
|
12
12
|
const REMOVE_STYLE_DELAY = 500;
|
|
13
|
-
const
|
|
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
|
|
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
|
-
|
|
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 [
|
|
45
|
+
return [nextCount, cache];
|
|
50
46
|
});
|
|
51
47
|
};
|
|
52
|
-
|
|
48
|
+
const doAllPendingDecrements = (count) => {
|
|
49
|
+
for (let i = 0; i < count; i++) doSingleDecrement();
|
|
50
|
+
};
|
|
51
|
+
if (immediate || !isClientSide) doSingleDecrement();
|
|
53
52
|
else {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antdv-next/cssinjs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"description": "cssinjs solution for ant-design-vue",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/antdv-next/antdv-next.git",
|
|
9
|
+
"directory": "packages/cssinjs"
|
|
10
|
+
},
|
|
6
11
|
"exports": {
|
|
7
12
|
".": {
|
|
8
13
|
"types": "./dist/index.d.mts",
|
|
@@ -30,7 +35,7 @@
|
|
|
30
35
|
"dependencies": {
|
|
31
36
|
"@emotion/hash": "^0.8.0",
|
|
32
37
|
"@emotion/unitless": "^0.7.5",
|
|
33
|
-
"@v-c/util": "^1.0.
|
|
38
|
+
"@v-c/util": "^1.0.11",
|
|
34
39
|
"csstype": "^3.2.3",
|
|
35
40
|
"defu": "^6.1.4",
|
|
36
41
|
"stylis": "^4.3.6"
|