e4ee652fb0ab86a2434bd54dcaed8c2e8ab9196509f9234bb815a3b104e97f3187d41ec60683d66b89db25847505ad1febe5af2742be45b5d241c8bc551891 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var shared = require('@vue/shared');
  5. var PatchFlags = /* @__PURE__ */ ((PatchFlags2) => {
  6. PatchFlags2[PatchFlags2["TEXT"] = 1] = "TEXT";
  7. PatchFlags2[PatchFlags2["CLASS"] = 2] = "CLASS";
  8. PatchFlags2[PatchFlags2["STYLE"] = 4] = "STYLE";
  9. PatchFlags2[PatchFlags2["PROPS"] = 8] = "PROPS";
  10. PatchFlags2[PatchFlags2["FULL_PROPS"] = 16] = "FULL_PROPS";
  11. PatchFlags2[PatchFlags2["HYDRATE_EVENTS"] = 32] = "HYDRATE_EVENTS";
  12. PatchFlags2[PatchFlags2["STABLE_FRAGMENT"] = 64] = "STABLE_FRAGMENT";
  13. PatchFlags2[PatchFlags2["KEYED_FRAGMENT"] = 128] = "KEYED_FRAGMENT";
  14. PatchFlags2[PatchFlags2["UNKEYED_FRAGMENT"] = 256] = "UNKEYED_FRAGMENT";
  15. PatchFlags2[PatchFlags2["NEED_PATCH"] = 512] = "NEED_PATCH";
  16. PatchFlags2[PatchFlags2["DYNAMIC_SLOTS"] = 1024] = "DYNAMIC_SLOTS";
  17. PatchFlags2[PatchFlags2["HOISTED"] = -1] = "HOISTED";
  18. PatchFlags2[PatchFlags2["BAIL"] = -2] = "BAIL";
  19. return PatchFlags2;
  20. })(PatchFlags || {});
  21. function isFragment(node) {
  22. return vue.isVNode(node) && node.type === vue.Fragment;
  23. }
  24. function isText(node) {
  25. return vue.isVNode(node) && node.type === vue.Text;
  26. }
  27. function isComment(node) {
  28. return vue.isVNode(node) && node.type === vue.Comment;
  29. }
  30. const TEMPLATE = "template";
  31. function isTemplate(node) {
  32. return vue.isVNode(node) && node.type === TEMPLATE;
  33. }
  34. function isValidElementNode(node) {
  35. return vue.isVNode(node) && !isFragment(node) && !isComment(node);
  36. }
  37. function getChildren(node, depth) {
  38. if (isComment(node))
  39. return;
  40. if (isFragment(node) || isTemplate(node)) {
  41. return depth > 0 ? getFirstValidNode(node.children, depth - 1) : void 0;
  42. }
  43. return node;
  44. }
  45. const getFirstValidNode = (nodes, maxDepth = 3) => {
  46. if (shared.isArray(nodes)) {
  47. return getChildren(nodes[0], maxDepth);
  48. } else {
  49. return getChildren(nodes, maxDepth);
  50. }
  51. };
  52. function renderIf(condition, ...args) {
  53. return condition ? renderBlock(...args) : vue.createCommentVNode("v-if", true);
  54. }
  55. function renderBlock(...args) {
  56. return vue.openBlock(), vue.createBlock(...args);
  57. }
  58. const getNormalizedProps = (node) => {
  59. if (!vue.isVNode(node)) {
  60. return {};
  61. }
  62. const raw = node.props || {};
  63. const type = (vue.isVNode(node.type) ? node.type.props : void 0) || {};
  64. const props = {};
  65. Object.keys(type).forEach((key) => {
  66. if (shared.hasOwn(type[key], "default")) {
  67. props[key] = type[key].default;
  68. }
  69. });
  70. Object.keys(raw).forEach((key) => {
  71. props[shared.camelize(key)] = raw[key];
  72. });
  73. return props;
  74. };
  75. const ensureOnlyChild = (children) => {
  76. if (!shared.isArray(children) || children.length > 1) {
  77. throw new Error("expect to receive a single Vue element child");
  78. }
  79. return children[0];
  80. };
  81. const flattedChildren = (children) => {
  82. const vNodes = shared.isArray(children) ? children : [children];
  83. const result = [];
  84. vNodes.forEach((child) => {
  85. var _a;
  86. if (shared.isArray(child)) {
  87. result.push(...flattedChildren(child));
  88. } else if (vue.isVNode(child) && ((_a = child.component) == null ? void 0 : _a.subTree)) {
  89. result.push(child, ...flattedChildren(child.component.subTree));
  90. } else if (vue.isVNode(child) && shared.isArray(child.children)) {
  91. result.push(...flattedChildren(child.children));
  92. } else if (vue.isVNode(child) && child.shapeFlag === 2) {
  93. result.push(...flattedChildren(child.type()));
  94. } else {
  95. result.push(child);
  96. }
  97. });
  98. return result;
  99. };
  100. exports.PatchFlags = PatchFlags;
  101. exports.ensureOnlyChild = ensureOnlyChild;
  102. exports.flattedChildren = flattedChildren;
  103. exports.getFirstValidNode = getFirstValidNode;
  104. exports.getNormalizedProps = getNormalizedProps;
  105. exports.isComment = isComment;
  106. exports.isFragment = isFragment;
  107. exports.isTemplate = isTemplate;
  108. exports.isText = isText;
  109. exports.isValidElementNode = isValidElementNode;
  110. exports.renderBlock = renderBlock;
  111. exports.renderIf = renderIf;
  112. //# sourceMappingURL=vnode.js.map