import{processDOM as A,removeBindings as B,Internals as M,DirectiveRegistry as w}from"../index.js";const{block:y,repeatCtx:u,internals:c,index:k}=M,b="*foreach",h=Symbol(),l=new Range,D={attribute:(n,o)=>o===b,process:({targetNode:n,scopeNode:o,expression:H})=>{const m=document.createElement("template");n[y]="abort",n.removeAttribute(b);const x=n.outerHTML,d=document.createComment("*foreach"),E=n.parentElement||n.parentNode||o.shadowRoot||o;E.insertBefore(d,n);let t=[];function C(f=[]){let s=f.length,i=t.length;if(s<i){const{[s]:e,[i-1]:a}=t;l.setStartBefore(e),l.setEndAfter(a),l.deleteContents(),t.slice(s).forEach(r=>{r[c][h].clear(),B(o,r)}),t.length=s}i=t.length,m.innerHTML=x.repeat(Math.max(0,s-i)),l.selectNodeContents(m.content);const p=l.extractContents(),g=Array.from(p.children);g.forEach((e,a)=>{e[u]=f[t.length+a];const{bounds:r,clear:R}=A(o,e);e[c]=e[c]||{},e[c][h]={bounds:r,clear:R},r.forEach(v=>v())}),E.insertBefore(p,d),t.forEach((e,a)=>{e[u]=f[a],e[c][h].bounds.forEach(r=>r())}),t.push(...g)}return{update:C,removeNode:!0}}};w.add(D,!0);
