phlex-reactive 0.16.5 → 0.16.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- import{Controller as Jc}from"@hotwired/stimulus";import{confirmResolver as bi}from"phlex/reactive/confirm";import{confirmPredicate as bs}from"phlex/reactive/confirm_predicate";var j=new WeakMap,Ve=new WeakMap;function N(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Ve.set(n.root,n)}return n}function x(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function G(e,t){x(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Ye(e,t){let n=N(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Ss(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")Is(n,s.target);else n.groups=$s(n),yr(n);hr(n)},x(n,"input change",n.show),x(n,"focusout",(s)=>{let c=s.target?.getAttribute?.("name");if(!c||n.touched?.has(c)||!n.core.owns(s.target))return;if((n.touched??=new Set).add(c),n.root.querySelector?.("[data-reactive-show-after]"))hr(n)}),G(n,n.show);if(!n.arm&&Es(n))x(n,"input change",(s)=>mr(n,s)),G(n,n.arm=()=>{mr(n,null),yr(n)});if(!r&&(r=n.show||n.arm))x(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=ue(n)))x(n,"input",(s)=>Ws(n,s)&&U(n)),G(n,()=>U(n));if(!i&&(i=fe(n)))G(n,()=>Nr(n));if(!a&&(a=Js(n)))x(n,"input change",(s)=>$r(n,s)),G(n,()=>at(n))})(),x(n,"keydown",(s)=>ia(n,s)),x(n,"paste drop",(s)=>sa(n,s)),x(n,"input",(s)=>aa(n,s))}function Xe(e){let t=j.get(e);if(!t)return;j.delete(e),Ve.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Ze(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Qe(e,t,n){return $r(N(e,t),n)}function et(e,t,n){return Wr(N(e,t),n)}var vs=/^#[A-Za-z_][\w-]*$/,Ar="[data-reactive-show-field], [data-reactive-show]";function ys(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Pr){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Dr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Sr(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function ws(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function Er(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return z(n,t);return As(e,t)}function As(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>pt(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function ce(e,t="show"){if(typeof e==="string"&&vs.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ss(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(Ar)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(le)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${kr}, ${Tr}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Es(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function xs(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:ws(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function mr(e,t){let n=xs(e);if(!n.length)return;let r=_r(e,e.core.ownership());n.forEach((o,i)=>{let a=z(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function hr(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=_r(e,t),o=[];for(let i of e.root.querySelectorAll(Ar)){if(!t(i))continue;let a=i.getAttribute("data-reactive-show");if(a!==null){let l=Er(Sr(a),r);if(l===null)continue;let d=i.getAttribute("data-reactive-show-after"),f=l&&(d==null||!!e.touched?.has(nt(d,n)));gr(i,f,t,n);let m=(e.shown??=new WeakMap).get(i);if(e.shown.set(i,f),_s.some((g)=>i.hasAttribute(`data-reactive-show-${g}`))&&m!==void 0&&m!==f)o.push(i);continue}let s=i.getAttribute("data-reactive-show-field");if(!s)continue;let c=r(s);if(c===null)continue;let u=ys(i,c);if(u===null)continue;gr(i,u,t,n)}if(e.groups)Ds(e,r,t,n);Os(e,r,t),Ms(e,r,t,n),Ts(e,r),qs(e,r);for(let i of o)ks(e,i,t,n)}var _s=["clear","focus","scroll"];function ks(e,t,n,r){if(t.hidden){let s=[];try{s=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(s)?s:[]).map((u)=>nt(String(u),r)));for(let u of c.size?e.root.querySelectorAll("[name]"):[]){if(!c.has(u.getAttribute("name"))||!n(u)||u.type==="file")continue;if(u.type==="checkbox"||u.type==="radio"){if(u.checked)u.checked=!1,M(u)}else e.core.setValue(u,"")}return}let o=t.getAttribute("data-reactive-show-scroll")==="true";if(o)t.scrollIntoView?.({block:"nearest"});let i=t.getAttribute("data-reactive-show-focus"),a=null;try{a=i?e.root.querySelector(i):null}catch{}a?.focus?.(o?{preventScroll:!0}:void 0)}function gr(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function Ts(e,t){let n=xr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Rs(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!ce(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>pt(l,a))}else{let l=qr(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function Rs(e,t,n){if(!ce(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=ra(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!oa(r))return;let i=z(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function xr(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function Ls(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(tt(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function tt(e,t){return`[name="${nt(e,t)}"]`}function nt(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function _r(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?rt(e,o,t,n).filter((s)=>s.checked).length:Ls(e,o,t,n));return r.get(a)}}var kr="[data-reactive-media]";function Os(e,t,n){for(let r of e.root.querySelectorAll(kr)){if(!n(r))continue;let o,i,a;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)a=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!a){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let s=t(o.field);if(s===null)continue;let c=o.take>0?[...s]:null,u=c?c.slice(0,o.take).join(""):s,l=c?.length<o.take||i?.test(u)===!1||a?.test(s)===!1;if(l&&o.pending==="keep"){br(r,"pending");continue}let d=!l&&Object.hasOwn(o.pool,u)?vr(e,o.pool[u])[0]:null,f=e.core.copyMedia(r,d??null);if(f===null)continue;if(br(r,l?"pending":f===!1?"miss":"hit"),typeof o.label!=="string")continue;let m=l?"":f===!1?String(o.blank??""):f;for(let v of vr(e,o.label))if(v.textContent!==m)v.textContent=m}}function br(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function vr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Tr="[data-reactive-css-vars]",Ns=/^--[a-z0-9-]+$/i,Fs=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ms(e,t,n,r){let o=[...e.root.querySelectorAll(Tr)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))o.unshift(e.root);for(let i of o){let a;try{a=JSON.parse(i.getAttribute("data-reactive-css-vars"))}catch{}if(!Array.isArray(a?.to)||!a.vars||typeof a.vars!=="object"){console.warn("[phlex-reactive] malformed data-reactive-css-vars — skipped (two reactive_css_vars on one element?)");continue}let s=a.to.flatMap((c)=>{let u={to:c,global:a.global===!0},l=[];try{l=e.core.opTargets(u)}catch{}if(!l.length)e.core.diagnose("reactive_css_vars",u);return l});for(let[c,u]of Object.entries(a.vars)){let l=u?.unit??"";if(!Ns.test(c)||!Fs.includes(l)||typeof u?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(c)} — skipped`);continue}let d=Cs(e,t,u.field,n,r);if(d===void 0)continue;let f=d===null?"":`${d}${l}`;for(let m of s){if(m.style.getPropertyValue(c)===f)continue;if(f)m.style.setProperty(c,f);else m.style.removeProperty(c)}}}}function Cs(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(tt(n,o))].some((s)=>r(s)&&s.type==="checkbox"))return i==="true"?1:0;let a=i.trim()?Number(i):NaN;return Number.isFinite(a)?a:null}var le="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function $s(e){return!!e.root.querySelector?.(le)}function rt(e,t,n,r,o){return[...e.root.querySelectorAll(tt(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Ps(i.getAttribute("data-reactive-group"),o)))}function Ps(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Is(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Rr(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function ot(e,t,n){if(!t)return;let r=Ve.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Rr(r,t,n!==!1),r.show?.()}function Rr(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=rt(e,t,e.core.ownership(),i,o).filter((s)=>s!==r&&s.checked!==n);for(let s of a)s.checked=n;e.flipping=!0;try{for(let s of a)for(let c of["input","change"])s.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function Ds(e,t,n,r){for(let o of e.root.querySelectorAll(le)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Er(Sr(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=o.getAttribute("data-reactive-select-all-under"),u=rt(e,s,n,r,c).filter((d)=>d!==o),l=u.filter((d)=>d.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function qs(e,t){for(let[n,r]of Object.entries(xr(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!ce(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!ce(a,"group"))continue;let c=z(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function yr(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${le}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function ue(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Ws(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var js=/[\s\-'(),./]/;function Bs(e,t,n){if(e==="prefix")return t.startsWith(n);if(e!=="word_start")return t.includes(n);for(let r=t.indexOf(n);r!==-1;r=t.indexOf(n,r+1))if(r===0||js.test(t[r-1]))return!0;return!1}function U(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=e.root.getAttribute("data-reactive-filter-match"),a=e.root.hasAttribute?.("data-reactive-filter-fold"),s=(f)=>{let m=(f??"").toLowerCase().trim();return a?m.normalize("NFD").replace(/\p{M}/gu,""):m},c=s(o.value),u=0;for(let f of e.root.querySelectorAll(n)){if(!r(f))continue;let m=f.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Bs(i,s(f.getAttribute("data-reactive-filter-text")??f.textContent),c);if(f.hidden=m,m)f.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let f of e.root.querySelectorAll(l)){if(!r(f))continue;let m=[...f.querySelectorAll(n)].filter(r);if(m.length===0)continue;f.hidden=m.every((v)=>v.hidden)}let d=e.root.getAttribute("data-reactive-filter-empty");if(d){for(let f of e.root.querySelectorAll(d))if(r(f))f.hidden=u>0}}function fe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Js(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function it(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function st(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function Lr(e,t){let n=it(e);if(!n)return!1;let r=st(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)Or(e,n,r);return i}function Or(e,t,n){t.value=n.join(","),M(t),Nr(e)}function Hs(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Nr(e){let t=it(e);if(!t)return;let n=st(t),r=e.core.ownership();Gs(e,n,r),Us(e,n,r)}function Gs(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Us(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!ue(e))o.hidden=!1}}if(ue(e))U(e)}function zs(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Ks(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Vs(e,t){if(e.nestedWarned)return;console.warn(`[phlex-reactive] nested rows: no owned [data-reactive-nested-list="${t}"] container + <template data-reactive-nested-template="${t}"> pair found in this root — the add `+"trigger did nothing. Render both inside the same reactive root (reactive_nested_list / reactive_nested_template)."),e.nestedWarned=!0}function Ys(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let d=a.find((f)=>Mr(f.getAttribute?.("name"))===c);if(!d)continue;Xs(d,l),s.push(l)}if(r)for(let c of s)Zs(c);return s[0]??null}function Xs(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:ze(t)!=="";else e.value=ze(t);M(e)}function Zs(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function Qs(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function wr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);at(e)}function at(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Cr(e,n.getAttribute("data-reactive-nested-json"))}function ea(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Fr(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=Mr(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=ze(o)}return n}function Mr(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function ze(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Cr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ea(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Fr(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function ct(e,t,n){let r=N(e,t);if(!fe(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!Lr(r,String(o.value??"").split(",")))return;if(o.value="",ue(r))U(r)}function ut(e,t,n){let r=N(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Lr(r,[i]))return;let a=Hs(r);if(!a)return;a.value="",U(r),a.focus?.()}function lt(e,t,n){let r=N(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=it(r);if(!a)return;let s=st(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Or(r,a,c)}function ft(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Vs(r,i);return}let l=u.cloneNode(!0);Ks(l,zs(r)),s.appendChild(l);let d=o?.getAttribute?.("data-reactive-nested-from-param"),f=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",m=Ys(r,l,d,f);if(d)m?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Cr(r,i)}function dt(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Wr(r,s):null);if(!c)return wr(r,i);let u=Fr(r,i),l=Qs(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((d)=>{if(d)wr(r,i)})}function $r(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;at(e)}var Pr=["gte","gt","lte","lt"],ta=["len_eq","len_gte","len_gt","len_lte","len_lt"],Ir=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],na=["digits_eq","digits_gte","digits_lt","digits_lte"];function Ke(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function Dr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function qr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Pr)if(n in e)return Dr(n,e[n],t);for(let n of ta)if(n in e)return Ke(n,e[n],[...String(t??"")].length);return null}function pt(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Ir.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Ke(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(a)=>{let s=String(t(a)??"");return e.fold===!0?s.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):s};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=na.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((s)=>Number.isInteger(e[s]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((s)=>Ke(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return qr(e,o)===!0}function z(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>pt(r,t)))}function ra(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n){if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field);if(typeof r?.same==="string")t.add(r.same)}}return t.size>0?[...t]:null}function oa(e){return e.flat().every((t)=>Ir.some((n)=>(n in Object(t))))}function Wr(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=bs(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=z(n.groups?.any,o)===!0;return i?n.message:null}function mt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ia(e,t){let n=mt(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function sa(e,t){let n=mt(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function aa(e,t){let n=mt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as ca}from"phlex/reactive/compute";var V=new WeakMap;function Hr(e,t){let n=V.get(e);if(!n)V.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function gt(e,t,n,r){let o=Hr(e,t),i=Ea(o);if(i)o.seed=()=>ht(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)ht(o)}function bt(e){let t=V.get(e);if(!t)return;if(V.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function vt(e){V.get(e)?.seed?.()}function yt(e,t,n){return ht(Hr(e,t),n)}var ua=Object.freeze({el:null,kind:""}),la=/^#[A-Za-z_][\w-]*$/;function K({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function Gr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function fa(e,t){if(t==="string")return K(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Gr(K(e));if(n)return e.el.checked?1:0;let r=Number(K(e));return Number.isFinite(r)?r:0}function da(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Gr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return pa(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function pa(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function ma(e){if(e==null)return null;let t=Array.isArray(e)?e:e.ops;if(Array.isArray(t))return t.length>0?t:null;return console.warn("[phlex-reactive] $ops must be an ops chain or a [[op, args], ...] list — skipped"),null}function ha(e){if(typeof e==="string"&&la.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function ga(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function ba(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function va(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function ya(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=wa(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function wa(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Br(e,t,n){let r=String(n);for(let o of Aa(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Aa(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Jr(e,t,n){let r=Sa(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?K(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!ha(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Sa(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function Ea(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function ht(e,t){if(t&&e.ours.has(t))return;let n=va(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let p=s.get(h);if(p)return p;let w=null,A=null,q=null;for(let W of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(W))continue;let ae=W.type;if(ae==="checkbox"||ae==="radio"&&W.checked){q={el:W,kind:ae};break}if(ae==="radio")w??=W;else A??=W}if(!q)if(w)q={el:w,kind:"radio"};else q=A?{el:A,kind:""}:ua;return s.set(h,q),q};for(let h of r)Br(e,h,K(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?ca(u):null;if(!l){Jr(e,{},c);return}let d=ba(e,"data-reactive-compute-outputs-param"),f={};for(let[h,p]of n)f[h]=fa(c(h),p);let m=l(f,{changed:ya(e,t,r,o)})||{},v=ma(m.$ops),g=[];for(let h of d){if(h==="$ops"||!(h in m))continue;let p=c(h);if(!p.el)continue;let w=da(e.root,a,p,i(h),m[h]);if(w)g.push(w)}for(let h of Object.keys(m)){if(h==="$ops")continue;let p=m[h];if(p===void 0||p===null)continue;Br(e,h,p)}Jr(e,m,c);for(let h of g){let p=new Event("input",{bubbles:!0});e.ours.add(p),h.dispatchEvent(p)}ga(e,v,Boolean(t))}var Et;function xt(e){Et=e}var Yr=1,xa="phlex-reactive:persist:",_a=new Set(["hidden","file","password","submit","button","reset","image"]),_t=Symbol("persist-no-value"),kt="data-reactive-persist-state",ka=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ta=new Set(["lexxy-editor","trix-editor"]),Ra="lexxy-editor, trix-editor, trix-toolbar",La=["lexxy:change","trix-change"],Oa=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),zr=new WeakSet,Kr=new WeakSet,Vr=new WeakSet;function pe(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!zr.has(e))zr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Tt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Rt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Kr.has(e))return;Kr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Lt(e){return xa+e.key}function At(e,t){let n=Tt(t);if(!n)return null;let r;try{r=n.getItem(Lt(t))}catch(c){return Rt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Yr)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return de(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function Xr(e,t,{fields:n,state:r}){let o=Tt(t);if(!o)return!1;let i={v:Yr,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Lt(t),JSON.stringify(i)),!0}catch(a){return Rt(e,a),!1}}function de(e,t){e?.removeAttribute?.(kt);let n=Tt(t);if(!n)return;try{n.removeItem(Lt(t))}catch(r){Rt(e,r)}}function Ot(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||_a.has(i.type)||i.closest(Ra))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(ka)){if(!o(i))continue;let a=Na(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Ta.has(i.localName)?"editor":"contenteditable"})}return r}function Zr(e){return e.hasAttribute("data-reactive-editable")?Et.text(e):e.textContent??""}function Na(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Nt(e){return typeof e.value==="string"}function Fa(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Oa.has(e.value.trim())}function Ma(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Vr.has(e))return;Vr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function Y(e){return e.tagName==="SELECT"&&e.multiple}function Qr(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function eo(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return _t;return e[0]}function to(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of Ot(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Nt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Zr(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(Y(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Ca(e,t,n){let r=t.restore==="always",o=Ot(e,t),i=Qr(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&Y(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||Y(s))){if(l=eo(l,c,i),l===_t)continue}if((s.type==="checkbox"||Y(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")no(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Zr(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((d)=>d.kind==="native"&&d.el.type==="radio"&&d.name===c&&d.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(Y(s)){if(!r&&[...s.options].some((f)=>f.selected))continue;let d=new Set((Array.isArray(l)?l:[l]).map(String));for(let f of s.options)f.selected=d.has(f.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}$a(e,t,n)}function no(e,t,n,r,o){if(Array.isArray(r))return;if(!Nt(t))return;if(!o&&!Fa(t))return;try{t.value=String(r)}catch(i){Ma(e,n,i)}}function $a(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Nt(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Ot(e,t),c=Qr(s);for(let{el:u,name:l,kind:d}of s){if(d!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let f=eo(n[l],l,c);if(f===null||f===void 0||f===_t)continue;no(e,u,l,f,i)}})}function Pa(e,t,n=!0){let r=pe(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=At(e,r),i={...o?.state??{},...t},a=n?to(e,r):o?.fields??{};if(Xr(e,r,{fields:a,state:i}))e.setAttribute?.(kt,JSON.stringify(i))}function Ia(e){let t=pe(e);if(t)de(e,t)}var St=new WeakMap,wt=new WeakMap;function Da(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=wt.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],wt.set(e,n)}let[r,o]=n;return r.add(t),()=>{if(r.delete(t),r.size>0)return;e.removeEventListener?.("turbo:submit-end",o),wt.delete(e)}}function Ft(e,t,n,r){let o=e.element,i=pe(o);if(!i)return;if(r?.submitted)de(o,i);let a=At(o,i);if(a){if(Ca(o,i,a.fields),a.state)o.setAttribute?.(kt,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let v=At(o,i);Xr(o,i,{fields:to(o,i),state:v?.state??null})},l=()=>{let v=Number(i.debounce)||0;if(v<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},v)},d=(v)=>{if(!v?.detail?.success)return;let g=v.target;if(g?.tagName!=="FORM"||typeof g.contains!=="function")return;if(!g.contains(o))return;c(),de(o,i)},f=["input",...La];for(let v of f)o.addEventListener?.(v,l);o.addEventListener?.("change",u);let m=Da(globalThis.document,d);if(St.set(e,()=>{if(s!==null)u();for(let v of f)o.removeEventListener?.(v,l);o.removeEventListener?.("change",u),m()}),r?.edited&&!r.submitted)u();for(let v of r?.ops??[])v(!0)}function Mt(e){let t=St.get(e);St.delete(e),t?.()}function ro(e,t){let n=Et?.waiting.get(e)?.persist;if(!n||!pe(e))return t(!0);(n.ops??=[]).push(t)}function Ct(e,t){ro(e,(n)=>Pa(e,t,n))}function $t(e){ro(e,()=>Ia(e))}var me=new WeakMap,io=new WeakSet,Pt=new WeakMap;function It(e,t){let n=e.element,r=[],o=[],i=(u,l,d)=>{u.addEventListener?.(l,d),r.push(()=>u.removeEventListener?.(l,d))},a,s,c=()=>{if(!a&&(a=qa(n,t))){let u=()=>he(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Ba(n,r)}if(!s&&(s=Ja(n,t))){let u=()=>Ha(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};me.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Dt(e){for(let t of me.get(e)?.[0]??[])t();me.delete(e)}function qt(e){me.get(e)?.[1]()}function qa(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function he(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,Wa(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function Wa(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function ja(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Ba(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Pt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(ja(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(io.has(c)||!i())return;if(io.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),Pt.delete(n)}},Pt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ja(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function Ha(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function Jt(e){Ga(e),za(e)}function Ga(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Wt);else setTimeout(Wt,0);return}let r=async(o)=>{await n(o),Wt()};r.__reactiveDismissWrapped=!0,t.render=r}function Wt(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var Ua=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),jt=Object.freeze(["fade","slide","scale","highlight","shake"]),Bt="data-reactive-fx-pending",Ht=1000;function za(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Ua[r?.getAttribute?.("action")];if(!o||Ya())return;let i=Ka(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Qa(ge(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Xa(r):null;if(await n(s),o==="enter")Za(c,i);else co(ge(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Ka(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return ao(n,t);let o=(t==="enter"?Va(e):ge(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?ao(o,t):null}function ge(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Va(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function ao(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?jt[Math.floor(Math.random()*jt.length)]:e;if(!jt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ya(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Xa(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Bt,"");return ge(e)}function Za(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Bt}]`)))n.removeAttribute(Bt),co(n,t)}async function Qa(e,t){if(!e?.classList)return;if(t.legs){await uo(e,t.legs);return}e.classList.add(t.className);let n=Gt(e);if(n<=0){e.classList.remove(t.className);return}await Ut(e,n),e.classList.remove(t.className)}function co(e,t){if(!e?.classList)return;if(t.legs){uo(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Gt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ut(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function uo(e,t){let[n,r,o]=t.map(ec),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await tc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Gt(e);if(a>0)await Ut(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function ec(e){return String(e??"").split(/\s+/).filter(Boolean)}function Gt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,Ht)}catch{return 0}}function Ut(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,Ht))})}function tc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Ht),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var nc="phlex-reactive:latency",zt=!1;function po(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function mo(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),zt=!1}function Vt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:po,disableLatencySim:mo}}function Yt(){if(typeof sessionStorage>"u")return Promise.resolve();let e=Number(sessionStorage.getItem("phlex-reactive:latency"));if(!Number.isFinite(e)||e<=0)return Promise.resolve();if(!zt)zt=!0,console.warn(`[phlex-reactive] latency simulator ACTIVE — every action is delayed by ${e}ms. Call PhlexReactive.disableLatencySim() (or clear sessionStorage) to turn it off.`);return new Promise((t)=>setTimeout(t,e))}var fo=new WeakMap;function Xt(e){let t=globalThis.document;if(!t)return!0;let n=fo.get(t);if(!n)n=new Set,fo.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Kt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function ho(e,t,n,r){if(Xt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Zt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Kt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}ho(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Qt(e){if(!Xt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function en(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Kt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Kt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}ho(t,o,`scoped to #${r?.id||"?"}`,i)}function tn(e,t){let n=e.element?.id||"?";if(Xt(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function rc(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function nn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function be(e,t,n){e.streams=rc(t),e.tokenRefreshed=n!=null}var ve=new WeakMap;function rn(e,t,n,r){let o=n&&typeof n==="object"?sc(n):n;return o?bo(t,o,r,!1):[]}function on(e,t,n,r){if(!n)return null;let o=bo(t,n,r,!0);return o.length?o:null}function bo(e,t,n,r){let o=[];for(let i of vo(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(oc(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function vo(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function oc(e,t){let n=ve.get(t);if(n)n.count++;else ve.set(t,{count:1,disabled:t.disabled,html:t.innerHTML,hadText:e.text!=null,swappedTo:e.text});if(e.disable)t.disabled=!0;if(e.text!=null)t.innerHTML=e.text;return()=>ic(t,e)}function ic(e,t){let n=ve.get(e);if(!n)return;if(--n.count>0)return;if(ve.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function sc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function sn(e,t,n,r){if(!n?.hide)return null;let o=vo(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var Ae;function un(e){Ae=e}var T=new Map;function So(e,t){let n=!T.has(e);if(T.set(e,t),n)Ae.enter()}function Se(e){if(T.delete(e))Ae.exit()}var wo=!1;function ln(e){Eo();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){dc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;Z(t,n)}function Eo(){if(wo||typeof document>"u"||!document.addEventListener)return;wo=!0,document.addEventListener("turbo:before-stream-render",mc,!0),document.addEventListener("turbo:before-stream-render",ac)}function ac(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(T.get(n)?.via==="stream")Se(n)}function Z(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}dn(e),To(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return So(e,r),pc(e,r,t)}function cc(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[gc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":bc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function xo(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(_o(t))return{src:t};return console.error(uc(t)),lc(t)||fc(e)}function uc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${fn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function lc(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${fn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&_o(r))return{src:r,fallback:!0}}function fc(e){dn(e.id),pn(e),e.setAttribute("data-reactive-error","defer"),e.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e.id,reason:"refused-url"}}))}function _o(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${fn()}/`)}catch{return!1}}function fn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function dc(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){Z(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}dn(e),To(n);let o=document.createElement("pgbus-stream-source");o.id=ko(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),So(e,{via:"stream"})}function ko(e){return`reactive-defer-src-${e}`}async function pc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},vc()),o;try{Ae.count("defer"),o=await fetch(...cc(n,t.abort.signal))}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),X(e,n);return}if(T.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),X(e,n,o.status);return}if(o.status===204){clearTimeout(r),Ao(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),X(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),X(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),X(e,n);return}if(clearTimeout(r),T.get(e)!==t)return;Ao(e),hc(a)}var cn=null,mc=(e)=>cn?.push(e);function hc(e){let t=cn=[];try{window.Turbo.renderStreamMessage(e)}finally{cn=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function dn(e){let t=T.get(e);if(!t)return;if(Se(e),t.via==="fetch")t.abort.abort();else document.getElementById(ko(e))?.remove?.()}function To(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function pn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Ao(e){Se(e);let t=document.getElementById(e);if(!t)return;pn(t),t.removeAttribute("data-reactive-error")}function X(e,t,n){Se(e);let r=document.getElementById(e);if(!r)return;pn(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),Z(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function gc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function bc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function vc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Ro="__materialize",we=new WeakMap;function ye(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function mn(e,t,n){Eo();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>Ee(e),d=(p)=>{if(ye(r)==="visible"){if(!a)m()}else if(p){let w=r.getAttribute("data-reactive-lazy-on");if(s===w)return;f(),r.addEventListener?.(w,l),s=w}},f=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},m=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let p=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:p}),a.observe(r)},v=()=>{let p=ye(r)!==null,w=o;if(o=p,!p)return f();if(i)return;if(t.forgetToken(),!w)return l();d(!0)};if(we.set(e,{load(){if(i)return;let p=xo(r);if(!p&&r.getAttribute("data-reactive-defer-src")!=null)return;if(p&&yc(r,t))return;let w=p?Z(r.id,p):t.proceed(r,Ro,"{}");if(!w)return;i=!0,f();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);f()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&ye(r)===null)an(r),c=(p)=>p.target===r&&an(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(p)=>{if(p.target!==r)return;if(!c)an(r);v()},r.addEventListener?.("turbo:morph-element",u),n)return v();if(o=ye(r)!==null,o)d(!1)}function hn(e){let t=we.get(e);we.delete(e),t?.off()}function Ee(e){return we.get(e)?.load()}function yc(e,t){return t.emit("reactive:before-dispatch",{action:Ro,params:{},element:e},{cancelable:!0}).defaultPrevented}function an(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||xo(e);if(t)Z(e.id,t)}var gn=new WeakMap,_e=new WeakMap,b=null,C,Oo;function wn(e,t){let n=e.element;_e.set(n,t),qo();let r=(i)=>Ac(i,t),o=(i)=>kc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),gn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function An(e){if(gn.get(e)?.(),gn.delete(e),_e.delete(e.element),b&&ke(b.origin)===e.element)xe()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),Q=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},ke=(e)=>e?.closest?.('[data-controller~="reactive"]'),Co=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),F=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==b?.row&&Co(t)===e),No=(e)=>Q(S(e,"-item"),null),bn=(e)=>S(e,"-disabled")==="true",wc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},$o=(e)=>{let t=S(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>S(n,"-group")===t&&!bn(n)&&_e.has(ke(n)))};function Po(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Co(n);if(b||!r||!t.owns(r)||bn(r)||bn(n))return;if(ke(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Ac(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Po(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(p)=>p.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(p)=>{if(!a(p))return;if(b)return vn(p.clientX,p.clientY);if(Math.abs(p.clientX-o)<=4&&Math.abs(p.clientY-i)<=4)return;if(!c)return h();Ec(n,t,p),vn(p.clientX,p.clientY)},d=(p)=>b&&p.cancelable&&p.preventDefault(),f=(p)=>{if(!a(p))return;if(h(),b)Sc(),yn()},m=(p)=>{if(p.type==="pointercancel"&&!a(p))return;if(h(),b)xe()},g=[["pointermove",l],["pointerup",f],["pointercancel",m],["keydown",(p)=>p.key==="Escape"&&b&&(p.preventDefault(),m(p))],["touchmove",d,{passive:!1}]];for(let[p,w,A]of g)document.addEventListener(p,w,A);function h(){clearTimeout(u);for(let[p,w]of g)document.removeEventListener(p,w)}}function Sc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Ec({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,b=Io({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),b.dx=r.clientX-o.left,b.dy=r.clientY-o.top,b.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function Io(e){let{row:t,origin:n,source:r}=e;return e.index=F(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),ee(n,!0),e}var ee=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Te(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function vn(e,t){b.x=e,b.y=t,b.row.style.left=`${e-b.dx}px`,b.row.style.top=`${t-b.dy}px`;let n=$o(b.origin).find((r)=>wc(r,e,t));if(n)xc(n,e,t);else if(b.source)Sn(null),b.placeholder.remove();_c(e,t)}function Sn(e){if(b.target!==b.origin)ee(b.target,!1);b.target=e,ee(e,!0)}function xc(e,t,n){Sn(e);let r=F(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});Te(e,r,s<0?r.length:s,b.placeholder)}function _c(e,t){let n=b.target??b.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(b.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,b.wy=t<40?-12:t>window.innerHeight-40?12:0,(b.vy||b.wy)&&!b.raf){let i=()=>{if(!b||!(b.vy||b.wy))return b&&(b.raf=0);if((b.target??b.origin).scrollTop+=b.vy,b.wy)window.scrollBy(0,b.wy);vn(b.x,b.y),b.raf=requestAnimationFrame(i)};b.raf=requestAnimationFrame(i)}}function kc(e,t){let n=e.key;if(b?.keyboard){if(e.target!==b.row||b.core!==t)return;let o={" ":yn,Enter:yn,Escape:xe,Tab:xe,ArrowUp:()=>Fo(-1),ArrowDown:()=>Fo(1),ArrowLeft:()=>Mo(-1),ArrowRight:()=>Mo(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Po(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),b=Io({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Le("picked")}function Fo(e){let t=F(b.target),n=Re()+e;if(n>=0&&n<=t.length)Te(b.target,t,n,b.row);Do()}function Mo(e){let t=$o(b.origin),n=t[t.indexOf(b.target)+e];if(n){let r=Re();Sn(n),Te(n,F(n),r,b.row)}Do()}function Do(){b.row.focus?.(),Le("moved")}function Re(){let e=F(b.target),t=b.keyboard?b.row:b.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function qo(){if(!C?.isConnected)C=document.createElement("div"),C.setAttribute("aria-live","polite"),C.setAttribute("data-reactive-sortable-live",""),C.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(C);return C}function Le(e){let t=b.target??b.origin,n=(Q(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Re()+1).replaceAll("{count}",F(t).length+1),r=qo();r.textContent="",cancelAnimationFrame(Oo),Oo=requestAnimationFrame(()=>r.textContent=n)}function yn(){let e=b,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?Re():-1,c=a?No(F(t)[s-1]):null;if(e.keyboard)Le("dropped");if(!r&&i)i.replaceWith(o);if(jo(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=Q(S(t,"-from"),{})[u]??S(t),d={...Q(S(t,"-params"),{}),item:No(e.item),position:s,after:c,from:u},f=[];for(let v=t;v;v=v.parentElement)f.push(v);let m=_e.get(ke(t))?.proceed(t,l,JSON.stringify(d),Q(S(t,"-busy")));if(r)return;Promise.resolve(m).then((v)=>Tc(v,f)||Wo(e))}function Tc(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&Rc(r,t))}function Rc(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function xe(){let e=b;if(e.keyboard)Le("cancelled");e.placeholder?.remove(),jo(e),Wo(e)}function Wo({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Te(t,F(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function jo(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(b=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),ee(n,!1),ee(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Uo={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},zo={x:"left",y:"top",width:"width",height:"height"},En=new WeakMap,kn=new WeakMap,y=null,P,Jo,Ho=!1;function Tn(e,t){let n=e.element;kn.set(n,t),ri(),qc();let r=[["pointerdown",(o)=>Cc(o,t,n)],["keydown",(o)=>Dc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Uo[o.key]&&_n()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&_n()],["input",(o)=>Go(o,t,n)],["change",(o)=>Go(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);En.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Rn(e){if(En.get(e)?.(),En.delete(e),kn.delete(e.element),y?.root===e.element)J(y)}var _=(e,t,n)=>Math.min(Math.max(e,t),n),R=(e)=>Math.round(e*1e4)/1e4;function Lc(e,t=1){let n=R(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Ln(e){let t={x:R(e.x),y:R(e.y)};if(e.width!=null)t.width=R(e.width),t.height=R(e.height),t.x=Math.min(t.x,R(1-t.width)),t.y=Math.min(t.y,R(1-t.height));return t}function Ko(e,t,n){return{x:_(e.x+t,0,1-e.width),y:_(e.y+n,0,1-e.height),width:e.width,height:e.height}}function Vo(e,t,n){return{x:_(e.x+t,0,1),y:_(e.y+n,0,1)}}function Yo(e,t,n,r,o,i){let[a,s,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,d=e.y+e.height,f=e.x+e.width/2,m=e.y+e.height/2,v=s?1-e.x:u?l:i?2*Math.min(f,1-f):1,g=c?1-e.y:a?d:i?2*Math.min(m,1-m):1,h=e.width+(s?n:u?-n:0),p=e.height+(c?r:a?-r:0);if(i){let w=(s||u)&&(!(a||c)||Math.abs(h-e.width)>=Math.abs(p-e.height)*i),A=Math.min(v,g*i);h=_(w?h:p*i,Math.min(Math.max(o,o*i),A),A),p=h/i}else{if(s||u)h=_(h,Math.min(o,v),v);if(a||c)p=_(p,Math.min(o,g),g)}return{x:u?l-h:s?e.x:f-h/2,y:a?d-p:c?e.y:m-p/2,width:h,height:p}}function Oc(e,t,n){let r=Math.min(1,t),o=_(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:_(e.x+e.width/2-o/2,0,1-o),y:_(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function Nc(e){let[t,n=1,r]=String(e??"").split(":").map(Number),o=r===void 0?t/n:0;return o>0&&Number.isFinite(o)?o:0}var E=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),On=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},L=(e)=>e.matches("[data-reactive-point]")?"point":"box",Xo=(e)=>Number(E(e,`${L(e)}-scale`))||1,B=(e)=>L(e)==="point"?["x","y"]:["x","y","width","height"];function Zo(e){let t={};for(let n of B(e))t[n]=(parseFloat(e.style[zo[n]])||0)/100;return t}function Oe(e,t){for(let n of B(e))e.style[zo[n]]=`${Math.round(t[n]*1e4)/100}%`}function Nn(e){let t=e.getBoundingClientRect();return{left:t.left+(e.clientLeft||0),top:t.top+(e.clientTop||0),width:e.clientWidth||t.width,height:e.clientHeight||t.height}}function Fc(e,t){try{return e.parentElement.closest(E(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function Qo(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function ei(e,t,n){let r=On(E(e,L(e)),{}),o={};for(let i of B(e)){let[a]=Qo(t,n,r[i]);if(a)o[i]=a}return o}function Mc(e,t,n,r){let o=E(e,"box-aspect"),i=o&&Qo(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),a=o?Nc(i?.value):Number(E(e,"box-ratio"))||0,{width:s,height:c}=Nn(t);return a&&s&&c?a*c/s:0}function Fn(e,t,n,r){let o=n.matches("[data-reactive-box-handle]")?n.closest("[data-reactive-box]"):n,i=o?.closest("[data-reactive-frame]");if(!i)return null;let a=Zo(o),s=ei(o,t,e),c=L(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?Fc(o,i):i,edge:E(n,"box-handle"),start:a,value:a,ratio:c?0:Mc(o,i,t,e),min:Number(E(o,"box-min"))||0,scale:Xo(o),fields:s,before:Object.fromEntries(Object.entries(s).map(([u,l])=>[u,l.value]))}}function ti(e,t,n,r){let o=Lc(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function te(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))ti(e.core,n,e.value[t],e.scale)}function Cc(e,t,n){if(ni(),y||e.button>0||e.isPrimary===!1||e.target.closest?.("input,textarea,select,[contenteditable]"))return;let r=e.target.closest?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]"),o=r&&t.owns(r)&&Fn(t,n,r,!1);if(!o)return;let{clientX:i,clientY:a}=e,s=Nn(o.bounds);o.p0=[(i-s.left)/s.width,(a-s.top)/s.height];let c=(g)=>g.pointerId===e.pointerId,u=(g)=>{if(!c(g)||o.over)return;if(y)return xn(g.clientX,g.clientY);if(Math.abs(g.clientX-i)<=4&&Math.abs(g.clientY-a)<=4)return;Pc(o),xn(g.clientX,g.clientY)},l=(g)=>{if(!c(g))return;if(v(),y)$c(),_n()},d=(g)=>{if(g.type==="pointercancel"&&!c(g))return;if(v(),y)si()},m=[["pointermove",u],["pointerup",l],["pointercancel",d],["keydown",(g)=>g.key==="Escape"&&y&&(g.preventDefault(),d(g))]];for(let[g,h]of m)document.addEventListener(g,h);function v(){for(let[g,h]of m)document.removeEventListener(g,h)}}function $c(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Pc(e){y=e,e.grip.setAttribute("data-reactive-dragging",""),e.frame.setAttribute("data-reactive-frame-active",""),e.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none"}function xn(e,t){let n=y;if(!n.el.isConnected)return J(n);n.x=e,n.y=t;let r=Nn(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:a,edge:s}=n;n.value=Ln(L(n.el)==="point"?Vo(a,o,i):s?Yo(a,s,o,i,n.min,n.ratio):Ko(a,o,i)),Oe(n.el,n.value),n.writing||=requestAnimationFrame(()=>te(n)),Ic(t)}function Ic(e){if(y.wy=e<40?-12:e>window.innerHeight-40?12:0,y.wy&&!y.raf){let t=()=>{if(!y?.wy)return y&&(y.raf=0);if(window.scrollBy(0,y.wy),xn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function ni(){if(y&&!y.el.isConnected)J(y)}function Dc(e,t,n){ni();let r=e.target;if(!r?.matches?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]")||!t.owns(r)||y&&(!y.keyboard||y.grip!==r))return;if(e.key==="Escape")return y&&(e.preventDefault(),si());let o=Uo[e.key];if(!o)return;if(e.preventDefault(),y??=Fn(t,n,r,!0),!y)return;let[i,a]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),s=e.altKey&&L(y.el)==="box",c=y.value;y.value=Ln(L(y.el)==="point"?Vo(c,i,a):s?Yo(c,y.edge??"se",i,a,y.min,y.ratio):Ko(c,i,a)),Oe(y.el,y.value),te(y),oi(y,s?"resized":"moved")}function ri(){if(!P?.isConnected)P=document.createElement("div"),P.setAttribute("aria-live","polite"),P.setAttribute("data-reactive-drag-live",""),P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(P);return P}function oi(e,t){let n=On(E(e.el,`${L(e.el)}-messages`),{})[t]??"";for(let o of B(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=ri();r.textContent="",cancelAnimationFrame(Jo),Jo=requestAnimationFrame(()=>r.textContent=n)}function Go(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(E(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=Fn(t,n,o,!0),{ratio:a,start:s}=i??{};if(!a||Math.abs(s.width/s.height/a-1)<0.005)continue;i.value=Ln(Oc(s,a,i.min)),Oe(o,i.value),te(i),ii(i)}}function _n(){let e=y;if(!e.el.isConnected)return J(e);te(e),J(e),ii(e)}function ii(e){for(let[o,i]of Object.entries(e.fields))if(i.value!==e.before[o])i.dispatchEvent(new Event("change",{bubbles:!0}));let t=L(e.el),n=E(e.el,`${t}-action`),r={};for(let o of B(e.el))r[o]=R(e.value[o]);if(!n||B(e.el).every((o)=>r[o]===R(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),On(E(e.el,`${t}-busy`)))}function si(){let e=y;if(e.value=e.start,Oe(e.el,e.start),te(e),e.keyboard)oi(e,"cancelled");J(e)}function J(e){if(y=null,e.over=!0,cancelAnimationFrame(e.raf),cancelAnimationFrame(e.writing),e.grip.removeAttribute("data-reactive-dragging"),e.frame.removeAttribute("data-reactive-frame-active"),!e.keyboard)document.documentElement.style.userSelect=e.select??""}function qc(){if(Ho)return;Ho=!0,document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.target,n=e.detail?.attributeName;if(!y)return;if(t===y.el&&n==="style"||t===y.grip&&n==="data-reactive-dragging"||t===y.frame&&n==="data-reactive-frame-active"||n==="value"&&Object.values(y.fields).includes(t))e.preventDefault()}),document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;if(t===y?.el||!t.matches?.("[data-reactive-box],[data-reactive-point]"))return;let n=t.closest('[data-controller~="reactive"]'),r=kn.get(n);if(!r?.owns(t))return;let o=Zo(t),i=Xo(t);for(let[a,s]of Object.entries(ei(t,n,r)))ti(r,s,o[a],i)})}var I=new Map,ci=new WeakSet;function Mn(e,t){let n=e.element,r=I.get(n.id);if(!r)I.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Wc(n);let o=(a)=>a.target===n&&queueMicrotask(()=>li(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},li(r)}function Cn(e){let t=e.element,n=I.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;I.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function $n(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=I.get(e.id);if(!n)I.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},fi(n)}function Wc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&ci.has(n))return;if(n?.remove(),!ui())setTimeout(()=>{if(!ui())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=I.get(e.id);if(!o||o.removing)return;fi(o),jc(o)}),ci.add(r),document.body.appendChild(r)}var ui=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function jc(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&di(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function fi(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function di(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function li(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=di(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}var mi=new Map,Pn=new WeakMap,Bc=0,Ne=new WeakMap;function In(e,t){let n=e.element;if(!n.id&&!Pn.has(n))Pn.set(n,`#${++Bc}`);let r=n.id||Pn.get(n),o=new Map,i=!1,a=(m)=>{clearTimeout(o.get(m)),o.delete(m)},s=(m,v,g)=>{a(m);let h=Date.parse(v.until)-Date.now();if(!(h>0))return c(m,v,g);let p=Math.ceil(h/1000);hi(m,`${Math.floor(p/60)}:${String(p%60).padStart(2,"0")}`,"running"),u(v.waiting,!0),u(v.done,!1),o.set(m,setTimeout(()=>s(m,v,g),(h-1)%1000+1))},c=(m,v,g)=>{hi(m,"0:00","done"),u(v.waiting,!1),u(v.done,!0);let h=mi.get(g)??new Set;if(h.has(v.until))return;mi.set(g,h.add(v.until)),m.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:v.until}}))},u=(m,v)=>{let g;try{g=m&&n.querySelector(m)}catch{}if(g&&g.hidden===v)g.hidden=!v},l=()=>{if(i=!1,!Ne.has(e))return;let m=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((g,h)=>{if(!t.owns(g))return;let p;try{p=JSON.parse(g.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(p?.until)))return;m.add(g),s(g,p,`${r}|${g.id||h}`)});for(let g of o.keys())if(!m.has(g))a(g)},d=()=>{if(i)return;i=!0,queueMicrotask(l)},f=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",d),n.addEventListener("reactive:streamed",d),document.addEventListener("visibilitychange",f),Ne.set(e,()=>{n.removeEventListener("turbo:morph-element",d),n.removeEventListener("reactive:streamed",d),document.removeEventListener("visibilitychange",f);for(let m of[...o.keys()])a(m)}),l()}function Dn(e){Ne.get(e)?.(),Ne.delete(e)}function hi(e,t,n){if(e.textContent!==t)e.textContent=t;if(e.getAttribute("data-reactive-countdown-state")!==n)e.setAttribute("data-reactive-countdown-state",n)}function Hc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:visit"])return;e["reactive:visit"]=function(){let t=this.getAttribute("data-url");if(t)window.Turbo.visit(t,{action:"advance"})}}function Gc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}function Uc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=fr(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)Qt(n);return}Qn(t,(i)=>Mu(i,o),r?(i,a)=>Zt(i,a,o):void 0)}}function zc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){ln(this)}}var vi=!1,Kc=null;function Vc(){if(vi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;vi=!0,document.addEventListener("turbo:before-stream-render",(e)=>{cu(e),Yc(e),Zc(e),Jt(e)})}var Pe="reactive:streamed";function Yc(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(Pe))}}function nr(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function rr(e){try{return e.matches(":modal")}catch{return!1}}function Ki(e){if(!nr(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||rr(e))return;if(e.open)e.close();e.showModal()}function Xc(e){if(nr(e)&&e.open)e.close()}function je(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!rr(r))Ki(r)}function Zc(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(o)=>{await n(o),je(document)}}var yi=!1;function Qc(){if(yi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;yi=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))je(t.target)}),document.addEventListener("turbo:morph",()=>je(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!nr(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!rr(n))return;e.delete(n),t.preventDefault(),n.close()})}var Yn=new WeakMap;function Vi(e,t,n,r){let o=Yn.get(e)??new Map;Yn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))fs(n.name)||i(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(i("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))Vi(a,"set_attr",{name:"aria-expanded"})}}var wi=!1;function eu(){if(wi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;wi=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Yn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var Yi="data-reactive-image-fallback",ne="data-reactive-image-state",Xn="data-reactive-image-hidden",qn=null,Zn="data-reactive-wrap-hidden";function Xi(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(Zn,"")}function Zi(e){if(!e.hasAttribute(Zn))return;e.removeAttribute("hidden"),e.removeAttribute(Zn)}function re(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Yi);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Qi=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function or(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function es(e,t){let n=or(e,t.alt);return n&&!n.contains(e)?n:null}function Be(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Xn,"");if(t.wrap){let o=or(e,t.wrap);if(o)Xi(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=es(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Ge(e,t);e.setAttribute(ne,n)}function Ge(e,t=re(e)){if(!t||e.getAttribute(ne)==null)return;if(e.getAttribute(ne)==="error"){if(e.hasAttribute(Xn))e.removeAttribute("hidden");let n=or(e,t.wrap);if(n)Zi(n);let r=es(e,t);if(r)r.hidden=!0}e.removeAttribute(ne),e.removeAttribute(Xn)}function Ai(e){let t=e.target,n=re(t);if(!n)return;if(e.type==="load")Be(t,n,"loaded");else if(Qi(t))Be(t,n,"error");else Ge(t,n)}function tu(){if(qn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;qn={error:Ai,load:Ai,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(ne);if(o==null||!r||!re(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=re(n);if(o)Be(n,o,r)})}};for(let[t,n]of Object.entries(qn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Yi}]`)??[]){if(!t.complete||!Qi(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Be(t,re(t)??{},o);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function rl(e){Kc=e}var Fe,Wn=null,Si="[data-reactive-editable][contenteditable=plaintext-only]";function ts(){if(Fe===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Fe=e.contentEditable==="plaintext-only"}catch{Fe=!1}return Fe}function Ie(e){if(e.matches?.(Si))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Si).forEach(Ie)}function nu(){if(Wn||typeof document>"u"||typeof document.createElement!=="function")return;if(ts())return;Ie(document),Wn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Ie(t.target);else t.addedNodes.forEach(Ie)}),Wn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Ei=!1;function xi(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function ru(){if(Ei)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ei=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=xi(t);if(r)iu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Je.set(t,D(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==k)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>ur(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===k)&&xi(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(k)&&sr(t)===ar(t))t.removeAttribute(k)})}var k="data-reactive-held",ir='[data-controller~="reactive"]',De=null,H=new Map;function sr(e){return e.hasAttribute("data-reactive-editable")?D(e):e.value}function ar(e){return e.hasAttribute("data-reactive-editable")?lr(e):e.defaultValue}function ou(e){if(e.hasAttribute("data-reactive-editable"))return D(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function iu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||H.has(e.closest(ir)))return;let r=ou(t);if(r===sr(e))return e.removeAttribute(k);if(r===ar(e))return;e.setAttribute(k,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function su(e){let t=[];for(let n of e.querySelectorAll(`[${k}]`)){if(n.closest(ir)!==e)continue;let r=n.getAttribute("name");if(sr(n)===ar(n))n.removeAttribute(k);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-￿]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ns(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${k}]`))if(n.closest(ir)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(k)}function au(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function _i(e,t,n=null){let r={root:e,streams:0,keep:n},o=De;De=r;try{window.Turbo.renderStreamMessage(t)}finally{De=o}if(r.streams===0)ns(e,n)}function cu(e){let t=De,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{H.set(t.root,(H.get(t.root)||0)+1);try{return await r(o)}finally{let i=H.get(t.root)-1;if(i)H.set(t.root,i);else H.delete(t.root);ns(t.root,t.keep)}}}var ki="__materialize",Ti=!1;function uu(){if(Ti)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ti=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}function cr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Vt()}var rs="data-reactive-active",O=0;function os(){if(O++,O===1)ss("reactive:busy")}function is(){if(O===0)return;if(O--,O===0)ss("reactive:idle")}function ol(){return O}function il(){O=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(rs)}function ss(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(rs,O>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:O}}))}var as="data-reactive-requests";function cs(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!lu(t))return;let n=fu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(as,JSON.stringify(n))}function lu(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function fu(e){try{let t=JSON.parse(e.getAttribute(as));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Ri(){Hc(),Gc(),Uc(),zc(),Vc(),ru(),Qc(),eu(),tu(),nu(),uu(),cr()}function du(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var us=Symbol.for("phlex-reactive.core");if(globalThis[us])console.error("[phlex-reactive] the client was loaded twice. Import EITHER phlex/reactive/reactive_controller (the default, "+"everything in one file) OR phlex/reactive/core (features on demand), not both — each carries its own state.");globalThis[us]=!0;var ls=!1;function pu(){if(ls)return;if(typeof document>"u")return;let e=document.querySelectorAll('[data-controller~="reactive"]');if(!e||e.length===0)return;console.warn("[phlex-reactive] found "+e.length+' element(s) with data-controller="reactive" '+"but the reactive controller never connected. It is loaded but not registered — "+'add `application.register("reactive", ReactiveController)` (importmap) or import it into app/javascript/controllers/ for lazyLoadControllersFrom apps. See the README.')}if(typeof window<"u"&&typeof document<"u"){let e=()=>setTimeout(pu,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var mu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function fs(e){let t=String(e).toLowerCase();return t.startsWith("on")||mu.has(t)}var jn=new WeakMap;function hu(e,t,n){let[r,o,i]=t;jn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,jn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};jn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,gu(e))}function gu(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var bu=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",vu=new Set(["lexxy-editor","trix-editor"]);function D(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
1
+ import{Controller as Jc}from"@hotwired/stimulus";import{confirmResolver as yi}from"phlex/reactive/confirm";import{confirmPredicate as bs}from"phlex/reactive/confirm_predicate";var j=new WeakMap,Ve=new WeakMap;function N(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Ve.set(n.root,n)}return n}function x(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function G(e,t){x(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Ye(e,t){let n=N(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Ss(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")Is(n,s.target);else n.groups=$s(n),Ar(n);br(n)},x(n,"input change",n.show),x(n,"focusout",(s)=>{let c=s.target?.getAttribute?.("name");if(!c||n.touched?.has(c)||!n.core.owns(s.target))return;if((n.touched??=new Set).add(c),n.root.querySelector?.("[data-reactive-show-after]"))br(n)}),G(n,n.show);if(!n.arm&&Es(n))x(n,"input change",(s)=>gr(n,s)),G(n,n.arm=()=>{gr(n,null),Ar(n)});if(!r&&(r=n.show||n.arm))x(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=ue(n)))x(n,"input",(s)=>Ws(n,s)&&U(n)),G(n,()=>U(n));if(!i&&(i=fe(n)))G(n,()=>Mr(n));if(!a&&(a=Js(n)))x(n,"input change",(s)=>Ir(n,s)),G(n,()=>at(n))})(),x(n,"keydown",(s)=>ia(n,s)),x(n,"paste drop",(s)=>sa(n,s)),x(n,"input",(s)=>aa(n,s))}function Xe(e){let t=j.get(e);if(!t)return;j.delete(e),Ve.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Ze(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Qe(e,t,n){return Ir(N(e,t),n)}function et(e,t,n){return Br(N(e,t),n)}var vs=/^#[A-Za-z_][\w-]*$/,Er="[data-reactive-show-field], [data-reactive-show]";function ys(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Dr){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Wr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function xr(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function ws(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function _r(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return z(n,t);return As(e,t)}function As(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>pt(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function ce(e,t="show"){if(typeof e==="string"&&vs.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ss(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(Er)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(le)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${Rr}, ${Lr}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Es(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function xs(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:ws(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function gr(e,t){let n=xs(e);if(!n.length)return;let r=Tr(e,e.core.ownership());n.forEach((o,i)=>{let a=z(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function br(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=Tr(e,t),o=[];for(let i of e.root.querySelectorAll(Er)){if(!t(i))continue;let a=i.getAttribute("data-reactive-show");if(a!==null){let l=_r(xr(a),r);if(l===null)continue;let d=i.getAttribute("data-reactive-show-after"),f=l&&(d==null||!!e.touched?.has(nt(d,n)));vr(i,f,t,n);let m=(e.shown??=new WeakMap).get(i);if(e.shown.set(i,f),_s.some((b)=>i.hasAttribute(`data-reactive-show-${b}`))&&m!==void 0&&m!==f)o.push(i);continue}let s=i.getAttribute("data-reactive-show-field");if(!s)continue;let c=r(s);if(c===null)continue;let u=ys(i,c);if(u===null)continue;vr(i,u,t,n)}if(e.groups)Ds(e,r,t,n);Os(e,r,t),Ms(e,r,t,n),Ts(e,r),qs(e,r);for(let i of o)ks(e,i,t,n)}var _s=["clear","focus","scroll"];function ks(e,t,n,r){if(t.hidden){let s=[];try{s=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(s)?s:[]).map((u)=>nt(String(u),r)));for(let u of c.size?e.root.querySelectorAll("[name]"):[]){if(!c.has(u.getAttribute("name"))||!n(u)||u.type==="file")continue;if(u.type==="checkbox"||u.type==="radio"){if(u.checked)u.checked=!1,M(u)}else e.core.setValue(u,"")}return}let o=t.getAttribute("data-reactive-show-scroll")==="true";if(o)t.scrollIntoView?.({block:"nearest"});let i=t.getAttribute("data-reactive-show-focus"),a=null;try{a=i?e.root.querySelector(i):null}catch{}a?.focus?.(o?{preventScroll:!0}:void 0)}function vr(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function Ts(e,t){let n=kr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Rs(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!ce(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>pt(l,a))}else{let l=jr(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function Rs(e,t,n){if(!ce(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=ra(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!oa(r))return;let i=z(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function kr(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function Ls(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(tt(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function tt(e,t){return`[name="${nt(e,t)}"]`}function nt(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Tr(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?rt(e,o,t,n).filter((s)=>s.checked).length:Ls(e,o,t,n));return r.get(a)}}var Rr="[data-reactive-media]";function Os(e,t,n){for(let r of e.root.querySelectorAll(Rr)){if(!n(r))continue;let o,i,a;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)a=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!a){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let s=t(o.field);if(s===null)continue;let c=o.take>0?[...s]:null,u=c?c.slice(0,o.take).join(""):s,l=c?.length<o.take||i?.test(u)===!1||a?.test(s)===!1;if(l&&o.pending==="keep"){yr(r,"pending");continue}let d=!l&&Object.hasOwn(o.pool,u)?wr(e,o.pool[u])[0]:null,f=e.core.copyMedia(r,d??null);if(f===null)continue;if(yr(r,l?"pending":f===!1?"miss":"hit"),typeof o.label!=="string")continue;let m=l?"":f===!1?String(o.blank??""):f;for(let v of wr(e,o.label))if(v.textContent!==m)v.textContent=m}}function yr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function wr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Lr="[data-reactive-css-vars]",Ns=/^--[a-z0-9-]+$/i,Fs=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ms(e,t,n,r){let o=[...e.root.querySelectorAll(Lr)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))o.unshift(e.root);for(let i of o){let a;try{a=JSON.parse(i.getAttribute("data-reactive-css-vars"))}catch{}if(!Array.isArray(a?.to)||!a.vars||typeof a.vars!=="object"){console.warn("[phlex-reactive] malformed data-reactive-css-vars — skipped (two reactive_css_vars on one element?)");continue}let s=a.to.flatMap((c)=>{let u={to:c,global:a.global===!0},l=[];try{l=e.core.opTargets(u)}catch{}if(!l.length)e.core.diagnose("reactive_css_vars",u);return l});for(let[c,u]of Object.entries(a.vars)){let l=u?.unit??"";if(!Ns.test(c)||!Fs.includes(l)||typeof u?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(c)} — skipped`);continue}let d=Cs(e,t,u.field,n,r);if(d===void 0)continue;let f=d===null?"":`${d}${l}`;for(let m of s){if(m.style.getPropertyValue(c)===f)continue;if(f)m.style.setProperty(c,f);else m.style.removeProperty(c)}}}}function Cs(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(tt(n,o))].some((s)=>r(s)&&s.type==="checkbox"))return i==="true"?1:0;let a=i.trim()?Number(i):NaN;return Number.isFinite(a)?a:null}var le="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function $s(e){return!!e.root.querySelector?.(le)}function rt(e,t,n,r,o){return[...e.root.querySelectorAll(tt(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Ps(i.getAttribute("data-reactive-group"),o)))}function Ps(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Is(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Or(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function ot(e,t,n){if(!t)return;let r=Ve.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Or(r,t,n!==!1),r.show?.()}function Or(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=rt(e,t,e.core.ownership(),i,o).filter((s)=>s!==r&&s.checked!==n);for(let s of a)s.checked=n;e.flipping=!0;try{for(let s of a)for(let c of["input","change"])s.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function Ds(e,t,n,r){for(let o of e.root.querySelectorAll(le)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=_r(xr(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=o.getAttribute("data-reactive-select-all-under"),u=rt(e,s,n,r,c).filter((d)=>d!==o),l=u.filter((d)=>d.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function qs(e,t){for(let[n,r]of Object.entries(kr(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!ce(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!ce(a,"group"))continue;let c=z(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function Ar(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${le}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function ue(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Ws(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var js=/[\s\-'(),./]/;function Bs(e,t,n){if(e==="prefix")return t.startsWith(n);if(e!=="word_start")return t.includes(n);for(let r=t.indexOf(n);r!==-1;r=t.indexOf(n,r+1))if(r===0||js.test(t[r-1]))return!0;return!1}function U(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=e.root.getAttribute("data-reactive-filter-match"),a=e.root.hasAttribute?.("data-reactive-filter-fold"),s=(f)=>{let m=(f??"").toLowerCase().trim();return a?m.normalize("NFD").replace(/\p{M}/gu,""):m},c=s(o.value),u=0;for(let f of e.root.querySelectorAll(n)){if(!r(f))continue;let m=f.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Bs(i,s(f.getAttribute("data-reactive-filter-text")??f.textContent),c);if(f.hidden=m,m)f.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let f of e.root.querySelectorAll(l)){if(!r(f))continue;let m=[...f.querySelectorAll(n)].filter(r);if(m.length===0)continue;f.hidden=m.every((v)=>v.hidden)}let d=e.root.getAttribute("data-reactive-filter-empty");if(d){for(let f of e.root.querySelectorAll(d))if(r(f))f.hidden=u>0}}function fe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Js(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function it(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function st(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function Nr(e,t){let n=it(e);if(!n)return!1;let r=st(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)Fr(e,n,r);return i}function Fr(e,t,n){t.value=n.join(","),M(t),Mr(e)}function Hs(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Mr(e){let t=it(e);if(!t)return;let n=st(t),r=e.core.ownership();Gs(e,n,r),Us(e,n,r)}function Gs(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Us(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!ue(e))o.hidden=!1}}if(ue(e))U(e)}function zs(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Ks(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Vs(e,t){if(e.nestedWarned)return;console.warn(`[phlex-reactive] nested rows: no owned [data-reactive-nested-list="${t}"] container + <template data-reactive-nested-template="${t}"> pair found in this root — the add `+"trigger did nothing. Render both inside the same reactive root (reactive_nested_list / reactive_nested_template)."),e.nestedWarned=!0}function Ys(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let d=a.find((f)=>$r(f.getAttribute?.("name"))===c);if(!d)continue;Xs(d,l),s.push(l)}if(r)for(let c of s)Zs(c);return s[0]??null}function Xs(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:ze(t)!=="";else e.value=ze(t);M(e)}function Zs(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function Qs(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Sr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);at(e)}function at(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Pr(e,n.getAttribute("data-reactive-nested-json"))}function ea(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Cr(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=$r(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=ze(o)}return n}function $r(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function ze(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Pr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ea(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Cr(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function ct(e,t,n){let r=N(e,t);if(!fe(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!Nr(r,String(o.value??"").split(",")))return;if(o.value="",ue(r))U(r)}function ut(e,t,n){let r=N(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Nr(r,[i]))return;let a=Hs(r);if(!a)return;a.value="",U(r),a.focus?.()}function lt(e,t,n){let r=N(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=it(r);if(!a)return;let s=st(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Fr(r,a,c)}function ft(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Vs(r,i);return}let l=u.cloneNode(!0);Ks(l,zs(r)),s.appendChild(l);let d=o?.getAttribute?.("data-reactive-nested-from-param"),f=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",m=Ys(r,l,d,f);if(d)m?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Pr(r,i)}function dt(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Br(r,s):null);if(!c)return Sr(r,i);let u=Cr(r,i),l=Qs(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((d)=>{if(d)Sr(r,i)})}function Ir(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;at(e)}var Dr=["gte","gt","lte","lt"],ta=["len_eq","len_gte","len_gt","len_lte","len_lt"],qr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],na=["digits_eq","digits_gte","digits_lt","digits_lte"];function Ke(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function Wr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function jr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Dr)if(n in e)return Wr(n,e[n],t);for(let n of ta)if(n in e)return Ke(n,e[n],[...String(t??"")].length);return null}function pt(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=qr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Ke(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(a)=>{let s=String(t(a)??"");return e.fold===!0?s.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):s};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=na.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((s)=>Number.isInteger(e[s]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((s)=>Ke(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return jr(e,o)===!0}function z(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>pt(r,t)))}function ra(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n){if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field);if(typeof r?.same==="string")t.add(r.same)}}return t.size>0?[...t]:null}function oa(e){return e.flat().every((t)=>qr.some((n)=>(n in Object(t))))}function Br(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=bs(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=z(n.groups?.any,o)===!0;return i?n.message:null}function mt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ia(e,t){let n=mt(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function sa(e,t){let n=mt(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function aa(e,t){let n=mt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as ca}from"phlex/reactive/compute";var V=new WeakMap;function Ur(e,t){let n=V.get(e);if(!n)V.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function gt(e,t,n,r){let o=Ur(e,t),i=Ea(o);if(i)o.seed=()=>ht(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)ht(o)}function bt(e){let t=V.get(e);if(!t)return;if(V.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function vt(e){V.get(e)?.seed?.()}function yt(e,t,n){return ht(Ur(e,t),n)}var ua=Object.freeze({el:null,kind:""}),la=/^#[A-Za-z_][\w-]*$/;function K({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function zr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function fa(e,t){if(t==="string")return K(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):zr(K(e));if(n)return e.el.checked?1:0;let r=Number(K(e));return Number.isFinite(r)?r:0}function da(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=zr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return pa(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function pa(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function ma(e){if(e==null)return null;let t=Array.isArray(e)?e:e.ops;if(Array.isArray(t))return t.length>0?t:null;return console.warn("[phlex-reactive] $ops must be an ops chain or a [[op, args], ...] list — skipped"),null}function ha(e){if(typeof e==="string"&&la.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function ga(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function ba(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function va(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function ya(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=wa(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function wa(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Hr(e,t,n){let r=String(n);for(let o of Aa(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Aa(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Gr(e,t,n){let r=Sa(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?K(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!ha(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Sa(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function Ea(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function ht(e,t){if(t&&e.ours.has(t))return;let n=va(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let p=s.get(h);if(p)return p;let w=null,A=null,q=null;for(let W of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(W))continue;let ae=W.type;if(ae==="checkbox"||ae==="radio"&&W.checked){q={el:W,kind:ae};break}if(ae==="radio")w??=W;else A??=W}if(!q)if(w)q={el:w,kind:"radio"};else q=A?{el:A,kind:""}:ua;return s.set(h,q),q};for(let h of r)Hr(e,h,K(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?ca(u):null;if(!l){Gr(e,{},c);return}let d=ba(e,"data-reactive-compute-outputs-param"),f={};for(let[h,p]of n)f[h]=fa(c(h),p);let m=l(f,{changed:ya(e,t,r,o)})||{},v=ma(m.$ops),b=[];for(let h of d){if(h==="$ops"||!(h in m))continue;let p=c(h);if(!p.el)continue;let w=da(e.root,a,p,i(h),m[h]);if(w)b.push(w)}for(let h of Object.keys(m)){if(h==="$ops")continue;let p=m[h];if(p===void 0||p===null)continue;Hr(e,h,p)}Gr(e,m,c);for(let h of b){let p=new Event("input",{bubbles:!0});e.ours.add(p),h.dispatchEvent(p)}ga(e,v,Boolean(t))}var Et;function xt(e){Et=e}var Zr=1,xa="phlex-reactive:persist:",_a=new Set(["hidden","file","password","submit","button","reset","image"]),_t=Symbol("persist-no-value"),kt="data-reactive-persist-state",ka=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ta=new Set(["lexxy-editor","trix-editor"]),Ra="lexxy-editor, trix-editor, trix-toolbar",La=["lexxy:change","trix-change"],Oa=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Vr=new WeakSet,Yr=new WeakSet,Xr=new WeakSet;function pe(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!Vr.has(e))Vr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Tt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Rt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Yr.has(e))return;Yr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Lt(e){return xa+e.key}function At(e,t){let n=Tt(t);if(!n)return null;let r;try{r=n.getItem(Lt(t))}catch(c){return Rt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Zr)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return de(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function Qr(e,t,{fields:n,state:r}){let o=Tt(t);if(!o)return!1;let i={v:Zr,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Lt(t),JSON.stringify(i)),!0}catch(a){return Rt(e,a),!1}}function de(e,t){e?.removeAttribute?.(kt);let n=Tt(t);if(!n)return;try{n.removeItem(Lt(t))}catch(r){Rt(e,r)}}function Ot(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||_a.has(i.type)||i.closest(Ra))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(ka)){if(!o(i))continue;let a=Na(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Ta.has(i.localName)?"editor":"contenteditable"})}return r}function eo(e){return e.hasAttribute("data-reactive-editable")?Et.text(e):e.textContent??""}function Na(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Nt(e){return typeof e.value==="string"}function Fa(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Oa.has(e.value.trim())}function Ma(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Xr.has(e))return;Xr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function Y(e){return e.tagName==="SELECT"&&e.multiple}function to(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function no(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return _t;return e[0]}function ro(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of Ot(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Nt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=eo(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(Y(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Ca(e,t,n){let r=t.restore==="always",o=Ot(e,t),i=to(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&Y(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||Y(s))){if(l=no(l,c,i),l===_t)continue}if((s.type==="checkbox"||Y(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")oo(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&eo(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((d)=>d.kind==="native"&&d.el.type==="radio"&&d.name===c&&d.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(Y(s)){if(!r&&[...s.options].some((f)=>f.selected))continue;let d=new Set((Array.isArray(l)?l:[l]).map(String));for(let f of s.options)f.selected=d.has(f.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}$a(e,t,n)}function oo(e,t,n,r,o){if(Array.isArray(r))return;if(!Nt(t))return;if(!o&&!Fa(t))return;try{t.value=String(r)}catch(i){Ma(e,n,i)}}function $a(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Nt(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Ot(e,t),c=to(s);for(let{el:u,name:l,kind:d}of s){if(d!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let f=no(n[l],l,c);if(f===null||f===void 0||f===_t)continue;oo(e,u,l,f,i)}})}function Pa(e,t,n=!0){let r=pe(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=At(e,r),i={...o?.state??{},...t},a=n?ro(e,r):o?.fields??{};if(Qr(e,r,{fields:a,state:i}))e.setAttribute?.(kt,JSON.stringify(i))}function Ia(e){let t=pe(e);if(t)de(e,t)}var St=new WeakMap,wt=new WeakMap;function Da(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=wt.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],wt.set(e,n)}let[r,o]=n;return r.add(t),()=>{if(r.delete(t),r.size>0)return;e.removeEventListener?.("turbo:submit-end",o),wt.delete(e)}}function Ft(e,t,n,r){let o=e.element,i=pe(o);if(!i)return;if(r?.submitted)de(o,i);let a=At(o,i);if(a){if(Ca(o,i,a.fields),a.state)o.setAttribute?.(kt,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let v=At(o,i);Qr(o,i,{fields:ro(o,i),state:v?.state??null})},l=()=>{let v=Number(i.debounce)||0;if(v<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},v)},d=(v)=>{if(!v?.detail?.success)return;let b=v.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),de(o,i)},f=["input",...La];for(let v of f)o.addEventListener?.(v,l);o.addEventListener?.("change",u);let m=Da(globalThis.document,d);if(St.set(e,()=>{if(s!==null)u();for(let v of f)o.removeEventListener?.(v,l);o.removeEventListener?.("change",u),m()}),r?.edited&&!r.submitted)u();for(let v of r?.ops??[])v(!0)}function Mt(e){let t=St.get(e);St.delete(e),t?.()}function io(e,t){let n=Et?.waiting.get(e)?.persist;if(!n||!pe(e))return t(!0);(n.ops??=[]).push(t)}function Ct(e,t){io(e,(n)=>Pa(e,t,n))}function $t(e){io(e,()=>Ia(e))}var me=new WeakMap,ao=new WeakSet,Pt=new WeakMap;function It(e,t){let n=e.element,r=[],o=[],i=(u,l,d)=>{u.addEventListener?.(l,d),r.push(()=>u.removeEventListener?.(l,d))},a,s,c=()=>{if(!a&&(a=qa(n,t))){let u=()=>he(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Ba(n,r)}if(!s&&(s=Ja(n,t))){let u=()=>Ha(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};me.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Dt(e){for(let t of me.get(e)?.[0]??[])t();me.delete(e)}function qt(e){me.get(e)?.[1]()}function qa(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function he(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,Wa(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function Wa(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function ja(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Ba(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Pt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(ja(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(ao.has(c)||!i())return;if(ao.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),Pt.delete(n)}},Pt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ja(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function Ha(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function Jt(e){Ga(e),za(e)}function Ga(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Wt);else setTimeout(Wt,0);return}let r=async(o)=>{await n(o),Wt()};r.__reactiveDismissWrapped=!0,t.render=r}function Wt(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var Ua=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),jt=Object.freeze(["fade","slide","scale","highlight","shake"]),Bt="data-reactive-fx-pending",Ht=1000;function za(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Ua[r?.getAttribute?.("action")];if(!o||Ya())return;let i=Ka(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Qa(ge(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Xa(r):null;if(await n(s),o==="enter")Za(c,i);else lo(ge(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Ka(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return uo(n,t);let o=(t==="enter"?Va(e):ge(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?uo(o,t):null}function ge(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Va(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function uo(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?jt[Math.floor(Math.random()*jt.length)]:e;if(!jt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ya(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Xa(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Bt,"");return ge(e)}function Za(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Bt}]`)))n.removeAttribute(Bt),lo(n,t)}async function Qa(e,t){if(!e?.classList)return;if(t.legs){await fo(e,t.legs);return}e.classList.add(t.className);let n=Gt(e);if(n<=0){e.classList.remove(t.className);return}await Ut(e,n),e.classList.remove(t.className)}function lo(e,t){if(!e?.classList)return;if(t.legs){fo(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Gt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ut(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function fo(e,t){let[n,r,o]=t.map(ec),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await tc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Gt(e);if(a>0)await Ut(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function ec(e){return String(e??"").split(/\s+/).filter(Boolean)}function Gt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,Ht)}catch{return 0}}function Ut(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,Ht))})}function tc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Ht),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var nc="phlex-reactive:latency",zt=!1;function ho(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function go(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),zt=!1}function Vt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:ho,disableLatencySim:go}}function Yt(){if(typeof sessionStorage>"u")return Promise.resolve();let e=Number(sessionStorage.getItem("phlex-reactive:latency"));if(!Number.isFinite(e)||e<=0)return Promise.resolve();if(!zt)zt=!0,console.warn(`[phlex-reactive] latency simulator ACTIVE — every action is delayed by ${e}ms. Call PhlexReactive.disableLatencySim() (or clear sessionStorage) to turn it off.`);return new Promise((t)=>setTimeout(t,e))}var mo=new WeakMap;function Xt(e){let t=globalThis.document;if(!t)return!0;let n=mo.get(t);if(!n)n=new Set,mo.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Kt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function bo(e,t,n,r){if(Xt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Zt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Kt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}bo(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Qt(e){if(!Xt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function en(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Kt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Kt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}bo(t,o,`scoped to #${r?.id||"?"}`,i)}function tn(e,t){let n=e.element?.id||"?";if(Xt(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function rc(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function nn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function be(e,t,n){e.streams=rc(t),e.tokenRefreshed=n!=null}var ve=new WeakMap;function rn(e,t,n,r){let o=n&&typeof n==="object"?sc(n):n;return o?yo(t,o,r,!1):[]}function on(e,t,n,r){if(!n)return null;let o=yo(t,n,r,!0);return o.length?o:null}function yo(e,t,n,r){let o=[];for(let i of wo(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(oc(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function wo(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function oc(e,t){let n=ve.get(t);if(n)n.count++;else ve.set(t,{count:1,disabled:t.disabled,html:t.innerHTML,hadText:e.text!=null,swappedTo:e.text});if(e.disable)t.disabled=!0;if(e.text!=null)t.innerHTML=e.text;return()=>ic(t,e)}function ic(e,t){let n=ve.get(e);if(!n)return;if(--n.count>0)return;if(ve.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function sc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function sn(e,t,n,r){if(!n?.hide)return null;let o=wo(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var Ae;function un(e){Ae=e}var T=new Map;function xo(e,t){let n=!T.has(e);if(T.set(e,t),n)Ae.enter()}function Se(e){if(T.delete(e))Ae.exit()}var So=!1;function ln(e){_o();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){dc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;Z(t,n)}function _o(){if(So||typeof document>"u"||!document.addEventListener)return;So=!0,document.addEventListener("turbo:before-stream-render",mc,!0),document.addEventListener("turbo:before-stream-render",ac)}function ac(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(T.get(n)?.via==="stream")Se(n)}function Z(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}dn(e),Lo(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return xo(e,r),pc(e,r,t)}function cc(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[gc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":bc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function ko(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(To(t))return{src:t};return console.error(uc(t)),lc(t)||fc(e)}function uc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${fn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function lc(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${fn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&To(r))return{src:r,fallback:!0}}function fc(e){dn(e.id),pn(e),e.setAttribute("data-reactive-error","defer"),e.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e.id,reason:"refused-url"}}))}function To(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${fn()}/`)}catch{return!1}}function fn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function dc(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){Z(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}dn(e),Lo(n);let o=document.createElement("pgbus-stream-source");o.id=Ro(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),xo(e,{via:"stream"})}function Ro(e){return`reactive-defer-src-${e}`}async function pc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},vc()),o;try{Ae.count("defer"),o=await fetch(...cc(n,t.abort.signal))}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),X(e,n);return}if(T.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),X(e,n,o.status);return}if(o.status===204){clearTimeout(r),Eo(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),X(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),X(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),X(e,n);return}if(clearTimeout(r),T.get(e)!==t)return;Eo(e),hc(a)}var cn=null,mc=(e)=>cn?.push(e);function hc(e){let t=cn=[];try{window.Turbo.renderStreamMessage(e)}finally{cn=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function dn(e){let t=T.get(e);if(!t)return;if(Se(e),t.via==="fetch")t.abort.abort();else document.getElementById(Ro(e))?.remove?.()}function Lo(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function pn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Eo(e){Se(e);let t=document.getElementById(e);if(!t)return;pn(t),t.removeAttribute("data-reactive-error")}function X(e,t,n){Se(e);let r=document.getElementById(e);if(!r)return;pn(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),Z(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function gc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function bc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function vc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Oo="__materialize",we=new WeakMap;function ye(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function mn(e,t,n){_o();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>Ee(e),d=(p)=>{if(ye(r)==="visible"){if(!a)m()}else if(p){let w=r.getAttribute("data-reactive-lazy-on");if(s===w)return;f(),r.addEventListener?.(w,l),s=w}},f=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},m=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let p=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:p}),a.observe(r)},v=()=>{let p=ye(r)!==null,w=o;if(o=p,!p)return f();if(i)return;if(t.forgetToken(),!w)return l();d(!0)};if(we.set(e,{load(){if(i)return;let p=ko(r);if(!p&&r.getAttribute("data-reactive-defer-src")!=null)return;if(p&&yc(r,t))return;let w=p?Z(r.id,p):t.proceed(r,Oo,"{}");if(!w)return;i=!0,f();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);f()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&ye(r)===null)an(r),c=(p)=>p.target===r&&an(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(p)=>{if(p.target!==r)return;if(!c)an(r);v()},r.addEventListener?.("turbo:morph-element",u),n)return v();if(o=ye(r)!==null,o)d(!1)}function hn(e){let t=we.get(e);we.delete(e),t?.off()}function Ee(e){return we.get(e)?.load()}function yc(e,t){return t.emit("reactive:before-dispatch",{action:Oo,params:{},element:e},{cancelable:!0}).defaultPrevented}function an(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||ko(e);if(t)Z(e.id,t)}var gn=new WeakMap,_e=new WeakMap,g=null,C,Fo;function wn(e,t){let n=e.element;_e.set(n,t),jo();let r=(i)=>Ac(i,t),o=(i)=>kc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),gn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function An(e){if(gn.get(e)?.(),gn.delete(e),_e.delete(e.element),g&&ke(g.origin)===e.element)xe()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),Q=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},ke=(e)=>e?.closest?.('[data-controller~="reactive"]'),Po=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),F=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&Po(t)===e),Mo=(e)=>Q(S(e,"-item"),null),bn=(e)=>S(e,"-disabled")==="true",wc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Io=(e)=>{let t=S(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>S(n,"-group")===t&&!bn(n)&&_e.has(ke(n)))};function Do(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Po(n);if(g||!r||!t.owns(r)||bn(r)||bn(n))return;if(ke(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Ac(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Do(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(p)=>p.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(p)=>{if(!a(p))return;if(g)return vn(p.clientX,p.clientY);if(Math.abs(p.clientX-o)<=4&&Math.abs(p.clientY-i)<=4)return;if(!c)return h();Ec(n,t,p),vn(p.clientX,p.clientY)},d=(p)=>g&&p.cancelable&&p.preventDefault(),f=(p)=>{if(!a(p))return;if(h(),g)Sc(),yn()},m=(p)=>{if(p.type==="pointercancel"&&!a(p))return;if(h(),g)xe()},b=[["pointermove",l],["pointerup",f],["pointercancel",m],["keydown",(p)=>p.key==="Escape"&&g&&(p.preventDefault(),m(p))],["touchmove",d,{passive:!1}]];for(let[p,w,A]of b)document.addEventListener(p,w,A);function h(){clearTimeout(u);for(let[p,w]of b)document.removeEventListener(p,w)}}function Sc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Ec({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,g=qo({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),g.dx=r.clientX-o.left,g.dy=r.clientY-o.top,g.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function qo(e){let{row:t,origin:n,source:r}=e;return e.index=F(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),ee(n,!0),e}var ee=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Te(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function vn(e,t){g.x=e,g.y=t,g.row.style.left=`${e-g.dx}px`,g.row.style.top=`${t-g.dy}px`;let n=Io(g.origin).find((r)=>wc(r,e,t));if(n)xc(n,e,t);else if(g.source)Sn(null),g.placeholder.remove();_c(e,t)}function Sn(e){if(g.target!==g.origin)ee(g.target,!1);g.target=e,ee(e,!0)}function xc(e,t,n){Sn(e);let r=F(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});Te(e,r,s<0?r.length:s,g.placeholder)}function _c(e,t){let n=g.target??g.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(g.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,g.wy=t<40?-12:t>window.innerHeight-40?12:0,(g.vy||g.wy)&&!g.raf){let i=()=>{if(!g||!(g.vy||g.wy))return g&&(g.raf=0);if((g.target??g.origin).scrollTop+=g.vy,g.wy)window.scrollBy(0,g.wy);vn(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function kc(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":yn,Enter:yn,Escape:xe,Tab:xe,ArrowUp:()=>Co(-1),ArrowDown:()=>Co(1),ArrowLeft:()=>$o(-1),ArrowRight:()=>$o(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Do(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),g=qo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Le("picked")}function Co(e){let t=F(g.target),n=Re()+e;if(n>=0&&n<=t.length)Te(g.target,t,n,g.row);Wo()}function $o(e){let t=Io(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=Re();Sn(n),Te(n,F(n),r,g.row)}Wo()}function Wo(){g.row.focus?.(),Le("moved")}function Re(){let e=F(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function jo(){if(!C?.isConnected)C=document.createElement("div"),C.setAttribute("aria-live","polite"),C.setAttribute("data-reactive-sortable-live",""),C.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(C);return C}function Le(e){let t=g.target??g.origin,n=(Q(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Re()+1).replaceAll("{count}",F(t).length+1),r=jo();r.textContent="",cancelAnimationFrame(Fo),Fo=requestAnimationFrame(()=>r.textContent=n)}function yn(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?Re():-1,c=a?Mo(F(t)[s-1]):null;if(e.keyboard)Le("dropped");if(!r&&i)i.replaceWith(o);if(Jo(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=Q(S(t,"-from"),{})[u]??S(t),d={...Q(S(t,"-params"),{}),item:Mo(e.item),position:s,after:c,from:u},f=[];for(let v=t;v;v=v.parentElement)f.push(v);let m=_e.get(ke(t))?.proceed(t,l,JSON.stringify(d),Q(S(t,"-busy")));if(r)return;Promise.resolve(m).then((v)=>Tc(v,f)||Bo(e))}function Tc(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&Rc(r,t))}function Rc(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function xe(){let e=g;if(e.keyboard)Le("cancelled");e.placeholder?.remove(),Jo(e),Bo(e)}function Bo({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Te(t,F(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Jo(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(g=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),ee(n,!1),ee(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Ko={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Vo={x:"left",y:"top",width:"width",height:"height"},En=new WeakMap,kn=new WeakMap,y=null,P,Go,Uo=!1;function Tn(e,t){let n=e.element;kn.set(n,t),ii(),qc();let r=[["pointerdown",(o)=>Cc(o,t,n)],["keydown",(o)=>Dc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Ko[o.key]&&_n()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&_n()],["input",(o)=>zo(o,t,n)],["change",(o)=>zo(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);En.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Rn(e){if(En.get(e)?.(),En.delete(e),kn.delete(e.element),y?.root===e.element)J(y)}var _=(e,t,n)=>Math.min(Math.max(e,t),n),R=(e)=>Math.round(e*1e4)/1e4;function Lc(e,t=1){let n=R(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Ln(e){let t={x:R(e.x),y:R(e.y)};if(e.width!=null)t.width=R(e.width),t.height=R(e.height),t.x=Math.min(t.x,R(1-t.width)),t.y=Math.min(t.y,R(1-t.height));return t}function Yo(e,t,n){return{x:_(e.x+t,0,1-e.width),y:_(e.y+n,0,1-e.height),width:e.width,height:e.height}}function Xo(e,t,n){return{x:_(e.x+t,0,1),y:_(e.y+n,0,1)}}function Zo(e,t,n,r,o,i){let[a,s,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,d=e.y+e.height,f=e.x+e.width/2,m=e.y+e.height/2,v=s?1-e.x:u?l:i?2*Math.min(f,1-f):1,b=c?1-e.y:a?d:i?2*Math.min(m,1-m):1,h=e.width+(s?n:u?-n:0),p=e.height+(c?r:a?-r:0);if(i){let w=(s||u)&&(!(a||c)||Math.abs(h-e.width)>=Math.abs(p-e.height)*i),A=Math.min(v,b*i);h=_(w?h:p*i,Math.min(Math.max(o,o*i),A),A),p=h/i}else{if(s||u)h=_(h,Math.min(o,v),v);if(a||c)p=_(p,Math.min(o,b),b)}return{x:u?l-h:s?e.x:f-h/2,y:a?d-p:c?e.y:m-p/2,width:h,height:p}}function Oc(e,t,n){let r=Math.min(1,t),o=_(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:_(e.x+e.width/2-o/2,0,1-o),y:_(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function Nc(e){let[t,n=1,r]=String(e??"").split(":").map(Number),o=r===void 0?t/n:0;return o>0&&Number.isFinite(o)?o:0}var E=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),On=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},L=(e)=>e.matches("[data-reactive-point]")?"point":"box",Qo=(e)=>Number(E(e,`${L(e)}-scale`))||1,B=(e)=>L(e)==="point"?["x","y"]:["x","y","width","height"];function ei(e){let t={};for(let n of B(e))t[n]=(parseFloat(e.style[Vo[n]])||0)/100;return t}function Oe(e,t){for(let n of B(e))e.style[Vo[n]]=`${Math.round(t[n]*1e4)/100}%`}function Nn(e){let t=e.getBoundingClientRect();return{left:t.left+(e.clientLeft||0),top:t.top+(e.clientTop||0),width:e.clientWidth||t.width,height:e.clientHeight||t.height}}function Fc(e,t){try{return e.parentElement.closest(E(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function ti(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function ni(e,t,n){let r=On(E(e,L(e)),{}),o={};for(let i of B(e)){let[a]=ti(t,n,r[i]);if(a)o[i]=a}return o}function Mc(e,t,n,r){let o=E(e,"box-aspect"),i=o&&ti(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),a=o?Nc(i?.value):Number(E(e,"box-ratio"))||0,{width:s,height:c}=Nn(t);return a&&s&&c?a*c/s:0}function Fn(e,t,n,r){let o=n.matches("[data-reactive-box-handle]")?n.closest("[data-reactive-box]"):n,i=o?.closest("[data-reactive-frame]");if(!i)return null;let a=ei(o),s=ni(o,t,e),c=L(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?Fc(o,i):i,edge:E(n,"box-handle"),start:a,value:a,ratio:c?0:Mc(o,i,t,e),min:Number(E(o,"box-min"))||0,scale:Qo(o),fields:s,before:Object.fromEntries(Object.entries(s).map(([u,l])=>[u,l.value]))}}function ri(e,t,n,r){let o=Lc(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function te(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))ri(e.core,n,e.value[t],e.scale)}function Cc(e,t,n){if(oi(),y||e.button>0||e.isPrimary===!1||e.target.closest?.("input,textarea,select,[contenteditable]"))return;let r=e.target.closest?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]"),o=r&&t.owns(r)&&Fn(t,n,r,!1);if(!o)return;let{clientX:i,clientY:a}=e,s=Nn(o.bounds);o.p0=[(i-s.left)/s.width,(a-s.top)/s.height];let c=(b)=>b.pointerId===e.pointerId,u=(b)=>{if(!c(b)||o.over)return;if(y)return xn(b.clientX,b.clientY);if(Math.abs(b.clientX-i)<=4&&Math.abs(b.clientY-a)<=4)return;Pc(o),xn(b.clientX,b.clientY)},l=(b)=>{if(!c(b))return;if(v(),y)$c(),_n()},d=(b)=>{if(b.type==="pointercancel"&&!c(b))return;if(v(),y)ci()},m=[["pointermove",u],["pointerup",l],["pointercancel",d],["keydown",(b)=>b.key==="Escape"&&y&&(b.preventDefault(),d(b))]];for(let[b,h]of m)document.addEventListener(b,h);function v(){for(let[b,h]of m)document.removeEventListener(b,h)}}function $c(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Pc(e){y=e,e.grip.setAttribute("data-reactive-dragging",""),e.frame.setAttribute("data-reactive-frame-active",""),e.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none"}function xn(e,t){let n=y;if(!n.el.isConnected)return J(n);n.x=e,n.y=t;let r=Nn(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:a,edge:s}=n;n.value=Ln(L(n.el)==="point"?Xo(a,o,i):s?Zo(a,s,o,i,n.min,n.ratio):Yo(a,o,i)),Oe(n.el,n.value),n.writing||=requestAnimationFrame(()=>te(n)),Ic(t)}function Ic(e){if(y.wy=e<40?-12:e>window.innerHeight-40?12:0,y.wy&&!y.raf){let t=()=>{if(!y?.wy)return y&&(y.raf=0);if(window.scrollBy(0,y.wy),xn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function oi(){if(y&&!y.el.isConnected)J(y)}function Dc(e,t,n){oi();let r=e.target;if(!r?.matches?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]")||!t.owns(r)||y&&(!y.keyboard||y.grip!==r))return;if(e.key==="Escape")return y&&(e.preventDefault(),ci());let o=Ko[e.key];if(!o)return;if(e.preventDefault(),y??=Fn(t,n,r,!0),!y)return;let[i,a]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),s=e.altKey&&L(y.el)==="box",c=y.value;y.value=Ln(L(y.el)==="point"?Xo(c,i,a):s?Zo(c,y.edge??"se",i,a,y.min,y.ratio):Yo(c,i,a)),Oe(y.el,y.value),te(y),si(y,s?"resized":"moved")}function ii(){if(!P?.isConnected)P=document.createElement("div"),P.setAttribute("aria-live","polite"),P.setAttribute("data-reactive-drag-live",""),P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(P);return P}function si(e,t){let n=On(E(e.el,`${L(e.el)}-messages`),{})[t]??"";for(let o of B(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=ii();r.textContent="",cancelAnimationFrame(Go),Go=requestAnimationFrame(()=>r.textContent=n)}function zo(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(E(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=Fn(t,n,o,!0),{ratio:a,start:s}=i??{};if(!a||Math.abs(s.width/s.height/a-1)<0.005)continue;i.value=Ln(Oc(s,a,i.min)),Oe(o,i.value),te(i),ai(i)}}function _n(){let e=y;if(!e.el.isConnected)return J(e);te(e),J(e),ai(e)}function ai(e){for(let[o,i]of Object.entries(e.fields))if(i.value!==e.before[o])i.dispatchEvent(new Event("change",{bubbles:!0}));let t=L(e.el),n=E(e.el,`${t}-action`),r={};for(let o of B(e.el))r[o]=R(e.value[o]);if(!n||B(e.el).every((o)=>r[o]===R(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),On(E(e.el,`${t}-busy`)))}function ci(){let e=y;if(e.value=e.start,Oe(e.el,e.start),te(e),e.keyboard)si(e,"cancelled");J(e)}function J(e){if(y=null,e.over=!0,cancelAnimationFrame(e.raf),cancelAnimationFrame(e.writing),e.grip.removeAttribute("data-reactive-dragging"),e.frame.removeAttribute("data-reactive-frame-active"),!e.keyboard)document.documentElement.style.userSelect=e.select??""}function qc(){if(Uo)return;Uo=!0,document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.target,n=e.detail?.attributeName;if(!y)return;if(t===y.el&&n==="style"||t===y.grip&&n==="data-reactive-dragging"||t===y.frame&&n==="data-reactive-frame-active"||n==="value"&&Object.values(y.fields).includes(t))e.preventDefault()}),document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;if(t===y?.el||!t.matches?.("[data-reactive-box],[data-reactive-point]"))return;let n=t.closest('[data-controller~="reactive"]'),r=kn.get(n);if(!r?.owns(t))return;let o=ei(t),i=Qo(t);for(let[a,s]of Object.entries(ni(t,n,r)))ri(r,s,o[a],i)})}var I=new Map,li=new WeakSet;function Mn(e,t){let n=e.element,r=I.get(n.id);if(!r)I.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Wc(n);let o=(a)=>a.target===n&&queueMicrotask(()=>di(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},di(r)}function Cn(e){let t=e.element,n=I.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;I.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function $n(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=I.get(e.id);if(!n)I.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},pi(n)}function Wc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&li.has(n))return;if(n?.remove(),!fi())setTimeout(()=>{if(!fi())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=I.get(e.id);if(!o||o.removing)return;pi(o),jc(o)}),li.add(r),document.body.appendChild(r)}var fi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function jc(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&mi(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function pi(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function mi(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function di(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=mi(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}var gi=new Map,Pn=new WeakMap,Bc=0,Ne=new WeakMap;function In(e,t){let n=e.element;if(!n.id&&!Pn.has(n))Pn.set(n,`#${++Bc}`);let r=n.id||Pn.get(n),o=new Map,i=!1,a=(m)=>{clearTimeout(o.get(m)),o.delete(m)},s=(m,v,b)=>{a(m);let h=Date.parse(v.until)-Date.now();if(!(h>0))return c(m,v,b);let p=Math.ceil(h/1000);bi(m,`${Math.floor(p/60)}:${String(p%60).padStart(2,"0")}`,"running"),u(v.waiting,!0),u(v.done,!1),o.set(m,setTimeout(()=>s(m,v,b),(h-1)%1000+1))},c=(m,v,b)=>{bi(m,"0:00","done"),u(v.waiting,!1),u(v.done,!0);let h=gi.get(b)??new Set;if(h.has(v.until))return;gi.set(b,h.add(v.until)),m.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:v.until}}))},u=(m,v)=>{let b;try{b=m&&n.querySelector(m)}catch{}if(b&&b.hidden===v)b.hidden=!v},l=()=>{if(i=!1,!Ne.has(e))return;let m=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((b,h)=>{if(!t.owns(b))return;let p;try{p=JSON.parse(b.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(p?.until)))return;m.add(b),s(b,p,`${r}|${b.id||h}`)});for(let b of o.keys())if(!m.has(b))a(b)},d=()=>{if(i)return;i=!0,queueMicrotask(l)},f=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",d),n.addEventListener("reactive:streamed",d),document.addEventListener("visibilitychange",f),Ne.set(e,()=>{n.removeEventListener("turbo:morph-element",d),n.removeEventListener("reactive:streamed",d),document.removeEventListener("visibilitychange",f);for(let m of[...o.keys()])a(m)}),l()}function Dn(e){Ne.get(e)?.(),Ne.delete(e)}function bi(e,t,n){if(e.textContent!==t)e.textContent=t;if(e.getAttribute("data-reactive-countdown-state")!==n)e.setAttribute("data-reactive-countdown-state",n)}function Hc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:visit"])return;e["reactive:visit"]=function(){let t=this.getAttribute("data-url");if(t)window.Turbo.visit(t,{action:"advance"})}}function Gc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}function Uc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=pr(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)Qt(n);return}tr(t,(i)=>Mu(i,o),r?(i,a)=>Zt(i,a,o):void 0)}}function zc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){ln(this)}}var wi=!1,Kc=null;function Vc(){if(wi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;wi=!0,document.addEventListener("turbo:before-stream-render",(e)=>{cu(e),Yc(e),Zc(e),Jt(e)})}var Pe="reactive:streamed";function Yc(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(Pe))}}function or(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function ir(e){try{return e.matches(":modal")}catch{return!1}}function Ki(e){if(!or(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||ir(e))return;if(e.open)e.close();e.showModal()}function Xc(e){if(or(e)&&e.open)e.close()}function je(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!ir(r))Ki(r)}function Zc(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(o)=>{await n(o),je(document)}}var Ai=!1;function Qc(){if(Ai)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ai=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))je(t.target)}),document.addEventListener("turbo:morph",()=>je(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!or(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!ir(n))return;e.delete(n),t.preventDefault(),n.close()})}var Zn=new WeakMap;function Vi(e,t,n,r){let o=Zn.get(e)??new Map;Zn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))fs(n.name)||i(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(i("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))Vi(a,"set_attr",{name:"aria-expanded"})}}var Si=!1;function eu(){if(Si)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Si=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Zn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var Yi="data-reactive-image-fallback",ne="data-reactive-image-state",Qn="data-reactive-image-hidden",qn=null,er="data-reactive-wrap-hidden";function Xi(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(er,"")}function Zi(e){if(!e.hasAttribute(er))return;e.removeAttribute("hidden"),e.removeAttribute(er)}function re(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Yi);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Qi=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function sr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function es(e,t){let n=sr(e,t.alt);return n&&!n.contains(e)?n:null}function Be(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Qn,"");if(t.wrap){let o=sr(e,t.wrap);if(o)Xi(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=es(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Ge(e,t);e.setAttribute(ne,n)}function Ge(e,t=re(e)){if(!t||e.getAttribute(ne)==null)return;if(e.getAttribute(ne)==="error"){if(e.hasAttribute(Qn))e.removeAttribute("hidden");let n=sr(e,t.wrap);if(n)Zi(n);let r=es(e,t);if(r)r.hidden=!0}e.removeAttribute(ne),e.removeAttribute(Qn)}function Ei(e){let t=e.target,n=re(t);if(!n)return;if(e.type==="load")Be(t,n,"loaded");else if(Qi(t))Be(t,n,"error");else Ge(t,n)}function tu(){if(qn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;qn={error:Ei,load:Ei,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(ne);if(o==null||!r||!re(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=re(n);if(o)Be(n,o,r)})}};for(let[t,n]of Object.entries(qn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Yi}]`)??[]){if(!t.complete||!Qi(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Be(t,re(t)??{},o);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function rl(e){Kc=e}var Fe,Wn=null,xi="[data-reactive-editable][contenteditable=plaintext-only]";function ts(){if(Fe===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Fe=e.contentEditable==="plaintext-only"}catch{Fe=!1}return Fe}function Ie(e){if(e.matches?.(xi))e.setAttribute("contenteditable","true");e.querySelectorAll?.(xi).forEach(Ie)}function nu(){if(Wn||typeof document>"u"||typeof document.createElement!=="function")return;if(ts())return;Ie(document),Wn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Ie(t.target);else t.addedNodes.forEach(Ie)}),Wn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var _i=!1;function ki(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function ru(){if(_i)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;_i=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=ki(t);if(r)iu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Je.set(t,D(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==k)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>fr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===k)&&ki(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(k)&&cr(t)===ur(t))t.removeAttribute(k)})}var k="data-reactive-held",ar='[data-controller~="reactive"]',De=null,H=new Map;function cr(e){return e.hasAttribute("data-reactive-editable")?D(e):e.value}function ur(e){return e.hasAttribute("data-reactive-editable")?dr(e):e.defaultValue}function ou(e){if(e.hasAttribute("data-reactive-editable"))return D(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function iu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||H.has(e.closest(ar)))return;let r=ou(t);if(r===cr(e))return e.removeAttribute(k);if(r===ur(e))return;e.setAttribute(k,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function su(e){let t=[];for(let n of e.querySelectorAll(`[${k}]`)){if(n.closest(ar)!==e)continue;let r=n.getAttribute("name");if(cr(n)===ur(n))n.removeAttribute(k);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-￿]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ns(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${k}]`))if(n.closest(ar)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(k)}function au(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ti(e,t,n=null){let r={root:e,streams:0,keep:n},o=De;De=r;try{window.Turbo.renderStreamMessage(t)}finally{De=o}if(r.streams===0)ns(e,n)}function cu(e){let t=De,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{H.set(t.root,(H.get(t.root)||0)+1);try{return await r(o)}finally{let i=H.get(t.root)-1;if(i)H.set(t.root,i);else H.delete(t.root);ns(t.root,t.keep)}}}var Ri="__materialize",Li=!1;function uu(){if(Li)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Li=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}function lr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Vt()}var rs="data-reactive-active",O=0;function os(){if(O++,O===1)ss("reactive:busy")}function is(){if(O===0)return;if(O--,O===0)ss("reactive:idle")}function ol(){return O}function il(){O=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(rs)}function ss(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(rs,O>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:O}}))}var as="data-reactive-requests";function cs(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!lu(t))return;let n=fu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(as,JSON.stringify(n))}function lu(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function fu(e){try{let t=JSON.parse(e.getAttribute(as));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Oi(){Hc(),Gc(),Uc(),zc(),Vc(),ru(),Qc(),eu(),tu(),nu(),uu(),lr()}function du(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var us=Symbol.for("phlex-reactive.core");if(globalThis[us])console.error("[phlex-reactive] the client was loaded twice. Import EITHER phlex/reactive/reactive_controller (the default, "+"everything in one file) OR phlex/reactive/core (features on demand), not both — each carries its own state.");globalThis[us]=!0;var ls=!1;function pu(){if(ls)return;if(typeof document>"u")return;let e=document.querySelectorAll('[data-controller~="reactive"]');if(!e||e.length===0)return;console.warn("[phlex-reactive] found "+e.length+' element(s) with data-controller="reactive" '+"but the reactive controller never connected. It is loaded but not registered — "+'add `application.register("reactive", ReactiveController)` (importmap) or import it into app/javascript/controllers/ for lazyLoadControllersFrom apps. See the README.')}if(typeof window<"u"&&typeof document<"u"){let e=()=>setTimeout(pu,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var mu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function fs(e){let t=String(e).toLowerCase();return t.startsWith("on")||mu.has(t)}var jn=new WeakMap;function hu(e,t,n){let[r,o,i]=t;jn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,jn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};jn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,gu(e))}function gu(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var bu=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",vu=new Set(["lexxy-editor","trix-editor"]);function D(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
2
2
  `))t+=`
3
3
  `;n=!1,t+=i},o=(i)=>{for(let a of i.childNodes){let s=/^(div|p|li)$/.test(a.localName);if(s)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
4
4
  `);else if(a.nodeType===1)o(a);if(s)n=!0}};return o(e),t=t.replace(/\r\n?/g,`
5
- `).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Je=new WeakMap;function ur(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Je.has(e))Je.set(e,D(e))}function lr(e){return ur(e),Je.get(e)}function yu(e){return vu.has(e.localName)?typeof e.value==="string":!0}var Li=Object.freeze({show:(e,t,n)=>Jn(e,!1,t,n),hide:(e,t,n)=>Jn(e,!0,t,n),toggle:(e,t,n)=>Jn(e,!e.hidden,t,n),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((n)=>e.classList.toggle(n)),set_attr:(e,t)=>{if(Hn(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Hn(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Hn(t.name))return;if(Array.isArray(t.values)){let[n,r]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===n?r:n)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>Tu(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Ki(e),close_dialog:(e)=>Xc(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}hs(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)ot(r,t.group,t.checked)},presence:(e,t)=>$n(e,t.state),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=wu(e);if(!r)return;let o=null;if(t?.submitter!=null&&typeof n==="function"){if(o=n({...t,to:t.submitter})[0]??null,!(o?.form===r&&(o.type==="submit"||o.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),o=null}o?r.requestSubmit?.(o):r.requestSubmit?.()},paste_into:(e)=>Au(e),preview_file:(e,t,n)=>Su(e,t,n),set_value:(e,t)=>ms(e,String(t.value??"")),persist_state:(e,t)=>Ct(e,t.state),persist_clear:(e)=>$t(e)});function wu(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Au(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ps(e),e.focus?.()}).catch(()=>{})}var oe=new Map,ie=null;function Su(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Bn(`reads an input[type=file], not <${e?.localName}>`);let r=typeof n==="function"?n({...t,to:t.into})[0]:null;if(r?.tagName!=="IMG")return Bn(`paints an <img>, and ${JSON.stringify(t.into)} is ${r?`a <${r.localName}>`:"not on the page"}`);let o=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],i=Eu(e,t.accept),a=o.filter((l)=>typeof l?.type==="string"&&i(l)),s=a.find((l)=>l.type.startsWith("image/")),c=o.length>0&&a.length===0?"type":null;if(s&&Number.isInteger(t.max_bytes)&&s.size>t.max_bytes)c="size";let u=c==="size"?s:o[0];if(c)s=null;if(ds(r),s){let l=URL.createObjectURL(s);oe.set(r,l),r.setAttribute("src",l),xu()}else r.removeAttribute("src");if(Ge(r),t.wrap!=null){let l=n({...t,to:t.wrap});if(l.length===0)Bn(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let d of l)s?Zi(d):Xi(d)}if(t.name!=null)for(let l of n({...t,to:t.name}))l.textContent=s?s.name:"";if(c)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:{reason:c,file:u}}))}function Eu(e,t){let n=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((r)=>r.trim()).filter(Boolean);if(n.length===0)return(r)=>r.type.startsWith("image/");return(r)=>{let o=r.type.toLowerCase();return n.some((i)=>i[0]==="."?String(r.name).toLowerCase().endsWith(i):i.endsWith("/*")?o.startsWith(i.slice(0,-1)):o===i)}}function Bn(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function ds(e){let t=oe.get(e);if(t===void 0)return;if(oe.delete(e),URL.revokeObjectURL(t),oe.size===0)ie?.disconnect(),ie=null}function xu(){if(ie||typeof MutationObserver!=="function"||!document?.documentElement)return;ie=new MutationObserver(()=>{for(let[e,t]of oe)if(!e.isConnected||e.getAttribute("src")!==t)ds(e)}),ie.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ps(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ms(e,t){if(!/^(input|textarea|select)$/.test(e.localName)||e.type==="file"&&t!==""){console.warn("[phlex-reactive] set_value skipped: not a field it can write",e);return}let n=Oi(e);if(e.value=t,Oi(e)!==n)ps(e)}function Oi(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
- `):e.value}function _u(e,t,n){if(n?.transition)hu(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Jn(e,t,n,r){if(_u(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function Hn(e){if(!fs(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function hs(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Ge(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var ku='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Tu(e){return e.querySelectorAll?.(ku)?.[0]??null}function fr(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var Ni=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),Fi=Object.freeze(["meta","ctrl","alt","shift"]);function Ue(e,t,n){let r=e.split("+");for(let a of Fi)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Fi.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Ni,o)?Ni[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Ru=(e)=>e&&typeof e==="object"?e.keys:String(e),dr=()=>qe().prevented??=new WeakSet;function Gn(e,t){if(t!=null&&!e.defaultPrevented)dr().add(e);e.preventDefault()}function Me(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!dr().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Ue(Ru(e).replace(/^mod\+/,`${o}+`),t,n)}function Lu(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:fr(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function Mi(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==pr(t.currentTarget))return!1;return o<0||n===null||Ue(r.slice(o+1),t,n)}function Ou(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((o)=>r[o]===n[o])}var Ci=new WeakMap;function Nu(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Ci.get(e);if(!o)o=new WeakMap,Ci.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var $i=new WeakMap;function Fu(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=$i.get(e);if(!o)o=new WeakMap,$i.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function Qn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Li,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(Li[o](s,i,t),i?.keep===!0)Vi(s,o,i,t)}}function Mu(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function Cu(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function er(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var Pi='[data-controller~="reactive"]',$u='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',tr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!er(e);function Ii(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&tr(r))r=r.parentElement?.closest?.(t);return r??null}var Ce=new WeakMap,$e=new WeakMap;function Pu(e){return(e.getAttribute?.("data-action")??"").includes("reactive#trackDirty")||e.getAttribute?.("data-reactive-clipboard")!=null||e.querySelector?.('[data-action*="reactive#trackDirty"],[data-reactive-clipboard]')!=null}function Iu(e){return["show-targets","group-targets","on-complete","filter-input","tags-field","css-vars"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media], [data-reactive-css-vars]")!=null}function Du(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function qu(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Wu(e){return Boolean(e.matches?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]")||e.querySelector?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]"))}function Di(e){return e.getAttribute?.("data-reactive-presence")!=null}function ju(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function sl(e,t,n){}function Bu(e,t){}function al(e){return[]}function cl(e){return Promise.resolve()}var qi=new Set;function Ju(e,t,n){let r=e+t;if(qi.has(r))return;qi.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function ul(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Wi=Promise.resolve();var ji={enter:os,exit:is,count:cs,text:D,served:lr,waiting:new WeakMap},Bi=1,Un=2,zn=4,Kn=8,Vn=16,Ji=32,Hi=64,Gi=128,Ui=256;xt(ji),un(ji);var se=Symbol.for("phlex-reactive.early"),Hu=1e4,Gu=1500,pr=(e)=>e!=null&&(e===globalThis.window||e.window===e),Uu="dispatch";function qe(){return globalThis[se]??={queue:[],connected:new WeakSet},globalThis[se]}function zu(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Hu}function Ku(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function Vu(e,t,n){return{[se]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Ku(t),key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,button:e.button,submitter:e.submitter,bubbles:e.bubbles,timeStamp:e.timeStamp,defaultPrevented:e.defaultPrevented&&!dr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var He=new WeakMap;function Yu(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=He.get(e);if(!s)He.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function zi(e,t,n,r){if(e?.[se])return!1;let o=pr(e?.currentTarget),i=o?r:e?.currentTarget,a=Zu(e,i,o?`@${t}`:t),s=He.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Ue(u.filter,e,n))continue;return u.armed=!1,!0}return a}var We=new WeakMap;function Xu(e,t,n){let r=We.get(e);if(!r)We.set(e,r=new Map),setTimeout(()=>We.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Zu(e,t,n){let r=e&&We.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class gs extends Jc{static values={token:String};#h;#f=new Map;#d=new Map;#V;#A;#M;#S=0;#p=new Map;#E=new WeakMap;#r;featuresReady=Wi;#Ne=new Map;#Fe=new Set;#Y=!1;#C=null;#Me=new Map;#Ce=new Map;#$e=new Map;#X=0;#$;#x=0;#o=0;connect(){if(ls=!0,qe().connected.add(this.element),Ce.set(this.element,this),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||er(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Pe)this.#I();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(Pe,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(ur),this.#X++,this.featuresReady=Wi,this.#P(),je(this.element),this.#Q()}#P(e){this.#t(Bi,"persist",Cu,(t)=>Ft(this,t,e)),this.#t(Un,"defer",er,(t)=>mn(this,t,e)),this.#t(zn,"form",Pu,(t)=>It(this,t,e)),this.#t(Kn,"bindings",Iu,(t)=>Ye(this,t,e)),this.#t(Vn,"compute",Du,(t)=>gt(this,t,e)),this.#t(Ji,"sortable",qu,(t)=>wn(this,t)),this.#t(Ui,"drag",Wu,(t)=>Tn(this,t)),this.#t(Hi,"presence",Di,(t)=>Mn(this,t)),this.#t(Gi,"countdown",ju,(t)=>In(this,t))}#t(e,t,n,r){if(this.#x&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#x|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#D(t,"connect",o)}}#Z(){{let e=this.#o;this.#x=this.#o=0;let t=this.#e();if(e&Bi)this.#n("persist",()=>Mt(this,t));if(e&Un)this.#n("defer",()=>hn(this,t));if(e&zn)this.#n("form",()=>Dt(this,t));if(e&Kn)this.#n("bindings",()=>Xe(this,t));if(e&Vn)this.#n("compute",()=>bt(this,t));if(e&Ji)this.#n("sortable",()=>An(this,t));if(e&Ui)this.#n("drag",()=>Rn(this,t));if(e&Hi)this.#n("presence",()=>Cn(this,t));if(e&Gi)this.#n("countdown",()=>Dn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Pe(e){}#Ie(e,t){}#De(e){}#qe(e,t){}#We(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#h=void 0},owns:(e)=>this.#y(e),ownership:()=>this.#H(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>Qn(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#G(),plain:ts,text:D,served:lr,copyMedia:hs,setValue:ms,confirm:(e,t)=>Promise.resolve().then(()=>bi(e,t)).catch(()=>!1)},this.#$}#I(){if(this.#o&zn)qt(this);if(this.#o&Kn)Ze(this);if(this.#o&Vn)vt(this)}#D(e,t,n){if(Ju(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#je(){}#Q(){if(this.element.setAttribute?.("data-reactive-connected",""),this.element.isConnected)this.element.dispatchEvent?.(new CustomEvent("reactive:connect",{bubbles:!0,composed:!0,detail:{id:this.element.id}}));this.#ee();for(let[e,t]of $e.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}$e.delete(this.element)}#_=new Set;#ee(){let{queue:e}=qe();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=zu(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(Gu,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#te(o)}}#te({event:e,el:t,descs:n,win:r}){let o=Vu(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Ue(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Yu(s,c,r&&JSON.stringify(o.params)))continue;this.#_.add(s)}if(Xu(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Z(),this.#ue(),this.#fe(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(Pe,this.#r);if(qe().connected.delete(this.element),Ce.get(this.element)===this)Ce.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#_)He.delete(e);this.#_.clear()}dispatch(e){if(e.params?.action&&e.params.action!==ki&&this.#re())return this.#oe(e);let t=e.params?.shortcut;if(t!=null&&!Me(t,e,this.application?.schema?.keyMappings))return;if(zi(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l}=e.params;if(!n)return;let d=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let f=e.currentTarget??e.target;if((t!=null||!u)&&!this.#z(l,f))Gn(e,t);if(n===ki){let g=()=>{if(this.#o&Un)return Ee(this);if(this.tokenValue)return this.#k(f,n,"{}")};return this.#Y?this.featuresReady.then(g):g()}let m=this.#q(a,s),v=()=>this.#k(f,n,r,o,i,l,d);if(!m)return v();if(m instanceof Promise)return m.then((g)=>g?this.#g(g,f,v):v());this.#g(m,f,v)}#g(e,t,n){return Promise.resolve().then(()=>bi(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return et(this,this.#e(),t)}#ne(e){}#re(){return!this.tokenValue&&tr(this.element)}#oe(e){let t=Ii(this.element.parentElement,$u);if(!t){if(this.element.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] "${e.params.action}": no token on this root or above, nothing sent`);return}let n=Ce.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i}=e.params;if(r!=null&&!Me(r,e,this.application?.schema?.keyMappings))return;let a=e.currentTarget??e.target;if((r!=null||!o)&&!this.#z(i,a))Gn(e,r);$e.set(t,[...$e.get(t)??[],[e,a]]);let s=t.dataset;if(s.reactiveDormant)s.controller=`${s.controller??""} ${s.reactiveDormant}`.trim(),delete s.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Me(t.shortcut,e,this.application?.schema?.keyMappings))return;if(zi(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Fu(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Lu(n.ops),i=o.filter((s)=>Mi(s,e,null)),a=i.length<=1?i:i.filter((s)=>Mi(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())tn(this,e);return}for(let s of a){if(s.outside&&e[se])continue;if(!Ou(s,e))continue;if(s.shortcut!=null&&!Me(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(Nu(this,e,s))continue;this.#ie(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0}:s,e,r,o.indexOf(s))}}#ie(e,t,n,r){let{ops:o,confirm:i,confirmWhen:a,outside:s,window:c,shortcut:u}=e;if(s&&this.element.contains(t.target))return;if(u!=null||!c)Gn(t,u);let l=this.#q(i,a),d=this.#se(e,r,n,()=>this.#Ee(this.#Se(o)));if(!l)return d();if(l instanceof Promise)return l.then((f)=>f?this.#g(f,n,d):d());this.#g(l,n,d)}#se(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let a=JSON.stringify([t,e]);if(o>0)return()=>this.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return yt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return ct(this,this.#e(),e)}tagsPick(e){return ut(this,this.#e(),e)}tagsRemove(e){return lt(this,this.#e(),e)}nestedAdd(e){return ft(this,this.#e(),e)}nestedRemove(e){return dt(this,this.#e(),e)}syncNestedJson(e){return Qe(this,this.#e(),e)}#Be(e,t){}trackDirty(){he(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#m(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#m(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#m(e);if(!n.length)return;e.preventDefault();let r=this.#ae(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ae(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#H();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#U(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ce(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#le(e,u,t,n,i,a);return this.#v(t,n,i,e,a)}#v(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#xe(e,r,i),s=Boolean(n||o),c=(f)=>{if(!s||!f)return;let m=this.#e();if(i.inverse=on(this,m,n,r),i.undo.push(...rn(this,m,o,r)),this.#R())i.resurrect=sn(this,m,n,r)},u=!0;c(!0);let l=()=>this.#he(e,t,i,a),d=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>d()),this.queue}#Je(){return this.#ne("hints")}#ce(e,t,n,r,o,i){this.#W(e,Uu,t,()=>this.#v(n,r,o,e,i))}#W(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!pr(e))e?.addEventListener?.("blur",o,{once:!0});let a=this.#f.get(e);if(!a)this.#f.set(e,a=new Map);a.set(t,{timer:i,flush:o})}#T(e,t){let n=this.#f.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#f.delete(e)}#ue(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#le(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#v(n,r,o,e,i))}#j(e,t,n,r){let o=this.#d.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#d.delete(e)},n);return o.set(t,i),this.#d.set(e,o),r()}#fe(){for(let e of this.#d.values())for(let t of e.values())clearTimeout(t);this.#d.clear()}#s(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#de(){this.element?.removeAttribute?.("data-reactive-error")}#pe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#me(){return Yt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#he(e,t,n,r){let{fields:o,files:i}=this.#G(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#we(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),d=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#me();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let f;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Le()};if(!u)h["Content-Type"]="application/json";let p=this.#Oe();if(p)h["X-Pgbus-Connection"]=p;let w=Di(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(w)h["X-Reactive-Presence"]=w;let A=su(this.element);if(A)h["X-Reactive-Held"]=A;cs("action"),f=await fetch(this.#Te(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Re())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#pe(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(d)d.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:f.status});return}if(!f.ok){let h=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,h),this.#u(n.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let p=this.#J(h);if(this.#c=p??this.#c,d)be(d,h,p);_i(this.element,h,!0)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:f.status,body:h});return}let m=f.headers.get("Content-Type")||"";if(!m.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${m}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:f.status});return}let v=await f.text(),g=this.#J(v);if(this.#c=g??this.#c,d)be(d,v,g);if(_i(this.element,v,au(f)),n.resurrect)queueMicrotask(n.resurrect);return this.#de(),this.#s("reactive:applied",{action:e,params:s,html:v}),v}catch(f){console.error("[phlex-reactive] action error",f),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),d)nn(this,{...d,ms:this.#B()-d.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ge(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#ge(e){let t=this.#M;if(t&&t.id===e)return t;let n=du(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#y(e){return e.closest('[data-controller~="reactive"]')===this.element}#H(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#be(){let e=this.element.querySelectorAll(Pi);if(e.length===0||[...e].every(tr))return()=>!0;return(t)=>Ii(t,Pi,this.element)===this.element}#G(){let e={},t=[],n=this.#be(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${bu}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#ve(r),a=this.#ye(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?D(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!yu(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#ve(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#ye(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#we(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#w(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#L(o,this.#w(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#Ae(r);for(let{name:s,file:c,multiple:u}of r){let d=u||a.has(s)?`${this.#w(s)}[]`:this.#w(s);o.append(d,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#Ae(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#U(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Se(e){return fr(e)}#Ee(e){Qn(e,(t)=>this.#F(t),(t,n)=>this.#N(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#N(e,t){if(!this.#O())return;en(this,e,t)}#He(e){}#F(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#y(n))}#z(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#xe(e,t,n){this.#_e(e,t),os();let r=!1;return()=>{if(r)return;r=!0,this.#ke(e,t),is();for(let o of n.undo)o()}}#_e(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#p.set(e,(this.#p.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#K(e))this.#l(n,e,1)}#ke(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#p.get(e)??1)-1;if(n<=0)this.#p.delete(e);else this.#p.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#K(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#K(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#Te(){return this.#V??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Re(){if(this.#A!=null)return this.#A;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#A=Number.isFinite(t)&&t>0?t:30000}#Le(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Oe(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)Ri();else document.addEventListener("turbo:load",Ri,{once:!0});cr();var vl=gs;export{rs as ACTIVE_ATTR,bu as EDITOR_SELECTOR,vu as EDITOR_TAGS,nc as LATENCY_KEY,as as REQUESTS_ATTR,pu as checkReactiveRegistration,cs as countReactiveRequest,vl as default,mo as disableLatencySim,D as editableValue,po as enableLatencySim,os as enterReactiveActivity,du as escapeRegExp,is as exitReactiveActivity,cl as loadReactiveFeature,rl as onReactiveStreamWithoutEffects,ol as reactiveActivityCount,ul as reactiveFeatureNames,Ri as registerReactiveActions,zc as registerReactiveDefer,cr as registerReactiveDev,Vc as registerReactiveDismiss,Vc as registerReactiveEffects,Bu as registerReactiveFeature,sl as registerReactiveFeatureLoader,tu as registerReactiveImageFallback,Uc as registerReactiveJs,eu as registerReactiveKeep,Qc as registerReactiveModals,ru as registerReactiveMorphFocus,uu as registerReactiveOffline,nu as registerReactivePlaintext,Vc as registerReactiveStreamRender,Gc as registerReactiveToken,Hc as registerReactiveVisit,il as resetReactiveActivity,lr as serverText,al as unloadedFeaturesFor};
5
+ `).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Je=new WeakMap;function fr(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Je.has(e))Je.set(e,D(e))}function dr(e){return fr(e),Je.get(e)}function yu(e){return vu.has(e.localName)?typeof e.value==="string":!0}var Ni=Object.freeze({show:(e,t,n)=>Jn(e,!1,t,n),hide:(e,t,n)=>Jn(e,!0,t,n),toggle:(e,t,n)=>Jn(e,!e.hidden,t,n),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((n)=>e.classList.toggle(n)),set_attr:(e,t)=>{if(Hn(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Hn(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Hn(t.name))return;if(Array.isArray(t.values)){let[n,r]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===n?r:n)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>Tu(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Ki(e),close_dialog:(e)=>Xc(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}hs(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)ot(r,t.group,t.checked)},presence:(e,t)=>$n(e,t.state),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=wu(e);if(!r)return;let o=null;if(t?.submitter!=null&&typeof n==="function"){if(o=n({...t,to:t.submitter})[0]??null,!(o?.form===r&&(o.type==="submit"||o.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),o=null}o?r.requestSubmit?.(o):r.requestSubmit?.()},paste_into:(e)=>Au(e),preview_file:(e,t,n)=>Su(e,t,n),set_value:(e,t)=>ms(e,String(t.value??"")),persist_state:(e,t)=>Ct(e,t.state),persist_clear:(e)=>$t(e)});function wu(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Au(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ps(e),e.focus?.()}).catch(()=>{})}var oe=new Map,ie=null;function Su(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Bn(`reads an input[type=file], not <${e?.localName}>`);let r=typeof n==="function"?n({...t,to:t.into})[0]:null;if(r?.tagName!=="IMG")return Bn(`paints an <img>, and ${JSON.stringify(t.into)} is ${r?`a <${r.localName}>`:"not on the page"}`);let o=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],i=Eu(e,t.accept),a=o.filter((l)=>typeof l?.type==="string"&&i(l)),s=a.find((l)=>l.type.startsWith("image/")),c=o.length>0&&a.length===0?"type":null;if(s&&Number.isInteger(t.max_bytes)&&s.size>t.max_bytes)c="size";let u=c==="size"?s:o[0];if(c)s=null;if(ds(r),s){let l=URL.createObjectURL(s);oe.set(r,l),r.setAttribute("src",l),xu()}else r.removeAttribute("src");if(Ge(r),t.wrap!=null){let l=n({...t,to:t.wrap});if(l.length===0)Bn(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let d of l)s?Zi(d):Xi(d)}if(t.name!=null)for(let l of n({...t,to:t.name}))l.textContent=s?s.name:"";if(c)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:{reason:c,file:u}}))}function Eu(e,t){let n=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((r)=>r.trim()).filter(Boolean);if(n.length===0)return(r)=>r.type.startsWith("image/");return(r)=>{let o=r.type.toLowerCase();return n.some((i)=>i[0]==="."?String(r.name).toLowerCase().endsWith(i):i.endsWith("/*")?o.startsWith(i.slice(0,-1)):o===i)}}function Bn(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function ds(e){let t=oe.get(e);if(t===void 0)return;if(oe.delete(e),URL.revokeObjectURL(t),oe.size===0)ie?.disconnect(),ie=null}function xu(){if(ie||typeof MutationObserver!=="function"||!document?.documentElement)return;ie=new MutationObserver(()=>{for(let[e,t]of oe)if(!e.isConnected||e.getAttribute("src")!==t)ds(e)}),ie.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ps(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ms(e,t){if(!/^(input|textarea|select)$/.test(e.localName)||e.type==="file"&&t!==""){console.warn("[phlex-reactive] set_value skipped: not a field it can write",e);return}let n=Fi(e);if(e.value=t,Fi(e)!==n)ps(e)}function Fi(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
+ `):e.value}function _u(e,t,n){if(n?.transition)hu(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Jn(e,t,n,r){if(_u(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function Hn(e){if(!fs(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function hs(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Ge(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var ku='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Tu(e){return e.querySelectorAll?.(ku)?.[0]??null}function pr(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var Mi=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),Ci=Object.freeze(["meta","ctrl","alt","shift"]);function Ue(e,t,n){let r=e.split("+");for(let a of Ci)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Ci.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Mi,o)?Mi[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Ru=(e)=>e&&typeof e==="object"?e.keys:String(e),mr=()=>qe().prevented??=new WeakSet;function Gn(e,t){if(t!=null&&!e.defaultPrevented)mr().add(e);e.preventDefault()}function Me(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!mr().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Ue(Ru(e).replace(/^mod\+/,`${o}+`),t,n)}function Lu(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:pr(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function $i(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==hr(t.currentTarget))return!1;return o<0||n===null||Ue(r.slice(o+1),t,n)}function Ou(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((o)=>r[o]===n[o])}var Pi=new WeakMap;function Nu(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Pi.get(e);if(!o)o=new WeakMap,Pi.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var Ii=new WeakMap;function Fu(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=Ii.get(e);if(!o)o=new WeakMap,Ii.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function tr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Ni,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(Ni[o](s,i,t),i?.keep===!0)Vi(s,o,i,t)}}function Mu(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function Cu(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function nr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var Un='[data-controller~="reactive"]',$u='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',rr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!nr(e);function zn(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&rr(r))r=r.parentElement?.closest?.(t);return r??null}var Ce=new WeakMap,$e=new WeakMap;function Pu(e){return(e.getAttribute?.("data-action")??"").includes("reactive#trackDirty")||e.getAttribute?.("data-reactive-clipboard")!=null||e.querySelector?.('[data-action*="reactive#trackDirty"],[data-reactive-clipboard]')!=null}function Iu(e){return["show-targets","group-targets","on-complete","filter-input","tags-field","css-vars"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media], [data-reactive-css-vars]")!=null}function Du(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function qu(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Wu(e){return Boolean(e.matches?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]")||e.querySelector?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]"))}function Di(e){return e.getAttribute?.("data-reactive-presence")!=null}function ju(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function sl(e,t,n){}function Bu(e,t){}function al(e){return[]}function cl(e){return Promise.resolve()}var qi=new Set;function Ju(e,t,n){let r=e+t;if(qi.has(r))return;qi.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function ul(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Wi=Promise.resolve();var ji={enter:os,exit:is,count:cs,text:D,served:dr,waiting:new WeakMap},Bi=1,Kn=2,Vn=4,Yn=8,Xn=16,Ji=32,Hi=64,Gi=128,Ui=256;xt(ji),un(ji);var se=Symbol.for("phlex-reactive.early"),Hu=1e4,Gu=1500,hr=(e)=>e!=null&&(e===globalThis.window||e.window===e),Uu="dispatch";function qe(){return globalThis[se]??={queue:[],connected:new WeakSet},globalThis[se]}function zu(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Hu}function Ku(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function Vu(e,t,n){return{[se]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Ku(t),key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,button:e.button,submitter:e.submitter,bubbles:e.bubbles,timeStamp:e.timeStamp,defaultPrevented:e.defaultPrevented&&!mr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var He=new WeakMap;function Yu(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=He.get(e);if(!s)He.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function zi(e,t,n,r){if(e?.[se])return!1;let o=hr(e?.currentTarget),i=o?r:e?.currentTarget,a=Zu(e,i,o?`@${t}`:t),s=He.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Ue(u.filter,e,n))continue;return u.armed=!1,!0}return a}var We=new WeakMap;function Xu(e,t,n){let r=We.get(e);if(!r)We.set(e,r=new Map),setTimeout(()=>We.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Zu(e,t,n){let r=e&&We.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class gs extends Jc{static values={token:String};#h;#f=new Map;#d=new Map;#V;#A;#M;#S=0;#p=new Map;#E=new WeakMap;#r;featuresReady=Wi;#Ne=new Map;#Fe=new Set;#Y=!1;#C=null;#Me=new Map;#Ce=new Map;#$e=new Map;#X=0;#$;#x=0;#o=0;connect(){if(ls=!0,qe().connected.add(this.element),Ce.set(this.element,this),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||nr(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Pe)this.#I();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(Pe,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(fr),this.#X++,this.featuresReady=Wi,this.#P(),je(this.element),this.#Q()}#P(e){this.#t(Bi,"persist",Cu,(t)=>Ft(this,t,e)),this.#t(Kn,"defer",nr,(t)=>mn(this,t,e)),this.#t(Vn,"form",Pu,(t)=>It(this,t,e)),this.#t(Yn,"bindings",Iu,(t)=>Ye(this,t,e)),this.#t(Xn,"compute",Du,(t)=>gt(this,t,e)),this.#t(Ji,"sortable",qu,(t)=>wn(this,t)),this.#t(Ui,"drag",Wu,(t)=>Tn(this,t)),this.#t(Hi,"presence",Di,(t)=>Mn(this,t)),this.#t(Gi,"countdown",ju,(t)=>In(this,t))}#t(e,t,n,r){if(this.#x&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#x|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#D(t,"connect",o)}}#Z(){{let e=this.#o;this.#x=this.#o=0;let t=this.#e();if(e&Bi)this.#n("persist",()=>Mt(this,t));if(e&Kn)this.#n("defer",()=>hn(this,t));if(e&Vn)this.#n("form",()=>Dt(this,t));if(e&Yn)this.#n("bindings",()=>Xe(this,t));if(e&Xn)this.#n("compute",()=>bt(this,t));if(e&Ji)this.#n("sortable",()=>An(this,t));if(e&Ui)this.#n("drag",()=>Rn(this,t));if(e&Hi)this.#n("presence",()=>Cn(this,t));if(e&Gi)this.#n("countdown",()=>Dn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Pe(e){}#Ie(e,t){}#De(e){}#qe(e,t){}#We(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#h=void 0},owns:(e)=>this.#y(e),ownership:()=>this.#H(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>tr(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#G(),plain:ts,text:D,served:dr,copyMedia:hs,setValue:ms,confirm:(e,t)=>Promise.resolve().then(()=>yi(e,t)).catch(()=>!1)},this.#$}#I(){if(this.#o&Vn)qt(this);if(this.#o&Yn)Ze(this);if(this.#o&Xn)vt(this)}#D(e,t,n){if(Ju(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#je(){}#Q(){if(this.element.setAttribute?.("data-reactive-connected",""),this.element.isConnected)this.element.dispatchEvent?.(new CustomEvent("reactive:connect",{bubbles:!0,composed:!0,detail:{id:this.element.id}}));this.#ee();for(let[e,t]of $e.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}$e.delete(this.element)}#_=new Set;#ee(){let{queue:e}=qe();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=zu(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(Gu,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#te(o)}}#te({event:e,el:t,descs:n,win:r}){let o=Vu(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Ue(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Yu(s,c,r&&JSON.stringify(o.params)))continue;this.#_.add(s)}if(Xu(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Z(),this.#ue(),this.#fe(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(Pe,this.#r);if(qe().connected.delete(this.element),Ce.get(this.element)===this)Ce.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#_)He.delete(e);this.#_.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Ri&&this.#re())return this.#oe(e);let t=e.params?.shortcut;if(t!=null&&!Me(t,e,this.application?.schema?.keyMappings))return;if(zi(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l,prevent:d}=e.params;if(!n)return;let f=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((t!=null||!u&&d!==!1)&&!this.#z(l,m))Gn(e,t);if(n===Ri){let h=()=>{if(this.#o&Kn)return Ee(this);if(this.tokenValue)return this.#k(m,n,"{}")};return this.#Y?this.featuresReady.then(h):h()}let v=this.#q(a,s),b=()=>this.#k(m,n,r,o,i,l,f);if(!v)return b();if(v instanceof Promise)return v.then((h)=>h?this.#g(h,m,b):b());this.#g(v,m,b)}#g(e,t,n){return Promise.resolve().then(()=>yi(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return et(this,this.#e(),t)}#ne(e){}#re(){return!this.tokenValue&&rr(this.element)}#oe(e){let t=zn(this.element.parentElement,$u);if(!t){if(this.element.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] "${e.params.action}": no token on this root or above, nothing sent`);return}let n=Ce.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:a}=e.params;if(r!=null&&!Me(r,e,this.application?.schema?.keyMappings))return;let s=e.currentTarget??e.target;if((r!=null||!o&&a!==!1)&&!this.#z(i,s))Gn(e,r);$e.set(t,[...$e.get(t)??[],[e,s]]);let c=t.dataset;if(c.reactiveDormant)c.controller=`${c.controller??""} ${c.reactiveDormant}`.trim(),delete c.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Me(t.shortcut,e,this.application?.schema?.keyMappings))return;if(zi(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Fu(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Lu(n.ops),i=o.filter((s)=>$i(s,e,null)),a=i.length<=1?i:i.filter((s)=>$i(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())tn(this,e);return}for(let s of a){if(s.outside&&e[se])continue;if(!Ou(s,e))continue;if(s.shortcut!=null&&!Me(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(Nu(this,e,s))continue;this.#ie(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0,prevent:void 0}:s,e,r,o.indexOf(s))}}#ie(e,t,n,r){let{ops:o,confirm:i,confirmWhen:a,outside:s,window:c,shortcut:u,prevent:l}=e;if(s&&this.element.contains(t.target))return;if(u!=null||!c&&l!==!1)Gn(t,u);let d=this.#q(i,a),f=this.#se(e,r,n,()=>this.#Ee(this.#Se(o)));if(!d)return f();if(d instanceof Promise)return d.then((m)=>m?this.#g(m,n,f):f());this.#g(d,n,f)}#se(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let a=JSON.stringify([t,e]);if(o>0)return()=>this.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return yt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return ct(this,this.#e(),e)}tagsPick(e){return ut(this,this.#e(),e)}tagsRemove(e){return lt(this,this.#e(),e)}nestedAdd(e){return ft(this,this.#e(),e)}nestedRemove(e){return dt(this,this.#e(),e)}syncNestedJson(e){return Qe(this,this.#e(),e)}#Be(e,t){}trackDirty(){he(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#m(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#m(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#m(e);if(!n.length)return;e.preventDefault();let r=this.#ae(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ae(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#H();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#U(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ce(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#le(e,u,t,n,i,a);return this.#v(t,n,i,e,a)}#v(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#xe(e,r,i),s=Boolean(n||o),c=(f)=>{if(!s||!f)return;let m=this.#e();if(i.inverse=on(this,m,n,r),i.undo.push(...rn(this,m,o,r)),this.#R())i.resurrect=sn(this,m,n,r)},u=!0;c(!0);let l=()=>this.#he(e,t,i,a),d=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>d()),this.queue}#Je(){return this.#ne("hints")}#ce(e,t,n,r,o,i){this.#W(e,Uu,t,()=>this.#v(n,r,o,e,i))}#W(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!hr(e))e?.addEventListener?.("blur",o,{once:!0});let a=this.#f.get(e);if(!a)this.#f.set(e,a=new Map);a.set(t,{timer:i,flush:o})}#T(e,t){let n=this.#f.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#f.delete(e)}#ue(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#le(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#v(n,r,o,e,i))}#j(e,t,n,r){let o=this.#d.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#d.delete(e)},n);return o.set(t,i),this.#d.set(e,o),r()}#fe(){for(let e of this.#d.values())for(let t of e.values())clearTimeout(t);this.#d.clear()}#s(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#de(){this.element?.removeAttribute?.("data-reactive-error")}#pe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#me(){return Yt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#he(e,t,n,r){let{fields:o,files:i}=this.#G(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#we(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),d=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#me();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let f;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Le()};if(!u)h["Content-Type"]="application/json";let p=this.#Oe();if(p)h["X-Pgbus-Connection"]=p;let w=Di(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(w)h["X-Reactive-Presence"]=w;let A=su(this.element);if(A)h["X-Reactive-Held"]=A;cs("action"),f=await fetch(this.#Te(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Re())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#pe(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(d)d.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:f.status});return}if(!f.ok){let h=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,h),this.#u(n.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let p=this.#J(h);if(this.#c=p??this.#c,d)be(d,h,p);Ti(this.element,h,!0)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:f.status,body:h});return}let m=f.headers.get("Content-Type")||"";if(!m.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${m}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:f.status});return}let v=await f.text(),b=this.#J(v);if(this.#c=b??this.#c,d)be(d,v,b);if(Ti(this.element,v,au(f)),n.resurrect)queueMicrotask(n.resurrect);return this.#de(),this.#s("reactive:applied",{action:e,params:s,html:v}),v}catch(f){console.error("[phlex-reactive] action error",f),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),d)nn(this,{...d,ms:this.#B()-d.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ge(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#ge(e){let t=this.#M;if(t&&t.id===e)return t;let n=du(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#y(e){return e.closest('[data-controller~="reactive"]')===this.element}#H(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#be(){let e=this.element.querySelectorAll(Un);if(e.length===0||[...e].every(rr))return()=>!0;return(t)=>{let n=zn(t,Un,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&zn(n.parentElement,Un,this.element)===this.element}}#G(){let e={},t=[],n=this.#be(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${bu}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#ve(r),a=this.#ye(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?D(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!yu(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#ve(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#ye(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#we(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#w(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#L(o,this.#w(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#Ae(r);for(let{name:s,file:c,multiple:u}of r){let d=u||a.has(s)?`${this.#w(s)}[]`:this.#w(s);o.append(d,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#Ae(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#U(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Se(e){return pr(e)}#Ee(e){tr(e,(t)=>this.#F(t),(t,n)=>this.#N(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#N(e,t){if(!this.#O())return;en(this,e,t)}#He(e){}#F(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#y(n))}#z(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#xe(e,t,n){this.#_e(e,t),os();let r=!1;return()=>{if(r)return;r=!0,this.#ke(e,t),is();for(let o of n.undo)o()}}#_e(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#p.set(e,(this.#p.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#K(e))this.#l(n,e,1)}#ke(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#p.get(e)??1)-1;if(n<=0)this.#p.delete(e);else this.#p.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#K(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#K(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#Te(){return this.#V??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Re(){if(this.#A!=null)return this.#A;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#A=Number.isFinite(t)&&t>0?t:30000}#Le(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Oe(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)Oi();else document.addEventListener("turbo:load",Oi,{once:!0});lr();var vl=gs;export{rs as ACTIVE_ATTR,bu as EDITOR_SELECTOR,vu as EDITOR_TAGS,nc as LATENCY_KEY,as as REQUESTS_ATTR,pu as checkReactiveRegistration,cs as countReactiveRequest,vl as default,go as disableLatencySim,D as editableValue,ho as enableLatencySim,os as enterReactiveActivity,du as escapeRegExp,is as exitReactiveActivity,cl as loadReactiveFeature,rl as onReactiveStreamWithoutEffects,ol as reactiveActivityCount,ul as reactiveFeatureNames,Oi as registerReactiveActions,zc as registerReactiveDefer,lr as registerReactiveDev,Vc as registerReactiveDismiss,Vc as registerReactiveEffects,Bu as registerReactiveFeature,sl as registerReactiveFeatureLoader,tu as registerReactiveImageFallback,Uc as registerReactiveJs,eu as registerReactiveKeep,Qc as registerReactiveModals,ru as registerReactiveMorphFocus,uu as registerReactiveOffline,nu as registerReactivePlaintext,Vc as registerReactiveStreamRender,Gc as registerReactiveToken,Hc as registerReactiveVisit,il as resetReactiveActivity,dr as serverText,al as unloadedFeaturesFor};
7
7
 
8
- //# debugId=7BDC87F3B501212664756E2164756E21
8
+ //# debugId=C06054A8CA230C4464756E2164756E21
9
9
  //# sourceMappingURL=reactive_controller.min.js.map