@unicom-cloud/utils 0.1.10 → 0.1.12

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 (206) 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/contentDisposition.js +7 -0
  6. package/cookie.js +7 -0
  7. package/date/convertTime.js +61 -0
  8. package/date/index.js +22 -0
  9. package/date.js +9 -0
  10. package/decimal.js +5 -0
  11. package/eventEmitter.js +4 -0
  12. package/file.js +6 -0
  13. package/filesize.js +8 -0
  14. package/index.js +56 -46
  15. package/invariant.js +4 -0
  16. package/is.js +92 -0
  17. package/lunar/index.js +36 -0
  18. package/lunar/lib/Holiday.js +42 -0
  19. package/lunar/lib/HolidayUtil.js +128 -0
  20. package/lunar/lib/I18n.js +1005 -0
  21. package/lunar/lib/JieQi.js +40 -0
  22. package/lunar/lib/Lunar.js +1035 -0
  23. package/lunar/lib/LunarMonth.js +150 -0
  24. package/lunar/lib/LunarTime.js +138 -0
  25. package/lunar/lib/LunarUtil.js +1752 -0
  26. package/lunar/lib/LunarYear.js +616 -0
  27. package/lunar/lib/ShouXingUtil.js +6915 -0
  28. package/lunar/lib/Solar.js +311 -0
  29. package/lunar/lib/SolarHalfYear.js +45 -0
  30. package/lunar/lib/SolarMonth.js +55 -0
  31. package/lunar/lib/SolarSeason.js +42 -0
  32. package/lunar/lib/SolarUtil.js +256 -0
  33. package/lunar/lib/SolarWeek.js +153 -0
  34. package/lunar/lib/SolarYear.js +35 -0
  35. package/lunar/lib/index.js +35 -0
  36. package/lunar.js +36 -0
  37. package/math.js +9 -0
  38. package/md5.js +4 -0
  39. package/mock.js +8 -0
  40. package/normalizeWheel.js +6 -0
  41. package/number-to-chinese/index.js +72 -0
  42. package/numberToChinese.js +4 -0
  43. package/nzh.js +4 -0
  44. package/object-keys-sort/index.js +7 -0
  45. package/objectKeysSort.js +2 -5
  46. package/package.json +1 -1
  47. package/random.js +15 -0
  48. package/screenfull.js +4 -0
  49. package/snapdom/src/api/preCache.js +26 -36
  50. package/snapdom/src/api/snapdom.js +78 -61
  51. package/snapdom/src/core/capture.js +54 -54
  52. package/snapdom/src/core/prepare.js +46 -37
  53. package/snapdom/src/modules/fonts.js +90 -92
  54. package/snapdom/src/modules/iconFonts.js +28 -0
  55. package/snapdom/src/modules/images.js +6 -6
  56. package/snapdom/src/modules/pseudo.js +51 -49
  57. package/snapdom/src/modules/styles.js +27 -7
  58. package/snapdom/src/modules/svgDefs.js +26 -0
  59. package/snapdom/src/utils/helpers.js +150 -103
  60. package/snapdom.js +6 -0
  61. package/tinycolor/index.js +46 -0
  62. package/tinycolor/src/conversion.js +143 -0
  63. package/tinycolor/src/css-color-names.js +153 -0
  64. package/tinycolor/src/format-input.js +77 -0
  65. package/tinycolor/src/from-ratio.js +21 -0
  66. package/tinycolor/src/index.js +404 -0
  67. package/tinycolor/src/random.js +221 -0
  68. package/tinycolor/src/readability.js +37 -0
  69. package/tinycolor/src/to-ms-filter.js +15 -0
  70. package/tinycolor/src/util.js +32 -0
  71. package/tinycolor.js +46 -0
  72. package/tree/index.js +10 -8
  73. package/tree/searchTree.js +54 -0
  74. package/tree.js +13 -0
  75. package/turboStream.js +6 -0
  76. package/types/case-name/index.d.ts +11 -0
  77. package/types/class-name/index.d.ts +2 -0
  78. package/types/clipboard-copy/index.d.ts +2 -0
  79. package/types/constant/address.d.ts +14 -0
  80. package/types/constant/chineseCharacters.d.ts +2 -0
  81. package/types/constant/constellations.d.ts +2 -0
  82. package/types/constant/domain.d.ts +2 -0
  83. package/types/constant/identity.d.ts +2 -0
  84. package/types/constant/index.d.ts +1 -0
  85. package/types/constant/keyboardCode.d.ts +158 -0
  86. package/types/constant/licensePlate.d.ts +2 -0
  87. package/types/constant/name.d.ts +4 -0
  88. package/types/constant/platform.d.ts +11 -0
  89. package/types/constant/protocol.d.ts +2 -0
  90. package/types/constant/ui.d.ts +14 -0
  91. package/types/content-disposition/index.d.ts +10 -0
  92. package/types/cookie/index.d.ts +4 -0
  93. package/types/cookie/src/index.d.ts +114 -0
  94. package/types/date/convertTime.d.ts +32 -0
  95. package/types/date/index.d.ts +4 -0
  96. package/types/decimal/decimal.d.ts +4 -0
  97. package/types/decimal/index.d.ts +1 -0
  98. package/types/event-emitter/index.d.ts +17 -0
  99. package/types/file/fileToURL.d.ts +2 -0
  100. package/types/file/index.d.ts +3 -0
  101. package/types/file/saveAs.d.ts +2 -0
  102. package/types/filesize/index.d.ts +2 -0
  103. package/types/filesize/src/constants.d.ts +42 -0
  104. package/types/filesize/src/filesize.d.ts +47 -0
  105. package/types/index.d.ts +25 -0
  106. package/types/invariant/index.d.ts +2 -0
  107. package/types/is/index.d.ts +53 -0
  108. package/types/lunar/index.d.ts +3 -0
  109. package/types/lunar/lib/Holiday.d.ts +17 -0
  110. package/types/lunar/lib/HolidayUtil.d.ts +23 -0
  111. package/types/lunar/lib/I18n.d.ts +23 -0
  112. package/types/lunar/lib/JieQi.d.ts +15 -0
  113. package/types/lunar/lib/Lunar.d.ts +245 -0
  114. package/types/lunar/lib/LunarMonth.d.ts +35 -0
  115. package/types/lunar/lib/LunarTime.d.ts +40 -0
  116. package/types/lunar/lib/LunarUtil.d.ts +128 -0
  117. package/types/lunar/lib/LunarYear.d.ts +61 -0
  118. package/types/lunar/lib/ShouXingUtil.d.ts +38 -0
  119. package/types/lunar/lib/Solar.d.ts +51 -0
  120. package/types/lunar/lib/SolarHalfYear.d.ts +15 -0
  121. package/types/lunar/lib/SolarMonth.d.ts +16 -0
  122. package/types/lunar/lib/SolarSeason.d.ts +15 -0
  123. package/types/lunar/lib/SolarUtil.d.ts +20 -0
  124. package/types/lunar/lib/SolarWeek.d.ts +23 -0
  125. package/types/lunar/lib/SolarYear.d.ts +12 -0
  126. package/types/lunar/lib/index.d.ts +17 -0
  127. package/types/math/index.d.ts +11 -0
  128. package/types/md5/index.d.ts +2 -0
  129. package/types/mock/MockWebSocket.d.ts +17 -0
  130. package/types/mock/MockXMLHttpRequest.d.ts +17 -0
  131. package/types/mock/index.d.ts +2 -0
  132. package/types/normalize-wheel/ExecutionEnvironment.d.ts +9 -0
  133. package/types/normalize-wheel/UserAgent_DEPRECATED.d.ts +86 -0
  134. package/types/normalize-wheel/index.d.ts +115 -0
  135. package/types/normalize-wheel/isEventSupported.d.ts +16 -0
  136. package/types/number-to-chinese/index.d.ts +11 -0
  137. package/types/nzh/cn.d.ts +8 -0
  138. package/types/nzh/hk.d.ts +8 -0
  139. package/types/nzh/index.d.ts +1 -0
  140. package/types/nzh/nzh.d.ts +36 -0
  141. package/types/nzh/src/autoGet.d.ts +8 -0
  142. package/types/nzh/src/index.d.ts +34 -0
  143. package/types/nzh/src/langs/cn_b.d.ts +10 -0
  144. package/types/nzh/src/langs/cn_s.d.ts +7 -0
  145. package/types/nzh/src/langs/hk_b.d.ts +10 -0
  146. package/types/nzh/src/langs/hk_s.d.ts +7 -0
  147. package/types/nzh/src/utils.d.ts +65 -0
  148. package/types/object-keys-sort/index.d.ts +4 -0
  149. package/types/random/address.d.ts +8 -0
  150. package/types/random/constellation.d.ts +2 -0
  151. package/types/random/image.d.ts +5 -0
  152. package/types/random/index.d.ts +40 -0
  153. package/types/random/licensePlate.d.ts +2 -0
  154. package/types/random/name.d.ts +9 -0
  155. package/types/random/number.d.ts +6 -0
  156. package/types/random/text.d.ts +13 -0
  157. package/types/random/time.d.ts +2 -0
  158. package/types/random/web.d.ts +11 -0
  159. package/types/screenfull/index.d.ts +10 -0
  160. package/types/snapdom/index.d.ts +1 -0
  161. package/types/snapdom/src/api/preCache.d.ts +8 -0
  162. package/types/snapdom/src/api/snapdom.d.ts +26 -0
  163. package/types/snapdom/src/core/cache.d.ts +11 -0
  164. package/types/snapdom/src/core/capture.d.ts +17 -0
  165. package/types/snapdom/src/core/clone.d.ts +11 -0
  166. package/types/snapdom/src/core/prepare.d.ts +8 -0
  167. package/types/snapdom/src/index.browser.d.ts +1 -0
  168. package/types/snapdom/src/index.d.ts +2 -0
  169. package/types/snapdom/src/modules/background.d.ts +10 -0
  170. package/types/snapdom/src/modules/fonts.d.ts +23 -0
  171. package/types/snapdom/src/modules/iconFonts.d.ts +2 -0
  172. package/types/snapdom/src/modules/images.d.ts +8 -0
  173. package/types/snapdom/src/modules/pseudo.d.ts +12 -0
  174. package/types/snapdom/src/modules/styles.d.ts +1 -0
  175. package/types/snapdom/src/modules/svgDefs.d.ts +19 -0
  176. package/types/snapdom/src/utils/cssTools.d.ts +38 -0
  177. package/types/snapdom/src/utils/helpers.d.ts +71 -0
  178. package/types/tinycolor/index.d.ts +2 -0
  179. package/types/tinycolor/src/conversion.d.ts +79 -0
  180. package/types/tinycolor/src/css-color-names.d.ts +4 -0
  181. package/types/tinycolor/src/format-input.d.ts +38 -0
  182. package/types/tinycolor/src/from-ratio.d.ts +14 -0
  183. package/types/tinycolor/src/index.d.ts +214 -0
  184. package/types/tinycolor/src/interfaces.d.ts +57 -0
  185. package/types/tinycolor/src/public_api.d.ts +10 -0
  186. package/types/tinycolor/src/random.d.ts +24 -0
  187. package/types/tinycolor/src/readability.d.ts +46 -0
  188. package/types/tinycolor/src/to-ms-filter.d.ts +5 -0
  189. package/types/tinycolor/src/umd_api.d.ts +22 -0
  190. package/types/tinycolor/src/util.d.ts +36 -0
  191. package/types/tree/index.d.ts +9 -0
  192. package/types/tree/searchTree.d.ts +20 -0
  193. package/types/turbo-stream/index.d.ts +1 -0
  194. package/types/turbo-stream/src/decode.d.ts +7 -0
  195. package/types/turbo-stream/src/encode.d.ts +27 -0
  196. package/types/turbo-stream/src/shared.d.ts +107 -0
  197. package/types/turbo-stream/src/turbo-stream.d.ts +4 -0
  198. package/types/ui-color/compareColorByRange.d.ts +2 -0
  199. package/types/ui-color/index.d.ts +183 -0
  200. package/types/url-toolkit/index.d.ts +2 -0
  201. package/types/url-toolkit/src/url-toolkit.d.ts +18 -0
  202. package/ui-color/compareColorByRange.js +9 -0
  203. package/ui-color/index.js +155 -0
  204. package/uiColor.js +28 -0
  205. package/urlToolkit.js +8 -0
  206. package/dayjs/index.js +0 -15
