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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate maths and range splitting over a "chunk sequence + global offset" model
|
|
3
|
+
* (pure functions, no DOM, easy to test).
|
|
4
|
+
*
|
|
5
|
+
* The use case: content is cut into chunks (pagination, sharding, a virtual list, log
|
|
6
|
+
* segments) while annotations / highlights / search hits are recorded as **offsets into
|
|
7
|
+
* the concatenated whole**. Storing an annotation in global coordinates rather than as
|
|
8
|
+
* "chunk N, character M" keeps it valid after re-chunking (a different font size, page
|
|
9
|
+
* width or shard size).
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* @description: The global start offset of every chunk in the concatenated coordinate
|
|
13
|
+
* space (a prefix sum). `offsets[i]` = the summed length of the first `i` chunks.
|
|
14
|
+
* @param {readonly number[]} lengths length of each chunk
|
|
15
|
+
* @return {number[]} offset array, same length as the input
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* buildOffsets([3, 5, 2]); // [0, 3, 8]
|
|
19
|
+
* buildOffsets(pages.map((p) => p.text.length));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const buildOffsets: (lengths: readonly number[]) => number[];
|
|
23
|
+
/**
|
|
24
|
+
* @description: Binary-search which chunk a global offset falls into — the last index
|
|
25
|
+
* satisfying `offsets[i] <= offset`. Out-of-range values are clamped to
|
|
26
|
+
* `[0, offsets.length - 1]` and an empty array returns 0, so the result is always safe to
|
|
27
|
+
* index with.
|
|
28
|
+
* @param {readonly number[]} offsets the result of buildOffsets (must be non-decreasing)
|
|
29
|
+
* @param {number} offset global offset
|
|
30
|
+
* @return {number} chunk index
|
|
31
|
+
*/
|
|
32
|
+
export declare const indexForOffset: (offsets: readonly number[], offset: number) => number;
|
|
33
|
+
/** An annotation in global coordinates: the half-open interval `[start, end)` plus any payload */
|
|
34
|
+
export interface OffsetRange<T> {
|
|
35
|
+
start: number;
|
|
36
|
+
end: number;
|
|
37
|
+
value: T;
|
|
38
|
+
}
|
|
39
|
+
/** One piece of the split result: `value === null` marks a plain span covered by no range */
|
|
40
|
+
export interface Segment<T> {
|
|
41
|
+
text: string;
|
|
42
|
+
/** Start in global coordinates (= chunkStart + the offset inside the chunk) */
|
|
43
|
+
start: number;
|
|
44
|
+
end: number;
|
|
45
|
+
value: T | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @description: Split one chunk of text into a sequence of plain / matched spans according
|
|
49
|
+
* to the ranges falling inside it, ready for span-by-span rendering (highlights,
|
|
50
|
+
* underlines, search hits, diff colouring).
|
|
51
|
+
*
|
|
52
|
+
* Ranges are sorted by start and consumed monotonically: on overlap the later range only
|
|
53
|
+
* takes its non-overlapping tail, and a fully swallowed range is skipped — so cut points
|
|
54
|
+
* strictly increase and no negative-length or duplicated text is produced. Ranges are not
|
|
55
|
+
* merged (personal annotations rarely overlap).
|
|
56
|
+
*
|
|
57
|
+
* @param {string} text this chunk's text
|
|
58
|
+
* @param {number} chunkStart this chunk's start offset in global coordinates (from buildOffsets)
|
|
59
|
+
* @param {readonly OffsetRange<T>[]} ranges ranges in global coordinates, may include unrelated items
|
|
60
|
+
* @return {Segment<T>[]} spans that concatenate back to `text`; always at least one
|
|
61
|
+
*/
|
|
62
|
+
export declare const segmentByRanges: <T>(text: string, chunkStart: number, ranges: readonly OffsetRange<T>[]) => Segment<T>[];
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import { SyncHook } from './subscribe';
|
|
2
|
+
/** Global event bus: a signal carrying a `subscriber` broadcasts through it on change */
|
|
2
3
|
export declare const subscribers: SyncHook;
|
|
3
|
-
export
|
|
4
|
+
export interface SignalOptions<T> {
|
|
5
|
+
/** Event name; only when given does a change broadcast through `subscribers` for cross-module listeners */
|
|
4
6
|
subscriber?: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Equality check, deciding whether a write counts as a change:
|
|
9
|
+
* - omitted / `true` — use `Object.is` (reference/value equality), the standard signal semantics
|
|
10
|
+
* - `false` — always a change, notify on every write
|
|
11
|
+
* - function — returning true means equal, so the notification is skipped. Pass `isEqual` for a deep comparison
|
|
12
|
+
*/
|
|
13
|
+
equals?: boolean | ((prev: T, next: T) => boolean);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @description: Create a minimal signal with optional event broadcasting, returned as
|
|
17
|
+
* `[read, write]`.
|
|
18
|
+
*
|
|
19
|
+
* Equality defaults to `Object.is` — **no deep comparison**. The old implementation
|
|
20
|
+
* `cloneDeep`-ed a snapshot on every write and compared it with `isEqual`: that put an
|
|
21
|
+
* O(data size) copy on the hot write path, and the deep comparison overrode the `equals`
|
|
22
|
+
* option, breaking `equals: false` ("always notify"). Pass `{ equals: isEqual }` explicitly
|
|
23
|
+
* when a deep comparison is wanted, so its cost is visible at the call site.
|
|
24
|
+
*
|
|
25
|
+
* @param {T} value initial value
|
|
26
|
+
* @param {SignalOptions} options
|
|
27
|
+
* @return {[() => T, (next: T) => void]}
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const [count, setCount] = createSignal(0, { subscriber: 'count-changed' });
|
|
31
|
+
* subscribers.tap('count-changed', () => render(count()));
|
|
32
|
+
* setCount(1); // notifies
|
|
33
|
+
* setCount(1); // same value, no notification
|
|
34
|
+
*
|
|
35
|
+
* const [tree, setTree] = createSignal(initial, { equals: isEqual }); // opt in to deep comparison
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare const createSignal: <T = unknown>(value: T, options?: SignalOptions<T>) => [() => T, (newValue: T) => void];
|
|
@@ -1,2 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* localStorage access that cannot throw.
|
|
3
|
+
*
|
|
4
|
+
* `localStorage` is not merely absent under SSR — it also throws on *access* in a
|
|
5
|
+
* third-party iframe with cookies blocked, and on *write* in Safari private mode or at
|
|
6
|
+
* quota. Every read and write here is guarded, because a storage failure should degrade a
|
|
7
|
+
* preference, never break the page.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @description: Write a string to localStorage. Silently does nothing when storage is
|
|
11
|
+
* unavailable or the write fails (quota, private mode).
|
|
12
|
+
* @param {string} name
|
|
13
|
+
* @param {string} value
|
|
14
|
+
* @return {void}
|
|
15
|
+
*/
|
|
1
16
|
export declare const localStorageSetItem: (name: string, value: string) => void;
|
|
17
|
+
/**
|
|
18
|
+
* @description: Read a string from localStorage, or `''` when missing or unavailable.
|
|
19
|
+
* @param {string} name
|
|
20
|
+
* @return {string}
|
|
21
|
+
*/
|
|
2
22
|
export declare const localStorageGetItem: (name: string) => string;
|
|
23
|
+
/**
|
|
24
|
+
* @description: Remove a key from localStorage. Silently does nothing when storage is unavailable.
|
|
25
|
+
* @param {string} name
|
|
26
|
+
* @return {void}
|
|
27
|
+
*/
|
|
28
|
+
export declare const localStorageRemoveItem: (name: string) => void;
|
|
29
|
+
export interface JsonStore<T> {
|
|
30
|
+
/** Stored value, or `fallback` when missing, unavailable, or not valid JSON. */
|
|
31
|
+
get: (key: string, fallback: T) => T;
|
|
32
|
+
/** Serialise and store. Returns false when nothing was written. */
|
|
33
|
+
set: (key: string, value: T) => boolean;
|
|
34
|
+
remove: (key: string) => void;
|
|
35
|
+
/** Full storage key for `key`, i.e. `prefix + key` — useful when listening for `storage` events. */
|
|
36
|
+
keyOf: (key: string) => string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description: A prefixed, JSON-serialising view over localStorage.
|
|
40
|
+
*
|
|
41
|
+
* The prefix is what lets several features share one origin's storage without collisions
|
|
42
|
+
* (`agent_history_`, `agent_api_key_`, …), and reading through `get` means a value written
|
|
43
|
+
* by an older version of the code — or by anything else on the origin — cannot throw a
|
|
44
|
+
* `SyntaxError` into the caller: invalid JSON yields the fallback.
|
|
45
|
+
*
|
|
46
|
+
* `get` **validates nothing**. Whatever was stored comes back typed as `T`; check it
|
|
47
|
+
* yourself if it crosses a version boundary. The fallback only covers absence and parse
|
|
48
|
+
* failure.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} prefix namespace prepended to every key
|
|
51
|
+
* @return {JsonStore<T>}
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const history = createStore<Message[]>('agent_history_');
|
|
55
|
+
* history.set('default', messages);
|
|
56
|
+
* const restored = history.get('default', []); // [] when absent or corrupt
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare const createStore: <T>(prefix?: string) => JsonStore<T>;
|
package/dist/src/utils/str.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description:
|
|
2
|
+
* @description: Parse a delimited string into an object, e.g.
|
|
3
3
|
* @param {string} url 'a=1&b=2&c=3'
|
|
4
4
|
* @param {string} sep &
|
|
5
5
|
* @param {string} eq =
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare const strParse: (str?: string, sep?: string | RegExp, eq?: string | RegExp) => Record<string, string>;
|
|
9
9
|
/**
|
|
10
|
-
* @description:
|
|
11
|
-
* @param {string} str
|
|
12
|
-
* @return {string}
|
|
10
|
+
* @description: Strip whitespace, line breaks and HTML tags out of a string
|
|
11
|
+
* @param {string} str string to clean
|
|
12
|
+
* @return {string} the resulting plain text
|
|
13
13
|
*/
|
|
14
14
|
export declare const clearBr: (str?: string) => string;
|
|
15
15
|
/**
|
|
16
|
-
* @description:
|
|
16
|
+
* @description: Parse a string into XML using the given MIME type
|
|
17
17
|
* @param {string} xmlStr
|
|
18
18
|
* @param {DOMParserSupportedType} format
|
|
19
19
|
* @return {Document}
|
|
@@ -26,20 +26,44 @@ interface ClearStrOption {
|
|
|
26
26
|
urlencoded?: boolean;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* @description:
|
|
29
|
+
* @description: Trim surrounding whitespace, percent-decode, and drop surrounding quotes
|
|
30
30
|
* @param {string} str
|
|
31
31
|
* @return {string}
|
|
32
32
|
*/
|
|
33
33
|
export declare const clearStr: (str: string, options?: ClearStrOption) => string;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @param
|
|
38
|
-
* @
|
|
35
|
+
* Collect the complete sentences of a text that contain the search term, keeping only the
|
|
36
|
+
* longest one among overlapping matches
|
|
37
|
+
* @param text source text
|
|
38
|
+
* @param searchValue search term
|
|
39
|
+
* @returns the complete sentences containing the term (de-duplicated)
|
|
39
40
|
*/
|
|
40
41
|
export declare function getMatchingSentences(text: string, searchValue: string): string[];
|
|
41
42
|
export declare const toString: (value: string | number) => string;
|
|
42
43
|
export declare const checkEncoding: (uint8Array: Uint8Array) => string;
|
|
44
|
+
/**
|
|
45
|
+
* @description: Decode bytes into a string using the sniffed encoding. Required when reading
|
|
46
|
+
* text files of unknown provenance (a user-uploaded txt, content scraped off an old site) —
|
|
47
|
+
* a plain `new TextDecoder().decode()` turns GBK/Big5 into mojibake, and such files are a
|
|
48
|
+
* sizeable share of Chinese-language content.
|
|
49
|
+
* @param {ArrayBuffer | Uint8Array} buffer
|
|
50
|
+
* @return {string}
|
|
51
|
+
*/
|
|
52
|
+
export declare const arrayBufferToString: (buffer: ArrayBuffer | Uint8Array) => string;
|
|
53
|
+
/**
|
|
54
|
+
* @description: Convert full-width characters to half-width (digits, letters, punctuation and
|
|
55
|
+
* the ideographic space). Full-width digits produced by a Chinese IME are not equivalent to
|
|
56
|
+
* half-width ones in regexes, `parseInt` or string comparison, so normalise before parsing.
|
|
57
|
+
* @param {string} value
|
|
58
|
+
* @return {string}
|
|
59
|
+
*/
|
|
60
|
+
export declare const toHalfWidth: (value: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* @description: Convert half-width characters to full-width (the inverse of `toHalfWidth`)
|
|
63
|
+
* @param {string} value
|
|
64
|
+
* @return {string}
|
|
65
|
+
*/
|
|
66
|
+
export declare const toFullWidth: (value: string) => string;
|
|
43
67
|
export interface TransformText {
|
|
44
68
|
encoding: string;
|
|
45
69
|
content: string;
|
|
@@ -62,150 +86,150 @@ type FileChunk = {
|
|
|
62
86
|
data: string;
|
|
63
87
|
};
|
|
64
88
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
89
|
+
* Message codec.
|
|
90
|
+
* Handles every Unicode character correctly, CJK and emoji included.
|
|
91
|
+
* The encoded string only contains the safe characters A-Z, a-z, 0-9, +, / and =,
|
|
92
|
+
* so it is usable in URLs, cookies and similar places.
|
|
93
|
+
* Encoding and decoding are exact inverses: no data is lost and the two never disagree.
|
|
70
94
|
*/
|
|
71
95
|
export declare const MessageCodec: {
|
|
72
96
|
/**
|
|
73
|
-
*
|
|
74
|
-
* @param data
|
|
75
|
-
* @returns
|
|
97
|
+
* Encode a message
|
|
98
|
+
* @param data data to encode
|
|
99
|
+
* @returns the encoded string
|
|
76
100
|
*/
|
|
77
101
|
encode(data: any): string;
|
|
78
102
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param encodedStr
|
|
81
|
-
* @returns
|
|
103
|
+
* Decode a message
|
|
104
|
+
* @param encodedStr the encoded string
|
|
105
|
+
* @returns the decoded data
|
|
82
106
|
*/
|
|
83
107
|
decode<T = any>(encodedStr: string): T | null;
|
|
84
108
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @param file File
|
|
87
|
-
* @returns
|
|
88
|
-
* @throws {MessageCodecError}
|
|
109
|
+
* Encode a File
|
|
110
|
+
* @param file the File
|
|
111
|
+
* @returns the encoded string
|
|
112
|
+
* @throws {MessageCodecError} when encoding the file fails
|
|
89
113
|
*/
|
|
90
114
|
encodeFile(file: File): Promise<string>;
|
|
91
115
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param encoded
|
|
94
|
-
* @returns
|
|
95
|
-
* @throws {MessageCodecError}
|
|
116
|
+
* Decode a File
|
|
117
|
+
* @param encoded the encoded string
|
|
118
|
+
* @returns the decoded File
|
|
119
|
+
* @throws {MessageCodecError} when decoding fails or the type does not match
|
|
96
120
|
*/
|
|
97
121
|
decodeFile(encoded: string): File;
|
|
98
122
|
/**
|
|
99
|
-
*
|
|
100
|
-
* @param blob Blob
|
|
101
|
-
* @returns
|
|
102
|
-
* @throws {MessageCodecError}
|
|
123
|
+
* Encode a Blob
|
|
124
|
+
* @param blob the Blob
|
|
125
|
+
* @returns the encoded string
|
|
126
|
+
* @throws {MessageCodecError} when encoding fails
|
|
103
127
|
*/
|
|
104
128
|
encodeBlob(blob: Blob): Promise<string>;
|
|
105
129
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @param encoded
|
|
108
|
-
* @returns
|
|
109
|
-
* @throws {MessageCodecError}
|
|
130
|
+
* Decode a Blob
|
|
131
|
+
* @param encoded the encoded string
|
|
132
|
+
* @returns the decoded Blob
|
|
133
|
+
* @throws {MessageCodecError} when decoding fails or the type does not match
|
|
110
134
|
*/
|
|
111
135
|
decodeBlob(encoded: string): Blob;
|
|
112
136
|
/**
|
|
113
|
-
*
|
|
114
|
-
* @param date Date
|
|
115
|
-
* @returns
|
|
137
|
+
* Encode a Date
|
|
138
|
+
* @param date the Date
|
|
139
|
+
* @returns the encoded string
|
|
116
140
|
*/
|
|
117
141
|
encodeDate(date: Date): string;
|
|
118
142
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @param encodedStr
|
|
121
|
-
* @returns
|
|
143
|
+
* Decode a Date
|
|
144
|
+
* @param encodedStr the encoded string
|
|
145
|
+
* @returns the decoded Date
|
|
122
146
|
*/
|
|
123
147
|
decodeDate(encodedStr: string): Date;
|
|
124
148
|
/**
|
|
125
|
-
*
|
|
126
|
-
* @param regexp RegExp
|
|
127
|
-
* @returns
|
|
149
|
+
* Encode a RegExp
|
|
150
|
+
* @param regexp the RegExp
|
|
151
|
+
* @returns the encoded string
|
|
128
152
|
*/
|
|
129
153
|
encodeRegExp(regexp: RegExp): string;
|
|
130
154
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @param encodedStr
|
|
133
|
-
* @returns
|
|
155
|
+
* Decode a RegExp
|
|
156
|
+
* @param encodedStr the encoded string
|
|
157
|
+
* @returns the decoded RegExp
|
|
134
158
|
*/
|
|
135
159
|
decodeRegExp(encodedStr: string): RegExp;
|
|
136
160
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param map Map
|
|
139
|
-
* @returns
|
|
161
|
+
* Encode a Map
|
|
162
|
+
* @param map the Map
|
|
163
|
+
* @returns the encoded string
|
|
140
164
|
*/
|
|
141
165
|
encodeMap<K, V>(map: Map<K, V>): string;
|
|
142
166
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param encodedStr
|
|
145
|
-
* @returns
|
|
167
|
+
* Decode a Map
|
|
168
|
+
* @param encodedStr the encoded string
|
|
169
|
+
* @returns the decoded Map
|
|
146
170
|
*/
|
|
147
171
|
decodeMap<K, V>(encodedStr: string): Map<K, V>;
|
|
148
172
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param set Set
|
|
151
|
-
* @returns
|
|
173
|
+
* Encode a Set
|
|
174
|
+
* @param set the Set
|
|
175
|
+
* @returns the encoded string
|
|
152
176
|
*/
|
|
153
177
|
encodeSet<T>(set: Set<T>): string;
|
|
154
178
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param encodedStr
|
|
157
|
-
* @returns
|
|
179
|
+
* Decode a Set
|
|
180
|
+
* @param encodedStr the encoded string
|
|
181
|
+
* @returns the decoded Set
|
|
158
182
|
*/
|
|
159
183
|
decodeSet<T>(encodedStr: string): Set<T>;
|
|
160
184
|
/**
|
|
161
|
-
*
|
|
162
|
-
* @param error Error
|
|
163
|
-
* @returns
|
|
185
|
+
* Encode an Error
|
|
186
|
+
* @param error the Error
|
|
187
|
+
* @returns the encoded string
|
|
164
188
|
*/
|
|
165
189
|
encodeError(error: Error): string;
|
|
166
190
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param encodedStr
|
|
169
|
-
* @returns
|
|
191
|
+
* Decode an Error
|
|
192
|
+
* @param encodedStr the encoded string
|
|
193
|
+
* @returns the decoded Error
|
|
170
194
|
*/
|
|
171
195
|
decodeError(encodedStr: string): Error;
|
|
172
196
|
/**
|
|
173
|
-
*
|
|
174
|
-
* @param buffer ArrayBuffer
|
|
175
|
-
* @returns
|
|
197
|
+
* Encode an ArrayBuffer
|
|
198
|
+
* @param buffer the ArrayBuffer
|
|
199
|
+
* @returns the encoded string
|
|
176
200
|
*/
|
|
177
201
|
encodeArrayBuffer(buffer: ArrayBuffer): string;
|
|
178
202
|
/**
|
|
179
|
-
*
|
|
180
|
-
* @param encodedStr
|
|
181
|
-
* @returns
|
|
203
|
+
* Decode an ArrayBuffer
|
|
204
|
+
* @param encodedStr the encoded string
|
|
205
|
+
* @returns the decoded ArrayBuffer
|
|
182
206
|
*/
|
|
183
207
|
decodeArrayBuffer(encodedStr: string): ArrayBuffer;
|
|
184
208
|
/**
|
|
185
|
-
*
|
|
186
|
-
* @param typedArray TypedArray
|
|
187
|
-
* @returns
|
|
209
|
+
* Encode a TypedArray
|
|
210
|
+
* @param typedArray the TypedArray
|
|
211
|
+
* @returns the encoded string
|
|
188
212
|
*/
|
|
189
213
|
encodeTypedArray(typedArray: ArrayBufferView): string;
|
|
190
214
|
/**
|
|
191
|
-
*
|
|
192
|
-
* @param encodedStr
|
|
193
|
-
* @returns
|
|
215
|
+
* Decode a TypedArray
|
|
216
|
+
* @param encodedStr the encoded string
|
|
217
|
+
* @returns the decoded TypedArray
|
|
194
218
|
*/
|
|
195
219
|
decodeTypedArray(encodedStr: string): ArrayBufferView;
|
|
196
220
|
/**
|
|
197
|
-
*
|
|
198
|
-
* @param file File
|
|
199
|
-
* @param chunkSize
|
|
200
|
-
* @returns
|
|
201
|
-
* @throws {MessageCodecError}
|
|
221
|
+
* Encode a File as chunks
|
|
222
|
+
* @param file the File
|
|
223
|
+
* @param chunkSize chunk size, defaults to 1MB
|
|
224
|
+
* @returns transferable objects carrying the file metadata and the chunk data
|
|
225
|
+
* @throws {MessageCodecError} when chunked encoding fails
|
|
202
226
|
*/
|
|
203
227
|
encodeFileChunked(file: File, chunkSize?: number): Promise<FileChunk[]>;
|
|
204
228
|
/**
|
|
205
|
-
*
|
|
206
|
-
* @param chunks
|
|
207
|
-
* @returns
|
|
208
|
-
* @throws {MessageCodecError}
|
|
229
|
+
* Decode a chunked File
|
|
230
|
+
* @param chunks the encoded file chunks
|
|
231
|
+
* @returns the reconstructed File
|
|
232
|
+
* @throws {MessageCodecError} when decoding fails or the chunks are incomplete
|
|
209
233
|
*/
|
|
210
234
|
decodeFileChunked(chunks: FileChunk[]): Promise<File>;
|
|
211
235
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** Default marker attribute on the <style> fallback, identifying styles this module injected */
|
|
2
|
+
export declare const ADOPTED_STYLE_MARKER = "data-adopted-style";
|
|
3
|
+
export declare const ADOPTED_SHEET_MARKER = "data-adopted-sheet";
|
|
4
|
+
/**
|
|
5
|
+
* @description: Inject a component's static styles into a shadow root.
|
|
6
|
+
*
|
|
7
|
+
* - SSR-safe: skipped outright when there is no `document`
|
|
8
|
+
* - Idempotent: one shadowRoot is never injected into twice
|
|
9
|
+
* - The fallback de-duplicates per **root**: a shadowRoot keeps exactly one marked <style>,
|
|
10
|
+
* first writer wins. A component's static styles should exist once per root, so a second
|
|
11
|
+
* call means the caller made a mistake.
|
|
12
|
+
*
|
|
13
|
+
* @param {ShadowRoot} shadowRoot target shadow root
|
|
14
|
+
* @param {string} cssText the style text
|
|
15
|
+
* @param {string} marker marker attribute on the fallback <style>, defaults to `data-adopted-style`
|
|
16
|
+
* @return {void}
|
|
17
|
+
*/
|
|
18
|
+
export declare const adoptStyles: (shadowRoot: ShadowRoot, cssText: string, marker?: string) => void;
|
|
19
|
+
/**
|
|
20
|
+
* @description: Inject dynamic styles supplied at runtime (a component's `sheet` property, say).
|
|
21
|
+
*
|
|
22
|
+
* The only difference from `adoptStyles` is what the fallback de-duplicates on: here it is
|
|
23
|
+
* the **cssText**, so one root can stack several distinct dynamic stylesheets while an
|
|
24
|
+
* identical one is injected only once.
|
|
25
|
+
*
|
|
26
|
+
* @param {ShadowRoot} shadowRoot target shadow root
|
|
27
|
+
* @param {string} cssText the style text
|
|
28
|
+
* @param {string} marker marker attribute on the fallback <style>, defaults to `data-adopted-sheet`
|
|
29
|
+
* @return {void}
|
|
30
|
+
*/
|
|
31
|
+
export declare const adoptSheetText: (shadowRoot: ShadowRoot, cssText: string, marker?: string) => void;
|
|
@@ -9,35 +9,35 @@ export declare const NEW_LISTENER = "NEW_LISTENER";
|
|
|
9
9
|
export declare class SyncHook {
|
|
10
10
|
readonly _events: Map<EventName, Set<EventItem>>;
|
|
11
11
|
/**
|
|
12
|
-
* @description:
|
|
12
|
+
* @description: Subscribe to an event
|
|
13
13
|
* @param {EventName} eventName
|
|
14
14
|
* @param {EventItem} eventItem
|
|
15
15
|
* @return {void}
|
|
16
16
|
*/
|
|
17
17
|
tap: (eventName: EventName, eventItem: EventItem | Callback) => this;
|
|
18
18
|
/**
|
|
19
|
-
* @description:
|
|
19
|
+
* @description: Emit an event
|
|
20
20
|
* @param {EventName} eventName
|
|
21
21
|
* @param {array} args
|
|
22
22
|
* @return {void}
|
|
23
23
|
*/
|
|
24
24
|
call: (eventName: EventName, ...args: Array<unknown>) => this;
|
|
25
25
|
/**
|
|
26
|
-
* @description:
|
|
26
|
+
* @description: Emit an event, awaiting each listener in turn
|
|
27
27
|
* @param {EventName} eventName
|
|
28
28
|
* @param {array} args
|
|
29
29
|
* @return {Promise<void>}
|
|
30
30
|
*/
|
|
31
31
|
callSync: (eventName: EventName, ...args: Array<unknown>) => Promise<this>;
|
|
32
32
|
/**
|
|
33
|
-
* @description:
|
|
33
|
+
* @description: Subscribe once — the listener is removed after it fires
|
|
34
34
|
* @param {EventName} eventName
|
|
35
35
|
* @param {EventItem} eventItem
|
|
36
36
|
* @return {void}
|
|
37
37
|
*/
|
|
38
38
|
once: (eventName: EventName, eventItem: EventItem | Callback) => this;
|
|
39
39
|
/**
|
|
40
|
-
* @description:
|
|
40
|
+
* @description: Remove a subscription
|
|
41
41
|
* @param {EventName} eventName
|
|
42
42
|
* @param {EventItem} eventItem
|
|
43
43
|
* @return {void}
|
|
@@ -1,15 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
export interface Throttled<T extends (...args: any[]) => any> {
|
|
2
|
+
(this: unknown, ...args: Parameters<T>): void;
|
|
3
|
+
/** Cancel the pending trailing invocation, if any. */
|
|
4
|
+
cancel: () => void;
|
|
5
|
+
/** Whether a trailing invocation is waiting to fire. */
|
|
6
|
+
pending: () => boolean;
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
|
-
* @description:
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
9
|
+
* @description: Throttle — under a burst of calls, run at a fixed interval: the first call
|
|
10
|
+
* runs immediately (leading) and the last call inside a window is replayed when the window
|
|
11
|
+
* closes (trailing), so the final state is never dropped. For scroll, mouse move and drag —
|
|
12
|
+
* anything needing **continuous feedback** (the opposite of `debounce`, which only wants the
|
|
13
|
+
* final value while throttle wants the intermediate ones).
|
|
14
|
+
*
|
|
15
|
+
* Preserves the caller's `this` and arguments. Uses the bare `setTimeout` rather than
|
|
16
|
+
* `window.setTimeout` — the latter throws a ReferenceError in Node / Workers / SSR.
|
|
17
|
+
*
|
|
18
|
+
* @param {Function} fn function to throttle
|
|
19
|
+
* @param {number} delay minimum interval in milliseconds, defaults to 300
|
|
20
|
+
* @return {Throttled} wrapped function with cancel / pending
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const onScroll = throttle(() => update(window.scrollY), 100);
|
|
24
|
+
* window.addEventListener('scroll', onScroll);
|
|
25
|
+
* onUnmount(() => { window.removeEventListener('scroll', onScroll); onScroll.cancel(); });
|
|
26
|
+
* ```
|
|
7
27
|
*/
|
|
8
|
-
export declare function throttle<T extends (...args: any[]) => any>(
|
|
9
|
-
/**
|
|
10
|
-
* @description: 生成节流函数
|
|
11
|
-
* @param {*} Function
|
|
12
|
-
* @return {*}
|
|
13
|
-
*/
|
|
14
|
-
export declare const generateThrottle: () => Function;
|
|
15
|
-
export {};
|
|
28
|
+
export declare function throttle<T extends (...args: any[]) => any>(fn: T, delay?: number): Throttled<T>;
|
package/dist/src/utils/time.d.ts
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* @description: Format a date with a token pattern. Accepts a timestamp, a date string, a
|
|
3
|
+
* `Date`, or nothing (meaning now). Wrap literal text in `[]` to keep it out of the substitution.
|
|
4
|
+
*
|
|
5
|
+
* | Token | Meaning | Token | Meaning |
|
|
6
|
+
* | ----- | -------------------- | ----- | ----------------------- |
|
|
7
|
+
* | `YYYY`/`YY` | Year | `mm`/`m` | Minute |
|
|
8
|
+
* | `MM`/`M` | Month (1-12) | `ss`/`s` | Second |
|
|
9
|
+
* | `DD`/`D` | Day | `SSS` | Milliseconds |
|
|
10
|
+
* | `HH`/`H` | Hour (0-23) | `A`/`a` | AM/PM · am/pm |
|
|
11
|
+
* | `hh`/`h` | Hour (1-12) | `[...]` | Literal text |
|
|
12
|
+
*
|
|
13
|
+
* The whole pattern is replaced in a **single pass**. The old implementation chained six
|
|
14
|
+
* `.replace()` calls with case-insensitive flags, which produced wrong output in two ways:
|
|
15
|
+
* a later pattern could match digits an earlier one had just written, and `/M+/g` vs
|
|
16
|
+
* `/m+/g` vs `/D+/gi` overlapped, so a lowercase pattern like `yyyy-mm-dd` came out as
|
|
17
|
+
* year-minute-day.
|
|
18
|
+
*
|
|
19
|
+
* @param {number | string | Date} value date to format; omit for the current time
|
|
20
|
+
* @param {string} pattern token pattern, default `'YYYY-MM-DD HH:mm:ss'`
|
|
21
|
+
* @return {string} formatted string, or `'Invalid Date'` when the input cannot be parsed
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* formatDate(); // '2026-07-25 14:30:00'
|
|
25
|
+
* formatDate(1753425000000, 'YYYY/MM/DD'); // '2026/07/25'
|
|
26
|
+
* formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026年07月25日 02:30 pm' (escaped literals)
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const formatDate: (value?: number | string | Date, pattern?: string) => string;
|
|
30
|
+
/**
|
|
31
|
+
* @description: Turn a timestamp into a `Date` carrying a `format` method.
|
|
32
|
+
* @deprecated Use [`formatDate`](#formatdate). This returns a `Date` with an extra method
|
|
33
|
+
* bolted onto the instance, which does not survive serialization, breaks `instanceof`-based
|
|
34
|
+
* type narrowing on the extra property, and is untypeable beyond `Function`. Its `format`
|
|
35
|
+
* now delegates to `formatDate`, so the token handling is fixed here too.
|
|
36
|
+
* @param {number | string} timestamp omit for the current time
|
|
37
|
+
* @return {Date & { format?: Function }}
|
|
6
38
|
*/
|
|
7
39
|
export declare function timestampToTime(timestamp?: number | string): Date & {
|
|
8
40
|
format?: Function;
|
|
9
41
|
};
|
|
10
42
|
/**
|
|
11
|
-
* @description:
|
|
43
|
+
* @description: Format a number of seconds as a colon-separated duration
|
|
12
44
|
* @param {number} time
|
|
13
45
|
* @return {*}
|
|
14
46
|
*/
|
|
15
47
|
export declare const timeFormat: (time: number) => string;
|
|
16
48
|
/**
|
|
17
|
-
* @description:
|
|
49
|
+
* @description: Current timestamp
|
|
18
50
|
* @return {*}
|
|
19
51
|
*/
|
|
20
52
|
export declare const performanceTime: () => number;
|