@chaibuilder/sdk 0.1.12 → 0.1.13

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.
Files changed (57) hide show
  1. package/dist/{AddBlocks-73aa52ed.js → AddBlocks-598b655e.js} +1 -1
  2. package/dist/{AddBlocks-eafcb8ab.cjs → AddBlocks-5df8b221.cjs} +1 -1
  3. package/dist/{BrandingOptions-6e8c6721.js → BrandingOptions-0acb0974.js} +1 -1
  4. package/dist/{BrandingOptions-45caece9.cjs → BrandingOptions-2795be29.cjs} +1 -1
  5. package/dist/{CanvasArea-3049f560.js → CanvasArea-73b0ec3b.js} +2 -2
  6. package/dist/{CanvasArea-a392ffc1.cjs → CanvasArea-a637ef3a.cjs} +2 -2
  7. package/dist/{CurrentPage-3d3209a1.js → CurrentPage-3a189b02.js} +1 -1
  8. package/dist/{CurrentPage-def95a2d.cjs → CurrentPage-77baf305.cjs} +1 -1
  9. package/dist/ImagesPanel-68a11293.cjs +1 -0
  10. package/dist/ImagesPanel-996761b1.js +27 -0
  11. package/dist/{Layers-23512777.js → Layers-42ba6c2e.js} +2 -2
  12. package/dist/{Layers-3bdb61c3.cjs → Layers-7f3a2335.cjs} +1 -1
  13. package/dist/{MarkAsGlobalBlock-37ae563e.js → MarkAsGlobalBlock-3e708ff4.js} +1 -1
  14. package/dist/{MarkAsGlobalBlock-d10b749d.cjs → MarkAsGlobalBlock-c18910cc.cjs} +1 -1
  15. package/dist/{PagesPanel-a0cb2a3c.js → PagesPanel-86323919.js} +2 -2
  16. package/dist/{PagesPanel-2e626ee0.cjs → PagesPanel-dfbcc68b.cjs} +1 -1
  17. package/dist/{ProjectPanel-453caab3.cjs → ProjectPanel-4be28a35.cjs} +1 -1
  18. package/dist/{ProjectPanel-590ad7b5.js → ProjectPanel-9f645945.js} +2 -2
  19. package/dist/{Settings-201df828.js → Settings-57f2a7c2.js} +3 -3
  20. package/dist/{Settings-3f024a5e.cjs → Settings-99916fc1.cjs} +1 -1
  21. package/dist/{SidePanels-2d310a73.cjs → SidePanels-0e4ab159.cjs} +1 -1
  22. package/dist/{SidePanels-2135b1a7.js → SidePanels-b0347e28.js} +2 -2
  23. package/dist/{Topbar-f722a517.cjs → Topbar-44c010e3.cjs} +1 -1
  24. package/dist/{Topbar-4e436076.js → Topbar-87c1c5b2.js} +1 -1
  25. package/dist/UnsplashImages-47374e0c.js +181 -0
  26. package/dist/UnsplashImages-f761ad96.cjs +1 -0
  27. package/dist/{add-page-modal-e38900bd.js → add-page-modal-71c100f9.js} +4 -4
  28. package/dist/{add-page-modal-17cd6043.cjs → add-page-modal-b4e12262.cjs} +1 -1
  29. package/dist/core.cjs +1 -1
  30. package/dist/core.d.ts +2 -0
  31. package/dist/core.js +1 -1
  32. package/dist/{delete-page-modal-69202329.js → delete-page-modal-9dbe3038.js} +1 -1
  33. package/dist/{delete-page-modal-7e833472.cjs → delete-page-modal-fe71e66d.cjs} +1 -1
  34. package/dist/{form-e9748a4e.cjs → form-5d04c9b3.cjs} +1 -1
  35. package/dist/{form-52b48fbc.js → form-bf09d392.js} +1 -1
  36. package/dist/{index-9ba9f277.js → index-0d399aef.js} +277 -276
  37. package/dist/{index-4462d894.cjs → index-d4a18b5d.cjs} +2 -2
  38. package/dist/{link-26d3158f.cjs → link-4585b2d6.cjs} +1 -1
  39. package/dist/{link-eeef0a29.js → link-6467eda6.js} +1 -1
  40. package/dist/{page-viewer-ddaba8df.js → page-viewer-8a0cd017.js} +2 -2
  41. package/dist/{page-viewer-2fb5485c.cjs → page-viewer-eec3bdfb.cjs} +1 -1
  42. package/dist/{project-general-setting-fc4ea1f6.cjs → project-general-setting-12172508.cjs} +1 -1
  43. package/dist/{project-general-setting-5810b457.js → project-general-setting-155bc3fc.js} +4 -4
  44. package/dist/{project-seo-setting-b3372d3f.cjs → project-seo-setting-3f645a02.cjs} +1 -1
  45. package/dist/{project-seo-setting-23fb5e80.js → project-seo-setting-e9587467.js} +3 -3
  46. package/dist/server.cjs +1 -1
  47. package/dist/server.d.ts +17 -17
  48. package/dist/server.js +33 -33
  49. package/dist/{single-page-detail-128a33a7.cjs → single-page-detail-1b3195d1.cjs} +1 -1
  50. package/dist/{single-page-detail-359a0806.js → single-page-detail-fb0fe01b.js} +5 -5
  51. package/dist/ui.cjs +1 -1
  52. package/dist/ui.js +2 -2
  53. package/package.json +1 -1
  54. package/dist/ImagesPanel-36a2f276.js +0 -27
  55. package/dist/ImagesPanel-731cda7a.cjs +0 -1
  56. package/dist/UnsplashImages-68492dc9.cjs +0 -1
  57. package/dist/UnsplashImages-afaa7706.js +0 -151
