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