phlex-reactive 0.16.14 → 0.18.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +118 -22
- data/README.md +72 -0
- data/app/javascript/phlex/reactive/core.js +1 -0
- data/app/javascript/phlex/reactive/core.min.js +6 -6
- data/app/javascript/phlex/reactive/core.min.js.map +4 -4
- data/app/javascript/phlex/reactive/features/presence.js +37 -3
- data/app/javascript/phlex/reactive/features/presence.min.js +2 -2
- data/app/javascript/phlex/reactive/features/presence.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/subscribe.js +188 -0
- data/app/javascript/phlex/reactive/features/subscribe.min.js +4 -0
- data/app/javascript/phlex/reactive/features/subscribe.min.js.map +10 -0
- data/app/javascript/phlex/reactive/reactive_controller.js +2 -0
- data/app/javascript/phlex/reactive/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +7 -6
- data/app/javascript/phlex/reactive/runtime.js +25 -1
- data/lib/phlex/reactive/component/dsl.rb +3 -0
- data/lib/phlex/reactive/component/helpers.rb +8 -0
- data/lib/phlex/reactive/component/presence_declaration.rb +2 -1
- data/lib/phlex/reactive/component/registry.rb +5 -2
- data/lib/phlex/reactive/component/subscribe_declaration.rb +132 -0
- data/lib/phlex/reactive/component.rb +1 -0
- data/lib/phlex/reactive/doctor.rb +51 -4
- data/lib/phlex/reactive/engine.rb +3 -3
- data/lib/phlex/reactive/subscribe.rb +150 -0
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +6 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as eu}from"@hotwired/stimulus";import{confirmResolver as Ri}from"phlex/reactive/confirm";import{confirmPredicate as ks}from"phlex/reactive/confirm_predicate";var j=new WeakMap,rt=new WeakMap;function M(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)rt.set(n.root,n)}return n}function x(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function K(e,t){x(e,"turbo:morph-element",t),e.seeds.push(t),t()}function ot(e,t){let n=M(e,t);n.offs=[],n.seeds=[];let r,o,i,s,a;(n.wire=()=>{if(!n.show&&Fs(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")zs(n,c.target);else n.groups=Gs(n),Rr(n);xr(n)},x(n,"input change",n.show),x(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]"))xr(n)}),K(n,n.show);if(!n.arm&&Ms(n))x(n,"input change",(c)=>Er(n,c)),K(n,n.arm=()=>{Er(n,null),Rr(n)});if(!r&&(r=n.show||n.arm))x(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))x(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!Ts(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=he(n)))x(n,"input",(c)=>Ys(n,c)&&Y(n)),K(n,()=>Y(n));if(!s&&(s=ge(n)))K(n,()=>Wr(n));if(!a&&(a=Qs(n)))x(n,"input change",(c)=>Hr(n,c)),K(n,()=>mt(n))})(),x(n,"keydown",(c)=>ma(n,c)),x(n,"paste drop",(c)=>ga(n,c)),x(n,"input",(c)=>ba(n,c))}function Ts(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function it(e){let t=j.get(e);if(!t)return;j.delete(e),rt.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function st(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function P(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function at(e,t,n){return Hr(M(e,t),n)}function ct(e,t,n){return Kr(M(e,t),n)}var Rs=/^#[A-Za-z_][\w-]*$/,Lr="[data-reactive-show-field], [data-reactive-show]";function Os(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 Gr){let s=e.getAttribute(`data-reactive-show-${i}`);if(s!==null)return zr(i,s,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Nr(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 Ls(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 Fr(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 X(n,t);return Ns(e,t)}function Ns(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)=>At(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function pe(e,t="show"){if(typeof e==="string"&&Rs.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Fs(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?.(Lr)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(me)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${$r}, ${Pr}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Ms(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Cs(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Ls(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Er(e,t){let n=Cs(e);if(!n.length)return;let r=Cr(e,e.core.bindingOwnership());n.forEach((o,i)=>{let s=X(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 xr(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=Cr(e,n),i=[];for(let s of e.root.querySelectorAll(Lr)){if(!t(s))continue;let a=s.getAttribute("data-reactive-show");if(a!==null){let d=Fr(Nr(a),o);if(d===null)continue;let f=s.getAttribute("data-reactive-show-after"),p=d&&(f==null||!!e.touched?.has(lt(f,r)));_r(s,p,n);let h=(e.shown??=new WeakMap).get(s);if(e.shown.set(s,p),$s.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=Os(s,u);if(l===null)continue;_r(s,l,n)}if(e.groups)Vs(e,o,t,r);Ws(e,o,t),Js(e,o,t,r,n),Ds(e,o),Ks(e,o);for(let s of i)Ps(e,s,n,r)}var $s=["clear","focus","scroll"];function Ps(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)=>lt(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,P(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 _r(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 Ds(e,t){let n=Mr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Is(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(!pe(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)=>At(l,s))}else{let l=Vr(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 Is(e,t,n){if(!pe(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=pa(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((s)=>n(s)===null)&&!ha(r))return;let i=X(r,n);if(i===null)return;for(let s of document.querySelectorAll(e))s.hidden=!i}function Mr(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 qs(e,t,n,r){let o=!1,i=null;for(let s of e.root.querySelectorAll(ut(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 ut(e,t){return`[name="${lt(e,t)}"]`}function lt(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Cr(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?ft(e,o,t,n).filter((a)=>a.checked).length:qs(e,o,t,n));return r.get(s)}}var $r="[data-reactive-media]";function Ws(e,t,n){for(let r of e.root.querySelectorAll($r)){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"){kr(r,"pending");continue}let d=!l&&Object.hasOwn(o.pool,u)?Tr(e,o.pool[u])[0]:null,f=e.core.copyMedia(r,d??null);if(f===null)continue;if(kr(r,l?"pending":f===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":f===!1?String(o.blank??""):f;for(let h of Tr(e,o.label))if(h.textContent!==p)h.textContent=p}}function kr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Tr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Pr="[data-reactive-css-vars]",js=/^--[a-z0-9-]+$/i,Bs=["","px","%","deg","turn","ms","s","em","rem","fr"];function Js(e,t,n,r,o){let i=[...e.root.querySelectorAll(Pr)].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},d=[];try{d=e.core.opTargets(l)}catch{}if(!d.length)e.core.diagnose("reactive_css_vars",l);return d});for(let[u,l]of Object.entries(a.vars)){let d=l?.unit??"";if(!js.test(u)||!Bs.includes(d)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let f=Hs(e,t,l.field,o,r);if(f===void 0)continue;let p=f===null?"":`${f}${d}`;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 Hs(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(ut(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 me="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Gs(e){return!!e.root.querySelector?.(me)}function ft(e,t,n,r,o){return[...e.root.querySelectorAll(ut(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Us(i.getAttribute("data-reactive-group"),o)))}function Us(e,t){return e===t||!!e?.startsWith(`${t}.`)}function zs(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Dr(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function dt(e,t,n){if(!t)return;let r=rt.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Dr(r,t,n!==!1),r.show?.()}function Dr(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,s=ft(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 Vs(e,t,n,r){for(let o of e.root.querySelectorAll(me)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Fr(Nr(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=ft(e,a,n,r,c).filter((d)=>d!==o),l=u.filter((d)=>d.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function Ks(e,t){for(let[n,r]of Object.entries(Mr(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(!pe(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(!pe(s,"group"))continue;let c=X(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 Rr(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?.(`${me}, [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 he(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Ys(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var Xs=/[\s\-'(),./]/;function Zs(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||Xs.test(t[r-1]))return!0;return!1}function Y(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=(f)=>{let p=(f??"").toLowerCase().trim();return s?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=a(o.value),u=0;for(let f of e.root.querySelectorAll(n)){if(!r(f))continue;let p=f.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Zs(i,a(f.getAttribute("data-reactive-filter-text")??f.textContent),c);if(f.hidden=p,p)f.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let f of e.root.querySelectorAll(l)){if(!r(f))continue;let p=[...f.querySelectorAll(n)].filter(r);if(p.length===0)continue;f.hidden=p.every((h)=>h.hidden)}let d=e.root.getAttribute("data-reactive-filter-empty");if(d){for(let f of e.root.querySelectorAll(d))if(r(f))f.hidden=u>0}}function ge(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Qs(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function pt(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 ht(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 Ir(e,t){let n=pt(e);if(!n)return!1;let r=ht(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)qr(e,n,r);return i}function qr(e,t,n){t.value=n.join(","),P(t),Wr(e)}function ea(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 Wr(e){let t=pt(e);if(!t)return;let n=ht(t),r=e.core.ownership();ta(e,n,r),na(e,n,r)}function ta(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 na(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"),!he(e))o.hidden=!1}}if(he(e))Y(e)}function ra(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function oa(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 ia(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 sa(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 d=s.find((f)=>Br(f.getAttribute?.("name"))===c);if(!d)continue;if(aa(d,l),!a.includes(l))a.push(l)}if(r)for(let c of a)ca(c,r);return a[0]??null}function aa(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:tt(t)!=="";else e.value=tt(t);P(e)}function ca(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??"":"";P(e)}function ua(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Or(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",P(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);mt(e)}function mt(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))Jr(e,n.getAttribute("data-reactive-nested-json"))}function la(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 jr(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=Br(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=tt(o)}return n}function Br(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function tt(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Jr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=la(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(jr(e,a))}let s=JSON.stringify(i);if(o.value===s)return;o.value=s,P(o)}function gt(e,t,n){let r=M(e,t);if(!ge(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(!Ir(r,String(o.value??"").split(",")))return;if(o.value="",he(r))Y(r)}function bt(e,t,n){let r=M(e,t);if(!ge(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Ir(r,[i]))return;let s=ea(r);if(!s)return;s.value="",Y(r),s.focus?.()}function vt(e,t,n){let r=M(e,t);if(!ge(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let s=pt(r);if(!s)return;let a=ht(s),c=a.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===a.length)return;qr(r,s,c)}function yt(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){ia(r,i);return}let l=u.cloneNode(!0);oa(l,ra(r)),a.appendChild(l);let d=o?.getAttribute?.("data-reactive-nested-from-param"),f=o?.getAttribute?.("data-reactive-nested-clear-param"),h=sa(r,l,d,f==="true"||f==="reset"?f:null);if(d)h?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(a.getAttribute?.("data-reactive-nested-json")===i)Jr(r,i)}function wt(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?Kr(r,a):null);if(!c)return Or(r,i);let u=jr(r,i),l=ua(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((d)=>{if(d)Or(r,i)})}function Hr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;mt(e)}var Gr=["gte","gt","lte","lt"],fa=["len_eq","len_gte","len_gt","len_lte","len_lt"],Ur=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],da=["digits_eq","digits_gte","digits_lt","digits_lte"];function nt(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 zr(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 Vr(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 Gr)if(n in e)return zr(n,e[n],t);for(let n of fa)if(n in e)return nt(n,e[n],[...String(t??"")].length);return null}function At(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Ur.find((i)=>(i in e));if(n){let i=t(e.field,!0);return nt(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=da.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)=>nt(a,e[a],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return Vr(e,o)===!0}function X(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>At(r,t)))}function pa(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 ha(e){return e.flat().every((t)=>Ur.some((n)=>(n in Object(t))))}function Kr(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=ks(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=X(n.groups?.any,o)===!0;return i?n.message:null}function St(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ma(e,t){let n=St(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),P(n),n.blur()}function ga(e,t){let n=St(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 ba(e,t){let n=St(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as va}from"phlex/reactive/compute";var Q=new WeakMap;function eo(e,t){let n=Q.get(e);if(!n)Q.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Et(e,t,n,r){let o=eo(e,t),i=Ma(o);if(i){o.seed=()=>be(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(s)=>s.target!==o.root&&[...s.target.querySelectorAll(Xr)].some(o.core.bindingOwns)&&o.seed();for(let s of to)o.root.addEventListener?.(s,o.nested)}if(o.share=(s)=>s.target?.matches?.(Xr)&&!o.core.owns(s.target)&&o.core.bindingOwns(s.target)&&be(o,s),o.root.addEventListener?.("input",o.share),i||r?.edited)be(o)}function xt(e){let t=Q.get(e);if(!t)return;if(Q.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of to)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function _t(e){Q.get(e)?.seed?.()}function kt(e,t,n){return be(eo(e,t),n)}var Xr="[data-reactive-shared-field]",to=["reactive:connect","reactive:persist-restored"],ya=Object.freeze({el:null,kind:""}),wa=/^#[A-Za-z_][\w-]*$/;function Z({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 no(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Aa(e,t){if(t==="string")return Z(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):no(Z(e));if(n)return e.el.checked?1:0;let r=Number(Z(e));return Number.isFinite(r)?r:0}function Sa(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let s=no(i);if(Boolean(n.checked)===s)return null;return n.checked=s,n}if(r==="radio")return Ea(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function Ea(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 xa(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 _a(e){if(typeof e==="string"&&wa.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function ka(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 Ta(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 Ra(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 Oa(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=La(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function La(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Zr(e,t,n){let r=String(n);for(let o of Na(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Na(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Qr(e,t,n){let r=Fa(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?Z(s):void 0;if(a===void 0||a===null)continue;let c=String(a);for(let u of Array.isArray(i)?i:[i]){if(!_a(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Fa(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 Ma(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function be(e,t){if(t&&e.ours.has(t))return;let n=Ra(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,E=null;for(let T of e.root.querySelectorAll(`[name="${i(v)}"]`)){if(!s(T))continue;let de=T.type;if(de==="checkbox"||de==="radio"&&T.checked){E={el:T,kind:de};break}if(de==="radio")w??=T;else A??=T}if(!E)if(w)E={el:w,kind:"radio"};else E=A?{el:A,kind:""}:ya;return a.set(v,E),E};for(let v of r)Zr(e,v,Z(c(v)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?va(u):null;if(!l){Qr(e,{},c);return}let d=Ta(e,"data-reactive-compute-outputs-param"),f={};for(let[v,m]of n)f[v]=Aa(c(v),m);let p=l(f,{changed:Oa(e,t,r,o)})||{},h=xa(p.$ops),b=[];for(let v of d){if(v==="$ops"||!(v in p))continue;let m=c(v);if(!m.el)continue;let w=Sa(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;Zr(e,v,m)}Qr(e,p,c);for(let v of b){let m=new Event("input",{bubbles:!0});e.ours.add(m),v.dispatchEvent(m)}ka(e,h,Boolean(t))}var Lt;function Nt(e){Lt=e}var ao=1,Ca="phlex-reactive:persist:",$a=new Set(["hidden","file","password","submit","button","reset","image"]),Ft=Symbol("persist-no-value"),Mt="data-reactive-persist-state",Pa=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Da=new Set(["lexxy-editor","trix-editor"]),Ia="lexxy-editor, trix-editor, trix-toolbar",qa=["lexxy:change","trix-change"],Wa=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),oo=new WeakSet,io=new WeakSet,so=new WeakSet;function ye(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(!oo.has(e))oo.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Ct(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function $t(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||io.has(e))return;io.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Pt(e){return Ca+e.key}function Rt(e,t){let n=Ct(t);if(!n)return null;let r;try{r=n.getItem(Pt(t))}catch(c){return $t(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==ao)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return ve(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 co(e,t,{fields:n,state:r}){let o=Ct(t);if(!o)return!1;let i={v:ao,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Pt(t),JSON.stringify(i)),!0}catch(s){return $t(e,s),!1}}function ve(e,t){e?.removeAttribute?.(Mt);let n=Ct(t);if(!n)return;try{n.removeItem(Pt(t))}catch(r){$t(e,r)}}function Dt(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||$a.has(i.type)||i.closest(Ia))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Pa)){if(!o(i))continue;let s=ja(i);if(!s||n&&!n.has(s))continue;r.push({el:i,name:s,kind:Da.has(i.localName)?"editor":"contenteditable"})}return r}function uo(e){return e.hasAttribute("data-reactive-editable")?Lt.text(e):e.textContent??""}function ja(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function It(e){return typeof e.value==="string"}function Ba(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Wa.has(e.value.trim())}function Ja(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||so.has(e))return;so.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function ee(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 fo(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Ft;return e[0]}function po(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 Dt(e,t)){let a=String(i).endsWith("[]");if(s==="editor"){if(It(o))if(a)r(i).push(o.value);else n[i]=o.value}else if(s==="contenteditable"){let c=uo(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(ee(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 Ha(e,t,n){let r=t.restore==="always",o=Dt(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)&&ee(a)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(a.type==="checkbox"||ee(a))){if(l=fo(l,c,i),l===Ft)continue}if((a.type==="checkbox"||ee(a))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")ho(e,a,c,l,r);else if(u==="contenteditable"){if(!r&&uo(a).trim()!=="")continue;a.textContent=String(l)}else if(a.type==="radio"){if(!r&&o.some((d)=>d.kind==="native"&&d.el.type==="radio"&&d.name===c&&d.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(ee(a)){if(!r&&[...a.options].some((f)=>f.selected))continue;let d=new Set((Array.isArray(l)?l:[l]).map(String));for(let f of a.options)f.selected=d.has(f.value)}else{if(!r&&a.value!=="")continue;a.value=String(l)}}Ga(e,t,n)}function ho(e,t,n,r,o){if(Array.isArray(r))return;if(!It(t))return;if(!o&&!Ba(t))return;try{t.value=String(r)}catch(i){Ja(e,n,i)}}function Ga(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(!It(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=Dt(e,t),c=lo(a);for(let{el:u,name:l,kind:d}of a){if(d!=="editor"||u.localName!==s||!Object.hasOwn(n,l))continue;let f=fo(n[l],l,c);if(f===null||f===void 0||f===Ft)continue;ho(e,u,l,f,i)}})}function Ua(e,t,n=!0){let r=ye(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=Rt(e,r),i={...o?.state??{},...t},s=n?po(e,r):o?.fields??{};if(co(e,r,{fields:s,state:i}))e.setAttribute?.(Mt,JSON.stringify(i))}function za(e){let t=ye(e);if(t)ve(e,t)}var Ot=new WeakMap,Tt=new WeakMap;function Va(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=Tt.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],Tt.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),Tt.delete(e)}}function qt(e,t,n,r){let o=e.element,i=ye(o);if(!i)return;if(r?.submitted)ve(o,i);let s=Rt(o,i);if(s){if(Ha(o,i,s.fields),s.state)o.setAttribute?.(Mt,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=Rt(o,i);co(o,i,{fields:po(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)},d=(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(),ve(o,i)},f=["input",...qa];for(let h of f)o.addEventListener?.(h,l);o.addEventListener?.("change",u);let p=Va(globalThis.document,d);if(Ot.set(e,()=>{if(a!==null)u();for(let h of f)o.removeEventListener?.(h,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let h of r?.ops??[])h(!0)}function Wt(e){let t=Ot.get(e);Ot.delete(e),t?.()}function mo(e,t){let n=Lt?.waiting.get(e)?.persist;if(!n||!ye(e))return t(!0);(n.ops??=[]).push(t)}function jt(e,t){mo(e,(n)=>Ua(e,t,n))}function Bt(e){mo(e,()=>za(e))}var we=new WeakMap,bo=new WeakSet,Jt=new WeakMap;function Ht(e,t){let n=e.element,r=[],o=[],i=(u,l,d)=>{u.addEventListener?.(l,d),r.push(()=>u.removeEventListener?.(l,d))},s,a,c=()=>{if(!s&&(s=Ka(n,t))){let u=()=>Ae(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Za(n,r)}if(!a&&(a=Qa(n,t))){let u=()=>ec(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};we.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Gt(e){for(let t of we.get(e)?.[0]??[])t();we.delete(e)}function Ut(e){we.get(e)?.[1]()}function Ka(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 Ae(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,Ya(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 Ya(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 Xa(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Za(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Jt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(Xa(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(bo.has(c)||!i())return;if(bo.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),Jt.delete(n)}},Jt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Qa(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 ec(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 Yt(e){tc(e),rc(e)}function tc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(zt);else setTimeout(zt,0);return}let r=async(o)=>{await n(o),zt()};r.__reactiveDismissWrapped=!0,t.render=r}function zt(){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 nc=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Vt=Object.freeze(["fade","slide","scale","highlight","shake"]),Kt="data-reactive-fx-pending",Xt=1000;function rc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=nc[r?.getAttribute?.("action")];if(!o||sc())return;let i=oc(r,o);if(!i)return;let s=o==="exit"?async(a)=>{await uc(Se(r),i),await n(a)}:async(a)=>{let c=o==="enter"?ac(r):null;if(await n(a),o==="enter")cc(c,i);else wo(Se(r),i)};s.__reactiveEffectsWrapped=!0,t.render=s}function oc(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return yo(n,t);let o=(t==="enter"?ic(e):Se(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?yo(o,t):null}function Se(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function ic(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function yo(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"?Vt[Math.floor(Math.random()*Vt.length)]:e;if(!Vt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function sc(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function ac(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Kt,"");return Se(e)}function cc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Kt}]`)))n.removeAttribute(Kt),wo(n,t)}async function uc(e,t){if(!e?.classList)return;if(t.legs){await Ao(e,t.legs);return}e.classList.add(t.className);let n=Zt(e);if(n<=0){e.classList.remove(t.className);return}await Qt(e,n),e.classList.remove(t.className)}function wo(e,t){if(!e?.classList)return;if(t.legs){Ao(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Zt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Qt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Ao(e,t){let[n,r,o]=t.map(lc),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await fc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let s=Zt(e);if(s>0)await Qt(e,s);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function lc(e){return String(e??"").split(/\s+/).filter(Boolean)}function Zt(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,Xt)}catch{return 0}}function Qt(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,Xt))})}function fc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Xt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var dc="phlex-reactive:latency",en=!1;function xo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function _o(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),en=!1}function nn(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:xo,disableLatencySim:_o}}function rn(){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(!en)en=!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 Eo=new WeakMap;function on(e){let t=globalThis.document;if(!t)return!0;let n=Eo.get(t);if(!n)n=new Set,Eo.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function tn(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function pc(e,t){try{return e?.matches?.(t)===!0}catch{return!1}}function ko(e,t,n,r){if(on(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function sn(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=tn(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}ko(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function an(e){if(!on(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function cn(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(pc(r,o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(tn(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let s=tn(globalThis.document,o);if(s>0)i=` — it matches ${s} element(s) outside this scope; use global: true`}ko(t,o,`scoped to #${r?.id||"?"}`,i)}function un(e,t){let n=e.element?.id||"?";if(on(`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 hc(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 ln(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 Ee(e,t,n){e.streams=hc(t),e.tokenRefreshed=n!=null}var xe=new WeakMap;function fn(e,t,n,r){let o=n&&typeof n==="object"?bc(n):n;return o?Ro(t,o,r,!1):[]}function dn(e,t,n,r){if(!n)return null;let o=Ro(t,n,r,!0);return o.length?o:null}function Ro(e,t,n,r){let o=[];for(let i of Oo(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(mc(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Oo(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 mc(e,t){let n=xe.get(t);if(n)n.count++;else xe.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()=>gc(t,e)}function gc(e,t){let n=xe.get(e);if(!n)return;if(--n.count>0)return;if(xe.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function bc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function pn(e,t,n,r){if(!n?.hide)return null;let o=Oo(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 B;function gn(e){B=e}var L=new Map;function Mo(e,t){let n=!L.has(e);if(L.set(e,t),n)B.enter()}function Te(e){if(L.delete(e))B.exit()}var No=!1;function bn(e){Co();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Ec(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;ne(t,n)}function Co(){if(No||typeof document>"u"||!document.addEventListener)return;No=!0,document.addEventListener("turbo:before-stream-render",_c,!0),document.addEventListener("turbo:before-stream-render",vc)}function vc(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")Te(n)}function ne(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}yn(e),Io(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Mo(e,r),xc(e,r,t)}function yc(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[Tc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Rc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function $o(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Po(t))return{src:t};return console.error(wc(t)),Ac(t)||Sc(e)}function wc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${vn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Ac(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${vn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Po(r))return{src:r,fallback:!0}}function Sc(e){B.fail({kind:"defer",root:e.id}),yn(e.id),wn(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 Po(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${vn()}/`)}catch{return!1}}function vn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Ec(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){ne(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}yn(e),Io(n);let o=document.createElement("pgbus-stream-source");o.id=Do(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Mo(e,{via:"stream"})}function Do(e){return`reactive-defer-src-${e}`}async function xc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Oc()),o;try{B.count("defer"),o=await fetch(...yc(n,t.abort.signal))}catch(a){if(clearTimeout(r),L.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",a),te(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"}`),te(e,n,o.status);return}if(o.status===204){clearTimeout(r),Fo(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),te(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}"`),te(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),te(e,n);return}if(clearTimeout(r),L.get(e)!==t)return;Fo(e),kc(s)}var mn=null,_c=(e)=>mn?.push(e);function kc(e){let t=mn=[];try{window.Turbo.renderStreamMessage(e)}finally{mn=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 yn(e){let t=L.get(e);if(!t)return;if(Te(e),t.via==="fetch")t.abort.abort();else document.getElementById(Do(e))?.remove?.()}function Io(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function wn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Fo(e){Te(e);let t=document.getElementById(e);if(!t)return;wn(t),t.removeAttribute("data-reactive-error")}function te(e,t,n){B.fail({kind:"defer",status:n,root:e}),Te(e);let r=document.getElementById(e);if(!r)return;wn(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"),ne(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function Tc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Rc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Oc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var qo="__materialize",ke=new WeakMap;function _e(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function An(e,t,n){Co();let r=e.element,o=!1,i=!1,s=null,a=null,c,u,l=()=>Re(e),d=(m)=>{if(_e(r)==="visible"){if(!s)p()}else if(m){let w=r.getAttribute("data-reactive-lazy-on");if(a===w)return;f(),r.addEventListener?.(w,l),a=w}},f=()=>{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=_e(r)!==null,w=o;if(o=m,!m)return f();if(i)return;if(t.forgetToken(),!w)return l();d(!0)};if(ke.set(e,{load(){if(i)return;let m=$o(r);if(!m&&r.getAttribute("data-reactive-defer-src")!=null)return;if(m&&Lc(r,t))return;let w=m?ne(r.id,m):t.proceed(r,qo,"{}");if(!w)return;i=!0,f();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);f()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&_e(r)===null)hn(r),c=(m)=>m.target===r&&hn(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)hn(r);h()},r.addEventListener?.("turbo:morph-element",u),n)return h();if(o=_e(r)!==null,o)d(!1)}function Sn(e){let t=ke.get(e);ke.delete(e),t?.off()}function Re(e){return ke.get(e)?.load()}function Lc(e,t){return t.emit("reactive:before-dispatch",{action:qo,params:{},element:e},{cancelable:!0}).defaultPrevented}function hn(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||$o(e);if(t)ne(e.id,t)}var En=new WeakMap,Le=new WeakMap,g=null,D,jo;function Tn(e,t){let n=e.element;Le.set(n,t),Yo();let r=(i)=>Fc(i,t),o=(i)=>Dc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),En.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Rn(e){if(En.get(e)?.(),En.delete(e),Le.delete(e.element),g&&Ne(g.origin)===e.element)Oe()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),re=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},Ne=(e)=>e?.closest?.('[data-controller~="reactive"]'),Go=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),C=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&Go(t)===e),Bo=(e)=>re(S(e,"-item"),null),xn=(e)=>S(e,"-disabled")==="true",Nc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Uo=(e)=>{let t=S(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>S(n,"-group")===t&&!xn(n)&&Le.has(Ne(n)))};function zo(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Go(n);if(g||!r||!t.owns(r)||xn(r)||xn(n))return;if(Ne(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Fc(e,t){if(e.button>0||e.isPrimary===!1)return;let n=zo(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,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 _n(m.clientX,m.clientY);if(Math.abs(m.clientX-o)<=4&&Math.abs(m.clientY-i)<=4)return;if(!c)return v();Cc(n,t,m),_n(m.clientX,m.clientY)},d=(m)=>g&&m.cancelable&&m.preventDefault(),f=(m)=>{if(!s(m))return;if(v(),g)Mc(),kn()},p=(m)=>{if(m.type==="pointercancel"&&!s(m))return;if(v(),g)Oe()},b=[["pointermove",l],["pointerup",f],["pointercancel",p],["keydown",(m)=>m.key==="Escape"&&g&&(m.preventDefault(),p(m))],["touchmove",d,{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 Mc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Cc({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=Vo({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 Vo(e){let{row:t,origin:n,source:r}=e;return e.index=C(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),oe(n,!0),e}var oe=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Fe(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 _n(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=Uo(g.origin).find((r)=>Nc(r,e,t));if(n)$c(n,e,t);else if(g.source)On(null),g.placeholder.remove();Pc(e,t)}function On(e){if(g.target!==g.origin)oe(g.target,!1);g.target=e,oe(e,!0)}function $c(e,t,n){On(e);let r=C(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});Fe(e,r,a<0?r.length:a,g.placeholder)}function Pc(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);_n(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function Dc(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":kn,Enter:kn,Escape:Oe,Tab:Oe,ArrowUp:()=>Jo(-1),ArrowDown:()=>Jo(1),ArrowLeft:()=>Ho(-1),ArrowRight:()=>Ho(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=zo(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),g=Vo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Ce("picked")}function Jo(e){let t=C(g.target),n=Me()+e;if(n>=0&&n<=t.length)Fe(g.target,t,n,g.row);Ko()}function Ho(e){let t=Uo(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=Me();On(n),Fe(n,C(n),r,g.row)}Ko()}function Ko(){g.row.focus?.(),Ce("moved")}function Me(){let e=C(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Yo(){if(!D?.isConnected)D=document.createElement("div"),D.setAttribute("aria-live","polite"),D.setAttribute("data-reactive-sortable-live",""),D.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(D);return D}function Ce(e){let t=g.target??g.origin,n=(re(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Me()+1).replaceAll("{count}",C(t).length+1),r=Yo();r.textContent="",cancelAnimationFrame(jo),jo=requestAnimationFrame(()=>r.textContent=n)}function kn(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,s=t&&(r?i.isConnected:!0),a=s?Me():-1,c=s?Bo(C(t)[a-1]):null;if(e.keyboard)Ce("dropped");if(!r&&i)i.replaceWith(o);if(Zo(e),!s||t===n&&a===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=re(S(t,"-from"),{})[u]??S(t),d={...re(S(t,"-params"),{}),item:Bo(e.item),position:a,after:c,from:u},f=[];for(let h=t;h;h=h.parentElement)f.push(h);let p=Le.get(Ne(t))?.proceed(t,l,JSON.stringify(d),re(S(t,"-busy")));if(r)return;Promise.resolve(p).then((h)=>Ic(h,f)||Xo(e))}function Ic(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"))&&qc(r,t))}function qc(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 Oe(){let e=g;if(e.keyboard)Ce("cancelled");e.placeholder?.remove(),Zo(e),Xo(e)}function Xo({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Fe(t,C(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Zo(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(),oe(n,!1),oe(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var ri={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},oi={x:"left",y:"top",width:"width",height:"height"},Ln=new WeakMap,Mn=new WeakMap,y=null,I,ei,ti=!1;function Cn(e,t){let n=e.element;Mn.set(n,t),hi(),Yc();let r=[["pointerdown",(o)=>Gc(o,t,n)],["keydown",(o)=>Kc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&ri[o.key]&&Fn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&Fn()],["input",(o)=>ni(o,t,n)],["change",(o)=>ni(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);Ln.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function $n(e){if(Ln.get(e)?.(),Ln.delete(e),Mn.delete(e.element),y?.root===e.element)H(y)}var R=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e)=>Math.round(e*1e4)/1e4;function Wc(e,t=1){let n=N(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Pn(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 ii(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 si(e,t,n){return{x:R(e.x+t,0,1),y:R(e.y+n,0,1)}}function ai(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,d=e.y+e.height,f=e.x+e.width/2,p=e.y+e.height/2,h=a?1-e.x:u?l:i?2*Math.min(f,1-f):1,b=c?1-e.y:s?d: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:f-v/2,y:s?d-m:c?e.y:p-m/2,width:v,height:m}}function jc(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 Bc(e){let[t,n=1,r]=String(e??"").split(":").map(Number),o=r===void 0?t/n:0;return o>0&&Number.isFinite(o)?o:0}var _=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Dn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},F=(e)=>e.matches("[data-reactive-point]")?"point":"box",ci=(e)=>Number(_(e,`${F(e)}-scale`))||1,J=(e)=>F(e)==="point"?["x","y"]:["x","y","width","height"];function ui(e){let t={};for(let n of J(e))t[n]=(parseFloat(e.style[oi[n]])||0)/100;return t}function $e(e,t){for(let n of J(e))e.style[oi[n]]=`${Math.round(t[n]*1e4)/100}%`}function In(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 Jc(e,t){try{return e.parentElement.closest(_(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function li(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function fi(e,t,n){let r=Dn(_(e,F(e)),{}),o={};for(let i of J(e)){let[s]=li(t,n,r[i]);if(s)o[i]=s}return o}function Hc(e,t,n,r){let o=_(e,"box-aspect"),i=o&&li(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),s=o?Bc(i?.value):Number(_(e,"box-ratio"))||0,{width:a,height:c}=In(t);return s&&a&&c?s*c/a:0}function qn(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=ui(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?Jc(o,i):i,edge:_(n,"box-handle"),start:s,value:s,ratio:c?0:Hc(o,i,t,e),min:Number(_(o,"box-min"))||0,scale:ci(o),fields:a,before:Object.fromEntries(Object.entries(a).map(([u,l])=>[u,l.value]))}}function di(e,t,n,r){let o=Wc(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function ie(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))di(e.core,n,e.value[t],e.scale)}function Gc(e,t,n){if(pi(),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)&&qn(t,n,r,!1);if(!o)return;let{clientX:i,clientY:s}=e,a=In(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 Nn(b.clientX,b.clientY);if(Math.abs(b.clientX-i)<=4&&Math.abs(b.clientY-s)<=4)return;zc(o),Nn(b.clientX,b.clientY)},l=(b)=>{if(!c(b))return;if(h(),y)Uc(),Fn()},d=(b)=>{if(b.type==="pointercancel"&&!c(b))return;if(h(),y)bi()},p=[["pointermove",u],["pointerup",l],["pointercancel",d],["keydown",(b)=>b.key==="Escape"&&y&&(b.preventDefault(),d(b))]];for(let[b,v]of p)document.addEventListener(b,v);function h(){for(let[b,v]of p)document.removeEventListener(b,v)}}function Uc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function zc(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 Nn(e,t){let n=y;if(!n.el.isConnected)return H(n);n.x=e,n.y=t;let r=In(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=Pn(F(n.el)==="point"?si(s,o,i):a?ai(s,a,o,i,n.min,n.ratio):ii(s,o,i)),$e(n.el,n.value),n.writing||=requestAnimationFrame(()=>ie(n)),Vc(t)}function Vc(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),Nn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function pi(){if(y&&!y.el.isConnected)H(y)}function Kc(e,t,n){pi();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(),bi());let o=ri[e.key];if(!o)return;if(e.preventDefault(),y??=qn(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=Pn(F(y.el)==="point"?si(c,i,s):a?ai(c,y.edge??"se",i,s,y.min,y.ratio):ii(c,i,s)),$e(y.el,y.value),ie(y),mi(y,a?"resized":"moved")}function hi(){if(!I?.isConnected)I=document.createElement("div"),I.setAttribute("aria-live","polite"),I.setAttribute("data-reactive-drag-live",""),I.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(I);return I}function mi(e,t){let n=Dn(_(e.el,`${F(e.el)}-messages`),{})[t]??"";for(let o of J(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=hi();r.textContent="",cancelAnimationFrame(ei),ei=requestAnimationFrame(()=>r.textContent=n)}function ni(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(_(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=qn(t,n,o,!0),{ratio:s,start:a}=i??{};if(!s||Math.abs(a.width/a.height/s-1)<0.005)continue;i.value=Pn(jc(a,s,i.min)),$e(o,i.value),ie(i),gi(i)}}function Fn(){let e=y;if(!e.el.isConnected)return H(e);ie(e),H(e),gi(e)}function gi(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=_(e.el,`${t}-action`),r={};for(let o of J(e.el))r[o]=N(e.value[o]);if(!n||J(e.el).every((o)=>r[o]===N(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Dn(_(e.el,`${t}-busy`)))}function bi(){let e=y;if(e.value=e.start,$e(e.el,e.start),ie(e),e.keyboard)mi(e,"cancelled");H(e)}function H(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 Yc(){if(ti)return;ti=!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=Mn.get(n);if(!r?.owns(t))return;let o=ui(t),i=ci(t);for(let[s,a]of Object.entries(fi(t,n,r)))di(r,a,o[s],i)})}var q=new Map,yi=new WeakSet;function Wn(e,t){let n=e.element,r=q.get(n.id);if(!r)q.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Xc(n);let o=(s)=>s.target===n&&queueMicrotask(()=>Ai(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)},Ai(r)}function jn(e){let t=e.element,n=q.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;q.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function Bn(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=q.get(e.id);if(!n)q.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},Si(n)}function Xc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&yi.has(n))return;if(n?.remove(),!wi())setTimeout(()=>{if(!wi())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=q.get(e.id);if(!o||o.removing)return;Si(o),Zc(o)}),yi.add(r),document.body.appendChild(r)}var wi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Zc(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&&Ei(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 Si(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 Ei(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 Ai(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=Ei(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 _i=new Map,Jn=new WeakMap,Qc=0,Pe=new WeakMap;function Hn(e,t){let n=e.element;if(!n.id&&!Jn.has(n))Jn.set(n,`#${++Qc}`);let r=n.id||Jn.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);ki(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)=>{ki(p,"0:00","done"),u(h.waiting,!1),u(h.done,!0);let v=_i.get(b)??new Set;if(v.has(h.until))return;_i.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,!Pe.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)},d=()=>{if(i)return;i=!0,queueMicrotask(l)},f=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",d),n.addEventListener("reactive:streamed",d),document.addEventListener("visibilitychange",f),Pe.set(e,()=>{n.removeEventListener("turbo:morph-element",d),n.removeEventListener("reactive:streamed",d),document.removeEventListener("visibilitychange",f);for(let p of[...o.keys()])s(p)}),l()}function Gn(e){Pe.get(e)?.(),Pe.delete(e)}function ki(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 tu(){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 nu(){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 ru=["focus","focus_first","blur"];function ou(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=wr(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)an(n);return}let i=(a)=>ar(a,(c)=>Qu(c,o),r?(c,u)=>sn(c,u,o):void 0),s=t.findIndex((a)=>ru.includes(a?.[0]));if(s<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,s)),requestAnimationFrame(()=>i(t.slice(s)))}}function iu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){bn(this)}}var Oi=!1,su=null;function au(){if(Oi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Oi=!0,document.addEventListener("turbo:before-stream-render",(e)=>{Au(e),cu(e),lu(e),Yt(e)})}var Be="reactive:streamed";function cu(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(Be))}}function lr(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function fr(e){try{return e.matches(":modal")}catch{return!1}}function os(e){if(!lr(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 uu(e){if(lr(e)&&e.open)e.close()}function Ve(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))os(r)}function lu(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),Ve(document)}}var Li=!1;function fu(){if(Li)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Li=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Ve(t.target)}),document.addEventListener("turbo:morph",()=>Ve(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!lr(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 nr=new WeakMap;function is(e,t,n,r){let o=nr.get(e)??new Map;nr.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"))ws(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}))is(s,"set_attr",{name:"aria-expanded"})}}var Ni=!1;function du(){if(Ni)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ni=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of nr.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 dr="data-reactive-image-fallback",z="data-reactive-image-state",rr="data-reactive-image-hidden",Un=null,or="data-reactive-wrap-hidden";function ss(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(or,"")}function as(e){if(!e.hasAttribute(or))return;e.removeAttribute("hidden"),e.removeAttribute(or)}function le(e){if(e?.localName!=="img")return null;let t=e.getAttribute(dr);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var cs=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function pr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function us(e,t){let n=pr(e,t.alt);return n&&!n.contains(e)?n:null}function Ke(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(rr,"");if(t.wrap){let o=pr(e,t.wrap);if(o)ss(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=us(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Qe(e,t);e.setAttribute(z,n)}function Qe(e,t=le(e)){if(!t||e.getAttribute(z)==null)return;if(e.getAttribute(z)==="error"){if(e.hasAttribute(rr))e.removeAttribute("hidden");let n=pr(e,t.wrap);if(n)as(n);let r=us(e,t);if(r)r.hidden=!0}e.removeAttribute(z),e.removeAttribute(rr)}function Fi(e){let t=e.target,n=le(t);if(!n)return;if(e.type==="load")Ke(t,n,"loaded");else if(cs(t))Ke(t,n,"error");else Qe(t,n)}function pu(){if(Un)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;Un={error:Fi,load:Fi,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(z);if(o==null||!r||!le(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=le(n);if(o)Ke(n,o,r)})},"turbo:frame-render":(t)=>De(t.target),"turbo:render":()=>De(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[${dr}]`))return;n.render=async(i)=>{await r(i),De(document)}}};for(let[t,n]of Object.entries(Un))document.addEventListener(t,n,!0);De(document)}function De(e){for(let t of e?.querySelectorAll?.(`img[${dr}]`)??[]){if(t.getAttribute(z)!=null||!t.complete||!cs(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Ke(t,le(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 El(e){su=e}var Ie,zn=null,Mi="[data-reactive-editable][contenteditable=plaintext-only]";function ls(){if(Ie===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Ie=e.contentEditable==="plaintext-only"}catch{Ie=!1}return Ie}function Je(e){if(e.matches?.(Mi))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Mi).forEach(Je)}function hu(){if(zn||typeof document>"u"||typeof document.createElement!=="function")return;if(ls())return;Je(document),zn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Je(t.target);else t.addedNodes.forEach(Je)}),zn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Ci=!1;function $i(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 mu(){if(Ci)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ci=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=$i(t);if(r)bu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Ye.set(t,W(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)=>vr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===O)&&$i(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(O)&&mr(t)===gr(t))t.removeAttribute(O)})}var O="data-reactive-held",hr='[data-controller~="reactive"]',He=null,U=new Map;function mr(e){return e.hasAttribute("data-reactive-editable")?W(e):e.value}function gr(e){return e.hasAttribute("data-reactive-editable")?yr(e):e.defaultValue}function gu(e){if(e.hasAttribute("data-reactive-editable"))return W(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function bu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||U.has(e.closest(hr)))return;let r=gu(t);if(r===mr(e))return e.removeAttribute(O);if(r===gr(e))return;e.setAttribute(O,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function vu(e){let t=[];for(let n of e.querySelectorAll(`[${O}]`)){if(n.closest(hr)!==e)continue;let r=n.getAttribute("name");if(mr(n)===gr(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 fs(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${O}]`))if(n.closest(hr)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(O)}function yu(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 Pi(e,t,n=null,r=30000){let o={root:e,streams:0,keep:n,events:[]},i=He;He=o;try{window.Turbo.renderStreamMessage(t)}finally{He=i}if(o.streams===0)fs(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)):wu(),c,u=new Promise((l)=>c=setTimeout(l,r));return Promise.race([a,u]).finally(()=>clearTimeout(c))}function wu(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function Au(e){let t=He,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)=>{U.set(t.root,(U.get(t.root)||0)+1);let s;try{return await r(i)}catch(a){throw s=a,a}finally{let a=U.get(t.root)-1;if(a)U.set(t.root,a);else U.delete(t.root);fs(t.root,t.keep),o(s)}}}var Di="__materialize",Ii=!1;function Su(){if(Ii)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ii=!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 br(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")nn()}var ds="data-reactive-active",ir="data-reactive-errors",k=0,V=[];function ps(){if(k++,k===1)V=[],ms("reactive:busy")}function ae({action:e=null,kind:t,status:n=null,root:r=null}){if(k===0)return;V.push({action:e??null,kind:t,status:n??null,root:r||null})}function hs(){if(k===0)return;if(k--,k===0)ms("reactive:idle")}function xl(){return k}function _l(){k=0,V=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(ds),e?.removeAttribute?.(ir)}function ms(e){if(typeof document>"u")return;let t=document.documentElement,n=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(ds,k>0),n&&V.length>0)t.setAttribute(ir,JSON.stringify(V));else t.removeAttribute(ir);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let r=n?{count:k,errors:V.slice()}:{count:k};document.dispatchEvent(new CustomEvent(e,{detail:r}))}}var gs="data-reactive-requests";function bs(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Eu(t))return;let n=xu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(gs,JSON.stringify(n))}function Eu(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function xu(e){try{let t=JSON.parse(e.getAttribute(gs));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function qi(){tu(),nu(),ou(),iu(),au(),mu(),fu(),du(),Du(),pu(),hu(),Su(),br()}function _u(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var vs=Symbol.for("phlex-reactive.core");if(globalThis[vs])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[vs]=!0;var ys=!1;function ku(){if(ys)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(ku,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Tu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function ws(e){let t=String(e).toLowerCase();return t.startsWith("on")||Tu.has(t)}var Vn=new WeakMap;function Ru(e,t,n){let[r,o,i]=t;Vn.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,Vn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(a),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Vn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Ou(e))}function Ou(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 Lu=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Nu=new Set(["lexxy-editor","trix-editor"]);function W(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as wu}from"@hotwired/stimulus";import{confirmResolver as Ji}from"phlex/reactive/confirm";import{confirmPredicate as Bs}from"phlex/reactive/confirm_predicate";var j=new WeakMap,it=new WeakMap;function M(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)it.set(n.root,n)}return n}function x(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function V(e,t){x(e,"turbo:morph-element",t),e.seeds.push(t),t()}function st(e,t){let n=M(e,t);n.offs=[],n.seeds=[];let r,o,i,s,a;(n.wire=()=>{if(!n.show&&Ks(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")ua(n,c.target);else n.groups=aa(n),Mr(n);Or(n)},x(n,"input change",n.show),x(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]"))Or(n)}),V(n,n.show);if(!n.arm&&Vs(n))x(n,"input change",(c)=>Rr(n,c)),V(n,n.arm=()=>{Rr(n,null),Mr(n)});if(!r&&(r=n.show||n.arm))x(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))x(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!Js(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=he(n)))x(n,"input",(c)=>da(n,c)&&Y(n)),V(n,()=>Y(n));if(!s&&(s=be(n)))V(n,()=>Gr(n));if(!a&&(a=ha(n)))x(n,"input change",(c)=>Vr(n,c)),V(n,()=>bt(n))})(),x(n,"keydown",(c)=>Na(n,c)),x(n,"paste drop",(c)=>Fa(n,c)),x(n,"input",(c)=>Ma(n,c))}function Js(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function at(e){let t=j.get(e);if(!t)return;j.delete(e),it.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function ct(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function I(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ut(e,t,n){return Vr(M(e,t),n)}function lt(e,t,n){return eo(M(e,t),n)}var Hs=/^#[A-Za-z_][\w-]*$/,$r="[data-reactive-show-field], [data-reactive-show]";function Gs(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 Yr){let s=e.getAttribute(`data-reactive-show-${i}`);if(s!==null)return Zr(i,s,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Pr(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 Us(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 Ir(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 X(n,t);return zs(e,t)}function zs(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)=>Et(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function me(e,t="show"){if(typeof e==="string"&&Hs.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ks(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?.($r)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(ge)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${Wr}, ${jr}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function Vs(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Ys(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Us(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Rr(e,t){let n=Ys(e);if(!n.length)return;let r=qr(e,e.core.bindingOwnership());n.forEach((o,i)=>{let s=X(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 Or(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($r)){if(!t(s))continue;let a=s.getAttribute("data-reactive-show");if(a!==null){let d=Ir(Pr(a),o);if(d===null)continue;let f=s.getAttribute("data-reactive-show-after"),p=d&&(f==null||!!e.touched?.has(dt(f,r)));Lr(s,p,n);let m=(e.shown??=new WeakMap).get(s);if(e.shown.set(s,p),Xs.some((v)=>s.hasAttribute(`data-reactive-show-${v}`))&&m!==void 0&&m!==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=Gs(s,u);if(l===null)continue;Lr(s,l,n)}if(e.groups)la(e,o,t,r);na(e,o,t),ia(e,o,t,r,n),Qs(e,o),fa(e,o);for(let s of i)Zs(e,s,n,r)}var Xs=["clear","focus","scroll"];function Zs(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)=>dt(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,I(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 Lr(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 Qs(e,t){let n=Dr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){ea(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(!me(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)=>Et(l,s))}else{let l=Qr(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 ea(e,t,n){if(!me(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Oa(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((s)=>n(s)===null)&&!La(r))return;let i=X(r,n);if(i===null)return;for(let s of document.querySelectorAll(e))s.hidden=!i}function Dr(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(ft(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 ft(e,t){return`[name="${dt(e,t)}"]`}function dt(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?pt(e,o,t,n).filter((a)=>a.checked).length:ta(e,o,t,n));return r.get(s)}}var Wr="[data-reactive-media]";function na(e,t,n){for(let r of e.root.querySelectorAll(Wr)){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"){Nr(r,"pending");continue}let d=!l&&Object.hasOwn(o.pool,u)?Fr(e,o.pool[u])[0]:null,f=e.core.copyMedia(r,d??null);if(f===null)continue;if(Nr(r,l?"pending":f===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":f===!1?String(o.blank??""):f;for(let m of Fr(e,o.label))if(m.textContent!==p)m.textContent=p}}function Nr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Fr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var jr="[data-reactive-css-vars]",ra=/^--[a-z0-9-]+$/i,oa=["","px","%","deg","turn","ms","s","em","rem","fr"];function ia(e,t,n,r,o){let i=[...e.root.querySelectorAll(jr)].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},d=[];try{d=e.core.opTargets(l)}catch{}if(!d.length)e.core.diagnose("reactive_css_vars",l);return d});for(let[u,l]of Object.entries(a.vars)){let d=l?.unit??"";if(!ra.test(u)||!oa.includes(d)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let f=sa(e,t,l.field,o,r);if(f===void 0)continue;let p=f===null?"":`${f}${d}`;for(let m of c){if(m.style.getPropertyValue(u)===p)continue;if(p)m.style.setProperty(u,p);else m.style.removeProperty(u)}}}}function sa(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(ft(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 ge="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function aa(e){return!!e.root.querySelector?.(ge)}function pt(e,t,n,r,o){return[...e.root.querySelectorAll(ft(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||ca(i.getAttribute("data-reactive-group"),o)))}function ca(e,t){return e===t||!!e?.startsWith(`${t}.`)}function ua(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Br(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function mt(e,t,n){if(!t)return;let r=it.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Br(r,t,n!==!1),r.show?.()}function Br(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,s=pt(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 la(e,t,n,r){for(let o of e.root.querySelectorAll(ge)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Ir(Pr(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=pt(e,a,n,r,c).filter((d)=>d!==o),l=u.filter((d)=>d.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function fa(e,t){for(let[n,r]of Object.entries(Dr(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(!me(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(!me(s,"group"))continue;let c=X(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 Mr(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?.(`${ge}, [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 he(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 pa=/[\s\-'(),./]/;function ma(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||pa.test(t[r-1]))return!0;return!1}function Y(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=(f)=>{let p=(f??"").toLowerCase().trim();return s?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=a(o.value),u=0;for(let f of e.root.querySelectorAll(n)){if(!r(f))continue;let p=f.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!ma(i,a(f.getAttribute("data-reactive-filter-text")??f.textContent),c);if(f.hidden=p,p)f.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let f of e.root.querySelectorAll(l)){if(!r(f))continue;let p=[...f.querySelectorAll(n)].filter(r);if(p.length===0)continue;f.hidden=p.every((m)=>m.hidden)}let d=e.root.getAttribute("data-reactive-filter-empty");if(d){for(let f of e.root.querySelectorAll(d))if(r(f))f.hidden=u>0}}function be(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function ha(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function ht(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 gt(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 Jr(e,t){let n=ht(e);if(!n)return!1;let r=gt(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)Hr(e,n,r);return i}function Hr(e,t,n){t.value=n.join(","),I(t),Gr(e)}function ga(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 Gr(e){let t=ht(e);if(!t)return;let n=gt(t),r=e.core.ownership();ba(e,n,r),va(e,n,r)}function ba(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 va(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"),!he(e))o.hidden=!1}}if(he(e))Y(e)}function ya(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function wa(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 Aa(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 Sa(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 d=s.find((f)=>zr(f.getAttribute?.("name"))===c);if(!d)continue;if(Ea(d,l),!a.includes(l))a.push(l)}if(r)for(let c of a)xa(c,r);return a[0]??null}function Ea(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:rt(t)!=="";else e.value=rt(t);I(e)}function xa(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??"":"";I(e)}function _a(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Cr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",I(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);bt(e)}function bt(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))Kr(e,n.getAttribute("data-reactive-nested-json"))}function ka(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 Ur(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=zr(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=rt(o)}return n}function zr(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function rt(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Kr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ka(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(Ur(e,a))}let s=JSON.stringify(i);if(o.value===s)return;o.value=s,I(o)}function vt(e,t,n){let r=M(e,t);if(!be(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(!Jr(r,String(o.value??"").split(",")))return;if(o.value="",he(r))Y(r)}function yt(e,t,n){let r=M(e,t);if(!be(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Jr(r,[i]))return;let s=ga(r);if(!s)return;s.value="",Y(r),s.focus?.()}function wt(e,t,n){let r=M(e,t);if(!be(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let s=ht(r);if(!s)return;let a=gt(s),c=a.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===a.length)return;Hr(r,s,c)}function At(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){Aa(r,i);return}let l=u.cloneNode(!0);wa(l,ya(r)),a.appendChild(l);let d=o?.getAttribute?.("data-reactive-nested-from-param"),f=o?.getAttribute?.("data-reactive-nested-clear-param"),m=Sa(r,l,d,f==="true"||f==="reset"?f:null);if(d)m?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(a.getAttribute?.("data-reactive-nested-json")===i)Kr(r,i)}function St(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?eo(r,a):null);if(!c)return Cr(r,i);let u=Ur(r,i),l=_a(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((d)=>{if(d)Cr(r,i)})}function Vr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;bt(e)}var Yr=["gte","gt","lte","lt"],Ta=["len_eq","len_gte","len_gt","len_lte","len_lt"],Xr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],Ra=["digits_eq","digits_gte","digits_lt","digits_lte"];function ot(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 Zr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function Qr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Yr)if(n in e)return Zr(n,e[n],t);for(let n of Ta)if(n in e)return ot(n,e[n],[...String(t??"")].length);return null}function Et(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Xr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return ot(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=Ra.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)=>ot(a,e[a],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return Qr(e,o)===!0}function X(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Et(r,t)))}function Oa(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 La(e){return e.flat().every((t)=>Xr.some((n)=>(n in Object(t))))}function eo(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=Bs(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=X(n.groups?.any,o)===!0;return i?n.message:null}function xt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function Na(e,t){let n=xt(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),I(n),n.blur()}function Fa(e,t){let n=xt(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 Ma(e,t){let n=xt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as Ca}from"phlex/reactive/compute";var Q=new WeakMap;function io(e,t){let n=Q.get(e);if(!n)Q.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function _t(e,t,n,r){let o=io(e,t),i=Va(o);if(i){o.seed=()=>ve(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(s)=>s.target!==o.root&&[...s.target.querySelectorAll(no)].some(o.core.bindingOwns)&&o.seed();for(let s of so)o.root.addEventListener?.(s,o.nested)}if(o.share=(s)=>s.target?.matches?.(no)&&!o.core.owns(s.target)&&o.core.bindingOwns(s.target)&&ve(o,s),o.root.addEventListener?.("input",o.share),i||r?.edited)ve(o)}function kt(e){let t=Q.get(e);if(!t)return;if(Q.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of so)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function Tt(e){Q.get(e)?.seed?.()}function Rt(e,t,n){return ve(io(e,t),n)}var no="[data-reactive-shared-field]",so=["reactive:connect","reactive:persist-restored"],$a=Object.freeze({el:null,kind:""}),Pa=/^#[A-Za-z_][\w-]*$/;function Z({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 ao(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Ia(e,t){if(t==="string")return Z(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):ao(Z(e));if(n)return e.el.checked?1:0;let r=Number(Z(e));return Number.isFinite(r)?r:0}function Da(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let s=ao(i);if(Boolean(n.checked)===s)return null;return n.checked=s,n}if(r==="radio")return qa(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function qa(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 Wa(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 ja(e){if(typeof e==="string"&&Pa.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function Ba(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 Ja(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 Ha(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 Ga(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=Ua(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function Ua(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function ro(e,t,n){let r=String(n);for(let o of za(e,t)){if(o.textContent===r)continue;o.textContent=r}}function za(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function oo(e,t,n){let r=Ka(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?Z(s):void 0;if(a===void 0||a===null)continue;let c=String(a);for(let u of Array.isArray(i)?i:[i]){if(!ja(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Ka(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 Va(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function ve(e,t){if(t&&e.ours.has(t))return;let n=Ha(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 h=a.get(v);if(h)return h;let w=null,A=null,E=null;for(let T of e.root.querySelectorAll(`[name="${i(v)}"]`)){if(!s(T))continue;let pe=T.type;if(pe==="checkbox"||pe==="radio"&&T.checked){E={el:T,kind:pe};break}if(pe==="radio")w??=T;else A??=T}if(!E)if(w)E={el:w,kind:"radio"};else E=A?{el:A,kind:""}:$a;return a.set(v,E),E};for(let v of r)ro(e,v,Z(c(v)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?Ca(u):null;if(!l){oo(e,{},c);return}let d=Ja(e,"data-reactive-compute-outputs-param"),f={};for(let[v,h]of n)f[v]=Ia(c(v),h);let p=l(f,{changed:Ga(e,t,r,o)})||{},m=Wa(p.$ops),b=[];for(let v of d){if(v==="$ops"||!(v in p))continue;let h=c(v);if(!h.el)continue;let w=Da(e.root,s,h,i(v),p[v]);if(w)b.push(w)}for(let v of Object.keys(p)){if(v==="$ops")continue;let h=p[v];if(h===void 0||h===null)continue;ro(e,v,h)}oo(e,p,c);for(let v of b){let h=new Event("input",{bubbles:!0});e.ours.add(h),v.dispatchEvent(h)}Ba(e,m,Boolean(t))}var Ft;function Mt(e){Ft=e}var po=1,Ya="phlex-reactive:persist:",Xa=new Set(["hidden","file","password","submit","button","reset","image"]),Ct=Symbol("persist-no-value"),$t="data-reactive-persist-state",Za=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Qa=new Set(["lexxy-editor","trix-editor"]),ec="lexxy-editor, trix-editor, trix-toolbar",tc=["lexxy:change","trix-change"],nc=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),uo=new WeakSet,lo=new WeakSet,fo=new WeakSet;function we(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(!uo.has(e))uo.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Pt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function It(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||lo.has(e))return;lo.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Dt(e){return Ya+e.key}function Lt(e,t){let n=Pt(t);if(!n)return null;let r;try{r=n.getItem(Dt(t))}catch(c){return It(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==po)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return ye(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 mo(e,t,{fields:n,state:r}){let o=Pt(t);if(!o)return!1;let i={v:po,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Dt(t),JSON.stringify(i)),!0}catch(s){return It(e,s),!1}}function ye(e,t){e?.removeAttribute?.($t);let n=Pt(t);if(!n)return;try{n.removeItem(Dt(t))}catch(r){It(e,r)}}function qt(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)||Xa.has(i.type)||i.closest(ec))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Za)){if(!o(i))continue;let s=rc(i);if(!s||n&&!n.has(s))continue;r.push({el:i,name:s,kind:Qa.has(i.localName)?"editor":"contenteditable"})}return r}function ho(e){return e.hasAttribute("data-reactive-editable")?Ft.text(e):e.textContent??""}function rc(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Wt(e){return typeof e.value==="string"}function oc(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return nc.has(e.value.trim())}function ic(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||fo.has(e))return;fo.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function ee(e){return e.tagName==="SELECT"&&e.multiple}function go(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 bo(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Ct;return e[0]}function vo(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 qt(e,t)){let a=String(i).endsWith("[]");if(s==="editor"){if(Wt(o))if(a)r(i).push(o.value);else n[i]=o.value}else if(s==="contenteditable"){let c=ho(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(ee(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 sc(e,t,n){let r=t.restore==="always",o=qt(e,t),i=go(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)&&ee(a)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(a.type==="checkbox"||ee(a))){if(l=bo(l,c,i),l===Ct)continue}if((a.type==="checkbox"||ee(a))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")yo(e,a,c,l,r);else if(u==="contenteditable"){if(!r&&ho(a).trim()!=="")continue;a.textContent=String(l)}else if(a.type==="radio"){if(!r&&o.some((d)=>d.kind==="native"&&d.el.type==="radio"&&d.name===c&&d.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(ee(a)){if(!r&&[...a.options].some((f)=>f.selected))continue;let d=new Set((Array.isArray(l)?l:[l]).map(String));for(let f of a.options)f.selected=d.has(f.value)}else{if(!r&&a.value!=="")continue;a.value=String(l)}}ac(e,t,n)}function yo(e,t,n,r,o){if(Array.isArray(r))return;if(!Wt(t))return;if(!o&&!oc(t))return;try{t.value=String(r)}catch(i){ic(e,n,i)}}function ac(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(!Wt(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=qt(e,t),c=go(a);for(let{el:u,name:l,kind:d}of a){if(d!=="editor"||u.localName!==s||!Object.hasOwn(n,l))continue;let f=bo(n[l],l,c);if(f===null||f===void 0||f===Ct)continue;yo(e,u,l,f,i)}})}function cc(e,t,n=!0){let r=we(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=Lt(e,r),i={...o?.state??{},...t},s=n?vo(e,r):o?.fields??{};if(mo(e,r,{fields:s,state:i}))e.setAttribute?.($t,JSON.stringify(i))}function uc(e){let t=we(e);if(t)ye(e,t)}var Nt=new WeakMap,Ot=new WeakMap;function lc(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=Ot.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],Ot.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),Ot.delete(e)}}function jt(e,t,n,r){let o=e.element,i=we(o);if(!i)return;if(r?.submitted)ye(o,i);let s=Lt(o,i);if(s){if(sc(o,i,s.fields),s.state)o.setAttribute?.($t,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 m=Lt(o,i);mo(o,i,{fields:vo(o,i),state:m?.state??null})},l=()=>{let m=Number(i.debounce)||0;if(m<=0)return u();if(a!==null)clearTimeout(a);a=setTimeout(()=>{a=null,u()},m)},d=(m)=>{if(!m?.detail?.success)return;let b=m.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),ye(o,i)},f=["input",...tc];for(let m of f)o.addEventListener?.(m,l);o.addEventListener?.("change",u);let p=lc(globalThis.document,d);if(Nt.set(e,()=>{if(a!==null)u();for(let m of f)o.removeEventListener?.(m,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let m of r?.ops??[])m(!0)}function Bt(e){let t=Nt.get(e);Nt.delete(e),t?.()}function wo(e,t){let n=Ft?.waiting.get(e)?.persist;if(!n||!we(e))return t(!0);(n.ops??=[]).push(t)}function Jt(e,t){wo(e,(n)=>cc(e,t,n))}function Ht(e){wo(e,()=>uc(e))}var Ae=new WeakMap,So=new WeakSet,Gt=new WeakMap;function Ut(e,t){let n=e.element,r=[],o=[],i=(u,l,d)=>{u.addEventListener?.(l,d),r.push(()=>u.removeEventListener?.(l,d))},s,a,c=()=>{if(!s&&(s=fc(n,t))){let u=()=>Se(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")mc(n,r)}if(!a&&(a=hc(n,t))){let u=()=>gc(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};Ae.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function zt(e){for(let t of Ae.get(e)?.[0]??[])t();Ae.delete(e)}function Kt(e){Ae.get(e)?.[1]()}function fc(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 Se(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 pc(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function mc(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Gt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(pc(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(So.has(c)||!i())return;if(So.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),Gt.delete(n)}},Gt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function hc(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 gc(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 Zt(e){bc(e),yc(e)}function bc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Vt);else setTimeout(Vt,0);return}let r=async(o)=>{await n(o),Vt()};r.__reactiveDismissWrapped=!0,t.render=r}function Vt(){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 vc=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Yt=Object.freeze(["fade","slide","scale","highlight","shake"]),Xt="data-reactive-fx-pending",Qt=1000;function yc(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=vc[r?.getAttribute?.("action")];if(!o||Sc())return;let i=wc(r,o);if(!i)return;let s=o==="exit"?async(a)=>{await _c(Ee(r),i),await n(a)}:async(a)=>{let c=o==="enter"?Ec(r):null;if(await n(a),o==="enter")xc(c,i);else _o(Ee(r),i)};s.__reactiveEffectsWrapped=!0,t.render=s}function wc(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return xo(n,t);let o=(t==="enter"?Ac(e):Ee(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?xo(o,t):null}function Ee(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Ac(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function xo(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"?Yt[Math.floor(Math.random()*Yt.length)]:e;if(!Yt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Sc(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Ec(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Xt,"");return Ee(e)}function xc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Xt}]`)))n.removeAttribute(Xt),_o(n,t)}async function _c(e,t){if(!e?.classList)return;if(t.legs){await ko(e,t.legs);return}e.classList.add(t.className);let n=en(e);if(n<=0){e.classList.remove(t.className);return}await tn(e,n),e.classList.remove(t.className)}function _o(e,t){if(!e?.classList)return;if(t.legs){ko(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=en(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;tn(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function ko(e,t){let[n,r,o]=t.map(kc),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Tc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let s=en(e);if(s>0)await tn(e,s);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function kc(e){return String(e??"").split(/\s+/).filter(Boolean)}function en(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,Qt)}catch{return 0}}function tn(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,Qt))})}function Tc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Qt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Rc="phlex-reactive:latency",nn=!1;function Oo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Lo(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),nn=!1}function on(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Oo,disableLatencySim:Lo}}function sn(){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(!nn)nn=!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 Ro=new WeakMap;function an(e){let t=globalThis.document;if(!t)return!0;let n=Ro.get(t);if(!n)n=new Set,Ro.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function rn(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function Oc(e,t){try{return e?.matches?.(t)===!0}catch{return!1}}function No(e,t,n,r){if(an(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function cn(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=rn(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}No(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function un(e){if(!an(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function ln(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(Oc(r,o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(rn(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let s=rn(globalThis.document,o);if(s>0)i=` — it matches ${s} element(s) outside this scope; use global: true`}No(t,o,`scoped to #${r?.id||"?"}`,i)}function fn(e,t){let n=e.element?.id||"?";if(an(`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 Lc(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 dn(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 xe(e,t,n){e.streams=Lc(t),e.tokenRefreshed=n!=null}var _e=new WeakMap;function pn(e,t,n,r){let o=n&&typeof n==="object"?Mc(n):n;return o?Mo(t,o,r,!1):[]}function mn(e,t,n,r){if(!n)return null;let o=Mo(t,n,r,!0);return o.length?o:null}function Mo(e,t,n,r){let o=[];for(let i of Co(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(Nc(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Co(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 Nc(e,t){let n=_e.get(t);if(n)n.count++;else _e.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()=>Fc(t,e)}function Fc(e,t){let n=_e.get(e);if(!n)return;if(--n.count>0)return;if(_e.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function Mc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function hn(e,t,n,r){if(!n?.hide)return null;let o=Co(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 B;function vn(e){B=e}var L=new Map;function Do(e,t){let n=!L.has(e);if(L.set(e,t),n)B.enter()}function Re(e){if(L.delete(e))B.exit()}var Po=!1;function yn(e){qo();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){qc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;ne(t,n)}function qo(){if(Po||typeof document>"u"||!document.addEventListener)return;Po=!0,document.addEventListener("turbo:before-stream-render",jc,!0),document.addEventListener("turbo:before-stream-render",Cc)}function Cc(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")Re(n)}function ne(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}An(e),Jo(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Do(e,r),Wc(e,r,t)}function $c(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[Jc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Hc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Wo(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(jo(t))return{src:t};return console.error(Pc(t)),Ic(t)||Dc(e)}function Pc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${wn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Ic(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${wn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&jo(r))return{src:r,fallback:!0}}function Dc(e){B.fail({kind:"defer",root:e.id}),An(e.id),Sn(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 jo(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${wn()}/`)}catch{return!1}}function wn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function qc(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){ne(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}An(e),Jo(n);let o=document.createElement("pgbus-stream-source");o.id=Bo(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Do(e,{via:"stream"})}function Bo(e){return`reactive-defer-src-${e}`}async function Wc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Gc()),o;try{B.count("defer"),o=await fetch(...$c(n,t.abort.signal))}catch(a){if(clearTimeout(r),L.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",a),te(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"}`),te(e,n,o.status);return}if(o.status===204){clearTimeout(r),Io(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),te(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}"`),te(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),te(e,n);return}if(clearTimeout(r),L.get(e)!==t)return;Io(e),Bc(s)}var bn=null,jc=(e)=>bn?.push(e);function Bc(e){let t=bn=[];try{window.Turbo.renderStreamMessage(e)}finally{bn=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 An(e){let t=L.get(e);if(!t)return;if(Re(e),t.via==="fetch")t.abort.abort();else document.getElementById(Bo(e))?.remove?.()}function Jo(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Sn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Io(e){Re(e);let t=document.getElementById(e);if(!t)return;Sn(t),t.removeAttribute("data-reactive-error")}function te(e,t,n){B.fail({kind:"defer",status:n,root:e}),Re(e);let r=document.getElementById(e);if(!r)return;Sn(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"),ne(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function Jc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Hc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Gc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Ho="__materialize",Te=new WeakMap;function ke(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function En(e,t,n){qo();let r=e.element,o=!1,i=!1,s=null,a=null,c,u,l=()=>Oe(e),d=(h)=>{if(ke(r)==="visible"){if(!s)p()}else if(h){let w=r.getAttribute("data-reactive-lazy-on");if(a===w)return;f(),r.addEventListener?.(w,l),a=w}},f=()=>{if(s?.disconnect(),s=null,a)r.removeEventListener?.(a,l);a=null},p=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let h=r.getAttribute("data-reactive-lazy-visible")||"0px";s=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:h}),s.observe(r)},m=()=>{let h=ke(r)!==null,w=o;if(o=h,!h)return f();if(i)return;if(t.forgetToken(),!w)return l();d(!0)};if(Te.set(e,{load(){if(i)return;let h=Wo(r);if(!h&&r.getAttribute("data-reactive-defer-src")!=null)return;if(h&&Uc(r,t))return;let w=h?ne(r.id,h):t.proceed(r,Ho,"{}");if(!w)return;i=!0,f();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);f()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&ke(r)===null)gn(r),c=(h)=>h.target===r&&gn(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=(h)=>{if(h.target!==r)return;if(!c)gn(r);m()},r.addEventListener?.("turbo:morph-element",u),n)return m();if(o=ke(r)!==null,o)d(!1)}function xn(e){let t=Te.get(e);Te.delete(e),t?.off()}function Oe(e){return Te.get(e)?.load()}function Uc(e,t){return t.emit("reactive:before-dispatch",{action:Ho,params:{},element:e},{cancelable:!0}).defaultPrevented}function gn(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Wo(e);if(t)ne(e.id,t)}var _n=new WeakMap,Ne=new WeakMap,g=null,D,Uo;function On(e,t){let n=e.element;Ne.set(n,t),ti();let r=(i)=>Kc(i,t),o=(i)=>Qc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),_n.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Ln(e){if(_n.get(e)?.(),_n.delete(e),Ne.delete(e.element),g&&Fe(g.origin)===e.element)Le()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),re=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},Fe=(e)=>e?.closest?.('[data-controller~="reactive"]'),Yo=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),C=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&Yo(t)===e),zo=(e)=>re(S(e,"-item"),null),kn=(e)=>S(e,"-disabled")==="true",zc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Xo=(e)=>{let t=S(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>S(n,"-group")===t&&!kn(n)&&Ne.has(Fe(n)))};function Zo(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Yo(n);if(g||!r||!t.owns(r)||kn(r)||kn(n))return;if(Fe(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Kc(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Zo(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,s=(h)=>h.pointerId===e.pointerId,a=e.pointerType==="touch",c=!a,u=a&&setTimeout(()=>c=!0,200),l=(h)=>{if(!s(h))return;if(g)return Tn(h.clientX,h.clientY);if(Math.abs(h.clientX-o)<=4&&Math.abs(h.clientY-i)<=4)return;if(!c)return v();Yc(n,t,h),Tn(h.clientX,h.clientY)},d=(h)=>g&&h.cancelable&&h.preventDefault(),f=(h)=>{if(!s(h))return;if(v(),g)Vc(),Rn()},p=(h)=>{if(h.type==="pointercancel"&&!s(h))return;if(v(),g)Le()},b=[["pointermove",l],["pointerup",f],["pointercancel",p],["keydown",(h)=>h.key==="Escape"&&g&&(h.preventDefault(),p(h))],["touchmove",d,{passive:!1}]];for(let[h,w,A]of b)document.addEventListener(h,w,A);function v(){clearTimeout(u);for(let[h,w]of b)document.removeEventListener(h,w)}}function Vc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Yc({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=Qo({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 Qo(e){let{row:t,origin:n,source:r}=e;return e.index=C(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),oe(n,!0),e}var oe=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Me(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 Tn(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=Xo(g.origin).find((r)=>zc(r,e,t));if(n)Xc(n,e,t);else if(g.source)Nn(null),g.placeholder.remove();Zc(e,t)}function Nn(e){if(g.target!==g.origin)oe(g.target,!1);g.target=e,oe(e,!0)}function Xc(e,t,n){Nn(e);let r=C(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});Me(e,r,a<0?r.length:a,g.placeholder)}function Zc(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);Tn(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function Qc(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":Rn,Enter:Rn,Escape:Le,Tab:Le,ArrowUp:()=>Ko(-1),ArrowDown:()=>Ko(1),ArrowLeft:()=>Vo(-1),ArrowRight:()=>Vo(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Zo(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),g=Qo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),$e("picked")}function Ko(e){let t=C(g.target),n=Ce()+e;if(n>=0&&n<=t.length)Me(g.target,t,n,g.row);ei()}function Vo(e){let t=Xo(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=Ce();Nn(n),Me(n,C(n),r,g.row)}ei()}function ei(){g.row.focus?.(),$e("moved")}function Ce(){let e=C(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function ti(){if(!D?.isConnected)D=document.createElement("div"),D.setAttribute("aria-live","polite"),D.setAttribute("data-reactive-sortable-live",""),D.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(D);return D}function $e(e){let t=g.target??g.origin,n=(re(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Ce()+1).replaceAll("{count}",C(t).length+1),r=ti();r.textContent="",cancelAnimationFrame(Uo),Uo=requestAnimationFrame(()=>r.textContent=n)}function Rn(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,s=t&&(r?i.isConnected:!0),a=s?Ce():-1,c=s?zo(C(t)[a-1]):null;if(e.keyboard)$e("dropped");if(!r&&i)i.replaceWith(o);if(ri(e),!s||t===n&&a===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=re(S(t,"-from"),{})[u]??S(t),d={...re(S(t,"-params"),{}),item:zo(e.item),position:a,after:c,from:u},f=[];for(let m=t;m;m=m.parentElement)f.push(m);let p=Ne.get(Fe(t))?.proceed(t,l,JSON.stringify(d),re(S(t,"-busy")));if(r)return;Promise.resolve(p).then((m)=>eu(m,f)||ni(e))}function eu(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 Le(){let e=g;if(e.keyboard)$e("cancelled");e.placeholder?.remove(),ri(e),ni(e)}function ni({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Me(t,C(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function ri(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(),oe(n,!1),oe(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var ci={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},ui={x:"left",y:"top",width:"width",height:"height"},Fn=new WeakMap,$n=new WeakMap,y=null,q,ii,si=!1;function Pn(e,t){let n=e.element;$n.set(n,t),yi(),du();let r=[["pointerdown",(o)=>au(o,t,n)],["keydown",(o)=>fu(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&ci[o.key]&&Cn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&Cn()],["input",(o)=>ai(o,t,n)],["change",(o)=>ai(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);Fn.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function In(e){if(Fn.get(e)?.(),Fn.delete(e),$n.delete(e.element),y?.root===e.element)H(y)}var R=(e,t,n)=>Math.min(Math.max(e,t),n),N=(e)=>Math.round(e*1e4)/1e4;function nu(e,t=1){let n=N(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Dn(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 li(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 fi(e,t,n){return{x:R(e.x+t,0,1),y:R(e.y+n,0,1)}}function di(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,d=e.y+e.height,f=e.x+e.width/2,p=e.y+e.height/2,m=a?1-e.x:u?l:i?2*Math.min(f,1-f):1,b=c?1-e.y:s?d:i?2*Math.min(p,1-p):1,v=e.width+(a?n:u?-n:0),h=e.height+(c?r:s?-r:0);if(i){let w=(a||u)&&(!(s||c)||Math.abs(v-e.width)>=Math.abs(h-e.height)*i),A=Math.min(m,b*i);v=R(w?v:h*i,Math.min(Math.max(o,o*i),A),A),h=v/i}else{if(a||u)v=R(v,Math.min(o,m),m);if(s||c)h=R(h,Math.min(o,b),b)}return{x:u?l-v:a?e.x:f-v/2,y:s?d-h:c?e.y:p-h/2,width:v,height:h}}function ru(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 ou(e){let[t,n=1,r]=String(e??"").split(":").map(Number),o=r===void 0?t/n:0;return o>0&&Number.isFinite(o)?o:0}var _=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),qn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},F=(e)=>e.matches("[data-reactive-point]")?"point":"box",pi=(e)=>Number(_(e,`${F(e)}-scale`))||1,J=(e)=>F(e)==="point"?["x","y"]:["x","y","width","height"];function mi(e){let t={};for(let n of J(e))t[n]=(parseFloat(e.style[ui[n]])||0)/100;return t}function Pe(e,t){for(let n of J(e))e.style[ui[n]]=`${Math.round(t[n]*1e4)/100}%`}function Wn(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 iu(e,t){try{return e.parentElement.closest(_(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function hi(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function gi(e,t,n){let r=qn(_(e,F(e)),{}),o={};for(let i of J(e)){let[s]=hi(t,n,r[i]);if(s)o[i]=s}return o}function su(e,t,n,r){let o=_(e,"box-aspect"),i=o&&hi(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),s=o?ou(i?.value):Number(_(e,"box-ratio"))||0,{width:a,height:c}=Wn(t);return s&&a&&c?s*c/a:0}function jn(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=mi(o),a=gi(o,t,e),c=F(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?iu(o,i):i,edge:_(n,"box-handle"),start:s,value:s,ratio:c?0:su(o,i,t,e),min:Number(_(o,"box-min"))||0,scale:pi(o),fields:a,before:Object.fromEntries(Object.entries(a).map(([u,l])=>[u,l.value]))}}function bi(e,t,n,r){let o=nu(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function ie(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))bi(e.core,n,e.value[t],e.scale)}function au(e,t,n){if(vi(),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)&&jn(t,n,r,!1);if(!o)return;let{clientX:i,clientY:s}=e,a=Wn(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 Mn(b.clientX,b.clientY);if(Math.abs(b.clientX-i)<=4&&Math.abs(b.clientY-s)<=4)return;uu(o),Mn(b.clientX,b.clientY)},l=(b)=>{if(!c(b))return;if(m(),y)cu(),Cn()},d=(b)=>{if(b.type==="pointercancel"&&!c(b))return;if(m(),y)Si()},p=[["pointermove",u],["pointerup",l],["pointercancel",d],["keydown",(b)=>b.key==="Escape"&&y&&(b.preventDefault(),d(b))]];for(let[b,v]of p)document.addEventListener(b,v);function m(){for(let[b,v]of p)document.removeEventListener(b,v)}}function cu(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function uu(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 Mn(e,t){let n=y;if(!n.el.isConnected)return H(n);n.x=e,n.y=t;let r=Wn(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=Dn(F(n.el)==="point"?fi(s,o,i):a?di(s,a,o,i,n.min,n.ratio):li(s,o,i)),Pe(n.el,n.value),n.writing||=requestAnimationFrame(()=>ie(n)),lu(t)}function lu(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),Mn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function vi(){if(y&&!y.el.isConnected)H(y)}function fu(e,t,n){vi();let r=e.target;if(!r?.matches?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]")||!t.owns(r)||y&&(!y.keyboard||y.grip!==r))return;if(e.key==="Escape")return y&&(e.preventDefault(),Si());let o=ci[e.key];if(!o)return;if(e.preventDefault(),y??=jn(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=Dn(F(y.el)==="point"?fi(c,i,s):a?di(c,y.edge??"se",i,s,y.min,y.ratio):li(c,i,s)),Pe(y.el,y.value),ie(y),wi(y,a?"resized":"moved")}function yi(){if(!q?.isConnected)q=document.createElement("div"),q.setAttribute("aria-live","polite"),q.setAttribute("data-reactive-drag-live",""),q.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(q);return q}function wi(e,t){let n=qn(_(e.el,`${F(e.el)}-messages`),{})[t]??"";for(let o of J(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=yi();r.textContent="",cancelAnimationFrame(ii),ii=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(_(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=jn(t,n,o,!0),{ratio:s,start:a}=i??{};if(!s||Math.abs(a.width/a.height/s-1)<0.005)continue;i.value=Dn(ru(a,s,i.min)),Pe(o,i.value),ie(i),Ai(i)}}function Cn(){let e=y;if(!e.el.isConnected)return H(e);ie(e),H(e),Ai(e)}function Ai(e){for(let[o,i]of Object.entries(e.fields))if(i.value!==e.before[o])i.dispatchEvent(new Event("change",{bubbles:!0}));let t=F(e.el),n=_(e.el,`${t}-action`),r={};for(let o of J(e.el))r[o]=N(e.value[o]);if(!n||J(e.el).every((o)=>r[o]===N(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),qn(_(e.el,`${t}-busy`)))}function Si(){let e=y;if(e.value=e.start,Pe(e.el,e.start),ie(e),e.keyboard)wi(e,"cancelled");H(e)}function H(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(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=$n.get(n);if(!r?.owns(t))return;let o=mi(t),i=pi(t);for(let[s,a]of Object.entries(gi(t,n,r)))bi(r,a,o[s],i)})}var P=new Map,xi=new WeakSet,_i=!1;function Bn(e,t){if(!_i)_i=!0,document.addEventListener("turbo:morph",ki),document.addEventListener("turbo:render",ki);let n=e.element,r=P.get(n.id);if(!r)P.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Oi(n);let o=(s)=>s.target===n&&queueMicrotask(()=>Ri(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)},Ri(r)}function Jn(e){let t=e.element,n=P.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;P.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function Hn(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=P.get(e.id);if(!n)P.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},Li(n)}function ki(){for(let e of P.values())if(e.core&&!e.removing&&e.root.isConnected)Oi(e.root)}function Oi(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&xi.has(n))return;if(n?.remove(),!Ti())setTimeout(()=>{if(!Ti())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=P.get(e.id);if(!o||o.removing)return;Li(o),mu(o)}),xi.add(r),pu().appendChild(r)}function pu(){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 Ti=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function mu(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&&Ni(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 Li(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 Ni(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 Ri(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=Ni(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 Ie=new Map,se=new Map,Pi=new WeakMap,Ii=new WeakSet,Mi=!1;function Un(e){if(!Mi)Mi=!0,document.addEventListener("turbo:morph",Ci),document.addEventListener("turbo:render",Ci);let t=e.element,n=se.get(t.id);if(!n)se.set(t.id,n={id:t.id,src:null});Pi.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(!Ii.has(r))r.remove();Gn(n,t.getAttribute("data-reactive-subscribe")),n.observer=new MutationObserver(()=>Gn(n,t.getAttribute("data-reactive-subscribe"))),n.observer.observe(t,{attributes:!0,attributeFilter:["data-reactive-subscribe"]})}function zn(e){let t=e.element,n=Pi.get(t);if(!n||n.root!==t)return;n.observer.disconnect(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;se.delete(n.id),Gn(n,null)})}function Gn(e,t){let n=e.src;if(e.src=t||null,e.src)Di(e.src,e.id);if(n&&n!==e.src)hu(n,e.id)}function Ci(){for(let e of se.values())if(e.src&&!e.removing&&e.root.isConnected)Di(e.src,e.id)}function Di(e,t){let n=Ie.get(e);if(!n)Ie.set(e,n={source:null,ids:new Set,connected:!1});if(n.ids.add(t),!n.source?.isConnected)n.source=gu(e,n)}function hu(e,t){let n=Ie.get(e);if(!n)return;if(n.ids.delete(t),n.ids.size)return;Ie.delete(e),n.source.remove()}function gu(e,t){if(!$i())setTimeout(()=>{if(!$i())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=bu(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=se.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}}))}}),Ii.add(n),vu().appendChild(n),n}function bu(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 vu(){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 $i=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");var Wi=new Map,Kn=new WeakMap,yu=0,De=new WeakMap;function Vn(e,t){let n=e.element;if(!n.id&&!Kn.has(n))Kn.set(n,`#${++yu}`);let r=n.id||Kn.get(n),o=new Map,i=!1,s=(p)=>{clearTimeout(o.get(p)),o.delete(p)},a=(p,m,b)=>{s(p);let v=Date.parse(m.until)-Date.now();if(!(v>0))return c(p,m,b);let h=Math.ceil(v/1000);ji(p,`${Math.floor(h/60)}:${String(h%60).padStart(2,"0")}`,"running"),u(m.waiting,!0),u(m.done,!1),o.set(p,setTimeout(()=>a(p,m,b),(v-1)%1000+1))},c=(p,m,b)=>{ji(p,"0:00","done"),u(m.waiting,!1),u(m.done,!0);let v=Wi.get(b)??new Set;if(v.has(m.until))return;Wi.set(b,v.add(m.until)),p.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:m.until}}))},u=(p,m)=>{let b;try{b=p&&n.querySelector(p)}catch{}if(b&&b.hidden===m)b.hidden=!m},l=()=>{if(i=!1,!De.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 h;try{h=JSON.parse(b.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(h?.until)))return;p.add(b),a(b,h,`${r}|${b.id||v}`)});for(let b of o.keys())if(!p.has(b))s(b)},d=()=>{if(i)return;i=!0,queueMicrotask(l)},f=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",d),n.addEventListener("reactive:streamed",d),document.addEventListener("visibilitychange",f),De.set(e,()=>{n.removeEventListener("turbo:morph-element",d),n.removeEventListener("reactive:streamed",d),document.removeEventListener("visibilitychange",f);for(let p of[...o.keys()])s(p)}),l()}function Yn(e){De.get(e)?.(),De.delete(e)}function ji(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 Au(){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 Su(){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 Eu=["focus","focus_first","blur"];function xu(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=_r(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)un(n);return}let i=(a)=>dr(a,(c)=>yl(c,o),r?(c,u)=>cn(c,u,o):void 0),s=t.findIndex((a)=>Eu.includes(a?.[0]));if(s<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,s)),requestAnimationFrame(()=>i(t.slice(s)))}}function _u(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){yn(this)}}var Hi=!1,ku=null;function Tu(){if(Hi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Hi=!0,document.addEventListener("turbo:before-stream-render",(e)=>{ju(e),Ru(e),Lu(e),Zt(e)})}var He="reactive:streamed";function Ru(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(He))}}function hr(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function gr(e){try{return e.matches(":modal")}catch{return!1}}function ws(e){if(!hr(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||gr(e))return;if(e.open)e.close();e.showModal()}function Ou(e){if(hr(e)&&e.open)e.close()}function Ye(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&&!gr(r))ws(r)}function Lu(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),Ye(document)}}var Gi=!1;function Nu(){if(Gi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Gi=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Ye(t.target)}),document.addEventListener("turbo:morph",()=>Ye(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!hr(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||!gr(n))return;e.delete(n),t.preventDefault(),n.close()})}var ar=new WeakMap;function As(e,t,n,r){let o=ar.get(e)??new Map;ar.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"))Ps(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}))As(s,"set_attr",{name:"aria-expanded"})}}var Ui=!1;function Fu(){if(Ui)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ui=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of ar.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 br="data-reactive-image-fallback",z="data-reactive-image-state",cr="data-reactive-image-hidden",Xn=null,ur="data-reactive-wrap-hidden";function Ss(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(ur,"")}function Es(e){if(!e.hasAttribute(ur))return;e.removeAttribute("hidden"),e.removeAttribute(ur)}function fe(e){if(e?.localName!=="img")return null;let t=e.getAttribute(br);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var xs=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function vr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function _s(e,t){let n=vr(e,t.alt);return n&&!n.contains(e)?n:null}function Xe(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(cr,"");if(t.wrap){let o=vr(e,t.wrap);if(o)Ss(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=_s(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else tt(e,t);e.setAttribute(z,n)}function tt(e,t=fe(e)){if(!t||e.getAttribute(z)==null)return;if(e.getAttribute(z)==="error"){if(e.hasAttribute(cr))e.removeAttribute("hidden");let n=vr(e,t.wrap);if(n)Es(n);let r=_s(e,t);if(r)r.hidden=!0}e.removeAttribute(z),e.removeAttribute(cr)}function zi(e){let t=e.target,n=fe(t);if(!n)return;if(e.type==="load")Xe(t,n,"loaded");else if(xs(t))Xe(t,n,"error");else tt(t,n)}function Mu(){if(Xn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;Xn={error:zi,load:zi,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(z);if(o==null||!r||!fe(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=fe(n);if(o)Xe(n,o,r)})},"turbo:frame-render":(t)=>qe(t.target),"turbo:render":()=>qe(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[${br}]`))return;n.render=async(i)=>{await r(i),qe(document)}}};for(let[t,n]of Object.entries(Xn))document.addEventListener(t,n,!0);qe(document)}function qe(e){for(let t of e?.querySelectorAll?.(`img[${br}]`)??[]){if(t.getAttribute(z)!=null||!t.complete||!xs(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Xe(t,fe(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 Hl(e){ku=e}var We,Zn=null,Ki="[data-reactive-editable][contenteditable=plaintext-only]";function ks(){if(We===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",We=e.contentEditable==="plaintext-only"}catch{We=!1}return We}function Ge(e){if(e.matches?.(Ki))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Ki).forEach(Ge)}function Cu(){if(Zn||typeof document>"u"||typeof document.createElement!=="function")return;if(ks())return;Ge(document),Zn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Ge(t.target);else t.addedNodes.forEach(Ge)}),Zn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Vi=!1;function Yi(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 $u(){if(Vi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Vi=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=Yi(t);if(r)Iu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Ze.set(t,W(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)=>Er(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===O)&&Yi(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(O)&&wr(t)===Ar(t))t.removeAttribute(O)})}var O="data-reactive-held",yr='[data-controller~="reactive"]',Ue=null,U=new Map;function wr(e){return e.hasAttribute("data-reactive-editable")?W(e):e.value}function Ar(e){return e.hasAttribute("data-reactive-editable")?xr(e):e.defaultValue}function Pu(e){if(e.hasAttribute("data-reactive-editable"))return W(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Iu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||U.has(e.closest(yr)))return;let r=Pu(t);if(r===wr(e))return e.removeAttribute(O);if(r===Ar(e))return;e.setAttribute(O,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function Du(e){let t=[];for(let n of e.querySelectorAll(`[${O}]`)){if(n.closest(yr)!==e)continue;let r=n.getAttribute("name");if(wr(n)===Ar(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 Ts(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${O}]`))if(n.closest(yr)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(O)}function qu(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 Xi(e,t,n=null,r=30000){let o={root:e,streams:0,keep:n,events:[]},i=Ue;Ue=o;try{window.Turbo.renderStreamMessage(t)}finally{Ue=i}if(o.streams===0)Ts(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)):Wu(),c,u=new Promise((l)=>c=setTimeout(l,r));return Promise.race([a,u]).finally(()=>clearTimeout(c))}function Wu(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function ju(e){let t=Ue,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)=>{U.set(t.root,(U.get(t.root)||0)+1);let s;try{return await r(i)}catch(a){throw s=a,a}finally{let a=U.get(t.root)-1;if(a)U.set(t.root,a);else U.delete(t.root);Ts(t.root,t.keep),o(s)}}}var Zi="__materialize",Qi=!1;function Bu(){if(Qi)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Qi=!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 Sr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")on()}var Rs="data-reactive-active",lr="data-reactive-errors",k=0,K=[];function Os(){if(k++,k===1)K=[],Ns("reactive:busy")}function ce({action:e=null,kind:t,status:n=null,root:r=null}){if(k===0)return;K.push({action:e??null,kind:t,status:n??null,root:r||null})}function Ls(){if(k===0)return;if(k--,k===0)Ns("reactive:idle")}function Gl(){return k}function Ul(){k=0,K=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(Rs),e?.removeAttribute?.(lr)}function Ns(e){if(typeof document>"u")return;let t=document.documentElement,n=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(Rs,k>0),n&&K.length>0)t.setAttribute(lr,JSON.stringify(K));else t.removeAttribute(lr);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let r=n?{count:k,errors:K.slice()}:{count:k};document.dispatchEvent(new CustomEvent(e,{detail:r}))}}var Fs="data-reactive-requests";function Ms(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Ju(t))return;let n=Hu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(Fs,JSON.stringify(n))}function Ju(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Hu(e){try{let t=JSON.parse(e.getAttribute(Fs));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function es(){Au(),Su(),xu(),_u(),Tu(),$u(),Nu(),Fu(),rl(),Mu(),Cu(),Bu(),Sr()}function Gu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Cs=Symbol.for("phlex-reactive.core");if(globalThis[Cs])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[Cs]=!0;var $s=!1;function Uu(){if($s)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(Uu,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var zu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Ps(e){let t=String(e).toLowerCase();return t.startsWith("on")||zu.has(t)}var Qn=new WeakMap;function Ku(e,t,n){let[r,o,i]=t;Qn.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,Qn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(a),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Qn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Vu(e))}function Vu(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 Yu=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Xu=new Set(["lexxy-editor","trix-editor"]);function W(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
|
|
6
|
-
`):e.value}function ju(e,t,n){if(n?.transition)Ru(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Kn(e,t,n,r){if(ju(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 Yn(e){if(!ws(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function xs(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)Qe(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Bu='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ju(e){return e.querySelectorAll?.(Bu)?.[0]??null}function wr(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 Ji=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"}),Hi=Object.freeze(["meta","ctrl","alt","shift"]);function et(e,t,n){let r=e.split("+");for(let s of Hi)if(r.includes(s)!==Boolean(t[`${s}Key`]))return!1;let o=r.find((s)=>!Hi.includes(s));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Ji,o)?Ji[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Hu=(e)=>e&&typeof e==="object"?e.keys:String(e),Ar=()=>Ue().prevented??=new WeakSet;function Xn(e,t){if(t!=null&&!e.defaultPrevented)Ar().add(e);e.preventDefault()}function qe(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!Ar().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return et(Hu(e).replace(/^mod\+/,`${o}+`),t,n)}function Gu(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:wr(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 Gi(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==Sr(t.currentTarget))return!1;return o<0||n===null||et(r.slice(o+1),t,n)}function Uu(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 Ui=new WeakMap;function zu(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Ui.get(e);if(!o)o=new WeakMap,Ui.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let s=t.params?.ops,c=(r===globalThis.window?`${typeof s==="string"?s:JSON.stringify(s??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var zi=new WeakMap;function Vu(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=zi.get(e);if(!o)o=new WeakMap,zi.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let s=i.get(e.currentTarget);if(!s)s=new Set,i.set(e.currentTarget,s);if(s.has(r))return!0;return s.add(r),!1}var Ku=new Set(["click"]);function ar(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Wi,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&&Ku.has(o))s=s.slice(0,1);if(s.length>0)i=Xu(o,i,t,n);if(!i)continue;for(let a of s)if(Wi[o](a,i,t),i?.keep===!0)is(a,o,i,t)}}var Yu=new Set(["set_value","text","set_attr"]);function Xu(e,t,n,r){let o=e==="dispatch",i=o?t.detail_from:Yu.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,d]of Object.entries(i)){let f=Zu(c,d);if(f==null)return null;u[l]=f}return o?{...t,detail:u}:{...t,...u}}function Zu(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 Qu(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 el(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function cr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var G='[data-controller~="reactive"]',tl='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',ur=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!cr(e);function se(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&ur(r))r=r.parentElement?.closest?.(t);return r??null}var We=new WeakMap,je=new WeakMap;function nl(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 rl(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 ol(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function il(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function sl(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 Vi(e){return e.getAttribute?.("data-reactive-presence")!=null}function al(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function kl(e,t,n){}function cl(e,t){}function Tl(e){return[]}function Rl(e){return Promise.resolve()}var Ki=new Set;function ul(e,t,n){let r=e+t;if(Ki.has(r))return;Ki.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 Ol(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Yi=Promise.resolve();var Xi={enter:ps,exit:hs,fail:ae,count:bs,text:W,served:yr,waiting:new WeakMap},Zi=1,Zn=2,Qn=4,er=8,tr=16,Qi=32,es=64,ts=128,ns=256;Nt(Xi),gn(Xi);var fe=Symbol.for("phlex-reactive.early"),ll=1e4,fl=1500,Sr=(e)=>e!=null&&(e===globalThis.window||e.window===e),dl="dispatch";function Ue(){return globalThis[fe]??={queue:[],connected:new WeakSet},globalThis[fe]}function pl(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:ll}function hl(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 ml(e,t,n){return{[fe]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:hl(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&&!Ar().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var Ze=new WeakMap;function gl(e,{token:t,type:n,method:r,filter:o,win:i},s){let a=Ze.get(e);if(!a)Ze.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 rs(e,t,n,r){if(e?.[fe])return!1;let o=Sr(e?.currentTarget),i=o?r:e?.currentTarget,s=vl(e,i,o?`@${t}`:t),a=Ze.get(i),c=o&&JSON.stringify(e.params);for(let u of a?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!et(u.filter,e,n))continue;return u.armed=!1,!0}return s}var ze=new WeakMap;function bl(e,t,n){let r=ze.get(e);if(!r)ze.set(e,r=new Map),setTimeout(()=>ze.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function vl(e,t,n){let r=e&&ze.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class _s extends eu{static values={token:String};#g;#d=new Map;#p=new Map;#X;#S;#C;#E=0;#h=new Map;#x=new WeakMap;#o;featuresReady=Yi;#Ce=new Map;#$e=new Set;#Z=!1;#$=null;#Pe=new Map;#De=new Map;#Ie=new Map;#Q=0;#P;#_=0;#i=0;connect(){if(ys=!0,Ue().connected.add(this.element),We.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||cr(this.element))this.#o=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Be)this.#I();this.#D(!0)},this.element.addEventListener?.("turbo:morph-element",this.#o),this.element.addEventListener?.("focusin",this.#o),this.element.addEventListener?.(Be,this.#o);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(vr),this.#Q++,this.featuresReady=Yi,this.#D(),Ve(this.element),this.#te()}#D(e){this.#t(Zi,"persist",el,(t)=>qt(this,t,e)),this.#t(Zn,"defer",cr,(t)=>An(this,t,e)),this.#t(Qn,"form",nl,(t)=>Ht(this,t,e)),this.#t(er,"bindings",rl,(t)=>ot(this,t,e)),this.#t(tr,"compute",ol,(t)=>Et(this,t,e)),this.#t(Qi,"sortable",il,(t)=>Tn(this,t)),this.#t(ns,"drag",sl,(t)=>Cn(this,t)),this.#t(es,"presence",Vi,(t)=>Wn(this,t)),this.#t(ts,"countdown",al,(t)=>Hn(this,t))}#t(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#i|=e}catch(o){this.#q(t,"connect",o)}}#ee(){{let e=this.#i;this.#_=this.#i=0;let t=this.#e();if(e&Zi)this.#n("persist",()=>Wt(this,t));if(e&Zn)this.#n("defer",()=>Sn(this,t));if(e&Qn)this.#n("form",()=>Gt(this,t));if(e&er)this.#n("bindings",()=>it(this,t));if(e&tr)this.#n("compute",()=>xt(this,t));if(e&Qi)this.#n("sortable",()=>Rn(this,t));if(e&ns)this.#n("drag",()=>$n(this,t));if(e&es)this.#n("presence",()=>jn(this,t));if(e&ts)this.#n("countdown",()=>Gn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#qe(e){}#We(e,t){}#je(e){}#Be(e,t){}#Je(e,t,n,r){}#e(){return this.#P??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),proceed:(e,t,n,r)=>this.#T(e,t,n,0,0,null,r),forgetToken:()=>{this.#g=void 0},owns:(e)=>this.#u(e),ownership:()=>this.#G(),bindingOwns:(e)=>this.#U(e),bindingOwnership:()=>this.#Ae(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>ar(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#z(),plain:ls,text:W,served:yr,copyMedia:xs,setValue:Es,confirm:(e,t)=>Promise.resolve().then(()=>Ri(e,t)).catch(()=>!1)},this.#P}#I(){if(this.#i&Qn)Ut(this);if(this.#i&er)st(this);if(this.#i&tr)_t(this)}#q(e,t,n){if(ul(e,t,n),this.#r("feature"),ae({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})}#He(){}#te(){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.#ne();for(let[e,t]of je.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}je.delete(this.element)}#k=new Set;#ne(){let{queue:e}=Ue();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=pl(),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(fl,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.#re(o)}}#re({event:e,el:t,descs:n,win:r}){let o=ml(e,t,r),i=this.application?.schema?.keyMappings,s=(t.getAttribute("data-action")??"").split(/\s+/),a=r?this.element:t;for(let c of n){if(!s.includes(c.token))continue;if(c.filter&&!et(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!gl(a,c,r&&JSON.stringify(o.params)))continue;this.#k.add(a)}if(bl(e,a,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#ee(),this.#de(),this.#he(),this.#o)this.element.removeEventListener?.("turbo:morph-element",this.#o),this.element.removeEventListener?.("focusin",this.#o),this.element.removeEventListener?.(Be,this.#o);if(Ue().connected.delete(this.element),We.get(this.element)===this)We.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#k)Ze.delete(e);this.#k.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Di&&this.#ie())return this.#se(e);let t=e.params?.shortcut;if(t!=null&&!qe(t,e,this.application?.schema?.keyMappings))return;if(rs(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:d}=e.params;if(!n)return;let f=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u&&d!==!1)&&!this.#K(l,p))Xn(e,t);if(n===Di){let v=()=>{if(this.#i&Zn)return Re(this);if(this.tokenValue)return this.#T(p,n,"{}")};return this.#Z?this.featuresReady.then(v):v()}let h=this.#W(s,a),b=()=>this.#T(p,n,r,o,i,l,f);if(!h)return b();if(h instanceof Promise)return h.then((v)=>v?this.#b(v,p,b):b());this.#b(h,p,b)}#b(e,t,n){return Promise.resolve().then(()=>Ri(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return ct(this,this.#e(),t)}#oe(e){}#ie(){return!this.tokenValue&&ur(this.element)}#se(e){let t=se(this.element.parentElement,tl);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=We.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:s}=e.params;if(r!=null&&!qe(r,e,this.application?.schema?.keyMappings))return;let a=e.currentTarget??e.target;if((r!=null||!o&&s!==!1)&&!this.#K(i,a))Xn(e,r);je.set(t,[...je.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&&!qe(t.shortcut,e,this.application?.schema?.keyMappings))return;if(rs(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Vu(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Gu(n.ops),i=o.filter((a)=>Gi(a,e,null)),s=i.length<=1?i:i.filter((a)=>Gi(a,e,this.application?.schema?.keyMappings));if(s.length===0&&o.length>0){if(this.#A())un(this,e);return}for(let a of s){if(a.outside&&e[fe])continue;if(!Uu(a,e))continue;let c=a.within==null?r:this.#ae(a.within,e);if(a.within!=null&&!c)continue;if(a.shortcut!=null&&!qe(a.shortcut,e,this.application?.schema?.keyMappings))continue;if(zu(this,e,a))continue;this.#ce(a.legacy?{...n,ops:a.ops,debounce:void 0,throttle:void 0,prevent:void 0}:a,e,c,o.indexOf(a),r)}}#ae(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.#u(r)?r:null}#ce(e,t,n,r,o=n){let{ops:i,confirm:s,confirmWhen:a,outside:c,window:u,shortcut:l,prevent:d}=e;if(c&&this.element.contains(t.target))return;if(l!=null||!u&&d!==!1)Xn(t,l);let f=this.#W(s,a),p=this.#ue(e,r,o,()=>this.#Te(this.#ke(i),n));if(!f)return p();if(f instanceof Promise)return f.then((h)=>h?this.#b(h,n,p):p());this.#b(f,n,p)}#ue(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.#j(n,s,o,r);return()=>this.#B(n,s,i,r)}recompute(e){return kt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return gt(this,this.#e(),e)}tagsPick(e){return bt(this,this.#e(),e)}tagsRemove(e){return vt(this,this.#e(),e)}nestedAdd(e){return yt(this,this.#e(),e)}nestedRemove(e){return wt(this,this.#e(),e)}syncNestedJson(e){return at(this,this.#e(),e)}#Ge(e,t){}trackDirty(){Ae(this,this.#e())}listnavNext(e){this.#v(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#v(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#v(e,()=>0)}listnavLast(e){this.#v(e,(t,n)=>n-1)}listnavPick(e){let t=this.#m(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#m(e))t.removeAttribute("data-reactive-highlighted")}#v(e,t){let n=this.#m(e);if(!n.length)return;e.preventDefault();let r=this.#le(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"})}#le(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#G();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#T(e,t,n,r,o,i,s){if(this.#s("reactive:before-dispatch",{action:t,params:this.#V(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#fe(e,c,t,n,i,s);let u=Number(o)||0;if(u>0)return this.#pe(e,u,t,n,i,s);return this.#y(t,n,i,e,s)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},s=this.#Re(e,r,i),a=Boolean(n||o),c=(f)=>{if(!a||!f)return;let p=this.#e();if(i.inverse=dn(this,p,n,r),i.undo.push(...fn(this,p,o,r)),this.#O())i.resurrect=pn(this,p,n,r)},u=!0;c(!0);let l=()=>this.#ve(e,t,i,s),d=()=>this.#$?this.#$.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>d()),this.queue}#Ue(){return this.#oe("hints")}#fe(e,t,n,r,o,i){this.#j(e,dl,t,()=>this.#y(n,r,o,e,i))}#j(e,t,n,r){this.#R(e,t);let o=()=>{this.#R(e,t),r()},i=setTimeout(o,n);if(!Sr(e))e?.addEventListener?.("blur",o,{once:!0});let s=this.#d.get(e);if(!s)this.#d.set(e,s=new Map);s.set(t,{timer:i,flush:o})}#R(e,t){let n=this.#d.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#d.delete(e)}#de(){for(let[e,t]of[...this.#d])for(let n of[...t.keys()])this.#R(e,n)}#pe(e,t,n,r,o,i){return this.#B(e,n,t,()=>this.#y(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()}#he(){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}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#y(e,t)};ae({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)}#me(){this.element?.removeAttribute?.("data-reactive-error")}#ge(){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))}#be(){return rn()}#O(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#J(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ve(e,t,n,r){let{fields:o,files:i}=this.#z(),s=this.#V(t),a={...o,...s},c=this.#c,u=i.length>0,l=u?this.#xe(c,e,a,i):JSON.stringify({token:c,act:e,params:a}),d=this.#O()?{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.#be();try{if(navigator.onLine===!1){this.#l(n.inverse),this.#r("offline"),this.#a(e,t,a,{kind:"offline"});return}let f;try{let w={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Fe()};if(!u)w["Content-Type"]="application/json";let A=this.#Me();if(A)w["X-Pgbus-Connection"]=A;let E=Vi(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(E)w["X-Reactive-Presence"]=E;let T=vu(this.element);if(T)w["X-Reactive-Held"]=T;bs("action"),f=await fetch(this.#Ne(),{method:"POST",headers:w,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#M())})}catch(w){if(console.error("[phlex-reactive] action error",w),this.#l(n.inverse),w?.name==="TimeoutError"||w?.name==="AbortError"){this.#r("timeout"),this.#a(e,t,a,{kind:"timeout"});return}this.#ge(),this.#r("network"),this.#a(e,t,a,{kind:"network"});return}if(d)d.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#l(n.inverse),this.#r("redirected"),this.#a(e,t,a,{kind:"redirected",status:f.status});return}if(!f.ok){let w=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,w),this.#l(n.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let A=this.#H(w);if(this.#c=A??this.#c,d)Ee(d,w,A);let E=Pi(this.element,w,!0,this.#M());r?.handoff?.(),await E}this.#r("http"),this.#a(e,t,a,{kind:"http",status:f.status,body:w});return}let p=f.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#l(n.inverse),this.#r("content-type"),this.#a(e,t,a,{kind:"content-type",status:f.status});return}let h=await f.text(),b=this.#H(h);if(this.#c=b??this.#c,d)Ee(d,h,b);let v=Pi(this.element,h,yu(f),this.#M());if(n.resurrect)queueMicrotask(n.resurrect);if(this.#me(),this.#s("reactive:applied",{action:e,params:a,html:h}),r?.handoff?.(),await v)this.#r("apply"),ae({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"});return h}catch(f){console.error("[phlex-reactive] action error",f),this.#l(n.inverse),this.#r("apply"),ae({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"})}finally{if(r?.(),d)ln(this,{...d,ms:this.#J()-d.started})}}get#c(){return this.#g??this.tokenValue}set#c(e){this.#g=e}tokenValueChanged(){this.#g=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.#ye(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}#ye(e){let t=this.#C;if(t&&t.id===e)return t;let n=_u(e);return this.#C={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>`)}}#u(e){return e.closest('[data-controller~="reactive"]')===this.element}#G(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#u(t)}#we(){let e=this.element.querySelectorAll(G);if(e.length===0||[...e].every(ur))return()=>!0;return(t)=>{let n=se(t,G,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&se(n.parentElement,G,this.element)===this.element}}#U(e){if(this.#u(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=se(e,G,this.element);return t===this.element||se(t?.parentElement,G,this.element)===this.element}#Ae(){if(this.element.querySelectorAll(G).length===0)return()=>!0;return(e)=>this.#U(e)}#z(){let e={},t=[],n=this.#we(),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]${Lu}`).forEach((a)=>{if(n(a))o.push(a)});let i=this.#Se(r),s=this.#Ee(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?W(a):a.value??a.textContent??a.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Fu(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}}#Se(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}#Ee(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#xe(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.#L(o,this.#w(a),c);for(let a of i)o.append("empty_groups[]",a);let s=this.#_e(r);for(let{name:a,file:c,multiple:u}of r){let d=u||s.has(a)?`${this.#w(a)}[]`:this.#w(a);o.append(d,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#_e(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))}#V(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#ke(e){return wr(e)}#Te(e,t){ar(e,(n)=>this.#F(n,t),(n,r)=>this.#N(`client op "${n}"`,r))}#A(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#O()}#N(e,t){if(!this.#A())return;cn(this,e,t)}#ze(e){}#F(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.#u(r))}#K(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#l(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Re(e,t,n){this.#Oe(e,t),ps();let r=!1,o=!1,i=()=>{if(r)return;r=!0,this.#Le(e,t);for(let a of n.undo)a()},s=()=>{if(o)return;o=!0,i(),hs()};return s.handoff=i,s}#Oe(e,t){if(this.#f(t,e,1),this.#f(this.element,e,1),this.#h.set(e,(this.#h.get(e)??0)+1),this.#E++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#Y(e))this.#f(n,e,1)}#Le(e,t){this.#f(t,e,-1),this.#f(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.#E<=0)this.#E=0,this.element.removeAttribute("aria-busy");for(let r of this.#Y(e))this.#f(r,e,-1)}#f(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.#u(n))}#Ne(){return this.#X??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#M(){if(this.#S!=null)return this.#S;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#S=Number.isFinite(t)&&t>0?t:30000}#Fe(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Me(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)qi();else document.addEventListener("turbo:load",qi,{once:!0});br();var Il=_s;export{ds as ACTIVE_ATTR,Lu as EDITOR_SELECTOR,Nu as EDITOR_TAGS,ir as ERRORS_ATTR,dc as LATENCY_KEY,gs as REQUESTS_ATTR,ku as checkReactiveRegistration,bs as countReactiveRequest,Il as default,_o as disableLatencySim,W as editableValue,xo as enableLatencySim,ps as enterReactiveActivity,_u as escapeRegExp,hs as exitReactiveActivity,Rl as loadReactiveFeature,El as onReactiveStreamWithoutEffects,xl as reactiveActivityCount,Ol as reactiveFeatureNames,ae as recordReactiveError,qi as registerReactiveActions,iu as registerReactiveDefer,br as registerReactiveDev,au as registerReactiveDismiss,au as registerReactiveEffects,cl as registerReactiveFeature,kl as registerReactiveFeatureLoader,pu as registerReactiveImageFallback,ou as registerReactiveJs,du as registerReactiveKeep,fu as registerReactiveModals,mu as registerReactiveMorphFocus,Su as registerReactiveOffline,hu as registerReactivePlaintext,Du as registerReactiveRejectedFiles,au as registerReactiveStreamRender,nu as registerReactiveToken,tu as registerReactiveVisit,_l as resetReactiveActivity,yr as serverText,Tl as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Ze=new WeakMap;function Er(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Ze.has(e))Ze.set(e,W(e))}function xr(e){return Er(e),Ze.get(e)}function Zu(e){return Xu.has(e.localName)?typeof e.value==="string":!0}var ts=Object.freeze({show:(e,t,n)=>er(e,!1,t,n),hide:(e,t,n)=>er(e,!0,t,n),toggle:(e,t,n)=>er(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(tr(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(tr(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!tr(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)=>ul(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>ws(e),close_dialog:(e)=>Ou(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{}Ws(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)mt(r,t.group,t.checked)},presence:(e,t)=>Hn(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=Qu(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)=>el(e),preview_file:(e,t,n)=>tl(e,t,n),set_value:(e,t)=>qs(e,String(t.value??"")),persist_state:(e,t)=>Jt(e,t.state),persist_clear:(e)=>Ht(e)});function Qu(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function el(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,Ds(e),e.focus?.()}).catch(()=>{})}var ue=new Map,le=null;function tl(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return ze(`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 ze(`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=il(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((d,f)=>{let p=typeof d?.type==="string"&&i(d)?s(d)&&"size":"type";if(p)a.push({reason:p,file:d,index:f});return!p}),l=a.length>0&&!ol(e,u)?o.length:u.length;for(let d of a)d.remaining=l;c=u.find((d)=>d.type.startsWith("image/"))}else{let u=o.filter((d)=>typeof d?.type==="string"&&i(d));c=u.find((d)=>d.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(Is(r),c){let u=URL.createObjectURL(c);ue.set(r,u),r.setAttribute("src",u),sl()}else r.removeAttribute("src");if(tt(r),t.wrap!=null){let u=n({...t,to:t.wrap});if(u.length===0)ze(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let l of u)c?Es(l):Ss(l)}if(t.name!=null)for(let u of n({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)nl(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 Qe="data-reactive-file-rejected";function nl(e,t,n,r){if(t.length===0)return fr(e,`rejected: ${JSON.stringify(r)} is not on the page`);for(let o of t){for(let s of[...o.children])if(s.hasAttribute(Qe))s.remove();let i=[...o.children].find((s)=>s.localName==="template");if(!i){fr(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(Qe,""),o.append(u)}}}}var ns=!1;function rl(){if(ns)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ns=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented||!t.lastElementChild?.hasAttribute(Qe))return;for(let r of t.children)if(r.hasAttribute(Qe))n.append(r.cloneNode(!0))})}function ol(e,t){if(typeof DataTransfer!=="function")return fr(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 il(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 ze(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function fr(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))ze(t)}function Is(e){let t=ue.get(e);if(t===void 0)return;if(ue.delete(e),URL.revokeObjectURL(t),ue.size===0)le?.disconnect(),le=null}function sl(){if(le||typeof MutationObserver!=="function"||!document?.documentElement)return;le=new MutationObserver(()=>{for(let[e,t]of ue)if(!e.isConnected||e.getAttribute("src")!==t)Is(e)}),le.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function Ds(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function qs(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=rs(e);if(e.value=t,rs(e)!==n)Ds(e)}function rs(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function al(e,t,n){if(n?.transition)Ku(e,n.transition,()=>e.hidden=t);else e.hidden=t}function er(e,t,n,r){if(al(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 tr(e){if(!Ps(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function Ws(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)tt(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var cl='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function ul(e){return e.querySelectorAll?.(cl)?.[0]??null}function _r(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 os=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"}),is=Object.freeze(["meta","ctrl","alt","shift"]);function nt(e,t,n){let r=e.split("+");for(let s of is)if(r.includes(s)!==Boolean(t[`${s}Key`]))return!1;let o=r.find((s)=>!is.includes(s));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(os,o)?os[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var ll=(e)=>e&&typeof e==="object"?e.keys:String(e),kr=()=>Ke().prevented??=new WeakSet;function nr(e,t){if(t!=null&&!e.defaultPrevented)kr().add(e);e.preventDefault()}function je(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!kr().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return nt(ll(e).replace(/^mod\+/,`${o}+`),t,n)}function fl(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:_r(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 ss(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==Tr(t.currentTarget))return!1;return o<0||n===null||nt(r.slice(o+1),t,n)}function dl(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 as=new WeakMap;function pl(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=as.get(e);if(!o)o=new WeakMap,as.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let s=t.params?.ops,c=(r===globalThis.window?`${typeof s==="string"?s:JSON.stringify(s??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var cs=new WeakMap;function ml(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=cs.get(e);if(!o)o=new WeakMap,cs.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let s=i.get(e.currentTarget);if(!s)s=new Set,i.set(e.currentTarget,s);if(s.has(r))return!0;return s.add(r),!1}var hl=new Set(["click"]);function dr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(ts,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&&hl.has(o))s=s.slice(0,1);if(s.length>0)i=bl(o,i,t,n);if(!i)continue;for(let a of s)if(ts[o](a,i,t),i?.keep===!0)As(a,o,i,t)}}var gl=new Set(["set_value","text","set_attr"]);function bl(e,t,n,r){let o=e==="dispatch",i=o?t.detail_from:gl.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,d]of Object.entries(i)){let f=vl(c,d);if(f==null)return null;u[l]=f}return o?{...t,detail:u}:{...t,...u}}function vl(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 yl(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 wl(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function pr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var G='[data-controller~="reactive"]',Al='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',mr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!pr(e);function ae(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&mr(r))r=r.parentElement?.closest?.(t);return r??null}var Be=new WeakMap,Je=new WeakMap;function Sl(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 El(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 xl(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function _l(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function kl(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 us(e){return e.getAttribute?.("data-reactive-presence")!=null}function Tl(e){return e.getAttribute?.("data-reactive-subscribe")!=null}function Rl(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function zl(e,t,n){}function Ol(e,t){}function Kl(e){return[]}function Vl(e){return Promise.resolve()}var ls=new Set;function Ll(e,t,n){let r=e+t;if(ls.has(r))return;ls.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 Yl(){return["persist","defer","form","bindings","compute","sortable","drag","presence","subscribe","countdown","effects","hints","devtools"]}var fs=Promise.resolve();var ds={enter:Os,exit:Ls,fail:ce,count:Ms,text:W,served:xr,waiting:new WeakMap},ps=1,rr=2,or=4,ir=8,sr=16,ms=32,hs=64,gs=128,bs=256,vs=512;Mt(ds),vn(ds);var de=Symbol.for("phlex-reactive.early"),Nl=1e4,Fl=1500,Tr=(e)=>e!=null&&(e===globalThis.window||e.window===e),Ml="dispatch";function Ke(){return globalThis[de]??={queue:[],connected:new WeakSet},globalThis[de]}function Cl(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Nl}function $l(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 Pl(e,t,n){return{[de]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:$l(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&&!kr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var et=new WeakMap;function Il(e,{token:t,type:n,method:r,filter:o,win:i},s){let a=et.get(e);if(!a)et.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 ys(e,t,n,r){if(e?.[de])return!1;let o=Tr(e?.currentTarget),i=o?r:e?.currentTarget,s=ql(e,i,o?`@${t}`:t),a=et.get(i),c=o&&JSON.stringify(e.params);for(let u of a?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!nt(u.filter,e,n))continue;return u.armed=!1,!0}return s}var Ve=new WeakMap;function Dl(e,t,n){let r=Ve.get(e);if(!r)Ve.set(e,r=new Map),setTimeout(()=>Ve.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function ql(e,t,n){let r=e&&Ve.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class js extends wu{static values={token:String};#g;#d=new Map;#p=new Map;#X;#S;#C;#E=0;#m=new Map;#x=new WeakMap;#o;featuresReady=fs;#Ce=new Map;#$e=new Set;#Z=!1;#$=null;#Pe=new Map;#Ie=new Map;#De=new Map;#Q=0;#P;#_=0;#i=0;connect(){if($s=!0,Ke().connected.add(this.element),Be.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||pr(this.element))this.#o=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===He)this.#D();this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#o),this.element.addEventListener?.("focusin",this.#o),this.element.addEventListener?.(He,this.#o);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Er),this.#Q++,this.featuresReady=fs,this.#I(),Ye(this.element),this.#te()}#I(e){this.#t(ps,"persist",wl,(t)=>jt(this,t,e)),this.#t(rr,"defer",pr,(t)=>En(this,t,e)),this.#t(or,"form",Sl,(t)=>Ut(this,t,e)),this.#t(ir,"bindings",El,(t)=>st(this,t,e)),this.#t(sr,"compute",xl,(t)=>_t(this,t,e)),this.#t(ms,"sortable",_l,(t)=>On(this,t)),this.#t(bs,"drag",kl,(t)=>Pn(this,t)),this.#t(hs,"presence",us,(t)=>Bn(this,t)),this.#t(vs,"subscribe",Tl,()=>Un(this)),this.#t(gs,"countdown",Rl,(t)=>Vn(this,t))}#t(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#i|=e}catch(o){this.#q(t,"connect",o)}}#ee(){{let e=this.#i;this.#_=this.#i=0;let t=this.#e();if(e&ps)this.#n("persist",()=>Bt(this,t));if(e&rr)this.#n("defer",()=>xn(this,t));if(e&or)this.#n("form",()=>zt(this,t));if(e&ir)this.#n("bindings",()=>at(this,t));if(e&sr)this.#n("compute",()=>kt(this,t));if(e&ms)this.#n("sortable",()=>Ln(this,t));if(e&bs)this.#n("drag",()=>In(this,t));if(e&hs)this.#n("presence",()=>Jn(this,t));if(e&vs)this.#n("subscribe",()=>zn(this));if(e&gs)this.#n("countdown",()=>Yn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#qe(e){}#We(e,t){}#je(e){}#Be(e,t){}#Je(e,t,n,r){}#e(){return this.#P??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#D(),proceed:(e,t,n,r)=>this.#T(e,t,n,0,0,null,r),forgetToken:()=>{this.#g=void 0},owns:(e)=>this.#u(e),ownership:()=>this.#G(),bindingOwns:(e)=>this.#U(e),bindingOwnership:()=>this.#Ae(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>dr(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#h(e),collectFields:()=>this.#z(),plain:ks,text:W,served:xr,copyMedia:Ws,setValue:qs,confirm:(e,t)=>Promise.resolve().then(()=>Ji(e,t)).catch(()=>!1)},this.#P}#D(){if(this.#i&or)Kt(this);if(this.#i&ir)ct(this);if(this.#i&sr)Tt(this)}#q(e,t,n){if(Ll(e,t,n),this.#r("feature"),ce({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})}#He(){}#te(){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.#ne();for(let[e,t]of Je.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Je.delete(this.element)}#k=new Set;#ne(){let{queue:e}=Ke();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=Cl(),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(Fl,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.#re(o)}}#re({event:e,el:t,descs:n,win:r}){let o=Pl(e,t,r),i=this.application?.schema?.keyMappings,s=(t.getAttribute("data-action")??"").split(/\s+/),a=r?this.element:t;for(let c of n){if(!s.includes(c.token))continue;if(c.filter&&!nt(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Il(a,c,r&&JSON.stringify(o.params)))continue;this.#k.add(a)}if(Dl(e,a,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#ee(),this.#de(),this.#me(),this.#o)this.element.removeEventListener?.("turbo:morph-element",this.#o),this.element.removeEventListener?.("focusin",this.#o),this.element.removeEventListener?.(He,this.#o);if(Ke().connected.delete(this.element),Be.get(this.element)===this)Be.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#k)et.delete(e);this.#k.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Zi&&this.#ie())return this.#se(e);let t=e.params?.shortcut;if(t!=null&&!je(t,e,this.application?.schema?.keyMappings))return;if(ys(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:d}=e.params;if(!n)return;let f=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u&&d!==!1)&&!this.#V(l,p))nr(e,t);if(n===Zi){let v=()=>{if(this.#i&rr)return Oe(this);if(this.tokenValue)return this.#T(p,n,"{}")};return this.#Z?this.featuresReady.then(v):v()}let m=this.#W(s,a),b=()=>this.#T(p,n,r,o,i,l,f);if(!m)return b();if(m instanceof Promise)return m.then((v)=>v?this.#b(v,p,b):b());this.#b(m,p,b)}#b(e,t,n){return Promise.resolve().then(()=>Ji(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return lt(this,this.#e(),t)}#oe(e){}#ie(){return!this.tokenValue&&mr(this.element)}#se(e){let t=ae(this.element.parentElement,Al);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=Be.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:s}=e.params;if(r!=null&&!je(r,e,this.application?.schema?.keyMappings))return;let a=e.currentTarget??e.target;if((r!=null||!o&&s!==!1)&&!this.#V(i,a))nr(e,r);Je.set(t,[...Je.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&&!je(t.shortcut,e,this.application?.schema?.keyMappings))return;if(ys(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(ml(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=fl(n.ops),i=o.filter((a)=>ss(a,e,null)),s=i.length<=1?i:i.filter((a)=>ss(a,e,this.application?.schema?.keyMappings));if(s.length===0&&o.length>0){if(this.#A())fn(this,e);return}for(let a of s){if(a.outside&&e[de])continue;if(!dl(a,e))continue;let c=a.within==null?r:this.#ae(a.within,e);if(a.within!=null&&!c)continue;if(a.shortcut!=null&&!je(a.shortcut,e,this.application?.schema?.keyMappings))continue;if(pl(this,e,a))continue;this.#ce(a.legacy?{...n,ops:a.ops,debounce:void 0,throttle:void 0,prevent:void 0}:a,e,c,o.indexOf(a),r)}}#ae(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.#u(r)?r:null}#ce(e,t,n,r,o=n){let{ops:i,confirm:s,confirmWhen:a,outside:c,window:u,shortcut:l,prevent:d}=e;if(c&&this.element.contains(t.target))return;if(l!=null||!u&&d!==!1)nr(t,l);let f=this.#W(s,a),p=this.#ue(e,r,o,()=>this.#Te(this.#ke(i),n));if(!f)return p();if(f instanceof Promise)return f.then((m)=>m?this.#b(m,n,p):p());this.#b(f,n,p)}#ue(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.#j(n,s,o,r);return()=>this.#B(n,s,i,r)}recompute(e){return Rt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#h(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return vt(this,this.#e(),e)}tagsPick(e){return yt(this,this.#e(),e)}tagsRemove(e){return wt(this,this.#e(),e)}nestedAdd(e){return At(this,this.#e(),e)}nestedRemove(e){return St(this,this.#e(),e)}syncNestedJson(e){return ut(this,this.#e(),e)}#Ge(e,t){}trackDirty(){Se(this,this.#e())}listnavNext(e){this.#v(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#v(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#v(e,()=>0)}listnavLast(e){this.#v(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")}#v(e,t){let n=this.#h(e);if(!n.length)return;e.preventDefault();let r=this.#le(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"})}#le(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){if(this.#s("reactive:before-dispatch",{action:t,params:this.#K(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#fe(e,c,t,n,i,s);let u=Number(o)||0;if(u>0)return this.#pe(e,u,t,n,i,s);return this.#y(t,n,i,e,s)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},s=this.#Re(e,r,i),a=Boolean(n||o),c=(f)=>{if(!a||!f)return;let p=this.#e();if(i.inverse=mn(this,p,n,r),i.undo.push(...pn(this,p,o,r)),this.#O())i.resurrect=hn(this,p,n,r)},u=!0;c(!0);let l=()=>this.#ve(e,t,i,s),d=()=>this.#$?this.#$.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>d()),this.queue}#Ue(){return this.#oe("hints")}#fe(e,t,n,r,o,i){this.#j(e,Ml,t,()=>this.#y(n,r,o,e,i))}#j(e,t,n,r){this.#R(e,t);let o=()=>{this.#R(e,t),r()},i=setTimeout(o,n);if(!Tr(e))e?.addEventListener?.("blur",o,{once:!0});let s=this.#d.get(e);if(!s)this.#d.set(e,s=new Map);s.set(t,{timer:i,flush:o})}#R(e,t){let n=this.#d.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#d.delete(e)}#de(){for(let[e,t]of[...this.#d])for(let n of[...t.keys()])this.#R(e,n)}#pe(e,t,n,r,o,i){return this.#B(e,n,t,()=>this.#y(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()}#me(){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}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#y(e,t)};ce({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)}#he(){this.element?.removeAttribute?.("data-reactive-error")}#ge(){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))}#be(){return sn()}#O(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#J(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ve(e,t,n,r){let{fields:o,files:i}=this.#z(),s=this.#K(t),a={...o,...s},c=this.#c,u=i.length>0,l=u?this.#xe(c,e,a,i):JSON.stringify({token:c,act:e,params:a}),d=this.#O()?{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.#be();try{if(navigator.onLine===!1){this.#l(n.inverse),this.#r("offline"),this.#a(e,t,a,{kind:"offline"});return}let f;try{let w={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Fe()};if(!u)w["Content-Type"]="application/json";let A=this.#Me();if(A)w["X-Pgbus-Connection"]=A;let E=us(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(E)w["X-Reactive-Presence"]=E;let T=Du(this.element);if(T)w["X-Reactive-Held"]=T;Ms("action"),f=await fetch(this.#Ne(),{method:"POST",headers:w,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#M())})}catch(w){if(console.error("[phlex-reactive] action error",w),this.#l(n.inverse),w?.name==="TimeoutError"||w?.name==="AbortError"){this.#r("timeout"),this.#a(e,t,a,{kind:"timeout"});return}this.#ge(),this.#r("network"),this.#a(e,t,a,{kind:"network"});return}if(d)d.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#l(n.inverse),this.#r("redirected"),this.#a(e,t,a,{kind:"redirected",status:f.status});return}if(!f.ok){let w=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,w),this.#l(n.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let A=this.#H(w);if(this.#c=A??this.#c,d)xe(d,w,A);let E=Xi(this.element,w,!0,this.#M());r?.handoff?.(),await E}this.#r("http"),this.#a(e,t,a,{kind:"http",status:f.status,body:w});return}let p=f.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#l(n.inverse),this.#r("content-type"),this.#a(e,t,a,{kind:"content-type",status:f.status});return}let m=await f.text(),b=this.#H(m);if(this.#c=b??this.#c,d)xe(d,m,b);let v=Xi(this.element,m,qu(f),this.#M());if(n.resurrect)queueMicrotask(n.resurrect);if(this.#he(),this.#s("reactive:applied",{action:e,params:a,html:m}),r?.handoff?.(),await v)this.#r("apply"),ce({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"});return m}catch(f){console.error("[phlex-reactive] action error",f),this.#l(n.inverse),this.#r("apply"),ce({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:a,kind:"apply"})}finally{if(r?.(),d)dn(this,{...d,ms:this.#J()-d.started})}}get#c(){return this.#g??this.tokenValue}set#c(e){this.#g=e}tokenValueChanged(){this.#g=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.#ye(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}#ye(e){let t=this.#C;if(t&&t.id===e)return t;let n=Gu(e);return this.#C={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>`)}}#u(e){return e.closest('[data-controller~="reactive"]')===this.element}#G(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#u(t)}#we(){let e=this.element.querySelectorAll(G);if(e.length===0||[...e].every(mr))return()=>!0;return(t)=>{let n=ae(t,G,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&ae(n.parentElement,G,this.element)===this.element}}#U(e){if(this.#u(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=ae(e,G,this.element);return t===this.element||ae(t?.parentElement,G,this.element)===this.element}#Ae(){if(this.element.querySelectorAll(G).length===0)return()=>!0;return(e)=>this.#U(e)}#z(){let e={},t=[],n=this.#we(),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]${Yu}`).forEach((a)=>{if(n(a))o.push(a)});let i=this.#Se(r),s=this.#Ee(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?W(a):a.value??a.textContent??a.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Zu(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}}#Se(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}#Ee(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#xe(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.#L(o,this.#w(a),c);for(let a of i)o.append("empty_groups[]",a);let s=this.#_e(r);for(let{name:a,file:c,multiple:u}of r){let d=u||s.has(a)?`${this.#w(a)}[]`:this.#w(a);o.append(d,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#_e(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{}}}#ke(e){return _r(e)}#Te(e,t){dr(e,(n)=>this.#F(n,t),(n,r)=>this.#N(`client op "${n}"`,r))}#A(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#O()}#N(e,t){if(!this.#A())return;ln(this,e,t)}#ze(e){}#F(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.#u(r))}#V(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#l(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Re(e,t,n){this.#Oe(e,t),Os();let r=!1,o=!1,i=()=>{if(r)return;r=!0,this.#Le(e,t);for(let a of n.undo)a()},s=()=>{if(o)return;o=!0,i(),Ls()};return s.handoff=i,s}#Oe(e,t){if(this.#f(t,e,1),this.#f(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.#f(n,e,1)}#Le(e,t){this.#f(t,e,-1),this.#f(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.#f(r,e,-1)}#f(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.#u(n))}#Ne(){return this.#X??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#M(){if(this.#S!=null)return this.#S;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#S=Number.isFinite(t)&&t>0?t:30000}#Fe(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Me(){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)es();else document.addEventListener("turbo:load",es,{once:!0});Sr();var sf=js;export{Rs as ACTIVE_ATTR,Yu as EDITOR_SELECTOR,Xu as EDITOR_TAGS,lr as ERRORS_ATTR,Rc as LATENCY_KEY,Fs as REQUESTS_ATTR,Uu as checkReactiveRegistration,Ms as countReactiveRequest,sf as default,Lo as disableLatencySim,W as editableValue,Oo as enableLatencySim,Os as enterReactiveActivity,Gu as escapeRegExp,Ls as exitReactiveActivity,Vl as loadReactiveFeature,Hl as onReactiveStreamWithoutEffects,Gl as reactiveActivityCount,Yl as reactiveFeatureNames,ce as recordReactiveError,es as registerReactiveActions,_u as registerReactiveDefer,Sr as registerReactiveDev,Tu as registerReactiveDismiss,Tu as registerReactiveEffects,Ol as registerReactiveFeature,zl as registerReactiveFeatureLoader,Mu as registerReactiveImageFallback,xu as registerReactiveJs,Fu as registerReactiveKeep,Nu as registerReactiveModals,$u as registerReactiveMorphFocus,Bu as registerReactiveOffline,Cu as registerReactivePlaintext,rl as registerReactiveRejectedFiles,Tu as registerReactiveStreamRender,Su as registerReactiveToken,Au as registerReactiveVisit,Ul as resetReactiveActivity,xr as serverText,Kl as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=C5F6743D6037A4D464756E2164756E21
|
|
9
9
|
//# sourceMappingURL=reactive_controller.min.js.map
|