server-renderer.esm-bundler.js 34 KB

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