global-node.mjs 759 B

1234567891011121314151617181920212223242526272829303132
  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. if (target) {
  10. target.appendChild(el);
  11. globalNodes.push(el);
  12. }
  13. return el;
  14. }
  15. function removeGlobalNode(el) {
  16. globalNodes.splice(globalNodes.indexOf(el), 1);
  17. el.remove();
  18. }
  19. function changeGlobalNodesTarget(el) {
  20. if (el === target)
  21. return;
  22. target = el;
  23. globalNodes.forEach((el2) => {
  24. if (target && !el2.contains(target)) {
  25. target.appendChild(el2);
  26. }
  27. });
  28. }
  29. export { changeGlobalNodesTarget, createGlobalNode, removeGlobalNode };
  30. //# sourceMappingURL=global-node.mjs.map