1 | /**
|
---|
2 | * @vue/server-renderer v3.5.13
|
---|
3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
4 | * @license MIT
|
---|
5 | **/
|
---|
6 | import { createVNode, ssrUtils, ssrContextKey, warn as warn$2, Fragment, Static, Comment, Text, mergeProps, createApp, initDirectivesForSSR } from 'vue';
|
---|
7 | import { isOn, isRenderableAttrValue, isSVGTag, propsToAttrMap, isBooleanAttr, includeBooleanAttr, isSSRSafeAttrName, escapeHtml, normalizeClass, isString, normalizeStyle, stringifyStyle, makeMap, isArray, toDisplayString, extend, isFunction, EMPTY_OBJ, getGlobalThis, NOOP, isObject, looseEqual, looseIndexOf, isPromise, escapeHtmlComment, isVoidTag } from '@vue/shared';
|
---|
8 | export { includeBooleanAttr as ssrIncludeBooleanAttr } from '@vue/shared';
|
---|
9 |
|
---|
10 | const shouldIgnoreProp = /* @__PURE__ */ makeMap(
|
---|
11 | `,key,ref,innerHTML,textContent,ref_key,ref_for`
|
---|
12 | );
|
---|
13 | function ssrRenderAttrs(props, tag) {
|
---|
14 | let ret = "";
|
---|
15 | for (const key in props) {
|
---|
16 | if (shouldIgnoreProp(key) || isOn(key) || tag === "textarea" && key === "value") {
|
---|
17 | continue;
|
---|
18 | }
|
---|
19 | const value = props[key];
|
---|
20 | if (key === "class") {
|
---|
21 | ret += ` class="${ssrRenderClass(value)}"`;
|
---|
22 | } else if (key === "style") {
|
---|
23 | ret += ` style="${ssrRenderStyle(value)}"`;
|
---|
24 | } else if (key === "className") {
|
---|
25 | ret += ` class="${String(value)}"`;
|
---|
26 | } else {
|
---|
27 | ret += ssrRenderDynamicAttr(key, value, tag);
|
---|
28 | }
|
---|
29 | }
|
---|
30 | return ret;
|
---|
31 | }
|
---|
32 | function ssrRenderDynamicAttr(key, value, tag) {
|
---|
33 | if (!isRenderableAttrValue(value)) {
|
---|
34 | return ``;
|
---|
35 | }
|
---|
36 | const attrKey = tag && (tag.indexOf("-") > 0 || isSVGTag(tag)) ? key : propsToAttrMap[key] || key.toLowerCase();
|
---|
37 | if (isBooleanAttr(attrKey)) {
|
---|
38 | return includeBooleanAttr(value) ? ` ${attrKey}` : ``;
|
---|
39 | } else if (isSSRSafeAttrName(attrKey)) {
|
---|
40 | return value === "" ? ` ${attrKey}` : ` ${attrKey}="${escapeHtml(value)}"`;
|
---|
41 | } else {
|
---|
42 | console.warn(
|
---|
43 | `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
|
---|
44 | );
|
---|
45 | return ``;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | function ssrRenderAttr(key, value) {
|
---|
49 | if (!isRenderableAttrValue(value)) {
|
---|
50 | return ``;
|
---|
51 | }
|
---|
52 | return ` ${key}="${escapeHtml(value)}"`;
|
---|
53 | }
|
---|
54 | function ssrRenderClass(raw) {
|
---|
55 | return escapeHtml(normalizeClass(raw));
|
---|
56 | }
|
---|
57 | function ssrRenderStyle(raw) {
|
---|
58 | if (!raw) {
|
---|
59 | return "";
|
---|
60 | }
|
---|
61 | if (isString(raw)) {
|
---|
62 | return escapeHtml(raw);
|
---|
63 | }
|
---|
64 | const styles = normalizeStyle(raw);
|
---|
65 | return escapeHtml(stringifyStyle(styles));
|
---|
66 | }
|
---|
67 |
|
---|
68 | function ssrRenderComponent(comp, props = null, children = null, parentComponent = null, slotScopeId) {
|
---|
69 | return renderComponentVNode(
|
---|
70 | createVNode(comp, props, children),
|
---|
71 | parentComponent,
|
---|
72 | slotScopeId
|
---|
73 | );
|
---|
74 | }
|
---|
75 |
|
---|
76 | const { ensureValidVNode } = ssrUtils;
|
---|
77 | function ssrRenderSlot(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId) {
|
---|
78 | push(`<!--[-->`);
|
---|
79 | ssrRenderSlotInner(
|
---|
80 | slots,
|
---|
81 | slotName,
|
---|
82 | slotProps,
|
---|
83 | fallbackRenderFn,
|
---|
84 | push,
|
---|
85 | parentComponent,
|
---|
86 | slotScopeId
|
---|
87 | );
|
---|
88 | push(`<!--]-->`);
|
---|
89 | }
|
---|
90 | function ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId, transition) {
|
---|
91 | const slotFn = slots[slotName];
|
---|
92 | if (slotFn) {
|
---|
93 | const slotBuffer = [];
|
---|
94 | const bufferedPush = (item) => {
|
---|
95 | slotBuffer.push(item);
|
---|
96 | };
|
---|
97 | const ret = slotFn(
|
---|
98 | slotProps,
|
---|
99 | bufferedPush,
|
---|
100 | parentComponent,
|
---|
101 | slotScopeId ? " " + slotScopeId : ""
|
---|
102 | );
|
---|
103 | if (isArray(ret)) {
|
---|
104 | const validSlotContent = ensureValidVNode(ret);
|
---|
105 | if (validSlotContent) {
|
---|
106 | renderVNodeChildren(
|
---|
107 | push,
|
---|
108 | validSlotContent,
|
---|
109 | parentComponent,
|
---|
110 | slotScopeId
|
---|
111 | );
|
---|
112 | } else if (fallbackRenderFn) {
|
---|
113 | fallbackRenderFn();
|
---|
114 | }
|
---|
115 | } else {
|
---|
116 | let isEmptySlot = true;
|
---|
117 | if (transition) {
|
---|
118 | isEmptySlot = false;
|
---|
119 | } else {
|
---|
120 | for (let i = 0; i < slotBuffer.length; i++) {
|
---|
121 | if (!isComment(slotBuffer[i])) {
|
---|
122 | isEmptySlot = false;
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|
127 | if (isEmptySlot) {
|
---|
128 | if (fallbackRenderFn) {
|
---|
129 | fallbackRenderFn();
|
---|
130 | }
|
---|
131 | } else {
|
---|
132 | let start = 0;
|
---|
133 | let end = slotBuffer.length;
|
---|
134 | if (transition && slotBuffer[0] === "<!--[-->" && slotBuffer[end - 1] === "<!--]-->") {
|
---|
135 | start++;
|
---|
136 | end--;
|
---|
137 | }
|
---|
138 | for (let i = start; i < end; i++) {
|
---|
139 | push(slotBuffer[i]);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 | } else if (fallbackRenderFn) {
|
---|
144 | fallbackRenderFn();
|
---|
145 | }
|
---|
146 | }
|
---|
147 | const commentTestRE = /^<!--[\s\S]*-->$/;
|
---|
148 | const commentRE = /<!--[^]*?-->/gm;
|
---|
149 | function isComment(item) {
|
---|
150 | if (typeof item !== "string" || !commentTestRE.test(item)) return false;
|
---|
151 | if (item.length <= 8) return true;
|
---|
152 | return !item.replace(commentRE, "").trim();
|
---|
153 | }
|
---|
154 |
|
---|
155 | function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
|
---|
156 | parentPush("<!--teleport start-->");
|
---|
157 | const context = parentComponent.appContext.provides[ssrContextKey];
|
---|
158 | const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
|
---|
159 | const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
|
---|
160 | const bufferIndex = targetBuffer.length;
|
---|
161 | let teleportContent;
|
---|
162 | if (disabled) {
|
---|
163 | contentRenderFn(parentPush);
|
---|
164 | teleportContent = `<!--teleport start anchor--><!--teleport anchor-->`;
|
---|
165 | } else {
|
---|
166 | const { getBuffer, push } = createBuffer();
|
---|
167 | push(`<!--teleport start anchor-->`);
|
---|
168 | contentRenderFn(push);
|
---|
169 | push(`<!--teleport anchor-->`);
|
---|
170 | teleportContent = getBuffer();
|
---|
171 | }
|
---|
172 | targetBuffer.splice(bufferIndex, 0, teleportContent);
|
---|
173 | parentPush("<!--teleport end-->");
|
---|
174 | }
|
---|
175 |
|
---|
176 | function ssrInterpolate(value) {
|
---|
177 | return escapeHtml(toDisplayString(value));
|
---|
178 | }
|
---|
179 |
|
---|
180 | let activeSub;
|
---|
181 | let batchDepth = 0;
|
---|
182 | let batchedSub;
|
---|
183 | function startBatch() {
|
---|
184 | batchDepth++;
|
---|
185 | }
|
---|
186 | function endBatch() {
|
---|
187 | if (--batchDepth > 0) {
|
---|
188 | return;
|
---|
189 | }
|
---|
190 | let error;
|
---|
191 | while (batchedSub) {
|
---|
192 | let e = batchedSub;
|
---|
193 | batchedSub = void 0;
|
---|
194 | while (e) {
|
---|
195 | const next = e.next;
|
---|
196 | e.next = void 0;
|
---|
197 | e.flags &= ~8;
|
---|
198 | if (e.flags & 1) {
|
---|
199 | try {
|
---|
200 | ;
|
---|
201 | e.trigger();
|
---|
202 | } catch (err) {
|
---|
203 | if (!error) error = err;
|
---|
204 | }
|
---|
205 | }
|
---|
206 | e = next;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | if (error) throw error;
|
---|
210 | }
|
---|
211 | let shouldTrack = true;
|
---|
212 | const trackStack = [];
|
---|
213 | function pauseTracking() {
|
---|
214 | trackStack.push(shouldTrack);
|
---|
215 | shouldTrack = false;
|
---|
216 | }
|
---|
217 | function resetTracking() {
|
---|
218 | const last = trackStack.pop();
|
---|
219 | shouldTrack = last === void 0 ? true : last;
|
---|
220 | }
|
---|
221 |
|
---|
222 | class Dep {
|
---|
223 | constructor(computed) {
|
---|
224 | this.computed = computed;
|
---|
225 | this.version = 0;
|
---|
226 | /**
|
---|
227 | * Link between this dep and the current active effect
|
---|
228 | */
|
---|
229 | this.activeLink = void 0;
|
---|
230 | /**
|
---|
231 | * Doubly linked list representing the subscribing effects (tail)
|
---|
232 | */
|
---|
233 | this.subs = void 0;
|
---|
234 | /**
|
---|
235 | * For object property deps cleanup
|
---|
236 | */
|
---|
237 | this.map = void 0;
|
---|
238 | this.key = void 0;
|
---|
239 | /**
|
---|
240 | * Subscriber counter
|
---|
241 | */
|
---|
242 | this.sc = 0;
|
---|
243 | if (!!(process.env.NODE_ENV !== "production")) {
|
---|
244 | this.subsHead = void 0;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | track(debugInfo) {
|
---|
248 | {
|
---|
249 | return;
|
---|
250 | }
|
---|
251 | }
|
---|
252 | trigger(debugInfo) {
|
---|
253 | this.version++;
|
---|
254 | this.notify(debugInfo);
|
---|
255 | }
|
---|
256 | notify(debugInfo) {
|
---|
257 | startBatch();
|
---|
258 | try {
|
---|
259 | if (!!(process.env.NODE_ENV !== "production")) {
|
---|
260 | for (let head = this.subsHead; head; head = head.nextSub) {
|
---|
261 | if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
---|
262 | head.sub.onTrigger(
|
---|
263 | extend(
|
---|
264 | {
|
---|
265 | effect: head.sub
|
---|
266 | },
|
---|
267 | debugInfo
|
---|
268 | )
|
---|
269 | );
|
---|
270 | }
|
---|
271 | }
|
---|
272 | }
|
---|
273 | for (let link = this.subs; link; link = link.prevSub) {
|
---|
274 | if (link.sub.notify()) {
|
---|
275 | ;
|
---|
276 | link.sub.dep.notify();
|
---|
277 | }
|
---|
278 | }
|
---|
279 | } finally {
|
---|
280 | endBatch();
|
---|
281 | }
|
---|
282 | }
|
---|
283 | }
|
---|
284 | const targetMap = /* @__PURE__ */ new WeakMap();
|
---|
285 | Symbol(
|
---|
286 | !!(process.env.NODE_ENV !== "production") ? "Object iterate" : ""
|
---|
287 | );
|
---|
288 | Symbol(
|
---|
289 | !!(process.env.NODE_ENV !== "production") ? "Map keys iterate" : ""
|
---|
290 | );
|
---|
291 | Symbol(
|
---|
292 | !!(process.env.NODE_ENV !== "production") ? "Array iterate" : ""
|
---|
293 | );
|
---|
294 | function track(target, type, key) {
|
---|
295 | if (shouldTrack && activeSub) {
|
---|
296 | let depsMap = targetMap.get(target);
|
---|
297 | if (!depsMap) {
|
---|
298 | targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
---|
299 | }
|
---|
300 | let dep = depsMap.get(key);
|
---|
301 | if (!dep) {
|
---|
302 | depsMap.set(key, dep = new Dep());
|
---|
303 | dep.map = depsMap;
|
---|
304 | dep.key = key;
|
---|
305 | }
|
---|
306 | if (!!(process.env.NODE_ENV !== "production")) {
|
---|
307 | dep.track({
|
---|
308 | target,
|
---|
309 | type,
|
---|
310 | key
|
---|
311 | });
|
---|
312 | } else {
|
---|
313 | dep.track();
|
---|
314 | }
|
---|
315 | }
|
---|
316 | }
|
---|
317 |
|
---|
318 | function isProxy(value) {
|
---|
319 | return value ? !!value["__v_raw"] : false;
|
---|
320 | }
|
---|
321 | function toRaw(observed) {
|
---|
322 | const raw = observed && observed["__v_raw"];
|
---|
323 | return raw ? toRaw(raw) : observed;
|
---|
324 | }
|
---|
325 |
|
---|
326 | function isRef(r) {
|
---|
327 | return r ? r["__v_isRef"] === true : false;
|
---|
328 | }
|
---|
329 |
|
---|
330 | const stack = [];
|
---|
331 | function pushWarningContext$1(vnode) {
|
---|
332 | stack.push(vnode);
|
---|
333 | }
|
---|
334 | function popWarningContext$1() {
|
---|
335 | stack.pop();
|
---|
336 | }
|
---|
337 | let isWarning = false;
|
---|
338 | function warn$1(msg, ...args) {
|
---|
339 | if (isWarning) return;
|
---|
340 | isWarning = true;
|
---|
341 | pauseTracking();
|
---|
342 | const instance = stack.length ? stack[stack.length - 1].component : null;
|
---|
343 | const appWarnHandler = instance && instance.appContext.config.warnHandler;
|
---|
344 | const trace = getComponentTrace();
|
---|
345 | if (appWarnHandler) {
|
---|
346 | callWithErrorHandling(
|
---|
347 | appWarnHandler,
|
---|
348 | instance,
|
---|
349 | 11,
|
---|
350 | [
|
---|
351 | // eslint-disable-next-line no-restricted-syntax
|
---|
352 | msg + args.map((a) => {
|
---|
353 | var _a, _b;
|
---|
354 | return (_b = (_a = a.toString) == null ? void 0 : _a.call(a)) != null ? _b : JSON.stringify(a);
|
---|
355 | }).join(""),
|
---|
356 | instance && instance.proxy,
|
---|
357 | trace.map(
|
---|
358 | ({ vnode }) => `at <${formatComponentName(instance, vnode.type)}>`
|
---|
359 | ).join("\n"),
|
---|
360 | trace
|
---|
361 | ]
|
---|
362 | );
|
---|
363 | } else {
|
---|
364 | const warnArgs = [`[Vue warn]: ${msg}`, ...args];
|
---|
365 | if (trace.length && // avoid spamming console during tests
|
---|
366 | true) {
|
---|
367 | warnArgs.push(`
|
---|
368 | `, ...formatTrace(trace));
|
---|
369 | }
|
---|
370 | console.warn(...warnArgs);
|
---|
371 | }
|
---|
372 | resetTracking();
|
---|
373 | isWarning = false;
|
---|
374 | }
|
---|
375 | function getComponentTrace() {
|
---|
376 | let currentVNode = stack[stack.length - 1];
|
---|
377 | if (!currentVNode) {
|
---|
378 | return [];
|
---|
379 | }
|
---|
380 | const normalizedStack = [];
|
---|
381 | while (currentVNode) {
|
---|
382 | const last = normalizedStack[0];
|
---|
383 | if (last && last.vnode === currentVNode) {
|
---|
384 | last.recurseCount++;
|
---|
385 | } else {
|
---|
386 | normalizedStack.push({
|
---|
387 | vnode: currentVNode,
|
---|
388 | recurseCount: 0
|
---|
389 | });
|
---|
390 | }
|
---|
391 | const parentInstance = currentVNode.component && currentVNode.component.parent;
|
---|
392 | currentVNode = parentInstance && parentInstance.vnode;
|
---|
393 | }
|
---|
394 | return normalizedStack;
|
---|
395 | }
|
---|
396 | function formatTrace(trace) {
|
---|
397 | const logs = [];
|
---|
398 | trace.forEach((entry, i) => {
|
---|
399 | logs.push(...i === 0 ? [] : [`
|
---|
400 | `], ...formatTraceEntry(entry));
|
---|
401 | });
|
---|
402 | return logs;
|
---|
403 | }
|
---|
404 | function formatTraceEntry({ vnode, recurseCount }) {
|
---|
405 | const postfix = recurseCount > 0 ? `... (${recurseCount} recursive calls)` : ``;
|
---|
406 | const isRoot = vnode.component ? vnode.component.parent == null : false;
|
---|
407 | const open = ` at <${formatComponentName(
|
---|
408 | vnode.component,
|
---|
409 | vnode.type,
|
---|
410 | isRoot
|
---|
411 | )}`;
|
---|
412 | const close = `>` + postfix;
|
---|
413 | return vnode.props ? [open, ...formatProps(vnode.props), close] : [open + close];
|
---|
414 | }
|
---|
415 | function formatProps(props) {
|
---|
416 | const res = [];
|
---|
417 | const keys = Object.keys(props);
|
---|
418 | keys.slice(0, 3).forEach((key) => {
|
---|
419 | res.push(...formatProp(key, props[key]));
|
---|
420 | });
|
---|
421 | if (keys.length > 3) {
|
---|
422 | res.push(` ...`);
|
---|
423 | }
|
---|
424 | return res;
|
---|
425 | }
|
---|
426 | function formatProp(key, value, raw) {
|
---|
427 | if (isString(value)) {
|
---|
428 | value = JSON.stringify(value);
|
---|
429 | return raw ? value : [`${key}=${value}`];
|
---|
430 | } else if (typeof value === "number" || typeof value === "boolean" || value == null) {
|
---|
431 | return raw ? value : [`${key}=${value}`];
|
---|
432 | } else if (isRef(value)) {
|
---|
433 | value = formatProp(key, toRaw(value.value), true);
|
---|
434 | return raw ? value : [`${key}=Ref<`, value, `>`];
|
---|
435 | } else if (isFunction(value)) {
|
---|
436 | return [`${key}=fn${value.name ? `<${value.name}>` : ``}`];
|
---|
437 | } else {
|
---|
438 | value = toRaw(value);
|
---|
439 | return raw ? value : [`${key}=`, value];
|
---|
440 | }
|
---|
441 | }
|
---|
442 |
|
---|
443 | const ErrorTypeStrings = {
|
---|
444 | ["sp"]: "serverPrefetch hook",
|
---|
445 | ["bc"]: "beforeCreate hook",
|
---|
446 | ["c"]: "created hook",
|
---|
447 | ["bm"]: "beforeMount hook",
|
---|
448 | ["m"]: "mounted hook",
|
---|
449 | ["bu"]: "beforeUpdate hook",
|
---|
450 | ["u"]: "updated",
|
---|
451 | ["bum"]: "beforeUnmount hook",
|
---|
452 | ["um"]: "unmounted hook",
|
---|
453 | ["a"]: "activated hook",
|
---|
454 | ["da"]: "deactivated hook",
|
---|
455 | ["ec"]: "errorCaptured hook",
|
---|
456 | ["rtc"]: "renderTracked hook",
|
---|
457 | ["rtg"]: "renderTriggered hook",
|
---|
458 | [0]: "setup function",
|
---|
459 | [1]: "render function",
|
---|
460 | [2]: "watcher getter",
|
---|
461 | [3]: "watcher callback",
|
---|
462 | [4]: "watcher cleanup function",
|
---|
463 | [5]: "native event handler",
|
---|
464 | [6]: "component event handler",
|
---|
465 | [7]: "vnode hook",
|
---|
466 | [8]: "directive hook",
|
---|
467 | [9]: "transition hook",
|
---|
468 | [10]: "app errorHandler",
|
---|
469 | [11]: "app warnHandler",
|
---|
470 | [12]: "ref function",
|
---|
471 | [13]: "async component loader",
|
---|
472 | [14]: "scheduler flush",
|
---|
473 | [15]: "component update",
|
---|
474 | [16]: "app unmount cleanup function"
|
---|
475 | };
|
---|
476 | function callWithErrorHandling(fn, instance, type, args) {
|
---|
477 | try {
|
---|
478 | return args ? fn(...args) : fn();
|
---|
479 | } catch (err) {
|
---|
480 | handleError(err, instance, type);
|
---|
481 | }
|
---|
482 | }
|
---|
483 | function handleError(err, instance, type, throwInDev = true) {
|
---|
484 | const contextVNode = instance ? instance.vnode : null;
|
---|
485 | const { errorHandler, throwUnhandledErrorInProduction } = instance && instance.appContext.config || EMPTY_OBJ;
|
---|
486 | if (instance) {
|
---|
487 | let cur = instance.parent;
|
---|
488 | const exposedInstance = instance.proxy;
|
---|
489 | const errorInfo = !!(process.env.NODE_ENV !== "production") ? ErrorTypeStrings[type] : `https://vuejs.org/error-reference/#runtime-${type}`;
|
---|
490 | while (cur) {
|
---|
491 | const errorCapturedHooks = cur.ec;
|
---|
492 | if (errorCapturedHooks) {
|
---|
493 | for (let i = 0; i < errorCapturedHooks.length; i++) {
|
---|
494 | if (errorCapturedHooks[i](err, exposedInstance, errorInfo) === false) {
|
---|
495 | return;
|
---|
496 | }
|
---|
497 | }
|
---|
498 | }
|
---|
499 | cur = cur.parent;
|
---|
500 | }
|
---|
501 | if (errorHandler) {
|
---|
502 | pauseTracking();
|
---|
503 | callWithErrorHandling(errorHandler, null, 10, [
|
---|
504 | err,
|
---|
505 | exposedInstance,
|
---|
506 | errorInfo
|
---|
507 | ]);
|
---|
508 | resetTracking();
|
---|
509 | return;
|
---|
510 | }
|
---|
511 | }
|
---|
512 | logError(err, type, contextVNode, throwInDev, throwUnhandledErrorInProduction);
|
---|
513 | }
|
---|
514 | function logError(err, type, contextVNode, throwInDev = true, throwInProd = false) {
|
---|
515 | if (!!(process.env.NODE_ENV !== "production")) {
|
---|
516 | const info = ErrorTypeStrings[type];
|
---|
517 | if (contextVNode) {
|
---|
518 | pushWarningContext$1(contextVNode);
|
---|
519 | }
|
---|
520 | warn$1(`Unhandled error${info ? ` during execution of ${info}` : ``}`);
|
---|
521 | if (contextVNode) {
|
---|
522 | popWarningContext$1();
|
---|
523 | }
|
---|
524 | if (throwInDev) {
|
---|
525 | throw err;
|
---|
526 | } else {
|
---|
527 | console.error(err);
|
---|
528 | }
|
---|
529 | } else if (throwInProd) {
|
---|
530 | throw err;
|
---|
531 | } else {
|
---|
532 | console.error(err);
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | let devtools;
|
---|
537 | let buffer = [];
|
---|
538 | function setDevtoolsHook(hook, target) {
|
---|
539 | var _a, _b;
|
---|
540 | devtools = hook;
|
---|
541 | if (devtools) {
|
---|
542 | devtools.enabled = true;
|
---|
543 | buffer.forEach(({ event, args }) => devtools.emit(event, ...args));
|
---|
544 | buffer = [];
|
---|
545 | } else if (
|
---|
546 | // handle late devtools injection - only do this if we are in an actual
|
---|
547 | // browser environment to avoid the timer handle stalling test runner exit
|
---|
548 | // (#4815)
|
---|
549 | typeof window !== "undefined" && // some envs mock window but not fully
|
---|
550 | window.HTMLElement && // also exclude jsdom
|
---|
551 | // eslint-disable-next-line no-restricted-syntax
|
---|
552 | !((_b = (_a = window.navigator) == null ? void 0 : _a.userAgent) == null ? void 0 : _b.includes("jsdom"))
|
---|
553 | ) {
|
---|
554 | const replay = target.__VUE_DEVTOOLS_HOOK_REPLAY__ = target.__VUE_DEVTOOLS_HOOK_REPLAY__ || [];
|
---|
555 | replay.push((newHook) => {
|
---|
556 | setDevtoolsHook(newHook, target);
|
---|
557 | });
|
---|
558 | setTimeout(() => {
|
---|
559 | if (!devtools) {
|
---|
560 | target.__VUE_DEVTOOLS_HOOK_REPLAY__ = null;
|
---|
561 | buffer = [];
|
---|
562 | }
|
---|
563 | }, 3e3);
|
---|
564 | } else {
|
---|
565 | buffer = [];
|
---|
566 | }
|
---|
567 | }
|
---|
568 |
|
---|
569 | {
|
---|
570 | const g = getGlobalThis();
|
---|
571 | const registerGlobalSetter = (key, setter) => {
|
---|
572 | let setters;
|
---|
573 | if (!(setters = g[key])) setters = g[key] = [];
|
---|
574 | setters.push(setter);
|
---|
575 | return (v) => {
|
---|
576 | if (setters.length > 1) setters.forEach((set) => set(v));
|
---|
577 | else setters[0](v);
|
---|
578 | };
|
---|
579 | };
|
---|
580 | registerGlobalSetter(
|
---|
581 | `__VUE_INSTANCE_SETTERS__`,
|
---|
582 | (v) => v
|
---|
583 | );
|
---|
584 | registerGlobalSetter(
|
---|
585 | `__VUE_SSR_SETTERS__`,
|
---|
586 | (v) => v
|
---|
587 | );
|
---|
588 | }
|
---|
589 | !!(process.env.NODE_ENV !== "production") ? {
|
---|
590 | get(target, key) {
|
---|
591 | track(target, "get", "");
|
---|
592 | return target[key];
|
---|
593 | },
|
---|
594 | set() {
|
---|
595 | warn$1(`setupContext.attrs is readonly.`);
|
---|
596 | return false;
|
---|
597 | },
|
---|
598 | deleteProperty() {
|
---|
599 | warn$1(`setupContext.attrs is readonly.`);
|
---|
600 | return false;
|
---|
601 | }
|
---|
602 | } : {
|
---|
603 | get(target, key) {
|
---|
604 | track(target, "get", "");
|
---|
605 | return target[key];
|
---|
606 | }
|
---|
607 | };
|
---|
608 | const classifyRE = /(?:^|[-_])(\w)/g;
|
---|
609 | const classify = (str) => str.replace(classifyRE, (c) => c.toUpperCase()).replace(/[-_]/g, "");
|
---|
610 | function getComponentName(Component, includeInferred = true) {
|
---|
611 | return isFunction(Component) ? Component.displayName || Component.name : Component.name || includeInferred && Component.__name;
|
---|
612 | }
|
---|
613 | function formatComponentName(instance, Component, isRoot = false) {
|
---|
614 | let name = getComponentName(Component);
|
---|
615 | if (!name && Component.__file) {
|
---|
616 | const match = Component.__file.match(/([^/\\]+)\.\w+$/);
|
---|
617 | if (match) {
|
---|
618 | name = match[1];
|
---|
619 | }
|
---|
620 | }
|
---|
621 | if (!name && instance && instance.parent) {
|
---|
622 | const inferFromRegistry = (registry) => {
|
---|
623 | for (const key in registry) {
|
---|
624 | if (registry[key] === Component) {
|
---|
625 | return key;
|
---|
626 | }
|
---|
627 | }
|
---|
628 | };
|
---|
629 | name = inferFromRegistry(
|
---|
630 | instance.components || instance.parent.type.components
|
---|
631 | ) || inferFromRegistry(instance.appContext.components);
|
---|
632 | }
|
---|
633 | return name ? classify(name) : isRoot ? `App` : `Anonymous`;
|
---|
634 | }
|
---|
635 | function isClassComponent(value) {
|
---|
636 | return isFunction(value) && "__vccOpts" in value;
|
---|
637 | }
|
---|
638 |
|
---|
639 | const warn = !!(process.env.NODE_ENV !== "production") ? warn$1 : NOOP;
|
---|
640 | !!(process.env.NODE_ENV !== "production") || true ? devtools : void 0;
|
---|
641 | !!(process.env.NODE_ENV !== "production") || true ? setDevtoolsHook : NOOP;
|
---|
642 |
|
---|
643 | function ssrRenderList(source, renderItem) {
|
---|
644 | if (isArray(source) || isString(source)) {
|
---|
645 | for (let i = 0, l = source.length; i < l; i++) {
|
---|
646 | renderItem(source[i], i);
|
---|
647 | }
|
---|
648 | } else if (typeof source === "number") {
|
---|
649 | if (!!(process.env.NODE_ENV !== "production") && !Number.isInteger(source)) {
|
---|
650 | warn(`The v-for range expect an integer value but got ${source}.`);
|
---|
651 | return;
|
---|
652 | }
|
---|
653 | for (let i = 0; i < source; i++) {
|
---|
654 | renderItem(i + 1, i);
|
---|
655 | }
|
---|
656 | } else if (isObject(source)) {
|
---|
657 | if (source[Symbol.iterator]) {
|
---|
658 | const arr = Array.from(source);
|
---|
659 | for (let i = 0, l = arr.length; i < l; i++) {
|
---|
660 | renderItem(arr[i], i);
|
---|
661 | }
|
---|
662 | } else {
|
---|
663 | const keys = Object.keys(source);
|
---|
664 | for (let i = 0, l = keys.length; i < l; i++) {
|
---|
665 | const key = keys[i];
|
---|
666 | renderItem(source[key], key, i);
|
---|
667 | }
|
---|
668 | }
|
---|
669 | }
|
---|
670 | }
|
---|
671 |
|
---|
672 | async function ssrRenderSuspense(push, { default: renderContent }) {
|
---|
673 | if (renderContent) {
|
---|
674 | renderContent();
|
---|
675 | } else {
|
---|
676 | push(`<!---->`);
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
|
---|
681 | if (typeof dir !== "function" && dir.getSSRProps) {
|
---|
682 | return dir.getSSRProps(
|
---|
683 | {
|
---|
684 | dir,
|
---|
685 | instance: ssrUtils.getComponentPublicInstance(instance.$),
|
---|
686 | value,
|
---|
687 | oldValue: void 0,
|
---|
688 | arg,
|
---|
689 | modifiers
|
---|
690 | },
|
---|
691 | null
|
---|
692 | ) || {};
|
---|
693 | }
|
---|
694 | return {};
|
---|
695 | }
|
---|
696 |
|
---|
697 | const ssrLooseEqual = looseEqual;
|
---|
698 | function ssrLooseContain(arr, value) {
|
---|
699 | return looseIndexOf(arr, value) > -1;
|
---|
700 | }
|
---|
701 | function ssrRenderDynamicModel(type, model, value) {
|
---|
702 | switch (type) {
|
---|
703 | case "radio":
|
---|
704 | return looseEqual(model, value) ? " checked" : "";
|
---|
705 | case "checkbox":
|
---|
706 | return (isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
|
---|
707 | default:
|
---|
708 | return ssrRenderAttr("value", model);
|
---|
709 | }
|
---|
710 | }
|
---|
711 | function ssrGetDynamicModelProps(existingProps = {}, model) {
|
---|
712 | const { type, value } = existingProps;
|
---|
713 | switch (type) {
|
---|
714 | case "radio":
|
---|
715 | return looseEqual(model, value) ? { checked: true } : null;
|
---|
716 | case "checkbox":
|
---|
717 | return (isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
|
---|
718 | default:
|
---|
719 | return { value: model };
|
---|
720 | }
|
---|
721 | }
|
---|
722 |
|
---|
723 | function ssrCompile(template, instance) {
|
---|
724 | {
|
---|
725 | throw new Error(
|
---|
726 | `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.`
|
---|
727 | );
|
---|
728 | }
|
---|
729 | }
|
---|
730 |
|
---|
731 | const {
|
---|
732 | createComponentInstance,
|
---|
733 | setCurrentRenderingInstance,
|
---|
734 | setupComponent,
|
---|
735 | renderComponentRoot,
|
---|
736 | normalizeVNode,
|
---|
737 | pushWarningContext,
|
---|
738 | popWarningContext
|
---|
739 | } = ssrUtils;
|
---|
740 | function createBuffer() {
|
---|
741 | let appendable = false;
|
---|
742 | const buffer = [];
|
---|
743 | return {
|
---|
744 | getBuffer() {
|
---|
745 | return buffer;
|
---|
746 | },
|
---|
747 | push(item) {
|
---|
748 | const isStringItem = isString(item);
|
---|
749 | if (appendable && isStringItem) {
|
---|
750 | buffer[buffer.length - 1] += item;
|
---|
751 | return;
|
---|
752 | }
|
---|
753 | buffer.push(item);
|
---|
754 | appendable = isStringItem;
|
---|
755 | if (isPromise(item) || isArray(item) && item.hasAsync) {
|
---|
756 | buffer.hasAsync = true;
|
---|
757 | }
|
---|
758 | }
|
---|
759 | };
|
---|
760 | }
|
---|
761 | function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
|
---|
762 | const instance = vnode.component = createComponentInstance(
|
---|
763 | vnode,
|
---|
764 | parentComponent,
|
---|
765 | null
|
---|
766 | );
|
---|
767 | if (!!(process.env.NODE_ENV !== "production")) pushWarningContext(vnode);
|
---|
768 | const res = setupComponent(
|
---|
769 | instance,
|
---|
770 | true
|
---|
771 | /* isSSR */
|
---|
772 | );
|
---|
773 | if (!!(process.env.NODE_ENV !== "production")) popWarningContext();
|
---|
774 | const hasAsyncSetup = isPromise(res);
|
---|
775 | let prefetches = instance.sp;
|
---|
776 | if (hasAsyncSetup || prefetches) {
|
---|
777 | const p = Promise.resolve(res).then(() => {
|
---|
778 | if (hasAsyncSetup) prefetches = instance.sp;
|
---|
779 | if (prefetches) {
|
---|
780 | return Promise.all(
|
---|
781 | prefetches.map((prefetch) => prefetch.call(instance.proxy))
|
---|
782 | );
|
---|
783 | }
|
---|
784 | }).catch(NOOP);
|
---|
785 | return p.then(() => renderComponentSubTree(instance, slotScopeId));
|
---|
786 | } else {
|
---|
787 | return renderComponentSubTree(instance, slotScopeId);
|
---|
788 | }
|
---|
789 | }
|
---|
790 | function renderComponentSubTree(instance, slotScopeId) {
|
---|
791 | if (!!(process.env.NODE_ENV !== "production")) pushWarningContext(instance.vnode);
|
---|
792 | const comp = instance.type;
|
---|
793 | const { getBuffer, push } = createBuffer();
|
---|
794 | if (isFunction(comp)) {
|
---|
795 | let root = renderComponentRoot(instance);
|
---|
796 | if (!comp.props) {
|
---|
797 | for (const key in instance.attrs) {
|
---|
798 | if (key.startsWith(`data-v-`)) {
|
---|
799 | (root.props || (root.props = {}))[key] = ``;
|
---|
800 | }
|
---|
801 | }
|
---|
802 | }
|
---|
803 | renderVNode(push, instance.subTree = root, instance, slotScopeId);
|
---|
804 | } else {
|
---|
805 | if ((!instance.render || instance.render === NOOP) && !instance.ssrRender && !comp.ssrRender && isString(comp.template)) {
|
---|
806 | comp.ssrRender = ssrCompile(comp.template);
|
---|
807 | }
|
---|
808 | const ssrRender = instance.ssrRender || comp.ssrRender;
|
---|
809 | if (ssrRender) {
|
---|
810 | let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
|
---|
811 | let hasCloned = false;
|
---|
812 | let cur = instance;
|
---|
813 | while (true) {
|
---|
814 | const scopeId = cur.vnode.scopeId;
|
---|
815 | if (scopeId) {
|
---|
816 | if (!hasCloned) {
|
---|
817 | attrs = { ...attrs };
|
---|
818 | hasCloned = true;
|
---|
819 | }
|
---|
820 | attrs[scopeId] = "";
|
---|
821 | }
|
---|
822 | const parent = cur.parent;
|
---|
823 | if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
---|
824 | cur = parent;
|
---|
825 | } else {
|
---|
826 | break;
|
---|
827 | }
|
---|
828 | }
|
---|
829 | if (slotScopeId) {
|
---|
830 | if (!hasCloned) attrs = { ...attrs };
|
---|
831 | const slotScopeIdList = slotScopeId.trim().split(" ");
|
---|
832 | for (let i = 0; i < slotScopeIdList.length; i++) {
|
---|
833 | attrs[slotScopeIdList[i]] = "";
|
---|
834 | }
|
---|
835 | }
|
---|
836 | const prev = setCurrentRenderingInstance(instance);
|
---|
837 | try {
|
---|
838 | ssrRender(
|
---|
839 | instance.proxy,
|
---|
840 | push,
|
---|
841 | instance,
|
---|
842 | attrs,
|
---|
843 | // compiler-optimized bindings
|
---|
844 | instance.props,
|
---|
845 | instance.setupState,
|
---|
846 | instance.data,
|
---|
847 | instance.ctx
|
---|
848 | );
|
---|
849 | } finally {
|
---|
850 | setCurrentRenderingInstance(prev);
|
---|
851 | }
|
---|
852 | } else if (instance.render && instance.render !== NOOP) {
|
---|
853 | renderVNode(
|
---|
854 | push,
|
---|
855 | instance.subTree = renderComponentRoot(instance),
|
---|
856 | instance,
|
---|
857 | slotScopeId
|
---|
858 | );
|
---|
859 | } else {
|
---|
860 | const componentName = comp.name || comp.__file || `<Anonymous>`;
|
---|
861 | warn$2(`Component ${componentName} is missing template or render function.`);
|
---|
862 | push(`<!---->`);
|
---|
863 | }
|
---|
864 | }
|
---|
865 | if (!!(process.env.NODE_ENV !== "production")) popWarningContext();
|
---|
866 | return getBuffer();
|
---|
867 | }
|
---|
868 | function renderVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
869 | const { type, shapeFlag, children, dirs, props } = vnode;
|
---|
870 | if (dirs) {
|
---|
871 | vnode.props = applySSRDirectives(vnode, props, dirs);
|
---|
872 | }
|
---|
873 | switch (type) {
|
---|
874 | case Text:
|
---|
875 | push(escapeHtml(children));
|
---|
876 | break;
|
---|
877 | case Comment:
|
---|
878 | push(
|
---|
879 | children ? `<!--${escapeHtmlComment(children)}-->` : `<!---->`
|
---|
880 | );
|
---|
881 | break;
|
---|
882 | case Static:
|
---|
883 | push(children);
|
---|
884 | break;
|
---|
885 | case Fragment:
|
---|
886 | if (vnode.slotScopeIds) {
|
---|
887 | slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
|
---|
888 | }
|
---|
889 | push(`<!--[-->`);
|
---|
890 | renderVNodeChildren(
|
---|
891 | push,
|
---|
892 | children,
|
---|
893 | parentComponent,
|
---|
894 | slotScopeId
|
---|
895 | );
|
---|
896 | push(`<!--]-->`);
|
---|
897 | break;
|
---|
898 | default:
|
---|
899 | if (shapeFlag & 1) {
|
---|
900 | renderElementVNode(push, vnode, parentComponent, slotScopeId);
|
---|
901 | } else if (shapeFlag & 6) {
|
---|
902 | push(renderComponentVNode(vnode, parentComponent, slotScopeId));
|
---|
903 | } else if (shapeFlag & 64) {
|
---|
904 | renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
|
---|
905 | } else if (shapeFlag & 128) {
|
---|
906 | renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
|
---|
907 | } else {
|
---|
908 | warn$2(
|
---|
909 | "[@vue/server-renderer] Invalid VNode type:",
|
---|
910 | type,
|
---|
911 | `(${typeof type})`
|
---|
912 | );
|
---|
913 | }
|
---|
914 | }
|
---|
915 | }
|
---|
916 | function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
|
---|
917 | for (let i = 0; i < children.length; i++) {
|
---|
918 | renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
|
---|
919 | }
|
---|
920 | }
|
---|
921 | function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
922 | const tag = vnode.type;
|
---|
923 | let { props, children, shapeFlag, scopeId } = vnode;
|
---|
924 | let openTag = `<${tag}`;
|
---|
925 | if (props) {
|
---|
926 | openTag += ssrRenderAttrs(props, tag);
|
---|
927 | }
|
---|
928 | if (scopeId) {
|
---|
929 | openTag += ` ${scopeId}`;
|
---|
930 | }
|
---|
931 | let curParent = parentComponent;
|
---|
932 | let curVnode = vnode;
|
---|
933 | while (curParent && curVnode === curParent.subTree) {
|
---|
934 | curVnode = curParent.vnode;
|
---|
935 | if (curVnode.scopeId) {
|
---|
936 | openTag += ` ${curVnode.scopeId}`;
|
---|
937 | }
|
---|
938 | curParent = curParent.parent;
|
---|
939 | }
|
---|
940 | if (slotScopeId) {
|
---|
941 | openTag += ` ${slotScopeId}`;
|
---|
942 | }
|
---|
943 | push(openTag + `>`);
|
---|
944 | if (!isVoidTag(tag)) {
|
---|
945 | let hasChildrenOverride = false;
|
---|
946 | if (props) {
|
---|
947 | if (props.innerHTML) {
|
---|
948 | hasChildrenOverride = true;
|
---|
949 | push(props.innerHTML);
|
---|
950 | } else if (props.textContent) {
|
---|
951 | hasChildrenOverride = true;
|
---|
952 | push(escapeHtml(props.textContent));
|
---|
953 | } else if (tag === "textarea" && props.value) {
|
---|
954 | hasChildrenOverride = true;
|
---|
955 | push(escapeHtml(props.value));
|
---|
956 | }
|
---|
957 | }
|
---|
958 | if (!hasChildrenOverride) {
|
---|
959 | if (shapeFlag & 8) {
|
---|
960 | push(escapeHtml(children));
|
---|
961 | } else if (shapeFlag & 16) {
|
---|
962 | renderVNodeChildren(
|
---|
963 | push,
|
---|
964 | children,
|
---|
965 | parentComponent,
|
---|
966 | slotScopeId
|
---|
967 | );
|
---|
968 | }
|
---|
969 | }
|
---|
970 | push(`</${tag}>`);
|
---|
971 | }
|
---|
972 | }
|
---|
973 | function applySSRDirectives(vnode, rawProps, dirs) {
|
---|
974 | const toMerge = [];
|
---|
975 | for (let i = 0; i < dirs.length; i++) {
|
---|
976 | const binding = dirs[i];
|
---|
977 | const {
|
---|
978 | dir: { getSSRProps }
|
---|
979 | } = binding;
|
---|
980 | if (getSSRProps) {
|
---|
981 | const props = getSSRProps(binding, vnode);
|
---|
982 | if (props) toMerge.push(props);
|
---|
983 | }
|
---|
984 | }
|
---|
985 | return mergeProps(rawProps || {}, ...toMerge);
|
---|
986 | }
|
---|
987 | function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
988 | const target = vnode.props && vnode.props.to;
|
---|
989 | const disabled = vnode.props && vnode.props.disabled;
|
---|
990 | if (!target) {
|
---|
991 | if (!disabled) {
|
---|
992 | warn$2(`[@vue/server-renderer] Teleport is missing target prop.`);
|
---|
993 | }
|
---|
994 | return [];
|
---|
995 | }
|
---|
996 | if (!isString(target)) {
|
---|
997 | warn$2(
|
---|
998 | `[@vue/server-renderer] Teleport target must be a query selector string.`
|
---|
999 | );
|
---|
1000 | return [];
|
---|
1001 | }
|
---|
1002 | ssrRenderTeleport(
|
---|
1003 | push,
|
---|
1004 | (push2) => {
|
---|
1005 | renderVNodeChildren(
|
---|
1006 | push2,
|
---|
1007 | vnode.children,
|
---|
1008 | parentComponent,
|
---|
1009 | slotScopeId
|
---|
1010 | );
|
---|
1011 | },
|
---|
1012 | target,
|
---|
1013 | disabled || disabled === "",
|
---|
1014 | parentComponent
|
---|
1015 | );
|
---|
1016 | }
|
---|
1017 |
|
---|
1018 | const { isVNode: isVNode$1 } = ssrUtils;
|
---|
1019 | function nestedUnrollBuffer(buffer, parentRet, startIndex) {
|
---|
1020 | if (!buffer.hasAsync) {
|
---|
1021 | return parentRet + unrollBufferSync$1(buffer);
|
---|
1022 | }
|
---|
1023 | let ret = parentRet;
|
---|
1024 | for (let i = startIndex; i < buffer.length; i += 1) {
|
---|
1025 | const item = buffer[i];
|
---|
1026 | if (isString(item)) {
|
---|
1027 | ret += item;
|
---|
1028 | continue;
|
---|
1029 | }
|
---|
1030 | if (isPromise(item)) {
|
---|
1031 | return item.then((nestedItem) => {
|
---|
1032 | buffer[i] = nestedItem;
|
---|
1033 | return nestedUnrollBuffer(buffer, ret, i);
|
---|
1034 | });
|
---|
1035 | }
|
---|
1036 | const result = nestedUnrollBuffer(item, ret, 0);
|
---|
1037 | if (isPromise(result)) {
|
---|
1038 | return result.then((nestedItem) => {
|
---|
1039 | buffer[i] = nestedItem;
|
---|
1040 | return nestedUnrollBuffer(buffer, "", i);
|
---|
1041 | });
|
---|
1042 | }
|
---|
1043 | ret = result;
|
---|
1044 | }
|
---|
1045 | return ret;
|
---|
1046 | }
|
---|
1047 | function unrollBuffer$1(buffer) {
|
---|
1048 | return nestedUnrollBuffer(buffer, "", 0);
|
---|
1049 | }
|
---|
1050 | function unrollBufferSync$1(buffer) {
|
---|
1051 | let ret = "";
|
---|
1052 | for (let i = 0; i < buffer.length; i++) {
|
---|
1053 | let item = buffer[i];
|
---|
1054 | if (isString(item)) {
|
---|
1055 | ret += item;
|
---|
1056 | } else {
|
---|
1057 | ret += unrollBufferSync$1(item);
|
---|
1058 | }
|
---|
1059 | }
|
---|
1060 | return ret;
|
---|
1061 | }
|
---|
1062 | async function renderToString(input, context = {}) {
|
---|
1063 | if (isVNode$1(input)) {
|
---|
1064 | return renderToString(createApp({ render: () => input }), context);
|
---|
1065 | }
|
---|
1066 | const vnode = createVNode(input._component, input._props);
|
---|
1067 | vnode.appContext = input._context;
|
---|
1068 | input.provide(ssrContextKey, context);
|
---|
1069 | const buffer = await renderComponentVNode(vnode);
|
---|
1070 | const result = await unrollBuffer$1(buffer);
|
---|
1071 | await resolveTeleports(context);
|
---|
1072 | if (context.__watcherHandles) {
|
---|
1073 | for (const unwatch of context.__watcherHandles) {
|
---|
1074 | unwatch();
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 | return result;
|
---|
1078 | }
|
---|
1079 | async function resolveTeleports(context) {
|
---|
1080 | if (context.__teleportBuffers) {
|
---|
1081 | context.teleports = context.teleports || {};
|
---|
1082 | for (const key in context.__teleportBuffers) {
|
---|
1083 | context.teleports[key] = await unrollBuffer$1(
|
---|
1084 | await Promise.all([context.__teleportBuffers[key]])
|
---|
1085 | );
|
---|
1086 | }
|
---|
1087 | }
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | const { isVNode } = ssrUtils;
|
---|
1091 | async function unrollBuffer(buffer, stream) {
|
---|
1092 | if (buffer.hasAsync) {
|
---|
1093 | for (let i = 0; i < buffer.length; i++) {
|
---|
1094 | let item = buffer[i];
|
---|
1095 | if (isPromise(item)) {
|
---|
1096 | item = await item;
|
---|
1097 | }
|
---|
1098 | if (isString(item)) {
|
---|
1099 | stream.push(item);
|
---|
1100 | } else {
|
---|
1101 | await unrollBuffer(item, stream);
|
---|
1102 | }
|
---|
1103 | }
|
---|
1104 | } else {
|
---|
1105 | unrollBufferSync(buffer, stream);
|
---|
1106 | }
|
---|
1107 | }
|
---|
1108 | function unrollBufferSync(buffer, stream) {
|
---|
1109 | for (let i = 0; i < buffer.length; i++) {
|
---|
1110 | let item = buffer[i];
|
---|
1111 | if (isString(item)) {
|
---|
1112 | stream.push(item);
|
---|
1113 | } else {
|
---|
1114 | unrollBufferSync(item, stream);
|
---|
1115 | }
|
---|
1116 | }
|
---|
1117 | }
|
---|
1118 | function renderToSimpleStream(input, context, stream) {
|
---|
1119 | if (isVNode(input)) {
|
---|
1120 | return renderToSimpleStream(
|
---|
1121 | createApp({ render: () => input }),
|
---|
1122 | context,
|
---|
1123 | stream
|
---|
1124 | );
|
---|
1125 | }
|
---|
1126 | const vnode = createVNode(input._component, input._props);
|
---|
1127 | vnode.appContext = input._context;
|
---|
1128 | input.provide(ssrContextKey, context);
|
---|
1129 | Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
|
---|
1130 | if (context.__watcherHandles) {
|
---|
1131 | for (const unwatch of context.__watcherHandles) {
|
---|
1132 | unwatch();
|
---|
1133 | }
|
---|
1134 | }
|
---|
1135 | }).then(() => stream.push(null)).catch((error) => {
|
---|
1136 | stream.destroy(error);
|
---|
1137 | });
|
---|
1138 | return stream;
|
---|
1139 | }
|
---|
1140 | function renderToStream(input, context = {}) {
|
---|
1141 | console.warn(
|
---|
1142 | `[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
|
---|
1143 | );
|
---|
1144 | return renderToNodeStream(input, context);
|
---|
1145 | }
|
---|
1146 | function renderToNodeStream(input, context = {}) {
|
---|
1147 | {
|
---|
1148 | throw new Error(
|
---|
1149 | `ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
|
---|
1150 | );
|
---|
1151 | }
|
---|
1152 | }
|
---|
1153 | function pipeToNodeWritable(input, context = {}, writable) {
|
---|
1154 | renderToSimpleStream(input, context, {
|
---|
1155 | push(content) {
|
---|
1156 | if (content != null) {
|
---|
1157 | writable.write(content);
|
---|
1158 | } else {
|
---|
1159 | writable.end();
|
---|
1160 | }
|
---|
1161 | },
|
---|
1162 | destroy(err) {
|
---|
1163 | writable.destroy(err);
|
---|
1164 | }
|
---|
1165 | });
|
---|
1166 | }
|
---|
1167 | function renderToWebStream(input, context = {}) {
|
---|
1168 | if (typeof ReadableStream !== "function") {
|
---|
1169 | throw new Error(
|
---|
1170 | `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.`
|
---|
1171 | );
|
---|
1172 | }
|
---|
1173 | const encoder = new TextEncoder();
|
---|
1174 | let cancelled = false;
|
---|
1175 | return new ReadableStream({
|
---|
1176 | start(controller) {
|
---|
1177 | renderToSimpleStream(input, context, {
|
---|
1178 | push(content) {
|
---|
1179 | if (cancelled) return;
|
---|
1180 | if (content != null) {
|
---|
1181 | controller.enqueue(encoder.encode(content));
|
---|
1182 | } else {
|
---|
1183 | controller.close();
|
---|
1184 | }
|
---|
1185 | },
|
---|
1186 | destroy(err) {
|
---|
1187 | controller.error(err);
|
---|
1188 | }
|
---|
1189 | });
|
---|
1190 | },
|
---|
1191 | cancel() {
|
---|
1192 | cancelled = true;
|
---|
1193 | }
|
---|
1194 | });
|
---|
1195 | }
|
---|
1196 | function pipeToWebWritable(input, context = {}, writable) {
|
---|
1197 | const writer = writable.getWriter();
|
---|
1198 | const encoder = new TextEncoder();
|
---|
1199 | let hasReady = false;
|
---|
1200 | try {
|
---|
1201 | hasReady = isPromise(writer.ready);
|
---|
1202 | } catch (e) {
|
---|
1203 | }
|
---|
1204 | renderToSimpleStream(input, context, {
|
---|
1205 | async push(content) {
|
---|
1206 | if (hasReady) {
|
---|
1207 | await writer.ready;
|
---|
1208 | }
|
---|
1209 | if (content != null) {
|
---|
1210 | return writer.write(encoder.encode(content));
|
---|
1211 | } else {
|
---|
1212 | return writer.close();
|
---|
1213 | }
|
---|
1214 | },
|
---|
1215 | destroy(err) {
|
---|
1216 | console.log(err);
|
---|
1217 | writer.close();
|
---|
1218 | }
|
---|
1219 | });
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | initDirectivesForSSR();
|
---|
1223 |
|
---|
1224 | 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 };
|
---|