server-renderer.cjs.prod.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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 ssrRenderList(source, renderItem) {
  188. if (shared.isArray(source) || shared.isString(source)) {
  189. for (let i = 0, l = source.length; i < l; i++) {
  190. renderItem(source[i], i);
  191. }
  192. } else if (typeof source === "number") {
  193. for (let i = 0; i < source; i++) {
  194. renderItem(i + 1, i);
  195. }
  196. } else if (shared.isObject(source)) {
  197. if (source[Symbol.iterator]) {
  198. const arr = Array.from(source);
  199. for (let i = 0, l = arr.length; i < l; i++) {
  200. renderItem(arr[i], i);
  201. }
  202. } else {
  203. const keys = Object.keys(source);
  204. for (let i = 0, l = keys.length; i < l; i++) {
  205. const key = keys[i];
  206. renderItem(source[key], key, i);
  207. }
  208. }
  209. }
  210. }
  211. async function ssrRenderSuspense(push, { default: renderContent }) {
  212. if (renderContent) {
  213. renderContent();
  214. } else {
  215. push(`<!---->`);
  216. }
  217. }
  218. function ssrGetDirectiveProps(instance, dir, value, arg, modifiers = {}) {
  219. if (typeof dir !== "function" && dir.getSSRProps) {
  220. return dir.getSSRProps(
  221. {
  222. dir,
  223. instance: Vue.ssrUtils.getComponentPublicInstance(instance.$),
  224. value,
  225. oldValue: void 0,
  226. arg,
  227. modifiers
  228. },
  229. null
  230. ) || {};
  231. }
  232. return {};
  233. }
  234. const ssrLooseEqual = shared.looseEqual;
  235. function ssrLooseContain(arr, value) {
  236. return shared.looseIndexOf(arr, value) > -1;
  237. }
  238. function ssrRenderDynamicModel(type, model, value) {
  239. switch (type) {
  240. case "radio":
  241. return shared.looseEqual(model, value) ? " checked" : "";
  242. case "checkbox":
  243. return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? " checked" : "";
  244. default:
  245. return ssrRenderAttr("value", model);
  246. }
  247. }
  248. function ssrGetDynamicModelProps(existingProps = {}, model) {
  249. const { type, value } = existingProps;
  250. switch (type) {
  251. case "radio":
  252. return shared.looseEqual(model, value) ? { checked: true } : null;
  253. case "checkbox":
  254. return (shared.isArray(model) ? ssrLooseContain(model, value) : model) ? { checked: true } : null;
  255. default:
  256. return { value: model };
  257. }
  258. }
  259. var helpers = /*#__PURE__*/Object.freeze({
  260. __proto__: null,
  261. ssrGetDirectiveProps: ssrGetDirectiveProps,
  262. ssrGetDynamicModelProps: ssrGetDynamicModelProps,
  263. ssrIncludeBooleanAttr: shared.includeBooleanAttr,
  264. ssrInterpolate: ssrInterpolate,
  265. ssrLooseContain: ssrLooseContain,
  266. ssrLooseEqual: ssrLooseEqual,
  267. ssrRenderAttr: ssrRenderAttr,
  268. ssrRenderAttrs: ssrRenderAttrs,
  269. ssrRenderClass: ssrRenderClass,
  270. ssrRenderComponent: ssrRenderComponent,
  271. ssrRenderDynamicAttr: ssrRenderDynamicAttr,
  272. ssrRenderDynamicModel: ssrRenderDynamicModel,
  273. ssrRenderList: ssrRenderList,
  274. ssrRenderSlot: ssrRenderSlot,
  275. ssrRenderSlotInner: ssrRenderSlotInner,
  276. ssrRenderStyle: ssrRenderStyle,
  277. ssrRenderSuspense: ssrRenderSuspense,
  278. ssrRenderTeleport: ssrRenderTeleport,
  279. ssrRenderVNode: renderVNode
  280. });
  281. const compileCache = /* @__PURE__ */ Object.create(null);
  282. function ssrCompile(template, instance) {
  283. const Component = instance.type;
  284. const { isCustomElement, compilerOptions } = instance.appContext.config;
  285. const { delimiters, compilerOptions: componentCompilerOptions } = Component;
  286. const finalCompilerOptions = shared.extend(
  287. shared.extend(
  288. {
  289. isCustomElement,
  290. delimiters
  291. },
  292. compilerOptions
  293. ),
  294. componentCompilerOptions
  295. );
  296. finalCompilerOptions.isCustomElement = finalCompilerOptions.isCustomElement || shared.NO;
  297. finalCompilerOptions.isNativeTag = finalCompilerOptions.isNativeTag || shared.NO;
  298. const cacheKey = JSON.stringify(
  299. {
  300. template,
  301. compilerOptions: finalCompilerOptions
  302. },
  303. (key, value) => {
  304. return shared.isFunction(value) ? value.toString() : value;
  305. }
  306. );
  307. const cached = compileCache[cacheKey];
  308. if (cached) {
  309. return cached;
  310. }
  311. finalCompilerOptions.onError = (err) => {
  312. {
  313. throw err;
  314. }
  315. };
  316. const { code } = compilerSsr.compile(template, finalCompilerOptions);
  317. const requireMap = {
  318. vue: Vue__namespace,
  319. "vue/server-renderer": helpers
  320. };
  321. const fakeRequire = (id) => requireMap[id];
  322. return compileCache[cacheKey] = Function("require", code)(fakeRequire);
  323. }
  324. const {
  325. createComponentInstance,
  326. setCurrentRenderingInstance,
  327. setupComponent,
  328. renderComponentRoot,
  329. normalizeVNode,
  330. pushWarningContext,
  331. popWarningContext
  332. } = Vue.ssrUtils;
  333. function createBuffer() {
  334. let appendable = false;
  335. const buffer = [];
  336. return {
  337. getBuffer() {
  338. return buffer;
  339. },
  340. push(item) {
  341. const isStringItem = shared.isString(item);
  342. if (appendable && isStringItem) {
  343. buffer[buffer.length - 1] += item;
  344. return;
  345. }
  346. buffer.push(item);
  347. appendable = isStringItem;
  348. if (shared.isPromise(item) || shared.isArray(item) && item.hasAsync) {
  349. buffer.hasAsync = true;
  350. }
  351. }
  352. };
  353. }
  354. function renderComponentVNode(vnode, parentComponent = null, slotScopeId) {
  355. const instance = vnode.component = createComponentInstance(
  356. vnode,
  357. parentComponent,
  358. null
  359. );
  360. const res = setupComponent(
  361. instance,
  362. true
  363. /* isSSR */
  364. );
  365. const hasAsyncSetup = shared.isPromise(res);
  366. let prefetches = instance.sp;
  367. if (hasAsyncSetup || prefetches) {
  368. const p = Promise.resolve(res).then(() => {
  369. if (hasAsyncSetup) prefetches = instance.sp;
  370. if (prefetches) {
  371. return Promise.all(
  372. prefetches.map((prefetch) => prefetch.call(instance.proxy))
  373. );
  374. }
  375. }).catch(shared.NOOP);
  376. return p.then(() => renderComponentSubTree(instance, slotScopeId));
  377. } else {
  378. return renderComponentSubTree(instance, slotScopeId);
  379. }
  380. }
  381. function renderComponentSubTree(instance, slotScopeId) {
  382. const comp = instance.type;
  383. const { getBuffer, push } = createBuffer();
  384. if (shared.isFunction(comp)) {
  385. let root = renderComponentRoot(instance);
  386. if (!comp.props) {
  387. for (const key in instance.attrs) {
  388. if (key.startsWith(`data-v-`)) {
  389. (root.props || (root.props = {}))[key] = ``;
  390. }
  391. }
  392. }
  393. renderVNode(push, instance.subTree = root, instance, slotScopeId);
  394. } else {
  395. if ((!instance.render || instance.render === shared.NOOP) && !instance.ssrRender && !comp.ssrRender && shared.isString(comp.template)) {
  396. comp.ssrRender = ssrCompile(comp.template, instance);
  397. }
  398. const ssrRender = instance.ssrRender || comp.ssrRender;
  399. if (ssrRender) {
  400. let attrs = instance.inheritAttrs !== false ? instance.attrs : void 0;
  401. let hasCloned = false;
  402. let cur = instance;
  403. while (true) {
  404. const scopeId = cur.vnode.scopeId;
  405. if (scopeId) {
  406. if (!hasCloned) {
  407. attrs = { ...attrs };
  408. hasCloned = true;
  409. }
  410. attrs[scopeId] = "";
  411. }
  412. const parent = cur.parent;
  413. if (parent && parent.subTree && parent.subTree === cur.vnode) {
  414. cur = parent;
  415. } else {
  416. break;
  417. }
  418. }
  419. if (slotScopeId) {
  420. if (!hasCloned) attrs = { ...attrs };
  421. const slotScopeIdList = slotScopeId.trim().split(" ");
  422. for (let i = 0; i < slotScopeIdList.length; i++) {
  423. attrs[slotScopeIdList[i]] = "";
  424. }
  425. }
  426. const prev = setCurrentRenderingInstance(instance);
  427. try {
  428. ssrRender(
  429. instance.proxy,
  430. push,
  431. instance,
  432. attrs,
  433. // compiler-optimized bindings
  434. instance.props,
  435. instance.setupState,
  436. instance.data,
  437. instance.ctx
  438. );
  439. } finally {
  440. setCurrentRenderingInstance(prev);
  441. }
  442. } else if (instance.render && instance.render !== shared.NOOP) {
  443. renderVNode(
  444. push,
  445. instance.subTree = renderComponentRoot(instance),
  446. instance,
  447. slotScopeId
  448. );
  449. } else {
  450. const componentName = comp.name || comp.__file || `<Anonymous>`;
  451. Vue.warn(`Component ${componentName} is missing template or render function.`);
  452. push(`<!---->`);
  453. }
  454. }
  455. return getBuffer();
  456. }
  457. function renderVNode(push, vnode, parentComponent, slotScopeId) {
  458. const { type, shapeFlag, children, dirs, props } = vnode;
  459. if (dirs) {
  460. vnode.props = applySSRDirectives(vnode, props, dirs);
  461. }
  462. switch (type) {
  463. case Vue.Text:
  464. push(shared.escapeHtml(children));
  465. break;
  466. case Vue.Comment:
  467. push(
  468. children ? `<!--${shared.escapeHtmlComment(children)}-->` : `<!---->`
  469. );
  470. break;
  471. case Vue.Static:
  472. push(children);
  473. break;
  474. case Vue.Fragment:
  475. if (vnode.slotScopeIds) {
  476. slotScopeId = (slotScopeId ? slotScopeId + " " : "") + vnode.slotScopeIds.join(" ");
  477. }
  478. push(`<!--[-->`);
  479. renderVNodeChildren(
  480. push,
  481. children,
  482. parentComponent,
  483. slotScopeId
  484. );
  485. push(`<!--]-->`);
  486. break;
  487. default:
  488. if (shapeFlag & 1) {
  489. renderElementVNode(push, vnode, parentComponent, slotScopeId);
  490. } else if (shapeFlag & 6) {
  491. push(renderComponentVNode(vnode, parentComponent, slotScopeId));
  492. } else if (shapeFlag & 64) {
  493. renderTeleportVNode(push, vnode, parentComponent, slotScopeId);
  494. } else if (shapeFlag & 128) {
  495. renderVNode(push, vnode.ssContent, parentComponent, slotScopeId);
  496. } else {
  497. Vue.warn(
  498. "[@vue/server-renderer] Invalid VNode type:",
  499. type,
  500. `(${typeof type})`
  501. );
  502. }
  503. }
  504. }
  505. function renderVNodeChildren(push, children, parentComponent, slotScopeId) {
  506. for (let i = 0; i < children.length; i++) {
  507. renderVNode(push, normalizeVNode(children[i]), parentComponent, slotScopeId);
  508. }
  509. }
  510. function renderElementVNode(push, vnode, parentComponent, slotScopeId) {
  511. const tag = vnode.type;
  512. let { props, children, shapeFlag, scopeId } = vnode;
  513. let openTag = `<${tag}`;
  514. if (props) {
  515. openTag += ssrRenderAttrs(props, tag);
  516. }
  517. if (scopeId) {
  518. openTag += ` ${scopeId}`;
  519. }
  520. let curParent = parentComponent;
  521. let curVnode = vnode;
  522. while (curParent && curVnode === curParent.subTree) {
  523. curVnode = curParent.vnode;
  524. if (curVnode.scopeId) {
  525. openTag += ` ${curVnode.scopeId}`;
  526. }
  527. curParent = curParent.parent;
  528. }
  529. if (slotScopeId) {
  530. openTag += ` ${slotScopeId}`;
  531. }
  532. push(openTag + `>`);
  533. if (!shared.isVoidTag(tag)) {
  534. let hasChildrenOverride = false;
  535. if (props) {
  536. if (props.innerHTML) {
  537. hasChildrenOverride = true;
  538. push(props.innerHTML);
  539. } else if (props.textContent) {
  540. hasChildrenOverride = true;
  541. push(shared.escapeHtml(props.textContent));
  542. } else if (tag === "textarea" && props.value) {
  543. hasChildrenOverride = true;
  544. push(shared.escapeHtml(props.value));
  545. }
  546. }
  547. if (!hasChildrenOverride) {
  548. if (shapeFlag & 8) {
  549. push(shared.escapeHtml(children));
  550. } else if (shapeFlag & 16) {
  551. renderVNodeChildren(
  552. push,
  553. children,
  554. parentComponent,
  555. slotScopeId
  556. );
  557. }
  558. }
  559. push(`</${tag}>`);
  560. }
  561. }
  562. function applySSRDirectives(vnode, rawProps, dirs) {
  563. const toMerge = [];
  564. for (let i = 0; i < dirs.length; i++) {
  565. const binding = dirs[i];
  566. const {
  567. dir: { getSSRProps }
  568. } = binding;
  569. if (getSSRProps) {
  570. const props = getSSRProps(binding, vnode);
  571. if (props) toMerge.push(props);
  572. }
  573. }
  574. return Vue.mergeProps(rawProps || {}, ...toMerge);
  575. }
  576. function renderTeleportVNode(push, vnode, parentComponent, slotScopeId) {
  577. const target = vnode.props && vnode.props.to;
  578. const disabled = vnode.props && vnode.props.disabled;
  579. if (!target) {
  580. if (!disabled) {
  581. Vue.warn(`[@vue/server-renderer] Teleport is missing target prop.`);
  582. }
  583. return [];
  584. }
  585. if (!shared.isString(target)) {
  586. Vue.warn(
  587. `[@vue/server-renderer] Teleport target must be a query selector string.`
  588. );
  589. return [];
  590. }
  591. ssrRenderTeleport(
  592. push,
  593. (push2) => {
  594. renderVNodeChildren(
  595. push2,
  596. vnode.children,
  597. parentComponent,
  598. slotScopeId
  599. );
  600. },
  601. target,
  602. disabled || disabled === "",
  603. parentComponent
  604. );
  605. }
  606. const { isVNode: isVNode$1 } = Vue.ssrUtils;
  607. function nestedUnrollBuffer(buffer, parentRet, startIndex) {
  608. if (!buffer.hasAsync) {
  609. return parentRet + unrollBufferSync$1(buffer);
  610. }
  611. let ret = parentRet;
  612. for (let i = startIndex; i < buffer.length; i += 1) {
  613. const item = buffer[i];
  614. if (shared.isString(item)) {
  615. ret += item;
  616. continue;
  617. }
  618. if (shared.isPromise(item)) {
  619. return item.then((nestedItem) => {
  620. buffer[i] = nestedItem;
  621. return nestedUnrollBuffer(buffer, ret, i);
  622. });
  623. }
  624. const result = nestedUnrollBuffer(item, ret, 0);
  625. if (shared.isPromise(result)) {
  626. return result.then((nestedItem) => {
  627. buffer[i] = nestedItem;
  628. return nestedUnrollBuffer(buffer, "", i);
  629. });
  630. }
  631. ret = result;
  632. }
  633. return ret;
  634. }
  635. function unrollBuffer$1(buffer) {
  636. return nestedUnrollBuffer(buffer, "", 0);
  637. }
  638. function unrollBufferSync$1(buffer) {
  639. let ret = "";
  640. for (let i = 0; i < buffer.length; i++) {
  641. let item = buffer[i];
  642. if (shared.isString(item)) {
  643. ret += item;
  644. } else {
  645. ret += unrollBufferSync$1(item);
  646. }
  647. }
  648. return ret;
  649. }
  650. async function renderToString(input, context = {}) {
  651. if (isVNode$1(input)) {
  652. return renderToString(Vue.createApp({ render: () => input }), context);
  653. }
  654. const vnode = Vue.createVNode(input._component, input._props);
  655. vnode.appContext = input._context;
  656. input.provide(Vue.ssrContextKey, context);
  657. const buffer = await renderComponentVNode(vnode);
  658. const result = await unrollBuffer$1(buffer);
  659. await resolveTeleports(context);
  660. if (context.__watcherHandles) {
  661. for (const unwatch of context.__watcherHandles) {
  662. unwatch();
  663. }
  664. }
  665. return result;
  666. }
  667. async function resolveTeleports(context) {
  668. if (context.__teleportBuffers) {
  669. context.teleports = context.teleports || {};
  670. for (const key in context.__teleportBuffers) {
  671. context.teleports[key] = await unrollBuffer$1(
  672. await Promise.all([context.__teleportBuffers[key]])
  673. );
  674. }
  675. }
  676. }
  677. const { isVNode } = Vue.ssrUtils;
  678. async function unrollBuffer(buffer, stream) {
  679. if (buffer.hasAsync) {
  680. for (let i = 0; i < buffer.length; i++) {
  681. let item = buffer[i];
  682. if (shared.isPromise(item)) {
  683. item = await item;
  684. }
  685. if (shared.isString(item)) {
  686. stream.push(item);
  687. } else {
  688. await unrollBuffer(item, stream);
  689. }
  690. }
  691. } else {
  692. unrollBufferSync(buffer, stream);
  693. }
  694. }
  695. function unrollBufferSync(buffer, stream) {
  696. for (let i = 0; i < buffer.length; i++) {
  697. let item = buffer[i];
  698. if (shared.isString(item)) {
  699. stream.push(item);
  700. } else {
  701. unrollBufferSync(item, stream);
  702. }
  703. }
  704. }
  705. function renderToSimpleStream(input, context, stream) {
  706. if (isVNode(input)) {
  707. return renderToSimpleStream(
  708. Vue.createApp({ render: () => input }),
  709. context,
  710. stream
  711. );
  712. }
  713. const vnode = Vue.createVNode(input._component, input._props);
  714. vnode.appContext = input._context;
  715. input.provide(Vue.ssrContextKey, context);
  716. Promise.resolve(renderComponentVNode(vnode)).then((buffer) => unrollBuffer(buffer, stream)).then(() => resolveTeleports(context)).then(() => {
  717. if (context.__watcherHandles) {
  718. for (const unwatch of context.__watcherHandles) {
  719. unwatch();
  720. }
  721. }
  722. }).then(() => stream.push(null)).catch((error) => {
  723. stream.destroy(error);
  724. });
  725. return stream;
  726. }
  727. function renderToStream(input, context = {}) {
  728. console.warn(
  729. `[@vue/server-renderer] renderToStream is deprecated - use renderToNodeStream instead.`
  730. );
  731. return renderToNodeStream(input, context);
  732. }
  733. function renderToNodeStream(input, context = {}) {
  734. const stream = new (require("node:stream")).Readable({ read() {
  735. } }) ;
  736. if (!stream) {
  737. throw new Error(
  738. `ESM build of renderToStream() does not support renderToNodeStream(). Use pipeToNodeWritable() with an existing Node.js Writable stream instance instead.`
  739. );
  740. }
  741. return renderToSimpleStream(input, context, stream);
  742. }
  743. function pipeToNodeWritable(input, context = {}, writable) {
  744. renderToSimpleStream(input, context, {
  745. push(content) {
  746. if (content != null) {
  747. writable.write(content);
  748. } else {
  749. writable.end();
  750. }
  751. },
  752. destroy(err) {
  753. writable.destroy(err);
  754. }
  755. });
  756. }
  757. function renderToWebStream(input, context = {}) {
  758. if (typeof ReadableStream !== "function") {
  759. throw new Error(
  760. `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.`
  761. );
  762. }
  763. const encoder = new TextEncoder();
  764. let cancelled = false;
  765. return new ReadableStream({
  766. start(controller) {
  767. renderToSimpleStream(input, context, {
  768. push(content) {
  769. if (cancelled) return;
  770. if (content != null) {
  771. controller.enqueue(encoder.encode(content));
  772. } else {
  773. controller.close();
  774. }
  775. },
  776. destroy(err) {
  777. controller.error(err);
  778. }
  779. });
  780. },
  781. cancel() {
  782. cancelled = true;
  783. }
  784. });
  785. }
  786. function pipeToWebWritable(input, context = {}, writable) {
  787. const writer = writable.getWriter();
  788. const encoder = new TextEncoder();
  789. let hasReady = false;
  790. try {
  791. hasReady = shared.isPromise(writer.ready);
  792. } catch (e) {
  793. }
  794. renderToSimpleStream(input, context, {
  795. async push(content) {
  796. if (hasReady) {
  797. await writer.ready;
  798. }
  799. if (content != null) {
  800. return writer.write(encoder.encode(content));
  801. } else {
  802. return writer.close();
  803. }
  804. },
  805. destroy(err) {
  806. console.log(err);
  807. writer.close();
  808. }
  809. });
  810. }
  811. Vue.initDirectivesForSSR();
  812. exports.ssrIncludeBooleanAttr = shared.includeBooleanAttr;
  813. exports.pipeToNodeWritable = pipeToNodeWritable;
  814. exports.pipeToWebWritable = pipeToWebWritable;
  815. exports.renderToNodeStream = renderToNodeStream;
  816. exports.renderToSimpleStream = renderToSimpleStream;
  817. exports.renderToStream = renderToStream;
  818. exports.renderToString = renderToString;
  819. exports.renderToWebStream = renderToWebStream;
  820. exports.ssrGetDirectiveProps = ssrGetDirectiveProps;
  821. exports.ssrGetDynamicModelProps = ssrGetDynamicModelProps;
  822. exports.ssrInterpolate = ssrInterpolate;
  823. exports.ssrLooseContain = ssrLooseContain;
  824. exports.ssrLooseEqual = ssrLooseEqual;
  825. exports.ssrRenderAttr = ssrRenderAttr;
  826. exports.ssrRenderAttrs = ssrRenderAttrs;
  827. exports.ssrRenderClass = ssrRenderClass;
  828. exports.ssrRenderComponent = ssrRenderComponent;
  829. exports.ssrRenderDynamicAttr = ssrRenderDynamicAttr;
  830. exports.ssrRenderDynamicModel = ssrRenderDynamicModel;
  831. exports.ssrRenderList = ssrRenderList;
  832. exports.ssrRenderSlot = ssrRenderSlot;
  833. exports.ssrRenderSlotInner = ssrRenderSlotInner;
  834. exports.ssrRenderStyle = ssrRenderStyle;
  835. exports.ssrRenderSuspense = ssrRenderSuspense;
  836. exports.ssrRenderTeleport = ssrRenderTeleport;
  837. exports.ssrRenderVNode = renderVNode;