server-renderer.cjs.js 32 KB

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