phlex-reactive 0.19.3 → 0.19.4

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 zu}from"@hotwired/stimulus";import{confirmResolver as rs}from"phlex/reactive/confirm";import{confirmPredicate as ma}from"phlex/reactive/confirm_predicate";var G=new WeakMap,ft=new WeakMap;function M(e,t){let n=G.get(e);if(!n){if(G.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)ft.set(n.root,n)}return n}function _(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function te(e,t){_(e,"turbo:morph-element",t),e.seeds.push(t),t()}function dt(e,t){let n=M(e,t);n.offs=[],n.seeds=[];let r,o,i,s,a;(n.wire=()=>{if(!n.show&&wa(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")$a(n,c.target);else n.groups=Ca(n),Ur(n);Jr(n)},_(n,"input change",n.show),_(n,"focusout",(c)=>{let u=c.target?.getAttribute?.("name");if(!u||n.touched?.has(u)||!n.core.bindingOwns(c.target))return;if((n.touched??=new Set).add(u),n.root.querySelector?.("[data-reactive-show-after]"))Jr(n)}),te(n,n.show);if(!n.arm&&Aa(n))_(n,"input change",(c)=>Br(n,c)),te(n,n.arm=()=>{Br(n,null),Ur(n)});if(!r&&(r=n.show||n.arm))_(n,"reset",()=>setTimeout(()=>{if(G.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))_(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!ha(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=Ae(n)))_(n,"input",(c)=>Da(n,c)&&ne(n)),te(n,()=>ne(n));if(!s&&(s=Ee(n)))te(n,()=>io(n));if(!a&&(a=ja(n)))_(n,"input change",(c)=>uo(n,c)),te(n,()=>Et(n))})(),_(n,"keydown",(c)=>rc(n,c)),_(n,"paste drop",(c)=>oc(n,c)),_(n,"input",(c)=>ic(n,c))}function ha(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function pt(e){let t=G.get(e);if(!t)return;G.delete(e),ft.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function mt(e){let t=G.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function q(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ht(e,t,n){return uo(M(e,t),n)}function gt(e,t,n){return ho(M(e,t),n)}var ga=/^#[A-Za-z_][\w-]*$/,Vr="[data-reactive-show-field], [data-reactive-show]";function ba(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 lo){let s=e.getAttribute(`data-reactive-show-${i}`);if(s!==null)return po(i,s,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Yr(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 va(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 Xr(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 re(n,t);return ya(e,t)}function ya(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)=>Ot(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function we(e,t="show"){if(typeof e==="string"&&ga.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function wa(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?.(Vr)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(Se)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${eo}, ${to}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Aa(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Sa(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:va(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Br(e,t){let n=Sa(e);if(!n.length)return;let r=Qr(e,e.core.bindingOwnership());n.forEach((o,i)=>{let s=re(o.any,r);if(s===null)return;let a=s&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=s,a)e.core.applyOps(o.ops,"@root")})}function Jr(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.core.bindingOwnership(),r=e.root.getAttribute?.("data-reactive-scope")||null,o=Qr(e,n),i=[];for(let s of e.root.querySelectorAll(Vr)){if(!t(s))continue;let a=s.getAttribute("data-reactive-show");if(a!==null){let f=Xr(Yr(a),o);if(f===null)continue;let d=s.getAttribute("data-reactive-show-after"),p=f&&(d==null||!!e.touched?.has(vt(d,r)));Hr(s,p,n);let h=(e.shown??=new WeakMap).get(s);if(e.shown.set(s,p),Ea.some((v)=>s.hasAttribute(`data-reactive-show-${v}`))&&h!==void 0&&h!==p)i.push(s);continue}let c=s.getAttribute("data-reactive-show-field");if(!c)continue;let u=o(c);if(u===null)continue;let l=ba(s,u);if(l===null)continue;Hr(s,l,n)}if(e.groups)Pa(e,o,t,r);Ra(e,o,t),Na(e,o,t,r,n),_a(e,o),Ia(e,o);for(let s of i)xa(e,s,n,r)}var Ea=["clear","focus","scroll"];function xa(e,t,n,r){if(t.hidden){let a=[];try{a=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(a)?a:[]).map((u)=>vt(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,q(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"),s=null;try{s=i?e.root.querySelector(i):null}catch{}s?.focus?.(o?{preventScroll:!0}:void 0)}function Hr(e,t,n){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let r of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(r))r.disabled=!t;if(e.name&&n(e))e.disabled=!t}function _a(e,t){let n=Zr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){ka(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let s=(a,c)=>c?t(r,!0):i;for(let[a,c]of Object.entries(o)){if(!we(a))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${a} — skipped`);continue}u=c.every((l)=>Ot(l,s))}else{let l=mo(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${a} — skipped`);continue}u=l}for(let l of document.querySelectorAll(a))l.hidden=!u}}}function ka(e,t,n){if(!we(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=tc(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((s)=>n(s)===null)&&!nc(r))return;let i=re(r,n);if(i===null)return;for(let s of document.querySelectorAll(e))s.hidden=!i}function Zr(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 Ta(e,t,n,r){let o=!1,i=null;for(let s of e.root.querySelectorAll(bt(t,r))){if(!n(s))continue;if(s.type==="checkbox")return s.checked?"true":"false";if(s.type==="radio"){if(s.checked)return s.value??"";o=!0;continue}i??=s}if(i)return i.value??"";return o?"":null}function bt(e,t){return`[name="${vt(e,t)}"]`}function vt(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Qr(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let s=i?`#${o}`:o;if(!r.has(s))r.set(s,i?yt(e,o,t,n).filter((a)=>a.checked).length:Ta(e,o,t,n));return r.get(s)}}var eo="[data-reactive-media]";function Ra(e,t,n){for(let r of e.root.querySelectorAll(eo)){if(!n(r))continue;let o,i,s;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)s=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!s){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let a=t(o.field);if(a===null)continue;let c=o.take>0?[...a]:null,u=c?c.slice(0,o.take).join(""):a,l=c?.length<o.take||i?.test(u)===!1||s?.test(a)===!1;if(l&&o.pending==="keep"){Gr(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?zr(e,o.pool[u])[0]:null,d=e.core.copyMedia(r,f??null);if(d===null)continue;if(Gr(r,l?"pending":d===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":d===!1?String(o.blank??""):d;for(let h of zr(e,o.label))if(h.textContent!==p)h.textContent=p}}function Gr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function zr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var to="[data-reactive-css-vars]",Oa=/^--[a-z0-9-]+$/i,La=["","px","%","deg","turn","ms","s","em","rem","fr"];function Na(e,t,n,r,o){let i=[...e.root.querySelectorAll(to)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))i.unshift(e.root);for(let s of i){let a;try{a=JSON.parse(s.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 c=a.to.flatMap((u)=>{let l={to:u,global:a.global===!0},f=[];try{f=e.core.opTargets(l)}catch{}if(!f.length)e.core.diagnose("reactive_css_vars",l);return f});for(let[u,l]of Object.entries(a.vars)){let f=l?.unit??"";if(!Oa.test(u)||!La.includes(f)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let d=Fa(e,t,l.field,o,r);if(d===void 0)continue;let p=d===null?"":`${d}${f}`;for(let h of c){if(h.style.getPropertyValue(u)===p)continue;if(p)h.style.setProperty(u,p);else h.style.removeProperty(u)}}}}function Fa(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(bt(n,o))].some((a)=>r(a)&&a.type==="checkbox"))return i==="true"?1:0;let s=i.trim()?Number(i):NaN;return Number.isFinite(s)?s:null}var Se="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Ca(e){return!!e.root.querySelector?.(Se)}function yt(e,t,n,r,o){return[...e.root.querySelectorAll(bt(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Ma(i.getAttribute("data-reactive-group"),o)))}function Ma(e,t){return e===t||!!e?.startsWith(`${t}.`)}function $a(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))no(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function wt(e,t,n){if(!t)return;let r=ft.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};no(r,t,n!==!1),r.show?.()}function no(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,s=yt(e,t,e.core.ownership(),i,o).filter((a)=>a!==r&&a.checked!==n);for(let a of s)a.checked=n;e.flipping=!0;try{for(let a of s)for(let c of["input","change"])a.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function Pa(e,t,n,r){for(let o of e.root.querySelectorAll(Se)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Xr(Yr(i),t);if(c!==null)o.disabled=!c}let s=o.getAttribute("data-reactive-count");if(s){let c=String(t(s,!0));if(o.textContent!==c)o.textContent=c}let a=o.getAttribute("data-reactive-select-all");if(a){let c=o.getAttribute("data-reactive-select-all-under"),u=yt(e,a,n,r,c).filter((f)=>f!==o),l=u.filter((f)=>f.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function Ia(e,t){for(let[n,r]of Object.entries(Zr(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let s of Array.isArray(r.count)?r.count:[]){if(!we(s,"group"))continue;for(let a of document.querySelectorAll(s))if(a.textContent!==o)a.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[s,a]of Object.entries(i)){if(!we(s,"group"))continue;let c=re(a?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${s} — skipped`);continue}for(let u of document.querySelectorAll(s))u.disabled=!c}}}function Ur(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?.(`${Se}, [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 Ae(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Da(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var qa=/[\s\-'(),./]/;function Wa(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||qa.test(t[r-1]))return!0;return!1}function ne(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"),s=e.root.hasAttribute?.("data-reactive-filter-fold"),a=(d)=>{let p=(d??"").toLowerCase().trim();return s?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=a(o.value),u=0;for(let d of e.root.querySelectorAll(n)){if(!r(d))continue;let p=d.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Wa(i,a(d.getAttribute("data-reactive-filter-text")??d.textContent),c);if(d.hidden=p,p)d.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let d of e.root.querySelectorAll(l)){if(!r(d))continue;let p=[...d.querySelectorAll(n)].filter(r);if(p.length===0)continue;d.hidden=p.every((h)=>h.hidden)}let f=e.root.getAttribute("data-reactive-filter-empty");if(f){for(let d of e.root.querySelectorAll(f))if(r(d))d.hidden=u>0}}function Ee(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function ja(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function At(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 ro(e,t){let n=At(e);if(!n)return!1;let r=St(n),o=new Set(r.map((s)=>s.toLowerCase())),i=!1;for(let s of t){let a=String(s??"").trim();if(a===""||o.has(a.toLowerCase()))continue;o.add(a.toLowerCase()),r.push(a),i=!0}if(i)oo(e,n,r);return i}function oo(e,t,n){t.value=n.join(","),q(t),io(e)}function Ba(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 io(e){let t=At(e);if(!t)return;let n=St(t),r=e.core.ownership();Ja(e,n,r),Ha(e,n,r)}function Ja(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 s of t){let a=i.cloneNode(!0);a.setAttribute?.("data-reactive-tag",s);let c=a.matches?.("[data-reactive-tag-text]")?a:(a.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=s;let u=[...a.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(a.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(a);for(let l of u)l.setAttribute?.("data-reactive-tag-param",s);r.appendChild(a)}}function Ha(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"),!Ae(e))o.hidden=!1}}if(Ae(e))ne(e)}function Ga(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function za(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 Ua(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 Ka(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(),s=[...t.querySelectorAll?.("input, select, textarea")??[]],a=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let f=s.find((d)=>ao(d.getAttribute?.("name"))===c);if(!f)continue;if(Va(f,l),!a.includes(l))a.push(l)}if(r)for(let c of a)Ya(c,r);return a[0]??null}function Va(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:ut(t)!=="";else e.value=ut(t);q(e)}function Ya(e,t){let n=t==="reset";if(e.type==="checkbox"||n&&e.type==="radio")e.checked=n&&!!e.defaultChecked;else if(n&&e.options){let r=Array.from(e.options),o=!e.multiple&&!(e.size>1),i=r.filter((s)=>s.defaultSelected).pop()??r.find((s)=>!s.closest?.("optgroup")?.disabled&&!s.disabled);for(let s of r)s.selected=o?s===i:!!s.defaultSelected}else e.value=n?e.defaultValue??"":"";q(e)}function Xa(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Kr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",q(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);Et(e)}function Et(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))co(e,n.getAttribute("data-reactive-nested-json"))}function Za(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 so(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=ao(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=ut(o)}return n}function ao(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function ut(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function co(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Za(e,r);if(!o)return;let i=[];for(let a of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(a)||a.hidden)continue;i.push(so(e,a))}let s=JSON.stringify(i);if(o.value===s)return;o.value=s,q(o)}function xt(e,t,n){let r=M(e,t);if(!Ee(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((s)=>s.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!ro(r,String(o.value??"").split(",")))return;if(o.value="",Ae(r))ne(r)}function _t(e,t,n){let r=M(e,t);if(!Ee(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!ro(r,[i]))return;let s=Ba(r);if(!s)return;s.value="",ne(r),s.focus?.()}function kt(e,t,n){let r=M(e,t);if(!Ee(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let s=At(r);if(!s)return;let a=St(s),c=a.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===a.length)return;oo(r,s,c)}function Tt(e,t,n){let r=M(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 s=r.core.ownership(),a=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(s),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(s)?.content?.firstElementChild;if(!a||!u){Ua(r,i);return}let l=u.cloneNode(!0);za(l,Ga(r)),a.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param"),h=Ka(r,l,f,d==="true"||d==="reset"?d:null);if(f)h?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(a.getAttribute?.("data-reactive-nested-json")===i)co(r,i)}function Rt(e,t,n){let r=M(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 s=o?.getAttribute?.("data-reactive-confirm-param"),a=o?.getAttribute?.("data-reactive-confirm-when-param"),c=s||(a?ho(r,a):null);if(!c)return Kr(r,i);let u=so(r,i),l=Xa(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Kr(r,i)})}function uo(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Et(e)}var lo=["gte","gt","lte","lt"],Qa=["len_eq","len_gte","len_gt","len_lte","len_lt"],fo=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],ec=["digits_eq","digits_gte","digits_lt","digits_lte"];function lt(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 po(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 mo(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 lo)if(n in e)return po(n,e[n],t);for(let n of Qa)if(n in e)return lt(n,e[n],[...String(t??"")].length);return null}function Ot(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=fo.find((i)=>(i in e));if(n){let i=t(e.field,!0);return lt(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(s)=>{let a=String(t(s)??"");return e.fold===!0?a.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):a};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=ec.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((a)=>Number.isInteger(e[a]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((a)=>lt(a,e[a],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return mo(e,o)===!0}function re(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Ot(r,t)))}function tc(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 nc(e){return e.flat().every((t)=>fo.some((n)=>(n in Object(t))))}function ho(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=(s)=>r[s],i;if(typeof n.predicate==="string"){let s=ma(n.predicate);if(!s)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!s(r)}else i=re(n.groups?.any,o)===!0;return i?n.message:null}function Lt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function rc(e,t){let n=Lt(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),q(n),n.blur()}function oc(e,t){let n=Lt(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 ic(e,t){let n=Lt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as sc}from"phlex/reactive/compute";var ie=new WeakMap;function wo(e,t){let n=ie.get(e);if(!n)ie.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Nt(e,t,n,r){let o=wo(e,t),i=Ac(o);if(i){o.seed=()=>xe(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(s)=>s.target!==o.root&&[...s.target.querySelectorAll(bo)].some(o.core.bindingOwns)&&o.seed();for(let s of Ao)o.root.addEventListener?.(s,o.nested)}if(o.share=(s)=>s.target?.matches?.(bo)&&!o.core.owns(s.target)&&o.core.bindingOwns(s.target)&&xe(o,s),o.root.addEventListener?.("input",o.share),i||r?.edited)xe(o)}function Ft(e){let t=ie.get(e);if(!t)return;if(ie.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of Ao)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function Ct(e){ie.get(e)?.seed?.()}function Mt(e,t,n){return xe(wo(e,t),n)}var bo="[data-reactive-shared-field]",Ao=["reactive:connect","reactive:persist-restored"],ac=Object.freeze({el:null,kind:""}),cc=/^#[A-Za-z_][\w-]*$/;function oe({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 So(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function uc(e,t){if(t==="string")return oe(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):So(oe(e));if(n)return e.el.checked?1:0;let r=Number(oe(e));return Number.isFinite(r)?r:0}function lc(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let s=So(i);if(Boolean(n.checked)===s)return null;return n.checked=s,n}if(r==="radio")return fc(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function fc(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let s=i.value===r;if(Boolean(i.checked)===s)continue;if(i.checked=s,s)o=i;else o??=i}return o}function dc(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 pc(e){if(typeof e==="string"&&cc.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function mc(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 hc(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 gc(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 bc(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=vc(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function vc(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function vo(e,t,n){let r=String(n);for(let o of yc(e,t)){if(o.textContent===r)continue;o.textContent=r}}function yc(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function yo(e,t,n){let r=wc(e);for(let[o,i]of Object.entries(r)){let s=o in t?null:n(o),a=o in t?t[o]:s.el?oe(s):void 0;if(a===void 0||a===null)continue;let c=String(a);for(let u of Array.isArray(i)?i:[i]){if(!pc(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function wc(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 Ac(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function xe(e,t){if(t&&e.ours.has(t))return;let n=gc(e),r=n.map(([v])=>v),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(v)=>o&&!v.includes("[")?`${o}[${v}]`:v,s=e.core.bindingOwnership(),a=new Map,c=(v)=>{let m=a.get(v);if(m)return m;let w=null,A=null,x=null;for(let T of e.root.querySelectorAll(`[name="${i(v)}"]`)){if(!s(T))continue;let ye=T.type;if(ye==="checkbox"||ye==="radio"&&T.checked){x={el:T,kind:ye};break}if(ye==="radio")w??=T;else A??=T}if(!x)if(w)x={el:w,kind:"radio"};else x=A?{el:A,kind:""}:ac;return a.set(v,x),x};for(let v of r)vo(e,v,oe(c(v)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?sc(u):null;if(!l){yo(e,{},c);return}let f=hc(e,"data-reactive-compute-outputs-param"),d={};for(let[v,m]of n)d[v]=uc(c(v),m);let p=l(d,{changed:bc(e,t,r,o)})||{},h=dc(p.$ops),b=[];for(let v of f){if(v==="$ops"||!(v in p))continue;let m=c(v);if(!m.el)continue;let w=lc(e.root,s,m,i(v),p[v]);if(w)b.push(w)}for(let v of Object.keys(p)){if(v==="$ops")continue;let m=p[v];if(m===void 0||m===null)continue;vo(e,v,m)}yo(e,p,c);for(let v of b){let m=new Event("input",{bubbles:!0});e.ours.add(m),v.dispatchEvent(m)}mc(e,h,Boolean(t))}var Dt;function qt(e){Dt=e}var To=1,Sc="phlex-reactive:persist:",Ec=new Set(["hidden","file","password","submit","button","reset","image"]),Wt=Symbol("persist-no-value"),jt="data-reactive-persist-state",xc=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",_c=new Set(["lexxy-editor","trix-editor"]),kc="lexxy-editor, trix-editor, trix-toolbar",Tc=["lexxy:change","trix-change"],Rc=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),xo=new WeakSet,_o=new WeakSet,ko=new WeakSet;function ke(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(!xo.has(e))xo.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Bt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Jt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||_o.has(e))return;_o.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Ht(e){return Sc+e.key}function Pt(e,t){let n=Bt(t);if(!n)return null;let r;try{r=n.getItem(Ht(t))}catch(c){return Jt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==To)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return _e(e,t),null;let s=o.fields&&typeof o.fields==="object"?o.fields:{},a=o.state&&typeof o.state==="object"?o.state:null;return{fields:s,state:a}}function Ro(e,t,{fields:n,state:r}){let o=Bt(t);if(!o)return!1;let i={v:To,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Ht(t),JSON.stringify(i)),!0}catch(s){return Jt(e,s),!1}}function _e(e,t){e?.removeAttribute?.(jt);let n=Bt(t);if(!n)return;try{n.removeItem(Ht(t))}catch(r){Jt(e,r)}}function Gt(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)||Ec.has(i.type)||i.closest(kc))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(xc)){if(!o(i))continue;let s=Oc(i);if(!s||n&&!n.has(s))continue;r.push({el:i,name:s,kind:_c.has(i.localName)?"editor":"contenteditable"})}return r}function Oo(e){return e.hasAttribute("data-reactive-editable")?Dt.text(e):e.textContent??""}function Oc(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function zt(e){return typeof e.value==="string"}function Lc(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Rc.has(e.value.trim())}function Nc(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||ko.has(e))return;ko.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function se(e){return e.tagName==="SELECT"&&e.multiple}function Lo(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 Wt;return e[0]}function Fo(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:s}of Gt(e,t)){let a=String(i).endsWith("[]");if(s==="editor"){if(zt(o))if(a)r(i).push(o.value);else n[i]=o.value}else if(s==="contenteditable"){let c=Oo(o);if(a)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(a){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(se(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(a)r(i).push(...c);else n[i]=c}else if(a)r(i).push(o.value);else n[i]=o.value}return n}function Fc(e,t,n){let r=t.restore==="always",o=Gt(e,t),i=Lo(o),s=new Set;for(let a of o)if(a.kind==="native"&&a.el.type==="checkbox"&&a.el.checked)s.add(a.name);for(let{el:a,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)&&se(a)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(a.type==="checkbox"||se(a))){if(l=No(l,c,i),l===Wt)continue}if((a.type==="checkbox"||se(a))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Co(e,a,c,l,r);else if(u==="contenteditable"){if(!r&&Oo(a).trim()!=="")continue;a.textContent=String(l)}else if(a.type==="radio"){if(!r&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;a.checked=a.value===String(l)}else if(a.type==="checkbox"&&Array.isArray(l)){if(!r&&s.has(c))continue;a.checked=l.map(String).includes(a.value)}else if(a.type==="checkbox"){if(!r&&a.checked)continue;a.checked=Boolean(l)}else if(se(a)){if(!r&&[...a.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of a.options)d.selected=f.has(d.value)}else{if(!r&&a.value!=="")continue;a.value=String(l)}}Cc(e,t,n)}function Co(e,t,n,r,o){if(Array.isArray(r))return;if(!zt(t))return;if(!o&&!Lc(t))return;try{t.value=String(r)}catch(i){Nc(e,n,i)}}function Cc(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let s of e.querySelectorAll("lexxy-editor, trix-editor"))if(!zt(s)&&!r.get?.(s.localName))o.add(s.localName);let i=t.restore==="always";for(let s of o)r.whenDefined(s).then(()=>{if(!e.isConnected)return;let a=Gt(e,t),c=Lo(a);for(let{el:u,name:l,kind:f}of a){if(f!=="editor"||u.localName!==s||!Object.hasOwn(n,l))continue;let d=No(n[l],l,c);if(d===null||d===void 0||d===Wt)continue;Co(e,u,l,d,i)}})}function Mc(e,t,n=!0){let r=ke(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=Pt(e,r),i={...o?.state??{},...t},s=n?Fo(e,r):o?.fields??{};if(Ro(e,r,{fields:s,state:i}))e.setAttribute?.(jt,JSON.stringify(i))}function $c(e){let t=ke(e);if(t)_e(e,t)}var It=new WeakMap,$t=new WeakMap;function Pc(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=$t.get(e);if(!n){let i=new Set,s=(a)=>{for(let c of i)c(a)};e.addEventListener("turbo:submit-end",s),n=[i,s],$t.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),$t.delete(e)}}function Ut(e,t,n,r){let o=e.element,i=ke(o);if(!i)return;if(r?.submitted)_e(o,i);let s=Pt(o,i);if(s){if(Fc(o,i,s.fields),s.state)o.setAttribute?.(jt,JSON.stringify(s.state));t.emit("reactive:persist-restored",{key:i.key,fields:s.fields,state:s.state??{}}),t.reseed()}let a=null,c=()=>{if(a!==null)clearTimeout(a),a=null},u=()=>{c();let h=Pt(o,i);Ro(o,i,{fields:Fo(o,i),state:h?.state??null})},l=()=>{let h=Number(i.debounce)||0;if(h<=0)return u();if(a!==null)clearTimeout(a);a=setTimeout(()=>{a=null,u()},h)},f=(h)=>{if(!h?.detail?.success)return;let b=h.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),_e(o,i)},d=["input",...Tc];for(let h of d)o.addEventListener?.(h,l);o.addEventListener?.("change",u);let p=Pc(globalThis.document,f);if(It.set(e,()=>{if(a!==null)u();for(let h of d)o.removeEventListener?.(h,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let h of r?.ops??[])h(!0)}function Kt(e){let t=It.get(e);It.delete(e),t?.()}function Mo(e,t){let n=Dt?.waiting.get(e)?.persist;if(!n||!ke(e))return t(!0);(n.ops??=[]).push(t)}function Vt(e,t){Mo(e,(n)=>Mc(e,t,n))}function Yt(e){Mo(e,()=>$c(e))}var Te=new WeakMap,Po=new WeakSet,Xt=new WeakMap;function Zt(e,t){let n=e.element,r=[],o=[],i=(u,l,f)=>{u.addEventListener?.(l,f),r.push(()=>u.removeEventListener?.(l,f))},s,a,c=()=>{if(!s&&(s=Ic(n,t))){let u=()=>Re(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Wc(n,r)}if(!a&&(a=jc(n,t))){let u=()=>Bc(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};Te.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Qt(e){for(let t of Te.get(e)?.[0]??[])t();Te.delete(e)}function en(e){Te.get(e)?.[1]()}function Ic(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 Re(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,s)=>{if(s)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,Dc(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 Dc(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 qc(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Wc(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Xt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(qc(c)>0)return c;return null},s=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},a=(c)=>{if(Po.has(c)||!i())return;if(Po.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",s),n.addEventListener("turbo:before-visit",a),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",s),n.removeEventListener?.("turbo:before-visit",a),Xt.delete(n)}},Xt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function jc(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 Bc(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 on(e){Jc(e),Gc(e)}function Jc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(tn);else setTimeout(tn,0);return}let r=async(o)=>{await n(o),tn()};r.__reactiveDismissWrapped=!0,t.render=r}function tn(){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 Hc=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),nn=Object.freeze(["fade","slide","scale","highlight","shake"]),rn="data-reactive-fx-pending",sn=1000;function Gc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Hc[r?.getAttribute?.("action")];if(!o||Kc())return;let i=zc(r,o);if(!i)return;let s=o==="exit"?async(a)=>{await Xc(Oe(r),i),await n(a)}:async(a)=>{let c=o==="enter"?Vc(r):null;if(await n(a),o==="enter")Yc(c,i);else qo(Oe(r),i)};s.__reactiveEffectsWrapped=!0,t.render=s}function zc(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return Do(n,t);let o=(t==="enter"?Uc(e):Oe(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Do(o,t):null}function Oe(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Uc(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Do(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"?nn[Math.floor(Math.random()*nn.length)]:e;if(!nn.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Kc(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Vc(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(rn,"");return Oe(e)}function Yc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${rn}]`)))n.removeAttribute(rn),qo(n,t)}async function Xc(e,t){if(!e?.classList)return;if(t.legs){await Wo(e,t.legs);return}e.classList.add(t.className);let n=an(e);if(n<=0){e.classList.remove(t.className);return}await cn(e,n),e.classList.remove(t.className)}function qo(e,t){if(!e?.classList)return;if(t.legs){Wo(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=an(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;cn(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Wo(e,t){let[n,r,o]=t.map(Zc),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Qc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let s=an(e);if(s>0)await cn(e,s);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Zc(e){return String(e??"").split(/\s+/).filter(Boolean)}function an(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((s,a)=>Math.max(s,parseFloat(a)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,sn)}catch{return 0}}function cn(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,sn))})}function Qc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},sn),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var eu="phlex-reactive:latency",un=!1;function Jo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Ho(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),un=!1}function fn(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Jo,disableLatencySim:Ho}}function dn(){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(!un)un=!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 Bo=new WeakMap;function pn(e){let t=globalThis.document;if(!t)return!0;let n=Bo.get(t);if(!n)n=new Set,Bo.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function ln(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function tu(e,t){try{return e?.matches?.(t)===!0}catch{return!1}}function Go(e,t,n,r){if(pn(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function mn(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o=r==="@trigger"?" — a server-pushed op has no trigger element":"";if(!o&&n&&!t.global){let i=ln(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}Go(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function hn(e){if(!pn(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function gn(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i=o==="@trigger"?" — this run has no trigger element":"";if(!i&&!n.global)if(tu(r,o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(ln(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let s=ln(globalThis.document,o);if(s>0)i=` — it matches ${s} element(s) outside this scope; use global: true`}Go(t,o,`scoped to #${r?.id||"?"}`,i)}function bn(e,t){let n=e.element?.id||"?";if(pn(`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 nu(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]??"?",s=o.match(/\btarget="([^"]*)"/)?.[1];t.push(s?`${i} → #${s}`:i)}return t}function vn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,a=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(a),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 Le(e,t,n){e.streams=nu(t),e.tokenRefreshed=n!=null}var Ne=new WeakMap;function yn(e,t,n,r){let o=n&&typeof n==="object"?iu(n):n;return o?Uo(t,o,r,!1):[]}function wn(e,t,n,r){if(!n)return null;let o=Uo(t,n,r,!0);return o.length?o:null}function Uo(e,t,n,r){let o=[];for(let i of Ko(e,t,n)){if(t.add_class){let s=t.add_class.filter((a)=>!i.classList.contains(a));if(i.classList.add(...s),s.length)o.push(()=>i.classList.remove(...s))}if(t.remove_class){let s=t.remove_class.filter((a)=>i.classList.contains(a));if(i.classList.remove(...s),s.length)o.push(()=>i.classList.add(...s))}if(t.toggle_class)t.toggle_class.forEach((s)=>i.classList.toggle(s)),o.push(()=>t.toggle_class.forEach((s)=>i.classList.toggle(s)));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(ru(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Ko(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 ru(e,t){let n=Ne.get(t);if(n)n.count++;else Ne.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()=>ou(t,e)}function ou(e,t){let n=Ne.get(e);if(!n)return;if(--n.count>0)return;if(Ne.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function iu(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function An(e,t,n,r){if(!n?.hide)return null;let o=Ko(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((s)=>s.isConnected&&!s.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 z;function xn(e){z=e}var L=new Map;function Zo(e,t){let n=!L.has(e);if(L.set(e,t),n)z.enter()}function Me(e){if(L.delete(e))z.exit()}var Yo=!1;function _n(e){Qo();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){fu(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;ce(t,n)}function Qo(){if(Yo||typeof document>"u"||!document.addEventListener)return;Yo=!0,document.addEventListener("turbo:before-stream-render",pu,!0),document.addEventListener("turbo:before-stream-render",su)}function su(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(L.get(n)?.via==="stream")Me(n)}function ce(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}Tn(e),ri(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Zo(e,r),du(e,r,t)}function au(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[hu(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":gu()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function ei(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(ti(t))return{src:t};return console.error(cu(t)),uu(t)||lu(e)}function cu(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${kn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function uu(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${kn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&ti(r))return{src:r,fallback:!0}}function lu(e){z.fail({kind:"defer",root:e.id}),Tn(e.id),Rn(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 ti(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${kn()}/`)}catch{return!1}}function kn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function fu(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){ce(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}Tn(e),ri(n);let o=document.createElement("pgbus-stream-source");o.id=ni(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Zo(e,{via:"stream"})}function ni(e){return`reactive-defer-src-${e}`}async function du(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},bu()),o;try{z.count("defer"),o=await fetch(...au(n,t.abort.signal))}catch(a){if(clearTimeout(r),L.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",a),ae(e,n);return}if(L.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),ae(e,n,o.status);return}if(o.status===204){clearTimeout(r),Xo(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),ae(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}"`),ae(e,n,o.status);return}let s;try{s=await o.text()}catch(a){if(clearTimeout(r),L.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",a),ae(e,n);return}if(clearTimeout(r),L.get(e)!==t)return;Xo(e),mu(s)}var En=null,pu=(e)=>En?.push(e);function mu(e){let t=En=[];try{window.Turbo.renderStreamMessage(e)}finally{En=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 Tn(e){let t=L.get(e);if(!t)return;if(Me(e),t.via==="fetch")t.abort.abort();else document.getElementById(ni(e))?.remove?.()}function ri(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Rn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Xo(e){Me(e);let t=document.getElementById(e);if(!t)return;Rn(t),t.removeAttribute("data-reactive-error")}function ae(e,t,n){z.fail({kind:"defer",status:n,root:e}),Me(e);let r=document.getElementById(e);if(!r)return;Rn(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"),ce(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function hu(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function gu(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function bu(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var oi="__materialize",Ce=new WeakMap;function Fe(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function On(e,t,n){Qo();let r=e.element,o=!1,i=!1,s=null,a=null,c,u,l=()=>$e(e),f=(m)=>{if(Fe(r)==="visible"){if(!s)p()}else if(m){let w=r.getAttribute("data-reactive-lazy-on");if(a===w)return;d(),r.addEventListener?.(w,l),a=w}},d=()=>{if(s?.disconnect(),s=null,a)r.removeEventListener?.(a,l);a=null},p=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let m=r.getAttribute("data-reactive-lazy-visible")||"0px";s=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:m}),s.observe(r)},h=()=>{let m=Fe(r)!==null,w=o;if(o=m,!m)return d();if(i)return;if(t.forgetToken(),!w)return l();f(!0)};if(Ce.set(e,{load(){if(i)return;let m=ei(r);if(!m&&r.getAttribute("data-reactive-defer-src")!=null)return;if(m&&vu(r,t))return;let w=m?ce(r.id,m):t.proceed(r,oi,"{}");if(!w)return;i=!0,d();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);d()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&Fe(r)===null)Sn(r),c=(m)=>m.target===r&&Sn(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=(m)=>{if(m.target!==r)return;if(!c)Sn(r);h()},r.addEventListener?.("turbo:morph-element",u),n)return h();if(o=Fe(r)!==null,o)f(!1)}function Ln(e){let t=Ce.get(e);Ce.delete(e),t?.off()}function $e(e){return Ce.get(e)?.load()}function vu(e,t){return t.emit("reactive:before-dispatch",{action:oi,params:{},element:e},{cancelable:!0}).defaultPrevented}function Sn(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||ei(e);if(t)ce(e.id,t)}var Nn=new WeakMap,Ie=new WeakMap,g=null,W,si;function $n(e,t){let n=e.element;Ie.set(n,t),hi();let r=(i)=>wu(i,t),o=(i)=>_u(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Nn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Pn(e){if(Nn.get(e)?.(),Nn.delete(e),Ie.delete(e.element),g&&De(g.origin)===e.element)Pe()}var E=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),ue=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},De=(e)=>e?.closest?.('[data-controller~="reactive"]'),li=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),P=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&li(t)===e),ai=(e)=>ue(E(e,"-item"),null),Fn=(e)=>E(e,"-disabled")==="true",yu=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},fi=(e)=>{let t=E(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>E(n,"-group")===t&&!Fn(n)&&Ie.has(De(n)))};function di(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&li(n);if(g||!r||!t.owns(r)||Fn(r)||Fn(n))return;if(De(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function wu(e,t){if(e.button>0||e.isPrimary===!1)return;let n=di(e.target,t);if(!n)return;let r=E(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,s=(m)=>m.pointerId===e.pointerId,a=e.pointerType==="touch",c=!a,u=a&&setTimeout(()=>c=!0,200),l=(m)=>{if(!s(m))return;if(g)return Cn(m.clientX,m.clientY);if(Math.abs(m.clientX-o)<=4&&Math.abs(m.clientY-i)<=4)return;if(!c)return v();Su(n,t,m),Cn(m.clientX,m.clientY)},f=(m)=>g&&m.cancelable&&m.preventDefault(),d=(m)=>{if(!s(m))return;if(v(),g)Au(),Mn()},p=(m)=>{if(m.type==="pointercancel"&&!s(m))return;if(v(),g)Pe()},b=[["pointermove",l],["pointerup",d],["pointercancel",p],["keydown",(m)=>m.key==="Escape"&&g&&(m.preventDefault(),p(m))],["touchmove",f,{passive:!1}]];for(let[m,w,A]of b)document.addEventListener(m,w,A);function v(){clearTimeout(u);for(let[m,w]of b)document.removeEventListener(m,w)}}function Au(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Su({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),s=i?e.cloneNode(!0):e;if(i){for(let c of[s,...s.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(s)}let a=document.createElement(e.tagName);if(a.setAttribute("data-reactive-sortable-placeholder",""),a.setAttribute("aria-hidden","true"),a.style.height=`${o.height}px`,g=pi({core:n,item:e,row:s,origin:t,source:i,placeholder:a,style:s.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(a);Object.assign(s.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 pi(e){let{row:t,origin:n,source:r}=e;return e.index=P(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),le(n,!0),e}var le=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function qe(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 Cn(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=fi(g.origin).find((r)=>yu(r,e,t));if(n)Eu(n,e,t);else if(g.source)In(null),g.placeholder.remove();xu(e,t)}function In(e){if(g.target!==g.origin)le(g.target,!1);g.target=e,le(e,!0)}function Eu(e,t,n){In(e);let r=P(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),s=i&&o.top===i.top&&o.left!==i.left,a=r.findIndex((c)=>{let u=c.getBoundingClientRect();return s?t<u.left+u.width/2:n<u.top+u.height/2});qe(e,r,a<0?r.length:a,g.placeholder)}function xu(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);Cn(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function _u(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":Mn,Enter:Mn,Escape:Pe,Tab:Pe,ArrowUp:()=>ci(-1),ArrowDown:()=>ci(1),ArrowLeft:()=>ui(-1),ArrowRight:()=>ui(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=di(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),g=pi({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),je("picked")}function ci(e){let t=P(g.target),n=We()+e;if(n>=0&&n<=t.length)qe(g.target,t,n,g.row);mi()}function ui(e){let t=fi(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=We();In(n),qe(n,P(n),r,g.row)}mi()}function mi(){g.row.focus?.(),je("moved")}function We(){let e=P(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function hi(){if(!W?.isConnected)W=document.createElement("div"),W.setAttribute("aria-live","polite"),W.setAttribute("data-reactive-sortable-live",""),W.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(W);return W}function je(e){let t=g.target??g.origin,n=(ue(E(t,"-messages"),{})[e]??"").replaceAll("{position}",We()+1).replaceAll("{count}",P(t).length+1),r=hi();r.textContent="",cancelAnimationFrame(si),si=requestAnimationFrame(()=>r.textContent=n)}function Mn(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,s=t&&(r?i.isConnected:!0),a=s?We():-1,c=s?ai(P(t)[a-1]):null;if(e.keyboard)je("dropped");if(!r&&i)i.replaceWith(o);if(bi(e),!s||t===n&&a===e.index)return;let u=t===n?"self":r?E(n,"-source"):E(n,"-name")??"list",l=ue(E(t,"-from"),{})[u]??E(t),f={...ue(E(t,"-params"),{}),item:ai(e.item),position:a,after:c,from:u},d=[];for(let h=t;h;h=h.parentElement)d.push(h);let p=Ie.get(De(t))?.proceed(t,l,JSON.stringify(f),ue(E(t,"-busy")));if(r)return;Promise.resolve(p).then((h)=>ku(h,d)||gi(e))}function ku(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"))&&Tu(r,t))}function Tu(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 Pe(){let e=g;if(e.keyboard)je("cancelled");e.placeholder?.remove(),bi(e),gi(e)}function gi({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(qe(t,P(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function bi(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:s}=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(s?.remove(),le(n,!1),le(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Si={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Ei={x:"left",y:"top",width:"width",height:"height"},Dn=new WeakMap,jn=new WeakMap,y=null,j,yi,wi=!1;function Bn(e,t){let n=e.element;jn.set(n,t),Ci(),Du();let r=[["pointerdown",(o)=>Cu(o,t,n)],["keydown",(o)=>Iu(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Si[o.key]&&Wn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&Wn()],["input",(o)=>Ai(o,t,n)],["change",(o)=>Ai(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);Dn.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Jn(e){if(Dn.get(e)?.(),Dn.delete(e),jn.delete(e.element),y?.root===e.element)K(y)}var R=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e)=>Math.round(e*1e4)/1e4;function Ru(e,t=1){let n=N(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Hn(e){let t={x:N(e.x),y:N(e.y)};if(e.width!=null)t.width=N(e.width),t.height=N(e.height),t.x=Math.min(t.x,N(1-t.width)),t.y=Math.min(t.y,N(1-t.height));return t}function xi(e,t,n){return{x:R(e.x+t,0,1-e.width),y:R(e.y+n,0,1-e.height),width:e.width,height:e.height}}function _i(e,t,n){return{x:R(e.x+t,0,1),y:R(e.y+n,0,1)}}function ki(e,t,n,r,o,i){let[s,a,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,f=e.y+e.height,d=e.x+e.width/2,p=e.y+e.height/2,h=a?1-e.x:u?l:i?2*Math.min(d,1-d):1,b=c?1-e.y:s?f:i?2*Math.min(p,1-p):1,v=e.width+(a?n:u?-n:0),m=e.height+(c?r:s?-r:0);if(i){let w=(a||u)&&(!(s||c)||Math.abs(v-e.width)>=Math.abs(m-e.height)*i),A=Math.min(h,b*i);v=R(w?v:m*i,Math.min(Math.max(o,o*i),A),A),m=v/i}else{if(a||u)v=R(v,Math.min(o,h),h);if(s||c)m=R(m,Math.min(o,b),b)}return{x:u?l-v:a?e.x:d-v/2,y:s?f-m:c?e.y:p-m/2,width:v,height:m}}function Ou(e,t,n){let r=Math.min(1,t),o=R(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:R(e.x+e.width/2-o/2,0,1-o),y:R(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function Lu(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 k=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Gn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},F=(e)=>e.matches("[data-reactive-point]")?"point":"box",Ti=(e)=>Number(k(e,`${F(e)}-scale`))||1,U=(e)=>F(e)==="point"?["x","y"]:["x","y","width","height"];function Ri(e){let t={};for(let n of U(e))t[n]=(parseFloat(e.style[Ei[n]])||0)/100;return t}function Be(e,t){for(let n of U(e))e.style[Ei[n]]=`${Math.round(t[n]*1e4)/100}%`}function zn(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 Nu(e,t){try{return e.parentElement.closest(k(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function Oi(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function Li(e,t,n){let r=Gn(k(e,F(e)),{}),o={};for(let i of U(e)){let[s]=Oi(t,n,r[i]);if(s)o[i]=s}return o}function Fu(e,t,n,r){let o=k(e,"box-aspect"),i=o&&Oi(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),s=o?Lu(i?.value):Number(k(e,"box-ratio"))||0,{width:a,height:c}=zn(t);return s&&a&&c?s*c/a:0}function Un(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 s=Ri(o),a=Li(o,t,e),c=F(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?Nu(o,i):i,edge:k(n,"box-handle"),start:s,value:s,ratio:c?0:Fu(o,i,t,e),min:Number(k(o,"box-min"))||0,scale:Ti(o),fields:a,before:Object.fromEntries(Object.entries(a).map(([u,l])=>[u,l.value]))}}function Ni(e,t,n,r){let o=Ru(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function fe(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))Ni(e.core,n,e.value[t],e.scale)}function Cu(e,t,n){if(Fi(),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)&&Un(t,n,r,!1);if(!o)return;let{clientX:i,clientY:s}=e,a=zn(o.bounds);o.p0=[(i-a.left)/a.width,(s-a.top)/a.height];let c=(b)=>b.pointerId===e.pointerId,u=(b)=>{if(!c(b)||o.over)return;if(y)return qn(b.clientX,b.clientY);if(Math.abs(b.clientX-i)<=4&&Math.abs(b.clientY-s)<=4)return;$u(o),qn(b.clientX,b.clientY)},l=(b)=>{if(!c(b))return;if(h(),y)Mu(),Wn()},f=(b)=>{if(b.type==="pointercancel"&&!c(b))return;if(h(),y)Pi()},p=[["pointermove",u],["pointerup",l],["pointercancel",f],["keydown",(b)=>b.key==="Escape"&&y&&(b.preventDefault(),f(b))]];for(let[b,v]of p)document.addEventListener(b,v);function h(){for(let[b,v]of p)document.removeEventListener(b,v)}}function Mu(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function $u(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 qn(e,t){let n=y;if(!n.el.isConnected)return K(n);n.x=e,n.y=t;let r=zn(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:s,edge:a}=n;n.value=Hn(F(n.el)==="point"?_i(s,o,i):a?ki(s,a,o,i,n.min,n.ratio):xi(s,o,i)),Be(n.el,n.value),n.writing||=requestAnimationFrame(()=>fe(n)),Pu(t)}function Pu(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),qn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function Fi(){if(y&&!y.el.isConnected)K(y)}function Iu(e,t,n){Fi();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(),Pi());let o=Si[e.key];if(!o)return;if(e.preventDefault(),y??=Un(t,n,r,!0),!y)return;let[i,s]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),a=e.altKey&&F(y.el)==="box",c=y.value;y.value=Hn(F(y.el)==="point"?_i(c,i,s):a?ki(c,y.edge??"se",i,s,y.min,y.ratio):xi(c,i,s)),Be(y.el,y.value),fe(y),Mi(y,a?"resized":"moved")}function Ci(){if(!j?.isConnected)j=document.createElement("div"),j.setAttribute("aria-live","polite"),j.setAttribute("data-reactive-drag-live",""),j.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(j);return j}function Mi(e,t){let n=Gn(k(e.el,`${F(e.el)}-messages`),{})[t]??"";for(let o of U(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=Ci();r.textContent="",cancelAnimationFrame(yi),yi=requestAnimationFrame(()=>r.textContent=n)}function Ai(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(k(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=Un(t,n,o,!0),{ratio:s,start:a}=i??{};if(!s||Math.abs(a.width/a.height/s-1)<0.005)continue;i.value=Hn(Ou(a,s,i.min)),Be(o,i.value),fe(i),$i(i)}}function Wn(){let e=y;if(!e.el.isConnected)return K(e);fe(e),K(e),$i(e)}function $i(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=F(e.el),n=k(e.el,`${t}-action`),r={};for(let o of U(e.el))r[o]=N(e.value[o]);if(!n||U(e.el).every((o)=>r[o]===N(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Gn(k(e.el,`${t}-busy`)))}function Pi(){let e=y;if(e.value=e.start,Be(e.el,e.start),fe(e),e.keyboard)Mi(e,"cancelled");K(e)}function K(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 Du(){if(wi)return;wi=!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=jn.get(n);if(!r?.owns(t))return;let o=Ri(t),i=Ti(t);for(let[s,a]of Object.entries(Li(t,n,r)))Ni(r,a,o[s],i)})}var I=new Map,Di=new WeakSet,qi=!1;function Kn(e,t){if(!qi)qi=!0,document.addEventListener("turbo:morph",Wi),document.addEventListener("turbo:render",Wi);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,Ji(n);let o=(s)=>s.target===n&&queueMicrotask(()=>Bi(r)),i=(s)=>s.target===n&&s.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,s.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)},Bi(r)}function Vn(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 Yn(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},Hi(n)}function Wi(){for(let e of I.values())if(e.core&&!e.removing&&e.root.isConnected)Ji(e.root)}function Ji(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&Di.has(n))return;if(n?.remove(),!ji())setTimeout(()=>{if(!ji())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;Hi(o),Wu(o)}),Di.add(r),qu().appendChild(r)}function qu(){let e=[...document.body.children].find((t)=>t.localName==="reactive-stream-sources");if(!e)e=document.createElement("reactive-stream-sources"),e.hidden=!0,e.setAttribute("data-turbo-permanent",""),document.body.appendChild(e);return e}var ji=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Wu(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&&Gi(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 Hi(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 Gi(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 Bi(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=Gi(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 s=e.seats;if(e.seats=o,!s)return;let a=[...o].filter((u)=>!s.has(u)),c=[...s].filter((u)=>!o.has(u));if(a.length||c.length)e.core.emit("reactive:presence",{joined:a,left:c,me:n??null})}var Je=new Map,de=new Map,Yi=new WeakMap,Xi=new WeakSet,Ui=!1;function Zn(e){if(!Ui)Ui=!0,document.addEventListener("turbo:morph",Ki),document.addEventListener("turbo:render",Ki);let t=e.element,n=de.get(t.id);if(!n)de.set(t.id,n={id:t.id,src:null});Yi.set(t,n),n.observer?.disconnect(),n.root=t,n.removing=!1;for(let r of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source]"))if(!Xi.has(r))r.remove();Xn(n,t.getAttribute("data-reactive-subscribe")),n.observer=new MutationObserver(()=>Xn(n,t.getAttribute("data-reactive-subscribe"))),n.observer.observe(t,{attributes:!0,attributeFilter:["data-reactive-subscribe"]})}function Qn(e){let t=e.element,n=Yi.get(t);if(!n||n.root!==t)return;n.observer.disconnect(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;de.delete(n.id),Xn(n,null)})}function Xn(e,t){let n=e.src;if(e.src=t||null,e.src)Zi(e.src,e.id);if(n&&n!==e.src)ju(n,e.id)}function Ki(){for(let e of de.values())if(e.src&&!e.removing&&e.root.isConnected)Zi(e.src,e.id)}function Zi(e,t){let n=Je.get(e);if(!n)Je.set(e,n={source:null,ids:new Set,connected:!1});if(n.ids.add(t),!n.source?.isConnected)n.source=Bu(e,n)}function ju(e,t){let n=Je.get(e);if(!n)return;if(n.ids.delete(t),n.ids.size)return;Je.delete(e),n.source.remove()}function Bu(e,t){if(!Vi())setTimeout(()=>{if(!Vi())console.error('[phlex-reactive] reactive_subscribe needs the pgbus client (<pgbus-stream-source>) on this page: import "pgbus/stream_source_element"')},5000);let n=document.createElement("pgbus-stream-source");n.setAttribute("src",e),n.setAttribute("data-reactive-subscribe-source",""),n.hidden=!0;let r=Ju(e);if(r!=null)n.setAttribute("since-id",String(r));return n.addEventListener("pgbus:connected",(o)=>{if(t.source!==n)return;let i=t.connected;t.connected=!0;let s=o.detail?.connectionId??null;for(let a of t.ids){let c=de.get(a);if(!c||c.removing||c.src!==e||!c.root.isConnected)continue;c.root.dispatchEvent(new CustomEvent("reactive:subscribed",{detail:{connectionId:s,reconnect:i}}))}}),Xi.add(n),Hu().appendChild(n),n}function Ju(e){let t=null;for(let n of document.querySelectorAll("[data-reactive-subscribe-since]")){if(n.getAttribute("data-reactive-subscribe")!==e)continue;let r=Number(n.getAttribute("data-reactive-subscribe-since"));if(Number.isFinite(r)&&r>=0&&(t==null||r<t))t=r}return t}function Hu(){let e=[...document.body.children].find((t)=>t.localName==="reactive-stream-sources");if(!e)e=document.createElement("reactive-stream-sources"),e.hidden=!0,e.setAttribute("data-turbo-permanent",""),document.body.appendChild(e);return e}var Vi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");var es=new Map,er=new WeakMap,Gu=0,He=new WeakMap;function tr(e,t){let n=e.element;if(!n.id&&!er.has(n))er.set(n,`#${++Gu}`);let r=n.id||er.get(n),o=new Map,i=!1,s=(p)=>{clearTimeout(o.get(p)),o.delete(p)},a=(p,h,b)=>{s(p);let v=Date.parse(h.until)-Date.now();if(!(v>0))return c(p,h,b);let m=Math.ceil(v/1000);ts(p,`${Math.floor(m/60)}:${String(m%60).padStart(2,"0")}`,"running"),u(h.waiting,!0),u(h.done,!1),o.set(p,setTimeout(()=>a(p,h,b),(v-1)%1000+1))},c=(p,h,b)=>{ts(p,"0:00","done"),u(h.waiting,!1),u(h.done,!0);let v=es.get(b)??new Set;if(v.has(h.until))return;es.set(b,v.add(h.until)),p.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:h.until}}))},u=(p,h)=>{let b;try{b=p&&n.querySelector(p)}catch{}if(b&&b.hidden===h)b.hidden=!h},l=()=>{if(i=!1,!He.has(e))return;let p=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((b,v)=>{if(!t.owns(b))return;let m;try{m=JSON.parse(b.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(m?.until)))return;p.add(b),a(b,m,`${r}|${b.id||v}`)});for(let b of o.keys())if(!p.has(b))s(b)},f=()=>{if(i)return;i=!0,queueMicrotask(l)},d=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",f),n.addEventListener("reactive:streamed",f),document.addEventListener("visibilitychange",d),He.set(e,()=>{n.removeEventListener("turbo:morph-element",f),n.removeEventListener("reactive:streamed",f),document.removeEventListener("visibilitychange",d);for(let p of[...o.keys()])s(p)}),l()}function nr(e){He.get(e)?.(),He.delete(e)}function ts(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 Uu(){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 Ku(){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)}}var Vu=["focus","focus_first","blur"];function Yu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=qr(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)hn(n);return}let i=(a)=>kr(a,(c)=>of(c,o),r?(c,u)=>mn(c,u,o):void 0),s=t.findIndex((a)=>Vu.includes(a?.[0]));if(s<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,s)),requestAnimationFrame(()=>i(t.slice(s)))}}function Xu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){_n(this)}}var os=!1,Zu=null;function Qu(){if(os)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;os=!0,document.addEventListener("turbo:before-stream-render",(e)=>{pl(e),el(e),nl(e),on(e)})}var Ke="reactive:streamed";function el(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 s=r.getAttribute("target"),a=r.getAttribute("targets"),c=new Set;for(let u of s?[document.getElementById(s)]:a?document.querySelectorAll(a):[]){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(Ke))}}function Or(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function Lr(e){try{return e.matches(":modal")}catch{return!1}}function Is(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||Lr(e))return;if(e.open)e.close();e.showModal()}function tl(e){if(Or(e)&&e.open)e.close()}function et(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&&!Lr(r))Is(r)}function nl(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),et(document)}}var is=!1;function rl(){if(is)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;is=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))et(t.target)}),document.addEventListener("turbo:morph",()=>et(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||!Lr(n))return;e.delete(n),t.preventDefault(),n.close()})}var vr=new WeakMap;function Ds(e,t,n,r){let o=vr.get(e)??new Map;vr.set(e,o);let i=(s,a)=>{o.delete(s),o.set(s,a)};if(t.endsWith("_class"))for(let s of n.classes??[])i(`.${s}`,e.classList.contains(s));else if(t.endsWith("_attr"))oa(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 s of r({...n,to:n.expanded}))Ds(s,"set_attr",{name:"aria-expanded"})}}var ss=!1;function ol(){if(ss)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ss=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of vr.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 Nr="data-reactive-image-fallback",Z="data-reactive-image-state",yr="data-reactive-image-hidden",rr=null,wr="data-reactive-wrap-hidden";function qs(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(wr,"")}function Ws(e){if(!e.hasAttribute(wr))return;e.removeAttribute("hidden"),e.removeAttribute(wr)}function ve(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Nr);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var js=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Fr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Bs(e,t){let n=Fr(e,t.alt);return n&&!n.contains(e)?n:null}function tt(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(yr,"");if(t.wrap){let o=Fr(e,t.wrap);if(o)qs(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=Bs(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else at(e,t);e.setAttribute(Z,n)}function at(e,t=ve(e)){if(!t||e.getAttribute(Z)==null)return;if(e.getAttribute(Z)==="error"){if(e.hasAttribute(yr))e.removeAttribute("hidden");let n=Fr(e,t.wrap);if(n)Ws(n);let r=Bs(e,t);if(r)r.hidden=!0}e.removeAttribute(Z),e.removeAttribute(yr)}function as(e){let t=e.target,n=ve(t);if(!n)return;if(e.type==="load")tt(t,n,"loaded");else if(js(t))tt(t,n,"error");else at(t,n)}function il(){if(rr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;rr={error:as,load:as,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(Z);if(o==null||!r||!ve(n))return;let i=(s)=>n.getAttribute(s)===r.getAttribute?.(s);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=ve(n);if(o)tt(n,o,r)})},"turbo:frame-render":(t)=>Ge(t.target),"turbo:render":()=>Ge(document),"turbo:before-stream-render":(t)=>{let n=t.detail,r=n?.render,o=n?.newStream??t.target;if(typeof r!=="function"||!o?.querySelector?.("template")?.content?.querySelector?.(`img[${Nr}]`))return;n.render=async(i)=>{await r(i),Ge(document)}}};for(let[t,n]of Object.entries(rr))document.addEventListener(t,n,!0);Ge(document)}function Ge(e){for(let t of e?.querySelectorAll?.(`img[${Nr}]`)??[]){if(t.getAttribute(Z)!=null||!t.complete||!js(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&tt(t,ve(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 Of(e){Zu=e}var ze,or=null,cs="[data-reactive-editable][contenteditable=plaintext-only]";function Js(){if(ze===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",ze=e.contentEditable==="plaintext-only"}catch{ze=!1}return ze}function Ve(e){if(e.matches?.(cs))e.setAttribute("contenteditable","true");e.querySelectorAll?.(cs).forEach(Ve)}function sl(){if(or||typeof document>"u"||typeof document.createElement!=="function")return;if(Js())return;Ve(document),or=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Ve(t.target);else t.addedNodes.forEach(Ve)}),or.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var us=!1;function ls(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 al(){if(us)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;us=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=ls(t);if(r)ul(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(rt.set(t,H(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==O)t.removeAttribute(i);for(let{name:i,value:s}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==s)t.setAttribute(i,s);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)=>Ir(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===O)&&ls(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(O)&&Mr(t)===$r(t))t.removeAttribute(O)})}var O="data-reactive-held",Cr='[data-controller~="reactive"]',Ye=null,X=new Map;function Mr(e){return e.hasAttribute("data-reactive-editable")?H(e):e.value}function $r(e){return e.hasAttribute("data-reactive-editable")?Dr(e):e.defaultValue}function cl(e){if(e.hasAttribute("data-reactive-editable"))return H(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function ul(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||X.has(e.closest(Cr)))return;let r=cl(t);if(r===Mr(e))return e.removeAttribute(O);if(r===$r(e))return;e.setAttribute(O,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function ll(e){let t=[];for(let n of e.querySelectorAll(`[${O}]`)){if(n.closest(Cr)!==e)continue;let r=n.getAttribute("name");if(Mr(n)===$r(n))n.removeAttribute(O);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 Hs(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${O}]`))if(n.closest(Cr)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(O)}function fl(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 fs(e,t,n=null,r=30000){let o={root:e,streams:0,keep:n,events:[]},i=Ye;Ye=o;try{window.Turbo.renderStreamMessage(t)}finally{Ye=i}if(o.streams===0)Hs(e,n);let s=o.events.filter((l)=>!l.event.defaultPrevented).map((l)=>l.done),a=s.length>0?Promise.all(s).then((l)=>l.find(Boolean)):dl(),c,u=new Promise((l)=>c=setTimeout(l,r));return Promise.race([a,u]).finally(()=>clearTimeout(c))}function dl(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function pl(e){let t=Ye,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++;let o;t.events.push({event:e,done:new Promise((i)=>o=i)}),n.render=async(i)=>{X.set(t.root,(X.get(t.root)||0)+1);let s;try{return await r(i)}catch(a){throw s=a,a}finally{let a=X.get(t.root)-1;if(a)X.set(t.root,a);else X.delete(t.root);Hs(t.root,t.keep),o(s)}}}var ds="__materialize",ps=!1;function ml(){if(ps)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;ps=!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 Pr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")fn()}var Gs="data-reactive-active",Ar="data-reactive-errors",S=0,J=[];function zs(){if(S++,S===1)J=[],Ks("reactive:busy")}function me({action:e=null,kind:t,status:n=null,root:r=null}){if(S===0)return;J.push({action:e??null,kind:t,status:n??null,root:r||null})}function Us(){if(S===0)return;if(S--,S===0){let e=J;Ks("reactive:idle"),wl(e)}}function Lf(){return S}function Nf(){S=0,J=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(Gs),e?.removeAttribute?.(Ar)}function Ks(e){if(typeof document>"u")return;let t=document.documentElement,n=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(Gs,S>0),n&&J.length>0)t.setAttribute(Ar,JSON.stringify(J));else t.removeAttribute(Ar);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let r=n?{count:S,errors:J.slice()}:{count:S};document.dispatchEvent(new CustomEvent(e,{detail:r}))}}var hl="data-reactive-debouncing",C=new Set,D=[];function gl(e){if(C.add(e),C.size===1)Vs()}function bl(e){if(!C.delete(e)||C.size>0)return;Vs(),queueMicrotask(Ys)}function Vs(){(typeof document<"u"?document.documentElement:null)?.toggleAttribute?.(hl,C.size>0)}function Ff(){return C.size}function vl(){for(let e of[...C])if(C.has(e))e()}var ct=()=>S===0&&C.size===0;function yl({timeout:e}={}){if(ct())return Promise.resolve({count:0,errors:[]});return new Promise((t)=>{let n={resolve:t,errors:[],timer:null};if(Number(e)>0)n.timer=setTimeout(()=>{D=D.filter((r)=>r!==n),t({count:S,errors:n.errors,timedOut:!0})},Number(e));D.push(n)})}function wl(e){if(D.length===0)return;for(let t of D)t.errors.push(...e);Ys()}function Ys(){if(!ct()||D.length===0)return;let e=D;D=[];for(let t of e)clearTimeout(t.timer),t.resolve({count:0,errors:t.errors})}function Xs(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:30000}var ms="data-reactive-await-settled",he="data-reactive-awaiting",ir=new WeakSet,sr=null,nt=0,hs=0,B=(e)=>e?.hasAttribute?.(ms)===!0&&e.getAttribute(ms)!=="false";function Al(e,t){let n=e.getAttribute("id"),r=n?null:e.parentElement?.closest?.("[id]");return()=>{let i=(n?[document.getElementById(n)]:Array.from((r&&document.getElementById(r.getAttribute("id"))?.querySelectorAll(e.tagName))??[])).filter((s)=>s?.tagName===e.tagName&&t(s));return i.length===1?i[0]:null}}var Sr=(e)=>[e.tagName,e.type,e.name,e.value,e.getAttribute("formaction"),e.getAttribute("formmethod")].join("\x00");function gs(e,t,n){if(t.isConnected&&t.form===e&&Sr(t)===n)return t;let r=Array.from(e.elements).filter((o)=>Sr(o)===n);return r.length===1?r[0]:null}function Zs(e,t){let n=nt;return vl(),yl({timeout:e*2}).then(({errors:r,timedOut:o})=>t(!o&&r.length===0&&n===nt))}function Qs(e,t,n,r){if(ir.has(t)||ct())return;if(e.preventDefault(),e.stopImmediatePropagation(),t.hasAttribute(he))return;let o=++hs,i=Al(t,n);Zs(Xs(),(s)=>{t.removeAttribute(he);let a=t.isConnected&&n(t)?t:i();if(!s||o!==hs||!a)return;ir.add(a);try{r(a)}finally{ir.delete(a)}}),t.setAttribute(he,"")}function Sl(e){if(e.defaultPrevented)return;let t=e.target;if(t?.tagName!=="FORM")return;let n=e.submitter??null,r=B(t);if(!r&&!B(n))return;let o=(c)=>[c.getAttribute("action"),c.getAttribute("method")].join("\x00"),i=o(t),s=n&&Sr(n);Qs(e,t,(c)=>o(c)===i&&(r?B(c):B(gs(c,n,s))),(c)=>{if(!n)return c.requestSubmit();let u=gs(c,n,s);if(u)c.requestSubmit(u)})}function El(e){if(e.defaultPrevented||e.button!==0)return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.("a[href]");if(!t||!B(t)||t.hasAttribute("download"))return;let n=t.getAttribute("target");if(n&&n!=="_self")return;let r=t.getAttribute("href");Qs(e,t,(i)=>i.getAttribute("href")===r&&B(i),(i)=>i.click())}function xl(){if(sr)return;if(typeof window>"u"||typeof window.addEventListener!=="function")return;let e=()=>nt++;sr={submit:Sl,click:El,"turbo:before-prefetch":(t)=>B(t.target)&&t.preventDefault(),"turbo:visit":e,"turbo:before-render":e};for(let[t,n]of Object.entries(sr))window.addEventListener(t,n,!0)}var ea="data-reactive-requests";function ta(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!_l(t))return;let n=kl(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(ea,JSON.stringify(n))}function _l(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function kl(e){try{let t=JSON.parse(e.getAttribute(ea));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function bs(){Uu(),Ku(),Yu(),Xu(),Qu(),al(),rl(),ol(),ql(),il(),xl(),sl(),ml(),Pr()}function Tl(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var na=Symbol.for("phlex-reactive.core");if(globalThis[na])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[na]=!0;var ra=!1;function Rl(){if(ra)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(Rl,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Ol=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function oa(e){let t=String(e).toLowerCase();return t.startsWith("on")||Ol.has(t)}var ar=new WeakMap;function Ll(e,t,n){let[r,o,i]=t;ar.get(e)?.(),e.classList.add(r,o),n();let s=!1,a=requestAnimationFrame(()=>{if(s)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(s||l&&l.target!==e)return;s=!0,ar.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(a),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};ar.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Nl(e))}function Nl(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((a)=>String(n[r+a]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),s=String(n[r+"IterationCount"]).split(",").map((a)=>/inf/.test(a)?1/0:parseFloat(a)>=0?parseFloat(a):1);for(let a=0;a<o.length||a<i.length||a<s.length;a++){let c=o[a%o.length]*s[a%s.length]||0;t=Math.max(t,c+i[a%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Fl=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Cl=new Set(["lexxy-editor","trix-editor"]);function H(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
1
+ import{Controller as Ku}from"@hotwired/stimulus";import{confirmResolver as is}from"phlex/reactive/confirm";import{confirmPredicate as ga}from"phlex/reactive/confirm_predicate";var q=new WeakMap,pt=new WeakMap;function M(e,t){let n=q.get(e);if(!n){if(q.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)pt.set(n.root,n);let r;n.listnav=()=>{if(r)return;r=!0,queueMicrotask(()=>{if(r=!1,q.get(e)===n)n.core.syncListnav()})}}return n}function E(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){E(e,"turbo:morph-element",t),e.seeds.push(t),t()}function mt(e,t){let n=M(e,t);n.offs=[],n.seeds=[];let r,o,i,s,a;if((n.wire=()=>{if(!n.show&&Sa(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")Ia(n,c.target);else n.groups=$a(n),Vr(n);zr(n)},E(n,"input change",n.show),E(n,"focusout",(c)=>{let u=c.target?.getAttribute?.("name");if(!u||n.touched?.has(u)||!n.core.bindingOwns(c.target))return;if((n.touched??=new Set).add(u),n.root.querySelector?.("[data-reactive-show-after]"))zr(n)}),G(n,n.show);if(!n.arm&&Ea(n))E(n,"input change",(c)=>Hr(n,c)),G(n,n.arm=()=>{Hr(n,null),Vr(n)});if(!r&&(r=n.show||n.arm))E(n,"reset",()=>setTimeout(()=>{if(q.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))E(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!ba(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=Ae(n)))E(n,"input",(c)=>Wa(n,c)&&ne(n)),G(n,()=>{ne(n),n.listnav()});if(!s&&(s=xe(n)))G(n,()=>ao(n));if(!a&&(a=Ja(n)))E(n,"input change",(c)=>fo(n,c)),G(n,()=>xt(n))})(),!i)G(n,n.listnav);if(E(n,"keydown",(c)=>ic(n,c)),E(n,"paste drop",(c)=>sc(n,c)),E(n,"input",(c)=>ac(n,c)),["token-value","defer-token","defer-src","lazy-on","lazy-visible"].every((c)=>n.root.getAttribute?.(`data-reactive-${c}`)==null))E(n,"reactive:streamed",()=>Se(e))}function ba(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function ht(e){let t=q.get(e);if(!t)return;q.delete(e),pt.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Se(e){let t=q.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function W(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function gt(e,t,n){return fo(M(e,t),n)}function bt(e,t,n){return bo(M(e,t),n)}var va=/^#[A-Za-z_][\w-]*$/,Xr="[data-reactive-show-field], [data-reactive-show]";function ya(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 po){let s=e.getAttribute(`data-reactive-show-${i}`);if(s!==null)return ho(i,s,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Zr(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 wa(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 Qr(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 re(n,t);return Aa(e,t)}function Aa(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)=>Ot(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function we(e,t="show"){if(typeof e==="string"&&va.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Sa(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?.(Xr)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(Ee)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${no}, ${ro}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Ea(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function xa(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:wa(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Hr(e,t){let n=xa(e);if(!n.length)return;let r=to(e,e.core.bindingOwnership());n.forEach((o,i)=>{let s=re(o.any,r);if(s===null)return;let a=s&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=s,a)e.core.applyOps(o.ops,"@root")})}function zr(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.core.bindingOwnership(),r=e.root.getAttribute?.("data-reactive-scope")||null,o=to(e,n),i=[];for(let s of e.root.querySelectorAll(Xr)){if(!t(s))continue;let a=s.getAttribute("data-reactive-show");if(a!==null){let f=Qr(Zr(a),o);if(f===null)continue;let d=s.getAttribute("data-reactive-show-after"),p=f&&(d==null||!!e.touched?.has(yt(d,r)));Gr(s,p,n);let h=(e.shown??=new WeakMap).get(s);if(e.shown.set(s,p),_a.some((v)=>s.hasAttribute(`data-reactive-show-${v}`))&&h!==void 0&&h!==p)i.push(s);continue}let c=s.getAttribute("data-reactive-show-field");if(!c)continue;let u=o(c);if(u===null)continue;let l=ya(s,u);if(l===null)continue;Gr(s,l,n)}if(e.groups)Da(e,o,t,r);Oa(e,o,t),Ca(e,o,t,r,n),Ta(e,o),qa(e,o);for(let s of i)ka(e,s,n,r)}var _a=["clear","focus","scroll"];function ka(e,t,n,r){if(t.hidden){let a=[];try{a=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(a)?a:[]).map((u)=>yt(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,W(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"),s=null;try{s=i?e.root.querySelector(i):null}catch{}s?.focus?.(o?{preventScroll:!0}:void 0)}function Gr(e,t,n){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let r of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(r))r.disabled=!t;if(e.name&&n(e))e.disabled=!t}function Ta(e,t){let n=eo(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Ra(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let s=(a,c)=>c?t(r,!0):i;for(let[a,c]of Object.entries(o)){if(!we(a))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${a} — skipped`);continue}u=c.every((l)=>Ot(l,s))}else{let l=go(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${a} — skipped`);continue}u=l}for(let l of document.querySelectorAll(a))l.hidden=!u}}}function Ra(e,t,n){if(!we(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=rc(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((s)=>n(s)===null)&&!oc(r))return;let i=re(r,n);if(i===null)return;for(let s of document.querySelectorAll(e))s.hidden=!i}function eo(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 La(e,t,n,r){let o=!1,i=null;for(let s of e.root.querySelectorAll(vt(t,r))){if(!n(s))continue;if(s.type==="checkbox")return s.checked?"true":"false";if(s.type==="radio"){if(s.checked)return s.value??"";o=!0;continue}i??=s}if(i)return i.value??"";return o?"":null}function vt(e,t){return`[name="${yt(e,t)}"]`}function yt(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function to(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let s=i?`#${o}`:o;if(!r.has(s))r.set(s,i?wt(e,o,t,n).filter((a)=>a.checked).length:La(e,o,t,n));return r.get(s)}}var no="[data-reactive-media]";function Oa(e,t,n){for(let r of e.root.querySelectorAll(no)){if(!n(r))continue;let o,i,s;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)s=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!s){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let a=t(o.field);if(a===null)continue;let c=o.take>0?[...a]:null,u=c?c.slice(0,o.take).join(""):a,l=c?.length<o.take||i?.test(u)===!1||s?.test(a)===!1;if(l&&o.pending==="keep"){Ur(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?Kr(e,o.pool[u])[0]:null,d=e.core.copyMedia(r,f??null);if(d===null)continue;if(Ur(r,l?"pending":d===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":d===!1?String(o.blank??""):d;for(let h of Kr(e,o.label))if(h.textContent!==p)h.textContent=p}}function Ur(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Kr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var ro="[data-reactive-css-vars]",Na=/^--[a-z0-9-]+$/i,Fa=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ca(e,t,n,r,o){let i=[...e.root.querySelectorAll(ro)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))i.unshift(e.root);for(let s of i){let a;try{a=JSON.parse(s.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 c=a.to.flatMap((u)=>{let l={to:u,global:a.global===!0},f=[];try{f=e.core.opTargets(l)}catch{}if(!f.length)e.core.diagnose("reactive_css_vars",l);return f});for(let[u,l]of Object.entries(a.vars)){let f=l?.unit??"";if(!Na.test(u)||!Fa.includes(f)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let d=Ma(e,t,l.field,o,r);if(d===void 0)continue;let p=d===null?"":`${d}${f}`;for(let h of c){if(h.style.getPropertyValue(u)===p)continue;if(p)h.style.setProperty(u,p);else h.style.removeProperty(u)}}}}function Ma(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(vt(n,o))].some((a)=>r(a)&&a.type==="checkbox"))return i==="true"?1:0;let s=i.trim()?Number(i):NaN;return Number.isFinite(s)?s:null}var Ee="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function $a(e){return!!e.root.querySelector?.(Ee)}function wt(e,t,n,r,o){return[...e.root.querySelectorAll(vt(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Pa(i.getAttribute("data-reactive-group"),o)))}function Pa(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Ia(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))oo(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function At(e,t,n){if(!t)return;let r=pt.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};oo(r,t,n!==!1),r.show?.()}function oo(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,s=wt(e,t,e.core.ownership(),i,o).filter((a)=>a!==r&&a.checked!==n);for(let a of s)a.checked=n;e.flipping=!0;try{for(let a of s)for(let c of["input","change"])a.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function Da(e,t,n,r){for(let o of e.root.querySelectorAll(Ee)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Qr(Zr(i),t);if(c!==null)o.disabled=!c}let s=o.getAttribute("data-reactive-count");if(s){let c=String(t(s,!0));if(o.textContent!==c)o.textContent=c}let a=o.getAttribute("data-reactive-select-all");if(a){let c=o.getAttribute("data-reactive-select-all-under"),u=wt(e,a,n,r,c).filter((f)=>f!==o),l=u.filter((f)=>f.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function qa(e,t){for(let[n,r]of Object.entries(eo(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let s of Array.isArray(r.count)?r.count:[]){if(!we(s,"group"))continue;for(let a of document.querySelectorAll(s))if(a.textContent!==o)a.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[s,a]of Object.entries(i)){if(!we(s,"group"))continue;let c=re(a?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${s} — skipped`);continue}for(let u of document.querySelectorAll(s))u.disabled=!c}}}function Vr(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?.(`${Ee}, [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 Ae(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Wa(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var ja=/[\s\-'(),./]/;function Ba(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||ja.test(t[r-1]))return!0;return!1}function ne(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"),s=e.root.hasAttribute?.("data-reactive-filter-fold"),a=(d)=>{let p=(d??"").toLowerCase().trim();return s?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=a(o.value),u=0;for(let d of e.root.querySelectorAll(n)){if(!r(d))continue;let p=d.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Ba(i,a(d.getAttribute("data-reactive-filter-text")??d.textContent),c);if(d.hidden=p,p)d.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let d of e.root.querySelectorAll(l)){if(!r(d))continue;let p=[...d.querySelectorAll(n)].filter(r);if(p.length===0)continue;d.hidden=p.every((h)=>h.hidden)}let f=e.root.getAttribute("data-reactive-filter-empty");if(f){for(let d of e.root.querySelectorAll(f))if(r(d))d.hidden=u>0}e.listnav()}function xe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Ja(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function St(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 Et(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 io(e,t){let n=St(e);if(!n)return!1;let r=Et(n),o=new Set(r.map((s)=>s.toLowerCase())),i=!1;for(let s of t){let a=String(s??"").trim();if(a===""||o.has(a.toLowerCase()))continue;o.add(a.toLowerCase()),r.push(a),i=!0}if(i)so(e,n,r);return i}function so(e,t,n){t.value=n.join(","),W(t),ao(e)}function Ha(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 ao(e){let t=St(e);if(!t)return;let n=Et(t),r=e.core.ownership();za(e,n,r),Ga(e,n,r)}function za(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 s of t){let a=i.cloneNode(!0);a.setAttribute?.("data-reactive-tag",s);let c=a.matches?.("[data-reactive-tag-text]")?a:(a.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=s;let u=[...a.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(a.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(a);for(let l of u)l.setAttribute?.("data-reactive-tag-param",s);r.appendChild(a)}}function Ga(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"),!Ae(e))o.hidden=!1}}if(Ae(e))ne(e);e.listnav()}function Ua(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Ka(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 Va(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 Ya(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(),s=[...t.querySelectorAll?.("input, select, textarea")??[]],a=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let f=s.find((d)=>uo(d.getAttribute?.("name"))===c);if(!f)continue;if(Xa(f,l),!a.includes(l))a.push(l)}if(r)for(let c of a)Za(c,r);return a[0]??null}function Xa(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:ft(t)!=="";else e.value=ft(t);W(e)}function Za(e,t){let n=t==="reset";if(e.type==="checkbox"||n&&e.type==="radio")e.checked=n&&!!e.defaultChecked;else if(n&&e.options){let r=Array.from(e.options),o=!e.multiple&&!(e.size>1),i=r.filter((s)=>s.defaultSelected).pop()??r.find((s)=>!s.closest?.("optgroup")?.disabled&&!s.disabled);for(let s of r)s.selected=o?s===i:!!s.defaultSelected}else e.value=n?e.defaultValue??"":"";W(e)}function Qa(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Yr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",W(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);xt(e)}function xt(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))lo(e,n.getAttribute("data-reactive-nested-json"))}function ec(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 co(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=uo(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=ft(o)}return n}function uo(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function ft(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function lo(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ec(e,r);if(!o)return;let i=[];for(let a of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(a)||a.hidden)continue;i.push(co(e,a))}let s=JSON.stringify(i);if(o.value===s)return;o.value=s,W(o)}function _t(e,t,n){let r=M(e,t);if(!xe(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((s)=>s.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!io(r,String(o.value??"").split(",")))return;if(o.value="",Ae(r))ne(r)}function kt(e,t,n){let r=M(e,t);if(!xe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!io(r,[i]))return;let s=Ha(r);if(!s)return;s.value="",ne(r),s.focus?.()}function Tt(e,t,n){let r=M(e,t);if(!xe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let s=St(r);if(!s)return;let a=Et(s),c=a.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===a.length)return;so(r,s,c)}function Rt(e,t,n){let r=M(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 s=r.core.ownership(),a=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(s),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(s)?.content?.firstElementChild;if(!a||!u){Va(r,i);return}let l=u.cloneNode(!0);Ka(l,Ua(r)),a.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param"),h=Ya(r,l,f,d==="true"||d==="reset"?d:null);if(f)h?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(a.getAttribute?.("data-reactive-nested-json")===i)lo(r,i)}function Lt(e,t,n){let r=M(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 s=o?.getAttribute?.("data-reactive-confirm-param"),a=o?.getAttribute?.("data-reactive-confirm-when-param"),c=s||(a?bo(r,a):null);if(!c)return Yr(r,i);let u=co(r,i),l=Qa(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Yr(r,i)})}function fo(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;xt(e)}var po=["gte","gt","lte","lt"],tc=["len_eq","len_gte","len_gt","len_lte","len_lt"],mo=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],nc=["digits_eq","digits_gte","digits_lt","digits_lte"];function dt(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 ho(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 go(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 po)if(n in e)return ho(n,e[n],t);for(let n of tc)if(n in e)return dt(n,e[n],[...String(t??"")].length);return null}function Ot(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=mo.find((i)=>(i in e));if(n){let i=t(e.field,!0);return dt(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(s)=>{let a=String(t(s)??"");return e.fold===!0?a.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):a};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=nc.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((a)=>Number.isInteger(e[a]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((a)=>dt(a,e[a],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return go(e,o)===!0}function re(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Ot(r,t)))}function rc(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 oc(e){return e.flat().every((t)=>mo.some((n)=>(n in Object(t))))}function bo(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=(s)=>r[s],i;if(typeof n.predicate==="string"){let s=ga(n.predicate);if(!s)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!s(r)}else i=re(n.groups?.any,o)===!0;return i?n.message:null}function Nt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ic(e,t){let n=Nt(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),W(n),n.blur()}function sc(e,t){let n=Nt(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 ac(e,t){let n=Nt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as cc}from"phlex/reactive/compute";var ie=new WeakMap;function So(e,t){let n=ie.get(e);if(!n)ie.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Ft(e,t,n,r){let o=So(e,t),i=Ec(o);if(i){o.seed=()=>_e(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(s)=>s.target!==o.root&&[...s.target.querySelectorAll(yo)].some(o.core.bindingOwns)&&o.seed();for(let s of Eo)o.root.addEventListener?.(s,o.nested)}if(o.share=(s)=>s.target?.matches?.(yo)&&!o.core.owns(s.target)&&o.core.bindingOwns(s.target)&&_e(o,s),o.root.addEventListener?.("input",o.share),i||r?.edited)_e(o)}function Ct(e){let t=ie.get(e);if(!t)return;if(ie.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of Eo)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function Mt(e){ie.get(e)?.seed?.()}function $t(e,t,n){return _e(So(e,t),n)}var yo="[data-reactive-shared-field]",Eo=["reactive:connect","reactive:persist-restored"],uc=Object.freeze({el:null,kind:""}),lc=/^#[A-Za-z_][\w-]*$/;function oe({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 xo(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function fc(e,t){if(t==="string")return oe(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):xo(oe(e));if(n)return e.el.checked?1:0;let r=Number(oe(e));return Number.isFinite(r)?r:0}function dc(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let s=xo(i);if(Boolean(n.checked)===s)return null;return n.checked=s,n}if(r==="radio")return pc(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function pc(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let s=i.value===r;if(Boolean(i.checked)===s)continue;if(i.checked=s,s)o=i;else o??=i}return o}function mc(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 hc(e){if(typeof e==="string"&&lc.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function gc(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 bc(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 vc(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 yc(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=wc(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function wc(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function wo(e,t,n){let r=String(n);for(let o of Ac(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Ac(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Ao(e,t,n){let r=Sc(e);for(let[o,i]of Object.entries(r)){let s=o in t?null:n(o),a=o in t?t[o]:s.el?oe(s):void 0;if(a===void 0||a===null)continue;let c=String(a);for(let u of Array.isArray(i)?i:[i]){if(!hc(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Sc(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 Ec(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function _e(e,t){if(t&&e.ours.has(t))return;let n=vc(e),r=n.map(([v])=>v),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(v)=>o&&!v.includes("[")?`${o}[${v}]`:v,s=e.core.bindingOwnership(),a=new Map,c=(v)=>{let m=a.get(v);if(m)return m;let w=null,A=null,_=null;for(let T of e.root.querySelectorAll(`[name="${i(v)}"]`)){if(!s(T))continue;let ye=T.type;if(ye==="checkbox"||ye==="radio"&&T.checked){_={el:T,kind:ye};break}if(ye==="radio")w??=T;else A??=T}if(!_)if(w)_={el:w,kind:"radio"};else _=A?{el:A,kind:""}:uc;return a.set(v,_),_};for(let v of r)wo(e,v,oe(c(v)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?cc(u):null;if(!l){Ao(e,{},c);return}let f=bc(e,"data-reactive-compute-outputs-param"),d={};for(let[v,m]of n)d[v]=fc(c(v),m);let p=l(d,{changed:yc(e,t,r,o)})||{},h=mc(p.$ops),b=[];for(let v of f){if(v==="$ops"||!(v in p))continue;let m=c(v);if(!m.el)continue;let w=dc(e.root,s,m,i(v),p[v]);if(w)b.push(w)}for(let v of Object.keys(p)){if(v==="$ops")continue;let m=p[v];if(m===void 0||m===null)continue;wo(e,v,m)}Ao(e,p,c);for(let v of b){let m=new Event("input",{bubbles:!0});e.ours.add(m),v.dispatchEvent(m)}gc(e,h,Boolean(t))}var qt;function Wt(e){qt=e}var Lo=1,xc="phlex-reactive:persist:",_c=new Set(["hidden","file","password","submit","button","reset","image"]),jt=Symbol("persist-no-value"),Bt="data-reactive-persist-state",kc=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Tc=new Set(["lexxy-editor","trix-editor"]),Rc="lexxy-editor, trix-editor, trix-toolbar",Lc=["lexxy:change","trix-change"],Oc=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),ko=new WeakSet,To=new WeakSet,Ro=new WeakSet;function Te(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(!ko.has(e))ko.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Jt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Ht(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||To.has(e))return;To.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function zt(e){return xc+e.key}function It(e,t){let n=Jt(t);if(!n)return null;let r;try{r=n.getItem(zt(t))}catch(c){return Ht(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Lo)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return ke(e,t),null;let s=o.fields&&typeof o.fields==="object"?o.fields:{},a=o.state&&typeof o.state==="object"?o.state:null;return{fields:s,state:a}}function Oo(e,t,{fields:n,state:r}){let o=Jt(t);if(!o)return!1;let i={v:Lo,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(zt(t),JSON.stringify(i)),!0}catch(s){return Ht(e,s),!1}}function ke(e,t){e?.removeAttribute?.(Bt);let n=Jt(t);if(!n)return;try{n.removeItem(zt(t))}catch(r){Ht(e,r)}}function Gt(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)||_c.has(i.type)||i.closest(Rc))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(kc)){if(!o(i))continue;let s=Nc(i);if(!s||n&&!n.has(s))continue;r.push({el:i,name:s,kind:Tc.has(i.localName)?"editor":"contenteditable"})}return r}function No(e){return e.hasAttribute("data-reactive-editable")?qt.text(e):e.textContent??""}function Nc(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Ut(e){return typeof e.value==="string"}function Fc(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Oc.has(e.value.trim())}function Cc(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Ro.has(e))return;Ro.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function se(e){return e.tagName==="SELECT"&&e.multiple}function Fo(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 Co(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return jt;return e[0]}function Mo(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:s}of Gt(e,t)){let a=String(i).endsWith("[]");if(s==="editor"){if(Ut(o))if(a)r(i).push(o.value);else n[i]=o.value}else if(s==="contenteditable"){let c=No(o);if(a)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(a){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(se(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(a)r(i).push(...c);else n[i]=c}else if(a)r(i).push(o.value);else n[i]=o.value}return n}function Mc(e,t,n){let r=t.restore==="always",o=Gt(e,t),i=Fo(o),s=new Set;for(let a of o)if(a.kind==="native"&&a.el.type==="checkbox"&&a.el.checked)s.add(a.name);for(let{el:a,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)&&se(a)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(a.type==="checkbox"||se(a))){if(l=Co(l,c,i),l===jt)continue}if((a.type==="checkbox"||se(a))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")$o(e,a,c,l,r);else if(u==="contenteditable"){if(!r&&No(a).trim()!=="")continue;a.textContent=String(l)}else if(a.type==="radio"){if(!r&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;a.checked=a.value===String(l)}else if(a.type==="checkbox"&&Array.isArray(l)){if(!r&&s.has(c))continue;a.checked=l.map(String).includes(a.value)}else if(a.type==="checkbox"){if(!r&&a.checked)continue;a.checked=Boolean(l)}else if(se(a)){if(!r&&[...a.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of a.options)d.selected=f.has(d.value)}else{if(!r&&a.value!=="")continue;a.value=String(l)}}$c(e,t,n)}function $o(e,t,n,r,o){if(Array.isArray(r))return;if(!Ut(t))return;if(!o&&!Fc(t))return;try{t.value=String(r)}catch(i){Cc(e,n,i)}}function $c(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let s of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Ut(s)&&!r.get?.(s.localName))o.add(s.localName);let i=t.restore==="always";for(let s of o)r.whenDefined(s).then(()=>{if(!e.isConnected)return;let a=Gt(e,t),c=Fo(a);for(let{el:u,name:l,kind:f}of a){if(f!=="editor"||u.localName!==s||!Object.hasOwn(n,l))continue;let d=Co(n[l],l,c);if(d===null||d===void 0||d===jt)continue;$o(e,u,l,d,i)}})}function Pc(e,t,n=!0){let r=Te(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=It(e,r),i={...o?.state??{},...t},s=n?Mo(e,r):o?.fields??{};if(Oo(e,r,{fields:s,state:i}))e.setAttribute?.(Bt,JSON.stringify(i))}function Ic(e){let t=Te(e);if(t)ke(e,t)}var Dt=new WeakMap,Pt=new WeakMap;function Dc(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=Pt.get(e);if(!n){let i=new Set,s=(a)=>{for(let c of i)c(a)};e.addEventListener("turbo:submit-end",s),n=[i,s],Pt.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),Pt.delete(e)}}function Kt(e,t,n,r){let o=e.element,i=Te(o);if(!i)return;if(r?.submitted)ke(o,i);let s=It(o,i);if(s){if(Mc(o,i,s.fields),s.state)o.setAttribute?.(Bt,JSON.stringify(s.state));t.emit("reactive:persist-restored",{key:i.key,fields:s.fields,state:s.state??{}}),t.reseed()}let a=null,c=()=>{if(a!==null)clearTimeout(a),a=null},u=()=>{c();let h=It(o,i);Oo(o,i,{fields:Mo(o,i),state:h?.state??null})},l=()=>{let h=Number(i.debounce)||0;if(h<=0)return u();if(a!==null)clearTimeout(a);a=setTimeout(()=>{a=null,u()},h)},f=(h)=>{if(!h?.detail?.success)return;let b=h.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),ke(o,i)},d=["input",...Lc];for(let h of d)o.addEventListener?.(h,l);o.addEventListener?.("change",u);let p=Dc(globalThis.document,f);if(Dt.set(e,()=>{if(a!==null)u();for(let h of d)o.removeEventListener?.(h,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let h of r?.ops??[])h(!0)}function Vt(e){let t=Dt.get(e);Dt.delete(e),t?.()}function Po(e,t){let n=qt?.waiting.get(e)?.persist;if(!n||!Te(e))return t(!0);(n.ops??=[]).push(t)}function Yt(e,t){Po(e,(n)=>Pc(e,t,n))}function Xt(e){Po(e,()=>Ic(e))}var Re=new WeakMap,Do=new WeakSet,Zt=new WeakMap;function Qt(e,t){let n=e.element,r=[],o=[],i=(u,l,f)=>{u.addEventListener?.(l,f),r.push(()=>u.removeEventListener?.(l,f))},s,a,c=()=>{if(!s&&(s=qc(n,t))){let u=()=>Le(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Bc(n,r)}if(!a&&(a=Jc(n,t))){let u=()=>Hc(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};Re.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function en(e){for(let t of Re.get(e)?.[0]??[])t();Re.delete(e)}function tn(e){Re.get(e)?.[1]()}function qc(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 Le(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,s)=>{if(s)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,Wc(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 Wc(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 jc(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Bc(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Zt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(jc(c)>0)return c;return null},s=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},a=(c)=>{if(Do.has(c)||!i())return;if(Do.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",s),n.addEventListener("turbo:before-visit",a),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",s),n.removeEventListener?.("turbo:before-visit",a),Zt.delete(n)}},Zt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Jc(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 Hc(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 sn(e){zc(e),Uc(e)}function zc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(nn);else setTimeout(nn,0);return}let r=async(o)=>{await n(o),nn()};r.__reactiveDismissWrapped=!0,t.render=r}function nn(){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 Gc=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),rn=Object.freeze(["fade","slide","scale","highlight","shake"]),on="data-reactive-fx-pending",an=1000;function Uc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Gc[r?.getAttribute?.("action")];if(!o||Yc())return;let i=Kc(r,o);if(!i)return;let s=o==="exit"?async(a)=>{await Qc(Oe(r),i),await n(a)}:async(a)=>{let c=o==="enter"?Xc(r):null;if(await n(a),o==="enter")Zc(c,i);else jo(Oe(r),i)};s.__reactiveEffectsWrapped=!0,t.render=s}function Kc(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return Wo(n,t);let o=(t==="enter"?Vc(e):Oe(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Wo(o,t):null}function Oe(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Vc(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Wo(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"?rn[Math.floor(Math.random()*rn.length)]:e;if(!rn.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Yc(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Xc(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(on,"");return Oe(e)}function Zc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${on}]`)))n.removeAttribute(on),jo(n,t)}async function Qc(e,t){if(!e?.classList)return;if(t.legs){await Bo(e,t.legs);return}e.classList.add(t.className);let n=cn(e);if(n<=0){e.classList.remove(t.className);return}await un(e,n),e.classList.remove(t.className)}function jo(e,t){if(!e?.classList)return;if(t.legs){Bo(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=cn(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;un(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Bo(e,t){let[n,r,o]=t.map(eu),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await tu(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let s=cn(e);if(s>0)await un(e,s);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function eu(e){return String(e??"").split(/\s+/).filter(Boolean)}function cn(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((s,a)=>Math.max(s,parseFloat(a)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,an)}catch{return 0}}function un(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,an))})}function tu(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},an),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var nu="phlex-reactive:latency",ln=!1;function zo(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"),ln=!1}function dn(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:zo,disableLatencySim:Go}}function pn(){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(!ln)ln=!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 Ho=new WeakMap;function mn(e){let t=globalThis.document;if(!t)return!0;let n=Ho.get(t);if(!n)n=new Set,Ho.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function fn(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function ru(e,t){try{return e?.matches?.(t)===!0}catch{return!1}}function Uo(e,t,n,r){if(mn(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function hn(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o=r==="@trigger"?" — a server-pushed op has no trigger element":"";if(!o&&n&&!t.global){let i=fn(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}Uo(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function gn(e){if(!mn(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function bn(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i=o==="@trigger"?" — this run has no trigger element":"";if(!i&&!n.global)if(ru(r,o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(fn(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let s=fn(globalThis.document,o);if(s>0)i=` — it matches ${s} element(s) outside this scope; use global: true`}Uo(t,o,`scoped to #${r?.id||"?"}`,i)}function vn(e,t){let n=e.element?.id||"?";if(mn(`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 ou(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]??"?",s=o.match(/\btarget="([^"]*)"/)?.[1];t.push(s?`${i} → #${s}`:i)}return t}function yn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,a=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(a),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 Ne(e,t,n){e.streams=ou(t),e.tokenRefreshed=n!=null}var Fe=new WeakMap;function wn(e,t,n,r){let o=n&&typeof n==="object"?au(n):n;return o?Vo(t,o,r,!1):[]}function An(e,t,n,r){if(!n)return null;let o=Vo(t,n,r,!0);return o.length?o:null}function Vo(e,t,n,r){let o=[];for(let i of Yo(e,t,n)){if(t.add_class){let s=t.add_class.filter((a)=>!i.classList.contains(a));if(i.classList.add(...s),s.length)o.push(()=>i.classList.remove(...s))}if(t.remove_class){let s=t.remove_class.filter((a)=>i.classList.contains(a));if(i.classList.remove(...s),s.length)o.push(()=>i.classList.add(...s))}if(t.toggle_class)t.toggle_class.forEach((s)=>i.classList.toggle(s)),o.push(()=>t.toggle_class.forEach((s)=>i.classList.toggle(s)));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(iu(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Yo(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 iu(e,t){let n=Fe.get(t);if(n)n.count++;else Fe.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()=>su(t,e)}function su(e,t){let n=Fe.get(e);if(!n)return;if(--n.count>0)return;if(Fe.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function au(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=Yo(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((s)=>s.isConnected&&!s.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 U;function _n(e){U=e}var O=new Map;function ei(e,t){let n=!O.has(e);if(O.set(e,t),n)U.enter()}function $e(e){if(O.delete(e))U.exit()}var Zo=!1;function kn(e){ti();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){pu(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;ce(t,n)}function ti(){if(Zo||typeof document>"u"||!document.addEventListener)return;Zo=!0,document.addEventListener("turbo:before-stream-render",hu,!0),document.addEventListener("turbo:before-stream-render",cu)}function cu(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(O.get(n)?.via==="stream")$e(n)}function ce(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}Rn(e),ii(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return ei(e,r),mu(e,r,t)}function uu(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[bu(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":vu()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function ni(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(ri(t))return{src:t};return console.error(lu(t)),fu(t)||du(e)}function lu(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Tn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function fu(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Tn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&ri(r))return{src:r,fallback:!0}}function du(e){U.fail({kind:"defer",root:e.id}),Rn(e.id),Ln(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 ri(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Tn()}/`)}catch{return!1}}function Tn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function pu(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){ce(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}Rn(e),ii(n);let o=document.createElement("pgbus-stream-source");o.id=oi(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),ei(e,{via:"stream"})}function oi(e){return`reactive-defer-src-${e}`}async function mu(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},yu()),o;try{U.count("defer"),o=await fetch(...uu(n,t.abort.signal))}catch(a){if(clearTimeout(r),O.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",a),ae(e,n);return}if(O.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),ae(e,n,o.status);return}if(o.status===204){clearTimeout(r),Qo(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),ae(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}"`),ae(e,n,o.status);return}let s;try{s=await o.text()}catch(a){if(clearTimeout(r),O.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",a),ae(e,n);return}if(clearTimeout(r),O.get(e)!==t)return;Qo(e),gu(s)}var xn=null,hu=(e)=>xn?.push(e);function gu(e){let t=xn=[];try{window.Turbo.renderStreamMessage(e)}finally{xn=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 Rn(e){let t=O.get(e);if(!t)return;if($e(e),t.via==="fetch")t.abort.abort();else document.getElementById(oi(e))?.remove?.()}function ii(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Ln(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Qo(e){$e(e);let t=document.getElementById(e);if(!t)return;Ln(t),t.removeAttribute("data-reactive-error")}function ae(e,t,n){U.fail({kind:"defer",status:n,root:e}),$e(e);let r=document.getElementById(e);if(!r)return;Ln(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"),ce(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function bu(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function vu(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function yu(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var si="__materialize",Me=new WeakMap;function Ce(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function On(e,t,n){ti();let r=e.element,o=!1,i=!1,s=null,a=null,c,u,l=()=>Pe(e),f=(m)=>{if(Ce(r)==="visible"){if(!s)p()}else if(m){let w=r.getAttribute("data-reactive-lazy-on");if(a===w)return;d(),r.addEventListener?.(w,l),a=w}},d=()=>{if(s?.disconnect(),s=null,a)r.removeEventListener?.(a,l);a=null},p=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let m=r.getAttribute("data-reactive-lazy-visible")||"0px";s=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:m}),s.observe(r)},h=()=>{let m=Ce(r)!==null,w=o;if(o=m,!m)return d();if(i)return;if(t.forgetToken(),!w)return l();f(!0)};if(Me.set(e,{load(){if(i)return;let m=ni(r);if(!m&&r.getAttribute("data-reactive-defer-src")!=null)return;if(m&&wu(r,t))return;let w=m?ce(r.id,m):t.proceed(r,si,"{}");if(!w)return;i=!0,d();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);d()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&Ce(r)===null)En(r),c=(m)=>m.target===r&&En(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=(m)=>{if(m.target!==r)return;if(!c)En(r);h()},r.addEventListener?.("turbo:morph-element",u),n)return h();if(o=Ce(r)!==null,o)f(!1)}function Nn(e){let t=Me.get(e);Me.delete(e),t?.off()}function Pe(e){return Me.get(e)?.load()}function wu(e,t){return t.emit("reactive:before-dispatch",{action:si,params:{},element:e},{cancelable:!0}).defaultPrevented}function En(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||ni(e);if(t)ce(e.id,t)}var Fn=new WeakMap,De=new WeakMap,g=null,j,ci;function Pn(e,t){let n=e.element;De.set(n,t),bi();let r=(i)=>Su(i,t),o=(i)=>Tu(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Fn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function In(e){if(Fn.get(e)?.(),Fn.delete(e),De.delete(e.element),g&&qe(g.origin)===e.element)Ie()}var x=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),ue=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},qe=(e)=>e?.closest?.('[data-controller~="reactive"]'),di=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),P=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&di(t)===e),ui=(e)=>ue(x(e,"-item"),null),Cn=(e)=>x(e,"-disabled")==="true",Au=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},pi=(e)=>{let t=x(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>x(n,"-group")===t&&!Cn(n)&&De.has(qe(n)))};function mi(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&di(n);if(g||!r||!t.owns(r)||Cn(r)||Cn(n))return;if(qe(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Su(e,t){if(e.button>0||e.isPrimary===!1)return;let n=mi(e.target,t);if(!n)return;let r=x(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,s=(m)=>m.pointerId===e.pointerId,a=e.pointerType==="touch",c=!a,u=a&&setTimeout(()=>c=!0,200),l=(m)=>{if(!s(m))return;if(g)return Mn(m.clientX,m.clientY);if(Math.abs(m.clientX-o)<=4&&Math.abs(m.clientY-i)<=4)return;if(!c)return v();xu(n,t,m),Mn(m.clientX,m.clientY)},f=(m)=>g&&m.cancelable&&m.preventDefault(),d=(m)=>{if(!s(m))return;if(v(),g)Eu(),$n()},p=(m)=>{if(m.type==="pointercancel"&&!s(m))return;if(v(),g)Ie()},b=[["pointermove",l],["pointerup",d],["pointercancel",p],["keydown",(m)=>m.key==="Escape"&&g&&(m.preventDefault(),p(m))],["touchmove",f,{passive:!1}]];for(let[m,w,A]of b)document.addEventListener(m,w,A);function v(){clearTimeout(u);for(let[m,w]of b)document.removeEventListener(m,w)}}function Eu(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function xu({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),s=i?e.cloneNode(!0):e;if(i){for(let c of[s,...s.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(s)}let a=document.createElement(e.tagName);if(a.setAttribute("data-reactive-sortable-placeholder",""),a.setAttribute("aria-hidden","true"),a.style.height=`${o.height}px`,g=hi({core:n,item:e,row:s,origin:t,source:i,placeholder:a,style:s.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(a);Object.assign(s.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 hi(e){let{row:t,origin:n,source:r}=e;return e.index=P(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),le(n,!0),e}var le=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function We(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 Mn(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=pi(g.origin).find((r)=>Au(r,e,t));if(n)_u(n,e,t);else if(g.source)Dn(null),g.placeholder.remove();ku(e,t)}function Dn(e){if(g.target!==g.origin)le(g.target,!1);g.target=e,le(e,!0)}function _u(e,t,n){Dn(e);let r=P(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),s=i&&o.top===i.top&&o.left!==i.left,a=r.findIndex((c)=>{let u=c.getBoundingClientRect();return s?t<u.left+u.width/2:n<u.top+u.height/2});We(e,r,a<0?r.length:a,g.placeholder)}function ku(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);Mn(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function Tu(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":$n,Enter:$n,Escape:Ie,Tab:Ie,ArrowUp:()=>li(-1),ArrowDown:()=>li(1),ArrowLeft:()=>fi(-1),ArrowRight:()=>fi(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=mi(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),g=hi({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Be("picked")}function li(e){let t=P(g.target),n=je()+e;if(n>=0&&n<=t.length)We(g.target,t,n,g.row);gi()}function fi(e){let t=pi(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=je();Dn(n),We(n,P(n),r,g.row)}gi()}function gi(){g.row.focus?.(),Be("moved")}function je(){let e=P(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function bi(){if(!j?.isConnected)j=document.createElement("div"),j.setAttribute("aria-live","polite"),j.setAttribute("data-reactive-sortable-live",""),j.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(j);return j}function Be(e){let t=g.target??g.origin,n=(ue(x(t,"-messages"),{})[e]??"").replaceAll("{position}",je()+1).replaceAll("{count}",P(t).length+1),r=bi();r.textContent="",cancelAnimationFrame(ci),ci=requestAnimationFrame(()=>r.textContent=n)}function $n(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,s=t&&(r?i.isConnected:!0),a=s?je():-1,c=s?ui(P(t)[a-1]):null;if(e.keyboard)Be("dropped");if(!r&&i)i.replaceWith(o);if(yi(e),!s||t===n&&a===e.index)return;let u=t===n?"self":r?x(n,"-source"):x(n,"-name")??"list",l=ue(x(t,"-from"),{})[u]??x(t),f={...ue(x(t,"-params"),{}),item:ui(e.item),position:a,after:c,from:u},d=[];for(let h=t;h;h=h.parentElement)d.push(h);let p=De.get(qe(t))?.proceed(t,l,JSON.stringify(f),ue(x(t,"-busy")));if(r)return;Promise.resolve(p).then((h)=>Ru(h,d)||vi(e))}function Ru(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"))&&Lu(r,t))}function Lu(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 Ie(){let e=g;if(e.keyboard)Be("cancelled");e.placeholder?.remove(),yi(e),vi(e)}function vi({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(We(t,P(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function yi(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:s}=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(s?.remove(),le(n,!1),le(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var xi={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},_i={x:"left",y:"top",width:"width",height:"height"},qn=new WeakMap,Bn=new WeakMap,y=null,B,Ai,Si=!1;function Jn(e,t){let n=e.element;Bn.set(n,t),$i(),Wu();let r=[["pointerdown",(o)=>$u(o,t,n)],["keydown",(o)=>qu(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&xi[o.key]&&jn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&jn()],["input",(o)=>Ei(o,t,n)],["change",(o)=>Ei(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);qn.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Hn(e){if(qn.get(e)?.(),qn.delete(e),Bn.delete(e.element),y?.root===e.element)V(y)}var R=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e)=>Math.round(e*1e4)/1e4;function Ou(e,t=1){let n=N(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function zn(e){let t={x:N(e.x),y:N(e.y)};if(e.width!=null)t.width=N(e.width),t.height=N(e.height),t.x=Math.min(t.x,N(1-t.width)),t.y=Math.min(t.y,N(1-t.height));return t}function ki(e,t,n){return{x:R(e.x+t,0,1-e.width),y:R(e.y+n,0,1-e.height),width:e.width,height:e.height}}function Ti(e,t,n){return{x:R(e.x+t,0,1),y:R(e.y+n,0,1)}}function Ri(e,t,n,r,o,i){let[s,a,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,f=e.y+e.height,d=e.x+e.width/2,p=e.y+e.height/2,h=a?1-e.x:u?l:i?2*Math.min(d,1-d):1,b=c?1-e.y:s?f:i?2*Math.min(p,1-p):1,v=e.width+(a?n:u?-n:0),m=e.height+(c?r:s?-r:0);if(i){let w=(a||u)&&(!(s||c)||Math.abs(v-e.width)>=Math.abs(m-e.height)*i),A=Math.min(h,b*i);v=R(w?v:m*i,Math.min(Math.max(o,o*i),A),A),m=v/i}else{if(a||u)v=R(v,Math.min(o,h),h);if(s||c)m=R(m,Math.min(o,b),b)}return{x:u?l-v:a?e.x:d-v/2,y:s?f-m:c?e.y:p-m/2,width:v,height:m}}function Nu(e,t,n){let r=Math.min(1,t),o=R(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:R(e.x+e.width/2-o/2,0,1-o),y:R(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function Fu(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 k=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Gn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},F=(e)=>e.matches("[data-reactive-point]")?"point":"box",Li=(e)=>Number(k(e,`${F(e)}-scale`))||1,K=(e)=>F(e)==="point"?["x","y"]:["x","y","width","height"];function Oi(e){let t={};for(let n of K(e))t[n]=(parseFloat(e.style[_i[n]])||0)/100;return t}function Je(e,t){for(let n of K(e))e.style[_i[n]]=`${Math.round(t[n]*1e4)/100}%`}function Un(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 Cu(e,t){try{return e.parentElement.closest(k(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function Ni(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function Fi(e,t,n){let r=Gn(k(e,F(e)),{}),o={};for(let i of K(e)){let[s]=Ni(t,n,r[i]);if(s)o[i]=s}return o}function Mu(e,t,n,r){let o=k(e,"box-aspect"),i=o&&Ni(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),s=o?Fu(i?.value):Number(k(e,"box-ratio"))||0,{width:a,height:c}=Un(t);return s&&a&&c?s*c/a:0}function Kn(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 s=Oi(o),a=Fi(o,t,e),c=F(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?Cu(o,i):i,edge:k(n,"box-handle"),start:s,value:s,ratio:c?0:Mu(o,i,t,e),min:Number(k(o,"box-min"))||0,scale:Li(o),fields:a,before:Object.fromEntries(Object.entries(a).map(([u,l])=>[u,l.value]))}}function Ci(e,t,n,r){let o=Ou(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function fe(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))Ci(e.core,n,e.value[t],e.scale)}function $u(e,t,n){if(Mi(),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)&&Kn(t,n,r,!1);if(!o)return;let{clientX:i,clientY:s}=e,a=Un(o.bounds);o.p0=[(i-a.left)/a.width,(s-a.top)/a.height];let c=(b)=>b.pointerId===e.pointerId,u=(b)=>{if(!c(b)||o.over)return;if(y)return Wn(b.clientX,b.clientY);if(Math.abs(b.clientX-i)<=4&&Math.abs(b.clientY-s)<=4)return;Iu(o),Wn(b.clientX,b.clientY)},l=(b)=>{if(!c(b))return;if(h(),y)Pu(),jn()},f=(b)=>{if(b.type==="pointercancel"&&!c(b))return;if(h(),y)Di()},p=[["pointermove",u],["pointerup",l],["pointercancel",f],["keydown",(b)=>b.key==="Escape"&&y&&(b.preventDefault(),f(b))]];for(let[b,v]of p)document.addEventListener(b,v);function h(){for(let[b,v]of p)document.removeEventListener(b,v)}}function Pu(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Iu(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 Wn(e,t){let n=y;if(!n.el.isConnected)return V(n);n.x=e,n.y=t;let r=Un(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:s,edge:a}=n;n.value=zn(F(n.el)==="point"?Ti(s,o,i):a?Ri(s,a,o,i,n.min,n.ratio):ki(s,o,i)),Je(n.el,n.value),n.writing||=requestAnimationFrame(()=>fe(n)),Du(t)}function Du(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),Wn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function Mi(){if(y&&!y.el.isConnected)V(y)}function qu(e,t,n){Mi();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(),Di());let o=xi[e.key];if(!o)return;if(e.preventDefault(),y??=Kn(t,n,r,!0),!y)return;let[i,s]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),a=e.altKey&&F(y.el)==="box",c=y.value;y.value=zn(F(y.el)==="point"?Ti(c,i,s):a?Ri(c,y.edge??"se",i,s,y.min,y.ratio):ki(c,i,s)),Je(y.el,y.value),fe(y),Pi(y,a?"resized":"moved")}function $i(){if(!B?.isConnected)B=document.createElement("div"),B.setAttribute("aria-live","polite"),B.setAttribute("data-reactive-drag-live",""),B.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(B);return B}function Pi(e,t){let n=Gn(k(e.el,`${F(e.el)}-messages`),{})[t]??"";for(let o of K(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=$i();r.textContent="",cancelAnimationFrame(Ai),Ai=requestAnimationFrame(()=>r.textContent=n)}function Ei(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(k(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=Kn(t,n,o,!0),{ratio:s,start:a}=i??{};if(!s||Math.abs(a.width/a.height/s-1)<0.005)continue;i.value=zn(Nu(a,s,i.min)),Je(o,i.value),fe(i),Ii(i)}}function jn(){let e=y;if(!e.el.isConnected)return V(e);fe(e),V(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=F(e.el),n=k(e.el,`${t}-action`),r={};for(let o of K(e.el))r[o]=N(e.value[o]);if(!n||K(e.el).every((o)=>r[o]===N(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Gn(k(e.el,`${t}-busy`)))}function Di(){let e=y;if(e.value=e.start,Je(e.el,e.start),fe(e),e.keyboard)Pi(e,"cancelled");V(e)}function V(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 Wu(){if(Si)return;Si=!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=Bn.get(n);if(!r?.owns(t))return;let o=Oi(t),i=Li(t);for(let[s,a]of Object.entries(Fi(t,n,r)))Ci(r,a,o[s],i)})}var I=new Map,Wi=new WeakSet,ji=!1;function Vn(e,t){if(!ji)ji=!0,document.addEventListener("turbo:morph",Bi),document.addEventListener("turbo:render",Bi);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,zi(n);let o=(s)=>s.target===n&&queueMicrotask(()=>Hi(r)),i=(s)=>s.target===n&&s.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,s.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)},Hi(r)}function Yn(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 Xn(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},Gi(n)}function Bi(){for(let e of I.values())if(e.core&&!e.removing&&e.root.isConnected)zi(e.root)}function zi(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&Wi.has(n))return;if(n?.remove(),!Ji())setTimeout(()=>{if(!Ji())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;Gi(o),Bu(o)}),Wi.add(r),ju().appendChild(r)}function ju(){let e=[...document.body.children].find((t)=>t.localName==="reactive-stream-sources");if(!e)e=document.createElement("reactive-stream-sources"),e.hidden=!0,e.setAttribute("data-turbo-permanent",""),document.body.appendChild(e);return e}var Ji=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Bu(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&&Ui(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 Gi(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 Ui(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 Hi(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=Ui(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 s=e.seats;if(e.seats=o,!s)return;let a=[...o].filter((u)=>!s.has(u)),c=[...s].filter((u)=>!o.has(u));if(a.length||c.length)e.core.emit("reactive:presence",{joined:a,left:c,me:n??null})}var He=new Map,de=new Map,Zi=new WeakMap,Qi=new WeakSet,Vi=!1;function Qn(e){if(!Vi)Vi=!0,document.addEventListener("turbo:morph",Yi),document.addEventListener("turbo:render",Yi);let t=e.element,n=de.get(t.id);if(!n)de.set(t.id,n={id:t.id,src:null});Zi.set(t,n),n.observer?.disconnect(),n.root=t,n.removing=!1;for(let r of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source]"))if(!Qi.has(r))r.remove();Zn(n,t.getAttribute("data-reactive-subscribe")),n.observer=new MutationObserver(()=>Zn(n,t.getAttribute("data-reactive-subscribe"))),n.observer.observe(t,{attributes:!0,attributeFilter:["data-reactive-subscribe"]})}function er(e){let t=e.element,n=Zi.get(t);if(!n||n.root!==t)return;n.observer.disconnect(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;de.delete(n.id),Zn(n,null)})}function Zn(e,t){let n=e.src;if(e.src=t||null,e.src)es(e.src,e.id);if(n&&n!==e.src)Ju(n,e.id)}function Yi(){for(let e of de.values())if(e.src&&!e.removing&&e.root.isConnected)es(e.src,e.id)}function es(e,t){let n=He.get(e);if(!n)He.set(e,n={source:null,ids:new Set,connected:!1});if(n.ids.add(t),!n.source?.isConnected)n.source=Hu(e,n)}function Ju(e,t){let n=He.get(e);if(!n)return;if(n.ids.delete(t),n.ids.size)return;He.delete(e),n.source.remove()}function Hu(e,t){if(!Xi())setTimeout(()=>{if(!Xi())console.error('[phlex-reactive] reactive_subscribe needs the pgbus client (<pgbus-stream-source>) on this page: import "pgbus/stream_source_element"')},5000);let n=document.createElement("pgbus-stream-source");n.setAttribute("src",e),n.setAttribute("data-reactive-subscribe-source",""),n.hidden=!0;let r=zu(e);if(r!=null)n.setAttribute("since-id",String(r));return n.addEventListener("pgbus:connected",(o)=>{if(t.source!==n)return;let i=t.connected;t.connected=!0;let s=o.detail?.connectionId??null;for(let a of t.ids){let c=de.get(a);if(!c||c.removing||c.src!==e||!c.root.isConnected)continue;c.root.dispatchEvent(new CustomEvent("reactive:subscribed",{detail:{connectionId:s,reconnect:i}}))}}),Qi.add(n),Gu().appendChild(n),n}function zu(e){let t=null;for(let n of document.querySelectorAll("[data-reactive-subscribe-since]")){if(n.getAttribute("data-reactive-subscribe")!==e)continue;let r=Number(n.getAttribute("data-reactive-subscribe-since"));if(Number.isFinite(r)&&r>=0&&(t==null||r<t))t=r}return t}function Gu(){let e=[...document.body.children].find((t)=>t.localName==="reactive-stream-sources");if(!e)e=document.createElement("reactive-stream-sources"),e.hidden=!0,e.setAttribute("data-turbo-permanent",""),document.body.appendChild(e);return e}var Xi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");var ns=new Map,tr=new WeakMap,Uu=0,ze=new WeakMap;function nr(e,t){let n=e.element;if(!n.id&&!tr.has(n))tr.set(n,`#${++Uu}`);let r=n.id||tr.get(n),o=new Map,i=!1,s=(p)=>{clearTimeout(o.get(p)),o.delete(p)},a=(p,h,b)=>{s(p);let v=Date.parse(h.until)-Date.now();if(!(v>0))return c(p,h,b);let m=Math.ceil(v/1000);rs(p,`${Math.floor(m/60)}:${String(m%60).padStart(2,"0")}`,"running"),u(h.waiting,!0),u(h.done,!1),o.set(p,setTimeout(()=>a(p,h,b),(v-1)%1000+1))},c=(p,h,b)=>{rs(p,"0:00","done"),u(h.waiting,!1),u(h.done,!0);let v=ns.get(b)??new Set;if(v.has(h.until))return;ns.set(b,v.add(h.until)),p.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:h.until}}))},u=(p,h)=>{let b;try{b=p&&n.querySelector(p)}catch{}if(b&&b.hidden===h)b.hidden=!h},l=()=>{if(i=!1,!ze.has(e))return;let p=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((b,v)=>{if(!t.owns(b))return;let m;try{m=JSON.parse(b.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(m?.until)))return;p.add(b),a(b,m,`${r}|${b.id||v}`)});for(let b of o.keys())if(!p.has(b))s(b)},f=()=>{if(i)return;i=!0,queueMicrotask(l)},d=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",f),n.addEventListener("reactive:streamed",f),document.addEventListener("visibilitychange",d),ze.set(e,()=>{n.removeEventListener("turbo:morph-element",f),n.removeEventListener("reactive:streamed",f),document.removeEventListener("visibilitychange",d);for(let p of[...o.keys()])s(p)}),l()}function rr(e){ze.get(e)?.(),ze.delete(e)}function rs(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 Vu(){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 Yu(){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)}}var Xu=["focus","focus_first","blur"];function Zu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=jr(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)gn(n);return}let i=(a)=>Rr(a,(c)=>cf(c,o),r?(c,u)=>hn(c,u,o):void 0),s=t.findIndex((a)=>Xu.includes(a?.[0]));if(s<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,s)),requestAnimationFrame(()=>i(t.slice(s)))}}function Qu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){kn(this)}}var ss=!1,el=null;function tl(){if(ss)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ss=!0,document.addEventListener("turbo:before-stream-render",(e)=>{gl(e),rl(e),il(e),sn(e)})}var Ye="reactive:streamed",or=new WeakMap,nl=0;function Ge(e){return!!e?.isComposing||e?.keyCode===229}function rl(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 s=r.getAttribute("target"),a=r.getAttribute("targets"),c=new Set;for(let u of s?[document.getElementById(s)]:a?document.querySelectorAll(a):[]){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(Ye))}}function Nr(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function Fr(e){try{return e.matches(":modal")}catch{return!1}}function qs(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||Fr(e))return;if(e.open)e.close();e.showModal()}function ol(e){if(Nr(e)&&e.open)e.close()}function nt(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&&!Fr(r))qs(r)}function il(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),nt(document)}}var as=!1;function sl(){if(as)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;as=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))nt(t.target)}),document.addEventListener("turbo:morph",()=>nt(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||!Fr(n))return;e.delete(n),t.preventDefault(),n.close()})}var wr=new WeakMap;function Ws(e,t,n,r){let o=wr.get(e)??new Map;wr.set(e,o);let i=(s,a)=>{o.delete(s),o.set(s,a)};if(t.endsWith("_class"))for(let s of n.classes??[])i(`.${s}`,e.classList.contains(s));else if(t.endsWith("_attr"))sa(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 s of r({...n,to:n.expanded}))Ws(s,"set_attr",{name:"aria-expanded"})}}var cs=!1;function al(){if(cs)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;cs=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of wr.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 Cr="data-reactive-image-fallback",Q="data-reactive-image-state",Ar="data-reactive-image-hidden",ir=null,Sr="data-reactive-wrap-hidden";function js(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(Sr,"")}function Bs(e){if(!e.hasAttribute(Sr))return;e.removeAttribute("hidden"),e.removeAttribute(Sr)}function ve(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Cr);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Js=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Mr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Hs(e,t){let n=Mr(e,t.alt);return n&&!n.contains(e)?n:null}function rt(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Ar,"");if(t.wrap){let o=Mr(e,t.wrap);if(o)js(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=Hs(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else ut(e,t);e.setAttribute(Q,n)}function ut(e,t=ve(e)){if(!t||e.getAttribute(Q)==null)return;if(e.getAttribute(Q)==="error"){if(e.hasAttribute(Ar))e.removeAttribute("hidden");let n=Mr(e,t.wrap);if(n)Bs(n);let r=Hs(e,t);if(r)r.hidden=!0}e.removeAttribute(Q),e.removeAttribute(Ar)}function us(e){let t=e.target,n=ve(t);if(!n)return;if(e.type==="load")rt(t,n,"loaded");else if(Js(t))rt(t,n,"error");else ut(t,n)}function cl(){if(ir)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;ir={error:us,load:us,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(Q);if(o==null||!r||!ve(n))return;let i=(s)=>n.getAttribute(s)===r.getAttribute?.(s);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=ve(n);if(o)rt(n,o,r)})},"turbo:frame-render":(t)=>Ue(t.target),"turbo:render":()=>Ue(document),"turbo:before-stream-render":(t)=>{let n=t.detail,r=n?.render,o=n?.newStream??t.target;if(typeof r!=="function"||!o?.querySelector?.("template")?.content?.querySelector?.(`img[${Cr}]`))return;n.render=async(i)=>{await r(i),Ue(document)}}};for(let[t,n]of Object.entries(ir))document.addEventListener(t,n,!0);Ue(document)}function Ue(e){for(let t of e?.querySelectorAll?.(`img[${Cr}]`)??[]){if(t.getAttribute(Q)!=null||!t.complete||!Js(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&rt(t,ve(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 Ff(e){el=e}var Ke,sr=null,ls="[data-reactive-editable][contenteditable=plaintext-only]";function zs(){if(Ke===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Ke=e.contentEditable==="plaintext-only"}catch{Ke=!1}return Ke}function Xe(e){if(e.matches?.(ls))e.setAttribute("contenteditable","true");e.querySelectorAll?.(ls).forEach(Xe)}function ul(){if(sr||typeof document>"u"||typeof document.createElement!=="function")return;if(zs())return;Xe(document),sr=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Xe(t.target);else t.addedNodes.forEach(Xe)}),sr.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var fs=!1;function ds(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 ll(){if(fs)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;fs=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=ds(t);if(r)dl(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(it.set(t,z(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==L)t.removeAttribute(i);for(let{name:i,value:s}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==s)t.setAttribute(i,s);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)=>qr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===L)&&ds(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(L)&&Pr(t)===Ir(t))t.removeAttribute(L)})}var L="data-reactive-held",$r='[data-controller~="reactive"]',Ze=null,Z=new Map;function Pr(e){return e.hasAttribute("data-reactive-editable")?z(e):e.value}function Ir(e){return e.hasAttribute("data-reactive-editable")?Wr(e):e.defaultValue}function fl(e){if(e.hasAttribute("data-reactive-editable"))return z(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function dl(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||Z.has(e.closest($r)))return;let r=fl(t);if(r===Pr(e))return e.removeAttribute(L);if(r===Ir(e))return;e.setAttribute(L,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function pl(e){let t=[];for(let n of e.querySelectorAll(`[${L}]`)){if(n.closest($r)!==e)continue;let r=n.getAttribute("name");if(Pr(n)===Ir(n))n.removeAttribute(L);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 Gs(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${L}]`))if(n.closest($r)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(L)}function ml(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 ps(e,t,n=null,r=30000){let o={root:e,streams:0,keep:n,events:[]},i=Ze;Ze=o;try{window.Turbo.renderStreamMessage(t)}finally{Ze=i}if(o.streams===0)Gs(e,n);let s=o.events.filter((l)=>!l.event.defaultPrevented).map((l)=>l.done),a=s.length>0?Promise.all(s).then((l)=>l.find(Boolean)):hl(),c,u=new Promise((l)=>c=setTimeout(l,r));return Promise.race([a,u]).finally(()=>clearTimeout(c))}function hl(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function gl(e){let t=Ze,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++;let o;t.events.push({event:e,done:new Promise((i)=>o=i)}),n.render=async(i)=>{Z.set(t.root,(Z.get(t.root)||0)+1);let s;try{return await r(i)}catch(a){throw s=a,a}finally{let a=Z.get(t.root)-1;if(a)Z.set(t.root,a);else Z.delete(t.root);Gs(t.root,t.keep),o(s)}}}var ms="__materialize",hs=!1;function bl(){if(hs)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;hs=!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 Dr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")dn()}var Us="data-reactive-active",Er="data-reactive-errors",S=0,H=[];function Ks(){if(S++,S===1)H=[],Ys("reactive:busy")}function me({action:e=null,kind:t,status:n=null,root:r=null}){if(S===0)return;H.push({action:e??null,kind:t,status:n??null,root:r||null})}function Vs(){if(S===0)return;if(S--,S===0){let e=H;Ys("reactive:idle"),El(e)}}function Cf(){return S}function Mf(){S=0,H=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(Us),e?.removeAttribute?.(Er)}function Ys(e){if(typeof document>"u")return;let t=document.documentElement,n=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(Us,S>0),n&&H.length>0)t.setAttribute(Er,JSON.stringify(H));else t.removeAttribute(Er);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let r=n?{count:S,errors:H.slice()}:{count:S};document.dispatchEvent(new CustomEvent(e,{detail:r}))}}var vl="data-reactive-debouncing",C=new Set,D=[];function yl(e){if(C.add(e),C.size===1)Xs()}function wl(e){if(!C.delete(e)||C.size>0)return;Xs(),queueMicrotask(Zs)}function Xs(){(typeof document<"u"?document.documentElement:null)?.toggleAttribute?.(vl,C.size>0)}function $f(){return C.size}function Al(){for(let e of[...C])if(C.has(e))e()}var lt=()=>S===0&&C.size===0;function Sl({timeout:e}={}){if(lt())return Promise.resolve({count:0,errors:[]});return new Promise((t)=>{let n={resolve:t,errors:[],timer:null};if(Number(e)>0)n.timer=setTimeout(()=>{D=D.filter((r)=>r!==n),t({count:S,errors:n.errors,timedOut:!0})},Number(e));D.push(n)})}function El(e){if(D.length===0)return;for(let t of D)t.errors.push(...e);Zs()}function Zs(){if(!lt()||D.length===0)return;let e=D;D=[];for(let t of e)clearTimeout(t.timer),t.resolve({count:0,errors:t.errors})}function Qs(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:30000}var gs="data-reactive-await-settled",he="data-reactive-awaiting",ar=new WeakSet,cr=null,ot=0,bs=0,J=(e)=>e?.hasAttribute?.(gs)===!0&&e.getAttribute(gs)!=="false";function xl(e,t){let n=e.getAttribute("id"),r=n?null:e.parentElement?.closest?.("[id]");return()=>{let i=(n?[document.getElementById(n)]:Array.from((r&&document.getElementById(r.getAttribute("id"))?.querySelectorAll(e.tagName))??[])).filter((s)=>s?.tagName===e.tagName&&t(s));return i.length===1?i[0]:null}}var xr=(e)=>[e.tagName,e.type,e.name,e.value,e.getAttribute("formaction"),e.getAttribute("formmethod")].join("\x00");function vs(e,t,n){if(t.isConnected&&t.form===e&&xr(t)===n)return t;let r=Array.from(e.elements).filter((o)=>xr(o)===n);return r.length===1?r[0]:null}function ea(e,t){let n=ot;return Al(),Sl({timeout:e*2}).then(({errors:r,timedOut:o})=>t(!o&&r.length===0&&n===ot))}function ta(e,t,n,r){if(ar.has(t)||lt())return;if(e.preventDefault(),e.stopImmediatePropagation(),t.hasAttribute(he))return;let o=++bs,i=xl(t,n);ea(Qs(),(s)=>{t.removeAttribute(he);let a=t.isConnected&&n(t)?t:i();if(!s||o!==bs||!a)return;ar.add(a);try{r(a)}finally{ar.delete(a)}}),t.setAttribute(he,"")}function _l(e){if(e.defaultPrevented)return;let t=e.target;if(t?.tagName!=="FORM")return;let n=e.submitter??null,r=J(t);if(!r&&!J(n))return;let o=(c)=>[c.getAttribute("action"),c.getAttribute("method")].join("\x00"),i=o(t),s=n&&xr(n);ta(e,t,(c)=>o(c)===i&&(r?J(c):J(vs(c,n,s))),(c)=>{if(!n)return c.requestSubmit();let u=vs(c,n,s);if(u)c.requestSubmit(u)})}function kl(e){if(e.defaultPrevented||e.button!==0)return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.("a[href]");if(!t||!J(t)||t.hasAttribute("download"))return;let n=t.getAttribute("target");if(n&&n!=="_self")return;let r=t.getAttribute("href");ta(e,t,(i)=>i.getAttribute("href")===r&&J(i),(i)=>i.click())}function Tl(){if(cr)return;if(typeof window>"u"||typeof window.addEventListener!=="function")return;let e=()=>ot++;cr={submit:_l,click:kl,"turbo:before-prefetch":(t)=>J(t.target)&&t.preventDefault(),"turbo:visit":e,"turbo:before-render":e};for(let[t,n]of Object.entries(cr))window.addEventListener(t,n,!0)}var na="data-reactive-requests";function ra(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Rl(t))return;let n=Ll(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(na,JSON.stringify(n))}function Rl(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Ll(e){try{let t=JSON.parse(e.getAttribute(na));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function ys(){Vu(),Yu(),Zu(),Qu(),tl(),ll(),sl(),al(),Bl(),cl(),Tl(),ul(),bl(),Dr()}function Ol(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var oa=Symbol.for("phlex-reactive.core");if(globalThis[oa])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[oa]=!0;var ia=!1;function Nl(){if(ia)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(Nl,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Fl=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function sa(e){let t=String(e).toLowerCase();return t.startsWith("on")||Fl.has(t)}var ur=new WeakMap;function Cl(e,t,n){let[r,o,i]=t;ur.get(e)?.(),e.classList.add(r,o),n();let s=!1,a=requestAnimationFrame(()=>{if(s)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(s||l&&l.target!==e)return;s=!0,ur.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(a),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};ur.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Ml(e))}function Ml(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((a)=>String(n[r+a]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),s=String(n[r+"IterationCount"]).split(",").map((a)=>/inf/.test(a)?1/0:parseFloat(a)>=0?parseFloat(a):1);for(let a=0;a<o.length||a<i.length||a<s.length;a++){let c=o[a%o.length]*s[a%s.length]||0;t=Math.max(t,c+i[a%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var $l=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Pl=new Set(["lexxy-editor","trix-editor"]);function z(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 s of i.childNodes){let a=/^(div|p|li)$/.test(s.localName);if(a)n=!0;if(s.nodeType===3)s.data&&r(s.data);else if(s.localName==="br")r(`
4
4
  `);else if(s.nodeType===1)o(s);if(a)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 rt=new WeakMap;function Ir(e){if(e?.hasAttribute?.("data-reactive-editable")&&!rt.has(e))rt.set(e,H(e))}function Dr(e){return Ir(e),rt.get(e)}function Ml(e){return Cl.has(e.localName)?typeof e.value==="string":!0}var vs=Object.freeze({show:(e,t,n)=>cr(e,!1,t,n),hide:(e,t,n)=>cr(e,!0,t,n),toggle:(e,t,n)=>cr(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(ur(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(ur(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!ur(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)=>Gl(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Is(e),close_dialog:(e)=>tl(e),click:(e)=>e.click?.(),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{}ca(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)wt(r,t.group,t.checked)},presence:(e,t)=>Yn(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=$l(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)=>Pl(e),preview_file:(e,t,n)=>Il(e,t,n),set_value:(e,t)=>aa(e,String(t.value??"")),persist_state:(e,t)=>Vt(e,t.state),persist_clear:(e)=>Yt(e)});function $l(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Pl(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,sa(e),e.focus?.()}).catch(()=>{})}var ge=new Map,be=null;function Il(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Xe(`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 Xe(`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=jl(e,t.accept),s=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,a=[],c;if(t.per_file===!0&&e.multiple){let u=o.filter((f,d)=>{let p=typeof f?.type==="string"&&i(f)?s(f)&&"size":"type";if(p)a.push({reason:p,file:f,index:d});return!p}),l=a.length>0&&!Wl(e,u)?o.length:u.length;for(let f of a)f.remaining=l;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=o.filter((f)=>typeof f?.type==="string"&&i(f));c=u.find((f)=>f.type.startsWith("image/"));let l=o.length>0&&u.length===0?"type":null;if(c&&s(c))l="size";if(l)a.push({reason:l,file:l==="size"?c:o[0]}),c=null}if(ia(r),c){let u=URL.createObjectURL(c);ge.set(r,u),r.setAttribute("src",u),Bl()}else r.removeAttribute("src");if(at(r),t.wrap!=null){let u=n({...t,to:t.wrap});if(u.length===0)Xe(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let l of u)c?Ws(l):qs(l)}if(t.name!=null)for(let u of n({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)Dl(e,n({...t,to:t.rejected}),a,t.rejected);for(let u of a)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}var ot="data-reactive-file-rejected";function Dl(e,t,n,r){if(t.length===0)return Er(e,`rejected: ${JSON.stringify(r)} is not on the page`);for(let o of t){for(let s of[...o.children])if(s.hasAttribute(ot))s.remove();let i=[...o.children].find((s)=>s.localName==="template");if(!i){Er(e,`rejected: ${JSON.stringify(r)} has no <template> child`);continue}for(let{reason:s,file:a}of n){let c=i.content.cloneNode(!0);for(let u of c.querySelectorAll("[data-reactive-file-reason]"))if(u.getAttribute("data-reactive-file-reason")!==s)u.remove();for(let u of c.querySelectorAll('[data-reactive-file="name"]'))u.textContent=a.name;for(let u of[...c.childNodes]){if(u.nodeType!==1)continue;u.setAttribute(ot,""),o.append(u)}}}}var ys=!1;function ql(){if(ys)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ys=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented||!t.lastElementChild?.hasAttribute(ot))return;for(let r of t.children)if(r.hasAttribute(ot))n.append(r.cloneNode(!0))})}function Wl(e,t){if(typeof DataTransfer!=="function")return Er(e,"per_file: has no DataTransfer to drop the refused files from the input"),!1;let n=new DataTransfer;for(let r of t)n.items.add(r);return e.files=n.files,!0}function jl(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 Xe(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function Er(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))Xe(t)}function ia(e){let t=ge.get(e);if(t===void 0)return;if(ge.delete(e),URL.revokeObjectURL(t),ge.size===0)be?.disconnect(),be=null}function Bl(){if(be||typeof MutationObserver!=="function"||!document?.documentElement)return;be=new MutationObserver(()=>{for(let[e,t]of ge)if(!e.isConnected||e.getAttribute("src")!==t)ia(e)}),be.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function sa(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function aa(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=ws(e);if(e.value=t,ws(e)!==n)sa(e)}function ws(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
- `):e.value}function Jl(e,t,n){if(n?.transition)Ll(e,n.transition,()=>e.hidden=t);else e.hidden=t}function cr(e,t,n,r){if(Jl(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 ur(e){if(!oa(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function ca(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 s of["srcset","src"]){let a=r?n.getAttribute(s):null;if(a==null){if(e.hasAttribute(s))o=e.removeAttribute(s)??!0}else if(e.getAttribute(s)!==a)o=e.setAttribute(s,a)??!0}if(o)at(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Hl='a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([type=hidden]):not([disabled])';function Gl(e){return e.querySelectorAll?.(Hl)?.[0]??null}function qr(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 As=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"}),Ss=Object.freeze(["meta","ctrl","alt","shift"]);function Q(e,t,n){let r=e.split("+");for(let s of Ss)if(r.includes(s)!==Boolean(t[`${s}Key`]))return!1;let o=r.find((s)=>!Ss.includes(s));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(As,o)?As[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var zl=(e)=>e&&typeof e==="object"?e.keys:String(e),Wr=()=>Ze().prevented??=new WeakSet;function lr(e,t){if(t!=null&&!e.defaultPrevented)Wr().add(e);e.preventDefault()}var ua=(e)=>e?.isContentEditable||/^(input|textarea|select)$/.test(e?.localName);function la(e,t,n,r){if(n.defaultPrevented&&e?.handled!==!0&&!Wr().has(n))return!1;if(e?.inEditable!==!0&&ua(n.target))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Q(t.replace(/^mod\+/,`${o}+`),n,r)}var Ul=1000,it={strokes:[],done:!1,seen:new WeakSet,listening:!1},fr=()=>it.done=!0;function fa(e){let t=it;if(t.seen.has(e))return;if(t.seen.add(e),!t.listening)t.listening=!0,globalThis.window?.addEventListener?.("keydown",fa,!0),globalThis.window?.addEventListener?.("blur",fr),globalThis.document?.addEventListener?.("turbo:before-render",fr,!0),globalThis.document?.addEventListener?.("focusin",(n)=>ua(n.target)&&fr(),!0);if(t.done)t.strokes=[],t.done=!1;if(!e.repeat&&!/^(Shift|Control|Alt|AltGraph|Meta|CapsLock|Fn|OS)$/.test(e.key))t.strokes=[...t.strokes.slice(-2),e]}function Kl(e,t,n,r){if(n[ee])return!1;fa(n);let o=it.strokes.slice(-t.length);if(o.at(-1)!==n||o.length<t.length)return!1;let i=e?.within??Ul,s=o.every((a,c)=>la(e,t[c],a,r)&&(c===0||a.timeStamp-o[c-1].timeStamp<=i));if(s)it.done=!0;return s}function xr(e,t,n){let r=zl(e).split(" ");return r.length>1?Kl(e,r,t,n):la(e,r[0],t,n)}var _r=/^key(down|up|press)\.([a-z]+\+)*(delete|backspace)$/;function Vl(e,t){let{shortcut:n,key:r}=e.params??{};return n!=null&&!xr(n,e,t)||r!=null&&!Q(String(r),e,t)}function Yl(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:qr(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 dr(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=/^key(down|up|press)\./.test(r)?r.indexOf("."):-1;if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==jr(t.currentTarget))return!1;return o<0||n===null&&!_r.test(r)||Q(r.slice(o+1),t,n)}function Xl(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 Es=new WeakMap;function Zl(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Es.get(e);if(!o)o=new WeakMap,Es.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=(r===globalThis.window?`${da(t.params?.ops)}|`:"")+JSON.stringify(n);if(i.has(a))return!0;return i.add(a),!1}var xs=new WeakMap,da=(e)=>typeof e==="string"?e:JSON.stringify(e??null);function Ql(e,t){if(e===null||typeof e!=="object")return!1;let n=da(e.params?.ops),r=xs.get(e);if(!r)r=new WeakMap,xs.set(e,r);let o=r.get(t);if(!o)o=new Map,r.set(t,o);let i=o.get(e.currentTarget);if(!i)i=new Set,o.set(e.currentTarget,i);if(i.has(n))return!0;return i.add(n),!1}var ef=new Set(["click","focus","focus_first"]);function kr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(vs,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let s=t(i);if(s.length===0&&n)n(o,i);if(s.length>1&&ef.has(o))s=s.slice(0,1);if(s.length>0)i=nf(o,i,t,n);if(!i)continue;for(let a of s)if(vs[o](a,i,t),i?.keep===!0)Ds(a,o,i,t)}}var tf=new Set(["set_value","text","set_attr"]);function nf(e,t,n,r){let o=e==="dispatch",i=o?t.detail_from:tf.has(e)&&t.from!=null&&{value:t.attr};if(!i||o&&!Object.keys(i).length)return t;let s=o?t.detail??{}:{};if(typeof s!="object"||Array.isArray(s))return console.warn(`[phlex-reactive] refused client read over detail ${JSON.stringify(s)} — skipped`),null;let a=o?"@trigger":t.from,c;try{c=n({...t,to:a})[0]}catch{}if(!c)return r?.(e,{...t,to:a}),null;let u={...s};for(let[l,f]of Object.entries(i)){let d=rf(c,f);if(d==null)return null;u[l]=d}return o?{...t,detail:u}:{...t,...u}}function rf(e,t){if(t==="@text")return e.textContent??"";if(typeof t==="string"&&/^data-[a-z][a-z0-9-]*$/i.test(t))return e.getAttribute(t)??"";return console.warn(`[phlex-reactive] refused client read of ${JSON.stringify(t)} — skipped`),null}function of(e,t){let n=e.to;if(n==="@trigger")return[];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 sf(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Tr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var V='[data-controller~="reactive"]',af='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',Rr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Tr(e);function pe(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&Rr(r))r=r.parentElement?.closest?.(t);return r??null}var Y=new WeakMap,pr=new Set,Ue=new WeakMap;function cf(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 uf(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 lf(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function ff(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function df(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 _s(e){return e.getAttribute?.("data-reactive-presence")!=null}function pf(e){return e.getAttribute?.("data-reactive-subscribe")!=null}function mf(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function Cf(e,t,n){}function hf(e,t){}function Mf(e){return[]}function $f(e){return Promise.resolve()}var ks=new Set;function gf(e,t,n){let r=e+t;if(ks.has(r))return;ks.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 Pf(){return["persist","defer","form","bindings","compute","sortable","drag","presence","subscribe","countdown","effects","hints","devtools"]}var Ts=Promise.resolve();var Rs={enter:zs,exit:Us,fail:me,count:ta,text:H,served:Dr,waiting:new WeakMap},Os=1,mr=2,hr=4,gr=8,br=16,Ls=32,Ns=64,Fs=128,Cs=256,Ms=512;qt(Rs),xn(Rs);var ee=Symbol.for("phlex-reactive.early"),bf=1e4,vf=1500,jr=(e)=>e!=null&&(e===globalThis.window||e.window===e),yf="dispatch";function Ze(){return globalThis[ee]??={queue:[],connected:new WeakSet},globalThis[ee]}function wf(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:bf}function Af(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,(s,a)=>a.toUpperCase())]=i}return t}function Sf(e,t,n){return{[ee]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Af(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&&!Wr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var st=new WeakMap;function Ef(e,{token:t,type:n,method:r,filter:o,win:i},s){let a=st.get(e);if(!a)st.set(e,a=new Map);let c=i?`${t} ${s}`:t;if(a.has(c))return!1;return a.set(c,{type:n,method:r,filter:o,win:i,params:s,armed:!0}),!0}function $s(e,t,n,r){if(e?.[ee])return!1;let o=jr(e?.currentTarget),i=o?r:e?.currentTarget,s=o&&JSON.stringify(e.params),a=xf(e,i,o?`@${t}${s}`:t),c=st.get(i);for(let u of c?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==s)continue;if(u.filter&&!Q(u.filter,e,n))continue;return u.armed=!1,!0}return a}var Qe=new WeakMap;function Ps(e,t,n){let r=Qe.get(e);if(!r)Qe.set(e,r=new Map),setTimeout(()=>Qe.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function xf(e,t,n){let r=e&&Qe.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class pa extends zu{static values={token:String};#b;#a=new Map;#p=new Map;#X;#Z;#F;#E=0;#m=new Map;#x=new WeakMap;#o;featuresReady=Ts;#Pe=new Map;#Ie=new Set;#Q=!1;#C=null;#De=new Map;#qe=new Map;#We=new Map;#ee=0;#M;#_=0;#i=0;connect(){if(ra=!0,Ze().connected.add(this.element),Y.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||Tr(this.element))this.#o=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Ke)this.#P();this.#$(!0)},this.element.addEventListener?.("turbo:morph-element",this.#o),this.element.addEventListener?.("focusin",this.#o),this.element.addEventListener?.(Ke,this.#o);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Ir),this.#ee++,this.featuresReady=Ts,this.#$(),et(this.element),this.#ne()}#$(e){this.#t(Os,"persist",sf,(t)=>Ut(this,t,e)),this.#t(mr,"defer",Tr,(t)=>On(this,t,e)),this.#t(hr,"form",cf,(t)=>Zt(this,t,e)),this.#t(gr,"bindings",uf,(t)=>dt(this,t,e)),this.#t(br,"compute",lf,(t)=>Nt(this,t,e)),this.#t(Ls,"sortable",ff,(t)=>$n(this,t)),this.#t(Cs,"drag",df,(t)=>Bn(this,t)),this.#t(Ns,"presence",_s,(t)=>Kn(this,t)),this.#t(Ms,"subscribe",pf,()=>Zn(this)),this.#t(Fs,"countdown",mf,(t)=>tr(this,t))}#t(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#I(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#i|=e}catch(o){this.#I(t,"connect",o)}}#te(){{let e=this.#i;this.#_=this.#i=0;let t=this.#e();if(e&Os)this.#n("persist",()=>Kt(this,t));if(e&mr)this.#n("defer",()=>Ln(this,t));if(e&hr)this.#n("form",()=>Qt(this,t));if(e&gr)this.#n("bindings",()=>pt(this,t));if(e&br)this.#n("compute",()=>Ft(this,t));if(e&Ls)this.#n("sortable",()=>Pn(this,t));if(e&Cs)this.#n("drag",()=>Jn(this,t));if(e&Ns)this.#n("presence",()=>Vn(this,t));if(e&Ms)this.#n("subscribe",()=>Qn(this));if(e&Fs)this.#n("countdown",()=>nr(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#je(e){}#Be(e,t){}#Je(e){}#He(e,t){}#Ge(e,t,n,r){}#e(){return this.#M??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#P(),proceed:(e,t,n,r)=>this.#T(e,t,n,0,0,null,r),forgetToken:()=>{this.#b=void 0},owns:(e)=>this.#l(e),ownership:()=>this.#G(),bindingOwns:(e)=>this.#z(e),bindingOwnership:()=>this.#Ee(),opTargets:(e)=>this.#N(e),diagnose:(e,t)=>this.#L(e,t),applyOps:(e,t)=>kr(e,(n)=>this.#N(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#L(`client op "${n}"`,r)),listnavOptions:(e)=>this.#h(e),collectFields:()=>this.#U(),plain:Js,text:H,served:Dr,copyMedia:ca,setValue:aa,confirm:(e,t)=>Promise.resolve().then(()=>rs(e,t)).catch(()=>!1)},this.#M}#P(){if(this.#i&hr)en(this);if(this.#i&gr)mt(this);if(this.#i&br)Ct(this)}#I(e,t,n){if(gf(e,t,n),this.#r("feature"),me({kind:"feature",root:this.element.id}),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})}#ze(){}#ne(){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.#re();for(let[e,t]of Ue.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Ue.delete(this.element)}#k=new Set;#re(){let{queue:e}=Ze();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=wf(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let s=i[+!!o.win];if(s.has(o.el))continue;s.add(o.el);let a=o.win?Math.min(vf,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>a?`it is older than the ${a} 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.#A())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#oe(o)}}#oe({event:e,el:t,descs:n,win:r}){let o=Sf(e,t,r),i=this.application?.schema?.keyMappings,s=(t.getAttribute("data-action")??"").split(/\s+/),a=r?this.element:t,c=r?JSON.stringify(o.params):"",u=r?`@runOps${c}`:"runOps",l=!1;for(let f of n){if(!s.includes(f.token))continue;if(f.filter&&!Q(f.filter,e,i))continue;if(/#\w+.*:once\b/.test(f.token)){if(!Ef(a,f,r&&JSON.stringify(o.params)))continue;this.#k.add(a)}if(f.method==="runOps")l=!0,this.runOps(o);else Ps(e,a,r?`@dispatch${c}`:"dispatch"),this.dispatch(o)}if(l)for(let f of s){let d=/^(?:(key(?:down|up|press))(?:\.([\w+]+))?|([^@>]+))(@window)?->reactive#runOps/.exec(f);if(d&&(d[1]??d[3])===e.type&&!!d[4]===!!r&&(!d[2]||Q(d[2],e,i)))Ps(e,a,u)}}disconnect(){if(this.#te(),this.#me(),this.#ge(),this.#o)this.element.removeEventListener?.("turbo:morph-element",this.#o),this.element.removeEventListener?.("focusin",this.#o),this.element.removeEventListener?.(Ke,this.#o);if(Ze().connected.delete(this.element),Y.get(this.element)===this)Y.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#k)st.delete(e);this.#k.clear()}dispatch(e){if(Vl(e,this.application?.schema?.keyMappings))return;if(e.params?.action&&e.params.action!==ds&&this.#se())return this.#ae(e);let t=e.params?.shortcut;if($s(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:s,confirmWhen:a,outside:c,window:u,optimistic:l,prevent:f,awaitSettled:d}=e.params;if(!n)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let h=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#V(l,h))lr(e,t);if(n===ds){let m=()=>{if(this.#i&mr)return $e(this);if(this.tokenValue)return this.#T(h,n,"{}")};return this.#Q?this.featuresReady.then(m):m()}let b=this.#D(s,a),v=()=>this.#T(h,n,r,o,i,l,p,d);if(!b)return v();if(b instanceof Promise)return b.then((m)=>m?this.#v(m,h,v):v());this.#v(b,h,v)}#v(e,t,n){return Promise.resolve().then(()=>rs(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#D(e,t){if(e)return e;if(!t)return null;return gt(this,this.#e(),t)}#ie(e){}#se(){return!this.tokenValue&&Rr(this.element)}#ae(e){let t=pe(this.element.parentElement,af);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=Y.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:s}=e.params,a=e.currentTarget??e.target;if((r!=null||!o&&s!==!1)&&!this.#V(i,a))lr(e,r);Ue.set(t,[...Ue.get(t)??[],[e,a]]);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&&!xr(t.shortcut,e,this.application?.schema?.keyMappings))return;if(_r.test(t?.on)&&!dr(t,e,this.application?.schema?.keyMappings))return;if($s(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Ql(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Yl(n.ops),i=o.some((c)=>_r.test(c.on)),s=o.filter((c)=>dr(c,e,null)),a=s.length<=1&&!i?s:s.filter((c)=>dr(c,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#A()&&!i)bn(this,e);return}for(let c of a){if(c.outside&&e[ee])continue;if(!Xl(c,e))continue;let u=c.within==null?r:this.#ce(c.within,e);if(c.within!=null&&!u)continue;if(c.shortcut!=null&&!xr(c.shortcut,e,this.application?.schema?.keyMappings))continue;if(Zl(this,e,c))continue;this.#ue(c.legacy?{...n,ops:c.ops,debounce:void 0,throttle:void 0,prevent:void 0}:c,e,u,o.indexOf(c),r)}}#ce(e,t){let n=t.currentTarget,r=null;try{r=t.target?.closest?.(e)}catch{if(this.#A())console.warn(`[phlex-reactive] on_client within: ${JSON.stringify(e)} is not a selector — nothing ran`)}return r&&r!==n&&n?.contains?.(r)&&this.#l(r)?r:null}#ue(e,t,n,r,o=n){let{ops:i,confirm:s,confirmWhen:a,outside:c,window:u,shortcut:l,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(l!=null||!u&&f!==!1)lr(t,l);let d=this.#D(s,a),p=this.#le(e,r,o,()=>this.#Oe(this.#Re(i),n));if(!d)return p();if(d instanceof Promise)return d.then((h)=>h?this.#v(h,n,p):p());this.#v(d,n,p)}#le(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let s=JSON.stringify([t,e]);if(o>0)return()=>this.#q(n,s,o,r);return()=>this.#B(n,s,i,r)}recompute(e){return Mt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#h(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return xt(this,this.#e(),e)}tagsPick(e){return _t(this,this.#e(),e)}tagsRemove(e){return kt(this,this.#e(),e)}nestedAdd(e){return Tt(this,this.#e(),e)}nestedRemove(e){return Rt(this,this.#e(),e)}syncNestedJson(e){return ht(this,this.#e(),e)}#Ue(e,t){}trackDirty(){Re(this,this.#e())}listnavNext(e){this.#y(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#y(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#y(e,()=>0)}listnavLast(e){this.#y(e,(t,n)=>n-1)}listnavPick(e){let t=this.#h(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.#h(e))t.removeAttribute("data-reactive-highlighted")}#y(e,t){let n=this.#h(e);if(!n.length)return;e.preventDefault();let r=this.#fe(e),o=globalThis.document?.activeElement,i=r?n.findIndex((a)=>a===o||o!=null&&a.contains?.(o)):n.findIndex((a)=>a.hasAttribute("data-reactive-highlighted")),s=n[t(i,n.length)];if(r)s.focus?.();else{for(let a of n)a.removeAttribute("data-reactive-highlighted");s.setAttribute("data-reactive-highlighted","true")}s.scrollIntoView?.({block:"nearest"})}#fe(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#h(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.#G();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#T(e,t,n,r,o,i,s,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#K(n),element:this.element},{cancelable:!0}).defaultPrevented)return;if(a&&!ct())return this.#de(t,n,e,(f)=>f.#g(t,n,i,e,s));let u=Number(r)||0;if(u>0)return this.#pe(e,u,t,n,i,s);let l=Number(o)||0;if(l>0)return this.#he(e,l,t,n,i,s);return this.#g(t,n,i,e,s)}#de(e,t,n,r){let o=this.element.id,i=`${nt}\x00${o}\x00${e}\x00${typeof t==="string"?t:JSON.stringify(t)}`;if(pr.has(i))return;let s=n?.nodeType===1?n:null,a=Zs(this.#S(),(c)=>{pr.delete(i),s?.removeAttribute(he);let u=this.element.isConnected&&Y.get(this.element)===this?this:o&&Y.get(document.getElementById(o));if(c&&u)return r(u)});return pr.add(i),s?.setAttribute(he,""),a}#g(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},s=this.#Le(e,r,i),a=Boolean(n||o),c=(d)=>{if(!a||!d)return;let p=this.#e();if(i.inverse=wn(this,p,n,r),i.undo.push(...yn(this,p,o,r)),this.#R())i.resurrect=An(this,p,n,r)},u=!0;c(!0);let l=()=>this.#we(e,t,i,s),f=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Ke(){return this.#ie("hints")}#pe(e,t,n,r,o,i){this.#q(e,yf,t,()=>this.#g(n,r,o,e,i))}#q(e,t,n,r){let o=this.#a.get(e)?.get(t),i=()=>{this.#j(e,t),r()},s=setTimeout(i,n);if(!jr(e))e?.addEventListener?.("blur",i,{once:!0});let a=this.#a.get(e);if(!a)this.#a.set(e,a=new Map);if(a.set(t,{timer:s,flush:i}),gl(i),o)this.#W(e,o)}#W(e,t){clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),bl(t.flush)}#j(e,t){let n=this.#a.get(e),r=n?.get(t);if(!r)return;if(this.#W(e,r),n.delete(t),n.size===0)this.#a.delete(e)}#me(){for(let[e,t]of[...this.#a])for(let n of[...t.keys()])this.#j(e,n)}#he(e,t,n,r,o,i){return this.#B(e,n,t,()=>this.#g(n,r,o,e,i))}#B(e,t,n,r){let o=this.#p.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#p.delete(e)},n);return o.set(t,i),this.#p.set(e,o),r()}#ge(){for(let e of this.#p.values())for(let t of e.values())clearTimeout(t);this.#p.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}#c(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.#g(e,t)};me({action:e,kind:r.kind,status:r.status,root:this.element.id}),this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#r(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#be(){this.element?.removeAttribute?.("data-reactive-error")}#ve(){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))}#ye(){return dn()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#J(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#we(e,t,n,r){let{fields:o,files:i}=this.#U(),s=this.#K(t),a={...o,...s},c=this.#u,u=i.length>0,l=u?this.#ke(c,e,a,i):JSON.stringify({token:c,act:e,params:a}),f=this.#R()?{action:e,paramNames:Object.keys(s),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#J()}:null;await this.#ye();try{if(navigator.onLine===!1){this.#f(n.inverse),this.#r("offline"),this.#c(e,t,a,{kind:"offline"});return}let d;try{let w={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Me()};if(!u)w["Content-Type"]="application/json";let A=this.#$e();if(A)w["X-Pgbus-Connection"]=A;let x=_s(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(x)w["X-Reactive-Presence"]=x;let T=ll(this.element);if(T)w["X-Reactive-Held"]=T;ta("action"),d=await fetch(this.#Ce(),{method:"POST",headers:w,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#S())})}catch(w){if(console.error("[phlex-reactive] action error",w),this.#f(n.inverse),w?.name==="TimeoutError"||w?.name==="AbortError"){this.#r("timeout"),this.#c(e,t,a,{kind:"timeout"});return}this.#ve(),this.#r("network"),this.#c(e,t,a,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#f(n.inverse),this.#r("redirected"),this.#c(e,t,a,{kind:"redirected",status:d.status});return}if(!d.ok){let w=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,w),this.#f(n.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let A=this.#H(w);if(this.#u=A??this.#u,f)Le(f,w,A);let x=fs(this.element,w,!0,this.#S());r?.handoff?.(),await x}this.#r("http"),this.#c(e,t,a,{kind:"http",status:d.status,body:w});return}let p=d.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#f(n.inverse),this.#r("content-type"),this.#c(e,t,a,{kind:"content-type",status:d.status});return}let h=await d.text(),b=this.#H(h);if(this.#u=b??this.#u,f)Le(f,h,b);let v=fs(this.element,h,fl(d),this.#S());if(n.resurrect)queueMicrotask(n.resurrect);if(this.#be(),this.#s("reactive:applied",{action:e,params:a,html:h}),r?.handoff?.(),await v)this.#r("apply"),me({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"});return h}catch(d){console.error("[phlex-reactive] action error",d),this.#f(n.inverse),this.#r("apply"),me({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"})}finally{if(r?.(),f)vn(this,{...f,ms:this.#J()-f.started})}}get#u(){return this.#b??this.tokenValue}set#u(e){this.#b=e}tokenValueChanged(){this.#b=void 0}#H(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#Ae(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}#Ae(e){let t=this.#F;if(t&&t.id===e)return t;let n=Tl(e);return this.#F={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>`)}}#l(e){return e.closest('[data-controller~="reactive"]')===this.element}#G(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#l(t)}#Se(){let e=this.element.querySelectorAll(V);if(e.length===0||[...e].every(Rr))return()=>!0;return(t)=>{let n=pe(t,V,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&pe(n.parentElement,V,this.element)===this.element}}#z(e){if(this.#l(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=pe(e,V,this.element);return t===this.element||pe(t?.parentElement,V,this.element)===this.element}#Ee(){if(this.element.querySelectorAll(V).length===0)return()=>!0;return(e)=>this.#z(e)}#U(){let e={},t=[],n=this.#Se(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((a)=>{if(!n(a))return;if(a.type==="file")for(let c of a.files??[])t.push({name:a.name,file:c,multiple:a.multiple});else r.push(a)});let o=[];this.element.querySelectorAll(`[name]${Fl}`).forEach((a)=>{if(n(a))o.push(a)});let i=this.#xe(r),s=this.#_e(r);for(let a of r)if(i.has(a.name)){let c=e[a.name]??(e[a.name]=[]);if(a.type==="checkbox"||a.type==="radio"){if(a.checked)c.push(a.value)}else if(a.type==="hidden"){if(!s.has(a.name))c.push(a.value)}else if(a.multiple&&a.options){for(let u of a.options)if(u.selected)c.push(u.value)}else c.push(a.value)}else if(a.type==="checkbox")e[a.name]=a.checked;else if(a.type==="radio"){if(a.checked)e[a.name]=a.value}else e[a.name]=a.value;return o.forEach((a)=>{let c=a.getAttribute("name");if(!c)return;let u=a.getAttribute("data-reactive-editable")!=null?H(a):a.value??a.textContent??a.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Ml(a))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}}#xe(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}#_e(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#ke(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[a,c]of Object.entries(n))if(Array.isArray(c)&&String(a).endsWith("[]"))if(c.length===0)i.push(String(a).slice(0,-2));else{let u=`${this.#w(a)}[]`;for(let l of c)o.append(u,String(l))}else this.#O(o,this.#w(a),c);for(let a of i)o.append("empty_groups[]",a);let s=this.#Te(r);for(let{name:a,file:c,multiple:u}of r){let f=u||s.has(a)?`${this.#w(a)}[]`:this.#w(a);o.append(f,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("")}`}#O(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#O(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#O(e,`${t}[${r}]`,o);else e.append(t,String(n))}#Te(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))}#K(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Re(e){return qr(e)}#Oe(e,t){kr(e,(n)=>this.#N(n,t),(n,r)=>this.#L(`client op "${n}"`,r))}#A(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#L(e,t){if(!this.#A())return;gn(this,e,t)}#Ve(e){}#N(e,t){let n=e.to;if(n==="@root")return[this.element];if(n==="@trigger")return t?.nodeType===1?[t]:[];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...this.element.querySelectorAll(n)].filter((r)=>this.#l(r))}#V(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#f(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Le(e,t,n){this.#Ne(e,t),zs();let r=!1,o=!1,i=()=>{if(r)return;r=!0,this.#Fe(e,t);for(let a of n.undo)a()},s=()=>{if(o)return;o=!0,i(),Us()};return s.handoff=i,s}#Ne(e,t){if(this.#d(t,e,1),this.#d(this.element,e,1),this.#m.set(e,(this.#m.get(e)??0)+1),this.#E++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#Y(e))this.#d(n,e,1)}#Fe(e,t){this.#d(t,e,-1),this.#d(this.element,e,-1);let n=(this.#m.get(e)??1)-1;if(n<=0)this.#m.delete(e);else this.#m.set(e,n);if(--this.#E<=0)this.#E=0,this.element.removeAttribute("aria-busy");for(let r of this.#Y(e))this.#d(r,e,-1)}#d(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#x.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.#x.delete(e),e.removeAttribute("data-reactive-busy");return}this.#x.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#Y(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#l(n))}#Ce(){return this.#X??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#S(){return this.#Z??=Xs()}#Me(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#$e(){let e=this.element.getAttribute?.("data-reactive-subscribe"),t;if(e){for(let n of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source][connection-id]"))if(n.getAttribute("src")===e)t=n.getAttribute("connection-id")}return t||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)bs();else document.addEventListener("turbo:load",bs,{once:!0});Pr();var Gf=pa;export{Gs as ACTIVE_ATTR,Fl as EDITOR_SELECTOR,Cl as EDITOR_TAGS,Ar as ERRORS_ATTR,eu as LATENCY_KEY,ea as REQUESTS_ATTR,Rl as checkReactiveRegistration,ta as countReactiveRequest,Gf as default,Ho as disableLatencySim,H as editableValue,Jo as enableLatencySim,zs as enterReactiveActivity,Tl as escapeRegExp,Us as exitReactiveActivity,vl as flushReactiveDebounces,$f as loadReactiveFeature,Of as onReactiveStreamWithoutEffects,Lf as reactiveActivityCount,Ff as reactiveDebounceCount,Pf as reactiveFeatureNames,yl as reactiveSettled,me as recordReactiveError,bs as registerReactiveActions,xl as registerReactiveAwaitSettled,Xu as registerReactiveDefer,Pr as registerReactiveDev,Qu as registerReactiveDismiss,Qu as registerReactiveEffects,hf as registerReactiveFeature,Cf as registerReactiveFeatureLoader,il as registerReactiveImageFallback,Yu as registerReactiveJs,ol as registerReactiveKeep,rl as registerReactiveModals,al as registerReactiveMorphFocus,ml as registerReactiveOffline,sl as registerReactivePlaintext,ql as registerReactiveRejectedFiles,Qu as registerReactiveStreamRender,Ku as registerReactiveToken,Uu as registerReactiveVisit,Nf as resetReactiveActivity,Dr as serverText,Mf as unloadedFeaturesFor};
5
+ `).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var it=new WeakMap;function qr(e){if(e?.hasAttribute?.("data-reactive-editable")&&!it.has(e))it.set(e,z(e))}function Wr(e){return qr(e),it.get(e)}function Il(e){return Pl.has(e.localName)?typeof e.value==="string":!0}var ws=Object.freeze({show:(e,t,n)=>lr(e,!1,t,n),hide:(e,t,n)=>lr(e,!0,t,n),toggle:(e,t,n)=>lr(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(fr(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(fr(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!fr(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)=>Kl(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>qs(e),close_dialog:(e)=>ol(e),click:(e)=>e.click?.(),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{}la(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)At(r,t.group,t.checked)},presence:(e,t)=>Xn(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=Dl(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)=>ql(e),preview_file:(e,t,n)=>Wl(e,t,n),set_value:(e,t)=>ua(e,String(t.value??"")),persist_state:(e,t)=>Yt(e,t.state),persist_clear:(e)=>Xt(e)});function Dl(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function ql(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ca(e),e.focus?.()}).catch(()=>{})}var ge=new Map,be=null;function Wl(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Qe(`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 Qe(`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=Hl(e,t.accept),s=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,a=[],c;if(t.per_file===!0&&e.multiple){let u=o.filter((f,d)=>{let p=typeof f?.type==="string"&&i(f)?s(f)&&"size":"type";if(p)a.push({reason:p,file:f,index:d});return!p}),l=a.length>0&&!Jl(e,u)?o.length:u.length;for(let f of a)f.remaining=l;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=o.filter((f)=>typeof f?.type==="string"&&i(f));c=u.find((f)=>f.type.startsWith("image/"));let l=o.length>0&&u.length===0?"type":null;if(c&&s(c))l="size";if(l)a.push({reason:l,file:l==="size"?c:o[0]}),c=null}if(aa(r),c){let u=URL.createObjectURL(c);ge.set(r,u),r.setAttribute("src",u),zl()}else r.removeAttribute("src");if(ut(r),t.wrap!=null){let u=n({...t,to:t.wrap});if(u.length===0)Qe(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let l of u)c?Bs(l):js(l)}if(t.name!=null)for(let u of n({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)jl(e,n({...t,to:t.rejected}),a,t.rejected);for(let u of a)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}var st="data-reactive-file-rejected";function jl(e,t,n,r){if(t.length===0)return _r(e,`rejected: ${JSON.stringify(r)} is not on the page`);for(let o of t){for(let s of[...o.children])if(s.hasAttribute(st))s.remove();let i=[...o.children].find((s)=>s.localName==="template");if(!i){_r(e,`rejected: ${JSON.stringify(r)} has no <template> child`);continue}for(let{reason:s,file:a}of n){let c=i.content.cloneNode(!0);for(let u of c.querySelectorAll("[data-reactive-file-reason]"))if(u.getAttribute("data-reactive-file-reason")!==s)u.remove();for(let u of c.querySelectorAll('[data-reactive-file="name"]'))u.textContent=a.name;for(let u of[...c.childNodes]){if(u.nodeType!==1)continue;u.setAttribute(st,""),o.append(u)}}}}var As=!1;function Bl(){if(As)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;As=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented||!t.lastElementChild?.hasAttribute(st))return;for(let r of t.children)if(r.hasAttribute(st))n.append(r.cloneNode(!0))})}function Jl(e,t){if(typeof DataTransfer!=="function")return _r(e,"per_file: has no DataTransfer to drop the refused files from the input"),!1;let n=new DataTransfer;for(let r of t)n.items.add(r);return e.files=n.files,!0}function Hl(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 Qe(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function _r(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))Qe(t)}function aa(e){let t=ge.get(e);if(t===void 0)return;if(ge.delete(e),URL.revokeObjectURL(t),ge.size===0)be?.disconnect(),be=null}function zl(){if(be||typeof MutationObserver!=="function"||!document?.documentElement)return;be=new MutationObserver(()=>{for(let[e,t]of ge)if(!e.isConnected||e.getAttribute("src")!==t)aa(e)}),be.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ca(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ua(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=Ss(e);if(e.value=t,Ss(e)!==n)ca(e)}function Ss(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
+ `):e.value}function Gl(e,t,n){if(n?.transition)Cl(e,n.transition,()=>e.hidden=t);else e.hidden=t}function lr(e,t,n,r){if(Gl(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 fr(e){if(!sa(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function la(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 s of["srcset","src"]){let a=r?n.getAttribute(s):null;if(a==null){if(e.hasAttribute(s))o=e.removeAttribute(s)??!0}else if(e.getAttribute(s)!==a)o=e.setAttribute(s,a)??!0}if(o)ut(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Ul='a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([type=hidden]):not([disabled])';function Kl(e){return e.querySelectorAll?.(Ul)?.[0]??null}function jr(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 Es=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"}),xs=Object.freeze(["meta","ctrl","alt","shift"]);function ee(e,t,n){let r=e.split("+");for(let s of xs)if(r.includes(s)!==Boolean(t[`${s}Key`]))return!1;let o=r.find((s)=>!xs.includes(s));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Es,o)?Es[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Vl=(e)=>e&&typeof e==="object"?e.keys:String(e),Br=()=>et().prevented??=new WeakSet;function dr(e,t){if(t!=null&&!e.defaultPrevented)Br().add(e);e.preventDefault()}var fa=(e)=>e?.isContentEditable||/^(input|textarea|select)$/.test(e?.localName);function da(e,t,n,r){if(n.defaultPrevented&&e?.handled!==!0&&!Br().has(n))return!1;if(e?.inEditable!==!0&&fa(n.target))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return ee(t.replace(/^mod\+/,`${o}+`),n,r)}var Yl=1000,at={strokes:[],done:!1,seen:new WeakSet,listening:!1},pr=()=>at.done=!0;function pa(e){let t=at;if(t.seen.has(e))return;if(t.seen.add(e),!t.listening)t.listening=!0,globalThis.window?.addEventListener?.("keydown",pa,!0),globalThis.window?.addEventListener?.("blur",pr),globalThis.document?.addEventListener?.("turbo:before-render",pr,!0),globalThis.document?.addEventListener?.("focusin",(n)=>fa(n.target)&&pr(),!0);if(t.done)t.strokes=[],t.done=!1;if(!e.repeat&&!/^(Shift|Control|Alt|AltGraph|Meta|CapsLock|Fn|OS)$/.test(e.key))t.strokes=[...t.strokes.slice(-2),e]}function Xl(e,t,n,r){if(n[te])return!1;pa(n);let o=at.strokes.slice(-t.length);if(o.at(-1)!==n||o.length<t.length)return!1;let i=e?.within??Yl,s=o.every((a,c)=>da(e,t[c],a,r)&&(c===0||a.timeStamp-o[c-1].timeStamp<=i));if(s)at.done=!0;return s}function kr(e,t,n){let r=Vl(e).split(" ");return r.length>1?Xl(e,r,t,n):da(e,r[0],t,n)}var Tr=/^key(down|up|press)\.([a-z]+\+)*(delete|backspace)$/;function Zl(e,t){let{shortcut:n,key:r}=e.params??{};return n!=null&&!kr(n,e,t)||r!=null&&!ee(String(r),e,t)}function Ql(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:jr(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 mr(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=/^key(down|up|press)\./.test(r)?r.indexOf("."):-1;if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==Jr(t.currentTarget))return!1;return o<0||n===null&&!Tr.test(r)||ee(r.slice(o+1),t,n)}function ef(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 _s=new WeakMap;function tf(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=_s.get(e);if(!o)o=new WeakMap,_s.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=(r===globalThis.window?`${ma(t.params?.ops)}|`:"")+JSON.stringify(n);if(i.has(a))return!0;return i.add(a),!1}var ks=new WeakMap,ma=(e)=>typeof e==="string"?e:JSON.stringify(e??null);function nf(e,t){if(e===null||typeof e!=="object")return!1;let n=ma(e.params?.ops),r=ks.get(e);if(!r)r=new WeakMap,ks.set(e,r);let o=r.get(t);if(!o)o=new Map,r.set(t,o);let i=o.get(e.currentTarget);if(!i)i=new Set,o.set(e.currentTarget,i);if(i.has(n))return!0;return i.add(n),!1}var rf=new Set(["click","focus","focus_first"]);function Rr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(ws,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let s=t(i);if(s.length===0&&n)n(o,i);if(s.length>1&&rf.has(o))s=s.slice(0,1);if(s.length>0)i=sf(o,i,t,n);if(!i)continue;for(let a of s)if(ws[o](a,i,t),i?.keep===!0)Ws(a,o,i,t)}}var of=new Set(["set_value","text","set_attr"]);function sf(e,t,n,r){let o=e==="dispatch",i=o?t.detail_from:of.has(e)&&t.from!=null&&{value:t.attr};if(!i||o&&!Object.keys(i).length)return t;let s=o?t.detail??{}:{};if(typeof s!="object"||Array.isArray(s))return console.warn(`[phlex-reactive] refused client read over detail ${JSON.stringify(s)} — skipped`),null;let a=o?"@trigger":t.from,c;try{c=n({...t,to:a})[0]}catch{}if(!c)return r?.(e,{...t,to:a}),null;let u={...s};for(let[l,f]of Object.entries(i)){let d=af(c,f);if(d==null)return null;u[l]=d}return o?{...t,detail:u}:{...t,...u}}function af(e,t){if(t==="@text")return e.textContent??"";if(typeof t==="string"&&/^data-[a-z][a-z0-9-]*$/i.test(t))return e.getAttribute(t)??"";return console.warn(`[phlex-reactive] refused client read of ${JSON.stringify(t)} — skipped`),null}function cf(e,t){let n=e.to;if(n==="@trigger")return[];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 uf(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Lr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var Y='[data-controller~="reactive"]',lf='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',Or=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Lr(e);function pe(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&Or(r))r=r.parentElement?.closest?.(t);return r??null}var X=new WeakMap,hr=new Set,Ve=new WeakMap;function ff(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 df(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], [data-reactive-listnav-highlight-param]")!=null}function pf(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function mf(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function hf(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 Ts(e){return e.getAttribute?.("data-reactive-presence")!=null}function gf(e){return e.getAttribute?.("data-reactive-subscribe")!=null}function bf(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function Pf(e,t,n){}function vf(e,t){}function If(e){return[]}function Df(e){return Promise.resolve()}var Rs=new Set;function yf(e,t,n){let r=e+t;if(Rs.has(r))return;Rs.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 qf(){return["persist","defer","form","bindings","compute","sortable","drag","presence","subscribe","countdown","effects","hints","devtools"]}var Ls=Promise.resolve();var Os={enter:Ks,exit:Vs,fail:me,count:ra,text:z,served:Wr,waiting:new WeakMap},Ns=1,gr=2,br=4,vr=8,yr=16,Fs=32,Cs=64,Ms=128,$s=256,Ps=512;Wt(Os),_n(Os);var te=Symbol.for("phlex-reactive.early"),wf=1e4,Af=1500,Jr=(e)=>e!=null&&(e===globalThis.window||e.window===e),Sf="dispatch";function et(){return globalThis[te]??={queue:[],connected:new WeakSet},globalThis[te]}function Ef(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:wf}function xf(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,(s,a)=>a.toUpperCase())]=i}return t}function _f(e,t,n){return{[te]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:xf(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&&!Br().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var ct=new WeakMap;function kf(e,{token:t,type:n,method:r,filter:o,win:i},s){let a=ct.get(e);if(!a)ct.set(e,a=new Map);let c=i?`${t} ${s}`:t;if(a.has(c))return!1;return a.set(c,{type:n,method:r,filter:o,win:i,params:s,armed:!0}),!0}function Is(e,t,n,r){if(e?.[te])return!1;let o=Jr(e?.currentTarget),i=o?r:e?.currentTarget,s=o&&JSON.stringify(e.params),a=Tf(e,i,o?`@${t}${s}`:t),c=ct.get(i);for(let u of c?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==s)continue;if(u.filter&&!ee(u.filter,e,n))continue;return u.armed=!1,!0}return a}var tt=new WeakMap;function Ds(e,t,n){let r=tt.get(e);if(!r)tt.set(e,r=new Map),setTimeout(()=>tt.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Tf(e,t,n){let r=e&&tt.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class ha extends Ku{static values={token:String};#v;#c=new Map;#m=new Map;#re;#oe;#P;#_=0;#h=new Map;#k=new WeakMap;#o;featuresReady=Ls;#Be=new Map;#Je=new Set;#ie=!1;#I=null;#He=new Map;#ze=new Map;#Ge=new Map;#se=0;#D;#T=0;#i=0;connect(){if(ia=!0,et().connected.add(this.element),X.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||Lr(this.element))this.#o=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Ye)this.#W();this.#q(!0)},this.element.addEventListener?.("turbo:morph-element",this.#o),this.element.addEventListener?.("focusin",this.#o),this.element.addEventListener?.(Ye,this.#o);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(qr),this.#se++,this.featuresReady=Ls,this.#q(),nt(this.element),this.#ce()}#q(e){this.#t(Ns,"persist",uf,(t)=>Kt(this,t,e)),this.#t(gr,"defer",Lr,(t)=>On(this,t,e)),this.#t(br,"form",ff,(t)=>Qt(this,t,e)),this.#t(vr,"bindings",df,(t)=>mt(this,t,e)),this.#t(yr,"compute",pf,(t)=>Ft(this,t,e)),this.#t(Fs,"sortable",mf,(t)=>Pn(this,t)),this.#t($s,"drag",hf,(t)=>Jn(this,t)),this.#t(Cs,"presence",Ts,(t)=>Vn(this,t)),this.#t(Ps,"subscribe",gf,()=>Qn(this)),this.#t(Ms,"countdown",bf,(t)=>nr(this,t))}#t(e,t,n,r){if(this.#T&e)return;try{if(!n(this.element))return}catch(o){return this.#j(t,"detect",o)}this.#T|=e;try{r(this.#e()),this.#i|=e}catch(o){this.#j(t,"connect",o)}}#ae(){{let e=this.#i;this.#T=this.#i=0;let t=this.#e();if(e&Ns)this.#n("persist",()=>Vt(this,t));if(e&gr)this.#n("defer",()=>Nn(this,t));if(e&br)this.#n("form",()=>en(this,t));if(e&vr)this.#n("bindings",()=>ht(this,t));if(e&yr)this.#n("compute",()=>Ct(this,t));if(e&Fs)this.#n("sortable",()=>In(this,t));if(e&$s)this.#n("drag",()=>Hn(this,t));if(e&Cs)this.#n("presence",()=>Yn(this,t));if(e&Ps)this.#n("subscribe",()=>er(this));if(e&Ms)this.#n("countdown",()=>rr(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Ue(e){}#Ke(e,t){}#Ve(e){}#Ye(e,t){}#Xe(e,t,n,r){}#e(){return this.#D??={emit:(e,t,n)=>this.#a(e,t,n),reseed:()=>this.#W(),proceed:(e,t,n,r)=>this.#O(e,t,n,0,0,null,r),forgetToken:()=>{this.#v=void 0},owns:(e)=>this.#f(e),ownership:()=>this.#F(),bindingOwns:(e)=>this.#Z(e),bindingOwnership:()=>this.#Le(),opTargets:(e)=>this.#$(e),diagnose:(e,t)=>this.#M(e,t),applyOps:(e,t)=>Rr(e,(n)=>this.#$(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#M(`client op "${n}"`,r)),listnavOptions:(e)=>this.#g(e),syncListnav:()=>this.#be(),collectFields:()=>this.#Q(),plain:zs,text:z,served:Wr,copyMedia:la,setValue:ua,confirm:(e,t)=>Promise.resolve().then(()=>is(e,t)).catch(()=>!1)},this.#D}#W(){if(this.#i&br)tn(this);if(this.#i&vr)Se(this);if(this.#i&yr)Mt(this)}#j(e,t,n){if(yf(e,t,n),this.#r("feature"),me({kind:"feature",root:this.element.id}),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#a("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#Ze(){}#ce(){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.#ue();for(let[e,t]of Ve.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Ve.delete(this.element)}#R=new Set;#ue(){let{queue:e}=et();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=Ef(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let s=i[+!!o.win];if(s.has(o.el))continue;s.add(o.el);let a=o.win?Math.min(Af,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>a?`it is older than the ${a} 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.#E())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#le(o)}}#le({event:e,el:t,descs:n,win:r}){let o=_f(e,t,r),i=this.application?.schema?.keyMappings,s=(t.getAttribute("data-action")??"").split(/\s+/),a=r?this.element:t,c=r?JSON.stringify(o.params):"",u=r?`@runOps${c}`:"runOps",l=!1;for(let f of n){if(!s.includes(f.token))continue;if(f.filter&&!ee(f.filter,e,i))continue;if(/#\w+.*:once\b/.test(f.token)){if(!kf(a,f,r&&JSON.stringify(o.params)))continue;this.#R.add(a)}if(f.method==="runOps")l=!0,this.runOps(o);else Ds(e,a,r?`@dispatch${c}`:"dispatch"),this.dispatch(o)}if(l)for(let f of s){let d=/^(?:(key(?:down|up|press))(?:\.([\w+]+))?|([^@>]+))(@window)?->reactive#runOps/.exec(f);if(d&&(d[1]??d[3])===e.type&&!!d[4]===!!r&&(!d[2]||ee(d[2],e,i)))Ds(e,a,u)}}disconnect(){if(this.#ae(),this.#we(),this.#Se(),this.#o)this.element.removeEventListener?.("turbo:morph-element",this.#o),this.element.removeEventListener?.("focusin",this.#o),this.element.removeEventListener?.(Ye,this.#o);if(et().connected.delete(this.element),X.get(this.element)===this)X.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#R)ct.delete(e);this.#R.clear()}dispatch(e){if(Zl(e,this.application?.schema?.keyMappings))return;if(e.params?.action&&e.params.action!==ms&&this.#de())return this.#pe(e);let t=e.params?.shortcut;if(Is(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:s,confirmWhen:a,outside:c,window:u,optimistic:l,prevent:f,awaitSettled:d}=e.params;if(!n)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let h=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#te(l,h))dr(e,t);if(n===ms){let m=()=>{if(this.#i&gr)return Pe(this);if(this.tokenValue)return this.#O(h,n,"{}")};return this.#ie?this.featuresReady.then(m):m()}let b=this.#B(s,a),v=()=>this.#O(h,n,r,o,i,l,p,d);if(!b)return v();if(b instanceof Promise)return b.then((m)=>m?this.#y(m,h,v):v());this.#y(b,h,v)}#y(e,t,n){return Promise.resolve().then(()=>is(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#B(e,t){if(e)return e;if(!t)return null;return bt(this,this.#e(),t)}#fe(e){}#de(){return!this.tokenValue&&Or(this.element)}#pe(e){let t=pe(this.element.parentElement,lf);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=X.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:s}=e.params,a=e.currentTarget??e.target;if((r!=null||!o&&s!==!1)&&!this.#te(i,a))dr(e,r);Ve.set(t,[...Ve.get(t)??[],[e,a]]);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&&!kr(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Tr.test(t?.on)&&!mr(t,e,this.application?.schema?.keyMappings))return;if(Is(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(nf(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Ql(n.ops),i=o.some((c)=>Tr.test(c.on)),s=o.filter((c)=>mr(c,e,null)),a=s.length<=1&&!i?s:s.filter((c)=>mr(c,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#E()&&!i)vn(this,e);return}for(let c of a){if(c.outside&&e[te])continue;if(!ef(c,e))continue;let u=c.within==null?r:this.#me(c.within,e);if(c.within!=null&&!u)continue;if(c.shortcut!=null&&!kr(c.shortcut,e,this.application?.schema?.keyMappings))continue;if(tf(this,e,c))continue;this.#he(c.legacy?{...n,ops:c.ops,debounce:void 0,throttle:void 0,prevent:void 0}:c,e,u,o.indexOf(c),r)}}#me(e,t){let n=t.currentTarget,r=null;try{r=t.target?.closest?.(e)}catch{if(this.#E())console.warn(`[phlex-reactive] on_client within: ${JSON.stringify(e)} is not a selector — nothing ran`)}return r&&r!==n&&n?.contains?.(r)&&this.#f(r)?r:null}#he(e,t,n,r,o=n){let{ops:i,confirm:s,confirmWhen:a,outside:c,window:u,shortcut:l,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(l!=null||!u&&f!==!1)dr(t,l);let d=this.#B(s,a),p=this.#ge(e,r,o,()=>this.#$e(this.#Me(i),n));if(!d)return p();if(d instanceof Promise)return d.then((h)=>h?this.#y(h,n,p):p());this.#y(d,n,p)}#ge(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let s=JSON.stringify([t,e]);if(o>0)return()=>this.#G(n,s,o,r);return()=>this.#V(n,s,i,r)}recompute(e){return $t(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented||Ge(e))return;if(this.#g(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return _t(this,this.#e(),e)}tagsPick(e){return kt(this,this.#e(),e)}tagsRemove(e){return Tt(this,this.#e(),e)}nestedAdd(e){return Rt(this,this.#e(),e)}nestedRemove(e){return Lt(this,this.#e(),e)}syncNestedJson(e){return gt(this,this.#e(),e)}#Qe(e,t){}trackDirty(){Le(this,this.#e())}listnavNext(e){this.#w(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#w(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){if(!this.#H(e))this.#w(e,()=>0)}listnavLast(e){if(!this.#H(e))this.#w(e,(t,n)=>n-1)}listnavPick(e){if(Ge(e))return;let t=()=>this.#g(e).find((r)=>r.hasAttribute("data-reactive-highlighted")),n=t();if(!n&&this.#s(e).getAttribute?.("data-reactive-listnav-highlight-param")==="first")this.#z(this.#s(e)),n=t();if(!n)return;if(e.preventDefault(),e.metaKey||e.ctrlKey)n.dispatchEvent(new MouseEvent("click",{metaKey:e.metaKey,ctrlKey:e.ctrlKey,bubbles:!0,cancelable:!0}));else n.click()}listnavClose(e){if(Ge(e))return;this.#L(this.#s(e),this.#A(e))}#w(e,t){let n=this.#A(e),r=this.#g(e,n);if(!r.length||Ge(e))return;e.preventDefault();let o=this.#J(e),i=globalThis.document?.activeElement,s=o?r.findIndex((c)=>c===i||i!=null&&c.contains?.(i)):r.findIndex((c)=>c.hasAttribute("data-reactive-highlighted")),a=r[t(s,r.length)];if(o)a.focus?.();else this.#L(this.#s(e),n,a);a.scrollIntoView?.({block:"nearest"})}#s(e){return e?.currentTarget??e?.target??this.element}#J(e){return this.#s(e).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#H(e){return!this.#J(e)&&!e.ctrlKey&&!!this.#s(e).value}#L(e,t,n){let r=e.getAttribute?.("data-reactive-listnav-highlight-param")==="first";for(let o of t){if(o===n)continue;if(o.hasAttribute("data-reactive-highlighted"))o.removeAttribute("data-reactive-highlighted");if(r&&o.hasAttribute("data-reactive-aria-selected"))o.removeAttribute("aria-selected"),o.removeAttribute("data-reactive-aria-selected")}if(n?.setAttribute("data-reactive-highlighted","true"),!r)return;if(!n)return e.removeAttribute("aria-activedescendant");if(!n.hasAttribute("aria-selected"))n.setAttribute("aria-selected","true"),n.setAttribute("data-reactive-aria-selected","");n.id||=`reactive-option-${++nl}`,e.setAttribute("aria-activedescendant",n.id)}#be(){if(!this.element.querySelector?.('[data-reactive-listnav-highlight-param="first"]'))return;let t=this.#F();for(let n of this.element.querySelectorAll('[data-reactive-listnav-highlight-param="first"]'))if(t(n))this.#z(n)}#z(e){let t={currentTarget:e},n=this.#A(t),r=this.#g(t,n),o=e.value??"",i=r.find((s)=>s.hasAttribute("data-reactive-highlighted"));if(or.has(e)&&or.get(e)!==o)i=void 0;or.set(e,o),this.#L(e,n,i??r[0])}#g(e,t=this.#A(e)){let n=this.element;return t.filter((r)=>{for(let o=r;o;o=o===n?null:o.parentElement)if(o.hidden)return!1;return!0})}#A(e){let n=this.#s(e).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];return Array.from(this.element.querySelectorAll(n)).filter(this.#F())}#O(e,t,n,r,o,i,s,a){if(this.#a("reactive:before-dispatch",{action:t,params:this.#ee(n),element:this.element},{cancelable:!0}).defaultPrevented)return;if(a&&!lt())return this.#ve(t,n,e,(f)=>f.#b(t,n,i,e,s));let u=Number(r)||0;if(u>0)return this.#ye(e,u,t,n,i,s);let l=Number(o)||0;if(l>0)return this.#Ae(e,l,t,n,i,s);return this.#b(t,n,i,e,s)}#ve(e,t,n,r){let o=this.element.id,i=`${ot}\x00${o}\x00${e}\x00${typeof t==="string"?t:JSON.stringify(t)}`;if(hr.has(i))return;let s=n?.nodeType===1?n:null,a=ea(this.#x(),(c)=>{hr.delete(i),s?.removeAttribute(he);let u=this.element.isConnected&&X.get(this.element)===this?this:o&&X.get(document.getElementById(o));if(c&&u)return r(u)});return hr.add(i),s?.setAttribute(he,""),a}#b(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},s=this.#Pe(e,r,i),a=Boolean(n||o),c=(d)=>{if(!a||!d)return;let p=this.#e();if(i.inverse=An(this,p,n,r),i.undo.push(...wn(this,p,o,r)),this.#N())i.resurrect=Sn(this,p,n,r)},u=!0;c(!0);let l=()=>this.#ke(e,t,i,s),f=()=>this.#I?this.#I.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#et(){return this.#fe("hints")}#ye(e,t,n,r,o,i){this.#G(e,Sf,t,()=>this.#b(n,r,o,e,i))}#G(e,t,n,r){let o=this.#c.get(e)?.get(t),i=()=>{this.#K(e,t),r()},s=setTimeout(i,n);if(!Jr(e))e?.addEventListener?.("blur",i,{once:!0});let a=this.#c.get(e);if(!a)this.#c.set(e,a=new Map);if(a.set(t,{timer:s,flush:i}),yl(i),o)this.#U(e,o)}#U(e,t){clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),wl(t.flush)}#K(e,t){let n=this.#c.get(e),r=n?.get(t);if(!r)return;if(this.#U(e,r),n.delete(t),n.size===0)this.#c.delete(e)}#we(){for(let[e,t]of[...this.#c])for(let n of[...t.keys()])this.#K(e,n)}#Ae(e,t,n,r,o,i){return this.#V(e,n,t,()=>this.#b(n,r,o,e,i))}#V(e,t,n,r){let o=this.#m.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#m.delete(e)},n);return o.set(t,i),this.#m.set(e,o),r()}#Se(){for(let e of this.#m.values())for(let t of e.values())clearTimeout(t);this.#m.clear()}#a(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}#u(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.#b(e,t)};me({action:e,kind:r.kind,status:r.status,root:this.element.id}),this.#a("reactive:error",{action:e,params:n,...r,retry:o})}#r(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#Ee(){this.element?.removeAttribute?.("data-reactive-error")}#xe(){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))}#_e(){return pn()}#N(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#Y(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ke(e,t,n,r){let{fields:o,files:i}=this.#Q(),s=this.#ee(t),a={...o,...s},c=this.#l,u=i.length>0,l=u?this.#Fe(c,e,a,i):JSON.stringify({token:c,act:e,params:a}),f=this.#N()?{action:e,paramNames:Object.keys(s),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#Y()}:null;await this.#_e();try{if(navigator.onLine===!1){this.#d(n.inverse),this.#r("offline"),this.#u(e,t,a,{kind:"offline"});return}let d;try{let w={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#We()};if(!u)w["Content-Type"]="application/json";let A=this.#je();if(A)w["X-Pgbus-Connection"]=A;let _=Ts(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(_)w["X-Reactive-Presence"]=_;let T=pl(this.element);if(T)w["X-Reactive-Held"]=T;ra("action"),d=await fetch(this.#qe(),{method:"POST",headers:w,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#x())})}catch(w){if(console.error("[phlex-reactive] action error",w),this.#d(n.inverse),w?.name==="TimeoutError"||w?.name==="AbortError"){this.#r("timeout"),this.#u(e,t,a,{kind:"timeout"});return}this.#xe(),this.#r("network"),this.#u(e,t,a,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#d(n.inverse),this.#r("redirected"),this.#u(e,t,a,{kind:"redirected",status:d.status});return}if(!d.ok){let w=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,w),this.#d(n.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let A=this.#X(w);if(this.#l=A??this.#l,f)Ne(f,w,A);let _=ps(this.element,w,!0,this.#x());r?.handoff?.(),await _}this.#r("http"),this.#u(e,t,a,{kind:"http",status:d.status,body:w});return}let p=d.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#d(n.inverse),this.#r("content-type"),this.#u(e,t,a,{kind:"content-type",status:d.status});return}let h=await d.text(),b=this.#X(h);if(this.#l=b??this.#l,f)Ne(f,h,b);let v=ps(this.element,h,ml(d),this.#x());if(n.resurrect)queueMicrotask(n.resurrect);if(this.#Ee(),this.#a("reactive:applied",{action:e,params:a,html:h}),r?.handoff?.(),await v)this.#r("apply"),me({action:e,kind:"apply",root:this.element.id}),this.#a("reactive:error",{action:e,params:a,kind:"apply"});return h}catch(d){console.error("[phlex-reactive] action error",d),this.#d(n.inverse),this.#r("apply"),me({action:e,kind:"apply",root:this.element.id}),this.#a("reactive:error",{action:e,params:a,kind:"apply"})}finally{if(r?.(),f)yn(this,{...f,ms:this.#Y()-f.started})}}get#l(){return this.#v??this.tokenValue}set#l(e){this.#v=e}tokenValueChanged(){this.#v=void 0}#X(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#Te(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}#Te(e){let t=this.#P;if(t&&t.id===e)return t;let n=Ol(e);return this.#P={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>`)}}#f(e){return e.closest('[data-controller~="reactive"]')===this.element}#F(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#f(t)}#Re(){let e=this.element.querySelectorAll(Y);if(e.length===0||[...e].every(Or))return()=>!0;return(t)=>{let n=pe(t,Y,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&pe(n.parentElement,Y,this.element)===this.element}}#Z(e){if(this.#f(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=pe(e,Y,this.element);return t===this.element||pe(t?.parentElement,Y,this.element)===this.element}#Le(){if(this.element.querySelectorAll(Y).length===0)return()=>!0;return(e)=>this.#Z(e)}#Q(){let e={},t=[],n=this.#Re(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((a)=>{if(!n(a))return;if(a.type==="file")for(let c of a.files??[])t.push({name:a.name,file:c,multiple:a.multiple});else r.push(a)});let o=[];this.element.querySelectorAll(`[name]${$l}`).forEach((a)=>{if(n(a))o.push(a)});let i=this.#Oe(r),s=this.#Ne(r);for(let a of r)if(i.has(a.name)){let c=e[a.name]??(e[a.name]=[]);if(a.type==="checkbox"||a.type==="radio"){if(a.checked)c.push(a.value)}else if(a.type==="hidden"){if(!s.has(a.name))c.push(a.value)}else if(a.multiple&&a.options){for(let u of a.options)if(u.selected)c.push(u.value)}else c.push(a.value)}else if(a.type==="checkbox")e[a.name]=a.checked;else if(a.type==="radio"){if(a.checked)e[a.name]=a.value}else e[a.name]=a.value;return o.forEach((a)=>{let c=a.getAttribute("name");if(!c)return;let u=a.getAttribute("data-reactive-editable")!=null?z(a):a.value??a.textContent??a.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Il(a))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}}#Oe(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}#Ne(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Fe(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[a,c]of Object.entries(n))if(Array.isArray(c)&&String(a).endsWith("[]"))if(c.length===0)i.push(String(a).slice(0,-2));else{let u=`${this.#S(a)}[]`;for(let l of c)o.append(u,String(l))}else this.#C(o,this.#S(a),c);for(let a of i)o.append("empty_groups[]",a);let s=this.#Ce(r);for(let{name:a,file:c,multiple:u}of r){let f=u||s.has(a)?`${this.#S(a)}[]`:this.#S(a);o.append(f,c,c.name)}return o}#S(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("")}`}#C(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#C(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#C(e,`${t}[${r}]`,o);else e.append(t,String(n))}#Ce(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))}#ee(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Me(e){return jr(e)}#$e(e,t){Rr(e,(n)=>this.#$(n,t),(n,r)=>this.#M(`client op "${n}"`,r))}#E(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#N()}#M(e,t){if(!this.#E())return;bn(this,e,t)}#tt(e){}#$(e,t){let n=e.to;if(n==="@root")return[this.element];if(n==="@trigger")return t?.nodeType===1?[t]:[];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...this.element.querySelectorAll(n)].filter((r)=>this.#f(r))}#te(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#d(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Pe(e,t,n){this.#Ie(e,t),Ks();let r=!1,o=!1,i=()=>{if(r)return;r=!0,this.#De(e,t);for(let a of n.undo)a()},s=()=>{if(o)return;o=!0,i(),Vs()};return s.handoff=i,s}#Ie(e,t){if(this.#p(t,e,1),this.#p(this.element,e,1),this.#h.set(e,(this.#h.get(e)??0)+1),this.#_++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#ne(e))this.#p(n,e,1)}#De(e,t){this.#p(t,e,-1),this.#p(this.element,e,-1);let n=(this.#h.get(e)??1)-1;if(n<=0)this.#h.delete(e);else this.#h.set(e,n);if(--this.#_<=0)this.#_=0,this.element.removeAttribute("aria-busy");for(let r of this.#ne(e))this.#p(r,e,-1)}#p(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#k.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.#k.delete(e),e.removeAttribute("data-reactive-busy");return}this.#k.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#ne(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#f(n))}#qe(){return this.#re??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#x(){return this.#oe??=Qs()}#We(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#je(){let e=this.element.getAttribute?.("data-reactive-subscribe"),t;if(e){for(let n of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source][connection-id]"))if(n.getAttribute("src")===e)t=n.getAttribute("connection-id")}return t||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)ys();else document.addEventListener("turbo:load",ys,{once:!0});Dr();var Kf=ha;export{Us as ACTIVE_ATTR,$l as EDITOR_SELECTOR,Pl as EDITOR_TAGS,Er as ERRORS_ATTR,nu as LATENCY_KEY,na as REQUESTS_ATTR,Nl as checkReactiveRegistration,ra as countReactiveRequest,Kf as default,Go as disableLatencySim,z as editableValue,zo as enableLatencySim,Ks as enterReactiveActivity,Ol as escapeRegExp,Vs as exitReactiveActivity,Al as flushReactiveDebounces,Df as loadReactiveFeature,Ff as onReactiveStreamWithoutEffects,Cf as reactiveActivityCount,$f as reactiveDebounceCount,qf as reactiveFeatureNames,Sl as reactiveSettled,me as recordReactiveError,ys as registerReactiveActions,Tl as registerReactiveAwaitSettled,Qu as registerReactiveDefer,Dr as registerReactiveDev,tl as registerReactiveDismiss,tl as registerReactiveEffects,vf as registerReactiveFeature,Pf as registerReactiveFeatureLoader,cl as registerReactiveImageFallback,Zu as registerReactiveJs,al as registerReactiveKeep,sl as registerReactiveModals,ll as registerReactiveMorphFocus,bl as registerReactiveOffline,ul as registerReactivePlaintext,Bl as registerReactiveRejectedFiles,tl as registerReactiveStreamRender,Yu as registerReactiveToken,Vu as registerReactiveVisit,Mf as resetReactiveActivity,Wr as serverText,If as unloadedFeaturesFor};
7
7
 
8
- //# debugId=422CFF6729A0CBC264756E2164756E21
8
+ //# debugId=C487E14BA3B8D19F64756E2164756E21
9
9
  //# sourceMappingURL=reactive_controller.min.js.map