@unicom-cloud/utils 0.1.5 → 0.1.11

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 (135) hide show
  1. package/caseName.js +11 -0
  2. package/className.js +5 -0
  3. package/clipboardCopy.js +6 -0
  4. package/constant.js +4 -0
  5. package/content-disposition/index.js +56 -0
  6. package/contentDisposition.js +7 -0
  7. package/convert-time/index.js +61 -0
  8. package/convertTime.js +4 -0
  9. package/cookie.js +7 -0
  10. package/dayjs.js +5 -0
  11. package/decimal.js +5 -0
  12. package/eventEmitter.js +4 -0
  13. package/file.js +6 -0
  14. package/filesize.js +8 -0
  15. package/index.js +44 -31
  16. package/invariant.js +4 -0
  17. package/is.js +92 -0
  18. package/lunar-converter/index.js +641 -0
  19. package/lunarConverter.js +4 -0
  20. package/math.js +9 -0
  21. package/md5.js +4 -0
  22. package/mock.js +8 -0
  23. package/normalizeWheel.js +6 -0
  24. package/number-to-chinese/index.js +72 -0
  25. package/numberToChinese.js +4 -0
  26. package/nzh.js +4 -0
  27. package/object-keys-sort/index.js +7 -0
  28. package/objectKeysSort.js +2 -5
  29. package/package.json +1 -1
  30. package/random.js +15 -0
  31. package/screenfull.js +4 -0
  32. package/search-tree/index.js +54 -0
  33. package/searchTree.js +4 -0
  34. package/snapdom/src/api/preCache.js +31 -27
  35. package/snapdom/src/core/capture.js +55 -44
  36. package/snapdom/src/core/clone.js +11 -11
  37. package/snapdom/src/core/prepare.js +38 -31
  38. package/snapdom/src/modules/background.js +18 -43
  39. package/snapdom/src/modules/pseudo.js +66 -67
  40. package/snapdom/src/utils/helpers.js +105 -56
  41. package/snapdom.js +6 -0
  42. package/tree.js +11 -0
  43. package/turboStream.js +6 -0
  44. package/types/case-name/index.d.ts +11 -0
  45. package/types/class-name/index.d.ts +2 -0
  46. package/types/clipboard-copy/index.d.ts +2 -0
  47. package/types/constant/address.d.ts +14 -0
  48. package/types/constant/chineseCharacters.d.ts +2 -0
  49. package/types/constant/constellations.d.ts +2 -0
  50. package/types/constant/domain.d.ts +2 -0
  51. package/types/constant/identity.d.ts +2 -0
  52. package/types/constant/index.d.ts +1 -0
  53. package/types/constant/keyboardCode.d.ts +158 -0
  54. package/types/constant/licensePlate.d.ts +2 -0
  55. package/types/constant/name.d.ts +4 -0
  56. package/types/constant/platform.d.ts +11 -0
  57. package/types/constant/protocol.d.ts +2 -0
  58. package/types/constant/ui.d.ts +14 -0
  59. package/types/content-disposition/index.d.ts +10 -0
  60. package/types/convert-time/index.d.ts +32 -0
  61. package/types/cookie/index.d.ts +4 -0
  62. package/types/cookie/src/index.d.ts +114 -0
  63. package/types/dayjs/index.d.ts +1 -0
  64. package/types/decimal/decimal.d.ts +4 -0
  65. package/types/decimal/index.d.ts +1 -0
  66. package/types/event-emitter/index.d.ts +17 -0
  67. package/types/file/fileToURL.d.ts +2 -0
  68. package/types/file/index.d.ts +3 -0
  69. package/types/file/saveAs.d.ts +2 -0
  70. package/types/filesize/index.d.ts +2 -0
  71. package/types/filesize/src/constants.d.ts +42 -0
  72. package/types/filesize/src/filesize.d.ts +47 -0
  73. package/types/index.d.ts +24 -0
  74. package/types/invariant/index.d.ts +2 -0
  75. package/types/is/index.d.ts +53 -0
  76. package/types/lunar-converter/index.d.ts +113 -0
  77. package/types/math/index.d.ts +11 -0
  78. package/types/md5/index.d.ts +2 -0
  79. package/types/mock/MockWebSocket.d.ts +17 -0
  80. package/types/mock/MockXMLHttpRequest.d.ts +17 -0
  81. package/types/mock/index.d.ts +2 -0
  82. package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
  83. package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
  84. package/types/normalize-wheel/index.d.ts +115 -0
  85. package/types/normalize-wheel/isEventSupported.d.ts +16 -0
  86. package/types/number-to-chinese/index.d.ts +11 -0
  87. package/types/nzh/cn.d.ts +8 -0
  88. package/types/nzh/hk.d.ts +8 -0
  89. package/types/nzh/index.d.ts +1 -0
  90. package/types/nzh/nzh.d.ts +36 -0
  91. package/types/nzh/src/autoGet.d.ts +8 -0
  92. package/types/nzh/src/index.d.ts +34 -0
  93. package/types/nzh/src/langs/cn_b.d.ts +10 -0
  94. package/types/nzh/src/langs/cn_s.d.ts +7 -0
  95. package/types/nzh/src/langs/hk_b.d.ts +10 -0
  96. package/types/nzh/src/langs/hk_s.d.ts +7 -0
  97. package/types/nzh/src/utils.d.ts +65 -0
  98. package/types/object-keys-sort/index.d.ts +4 -0
  99. package/types/random/address.d.ts +8 -0
  100. package/types/random/constellation.d.ts +2 -0
  101. package/types/random/image.d.ts +5 -0
  102. package/types/random/index.d.ts +40 -0
  103. package/types/random/licensePlate.d.ts +2 -0
  104. package/types/random/name.d.ts +9 -0
  105. package/types/random/number.d.ts +6 -0
  106. package/types/random/text.d.ts +13 -0
  107. package/types/random/time.d.ts +2 -0
  108. package/types/random/web.d.ts +11 -0
  109. package/types/screenfull/index.d.ts +10 -0
  110. package/types/search-tree/index.d.ts +20 -0
  111. package/types/snapdom/index.d.ts +1 -0
  112. package/types/snapdom/src/api/preCache.d.ts +8 -0
  113. package/types/snapdom/src/api/snapdom.d.ts +26 -0
  114. package/types/snapdom/src/core/cache.d.ts +11 -0
  115. package/types/snapdom/src/core/capture.d.ts +17 -0
  116. package/types/snapdom/src/core/clone.d.ts +11 -0
  117. package/types/snapdom/src/core/prepare.d.ts +8 -0
  118. package/types/snapdom/src/index.browser.d.ts +1 -0
  119. package/types/snapdom/src/index.d.ts +2 -0
  120. package/types/snapdom/src/modules/background.d.ts +10 -0
  121. package/types/snapdom/src/modules/fonts.d.ts +25 -0
  122. package/types/snapdom/src/modules/images.d.ts +8 -0
  123. package/types/snapdom/src/modules/pseudo.d.ts +12 -0
  124. package/types/snapdom/src/modules/styles.d.ts +10 -0
  125. package/types/snapdom/src/utils/cssTools.d.ts +38 -0
  126. package/types/snapdom/src/utils/helpers.d.ts +71 -0
  127. package/types/tree/index.d.ts +8 -0
  128. package/types/turbo-stream/index.d.ts +1 -0
  129. package/types/turbo-stream/src/decode.d.ts +7 -0
  130. package/types/turbo-stream/src/encode.d.ts +27 -0
  131. package/types/turbo-stream/src/shared.d.ts +107 -0
  132. package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
  133. package/types/url-toolkit/index.d.ts +2 -0
  134. package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
  135. package/urlToolkit.js +8 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts all <img> elements in the clone to data URLs or replaces them with placeholders if loading fails.
