3ceadf640980e98ebeab3a5930c10c00791935077abd9d25dc0727a1600a839b00425da96cf89c6b89e6fbfafb90545dec722b408959378b93253ff8c413bb 3.5 KB

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