Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

server-renderer.cjs.prod.js 24KB

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