global-node.js 940 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. require('../browser.js');
  4. var core = require('@vueuse/core');
  5. const globalNodes = [];
  6. let target = !core.isClient ? void 0 : document.body;
  7. function createGlobalNode(id) {
  8. const el = document.createElement("div");
  9. if (id !== void 0) {
  10. el.setAttribute("id", id);
  11. }
  12. if (target) {
  13. target.appendChild(el);
  14. globalNodes.push(el);
  15. }
  16. return el;
  17. }
  18. function removeGlobalNode(el) {
  19. globalNodes.splice(globalNodes.indexOf(el), 1);
  20. el.remove();
  21. }
  22. function changeGlobalNodesTarget(el) {
  23. if (el === target)
  24. return;
  25. target = el;
  26. globalNodes.forEach((el2) => {
  27. if (target && !el2.contains(target)) {
  28. target.appendChild(el2);
  29. }
  30. });
  31. }
  32. exports.changeGlobalNodesTarget = changeGlobalNodesTarget;
  33. exports.createGlobalNode = createGlobalNode;
  34. exports.removeGlobalNode = removeGlobalNode;
  35. //# sourceMappingURL=global-node.js.map