[57e58a3] | 1 | /**
|
---|
| 2 | * @vue/server-renderer v3.5.13
|
---|
| 3 | * (c) 2018-present Yuxi (Evan) You and Vue contributors
|
---|
| 4 | * @license MIT
|
---|
| 5 | **/
|
---|
| 6 | 'use strict';
|
---|
| 7 |
|
---|
| 8 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
| 9 |
|
---|
| 10 | var Vue = require('vue');
|
---|
| 11 | var shared = require('@vue/shared');
|
---|
| 12 | var compilerSsr = require('@vue/compiler-ssr');
|
---|
| 13 |
|
---|
| 14 | function _interopNamespaceDefault(e) {
|
---|
| 15 | var n = Object.create(null);
|
---|
| 16 | if (e) {
|
---|
| 17 | for (var k in e) {
|
---|
| 18 | n[k] = e[k];
|
---|
| 19 | }
|
---|
| 20 | }
|
---|
| 21 | n.default = e;
|
---|
| 22 | return Object.freeze(n);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
|
---|
| 26 |
|
---|
| 27 | const shouldIgnoreProp = /* @__PURE__ */ shared.makeMap(
|
---|
| 28 | `,key,ref,innerHTML,textContent,ref_key,ref_for`
|
---|
| 29 | );
|
---|
| 30 | function ssrRenderAttrs(props, tag) {
|
---|
| 31 | let ret = "";
|
---|
| 32 | for (const key in props) {
|
---|
| 33 | if (shouldIgnoreProp(key) || shared.isOn(key) || tag === "textarea" && key === "value") {
|
---|
| 34 | continue;
|
---|
| 35 | }
|
---|
| 36 | const value = props[key];
|
---|
| 37 | if (key === "class") {
|
---|
| 38 | ret += ` class="${ssrRenderClass(value)}"`;
|
---|
| 39 | } else if (key === "style") {
|
---|
| 40 | ret += ` style="${ssrRenderStyle(value)}"`;
|
---|
| 41 | } else if (key === "className") {
|
---|
| 42 | ret += ` class="${String(value)}"`;
|
---|
| 43 | } else {
|
---|
| 44 | ret += ssrRenderDynamicAttr(key, value, tag);
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | return ret;
|
---|
| 48 | }
|
---|
| 49 | function ssrRenderDynamicAttr(key, value, tag) {
|
---|
| 50 | if (!shared.isRenderableAttrValue(value)) {
|
---|
| 51 | return ``;
|
---|
| 52 | }
|
---|
| 53 | const attrKey = tag && (tag.indexOf("-") > 0 || shared.isSVGTag(tag)) ? key : shared.propsToAttrMap[key] || key.toLowerCase();
|
---|
| 54 | if (shared.isBooleanAttr(attrKey)) {
|
---|
| 55 | return shared.includeBooleanAttr(value) ? ` ${attrKey}` : ``;
|
---|
| 56 | } else if (shared.isSSRSafeAttrName(attrKey)) {
|
---|
| 57 | return value === "" ? ` ${attrKey}` : ` ${attrKey}="${shared.escapeHtml(value)}"`;
|
---|
| 58 | } else {
|
---|
| 59 | console.warn(
|
---|
| 60 | `[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
|
---|
| 61 | );
|
---|
| 62 | return ``;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | function ssrRenderAttr(key, value) {
|
---|
| 66 | if (!shared.isRenderableAttrValue(value)) {
|
---|
| 67 | return ``;
|
---|
| 68 | }
|
---|
| 69 | return ` ${key}="${shared.escapeHtml(value)}"`;
|
---|
| 70 | }
|
---|
| 71 | function ssrRenderClass(raw) {
|
---|
| 72 | return shared.escapeHtml(shared.normalizeClass(raw));
|
---|
| 73 | }
|
---|
| 74 | function ssrRenderStyle(raw) {
|
---|
| 75 | if (!raw) {
|
---|
| 76 | return "";
|
---|
| 77 | }
|
---|
| 78 | if (shared.isString(raw)) {
|
---|
| 79 | return shared.escapeHtml(raw);
|
---|
| 80 | }
|
---|
| 81 | const styles = shared.normalizeStyle(raw);
|
---|
| 82 | return shared.escapeHtml(shared.stringifyStyle(styles));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | function ssrRenderComponent(comp, props = null, children = null, parentComponent = null, slotScopeId) {
|
---|
| 86 | return renderComponentVNode(
|
---|
| 87 | Vue.createVNode(comp, props, children),
|
---|
| 88 | parentComponent,
|
---|
| 89 | slotScopeId
|
---|
| 90 | );
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | const { ensureValidVNode } = Vue.ssrUtils;
|
---|
| 94 | function ssrRenderSlot(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId) {
|
---|
| 95 | push(`<!--[-->`);
|
---|
| 96 | ssrRenderSlotInner(
|
---|
| 97 | slots,
|
---|
| 98 | slotName,
|
---|
| 99 | slotProps,
|
---|
| 100 | fallbackRenderFn,
|
---|
| 101 | push,
|
---|
| 102 | parentComponent,
|
---|
| 103 | slotScopeId
|
---|
| 104 | );
|
---|
| 105 | push(`<!--]-->`);
|
---|
| 106 | }
|
---|
| 107 | function ssrRenderSlotInner(slots, slotName, slotProps, fallbackRenderFn, push, parentComponent, slotScopeId, transition) {
|
---|
| 108 | const slotFn = slots[slotName];
|
---|
| 109 | if (slotFn) {
|
---|
| 110 | const slotBuffer = [];
|
---|
| 111 | const bufferedPush = (item) => {
|
---|
| 112 | slotBuffer.push(item);
|
---|
| 113 | };
|
---|
| 114 | const ret = slotFn(
|
---|
| 115 | slotProps,
|
---|
| 116 | bufferedPush,
|
---|
| 117 | parentComponent,
|
---|
| 118 | slotScopeId ? " " + slotScopeId : ""
|
---|
| 119 | );
|
---|
| 120 | if (shared.isArray(ret)) {
|
---|
| 121 | const validSlotContent = ensureValidVNode(ret);
|
---|
| 122 | if (validSlotContent) {
|
---|
| 123 | renderVNodeChildren(
|
---|
| 124 | push,
|
---|
| 125 | validSlotContent,
|
---|
| 126 | parentComponent,
|
---|
| 127 | slotScopeId
|
---|
| 128 | );
|
---|
| 129 | } else if (fallbackRenderFn) {
|
---|
| 130 | fallbackRenderFn();
|
---|
| 131 | }
|
---|
| 132 | } else {
|
---|
| 133 | let isEmptySlot = true;
|
---|
| 134 | if (transition) {
|
---|
| 135 | isEmptySlot = false;
|
---|
| 136 | } else {
|
---|
| 137 | for (let i = 0; i < slotBuffer.length; i++) {
|
---|
| 138 | if (!isComment(slotBuffer[i])) {
|
---|
| 139 | isEmptySlot = false;
|
---|
| 140 | break;
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | if (isEmptySlot) {
|
---|
| 145 | if (fallbackRenderFn) {
|
---|
| 146 | fallbackRenderFn();
|
---|
| 147 | }
|
---|
| 148 | } else {
|
---|
| 149 | let start = 0;
|
---|
| 150 | let end = slotBuffer.length;
|
---|
| 151 | if (transition && slotBuffer[0] === "<!--[-->" && slotBuffer[end - 1] === "<!--]-->") {
|
---|
| 152 | start++;
|
---|
| 153 | end--;
|
---|
| 154 | }
|
---|
| 155 | for (let i = start; i < end; i++) {
|
---|
| 156 | push(slotBuffer[i]);
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
| 160 | } else if (fallbackRenderFn) {
|
---|
| 161 | fallbackRenderFn();
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 | const commentTestRE = /^<!--[\s\S]*-->$/;
|
---|
| 165 | const commentRE = /<!--[^]*?-->/gm;
|
---|
| 166 | function isComment(item) {
|
---|
| 167 | if (typeof item !== "string" || !commentTestRE.test(item)) return false;
|
---|
| 168 | if (item.length <= 8) return true;
|
---|
| 169 | return !item.replace(commentRE, "").trim();
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | function ssrRenderTeleport(parentPush, contentRenderFn, target, disabled, parentComponent) {
|
---|
| 173 | parentPush("<!--teleport start-->");
|
---|
| 174 | const context = parentComponent.appContext.provides[Vue.ssrContextKey];
|
---|
| 175 | const teleportBuffers = context.__teleportBuffers || (context.__teleportBuffers = {});
|
---|
| 176 | const targetBuffer = teleportBuffers[target] || (teleportBuffers[target] = []);
|
---|
| 177 | const bufferIndex = targetBuffer.length;
|
---|
| 178 | let teleportContent;
|
---|
| 179 | if (disabled) {
|
---|
| 180 | contentRenderFn(parentPush);
|
---|
| 181 | teleportContent = `<!--teleport start anchor--><!--teleport anchor-->`;
|
---|
| 182 | } else {
|
---|
| 183 | const { getBuffer, push } = createBuffer();
|
---|
| 184 | push(`<!--teleport start anchor-->`);
|
---|
| 185 | contentRenderFn(push);
|
---|
| 186 | push(`<!--teleport anchor-->`);
|
---|
| 187 | teleportContent = getBuffer();
|
---|
| 188 | }
|
---|
| 189 | targetBuffer.splice(bufferIndex, 0, teleportContent);
|
---|
| 190 | parentPush("<!--teleport end-->");
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | function ssrInterpolate(value) {
|
---|
| 194 | return shared.escapeHtml(shared.toDisplayString(value));
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | function ssrRenderList(source, renderItem) {
|
---|
| 198 | if (shared.isArray(source) || shared.isString(source)) {
|
---|
| 199 | for (let i = 0, l = source.length; i < l; i++) {
|
---|
| 200 | renderItem(source[i], i);
|
---|
| 201 | }
|
---|
| 202 | } else if (typeof source === "number") {
|
---|
| 203 | for (let i = 0; i < source; i++) {
|
---|
| 204 | renderItem(i + 1, i);
|
---|
| 205 | }
|
---|
| 206 | } else if (shared.isObject(source)) {
|
---|
| 207 | if (source[Symbol.iterator]) {
|
---|
| 208 | const arr = Array.from(source);
|
---|
| 209 | for (let i = 0, l = arr.length; i < l; i++) {
|
---|
| 210 | renderItem(arr[i], i);
|
---|
| 211 | }
|
---|
| 212 | } else {
|
---|
| 213 | const keys = Object.keys(source);
|
---|
| 214 | for (let i = 0, l = keys.length; i < l; i++) {
|
---|
| 215 | const key = keys[i];
|
---|
| 216 | renderItem(source[key], key, i);
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | async function ssrRenderSuspense(push, { default: renderContent }) {
|
---|
| 223 | if (renderContent) {
|
---|
| 224 | renderContent();
|
---|
| 225 | } else {
|
---|
| 226 | push(`<!---->`);
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
|
---|
| 231 | if (typeof dir !== "function" && dir.getSSRProps) {
|
---|
| 232 | return dir.getSSRProps(
|
---|
| 233 | {
|
---|
| 234 | dir,
|
---|
| 235 | instance: Vue.ssrUtils.getComponentPublicInstance(instance.$),
|
---|
| 236 | value,
|
---|
| 237 | oldValue: void 0,
|
---|
| 238 | arg,
|
---|
| 239 | modifiers
|
---|
| 240 | },
|
---|
| 241 | null
|
---|
| 242 | ) || {};
|
---|
| 243 | }
|
---|
| 244 | return {};
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | const ssrLooseEqual = shared.looseEqual;
|
---|
| 248 | function ssrLooseContain(arr, value) {
|
---|
| 249 | return shared.looseIndexOf(arr, value) > -1;
|
---|
| 250 | }
|
---|
| 251 | function ssrRenderDynamicModel(type, model, value) {
|
---|
| 252 | switch (type) {
|
---|
| 253 | case "radio":
|
---|
| 254 | return shared.looseEqual(model, value) ? " checked" : "";
|
---|
| 255 | case "checkbox":
|
---|
| 256 | return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
|
---|
| 257 | default:
|
---|
| 258 | return ssrRenderAttr("value", model);
|
---|
| 259 | }
|
---|
| 260 | }
|
---|
| 261 | function ssrGetDynamicModelProps(existingProps = {}, model) {
|
---|
| 262 | const { type, value } = existingProps;
|
---|
| 263 | switch (type) {
|
---|
| 264 | case "radio":
|
---|
| 265 | return shared.looseEqual(model, value) ? { checked: true } : null;
|
---|
| 266 | case "checkbox":
|
---|
| 267 | return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
|
---|
| 268 | default:
|
---|
| 269 | return { value: model };
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | var helpers = /*#__PURE__*/Object.freeze({
|
---|
| 274 | __proto__: null,
|
---|
| 275 | ssrGetDirectiveProps: ssrGetDirectiveProps,
|
---|
| 276 | ssrGetDynamicModelProps: ssrGetDynamicModelProps,
|
---|
| 277 | ssrIncludeBooleanAttr: shared.includeBooleanAttr,
|
---|
| 278 | ssrInterpolate: ssrInterpolate,
|
---|
| 279 | ssrLooseContain: ssrLooseContain,
|
---|
| 280 | ssrLooseEqual: ssrLooseEqual,
|
---|
| 281 | ssrRenderAttr: ssrRenderAttr,
|
---|
| 282 | ssrRenderAttrs: ssrRenderAttrs,
|
---|
| 283 | ssrRenderClass: ssrRenderClass,
|
---|
| 284 | ssrRenderComponent: ssrRenderComponent,
|
---|
| 285 | ssrRenderDynamicAttr: ssrRenderDynamicAttr,
|
---|
| 286 | ssrRenderDynamicModel: ssrRenderDynamicModel,
|
---|
| 287 | ssrRenderList: ssrRenderList,
|
---|
| 288 | ssrRenderSlot: ssrRenderSlot,
|
---|
| 289 | ssrRenderSlotInner: ssrRenderSlotInner,
|
---|
| 290 | ssrRenderStyle: ssrRenderStyle,
|
---|
| 291 | ssrRenderSuspense: ssrRenderSuspense,
|
---|
| 292 | ssrRenderTeleport: ssrRenderTeleport,
|
---|
| 293 | ssrRenderVNode: renderVNode
|
---|
| 294 | });
|
---|
| 295 |
|
---|
| 296 | const compileCache = /* @__PURE__ */ Object.create(null);
|
---|
| 297 | function ssrCompile(template, instance) {
|
---|
| 298 | const Component = instance.type;
|
---|
| 299 | const { isCustomElement, compilerOptions } = instance.appContext.config;
|
---|
| 300 | const { delimiters, compilerOptions: componentCompilerOptions } = Component;
|
---|
| 301 | const finalCompilerOptions = shared.extend(
|
---|
| 302 | shared.extend(
|
---|
| 303 | {
|
---|
| 304 | isCustomElement,
|
---|
| 305 | delimiters
|
---|
| 306 | },
|
---|
| 307 | compilerOptions
|
---|
| 308 | ),
|
---|
| 309 | componentCompilerOptions
|
---|
| 310 | );
|
---|
| 311 | finalCompilerOptions.isCustomElement = finalCompilerOptions.isCustomElement || shared.NO;
|
---|
| 312 | finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
|
---|
| 313 | const cacheKey = JSON.stringify(
|
---|
| 314 | {
|
---|
| 315 | template,
|
---|
| 316 | compilerOptions: finalCompilerOptions
|
---|
| 317 | },
|
---|
| 318 | (key, value) => {
|
---|
| 319 | return shared.isFunction(value) ? value.toString() : value;
|
---|
| 320 | }
|
---|
| 321 | );
|
---|
| 322 | const cached = compileCache[cacheKey];
|
---|
| 323 | if (cached) {
|
---|
| 324 | return cached;
|
---|
| 325 | }
|
---|
| 326 | finalCompilerOptions.onError = (err) => {
|
---|
| 327 | {
|
---|
| 328 | throw err;
|
---|
| 329 | }
|
---|
| 330 | };
|
---|
| 331 | const { code } = compilerSsr.compile(template, finalCompilerOptions);
|
---|
| 332 | const requireMap = {
|
---|
| 333 | vue: Vue__namespace,
|
---|
| 334 | "vue/server-renderer": helpers
|
---|
| 335 | };
|
---|
| 336 | const fakeRequire = (id) => requireMap[id];
|
---|
| 337 | return compileCache[cacheKey] = Function("require", code)(fakeRequire);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
| 340 | const {
|
---|
| 341 | createComponentInstance,
|
---|
| 342 | setCurrentRenderingInstance,
|
---|
| 343 | setupComponent,
|
---|
| 344 | renderComponentRoot,
|
---|
| 345 | normalizeVNode,
|
---|
| 346 | pushWarningContext,
|
---|
| 347 | popWarningContext
|
---|
| 348 | } = Vue.ssrUtils;
|
---|
| 349 | function createBuffer() {
|
---|
| 350 | let appendable = false;
|
---|
| 351 | const buffer = [];
|
---|
| 352 | return {
|
---|
| 353 | getBuffer() {
|
---|
| 354 | return buffer;
|
---|
| 355 | },
|
---|
| 356 | push(item) {
|
---|
| 357 | const isStringItem = shared.isString(item);
|
---|
| 358 | if (appendable && isStringItem) {
|
---|
| 359 | buffer[buffer.length - 1] += item;
|
---|
| 360 | return;
|
---|
| 361 | }
|
---|
| 362 | buffer.push(item);
|
---|
| 363 | appendable = isStringItem;
|
---|
| 364 | if (shared.isPromise(item) || shared.isArray(item) && item.hasAsync) {
|
---|
| 365 | buffer.hasAsync = true;
|
---|
| 366 | }
|
---|
| 367 | }
|
---|
| 368 | };
|
---|
| 369 | }
|
---|
| 370 | function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
|
---|
| 371 | const instance = vnode.component = createComponentInstance(
|
---|
| 372 | vnode,
|
---|
| 373 | parentComponent,
|
---|
| 374 | null
|
---|
| 375 | );
|
---|
| 376 | const res = setupComponent(
|
---|
| 377 | instance,
|
---|
| 378 | true
|
---|
| 379 | /* isSSR */
|
---|
| 380 | );
|
---|
| 381 | const hasAsyncSetup = shared.isPromise(res);
|
---|
| 382 | let prefetches = instance.sp;
|
---|
| 383 | if (hasAsyncSetup || prefetches) {
|
---|
| 384 | const p = Promise.resolve(res).then(() => {
|
---|
| 385 | if (hasAsyncSetup) prefetches = instance.sp;
|
---|
| 386 | if (prefetches) {
|
---|
| 387 | return Promise.all(
|
---|
| 388 | prefetches.map((prefetch) => prefetch.call(instance.proxy))
|
---|
| 389 | );
|
---|
| 390 | }
|
---|
| 391 | }).catch(shared.NOOP);
|
---|
| 392 | return p.then(() => renderComponentSubTree(instance, slotScopeId));
|
---|
| 393 | } else {
|
---|
| 394 | return renderComponentSubTree(instance, slotScopeId);
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 | function renderComponentSubTree(instance, slotScopeId) {
|
---|
| 398 | const comp = instance.type;
|
---|
| 399 | const { getBuffer, push } = createBuffer();
|
---|
| 400 | if (shared.isFunction(comp)) {
|
---|
| 401 | let root = renderComponentRoot(instance);
|
---|
| 402 | if (!comp.props) {
|
---|
| 403 | for (const key in instance.attrs) {
|
---|
| 404 | if (key.startsWith(`data-v-`)) {
|
---|
| 405 | (root.props || (root.props = {}))[key] = ``;
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 | renderVNode(push, instance.subTree = root, instance, slotScopeId);
|
---|
| 410 | } else {
|
---|
| 411 | if ((!instance.render || instance.render === shared.NOOP) && !instance.ssrRender && !comp.ssrRender && shared.isString(comp.template)) {
|
---|
| 412 | comp.ssrRender = ssrCompile(comp.template, instance);
|
---|
| 413 | }
|
---|
| 414 | const ssrRender = instance.ssrRender || comp.ssrRender;
|
---|
| 415 | if (ssrRender) {
|
---|
| 416 | let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
|
---|
| 417 | let hasCloned = false;
|
---|
| 418 | let cur = instance;
|
---|
| 419 | while (true) {
|
---|
| 420 | const scopeId = cur.vnode.scopeId;
|
---|
| 421 | if (scopeId) {
|
---|
| 422 | if (!hasCloned) {
|
---|
| 423 | attrs = { ...attrs };
|
---|
| 424 | hasCloned = true;
|
---|
| 425 | }
|
---|
| 426 | attrs[scopeId] = "";
|
---|
| 427 | }
|
---|
| 428 | const parent = cur.parent;
|
---|
| 429 | if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
---|
| 430 | cur = parent;
|
---|
| 431 | } else {
|
---|
| 432 | break;
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | if (slotScopeId) {
|
---|
| 436 | if (!hasCloned) attrs = { ...attrs };
|
---|
| 437 | const slotScopeIdList = slotScopeId.trim().split(" ");
|
---|
| 438 | for (let i = 0; i < slotScopeIdList.length; i++) {
|
---|
| 439 | attrs[slotScopeIdList[i]] = "";
|
---|
| 440 | }
|
---|
| 441 | }
|
---|
| 442 | const prev = setCurrentRenderingInstance(instance);
|
---|
| 443 | try {
|
---|
| 444 | ssrRender(
|
---|
| 445 | instance.proxy,
|
---|
| 446 | push,
|
---|
| 447 | instance,
|
---|
| 448 | attrs,
|
---|
| 449 | // compiler-optimized bindings
|
---|
| 450 | instance.props,
|
---|
| 451 | instance.setupState,
|
---|
| 452 | instance.data,
|
---|
| 453 | instance.ctx
|
---|
| 454 | );
|
---|
| 455 | } finally {
|
---|
| 456 | setCurrentRenderingInstance(prev);
|
---|
| 457 | }
|
---|
| 458 | } else if (instance.render && instance.render !== shared.NOOP) {
|
---|
| 459 | renderVNode(
|
---|
| 460 | push,
|
---|
| 461 | instance.subTree = renderComponentRoot(instance),
|
---|
| 462 | instance,
|
---|
| 463 | slotScopeId
|
---|
| 464 | );
|
---|
| 465 | } else {
|
---|
| 466 | const componentName = comp.name || comp.__file || `<Anonymous>`;
|
---|
| 467 | Vue.warn(`Component ${componentName} is missing template or render function.`);
|
---|
| 468 | push(`<!---->`);
|
---|
| 469 | }
|
---|
| 470 | }
|
---|
| 471 | return getBuffer();
|
---|
| 472 | }
|
---|
| 473 | function renderVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
| 474 | const { type, shapeFlag, children, dirs, props } = vnode;
|
---|
| 475 | if (dirs) {
|
---|
| 476 | vnode.props = applySSRDirectives(vnode, props, dirs);
|
---|
| 477 | }
|
---|
| 478 | switch (type) {
|
---|
| 479 | case Vue.Text:
|
---|
| 480 | push(shared.escapeHtml(children));
|
---|
| 481 | break;
|
---|
| 482 | case Vue.Comment:
|
---|
| 483 | push(
|
---|
| 484 | children ? `<!--${shared.escapeHtmlComment(children)}-->` : `<!---->`
|
---|
| 485 | );
|
---|
| 486 | break;
|
---|
| 487 | case Vue.Static:
|
---|
| 488 | push(children);
|
---|
| 489 | break;
|
---|
| 490 | case Vue.Fragment:
|
---|
| 491 | if (vnode.slotScopeIds) {
|
---|
| 492 | slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
|
---|
| 493 | }
|
---|
| 494 | push(`<!--[-->`);
|
---|
| 495 | renderVNodeChildren(
|
---|
| 496 | push,
|
---|
| 497 | children,
|
---|
| 498 | parentComponent,
|
---|
| 499 | slotScopeId
|
---|
| 500 | );
|
---|
| 501 | push(`<!--]-->`);
|
---|
| 502 | break;
|
---|
| 503 | default:
|
---|
| 504 | if (shapeFlag & 1) {
|
---|
| 505 | renderElementVNode(push, vnode, parentComponent, slotScopeId);
|
---|
| 506 | } else if (shapeFlag & 6) {
|
---|
| 507 | push(renderComponentVNode(vnode, parentComponent, slotScopeId));
|
---|
| 508 | } else if (shapeFlag & 64) {
|
---|
| 509 | renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
|
---|
| 510 | } else if (shapeFlag & 128) {
|
---|
| 511 | renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
|
---|
| 512 | } else {
|
---|
| 513 | Vue.warn(
|
---|
| 514 | "[@vue/server-renderer] Invalid VNode type:",
|
---|
| 515 | type,
|
---|
| 516 | `(${typeof type})`
|
---|
| 517 | );
|
---|
| 518 | }
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
|
---|
| 522 | for (let i = 0; i < children.length; i++) {
|
---|
| 523 | renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
|
---|
| 524 | }
|
---|
| 525 | }
|
---|
| 526 | function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
| 527 | const tag = vnode.type;
|
---|
| 528 | let { props, children, shapeFlag, scopeId } = vnode;
|
---|
| 529 | let openTag = `<${tag}`;
|
---|
| 530 | if (props) {
|
---|
| 531 | openTag += ssrRenderAttrs(props, tag);
|
---|
| 532 | }
|
---|
| 533 | if (scopeId) {
|
---|
| 534 | openTag += ` ${scopeId}`;
|
---|
| 535 | }
|
---|
| 536 | let curParent = parentComponent;
|
---|
| 537 | let curVnode = vnode;
|
---|
| 538 | while (curParent && curVnode === curParent.subTree) {
|
---|
| 539 | curVnode = curParent.vnode;
|
---|
| 540 | if (curVnode.scopeId) {
|
---|
| 541 | openTag += ` ${curVnode.scopeId}`;
|
---|
| 542 | }
|
---|
| 543 | curParent = curParent.parent;
|
---|
| 544 | }
|
---|
| 545 | if (slotScopeId) {
|
---|
| 546 | openTag += ` ${slotScopeId}`;
|
---|
| 547 | }
|
---|
| 548 | push(openTag + `>`);
|
---|
| 549 | if (!shared.isVoidTag(tag)) {
|
---|
| 550 | let hasChildrenOverride = false;
|
---|
| 551 | if (props) {
|
---|
| 552 | if (props.innerHTML) {
|
---|
| 553 | hasChildrenOverride = true;
|
---|
| 554 | push(props.innerHTML);
|
---|
| 555 | } else if (props.textContent) {
|
---|
| 556 | hasChildrenOverride = true;
|
---|
| 557 | push(shared.escapeHtml(props.textContent));
|
---|
| 558 | } else if (tag === "textarea" && props.value) {
|
---|
| 559 | hasChildrenOverride = true;
|
---|
| 560 | push(shared.escapeHtml(props.value));
|
---|
| 561 | }
|
---|
| 562 | }
|
---|
| 563 | if (!hasChildrenOverride) {
|
---|
| 564 | if (shapeFlag & 8) {
|
---|
| 565 | push(shared.escapeHtml(children));
|
---|
| 566 | } else if (shapeFlag & 16) {
|
---|
| 567 | renderVNodeChildren(
|
---|
| 568 | push,
|
---|
| 569 | children,
|
---|
| 570 | parentComponent,
|
---|
| 571 | slotScopeId
|
---|
| 572 | );
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
| 575 | push(`</${tag}>`);
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | function applySSRDirectives(vnode, rawProps, dirs) {
|
---|
| 579 | const toMerge = [];
|
---|
| 580 | for (let i = 0; i < dirs.length; i++) {
|
---|
| 581 | const binding = dirs[i];
|
---|
| 582 | const {
|
---|
| 583 | dir: { getSSRProps }
|
---|
| 584 | } = binding;
|
---|
| 585 | if (getSSRProps) {
|
---|
| 586 | const props = getSSRProps(binding, vnode);
|
---|
| 587 | if (props) toMerge.push(props);
|
---|
| 588 | }
|
---|
| 589 | }
|
---|
| 590 | return Vue.mergeProps(rawProps || {}, ...toMerge);
|
---|
| 591 | }
|
---|
| 592 | function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
|
---|
| 593 | const target = vnode.props && vnode.props.to;
|
---|
| 594 | const disabled = vnode.props && vnode.props.disabled;
|
---|
| 595 | if (!target) {
|
---|
| 596 | if (!disabled) {
|
---|
| 597 | Vue.warn(`[@vue/server-renderer] Teleport is missing target prop.`);
|
---|
| 598 | }
|
---|
| 599 | return [];
|
---|
| 600 | }
|
---|
| 601 | if (!shared.isString(target)) {
|
---|
| 602 | Vue.warn(
|
---|
| 603 | `[@vue/server-renderer] Teleport target must be a query selector string.`
|
---|
| 604 | );
|
---|
| 605 | return [];
|
---|
| 606 | }
|
---|
| 607 | ssrRenderTeleport(
|
---|
| 608 | push,
|
---|
| 609 | (push2) => {
|
---|
| 610 | renderVNodeChildren(
|
---|
| 611 | push2,
|
---|
| 612 | vnode.children,
|
---|
| 613 | parentComponent,
|
---|
| 614 | slotScopeId
|
---|
| 615 | );
|
---|
| 616 | },
|
---|
| 617 | target,
|
---|
| 618 | disabled || disabled === "",
|
---|
| 619 | parentComponent
|
---|
| 620 | );
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | const { isVNode: isVNode$1 } = Vue.ssrUtils;
|
---|
| 624 | function nestedUnrollBuffer(buffer, parentRet, startIndex) {
|
---|
| 625 | if (!buffer.hasAsync) {
|
---|
| 626 | return parentRet + unrollBufferSync$1(buffer);
|
---|
| 627 | }
|
---|
| 628 | let ret = parentRet;
|
---|
| 629 | for (let i = startIndex; i < buffer.length; i += 1) {
|
---|
| 630 | const item = buffer[i];
|
---|
| 631 | if (shared.isString(item)) {
|
---|
| 632 | ret += item;
|
---|
| 633 | continue;
|
---|
| 634 | }
|
---|
| 635 | if (shared.isPromise(item)) {
|
---|
| 636 | return item.then((nestedItem) => {
|
---|
| 637 | buffer[i] = nestedItem;
|
---|
| 638 | return nestedUnrollBuffer(buffer, ret, i);
|
---|
| 639 | });
|
---|
| 640 | }
|
---|
| 641 | const result = nestedUnrollBuffer(item, ret, 0);
|
---|
| 642 | if (shared.isPromise(result)) {
|
---|
| 643 | return result.then((nestedItem) => {
|
---|
| 644 | buffer[i] = nestedItem;
|
---|
| 645 | return nestedUnrollBuffer(buffer, "", i);
|
---|
| 646 | });
|
---|
| 647 | }
|
---|
| 648 | ret = result;
|
---|
| 649 | }
|
---|
| 650 | return ret;
|
---|
| 651 | }
|
---|
| 652 | function unrollBuffer$1(buffer) {
|
---|
| 653 | return nestedUnrollBuffer(buffer, "", 0);
|
---|
| 654 | }
|
---|
| 655 | function unrollBufferSync$1(buffer) {
|
---|
| 656 | let ret = "";
|
---|
| 657 | for (let i = 0; i < buffer.length; i++) {
|
---|
| 658 | let item = buffer[i];
|
---|
| 659 | if (shared.isString(item)) {
|
---|
| 660 | ret += item;
|
---|
| 661 | } else {
|
---|
| 662 | ret += unrollBufferSync$1(item);
|
---|
| 663 | }
|
---|
| 664 | }
|
---|
| 665 | return ret;
|
---|
| 666 | }
|
---|
| 667 | async function renderToString(input, context = {}) {
|
---|
| 668 | if (isVNode$1(input)) {
|
---|
| 669 | return renderToString(Vue.createApp({ render: () => input }), context);
|
---|
| 670 | }
|
---|
| 671 | const vnode = Vue.createVNode(input._component, input._props);
|
---|
| 672 | vnode.appContext = input._context;
|
---|
| 673 | input.provide(Vue.ssrContextKey, context);
|
---|
| 674 | const buffer = await renderComponentVNode(vnode);
|
---|
| 675 | const result = await unrollBuffer$1(buffer);
|
---|
| 676 | await resolveTeleports(context);
|
---|
| 677 | if (context.__watcherHandles) {
|
---|
| 678 | for (const unwatch of context.__watcherHandles) {
|
---|
| 679 | unwatch();
|
---|
| 680 | }
|
---|
| 681 | }
|
---|
| 682 | return result;
|
---|
| 683 | }
|
---|
| 684 | async function resolveTeleports(context) {
|
---|
| 685 | if (context.__teleportBuffers) {
|
---|
| 686 | context.teleports = context.teleports || {};
|
---|
| 687 | for (const key in context.__teleportBuffers) {
|
---|
| 688 | context.teleports[key] = await unrollBuffer$1(
|
---|
| 689 | await Promise.all([context.__teleportBuffers[key]])
|
---|
| 690 | );
|
---|
| 691 | }
|
---|
| 692 | }
|
---|
| 693 | }
|
---|
| 694 |
|
---|
| 695 | const { isVNode } = Vue.ssrUtils;
|
---|
| 696 | async function unrollBuffer(buffer, stream) {
|
---|
| 697 | if (buffer.hasAsync) {
|
---|
| 698 | for (let i = 0; i < buffer.length; i++) {
|
---|
| 699 | let item = buffer[i];
|
---|
| 700 | if (shared.isPromise(item)) {
|
---|
| 701 | item = await item;
|
---|
| 702 | }
|
---|
| 703 | if (shared.isString(item)) {
|
---|
| 704 | stream.push(item);
|
---|
| 705 | } else {
|
---|
| 706 | await unrollBuffer(item, stream);
|
---|
| 707 | }
|
---|
| 708 | }
|
---|
| 709 | } else {
|
---|
| 710 | unrollBufferSync(buffer, stream);
|
---|
| 711 | }
|
---|
| 712 | }
|
---|
| 713 | function unrollBufferSync(buffer, stream) {
|
---|
| 714 | for (let i = 0; i < buffer.length; i++) {
|
---|
| 715 | let item = buffer[i];
|
---|
| 716 | if (shared.isString(item)) {
|
---|
| 717 | stream.push(item);
|
---|
| 718 | } else {
|
---|
| 719 | unrollBufferSync(item, stream);
|
---|
| 720 | }
|
---|
| 721 | }
|
---|
| 722 | }
|
---|
| 723 | function renderToSimpleStream(input, context, stream) {
|
---|
| 724 | if (isVNode(input)) {
|
---|
| 725 | return renderToSimpleStream(
|
---|
| 726 | Vue.createApp({ render: () => input }),
|
---|
| 727 | context,
|
---|
| 728 | stream
|
---|
| 729 | );
|
---|
| 730 | }
|
---|
| 731 | const vnode = Vue.createVNode(input._component, input._props);
|
---|
| 732 | vnode.appContext = input._context;
|
---|
| 733 | input.provide(Vue.ssrContextKey, context);
|
---|
| 734 | Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
|
---|
| 735 | if (context.__watcherHandles) {
|
---|
| 736 | for (const unwatch of context.__watcherHandles) {
|
---|
| 737 | unwatch();
|
---|
| 738 | }
|
---|
| 739 | }
|
---|
| 740 | }).then(() => stream.push(null)).catch((error) => {
|
---|
| 741 | stream.destroy(error);
|
---|
| 742 | });
|
---|
| 743 | return stream;
|
---|
| 744 | }
|
---|
| 745 | function renderToStream(input, context = {}) {
|
---|
| 746 | console.warn(
|
---|
| 747 | `[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
|
---|
| 748 | );
|
---|
| 749 | return renderToNodeStream(input, context);
|
---|
| 750 | }
|
---|
| 751 | function renderToNodeStream(input, context = {}) {
|
---|
| 752 | const stream = new (require("node:stream")).Readable({ read() {
|
---|
| 753 | } }) ;
|
---|
| 754 | if (!stream) {
|
---|
| 755 | throw new Error(
|
---|
| 756 | `ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
|
---|
| 757 | );
|
---|
| 758 | }
|
---|
| 759 | return renderToSimpleStream(input, context, stream);
|
---|
| 760 | }
|
---|
| 761 | function pipeToNodeWritable(input, context = {}, writable) {
|
---|
| 762 | renderToSimpleStream(input, context, {
|
---|
| 763 | push(content) {
|
---|
| 764 | if (content != null) {
|
---|
| 765 | writable.write(content);
|
---|
| 766 | } else {
|
---|
| 767 | writable.end();
|
---|
| 768 | }
|
---|
| 769 | },
|
---|
| 770 | destroy(err) {
|
---|
| 771 | writable.destroy(err);
|
---|
| 772 | }
|
---|
| 773 | });
|
---|
| 774 | }
|
---|
| 775 | function renderToWebStream(input, context = {}) {
|
---|
| 776 | if (typeof ReadableStream !== "function") {
|
---|
| 777 | throw new Error(
|
---|
| 778 | `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.`
|
---|
| 779 | );
|
---|
| 780 | }
|
---|
| 781 | const encoder = new TextEncoder();
|
---|
| 782 | let cancelled = false;
|
---|
| 783 | return new ReadableStream({
|
---|
| 784 | start(controller) {
|
---|
| 785 | renderToSimpleStream(input, context, {
|
---|
| 786 | push(content) {
|
---|
| 787 | if (cancelled) return;
|
---|
| 788 | if (content != null) {
|
---|
| 789 | controller.enqueue(encoder.encode(content));
|
---|
| 790 | } else {
|
---|
| 791 | controller.close();
|
---|
| 792 | }
|
---|
| 793 | },
|
---|
| 794 | destroy(err) {
|
---|
| 795 | controller.error(err);
|
---|
| 796 | }
|
---|
| 797 | });
|
---|
| 798 | },
|
---|
| 799 | cancel() {
|
---|
| 800 | cancelled = true;
|
---|
| 801 | }
|
---|
| 802 | });
|
---|
| 803 | }
|
---|
| 804 | function pipeToWebWritable(input, context = {}, writable) {
|
---|
| 805 | const writer = writable.getWriter();
|
---|
| 806 | const encoder = new TextEncoder();
|
---|
| 807 | let hasReady = false;
|
---|
| 808 | try {
|
---|
| 809 | hasReady = shared.isPromise(writer.ready);
|
---|
| 810 | } catch (e) {
|
---|
| 811 | }
|
---|
| 812 | renderToSimpleStream(input, context, {
|
---|
| 813 | async push(content) {
|
---|
| 814 | if (hasReady) {
|
---|
| 815 | await writer.ready;
|
---|
| 816 | }
|
---|
| 817 | if (content != null) {
|
---|
| 818 | return writer.write(encoder.encode(content));
|
---|
| 819 | } else {
|
---|
| 820 | return writer.close();
|
---|
| 821 | }
|
---|
| 822 | },
|
---|
| 823 | destroy(err) {
|
---|
| 824 | console.log(err);
|
---|
| 825 | writer.close();
|
---|
| 826 | }
|
---|
| 827 | });
|
---|
| 828 | }
|
---|
| 829 |
|
---|
| 830 | Vue.initDirectivesForSSR();
|
---|
| 831 |
|
---|
| 832 | exports.ssrIncludeBooleanAttr = shared.includeBooleanAttr;
|
---|
| 833 | exports.pipeToNodeWritable = pipeToNodeWritable;
|
---|
| 834 | exports.pipeToWebWritable = pipeToWebWritable;
|
---|
| 835 | exports.renderToNodeStream = renderToNodeStream;
|
---|
| 836 | exports.renderToSimpleStream = renderToSimpleStream;
|
---|
| 837 | exports.renderToStream = renderToStream;
|
---|
| 838 | exports.renderToString = renderToString;
|
---|
| 839 | exports.renderToWebStream = renderToWebStream;
|
---|
| 840 | exports.ssrGetDirectiveProps = ssrGetDirectiveProps;
|
---|
| 841 | exports.ssrGetDynamicModelProps = ssrGetDynamicModelProps;
|
---|
| 842 | exports.ssrInterpolate = ssrInterpolate;
|
---|
| 843 | exports.ssrLooseContain = ssrLooseContain;
|
---|
| 844 | exports.ssrLooseEqual = ssrLooseEqual;
|
---|
| 845 | exports.ssrRenderAttr = ssrRenderAttr;
|
---|
| 846 | exports.ssrRenderAttrs = ssrRenderAttrs;
|
---|
| 847 | exports.ssrRenderClass = ssrRenderClass;
|
---|
| 848 | exports.ssrRenderComponent = ssrRenderComponent;
|
---|
| 849 | exports.ssrRenderDynamicAttr = ssrRenderDynamicAttr;
|
---|
| 850 | exports.ssrRenderDynamicModel = ssrRenderDynamicModel;
|
---|
| 851 | exports.ssrRenderList = ssrRenderList;
|
---|
| 852 | exports.ssrRenderSlot = ssrRenderSlot;
|
---|
| 853 | exports.ssrRenderSlotInner = ssrRenderSlotInner;
|
---|
| 854 | exports.ssrRenderStyle = ssrRenderStyle;
|
---|
| 855 | exports.ssrRenderSuspense = ssrRenderSuspense;
|
---|
| 856 | exports.ssrRenderTeleport = ssrRenderTeleport;
|
---|
| 857 | exports.ssrRenderVNode = renderVNode;
|
---|