@masters-union/union-stack 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var UnionStack=(()=>{var N=Object.defineProperty,ke=Object.defineProperties,we=Object.getOwnPropertyDescriptor,Ce=Object.getOwnPropertyDescriptors,Ee=Object.getOwnPropertyNames,ee=Object.getOwnPropertySymbols;var re=Object.prototype.hasOwnProperty,$e=Object.prototype.propertyIsEnumerable;var te=(o,e,t)=>e in o?N(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,C=(o,e)=>{for(var t in e||(e={}))re.call(e,t)&&te(o,t,e[t]);if(ee)for(var t of ee(e))$e.call(e,t)&&te(o,t,e[t]);return o},I=(o,e)=>ke(o,Ce(e));var _=(o,e)=>()=>(o&&(e=o(o=0)),e);var ie=(o,e)=>{for(var t in e)N(o,t,{get:e[t],enumerable:!0})},Ue=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ee(e))!re.call(o,r)&&r!==t&&N(o,r,{get:()=>e[r],enumerable:!(i=we(e,r))||i.enumerable});return o};var Te=o=>Ue(N({},"__esModule",{value:!0}),o);function Ae(){if(document.getElementById(ce))return;let o=(t,i)=>{let r=document.createElement("link");r.rel="preconnect",r.href=t,i&&(r.crossOrigin="anonymous"),document.head.appendChild(r)};o("https://fonts.googleapis.com"),o("https://fonts.gstatic.com",!0);let e=document.createElement("link");e.id=ce,e.rel="stylesheet",e.href=Fe,document.head.appendChild(e)}function pe(){if(typeof document=="undefined"||(Ae(),document.getElementById(de)))return;let o=document.createElement("style");o.id=de,o.textContent=He,document.head.appendChild(o)}function ue(o){var i,r,n,a,s;let t=((o==null?void 0:o.mode)||"light")==="dark"?ze:Be;return{"--us-primary":(i=o==null?void 0:o.primary)!=null?i:t.primary,"--us-on-primary":t.onPrimary,"--us-bg":(r=o==null?void 0:o.background)!=null?r:t.background,"--us-fg":(n=o==null?void 0:o.foreground)!=null?n:t.foreground,"--us-muted":t.muted,"--us-border":(a=o==null?void 0:o.border)!=null?a:t.border,"--us-subtle":"color-mix(in srgb, var(--us-fg) 5%, var(--us-bg))","--us-overlay":"color-mix(in srgb, var(--us-fg) 9%, var(--us-bg))","--us-border-strong":"color-mix(in srgb, var(--us-fg) 18%, var(--us-border))","--us-elevated":t.elevated,"--us-raised":t.raised,"--us-accent":t.accent,"--us-success":t.success,"--us-danger":t.danger,"--us-radius":(s=o==null?void 0:o.radius)!=null?s:"12px"}}var de,ce,Fe,Be,ze,He,he=_(()=>{"use strict";de="unionstack-picker-styles",ce="unionstack-picker-fonts",Fe="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap";Be={primary:"#494bd6",onPrimary:"#ffffff",background:"#fdfbff",foreground:"#1b1b21",muted:"#5e5c6e",subtle:"#f3f1fa",border:"#e4e1ee",borderStrong:"#c8c5d4",elevated:"#ffffff",overlay:"#eceaf4",raised:"#ffffff",accent:"#b35a00",success:"#2c9a5b",danger:"#ba1a1a"},ze={primary:"#f4f4f5",onPrimary:"#18181b",background:"#0a0a0c",foreground:"#f4f4f5",muted:"#8b8b93",subtle:"#161618",border:"#2a2a2e",borderStrong:"#3f3f46",elevated:"#141416",overlay:"#1d1d20",raised:"#27272a",accent:"#ffb783",success:"#7ad08e",danger:"#ffb4ab"},He=`
1
+ "use strict";var UnionStack=(()=>{var W=Object.defineProperty,$e=Object.defineProperties,Ue=Object.getOwnPropertyDescriptor,Pe=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertyNames,ie=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,Te=Object.prototype.propertyIsEnumerable;var oe=(o,e,t)=>e in o?W(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,E=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&oe(o,t,e[t]);if(ie)for(var t of ie(e))Te.call(e,t)&&oe(o,t,e[t]);return o},z=(o,e)=>$e(o,Pe(e));var K=(o,e)=>()=>(o&&(e=o(o=0)),e);var se=(o,e)=>{for(var t in e)W(o,t,{get:e[t],enumerable:!0})},Ie=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Re(e))!ne.call(o,r)&&r!==t&&W(o,r,{get:()=>e[r],enumerable:!(i=Ue(e,r))||i.enumerable});return o};var Me=o=>Ie(W({},"__esModule",{value:!0}),o);function je(){if(document.getElementById(he))return;let o=(t,i)=>{let r=document.createElement("link");r.rel="preconnect",r.href=t,i&&(r.crossOrigin="anonymous"),document.head.appendChild(r)};o("https://fonts.googleapis.com"),o("https://fonts.gstatic.com",!0);let e=document.createElement("link");e.id=he,e.rel="stylesheet",e.href=He,document.head.appendChild(e)}function me(){if(typeof document=="undefined"||(je(),document.getElementById(ue)))return;let o=document.createElement("style");o.id=ue,o.textContent=Ne,document.head.appendChild(o)}function fe(o){var i,r,n,a,s;let t=((o==null?void 0:o.mode)||"light")==="dark"?De:Oe;return{"--us-primary":(i=o==null?void 0:o.primary)!=null?i:t.primary,"--us-on-primary":t.onPrimary,"--us-bg":(r=o==null?void 0:o.background)!=null?r:t.background,"--us-fg":(n=o==null?void 0:o.foreground)!=null?n:t.foreground,"--us-muted":t.muted,"--us-border":(a=o==null?void 0:o.border)!=null?a:t.border,"--us-subtle":"color-mix(in srgb, var(--us-fg) 5%, var(--us-bg))","--us-overlay":"color-mix(in srgb, var(--us-fg) 9%, var(--us-bg))","--us-border-strong":"color-mix(in srgb, var(--us-fg) 18%, var(--us-border))","--us-elevated":t.elevated,"--us-raised":t.raised,"--us-accent":t.accent,"--us-success":t.success,"--us-danger":t.danger,"--us-radius":(s=o==null?void 0:o.radius)!=null?s:"12px"}}var ue,he,He,Oe,De,Ne,ge=K(()=>{"use strict";ue="unionstack-picker-styles",he="unionstack-picker-fonts",He="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap";Oe={primary:"#494bd6",onPrimary:"#ffffff",background:"#fdfbff",foreground:"#1b1b21",muted:"#5e5c6e",subtle:"#f3f1fa",border:"#e4e1ee",borderStrong:"#c8c5d4",elevated:"#ffffff",overlay:"#eceaf4",raised:"#ffffff",accent:"#b35a00",success:"#2c9a5b",danger:"#ba1a1a"},De={primary:"#f4f4f5",onPrimary:"#18181b",background:"#0a0a0c",foreground:"#f4f4f5",muted:"#8b8b93",subtle:"#161618",border:"#2a2a2e",borderStrong:"#3f3f46",elevated:"#141416",overlay:"#1d1d20",raised:"#27272a",accent:"#ffb783",success:"#7ad08e",danger:"#ffb4ab"},Ne=`
2
2
  .us-picker-backdrop {
3
3
  --us-font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
4
4
  --us-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
@@ -146,6 +146,8 @@
146
146
  }
147
147
  .us-file[data-state="done"] { border-color: color-mix(in srgb, var(--us-success) 35%, var(--us-border)); }
148
148
  .us-file[data-state="failed"] { border-color: color-mix(in srgb, var(--us-danger) 35%, var(--us-border)); }
149
+ /* Force-crop: image queued but not yet cropped to the required ratio. */
150
+ .us-file[data-crop-required="true"] { border-color: color-mix(in srgb, var(--us-danger) 35%, var(--us-border)); }
149
151
 
150
152
  .us-file-thumb {
151
153
  width: 40px; height: 40px; flex-shrink: 0;
@@ -506,5 +508,5 @@
506
508
 
507
509
  /* \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 empty state niceties \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
508
510
  .us-file-list:empty { display: none; }
509
- `});function $(o,e,t){let i=document.createElement(o);return e&&(i.className=e),t!==void 0&&(i.textContent=t),i}function W(o,e){let t=document.createElement("button");return t.type="button",t.className="us-tool",t.innerHTML=`${e} <span>${je(o)}</span>`,t}function je(o){return o.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e])}function E(o,e,t){return Math.max(e,Math.min(t,o))}function me(o){return new Promise((e,t)=>{let i=URL.createObjectURL(o),r=new Image;r.onload=()=>{URL.revokeObjectURL(i),e(r)},r.onerror=()=>{URL.revokeObjectURL(i),t(new Error("decode failed"))},r.src=i})}function fe(o){return/^image\/(png|webp|gif)$/.test(o)}var P,q,ge=_(()=>{"use strict";P={back:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>',crop:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></svg>',circle:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/></svg>',rotate:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.82.93 6.58 2.46L21 8"/><path d="M21 3v5h-5"/></svg>',undo:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-15-6.7L3 13"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'},q=class{constructor(e){this.opts=e;this.cropBox=null;this.displayScale=1;this.hasAlpha=!1;this.mode="none";this.cropRect=null;this.dragKind=null;this.dragStart=null;this.onPointerMove=e=>{if(!this.dragKind||!this.dragStart||!this.cropRect)return;let t=e.clientX-this.dragStart.px,i=e.clientY-this.dragStart.py,r=this.dragStart.rect,n=this.displayCanvas.width,a=this.displayCanvas.height,s=24,{x:l,y:d,w:c,h:p}=r;switch(this.dragKind){case"move":l=E(r.x+t,0,n-r.w),d=E(r.y+i,0,a-r.h);break;case"nw":{let h=E(r.x+t,0,r.x+r.w-s),u=E(r.y+i,0,r.y+r.h-s);c=r.w+(r.x-h),p=r.h+(r.y-u),l=h,d=u;break}case"ne":{let h=E(r.w+t,s,n-r.x),u=E(r.y+i,0,r.y+r.h-s);p=r.h+(r.y-u),c=h,d=u;break}case"sw":{let h=E(r.x+t,0,r.x+r.w-s),u=E(r.h+i,s,a-r.y);c=r.w+(r.x-h),p=u,l=h;break}case"se":c=E(r.w+t,s,n-r.x),p=E(r.h+i,s,a-r.y);break}this.cropRect={x:l,y:d,w:c,h:p},this.updateCropBox()};this.onPointerUp=()=>{this.dragKind=null,this.dragStart=null,document.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp)}}async open(){this.mount();try{await this.loadOriginalIntoWorking(),this.opts.originalFile&&this.opts.originalFile!==this.opts.file&&this.markEdited(!0),this.draw()}catch(e){this.canvasWrap.textContent=`Couldn't load image: ${e.message}`}}close(){document.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp),this.root.remove()}mount(){this.root=$("div","us-editor");let e=$("div","us-editor-header"),t=document.createElement("button");t.type="button",t.className="us-editor-back",t.setAttribute("aria-label","Back"),t.innerHTML=P.back,t.onclick=()=>{this.opts.onCancel(),this.close()},e.appendChild(t),e.appendChild($("div","us-editor-title",this.opts.title)),this.root.appendChild(e),this.canvasWrap=$("div","us-editor-canvas-wrap"),this.displayCanvas=document.createElement("canvas"),this.displayCanvas.className="us-editor-canvas",this.canvasWrap.appendChild(this.displayCanvas),this.root.appendChild(this.canvasWrap);let i=$("div","us-editor-toolbar");this.cropTool=W("Crop",P.crop),this.cropTool.onclick=()=>this.toggleCropMode(),this.circleTool=W("Circle",P.circle),this.circleTool.onclick=()=>this.applyCircle(),this.rotateTool=W("Rotate 90\xB0",P.rotate),this.rotateTool.onclick=()=>this.applyRotate(),this.revertTool=W("Revert",P.undo),this.revertTool.onclick=()=>this.revert(),this.revertTool.disabled=!0,i.appendChild(this.cropTool),i.appendChild(this.circleTool),i.appendChild(this.rotateTool),i.appendChild($("div","us-tool-spacer")),i.appendChild(this.revertTool),this.root.appendChild(i);let r=$("div","us-editor-footer"),n=document.createElement("button");n.type="button",n.className="us-btn",n.textContent="Cancel",n.onclick=()=>{this.opts.onCancel(),this.close()},this.applyBtn=document.createElement("button"),this.applyBtn.type="button",this.applyBtn.className="us-btn us-btn-primary",this.applyBtn.innerHTML=`${P.check} <span>Apply</span>`,this.applyBtn.onclick=()=>this.applyAndClose(),r.appendChild(n),r.appendChild(this.applyBtn),this.root.appendChild(r),this.opts.host.appendChild(this.root)}async loadOriginalIntoWorking(){let e=await me(this.opts.file),t=document.createElement("canvas");t.width=e.naturalWidth,t.height=e.naturalHeight;let i=t.getContext("2d");if(!i)throw new Error("Canvas 2D context unavailable");i.drawImage(e,0,0),this.working=t,this.hasAlpha=fe(this.opts.file.type),this.markEdited(!1)}async loadTrueOriginalIntoWorking(){var n;let e=(n=this.opts.originalFile)!=null?n:this.opts.file,t=await me(e),i=document.createElement("canvas");i.width=t.naturalWidth,i.height=t.naturalHeight;let r=i.getContext("2d");if(!r)throw new Error("Canvas 2D context unavailable");r.drawImage(t,0,0),this.working=i,this.hasAlpha=fe(e.type),this.markEdited(!1)}draw(){let{width:e,height:t}=this.working,i=Math.min(1,720/Math.max(e,t)),r=Math.max(1,Math.round(e*i)),n=Math.max(1,Math.round(t*i));this.displayCanvas.width=r,this.displayCanvas.height=n,this.displayScale=i;let a=this.displayCanvas.getContext("2d");a&&(a.clearRect(0,0,r,n),a.drawImage(this.working,0,0,r,n),this.updateCropBox())}toggleCropMode(){this.mode==="crop"?this.applyCrop():this.enterCropMode()}enterCropMode(){this.mode="crop",this.cropTool.dataset.active="true",this.cropTool.innerHTML=`${P.check} <span>Apply crop</span>`;let e=this.displayCanvas.width,t=this.displayCanvas.height,i=Math.round(Math.min(e,t)*.1);this.cropRect={x:i,y:i,w:e-i*2,h:t-i*2},this.renderCropBox()}exitCropMode(){this.mode="none",this.cropTool.removeAttribute("data-active"),this.cropTool.innerHTML=`${P.crop} <span>Crop</span>`,this.cropRect=null,this.cropBox&&(this.cropBox.remove(),this.cropBox=null)}renderCropBox(){if(!this.cropRect)return;this.cropBox&&this.cropBox.remove();let e=$("div","us-crop-box");for(let t of["nw","ne","sw","se"]){let i=$("div","us-crop-handle");i.dataset.pos=t,i.addEventListener("pointerdown",r=>this.beginDrag(r,t)),e.appendChild(i)}e.addEventListener("pointerdown",t=>{t.target.classList.contains("us-crop-handle")||this.beginDrag(t,"move")}),this.canvasWrap.appendChild(e),this.cropBox=e,this.updateCropBox()}updateCropBox(){if(!this.cropBox||!this.cropRect)return;let e=this.displayCanvas.getBoundingClientRect(),t=this.canvasWrap.getBoundingClientRect(),i=e.left-t.left+this.cropRect.x,r=e.top-t.top+this.cropRect.y;this.cropBox.style.left=`${i}px`,this.cropBox.style.top=`${r}px`,this.cropBox.style.width=`${this.cropRect.w}px`,this.cropBox.style.height=`${this.cropRect.h}px`}beginDrag(e,t){this.cropRect&&(e.preventDefault(),this.dragKind=t,this.dragStart={px:e.clientX,py:e.clientY,rect:C({},this.cropRect)},document.addEventListener("pointermove",this.onPointerMove),document.addEventListener("pointerup",this.onPointerUp))}applyCrop(){if(!this.cropRect){this.exitCropMode();return}let e=this.displayScale,t=Math.round(this.cropRect.x/e),i=Math.round(this.cropRect.y/e),r=Math.round(this.cropRect.w/e),n=Math.round(this.cropRect.h/e),a=document.createElement("canvas");a.width=r,a.height=n;let s=a.getContext("2d");s&&(s.drawImage(this.working,t,i,r,n,0,0,r,n),this.working=a,this.exitCropMode(),this.markEdited(!0),this.draw())}applyRotate(){let{width:e,height:t}=this.working,i=document.createElement("canvas");i.width=t,i.height=e;let r=i.getContext("2d");r&&(r.translate(t,0),r.rotate(Math.PI/2),r.drawImage(this.working,0,0),this.working=i,this.exitCropMode(),this.markEdited(!0),this.draw())}applyCircle(){let{width:e,height:t}=this.working,i=Math.min(e,t),r=Math.round((e-i)/2),n=Math.round((t-i)/2),a=document.createElement("canvas");a.width=i,a.height=i;let s=a.getContext("2d");s&&(s.save(),s.beginPath(),s.arc(i/2,i/2,i/2,0,Math.PI*2),s.closePath(),s.clip(),s.drawImage(this.working,r,n,i,i,0,0,i,i),s.restore(),this.working=a,this.hasAlpha=!0,this.exitCropMode(),this.markEdited(!0),this.draw())}async revert(){await this.loadTrueOriginalIntoWorking(),this.exitCropMode(),this.draw()}markEdited(e){this.revertTool.disabled=!e}async applyAndClose(){this.applyBtn.disabled=!0;try{let e=await this.exportFile();this.opts.onApply(e),this.close()}catch(e){this.applyBtn.disabled=!1,console.error("[union-stack] image export failed",e)}}exportFile(){return new Promise((e,t)=>{let i=this.hasAlpha?"image/png":"image/jpeg",r=i==="image/jpeg"?.92:void 0;this.working.toBlob(n=>{if(!n)return t(new Error("toBlob returned null"));let a=this.opts.file.name.replace(/\.[^.]+$/,""),s=i==="image/png"?"png":"jpg";e(new File([n],`${a}-edited.${s}`,{type:i}))},i,r)})}}});function Oe(o,e){var n,a,s,l,d,c,p,h,u,y,S,M,U,T,x,k,f,w,R,b;let t=C({},e),i=e.branding||{};t.branding={logoUrl:(a=(n=i.logoUrl)!=null?n:o.branding.logoUrl)!=null?a:void 0,title:(l=(s=i.title)!=null?s:o.branding.title)!=null?l:void 0,hideFooter:(d=i.hideFooter)!=null?d:o.branding.hideFooter};let r=e.theme||{};if(t.theme={primary:(p=(c=r.primary)!=null?c:o.theme.primary)!=null?p:void 0,background:(u=(h=r.background)!=null?h:o.theme.background)!=null?u:void 0,foreground:(S=(y=r.foreground)!=null?y:o.theme.foreground)!=null?S:void 0,border:(U=(M=r.border)!=null?M:o.theme.border)!=null?U:void 0,radius:(x=(T=r.radius)!=null?T:o.theme.radius)!=null?x:void 0,mode:(f=(k=r.mode)!=null?k:o.theme.mode)!=null?f:void 0},t.maxFileSize=(w=e.maxFileSize)!=null?w:o.constraints.maxFileSizeBytes,t.maxFiles=(R=e.maxFiles)!=null?R:o.constraints.maxFilesPerUpload,!e.accept&&((b=o.constraints.allowedMimeTypes)!=null&&b.length)){let z=o.constraints.allowedMimeTypes.filter(G=>G!=="*/*");z.length>0&&(t.accept=z.join(","))}return t}function V(o){return o?o.startsWith("image/")?v.image:o.startsWith("video/")?v.video:o.startsWith("audio/")?v.audio:o==="application/pdf"?v.pdf:o.startsWith("application/zip")||o.includes("compressed")||o==="application/x-tar"||o==="application/gzip"?v.archive:v.file:v.file}function m(o,e,t){let i=document.createElement(o);return e&&(i.className=e),t!==void 0&&(i.textContent=t),i}function We(o){var i,r,n;let e=o.trim().toLowerCase();if(!e)return"";if(e.endsWith("/*")||!e.includes("/")){let a=e.replace("/*","");return(i=Ke[a])!=null?i:a.charAt(0).toUpperCase()+a.slice(1)}if(ve[e])return ve[e];if(e.startsWith("."))return e.slice(1).toUpperCase();let t=(r=e.split("/")[1])!=null?r:e;return((n=t.split("+")[0].split(".").pop())!=null?n:t).toUpperCase()}function H(o){return o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:o<1024*1024*1024?`${(o/1024/1024).toFixed(1)} MB`:`${(o/1024/1024/1024).toFixed(2)} GB`}function J(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,""):Math.random().toString(36).slice(2)+Date.now().toString(36)}async function qe(o){let e;try{e=await fetch(o,{mode:"cors",credentials:"omit"})}catch(n){throw new Error(`Could not reach ${Ve(o)} \u2014 check the URL or CORS.`)}if(!e.ok)throw new Error(`Server returned ${e.status} \u2014 file unavailable.`);let t=await e.blob(),i=Xe(o)||"download",r=t.type||Ye(i);return new File([t],i,{type:r})}function Ve(o){try{return new URL(o).host}catch(e){return"that host"}}function Xe(o){try{let t=new URL(o).pathname.split("/").filter(Boolean).pop();return t?decodeURIComponent(t):""}catch(e){return""}}function Ye(o){let e=o.toLowerCase().split(".").pop()||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",mp4:"video/mp4",mov:"video/quicktime",mp3:"audio/mpeg",wav:"audio/wav",zip:"application/zip",json:"application/json",txt:"text/plain",csv:"text/csv"}[e]||"application/octet-stream"}function X(o,e){let t=new F(o,e);return{open:()=>t.open(),close:()=>t.close(),cancel:()=>t.cancel()}}var De,Ne,v,_e,F,ve,Ke,be=_(()=>{"use strict";he();ge();De="Upload files",Ne="https://unionstack.link",v={upload:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>',fileUp:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><path d="M12 18v-6"/><path d="m9 15 3-3 3 3"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',alert:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',spinner:'<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="9" stroke="currentColor" opacity="0.2"/><path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor"/></svg>',clock:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><polyline points="12 7.5 12 12 15 13.5"/></svg>',image:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',video:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg>',audio:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>',pdf:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="9" y1="13" x2="15" y2="13"/><line x1="9" y1="17" x2="13" y2="17"/></svg>',archive:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="5" rx="2"/><path d="M4 9v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9"/><line x1="10" y1="13" x2="14" y2="13"/></svg>',file:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',zap:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>',device:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>',link:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.72"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.72-1.72"/></svg>',pencil:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>'};_e='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',F=class{constructor(e,t){this.client=e;this.opts=t;this.$backdrop=null;this.$panel=null;this.$list=null;this.$confirm=null;this.$cancel=null;this.$closeBtn=null;this.$input=null;this.$deviceSource=null;this.$urlSource=null;this.$urlInput=null;this.$urlHint=null;this.$urlAddBtn=null;this.items=[];this.editor=null;this.abortCtrl=new AbortController;this.uploadStarted=!1;this.resolved=!1;this.previouslyFocused=null;this.noticeTimer=null;this.$summary=null;this.donePromise=new Promise(i=>{this.resolvePromise=i})}async open(){var e,t;if(typeof document=="undefined")throw new Error("[union-stack] Picker requires a browser environment.");try{let i=await this.client.pickerConfigPromise;i&&(this.opts=Oe(i,this.opts))}catch(i){}return pe(),this.mount(),(t=(e=this.opts).onOpen)==null||t.call(e),this.donePromise}close(){this.unmount(),this.resolved||this.resolveResult()}cancel(){var e,t;this.abortCtrl.abort(),(t=(e=this.opts).onCancel)==null||t.call(e),this.close()}get acceptStr(){let e=this.opts.accept;return Array.isArray(e)?e.join(","):e!=null?e:""}mount(){var u,y,S,M,U,T,x,k;this.previouslyFocused=(u=document.activeElement)!=null?u:null;let e=document.createElement("div");e.className="us-picker-backdrop",Object.entries(ue(this.opts.theme)).forEach(([f,w])=>{e.style.setProperty(f,w)}),e.addEventListener("click",f=>{f.target===e&&!this.uploadStarted&&this.cancel()});let t=m("div","us-picker");this.$panel=t;let i=`us-picker-title-${J()}`;t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),t.setAttribute("aria-labelledby",i),t.tabIndex=-1,t.addEventListener("keydown",f=>{f.key==="Escape"&&!this.uploadStarted?(f.preventDefault(),this.cancel()):f.key==="Tab"&&this.trapFocus(f)});let r=m("div","us-picker-header"),n=m("div","us-picker-header-logo");if((y=this.opts.branding)!=null&&y.logoUrl){let f=document.createElement("img");f.src=this.opts.branding.logoUrl,f.alt="",n.appendChild(f)}else n.innerHTML=v.zap;r.appendChild(n);let a=m("div","us-picker-title",(M=(S=this.opts.branding)==null?void 0:S.title)!=null?M:De);a.id=i,r.appendChild(a),this.$closeBtn=document.createElement("button"),this.$closeBtn.type="button",this.$closeBtn.className="us-picker-close",this.$closeBtn.setAttribute("aria-label","Close"),this.$closeBtn.innerHTML=v.close,this.$closeBtn.onclick=()=>this.cancel(),r.appendChild(this.$closeBtn),t.appendChild(r);let s=m("div","us-picker-body"),l=this.resolvedSources();l.length>1&&s.appendChild(this.renderSourceTabs(l)),l.includes("device")&&(this.$deviceSource=this.renderDropzone(),s.appendChild(this.$deviceSource)),l.includes("url")&&(this.$urlSource=this.renderUrlSource(),s.appendChild(this.$urlSource)),this.activateSource((U=l[0])!=null?U:"device"),this.$list=m("div","us-file-list"),s.appendChild(this.$list),t.appendChild(s);let d=this.opts.autoUpload===!0,c=m("div","us-actions");this.$summary=m("div","us-actions-summary",""),this.$summary.setAttribute("role","status"),this.$summary.setAttribute("aria-live","polite"),c.appendChild(this.$summary);let p=m("div","us-actions-buttons");if(this.$cancel=document.createElement("button"),this.$cancel.type="button",this.$cancel.className="us-btn",this.$cancel.textContent="Cancel",this.$cancel.onclick=()=>this.cancel(),p.appendChild(this.$cancel),d||(this.$confirm=document.createElement("button"),this.$confirm.type="button",this.$confirm.className="us-btn us-btn-primary",this.$confirm.innerHTML=`${v.upload} <span>Upload</span>`,this.$confirm.disabled=!0,this.$confirm.onclick=()=>this.startUpload(),p.appendChild(this.$confirm)),c.appendChild(p),t.appendChild(c),!((T=this.opts.branding)!=null&&T.hideFooter)){let f=m("div","us-footer");f.innerHTML=`${v.zap} <span>Powered by <a href="${Ne}" target="_blank" rel="noopener">UnionStack</a></span>`,t.appendChild(f)}e.appendChild(t),((x=this.opts.container)!=null?x:document.body).appendChild(e),this.$backdrop=e,((k=t.querySelector('.us-source-tab[data-active="true"]'))!=null?k:t).focus()}trapFocus(e){if(!this.$panel)return;let t=Array.from(this.$panel.querySelectorAll(_e)).filter(a=>!a.hasAttribute("disabled")&&a.offsetParent!==null);if(t.length===0)return;let i=t[0],r=t[t.length-1],n=document.activeElement;e.shiftKey&&n===i?(e.preventDefault(),r.focus()):!e.shiftKey&&n===r&&(e.preventDefault(),i.focus())}resolvedSources(){let e=this.opts.fromSources;return!e||e.length===0?["device","url"]:e}renderSourceTabs(e){let t=m("div","us-source-tabs");return t.setAttribute("role","tablist"),t.setAttribute("aria-label","Upload source"),e.forEach((i,r)=>{let n=document.createElement("button");n.type="button",n.className="us-source-tab",n.setAttribute("role","tab"),n.setAttribute("aria-selected","false"),n.tabIndex=-1,n.dataset.source=i,n.innerHTML=i==="device"?`${v.device} <span>My Device</span>`:`${v.link} <span>Link</span>`,n.onclick=()=>this.activateSource(i),n.onkeydown=a=>this.onTabKeydown(a,e,r),t.appendChild(n)}),t}onTabKeydown(e,t,i){var n,a;let r=i;if(e.key==="ArrowRight"||e.key==="ArrowDown")r=(i+1)%t.length;else if(e.key==="ArrowLeft"||e.key==="ArrowUp")r=(i-1+t.length)%t.length;else if(e.key==="Home")r=0;else if(e.key==="End")r=t.length-1;else return;e.preventDefault(),this.activateSource(t[r]),(a=(n=this.$panel)==null?void 0:n.querySelector(`.us-source-tab[data-source="${t[r]}"]`))==null||a.focus()}activateSource(e){var i;if(this.$deviceSource){let r=e==="device";this.$deviceSource.style.display=r?"":"none"}this.$urlSource&&(this.$urlSource.dataset.active=e==="url"?"true":"false");let t=(i=this.$panel)==null?void 0:i.querySelectorAll(".us-source-tab");t==null||t.forEach(r=>{let n=r.dataset.source===e;r.dataset.active=n?"true":"false",r.setAttribute("aria-selected",n?"true":"false"),r.tabIndex=n?0:-1})}renderUrlSource(){let e=m("div","us-url-source"),t=m("div","us-url-form"),i=document.createElement("input");i.type="url",i.className="us-url-input",i.placeholder="https://example.com/photo.jpg",i.setAttribute("aria-label","File URL"),i.onkeydown=a=>{a.key==="Enter"&&(a.preventDefault(),this.handleUrlAdd())},this.$urlInput=i;let r=document.createElement("button");r.type="button",r.className="us-btn us-btn-primary",r.textContent="Add file",r.onclick=()=>this.handleUrlAdd(),this.$urlAddBtn=r,t.appendChild(i),t.appendChild(r),e.appendChild(t);let n=m("div","us-url-hint","Paste a direct file URL. The host must allow CORS so we can fetch it from the browser.");return this.$urlHint=n,e.appendChild(n),e}async handleUrlAdd(){if(!this.$urlInput||!this.$urlAddBtn||!this.$urlHint)return;let e=this.$urlInput.value.trim();if(!e){this.setUrlHint("Enter a URL first.",!0);return}if(!/^https?:\/\//i.test(e)){this.setUrlHint("URL must start with http:// or https://",!0);return}this.$urlAddBtn.disabled=!0;let t=this.$urlAddBtn.textContent;this.$urlAddBtn.textContent="Fetching\u2026",this.setUrlHint("Downloading\u2026",!1);try{let i=await qe(e);this.addFiles([i]),this.$urlInput.value="",this.setUrlHint("Paste a direct file URL. The host must allow CORS so we can fetch it from the browser.",!1)}catch(i){let r=i.message||"Failed to fetch URL";this.setUrlHint(r,!0)}finally{this.$urlAddBtn.disabled=!1,this.$urlAddBtn.textContent=t||"Add file"}}setUrlHint(e,t){this.$urlHint&&(this.$urlHint.textContent=e,this.$urlHint.dataset.error=t?"true":"false")}renderDropzone(){var a;let e=m("div","us-dropzone");e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label","Drop files here or click to browse");let t=m("div","us-dropzone-icon");t.innerHTML=v.fileUp,e.appendChild(t),e.appendChild(m("div","us-dropzone-title","Drop files to upload")),e.appendChild(m("div","us-dropzone-hint","or click to browse from your device"));let i=[];if(this.opts.maxFileSize&&i.push(`max ${H(this.opts.maxFileSize)}`),this.acceptStr){let s=[],l=new Set;for(let d of this.acceptStr.split(",")){let c=d.trim();if(!c||c==="*/*")continue;let p=We(c);p&&!l.has(p)&&(l.add(p),s.push(p))}s.length>0&&i.push(s.length>5?`${s.slice(0,5).join(", ")} +${s.length-5}`:s.join(", "))}i.length>0&&e.appendChild(m("div","us-dropzone-constraints",i.join(" \xB7 ")));let r=document.createElement("input");r.type="file",r.multiple=((a=this.opts.maxFiles)!=null?a:10)>1,this.acceptStr&&(r.accept=this.acceptStr),r.style.display="none",r.onchange=()=>{r.files&&this.addFiles(Array.from(r.files)),r.value=""},this.$input=r,e.appendChild(r),e.onclick=()=>r.click(),e.onkeydown=s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),r.click())};let n=0;return e.addEventListener("dragenter",s=>{s.preventDefault(),n++,e.setAttribute("data-drag","over")}),e.addEventListener("dragover",s=>s.preventDefault()),e.addEventListener("dragleave",()=>{n=Math.max(0,n-1),n===0&&e.removeAttribute("data-drag")}),e.addEventListener("drop",s=>{var d;s.preventDefault(),n=0,e.removeAttribute("data-drag");let l=(d=s.dataTransfer)==null?void 0:d.files;l&&this.addFiles(Array.from(l))}),e}unmount(){var e,t,i,r,n;this.editor&&(this.editor.close(),this.editor=null),this.noticeTimer&&(clearTimeout(this.noticeTimer),this.noticeTimer=null),(e=this.$backdrop)!=null&&e.parentNode&&this.$backdrop.parentNode.removeChild(this.$backdrop),this.$backdrop=null,this.$panel=null;for(let a of this.items)a.objectUrl&&URL.revokeObjectURL(a.objectUrl);(i=(t=this.previouslyFocused)==null?void 0:t.focus)==null||i.call(t),this.previouslyFocused=null,(n=(r=this.opts).onClose)==null||n.call(r)}fileMatchesAccept(e){let t=this.acceptStr.split(",").map(n=>n.trim().toLowerCase()).filter(Boolean);if(t.length===0||t.includes("*/*"))return!0;let i=(e.type||"").toLowerCase(),r=e.name.toLowerCase();return t.some(n=>n.startsWith(".")?r.endsWith(n):n.endsWith("/*")?i.startsWith(n.slice(0,-1)):i===n)}addFiles(e){var p;let t=(p=this.opts.maxFiles)!=null?p:1/0,i=0,r=e.filter(h=>this.fileMatchesAccept(h)?!0:(i++,!1)),n=t-this.items.length,a=n>0?r.slice(0,n):[],s=r.length-a.length,l=[];i>0&&l.push(`${i} file${i>1?"s":""} skipped \u2014 unsupported type`),s>0&&l.push(`${s} file${s>1?"s":""} skipped \u2014 max ${t} allowed`),l.length&&this.flashNotice(l.join(" \xB7 "));for(let h of a){if(this.opts.maxFileSize&&h.size>this.opts.maxFileSize){let y={uploadId:J(),file:h,originalFile:h,edited:!1,state:"failed",progress:0,error:`File exceeds ${H(this.opts.maxFileSize)} limit`};this.items.push(y),this.renderItem(y);continue}let u={uploadId:J(),file:h,originalFile:h,edited:!1,state:"queued",progress:0};this.items.push(u),this.renderItem(u)}this.refreshConfirm();let d=this.opts.autoUpload===!0,c=this.items.some(h=>h.state==="queued");d&&c&&!this.uploadStarted&&requestAnimationFrame(()=>{this.uploadStarted||this.startUpload()})}renderItem(e){if(!this.$list)return;let t=m("div","us-file");t.dataset.state=e.state,t.dataset.uploadId=e.uploadId;let i=Math.min(this.items.length-1,8);t.style.animationDelay=`${i*35}ms`;let r=m("div","us-file-thumb");if(e.file.type.startsWith("image/")&&typeof URL!="undefined"&&URL.createObjectURL)try{let u=URL.createObjectURL(e.file);e.objectUrl=u,r.style.backgroundImage=`url("${u}")`,r.dataset.image="true"}catch(u){r.innerHTML=V(e.file.type)}else r.innerHTML=V(e.file.type);t.appendChild(r);let n=m("div","us-file-main"),a=m("div","us-file-row1");a.appendChild(m("div","us-file-name",e.file.name));let s=m("div","us-file-meta",H(e.file.size));a.appendChild(s),n.appendChild(a);let l=m("div","us-file-progress"),d=m("div","us-file-progress-bar");l.appendChild(d),n.appendChild(l),t.appendChild(n);let c=e.file.type.startsWith("image/"),p=this.opts.imageEditing!==!1;if(c&&p&&e.state==="queued"){let u=document.createElement("button");u.type="button",u.className="us-file-action",u.setAttribute("aria-label","Edit image"),u.title="Edit image",u.innerHTML=v.pencil,u.dataset.edited=e.edited?"true":"false",u.onclick=()=>this.openEditor(e),t.appendChild(u),e.$edit=u}let h=m("div","us-file-status");h.setAttribute("aria-label",this.statusLabel(e)),h.innerHTML=this.statusIcon(e.state),t.appendChild(h),e.$row=t,e.$bar=d,e.$status=h,e.$meta=s,e.$thumb=r,this.$list.appendChild(t),this.updateSummary()}replaceItemFile(e,t,i){if(e.file=t,e.edited=i,e.objectUrl&&URL.revokeObjectURL(e.objectUrl),e.objectUrl=void 0,e.$thumb)if(e.$thumb.style.backgroundImage="",e.$thumb.removeAttribute("data-image"),t.type.startsWith("image/")&&typeof URL!="undefined"&&URL.createObjectURL)try{let r=URL.createObjectURL(t);e.objectUrl=r,e.$thumb.style.backgroundImage=`url("${r}")`,e.$thumb.dataset.image="true",e.$thumb.innerHTML=""}catch(r){e.$thumb.innerHTML=V(t.type)}else e.$thumb.innerHTML=V(t.type);if(e.$meta&&(e.$meta.textContent=H(t.size)),e.$row){let r=e.$row.querySelector(".us-file-name");r&&(r.textContent=t.name)}e.$edit&&(e.$edit.dataset.edited=i?"true":"false")}openEditor(e){!this.$panel||this.editor||e.state!=="queued"||(this.editor=new q({host:this.$panel,file:e.file,originalFile:e.originalFile,title:e.originalFile.name,onApply:t=>{let i=t!==e.originalFile;this.replaceItemFile(e,t,i),this.editor=null},onCancel:()=>{this.editor=null}}),this.editor.open())}statusIcon(e){switch(e){case"uploading":return v.spinner;case"done":return v.check;case"failed":return v.alert;case"cancelled":return v.alert;default:return v.clock}}statusLabel(e){switch(e.state){case"queued":return"Waiting to upload";case"uploading":return`Uploading ${Math.round(e.progress)} percent`;case"done":return"Upload complete";case"failed":return e.error?`Failed: ${e.error}`:"Upload failed";case"cancelled":return"Cancelled"}}setItemState(e,t,i){if(e.state=t,i!==void 0&&(e.progress=i),e.$row&&(e.$row.dataset.state=t),e.$bar&&(e.$bar.style.width=`${e.progress}%`),e.$status&&(e.$status.innerHTML=this.statusIcon(t),e.$status.setAttribute("aria-label",this.statusLabel(e))),e.$meta){let r=H(e.file.size);switch(t){case"uploading":e.$meta.textContent=`${r} \xB7 ${Math.round(e.progress)}%`;break;case"done":e.$meta.textContent=r;break;case"failed":e.$meta.textContent=e.error||"Failed";break;default:e.$meta.textContent=r}}this.updateSummary()}updateSummary(){if(!this.$summary)return;let e=this.items.length;if(e===0){this.$summary.textContent="";return}let t=this.items.filter(n=>n.state==="done").length,i=this.items.filter(n=>n.state==="failed").length,r=this.items.filter(n=>n.state==="uploading"||n.state==="queued").length;if(!this.uploadStarted&&r>0){let n=this.items.filter(a=>a.state==="queued").length;this.$summary.textContent=`${n} file${n===1?"":"s"} ready`}else r>0?this.$summary.textContent=`Uploading ${t+1} of ${e}`:i>0?this.$summary.textContent=`${t} of ${e} uploaded \xB7 ${i} failed`:t===e?this.$summary.textContent=`${e} file${e===1?"":"s"} uploaded`:this.$summary.textContent=`${e} file${e===1?"":"s"} ready`}refreshConfirm(){if(!this.$confirm)return;let e=this.items.filter(t=>t.state==="queued").length;this.$confirm.disabled=e===0||this.uploadStarted}flashNotice(e){this.$summary&&(this.$summary.textContent=e,this.$summary.dataset.tone="warn",this.noticeTimer&&clearTimeout(this.noticeTimer),this.noticeTimer=setTimeout(()=>{this.$summary&&(this.$summary.textContent="",delete this.$summary.dataset.tone),this.noticeTimer=null},4e3))}async startUpload(){if(this.uploadStarted)return;let e=this.items.filter(r=>r.state==="queued");if(e.length===0)return;this.uploadStarted=!0,this.$confirm&&(this.$confirm.disabled=!0,this.$confirm.textContent="Uploading\u2026"),this.$cancel&&(this.$cancel.textContent="Stop"),this.$closeBtn&&(this.$closeBtn.disabled=!0),this.$input&&(this.$input.disabled=!0);let t=new Map,i=e.map(r=>r.file);try{await this.client.uploadMany(i,I(C({},this.opts),{signal:this.abortCtrl.signal,onUploadStarted:r=>{var n,a;r.forEach((s,l)=>{let d=e[l];d&&(d.uploadId=s.uploadId,d.$row&&(d.$row.dataset.uploadId=s.uploadId),t.set(s.uploadId,d))}),(a=(n=this.opts).onUploadStarted)==null||a.call(n,r)},onFileUploadStarted:r=>{var a,s;let n=t.get(r.uploadId);n&&this.setItemState(n,"uploading",0),(s=(a=this.opts).onFileUploadStarted)==null||s.call(a,r)},onFileUploadProgress:(r,n)=>{var s,l;let a=t.get(r.uploadId);a&&this.setItemState(a,"uploading",n.totalPercent),(l=(s=this.opts).onFileUploadProgress)==null||l.call(s,r,n)},onFileUploadFinished:r=>{var a,s;let n=t.get(r.uploadId);n&&(n.uploaded=r,this.setItemState(n,"done",100)),(s=(a=this.opts).onFileUploadFinished)==null||s.call(a,r)},onFileUploadFailed:(r,n)=>{var s,l;let a=t.get(r.uploadId);a&&(a.error=n.message,this.setItemState(a,"failed")),(l=(s=this.opts).onFileUploadFailed)==null||l.call(s,r,n)},onUploadDone:r=>{var n,a;(a=(n=this.opts).onUploadDone)==null||a.call(n,r),this.resolveResult(r),this.unmount()},onError:r=>{var n,a;(a=(n=this.opts).onError)==null||a.call(n,r),this.resolveResult(),this.unmount()}}))}catch(r){this.resolved||(this.resolveResult(),this.unmount())}}resolveResult(e){if(this.resolved)return;this.resolved=!0;let t=e!=null?e:{filesUploaded:this.items.filter(i=>i.uploaded).map(i=>i.uploaded),filesFailed:this.items.filter(i=>i.state==="failed").map(i=>({file:{uploadId:i.uploadId,filename:i.file.name,mimetype:i.file.type||"application/octet-stream",size:i.file.size,source:"local"},error:{code:"VALIDATION",message:i.error||"failed",retryable:!1}}))};this.resolvePromise(t)}};ve={"application/pdf":"PDF","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","application/vnd.ms-powerpoint":"PPT","application/vnd.openxmlformats-officedocument.presentationml.presentation":"PPTX","application/zip":"ZIP","application/json":"JSON","application/rtf":"RTF","text/plain":"TXT","text/csv":"CSV","text/html":"HTML","text/markdown":"MD","image/jpeg":"JPG","image/png":"PNG","image/gif":"GIF","image/webp":"WEBP","image/svg+xml":"SVG","image/heic":"HEIC","video/mp4":"MP4","audio/mpeg":"MP3"},Ke={image:"Images",video:"Video",audio:"Audio",text:"Text",font:"Fonts"}});var ye={};ie(ye,{Picker:()=>F,openPicker:()=>X});var Q=_(()=>{"use strict";be()});var Ze={};ie(Ze,{Picker:()=>F,UnionStackClient:()=>A,init:()=>Qe,openPicker:()=>X});function g(o,e,t={}){var i;return{code:o,message:e,status:t.status,retryable:(i=t.retryable)!=null?i:Pe(o,t.status),cause:t.cause}}function Pe(o,e){return!!(o==="NETWORK"||o==="PART_FAILED"||o==="SERVER"&&e&&e>=500)}function oe(o,e){let t=e==null?void 0:e.error,i=(t==null?void 0:t.message)||`Request failed with status ${o}`,r=((t==null?void 0:t.code)||"").toUpperCase();if(o===401)return g("AUTH",i,{status:o,retryable:!1});if(o===403)return g("AUTH",i,{status:o,retryable:!1});if(o===413)return g("VALIDATION",i,{status:o,retryable:!1});if(o===415)return g("VALIDATION",i,{status:o,retryable:!1});if(o===426)return g("CONFIG",i,{status:o,retryable:!1});if(o===429){let n=r==="QUOTA_EXCEEDED";return g(n?"QUOTA":"NETWORK",i,{status:o,retryable:!n})}return o>=500?g("SERVER",i,{status:o,retryable:!0}):g("SERVER",i,{status:o,retryable:!1})}var ne="0.3.9",se=`js/${ne}`,it=`node/${ne}`;var Se=3,Me=3,ae=[400,1200,3600],K=class{constructor(e){this.cfg=e}describe(e,t={}){let i=typeof File!="undefined"&&e instanceof File,r=t.filename||(i?e.name:"untitled"),n=t.mimeType||e.type||"application/octet-stream";return{uploadId:Re(),filename:r,mimetype:n,size:e.size,source:"local"}}async upload(e,t={}){var r,n,a;let i=this.describe(e,{filename:t.filename,mimeType:t.mimeType});(r=t.onFileUploadStarted)==null||r.call(t,i);try{let s=await this.initUpload(i,t),l=await this.uploadAllParts(e,s,i,t),d=await this.completeUpload(s.sessionId,l,t),c=I(C({},i),{handle:d.handle,fileId:d.fileId,url:d.url,size:d.size,mimetype:d.mimetype,filename:d.filename,key:d.key,container:d.container,status:"Stored",etag:d.etag,metadata:d.metadata});return(n=t.onFileUploadFinished)==null||n.call(t,c),c}catch(s){let l=le(s);throw(a=t.onFileUploadFailed)==null||a.call(t,i,l),s!=null&&s.sessionId&&this.abortSilently(s.sessionId).catch(()=>{}),l}}async abort(e){await this.api("POST","/sdk/v1/uploads/abort",{sessionId:e})}async fetchPickerConfig(){return this.api("GET","/sdk/v1/picker-config")}async initUpload(e,t){return this.api("POST","/sdk/v1/uploads/init",{filename:e.filename,mimeType:e.mimetype,size:e.size,metadata:t.metadata},t.signal)}async uploadAllParts(e,t,i,r){var U,T;let n=t.totalParts,a=t.chunkSize,s=Math.max(1,(U=r.concurrency)!=null?U:Se),l=(T=r.maxRetriesPerPart)!=null?T:Me,d=new Map(t.partUrls.map(x=>[x.partNumber,x.url])),c=new Array(n),p=new Array(n).fill(0),h=1,u=e.size,y=()=>{var w;let x=p.reduce((R,b)=>R+b,0),k=u>0?Math.min(100,Math.round(x/u*100)):100,f={totalBytes:u,loaded:x,totalPercent:k};(w=r.onFileUploadProgress)==null||w.call(r,i,f)},S=async()=>{var x,k,f,w,R;for(;;){if((x=r.signal)!=null&&x.aborted)throw g("ABORTED","Upload aborted by caller.",{retryable:!1});let b=h++;if(b>n)return;let z=(b-1)*a,G=Math.min(z+a,e.size),j=e.slice(z,G),O=0,D;for(;O<=l;){if((k=r.signal)!=null&&k.aborted)throw g("ABORTED","Upload aborted by caller.",{retryable:!1});try{let L=d.get(b);L||(L=(await this.api("POST","/sdk/v1/uploads/sign-part",{sessionId:t.sessionId,partNumber:b},r.signal)).url,d.set(b,L));let B=(R=await((w=(f=this.cfg).fetch)==null?void 0:w.call(f,L,{method:"PUT",body:j,signal:r.signal})))!=null?R:await fetch(L,{method:"PUT",body:j,signal:r.signal});if(!B.ok)throw(B.status===403||B.status===401)&&d.delete(b),g("PART_FAILED",`Part ${b} PUT failed (HTTP ${B.status})`,{status:B.status});let Z=B.headers.get("etag");if(!Z)throw g("PART_FAILED",`Part ${b}: R2 did not return an ETag.`);c[b-1]={partNumber:b,etag:Z,size:j.size},p[b-1]=j.size,y();break}catch(L){if(D=L,O++,O>l)break;await Le(ae[Math.min(O-1,ae.length-1)])}}if(!c[b-1])throw Ie(le(D!=null?D:g("PART_FAILED",`Part ${b} failed after ${l} retries.`)),t.sessionId)}},M=Array.from({length:Math.min(s,n)},S);return await Promise.all(M),c}async completeUpload(e,t,i){return this.api("POST","/sdk/v1/uploads/complete",{sessionId:e,parts:t.map(r=>({partNumber:r.partNumber,etag:r.etag}))},i.signal)}async abortSilently(e){try{await this.abort(e)}catch(t){}}async api(e,t,i,r){var d,c;let n=(d=this.cfg.fetch)!=null?d:fetch,a=`${this.cfg.apiBase}${t}`,s;try{s=await n(a,{method:e,headers:{Authorization:`Bearer ${this.cfg.apiKey}`,"Content-Type":"application/json","X-UnionStack-SDK":(c=this.cfg.sdkHeader)!=null?c:se},body:i===void 0?void 0:JSON.stringify(i),signal:r})}catch(p){throw(p==null?void 0:p.name)==="AbortError"?g("ABORTED","Request aborted.",{retryable:!1,cause:p}):g("NETWORK","Network request failed.",{retryable:!0,cause:p})}let l=null;try{l=await s.json()}catch(p){}if(!s.ok)throw oe(s.status,l);return l}};function Re(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,""):Math.random().toString(36).slice(2)+Date.now().toString(36)}function Le(o){return new Promise(e=>setTimeout(e,o))}function le(o){if(o&&typeof o=="object"&&"code"in o&&"message"in o&&"retryable"in o)return o;let e=(o==null?void 0:o.message)||"Upload failed.";return g("NETWORK",e,{cause:o})}function Ie(o,e){return o&&typeof o=="object"&&(o.sessionId=e),o}var Ge="https://api.unionstack.link/v1",xe="unionstack-preloader-styles";function Je(){if(typeof document=="undefined")return()=>{};if(!document.getElementById(xe)){let i=document.createElement("style");i.id=xe,i.textContent="@keyframes us-preload-spin{to{transform:rotate(360deg)}}@keyframes us-preload-fade{from{opacity:0}to{opacity:1}}",document.head.appendChild(i)}let o=document.createElement("div");o.setAttribute("role","status"),o.setAttribute("aria-label","Loading file picker"),o.style.cssText="position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;background:rgba(2,6,23,0.4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);animation:us-preload-fade 140ms ease-out;";let e=document.createElement("div");e.style.cssText="width:36px;height:36px;border-radius:50%;border:3px solid rgba(220,225,251,0.25);border-top-color:#c0c1ff;animation:us-preload-spin 0.8s linear infinite;",o.appendChild(e),document.body.appendChild(o);let t=!1;return()=>{t||(t=!0,o.remove())}}var A=class{constructor(e){e.apiKey||console.error("[UnionStack] apiKey is not set. Uploads and the picker are disabled until a valid apiKey is provided."),this.resolvedCfg=I(C({},e),{apiBase:Ge}),this.uploader=new K(this.resolvedCfg),this.pickerConfigPromise=!e.apiKey||this.resolvedCfg.skipConfigPrefetch?Promise.resolve(null):this.uploader.fetchPickerConfig().then(t=>(t!=null&&t.sdkWarning&&console.warn(`[UnionStack] ${t.sdkWarning}`),t)).catch(()=>null)}missingKeyError(){return this.resolvedCfg.apiKey?null:g("CONFIG","apiKey is required.",{retryable:!1})}upload(e,t={}){let i=this.missingKeyError();return i?Promise.reject(i):this.uploader.upload(e,t)}async uploadMany(e,t={}){var l,d,c,p;let i=this.missingKeyError();if(i)throw(l=t.onError)==null||l.call(t,i),i;if(!Array.isArray(e)||e.length===0){let h=g("VALIDATION","uploadMany requires a non-empty array of files.",{retryable:!1});throw(d=t.onError)==null||d.call(t,h),h}let r=e.map(h=>this.uploader.describe(h,{filename:t.filename,mimeType:t.mimeType}));(c=t.onUploadStarted)==null||c.call(t,r);let n=[],a=[];await Promise.all(e.map(async(h,u)=>{try{let y=await this.uploader.upload(h,t);y.uploadId=r[u].uploadId,n.push(y)}catch(y){a.push({file:r[u],error:y})}}));let s={filesUploaded:n,filesFailed:a};return(p=t.onUploadDone)==null||p.call(t,s),s}picker(e={}){let t=null,i=!1,r,n,a=new Promise((s,l)=>{r=s,n=l});return{open:async()=>{if(i)return a;let s=this.missingKeyError();if(s)throw n(s),s;i=!0;let l=Je();try{t=(await Promise.resolve().then(()=>(Q(),ye))).openPicker(this,I(C({},e),{onOpen:()=>{var p;l(),(p=e.onOpen)==null||p.call(e)}}));let c=await t.open();return l(),r(c),c}catch(d){l();let c=d!=null&&d.code?d:g("CONFIG","Failed to load picker.",{retryable:!1,cause:d});throw n(c),c}},close:()=>{t==null||t.close()},cancel:()=>{t==null||t.cancel()}}}get config(){return this.resolvedCfg}};var Y={init(o){return new A(o)}};Q();var Qe=Y.init.bind(Y);(function(){if(typeof document=="undefined")return;let e=document.currentScript;if(!e)return;let t=e.getAttribute("data-unionstack-key");if(t)try{let i=Y.init({apiKey:t});queueMicrotask(()=>{window.UnionStack&&(window.UnionStack.client=i)})}catch(i){console.error("[UnionStack] auto-init failed:",i)}})();return Te(Ze);})();
511
+ `});function P(o,e,t){let i=document.createElement(o);return e&&(i.className=e),t!==void 0&&(i.textContent=t),i}function V(o,e){let t=document.createElement("button");return t.type="button",t.className="us-tool",t.innerHTML=`${e} <span>${_e(o)}</span>`,t}function _e(o){return o.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e])}function $(o,e,t){return Math.max(e,Math.min(t,o))}function ve(o){return new Promise((e,t)=>{let i=URL.createObjectURL(o),r=new Image;r.onload=()=>{URL.revokeObjectURL(i),e(r)},r.onerror=()=>{URL.revokeObjectURL(i),t(new Error("decode failed"))},r.src=i})}function be(o){return/^image\/(png|webp|gif)$/.test(o)}var I,X,ye=K(()=>{"use strict";I={back:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 18 9 12 15 6"/></svg>',crop:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></svg>',circle:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/></svg>',rotate:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.82.93 6.58 2.46L21 8"/><path d="M21 3v5h-5"/></svg>',undo:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-15-6.7L3 13"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'},X=class{constructor(e){this.opts=e;this.cropBox=null;this.displayScale=1;this.hasAlpha=!1;this.mode="none";this.cropRect=null;this.dragKind=null;this.dragStart=null;this.onPointerMove=e=>{if(!this.dragKind||!this.dragStart||!this.cropRect)return;let t=e.clientX-this.dragStart.px,i=e.clientY-this.dragStart.py,r=this.dragStart.rect,n=this.displayCanvas.width,a=this.displayCanvas.height,s=24;if(this.aspect&&this.dragKind!=="move"){switch(this.dragKind){case"se":this.cropRect=this.lockedRectFromDrag(r.x,r.y,r.w+t,1,1);break;case"nw":{let u=r.x+r.w,h=r.y+r.h;this.cropRect=this.lockedRectFromDrag(u,h,u-(r.x+t),-1,-1);break}case"ne":{let u=r.y+r.h;this.cropRect=this.lockedRectFromDrag(r.x,u,r.w+t,1,-1);break}case"sw":{let u=r.x+r.w;this.cropRect=this.lockedRectFromDrag(u,r.y,u-(r.x+t),-1,1);break}}this.updateCropBox();return}let{x:d,y:l,w:c,h:p}=r;switch(this.dragKind){case"move":d=$(r.x+t,0,n-r.w),l=$(r.y+i,0,a-r.h);break;case"nw":{let u=$(r.x+t,0,r.x+r.w-s),h=$(r.y+i,0,r.y+r.h-s);c=r.w+(r.x-u),p=r.h+(r.y-h),d=u,l=h;break}case"ne":{let u=$(r.w+t,s,n-r.x),h=$(r.y+i,0,r.y+r.h-s);p=r.h+(r.y-h),c=u,l=h;break}case"sw":{let u=$(r.x+t,0,r.x+r.w-s),h=$(r.h+i,s,a-r.y);c=r.w+(r.x-u),p=h,d=u;break}case"se":c=$(r.w+t,s,n-r.x),p=$(r.h+i,s,a-r.y);break}this.cropRect={x:d,y:l,w:c,h:p},this.updateCropBox()};this.onPointerUp=()=>{this.dragKind=null,this.dragStart=null,document.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp)}}get aspect(){let e=this.opts.lockedAspect;return e&&e.width>0&&e.height>0?e.width/e.height:null}async open(){this.mount();try{await this.loadOriginalIntoWorking(),this.opts.originalFile&&this.opts.originalFile!==this.opts.file&&this.markEdited(!0),this.draw()}catch(e){this.canvasWrap.textContent=`Couldn't load image: ${e.message}`}}close(){document.removeEventListener("pointermove",this.onPointerMove),document.removeEventListener("pointerup",this.onPointerUp),this.root.remove()}mount(){this.root=P("div","us-editor");let e=P("div","us-editor-header"),t=document.createElement("button");t.type="button",t.className="us-editor-back",t.setAttribute("aria-label","Back"),t.innerHTML=I.back,t.onclick=()=>{this.opts.onCancel(),this.close()},e.appendChild(t),e.appendChild(P("div","us-editor-title",this.opts.title)),this.root.appendChild(e),this.canvasWrap=P("div","us-editor-canvas-wrap"),this.displayCanvas=document.createElement("canvas"),this.displayCanvas.className="us-editor-canvas",this.canvasWrap.appendChild(this.displayCanvas),this.root.appendChild(this.canvasWrap);let i=P("div","us-editor-toolbar");this.cropTool=V("Crop",I.crop),this.cropTool.onclick=()=>this.toggleCropMode(),this.circleTool=V("Circle",I.circle),this.circleTool.onclick=()=>this.applyCircle(),this.rotateTool=V("Rotate 90\xB0",I.rotate),this.rotateTool.onclick=()=>this.applyRotate(),this.revertTool=V("Revert",I.undo),this.revertTool.onclick=()=>this.revert(),this.revertTool.disabled=!0,i.appendChild(this.cropTool),i.appendChild(this.circleTool),i.appendChild(this.rotateTool),i.appendChild(P("div","us-tool-spacer")),i.appendChild(this.revertTool),this.root.appendChild(i);let r=P("div","us-editor-footer"),n=document.createElement("button");n.type="button",n.className="us-btn",n.textContent="Cancel",n.onclick=()=>{this.opts.onCancel(),this.close()},this.applyBtn=document.createElement("button"),this.applyBtn.type="button",this.applyBtn.className="us-btn us-btn-primary",this.applyBtn.innerHTML=`${I.check} <span>Apply</span>`,this.applyBtn.onclick=()=>this.applyAndClose(),r.appendChild(n),r.appendChild(this.applyBtn),this.root.appendChild(r),this.opts.host.appendChild(this.root)}async loadOriginalIntoWorking(){let e=await ve(this.opts.file),t=document.createElement("canvas");t.width=e.naturalWidth,t.height=e.naturalHeight;let i=t.getContext("2d");if(!i)throw new Error("Canvas 2D context unavailable");i.drawImage(e,0,0),this.working=t,this.hasAlpha=be(this.opts.file.type),this.markEdited(!1)}async loadTrueOriginalIntoWorking(){var n;let e=(n=this.opts.originalFile)!=null?n:this.opts.file,t=await ve(e),i=document.createElement("canvas");i.width=t.naturalWidth,i.height=t.naturalHeight;let r=i.getContext("2d");if(!r)throw new Error("Canvas 2D context unavailable");r.drawImage(t,0,0),this.working=i,this.hasAlpha=be(e.type),this.markEdited(!1)}draw(){let{width:e,height:t}=this.working,i=Math.min(1,720/Math.max(e,t)),r=Math.max(1,Math.round(e*i)),n=Math.max(1,Math.round(t*i));this.displayCanvas.width=r,this.displayCanvas.height=n,this.displayScale=i;let a=this.displayCanvas.getContext("2d");a&&(a.clearRect(0,0,r,n),a.drawImage(this.working,0,0,r,n),this.updateCropBox())}toggleCropMode(){this.mode==="crop"?this.applyCrop():this.enterCropMode()}enterCropMode(){this.mode="crop",this.cropTool.dataset.active="true",this.cropTool.innerHTML=`${I.check} <span>Apply crop</span>`;let e=this.displayCanvas.width,t=this.displayCanvas.height;if(this.aspect){let i=e,r=i/this.aspect;r>t&&(r=t,i=r*this.aspect),i=Math.max(24,Math.round(i*.9)),r=Math.max(24,Math.round(i/this.aspect)),i>e&&(i=e,r=i/this.aspect),r>t&&(r=t,i=r*this.aspect),this.cropRect={x:Math.round((e-i)/2),y:Math.round((t-r)/2),w:i,h:r}}else{let i=Math.round(Math.min(e,t)*.1);this.cropRect={x:i,y:i,w:e-i*2,h:t-i*2}}this.renderCropBox()}exitCropMode(){this.mode="none",this.cropTool.removeAttribute("data-active"),this.cropTool.innerHTML=`${I.crop} <span>Crop</span>`,this.cropRect=null,this.cropBox&&(this.cropBox.remove(),this.cropBox=null)}renderCropBox(){if(!this.cropRect)return;this.cropBox&&this.cropBox.remove();let e=P("div","us-crop-box");for(let t of["nw","ne","sw","se"]){let i=P("div","us-crop-handle");i.dataset.pos=t,i.addEventListener("pointerdown",r=>this.beginDrag(r,t)),e.appendChild(i)}e.addEventListener("pointerdown",t=>{t.target.classList.contains("us-crop-handle")||this.beginDrag(t,"move")}),this.canvasWrap.appendChild(e),this.cropBox=e,this.updateCropBox()}updateCropBox(){if(!this.cropBox||!this.cropRect)return;let e=this.displayCanvas.getBoundingClientRect(),t=this.canvasWrap.getBoundingClientRect(),i=e.left-t.left+this.cropRect.x,r=e.top-t.top+this.cropRect.y;this.cropBox.style.left=`${i}px`,this.cropBox.style.top=`${r}px`,this.cropBox.style.width=`${this.cropRect.w}px`,this.cropBox.style.height=`${this.cropRect.h}px`}beginDrag(e,t){this.cropRect&&(e.preventDefault(),this.dragKind=t,this.dragStart={px:e.clientX,py:e.clientY,rect:E({},this.cropRect)},document.addEventListener("pointermove",this.onPointerMove),document.addEventListener("pointerup",this.onPointerUp))}lockedRectFromDrag(e,t,i,r,n){let a=this.aspect,s=this.displayCanvas.width,d=this.displayCanvas.height,l=Math.max(24,i),c=l/a;c<24&&(c=24,l=c*a);let p=r>0?s-e:e,u=n>0?d-t:t;l=Math.min(l,p,u*a),c=l/a;let h=r>0?e:e-l,y=n>0?t:t-c;return{x:h,y,w:l,h:c}}applyCrop(){var d,l;if(!this.cropRect){this.exitCropMode();return}let e=this.displayScale,t=Math.round(this.cropRect.x/e),i=Math.round(this.cropRect.y/e),r=Math.round(this.cropRect.w/e),n=Math.round(this.cropRect.h/e),a=document.createElement("canvas");a.width=r,a.height=n;let s=a.getContext("2d");s&&(s.drawImage(this.working,t,i,r,n,0,0,r,n),this.working=a,this.exitCropMode(),this.markEdited(!0),(l=(d=this.opts).onCropApplied)==null||l.call(d),this.draw())}applyRotate(){let{width:e,height:t}=this.working,i=document.createElement("canvas");i.width=t,i.height=e;let r=i.getContext("2d");r&&(r.translate(t,0),r.rotate(Math.PI/2),r.drawImage(this.working,0,0),this.working=i,this.exitCropMode(),this.markEdited(!0),this.draw())}applyCircle(){let{width:e,height:t}=this.working,i=Math.min(e,t),r=Math.round((e-i)/2),n=Math.round((t-i)/2),a=document.createElement("canvas");a.width=i,a.height=i;let s=a.getContext("2d");s&&(s.save(),s.beginPath(),s.arc(i/2,i/2,i/2,0,Math.PI*2),s.closePath(),s.clip(),s.drawImage(this.working,r,n,i,i,0,0,i,i),s.restore(),this.working=a,this.hasAlpha=!0,this.exitCropMode(),this.markEdited(!0),this.draw())}async revert(){await this.loadTrueOriginalIntoWorking(),this.exitCropMode(),this.draw()}markEdited(e){this.revertTool.disabled=!e}async applyAndClose(){this.applyBtn.disabled=!0;try{let e=await this.exportFile();this.opts.onApply(e),this.close()}catch(e){this.applyBtn.disabled=!1,console.error("[union-stack] image export failed",e)}}exportFile(){return new Promise((e,t)=>{let i=this.hasAlpha?"image/png":"image/jpeg",r=i==="image/jpeg"?.92:void 0;this.working.toBlob(n=>{if(!n)return t(new Error("toBlob returned null"));let a=this.opts.file.name.replace(/\.[^.]+$/,""),s=i==="image/png"?"png":"jpg";e(new File([n],`${a}-edited.${s}`,{type:i}))},i,r)})}}});function We(o,e){var s,d,l,c,p,u,h,y,M,S,R,T,x,k,f,w,L,b,D,_,F,A,B,C,U,N,Q,te;let t=E({},e),i=e.branding||{};t.branding={logoUrl:(d=(s=i.logoUrl)!=null?s:o.branding.logoUrl)!=null?d:void 0,title:(c=(l=i.title)!=null?l:o.branding.title)!=null?c:void 0,hideFooter:(p=i.hideFooter)!=null?p:o.branding.hideFooter};let r=e.theme||{};if(t.theme={primary:(h=(u=r.primary)!=null?u:o.theme.primary)!=null?h:void 0,background:(M=(y=r.background)!=null?y:o.theme.background)!=null?M:void 0,foreground:(R=(S=r.foreground)!=null?S:o.theme.foreground)!=null?R:void 0,border:(x=(T=r.border)!=null?T:o.theme.border)!=null?x:void 0,radius:(f=(k=r.radius)!=null?k:o.theme.radius)!=null?f:void 0,mode:(L=(w=r.mode)!=null?w:o.theme.mode)!=null?L:void 0},t.maxFileSize=(b=e.maxFileSize)!=null?b:o.constraints.maxFileSizeBytes,t.maxFiles=(D=e.maxFiles)!=null?D:o.constraints.maxFilesPerUpload,!e.accept&&((_=o.constraints.allowedMimeTypes)!=null&&_.length)){let re=o.constraints.allowedMimeTypes.filter(Ee=>Ee!=="*/*");re.length>0&&(t.accept=re.join(","))}let n=(F=o.image)!=null?F:null,a=(A=e.cropAspectRatio)!=null?A:n&&n.cropRatioW&&n.cropRatioH?{width:n.cropRatioW,height:n.cropRatioH}:void 0;return t.cropAspectRatio=a,t.forceCrop=((C=(B=e.forceCrop)!=null?B:n==null?void 0:n.forceCrop)!=null?C:!1)&&!!a&&e.imageEditing!==!1,t.minImageWidth=(N=(U=e.minImageWidth)!=null?U:n==null?void 0:n.minWidth)!=null?N:void 0,t.minImageHeight=(te=(Q=e.minImageHeight)!=null?Q:n==null?void 0:n.minHeight)!=null?te:void 0,t}function G(o){return o?o.startsWith("image/")?v.image:o.startsWith("video/")?v.video:o.startsWith("audio/")?v.audio:o==="application/pdf"?v.pdf:o.startsWith("application/zip")||o.includes("compressed")||o==="application/x-tar"||o==="application/gzip"?v.archive:v.file:v.file}function m(o,e,t){let i=document.createElement(o);return e&&(i.className=e),t!==void 0&&(i.textContent=t),i}function Ge(o){var i,r,n;let e=o.trim().toLowerCase();if(!e)return"";if(e.endsWith("/*")||!e.includes("/")){let a=e.replace("/*","");return(i=Xe[a])!=null?i:a.charAt(0).toUpperCase()+a.slice(1)}if(xe[e])return xe[e];if(e.startsWith("."))return e.slice(1).toUpperCase();let t=(r=e.split("/")[1])!=null?r:e;return((n=t.split("+")[0].split(".").pop())!=null?n:t).toUpperCase()}function O(o){return o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:o<1024*1024*1024?`${(o/1024/1024).toFixed(1)} MB`:`${(o/1024/1024/1024).toFixed(2)} GB`}function Z(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,""):Math.random().toString(36).slice(2)+Date.now().toString(36)}async function Ye(o){var e;if(typeof createImageBitmap=="function")try{let t=await createImageBitmap(o),i=t.width,r=t.height;return(e=t.close)==null||e.call(t),{w:i,h:r}}catch(t){}return new Promise((t,i)=>{if(typeof URL=="undefined"||!URL.createObjectURL){i(new Error("no object URL support"));return}let r=URL.createObjectURL(o),n=new Image;n.onload=()=>{URL.revokeObjectURL(r),t({w:n.naturalWidth,h:n.naturalHeight})},n.onerror=()=>{URL.revokeObjectURL(r),i(new Error("decode failed"))},n.src=r})}async function Je(o){let e;try{e=await fetch(o,{mode:"cors",credentials:"omit"})}catch(n){throw new Error(`Could not reach ${Qe(o)} \u2014 check the URL or CORS.`)}if(!e.ok)throw new Error(`Server returned ${e.status} \u2014 file unavailable.`);let t=await e.blob(),i=Ze(o)||"download",r=t.type||et(i);return new File([t],i,{type:r})}function Qe(o){try{return new URL(o).host}catch(e){return"that host"}}function Ze(o){try{let t=new URL(o).pathname.split("/").filter(Boolean).pop();return t?decodeURIComponent(t):""}catch(e){return""}}function et(o){let e=o.toLowerCase().split(".").pop()||"";return{jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",svg:"image/svg+xml",pdf:"application/pdf",mp4:"video/mp4",mov:"video/quicktime",mp3:"audio/mpeg",wav:"audio/wav",zip:"application/zip",json:"application/json",txt:"text/plain",csv:"text/csv"}[e]||"application/octet-stream"}function Y(o,e){let t=new H(o,e);return{open:()=>t.open(),close:()=>t.close(),cancel:()=>t.cancel()}}var Ke,qe,v,Ve,H,xe,Xe,ke=K(()=>{"use strict";ge();ye();Ke="Upload files",qe="https://unionstack.link",v={upload:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>',fileUp:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><path d="M12 18v-6"/><path d="m9 15 3-3 3 3"/></svg>',close:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',check:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>',alert:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',spinner:'<svg viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="9" stroke="currentColor" opacity="0.2"/><path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor"/></svg>',clock:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><polyline points="12 7.5 12 12 15 13.5"/></svg>',image:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/></svg>',video:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg>',audio:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>',pdf:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="9" y1="13" x2="15" y2="13"/><line x1="9" y1="17" x2="13" y2="17"/></svg>',archive:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="5" rx="2"/><path d="M4 9v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9"/><line x1="10" y1="13" x2="14" y2="13"/></svg>',file:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',zap:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>',device:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg>',link:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.72"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.72-1.72"/></svg>',pencil:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>'};Ve='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',H=class{constructor(e,t){this.client=e;this.opts=t;this.$backdrop=null;this.$panel=null;this.$list=null;this.$confirm=null;this.$cancel=null;this.$closeBtn=null;this.$input=null;this.$deviceSource=null;this.$urlSource=null;this.$urlInput=null;this.$urlHint=null;this.$urlAddBtn=null;this.items=[];this.editor=null;this.abortCtrl=new AbortController;this.uploadStarted=!1;this.resolved=!1;this.previouslyFocused=null;this.noticeTimer=null;this.$summary=null;this.donePromise=new Promise(i=>{this.resolvePromise=i})}async open(){var e,t;if(typeof document=="undefined")throw new Error("[union-stack] Picker requires a browser environment.");try{let i=await this.client.pickerConfigPromise;i&&(this.opts=We(i,this.opts))}catch(i){}return me(),this.mount(),(t=(e=this.opts).onOpen)==null||t.call(e),this.donePromise}close(){this.unmount(),this.resolved||this.resolveResult()}cancel(){var e,t;this.abortCtrl.abort(),(t=(e=this.opts).onCancel)==null||t.call(e),this.close()}get acceptStr(){let e=this.opts.accept;return Array.isArray(e)?e.join(","):e!=null?e:""}mount(){var h,y,M,S,R,T,x,k;this.previouslyFocused=(h=document.activeElement)!=null?h:null;let e=document.createElement("div");e.className="us-picker-backdrop",Object.entries(fe(this.opts.theme)).forEach(([f,w])=>{e.style.setProperty(f,w)}),e.addEventListener("click",f=>{f.target===e&&!this.uploadStarted&&this.cancel()});let t=m("div","us-picker");this.$panel=t;let i=`us-picker-title-${Z()}`;t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),t.setAttribute("aria-labelledby",i),t.tabIndex=-1,t.addEventListener("keydown",f=>{f.key==="Escape"&&!this.uploadStarted?(f.preventDefault(),this.cancel()):f.key==="Tab"&&this.trapFocus(f)});let r=m("div","us-picker-header"),n=m("div","us-picker-header-logo");if((y=this.opts.branding)!=null&&y.logoUrl){let f=document.createElement("img");f.src=this.opts.branding.logoUrl,f.alt="",n.appendChild(f)}else n.innerHTML=v.zap;r.appendChild(n);let a=m("div","us-picker-title",(S=(M=this.opts.branding)==null?void 0:M.title)!=null?S:Ke);a.id=i,r.appendChild(a),this.$closeBtn=document.createElement("button"),this.$closeBtn.type="button",this.$closeBtn.className="us-picker-close",this.$closeBtn.setAttribute("aria-label","Close"),this.$closeBtn.innerHTML=v.close,this.$closeBtn.onclick=()=>this.cancel(),r.appendChild(this.$closeBtn),t.appendChild(r);let s=m("div","us-picker-body"),d=this.resolvedSources();d.length>1&&s.appendChild(this.renderSourceTabs(d)),d.includes("device")&&(this.$deviceSource=this.renderDropzone(),s.appendChild(this.$deviceSource)),d.includes("url")&&(this.$urlSource=this.renderUrlSource(),s.appendChild(this.$urlSource)),this.activateSource((R=d[0])!=null?R:"device"),this.$list=m("div","us-file-list"),s.appendChild(this.$list),t.appendChild(s);let l=this.opts.autoUpload===!0,c=m("div","us-actions");this.$summary=m("div","us-actions-summary",""),this.$summary.setAttribute("role","status"),this.$summary.setAttribute("aria-live","polite"),c.appendChild(this.$summary);let p=m("div","us-actions-buttons");if(this.$cancel=document.createElement("button"),this.$cancel.type="button",this.$cancel.className="us-btn",this.$cancel.textContent="Cancel",this.$cancel.onclick=()=>this.cancel(),p.appendChild(this.$cancel),l||(this.$confirm=document.createElement("button"),this.$confirm.type="button",this.$confirm.className="us-btn us-btn-primary",this.$confirm.innerHTML=`${v.upload} <span>Upload</span>`,this.$confirm.disabled=!0,this.$confirm.onclick=()=>this.startUpload(),p.appendChild(this.$confirm)),c.appendChild(p),t.appendChild(c),!((T=this.opts.branding)!=null&&T.hideFooter)){let f=m("div","us-footer");f.innerHTML=`${v.zap} <span>Powered by <a href="${qe}" target="_blank" rel="noopener">UnionStack</a></span>`,t.appendChild(f)}e.appendChild(t),((x=this.opts.container)!=null?x:document.body).appendChild(e),this.$backdrop=e,((k=t.querySelector('.us-source-tab[data-active="true"]'))!=null?k:t).focus()}trapFocus(e){if(!this.$panel)return;let t=Array.from(this.$panel.querySelectorAll(Ve)).filter(a=>!a.hasAttribute("disabled")&&a.offsetParent!==null);if(t.length===0)return;let i=t[0],r=t[t.length-1],n=document.activeElement;e.shiftKey&&n===i?(e.preventDefault(),r.focus()):!e.shiftKey&&n===r&&(e.preventDefault(),i.focus())}resolvedSources(){let e=this.opts.fromSources;return!e||e.length===0?["device","url"]:e}renderSourceTabs(e){let t=m("div","us-source-tabs");return t.setAttribute("role","tablist"),t.setAttribute("aria-label","Upload source"),e.forEach((i,r)=>{let n=document.createElement("button");n.type="button",n.className="us-source-tab",n.setAttribute("role","tab"),n.setAttribute("aria-selected","false"),n.tabIndex=-1,n.dataset.source=i,n.innerHTML=i==="device"?`${v.device} <span>My Device</span>`:`${v.link} <span>Link</span>`,n.onclick=()=>this.activateSource(i),n.onkeydown=a=>this.onTabKeydown(a,e,r),t.appendChild(n)}),t}onTabKeydown(e,t,i){var n,a;let r=i;if(e.key==="ArrowRight"||e.key==="ArrowDown")r=(i+1)%t.length;else if(e.key==="ArrowLeft"||e.key==="ArrowUp")r=(i-1+t.length)%t.length;else if(e.key==="Home")r=0;else if(e.key==="End")r=t.length-1;else return;e.preventDefault(),this.activateSource(t[r]),(a=(n=this.$panel)==null?void 0:n.querySelector(`.us-source-tab[data-source="${t[r]}"]`))==null||a.focus()}activateSource(e){var i;if(this.$deviceSource){let r=e==="device";this.$deviceSource.style.display=r?"":"none"}this.$urlSource&&(this.$urlSource.dataset.active=e==="url"?"true":"false");let t=(i=this.$panel)==null?void 0:i.querySelectorAll(".us-source-tab");t==null||t.forEach(r=>{let n=r.dataset.source===e;r.dataset.active=n?"true":"false",r.setAttribute("aria-selected",n?"true":"false"),r.tabIndex=n?0:-1})}renderUrlSource(){let e=m("div","us-url-source"),t=m("div","us-url-form"),i=document.createElement("input");i.type="url",i.className="us-url-input",i.placeholder="https://example.com/photo.jpg",i.setAttribute("aria-label","File URL"),i.onkeydown=a=>{a.key==="Enter"&&(a.preventDefault(),this.handleUrlAdd())},this.$urlInput=i;let r=document.createElement("button");r.type="button",r.className="us-btn us-btn-primary",r.textContent="Add file",r.onclick=()=>this.handleUrlAdd(),this.$urlAddBtn=r,t.appendChild(i),t.appendChild(r),e.appendChild(t);let n=m("div","us-url-hint","Paste a direct file URL. The host must allow CORS so we can fetch it from the browser.");return this.$urlHint=n,e.appendChild(n),e}async handleUrlAdd(){if(!this.$urlInput||!this.$urlAddBtn||!this.$urlHint)return;let e=this.$urlInput.value.trim();if(!e){this.setUrlHint("Enter a URL first.",!0);return}if(!/^https?:\/\//i.test(e)){this.setUrlHint("URL must start with http:// or https://",!0);return}this.$urlAddBtn.disabled=!0;let t=this.$urlAddBtn.textContent;this.$urlAddBtn.textContent="Fetching\u2026",this.setUrlHint("Downloading\u2026",!1);try{let i=await Je(e);this.addFiles([i]),this.$urlInput.value="",this.setUrlHint("Paste a direct file URL. The host must allow CORS so we can fetch it from the browser.",!1)}catch(i){let r=i.message||"Failed to fetch URL";this.setUrlHint(r,!0)}finally{this.$urlAddBtn.disabled=!1,this.$urlAddBtn.textContent=t||"Add file"}}setUrlHint(e,t){this.$urlHint&&(this.$urlHint.textContent=e,this.$urlHint.dataset.error=t?"true":"false")}renderDropzone(){var a;let e=m("div","us-dropzone");e.setAttribute("role","button"),e.setAttribute("tabindex","0"),e.setAttribute("aria-label","Drop files here or click to browse");let t=m("div","us-dropzone-icon");t.innerHTML=v.fileUp,e.appendChild(t),e.appendChild(m("div","us-dropzone-title","Drop files to upload")),e.appendChild(m("div","us-dropzone-hint","or click to browse from your device"));let i=[];if(this.opts.maxFileSize&&i.push(`max ${O(this.opts.maxFileSize)}`),this.acceptStr){let s=[],d=new Set;for(let l of this.acceptStr.split(",")){let c=l.trim();if(!c||c==="*/*")continue;let p=Ge(c);p&&!d.has(p)&&(d.add(p),s.push(p))}s.length>0&&i.push(s.length>5?`${s.slice(0,5).join(", ")} +${s.length-5}`:s.join(", "))}i.length>0&&e.appendChild(m("div","us-dropzone-constraints",i.join(" \xB7 ")));let r=document.createElement("input");r.type="file",r.multiple=((a=this.opts.maxFiles)!=null?a:10)>1,this.acceptStr&&(r.accept=this.acceptStr),r.style.display="none",r.onchange=()=>{r.files&&this.addFiles(Array.from(r.files)),r.value=""},this.$input=r,e.appendChild(r),e.onclick=()=>r.click(),e.onkeydown=s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),r.click())};let n=0;return e.addEventListener("dragenter",s=>{s.preventDefault(),n++,e.setAttribute("data-drag","over")}),e.addEventListener("dragover",s=>s.preventDefault()),e.addEventListener("dragleave",()=>{n=Math.max(0,n-1),n===0&&e.removeAttribute("data-drag")}),e.addEventListener("drop",s=>{var l;s.preventDefault(),n=0,e.removeAttribute("data-drag");let d=(l=s.dataTransfer)==null?void 0:l.files;d&&this.addFiles(Array.from(d))}),e}unmount(){var e,t,i,r,n;this.editor&&(this.editor.close(),this.editor=null),this.noticeTimer&&(clearTimeout(this.noticeTimer),this.noticeTimer=null),(e=this.$backdrop)!=null&&e.parentNode&&this.$backdrop.parentNode.removeChild(this.$backdrop),this.$backdrop=null,this.$panel=null;for(let a of this.items)a.objectUrl&&URL.revokeObjectURL(a.objectUrl);(i=(t=this.previouslyFocused)==null?void 0:t.focus)==null||i.call(t),this.previouslyFocused=null,(n=(r=this.opts).onClose)==null||n.call(r)}fileMatchesAccept(e){let t=this.acceptStr.split(",").map(n=>n.trim().toLowerCase()).filter(Boolean);if(t.length===0||t.includes("*/*"))return!0;let i=(e.type||"").toLowerCase(),r=e.name.toLowerCase();return t.some(n=>n.startsWith(".")?r.endsWith(n):n.endsWith("/*")?i.startsWith(n.slice(0,-1)):i===n)}addFiles(e){var l;let t=(l=this.opts.maxFiles)!=null?l:1/0,i=0,r=e.filter(c=>this.fileMatchesAccept(c)?!0:(i++,!1)),n=t-this.items.length,a=n>0?r.slice(0,n):[],s=r.length-a.length,d=[];i>0&&d.push(`${i} file${i>1?"s":""} skipped \u2014 unsupported type`),s>0&&d.push(`${s} file${s>1?"s":""} skipped \u2014 max ${t} allowed`),d.length&&this.flashNotice(d.join(" \xB7 "));for(let c of a){if(this.opts.maxFileSize&&c.size>this.opts.maxFileSize){let u={uploadId:Z(),file:c,originalFile:c,edited:!1,state:"failed",progress:0,error:`File exceeds ${O(this.opts.maxFileSize)} limit`};this.items.push(u),this.renderItem(u);continue}let p={uploadId:Z(),file:c,originalFile:c,edited:!1,state:"queued",progress:0};this.items.push(p),this.renderItem(p),this.shouldCheckDimensions(c)&&(p.validating=!0,this.validateDimensions(p))}this.refreshConfirm(),this.maybeAutoUpload()}renderItem(e){if(!this.$list)return;let t=m("div","us-file");t.dataset.state=e.state,t.dataset.uploadId=e.uploadId;let i=Math.min(this.items.length-1,8);t.style.animationDelay=`${i*35}ms`;let r=m("div","us-file-thumb");if(e.file.type.startsWith("image/")&&typeof URL!="undefined"&&URL.createObjectURL)try{let h=URL.createObjectURL(e.file);e.objectUrl=h,r.style.backgroundImage=`url("${h}")`,r.dataset.image="true"}catch(h){r.innerHTML=G(e.file.type)}else r.innerHTML=G(e.file.type);t.appendChild(r);let n=m("div","us-file-main"),a=m("div","us-file-row1");a.appendChild(m("div","us-file-name",e.file.name));let s=m("div","us-file-meta",O(e.file.size));a.appendChild(s),n.appendChild(a);let d=m("div","us-file-progress"),l=m("div","us-file-progress-bar");d.appendChild(l),n.appendChild(d),t.appendChild(n);let c=e.file.type.startsWith("image/"),p=this.opts.imageEditing!==!1;if(c&&p&&e.state==="queued"){let h=document.createElement("button");h.type="button",h.className="us-file-action",h.setAttribute("aria-label","Edit image"),h.title="Edit image",h.innerHTML=v.pencil,h.dataset.edited=e.edited?"true":"false",h.onclick=()=>this.openEditor(e),t.appendChild(h),e.$edit=h}let u=m("div","us-file-status");u.setAttribute("aria-label",this.statusLabel(e)),u.innerHTML=this.statusIcon(e.state),t.appendChild(u),e.$row=t,e.$bar=l,e.$status=u,e.$meta=s,e.$thumb=r,this.$list.appendChild(t),this.updateSummary(),this.updateItemBadge(e)}replaceItemFile(e,t,i){if(e.file=t,e.edited=i,e.objectUrl&&URL.revokeObjectURL(e.objectUrl),e.objectUrl=void 0,e.$thumb)if(e.$thumb.style.backgroundImage="",e.$thumb.removeAttribute("data-image"),t.type.startsWith("image/")&&typeof URL!="undefined"&&URL.createObjectURL)try{let r=URL.createObjectURL(t);e.objectUrl=r,e.$thumb.style.backgroundImage=`url("${r}")`,e.$thumb.dataset.image="true",e.$thumb.innerHTML=""}catch(r){e.$thumb.innerHTML=G(t.type)}else e.$thumb.innerHTML=G(t.type);if(e.$meta&&(e.$meta.textContent=O(t.size)),e.$row){let r=e.$row.querySelector(".us-file-name");r&&(r.textContent=t.name)}e.$edit&&(e.$edit.dataset.edited=i?"true":"false")}openEditor(e){if(!this.$panel||this.editor||e.state!=="queued")return;let t=!1;this.editor=new X({host:this.$panel,file:e.file,originalFile:e.originalFile,title:e.originalFile.name,lockedAspect:this.opts.cropAspectRatio,onCropApplied:()=>{t=!0},onApply:i=>{let r=i!==e.originalFile;this.replaceItemFile(e,i,r),t&&(e.ratioCropped=!0),this.editor=null,this.shouldCheckDimensions(e.file)&&(e.validating=!0,this.validateDimensions(e)),this.updateItemBadge(e),this.refreshConfirm()},onCancel:()=>{this.editor=null}}),this.editor.open()}statusIcon(e){switch(e){case"uploading":return v.spinner;case"done":return v.check;case"failed":return v.alert;case"cancelled":return v.alert;default:return v.clock}}statusLabel(e){switch(e.state){case"queued":return"Waiting to upload";case"uploading":return`Uploading ${Math.round(e.progress)} percent`;case"done":return"Upload complete";case"failed":return e.error?`Failed: ${e.error}`:"Upload failed";case"cancelled":return"Cancelled"}}setItemState(e,t,i){if(e.state=t,i!==void 0&&(e.progress=i),e.$row&&(e.$row.dataset.state=t),e.$bar&&(e.$bar.style.width=`${e.progress}%`),e.$status&&(e.$status.innerHTML=this.statusIcon(t),e.$status.setAttribute("aria-label",this.statusLabel(e))),e.$meta){let r=O(e.file.size);switch(t){case"uploading":e.$meta.textContent=`${r} \xB7 ${Math.round(e.progress)}%`;break;case"done":e.$meta.textContent=r;break;case"failed":e.$meta.textContent=e.error||"Failed";break;default:e.$meta.textContent=r}}this.updateSummary()}updateSummary(){if(!this.$summary)return;let e=this.items.length;if(e===0){this.$summary.textContent="";return}let t=this.items.filter(n=>n.state==="done").length,i=this.items.filter(n=>n.state==="failed").length,r=this.items.filter(n=>n.state==="uploading"||n.state==="queued").length;if(!this.uploadStarted&&r>0){let n=this.items.filter(a=>a.state==="queued").length;this.$summary.textContent=`${n} file${n===1?"":"s"} ready`}else r>0?this.$summary.textContent=`Uploading ${t+1} of ${e}`:i>0?this.$summary.textContent=`${t} of ${e} uploaded \xB7 ${i} failed`:t===e?this.$summary.textContent=`${e} file${e===1?"":"s"} uploaded`:this.$summary.textContent=`${e} file${e===1?"":"s"} ready`}needsCrop(e){return this.opts.forceCrop===!0&&!!this.opts.cropAspectRatio&&e.state==="queued"&&e.file.type.startsWith("image/")&&e.file.type!=="image/svg+xml"&&!e.ratioCropped}hasUncroppedImages(){return this.items.some(e=>this.needsCrop(e))}anyValidating(){return this.items.some(e=>e.validating===!0)}shouldCheckDimensions(e){return!!(this.opts.minImageWidth||this.opts.minImageHeight)&&e.type.startsWith("image/")&&e.type!=="image/svg+xml"}updateItemBadge(e){e.$row&&(this.needsCrop(e)?(e.$row.dataset.cropRequired="true",e.$meta&&(e.$meta.textContent="Crop to ratio required")):(delete e.$row.dataset.cropRequired,e.state==="queued"&&e.$meta&&!e.validating&&(e.$meta.textContent=O(e.file.size))))}async validateDimensions(e){var n,a;let t=(n=this.opts.minImageWidth)!=null?n:0,i=(a=this.opts.minImageHeight)!=null?a:0,r=null;try{r=await Ye(e.file)}catch(s){r=null}if(e.state!=="queued"){e.validating=!1;return}if(e.validating=!1,r&&r.w>0&&r.h>0&&(r.w<t||r.h<i)){let s=`${t||"?"}\xD7${i||"?"}`;e.error=`Image too small \u2014 needs at least ${s}px (got ${r.w}\xD7${r.h})`,this.setItemState(e,"failed")}else this.updateItemBadge(e);this.refreshConfirm(),this.maybeAutoUpload()}maybeAutoUpload(){this.opts.autoUpload!==!0||this.uploadStarted||this.anyValidating()||this.hasUncroppedImages()||this.items.some(e=>e.state==="queued")&&requestAnimationFrame(()=>{this.uploadStarted||this.startUpload()})}refreshConfirm(){if(!this.$confirm)return;let e=this.items.filter(t=>t.state==="queued").length;this.$confirm.disabled=e===0||this.uploadStarted||this.hasUncroppedImages()||this.anyValidating()}flashNotice(e){this.$summary&&(this.$summary.textContent=e,this.$summary.dataset.tone="warn",this.noticeTimer&&clearTimeout(this.noticeTimer),this.noticeTimer=setTimeout(()=>{this.$summary&&(this.$summary.textContent="",delete this.$summary.dataset.tone),this.noticeTimer=null},4e3))}async startUpload(){if(this.uploadStarted)return;if(this.anyValidating()){this.flashNotice("Checking image dimensions\u2026");return}if(this.hasUncroppedImages()){this.items.forEach(r=>this.updateItemBadge(r)),this.flashNotice("Crop required \u2014 crop every image to the set ratio before uploading.");return}let e=this.items.filter(r=>r.state==="queued");if(e.length===0)return;this.uploadStarted=!0,this.$confirm&&(this.$confirm.disabled=!0,this.$confirm.textContent="Uploading\u2026"),this.$cancel&&(this.$cancel.textContent="Stop"),this.$closeBtn&&(this.$closeBtn.disabled=!0),this.$input&&(this.$input.disabled=!0);let t=new Map,i=e.map(r=>r.file);try{await this.client.uploadMany(i,z(E({},this.opts),{signal:this.abortCtrl.signal,onUploadStarted:r=>{var n,a;r.forEach((s,d)=>{let l=e[d];l&&(l.uploadId=s.uploadId,l.$row&&(l.$row.dataset.uploadId=s.uploadId),t.set(s.uploadId,l))}),(a=(n=this.opts).onUploadStarted)==null||a.call(n,r)},onFileUploadStarted:r=>{var a,s;let n=t.get(r.uploadId);n&&this.setItemState(n,"uploading",0),(s=(a=this.opts).onFileUploadStarted)==null||s.call(a,r)},onFileUploadProgress:(r,n)=>{var s,d;let a=t.get(r.uploadId);a&&this.setItemState(a,"uploading",n.totalPercent),(d=(s=this.opts).onFileUploadProgress)==null||d.call(s,r,n)},onFileUploadFinished:r=>{var a,s;let n=t.get(r.uploadId);n&&(n.uploaded=r,this.setItemState(n,"done",100)),(s=(a=this.opts).onFileUploadFinished)==null||s.call(a,r)},onFileUploadFailed:(r,n)=>{var s,d;let a=t.get(r.uploadId);a&&(a.error=n.message,this.setItemState(a,"failed")),(d=(s=this.opts).onFileUploadFailed)==null||d.call(s,r,n)},onUploadDone:r=>{var n,a;(a=(n=this.opts).onUploadDone)==null||a.call(n,r),this.resolveResult(r),this.unmount()},onError:r=>{var n,a;(a=(n=this.opts).onError)==null||a.call(n,r),this.resolveResult(),this.unmount()}}))}catch(r){this.resolved||(this.resolveResult(),this.unmount())}}resolveResult(e){if(this.resolved)return;this.resolved=!0;let t=e!=null?e:{filesUploaded:this.items.filter(i=>i.uploaded).map(i=>i.uploaded),filesFailed:this.items.filter(i=>i.state==="failed").map(i=>({file:{uploadId:i.uploadId,filename:i.file.name,mimetype:i.file.type||"application/octet-stream",size:i.file.size,source:"local"},error:{code:"VALIDATION",message:i.error||"failed",retryable:!1}}))};this.resolvePromise(t)}};xe={"application/pdf":"PDF","application/msword":"DOC","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"DOCX","application/vnd.ms-excel":"XLS","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":"XLSX","application/vnd.ms-powerpoint":"PPT","application/vnd.openxmlformats-officedocument.presentationml.presentation":"PPTX","application/zip":"ZIP","application/json":"JSON","application/rtf":"RTF","text/plain":"TXT","text/csv":"CSV","text/html":"HTML","text/markdown":"MD","image/jpeg":"JPG","image/png":"PNG","image/gif":"GIF","image/webp":"WEBP","image/svg+xml":"SVG","image/heic":"HEIC","video/mp4":"MP4","audio/mpeg":"MP3"},Xe={image:"Images",video:"Video",audio:"Audio",text:"Text",font:"Fonts"}});var we={};se(we,{Picker:()=>H,openPicker:()=>Y});var ee=K(()=>{"use strict";ke()});var ot={};se(ot,{Picker:()=>H,UnionStackClient:()=>j,init:()=>it,openPicker:()=>Y});function g(o,e,t={}){var i;return{code:o,message:e,status:t.status,retryable:(i=t.retryable)!=null?i:Se(o,t.status),cause:t.cause}}function Se(o,e){return!!(o==="NETWORK"||o==="PART_FAILED"||o==="SERVER"&&e&&e>=500)}function ae(o,e){let t=e==null?void 0:e.error,i=(t==null?void 0:t.message)||`Request failed with status ${o}`,r=((t==null?void 0:t.code)||"").toUpperCase();if(o===401)return g("AUTH",i,{status:o,retryable:!1});if(o===403)return g("AUTH",i,{status:o,retryable:!1});if(o===413)return g("VALIDATION",i,{status:o,retryable:!1});if(o===415)return g("VALIDATION",i,{status:o,retryable:!1});if(o===426)return g("CONFIG",i,{status:o,retryable:!1});if(o===429){let n=r==="QUOTA_EXCEEDED";return g(n?"QUOTA":"NETWORK",i,{status:o,retryable:!n})}return o>=500?g("SERVER",i,{status:o,retryable:!0}):g("SERVER",i,{status:o,retryable:!1})}var le="0.3.10",de=`js/${le}`,at=`node/${le}`;var Le=3,Fe=3,ce=[400,1200,3600],q=class{constructor(e){this.cfg=e}describe(e,t={}){let i=typeof File!="undefined"&&e instanceof File,r=t.filename||(i?e.name:"untitled"),n=t.mimeType||e.type||"application/octet-stream";return{uploadId:Ae(),filename:r,mimetype:n,size:e.size,source:"local"}}async upload(e,t={}){var r,n,a;let i=this.describe(e,{filename:t.filename,mimeType:t.mimeType});(r=t.onFileUploadStarted)==null||r.call(t,i);try{let s=await this.initUpload(i,t),d=await this.uploadAllParts(e,s,i,t),l=await this.completeUpload(s.sessionId,d,t),c=z(E({},i),{handle:l.handle,fileId:l.fileId,url:l.url,size:l.size,mimetype:l.mimetype,filename:l.filename,key:l.key,container:l.container,status:"Stored",etag:l.etag,metadata:l.metadata});return(n=t.onFileUploadFinished)==null||n.call(t,c),c}catch(s){let d=pe(s);throw(a=t.onFileUploadFailed)==null||a.call(t,i,d),s!=null&&s.sessionId&&this.abortSilently(s.sessionId).catch(()=>{}),d}}async abort(e){await this.api("POST","/sdk/v1/uploads/abort",{sessionId:e})}async fetchPickerConfig(){return this.api("GET","/sdk/v1/picker-config")}async initUpload(e,t){return this.api("POST","/sdk/v1/uploads/init",{filename:e.filename,mimeType:e.mimetype,size:e.size,metadata:t.metadata},t.signal)}async uploadAllParts(e,t,i,r){var R,T;let n=t.totalParts,a=t.chunkSize,s=Math.max(1,(R=r.concurrency)!=null?R:Le),d=(T=r.maxRetriesPerPart)!=null?T:Fe,l=new Map(t.partUrls.map(x=>[x.partNumber,x.url])),c=new Array(n),p=new Array(n).fill(0),u=1,h=e.size,y=()=>{var w;let x=p.reduce((L,b)=>L+b,0),k=h>0?Math.min(100,Math.round(x/h*100)):100,f={totalBytes:h,loaded:x,totalPercent:k};(w=r.onFileUploadProgress)==null||w.call(r,i,f)},M=async()=>{var x,k,f,w,L;for(;;){if((x=r.signal)!=null&&x.aborted)throw g("ABORTED","Upload aborted by caller.",{retryable:!1});let b=u++;if(b>n)return;let D=(b-1)*a,_=Math.min(D+a,e.size),F=e.slice(D,_),A=0,B;for(;A<=d;){if((k=r.signal)!=null&&k.aborted)throw g("ABORTED","Upload aborted by caller.",{retryable:!1});try{let C=l.get(b);C||(C=(await this.api("POST","/sdk/v1/uploads/sign-part",{sessionId:t.sessionId,partNumber:b},r.signal)).url,l.set(b,C));let U=(L=await((w=(f=this.cfg).fetch)==null?void 0:w.call(f,C,{method:"PUT",body:F,signal:r.signal})))!=null?L:await fetch(C,{method:"PUT",body:F,signal:r.signal});if(!U.ok)throw(U.status===403||U.status===401)&&l.delete(b),g("PART_FAILED",`Part ${b} PUT failed (HTTP ${U.status})`,{status:U.status});let N=U.headers.get("etag");if(!N)throw g("PART_FAILED",`Part ${b}: R2 did not return an ETag.`);c[b-1]={partNumber:b,etag:N,size:F.size},p[b-1]=F.size,y();break}catch(C){if(B=C,A++,A>d)break;await Be(ce[Math.min(A-1,ce.length-1)])}}if(!c[b-1])throw ze(pe(B!=null?B:g("PART_FAILED",`Part ${b} failed after ${d} retries.`)),t.sessionId)}},S=Array.from({length:Math.min(s,n)},M);return await Promise.all(S),c}async completeUpload(e,t,i){return this.api("POST","/sdk/v1/uploads/complete",{sessionId:e,parts:t.map(r=>({partNumber:r.partNumber,etag:r.etag}))},i.signal)}async abortSilently(e){try{await this.abort(e)}catch(t){}}async api(e,t,i,r){var l,c;let n=(l=this.cfg.fetch)!=null?l:fetch,a=`${this.cfg.apiBase}${t}`,s;try{s=await n(a,{method:e,headers:{Authorization:`Bearer ${this.cfg.apiKey}`,"Content-Type":"application/json","X-UnionStack-SDK":(c=this.cfg.sdkHeader)!=null?c:de},body:i===void 0?void 0:JSON.stringify(i),signal:r})}catch(p){throw(p==null?void 0:p.name)==="AbortError"?g("ABORTED","Request aborted.",{retryable:!1,cause:p}):g("NETWORK","Network request failed.",{retryable:!0,cause:p})}let d=null;try{d=await s.json()}catch(p){}if(!s.ok)throw ae(s.status,d);return d}};function Ae(){return typeof crypto!="undefined"&&"randomUUID"in crypto?crypto.randomUUID().replace(/-/g,""):Math.random().toString(36).slice(2)+Date.now().toString(36)}function Be(o){return new Promise(e=>setTimeout(e,o))}function pe(o){if(o&&typeof o=="object"&&"code"in o&&"message"in o&&"retryable"in o)return o;let e=(o==null?void 0:o.message)||"Upload failed.";return g("NETWORK",e,{cause:o})}function ze(o,e){return o&&typeof o=="object"&&(o.sessionId=e),o}var tt="https://api.unionstack.link/v1",Ce="unionstack-preloader-styles";function rt(){if(typeof document=="undefined")return()=>{};if(!document.getElementById(Ce)){let i=document.createElement("style");i.id=Ce,i.textContent="@keyframes us-preload-spin{to{transform:rotate(360deg)}}@keyframes us-preload-fade{from{opacity:0}to{opacity:1}}",document.head.appendChild(i)}let o=document.createElement("div");o.setAttribute("role","status"),o.setAttribute("aria-label","Loading file picker"),o.style.cssText="position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;background:rgba(2,6,23,0.4);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);animation:us-preload-fade 140ms ease-out;";let e=document.createElement("div");e.style.cssText="width:36px;height:36px;border-radius:50%;border:3px solid rgba(220,225,251,0.25);border-top-color:#c0c1ff;animation:us-preload-spin 0.8s linear infinite;",o.appendChild(e),document.body.appendChild(o);let t=!1;return()=>{t||(t=!0,o.remove())}}var j=class{constructor(e){e.apiKey||console.error("[UnionStack] apiKey is not set. Uploads and the picker are disabled until a valid apiKey is provided."),this.resolvedCfg=z(E({},e),{apiBase:tt}),this.uploader=new q(this.resolvedCfg),this.pickerConfigPromise=!e.apiKey||this.resolvedCfg.skipConfigPrefetch?Promise.resolve(null):this.uploader.fetchPickerConfig().then(t=>(t!=null&&t.sdkWarning&&console.warn(`[UnionStack] ${t.sdkWarning}`),t)).catch(()=>null)}missingKeyError(){return this.resolvedCfg.apiKey?null:g("CONFIG","apiKey is required.",{retryable:!1})}upload(e,t={}){let i=this.missingKeyError();return i?Promise.reject(i):this.uploader.upload(e,t)}async uploadMany(e,t={}){var d,l,c,p;let i=this.missingKeyError();if(i)throw(d=t.onError)==null||d.call(t,i),i;if(!Array.isArray(e)||e.length===0){let u=g("VALIDATION","uploadMany requires a non-empty array of files.",{retryable:!1});throw(l=t.onError)==null||l.call(t,u),u}let r=e.map(u=>this.uploader.describe(u,{filename:t.filename,mimeType:t.mimeType}));(c=t.onUploadStarted)==null||c.call(t,r);let n=[],a=[];await Promise.all(e.map(async(u,h)=>{try{let y=await this.uploader.upload(u,t);y.uploadId=r[h].uploadId,n.push(y)}catch(y){a.push({file:r[h],error:y})}}));let s={filesUploaded:n,filesFailed:a};return(p=t.onUploadDone)==null||p.call(t,s),s}picker(e={}){let t=null,i=!1,r,n,a=new Promise((s,d)=>{r=s,n=d});return{open:async()=>{if(i)return a;let s=this.missingKeyError();if(s)throw n(s),s;i=!0;let d=rt();try{t=(await Promise.resolve().then(()=>(ee(),we))).openPicker(this,z(E({},e),{onOpen:()=>{var p;d(),(p=e.onOpen)==null||p.call(e)}}));let c=await t.open();return d(),r(c),c}catch(l){d();let c=l!=null&&l.code?l:g("CONFIG","Failed to load picker.",{retryable:!1,cause:l});throw n(c),c}},close:()=>{t==null||t.close()},cancel:()=>{t==null||t.cancel()}}}get config(){return this.resolvedCfg}};var J={init(o){return new j(o)}};ee();var it=J.init.bind(J);(function(){if(typeof document=="undefined")return;let e=document.currentScript;if(!e)return;let t=e.getAttribute("data-unionstack-key");if(t)try{let i=J.init({apiKey:t});queueMicrotask(()=>{window.UnionStack&&(window.UnionStack.client=i)})}catch(i){console.error("[UnionStack] auto-init failed:",i)}})();return Me(ot);})();
510
512
  //# sourceMappingURL=loader.v1.global.js.map