UNPKG

tav-ui

Version:
1,832 lines (1,798 loc) 12.6 MB
/*! Castianta Vue Admin UI v0.0.0 */ import { defineComponent, computed, openBlock, createElementBlock, normalizeClass, normalizeStyle, createElementVNode, ref, watch, onMounted, unref, nextTick as nextTick$2, resolveComponent, createBlock, createVNode, h as h$2, Comment as Comment$7, Fragment, Text as Text$2, isVNode, reactive, getCurrentInstance, onUpdated, onUnmounted, inject, provide, Transition, Teleport, TransitionGroup, render as render$2, watchEffect, onBeforeUnmount, withDirectives, resolveDirective, cloneVNode, toRef, withModifiers, vShow, onBeforeMount, createTextVNode, isRef, toRefs, shallowRef, toRaw, onActivated, onDeactivated, useAttrs as useAttrs$1, onBeforeUpdate, getCurrentScope, onScopeDispose, camelize as camelize$2, renderSlot, createApp, createCommentVNode, normalizeProps, guardReactiveProps, mergeProps, defineAsyncComponent, withCtx, readonly, renderList, toDisplayString, toHandlers, resolveDynamicComponent, createSlots, useSlots, withKeys } from 'vue'; function _mergeNamespaces(n, m) { m.forEach(function (e) { e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) { if (k !== 'default' && !(k in n)) { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); }); return Object.freeze(n); } const withInstall$1 = (comp) => { comp.install = function(app) { app.component(comp.name, comp); }; return comp; }; /** * (c) Iconify * * For the full copyright and license information, please view the license.txt or license.gpl.txt * files at https://github.com/iconify/iconify * * Licensed under Apache 2.0 or GPL 2.0 at your option. * If derivative product is not compatible with one of licenses, you can pick one of licenses. * * @license Apache 2.0 * @license GPL 2.0 * @version 2.2.1 */ const matchName = /^[a-z0-9]+(-[a-z0-9]+)*$/; const iconDefaults = Object.freeze({ left: 0, top: 0, width: 16, height: 16, rotate: 0, vFlip: false, hFlip: false }); function fullIcon(data) { return { ...iconDefaults, ...data }; } function mergeIconData(icon, alias) { const result = { ...icon }; for (const key in iconDefaults) { const prop = key; if (alias[prop] !== void 0) { const value = alias[prop]; if (result[prop] === void 0) { result[prop] = value; continue; } switch (prop) { case "rotate": result[prop] = (result[prop] + value) % 4; break; case "hFlip": case "vFlip": result[prop] = value !== result[prop]; break; default: result[prop] = value; } } } return result; } function getIconData$1(data, name, full = false) { function getIcon(name2, iteration) { if (data.icons[name2] !== void 0) { return Object.assign({}, data.icons[name2]); } if (iteration > 5) { return null; } const aliases = data.aliases; if (aliases && aliases[name2] !== void 0) { const item = aliases[name2]; const result2 = getIcon(item.parent, iteration + 1); if (result2) { return mergeIconData(result2, item); } return result2; } const chars = data.chars; if (!iteration && chars && chars[name2] !== void 0) { return getIcon(chars[name2], iteration + 1); } return null; } const result = getIcon(name, 0); if (result) { for (const key in iconDefaults) { if (result[key] === void 0 && data[key] !== void 0) { result[key] = data[key]; } } } return result && full ? fullIcon(result) : result; } function isVariation(item) { for (const key in iconDefaults) { if (item[key] !== void 0) { return true; } } return false; } function parseIconSet(data, callback, options) { options = options || {}; const names = []; if (typeof data !== "object" || typeof data.icons !== "object") { return names; } if (data.not_found instanceof Array) { data.not_found.forEach((name) => { callback(name, null); names.push(name); }); } const icons = data.icons; Object.keys(icons).forEach((name) => { const iconData = getIconData$1(data, name, true); if (iconData) { callback(name, iconData); names.push(name); } }); const parseAliases = options.aliases || "all"; if (parseAliases !== "none" && typeof data.aliases === "object") { const aliases = data.aliases; Object.keys(aliases).forEach((name) => { if (parseAliases === "variations" && isVariation(aliases[name])) { return; } const iconData = getIconData$1(data, name, true); if (iconData) { callback(name, iconData); names.push(name); } }); } return names; } const optionalProperties = { provider: "string", aliases: "object", not_found: "object" }; for (const prop in iconDefaults) { optionalProperties[prop] = typeof iconDefaults[prop]; } function quicklyValidateIconSet(obj) { if (typeof obj !== "object" || obj === null) { return null; } const data = obj; if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") { return null; } for (const prop in optionalProperties) { if (obj[prop] !== void 0 && typeof obj[prop] !== optionalProperties[prop]) { return null; } } const icons = data.icons; for (const name in icons) { const icon = icons[name]; if (!name.match(matchName) || typeof icon.body !== "string") { return null; } for (const prop in iconDefaults) { if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) { return null; } } } const aliases = data.aliases; if (aliases) { for (const name in aliases) { const icon = aliases[name]; const parent = icon.parent; if (!name.match(matchName) || typeof parent !== "string" || !icons[parent] && !aliases[parent]) { return null; } for (const prop in iconDefaults) { if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) { return null; } } } } return data; } const stringToIcon = (value, validate, allowSimpleName, provider = "") => { const colonSeparated = value.split(":"); if (value.slice(0, 1) === "@") { if (colonSeparated.length < 2 || colonSeparated.length > 3) { return null; } provider = colonSeparated.shift().slice(1); } if (colonSeparated.length > 3 || !colonSeparated.length) { return null; } if (colonSeparated.length > 1) { const name2 = colonSeparated.pop(); const prefix = colonSeparated.pop(); const result = { provider: colonSeparated.length > 0 ? colonSeparated[0] : provider, prefix, name: name2 }; return validate && !validateIcon(result) ? null : result; } const name = colonSeparated[0]; const dashSeparated = name.split("-"); if (dashSeparated.length > 1) { const result = { provider, prefix: dashSeparated.shift(), name: dashSeparated.join("-") }; return validate && !validateIcon(result) ? null : result; } if (allowSimpleName && provider === "") { const result = { provider, prefix: "", name }; return validate && !validateIcon(result, allowSimpleName) ? null : result; } return null; }; const validateIcon = (icon, allowSimpleName) => { if (!icon) { return false; } return !!((icon.provider === "" || icon.provider.match(matchName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchName)) && icon.name.match(matchName)); }; const storageVersion = 1; let storage$1 = /* @__PURE__ */ Object.create(null); try { const w = window || self; if (w && w._iconifyStorage.version === storageVersion) { storage$1 = w._iconifyStorage.storage; } } catch (err) { } function shareStorage() { try { const w = window || self; if (w && !w._iconifyStorage) { w._iconifyStorage = { version: storageVersion, storage: storage$1 }; } } catch (err) { } } function newStorage(provider, prefix) { return { provider, prefix, icons: /* @__PURE__ */ Object.create(null), missing: /* @__PURE__ */ Object.create(null) }; } function getStorage(provider, prefix) { if (storage$1[provider] === void 0) { storage$1[provider] = /* @__PURE__ */ Object.create(null); } const providerStorage = storage$1[provider]; if (providerStorage[prefix] === void 0) { providerStorage[prefix] = newStorage(provider, prefix); } return providerStorage[prefix]; } function addIconSet(storage2, data) { if (!quicklyValidateIconSet(data)) { return []; } const t = Date.now(); return parseIconSet(data, (name, icon) => { if (icon) { storage2.icons[name] = icon; } else { storage2.missing[name] = t; } }); } function addIconToStorage(storage2, name, icon) { try { if (typeof icon.body === "string") { storage2.icons[name] = Object.freeze(fullIcon(icon)); return true; } } catch (err) { } return false; } function getIconFromStorage(storage2, name) { const value = storage2.icons[name]; return value === void 0 ? null : value; } function listIcons(provider, prefix) { let allIcons = []; let providers; if (typeof provider === "string") { providers = [provider]; } else { providers = Object.keys(storage$1); } providers.forEach((provider2) => { let prefixes; if (typeof provider2 === "string" && typeof prefix === "string") { prefixes = [prefix]; } else { prefixes = storage$1[provider2] === void 0 ? [] : Object.keys(storage$1[provider2]); } prefixes.forEach((prefix2) => { const storage2 = getStorage(provider2, prefix2); const icons = Object.keys(storage2.icons).map((name) => (provider2 !== "" ? "@" + provider2 + ":" : "") + prefix2 + ":" + name); allIcons = allIcons.concat(icons); }); }); return allIcons; } let simpleNames = false; function allowSimpleNames(allow) { if (typeof allow === "boolean") { simpleNames = allow; } return simpleNames; } function getIconData(name) { const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name; return icon ? getIconFromStorage(getStorage(icon.provider, icon.prefix), icon.name) : null; } function addIcon(name, data) { const icon = stringToIcon(name, true, simpleNames); if (!icon) { return false; } const storage = getStorage(icon.provider, icon.prefix); return addIconToStorage(storage, icon.name, data); } function addCollection(data, provider) { if (typeof data !== "object") { return false; } if (typeof provider !== "string") { provider = typeof data.provider === "string" ? data.provider : ""; } if (simpleNames && provider === "" && (typeof data.prefix !== "string" || data.prefix === "")) { let added = false; if (quicklyValidateIconSet(data)) { data.prefix = ""; parseIconSet(data, (name, icon) => { if (icon && addIcon(name, icon)) { added = true; } }); } return added; } if (typeof data.prefix !== "string" || !validateIcon({ provider, prefix: data.prefix, name: "a" })) { return false; } const storage = getStorage(provider, data.prefix); return !!addIconSet(storage, data); } function iconExists(name) { return getIconData(name) !== null; } function getIcon$2(name) { const result = getIconData(name); return result ? { ...result } : null; } const defaults$8 = Object.freeze({ inline: false, width: null, height: null, hAlign: "center", vAlign: "middle", slice: false, hFlip: false, vFlip: false, rotate: 0 }); function mergeCustomisations(defaults2, item) { const result = {}; for (const key in defaults2) { const attr = key; result[attr] = defaults2[attr]; if (item[attr] === void 0) { continue; } const value = item[attr]; switch (attr) { case "inline": case "slice": if (typeof value === "boolean") { result[attr] = value; } break; case "hFlip": case "vFlip": if (value === true) { result[attr] = !result[attr]; } break; case "hAlign": case "vAlign": if (typeof value === "string" && value !== "") { result[attr] = value; } break; case "width": case "height": if (typeof value === "string" && value !== "" || typeof value === "number" && value || value === null) { result[attr] = value; } break; case "rotate": if (typeof value === "number") { result[attr] += value; } break; } } return result; } const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g; const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g; function calculateSize(size, ratio, precision) { if (ratio === 1) { return size; } precision = precision === void 0 ? 100 : precision; if (typeof size === "number") { return Math.ceil(size * ratio * precision) / precision; } if (typeof size !== "string") { return size; } const oldParts = size.split(unitsSplit); if (oldParts === null || !oldParts.length) { return size; } const newParts = []; let code = oldParts.shift(); let isNumber = unitsTest.test(code); while (true) { if (isNumber) { const num = parseFloat(code); if (isNaN(num)) { newParts.push(code); } else { newParts.push(Math.ceil(num * ratio * precision) / precision); } } else { newParts.push(code); } code = oldParts.shift(); if (code === void 0) { return newParts.join(""); } isNumber = !isNumber; } } function preserveAspectRatio(props) { let result = ""; switch (props.hAlign) { case "left": result += "xMin"; break; case "right": result += "xMax"; break; default: result += "xMid"; } switch (props.vAlign) { case "top": result += "YMin"; break; case "bottom": result += "YMax"; break; default: result += "YMid"; } result += props.slice ? " slice" : " meet"; return result; } function iconToSVG(icon, customisations) { const box = { left: icon.left, top: icon.top, width: icon.width, height: icon.height }; let body = icon.body; [icon, customisations].forEach((props) => { const transformations = []; const hFlip = props.hFlip; const vFlip = props.vFlip; let rotation = props.rotate; if (hFlip) { if (vFlip) { rotation += 2; } else { transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")"); transformations.push("scale(-1 1)"); box.top = box.left = 0; } } else if (vFlip) { transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")"); transformations.push("scale(1 -1)"); box.top = box.left = 0; } let tempValue; if (rotation < 0) { rotation -= Math.floor(rotation / 4) * 4; } rotation = rotation % 4; switch (rotation) { case 1: tempValue = box.height / 2 + box.top; transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")"); break; case 2: transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")"); break; case 3: tempValue = box.width / 2 + box.left; transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")"); break; } if (rotation % 2 === 1) { if (box.left !== 0 || box.top !== 0) { tempValue = box.left; box.left = box.top; box.top = tempValue; } if (box.width !== box.height) { tempValue = box.width; box.width = box.height; box.height = tempValue; } } if (transformations.length) { body = '<g transform="' + transformations.join(" ") + '">' + body + "</g>"; } }); let width, height; if (customisations.width === null && customisations.height === null) { height = "1em"; width = calculateSize(height, box.width / box.height); } else if (customisations.width !== null && customisations.height !== null) { width = customisations.width; height = customisations.height; } else if (customisations.height !== null) { height = customisations.height; width = calculateSize(height, box.width / box.height); } else { width = customisations.width; height = calculateSize(width, box.height / box.width); } if (width === "auto") { width = box.width; } if (height === "auto") { height = box.height; } width = typeof width === "string" ? width : width.toString() + ""; height = typeof height === "string" ? height : height.toString() + ""; const result = { attributes: { width, height, preserveAspectRatio: preserveAspectRatio(customisations), viewBox: box.left.toString() + " " + box.top.toString() + " " + box.width.toString() + " " + box.height.toString() }, body }; if (customisations.inline) { result.inline = true; } return result; } function buildIcon(icon, customisations) { return iconToSVG(fullIcon(icon), customisations ? mergeCustomisations(defaults$8, customisations) : defaults$8); } const regex$2 = /\sid="(\S+)"/g; const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16); let counter = 0; function replaceIDs(body, prefix = randomPrefix) { const ids = []; let match; while (match = regex$2.exec(body)) { ids.push(match[1]); } if (!ids.length) { return body; } ids.forEach((id) => { const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString(); const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); body = body.replace(new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"), "$1" + newID + "$3"); }); return body; } const cacheVersion = "iconify2"; const cachePrefix = "iconify"; const countKey = cachePrefix + "-count"; const versionKey = cachePrefix + "-version"; const hour = 36e5; const cacheExpiration = 168; const config$2 = { local: true, session: true }; let loaded = false; const count = { local: 0, session: 0 }; const emptyList = { local: [], session: [] }; let _window$1 = typeof window === "undefined" ? {} : window; function getGlobal$1(key) { const attr = key + "Storage"; try { if (_window$1 && _window$1[attr] && typeof _window$1[attr].length === "number") { return _window$1[attr]; } } catch (err) { } config$2[key] = false; return null; } function setCount(storage, key, value) { try { storage.setItem(countKey, value.toString()); count[key] = value; return true; } catch (err) { return false; } } function getCount(storage) { const count2 = storage.getItem(countKey); if (count2) { const total = parseInt(count2); return total ? total : 0; } return 0; } function initCache(storage, key) { try { storage.setItem(versionKey, cacheVersion); } catch (err) { } setCount(storage, key, 0); } function destroyCache(storage) { try { const total = getCount(storage); for (let i = 0; i < total; i++) { storage.removeItem(cachePrefix + i.toString()); } } catch (err) { } } const loadCache = () => { if (loaded) { return; } loaded = true; const minTime = Math.floor(Date.now() / hour) - cacheExpiration; function load(key) { const func = getGlobal$1(key); if (!func) { return; } const getItem = (index) => { const name = cachePrefix + index.toString(); const item = func.getItem(name); if (typeof item !== "string") { return false; } let valid = true; try { const data = JSON.parse(item); if (typeof data !== "object" || typeof data.cached !== "number" || data.cached < minTime || typeof data.provider !== "string" || typeof data.data !== "object" || typeof data.data.prefix !== "string") { valid = false; } else { const provider = data.provider; const prefix = data.data.prefix; const storage = getStorage(provider, prefix); valid = addIconSet(storage, data.data).length > 0; } } catch (err) { valid = false; } if (!valid) { func.removeItem(name); } return valid; }; try { const version = func.getItem(versionKey); if (version !== cacheVersion) { if (version) { destroyCache(func); } initCache(func, key); return; } let total = getCount(func); for (let i = total - 1; i >= 0; i--) { if (!getItem(i)) { if (i === total - 1) { total--; } else { emptyList[key].push(i); } } } setCount(func, key, total); } catch (err) { } } for (const key in config$2) { load(key); } }; const storeCache = (provider, data) => { if (!loaded) { loadCache(); } function store(key) { if (!config$2[key]) { return false; } const func = getGlobal$1(key); if (!func) { return false; } let index = emptyList[key].shift(); if (index === void 0) { index = count[key]; if (!setCount(func, key, index + 1)) { return false; } } try { const item = { cached: Math.floor(Date.now() / hour), provider, data }; func.setItem(cachePrefix + index.toString(), JSON.stringify(item)); } catch (err) { return false; } return true; } if (!Object.keys(data.icons).length) { return; } if (data.not_found) { data = Object.assign({}, data); delete data.not_found; } if (!store("local")) { store("session"); } }; const cache = {}; function toggleBrowserCache(storage, value) { switch (storage) { case "local": case "session": config$2[storage] = value; break; case "all": for (const key in config$2) { config$2[key] = value; } break; } } const storage = /* @__PURE__ */ Object.create(null); function setAPIModule(provider, item) { storage[provider] = item; } function getAPIModule(provider) { return storage[provider] || storage[""]; } function createAPIConfig(source) { let resources; if (typeof source.resources === "string") { resources = [source.resources]; } else { resources = source.resources; if (!(resources instanceof Array) || !resources.length) { return null; } } const result = { resources, path: source.path === void 0 ? "/" : source.path, maxURL: source.maxURL ? source.maxURL : 500, rotate: source.rotate ? source.rotate : 750, timeout: source.timeout ? source.timeout : 5e3, random: source.random === true, index: source.index ? source.index : 0, dataAfterTimeout: source.dataAfterTimeout !== false }; return result; } const configStorage = /* @__PURE__ */ Object.create(null); const fallBackAPISources = [ "https://api.simplesvg.com", "https://api.unisvg.com" ]; const fallBackAPI = []; while (fallBackAPISources.length > 0) { if (fallBackAPISources.length === 1) { fallBackAPI.push(fallBackAPISources.shift()); } else { if (Math.random() > 0.5) { fallBackAPI.push(fallBackAPISources.shift()); } else { fallBackAPI.push(fallBackAPISources.pop()); } } } configStorage[""] = createAPIConfig({ resources: ["https://api.iconify.design"].concat(fallBackAPI) }); function addAPIProvider(provider, customConfig) { const config = createAPIConfig(customConfig); if (config === null) { return false; } configStorage[provider] = config; return true; } function getAPIConfig(provider) { return configStorage[provider]; } function listAPIProviders() { return Object.keys(configStorage); } const mergeParams = (base, params) => { let result = base, hasParams = result.indexOf("?") !== -1; function paramToString(value) { switch (typeof value) { case "boolean": return value ? "true" : "false"; case "number": return encodeURIComponent(value); case "string": return encodeURIComponent(value); default: throw new Error("Invalid parameter"); } } Object.keys(params).forEach((key) => { let value; try { value = paramToString(params[key]); } catch (err) { return; } result += (hasParams ? "&" : "?") + encodeURIComponent(key) + "=" + value; hasParams = true; }); return result; }; const maxLengthCache = {}; const pathCache = {}; const detectFetch = () => { let callback; try { callback = fetch; if (typeof callback === "function") { return callback; } } catch (err) { } return null; }; let fetchModule = detectFetch(); function setFetch(fetch2) { fetchModule = fetch2; } function getFetch() { return fetchModule; } function calculateMaxLength(provider, prefix) { const config = getAPIConfig(provider); if (!config) { return 0; } let result; if (!config.maxURL) { result = 0; } else { let maxHostLength = 0; config.resources.forEach((item) => { const host = item; maxHostLength = Math.max(maxHostLength, host.length); }); const url = mergeParams(prefix + ".json", { icons: "" }); result = config.maxURL - maxHostLength - config.path.length - url.length; } const cacheKey = provider + ":" + prefix; pathCache[provider] = config.path; maxLengthCache[cacheKey] = result; return result; } function shouldAbort(status) { return status === 404; } const prepare = (provider, prefix, icons) => { const results = []; let maxLength = maxLengthCache[prefix]; if (maxLength === void 0) { maxLength = calculateMaxLength(provider, prefix); } const type = "icons"; let item = { type, provider, prefix, icons: [] }; let length = 0; icons.forEach((name, index) => { length += name.length + 1; if (length >= maxLength && index > 0) { results.push(item); item = { type, provider, prefix, icons: [] }; length = name.length; } item.icons.push(name); }); results.push(item); return results; }; function getPath(provider) { if (typeof provider === "string") { if (pathCache[provider] === void 0) { const config = getAPIConfig(provider); if (!config) { return "/"; } pathCache[provider] = config.path; } return pathCache[provider]; } return "/"; } const send = (host, params, callback) => { if (!fetchModule) { callback("abort", 424); return; } let path = getPath(params.provider); switch (params.type) { case "icons": { const prefix = params.prefix; const icons = params.icons; const iconsList = icons.join(","); path += mergeParams(prefix + ".json", { icons: iconsList }); break; } case "custom": { const uri = params.uri; path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri; break; } default: callback("abort", 400); return; } let defaultError = 503; fetchModule(host + path).then((response) => { const status = response.status; if (status !== 200) { setTimeout(() => { callback(shouldAbort(status) ? "abort" : "next", status); }); return; } defaultError = 501; return response.json(); }).then((data) => { if (typeof data !== "object" || data === null) { setTimeout(() => { callback("next", defaultError); }); return; } setTimeout(() => { callback("success", data); }); }).catch(() => { callback("next", defaultError); }); }; const fetchAPIModule = { prepare, send }; function sortIcons(icons) { const result = { loaded: [], missing: [], pending: [] }; const storage = /* @__PURE__ */ Object.create(null); icons.sort((a, b) => { if (a.provider !== b.provider) { return a.provider.localeCompare(b.provider); } if (a.prefix !== b.prefix) { return a.prefix.localeCompare(b.prefix); } return a.name.localeCompare(b.name); }); let lastIcon = { provider: "", prefix: "", name: "" }; icons.forEach((icon) => { if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) { return; } lastIcon = icon; const provider = icon.provider; const prefix = icon.prefix; const name = icon.name; if (storage[provider] === void 0) { storage[provider] = /* @__PURE__ */ Object.create(null); } const providerStorage = storage[provider]; if (providerStorage[prefix] === void 0) { providerStorage[prefix] = getStorage(provider, prefix); } const localStorage = providerStorage[prefix]; let list; if (localStorage.icons[name] !== void 0) { list = result.loaded; } else if (prefix === "" || localStorage.missing[name] !== void 0) { list = result.missing; } else { list = result.pending; } const item = { provider, prefix, name }; list.push(item); }); return result; } const callbacks = /* @__PURE__ */ Object.create(null); const pendingUpdates = /* @__PURE__ */ Object.create(null); function removeCallback(sources, id) { sources.forEach((source) => { const provider = source.provider; if (callbacks[provider] === void 0) { return; } const providerCallbacks = callbacks[provider]; const prefix = source.prefix; const items = providerCallbacks[prefix]; if (items) { providerCallbacks[prefix] = items.filter((row) => row.id !== id); } }); } function updateCallbacks(provider, prefix) { if (pendingUpdates[provider] === void 0) { pendingUpdates[provider] = /* @__PURE__ */ Object.create(null); } const providerPendingUpdates = pendingUpdates[provider]; if (!providerPendingUpdates[prefix]) { providerPendingUpdates[prefix] = true; setTimeout(() => { providerPendingUpdates[prefix] = false; if (callbacks[provider] === void 0 || callbacks[provider][prefix] === void 0) { return; } const items = callbacks[provider][prefix].slice(0); if (!items.length) { return; } const storage = getStorage(provider, prefix); let hasPending = false; items.forEach((item) => { const icons = item.icons; const oldLength = icons.pending.length; icons.pending = icons.pending.filter((icon) => { if (icon.prefix !== prefix) { return true; } const name = icon.name; if (storage.icons[name] !== void 0) { icons.loaded.push({ provider, prefix, name }); } else if (storage.missing[name] !== void 0) { icons.missing.push({ provider, prefix, name }); } else { hasPending = true; return true; } return false; }); if (icons.pending.length !== oldLength) { if (!hasPending) { removeCallback([ { provider, prefix } ], item.id); } item.callback(icons.loaded.slice(0), icons.missing.slice(0), icons.pending.slice(0), item.abort); } }); }); } } let idCounter$1 = 0; function storeCallback(callback, icons, pendingSources) { const id = idCounter$1++; const abort = removeCallback.bind(null, pendingSources, id); if (!icons.pending.length) { return abort; } const item = { id, icons, callback, abort }; pendingSources.forEach((source) => { const provider = source.provider; const prefix = source.prefix; if (callbacks[provider] === void 0) { callbacks[provider] = /* @__PURE__ */ Object.create(null); } const providerCallbacks = callbacks[provider]; if (providerCallbacks[prefix] === void 0) { providerCallbacks[prefix] = []; } providerCallbacks[prefix].push(item); }); return abort; } function listToIcons(list, validate = true, simpleNames = false) { const result = []; list.forEach((item) => { const icon = typeof item === "string" ? stringToIcon(item, false, simpleNames) : item; if (!validate || validateIcon(icon, simpleNames)) { result.push({ provider: icon.provider, prefix: icon.prefix, name: icon.name }); } }); return result; } // src/config.ts var defaultConfig = { resources: [], index: 0, timeout: 2e3, rotate: 750, random: false, dataAfterTimeout: false }; // src/query.ts function sendQuery(config, payload, query, done) { const resourcesCount = config.resources.length; const startIndex = config.random ? Math.floor(Math.random() * resourcesCount) : config.index; let resources; if (config.random) { let list = config.resources.slice(0); resources = []; while (list.length > 1) { const nextIndex = Math.floor(Math.random() * list.length); resources.push(list[nextIndex]); list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1)); } resources = resources.concat(list); } else { resources = config.resources.slice(startIndex).concat(config.resources.slice(0, startIndex)); } const startTime = Date.now(); let status = "pending"; let queriesSent = 0; let lastError; let timer = null; let queue = []; let doneCallbacks = []; if (typeof done === "function") { doneCallbacks.push(done); } function resetTimer() { if (timer) { clearTimeout(timer); timer = null; } } function abort() { if (status === "pending") { status = "aborted"; } resetTimer(); queue.forEach((item) => { if (item.status === "pending") { item.status = "aborted"; } }); queue = []; } function subscribe(callback, overwrite) { if (overwrite) { doneCallbacks = []; } if (typeof callback === "function") { doneCallbacks.push(callback); } } function getQueryStatus() { return { startTime, payload, status, queriesSent, queriesPending: queue.length, subscribe, abort }; } function failQuery() { status = "failed"; doneCallbacks.forEach((callback) => { callback(void 0, lastError); }); } function clearQueue() { queue.forEach((item) => { if (item.status === "pending") { item.status = "aborted"; } }); queue = []; } function moduleResponse(item, response, data) { const isError = response !== "success"; queue = queue.filter((queued) => queued !== item); switch (status) { case "pending": break; case "failed": if (isError || !config.dataAfterTimeout) { return; } break; default: return; } if (response === "abort") { lastError = data; failQuery(); return; } if (isError) { lastError = data; if (!queue.length) { if (!resources.length) { failQuery(); } else { execNext(); } } return; } resetTimer(); clearQueue(); if (!config.random) { const index = config.resources.indexOf(item.resource); if (index !== -1 && index !== config.index) { config.index = index; } } status = "completed"; doneCallbacks.forEach((callback) => { callback(data); }); } function execNext() { if (status !== "pending") { return; } resetTimer(); const resource = resources.shift(); if (resource === void 0) { if (queue.length) { timer = setTimeout(() => { resetTimer(); if (status === "pending") { clearQueue(); failQuery(); } }, config.timeout); return; } failQuery(); return; } const item = { status: "pending", resource, callback: (status2, data) => { moduleResponse(item, status2, data); } }; queue.push(item); queriesSent++; timer = setTimeout(execNext, config.rotate); query(resource, payload, item.callback); } setTimeout(execNext); return getQueryStatus; } // src/index.ts function setConfig(config) { if (typeof config !== "object" || typeof config.resources !== "object" || !(config.resources instanceof Array) || !config.resources.length) { throw new Error("Invalid Reduncancy configuration"); } const newConfig = /* @__PURE__ */ Object.create(null); let key; for (key in defaultConfig) { if (config[key] !== void 0) { newConfig[key] = config[key]; } else { newConfig[key] = defaultConfig[key]; } } return newConfig; } function initRedundancy(cfg) { const config = setConfig(cfg); let queries = []; function cleanup() { queries = queries.filter((item) => item().status === "pending"); } function query(payload, queryCallback, doneCallback) { const query2 = sendQuery(config, payload, queryCallback, (data, error) => { cleanup(); if (doneCallback) { doneCallback(data, error); } }); queries.push(query2); return query2; } function find(callback) { const result = queries.find((value) => { return callback(value); }); return result !== void 0 ? result : null; } const instance = { query, find, setIndex: (index) => { config.index = index; }, getIndex: () => config.index, cleanup }; return instance; } function emptyCallback$1() { } const redundancyCache = /* @__PURE__ */ Object.create(null); function getRedundancyCache(provider) { if (redundancyCache[provider] === void 0) { const config = getAPIConfig(provider); if (!config) { return; } const redundancy = initRedundancy(config); const cachedReundancy = { config, redundancy }; redundancyCache[provider] = cachedReundancy; } return redundancyCache[provider]; } function sendAPIQuery(target, query, callback) { let redundancy; let send; if (typeof target === "string") { const api = getAPIModule(target); if (!api) { callback(void 0, 424); return emptyCallback$1; } send = api.send; const cached = getRedundancyCache(target); if (cached) { redundancy = cached.redundancy; } } else { const config = createAPIConfig(target); if (config) { redundancy = initRedundancy(config); const moduleKey = target.resources ? target.resources[0] : ""; const api = getAPIModule(moduleKey); if (api) { send = api.send; } } } if (!redundancy || !send) { callback(void 0, 424); return emptyCallback$1; } return redundancy.query(query, send, callback)().abort; } function emptyCallback() { } const pendingIcons = /* @__PURE__ */ Object.create(null); const iconsToLoad = /* @__PURE__ */ Object.create(null); const loaderFlags = /* @__PURE__ */ Object.create(null); const queueFlags = /* @__PURE__ */ Object.create(null); function loadedNewIcons(provider, prefix) { if (loaderFlags[provider] === void 0) { loaderFlags[provider] = /* @__PURE__ */ Object.create(null); } const providerLoaderFlags = loaderFlags[provider]; if (!providerLoaderFlags[prefix]) { providerLoaderFlags[prefix] = true; setTimeout(() => { providerLoaderFlags[prefix] = false; updateCallbacks(provider, prefix); }); } } const errorsCache = /* @__PURE__ */ Object.create(null); function loadNewIcons(provider, prefix, icons) { function err() { const key = (provider === "" ? "" : "@" + provider + ":") + prefix; const time = Math.floor(Date.now() / 6e4); if (errorsCache[key] < time) { errorsCache[key] = time; console.error('Unable to retrieve icons for "' + key + '" because API is not configured properly.'); } } if (iconsToLoad[provider] === void 0) { iconsToLoad[provider] = /* @__PURE__ */ Object.create(null); } const providerIconsToLoad = iconsToLoad[provider]; if (queueFlags[provider] === void 0) { queueFlags[provider] = /* @__PURE__ */ Object.create(null); } const providerQueueFlags = queueFlags[provider]; if (pendingIcons[provider] === void 0) { pendingIcons[provider] = /* @__PURE__ */ Object.create(null); } const providerPendingIcons = pendingIcons[provider]; if (providerIconsToLoad[prefix] === void 0) { providerIconsToLoad[prefix] = icons; } else { providerIconsToLoad[prefix] = providerIconsToLoad[prefix].concat(icons).sort(); } if (!providerQueueFlags[prefix]) { providerQueueFlags[prefix] = true; setTimeout(() => { providerQueueFlags[prefix] = false; const icons2 = providerIconsToLoad[prefix]; delete providerIconsToLoad[prefix]; const api = getAPIModule(provider); if (!api) { err(); return; } const params = api.prepare(provider, prefix, icons2); params.forEach((item) => { sendAPIQuery(provider, item, (data, error) => { const storage = getStorage(provider, prefix); if (typeof data !== "object") { if (error !== 404) { return; } const t = Date.now(); item.icons.forEach((name) => { storage.missing[name] = t; }); } else { try { const parsed = addIconSet(storage, data); if (!parsed.length) { return; } const pending = providerPendingIcons[prefix]; parsed.forEach((name) => { delete pending[name]; }); if (cache.store) { cache.store(provider, data); } } catch (err2) { console.error(err2); } } loadedNewIcons(provider, prefix); }); }); }); } } const isPending = (icon) => { const provider = icon.provider; const prefix = icon.prefix; return pendingIcons[provider] && pendingIcons[provider][prefix] && pendingIcons[provider][prefix][icon.name] !== void 0; }; const loadIcons = (icons, callback) => { const cleanedIcons = listToIcons(icons, true, allowSimpleNames()); const sortedIcons = sortIcons(cleanedIcons); if (!sortedIcons.pending.length) { let callCallback = true; if (callback) { setTimeout(() => { if (callCallback) { callback(sortedIcons.loaded, sortedIcons.missing, sortedIcons.pending, emptyCallback); } }); } return () => { callCallback = false; }; } const newIcons = /* @__PURE__ */ Object.create(null); const sources = []; let lastProvider, lastPrefix; sortedIcons.pending.forEach((icon) => { const provider = icon.provider; const prefix = icon.prefix; if (prefix === lastPrefix && provider === lastProvider) { return; } lastProvider = provider; lastPrefix = prefix; sources.push({ provider, prefix }); if (pendingIcons[provider] === void 0) { pendingIcons[provider] = /* @__PURE__ */ Object.create(null); } const providerPendingIcons = pendingIcons[provider]; if (providerPendingIcons[prefix] === void 0) { providerPendingIcons[prefix] = /* @__PURE__ */ Object.create(null); } if (newIcons[provider] === void 0) { newIcons[provider] = /* @__PURE__ */ Object.create(null); } const providerNewIcons = newIcons[provider]; if (providerNewIcons[prefix] === void 0) { providerNewIcons[prefix] = []; } }); const time = Date.now(); sortedIcons.pending.forEach((icon) => { const provider = icon.provider; const prefix = icon.prefix; const name = icon.name; const pendingQueue = pendingIcons[provider][prefix]; if (pendingQueue[name] === void 0) { pendingQueue[name] = time; newIcons[provider][prefix].push(name); } }); sources.forEach((source) => { const provider = source.provider; const prefix = source.prefix; if (newIcons[provider][prefix].length) { loadNewIcons(provider, prefix, newIcons[provider][prefix]); } }); return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback; }; const loadIcon = (icon) => { return new Promise((fulfill, reject) => { const iconObj = typeof icon === "string" ? stringToIcon(icon) : icon; loadIcons([iconObj || icon], (loaded) => { if (loaded.length && iconObj) { const storage = getStorage(iconObj.provider, iconObj.prefix); const data = getIconFromStorage(storage, iconObj.name); if (data) { fulfill(data); return; } } reject(icon); }); }); }; /** * Names of properties to add to nodes */ const elementFinderProperty = ('iconifyFinder' + Date.now()); const elementDataProperty = ('iconifyData' + Date.now()); /** * Replace element with SVG */ function renderIconInPlaceholder(placeholder, customisations, iconData, returnString) { // Create placeholder. Why placeholder? IE11 doesn't support innerHTML method on SVG. let span; try { span = document.createElement('span'); } catch (err) { return returnString ? '' : null; } const data = iconToSVG(iconData, mergeCustomisations(defaults$8, customisations)); // Placeholder properties const placeholderElement = placeholder.element; const finder = placeholder.finder; const name = placeholder.name; // Get class name const placeholderClassName = placeholderElement ? placeholderElement.getAttribute('class') : ''; const filteredClassList = finder ? finder.classFilter(placeholderClassName ? placeholderClassName.split(/\s+/) : []) : []; const className = 'iconify iconify--' + name.prefix + (name.provider === '' ? '' : ' iconify--' + name.provider) + (filteredClassList.length ? ' ' + filteredClassList.join(' ') : ''); // Generate SVG as string const html = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="' + className + '">' + replaceIDs(data.body) + '</svg>'; // Set HTML for placeholder span.innerHTML = html; // Get SVG element const svg = span.childNodes[0]; const svgStyle = svg.style; // Add attributes const svgAttributes = data.attributes; Object.keys(svgAttributes).forEach((attr) => { svg.setAttribute(attr, svgAttributes[attr]); }); // Add custom styles if (data.inline) { svgStyle.verticalAlign = '-0.125em'; } // Copy stuff from placeholder if (placeholderElement) { // Copy attributes const placeholderAttributes = placeholderElement.attributes; for (let i = 0; i < placeholderAttributes.length; i++) { const item = placeholderAttributes.item(i); if (item) { const name = item.name; if (name !== 'class' && name !== 'style' && svgAttributes[name] === void 0) { try { svg.setAttribute(name, item.value); } catch (err) { // } } } } // Copy styles const placeholderStyle = placeholderElement.style; for (let i = 0; i < placeholderStyle.length; i++) { const attr = placeholderStyle[i]; svgStyle[attr] = placeholderStyle[attr]; } } // Store finder specific data if (finder) { const elementData = { name: name, status: 'loaded', customisations: customisations, }; svg[elementDataProperty] = elementData; svg[elementFinderProperty] = finder; } // Get result const result = returnString ? span.innerHTML : svg; // Replace placeholder if (placeholderElement && placeholderElement.parentNode) { placeholderElement.parentNode.replaceChild(svg, placeholderElement); } else { // Placeholder has no parent? Remove SVG parent as well span.removeChild(svg); } // Return new node return result; } /** * List of root nodes */ let nodes = []; /** * Find node */ function findRootNode(node) { for (let i = 0; i < nodes.length; i++) { const item = nodes[i]; const root = typeof item.node === 'function' ? item.node() : item.node; if (root === node) { return item; } } } /** * Add extra root node */ function addRootNode(root, autoRemove = false) { let node = findRootNode(root); if (node) { // Node already exist: switch type if needed if (node.temporary) { node.temporary = autoRemove; } return node; } // Create item, add it to list, start observer node = { node: root, temporary: autoRemove, }; nodes.push(node); return node; } /** * Add document.body node */ function