@@ -0,0 +1,10 @@
1
+ export default screenfull;
2
+ declare namespace screenfull {
3
+ export function request(element: HTMLElement | undefined, options: any): Promise<any>;
4
+ export function exit(): Promise<any>;
5
+ export function toggle(element: any, options: any): any;
6
+ export function on(event: any, callback: any): void;
7
+ export function off(event: any, callback: any): void;
8
+ export { nativeAPI as raw };
9
+ }
10
+ declare const nativeAPI: {};
@@ -0,0 +1 @@
1
+ export * from "./src";
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Preloads images, background images, and optionally fonts into cache before DOM capture.
3
+ *
4
+ * @param {Document|Element} [root=document] - The root node to search for resources
5
+ * @param {Object} [options={}] - Pre-caching options
6
+ * @returns {Promise<void>} Resolves when all resources are pre-cached
7
+ */
8
+ export function preCache(root?: Document | Element, options?: Object): Promise<void>;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Main entry point: captures a DOM element and returns an object with export methods.
3
+ *
4
+ * @param {Element} element - DOM element to capture
5
+ * @param {Object} [options={}] - Capture options
6
+ * @returns {Promise<Object>} Object with export methods (toRaw, toImg, toCanvas, etc.)
7
+ */
8
+ export function snapdom(element: Element, options?: Object): Promise<Object>;
9
+ export namespace snapdom {
10
+ /**
11
+ * Captures a DOM element and returns an object with export methods (internal use).
12
+ *
13
+ * @param {Element} el - DOM element to capture
14
+ * @param {Object} [options={}] - Capture options
15
+ * @returns {Promise<Object>} Object with export methods
16
+ */
17
+ function capture(el: Element, options?: Object): Promise<Object>;
18
+ function toRaw(el: any, options: any): Promise<any>;
19
+ function toImg(el: any, options: any): Promise<any>;
20
+ function toCanvas(el: any, options: any): Promise<any>;
21
+ function toBlob(el: any, options: any): Promise<any>;
22
+ function toPng(el: any, options: any): Promise<any>;
23
+ function toJpg(el: any, options: any): Promise<any>;
24
+ function toWebp(el: any, options: any): Promise<any>;
25
+ function download(el: any, options?: {}): Promise<any>;
26
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Caches for images, backgrounds, resources, and computed styles used during DOM capture.
3
+ * @module cache
4
+ */
5
+ export const imageCache: Map<any, any>;
6
+ export const bgCache: Map<any, any>;
7
+ export const resourceCache: Map<any, any>;
8
+ export const defaultStylesCache: Map<any, any>;
9
+ export const baseCSSCache: Map<any, any>;
10
+ export const computedStyleCache: WeakMap<WeakKey, any>;
11
+ export const processedFontURLs: Set<any>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Captures an HTML element as an SVG data URL, inlining styles, images, backgrounds, and optionally fonts.
3
+ *
4
+ * @param {Element} element - DOM element to capture
5
+ * @param {Object} [options={}] - Capture options
6
+ * @param {boolean} [options.compress=true] - Whether to compress style keys
7
+ * @param {boolean} [options.embedFonts=false] - Whether to embed custom fonts
8
+ * @param {boolean} [options.fast=true] - Whether to skip idle delay for faster results
9
+ * @param {number} [options.scale=1] - Output scale multiplier
10
+ * @returns {Promise<string>} Promise that resolves to an SVG data URL
11
+ */
12
+ export function captureDOM(element: Element, options?: {
13
+ compress?: boolean | undefined;
14
+ embedFonts?: boolean | undefined;
15
+ fast?: boolean | undefined;
16
+ scale?: number | undefined;
17
+ }): Promise<string>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Creates a deep clone of a DOM node, including styles, shadow DOM, and special handling for excluded/placeholder/canvas nodes.
3
+ *
4
+ * @param {Node} node - Node to clone
5
+ * @param {Map} styleMap - Map to store element-to-style-key mappings
6
+ * @param {WeakMap} styleCache - Cache of computed styles
7
+ * @param {WeakMap} nodeMap - Map to track original-to-clone node relationships
8
+ * @param {boolean} compress - Whether to compress style keys
9
+ * @returns {Node|null} Cloned node with styles and shadow DOM content, or null for empty text nodes
10
+ */
11
+ export function deepClone(node: Node, styleMap: Map<any, any>, styleCache: WeakMap<any, any>, nodeMap: WeakMap<any, any>, compress: boolean): Node | null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Prepares a clone of an element for capture, inlining pseudo-elements and generating CSS classes.
3
+ *
4
+ * @param {Element} element - Element to clone
5
+ * @param {boolean} [compress=false] - Whether to compress style keys
6
+ * @returns {Promise<Object>} Object containing the clone, generated CSS, and style cache
7
+ */
8
+ export function prepareClone(element: Element, compress?: boolean, embedFonts?: boolean, useProxy?: string): Promise<Object>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { preCache } from "./api/preCache.js";
2
+ export { snapdom } from "./api/snapdom.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts all background images in the cloned element tree to data URLs.
3
+ *
4
+ * @param {Element} source - Original element
5
+ * @param {Element} clone - Cloned element
6
+ * @param {WeakMap} styleCache - Cache of computed styles
7
+ * @param {Object} [options={}] - Options for image processing
8
+ * @returns {Promise<void>} Promise that resolves when all background images are processed
9
+ */
10
+ export function inlineBackgroundImages(source: Element, clone: Element, styleCache: WeakMap<any, any>, options?: Object): Promise<void>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Converts a unicode character from an icon font into a data URL image.
3
+ *
4
+ * @export
5
+ * @param {string} unicodeChar - The unicode character to render
6
+ * @param {string} fontFamily - The font family name
7
+ * @param {string|number} fontWeight - The font weight
8
+ * @param {number} [fontSize=32] - The font size in pixels
9
+ * @param {string} [color="#000"] - The color to use
10
+ * @returns {Promise<string>} Data URL of the rendered icon
11
+ */
12
+ export function iconToImage(unicodeChar: string, fontFamily: string, fontWeight: string | number, fontSize?: number, color?: string): Promise<string>;
13
+ /**
14
+ * Embeds custom fonts found in the document as data URLs in CSS.
15
+ *
16
+ * @export
17
+ * @param {Object} options
18
+ * @param {boolean} [options.preCached=false] - Whether to use pre-cached resources
19
+ * @returns {Promise<string>} The inlined CSS for custom fonts
20
+ */
21
+ export function embedCustomFonts({ preCached }?: {
22
+ preCached?: boolean | undefined;
23
+ }): Promise<string>;
@@ -0,0 +1,2 @@
1
+ export function extendIconFonts(fonts: any): void;
2
+ export function isIconFont(input: any): boolean;
@@ -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 | undefined, useProxy: any): Promise<any>;
@@ -0,0 +1 @@
1
+ export function inlineAllStyles(source: any, clone: any, styleMap: any, cache: any, compress: any): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Inlines external `<defs>` used by `<use xlink:href="#...">` or `<use href="#...">` inside SVGs,
3
+ * copying only the necessary definitions into each individual cloned SVG.
4
+ *
5
+ * This is needed because cloned SVGs using `<use>` may reference elements like `<symbol>`, `<path>`, etc.,
6
+ * defined elsewhere in the document (e.g., in a shared `<defs>` block that is not part of the cloned subtree).
7
+ *
8
+ * The function finds all `<use>` elements within `root`, extracts the referenced IDs,
9
+ * and embeds the required definitions at the top of each SVG.
10
+ *
11
+ * @function inlineExternalDef
12
+ * @param {ParentNode} root - The root node containing cloned SVGs (usually the result of a DOM snapshot).
13
+ * @returns {void}
14
+ *
15
+ * @example
16
+ * const { clone } = await prepareClone(element);
17
+ * inlineExternalDef(clone);
18
+ */
19
+ export function inlineExternalDef(root: ParentNode): 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, useProxy }?: number): 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,2 @@
1
+ export * from './src/public_api';
2
+ export { TinyColor as default } from './src';
@@ -0,0 +1,79 @@
1
+ import { HSL, HSV, Numberify, RGB } from './interfaces.js';
2
+ /**
3
+ * Handle bounds / percentage checking to conform to CSS color spec
4
+ * <http://www.w3.org/TR/css3-color/>
5
+ * *Assumes:* r, g, b in [0, 255] or [0, 1]
6
+ * *Returns:* { r, g, b } in [0, 255]
7
+ */
8
+ export declare function rgbToRgb(r: number | string, g: number | string, b: number | string): Numberify<RGB>;
9
+ /**
10
+ * Converts an RGB color value to HSL.
11
+ * *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
12
+ * *Returns:* { h, s, l } in [0,1]
13
+ */
14
+ export declare function rgbToHsl(r: number, g: number, b: number): Numberify<HSL>;
15
+ /**
16
+ * Converts an HSL color value to RGB.
17
+ *
18
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
19
+ * *Returns:* { r, g, b } in the set [0, 255]
20
+ */
21
+ export declare function hslToRgb(h: number | string, s: number | string, l: number | string): Numberify<RGB>;
22
+ /**
23
+ * Converts an RGB color value to HSV
24
+ *
25
+ * *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
26
+ * *Returns:* { h, s, v } in [0,1]
27
+ */
28
+ export declare function rgbToHsv(r: number, g: number, b: number): Numberify<HSV>;
29
+ /**
30
+ * Converts an HSV color value to RGB.
31
+ *
32
+ * *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
33
+ * *Returns:* { r, g, b } in the set [0, 255]
34
+ */
35
+ export declare function hsvToRgb(h: number | string, s: number | string, v: number | string): Numberify<RGB>;
36
+ /**
37
+ * Converts an RGB color to hex
38
+ *
39
+ * *Assumes:* r, g, and b are contained in the set [0, 255]
40
+ * *Returns:* a 3 or 6 character hex
41
+ */
42
+ export declare function rgbToHex(r: number, g: number, b: number, allow3Char: boolean): string;
43
+ /**
44
+ * Converts an RGBA color plus alpha transparency to hex
45
+ *
46
+ * *Assumes:* r, g, b are contained in the set [0, 255] and a in [0, 1]
47
+ * *Returns:* a 4 or 8 character rgba hex
48
+ */
49
+ export declare function rgbaToHex(r: number, g: number, b: number, a: number, allow4Char: boolean): string;
50
+ /**
51
+ * Converts an RGBA color to an ARGB Hex8 string
52
+ * Rarely used, but required for "toFilter()"
53
+ *
54
+ * *Assumes:* r, g, b are contained in the set [0, 255] and a in [0, 1]
55
+ * *Returns:* a 8 character argb hex
56
+ */
57
+ export declare function rgbaToArgbHex(r: number, g: number, b: number, a: number): string;
58
+ /**
59
+ * Converts CMYK to RBG
60
+ * Assumes c, m, y, k are in the set [0, 100]
61
+ */
62
+ export declare function cmykToRgb(c: number, m: number, y: number, k: number): {
63
+ r: number;
64
+ g: number;
65
+ b: number;
66
+ };
67
+ export declare function rgbToCmyk(r: number, g: number, b: number): {
68
+ c: number;
69
+ m: number;
70
+ y: number;
71
+ k: number;
72
+ };
73
+ /** Converts a decimal to a hex value */
74
+ export declare function convertDecimalToHex(d: string | number): string;
75
+ /** Converts a hex value to a decimal */
76
+ export declare function convertHexToDecimal(h: string): number;
77
+ /** Parse a base-16 hex value into a base-10 integer */
78
+ export declare function parseIntFromHex(val: string): number;
79
+ export declare function numberInputToObject(color: number): RGB;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @hidden
3
+ */
4
+ export declare const names: Record<string, string>;
@@ -0,0 +1,38 @@
1
+ import { CMYK, HSL, HSLA, HSV, HSVA, RGB, RGBA } from './interfaces.js';
2
+ /**
3
+ * Given a string or object, convert that input to RGB
4
+ *
5
+ * Possible string inputs:
6
+ * ```
7
+ * "red"
8
+ * "#f00" or "f00"
9
+ * "#ff0000" or "ff0000"
10
+ * "#ff000000" or "ff000000"
11
+ * "rgb 255 0 0" or "rgb (255, 0, 0)"
12
+ * "rgb 1.0 0 0" or "rgb (1, 0, 0)"
13
+ * "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
14
+ * "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
15
+ * "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
16
+ * "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
17
+ * "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
18
+ * "cmyk(0, 20, 0, 0)" or "cmyk 0 20 0 0"
19
+ * ```
20
+ */
21
+ export declare function inputToRGB(color: string | RGB | RGBA | HSL | HSLA | HSV | HSVA | CMYK | any): {
22
+ ok: boolean;
23
+ format: any;
24
+ r: number;
25
+ g: number;
26
+ b: number;
27
+ a: number;
28
+ };
29
+ /**
30
+ * Permissive string parsing. Take in a number of formats, and output an object
31
+ * based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}` or `{c, m, y, k}` or `{c, m, y, k, a}`
32
+ */
33
+ export declare function stringInputToObject(color: string): any;
34
+ /**
35
+ * Check to see if it looks like a CSS unit
36
+ * (see `matchers` above for definition).
37
+ */
38
+ export declare function isValidCSSUnit(color: string | number): boolean;
@@ -0,0 +1,14 @@
1
+ import { TinyColor } from './index.js';
2
+ export interface RatioInput {
3
+ r: number | string;
4
+ g: number | string;
5
+ b: number | string;
6
+ a?: number | string;
7
+ }
8
+ /**
9
+ * If input is an object, force 1 into "1.0" to handle ratios properly
10
+ * String input requires "1.0" as input, so 1 will be treated as 1
11
+ */
12
+ export declare function fromRatio(ratio: RatioInput, opts?: any): TinyColor;
13
+ /** old random function */
14
+ export declare function legacyRandom(): TinyColor;
@@ -0,0 +1,214 @@
1
+ import { CMYK, HSL, HSLA, HSV, HSVA, Numberify, RGB, RGBA } from './interfaces.js';
2
+ export interface TinyColorOptions {
3
+ format: string;
4
+ gradientType: string;
5
+ }
6
+ export type ColorInput = string | number | RGB | RGBA | HSL | HSLA | HSV | HSVA | CMYK | TinyColor | unknown;
7
+ export type ColorFormats = 'rgb' | 'prgb' | 'hex' | 'hex3' | 'hex4' | 'hex6' | 'hex8' | 'name' | 'hsl' | 'hsv' | 'cmyk';
8
+ export declare class TinyColor {
9
+ /** red */
10
+ r: number;
11
+ /** green */
12
+ g: number;
13
+ /** blue */
14
+ b: number;
15
+ /** alpha */
16
+ a: number;
17
+ /** the format used to create the tinycolor instance */
18
+ format: ColorFormats;
19
+ /** input passed into the constructer used to create the tinycolor instance */
20
+ originalInput: ColorInput;
21
+ /** the color was successfully parsed */
22
+ isValid: boolean;
23
+ gradientType?: string;
24
+ /** rounded alpha */
25
+ roundA: number;
26
+ constructor(color?: ColorInput, opts?: Partial<TinyColorOptions>);
27
+ get ok(): boolean;
28
+ isDark(): boolean;
29
+ isLight(): boolean;
30
+ /**
31
+ * Returns the perceived brightness of the color, from 0-255.
32
+ */
33
+ getBrightness(): number;
34
+ /**
35
+ * Returns the perceived luminance of a color, from 0-1.
36
+ */
37
+ getLuminance(): number;
38
+ /**
39
+ * Returns the alpha value of a color, from 0-1.
40
+ */
41
+ getAlpha(): number;
42
+ /**
43
+ * Sets the alpha value on the current color.
44
+ *
45
+ * @param alpha - The new alpha value. The accepted range is 0-1.
46
+ */
47
+ setAlpha(alpha?: string | number): this;
48
+ /**
49
+ * Returns whether the color is monochrome.
50
+ */
51
+ isMonochrome(): boolean;
52
+ /**
53
+ * Returns the object as a HSVA object.
54
+ */
55
+ toHsv(): Numberify<HSVA>;
56
+ toHsv_(): Numberify<HSVA>;
57
+ /**
58
+ * Returns the hsva values interpolated into a string with the following format:
59
+ * "hsva(xxx, xxx, xxx, xx)".
60
+ */
61
+ toHsvString(): string;
62
+ /**
63
+ * Returns the object as a HSLA object.
64
+ */
65
+ toHsl(): Numberify<HSLA>;
66
+ /**
67
+ * Returns the hsla values interpolated into a string with the following format:
68
+ * "hsla(xxx, xxx, xxx, xx)".
69
+ */
70
+ toHslString(): string;
71
+ /**
72
+ * Returns the hex value of the color.
73
+ * @param allow3Char will shorten hex value to 3 char if possible
74
+ */
75
+ toHex(allow3Char?: boolean): string;
76
+ /**
77
+ * Returns the hex value of the color -with a # prefixed.
78
+ * @param allow3Char will shorten hex value to 3 char if possible
79
+ */
80
+ toHexString(allow3Char?: boolean): string;
81
+ /**
82
+ * Returns the hex 8 value of the color.
83
+ * @param allow4Char will shorten hex value to 4 char if possible
84
+ */
85
+ toHex8(allow4Char?: boolean): string;
86
+ /**
87
+ * Returns the hex 8 value of the color -with a # prefixed.
88
+ * @param allow4Char will shorten hex value to 4 char if possible
89
+ */
90
+ toHex8String(allow4Char?: boolean): string;
91
+ /**
92
+ * Returns the shorter hex value of the color depends on its alpha -with a # prefixed.
93
+ * @param allowShortChar will shorten hex value to 3 or 4 char if possible
94
+ */
95
+ toHexShortString(allowShortChar?: boolean): string;
96
+ /**
97
+ * Returns the object as a RGBA object.
98
+ */
99
+ toRgb(): Numberify<RGBA>;
100
+ toRgba(): Numberify<RGBA>;
101
+ toRgbArray(): number[];
102
+ toRgbArrayString(): string;
103
+ /**
104
+ * Returns the RGBA values interpolated into a string with the following format:
105
+ * "RGBA(xxx, xxx, xxx, xx)".
106
+ */
107
+ toRgbString(): string;
108
+ toRgbaString(): string;
109
+ /**
110
+ * Returns the object as a RGBA object.
111
+ */
112
+ toPercentageRgb(): RGBA;
113
+ /**
114
+ * Returns the RGBA relative values interpolated into a string
115
+ */
116
+ toPercentageRgbString(): string;
117
+ toCmyk(): Numberify<CMYK>;
118
+ toCmykString(): string;
119
+ /**
120
+ * The 'real' name of the color -if there is one.
121
+ */
122
+ toName(): string | false;
123
+ /**
124
+ * String representation of the color.
125
+ *
126
+ * @param format - The format to be used when displaying the string representation.
127
+ */
128
+ toString<T extends 'name'>(format: T): boolean | string;
129
+ toString<T extends ColorFormats>(format?: T): string;
130
+ toNumber(): number;
131
+ clone(): TinyColor;
132
+ /**
133
+ * Lighten the color a given amount. Providing 100 will always return white.
134
+ * @param amount - valid between 1-100
135
+ */
136
+ lighten(amount?: number): TinyColor;
137
+ /**
138
+ * Brighten the color a given amount, from 0 to 100.
139
+ * @param amount - valid between 1-100
140
+ */
141
+ brighten(amount?: number): TinyColor;
142
+ /**
143
+ * Darken the color a given amount, from 0 to 100.
144
+ * Providing 100 will always return black.
145
+ * @param amount - valid between 1-100
146
+ */
147
+ darken(amount?: number): TinyColor;
148
+ /**
149
+ * Mix the color with pure white, from 0 to 100.
150
+ * Providing 0 will do nothing, providing 100 will always return white.
151
+ * @param amount - valid between 1-100
152
+ */
153
+ tint(amount?: number): TinyColor;
154
+ /**
155
+ * Mix the color with pure black, from 0 to 100.
156
+ * Providing 0 will do nothing, providing 100 will always return black.
157
+ * @param amount - valid between 1-100
158
+ */
159
+ shade(amount?: number): TinyColor;
160
+ /**
161
+ * Desaturate the color a given amount, from 0 to 100.
162
+ * Providing 100 will is the same as calling greyscale
163
+ * @param amount - valid between 1-100
164
+ */
165
+ desaturate(amount?: number): TinyColor;
166
+ /**
167
+ * Saturate the color a given amount, from 0 to 100.
168
+ * @param amount - valid between 1-100
169
+ */
170
+ saturate(amount?: number): TinyColor;
171
+ /**
172
+ * Completely desaturates a color into greyscale.
173
+ * Same as calling `desaturate(100)`
174
+ */
175
+ greyscale(): TinyColor;
176
+ /**
177
+ * Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
178
+ * Values outside of this range will be wrapped into this range.
179
+ */
180
+ spin(amount: number): TinyColor;
181
+ /**
182
+ * Mix the current color a given amount with another color, from 0 to 100.
183
+ * 0 means no mixing (return current color).
184
+ */
185
+ mix(color: ColorInput, amount?: number): TinyColor;
186
+ analogous(results?: number, slices?: number): TinyColor[];
187
+ /**
188
+ * taken from https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js
189
+ */
190
+ complement(): TinyColor;
191
+ monochromatic(results?: number): TinyColor[];
192
+ splitcomplement(): TinyColor[];
193
+ /**
194
+ * Compute how the color would appear on a background
195
+ */
196
+ onBackground(background: ColorInput): TinyColor;
197
+ /**
198
+ * Alias for `polyad(3)`
199
+ */
200
+ triad(): TinyColor[];
201
+ /**
202
+ * Alias for `polyad(4)`
203
+ */
204
+ tetrad(): TinyColor[];
205
+ /**
206
+ * Get polyad colors, like (for 1, 2, 3, 4, 5, 6, 7, 8, etc...)
207
+ * monad, dyad, triad, tetrad, pentad, hexad, heptad, octad, etc...
208
+ */
209
+ polyad(n: number): TinyColor[];
210
+ /**
211
+ * compare color vs current color
212
+ */
213
+ equals(color?: ColorInput): boolean;
214
+ }