323 lines
11 KiB
JavaScript
323 lines
11 KiB
JavaScript
import { defineComponent, computed, h, ref, shallowRef, toRef, getCurrentInstance, onServerPrefetch, unref } from 'vue';
|
|
import { Icon, loadIcons, getIcon } from '@iconify/vue';
|
|
import { getIconCSS } from '@iconify/utils/lib/css/icon';
|
|
import { b as useNuxtApp, a$ as useAppConfig, c as useRuntimeConfig, aZ as asyncDataDefaults, a_ as createError } from './server.mjs';
|
|
import { u as useHead } from './index-Cnev2rJz.mjs';
|
|
import '../_/nitro.mjs';
|
|
import 'node:http';
|
|
import 'node:https';
|
|
import 'node:fs';
|
|
import 'node:url';
|
|
import '@iconify/utils';
|
|
import 'consola/core';
|
|
import '../routes/renderer.mjs';
|
|
import 'vue-bundle-renderer/runtime';
|
|
import 'devalue';
|
|
import 'vue/server-renderer';
|
|
import '@unhead/ssr';
|
|
import 'unhead';
|
|
import '@unhead/shared';
|
|
import 'vue-router';
|
|
|
|
const isDefer = (dedupe) => dedupe === "defer" || dedupe === false;
|
|
function useAsyncData(...args) {
|
|
var _a2, _b2, _c, _d, _e, _f, _g, _h;
|
|
var _b;
|
|
const autoKey = typeof args[args.length - 1] === "string" ? args.pop() : void 0;
|
|
if (typeof args[0] !== "string") {
|
|
args.unshift(autoKey);
|
|
}
|
|
let [key, _handler, options = {}] = args;
|
|
if (typeof key !== "string") {
|
|
throw new TypeError("[nuxt] [asyncData] key must be a string.");
|
|
}
|
|
if (typeof _handler !== "function") {
|
|
throw new TypeError("[nuxt] [asyncData] handler must be a function.");
|
|
}
|
|
const nuxtApp = useNuxtApp();
|
|
const handler = _handler ;
|
|
const getDefault = () => asyncDataDefaults.value;
|
|
const getDefaultCachedData = () => nuxtApp.isHydrating ? nuxtApp.payload.data[key] : nuxtApp.static.data[key];
|
|
options.server = (_a2 = options.server) != null ? _a2 : true;
|
|
options.default = (_b2 = options.default) != null ? _b2 : getDefault;
|
|
options.getCachedData = (_c = options.getCachedData) != null ? _c : getDefaultCachedData;
|
|
options.lazy = (_d = options.lazy) != null ? _d : false;
|
|
options.immediate = (_e = options.immediate) != null ? _e : true;
|
|
options.deep = (_f = options.deep) != null ? _f : asyncDataDefaults.deep;
|
|
options.dedupe = (_g = options.dedupe) != null ? _g : "cancel";
|
|
const initialCachedData = options.getCachedData(key, nuxtApp);
|
|
const hasCachedData = initialCachedData != null;
|
|
if (!nuxtApp._asyncData[key] || !options.immediate) {
|
|
(_h = (_b = nuxtApp.payload._errors)[key]) != null ? _h : _b[key] = asyncDataDefaults.errorValue;
|
|
const _ref = options.deep ? ref : shallowRef;
|
|
nuxtApp._asyncData[key] = {
|
|
data: _ref(hasCachedData ? initialCachedData : options.default()),
|
|
pending: ref(!hasCachedData),
|
|
error: toRef(nuxtApp.payload._errors, key),
|
|
status: ref("idle"),
|
|
_default: options.default
|
|
};
|
|
}
|
|
const asyncData = { ...nuxtApp._asyncData[key] };
|
|
delete asyncData._default;
|
|
asyncData.refresh = asyncData.execute = (opts = {}) => {
|
|
var _a3;
|
|
if (nuxtApp._asyncDataPromises[key]) {
|
|
if (isDefer((_a3 = opts.dedupe) != null ? _a3 : options.dedupe)) {
|
|
return nuxtApp._asyncDataPromises[key];
|
|
}
|
|
nuxtApp._asyncDataPromises[key].cancelled = true;
|
|
}
|
|
if (opts._initial || nuxtApp.isHydrating && opts._initial !== false) {
|
|
const cachedData = opts._initial ? initialCachedData : options.getCachedData(key, nuxtApp);
|
|
if (cachedData != null) {
|
|
return Promise.resolve(cachedData);
|
|
}
|
|
}
|
|
asyncData.pending.value = true;
|
|
asyncData.status.value = "pending";
|
|
const promise = new Promise(
|
|
(resolve, reject) => {
|
|
try {
|
|
resolve(handler(nuxtApp));
|
|
} catch (err) {
|
|
reject(err);
|
|
}
|
|
}
|
|
).then(async (_result) => {
|
|
if (promise.cancelled) {
|
|
return nuxtApp._asyncDataPromises[key];
|
|
}
|
|
let result = _result;
|
|
if (options.transform) {
|
|
result = await options.transform(_result);
|
|
}
|
|
if (options.pick) {
|
|
result = pick(result, options.pick);
|
|
}
|
|
nuxtApp.payload.data[key] = result;
|
|
asyncData.data.value = result;
|
|
asyncData.error.value = asyncDataDefaults.errorValue;
|
|
asyncData.status.value = "success";
|
|
}).catch((error) => {
|
|
if (promise.cancelled) {
|
|
return nuxtApp._asyncDataPromises[key];
|
|
}
|
|
asyncData.error.value = createError(error);
|
|
asyncData.data.value = unref(options.default());
|
|
asyncData.status.value = "error";
|
|
}).finally(() => {
|
|
if (promise.cancelled) {
|
|
return;
|
|
}
|
|
asyncData.pending.value = false;
|
|
delete nuxtApp._asyncDataPromises[key];
|
|
});
|
|
nuxtApp._asyncDataPromises[key] = promise;
|
|
return nuxtApp._asyncDataPromises[key];
|
|
};
|
|
asyncData.clear = () => clearNuxtDataByKey(nuxtApp, key);
|
|
const initialFetch = () => asyncData.refresh({ _initial: true });
|
|
const fetchOnServer = options.server !== false && nuxtApp.payload.serverRendered;
|
|
if (fetchOnServer && options.immediate) {
|
|
const promise = initialFetch();
|
|
if (getCurrentInstance()) {
|
|
onServerPrefetch(() => promise);
|
|
} else {
|
|
nuxtApp.hook("app:created", async () => {
|
|
await promise;
|
|
});
|
|
}
|
|
}
|
|
const asyncDataPromise = Promise.resolve(nuxtApp._asyncDataPromises[key]).then(() => asyncData);
|
|
Object.assign(asyncDataPromise, asyncData);
|
|
return asyncDataPromise;
|
|
}
|
|
function clearNuxtDataByKey(nuxtApp, key) {
|
|
if (key in nuxtApp.payload.data) {
|
|
nuxtApp.payload.data[key] = void 0;
|
|
}
|
|
if (key in nuxtApp.payload._errors) {
|
|
nuxtApp.payload._errors[key] = asyncDataDefaults.errorValue;
|
|
}
|
|
if (nuxtApp._asyncData[key]) {
|
|
nuxtApp._asyncData[key].data.value = void 0;
|
|
nuxtApp._asyncData[key].error.value = asyncDataDefaults.errorValue;
|
|
nuxtApp._asyncData[key].pending.value = false;
|
|
nuxtApp._asyncData[key].status.value = "idle";
|
|
}
|
|
if (key in nuxtApp._asyncDataPromises) {
|
|
if (nuxtApp._asyncDataPromises[key]) {
|
|
nuxtApp._asyncDataPromises[key].cancelled = true;
|
|
}
|
|
nuxtApp._asyncDataPromises[key] = void 0;
|
|
}
|
|
}
|
|
function pick(obj, keys) {
|
|
const newObj = {};
|
|
for (const key of keys) {
|
|
newObj[key] = obj[key];
|
|
}
|
|
return newObj;
|
|
}
|
|
async function loadIcon(name) {
|
|
await new Promise((resolve) => loadIcons([name], () => resolve(true))).catch(() => null);
|
|
return getIcon(name);
|
|
}
|
|
function useResolvedName(getName) {
|
|
const options = useAppConfig().icon;
|
|
const collections = (options.collections || []).sort((a, b) => b.length - a.length);
|
|
return computed(() => {
|
|
var _a;
|
|
const name = getName();
|
|
const bare = name.startsWith(options.cssSelectorPrefix) ? name.slice(options.cssSelectorPrefix.length) : name;
|
|
const resolved = ((_a = options.aliases) == null ? void 0 : _a[bare]) || bare;
|
|
if (!resolved.includes(":")) {
|
|
const collection = collections.find((c) => resolved.startsWith(c + "-"));
|
|
return collection ? collection + ":" + resolved.slice(collection.length + 1) : resolved;
|
|
}
|
|
return resolved;
|
|
});
|
|
}
|
|
const SYMBOL_SERVER_CSS = "NUXT_ICONS_SERVER_CSS";
|
|
function escapeCssSelector(selector) {
|
|
return selector.replace(/([^\w-])/g, "\\$1");
|
|
}
|
|
const NuxtIconCss = /* @__PURE__ */ defineComponent({
|
|
name: "NuxtIconCss",
|
|
props: {
|
|
name: {
|
|
type: String,
|
|
required: true
|
|
}
|
|
},
|
|
async setup(props) {
|
|
var _a;
|
|
const nuxt = useNuxtApp();
|
|
const options = useAppConfig().icon;
|
|
const cssClass = computed(() => options.cssSelectorPrefix + props.name);
|
|
const selector = computed(() => "." + escapeCssSelector(cssClass.value));
|
|
function getCSS(icon, withLayer = true) {
|
|
let iconSelector = selector.value;
|
|
if (options.cssWherePseudo) {
|
|
iconSelector = `:where(${iconSelector})`;
|
|
}
|
|
const css = getIconCSS(icon, {
|
|
iconSelector,
|
|
format: "compressed"
|
|
});
|
|
if (options.cssLayer && withLayer) {
|
|
return `@layer ${options.cssLayer} { ${css} }`;
|
|
}
|
|
return css;
|
|
}
|
|
{
|
|
const configs = useRuntimeConfig().icon || {};
|
|
if (!((_a = configs == null ? void 0 : configs.serverKnownCssClasses) == null ? void 0 : _a.includes(cssClass.value))) {
|
|
const icon = await loadIcon(props.name);
|
|
if (icon) {
|
|
let ssrCSS = nuxt.vueApp._context.provides[SYMBOL_SERVER_CSS];
|
|
if (!ssrCSS) {
|
|
ssrCSS = nuxt.vueApp._context.provides[SYMBOL_SERVER_CSS] = /* @__PURE__ */ new Map();
|
|
nuxt.runWithContext(() => {
|
|
useHead({
|
|
style: [
|
|
() => {
|
|
const sep = "";
|
|
let css = Array.from(ssrCSS.values()).sort().join(sep);
|
|
if (options.cssLayer) {
|
|
css = `@layer ${options.cssLayer} {${sep}${css}${sep}}`;
|
|
}
|
|
return { innerHTML: css };
|
|
}
|
|
]
|
|
}, {
|
|
tagPriority: "low"
|
|
});
|
|
});
|
|
}
|
|
if (!ssrCSS.has(props.name)) {
|
|
const css = getCSS(icon, false);
|
|
ssrCSS.set(props.name, css);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return () => h("span", { class: ["iconify", cssClass.value, options.class] });
|
|
}
|
|
});
|
|
const NuxtIconSvg = /* @__PURE__ */ defineComponent({
|
|
name: "NuxtIconSvg",
|
|
props: {
|
|
name: {
|
|
type: String,
|
|
required: true
|
|
}
|
|
},
|
|
async setup(props, { slots }) {
|
|
useNuxtApp();
|
|
const options = useAppConfig().icon;
|
|
const name = useResolvedName(() => props.name);
|
|
const storeKey = "i-" + name.value;
|
|
{
|
|
useAsyncData(
|
|
storeKey,
|
|
() => loadIcon(name.value),
|
|
{ deep: false }
|
|
);
|
|
}
|
|
return () => h(Icon, {
|
|
icon: name.value,
|
|
ssr: true,
|
|
class: options.class
|
|
}, slots);
|
|
}
|
|
});
|
|
const index = defineComponent({
|
|
name: "NuxtIcon",
|
|
props: {
|
|
name: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
mode: {
|
|
type: String,
|
|
required: false,
|
|
default: null
|
|
},
|
|
size: {
|
|
type: [Number, String],
|
|
required: false,
|
|
default: null
|
|
}
|
|
},
|
|
async setup(props, { slots }) {
|
|
const nuxtApp = useNuxtApp();
|
|
const options = useAppConfig().icon;
|
|
const name = useResolvedName(() => props.name);
|
|
const component = computed(
|
|
() => {
|
|
var _a;
|
|
return ((_a = nuxtApp.vueApp) == null ? void 0 : _a.component(name.value)) || ((props.mode || options.mode) === "svg" ? NuxtIconSvg : NuxtIconCss);
|
|
}
|
|
);
|
|
const style = computed(() => {
|
|
const size = props.size || options.size;
|
|
return size ? { fontSize: Number.isNaN(+size) ? size : size + "px" } : null;
|
|
});
|
|
return () => h(
|
|
component.value,
|
|
{
|
|
...options.attrs,
|
|
name: name.value,
|
|
class: options.class,
|
|
style: style.value
|
|
},
|
|
slots
|
|
);
|
|
}
|
|
});
|
|
|
|
export { index as default };
|
|
//# sourceMappingURL=index-Cj-NT10V.mjs.map
|