@taicode/common-web 3.7.7 → 3.7.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/output/components/alert-dialog.d.ts +20 -0
- package/output/components/alert-dialog.d.ts.map +1 -0
- package/output/components/alert-dialog.js +65 -0
- package/output/components/alert.d.ts +11 -0
- package/output/components/alert.d.ts.map +1 -0
- package/output/components/alert.js +38 -0
- package/output/components/avatar.d.ts +13 -0
- package/output/components/avatar.d.ts.map +1 -0
- package/output/components/avatar.js +40 -0
- package/output/components/badge.d.ts +11 -0
- package/output/components/badge.d.ts.map +1 -0
- package/output/components/badge.js +39 -0
- package/output/components/button.d.ts +12 -0
- package/output/components/button.d.ts.map +1 -0
- package/output/components/button.js +48 -0
- package/output/components/calendar.d.ts +13 -0
- package/output/components/calendar.d.ts.map +1 -0
- package/output/components/calendar.js +57 -0
- package/output/components/card.d.ts +13 -0
- package/output/components/card.d.ts.map +1 -0
- package/output/components/card.js +43 -0
- package/output/components/chart.d.ts +56 -0
- package/output/components/chart.d.ts.map +1 -0
- package/output/components/chart.js +127 -0
- package/output/components/checkbox.d.ts +5 -0
- package/output/components/checkbox.d.ts.map +1 -0
- package/output/components/checkbox.js +21 -0
- package/output/components/command.d.ts +20 -0
- package/output/components/command.d.ts.map +1 -0
- package/output/components/command.js +55 -0
- package/output/components/dialog.d.ts +20 -0
- package/output/components/dialog.d.ts.map +1 -0
- package/output/components/dialog.js +58 -0
- package/output/components/direction.d.ts +9 -0
- package/output/components/direction.d.ts.map +1 -0
- package/output/components/direction.js +10 -0
- package/output/components/drawer.d.ts +14 -0
- package/output/components/drawer.d.ts.map +1 -0
- package/output/components/drawer.js +56 -0
- package/output/components/dropdown-menu.d.ts +29 -0
- package/output/components/dropdown-menu.d.ts.map +1 -0
- package/output/components/dropdown-menu.js +78 -0
- package/output/components/field.d.ts +39 -0
- package/output/components/field.d.ts.map +1 -0
- package/output/components/field.js +102 -0
- package/output/components/footer/index.d.ts +27 -0
- package/output/components/footer/index.d.ts.map +1 -0
- package/output/components/footer/index.js +17 -0
- package/output/components/form.d.ts +26 -0
- package/output/components/form.d.ts.map +1 -0
- package/output/components/form.js +69 -0
- package/output/components/index.d.ts +46 -0
- package/output/components/index.d.ts.map +1 -0
- package/output/components/index.js +45 -0
- package/output/components/input-group.d.ts +17 -0
- package/output/components/input-group.d.ts.map +1 -0
- package/output/components/input-group.js +75 -0
- package/output/components/input.d.ts +4 -0
- package/output/components/input.d.ts.map +1 -0
- package/output/components/input.js +19 -0
- package/output/components/item.d.ts +25 -0
- package/output/components/item.d.ts.map +1 -0
- package/output/components/item.js +89 -0
- package/output/components/json-view/index.d.ts +11 -0
- package/output/components/json-view/index.d.ts.map +1 -0
- package/output/components/json-view/index.js +52 -0
- package/output/components/json-view/lazy/index.d.ts +18 -0
- package/output/components/json-view/lazy/index.d.ts.map +1 -0
- package/output/components/json-view/lazy/index.js +22 -0
- package/output/components/kbd.d.ts +4 -0
- package/output/components/kbd.d.ts.map +1 -0
- package/output/components/kbd.js +22 -0
- package/output/components/label.d.ts +5 -0
- package/output/components/label.d.ts.map +1 -0
- package/output/components/label.js +20 -0
- package/output/components/list-actions/index.d.ts +23 -0
- package/output/components/list-actions/index.d.ts.map +1 -0
- package/output/components/list-actions/index.js +15 -0
- package/output/components/loading-button/index.d.ts +44 -0
- package/output/components/loading-button/index.d.ts.map +1 -0
- package/output/components/loading-button/index.js +75 -0
- package/output/components/loading-button/index.test.d.ts +2 -0
- package/output/components/loading-button/index.test.d.ts.map +1 -0
- package/output/components/loading-button/index.test.js +203 -0
- package/output/components/native-select.d.ts +9 -0
- package/output/components/native-select.d.ts.map +1 -0
- package/output/components/native-select.js +28 -0
- package/output/components/page-back-button/index.d.ts +8 -0
- package/output/components/page-back-button/index.d.ts.map +1 -0
- package/output/components/page-back-button/index.js +7 -0
- package/output/components/page-state.d.ts +19 -0
- package/output/components/page-state.d.ts.map +1 -0
- package/output/components/page-state.js +13 -0
- package/output/components/pagination/index.d.ts +34 -0
- package/output/components/pagination/index.d.ts.map +1 -0
- package/output/components/pagination/index.js +75 -0
- package/output/components/popover.d.ts +11 -0
- package/output/components/popover.d.ts.map +1 -0
- package/output/components/popover.js +44 -0
- package/output/components/progress.d.ts +5 -0
- package/output/components/progress.d.ts.map +1 -0
- package/output/components/progress.js +21 -0
- package/output/components/radio-group.d.ts +6 -0
- package/output/components/radio-group.d.ts.map +1 -0
- package/output/components/radio-group.js +25 -0
- package/output/components/route-pending-indicator/index.d.ts +20 -0
- package/output/components/route-pending-indicator/index.d.ts.map +1 -0
- package/output/components/route-pending-indicator/index.js +17 -0
- package/output/components/scroll-area.d.ts +6 -0
- package/output/components/scroll-area.d.ts.map +1 -0
- package/output/components/scroll-area.js +24 -0
- package/output/components/searchable-select/index.d.ts +41 -0
- package/output/components/searchable-select/index.d.ts.map +1 -0
- package/output/components/searchable-select/index.js +46 -0
- package/output/components/select.d.ts +17 -0
- package/output/components/select.d.ts.map +1 -0
- package/output/components/select.js +58 -0
- package/output/components/separator.d.ts +5 -0
- package/output/components/separator.d.ts.map +1 -0
- package/output/components/separator.js +20 -0
- package/output/components/sheet.d.ts +16 -0
- package/output/components/sheet.d.ts.map +1 -0
- package/output/components/sheet.js +58 -0
- package/output/components/sidebar.d.ts +78 -0
- package/output/components/sidebar.d.ts.map +1 -0
- package/output/components/sidebar.js +233 -0
- package/output/components/size-provider/index.d.ts +2 -0
- package/output/components/size-provider/index.d.ts.map +1 -0
- package/output/components/size-provider/index.js +1 -0
- package/output/components/size-provider/size-provider.d.ts +9 -0
- package/output/components/size-provider/size-provider.d.ts.map +1 -0
- package/output/components/size-provider/size-provider.js +29 -0
- package/output/components/skeleton.d.ts +3 -0
- package/output/components/skeleton.d.ts.map +1 -0
- package/output/components/skeleton.js +18 -0
- package/output/components/sonner.d.ts +8 -0
- package/output/components/sonner.d.ts.map +1 -0
- package/output/components/sonner.js +34 -0
- package/output/components/spinner.d.ts +3 -0
- package/output/components/spinner.d.ts.map +1 -0
- package/output/components/spinner.js +19 -0
- package/output/components/switch.d.ts +8 -0
- package/output/components/switch.d.ts.map +1 -0
- package/output/components/switch.js +20 -0
- package/output/components/table.d.ts +11 -0
- package/output/components/table.d.ts.map +1 -0
- package/output/components/table.js +47 -0
- package/output/components/tabs.d.ts +12 -0
- package/output/components/tabs.d.ts.map +1 -0
- package/output/components/tabs.js +45 -0
- package/output/components/textarea.d.ts +4 -0
- package/output/components/textarea.d.ts.map +1 -0
- package/output/components/textarea.js +19 -0
- package/output/components/theme-switcher.d.ts +6 -0
- package/output/components/theme-switcher.d.ts.map +1 -0
- package/output/components/theme-switcher.js +19 -0
- package/output/components/toaster/index.d.ts +16 -0
- package/output/components/toaster/index.d.ts.map +1 -0
- package/output/components/toaster/index.js +70 -0
- package/output/components/toggle-group.d.ts +12 -0
- package/output/components/toggle-group.d.ts.map +1 -0
- package/output/components/toggle-group.js +38 -0
- package/output/components/toggle.d.ts +10 -0
- package/output/components/toggle.d.ts.map +1 -0
- package/output/components/toggle.js +38 -0
- package/output/components/tooltip.d.ts +8 -0
- package/output/components/tooltip.d.ts.map +1 -0
- package/output/components/tooltip.js +33 -0
- package/output/features/confirm-dialog/index.d.ts +41 -0
- package/output/features/confirm-dialog/index.d.ts.map +1 -0
- package/output/features/confirm-dialog/index.js +19 -0
- package/output/features/input-confirm/index.d.ts +26 -0
- package/output/features/input-confirm/index.d.ts.map +1 -0
- package/output/features/input-confirm/index.js +59 -0
- package/output/features/signin/context.d.ts +14 -0
- package/output/features/signin/context.d.ts.map +1 -0
- package/output/features/signin/context.js +13 -0
- package/output/features/signin/index.d.ts +58 -0
- package/output/features/signin/index.d.ts.map +1 -0
- package/output/features/signin/index.js +137 -0
- package/output/features/signin/service.d.ts +92 -0
- package/output/features/signin/service.d.ts.map +1 -0
- package/output/features/signin/service.js +519 -0
- package/output/features/signin/service.test.d.ts +2 -0
- package/output/features/signin/service.test.d.ts.map +1 -0
- package/output/features/signin/service.test.js +211 -0
- package/output/features/signin/types.d.ts +63 -0
- package/output/features/signin/types.d.ts.map +1 -0
- package/output/features/signin/types.js +1 -0
- package/output/hooks/use-loading/index.d.ts +6 -0
- package/output/hooks/use-loading/index.d.ts.map +1 -0
- package/output/hooks/use-loading/index.js +14 -0
- package/output/hooks/use-loading/index.test.d.ts +2 -0
- package/output/hooks/use-loading/index.test.d.ts.map +1 -0
- package/output/hooks/use-loading/index.test.js +24 -0
- package/output/hooks/use-mobile/index.d.ts +2 -0
- package/output/hooks/use-mobile/index.d.ts.map +1 -0
- package/output/hooks/use-mobile/index.js +16 -0
- package/output/hooks/use-observer/index.d.ts +2 -0
- package/output/hooks/use-observer/index.d.ts.map +1 -0
- package/output/hooks/use-observer/index.js +1 -0
- package/output/hooks/use-observer/use-observer.d.ts +3 -0
- package/output/hooks/use-observer/use-observer.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.js +16 -0
- package/output/hooks/use-observer/use-observer.test.d.ts +2 -0
- package/output/hooks/use-observer/use-observer.test.d.ts.map +1 -0
- package/output/hooks/use-observer/use-observer.test.js +134 -0
- package/output/hooks/use-offline/index.d.ts +6 -0
- package/output/hooks/use-offline/index.d.ts.map +1 -0
- package/output/hooks/use-offline/index.js +19 -0
- package/output/layout/app/index.d.ts +34 -0
- package/output/layout/app/index.d.ts.map +1 -0
- package/output/layout/app/index.js +34 -0
- package/output/layout/dashboard/index.d.ts +76 -0
- package/output/layout/dashboard/index.d.ts.map +1 -0
- package/output/layout/dashboard/index.js +84 -0
- package/output/layout/index.d.ts +3 -0
- package/output/layout/index.d.ts.map +1 -0
- package/output/layout/index.js +2 -0
- package/output/services/cache-api/cache-api.d.ts +23 -0
- package/output/services/cache-api/cache-api.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.js +145 -0
- package/output/services/cache-api/cache-api.test.d.ts +2 -0
- package/output/services/cache-api/cache-api.test.d.ts.map +1 -0
- package/output/services/cache-api/cache-api.test.js +610 -0
- package/output/services/cache-api/index.d.ts +2 -0
- package/output/services/cache-api/index.d.ts.map +1 -0
- package/output/services/cache-api/index.js +1 -0
- package/output/services/cached-fetch/index.d.ts +50 -0
- package/output/services/cached-fetch/index.d.ts.map +1 -0
- package/output/services/cached-fetch/index.js +196 -0
- package/output/services/service/index.d.ts +2 -0
- package/output/services/service/index.d.ts.map +1 -0
- package/output/services/service/index.js +1 -0
- package/output/services/service/service.d.ts +135 -0
- package/output/services/service/service.d.ts.map +1 -0
- package/output/services/service/service.js +276 -0
- package/output/services/service/service.test.d.ts +2 -0
- package/output/services/service/service.test.d.ts.map +1 -0
- package/output/services/service/service.test.js +1399 -0
- package/output/services/side-cache/index.d.ts +2 -0
- package/output/services/side-cache/index.d.ts.map +1 -0
- package/output/services/side-cache/index.js +1 -0
- package/output/services/side-cache/side-cache.d.ts +11 -0
- package/output/services/side-cache/side-cache.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.js +161 -0
- package/output/services/side-cache/side-cache.test.d.ts +2 -0
- package/output/services/side-cache/side-cache.test.d.ts.map +1 -0
- package/output/services/side-cache/side-cache.test.js +271 -0
- package/output/utils/avatar/index.d.ts +28 -0
- package/output/utils/avatar/index.d.ts.map +1 -0
- package/output/utils/avatar/index.js +35 -0
- package/output/utils/delay/index.d.ts +2 -0
- package/output/utils/delay/index.d.ts.map +1 -0
- package/output/utils/delay/index.js +5 -0
- package/output/utils/form/index.d.ts +3 -0
- package/output/utils/form/index.d.ts.map +1 -0
- package/output/utils/form/index.js +1 -0
- package/output/utils/merge-class-names/index.d.ts +3 -0
- package/output/utils/merge-class-names/index.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.js +5 -0
- package/output/utils/merge-class-names/index.test.d.ts +2 -0
- package/output/utils/merge-class-names/index.test.d.ts.map +1 -0
- package/output/utils/merge-class-names/index.test.js +7 -0
- package/output/utils/performance/index.d.ts +82 -0
- package/output/utils/performance/index.d.ts.map +1 -0
- package/output/utils/performance/index.js +129 -0
- package/output/utils/redirect/index.d.ts +6 -0
- package/output/utils/redirect/index.d.ts.map +1 -0
- package/output/utils/redirect/index.js +32 -0
- package/package.json +8 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SideCache } from './side-cache.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class SideCache<T> {
|
|
2
|
+
private accessor emptyFlag;
|
|
3
|
+
private accessor currentKey;
|
|
4
|
+
private accessor cache;
|
|
5
|
+
get value(): T | undefined;
|
|
6
|
+
get empty(): boolean;
|
|
7
|
+
handle<F extends ((...args: unknown[]) => T)>(key: unknown, func: F): T;
|
|
8
|
+
handle<F extends ((...args: unknown[]) => Promise<T> | T)>(key: unknown, func: F): Promise<T> | T;
|
|
9
|
+
clear(key?: unknown): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=side-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-cache.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/side-cache.ts"],"names":[],"mappings":"AAWA,qBAAa,SAAS,CAAC,CAAC;IAEtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAgB;IAG1C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAG/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;IAE1D,IACW,KAAK,IAAI,CAAC,GAAG,SAAS,CAIhC;IAED,IACW,KAAK,IAAI,OAAO,CAE1B;IAED,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC;IACvE,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;IAyC1F,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,IAAI;CAoBlC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
38
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
39
|
+
};
|
|
40
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
41
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
42
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
43
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
44
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
45
|
+
};
|
|
46
|
+
import { action, computed, observable, runInAction } from 'mobx';
|
|
47
|
+
function isPromiseLike(value) {
|
|
48
|
+
return value != null && typeof value.then === 'function';
|
|
49
|
+
}
|
|
50
|
+
let SideCache = (() => {
|
|
51
|
+
var _a, _SideCache_emptyFlag_accessor_storage, _SideCache_currentKey_accessor_storage, _SideCache_cache_accessor_storage;
|
|
52
|
+
var _b, _c, _d;
|
|
53
|
+
let _instanceExtraInitializers = [];
|
|
54
|
+
let _emptyFlag_decorators;
|
|
55
|
+
let _emptyFlag_initializers = [];
|
|
56
|
+
let _emptyFlag_extraInitializers = [];
|
|
57
|
+
let _currentKey_decorators;
|
|
58
|
+
let _currentKey_initializers = [];
|
|
59
|
+
let _currentKey_extraInitializers = [];
|
|
60
|
+
let _cache_decorators;
|
|
61
|
+
let _cache_initializers = [];
|
|
62
|
+
let _cache_extraInitializers = [];
|
|
63
|
+
let _get_value_decorators;
|
|
64
|
+
let _get_empty_decorators;
|
|
65
|
+
let _handle_decorators;
|
|
66
|
+
let _clear_decorators;
|
|
67
|
+
return _a = class SideCache {
|
|
68
|
+
get emptyFlag() { return __classPrivateFieldGet(this, _SideCache_emptyFlag_accessor_storage, "f"); }
|
|
69
|
+
set emptyFlag(value) { __classPrivateFieldSet(this, _SideCache_emptyFlag_accessor_storage, value, "f"); }
|
|
70
|
+
get currentKey() { return __classPrivateFieldGet(this, _SideCache_currentKey_accessor_storage, "f"); }
|
|
71
|
+
set currentKey(value) { __classPrivateFieldSet(this, _SideCache_currentKey_accessor_storage, value, "f"); }
|
|
72
|
+
get cache() { return __classPrivateFieldGet(this, _SideCache_cache_accessor_storage, "f"); }
|
|
73
|
+
set cache(value) { __classPrivateFieldSet(this, _SideCache_cache_accessor_storage, value, "f"); }
|
|
74
|
+
get value() {
|
|
75
|
+
if (this.currentKey == null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const cacheItem = this.cache[this.currentKey];
|
|
78
|
+
return cacheItem ? cacheItem.data : undefined;
|
|
79
|
+
}
|
|
80
|
+
get empty() {
|
|
81
|
+
return this.emptyFlag;
|
|
82
|
+
}
|
|
83
|
+
handle(key, func) {
|
|
84
|
+
var _b;
|
|
85
|
+
// 不需要跨设备、软件一致,所以直接用 JSON.stringify
|
|
86
|
+
// 但需要处理 JSON.stringify(undefined) 返回 undefined 的情况
|
|
87
|
+
const keyStringify = (_b = JSON.stringify(key)) !== null && _b !== void 0 ? _b : 'undefined';
|
|
88
|
+
// 这会让外面立马可以拿到之前缓存的值,如果存在的话
|
|
89
|
+
runInAction(() => this.currentKey = keyStringify);
|
|
90
|
+
const funcReturn = func();
|
|
91
|
+
if (isPromiseLike(funcReturn)) {
|
|
92
|
+
return funcReturn.then(result => runInAction(() => {
|
|
93
|
+
this.emptyFlag = false;
|
|
94
|
+
this.cache = Object.assign(Object.assign({}, this.cache), { [keyStringify]: {
|
|
95
|
+
data: result,
|
|
96
|
+
createTime: new Date().toISOString()
|
|
97
|
+
} });
|
|
98
|
+
return result;
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
runInAction(() => {
|
|
102
|
+
this.emptyFlag = false;
|
|
103
|
+
this.cache = Object.assign(Object.assign({}, this.cache), { [keyStringify]: {
|
|
104
|
+
data: funcReturn,
|
|
105
|
+
createTime: new Date().toISOString()
|
|
106
|
+
} });
|
|
107
|
+
});
|
|
108
|
+
return funcReturn;
|
|
109
|
+
}
|
|
110
|
+
clear(key) {
|
|
111
|
+
var _b;
|
|
112
|
+
if (key === undefined) {
|
|
113
|
+
// 清除所有缓存
|
|
114
|
+
this.cache = {};
|
|
115
|
+
this.emptyFlag = true;
|
|
116
|
+
this.currentKey = undefined;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
// 清除指定 key 的缓存
|
|
120
|
+
const keyStringify = (_b = JSON.stringify(key)) !== null && _b !== void 0 ? _b : 'undefined';
|
|
121
|
+
const newCache = Object.assign({}, this.cache);
|
|
122
|
+
delete newCache[keyStringify];
|
|
123
|
+
this.cache = newCache;
|
|
124
|
+
// 如果清除的是当前 key,需要重置状态
|
|
125
|
+
if (this.currentKey === keyStringify) {
|
|
126
|
+
this.emptyFlag = Object.keys(this.cache).length === 0;
|
|
127
|
+
this.currentKey = undefined;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
constructor() {
|
|
132
|
+
_SideCache_emptyFlag_accessor_storage.set(this, (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _emptyFlag_initializers, true)));
|
|
133
|
+
_SideCache_currentKey_accessor_storage.set(this, (__runInitializers(this, _emptyFlag_extraInitializers), __runInitializers(this, _currentKey_initializers, void 0)));
|
|
134
|
+
_SideCache_cache_accessor_storage.set(this, (__runInitializers(this, _currentKey_extraInitializers), __runInitializers(this, _cache_initializers, {})));
|
|
135
|
+
__runInitializers(this, _cache_extraInitializers);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
_SideCache_emptyFlag_accessor_storage = new WeakMap(),
|
|
139
|
+
_SideCache_currentKey_accessor_storage = new WeakMap(),
|
|
140
|
+
_SideCache_cache_accessor_storage = new WeakMap(),
|
|
141
|
+
(() => {
|
|
142
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
143
|
+
_emptyFlag_decorators = [observable];
|
|
144
|
+
_currentKey_decorators = [observable];
|
|
145
|
+
_cache_decorators = [(_b = observable).ref.bind(_b)];
|
|
146
|
+
_get_value_decorators = [computed];
|
|
147
|
+
_get_empty_decorators = [computed];
|
|
148
|
+
_handle_decorators = [(_c = action).bound.bind(_c)];
|
|
149
|
+
_clear_decorators = [(_d = action).bound.bind(_d)];
|
|
150
|
+
__esDecorate(_a, null, _emptyFlag_decorators, { kind: "accessor", name: "emptyFlag", static: false, private: false, access: { has: obj => "emptyFlag" in obj, get: obj => obj.emptyFlag, set: (obj, value) => { obj.emptyFlag = value; } }, metadata: _metadata }, _emptyFlag_initializers, _emptyFlag_extraInitializers);
|
|
151
|
+
__esDecorate(_a, null, _currentKey_decorators, { kind: "accessor", name: "currentKey", static: false, private: false, access: { has: obj => "currentKey" in obj, get: obj => obj.currentKey, set: (obj, value) => { obj.currentKey = value; } }, metadata: _metadata }, _currentKey_initializers, _currentKey_extraInitializers);
|
|
152
|
+
__esDecorate(_a, null, _cache_decorators, { kind: "accessor", name: "cache", static: false, private: false, access: { has: obj => "cache" in obj, get: obj => obj.cache, set: (obj, value) => { obj.cache = value; } }, metadata: _metadata }, _cache_initializers, _cache_extraInitializers);
|
|
153
|
+
__esDecorate(_a, null, _get_value_decorators, { kind: "getter", name: "value", static: false, private: false, access: { has: obj => "value" in obj, get: obj => obj.value }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
154
|
+
__esDecorate(_a, null, _get_empty_decorators, { kind: "getter", name: "empty", static: false, private: false, access: { has: obj => "empty" in obj, get: obj => obj.empty }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
155
|
+
__esDecorate(_a, null, _handle_decorators, { kind: "method", name: "handle", static: false, private: false, access: { has: obj => "handle" in obj, get: obj => obj.handle }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
156
|
+
__esDecorate(_a, null, _clear_decorators, { kind: "method", name: "clear", static: false, private: false, access: { has: obj => "clear" in obj, get: obj => obj.clear }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
157
|
+
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
158
|
+
})(),
|
|
159
|
+
_a;
|
|
160
|
+
})();
|
|
161
|
+
export { SideCache };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"side-cache.test.d.ts","sourceRoot":"","sources":["../../../source/services/side-cache/side-cache.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { runInAction } from 'mobx';
|
|
3
|
+
import { SideCache } from './side-cache.js';
|
|
4
|
+
describe('SideCache', () => {
|
|
5
|
+
let cache;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
cache = new SideCache();
|
|
8
|
+
});
|
|
9
|
+
describe('初始状态', () => {
|
|
10
|
+
it('应该初始化为空状态', () => {
|
|
11
|
+
expect(cache.empty).toBe(true);
|
|
12
|
+
expect(cache.value).toBe(undefined);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
describe('同步缓存', () => {
|
|
16
|
+
it('应该能够缓存同步函数的结果', () => {
|
|
17
|
+
const mockFunc = vi.fn(() => 'test-result');
|
|
18
|
+
const key = 'test-key';
|
|
19
|
+
const result = cache.handle(key, mockFunc);
|
|
20
|
+
expect(result).toBe('test-result');
|
|
21
|
+
expect(mockFunc).toHaveBeenCalledTimes(1);
|
|
22
|
+
expect(cache.empty).toBe(false);
|
|
23
|
+
expect(cache.value).toBe('test-result');
|
|
24
|
+
});
|
|
25
|
+
it('应该对相同 key 返回缓存的结果', () => {
|
|
26
|
+
const mockFunc = vi.fn(() => 'cached-result');
|
|
27
|
+
const key = 'same-key';
|
|
28
|
+
// 第一次调用
|
|
29
|
+
const result1 = cache.handle(key, mockFunc);
|
|
30
|
+
expect(result1).toBe('cached-result');
|
|
31
|
+
expect(mockFunc).toHaveBeenCalledTimes(1);
|
|
32
|
+
// 第二次调用相同 key,应该直接返回缓存
|
|
33
|
+
const result2 = cache.handle(key, mockFunc);
|
|
34
|
+
expect(result2).toBe('cached-result');
|
|
35
|
+
expect(mockFunc).toHaveBeenCalledTimes(2); // 函数仍会被调用,但会更新缓存
|
|
36
|
+
expect(cache.value).toBe('cached-result');
|
|
37
|
+
});
|
|
38
|
+
it('应该对不同 key 分别缓存', () => {
|
|
39
|
+
const mockFunc1 = vi.fn(() => 'result1');
|
|
40
|
+
const mockFunc2 = vi.fn(() => 'result2');
|
|
41
|
+
cache.handle('key1', mockFunc1);
|
|
42
|
+
expect(cache.value).toBe('result1');
|
|
43
|
+
cache.handle('key2', mockFunc2);
|
|
44
|
+
expect(cache.value).toBe('result2');
|
|
45
|
+
// 切换回 key1
|
|
46
|
+
cache.handle('key1', mockFunc1);
|
|
47
|
+
expect(cache.value).toBe('result1');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('异步缓存', () => {
|
|
51
|
+
it('应该能够缓存异步函数的结果', async () => {
|
|
52
|
+
const mockAsyncFunc = vi.fn(async () => 'async-result');
|
|
53
|
+
const key = 'async-key';
|
|
54
|
+
const promise = cache.handle(key, mockAsyncFunc);
|
|
55
|
+
expect(promise).toBeInstanceOf(Promise);
|
|
56
|
+
const result = await promise;
|
|
57
|
+
expect(result).toBe('async-result');
|
|
58
|
+
expect(mockAsyncFunc).toHaveBeenCalledTimes(1);
|
|
59
|
+
expect(cache.empty).toBe(false);
|
|
60
|
+
expect(cache.value).toBe('async-result');
|
|
61
|
+
});
|
|
62
|
+
it('应该在异步函数执行期间立即设置 currentKey', async () => {
|
|
63
|
+
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
64
|
+
const mockAsyncFunc = vi.fn(async () => {
|
|
65
|
+
await delay(10);
|
|
66
|
+
return 'delayed-result';
|
|
67
|
+
});
|
|
68
|
+
const key = 'delayed-key';
|
|
69
|
+
// 在异步函数开始执行时,currentKey 应该已经设置
|
|
70
|
+
const promise = cache.handle(key, mockAsyncFunc);
|
|
71
|
+
// 此时异步函数还在执行,但 currentKey 已设置
|
|
72
|
+
// 如果之前有缓存,value 应该能立即获取到
|
|
73
|
+
const result = await promise;
|
|
74
|
+
expect(result).toBe('delayed-result');
|
|
75
|
+
expect(cache.value).toBe('delayed-result');
|
|
76
|
+
});
|
|
77
|
+
it('应该处理异步函数的错误', async () => {
|
|
78
|
+
const error = new Error('Async error');
|
|
79
|
+
const mockAsyncFunc = vi.fn(async () => {
|
|
80
|
+
throw error;
|
|
81
|
+
});
|
|
82
|
+
const key = 'error-key';
|
|
83
|
+
await expect(cache.handle(key, mockAsyncFunc)).rejects.toThrow('Async error');
|
|
84
|
+
expect(mockAsyncFunc).toHaveBeenCalledTimes(1);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
describe('key 序列化', () => {
|
|
88
|
+
it('应该正确处理不同类型的 key', () => {
|
|
89
|
+
const mockFunc = vi.fn(() => 'result');
|
|
90
|
+
// 字符串 key
|
|
91
|
+
cache.handle('string-key', mockFunc);
|
|
92
|
+
expect(cache.value).toBe('result');
|
|
93
|
+
// 数字 key
|
|
94
|
+
cache.handle(123, mockFunc);
|
|
95
|
+
expect(cache.value).toBe('result');
|
|
96
|
+
// 对象 key
|
|
97
|
+
cache.handle({ id: 1, name: 'test' }, mockFunc);
|
|
98
|
+
expect(cache.value).toBe('result');
|
|
99
|
+
// 数组 key
|
|
100
|
+
cache.handle([1, 2, 3], mockFunc);
|
|
101
|
+
expect(cache.value).toBe('result');
|
|
102
|
+
});
|
|
103
|
+
it('相同内容的对象 key 应该被视为相同', () => {
|
|
104
|
+
const mockFunc = vi.fn(() => 'object-result');
|
|
105
|
+
const key1 = { id: 1, name: 'test' };
|
|
106
|
+
const key2 = { id: 1, name: 'test' };
|
|
107
|
+
cache.handle(key1, mockFunc);
|
|
108
|
+
const result1 = cache.value;
|
|
109
|
+
cache.handle(key2, mockFunc);
|
|
110
|
+
const result2 = cache.value;
|
|
111
|
+
expect(result1).toBe(result2);
|
|
112
|
+
expect(result1).toBe('object-result');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('缓存时间戳', () => {
|
|
116
|
+
it('应该为缓存项添加创建时间', () => {
|
|
117
|
+
const mockFunc = vi.fn(() => 'timestamped-result');
|
|
118
|
+
const key = 'timestamp-key';
|
|
119
|
+
const beforeTime = new Date().toISOString();
|
|
120
|
+
cache.handle(key, mockFunc);
|
|
121
|
+
const afterTime = new Date().toISOString();
|
|
122
|
+
// 访问私有属性进行测试(仅用于测试目的)
|
|
123
|
+
const cacheData = cache.cache;
|
|
124
|
+
const cachedItem = cacheData[JSON.stringify(key)];
|
|
125
|
+
expect(cachedItem).toBeDefined();
|
|
126
|
+
expect(cachedItem.data).toBe('timestamped-result');
|
|
127
|
+
expect(cachedItem.createTime).toBeDefined();
|
|
128
|
+
expect(typeof cachedItem.createTime).toBe('string');
|
|
129
|
+
// 验证时间戳在合理范围内
|
|
130
|
+
expect(cachedItem.createTime >= beforeTime).toBe(true);
|
|
131
|
+
expect(cachedItem.createTime <= afterTime).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
describe('边界情况', () => {
|
|
135
|
+
it('应该处理 null 和 undefined key', () => {
|
|
136
|
+
const mockFunc1 = vi.fn(() => 'null-key-result');
|
|
137
|
+
const mockFunc2 = vi.fn(() => 'undefined-key-result');
|
|
138
|
+
cache.handle(null, mockFunc1);
|
|
139
|
+
expect(cache.value).toBe('null-key-result');
|
|
140
|
+
cache.handle(undefined, mockFunc2);
|
|
141
|
+
expect(cache.value).toBe('undefined-key-result');
|
|
142
|
+
});
|
|
143
|
+
it('应该处理返回 null 或 undefined 的函数', () => {
|
|
144
|
+
const nullFunc = vi.fn(() => null);
|
|
145
|
+
const undefinedFunc = vi.fn(() => undefined);
|
|
146
|
+
cache.handle('null-key', nullFunc);
|
|
147
|
+
expect(cache.value).toBe(null);
|
|
148
|
+
expect(cache.empty).toBe(false);
|
|
149
|
+
cache.handle('undefined-key', undefinedFunc);
|
|
150
|
+
expect(cache.value).toBe(undefined);
|
|
151
|
+
expect(cache.empty).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
it('应该处理返回 Promise.resolve(null) 的异步函数', async () => {
|
|
154
|
+
const nullAsyncFunc = vi.fn(async () => null);
|
|
155
|
+
const result = await cache.handle('async-null', nullAsyncFunc);
|
|
156
|
+
expect(result).toBe(null);
|
|
157
|
+
expect(cache.value).toBe(null);
|
|
158
|
+
expect(cache.empty).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('类型检查', () => {
|
|
162
|
+
it('应该正确识别 Promise-like 对象', async () => {
|
|
163
|
+
let thenCallback;
|
|
164
|
+
const promiseLike = {
|
|
165
|
+
then: vi.fn((callback) => {
|
|
166
|
+
thenCallback = callback;
|
|
167
|
+
return promiseLike;
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
const mockFunc = vi.fn(() => promiseLike);
|
|
171
|
+
const result = cache.handle('promise-like', mockFunc);
|
|
172
|
+
expect(result).toBe(promiseLike);
|
|
173
|
+
expect(promiseLike.then).toHaveBeenCalled();
|
|
174
|
+
// 模拟 Promise 完成
|
|
175
|
+
if (thenCallback) {
|
|
176
|
+
thenCallback('resolved-value');
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe('clear 方法', () => {
|
|
181
|
+
it('应该能够清除指定 key 的缓存', () => {
|
|
182
|
+
const mockFunc = vi.fn(() => 'test-result');
|
|
183
|
+
const key = 'test-key';
|
|
184
|
+
// 先添加缓存
|
|
185
|
+
cache.handle(key, mockFunc);
|
|
186
|
+
expect(cache.empty).toBe(false);
|
|
187
|
+
expect(cache.value).toBe('test-result');
|
|
188
|
+
// 清除指定 key 的缓存
|
|
189
|
+
cache.clear(key);
|
|
190
|
+
expect(cache.empty).toBe(true);
|
|
191
|
+
expect(cache.value).toBe(undefined);
|
|
192
|
+
});
|
|
193
|
+
it('应该能够清除当前激活的缓存', () => {
|
|
194
|
+
const mockFunc = vi.fn(() => 'active-result');
|
|
195
|
+
const key = 'active-key';
|
|
196
|
+
cache.handle(key, mockFunc);
|
|
197
|
+
expect(cache.value).toBe('active-result');
|
|
198
|
+
// 清除当前激活的 key
|
|
199
|
+
cache.clear(key);
|
|
200
|
+
expect(cache.value).toBe(undefined);
|
|
201
|
+
expect(cache.empty).toBe(true);
|
|
202
|
+
});
|
|
203
|
+
it('应该能够清除所有缓存', () => {
|
|
204
|
+
const mockFunc1 = vi.fn(() => 'result1');
|
|
205
|
+
const mockFunc2 = vi.fn(() => 'result2');
|
|
206
|
+
// 添加多个缓存
|
|
207
|
+
cache.handle('key1', mockFunc1);
|
|
208
|
+
cache.handle('key2', mockFunc2);
|
|
209
|
+
expect(cache.value).toBe('result2');
|
|
210
|
+
expect(cache.empty).toBe(false);
|
|
211
|
+
// 清除所有缓存
|
|
212
|
+
cache.clear();
|
|
213
|
+
expect(cache.value).toBe(undefined);
|
|
214
|
+
expect(cache.empty).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
it('应该能够清除非当前激活的缓存而不影响当前状态', () => {
|
|
217
|
+
const mockFunc1 = vi.fn(() => 'result1');
|
|
218
|
+
const mockFunc2 = vi.fn(() => 'result2');
|
|
219
|
+
// 添加两个缓存
|
|
220
|
+
cache.handle('key1', mockFunc1);
|
|
221
|
+
cache.handle('key2', mockFunc2);
|
|
222
|
+
expect(cache.value).toBe('result2'); // 当前激活的是 key2
|
|
223
|
+
// 清除非当前激活的 key1
|
|
224
|
+
cache.clear('key1');
|
|
225
|
+
expect(cache.value).toBe('result2'); // 当前值不变
|
|
226
|
+
expect(cache.empty).toBe(false); // 仍有缓存存在
|
|
227
|
+
});
|
|
228
|
+
it('应该正确处理清除不存在的 key', () => {
|
|
229
|
+
const mockFunc = vi.fn(() => 'test-result');
|
|
230
|
+
cache.handle('existing-key', mockFunc);
|
|
231
|
+
// 清除不存在的 key 不应该影响现有缓存
|
|
232
|
+
cache.clear('non-existing-key');
|
|
233
|
+
expect(cache.value).toBe('test-result');
|
|
234
|
+
expect(cache.empty).toBe(false);
|
|
235
|
+
});
|
|
236
|
+
it('应该正确处理复杂对象作为 key', () => {
|
|
237
|
+
const complexKey = { id: 1, data: { nested: 'value' } };
|
|
238
|
+
const mockFunc = vi.fn(() => 'complex-result');
|
|
239
|
+
// 使用复杂对象作为 key
|
|
240
|
+
cache.handle(complexKey, mockFunc);
|
|
241
|
+
expect(cache.value).toBe('complex-result');
|
|
242
|
+
// 清除复杂对象 key
|
|
243
|
+
cache.clear(complexKey);
|
|
244
|
+
expect(cache.value).toBe(undefined);
|
|
245
|
+
expect(cache.empty).toBe(true);
|
|
246
|
+
});
|
|
247
|
+
it('应该正确处理 undefined 作为 key', () => {
|
|
248
|
+
const mockFunc = vi.fn(() => 'undefined-key-result');
|
|
249
|
+
// 使用 undefined 作为 key
|
|
250
|
+
cache.handle(undefined, mockFunc);
|
|
251
|
+
expect(cache.value).toBe('undefined-key-result');
|
|
252
|
+
// 清除 undefined key
|
|
253
|
+
cache.clear(undefined);
|
|
254
|
+
expect(cache.value).toBe(undefined);
|
|
255
|
+
expect(cache.empty).toBe(true);
|
|
256
|
+
});
|
|
257
|
+
it('应该在 MobX action 中正确更新状态', () => {
|
|
258
|
+
const mockFunc = vi.fn(() => 'action-result');
|
|
259
|
+
const key = 'action-key';
|
|
260
|
+
runInAction(() => {
|
|
261
|
+
cache.handle(key, mockFunc);
|
|
262
|
+
});
|
|
263
|
+
expect(cache.value).toBe('action-result');
|
|
264
|
+
runInAction(() => {
|
|
265
|
+
cache.clear(key);
|
|
266
|
+
});
|
|
267
|
+
expect(cache.value).toBe(undefined);
|
|
268
|
+
expect(cache.empty).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Avatar 工具函数
|
|
3
|
+
* 用于生成用户头像 URL
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 使用原生 Web Crypto API 生成 SHA-256 哈希
|
|
7
|
+
* @param input 输入字符串
|
|
8
|
+
* @returns SHA-256 哈希值(十六进制字符串)
|
|
9
|
+
*/
|
|
10
|
+
export type GetUserAvatarUrlParams = {
|
|
11
|
+
username: string;
|
|
12
|
+
avatar?: string | null;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* 生成 Gravatar 头像 URL
|
|
16
|
+
* @param email 用户邮箱
|
|
17
|
+
* @param size 头像大小(像素)
|
|
18
|
+
* @returns Gravatar URL
|
|
19
|
+
*/
|
|
20
|
+
export declare function getGravatarUrl(email: string, size?: number): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* 生成用户头像 URL
|
|
23
|
+
* @param user 用户对象
|
|
24
|
+
* @param size 头像大小(像素)
|
|
25
|
+
* @returns 头像 URL(如果有自定义头像返回自定义,否则返回 Gravatar)
|
|
26
|
+
*/
|
|
27
|
+
export declare function getUserAvatarUrl(user: GetUserAvatarUrlParams, size?: number): Promise<string>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/avatar/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAA;AAWjF;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9E;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,EAAE,IAAI,SAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAK/F"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Avatar 工具函数
|
|
3
|
+
* 用于生成用户头像 URL
|
|
4
|
+
*/
|
|
5
|
+
async function sha256(input) {
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
const data = encoder.encode(input);
|
|
8
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
9
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
10
|
+
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 生成 Gravatar 头像 URL
|
|
14
|
+
* @param email 用户邮箱
|
|
15
|
+
* @param size 头像大小(像素)
|
|
16
|
+
* @returns Gravatar URL
|
|
17
|
+
*/
|
|
18
|
+
export async function getGravatarUrl(email, size = 80) {
|
|
19
|
+
const trimmedEmail = email.trim();
|
|
20
|
+
const lowerEmail = trimmedEmail.toLowerCase();
|
|
21
|
+
const hash = await sha256(lowerEmail);
|
|
22
|
+
return `https://www.gravatar.com/avatar/${hash}?d=mp&s=${size}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 生成用户头像 URL
|
|
26
|
+
* @param user 用户对象
|
|
27
|
+
* @param size 头像大小(像素)
|
|
28
|
+
* @returns 头像 URL(如果有自定义头像返回自定义,否则返回 Gravatar)
|
|
29
|
+
*/
|
|
30
|
+
export async function getUserAvatarUrl(user, size = 80) {
|
|
31
|
+
if (user.avatar) {
|
|
32
|
+
return user.avatar;
|
|
33
|
+
}
|
|
34
|
+
return getGravatarUrl(user.username, size);
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/delay/index.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAI/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/form/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;AACzF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/utils/merge-class-names/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAG5C,wBAAgB,eAAe,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../../source/utils/merge-class-names/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { mergeClassNames } from './index.js';
|
|
3
|
+
describe('mergeClassNames', () => {
|
|
4
|
+
it('merges conditional and conflicting Tailwind classes', () => {
|
|
5
|
+
expect(mergeClassNames('px-2', false && 'text-muted-foreground', 'px-4')).toBe('px-4');
|
|
6
|
+
});
|
|
7
|
+
});
|