twcpt 0.0.28 → 0.0.29
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/index.d.ts +6 -0
- package/dist/twcpt.cjs.js +6 -6
- package/dist/twcpt.es.js +3173 -2995
- package/dist/utils/getCssVarValue.d.ts +29 -0
- package/dist/utils/img-load/index.d.ts +2 -0
- package/dist/utils/img-load/preloadImage.d.ts +32 -0
- package/dist/utils/useIntervalPolling.d.ts +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* getCssVarValue 配置项
|
|
3
|
+
* @example
|
|
4
|
+
* const color = getCssVarValue(['--j-color-white', '--el-color-white'], {
|
|
5
|
+
* fallback: '#fff',
|
|
6
|
+
* });
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const spacing = getCssVarValue('--j-spacing-base', {
|
|
10
|
+
* fallback: 16,
|
|
11
|
+
* transform: (v) => Number.parseFloat(v),
|
|
12
|
+
* });
|
|
13
|
+
*/
|
|
14
|
+
export interface GetCssVarValueOptions<T = string> {
|
|
15
|
+
fallback?: T | string;
|
|
16
|
+
target?: HTMLElement | null;
|
|
17
|
+
trim?: boolean;
|
|
18
|
+
transform?: (value: string) => T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 读取 CSS 变量值,支持多变量回退与结果转换
|
|
22
|
+
* @param variableName CSS 变量名(支持 '--token' 或 'token'),也支持变量名数组(按顺序回退)
|
|
23
|
+
* @param options 配置项
|
|
24
|
+
* @example
|
|
25
|
+
* import { getCssVarValue } from 'twcpt';
|
|
26
|
+
*
|
|
27
|
+
* const whiteColor = getCssVarValue('--j-color-white', { fallback: '#FFFFFF' });
|
|
28
|
+
*/
|
|
29
|
+
export declare function getCssVarValue<T = string>(variableName: string | string[], options?: GetCssVarValueOptions<T>): T | string;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type ImageLoadStatus = 'loaded' | 'placeholder' | 'error';
|
|
2
|
+
export interface PreloadImageOptions {
|
|
3
|
+
placeholderSrc?: string;
|
|
4
|
+
errorSrc?: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
crossOrigin?: '' | 'anonymous' | 'use-credentials';
|
|
7
|
+
referrerPolicy?: ReferrerPolicy;
|
|
8
|
+
decode?: boolean;
|
|
9
|
+
cache?: boolean;
|
|
10
|
+
force?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface PreloadImageResult {
|
|
13
|
+
src: string;
|
|
14
|
+
displaySrc: string;
|
|
15
|
+
status: ImageLoadStatus;
|
|
16
|
+
fromCache: boolean;
|
|
17
|
+
img: HTMLImageElement | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 预加载图片并返回可直接用于 img 的 displaySrc(成功图 / 占位图 / 错误图)
|
|
21
|
+
* @example
|
|
22
|
+
* const result = await preloadImage('https://cdn.xxx.com/a.png', {
|
|
23
|
+
* placeholderSrc: '/images/placeholder.png',
|
|
24
|
+
* errorSrc: '/images/error.png',
|
|
25
|
+
* timeout: 8000,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // result.displaySrc 可直接用于 <img :src="result.displaySrc" />
|
|
29
|
+
*/
|
|
30
|
+
export declare function preloadImage(src: string, options?: PreloadImageOptions): Promise<PreloadImageResult>;
|
|
31
|
+
export declare function hasPreloadedImage(src: string): boolean;
|
|
32
|
+
export declare function clearPreloadedImageCache(src?: string): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IntervalPollingOptions {
|
|
2
|
+
interval?: number;
|
|
3
|
+
immediate?: boolean;
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
autoStopWhenHidden?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface IntervalPollingController {
|
|
8
|
+
start: () => void;
|
|
9
|
+
stop: () => void;
|
|
10
|
+
isRunning: () => boolean;
|
|
11
|
+
updateInterval: (newInterval: number) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function useIntervalPolling(callback: () => any, options?: IntervalPollingOptions): IntervalPollingController;
|
package/package.json
CHANGED