/** * Copyright 2007-2025 MAIYUN.NET * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * --- 运行 iife 代码 --- * @param code iife 代码 * @returns 模块对象 */ export declare function runIife(code: string): any; /** * --- 压缩一个图片 --- * @param file 文件或 blob 类型 --- * @param options 参数 */ export declare function compressor(file: T, options?: { /** --- 最大宽度,默认无限 --- */ 'maxWidth'?: number; /** --- 最高高度,默认无限 --- */ 'maxHeight'?: number; /** --- 压缩质量,默认 0.8 --- */ 'quality'?: number; }): Promise; /** --- 类原型信息 --- */ export interface IClassPrototype { /** --- 方法列表,key 为方法名,value 为函数体,例如:{'method1': function() { ... }} --- */ 'method': Record; /** --- 访问器列表,key 为属性名,value 为包含 get 和 set 的对象,例如:{'prop1': { 'get': function() { ... }, 'set': function(v) { ... } }} --- */ 'access': Record; } /** * --- 获取 class 的所有 method 和 get/set --- * @param obj 实例化 class 对象 * @param over 不传入此参数 * @param level 不传入此参数 */ export declare function getClassPrototype(obj: object, over?: string[], level?: number): IClassPrototype; /** * --- 将 blob 对象转换为 ArrayBuffer --- * @param blob 对象 */ export declare function blob2ArrayBuffer(blob: Blob): Promise; /** * --- 将文件大小格式化为带单位的字符串 --- * @param size 文件大小 * @param spliter 分隔符 */ export declare function sizeFormat(size: number, spliter?: string): string; /** * --- 将毫克重量格式化为带单位的字符串 --- * @param weight 毫克重量 * @param spliter 分隔符 */ export declare function weightFormat(weight: number, spliter?: string): string; /** * --- 完整的克隆一份数组/对象 --- * @param obj 要克隆的对象 */ export declare function clone(obj: T): T; /** * --- 等待毫秒 --- * @param ms 等待的毫秒,默认 0,最大 30 秒 */ export declare function sleep(ms?: number): Promise; /** * --- 等待浏览器帧 --- */ export declare function nextFrame(): Promise; /** * --- 等待浏览器帧 --- * @param count 等待帧数最高 10 帧 */ export declare function sleepFrame(count: number): Promise; /** * --- 去除 html 的空白符、换行以及注释 --- * @param text 要纯净的字符串 */ export declare function purify(text: string): string; /** * --- 传入正则进行匹配 str 是否有一项满足 --- * @param str 要检测的字符串 * @param regs 正则列表 */ export declare function match(str: string, regs: RegExp[]): boolean; /** * --- 将 style 中的 url 转换成 base64 data url --- * @param path 路径基准或以文件的路径为基准,以 / 结尾 * @param style 样式表 * @param files 在此文件列表中查找 */ export declare function styleUrl2DataUrl(path: string, style: string, files: Record): Promise; /** * --- 给标签增加 tag-tagname 的 class,同时给标签增加 cg- 前导(仅字符串,不是操作真实 dom) --- * @param layout layout * @param retagname 是否更改 tagname 为 cg-tagname */ export declare function layoutAddTagClassAndReTagName(layout: string, retagname: boolean): string; /** * --- 给标签追加 attr,即使 attr 存在也会追加上一个新的(非真实 DOM 操作,仅仅是对字符串进行处理) --- * @param layout 被追加 * @param insert 要追加 * @param opt 选项, ignore 忽略的标签,include 包含的标签 */ export declare function layoutInsertAttr(layout: string, insert: string, opt?: { 'ignore'?: RegExp[]; 'include'?: RegExp[]; }): string; /** * --- 给 class 增加 scope 的随机前缀,给 id 新增前缀 --- * @param layout layout * @param preps 前置标识符列表,特殊字符串 scope 会被替换为随机前缀 */ export declare function layoutClassPrepend(layout: string, preps: string[]): string; /** * --- 对 layout 的 events 事件进行包裹 --- * @param layout 要包裹的 layout */ export declare function eventsAttrWrap(layout: string): string; /** * --- 对 layout 的 teleport 做转义处理为 vue 识别的内容 --- * @param layout 要处理的窗体或控件的 layout * @param formId 要加入的 formId */ export declare function teleportGlue(layout: string, formId: string): string; /** * --- 给 class 前部增加唯一标识符 --- * @param style 样式内容 * @param prep 给 class、font 等增加前置 */ export declare function stylePrepend(style: string, prep?: string): { 'style': string; 'prep': string; }; /** * --- 根据后缀、文件名或路径获取 mime 类型(简单版,完整版请使用 @litert/mime.js) --- * @param path 后缀、文件名或路径 */ export declare function getMimeByPath(path: string): { 'mime': string; 'ext': string; }; /** * --- 生成范围内的随机数 --- * @param min >= 最小值 * @param max <= 最大值 * @param prec 保留几位小数 */ export declare function rand(min: number, max: number, prec?: number): number; export declare const RANDOM_N = "0123456789"; export declare const RANDOM_U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; export declare const RANDOM_L = "abcdefghijklmnopqrstuvwxyz"; export declare const RANDOM_UN: string; export declare const RANDOM_LN: string; export declare const RANDOM_LU: string; export declare const RANDOM_LUN: string; export declare const RANDOM_V = "ACEFGHJKLMNPRSTWXY34567"; export declare const RANDOM_LUNS: string; /** * --- 生成随机字符串 --- * @param length 长度 * @param source 字符源 * @param block 剔除字符 * @returns 随机字符串 */ export declare function random(length?: number, source?: string, block?: string): string; /** * --- 根据参数获取最终的布尔值 --- * @param param 参数 */ export declare function getBoolean(param: boolean | string | number | undefined): boolean; /** * --- 根据参数获取最终的数字型 --- * @param param 参数 */ export declare function getNumber(param: string | number): number; /** * --- 根据参数获取最终的数组型,可传入类似 [1,2,3] 或 1,2,3 --- * @param param 参数 */ export declare function getArray(param: string | any[]): any[]; /** * --- 转义 HTML --- * @param html HTML 字符 */ export declare function escapeHTML(html: string): string; /** * --- 还原转义后的 HTML --- * @param html 已转义的 HTML 字符 */ export declare function unescapeHTML(html: string): string; /** * --- 将 rgb 或 hsl 等颜色转换为数字数组 --- * @param color 颜色字符串 */ export declare function formatColor(color: string): number[]; /** * --- 将 r, g, b 转换为 hex 字符串,不含 # --- * @param r r 或 rgb 用 , 分隔的字符串 * @param g 可留空,g * @param b 可留空,b */ export declare function rgb2hex(r: string | number, g?: string | number, b?: string | number, a?: string | number): string; /** * --- hex 转换为 rgba,#27ae60ff, 27ae60 #fff * @param hex hex 字符串,无所谓带不带 # */ export declare function hex2rgb(hex: string): { 'r': number; 'g': number; 'b': number; 'a': number; 'rgb': string; }; /** * --- rgb 字符串转 hsl 数组 --- * @param r r 值或 rgb(x, x, x) 或直接 x,x,x * @param g g 值 * @param b b 值 * @param a a 值 * @param decimal 是否保留小数 */ export declare function rgb2hsl(r: string | number, g?: string | number, b?: string | number, a?: string | number, decimal?: boolean): { 'h': number; 's': number; 'l': number; 'a': number; 'hsl': string; }; /** * --- hsl 字符串转 rgb 数组 --- * @param h h 值或 hsl(x, x, x) 或直接 x,x,x * @param s s 值 * @param l l 值 * @param a a 值 * @param decimal 是否保留小数 */ export declare function hsl2rgb(h: string | number, s?: string | number, l?: string | number, a?: string | number, decimal?: boolean): { 'r': number; 'g': number; 'b': number; 'a': number; 'rgb': string; }; /** * --- 发起一个网络请求,若是返回值是 JSON 则自动解析,否则直接返回字符串 --- * @param url 网址 * @param opt 选项 */ export declare function request(url: string, opt: IRequestOptions): Promise; /** * --- 发起 fetch 请求 --- * @param url 网址 * @param init 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function fetch(url: string, init?: RequestInit): Promise; /** * --- 发起 GET 请求 --- * @param url 网址 * @param init 选项 * @param opt 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function get(url: string, init?: RequestInit, opt?: { /** --- 重试次数,默认 3 次 --- */ 'retry'?: number; }): Promise; /** * --- 发起 POST 请求(除 FormData 外都会转换为 JSON 提交) --- * @param url 网址 * @param data 数据 * @param init 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function post(url: string, data: Record | FormData, init?: RequestInit): Promise; /** * --- 发起 GET 请求并解析 JSON 响应 --- * @param url 网址 * @param init 选项 * @returns JSON 数据,失败时返回 null */ export declare function getResponseJson(url: string, init?: RequestInit): Promise; /** * --- 发起 JSON 请求并获得文本 SSE 响应 --- * @param url 网址 * @param data 数据 * @param opts 选项 * @returns 返回可随时中止的控制器 */ export declare function postResponseEventStream(url: string, data: Record, opts?: { 'init'?: RequestInit; /** --- 连接成功建立的回调 --- */ onStart?: () => void | Promise; /** --- 初始化回调(不一定会有) --- */ onInit?: (data: { /** --- chat uid --- */ 'uid': string; /** --- chat name --- */ 'name': string; }) => void | Promise; /** --- 来数据了 --- */ onData?: (chunk: string) => void | Promise; /** --- 结束事件回调,主动结束、错误也会回调 --- */ onEnd?: () => void | Promise; /** --- 连接失败(onStart 前调用) --- */ onTimeout?: () => void | Promise; }): AbortController; /** * --- 发起 POST 请求并解析 JSON 响应 --- * @param url 网址 * @param data 数据 * @param init 选项 * @returns JSON 数据,失败时返回 null */ export declare function postResponseJson(url: string, data: Record | FormData, init?: RequestInit): Promise; /** * --- 传输 url 并解析为 IUrl 对象 --- * @param url url 字符串 */ export declare function parseUrl(url: string): IUrl; /** * --- 将相对路径根据基准路径进行转换 --- * @param from 基准路径 * @param to 相对路径 */ export declare function urlResolve(from: string, to: string): string; /** --- 处理 URL 中的 .. / . 等 --- */ export declare function urlAtom(url: string): string; /** * --- 将 blob 对象转换为 text --- * @param blob 对象 */ export declare function blob2Text(blob: Blob): Promise; /** * --- 将 blob 对象转换为 base64 url --- * @param blob 对象 */ export declare function blob2DataUrl(blob: Blob): Promise; export declare function execCommand(ac: string): void; /** * ---- 对比老值和新值,看看新值中哪些移除了,哪些新增了 --- * @param before 老值 * @param after 新值 */ export declare function compar(before: Array, after: Array): { 'remove': Record; 'add': Record; 'length': { 'remove': number; 'add': number; }; }; /** --- 将秒数格式化为 0:0:0 的字符串 --- */ export declare function formatSecond(second: number): string; /** * --- 将日期对象或毫秒级时间戳转换为字符串 --- * @param ts 时间戳或日期对象 * @param tz 传入要显示的时区,小时,如 8,默认以当前客户端时区为准 */ export declare function formatTime(ts: number | Date, tz?: number): { 'date': string; 'time': string; 'zone': string; }; /** * --- 是否是毫秒 --- * @param time 要判断的时间戳 */ export declare function isMs(time: number): boolean; /** * --- 将对象转换为 query string --- * @param query 要转换的对象 * @param encode 是否转义 */ export declare function queryStringify(query: Record, encode?: boolean): string; /** * --- 将 query string 转换为对象 --- * @param query 要转换的字符串 */ export declare function queryParse(query: string): Record; /** * --- 转义字符检查 --- * 检查指定位置的字符是否被转义 * @param str 字符串 * @param pos 检查位置 * @returns 是否被转义 */ export declare function isEscaped(str: string, pos: number): boolean; /** * --- 数组字符串解析器 --- * 解析数组字符串为各元素组成的字符串数组 * @param arrayStr 数组字符串 * @returns 解析后的字符串数组 */ export declare function parseArrayString(arrayStr: string): string[]; /** * --- 判断字符是否是转义字符 --- * @param code 字符串 * @param index 字符在字符串中的位置 * @returns 是否是转义字符 */ export declare function isEscapeChar(code: string, index: number): boolean; /** --- 状态机状态 --- */ export declare enum ESTATE { /** --- 普通 --- */ 'NORMAL' = 0, /** --- 单词 --- */ 'WORD' = 1, /** --- 字符串 --- */ 'STRING' = 2, /** --- 正则 --- */ 'REG' = 3, /** --- 注释 --- */ 'COMMENT' = 4 } /** * --- 状态机 --- * @param code 代码 * @param start 开始位置 * @param process 处理函数 * @returns 是否继续 */ export declare function stateMachine(code: string, start: number, process: (event: { 'state': ESTATE; 'start': number; 'end': number; 'word': string; 'pre': { 'state': ESTATE; 'word': string; 'nonnull': string; }; 'bracket': { 's': number; 'm': number; 'l': number; }; }) => boolean): void; /** * --- 加载脚本 --- * @param url 脚本网址 */ export declare function loadScript(url: string): Promise; /** * --- 批量加载 js 文件 --- * @param urls js 文件列表 * @param opt 选项 */ export declare function loadScripts(urls: string[], opt?: { loaded?: (url: string, state: number) => void; }): Promise; /** * --- 加载 css 文件 --- * @param url css 文件网址 * @returns 加载是否成功 */ export declare function loadLink(url: string, pos?: 'before' | 'after'): Promise; /** * --- 批量加载 css 文件 --- * @param urls css 文件列表 * @param opt 选项 */ export declare function loadLinks(urls: string[], opt?: { loaded?: (url: string, state: number) => void; }): Promise; /** * --- 加载 css 字符串 --- * @param style css 字符串 */ export declare function loadStyle(style: string): void; /** * --- 判断一个值是否是虚假的(为 null/undefined/空字符串/false/0) --- * @param val 要判断的值 */ export declare function isFalsy(val: any): val is TFalsy; /** * --- 判断一个值是否是真实的(不为 null/undefined/空字符串/false/0) --- * @param val 要判断的值 */ export declare function isTruthy(val: any): val is Exclude; /** * --- 类似 || 运算符的效果 --- * @param v1 比对值 * @param v2 比对值 */ export declare function logicalOr(v1: T, v2: T2): [T] extends [TFalsy] ? T2 : T; /** --- 语言相关 --- */ export declare const lang: { /** --- 语言代号 --- */ 'codes': string[]; /** --- 语言名称 --- */ 'names': string[]; /** --- 浏览器常用映射为本语言 --- */ 'map': Record; /** * --- 根据常用语言字符串获取语言 code --- * @param accept 常用字符串,如 zh-cn,或包含 zh-cn 的字符串,默认取浏览器的语言 */ getCodeByAccept: (accept?: string) => string; }; /** --- 网址对象 --- */ export interface IUrl { 'auth': string | null; 'hash': string | null; 'host': string | null; 'hostname': string | null; 'pass': string | null; 'path': string | null; 'pathname': string; 'protocol': string | null; 'port': string | null; 'query': string | null; 'user': string | null; } /** --- 请求选项 --- */ export interface IRequestOptions { 'credentials'?: boolean; 'method'?: 'GET' | 'POST'; 'body'?: FormData; 'timeout'?: number; 'responseType'?: XMLHttpRequestResponseType; 'headers'?: HeadersInit; 'uploadStart'?: (total: number) => void | Promise; 'uploadProgress'?: (loaded: number, total: number) => void | Promise; 'uploadEnd'?: () => void | Promise; 'start'?: (total: number) => void | Promise; 'end'?: () => void | Promise; 'progress'?: (loaded: number, total: number) => void | Promise; 'load'?: (res: any) => void | Promise; 'error'?: () => void | Promise; } /** --- 虚假值类型 --- */ export type TFalsy = false | '' | 0 | null | undefined | typeof NaN;