ranuts 0.2.0-alpha.0 → 0.3.0-alpha.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.
- package/CLAUDE.md +107 -16
- package/README.md +7 -5
- package/README.zh-CN.md +7 -5
- package/dist/chain-CTywmh_H.js +1 -0
- package/dist/{color-CRdlaDqQ.js → color-Dohr9BXX.js} +1 -1
- package/dist/enums-BAgbyGdH.js +1 -0
- package/dist/i18n-Cf5TtRb4.js +1 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -1
- package/dist/src/node/appendFile.d.ts +3 -3
- package/dist/src/node/fileInfo.d.ts +2 -2
- package/dist/src/node/index.js +1 -1
- package/dist/src/node/paresUrl.d.ts +1 -1
- package/dist/src/node/readFile.d.ts +3 -3
- package/dist/src/node/traverse.d.ts +2 -2
- package/dist/src/node/watchFile.d.ts +3 -3
- package/dist/src/node/writeFile.d.ts +3 -3
- package/dist/src/utils/async.d.ts +81 -0
- package/dist/src/utils/audioRecorder.d.ts +1 -1
- package/dist/src/utils/behavior.d.ts +12 -3
- package/dist/src/utils/bom.d.ts +68 -178
- package/dist/src/utils/bridge.d.ts +153 -0
- package/dist/src/utils/canvas.d.ts +54 -0
- package/dist/src/utils/chain.d.ts +80 -0
- package/dist/src/utils/color.d.ts +76 -4
- package/dist/src/utils/compose.d.ts +1 -1
- package/dist/src/utils/console.d.ts +19 -1
- package/dist/src/utils/debounce.d.ts +27 -5
- package/dist/src/utils/device.d.ts +31 -3
- package/dist/src/utils/dom.d.ts +5 -84
- package/dist/src/utils/error.d.ts +18 -1
- package/dist/src/utils/event.d.ts +61 -0
- package/dist/src/utils/file.d.ts +30 -0
- package/dist/src/utils/i18n/index.js +1 -0
- package/dist/src/utils/i18n.d.ts +69 -0
- package/dist/src/utils/idb.d.ts +178 -0
- package/dist/src/utils/img.d.ts +60 -4
- package/dist/src/utils/index.d.ts +48 -16
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/lang.d.ts +69 -0
- package/dist/src/utils/localePath.d.ts +62 -0
- package/dist/src/utils/memoize.d.ts +53 -5
- package/dist/src/utils/monitor.d.ts +55 -26
- package/dist/src/utils/number.d.ts +46 -9
- package/dist/src/utils/obj.d.ts +56 -31
- package/dist/src/utils/prefetch.d.ts +81 -0
- package/dist/src/utils/queue.d.ts +53 -23
- package/dist/src/utils/report.d.ts +51 -3
- package/dist/src/utils/request.d.ts +26 -7
- package/dist/src/utils/script.d.ts +26 -4
- package/dist/src/utils/segment.d.ts +62 -0
- package/dist/src/utils/signal.d.ts +35 -3
- package/dist/src/utils/storage.d.ts +57 -0
- package/dist/src/utils/str.d.ts +112 -88
- package/dist/src/utils/style.d.ts +31 -0
- package/dist/src/utils/subscribe.d.ts +5 -5
- package/dist/src/utils/throttle.d.ts +26 -13
- package/dist/src/utils/time.d.ts +38 -6
- package/dist/src/utils/tween.d.ts +40 -0
- package/dist/src/utils/visual/application.d.ts +4 -4
- package/dist/src/utils/visual/enums.d.ts +4 -4
- package/dist/src/utils/visual/graphics/graphics.d.ts +25 -25
- package/dist/src/utils/visual/graphics/graphicsData.d.ts +1 -1
- package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +6 -6
- package/dist/src/utils/visual/index.js +1 -1
- package/dist/src/utils/visual/math/matrix.d.ts +8 -8
- package/dist/src/utils/visual/math/transform.d.ts +1 -1
- package/dist/src/utils/visual/render/batchRenderer.d.ts +20 -18
- package/dist/src/utils/visual/render/utils/batch/index.d.ts +13 -13
- package/dist/src/utils/visual/render/utils/float.d.ts +13 -13
- package/dist/src/utils/visual/render/utils/verticy.d.ts +3 -3
- package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +3 -2
- package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +2 -2
- package/dist/src/utils/visual/render/webGPURenderer.d.ts +8 -8
- package/dist/src/utils/visual/vertex/container.d.ts +17 -16
- package/dist/src/utils/worker.d.ts +76 -0
- package/dist/src/utils/zip.d.ts +162 -0
- package/dist/src/vnode/index.d.ts +1 -1
- package/dist/src/vnode/index.js +1 -1
- package/dist/src/vnode/is.d.ts +4 -0
- package/dist/test/canvas.test.d.ts +1 -0
- package/dist/test/color.test.d.ts +1 -0
- package/dist/test/tween.test.d.ts +1 -0
- package/dist/test/utils/async.test.d.ts +1 -0
- package/dist/test/utils/file-read.test.d.ts +1 -0
- package/dist/test/utils/format.test.d.ts +1 -0
- package/dist/test/utils/idb.test.d.ts +1 -0
- package/dist/test/utils/instrumentation.test.d.ts +1 -0
- package/dist/test/utils/lang.test.d.ts +1 -0
- package/dist/test/utils/locale-path.test.d.ts +1 -0
- package/dist/test/utils/media-query.test.d.ts +1 -0
- package/dist/test/utils/number-parse.test.d.ts +1 -0
- package/dist/test/utils/prefetch.test.d.ts +1 -0
- package/dist/test/utils/query-storage.test.d.ts +1 -0
- package/dist/test/utils/queue.test.d.ts +1 -0
- package/dist/test/utils/report-config.test.d.ts +1 -0
- package/dist/test/utils/report-image.test.d.ts +1 -0
- package/dist/test/utils/segment.test.d.ts +1 -0
- package/dist/test/utils/signal-once.test.d.ts +1 -0
- package/dist/test/utils/single-flight.test.d.ts +1 -0
- package/dist/test/utils/timing.test.d.ts +1 -0
- package/dist/test/utils/worker-client.test.d.ts +1 -0
- package/dist/test/utils/zip.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/node/node.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/utils-BDtXHcK8.js +1 -0
- package/docs/API.md +306 -147
- package/package.json +32 -14
- package/dist/src/vnode/chainDom.d.ts +0 -47
- package/dist/subscribe-CINWsor3.js +0 -1
- package/dist/utils-_OxsVZmz.js +0 -1
|
@@ -45,7 +45,16 @@ export declare class Color {
|
|
|
45
45
|
updateFromHsl(): void;
|
|
46
46
|
}
|
|
47
47
|
export declare const randomColor: () => Color;
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* @description: `#rrggbb` / `#rgb` (with or without the `#`) to `[r, g, b]`; null when it cannot be parsed.
|
|
50
|
+
*
|
|
51
|
+
* The three-digit shorthand is expanded per the CSS rule (`#abc` → `#aabbcc`), not
|
|
52
|
+
* zero-padded — padding would turn `#fff` into `#0f0f0f`, a dark grey rather than white.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} hex
|
|
55
|
+
* @return {Array<number> | null}
|
|
56
|
+
*/
|
|
57
|
+
export declare const hexToRgb: (hex: string) => Array<number> | null;
|
|
49
58
|
export declare const componentToHex: (c: string | number) => string;
|
|
50
59
|
export declare const rgbToHex: (r: string | number | Array<string | number>, g?: string | number, b?: string | number) => string;
|
|
51
60
|
export declare const rgbToHsl: (r: number | number[], g?: number, b?: number) => Array<number>;
|
|
@@ -53,9 +62,72 @@ export declare const hue2rgb: (p: number, q: number, t: number) => number;
|
|
|
53
62
|
export declare const hslToRgb: (h: number | string | number[], s: number | string, l: number | string) => Array<number>;
|
|
54
63
|
export declare const rgbToHsb: (r: number, g: number, b: number) => number[];
|
|
55
64
|
export declare const hsbToRgb: (h: number, s: number, v: number) => number[];
|
|
56
|
-
export declare const hsvToRgb:
|
|
57
|
-
export declare const hsbToHsl: (h:
|
|
58
|
-
export declare const hsvToHsl:
|
|
65
|
+
export declare const hsvToRgb: typeof hsbToRgb;
|
|
66
|
+
export declare const hsbToHsl: (h: number, s: number, b: number) => number[];
|
|
67
|
+
export declare const hsvToHsl: typeof hsbToHsl;
|
|
68
|
+
/** Alias of `rgbToHsb` — HSV and HSB are two names for the same colour space. */
|
|
69
|
+
export declare const rgbToHsv: typeof rgbToHsb;
|
|
70
|
+
/**
|
|
71
|
+
* @description: `#rrggbb` / `#rgb` to `[h, s, b]`; null when the hex is invalid.
|
|
72
|
+
* @param {string} hex
|
|
73
|
+
* @return {number[] | null}
|
|
74
|
+
*/
|
|
75
|
+
export declare const hexToHsb: (hex: string) => number[] | null;
|
|
76
|
+
export declare const hexToHsv: typeof hexToHsb;
|
|
77
|
+
/**
|
|
78
|
+
* @description: `[h, s, l]` to `[h, s, b]`
|
|
79
|
+
* @param {number} h hue, 0–360
|
|
80
|
+
* @param {number} s saturation, 0–100
|
|
81
|
+
* @param {number} l lightness, 0–100
|
|
82
|
+
* @return {number[]}
|
|
83
|
+
*/
|
|
84
|
+
export declare const hslToHsb: (h: number, s: number, l: number) => number[];
|
|
85
|
+
export declare const hslToHsv: typeof hslToHsb;
|
|
86
|
+
/**
|
|
87
|
+
* @description: A two-digit hex alpha channel (`ff` / `80` / `00`) to a 0–100 percentage.
|
|
88
|
+
* @param {string} aa two hex digits
|
|
89
|
+
* @return {number} 0 ~ 100
|
|
90
|
+
*/
|
|
91
|
+
export declare const hexToAlpha: (aa: string) => number;
|
|
92
|
+
/**
|
|
93
|
+
* @description: Build a CSS `rgba()` string. Alpha is 0–100 rather than 0–1, matching the
|
|
94
|
+
* percentage convention the rest of this module uses.
|
|
95
|
+
* @param {number} r 0~255
|
|
96
|
+
* @param {number} g 0~255
|
|
97
|
+
* @param {number} b 0~255
|
|
98
|
+
* @param {number} a 0~100
|
|
99
|
+
* @return {string}
|
|
100
|
+
*/
|
|
101
|
+
export declare const rgbaString: (r: number, g: number, b: number, a: number) => string;
|
|
102
|
+
/**
|
|
103
|
+
* @description: Composite a translucent colour **over white**, giving the equivalent opaque rgb.
|
|
104
|
+
*
|
|
105
|
+
* For places that do not accept alpha (writing back a 6-digit hex, say). Note the backdrop
|
|
106
|
+
* is hard-coded to white: under a dark theme the result comes out too light, so composite
|
|
107
|
+
* against your own backdrop when you need a different one.
|
|
108
|
+
*
|
|
109
|
+
* @param {number} r 0~255
|
|
110
|
+
* @param {number} g 0~255
|
|
111
|
+
* @param {number} b 0~255
|
|
112
|
+
* @param {number} a 0~100
|
|
113
|
+
* @return {number[]} [r, g, b]
|
|
114
|
+
*/
|
|
115
|
+
export declare const rgbaToRgb: (r: number, g: number, b: number, a: number) => number[];
|
|
116
|
+
/**
|
|
117
|
+
* @description: Composite a translucent colour over white and return it as a 6-digit hex.
|
|
118
|
+
* @param {number} r 0~255
|
|
119
|
+
* @param {number} g 0~255
|
|
120
|
+
* @param {number} b 0~255
|
|
121
|
+
* @param {number} a 0~100
|
|
122
|
+
* @return {string}
|
|
123
|
+
*/
|
|
124
|
+
export declare const rgbaToHex: (r: number, g: number, b: number, a: number) => string;
|
|
125
|
+
/** `#rgb` / `#rrggbb` (the `#` is required) */
|
|
126
|
+
export declare const HEX_COLOR_REGEX: RegExp;
|
|
127
|
+
/** `rgb(r,g,b)`, no spaces — strip whitespace before matching */
|
|
128
|
+
export declare const RGB_REGEX: RegExp;
|
|
129
|
+
/** `rgba(r,g,b,a)`, no spaces — strip whitespace before matching */
|
|
130
|
+
export declare const RGBA_REGEX: RegExp;
|
|
59
131
|
export declare class ColorScheme {
|
|
60
132
|
palette: Color[];
|
|
61
133
|
constructor(colorVal: (string | number)[], angleArray: number[]);
|
|
@@ -2,7 +2,7 @@ export type Next = () => Promise<never> | Promise<void>;
|
|
|
2
2
|
type Middleware<T> = (context: T, next: Next) => any;
|
|
3
3
|
type ComposedMiddleware<T> = (context: T, next?: Next) => Promise<void>;
|
|
4
4
|
/**
|
|
5
|
-
* @description:
|
|
5
|
+
* @description: Run a chain of async functions as if it were sequential
|
|
6
6
|
* @param {Array} middleware
|
|
7
7
|
* @return {*}
|
|
8
8
|
*/
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'assert';
|
|
2
|
+
/**
|
|
3
|
+
* @description: Tap into `console` so every call also reaches your hook, while still printing
|
|
4
|
+
* as usual. Used to ship console output to a monitoring backend.
|
|
5
|
+
*
|
|
6
|
+
* Returns a **restore function** — patching a global without one is a one-way door: tests
|
|
7
|
+
* cannot clean up after themselves, and a hot reload re-patches an already-patched console
|
|
8
|
+
* until every log is nested through a dozen wrappers.
|
|
9
|
+
*
|
|
10
|
+
* @param {Function} hooks receives `(type, ...args)` for every console call
|
|
11
|
+
* @return {Function} restore — puts the original console methods back
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const restore = handleConsole((type, ...args) => send({ type, args }));
|
|
15
|
+
* // on teardown
|
|
16
|
+
* restore();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const handleConsole: (hooks?: (...args: unknown[]) => void) => (() => void);
|
|
@@ -1,7 +1,29 @@
|
|
|
1
|
+
export interface Debounced<T extends (...args: any[]) => any> {
|
|
2
|
+
(this: unknown, ...args: Parameters<T>): void;
|
|
3
|
+
/** Cancel the pending invocation, if any. */
|
|
4
|
+
cancel: () => void;
|
|
5
|
+
/** Invoke the pending call immediately (e.g. force a flush before form submit). */
|
|
6
|
+
flush: () => void;
|
|
7
|
+
/** Whether an invocation is currently waiting to fire. */
|
|
8
|
+
pending: () => boolean;
|
|
9
|
+
}
|
|
1
10
|
/**
|
|
2
|
-
* @description:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
11
|
+
* @description: Debounce — on a burst of calls, run only the last one, **`ms` milliseconds
|
|
12
|
+
* after the calls stop**. For input suggestions, window resize, autosave — anything that
|
|
13
|
+
* only cares about the final state.
|
|
14
|
+
*
|
|
15
|
+
* Preserves the caller's `this` and the arguments of the last call. The returned function
|
|
16
|
+
* carries `cancel` / `flush`: call `cancel()` on unmount, otherwise the pending timer fires
|
|
17
|
+
* into an already destroyed context.
|
|
18
|
+
*
|
|
19
|
+
* @param {Function} fn function to debounce
|
|
20
|
+
* @param {number} ms quiet period in milliseconds, defaults to 500
|
|
21
|
+
* @return {Debounced} wrapped function with cancel / flush / pending
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const save = debounce((draft: string) => api.save(draft), 800);
|
|
25
|
+
* input.addEventListener('input', (e) => save(e.target.value));
|
|
26
|
+
* onUnmount(() => save.cancel());
|
|
27
|
+
* ```
|
|
6
28
|
*/
|
|
7
|
-
export declare const debounce: (fn:
|
|
29
|
+
export declare const debounce: <T extends (...args: any[]) => any>(fn: T, ms?: number) => Debounced<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description:
|
|
2
|
+
* @description: Detect the current device
|
|
3
3
|
* @param {*} function
|
|
4
4
|
* @return {*}
|
|
5
5
|
*/
|
|
@@ -12,14 +12,42 @@ export declare enum DEVICE {
|
|
|
12
12
|
export type CurrentDevice = 'ipad' | 'android' | 'iphone' | 'pc';
|
|
13
13
|
export declare const currentDevice: () => CurrentDevice;
|
|
14
14
|
export declare const isClient: boolean;
|
|
15
|
+
/** Viewport breakpoint, matching where the mobile layout takes over */
|
|
16
|
+
export declare const MOBILE_MEDIA_QUERY = "(max-width: 768px)";
|
|
15
17
|
/**
|
|
16
|
-
* @description:
|
|
18
|
+
* @description: Read whether a media query currently matches, synchronously. Returns false under SSR.
|
|
19
|
+
*
|
|
20
|
+
* Prefer this over `isMobile()` when asking "is this mobile": UA sniffing identifies the
|
|
21
|
+
* **device**, a media query the **viewport** — and only the latter is right when a desktop
|
|
22
|
+
* window is narrowed or a tablet is rotated.
|
|
23
|
+
* @param {string} query the media query
|
|
24
|
+
* @return {boolean}
|
|
25
|
+
*/
|
|
26
|
+
export declare const matchMediaQuery: (query: string) => boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description: Watch a media query. The callback **fires once synchronously with the
|
|
29
|
+
* current value** (so the caller need not read the initial state separately), then on every
|
|
30
|
+
* change. Returns an unsubscribe function — call it when the component is destroyed or the
|
|
31
|
+
* page is disposed; an unreleased MediaQueryList listener leaks the closure and every DOM
|
|
32
|
+
* node it captured.
|
|
33
|
+
* @param {string} query the media query
|
|
34
|
+
* @param {Function} callback called when the match state changes
|
|
35
|
+
* @return {Function} unsubscribe
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const off = watchMediaQuery(MOBILE_MEDIA_QUERY, (isMobile) => render(isMobile));
|
|
39
|
+
* onCleanup(off);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const watchMediaQuery: (query: string, callback: (matches: boolean) => void) => (() => void);
|
|
43
|
+
/**
|
|
44
|
+
* @description: Whether this is the WeChat in-app browser
|
|
17
45
|
* @param {*} boolean
|
|
18
46
|
* @return {*}
|
|
19
47
|
*/
|
|
20
48
|
export declare const isWeiXin: () => boolean;
|
|
21
49
|
/**
|
|
22
|
-
*
|
|
50
|
+
* Whether this is a mobile device
|
|
23
51
|
*/
|
|
24
52
|
export declare const isMobile: () => boolean;
|
|
25
53
|
export declare const isBangDevice: () => boolean;
|
package/dist/src/utils/dom.d.ts
CHANGED
|
@@ -1,105 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description:
|
|
2
|
+
* @description: Add a class to an element
|
|
3
3
|
* @param {Element} element
|
|
4
4
|
* @param {string} addClass
|
|
5
5
|
*/
|
|
6
6
|
export declare const addClassToElement: (element: Element, addClass: string) => void;
|
|
7
7
|
/**
|
|
8
|
-
* @description:
|
|
8
|
+
* @description: Remove a class from an element
|
|
9
9
|
* @param {Element} element
|
|
10
10
|
* @param {string} removeClass
|
|
11
11
|
*/
|
|
12
12
|
export declare const removeClassToElement: (element: Element, removeClass: string) => void;
|
|
13
13
|
/**
|
|
14
|
-
* @description:
|
|
14
|
+
* @description: Create a DocumentFragment
|
|
15
15
|
* @param {Element} list
|
|
16
16
|
* @return {*}
|
|
17
17
|
*/
|
|
18
18
|
export declare const createDocumentFragment: (list: Element[]) => DocumentFragment | undefined;
|
|
19
19
|
export declare function escapeHtml(string?: string | number | null): string;
|
|
20
20
|
/**
|
|
21
|
-
* @description:
|
|
21
|
+
* @description: Set the root font size from the design mock's width
|
|
22
22
|
* @param {*} void
|
|
23
23
|
* @return {*}
|
|
24
24
|
*/
|
|
25
25
|
export declare const setFontSize2html: (designWidth?: number) => void;
|
|
26
|
-
|
|
27
|
-
* @description: 链式调用的 dom 操作
|
|
28
|
-
* (tag) (key value) (children)
|
|
29
|
-
* @return {HTMLElement}
|
|
30
|
-
*/
|
|
31
|
-
export declare class Chain {
|
|
32
|
-
listener: Map<string, Map<string, EventListener>>;
|
|
33
|
-
element: HTMLElement;
|
|
34
|
-
constructor(tagName: string, options?: ElementCreationOptions);
|
|
35
|
-
/**
|
|
36
|
-
* @description: 创建元素
|
|
37
|
-
* @param {string} tagName
|
|
38
|
-
* @param {ElementCreationOptions} options
|
|
39
|
-
* @return {Chain}
|
|
40
|
-
*/
|
|
41
|
-
create: (tagName: string, options?: ElementCreationOptions) => HTMLElement;
|
|
42
|
-
/**
|
|
43
|
-
* @description: 设置当前元素的属性
|
|
44
|
-
* @param {string} name
|
|
45
|
-
* @param {string} value
|
|
46
|
-
* @return {Chain}
|
|
47
|
-
*/
|
|
48
|
-
setAttribute: (name: string, value: string) => Chain;
|
|
49
|
-
/**
|
|
50
|
-
* @description: 移除当前元素的属性
|
|
51
|
-
* @param {string} name
|
|
52
|
-
* @return {Chain}
|
|
53
|
-
*/
|
|
54
|
-
removeAttribute: (name: string) => Chain;
|
|
55
|
-
/**
|
|
56
|
-
* @description: 当前元素添加子元素
|
|
57
|
-
* @param {HTMLElement} child
|
|
58
|
-
* @return {ChainElement}
|
|
59
|
-
*/
|
|
60
|
-
append: (child: HTMLElement) => Chain;
|
|
61
|
-
/**
|
|
62
|
-
* @description: 当前元素移除子元素
|
|
63
|
-
* @param {HTMLElement} child
|
|
64
|
-
* @return {Chain}
|
|
65
|
-
*/
|
|
66
|
-
remove: (child: HTMLElement) => Chain;
|
|
67
|
-
/**
|
|
68
|
-
* @description: 给当前元素设置文本内容
|
|
69
|
-
* @param {string} text
|
|
70
|
-
* @return {Chain}
|
|
71
|
-
*/
|
|
72
|
-
setTextContent: (text: string) => Chain;
|
|
73
|
-
/**
|
|
74
|
-
* @description: 给当前元素设置样式
|
|
75
|
-
* @param {string} name
|
|
76
|
-
* @param {string} value
|
|
77
|
-
* @return {Chain}
|
|
78
|
-
*/
|
|
79
|
-
setStyle: (name: string, value: string) => Chain;
|
|
80
|
-
private addElementByType;
|
|
81
|
-
/**
|
|
82
|
-
* @description: 给当前元素添加子元素
|
|
83
|
-
* @return {Chain}
|
|
84
|
-
*/
|
|
85
|
-
addChild: (child: Chain | Chain[] | HTMLElement | HTMLElement[]) => Chain;
|
|
86
|
-
/**
|
|
87
|
-
* @description: 给当前元素添加事件监听
|
|
88
|
-
* @param {string} type
|
|
89
|
-
* @param {EventListener} listener
|
|
90
|
-
* @return {Chain}
|
|
91
|
-
*/
|
|
92
|
-
listen: <K extends keyof HTMLElementEventMap>(type: K, listener: EventListener, options?: boolean | AddEventListenerOptions) => Chain;
|
|
93
|
-
/**
|
|
94
|
-
* @description: 移除当前元素的事件监听
|
|
95
|
-
* @param {string} type
|
|
96
|
-
* @return {Chain}
|
|
97
|
-
*/
|
|
98
|
-
clearListener: <K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions) => Chain;
|
|
99
|
-
/**
|
|
100
|
-
* @description: 移除当前元素的所有事件监听
|
|
101
|
-
* @return {Chain}
|
|
102
|
-
*/
|
|
103
|
-
clearAllListener: () => Chain;
|
|
104
|
-
}
|
|
105
|
-
export declare const create: (tagName: string, options?: ElementCreationOptions) => Chain;
|
|
26
|
+
export { Chain, create } from './chain';
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type ErrorPayload = Error | PromiseRejectionEvent | ErrorEvent;
|
|
2
|
+
/**
|
|
3
|
+
* @description: Listen for uncaught errors and unhandled promise rejections, in the capture
|
|
4
|
+
* phase so a handler further down cannot swallow them first.
|
|
5
|
+
*
|
|
6
|
+
* Returns an **unsubscribe function**. Without one these listeners live for the lifetime of
|
|
7
|
+
* the page: a hot reload adds a second pair, then a third, and every error is reported N times.
|
|
8
|
+
*
|
|
9
|
+
* @param {Function} hooks receives the error / rejection event
|
|
10
|
+
* @return {Function} unsubscribe
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const off = handleError((error) => report({ payload: { error: String(error) } }));
|
|
14
|
+
* // on teardown
|
|
15
|
+
* off();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare const handleError: (hooks?: (error: ErrorPayload) => void) => (() => void);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: EventManager — a scoped listener registry built on AbortController.
|
|
3
|
+
*
|
|
4
|
+
* The problem it solves is removing every listener you installed. A manual
|
|
5
|
+
* `removeEventListener` needs the **exact** same function reference and options used to
|
|
6
|
+
* register — wrap the handler in an arrow function anywhere along the way and it can never
|
|
7
|
+
* be removed, so a component that mounts and unmounts repeatedly leaks listeners.
|
|
8
|
+
* AbortController reduces all of that to a single `abort()`.
|
|
9
|
+
*
|
|
10
|
+
* In a Web Component:
|
|
11
|
+
*
|
|
12
|
+
* private _events = new EventManager();
|
|
13
|
+
*
|
|
14
|
+
* connectedCallback() {
|
|
15
|
+
* this._events
|
|
16
|
+
* .on(this._input, 'input', this.handleInput)
|
|
17
|
+
* .on(this, 'click', this.handleClick, { capture: true });
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* disconnectedCallback() {
|
|
21
|
+
* this._events.abort(); // remove every listener and reset for the next connect
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* In an ordinary page:
|
|
25
|
+
*
|
|
26
|
+
* function initSection(container: HTMLElement) {
|
|
27
|
+
* const scope = new EventManager();
|
|
28
|
+
*
|
|
29
|
+
* scope
|
|
30
|
+
* .on(input, 'input', handleSearch)
|
|
31
|
+
* .delegate(container, '[data-action]', 'click', (ev, target) => {
|
|
32
|
+
* handleAction(target.getAttribute('data-action'));
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* return () => scope.abort(); // call when the section is torn down
|
|
36
|
+
* }
|
|
37
|
+
*/
|
|
38
|
+
export declare class EventManager {
|
|
39
|
+
private ac;
|
|
40
|
+
constructor();
|
|
41
|
+
/** The underlying AbortSignal — pass it straight to addEventListener's options when needed. */
|
|
42
|
+
get signal(): AbortSignal;
|
|
43
|
+
on<K extends keyof HTMLElementEventMap>(target: HTMLElement, type: K, handler: (this: HTMLElement, ev: HTMLElementEventMap[K]) => unknown, options?: Omit<AddEventListenerOptions, 'signal'>): this;
|
|
44
|
+
on(target: EventTarget, type: string, handler: EventListener, options?: Omit<AddEventListenerOptions, 'signal'>): this;
|
|
45
|
+
/**
|
|
46
|
+
* @description: Event delegation — one listener on `parent`, invoking `handler` only when
|
|
47
|
+
* the event came from a descendant matching `selector`.
|
|
48
|
+
*
|
|
49
|
+
* The handler receives the original event and the matched element.
|
|
50
|
+
*
|
|
51
|
+
* scope.delegate(list, '.item', 'click', (ev, item) => {
|
|
52
|
+
* console.log(item.getAttribute('data-id'));
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
delegate<K extends keyof HTMLElementEventMap>(parent: HTMLElement, selector: string, type: K, handler: (ev: HTMLElementEventMap[K], target: Element) => void, options?: Omit<AddEventListenerOptions, 'signal'>): this;
|
|
56
|
+
/**
|
|
57
|
+
* @description: Remove every registered listener and reset the internal AbortController.
|
|
58
|
+
* Safe to call repeatedly; later on() / delegate() calls start from a clean scope.
|
|
59
|
+
*/
|
|
60
|
+
abort(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Promise wrappers around FileReader. The native FileReader exposes three callbacks —
|
|
3
|
+
* `onload` / `onerror` / `onabort` — and forgetting `onabort` leaves the promise pending
|
|
4
|
+
* forever when the user cancels; all three exits are wired up here.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* @description: Read a File / Blob as an ArrayBuffer
|
|
8
|
+
* @param {Blob} blob
|
|
9
|
+
* @return {Promise<ArrayBuffer>}
|
|
10
|
+
*/
|
|
11
|
+
export declare const readFileAsArrayBuffer: (blob: Blob) => Promise<ArrayBuffer>;
|
|
12
|
+
/**
|
|
13
|
+
* @description: Read a File / Blob as a Uint8Array (pair with checkEncoding / arrayBufferToString for encoding sniffing)
|
|
14
|
+
* @param {Blob} blob
|
|
15
|
+
* @return {Promise<Uint8Array>}
|
|
16
|
+
*/
|
|
17
|
+
export declare const readFileAsUint8Array: (blob: Blob) => Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* @description: Read a File / Blob as text
|
|
20
|
+
* @param {Blob} blob
|
|
21
|
+
* @param {string} encoding charset, defaults to utf-8; sniff with checkEncoding first when the encoding is unknown
|
|
22
|
+
* @return {Promise<string>}
|
|
23
|
+
*/
|
|
24
|
+
export declare const readFileAsText: (blob: Blob, encoding?: string) => Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* @description: Read a File / Blob as a data: URL (image previews and the like)
|
|
27
|
+
* @param {Blob} blob
|
|
28
|
+
* @return {Promise<string>}
|
|
29
|
+
*/
|
|
30
|
+
export declare const readFileAsDataURL: (blob: Blob) => Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as r,r as s,t as a}from"../../../i18n-Cf5TtRb4.js";export{a as I18nCore,r as createI18n,s as useI18n};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export type MessageDict = Record<string, string>;
|
|
2
|
+
export type LocaleMessages = Record<string, MessageDict>;
|
|
3
|
+
export type TranslateParams = Record<string, string | number>;
|
|
4
|
+
export type LocaleChangeHandler = (locale: string) => void;
|
|
5
|
+
export interface I18nConfig {
|
|
6
|
+
/** Initial locale. Overridden by a persisted choice when `persist` is on. */
|
|
7
|
+
locale?: string;
|
|
8
|
+
/** Locale used when a key is missing in the active locale. Defaults to 'en'. */
|
|
9
|
+
fallbackLocale?: string;
|
|
10
|
+
/** Locale → key → string. */
|
|
11
|
+
messages?: LocaleMessages;
|
|
12
|
+
/** Persist the active locale to localStorage. Defaults to false. */
|
|
13
|
+
persist?: boolean;
|
|
14
|
+
/** localStorage key used when `persist` is on. Defaults to 'ran-locale'. */
|
|
15
|
+
storageKey?: string;
|
|
16
|
+
/** Seed the initial locale from the browser's language preferences when nothing else applies. */
|
|
17
|
+
detectNavigator?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare class I18nCore {
|
|
20
|
+
private _locale;
|
|
21
|
+
private _fallback;
|
|
22
|
+
private _messages;
|
|
23
|
+
private _persist;
|
|
24
|
+
private _storageKey;
|
|
25
|
+
private _handlers;
|
|
26
|
+
constructor(config?: I18nConfig);
|
|
27
|
+
private _resolveInitialLocale;
|
|
28
|
+
/** The active locale. */
|
|
29
|
+
get locale(): string;
|
|
30
|
+
getLocale(): string;
|
|
31
|
+
/** Switch locale; persists (when enabled) and notifies subscribers. No-op if unchanged. */
|
|
32
|
+
setLocale(locale: string): void;
|
|
33
|
+
/** Merge a dictionary into a locale (creating it if needed). */
|
|
34
|
+
addMessages(locale: string, dict: MessageDict): void;
|
|
35
|
+
getMessages(locale?: string): MessageDict;
|
|
36
|
+
/** Locales that have a dictionary registered. */
|
|
37
|
+
get availableLocales(): string[];
|
|
38
|
+
/**
|
|
39
|
+
* Translate a key against the active locale, falling back to the fallback
|
|
40
|
+
* locale and finally the key itself. `{param}` placeholders are interpolated;
|
|
41
|
+
* `{{` / `}}` are escapes for literal `{` / `}` (see {@link I18nCore._interpolate}).
|
|
42
|
+
*/
|
|
43
|
+
t(key: string, params?: TranslateParams): string;
|
|
44
|
+
/**
|
|
45
|
+
* Substitute `{param}` placeholders and unescape literal braces.
|
|
46
|
+
*
|
|
47
|
+
* Grammar (a single left-to-right pass, so escapes and placeholders never
|
|
48
|
+
* fight each other), matching the format-string convention used by Rust
|
|
49
|
+
* `format!`, Python `str.format`, and .NET `String.Format`:
|
|
50
|
+
* - `{{` → literal `{`
|
|
51
|
+
* - `}}` → literal `}`
|
|
52
|
+
* - `{name}` → `params.name` (stringified), or left untouched when the param
|
|
53
|
+
* is absent, so a stray placeholder is visible rather than silently blank.
|
|
54
|
+
*
|
|
55
|
+
* A lone `{`/`}` or a `{ spaced }` group is not a placeholder and is emitted
|
|
56
|
+
* verbatim, so CSS/JSON/code fragments in a message pass through unharmed.
|
|
57
|
+
* To wrap a value in literal braces, double the outer pair: `{{{name}}}`.
|
|
58
|
+
*/
|
|
59
|
+
private _interpolate;
|
|
60
|
+
/** Subscribe to locale changes. Returns an unsubscribe function. */
|
|
61
|
+
onChange(handler: LocaleChangeHandler): () => void;
|
|
62
|
+
private _notify;
|
|
63
|
+
/** Remove all subscribers. */
|
|
64
|
+
destroy(): void;
|
|
65
|
+
}
|
|
66
|
+
/** Create and register the global i18n singleton. */
|
|
67
|
+
export declare function createI18n(config?: I18nConfig): I18nCore;
|
|
68
|
+
/** Return the active global i18n instance, or null if none was created. */
|
|
69
|
+
export declare function useI18n(): I18nCore | null;
|