@uploadcare/file-uploader
Version:
Building blocks for Uploadcare products integration
29 lines • 134 kB
JavaScript
/**
* @license
* MIT License
*
* Copyright (c) 2025 Uploadcare (hello@uploadcare.com). All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
var er=Object.defineProperty;var tr=Object.getPrototypeOf;var ir=Reflect.get;var rr=(r,t,e)=>t in r?er(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var f=(r,t,e)=>rr(r,typeof t!="symbol"?t+"":t,e);var Mt=(r,t,e)=>ir(tr(r),e,t);var sr=Object.defineProperty,or=(r,t,e)=>t in r?sr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,st=(r,t,e)=>(or(r,typeof t!="symbol"?t+"":t,e),e);function nr(r){let t=e=>{var i;for(let s in e)((i=e[s])==null?void 0:i.constructor)===Object&&(e[s]=t(e[s]));return{...e}};return t(r)}var E=class{constructor(r){r.constructor===Object?this.store=nr(r):(this._storeIsProxy=!0,this.store=r),this.callbackMap=Object.create(null)}static warn(r,t){console.warn(`Symbiote Data: cannot ${r}. Prop name: `+t)}read(r){return!this._storeIsProxy&&!this.store.hasOwnProperty(r)?(E.warn("read",r),null):this.store[r]}has(r){return this._storeIsProxy?this.store[r]!==void 0:this.store.hasOwnProperty(r)}add(r,t,e=!1){!e&&Object.keys(this.store).includes(r)||(this.store[r]=t,this.notify(r))}pub(r,t){if(!this._storeIsProxy&&!this.store.hasOwnProperty(r)){E.warn("publish",r);return}this.store[r]=t,this.notify(r)}multiPub(r){for(let t in r)this.pub(t,r[t])}notify(r){this.callbackMap[r]&&this.callbackMap[r].forEach(t=>{t(this.store[r])})}sub(r,t,e=!0){return!this._storeIsProxy&&!this.store.hasOwnProperty(r)?(E.warn("subscribe",r),null):(this.callbackMap[r]||(this.callbackMap[r]=new Set),this.callbackMap[r].add(t),e&&t(this.store[r]),{remove:()=>{this.callbackMap[r].delete(t),this.callbackMap[r].size||delete this.callbackMap[r]},callback:t})}static registerCtx(r,t=Symbol()){let e=E.globalStore.get(t);return e?console.warn('State: context UID "'+t+'" already in use'):(e=new E(r),E.globalStore.set(t,e)),e}static deleteCtx(r){E.globalStore.delete(r)}static getCtx(r,t=!0){return E.globalStore.get(r)||(t&&console.warn('State: wrong context UID - "'+r+'"'),null)}};E.globalStore=new Map;var _=Object.freeze({BIND_ATTR:"set",ATTR_BIND_PRFX:"@",EXT_DATA_CTX_PRFX:"*",NAMED_DATA_CTX_SPLTR:"/",CTX_NAME_ATTR:"ctx-name",CTX_OWNER_ATTR:"ctx-owner",CSS_CTX_PROP:"--ctx-name",EL_REF_ATTR:"ref",AUTO_TAG_PRFX:"sym",REPEAT_ATTR:"repeat",REPEAT_ITEM_TAG_ATTR:"repeat-item-tag",SET_LATER_KEY:"__toSetLater__",USE_TPL:"use-template",ROOT_STYLE_ATTR_NAME:"sym-component"}),Dt="1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm",ar=Dt.length-1,ot=class{static generate(r="XXXXXXXXX-XXX"){let t="";for(let e=0;e<r.length;e++)t+=r[e]==="-"?r[e]:Dt.charAt(Math.random()*ar);return t}};function Ft(r,t,e){let i=!0,s,o=t.split(".");return o.forEach((n,a)=>{a<o.length-1?r=r[n]:s=n}),r?r[s]=e:i=!1,i}function lr(r){return r.split("-").map((t,e)=>t&&e?t[0].toUpperCase()+t.slice(1):t).join("").split("_").map((t,e)=>t&&e?t.toUpperCase():t).join("")}function cr(r,t){[...r.querySelectorAll(`[${_.REPEAT_ATTR}]`)].forEach(e=>{let i=e.getAttribute(_.REPEAT_ITEM_TAG_ATTR),s;if(i&&(s=window.customElements.get(i)),!s){s=class extends t.BaseComponent{constructor(){super(),i||(this.style.display="contents")}};let n=e.innerHTML;s.template=n,s.reg(i)}for(;e.firstChild;)e.firstChild.remove();let o=e.getAttribute(_.REPEAT_ATTR);t.sub(o,n=>{if(!n){for(;e.firstChild;)e.firstChild.remove();return}let a=[...e.children],l,c=h=>{h.forEach((d,p)=>{if(a[p])if(a[p].set$)setTimeout(()=>{a[p].set$(d)});else for(let g in d)a[p][g]=d[g];else{l||(l=new DocumentFragment);let g=new s;Object.assign(g.init$,d),l.appendChild(g)}}),l&&e.appendChild(l);let u=a.slice(h.length,a.length);for(let d of u)d.remove()};if(n.constructor===Array)c(n);else if(n.constructor===Object){let h=[];for(let u in n){let d=n[u];Object.defineProperty(d,"_KEY_",{value:u,enumerable:!0}),h.push(d)}c(h)}else console.warn("Symbiote repeat data type error:"),console.log(n)}),e.removeAttribute(_.REPEAT_ATTR),e.removeAttribute(_.REPEAT_ITEM_TAG_ATTR)})}var Nt="__default__";function ur(r,t){if(t.shadowRoot)return;let e=[...r.querySelectorAll("slot")];if(!e.length)return;let i={};e.forEach(s=>{let o=s.getAttribute("name")||Nt;i[o]={slot:s,fr:document.createDocumentFragment()}}),t.initChildren.forEach(s=>{var o;let n=Nt;s instanceof Element&&s.hasAttribute("slot")&&(n=s.getAttribute("slot"),s.removeAttribute("slot")),(o=i[n])==null||o.fr.appendChild(s)}),Object.values(i).forEach(s=>{if(s.fr.childNodes.length)s.slot.parentNode.replaceChild(s.fr,s.slot);else if(s.slot.childNodes.length){let o=document.createDocumentFragment();o.append(...s.slot.childNodes),s.slot.parentNode.replaceChild(o,s.slot)}else s.slot.remove()})}function hr(r,t){[...r.querySelectorAll(`[${_.EL_REF_ATTR}]`)].forEach(e=>{let i=e.getAttribute(_.EL_REF_ATTR);t.ref[i]=e,e.removeAttribute(_.EL_REF_ATTR)})}function dr(r,t){[...r.querySelectorAll(`[${_.BIND_ATTR}]`)].forEach(e=>{let s=e.getAttribute(_.BIND_ATTR).split(";");[...e.attributes].forEach(o=>{if(o.name.startsWith("-")&&o.value){let n=lr(o.name.replace("-",""));s.push(n+":"+o.value),e.removeAttribute(o.name)}}),s.forEach(o=>{if(!o)return;let n=o.split(":").map(h=>h.trim()),a=n[0],l;a.indexOf(_.ATTR_BIND_PRFX)===0&&(l=!0,a=a.replace(_.ATTR_BIND_PRFX,""));let c=n[1].split(",").map(h=>h.trim());for(let h of c){let u;h.startsWith("!!")?(u="double",h=h.replace("!!","")):h.startsWith("!")&&(u="single",h=h.replace("!","")),t.sub(h,d=>{u==="double"?d=!!d:u==="single"&&(d=!d),l?(d==null?void 0:d.constructor)===Boolean?d?e.setAttribute(a,""):e.removeAttribute(a):e.setAttribute(a,d):Ft(e,a,d)||(e[_.SET_LATER_KEY]||(e[_.SET_LATER_KEY]=Object.create(null)),e[_.SET_LATER_KEY][a]=d)})}}),e.removeAttribute(_.BIND_ATTR)})}var $e="{{",de="}}",fr="skip-text";function pr(r){let t,e=[],i=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,{acceptNode:s=>{var o;return!((o=s.parentElement)!=null&&o.hasAttribute(fr))&&s.textContent.includes($e)&&s.textContent.includes(de)&&1}});for(;t=i.nextNode();)e.push(t);return e}var mr=function(r,t){pr(r).forEach(i=>{let s=[],o;for(;i.textContent.includes(de);)i.textContent.startsWith($e)?(o=i.textContent.indexOf(de)+de.length,i.splitText(o),s.push(i)):(o=i.textContent.indexOf($e),i.splitText(o)),i=i.nextSibling;s.forEach(n=>{let a=n.textContent.replace($e,"").replace(de,"");n.textContent="",t.sub(a,l=>{n.textContent=l})})})},_r=[cr,ur,hr,dr,mr],Oe="'",te='"',gr=/\\([0-9a-fA-F]{1,6} ?)/g;function br(r){return(r[0]===te||r[0]===Oe)&&(r[r.length-1]===te||r[r.length-1]===Oe)}function yr(r){return(r[0]===te||r[0]===Oe)&&(r=r.slice(1)),(r[r.length-1]===te||r[r.length-1]===Oe)&&(r=r.slice(0,-1)),r}function vr(r){let t="",e="";for(var i=0;i<r.length;i++){let s=r[i+1];r[i]==="\\"&&s==='"'?(t+='\\"',i++):r[i]==='"'&&e!=="\\"?t+='\\"':t+=r[i],e=r[i]}return t}function wr(r){let t=r;br(r)&&(t=yr(t),t=t.replace(gr,(e,i)=>String.fromCodePoint(parseInt(i.trim(),16))),t=t.replaceAll(`\\
`,"\\n"),t=vr(t),t=te+t+te);try{return JSON.parse(t)}catch{throw new Error(`Failed to parse CSS property value: ${t}. Original input: ${r}`)}}var Ut=0,ee=null,j=null,X=class extends HTMLElement{constructor(){super(),st(this,"updateCssData",()=>{var r;this.dropCssDataCache(),(r=this.__boundCssProps)==null||r.forEach(t=>{let e=this.getCssData(this.__extractCssName(t),!0);e!==null&&this.$[t]!==e&&(this.$[t]=e)})}),this.init$=Object.create(null),this.cssInit$=Object.create(null),this.tplProcessors=new Set,this.ref=Object.create(null),this.allSubs=new Set,this.pauseRender=!1,this.renderShadow=!1,this.readyToDestroy=!0,this.processInnerHtml=!1,this.allowCustomTemplate=!1,this.ctxOwner=!1}get BaseComponent(){return X}initCallback(){}__initCallback(){var r;this.__initialized||(this.__initialized=!0,(r=this.initCallback)==null||r.call(this))}render(r,t=this.renderShadow){let e;if((t||this.constructor.__shadowStylesUrl)&&!this.shadowRoot&&this.attachShadow({mode:"open"}),this.allowCustomTemplate){let s=this.getAttribute(_.USE_TPL);if(s){let o=this.getRootNode(),n=(o==null?void 0:o.querySelector(s))||document.querySelector(s);n?r=n.content.cloneNode(!0):console.warn(`Symbiote template "${s}" is not found...`)}}if(this.processInnerHtml)for(let s of this.tplProcessors)s(this,this);if(r||this.constructor.template){if(this.constructor.template&&!this.constructor.__tpl&&(this.constructor.__tpl=document.createElement("template"),this.constructor.__tpl.innerHTML=this.constructor.template),(r==null?void 0:r.constructor)===DocumentFragment)e=r;else if((r==null?void 0:r.constructor)===String){let s=document.createElement("template");s.innerHTML=r,e=s.content.cloneNode(!0)}else this.constructor.__tpl&&(e=this.constructor.__tpl.content.cloneNode(!0));for(let s of this.tplProcessors)s(e,this)}let i=()=>{e&&(t&&this.shadowRoot.appendChild(e)||this.appendChild(e)),this.__initCallback()};if(this.constructor.__shadowStylesUrl){t=!0;let s=document.createElement("link");s.rel="stylesheet",s.href=this.constructor.__shadowStylesUrl,s.onload=i,this.shadowRoot.prepend(s)}else i()}addTemplateProcessor(r){this.tplProcessors.add(r)}get autoCtxName(){return this.__autoCtxName||(this.__autoCtxName=ot.generate(),this.style.setProperty(_.CSS_CTX_PROP,`'${this.__autoCtxName}'`)),this.__autoCtxName}get cssCtxName(){return this.getCssData(_.CSS_CTX_PROP,!0)}get ctxName(){var r;let t=((r=this.getAttribute(_.CTX_NAME_ATTR))==null?void 0:r.trim())||this.cssCtxName||this.__cachedCtxName||this.autoCtxName;return this.__cachedCtxName=t,t}get localCtx(){return this.__localCtx||(this.__localCtx=E.registerCtx({},this)),this.__localCtx}get nodeCtx(){return E.getCtx(this.ctxName,!1)||E.registerCtx({},this.ctxName)}static __parseProp(r,t){let e,i;if(r.startsWith(_.EXT_DATA_CTX_PRFX))e=t.nodeCtx,i=r.replace(_.EXT_DATA_CTX_PRFX,"");else if(r.includes(_.NAMED_DATA_CTX_SPLTR)){let s=r.split(_.NAMED_DATA_CTX_SPLTR);e=E.getCtx(s[0]),i=s[1]}else e=t.localCtx,i=r;return{ctx:e,name:i}}sub(r,t,e=!0){let i=o=>{this.isConnected&&t(o)},s=X.__parseProp(r,this);s.ctx.has(s.name)?this.allSubs.add(s.ctx.sub(s.name,i,e)):window.setTimeout(()=>{this.allSubs.add(s.ctx.sub(s.name,i,e))})}notify(r){let t=X.__parseProp(r,this);t.ctx.notify(t.name)}has(r){let t=X.__parseProp(r,this);return t.ctx.has(t.name)}add(r,t,e=!1){let i=X.__parseProp(r,this);i.ctx.add(i.name,t,e)}add$(r,t=!1){for(let e in r)this.add(e,r[e],t)}get $(){if(!this.__stateProxy){let r=Object.create(null);this.__stateProxy=new Proxy(r,{set:(t,e,i)=>{let s=X.__parseProp(e,this);return s.ctx.pub(s.name,i),!0},get:(t,e)=>{let i=X.__parseProp(e,this);return i.ctx.read(i.name)}})}return this.__stateProxy}set$(r,t=!1){for(let e in r){let i=r[e];t||![String,Number,Boolean].includes(i==null?void 0:i.constructor)?this.$[e]=i:this.$[e]!==i&&(this.$[e]=i)}}get __ctxOwner(){return this.ctxOwner||this.hasAttribute(_.CTX_OWNER_ATTR)&&this.getAttribute(_.CTX_OWNER_ATTR)!=="false"}__initDataCtx(){let r=this.constructor.__attrDesc;if(r)for(let t of Object.values(r))Object.keys(this.init$).includes(t)||(this.init$[t]="");for(let t in this.init$)if(t.startsWith(_.EXT_DATA_CTX_PRFX))this.nodeCtx.add(t.replace(_.EXT_DATA_CTX_PRFX,""),this.init$[t],this.__ctxOwner);else if(t.includes(_.NAMED_DATA_CTX_SPLTR)){let e=t.split(_.NAMED_DATA_CTX_SPLTR),i=e[0].trim(),s=e[1].trim();if(i&&s){let o=E.getCtx(i,!1);o||(o=E.registerCtx({},i)),o.add(s,this.init$[t])}}else this.localCtx.add(t,this.init$[t]);for(let t in this.cssInit$)this.bindCssData(t,this.cssInit$[t]);this.__dataCtxInitialized=!0}connectedCallback(){var r;if(this.isConnected){if(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),!this.connectedOnce){let t=(r=this.getAttribute(_.CTX_NAME_ATTR))==null?void 0:r.trim();if(t&&this.style.setProperty(_.CSS_CTX_PROP,`'${t}'`),this.__initDataCtx(),this[_.SET_LATER_KEY]){for(let e in this[_.SET_LATER_KEY])Ft(this,e,this[_.SET_LATER_KEY][e]);delete this[_.SET_LATER_KEY]}this.initChildren=[...this.childNodes];for(let e of _r)this.addTemplateProcessor(e);if(this.pauseRender)this.__initCallback();else if(this.constructor.__rootStylesLink){let e=this.getRootNode();if(!e)return;if(e==null?void 0:e.querySelector(`link[${_.ROOT_STYLE_ATTR_NAME}="${this.constructor.is}"]`)){this.render();return}let s=this.constructor.__rootStylesLink.cloneNode(!0);s.setAttribute(_.ROOT_STYLE_ATTR_NAME,this.constructor.is),s.onload=()=>{this.render()},e.nodeType===Node.DOCUMENT_NODE?e.head.appendChild(s):e.prepend(s)}else this.render()}this.connectedOnce=!0}}destroyCallback(){}disconnectedCallback(){this.connectedOnce&&(this.dropCssDataCache(),this.readyToDestroy&&(this.__disconnectTimeout&&window.clearTimeout(this.__disconnectTimeout),this.__disconnectTimeout=window.setTimeout(()=>{this.destroyCallback();for(let r of this.allSubs)r.remove(),this.allSubs.delete(r);for(let r of this.tplProcessors)this.tplProcessors.delete(r);j==null||j.delete(this.updateCssData),j!=null&&j.size||(ee==null||ee.disconnect(),ee=null,j=null)},100)))}static reg(r,t=!1){r||(Ut++,r=`${_.AUTO_TAG_PRFX}-${Ut}`),this.__tag=r;let e=window.customElements.get(r);if(e){!t&&e!==this&&console.warn([`Element with tag name "${r}" 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(r,t?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(r){this.observedAttributes=Object.keys(r),this.__attrDesc=r}attributeChangedCallback(r,t,e){var i;if(t===e)return;let s=(i=this.constructor.__attrDesc)==null?void 0:i[r];s?this.__dataCtxInitialized?this.$[s]=e:this.init$[s]=e:this[r]=e}getCssData(r,t=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(r)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let e=this.__computedStyle.getPropertyValue(r).trim();try{this.__cssDataCache[r]=wr(e)}catch{!t&&console.warn(`CSS Data error: ${r}`),this.__cssDataCache[r]=null}}return this.__cssDataCache[r]}__extractCssName(r){return r.split("--").map((t,e)=>e===0?"":t).join("--")}__initStyleAttrObserver(){j||(j=new Set),j.add(this.updateCssData),ee||(ee=new MutationObserver(r=>{r[0].type==="attributes"&&j.forEach(t=>{t()})}),ee.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(r,t=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(r);let e=this.getCssData(this.__extractCssName(r),!0);e===null&&(e=t),this.add(r,e),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(r,t,e){let i="__"+r;this[i]=this[r],Object.defineProperty(this,r,{set:s=>{this[i]=s,e?window.setTimeout(()=>{t==null||t(s)}):t==null||t(s)},get:()=>this[i]}),this[r]=this[i]}static set shadowStyles(r){let t=new Blob([r],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(t)}static set rootStyles(r){if(!this.__rootStylesLink){let t=new Blob([r],{type:"text/css"}),e=URL.createObjectURL(t),i=document.createElement("link");i.href=e,i.rel="stylesheet",this.__rootStylesLink=i}}},nt=X;st(nt,"template");var rt=class{static _print(r){console.warn(r)}static setDefaultTitle(r){this.defaultTitle=r}static setRoutingMap(r){Object.assign(this.appMap,r);for(let t in this.appMap)!this.defaultRoute&&this.appMap[t].default===!0?this.defaultRoute=t:!this.errorRoute&&this.appMap[t].error===!0&&(this.errorRoute=t)}static set routingEventName(r){this.__routingEventName=r}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let r={route:null,options:{}};return window.location.search.split(this.separator).forEach(e=>{if(e.includes("?"))r.route=e.replace("?","");else if(e.includes("=")){let i=e.split("=");r.options[i[0]]=decodeURI(i[1])}else r.options[e]=!0}),r}static notify(){let r=this.readAddressBar(),t=this.appMap[r.route];if(t&&t.title&&(document.title=t.title),r.route===null&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!t&&this.errorRoute){this.applyRoute(this.errorRoute);return}else if(!t&&this.defaultRoute){this.applyRoute(this.defaultRoute);return}else if(!t){this._print(`Route "${r.route}" not found...`);return}let e=new CustomEvent(rt.routingEventName,{detail:{route:r.route,options:Object.assign(t||{},r.options)}});window.dispatchEvent(e)}static reflect(r,t={}){let e=this.appMap[r];if(!e){this._print("Wrong route: "+r);return}let i="?"+r;for(let o in t)t[o]===!0?i+=this.separator+o:i+=this.separator+o+`=${t[o]}`;let s=e.title||this.defaultTitle||"";window.history.pushState(null,s,i),document.title=s}static applyRoute(r,t={}){this.reflect(r,t),this.notify()}static setSeparator(r){this._separator=r}static get separator(){return this._separator||"&"}static createRouterData(r,t){this.setRoutingMap(t);let e=E.registerCtx({route:null,options:null,title:null},r);return window.addEventListener(this.routingEventName,i=>{var s;e.multiPub({route:i.detail.route,options:i.detail.options,title:((s=i.detail.options)==null?void 0:s.title)||this.defaultTitle||""})}),rt.notify(),this.initPopstateListener(),e}static initPopstateListener(){this.__onPopstate||(this.__onPopstate=()=>{this.notify()},window.addEventListener("popstate",this.__onPopstate))}static removePopstateListener(){window.removeEventListener("popstate",this.__onPopstate),this.__onPopstate=null}};rt.appMap=Object.create(null);var zt="idb-store-ready",Er="symbiote-db",Cr="symbiote-idb-update_",Tr=class{_notifyWhenReady(r=null){window.dispatchEvent(new CustomEvent(zt,{detail:{dbName:this.name,storeName:this.storeName,event:r}}))}get _updEventName(){return Cr+this.name}_getUpdateEvent(r){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:r}})}_notifySubscribers(r){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,r),window.dispatchEvent(this._getUpdateEvent(r))}constructor(r,t){this.name=r,this.storeName=t,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=e=>{this.db=e.target.result,this.objStore=this.db.createObjectStore(t,{keyPath:"_key"}),this.objStore.transaction.oncomplete=i=>{this._notifyWhenReady(i)}},this.request.onsuccess=e=>{this.db=e.target.result,this._notifyWhenReady(e)},this.request.onerror=e=>{console.error(e)},this._subscriptionsMap={},this._updateHandler=e=>{e.key===this.name&&this._subscriptionsMap[e.newValue]&&this._subscriptionsMap[e.newValue].forEach(async s=>{s(await this.read(e.newValue))})},this._localUpdateHandler=e=>{this._updateHandler(e.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(r){let e=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(r);return new Promise((i,s)=>{e.onsuccess=o=>{var n;(n=o.target.result)!=null&&n._value?i(o.target.result._value):(i(null),console.warn(`IDB: cannot read "${r}"`))},e.onerror=o=>{s(o)}})}write(r,t,e=!1){let i={_key:r,_value:t},o=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(i);return new Promise((n,a)=>{o.onsuccess=l=>{e||this._notifySubscribers(r),n(l.target.result)},o.onerror=l=>{a(l)}})}delete(r,t=!1){let i=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(r);return new Promise((s,o)=>{i.onsuccess=n=>{t||this._notifySubscribers(r),s(n)},i.onerror=n=>{o(n)}})}getAll(){let t=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((e,i)=>{t.onsuccess=s=>{let o=s.target.result;e(o.map(n=>n._value))},t.onerror=s=>{i(s)}})}subscribe(r,t){this._subscriptionsMap[r]||(this._subscriptionsMap[r]=new Set);let e=this._subscriptionsMap[r];return e.add(t),{remove:()=>{e.delete(t),e.size||delete this._subscriptionsMap[r]}}}stop(){window.removeEventListener("storage",this._updateHandler),this._subscriptionsMap=null,jt.clear(this.name)}},jt=class{static get readyEventName(){return zt}static open(r=Er,t="store"){let e=r+"/"+t;return this._reg[e]||(this._reg[e]=new Tr(r,t)),this._reg[e]}static clear(r){window.indexedDB.deleteDatabase(r);for(let t in this._reg)t.split("/")[0]===r&&delete this._reg[t]}};st(jt,"_reg",Object.create(null));var Bt=r=>{if(typeof r!="string"||!r)return"";let t=r.trim();return t.startsWith("-/")?t=t.slice(2):t.startsWith("/")&&(t=t.slice(1)),t.endsWith("/")&&(t=t.slice(0,t.length-1)),t},ke=(...r)=>r.filter(t=>typeof t=="string"&&t).map(t=>Bt(t)).join("/-/"),B=(...r)=>{let t=ke(...r);return t?`-/${t}/`:""};function Ie(r){let t=new URL(r),e=t.pathname+t.search+t.hash,i=e.lastIndexOf("http"),s=e.lastIndexOf("/"),o="";return i>=0?o=e.slice(i):s>=0&&(o=e.slice(s+1)),o}function Le(r){let t=new URL(r),{pathname:e}=t,i=e.indexOf("/"),s=e.indexOf("/",i+1);return e.substring(i+1,s)}function at(r){let t=Vt(r),e=new URL(t),i=e.pathname.indexOf("/-/");return i===-1?"":e.pathname.substring(i).slice(1)}function lt(r){return at(r).split("/-/").filter(Boolean).map(e=>Bt(e))}function Vt(r){let t=new URL(r),e=Ie(r),i=Ht(e)?Xt(e).pathname:e;return t.pathname=t.pathname.replace(i,""),t.search="",t.hash="",t.toString()}function Ht(r){return r.startsWith("http")}function Xt(r){let t=new URL(r);return{pathname:t.origin+t.pathname||"",search:t.search||"",hash:t.hash||""}}var V=(r,t,e)=>{let i=new URL(Vt(r));if(e=e||Ie(r),i.pathname.startsWith("//")&&(i.pathname=i.pathname.replace("//","/")),Ht(e)){let s=Xt(e);i.pathname=i.pathname+(t||"")+(s.pathname||""),i.search=s.search,i.hash=s.hash}else i.pathname=i.pathname+(t||"")+(e||"");return i.toString()},ct=(r,t)=>{let e=new URL(r);return e.pathname=t+"/",e.toString()};var fe=(r,t=",")=>r.trim().split(t).map(e=>e.trim()).filter(e=>e.length>0);var L=Object.freeze({brightness:0,exposure:0,gamma:100,contrast:0,saturation:0,vibrance:0,warmth:0,enhance:0,filter:0,rotate:0,mirror:!1,flip:!1,crop:void 0}),Wt=["enhance","brightness","exposure","gamma","contrast","saturation","vibrance","warmth","filter","mirror","flip","rotate","crop"];function xr(r,t){if(typeof t=="number"){let e=t;return L[r]!==e?`${r}/${e}`:""}if(typeof t=="boolean"){let e=t;return L[r]!==e?`${r}`:""}if(r==="filter"&&t){let{name:e,amount:i}=t;return L.filter===i?"":`${r}/${e}/${i}`}if(r==="crop"&&t){let{dimensions:e,coords:i}=t;return`${r}/${e.join("x")}/${i.join(",")}`}return""}function G(r){return ke(...Wt.filter(t=>typeof r[t]!="undefined"&&r[t]!==null).map(t=>{let e=r[t];return xr(t,e)}).filter(t=>!!t))}var Pe=ke("format/auto","progressive/yes"),H=([r])=>typeof r!="undefined"?Number(r):void 0,Gt=()=>!0,Ar=([r,t])=>({name:r,amount:typeof t!="undefined"?Number(t):100}),Sr=([r,t])=>{if(!/\d+x\d+/.test(r)||!/\d+,\d+/.test(t))throw new Error("Crop by aspect ratio, percentage or alignment shortcuts is not supported.");return{dimensions:fe(r,"x").map(Number),coords:fe(t).map(Number)}},$r=Object.freeze({enhance:H,brightness:H,exposure:H,gamma:H,contrast:H,saturation:H,vibrance:H,warmth:H,filter:Ar,mirror:Gt,flip:Gt,rotate:H,crop:Sr});function ut(r){let t={};for(let e of r){let[i,...s]=e.split("/");if(!Wt.includes(i))continue;let o=i,n=$r[o];try{let a=n(s);t[o]=a}catch(a){console.warn([`Failed to parse URL operation "${e}". It will be ignored.`,a instanceof Error?`Error message: "${a.message}"`:a,"If you need this functionality, please feel free to open an issue at https://github.com/uploadcare/blocks/issues/new"].join(`
`))}}return t}var y=Object.freeze({CROP:"crop",TUNING:"tuning",FILTERS:"filters"}),I=[y.CROP,y.TUNING,y.FILTERS],qt=["brightness","exposure","gamma","contrast","saturation","vibrance","warmth","enhance"],Kt=["adaris","briaril","calarel","carris","cynarel","cyren","elmet","elonni","enzana","erydark","fenralan","ferand","galen","gavin","gethriel","iorill","iothari","iselva","jadis","lavra","misiara","namala","nerion","nethari","pamaya","sarnar","sedis","sewen","sorahel","sorlen","tarian","thellassan","varriel","varven","vevera","virkas","yedis","yllara","zatvel","zevcen"],Yt=["rotate","mirror","flip"],U=Object.freeze({brightness:{zero:L.brightness,range:[-100,100],keypointsNumber:2},exposure:{zero:L.exposure,range:[-500,500],keypointsNumber:2},gamma:{zero:L.gamma,range:[0,1e3],keypointsNumber:2},contrast:{zero:L.contrast,range:[-100,500],keypointsNumber:2},saturation:{zero:L.saturation,range:[-100,500],keypointsNumber:1},vibrance:{zero:L.vibrance,range:[-100,500],keypointsNumber:1},warmth:{zero:L.warmth,range:[-100,100],keypointsNumber:1},enhance:{zero:L.enhance,range:[0,100],keypointsNumber:1},filter:{zero:L.filter,range:[0,100],keypointsNumber:1}});var Y=r=>r?r.split(",").map(t=>t.trim()).filter(Boolean):[],Z=r=>r?r.join(","):"";var ht="https://ucarecdn.com",Or="https://upload.uploadcare.com",kr="https://social.uploadcare.com",Ir="https://ucarecd.net",P=Object.freeze({pubkey:"",multiple:!0,multipleMin:0,multipleMax:Number.MAX_SAFE_INTEGER,confirmUpload:!1,imgOnly:!1,accept:"",externalSourcesPreferredTypes:"",externalSourcesEmbedCss:"",store:"auto",cameraMirror:!1,cameraCapture:"",sourceList:"local, url, camera, dropbox, gdrive",topLevelOrigin:"",cloudImageEditorTabs:Z(I),maxLocalFileSizeBytes:0,thumbSize:76,showEmptyList:!1,useLocalImageEditor:!1,useCloudImageEditor:!0,removeCopyright:!1,cropPreset:"",imageShrink:"",modalScrollLock:!0,modalBackdropStrokes:!1,sourceListWrap:!0,remoteTabSessionKey:"",cdnCname:ht,cdnCnamePrefixed:Ir,baseUrl:Or,socialBaseUrl:kr,secureSignature:"",secureExpire:"",secureDeliveryProxy:"",retryThrottledRequestMaxTimes:10,retryNetworkErrorMaxTimes:3,multipartMinFileSize:26214400,multipartChunkSize:5242880,maxConcurrentRequests:10,multipartMaxConcurrentRequests:4,multipartMaxAttempts:3,checkForUrlDuplicates:!1,saveUrlForRecurrentUploads:!1,groupOutput:!1,userAgentIntegration:"",debug:!1,metadata:null,localeName:"en",localeDefinitionOverride:null,secureUploadsExpireThreshold:10*60*1e3,secureUploadsSignatureResolver:null,secureDeliveryProxyUrlResolver:null,iconHrefResolver:null,fileValidators:[],collectionValidators:[],validationTimeout:15*1e3,validationConcurrency:100,cameraModes:"photo, video",defaultCameraMode:null,enableAudioRecording:!0,enableVideoRecording:null,maxVideoRecordingDuration:null,mediaRecorderOptions:null,filesViewMode:"list",gridShowFileNames:!1,cloudImageEditorAutoOpen:!1,cloudImageEditorMaskHref:null,testMode:!1,qualityInsights:!0});var dt=Object.freeze({INIT_SOLUTION:"init-solution",CHANGE_CONFIG:"change-config"}),A=Object.freeze({FILE_ADDED:"file-added",FILE_REMOVED:"file-removed",FILE_UPLOAD_START:"file-upload-start",FILE_UPLOAD_PROGRESS:"file-upload-progress",FILE_UPLOAD_SUCCESS:"file-upload-success",FILE_UPLOAD_FAILED:"file-upload-failed",FILE_URL_CHANGED:"file-url-changed",MODAL_OPEN:"modal-open",MODAL_CLOSE:"modal-close",DONE_CLICK:"done-click",UPLOAD_CLICK:"upload-click",ACTIVITY_CHANGE:"activity-change",COMMON_UPLOAD_START:"common-upload-start",COMMON_UPLOAD_PROGRESS:"common-upload-progress",COMMON_UPLOAD_SUCCESS:"common-upload-success",COMMON_UPLOAD_FAILED:"common-upload-failed",CHANGE:"change",GROUP_CREATED:"group-created",...dt}),Re=class{constructor(t){f(this,"_timeoutStore",new Map);f(this,"_targets",new Set);f(this,"_debugPrint",null);this._debugPrint=t}bindTarget(t){this._targets.add(t)}unbindTarget(t){this._targets.delete(t)}_dispatch(t,e){var i;for(let s of this._targets)s.dispatchEvent(new CustomEvent(t,{detail:e}));(i=this._debugPrint)==null||i.call(this,()=>{let s=e&&typeof e=="object"?{...e}:e;return[`event "${t}"`,s]})}emit(t,e,{debounce:i}={}){if(typeof i!="number"&&!i){this._dispatch(t,typeof e=="function"?e():e);return}this._timeoutStore.has(t)&&window.clearTimeout(this._timeoutStore.get(t));let s=typeof i=="number"?i:20,o=window.setTimeout(()=>{this._dispatch(t,typeof e=="function"?e():e),this._timeoutStore.delete(t)},s);this._timeoutStore.set(t,o)}};function S(r,t){let e,i=(...s)=>{clearTimeout(e),e=setTimeout(()=>r(...s),t)};return i.cancel=()=>{clearTimeout(e)},i}var Zt="--uploadcare-blocks-window-height",J=class{static registerClient(t){this.clientsRegistry.size===0&&this.attachTracker(),this.clientsRegistry.add(t)}static unregisterClient(t){this.clientsRegistry.delete(t),this.clientsRegistry.size===0&&this.detachTracker()}static attachTracker(){window.addEventListener("resize",this.flush,{passive:!0,capture:!0}),this.flush()}static detachTracker(){window.removeEventListener("resize",this.flush,{capture:!0}),document.documentElement.style.removeProperty(Zt)}};f(J,"clientsRegistry",new Set),f(J,"flush",S(()=>{document.documentElement.style.setProperty(Zt,`${window.innerHeight}px`)},100));var Jt=r=>{var i;let t=new Intl.Locale(r),e="ltr";return typeof t.getTextInfo=="function"&&t.getTextInfo().direction?e=t.getTextInfo().direction:"textInfo"in t&&((i=t.textInfo)!=null&&i.direction)&&(e=t.textInfo.direction),e};var Qt=(r,t)=>new Intl.PluralRules(r).select(t);var Lr=r=>r,ft="{{",ti="}}",ei="plural:";function pt(r,t,e={}){var n;let{openToken:i=ft,closeToken:s=ti,transform:o=Lr}=e;for(let a in t){let l=(n=t[a])==null?void 0:n.toString();r=r.replaceAll(i+a+s,typeof l=="string"?o(l):l)}return r}function ii(r){let t=[],e=r.indexOf(ft);for(;e!==-1;){let i=r.indexOf(ti,e),s=r.substring(e+2,i);if(s.startsWith(ei)){let o=r.substring(e+2,i).replace(ei,""),n=o.substring(0,o.indexOf("(")),a=o.substring(o.indexOf("(")+1,o.indexOf(")"));t.push({variable:s,pluralKey:n,countVariable:a})}e=r.indexOf(ft,i)}return t}var ri=({element:r,attribute:t,onSuccess:e,onTimeout:i,timeout:s=300})=>{let o=r.getAttribute(t);if(o!==null){e(o);return}let n=new MutationObserver(c=>{let h=c[c.length-1];l(h)});n.observe(r,{attributes:!0,attributeFilter:[t]});let a=setTimeout(()=>{n.disconnect(),i()},s),l=c=>{let h=r.getAttribute(t);c.type==="attributes"&&c.attributeName===t&&h!==null&&(clearTimeout(a),n.disconnect(),e(h))}};var eo={baseCDN:"https://ucarecdn.com",baseURL:"https://upload.uploadcare.com",maxContentLength:50*1024*1024,retryThrottledRequestMaxTimes:1,retryNetworkErrorMaxTimes:3,multipartMinFileSize:25*1024*1024,multipartChunkSize:5*1024*1024,multipartMinLastPartSize:1024*1024,maxConcurrentRequests:4,pollingTimeoutMilliseconds:1e4,pusherKey:"79ae88bd931ea68464d9"};var si;(function(r){r.Token="token",r.FileInfo="file_info"})(si||(si={}));var oi;(function(r){r.Unknown="unknown",r.Waiting="waiting",r.Progress="progress",r.Error="error",r.Success="success"})(oi||(oi={}));var to=window.WebSocket;var Me=class{constructor(t){f(this,"_concurrency",1);f(this,"_pending",[]);f(this,"_running",0);f(this,"_resolvers",new Map);f(this,"_rejectors",new Map);this._concurrency=t}run(){let t=this._concurrency-this._running;for(let e=0;e<t;e++){let i=this._pending.shift();if(!i)return;let s=this._resolvers.get(i),o=this._rejectors.get(i);if(!s||!o)throw new Error("Unexpected behavior: resolver or rejector is undefined");this._running+=1,i().finally(()=>{this._resolvers.delete(i),this._rejectors.delete(i),this._running-=1,this.run()}).then(n=>s(n)).catch(n=>o(n))}}add(t,{autoRun:e}={autoRun:!0}){return new Promise((i,s)=>{this._resolvers.set(t,i),this._rejectors.set(t,s),this._pending.push(t),e&&this.run()})}get pending(){return this._pending.length}get running(){return this._running}set concurrency(t){this._concurrency=t,this.run()}get concurrency(){return this._concurrency}};var ni=()=>({});var pe={"locale-id":"en","social-source-lang":"en","upload-file":"Upload file","upload-files":"Upload files","choose-file":"Choose file","choose-files":"Choose files","drop-files-here":"Drop files here","select-file-source":"Select file source",selected:"Selected",upload:"Upload","add-more":"Add more",cancel:"Cancel","start-from-cancel":"Cancel",clear:"Clear","camera-shot":"Shot","upload-url":"Import","upload-url-placeholder":"Paste link here","edit-image":"Edit image","edit-detail":"Details",back:"Back",done:"Done",ok:"Ok","remove-from-list":"Remove",no:"No",yes:"Yes","confirm-your-action":"Confirm your action","are-you-sure":"Are you sure?","selected-count":"{{count}} of {{total}} selected","select-all":"Select all","deselect-all":"Deselect all","upload-error":"Upload error","validation-error":"Validation error","no-files":"No files selected",browse:"Browse","not-uploaded-yet":"Not uploaded yet...",file__one:"file",file__other:"files",error__one:"error",error__other:"errors","header-uploading":"Uploading {{count}} {{plural:file(count)}}","header-failed":"{{count}} {{plural:error(count)}}","header-succeed":"{{count}} {{plural:file(count)}} uploaded","header-total":"{{count}} {{plural:file(count)}} selected","src-type-local":"From device","src-type-from-url":"From link","src-type-camera":"Camera","src-type-mobile-video-camera":"Video","src-type-mobile-photo-camera":"Photo","src-type-draw":"Draw","src-type-facebook":"Facebook","src-type-dropbox":"Dropbox","src-type-gdrive":"Google Drive","src-type-ngdrive":"Google Drive","src-type-gphotos":"Google Photos","src-type-flickr":"Flickr","src-type-vk":"VK","src-type-evernote":"Evernote","src-type-box":"Box","src-type-onedrive":"OneDrive","src-type-huddle":"Huddle","src-type-other":"Other","caption-from-url":"Import from link","caption-camera":"Camera","caption-draw":"Draw","caption-edit-file":"Edit file","file-no-name":"No name...","toggle-fullscreen":"Toggle fullscreen","toggle-guides":"Toggle guides",rotate:"Rotate","flip-vertical":"Flip vertical","flip-horizontal":"Flip horizontal",apply:"Apply",brightness:"Brightness",contrast:"Contrast",saturation:"Saturation",exposure:"Exposure",gamma:"Gamma",vibrance:"Vibrance",warmth:"Warmth",enhance:"Enhance",original:"Original",resize:"Resize image",crop:"Crop","select-color":"Select color",text:"Text",draw:"Draw","cancel-edit":"Cancel edit","tab-view":"Preview","tab-details":"Details","file-name":"Name","file-size":"Size","cdn-url":"CDN URL","file-size-unknown":"Unknown","camera-permissions-denied":"Camera access denied","camera-permissions-prompt":"Please allow access to the camera","camera-permissions-request":"Request access","files-count-limit-error-title":"Files count limit overflow","files-count-limit-error-too-few":"You\u2019ve chosen {{total}} {{plural:file(total)}}. At least {{min}} {{plural:file(min)}} required.","files-count-limit-error-too-many":"You\u2019ve chosen too many files. {{max}} {{plural:file(max)}} is maximum.","files-max-size-limit-error":"File is too big. Max file size is {{maxFileSize}}.","has-validation-errors":"File validation error occurred. Please, check your files before upload.","images-only-accepted":"Only image files are accepted.","file-type-not-allowed":"Uploading of these file types is not allowed.","some-files-were-not-uploaded":"Some files were not uploaded.","file-item-edit-button":"Edit","file-item-remove-button":"Remove","a11y-editor-tab-filters":"Filters","a11y-editor-tab-tuning":"Tuning","a11y-editor-tab-crop":"Crop","a11y-activity-header-button-close":"Close",flip:"Flip",mirror:"Mirror","a11y-cloud-editor-apply-filter":"Apply {{name}} filter","a11y-cloud-editor-apply-crop":"Apply {{name}} operation","a11y-cloud-editor-apply-tuning":"Apply {{name}} tuning","a11y-cloud-editor-apply-aspect-ratio":"Apply operation {{name}} {{value}}",finished:"Finished",failed:"Failed",uploading:"Uploading",idle:"Idle","a11y-file-item-status":"File {{fileName}} in status {{status}}","waiting-for":"Waiting for {{source}}","queued-uploading":"Queued for upload","queued-validation":"Queued for validation",validation:"Validating","crop-to-shape":"Crop to {{value}}",custom:"Freeform","freeform-crop":"Freeform crop"};var Ne=new Map,mt=new Map,ai=(r,t)=>{Ne.has(r)&&console.log(`Locale ${r} is already defined. Overwriting...`),Ne.set(r,{...pe,...t})},Pr=(r,t)=>{mt.set(r,t)},Rr=(r,t)=>{typeof t=="function"?Pr(r,t):ai(r,t)},li=async r=>{if(!Ne.has(r)){if(!mt.has(r))throw new Error(`Locale ${r} is not defined`);let e=await mt.get(r)();ai(r,e)}return Ne.get(r)};Rr("en",pe);var M=r=>`*l10n/${r}`,Mr="en",Ue=class{constructor(t){f(this,"_blockInstance",null);f(this,"_localeName","");f(this,"_callbacks",new Set);f(this,"_boundBlocks",new Map);this._blockInstance=t;for(let[e,i]of Object.entries(pe)){let s=this._blockInstance.has(M(e))?!this._blockInstance.$[M(e)]:!0;this._blockInstance.add(M(e),i,s)}setTimeout(()=>{t.subConfigValue("localeName",async e=>{var o;if(!this._blockInstance||!e)return;this._localeName=e;let i=await li(e);if(e!==Mr&&this._localeName!==e)return;let s=(o=this._blockInstance.cfg.localeDefinitionOverride)==null?void 0:o[e];for(let[n,a]of Object.entries(i)){let l=s==null?void 0:s[n];this._blockInstance.add(M(n),l!=null?l:a,!0);for(let c of this._callbacks)c()}}),t.subConfigValue("localeDefinitionOverride",e=>{var s;if(!e)return;let i=e[this._localeName];if(i)for(let[o,n]of Object.entries(i)){(s=this._blockInstance)==null||s.add(M(o),n,!0);for(let a of this._callbacks)a()}})})}onLocaleChange(t){let e=S(t,0);return this._callbacks.add(e),()=>{this._callbacks.delete(e)}}bindL10n(t,e,i){var o,n,a;t.$[e]=i(),this._boundBlocks.has(t)||this._boundBlocks.set(t,new Map),(n=(o=this._boundBlocks.get(t))==null?void 0:o.get(e))==null||n();let s=this.onLocaleChange(()=>{t.$[e]=i()});(a=this._boundBlocks.get(t))==null||a.set(e,s)}destroyL10nBindings(t){let e=this._boundBlocks.get(t);if(e){for(let i of e.values())i();this._boundBlocks.delete(t)}}destroy(){this._callbacks.clear()}};function ci(r,t){[...r.querySelectorAll("[l10n]")].forEach(e=>{let i=e.getAttribute("l10n");if(!i)return;let s=i.split(";");for(let o of s)o&&Nr(e,o,t)})}var Nr=(r,t,e)=>{let i="textContent",s=!1;if(t.includes(":")){let a=t.split(":");i=a[0],t=a[1],i.startsWith("@")&&(i=i.slice(1),s=!0)}let o=t;e.has(o)&&e.sub(o,a=>{if(!a)return;e.l10nProcessorSubs.has(o)||e.l10nProcessorSubs.set(o,new Set);let l=e.l10nProcessorSubs.get(o);l==null||l.forEach(u=>{u.remove(),l.delete(u),e.allSubs.delete(u)});let c=M(a).replace("*","");e.nodeCtx.has(c)||e.nodeCtx.add(c,a);let h=e.nodeCtx.sub(c,()=>{r[i]=e.l10n(a)});l==null||l.add(h),e.allSubs.add(h),r.removeAttribute("l10n")});let n=M(t);e.has(n)||e.add(n,""),e.sub(n,()=>{t=t,s?r.setAttribute(i,e.l10n(t)):r[i]=e.l10n(t)}),r.removeAttribute("l10n")};var $=r=>`*cfg/${r}`;function ui(r,t){let e=r.querySelectorAll("[data-testid]");if(e.length===0)return;let i=new WeakMap;for(let s of e){let o=s.getAttribute("data-testid");o&&i.set(s,o)}t.subConfigValue("testMode",s=>{if(!s){for(let n of e)n.removeAttribute("data-testid");return}let o=t.testId;for(let n of e){let a=i.get(n);a&&n.setAttribute("data-testid",`${o}--${a}`)}})}var Ur={button:["toolbar"],checkbox:["toolbar"],menuitem:["menu","menubar"],option:["listbox"],tab:["tablist"]};function me(r,t){t.tabIndex=0,t.focus(),r.tabIndex=-1}function _t(r){let t=r.role||r.type||r.tagName;if(!t)return null;let e=Ur[t.toLowerCase()];if(!e)return null;for(let i of e){let s=r.closest(`[role=${i}]`);if(s)return s}}function gt(r,t){return t.role==="toolbar"?Dr(t):t.querySelectorAll(`[role=${r.role}]`)}function Dr(r){return[...r.querySelectorAll("*")].filter(e=>e.role==="button"||e.type==="button"||e.role==="checkbox"||e.type==="checkbox")}function Fr(r){let t=r.getAttribute("aria-orientation");if(t==="vertical")return!1;if(t==="horizontal")return!0;let e=r.role;return e==="menubar"||e==="tablist"||e==="toolbar"}function hi(r){return t=>{let e=!1,i=(r==null?void 0:r.searchDelayMs)||300,s=0,o="";function n(u){let d=_t(u.target);if(!d){a();return}let p=gt(u.target,d),g=Array.from(p).indexOf(u.target),N="ArrowDown",k="ArrowUp";if(Fr(d)&&(t.document.dir==="rtl"?(N="ArrowLeft",k="ArrowRight"):(N="ArrowRight",k="ArrowLeft")),u.key===N)u.preventDefault(),me(u.target,p[g+1]||p[0]);else if(u.key===k)u.preventDefault(),me(u.target,p[g-1]||p[p.length-1]);else if(u.key==="Home")u.preventDefault(),me(u.target,p[0]);else if(u.key==="End")u.preventDefault(),me(u.target,p[p.length-1]);else if(u.key.length===1&&d.role!=="tablist"){let T=Date.now();T-s<=i?o+=u.key.toLowerCase():o=u.key.toLowerCase(),s=T;let It=Array.from(p).find(Qi=>{var Lt,Pt,Rt;return(Rt=(Pt=(Lt=Qi.textContent)==null?void 0:Lt.trim())==null?void 0:Pt.toLowerCase())==null?void 0:Rt.startsWith(o)});It&&(u.preventDefault(),me(u.target,It))}}function a(){e=!1,t.removeEventListener("keydown",n)}function l(u){let d=_t(u.target);if(d){e||(e=!0,t.addEventListener("keydown",n));let p=gt(u.target,d);for(let g of p)g!==u.target&&g.setAttribute("tabindex",-1)}else e&&a()}function c(u){(!u.relatedTarget||u.relatedTarget===t.document)&&a()}function h(u){let d=_t(u.target);if(d){let p=gt(u.target,d);for(let g of p)g!==u.target&&g.setAttribute("tabindex",-1);u.target.setAttribute("tabindex",0)}}return t.addEventListener("click",h),t.addEventListener("focusin",l),t.addEventListener("focusout",c),()=>{a(),t.removeEventListener("click",h),t.removeEventListener("focusin",l),t.removeEventListener("focusout",c)}}}function di(){return r=>{let t,e;function i(o){if(o.target.getAttribute("aria-hidden")==="true"){t=o.target,t.setAttribute("aria-hidden","false"),e=t.hidden,e&&(t.hidden=!1);let n=o.target.querySelector('a, button, select, textarea, input:not([type=radio]), [type=radio]:checked, [tabindex]:not([tabindex="-1"])');n&&(n.tabIndex=0)}}function s(o){t&&t.contains(o.target)&&(!o.relatedTarget||!t.contains(o.relatedTarget))&&(o.target.tabIndex=-1,t.setAttribute("aria-hidden","true"),e&&(t.hidden=!0),t=null)}return r.addEventListener("keyuxJump",i),r.addEventListener("focusout",s),()=>{r.removeEventListener("keyuxJump",i),r.removeEventListener("focusout",s)}}}function fi(){return r=>{let t=[];function e(l){let c=r.document.activeElement;c&&c!==r.document.body&&t.push(new WeakRef(c)),l.focus({focusVisible:!0})}function i(){let l=t.pop();if(!l){r.document.activeElement.blur();return}let c=l.deref();c&&c.isConnected?c.focus():i()}let s=0,o;function n(l){clearInterval(o);let c=l.getAttribute("aria-controls");o=setInterval(()=>{if(s++>50){clearInterval(o);return}let h=r.document.getElementById(c);if(h){let u=h.querySelector('a, button, select, textarea, input:not([type=radio]), [type=radio]:checked, [tabindex]:not([tabindex="-1"])');u&&(clearInterval(o),h.dispatchEvent(new r.CustomEvent("keyuxJump",{bubbles:!0})),e(u))}},50)}function a(l){l.target.getAttribute("aria-controls")&&l.key==="Enter"&&n(l.target),l.key==="Escape"&&i()}return r.addEventListener("keydown",a),()=>{r.removeEventListener("keydown",a)}}}function pi(r){let t,e=r.split(" "),i;function s(a){a.key==="Enter"&&(a.target.tagName==="BUTTON"||a.target.tagName==="A")&&(o(),a.target.classList.add(...e),t=a.target,i=a.target)}function o(){t&&t.classList.remove(...e),i=null}function n(a){a.clientX===0&&a.clientY===0&&i!==a.target&&(o(),a.target.classList.add(...e),t=a.target)}return a=>(a.addEventListener("click",n),a.addEventListener("keydown",s),a.addEventListener("keyup",o),()=>{a.removeEventListener("click",n),a.removeEventListener("keydown",s),a.removeEventListener("keyup",o)})}function mi(r,t){let e=t.map(i=>i(r));return()=>{e.forEach(i=>i())}}var bt=class{constructor(){f(this,"_listeners",new Map);f(this,"_scope",[])}addEventListener(t,e){let i=s=>{let o=s.target;o&&this._scope.some(n=>n===s.target||n.contains(o))&&e(s)};this._listeners.set(e,i),window.addEventListener(t,i)}removeEventListener(t,e){let i=this._listeners.get(e);i&&window.removeEventListener(t,i),this._listeners.delete(e)}get CustomEvent(){return window.CustomEvent}get document(){return window.document}get navigator(){return window.navigator}registerScope(t){this._scope.push(t)}destroy(){this._scope=[],this._listeners.forEach((t,e)=>{window.removeEventListener("keydown",t),window.removeEventListener("keyup",t),this._listeners.delete(e)})}},De=class{constructor(){f(this,"_destroyKeyUX");f(this,"_scopedWindow");this._scopedWindow=new bt,this._destroyKeyUX=mi(this._scopedWindow,[hi(),pi("is-pressed"),fi(),di()])}registerBlock(t){this._scopedWindow.registerScope(t)}destroy(){var t;(t=this._destroyKeyUX)==null||t.call(this),this._scopedWindow.destroy()}};var ie=Object.freeze({ADD:"modal:add",DELETE:"modal:delete",OPEN:"modal:open",CLOSE:"modal:close",CLOSE_ALL:"modal:closeAll",DESTROY:"modal:destroy"}),Fe=class{constructor(t){f(this,"_modals",new Map);f(this,"_activeModals",new Set);f(this,"_subscribers",new Map);this._block=t}_debugPrint(...t){this._block.debugPrint("[modal-manager]",...t)}registerModal(t,e){this._modals.set(t,e),this._notify(ie.ADD,{id:t,modal:e})}deleteModal(t){if(!this._modals.has(t))return!1;let e=this._modals.get(t);return this._modals.delete(t),this._activeModals.delete(t),this._notify(ie.DELETE,{id:t,modal:e}),!0}open(t){if(!this._modals.has(t))return this._debugPrint(`Modal with ID "${t}" not found`),!1;let e=this._modals.get(t);return this._activeModals.add(t),this._notify(ie.OPEN,{modal:e,id:t}),!0}close(t){if(!this._modals.has(t)||!this._activeModals.has(t))return this._debugPrint(`Modal with ID "${t}" not found or not active`),!1;let e=this._modals.get(t);return this._activeModals.delete(t),this._notify(ie.CLOSE,{id:t,modal:e}),!0}toggle(t){return this._modals.has(t)?this._activeModals.has(t)?this.close(t):this.open(t):(this._debugPrint(`Modal with ID "${t}" not found`),!1)}get hasActiveModals(){return this._activeModals.size>0}back(){if(this._activeModals.size===0)return this._debugPrint("No active modals to go back from"),!1;let t=Array.from(this._activeModals).pop();return this.close(t)}closeAll(){let t=this._activeModals.size;return this._activeModals.clear(),this._notify(ie.CLOSE_ALL,{}),t}subscribe(t,e){var i;return this._subscribers.has(t)||this._subscribers.set(t,new Set),(i=this._subscribers.get(t))==null||i.add(e),()=>this.unsubscribe(t,e)}unsubscribe(t,e){var i;this._subscribers.has(t)&&((i=this._subscribers.get(t))==null||i.delete(e))}_notify(t,e){var i;if(this._subscribers.has(t))for(let s of(i=this._subscribers.get(t))!=null?i:new Set)try{s(e)}catch(o){this._block.telemetryManager.sendEventError(o,"modal subscriber"),this._debugPrint("Error in modal subscriber:",o)}}destroy(){this.closeAll(),this._modals.clear(),this._subscribers.clear(),this._notify(ie.DESTROY,{})}};function zr(r){return r.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`).replace(/__/g,"_")}function vt(r){return Array.isArray(r)?r.map(t=>typeof t=="object"&&t!==null?vt(t):t):typeof r!="object"||r===null?r:Object.fromEntries(Object.entries(r).map(([t,e])=>{let i=zr(t);return typeof e=="object"&&e!==null?[i,vt(e)]:[i,e]}))}function jr(r){return{ok:!0,value:r}}function yt(r){return{ok:!1,error:r}}var Br="https://tlm.uploadcare.com/api/",wt=class{constructor(t=Br){this.baseUrl=t}async base(t,e={}){let i=`${this.baseUrl}${t}`;try{let s=await fetch(i,e);if(!s.ok)return yt(new Error(`Got non-200 response from "${i}". Status: ${s.status.toString()}`));try{let o=await s.json();return jr(o)}catch(o){return yt(new Error(`Error parsing JSON from "${i}". Error: ${o}`))}}catch(s){return yt(new Error(`Error fetching data from "${i}". Error: ${s}`))}}async post(t,e,i={}){return await this.base(t,{...i,method:"POST",body:JSON.stringify(vt(e)),headers:{"Content-Type":"application/json",...i.headers||{}}})}async get(t,e={}){return await this.base(t,{method:"GET",...e})}},Vr=async(r,t)=>({success:!0,data:t}),ze=class extends wt{constructor(){super()}async sendEvent(t,e){let i=await Vr(void 0,t);if(!i.success)throw console.error("TelemetryAPIService: events: body is invalid",i.error),new Error("TelemetryAPIService: events: body is invalid");return this.post("v1/events",t,e)}};var je="blocks",Be="1.23.1";var Ve=class{constructor(t){f(this,"_sessionId",crypto.randomUUID());f(this,"_telemetryInstance",null);f(this,"_block",null);f(this,"_config",structuredClone(P));f(this,"_initialized",!1);f(this,"_lastPayload",null);f(this,"_queue",null);this._block=t,this._telemetryInstance=new ze,this._queue=new Me(10);for(let e of Object.keys(this._config))this._block.subConfigValue(e,i=>{var s;this._initialized&&this._config[e]!==i&&((s=this._block)==null||s.emit(A.CHANGE_CONFIG,void 0)),this._setConfig(e,i)})}_init(t){t===A.INIT_SOLUTION&&!this._initialized&&(this._initialized=!0)}_setConfig(t,e){this._config[t]!==e&&(this._config[t]=e)}_formattingPayload(t){var s,o;let e=t.payload?{...t.payload}:{};e.activity&&(e.activity=void 0);let i={...t};return(t.eventType===A.INIT_SOLUTION||t.eventType===A.CHANGE_CONFIG)&&(i.config=this._config),{...i,appVersion:Be,appName:je,sessionId:this._sessionId,component:this._solution,activity:this._activity,projectPubkey:(s=this._config)==null?void 0:s.pubkey,userAgent:navigator.userAgent,eventType:(o=i.eventType)!=null?o:"",eventTimestamp:this._timestamp,payload:{...e}}}_excludedEvents(t){return!!(t&&[A.CHANGE,A.COMMON_UPLOAD_PROGRESS,A.FILE_ADDED,A.FILE_REMOVED,A.FILE_UPLOAD_START,A.FILE_UPLOAD_PROGRESS,A.FILE_UPLOAD_SUCCESS,A.FILE_UPLOAD_FAILED,A.FILE_URL_CHANGED,A.GROUP_CREATED].includes(t))}sendEvent(t){var o;let e=this._formattingPayload(t);if(this._init(t.eventType),this._excludedEvents(t.eventType)||this._lastPayload&&this._checkObj(this._lastPayload,e))return null;(o=this._queue)==null||o.add(async()=>{var n;this._lastPayload