@@ -1,2 +1,2 @@
1
- "use strict";var Gs=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)};var a=(e,t,s)=>(Gs(e,t,"read from private field"),s?s.call(e):t.get(e)),L=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},P=(e,t,s,n)=>(Gs(e,t,"write to private field"),n?n.call(e,s):t.set(e,s),s);var vs=(e,t,s,n)=>({set _(r){P(e,t,r,s)},get _(){return a(e,t,n)}}),K=(e,t,s)=>(Gs(e,t,"access private method"),s);const _=require("./jsx-runtime-5c3ac4f7.cjs"),ki=require("i18next"),Ai=require("react-i18next"),Pi=require("flagged"),B=require("react"),Oi=require("react-dnd"),l=require("lodash"),zn=require("@minoru/react-dnd-treeview"),be=require("./useBuilderProp-5e57d0c8.cjs"),y=require("jotai"),ji=require("./utils-3c452dd0.cjs"),Le=require("react-hotkeys-hook"),Wr=require("flat-to-nested"),le=require("./html-to-json-78bfa1f3.cjs"),Ht=require("redux-undo"),Ci=require("@react-hookz/web"),ue=require("./MODIFIERS-70fef873.cjs"),Jr=require("@chaibuilder/blocks"),Cs=require("@radix-ui/react-icons"),_i=require("lucide-react"),_e=require("sonner");function Bi(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const re=Bi(B),Ii="Dark mode",Ri="This page has no blocks. Add a block by clicking the + button",Di="This page is empty",Mi="Please select a block to edit settings or styles",Li="Please select a styling block",Ni="Drop your block here",Ti={dark_mode:Ii,tree_view_no_blocks:Ri,canvas_empty:Di,no_block_selected_for_styling:Mi,no_styling_block_selected:Li,drop_here_message:Ni};ki.use(Ai.initReactI18next).init({resources:{en:{translation:Ti}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});const Ui="";const Fi={};class Yr extends B.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(t){return console.error(t),{hasError:!0}}render(){return this.state.hasError?_.jsxRuntimeExports.jsx("h1",{children:"Something went wrong."}):this.props.children}}const qi=e=>{const t=e.replace(ue.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}};let $i=0;function Ue(e,t){const s=`atom${++$i}`,n={toString:()=>s};return typeof e=="function"?n.read=e:(n.init=e,n.read=r=>r(n),n.write=(r,o,i)=>o(n,typeof i=="function"?i(r(n)):i)),t&&(n.write=t),n}const Hn=e=>"init"in e,Gn=e=>!!e.write,_s=new WeakMap,Vi=(e,t)=>{_s.set(e,t),e.catch(()=>{}).finally(()=>_s.delete(e))},Wn=(e,t)=>{const s=_s.get(e);s&&(_s.delete(e),s(t))},Jn=(e,t)=>{e.status="fulfilled",e.value=t},Yn=(e,t)=>{e.status="rejected",e.reason=t},Qi=e=>typeof(e==null?void 0:e.then)=="function",Qt=(e,t)=>"v"in e&&"v"in t&&Object.is(e.v,t.v),Xn=(e,t)=>"e"in e&&"e"in t&&Object.is(e.e,t.e),ft=e=>"v"in e&&e.v instanceof Promise,Ki=(e,t)=>"v"in e&&"v"in t&&e.v.orig&&e.v.orig===t.v.orig,bs=e=>{if("e"in e)throw e.e;return e.v},zi=()=>{const e=new WeakMap,t=new WeakMap,s=new Map;let n,r,o;const i=g=>e.get(g),u=(g,x)=>{const D=e.get(g);if(e.set(g,x),s.has(g)||s.set(g,D),D&&ft(D)){const S="v"in x?x.v instanceof Promise?x.v:Promise.resolve(x.v):Promise.reject(x.e);Wn(D.v,S)}},d=(g,x,D)=>{const S=new Map;let N=!1;D.forEach((j,E)=>{!j&&E===g&&(j=x),j&&(S.set(E,j),x.d.get(E)!==j&&(N=!0))}),(N||x.d.size!==S.size)&&(x.d=S)},c=(g,x,D)=>{const S=i(g),N={d:(S==null?void 0:S.d)||new Map,v:x};if(D&&d(g,N,D),S&&Qt(S,N)&&S.d===N.d)return S;if(S&&ft(S)&&ft(N)&&Ki(S,N)){if(S.d===N.d)return S;N.v=S.v}return u(g,N),N},h=(g,x,D,S)=>{if(Qi(x)){let N;const j=new Promise((E,z)=>{let Q=!1;x.then(W=>{if(!Q){Q=!0;const f=i(g),p=c(g,j,D);Jn(j,W),E(W),(f==null?void 0:f.d)!==p.d&&q(g,p,f==null?void 0:f.d)}},W=>{if(!Q){Q=!0;const f=i(g),p=c(g,j,D);Yn(j,W),z(W),(f==null?void 0:f.d)!==p.d&&q(g,p,f==null?void 0:f.d)}}),N=W=>{Q||(Q=!0,W.then(f=>Jn(j,f),f=>Yn(j,f)),E(W))}});return j.orig=x,j.status="pending",Vi(j,E=>{E&&N(E),S==null||S()}),c(g,j,D)}return c(g,x,D)},m=(g,x,D)=>{const S=i(g),N={d:(S==null?void 0:S.d)||new Map,e:x};return D&&d(g,N,D),S&&Xn(S,N)&&S.d===N.d?S:(u(g,N),N)},k=g=>{const x=i(g);if(x&&(x.d.forEach((Q,W)=>{W!==g&&!t.has(W)&&k(W)}),Array.from(x.d).every(([Q,W])=>{const f=i(Q);return Q===g||f===W||f&&!ft(f)&&Qt(f,W)})))return x;const D=new Map;let S=!0;const N=Q=>{if(Q===g){const f=i(Q);if(f)return D.set(Q,f),bs(f);if(Hn(Q))return D.set(Q,void 0),Q.init;throw new Error("no atom init")}const W=k(Q);return D.set(Q,W),bs(W)};let j,E;const z={get signal(){return j||(j=new AbortController),j.signal},get setSelf(){return!E&&Gn(g)&&(E=(...Q)=>{if(!S)return M(g,...Q)}),E}};try{const Q=g.read(N,z);return h(g,Q,D,()=>j==null?void 0:j.abort())}catch(Q){return m(g,Q,D)}finally{S=!1}},v=g=>bs(k(g)),C=g=>{let x=t.get(g);return x||(x=w(g)),x},I=(g,x)=>!x.l.size&&(!x.t.size||x.t.size===1&&x.t.has(g)),b=g=>{const x=t.get(g);x&&I(g,x)&&A(g)},O=g=>{const x=new Map,D=new WeakMap,S=j=>{const E=t.get(j);E==null||E.t.forEach(z=>{z!==j&&(x.set(z,(x.get(z)||new Set).add(j)),D.set(z,(D.get(z)||0)+1),S(z))})};S(g);const N=j=>{const E=t.get(j);E==null||E.t.forEach(z=>{var Q;if(z!==j){let W=D.get(z);if(W&&D.set(z,--W),!W){let f=!!((Q=x.get(z))!=null&&Q.size);if(f){const p=i(z),U=k(z);f=!p||!Qt(p,U)}f||x.forEach(p=>p.delete(z))}N(z)}})};N(g)},R=(g,...x)=>{let D=!0;const S=E=>bs(k(E)),N=(E,...z)=>{let Q;if(E===g){if(!Hn(E))throw new Error("atom not writable");const W=i(E),f=h(E,z[0]);(!W||!Qt(W,f))&&O(E)}else Q=R(E,...z);if(!D){const W=F()}return Q},j=g.write(S,N,...x);return D=!1,j},M=(g,...x)=>{const D=R(g,...x),S=F();return D},w=(g,x)=>{const D={t:new Set(x&&[x]),l:new Set};if(t.set(g,D),k(g).d.forEach((S,N)=>{const j=t.get(N);j?j.t.add(g):N!==g&&w(N,g)}),k(g),Gn(g)&&g.onMount){const S=g.onMount((...N)=>M(g,...N));S&&(D.u=S)}return D},A=g=>{var x;const D=(x=t.get(g))==null?void 0:x.u;D&&D(),t.delete(g);const S=i(g);S&&(ft(S)&&Wn(S.v),S.d.forEach((N,j)=>{if(j!==g){const E=t.get(j);E&&(E.t.delete(g),I(j,E)&&A(j))}}))},q=(g,x,D)=>{const S=new Set(x.d.keys());D==null||D.forEach((N,j)=>{if(S.has(j)){S.delete(j);return}const E=t.get(j);E&&(E.t.delete(g),I(j,E)&&A(j))}),S.forEach(N=>{const j=t.get(N);j?j.t.add(g):t.has(g)&&w(N,g)})},F=()=>{let g;for(;s.size;){const x=Array.from(s);s.clear(),x.forEach(([D,S])=>{const N=i(D);if(N){N.d!==(S==null?void 0:S.d)&&q(D,N,S==null?void 0:S.d);const j=t.get(D);j&&!(S&&!ft(S)&&(Qt(S,N)||Xn(S,N)))&&j.l.forEach(E=>E())}})}};return{get:v,set:M,sub:(g,x)=>{const D=C(g),S=F(),N=D.l;return N.add(x),()=>{N.delete(x),b(g)}}}};let Ws;const Hi=()=>(Ws||(Ws=zi()),Ws),Gi=Symbol();function Wi(e,t){const s=Ue(e,(n,r,o)=>r(s,t(n(s),o)));return s}const Zn=(e,t,s)=>(t.has(s)?t:t.set(s,e())).get(s),Ji=new WeakMap,Yi=(e,t,s)=>{const n=Zn(()=>new WeakMap,Ji,t);return Zn(e,n,s)},Xi={},er=e=>!!e.write,Zi=e=>typeof e=="function";function ea(e,t){return Yi(()=>{const s=new WeakMap,n=(i,u)=>{let d=s.get(i);if(d)return d;const c=u&&s.get(u),h=[],m=[];return i.forEach((k,v)=>{const C=t?t(k):v;m[v]=C;const I=c&&c.atomList[c.keyList.indexOf(C)];if(I){h[v]=I;return}const b=R=>{const M=R(r),w=R(e),q=n(w,M==null?void 0:M.arr).keyList.indexOf(C);if(q<0||q>=w.length){const F=i[n(i).keyList.indexOf(C)];if(F)return F;throw new Error("splitAtom: index out of bounds for read")}return w[q]},O=(R,M,w)=>{const A=R(r),q=R(e),T=n(q,A==null?void 0:A.arr).keyList.indexOf(C);if(T<0||T>=q.length)throw new Error("splitAtom: index out of bounds for write");const g=Zi(w)?w(q[T]):w;M(e,[...q.slice(0,T),g,...q.slice(T+1)])};h[v]=er(e)?Ue(b,O):Ue(b)}),c&&c.keyList.length===m.length&&c.keyList.every((k,v)=>k===m[v])?d=c:d={arr:i,atomList:h,keyList:m},s.set(i,d),d},r=Ue(i=>{const u=i(r),d=i(e);return n(d,u==null?void 0:u.arr)});r.init=void 0;const o=er(e)?Ue(i=>i(r).atomList,(i,u,d)=>{switch(d.type){case"remove":{const c=i(o).indexOf(d.atom);if(c>=0){const h=i(e);u(e,[...h.slice(0,c),...h.slice(c+1)])}break}case"insert":{const c=d.before?i(o).indexOf(d.before):i(o).length;if(c>=0){const h=i(e);u(e,[...h.slice(0,c),d.value,...h.slice(c)])}break}case"move":{const c=i(o).indexOf(d.atom),h=d.before?i(o).indexOf(d.before):i(o).length;if(c>=0&&h>=0){const m=i(e);c<h?u(e,[...m.slice(0,c),...m.slice(c+1,h),m[c],...m.slice(h)]):u(e,[...m.slice(0,h),m[c],...m.slice(h,c),...m.slice(c+1)])}break}}}):Ue(i=>i(r).atomList);return o},e,t||Xi)}const ta=e=>typeof(e==null?void 0:e.then)=="function";function sa(e){let t,s;const n={getItem:(r,o)=>{var i,u;const d=h=>{if(h=h||"",t!==h){try{s=JSON.parse(h)}catch{return o}t=h}return s},c=(u=(i=e())==null?void 0:i.getItem(r))!=null?u:null;return ta(c)?c.then(d):d(c)},setItem:(r,o)=>{var i;return(i=e())==null?void 0:i.setItem(r,JSON.stringify(o))},removeItem:r=>{var o;return(o=e())==null?void 0:o.removeItem(r)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&(n.subscribe=(r,o,i)=>{if(!(e()instanceof window.Storage))return()=>{};const u=d=>{if(d.storageArea===e()&&d.key===r){let c;try{c=JSON.parse(d.newValue||"")}catch{c=i}o(c)}};return window.addEventListener("storage",u),()=>{window.removeEventListener("storage",u)}}),n}const na=sa(()=>typeof window<"u"?window.localStorage:void 0);function dt(e,t,s=na,n){const r=n==null?void 0:n.unstable_getOnInit,o=Ue(r?s.getItem(e,t):t);return o.onMount=u=>{r||u(s.getItem(e,t));let d;return s.subscribe&&(d=s.subscribe(e,u,t)),d},Ue(u=>u(o),(u,d,c)=>{const h=typeof c=="function"?c(u(o)):c;return h===Gi?(d(o,t),s.removeItem(e)):h instanceof Promise?h.then(m=>(d(o,m),s.setItem(e,m))):(d(o,h),s.setItem(e,h))})}const ra=B.createContext(void 0),Xr=e=>{const t=B.useContext(ra);return(e==null?void 0:e.store)||t||Hi()},oa=e=>typeof(e==null?void 0:e.then)=="function",ia=B.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)});function aa(e,t){const s=Xr(t),[[n,r,o],i]=B.useReducer(c=>{const h=s.get(e);return Object.is(c[0],h)&&c[1]===s&&c[2]===e?c:[h,s,e]},void 0,()=>[s.get(e),s,e]);let u=n;(r!==s||o!==e)&&(i(),u=s.get(e));const d=t==null?void 0:t.delay;return B.useEffect(()=>{const c=s.sub(e,()=>{if(typeof d=="number"){setTimeout(i,d);return}i()});return i(),c},[s,e,d]),B.useDebugValue(u),oa(u)?ia(u):u}function ua(e,t){const s=Xr(t);return B.useCallback((...r)=>s.set(e,...r),[s,e])}function ca(e,t){return[aa(e,t),ua(e,t)]}const la=new Wr({children:"blockNodes"}),Zr=(e,t=null)=>l.flatten(e.map(s=>{if(s=t!==null?{...s,parent:t}:s,s.children&&s.children.length){const n=[...s.children];return delete s.children,l.flatten([s,...Zr(n,s._id)])}return s}));function eo(e,t,s){const n=l.filter(e,o=>o._parent===t),r=[];for(let o=0;o<n.length;o++){const i=to(n[o]);if(Object.keys(i).length>0&&Object.keys(i).forEach(u=>{n[o][u]=`slot:${le.generateUUID()}`}),l.filter(e,{_parent:n[o]._id}).length>0){const u=le.generateUUID();r.push({...n[o],oldId:n[o]._id,_id:u,_parent:s}),r.push(l.flatten(eo(e,n[o]._id,u)))}else r.push({...n[o],oldId:n[o]._id,_id:le.generateUUID(),_parent:s})}return l.flatten(r)}function da(e){let t=la.convert(e.map(s=>l.omit(s,["settings"])));return t=!t.type&&t.blockNodes?t.blockNodes:l.isEmpty(t)?[]:[t],t}const to=e=>{const t={};return Object.keys(e).forEach(s=>{l.isString(e[s])&&e[s].startsWith("slot")&&(t[s]=e[s].replace("slot:",""))}),t},fa=(e,t,s=null)=>{let n=l.find(e,{_id:t});n={...n,oldId:n._id,_id:le.generateUUID()},s&&(n={...n,_parent:s});const r=[n];l.filter(e,{_parent:t}).length>0&&r.push(l.flatten(eo(e,t,n._id)));const o=l.flatten(r);return l.map(o,i=>{const u=i,d=to(u);return Object.keys(d).length>0&&Object.keys(d).forEach(c=>{const h=l.find(o,{oldId:d[c].replace("slot:","")});u[c]=`slot:${h._id}`}),l.omit(u,["global","oldId"])})},ha=Ht((e=[],t)=>{switch(t.type){case"add_new_blocks":case"add_duplicate_blocks":return[...e,...t.payload];case"create_snapshot":return[...e];case"set_blocks":case"set_page_blocks":return[...t.payload];case"update_props":case"update_props_realtime":const{payload:s}=t;return e.map(n=>(s.ids.includes(n._id)&&!l.isEmpty(t.payload.props)&&Object.keys(t.payload.props).forEach(r=>{l.set(n,r,t.payload.props[r])}),n));default:return e}},{debug:!1,ignoreInitialState:!1,limit:30,filter:Ht.excludeAction(["update_props_realtime","add_duplicate_blocks","set_page_blocks"])}),Ns=Wi({past:[],present:[],future:[]},ha);Ns.debugLabel="pageBlocksAtom";const xe=y.atom(e=>{var t;return(t=e(Ns))==null?void 0:t.present});xe.debugLabel="presentBlocksAtom";const wn=ea(xe);wn.debugLabel="pageBlocksAtomsAtom";const so=y.atom(e=>da(e(xe)));so.debugLabel="pageBlocksTreeAtom";const pa=y.atom("");pa.debugLabel="builderActivePageAtom";const ma=y.atom(-1);ma.debugLabel="destinationDropIndexAtom";const no=y.atom(!1);no.debugLabel="addBlocksModalAtom";const we=()=>{const[,e]=y.useAtom(Ns);return e},ga=()=>{const e=we(),t=y.useAtomValue(so),s=B.useCallback(n=>{const r=Zr(n);e({type:"set_page_blocks",payload:r})},[e]);return[t,s]},ro=()=>{const e=we();return[B.useCallback(s=>{e({type:"set_page_blocks",payload:s})},[e])]},tn=e=>["Box","Slot","Form","DataContext","Link","List","ListItem","Row","Column","Table","TableCell"].includes(e),ya=e=>!["Slot"].includes(e),va=e=>!["Slot"].includes(e);function ba(e,t){return e==="Slot"||t==="List"&&e!=="ListItem"||t==="Row"&&e!=="Column"?!1:tn(t)}const xa=(e,{dragSource:t,dropTarget:s})=>{const n=l.get(t,"data._type",""),r=l.get(s,"data._type","");return n==="Slot"||l.get(t,"id")&&l.get(t,"id")===l.get(s,"id")?!1:l.isEmpty(r)?!0:ba(n,r)},Sn=y.atom([]);Sn.debugLabel="selectedBlockIdsAtom";const En=y.atom(e=>{const t=e(xe),s=e(Sn);return l.map(l.filter(t,({_id:n})=>l.includes(s,n)),n=>({...n}))});En.debugLabel="selectedBlocksAtom";const kn=y.atom(e=>{const t=e(En);return t.length===0?null:t.length===1?t[0]:{type:"Multiple",id:l.map(t,"id")}});kn.debugLabel="selectedBlockAtom";const wa=e=>l.get(e,"parent",null),Sa=y.atom(e=>{const t=e(En),s=l.map(t,wa);return l.filter(e(xe),n=>l.includes(s,n._id))});Sa.debugLabel="selectedBlocksParentsAtom";const oo=y.atom(()=>!1);oo.debugLabel="selectedBlockFlexChildAtom";const io=y.atom(()=>!1);io.debugLabel="selectedBlockGridChildAtom";const An=y.atom("");An.debugLabel="styleStateAtom";const ao=dt("styleBreakpoint","xs");ao.debugLabel="styleBreakpointAtom";const Ea=()=>({flexChild:y.useAtomValue(oo),gridChild:y.useAtomValue(io)}),ka=()=>y.useAtomValue(kn),Je=()=>{const[e,t]=y.useAtom(Sn),s=B.useCallback(n=>{t(r=>l.includes(r,n)?l.without(r,n):[...r,n])},[t]);return[e,t,s]},sn=(e,t="")=>{switch(e.type){case"singular":return e.uiSchema;case"model":const{properties:s}=e,n={};return Object.keys(s).forEach(i=>{const u=s[i];if(l.includes(["slot","styles"],u.type))return;const d=l.get(u,"i18n",!1)?`${i}-${t}`:i;n[d]=sn(u,t)}),n;case"list":const{itemProperties:r}=e,o={items:{}};return Object.keys(r).forEach(i=>{const u=r[i];if(l.includes(["slot","styles"],u.type))return;const d=l.get(u,"i18n",!1)?`${i}-${t}`:i;o.items[d]=sn(u,t)}),o;default:return{}}},nn=(e,t="")=>{switch(e.type){case"singular":return e.schema;case"model":const{properties:s,title:n}=e,r={title:n,type:"object",properties:{}};return Object.keys(s).forEach(d=>{const c=s[d];if(l.includes(["slot","styles"],c.type))return;const h=l.get(c,"i18n",!1)?`${d}-${t}`:d;r.properties[h]=nn(c,t)}),r;case"list":const{itemProperties:o,title:i}=e,u={title:i,type:"array",items:{type:"object",properties:{}}};return Object.keys(o).forEach(d=>{const c=o[d];if(l.includes(["slot","styles"],c.type))return;const h=l.get(c,"i18n",!1)?`${d}-${t}`:d;u.items.properties[h]=nn(c,t),l.set(u.items,"title",l.get(c,"itemTitle",`${i} item`))}),u;default:return{}}},uo=e=>{const t={};return Object.keys(e).forEach(s=>{t[s]=Pa(e[s])}),t},Aa=e=>{if(l.isEmpty(e.default))return[];const{itemProperties:t}=e;return l.map(e.default,s=>{const n={...s};return l.forIn(s,(r,o)=>{l.has(t,o)&&l.get(t[o],"i18n",!1)&&(n[o]=ue.I18N_KEY)}),n})},Pa=e=>{switch(e.type){case"styles":return e.default;case"slot":return`${ue.SLOT_KEY}${le.generateUUID()}`;case"singular":const{i18n:t,schema:s}=e;return t?ue.I18N_KEY:l.get(s,"default","");case"model":return uo(e.properties);case"list":return Aa(e);default:return""}},co=()=>y.useAtomValue(xe);function tr(e,t,s,n,r){if(t===null)return[...e,...n];if(s!==null){const d=l.findIndex(e,{_parent:t}),c=(d===-1?0:d)+s;return e.splice(c,0,...n),e}if(!r){const c=l.findIndex(e,{_id:t})+1;return e.splice(c,0,...n),e}let o=l.findIndex(e,{_id:t});const i=l.filter(e,{_parent:t});l.isEmpty(i)||(o=l.findIndex(e,{_id:l.last(i)._id}));const u=o+1;return e.splice(u,0,...n),e}const Oa=()=>{const e=we(),t=co(),[,s]=Je(),n=B.useCallback((o,i,u)=>{var h;for(let m=0;m<o.length;m++){const{_id:k}=o[m];o[m]._id=le.generateUUID();const v=l.filter(o,{_parent:k});for(let C=0;C<v.length;C++)v[C]._parent=o[m]._id}let d;i&&(d=l.find(t,{_id:i}),o[0]._parent=i);const c=d?tn(d._type):!0;return!c&&d&&(o[0]._parent=d._parent),e({type:"set_blocks",payload:tr(t,i||null,u||null,o,c)}),s([(h=l.first(o))==null?void 0:h._id]),l.first(o)},[t,e,s]);return{addCoreBlock:B.useCallback((o,i,u)=>{if(l.has(o,"blocks")){const I=o.blocks;return n(I,i,u)}const d=le.generateUUID(),c=uo(o.props),h=[];l.forIn(c,(I,b)=>{if(l.startsWith(I,ue.SLOT_KEY)){const O=I.replace(ue.SLOT_KEY,"");h.push({_id:O,_type:"Slot",_parent:d,_name:o.props[b].name,_styles:o.props[b].styles,_emptyStyles:o.props[b].emptyStyles})}});const m={_type:o.type,_id:d,...c};let k;i&&(k=l.find(t,{_id:i}),m._parent=i);const v=k?tn(k._type):!0;!v&&k&&(m._parent=k._parent);const C=[m,...h];return e({type:"set_blocks",payload:tr(t,i||null,u||null,C,v)}),s([m._id]),m},[n,t,e,s]),addPredefinedBlock:n}},sr={xs:420,sm:620,md:768,lg:1024,xl:1280,"2xl":1536},nr=["xs","sm","md","lg","xl","2xl"];function ja(e,t){if(t===null)return"baseClasses";const s=t.mq;if(s==="xs"||t.dark||t.mod!=="")return"classes";let n="baseClasses",r=nr.indexOf(s);for(;r>0;){const o=nr[r-1];if(l.find(e,{mq:o,property:t.property})){n="classes";break}r--}return n}const rr=[];function Ca(e="",t="",s=[]){e=e.trim().replace(/ +/g,"");let n=l.filter(l.map(e.split(" "),le.constructClassObject),c=>!l.isNull(c)),r=l.filter(l.map(t.split(" "),le.constructClassObject),c=>!l.isNull(c));r=l.filter(r,c=>!l.includes(rr,c.property));const o=[],i=[];l.each(s,c=>{const h=le.constructClassObject(c),m=l.find(n,l.pick(h,["dark","mq","mod","property"]));if(m&&(n=l.filter(n,k=>k.fullCls!==(m==null?void 0:m.fullCls))),o.push(h),h.mq==="xs"&&!h.dark&&h.mod===""&&(r=l.filter(r,k=>k.property!==h.property)),ja(n,h)==="baseClasses"&&!l.includes(rr,h.property)){const k=l.find(r,l.pick(h,["property"]));m&&(r=l.filter(r,v=>v.fullCls!==(k==null?void 0:k.fullCls))),i.push({...h,fullCls:h.cls,mq:"xs"})}});const u=l.map(l.sortBy([...n,...o],c=>sr[c.mq]),"fullCls").join(" ");return`${l.map(l.sortBy([...r,...i],c=>sr[c.mq]),"fullCls").join(" ").trim()},${u.trim()}`.trim().replace(/ +/g,"")}const hs=y.atom([]);hs.debugLabel="selectedStylingBlocksAtom";const Pn=()=>y.useAtom(hs),_a=e=>{const t=e.replace(ue.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},Ba=y.atom(null,(e,t,{blockIds:s,newClasses:n,dispatch:r})=>{const o=l.filter(e(wn),u=>s.includes(e(u)._id)),i=l.first(e(hs));l.each(o,u=>{const d=e(u),c=l.get(d,i.prop,`${ue.STYLES_KEY},`),{baseClasses:h,classes:m}=_a(c);r({type:"update_props_realtime",payload:{ids:[d._id],props:{[i.prop]:`${ue.STYLES_KEY}${Ca(m,h,n)}`}}})})}),Ia=()=>{const e=we(),t=y.useSetAtom(Ba);return B.useCallback((s,n,r)=>{t({blockIds:s,newClasses:n,dispatch:e}),r&&setTimeout(()=>e({type:"create_snapshot"}),500)},[e,t])},lo=y.atom([]);lo.debugLabel="buildingBlocksAtom";const Ra=y.atom(e=>{const t=e(lo);return l.filter(t,s=>l.has(s,"blockId"))}),Da=()=>{},fo=()=>{const e=Jr.useChaiBlocks(),t=y.useAtomValue(Ra),s=()=>{},n=B.useCallback(()=>Da(),[]);return[e,t,s,n]},Ma=y.atom(!1),On=()=>{const[e,t]=y.useAtom(Ma);return[e,t]},La=y.atom(ue.BRANDING_OPTIONS_DEFAULTS),jn=()=>{const[e,t]=y.useAtom(La);return[l.isObject(e)?{...ue.BRANDING_OPTIONS_DEFAULTS,...e}:ue.BRANDING_OPTIONS_DEFAULTS,t]},Na=y.atom(null),ho=()=>({currentPage:y.useAtomValue(Na)}),po=new Wr({});function Ta(e){let t=po.convert(e);return t=!t.type&&t.children&&t.children.length?t.children:l.isEmpty(t)?[]:[t],t}const Cn=(e,t)=>l.flatten(e.map(s=>{if(s=t?{...s,parent:t}:{...s},s.children){const n=[...s.children];return delete s.children,l.flatten([s,...Cn(n,s._id)])}return s}));function _n(e,t=!1){for(let s=0;s<e.length;s++){const n=e[s];n.global&&!t?e[s]={type:"GlobalBlock",_parent:l.get(n,"parent",null),blockId:n.blockId,_id:n._id}:n.children&&n.children.length&&_n(n.children)}}function mo(e){let t=[],s=l.filter(e,{type:"GlobalBlock"});return s.length>0&&(s=l.map(s,go),l.each(s,n=>{t=[...t,...Ua(n)]})),t}function Ua(e){let t=[];const s=l.get(l.first(e),"parent",null);l.set(l.first(e),"parent",null);const n=[po.convert(yo(e))];_n(n,!0);let r=Cn(n,e[0]._id);return r=l.set(r,"0.parent",s),t=[...t,r,...mo(r)],t}function go(e){const t=l.find(rn,{_id:e._id});if(!t)return[];const s=[t],n=l.filter(rn,{_parent:e._id});return n.length?l.flatten([...s,...l.flatten(l.map(n,go))]):l.flatten(s)}const yo=e=>JSON.parse(JSON.stringify(e));let rn=[];function Fa(e){rn=e;const t=Ta(yo(e));_n(t);const s=Cn(t,null),n=mo(s),r={};return l.each(n,o=>l.set(r,l.first(o).blockId,o)),[s,r]}const Bn=()=>{const[e]=jn(),{currentPage:t}=ho(),s=y.useAtomValue(xe);return B.useCallback(()=>{const n=l.map(s,i=>l.omit(i,["expanded","order","title","siblings","tempClasses"])),[r=[],o=[]]=Fa(n);return{currentPage:t,blocks:r,globalBlocks:o}},[e,t,s])};dt("blockStylingActiveTab",1);y.atom([]);const vo=y.atom(!1);vo.debugLabel="readOnlyModeAtom";const bo=y.atom(!1);bo.debugLabel="inlineEditingActiveAtom";const xo=y.atom(!1);xo.debugLabel="advanceStylingOpenAtom";const wo=y.atom("online");wo.debugLabel="networkModeAtom";dt("currentUiLibrary","");const qa=y.atom(!1);qa.debugLabel="codeEditorOpenAtom";const So=y.atom(!1);So.debugLabel="editLayerNameAtom";const $a=y.atom("");$a.debugLabel="activeLanguageAtom";const Va=y.atom("");Va.debugLabel="primaryLanguageAtom";const Eo=y.atom(null);Eo.debugLabel="canvasIframeAtom";const ko=y.atom("layers");ko.debugLabel="activePanelAtom";const Ao=y.atom(!1);Ao.debugLabel="addBlockOffCanvasAtom";const Po=y.atom("");Po.debugLabel="showPredefinedBlockCategoryAtom";const Ts=y.atom({undoCount:0,redoCount:0});Ts.debugLabel="historyStatesAtom";const Us=y.atom("SAVED");Us.debugLabel="pageSyncStateAtom";const Qa=()=>{const[e,t]=y.useAtom(Us),s=be.useBuilderProp("onSaveBlocks",async()=>{}),n=be.useBuilderProp("onSyncStatusChange",()=>{}),r=Bn(),o=y.useSetAtom(Ts),{undoCount:i,redoCount:u}=ps();return{savePage:Ci.useThrottledCallback(async()=>{t("SAVING"),n("SAVING");const c=r();return await s({blocks:c.blocks,identifier:"pageData.id"}),setTimeout(()=>{o({undoCount:i,redoCount:u}),t("SAVED"),n("SAVED")},100),!0},[r,t,n,s],5e3),syncState:e,setSyncState:t}},ps=()=>{const e=y.useAtomValue(Ns),[{undoCount:t,redoCount:s}]=y.useAtom(Ts),n=we(),[r]=On(),[,o]=Je(),[,i]=Pn(),[,u]=y.useAtom(Us),d=be.useBuilderProp("onSyncStatusChange",()=>{}),c=B.useCallback(()=>{n({type:"create_snapshot"})},[n]);return B.useEffect(()=>{t!==(e==null?void 0:e.past.length)||s!==(e==null?void 0:e.future.length)?(u("UNSAVED"),d("UNSAVED")):t===(e==null?void 0:e.past.length)&&s===(e==null?void 0:e.future.length)&&(u("SAVED"),d("SAVED"))},[e==null?void 0:e.past.length,e==null?void 0:e.future.length,t,s,d,u]),{undoCount:e==null?void 0:e.past.length,redoCount:e==null?void 0:e.future.length,undo:B.useCallback(()=>{r||(n(Ht.ActionCreators.undo()),setTimeout(()=>{i([]),o([])},200))},[n,r,u]),redo:B.useCallback(()=>{r||(n(Ht.ActionCreators.redo()),setTimeout(()=>{i([]),o([])},200))},[r,n]),clear:()=>{n(Ht.ActionCreators.clearHistory())},createSnapshot:c}},Oo=()=>y.useAtom(ao),jo=dt("canvasWidth",360),Co=y.atom(e=>{const t=e(jo);return le.getBreakpointValue(t).toLowerCase()}),Ka=()=>{const[e,t]=y.useAtom(jo),s=y.useAtomValue(Co),[n,r]=Oo();return B.useEffect(()=>{n!=="xs"&&r(s)},[s,n,r]),[e,s,t]},za=dt("canvasZoom",100),Ha=()=>y.useAtom(za),_o=y.atom([]),In=()=>{const[e,t]=y.useAtom(_o),s=y.useSetAtom(Rn),n=B.useCallback(r=>{t(r),s([])},[t,s]);return[e,n]},Rn=y.atom([]),Bo=()=>{const[e,t]=y.useAtom(Rn),s=y.useSetAtom(_o),n=B.useCallback(r=>{t(r),s([])},[t,s]);return[e,n]},Io=dt("darkMode",!1),Ga=()=>{const[e,t]=y.useAtom(Io);return[e,t]},Wa=y.atom(!1),Ja=()=>{const[e,t]=y.useAtom(Wa);return[e,t]},Dn=()=>{const e=we(),t=y.useAtomValue(xe),[,s]=Je();return B.useCallback((n,r=null)=>{const o=[];l.each(n,i=>{const d=fa(t,i,r===i?null:r);o.push(l.get(d,"0._id","")),e({type:"add_duplicate_blocks",payload:d})}),s(o),e({type:"create_snapshot"})},[t,s,e])},Ya=y.atom([]),Xa=()=>{const[e,t]=y.useAtom(Ya),s=B.useCallback(n=>{t(r=>l.includes(r,n)?l.without(r,n):[...r,n])},[t]);return[e,t,s]},Za=y.atom(""),Ro=()=>y.useAtom(Za),eu=()=>{const e=y.useAtomValue(xe),t=we(),s=Bn(),[,,n]=fo();return B.useCallback(async(r,o)=>{const i=le.generateUUID(16),u=l.map(e,d=>(d._id===r&&(d._globalBlockId=i,d._name=o),d));t({type:"set_page_blocks",payload:u}),n()},[e,t,s,n])},tu=()=>({}),su=()=>{const e=y.useAtomValue(xe),t=we();return B.useCallback((s,n)=>{const r=l.map(e,o=>(l.includes(s,l.get(o,"_id"))&&l.set(o,"_parent",n),o));t({type:"set_blocks",payload:r})},[e,t])},Do=()=>{const e=y.useAtomValue(Rn),[t,s]=In(),n=Dn(),r=su();return{canPaste:B.useMemo(()=>t.length>0||e.length>0,[e,t]),pasteBlocks:B.useCallback(i=>{l.isEmpty(e)?r(t,i):n(e,i),s(()=>[])},[t,e,n,r,s])}},nu=y.atom(""),ru=()=>{const e=y.useAtomValue(nu),t=B.useCallback(()=>{},[]),s=B.useCallback(()=>{},[]),n=B.useCallback(()=>{},[]);return{currentProject:e,createProject:n,deleteProject:t,updateProject:s}},Mo=(e,t)=>{const s=[],n=l.filter(e,r=>l.includes(t,r._id)||l.includes(t,r._parent)?(s.push(r._id),!1):!0);return l.isEmpty(s)?n:Mo(n,s)},Lo=()=>{const e=we(),t=y.useAtomValue(xe),[s,n]=Je();return B.useCallback(r=>{var u;const o=((u=l.find(t,{_id:r[0]}))==null?void 0:u._parent)||null,i=Mo(t,r);e({type:"set_blocks",payload:i}),n(o?[o]:[])},[t,n,e,s])},ou=y.atom(null,(e,t,{blockIds:s,fullClasses:n,dispatch:r})=>{const o=l.first(e(hs)),i=l.filter(e(wn),u=>s.includes(e(u)._id));l.each(i,u=>{const d=e(u),c=n;let{classes:h,baseClasses:m}=qi(l.get(d,o.prop,"styles:,"));l.each(c,k=>{const v=new RegExp(`(^| )${k.replace("[","\\[").replace("]","\\]")}($| )`,"g");h=h.replace(v," ").replace(/ +/g," ").trim();const C=l.first(k.split(":"));l.includes(["2xl","xl","lg","md","sm"],C)&&c.push(k.split(":").pop().trim())}),l.each(c,k=>{const v=new RegExp(`(^| )${k.replace("[","\\[").replace("]","\\]")}($| )`,"g");m=m.replace(v," ").replace(/ +/g," ").trim()}),r({type:"update_props_realtime",payload:{ids:[d._id],props:{[o.prop]:`${ue.STYLES_KEY}${m},${h}`}}})})}),iu=()=>{const e=we(),t=y.useSetAtom(ou);return B.useCallback((s,n)=>{t({blockIds:s,fullClasses:n,dispatch:e}),setTimeout(()=>e({type:"create_snapshot"}))},[e,t])},No=y.atom(e=>{const t=l.first(e(hs)),s=e(kn);if(!t||t.blockId!==l.get(s,"_id",null))return[];const r=l.get(s,t.prop,`${ue.STYLES_KEY},`).replace(ue.STYLES_KEY,"").split(",").join(" ");return l.filter(l.map(r.trim().split(" "),le.constructClassObject),o=>!l.isNull(o))}),au=()=>y.useAtomValue(No),or={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},uu=y.atom(e=>{const t=e(Co),s=e(An),n=e(Io),r=cu(t);let o=l.filter(e(No),{mod:s});return l.startsWith(s,"_")||(o=l.filter(o,i=>r.includes(i.mq))),o=o.sort((i,u)=>or[i.mq]-or[u.mq]),n||(o=l.filter(o,{dark:!1})),o}),cu=e=>{let t=[];switch(e){case"xs":t=["xs"];break;case"sm":t=["xs","sm"];break;case"md":t=["xs","sm","md"];break;case"lg":t=["xs","sm","md","lg"];break;case"xl":t=["xs","sm","md","lg","xl"];break;case"2xl":t=["xs","sm","md","lg","xl","2xl"];break;default:t=["xs"];break}return t},lu=()=>y.useAtomValue(uu),du=()=>y.useAtom(An),To=y.atom(null,(e,t,{blockIds:s,props:n,dispatch:r})=>{r({type:"update_props_realtime",payload:{ids:s,props:n}})}),fu=()=>{const{createSnapshot:e}=ps(),t=we(),s=y.useSetAtom(To);return B.useCallback((n,r)=>{s({blockIds:n,props:r,dispatch:t}),e()},[e,t,s])},hu=()=>{const e=we(),t=y.useSetAtom(To);return B.useCallback((s,n)=>{t({blockIds:s,props:n,dispatch:e})},[e,t])},Uo={name:"",props:{},modalProps:{},backdropClose:!0},pu=y.atom(Uo),mu=()=>{const[e,t]=y.useAtom(pu),s=B.useCallback((r,o={},i={})=>{t({name:r,props:o,modalProps:i})},[t]),n=B.useCallback((...r)=>{l.get(e,"props.onClose",()=>{})(...r),t(Uo)},[t,e]);return{activeModal:e,openModal:s,closeModal:n}},gu=()=>y.useAtomValue(vo),yu=y.atom(""),vu=y.atom(null),bu=()=>y.useAtom(yu),xu=()=>y.useAtom(vu),wu=dt("selectedBreakpoints",["XS","MD","XL"]),Su=()=>{const[e,t]=y.useAtom(wu);return[e,t]},Mn=()=>{const e=y.useSetAtom(Ts),{clear:t}=ps(),[,s]=Je(),[,n]=Ro(),[,r]=Pn();return()=>{s([]),r([]),n(""),t(),e({undoCount:0,redoCount:0})}},Eu=y.atom({en:{}}),ku=()=>{const[e,t]=y.useAtom(Eu),s=B.useCallback((n,r,o)=>{l.set(e,`${n}.${r}`,o),t(e)},[e,t]);return[e,s]},Au=(e,t)=>{const[s]=y.useAtom(be.chaiBuilderPropsAtom);return l.get(s,e,t)},Pu=y.atom([]),Ou=()=>{const[e,t]=B.useState(!1),[s,n]=y.useAtom(Pu),r=be.useBuilderProp("getUILibraryBlocks",()=>[]);return B.useEffect(()=>{(async()=>s.length>0||(t(!0),n(await r()),t(!1)))()},[]),{data:s,isLoading:e}},ju=y.atom("en"),Cu=y.atom("en"),_u=y.atom(["en"]),Fo=()=>y.useAtom(ju),Bu=()=>y.useAtom(Cu),Iu=()=>y.useAtom(_u),Ru=(e,t)=>{const[s]=Fo(),n=`${e}${s?`-${s}`:""}`;return{content:l.get(t,n,l.get(t,e,"")),propKey:e}},Du=()=>{const[e,t]=On(),s=be.useBuilderProp("previewComponent");return _.jsxRuntimeExports.jsxs("div",{className:ji.cn("fixed inset-0 z-[999] bg-background",e?"block":"hidden"),children:[_.jsxRuntimeExports.jsx(be.Button,{size:"sm",className:"absolute right-0 top-0 m-4",onClick:()=>t(!1),children:"Close Preview"}),_.jsxRuntimeExports.jsx("div",{children:s?_.jsxRuntimeExports.jsx(B.Suspense,{fallback:_.jsxRuntimeExports.jsx(be.Skeleton,{className:"h-96 w-full"}),children:B.createElement(s)}):null})]})},Mu=()=>{const[e,t]=Je(),[,s]=Bo(),n=Lo(),r=Dn(),[,o]=In(),{pasteBlocks:i}=Do(),{undo:u,redo:d}=ps();Le.useHotkeys("esc",()=>t([]),{},[t]),Le.useHotkeys("ctrl+c,command+c",()=>s(e),{},[e,s]),Le.useHotkeys("ctrl+d,command+d",()=>r(e),{preventDefault:!0},[e,r]),Le.useHotkeys("ctrl+x,command+x",()=>o(e),{},[e,o]),Le.useHotkeys("ctrl+v,command+v",()=>e.length===1?i(e[0]):null,{},[e,i]),Le.useHotkeys("ctrl+z,command+z",()=>u(),{},[u]),Le.useHotkeys("ctrl+y,command+y",()=>d(),{},[d]),Le.useHotkeys("del, backspace",c=>{c.preventDefault(),n(e)},{},[e,n])},Lu=(e,t)=>{const s=[];let n=l.find(e,{_id:t}),r=l.get(n,"_parent","");for(;l.isString(r)&&!l.isEmpty(r);)s.push(n==null?void 0:n._parent),n=l.find(e,{_id:r}),r=n==null?void 0:n._parent;return l.flatten(s)},qo=y.atom([]),Nu=()=>{const[e]=Je(),t=y.useAtomValue(xe),[,s]=y.useAtom(qo);B.useEffect(()=>{let n=[];const r=l.first(e);l.isString(r)&&(n=[r,...Lu(t,r)]),s(n)},[e,t,s])},Tu=()=>y.useAtomValue(qo),Uu=B.lazy(()=>Promise.resolve().then(()=>require("./SidePanels-2d310a73.cjs"))),Fu=B.lazy(()=>Promise.resolve().then(()=>require("./Topbar-f722a517.cjs"))),qu=B.lazy(()=>Promise.resolve().then(()=>require("./CanvasArea-a392ffc1.cjs"))),$u=B.lazy(()=>Promise.resolve().then(()=>require("./Settings-3f024a5e.cjs"))),Vu=()=>{const[e]=ca(Us),t=s=>{s.preventDefault()};return Mu(),Nu(),B.useEffect(()=>(e!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[e]),_.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-background text-foreground",children:_.jsxRuntimeExports.jsxs(be.TooltipProvider,{children:[_.jsxRuntimeExports.jsxs("div",{onContextMenu:t,className:"flex h-screen flex-col overflow-hidden bg-background text-foreground",children:[_.jsxRuntimeExports.jsx("div",{className:"h-14 w-screen shrink-0 border-b border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(Fu,{})})}),_.jsxRuntimeExports.jsxs("main",{className:"flex h-full flex-row",children:[_.jsxRuntimeExports.jsx("div",{className:"flex h-full w-fit border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(Uu,{})})}),_.jsxRuntimeExports.jsx("div",{className:"h-full flex-1 bg-slate-800/20",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(qu,{})})}),_.jsxRuntimeExports.jsx("div",{className:"flex h-full w-[280px] min-w-[280px] border-l border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx($u,{})})})]})]}),_.jsxRuntimeExports.jsx(Du,{})]})})},Qu=y.getDefaultStore();y.atom({});function ir(e,t,s,n,r){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:r;return e===r?s:e}var xs="undefined",ar="object",$o="any",Vo="*",ut="__",Bs=typeof process<"u"?process:{};Bs.env&&Bs.env.NODE_ENV;var Ee=typeof document<"u";Bs.versions!=null&&Bs.versions.node!=null;typeof Deno<"u"&&Deno.core;Ee&&window.name==="nodejs"||typeof navigator<"u"&&navigator.userAgent!==void 0&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));function Qo(e,t){return t.charAt(0)[e]()+t.slice(1)}var Ku=Qo.bind(null,"toUpperCase"),zu=Qo.bind(null,"toLowerCase");function Hu(e){return Ko(e)?Ku("null"):typeof e=="object"?Xu(e):Object.prototype.toString.call(e).slice(8,-1)}function Is(e,t){t===void 0&&(t=!0);var s=Hu(e);return t?zu(s):s}function ms(e,t){return typeof t===e}var Ce=ms.bind(null,"function"),mt=ms.bind(null,"string"),ht=ms.bind(null,"undefined"),Gu=ms.bind(null,"boolean");ms.bind(null,"symbol");function Ko(e){return e===null}function Wu(e){return Is(e)==="number"&&!isNaN(e)}function Ju(e){return Is(e)==="array"}function he(e){if(!Yu(e))return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Yu(e){return e&&(typeof e=="object"||e!==null)}function Xu(e){return Ce(e.constructor)?e.constructor.name:null}function Zu(e){return e instanceof Error||mt(e.message)&&e.constructor&&Wu(e.constructor.stackTraceLimit)}function zo(e,t){if(typeof t!="object"||Ko(t))return!1;if(t instanceof e)return!0;var s=Is(new e(""));if(Zu(t))for(;t;){if(Is(t)===s)return!0;t=Object.getPrototypeOf(t)}return!1}zo.bind(null,TypeError);zo.bind(null,SyntaxError);function Fs(e,t){var s=e instanceof Element||e instanceof HTMLDocument;return s&&t?ec(e,t):s}function ec(e,t){return t===void 0&&(t=""),e&&e.nodeName===t.toUpperCase()}function qs(e){var t=[].slice.call(arguments,1);return function(){return e.apply(void 0,[].slice.call(arguments).concat(t))}}qs(Fs,"form");qs(Fs,"button");qs(Fs,"input");qs(Fs,"select");function ur(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function tc(){if(Ee){var e=navigator,t=e.languages;return e.userLanguage||(t&&t.length?t[0]:e.language)}}function sc(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function nc(e){return function(t){for(var s,n=Object.create(null),r=/([^&=]+)=?([^&]*)/g;s=r.exec(t);){var o=ur(s[1]),i=ur(s[2]);o.substring(o.length-2)==="[]"?(n[o=o.substring(0,o.length-2)]||(n[o]=[])).push(i):n[o]=i===""||i}for(var u in n){var d=u.split("[");d.length>1&&(rc(n,d.map(function(c){return c.replace(/[?[\]\\ ]/g,"")}),n[u]),delete n[u])}return n}(function(t){if(t){var s=t.match(/\?(.*)/);return s&&s[1]?s[1].split("#")[0]:""}return Ee&&window.location.search.substring(1)}(e))}function rc(e,t,s){for(var n=t.length-1,r=0;r<n;++r){var o=t[r];if(o==="__proto__"||o==="constructor")break;o in e||(e[o]={}),e=e[o]}e[t[n]]=s}function $s(){for(var e="",t=0,s=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],r=15&s;e+=n=="-"||n=="4"?n:(n=="x"?r:3&r|8).toString(16),s=t%8==0?4294967295*Math.random()|0:s>>4}return e}var Gt="global",Mt=ut+"global"+ut,Lt=typeof self===ar&&self.self===self&&self||typeof global===ar&&global.global===global&&global||void 0;function ct(e){return Lt[Mt][e]}function lt(e,t){return Lt[Mt][e]=t}function Ut(e){delete Lt[Mt][e]}function Ft(e,t,s){var n;try{if(Ln(e)){var r=window[e];n=r[t].bind(r)}}catch{}return n||s}Lt[Mt]||(Lt[Mt]={});var ws={};function Ln(e){if(typeof ws[e]!==xs)return ws[e];try{var t=window[e];t.setItem(xs,xs),t.removeItem(xs)}catch{return ws[e]=!1}return ws[e]=!0}function V(){return V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},V.apply(this,arguments)}var Fe="function",De="undefined",oc="@@redux/"+Math.random().toString(36),cr=function(){return typeof Symbol===Fe&&Symbol.observable||"@@observable"}(),Ss=" != "+Fe;function Ho(e,t,s){var n;if(typeof t===Fe&&typeof s===De&&(s=t,t=void 0),typeof s!==De){if(typeof s!==Fe)throw new Error("enhancer"+Ss);return s(Ho)(e,t)}if(typeof e!==Fe)throw new Error("reducer"+Ss);var r=e,o=t,i=[],u=i,d=!1;function c(){u===i&&(u=i.slice())}function h(){return o}function m(v){if(typeof v!==Fe)throw new Error("Listener"+Ss);var C=!0;return c(),u.push(v),function(){if(C){C=!1,c();var I=u.indexOf(v);u.splice(I,1)}}}function k(v){if(!he(v))throw new Error("Act != obj");if(typeof v.type===De)throw new Error("ActType "+De);if(d)throw new Error("Dispatch in reducer");try{d=!0,o=r(o,v)}finally{d=!1}for(var C=i=u,I=0;I<C.length;I++)(0,C[I])();return v}return k({type:"@@redux/INIT"}),(n={dispatch:k,subscribe:m,getState:h,replaceReducer:function(v){if(typeof v!==Fe)throw new Error("next reducer"+Ss);r=v,k({type:"@@redux/INIT"})}})[cr]=function(){var v,C=m;return(v={subscribe:function(I){if(typeof I!="object")throw new TypeError("Observer != obj");function b(){I.next&&I.next(h())}return b(),{unsubscribe:C(b)}}})[cr]=function(){return this},v},n}function ic(e,t){var s=t&&t.type;return"action "+(s&&s.toString()||"?")+"reducer "+e+" returns "+De}function Nt(){var e=[].slice.call(arguments);return e.length===0?function(t){return t}:e.length===1?e[0]:e.reduce(function(t,s){return function(){return t(s.apply(void 0,[].slice.call(arguments)))}})}function ac(){var e=arguments;return function(t){return function(s,n,r){var o,i=t(s,n,r),u=i.dispatch,d={getState:i.getState,dispatch:function(c){return u(c)}};return o=[].slice.call(e).map(function(c){return c(d)}),V({},i,{dispatch:u=Nt.apply(void 0,o)(i.dispatch)})}}}var We=ut+"anon_id",at=ut+"user_id",gt=ut+"user_traits",Te="userId",pt="anonymousId",Ps=["bootstrap","params","campaign","initializeStart","initialize","initializeEnd","ready","resetStart","reset","resetEnd","pageStart","page","pageEnd","pageAborted","trackStart","track","trackEnd","trackAborted","identifyStart","identify","identifyEnd","identifyAborted","userIdChanged","registerPlugins","enablePlugin","disablePlugin","online","offline","setItemStart","setItem","setItemEnd","setItemAborted","removeItemStart","removeItem","removeItemEnd","removeItemAborted"],on=["name","EVENTS","config","loaded"],$=Ps.reduce(function(e,t){return e[t]=t,e},{registerPluginType:function(e){return"registerPlugin:"+e},pluginReadyType:function(e){return"ready:"+e}}),lr=/^utm_/,dr=/^an_prop_/,fr=/^an_trait_/;function uc(e){var t=e.storage.setItem;return function(s){return function(n){return function(r){if(r.type===$.bootstrap){var o=r.params,i=r.user,u=r.persistedUser,d=r.initialUser,c=u.userId===i.userId;u.anonymousId!==i.anonymousId&&t(We,i.anonymousId),c||t(at,i.userId),d.traits&&t(gt,V({},c&&u.traits?u.traits:{},d.traits));var h=Object.keys(r.params);if(h.length){var m=o.an_uid,k=o.an_event,v=h.reduce(function(C,I){if(I.match(lr)||I.match(/^(d|g)clid/)){var b=I.replace(lr,"");C.campaign[b==="campaign"?"name":b]=o[I]}return I.match(dr)&&(C.props[I.replace(dr,"")]=o[I]),I.match(fr)&&(C.traits[I.replace(fr,"")]=o[I]),C},{campaign:{},props:{},traits:{}});s.dispatch(V({type:$.params,raw:o},v,m?{userId:m}:{})),m&&setTimeout(function(){return e.identify(m,v.traits)},0),k&&setTimeout(function(){return e.track(k,v.props)},0),Object.keys(v.campaign).length&&s.dispatch({type:$.campaign,campaign:v.campaign})}}return n(r)}}}}function cc(e){return function(t,s){if(t===void 0&&(t={}),s===void 0&&(s={}),s.type===$.setItemEnd){if(s.key===We)return V({},t,{anonymousId:s.value});if(s.key===at)return V({},t,{userId:s.value})}switch(s.type){case $.identify:return Object.assign({},t,{userId:s.userId,traits:V({},t.traits,s.traits)});case $.reset:return[at,We,gt].forEach(function(n){e.removeItem(n)}),Object.assign({},t,{userId:null,anonymousId:null,traits:{}});default:return t}}}function hr(e){return{userId:e.getItem(at),anonymousId:e.getItem(We),traits:e.getItem(gt)}}var an=function(e){return ut+"TEMP"+ut+e};function lc(e){var t=e.storage,s=t.setItem,n=t.removeItem,r=t.getItem;return function(o){return function(i){return function(u){var d=u.userId,c=u.traits,h=u.options;if(u.type===$.reset&&([at,gt,We].forEach(function(v){n(v)}),[Te,pt,"traits"].forEach(function(v){Ut(an(v))})),u.type===$.identify){r(We)||s(We,$s());var m=r(at),k=r(gt)||{};m&&m!==d&&o.dispatch({type:$.userIdChanged,old:{userId:m,traits:k},new:{userId:d,traits:c},options:h}),d&&s(at,d),c&&s(gt,V({},k,c))}return i(u)}}}}var Kt={};function pr(e,t){Kt[e]&&Ce(Kt[e])&&(Kt[e](t),delete Kt[e])}function Go(e,t,s){return new Promise(function(n,r){return t()?n(e):s<1?r(V({},e,{queue:!0})):new Promise(function(o){return setTimeout(o,10)}).then(function(o){return Go(e,t,s-10).then(n,r)})})}function Wo(e,t,s){var n=t(),r=e.getState(),o=r.plugins,i=r.queue,u=r.user;if(!r.context.offline&&i&&i.actions&&i.actions.length){var d=i.actions.reduce(function(h,m,k){return o[m.plugin].loaded?(h.process.push(m),h.processIndex.push(k)):(h.requeue.push(m),h.requeueIndex.push(k)),h},{processIndex:[],process:[],requeue:[],requeueIndex:[]});if(d.processIndex&&d.processIndex.length){d.processIndex.forEach(function(h){var m=i.actions[h],k=m.plugin,v=m.payload.type,C=n[k][v];if(C&&Ce(C)){var I=function(O,R){return O===void 0&&(O={}),R===void 0&&(R={}),[Te,pt].reduce(function(M,w){return O.hasOwnProperty(w)&&R[w]&&R[w]!==O[w]&&(M[w]=R[w]),M},O)}(m.payload,u);C({payload:I,config:o[k].config,instance:s});var b=v+":"+k;e.dispatch(V({},I,{type:b,_:{called:b,from:"queueDrain"}}))}});var c=i.actions.filter(function(h,m){return!~d.processIndex.indexOf(m)});i.actions=c}}}var Js=function(e){var t=e.data,s=e.action,n=e.instance,r=e.state,o=e.allPlugins,i=e.allMatches,u=e.store,d=e.EVENTS;try{var c=r.plugins,h=r.context,m=s.type,k=m.match(yt),v=t.exact.map(function(b){return b.pluginName});k&&(v=i.during.map(function(b){return b.pluginName}));var C=function(b,O){return function(R,M,w){var A=M.config,q=M.name,F=q+"."+R.type;w&&(F=w.event);var T=R.type.match(yt)?function(g,x,D,S,N){return function(j,E){var z=S?S.name:g,Q=E&&Xt(E)?E:D;if(S&&(!(Q=E&&Xt(E)?E:[g]).includes(g)||Q.length!==1))throw new Error("Method "+x+" can only abort "+g+" plugin. "+JSON.stringify(Q)+" input valid");return V({},N,{abort:{reason:j,plugins:Q,caller:x,_:z}})}}(q,F,O,w,R):function(g,x){return function(){throw new Error(g.type+" action not cancellable. Remove abort in "+x)}}(R,F);return{payload:dc(R),instance:b,config:A||{},abort:T}}}(n,v),I=t.exact.reduce(function(b,O){var R=O.pluginName,M=O.methodName,w=!1;return M.match(/^initialize/)||M.match(/^reset/)||(w=!c[R].loaded),h.offline&&M.match(/^(page|track|identify)/)&&(w=!0),b[""+R]=w,b},{});return Promise.resolve(t.exact.reduce(function(b,O,R){try{var M=O.pluginName;return Promise.resolve(b).then(function(w){function A(){return Promise.resolve(w)}var q=function(){if(t.namespaced&&t.namespaced[M])return Promise.resolve(t.namespaced[M].reduce(function(F,T,g){try{return Promise.resolve(F).then(function(x){return T.method&&Ce(T.method)?(function(j,E){var z=wr(j);if(z&&z.name===E){var Q=wr(z.method);throw new Error([E+" plugin is calling method "+j,"Plugins cant call self","Use "+z.method+" "+(Q?"or "+Q.method:"")+" in "+E+" plugin insteadof "+j].join(`
2
- `))}}(T.methodName,T.pluginName),Promise.resolve(T.method({payload:x,instance:n,abort:(D=x,S=M,N=T.pluginName,function(j,E){return V({},D,{abort:{reason:j,plugins:E||[S],caller:m,from:N||S}})}),config:yr(T.pluginName,c,o),plugins:c})).then(function(j){var E=he(j)?j:{};return Promise.resolve(V({},x,E))})):x;var D,S,N})}catch(x){return Promise.reject(x)}},Promise.resolve(s))).then(function(F){w[M]=F});w[M]=s}();return q&&q.then?q.then(A):A()})}catch(w){return Promise.reject(w)}},Promise.resolve({}))).then(function(b){return Promise.resolve(t.exact.reduce(function(O,R,M){try{var w=t.exact.length===M+1,A=R.pluginName,q=o[A];return Promise.resolve(O).then(function(F){var T=b[A]?b[A]:{};if(k&&(T=F),Xs(T,A))return Ys({data:T,method:m,instance:n,pluginName:A,store:u}),Promise.resolve(F);if(Xs(F,A))return w&&Ys({data:F,method:m,instance:n,store:u}),Promise.resolve(F);if(I.hasOwnProperty(A)&&I[A]===!0)return u.dispatch({type:"queue",plugin:A,payload:T,_:{called:"queue",from:"queueMechanism"}}),Promise.resolve(F);var g=C(b[A],o[A]);return Promise.resolve(q[m]({abort:g.abort,payload:T,instance:n,config:yr(A,c,o),plugins:c})).then(function(x){var D=he(x)?x:{},S=V({},F,D),N=b[A];if(Xs(N,A))Ys({data:N,method:m,instance:n,pluginName:A,store:u});else{var j=m+":"+A;(j.match(/:/g)||[]).length<2&&!m.match(mr)&&!m.match(gr)&&n.dispatch(V({},k?S:T,{type:j,_:{called:j,from:"submethod"}}))}return Promise.resolve(S)})})}catch(F){return Promise.reject(F)}},Promise.resolve(s))).then(function(O){if(!(m.match(yt)||m.match(/^registerPlugin/)||m.match(gr)||m.match(mr)||m.match(/^params/)||m.match(/^userIdChanged/))){if(d.plugins.includes(m),O._&&O._.originalAction===m)return O;var R=V({},O,{_:{originalAction:O.type,called:O.type,from:"engineEnd"}});Jo(O,t.exact.length)&&!m.match(/End$/)&&(R=V({},R,{type:O.type+"Aborted"})),u.dispatch(R)}return O})})}catch(b){return Promise.reject(b)}},yt=/Start$/,mr=/^bootstrap/,gr=/^ready/;function Ys(e){var t=e.pluginName,s=e.method+"Aborted"+(t?":"+t:"");e.store.dispatch(V({},e.data,{type:s,_:{called:s,from:"abort"}}))}function yr(e,t,s){var n=t[e]||s[e];return n&&n.config?n.config:{}}function vr(e,t){return t.reduce(function(s,n){return n[e]?s.concat({methodName:e,pluginName:n.name,method:n[e]}):s},[])}function br(e,t){var s=e.replace(yt,""),n=t?":"+t:"";return[""+e+n,""+s+n,s+"End"+n]}function Xs(e,t){var s=e.abort;return!!s&&(s===!0||xr(s,t)||s&&xr(s.plugins,t))}function Jo(e,t){var s=e.abort;if(!s)return!1;if(s===!0||mt(s))return!0;var n=s.plugins;return Xt(s)&&s.length===t||Xt(n)&&n.length===t}function Xt(e){return Array.isArray(e)}function xr(e,t){return!(!e||!Xt(e))&&e.includes(t)}function wr(e){var t=e.match(/(.*):(.*)/);return!!t&&{method:t[1],name:t[2]}}function dc(e){return Object.keys(e).reduce(function(t,s){return s==="type"||(t[s]=he(e[s])?Object.assign({},e[s]):e[s]),t},{})}function fc(e,t,s){var n={};return function(r){return function(o){return function(i){try{var u,d=function(w){return u?w:o(m)},c=i.type,h=i.plugins,m=i;if(i.abort)return Promise.resolve(o(i));if(c===$.enablePlugin&&r.dispatch({type:$.initializeStart,plugins:h,disabled:[],fromEnable:!0,meta:i.meta}),c===$.disablePlugin&&setTimeout(function(){return pr(i.meta.rid,{payload:i})},0),c===$.initializeEnd){var k=t(),v=Object.keys(k),C=v.filter(function(w){return h.includes(w)}).map(function(w){return k[w]}),I=[],b=[],O=i.disabled,R=C.map(function(w){var A=w.loaded,q=w.name,F=w.config;return Go(w,function(){return A({config:F})},1e4).then(function(T){return n[q]||(r.dispatch({type:$.pluginReadyType(q),name:q,events:Object.keys(w).filter(function(g){return!on.includes(g)})}),n[q]=!0),I=I.concat(q),w}).catch(function(T){if(T instanceof Error)throw new Error(T);return b=b.concat(T.name),T})});Promise.all(R).then(function(w){var A={plugins:I,failed:b,disabled:O};setTimeout(function(){v.length===R.length+O.length&&r.dispatch(V({},{type:$.ready},A))},0)})}var M=function(){if(c!==$.bootstrap)return/^ready:([^:]*)$/.test(c)&&setTimeout(function(){return Wo(r,t,e)},0),Promise.resolve(function(w,A,q,F,T){try{var g=Ce(A)?A():A,x=w.type,D=x.replace(yt,"");if(w._&&w._.called)return Promise.resolve(w);var S=q.getState(),N=(z=g,(Q=S.plugins)===void 0&&(Q={}),(W=w.options)===void 0&&(W={}),Object.keys(z).filter(function(f){var p=W.plugins||{};return Gu(p[f])?p[f]:p.all!==!1&&(!Q[f]||Q[f].enabled!==!1)}).map(function(f){return z[f]}));x===$.initializeStart&&w.fromEnable&&(N=Object.keys(S.plugins).filter(function(f){var p=S.plugins[f];return w.plugins.includes(f)&&!p.initialized}).map(function(f){return g[f]}));var j=N.map(function(f){return f.name}),E=function(f,p,U){var H=br(f).map(function(G){return vr(G,p)});return p.reduce(function(G,J){var oe=J.name,X=br(f,oe).map(function(Vt){return vr(Vt,p)}),ee=X[0],Y=X[1],ke=X[2];return ee.length&&(G.beforeNS[oe]=ee),Y.length&&(G.duringNS[oe]=Y),ke.length&&(G.afterNS[oe]=ke),G},{before:H[0],beforeNS:{},during:H[1],duringNS:{},after:H[2],afterNS:{}})}(x,N);return Promise.resolve(Js({action:w,data:{exact:E.before,namespaced:E.beforeNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(f){function p(){var G=function(){if(x.match(yt))return Promise.resolve(Js({action:V({},U,{type:D+"End"}),data:{exact:E.after,namespaced:E.afterNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(J){J.meta&&J.meta.hasCallback&&pr(J.meta.rid,{payload:J})})}();return G&&G.then?G.then(function(){return f}):f}if(Jo(f,j.length))return f;var U,H=function(){if(x!==D)return Promise.resolve(Js({action:V({},f,{type:D}),data:{exact:E.during,namespaced:E.duringNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(G){U=G});U=f}();return H&&H.then?H.then(p):p()})}catch(f){return Promise.reject(f)}var z,Q,W}(i,t,e,r,s)).then(function(w){return u=1,o(w)})}();return Promise.resolve(M&&M.then?M.then(d):d(M))}catch(w){return Promise.reject(w)}}}}}function hc(e){return function(t){return function(s){return function(n){var r=n.type,o=n.key,i=n.value,u=n.options;if(r===$.setItem||r===$.removeItem){if(n.abort)return s(n);r===$.setItem?e.setItem(o,i,u):e.removeItem(o,u)}return s(n)}}}}var pc=function(){var e=this;this.before=[],this.after=[],this.addMiddleware=function(t,s){e[s]=e[s].concat(t)},this.removeMiddleware=function(t,s){var n=e[s].findIndex(function(r){return r===t});n!==-1&&(e[s]=[].concat(e[s].slice(0,n),e[s].slice(n+1)))},this.dynamicMiddlewares=function(t){return function(s){return function(n){return function(r){var o={getState:s.getState,dispatch:function(u){return s.dispatch(u)}},i=e[t].map(function(u){return u(o)});return Nt.apply(void 0,i)(n)(r)}}}}};function mc(e){return function(t,s){t===void 0&&(t={});var n={};if(s.type==="initialize:aborted")return t;if(/^registerPlugin:([^:]*)$/.test(s.type)){var r=Sr(s.type,"registerPlugin"),o=e()[r];if(!o||!r)return t;var i=s.enabled,u=o.config;return n[r]={enabled:i,initialized:!!i&&!o.initialize,loaded:!!i&&!!o.loaded({config:u}),config:u},V({},t,n)}if(/^initialize:([^:]*)$/.test(s.type)){var d=Sr(s.type,$.initialize),c=e()[d];return c&&d?(n[d]=V({},t[d],{initialized:!0,loaded:!!c.loaded({config:c.config})}),V({},t,n)):t}if(/^ready:([^:]*)$/.test(s.type))return n[s.name]=V({},t[s.name],{loaded:!0}),V({},t,n);switch(s.type){case $.disablePlugin:return V({},t,Er(s.plugins,!1,t));case $.enablePlugin:return V({},t,Er(s.plugins,!0,t));default:return t}}}function Sr(e,t){return e.substring(t.length+1,e.length)}function Er(e,t,s){return e.reduce(function(n,r){return n[r]=V({},s[r],{enabled:t}),n},s)}function Yo(e){try{return JSON.parse(JSON.stringify(e))}catch{}return e}var gc={last:{},history:[]};function yc(e,t){e===void 0&&(e=gc);var s=t.options,n=t.meta;if(t.type===$.track){var r=Yo(V({event:t.event,properties:t.properties},Object.keys(s).length&&{options:s},{meta:n}));return V({},e,{last:r,history:e.history.concat(r)})}return e}var vc={actions:[]};function bc(e,t){e===void 0&&(e=vc);var s=t.payload;switch(t.type){case"queue":var n;return n=s&&s.type&&s.type===$.identify?[t].concat(e.actions):e.actions.concat(t),V({},e,{actions:n});case"dequeue":return[];default:return e}}var Xo=/#.*$/;function xc(e){var t=/(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g.exec(e);return"/"+(t&&t[3]?t[3].split("?")[0].replace(Xo,""):"")}var Zo,ei,ti,si,wc=function(e){if(e===void 0&&(e={}),!Ee)return e;var t=document,s=t.title,n=t.referrer,r=window,o=r.location,i=r.innerWidth,u=r.innerHeight,d=o.hash,c=o.search,h=function(k){var v=function(){if(Ee){for(var C,I=document.getElementsByTagName("link"),b=0;C=I[b];b++)if(C.getAttribute("rel")==="canonical")return C.getAttribute("href")}}();return v?v.match(/\?/)?v:v+k:window.location.href.replace(Xo,"")}(c),m={title:s,url:h,path:xc(h),hash:d,search:c,width:i,height:u};return n&&n!==""&&(m.referrer=n),V({},m,e)},Sc={last:{},history:[]};function Ec(e,t){e===void 0&&(e=Sc);var s=t.options;if(t.type===$.page){var n=Yo(V({properties:t.properties,meta:t.meta},Object.keys(s).length&&{options:s}));return V({},e,{last:n,history:e.history.concat(n)})}return e}Zo=function(){if(!Ee)return!1;var e=navigator.appVersion;return~e.indexOf("Win")?"Windows":~e.indexOf("Mac")?"MacOS":~e.indexOf("X11")?"UNIX":~e.indexOf("Linux")?"Linux":"Unknown OS"}(),ei=Ee?document.referrer:null,ti=tc(),si=sc();var kr={initialized:!1,sessionId:$s(),app:null,version:null,debug:!1,offline:!!Ee&&!navigator.onLine,os:{name:Zo},userAgent:Ee?navigator.userAgent:"node",library:{name:"analytics",version:"0.12.5"},timezone:si,locale:ti,campaign:{},referrer:ei};function kc(e,t){e===void 0&&(e=kr);var s=e.initialized,n=t.campaign;switch(t.type){case $.campaign:return V({},e,{campaign:n});case $.offline:return V({},e,{offline:!0});case $.online:return V({},e,{offline:!1});default:return s?e:V({},kr,e,{initialized:!0})}}var Ac=["plugins","reducers","storage"];function Pc(e,t,s){if(Ee){var n=window[(s?"add":"remove")+"EventListener"];e.split(" ").forEach(function(r){n(r,t)})}}function Oc(e){var t=Pc.bind(null,"online offline",function(s){return Promise.resolve(!navigator.onLine).then(e)});return t(!0),function(s){return t(!1)}}function ni(){return lt("analytics",[]),function(e){return function(t,s,n){var r=e(t,s,n),o=r.dispatch;return Object.assign(r,{dispatch:function(i){return Lt[Mt].analytics.push(i.action||i),o(i)}})}}}function Ar(e){return function(){return Nt(Nt.apply(null,arguments),ni())}}function Zs(e){return e?Ju(e)?e:[e]:[]}function Pr(e,t,s){e===void 0&&(e={});var n,r,o=$s();return t&&(Kt[o]=(n=t,r=function(i){for(var u,d=i||Array.prototype.slice.call(arguments),c=0;c<d.length;c++)if(Ce(d[c])){u=d[c];break}return u}(s),function(i){r&&r(i),n(i)})),V({},e,{rid:o,ts:new Date().getTime()},t?{hasCallback:!0}:{})}function jc(e){e===void 0&&(e={});var t=e.reducers||{},s=e.initialUser||{},n=(e.plugins||[]).reduce(function(f,p){if(Ce(p))return f.middlewares=f.middlewares.concat(p),f;if(p.NAMESPACE&&(p.name=p.NAMESPACE),!p.name)throw new Error("https://lytics.dev/errors/1");p.config||(p.config={});var U=p.EVENTS?Object.keys(p.EVENTS).map(function(J){return p.EVENTS[J]}):[];f.pluginEnabled[p.name]=!(p.enabled===!1||p.config.enabled===!1),delete p.enabled,p.methods&&(f.methods[p.name]=Object.keys(p.methods).reduce(function(J,oe){var X;return J[oe]=(X=p.methods[oe],function(){for(var ee=Array.prototype.slice.call(arguments),Y=new Array(X.length),ke=0;ke<ee.length;ke++)Y[ke]=ee[ke];return Y[Y.length]=A,X.apply({instance:A},Y)}),J},{}),delete p.methods);var H=Object.keys(p).concat(U),G=new Set(f.events.concat(H));if(f.events=Array.from(G),f.pluginsArray=f.pluginsArray.concat(p),f.plugins[p.name])throw new Error(p.name+"AlreadyLoaded");return f.plugins[p.name]=p,f.plugins[p.name].loaded||(f.plugins[p.name].loaded=function(){return!0}),f},{plugins:{},pluginEnabled:{},methods:{},pluginsArray:[],middlewares:[],events:[]}),r=e.storage?e.storage:{getItem:ct,setItem:lt,removeItem:Ut},o=function(f){return function(p,U,H){return U.getState("user")[p]||(H&&he(H)&&H[p]?H[p]:hr(f)[p]||ct(an(p))||null)}}(r),i=n.plugins,u=n.events.filter(function(f){return!on.includes(f)}).sort(),d=new Set(u.concat(Ps).filter(function(f){return!on.includes(f)})),c=Array.from(d).sort(),h=function(){return i},m=new pc,k=m.addMiddleware,v=m.removeMiddleware,C=m.dynamicMiddlewares,I=function(){throw new Error("Abort disabled inListener")},b=nc(),O=hr(r),R=V({},O,s,b.an_uid?{userId:b.an_uid}:{},b.an_aid?{anonymousId:b.an_aid}:{});R.anonymousId||(R.anonymousId=$s());var M=V({enable:function(f,p){return new Promise(function(U){E.dispatch({type:$.enablePlugin,plugins:Zs(f),_:{originalAction:$.enablePlugin}},U,[p])})},disable:function(f,p){return new Promise(function(U){E.dispatch({type:$.disablePlugin,plugins:Zs(f),_:{originalAction:$.disablePlugin}},U,[p])})}},n.methods),w=!1,A={identify:function(f,p,U,H){try{var G=mt(f)?f:null,J=he(f)?f:p,oe=U||{},X=A.user();lt(an(Te),G);var ee=G||J.userId||o(Te,A,J);return Promise.resolve(new Promise(function(Y){E.dispatch(V({type:$.identifyStart,userId:ee,traits:J||{},options:oe,anonymousId:X.anonymousId},X.id&&X.id!==G&&{previousId:X.id}),Y,[p,U,H])}))}catch(Y){return Promise.reject(Y)}},track:function(f,p,U,H){try{var G=he(f)?f.event:f;if(!G||!mt(G))throw new Error("EventMissing");var J=he(f)?f:p||{},oe=he(U)?U:{};return Promise.resolve(new Promise(function(X){E.dispatch({type:$.trackStart,event:G,properties:J,options:oe,userId:o(Te,A,p),anonymousId:o(pt,A,p)},X,[p,U,H])}))}catch(X){return Promise.reject(X)}},page:function(f,p,U){try{var H=he(f)?f:{},G=he(p)?p:{};return Promise.resolve(new Promise(function(J){E.dispatch({type:$.pageStart,properties:wc(H),options:G,userId:o(Te,A,H),anonymousId:o(pt,A,H)},J,[f,p,U])}))}catch(J){return Promise.reject(J)}},user:function(f){if(f===Te||f==="id")return o(Te,A);if(f===pt||f==="anonId")return o(pt,A);var p=A.getState("user");return f?ir(p,f):p},reset:function(f){return new Promise(function(p){E.dispatch({type:$.resetStart},p,f)})},ready:function(f){return w&&f({plugins:M,instance:A}),A.on($.ready,function(p){f(p),w=!0})},on:function(f,p){if(!f||!Ce(p))return!1;if(f===$.bootstrap)throw new Error(".on disabled for "+f);var U=/Start$|Start:/;if(f==="*"){var H=function(X){return function(ee){return function(Y){return Y.type.match(U)&&p({payload:Y,instance:A,plugins:i}),ee(Y)}}},G=function(X){return function(ee){return function(Y){return Y.type.match(U)||p({payload:Y,instance:A,plugins:i}),ee(Y)}}};return k(H,Es),k(G,ks),function(){v(H,Es),v(G,ks)}}var J=f.match(U)?Es:ks,oe=function(X){return function(ee){return function(Y){return Y.type===f&&p({payload:Y,instance:A,plugins:i,abort:I}),ee(Y)}}};return k(oe,J),function(){return v(oe,J)}},once:function(f,p){if(!f||!Ce(p))return!1;if(f===$.bootstrap)throw new Error(".once disabled for "+f);var U=A.on(f,function(H){p({payload:H.payload,instance:A,plugins:i,abort:I}),U()});return U},getState:function(f){var p=E.getState();return f?ir(p,f):Object.assign({},p)},dispatch:function(f){var p=mt(f)?{type:f}:f;if(Ps.includes(p.type))throw new Error("reserved action "+p.type);var U=V({},p,{_:V({originalAction:p.type},f._||{})});E.dispatch(U)},enablePlugin:M.enable,disablePlugin:M.disable,plugins:M,storage:{getItem:r.getItem,setItem:function(f,p,U){E.dispatch({type:$.setItemStart,key:f,value:p,options:U})},removeItem:function(f,p){E.dispatch({type:$.removeItemStart,key:f,options:p})}},setAnonymousId:function(f,p){A.storage.setItem(We,f,p)},events:{core:Ps,plugins:u}},q=n.middlewares.concat([function(f){return function(p){return function(U){return U.meta||(U.meta=Pr()),p(U)}}},C(Es),fc(A,h,{all:c,plugins:u}),hc(r),uc(A),lc(A),C(ks)]),F={context:kc,user:cc(r),page:Ec,track:yc,plugins:mc(h),queue:bc},T=Nt,g=Nt;if(Ee&&e.debug){var x=window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;x&&(T=x({trace:!0,traceLimit:25})),g=function(){return arguments.length===0?ni():he(typeof arguments[0])?Ar():Ar().apply(null,arguments)}}var D,S=function(f){return Object.keys(f).reduce(function(p,U){return Ac.includes(U)||(p[U]=f[U]),p},{})}(e),N=n.pluginsArray.reduce(function(f,p){var U=p.name,H=p.config,G=p.loaded,J=n.pluginEnabled[U];return f[U]={enabled:J,initialized:!!J&&!p.initialize,loaded:!!G({config:H}),config:H},f},{}),j={context:S,user:R,plugins:N},E=Ho(function(f){for(var p=Object.keys(f),U={},H=0;H<p.length;H++){var G=p[H];typeof f[G]===Fe&&(U[G]=f[G])}var J,oe=Object.keys(U);try{(function(X){Object.keys(X).forEach(function(ee){var Y=X[ee];if(typeof Y(void 0,{type:"@@redux/INIT"})===De||typeof Y(void 0,{type:oc})===De)throw new Error("reducer "+ee+" "+De)})})(U)}catch(X){J=X}return function(X,ee){if(X===void 0&&(X={}),J)throw J;for(var Y=!1,ke={},Vt=0;Vt<oe.length;Vt++){var ys=oe[Vt],Kn=X[ys],Hs=(0,U[ys])(Kn,ee);if(typeof Hs===De){var Ei=ic(ys,ee);throw new Error(Ei)}ke[ys]=Hs,Y=Y||Hs!==Kn}return Y?ke:X}}(V({},F,t)),j,g(T(ac.apply(void 0,q))));E.dispatch=(D=E.dispatch,function(f,p,U){var H=V({},f,{meta:Pr(f.meta,p,Zs(U))});return D.apply(null,[H])});var z=Object.keys(i);E.dispatch({type:$.bootstrap,plugins:z,config:S,params:b,user:R,initialUser:s,persistedUser:O});var Q=z.filter(function(f){return n.pluginEnabled[f]}),W=z.filter(function(f){return!n.pluginEnabled[f]});return E.dispatch({type:$.registerPlugins,plugins:z,enabled:n.pluginEnabled}),n.pluginsArray.map(function(f,p){var U=f.bootstrap,H=f.config,G=f.name;U&&Ce(U)&&U({instance:A,config:H,payload:f}),E.dispatch({type:$.registerPluginType(G),name:G,enabled:n.pluginEnabled[G],plugin:f}),n.pluginsArray.length===p+1&&E.dispatch({type:$.initializeStart,plugins:Q,disabled:W})}),Oc(function(f){E.dispatch({type:f?$.offline:$.online})}),function(f,p,U){setInterval(function(){return Wo(f,p,U)},3e3)}(E,h,A),A}var Es="before",ks="after",Wt="cookie",Ye=ii(),ri=Vs,Cc=Vs;function oi(e){return Ye?Vs(e,"",-1):Ut(e)}function ii(){if(Ye!==void 0)return Ye;var e="cookiecookie";try{Vs(e,e),Ye=document.cookie.indexOf(e)!==-1,oi(e)}catch{Ye=!1}return Ye}function Vs(e,t,s,n,r,o){if(typeof window<"u"){var i=arguments.length>1;return Ye===!1&&(i?lt(e,t):ct(e)),i?document.cookie=e+"="+encodeURIComponent(t)+(s?"; expires="+new Date(+new Date+1e3*s).toUTCString()+(n?"; path="+n:"")+(r?"; domain="+r:"")+(o?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}var Jt="localStorage",_c=Ln.bind(null,"localStorage");Ft("localStorage","getItem",ct);Ft("localStorage","setItem",lt);Ft("localStorage","removeItem",Ut);var Yt="sessionStorage",Bc=Ln.bind(null,"sessionStorage");Ft("sessionStorage","getItem",ct);Ft("sessionStorage","setItem",lt);Ft("sessionStorage","removeItem",Ut);function vt(e){var t=e;try{if((t=JSON.parse(e))==="true")return!0;if(t==="false")return!1;if(he(t))return t;parseFloat(t)===t&&(t=parseFloat(t))}catch{}if(t!==null&&t!=="")return t}var Ic=_c(),Rc=Bc(),Dc=ii();function ai(e,t){if(e){var s=Nn(t),n=!qn(s),r=Tn(s)?vt(localStorage.getItem(e)):void 0;if(n&&!ht(r))return r;var o=Un(s)?vt(ri(e)):void 0;if(n&&o)return o;var i=Fn(s)?vt(sessionStorage.getItem(e)):void 0;if(n&&i)return i;var u=ct(e);return n?u:{localStorage:r,sessionStorage:i,cookie:o,global:u}}}function Mc(e,t,s){if(e&&!ht(t)){var n={},r=Nn(s),o=JSON.stringify(t),i=!qn(r);return Tn(r)&&(n[Jt]=As(Jt,t,vt(localStorage.getItem(e))),localStorage.setItem(e,o),i)?n[Jt]:Un(r)&&(n[Wt]=As(Wt,t,vt(ri(e))),Cc(e,o),i)?n[Wt]:Fn(r)&&(n[Yt]=As(Yt,t,vt(sessionStorage.getItem(e))),sessionStorage.setItem(e,o),i)?n[Yt]:(n[Gt]=As(Gt,t,ct(e)),lt(e,t),i?n[Gt]:n)}}function Lc(e,t){if(e){var s=Nn(t),n=ai(e,Vo),r={};return!ht(n.localStorage)&&Tn(s)&&(localStorage.removeItem(e),r[Jt]=n.localStorage),!ht(n.cookie)&&Un(s)&&(oi(e),r[Wt]=n.cookie),!ht(n.sessionStorage)&&Fn(s)&&(sessionStorage.removeItem(e),r[Yt]=n.sessionStorage),!ht(n.global)&&Qs(s,Gt)&&(Ut(e),r[Gt]=n.global),r}}function Nn(e){return e?mt(e)?e:e.storage:$o}function Tn(e){return Ic&&Qs(e,Jt)}function Un(e){return Dc&&Qs(e,Wt)}function Fn(e){return Rc&&Qs(e,Yt)}function qn(e){return e===Vo||e==="all"}function Qs(e,t){return e===$o||e===t||qn(e)}function As(e,t,s){return{location:e,current:t,previous:s}}var Nc={setItem:Mc,getItem:ai,removeItem:Lc};function Tc(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function Or(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),s.push.apply(s,n)}return s}function jr(e){for(var t=1;t<arguments.length;t++){var s=arguments[t]!=null?arguments[t]:{};t%2?Or(Object(s),!0).forEach(function(n){Tc(e,n,s[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):Or(Object(s)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(s,n))})}return e}function Uc(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t={storage:Nc};return jc(jr(jr({},t),e))}const Fc="@chaibuilder/sdk",qc="0.1.12",$c="module",Vc=["dist"],Qc="dist/core.js",Kc=!1,zc={".":{import:"./dist/core.js",require:"./dist/core.cjs",types:"./dist/core.d.ts"},"./render":{import:"./dist/render.js",require:"./dist/render.cjs",types:"./dist/render.d.ts"},"./ui":{import:"./dist/ui.js",require:"./dist/ui.cjs",types:"./dist/ui.d.ts"},"./lib":{import:"./dist/lib.js",require:"./dist/lib.cjs",types:"./dist/lib.d.ts"},"./server":{import:"./dist/server.js",require:"./dist/server.cjs",types:"./dist/server.d.ts"},"./styles":{import:"./dist/style.css",require:"./dist/style.css"}},Hc={dev:"vite",build:"tsc && vite build",lint:"eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",preview:"vite preview",test:"jest --colors","test:watch":"jest --watch --colors","test:coverage":"jest --coverage --colors",e2e:"playwright test","e2e:report":"playwright show-report","e2e:ui":"playwright test --ui",docs:"jsdoc -c jsdoc.conf.json"},Gc={"@analytics/google-analytics":"^1.0.7","@bobthered/tailwindcss-palette-generator":"3.1.1","@chaibuilder/blocks":"^0.1.0","@floating-ui/dom":"1.4.5","@floating-ui/react-dom":"2.0.1","@mhsdesign/jit-browser-tailwindcss":"0.3.0","@minoru/react-dnd-treeview":"3.4.4","@radix-ui/react-accordion":"^1.1.2","@radix-ui/react-alert-dialog":"^1.0.4","@radix-ui/react-context-menu":"^2.1.4","@radix-ui/react-dialog":"^1.0.4","@radix-ui/react-dropdown-menu":"^2.0.5","@radix-ui/react-hover-card":"^1.0.6","@radix-ui/react-icons":"^1.3.0","@radix-ui/react-label":"^2.0.2","@radix-ui/react-menubar":"^1.0.3","@radix-ui/react-navigation-menu":"^1.1.3","@radix-ui/react-popover":"^1.0.6","@radix-ui/react-scroll-area":"^1.0.4","@radix-ui/react-select":"^1.2.2","@radix-ui/react-separator":"^1.0.3","@radix-ui/react-slot":"^1.0.2","@radix-ui/react-switch":"^1.0.3","@radix-ui/react-tabs":"^1.0.4","@radix-ui/react-toast":"^1.1.4","@radix-ui/react-toggle":"^1.0.3","@radix-ui/react-tooltip":"^1.0.6","@react-hookz/web":"23.1.0","@rjsf/core":"5.11.2","@rjsf/utils":"5.11.2","@rjsf/validator-ajv8":"5.11.2","@tailwindcss/aspect-ratio":"0.4.2","@tailwindcss/forms":"^0.5.6","@tailwindcss/line-clamp":"^0.4.4","@tailwindcss/typography":"^0.5.10","@tanstack/react-query":"^5.8.4",analytics:"^0.8.9","class-variance-authority":"0.6.1",clsx:"1.2.1",cmdk:"0.2.0","date-fns":"^2.30.0",flagged:"2.0.9","flat-to-nested":"1.1.1","focus-trap-react":"^10.2.1","forgiving-xml-parser":"1.4.0","framer-motion":"^10.12.18","fuse.js":"6.6.2","gray-matter":"^4.0.3",himalaya:"^1.1.0","html-formatter":"0.1.9",i18next:"^23.2.8",jotai:"2.2.2",lodash:"4.17.21","lucide-react":"^0.244.0",nanoid:"^4.0.2","post-robot":"10.0.46",react:"^18.2.0","react-autosuggest":"10.1.0","react-colorful":"5.6.1","react-dnd":"16.0.1","react-dnd-html5-backend":"16.0.1","react-dom":"^18.2.0","react-hotkeys-hook":"4.4.1","react-i18next":"13.0.1","react-icons":"^4.10.1","react-icons-picker":"^1.0.9","react-quill":"^2.0.0","react-textarea-autosize":"^8.5.2","react-wrap-balancer":"^1.0.0","redux-undo":"1.1.0",sonner:"^1.2.0","tailwind-merge":"1.13.2","tailwindcss-animate":"1.0.6","tippy.js":"^6.3.7","unist-util-visit":"^4.1.2","unsplash-js":"^7.0.18"},Wc={"@commitlint/cli":"17.7.1","@commitlint/config-conventional":"17.7.0","@faker-js/faker":"^8.3.1","@nozbe/watermelondb":"^0.27.1","@playwright/test":"^1.39.0","@tanstack/eslint-plugin-query":"^5.8.4","@testing-library/react-hooks":"^8.0.1","@types/better-sqlite3":"^7.6.7","@types/jest":"^29.5.7","@types/lodash":"^4.14.200","@types/node":"^20.8.10","@types/react":"^18.2.15","@types/react-dom":"^18.2.7","@typescript-eslint/eslint-plugin":"^6.0.0","@typescript-eslint/parser":"^6.0.0","@vitejs/plugin-react-swc":"^3.3.2",autoprefixer:"^10.4.16","better-docs":"^2.7.2","better-sqlite3":"^9.1.1","drizzle-kit":"^0.20.4","drizzle-orm":"^0.29.0",eslint:"^8.45.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-react-refresh":"^0.4.3",jest:"^29.7.0","jest-environment-jsdom":"^29.7.0",jsdoc:"^4.0.2",msw:"^2.0.8",postcss:"^8.4.31",prettier:"^3.0.3","prettier-plugin-tailwindcss":"^0.5.6","prop-types":"^15.8.1","react-router-dom":"^6.19.0",tailwindcss:"^3.3.5","ts-jest":"^29.1.1",typescript:"^5.0.2",vite:"^4.4.5","vite-plugin-dts":"^3.6.3"},Jc={workerDirectory:"public"},Yc={name:Fc,private:!1,version:qc,type:$c,files:Vc,main:Qc,sideEffects:Kc,exports:zc,scripts:Hc,dependencies:Gc,devDependencies:Wc,msw:Jc},Cr="https://api.chaibuilder.com",_r=()=>typeof window>"u"?!1:window.location.href.includes("localhost");function Xc(){return{name:"chaibuilder-analytics",config:{},initialize:()=>{if(typeof window>"u")return!1;window.chaibuilderAnalyticsLoaded=!0},page:e=>{if(typeof window>"u")return!1;if(_r())return;const{payload:t}=e;fetch(`${Cr}/v1/log`,{method:"post",body:JSON.stringify(t)}).then(s=>s.json())},track:({payload:e})=>{if(typeof window>"u")return!1;_r()||fetch(`${Cr}/v1/log`,{method:"post",body:JSON.stringify(e)})},loaded:()=>typeof window>"u"?!0:!!window.chaibuilderAnalyticsLoaded}}const Zc=Uc({app:"chaibuilder",version:Yc.version,plugins:[Xc()]});({}).NODE_ENV==="development"&&console.log("Chai Builder:",Ui);const el=e=>_.jsxRuntimeExports.jsx(_.jsxRuntimeExports.Fragment,{children:e.children}),tl=e=>{const{dndOptions:t={backend:zn.MultiBackend}}=e,[s]=ro(),[,n]=jn(),r=Mn();return B.useEffect(()=>{Qu.set(be.chaiBuilderPropsAtom,l.omit(e,["blocks","globalBlocks","brandingOptions"]))},[e]),B.useEffect(()=>{s(Jr.syncBlocksWithDefaults(e.blocks||[])),r()},[e.blocks]),B.useEffect(()=>{n(e.brandingOptions)},[e.brandingOptions]),B.useEffect(()=>{Zc.page()},[]),_.jsxRuntimeExports.jsx(Oi.DndProvider,{...t,options:zn.getBackendOptions(),children:_.jsxRuntimeExports.jsx(el,{children:_.jsxRuntimeExports.jsx(Vu,{})})})},ui=e=>_.jsxRuntimeExports.jsxs(Yr,{children:[_.jsxRuntimeExports.jsx(Pi.FlagsProvider,{features:Fi,children:_.jsxRuntimeExports.jsx(tl,{...e})}),_.jsxRuntimeExports.jsx(be.Toaster,{})]});var qt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Tt=typeof window>"u"||"Deno"in window;function ve(){}function sl(e,t){return typeof e=="function"?e(t):e}function un(e){return typeof e=="number"&&e>=0&&e!==1/0}function ci(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Br(e,t){const{type:s="all",exact:n,fetchStatus:r,predicate:o,queryKey:i,stale:u}=e;if(i){if(n){if(t.queryHash!==$n(i,t.options))return!1}else if(!es(t.queryKey,i))return!1}if(s!=="all"){const d=t.isActive();if(s==="active"&&!d||s==="inactive"&&d)return!1}return!(typeof u=="boolean"&&t.isStale()!==u||typeof r<"u"&&r!==t.state.fetchStatus||o&&!o(t))}function Ir(e,t){const{exact:s,status:n,predicate:r,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(s){if(Zt(t.options.mutationKey)!==Zt(o))return!1}else if(!es(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||r&&!r(t))}function $n(e,t){return((t==null?void 0:t.queryKeyHashFn)||Zt)(e)}function Zt(e){return JSON.stringify(e,(t,s)=>cn(s)?Object.keys(s).sort().reduce((n,r)=>(n[r]=s[r],n),{}):s)}function es(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(s=>!es(e[s],t[s])):!1}function li(e,t){if(e===t)return e;const s=Rr(e)&&Rr(t);if(s||cn(e)&&cn(t)){const n=s?e.length:Object.keys(e).length,r=s?t:Object.keys(t),o=r.length,i=s?[]:{};let u=0;for(let d=0;d<o;d++){const c=s?d:r[d];i[c]=li(e[c],t[c]),i[c]===e[c]&&u++}return n===o&&u===n?e:i}return t}function Rs(e,t){if(e&&!t||t&&!e)return!1;for(const s in e)if(e[s]!==t[s])return!1;return!0}function Rr(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function cn(e){if(!Dr(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const s=t.prototype;return!(!Dr(s)||!s.hasOwnProperty("isPrototypeOf"))}function Dr(e){return Object.prototype.toString.call(e)==="[object Object]"}function di(e){return new Promise(t=>{setTimeout(t,e)})}function Mr(e){di(0).then(e)}function ln(e,t,s){return typeof s.structuralSharing=="function"?s.structuralSharing(e,t):s.structuralSharing!==!1?li(e,t):t}function nl(e,t,s=0){const n=[...e,t];return s&&n.length>s?n.slice(1):n}function rl(e,t,s=0){const n=[t,...e];return s&&n.length>s?n.slice(0,-1):n}var Xe,qe,bt,Ur,ol=(Ur=class extends qt{constructor(){super();L(this,Xe,void 0);L(this,qe,void 0);L(this,bt,void 0);P(this,bt,t=>{if(!Tt&&window.addEventListener){const s=()=>t();return window.addEventListener("visibilitychange",s,!1),()=>{window.removeEventListener("visibilitychange",s)}}})}onSubscribe(){a(this,qe)||this.setEventListener(a(this,bt))}onUnsubscribe(){var t;this.hasListeners()||((t=a(this,qe))==null||t.call(this),P(this,qe,void 0))}setEventListener(t){var s;P(this,bt,t),(s=a(this,qe))==null||s.call(this),P(this,qe,t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()}))}setFocused(t){a(this,Xe)!==t&&(P(this,Xe,t),this.onFocus())}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){var t;return typeof a(this,Xe)=="boolean"?a(this,Xe):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},Xe=new WeakMap,qe=new WeakMap,bt=new WeakMap,Ur),Ds=new ol,xt,$e,wt,Fr,il=(Fr=class extends qt{constructor(){super();L(this,xt,!0);L(this,$e,void 0);L(this,wt,void 0);P(this,wt,t=>{if(!Tt&&window.addEventListener){const s=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",s,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",n)}}})}onSubscribe(){a(this,$e)||this.setEventListener(a(this,wt))}onUnsubscribe(){var t;this.hasListeners()||((t=a(this,$e))==null||t.call(this),P(this,$e,void 0))}setEventListener(t){var s;P(this,wt,t),(s=a(this,$e))==null||s.call(this),P(this,$e,t(this.setOnline.bind(this)))}setOnline(t){a(this,xt)!==t&&(P(this,xt,t),this.listeners.forEach(n=>{n(t)}))}isOnline(){return a(this,xt)}},xt=new WeakMap,$e=new WeakMap,wt=new WeakMap,Fr),Ms=new il;function al(e){return Math.min(1e3*2**e,3e4)}function Ks(e){return(e??"online")==="online"?Ms.isOnline():!0}var fi=class{constructor(e){this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function en(e){return e instanceof fi}function hi(e){let t=!1,s=0,n=!1,r,o,i;const u=new Promise((b,O)=>{o=b,i=O}),d=b=>{var O;n||(v(new fi(b)),(O=e.abort)==null||O.call(e))},c=()=>{t=!0},h=()=>{t=!1},m=()=>!Ds.isFocused()||e.networkMode!=="always"&&!Ms.isOnline(),k=b=>{var O;n||(n=!0,(O=e.onSuccess)==null||O.call(e,b),r==null||r(),o(b))},v=b=>{var O;n||(n=!0,(O=e.onError)==null||O.call(e,b),r==null||r(),i(b))},C=()=>new Promise(b=>{var O;r=R=>{const M=n||!m();return M&&b(R),M},(O=e.onPause)==null||O.call(e)}).then(()=>{var b;r=void 0,n||(b=e.onContinue)==null||b.call(e)}),I=()=>{if(n)return;let b;try{b=e.fn()}catch(O){b=Promise.reject(O)}Promise.resolve(b).then(k).catch(O=>{var q;if(n)return;const R=e.retry??(Tt?0:3),M=e.retryDelay??al,w=typeof M=="function"?M(s,O):M,A=R===!0||typeof R=="number"&&s<R||typeof R=="function"&&R(s,O);if(t||!A){v(O);return}s++,(q=e.onFail)==null||q.call(e,s,O),di(w).then(()=>{if(m())return C()}).then(()=>{t?v(O):I()})})};return Ks(e.networkMode)?I():C().then(I),{promise:u,cancel:d,continue:()=>(r==null?void 0:r())?u:Promise.resolve(),cancelRetry:c,continueRetry:h}}function ul(){let e=[],t=0,s=h=>{h()},n=h=>{h()};const r=h=>{let m;t++;try{m=h()}finally{t--,t||u()}return m},o=h=>{t?e.push(h):Mr(()=>{s(h)})},i=h=>(...m)=>{o(()=>{h(...m)})},u=()=>{const h=e;e=[],h.length&&Mr(()=>{n(()=>{h.forEach(m=>{s(m)})})})};return{batch:r,batchCalls:i,schedule:o,setNotifyFunction:h=>{s=h},setBatchNotifyFunction:h=>{n=h}}}var se=ul(),Ze,qr,pi=(qr=class{constructor(){L(this,Ze,void 0)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),un(this.gcTime)&&P(this,Ze,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Tt?1/0:5*60*1e3))}clearGcTimeout(){a(this,Ze)&&(clearTimeout(a(this,Ze)),P(this,Ze,void 0))}},Ze=new WeakMap,qr),St,Et,pe,Ve,me,ne,ts,et,kt,Os,Se,Ie,$r,cl=($r=class extends pi{constructor(t){super();L(this,kt);L(this,Se);L(this,St,void 0);L(this,Et,void 0);L(this,pe,void 0);L(this,Ve,void 0);L(this,me,void 0);L(this,ne,void 0);L(this,ts,void 0);L(this,et,void 0);P(this,et,!1),P(this,ts,t.defaultOptions),K(this,kt,Os).call(this,t.options),P(this,ne,[]),P(this,pe,t.cache),this.queryKey=t.queryKey,this.queryHash=t.queryHash,P(this,St,t.state||ll(this.options)),this.state=a(this,St),this.scheduleGc()}get meta(){return this.options.meta}optionalRemove(){!a(this,ne).length&&this.state.fetchStatus==="idle"&&a(this,pe).remove(this)}setData(t,s){const n=ln(this.state.data,t,this.options);return K(this,Se,Ie).call(this,{data:n,type:"success",dataUpdatedAt:s==null?void 0:s.updatedAt,manual:s==null?void 0:s.manual}),n}setState(t,s){K(this,Se,Ie).call(this,{type:"setState",state:t,setStateOptions:s})}cancel(t){var n;const s=a(this,Ve);return(n=a(this,me))==null||n.cancel(t),s?s.then(ve).catch(ve):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(a(this,St))}isActive(){return a(this,ne).some(t=>t.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||a(this,ne).some(t=>t.getCurrentResult().isStale)}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!ci(this.state.dataUpdatedAt,t)}onFocus(){var s;const t=a(this,ne).find(n=>n.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(s=a(this,me))==null||s.continue()}onOnline(){var s;const t=a(this,ne).find(n=>n.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(s=a(this,me))==null||s.continue()}addObserver(t){a(this,ne).includes(t)||(a(this,ne).push(t),this.clearGcTimeout(),a(this,pe).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){a(this,ne).includes(t)&&(P(this,ne,a(this,ne).filter(s=>s!==t)),a(this,ne).length||(a(this,me)&&(a(this,et)?a(this,me).cancel({revert:!0}):a(this,me).cancelRetry()),this.scheduleGc()),a(this,pe).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return a(this,ne).length}invalidate(){this.state.isInvalidated||K(this,Se,Ie).call(this,{type:"invalidate"})}fetch(t,s){var c,h,m,k;if(this.state.fetchStatus!=="idle"){if(this.state.dataUpdatedAt&&(s!=null&&s.cancelRefetch))this.cancel({silent:!0});else if(a(this,Ve))return(c=a(this,me))==null||c.continueRetry(),a(this,Ve)}if(t&&K(this,kt,Os).call(this,t),!this.options.queryFn){const v=a(this,ne).find(C=>C.options.queryFn);v&&K(this,kt,Os).call(this,v.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const n=new AbortController,r={queryKey:this.queryKey,meta:this.meta},o=v=>{Object.defineProperty(v,"signal",{enumerable:!0,get:()=>(P(this,et,!0),n.signal)})};o(r);const i=()=>this.options.queryFn?(P(this,et,!1),this.options.persister?this.options.persister(this.options.queryFn,r,this):this.options.queryFn(r)):Promise.reject(new Error(`Missing queryFn: '${this.options.queryHash}'`)),u={fetchOptions:s,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};o(u),(h=this.options.behavior)==null||h.onFetch(u,this),P(this,Et,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((m=u.fetchOptions)==null?void 0:m.meta))&&K(this,Se,Ie).call(this,{type:"fetch",meta:(k=u.fetchOptions)==null?void 0:k.meta});const d=v=>{var C,I,b,O;en(v)&&v.silent||K(this,Se,Ie).call(this,{type:"error",error:v}),en(v)||((I=(C=a(this,pe).config).onError)==null||I.call(C,v,this),(O=(b=a(this,pe).config).onSettled)==null||O.call(b,this.state.data,v,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return P(this,me,hi({fn:u.fetchFn,abort:n.abort.bind(n),onSuccess:v=>{var C,I,b,O;if(typeof v>"u"){process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),d(new Error(`${this.queryHash} data is undefined`));return}this.setData(v),(I=(C=a(this,pe).config).onSuccess)==null||I.call(C,v,this),(O=(b=a(this,pe).config).onSettled)==null||O.call(b,v,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:d,onFail:(v,C)=>{K(this,Se,Ie).call(this,{type:"failed",failureCount:v,error:C})},onPause:()=>{K(this,Se,Ie).call(this,{type:"pause"})},onContinue:()=>{K(this,Se,Ie).call(this,{type:"continue"})},retry:u.options.retry,retryDelay:u.options.retryDelay,networkMode:u.options.networkMode})),P(this,Ve,a(this,me).promise),a(this,Ve)}},St=new WeakMap,Et=new WeakMap,pe=new WeakMap,Ve=new WeakMap,me=new WeakMap,ne=new WeakMap,ts=new WeakMap,et=new WeakMap,kt=new WeakSet,Os=function(t){this.options={...a(this,ts),...t},this.updateGcTime(this.options.gcTime)},Se=new WeakSet,Ie=function(t){const s=n=>{switch(t.type){case"failed":return{...n,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:Ks(this.options.networkMode)?"fetching":"paused",...!n.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...n,data:t.data,dataUpdateCount:n.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const r=t.error;return en(r)&&r.revert&&a(this,Et)?{...a(this,Et),fetchStatus:"idle"}:{...n,error:r,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...t.state}}};this.state=s(this.state),se.batch(()=>{a(this,ne).forEach(n=>{n.onQueryUpdate()}),a(this,pe).notify({query:this,type:"updated",action:t})})},$r);function ll(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,s=typeof t<"u",n=s?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:s?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}var Ae,Vr,dl=(Vr=class extends qt{constructor(t={}){super();L(this,Ae,void 0);this.config=t,P(this,Ae,new Map)}build(t,s,n){const r=s.queryKey,o=s.queryHash??$n(r,s);let i=this.get(o);return i||(i=new cl({cache:this,queryKey:r,queryHash:o,options:t.defaultQueryOptions(s),state:n,defaultOptions:t.getQueryDefaults(r)}),this.add(i)),i}add(t){a(this,Ae).has(t.queryHash)||(a(this,Ae).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const s=a(this,Ae).get(t.queryHash);s&&(t.destroy(),s===t&&a(this,Ae).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){se.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return a(this,Ae).get(t)}getAll(){return[...a(this,Ae).values()]}find(t){const s={exact:!0,...t};return this.getAll().find(n=>Br(s,n))}findAll(t={}){const s=this.getAll();return Object.keys(t).length>0?s.filter(n=>Br(t,n)):s}notify(t){se.batch(()=>{this.listeners.forEach(s=>{s(t)})})}onFocus(){se.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){se.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Ae=new WeakMap,Vr),Pe,ss,fe,At,Oe,Ne,Qr,fl=(Qr=class extends pi{constructor(t){super();L(this,Oe);L(this,Pe,void 0);L(this,ss,void 0);L(this,fe,void 0);L(this,At,void 0);this.mutationId=t.mutationId,P(this,ss,t.defaultOptions),P(this,fe,t.mutationCache),P(this,Pe,[]),this.state=t.state||mi(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...a(this,ss),...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){a(this,Pe).includes(t)||(a(this,Pe).push(t),this.clearGcTimeout(),a(this,fe).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){P(this,Pe,a(this,Pe).filter(s=>s!==t)),this.scheduleGc(),a(this,fe).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){a(this,Pe).length||(this.state.status==="pending"?this.scheduleGc():a(this,fe).remove(this))}continue(){var t;return((t=a(this,At))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var r,o,i,u,d,c,h,m,k,v,C,I,b,O,R,M,w,A,q,F;const s=()=>(P(this,At,hi({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(T,g)=>{K(this,Oe,Ne).call(this,{type:"failed",failureCount:T,error:g})},onPause:()=>{K(this,Oe,Ne).call(this,{type:"pause"})},onContinue:()=>{K(this,Oe,Ne).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode})),a(this,At).promise),n=this.state.status==="pending";try{if(!n){K(this,Oe,Ne).call(this,{type:"pending",variables:t}),await((o=(r=a(this,fe).config).onMutate)==null?void 0:o.call(r,t,this));const g=await((u=(i=this.options).onMutate)==null?void 0:u.call(i,t));g!==this.state.context&&K(this,Oe,Ne).call(this,{type:"pending",context:g,variables:t})}const T=await s();return await((c=(d=a(this,fe).config).onSuccess)==null?void 0:c.call(d,T,t,this.state.context,this)),await((m=(h=this.options).onSuccess)==null?void 0:m.call(h,T,t,this.state.context)),await((v=(k=a(this,fe).config).onSettled)==null?void 0:v.call(k,T,null,this.state.variables,this.state.context,this)),await((I=(C=this.options).onSettled)==null?void 0:I.call(C,T,null,t,this.state.context)),K(this,Oe,Ne).call(this,{type:"success",data:T}),T}catch(T){try{throw await((O=(b=a(this,fe).config).onError)==null?void 0:O.call(b,T,t,this.state.context,this)),await((M=(R=this.options).onError)==null?void 0:M.call(R,T,t,this.state.context)),await((A=(w=a(this,fe).config).onSettled)==null?void 0:A.call(w,void 0,T,this.state.variables,this.state.context,this)),await((F=(q=this.options).onSettled)==null?void 0:F.call(q,void 0,T,t,this.state.context)),T}finally{K(this,Oe,Ne).call(this,{type:"error",error:T})}}}},Pe=new WeakMap,ss=new WeakMap,fe=new WeakMap,At=new WeakMap,Oe=new WeakSet,Ne=function(t){const s=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!Ks(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=s(this.state),se.batch(()=>{a(this,Pe).forEach(n=>{n.onMutationUpdate(t)}),a(this,fe).notify({mutation:this,type:"updated",action:t})})},Qr);function mi(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var ge,ns,tt,Kr,hl=(Kr=class extends qt{constructor(t={}){super();L(this,ge,void 0);L(this,ns,void 0);L(this,tt,void 0);this.config=t,P(this,ge,[]),P(this,ns,0)}build(t,s,n){const r=new fl({mutationCache:this,mutationId:++vs(this,ns)._,options:t.defaultMutationOptions(s),state:n});return this.add(r),r}add(t){a(this,ge).push(t),this.notify({type:"added",mutation:t})}remove(t){P(this,ge,a(this,ge).filter(s=>s!==t)),this.notify({type:"removed",mutation:t})}clear(){se.batch(()=>{a(this,ge).forEach(t=>{this.remove(t)})})}getAll(){return a(this,ge)}find(t){const s={exact:!0,...t};return a(this,ge).find(n=>Ir(s,n))}findAll(t={}){return a(this,ge).filter(s=>Ir(t,s))}notify(t){se.batch(()=>{this.listeners.forEach(s=>{s(t)})})}resumePausedMutations(){return P(this,tt,(a(this,tt)??Promise.resolve()).then(()=>{const t=a(this,ge).filter(s=>s.state.isPaused);return se.batch(()=>t.reduce((s,n)=>s.then(()=>n.continue().catch(ve)),Promise.resolve()))}).then(()=>{P(this,tt,void 0)})),a(this,tt)}},ge=new WeakMap,ns=new WeakMap,tt=new WeakMap,Kr);function pl(e){return{onFetch:(t,s)=>{const n=async()=>{var C,I,b,O,R;const r=t.options,o=(b=(I=(C=t.fetchOptions)==null?void 0:C.meta)==null?void 0:I.fetchMore)==null?void 0:b.direction,i=((O=t.state.data)==null?void 0:O.pages)||[],u=((R=t.state.data)==null?void 0:R.pageParams)||[],d={pages:[],pageParams:[]};let c=!1;const h=M=>{Object.defineProperty(M,"signal",{enumerable:!0,get:()=>(t.signal.aborted?c=!0:t.signal.addEventListener("abort",()=>{c=!0}),t.signal)})},m=t.options.queryFn||(()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`))),k=async(M,w,A)=>{if(c)return Promise.reject();if(w==null&&M.pages.length)return Promise.resolve(M);const q={queryKey:t.queryKey,pageParam:w,direction:A?"backward":"forward",meta:t.options.meta};h(q);const F=await m(q),{maxPages:T}=t.options,g=A?rl:nl;return{pages:g(M.pages,F,T),pageParams:g(M.pageParams,w,T)}};let v;if(o&&i.length){const M=o==="backward",w=M?ml:Lr,A={pages:i,pageParams:u},q=w(r,A);v=await k(A,q,M)}else{v=await k(d,u[0]??r.initialPageParam);const M=e??i.length;for(let w=1;w<M;w++){const A=Lr(r,v);v=await k(v,A)}}return v};t.options.persister?t.fetchFn=()=>{var r,o;return(o=(r=t.options).persister)==null?void 0:o.call(r,n,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s)}:t.fetchFn=n}}}function Lr(e,{pages:t,pageParams:s}){const n=t.length-1;return e.getNextPageParam(t[n],t,s[n],s)}function ml(e,{pages:t,pageParams:s}){var n;return(n=e.getPreviousPageParam)==null?void 0:n.call(e,t[0],t,s[0],s)}var te,Qe,Ke,Pt,Ot,ze,jt,Ct,zr,gl=(zr=class{constructor(e={}){L(this,te,void 0);L(this,Qe,void 0);L(this,Ke,void 0);L(this,Pt,void 0);L(this,Ot,void 0);L(this,ze,void 0);L(this,jt,void 0);L(this,Ct,void 0);P(this,te,e.queryCache||new dl),P(this,Qe,e.mutationCache||new hl),P(this,Ke,e.defaultOptions||{}),P(this,Pt,new Map),P(this,Ot,new Map),P(this,ze,0)}mount(){vs(this,ze)._++,a(this,ze)===1&&(P(this,jt,Ds.subscribe(()=>{Ds.isFocused()&&(this.resumePausedMutations(),a(this,te).onFocus())})),P(this,Ct,Ms.subscribe(()=>{Ms.isOnline()&&(this.resumePausedMutations(),a(this,te).onOnline())})))}unmount(){var e,t;vs(this,ze)._--,a(this,ze)===0&&((e=a(this,jt))==null||e.call(this),P(this,jt,void 0),(t=a(this,Ct))==null||t.call(this),P(this,Ct,void 0))}isFetching(e){return a(this,te).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return a(this,Qe).findAll({...e,status:"pending"}).length}getQueryData(e){var t;return(t=a(this,te).find({queryKey:e}))==null?void 0:t.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);return t!==void 0?Promise.resolve(t):this.fetchQuery(e)}getQueriesData(e){return this.getQueryCache().findAll(e).map(({queryKey:t,state:s})=>{const n=s.data;return[t,n]})}setQueryData(e,t,s){const n=a(this,te).find({queryKey:e}),r=n==null?void 0:n.state.data,o=sl(t,r);if(typeof o>"u")return;const i=this.defaultQueryOptions({queryKey:e});return a(this,te).build(this,i).setData(o,{...s,manual:!0})}setQueriesData(e,t,s){return se.batch(()=>this.getQueryCache().findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,s)]))}getQueryState(e){var t;return(t=a(this,te).find({queryKey:e}))==null?void 0:t.state}removeQueries(e){const t=a(this,te);se.batch(()=>{t.findAll(e).forEach(s=>{t.remove(s)})})}resetQueries(e,t){const s=a(this,te),n={type:"active",...e};return se.batch(()=>(s.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries(n,t)))}cancelQueries(e={},t={}){const s={revert:!0,...t},n=se.batch(()=>a(this,te).findAll(e).map(r=>r.cancel(s)));return Promise.all(n).then(ve).catch(ve)}invalidateQueries(e={},t={}){return se.batch(()=>{if(a(this,te).findAll(e).forEach(n=>{n.invalidate()}),e.refetchType==="none")return Promise.resolve();const s={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(s,t)})}refetchQueries(e={},t){const s={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},n=se.batch(()=>a(this,te).findAll(e).filter(r=>!r.isDisabled()).map(r=>{let o=r.fetch(void 0,s);return s.throwOnError||(o=o.catch(ve)),r.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(ve)}fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const s=a(this,te).build(this,t);return s.isStaleByTime(t.staleTime)?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(ve).catch(ve)}fetchInfiniteQuery(e){return e.behavior=pl(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(ve).catch(ve)}resumePausedMutations(){return a(this,Qe).resumePausedMutations()}getQueryCache(){return a(this,te)}getMutationCache(){return a(this,Qe)}getDefaultOptions(){return a(this,Ke)}setDefaultOptions(e){P(this,Ke,e)}setQueryDefaults(e,t){a(this,Pt).set(Zt(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...a(this,Pt).values()];let s={};return t.forEach(n=>{es(e,n.queryKey)&&(s={...s,...n.defaultOptions})}),s}setMutationDefaults(e,t){a(this,Ot).set(Zt(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...a(this,Ot).values()];let s={};return t.forEach(n=>{es(e,n.mutationKey)&&(s={...s,...n.defaultOptions})}),s}defaultQueryOptions(e){if(e!=null&&e._defaulted)return e;const t={...a(this,Ke).queries,...(e==null?void 0:e.queryKey)&&this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=$n(t.queryKey,t)),typeof t.refetchOnReconnect>"u"&&(t.refetchOnReconnect=t.networkMode!=="always"),typeof t.throwOnError>"u"&&(t.throwOnError=!!t.suspense),typeof t.networkMode>"u"&&t.persister&&(t.networkMode="offlineFirst"),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...a(this,Ke).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){a(this,te).clear(),a(this,Qe).clear()}},te=new WeakMap,Qe=new WeakMap,Ke=new WeakMap,Pt=new WeakMap,Ot=new WeakMap,ze=new WeakMap,jt=new WeakMap,Ct=new WeakMap,zr),ce,Z,_t,ie,st,Bt,je,rs,It,Rt,nt,rt,He,ot,it,zt,os,dn,is,fn,as,hn,us,pn,cs,mn,ls,gn,ds,yn,Ls,gi,Hr,yl=(Hr=class extends qt{constructor(t,s){super();L(this,it);L(this,os);L(this,is);L(this,as);L(this,us);L(this,cs);L(this,ls);L(this,ds);L(this,Ls);L(this,ce,void 0);L(this,Z,void 0);L(this,_t,void 0);L(this,ie,void 0);L(this,st,void 0);L(this,Bt,void 0);L(this,je,void 0);L(this,rs,void 0);L(this,It,void 0);L(this,Rt,void 0);L(this,nt,void 0);L(this,rt,void 0);L(this,He,void 0);L(this,ot,void 0);P(this,Z,void 0),P(this,_t,void 0),P(this,ie,void 0),P(this,ot,new Set),P(this,ce,t),this.options=s,P(this,je,null),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(a(this,Z).addObserver(this),Nr(a(this,Z),this.options)?K(this,it,zt).call(this):this.updateResult(),K(this,us,pn).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return vn(a(this,Z),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return vn(a(this,Z),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,K(this,cs,mn).call(this),K(this,ls,gn).call(this),a(this,Z).removeObserver(this)}setOptions(t,s){const n=this.options,r=a(this,Z);if(this.options=a(this,ce).defaultQueryOptions(t),Rs(n,this.options)||a(this,ce).getQueryCache().notify({type:"observerOptionsUpdated",query:a(this,Z),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),K(this,ds,yn).call(this);const o=this.hasListeners();o&&Tr(a(this,Z),r,this.options,n)&&K(this,it,zt).call(this),this.updateResult(s),o&&(a(this,Z)!==r||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&K(this,os,dn).call(this);const i=K(this,is,fn).call(this);o&&(a(this,Z)!==r||this.options.enabled!==n.enabled||i!==a(this,He))&&K(this,as,hn).call(this,i)}getOptimisticResult(t){const s=a(this,ce).getQueryCache().build(a(this,ce),t),n=this.createResult(s,t);return bl(this,n)&&(P(this,ie,n),P(this,Bt,this.options),P(this,st,a(this,Z).state)),n}getCurrentResult(){return a(this,ie)}trackResult(t){const s={};return Object.keys(t).forEach(n=>{Object.defineProperty(s,n,{configurable:!1,enumerable:!0,get:()=>(a(this,ot).add(n),t[n])})}),s}getCurrentQuery(){return a(this,Z)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const s=a(this,ce).defaultQueryOptions(t),n=a(this,ce).getQueryCache().build(a(this,ce),s);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,s))}fetch(t){return K(this,it,zt).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),a(this,ie)))}createResult(t,s){var q;const n=a(this,Z),r=this.options,o=a(this,ie),i=a(this,st),u=a(this,Bt),c=t!==n?t.state:a(this,_t),{state:h}=t;let{error:m,errorUpdatedAt:k,fetchStatus:v,status:C}=h,I=!1,b;if(s._optimisticResults){const F=this.hasListeners(),T=!F&&Nr(t,s),g=F&&Tr(t,n,s,r);(T||g)&&(v=Ks(t.options.networkMode)?"fetching":"paused",h.dataUpdatedAt||(C="pending")),s._optimisticResults==="isRestoring"&&(v="idle")}if(s.select&&typeof h.data<"u")if(o&&h.data===(i==null?void 0:i.data)&&s.select===a(this,rs))b=a(this,It);else try{P(this,rs,s.select),b=s.select(h.data),b=ln(o==null?void 0:o.data,b,s),P(this,It,b),P(this,je,null)}catch(F){P(this,je,F)}else b=h.data;if(typeof s.placeholderData<"u"&&typeof b>"u"&&C==="pending"){let F;if(o!=null&&o.isPlaceholderData&&s.placeholderData===(u==null?void 0:u.placeholderData))F=o.data;else if(F=typeof s.placeholderData=="function"?s.placeholderData((q=a(this,Rt))==null?void 0:q.state.data,a(this,Rt)):s.placeholderData,s.select&&typeof F<"u")try{F=s.select(F),P(this,je,null)}catch(T){P(this,je,T)}typeof F<"u"&&(C="success",b=ln(o==null?void 0:o.data,F,s),I=!0)}a(this,je)&&(m=a(this,je),b=a(this,It),k=Date.now(),C="error");const O=v==="fetching",R=C==="pending",M=C==="error",w=R&&O;return{status:C,fetchStatus:v,isPending:R,isSuccess:C==="success",isError:M,isInitialLoading:w,isLoading:w,data:b,dataUpdatedAt:h.dataUpdatedAt,error:m,errorUpdatedAt:k,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>c.dataUpdateCount||h.errorUpdateCount>c.errorUpdateCount,isFetching:O,isRefetching:O&&!R,isLoadingError:M&&h.dataUpdatedAt===0,isPaused:v==="paused",isPlaceholderData:I,isRefetchError:M&&h.dataUpdatedAt!==0,isStale:Vn(t,s),refetch:this.refetch}}updateResult(t){const s=a(this,ie),n=this.createResult(a(this,Z),this.options);if(P(this,st,a(this,Z).state),P(this,Bt,this.options),a(this,st).data!==void 0&&P(this,Rt,a(this,Z)),Rs(n,s))return;P(this,ie,n);const r={},o=()=>{if(!s)return!0;const{notifyOnChangeProps:i}=this.options,u=typeof i=="function"?i():i;if(u==="all"||!u&&!a(this,ot).size)return!0;const d=new Set(u??a(this,ot));return this.options.throwOnError&&d.add("error"),Object.keys(a(this,ie)).some(c=>{const h=c;return a(this,ie)[h]!==s[h]&&d.has(h)})};(t==null?void 0:t.listeners)!==!1&&o()&&(r.listeners=!0),K(this,Ls,gi).call(this,{...r,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&K(this,us,pn).call(this)}},ce=new WeakMap,Z=new WeakMap,_t=new WeakMap,ie=new WeakMap,st=new WeakMap,Bt=new WeakMap,je=new WeakMap,rs=new WeakMap,It=new WeakMap,Rt=new WeakMap,nt=new WeakMap,rt=new WeakMap,He=new WeakMap,ot=new WeakMap,it=new WeakSet,zt=function(t){K(this,ds,yn).call(this);let s=a(this,Z).fetch(this.options,t);return t!=null&&t.throwOnError||(s=s.catch(ve)),s},os=new WeakSet,dn=function(){if(K(this,cs,mn).call(this),Tt||a(this,ie).isStale||!un(this.options.staleTime))return;const s=ci(a(this,ie).dataUpdatedAt,this.options.staleTime)+1;P(this,nt,setTimeout(()=>{a(this,ie).isStale||this.updateResult()},s))},is=new WeakSet,fn=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(a(this,Z)):this.options.refetchInterval)??!1},as=new WeakSet,hn=function(t){K(this,ls,gn).call(this),P(this,He,t),!(Tt||this.options.enabled===!1||!un(a(this,He))||a(this,He)===0)&&P(this,rt,setInterval(()=>{(this.options.refetchIntervalInBackground||Ds.isFocused())&&K(this,it,zt).call(this)},a(this,He)))},us=new WeakSet,pn=function(){K(this,os,dn).call(this),K(this,as,hn).call(this,K(this,is,fn).call(this))},cs=new WeakSet,mn=function(){a(this,nt)&&(clearTimeout(a(this,nt)),P(this,nt,void 0))},ls=new WeakSet,gn=function(){a(this,rt)&&(clearInterval(a(this,rt)),P(this,rt,void 0))},ds=new WeakSet,yn=function(){const t=a(this,ce).getQueryCache().build(a(this,ce),this.options);if(t===a(this,Z))return;const s=a(this,Z);P(this,Z,t),P(this,_t,t.state),this.hasListeners()&&(s==null||s.removeObserver(this),t.addObserver(this))},Ls=new WeakSet,gi=function(t){se.batch(()=>{t.listeners&&this.listeners.forEach(s=>{s(a(this,ie))}),a(this,ce).getQueryCache().notify({query:a(this,Z),type:"observerResultsUpdated"})})},Hr);function vl(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function Nr(e,t){return vl(e,t)||e.state.dataUpdatedAt>0&&vn(e,t,t.refetchOnMount)}function vn(e,t,s){if(t.enabled!==!1){const n=typeof s=="function"?s(e):s;return n==="always"||n!==!1&&Vn(e,t)}return!1}function Tr(e,t,s,n){return s.enabled!==!1&&(e!==t||n.enabled===!1)&&(!s.suspense||e.state.status!=="error")&&Vn(e,s)}function Vn(e,t){return e.isStaleByTime(t.staleTime)}function bl(e,t){return!Rs(e.getCurrentResult(),t)}var Ge,ae,ye,Re,Dt,js,fs,bn,Gr,xl=(Gr=class extends qt{constructor(t,s){super();L(this,Dt);L(this,fs);L(this,Ge,void 0);L(this,ae,void 0);L(this,ye,void 0);L(this,Re,void 0);P(this,ae,void 0),P(this,Ge,t),this.setOptions(s),this.bindMethods(),K(this,Dt,js).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var n;const s=this.options;this.options=a(this,Ge).defaultMutationOptions(t),Rs(s,this.options)||a(this,Ge).getMutationCache().notify({type:"observerOptionsUpdated",mutation:a(this,ye),observer:this}),(n=a(this,ye))==null||n.setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=a(this,ye))==null||t.removeObserver(this)}onMutationUpdate(t){K(this,Dt,js).call(this),K(this,fs,bn).call(this,t)}getCurrentResult(){return a(this,ae)}reset(){P(this,ye,void 0),K(this,Dt,js).call(this),K(this,fs,bn).call(this)}mutate(t,s){var n;return P(this,Re,s),(n=a(this,ye))==null||n.removeObserver(this),P(this,ye,a(this,Ge).getMutationCache().build(a(this,Ge),this.options)),a(this,ye).addObserver(this),a(this,ye).execute(t)}},Ge=new WeakMap,ae=new WeakMap,ye=new WeakMap,Re=new WeakMap,Dt=new WeakSet,js=function(){var s;const t=((s=a(this,ye))==null?void 0:s.state)??mi();P(this,ae,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},fs=new WeakSet,bn=function(t){se.batch(()=>{var s,n,r,o,i,u,d,c;a(this,Re)&&this.hasListeners()&&((t==null?void 0:t.type)==="success"?((n=(s=a(this,Re)).onSuccess)==null||n.call(s,t.data,a(this,ae).variables,a(this,ae).context),(o=(r=a(this,Re)).onSettled)==null||o.call(r,t.data,null,a(this,ae).variables,a(this,ae).context)):(t==null?void 0:t.type)==="error"&&((u=(i=a(this,Re)).onError)==null||u.call(i,t.error,a(this,ae).variables,a(this,ae).context),(c=(d=a(this,Re)).onSettled)==null||c.call(d,void 0,t.error,a(this,ae).variables,a(this,ae).context))),this.listeners.forEach(h=>{h(a(this,ae))})})},Gr),yi=re.createContext(void 0),Be=e=>{const t=re.useContext(yi);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},wl=({client:e,children:t})=>(re.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),re.createElement(yi.Provider,{value:e},t)),vi=re.createContext(!1),Sl=()=>re.useContext(vi);vi.Provider;function El(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var kl=re.createContext(El()),Al=()=>re.useContext(kl);function bi(e,t){return typeof e=="function"?e(...t):!!e}var Pl=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},Ol=e=>{re.useEffect(()=>{e.clearReset()},[e])},jl=({result:e,errorResetBoundary:t,throwOnError:s,query:n})=>e.isError&&!t.isReset()&&!e.isFetching&&bi(s,[e.error,n]),Cl=e=>{e.suspense&&typeof e.staleTime!="number"&&(e.staleTime=1e3)},_l=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,Bl=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function Il(e,t,s){if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Be(s),r=Sl(),o=Al(),i=n.defaultQueryOptions(e);i._optimisticResults=r?"isRestoring":"optimistic",Cl(i),Pl(i,o),Ol(o);const[u]=re.useState(()=>new t(n,i)),d=u.getOptimisticResult(i);if(re.useSyncExternalStore(re.useCallback(c=>{const h=r?()=>{}:u.subscribe(se.batchCalls(c));return u.updateResult(),h},[u,r]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),re.useEffect(()=>{u.setOptions(i,{listeners:!1})},[i,u]),_l(i,d))throw Bl(i,u,o);if(jl({result:d,errorResetBoundary:o,throwOnError:i.throwOnError,query:u.getCurrentQuery()}))throw d.error;return i.notifyOnChangeProps?d:u.trackResult(d)}function gs(e,t){return Il(e,yl,t)}function Me(e,t){const s=Be(t),[n]=re.useState(()=>new xl(s,e));re.useEffect(()=>{n.setOptions(e)},[n,e]);const r=re.useSyncExternalStore(re.useCallback(i=>n.subscribe(se.batchCalls(i)),[n]),()=>n.getCurrentResult(),()=>n.getCurrentResult()),o=re.useCallback((i,u)=>{n.mutate(i,u).catch(Rl)},[n]);if(r.error&&bi(n.options.throwOnError,[r.error]))throw r.error;return{...r,mutate:o,mutateAsync:r.mutate}}function Rl(){}function de(){return Be().getQueryData(["apiBaseUrl"])||"/api/chaibuilder"}const $t=()=>{const{data:e,refetch:t}=gs({queryKey:["currentPage"],queryFn:()=>localStorage.getItem("currentPage")||""});return[e,s=>{s&&(localStorage.setItem("currentPage",s||""),t())}]},zs=()=>{const[e,t]=$t(),s=de();return gs({queryKey:["project"],queryFn:async()=>{const n=await fetch(`${s}/project`).then(r=>r.json());if(!e&&n){const r=localStorage.getItem("currentPage");t(r||(n==null?void 0:n.homepage))}return n}})},Qn=()=>{const e=de();return gs({queryKey:["pages"],queryFn:async()=>await fetch(`${e}/pages`).then(s=>s.json())||[]})},Dl=()=>{const[e,t]=$t(),{data:s}=zs(),n=de();return gs({queryKey:["page_data",e],queryFn:async()=>{const r=await fetch(`${n}/page?uuid=${e}`);return r.ok?r.json():(t(s.homepage),null)},enabled:!!e,staleTime:3e3})},xn=()=>_.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-gray-200",children:_.jsxRuntimeExports.jsxs("div",{className:"flex flex-col h-full w-full justify-center items-center",children:[_.jsxRuntimeExports.jsxs("div",{className:"flex flex-row gap-2",children:[_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-orange-600 animate-bounce [animation-delay:.6s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-blue-600 animate-bounce [animation-delay:.4s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-green-600 animate-bounce [animation-delay:.2s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-yellow-600 animate-bounce [animation-delay:.0s]"})]}),_.jsxRuntimeExports.jsx("div",{className:"text-gray-700 font-thin",children:"Loading Builder..."})]})}),xi=(e="Project updated successfully.")=>{const t=Be(),s=de();return Me({mutationFn:async n=>await fetch(`${s}/project`,{method:"PUT",body:JSON.stringify(n)}),onSuccess:()=>{t.invalidateQueries({queryKey:["project"]}),_e.toast.success(e)}})},wi=()=>{const[e]=["SAVED"],[t,s]=$t(),n=Mn();return r=>e!=="SAVED"?(_e.toast.error("You have unsaved changes. Please save before changing the page."),!1):t===r.uuid?!1:(n(),setTimeout(()=>{s(r.uuid)},100),!0)},Ml=()=>{const e=Be(),t=wi(),s=de();return Me({mutationFn:async n=>fetch(`${s}/pages`,{method:"POST",body:JSON.stringify(n)}).then(r=>r.json()),onSuccess:n=>{e.invalidateQueries({queryKey:["pages"]}),t({uuid:n.uuid,slug:n.slug}),_e.toast.success("Page added successfully.")}})},Si=()=>{const e=de();return Me({mutationFn:async t=>fetch(`${e}/page`,{method:"PUT",body:JSON.stringify(t)}),onSuccess:()=>{_e.toast.success("Page saved successfully.")}})},Ll=()=>{const e=de(),{data:t}=Qn(),[s]=$t(),{data:n}=zs();return Me({mutationFn:async()=>{const r=t.find(o=>o.uuid===s).slug;await fetch(`${e}/publish`,{method:"POST",body:JSON.stringify({slug:r,uuid:s,isHomepage:(n==null?void 0:n.homepage)===s})})},onSuccess:()=>{_e.toast.success("Page published successfully.",{position:"top-right",duration:2e3})}})},Nl=()=>{const e=Be(),t=de();return Me({mutationFn:async s=>fetch(`${t}/page`,{method:"DELETE",body:JSON.stringify(s)}),onSuccess:()=>{_e.toast.success("Page deleted successfully."),e.invalidateQueries({queryKey:["pages"]})}})},Tl=()=>{const e=de();return Me({mutationFn:async()=>{const t=await fetch(`${e}/library`).then(s=>s.json());return l.sortBy(l.filter(t,s=>!l.has(s,"hidden")),"group")}})},Ul=()=>{const e=de();return Me({mutationFn:async t=>{if(!t||!t.uuid)return[];try{const s=await fetch(`${e}/block?uuid=${t.uuid}&format=${t.format}`).then(async n=>t.format==="html"?le.getBlocksFromHTML(await n.text()):await n.json());debugger;return l.set(s,"0._name",l.capitalize(t.group)),s||[]}catch{return[]}}})},Fl=()=>{const e=de();return Me({mutationFn:async t=>{const s=new FormData;return s.append("file",t),(await(await fetch(`${e}/upload`,{method:"POST",body:s})).json()).url}})},ql=B.lazy(()=>Promise.resolve().then(()=>require("./PagesPanel-2e626ee0.cjs"))),$l=B.lazy(()=>Promise.resolve().then(()=>require("./ProjectPanel-453caab3.cjs"))),Vl=B.lazy(()=>Promise.resolve().then(()=>require("./CurrentPage-def95a2d.cjs"))),Ql=()=>_.jsxRuntimeExports.jsx("h2",{children:"Your Logo"}),Kl=()=>{const e=Be();return _.jsxRuntimeExports.jsx("div",{className:"border-gray-200 rounded-md p-2 mb-2 border",children:_.jsxRuntimeExports.jsx(_i.LogOutIcon,{className:"w-4 h-4 text-red-500",onClick:()=>{localStorage.removeItem("__anon_token"),e.invalidateQueries({queryKey:["verify"]})}})})},zl=()=>{const{mutate:e}=Ll();return _.jsxRuntimeExports.jsx(be.Button,{onClick:e,className:"bg-blue-600 text-white",children:"Publish"})},Hl=e=>{const{data:t,isLoading:s}=zs(),{data:n,isLoading:r}=Qn(),{data:o}=Dl(),{mutate:i}=xi(),{mutate:u}=Si(),[d]=$t(),c=Fl(),h=Tl(),m=Ul(),k=de(),v=B.useCallback(async R=>await c.mutateAsync(R),[c]),C=B.useCallback(async()=>await h.mutateAsync(),[h]),I=B.useCallback(async R=>await m.mutateAsync(R),[m]),b=async(R=20,M=0)=>{const w=`limit=${R}&offset=${M}`;return await fetch(`${k}/assets?${w}`).then(A=>A.json())},{logo:O=Ql}=e;return s||!t?_.jsxRuntimeExports.jsx(xn,{}):r||!n?_.jsxRuntimeExports.jsx(xn,{}):_.jsxRuntimeExports.jsx("div",{className:"bg-background text-foreground",children:_.jsxRuntimeExports.jsx(ui,{blocks:(o==null?void 0:o.blocks)||[],brandingOptions:t.brandingOptions,darkMode:e.darkMode||!1,onSaveBlocks:async({blocks:R})=>{u({blocks:R,uuid:d})},onSaveBrandingOptions:async R=>{i({brandingOptions:R})},topBarComponents:{left:[O],center:[Vl],right:[zl]},sideBarComponents:{top:[{icon:Cs.FileTextIcon,name:"pages",panel:ql},{icon:Cs.GearIcon,name:"settings",panel:$l}],bottom:[Kl]},uploadMediaCallback:v,fetchMediaCallback:b,getUILibraryBlocks:C,getExternalPredefinedBlock:I,getPages:()=>n})})},Gl=()=>{const e=de(),t=Be();return Me({mutationFn:async s=>{const n=await fetch(`${e}/authenticate`,{method:"POST",body:JSON.stringify(s)});if(n.ok)return await n.json();throw new Error("INvalid")},onSuccess:s=>{if(!s.token){_e.toast.error("Something went wrong. Please try again.");return}localStorage.setItem("__anon_token",s.token),t.invalidateQueries({queryKey:["verify"]}),_e.toast.success("Authenticated successfully.")},onError:()=>{_e.toast.error("Incorrect password. Please try again.")}})},Wl=()=>{const e=de();return gs({queryKey:["verify"],queryFn:async()=>{const t=localStorage.getItem("__anon_token");if(!t)return{valid:!1};const s=await fetch(`${e}/verify?token=`+t,{method:"GET"});return s.ok?(await s.json()).result==="success"?{valid:!0}:(localStorage.removeItem("__anon_token"),{valid:!1}):(localStorage.removeItem("__anon_token"),{valid:!0})}})},Jl=({logo:e})=>{const[t,s]=B.useState(!1),[n,r]=B.useState(""),{mutate:o,isPending:i}=Gl(),u=()=>{o({password:n})};return _.jsxRuntimeExports.jsx("section",{className:"h-screen w-screen flex items-center justify-center bg-[radial-gradient(#AAA,transparent_0.5px)] duration-300 [background-size:6px_6px]",children:_.jsxRuntimeExports.jsx("div",{className:"overflow-hidden bg-white rounded-xl w-96 drop-shadow-2xl duration-300",children:_.jsxRuntimeExports.jsxs("div",{className:"p-12",children:[_.jsxRuntimeExports.jsxs("div",{className:"max-w-2xl mx-auto text-center",children:[_.jsxRuntimeExports.jsx(B.Suspense,{children:e?B.createElement(e):""}),_.jsxRuntimeExports.jsx("p",{className:"max-w-xl mx-auto text-base leading-relaxed text-gray-700 font-thin",children:"Enter your app password to continue"})]}),_.jsxRuntimeExports.jsx("div",{className:"mt-8",children:_.jsxRuntimeExports.jsxs("div",{className:"space-y-5",children:[_.jsxRuntimeExports.jsx("div",{children:_.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[_.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:_.jsxRuntimeExports.jsx("svg",{className:"w-5 h-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:_.jsxRuntimeExports.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4"})})}),_.jsxRuntimeExports.jsx("input",{value:n,onChange:d=>r(d.target.value),type:t?"text":"password",id:"pwd",placeholder:"Enter password",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"}),_.jsxRuntimeExports.jsx("button",{className:"absolute inset-y-0 right-4 flex items-center pl-3 cursor-pointer",onClick:()=>s(!t),children:t?_.jsxRuntimeExports.jsx(Cs.EyeClosedIcon,{}):_.jsxRuntimeExports.jsx(Cs.EyeOpenIcon,{})})]})}),_.jsxRuntimeExports.jsx("div",{children:_.jsxRuntimeExports.jsx("button",{disabled:i||l.isEmpty(n)||n.length<3,onClick:u,type:"button",className:"inline-flex disabled:bg-gray-400 items-center justify-center w-full px-4 py-4 text-base font-semibold text-white transition-all duration-200 bg-blue-600 border border-transparent rounded-md focus:outline-none hover:bg-blue-700 focus:bg-blue-700",children:i?"Authenticating...":"Authenticate"})})]})})]})})})},Yl=e=>{const{data:t,isLoading:s}=Wl(),n=Be();return B.useEffect(()=>{n.setQueryData(["apiBaseUrl"],e.apiBaseUrl||"/api/chaibuilder")},[e.apiBaseUrl,n]),s?_.jsxRuntimeExports.jsx(xn,{}):t!=null&&t.valid?_.jsxRuntimeExports.jsx(Hl,{...e}):_.jsxRuntimeExports.jsx(Jl,{logo:e.logo})},Xl=new gl,Zl=e=>_.jsxRuntimeExports.jsxs(wl,{client:Xl,children:[_.jsxRuntimeExports.jsx(_e.Toaster,{richColors:!0}),_.jsxRuntimeExports.jsx(Yl,{...e})]});exports.ChaiBuilderEditor=ui;exports.ChaiBuilderStudio=Zl;exports.ErrorBoundary=Yr;exports.activePanelAtom=ko;exports.addBlockOffCanvasAtom=Ao;exports.addBlocksModalAtom=no;exports.advanceStylingOpenAtom=xo;exports.canDeleteBlock=va;exports.canDropBlock=xa;exports.canDuplicateBlock=ya;exports.canvasIframeAtom=Eo;exports.editLayerNameAtom=So;exports.getBlockJSONFromSchemas=nn;exports.getBlockJSONFromUISchemas=sn;exports.inlineEditingActiveAtom=bo;exports.networkModeAtom=wo;exports.showPredefinedBlockCategoryAtom=Po;exports.useActiveLanguage=Fo;exports.useActiveModal=mu;exports.useActivePanel=bu;exports.useAddBlock=Oa;exports.useAddBlockParent=xu;exports.useAddClassesToBlocks=Ia;exports.useAddPage=Ml;exports.useAllBlocks=co;exports.useBlockContentByLanguage=Ru;exports.useBrandingOptions=jn;exports.useBuilderReset=Mn;exports.useBuildingBlocks=fo;exports.useCanvasHistory=ps;exports.useCanvasWidth=Ka;exports.useCanvasZoom=Ha;exports.useChangePage=wi;exports.useCopyBlockIds=Bo;exports.useCurrentPage=$t;exports.useCurrentPage$1=ho;exports.useCutBlockIds=In;exports.useDarkMode=Ga;exports.useDeletePage=Nl;exports.useDeveloperPreviewMode=Ja;exports.useDuplicateBlocks=Dn;exports.useExpandedIds=Tu;exports.useFeatureSupport=Au;exports.useGetPageData=Bn;exports.useHiddenBlockIds=Xa;exports.useHighlightBlockId=Ro;exports.useLanguages=Iu;exports.useMarkAsGlobalBlock=eu;exports.useMoveBlocks=tu;exports.usePages=Qn;exports.usePasteBlocks=Do;exports.usePreviewMode=On;exports.usePrimaryLanguage=Bu;exports.useProject=zs;exports.useProject$1=ru;exports.useQueryClient=Be;exports.useReadOnlyMode=gu;exports.useRemoveBlocks=Lo;exports.useRemoveClassesFromBlocks=iu;exports.useSavePage=Qa;exports.useSelectedBlock=ka;exports.useSelectedBlockAllClasses=au;exports.useSelectedBlockCurrentClasses=lu;exports.useSelectedBlockIds=Je;exports.useSelectedBlocksDisplayChild=Ea;exports.useSelectedBreakpoints=Su;exports.useSelectedStylingBlocks=Pn;exports.useSetAllBlocks=ro;exports.useStylingBreakpoint=Oo;exports.useStylingState=du;exports.useTranslations=ku;exports.useTreeData=ga;exports.useUILibraryBlocks=Ou;exports.useUpdateBlocksProps=fu;exports.useUpdateBlocksPropsRealtime=hu;exports.useUpdatePage=Si;exports.useUpdateProject=xi;
1
+ "use strict";var Gs=(e,t,s)=>{if(!t.has(e))throw TypeError("Cannot "+s)};var a=(e,t,s)=>(Gs(e,t,"read from private field"),s?s.call(e):t.get(e)),L=(e,t,s)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,s)},P=(e,t,s,n)=>(Gs(e,t,"write to private field"),n?n.call(e,s):t.set(e,s),s);var vs=(e,t,s,n)=>({set _(r){P(e,t,r,s)},get _(){return a(e,t,n)}}),K=(e,t,s)=>(Gs(e,t,"access private method"),s);const _=require("./jsx-runtime-5c3ac4f7.cjs"),ki=require("i18next"),Ai=require("react-i18next"),Pi=require("flagged"),B=require("react"),Oi=require("react-dnd"),l=require("lodash"),zn=require("@minoru/react-dnd-treeview"),be=require("./useBuilderProp-5e57d0c8.cjs"),y=require("jotai"),ji=require("./utils-3c452dd0.cjs"),Le=require("react-hotkeys-hook"),Wr=require("flat-to-nested"),le=require("./html-to-json-78bfa1f3.cjs"),Ht=require("redux-undo"),Ci=require("@react-hookz/web"),ue=require("./MODIFIERS-70fef873.cjs"),Jr=require("@chaibuilder/blocks"),Cs=require("@radix-ui/react-icons"),_i=require("lucide-react"),_e=require("sonner");function Bi(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const re=Bi(B),Ii="Dark mode",Ri="This page has no blocks. Add a block by clicking the + button",Di="This page is empty",Mi="Please select a block to edit settings or styles",Li="Please select a styling block",Ni="Drop your block here",Ti={dark_mode:Ii,tree_view_no_blocks:Ri,canvas_empty:Di,no_block_selected_for_styling:Mi,no_styling_block_selected:Li,drop_here_message:Ni};ki.use(Ai.initReactI18next).init({resources:{en:{translation:Ti}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});const Ui="";const Fi={};class Yr extends B.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(t){return console.error(t),{hasError:!0}}render(){return this.state.hasError?_.jsxRuntimeExports.jsx("h1",{children:"Something went wrong."}):this.props.children}}const qi=e=>{const t=e.replace(ue.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}};let $i=0;function Ue(e,t){const s=`atom${++$i}`,n={toString:()=>s};return typeof e=="function"?n.read=e:(n.init=e,n.read=r=>r(n),n.write=(r,o,i)=>o(n,typeof i=="function"?i(r(n)):i)),t&&(n.write=t),n}const Hn=e=>"init"in e,Gn=e=>!!e.write,_s=new WeakMap,Vi=(e,t)=>{_s.set(e,t),e.catch(()=>{}).finally(()=>_s.delete(e))},Wn=(e,t)=>{const s=_s.get(e);s&&(_s.delete(e),s(t))},Jn=(e,t)=>{e.status="fulfilled",e.value=t},Yn=(e,t)=>{e.status="rejected",e.reason=t},Qi=e=>typeof(e==null?void 0:e.then)=="function",Qt=(e,t)=>"v"in e&&"v"in t&&Object.is(e.v,t.v),Xn=(e,t)=>"e"in e&&"e"in t&&Object.is(e.e,t.e),ft=e=>"v"in e&&e.v instanceof Promise,Ki=(e,t)=>"v"in e&&"v"in t&&e.v.orig&&e.v.orig===t.v.orig,bs=e=>{if("e"in e)throw e.e;return e.v},zi=()=>{const e=new WeakMap,t=new WeakMap,s=new Map;let n,r,o;const i=g=>e.get(g),u=(g,x)=>{const D=e.get(g);if(e.set(g,x),s.has(g)||s.set(g,D),D&&ft(D)){const S="v"in x?x.v instanceof Promise?x.v:Promise.resolve(x.v):Promise.reject(x.e);Wn(D.v,S)}},d=(g,x,D)=>{const S=new Map;let N=!1;D.forEach((j,E)=>{!j&&E===g&&(j=x),j&&(S.set(E,j),x.d.get(E)!==j&&(N=!0))}),(N||x.d.size!==S.size)&&(x.d=S)},c=(g,x,D)=>{const S=i(g),N={d:(S==null?void 0:S.d)||new Map,v:x};if(D&&d(g,N,D),S&&Qt(S,N)&&S.d===N.d)return S;if(S&&ft(S)&&ft(N)&&Ki(S,N)){if(S.d===N.d)return S;N.v=S.v}return u(g,N),N},h=(g,x,D,S)=>{if(Qi(x)){let N;const j=new Promise((E,z)=>{let Q=!1;x.then(W=>{if(!Q){Q=!0;const f=i(g),p=c(g,j,D);Jn(j,W),E(W),(f==null?void 0:f.d)!==p.d&&q(g,p,f==null?void 0:f.d)}},W=>{if(!Q){Q=!0;const f=i(g),p=c(g,j,D);Yn(j,W),z(W),(f==null?void 0:f.d)!==p.d&&q(g,p,f==null?void 0:f.d)}}),N=W=>{Q||(Q=!0,W.then(f=>Jn(j,f),f=>Yn(j,f)),E(W))}});return j.orig=x,j.status="pending",Vi(j,E=>{E&&N(E),S==null||S()}),c(g,j,D)}return c(g,x,D)},m=(g,x,D)=>{const S=i(g),N={d:(S==null?void 0:S.d)||new Map,e:x};return D&&d(g,N,D),S&&Xn(S,N)&&S.d===N.d?S:(u(g,N),N)},k=g=>{const x=i(g);if(x&&(x.d.forEach((Q,W)=>{W!==g&&!t.has(W)&&k(W)}),Array.from(x.d).every(([Q,W])=>{const f=i(Q);return Q===g||f===W||f&&!ft(f)&&Qt(f,W)})))return x;const D=new Map;let S=!0;const N=Q=>{if(Q===g){const f=i(Q);if(f)return D.set(Q,f),bs(f);if(Hn(Q))return D.set(Q,void 0),Q.init;throw new Error("no atom init")}const W=k(Q);return D.set(Q,W),bs(W)};let j,E;const z={get signal(){return j||(j=new AbortController),j.signal},get setSelf(){return!E&&Gn(g)&&(E=(...Q)=>{if(!S)return M(g,...Q)}),E}};try{const Q=g.read(N,z);return h(g,Q,D,()=>j==null?void 0:j.abort())}catch(Q){return m(g,Q,D)}finally{S=!1}},v=g=>bs(k(g)),C=g=>{let x=t.get(g);return x||(x=w(g)),x},I=(g,x)=>!x.l.size&&(!x.t.size||x.t.size===1&&x.t.has(g)),b=g=>{const x=t.get(g);x&&I(g,x)&&A(g)},O=g=>{const x=new Map,D=new WeakMap,S=j=>{const E=t.get(j);E==null||E.t.forEach(z=>{z!==j&&(x.set(z,(x.get(z)||new Set).add(j)),D.set(z,(D.get(z)||0)+1),S(z))})};S(g);const N=j=>{const E=t.get(j);E==null||E.t.forEach(z=>{var Q;if(z!==j){let W=D.get(z);if(W&&D.set(z,--W),!W){let f=!!((Q=x.get(z))!=null&&Q.size);if(f){const p=i(z),U=k(z);f=!p||!Qt(p,U)}f||x.forEach(p=>p.delete(z))}N(z)}})};N(g)},R=(g,...x)=>{let D=!0;const S=E=>bs(k(E)),N=(E,...z)=>{let Q;if(E===g){if(!Hn(E))throw new Error("atom not writable");const W=i(E),f=h(E,z[0]);(!W||!Qt(W,f))&&O(E)}else Q=R(E,...z);if(!D){const W=F()}return Q},j=g.write(S,N,...x);return D=!1,j},M=(g,...x)=>{const D=R(g,...x),S=F();return D},w=(g,x)=>{const D={t:new Set(x&&[x]),l:new Set};if(t.set(g,D),k(g).d.forEach((S,N)=>{const j=t.get(N);j?j.t.add(g):N!==g&&w(N,g)}),k(g),Gn(g)&&g.onMount){const S=g.onMount((...N)=>M(g,...N));S&&(D.u=S)}return D},A=g=>{var x;const D=(x=t.get(g))==null?void 0:x.u;D&&D(),t.delete(g);const S=i(g);S&&(ft(S)&&Wn(S.v),S.d.forEach((N,j)=>{if(j!==g){const E=t.get(j);E&&(E.t.delete(g),I(j,E)&&A(j))}}))},q=(g,x,D)=>{const S=new Set(x.d.keys());D==null||D.forEach((N,j)=>{if(S.has(j)){S.delete(j);return}const E=t.get(j);E&&(E.t.delete(g),I(j,E)&&A(j))}),S.forEach(N=>{const j=t.get(N);j?j.t.add(g):t.has(g)&&w(N,g)})},F=()=>{let g;for(;s.size;){const x=Array.from(s);s.clear(),x.forEach(([D,S])=>{const N=i(D);if(N){N.d!==(S==null?void 0:S.d)&&q(D,N,S==null?void 0:S.d);const j=t.get(D);j&&!(S&&!ft(S)&&(Qt(S,N)||Xn(S,N)))&&j.l.forEach(E=>E())}})}};return{get:v,set:M,sub:(g,x)=>{const D=C(g),S=F(),N=D.l;return N.add(x),()=>{N.delete(x),b(g)}}}};let Ws;const Hi=()=>(Ws||(Ws=zi()),Ws),Gi=Symbol();function Wi(e,t){const s=Ue(e,(n,r,o)=>r(s,t(n(s),o)));return s}const Zn=(e,t,s)=>(t.has(s)?t:t.set(s,e())).get(s),Ji=new WeakMap,Yi=(e,t,s)=>{const n=Zn(()=>new WeakMap,Ji,t);return Zn(e,n,s)},Xi={},er=e=>!!e.write,Zi=e=>typeof e=="function";function ea(e,t){return Yi(()=>{const s=new WeakMap,n=(i,u)=>{let d=s.get(i);if(d)return d;const c=u&&s.get(u),h=[],m=[];return i.forEach((k,v)=>{const C=t?t(k):v;m[v]=C;const I=c&&c.atomList[c.keyList.indexOf(C)];if(I){h[v]=I;return}const b=R=>{const M=R(r),w=R(e),q=n(w,M==null?void 0:M.arr).keyList.indexOf(C);if(q<0||q>=w.length){const F=i[n(i).keyList.indexOf(C)];if(F)return F;throw new Error("splitAtom: index out of bounds for read")}return w[q]},O=(R,M,w)=>{const A=R(r),q=R(e),T=n(q,A==null?void 0:A.arr).keyList.indexOf(C);if(T<0||T>=q.length)throw new Error("splitAtom: index out of bounds for write");const g=Zi(w)?w(q[T]):w;M(e,[...q.slice(0,T),g,...q.slice(T+1)])};h[v]=er(e)?Ue(b,O):Ue(b)}),c&&c.keyList.length===m.length&&c.keyList.every((k,v)=>k===m[v])?d=c:d={arr:i,atomList:h,keyList:m},s.set(i,d),d},r=Ue(i=>{const u=i(r),d=i(e);return n(d,u==null?void 0:u.arr)});r.init=void 0;const o=er(e)?Ue(i=>i(r).atomList,(i,u,d)=>{switch(d.type){case"remove":{const c=i(o).indexOf(d.atom);if(c>=0){const h=i(e);u(e,[...h.slice(0,c),...h.slice(c+1)])}break}case"insert":{const c=d.before?i(o).indexOf(d.before):i(o).length;if(c>=0){const h=i(e);u(e,[...h.slice(0,c),d.value,...h.slice(c)])}break}case"move":{const c=i(o).indexOf(d.atom),h=d.before?i(o).indexOf(d.before):i(o).length;if(c>=0&&h>=0){const m=i(e);c<h?u(e,[...m.slice(0,c),...m.slice(c+1,h),m[c],...m.slice(h)]):u(e,[...m.slice(0,h),m[c],...m.slice(h,c),...m.slice(c+1)])}break}}}):Ue(i=>i(r).atomList);return o},e,t||Xi)}const ta=e=>typeof(e==null?void 0:e.then)=="function";function sa(e){let t,s;const n={getItem:(r,o)=>{var i,u;const d=h=>{if(h=h||"",t!==h){try{s=JSON.parse(h)}catch{return o}t=h}return s},c=(u=(i=e())==null?void 0:i.getItem(r))!=null?u:null;return ta(c)?c.then(d):d(c)},setItem:(r,o)=>{var i;return(i=e())==null?void 0:i.setItem(r,JSON.stringify(o))},removeItem:r=>{var o;return(o=e())==null?void 0:o.removeItem(r)}};return typeof window<"u"&&typeof window.addEventListener=="function"&&(n.subscribe=(r,o,i)=>{if(!(e()instanceof window.Storage))return()=>{};const u=d=>{if(d.storageArea===e()&&d.key===r){let c;try{c=JSON.parse(d.newValue||"")}catch{c=i}o(c)}};return window.addEventListener("storage",u),()=>{window.removeEventListener("storage",u)}}),n}const na=sa(()=>typeof window<"u"?window.localStorage:void 0);function dt(e,t,s=na,n){const r=n==null?void 0:n.unstable_getOnInit,o=Ue(r?s.getItem(e,t):t);return o.onMount=u=>{r||u(s.getItem(e,t));let d;return s.subscribe&&(d=s.subscribe(e,u,t)),d},Ue(u=>u(o),(u,d,c)=>{const h=typeof c=="function"?c(u(o)):c;return h===Gi?(d(o,t),s.removeItem(e)):h instanceof Promise?h.then(m=>(d(o,m),s.setItem(e,m))):(d(o,h),s.setItem(e,h))})}const ra=B.createContext(void 0),Xr=e=>{const t=B.useContext(ra);return(e==null?void 0:e.store)||t||Hi()},oa=e=>typeof(e==null?void 0:e.then)=="function",ia=B.use||(e=>{if(e.status==="pending")throw e;if(e.status==="fulfilled")return e.value;throw e.status==="rejected"?e.reason:(e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e)});function aa(e,t){const s=Xr(t),[[n,r,o],i]=B.useReducer(c=>{const h=s.get(e);return Object.is(c[0],h)&&c[1]===s&&c[2]===e?c:[h,s,e]},void 0,()=>[s.get(e),s,e]);let u=n;(r!==s||o!==e)&&(i(),u=s.get(e));const d=t==null?void 0:t.delay;return B.useEffect(()=>{const c=s.sub(e,()=>{if(typeof d=="number"){setTimeout(i,d);return}i()});return i(),c},[s,e,d]),B.useDebugValue(u),oa(u)?ia(u):u}function ua(e,t){const s=Xr(t);return B.useCallback((...r)=>s.set(e,...r),[s,e])}function ca(e,t){return[aa(e,t),ua(e,t)]}const la=new Wr({children:"blockNodes"}),Zr=(e,t=null)=>l.flatten(e.map(s=>{if(s=t!==null?{...s,parent:t}:s,s.children&&s.children.length){const n=[...s.children];return delete s.children,l.flatten([s,...Zr(n,s._id)])}return s}));function eo(e,t,s){const n=l.filter(e,o=>o._parent===t),r=[];for(let o=0;o<n.length;o++){const i=to(n[o]);if(Object.keys(i).length>0&&Object.keys(i).forEach(u=>{n[o][u]=`slot:${le.generateUUID()}`}),l.filter(e,{_parent:n[o]._id}).length>0){const u=le.generateUUID();r.push({...n[o],oldId:n[o]._id,_id:u,_parent:s}),r.push(l.flatten(eo(e,n[o]._id,u)))}else r.push({...n[o],oldId:n[o]._id,_id:le.generateUUID(),_parent:s})}return l.flatten(r)}function da(e){let t=la.convert(e.map(s=>l.omit(s,["settings"])));return t=!t.type&&t.blockNodes?t.blockNodes:l.isEmpty(t)?[]:[t],t}const to=e=>{const t={};return Object.keys(e).forEach(s=>{l.isString(e[s])&&e[s].startsWith("slot")&&(t[s]=e[s].replace("slot:",""))}),t},fa=(e,t,s=null)=>{let n=l.find(e,{_id:t});n={...n,oldId:n._id,_id:le.generateUUID()},s&&(n={...n,_parent:s});const r=[n];l.filter(e,{_parent:t}).length>0&&r.push(l.flatten(eo(e,t,n._id)));const o=l.flatten(r);return l.map(o,i=>{const u=i,d=to(u);return Object.keys(d).length>0&&Object.keys(d).forEach(c=>{const h=l.find(o,{oldId:d[c].replace("slot:","")});u[c]=`slot:${h._id}`}),l.omit(u,["global","oldId"])})},ha=Ht((e=[],t)=>{switch(t.type){case"add_new_blocks":case"add_duplicate_blocks":return[...e,...t.payload];case"create_snapshot":return[...e];case"set_blocks":case"set_page_blocks":return[...t.payload];case"update_props":case"update_props_realtime":const{payload:s}=t;return e.map(n=>(s.ids.includes(n._id)&&!l.isEmpty(t.payload.props)&&Object.keys(t.payload.props).forEach(r=>{l.set(n,r,t.payload.props[r])}),n));default:return e}},{debug:!1,ignoreInitialState:!1,limit:30,filter:Ht.excludeAction(["update_props_realtime","add_duplicate_blocks","set_page_blocks"])}),Ns=Wi({past:[],present:[],future:[]},ha);Ns.debugLabel="pageBlocksAtom";const xe=y.atom(e=>{var t;return(t=e(Ns))==null?void 0:t.present});xe.debugLabel="presentBlocksAtom";const wn=ea(xe);wn.debugLabel="pageBlocksAtomsAtom";const so=y.atom(e=>da(e(xe)));so.debugLabel="pageBlocksTreeAtom";const pa=y.atom("");pa.debugLabel="builderActivePageAtom";const ma=y.atom(-1);ma.debugLabel="destinationDropIndexAtom";const no=y.atom(!1);no.debugLabel="addBlocksModalAtom";const we=()=>{const[,e]=y.useAtom(Ns);return e},ga=()=>{const e=we(),t=y.useAtomValue(so),s=B.useCallback(n=>{const r=Zr(n);e({type:"set_page_blocks",payload:r})},[e]);return[t,s]},ro=()=>{const e=we();return[B.useCallback(s=>{e({type:"set_page_blocks",payload:s})},[e])]},tn=e=>["Box","Slot","Form","DataContext","Link","List","ListItem","Row","Column","Table","TableCell"].includes(e),ya=e=>!["Slot"].includes(e),va=e=>!["Slot"].includes(e);function ba(e,t){return e==="Slot"||t==="List"&&e!=="ListItem"||t==="Row"&&e!=="Column"?!1:tn(t)}const xa=(e,{dragSource:t,dropTarget:s})=>{const n=l.get(t,"data._type",""),r=l.get(s,"data._type","");return n==="Slot"||l.get(t,"id")&&l.get(t,"id")===l.get(s,"id")?!1:l.isEmpty(r)?!0:ba(n,r)},Sn=y.atom([]);Sn.debugLabel="selectedBlockIdsAtom";const En=y.atom(e=>{const t=e(xe),s=e(Sn);return l.map(l.filter(t,({_id:n})=>l.includes(s,n)),n=>({...n}))});En.debugLabel="selectedBlocksAtom";const kn=y.atom(e=>{const t=e(En);return t.length===0?null:t.length===1?t[0]:{type:"Multiple",id:l.map(t,"id")}});kn.debugLabel="selectedBlockAtom";const wa=e=>l.get(e,"parent",null),Sa=y.atom(e=>{const t=e(En),s=l.map(t,wa);return l.filter(e(xe),n=>l.includes(s,n._id))});Sa.debugLabel="selectedBlocksParentsAtom";const oo=y.atom(()=>!1);oo.debugLabel="selectedBlockFlexChildAtom";const io=y.atom(()=>!1);io.debugLabel="selectedBlockGridChildAtom";const An=y.atom("");An.debugLabel="styleStateAtom";const ao=dt("styleBreakpoint","xs");ao.debugLabel="styleBreakpointAtom";const Ea=()=>({flexChild:y.useAtomValue(oo),gridChild:y.useAtomValue(io)}),ka=()=>y.useAtomValue(kn),Je=()=>{const[e,t]=y.useAtom(Sn),s=B.useCallback(n=>{t(r=>l.includes(r,n)?l.without(r,n):[...r,n])},[t]);return[e,t,s]},sn=(e,t="")=>{switch(e.type){case"singular":return e.uiSchema;case"model":const{properties:s}=e,n={};return Object.keys(s).forEach(i=>{const u=s[i];if(l.includes(["slot","styles"],u.type))return;const d=l.get(u,"i18n",!1)?`${i}-${t}`:i;n[d]=sn(u,t)}),n;case"list":const{itemProperties:r}=e,o={items:{}};return Object.keys(r).forEach(i=>{const u=r[i];if(l.includes(["slot","styles"],u.type))return;const d=l.get(u,"i18n",!1)?`${i}-${t}`:i;o.items[d]=sn(u,t)}),o;default:return{}}},nn=(e,t="")=>{switch(e.type){case"singular":return e.schema;case"model":const{properties:s,title:n}=e,r={title:n,type:"object",properties:{}};return Object.keys(s).forEach(d=>{const c=s[d];if(l.includes(["slot","styles"],c.type))return;const h=l.get(c,"i18n",!1)?`${d}-${t}`:d;r.properties[h]=nn(c,t)}),r;case"list":const{itemProperties:o,title:i}=e,u={title:i,type:"array",items:{type:"object",properties:{}}};return Object.keys(o).forEach(d=>{const c=o[d];if(l.includes(["slot","styles"],c.type))return;const h=l.get(c,"i18n",!1)?`${d}-${t}`:d;u.items.properties[h]=nn(c,t),l.set(u.items,"title",l.get(c,"itemTitle",`${i} item`))}),u;default:return{}}},uo=e=>{const t={};return Object.keys(e).forEach(s=>{t[s]=Pa(e[s])}),t},Aa=e=>{if(l.isEmpty(e.default))return[];const{itemProperties:t}=e;return l.map(e.default,s=>{const n={...s};return l.forIn(s,(r,o)=>{l.has(t,o)&&l.get(t[o],"i18n",!1)&&(n[o]=ue.I18N_KEY)}),n})},Pa=e=>{switch(e.type){case"styles":return e.default;case"slot":return`${ue.SLOT_KEY}${le.generateUUID()}`;case"singular":const{i18n:t,schema:s}=e;return t?ue.I18N_KEY:l.get(s,"default","");case"model":return uo(e.properties);case"list":return Aa(e);default:return""}},co=()=>y.useAtomValue(xe);function tr(e,t,s,n,r){if(t===null)return[...e,...n];if(s!==null){const d=l.findIndex(e,{_parent:t}),c=(d===-1?0:d)+s;return e.splice(c,0,...n),e}if(!r){const c=l.findIndex(e,{_id:t})+1;return e.splice(c,0,...n),e}let o=l.findIndex(e,{_id:t});const i=l.filter(e,{_parent:t});l.isEmpty(i)||(o=l.findIndex(e,{_id:l.last(i)._id}));const u=o+1;return e.splice(u,0,...n),e}const Oa=()=>{const e=we(),t=co(),[,s]=Je(),n=B.useCallback((o,i,u)=>{var h;for(let m=0;m<o.length;m++){const{_id:k}=o[m];o[m]._id=le.generateUUID();const v=l.filter(o,{_parent:k});for(let C=0;C<v.length;C++)v[C]._parent=o[m]._id}let d;i&&(d=l.find(t,{_id:i}),o[0]._parent=i);const c=d?tn(d._type):!0;return!c&&d&&(o[0]._parent=d._parent),e({type:"set_blocks",payload:tr(t,i||null,u||null,o,c)}),s([(h=l.first(o))==null?void 0:h._id]),l.first(o)},[t,e,s]);return{addCoreBlock:B.useCallback((o,i,u)=>{if(l.has(o,"blocks")){const I=o.blocks;return n(I,i,u)}const d=le.generateUUID(),c=uo(o.props),h=[];l.forIn(c,(I,b)=>{if(l.startsWith(I,ue.SLOT_KEY)){const O=I.replace(ue.SLOT_KEY,"");h.push({_id:O,_type:"Slot",_parent:d,_name:o.props[b].name,_styles:o.props[b].styles,_emptyStyles:o.props[b].emptyStyles})}});const m={_type:o.type,_id:d,...c};let k;i&&(k=l.find(t,{_id:i}),m._parent=i);const v=k?tn(k._type):!0;!v&&k&&(m._parent=k._parent);const C=[m,...h];return e({type:"set_blocks",payload:tr(t,i||null,u||null,C,v)}),s([m._id]),m},[n,t,e,s]),addPredefinedBlock:n}},sr={xs:420,sm:620,md:768,lg:1024,xl:1280,"2xl":1536},nr=["xs","sm","md","lg","xl","2xl"];function ja(e,t){if(t===null)return"baseClasses";const s=t.mq;if(s==="xs"||t.dark||t.mod!=="")return"classes";let n="baseClasses",r=nr.indexOf(s);for(;r>0;){const o=nr[r-1];if(l.find(e,{mq:o,property:t.property})){n="classes";break}r--}return n}const rr=[];function Ca(e="",t="",s=[]){e=e.trim().replace(/ +/g,"");let n=l.filter(l.map(e.split(" "),le.constructClassObject),c=>!l.isNull(c)),r=l.filter(l.map(t.split(" "),le.constructClassObject),c=>!l.isNull(c));r=l.filter(r,c=>!l.includes(rr,c.property));const o=[],i=[];l.each(s,c=>{const h=le.constructClassObject(c),m=l.find(n,l.pick(h,["dark","mq","mod","property"]));if(m&&(n=l.filter(n,k=>k.fullCls!==(m==null?void 0:m.fullCls))),o.push(h),h.mq==="xs"&&!h.dark&&h.mod===""&&(r=l.filter(r,k=>k.property!==h.property)),ja(n,h)==="baseClasses"&&!l.includes(rr,h.property)){const k=l.find(r,l.pick(h,["property"]));m&&(r=l.filter(r,v=>v.fullCls!==(k==null?void 0:k.fullCls))),i.push({...h,fullCls:h.cls,mq:"xs"})}});const u=l.map(l.sortBy([...n,...o],c=>sr[c.mq]),"fullCls").join(" ");return`${l.map(l.sortBy([...r,...i],c=>sr[c.mq]),"fullCls").join(" ").trim()},${u.trim()}`.trim().replace(/ +/g,"")}const hs=y.atom([]);hs.debugLabel="selectedStylingBlocksAtom";const Pn=()=>y.useAtom(hs),_a=e=>{const t=e.replace(ue.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},Ba=y.atom(null,(e,t,{blockIds:s,newClasses:n,dispatch:r})=>{const o=l.filter(e(wn),u=>s.includes(e(u)._id)),i=l.first(e(hs));l.each(o,u=>{const d=e(u),c=l.get(d,i.prop,`${ue.STYLES_KEY},`),{baseClasses:h,classes:m}=_a(c);r({type:"update_props_realtime",payload:{ids:[d._id],props:{[i.prop]:`${ue.STYLES_KEY}${Ca(m,h,n)}`}}})})}),Ia=()=>{const e=we(),t=y.useSetAtom(Ba);return B.useCallback((s,n,r)=>{t({blockIds:s,newClasses:n,dispatch:e}),r&&setTimeout(()=>e({type:"create_snapshot"}),500)},[e,t])},lo=y.atom([]);lo.debugLabel="buildingBlocksAtom";const Ra=y.atom(e=>{const t=e(lo);return l.filter(t,s=>l.has(s,"blockId"))}),Da=()=>{},fo=()=>{const e=Jr.useChaiBlocks(),t=y.useAtomValue(Ra),s=()=>{},n=B.useCallback(()=>Da(),[]);return[e,t,s,n]},Ma=y.atom(!1),On=()=>{const[e,t]=y.useAtom(Ma);return[e,t]},La=y.atom(ue.BRANDING_OPTIONS_DEFAULTS),jn=()=>{const[e,t]=y.useAtom(La);return[l.isObject(e)?{...ue.BRANDING_OPTIONS_DEFAULTS,...e}:ue.BRANDING_OPTIONS_DEFAULTS,t]},Na=y.atom(null),ho=()=>({currentPage:y.useAtomValue(Na)}),po=new Wr({});function Ta(e){let t=po.convert(e);return t=!t.type&&t.children&&t.children.length?t.children:l.isEmpty(t)?[]:[t],t}const Cn=(e,t)=>l.flatten(e.map(s=>{if(s=t?{...s,parent:t}:{...s},s.children){const n=[...s.children];return delete s.children,l.flatten([s,...Cn(n,s._id)])}return s}));function _n(e,t=!1){for(let s=0;s<e.length;s++){const n=e[s];n.global&&!t?e[s]={type:"GlobalBlock",_parent:l.get(n,"parent",null),blockId:n.blockId,_id:n._id}:n.children&&n.children.length&&_n(n.children)}}function mo(e){let t=[],s=l.filter(e,{type:"GlobalBlock"});return s.length>0&&(s=l.map(s,go),l.each(s,n=>{t=[...t,...Ua(n)]})),t}function Ua(e){let t=[];const s=l.get(l.first(e),"parent",null);l.set(l.first(e),"parent",null);const n=[po.convert(yo(e))];_n(n,!0);let r=Cn(n,e[0]._id);return r=l.set(r,"0.parent",s),t=[...t,r,...mo(r)],t}function go(e){const t=l.find(rn,{_id:e._id});if(!t)return[];const s=[t],n=l.filter(rn,{_parent:e._id});return n.length?l.flatten([...s,...l.flatten(l.map(n,go))]):l.flatten(s)}const yo=e=>JSON.parse(JSON.stringify(e));let rn=[];function Fa(e){rn=e;const t=Ta(yo(e));_n(t);const s=Cn(t,null),n=mo(s),r={};return l.each(n,o=>l.set(r,l.first(o).blockId,o)),[s,r]}const Bn=()=>{const[e]=jn(),{currentPage:t}=ho(),s=y.useAtomValue(xe);return B.useCallback(()=>{const n=l.map(s,i=>l.omit(i,["expanded","order","title","siblings","tempClasses"])),[r=[],o=[]]=Fa(n);return{currentPage:t,blocks:r,globalBlocks:o}},[e,t,s])};dt("blockStylingActiveTab",1);y.atom([]);const vo=y.atom(!1);vo.debugLabel="readOnlyModeAtom";const bo=y.atom(!1);bo.debugLabel="inlineEditingActiveAtom";const xo=y.atom(!1);xo.debugLabel="advanceStylingOpenAtom";const wo=y.atom("online");wo.debugLabel="networkModeAtom";dt("currentUiLibrary","");const qa=y.atom(!1);qa.debugLabel="codeEditorOpenAtom";const So=y.atom(!1);So.debugLabel="editLayerNameAtom";const $a=y.atom("");$a.debugLabel="activeLanguageAtom";const Va=y.atom("");Va.debugLabel="primaryLanguageAtom";const Eo=y.atom(null);Eo.debugLabel="canvasIframeAtom";const ko=y.atom("layers");ko.debugLabel="activePanelAtom";const Ao=y.atom(!1);Ao.debugLabel="addBlockOffCanvasAtom";const Po=y.atom("");Po.debugLabel="showPredefinedBlockCategoryAtom";const Ts=y.atom({undoCount:0,redoCount:0});Ts.debugLabel="historyStatesAtom";const Us=y.atom("SAVED");Us.debugLabel="pageSyncStateAtom";const Qa=()=>{const[e,t]=y.useAtom(Us),s=be.useBuilderProp("onSaveBlocks",async()=>{}),n=be.useBuilderProp("onSyncStatusChange",()=>{}),r=Bn(),o=y.useSetAtom(Ts),{undoCount:i,redoCount:u}=ps();return{savePage:Ci.useThrottledCallback(async()=>{t("SAVING"),n("SAVING");const c=r();return await s({blocks:c.blocks,identifier:"pageData.id"}),setTimeout(()=>{o({undoCount:i,redoCount:u}),t("SAVED"),n("SAVED")},100),!0},[r,t,n,s],5e3),syncState:e,setSyncState:t}},ps=()=>{const e=y.useAtomValue(Ns),[{undoCount:t,redoCount:s}]=y.useAtom(Ts),n=we(),[r]=On(),[,o]=Je(),[,i]=Pn(),[,u]=y.useAtom(Us),d=be.useBuilderProp("onSyncStatusChange",()=>{}),c=B.useCallback(()=>{n({type:"create_snapshot"})},[n]);return B.useEffect(()=>{t!==(e==null?void 0:e.past.length)||s!==(e==null?void 0:e.future.length)?(u("UNSAVED"),d("UNSAVED")):t===(e==null?void 0:e.past.length)&&s===(e==null?void 0:e.future.length)&&(u("SAVED"),d("SAVED"))},[e==null?void 0:e.past.length,e==null?void 0:e.future.length,t,s,d,u]),{undoCount:e==null?void 0:e.past.length,redoCount:e==null?void 0:e.future.length,undo:B.useCallback(()=>{r||(n(Ht.ActionCreators.undo()),setTimeout(()=>{i([]),o([])},200))},[n,r,u]),redo:B.useCallback(()=>{r||(n(Ht.ActionCreators.redo()),setTimeout(()=>{i([]),o([])},200))},[r,n]),clear:()=>{n(Ht.ActionCreators.clearHistory())},createSnapshot:c}},Oo=()=>y.useAtom(ao),jo=dt("canvasWidth",360),Co=y.atom(e=>{const t=e(jo);return le.getBreakpointValue(t).toLowerCase()}),Ka=()=>{const[e,t]=y.useAtom(jo),s=y.useAtomValue(Co),[n,r]=Oo();return B.useEffect(()=>{n!=="xs"&&r(s)},[s,n,r]),[e,s,t]},za=dt("canvasZoom",100),Ha=()=>y.useAtom(za),_o=y.atom([]),In=()=>{const[e,t]=y.useAtom(_o),s=y.useSetAtom(Rn),n=B.useCallback(r=>{t(r),s([])},[t,s]);return[e,n]},Rn=y.atom([]),Bo=()=>{const[e,t]=y.useAtom(Rn),s=y.useSetAtom(_o),n=B.useCallback(r=>{t(r),s([])},[t,s]);return[e,n]},Io=dt("darkMode",!1),Ga=()=>{const[e,t]=y.useAtom(Io);return[e,t]},Wa=y.atom(!1),Ja=()=>{const[e,t]=y.useAtom(Wa);return[e,t]},Dn=()=>{const e=we(),t=y.useAtomValue(xe),[,s]=Je();return B.useCallback((n,r=null)=>{const o=[];l.each(n,i=>{const d=fa(t,i,r===i?null:r);o.push(l.get(d,"0._id","")),e({type:"add_duplicate_blocks",payload:d})}),s(o),e({type:"create_snapshot"})},[t,s,e])},Ya=y.atom([]),Xa=()=>{const[e,t]=y.useAtom(Ya),s=B.useCallback(n=>{t(r=>l.includes(r,n)?l.without(r,n):[...r,n])},[t]);return[e,t,s]},Za=y.atom(""),Ro=()=>y.useAtom(Za),eu=()=>{const e=y.useAtomValue(xe),t=we(),s=Bn(),[,,n]=fo();return B.useCallback(async(r,o)=>{const i=le.generateUUID(16),u=l.map(e,d=>(d._id===r&&(d._globalBlockId=i,d._name=o),d));t({type:"set_page_blocks",payload:u}),n()},[e,t,s,n])},tu=()=>({}),su=()=>{const e=y.useAtomValue(xe),t=we();return B.useCallback((s,n)=>{const r=l.map(e,o=>(l.includes(s,l.get(o,"_id"))&&l.set(o,"_parent",n),o));t({type:"set_blocks",payload:r})},[e,t])},Do=()=>{const e=y.useAtomValue(Rn),[t,s]=In(),n=Dn(),r=su();return{canPaste:B.useMemo(()=>t.length>0||e.length>0,[e,t]),pasteBlocks:B.useCallback(i=>{l.isEmpty(e)?r(t,i):n(e,i),s(()=>[])},[t,e,n,r,s])}},nu=y.atom(""),ru=()=>{const e=y.useAtomValue(nu),t=B.useCallback(()=>{},[]),s=B.useCallback(()=>{},[]),n=B.useCallback(()=>{},[]);return{currentProject:e,createProject:n,deleteProject:t,updateProject:s}},Mo=(e,t)=>{const s=[],n=l.filter(e,r=>l.includes(t,r._id)||l.includes(t,r._parent)?(s.push(r._id),!1):!0);return l.isEmpty(s)?n:Mo(n,s)},Lo=()=>{const e=we(),t=y.useAtomValue(xe),[s,n]=Je();return B.useCallback(r=>{var u;const o=((u=l.find(t,{_id:r[0]}))==null?void 0:u._parent)||null,i=Mo(t,r);e({type:"set_blocks",payload:i}),n(o?[o]:[])},[t,n,e,s])},ou=y.atom(null,(e,t,{blockIds:s,fullClasses:n,dispatch:r})=>{const o=l.first(e(hs)),i=l.filter(e(wn),u=>s.includes(e(u)._id));l.each(i,u=>{const d=e(u),c=n;let{classes:h,baseClasses:m}=qi(l.get(d,o.prop,"styles:,"));l.each(c,k=>{const v=new RegExp(`(^| )${k.replace("[","\\[").replace("]","\\]")}($| )`,"g");h=h.replace(v," ").replace(/ +/g," ").trim();const C=l.first(k.split(":"));l.includes(["2xl","xl","lg","md","sm"],C)&&c.push(k.split(":").pop().trim())}),l.each(c,k=>{const v=new RegExp(`(^| )${k.replace("[","\\[").replace("]","\\]")}($| )`,"g");m=m.replace(v," ").replace(/ +/g," ").trim()}),r({type:"update_props_realtime",payload:{ids:[d._id],props:{[o.prop]:`${ue.STYLES_KEY}${m},${h}`}}})})}),iu=()=>{const e=we(),t=y.useSetAtom(ou);return B.useCallback((s,n)=>{t({blockIds:s,fullClasses:n,dispatch:e}),setTimeout(()=>e({type:"create_snapshot"}))},[e,t])},No=y.atom(e=>{const t=l.first(e(hs)),s=e(kn);if(!t||t.blockId!==l.get(s,"_id",null))return[];const r=l.get(s,t.prop,`${ue.STYLES_KEY},`).replace(ue.STYLES_KEY,"").split(",").join(" ");return l.filter(l.map(r.trim().split(" "),le.constructClassObject),o=>!l.isNull(o))}),au=()=>y.useAtomValue(No),or={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},uu=y.atom(e=>{const t=e(Co),s=e(An),n=e(Io),r=cu(t);let o=l.filter(e(No),{mod:s});return l.startsWith(s,"_")||(o=l.filter(o,i=>r.includes(i.mq))),o=o.sort((i,u)=>or[i.mq]-or[u.mq]),n||(o=l.filter(o,{dark:!1})),o}),cu=e=>{let t=[];switch(e){case"xs":t=["xs"];break;case"sm":t=["xs","sm"];break;case"md":t=["xs","sm","md"];break;case"lg":t=["xs","sm","md","lg"];break;case"xl":t=["xs","sm","md","lg","xl"];break;case"2xl":t=["xs","sm","md","lg","xl","2xl"];break;default:t=["xs"];break}return t},lu=()=>y.useAtomValue(uu),du=()=>y.useAtom(An),To=y.atom(null,(e,t,{blockIds:s,props:n,dispatch:r})=>{r({type:"update_props_realtime",payload:{ids:s,props:n}})}),fu=()=>{const{createSnapshot:e}=ps(),t=we(),s=y.useSetAtom(To);return B.useCallback((n,r)=>{s({blockIds:n,props:r,dispatch:t}),e()},[e,t,s])},hu=()=>{const e=we(),t=y.useSetAtom(To);return B.useCallback((s,n)=>{t({blockIds:s,props:n,dispatch:e})},[e,t])},Uo={name:"",props:{},modalProps:{},backdropClose:!0},pu=y.atom(Uo),mu=()=>{const[e,t]=y.useAtom(pu),s=B.useCallback((r,o={},i={})=>{t({name:r,props:o,modalProps:i})},[t]),n=B.useCallback((...r)=>{l.get(e,"props.onClose",()=>{})(...r),t(Uo)},[t,e]);return{activeModal:e,openModal:s,closeModal:n}},gu=()=>y.useAtomValue(vo),yu=y.atom(""),vu=y.atom(null),bu=()=>y.useAtom(yu),xu=()=>y.useAtom(vu),wu=dt("selectedBreakpoints",["XS","MD","XL"]),Su=()=>{const[e,t]=y.useAtom(wu);return[e,t]},Mn=()=>{const e=y.useSetAtom(Ts),{clear:t}=ps(),[,s]=Je(),[,n]=Ro(),[,r]=Pn();return()=>{s([]),r([]),n(""),t(),e({undoCount:0,redoCount:0})}},Eu=y.atom({en:{}}),ku=()=>{const[e,t]=y.useAtom(Eu),s=B.useCallback((n,r,o)=>{l.set(e,`${n}.${r}`,o),t(e)},[e,t]);return[e,s]},Au=(e,t)=>{const[s]=y.useAtom(be.chaiBuilderPropsAtom);return l.get(s,e,t)},Pu=y.atom([]),Ou=()=>{const[e,t]=B.useState(!1),[s,n]=y.useAtom(Pu),r=be.useBuilderProp("getUILibraryBlocks",()=>[]);return B.useEffect(()=>{(async()=>s.length>0||(t(!0),n(await r()),t(!1)))()},[]),{data:s,isLoading:e}},ju=y.atom("en"),Cu=y.atom("en"),_u=y.atom(["en"]),Fo=()=>y.useAtom(ju),Bu=()=>y.useAtom(Cu),Iu=()=>y.useAtom(_u),Ru=(e,t)=>{const[s]=Fo(),n=`${e}${s?`-${s}`:""}`;return{content:l.get(t,n,l.get(t,e,"")),propKey:e}},Du=()=>{const[e,t]=On(),s=be.useBuilderProp("previewComponent");return _.jsxRuntimeExports.jsxs("div",{className:ji.cn("fixed inset-0 z-[999] bg-background",e?"block":"hidden"),children:[_.jsxRuntimeExports.jsx(be.Button,{size:"sm",className:"absolute right-0 top-0 m-4",onClick:()=>t(!1),children:"Close Preview"}),_.jsxRuntimeExports.jsx("div",{children:s?_.jsxRuntimeExports.jsx(B.Suspense,{fallback:_.jsxRuntimeExports.jsx(be.Skeleton,{className:"h-96 w-full"}),children:B.createElement(s)}):null})]})},Mu=()=>{const[e,t]=Je(),[,s]=Bo(),n=Lo(),r=Dn(),[,o]=In(),{pasteBlocks:i}=Do(),{undo:u,redo:d}=ps();Le.useHotkeys("esc",()=>t([]),{},[t]),Le.useHotkeys("ctrl+c,command+c",()=>s(e),{},[e,s]),Le.useHotkeys("ctrl+d,command+d",()=>r(e),{preventDefault:!0},[e,r]),Le.useHotkeys("ctrl+x,command+x",()=>o(e),{},[e,o]),Le.useHotkeys("ctrl+v,command+v",()=>e.length===1?i(e[0]):null,{},[e,i]),Le.useHotkeys("ctrl+z,command+z",()=>u(),{},[u]),Le.useHotkeys("ctrl+y,command+y",()=>d(),{},[d]),Le.useHotkeys("del, backspace",c=>{c.preventDefault(),n(e)},{},[e,n])},Lu=(e,t)=>{const s=[];let n=l.find(e,{_id:t}),r=l.get(n,"_parent","");for(;l.isString(r)&&!l.isEmpty(r);)s.push(n==null?void 0:n._parent),n=l.find(e,{_id:r}),r=n==null?void 0:n._parent;return l.flatten(s)},qo=y.atom([]),Nu=()=>{const[e]=Je(),t=y.useAtomValue(xe),[,s]=y.useAtom(qo);B.useEffect(()=>{let n=[];const r=l.first(e);l.isString(r)&&(n=[r,...Lu(t,r)]),s(n)},[e,t,s])},Tu=()=>y.useAtomValue(qo),Uu=B.lazy(()=>Promise.resolve().then(()=>require("./SidePanels-0e4ab159.cjs"))),Fu=B.lazy(()=>Promise.resolve().then(()=>require("./Topbar-44c010e3.cjs"))),qu=B.lazy(()=>Promise.resolve().then(()=>require("./CanvasArea-a637ef3a.cjs"))),$u=B.lazy(()=>Promise.resolve().then(()=>require("./Settings-99916fc1.cjs"))),Vu=()=>{const[e]=ca(Us),t=s=>{s.preventDefault()};return Mu(),Nu(),B.useEffect(()=>(e!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[e]),_.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-background text-foreground",children:_.jsxRuntimeExports.jsxs(be.TooltipProvider,{children:[_.jsxRuntimeExports.jsxs("div",{onContextMenu:t,className:"flex h-screen flex-col overflow-hidden bg-background text-foreground",children:[_.jsxRuntimeExports.jsx("div",{className:"h-14 w-screen shrink-0 border-b border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(Fu,{})})}),_.jsxRuntimeExports.jsxs("main",{className:"flex h-full flex-row",children:[_.jsxRuntimeExports.jsx("div",{className:"flex h-full w-fit border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(Uu,{})})}),_.jsxRuntimeExports.jsx("div",{className:"h-full flex-1 bg-slate-800/20",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx(qu,{})})}),_.jsxRuntimeExports.jsx("div",{className:"flex h-full w-[280px] min-w-[280px] border-l border-border",children:_.jsxRuntimeExports.jsx(B.Suspense,{children:_.jsxRuntimeExports.jsx($u,{})})})]})]}),_.jsxRuntimeExports.jsx(Du,{})]})})},Qu=y.getDefaultStore();y.atom({});function ir(e,t,s,n,r){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:r;return e===r?s:e}var xs="undefined",ar="object",$o="any",Vo="*",ut="__",Bs=typeof process<"u"?process:{};Bs.env&&Bs.env.NODE_ENV;var Ee=typeof document<"u";Bs.versions!=null&&Bs.versions.node!=null;typeof Deno<"u"&&Deno.core;Ee&&window.name==="nodejs"||typeof navigator<"u"&&navigator.userAgent!==void 0&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));function Qo(e,t){return t.charAt(0)[e]()+t.slice(1)}var Ku=Qo.bind(null,"toUpperCase"),zu=Qo.bind(null,"toLowerCase");function Hu(e){return Ko(e)?Ku("null"):typeof e=="object"?Xu(e):Object.prototype.toString.call(e).slice(8,-1)}function Is(e,t){t===void 0&&(t=!0);var s=Hu(e);return t?zu(s):s}function ms(e,t){return typeof t===e}var Ce=ms.bind(null,"function"),mt=ms.bind(null,"string"),ht=ms.bind(null,"undefined"),Gu=ms.bind(null,"boolean");ms.bind(null,"symbol");function Ko(e){return e===null}function Wu(e){return Is(e)==="number"&&!isNaN(e)}function Ju(e){return Is(e)==="array"}function he(e){if(!Yu(e))return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Yu(e){return e&&(typeof e=="object"||e!==null)}function Xu(e){return Ce(e.constructor)?e.constructor.name:null}function Zu(e){return e instanceof Error||mt(e.message)&&e.constructor&&Wu(e.constructor.stackTraceLimit)}function zo(e,t){if(typeof t!="object"||Ko(t))return!1;if(t instanceof e)return!0;var s=Is(new e(""));if(Zu(t))for(;t;){if(Is(t)===s)return!0;t=Object.getPrototypeOf(t)}return!1}zo.bind(null,TypeError);zo.bind(null,SyntaxError);function Fs(e,t){var s=e instanceof Element||e instanceof HTMLDocument;return s&&t?ec(e,t):s}function ec(e,t){return t===void 0&&(t=""),e&&e.nodeName===t.toUpperCase()}function qs(e){var t=[].slice.call(arguments,1);return function(){return e.apply(void 0,[].slice.call(arguments).concat(t))}}qs(Fs,"form");qs(Fs,"button");qs(Fs,"input");qs(Fs,"select");function ur(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function tc(){if(Ee){var e=navigator,t=e.languages;return e.userLanguage||(t&&t.length?t[0]:e.language)}}function sc(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function nc(e){return function(t){for(var s,n=Object.create(null),r=/([^&=]+)=?([^&]*)/g;s=r.exec(t);){var o=ur(s[1]),i=ur(s[2]);o.substring(o.length-2)==="[]"?(n[o=o.substring(0,o.length-2)]||(n[o]=[])).push(i):n[o]=i===""||i}for(var u in n){var d=u.split("[");d.length>1&&(rc(n,d.map(function(c){return c.replace(/[?[\]\\ ]/g,"")}),n[u]),delete n[u])}return n}(function(t){if(t){var s=t.match(/\?(.*)/);return s&&s[1]?s[1].split("#")[0]:""}return Ee&&window.location.search.substring(1)}(e))}function rc(e,t,s){for(var n=t.length-1,r=0;r<n;++r){var o=t[r];if(o==="__proto__"||o==="constructor")break;o in e||(e[o]={}),e=e[o]}e[t[n]]=s}function $s(){for(var e="",t=0,s=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],r=15&s;e+=n=="-"||n=="4"?n:(n=="x"?r:3&r|8).toString(16),s=t%8==0?4294967295*Math.random()|0:s>>4}return e}var Gt="global",Mt=ut+"global"+ut,Lt=typeof self===ar&&self.self===self&&self||typeof global===ar&&global.global===global&&global||void 0;function ct(e){return Lt[Mt][e]}function lt(e,t){return Lt[Mt][e]=t}function Ut(e){delete Lt[Mt][e]}function Ft(e,t,s){var n;try{if(Ln(e)){var r=window[e];n=r[t].bind(r)}}catch{}return n||s}Lt[Mt]||(Lt[Mt]={});var ws={};function Ln(e){if(typeof ws[e]!==xs)return ws[e];try{var t=window[e];t.setItem(xs,xs),t.removeItem(xs)}catch{return ws[e]=!1}return ws[e]=!0}function V(){return V=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},V.apply(this,arguments)}var Fe="function",De="undefined",oc="@@redux/"+Math.random().toString(36),cr=function(){return typeof Symbol===Fe&&Symbol.observable||"@@observable"}(),Ss=" != "+Fe;function Ho(e,t,s){var n;if(typeof t===Fe&&typeof s===De&&(s=t,t=void 0),typeof s!==De){if(typeof s!==Fe)throw new Error("enhancer"+Ss);return s(Ho)(e,t)}if(typeof e!==Fe)throw new Error("reducer"+Ss);var r=e,o=t,i=[],u=i,d=!1;function c(){u===i&&(u=i.slice())}function h(){return o}function m(v){if(typeof v!==Fe)throw new Error("Listener"+Ss);var C=!0;return c(),u.push(v),function(){if(C){C=!1,c();var I=u.indexOf(v);u.splice(I,1)}}}function k(v){if(!he(v))throw new Error("Act != obj");if(typeof v.type===De)throw new Error("ActType "+De);if(d)throw new Error("Dispatch in reducer");try{d=!0,o=r(o,v)}finally{d=!1}for(var C=i=u,I=0;I<C.length;I++)(0,C[I])();return v}return k({type:"@@redux/INIT"}),(n={dispatch:k,subscribe:m,getState:h,replaceReducer:function(v){if(typeof v!==Fe)throw new Error("next reducer"+Ss);r=v,k({type:"@@redux/INIT"})}})[cr]=function(){var v,C=m;return(v={subscribe:function(I){if(typeof I!="object")throw new TypeError("Observer != obj");function b(){I.next&&I.next(h())}return b(),{unsubscribe:C(b)}}})[cr]=function(){return this},v},n}function ic(e,t){var s=t&&t.type;return"action "+(s&&s.toString()||"?")+"reducer "+e+" returns "+De}function Nt(){var e=[].slice.call(arguments);return e.length===0?function(t){return t}:e.length===1?e[0]:e.reduce(function(t,s){return function(){return t(s.apply(void 0,[].slice.call(arguments)))}})}function ac(){var e=arguments;return function(t){return function(s,n,r){var o,i=t(s,n,r),u=i.dispatch,d={getState:i.getState,dispatch:function(c){return u(c)}};return o=[].slice.call(e).map(function(c){return c(d)}),V({},i,{dispatch:u=Nt.apply(void 0,o)(i.dispatch)})}}}var We=ut+"anon_id",at=ut+"user_id",gt=ut+"user_traits",Te="userId",pt="anonymousId",Ps=["bootstrap","params","campaign","initializeStart","initialize","initializeEnd","ready","resetStart","reset","resetEnd","pageStart","page","pageEnd","pageAborted","trackStart","track","trackEnd","trackAborted","identifyStart","identify","identifyEnd","identifyAborted","userIdChanged","registerPlugins","enablePlugin","disablePlugin","online","offline","setItemStart","setItem","setItemEnd","setItemAborted","removeItemStart","removeItem","removeItemEnd","removeItemAborted"],on=["name","EVENTS","config","loaded"],$=Ps.reduce(function(e,t){return e[t]=t,e},{registerPluginType:function(e){return"registerPlugin:"+e},pluginReadyType:function(e){return"ready:"+e}}),lr=/^utm_/,dr=/^an_prop_/,fr=/^an_trait_/;function uc(e){var t=e.storage.setItem;return function(s){return function(n){return function(r){if(r.type===$.bootstrap){var o=r.params,i=r.user,u=r.persistedUser,d=r.initialUser,c=u.userId===i.userId;u.anonymousId!==i.anonymousId&&t(We,i.anonymousId),c||t(at,i.userId),d.traits&&t(gt,V({},c&&u.traits?u.traits:{},d.traits));var h=Object.keys(r.params);if(h.length){var m=o.an_uid,k=o.an_event,v=h.reduce(function(C,I){if(I.match(lr)||I.match(/^(d|g)clid/)){var b=I.replace(lr,"");C.campaign[b==="campaign"?"name":b]=o[I]}return I.match(dr)&&(C.props[I.replace(dr,"")]=o[I]),I.match(fr)&&(C.traits[I.replace(fr,"")]=o[I]),C},{campaign:{},props:{},traits:{}});s.dispatch(V({type:$.params,raw:o},v,m?{userId:m}:{})),m&&setTimeout(function(){return e.identify(m,v.traits)},0),k&&setTimeout(function(){return e.track(k,v.props)},0),Object.keys(v.campaign).length&&s.dispatch({type:$.campaign,campaign:v.campaign})}}return n(r)}}}}function cc(e){return function(t,s){if(t===void 0&&(t={}),s===void 0&&(s={}),s.type===$.setItemEnd){if(s.key===We)return V({},t,{anonymousId:s.value});if(s.key===at)return V({},t,{userId:s.value})}switch(s.type){case $.identify:return Object.assign({},t,{userId:s.userId,traits:V({},t.traits,s.traits)});case $.reset:return[at,We,gt].forEach(function(n){e.removeItem(n)}),Object.assign({},t,{userId:null,anonymousId:null,traits:{}});default:return t}}}function hr(e){return{userId:e.getItem(at),anonymousId:e.getItem(We),traits:e.getItem(gt)}}var an=function(e){return ut+"TEMP"+ut+e};function lc(e){var t=e.storage,s=t.setItem,n=t.removeItem,r=t.getItem;return function(o){return function(i){return function(u){var d=u.userId,c=u.traits,h=u.options;if(u.type===$.reset&&([at,gt,We].forEach(function(v){n(v)}),[Te,pt,"traits"].forEach(function(v){Ut(an(v))})),u.type===$.identify){r(We)||s(We,$s());var m=r(at),k=r(gt)||{};m&&m!==d&&o.dispatch({type:$.userIdChanged,old:{userId:m,traits:k},new:{userId:d,traits:c},options:h}),d&&s(at,d),c&&s(gt,V({},k,c))}return i(u)}}}}var Kt={};function pr(e,t){Kt[e]&&Ce(Kt[e])&&(Kt[e](t),delete Kt[e])}function Go(e,t,s){return new Promise(function(n,r){return t()?n(e):s<1?r(V({},e,{queue:!0})):new Promise(function(o){return setTimeout(o,10)}).then(function(o){return Go(e,t,s-10).then(n,r)})})}function Wo(e,t,s){var n=t(),r=e.getState(),o=r.plugins,i=r.queue,u=r.user;if(!r.context.offline&&i&&i.actions&&i.actions.length){var d=i.actions.reduce(function(h,m,k){return o[m.plugin].loaded?(h.process.push(m),h.processIndex.push(k)):(h.requeue.push(m),h.requeueIndex.push(k)),h},{processIndex:[],process:[],requeue:[],requeueIndex:[]});if(d.processIndex&&d.processIndex.length){d.processIndex.forEach(function(h){var m=i.actions[h],k=m.plugin,v=m.payload.type,C=n[k][v];if(C&&Ce(C)){var I=function(O,R){return O===void 0&&(O={}),R===void 0&&(R={}),[Te,pt].reduce(function(M,w){return O.hasOwnProperty(w)&&R[w]&&R[w]!==O[w]&&(M[w]=R[w]),M},O)}(m.payload,u);C({payload:I,config:o[k].config,instance:s});var b=v+":"+k;e.dispatch(V({},I,{type:b,_:{called:b,from:"queueDrain"}}))}});var c=i.actions.filter(function(h,m){return!~d.processIndex.indexOf(m)});i.actions=c}}}var Js=function(e){var t=e.data,s=e.action,n=e.instance,r=e.state,o=e.allPlugins,i=e.allMatches,u=e.store,d=e.EVENTS;try{var c=r.plugins,h=r.context,m=s.type,k=m.match(yt),v=t.exact.map(function(b){return b.pluginName});k&&(v=i.during.map(function(b){return b.pluginName}));var C=function(b,O){return function(R,M,w){var A=M.config,q=M.name,F=q+"."+R.type;w&&(F=w.event);var T=R.type.match(yt)?function(g,x,D,S,N){return function(j,E){var z=S?S.name:g,Q=E&&Xt(E)?E:D;if(S&&(!(Q=E&&Xt(E)?E:[g]).includes(g)||Q.length!==1))throw new Error("Method "+x+" can only abort "+g+" plugin. "+JSON.stringify(Q)+" input valid");return V({},N,{abort:{reason:j,plugins:Q,caller:x,_:z}})}}(q,F,O,w,R):function(g,x){return function(){throw new Error(g.type+" action not cancellable. Remove abort in "+x)}}(R,F);return{payload:dc(R),instance:b,config:A||{},abort:T}}}(n,v),I=t.exact.reduce(function(b,O){var R=O.pluginName,M=O.methodName,w=!1;return M.match(/^initialize/)||M.match(/^reset/)||(w=!c[R].loaded),h.offline&&M.match(/^(page|track|identify)/)&&(w=!0),b[""+R]=w,b},{});return Promise.resolve(t.exact.reduce(function(b,O,R){try{var M=O.pluginName;return Promise.resolve(b).then(function(w){function A(){return Promise.resolve(w)}var q=function(){if(t.namespaced&&t.namespaced[M])return Promise.resolve(t.namespaced[M].reduce(function(F,T,g){try{return Promise.resolve(F).then(function(x){return T.method&&Ce(T.method)?(function(j,E){var z=wr(j);if(z&&z.name===E){var Q=wr(z.method);throw new Error([E+" plugin is calling method "+j,"Plugins cant call self","Use "+z.method+" "+(Q?"or "+Q.method:"")+" in "+E+" plugin insteadof "+j].join(`
2
+ `))}}(T.methodName,T.pluginName),Promise.resolve(T.method({payload:x,instance:n,abort:(D=x,S=M,N=T.pluginName,function(j,E){return V({},D,{abort:{reason:j,plugins:E||[S],caller:m,from:N||S}})}),config:yr(T.pluginName,c,o),plugins:c})).then(function(j){var E=he(j)?j:{};return Promise.resolve(V({},x,E))})):x;var D,S,N})}catch(x){return Promise.reject(x)}},Promise.resolve(s))).then(function(F){w[M]=F});w[M]=s}();return q&&q.then?q.then(A):A()})}catch(w){return Promise.reject(w)}},Promise.resolve({}))).then(function(b){return Promise.resolve(t.exact.reduce(function(O,R,M){try{var w=t.exact.length===M+1,A=R.pluginName,q=o[A];return Promise.resolve(O).then(function(F){var T=b[A]?b[A]:{};if(k&&(T=F),Xs(T,A))return Ys({data:T,method:m,instance:n,pluginName:A,store:u}),Promise.resolve(F);if(Xs(F,A))return w&&Ys({data:F,method:m,instance:n,store:u}),Promise.resolve(F);if(I.hasOwnProperty(A)&&I[A]===!0)return u.dispatch({type:"queue",plugin:A,payload:T,_:{called:"queue",from:"queueMechanism"}}),Promise.resolve(F);var g=C(b[A],o[A]);return Promise.resolve(q[m]({abort:g.abort,payload:T,instance:n,config:yr(A,c,o),plugins:c})).then(function(x){var D=he(x)?x:{},S=V({},F,D),N=b[A];if(Xs(N,A))Ys({data:N,method:m,instance:n,pluginName:A,store:u});else{var j=m+":"+A;(j.match(/:/g)||[]).length<2&&!m.match(mr)&&!m.match(gr)&&n.dispatch(V({},k?S:T,{type:j,_:{called:j,from:"submethod"}}))}return Promise.resolve(S)})})}catch(F){return Promise.reject(F)}},Promise.resolve(s))).then(function(O){if(!(m.match(yt)||m.match(/^registerPlugin/)||m.match(gr)||m.match(mr)||m.match(/^params/)||m.match(/^userIdChanged/))){if(d.plugins.includes(m),O._&&O._.originalAction===m)return O;var R=V({},O,{_:{originalAction:O.type,called:O.type,from:"engineEnd"}});Jo(O,t.exact.length)&&!m.match(/End$/)&&(R=V({},R,{type:O.type+"Aborted"})),u.dispatch(R)}return O})})}catch(b){return Promise.reject(b)}},yt=/Start$/,mr=/^bootstrap/,gr=/^ready/;function Ys(e){var t=e.pluginName,s=e.method+"Aborted"+(t?":"+t:"");e.store.dispatch(V({},e.data,{type:s,_:{called:s,from:"abort"}}))}function yr(e,t,s){var n=t[e]||s[e];return n&&n.config?n.config:{}}function vr(e,t){return t.reduce(function(s,n){return n[e]?s.concat({methodName:e,pluginName:n.name,method:n[e]}):s},[])}function br(e,t){var s=e.replace(yt,""),n=t?":"+t:"";return[""+e+n,""+s+n,s+"End"+n]}function Xs(e,t){var s=e.abort;return!!s&&(s===!0||xr(s,t)||s&&xr(s.plugins,t))}function Jo(e,t){var s=e.abort;if(!s)return!1;if(s===!0||mt(s))return!0;var n=s.plugins;return Xt(s)&&s.length===t||Xt(n)&&n.length===t}function Xt(e){return Array.isArray(e)}function xr(e,t){return!(!e||!Xt(e))&&e.includes(t)}function wr(e){var t=e.match(/(.*):(.*)/);return!!t&&{method:t[1],name:t[2]}}function dc(e){return Object.keys(e).reduce(function(t,s){return s==="type"||(t[s]=he(e[s])?Object.assign({},e[s]):e[s]),t},{})}function fc(e,t,s){var n={};return function(r){return function(o){return function(i){try{var u,d=function(w){return u?w:o(m)},c=i.type,h=i.plugins,m=i;if(i.abort)return Promise.resolve(o(i));if(c===$.enablePlugin&&r.dispatch({type:$.initializeStart,plugins:h,disabled:[],fromEnable:!0,meta:i.meta}),c===$.disablePlugin&&setTimeout(function(){return pr(i.meta.rid,{payload:i})},0),c===$.initializeEnd){var k=t(),v=Object.keys(k),C=v.filter(function(w){return h.includes(w)}).map(function(w){return k[w]}),I=[],b=[],O=i.disabled,R=C.map(function(w){var A=w.loaded,q=w.name,F=w.config;return Go(w,function(){return A({config:F})},1e4).then(function(T){return n[q]||(r.dispatch({type:$.pluginReadyType(q),name:q,events:Object.keys(w).filter(function(g){return!on.includes(g)})}),n[q]=!0),I=I.concat(q),w}).catch(function(T){if(T instanceof Error)throw new Error(T);return b=b.concat(T.name),T})});Promise.all(R).then(function(w){var A={plugins:I,failed:b,disabled:O};setTimeout(function(){v.length===R.length+O.length&&r.dispatch(V({},{type:$.ready},A))},0)})}var M=function(){if(c!==$.bootstrap)return/^ready:([^:]*)$/.test(c)&&setTimeout(function(){return Wo(r,t,e)},0),Promise.resolve(function(w,A,q,F,T){try{var g=Ce(A)?A():A,x=w.type,D=x.replace(yt,"");if(w._&&w._.called)return Promise.resolve(w);var S=q.getState(),N=(z=g,(Q=S.plugins)===void 0&&(Q={}),(W=w.options)===void 0&&(W={}),Object.keys(z).filter(function(f){var p=W.plugins||{};return Gu(p[f])?p[f]:p.all!==!1&&(!Q[f]||Q[f].enabled!==!1)}).map(function(f){return z[f]}));x===$.initializeStart&&w.fromEnable&&(N=Object.keys(S.plugins).filter(function(f){var p=S.plugins[f];return w.plugins.includes(f)&&!p.initialized}).map(function(f){return g[f]}));var j=N.map(function(f){return f.name}),E=function(f,p,U){var H=br(f).map(function(G){return vr(G,p)});return p.reduce(function(G,J){var oe=J.name,X=br(f,oe).map(function(Vt){return vr(Vt,p)}),ee=X[0],Y=X[1],ke=X[2];return ee.length&&(G.beforeNS[oe]=ee),Y.length&&(G.duringNS[oe]=Y),ke.length&&(G.afterNS[oe]=ke),G},{before:H[0],beforeNS:{},during:H[1],duringNS:{},after:H[2],afterNS:{}})}(x,N);return Promise.resolve(Js({action:w,data:{exact:E.before,namespaced:E.beforeNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(f){function p(){var G=function(){if(x.match(yt))return Promise.resolve(Js({action:V({},U,{type:D+"End"}),data:{exact:E.after,namespaced:E.afterNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(J){J.meta&&J.meta.hasCallback&&pr(J.meta.rid,{payload:J})})}();return G&&G.then?G.then(function(){return f}):f}if(Jo(f,j.length))return f;var U,H=function(){if(x!==D)return Promise.resolve(Js({action:V({},f,{type:D}),data:{exact:E.during,namespaced:E.duringNS},state:S,allPlugins:g,allMatches:E,instance:q,store:F,EVENTS:T})).then(function(G){U=G});U=f}();return H&&H.then?H.then(p):p()})}catch(f){return Promise.reject(f)}var z,Q,W}(i,t,e,r,s)).then(function(w){return u=1,o(w)})}();return Promise.resolve(M&&M.then?M.then(d):d(M))}catch(w){return Promise.reject(w)}}}}}function hc(e){return function(t){return function(s){return function(n){var r=n.type,o=n.key,i=n.value,u=n.options;if(r===$.setItem||r===$.removeItem){if(n.abort)return s(n);r===$.setItem?e.setItem(o,i,u):e.removeItem(o,u)}return s(n)}}}}var pc=function(){var e=this;this.before=[],this.after=[],this.addMiddleware=function(t,s){e[s]=e[s].concat(t)},this.removeMiddleware=function(t,s){var n=e[s].findIndex(function(r){return r===t});n!==-1&&(e[s]=[].concat(e[s].slice(0,n),e[s].slice(n+1)))},this.dynamicMiddlewares=function(t){return function(s){return function(n){return function(r){var o={getState:s.getState,dispatch:function(u){return s.dispatch(u)}},i=e[t].map(function(u){return u(o)});return Nt.apply(void 0,i)(n)(r)}}}}};function mc(e){return function(t,s){t===void 0&&(t={});var n={};if(s.type==="initialize:aborted")return t;if(/^registerPlugin:([^:]*)$/.test(s.type)){var r=Sr(s.type,"registerPlugin"),o=e()[r];if(!o||!r)return t;var i=s.enabled,u=o.config;return n[r]={enabled:i,initialized:!!i&&!o.initialize,loaded:!!i&&!!o.loaded({config:u}),config:u},V({},t,n)}if(/^initialize:([^:]*)$/.test(s.type)){var d=Sr(s.type,$.initialize),c=e()[d];return c&&d?(n[d]=V({},t[d],{initialized:!0,loaded:!!c.loaded({config:c.config})}),V({},t,n)):t}if(/^ready:([^:]*)$/.test(s.type))return n[s.name]=V({},t[s.name],{loaded:!0}),V({},t,n);switch(s.type){case $.disablePlugin:return V({},t,Er(s.plugins,!1,t));case $.enablePlugin:return V({},t,Er(s.plugins,!0,t));default:return t}}}function Sr(e,t){return e.substring(t.length+1,e.length)}function Er(e,t,s){return e.reduce(function(n,r){return n[r]=V({},s[r],{enabled:t}),n},s)}function Yo(e){try{return JSON.parse(JSON.stringify(e))}catch{}return e}var gc={last:{},history:[]};function yc(e,t){e===void 0&&(e=gc);var s=t.options,n=t.meta;if(t.type===$.track){var r=Yo(V({event:t.event,properties:t.properties},Object.keys(s).length&&{options:s},{meta:n}));return V({},e,{last:r,history:e.history.concat(r)})}return e}var vc={actions:[]};function bc(e,t){e===void 0&&(e=vc);var s=t.payload;switch(t.type){case"queue":var n;return n=s&&s.type&&s.type===$.identify?[t].concat(e.actions):e.actions.concat(t),V({},e,{actions:n});case"dequeue":return[];default:return e}}var Xo=/#.*$/;function xc(e){var t=/(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g.exec(e);return"/"+(t&&t[3]?t[3].split("?")[0].replace(Xo,""):"")}var Zo,ei,ti,si,wc=function(e){if(e===void 0&&(e={}),!Ee)return e;var t=document,s=t.title,n=t.referrer,r=window,o=r.location,i=r.innerWidth,u=r.innerHeight,d=o.hash,c=o.search,h=function(k){var v=function(){if(Ee){for(var C,I=document.getElementsByTagName("link"),b=0;C=I[b];b++)if(C.getAttribute("rel")==="canonical")return C.getAttribute("href")}}();return v?v.match(/\?/)?v:v+k:window.location.href.replace(Xo,"")}(c),m={title:s,url:h,path:xc(h),hash:d,search:c,width:i,height:u};return n&&n!==""&&(m.referrer=n),V({},m,e)},Sc={last:{},history:[]};function Ec(e,t){e===void 0&&(e=Sc);var s=t.options;if(t.type===$.page){var n=Yo(V({properties:t.properties,meta:t.meta},Object.keys(s).length&&{options:s}));return V({},e,{last:n,history:e.history.concat(n)})}return e}Zo=function(){if(!Ee)return!1;var e=navigator.appVersion;return~e.indexOf("Win")?"Windows":~e.indexOf("Mac")?"MacOS":~e.indexOf("X11")?"UNIX":~e.indexOf("Linux")?"Linux":"Unknown OS"}(),ei=Ee?document.referrer:null,ti=tc(),si=sc();var kr={initialized:!1,sessionId:$s(),app:null,version:null,debug:!1,offline:!!Ee&&!navigator.onLine,os:{name:Zo},userAgent:Ee?navigator.userAgent:"node",library:{name:"analytics",version:"0.12.5"},timezone:si,locale:ti,campaign:{},referrer:ei};function kc(e,t){e===void 0&&(e=kr);var s=e.initialized,n=t.campaign;switch(t.type){case $.campaign:return V({},e,{campaign:n});case $.offline:return V({},e,{offline:!0});case $.online:return V({},e,{offline:!1});default:return s?e:V({},kr,e,{initialized:!0})}}var Ac=["plugins","reducers","storage"];function Pc(e,t,s){if(Ee){var n=window[(s?"add":"remove")+"EventListener"];e.split(" ").forEach(function(r){n(r,t)})}}function Oc(e){var t=Pc.bind(null,"online offline",function(s){return Promise.resolve(!navigator.onLine).then(e)});return t(!0),function(s){return t(!1)}}function ni(){return lt("analytics",[]),function(e){return function(t,s,n){var r=e(t,s,n),o=r.dispatch;return Object.assign(r,{dispatch:function(i){return Lt[Mt].analytics.push(i.action||i),o(i)}})}}}function Ar(e){return function(){return Nt(Nt.apply(null,arguments),ni())}}function Zs(e){return e?Ju(e)?e:[e]:[]}function Pr(e,t,s){e===void 0&&(e={});var n,r,o=$s();return t&&(Kt[o]=(n=t,r=function(i){for(var u,d=i||Array.prototype.slice.call(arguments),c=0;c<d.length;c++)if(Ce(d[c])){u=d[c];break}return u}(s),function(i){r&&r(i),n(i)})),V({},e,{rid:o,ts:new Date().getTime()},t?{hasCallback:!0}:{})}function jc(e){e===void 0&&(e={});var t=e.reducers||{},s=e.initialUser||{},n=(e.plugins||[]).reduce(function(f,p){if(Ce(p))return f.middlewares=f.middlewares.concat(p),f;if(p.NAMESPACE&&(p.name=p.NAMESPACE),!p.name)throw new Error("https://lytics.dev/errors/1");p.config||(p.config={});var U=p.EVENTS?Object.keys(p.EVENTS).map(function(J){return p.EVENTS[J]}):[];f.pluginEnabled[p.name]=!(p.enabled===!1||p.config.enabled===!1),delete p.enabled,p.methods&&(f.methods[p.name]=Object.keys(p.methods).reduce(function(J,oe){var X;return J[oe]=(X=p.methods[oe],function(){for(var ee=Array.prototype.slice.call(arguments),Y=new Array(X.length),ke=0;ke<ee.length;ke++)Y[ke]=ee[ke];return Y[Y.length]=A,X.apply({instance:A},Y)}),J},{}),delete p.methods);var H=Object.keys(p).concat(U),G=new Set(f.events.concat(H));if(f.events=Array.from(G),f.pluginsArray=f.pluginsArray.concat(p),f.plugins[p.name])throw new Error(p.name+"AlreadyLoaded");return f.plugins[p.name]=p,f.plugins[p.name].loaded||(f.plugins[p.name].loaded=function(){return!0}),f},{plugins:{},pluginEnabled:{},methods:{},pluginsArray:[],middlewares:[],events:[]}),r=e.storage?e.storage:{getItem:ct,setItem:lt,removeItem:Ut},o=function(f){return function(p,U,H){return U.getState("user")[p]||(H&&he(H)&&H[p]?H[p]:hr(f)[p]||ct(an(p))||null)}}(r),i=n.plugins,u=n.events.filter(function(f){return!on.includes(f)}).sort(),d=new Set(u.concat(Ps).filter(function(f){return!on.includes(f)})),c=Array.from(d).sort(),h=function(){return i},m=new pc,k=m.addMiddleware,v=m.removeMiddleware,C=m.dynamicMiddlewares,I=function(){throw new Error("Abort disabled inListener")},b=nc(),O=hr(r),R=V({},O,s,b.an_uid?{userId:b.an_uid}:{},b.an_aid?{anonymousId:b.an_aid}:{});R.anonymousId||(R.anonymousId=$s());var M=V({enable:function(f,p){return new Promise(function(U){E.dispatch({type:$.enablePlugin,plugins:Zs(f),_:{originalAction:$.enablePlugin}},U,[p])})},disable:function(f,p){return new Promise(function(U){E.dispatch({type:$.disablePlugin,plugins:Zs(f),_:{originalAction:$.disablePlugin}},U,[p])})}},n.methods),w=!1,A={identify:function(f,p,U,H){try{var G=mt(f)?f:null,J=he(f)?f:p,oe=U||{},X=A.user();lt(an(Te),G);var ee=G||J.userId||o(Te,A,J);return Promise.resolve(new Promise(function(Y){E.dispatch(V({type:$.identifyStart,userId:ee,traits:J||{},options:oe,anonymousId:X.anonymousId},X.id&&X.id!==G&&{previousId:X.id}),Y,[p,U,H])}))}catch(Y){return Promise.reject(Y)}},track:function(f,p,U,H){try{var G=he(f)?f.event:f;if(!G||!mt(G))throw new Error("EventMissing");var J=he(f)?f:p||{},oe=he(U)?U:{};return Promise.resolve(new Promise(function(X){E.dispatch({type:$.trackStart,event:G,properties:J,options:oe,userId:o(Te,A,p),anonymousId:o(pt,A,p)},X,[p,U,H])}))}catch(X){return Promise.reject(X)}},page:function(f,p,U){try{var H=he(f)?f:{},G=he(p)?p:{};return Promise.resolve(new Promise(function(J){E.dispatch({type:$.pageStart,properties:wc(H),options:G,userId:o(Te,A,H),anonymousId:o(pt,A,H)},J,[f,p,U])}))}catch(J){return Promise.reject(J)}},user:function(f){if(f===Te||f==="id")return o(Te,A);if(f===pt||f==="anonId")return o(pt,A);var p=A.getState("user");return f?ir(p,f):p},reset:function(f){return new Promise(function(p){E.dispatch({type:$.resetStart},p,f)})},ready:function(f){return w&&f({plugins:M,instance:A}),A.on($.ready,function(p){f(p),w=!0})},on:function(f,p){if(!f||!Ce(p))return!1;if(f===$.bootstrap)throw new Error(".on disabled for "+f);var U=/Start$|Start:/;if(f==="*"){var H=function(X){return function(ee){return function(Y){return Y.type.match(U)&&p({payload:Y,instance:A,plugins:i}),ee(Y)}}},G=function(X){return function(ee){return function(Y){return Y.type.match(U)||p({payload:Y,instance:A,plugins:i}),ee(Y)}}};return k(H,Es),k(G,ks),function(){v(H,Es),v(G,ks)}}var J=f.match(U)?Es:ks,oe=function(X){return function(ee){return function(Y){return Y.type===f&&p({payload:Y,instance:A,plugins:i,abort:I}),ee(Y)}}};return k(oe,J),function(){return v(oe,J)}},once:function(f,p){if(!f||!Ce(p))return!1;if(f===$.bootstrap)throw new Error(".once disabled for "+f);var U=A.on(f,function(H){p({payload:H.payload,instance:A,plugins:i,abort:I}),U()});return U},getState:function(f){var p=E.getState();return f?ir(p,f):Object.assign({},p)},dispatch:function(f){var p=mt(f)?{type:f}:f;if(Ps.includes(p.type))throw new Error("reserved action "+p.type);var U=V({},p,{_:V({originalAction:p.type},f._||{})});E.dispatch(U)},enablePlugin:M.enable,disablePlugin:M.disable,plugins:M,storage:{getItem:r.getItem,setItem:function(f,p,U){E.dispatch({type:$.setItemStart,key:f,value:p,options:U})},removeItem:function(f,p){E.dispatch({type:$.removeItemStart,key:f,options:p})}},setAnonymousId:function(f,p){A.storage.setItem(We,f,p)},events:{core:Ps,plugins:u}},q=n.middlewares.concat([function(f){return function(p){return function(U){return U.meta||(U.meta=Pr()),p(U)}}},C(Es),fc(A,h,{all:c,plugins:u}),hc(r),uc(A),lc(A),C(ks)]),F={context:kc,user:cc(r),page:Ec,track:yc,plugins:mc(h),queue:bc},T=Nt,g=Nt;if(Ee&&e.debug){var x=window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;x&&(T=x({trace:!0,traceLimit:25})),g=function(){return arguments.length===0?ni():he(typeof arguments[0])?Ar():Ar().apply(null,arguments)}}var D,S=function(f){return Object.keys(f).reduce(function(p,U){return Ac.includes(U)||(p[U]=f[U]),p},{})}(e),N=n.pluginsArray.reduce(function(f,p){var U=p.name,H=p.config,G=p.loaded,J=n.pluginEnabled[U];return f[U]={enabled:J,initialized:!!J&&!p.initialize,loaded:!!G({config:H}),config:H},f},{}),j={context:S,user:R,plugins:N},E=Ho(function(f){for(var p=Object.keys(f),U={},H=0;H<p.length;H++){var G=p[H];typeof f[G]===Fe&&(U[G]=f[G])}var J,oe=Object.keys(U);try{(function(X){Object.keys(X).forEach(function(ee){var Y=X[ee];if(typeof Y(void 0,{type:"@@redux/INIT"})===De||typeof Y(void 0,{type:oc})===De)throw new Error("reducer "+ee+" "+De)})})(U)}catch(X){J=X}return function(X,ee){if(X===void 0&&(X={}),J)throw J;for(var Y=!1,ke={},Vt=0;Vt<oe.length;Vt++){var ys=oe[Vt],Kn=X[ys],Hs=(0,U[ys])(Kn,ee);if(typeof Hs===De){var Ei=ic(ys,ee);throw new Error(Ei)}ke[ys]=Hs,Y=Y||Hs!==Kn}return Y?ke:X}}(V({},F,t)),j,g(T(ac.apply(void 0,q))));E.dispatch=(D=E.dispatch,function(f,p,U){var H=V({},f,{meta:Pr(f.meta,p,Zs(U))});return D.apply(null,[H])});var z=Object.keys(i);E.dispatch({type:$.bootstrap,plugins:z,config:S,params:b,user:R,initialUser:s,persistedUser:O});var Q=z.filter(function(f){return n.pluginEnabled[f]}),W=z.filter(function(f){return!n.pluginEnabled[f]});return E.dispatch({type:$.registerPlugins,plugins:z,enabled:n.pluginEnabled}),n.pluginsArray.map(function(f,p){var U=f.bootstrap,H=f.config,G=f.name;U&&Ce(U)&&U({instance:A,config:H,payload:f}),E.dispatch({type:$.registerPluginType(G),name:G,enabled:n.pluginEnabled[G],plugin:f}),n.pluginsArray.length===p+1&&E.dispatch({type:$.initializeStart,plugins:Q,disabled:W})}),Oc(function(f){E.dispatch({type:f?$.offline:$.online})}),function(f,p,U){setInterval(function(){return Wo(f,p,U)},3e3)}(E,h,A),A}var Es="before",ks="after",Wt="cookie",Ye=ii(),ri=Vs,Cc=Vs;function oi(e){return Ye?Vs(e,"",-1):Ut(e)}function ii(){if(Ye!==void 0)return Ye;var e="cookiecookie";try{Vs(e,e),Ye=document.cookie.indexOf(e)!==-1,oi(e)}catch{Ye=!1}return Ye}function Vs(e,t,s,n,r,o){if(typeof window<"u"){var i=arguments.length>1;return Ye===!1&&(i?lt(e,t):ct(e)),i?document.cookie=e+"="+encodeURIComponent(t)+(s?"; expires="+new Date(+new Date+1e3*s).toUTCString()+(n?"; path="+n:"")+(r?"; domain="+r:"")+(o?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}var Jt="localStorage",_c=Ln.bind(null,"localStorage");Ft("localStorage","getItem",ct);Ft("localStorage","setItem",lt);Ft("localStorage","removeItem",Ut);var Yt="sessionStorage",Bc=Ln.bind(null,"sessionStorage");Ft("sessionStorage","getItem",ct);Ft("sessionStorage","setItem",lt);Ft("sessionStorage","removeItem",Ut);function vt(e){var t=e;try{if((t=JSON.parse(e))==="true")return!0;if(t==="false")return!1;if(he(t))return t;parseFloat(t)===t&&(t=parseFloat(t))}catch{}if(t!==null&&t!=="")return t}var Ic=_c(),Rc=Bc(),Dc=ii();function ai(e,t){if(e){var s=Nn(t),n=!qn(s),r=Tn(s)?vt(localStorage.getItem(e)):void 0;if(n&&!ht(r))return r;var o=Un(s)?vt(ri(e)):void 0;if(n&&o)return o;var i=Fn(s)?vt(sessionStorage.getItem(e)):void 0;if(n&&i)return i;var u=ct(e);return n?u:{localStorage:r,sessionStorage:i,cookie:o,global:u}}}function Mc(e,t,s){if(e&&!ht(t)){var n={},r=Nn(s),o=JSON.stringify(t),i=!qn(r);return Tn(r)&&(n[Jt]=As(Jt,t,vt(localStorage.getItem(e))),localStorage.setItem(e,o),i)?n[Jt]:Un(r)&&(n[Wt]=As(Wt,t,vt(ri(e))),Cc(e,o),i)?n[Wt]:Fn(r)&&(n[Yt]=As(Yt,t,vt(sessionStorage.getItem(e))),sessionStorage.setItem(e,o),i)?n[Yt]:(n[Gt]=As(Gt,t,ct(e)),lt(e,t),i?n[Gt]:n)}}function Lc(e,t){if(e){var s=Nn(t),n=ai(e,Vo),r={};return!ht(n.localStorage)&&Tn(s)&&(localStorage.removeItem(e),r[Jt]=n.localStorage),!ht(n.cookie)&&Un(s)&&(oi(e),r[Wt]=n.cookie),!ht(n.sessionStorage)&&Fn(s)&&(sessionStorage.removeItem(e),r[Yt]=n.sessionStorage),!ht(n.global)&&Qs(s,Gt)&&(Ut(e),r[Gt]=n.global),r}}function Nn(e){return e?mt(e)?e:e.storage:$o}function Tn(e){return Ic&&Qs(e,Jt)}function Un(e){return Dc&&Qs(e,Wt)}function Fn(e){return Rc&&Qs(e,Yt)}function qn(e){return e===Vo||e==="all"}function Qs(e,t){return e===$o||e===t||qn(e)}function As(e,t,s){return{location:e,current:t,previous:s}}var Nc={setItem:Mc,getItem:ai,removeItem:Lc};function Tc(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}function Or(e,t){var s=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),s.push.apply(s,n)}return s}function jr(e){for(var t=1;t<arguments.length;t++){var s=arguments[t]!=null?arguments[t]:{};t%2?Or(Object(s),!0).forEach(function(n){Tc(e,n,s[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):Or(Object(s)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(s,n))})}return e}function Uc(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t={storage:Nc};return jc(jr(jr({},t),e))}const Fc="@chaibuilder/sdk",qc="0.1.13",$c="module",Vc=["dist"],Qc="dist/core.js",Kc=!1,zc={".":{import:"./dist/core.js",require:"./dist/core.cjs",types:"./dist/core.d.ts"},"./render":{import:"./dist/render.js",require:"./dist/render.cjs",types:"./dist/render.d.ts"},"./ui":{import:"./dist/ui.js",require:"./dist/ui.cjs",types:"./dist/ui.d.ts"},"./lib":{import:"./dist/lib.js",require:"./dist/lib.cjs",types:"./dist/lib.d.ts"},"./server":{import:"./dist/server.js",require:"./dist/server.cjs",types:"./dist/server.d.ts"},"./styles":{import:"./dist/style.css",require:"./dist/style.css"}},Hc={dev:"vite",build:"tsc && vite build",lint:"eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",preview:"vite preview",test:"jest --colors","test:watch":"jest --watch --colors","test:coverage":"jest --coverage --colors",e2e:"playwright test","e2e:report":"playwright show-report","e2e:ui":"playwright test --ui",docs:"jsdoc -c jsdoc.conf.json"},Gc={"@analytics/google-analytics":"^1.0.7","@bobthered/tailwindcss-palette-generator":"3.1.1","@chaibuilder/blocks":"^0.1.0","@floating-ui/dom":"1.4.5","@floating-ui/react-dom":"2.0.1","@mhsdesign/jit-browser-tailwindcss":"0.3.0","@minoru/react-dnd-treeview":"3.4.4","@radix-ui/react-accordion":"^1.1.2","@radix-ui/react-alert-dialog":"^1.0.4","@radix-ui/react-context-menu":"^2.1.4","@radix-ui/react-dialog":"^1.0.4","@radix-ui/react-dropdown-menu":"^2.0.5","@radix-ui/react-hover-card":"^1.0.6","@radix-ui/react-icons":"^1.3.0","@radix-ui/react-label":"^2.0.2","@radix-ui/react-menubar":"^1.0.3","@radix-ui/react-navigation-menu":"^1.1.3","@radix-ui/react-popover":"^1.0.6","@radix-ui/react-scroll-area":"^1.0.4","@radix-ui/react-select":"^1.2.2","@radix-ui/react-separator":"^1.0.3","@radix-ui/react-slot":"^1.0.2","@radix-ui/react-switch":"^1.0.3","@radix-ui/react-tabs":"^1.0.4","@radix-ui/react-toast":"^1.1.4","@radix-ui/react-toggle":"^1.0.3","@radix-ui/react-tooltip":"^1.0.6","@react-hookz/web":"23.1.0","@rjsf/core":"5.11.2","@rjsf/utils":"5.11.2","@rjsf/validator-ajv8":"5.11.2","@tailwindcss/aspect-ratio":"0.4.2","@tailwindcss/forms":"^0.5.6","@tailwindcss/line-clamp":"^0.4.4","@tailwindcss/typography":"^0.5.10","@tanstack/react-query":"^5.8.4",analytics:"^0.8.9","class-variance-authority":"0.6.1",clsx:"1.2.1",cmdk:"0.2.0","date-fns":"^2.30.0",flagged:"2.0.9","flat-to-nested":"1.1.1","focus-trap-react":"^10.2.1","forgiving-xml-parser":"1.4.0","framer-motion":"^10.12.18","fuse.js":"6.6.2","gray-matter":"^4.0.3",himalaya:"^1.1.0","html-formatter":"0.1.9",i18next:"^23.2.8",jotai:"2.2.2",lodash:"4.17.21","lucide-react":"^0.244.0",nanoid:"^4.0.2","post-robot":"10.0.46",react:"^18.2.0","react-autosuggest":"10.1.0","react-colorful":"5.6.1","react-dnd":"16.0.1","react-dnd-html5-backend":"16.0.1","react-dom":"^18.2.0","react-hotkeys-hook":"4.4.1","react-i18next":"13.0.1","react-icons":"^4.10.1","react-icons-picker":"^1.0.9","react-quill":"^2.0.0","react-textarea-autosize":"^8.5.2","react-wrap-balancer":"^1.0.0","redux-undo":"1.1.0",sonner:"^1.2.0","tailwind-merge":"1.13.2","tailwindcss-animate":"1.0.6","tippy.js":"^6.3.7","unist-util-visit":"^4.1.2","unsplash-js":"^7.0.18"},Wc={"@commitlint/cli":"17.7.1","@commitlint/config-conventional":"17.7.0","@faker-js/faker":"^8.3.1","@nozbe/watermelondb":"^0.27.1","@playwright/test":"^1.39.0","@tanstack/eslint-plugin-query":"^5.8.4","@testing-library/react-hooks":"^8.0.1","@types/better-sqlite3":"^7.6.7","@types/jest":"^29.5.7","@types/lodash":"^4.14.200","@types/node":"^20.8.10","@types/react":"^18.2.15","@types/react-dom":"^18.2.7","@typescript-eslint/eslint-plugin":"^6.0.0","@typescript-eslint/parser":"^6.0.0","@vitejs/plugin-react-swc":"^3.3.2",autoprefixer:"^10.4.16","better-docs":"^2.7.2","better-sqlite3":"^9.1.1","drizzle-kit":"^0.20.4","drizzle-orm":"^0.29.0",eslint:"^8.45.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-react-refresh":"^0.4.3",jest:"^29.7.0","jest-environment-jsdom":"^29.7.0",jsdoc:"^4.0.2",msw:"^2.0.8",postcss:"^8.4.31",prettier:"^3.0.3","prettier-plugin-tailwindcss":"^0.5.6","prop-types":"^15.8.1","react-router-dom":"^6.19.0",tailwindcss:"^3.3.5","ts-jest":"^29.1.1",typescript:"^5.0.2",vite:"^4.4.5","vite-plugin-dts":"^3.6.3"},Jc={workerDirectory:"public"},Yc={name:Fc,private:!1,version:qc,type:$c,files:Vc,main:Qc,sideEffects:Kc,exports:zc,scripts:Hc,dependencies:Gc,devDependencies:Wc,msw:Jc},Cr="https://api.chaibuilder.com",_r=()=>typeof window>"u"?!1:window.location.href.includes("localhost");function Xc(){return{name:"chaibuilder-analytics",config:{},initialize:()=>{if(typeof window>"u")return!1;window.chaibuilderAnalyticsLoaded=!0},page:e=>{if(typeof window>"u")return!1;if(_r())return;const{payload:t}=e;fetch(`${Cr}/v1/log`,{method:"post",body:JSON.stringify(t)}).then(s=>s.json())},track:({payload:e})=>{if(typeof window>"u")return!1;_r()||fetch(`${Cr}/v1/log`,{method:"post",body:JSON.stringify(e)})},loaded:()=>typeof window>"u"?!0:!!window.chaibuilderAnalyticsLoaded}}const Zc=Uc({app:"chaibuilder",version:Yc.version,plugins:[Xc()]});({}).NODE_ENV==="development"&&console.log("Chai Builder:",Ui);const el=e=>_.jsxRuntimeExports.jsx(_.jsxRuntimeExports.Fragment,{children:e.children}),tl=e=>{const{dndOptions:t={backend:zn.MultiBackend}}=e,[s]=ro(),[,n]=jn(),r=Mn();return B.useEffect(()=>{Qu.set(be.chaiBuilderPropsAtom,l.omit(e,["blocks","globalBlocks","brandingOptions"]))},[e]),B.useEffect(()=>{s(Jr.syncBlocksWithDefaults(e.blocks||[])),r()},[e.blocks]),B.useEffect(()=>{n(e.brandingOptions)},[e.brandingOptions]),B.useEffect(()=>{Zc.page()},[]),_.jsxRuntimeExports.jsx(Oi.DndProvider,{...t,options:zn.getBackendOptions(),children:_.jsxRuntimeExports.jsx(el,{children:_.jsxRuntimeExports.jsx(Vu,{})})})},ui=e=>_.jsxRuntimeExports.jsxs(Yr,{children:[_.jsxRuntimeExports.jsx(Pi.FlagsProvider,{features:Fi,children:_.jsxRuntimeExports.jsx(tl,{...e})}),_.jsxRuntimeExports.jsx(be.Toaster,{})]});var qt=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Tt=typeof window>"u"||"Deno"in window;function ve(){}function sl(e,t){return typeof e=="function"?e(t):e}function un(e){return typeof e=="number"&&e>=0&&e!==1/0}function ci(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Br(e,t){const{type:s="all",exact:n,fetchStatus:r,predicate:o,queryKey:i,stale:u}=e;if(i){if(n){if(t.queryHash!==$n(i,t.options))return!1}else if(!es(t.queryKey,i))return!1}if(s!=="all"){const d=t.isActive();if(s==="active"&&!d||s==="inactive"&&d)return!1}return!(typeof u=="boolean"&&t.isStale()!==u||typeof r<"u"&&r!==t.state.fetchStatus||o&&!o(t))}function Ir(e,t){const{exact:s,status:n,predicate:r,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(s){if(Zt(t.options.mutationKey)!==Zt(o))return!1}else if(!es(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||r&&!r(t))}function $n(e,t){return((t==null?void 0:t.queryKeyHashFn)||Zt)(e)}function Zt(e){return JSON.stringify(e,(t,s)=>cn(s)?Object.keys(s).sort().reduce((n,r)=>(n[r]=s[r],n),{}):s)}function es(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(s=>!es(e[s],t[s])):!1}function li(e,t){if(e===t)return e;const s=Rr(e)&&Rr(t);if(s||cn(e)&&cn(t)){const n=s?e.length:Object.keys(e).length,r=s?t:Object.keys(t),o=r.length,i=s?[]:{};let u=0;for(let d=0;d<o;d++){const c=s?d:r[d];i[c]=li(e[c],t[c]),i[c]===e[c]&&u++}return n===o&&u===n?e:i}return t}function Rs(e,t){if(e&&!t||t&&!e)return!1;for(const s in e)if(e[s]!==t[s])return!1;return!0}function Rr(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function cn(e){if(!Dr(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const s=t.prototype;return!(!Dr(s)||!s.hasOwnProperty("isPrototypeOf"))}function Dr(e){return Object.prototype.toString.call(e)==="[object Object]"}function di(e){return new Promise(t=>{setTimeout(t,e)})}function Mr(e){di(0).then(e)}function ln(e,t,s){return typeof s.structuralSharing=="function"?s.structuralSharing(e,t):s.structuralSharing!==!1?li(e,t):t}function nl(e,t,s=0){const n=[...e,t];return s&&n.length>s?n.slice(1):n}function rl(e,t,s=0){const n=[t,...e];return s&&n.length>s?n.slice(0,-1):n}var Xe,qe,bt,Ur,ol=(Ur=class extends qt{constructor(){super();L(this,Xe,void 0);L(this,qe,void 0);L(this,bt,void 0);P(this,bt,t=>{if(!Tt&&window.addEventListener){const s=()=>t();return window.addEventListener("visibilitychange",s,!1),()=>{window.removeEventListener("visibilitychange",s)}}})}onSubscribe(){a(this,qe)||this.setEventListener(a(this,bt))}onUnsubscribe(){var t;this.hasListeners()||((t=a(this,qe))==null||t.call(this),P(this,qe,void 0))}setEventListener(t){var s;P(this,bt,t),(s=a(this,qe))==null||s.call(this),P(this,qe,t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()}))}setFocused(t){a(this,Xe)!==t&&(P(this,Xe,t),this.onFocus())}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){var t;return typeof a(this,Xe)=="boolean"?a(this,Xe):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},Xe=new WeakMap,qe=new WeakMap,bt=new WeakMap,Ur),Ds=new ol,xt,$e,wt,Fr,il=(Fr=class extends qt{constructor(){super();L(this,xt,!0);L(this,$e,void 0);L(this,wt,void 0);P(this,wt,t=>{if(!Tt&&window.addEventListener){const s=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",s,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",s),window.removeEventListener("offline",n)}}})}onSubscribe(){a(this,$e)||this.setEventListener(a(this,wt))}onUnsubscribe(){var t;this.hasListeners()||((t=a(this,$e))==null||t.call(this),P(this,$e,void 0))}setEventListener(t){var s;P(this,wt,t),(s=a(this,$e))==null||s.call(this),P(this,$e,t(this.setOnline.bind(this)))}setOnline(t){a(this,xt)!==t&&(P(this,xt,t),this.listeners.forEach(n=>{n(t)}))}isOnline(){return a(this,xt)}},xt=new WeakMap,$e=new WeakMap,wt=new WeakMap,Fr),Ms=new il;function al(e){return Math.min(1e3*2**e,3e4)}function Ks(e){return(e??"online")==="online"?Ms.isOnline():!0}var fi=class{constructor(e){this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function en(e){return e instanceof fi}function hi(e){let t=!1,s=0,n=!1,r,o,i;const u=new Promise((b,O)=>{o=b,i=O}),d=b=>{var O;n||(v(new fi(b)),(O=e.abort)==null||O.call(e))},c=()=>{t=!0},h=()=>{t=!1},m=()=>!Ds.isFocused()||e.networkMode!=="always"&&!Ms.isOnline(),k=b=>{var O;n||(n=!0,(O=e.onSuccess)==null||O.call(e,b),r==null||r(),o(b))},v=b=>{var O;n||(n=!0,(O=e.onError)==null||O.call(e,b),r==null||r(),i(b))},C=()=>new Promise(b=>{var O;r=R=>{const M=n||!m();return M&&b(R),M},(O=e.onPause)==null||O.call(e)}).then(()=>{var b;r=void 0,n||(b=e.onContinue)==null||b.call(e)}),I=()=>{if(n)return;let b;try{b=e.fn()}catch(O){b=Promise.reject(O)}Promise.resolve(b).then(k).catch(O=>{var q;if(n)return;const R=e.retry??(Tt?0:3),M=e.retryDelay??al,w=typeof M=="function"?M(s,O):M,A=R===!0||typeof R=="number"&&s<R||typeof R=="function"&&R(s,O);if(t||!A){v(O);return}s++,(q=e.onFail)==null||q.call(e,s,O),di(w).then(()=>{if(m())return C()}).then(()=>{t?v(O):I()})})};return Ks(e.networkMode)?I():C().then(I),{promise:u,cancel:d,continue:()=>(r==null?void 0:r())?u:Promise.resolve(),cancelRetry:c,continueRetry:h}}function ul(){let e=[],t=0,s=h=>{h()},n=h=>{h()};const r=h=>{let m;t++;try{m=h()}finally{t--,t||u()}return m},o=h=>{t?e.push(h):Mr(()=>{s(h)})},i=h=>(...m)=>{o(()=>{h(...m)})},u=()=>{const h=e;e=[],h.length&&Mr(()=>{n(()=>{h.forEach(m=>{s(m)})})})};return{batch:r,batchCalls:i,schedule:o,setNotifyFunction:h=>{s=h},setBatchNotifyFunction:h=>{n=h}}}var se=ul(),Ze,qr,pi=(qr=class{constructor(){L(this,Ze,void 0)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),un(this.gcTime)&&P(this,Ze,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Tt?1/0:5*60*1e3))}clearGcTimeout(){a(this,Ze)&&(clearTimeout(a(this,Ze)),P(this,Ze,void 0))}},Ze=new WeakMap,qr),St,Et,pe,Ve,me,ne,ts,et,kt,Os,Se,Ie,$r,cl=($r=class extends pi{constructor(t){super();L(this,kt);L(this,Se);L(this,St,void 0);L(this,Et,void 0);L(this,pe,void 0);L(this,Ve,void 0);L(this,me,void 0);L(this,ne,void 0);L(this,ts,void 0);L(this,et,void 0);P(this,et,!1),P(this,ts,t.defaultOptions),K(this,kt,Os).call(this,t.options),P(this,ne,[]),P(this,pe,t.cache),this.queryKey=t.queryKey,this.queryHash=t.queryHash,P(this,St,t.state||ll(this.options)),this.state=a(this,St),this.scheduleGc()}get meta(){return this.options.meta}optionalRemove(){!a(this,ne).length&&this.state.fetchStatus==="idle"&&a(this,pe).remove(this)}setData(t,s){const n=ln(this.state.data,t,this.options);return K(this,Se,Ie).call(this,{data:n,type:"success",dataUpdatedAt:s==null?void 0:s.updatedAt,manual:s==null?void 0:s.manual}),n}setState(t,s){K(this,Se,Ie).call(this,{type:"setState",state:t,setStateOptions:s})}cancel(t){var n;const s=a(this,Ve);return(n=a(this,me))==null||n.cancel(t),s?s.then(ve).catch(ve):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(a(this,St))}isActive(){return a(this,ne).some(t=>t.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||a(this,ne).some(t=>t.getCurrentResult().isStale)}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!ci(this.state.dataUpdatedAt,t)}onFocus(){var s;const t=a(this,ne).find(n=>n.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(s=a(this,me))==null||s.continue()}onOnline(){var s;const t=a(this,ne).find(n=>n.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(s=a(this,me))==null||s.continue()}addObserver(t){a(this,ne).includes(t)||(a(this,ne).push(t),this.clearGcTimeout(),a(this,pe).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){a(this,ne).includes(t)&&(P(this,ne,a(this,ne).filter(s=>s!==t)),a(this,ne).length||(a(this,me)&&(a(this,et)?a(this,me).cancel({revert:!0}):a(this,me).cancelRetry()),this.scheduleGc()),a(this,pe).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return a(this,ne).length}invalidate(){this.state.isInvalidated||K(this,Se,Ie).call(this,{type:"invalidate"})}fetch(t,s){var c,h,m,k;if(this.state.fetchStatus!=="idle"){if(this.state.dataUpdatedAt&&(s!=null&&s.cancelRefetch))this.cancel({silent:!0});else if(a(this,Ve))return(c=a(this,me))==null||c.continueRetry(),a(this,Ve)}if(t&&K(this,kt,Os).call(this,t),!this.options.queryFn){const v=a(this,ne).find(C=>C.options.queryFn);v&&K(this,kt,Os).call(this,v.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const n=new AbortController,r={queryKey:this.queryKey,meta:this.meta},o=v=>{Object.defineProperty(v,"signal",{enumerable:!0,get:()=>(P(this,et,!0),n.signal)})};o(r);const i=()=>this.options.queryFn?(P(this,et,!1),this.options.persister?this.options.persister(this.options.queryFn,r,this):this.options.queryFn(r)):Promise.reject(new Error(`Missing queryFn: '${this.options.queryHash}'`)),u={fetchOptions:s,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:i};o(u),(h=this.options.behavior)==null||h.onFetch(u,this),P(this,Et,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((m=u.fetchOptions)==null?void 0:m.meta))&&K(this,Se,Ie).call(this,{type:"fetch",meta:(k=u.fetchOptions)==null?void 0:k.meta});const d=v=>{var C,I,b,O;en(v)&&v.silent||K(this,Se,Ie).call(this,{type:"error",error:v}),en(v)||((I=(C=a(this,pe).config).onError)==null||I.call(C,v,this),(O=(b=a(this,pe).config).onSettled)==null||O.call(b,this.state.data,v,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return P(this,me,hi({fn:u.fetchFn,abort:n.abort.bind(n),onSuccess:v=>{var C,I,b,O;if(typeof v>"u"){process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),d(new Error(`${this.queryHash} data is undefined`));return}this.setData(v),(I=(C=a(this,pe).config).onSuccess)==null||I.call(C,v,this),(O=(b=a(this,pe).config).onSettled)==null||O.call(b,v,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:d,onFail:(v,C)=>{K(this,Se,Ie).call(this,{type:"failed",failureCount:v,error:C})},onPause:()=>{K(this,Se,Ie).call(this,{type:"pause"})},onContinue:()=>{K(this,Se,Ie).call(this,{type:"continue"})},retry:u.options.retry,retryDelay:u.options.retryDelay,networkMode:u.options.networkMode})),P(this,Ve,a(this,me).promise),a(this,Ve)}},St=new WeakMap,Et=new WeakMap,pe=new WeakMap,Ve=new WeakMap,me=new WeakMap,ne=new WeakMap,ts=new WeakMap,et=new WeakMap,kt=new WeakSet,Os=function(t){this.options={...a(this,ts),...t},this.updateGcTime(this.options.gcTime)},Se=new WeakSet,Ie=function(t){const s=n=>{switch(t.type){case"failed":return{...n,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:Ks(this.options.networkMode)?"fetching":"paused",...!n.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...n,data:t.data,dataUpdateCount:n.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const r=t.error;return en(r)&&r.revert&&a(this,Et)?{...a(this,Et),fetchStatus:"idle"}:{...n,error:r,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:r,fetchStatus:"idle",status:"error"};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...t.state}}};this.state=s(this.state),se.batch(()=>{a(this,ne).forEach(n=>{n.onQueryUpdate()}),a(this,pe).notify({query:this,type:"updated",action:t})})},$r);function ll(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,s=typeof t<"u",n=s?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:s?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:s?"success":"pending",fetchStatus:"idle"}}var Ae,Vr,dl=(Vr=class extends qt{constructor(t={}){super();L(this,Ae,void 0);this.config=t,P(this,Ae,new Map)}build(t,s,n){const r=s.queryKey,o=s.queryHash??$n(r,s);let i=this.get(o);return i||(i=new cl({cache:this,queryKey:r,queryHash:o,options:t.defaultQueryOptions(s),state:n,defaultOptions:t.getQueryDefaults(r)}),this.add(i)),i}add(t){a(this,Ae).has(t.queryHash)||(a(this,Ae).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const s=a(this,Ae).get(t.queryHash);s&&(t.destroy(),s===t&&a(this,Ae).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){se.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return a(this,Ae).get(t)}getAll(){return[...a(this,Ae).values()]}find(t){const s={exact:!0,...t};return this.getAll().find(n=>Br(s,n))}findAll(t={}){const s=this.getAll();return Object.keys(t).length>0?s.filter(n=>Br(t,n)):s}notify(t){se.batch(()=>{this.listeners.forEach(s=>{s(t)})})}onFocus(){se.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){se.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},Ae=new WeakMap,Vr),Pe,ss,fe,At,Oe,Ne,Qr,fl=(Qr=class extends pi{constructor(t){super();L(this,Oe);L(this,Pe,void 0);L(this,ss,void 0);L(this,fe,void 0);L(this,At,void 0);this.mutationId=t.mutationId,P(this,ss,t.defaultOptions),P(this,fe,t.mutationCache),P(this,Pe,[]),this.state=t.state||mi(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...a(this,ss),...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){a(this,Pe).includes(t)||(a(this,Pe).push(t),this.clearGcTimeout(),a(this,fe).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){P(this,Pe,a(this,Pe).filter(s=>s!==t)),this.scheduleGc(),a(this,fe).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){a(this,Pe).length||(this.state.status==="pending"?this.scheduleGc():a(this,fe).remove(this))}continue(){var t;return((t=a(this,At))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var r,o,i,u,d,c,h,m,k,v,C,I,b,O,R,M,w,A,q,F;const s=()=>(P(this,At,hi({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(T,g)=>{K(this,Oe,Ne).call(this,{type:"failed",failureCount:T,error:g})},onPause:()=>{K(this,Oe,Ne).call(this,{type:"pause"})},onContinue:()=>{K(this,Oe,Ne).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode})),a(this,At).promise),n=this.state.status==="pending";try{if(!n){K(this,Oe,Ne).call(this,{type:"pending",variables:t}),await((o=(r=a(this,fe).config).onMutate)==null?void 0:o.call(r,t,this));const g=await((u=(i=this.options).onMutate)==null?void 0:u.call(i,t));g!==this.state.context&&K(this,Oe,Ne).call(this,{type:"pending",context:g,variables:t})}const T=await s();return await((c=(d=a(this,fe).config).onSuccess)==null?void 0:c.call(d,T,t,this.state.context,this)),await((m=(h=this.options).onSuccess)==null?void 0:m.call(h,T,t,this.state.context)),await((v=(k=a(this,fe).config).onSettled)==null?void 0:v.call(k,T,null,this.state.variables,this.state.context,this)),await((I=(C=this.options).onSettled)==null?void 0:I.call(C,T,null,t,this.state.context)),K(this,Oe,Ne).call(this,{type:"success",data:T}),T}catch(T){try{throw await((O=(b=a(this,fe).config).onError)==null?void 0:O.call(b,T,t,this.state.context,this)),await((M=(R=this.options).onError)==null?void 0:M.call(R,T,t,this.state.context)),await((A=(w=a(this,fe).config).onSettled)==null?void 0:A.call(w,void 0,T,this.state.variables,this.state.context,this)),await((F=(q=this.options).onSettled)==null?void 0:F.call(q,void 0,T,t,this.state.context)),T}finally{K(this,Oe,Ne).call(this,{type:"error",error:T})}}}},Pe=new WeakMap,ss=new WeakMap,fe=new WeakMap,At=new WeakMap,Oe=new WeakSet,Ne=function(t){const s=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!Ks(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=s(this.state),se.batch(()=>{a(this,Pe).forEach(n=>{n.onMutationUpdate(t)}),a(this,fe).notify({mutation:this,type:"updated",action:t})})},Qr);function mi(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var ge,ns,tt,Kr,hl=(Kr=class extends qt{constructor(t={}){super();L(this,ge,void 0);L(this,ns,void 0);L(this,tt,void 0);this.config=t,P(this,ge,[]),P(this,ns,0)}build(t,s,n){const r=new fl({mutationCache:this,mutationId:++vs(this,ns)._,options:t.defaultMutationOptions(s),state:n});return this.add(r),r}add(t){a(this,ge).push(t),this.notify({type:"added",mutation:t})}remove(t){P(this,ge,a(this,ge).filter(s=>s!==t)),this.notify({type:"removed",mutation:t})}clear(){se.batch(()=>{a(this,ge).forEach(t=>{this.remove(t)})})}getAll(){return a(this,ge)}find(t){const s={exact:!0,...t};return a(this,ge).find(n=>Ir(s,n))}findAll(t={}){return a(this,ge).filter(s=>Ir(t,s))}notify(t){se.batch(()=>{this.listeners.forEach(s=>{s(t)})})}resumePausedMutations(){return P(this,tt,(a(this,tt)??Promise.resolve()).then(()=>{const t=a(this,ge).filter(s=>s.state.isPaused);return se.batch(()=>t.reduce((s,n)=>s.then(()=>n.continue().catch(ve)),Promise.resolve()))}).then(()=>{P(this,tt,void 0)})),a(this,tt)}},ge=new WeakMap,ns=new WeakMap,tt=new WeakMap,Kr);function pl(e){return{onFetch:(t,s)=>{const n=async()=>{var C,I,b,O,R;const r=t.options,o=(b=(I=(C=t.fetchOptions)==null?void 0:C.meta)==null?void 0:I.fetchMore)==null?void 0:b.direction,i=((O=t.state.data)==null?void 0:O.pages)||[],u=((R=t.state.data)==null?void 0:R.pageParams)||[],d={pages:[],pageParams:[]};let c=!1;const h=M=>{Object.defineProperty(M,"signal",{enumerable:!0,get:()=>(t.signal.aborted?c=!0:t.signal.addEventListener("abort",()=>{c=!0}),t.signal)})},m=t.options.queryFn||(()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`))),k=async(M,w,A)=>{if(c)return Promise.reject();if(w==null&&M.pages.length)return Promise.resolve(M);const q={queryKey:t.queryKey,pageParam:w,direction:A?"backward":"forward",meta:t.options.meta};h(q);const F=await m(q),{maxPages:T}=t.options,g=A?rl:nl;return{pages:g(M.pages,F,T),pageParams:g(M.pageParams,w,T)}};let v;if(o&&i.length){const M=o==="backward",w=M?ml:Lr,A={pages:i,pageParams:u},q=w(r,A);v=await k(A,q,M)}else{v=await k(d,u[0]??r.initialPageParam);const M=e??i.length;for(let w=1;w<M;w++){const A=Lr(r,v);v=await k(v,A)}}return v};t.options.persister?t.fetchFn=()=>{var r,o;return(o=(r=t.options).persister)==null?void 0:o.call(r,n,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},s)}:t.fetchFn=n}}}function Lr(e,{pages:t,pageParams:s}){const n=t.length-1;return e.getNextPageParam(t[n],t,s[n],s)}function ml(e,{pages:t,pageParams:s}){var n;return(n=e.getPreviousPageParam)==null?void 0:n.call(e,t[0],t,s[0],s)}var te,Qe,Ke,Pt,Ot,ze,jt,Ct,zr,gl=(zr=class{constructor(e={}){L(this,te,void 0);L(this,Qe,void 0);L(this,Ke,void 0);L(this,Pt,void 0);L(this,Ot,void 0);L(this,ze,void 0);L(this,jt,void 0);L(this,Ct,void 0);P(this,te,e.queryCache||new dl),P(this,Qe,e.mutationCache||new hl),P(this,Ke,e.defaultOptions||{}),P(this,Pt,new Map),P(this,Ot,new Map),P(this,ze,0)}mount(){vs(this,ze)._++,a(this,ze)===1&&(P(this,jt,Ds.subscribe(()=>{Ds.isFocused()&&(this.resumePausedMutations(),a(this,te).onFocus())})),P(this,Ct,Ms.subscribe(()=>{Ms.isOnline()&&(this.resumePausedMutations(),a(this,te).onOnline())})))}unmount(){var e,t;vs(this,ze)._--,a(this,ze)===0&&((e=a(this,jt))==null||e.call(this),P(this,jt,void 0),(t=a(this,Ct))==null||t.call(this),P(this,Ct,void 0))}isFetching(e){return a(this,te).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return a(this,Qe).findAll({...e,status:"pending"}).length}getQueryData(e){var t;return(t=a(this,te).find({queryKey:e}))==null?void 0:t.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);return t!==void 0?Promise.resolve(t):this.fetchQuery(e)}getQueriesData(e){return this.getQueryCache().findAll(e).map(({queryKey:t,state:s})=>{const n=s.data;return[t,n]})}setQueryData(e,t,s){const n=a(this,te).find({queryKey:e}),r=n==null?void 0:n.state.data,o=sl(t,r);if(typeof o>"u")return;const i=this.defaultQueryOptions({queryKey:e});return a(this,te).build(this,i).setData(o,{...s,manual:!0})}setQueriesData(e,t,s){return se.batch(()=>this.getQueryCache().findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,s)]))}getQueryState(e){var t;return(t=a(this,te).find({queryKey:e}))==null?void 0:t.state}removeQueries(e){const t=a(this,te);se.batch(()=>{t.findAll(e).forEach(s=>{t.remove(s)})})}resetQueries(e,t){const s=a(this,te),n={type:"active",...e};return se.batch(()=>(s.findAll(e).forEach(r=>{r.reset()}),this.refetchQueries(n,t)))}cancelQueries(e={},t={}){const s={revert:!0,...t},n=se.batch(()=>a(this,te).findAll(e).map(r=>r.cancel(s)));return Promise.all(n).then(ve).catch(ve)}invalidateQueries(e={},t={}){return se.batch(()=>{if(a(this,te).findAll(e).forEach(n=>{n.invalidate()}),e.refetchType==="none")return Promise.resolve();const s={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(s,t)})}refetchQueries(e={},t){const s={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},n=se.batch(()=>a(this,te).findAll(e).filter(r=>!r.isDisabled()).map(r=>{let o=r.fetch(void 0,s);return s.throwOnError||(o=o.catch(ve)),r.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(ve)}fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const s=a(this,te).build(this,t);return s.isStaleByTime(t.staleTime)?s.fetch(t):Promise.resolve(s.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(ve).catch(ve)}fetchInfiniteQuery(e){return e.behavior=pl(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(ve).catch(ve)}resumePausedMutations(){return a(this,Qe).resumePausedMutations()}getQueryCache(){return a(this,te)}getMutationCache(){return a(this,Qe)}getDefaultOptions(){return a(this,Ke)}setDefaultOptions(e){P(this,Ke,e)}setQueryDefaults(e,t){a(this,Pt).set(Zt(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...a(this,Pt).values()];let s={};return t.forEach(n=>{es(e,n.queryKey)&&(s={...s,...n.defaultOptions})}),s}setMutationDefaults(e,t){a(this,Ot).set(Zt(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...a(this,Ot).values()];let s={};return t.forEach(n=>{es(e,n.mutationKey)&&(s={...s,...n.defaultOptions})}),s}defaultQueryOptions(e){if(e!=null&&e._defaulted)return e;const t={...a(this,Ke).queries,...(e==null?void 0:e.queryKey)&&this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=$n(t.queryKey,t)),typeof t.refetchOnReconnect>"u"&&(t.refetchOnReconnect=t.networkMode!=="always"),typeof t.throwOnError>"u"&&(t.throwOnError=!!t.suspense),typeof t.networkMode>"u"&&t.persister&&(t.networkMode="offlineFirst"),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...a(this,Ke).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){a(this,te).clear(),a(this,Qe).clear()}},te=new WeakMap,Qe=new WeakMap,Ke=new WeakMap,Pt=new WeakMap,Ot=new WeakMap,ze=new WeakMap,jt=new WeakMap,Ct=new WeakMap,zr),ce,Z,_t,ie,st,Bt,je,rs,It,Rt,nt,rt,He,ot,it,zt,os,dn,is,fn,as,hn,us,pn,cs,mn,ls,gn,ds,yn,Ls,gi,Hr,yl=(Hr=class extends qt{constructor(t,s){super();L(this,it);L(this,os);L(this,is);L(this,as);L(this,us);L(this,cs);L(this,ls);L(this,ds);L(this,Ls);L(this,ce,void 0);L(this,Z,void 0);L(this,_t,void 0);L(this,ie,void 0);L(this,st,void 0);L(this,Bt,void 0);L(this,je,void 0);L(this,rs,void 0);L(this,It,void 0);L(this,Rt,void 0);L(this,nt,void 0);L(this,rt,void 0);L(this,He,void 0);L(this,ot,void 0);P(this,Z,void 0),P(this,_t,void 0),P(this,ie,void 0),P(this,ot,new Set),P(this,ce,t),this.options=s,P(this,je,null),this.bindMethods(),this.setOptions(s)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(a(this,Z).addObserver(this),Nr(a(this,Z),this.options)?K(this,it,zt).call(this):this.updateResult(),K(this,us,pn).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return vn(a(this,Z),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return vn(a(this,Z),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,K(this,cs,mn).call(this),K(this,ls,gn).call(this),a(this,Z).removeObserver(this)}setOptions(t,s){const n=this.options,r=a(this,Z);if(this.options=a(this,ce).defaultQueryOptions(t),Rs(n,this.options)||a(this,ce).getQueryCache().notify({type:"observerOptionsUpdated",query:a(this,Z),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),K(this,ds,yn).call(this);const o=this.hasListeners();o&&Tr(a(this,Z),r,this.options,n)&&K(this,it,zt).call(this),this.updateResult(s),o&&(a(this,Z)!==r||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&K(this,os,dn).call(this);const i=K(this,is,fn).call(this);o&&(a(this,Z)!==r||this.options.enabled!==n.enabled||i!==a(this,He))&&K(this,as,hn).call(this,i)}getOptimisticResult(t){const s=a(this,ce).getQueryCache().build(a(this,ce),t),n=this.createResult(s,t);return bl(this,n)&&(P(this,ie,n),P(this,Bt,this.options),P(this,st,a(this,Z).state)),n}getCurrentResult(){return a(this,ie)}trackResult(t){const s={};return Object.keys(t).forEach(n=>{Object.defineProperty(s,n,{configurable:!1,enumerable:!0,get:()=>(a(this,ot).add(n),t[n])})}),s}getCurrentQuery(){return a(this,Z)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const s=a(this,ce).defaultQueryOptions(t),n=a(this,ce).getQueryCache().build(a(this,ce),s);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,s))}fetch(t){return K(this,it,zt).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),a(this,ie)))}createResult(t,s){var q;const n=a(this,Z),r=this.options,o=a(this,ie),i=a(this,st),u=a(this,Bt),c=t!==n?t.state:a(this,_t),{state:h}=t;let{error:m,errorUpdatedAt:k,fetchStatus:v,status:C}=h,I=!1,b;if(s._optimisticResults){const F=this.hasListeners(),T=!F&&Nr(t,s),g=F&&Tr(t,n,s,r);(T||g)&&(v=Ks(t.options.networkMode)?"fetching":"paused",h.dataUpdatedAt||(C="pending")),s._optimisticResults==="isRestoring"&&(v="idle")}if(s.select&&typeof h.data<"u")if(o&&h.data===(i==null?void 0:i.data)&&s.select===a(this,rs))b=a(this,It);else try{P(this,rs,s.select),b=s.select(h.data),b=ln(o==null?void 0:o.data,b,s),P(this,It,b),P(this,je,null)}catch(F){P(this,je,F)}else b=h.data;if(typeof s.placeholderData<"u"&&typeof b>"u"&&C==="pending"){let F;if(o!=null&&o.isPlaceholderData&&s.placeholderData===(u==null?void 0:u.placeholderData))F=o.data;else if(F=typeof s.placeholderData=="function"?s.placeholderData((q=a(this,Rt))==null?void 0:q.state.data,a(this,Rt)):s.placeholderData,s.select&&typeof F<"u")try{F=s.select(F),P(this,je,null)}catch(T){P(this,je,T)}typeof F<"u"&&(C="success",b=ln(o==null?void 0:o.data,F,s),I=!0)}a(this,je)&&(m=a(this,je),b=a(this,It),k=Date.now(),C="error");const O=v==="fetching",R=C==="pending",M=C==="error",w=R&&O;return{status:C,fetchStatus:v,isPending:R,isSuccess:C==="success",isError:M,isInitialLoading:w,isLoading:w,data:b,dataUpdatedAt:h.dataUpdatedAt,error:m,errorUpdatedAt:k,failureCount:h.fetchFailureCount,failureReason:h.fetchFailureReason,errorUpdateCount:h.errorUpdateCount,isFetched:h.dataUpdateCount>0||h.errorUpdateCount>0,isFetchedAfterMount:h.dataUpdateCount>c.dataUpdateCount||h.errorUpdateCount>c.errorUpdateCount,isFetching:O,isRefetching:O&&!R,isLoadingError:M&&h.dataUpdatedAt===0,isPaused:v==="paused",isPlaceholderData:I,isRefetchError:M&&h.dataUpdatedAt!==0,isStale:Vn(t,s),refetch:this.refetch}}updateResult(t){const s=a(this,ie),n=this.createResult(a(this,Z),this.options);if(P(this,st,a(this,Z).state),P(this,Bt,this.options),a(this,st).data!==void 0&&P(this,Rt,a(this,Z)),Rs(n,s))return;P(this,ie,n);const r={},o=()=>{if(!s)return!0;const{notifyOnChangeProps:i}=this.options,u=typeof i=="function"?i():i;if(u==="all"||!u&&!a(this,ot).size)return!0;const d=new Set(u??a(this,ot));return this.options.throwOnError&&d.add("error"),Object.keys(a(this,ie)).some(c=>{const h=c;return a(this,ie)[h]!==s[h]&&d.has(h)})};(t==null?void 0:t.listeners)!==!1&&o()&&(r.listeners=!0),K(this,Ls,gi).call(this,{...r,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&K(this,us,pn).call(this)}},ce=new WeakMap,Z=new WeakMap,_t=new WeakMap,ie=new WeakMap,st=new WeakMap,Bt=new WeakMap,je=new WeakMap,rs=new WeakMap,It=new WeakMap,Rt=new WeakMap,nt=new WeakMap,rt=new WeakMap,He=new WeakMap,ot=new WeakMap,it=new WeakSet,zt=function(t){K(this,ds,yn).call(this);let s=a(this,Z).fetch(this.options,t);return t!=null&&t.throwOnError||(s=s.catch(ve)),s},os=new WeakSet,dn=function(){if(K(this,cs,mn).call(this),Tt||a(this,ie).isStale||!un(this.options.staleTime))return;const s=ci(a(this,ie).dataUpdatedAt,this.options.staleTime)+1;P(this,nt,setTimeout(()=>{a(this,ie).isStale||this.updateResult()},s))},is=new WeakSet,fn=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(a(this,Z)):this.options.refetchInterval)??!1},as=new WeakSet,hn=function(t){K(this,ls,gn).call(this),P(this,He,t),!(Tt||this.options.enabled===!1||!un(a(this,He))||a(this,He)===0)&&P(this,rt,setInterval(()=>{(this.options.refetchIntervalInBackground||Ds.isFocused())&&K(this,it,zt).call(this)},a(this,He)))},us=new WeakSet,pn=function(){K(this,os,dn).call(this),K(this,as,hn).call(this,K(this,is,fn).call(this))},cs=new WeakSet,mn=function(){a(this,nt)&&(clearTimeout(a(this,nt)),P(this,nt,void 0))},ls=new WeakSet,gn=function(){a(this,rt)&&(clearInterval(a(this,rt)),P(this,rt,void 0))},ds=new WeakSet,yn=function(){const t=a(this,ce).getQueryCache().build(a(this,ce),this.options);if(t===a(this,Z))return;const s=a(this,Z);P(this,Z,t),P(this,_t,t.state),this.hasListeners()&&(s==null||s.removeObserver(this),t.addObserver(this))},Ls=new WeakSet,gi=function(t){se.batch(()=>{t.listeners&&this.listeners.forEach(s=>{s(a(this,ie))}),a(this,ce).getQueryCache().notify({query:a(this,Z),type:"observerResultsUpdated"})})},Hr);function vl(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function Nr(e,t){return vl(e,t)||e.state.dataUpdatedAt>0&&vn(e,t,t.refetchOnMount)}function vn(e,t,s){if(t.enabled!==!1){const n=typeof s=="function"?s(e):s;return n==="always"||n!==!1&&Vn(e,t)}return!1}function Tr(e,t,s,n){return s.enabled!==!1&&(e!==t||n.enabled===!1)&&(!s.suspense||e.state.status!=="error")&&Vn(e,s)}function Vn(e,t){return e.isStaleByTime(t.staleTime)}function bl(e,t){return!Rs(e.getCurrentResult(),t)}var Ge,ae,ye,Re,Dt,js,fs,bn,Gr,xl=(Gr=class extends qt{constructor(t,s){super();L(this,Dt);L(this,fs);L(this,Ge,void 0);L(this,ae,void 0);L(this,ye,void 0);L(this,Re,void 0);P(this,ae,void 0),P(this,Ge,t),this.setOptions(s),this.bindMethods(),K(this,Dt,js).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var n;const s=this.options;this.options=a(this,Ge).defaultMutationOptions(t),Rs(s,this.options)||a(this,Ge).getMutationCache().notify({type:"observerOptionsUpdated",mutation:a(this,ye),observer:this}),(n=a(this,ye))==null||n.setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=a(this,ye))==null||t.removeObserver(this)}onMutationUpdate(t){K(this,Dt,js).call(this),K(this,fs,bn).call(this,t)}getCurrentResult(){return a(this,ae)}reset(){P(this,ye,void 0),K(this,Dt,js).call(this),K(this,fs,bn).call(this)}mutate(t,s){var n;return P(this,Re,s),(n=a(this,ye))==null||n.removeObserver(this),P(this,ye,a(this,Ge).getMutationCache().build(a(this,Ge),this.options)),a(this,ye).addObserver(this),a(this,ye).execute(t)}},Ge=new WeakMap,ae=new WeakMap,ye=new WeakMap,Re=new WeakMap,Dt=new WeakSet,js=function(){var s;const t=((s=a(this,ye))==null?void 0:s.state)??mi();P(this,ae,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},fs=new WeakSet,bn=function(t){se.batch(()=>{var s,n,r,o,i,u,d,c;a(this,Re)&&this.hasListeners()&&((t==null?void 0:t.type)==="success"?((n=(s=a(this,Re)).onSuccess)==null||n.call(s,t.data,a(this,ae).variables,a(this,ae).context),(o=(r=a(this,Re)).onSettled)==null||o.call(r,t.data,null,a(this,ae).variables,a(this,ae).context)):(t==null?void 0:t.type)==="error"&&((u=(i=a(this,Re)).onError)==null||u.call(i,t.error,a(this,ae).variables,a(this,ae).context),(c=(d=a(this,Re)).onSettled)==null||c.call(d,void 0,t.error,a(this,ae).variables,a(this,ae).context))),this.listeners.forEach(h=>{h(a(this,ae))})})},Gr),yi=re.createContext(void 0),Be=e=>{const t=re.useContext(yi);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},wl=({client:e,children:t})=>(re.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),re.createElement(yi.Provider,{value:e},t)),vi=re.createContext(!1),Sl=()=>re.useContext(vi);vi.Provider;function El(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var kl=re.createContext(El()),Al=()=>re.useContext(kl);function bi(e,t){return typeof e=="function"?e(...t):!!e}var Pl=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},Ol=e=>{re.useEffect(()=>{e.clearReset()},[e])},jl=({result:e,errorResetBoundary:t,throwOnError:s,query:n})=>e.isError&&!t.isReset()&&!e.isFetching&&bi(s,[e.error,n]),Cl=e=>{e.suspense&&typeof e.staleTime!="number"&&(e.staleTime=1e3)},_l=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,Bl=(e,t,s)=>t.fetchOptimistic(e).catch(()=>{s.clearReset()});function Il(e,t,s){if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Be(s),r=Sl(),o=Al(),i=n.defaultQueryOptions(e);i._optimisticResults=r?"isRestoring":"optimistic",Cl(i),Pl(i,o),Ol(o);const[u]=re.useState(()=>new t(n,i)),d=u.getOptimisticResult(i);if(re.useSyncExternalStore(re.useCallback(c=>{const h=r?()=>{}:u.subscribe(se.batchCalls(c));return u.updateResult(),h},[u,r]),()=>u.getCurrentResult(),()=>u.getCurrentResult()),re.useEffect(()=>{u.setOptions(i,{listeners:!1})},[i,u]),_l(i,d))throw Bl(i,u,o);if(jl({result:d,errorResetBoundary:o,throwOnError:i.throwOnError,query:u.getCurrentQuery()}))throw d.error;return i.notifyOnChangeProps?d:u.trackResult(d)}function gs(e,t){return Il(e,yl,t)}function Me(e,t){const s=Be(t),[n]=re.useState(()=>new xl(s,e));re.useEffect(()=>{n.setOptions(e)},[n,e]);const r=re.useSyncExternalStore(re.useCallback(i=>n.subscribe(se.batchCalls(i)),[n]),()=>n.getCurrentResult(),()=>n.getCurrentResult()),o=re.useCallback((i,u)=>{n.mutate(i,u).catch(Rl)},[n]);if(r.error&&bi(n.options.throwOnError,[r.error]))throw r.error;return{...r,mutate:o,mutateAsync:r.mutate}}function Rl(){}function de(){return Be().getQueryData(["apiBaseUrl"])||"/api/chaibuilder"}const $t=()=>{const{data:e,refetch:t}=gs({queryKey:["currentPage"],queryFn:()=>localStorage.getItem("currentPage")||""});return[e,s=>{s&&(localStorage.setItem("currentPage",s||""),t())}]},zs=()=>{const[e,t]=$t(),s=de();return gs({queryKey:["project"],queryFn:async()=>{const n=await fetch(`${s}/project`).then(r=>r.json());if(!e&&n){const r=localStorage.getItem("currentPage");t(r||(n==null?void 0:n.homepage))}return n}})},Qn=()=>{const e=de();return gs({queryKey:["pages"],queryFn:async()=>await fetch(`${e}/pages`).then(s=>s.json())||[]})},Dl=()=>{const[e,t]=$t(),{data:s}=zs(),n=de();return gs({queryKey:["page_data",e],queryFn:async()=>{const r=await fetch(`${n}/page?uuid=${e}`);return r.ok?r.json():(t(s.homepage),null)},enabled:!!e,staleTime:3e3})},xn=()=>_.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-gray-200",children:_.jsxRuntimeExports.jsxs("div",{className:"flex flex-col h-full w-full justify-center items-center",children:[_.jsxRuntimeExports.jsxs("div",{className:"flex flex-row gap-2",children:[_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-orange-600 animate-bounce [animation-delay:.6s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-blue-600 animate-bounce [animation-delay:.4s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-green-600 animate-bounce [animation-delay:.2s]"}),_.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-yellow-600 animate-bounce [animation-delay:.0s]"})]}),_.jsxRuntimeExports.jsx("div",{className:"text-gray-700 font-thin",children:"Loading Builder..."})]})}),xi=(e="Project updated successfully.")=>{const t=Be(),s=de();return Me({mutationFn:async n=>await fetch(`${s}/project`,{method:"PUT",body:JSON.stringify(n)}),onSuccess:()=>{t.invalidateQueries({queryKey:["project"]}),_e.toast.success(e)}})},wi=()=>{const[e]=["SAVED"],[t,s]=$t(),n=Mn();return r=>e!=="SAVED"?(_e.toast.error("You have unsaved changes. Please save before changing the page."),!1):t===r.uuid?!1:(n(),setTimeout(()=>{s(r.uuid)},100),!0)},Ml=()=>{const e=Be(),t=wi(),s=de();return Me({mutationFn:async n=>fetch(`${s}/pages`,{method:"POST",body:JSON.stringify(n)}).then(r=>r.json()),onSuccess:n=>{e.invalidateQueries({queryKey:["pages"]}),t({uuid:n.uuid,slug:n.slug}),_e.toast.success("Page added successfully.")}})},Si=()=>{const e=de();return Me({mutationFn:async t=>fetch(`${e}/page`,{method:"PUT",body:JSON.stringify(t)}),onSuccess:()=>{_e.toast.success("Page saved successfully.")}})},Ll=()=>{const e=de(),{data:t}=Qn(),[s]=$t(),{data:n}=zs();return Me({mutationFn:async()=>{const r=t.find(o=>o.uuid===s).slug;await fetch(`${e}/publish`,{method:"POST",body:JSON.stringify({slug:r,uuid:s,isHomepage:(n==null?void 0:n.homepage)===s})})},onSuccess:()=>{_e.toast.success("Page published successfully.",{position:"top-right",duration:2e3})}})},Nl=()=>{const e=Be(),t=de();return Me({mutationFn:async s=>fetch(`${t}/page`,{method:"DELETE",body:JSON.stringify(s)}),onSuccess:()=>{_e.toast.success("Page deleted successfully."),e.invalidateQueries({queryKey:["pages"]})}})},Tl=()=>{const e=de();return Me({mutationFn:async()=>{const t=await fetch(`${e}/library`).then(s=>s.json());return l.sortBy(l.filter(t,s=>!l.has(s,"hidden")),"group")}})},Ul=()=>{const e=de();return Me({mutationFn:async t=>{if(!t||!t.uuid)return[];try{const s=await fetch(`${e}/block?uuid=${t.uuid}&format=${t.format}`).then(async n=>t.format==="html"?le.getBlocksFromHTML(await n.text()):await n.json());debugger;return l.set(s,"0._name",l.capitalize(t.group)),s||[]}catch{return[]}}})},Fl=()=>{const e=de();return Me({mutationFn:async t=>{const s=new FormData;return s.append("file",t),(await(await fetch(`${e}/upload`,{method:"POST",body:s})).json()).url}})},ql=B.lazy(()=>Promise.resolve().then(()=>require("./PagesPanel-dfbcc68b.cjs"))),$l=B.lazy(()=>Promise.resolve().then(()=>require("./ProjectPanel-4be28a35.cjs"))),Vl=B.lazy(()=>Promise.resolve().then(()=>require("./CurrentPage-77baf305.cjs"))),Ql=()=>_.jsxRuntimeExports.jsx("h2",{children:"Your Logo"}),Kl=()=>{const e=Be();return _.jsxRuntimeExports.jsx("div",{className:"border-gray-200 rounded-md p-2 mb-2 border",children:_.jsxRuntimeExports.jsx(_i.LogOutIcon,{className:"w-4 h-4 text-red-500",onClick:()=>{localStorage.removeItem("__anon_token"),e.invalidateQueries({queryKey:["verify"]})}})})},zl=()=>{const{mutate:e}=Ll();return _.jsxRuntimeExports.jsx(be.Button,{onClick:e,className:"bg-blue-600 text-white",children:"Publish"})},Hl=e=>{const{data:t,isLoading:s}=zs(),{data:n,isLoading:r}=Qn(),{data:o}=Dl(),{mutate:i}=xi(),{mutate:u}=Si(),[d]=$t(),c=Fl(),h=Tl(),m=Ul(),k=de(),v=B.useCallback(async R=>await c.mutateAsync(R),[c]),C=B.useCallback(async()=>await h.mutateAsync(),[h]),I=B.useCallback(async R=>await m.mutateAsync(R),[m]),b=async(R=20,M=0)=>{const w=`limit=${R}&offset=${M}`;return await fetch(`${k}/assets?${w}`).then(A=>A.json())},{logo:O=Ql}=e;return s||!t?_.jsxRuntimeExports.jsx(xn,{}):r||!n?_.jsxRuntimeExports.jsx(xn,{}):_.jsxRuntimeExports.jsx("div",{className:"bg-background text-foreground",children:_.jsxRuntimeExports.jsx(ui,{blocks:(o==null?void 0:o.blocks)||[],brandingOptions:t.brandingOptions,darkMode:e.darkMode||!1,onSaveBlocks:async({blocks:R})=>{u({blocks:R,uuid:d})},onSaveBrandingOptions:async R=>{i({brandingOptions:R})},topBarComponents:{left:[O],center:[Vl],right:[zl]},sideBarComponents:{top:[{icon:Cs.FileTextIcon,name:"pages",panel:ql},{icon:Cs.GearIcon,name:"settings",panel:$l}],bottom:[Kl]},uploadMediaCallback:v,fetchMediaCallback:b,getUILibraryBlocks:C,getExternalPredefinedBlock:I,getPages:()=>n,unsplashAccessKey:e.unsplashAccessKey||""})})},Gl=()=>{const e=de(),t=Be();return Me({mutationFn:async s=>{const n=await fetch(`${e}/authenticate`,{method:"POST",body:JSON.stringify(s)});if(n.ok)return await n.json();throw new Error("INvalid")},onSuccess:s=>{if(!s.token){_e.toast.error("Something went wrong. Please try again.");return}localStorage.setItem("__anon_token",s.token),t.invalidateQueries({queryKey:["verify"]}),_e.toast.success("Authenticated successfully.")},onError:()=>{_e.toast.error("Incorrect password. Please try again.")}})},Wl=()=>{const e=de();return gs({queryKey:["verify"],queryFn:async()=>{const t=localStorage.getItem("__anon_token");if(!t)return{valid:!1};const s=await fetch(`${e}/verify?token=`+t,{method:"GET"});return s.ok?(await s.json()).result==="success"?{valid:!0}:(localStorage.removeItem("__anon_token"),{valid:!1}):(localStorage.removeItem("__anon_token"),{valid:!0})}})},Jl=({logo:e})=>{const[t,s]=B.useState(!1),[n,r]=B.useState(""),{mutate:o,isPending:i}=Gl(),u=()=>{o({password:n})};return _.jsxRuntimeExports.jsx("section",{className:"h-screen w-screen flex items-center justify-center bg-[radial-gradient(#AAA,transparent_0.5px)] duration-300 [background-size:6px_6px]",children:_.jsxRuntimeExports.jsx("div",{className:"overflow-hidden bg-white rounded-xl w-96 drop-shadow-2xl duration-300",children:_.jsxRuntimeExports.jsxs("div",{className:"p-12",children:[_.jsxRuntimeExports.jsxs("div",{className:"max-w-2xl mx-auto text-center",children:[_.jsxRuntimeExports.jsx(B.Suspense,{children:e?B.createElement(e):""}),_.jsxRuntimeExports.jsx("p",{className:"max-w-xl mx-auto text-base leading-relaxed text-gray-700 font-thin",children:"Enter your app password to continue"})]}),_.jsxRuntimeExports.jsx("div",{className:"mt-8",children:_.jsxRuntimeExports.jsxs("div",{className:"space-y-5",children:[_.jsxRuntimeExports.jsx("div",{children:_.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[_.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:_.jsxRuntimeExports.jsx("svg",{className:"w-5 h-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:_.jsxRuntimeExports.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4"})})}),_.jsxRuntimeExports.jsx("input",{value:n,onChange:d=>r(d.target.value),type:t?"text":"password",id:"pwd",placeholder:"Enter password",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"}),_.jsxRuntimeExports.jsx("button",{className:"absolute inset-y-0 right-4 flex items-center pl-3 cursor-pointer",onClick:()=>s(!t),children:t?_.jsxRuntimeExports.jsx(Cs.EyeClosedIcon,{}):_.jsxRuntimeExports.jsx(Cs.EyeOpenIcon,{})})]})}),_.jsxRuntimeExports.jsx("div",{children:_.jsxRuntimeExports.jsx("button",{disabled:i||l.isEmpty(n)||n.length<3,onClick:u,type:"button",className:"inline-flex disabled:bg-gray-400 items-center justify-center w-full px-4 py-4 text-base font-semibold text-white transition-all duration-200 bg-blue-600 border border-transparent rounded-md focus:outline-none hover:bg-blue-700 focus:bg-blue-700",children:i?"Authenticating...":"Authenticate"})})]})})]})})})},Yl=e=>{const{data:t,isLoading:s}=Wl(),n=Be();return B.useEffect(()=>{n.setQueryData(["apiBaseUrl"],e.apiBaseUrl||"/api/chaibuilder")},[e.apiBaseUrl,n]),s?_.jsxRuntimeExports.jsx(xn,{}):t!=null&&t.valid?_.jsxRuntimeExports.jsx(Hl,{...e}):_.jsxRuntimeExports.jsx(Jl,{logo:e.logo})},Xl=new gl,Zl=e=>_.jsxRuntimeExports.jsxs(wl,{client:Xl,children:[_.jsxRuntimeExports.jsx(_e.Toaster,{richColors:!0}),_.jsxRuntimeExports.jsx(Yl,{...e})]});exports.ChaiBuilderEditor=ui;exports.ChaiBuilderStudio=Zl;exports.ErrorBoundary=Yr;exports.activePanelAtom=ko;exports.addBlockOffCanvasAtom=Ao;exports.addBlocksModalAtom=no;exports.advanceStylingOpenAtom=xo;exports.canDeleteBlock=va;exports.canDropBlock=xa;exports.canDuplicateBlock=ya;exports.canvasIframeAtom=Eo;exports.editLayerNameAtom=So;exports.getBlockJSONFromSchemas=nn;exports.getBlockJSONFromUISchemas=sn;exports.inlineEditingActiveAtom=bo;exports.networkModeAtom=wo;exports.showPredefinedBlockCategoryAtom=Po;exports.useActiveLanguage=Fo;exports.useActiveModal=mu;exports.useActivePanel=bu;exports.useAddBlock=Oa;exports.useAddBlockParent=xu;exports.useAddClassesToBlocks=Ia;exports.useAddPage=Ml;exports.useAllBlocks=co;exports.useBlockContentByLanguage=Ru;exports.useBrandingOptions=jn;exports.useBuilderReset=Mn;exports.useBuildingBlocks=fo;exports.useCanvasHistory=ps;exports.useCanvasWidth=Ka;exports.useCanvasZoom=Ha;exports.useChangePage=wi;exports.useCopyBlockIds=Bo;exports.useCurrentPage=$t;exports.useCurrentPage$1=ho;exports.useCutBlockIds=In;exports.useDarkMode=Ga;exports.useDeletePage=Nl;exports.useDeveloperPreviewMode=Ja;exports.useDuplicateBlocks=Dn;exports.useExpandedIds=Tu;exports.useFeatureSupport=Au;exports.useGetPageData=Bn;exports.useHiddenBlockIds=Xa;exports.useHighlightBlockId=Ro;exports.useLanguages=Iu;exports.useMarkAsGlobalBlock=eu;exports.useMoveBlocks=tu;exports.usePages=Qn;exports.usePasteBlocks=Do;exports.usePreviewMode=On;exports.usePrimaryLanguage=Bu;exports.useProject=zs;exports.useProject$1=ru;exports.useQueryClient=Be;exports.useReadOnlyMode=gu;exports.useRemoveBlocks=Lo;exports.useRemoveClassesFromBlocks=iu;exports.useSavePage=Qa;exports.useSelectedBlock=ka;exports.useSelectedBlockAllClasses=au;exports.useSelectedBlockCurrentClasses=lu;exports.useSelectedBlockIds=Je;exports.useSelectedBlocksDisplayChild=Ea;exports.useSelectedBreakpoints=Su;exports.useSelectedStylingBlocks=Pn;exports.useSetAllBlocks=ro;exports.useStylingBreakpoint=Oo;exports.useStylingState=du;exports.useTranslations=ku;exports.useTreeData=ga;exports.useUILibraryBlocks=Ou;exports.useUpdateBlocksProps=fu;exports.useUpdateBlocksPropsRealtime=hu;exports.useUpdatePage=Si;exports.useUpdateProject=xi;