phlex-reactive 0.16.8 → 0.16.9
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 +47 -1
- data/README.md +60 -5
- data/app/javascript/phlex/reactive/core.min.js +4 -4
- data/app/javascript/phlex/reactive/core.min.js.map +3 -3
- data/app/javascript/phlex/reactive/early.js +28 -1
- data/app/javascript/phlex/reactive/early.min.js +2 -2
- data/app/javascript/phlex/reactive/early.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/devtools.js +15 -5
- data/app/javascript/phlex/reactive/features/devtools.min.js +2 -2
- data/app/javascript/phlex/reactive/features/devtools.min.js.map +3 -3
- data/app/javascript/phlex/reactive/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +4 -4
- data/app/javascript/phlex/reactive/runtime.js +85 -11
- data/lib/phlex/reactive/component/dsl.rb +2 -0
- data/lib/phlex/reactive/component/helpers.rb +50 -4
- data/lib/phlex/reactive/js.rb +211 -41
- data/lib/phlex/reactive/response.rb +4 -0
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as Uc}from"@hotwired/stimulus";import{confirmResolver as Ai}from"phlex/reactive/confirm";import{confirmPredicate as ys}from"phlex/reactive/confirm_predicate";var j=new WeakMap,Qe=new WeakMap;function F(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Qe.set(n.root,n)}return n}function E(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function U(e,t){E(e,"turbo:morph-element",t),e.seeds.push(t),t()}function et(e,t){let n=F(e,t);n.offs=[],n.seeds=[];let r,o,i,a,s;(n.wire=()=>{if(!n.show&&_s(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")Ws(n,c.target);else n.groups=Ds(n),Ar(n);br(n)},E(n,"input change",n.show),E(n,"focusout",(c)=>{let u=c.target?.getAttribute?.("name");if(!u||n.touched?.has(u)||!n.core.bindingOwns(c.target))return;if((n.touched??=new Set).add(u),n.root.querySelector?.("[data-reactive-show-after]"))br(n)}),U(n,n.show);if(!n.arm&&ks(n))E(n,"input change",(c)=>gr(n,c)),U(n,n.arm=()=>{gr(n,null),Ar(n)});if(!r&&(r=n.show||n.arm))E(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))E(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!ws(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=fe(n)))E(n,"input",(c)=>Js(n,c)&&z(n)),U(n,()=>z(n));if(!a&&(a=pe(n)))U(n,()=>Mr(n));if(!s&&(s=Us(n)))E(n,"input change",(c)=>Ir(n,c)),U(n,()=>ft(n))})(),E(n,"keydown",(c)=>ca(n,c)),E(n,"paste drop",(c)=>ua(n,c)),E(n,"input",(c)=>la(n,c))}function ws(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function tt(e){let t=j.get(e);if(!t)return;j.delete(e),Qe.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function nt(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function rt(e,t,n){return Ir(F(e,t),n)}function ot(e,t,n){return Br(F(e,t),n)}var As=/^#[A-Za-z_][\w-]*$/,Er="[data-reactive-show-field], [data-reactive-show]";function Ss(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Dr){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Wr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function xr(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function Es(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function _r(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return K(n,t);return xs(e,t)}function xs(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)=>bt(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function le(e,t="show"){if(typeof e==="string"&&As.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function _s(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(Er)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(de)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${Rr}, ${Lr}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function ks(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Ts(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Es(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function gr(e,t){let n=Ts(e);if(!n.length)return;let r=Tr(e,e.core.bindingOwnership());n.forEach((o,i)=>{let a=K(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function br(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.core.bindingOwnership(),r=e.root.getAttribute?.("data-reactive-scope")||null,o=Tr(e,n),i=[];for(let a of e.root.querySelectorAll(Er)){if(!t(a))continue;let s=a.getAttribute("data-reactive-show");if(s!==null){let f=_r(xr(s),o);if(f===null)continue;let d=a.getAttribute("data-reactive-show-after"),p=f&&(d==null||!!e.touched?.has(st(d,r)));vr(a,p,n);let g=(e.shown??=new WeakMap).get(a);if(e.shown.set(a,p),Rs.some((m)=>a.hasAttribute(`data-reactive-show-${m}`))&&g!==void 0&&g!==p)i.push(a);continue}let c=a.getAttribute("data-reactive-show-field");if(!c)continue;let u=o(c);if(u===null)continue;let l=Ss(a,u);if(l===null)continue;vr(a,l,n)}if(e.groups)js(e,o,t,r);Ms(e,o,t),Ps(e,o,t,r,n),Os(e,o),Bs(e,o);for(let a of i)Ls(e,a,n,r)}var Rs=["clear","focus","scroll"];function Ls(e,t,n,r){if(t.hidden){let s=[];try{s=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(s)?s:[]).map((u)=>st(String(u),r)));for(let u of c.size?e.root.querySelectorAll("[name]"):[]){if(!c.has(u.getAttribute("name"))||!n(u)||u.type==="file")continue;if(u.type==="checkbox"||u.type==="radio"){if(u.checked)u.checked=!1,M(u)}else e.core.setValue(u,"")}return}let o=t.getAttribute("data-reactive-show-scroll")==="true";if(o)t.scrollIntoView?.({block:"nearest"});let i=t.getAttribute("data-reactive-show-focus"),a=null;try{a=i?e.root.querySelector(i):null}catch{}a?.focus?.(o?{preventScroll:!0}:void 0)}function vr(e,t,n){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 Os(e,t){let n=kr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Fs(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!le(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>bt(l,a))}else{let l=jr(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function Fs(e,t,n){if(!le(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=sa(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!aa(r))return;let i=K(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function kr(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function Ns(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(it(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function it(e,t){return`[name="${st(e,t)}"]`}function st(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Tr(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?at(e,o,t,n).filter((s)=>s.checked).length:Ns(e,o,t,n));return r.get(a)}}var Rr="[data-reactive-media]";function Ms(e,t,n){for(let r of e.root.querySelectorAll(Rr)){if(!n(r))continue;let o,i,a;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)a=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!a){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let s=t(o.field);if(s===null)continue;let c=o.take>0?[...s]:null,u=c?c.slice(0,o.take).join(""):s,l=c?.length<o.take||i?.test(u)===!1||a?.test(s)===!1;if(l&&o.pending==="keep"){yr(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?wr(e,o.pool[u])[0]:null,d=e.core.copyMedia(r,f??null);if(d===null)continue;if(yr(r,l?"pending":d===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":d===!1?String(o.blank??""):d;for(let g of wr(e,o.label))if(g.textContent!==p)g.textContent=p}}function yr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function wr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Lr="[data-reactive-css-vars]",Cs=/^--[a-z0-9-]+$/i,$s=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ps(e,t,n,r,o){let i=[...e.root.querySelectorAll(Lr)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))i.unshift(e.root);for(let a of i){let s;try{s=JSON.parse(a.getAttribute("data-reactive-css-vars"))}catch{}if(!Array.isArray(s?.to)||!s.vars||typeof s.vars!=="object"){console.warn("[phlex-reactive] malformed data-reactive-css-vars — skipped (two reactive_css_vars on one element?)");continue}let c=s.to.flatMap((u)=>{let l={to:u,global:s.global===!0},f=[];try{f=e.core.opTargets(l)}catch{}if(!f.length)e.core.diagnose("reactive_css_vars",l);return f});for(let[u,l]of Object.entries(s.vars)){let f=l?.unit??"";if(!Cs.test(u)||!$s.includes(f)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let d=Is(e,t,l.field,o,r);if(d===void 0)continue;let p=d===null?"":`${d}${f}`;for(let g of c){if(g.style.getPropertyValue(u)===p)continue;if(p)g.style.setProperty(u,p);else g.style.removeProperty(u)}}}}function Is(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(it(n,o))].some((s)=>r(s)&&s.type==="checkbox"))return i==="true"?1:0;let a=i.trim()?Number(i):NaN;return Number.isFinite(a)?a:null}var de="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Ds(e){return!!e.root.querySelector?.(de)}function at(e,t,n,r,o){return[...e.root.querySelectorAll(it(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||qs(i.getAttribute("data-reactive-group"),o)))}function qs(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Ws(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Or(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function ct(e,t,n){if(!t)return;let r=Qe.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Or(r,t,n!==!1),r.show?.()}function Or(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=at(e,t,e.core.ownership(),i,o).filter((s)=>s!==r&&s.checked!==n);for(let s of a)s.checked=n;e.flipping=!0;try{for(let s of a)for(let c of["input","change"])s.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function js(e,t,n,r){for(let o of e.root.querySelectorAll(de)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=_r(xr(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=o.getAttribute("data-reactive-select-all-under"),u=at(e,s,n,r,c).filter((f)=>f!==o),l=u.filter((f)=>f.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function Bs(e,t){for(let[n,r]of Object.entries(kr(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!le(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!le(a,"group"))continue;let c=K(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function Ar(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${de}, [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 fe(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Js(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var Hs=/[\s\-'(),./]/;function Gs(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||Hs.test(t[r-1]))return!0;return!1}function z(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=e.root.getAttribute("data-reactive-filter-match"),a=e.root.hasAttribute?.("data-reactive-filter-fold"),s=(d)=>{let p=(d??"").toLowerCase().trim();return a?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=s(o.value),u=0;for(let d of e.root.querySelectorAll(n)){if(!r(d))continue;let p=d.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Gs(i,s(d.getAttribute("data-reactive-filter-text")??d.textContent),c);if(d.hidden=p,p)d.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let d of e.root.querySelectorAll(l)){if(!r(d))continue;let p=[...d.querySelectorAll(n)].filter(r);if(p.length===0)continue;d.hidden=p.every((g)=>g.hidden)}let f=e.root.getAttribute("data-reactive-filter-empty");if(f){for(let d of e.root.querySelectorAll(f))if(r(d))d.hidden=u>0}}function pe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Us(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function ut(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 lt(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 Fr(e,t){let n=ut(e);if(!n)return!1;let r=lt(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)Nr(e,n,r);return i}function Nr(e,t,n){t.value=n.join(","),M(t),Mr(e)}function zs(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Mr(e){let t=ut(e);if(!t)return;let n=lt(t),r=e.core.ownership();Ks(e,n,r),Vs(e,n,r)}function Ks(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Vs(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"),!fe(e))o.hidden=!1}}if(fe(e))z(e)}function Ys(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Xs(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 Zs(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 Qs(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let f=a.find((d)=>$r(d.getAttribute?.("name"))===c);if(!f)continue;ea(f,l),s.push(l)}if(r)for(let c of s)ta(c);return s[0]??null}function ea(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Xe(t)!=="";else e.value=Xe(t);M(e)}function ta(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function na(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Sr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);ft(e)}function ft(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Pr(e,n.getAttribute("data-reactive-nested-json"))}function ra(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Cr(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=$r(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Xe(o)}return n}function $r(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Xe(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Pr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ra(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Cr(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function dt(e,t,n){let r=F(e,t);if(!pe(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!Fr(r,String(o.value??"").split(",")))return;if(o.value="",fe(r))z(r)}function pt(e,t,n){let r=F(e,t);if(!pe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Fr(r,[i]))return;let a=zs(r);if(!a)return;a.value="",z(r),a.focus?.()}function mt(e,t,n){let r=F(e,t);if(!pe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=ut(r);if(!a)return;let s=lt(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Nr(r,a,c)}function ht(e,t,n){let r=F(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Zs(r,i);return}let l=u.cloneNode(!0);Xs(l,Ys(r)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",p=Qs(r,l,f,d);if(f)p?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Pr(r,i)}function gt(e,t,n){let r=F(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Br(r,s):null);if(!c)return Sr(r,i);let u=Cr(r,i),l=na(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Sr(r,i)})}function Ir(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;ft(e)}var Dr=["gte","gt","lte","lt"],oa=["len_eq","len_gte","len_gt","len_lte","len_lt"],qr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],ia=["digits_eq","digits_gte","digits_lt","digits_lte"];function Ze(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function Wr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function jr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Dr)if(n in e)return Wr(n,e[n],t);for(let n of oa)if(n in e)return Ze(n,e[n],[...String(t??"")].length);return null}function bt(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=qr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Ze(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(a)=>{let s=String(t(a)??"");return e.fold===!0?s.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):s};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=ia.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((s)=>Number.isInteger(e[s]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((s)=>Ze(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return jr(e,o)===!0}function K(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>bt(r,t)))}function sa(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 aa(e){return e.flat().every((t)=>qr.some((n)=>(n in Object(t))))}function Br(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=ys(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=K(n.groups?.any,o)===!0;return i?n.message:null}function vt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ca(e,t){let n=vt(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function ua(e,t){let n=vt(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 la(e,t){let n=vt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as fa}from"phlex/reactive/compute";var Y=new WeakMap;function zr(e,t){let n=Y.get(e);if(!n)Y.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function yt(e,t,n,r){let o=zr(e,t),i=ka(o);if(i){o.seed=()=>me(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(a)=>a.target!==o.root&&[...a.target.querySelectorAll(Hr)].some(o.core.bindingOwns)&&o.seed();for(let a of Kr)o.root.addEventListener?.(a,o.nested)}if(o.share=(a)=>a.target?.matches?.(Hr)&&!o.core.owns(a.target)&&o.core.bindingOwns(a.target)&&me(o,a),o.root.addEventListener?.("input",o.share),i||r?.edited)me(o)}function wt(e){let t=Y.get(e);if(!t)return;if(Y.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of Kr)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function At(e){Y.get(e)?.seed?.()}function St(e,t,n){return me(zr(e,t),n)}var Hr="[data-reactive-shared-field]",Kr=["reactive:connect","reactive:persist-restored"],da=Object.freeze({el:null,kind:""}),pa=/^#[A-Za-z_][\w-]*$/;function V({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 Vr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function ma(e,t){if(t==="string")return V(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Vr(V(e));if(n)return e.el.checked?1:0;let r=Number(V(e));return Number.isFinite(r)?r:0}function ha(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Vr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return ga(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function ga(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function ba(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 va(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 ya(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 wa(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 Aa(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 Sa(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=Ea(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function Ea(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Gr(e,t,n){let r=String(n);for(let o of xa(e,t)){if(o.textContent===r)continue;o.textContent=r}}function xa(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Ur(e,t,n){let r=_a(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?V(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!va(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function _a(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 ka(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function me(e,t){if(t&&e.ours.has(t))return;let n=Aa(e),r=n.map(([m])=>m),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(m)=>o&&!m.includes("[")?`${o}[${m}]`:m,a=e.core.bindingOwnership(),s=new Map,c=(m)=>{let h=s.get(m);if(h)return h;let w=null,A=null,q=null;for(let W of e.root.querySelectorAll(`[name="${i(m)}"]`)){if(!a(W))continue;let ue=W.type;if(ue==="checkbox"||ue==="radio"&&W.checked){q={el:W,kind:ue};break}if(ue==="radio")w??=W;else A??=W}if(!q)if(w)q={el:w,kind:"radio"};else q=A?{el:A,kind:""}:da;return s.set(m,q),q};for(let m of r)Gr(e,m,V(c(m)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?fa(u):null;if(!l){Ur(e,{},c);return}let f=wa(e,"data-reactive-compute-outputs-param"),d={};for(let[m,h]of n)d[m]=ma(c(m),h);let p=l(d,{changed:Sa(e,t,r,o)})||{},g=ba(p.$ops),v=[];for(let m of f){if(m==="$ops"||!(m in p))continue;let h=c(m);if(!h.el)continue;let w=ha(e.root,a,h,i(m),p[m]);if(w)v.push(w)}for(let m of Object.keys(p)){if(m==="$ops")continue;let h=p[m];if(h===void 0||h===null)continue;Gr(e,m,h)}Ur(e,p,c);for(let m of v){let h=new Event("input",{bubbles:!0});e.ours.add(h),m.dispatchEvent(h)}ya(e,g,Boolean(t))}var kt;function Tt(e){kt=e}var eo=1,Ta="phlex-reactive:persist:",Ra=new Set(["hidden","file","password","submit","button","reset","image"]),Rt=Symbol("persist-no-value"),Lt="data-reactive-persist-state",La=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Oa=new Set(["lexxy-editor","trix-editor"]),Fa="lexxy-editor, trix-editor, trix-toolbar",Na=["lexxy:change","trix-change"],Ma=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Xr=new WeakSet,Zr=new WeakSet,Qr=new WeakSet;function ge(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(!Xr.has(e))Xr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Ot(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Ft(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Zr.has(e))return;Zr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Nt(e){return Ta+e.key}function xt(e,t){let n=Ot(t);if(!n)return null;let r;try{r=n.getItem(Nt(t))}catch(c){return Ft(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==eo)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return he(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function to(e,t,{fields:n,state:r}){let o=Ot(t);if(!o)return!1;let i={v:eo,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Nt(t),JSON.stringify(i)),!0}catch(a){return Ft(e,a),!1}}function he(e,t){e?.removeAttribute?.(Lt);let n=Ot(t);if(!n)return;try{n.removeItem(Nt(t))}catch(r){Ft(e,r)}}function Mt(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)||Ra.has(i.type)||i.closest(Fa))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(La)){if(!o(i))continue;let a=Ca(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Oa.has(i.localName)?"editor":"contenteditable"})}return r}function no(e){return e.hasAttribute("data-reactive-editable")?kt.text(e):e.textContent??""}function Ca(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Ct(e){return typeof e.value==="string"}function $a(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Ma.has(e.value.trim())}function Pa(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Qr.has(e))return;Qr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function X(e){return e.tagName==="SELECT"&&e.multiple}function ro(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 oo(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Rt;return e[0]}function io(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of Mt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Ct(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=no(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(X(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Ia(e,t,n){let r=t.restore==="always",o=Mt(e,t),i=ro(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&X(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||X(s))){if(l=oo(l,c,i),l===Rt)continue}if((s.type==="checkbox"||X(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")so(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&no(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(X(s)){if(!r&&[...s.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of s.options)d.selected=f.has(d.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}Da(e,t,n)}function so(e,t,n,r,o){if(Array.isArray(r))return;if(!Ct(t))return;if(!o&&!$a(t))return;try{t.value=String(r)}catch(i){Pa(e,n,i)}}function Da(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Ct(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Mt(e,t),c=ro(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let d=oo(n[l],l,c);if(d===null||d===void 0||d===Rt)continue;so(e,u,l,d,i)}})}function qa(e,t,n=!0){let r=ge(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=xt(e,r),i={...o?.state??{},...t},a=n?io(e,r):o?.fields??{};if(to(e,r,{fields:a,state:i}))e.setAttribute?.(Lt,JSON.stringify(i))}function Wa(e){let t=ge(e);if(t)he(e,t)}var _t=new WeakMap,Et=new WeakMap;function ja(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=Et.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],Et.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),Et.delete(e)}}function $t(e,t,n,r){let o=e.element,i=ge(o);if(!i)return;if(r?.submitted)he(o,i);let a=xt(o,i);if(a){if(Ia(o,i,a.fields),a.state)o.setAttribute?.(Lt,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=xt(o,i);to(o,i,{fields:io(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},f=(g)=>{if(!g?.detail?.success)return;let v=g.target;if(v?.tagName!=="FORM"||typeof v.contains!=="function")return;if(!v.contains(o))return;c(),he(o,i)},d=["input",...Na];for(let g of d)o.addEventListener?.(g,l);o.addEventListener?.("change",u);let p=ja(globalThis.document,f);if(_t.set(e,()=>{if(s!==null)u();for(let g of d)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function Pt(e){let t=_t.get(e);_t.delete(e),t?.()}function ao(e,t){let n=kt?.waiting.get(e)?.persist;if(!n||!ge(e))return t(!0);(n.ops??=[]).push(t)}function It(e,t){ao(e,(n)=>qa(e,t,n))}function Dt(e){ao(e,()=>Wa(e))}var be=new WeakMap,uo=new WeakSet,qt=new WeakMap;function Wt(e,t){let n=e.element,r=[],o=[],i=(u,l,f)=>{u.addEventListener?.(l,f),r.push(()=>u.removeEventListener?.(l,f))},a,s,c=()=>{if(!a&&(a=Ba(n,t))){let u=()=>ve(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Ga(n,r)}if(!s&&(s=Ua(n,t))){let u=()=>za(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};be.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function jt(e){for(let t of be.get(e)?.[0]??[])t();be.delete(e)}function Bt(e){be.get(e)?.[1]()}function Ba(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 ve(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,Ja(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 Ja(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 Ha(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Ga(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=qt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(Ha(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(uo.has(c)||!i())return;if(uo.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),qt.delete(n)}},qt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ua(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 za(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 Ut(e){Ka(e),Ya(e)}function Ka(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Jt);else setTimeout(Jt,0);return}let r=async(o)=>{await n(o),Jt()};r.__reactiveDismissWrapped=!0,t.render=r}function Jt(){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 Va=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Ht=Object.freeze(["fade","slide","scale","highlight","shake"]),Gt="data-reactive-fx-pending",zt=1000;function Ya(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Va[r?.getAttribute?.("action")];if(!o||Qa())return;let i=Xa(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await nc(ye(r),i),await n(s)}:async(s)=>{let c=o==="enter"?ec(r):null;if(await n(s),o==="enter")tc(c,i);else po(ye(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Xa(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return fo(n,t);let o=(t==="enter"?Za(e):ye(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?fo(o,t):null}function ye(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Za(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function fo(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"?Ht[Math.floor(Math.random()*Ht.length)]:e;if(!Ht.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Qa(){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?.(Gt,"");return ye(e)}function tc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Gt}]`)))n.removeAttribute(Gt),po(n,t)}async function nc(e,t){if(!e?.classList)return;if(t.legs){await mo(e,t.legs);return}e.classList.add(t.className);let n=Kt(e);if(n<=0){e.classList.remove(t.className);return}await Vt(e,n),e.classList.remove(t.className)}function po(e,t){if(!e?.classList)return;if(t.legs){mo(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Kt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Vt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function mo(e,t){let[n,r,o]=t.map(rc),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await oc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Kt(e);if(a>0)await Vt(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function rc(e){return String(e??"").split(/\s+/).filter(Boolean)}function Kt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,zt)}catch{return 0}}function Vt(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,zt))})}function oc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},zt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var ic="phlex-reactive:latency",Yt=!1;function bo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function vo(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Yt=!1}function Zt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:bo,disableLatencySim:vo}}function Qt(){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(!Yt)Yt=!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 go=new WeakMap;function en(e){let t=globalThis.document;if(!t)return!0;let n=go.get(t);if(!n)n=new Set,go.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Xt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function yo(e,t,n,r){if(en(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function tn(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Xt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}yo(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function nn(e){if(!en(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function rn(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Xt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Xt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}yo(t,o,`scoped to #${r?.id||"?"}`,i)}function on(e,t){let n=e.element?.id||"?";if(en(`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 sc(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function sn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function we(e,t,n){e.streams=sc(t),e.tokenRefreshed=n!=null}var Ae=new WeakMap;function an(e,t,n,r){let o=n&&typeof n==="object"?uc(n):n;return o?Ao(t,o,r,!1):[]}function cn(e,t,n,r){if(!n)return null;let o=Ao(t,n,r,!0);return o.length?o:null}function Ao(e,t,n,r){let o=[];for(let i of So(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(ac(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function So(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 ac(e,t){let n=Ae.get(t);if(n)n.count++;else Ae.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()=>cc(t,e)}function cc(e,t){let n=Ae.get(e);if(!n)return;if(--n.count>0)return;if(Ae.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function uc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function un(e,t,n,r){if(!n?.hide)return null;let o=So(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var xe;function dn(e){xe=e}var T=new Map;function ko(e,t){let n=!T.has(e);if(T.set(e,t),n)xe.enter()}function _e(e){if(T.delete(e))xe.exit()}var xo=!1;function pn(e){To();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){hc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;Q(t,n)}function To(){if(xo||typeof document>"u"||!document.addEventListener)return;xo=!0,document.addEventListener("turbo:before-stream-render",bc,!0),document.addEventListener("turbo:before-stream-render",lc)}function lc(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(T.get(n)?.via==="stream")_e(n)}function Q(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}hn(e),Fo(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return ko(e,r),gc(e,r,t)}function fc(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[yc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":wc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Ro(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Lo(t))return{src:t};return console.error(dc(t)),pc(t)||mc(e)}function dc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${mn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function pc(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${mn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Lo(r))return{src:r,fallback:!0}}function mc(e){hn(e.id),gn(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 Lo(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${mn()}/`)}catch{return!1}}function mn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function hc(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){Q(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}hn(e),Fo(n);let o=document.createElement("pgbus-stream-source");o.id=Oo(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),ko(e,{via:"stream"})}function Oo(e){return`reactive-defer-src-${e}`}async function gc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Ac()),o;try{xe.count("defer"),o=await fetch(...fc(n,t.abort.signal))}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),Z(e,n);return}if(T.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),Z(e,n,o.status);return}if(o.status===204){clearTimeout(r),_o(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),Z(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}"`),Z(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),Z(e,n);return}if(clearTimeout(r),T.get(e)!==t)return;_o(e),vc(a)}var fn=null,bc=(e)=>fn?.push(e);function vc(e){let t=fn=[];try{window.Turbo.renderStreamMessage(e)}finally{fn=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 hn(e){let t=T.get(e);if(!t)return;if(_e(e),t.via==="fetch")t.abort.abort();else document.getElementById(Oo(e))?.remove?.()}function Fo(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function gn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function _o(e){_e(e);let t=document.getElementById(e);if(!t)return;gn(t),t.removeAttribute("data-reactive-error")}function Z(e,t,n){_e(e);let r=document.getElementById(e);if(!r)return;gn(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"),Q(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function yc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function wc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Ac(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var No="__materialize",Ee=new WeakMap;function Se(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function bn(e,t,n){To();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>ke(e),f=(h)=>{if(Se(r)==="visible"){if(!a)p()}else if(h){let w=r.getAttribute("data-reactive-lazy-on");if(s===w)return;d(),r.addEventListener?.(w,l),s=w}},d=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},p=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let h=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:h}),a.observe(r)},g=()=>{let h=Se(r)!==null,w=o;if(o=h,!h)return d();if(i)return;if(t.forgetToken(),!w)return l();f(!0)};if(Ee.set(e,{load(){if(i)return;let h=Ro(r);if(!h&&r.getAttribute("data-reactive-defer-src")!=null)return;if(h&&Sc(r,t))return;let w=h?Q(r.id,h):t.proceed(r,No,"{}");if(!w)return;i=!0,d();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);d()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&Se(r)===null)ln(r),c=(h)=>h.target===r&&ln(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)ln(r);g()},r.addEventListener?.("turbo:morph-element",u),n)return g();if(o=Se(r)!==null,o)f(!1)}function vn(e){let t=Ee.get(e);Ee.delete(e),t?.off()}function ke(e){return Ee.get(e)?.load()}function Sc(e,t){return t.emit("reactive:before-dispatch",{action:No,params:{},element:e},{cancelable:!0}).defaultPrevented}function ln(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Ro(e);if(t)Q(e.id,t)}var yn=new WeakMap,Re=new WeakMap,b=null,C,Co;function En(e,t){let n=e.element;Re.set(n,t),Jo();let r=(i)=>xc(i,t),o=(i)=>Lc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),yn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function xn(e){if(yn.get(e)?.(),yn.delete(e),Re.delete(e.element),b&&Le(b.origin)===e.element)Te()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),ee=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},Le=(e)=>e?.closest?.('[data-controller~="reactive"]'),Do=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),N=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==b?.row&&Do(t)===e),$o=(e)=>ee(S(e,"-item"),null),wn=(e)=>S(e,"-disabled")==="true",Ec=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},qo=(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&&!wn(n)&&Re.has(Le(n)))};function Wo(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Do(n);if(b||!r||!t.owns(r)||wn(r)||wn(n))return;if(Le(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function xc(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Wo(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(h)=>h.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(h)=>{if(!a(h))return;if(b)return An(h.clientX,h.clientY);if(Math.abs(h.clientX-o)<=4&&Math.abs(h.clientY-i)<=4)return;if(!c)return m();kc(n,t,h),An(h.clientX,h.clientY)},f=(h)=>b&&h.cancelable&&h.preventDefault(),d=(h)=>{if(!a(h))return;if(m(),b)_c(),Sn()},p=(h)=>{if(h.type==="pointercancel"&&!a(h))return;if(m(),b)Te()},v=[["pointermove",l],["pointerup",d],["pointercancel",p],["keydown",(h)=>h.key==="Escape"&&b&&(h.preventDefault(),p(h))],["touchmove",f,{passive:!1}]];for(let[h,w,A]of v)document.addEventListener(h,w,A);function m(){clearTimeout(u);for(let[h,w]of v)document.removeEventListener(h,w)}}function _c(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function kc({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,b=jo({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),b.dx=r.clientX-o.left,b.dy=r.clientY-o.top,b.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function jo(e){let{row:t,origin:n,source:r}=e;return e.index=N(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),te(n,!0),e}var te=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Oe(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 An(e,t){b.x=e,b.y=t,b.row.style.left=`${e-b.dx}px`,b.row.style.top=`${t-b.dy}px`;let n=qo(b.origin).find((r)=>Ec(r,e,t));if(n)Tc(n,e,t);else if(b.source)_n(null),b.placeholder.remove();Rc(e,t)}function _n(e){if(b.target!==b.origin)te(b.target,!1);b.target=e,te(e,!0)}function Tc(e,t,n){_n(e);let r=N(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});Oe(e,r,s<0?r.length:s,b.placeholder)}function Rc(e,t){let n=b.target??b.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(b.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,b.wy=t<40?-12:t>window.innerHeight-40?12:0,(b.vy||b.wy)&&!b.raf){let i=()=>{if(!b||!(b.vy||b.wy))return b&&(b.raf=0);if((b.target??b.origin).scrollTop+=b.vy,b.wy)window.scrollBy(0,b.wy);An(b.x,b.y),b.raf=requestAnimationFrame(i)};b.raf=requestAnimationFrame(i)}}function Lc(e,t){let n=e.key;if(b?.keyboard){if(e.target!==b.row||b.core!==t)return;let o={" ":Sn,Enter:Sn,Escape:Te,Tab:Te,ArrowUp:()=>Po(-1),ArrowDown:()=>Po(1),ArrowLeft:()=>Io(-1),ArrowRight:()=>Io(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Wo(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),b=jo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Ne("picked")}function Po(e){let t=N(b.target),n=Fe()+e;if(n>=0&&n<=t.length)Oe(b.target,t,n,b.row);Bo()}function Io(e){let t=qo(b.origin),n=t[t.indexOf(b.target)+e];if(n){let r=Fe();_n(n),Oe(n,N(n),r,b.row)}Bo()}function Bo(){b.row.focus?.(),Ne("moved")}function Fe(){let e=N(b.target),t=b.keyboard?b.row:b.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Jo(){if(!C?.isConnected)C=document.createElement("div"),C.setAttribute("aria-live","polite"),C.setAttribute("data-reactive-sortable-live",""),C.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(C);return C}function Ne(e){let t=b.target??b.origin,n=(ee(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Fe()+1).replaceAll("{count}",N(t).length+1),r=Jo();r.textContent="",cancelAnimationFrame(Co),Co=requestAnimationFrame(()=>r.textContent=n)}function Sn(){let e=b,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?Fe():-1,c=a?$o(N(t)[s-1]):null;if(e.keyboard)Ne("dropped");if(!r&&i)i.replaceWith(o);if(Go(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=ee(S(t,"-from"),{})[u]??S(t),f={...ee(S(t,"-params"),{}),item:$o(e.item),position:s,after:c,from:u},d=[];for(let g=t;g;g=g.parentElement)d.push(g);let p=Re.get(Le(t))?.proceed(t,l,JSON.stringify(f),ee(S(t,"-busy")));if(r)return;Promise.resolve(p).then((g)=>Oc(g,d)||Ho(e))}function Oc(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"))&&Fc(r,t))}function Fc(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 Te(){let e=b;if(e.keyboard)Ne("cancelled");e.placeholder?.remove(),Go(e),Ho(e)}function Ho({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Oe(t,N(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Go(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(b=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),te(n,!1),te(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Yo={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Xo={x:"left",y:"top",width:"width",height:"height"},kn=new WeakMap,Ln=new WeakMap,y=null,P,zo,Ko=!1;function On(e,t){let n=e.element;Ln.set(n,t),ai(),Bc();let r=[["pointerdown",(o)=>Ic(o,t,n)],["keydown",(o)=>jc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Yo[o.key]&&Rn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&Rn()],["input",(o)=>Vo(o,t,n)],["change",(o)=>Vo(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);kn.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Fn(e){if(kn.get(e)?.(),kn.delete(e),Ln.delete(e.element),y?.root===e.element)J(y)}var _=(e,t,n)=>Math.min(Math.max(e,t),n),R=(e)=>Math.round(e*1e4)/1e4;function Nc(e,t=1){let n=R(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Nn(e){let t={x:R(e.x),y:R(e.y)};if(e.width!=null)t.width=R(e.width),t.height=R(e.height),t.x=Math.min(t.x,R(1-t.width)),t.y=Math.min(t.y,R(1-t.height));return t}function Zo(e,t,n){return{x:_(e.x+t,0,1-e.width),y:_(e.y+n,0,1-e.height),width:e.width,height:e.height}}function Qo(e,t,n){return{x:_(e.x+t,0,1),y:_(e.y+n,0,1)}}function ei(e,t,n,r,o,i){let[a,s,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,f=e.y+e.height,d=e.x+e.width/2,p=e.y+e.height/2,g=s?1-e.x:u?l:i?2*Math.min(d,1-d):1,v=c?1-e.y:a?f:i?2*Math.min(p,1-p):1,m=e.width+(s?n:u?-n:0),h=e.height+(c?r:a?-r:0);if(i){let w=(s||u)&&(!(a||c)||Math.abs(m-e.width)>=Math.abs(h-e.height)*i),A=Math.min(g,v*i);m=_(w?m:h*i,Math.min(Math.max(o,o*i),A),A),h=m/i}else{if(s||u)m=_(m,Math.min(o,g),g);if(a||c)h=_(h,Math.min(o,v),v)}return{x:u?l-m:s?e.x:d-m/2,y:a?f-h:c?e.y:p-h/2,width:m,height:h}}function Mc(e,t,n){let r=Math.min(1,t),o=_(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:_(e.x+e.width/2-o/2,0,1-o),y:_(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function Cc(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 x=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Mn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},L=(e)=>e.matches("[data-reactive-point]")?"point":"box",ti=(e)=>Number(x(e,`${L(e)}-scale`))||1,B=(e)=>L(e)==="point"?["x","y"]:["x","y","width","height"];function ni(e){let t={};for(let n of B(e))t[n]=(parseFloat(e.style[Xo[n]])||0)/100;return t}function Me(e,t){for(let n of B(e))e.style[Xo[n]]=`${Math.round(t[n]*1e4)/100}%`}function Cn(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 $c(e,t){try{return e.parentElement.closest(x(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function ri(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function oi(e,t,n){let r=Mn(x(e,L(e)),{}),o={};for(let i of B(e)){let[a]=ri(t,n,r[i]);if(a)o[i]=a}return o}function Pc(e,t,n,r){let o=x(e,"box-aspect"),i=o&&ri(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),a=o?Cc(i?.value):Number(x(e,"box-ratio"))||0,{width:s,height:c}=Cn(t);return a&&s&&c?a*c/s:0}function $n(e,t,n,r){let o=n.matches("[data-reactive-box-handle]")?n.closest("[data-reactive-box]"):n,i=o?.closest("[data-reactive-frame]");if(!i)return null;let a=ni(o),s=oi(o,t,e),c=L(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?$c(o,i):i,edge:x(n,"box-handle"),start:a,value:a,ratio:c?0:Pc(o,i,t,e),min:Number(x(o,"box-min"))||0,scale:ti(o),fields:s,before:Object.fromEntries(Object.entries(s).map(([u,l])=>[u,l.value]))}}function ii(e,t,n,r){let o=Nc(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function ne(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))ii(e.core,n,e.value[t],e.scale)}function Ic(e,t,n){if(si(),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)&&$n(t,n,r,!1);if(!o)return;let{clientX:i,clientY:a}=e,s=Cn(o.bounds);o.p0=[(i-s.left)/s.width,(a-s.top)/s.height];let c=(v)=>v.pointerId===e.pointerId,u=(v)=>{if(!c(v)||o.over)return;if(y)return Tn(v.clientX,v.clientY);if(Math.abs(v.clientX-i)<=4&&Math.abs(v.clientY-a)<=4)return;qc(o),Tn(v.clientX,v.clientY)},l=(v)=>{if(!c(v))return;if(g(),y)Dc(),Rn()},f=(v)=>{if(v.type==="pointercancel"&&!c(v))return;if(g(),y)li()},p=[["pointermove",u],["pointerup",l],["pointercancel",f],["keydown",(v)=>v.key==="Escape"&&y&&(v.preventDefault(),f(v))]];for(let[v,m]of p)document.addEventListener(v,m);function g(){for(let[v,m]of p)document.removeEventListener(v,m)}}function Dc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function qc(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 Tn(e,t){let n=y;if(!n.el.isConnected)return J(n);n.x=e,n.y=t;let r=Cn(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:a,edge:s}=n;n.value=Nn(L(n.el)==="point"?Qo(a,o,i):s?ei(a,s,o,i,n.min,n.ratio):Zo(a,o,i)),Me(n.el,n.value),n.writing||=requestAnimationFrame(()=>ne(n)),Wc(t)}function Wc(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),Tn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function si(){if(y&&!y.el.isConnected)J(y)}function jc(e,t,n){si();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(),li());let o=Yo[e.key];if(!o)return;if(e.preventDefault(),y??=$n(t,n,r,!0),!y)return;let[i,a]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),s=e.altKey&&L(y.el)==="box",c=y.value;y.value=Nn(L(y.el)==="point"?Qo(c,i,a):s?ei(c,y.edge??"se",i,a,y.min,y.ratio):Zo(c,i,a)),Me(y.el,y.value),ne(y),ci(y,s?"resized":"moved")}function ai(){if(!P?.isConnected)P=document.createElement("div"),P.setAttribute("aria-live","polite"),P.setAttribute("data-reactive-drag-live",""),P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(P);return P}function ci(e,t){let n=Mn(x(e.el,`${L(e.el)}-messages`),{})[t]??"";for(let o of B(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=ai();r.textContent="",cancelAnimationFrame(zo),zo=requestAnimationFrame(()=>r.textContent=n)}function Vo(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(x(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=$n(t,n,o,!0),{ratio:a,start:s}=i??{};if(!a||Math.abs(s.width/s.height/a-1)<0.005)continue;i.value=Nn(Mc(s,a,i.min)),Me(o,i.value),ne(i),ui(i)}}function Rn(){let e=y;if(!e.el.isConnected)return J(e);ne(e),J(e),ui(e)}function ui(e){for(let[o,i]of Object.entries(e.fields))if(i.value!==e.before[o])i.dispatchEvent(new Event("change",{bubbles:!0}));let t=L(e.el),n=x(e.el,`${t}-action`),r={};for(let o of B(e.el))r[o]=R(e.value[o]);if(!n||B(e.el).every((o)=>r[o]===R(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Mn(x(e.el,`${t}-busy`)))}function li(){let e=y;if(e.value=e.start,Me(e.el,e.start),ne(e),e.keyboard)ci(e,"cancelled");J(e)}function J(e){if(y=null,e.over=!0,cancelAnimationFrame(e.raf),cancelAnimationFrame(e.writing),e.grip.removeAttribute("data-reactive-dragging"),e.frame.removeAttribute("data-reactive-frame-active"),!e.keyboard)document.documentElement.style.userSelect=e.select??""}function Bc(){if(Ko)return;Ko=!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=Ln.get(n);if(!r?.owns(t))return;let o=ni(t),i=ti(t);for(let[a,s]of Object.entries(oi(t,n,r)))ii(r,s,o[a],i)})}var I=new Map,di=new WeakSet;function Pn(e,t){let n=e.element,r=I.get(n.id);if(!r)I.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Jc(n);let o=(a)=>a.target===n&&queueMicrotask(()=>mi(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},mi(r)}function In(e){let t=e.element,n=I.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;I.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function Dn(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=I.get(e.id);if(!n)I.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},hi(n)}function Jc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&di.has(n))return;if(n?.remove(),!pi())setTimeout(()=>{if(!pi())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=I.get(e.id);if(!o||o.removing)return;hi(o),Hc(o)}),di.add(r),document.body.appendChild(r)}var pi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Hc(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&gi(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function hi(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function gi(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function mi(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=gi(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}var vi=new Map,qn=new WeakMap,Gc=0,Ce=new WeakMap;function Wn(e,t){let n=e.element;if(!n.id&&!qn.has(n))qn.set(n,`#${++Gc}`);let r=n.id||qn.get(n),o=new Map,i=!1,a=(p)=>{clearTimeout(o.get(p)),o.delete(p)},s=(p,g,v)=>{a(p);let m=Date.parse(g.until)-Date.now();if(!(m>0))return c(p,g,v);let h=Math.ceil(m/1000);yi(p,`${Math.floor(h/60)}:${String(h%60).padStart(2,"0")}`,"running"),u(g.waiting,!0),u(g.done,!1),o.set(p,setTimeout(()=>s(p,g,v),(m-1)%1000+1))},c=(p,g,v)=>{yi(p,"0:00","done"),u(g.waiting,!1),u(g.done,!0);let m=vi.get(v)??new Set;if(m.has(g.until))return;vi.set(v,m.add(g.until)),p.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:g.until}}))},u=(p,g)=>{let v;try{v=p&&n.querySelector(p)}catch{}if(v&&v.hidden===g)v.hidden=!g},l=()=>{if(i=!1,!Ce.has(e))return;let p=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((v,m)=>{if(!t.owns(v))return;let h;try{h=JSON.parse(v.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(h?.until)))return;p.add(v),s(v,h,`${r}|${v.id||m}`)});for(let v of o.keys())if(!p.has(v))a(v)},f=()=>{if(i)return;i=!0,queueMicrotask(l)},d=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",f),n.addEventListener("reactive:streamed",f),document.addEventListener("visibilitychange",d),Ce.set(e,()=>{n.removeEventListener("turbo:morph-element",f),n.removeEventListener("reactive:streamed",f),document.removeEventListener("visibilitychange",d);for(let p of[...o.keys()])a(p)}),l()}function jn(e){Ce.get(e)?.(),Ce.delete(e)}function yi(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 zc(){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 Kc(){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 Vc=["focus","focus_first","blur"];function Yc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=pr(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)nn(n);return}let i=(s)=>tr(s,(c)=>Du(c,o),r?(c,u)=>tn(c,u,o):void 0),a=t.findIndex((s)=>Vc.includes(s?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,a)),requestAnimationFrame(()=>i(t.slice(a)))}}function Xc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){pn(this)}}var Si=!1,Zc=null;function Qc(){if(Si)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Si=!0,document.addEventListener("turbo:before-stream-render",(e)=>{du(e),eu(e),nu(e),Ut(e)})}var qe="reactive:streamed";function eu(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(qe))}}function or(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function ir(e){try{return e.matches(":modal")}catch{return!1}}function Yi(e){if(!or(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||ir(e))return;if(e.open)e.close();e.showModal()}function tu(e){if(or(e)&&e.open)e.close()}function Ge(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!ir(r))Yi(r)}function nu(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),Ge(document)}}var Ei=!1;function ru(){if(Ei)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ei=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Ge(t.target)}),document.addEventListener("turbo:morph",()=>Ge(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!or(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!ir(n))return;e.delete(n),t.preventDefault(),n.close()})}var Zn=new WeakMap;function Xi(e,t,n,r){let o=Zn.get(e)??new Map;Zn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))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 a of r({...n,to:n.expanded}))Xi(a,"set_attr",{name:"aria-expanded"})}}var xi=!1;function ou(){if(xi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;xi=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Zn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var Zi="data-reactive-image-fallback",oe="data-reactive-image-state",Qn="data-reactive-image-hidden",Bn=null,er="data-reactive-wrap-hidden";function Qi(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(er,"")}function es(e){if(!e.hasAttribute(er))return;e.removeAttribute("hidden"),e.removeAttribute(er)}function ie(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Zi);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var ts=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function sr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function ns(e,t){let n=sr(e,t.alt);return n&&!n.contains(e)?n:null}function Ue(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Qn,"");if(t.wrap){let o=sr(e,t.wrap);if(o)Qi(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=ns(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Ve(e,t);e.setAttribute(oe,n)}function Ve(e,t=ie(e)){if(!t||e.getAttribute(oe)==null)return;if(e.getAttribute(oe)==="error"){if(e.hasAttribute(Qn))e.removeAttribute("hidden");let n=sr(e,t.wrap);if(n)es(n);let r=ns(e,t);if(r)r.hidden=!0}e.removeAttribute(oe),e.removeAttribute(Qn)}function _i(e){let t=e.target,n=ie(t);if(!n)return;if(e.type==="load")Ue(t,n,"loaded");else if(ts(t))Ue(t,n,"error");else Ve(t,n)}function iu(){if(Bn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;Bn={error:_i,load:_i,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(oe);if(o==null||!r||!ie(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=ie(n);if(o)Ue(n,o,r)})}};for(let[t,n]of Object.entries(Bn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Zi}]`)??[]){if(!t.complete||!ts(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Ue(t,ie(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 cl(e){Zc=e}var $e,Jn=null,ki="[data-reactive-editable][contenteditable=plaintext-only]";function rs(){if($e===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",$e=e.contentEditable==="plaintext-only"}catch{$e=!1}return $e}function We(e){if(e.matches?.(ki))e.setAttribute("contenteditable","true");e.querySelectorAll?.(ki).forEach(We)}function su(){if(Jn||typeof document>"u"||typeof document.createElement!=="function")return;if(rs())return;We(document),Jn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")We(t.target);else t.addedNodes.forEach(We)}),Jn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Ti=!1;function Ri(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 au(){if(Ti)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ti=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=Ri(t);if(r)uu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(ze.set(t,D(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==k)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>fr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===k)&&Ri(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(k)&&cr(t)===ur(t))t.removeAttribute(k)})}var k="data-reactive-held",ar='[data-controller~="reactive"]',je=null,G=new Map;function cr(e){return e.hasAttribute("data-reactive-editable")?D(e):e.value}function ur(e){return e.hasAttribute("data-reactive-editable")?dr(e):e.defaultValue}function cu(e){if(e.hasAttribute("data-reactive-editable"))return D(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function uu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||G.has(e.closest(ar)))return;let r=cu(t);if(r===cr(e))return e.removeAttribute(k);if(r===ur(e))return;e.setAttribute(k,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function lu(e){let t=[];for(let n of e.querySelectorAll(`[${k}]`)){if(n.closest(ar)!==e)continue;let r=n.getAttribute("name");if(cr(n)===ur(n))n.removeAttribute(k);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function os(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${k}]`))if(n.closest(ar)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(k)}function fu(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 Li(e,t,n=null){let r={root:e,streams:0,keep:n},o=je;je=r;try{window.Turbo.renderStreamMessage(t)}finally{je=o}if(r.streams===0)os(e,n)}function du(e){let t=je,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{G.set(t.root,(G.get(t.root)||0)+1);try{return await r(o)}finally{let i=G.get(t.root)-1;if(i)G.set(t.root,i);else G.delete(t.root);os(t.root,t.keep)}}}var Oi="__materialize",Fi=!1;function pu(){if(Fi)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Fi=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}function lr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Zt()}var is="data-reactive-active",O=0;function ss(){if(O++,O===1)cs("reactive:busy")}function as(){if(O===0)return;if(O--,O===0)cs("reactive:idle")}function ul(){return O}function ll(){O=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(is)}function cs(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(is,O>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:O}}))}var us="data-reactive-requests";function ls(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!mu(t))return;let n=hu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(us,JSON.stringify(n))}function mu(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function hu(e){try{let t=JSON.parse(e.getAttribute(us));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Ni(){zc(),Kc(),Yc(),Xc(),Qc(),au(),ru(),ou(),iu(),su(),pu(),lr()}function gu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var fs=Symbol.for("phlex-reactive.core");if(globalThis[fs])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[fs]=!0;var ds=!1;function bu(){if(ds)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(bu,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var vu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function ps(e){let t=String(e).toLowerCase();return t.startsWith("on")||vu.has(t)}var Hn=new WeakMap;function yu(e,t,n){let[r,o,i]=t;Hn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,Hn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Hn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,wu(e))}function wu(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Au=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Su=new Set(["lexxy-editor","trix-editor"]);function D(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as zc}from"@hotwired/stimulus";import{confirmResolver as Ai}from"phlex/reactive/confirm";import{confirmPredicate as ys}from"phlex/reactive/confirm_predicate";var j=new WeakMap,Qe=new WeakMap;function N(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Qe.set(n.root,n)}return n}function E(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function U(e,t){E(e,"turbo:morph-element",t),e.seeds.push(t),t()}function et(e,t){let n=N(e,t);n.offs=[],n.seeds=[];let r,o,i,a,s;(n.wire=()=>{if(!n.show&&_s(n))n.show=(c)=>{if(n.flipping)return;if(c?.type==="input"||c?.type==="change")Ws(n,c.target);else n.groups=Is(n),Ar(n);br(n)},E(n,"input change",n.show),E(n,"focusout",(c)=>{let u=c.target?.getAttribute?.("name");if(!u||n.touched?.has(u)||!n.core.bindingOwns(c.target))return;if((n.touched??=new Set).add(u),n.root.querySelector?.("[data-reactive-show-after]"))br(n)}),U(n,n.show);if(!n.arm&&ks(n))E(n,"input change",(c)=>gr(n,c)),U(n,n.arm=()=>{gr(n,null),Ar(n)});if(!r&&(r=n.show||n.arm))E(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=n.show||n.arm))E(n,"reactive:connect reactive:persist-restored",(c)=>{if(c.target===n.root||!ws(n,c.target))return;n.show?.(),n.arm?.()});if(!i&&(i=fe(n)))E(n,"input",(c)=>Js(n,c)&&z(n)),U(n,()=>z(n));if(!a&&(a=pe(n)))U(n,()=>Mr(n));if(!s&&(s=Us(n)))E(n,"input change",(c)=>Dr(n,c)),U(n,()=>ft(n))})(),E(n,"keydown",(c)=>ca(n,c)),E(n,"paste drop",(c)=>ua(n,c)),E(n,"input",(c)=>la(n,c))}function ws(e,t){return[...t.querySelectorAll?.("[data-reactive-shared-field]")??[]].some(e.core.bindingOwns)}function tt(e){let t=j.get(e);if(!t)return;j.delete(e),Qe.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function nt(e){let t=j.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function rt(e,t,n){return Dr(N(e,t),n)}function ot(e,t,n){return Br(N(e,t),n)}var As=/^#[A-Za-z_][\w-]*$/,Er="[data-reactive-show-field], [data-reactive-show]";function Ss(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 Ir){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Wr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function xr(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function Es(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function _r(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return K(n,t);return xs(e,t)}function xs(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)=>bt(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function le(e,t="show"){if(typeof e==="string"&&As.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function _s(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(Er)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(de)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${Rr}, ${Or}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function ks(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Ts(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Es(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function gr(e,t){let n=Ts(e);if(!n.length)return;let r=Tr(e,e.core.bindingOwnership());n.forEach((o,i)=>{let a=K(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function br(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.core.bindingOwnership(),r=e.root.getAttribute?.("data-reactive-scope")||null,o=Tr(e,n),i=[];for(let a of e.root.querySelectorAll(Er)){if(!t(a))continue;let s=a.getAttribute("data-reactive-show");if(s!==null){let f=_r(xr(s),o);if(f===null)continue;let d=a.getAttribute("data-reactive-show-after"),p=f&&(d==null||!!e.touched?.has(st(d,r)));vr(a,p,n);let g=(e.shown??=new WeakMap).get(a);if(e.shown.set(a,p),Rs.some((h)=>a.hasAttribute(`data-reactive-show-${h}`))&&g!==void 0&&g!==p)i.push(a);continue}let c=a.getAttribute("data-reactive-show-field");if(!c)continue;let u=o(c);if(u===null)continue;let l=Ss(a,u);if(l===null)continue;vr(a,l,n)}if(e.groups)js(e,o,t,r);Ms(e,o,t),Ps(e,o,t,r,n),Ls(e,o),Bs(e,o);for(let a of i)Os(e,a,n,r)}var Rs=["clear","focus","scroll"];function Os(e,t,n,r){if(t.hidden){let s=[];try{s=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(s)?s:[]).map((u)=>st(String(u),r)));for(let u of c.size?e.root.querySelectorAll("[name]"):[]){if(!c.has(u.getAttribute("name"))||!n(u)||u.type==="file")continue;if(u.type==="checkbox"||u.type==="radio"){if(u.checked)u.checked=!1,M(u)}else e.core.setValue(u,"")}return}let o=t.getAttribute("data-reactive-show-scroll")==="true";if(o)t.scrollIntoView?.({block:"nearest"});let i=t.getAttribute("data-reactive-show-focus"),a=null;try{a=i?e.root.querySelector(i):null}catch{}a?.focus?.(o?{preventScroll:!0}:void 0)}function vr(e,t,n){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 Ls(e,t){let n=kr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Ns(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!le(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>bt(l,a))}else{let l=jr(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function Ns(e,t,n){if(!le(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=sa(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!aa(r))return;let i=K(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function kr(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function Fs(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(it(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function it(e,t){return`[name="${st(e,t)}"]`}function st(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Tr(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?at(e,o,t,n).filter((s)=>s.checked).length:Fs(e,o,t,n));return r.get(a)}}var Rr="[data-reactive-media]";function Ms(e,t,n){for(let r of e.root.querySelectorAll(Rr)){if(!n(r))continue;let o,i,a;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)a=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!a){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let s=t(o.field);if(s===null)continue;let c=o.take>0?[...s]:null,u=c?c.slice(0,o.take).join(""):s,l=c?.length<o.take||i?.test(u)===!1||a?.test(s)===!1;if(l&&o.pending==="keep"){yr(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?wr(e,o.pool[u])[0]:null,d=e.core.copyMedia(r,f??null);if(d===null)continue;if(yr(r,l?"pending":d===!1?"miss":"hit"),typeof o.label!=="string")continue;let p=l?"":d===!1?String(o.blank??""):d;for(let g of wr(e,o.label))if(g.textContent!==p)g.textContent=p}}function yr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function wr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Or="[data-reactive-css-vars]",Cs=/^--[a-z0-9-]+$/i,$s=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ps(e,t,n,r,o){let i=[...e.root.querySelectorAll(Or)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))i.unshift(e.root);for(let a of i){let s;try{s=JSON.parse(a.getAttribute("data-reactive-css-vars"))}catch{}if(!Array.isArray(s?.to)||!s.vars||typeof s.vars!=="object"){console.warn("[phlex-reactive] malformed data-reactive-css-vars — skipped (two reactive_css_vars on one element?)");continue}let c=s.to.flatMap((u)=>{let l={to:u,global:s.global===!0},f=[];try{f=e.core.opTargets(l)}catch{}if(!f.length)e.core.diagnose("reactive_css_vars",l);return f});for(let[u,l]of Object.entries(s.vars)){let f=l?.unit??"";if(!Cs.test(u)||!$s.includes(f)||typeof l?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(u)} — skipped`);continue}let d=Ds(e,t,l.field,o,r);if(d===void 0)continue;let p=d===null?"":`${d}${f}`;for(let g of c){if(g.style.getPropertyValue(u)===p)continue;if(p)g.style.setProperty(u,p);else g.style.removeProperty(u)}}}}function Ds(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(it(n,o))].some((s)=>r(s)&&s.type==="checkbox"))return i==="true"?1:0;let a=i.trim()?Number(i):NaN;return Number.isFinite(a)?a:null}var de="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Is(e){return!!e.root.querySelector?.(de)}function at(e,t,n,r,o){return[...e.root.querySelectorAll(it(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||qs(i.getAttribute("data-reactive-group"),o)))}function qs(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Ws(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Lr(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function ct(e,t,n){if(!t)return;let r=Qe.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Lr(r,t,n!==!1),r.show?.()}function Lr(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=at(e,t,e.core.ownership(),i,o).filter((s)=>s!==r&&s.checked!==n);for(let s of a)s.checked=n;e.flipping=!0;try{for(let s of a)for(let c of["input","change"])s.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function js(e,t,n,r){for(let o of e.root.querySelectorAll(de)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=_r(xr(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=o.getAttribute("data-reactive-select-all-under"),u=at(e,s,n,r,c).filter((f)=>f!==o),l=u.filter((f)=>f.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function Bs(e,t){for(let[n,r]of Object.entries(kr(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!le(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!le(a,"group"))continue;let c=K(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function Ar(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${de}, [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 fe(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Js(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}var Hs=/[\s\-'(),./]/;function Gs(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||Hs.test(t[r-1]))return!0;return!1}function z(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=e.root.getAttribute("data-reactive-filter-match"),a=e.root.hasAttribute?.("data-reactive-filter-fold"),s=(d)=>{let p=(d??"").toLowerCase().trim();return a?p.normalize("NFD").replace(/\p{M}/gu,""):p},c=s(o.value),u=0;for(let d of e.root.querySelectorAll(n)){if(!r(d))continue;let p=d.hasAttribute?.("data-reactive-tags-selected")||c!==""&&!Gs(i,s(d.getAttribute("data-reactive-filter-text")??d.textContent),c);if(d.hidden=p,p)d.removeAttribute("data-reactive-highlighted");else u++}let l=e.root.getAttribute("data-reactive-filter-group");if(l)for(let d of e.root.querySelectorAll(l)){if(!r(d))continue;let p=[...d.querySelectorAll(n)].filter(r);if(p.length===0)continue;d.hidden=p.every((g)=>g.hidden)}let f=e.root.getAttribute("data-reactive-filter-empty");if(f){for(let d of e.root.querySelectorAll(f))if(r(d))d.hidden=u>0}}function pe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Us(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function ut(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 lt(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function Nr(e,t){let n=ut(e);if(!n)return!1;let r=lt(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)Fr(e,n,r);return i}function Fr(e,t,n){t.value=n.join(","),M(t),Mr(e)}function zs(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Mr(e){let t=ut(e);if(!t)return;let n=lt(t),r=e.core.ownership();Ks(e,n,r),Vs(e,n,r)}function Ks(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Vs(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"),!fe(e))o.hidden=!1}}if(fe(e))z(e)}function Ys(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Xs(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 Zs(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 Qs(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let f=a.find((d)=>$r(d.getAttribute?.("name"))===c);if(!f)continue;ea(f,l),s.push(l)}if(r)for(let c of s)ta(c);return s[0]??null}function ea(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Xe(t)!=="";else e.value=Xe(t);M(e)}function ta(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function na(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Sr(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);ft(e)}function ft(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Pr(e,n.getAttribute("data-reactive-nested-json"))}function ra(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Cr(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=$r(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Xe(o)}return n}function $r(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Xe(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Pr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ra(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Cr(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function dt(e,t,n){let r=N(e,t);if(!pe(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!Nr(r,String(o.value??"").split(",")))return;if(o.value="",fe(r))z(r)}function pt(e,t,n){let r=N(e,t);if(!pe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Nr(r,[i]))return;let a=zs(r);if(!a)return;a.value="",z(r),a.focus?.()}function ht(e,t,n){let r=N(e,t);if(!pe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=ut(r);if(!a)return;let s=lt(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Fr(r,a,c)}function mt(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Zs(r,i);return}let l=u.cloneNode(!0);Xs(l,Ys(r)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",p=Qs(r,l,f,d);if(f)p?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Pr(r,i)}function gt(e,t,n){let r=N(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Br(r,s):null);if(!c)return Sr(r,i);let u=Cr(r,i),l=na(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Sr(r,i)})}function Dr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;ft(e)}var Ir=["gte","gt","lte","lt"],oa=["len_eq","len_gte","len_gt","len_lte","len_lt"],qr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],ia=["digits_eq","digits_gte","digits_lt","digits_lte"];function Ze(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function Wr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function jr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Ir)if(n in e)return Wr(n,e[n],t);for(let n of oa)if(n in e)return Ze(n,e[n],[...String(t??"")].length);return null}function bt(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=qr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Ze(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(a)=>{let s=String(t(a)??"");return e.fold===!0?s.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):s};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=ia.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((s)=>Number.isInteger(e[s]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((s)=>Ze(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return jr(e,o)===!0}function K(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>bt(r,t)))}function sa(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 aa(e){return e.flat().every((t)=>qr.some((n)=>(n in Object(t))))}function Br(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=ys(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=K(n.groups?.any,o)===!0;return i?n.message:null}function vt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ca(e,t){let n=vt(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function ua(e,t){let n=vt(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 la(e,t){let n=vt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as fa}from"phlex/reactive/compute";var Y=new WeakMap;function zr(e,t){let n=Y.get(e);if(!n)Y.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function yt(e,t,n,r){let o=zr(e,t),i=ka(o);if(i){o.seed=()=>he(o),o.root.addEventListener?.("turbo:morph-element",o.seed),o.nested=(a)=>a.target!==o.root&&[...a.target.querySelectorAll(Hr)].some(o.core.bindingOwns)&&o.seed();for(let a of Kr)o.root.addEventListener?.(a,o.nested)}if(o.share=(a)=>a.target?.matches?.(Hr)&&!o.core.owns(a.target)&&o.core.bindingOwns(a.target)&&he(o,a),o.root.addEventListener?.("input",o.share),i||r?.edited)he(o)}function wt(e){let t=Y.get(e);if(!t)return;if(Y.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed);for(let n of Kr)t.root.removeEventListener?.(n,t.nested);t.root.removeEventListener?.("input",t.share)}function At(e){Y.get(e)?.seed?.()}function St(e,t,n){return he(zr(e,t),n)}var Hr="[data-reactive-shared-field]",Kr=["reactive:connect","reactive:persist-restored"],da=Object.freeze({el:null,kind:""}),pa=/^#[A-Za-z_][\w-]*$/;function V({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 Vr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function ha(e,t){if(t==="string")return V(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Vr(V(e));if(n)return e.el.checked?1:0;let r=Number(V(e));return Number.isFinite(r)?r:0}function ma(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Vr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return ga(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function ga(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function ba(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 va(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 ya(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 wa(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 Aa(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 Sa(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=Ea(o.name,r);if(!n.includes(i))return null;return e.core.bindingOwns(o)?i:null}function Ea(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Gr(e,t,n){let r=String(n);for(let o of xa(e,t)){if(o.textContent===r)continue;o.textContent=r}}function xa(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Ur(e,t,n){let r=_a(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?V(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!va(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function _a(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 ka(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function he(e,t){if(t&&e.ours.has(t))return;let n=Aa(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.bindingOwnership(),s=new Map,c=(h)=>{let m=s.get(h);if(m)return m;let w=null,A=null,q=null;for(let W of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(W))continue;let ue=W.type;if(ue==="checkbox"||ue==="radio"&&W.checked){q={el:W,kind:ue};break}if(ue==="radio")w??=W;else A??=W}if(!q)if(w)q={el:w,kind:"radio"};else q=A?{el:A,kind:""}:da;return s.set(h,q),q};for(let h of r)Gr(e,h,V(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?fa(u):null;if(!l){Ur(e,{},c);return}let f=wa(e,"data-reactive-compute-outputs-param"),d={};for(let[h,m]of n)d[h]=ha(c(h),m);let p=l(d,{changed:Sa(e,t,r,o)})||{},g=ba(p.$ops),v=[];for(let h of f){if(h==="$ops"||!(h in p))continue;let m=c(h);if(!m.el)continue;let w=ma(e.root,a,m,i(h),p[h]);if(w)v.push(w)}for(let h of Object.keys(p)){if(h==="$ops")continue;let m=p[h];if(m===void 0||m===null)continue;Gr(e,h,m)}Ur(e,p,c);for(let h of v){let m=new Event("input",{bubbles:!0});e.ours.add(m),h.dispatchEvent(m)}ya(e,g,Boolean(t))}var kt;function Tt(e){kt=e}var eo=1,Ta="phlex-reactive:persist:",Ra=new Set(["hidden","file","password","submit","button","reset","image"]),Rt=Symbol("persist-no-value"),Ot="data-reactive-persist-state",Oa=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",La=new Set(["lexxy-editor","trix-editor"]),Na="lexxy-editor, trix-editor, trix-toolbar",Fa=["lexxy:change","trix-change"],Ma=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Xr=new WeakSet,Zr=new WeakSet,Qr=new WeakSet;function ge(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(!Xr.has(e))Xr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Lt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function Nt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Zr.has(e))return;Zr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Ft(e){return Ta+e.key}function xt(e,t){let n=Lt(t);if(!n)return null;let r;try{r=n.getItem(Ft(t))}catch(c){return Nt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==eo)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return me(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function to(e,t,{fields:n,state:r}){let o=Lt(t);if(!o)return!1;let i={v:eo,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Ft(t),JSON.stringify(i)),!0}catch(a){return Nt(e,a),!1}}function me(e,t){e?.removeAttribute?.(Ot);let n=Lt(t);if(!n)return;try{n.removeItem(Ft(t))}catch(r){Nt(e,r)}}function Mt(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)||Ra.has(i.type)||i.closest(Na))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Oa)){if(!o(i))continue;let a=Ca(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:La.has(i.localName)?"editor":"contenteditable"})}return r}function no(e){return e.hasAttribute("data-reactive-editable")?kt.text(e):e.textContent??""}function Ca(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Ct(e){return typeof e.value==="string"}function $a(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Ma.has(e.value.trim())}function Pa(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Qr.has(e))return;Qr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function X(e){return e.tagName==="SELECT"&&e.multiple}function ro(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 oo(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Rt;return e[0]}function io(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of Mt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Ct(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=no(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(X(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Da(e,t,n){let r=t.restore==="always",o=Mt(e,t),i=ro(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&X(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||X(s))){if(l=oo(l,c,i),l===Rt)continue}if((s.type==="checkbox"||X(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")so(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&no(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(X(s)){if(!r&&[...s.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of s.options)d.selected=f.has(d.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}Ia(e,t,n)}function so(e,t,n,r,o){if(Array.isArray(r))return;if(!Ct(t))return;if(!o&&!$a(t))return;try{t.value=String(r)}catch(i){Pa(e,n,i)}}function Ia(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Ct(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Mt(e,t),c=ro(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let d=oo(n[l],l,c);if(d===null||d===void 0||d===Rt)continue;so(e,u,l,d,i)}})}function qa(e,t,n=!0){let r=ge(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=xt(e,r),i={...o?.state??{},...t},a=n?io(e,r):o?.fields??{};if(to(e,r,{fields:a,state:i}))e.setAttribute?.(Ot,JSON.stringify(i))}function Wa(e){let t=ge(e);if(t)me(e,t)}var _t=new WeakMap,Et=new WeakMap;function ja(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=Et.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],Et.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),Et.delete(e)}}function $t(e,t,n,r){let o=e.element,i=ge(o);if(!i)return;if(r?.submitted)me(o,i);let a=xt(o,i);if(a){if(Da(o,i,a.fields),a.state)o.setAttribute?.(Ot,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=xt(o,i);to(o,i,{fields:io(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},f=(g)=>{if(!g?.detail?.success)return;let v=g.target;if(v?.tagName!=="FORM"||typeof v.contains!=="function")return;if(!v.contains(o))return;c(),me(o,i)},d=["input",...Fa];for(let g of d)o.addEventListener?.(g,l);o.addEventListener?.("change",u);let p=ja(globalThis.document,f);if(_t.set(e,()=>{if(s!==null)u();for(let g of d)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),p()}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function Pt(e){let t=_t.get(e);_t.delete(e),t?.()}function ao(e,t){let n=kt?.waiting.get(e)?.persist;if(!n||!ge(e))return t(!0);(n.ops??=[]).push(t)}function Dt(e,t){ao(e,(n)=>qa(e,t,n))}function It(e){ao(e,()=>Wa(e))}var be=new WeakMap,uo=new WeakSet,qt=new WeakMap;function Wt(e,t){let n=e.element,r=[],o=[],i=(u,l,f)=>{u.addEventListener?.(l,f),r.push(()=>u.removeEventListener?.(l,f))},a,s,c=()=>{if(!a&&(a=Ba(n,t))){let u=()=>ve(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Ga(n,r)}if(!s&&(s=Ua(n,t))){let u=()=>za(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};be.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function jt(e){for(let t of be.get(e)?.[0]??[])t();be.delete(e)}function Bt(e){be.get(e)?.[1]()}function Ba(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 ve(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,Ja(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 Ja(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 Ha(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Ga(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=qt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(Ha(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(uo.has(c)||!i())return;if(uo.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),qt.delete(n)}},qt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ua(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 za(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 Ut(e){Ka(e),Ya(e)}function Ka(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Jt);else setTimeout(Jt,0);return}let r=async(o)=>{await n(o),Jt()};r.__reactiveDismissWrapped=!0,t.render=r}function Jt(){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 Va=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Ht=Object.freeze(["fade","slide","scale","highlight","shake"]),Gt="data-reactive-fx-pending",zt=1000;function Ya(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Va[r?.getAttribute?.("action")];if(!o||Qa())return;let i=Xa(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await nc(ye(r),i),await n(s)}:async(s)=>{let c=o==="enter"?ec(r):null;if(await n(s),o==="enter")tc(c,i);else po(ye(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Xa(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return fo(n,t);let o=(t==="enter"?Za(e):ye(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?fo(o,t):null}function ye(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Za(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function fo(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"?Ht[Math.floor(Math.random()*Ht.length)]:e;if(!Ht.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Qa(){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?.(Gt,"");return ye(e)}function tc(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Gt}]`)))n.removeAttribute(Gt),po(n,t)}async function nc(e,t){if(!e?.classList)return;if(t.legs){await ho(e,t.legs);return}e.classList.add(t.className);let n=Kt(e);if(n<=0){e.classList.remove(t.className);return}await Vt(e,n),e.classList.remove(t.className)}function po(e,t){if(!e?.classList)return;if(t.legs){ho(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Kt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Vt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function ho(e,t){let[n,r,o]=t.map(rc),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await oc(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Kt(e);if(a>0)await Vt(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function rc(e){return String(e??"").split(/\s+/).filter(Boolean)}function Kt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,zt)}catch{return 0}}function Vt(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,zt))})}function oc(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},zt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var ic="phlex-reactive:latency",Yt=!1;function bo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function vo(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Yt=!1}function Zt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:bo,disableLatencySim:vo}}function Qt(){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(!Yt)Yt=!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 go=new WeakMap;function en(e){let t=globalThis.document;if(!t)return!0;let n=go.get(t);if(!n)n=new Set,go.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Xt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function sc(e,t){try{return e?.matches?.(t)===!0}catch{return!1}}function yo(e,t,n,r){if(en(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function tn(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=Xt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}yo(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function nn(e){if(!en(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function rn(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(sc(r,o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Xt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Xt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}yo(t,o,`scoped to #${r?.id||"?"}`,i)}function on(e,t){let n=e.element?.id||"?";if(en(`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 ac(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function sn(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function we(e,t,n){e.streams=ac(t),e.tokenRefreshed=n!=null}var Ae=new WeakMap;function an(e,t,n,r){let o=n&&typeof n==="object"?lc(n):n;return o?Ao(t,o,r,!1):[]}function cn(e,t,n,r){if(!n)return null;let o=Ao(t,n,r,!0);return o.length?o:null}function Ao(e,t,n,r){let o=[];for(let i of So(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(cc(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function So(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 cc(e,t){let n=Ae.get(t);if(n)n.count++;else Ae.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()=>uc(t,e)}function uc(e,t){let n=Ae.get(e);if(!n)return;if(--n.count>0)return;if(Ae.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function lc(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function un(e,t,n,r){if(!n?.hide)return null;let o=So(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var xe;function dn(e){xe=e}var T=new Map;function ko(e,t){let n=!T.has(e);if(T.set(e,t),n)xe.enter()}function _e(e){if(T.delete(e))xe.exit()}var xo=!1;function pn(e){To();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){gc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;Q(t,n)}function To(){if(xo||typeof document>"u"||!document.addEventListener)return;xo=!0,document.addEventListener("turbo:before-stream-render",vc,!0),document.addEventListener("turbo:before-stream-render",fc)}function fc(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(T.get(n)?.via==="stream")_e(n)}function Q(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}mn(e),No(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return ko(e,r),bc(e,r,t)}function dc(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[wc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Ac()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Ro(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Oo(t))return{src:t};return console.error(pc(t)),hc(t)||mc(e)}function pc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${hn()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function hc(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${hn()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Oo(r))return{src:r,fallback:!0}}function mc(e){mn(e.id),gn(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 Oo(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${hn()}/`)}catch{return!1}}function hn(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function gc(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){Q(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}mn(e),No(n);let o=document.createElement("pgbus-stream-source");o.id=Lo(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),ko(e,{via:"stream"})}function Lo(e){return`reactive-defer-src-${e}`}async function bc(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Sc()),o;try{xe.count("defer"),o=await fetch(...dc(n,t.abort.signal))}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),Z(e,n);return}if(T.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),Z(e,n,o.status);return}if(o.status===204){clearTimeout(r),_o(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),Z(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}"`),Z(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),T.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),Z(e,n);return}if(clearTimeout(r),T.get(e)!==t)return;_o(e),yc(a)}var fn=null,vc=(e)=>fn?.push(e);function yc(e){let t=fn=[];try{window.Turbo.renderStreamMessage(e)}finally{fn=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 mn(e){let t=T.get(e);if(!t)return;if(_e(e),t.via==="fetch")t.abort.abort();else document.getElementById(Lo(e))?.remove?.()}function No(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function gn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function _o(e){_e(e);let t=document.getElementById(e);if(!t)return;gn(t),t.removeAttribute("data-reactive-error")}function Z(e,t,n){_e(e);let r=document.getElementById(e);if(!r)return;gn(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"),Q(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function wc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Ac(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Sc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Fo="__materialize",Ee=new WeakMap;function Se(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function bn(e,t,n){To();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>ke(e),f=(m)=>{if(Se(r)==="visible"){if(!a)p()}else if(m){let w=r.getAttribute("data-reactive-lazy-on");if(s===w)return;d(),r.addEventListener?.(w,l),s=w}},d=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},p=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let m=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:m}),a.observe(r)},g=()=>{let m=Se(r)!==null,w=o;if(o=m,!m)return d();if(i)return;if(t.forgetToken(),!w)return l();f(!0)};if(Ee.set(e,{load(){if(i)return;let m=Ro(r);if(!m&&r.getAttribute("data-reactive-defer-src")!=null)return;if(m&&Ec(r,t))return;let w=m?Q(r.id,m):t.proceed(r,Fo,"{}");if(!w)return;i=!0,d();let A=()=>{i=!1};return w.then(A,A),w},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);d()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&Se(r)===null)ln(r),c=(m)=>m.target===r&&ln(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)ln(r);g()},r.addEventListener?.("turbo:morph-element",u),n)return g();if(o=Se(r)!==null,o)f(!1)}function vn(e){let t=Ee.get(e);Ee.delete(e),t?.off()}function ke(e){return Ee.get(e)?.load()}function Ec(e,t){return t.emit("reactive:before-dispatch",{action:Fo,params:{},element:e},{cancelable:!0}).defaultPrevented}function ln(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Ro(e);if(t)Q(e.id,t)}var yn=new WeakMap,Re=new WeakMap,b=null,C,Co;function En(e,t){let n=e.element;Re.set(n,t),Jo();let r=(i)=>_c(i,t),o=(i)=>Lc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),yn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function xn(e){if(yn.get(e)?.(),yn.delete(e),Re.delete(e.element),b&&Oe(b.origin)===e.element)Te()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),ee=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},Oe=(e)=>e?.closest?.('[data-controller~="reactive"]'),Io=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),F=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==b?.row&&Io(t)===e),$o=(e)=>ee(S(e,"-item"),null),wn=(e)=>S(e,"-disabled")==="true",xc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},qo=(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&&!wn(n)&&Re.has(Oe(n)))};function Wo(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Io(n);if(b||!r||!t.owns(r)||wn(r)||wn(n))return;if(Oe(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function _c(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Wo(e.target,t);if(!n)return;let r=S(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(m)=>m.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(m)=>{if(!a(m))return;if(b)return An(m.clientX,m.clientY);if(Math.abs(m.clientX-o)<=4&&Math.abs(m.clientY-i)<=4)return;if(!c)return h();Tc(n,t,m),An(m.clientX,m.clientY)},f=(m)=>b&&m.cancelable&&m.preventDefault(),d=(m)=>{if(!a(m))return;if(h(),b)kc(),Sn()},p=(m)=>{if(m.type==="pointercancel"&&!a(m))return;if(h(),b)Te()},v=[["pointermove",l],["pointerup",d],["pointercancel",p],["keydown",(m)=>m.key==="Escape"&&b&&(m.preventDefault(),p(m))],["touchmove",f,{passive:!1}]];for(let[m,w,A]of v)document.addEventListener(m,w,A);function h(){clearTimeout(u);for(let[m,w]of v)document.removeEventListener(m,w)}}function kc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Tc({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,b=jo({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),b.dx=r.clientX-o.left,b.dy=r.clientY-o.top,b.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function jo(e){let{row:t,origin:n,source:r}=e;return e.index=F(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),te(n,!0),e}var te=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Le(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 An(e,t){b.x=e,b.y=t,b.row.style.left=`${e-b.dx}px`,b.row.style.top=`${t-b.dy}px`;let n=qo(b.origin).find((r)=>xc(r,e,t));if(n)Rc(n,e,t);else if(b.source)_n(null),b.placeholder.remove();Oc(e,t)}function _n(e){if(b.target!==b.origin)te(b.target,!1);b.target=e,te(e,!0)}function Rc(e,t,n){_n(e);let r=F(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});Le(e,r,s<0?r.length:s,b.placeholder)}function Oc(e,t){let n=b.target??b.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(b.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,b.wy=t<40?-12:t>window.innerHeight-40?12:0,(b.vy||b.wy)&&!b.raf){let i=()=>{if(!b||!(b.vy||b.wy))return b&&(b.raf=0);if((b.target??b.origin).scrollTop+=b.vy,b.wy)window.scrollBy(0,b.wy);An(b.x,b.y),b.raf=requestAnimationFrame(i)};b.raf=requestAnimationFrame(i)}}function Lc(e,t){let n=e.key;if(b?.keyboard){if(e.target!==b.row||b.core!==t)return;let o={" ":Sn,Enter:Sn,Escape:Te,Tab:Te,ArrowUp:()=>Po(-1),ArrowDown:()=>Po(1),ArrowLeft:()=>Do(-1),ArrowRight:()=>Do(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Wo(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),b=jo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Fe("picked")}function Po(e){let t=F(b.target),n=Ne()+e;if(n>=0&&n<=t.length)Le(b.target,t,n,b.row);Bo()}function Do(e){let t=qo(b.origin),n=t[t.indexOf(b.target)+e];if(n){let r=Ne();_n(n),Le(n,F(n),r,b.row)}Bo()}function Bo(){b.row.focus?.(),Fe("moved")}function Ne(){let e=F(b.target),t=b.keyboard?b.row:b.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Jo(){if(!C?.isConnected)C=document.createElement("div"),C.setAttribute("aria-live","polite"),C.setAttribute("data-reactive-sortable-live",""),C.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(C);return C}function Fe(e){let t=b.target??b.origin,n=(ee(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Ne()+1).replaceAll("{count}",F(t).length+1),r=Jo();r.textContent="",cancelAnimationFrame(Co),Co=requestAnimationFrame(()=>r.textContent=n)}function Sn(){let e=b,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?Ne():-1,c=a?$o(F(t)[s-1]):null;if(e.keyboard)Fe("dropped");if(!r&&i)i.replaceWith(o);if(Go(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=ee(S(t,"-from"),{})[u]??S(t),f={...ee(S(t,"-params"),{}),item:$o(e.item),position:s,after:c,from:u},d=[];for(let g=t;g;g=g.parentElement)d.push(g);let p=Re.get(Oe(t))?.proceed(t,l,JSON.stringify(f),ee(S(t,"-busy")));if(r)return;Promise.resolve(p).then((g)=>Nc(g,d)||Ho(e))}function Nc(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"))&&Fc(r,t))}function Fc(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 Te(){let e=b;if(e.keyboard)Fe("cancelled");e.placeholder?.remove(),Go(e),Ho(e)}function Ho({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Le(t,F(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Go(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(b=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),te(n,!1),te(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Yo={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Xo={x:"left",y:"top",width:"width",height:"height"},kn=new WeakMap,On=new WeakMap,y=null,P,zo,Ko=!1;function Ln(e,t){let n=e.element;On.set(n,t),ai(),Jc();let r=[["pointerdown",(o)=>Ic(o,t,n)],["keydown",(o)=>Bc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Yo[o.key]&&Rn()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&Rn()],["input",(o)=>Vo(o,t,n)],["change",(o)=>Vo(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);kn.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function Nn(e){if(kn.get(e)?.(),kn.delete(e),On.delete(e.element),y?.root===e.element)J(y)}var _=(e,t,n)=>Math.min(Math.max(e,t),n),R=(e)=>Math.round(e*1e4)/1e4;function Mc(e,t=1){let n=R(e)*t,r=Number(n.toPrecision(15));return String(Number.isFinite(r)?r:n)}function Fn(e){let t={x:R(e.x),y:R(e.y)};if(e.width!=null)t.width=R(e.width),t.height=R(e.height),t.x=Math.min(t.x,R(1-t.width)),t.y=Math.min(t.y,R(1-t.height));return t}function Zo(e,t,n){return{x:_(e.x+t,0,1-e.width),y:_(e.y+n,0,1-e.height),width:e.width,height:e.height}}function Qo(e,t,n){return{x:_(e.x+t,0,1),y:_(e.y+n,0,1)}}function ei(e,t,n,r,o,i){let[a,s,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,f=e.y+e.height,d=e.x+e.width/2,p=e.y+e.height/2,g=s?1-e.x:u?l:i?2*Math.min(d,1-d):1,v=c?1-e.y:a?f:i?2*Math.min(p,1-p):1,h=e.width+(s?n:u?-n:0),m=e.height+(c?r:a?-r:0);if(i){let w=(s||u)&&(!(a||c)||Math.abs(h-e.width)>=Math.abs(m-e.height)*i),A=Math.min(g,v*i);h=_(w?h:m*i,Math.min(Math.max(o,o*i),A),A),m=h/i}else{if(s||u)h=_(h,Math.min(o,g),g);if(a||c)m=_(m,Math.min(o,v),v)}return{x:u?l-h:s?e.x:d-h/2,y:a?f-m:c?e.y:p-m/2,width:h,height:m}}function Cc(e,t,n){let r=Math.min(1,t),o=_(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:_(e.x+e.width/2-o/2,0,1-o),y:_(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function $c(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 x=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Mn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},O=(e)=>e.matches("[data-reactive-point]")?"point":"box",ti=(e)=>Number(x(e,`${O(e)}-scale`))||1,B=(e)=>O(e)==="point"?["x","y"]:["x","y","width","height"];function ni(e){let t={};for(let n of B(e))t[n]=(parseFloat(e.style[Xo[n]])||0)/100;return t}function Me(e,t){for(let n of B(e))e.style[Xo[n]]=`${Math.round(t[n]*1e4)/100}%`}function Cn(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 Pc(e,t){try{return e.parentElement.closest(x(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function ri(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function oi(e,t,n){let r=Mn(x(e,O(e)),{}),o={};for(let i of B(e)){let[a]=ri(t,n,r[i]);if(a)o[i]=a}return o}function Dc(e,t,n,r){let o=x(e,"box-aspect"),i=o&&ri(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),a=o?$c(i?.value):Number(x(e,"box-ratio"))||0,{width:s,height:c}=Cn(t);return a&&s&&c?a*c/s:0}function $n(e,t,n,r){let o=n.matches("[data-reactive-box-handle]")?n.closest("[data-reactive-box]"):n,i=o?.closest("[data-reactive-frame]");if(!i)return null;let a=ni(o),s=oi(o,t,e),c=O(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?Pc(o,i):i,edge:x(n,"box-handle"),start:a,value:a,ratio:c?0:Dc(o,i,t,e),min:Number(x(o,"box-min"))||0,scale:ti(o),fields:s,before:Object.fromEntries(Object.entries(s).map(([u,l])=>[u,l.value]))}}function ii(e,t,n,r){let o=Mc(n,r);if(t.value===""||!(Math.abs(t.value-o)<r/20000))e.setValue(t,o)}function ne(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))ii(e.core,n,e.value[t],e.scale)}function Ic(e,t,n){if(si(),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)&&$n(t,n,r,!1);if(!o)return;let{clientX:i,clientY:a}=e,s=Cn(o.bounds);o.p0=[(i-s.left)/s.width,(a-s.top)/s.height];let c=(v)=>v.pointerId===e.pointerId,u=(v)=>{if(!c(v)||o.over)return;if(y)return Tn(v.clientX,v.clientY);if(Math.abs(v.clientX-i)<=4&&Math.abs(v.clientY-a)<=4)return;Wc(o),Tn(v.clientX,v.clientY)},l=(v)=>{if(!c(v))return;if(g(),y)qc(),Rn()},f=(v)=>{if(v.type==="pointercancel"&&!c(v))return;if(g(),y)li()},p=[["pointermove",u],["pointerup",l],["pointercancel",f],["keydown",(v)=>v.key==="Escape"&&y&&(v.preventDefault(),f(v))]];for(let[v,h]of p)document.addEventListener(v,h);function g(){for(let[v,h]of p)document.removeEventListener(v,h)}}function qc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Wc(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 Tn(e,t){let n=y;if(!n.el.isConnected)return J(n);n.x=e,n.y=t;let r=Cn(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:a,edge:s}=n;n.value=Fn(O(n.el)==="point"?Qo(a,o,i):s?ei(a,s,o,i,n.min,n.ratio):Zo(a,o,i)),Me(n.el,n.value),n.writing||=requestAnimationFrame(()=>ne(n)),jc(t)}function jc(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),Tn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function si(){if(y&&!y.el.isConnected)J(y)}function Bc(e,t,n){si();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(),li());let o=Yo[e.key];if(!o)return;if(e.preventDefault(),y??=$n(t,n,r,!0),!y)return;let[i,a]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),s=e.altKey&&O(y.el)==="box",c=y.value;y.value=Fn(O(y.el)==="point"?Qo(c,i,a):s?ei(c,y.edge??"se",i,a,y.min,y.ratio):Zo(c,i,a)),Me(y.el,y.value),ne(y),ci(y,s?"resized":"moved")}function ai(){if(!P?.isConnected)P=document.createElement("div"),P.setAttribute("aria-live","polite"),P.setAttribute("data-reactive-drag-live",""),P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(P);return P}function ci(e,t){let n=Mn(x(e.el,`${O(e.el)}-messages`),{})[t]??"";for(let o of B(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=ai();r.textContent="",cancelAnimationFrame(zo),zo=requestAnimationFrame(()=>r.textContent=n)}function Vo(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(x(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=$n(t,n,o,!0),{ratio:a,start:s}=i??{};if(!a||Math.abs(s.width/s.height/a-1)<0.005)continue;i.value=Fn(Cc(s,a,i.min)),Me(o,i.value),ne(i),ui(i)}}function Rn(){let e=y;if(!e.el.isConnected)return J(e);ne(e),J(e),ui(e)}function ui(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=O(e.el),n=x(e.el,`${t}-action`),r={};for(let o of B(e.el))r[o]=R(e.value[o]);if(!n||B(e.el).every((o)=>r[o]===R(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Mn(x(e.el,`${t}-busy`)))}function li(){let e=y;if(e.value=e.start,Me(e.el,e.start),ne(e),e.keyboard)ci(e,"cancelled");J(e)}function J(e){if(y=null,e.over=!0,cancelAnimationFrame(e.raf),cancelAnimationFrame(e.writing),e.grip.removeAttribute("data-reactive-dragging"),e.frame.removeAttribute("data-reactive-frame-active"),!e.keyboard)document.documentElement.style.userSelect=e.select??""}function Jc(){if(Ko)return;Ko=!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=On.get(n);if(!r?.owns(t))return;let o=ni(t),i=ti(t);for(let[a,s]of Object.entries(oi(t,n,r)))ii(r,s,o[a],i)})}var D=new Map,di=new WeakSet;function Pn(e,t){let n=e.element,r=D.get(n.id);if(!r)D.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Hc(n);let o=(a)=>a.target===n&&queueMicrotask(()=>hi(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},hi(r)}function Dn(e){let t=e.element,n=D.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;D.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function In(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=D.get(e.id);if(!n)D.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},mi(n)}function Hc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&di.has(n))return;if(n?.remove(),!pi())setTimeout(()=>{if(!pi())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=D.get(e.id);if(!o||o.removing)return;mi(o),Gc(o)}),di.add(r),document.body.appendChild(r)}var pi=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Gc(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&gi(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function mi(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function gi(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function hi(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=gi(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}var vi=new Map,qn=new WeakMap,Uc=0,Ce=new WeakMap;function Wn(e,t){let n=e.element;if(!n.id&&!qn.has(n))qn.set(n,`#${++Uc}`);let r=n.id||qn.get(n),o=new Map,i=!1,a=(p)=>{clearTimeout(o.get(p)),o.delete(p)},s=(p,g,v)=>{a(p);let h=Date.parse(g.until)-Date.now();if(!(h>0))return c(p,g,v);let m=Math.ceil(h/1000);yi(p,`${Math.floor(m/60)}:${String(m%60).padStart(2,"0")}`,"running"),u(g.waiting,!0),u(g.done,!1),o.set(p,setTimeout(()=>s(p,g,v),(h-1)%1000+1))},c=(p,g,v)=>{yi(p,"0:00","done"),u(g.waiting,!1),u(g.done,!0);let h=vi.get(v)??new Set;if(h.has(g.until))return;vi.set(v,h.add(g.until)),p.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:g.until}}))},u=(p,g)=>{let v;try{v=p&&n.querySelector(p)}catch{}if(v&&v.hidden===g)v.hidden=!g},l=()=>{if(i=!1,!Ce.has(e))return;let p=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((v,h)=>{if(!t.owns(v))return;let m;try{m=JSON.parse(v.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(m?.until)))return;p.add(v),s(v,m,`${r}|${v.id||h}`)});for(let v of o.keys())if(!p.has(v))a(v)},f=()=>{if(i)return;i=!0,queueMicrotask(l)},d=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",f),n.addEventListener("reactive:streamed",f),document.addEventListener("visibilitychange",d),Ce.set(e,()=>{n.removeEventListener("turbo:morph-element",f),n.removeEventListener("reactive:streamed",f),document.removeEventListener("visibilitychange",d);for(let p of[...o.keys()])a(p)}),l()}function jn(e){Ce.get(e)?.(),Ce.delete(e)}function yi(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 Kc(){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 Vc(){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 Yc=["focus","focus_first","blur"];function Xc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=pr(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)nn(n);return}let i=(s)=>tr(s,(c)=>Bu(c,o),r?(c,u)=>tn(c,u,o):void 0),a=t.findIndex((s)=>Yc.includes(s?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return i(t);i(t.slice(0,a)),requestAnimationFrame(()=>i(t.slice(a)))}}function Zc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){pn(this)}}var Si=!1,Qc=null;function eu(){if(Si)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Si=!0,document.addEventListener("turbo:before-stream-render",(e)=>{pu(e),tu(e),ru(e),Ut(e)})}var qe="reactive:streamed";function tu(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(qe))}}function or(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function ir(e){try{return e.matches(":modal")}catch{return!1}}function Yi(e){if(!or(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||ir(e))return;if(e.open)e.close();e.showModal()}function nu(e){if(or(e)&&e.open)e.close()}function Ge(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!ir(r))Yi(r)}function ru(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),Ge(document)}}var Ei=!1;function ou(){if(Ei)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ei=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Ge(t.target)}),document.addEventListener("turbo:morph",()=>Ge(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!or(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!ir(n))return;e.delete(n),t.preventDefault(),n.close()})}var Zn=new WeakMap;function Xi(e,t,n,r){let o=Zn.get(e)??new Map;Zn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))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 a of r({...n,to:n.expanded}))Xi(a,"set_attr",{name:"aria-expanded"})}}var xi=!1;function iu(){if(xi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;xi=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Zn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var Zi="data-reactive-image-fallback",oe="data-reactive-image-state",Qn="data-reactive-image-hidden",Bn=null,er="data-reactive-wrap-hidden";function Qi(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(er,"")}function es(e){if(!e.hasAttribute(er))return;e.removeAttribute("hidden"),e.removeAttribute(er)}function ie(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Zi);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var ts=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function sr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function ns(e,t){let n=sr(e,t.alt);return n&&!n.contains(e)?n:null}function Ue(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Qn,"");if(t.wrap){let o=sr(e,t.wrap);if(o)Qi(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=ns(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Ve(e,t);e.setAttribute(oe,n)}function Ve(e,t=ie(e)){if(!t||e.getAttribute(oe)==null)return;if(e.getAttribute(oe)==="error"){if(e.hasAttribute(Qn))e.removeAttribute("hidden");let n=sr(e,t.wrap);if(n)es(n);let r=ns(e,t);if(r)r.hidden=!0}e.removeAttribute(oe),e.removeAttribute(Qn)}function _i(e){let t=e.target,n=ie(t);if(!n)return;if(e.type==="load")Ue(t,n,"loaded");else if(ts(t))Ue(t,n,"error");else Ve(t,n)}function su(){if(Bn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;Bn={error:_i,load:_i,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(oe);if(o==null||!r||!ie(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=ie(n);if(o)Ue(n,o,r)})}};for(let[t,n]of Object.entries(Bn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Zi}]`)??[]){if(!t.complete||!ts(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Ue(t,ie(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 dl(e){Qc=e}var $e,Jn=null,ki="[data-reactive-editable][contenteditable=plaintext-only]";function rs(){if($e===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",$e=e.contentEditable==="plaintext-only"}catch{$e=!1}return $e}function We(e){if(e.matches?.(ki))e.setAttribute("contenteditable","true");e.querySelectorAll?.(ki).forEach(We)}function au(){if(Jn||typeof document>"u"||typeof document.createElement!=="function")return;if(rs())return;We(document),Jn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")We(t.target);else t.addedNodes.forEach(We)}),Jn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Ti=!1;function Ri(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 cu(){if(Ti)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ti=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=Ri(t);if(r)lu(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(ze.set(t,I(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==k)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>fr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===k)&&Ri(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(k)&&cr(t)===ur(t))t.removeAttribute(k)})}var k="data-reactive-held",ar='[data-controller~="reactive"]',je=null,G=new Map;function cr(e){return e.hasAttribute("data-reactive-editable")?I(e):e.value}function ur(e){return e.hasAttribute("data-reactive-editable")?dr(e):e.defaultValue}function uu(e){if(e.hasAttribute("data-reactive-editable"))return I(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function lu(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||G.has(e.closest(ar)))return;let r=uu(t);if(r===cr(e))return e.removeAttribute(k);if(r===ur(e))return;e.setAttribute(k,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function fu(e){let t=[];for(let n of e.querySelectorAll(`[${k}]`)){if(n.closest(ar)!==e)continue;let r=n.getAttribute("name");if(cr(n)===ur(n))n.removeAttribute(k);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function os(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${k}]`))if(n.closest(ar)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(k)}function du(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 Oi(e,t,n=null){let r={root:e,streams:0,keep:n},o=je;je=r;try{window.Turbo.renderStreamMessage(t)}finally{je=o}if(r.streams===0)os(e,n)}function pu(e){let t=je,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{G.set(t.root,(G.get(t.root)||0)+1);try{return await r(o)}finally{let i=G.get(t.root)-1;if(i)G.set(t.root,i);else G.delete(t.root);os(t.root,t.keep)}}}var Li="__materialize",Ni=!1;function hu(){if(Ni)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ni=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}function lr(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Zt()}var is="data-reactive-active",L=0;function ss(){if(L++,L===1)cs("reactive:busy")}function as(){if(L===0)return;if(L--,L===0)cs("reactive:idle")}function pl(){return L}function hl(){L=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(is)}function cs(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(is,L>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:L}}))}var us="data-reactive-requests";function ls(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!mu(t))return;let n=gu(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(us,JSON.stringify(n))}function mu(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function gu(e){try{let t=JSON.parse(e.getAttribute(us));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Fi(){Kc(),Vc(),Xc(),Zc(),eu(),cu(),ou(),iu(),su(),au(),hu(),lr()}function bu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var fs=Symbol.for("phlex-reactive.core");if(globalThis[fs])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[fs]=!0;var ds=!1;function vu(){if(ds)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(vu,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var yu=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function ps(e){let t=String(e).toLowerCase();return t.startsWith("on")||yu.has(t)}var Hn=new WeakMap;function wu(e,t,n){let[r,o,i]=t;Hn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,Hn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Hn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Au(e))}function Au(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Su=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Eu=new Set(["lexxy-editor","trix-editor"]);function I(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
2
2
|
`))t+=`
|
|
3
3
|
`;n=!1,t+=i},o=(i)=>{for(let a of i.childNodes){let s=/^(div|p|li)$/.test(a.localName);if(s)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
|
|
4
4
|
`);else if(a.nodeType===1)o(a);if(s)n=!0}};return o(e),t=t.replace(/\r\n?/g,`
|
|
5
|
-
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var ze=new WeakMap;function fr(e){if(e?.hasAttribute?.("data-reactive-editable")&&!ze.has(e))ze.set(e,
|
|
6
|
-
`):e.value}function Ou(e,t,n){if(n?.transition)yu(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Gn(e,t,n,r){if(Ou(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 Un(e){if(!ps(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function bs(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Ve(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Fu='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Nu(e){return e.querySelectorAll?.(Fu)?.[0]??null}function pr(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var $i=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"}),Pi=Object.freeze(["meta","ctrl","alt","shift"]);function Ye(e,t,n){let r=e.split("+");for(let a of Pi)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Pi.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn($i,o)?$i[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Mu=(e)=>e&&typeof e==="object"?e.keys:String(e),mr=()=>Je().prevented??=new WeakSet;function zn(e,t){if(t!=null&&!e.defaultPrevented)mr().add(e);e.preventDefault()}function Pe(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!mr().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Ye(Mu(e).replace(/^mod\+/,`${o}+`),t,n)}function Cu(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:pr(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function Ii(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==hr(t.currentTarget))return!1;return o<0||n===null||Ye(r.slice(o+1),t,n)}function $u(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 Di=new WeakMap;function Pu(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Di.get(e);if(!o)o=new WeakMap,Di.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var qi=new WeakMap;function Iu(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=qi.get(e);if(!o)o=new WeakMap,qi.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function tr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Mi,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(Mi[o](s,i,t),i?.keep===!0)Xi(s,o,i,t)}}function Du(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function qu(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function nr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var H='[data-controller~="reactive"]',Wu='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',rr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!nr(e);function re(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&rr(r))r=r.parentElement?.closest?.(t);return r??null}var Ie=new WeakMap,De=new WeakMap;function ju(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 Bu(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 Ju(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Hu(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Gu(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 Wi(e){return e.getAttribute?.("data-reactive-presence")!=null}function Uu(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function fl(e,t,n){}function zu(e,t){}function dl(e){return[]}function pl(e){return Promise.resolve()}var ji=new Set;function Ku(e,t,n){let r=e+t;if(ji.has(r))return;ji.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 ml(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Bi=Promise.resolve();var Ji={enter:ss,exit:as,count:ls,text:D,served:dr,waiting:new WeakMap},Hi=1,Kn=2,Vn=4,Yn=8,Xn=16,Gi=32,Ui=64,zi=128,Ki=256;Tt(Ji),dn(Ji);var ce=Symbol.for("phlex-reactive.early"),Vu=1e4,Yu=1500,hr=(e)=>e!=null&&(e===globalThis.window||e.window===e),Xu="dispatch";function Je(){return globalThis[ce]??={queue:[],connected:new WeakSet},globalThis[ce]}function Zu(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Vu}function Qu(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function el(e,t,n){return{[ce]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Qu(t),key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,button:e.button,submitter:e.submitter,bubbles:e.bubbles,timeStamp:e.timeStamp,defaultPrevented:e.defaultPrevented&&!mr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var Ke=new WeakMap;function tl(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Ke.get(e);if(!s)Ke.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function Vi(e,t,n,r){if(e?.[ce])return!1;let o=hr(e?.currentTarget),i=o?r:e?.currentTarget,a=rl(e,i,o?`@${t}`:t),s=Ke.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Ye(u.filter,e,n))continue;return u.armed=!1,!0}return a}var He=new WeakMap;function nl(e,t,n){let r=He.get(e);if(!r)He.set(e,r=new Map),setTimeout(()=>He.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function rl(e,t,n){let r=e&&He.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class vs extends Uc{static values={token:String};#g;#f=new Map;#d=new Map;#Y;#A;#M;#S=0;#p=new Map;#E=new WeakMap;#r;featuresReady=Bi;#Me=new Map;#Ce=new Set;#X=!1;#C=null;#$e=new Map;#Pe=new Map;#Ie=new Map;#Z=0;#$;#x=0;#o=0;connect(){if(ds=!0,Je().connected.add(this.element),Ie.set(this.element,this),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||nr(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===qe)this.#I();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(qe,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(fr),this.#Z++,this.featuresReady=Bi,this.#P(),Ge(this.element),this.#ee()}#P(e){this.#t(Hi,"persist",qu,(t)=>$t(this,t,e)),this.#t(Kn,"defer",nr,(t)=>bn(this,t,e)),this.#t(Vn,"form",ju,(t)=>Wt(this,t,e)),this.#t(Yn,"bindings",Bu,(t)=>et(this,t,e)),this.#t(Xn,"compute",Ju,(t)=>yt(this,t,e)),this.#t(Gi,"sortable",Hu,(t)=>En(this,t)),this.#t(Ki,"drag",Gu,(t)=>On(this,t)),this.#t(Ui,"presence",Wi,(t)=>Pn(this,t)),this.#t(zi,"countdown",Uu,(t)=>Wn(this,t))}#t(e,t,n,r){if(this.#x&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#x|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#D(t,"connect",o)}}#Q(){{let e=this.#o;this.#x=this.#o=0;let t=this.#e();if(e&Hi)this.#n("persist",()=>Pt(this,t));if(e&Kn)this.#n("defer",()=>vn(this,t));if(e&Vn)this.#n("form",()=>jt(this,t));if(e&Yn)this.#n("bindings",()=>tt(this,t));if(e&Xn)this.#n("compute",()=>wt(this,t));if(e&Gi)this.#n("sortable",()=>xn(this,t));if(e&Ki)this.#n("drag",()=>Fn(this,t));if(e&Ui)this.#n("presence",()=>In(this,t));if(e&zi)this.#n("countdown",()=>jn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#De(e){}#qe(e,t){}#We(e){}#je(e,t){}#Be(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#g=void 0},owns:(e)=>this.#h(e),ownership:()=>this.#H(),bindingOwns:(e)=>this.#G(e),bindingOwnership:()=>this.#ye(),opTargets:(e)=>this.#N(e),diagnose:(e,t)=>this.#F(e,t),applyOps:(e,t)=>tr(e,(n)=>this.#N(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#F(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#U(),plain:rs,text:D,served:dr,copyMedia:bs,setValue:gs,confirm:(e,t)=>Promise.resolve().then(()=>Ai(e,t)).catch(()=>!1)},this.#$}#I(){if(this.#o&Vn)Bt(this);if(this.#o&Yn)nt(this);if(this.#o&Xn)At(this)}#D(e,t,n){if(Ku(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#Je(){}#ee(){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.#te();for(let[e,t]of De.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}De.delete(this.element)}#_=new Set;#te(){let{queue:e}=Je();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=Zu(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(Yu,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#ne(o)}}#ne({event:e,el:t,descs:n,win:r}){let o=el(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Ye(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!tl(s,c,r&&JSON.stringify(o.params)))continue;this.#_.add(s)}if(nl(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Q(),this.#le(),this.#de(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(qe,this.#r);if(Je().connected.delete(this.element),Ie.get(this.element)===this)Ie.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#_)Ke.delete(e);this.#_.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Oi&&this.#oe())return this.#ie(e);let t=e.params?.shortcut;if(t!=null&&!Pe(t,e,this.application?.schema?.keyMappings))return;if(Vi(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l,prevent:f}=e.params;if(!n)return;let d=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#K(l,p))zn(e,t);if(n===Oi){let m=()=>{if(this.#o&Kn)return ke(this);if(this.tokenValue)return this.#k(p,n,"{}")};return this.#X?this.featuresReady.then(m):m()}let g=this.#q(a,s),v=()=>this.#k(p,n,r,o,i,l,d);if(!g)return v();if(g instanceof Promise)return g.then((m)=>m?this.#b(m,p,v):v());this.#b(g,p,v)}#b(e,t,n){return Promise.resolve().then(()=>Ai(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return ot(this,this.#e(),t)}#re(e){}#oe(){return!this.tokenValue&&rr(this.element)}#ie(e){let t=re(this.element.parentElement,Wu);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=Ie.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:a}=e.params;if(r!=null&&!Pe(r,e,this.application?.schema?.keyMappings))return;let s=e.currentTarget??e.target;if((r!=null||!o&&a!==!1)&&!this.#K(i,s))zn(e,r);De.set(t,[...De.get(t)??[],[e,s]]);let c=t.dataset;if(c.reactiveDormant)c.controller=`${c.controller??""} ${c.reactiveDormant}`.trim(),delete c.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Pe(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Vi(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Iu(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Cu(n.ops),i=o.filter((s)=>Ii(s,e,null)),a=i.length<=1?i:i.filter((s)=>Ii(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())on(this,e);return}for(let s of a){if(s.outside&&e[ce])continue;if(!$u(s,e))continue;if(s.shortcut!=null&&!Pe(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(Pu(this,e,s))continue;this.#se(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0,prevent:void 0}:s,e,r,o.indexOf(s))}}#se(e,t,n,r){let{ops:o,confirm:i,confirmWhen:a,outside:s,window:c,shortcut:u,prevent:l}=e;if(s&&this.element.contains(t.target))return;if(u!=null||!c&&l!==!1)zn(t,u);let f=this.#q(i,a),d=this.#ae(e,r,n,()=>this.#_e(this.#xe(o)));if(!f)return d();if(f instanceof Promise)return f.then((p)=>p?this.#b(p,n,d):d());this.#b(f,n,d)}#ae(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let a=JSON.stringify([t,e]);if(o>0)return()=>this.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return St(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return dt(this,this.#e(),e)}tagsPick(e){return pt(this,this.#e(),e)}tagsRemove(e){return mt(this,this.#e(),e)}nestedAdd(e){return ht(this,this.#e(),e)}nestedRemove(e){return gt(this,this.#e(),e)}syncNestedJson(e){return rt(this,this.#e(),e)}#He(e,t){}trackDirty(){ve(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.#ce(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ce(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#H();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#z(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ue(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#fe(e,u,t,n,i,a);return this.#y(t,n,i,e,a)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ke(e,r,i),s=Boolean(n||o),c=(d)=>{if(!s||!d)return;let p=this.#e();if(i.inverse=cn(this,p,n,r),i.undo.push(...an(this,p,o,r)),this.#R())i.resurrect=un(this,p,n,r)},u=!0;c(!0);let l=()=>this.#ge(e,t,i,a),f=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Ge(){return this.#re("hints")}#ue(e,t,n,r,o,i){this.#W(e,Xu,t,()=>this.#y(n,r,o,e,i))}#W(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!hr(e))e?.addEventListener?.("blur",o,{once:!0});let a=this.#f.get(e);if(!a)this.#f.set(e,a=new Map);a.set(t,{timer:i,flush:o})}#T(e,t){let n=this.#f.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#f.delete(e)}#le(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#fe(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#y(n,r,o,e,i))}#j(e,t,n,r){let o=this.#d.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#d.delete(e)},n);return o.set(t,i),this.#d.set(e,o),r()}#de(){for(let e of this.#d.values())for(let t of e.values())clearTimeout(t);this.#d.clear()}#s(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#y(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#pe(){this.element?.removeAttribute?.("data-reactive-error")}#me(){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))}#he(){return Qt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ge(e,t,n,r){let{fields:o,files:i}=this.#U(),a=this.#z(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#Se(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#he();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let d;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Fe()};if(!u)m["Content-Type"]="application/json";let h=this.#Ne();if(h)m["X-Pgbus-Connection"]=h;let w=Wi(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(w)m["X-Reactive-Presence"]=w;let A=lu(this.element);if(A)m["X-Reactive-Held"]=A;ls("action"),d=await fetch(this.#Le(),{method:"POST",headers:m,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Oe())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#u(n.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#me(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:d.status});return}if(!d.ok){let m=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,m),this.#u(n.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let h=this.#J(m);if(this.#c=h??this.#c,f)we(f,m,h);Li(this.element,m,!0)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:d.status,body:m});return}let p=d.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:d.status});return}let g=await d.text(),v=this.#J(g);if(this.#c=v??this.#c,f)we(f,g,v);if(Li(this.element,g,fu(d)),n.resurrect)queueMicrotask(n.resurrect);return this.#pe(),this.#s("reactive:applied",{action:e,params:s,html:g}),g}catch(d){console.error("[phlex-reactive] action error",d),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),f)sn(this,{...f,ms:this.#B()-f.started})}}get#c(){return this.#g??this.tokenValue}set#c(e){this.#g=e}tokenValueChanged(){this.#g=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#be(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}#be(e){let t=this.#M;if(t&&t.id===e)return t;let n=gu(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#h(e){return e.closest('[data-controller~="reactive"]')===this.element}#H(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#h(t)}#ve(){let e=this.element.querySelectorAll(H);if(e.length===0||[...e].every(rr))return()=>!0;return(t)=>{let n=re(t,H,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&re(n.parentElement,H,this.element)===this.element}}#G(e){if(this.#h(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=re(e,H,this.element);return t===this.element||re(t?.parentElement,H,this.element)===this.element}#ye(){if(this.element.querySelectorAll(H).length===0)return()=>!0;return(e)=>this.#G(e)}#U(){let e={},t=[],n=this.#ve(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${Au}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#we(r),a=this.#Ae(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?D(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Eu(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#we(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}#Ae(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Se(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#w(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#L(o,this.#w(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#Ee(r);for(let{name:s,file:c,multiple:u}of r){let f=u||a.has(s)?`${this.#w(s)}[]`:this.#w(s);o.append(f,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#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))}#Ee(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))}#z(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#xe(e){return pr(e)}#_e(e){tr(e,(t)=>this.#N(t),(t,n)=>this.#F(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#F(e,t){if(!this.#O())return;rn(this,e,t)}#Ue(e){}#N(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#h(n))}#K(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ke(e,t,n){this.#Te(e,t),ss();let r=!1;return()=>{if(r)return;r=!0,this.#Re(e,t),as();for(let o of n.undo)o()}}#Te(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#p.set(e,(this.#p.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#V(e))this.#l(n,e,1)}#Re(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#p.get(e)??1)-1;if(n<=0)this.#p.delete(e);else this.#p.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#V(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#V(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#h(n))}#Le(){return this.#Y??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Oe(){if(this.#A!=null)return this.#A;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#A=Number.isFinite(t)&&t>0?t:30000}#Fe(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Ne(){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)Ni();else document.addEventListener("turbo:load",Ni,{once:!0});lr();var El=vs;export{is as ACTIVE_ATTR,Au as EDITOR_SELECTOR,Su as EDITOR_TAGS,ic as LATENCY_KEY,us as REQUESTS_ATTR,bu as checkReactiveRegistration,ls as countReactiveRequest,El as default,vo as disableLatencySim,D as editableValue,bo as enableLatencySim,ss as enterReactiveActivity,gu as escapeRegExp,as as exitReactiveActivity,pl as loadReactiveFeature,cl as onReactiveStreamWithoutEffects,ul as reactiveActivityCount,ml as reactiveFeatureNames,Ni as registerReactiveActions,Xc as registerReactiveDefer,lr as registerReactiveDev,Qc as registerReactiveDismiss,Qc as registerReactiveEffects,zu as registerReactiveFeature,fl as registerReactiveFeatureLoader,iu as registerReactiveImageFallback,Yc as registerReactiveJs,ou as registerReactiveKeep,ru as registerReactiveModals,au as registerReactiveMorphFocus,pu as registerReactiveOffline,su as registerReactivePlaintext,Qc as registerReactiveStreamRender,Kc as registerReactiveToken,zc as registerReactiveVisit,ll as resetReactiveActivity,dr as serverText,dl as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var ze=new WeakMap;function fr(e){if(e?.hasAttribute?.("data-reactive-editable")&&!ze.has(e))ze.set(e,I(e))}function dr(e){return fr(e),ze.get(e)}function xu(e){return Eu.has(e.localName)?typeof e.value==="string":!0}var Mi=Object.freeze({show:(e,t,n)=>Gn(e,!1,t,n),hide:(e,t,n)=>Gn(e,!0,t,n),toggle:(e,t,n)=>Gn(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(Un(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Un(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Un(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)=>Mu(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Yi(e),close_dialog:(e)=>nu(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}bs(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)ct(r,t.group,t.checked)},presence:(e,t)=>In(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=_u(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)=>ku(e),preview_file:(e,t,n)=>Tu(e,t,n),set_value:(e,t)=>gs(e,String(t.value??"")),persist_state:(e,t)=>Dt(e,t.state),persist_clear:(e)=>It(e)});function _u(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function ku(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ms(e),e.focus?.()}).catch(()=>{})}var se=new Map,ae=null;function Tu(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Be(`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 Be(`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=Ou(e,t.accept),a=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,s=[],c;if(t.per_file===!0&&e.multiple){let u=o.filter((f,d)=>{let p=typeof f?.type==="string"&&i(f)?a(f)&&"size":"type";if(p)s.push({reason:p,file:f,index:d});return!p}),l=s.length>0&&!Ru(e,u)?o.length:u.length;for(let f of s)f.remaining=l;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=o.filter((f)=>typeof f?.type==="string"&&i(f));c=u.find((f)=>f.type.startsWith("image/"));let l=o.length>0&&u.length===0?"type":null;if(c&&a(c))l="size";if(l)s.push({reason:l,file:l==="size"?c:o[0]}),c=null}if(hs(r),c){let u=URL.createObjectURL(c);se.set(r,u),r.setAttribute("src",u),Lu()}else r.removeAttribute("src");if(Ve(r),t.wrap!=null){let u=n({...t,to:t.wrap});if(u.length===0)Be(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let l of u)c?es(l):Qi(l)}if(t.name!=null)for(let u of n({...t,to:t.name}))u.textContent=c?c.name:"";for(let u of s)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}function Ru(e,t){if(typeof DataTransfer!=="function"){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))Be("per_file: has no DataTransfer to drop the refused files from the input");return!1}let n=new DataTransfer;for(let r of t)n.items.add(r);return e.files=n.files,!0}function Ou(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 Be(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function hs(e){let t=se.get(e);if(t===void 0)return;if(se.delete(e),URL.revokeObjectURL(t),se.size===0)ae?.disconnect(),ae=null}function Lu(){if(ae||typeof MutationObserver!=="function"||!document?.documentElement)return;ae=new MutationObserver(()=>{for(let[e,t]of se)if(!e.isConnected||e.getAttribute("src")!==t)hs(e)}),ae.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ms(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function gs(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=Ci(e);if(e.value=t,Ci(e)!==n)ms(e)}function Ci(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function Nu(e,t,n){if(n?.transition)wu(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Gn(e,t,n,r){if(Nu(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 Un(e){if(!ps(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function bs(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Ve(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Fu='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Mu(e){return e.querySelectorAll?.(Fu)?.[0]??null}function pr(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var $i=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"}),Pi=Object.freeze(["meta","ctrl","alt","shift"]);function Ye(e,t,n){let r=e.split("+");for(let a of Pi)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Pi.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn($i,o)?$i[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Cu=(e)=>e&&typeof e==="object"?e.keys:String(e),hr=()=>Je().prevented??=new WeakSet;function zn(e,t){if(t!=null&&!e.defaultPrevented)hr().add(e);e.preventDefault()}function Pe(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!hr().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 Ye(Cu(e).replace(/^mod\+/,`${o}+`),t,n)}function $u(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:pr(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function Di(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)!==mr(t.currentTarget))return!1;return o<0||n===null||Ye(r.slice(o+1),t,n)}function Pu(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 Ii=new WeakMap;function Du(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Ii.get(e);if(!o)o=new WeakMap,Ii.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var qi=new WeakMap;function Iu(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=qi.get(e);if(!o)o=new WeakMap,qi.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function tr(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Mi,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);if(a.length>0)i=Wu(o,i,t,n);if(!i)continue;for(let s of a)if(Mi[o](s,i,t),i?.keep===!0)Xi(s,o,i,t)}}var qu=new Set(["set_value","text","set_attr"]);function Wu(e,t,n,r){let o=e==="dispatch",i=o?t.detail_from:qu.has(e)&&t.from!=null&&{value:t.attr};if(!i)return t;let a=o?"@trigger":t.from,s;try{s=n({...t,to:a})[0]}catch{}if(!s)return r?.(e,{...t,to:a}),null;let c=o?{...t.detail}:{};for(let[u,l]of Object.entries(i)){let f=ju(s,l);if(f==null)return null;c[u]=f}return o?{...t,detail:c}:{...t,...c}}function ju(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 Bu(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 Ju(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function nr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var H='[data-controller~="reactive"]',Hu='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',rr=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!nr(e);function re(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&rr(r))r=r.parentElement?.closest?.(t);return r??null}var De=new WeakMap,Ie=new WeakMap;function Gu(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 Uu(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 zu(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Ku(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Vu(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 Wi(e){return e.getAttribute?.("data-reactive-presence")!=null}function Yu(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function ml(e,t,n){}function Xu(e,t){}function gl(e){return[]}function bl(e){return Promise.resolve()}var ji=new Set;function Zu(e,t,n){let r=e+t;if(ji.has(r))return;ji.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 vl(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Bi=Promise.resolve();var Ji={enter:ss,exit:as,count:ls,text:I,served:dr,waiting:new WeakMap},Hi=1,Kn=2,Vn=4,Yn=8,Xn=16,Gi=32,Ui=64,zi=128,Ki=256;Tt(Ji),dn(Ji);var ce=Symbol.for("phlex-reactive.early"),Qu=1e4,el=1500,mr=(e)=>e!=null&&(e===globalThis.window||e.window===e),tl="dispatch";function Je(){return globalThis[ce]??={queue:[],connected:new WeakSet},globalThis[ce]}function nl(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Qu}function rl(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function ol(e,t,n){return{[ce]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:rl(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&&!hr().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var Ke=new WeakMap;function il(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Ke.get(e);if(!s)Ke.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function Vi(e,t,n,r){if(e?.[ce])return!1;let o=mr(e?.currentTarget),i=o?r:e?.currentTarget,a=al(e,i,o?`@${t}`:t),s=Ke.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Ye(u.filter,e,n))continue;return u.armed=!1,!0}return a}var He=new WeakMap;function sl(e,t,n){let r=He.get(e);if(!r)He.set(e,r=new Map),setTimeout(()=>He.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function al(e,t,n){let r=e&&He.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class vs extends zc{static values={token:String};#g;#d=new Map;#p=new Map;#Y;#S;#M;#E=0;#h=new Map;#x=new WeakMap;#r;featuresReady=Bi;#Ce=new Map;#$e=new Set;#X=!1;#C=null;#Pe=new Map;#De=new Map;#Ie=new Map;#Z=0;#$;#_=0;#o=0;connect(){if(ds=!0,Je().connected.add(this.element),De.set(this.element,this),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||nr(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===qe)this.#D();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(qe,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(fr),this.#Z++,this.featuresReady=Bi,this.#P(),Ge(this.element),this.#ee()}#P(e){this.#t(Hi,"persist",Ju,(t)=>$t(this,t,e)),this.#t(Kn,"defer",nr,(t)=>bn(this,t,e)),this.#t(Vn,"form",Gu,(t)=>Wt(this,t,e)),this.#t(Yn,"bindings",Uu,(t)=>et(this,t,e)),this.#t(Xn,"compute",zu,(t)=>yt(this,t,e)),this.#t(Gi,"sortable",Ku,(t)=>En(this,t)),this.#t(Ki,"drag",Vu,(t)=>Ln(this,t)),this.#t(Ui,"presence",Wi,(t)=>Pn(this,t)),this.#t(zi,"countdown",Yu,(t)=>Wn(this,t))}#t(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#I(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#I(t,"connect",o)}}#Q(){{let e=this.#o;this.#_=this.#o=0;let t=this.#e();if(e&Hi)this.#n("persist",()=>Pt(this,t));if(e&Kn)this.#n("defer",()=>vn(this,t));if(e&Vn)this.#n("form",()=>jt(this,t));if(e&Yn)this.#n("bindings",()=>tt(this,t));if(e&Xn)this.#n("compute",()=>wt(this,t));if(e&Gi)this.#n("sortable",()=>xn(this,t));if(e&Ki)this.#n("drag",()=>Nn(this,t));if(e&Ui)this.#n("presence",()=>Dn(this,t));if(e&zi)this.#n("countdown",()=>jn(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.#$??={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.#H(),bindingOwns:(e)=>this.#G(e),bindingOwnership:()=>this.#we(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>tr(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#U(),plain:rs,text:I,served:dr,copyMedia:bs,setValue:gs,confirm:(e,t)=>Promise.resolve().then(()=>Ai(e,t)).catch(()=>!1)},this.#$}#D(){if(this.#o&Vn)Bt(this);if(this.#o&Yn)nt(this);if(this.#o&Xn)At(this)}#I(e,t,n){if(Zu(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#He(){}#ee(){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.#te();for(let[e,t]of Ie.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Ie.delete(this.element)}#k=new Set;#te(){let{queue:e}=Je();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=nl(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(el,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#A())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#ne(o)}}#ne({event:e,el:t,descs:n,win:r}){let o=ol(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Ye(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!il(s,c,r&&JSON.stringify(o.params)))continue;this.#k.add(s)}if(sl(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Q(),this.#fe(),this.#pe(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(qe,this.#r);if(Je().connected.delete(this.element),De.get(this.element)===this)De.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#k)Ke.delete(e);this.#k.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Li&&this.#oe())return this.#ie(e);let t=e.params?.shortcut;if(t!=null&&!Pe(t,e,this.application?.schema?.keyMappings))return;if(Vi(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l,prevent:f}=e.params;if(!n)return;let d=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#K(l,p))zn(e,t);if(n===Li){let h=()=>{if(this.#o&Kn)return ke(this);if(this.tokenValue)return this.#T(p,n,"{}")};return this.#X?this.featuresReady.then(h):h()}let g=this.#q(a,s),v=()=>this.#T(p,n,r,o,i,l,d);if(!g)return v();if(g instanceof Promise)return g.then((h)=>h?this.#b(h,p,v):v());this.#b(g,p,v)}#b(e,t,n){return Promise.resolve().then(()=>Ai(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return ot(this,this.#e(),t)}#re(e){}#oe(){return!this.tokenValue&&rr(this.element)}#ie(e){let t=re(this.element.parentElement,Hu);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=De.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i,prevent:a}=e.params;if(r!=null&&!Pe(r,e,this.application?.schema?.keyMappings))return;let s=e.currentTarget??e.target;if((r!=null||!o&&a!==!1)&&!this.#K(i,s))zn(e,r);Ie.set(t,[...Ie.get(t)??[],[e,s]]);let c=t.dataset;if(c.reactiveDormant)c.controller=`${c.controller??""} ${c.reactiveDormant}`.trim(),delete c.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Pe(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Vi(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Iu(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=$u(n.ops),i=o.filter((s)=>Di(s,e,null)),a=i.length<=1?i:i.filter((s)=>Di(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#A())on(this,e);return}for(let s of a){if(s.outside&&e[ce])continue;if(!Pu(s,e))continue;let c=s.within==null?r:this.#se(s.within,e);if(s.within!=null&&!c)continue;if(s.shortcut!=null&&!Pe(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(Du(this,e,s))continue;this.#ae(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0,prevent:void 0}:s,e,c,o.indexOf(s),r)}}#se(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}#ae(e,t,n,r,o=n){let{ops:i,confirm:a,confirmWhen:s,outside:c,window:u,shortcut:l,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(l!=null||!u&&f!==!1)zn(t,l);let d=this.#q(a,s),p=this.#ce(e,r,o,()=>this.#ke(this.#_e(i),n));if(!d)return p();if(d instanceof Promise)return d.then((g)=>g?this.#b(g,n,p):p());this.#b(d,n,p)}#ce(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let a=JSON.stringify([t,e]);if(o>0)return()=>this.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return St(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return dt(this,this.#e(),e)}tagsPick(e){return pt(this,this.#e(),e)}tagsRemove(e){return ht(this,this.#e(),e)}nestedAdd(e){return mt(this,this.#e(),e)}nestedRemove(e){return gt(this,this.#e(),e)}syncNestedJson(e){return rt(this,this.#e(),e)}#Ge(e,t){}trackDirty(){ve(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.#ue(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ue(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#H();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#T(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#z(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#le(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#de(e,u,t,n,i,a);return this.#y(t,n,i,e,a)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#Te(e,r,i),s=Boolean(n||o),c=(d)=>{if(!s||!d)return;let p=this.#e();if(i.inverse=cn(this,p,n,r),i.undo.push(...an(this,p,o,r)),this.#O())i.resurrect=un(this,p,n,r)},u=!0;c(!0);let l=()=>this.#be(e,t,i,a),f=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Ue(){return this.#re("hints")}#le(e,t,n,r,o,i){this.#W(e,tl,t,()=>this.#y(n,r,o,e,i))}#W(e,t,n,r){this.#R(e,t);let o=()=>{this.#R(e,t),r()},i=setTimeout(o,n);if(!mr(e))e?.addEventListener?.("blur",o,{once:!0});let a=this.#d.get(e);if(!a)this.#d.set(e,a=new Map);a.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)}#fe(){for(let[e,t]of[...this.#d])for(let n of[...t.keys()])this.#R(e,n)}#de(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#y(n,r,o,e,i))}#j(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()}#pe(){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)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#he(){this.element?.removeAttribute?.("data-reactive-error")}#me(){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))}#ge(){return Qt()}#O(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#be(e,t,n,r){let{fields:o,files:i}=this.#U(),a=this.#z(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#Ee(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#O()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#ge();try{if(navigator.onLine===!1){this.#l(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let d;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Fe()};if(!u)h["Content-Type"]="application/json";let m=this.#Me();if(m)h["X-Pgbus-Connection"]=m;let w=Wi(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(w)h["X-Reactive-Presence"]=w;let A=fu(this.element);if(A)h["X-Reactive-Held"]=A;ls("action"),d=await fetch(this.#Le(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Ne())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#l(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#me(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#l(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:d.status});return}if(!d.ok){let h=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,h),this.#l(n.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let m=this.#J(h);if(this.#c=m??this.#c,f)we(f,h,m);Oi(this.element,h,!0)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:d.status,body:h});return}let p=d.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#l(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:d.status});return}let g=await d.text(),v=this.#J(g);if(this.#c=v??this.#c,f)we(f,g,v);if(Oi(this.element,g,du(d)),n.resurrect)queueMicrotask(n.resurrect);return this.#he(),this.#s("reactive:applied",{action:e,params:s,html:g}),g}catch(d){console.error("[phlex-reactive] action error",d),this.#l(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),f)sn(this,{...f,ms:this.#B()-f.started})}}get#c(){return this.#g??this.tokenValue}set#c(e){this.#g=e}tokenValueChanged(){this.#g=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ve(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}#ve(e){let t=this.#M;if(t&&t.id===e)return t;let n=bu(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#u(e){return e.closest('[data-controller~="reactive"]')===this.element}#H(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#u(t)}#ye(){let e=this.element.querySelectorAll(H);if(e.length===0||[...e].every(rr))return()=>!0;return(t)=>{let n=re(t,H,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&re(n.parentElement,H,this.element)===this.element}}#G(e){if(this.#u(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=re(e,H,this.element);return t===this.element||re(t?.parentElement,H,this.element)===this.element}#we(){if(this.element.querySelectorAll(H).length===0)return()=>!0;return(e)=>this.#G(e)}#U(){let e={},t=[],n=this.#ye(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${Su}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#Ae(r),a=this.#Se(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?I(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!xu(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#Ae(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}#Se(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Ee(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#w(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#L(o,this.#w(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#xe(r);for(let{name:s,file:c,multiple:u}of r){let f=u||a.has(s)?`${this.#w(s)}[]`:this.#w(s);o.append(f,c,c.name)}return o}#w(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#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))}#xe(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))}#z(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#_e(e){return pr(e)}#ke(e,t){tr(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;rn(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()}#Te(e,t,n){this.#Re(e,t),ss();let r=!1;return()=>{if(r)return;r=!0,this.#Oe(e,t),as();for(let o of n.undo)o()}}#Re(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.#V(e))this.#f(n,e,1)}#Oe(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.#V(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(" "))}#V(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#u(n))}#Le(){return this.#Y??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Ne(){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)Fi();else document.addEventListener("turbo:load",Fi,{once:!0});lr();var Tl=vs;export{is as ACTIVE_ATTR,Su as EDITOR_SELECTOR,Eu as EDITOR_TAGS,ic as LATENCY_KEY,us as REQUESTS_ATTR,vu as checkReactiveRegistration,ls as countReactiveRequest,Tl as default,vo as disableLatencySim,I as editableValue,bo as enableLatencySim,ss as enterReactiveActivity,bu as escapeRegExp,as as exitReactiveActivity,bl as loadReactiveFeature,dl as onReactiveStreamWithoutEffects,pl as reactiveActivityCount,vl as reactiveFeatureNames,Fi as registerReactiveActions,Zc as registerReactiveDefer,lr as registerReactiveDev,eu as registerReactiveDismiss,eu as registerReactiveEffects,Xu as registerReactiveFeature,ml as registerReactiveFeatureLoader,su as registerReactiveImageFallback,Xc as registerReactiveJs,iu as registerReactiveKeep,ou as registerReactiveModals,cu as registerReactiveMorphFocus,hu as registerReactiveOffline,au as registerReactivePlaintext,eu as registerReactiveStreamRender,Vc as registerReactiveToken,Kc as registerReactiveVisit,hl as resetReactiveActivity,dr as serverText,gl as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=446FA6AB61B1EBC064756E2164756E21
|
|
9
9
|
//# sourceMappingURL=reactive_controller.min.js.map
|