// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-or-later
// @source: https://gitlab.com/soapbox-pub/ditto/-/tree/f0a3877c
import{h as e,m as t,p as n,x as r}from"./EmbeddedNote-BKfkvcrg.js";import{n as i}from"./imeta-83Lqxs5-.js";import{t as a}from"./contentWarning-CNDzjeMP.js";var o=new Set([34236,21,22]),s=new Set([36787,34139,30054,30055,1222]);function c(e,t,n){if(t){if(t.startsWith(`video/`))return`video`;if(t.startsWith(`audio/`))return`audio`;if(t.startsWith(`image/`))return`image`}if(/\.(mp4|webm|mov|qt|m3u8)(\?.*)?$/i.test(e))return`video`;if(/\.(mp3|mpga|ogg|flac|wav|aac|opus)(\?.*)?$/i.test(e))return`audio`;if(n!==void 0){if(o.has(n))return`video`;if(s.has(n))return`audio`}return`image`}var l=1;function u(e){if(!e)return l;let t=e.match(/^(\d+)x(\d+)$/);if(!t)return l;let n=parseInt(t[1],10),r=parseInt(t[2],10);return!n||!r?l:n/r}function d(e){return e.match(/https?:\/\/[^\s]+\.(jpg|jpeg|png|gif|webp|svg|mp4|webm|mov|qt|mp3|mpga|ogg|flac|wav|aac|opus)(\?[^\s]*)?/gi)??[]}function f(e,i){let a=[];for(let{uri:o}of n(e)){let e=r(o.ext);if(!/^(image|video|audio)\//.test(e))continue;let[n]=t(o,i);n&&a.push(n)}return a}function p(t,n=[]){let r=i(t.tags).flatMap(t=>{let r=e(t.url,n);return r?[{...t,url:r}]:[]}),o=a(t);if(r.length>0){let e=r[0],n=c(e.url,e.mime,t.kind);return{url:e.url,type:n,blurhash:e.blurhash,dim:e.dim,alt:e.alt,mime:e.mime,encryption:e.encryption,allUrls:r.map(e=>e.url),allTypes:r.map(e=>c(e.url,e.mime,t.kind)),allDims:r.map(e=>e.dim),allEncryption:r.map(e=>e.encryption),event:t,hasMultiple:r.length>1,contentWarning:o}}if(t.kind===1){let e=[...d(t.content),...f(t.content,n)];if(e.length>0){let n=e.map(e=>c(e));return{url:e[0],type:n[0],allUrls:e,allTypes:n,allDims:e.map(()=>void 0),allEncryption:e.map(()=>void 0),event:t,hasMultiple:e.length>1,contentWarning:o}}}return null}export{u as n,p as t};
// @license-end
