123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131 |
- /**
- * @vue/server-renderer v3.4.38
- * (c) 2018-present Yuxi (Evan) You and Vue contributors
- * @license MIT
- **/
- import { createVNode, ssrUtils, ssrContextKey, warn as warn$2, Fragment, Static, Comment, Text, mergeProps, createApp, initDirectivesForSSR } from 'vue';
- import { isOn, isRenderableAttrValue, isSVGTag, propsToAttrMap, isBooleanAttr, includeBooleanAttr, isSSRSafeAttrName, escapeHtml, normalizeClass, isString, normalizeStyle, stringifyStyle, makeMap, isArray, toDisplayString, extend, isFunction, getGlobalThis, NOOP, isObject, looseEqual, looseIndexOf, isPromise, escapeHtmlComment, isVoidTag } from '@vue/shared';
- export { includeBooleanAttr as ssrIncludeBooleanAttr } from '@vue/shared';
-
- const shouldIgnoreProp = /* @__PURE__ */ makeMap(
- `,key,ref,innerHTML,textContent,ref_key,ref_for`
- );
- function ssrRenderAttrs(props, tag) {
- let ret = "";
- for (const key in props) {
- if (shouldIgnoreProp(key) || isOn(key) || tag === "textarea" && key === "value") {
- continue;
- }
- const value = props[key];
- if (key === "class") {
- ret += ` class="${ssrRenderClass(value)}"`;
- } else if (key === "style") {
- ret += ` style="${ssrRenderStyle(value)}"`;
- } else {
- ret += ssrRenderDynamicAttr(key, value, tag);
- }
- }
- return ret;
- }
- function ssrRenderDynamicAttr(key, value, tag) {
- if (!isRenderableAttrValue(value)) {
- return ``;
- }
- const attrKey = tag && (tag.indexOf("-") > 0 || isSVGTag(tag)) ? key : propsToAttrMap[key] || key.toLowerCase();
- if (isBooleanAttr(attrKey)) {
- return includeBooleanAttr(value) ? ` ${attrKey}` : ``;
- } else if (isSSRSafeAttrName(attrKey)) {
- return value === "" ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`;
- } else {
- console.warn(
- `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
- );
- return ``;
- }
- }
- function ssrRenderAttr(key, value) {
- if (!isRenderableAttrValue(value)) {
- return ``;
- }
- return ` ${key}="${escapeHtml(value)}"`;
- }
- function ssrRenderClass(raw) {
- return escapeHtml(normalizeClass(raw));
- }
- function ssrRenderStyle(raw) {
- if (!raw) {
- return "";
- }
- if (isString(raw)) {
- return escapeHtml(raw);
- }
- const styles = normalizeStyle(raw);
- return escapeHtml(stringifyStyle(styles));
- }
-
- function ssrRenderComponent(comp, props = null, children = null, parentComponent = null, slotScopeId) {
- return renderComponentVNode(
- createVNode(comp, props, children),
- parentComponent,
- slotScopeId
- );
- }
-
- const { ensureValidVNode } = ssrUtils;
- function ssrRenderSlot(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId) {
- push(`<!--[-->`);
- ssrRenderSlotInner(
- slots,
- slotName,
- slotProps,
- fallbackRenderFn,
- push,
- parentComponent,
- slotScopeId
- );
- push(`<!--]-->`);
- }
- function ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId, transition) {
- const slotFn = slots[slotName];
- if (slotFn) {
- const slotBuffer = [];
- const bufferedPush = (item) => {
- slotBuffer.push(item);
- };
- const ret = slotFn(
- slotProps,
- bufferedPush,
- parentComponent,
- slotScopeId ? " " + slotScopeId : ""
- );
- if (isArray(ret)) {
- const validSlotContent = ensureValidVNode(ret);
- if (validSlotContent) {
- renderVNodeChildren(
- push,
- validSlotContent,
- parentComponent,
- slotScopeId
- );
- } else if (fallbackRenderFn) {
- fallbackRenderFn();
- }
- } else {
- let isEmptySlot = true;
- if (transition) {
- isEmptySlot = false;
- } else {
- for (let i = 0; i < slotBuffer.length; i++) {
- if (!isComment(slotBuffer[i])) {
- isEmptySlot = false;
- break;
- }
- }
- }
- if (isEmptySlot) {
- if (fallbackRenderFn) {
- fallbackRenderFn();
- }
- } else {
- let start = 0;
- let end = slotBuffer.length;
- if (transition && slotBuffer[0] === "<!--[-->" && slotBuffer[end - 1] === "<!--]-->") {
- start++;
- end--;
- }
- for (let i = start; i < end; i++) {
- push(slotBuffer[i]);
- }
- }
- }
- } else if (fallbackRenderFn) {
- fallbackRenderFn();
- }
- }
- const commentTestRE = /^<!--[\s\S]*-->$/;
- const commentRE = /<!--[^]*?-->/gm;
- function isComment(item) {
- if (typeof item !== "string" || !commentTestRE.test(item)) return false;
- if (item.length <= 8) return true;
- return !item.replace(commentRE, "").trim();
- }
-
- function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
- parentPush("<!--teleport start-->");
- const context = parentComponent.appContext.provides[ssrContextKey];
- const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
- const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
- const bufferIndex = targetBuffer.length;
- let teleportContent;
- if (disabled) {
- contentRenderFn(parentPush);
- teleportContent = `<!--teleport start anchor--><!--teleport anchor-->`;
- } else {
- const { getBuffer, push } = createBuffer();
- push(`<!--teleport start anchor-->`);
- contentRenderFn(push);
- push(`<!--teleport anchor-->`);
- teleportContent = getBuffer();
- }
- targetBuffer.splice(bufferIndex, 0, teleportContent);
- parentPush("<!--teleport end-->");
- }
-
- function ssrInterpolate(value) {
- return escapeHtml(toDisplayString(value));
- }
-
- let activeEffect;
- let shouldTrack = true;
- const trackStack = [];
- function pauseTracking() {
- trackStack.push(shouldTrack);
- shouldTrack = false;
- }
- function resetTracking() {
- const last = trackStack.pop();
- shouldTrack = last === void 0 ? true : last;
- }
- function trackEffect(effect2, dep, debuggerEventExtraInfo) {
- var _a;
- if (dep.get(effect2) !== effect2._trackId) {
- dep.set(effect2, effect2._trackId);
- const oldDep = effect2.deps[effect2._depsLength];
- if (oldDep !== dep) {
- effect2.deps[effect2._depsLength++] = dep;
- } else {
- effect2._depsLength++;
- }
- if (!!(process.env.NODE_ENV !== "production")) {
- (_a = effect2.onTrack) == null ? void 0 : _a.call(effect2, extend({ effect: effect2 }, debuggerEventExtraInfo));
- }
- }
- }
-
- const createDep = (cleanup, computed) => {
- const dep = /* @__PURE__ */ new Map();
- dep.cleanup = cleanup;
- dep.computed = computed;
- return dep;
- };
-
- const targetMap = /* @__PURE__ */ new WeakMap();
- Symbol(!!(process.env.NODE_ENV !== "production") ? "iterate" : "");
- Symbol(!!(process.env.NODE_ENV !== "production") ? "Map key iterate" : "");
- function track(target, type, key) {
- if (shouldTrack && activeEffect) {
- let depsMap = targetMap.get(target);
- if (!depsMap) {
- targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
- }
- let dep = depsMap.get(key);
- if (!dep) {
- depsMap.set(key, dep = createDep(() => depsMap.delete(key)));
- }
- trackEffect(
- activeEffect,
- dep,
- !!(process.env.NODE_ENV !== "production") ? {
- target,
- type,
- key
- } : void 0
- );
- }
- }
-
- function toRaw(observed) {
- const raw = observed && observed["__v_raw"];
- return raw ? toRaw(raw) : observed;
- }
-
- function isRef(r) {
- return !!(r && r.__v_isRef === true);
- }
-
- const stack = [];
- function pushWarningContext(vnode) {
- stack.push(vnode);
- }
- function popWarningContext() {
- stack.pop();
- }
- let isWarning = false;
- function warn$1(msg, ...args) {
- if (isWarning) return;
- isWarning = true;
- pauseTracking();
- const instance = stack.length ? stack[stack.length - 1].component : null;
- const appWarnHandler = instance && instance.appContext.config.warnHandler;
- const trace = getComponentTrace();
- if (appWarnHandler) {
- callWithErrorHandling(
- appWarnHandler,
- instance,
- 11,
- [
- // eslint-disable-next-line no-restricted-syntax
- msg + args.map((a) => {
- var _a, _b;
- return (_b = (_a = a.toString) == null ? void 0 : _a.call(a)) != null ? _b : JSON.stringify(a);
- }).join(""),
- instance && instance.proxy,
- trace.map(
- ({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`
- ).join("\n"),
- trace
- ]
- );
- } else {
- const warnArgs = [`[Vue warn]: ${msg}`, ...args];
- if (trace.length && // avoid spamming console during tests
- true) {
- warnArgs.push(`
- `, ...formatTrace(trace));
- }
- console.warn(...warnArgs);
- }
- resetTracking();
- isWarning = false;
- }
- function getComponentTrace() {
- let currentVNode = stack[stack.length - 1];
- if (!currentVNode) {
- return [];
- }
- const normalizedStack = [];
- while (currentVNode) {
- const last = normalizedStack[0];
- if (last && last.vnode === currentVNode) {
- last.recurseCount++;
- } else {
- normalizedStack.push({
- vnode: currentVNode,
- recurseCount: 0
- });
- }
- const parentInstance = currentVNode.component && currentVNode.component.parent;
- currentVNode = parentInstance && parentInstance.vnode;
- }
- return normalizedStack;
- }
- function formatTrace(trace) {
- const logs = [];
- trace.forEach((entry, i) => {
- logs.push(...i === 0 ? [] : [`
- `], ...formatTraceEntry(entry));
- });
- return logs;
- }
- function formatTraceEntry({ vnode, recurseCount }) {
- const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
- const isRoot = vnode.component ? vnode.component.parent == null : false;
- const open = ` at <${formatComponentName(
- vnode.component,
- vnode.type,
- isRoot
- )}`;
- const close = `>` + postfix;
- return vnode.props ? [open, ...formatProps(vnode.props), close] : [open + close];
- }
- function formatProps(props) {
- const res = [];
- const keys = Object.keys(props);
- keys.slice(0, 3).forEach((key) => {
- res.push(...formatProp(key, props[key]));
- });
- if (keys.length > 3) {
- res.push(` ...`);
- }
- return res;
- }
- function formatProp(key, value, raw) {
- if (isString(value)) {
- value = JSON.stringify(value);
- return raw ? value : [`${key}=${value}`];
- } else if (typeof value === "number" || typeof value === "boolean" || value == null) {
- return raw ? value : [`${key}=${value}`];
- } else if (isRef(value)) {
- value = formatProp(key, toRaw(value.value), true);
- return raw ? value : [`${key}=Ref<`, value, `>`];
- } else if (isFunction(value)) {
- return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
- } else {
- value = toRaw(value);
- return raw ? value : [`${key}=`, value];
- }
- }
-
- const ErrorTypeStrings = {
- ["sp"]: "serverPrefetch hook",
- ["bc"]: "beforeCreate hook",
- ["c"]: "created hook",
- ["bm"]: "beforeMount hook",
- ["m"]: "mounted hook",
- ["bu"]: "beforeUpdate hook",
- ["u"]: "updated",
- ["bum"]: "beforeUnmount hook",
- ["um"]: "unmounted hook",
- ["a"]: "activated hook",
- ["da"]: "deactivated hook",
- ["ec"]: "errorCaptured hook",
- ["rtc"]: "renderTracked hook",
- ["rtg"]: "renderTriggered hook",
- [0]: "setup function",
- [1]: "render function",
- [2]: "watcher getter",
- [3]: "watcher callback",
- [4]: "watcher cleanup function",
- [5]: "native event handler",
- [6]: "component event handler",
- [7]: "vnode hook",
- [8]: "directive hook",
- [9]: "transition hook",
- [10]: "app errorHandler",
- [11]: "app warnHandler",
- [12]: "ref function",
- [13]: "async component loader",
- [14]: "scheduler flush",
- [15]: "component update"
- };
- function callWithErrorHandling(fn, instance, type, args) {
- try {
- return args ? fn(...args) : fn();
- } catch (err) {
- handleError(err, instance, type);
- }
- }
- function handleError(err, instance, type, throwInDev = true) {
- const contextVNode = instance ? instance.vnode : null;
- if (instance) {
- let cur = instance.parent;
- const exposedInstance = instance.proxy;
- const errorInfo = !!(process.env.NODE_ENV !== "production") ? ErrorTypeStrings[type] : `https://vuejs.org/error-reference/#runtime-${type}`;
- while (cur) {
- const errorCapturedHooks = cur.ec;
- if (errorCapturedHooks) {
- for (let i = 0; i < errorCapturedHooks.length; i++) {
- if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
- return;
- }
- }
- }
- cur = cur.parent;
- }
- const appErrorHandler = instance.appContext.config.errorHandler;
- if (appErrorHandler) {
- pauseTracking();
- callWithErrorHandling(
- appErrorHandler,
- null,
- 10,
- [err, exposedInstance, errorInfo]
- );
- resetTracking();
- return;
- }
- }
- logError(err, type, contextVNode, throwInDev);
- }
- function logError(err, type, contextVNode, throwInDev = true) {
- if (!!(process.env.NODE_ENV !== "production")) {
- const info = ErrorTypeStrings[type];
- if (contextVNode) {
- pushWarningContext(contextVNode);
- }
- warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
- if (contextVNode) {
- popWarningContext();
- }
- if (throwInDev) {
- throw err;
- } else {
- console.error(err);
- }
- } else {
- console.error(err);
- }
- }
-
- let devtools;
- let buffer = [];
- function setDevtoolsHook(hook, target) {
- var _a, _b;
- devtools = hook;
- if (devtools) {
- devtools.enabled = true;
- buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
- buffer = [];
- } else if (
- // handle late devtools injection - only do this if we are in an actual
- // browser environment to avoid the timer handle stalling test runner exit
- // (#4815)
- typeof window !== "undefined" && // some envs mock window but not fully
- window.HTMLElement && // also exclude jsdom
- // eslint-disable-next-line no-restricted-syntax
- !((_b = (_a = window.navigator) == null ? void 0 : _a.userAgent) == null ? void 0 : _b.includes("jsdom"))
- ) {
- const replay = target.__VUE_DEVTOOLS_HOOK_REPLAY__ = target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [];
- replay.push((newHook) => {
- setDevtoolsHook(newHook, target);
- });
- setTimeout(() => {
- if (!devtools) {
- target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
- buffer = [];
- }
- }, 3e3);
- } else {
- buffer = [];
- }
- }
-
- {
- const g = getGlobalThis();
- const registerGlobalSetter = (key, setter) => {
- let setters;
- if (!(setters = g[key])) setters = g[key] = [];
- setters.push(setter);
- return (v) => {
- if (setters.length > 1) setters.forEach((set) => set(v));
- else setters[0](v);
- };
- };
- registerGlobalSetter(
- `__VUE_INSTANCE_SETTERS__`,
- (v) => v
- );
- registerGlobalSetter(
- `__VUE_SSR_SETTERS__`,
- (v) => v
- );
- }
- !!(process.env.NODE_ENV !== "production") ? {
- get(target, key) {
- track(target, "get", "");
- return target[key];
- },
- set() {
- warn$1(`setupContext.attrs is readonly.`);
- return false;
- },
- deleteProperty() {
- warn$1(`setupContext.attrs is readonly.`);
- return false;
- }
- } : {
- get(target, key) {
- track(target, "get", "");
- return target[key];
- }
- };
- const classifyRE = /(?:^|[-_])(\w)/g;
- const classify = (str) => str.replace(classifyRE, (c) => c.toUpperCase()).replace(/[-_]/g, "");
- function getComponentName(Component, includeInferred = true) {
- return isFunction(Component) ? Component.displayName || Component.name : Component.name || includeInferred && Component.__name;
- }
- function formatComponentName(instance, Component, isRoot = false) {
- let name = getComponentName(Component);
- if (!name && Component.__file) {
- const match = Component.__file.match(/([^/\\]+)\.\w+$/);
- if (match) {
- name = match[1];
- }
- }
- if (!name && instance && instance.parent) {
- const inferFromRegistry = (registry) => {
- for (const key in registry) {
- if (registry[key] === Component) {
- return key;
- }
- }
- };
- name = inferFromRegistry(
- instance.components || instance.parent.type.components
- ) || inferFromRegistry(instance.appContext.components);
- }
- return name ? classify(name) : isRoot ? `App` : `Anonymous`;
- }
-
- const warn = !!(process.env.NODE_ENV !== "production") ? warn$1 : NOOP;
- !!(process.env.NODE_ENV !== "production") || true ? devtools : void 0;
- !!(process.env.NODE_ENV !== "production") || true ? setDevtoolsHook : NOOP;
-
- function ssrRenderList(source, renderItem) {
- if (isArray(source) || isString(source)) {
- for (let i = 0, l = source.length; i < l; i++) {
- renderItem(source[i], i);
- }
- } else if (typeof source === "number") {
- if (!!(process.env.NODE_ENV !== "production") && !Number.isInteger(source)) {
- warn(`The v-for range expect an integer value but got ${source}.`);
- return;
- }
- for (let i = 0; i < source; i++) {
- renderItem(i + 1, i);
- }
- } else if (isObject(source)) {
- if (source[Symbol.iterator]) {
- const arr = Array.from(source);
- for (let i = 0, l = arr.length; i < l; i++) {
- renderItem(arr[i], i);
- }
- } else {
- const keys = Object.keys(source);
- for (let i = 0, l = keys.length; i < l; i++) {
- const key = keys[i];
- renderItem(source[key], key, i);
- }
- }
- }
- }
-
- async function ssrRenderSuspense(push, { default: renderContent }) {
- if (renderContent) {
- renderContent();
- } else {
- push(`<!---->`);
- }
- }
-
- function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
- if (typeof dir !== "function" && dir.getSSRProps) {
- return dir.getSSRProps(
- {
- dir,
- instance: ssrUtils.getComponentPublicInstance(instance.$),
- value,
- oldValue: void 0,
- arg,
- modifiers
- },
- null
- ) || {};
- }
- return {};
- }
-
- const ssrLooseEqual = looseEqual;
- function ssrLooseContain(arr, value) {
- return looseIndexOf(arr, value) > -1;
- }
- function ssrRenderDynamicModel(type, model, value) {
- switch (type) {
- case "radio":
- return looseEqual(model, value) ? " checked" : "";
- case "checkbox":
- return (isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
- default:
- return ssrRenderAttr("value", model);
- }
- }
- function ssrGetDynamicModelProps(existingProps = {}, model) {
- const { type, value } = existingProps;
- switch (type) {
- case "radio":
- return looseEqual(model, value) ? { checked: true } : null;
- case "checkbox":
- return (isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
- default:
- return { value: model };
- }
- }
-
- function ssrCompile(template, instance) {
- {
- throw new Error(
- `On-the-fly template compilation is not supported in the ESM build of @vue/server-renderer. All templates must be pre-compiled into render functions.`
- );
- }
- }
-
- const {
- createComponentInstance,
- setCurrentRenderingInstance,
- setupComponent,
- renderComponentRoot,
- normalizeVNode
- } = ssrUtils;
- function createBuffer() {
- let appendable = false;
- const buffer = [];
- return {
- getBuffer() {
- return buffer;
- },
- push(item) {
- const isStringItem = isString(item);
- if (appendable && isStringItem) {
- buffer[buffer.length - 1] += item;
- return;
- }
- buffer.push(item);
- appendable = isStringItem;
- if (isPromise(item) || isArray(item) && item.hasAsync) {
- buffer.hasAsync = true;
- }
- }
- };
- }
- function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
- const instance = createComponentInstance(vnode, parentComponent, null);
- const res = setupComponent(
- instance,
- true
- /* isSSR */
- );
- const hasAsyncSetup = isPromise(res);
- const prefetches = instance.sp;
- if (hasAsyncSetup || prefetches) {
- let p = hasAsyncSetup ? res : Promise.resolve();
- if (prefetches) {
- p = p.then(
- () => Promise.all(
- prefetches.map((prefetch) => prefetch.call(instance.proxy))
- )
- ).catch(NOOP);
- }
- return p.then(() => renderComponentSubTree(instance, slotScopeId));
- } else {
- return renderComponentSubTree(instance, slotScopeId);
- }
- }
- function renderComponentSubTree(instance, slotScopeId) {
- const comp = instance.type;
- const { getBuffer, push } = createBuffer();
- if (isFunction(comp)) {
- let root = renderComponentRoot(instance);
- if (!comp.props) {
- for (const key in instance.attrs) {
- if (key.startsWith(`data-v-`)) {
- (root.props || (root.props = {}))[key] = ``;
- }
- }
- }
- renderVNode(push, instance.subTree = root, instance, slotScopeId);
- } else {
- if ((!instance.render || instance.render === NOOP) && !instance.ssrRender && !comp.ssrRender && isString(comp.template)) {
- comp.ssrRender = ssrCompile(comp.template);
- }
- for (const e of instance.scope.effects) {
- if (e.computed) {
- e.computed._dirty = true;
- e.computed._cacheable = true;
- }
- }
- const ssrRender = instance.ssrRender || comp.ssrRender;
- if (ssrRender) {
- let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
- let hasCloned = false;
- let cur = instance;
- while (true) {
- const scopeId = cur.vnode.scopeId;
- if (scopeId) {
- if (!hasCloned) {
- attrs = { ...attrs };
- hasCloned = true;
- }
- attrs[scopeId] = "";
- }
- const parent = cur.parent;
- if (parent && parent.subTree && parent.subTree === cur.vnode) {
- cur = parent;
- } else {
- break;
- }
- }
- if (slotScopeId) {
- if (!hasCloned) attrs = { ...attrs };
- const slotScopeIdList = slotScopeId.trim().split(" ");
- for (let i = 0; i < slotScopeIdList.length; i++) {
- attrs[slotScopeIdList[i]] = "";
- }
- }
- const prev = setCurrentRenderingInstance(instance);
- try {
- ssrRender(
- instance.proxy,
- push,
- instance,
- attrs,
- // compiler-optimized bindings
- instance.props,
- instance.setupState,
- instance.data,
- instance.ctx
- );
- } finally {
- setCurrentRenderingInstance(prev);
- }
- } else if (instance.render && instance.render !== NOOP) {
- renderVNode(
- push,
- instance.subTree = renderComponentRoot(instance),
- instance,
- slotScopeId
- );
- } else {
- const componentName = comp.name || comp.__file || `<Anonymous>`;
- warn$2(`Component ${componentName} is missing template or render function.`);
- push(`<!---->`);
- }
- }
- return getBuffer();
- }
- function renderVNode(push, vnode, parentComponent, slotScopeId) {
- const { type, shapeFlag, children } = vnode;
- switch (type) {
- case Text:
- push(escapeHtml(children));
- break;
- case Comment:
- push(
- children ? `<!--${escapeHtmlComment(children)}-->` : `<!---->`
- );
- break;
- case Static:
- push(children);
- break;
- case Fragment:
- if (vnode.slotScopeIds) {
- slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
- }
- push(`<!--[-->`);
- renderVNodeChildren(
- push,
- children,
- parentComponent,
- slotScopeId
- );
- push(`<!--]-->`);
- break;
- default:
- if (shapeFlag & 1) {
- renderElementVNode(push, vnode, parentComponent, slotScopeId);
- } else if (shapeFlag & 6) {
- push(renderComponentVNode(vnode, parentComponent, slotScopeId));
- } else if (shapeFlag & 64) {
- renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
- } else if (shapeFlag & 128) {
- renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
- } else {
- warn$2(
- "[@vue/server-renderer] Invalid VNode type:",
- type,
- `(${typeof type})`
- );
- }
- }
- }
- function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
- for (let i = 0; i < children.length; i++) {
- renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
- }
- }
- function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
- const tag = vnode.type;
- let { props, children, shapeFlag, scopeId, dirs } = vnode;
- let openTag = `<${tag}`;
- if (dirs) {
- props = applySSRDirectives(vnode, props, dirs);
- }
- if (props) {
- openTag += ssrRenderAttrs(props, tag);
- }
- if (scopeId) {
- openTag += ` ${scopeId}`;
- }
- let curParent = parentComponent;
- let curVnode = vnode;
- while (curParent && curVnode === curParent.subTree) {
- curVnode = curParent.vnode;
- if (curVnode.scopeId) {
- openTag += ` ${curVnode.scopeId}`;
- }
- curParent = curParent.parent;
- }
- if (slotScopeId) {
- openTag += ` ${slotScopeId}`;
- }
- push(openTag + `>`);
- if (!isVoidTag(tag)) {
- let hasChildrenOverride = false;
- if (props) {
- if (props.innerHTML) {
- hasChildrenOverride = true;
- push(props.innerHTML);
- } else if (props.textContent) {
- hasChildrenOverride = true;
- push(escapeHtml(props.textContent));
- } else if (tag === "textarea" && props.value) {
- hasChildrenOverride = true;
- push(escapeHtml(props.value));
- }
- }
- if (!hasChildrenOverride) {
- if (shapeFlag & 8) {
- push(escapeHtml(children));
- } else if (shapeFlag & 16) {
- renderVNodeChildren(
- push,
- children,
- parentComponent,
- slotScopeId
- );
- }
- }
- push(`</${tag}>`);
- }
- }
- function applySSRDirectives(vnode, rawProps, dirs) {
- const toMerge = [];
- for (let i = 0; i < dirs.length; i++) {
- const binding = dirs[i];
- const {
- dir: { getSSRProps }
- } = binding;
- if (getSSRProps) {
- const props = getSSRProps(binding, vnode);
- if (props) toMerge.push(props);
- }
- }
- return mergeProps(rawProps || {}, ...toMerge);
- }
- function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
- const target = vnode.props && vnode.props.to;
- const disabled = vnode.props && vnode.props.disabled;
- if (!target) {
- if (!disabled) {
- warn$2(`[@vue/server-renderer] Teleport is missing target prop.`);
- }
- return [];
- }
- if (!isString(target)) {
- warn$2(
- `[@vue/server-renderer] Teleport target must be a query selector string.`
- );
- return [];
- }
- ssrRenderTeleport(
- push,
- (push2) => {
- renderVNodeChildren(
- push2,
- vnode.children,
- parentComponent,
- slotScopeId
- );
- },
- target,
- disabled || disabled === "",
- parentComponent
- );
- }
-
- const { isVNode: isVNode$1 } = ssrUtils;
- function nestedUnrollBuffer(buffer, parentRet, startIndex) {
- if (!buffer.hasAsync) {
- return parentRet + unrollBufferSync$1(buffer);
- }
- let ret = parentRet;
- for (let i = startIndex; i < buffer.length; i += 1) {
- const item = buffer[i];
- if (isString(item)) {
- ret += item;
- continue;
- }
- if (isPromise(item)) {
- return item.then((nestedItem) => {
- buffer[i] = nestedItem;
- return nestedUnrollBuffer(buffer, ret, i);
- });
- }
- const result = nestedUnrollBuffer(item, ret, 0);
- if (isPromise(result)) {
- return result.then((nestedItem) => {
- buffer[i] = nestedItem;
- return nestedUnrollBuffer(buffer, "", i);
- });
- }
- ret = result;
- }
- return ret;
- }
- function unrollBuffer$1(buffer) {
- return nestedUnrollBuffer(buffer, "", 0);
- }
- function unrollBufferSync$1(buffer) {
- let ret = "";
- for (let i = 0; i < buffer.length; i++) {
- let item = buffer[i];
- if (isString(item)) {
- ret += item;
- } else {
- ret += unrollBufferSync$1(item);
- }
- }
- return ret;
- }
- async function renderToString(input, context = {}) {
- if (isVNode$1(input)) {
- return renderToString(createApp({ render: () => input }), context);
- }
- const vnode = createVNode(input._component, input._props);
- vnode.appContext = input._context;
- input.provide(ssrContextKey, context);
- const buffer = await renderComponentVNode(vnode);
- const result = await unrollBuffer$1(buffer);
- await resolveTeleports(context);
- if (context.__watcherHandles) {
- for (const unwatch of context.__watcherHandles) {
- unwatch();
- }
- }
- return result;
- }
- async function resolveTeleports(context) {
- if (context.__teleportBuffers) {
- context.teleports = context.teleports || {};
- for (const key in context.__teleportBuffers) {
- context.teleports[key] = await unrollBuffer$1(
- await Promise.all([context.__teleportBuffers[key]])
- );
- }
- }
- }
-
- const { isVNode } = ssrUtils;
- async function unrollBuffer(buffer, stream) {
- if (buffer.hasAsync) {
- for (let i = 0; i < buffer.length; i++) {
- let item = buffer[i];
- if (isPromise(item)) {
- item = await item;
- }
- if (isString(item)) {
- stream.push(item);
- } else {
- await unrollBuffer(item, stream);
- }
- }
- } else {
- unrollBufferSync(buffer, stream);
- }
- }
- function unrollBufferSync(buffer, stream) {
- for (let i = 0; i < buffer.length; i++) {
- let item = buffer[i];
- if (isString(item)) {
- stream.push(item);
- } else {
- unrollBufferSync(item, stream);
- }
- }
- }
- function renderToSimpleStream(input, context, stream) {
- if (isVNode(input)) {
- return renderToSimpleStream(
- createApp({ render: () => input }),
- context,
- stream
- );
- }
- const vnode = createVNode(input._component, input._props);
- vnode.appContext = input._context;
- input.provide(ssrContextKey, context);
- Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
- if (context.__watcherHandles) {
- for (const unwatch of context.__watcherHandles) {
- unwatch();
- }
- }
- }).then(() => stream.push(null)).catch((error) => {
- stream.destroy(error);
- });
- return stream;
- }
- function renderToStream(input, context = {}) {
- console.warn(
- `[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
- );
- return renderToNodeStream(input, context);
- }
- function renderToNodeStream(input, context = {}) {
- {
- throw new Error(
- `ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
- );
- }
- }
- function pipeToNodeWritable(input, context = {}, writable) {
- renderToSimpleStream(input, context, {
- push(content) {
- if (content != null) {
- writable.write(content);
- } else {
- writable.end();
- }
- },
- destroy(err) {
- writable.destroy(err);
- }
- });
- }
- function renderToWebStream(input, context = {}) {
- if (typeof ReadableStream !== "function") {
- throw new Error(
- `ReadableStream constructor is not available in the global scope. If the target environment does support web streams, consider using pipeToWebWritable() with an existing WritableStream instance instead.`
- );
- }
- const encoder = new TextEncoder();
- let cancelled = false;
- return new ReadableStream({
- start(controller) {
- renderToSimpleStream(input, context, {
- push(content) {
- if (cancelled) return;
- if (content != null) {
- controller.enqueue(encoder.encode(content));
- } else {
- controller.close();
- }
- },
- destroy(err) {
- controller.error(err);
- }
- });
- },
- cancel() {
- cancelled = true;
- }
- });
- }
- function pipeToWebWritable(input, context = {}, writable) {
- const writer = writable.getWriter();
- const encoder = new TextEncoder();
- let hasReady = false;
- try {
- hasReady = isPromise(writer.ready);
- } catch (e) {
- }
- renderToSimpleStream(input, context, {
- async push(content) {
- if (hasReady) {
- await writer.ready;
- }
- if (content != null) {
- return writer.write(encoder.encode(content));
- } else {
- return writer.close();
- }
- },
- destroy(err) {
- console.log(err);
- writer.close();
- }
- });
- }
-
- initDirectivesForSSR();
-
- export { pipeToNodeWritable, pipeToWebWritable, renderToNodeStream, renderToSimpleStream, renderToStream, renderToString, renderToWebStream, ssrGetDirectiveProps, ssrGetDynamicModelProps, ssrInterpolate, ssrLooseContain, ssrLooseEqual, ssrRenderAttr, ssrRenderAttrs, ssrRenderClass, ssrRenderComponent, ssrRenderDynamicAttr, ssrRenderDynamicModel, ssrRenderList, ssrRenderSlot, ssrRenderSlotInner, ssrRenderStyle, ssrRenderSuspense, ssrRenderTeleport, renderVNode as ssrRenderVNode };
|