global-node.mjs 734 B

123456789101112131415161718192021222324252627282930
  1. import { isClient } from '@vueuse/core';
  2. const globalNodes = [];
  3. let target = !isClient ? void 0 : document.body;
  4. function createGlobalNode(id) {
  5. const el = document.createElement("div");
  6. if (id !== void 0) {
  7. el.setAttribute("id", id);
  8. }
  9. target.appendChild(el);
  10. globalNodes.push(el);
  11. return el;
  12. }
  13. function removeGlobalNode(el) {
  14. globalNodes.splice(globalNodes.indexOf(el), 1);
  15. el.remove();
  16. }
  17. function changeGlobalNodesTarget(el) {
  18. if (el === target)
  19. return;
  20. target = el;
  21. globalNodes.forEach((el2) => {
  22. if (el2.contains(target) === false) {
  23. target.appendChild(el2);
  24. }
  25. });
  26. }
  27. export { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode };
  28. //# sourceMappingURL=global-node.mjs.map