3
+ *
4
+ * @param {Element} clone - Clone of the original element
5
+ * @param {Object} [options={}] - Options for image processing
6
+ * @returns {Promise<void>} Promise that resolves when all images are processed
7
+ */
8
+ export function inlineImages(clone: Element, options?: Object): Promise<void>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Creates elements to represent ::before, ::after, and ::first-letter pseudo-elements, inlining their styles and content.
3
+ *
4
+ * @param {Element} source - Original element
5
+ * @param {Element} clone - Cloned element
6
+ * @param {Map} styleMap - Map to store element-to-style-key mappings
7
+ * @param {WeakMap} styleCache - Cache of computed styles
8
+ * @param {boolean} compress - Whether to compress style keys
9
+ * @param {boolean} embedFonts - Whether to embed icon fonts as images
10
+ * @returns {Promise} Promise that resolves when all pseudo-elements are processed
11
+ */
12
+ export function inlinePseudoElements(source: Element, clone: Element, styleMap: Map<any, any>, styleCache: WeakMap<any, any>, compress: boolean, embedFonts?: boolean): Promise<any>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Records computed styles for an element to later generate CSS classes.
3
+ *
4
+ * @param {Element} source - Original element
5
+ * @param {Element} clone - Cloned element
6
+ * @param {Map} styleMap - Map to store element-to-style-key mappings
7
+ * @param {WeakMap} cache - Cache of computed styles
8
+ * @param {boolean} compress - Whether to compress style keys
9
+ */
10
+ export function inlineAllStyles(source: Element, clone: Element, styleMap: Map<any, any>, cache: WeakMap<any, any>, compress: boolean): void;
@@ -0,0 +1,38 @@
1
+ export function precacheCommonTags(): void;
2
+ /**
3
+ * Retrieves default CSS property values from a temporary element.
4
+ *
5
+ * @param {string} tagName - The tag name to get default styles for
6
+ * @returns {Object} Object containing default values for all CSS properties
7
+ */
8
+ export function getDefaultStyleForTag(tagName: string): Object;
9
+ /**
10
+ * Creates a unique key from an element's computed style that differs from defaults.
11
+ *
12
+ * @param {Object} snapshot - Computed style snapshot
13
+ * @param {string} tagName - The tag name of the element
14
+ * @param {boolean} [compress=false] - Whether to compress style keys
15
+ * @returns {string} Semi-colon separated list of non-default properties
16
+ */
17
+ export function getStyleKey(snapshot: Object, tagName: string, compress?: boolean): string;
18
+ /**
19
+ * Collects all unique tag names used in the DOM tree rooted at the given node.
20
+ *
21
+ * @param {Node} root - The root node to search
22
+ * @returns {string[]} Array of unique tag names
23
+ */
24
+ export function collectUsedTagNames(root: Node): string[];
25
+ /**
26
+ * Generates deduplicated base CSS for the given tag names.
27
+ *
28
+ * @param {string[]} usedTagNames - Array of tag names
29
+ * @returns {string} CSS string
30
+ */
31
+ export function generateDedupedBaseCSS(usedTagNames: string[]): string;
32
+ /**
33
+ * Generates CSS classes from a style map.
34
+ *
35
+ * @param {Map} styleMap - Map of elements to style keys
36
+ * @returns {Map} Map of style keys to class names
37
+ */
38
+ export function generateCSSClasses(styleMap: Map<any, any>): Map<any, any>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Fetches and inlines a single background-image entry to a data URL (with caching).
3
+ * - If entry is a gradient or "none", returns unchanged.
4
+ * - If entry is a url(...), fetches the image as data URL and caches it.
5
+ *
6
+ * @param {string} entry - Single background-image entry (e.g., "url(...)").
7
+ * @param {Object} [options={}] - Options like crossOrigin.
8
+ * @param {boolean} [options.skipInline=false] - If true, only fetches & caches, doesn't return a replacement.
9
+ * @returns {Promise<string|void>} - The processed entry (unless skipInline is true).
10
+ */
11
+ export function inlineSingleBackgroundEntry(entry: string, options?: {
12
+ skipInline?: boolean | undefined;
13
+ }): Promise<string | void>;
14
+ /**
15
+ * Creates a promise that resolves after the specified delay
16
+ * @param {number} [ms=0] - Milliseconds to delay
17
+ * @returns {Promise<void>} Promise that resolves after the delay
18
+ */
19
+ export function idle(fn: any, { fast }?: {
20
+ fast?: boolean | undefined;
21
+ }): Promise<void>;
22
+ /**
23
+ * Gets the computed style for an element or pseudo-element, with caching.
24
+ *
25
+ * @param {Element} el - The element
26
+ * @param {string|null} [pseudo=null] - The pseudo-element
27
+ * @returns {CSSStyleDeclaration} The computed style
28
+ */
29
+ export function getStyle(el: Element, pseudo?: string | null): CSSStyleDeclaration;
30
+ /**
31
+ * Parses the CSS content property value, handling unicode escapes.
32
+ *
33
+ * @param {string} content - The CSS content value
34
+ * @returns {string} The parsed content
35
+ */
36
+ export function parseContent(content: string): string;
37
+ /**
38
+ * Extracts a URL from a CSS value like background-image.
39
+ *
40
+ * @param {string} value - The CSS value
41
+ * @returns {string|null} The extracted URL or null
42
+ */
43
+ export function extractURL(value: string): string | null;
44
+ /**
45
+ * Determines if a font family or URL is an icon font.
46
+ *
47
+ * @param {string} familyOrUrl - The font family or URL
48
+ * @returns {boolean} True if it is an icon font
49
+ */
50
+ export function isIconFont(familyOrUrl: string): boolean;
51
+ /**
52
+ *
53
+ *
54
+ * @export
55
+ * @param {*} src
56
+ * @param {number} [timeout=3000]
57
+ * @return {*}
58
+ */
59
+ export function fetchImage(src: any, timeout?: number, crossOrigin?: string): any;
60
+ /**
61
+ *
62
+ *
63
+ * @export
64
+ * @param {*} style
65
+ * @return {*}
66
+ */
67
+ export function snapshotComputedStyle(style: any): any;
68
+ export function isSafari(): boolean;
69
+ export function stripTranslate(transform: any): any;
70
+ export function safeEncodeURI(uri: any): any;
71
+ export function splitBackgroundImage(bg: any): any[];
@@ -0,0 +1,8 @@
1
+ export function findNodeBy(root: any, key: any, value: any, childrenKey?: string): any;
2
+ export function getItemBy(root: any, key: any, value: any, childrenKey?: string): any;
3
+ export function getItemBy3(root: any, key: any, value: any, childrenKey?: string): any;
4
+ export function getItemByID(root: any, value: any): any;
5
+ export function getLabelFromDictionaryByValue(a: any, value: any, 保底?: boolean): any;
6
+ export function getChildWithParentBy(root: any, key: any, value: any, childrenKey?: string): null | undefined;
7
+ export function getItemBy2(root: any, key: any, value: any, childrenKey?: string): any;
8
+ export default getItemBy;
@@ -0,0 +1 @@
1
+ export * from "./src/turbo-stream";
@@ -0,0 +1,7 @@
1
+ export type DecodePlugin = (type: string, ...data: unknown[]) => {
2
+ value: unknown;
3
+ } | false | null | undefined;
4
+ export type DecodeOptions = {
5
+ plugins?: DecodePlugin[];
6
+ };
7
+ export declare function decode<T>(stream: ReadableStream<string>, { plugins }?: DecodeOptions): Promise<T>;
@@ -0,0 +1,27 @@
1
+ declare const ASYNC_FRAME_TYPE_PROMISE = 1;
2
+ declare const ASYNC_FRAME_TYPE_ITERABLE = 2;
3
+ type AsyncFrame = [
4
+ type: typeof ASYNC_FRAME_TYPE_PROMISE,
5
+ id: number,
6
+ promise: PromiseLike<unknown>
7
+ ] | [
8
+ type: typeof ASYNC_FRAME_TYPE_ITERABLE,
9
+ id: number,
10
+ iterable: AsyncIterable<unknown>
11
+ ];
12
+ export type EncodePlugin = (value: unknown) => [string, ...unknown[]] | false | null | undefined;
13
+ export type EncodeOptions = {
14
+ plugins?: EncodePlugin[];
15
+ redactErrors?: boolean | string;
16
+ signal?: AbortSignal;
17
+ };
18
+ export declare function encode(value: unknown, { plugins, redactErrors, signal }?: EncodeOptions): ReadableStream<string>;
19
+ export declare function encodeSync(value: unknown, chunks: {
20
+ push(...chunk: string[]): void;
21
+ }, refs: WeakMap<object, number>, promises: WeakMap<object, number>, asyncFrames: {
22
+ push(frame: AsyncFrame): void;
23
+ }, counters: {
24
+ refId: number;
25
+ promiseId: number;
26
+ }, plugins: EncodePlugin[], redactErrors: boolean | string): void;
27
+ export {};
@@ -0,0 +1,107 @@
1
+ export declare const STR_ARRAY_BUFFER = "A";
2
+ export declare const STR_ASYNC_ITERABLE = "*";
3
+ export declare const STR_BIG_INT_64_ARRAY = "J";
4
+ export declare const STR_BIG_UINT_64_ARRAY = "j";
5
+ export declare const STR_BIGINT = "b";
6
+ export declare const STR_BLOB = "K";
7
+ export declare const STR_DATA_VIEW = "V";
8
+ export declare const STR_DATE = "D";
9
+ export declare const STR_ERROR = "E";
10
+ export declare const STR_FAILURE = "!";
11
+ export declare const STR_FALSE = "false";
12
+ export declare const STR_FILE = "k";
13
+ export declare const STR_FLOAT_32_ARRAY = "H";
14
+ export declare const STR_FLOAT_64_ARRAY = "h";
15
+ export declare const STR_FORM_DATA = "F";
16
+ export declare const STR_INFINITY = "I";
17
+ export declare const STR_INT_16_ARRAY = "L";
18
+ export declare const STR_INT_32_ARRAY = "G";
19
+ export declare const STR_INT_8_ARRAY = "O";
20
+ export declare const STR_MAP = "M";
21
+ export declare const STR_NaN = "NaN";
22
+ export declare const STR_NEGATIVE_INFINITY = "i";
23
+ export declare const STR_NEGATIVE_ZERO = "z";
24
+ export declare const STR_NULL = "null";
25
+ export declare const STR_PLUGIN = "P";
26
+ export declare const STR_PROMISE = "$";
27
+ export declare const STR_READABLE_STREAM = "R";
28
+ export declare const STR_REDACTED = "<redacted>";
29
+ export declare const STR_REFERENCE_SYMBOL = "@";
30
+ export declare const STR_REGEXP = "r";
31
+ export declare const STR_SET = "S";
32
+ export declare const STR_SUCCESS = ":";
33
+ export declare const STR_SYMBOL = "s";
34
+ export declare const STR_TRUE = "true";
35
+ export declare const STR_UINT_16_ARRAY = "l";
36
+ export declare const STR_UINT_32_ARRAY = "g";
37
+ export declare const STR_UINT_8_ARRAY = "o";
38
+ export declare const STR_UINT_8_ARRAY_CLAMPED = "C";
39
+ export declare const STR_UNDEFINED = "u";
40
+ export declare const STR_URL = "U";
41
+ declare let SUPPORTS_FILE: boolean;
42
+ export { SUPPORTS_FILE };
43
+ export declare class WaitGroup {
44
+ #private;
45
+ p: number;
46
+ add(): void;
47
+ done(): void;
48
+ wait(): Promise<void>;
49
+ }
50
+ export declare class Deferred<T> {
51
+ promise: Promise<T>;
52
+ resolve: (value: T) => void;
53
+ reject: (error: unknown) => void;
54
+ constructor();
55
+ }
56
+ export declare class DeferredAsyncIterable<T> {
57
+ #private;
58
+ iterable: AsyncIterable<T>;
59
+ constructor();
60
+ resolve(): void;
61
+ reject(error: unknown): void;
62
+ yield(value: T): void;
63
+ }
64
+ export declare class DeferredReadableStream<T> extends DeferredAsyncIterable<T> {
65
+ readable: ReadableStream<T>;
66
+ }
67
+ export declare class TurboBlob extends Blob {
68
+ #private;
69
+ promise?: Promise<ArrayBuffer>;
70
+ constructor();
71
+ constructor(from: TurboBlob, start: number | undefined, end: number | undefined, contentType: string | undefined);
72
+ get size(): number;
73
+ set size(value: number);
74
+ get type(): string;
75
+ set type(value: string);
76
+ arrayBuffer(): Promise<ArrayBuffer>;
77
+ bytes(): Promise<Uint8Array>;
78
+ slice(start?: number, end?: number, contentType?: string): Blob;
79
+ stream(): ReadableStream<Uint8Array>;
80
+ text(): Promise<string>;
81
+ }
82
+ declare const FileBaseClass: {
83
+ new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
84
+ prototype: File;
85
+ } | {
86
+ new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
87
+ prototype: Blob;
88
+ };
89
+ export declare class TurboFile extends FileBaseClass {
90
+ #private;
91
+ promise?: Promise<ArrayBuffer>;
92
+ constructor();
93
+ constructor(from: TurboFile, start: number | undefined, end: number | undefined, contentType: string | undefined);
94
+ get name(): string;
95
+ set name(value: string);
96
+ get lastModified(): number;
97
+ set lastModified(value: number);
98
+ get size(): number;
99
+ set size(value: number);
100
+ get type(): string;
101
+ set type(value: string);
102
+ arrayBuffer(): Promise<ArrayBuffer>;
103
+ bytes(): Promise<Uint8Array>;
104
+ slice(start?: number, end?: number, contentType?: string): Blob;
105
+ stream(): ReadableStream<Uint8Array>;
106
+ text(): Promise<string>;
107
+ }
@@ -0,0 +1,4 @@
1
+ export { decode } from './decode.js';
2
+ export type { DecodeOptions, DecodePlugin } from './decode.js';
3
+ export { encode } from './encode.js';
4
+ export type { EncodeOptions, EncodePlugin } from './encode.js';
@@ -0,0 +1,2 @@
1
+ export * from "./src/url-toolkit";
2
+ export { "/Users/panqibao/work/ui/utils/url-toolkit/src/url-toolkit" as default } from "./src/url-toolkit";
@@ -0,0 +1,18 @@
1
+ declare namespace _default {
2
+ export { buildAbsoluteURL };
3
+ export { parseURL };
4
+ export { normalizePath };
5
+ export { buildURLFromParts };
6
+ }
7
+ export default _default;
8
+ export function buildAbsoluteURL(baseURL: any, relativeURL: any, opts: any): any;
9
+ export function buildURLFromParts(parts: any): any;
10
+ export function normalizePath(path: any): any;
11
+ export function parseURL(url: any): {
12
+ scheme: string;
13
+ netLoc: string;
14
+ path: string;
15
+ params: string;
16
+ query: string;
17
+ fragment: string;
18
+ } | null;
package/urlToolkit.js ADDED
@@ -0,0 +1,8 @@
1
+ import { buildAbsoluteURL as e, buildURLFromParts as l, default as o, normalizePath as t, parseURL as u } from "./url-toolkit/src/url-toolkit.js";
2
+ export {
3
+ e as buildAbsoluteURL,
4
+ l as buildURLFromParts,
5
+ o as default,
6
+ t as normalizePath,
7
+ u as parseURL
8
+ };