global-node.mjs 759 B

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