interface TagElementMap {
img: HTMLImageElement;
script: HTMLScriptElement;
link: HTMLLinkElement;
}
interface IOptions {
/**
* 标签类型
* @type 'img' | 'script' | 'link'
*/
tag: T;
/**
* 标签属性
*/
attributes?: Record;
/**
* 是否异步加载
* @default false
* @see https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/script#attr-async
*/
async?: boolean;
/**
* 是否延迟加载
* @default false
* @see https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/script#attr-defer
*/
defer?: boolean;
/**
* 加载超时时间
* @default 0
*/
timeout?: number;
/**
* 加载成功回调
*/
onload?: (el: TagElementMap[T], clean: () => void, event?: Event) => void;
/**
* 加载失败回调
*/
onerror?: (el: TagElementMap[T], err?: Error) => void;
/**
* 是否检查资源是否存在
* @default true
*/
checkExist?: boolean;
/**
* 插入到指定元素中
*/
appendTo?: HTMLElement;
}
/**
* 加载资源文件
* 1. 支持 img, link, script 文件标签
* 2. 检测已存在情况
* @param {string} url 资源Url
* @param {IOptions} options 配置项
* @returns
*/
declare function loadResource(url: string, options?: T | IOptions): {
element: TagElementMap[T];
clean: () => void;
} | undefined;
export { loadResource as default };