import './prototype.browser.js';
import './platform.browser.js';
import { delay } from './utils.common.js';
export * from './utils.common.js';
export async function pause(milliseconds = 3000) {
    await delay(milliseconds);
    debugger;
}
globalThis.pause = pause;
/** 表单 Form.Item 必填 `<Form.Item {...required}>` */
export const required = { required: true, rules: [{ required: true }] };
/** 切换所有已选择的 items 中是否包含当前 item */
export function switch_selecteds(selecteds, item) {
    return selecteds.includes(item) ?
        selecteds.filter(s => s !== item)
        :
            [...selecteds, item];
}
export function apply_css(css) {
    let $style = document.createElement('style');
    $style.appendChild(document.createTextNode(css));
    document.head.appendChild($style);
}
export function to_option(value) {
    return { label: value, value };
}
export function download_url(name, url) {
    // 创建一个隐藏的 <a> 元素
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;
    a.download = name;
    // 将 <a> 元素添加到 DOM 中
    document.body.appendChild(a);
    // 触发下载
    a.click();
    // 下载完成后移除 <a> 元素和 URL 对象
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
}
export function download(name, data, mime_type) {
    download_url(name, URL.createObjectURL(new Blob([data], { type: mime_type })));
}
export async function load_script(url, type) {
    return new Promise((resolve, reject) => {
        let $script = document.createElement('script');
        $script.src = url;
        $script.async = true;
        $script.onload = resolve;
        $script.onerror = reject;
        if (type)
            $script.type = type;
        document.head.appendChild($script);
    });
}
//# sourceMappingURL=utils.browser.js.map