"use strict";const h=require("./css-HnNQMUzV.cjs"),d=require("react"),b=require("./Editable-BXFY3-UW.cjs"),i=require("./Text-DECnk5vG.cjs"),x=require("./deep-DtdcJG4q.cjs"),q=({triggers:n,callback:u,region:c,loose:r,double:t,regionMustBeElement:l})=>{const{listen:e}=i.useContext();let a;n!=null&&n?.length>0&&typeof n[0]=="string"?a=[n]:a=n;const g=i.useMemoCompare(()=>a,([s],[f])=>s==null&&f==null?!0:s==null||f==null?!1:x.q.primitiveArrays(s.flat(),f.flat())===x.q.EQUAL,[a]);d.useEffect(()=>{if(!(g==null||g.length===0))return e(s=>{const f=i.filter(g,s.prev,{loose:r,double:t}),R=i.filter(g,s.next,{loose:r,double:t}),m=i.diff(R,f);let o=m[0];const p=m[1];if(o.length===0&&p.length===0)return;o=k(s.target,s.cursor,o,c,l);const v={target:s.target,cursor:s.cursor};o.length>0&&u?.({...v,stage:"start",triggers:o,prevTriggers:s.prev}),p.length>0&&u?.({...v,stage:"end",triggers:p,prevTriggers:s.prev})})},[u,g,e,r,c,t,l])},k=(n,u,c,r,t)=>{if(r==null)return c;if(r.current==null)return[];const l=h.jt.construct(r.current);return c.filter(e=>t??e.some(g=>g.includes("Mouse"))?h.jt.contains(l,u)&&n===r.current:h.jt.contains(l,u))},H=({triggers:n,loose:u})=>{const[c,r]=b.useStateRef({triggers:[],held:!1});return q({triggers:n,callback:d.useCallback(t=>{r(l=>{let e;return t.stage==="start"?e=h.c.unique([...l.triggers,...t.triggers]):e=i.purge(l.triggers,t.triggers),{triggers:e,held:e.length>0}})},[]),loose:u}),c},T=({triggers:n,loose:u})=>{const[c,r]=d.useState({triggers:[],held:!1});return q({triggers:n,callback:d.useCallback(t=>{r(l=>{let e;return t.stage==="start"?e=h.c.unique([...l.triggers,...t.triggers]):e=i.purge(l.triggers,t.triggers),{triggers:e,held:e.length>0}})},[]),loose:u}),c};exports.use=q;exports.useHeld=T;exports.useHeldRef=H;
