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.js 32KB

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