vitepress-theme-element-plus 0.0.2 → 0.0.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.
package/client/hooks/useSize.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { MaybeRef } from '@vueuse/core'
|
|
2
2
|
import type { Ref, ShallowRef } from 'vue'
|
|
3
3
|
import { useEventListener } from '@vueuse/core'
|
|
4
|
-
import { isString } from 'es-toolkit'
|
|
5
4
|
import { computed, isRef, onMounted, ref, shallowRef, unref, watch } from 'vue'
|
|
5
|
+
import { isString } from '../utils/common'
|
|
6
6
|
|
|
7
7
|
function getValue(value: string | number): string {
|
|
8
8
|
return isString(value) ? value : `${value}px`
|
package/client/utils/common.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
type AnyFn = (...args: any[]) => unknown
|
|
2
|
+
|
|
3
|
+
export interface Throttled<T extends AnyFn> {
|
|
4
|
+
(...args: Parameters<T>): void
|
|
5
|
+
cancel: () => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function throttle<T extends AnyFn>(fn: T, delay = 200): Throttled<T> {
|
|
9
|
+
let lastCall = 0
|
|
10
|
+
let timer: ReturnType<typeof setTimeout> | null = null
|
|
11
|
+
|
|
12
|
+
const invoke = (context: unknown, args: Parameters<T>) => {
|
|
13
|
+
lastCall = Date.now()
|
|
14
|
+
fn.apply(context, args)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const throttled = function (this: unknown, ...args: Parameters<T>) {
|
|
18
|
+
const now = Date.now()
|
|
19
|
+
const remaining = delay - (now - lastCall)
|
|
20
|
+
|
|
21
|
+
if (remaining <= 0) {
|
|
22
|
+
if (timer) {
|
|
23
|
+
clearTimeout(timer)
|
|
24
|
+
timer = null
|
|
25
|
+
}
|
|
26
|
+
invoke(this, args)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!timer) {
|
|
31
|
+
timer = setTimeout(() => {
|
|
32
|
+
timer = null
|
|
33
|
+
invoke(this, args)
|
|
34
|
+
}, remaining)
|
|
35
|
+
}
|
|
36
|
+
} as Throttled<T>
|
|
37
|
+
|
|
38
|
+
throttled.cancel = () => {
|
|
39
|
+
if (timer) {
|
|
40
|
+
clearTimeout(timer)
|
|
41
|
+
timer = null
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return throttled
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitepress-theme-element-plus",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"description": "A VitePress theme for Element Plus",
|
|
6
6
|
"author": "Hezhengxu",
|
|
7
7
|
"license": "MIT",
|
|
@@ -45,8 +45,10 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"vitepress": "2.0.0-alpha.12"
|
|
47
47
|
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@iconify/vue": "^4"
|
|
50
|
+
},
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@iconify/vue": "^4.2.1",
|
|
50
52
|
"@release-it/conventional-changelog": "^10",
|
|
51
53
|
"@types/glob": "^9.0.0",
|
|
52
54
|
"@types/markdown-it": "^14.1.0",
|
|
@@ -54,7 +56,6 @@
|
|
|
54
56
|
"@vitejs/plugin-vue": "^5.2.4",
|
|
55
57
|
"@vueuse/core": "^11.3.0",
|
|
56
58
|
"element-plus": "^2.11.7",
|
|
57
|
-
"es-toolkit": "^1.14.0",
|
|
58
59
|
"release-it": "^19",
|
|
59
60
|
"rimraf": "^6.0.1",
|
|
60
61
|
"sass-embedded": "^1.80.3",
|