=1&&k<=a.length){let $=a[k-1];if($.type==="irot"){L=$;break}}let E=N.offset+N.headerSize,S=N.size-N.headerSize,M=new Uint8Array(t.slice(E,E+S)),x=Lt(e,E),{width:H,height:oe}=Nt(e,ne),X=[];for(let k=0;ke.length)return 1;let o=t.getUint16(r),a;if(o===18761)a=!0;else if(o===19789)a=!1;else return 1;let i=r+t.getUint32(r+4,a);if(i+2>e.length)return 1;let s=t.getUint16(i,a);for(let c=0;ce.length)break;if(t.getUint16(u,a)===274){let f=t.getUint16(u+8,a);return f>=1&&f<=8?f:1}}return 1}function $t(e){let t=le(e,0,e.view.byteLength,"meta");if(!t)return null;let r=t.offset+t.headerSize+4,n=t.offset+t.size;return{box:t,children:fe(e,r,n)}}function fn(e){try{let t=new We(e),r=$t(t);if(!r)return 1;let n=r.children.find(f=>f.type==="iinf"),o=r.children.find(f=>f.type==="iloc");if(!n||!o)return 1;let a=Gt(t,n),i;for(let[f,d]of a)if(d==="Exif"){i=f;break}if(i===void 0)return 1;let s=zt(t,o).get(i);if(!s||s.extents.length===0)return 1;let c=r.children.find(f=>f.type==="idat"),u=c?c.offset+c.headerSize:0;return un(xe(e,s,u))}catch{return 1}}function ln(e){let t=$t(e);if(!t)return!1;let r=t.children.find(i=>i.type==="iprp");if(!r)return!1;let n=le(e,r.offset+r.headerSize,r.offset+r.size,"ipco");if(!n)return!1;let o=n.offset+n.headerSize,a=n.offset+n.size;return!!(le(e,o,a,"irot")||le(e,o,a,"imir"))}function Oe(e){try{if(ln(new We(e)))return 1}catch{return 1}return fn(e)}var O=w(q(),1);function Ae(){if(typeof navigator>"u")return null;let e=navigator.userAgentData?.brands;if(e?.length&&e.some(({brand:r})=>/Chromium/i.test(r)))return"chromium";let t=navigator.userAgent||"";return/Firefox|FxiOS/i.test(t)?"firefox":/Chrome|Chromium|CriOS|Edg|OPR/i.test(t)?"chromium":/Safari/i.test(t)?"safari":null}function qt(){if(typeof navigator>"u")return"other";let e=navigator.userAgentData?.platform||navigator.userAgent||"";return/iPhone|iPad|iPod|iOS/i.test(e)?"other":/macOS|Mac OS X|Macintosh/i.test(e)?"macos":/Windows/i.test(e)?"windows":/Android|CrOS|Chrome OS/i.test(e)?"other":/Linux|X11/i.test(e)?"linux":"other"}function dn(){if(Ae()==="chromium"){let e=navigator.userAgentData?.brands??[],t=navigator.userAgent||"";return e.some(({brand:r})=>/Edge/i.test(r))||/Edg\//i.test(t)?"Edge":e.some(({brand:r})=>/Opera/i.test(r))||/OPR\//i.test(t)?"Opera":"Chrome"}switch(Ae()){case"firefox":return"Firefox";case"safari":return"Safari";default:return null}}function de(){let e=qt(),t=Ae();if(e==="macos"){if(t==="chromium")return(0,O.__)("Safari usually can, or you can upload a JPEG instead.");if(t!=="safari")return(0,O.__)("Safari or Chrome usually can, or you can upload a JPEG instead.")}return e==="windows"&&t==="firefox"?(0,O.__)("Chrome or Edge might, or you can upload a JPEG instead."):(0,O.__)("You can upload a JPEG instead.")}function ee(){let e=qt(),t=Ae(),r=dn(),n;return e==="linux"?n=(0,O.__)("HEIC photos can't be decoded on Linux, so unfortunately we couldn't convert this one."):t==="firefox"?n=(0,O.__)("Firefox can't read HEIC photos, so we couldn't convert this one."):r&&e==="windows"?n=(0,O.sprintf)((0,O.__)("%s couldn't decode HEIC on this PC, so we couldn't convert this one."),r):r&&e==="macos"?n=(0,O.sprintf)((0,O.__)("%s couldn't decode HEIC on this Mac, so we couldn't convert this one."),r):r?n=(0,O.sprintf)((0,O.__)("%s couldn't decode HEIC on this device, so we couldn't convert this one."),r):n=(0,O.__)("This browser can't read HEIC photos, so we couldn't convert this one."),`${n} ${de()}`}var je=class extends Error{};async function Vt(e,t=.82){let r=W(e.name);try{let o=await createImageBitmap(e);try{let a=new OffscreenCanvas(o.width,o.height),i=a.getContext("2d");if(!i)throw new Error("Could not get canvas 2d context");i.drawImage(o,0,0);let s=await a.convertToBlob({type:"image/jpeg",quality:t});return new File([s],`${r}.jpg`,{type:"image/jpeg"})}finally{o.close()}}catch{}if(typeof ImageDecoder<"u"&&await ImageDecoder.isTypeSupported(e.type)){let a=new ImageDecoder({type:e.type,data:e.stream()});try{let{image:i}=await a.decode();try{let s=new OffscreenCanvas(i.displayWidth,i.displayHeight),c=s.getContext("2d");if(!c)throw new Error("Could not get canvas 2d context");c.drawImage(i,0,0);let u=await s.convertToBlob({type:"image/jpeg",quality:t});return new File([u],`${r}.jpg`,{type:"image/jpeg"})}finally{i.close()}}finally{a.close()}}let n;try{n=kt(await e.arrayBuffer())}catch(o){throw new Error("The HEIC file could not be parsed",{cause:o})}if(typeof VideoDecoder<"u"){let o=!1;try{o=(await VideoDecoder.isConfigSupported({codec:n.codecString})).supported===!0}catch{}if(o){let a=new OffscreenCanvas(n.outputWidth,n.outputHeight),i=a.getContext("2d");if(!i)throw new Error("Could not get canvas 2d context");for(let u of n.tiles){let f=await gn(n.codecString,n.description,n.tileWidth,n.tileHeight,u.data);try{i.drawImage(f,u.x,u.y)}finally{f.close()}}let c=await(n.rotation!==0?pn(a,n.rotation):mn(a,n.exifOrientation)).convertToBlob({type:"image/jpeg",quality:t});return new File([c],`${r}.jpg`,{type:"image/jpeg"})}}throw new je(ee())}function pn(e,t){if(t===0)return e;let r=t===90||t===270,n=r?e.height:e.width,o=r?e.width:e.height,a=new OffscreenCanvas(n,o),i=a.getContext("2d");return i?(i.translate(n/2,o/2),i.rotate(-t*Math.PI/180),i.drawImage(e,-e.width/2,-e.height/2),a):e}function mn(e,t){if(t<=1||t>8)return e;let{width:r,height:n}=e,o=t>=5,a=new OffscreenCanvas(o?n:r,o?r:n),i=a.getContext("2d");if(!i)return e;switch(t){case 2:i.transform(-1,0,0,1,r,0);break;case 3:i.transform(-1,0,0,-1,r,n);break;case 4:i.transform(1,0,0,-1,0,n);break;case 5:i.transform(0,1,1,0,0,0);break;case 6:i.transform(0,1,-1,0,n,0);break;case 7:i.transform(0,-1,-1,0,n,r);break;case 8:i.transform(0,-1,1,0,0,r);break}return i.drawImage(e,0,0),a}function gn(e,t,r,n,o){return new Promise((a,i)=>{let s=new VideoDecoder({output:c=>{s.close(),a(c)},error:c=>{s.state!=="closed"&&s.close(),i(c)}});s.configure({codec:e,codedWidth:r,codedHeight:n,description:t}),s.decode(new EncodedVideoChunk({type:"key",timestamp:0,data:o})),s.flush().catch(c=>{s.state!=="closed"&&s.close(),i(c)})})}var R=null;function Qe(){if(R!==null)return R;if(typeof WebAssembly>"u")return R={supported:!1,reason:"WebAssembly is not supported in this browser."},R;if(typeof SharedArrayBuffer>"u")return R={supported:!1,reason:"SharedArrayBuffer is not available. This may be due to missing cross-origin isolation headers."},R;if(typeof Worker>"u")return R={supported:!1,reason:"Web Workers are not supported in this browser."},R;if(typeof navigator<"u"&&"deviceMemory"in navigator&&navigator.deviceMemory<=2)return R={supported:!1,reason:"Device has insufficient memory for client-side media processing."},R;if(typeof navigator<"u"&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency<2)return R={supported:!1,reason:"Device has insufficient CPU cores for client-side media processing."},R;if(typeof navigator<"u"){let e=navigator.connection;if(e){if(e.saveData)return R={supported:!1,reason:"Data saver mode is enabled."},R;if(e.effectiveType==="slow-2g"||e.effectiveType==="2g")return R={supported:!1,reason:"Network connection is too slow for client-side media processing."},R}}if(typeof window<"u")try{let e=new Blob([""],{type:"application/javascript"}),t=URL.createObjectURL(e);try{new Worker(t).terminate()}finally{URL.revokeObjectURL(t)}}catch{return R={supported:!1,reason:"The site's Content Security Policy (CSP) does not allow blob: workers. The worker-src directive must include blob: to enable client-side media processing."},R}return R={supported:!0},R}function Pe(){return Qe().supported}function Wt(){return typeof createImageBitmap<"u"&&typeof OffscreenCanvas<"u"}function Yt(){R=null}var hn=4,yn=.5*1024*1024*1024,In=.9*1024*1024*1024;function jt(e){let{width:t,height:r,interlaced:n}=e;return t*r*hn>(n?yn:In)}var En=524288;function vn(e){let t=2;for(;t=e.byteLength)return null;let r=e.getUint8(t);if(t++,r===1||r>=208&&r<=217)continue;if(r===218||t+2>e.byteLength)return null;let n=e.getUint16(t);if(n<2)return null;if(r>=192&&r<=207&&r!==196&&r!==200&&r!==204){if(t+7>e.byteLength)return null;let a=e.getUint16(t+3);return{width:e.getUint16(t+5),height:a,interlaced:r===194||r===198||r===202||r===206}}t+=n}return null}function wn(e){if(e.byteLength<29||!(e.getUint8(12)===73&&e.getUint8(13)===72&&e.getUint8(14)===68&&e.getUint8(15)===82))return null;let r=e.getUint32(16),n=e.getUint32(20),o=e.getUint8(28);return{width:r,height:n,interlaced:o!==0}}async function Qt(e){try{let t=Math.min(e.size,En),r=await e.slice(0,t).arrayBuffer(),n=new DataView(r);return n.byteLength>=3&&n.getUint16(0)===65496?vn(n):n.byteLength>=8&&n.getUint32(0)===2303741511&&n.getUint32(4)===218765834?wn(n):null}catch{return null}}var Xt=class extends File{constructor(e="stub-file"){super([],e)}};var me=.82,Xe=new Set;function Rn({file:e,batchId:t,onChange:r,onSuccess:n,onBatchSuccess:o,onError:a,additionalData:i={},sourceUrl:s,sourceAttachmentId:c,abortController:u,operations:f}){return async({dispatch:d})=>{let p=B(),m=gt(e),y;m instanceof Xt||(y=(0,D.createBlobURL)(m),d({type:h.CacheBlobUrl,id:p,blobUrl:y})),d({type:h.Add,item:{id:p,batchId:t,status:z.Processing,sourceFile:Ge(m),file:m,attachment:{url:y},additionalData:{generate_sub_sizes:!1,...i},onChange:r,onSuccess:n,onBatchSuccess:o,onError:a,sourceUrl:s,sourceAttachmentId:c,abortController:u||new AbortController,operations:Array.isArray(f)?f:[l.Prepare]}}),d.processItem(p)}}function Sn({file:e,onChange:t,additionalData:r,operations:n,batchId:o,parentId:a}){return({dispatch:i})=>{let s=B();i({type:h.Add,item:{id:s,batchId:o,status:z.Processing,sourceFile:Ge(e),file:e,onChange:t,additionalData:{...r},parentId:a,operations:Array.isArray(n)?n:[l.Prepare],abortController:new AbortController}}),i.processItem(s)}}function Un(e){return async({select:t,dispatch:r})=>{if(t.isPaused())return;let n=t.getItem(e);if(!n)return;let{attachment:o,onChange:a,onSuccess:i,onBatchSuccess:s,batchId:c,parentId:u}=n,f=Array.isArray(n.operations?.[0])?n.operations[0][0]:n.operations?.[0],d=Array.isArray(n.operations?.[0])?n.operations[0][1]:void 0;if(f===l.Upload){let p=t.getSettings();if(t.getActiveUploadCount()>=p.maxConcurrentUploads)return}if(f===l.ResizeCrop||f===l.Rotate){let p=t.getSettings();if(t.getActiveImageProcessingCount()>=p.maxConcurrentImageProcessing)return}if(!(f===l.TranscodeGif&&t.getActiveVideoProcessingCount()>=1)){if(o&&(o.url&&/\.hei[cf]$/i.test(o.url)||a?.([o])),!f){if((u||!u&&!t.hasPendingItemsByParentId(e))&&(o&&i?.([o]),r.removeItem(e),r.revokeBlobUrls(e),c&&t.isBatchUploaded(c)&&s?.()),u&&c&&t.isBatchUploaded(c)){let p=t.getItem(u);if(!p)return;if(p.operations&&p.operations.length>0){r.processItem(u);return}o&&p.onSuccess?.([o]),r.removeItem(u),r.revokeBlobUrls(u),p.batchId&&t.isBatchUploaded(p.batchId)&&p.onBatchSuccess?.()}return}if(!(f===l.Finalize&&t.hasPendingItemsByParentId(e)))switch(r({type:h.OperationStart,id:e,operation:f}),Q(`Starting operation ${f} for ${n.file.name} (item ${n.id})`),f){case l.Prepare:r.prepareItem(n.id);break;case l.ResizeCrop:r.resizeCropItem(n.id,d);break;case l.Rotate:r.rotateItem(n.id,d);break;case l.TranscodeImage:r.transcodeImageItem(n.id,d);break;case l.TranscodeGif:r.transcodeGifItem(n.id,d);break;case l.Upload:n.parentId?r.sideloadItem(e):r.uploadItem(e);break;case l.ThumbnailGeneration:r.generateThumbnails(e);break;case l.Finalize:r.finalizeItem(e);break;case l.DetectUltraHdr:r.detectUltraHdr(e);break}}}}function _n(){return{type:h.PauseQueue}}function Cn(){return async({select:e,dispatch:t})=>{t({type:h.ResumeQueue});for(let r of e.getAllItems())r.status===z.PendingRetry?t.executeRetry(r.id):t.processItem(r.id)}}function bn(e){return async({dispatch:t})=>{t({type:h.PauseItem,id:e})}}function Tn(e){return async({select:t,dispatch:r})=>{t.getItem(e)&&(Xe.delete(e),Re(e),r({type:h.Remove,id:e}),t.getAllItems().length===0&&(qe(),bt()))}}function xn(e,t){return async({select:r,dispatch:n})=>{let a=r.getItem(e)?.currentOperation;if(n({type:h.OperationFinish,id:e,item:t}),n.processItem(e),a===l.Upload){let i=r.getPendingUploads();for(let s of i)n.processItem(s.id)}if(a===l.ResizeCrop||a===l.Rotate){let i=r.getPendingImageProcessing();for(let s of i)n.processItem(s.id)}if(a===l.TranscodeGif){let i=r.getPendingVideoProcessing();for(let s of i)n.processItem(s.id)}(a===l.ResizeCrop||a===l.Rotate||a===l.TranscodeImage)&&Ue(r.getActiveImageProcessingCount())}}var On=["jpeg","webp","avif","png","gif"];function An(e){return On.includes(e)}async function Jt(e,t,r=!1,n=me){if(e.type==="image/png"&&t==="image/jpeg"){let a=(0,D.createBlobURL)(e);try{if(await ke(a))return null}catch{return null}finally{(0,D.revokeBlobURL)(a)}}let o=t.split("/")[1];return An(o)?[l.TranscodeImage,{outputFormat:o,outputQuality:n,interlaced:r}]:null}function Pn(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;let{file:o}=n,a=[],i=t.getSettings();if(o.type==="image/gif"&&i.gifConvert!==!1&&typeof ImageDecoder<"u"&&typeof VideoEncoder<"u"){let m=!1;try{m=ht(await o.arrayBuffer())}catch{m=!1}if(m){let y=!1,v=(0,D.createBlobURL)(o);try{y=await ke(v)}catch{y=!0}finally{(0,D.revokeBlobURL)(v)}if(!y){a.push(l.Upload,l.ThumbnailGeneration,l.Finalize),r({type:h.AddOperations,id:e,operations:a}),r.finishOperation(e,{animatedGifFile:n.file});return}}}let s=null,c=o.type.startsWith("image/"),u=st.includes(o.type),f=ct.includes(o.type),d=!1;if(c&&u){let m=await Qt(o);m&&jt(m)&&(d=!0)}if(o.type==="image/jpeg"&&!d&&a.push(l.DetectUltraHdr),c&&u&&!d)a.push(l.Upload,l.ThumbnailGeneration,l.Finalize);else if(c&&f){try{s=await Vt(o,i.imageQuality??me)}catch(m){let y=m instanceof je;r.cancelItem(e,new U({code:y?I.HEIC_DECODE_ERROR:I.IMAGE_TRANSCODING_ERROR,message:y?ee():(0,pe.__)("This HEIC image could not be converted. Try converting it to JPEG before uploading."),file:o,cause:m instanceof Error?m:void 0}));return}a.push(l.Upload,l.ThumbnailGeneration,l.Finalize)}else a.push(l.Upload);r({type:h.AddOperations,id:e,operations:a});let p;if(f&&s){let m=Pe();p={file:s,sourceFile:s,originalHeicFile:n.file,additionalData:{...n.additionalData,generate_sub_sizes:!m,convert_format:!0}}}else!u||!c||d?p={additionalData:{...n.additionalData,generate_sub_sizes:!0,convert_format:!0}}:p={additionalData:{...n.additionalData,generate_sub_sizes:!1}};r.finishOperation(e,p)}}function Fn(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;let o;try{let a=await n.file.arrayBuffer();o=await It(a)}catch{}o&&Xe.add(e),r.finishOperation(e,{})}}function Mn(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;let o=performance.now(),a=!1,i=s=>{a||(a=!0,Z({measureName:`Upload ${n.file.name}`,startTime:o,tooltipText:n.file.name,properties:[["Item ID",n.id],["File name",n.file.name]]}),r.finishOperation(e,{attachment:s}))};t.getSettings().mediaUpload({filesList:[n.file],additionalData:n.additionalData,signal:n.abortController?.signal,isTransportOnly:!0,onFileChange:([s])=>{s&&!(0,D.isBlobURL)(s.url)&&i(s)},onSuccess:([s])=>{i(s)},onError:s=>{r.cancelItem(e,s)}})}}function Dn(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;let{post:o,...a}=n.additionalData,i=t.getSettings().mediaSideload;if(!i){r.finishOperation(e,{});return}let s=performance.now();i({file:n.file,attachmentId:o,additionalData:a,signal:n.abortController?.signal,onSuccess:c=>{Z({measureName:`Sideload ${n.file.name}`,startTime:s,tooltipText:n.file.name,properties:[["Item ID",n.id],["File name",n.file.name]]}),n.parentId&&r({type:h.AccumulateSubSize,id:n.parentId,subSize:c}),r.finishOperation(e,{})},onError:c=>{r.cancelItem(e,c)}})}}function zn(e,t){return async({select:r,dispatch:n})=>{let o=r.getItem(e);if(!o)return;if(!t?.resize){n.finishOperation(e,{file:o.file});return}let a=performance.now(),i=!!o.parentId,s=!!t.isThresholdResize,{imageStripMeta:c,imageMaxBitDepth:u}=r.getSettings();try{let f=await Et(o.id,o.file,t.resize,{smartCrop:!1,addSuffix:i,signal:o.abortController?.signal,scaledSuffix:s,quality:t.quality,stripMeta:c,maxBitdepth:u});Z({measureName:`ResizeCrop ${o.file.name}`,startTime:a,tooltipText:o.file.name,properties:[["Item ID",o.id],["File name",o.file.name]]});let d=(0,D.createBlobURL)(f);n({type:h.CacheBlobUrl,id:e,blobUrl:d}),n.finishOperation(e,{file:f,attachment:{url:d}})}catch(f){n.cancelItem(e,new U({code:I.IMAGE_TRANSCODING_ERROR,message:(0,pe.__)("The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading."),file:o.file,cause:f instanceof Error?f:void 0}))}}}function Nn(e,t){return async({select:r,dispatch:n})=>{let o=r.getItem(e);if(!o)return;if(!t?.orientation||t.orientation===1){n.finishOperation(e,{file:o.file});return}let a=performance.now();try{let i=await $e(o.id,o.file,t.orientation,o.abortController?.signal);Z({measureName:`Rotate ${o.file.name}`,startTime:a,tooltipText:o.file.name,properties:[["Item ID",o.id],["File name",o.file.name]]});let s=(0,D.createBlobURL)(i);n({type:h.CacheBlobUrl,id:e,blobUrl:s}),n.finishOperation(e,{file:i,attachment:{url:s}})}catch(i){n.cancelItem(e,new U({code:I.IMAGE_ROTATION_ERROR,message:(0,pe.__)("The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading."),file:o.file,cause:i instanceof Error?i:void 0}))}}}function Bn(e,t){return async({select:r,dispatch:n})=>{let o=r.getItem(e);if(!o)return;if(!t?.outputFormat){n.finishOperation(e,{file:o.file});return}let a=performance.now(),i=`image/${t.outputFormat}`,s=t.outputQuality??me,c=t.interlaced??!1,{imageStripMeta:u,imageMaxBitDepth:f}=r.getSettings();try{let d=await yt(o.id,o.file,i,{quality:s,interlaced:c,stripMeta:u,maxBitdepth:f});Z({measureName:`Transcode ${o.file.name}`,startTime:a,tooltipText:o.file.name,properties:[["Item ID",o.id],["File name",o.file.name]]});let p=(0,D.createBlobURL)(d);n({type:h.CacheBlobUrl,id:e,blobUrl:p}),n.finishOperation(e,{file:d,attachment:{url:p}})}catch(d){n.cancelItem(e,new U({code:I.MEDIA_TRANSCODING_ERROR,message:"Image could not be transcoded to the target format",file:o.file,cause:d instanceof Error?d:void 0}))}}}function Gn(e,t){return async({select:r,dispatch:n})=>{let o=r.getItem(e);if(!o)return;let i=`video/${t?.outputFormat??"mp4"}`,s=o.file;try{let c=await _t(o.id,s,i,{timeout:t?.timeout,maxTotalPixels:t?.maxTotalPixels});n.finishOperation(e,{file:c}),n.addSideloadItem({file:s,batchId:B(),parentId:o.parentId,additionalData:{post:o.additionalData?.post,image_size:"animated_video_poster",convert_format:!1},operations:[[l.TranscodeImage,{outputFormat:"jpeg",outputQuality:me,interlaced:!1}],l.Upload]})}catch(c){if(St(c)){Ut(c)&&Q(`Skipping GIF to video conversion: ${c instanceof Error?c.message:c}`),n.cancelItem(e,new Error("Animated GIF conversion unsupported"),!0);return}if(Ve(c)){Q(`GIF to video conversion timed out; keeping the original GIF only: ${c instanceof Error?c.message:c}`),n.cancelItem(e,new Error("Animated GIF conversion timed out"),!0);return}console.error("[video-conversion] GIF to video conversion failed:",c),n.cancelItem(e,new U({code:I.GIF_TRANSCODING_ERROR,message:"Animated GIF could not be converted to video",file:o.file,cause:c instanceof Error?c:void 0}),!0)}}}function Ln(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;if(!n.attachment){r.finishOperation(e,{});return}let o=n.attachment,a=t.getSettings();if(n.originalHeicFile&&o.id&&r.addSideloadItem({file:n.originalHeicFile,batchId:B(),parentId:n.id,additionalData:{post:o.id,image_size:"source_original",convert_format:!1},operations:[l.Upload]}),n.animatedGifFile&&o.id){let d=a.videoOutputFormat==="video/webm"?"webm":"mp4";r.addSideloadItem({file:n.animatedGifFile,batchId:B(),parentId:n.id,additionalData:{post:o.id,image_size:"animated_video",convert_format:!1},operations:[[l.TranscodeGif,{outputFormat:d}],l.Upload]})}let i=o.exif_orientation||1,s=n.sourceFile.type,c=s==="image/avif"||s==="image/heif",u=!1;c&&(i=Oe(await n.sourceFile.arrayBuffer()),u=i!==1);let f;{let d=i!==1&&!n.file.name.includes("-scaled");if((d||u)&&o.id)try{f=await $e(n.id,n.sourceFile,i,n.abortController?.signal)}catch{console.warn("Failed to rotate image, continuing with thumbnails")}d&&f&&o.id&&r.addSideloadItem({file:f,batchId:B(),parentId:n.id,additionalData:{post:o.id,image_size:"original",convert_format:!1},operations:[l.Upload]})}if(!n.parentId&&o.missing_image_sizes&&o.missing_image_sizes.length>0){let d=a.allImageSizes||{},p=o.missing_image_sizes,m=u&&f?f:n.sourceFile,y=o.filename?Se(m,o.filename):m,v=B(),b=Xe.has(n.id),P=o.image_output_format,A=o.image_save_progressive??!1,T=o.image_quality,F=a.imageQuality??me,N=typeof T?.default=="number"?T.default/100:F,ne=E=>{let S=T?.sizes?.[E];return typeof S=="number"?S/100:N},G=null;!b&&P&&(G=await Jt(m,P,A,N));let L=new Map;for(let E of p){let S=d[E];if(!S){console.warn(`Image size "${E}" not found in configuration`);continue}let M=`${S.width}x${S.height}x${S.crop}`,x=L.get(M);x?x.push(E):L.set(M,[E])}for(let[,E]of L){let S=d[E[0]],M=ne(E[0]),x=[[l.ResizeCrop,{resize:S,quality:M}]];!b&&G&&x.push([G[0],{...G[1],outputQuality:M}]),x.push(l.Upload);let H=E.length===1?E[0]:E;r.addSideloadItem({file:y,batchId:v,parentId:n.id,additionalData:{post:o.id,image_size:H,convert_format:!1},operations:x})}{let{bigImageSizeThreshold:E}=a;if(E&&o.id){let S=await createImageBitmap(m),M=S.width>E||S.height>E;if(S.close(),M){let x=o.filename?Se(m,o.filename):m,H=[[l.ResizeCrop,{resize:{width:E,height:E},isThresholdResize:!0,quality:N}]];!b&&G&&H.push(G),H.push(l.Upload),r.addSideloadItem({file:x,batchId:v,parentId:n.id,additionalData:{post:o.id,image_size:"scaled",convert_format:!1},operations:H})}}}}r.finishOperation(e,{})}}function Hn(e){return async({select:t,dispatch:r})=>{let n=t.getItem(e);if(!n)return;let o=n.attachment,{mediaFinalize:a}=t.getSettings(),i={};if(o?.id&&a)try{let s=await a(o.id,n.subSizes||[]);s&&(i.attachment=s)}catch(s){console.warn("Media finalization failed:",s),r.cancelItem(e,new U({code:I.MEDIA_FINALIZE_ERROR,message:(0,pe.__)("Could not finalize the upload."),file:n.file}));return}r.finishOperation(e,i)}}function kn(e){return async({select:t,dispatch:r})=>{let n=t.getBlobUrls(e);for(let o of n)(0,D.revokeBlobURL)(o);r({type:h.RevokeBlobUrls,id:e})}}function $n(e,t){return async({dispatch:r})=>{r({type:h.UpdateProgress,id:e,progress:t})}}function qn(e){return{type:h.UpdateSettings,settings:e}}var er=w(Kt(),1),{lock:Ii,unlock:ge}=(0,er.__dangerousOptInToUnstableAPIsOnlyForCoreModules)("I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.","@wordpress/upload-media");var tr={reducer:De,selectors:we,actions:Te},j=(0,te.createReduxStore)(ve,{reducer:De,selectors:we,actions:Te});(0,te.select)(j)||(0,te.register)(j);ge(j).registerPrivateActions(Je);ge(j).registerPrivateSelectors(ze);var ur=w(Ze(),1),fr=w(Ee(),1);var ar=w(Ze(),1),re=w(Ee(),1),sr=w(or(),1);var Fe=w(Ke(),1);function Vn(e,t,r){if(!r)return t;let n=e.get(t);return n||(n=(0,re.createRegistry)({},t),n.registerStore(ve,tr),e.set(t,n)),n}var Wn=(0,sr.createHigherOrderComponent)(e=>({useSubRegistry:t=!0,...r})=>{let n=(0,re.useRegistry)(),[o]=(0,ar.useState)(()=>new WeakMap),a=Vn(o,n,t);return a===n?(0,Fe.jsx)(e,{registry:n,...r}):(0,Fe.jsx)(re.RegistryProvider,{value:a,children:(0,Fe.jsx)(e,{registry:a,...r})})},"withRegistryProvider"),cr=Wn;var Me=w(Ke(),1),Yn=cr(e=>{let{children:t,settings:r}=e,{updateSettings:n}=ge((0,fr.useDispatch)(j));return(0,ur.useEffect)(()=>{n(r)},[r,n]),(0,Me.jsx)(Me.Fragment,{children:t})}),lr=Yn;var g=w(q(),1);function dr(e,t){return{[I.EMPTY_FILE]:{title:(0,g.__)("Empty file"),description:(0,g.sprintf)((0,g.__)('"%s" is empty.'),t),action:(0,g.__)("Please choose a different file.")},[I.SIZE_ABOVE_LIMIT]:{title:(0,g.__)("File too large"),description:(0,g.sprintf)((0,g.__)('"%s" exceeds the maximum upload size.'),t),action:(0,g.__)("Please reduce the file size and try again.")},[I.MIME_TYPE_NOT_SUPPORTED]:{title:(0,g.__)("Unsupported file type"),description:(0,g.sprintf)((0,g.__)('"%s" is not a supported file type.'),t),action:(0,g.__)("Please upload a different file format.")},[I.MIME_TYPE_NOT_ALLOWED_FOR_USER]:{title:(0,g.__)("File type not allowed"),description:(0,g.sprintf)((0,g.__)('You are not allowed to upload "%s".'),t),action:(0,g.__)("Please contact your site administrator.")},[I.HEIC_DECODE_ERROR]:{title:(0,g.__)("HEIC decode failed"),description:(0,g.sprintf)((0,g.__)('Failed to decode HEIC file "%s".'),t),action:de()},[I.IMAGE_TRANSCODING_ERROR]:{title:(0,g.__)("Image processing failed"),description:(0,g.sprintf)((0,g.__)('Failed to process "%s".'),t),action:(0,g.__)("The image may be corrupted. Try a different file.")},[I.IMAGE_ROTATION_ERROR]:{title:(0,g.__)("Image rotation failed"),description:(0,g.sprintf)((0,g.__)('Failed to rotate "%s".'),t),action:(0,g.__)("The image may be corrupted. Try a different file.")},[I.MEDIA_TRANSCODING_ERROR]:{title:(0,g.__)("Media processing failed"),description:(0,g.sprintf)((0,g.__)('Failed to convert "%s" to the target format.'),t),action:(0,g.__)("The file may be corrupted. Try a different file.")},[I.MEDIA_FINALIZE_ERROR]:{title:(0,g.__)("Upload failed"),description:(0,g.sprintf)((0,g.__)('Could not finalize the upload of "%s".'),t),action:(0,g.__)("Please try again.")},[I.GENERAL]:{title:(0,g.__)("Upload failed"),description:(0,g.sprintf)((0,g.__)('Failed to upload "%s".'),t),action:(0,g.__)("Please try again.")}}[e]||{title:(0,g.__)("Upload failed"),description:(0,g.sprintf)((0,g.__)('Failed to upload "%s".'),t),action:(0,g.__)("Please try again.")}}return Ir(jn);})();
(window.wp ||= {}).uploadMedia = wp.uploadMedia;
})();