@kylexd/composable-kit 0.0.1

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.
Files changed (48) hide show
  1. package/README.md +91 -0
  2. package/dist/composables/useApi.d.ts +78 -0
  3. package/dist/composables/useCache.d.ts +23 -0
  4. package/dist/composables/useCookies.d.ts +8 -0
  5. package/dist/composables/useCountdown.d.ts +31 -0
  6. package/dist/composables/useCreatedCancelApi.d.ts +41 -0
  7. package/dist/composables/useDownload.d.ts +5 -0
  8. package/dist/composables/useDownloadLink.d.ts +22 -0
  9. package/dist/composables/useForm.d.ts +13 -0
  10. package/dist/composables/useIsMobile.d.ts +7 -0
  11. package/dist/composables/useOpenLink.d.ts +8 -0
  12. package/dist/composables/useParseZod.d.ts +23 -0
  13. package/dist/composables/usePcHtmlToMobile.d.ts +40 -0
  14. package/dist/composables/usePopupQueue.d.ts +22 -0
  15. package/dist/composables/useQrCode.d.ts +6 -0
  16. package/dist/composables/useRsa.d.ts +6 -0
  17. package/dist/composables.d.ts +15 -0
  18. package/dist/composables.js +2 -0
  19. package/dist/dayjs-BXpdKo4H.js +65 -0
  20. package/dist/index.d.ts +34 -0
  21. package/dist/index.js +5 -0
  22. package/dist/sdk/useFirebase.d.ts +12 -0
  23. package/dist/sdk/useIntercom.d.ts +19 -0
  24. package/dist/sdk/useSalesmartly.d.ts +24 -0
  25. package/dist/sdk/useTurbolinkSdk.d.ts +30 -0
  26. package/dist/sdk.d.ts +4 -0
  27. package/dist/sdk.js +2 -0
  28. package/dist/tree-Ck3oXYA2.js +332 -0
  29. package/dist/types/shared.d.ts +11 -0
  30. package/dist/useRsa-aK-vaZUD.js +739 -0
  31. package/dist/useTurbolinkSdk-peRMONxI.js +250 -0
  32. package/dist/utils/copy.d.ts +5 -0
  33. package/dist/utils/dayjs.d.ts +15 -0
  34. package/dist/utils/debounce.d.ts +5 -0
  35. package/dist/utils/deepClone.d.ts +1 -0
  36. package/dist/utils/encryption.d.ts +11 -0
  37. package/dist/utils/formatParams.d.ts +4 -0
  38. package/dist/utils/isNotEmpty.d.ts +1 -0
  39. package/dist/utils/patterns.d.ts +1 -0
  40. package/dist/utils/piniaPersistedState.d.ts +15 -0
  41. package/dist/utils/renderSfc.d.ts +16 -0
  42. package/dist/utils/singleFlight.d.ts +6 -0
  43. package/dist/utils/thumbnail.d.ts +13 -0
  44. package/dist/utils/tree.d.ts +20 -0
  45. package/dist/utils/typeUtils.d.ts +3 -0
  46. package/dist/utils.d.ts +14 -0
  47. package/dist/utils.js +3 -0
  48. package/package.json +135 -0
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @kylexd/composable-kit
2
+
3
+ ## Overview
4
+
5
+ Small utility and composable package for browser-oriented Vue projects.
6
+
7
+ It includes general helpers, Vue composables, browser helpers, and several SDK wrappers. Some exports require peer packages to be installed by the host project.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @kylexd/composable-kit
13
+ ```
14
+
15
+ ## Exports
16
+
17
+ Utilities:
18
+
19
+ - `debounce`
20
+ - `singleFlight`
21
+ - `deepClone`
22
+ - `formatParams`
23
+ - `listToTreeOptimized`
24
+ - `treeOptimizedToList`
25
+ - `copyText`
26
+
27
+ Composables:
28
+
29
+ - `useCache`
30
+ - `useDataApi`
31
+ - `useListApi`
32
+ - `useScrollList`
33
+ - `useCountdown`
34
+ - `usePcHtmlToMobile`
35
+ - `usePopupQueue`
36
+ - `useQrCode`
37
+ - `useRsa`
38
+
39
+ Subpath entries:
40
+
41
+ - `@kylexd/composable-kit/utils`
42
+ - `@kylexd/composable-kit/composables`
43
+ - `@kylexd/composable-kit/sdk`
44
+
45
+ SDK helpers:
46
+
47
+ - `useFirebase`
48
+ - `useIntercom`
49
+ - `useSalesmartly`
50
+ - `useTurbolinkSdk`
51
+
52
+ ## Basic usage
53
+
54
+ ```ts
55
+ import { debounce, useCache } from '@kylexd/composable-kit'
56
+
57
+ const onSearch = debounce(() => {
58
+ // update search
59
+ }, 300)
60
+ ```
61
+
62
+ ```ts
63
+ import { usePopupQueue } from '@kylexd/composable-kit'
64
+
65
+ const popup = usePopupQueue({
66
+ key: 'default',
67
+ start() {},
68
+ })
69
+ ```
70
+
71
+ ```ts
72
+ import { debounce } from '@kylexd/composable-kit/utils'
73
+ import { useCache } from '@kylexd/composable-kit/composables'
74
+ ```
75
+
76
+ ## Build
77
+
78
+ ```bash
79
+ npm run build
80
+ ```
81
+
82
+ ## Notes
83
+
84
+ - Peer dependencies are optional, but individual exports still need their related packages at runtime.
85
+ - Prefer subpath entries when the host project only needs one group of exports.
86
+ - SDK helpers expect configuration and project data from the host project.
87
+ - Browser-only helpers should not be called in non-browser environments.
88
+
89
+ ## License
90
+
91
+ UNLICENSED
@@ -0,0 +1,78 @@
1
+ import { type Ref } from 'vue';
2
+ import { type CacheConfig } from './useCache';
3
+ import { type FormatParamsOptions } from '../utils/formatParams';
4
+ export interface UseDataApiOptions<R, F, Q> {
5
+ format?: (response: {
6
+ data: R;
7
+ }, oldData?: F) => F;
8
+ cache?: CacheConfig;
9
+ query?: Ref<Q>;
10
+ formatParams?: (params: Q) => Q;
11
+ catchError?: (error: Error, data?: F) => F | undefined;
12
+ onError?: (error: unknown) => void;
13
+ }
14
+ export interface AsyncApiOptions {
15
+ forceRefresh?: boolean;
16
+ }
17
+ export declare function useDataApi<T, R, F = R>(asyncApi: ((params: T) => Promise<{
18
+ data: R;
19
+ }>) | ((params?: T) => Promise<{
20
+ data: R;
21
+ }>), options?: UseDataApiOptions<R, F, T>): {
22
+ loading: Ref<boolean, boolean>;
23
+ data: Ref<F | undefined, F | undefined>;
24
+ sentDataApi: (params?: T, asyncApiOptions?: AsyncApiOptions) => Promise<F>;
25
+ };
26
+ export interface UseListApiOptions<R, F, Q, D> {
27
+ format?: (response: {
28
+ list: R;
29
+ total: number;
30
+ data?: D;
31
+ }, oldList?: F, params?: Q) => F;
32
+ formatParamsOptions?: FormatParamsOptions<Q>;
33
+ query?: Ref<Q>;
34
+ catchError?: (error: Error, oldList?: F) => F | undefined;
35
+ isCancel?: (error: unknown) => boolean;
36
+ onError?: (error: unknown) => void;
37
+ }
38
+ export declare function useListApi<T, R, F = R, D = undefined>(asyncApi: (params?: T) => Promise<{
39
+ list: R;
40
+ total: number;
41
+ data?: D;
42
+ }>, options?: UseListApiOptions<R, F, T, D>): {
43
+ loading: Ref<boolean, boolean>;
44
+ dataList: Ref<F | undefined, F | undefined>;
45
+ getList: () => Promise<F>;
46
+ total: Ref<number, number>;
47
+ data: Ref<D | undefined, D | undefined>;
48
+ };
49
+ export interface UseScrollListOptions<R extends unknown[], F, Q, D> {
50
+ format?: (response: {
51
+ list: R;
52
+ total: number;
53
+ data?: D;
54
+ }, params?: Q) => F;
55
+ formatParamsOptions?: FormatParamsOptions<Q>;
56
+ query?: Ref<Q & {
57
+ pageNum?: number;
58
+ pageSize?: number;
59
+ }>;
60
+ catchError?: (error: Error, oldList?: F) => F | undefined;
61
+ onError?: (error: unknown) => void;
62
+ }
63
+ export declare function useScrollList<T extends {
64
+ pageNum?: number;
65
+ pageSize?: number;
66
+ }, R extends unknown[], F = R, D = undefined>(asyncApi: (params?: T) => Promise<{
67
+ list: R;
68
+ total: number;
69
+ data?: D;
70
+ }>, options?: UseScrollListOptions<R, F, T, D>): {
71
+ loading: Ref<boolean, boolean>;
72
+ dataList: Ref<F | undefined, F | undefined>;
73
+ getList: () => Promise<F>;
74
+ total: Ref<number, number>;
75
+ data: Ref<D | undefined, D | undefined>;
76
+ isError: Ref<boolean, boolean>;
77
+ isNoMore: Ref<boolean, boolean>;
78
+ };
@@ -0,0 +1,23 @@
1
+ import { type Ref } from 'vue';
2
+ export interface CacheConfig {
3
+ key: string;
4
+ time: number;
5
+ useMemory?: boolean;
6
+ storageType?: 'localStorage' | 'sessionStorage';
7
+ baseKey?: string;
8
+ memoryStorage?: Map<string, StorageData<unknown>>;
9
+ exposeMemoryToWindow?: string | false;
10
+ }
11
+ export interface StorageData<T> {
12
+ data: T;
13
+ createdTime: number;
14
+ time: number;
15
+ }
16
+ export declare function useCache<T>(options: CacheConfig): {
17
+ cacheData: Ref<T | null, T | null>;
18
+ clearCache: () => void;
19
+ setCacheData: (data: T) => void;
20
+ getCacheData: () => T | null;
21
+ };
22
+ export declare function clearAllHooksCache(baseKey?: string, storageType?: 'localStorage' | 'sessionStorage'): void;
23
+ export declare function clearAllMemoryCache(memoryStorage?: Map<string, StorageData<unknown>>): void;
@@ -0,0 +1,8 @@
1
+ export interface UseCookiesOptions {
2
+ domain?: string | (() => string | undefined);
3
+ }
4
+ export declare function useCookies(options?: UseCookiesOptions): {
5
+ setCookie: (key: string, value: string, expires: number) => void;
6
+ getCookie: (key: string) => string | undefined;
7
+ removeCookie: (key: string) => void;
8
+ };
@@ -0,0 +1,31 @@
1
+ import { type Ref } from 'vue';
2
+ export interface DurationOfDays {
3
+ s: number;
4
+ m: number;
5
+ h: number;
6
+ d: number;
7
+ asSeconds: number;
8
+ }
9
+ export interface DurationOfHours {
10
+ s: number;
11
+ m: number;
12
+ h: number;
13
+ asSeconds: number;
14
+ }
15
+ export interface CountdownOptions {
16
+ stopCallback?: () => void;
17
+ }
18
+ export type CountdownDateRef<T extends object> = Ref<T> & T;
19
+ export declare function useCountdown(): {
20
+ getCurrentDurationOfDays: (targetTime?: string | Date, options?: CountdownOptions) => {
21
+ date: CountdownDateRef<DurationOfDays>;
22
+ stop: () => void;
23
+ updateTargetTime: (newTargetTime?: string | Date) => void;
24
+ };
25
+ getCurrentDurationOfHours: (targetTime?: string | Date, options?: CountdownOptions) => {
26
+ date: CountdownDateRef<DurationOfHours>;
27
+ stop: () => void;
28
+ updateTargetTime: (newTargetTime?: string | Date) => void;
29
+ };
30
+ getDiff: (targetTime: string | Date | undefined, unit: "seconds" | "minutes" | "hours" | "days") => number;
31
+ };
@@ -0,0 +1,41 @@
1
+ export interface AbortControllerReceiver {
2
+ useAbortController?: (controller: AbortController) => void;
3
+ }
4
+ export declare function useCreatedCancelApi<P, R, O extends AbortControllerReceiver = AbortControllerReceiver>(api: (params: P, options?: O) => Promise<R>): {
5
+ api: (params?: P) => Promise<R>;
6
+ cancel: import("vue").Ref<{
7
+ readonly signal: {
8
+ readonly aborted: boolean;
9
+ onabort: ((this: AbortSignal, ev: Event) => any) | null;
10
+ readonly reason: any;
11
+ throwIfAborted: () => void;
12
+ addEventListener: {
13
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
14
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
15
+ };
16
+ removeEventListener: {
17
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
18
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
19
+ };
20
+ dispatchEvent: (event: Event) => boolean;
21
+ };
22
+ abort: (reason?: any) => void;
23
+ } | null, AbortController | {
24
+ readonly signal: {
25
+ readonly aborted: boolean;
26
+ onabort: ((this: AbortSignal, ev: Event) => any) | null;
27
+ readonly reason: any;
28
+ throwIfAborted: () => void;
29
+ addEventListener: {
30
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
31
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
32
+ };
33
+ removeEventListener: {
34
+ <K extends keyof AbortSignalEventMap>(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
35
+ (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
36
+ };
37
+ dispatchEvent: (event: Event) => boolean;
38
+ };
39
+ abort: (reason?: any) => void;
40
+ } | null>;
41
+ };
@@ -0,0 +1,5 @@
1
+ export declare function useDownload(): {
2
+ downloadBase64File: (base64: string, name: string) => void;
3
+ downloadBlobFile: (blob: Blob, name: string) => void;
4
+ downloadUrlFile: (url: string, name: string) => void;
5
+ };
@@ -0,0 +1,22 @@
1
+ import { type UseCookiesOptions } from './useCookies';
2
+ export interface DownloadLinkPair {
3
+ appleURL: string;
4
+ googleURL: string;
5
+ }
6
+ export interface UseDownloadLinkOptions {
7
+ cookies?: UseCookiesOptions;
8
+ defaultLinks: DownloadLinkPair;
9
+ cookieKeys?: {
10
+ appleURL?: string;
11
+ googleURL?: string;
12
+ };
13
+ expires?: number;
14
+ userAgent?: string;
15
+ }
16
+ export declare function useDownloadLink(options: UseDownloadLinkOptions): {
17
+ setDownloadLinkToCookie: (links: DownloadLinkPair) => void;
18
+ getDownloadLinkFromCookie: () => Partial<DownloadLinkPair>;
19
+ getDownloadLink: () => DownloadLinkPair;
20
+ downloadApp: () => void;
21
+ getPlatformDownloadAppLink: () => string;
22
+ };
@@ -0,0 +1,13 @@
1
+ import { type Ref } from 'vue';
2
+ export interface FormResetAdapter {
3
+ resetValidation?: () => void;
4
+ }
5
+ export interface UseFormOptions<T> {
6
+ excludeKeys?: Array<keyof T>;
7
+ }
8
+ export declare function useForm<T extends {
9
+ pageNum?: number;
10
+ pageSize?: number;
11
+ } & Record<string, unknown>>(formData: Ref<T>, formRef?: Ref<FormResetAdapter | null | undefined>, options?: UseFormOptions<T>): {
12
+ resetForm: (excludeKeys?: Array<keyof T>) => void;
13
+ };
@@ -0,0 +1,7 @@
1
+ export declare function useIsMobile(userAgent?: string): {
2
+ any: boolean;
3
+ phone: boolean;
4
+ tablet: boolean;
5
+ isIOS: boolean;
6
+ raw: import("ismobilejs").isMobileResult;
7
+ };
@@ -0,0 +1,8 @@
1
+ export interface UseOpenLinkOptions {
2
+ baseUrl: string | (() => string);
3
+ isInternalRoute?: (path: string) => boolean;
4
+ open?: (url: string, target: string) => void;
5
+ }
6
+ export declare function useOpenLink(options: UseOpenLinkOptions): {
7
+ openLink: (link: string) => void;
8
+ };
@@ -0,0 +1,23 @@
1
+ export interface ZodLikeIssue {
2
+ message: string;
3
+ }
4
+ export interface ZodLikeError {
5
+ issues: ReadonlyArray<ZodLikeIssue>;
6
+ }
7
+ export type ZodLikeParseResult = {
8
+ success: true;
9
+ data: unknown;
10
+ } | {
11
+ success: false;
12
+ error: ZodLikeError;
13
+ };
14
+ export interface ZodLikeSchema {
15
+ safeParse: (data: unknown) => ZodLikeParseResult;
16
+ }
17
+ export interface UseParseZodOptions {
18
+ onError?: (issue: ZodLikeIssue, error: ZodLikeError) => void;
19
+ }
20
+ export declare function useParseZod(defaultOptions?: UseParseZodOptions): {
21
+ parseZod: (schema: ZodLikeSchema, data: unknown, options?: UseParseZodOptions) => boolean;
22
+ asyncParseZod: (schema: ZodLikeSchema, data: unknown, options?: UseParseZodOptions) => Promise<ZodLikeParseResult>;
23
+ };
@@ -0,0 +1,40 @@
1
+ import { type Ref } from 'vue';
2
+ export interface PcHtmlImageTransformContext {
3
+ index: number;
4
+ src: string | null;
5
+ width: string | null;
6
+ style: Record<string, string>;
7
+ content: DocumentFragment;
8
+ }
9
+ export interface PcHtmlLinkTransformContext {
10
+ index: number;
11
+ href: string | null;
12
+ content: DocumentFragment;
13
+ }
14
+ export interface UsePcHtmlToMobileOptions {
15
+ baseWidth?: number;
16
+ heightOffset?: number;
17
+ hiddenContainerId?: string;
18
+ transformImage?: (image: HTMLImageElement, context: PcHtmlImageTransformContext) => void;
19
+ transformLink?: (anchor: HTMLAnchorElement, context: PcHtmlLinkTransformContext) => void;
20
+ onImageClick?: (srcList: string[]) => void;
21
+ }
22
+ export interface PcHtmlTransformStyle {
23
+ scale: number;
24
+ translateX: number;
25
+ translateY: number;
26
+ }
27
+ export declare function usePcHtmlToMobile(options?: UsePcHtmlToMobileOptions): {
28
+ containerRef: Ref<HTMLElement | null, HTMLElement | null>;
29
+ adaptedHtml: Ref<string, string>;
30
+ contentHeight: Ref<number, number>;
31
+ transformStyle: {
32
+ scale: number;
33
+ translateX: number;
34
+ translateY: number;
35
+ };
36
+ formatHtml: (html: string) => Promise<string>;
37
+ updateLayout: () => void;
38
+ handleClick: (event: MouseEvent) => string[];
39
+ cleanup: () => void;
40
+ };
@@ -0,0 +1,22 @@
1
+ export type PopupQueueStatus = 'pending' | 'success' | 'cancel' | 'processing';
2
+ export interface PopupQueueItem {
3
+ start: () => void;
4
+ status: PopupQueueStatus;
5
+ key: symbol;
6
+ timeout?: number;
7
+ onStateChange?: (status: PopupQueueStatus) => void;
8
+ timer?: number;
9
+ }
10
+ export interface UsePopupQueueOptions {
11
+ key: string;
12
+ start: () => void;
13
+ timeout?: number;
14
+ onStateChange?: (status: PopupQueueStatus) => void;
15
+ onTimeout?: () => void;
16
+ }
17
+ export interface UsePopupQueueReturn {
18
+ end: () => void;
19
+ cancel: () => void;
20
+ getStatus: () => PopupQueueStatus | undefined;
21
+ }
22
+ export declare function usePopupQueue(options: UsePopupQueueOptions): UsePopupQueueReturn;
@@ -0,0 +1,6 @@
1
+ export interface UseQrCodeOptions {
2
+ width?: number;
3
+ }
4
+ export declare function useQrCode(defaultOptions?: UseQrCodeOptions): {
5
+ generateQrCode: (text: string, options?: UseQrCodeOptions) => Promise<string>;
6
+ };
@@ -0,0 +1,6 @@
1
+ export interface UseRsaOptions {
2
+ getPublicKey: () => Promise<string> | string;
3
+ }
4
+ export declare function useRsa(options: UseRsaOptions): {
5
+ encrypt: (needEncryptData: string) => Promise<string>;
6
+ };
@@ -0,0 +1,15 @@
1
+ export * from './composables/useApi';
2
+ export * from './composables/useCache';
3
+ export * from './composables/useCountdown';
4
+ export * from './composables/useCookies';
5
+ export * from './composables/useCreatedCancelApi';
6
+ export * from './composables/useDownload';
7
+ export * from './composables/useDownloadLink';
8
+ export * from './composables/useForm';
9
+ export * from './composables/useIsMobile';
10
+ export * from './composables/useOpenLink';
11
+ export * from './composables/useParseZod';
12
+ export * from './composables/usePcHtmlToMobile';
13
+ export * from './composables/usePopupQueue';
14
+ export * from './composables/useQrCode';
15
+ export * from './composables/useRsa';
@@ -0,0 +1,2 @@
1
+ import { _ as clearAllHooksCache, a as useParseZod, c as useDownloadLink, d as useCreatedCancelApi, f as useCookies, g as useScrollList, h as useListApi, i as usePcHtmlToMobile, l as useIsMobile, m as useDataApi, n as useQrCode, o as useOpenLink, p as useCountdown, r as usePopupQueue, s as useForm, t as useRsa, u as useDownload, v as clearAllMemoryCache, y as useCache } from "./useRsa-aK-vaZUD.js";
2
+ export { clearAllHooksCache, clearAllMemoryCache, useCache, useCookies, useCountdown, useCreatedCancelApi, useDataApi, useDownload, useDownloadLink, useForm, useIsMobile, useListApi, useOpenLink, useParseZod, usePcHtmlToMobile, usePopupQueue, useQrCode, useRsa, useScrollList };
@@ -0,0 +1,65 @@
1
+ import dayjs from "dayjs";
2
+ import duration from "dayjs/plugin/duration";
3
+ import minMax from "dayjs/plugin/minMax";
4
+ import relativeTime from "dayjs/plugin/relativeTime";
5
+ import timezone from "dayjs/plugin/timezone";
6
+ import utc from "dayjs/plugin/utc";
7
+ //#region src/utils/deepClone.ts
8
+ function deepClone(value) {
9
+ try {
10
+ return structuredClone(value);
11
+ } catch {
12
+ return customDeepClone(value);
13
+ }
14
+ }
15
+ function customDeepClone(value) {
16
+ if (value === null || typeof value !== "object") return value;
17
+ if (value instanceof Date) return new Date(value.getTime());
18
+ if (Array.isArray(value)) return value.map((item) => customDeepClone(item));
19
+ const output = {};
20
+ for (const key in value) if (Object.prototype.hasOwnProperty.call(value, key)) output[key] = customDeepClone(value[key]);
21
+ return output;
22
+ }
23
+ //#endregion
24
+ //#region src/utils/formatParams.ts
25
+ function formatParams(params, options) {
26
+ if (!params) return params;
27
+ if (Object.prototype.toString.call(params) !== "[object Object]") return params;
28
+ return Object.fromEntries(Object.entries(params).filter(([key, value]) => {
29
+ if (options?.skipFields?.includes(key)) return true;
30
+ return value !== void 0 && value !== null && value !== "";
31
+ }));
32
+ }
33
+ //#endregion
34
+ //#region src/utils/dayjs.ts
35
+ dayjs.extend(utc);
36
+ dayjs.extend(timezone);
37
+ dayjs.extend(duration);
38
+ dayjs.extend(relativeTime);
39
+ dayjs.extend(minMax);
40
+ var dayjsInstance = dayjs;
41
+ function formatTime(date, format = "YYYY-MM-DD HH:mm:ss") {
42
+ if (!date) return "--";
43
+ return dayjsInstance(date).format(format);
44
+ }
45
+ function formatTimeWithUtcOffset(date, offset = 8, format) {
46
+ const result = dayjsInstance(date).utcOffset(offset);
47
+ return format ? result.format(format) : result.format();
48
+ }
49
+ function formatLocalStringAsUtcOffset(date, offset = 8) {
50
+ return dayjsInstance(date).utc(true).utcOffset(offset, true).format();
51
+ }
52
+ function getNowWithUtcOffset(offset = 8, format = "YYYY-MM-DD HH:mm:ss") {
53
+ return dayjsInstance().utcOffset(offset).format(format);
54
+ }
55
+ function formatTimeBeijingStringToUtc8String(date) {
56
+ return formatLocalStringAsUtcOffset(date, 8);
57
+ }
58
+ function getNowBeijingTime() {
59
+ return getNowWithUtcOffset(8);
60
+ }
61
+ function utcFormatToBeijingString(date, format = "YYYY-MM-DD HH:mm:ss") {
62
+ return formatTimeWithUtcOffset(date, 8, format);
63
+ }
64
+ //#endregion
65
+ export { formatTimeWithUtcOffset as a, utcFormatToBeijingString as c, formatTimeBeijingStringToUtc8String as i, formatParams as l, formatLocalStringAsUtcOffset as n, getNowBeijingTime as o, formatTime as r, getNowWithUtcOffset as s, dayjsInstance as t, deepClone as u };
@@ -0,0 +1,34 @@
1
+ export * from './composables/useApi';
2
+ export * from './composables/useCache';
3
+ export * from './composables/useCountdown';
4
+ export * from './composables/useCookies';
5
+ export * from './composables/useCreatedCancelApi';
6
+ export * from './composables/useDownload';
7
+ export * from './composables/useDownloadLink';
8
+ export * from './composables/useForm';
9
+ export * from './composables/useIsMobile';
10
+ export * from './composables/useOpenLink';
11
+ export * from './composables/useParseZod';
12
+ export * from './composables/usePcHtmlToMobile';
13
+ export * from './composables/usePopupQueue';
14
+ export * from './composables/useQrCode';
15
+ export * from './composables/useRsa';
16
+ export * from './sdk/useFirebase';
17
+ export * from './sdk/useIntercom';
18
+ export * from './sdk/useSalesmartly';
19
+ export * from './sdk/useTurbolinkSdk';
20
+ export * from './types/shared';
21
+ export * from './utils/copy';
22
+ export * from './utils/dayjs';
23
+ export * from './utils/debounce';
24
+ export * from './utils/deepClone';
25
+ export * from './utils/encryption';
26
+ export * from './utils/formatParams';
27
+ export * from './utils/isNotEmpty';
28
+ export * from './utils/patterns';
29
+ export * from './utils/piniaPersistedState';
30
+ export * from './utils/renderSfc';
31
+ export * from './utils/singleFlight';
32
+ export * from './utils/thumbnail';
33
+ export * from './utils/tree';
34
+ export * from './utils/typeUtils';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { _ as clearAllHooksCache, a as useParseZod, c as useDownloadLink, d as useCreatedCancelApi, f as useCookies, g as useScrollList, h as useListApi, i as usePcHtmlToMobile, l as useIsMobile, m as useDataApi, n as useQrCode, o as useOpenLink, p as useCountdown, r as usePopupQueue, s as useForm, t as useRsa, u as useDownload, v as clearAllMemoryCache, y as useCache } from "./useRsa-aK-vaZUD.js";
2
+ import { a as formatTimeWithUtcOffset, c as utcFormatToBeijingString, i as formatTimeBeijingStringToUtc8String, l as formatParams, n as formatLocalStringAsUtcOffset, o as getNowBeijingTime, r as formatTime, s as getNowWithUtcOffset, t as dayjsInstance, u as deepClone } from "./dayjs-BXpdKo4H.js";
3
+ import { a as useFirebase, i as resolveMaybeRef, n as useSalesmartly, r as useIntercom, t as useTurbolinkSdk } from "./useTurbolinkSdk-peRMONxI.js";
4
+ import { _ as copyText, a as getThumbnailUrl, c as renderSFC, d as encodePersistedState, f as urlPattern, g as debounce, h as encrypt, i as getOssThumbnailUrl, l as createVersionedPiniaPersistedState, m as decrypt, n as treeOptimizedToList, o as createSingleFlight, p as isNotEmpty, r as getCdnThumbnailUrl, s as singleFlight, t as listToTreeOptimized, u as decodePersistedState } from "./tree-Ck3oXYA2.js";
5
+ export { clearAllHooksCache, clearAllMemoryCache, copyText, createSingleFlight, createVersionedPiniaPersistedState, dayjsInstance, debounce, decodePersistedState, decrypt, deepClone, encodePersistedState, encrypt, formatLocalStringAsUtcOffset, formatParams, formatTime, formatTimeBeijingStringToUtc8String, formatTimeWithUtcOffset, getCdnThumbnailUrl, getNowBeijingTime, getNowWithUtcOffset, getOssThumbnailUrl, getThumbnailUrl, isNotEmpty, listToTreeOptimized, renderSFC, resolveMaybeRef, singleFlight, treeOptimizedToList, urlPattern, useCache, useCookies, useCountdown, useCreatedCancelApi, useDataApi, useDownload, useDownloadLink, useFirebase, useForm, useIntercom, useIsMobile, useListApi, useOpenLink, useParseZod, usePcHtmlToMobile, usePopupQueue, useQrCode, useRsa, useSalesmartly, useScrollList, useTurbolinkSdk, utcFormatToBeijingString };
@@ -0,0 +1,12 @@
1
+ import { type FirebaseApp, type FirebaseOptions } from 'firebase/app';
2
+ import { type Analytics } from 'firebase/analytics';
3
+ export interface UseFirebaseOptions {
4
+ config: FirebaseOptions;
5
+ appName?: string;
6
+ eventExtras?: Record<string, unknown> | (() => Record<string, unknown>);
7
+ }
8
+ export declare function useFirebase(options: UseFirebaseOptions): {
9
+ app: FirebaseApp;
10
+ analytics: Analytics;
11
+ customLogEvent: (eventName: string, params?: Record<string, unknown>) => void;
12
+ };
@@ -0,0 +1,19 @@
1
+ import { type UseSdkUser, type UseSdkUserRef } from '../types/shared';
2
+ export interface UseIntercomOptions<T extends UseSdkUser = UseSdkUser> {
3
+ appId: string;
4
+ user?: UseSdkUserRef<T>;
5
+ encryptUserId?: (userId: string) => string;
6
+ mapUser?: (user: T) => Record<string, unknown>;
7
+ clearCookies?: (prefix: string) => void;
8
+ hideDefaultLauncher?: boolean;
9
+ }
10
+ export declare function useIntercom<T extends UseSdkUser = UseSdkUser>(options: UseIntercomOptions<T>): {
11
+ initIntercom: () => void;
12
+ updateUserInfo: () => void;
13
+ deleteIntercom: () => void;
14
+ shutdown: () => void;
15
+ showIntercom: () => void;
16
+ hideIntercom: () => void;
17
+ intercomLoading: import("vue").Ref<boolean, boolean>;
18
+ intercomUnreadMessage: import("vue").Ref<number, number>;
19
+ };
@@ -0,0 +1,24 @@
1
+ import { type UseSdkUser, type UseSdkUserRef } from '../types/shared';
2
+ export type SalesmartlyUnreadCallback = (params: {
3
+ num: number;
4
+ list: unknown[];
5
+ }) => void;
6
+ export type SalesmartlyMessageCallback = (params: unknown) => void;
7
+ export interface UseSalesmartlyOptions<T extends UseSdkUser = UseSdkUser> {
8
+ script: string;
9
+ user?: UseSdkUserRef<T>;
10
+ encryptUserId?: (userId: string) => string;
11
+ mapUser?: (user: T) => Record<string, unknown>;
12
+ adjustDom?: () => void;
13
+ }
14
+ export declare function useSalesmartly<T extends UseSdkUser = UseSdkUser>(options: UseSalesmartlyOptions<T>): {
15
+ loadSalesmartly: () => Promise<boolean>;
16
+ initSalesmartly: () => Promise<void>;
17
+ updateUserInfo: () => void;
18
+ deleteSalesmartly: () => Promise<void>;
19
+ showSalesmartly: () => Promise<void>;
20
+ hideSalesmartly: () => Promise<void>;
21
+ hideCloseIcon: () => Promise<void>;
22
+ onUnRead: (callback: SalesmartlyUnreadCallback) => Promise<void>;
23
+ onReceiveMessage: (callback: SalesmartlyMessageCallback) => Promise<void>;
24
+ };
@@ -0,0 +1,30 @@
1
+ import { type MaybeRef, type UseSdkUser, type UseSdkUserRef } from '../types/shared';
2
+ export interface TurbolinkEvent {
3
+ eventName: string;
4
+ backCamp?: boolean;
5
+ customData?: Array<{
6
+ key: string;
7
+ value: string;
8
+ }>;
9
+ }
10
+ export interface UseTurbolinkOptions<T extends UseSdkUser = UseSdkUser> {
11
+ config: MaybeRef<Record<string, unknown>>;
12
+ user?: UseSdkUserRef<T>;
13
+ lang?: MaybeRef<string | undefined>;
14
+ encryptUserId?: (userId: string) => string;
15
+ onLoadUrlEvent?: (event: unknown) => void | Promise<void>;
16
+ }
17
+ export declare function useTurbolinkSdk<T extends UseSdkUser = UseSdkUser>(options: UseTurbolinkOptions<T>): {
18
+ initTurbolink: () => Promise<unknown>;
19
+ setTurbolinkUserInfo: () => Promise<void>;
20
+ registerTurbolinkEvent: ({ uid }: {
21
+ uid: string | number;
22
+ }) => Promise<void>;
23
+ loginTurbolinkEvent: ({ uid }: {
24
+ uid: string | number;
25
+ }) => Promise<void>;
26
+ logoutTurbolinkEvent: () => Promise<unknown>;
27
+ loadUrl: (url: string, params?: Record<string, unknown>) => Promise<unknown>;
28
+ turbolinkCustomEvent: (event: TurbolinkEvent) => Promise<void>;
29
+ catchTurbolinkEvent: (event: TurbolinkEvent) => Promise<void>;
30
+ };