@qratilabs/qrati-connect 2.23.0-beta.25 → 2.23.0-beta.27

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.
@@ -81,7 +81,7 @@ return a("div",{className:o("relative h-4",h?"mb-3":"mb-0"),children:[
81
81
  /* @__PURE__ */a("path",{d:"M858.8214,579.15067,856.55622,595.913a11.0384,11.0384,0,0,1-14.52733,8.96062h0a11.03839,11.03839,0,0,1-5.6969-16.408l7.03407-10.94188,21.96289-82.97095,2.44032-56.94084,21.9629,1.62688-3.25376,65.07525Z",transform:"translate(-130.9042 -69.48176)",fill:"#ffb9b9"}),
82
82
  /* @__PURE__ */a("path",{d:"M892.57918,449.81361c-10.91641-4.69632-22.65976-4.46625-34.97794-.81344l8.1344-31.31748a13.42176,13.42176,0,0,1,13.42176-13.42175h0a13.42175,13.42175,0,0,1,13.42175,13.42175Z",transform:"translate(-130.9042 -69.48176)",fill:"#2f2e41"})]}),Gt=r(({parameter:t,selected:e,onChange:n,showValues:r=!0})=>{const i=s(t=>{e!==t&&n?.(t)},[e,n]);/* @__PURE__ */
83
83
  return a("div",{className:"mb-8 flex w-full flex-col gap-2 lg:mb-12 lg:gap-4",children:[/* @__PURE__ */a(b,{variant:"h4",className:"text-primary-light text-center font-semibold md:text-left",children:t.name}),/* @__PURE__ */a("div",{className:"grid w-full grid-cols-5 gap-1 lg:gap-2",children:(t.tooltips||[]).map(n=>{const s=`${t._id}-option-${n.value}`;/* @__PURE__ */
84
- return a("div",{children:[/* @__PURE__ */a("button",{type:"button",className:o("border-primary shadow-outer flex size-full min-h-12 items-center justify-center rounded border transition-all duration-100 active:scale-90",e===n.value?"bg-primary":"bg-background"),onClick:()=>i(n.value),children:[t.mode===m.TEXT&&/* @__PURE__ */a("div",{className:o("p-1 text-center text-xs font-semibold md:p-2 md:text-base",e===n.value?"text-primary-foreground":"text-foreground"),children:n.label}),t.mode===m.IMAGE&&/* @__PURE__ */a("img",{className:"h-12 w-auto rounded object-contain lg:h-16",src:n.imageUrl,alt:n.label||t.name||String(n.value),loading:"lazy"}),t.mode===m.LOTTIE&&n.imageUrl&&/* @__PURE__ */a(Nt,{className:"h-12 w-auto rounded object-contain lg:h-16",src:n.imageUrl,autoplay:!0,loop:!0})]}),r&&/* @__PURE__ */a("div",{className:"mt-1 w-full text-center",children:/* @__PURE__ */a("span",{className:"text-foreground inline-flex items-center px-2 py-[0.0625] text-xs font-medium md:px-3 md:py-0.5",children:n.value})})]},s)})})]})});Gt.displayName="RatingRadioButton";var Zt,jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,a=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=a.next()).done;)s.push(r.value)}catch(o){i={error:o}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return s};function Kt(t,e,n,r,i,a,s,o,l,_,d){var c,h,u,m;if(0!==s)if(s!==n-e+(a-i)){for(var p=n-e,g=a-i,f=Math.floor(g/2),v={},w=-s-1;w<=s+1;++w)v[w]={d:1/0,segments:0,direct:Zt.none};for(var b=((c={})[-s-1]={d:1/0,segments:0,direct:Zt.none},c[s+1]={d:1/0,segments:0,direct:Zt.none},c),y=0;y<=f;++y){h=jt([b,v],2),v=h[0],b=h[1];var L=function(n){var a=y+n;if(0===y&&0===a)return v[n]={d:0,segments:0,direct:o},"continue";var s=[{direct:Zt.horizontal,d:v[n-1].d+1,segments:v[n-1].segments+(v[n-1].direct&Zt.horizontal?0:1)},{direct:Zt.vertical,d:b[n+1].d+1,segments:b[n+1].segments+(b[n+1].direct&Zt.vertical?0:1)}];a>0&&a<=p&&y>0&&y<=g&&_(t[e+a-1],r[i+y-1])&&s.push({direct:Zt.diagonal,d:b[n].d,segments:b[n].segments+(b[n].direct&Zt.diagonal?0:1)});var l=s.reduce(function(t,e){return t.d>e.d||t.d===e.d&&t.segments>e.segments?e:t});s.forEach(function(t){l.d===t.d&&l.segments===t.segments&&(l.direct|=t.direct)}),v[n]=l};for(w=-s;w<=s;++w)L(w)}var M={};for(w=-s-1;w<=s+1;++w)M[w]={d:1/0,segments:0,direct:Zt.none};var C=((u={})[-s-1]={d:1/0,segments:0,direct:Zt.none},u[s+1]={d:1/0,segments:0,direct:Zt.none},u);for(y=g;y>=f;--y){m=jt([C,M],2),M=m[0],C=m[1];var I=function(n){var a=y+n;if(y===g&&a===p)return M[n]={d:0,segments:0,direct:l},"continue";var s=[{direct:Zt.horizontal,d:M[n+1].d+1,segments:M[n+1].segments+(M[n+1].direct&Zt.horizontal?0:1)},{direct:Zt.vertical,d:C[n-1].d+1,segments:C[n-1].segments+(C[n-1].direct&Zt.vertical?0:1)}];a>=0&&a<p&&y>=0&&y<g&&_(t[e+a],r[i+y])&&s.push({direct:Zt.diagonal,d:C[n].d,segments:C[n].segments+(C[n].direct&Zt.diagonal?0:1)});var o=s.reduce(function(t,e){return t.d>e.d||t.d===e.d&&t.segments>e.segments?e:t});s.forEach(function(t){o.d===t.d&&o.segments===t.segments&&(o.direct|=t.direct)}),M[n]=o};for(w=s;w>=-s;--w)I(w)}var S={k:-1,d:1/0,segments:0,direct:Zt.none};for(w=-s;w<=s;++w){var x=v[w].d+M[w].d;if(x<S.d)S.k=w,S.d=x,S.segments=v[w].segments+M[w].segments+(v[w].segments&M[w].segments?0:1),S.direct=M[w].direct;else if(x===S.d){var A=v[w].segments+M[w].segments+(v[w].segments&M[w].segments?0:1);(A<S.segments||A===S.segments&&!(S.direct&Zt.diagonal)&&M[w].direct&Zt.diagonal)&&(S.k=w,S.d=x,S.segments=A,S.direct=M[w].direct)}}f+S.k===0&&0===f&&(f++,v[S.k].direct=M[S.k].direct,M[S.k].direct=C[S.k].direct),Kt(t,e,e+f+S.k,r,i,i+f,v[S.k].d,o,M[S.k].direct,_,d),Kt(t,e+f+S.k,n,r,i+f,a,M[S.k].d,v[S.k].direct,l,_,d)}else(o&Zt.horizontal?1:0)+(l&Zt.vertical?1:0)>=(o&Zt.vertical?1:0)+(l&Zt.horizontal?1:0)?(e!==n&&d("remove",t,e,n,r,i,i),i!==a&&d("add",t,n,n,r,i,a)):(i!==a&&d("add",t,e,e,r,i,a),e!==n&&d("remove",t,e,n,r,a,a));else d("same",t,e,n,r,i,a)}function Jt(t,e,n,r){var i=function(t,e,n){for(var r=t.length,i=e.length,a=r+i,s={1:0},o=0;o<=a;++o)for(var l=-o;l<=o;l+=2){for(var _=void 0,d=(_=l===-o||l!==o&&s[l-1]+1<s[l+1]?s[l+1]:s[l-1]+1)-l;_<r&&d<i&&n(t[_],e[d]);)_++,d++;if(_===r&&d===i)return o;s[l]=_}return-1}(t,e,n);Kt(t,0,t.length,e,0,e.length,i,Zt.diagonal,Zt.all,n,r)}!function(t){t[t.none=0]="none",t[t.horizontal=1]="horizontal",t[t.vertical=2]="vertical",t[t.diagonal=4]="diagonal",t[t.all=7]="all"}(Zt||(Zt={}));var Qt=t=>{if(!t)return"";if("string"==typeof t)return t;if("number"==typeof t)return String(t);if("object"==typeof t&&null!==t&&"_id"in t)return Qt(t._id);if("object"==typeof t&&null!==t&&"id"in t)return Qt(t.id);if("object"==typeof t&&null!==t&&"$oid"in t)return Qt(t.$oid);if("function"==typeof t.toHexString)return t.toHexString();if("function"==typeof t.toString){const e=t.toString();return"[object Object]"===e?"":e}return""},Vt=()=>{const r=f(),{eventSlug:o,contentId:m}=g(),z=l(),U=z.props?.organizationId,q=z.props?.loginUrl,{t:B}=x(),H=z.user,W=z.loadingUser,G=z.organization,Z=G?.advancedSettings?.imageSearchProviders?.curate??k,[j,K]=n(!1),[J,Q]=n(null),[V,Y]=n([]),[X,$]=n({upload:0,curate:0}),[tt,et]=n({}),[nt,rt]=n(null),[it,at]=n(!1),[st,ot]=n(!0),[lt,_t]=n(null),{loading:dt,event:ct,parameters:ht}=A({eventSlug:o}),ut=i(()=>Qt(H?._id)||Qt(H?.id)||Qt(H?.userId),[H?._id,H?.id,H?.userId]),mt=s(t=>{const e=Qt(t?.userId);return Boolean(ut)&&Boolean(e)&&e===ut},[ut]),pt=s(t=>t?mt(t)||t.ratingStatus===d.OWN?"Sorry, you cannot rate your own photo!":t.ratingStatus===d.CURATED?"Sorry, you have already rated this content.":null:null,[mt]),gt=e(!1);t(()=>()=>{gt.current=!0},[]);const ft=s(async t=>{gt.current=!1,K(!0);try{const e=H?.token?{Authorization:`Bearer ${H.token}`}:{},[n,r]=await Promise.all([_.get(h.CONTENT_FOR_CURATION,{headers:{"x-org-id":U,...e},searchParams:{eventId:t,page:1,limit:10}}).json(),_.get(h.GET_EVENT_POINTS,{headers:{"x-org-id":U,...e},searchParams:{eventId:t}}).json()]),i=n,a=r;if(i.error)throw new Error(i.error);if(a.error)throw new Error(a.error);if(gt.current)return;const s=m?i.data.filter(t=>t._id!==m):i.data.filter(t=>!mt(t));let o=s,l=null;if(m){const t=await _.get(h.ELIGIBLE_TO_CURATE,{headers:{"x-org-id":U,...e},searchParams:{contentId:m}}).json();if(t.error)throw new Error(t.error);const n=t.data;o=n?[n,...s||[]]:s||[],l=pt(n)}if(gt.current)return;$(a.data??{}),Y(o),Q(l)}catch(e){if(gt.current)return;const t=e instanceof Error?e.message:"Failed to fetch contents";S.error(t)}gt.current||K(!1)},[H,U,ct?._id,pt,m,mt]);t(()=>{ct?._id&&ut&&ft(ct._id)},[ct?._id,ut,ft]);const vt=V.length>0?V[0]:null;t(()=>{const t=pt(vt);Q(t)},[vt,ut]);const wt=async()=>{const t=ht??[];if(Object.keys(tt).length<t.length)_t("please select your ratings");else{_t(null),at(!0);try{const e=await _.post(h.CURATE_CONTENT,{headers:{"x-org-id":U,...H?.token?{Authorization:`Bearer ${H.token}`}:{}},json:{eventId:ct?._id,contentId:vt?._id,parameterCount:t.length,userRatings:t.map(t=>({parameterId:t._id,weight:t.weight,rate:tt[t._id]})),inappropriate:""}}).json();if(gt.current)return;if(e.error)_t(e.error);else{const n=e.data,r=n?.crowdRatings||{},i={parameters:t.map(t=>({name:t.name??"",crowdRating:r[t._id]??0,userRating:n?.ratings?.find(e=>e.parameterId===t._id)?.rate??0})),similarity:n?.similarity||null,points:n?.points||0,rateCount:n?.rateCount||0};rt(i),$(t=>({...t,curate:(t.curate??0)+(ct?.activityScores?.curate??0)}))}}catch(e){if(gt.current)return;_t(B("error.submit_rating","Failed to submit rating"))}finally{gt.current||at(!1)}}},bt=s(()=>ot(!0),[]),yt=s(()=>ot(!1),[]),Lt=s(()=>ot(!1),[]),Mt=s((t,e)=>{et(n=>({...n,[t]:e}))},[]),Ct=s(()=>{const t=V.slice(1);Q(null),rt(null),et({}),3===t.length?(async t=>{if(!gt.current)try{const e=await _.get(h.CONTENT_FOR_CURATION,{headers:{"x-org-id":U,...H?.token?{Authorization:`Bearer ${H.token}`}:{}},searchParams:{eventId:ct?._id,page:1,limit:10}}).json();if(gt.current)return;if(e.error)throw new Error(e.error);if((e?.data?.length??0)>0){const n=function(t,e,n){void 0===n&&(n=function(t,e){return t===e});var r={removed:[],added:[]};return Jt(t,e,n,function(t,e,n,i,a,s,o){if("add"===t)for(var l=s;l<o;++l)r.added.push(a[l]);else if("remove"===t)for(l=n;l<i;++l)r.removed.push(e[l])}),r}(t,e.data??[],(t,e)=>t._id===e._id),r=[...t,...n.added.filter(t=>!mt(t))];Y(r)}}catch(e){if(gt.current)return;const t=e instanceof Error?e.message:"Failed to fetch more contents";S.error(t)}})(t):Y(t),ot(!0)},[V]),It=e(wt);It.current=wt;const St=s(()=>{J?Ct():It.current()},[J,Ct]);if(W)/* @__PURE__ */return a(L,{className:"mx-auto h-6 w-64"});if(!H){if(G?.customAuth){if(q&&I(q)){try{window.top?.location?.assign(q)}catch{window.location.href=q}/* @__PURE__ */
84
+ return a("div",{children:[/* @__PURE__ */a("button",{type:"button",className:o("border-primary shadow-outer flex size-full min-h-12 items-center justify-center rounded border transition-all duration-100 active:scale-90",e===n.value?"bg-primary":"bg-background"),onClick:()=>i(n.value),children:[t.mode===m.TEXT&&/* @__PURE__ */a("div",{className:o("p-1 text-center text-xs font-semibold md:p-2 md:text-base",e===n.value?"text-primary-foreground":"text-foreground"),children:n.label}),t.mode===m.IMAGE&&/* @__PURE__ */a("img",{className:"h-12 w-auto rounded object-contain lg:h-16",src:n.imageUrl,alt:n.label||t.name||String(n.value),loading:"lazy"}),t.mode===m.LOTTIE&&n.imageUrl&&/* @__PURE__ */a(Nt,{className:"h-12 w-auto rounded object-contain lg:h-16",src:n.imageUrl,autoplay:!0,loop:!0})]}),r&&/* @__PURE__ */a("div",{className:"mt-1 w-full text-center",children:/* @__PURE__ */a("span",{className:"text-foreground inline-flex items-center px-2 py-[0.0625] text-xs font-medium md:px-3 md:py-0.5",children:n.value})})]},s)})})]})});Gt.displayName="RatingRadioButton";var Zt,jt=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,a=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=a.next()).done;)s.push(r.value)}catch(o){i={error:o}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return s};function Kt(t,e,n,r,i,a,s,o,l,_,d){var c,h,u,m;if(0!==s)if(s!==n-e+(a-i)){for(var p=n-e,g=a-i,f=Math.floor(g/2),v={},w=-s-1;w<=s+1;++w)v[w]={d:1/0,segments:0,direct:Zt.none};for(var b=((c={})[-s-1]={d:1/0,segments:0,direct:Zt.none},c[s+1]={d:1/0,segments:0,direct:Zt.none},c),y=0;y<=f;++y){h=jt([b,v],2),v=h[0],b=h[1];var L=function(n){var a=y+n;if(0===y&&0===a)return v[n]={d:0,segments:0,direct:o},"continue";var s=[{direct:Zt.horizontal,d:v[n-1].d+1,segments:v[n-1].segments+(v[n-1].direct&Zt.horizontal?0:1)},{direct:Zt.vertical,d:b[n+1].d+1,segments:b[n+1].segments+(b[n+1].direct&Zt.vertical?0:1)}];a>0&&a<=p&&y>0&&y<=g&&_(t[e+a-1],r[i+y-1])&&s.push({direct:Zt.diagonal,d:b[n].d,segments:b[n].segments+(b[n].direct&Zt.diagonal?0:1)});var l=s.reduce(function(t,e){return t.d>e.d||t.d===e.d&&t.segments>e.segments?e:t});s.forEach(function(t){l.d===t.d&&l.segments===t.segments&&(l.direct|=t.direct)}),v[n]=l};for(w=-s;w<=s;++w)L(w)}var M={};for(w=-s-1;w<=s+1;++w)M[w]={d:1/0,segments:0,direct:Zt.none};var C=((u={})[-s-1]={d:1/0,segments:0,direct:Zt.none},u[s+1]={d:1/0,segments:0,direct:Zt.none},u);for(y=g;y>=f;--y){m=jt([C,M],2),M=m[0],C=m[1];var I=function(n){var a=y+n;if(y===g&&a===p)return M[n]={d:0,segments:0,direct:l},"continue";var s=[{direct:Zt.horizontal,d:M[n+1].d+1,segments:M[n+1].segments+(M[n+1].direct&Zt.horizontal?0:1)},{direct:Zt.vertical,d:C[n-1].d+1,segments:C[n-1].segments+(C[n-1].direct&Zt.vertical?0:1)}];a>=0&&a<p&&y>=0&&y<g&&_(t[e+a],r[i+y])&&s.push({direct:Zt.diagonal,d:C[n].d,segments:C[n].segments+(C[n].direct&Zt.diagonal?0:1)});var o=s.reduce(function(t,e){return t.d>e.d||t.d===e.d&&t.segments>e.segments?e:t});s.forEach(function(t){o.d===t.d&&o.segments===t.segments&&(o.direct|=t.direct)}),M[n]=o};for(w=s;w>=-s;--w)I(w)}var S={k:-1,d:1/0,segments:0,direct:Zt.none};for(w=-s;w<=s;++w){var x=v[w].d+M[w].d;if(x<S.d)S.k=w,S.d=x,S.segments=v[w].segments+M[w].segments+(v[w].segments&M[w].segments?0:1),S.direct=M[w].direct;else if(x===S.d){var A=v[w].segments+M[w].segments+(v[w].segments&M[w].segments?0:1);(A<S.segments||A===S.segments&&!(S.direct&Zt.diagonal)&&M[w].direct&Zt.diagonal)&&(S.k=w,S.d=x,S.segments=A,S.direct=M[w].direct)}}f+S.k===0&&0===f&&(f++,v[S.k].direct=M[S.k].direct,M[S.k].direct=C[S.k].direct),Kt(t,e,e+f+S.k,r,i,i+f,v[S.k].d,o,M[S.k].direct,_,d),Kt(t,e+f+S.k,n,r,i+f,a,M[S.k].d,v[S.k].direct,l,_,d)}else(o&Zt.horizontal?1:0)+(l&Zt.vertical?1:0)>=(o&Zt.vertical?1:0)+(l&Zt.horizontal?1:0)?(e!==n&&d("remove",t,e,n,r,i,i),i!==a&&d("add",t,n,n,r,i,a)):(i!==a&&d("add",t,e,e,r,i,a),e!==n&&d("remove",t,e,n,r,a,a));else d("same",t,e,n,r,i,a)}function Jt(t,e,n,r){var i=function(t,e,n){for(var r=t.length,i=e.length,a=r+i,s={1:0},o=0;o<=a;++o)for(var l=-o;l<=o;l+=2){for(var _=void 0,d=(_=l===-o||l!==o&&s[l-1]+1<s[l+1]?s[l+1]:s[l-1]+1)-l;_<r&&d<i&&n(t[_],e[d]);)_++,d++;if(_===r&&d===i)return o;s[l]=_}return-1}(t,e,n);Kt(t,0,t.length,e,0,e.length,i,Zt.diagonal,Zt.all,n,r)}!function(t){t[t.none=0]="none",t[t.horizontal=1]="horizontal",t[t.vertical=2]="vertical",t[t.diagonal=4]="diagonal",t[t.all=7]="all"}(Zt||(Zt={}));var Qt=t=>{if(!t)return"";if("string"==typeof t)return t;if("number"==typeof t)return String(t);if("object"==typeof t&&null!==t&&"_id"in t)return Qt(t._id);if("object"==typeof t&&null!==t&&"id"in t)return Qt(t.id);if("object"==typeof t&&null!==t&&"$oid"in t)return Qt(t.$oid);if("function"==typeof t.toHexString)return t.toHexString();if("function"==typeof t.toString){const e=t.toString();return"[object Object]"===e?"":e}return""},Vt=()=>{const r=f(),{eventSlug:o,contentId:m}=g(),z=l(),U=z.props?.organizationId,q=z.props?.loginUrl,{t:B}=x(),H=z.user,W=z.loadingUser,G=z.organization,Z=G?.advancedSettings?.imageSearchProviders?.curate??k,[j,K]=n(!1),[J,Q]=n(null),[V,Y]=n([]),[X,$]=n({upload:0,curate:0}),[tt,et]=n({}),[nt,rt]=n(null),[it,at]=n(!1),[st,ot]=n(!0),[lt,_t]=n(null),{loading:dt,event:ct,parameters:ht}=A({eventSlug:o}),ut=i(()=>Qt(H?._id)||Qt(H?.id)||Qt(H?.userId),[H?._id,H?.id,H?.userId]),mt=s(t=>{const e=Qt(t?.userId);return Boolean(ut)&&Boolean(e)&&e===ut},[ut]),pt=s(t=>t?mt(t)||t.ratingStatus===d.OWN?"Sorry, you cannot rate your own photo!":t.ratingStatus===d.CURATED?"Sorry, you have already rated this content.":null:null,[mt]),gt=e(!1);t(()=>()=>{gt.current=!0},[]);const ft=s(async t=>{gt.current=!1,K(!0);try{const e=H?.token?{Authorization:`Bearer ${H.token}`}:{},[n,r]=await Promise.all([_.get(h.CONTENT_FOR_CURATION,{headers:{"x-org-id":U,...e},searchParams:{eventId:t,page:1,limit:10}}).json(),_.get(h.GET_EVENT_POINTS,{headers:{"x-org-id":U,...e},searchParams:{eventId:t}}).json()]),i=n,a=r;if(i.error)throw new Error(i.error);if(a.error)throw new Error(a.error);if(gt.current)return;const s=m?i.data.filter(t=>t._id!==m):i.data.filter(t=>!mt(t));let o=s,l=null;if(m){const t=await _.get(h.ELIGIBLE_TO_CURATE,{headers:{"x-org-id":U,...e},searchParams:{contentId:m}}).json();if(t.error)throw new Error(t.error);const n=t.data;o=n?[n,...s||[]]:s||[],l=pt(n)}if(gt.current)return;$(a.data??{}),Y(o),Q(l)}catch(e){if(gt.current)return;const t=e instanceof Error?e.message:"Failed to fetch contents";S.error(t)}gt.current||K(!1)},[H,U,ct?._id,pt,m,mt]);t(()=>{ct?._id&&ut&&ft(ct._id)},[ct?._id,ut,ft]);const vt=V.length>0?V[0]:null;t(()=>{const t=pt(vt);Q(t)},[vt,ut]);const wt=async()=>{const t=ht??[];if(Object.keys(tt).length<t.length)_t("please select your ratings");else{_t(null),at(!0);try{const e=await _.post(h.CURATE_CONTENT,{headers:{"x-org-id":U,...H?.token?{Authorization:`Bearer ${H.token}`}:{}},json:{eventId:ct?._id,contentId:vt?._id,parameterCount:t.length,userRatings:t.map(t=>({parameterId:t._id,rate:tt[t._id]})),inappropriate:""}}).json();if(gt.current)return;if(e.error)_t(e.error);else{const n=e.data,r=n?.crowdRatings||{},i={parameters:t.map(t=>({name:t.name??"",crowdRating:r[t._id]??0,userRating:n?.ratings?.find(e=>e.parameterId===t._id)?.rate??0})),similarity:n?.similarity||null,points:n?.points||0,rateCount:n?.rateCount||0};rt(i),$(t=>({...t,curate:(t.curate??0)+(ct?.activityScores?.curate??0)}))}}catch(e){if(gt.current)return;_t(B("error.submit_rating","Failed to submit rating"))}finally{gt.current||at(!1)}}},bt=s(()=>ot(!0),[]),yt=s(()=>ot(!1),[]),Lt=s(()=>ot(!1),[]),Mt=s((t,e)=>{et(n=>({...n,[t]:e}))},[]),Ct=s(()=>{const t=V.slice(1);Q(null),rt(null),et({}),3===t.length?(async t=>{if(!gt.current)try{const e=await _.get(h.CONTENT_FOR_CURATION,{headers:{"x-org-id":U,...H?.token?{Authorization:`Bearer ${H.token}`}:{}},searchParams:{eventId:ct?._id,page:1,limit:10}}).json();if(gt.current)return;if(e.error)throw new Error(e.error);if((e?.data?.length??0)>0){const n=function(t,e,n){void 0===n&&(n=function(t,e){return t===e});var r={removed:[],added:[]};return Jt(t,e,n,function(t,e,n,i,a,s,o){if("add"===t)for(var l=s;l<o;++l)r.added.push(a[l]);else if("remove"===t)for(l=n;l<i;++l)r.removed.push(e[l])}),r}(t,e.data??[],(t,e)=>t._id===e._id),r=[...t,...n.added.filter(t=>!mt(t))];Y(r)}}catch(e){if(gt.current)return;const t=e instanceof Error?e.message:"Failed to fetch more contents";S.error(t)}})(t):Y(t),ot(!0)},[V]),It=e(wt);It.current=wt;const St=s(()=>{J?Ct():It.current()},[J,Ct]);if(W)/* @__PURE__ */return a(L,{className:"mx-auto h-6 w-64"});if(!H){if(G?.customAuth){if(q&&I(q)){try{window.top?.location?.assign(q)}catch{window.location.href=q}/* @__PURE__ */
85
85
  return a(y,{title:"Redirecting to login..."})}/* @__PURE__ */
86
86
  return a(y,{title:"Please login to curate content"})}/* @__PURE__ */
87
87
  return a(w,{to:p.LOGIN,state:{referrer:r.pathname},replace:!0})}/* @__PURE__ */
@@ -11,7 +11,7 @@ return u(Y,{open:e,onOpenChange:e=>!e&&t(),children:/* @__PURE__ */u(W,{children
11
11
  return u("div",{className:"mx-auto mt-24 w-fit max-w-xl space-y-8",children:[
12
12
  /* @__PURE__ */u(M,{variant:"h3",align:"center",children:r("upload.event_closed","Upload Closed")}),
13
13
  /* @__PURE__ */u(M,{variant:"h5",align:"center",color:"muted",children:r("upload.closed_description","This event is no longer accepting uploads.")}),
14
- /* @__PURE__ */u("div",{className:"flex flex-row justify-end",children:/* @__PURE__ */u(_,{to:i,state:t,children:/* @__PURE__ */u(q,{children:r("button.back_to_events","Back to Events")})})})]})};function he(e,t){let r=0;const i=[],n=()=>{if(r>=e)return;const t=i.shift();t&&t()};return function(e){return new Promise((o,a)=>{i.push(()=>{r++;const i=()=>function(e){let t;return Promise.race([e.finally(()=>clearTimeout(t)),new Promise((e,r)=>{t=setTimeout(()=>r(/* @__PURE__ */new Error("media task timed out")),3e4)})])}(e()).then(o,a).finally(()=>{r--,n()});t?setTimeout(i,0):i()}),n()})}}var pe=he(2,!1),me=he(1,!0);function ge(e,t,r,i,n,o,a,s,l,d,c,u,h,p,m,g,f,v,b,y){return w=>{const{data:x,width:S,height:T}=w,C=new Uint8ClampedArray(x.length);for(let F=0;F<x.length;F+=4){const w=x[F],S=x[F+1],T=x[F+2],k=x[F+3];C[F]=Math.min(255,Math.max(0,Math.round(e*w+t*S+r*T+i*k+255*n))),C[F+1]=Math.min(255,Math.max(0,Math.round(o*w+a*S+s*T+l*k+255*d))),C[F+2]=Math.min(255,Math.max(0,Math.round(c*w+u*S+h*T+p*k+255*m))),C[F+3]=Math.min(255,Math.max(0,Math.round(g*w+f*S+v*T+b*k+255*y)))}return new ImageData(C,S,T)}}function fe(e,t,r,i){const n=Math.cos(i*Math.PI/180),o=Math.sin(i*Math.PI/180);return{r:(.299+.701*n+.168*o)*e,g:(.587-.587*n+.33*o)*t,b:(.114-.114*n-.497*o)*r}}function ve(e){let t=255,r=0,i=0;for(let n=1;n<e.length;n++){const o=e[n]-e[n-1];o>i&&(i=o,t=e[n],r=e[n-1])}return{low:r,high:t}}var be="\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec4 u_row0; uniform float u_off0;\nuniform vec4 u_row1; uniform float u_off1;\nuniform vec4 u_row2; uniform float u_off2;\nuniform vec4 u_row3; uniform float u_off3;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = clamp(vec4(\n dot(u_row0, c) + u_off0,\n dot(u_row1, c) + u_off1,\n dot(u_row2, c) + u_off2,\n dot(u_row3, c) + u_off3\n ), 0.0, 1.0);\n}".trim(),ye=[{id:"underwater-correction",name:"Underwater Color Correction",description:"Restores colors absorbed by water — boosts red channel via histogram normalization",category:"color-correction",analyze(e,t){const r=t.blue_boost??1,i=t.hue_shift??0,n=t.intensity??1,o=function(e,t,r,i=1,n=0){const o=t*r,a=o/2e3,s=/* @__PURE__ */new Int32Array(256),l=/* @__PURE__ */new Int32Array(256),d=/* @__PURE__ */new Int32Array(256);let c=0,u=0,h=0;for(let I=0;I<e.length;I+=4)c+=e[I],u+=e[I+1],h+=e[I+2];const p=c/o,m=u/o,g=h/o;let f=0,v=p;for(;v<60;){const e=fe(p,m,g,f);if(v=e.r+e.g+e.b,f++,f>120){v=60;break}}const b=f+n;for(let I=0;I<e.length;I+=4){const t=fe(e[I],e[I+1],e[I+2],b);s[Math.min(255,Math.max(0,Math.round(t.r+t.g+t.b)))]++,l[e[I+1]]++,d[e[I+2]]++}const y=[0],w=[0],x=[0];for(let I=0;I<256;I++)s[I]-a<2&&y.push(I),l[I]-a<2&&w.push(I),d[I]-a<2&&x.push(I);y.push(255),w.push(255),x.push(255);const S=ve(y),T=ve(w),C=ve(x),F=256/Math.max(1,S.high-S.low),k=256/Math.max(1,T.high-T.low),_=256/Math.max(1,C.high-C.low),E=-S.low/256*F,M=-T.low/256*k,U=-C.low/256*_,R=fe(1,1,1,b);return{rR:R.r*F,rG:R.g*F,rB:R.b*F,rA:0,rOff:E,gR:0,gG:k,gB:0,gA:0,gOff:M,bR:0,bG:0,bB:_*i,bA:0,bOff:U,aR:0,aG:0,aB:0,aA:1,aOff:0}}(e.data,e.width,e.height,r,i);return{u_row0:[1*(1-n)+o.rR*n,o.rG*n,o.rB*n,o.rA*n],u_off0:o.rOff*n,u_row1:[o.gR*n,1*(1-n)+o.gG*n,o.gB*n,o.gA*n],u_off1:o.gOff*n,u_row2:[o.bR*n,o.bG*n,1*(1-n)+o.bB*n,o.bA*n],u_off2:o.bOff*n,u_row3:[o.aR,o.aG,o.aB,o.aA],u_off3:o.aOff}},fragShader:be,buildCpuTransform(e){const t=e.u_row0,r=e.u_row1,i=e.u_row2,n=e.u_row3;return ge(t[0],t[1],t[2],t[3],e.u_off0,r[0],r[1],r[2],r[3],e.u_off1,i[0],i[1],i[2],i[3],e.u_off2,n[0],n[1],n[2],n[3],e.u_off3)},defaultVariables:{intensity:1,blue_boost:1,hue_shift:0},variableSchema:[{key:"intensity",type:"number",label:"Intensity",min:0,max:1,step:.05,default:1},{key:"blue_boost",type:"number",label:"Blue boost",min:.5,max:2,step:.05,default:1},{key:"hue_shift",type:"number",label:"Hue shift",min:-30,max:30,step:1,default:0}]},{id:"vignette",name:"Vignette Effect",description:"Darken image corners for dramatic effect",category:"stylistic",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_vignette_strength;\nuniform float u_vignette_radius;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec2 uv = v_texCoord * 2.0 - 1.0;\n float dist = length(uv);\n float factor = 1.0;\n if (dist > u_vignette_radius) {\n float falloff = max(0.001, 1.414 - u_vignette_radius);\n float t = (dist - u_vignette_radius) / falloff;\n factor = 1.0 - clamp(t * u_vignette_strength, 0.0, 0.8);\n }\n gl_FragColor = vec4(c.rgb * factor, c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_vignette_strength??.5,r=e.u_vignette_radius??.7,i=new Float32Array(4096);for(let n=0;n<64;n++)for(let e=0;e<64;e++){const o=e/63*2-1,a=n/63*2-1,s=Math.sqrt(o*o+a*a);let l=1;if(s>r){const e=Math.max(.001,1.414-r);l=1-Math.min(.8,(s-r)/e*t)}i[64*n+e]=l}return e=>{const{data:t,width:r,height:n}=e,o=new Uint8ClampedArray(t.length);for(let a=0;a<n;a++)for(let e=0;e<r;e++){const s=4*(a*r+e),l=Math.round(e/Math.max(1,r-1)*63),d=Math.round(a/Math.max(1,n-1)*63),c=i[64*Math.min(63,d)+Math.min(63,l)];o[s]=Math.round(t[s]*c),o[s+1]=Math.round(t[s+1]*c),o[s+2]=Math.round(t[s+2]*c),o[s+3]=t[s+3]}return new ImageData(o,r,n)}},defaultVariables:{vignette_strength:.5,vignette_radius:.7},variableSchema:[{key:"vignette_strength",type:"number",label:"Vignette strength",min:0,max:1,step:.05,default:.5},{key:"vignette_radius",type:"number",label:"Vignette radius",min:0,max:1,step:.05,default:.7}]},{id:"sepia",name:"Sepia Tone",description:"Apply warm sepia tone for vintage look",category:"stylistic",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_sepia_intensity;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n vec3 sepia = vec3(\n min(1.0, gray + 40.0 / 255.0),\n min(1.0, gray + 20.0 / 255.0),\n max(0.0, gray - 30.0 / 255.0)\n );\n gl_FragColor = vec4(mix(c.rgb, sepia, u_sepia_intensity), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_sepia_intensity??.8;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4){const e=r[a],i=r[a+1],n=r[a+2],s=.299*e+.587*i+.114*n,l=Math.min(255,s+40),d=Math.min(255,s+20),c=Math.max(0,s-30);o[a]=Math.round(e*(1-t)+l*t),o[a+1]=Math.round(i*(1-t)+d*t),o[a+2]=Math.round(n*(1-t)+c*t),o[a+3]=r[a+3]}return new ImageData(o,i,n)}},defaultVariables:{sepia_intensity:.8},variableSchema:[{key:"sepia_intensity",type:"number",label:"Sepia intensity",min:0,max:1,step:.05,default:.8}]},{id:"auto-white-balance",name:"Auto White Balance",description:"Grey-world white balance — equalises channel averages from image analysis",category:"color-correction",analyze(e){const t=e.data,r=e.width*e.height;let i=0,n=0,o=0;for(let c=0;c<t.length;c+=4)i+=t[c],n+=t[c+1],o+=t[c+2];const a=i/r,s=n/r,l=o/r,d=(a+s+l)/3;return{u_gain_r:d/Math.max(1,a),u_gain_g:d/Math.max(1,s),u_gain_b:d/Math.max(1,l)}},fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_gain_r;\nuniform float u_gain_g;\nuniform float u_gain_b;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = vec4(\n clamp(c.r * u_gain_r, 0.0, 1.0),\n clamp(c.g * u_gain_g, 0.0, 1.0),\n clamp(c.b * u_gain_b, 0.0, 1.0),\n c.a\n );\n}".trim(),buildCpuTransform:e=>ge(e.u_gain_r??1,0,0,0,0,0,e.u_gain_g??1,0,0,0,0,0,e.u_gain_b??1,0,0,0,0,0,1,0),defaultVariables:{},variableSchema:[]},{id:"grayscale",name:"Black & White",description:"Convert image to grayscale using luminance weights",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n gl_FragColor = vec4(vec3(gray), c.a);\n}".trim(),buildCpuTransform:()=>e=>{const{data:t,width:r,height:i}=e,n=new Uint8ClampedArray(t.length);for(let o=0;o<t.length;o+=4){const e=.299*t[o]+.587*t[o+1]+.114*t[o+2];n[o]=n[o+1]=n[o+2]=Math.round(e),n[o+3]=t[o+3]}return new ImageData(n,r,i)},defaultVariables:{},variableSchema:[]},{id:"invert",name:"Invert Colors",description:"Invert all color channels for a negative effect",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = vec4(1.0 - c.rgb, c.a);\n}".trim(),buildCpuTransform:()=>e=>{const{data:t,width:r,height:i}=e,n=new Uint8ClampedArray(t.length);for(let o=0;o<t.length;o+=4)n[o]=255-t[o],n[o+1]=255-t[o+1],n[o+2]=255-t[o+2],n[o+3]=t[o+3];return new ImageData(n,r,i)},defaultVariables:{},variableSchema:[]},{id:"brightness-contrast",name:"Brightness & Contrast",description:"Adjust overall brightness and contrast",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_brightness;\nuniform float u_contrast;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 col = c.rgb + u_brightness;\n col = (col - 0.5) * u_contrast + 0.5;\n gl_FragColor = vec4(clamp(col, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_brightness??0,r=e.u_contrast??1;return e=>{const{data:i,width:n,height:o}=e,a=new Uint8ClampedArray(i.length);for(let s=0;s<i.length;s+=4){for(let e=0;e<3;e++){let n=i[s+e]/255+t;n=(n-.5)*r+.5,a[s+e]=Math.min(255,Math.max(0,Math.round(255*n)))}a[s+3]=i[s+3]}return new ImageData(a,n,o)}},defaultVariables:{brightness:0,contrast:1},variableSchema:[{key:"brightness",type:"number",label:"Brightness",min:-.5,max:.5,step:.05,default:0},{key:"contrast",type:"number",label:"Contrast",min:0,max:2,step:.05,default:1}]},{id:"saturation",name:"Saturation",description:"Increase or decrease color saturation",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_saturation;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n gl_FragColor = vec4(mix(vec3(gray), c.rgb, u_saturation), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_saturation??1;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4){const e=r[a],i=r[a+1],n=r[a+2],s=.299*e+.587*i+.114*n;o[a]=Math.round(s+(e-s)*t),o[a+1]=Math.round(s+(i-s)*t),o[a+2]=Math.round(s+(n-s)*t),o[a+3]=r[a+3]}return new ImageData(o,i,n)}},defaultVariables:{saturation:1.2},variableSchema:[{key:"saturation",type:"number",label:"Saturation",min:0,max:2,step:.05,default:1.2}]},{id:"hue-rotate",name:"Hue Shift",description:"Rotate the hue of all colors",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_hue_shift;\nvarying vec2 v_texCoord;\n\nvec3 hueShift(vec3 color, float hue) {\n vec3 k = vec3(0.57735, 0.57735, 0.57735);\n float cosAngle = cos(hue);\n float sinAngle = sin(hue);\n return color * cosAngle + cross(k, color) * sinAngle + k * dot(k, color) * (1.0 - cosAngle);\n}\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float rad = u_hue_shift * 3.14159265 / 180.0;\n gl_FragColor = vec4(hueShift(c.rgb, rad), c.a);\n}".trim(),buildCpuTransform(e){const t=(e.u_hue_shift??0)*Math.PI/180,r=Math.cos(t),i=Math.sin(t),n=1/Math.sqrt(3);return e=>{const{data:t,width:o,height:a}=e,s=new Uint8ClampedArray(t.length);for(let l=0;l<t.length;l+=4){const e=t[l]/255,o=t[l+1]/255,a=t[l+2]/255,d=n*(e+o+a),c=e*r+n*(a-o)*i+n*d*(1-r),u=o*r+n*(e-a)*i+n*d*(1-r),h=a*r+n*(o-e)*i+n*d*(1-r);s[l]=Math.min(255,Math.max(0,Math.round(255*c))),s[l+1]=Math.min(255,Math.max(0,Math.round(255*u))),s[l+2]=Math.min(255,Math.max(0,Math.round(255*h))),s[l+3]=t[l+3]}return new ImageData(s,o,a)}},defaultVariables:{hue_shift:30},variableSchema:[{key:"hue_shift",type:"number",label:"Hue shift",min:0,max:360,step:5,default:30}]},{id:"gaussian-blur",name:"Soft Blur",description:"Apply a gentle Gaussian-like blur",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_blur_radius;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = u_blur_radius / u_resolution;\n vec4 sum = texture2D(u_image, v_texCoord) * 0.25;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, 0.0)) * 0.125;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, 0.0)) * 0.125;\n sum += texture2D(u_image, v_texCoord + vec2(0.0, off.y)) * 0.125;\n sum += texture2D(u_image, v_texCoord - vec2(0.0, off.y)) * 0.125;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, -off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, -off.y)) * 0.0625;\n gl_FragColor = sum;\n}".trim(),buildCpuTransform(e){const t=Math.max(1,Math.round(e.u_blur_radius??2)),r=[[0,0],[t,0],[-t,0],[0,t],[0,-t],[t,t],[-t,-t],[t,-t],[-t,t]],i=[.25,.125,.125,.125,.125,.0625,.0625,.0625,.0625];return e=>{const{data:t,width:n,height:o}=e,a=new Uint8ClampedArray(t.length);for(let s=0;s<o;s++)for(let e=0;e<n;e++){let l=0,d=0,c=0,u=0;for(let a=0;a<9;a++){const h=Math.min(n-1,Math.max(0,e+r[a][0])),p=4*(Math.min(o-1,Math.max(0,s+r[a][1]))*n+h),m=i[a];l+=t[p]*m,d+=t[p+1]*m,c+=t[p+2]*m,u+=t[p+3]*m}const h=4*(s*n+e);a[h]=Math.round(l),a[h+1]=Math.round(d),a[h+2]=Math.round(c),a[h+3]=Math.round(u)}return new ImageData(a,n,o)}},defaultVariables:{blur_radius:2},variableSchema:[{key:"blur_radius",type:"number",label:"Blur radius",min:0,max:8,step:.5,default:2}]},{id:"sharpen",name:"Sharpen",description:"Enhance edge detail for a crisper look",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_sharpen_amount;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = 1.0 / u_resolution;\n vec4 c = texture2D(u_image, v_texCoord);\n vec4 left = texture2D(u_image, v_texCoord + vec2(-off.x, 0.0));\n vec4 right = texture2D(u_image, v_texCoord + vec2(off.x, 0.0));\n vec4 up = texture2D(u_image, v_texCoord + vec2(0.0, off.y));\n vec4 down = texture2D(u_image, v_texCoord + vec2(0.0, -off.y));\n vec4 edge = left + right + up + down - 4.0 * c;\n gl_FragColor = vec4(clamp(c.rgb - edge.rgb * u_sharpen_amount, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_sharpen_amount??.8;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length),a=(e,t,o)=>r[4*(Math.min(n-1,Math.max(0,e))*i+Math.min(i-1,Math.max(0,t)))+o];for(let s=0;s<n;s++)for(let e=0;e<i;e++){const n=4*(s*i+e);for(let i=0;i<3;i++){const l=r[n+i],d=a(s,e-1,i)+a(s,e+1,i)+a(s+1,e,i)+a(s-1,e,i)-4*l;o[n+i]=Math.min(255,Math.max(0,Math.round(l-d*t)))}o[n+3]=r[n+3]}return new ImageData(o,i,n)}},defaultVariables:{sharpen_amount:.8},variableSchema:[{key:"sharpen_amount",type:"number",label:"Sharpen amount",min:0,max:3,step:.1,default:.8}]},{id:"edge-detect",name:"Edge Detect",description:"Highlight edges using gradient detection",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_edge_intensity;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = 1.0 / u_resolution;\n vec4 c = texture2D(u_image, v_texCoord);\n vec4 left = texture2D(u_image, v_texCoord + vec2(-off.x, 0.0));\n vec4 right = texture2D(u_image, v_texCoord + vec2(off.x, 0.0));\n vec4 up = texture2D(u_image, v_texCoord + vec2(0.0, off.y));\n vec4 down = texture2D(u_image, v_texCoord + vec2(0.0, -off.y));\n vec3 edge = abs(left.rgb - right.rgb) + abs(up.rgb - down.rgb);\n float gray = dot(edge, vec3(0.299, 0.587, 0.114));\n vec3 result = mix(c.rgb, vec3(gray), u_edge_intensity);\n gl_FragColor = vec4(result, c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_edge_intensity??1;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length),a=(e,t,o)=>r[4*(Math.min(n-1,Math.max(0,e))*i+Math.min(i-1,Math.max(0,t)))+o]/255;for(let s=0;s<n;s++)for(let e=0;e<i;e++){const n=4*(s*i+e),l=.299*(Math.abs(a(s,e-1,0)-a(s,e+1,0))+Math.abs(a(s+1,e,0)-a(s-1,e,0)))+.587*(Math.abs(a(s,e-1,1)-a(s,e+1,1))+Math.abs(a(s+1,e,1)-a(s-1,e,1)))+.114*(Math.abs(a(s,e-1,2)-a(s,e+1,2))+Math.abs(a(s+1,e,2)-a(s-1,e,2)));for(let e=0;e<3;e++){const i=r[n+e]/255;o[n+e]=Math.min(255,Math.max(0,Math.round(255*(i*(1-t)+l*t))))}o[n+3]=r[n+3]}return new ImageData(o,i,n)}},defaultVariables:{edge_intensity:1},variableSchema:[{key:"edge_intensity",type:"number",label:"Edge intensity",min:0,max:1,step:.05,default:1}]},{id:"warm-tone",name:"Warm Tone",description:"Add warm orange-yellow tones",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_warmth;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 warm = c.rgb + vec3(0.08, 0.03, -0.05) * u_warmth;\n gl_FragColor = vec4(clamp(warm, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_warmth??.5;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4)o[a]=Math.min(255,Math.max(0,Math.round(r[a]+20.4*t))),o[a+1]=Math.min(255,Math.max(0,Math.round(r[a+1]+7.65*t))),o[a+2]=Math.min(255,Math.max(0,Math.round(r[a+2]-12.75*t))),o[a+3]=r[a+3];return new ImageData(o,i,n)}},defaultVariables:{warmth:.5},variableSchema:[{key:"warmth",type:"number",label:"Warmth",min:0,max:1,step:.05,default:.5}]},{id:"cool-tone",name:"Cool Tone",description:"Add cool blue-cyan tones",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_coolness;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 cool = c.rgb + vec3(-0.05, 0.02, 0.08) * u_coolness;\n gl_FragColor = vec4(clamp(cool, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_coolness??.5;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4)o[a]=Math.min(255,Math.max(0,Math.round(r[a]-12.75*t))),o[a+1]=Math.min(255,Math.max(0,Math.round(r[a+1]+5.1*t))),o[a+2]=Math.min(255,Math.max(0,Math.round(r[a+2]+20.4*t))),o[a+3]=r[a+3];return new ImageData(o,i,n)}},defaultVariables:{coolness:.5},variableSchema:[{key:"coolness",type:"number",label:"Coolness",min:0,max:1,step:.05,default:.5}]},{id:"custom-script",name:"Custom Shader",description:"Write a custom GLSL fragment shader",category:"custom",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\nvoid main() {\n // Your custom shader here.\n // Example — invert colours:\n // vec4 c = texture2D(u_image, v_texCoord);\n // gl_FragColor = vec4(1.0 - c.rgb, c.a);\n gl_FragColor = texture2D(u_image, v_texCoord);\n}".trim(),defaultVariables:{},variableSchema:[]}];function we(e){return ye.find(t=>t.id===e)}function xe(e,t){if(e){if("number"===e.type){if("number"!=typeof t||!Number.isFinite(t))return;const r=e.min??-1/0,i=e.max??1/0;return Math.min(i,Math.max(r,t))}return"boolean"===e.type?"boolean"==typeof t?t:void 0:"string"==typeof t?t:void 0}}var Se="\nattribute vec2 a_position;\nvarying vec2 v_texCoord;\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_position * 0.5 + 0.5;\n}".trim(),Te=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),Ce=null,Fe=null,ke=null;function _e(e,t,r){const i=e.createShader(t);if(!i)return null;if(e.shaderSource(i,r),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const r=e.getShaderInfoLog(i);return console.warn("[webgl-filter] shader error:",r),v(/* @__PURE__ */new Error(`WebGL shader compilation failed: ${r}`),{component:"webgl-filter-engine",tags:["upload","filter","webgl","shader"],extra:{shaderType:t===e.VERTEX_SHADER?"vertex":"fragment"}}),e.deleteShader(i),null}return i}function Ee(e,t){const r=_e(e,e.VERTEX_SHADER,Se),i=_e(e,e.FRAGMENT_SHADER,t);if(!r||!i)return e.deleteShader(r),e.deleteShader(i),null;const n=e.createProgram();if(e.attachShader(n,r),e.attachShader(n,i),e.linkProgram(n),e.deleteShader(r),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n);return console.warn("[webgl-filter] link error:",r),v(/* @__PURE__ */new Error(`WebGL program link failed: ${r}`),{component:"webgl-filter-engine",tags:["upload","filter","webgl","link"],extra:{fragmentLength:t.length}}),e.deleteProgram(n),null}return n}function Me(e){const t=e.createTexture();return e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),t}function Ue(e,t,r){const i=Me(e);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null);const n=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.bindFramebuffer(e.FRAMEBUFFER,null),{fbo:n,tex:i}}function Re(e,t,r){for(const[i,n]of Object.entries(r)){const r=e.getUniformLocation(t,i);if(r)if("number"!=typeof n)switch(n.length){case 2:e.uniform2fv(r,n);break;case 3:e.uniform3fv(r,n);break;case 4:e.uniform4fv(r,n)}else e.uniform1f(r,n)}}function Ie(e){const t=e.config,r=t?.templateId,i=t?.fragShader;if(r){const e=we(r);return{def:e??null,fragShader:e?.fragShader??null}}return i?{def:null,fragShader:i}:{def:null,fragShader:null}}function Ne(e){const t=e.config?.variables??{},r={};for(const[i,n]of Object.entries(t))"number"==typeof n&&(r[`u_${i}`]=n);return r}async function Oe(e,t,r,i="image/webp",n=.85){const o=Date.now(),a=t.filter(e=>e.enabled);if(!a.length)return{blob:e,appliedFilters:[],width:0,height:0,processingTime:0};const s=await createImageBitmap(e);let l=s.width,d=s.height;if(l>r||d>r){const e=Math.min(r/l,r/d);l=Math.round(l*e),d=Math.round(d*e)}const c=Math.min(150,l),u=Math.max(1,Math.round(c*d/l)),h=new OffscreenCanvas(c,u).getContext("2d");h.drawImage(s,0,0,c,u);const p=h.getImageData(0,0,c,u);let m;if(s.width!==l||s.height!==d){const e=new OffscreenCanvas(l,d);e.getContext("2d").drawImage(s,0,0,l,d),s.close(),m=await createImageBitmap(e,{imageOrientation:"flipY"})}else m=await createImageBitmap(s,{imageOrientation:"flipY"}),s.close();const g=Ce??new OffscreenCanvas(l,d);g.width===l&&g.height===d||(g.width=l,g.height=d),Ce=g;let f=Fe;if(f||(f=g.getContext("webgl",{preserveDrawingBuffer:!0,alpha:!0})||g.getContext("experimental-webgl",{preserveDrawingBuffer:!0,alpha:!0}),Fe=f),!f||f.isContextLost())return m.close(),Fe=null,Ce=null,async function(e,t,r,i,n,o,a="image/webp",s=.85){const l=new OffscreenCanvas(r,i),d=l.getContext("2d"),c=await createImageBitmap(e);d.drawImage(c,0,0,r,i),c.close();const u=[];for(const h of t){const{def:e}=Ie(h);if(!e?.buildCpuTransform)continue;const t=e.analyze?e.analyze(n,h.config?.variables??{}):{},o={},a=h.config?.variables??{};for(const[r,i]of Object.entries(a))"number"==typeof i&&(o[`u_${r}`]=i);const s=e.buildCpuTransform({...t,...o},r,i),l=d.getImageData(0,0,r,i);d.putImageData(s(l),0,0),u.push(h.id)}return u.length?{blob:await l.convertToBlob({type:a,quality:s}),appliedFilters:u,width:r,height:i,processingTime:Date.now()-o}:{blob:e,appliedFilters:[],width:r,height:i,processingTime:Date.now()-o}}(e,a,l,d,p,o,i,n);const v=Me(f);f.bindTexture(f.TEXTURE_2D,v),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,m),m.close(),f.viewport(0,0,l,d);const b=[Ue(f,l,d),Ue(f,l,d)],y=f.createBuffer();f.bindBuffer(f.ARRAY_BUFFER,y),f.bufferData(f.ARRAY_BUFFER,Te,f.STATIC_DRAW);const w=ke??/* @__PURE__ */new Map;ke=w;const x=[];let S=v,T=0;try{for(let e=0;e<a.length;e++){const t=a[e],r=e===a.length-1,{def:i,fragShader:n}=Ie(t);if(!n)continue;const o=t.config?.templateId??n;w.has(o)||w.set(o,Ee(f,n));const s=w.get(o);if(!s)continue;f.useProgram(s);const c=f.getAttribLocation(s,"a_position");f.bindBuffer(f.ARRAY_BUFFER,y),f.enableVertexAttribArray(c),f.vertexAttribPointer(c,2,f.FLOAT,!1,0,0),f.activeTexture(f.TEXTURE0),f.bindTexture(f.TEXTURE_2D,S),f.uniform1i(f.getUniformLocation(s,"u_image"),0);const u=f.getUniformLocation(s,"u_resolution");if(u&&f.uniform2f(u,l,d),Re(f,s,Ne(t)),i?.analyze&&Re(f,s,i.analyze(p,t.config?.variables??{})),r)f.bindFramebuffer(f.FRAMEBUFFER,null),f.drawArrays(f.TRIANGLES,0,6);else{const e=b[T];f.bindFramebuffer(f.FRAMEBUFFER,e.fbo),f.drawArrays(f.TRIANGLES,0,6),S=e.tex,T=1-T}x.push(t.id)}return x.length?{blob:await g.convertToBlob({type:i,quality:n}),appliedFilters:x,width:l,height:d,processingTime:Date.now()-o}:{blob:e,appliedFilters:[],width:l,height:d,processingTime:Date.now()-o}}finally{for(const{fbo:e,tex:t}of b)f.deleteFramebuffer(e),f.deleteTexture(t);f.deleteTexture(v),f.deleteBuffer(y)}}async function Pe(e,t,r,i){const n=Date.now(),o=e.filter(e=>e.enabled),a=e=>e;if(!o.length)return{transform:a,appliedFilters:[],processingTime:0};let s=null;try{const e=await createImageBitmap(t),r=Math.min(64,e.width),i=Math.round(r*e.height/e.width),n=new OffscreenCanvas(r,Math.max(1,i)).getContext("2d");n.drawImage(e,0,0,r,Math.max(1,i)),e.close(),s=n.getImageData(0,0,r,Math.max(1,i))}catch{}const l=[],d=[];for(const u of o){const{def:e}=Ie(u);if(!e?.buildCpuTransform)continue;const t=u.config?.variables??{},n=e.analyze&&s?e.analyze(s,t):{},o={};for(const[r,i]of Object.entries(t))"number"==typeof i&&(o[`u_${r}`]=i);try{const t=e.buildCpuTransform({...n,...o},r,i);l.push(t),d.push(u.id)}catch(c){console.warn(`[webgl-filter] buildCpuTransform failed for ${u.id}:`,c),v(c instanceof Error?c:/* @__PURE__ */new Error(`buildCpuTransform failed for ${u.id}`),{component:"webgl-filter-engine",tags:["upload","filter","cpu-transform"],extra:{filterId:u.id}})}}return l.length?{transform:1===l.length?l[0]:e=>l.reduce((e,t)=>t(e),e),appliedFilters:d,processingTime:Date.now()-n}:{transform:a,appliedFilters:[],processingTime:Date.now()-n}}var qe=800;async function Ae(e){return new Promise((t,r)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=()=>r(/* @__PURE__ */new Error("FileReader failed")),i.readAsDataURL(e)})}async function De(e,t){const r=Date.now(),i=t.filter(e=>e.enabled),n=await L(e);let o,a;const s=await createImageBitmap(n,{resizeWidth:qe});if(o=s.width,a=s.height,a>qe){const e=qe/a;o=Math.round(o*e),a=qe}const l=new OffscreenCanvas(o,a);l.getContext("2d").drawImage(s,0,0,o,a),s.close();const d=await l.convertToBlob({type:"image/jpeg",quality:.92}),c=await Ae(d);if(!i.length)return{original:c,processed:c,appliedFilters:[],failedFilters:[],totalExecutionTime:Date.now()-r};let u=c;const h=[],p=[];try{const e=await Oe(d,i,qe,"image/jpeg",.92);e.appliedFilters.length>0&&(u=await Ae(e.blob),h.push(...e.appliedFilters));for(const t of i)e.appliedFilters.includes(t.id)||p.push({id:t.id,error:"Filter not applied"})}catch(m){for(const e of i)p.push({id:e.id,error:m instanceof Error?m.message:"Unknown error"});v(m instanceof Error?m:/* @__PURE__ */new Error("Filter preview failed"),{component:"client-filter-engine",tags:["upload","filter-preview","webgl"],extra:{filterCount:i.length,failedFilters:p.map(e=>e.id)}})}return{original:c,processed:u,appliedFilters:h,failedFilters:p,totalExecutionTime:Date.now()-r}}var Le=/* @__PURE__ */new Map;function je(e,t,r,i){return`${e}:${JSON.stringify(t)}:${r}x${i}`}function ze(e){const t=Le.get(e);return t&&(Le.delete(e),Le.set(e,t)),t}function $e(e,t){if(Le.delete(e),Le.set(e,t),Le.size>3){const e=Le.keys().next().value;void 0!==e&&Le.delete(e)}}var Be=e=>{let t;const r=/* @__PURE__ */new Set,i=(e,i)=>{const n="function"==typeof e?e(t):e;if(!Object.is(n,t)){const e=t;t=(null!=i?i:"object"!=typeof n||null===n)?n:Object.assign({},t,n),r.forEach(r=>r(t,e))}},n=()=>t,o={setState:i,getState:n,getInitialState:()=>a,subscribe:e=>(r.add(e),()=>r.delete(e))},a=t=e(i,n,o);return o},He=e=>e;var Ve=r(null);function We({children:e,...t}){const r=a(null),i=a(t);return r.current&&t.eventId===i.current.eventId&&t.groupId===i.current.groupId||(r.current=function(e){return(t=t=>({eventId:e.eventId,groupId:e.groupId,selectedFiles:[],originalFiles:{},captions:{},hasStarted:!1,oversizedUids:{},showOversizedModal:!1,trimRanges:{},cropSelections:{},videoMuted:!0,uploadStates:{},uploadSpeedBps:0,showRestoreDialog:!1,restoredUids:[],activeFilters:[],showFilterChoice:!1,skipUploadFilters:!1,perFileFilterSkipped:{},filteredThumbs:{},filterOverrides:{},setSelectedFiles:e=>t(t=>({selectedFiles:"function"==typeof e?e(t.selectedFiles):e})),addOriginalFiles:e=>t(t=>({originalFiles:{...t.originalFiles,...e}})),removeFile:e=>t(t=>{if(!t.selectedFiles.some(t=>t.uid===e))return t;const r={...t.captions};delete r[e];const i={...t.oversizedUids};delete i[e];const n={...t.trimRanges};delete n[e];const o={...t.originalFiles};delete o[e];const a={...t.cropSelections};delete a[e];const s={...t.uploadStates};t.hasStarted||delete s[e];const l={...t.filteredThumbs};delete l[e];const d={...t.perFileFilterSkipped};delete d[e];const c={...t.filterOverrides};return delete c[e],{selectedFiles:t.selectedFiles.filter(t=>t.uid!==e),captions:r,oversizedUids:i,trimRanges:n,originalFiles:o,cropSelections:a,uploadStates:s,filteredThumbs:l,perFileFilterSkipped:d,filterOverrides:c}}),setCaption:(e,r)=>t(t=>({captions:{...t.captions,[e]:r}})),setHasStarted:e=>t({hasStarted:e}),addOversizedUids:e=>t(t=>({oversizedUids:{...t.oversizedUids,...e}})),removeOversizedFiles:()=>t(e=>{const t=new Set(Object.keys(e.oversizedUids)),r={...e.captions},i={...e.trimRanges},n={...e.originalFiles},o={...e.cropSelections},a={...e.uploadStates},s={...e.filteredThumbs},l={...e.perFileFilterSkipped},d={...e.filterOverrides};return t.forEach(e=>{delete r[e],delete i[e],delete n[e],delete o[e],delete a[e],delete s[e],delete l[e],delete d[e]}),{selectedFiles:e.selectedFiles.filter(e=>!t.has(e.uid)),captions:r,trimRanges:i,originalFiles:n,cropSelections:o,uploadStates:a,filteredThumbs:s,perFileFilterSkipped:l,filterOverrides:d,oversizedUids:{},showOversizedModal:!1}}),setShowOversizedModal:e=>t({showOversizedModal:e}),replaceFile:(e,r,i)=>t(t=>{const n={...t.cropSelections};i&&(n[e]=i);const o={...t.filteredThumbs};return delete o[e],{selectedFiles:t.selectedFiles.map(t=>t.uid===e?{...t,file:r}:t),cropSelections:n,filteredThumbs:o}}),setTrimRange:(e,r)=>t(t=>({trimRanges:{...t.trimRanges,[e]:r}})),setVideoMuted:e=>t({videoMuted:e}),setUploadState:(e,r)=>t(t=>({uploadStates:{...t.uploadStates,[e]:{...t.uploadStates[e],...r}}})),setUploadSpeedBps:e=>t({uploadSpeedBps:e}),setActiveFilters:(e,r)=>t({activeFilters:e,showFilterChoice:r}),setSkipUploadFilters:e=>t({skipUploadFilters:e}),setFileFilterSkipped:(e,r)=>t(t=>({perFileFilterSkipped:{...t.perFileFilterSkipped,[e]:r}})),setFilterOverride:(e,r,i,n)=>t(t=>{const o={...t.filteredThumbs};return delete o[e],{filterOverrides:{...t.filterOverrides,[e]:{...t.filterOverrides[e],[r]:{...t.filterOverrides[e]?.[r],[i]:n}}},filteredThumbs:o}}),resetFilterOverrides:e=>t(t=>{const r={...t.filterOverrides};delete r[e];const i={...t.filteredThumbs};return delete i[e],{filterOverrides:r,filteredThumbs:i}}),setFilteredThumb:(e,r)=>t(t=>({filteredThumbs:{...t.filteredThumbs,[e]:r}})),resetUploader:()=>{Le.clear(),t({selectedFiles:[],originalFiles:{},captions:{},hasStarted:!1,oversizedUids:{},showOversizedModal:!1,trimRanges:{},cropSelections:{},uploadStates:{},uploadSpeedBps:0,skipUploadFilters:!1,perFileFilterSkipped:{},filteredThumbs:{},filterOverrides:{}})}}))?Be(t):Be;var t}(t),i.current=t),/* @__PURE__ */u(Ve.Provider,{value:r.current,children:e})}function Ge(e){const t=p(Ve);if(!t)throw new Error("useUploadStore must be used within UploadStoreProvider");return function(e,t=He){const r=n.useSyncExternalStore(e.subscribe,n.useCallback(()=>t(e.getState()),[e,t]),n.useCallback(()=>t(e.getInitialState()),[e,t]));return n.useDebugValue(r),r}(t,e)}function Xe(){const e=p(Ve);if(!e)throw new Error("useUploadStoreInstance must be used within UploadStoreProvider");return e}var Ye=/* @__PURE__ */new Map,Qe=null;function Ke({className:e}){/* @__PURE__ */
14
+ /* @__PURE__ */u("div",{className:"flex flex-row justify-end",children:/* @__PURE__ */u(_,{to:i,state:t,children:/* @__PURE__ */u(q,{children:r("button.back_to_events","Back to Events")})})})]})};function he(e,t){let r=0;const i=[],n=()=>{if(r>=e)return;const t=i.shift();t&&t()};return function(e){return new Promise((o,a)=>{i.push(()=>{r++;const i=()=>function(e){let t;return Promise.race([e.finally(()=>clearTimeout(t)),new Promise((e,r)=>{t=setTimeout(()=>r(/* @__PURE__ */new Error("media task timed out")),3e4)})])}(e()).then(o,a).finally(()=>{r--,n()});t?setTimeout(i,0):i()}),n()})}}var pe=he(2,!1),me=he(1,!0);function ge(e,t,r,i,n,o,a,s,l,d,c,u,h,p,m,g,f,v,b,y){return w=>{const{data:x,width:S,height:T}=w,C=new Uint8ClampedArray(x.length);for(let F=0;F<x.length;F+=4){const w=x[F],S=x[F+1],T=x[F+2],k=x[F+3];C[F]=Math.min(255,Math.max(0,Math.round(e*w+t*S+r*T+i*k+255*n))),C[F+1]=Math.min(255,Math.max(0,Math.round(o*w+a*S+s*T+l*k+255*d))),C[F+2]=Math.min(255,Math.max(0,Math.round(c*w+u*S+h*T+p*k+255*m))),C[F+3]=Math.min(255,Math.max(0,Math.round(g*w+f*S+v*T+b*k+255*y)))}return new ImageData(C,S,T)}}function fe(e,t,r,i){const n=Math.cos(i*Math.PI/180),o=Math.sin(i*Math.PI/180);return{r:(.299+.701*n+.168*o)*e,g:(.587-.587*n+.33*o)*t,b:(.114-.114*n-.497*o)*r}}function ve(e){let t=255,r=0,i=0;for(let n=1;n<e.length;n++){const o=e[n]-e[n-1];o>i&&(i=o,t=e[n],r=e[n-1])}return{low:r,high:t}}var be="\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec4 u_row0; uniform float u_off0;\nuniform vec4 u_row1; uniform float u_off1;\nuniform vec4 u_row2; uniform float u_off2;\nuniform vec4 u_row3; uniform float u_off3;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = clamp(vec4(\n dot(u_row0, c) + u_off0,\n dot(u_row1, c) + u_off1,\n dot(u_row2, c) + u_off2,\n dot(u_row3, c) + u_off3\n ), 0.0, 1.0);\n}".trim(),ye=[{id:"underwater-correction",name:"Underwater Color Correction",description:"Restores colors absorbed by water — boosts red channel via histogram normalization",category:"color-correction",analyze(e,t){const r=t.blue_boost??1,i=t.hue_shift??0,n=t.intensity??1,o=function(e,t,r,i=1,n=0){const o=t*r,a=o/2e3,s=/* @__PURE__ */new Int32Array(256),l=/* @__PURE__ */new Int32Array(256),d=/* @__PURE__ */new Int32Array(256);let c=0,u=0,h=0;for(let I=0;I<e.length;I+=4)c+=e[I],u+=e[I+1],h+=e[I+2];const p=c/o,m=u/o,g=h/o;let f=0,v=p;for(;v<60;){const e=fe(p,m,g,f);if(v=e.r+e.g+e.b,f++,f>120){v=60;break}}const b=f+n;for(let I=0;I<e.length;I+=4){const t=fe(e[I],e[I+1],e[I+2],b);s[Math.min(255,Math.max(0,Math.round(t.r+t.g+t.b)))]++,l[e[I+1]]++,d[e[I+2]]++}const y=[0],w=[0],x=[0];for(let I=0;I<256;I++)s[I]-a<2&&y.push(I),l[I]-a<2&&w.push(I),d[I]-a<2&&x.push(I);y.push(255),w.push(255),x.push(255);const S=ve(y),T=ve(w),C=ve(x),F=256/Math.max(1,S.high-S.low),k=256/Math.max(1,T.high-T.low),_=256/Math.max(1,C.high-C.low),E=-S.low/256*F,M=-T.low/256*k,U=-C.low/256*_,R=fe(1,1,1,b);return{rR:R.r*F,rG:R.g*F,rB:R.b*F,rA:0,rOff:E,gR:0,gG:k,gB:0,gA:0,gOff:M,bR:0,bG:0,bB:_*i,bA:0,bOff:U,aR:0,aG:0,aB:0,aA:1,aOff:0}}(e.data,e.width,e.height,r,i);return{u_row0:[1*(1-n)+o.rR*n,o.rG*n,o.rB*n,o.rA*n],u_off0:o.rOff*n,u_row1:[o.gR*n,1*(1-n)+o.gG*n,o.gB*n,o.gA*n],u_off1:o.gOff*n,u_row2:[o.bR*n,o.bG*n,1*(1-n)+o.bB*n,o.bA*n],u_off2:o.bOff*n,u_row3:[o.aR,o.aG,o.aB,o.aA],u_off3:o.aOff}},fragShader:be,buildCpuTransform(e){const t=e.u_row0,r=e.u_row1,i=e.u_row2,n=e.u_row3;return ge(t[0],t[1],t[2],t[3],e.u_off0,r[0],r[1],r[2],r[3],e.u_off1,i[0],i[1],i[2],i[3],e.u_off2,n[0],n[1],n[2],n[3],e.u_off3)},defaultVariables:{intensity:1,blue_boost:1,hue_shift:0},variableSchema:[{key:"intensity",type:"number",label:"Intensity",min:0,max:1,step:.05,default:1},{key:"blue_boost",type:"number",label:"Blue boost",min:.5,max:2,step:.05,default:1},{key:"hue_shift",type:"number",label:"Hue shift",min:-30,max:30,step:1,default:0}]},{id:"vignette",name:"Vignette Effect",description:"Darken image corners for dramatic effect",category:"stylistic",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_vignette_strength;\nuniform float u_vignette_radius;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec2 uv = v_texCoord * 2.0 - 1.0;\n float dist = length(uv);\n float factor = 1.0;\n if (dist > u_vignette_radius) {\n float falloff = max(0.001, 1.414 - u_vignette_radius);\n float t = (dist - u_vignette_radius) / falloff;\n factor = 1.0 - clamp(t * u_vignette_strength, 0.0, 0.8);\n }\n gl_FragColor = vec4(c.rgb * factor, c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_vignette_strength??.5,r=e.u_vignette_radius??.7,i=64,n=new Float32Array(4096);for(let a=0;a<i;a++)for(let e=0;e<i;e++){const o=e/63*2-1,s=a/63*2-1,l=Math.sqrt(o*o+s*s);let d=1;if(l>r){const e=Math.max(.001,1.414-r);d=1-Math.min(.8,(l-r)/e*t)}n[a*i+e]=d}const o=(e,t)=>{const r=Math.min(63,Math.floor(e)),o=Math.min(63,Math.floor(t)),a=Math.min(63,r+1),s=Math.min(63,o+1),l=Math.min(1,e-r),d=Math.min(1,t-o),c=n[o*i+r],u=n[o*i+a],h=n[s*i+r];return c+(u-c)*l+(h-c)*d+(c-u-h+n[s*i+a])*l*d};return e=>{const{data:t,width:r,height:i}=e,n=new Uint8ClampedArray(t.length),a=(e,t)=>e/Math.max(1,t-1)*63;for(let s=0;s<i;s++){const e=a(s,i);for(let i=0;i<r;i++){const l=4*(s*r+i),d=o(a(i,r),e);n[l]=Math.round(t[l]*d),n[l+1]=Math.round(t[l+1]*d),n[l+2]=Math.round(t[l+2]*d),n[l+3]=t[l+3]}}return new ImageData(n,r,i)}},defaultVariables:{vignette_strength:.5,vignette_radius:.7},variableSchema:[{key:"vignette_strength",type:"number",label:"Vignette strength",min:0,max:1,step:.05,default:.5},{key:"vignette_radius",type:"number",label:"Vignette radius",min:0,max:1,step:.05,default:.7}]},{id:"sepia",name:"Sepia Tone",description:"Apply warm sepia tone for vintage look",category:"stylistic",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_sepia_intensity;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n vec3 sepia = vec3(\n min(1.0, gray + 40.0 / 255.0),\n min(1.0, gray + 20.0 / 255.0),\n max(0.0, gray - 30.0 / 255.0)\n );\n gl_FragColor = vec4(mix(c.rgb, sepia, u_sepia_intensity), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_sepia_intensity??.8;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4){const e=r[a],i=r[a+1],n=r[a+2],s=.299*e+.587*i+.114*n,l=Math.min(255,s+40),d=Math.min(255,s+20),c=Math.max(0,s-30);o[a]=Math.round(e*(1-t)+l*t),o[a+1]=Math.round(i*(1-t)+d*t),o[a+2]=Math.round(n*(1-t)+c*t),o[a+3]=r[a+3]}return new ImageData(o,i,n)}},defaultVariables:{sepia_intensity:.8},variableSchema:[{key:"sepia_intensity",type:"number",label:"Sepia intensity",min:0,max:1,step:.05,default:.8}]},{id:"auto-white-balance",name:"Auto White Balance",description:"Grey-world white balance — equalises channel averages from image analysis",category:"color-correction",analyze(e){const t=e.data,r=e.width*e.height;let i=0,n=0,o=0;for(let c=0;c<t.length;c+=4)i+=t[c],n+=t[c+1],o+=t[c+2];const a=i/r,s=n/r,l=o/r,d=(a+s+l)/3;return{u_gain_r:d/Math.max(1,a),u_gain_g:d/Math.max(1,s),u_gain_b:d/Math.max(1,l)}},fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_gain_r;\nuniform float u_gain_g;\nuniform float u_gain_b;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = vec4(\n clamp(c.r * u_gain_r, 0.0, 1.0),\n clamp(c.g * u_gain_g, 0.0, 1.0),\n clamp(c.b * u_gain_b, 0.0, 1.0),\n c.a\n );\n}".trim(),buildCpuTransform:e=>ge(e.u_gain_r??1,0,0,0,0,0,e.u_gain_g??1,0,0,0,0,0,e.u_gain_b??1,0,0,0,0,0,1,0),defaultVariables:{},variableSchema:[]},{id:"grayscale",name:"Black & White",description:"Convert image to grayscale using luminance weights",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n gl_FragColor = vec4(vec3(gray), c.a);\n}".trim(),buildCpuTransform:()=>e=>{const{data:t,width:r,height:i}=e,n=new Uint8ClampedArray(t.length);for(let o=0;o<t.length;o+=4){const e=.299*t[o]+.587*t[o+1]+.114*t[o+2];n[o]=n[o+1]=n[o+2]=Math.round(e),n[o+3]=t[o+3]}return new ImageData(n,r,i)},defaultVariables:{},variableSchema:[]},{id:"invert",name:"Invert Colors",description:"Invert all color channels for a negative effect",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n gl_FragColor = vec4(1.0 - c.rgb, c.a);\n}".trim(),buildCpuTransform:()=>e=>{const{data:t,width:r,height:i}=e,n=new Uint8ClampedArray(t.length);for(let o=0;o<t.length;o+=4)n[o]=255-t[o],n[o+1]=255-t[o+1],n[o+2]=255-t[o+2],n[o+3]=t[o+3];return new ImageData(n,r,i)},defaultVariables:{},variableSchema:[]},{id:"brightness-contrast",name:"Brightness & Contrast",description:"Adjust overall brightness and contrast",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_brightness;\nuniform float u_contrast;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 col = c.rgb + u_brightness;\n col = (col - 0.5) * u_contrast + 0.5;\n gl_FragColor = vec4(clamp(col, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_brightness??0,r=e.u_contrast??1;return e=>{const{data:i,width:n,height:o}=e,a=new Uint8ClampedArray(i.length);for(let s=0;s<i.length;s+=4){for(let e=0;e<3;e++){let n=i[s+e]/255+t;n=(n-.5)*r+.5,a[s+e]=Math.min(255,Math.max(0,Math.round(255*n)))}a[s+3]=i[s+3]}return new ImageData(a,n,o)}},defaultVariables:{brightness:0,contrast:1},variableSchema:[{key:"brightness",type:"number",label:"Brightness",min:-.5,max:.5,step:.05,default:0},{key:"contrast",type:"number",label:"Contrast",min:0,max:2,step:.05,default:1}]},{id:"saturation",name:"Saturation",description:"Increase or decrease color saturation",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_saturation;\nvarying vec2 v_texCoord;\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float gray = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n gl_FragColor = vec4(mix(vec3(gray), c.rgb, u_saturation), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_saturation??1;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4){const e=r[a],i=r[a+1],n=r[a+2],s=.299*e+.587*i+.114*n;o[a]=Math.round(s+(e-s)*t),o[a+1]=Math.round(s+(i-s)*t),o[a+2]=Math.round(s+(n-s)*t),o[a+3]=r[a+3]}return new ImageData(o,i,n)}},defaultVariables:{saturation:1.2},variableSchema:[{key:"saturation",type:"number",label:"Saturation",min:0,max:2,step:.05,default:1.2}]},{id:"hue-rotate",name:"Hue Shift",description:"Rotate the hue of all colors",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_hue_shift;\nvarying vec2 v_texCoord;\n\nvec3 hueShift(vec3 color, float hue) {\n vec3 k = vec3(0.57735, 0.57735, 0.57735);\n float cosAngle = cos(hue);\n float sinAngle = sin(hue);\n return color * cosAngle + cross(k, color) * sinAngle + k * dot(k, color) * (1.0 - cosAngle);\n}\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n float rad = u_hue_shift * 3.14159265 / 180.0;\n gl_FragColor = vec4(hueShift(c.rgb, rad), c.a);\n}".trim(),buildCpuTransform(e){const t=(e.u_hue_shift??0)*Math.PI/180,r=Math.cos(t),i=Math.sin(t),n=1/Math.sqrt(3);return e=>{const{data:t,width:o,height:a}=e,s=new Uint8ClampedArray(t.length);for(let l=0;l<t.length;l+=4){const e=t[l]/255,o=t[l+1]/255,a=t[l+2]/255,d=n*(e+o+a),c=e*r+n*(a-o)*i+n*d*(1-r),u=o*r+n*(e-a)*i+n*d*(1-r),h=a*r+n*(o-e)*i+n*d*(1-r);s[l]=Math.min(255,Math.max(0,Math.round(255*c))),s[l+1]=Math.min(255,Math.max(0,Math.round(255*u))),s[l+2]=Math.min(255,Math.max(0,Math.round(255*h))),s[l+3]=t[l+3]}return new ImageData(s,o,a)}},defaultVariables:{hue_shift:30},variableSchema:[{key:"hue_shift",type:"number",label:"Hue shift",min:0,max:360,step:5,default:30}]},{id:"gaussian-blur",name:"Soft Blur",description:"Apply a gentle Gaussian-like blur",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_blur_radius;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = u_blur_radius / u_resolution;\n vec4 sum = texture2D(u_image, v_texCoord) * 0.25;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, 0.0)) * 0.125;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, 0.0)) * 0.125;\n sum += texture2D(u_image, v_texCoord + vec2(0.0, off.y)) * 0.125;\n sum += texture2D(u_image, v_texCoord - vec2(0.0, off.y)) * 0.125;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord + vec2(off.x, -off.y)) * 0.0625;\n sum += texture2D(u_image, v_texCoord - vec2(off.x, -off.y)) * 0.0625;\n gl_FragColor = sum;\n}".trim(),buildCpuTransform(e){const t=Math.max(1,Math.round(e.u_blur_radius??2)),r=[[0,0],[t,0],[-t,0],[0,t],[0,-t],[t,t],[-t,-t],[t,-t],[-t,t]],i=[.25,.125,.125,.125,.125,.0625,.0625,.0625,.0625];return e=>{const{data:t,width:n,height:o}=e,a=new Uint8ClampedArray(t.length);for(let s=0;s<o;s++)for(let e=0;e<n;e++){let l=0,d=0,c=0,u=0;for(let a=0;a<9;a++){const h=Math.min(n-1,Math.max(0,e+r[a][0])),p=4*(Math.min(o-1,Math.max(0,s+r[a][1]))*n+h),m=i[a];l+=t[p]*m,d+=t[p+1]*m,c+=t[p+2]*m,u+=t[p+3]*m}const h=4*(s*n+e);a[h]=Math.round(l),a[h+1]=Math.round(d),a[h+2]=Math.round(c),a[h+3]=Math.round(u)}return new ImageData(a,n,o)}},defaultVariables:{blur_radius:2},variableSchema:[{key:"blur_radius",type:"number",label:"Blur radius",min:0,max:8,step:.5,default:2}]},{id:"sharpen",name:"Sharpen",description:"Enhance edge detail for a crisper look",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_sharpen_amount;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = 1.0 / u_resolution;\n vec4 c = texture2D(u_image, v_texCoord);\n vec4 left = texture2D(u_image, v_texCoord + vec2(-off.x, 0.0));\n vec4 right = texture2D(u_image, v_texCoord + vec2(off.x, 0.0));\n vec4 up = texture2D(u_image, v_texCoord + vec2(0.0, off.y));\n vec4 down = texture2D(u_image, v_texCoord + vec2(0.0, -off.y));\n vec4 edge = left + right + up + down - 4.0 * c;\n gl_FragColor = vec4(clamp(c.rgb - edge.rgb * u_sharpen_amount, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_sharpen_amount??.8;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length),a=(e,t,o)=>r[4*(Math.min(n-1,Math.max(0,e))*i+Math.min(i-1,Math.max(0,t)))+o];for(let s=0;s<n;s++)for(let e=0;e<i;e++){const n=4*(s*i+e);for(let i=0;i<3;i++){const l=r[n+i],d=a(s,e-1,i)+a(s,e+1,i)+a(s+1,e,i)+a(s-1,e,i)-4*l;o[n+i]=Math.min(255,Math.max(0,Math.round(l-d*t)))}o[n+3]=r[n+3]}return new ImageData(o,i,n)}},defaultVariables:{sharpen_amount:.8},variableSchema:[{key:"sharpen_amount",type:"number",label:"Sharpen amount",min:0,max:3,step:.1,default:.8}]},{id:"edge-detect",name:"Edge Detect",description:"Highlight edges using gradient detection",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_edge_intensity;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec2 off = 1.0 / u_resolution;\n vec4 c = texture2D(u_image, v_texCoord);\n vec4 left = texture2D(u_image, v_texCoord + vec2(-off.x, 0.0));\n vec4 right = texture2D(u_image, v_texCoord + vec2(off.x, 0.0));\n vec4 up = texture2D(u_image, v_texCoord + vec2(0.0, off.y));\n vec4 down = texture2D(u_image, v_texCoord + vec2(0.0, -off.y));\n vec3 edge = abs(left.rgb - right.rgb) + abs(up.rgb - down.rgb);\n float gray = dot(edge, vec3(0.299, 0.587, 0.114));\n vec3 result = mix(c.rgb, vec3(gray), u_edge_intensity);\n gl_FragColor = vec4(result, c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_edge_intensity??1;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length),a=(e,t,o)=>r[4*(Math.min(n-1,Math.max(0,e))*i+Math.min(i-1,Math.max(0,t)))+o]/255;for(let s=0;s<n;s++)for(let e=0;e<i;e++){const n=4*(s*i+e),l=.299*(Math.abs(a(s,e-1,0)-a(s,e+1,0))+Math.abs(a(s+1,e,0)-a(s-1,e,0)))+.587*(Math.abs(a(s,e-1,1)-a(s,e+1,1))+Math.abs(a(s+1,e,1)-a(s-1,e,1)))+.114*(Math.abs(a(s,e-1,2)-a(s,e+1,2))+Math.abs(a(s+1,e,2)-a(s-1,e,2)));for(let e=0;e<3;e++){const i=r[n+e]/255;o[n+e]=Math.min(255,Math.max(0,Math.round(255*(i*(1-t)+l*t))))}o[n+3]=r[n+3]}return new ImageData(o,i,n)}},defaultVariables:{edge_intensity:1},variableSchema:[{key:"edge_intensity",type:"number",label:"Edge intensity",min:0,max:1,step:.05,default:1}]},{id:"warm-tone",name:"Warm Tone",description:"Add warm orange-yellow tones",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_warmth;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 warm = c.rgb + vec3(0.08, 0.03, -0.05) * u_warmth;\n gl_FragColor = vec4(clamp(warm, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_warmth??.5;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4)o[a]=Math.min(255,Math.max(0,Math.round(r[a]+20.4*t))),o[a+1]=Math.min(255,Math.max(0,Math.round(r[a+1]+7.65*t))),o[a+2]=Math.min(255,Math.max(0,Math.round(r[a+2]-12.75*t))),o[a+3]=r[a+3];return new ImageData(o,i,n)}},defaultVariables:{warmth:.5},variableSchema:[{key:"warmth",type:"number",label:"Warmth",min:0,max:1,step:.05,default:.5}]},{id:"cool-tone",name:"Cool Tone",description:"Add cool blue-cyan tones",category:"utility",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform float u_coolness;\nvarying vec2 v_texCoord;\n\nvoid main() {\n vec4 c = texture2D(u_image, v_texCoord);\n vec3 cool = c.rgb + vec3(-0.05, 0.02, 0.08) * u_coolness;\n gl_FragColor = vec4(clamp(cool, 0.0, 1.0), c.a);\n}".trim(),buildCpuTransform(e){const t=e.u_coolness??.5;return e=>{const{data:r,width:i,height:n}=e,o=new Uint8ClampedArray(r.length);for(let a=0;a<r.length;a+=4)o[a]=Math.min(255,Math.max(0,Math.round(r[a]-12.75*t))),o[a+1]=Math.min(255,Math.max(0,Math.round(r[a+1]+5.1*t))),o[a+2]=Math.min(255,Math.max(0,Math.round(r[a+2]+20.4*t))),o[a+3]=r[a+3];return new ImageData(o,i,n)}},defaultVariables:{coolness:.5},variableSchema:[{key:"coolness",type:"number",label:"Coolness",min:0,max:1,step:.05,default:.5}]},{id:"custom-script",name:"Custom Shader",description:"Write a custom GLSL fragment shader",category:"custom",fragShader:"\nprecision highp float;\nuniform sampler2D u_image;\nuniform vec2 u_resolution;\nvarying vec2 v_texCoord;\nvoid main() {\n // Your custom shader here.\n // Example — invert colours:\n // vec4 c = texture2D(u_image, v_texCoord);\n // gl_FragColor = vec4(1.0 - c.rgb, c.a);\n gl_FragColor = texture2D(u_image, v_texCoord);\n}".trim(),defaultVariables:{},variableSchema:[]}];function we(e){return ye.find(t=>t.id===e)}function xe(e,t){if(e){if("number"===e.type){if("number"!=typeof t||!Number.isFinite(t))return;const r=e.min??-1/0,i=e.max??1/0;return Math.min(i,Math.max(r,t))}return"boolean"===e.type?"boolean"==typeof t?t:void 0:"string"==typeof t?t:void 0}}var Se="\nattribute vec2 a_position;\nvarying vec2 v_texCoord;\nvoid main() {\n gl_Position = vec4(a_position, 0.0, 1.0);\n v_texCoord = a_position * 0.5 + 0.5;\n}".trim(),Te=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),Ce=null,Fe=null,ke=null;function _e(e,t,r){const i=e.createShader(t);if(!i)return null;if(e.shaderSource(i,r),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS)){const r=e.getShaderInfoLog(i);return console.warn("[webgl-filter] shader error:",r),v(/* @__PURE__ */new Error(`WebGL shader compilation failed: ${r}`),{component:"webgl-filter-engine",tags:["upload","filter","webgl","shader"],extra:{shaderType:t===e.VERTEX_SHADER?"vertex":"fragment"}}),e.deleteShader(i),null}return i}function Ee(e,t){const r=_e(e,e.VERTEX_SHADER,Se),i=_e(e,e.FRAGMENT_SHADER,t);if(!r||!i)return e.deleteShader(r),e.deleteShader(i),null;const n=e.createProgram();if(e.attachShader(n,r),e.attachShader(n,i),e.linkProgram(n),e.deleteShader(r),e.deleteShader(i),!e.getProgramParameter(n,e.LINK_STATUS)){const r=e.getProgramInfoLog(n);return console.warn("[webgl-filter] link error:",r),v(/* @__PURE__ */new Error(`WebGL program link failed: ${r}`),{component:"webgl-filter-engine",tags:["upload","filter","webgl","link"],extra:{fragmentLength:t.length}}),e.deleteProgram(n),null}return n}function Me(e){const t=e.createTexture();return e.bindTexture(e.TEXTURE_2D,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),t}function Ue(e,t,r){const i=Me(e);e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null);const n=e.createFramebuffer();return e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.bindFramebuffer(e.FRAMEBUFFER,null),{fbo:n,tex:i}}function Re(e,t,r){for(const[i,n]of Object.entries(r)){const r=e.getUniformLocation(t,i);if(r)if("number"!=typeof n)switch(n.length){case 2:e.uniform2fv(r,n);break;case 3:e.uniform3fv(r,n);break;case 4:e.uniform4fv(r,n)}else e.uniform1f(r,n)}}function Ie(e){const t=e.config,r=t?.templateId,i=t?.fragShader;if(r){const e=we(r);return{def:e??null,fragShader:e?.fragShader??null}}return i?{def:null,fragShader:i}:{def:null,fragShader:null}}function Ne(e){const t=e.config?.variables??{},r={};for(const[i,n]of Object.entries(t))"number"==typeof n&&(r[`u_${i}`]=n);return r}async function Oe(e,t,r,i="image/webp",n=.85){const o=Date.now(),a=t.filter(e=>e.enabled);if(!a.length)return{blob:e,appliedFilters:[],width:0,height:0,processingTime:0};const s=await createImageBitmap(e);let l=s.width,d=s.height;if(l>r||d>r){const e=Math.min(r/l,r/d);l=Math.round(l*e),d=Math.round(d*e)}const c=Math.min(150,l),u=Math.max(1,Math.round(c*d/l)),h=new OffscreenCanvas(c,u).getContext("2d");h.drawImage(s,0,0,c,u);const p=h.getImageData(0,0,c,u);let m;if(s.width!==l||s.height!==d){const e=new OffscreenCanvas(l,d);e.getContext("2d").drawImage(s,0,0,l,d),s.close(),m=await createImageBitmap(e,{imageOrientation:"flipY"})}else m=await createImageBitmap(s,{imageOrientation:"flipY"}),s.close();const g=Ce??new OffscreenCanvas(l,d);g.width===l&&g.height===d||(g.width=l,g.height=d),Ce=g;let f=Fe;if(f||(f=g.getContext("webgl",{preserveDrawingBuffer:!0,alpha:!0})||g.getContext("experimental-webgl",{preserveDrawingBuffer:!0,alpha:!0}),Fe=f),!f||f.isContextLost())return m.close(),Fe=null,Ce=null,async function(e,t,r,i,n,o,a="image/webp",s=.85){const l=new OffscreenCanvas(r,i),d=l.getContext("2d"),c=await createImageBitmap(e);d.drawImage(c,0,0,r,i),c.close();const u=[];for(const h of t){const{def:e}=Ie(h);if(!e?.buildCpuTransform)continue;const t=e.analyze?e.analyze(n,h.config?.variables??{}):{},o={},a=h.config?.variables??{};for(const[r,i]of Object.entries(a))"number"==typeof i&&(o[`u_${r}`]=i);const s=e.buildCpuTransform({...t,...o},r,i),l=d.getImageData(0,0,r,i);d.putImageData(s(l),0,0),u.push(h.id)}return u.length?{blob:await l.convertToBlob({type:a,quality:s}),appliedFilters:u,width:r,height:i,processingTime:Date.now()-o}:{blob:e,appliedFilters:[],width:r,height:i,processingTime:Date.now()-o}}(e,a,l,d,p,o,i,n);const v=Me(f);f.bindTexture(f.TEXTURE_2D,v),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,f.RGBA,f.UNSIGNED_BYTE,m),m.close(),f.viewport(0,0,l,d);const b=[Ue(f,l,d),Ue(f,l,d)],y=f.createBuffer();f.bindBuffer(f.ARRAY_BUFFER,y),f.bufferData(f.ARRAY_BUFFER,Te,f.STATIC_DRAW);const w=ke??/* @__PURE__ */new Map;ke=w;const x=[];let S=v,T=0;try{for(let e=0;e<a.length;e++){const t=a[e],r=e===a.length-1,{def:i,fragShader:n}=Ie(t);if(!n)continue;const o=t.config?.templateId??n;w.has(o)||w.set(o,Ee(f,n));const s=w.get(o);if(!s)continue;f.useProgram(s);const c=f.getAttribLocation(s,"a_position");f.bindBuffer(f.ARRAY_BUFFER,y),f.enableVertexAttribArray(c),f.vertexAttribPointer(c,2,f.FLOAT,!1,0,0),f.activeTexture(f.TEXTURE0),f.bindTexture(f.TEXTURE_2D,S),f.uniform1i(f.getUniformLocation(s,"u_image"),0);const u=f.getUniformLocation(s,"u_resolution");if(u&&f.uniform2f(u,l,d),Re(f,s,Ne(t)),i?.analyze&&Re(f,s,i.analyze(p,t.config?.variables??{})),r)f.bindFramebuffer(f.FRAMEBUFFER,null),f.drawArrays(f.TRIANGLES,0,6);else{const e=b[T];f.bindFramebuffer(f.FRAMEBUFFER,e.fbo),f.drawArrays(f.TRIANGLES,0,6),S=e.tex,T=1-T}x.push(t.id)}return x.length?{blob:await g.convertToBlob({type:i,quality:n}),appliedFilters:x,width:l,height:d,processingTime:Date.now()-o}:{blob:e,appliedFilters:[],width:l,height:d,processingTime:Date.now()-o}}finally{for(const{fbo:e,tex:t}of b)f.deleteFramebuffer(e),f.deleteTexture(t);f.deleteTexture(v),f.deleteBuffer(y)}}async function Pe(e,t,r,i){const n=Date.now(),o=e.filter(e=>e.enabled),a=e=>e;if(!o.length)return{transform:a,appliedFilters:[],processingTime:0};let s=null;try{const e=await createImageBitmap(t),r=Math.min(64,e.width),i=Math.round(r*e.height/e.width),n=new OffscreenCanvas(r,Math.max(1,i)).getContext("2d");n.drawImage(e,0,0,r,Math.max(1,i)),e.close(),s=n.getImageData(0,0,r,Math.max(1,i))}catch{}const l=[],d=[];for(const u of o){const{def:e}=Ie(u);if(!e?.buildCpuTransform)continue;const t=u.config?.variables??{},n=e.analyze&&s?e.analyze(s,t):{},o={};for(const[r,i]of Object.entries(t))"number"==typeof i&&(o[`u_${r}`]=i);try{const t=e.buildCpuTransform({...n,...o},r,i);l.push(t),d.push(u.id)}catch(c){console.warn(`[webgl-filter] buildCpuTransform failed for ${u.id}:`,c),v(c instanceof Error?c:/* @__PURE__ */new Error(`buildCpuTransform failed for ${u.id}`),{component:"webgl-filter-engine",tags:["upload","filter","cpu-transform"],extra:{filterId:u.id}})}}return l.length?{transform:1===l.length?l[0]:e=>l.reduce((e,t)=>t(e),e),appliedFilters:d,processingTime:Date.now()-n}:{transform:a,appliedFilters:[],processingTime:Date.now()-n}}var qe=800;async function Ae(e){return new Promise((t,r)=>{const i=new FileReader;i.onload=()=>t(i.result),i.onerror=()=>r(/* @__PURE__ */new Error("FileReader failed")),i.readAsDataURL(e)})}async function De(e,t){const r=Date.now(),i=t.filter(e=>e.enabled),n=await L(e);let o,a;const s=await createImageBitmap(n,{resizeWidth:qe});if(o=s.width,a=s.height,a>qe){const e=qe/a;o=Math.round(o*e),a=qe}const l=new OffscreenCanvas(o,a);l.getContext("2d").drawImage(s,0,0,o,a),s.close();const d=await l.convertToBlob({type:"image/jpeg",quality:.92}),c=await Ae(d);if(!i.length)return{original:c,processed:c,appliedFilters:[],failedFilters:[],totalExecutionTime:Date.now()-r};let u=c;const h=[],p=[];try{const e=await Oe(d,i,qe,"image/jpeg",.92);e.appliedFilters.length>0&&(u=await Ae(e.blob),h.push(...e.appliedFilters));for(const t of i)e.appliedFilters.includes(t.id)||p.push({id:t.id,error:"Filter not applied"})}catch(m){for(const e of i)p.push({id:e.id,error:m instanceof Error?m.message:"Unknown error"});v(m instanceof Error?m:/* @__PURE__ */new Error("Filter preview failed"),{component:"client-filter-engine",tags:["upload","filter-preview","webgl"],extra:{filterCount:i.length,failedFilters:p.map(e=>e.id)}})}return{original:c,processed:u,appliedFilters:h,failedFilters:p,totalExecutionTime:Date.now()-r}}var Le=/* @__PURE__ */new Map;function je(e,t,r,i){return`${e}:${JSON.stringify(t)}:${r}x${i}`}function ze(e){const t=Le.get(e);return t&&(Le.delete(e),Le.set(e,t)),t}function $e(e,t){if(Le.delete(e),Le.set(e,t),Le.size>3){const e=Le.keys().next().value;void 0!==e&&Le.delete(e)}}var Be=e=>{let t;const r=/* @__PURE__ */new Set,i=(e,i)=>{const n="function"==typeof e?e(t):e;if(!Object.is(n,t)){const e=t;t=(null!=i?i:"object"!=typeof n||null===n)?n:Object.assign({},t,n),r.forEach(r=>r(t,e))}},n=()=>t,o={setState:i,getState:n,getInitialState:()=>a,subscribe:e=>(r.add(e),()=>r.delete(e))},a=t=e(i,n,o);return o},He=e=>e;var Ve=r(null);function We({children:e,...t}){const r=a(null),i=a(t);return r.current&&t.eventId===i.current.eventId&&t.groupId===i.current.groupId||(r.current=function(e){return(t=t=>({eventId:e.eventId,groupId:e.groupId,selectedFiles:[],originalFiles:{},captions:{},hasStarted:!1,oversizedUids:{},showOversizedModal:!1,trimRanges:{},cropSelections:{},videoMuted:!0,uploadStates:{},uploadSpeedBps:0,showRestoreDialog:!1,restoredUids:[],activeFilters:[],showFilterChoice:!1,skipUploadFilters:!1,perFileFilterSkipped:{},filteredThumbs:{},filterOverrides:{},setSelectedFiles:e=>t(t=>({selectedFiles:"function"==typeof e?e(t.selectedFiles):e})),addOriginalFiles:e=>t(t=>({originalFiles:{...t.originalFiles,...e}})),removeFile:e=>t(t=>{if(!t.selectedFiles.some(t=>t.uid===e))return t;const r={...t.captions};delete r[e];const i={...t.oversizedUids};delete i[e];const n={...t.trimRanges};delete n[e];const o={...t.originalFiles};delete o[e];const a={...t.cropSelections};delete a[e];const s={...t.uploadStates};t.hasStarted||delete s[e];const l={...t.filteredThumbs};delete l[e];const d={...t.perFileFilterSkipped};delete d[e];const c={...t.filterOverrides};return delete c[e],{selectedFiles:t.selectedFiles.filter(t=>t.uid!==e),captions:r,oversizedUids:i,trimRanges:n,originalFiles:o,cropSelections:a,uploadStates:s,filteredThumbs:l,perFileFilterSkipped:d,filterOverrides:c}}),setCaption:(e,r)=>t(t=>({captions:{...t.captions,[e]:r}})),setHasStarted:e=>t({hasStarted:e}),addOversizedUids:e=>t(t=>({oversizedUids:{...t.oversizedUids,...e}})),removeOversizedFiles:()=>t(e=>{const t=new Set(Object.keys(e.oversizedUids)),r={...e.captions},i={...e.trimRanges},n={...e.originalFiles},o={...e.cropSelections},a={...e.uploadStates},s={...e.filteredThumbs},l={...e.perFileFilterSkipped},d={...e.filterOverrides};return t.forEach(e=>{delete r[e],delete i[e],delete n[e],delete o[e],delete a[e],delete s[e],delete l[e],delete d[e]}),{selectedFiles:e.selectedFiles.filter(e=>!t.has(e.uid)),captions:r,trimRanges:i,originalFiles:n,cropSelections:o,uploadStates:a,filteredThumbs:s,perFileFilterSkipped:l,filterOverrides:d,oversizedUids:{},showOversizedModal:!1}}),setShowOversizedModal:e=>t({showOversizedModal:e}),replaceFile:(e,r,i)=>t(t=>{const n={...t.cropSelections};i&&(n[e]=i);const o={...t.filteredThumbs};return delete o[e],{selectedFiles:t.selectedFiles.map(t=>t.uid===e?{...t,file:r}:t),cropSelections:n,filteredThumbs:o}}),setTrimRange:(e,r)=>t(t=>({trimRanges:{...t.trimRanges,[e]:r}})),setVideoMuted:e=>t({videoMuted:e}),setUploadState:(e,r)=>t(t=>({uploadStates:{...t.uploadStates,[e]:{...t.uploadStates[e],...r}}})),setUploadSpeedBps:e=>t({uploadSpeedBps:e}),setActiveFilters:(e,r)=>t({activeFilters:e,showFilterChoice:r}),setSkipUploadFilters:e=>t({skipUploadFilters:e}),setFileFilterSkipped:(e,r)=>t(t=>({perFileFilterSkipped:{...t.perFileFilterSkipped,[e]:r}})),setFilterOverride:(e,r,i,n)=>t(t=>{const o={...t.filteredThumbs};return delete o[e],{filterOverrides:{...t.filterOverrides,[e]:{...t.filterOverrides[e],[r]:{...t.filterOverrides[e]?.[r],[i]:n}}},filteredThumbs:o}}),resetFilterOverrides:e=>t(t=>{const r={...t.filterOverrides};delete r[e];const i={...t.filteredThumbs};return delete i[e],{filterOverrides:r,filteredThumbs:i}}),setFilteredThumb:(e,r)=>t(t=>({filteredThumbs:{...t.filteredThumbs,[e]:r}})),resetUploader:()=>{Le.clear(),t({selectedFiles:[],originalFiles:{},captions:{},hasStarted:!1,oversizedUids:{},showOversizedModal:!1,trimRanges:{},cropSelections:{},uploadStates:{},uploadSpeedBps:0,skipUploadFilters:!1,perFileFilterSkipped:{},filteredThumbs:{},filterOverrides:{}})}}))?Be(t):Be;var t}(t),i.current=t),/* @__PURE__ */u(Ve.Provider,{value:r.current,children:e})}function Ge(e){const t=p(Ve);if(!t)throw new Error("useUploadStore must be used within UploadStoreProvider");return function(e,t=He){const r=n.useSyncExternalStore(e.subscribe,n.useCallback(()=>t(e.getState()),[e,t]),n.useCallback(()=>t(e.getInitialState()),[e,t]));return n.useDebugValue(r),r}(t,e)}function Xe(){const e=p(Ve);if(!e)throw new Error("useUploadStoreInstance must be used within UploadStoreProvider");return e}var Ye=/* @__PURE__ */new Map,Qe=null;function Ke({className:e}){/* @__PURE__ */
15
15
  return u("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24",className:e,"aria-hidden":"true",focusable:"false",children:/* @__PURE__ */u("path",{fill:"currentColor",d:"m20 7l-.95-2.05L17 4l2.05-.95L20 1l.95 2.05L23 4l-2.05.95L20 7ZM8.5 7l-.95-2.05L5.5 4l2.05-.95L8.5 1l.95 2.05L11.5 4l-2.05.95L8.5 7ZM20 18.5l-.95-2.05L17 15.5l2.05-.95l.95-2.05l.95 2.05l2.05.95l-2.05.95L20 18.5ZM5.1 21.7l-2.8-2.8q-.3-.3-.3-.725t.3-.725L13.45 6.3q.3-.3.725-.3t.725.3l2.8 2.8q.3.3.3.725t-.3.725L6.55 21.7q-.3.3-.725.3t-.725-.3Zm9.075-10.475l1.4-1.4l-1.4-1.4l-1.4 1.4l1.4 1.4Z"})})}function Je({className:e}){/* @__PURE__ */
16
16
  return u("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24",className:e,"aria-hidden":"true",focusable:"false",children:/* @__PURE__ */u("path",{fill:"currentColor",d:"m19.55 6.025l-.5-1.075l-1.075-.5Q17.7 4.325 17.7 4t.275-.45l1.075-.5l.5-1.075q.125-.275.45-.275t.45.275l.5 1.075l1.075.5q.275.125.275.45t-.275.45l-1.075.5l-.5 1.075q-.125.275-.45.275t-.45-.275Zm-4 6.675L11.3 8.45l2.15-2.15q.3-.3.725-.3t.725.3l2.8 2.8q.3.3.3.725t-.3.725l-2.15 2.15Zm3.55 9.2l-6.4-6.35l-6.15 6.15q-.3.3-.725.3t-.725-.3l-2.8-2.85q-.275-.275-.275-.7t.275-.7l6.15-6.15L2.1 4.9q-.3-.3-.3-.7t.3-.7q.275-.275.7-.275t.7.275l17 17q.275.275.275.7t-.275.7q-.3.3-.7.3t-.7-.3Z"})})}function Ze({className:e}){/* @__PURE__ */
17
17
  return u("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 24 24",className:e,"aria-hidden":"true",focusable:"false",children:/* @__PURE__ */u("path",{fill:"currentColor",d:"M10 21H5q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h5V2q0-.425.288-.712T11 1t.713.288T12 2v20q0 .425-.288.713T11 23t-.712-.288T10 22zm-5-3h5v-6zm9 3v-9l5 6V5h-5V3h5q.825 0 1.413.588T21 5v14q0 .825-.587 1.413T19 21z"})})}function et({className:e}){/* @__PURE__ */
@@ -30,7 +30,7 @@ return u(Y,{open:e,onOpenChange:e=>!e&&t(),children:/* @__PURE__ */u(W,{classNam
30
30
  return u("div",{className:"bg-background/80 text-foreground pointer-events-none absolute bottom-2 z-10 rounded-full px-2 py-0.5 text-[10px] font-semibold shadow "+("left"===e?"left-2":"right-2"),children:t})}var mt=(e,t,r)=>Math.min(Math.max(e,t),r),gt=e=>Math.max(0,Math.min(100,e)),ft=["nw","ne","sw","se"],vt=({open:e,onClose:t,imageSrc:r,outputSrc:i,aspectRatio:n,initialCrop:o,onCropComplete:l,title:d})=>{const c=a(null),[p,m]=s(null),[g,f]=s(!1),b=a(null),y=h((e,t)=>{const r=c.current.getBoundingClientRect();return{px:Math.min(Math.max(e-r.left,0),r.width),py:Math.min(Math.max(t-r.top,0),r.height)}},[]),w=h(e=>{const t=b.current,r=c.current;var i,o,a,s,l;if(t&&r)if("move"===t.mode)m((i=t.start,o=e.clientX-t.clientX,a=e.clientY-t.clientY,s=r.width,l=r.height,{...i,x:mt(i.x+o,0,s-i.w),y:mt(i.y+a,0,l-i.h)}));else{const{px:i,py:o}=y(e.clientX,e.clientY);m(function(e,t,r,i,n,o,a){const s=t.includes("e")?1:-1,l=t.includes("s")?1:-1,d=s>0?e.x:e.x+e.w,c=l>0?e.y:e.y+e.h,u=s>0?n-d:d,h=l>0?o-c:c;let p=mt((r-d)*s,20,u),m=mt((i-c)*l,20,h);return a&&(m=p/a,m<20&&(m=20,p=m*a),m>h&&(m=h,p=m*a),p>u&&(p=u,m=p/a)),{x:s>0?d:d-p,y:l>0?c:c-m,w:p,h:m}}(t.start,t.corner,i,o,r.width,r.height,n))}},[n,y]),x=h(()=>{b.current=null,window.removeEventListener("pointermove",w),window.removeEventListener("pointerup",x)},[w]),S=(e,t)=>r=>{p&&(r.preventDefault(),r.stopPropagation(),b.current={mode:e,corner:t,start:p,clientX:r.clientX,clientY:r.clientY},window.addEventListener("pointermove",w),window.addEventListener("pointerup",x))},T=h(()=>{m(null),t()},[t]),C=e=>({position:"absolute",width:"14px",height:"14px",background:"#fff",border:"1px solid rgba(0,0,0,.4)",borderRadius:"2px",touchAction:"none",cursor:`${e}-resize`,...e.includes("n")?{top:"-7px"}:{bottom:"-7px"},...e.includes("w")?{left:"-7px"}:{right:"-7px"}});/* @__PURE__ */
31
31
  return u(Y,{open:e,onOpenChange:T,children:/* @__PURE__ */u(W,{className:"flex h-[90vh] min-w-xl flex-col overflow-hidden p-0",children:[
32
32
  /* @__PURE__ */u("div",{className:"bg-background shrink-0",children:/* @__PURE__ */u(H,{children:[/* @__PURE__ */u(G,{children:d||"Crop Image"}),/* @__PURE__ */u(X,{className:"sr-only",children:"Drag the box to move it, or drag a corner to resize."})]})}),
33
- /* @__PURE__ */u("div",{className:"flex max-h-[50vh] min-h-0 flex-1 items-center justify-center overflow-hidden bg-black",children:/* @__PURE__ */u("div",{style:{position:"relative",display:"inline-block",lineHeight:0,touchAction:"none"},children:[/* @__PURE__ */u("img",{ref:c,src:r,alt:"Crop preview",draggable:!1,onLoad:()=>{const e=c.current;e&&m(o?{x:o.x/100*e.width,y:o.y/100*e.height,w:o.width/100*e.width,h:o.height/100*e.height}:function(e,t,r){let i=.9*e,n=.9*t;return r&&(n=i/r,n>.9*t&&(n=.9*t,i=n*r)),{x:(e-i)/2,y:(t-n)/2,w:i,h:n}}(e.width,e.height,n))},style:{display:"block",maxWidth:"100%",maxHeight:"50vh",width:"auto",height:"auto",userSelect:"none"}}),p&&/* @__PURE__ */u("div",{onPointerDown:S("move"),style:{position:"absolute",left:`${p.x}px`,top:`${p.y}px`,width:`${p.w}px`,height:`${p.h}px`,border:"1px dashed rgba(255,255,255,.9)",boxShadow:"0 0 0 9999px rgba(0,0,0,.5)",cursor:"move",touchAction:"none",boxSizing:"border-box"},children:ft.map(e=>/* @__PURE__ */u("div",{onPointerDown:S("resize",e),style:C(e)},e))})]})}),
33
+ /* @__PURE__ */u("div",{className:"flex max-h-[60vh] min-h-0 flex-1 items-center justify-center overflow-hidden bg-black",children:/* @__PURE__ */u("div",{style:{position:"relative",display:"inline-block",lineHeight:0,touchAction:"none"},children:[/* @__PURE__ */u("img",{ref:c,src:r,alt:"Crop preview",draggable:!1,onLoad:()=>{const e=c.current;e&&m(o?{x:o.x/100*e.width,y:o.y/100*e.height,w:o.width/100*e.width,h:o.height/100*e.height}:function(e,t,r){let i=.9*e,n=.9*t;return r&&(n=i/r,n>.9*t&&(n=.9*t,i=n*r)),{x:(e-i)/2,y:(t-n)/2,w:i,h:n}}(e.width,e.height,n))},style:{display:"block",maxWidth:"100%",maxHeight:"50vh",width:"auto",height:"auto",userSelect:"none"}}),p&&/* @__PURE__ */u("div",{onPointerDown:S("move"),style:{position:"absolute",left:`${p.x}px`,top:`${p.y}px`,width:`${p.w}px`,height:`${p.h}px`,border:"1px dashed rgba(255,255,255,.9)",boxShadow:"0 0 0 9999px rgba(0,0,0,.5)",cursor:"move",touchAction:"none",boxSizing:"border-box"},children:ft.map(e=>/* @__PURE__ */u("div",{onPointerDown:S("resize",e),style:C(e)},e))})]})}),
34
34
  /* @__PURE__ */u("div",{className:"border-border bg-background shrink-0 border-t",children:/* @__PURE__ */u(V,{children:[/* @__PURE__ */u(q,{variant:"outlined",onClick:T,disabled:g,children:"Cancel"}),/* @__PURE__ */u(q,{onClick:async()=>{const e=c.current;var t;if(p&&e)try{f(!0);const n=i&&i!==r?await(t=i,new Promise((e,r)=>{const i=new Image;i.onload=()=>e(i),i.onerror=()=>r(/* @__PURE__ */new Error("Failed to load image")),i.src=t})):e,o=p.x/e.width,a=p.y/e.height,s=p.w/e.width,d=p.h/e.height,c={x:Math.round(o*n.naturalWidth),y:Math.round(a*n.naturalHeight),w:Math.round(s*n.naturalWidth),h:Math.round(d*n.naturalHeight)},u={unit:"%",x:gt(100*o),y:gt(100*a),width:gt(100*s),height:gt(100*d)};l(await function(e,t){const r=document.createElement("canvas");r.width=t.w,r.height=t.h;const i=r.getContext("2d");return i?(i.drawImage(e,t.x,t.y,t.w,t.h,0,0,t.w,t.h),new Promise((e,t)=>{r.toBlob(r=>{r?e(r):t(/* @__PURE__ */new Error("Canvas is empty"))},"image/jpeg",.95)})):Promise.reject(/* @__PURE__ */new Error("Failed to get canvas context"))}(n,c),u),T()}catch(n){v(n instanceof Error?n:new Error(String(n)),{component:"ImageCropDialog",tags:["upload","crop"]})}finally{f(!1)}},loading:g,disabled:g||!p,children:"Crop"})]})})]})})},bt=({open:e,onClose:t,videoFile:r,activeFilters:n,onTrimComplete:o,title:l="Select 60 Second Clip"})=>{const d=a(null),c=a(null),p=a(null),m=n?.filter(e=>e.enabled)??[],g=m.length>0,[f,b]=s(0),[y,w]=s(0),[x,S]=s(60),[T,C]=s(0),[F,k]=s(!1),[_,E]=s(!1),[M,U]=s(null),[R,I]=s(null),[N,O]=s(0),[P,A]=s({start:0,end:0});i(()=>{if(r&&e){const e=URL.createObjectURL(r);return U(e),()=>URL.revokeObjectURL(e)}},[r,e]),i(()=>{if(!M||!g)return;const e=d.current,t=c.current;if(!e||!t||!e.requestVideoFrameCallback)return;let r=!1,i=null,n=!1;if(i=e.requestVideoFrameCallback(()=>{(async()=>{if(n||r||!e.videoWidth)return;n=!0;const o=Math.min(1,640/Math.max(e.videoWidth,e.videoHeight)),a=Math.max(1,Math.round(e.videoWidth*o)),s=Math.max(1,Math.round(e.videoHeight*o));t.width=a,t.height=s;const l=t.getContext("2d",{willReadFrequently:!0});if(!l)return;const d=document.createElement("canvas");d.width=a,d.height=s,d.getContext("2d")?.drawImage(e,0,0,a,s);const c=await new Promise(e=>d.toBlob(e,"image/jpeg",.85));if(r||!c)return;const u=await Pe(m,c,a,s);if(r||!u.appliedFilters.length)return;const h=u.transform,p=()=>{r||(l.drawImage(e,0,0,a,s),l.putImageData(h(l.getImageData(0,0,a,s)),0,0),i=e.requestVideoFrameCallback(p))};p()})()}),e.readyState>=2&&e.paused)try{e.currentTime=e.currentTime+.001}catch{}return()=>{r=!0,null!==i&&e.cancelVideoFrameCallback?.(i)}},[M,g,JSON.stringify(n)]);const D=h(e=>{if(!p.current||0===f)return 0;const t=p.current.getBoundingClientRect();return Math.max(0,Math.min(1,(e-t.left)/t.width))*f},[f]),L=h(e=>0===f?0:e/f*100,[f]),j=(e,t)=>{e.preventDefault(),e.stopPropagation(),I(t),O(e.clientX),A({start:y,end:x})},z=(e,t)=>{e.stopPropagation();const r=e.touches[0];I(t),O(r?.clientX??0),A({start:y,end:x})};i(()=>{if(!R||!p.current)return;const e=e=>{const t=p.current.getBoundingClientRect(),r=(e-N)/t.width*f;if("start"===R){let e=Math.max(0,P.start+r);e=Math.min(e,x-1),x-e>60&&(e=x-60),w(e),d.current&&(d.current.currentTime=e)}else if("end"===R){let e=Math.min(f,P.end+r);e=Math.max(e,y+1),e-y>60&&(e=y+60),S(e)}else if("range"===R){const e=P.end-P.start;let t=P.start+r,i=P.end+r;t<0&&(t=0,i=e),i>f&&(i=f,t=f-e),w(t),S(i),d.current&&(d.current.currentTime=t)}},t=t=>e(t.clientX),r=t=>e(t.touches[0].clientX),i=()=>I(null);return document.addEventListener("mousemove",t),document.addEventListener("mouseup",i),document.addEventListener("touchmove",r),document.addEventListener("touchend",i),()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",i),document.removeEventListener("touchmove",r),document.removeEventListener("touchend",i)}},[R,N,P,f,y,x]);const $=()=>{d.current&&(F?d.current.pause():((T<y||T>=x)&&(d.current.currentTime=y),d.current.play()),k(!F))},B=e=>`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,"0")}`,Q=()=>{w(0),S(60),C(0),k(!1),I(null),d.current&&d.current.pause(),t()},K=x-y;/* @__PURE__ */
35
35
  return u(Y,{open:e,onOpenChange:Q,children:/* @__PURE__ */u(W,{className:"max-h-[90vh] max-w-3xl overflow-y-auto p-0",children:[
36
36
  /* @__PURE__ */u("div",{className:"bg-background sticky top-0 z-10",children:/* @__PURE__ */u(H,{children:[/* @__PURE__ */u(G,{children:l}),/* @__PURE__ */u(X,{className:"hidden",children:"Review the video preview and choose the start and end times for the clip you want to keep."})]})}),
@@ -5,8 +5,8 @@ return o("div",{className:"group relative size-full overflow-hidden sm:rounded",
5
5
  /* @__PURE__ */o(D,{url:e.url||"",alt:e.caption||"",thumbnailUrl:e.thumbnailUrl||void 0,blurhash:e.blurhash||void 0,pswpData:{id:e._id,type:e.type,hash:e._id,width:e.dimension?.width,height:e.dimension?.height,thumbnailUrl:e.thumbnailUrl||void 0,caption:e.caption||""}}),
6
6
  /* @__PURE__ */o("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 flex items-center justify-between bg-gradient-to-t from-black/50 to-transparent pl-3",children:[/* @__PURE__ */o(N,{variant:"caption",className:"text-xs text-white opacity-90 sm:text-sm",children:Q(e.createdAt)}),/* @__PURE__ */o("div",{className:"pointer-events-auto flex items-center",children:[/* @__PURE__ */o("button",{type:"button",className:"cursor-pointer p-2 text-white hover:opacity-80","aria-label":"Edit caption",onClick:t=>{t.stopPropagation(),t.preventDefault(),a(e._id)},children:/* @__PURE__ */o("svg",{viewBox:"0 0 24 24",className:"size-5","aria-hidden":"true",children:/* @__PURE__ */o("path",{fill:"currentColor",d:"M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25ZM20.71 7.04a1 1 0 0 0 0-1.41l-2.34-2.34a1 1 0 0 0-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83Z"})})}),/* @__PURE__ */o(O,{icon:/* @__PURE__ */o(R,{className:"size-5"}),color:"error",size:"sm","aria-label":"Delete upload",tooltip:"Delete",onClick:a=>{a.stopPropagation(),a.preventDefault(),t(e._id)}})]})]}),
7
7
  /* @__PURE__ */o("button",{type:"button","aria-label":`Status: ${i?.title||"Unknown"}`,onClick:e=>{e.stopPropagation(),e.preventDefault(),n(r)},className:c("pointer-events-auto absolute top-1 right-1 cursor-pointer rounded-full p-1 transition-opacity hover:opacity-80",i?.bgColor||"bg-gray-500/20"),children:/* @__PURE__ */o("span",{className:c("block size-5",i?.color||"text-gray-500"),children:i?.icon||null})})]})})}),F=({content:t,onClose:n})=>{const[r,i]=a(""),s=function(){const e=l(),{user:t,props:a}=d(),n=a?.organizationId,r=t?.token,o=t?._id??t?.uid??null,i=[f.USER_UPLOADS,n??"",o];return h({mutationKey:["update-upload-caption",n??"",o],mutationFn:async({contentId:e,caption:t})=>{const a=await g.post(v.UPDATE_CONTENT_CAPTION,{json:{contentId:e,caption:t},throwHttpErrors:!1,headers:{"x-org-id":n,...r?{Authorization:`Bearer ${r}`}:{}}}).json();if(a.error)throw new Error(a.error);return{contentId:e,caption:t,content:a.data}},onMutate:async({contentId:t,caption:a})=>{await e.cancelQueries({queryKey:i,exact:!1});const n=e.getQueriesData({queryKey:i,exact:!1});return e.setQueriesData({queryKey:i,exact:!1},e=>e?.pages?{...e,pages:e.pages.map(e=>({...e,data:e.data.map(e=>e._id===t?{...e,caption:a,status:y.IN_REVIEW}:e)}))}:e),{previousData:n}},onError:(t,a,n)=>{n?.previousData?.forEach(([t,a])=>{e.setQueryData(t,a)})}})}();return e(()=>{i(t?.caption??"")},[t]),/* @__PURE__ */o(z,{open:Boolean(t),onOpenChange:e=>!e&&n(),children:/* @__PURE__ */o(S,{className:"w-full max-w-lg",children:[
8
- /* @__PURE__ */o(j,{children:[/* @__PURE__ */o(A,{children:"Update caption"}),/* @__PURE__ */o(_,{children:"Edit or clear the caption for this upload."})]}),
9
- /* @__PURE__ */o("div",{className:"px-4",children:/* @__PURE__ */o($,{label:"Caption",value:r,maxLength:1e3,rows:4,disabled:s.isPending,error:s.error instanceof Error?s.error.message:void 0,onInput:e=>i(e.currentTarget.value)})}),
8
+ /* @__PURE__ */o(j,{children:/* @__PURE__ */o(A,{children:"Update caption"})}),
9
+ /* @__PURE__ */o("div",{className:"px-4",children:/* @__PURE__ */o($,{value:r,maxLength:1e3,rows:4,disabled:s.isPending,error:s.error instanceof Error?s.error.message:void 0,onInput:e=>i(e.currentTarget.value)})}),
10
10
  /* @__PURE__ */o(I,{children:[/* @__PURE__ */o(E,{variant:"outlined",color:"foreground",disabled:s.isPending,onClick:n,children:"Cancel"}),/* @__PURE__ */o(E,{loading:s.isPending,onClick:async()=>{if(t)try{await s.mutateAsync({contentId:t._id,caption:r}),n()}catch{}},children:"Save"})]})]})})},Y=e=>new Date(e).toLocaleDateString("en-US",{month:"short",year:"numeric"}),G=e=>{if(0===e.length)return"";if(1===e.length)return Y(e[0].createdAt);const{minTime:t,maxTime:a}=e.reduce((e,t)=>{const a=new Date(t.createdAt).getTime();return{minTime:Math.min(e.minTime,a),maxTime:Math.max(e.maxTime,a)}},{minTime:1/0,maxTime:-1/0}),n=Y(new Date(t).toISOString()),r=Y(new Date(a).toISOString());return n===r?n:`${n} - ${r}`},H=()=>{const n=x(),l=w(),{user:p,loadingUser:h,portalContainer:y,organization:D}=d(),j=t(null),I=t(!1),M=t(null),U=t(null),[q,k]=a(null),[O,$]=a(null),[R,Q]=a(null),{contents:Y,loading:H,hasNextPage:W,fetchNextPage:Z,isFetchingNextPage:J}=function({sort:e="-createdAt",limit:t=20}={}){const{user:a,loadingUser:n,props:o,organization:i}=d(),s=o?.organizationId,l=a?.token,c=a?._id??a?.uid??null,{data:p,isLoading:h,isError:y,error:w,isFetchingNextPage:x,hasNextPage:N,fetchNextPage:b,refetch:T}=m({queryKey:[f.USER_UPLOADS,s??"",c,t,e],queryFn:async({pageParam:a=1})=>await g.get(v.MY_UPLOADS,{searchParams:"string"==typeof a?{after:a,limit:t,sort:e}:{page:a,limit:t,sort:e},headers:{"x-org-id":s,...l?{Authorization:`Bearer ${l}`}:{}}}).json(),initialPageParam:1,getPreviousPageParam:u,getNextPageParam:L,maxPages:25,staleTime:12e4,gcTime:3e5,enabled:!n&&!!a&&!0===i?.integrationSettings?.enableMyUploads});return{contents:r(()=>p?.pages?.flatMap(e=>e?.data??[])??[],[p]),loading:h,isError:y,error:w,isFetchingNextPage:x,hasNextPage:!!N,fetchNextPage:b,refetch:T,totalCount:p?.pages?.[0]?.meta?.totalCount??0}}({sort:"-createdAt",limit:20});e(()=>{h||p||n("/auth/login",{state:{referrer:l.pathname},replace:!0})},[h,p,n,l.pathname]),e(()=>{h||!D||D.integrationSettings?.enableMyUploads||n("/",{replace:!0})},[h,D,n]);const X=Y.length>0,ee=!H&&!X,te=r(()=>{if(!Y.length)return[];const e={};return Y.forEach(t=>{const a=t.eventId||"unknown";e[a]||(e[a]={eventId:a,eventName:t.event?.name||"Event",uploads:[]}),e[a].uploads.push(t)}),Object.values(e).sort((e,t)=>{const a=new Date(e.uploads[0]?.createdAt||0).getTime();return new Date(t.uploads[0]?.createdAt||0).getTime()-a})},[Y]);e(()=>()=>{j.current?.destroy?.(),j.current=null},[y]);const ae=i(async e=>{if(j.current||I.current)return;const t=M.current,a=e.target.closest("a");if(!t||!a||!t.contains(a))return;e.preventDefault(),I.current=!0;const n=Array.from(t.querySelectorAll("a")).indexOf(a);try{const[{default:e},{default:a},{default:r},{loadPhotoSwipe:o}]=await Promise.all([import("./web.es.js").then(e=>e.n),import("./Bo39kG4k2.js"),import("./xYXAtJi42.js"),import("./web.es.js").then(e=>e.t)]),i=new e({gallery:t,children:"a",counter:!1,bgOpacity:1,wheelToZoom:!0,pinchToClose:!0,zoom:!1,pswpModule:o,appendToEl:y??document.body});j.current=i,new a(i),new r(i),i.init(),n>=0&&j.current?.loadAndOpen?.(n)}finally{I.current=!1}},[y]);e(()=>{const e=U.current;if(!e||!W)return;const t=new IntersectionObserver(e=>{e[0]?.isIntersecting&&W&&!J&&Z()},{rootMargin:"200px"});return t.observe(e),()=>t.disconnect()},[W,J,Z]);const ne=r(()=>Y.find(e=>e._id===q)??null,[q,Y]),re=r(()=>Y.find(e=>e._id===O)??null,[O,Y]),oe=R?B[R]:null;return D&&!D.integrationSettings?.enableMyUploads?null:/* @__PURE__ */o("div",{className:"bg-background min-h-screen w-full",children:[
11
11
  /* @__PURE__ */o("div",{className:"relative flex items-center justify-center",children:[/* @__PURE__ */o(P,{}),/* @__PURE__ */o(N,{variant:"h4",align:"center",children:"My Uploads"})]}),
12
12
  /* @__PURE__ */o("section",{className:"space-y-3",children:H?/* @__PURE__ */o("div",{className:"space-y-8 py-4",children:Array.from({length:2}).map((e,t)=>/* @__PURE__ */o("div",{className:"space-y-4",children:[/* @__PURE__ */o("div",{className:"flex items-center justify-between",children:[/* @__PURE__ */o(C,{className:"h-6 w-48"}),/* @__PURE__ */o(C,{className:"h-5 w-24"})]}),/* @__PURE__ */o("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4",children:Array.from({length:4}).map((e,t)=>/* @__PURE__ */o(C,{className:"h-52 w-full lg:h-64"},t))})]},t))}):ee?/* @__PURE__ */o(T,{className:"py-12",title:"No uploads yet",description:"Photos and videos you upload to events will appear here."}):/* @__PURE__ */o(s,{children:[