vue.cjs.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * vue v3.5.12
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. var 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__ */ Object.create(null);
  23. function compileToFunction(template, options) {
  24. if (!shared.isString(template)) {
  25. if (template.nodeType) {
  26. template = template.innerHTML;
  27. } else {
  28. runtimeDom.warn(`invalid template option: `, template);
  29. return shared.NOOP;
  30. }
  31. }
  32. const key = shared.genCacheKey(template, options);
  33. const cached = compileCache[key];
  34. if (cached) {
  35. return cached;
  36. }
  37. if (template[0] === "#") {
  38. const el = document.querySelector(template);
  39. if (!el) {
  40. runtimeDom.warn(`Template element not found or is empty: ${template}`);
  41. }
  42. template = el ? el.innerHTML : ``;
  43. }
  44. const opts = shared.extend(
  45. {
  46. hoistStatic: true,
  47. onError: onError ,
  48. onWarn: (e) => onError(e, true)
  49. },
  50. options
  51. );
  52. if (!opts.isCustomElement && typeof customElements !== "undefined") {
  53. opts.isCustomElement = (tag) => !!customElements.get(tag);
  54. }
  55. const { code } = compilerDom.compile(template, opts);
  56. function onError(err, asWarning = false) {
  57. const message = asWarning ? err.message : `Template compilation error: ${err.message}`;
  58. const codeFrame = err.loc && shared.generateCodeFrame(
  59. template,
  60. err.loc.start.offset,
  61. err.loc.end.offset
  62. );
  63. runtimeDom.warn(codeFrame ? `${message}
  64. ${codeFrame}` : message);
  65. }
  66. const render = new Function("Vue", code)(runtimeDom__namespace);
  67. render._rc = true;
  68. return compileCache[key] = render;
  69. }
  70. runtimeDom.registerRuntimeCompiler(compileToFunction);
  71. exports.compile = compileToFunction;
  72. Object.keys(runtimeDom).forEach(function (k) {
  73. if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = runtimeDom[k];
  74. });