@uploadcare/file-uploader
Version:
Building blocks for Uploadcare products integration
8 lines • 23.6 kB
JavaScript
/**
* @license
* Package: @uploadcare/file-uploader@1.28.0 (MIT)
* License: https://github.com/uploadcare/blob/main/LICENSE
* Built: 2026-04-03T13:58:13.094Z
*/
var Kt=n=>{if(typeof n!="string"||!n)return "";let t=n.trim();return t.startsWith("-/")?t=t.slice(2):t.startsWith("/")&&(t=t.slice(1)),t.endsWith("/")&&(t=t.slice(0,t.length-1)),t},Vt=(...n)=>n.filter(t=>typeof t=="string"&&!!t).map(t=>Kt(t)).join("/-/"),lt=(...n)=>{let t=Vt(...n);return t?`-/${t}/`:""};function ct(n){let t=new URL(n),e=t.pathname+t.search+t.hash,s=e.lastIndexOf("http"),i=e.lastIndexOf("/"),r="";return s>=0?r=e.slice(s):i>=0&&(r=e.slice(i+1)),r}function Bt(n){let t=new URL(n),e=ct(n),s=ht(e)?pt(e).pathname:e;return t.pathname=t.pathname.replace(s,""),t.search="",t.hash="",t.toString()}function ht(n){return n.startsWith("http")}function pt(n){let t=new URL(n);return {pathname:`${t.origin}${t.pathname??""}`,search:t.search??"",hash:t.hash??""}}var S=(n,t,e)=>{let s=new URL(Bt(n)),i=e??ct(n),r=t??"";if(s.pathname.startsWith("//")&&(s.pathname=s.pathname.replace("//","/")),i&&ht(i)){let o=pt(i);s.pathname=`${s.pathname}${r}${o.pathname||""}`,s.search=o.search,s.hash=o.hash;}else s.pathname=`${s.pathname}${r}${i||""}`;return s.toString()},H=(n,t)=>{let e=new URL(n);return e.pathname=`${t}/`,e.toString()};var dt=(n,t=",")=>n.trim().split(t).map(e=>e.trim()).filter(e=>e.length>0);var Ht=n=>n;function ut(n,t={},e={}){let{openToken:s="{{",closeToken:i="}}",transform:r=Ht}=e;for(let o in t){let l=t[o],a=l?.toString(),h=typeof a=="string"?r(a):String(a);n=n.replaceAll(s+o+i,h);}return n}var mt=n=>[...new Set(n)];var b="--uc-img-",W="unresolved";var F=!window.location.host.trim()||window.location.host.includes(":")||window.location.hostname.includes("localhost"),Q=3e3,q=5e3,G=Object.freeze({PREVIEW:"PREVIEW",MAIN:"MAIN"});var L=globalThis,j=L.ShadowRoot&&(L.ShadyCSS===void 0||L.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,gt=Symbol(),ft=new WeakMap,k=class{constructor(t,e,s){if(this.St=true,s!==gt)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o,e=this.t;if(j&&t===void 0){let s=e!==void 0&&e.length===1;s&&(t=ft.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&ft.set(e,t));}return t}toString(){return this.cssText}},yt=n=>new k(typeof n=="string"?n:n+"",void 0,gt);var bt=(n,t)=>{if(j)n.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(let e of t){let s=document.createElement("style"),i=L.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,n.appendChild(s);}},J=j?n=>n:n=>n instanceof CSSStyleSheet?(t=>{let e="";for(let s of t.cssRules)e+=s.cssText;return yt(e)})(n):n;var{is:Wt,defineProperty:Ft,getOwnPropertyDescriptor:Qt,getOwnPropertyNames:qt,getOwnPropertySymbols:Gt,getPrototypeOf:Jt}=Object,N=globalThis,vt=N.trustedTypes,Xt=vt?vt.emptyScript:"",Zt=N.reactiveElementPolyfillSupport,$=(n,t)=>n,X={toAttribute(n,t){switch(t){case Boolean:n=n?Xt:null;break;case Object:case Array:n=n==null?n:JSON.stringify(n);}return n},fromAttribute(n,t){let e=n;switch(t){case Boolean:e=n!==null;break;case Number:e=n===null?null:Number(n);break;case Object:case Array:try{e=JSON.parse(n);}catch{e=null;}}return e}},wt=(n,t)=>!Wt(n,t),xt={attribute:true,type:String,converter:X,reflect:false,useDefault:false,hasChanged:wt};Symbol.metadata??=Symbol("metadata"),N.litPropertyMetadata??=new WeakMap;var m=class extends HTMLElement{static addInitializer(t){this.G(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this.S&&[...this.S.keys()]}static createProperty(t,e=xt){if(e.state&&(e.attribute=false),this.G(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=true),this.elementProperties.set(t,e),!e.noAccessor){let s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&Ft(this.prototype,t,i);}}static getPropertyDescriptor(t,e,s){let{get:i,set:r}=Qt(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o;}};return {get:i,set(o){let l=i?.call(this);r?.call(this,o),this.requestUpdate(t,l,s);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??xt}static G(){if(this.hasOwnProperty($("elementProperties")))return;let t=Jt(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty($("finalized")))return;if(this.finalized=true,this.G(),this.hasOwnProperty($("properties"))){let e=this.properties,s=[...qt(e),...Gt(e)];for(let i of s)this.createProperty(i,e[i]);}let t=this[Symbol.metadata];if(t!==null){let e=litPropertyMetadata.get(t);if(e!==void 0)for(let[s,i]of e)this.elementProperties.set(s,i);}this.S=new Map;for(let[e,s]of this.elementProperties){let i=this.J(e,s);i!==void 0&&this.S.set(i,e);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(t){let e=[];if(Array.isArray(t)){let s=new Set(t.flat(1/0).reverse());for(let i of s)e.unshift(J(i));}else t!==void 0&&e.push(J(t));return e}static J(t,e){let s=e.attribute;return s===false?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._=void 0,this.isUpdatePending=false,this.hasUpdated=false,this.f=null,this.Ct();}Ct(){this.X=new Promise(t=>this.enableUpdating=t),this.c=new Map,this.Tt(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this));}addController(t){(this.x??=new Set).add(t),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.();}removeController(t){this.x?.delete(t);}Tt(){let t=new Map,e=this.constructor.elementProperties;for(let s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._=t);}createRenderRoot(){let t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return bt(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this.x?.forEach(t=>t.hostConnected?.());}enableUpdating(t){}disconnectedCallback(){this.x?.forEach(t=>t.hostDisconnected?.());}attributeChangedCallback(t,e,s){this.Z(t,s);}Pt(t,e){let s=this.constructor.elementProperties.get(t),i=this.constructor.J(t,s);if(i!==void 0&&s.reflect===true){let r=(s.converter?.toAttribute!==void 0?s.converter:X).toAttribute(e,s.type);this.f=t,r==null?this.removeAttribute(i):this.setAttribute(i,r),this.f=null;}}Z(t,e){let s=this.constructor,i=s.S.get(t);if(i!==void 0&&this.f!==i){let r=s.getPropertyOptions(i),o=typeof r.converter=="function"?{fromAttribute:r.converter}:r.converter?.fromAttribute!==void 0?r.converter:X;this.f=i;let l=o.fromAttribute(e,r.type);this[i]=l??this.Y?.get(i)??l,this.f=null;}}requestUpdate(t,e,s,i=false,r){if(t!==void 0){let o=this.constructor;if(i===false&&(r=this[t]),s??=o.getPropertyOptions(t),!((s.hasChanged??wt)(r,e)||s.useDefault&&s.reflect&&r===this.Y?.get(t)&&!this.hasAttribute(o.J(t,s))))return;this.C(t,e,s);}this.isUpdatePending===false&&(this.X=this.$t());}C(t,e,{useDefault:s,reflect:i,wrapped:r},o){s&&!(this.Y??=new Map).has(t)&&(this.Y.set(t,o??e??this[t]),r!==true||o!==void 0)||(this.c.has(t)||(this.hasUpdated||s||(e=void 0),this.c.set(t,e)),i===true&&this.f!==t&&(this.lt??=new Set).add(t));}async $t(){this.isUpdatePending=true;try{await this.X;}catch(e){Promise.reject(e);}let t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._){for(let[i,r]of this._)this[i]=r;this._=void 0;}let s=this.constructor.elementProperties;if(s.size>0)for(let[i,r]of s){let{wrapped:o}=r,l=this[i];o!==true||this.c.has(i)||l===void 0||this.C(i,void 0,r,l);}}let t=false,e=this.c;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this.x?.forEach(s=>s.hostUpdate?.()),this.update(e)):this.tt();}catch(s){throw t=false,this.tt(),s}t&&this.Ot(e);}willUpdate(t){}Ot(t){this.x?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}tt(){this.c=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this.X}shouldUpdate(t){return true}update(t){this.lt&&=this.lt.forEach(e=>this.Pt(e,this[e])),this.tt();}updated(t){}firstUpdated(t){}};m.elementStyles=[],m.shadowRootOptions={mode:"open"},m[$("elementProperties")]=new Map,m[$("finalized")]=new Map,Zt?.({ReactiveElement:m}),(N.reactiveElementVersions??=[]).push("2.1.2");var nt=globalThis,Et=n=>n,_=nt.trustedTypes,St=_?_.createPolicy("lit-html",{createHTML:n=>n}):void 0,At="$lit$",g=`lit$${Math.random().toFixed(9).slice(2)}$`,Ut="?"+g,Yt=`<${Ut}>`,w=document,A=()=>w.createComment(""),U=n=>n===null||typeof n!="object"&&typeof n!="function",rt=Array.isArray,te=n=>rt(n)||typeof n?.[Symbol.iterator]=="function",Z=`[ \f\r]`,O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Ct=/-->/g,Tt=/>/g,v=RegExp(`>|${Z}(?:([^\\s"'>=/]+)(${Z}*=${Z}*(?:[^ \f\r"'\`<>=]|("|')|))|$)`,"g"),Pt=/'/g,$t=/"/g,Rt=/^(?:script|style|textarea|title)$/i,E=Symbol.for("lit-noChange"),d=Symbol.for("lit-nothing"),Ot=new WeakMap,x=w.createTreeWalker(w,129);function Mt(n,t){if(!rt(n)||!n.hasOwnProperty("raw"))throw Error("invalid template strings array");return St!==void 0?St.createHTML(t):t}var ee=(n,t)=>{let e=n.length-1,s=[],i,r=t===2?"<svg>":t===3?"<math>":"",o=O;for(let l=0;l<e;l++){let a=n[l],h,p,c=-1,u=0;for(;u<a.length&&(o.lastIndex=u,p=o.exec(a),p!==null);)u=o.lastIndex,o===O?p[1]==="!--"?o=Ct:p[1]!==void 0?o=Tt:p[2]!==void 0?(Rt.test(p[2])&&(i=RegExp("</"+p[2],"g")),o=v):p[3]!==void 0&&(o=v):o===v?p[0]===">"?(o=i??O,c=-1):p[1]===void 0?c=-2:(c=o.lastIndex-p[2].length,h=p[1],o=p[3]===void 0?v:p[3]==='"'?$t:Pt):o===$t||o===Pt?o=v:o===Ct||o===Tt?o=O:(o=v,i=void 0);let f=o===v&&n[l+1].startsWith("/>")?" ":"";r+=o===O?a+Yt:c>=0?(s.push(h),a.slice(0,c)+At+a.slice(c)+g+f):a+g+(c===-2?l:f);}return [Mt(n,r+(n[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]},R=class n{constructor({strings:t,et:e},s){let i;this.parts=[];let r=0,o=0,l=t.length-1,a=this.parts,[h,p]=ee(t,e);if(this.el=n.createElement(h,s),x.currentNode=this.el.content,e===2||e===3){let c=this.el.content.firstChild;c.replaceWith(...c.childNodes);}for(;(i=x.nextNode())!==null&&a.length<l;){if(i.nodeType===1){if(i.hasAttributes())for(let c of i.getAttributeNames())if(c.endsWith(At)){let u=p[o++],f=i.getAttribute(c).split(g),I=/([.?@])?(.*)/.exec(u);a.push({type:1,index:r,name:I[2],strings:f,ctor:I[1]==="."?tt:I[1]==="?"?et:I[1]==="@"?st:T}),i.removeAttribute(c);}else c.startsWith(g)&&(a.push({type:6,index:r}),i.removeAttribute(c));if(Rt.test(i.tagName)){let c=i.textContent.split(g),u=c.length-1;if(u>0){i.textContent=_?_.emptyScript:"";for(let f=0;f<u;f++)i.append(c[f],A()),x.nextNode(),a.push({type:2,index:++r});i.append(c[u],A());}}}else if(i.nodeType===8)if(i.data===Ut)a.push({type:2,index:r});else {let c=-1;for(;(c=i.data.indexOf(g,c+1))!==-1;)a.push({type:7,index:r}),c+=g.length-1;}r++;}}static createElement(t,e){let s=w.createElement("template");return s.innerHTML=t,s}};function C(n,t,e=n,s){if(t===E)return t;let i=s!==void 0?e.At?.[s]:e.Ut,r=U(t)?void 0:t.zt;return i?.constructor!==r&&(i?.Kt?.(false),r===void 0?i=void 0:(i=new r(n),i.Vt(n,e,s)),s!==void 0?(e.At??=[])[s]=i:e.Ut=i),i!==void 0&&(t=C(n,i.Bt(n,t.values),i,s)),t}var Y=class{constructor(t,e){this.ct=[],this.st=void 0,this.ht=t,this.i=e;}get parentNode(){return this.i.parentNode}get d(){return this.i.d}u(t){let{el:{content:e},parts:s}=this.ht,i=(t?.creationScope??w).importNode(e,true);x.currentNode=i;let r=x.nextNode(),o=0,l=0,a=s[0];for(;a!==void 0;){if(o===a.index){let h;a.type===2?h=new M(r,r.nextSibling,this,t):a.type===1?h=new a.ctor(r,a.name,a.strings,this,t):a.type===6&&(h=new it(r,this,t)),this.ct.push(h),a=s[++l];}o!==a?.index&&(r=x.nextNode(),o++);}return x.currentNode=w,i}p(t){let e=0;for(let s of this.ct)s!==void 0&&(s.strings!==void 0?(s.m(t,s,e),e+=s.strings.length-2):s.m(t[e])),e++;}},M=class n{get d(){return this.i?.d??this.pt}constructor(t,e,s,i){this.type=2,this.e=d,this.st=void 0,this.w=t,this.z=e,this.i=s,this.options=i,this.pt=i?.isConnected??true;}get parentNode(){let t=this.w.parentNode,e=this.i;return e!==void 0&&t?.nodeType===11&&(t=e.parentNode),t}get startNode(){return this.w}get endNode(){return this.z}m(t,e=this){t=C(this,t,e),U(t)?t===d||t==null||t===""?(this.e!==d&&this.K(),this.e=d):t!==this.e&&t!==E&&this.dt(t):t.et!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):te(t)?this.k(t):this.dt(t);}O(t){return this.w.parentNode.insertBefore(t,this.z)}T(t){this.e!==t&&(this.K(),this.e=this.O(t));}dt(t){this.e!==d&&U(this.e)?this.w.nextSibling.data=t:this.T(w.createTextNode(t)),this.e=t;}$(t){let{values:e,et:s}=t,i=typeof s=="number"?this.Rt(t):(s.el===void 0&&(s.el=R.createElement(Mt(s.h,s.h[0]),this.options)),s);if(this.e?.ht===i)this.e.p(e);else {let r=new Y(i,this),o=r.u(this.options);r.p(e),this.T(o),this.e=r;}}Rt(t){let e=Ot.get(t.strings);return e===void 0&&Ot.set(t.strings,e=new R(t)),e}k(t){rt(this.e)||(this.e=[],this.K());let e=this.e,s,i=0;for(let r of t)i===e.length?e.push(s=new n(this.O(A()),this.O(A()),this,this.options)):s=e[i],s.m(r),i++;i<e.length&&(this.K(s&&s.z.nextSibling,i),e.length=i);}K(t=this.w.nextSibling,e){for(this.Mt?.(false,true,e);t!==this.z;){let s=Et(t).nextSibling;Et(t).remove(),t=s;}}setConnected(t){this.i===void 0&&(this.pt=t,this.Mt?.(t));}},T=class{get tagName(){return this.element.tagName}get d(){return this.i.d}constructor(t,e,s,i,r){this.type=1,this.e=d,this.st=void 0,this.element=t,this.name=e,this.i=i,this.options=r,s.length>2||s[0]!==""||s[1]!==""?(this.e=Array(s.length-1).fill(new String),this.strings=s):this.e=d;}m(t,e=this,s,i){let r=this.strings,o=false;if(r===void 0)t=C(this,t,e,0),o=!U(t)||t!==this.e&&t!==E,o&&(this.e=t);else {let l=t,a,h;for(t=r[0],a=0;a<r.length-1;a++)h=C(this,l[s+a],e,a),h===E&&(h=this.e[a]),o||=!U(h)||h!==this.e[a],h===d?t=d:t!==d&&(t+=(h??"")+r[a+1]),this.e[a]=h;}o&&!i&&this.j(t);}j(t){t===d?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}},tt=class extends T{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===d?void 0:t;}},et=class extends T{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==d);}},st=class extends T{constructor(t,e,s,i,r){super(t,e,s,i,r),this.type=5;}m(t,e=this){if((t=C(this,t,e,0)??d)===E)return;let s=this.e,i=t===d&&s!==d||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,r=t!==d&&(s===d||i);i&&this.element.removeEventListener(this.name,this,s),r&&this.element.addEventListener(this.name,this,t),this.e=t;}handleEvent(t){typeof this.e=="function"?this.e.call(this.options?.host??this.element,t):this.e.handleEvent(t);}},it=class{constructor(t,e,s){this.element=t,this.type=6,this.st=void 0,this.i=e,this.options=s;}get d(){return this.i.d}m(t){C(this,t);}};var se=nt.litHtmlPolyfillSupport;se?.(R,M),(nt.litHtmlVersions??=[]).push("3.3.2");var It=(n,t,e)=>{let s=e?.renderBefore??t,i=s.It;if(i===void 0){let r=e?.renderBefore??null;s.It=i=new M(t.insertBefore(A(),r),r,void 0,e??{});}return i.m(n),i};var at=globalThis,y=class extends m{constructor(){super(...arguments),this.renderOptions={host:this},this.it=void 0;}createRenderRoot(){let t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){let e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this.it=It(e,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this.it?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this.it?.setConnected(false);}render(){return E}};y.Ht=true,y.finalized=true,at.litElementHydrateSupport?.({LitElement:y});var ie=at.litElementPolyfillSupport;ie?.({LitElement:y});(at.litElementVersions??=[]).push("4.2.2");var Lt="1.28.0";var kt="blocks",jt=Lt;var re=/\\([0-9a-fA-F]{1,6} ?)/g;function oe(n){return n.length<2?false:(n[0]==='"'||n[0]==="'")&&(n[n.length-1]==='"'||n[n.length-1]==="'")}function ae(n){let t=n;return (t[0]==='"'||t[0]==="'")&&(t=t.slice(1)),(t[t.length-1]==='"'||t[t.length-1]==="'")&&(t=t.slice(0,-1)),t}function le(n){let t="",e="";for(let s=0;s<n.length;s++){let i=n[s+1];n[s]==="\\"&&i==='"'?(t+='\\"',s++):n[s]==='"'&&e!=="\\"?t+='\\"':t+=n[s],e=n[s]??"";}return t}function Nt(n){let t=n;oe(n)&&(t=ae(t),t=t.replace(re,(e,s)=>String.fromCodePoint(parseInt(s.trim(),16))),t=t.replaceAll(`\\ `,"\\n"),t=le(t),t='"'+t+'"');try{return JSON.parse(t)}catch{return}}function _t(n){class t extends n{constructor(){super(...arguments);this.ut=null;this.nt=null;}getCssData(i,r=false){let o=this.ut??Object.create(null);if(!Object.keys(o).includes(i)||!o[i]){this.nt||(this.nt=window.getComputedStyle(this));let l=this.nt.getPropertyValue(i).trim();try{o[i]=Nt(l);}catch(a){r||console.warn(`CSS Data error: ${i}`,a),o[i]=null;}}return this.ut=o,o[i]}}return t}function Dt(n){class t extends n{static reg(s){let i=this,r=window.customElements.get(s);if(r){r!==i&&console.warn([`Element with tag name "${s}" already registered.`,`You're trying to override it with another class "${this.name}".`,"This is most likely a mistake.","New element will not be registered."].join(` `));return}window.customElements.define(s,i);}}return t}var ce="https://ucarecdn.com",P=Object.freeze({"dev-mode":{},pubkey:{},uuid:{},src:{},lazy:{default:1},intersection:{},breakpoints:{},"cdn-cname":{default:ce},"proxy-cname":{},"secure-delivery-proxy":{},"hi-res-support":{default:1},"ultra-res-support":{},format:{},"cdn-operations":{},progressive:{},quality:{},"is-background-for":{},"is-preview-blur":{default:1}});var D=class extends _t(Dt(y)){constructor(){super();this.g={};this.y=new Map;this.b=null;this.W=null;for(let e in P){let s=P[e];this.g[b+e]=s?.default||"";}}createRenderRoot(){return this}$$(e){return this.g[b+e]}set$$(e){for(let s in e){let i=b+s,r=e[s];this.g[i]=r,this.mt(i,r);}}sub$$(e,s){let i=b+e;this.y.has(i)||this.y.set(i,new Set),this.y.get(i)?.add(s);let r=this.g[i];r!==null&&r!==""&&s(r);}mt(e,s){this.y.has(e)&&this.y.get(e)?.forEach(i=>{s===null||s===""||i(s);});}analyticsParams(){return `-/@clib/${kt}/${jt}/uc-img/`}initAttributes(e){Array.from(this.attributes).forEach(s=>{let i=s;P[i.name]||e.setAttribute(i.name,i.value);});}initIntersection(e,s){let i={root:null,rootMargin:"0px"};this.b=new IntersectionObserver(r=>{r.forEach(o=>{o.isIntersecting&&(s(),this.b?.unobserve(e));});},i),this.b.observe(e),this.W||(this.W=new Set),this.W.add(e);}connectedCallback(){super.connectedCallback(),this.Lt();}Lt(){for(let e in P){let s=b+e,i=this.getCssData(s,true);i!=null&&(this.g[s]=i);}}disconnectedCallback(){super.disconnectedCallback(),this.b&&(this.W?.forEach(e=>{this.b?.unobserve(e);}),this.b=null),this.y.clear();}static get observedAttributes(){return Object.keys(P)}attributeChangedCallback(e,s,i){window.setTimeout(()=>{let r=b+e;this.g[r]=i,this.mt(r,i);});}};var zt=n=>Object.entries(n).filter(([t,e])=>e!==void 0&&e!=="").map(([t,e])=>t==="cdn-operations"||t==="analytics"?e:`${t}/${e}`);var V=class extends D{constructor(){super(...arguments);this.r=new Image;this.n=new Image;}ft(e){return !e.includes("//")&&!F&&(e=new URL(e,document.baseURI).href),e}Q(e){if(!e)return;let s=e,i=s.match(/\d+/)?.[0],r=s.match(/[a-zA-Z]+/)?.[0];if(!i||!r)return;let o=parseInt(i,10);return Number(o)>q&&this.gt?q+r:Number(o)>Q&&!this.gt?Q+r:e}kt(e,s){let i={format:this.rt("format"),quality:this.rt("quality"),resize:this.Q(e),blur:s,"cdn-operations":this.rt("cdn-operations")??void 0,analytics:this.analyticsParams()};return lt(...zt(i))}rt(e){let s=this.$$(e);if(s==null||typeof s=="string"||typeof s=="number"||typeof s=="boolean")return s}s(e="",s=""){let i=this.$$("src");if(i.startsWith("data:")||i.startsWith("blob:"))return i;if(F&&i&&!i.includes("//"))return this.E(i);let r=this.kt(e,s),o=this.$$("cdn-cname"),l=o;if(i.startsWith(String(o)))return S(i,r);let a=this.$$("uuid");if(l&&a)return this.E(S(H(l,a),r));if(a)return this.E(S(H(l,a),r));let h=this.$$("proxy-cname");if(h)return this.E(S(h,r,this.ft(i)));let p=this.$$("pubkey");if(p)return this.E(S(`https://${p}.ucr.io/`,r,this.ft(i)))}E(e){let s=this.$$("secure-delivery-proxy");return s?ut(s,{previewUrl:e},{transform:i=>window.encodeURIComponent(i)}):e}v(e,s=1,i=true){let r=e.getBoundingClientRect(),o=s*Math.round(r.width),l=i?"":s*Math.round(r.height);return o||l?`${o||""}x${l||""}`:null}jt(e){let s=r=>{r.stopPropagation();let o=new Event(r.type,r);this.dispatchEvent(o);},i=["load","error"];for(let r of i)e.addEventListener(r,s);}get img(){return this.a||(this.ot({elNode:this.r}),this.appendChild(this.r)),this.r}get q(){return this.a?{type:G.PREVIEW,img:this.n}:{type:G.MAIN,img:this.img}}get a(){return this.$$("is-preview-blur")}get yt(){return this.$$("is-background-for")}get bt(){let e=this.$$("breakpoints");if(e){let s=dt(e);return mt(s.map(i=>parseInt(i,10)))}else return null}get gt(){return this.$$("format").toLowerCase()==="jpeg"}vt(e){let s=new Set;s.add(`url("${this.s(this.v(e))}") 1x`),this.$$("hi-res-support")&&s.add(`url("${this.s(this.v(e,2))}") ${2}x`),this.$$("ultra-res-support")&&s.add(`url("${this.s(this.v(e,3))}") ${3}x`);let i=`image-set(${[...s].join(", ")})`;e.style.setProperty("background-image",i),e.style.setProperty("background-image",`-webkit-${i}`);}xt(){let e=new Set;return this.bt?this.bt.forEach(s=>{e.add(`${this.s(`${s}x`)} ${this.Q(`${s}w`)}`),this.$$("hi-res-support")&&e.add(`${this.s(`${s*2}x`)} ${this.Q(`${s*2}w`)}`),this.$$("ultra-res-support")&&e.add(`${this.s(`${s*3}x`)} ${this.Q(`${s*3}w`)}`);}):(e.add(`${this.s(this.v(this.q.img))} 1x`),this.$$("hi-res-support")&&e.add(`${this.s(this.v(this.q.img,2))} 2x`),this.$$("ultra-res-support")&&e.add(`${this.s(this.v(this.q.img,3))} 3x`)),[...e].join()}wt(){return this.s()}get Et(){return this.s("100x","100")}Nt(){let e=this.yt;[...document.querySelectorAll(e)].forEach(s=>{this.$$("intersection")?this.initIntersection(s,()=>{this.vt(s);}):this.vt(s);});}_t({elNode:e,src:s,srcset:i}){s&&(e.src=s),i&&(e.srcset=i);}ot({elNode:e}){this.jt(e),this.initAttributes(e);}at({src:e,srcset:s,elNode:i}){return new Promise((r,o)=>{this.ot({elNode:i}),i.setAttribute(W,""),i.addEventListener("load",()=>{i.removeAttribute(W),r(i);}),i.addEventListener("error",()=>{o(false);}),this._t({elNode:i,src:e,srcset:s});})}async Dt(){if(this.$$("intersection")){this.a&&(this.ot({elNode:this.n}),this.appendChild(this.n)),this.initIntersection(this.q.img,async()=>{this.a&&(this.n.src=this.Et);try{await this.at({src:this.wt(),srcset:this.xt(),elNode:this.r}),this.a&&await this.n.remove(),this.appendChild(this.r);}catch{this.a&&await this.n?.remove(),this.appendChild(this.r);}});return}try{this.a&&(await this.at({src:this.Et,elNode:this.n}),this.appendChild(this.n)),await this.at({src:this.wt(),srcset:this.xt(),elNode:this.r}),this.a&&await this.n?.remove(),this.appendChild(this.r);}catch{this.a&&await this.n?.remove(),this.appendChild(this.r);}}init(){this.yt?this.Nt():this.Dt();}};var B=class extends V{connectedCallback(){super.connectedCallback(),this.sub$$("src",()=>{this.init();}),this.sub$$("uuid",()=>{this.init();}),this.sub$$("lazy",t=>{!this.$$("is-background-for")&&!this.$$("is-preview-blur")&&(this.img.loading=t?"lazy":"eager");});}};B.reg("uc-img");/*! For license information please see uc-img.min.js.LEGAL.txt */
export{B as Img};