import e from"../../_util/canUseDom.mjs";import t from"./contains.mjs";var n=`data-vc-order`,r=`vc-util-key`,i=new Map;function a({mark:e}={}){return e?e.startsWith(`data-`)?e:`data-${e}`:r}function o(e){return e.attachTo?e.attachTo:document.querySelector(`head`)||document.body}function s(e){return e===`queue`?`prependQueue`:e?`prepend`:`append`}function c(e){return Array.from((i.get(e)||e).children).filter(e=>e.tagName===`STYLE`)}function l(t,r={}){if(!e())return null;let{csp:i,prepend:a}=r,l=document.createElement(`style`);l.setAttribute(n,s(a)),i?.nonce&&(l.nonce=i?.nonce),l.innerHTML=t;let u=o(r),{firstChild:d}=u;if(a){if(a===`queue`){let e=c(u).filter(e=>[`prepend`,`prependQueue`].includes(e.getAttribute(n)));if(e.length)return u.insertBefore(l,e[e.length-1].nextSibling),l}u.insertBefore(l,d)}else u.appendChild(l);return l}function u(e,t={}){return c(o(t)).find(n=>n.getAttribute(a(t))===e)}function d(e,t={}){let n=u(e,t);n&&o(t).removeChild(n)}function f(e,n){let r=i.get(e);if(!r||!t(document,r)){let t=l(``,n),{parentNode:r}=t;i.set(e,r),e.removeChild(t)}}function p(e,t,n={}){f(o(n),n);let r=u(t,n);if(r)return n.csp?.nonce&&r.nonce!==n.csp?.nonce&&(r.nonce=n.csp?.nonce),r.innerHTML!==e&&(r.innerHTML=e),r;let i=l(e,n);return i.setAttribute(a(n),t),i}export{l as injectCSS,d as removeCSS,p as updateCSS};