vue.cjs.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * vue v3.4.23
  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 compilerDom = require('@vue/compiler-dom');
  9. var runtimeDom = require('@vue/runtime-dom');
  10. var shared = require('@vue/shared');
  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 runtimeDom__namespace = /*#__PURE__*/_interopNamespaceDefault(runtimeDom);
  22. const compileCache = /* @__PURE__ */ new WeakMap();
  23. function getCache(options) {
  24. let c = compileCache.get(options != null ? options : shared.EMPTY_OBJ);
  25. if (!c) {
  26. c = /* @__PURE__ */ Object.create(null);
  27. compileCache.set(options != null ? options : shared.EMPTY_OBJ, c);
  28. }
  29. return c;
  30. }
  31. function compileToFunction(template, options) {
  32. if (!shared.isString(template)) {
  33. if (template.nodeType) {
  34. template = template.innerHTML;
  35. } else {
  36. runtimeDom.warn(`invalid template option: `, template);
  37. return shared.NOOP;
  38. }
  39. }
  40. const key = template;
  41. const cache = getCache(options);
  42. const cached = cache[key];
  43. if (cached) {
  44. return cached;
  45. }
  46. if (template[0] === "#") {
  47. const el = document.querySelector(template);
  48. if (!el) {
  49. runtimeDom.warn(`Template element not found or is empty: ${template}`);
  50. }
  51. template = el ? el.innerHTML : ``;
  52. }
  53. const opts = shared.extend(
  54. {
  55. hoistStatic: true,
  56. onError: onError ,
  57. onWarn: (e) => onError(e, true)
  58. },
  59. options
  60. );
  61. if (!opts.isCustomElement && typeof customElements !== "undefined") {
  62. opts.isCustomElement = (tag) => !!customElements.get(tag);
  63. }
  64. const { code } = compilerDom.compile(template, opts);
  65. function onError(err, asWarning = false) {
  66. const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
  67. const codeFrame = err.loc && shared.generateCodeFrame(
  68. template,
  69. err.loc.start.offset,
  70. err.loc.end.offset
  71. );
  72. runtimeDom.warn(codeFrame ? `${message}
  73. ${codeFrame}` : message);
  74. }
  75. const render = new Function("Vue", code)(runtimeDom__namespace);
  76. render._rc = true;
  77. return cache[key] = render;
  78. }
  79. runtimeDom.registerRuntimeCompiler(compileToFunction);
  80. exports.compile = compileToFunction;
  81. Object.keys(runtimeDom).forEach(function (k) {
  82. if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
  83. });