@uploadcare/file-uploader 1.24.5 → 1.25.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abstract/loadFileUploaderFrom.js +4 -0
- package/dist/env.js +1 -1
- package/dist/index.css +16 -6
- package/dist/index.d.ts +866 -539
- package/dist/index.js +7609 -6042
- package/dist/index.layered.css +16 -6
- package/dist/index.ssr.js +533 -762
- package/dist/lit.d.ts +1 -0
- package/dist/lit.js +28 -0
- package/dist/locales/file-uploader/ar.js +1 -1
- package/dist/locales/file-uploader/az.js +1 -1
- package/dist/locales/file-uploader/ca.js +1 -1
- package/dist/locales/file-uploader/cs.js +1 -1
- package/dist/locales/file-uploader/da.js +1 -1
- package/dist/locales/file-uploader/de.js +1 -1
- package/dist/locales/file-uploader/el.js +1 -1
- package/dist/locales/file-uploader/en.js +1 -1
- package/dist/locales/file-uploader/es.js +1 -1
- package/dist/locales/file-uploader/et.js +1 -1
- package/dist/locales/file-uploader/fi.js +1 -1
- package/dist/locales/file-uploader/fr.js +1 -1
- package/dist/locales/file-uploader/he.js +1 -1
- package/dist/locales/file-uploader/hy.js +1 -1
- package/dist/locales/file-uploader/is.js +1 -1
- package/dist/locales/file-uploader/it.js +1 -1
- package/dist/locales/file-uploader/ja.js +1 -1
- package/dist/locales/file-uploader/ka.js +1 -1
- package/dist/locales/file-uploader/kk.js +1 -1
- package/dist/locales/file-uploader/ko.js +1 -1
- package/dist/locales/file-uploader/lv.js +1 -1
- package/dist/locales/file-uploader/nb.js +1 -1
- package/dist/locales/file-uploader/nl.js +1 -1
- package/dist/locales/file-uploader/pl.js +1 -1
- package/dist/locales/file-uploader/pt.js +1 -1
- package/dist/locales/file-uploader/ro.js +1 -1
- package/dist/locales/file-uploader/ru.js +1 -1
- package/dist/locales/file-uploader/sk.js +1 -1
- package/dist/locales/file-uploader/sr.js +1 -1
- package/dist/locales/file-uploader/sv.js +1 -1
- package/dist/locales/file-uploader/tr.js +1 -1
- package/dist/locales/file-uploader/uk.js +1 -1
- package/dist/locales/file-uploader/vi.js +1 -1
- package/dist/locales/file-uploader/zh-TW.js +1 -1
- package/dist/locales/file-uploader/zh.js +1 -1
- package/package.json +29 -24
- package/web/file-uploader.iife.min.d.ts +872 -545
- package/web/file-uploader.iife.min.js +8 -4
- package/web/file-uploader.min.d.ts +872 -545
- package/web/file-uploader.min.js +7 -4
- package/web/uc-basic.layered.min.css +1 -1
- package/web/uc-basic.min.css +1 -1
- package/web/uc-cloud-image-editor.layered.min.css +1 -1
- package/web/uc-cloud-image-editor.min.css +1 -1
- package/web/uc-cloud-image-editor.min.d.ts +438 -235
- package/web/uc-cloud-image-editor.min.js +7 -4
- package/web/uc-file-uploader-inline.layered.min.css +1 -1
- package/web/uc-file-uploader-inline.min.css +1 -1
- package/web/uc-file-uploader-inline.min.d.ts +872 -545
- package/web/uc-file-uploader-inline.min.js +7 -4
- package/web/uc-file-uploader-minimal.layered.min.css +1 -1
- package/web/uc-file-uploader-minimal.min.css +1 -1
- package/web/uc-file-uploader-minimal.min.d.ts +872 -545
- package/web/uc-file-uploader-minimal.min.js +7 -4
- package/web/uc-file-uploader-regular.layered.min.css +1 -1
- package/web/uc-file-uploader-regular.min.css +1 -1
- package/web/uc-file-uploader-regular.min.d.ts +872 -545
- package/web/uc-file-uploader-regular.min.js +7 -4
- package/web/uc-img.min.d.ts +56 -91
- package/web/uc-img.min.js +3 -3
package/web/uc-img.min.d.ts
CHANGED
|
@@ -1,115 +1,80 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
2
|
|
|
3
|
-
declare
|
|
4
|
-
|
|
3
|
+
declare const ImgTypeEnum: Readonly<{
|
|
4
|
+
PREVIEW: "PREVIEW";
|
|
5
|
+
MAIN: "MAIN";
|
|
6
|
+
}>;
|
|
7
|
+
|
|
8
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
|
9
|
+
|
|
10
|
+
type CssPropValue = string | number | undefined | null;
|
|
11
|
+
declare const ImgConfig_base: typeof LitElement & Constructor<LitElement> & {
|
|
12
|
+
reg(tagName: string): void;
|
|
13
|
+
} & Constructor<{
|
|
14
|
+
getCssData(propName: string, silentCheck?: boolean): string | number | boolean | null | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
declare class ImgConfig extends ImgConfig_base {
|
|
17
|
+
private _state;
|
|
18
|
+
private _subscribers;
|
|
19
|
+
private _isnObserver;
|
|
20
|
+
private _observed;
|
|
21
|
+
createRenderRoot(): HTMLElement | ShadowRoot;
|
|
5
22
|
constructor();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*/
|
|
11
|
-
$$(key: string): any;
|
|
12
|
-
/** @param {Object<String, String | Number>} kvObj */
|
|
13
|
-
set$$(kvObj: any): void;
|
|
14
|
-
/**
|
|
15
|
-
* @param {String} key
|
|
16
|
-
* @param {(val: any) => void} kbFn
|
|
17
|
-
*/
|
|
18
|
-
sub$$(key: string, kbFn: (val: any) => void): void;
|
|
23
|
+
$$(key: string): unknown;
|
|
24
|
+
set$$(kvObj: Record<string, CssPropValue>): void;
|
|
25
|
+
sub$$<T = unknown>(key: string, kbFn: (val: T) => void): void;
|
|
26
|
+
private _notify;
|
|
19
27
|
analyticsParams(): string;
|
|
20
|
-
initAttributes(el:
|
|
21
|
-
/**
|
|
22
|
-
* @param {HTMLElement} el
|
|
23
|
-
* @param {() => void} cbkFn
|
|
24
|
-
*/
|
|
28
|
+
initAttributes(el: HTMLElement): void;
|
|
25
29
|
initIntersection(el: HTMLElement, cbkFn: () => void): void;
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
attributeChangedCallback(name:
|
|
30
|
+
connectedCallback(): void;
|
|
31
|
+
private _initCssProperties;
|
|
32
|
+
disconnectedCallback(): void;
|
|
33
|
+
static get observedAttributes(): string[];
|
|
34
|
+
attributeChangedCallback(name: string, _oldVal: string | null, newVal: string | null): void;
|
|
31
35
|
}
|
|
32
36
|
|
|
37
|
+
type ImgType = (typeof ImgTypeEnum)[keyof typeof ImgTypeEnum];
|
|
38
|
+
type LoaderParams = {
|
|
39
|
+
src?: string;
|
|
40
|
+
srcset?: string;
|
|
41
|
+
elNode: HTMLImageElement;
|
|
42
|
+
};
|
|
43
|
+
type CurrentImg = {
|
|
44
|
+
type: ImgType;
|
|
45
|
+
img: HTMLImageElement;
|
|
46
|
+
};
|
|
33
47
|
declare class ImgBase extends ImgConfig {
|
|
34
|
-
_img: HTMLImageElement;
|
|
35
|
-
_imgPreview: HTMLImageElement;
|
|
36
|
-
/**
|
|
37
|
-
* @private
|
|
38
|
-
* @param {String} src
|
|
39
|
-
*/
|
|
48
|
+
protected _img: HTMLImageElement;
|
|
49
|
+
protected _imgPreview: HTMLImageElement;
|
|
40
50
|
private _fmtAbs;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* @param {String} [size]
|
|
45
|
-
* @returns {String | Number}
|
|
46
|
-
*/
|
|
47
|
-
_validateSize(size?: string): string | number;
|
|
48
|
-
/**
|
|
49
|
-
* Image operations
|
|
50
|
-
*
|
|
51
|
-
* @param {String} [size]
|
|
52
|
-
* @param {String} [blur]
|
|
53
|
-
*/
|
|
54
|
-
_getCdnModifiers(size?: string, blur?: string): string;
|
|
55
|
-
/**
|
|
56
|
-
* @private
|
|
57
|
-
* @param {String} [size]
|
|
58
|
-
* @param {String} [blur]
|
|
59
|
-
* @returns {any}
|
|
60
|
-
*/
|
|
51
|
+
private _validateSize;
|
|
52
|
+
private _getCdnModifiers;
|
|
53
|
+
private _getTypedCssValue;
|
|
61
54
|
private _getUrlBase;
|
|
62
|
-
/**
|
|
63
|
-
* @private
|
|
64
|
-
* @param {String} url
|
|
65
|
-
* @returns {String}
|
|
66
|
-
*/
|
|
67
55
|
private _proxyUrl;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @param {Number} [k]
|
|
71
|
-
* @param {Boolean} [wOnly]
|
|
72
|
-
*/
|
|
73
|
-
_getElSize(el: HTMLElement, k?: number, wOnly?: boolean): string | null;
|
|
74
|
-
/** @param {HTMLImageElement} img */
|
|
75
|
-
_setupEventProxy(img: HTMLImageElement): void;
|
|
76
|
-
/** @type {HTMLImageElement} */
|
|
56
|
+
protected _getElSize(el: HTMLElement, k?: number, wOnly?: boolean): string | null;
|
|
57
|
+
private _setupEventProxy;
|
|
77
58
|
get img(): HTMLImageElement;
|
|
78
|
-
get currentImg():
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
} | {
|
|
82
|
-
type: "MAIN";
|
|
83
|
-
img: HTMLImageElement;
|
|
84
|
-
};
|
|
85
|
-
get hasPreviewImage(): any;
|
|
86
|
-
get bgSelector(): any;
|
|
59
|
+
get currentImg(): CurrentImg;
|
|
60
|
+
get hasPreviewImage(): string | number | boolean | undefined;
|
|
61
|
+
get bgSelector(): string | undefined;
|
|
87
62
|
get breakpoints(): number[] | null;
|
|
88
63
|
get hasFormatJPG(): boolean;
|
|
89
|
-
/** @param {HTMLElement} el */
|
|
90
64
|
renderBg(el: HTMLElement): void;
|
|
91
65
|
getSrcset(): string;
|
|
92
|
-
getSrc():
|
|
93
|
-
get srcUrlPreview():
|
|
66
|
+
getSrc(): string | undefined;
|
|
67
|
+
get srcUrlPreview(): string | undefined;
|
|
94
68
|
renderBackground(): void;
|
|
95
|
-
_appendURL
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
srcset: any;
|
|
99
|
-
}): void;
|
|
100
|
-
_setupConfigForImage({ elNode }: {
|
|
101
|
-
elNode: any;
|
|
102
|
-
}): void;
|
|
103
|
-
loaderImage({ src, srcset, elNode }: {
|
|
104
|
-
src: any;
|
|
105
|
-
srcset: any;
|
|
106
|
-
elNode: any;
|
|
107
|
-
}): Promise<any>;
|
|
69
|
+
private _appendURL;
|
|
70
|
+
private _setupConfigForImage;
|
|
71
|
+
loaderImage({ src, srcset, elNode }: LoaderParams): Promise<HTMLImageElement>;
|
|
108
72
|
renderImage(): Promise<void>;
|
|
109
73
|
init(): void;
|
|
110
74
|
}
|
|
111
75
|
|
|
112
76
|
declare class Img extends ImgBase {
|
|
77
|
+
connectedCallback(): void;
|
|
113
78
|
}
|
|
114
79
|
|
|
115
80
|
export { Img };
|
package/web/uc-img.min.js
CHANGED
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*
|
|
25
25
|
*/
|
|
26
|
-
var
|
|
27
|
-
`,"\\n"),
|
|
28
|
-
`));return}window.customElements.define(e,t?class extends this{}:this)}static get is(){return this.__tag||this.reg(),this.__tag}static bindAttributes(e){this.observedAttributes=Object.keys(e),this.__attrDesc=e}attributeChangedCallback(e,t,s){var i;if(t===s)return;let r=(i=this.constructor.__attrDesc)==null?void 0:i[e];r?this.__dataCtxInitialized?this.$[r]=s:this.init$[r]=s:this[e]=s}getCssData(e,t=!1){if(this.__cssDataCache||(this.__cssDataCache=Object.create(null)),!Object.keys(this.__cssDataCache).includes(e)){this.__computedStyle||(this.__computedStyle=window.getComputedStyle(this));let s=this.__computedStyle.getPropertyValue(e).trim();try{this.__cssDataCache[e]=St(s)}catch{!t&&console.warn(`CSS Data error: ${e}`),this.__cssDataCache[e]=null}}return this.__cssDataCache[e]}__extractCssName(e){return e.split("--").map((t,s)=>s===0?"":t).join("--")}__initStyleAttrObserver(){_||(_=new Set),_.add(this.updateCssData),y||(y=new MutationObserver(e=>{e[0].type==="attributes"&&_.forEach(t=>{t()})}),y.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style"]}))}bindCssData(e,t=""){this.__boundCssProps||(this.__boundCssProps=new Set),this.__boundCssProps.add(e);let s=this.getCssData(this.__extractCssName(e),!0);s===null&&(s=t),this.add(e,s),this.__initStyleAttrObserver()}dropCssDataCache(){this.__cssDataCache=null,this.__computedStyle=null}defineAccessor(e,t,s){let i="__"+e;this[i]=this[e],Object.defineProperty(this,e,{set:r=>{this[i]=r,s?window.setTimeout(()=>{t?.(r)}):t?.(r)},get:()=>this[i]}),this[e]=this[i]}static set shadowStyles(e){let t=new Blob([e],{type:"text/css"});this.__shadowStylesUrl=URL.createObjectURL(t)}static set rootStyles(e){if(!this.__rootStylesLink){let t=new Blob([e],{type:"text/css"}),s=URL.createObjectURL(t),i=document.createElement("link");i.href=s,i.rel="stylesheet",this.__rootStylesLink=i}}},B=m;M(B,"template");var U=class{static _print(e){console.warn(e)}static setDefaultTitle(e){this.defaultTitle=e}static setRoutingMap(e){Object.assign(this.appMap,e);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(e){this.__routingEventName=e}static get routingEventName(){return this.__routingEventName||"sym-on-route"}static readAddressBar(){let e={route:null,options:{}};return window.location.search.split(this.separator).forEach(s=>{if(s.includes("?"))e.route=s.replace("?","");else if(s.includes("=")){let i=s.split("=");e.options[i[0]]=decodeURI(i[1])}else e.options[s]=!0}),e}static notify(){let e=this.readAddressBar(),t=this.appMap[e.route];if(t&&t.title&&(document.title=t.title),e.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 "${e.route}" not found...`);return}let s=new CustomEvent(U.routingEventName,{detail:{route:e.route,options:Object.assign(t||{},e.options)}});window.dispatchEvent(s)}static reflect(e,t={}){let s=this.appMap[e];if(!s){this._print("Wrong route: "+e);return}let i="?"+e;for(let n in t)t[n]===!0?i+=this.separator+n:i+=this.separator+n+`=${t[n]}`;let r=s.title||this.defaultTitle||"";window.history.pushState(null,r,i),document.title=r}static applyRoute(e,t={}){this.reflect(e,t),this.notify()}static setSeparator(e){this._separator=e}static get separator(){return this._separator||"&"}static createRouterData(e,t){this.setRoutingMap(t);let s=h.registerCtx({route:null,options:null,title:null},e);return window.addEventListener(this.routingEventName,i=>{var r;s.multiPub({route:i.detail.route,options:i.detail.options,title:((r=i.detail.options)==null?void 0:r.title)||this.defaultTitle||""})}),U.notify(),this.initPopstateListener(),s}static initPopstateListener(){this.__onPopstate||(this.__onPopstate=()=>{this.notify()},window.addEventListener("popstate",this.__onPopstate))}static removePopstateListener(){window.removeEventListener("popstate",this.__onPopstate),this.__onPopstate=null}};U.appMap=Object.create(null);var Q="idb-store-ready",Pt="symbiote-db",$t="symbiote-idb-update_",Rt=class{_notifyWhenReady(e=null){window.dispatchEvent(new CustomEvent(Q,{detail:{dbName:this.name,storeName:this.storeName,event:e}}))}get _updEventName(){return $t+this.name}_getUpdateEvent(e){return new CustomEvent(this._updEventName,{detail:{key:this.name,newValue:e}})}_notifySubscribers(e){window.localStorage.removeItem(this.name),window.localStorage.setItem(this.name,e),window.dispatchEvent(this._getUpdateEvent(e))}constructor(e,t){this.name=e,this.storeName=t,this.version=1,this.request=window.indexedDB.open(this.name,this.version),this.request.onupgradeneeded=s=>{this.db=s.target.result,this.objStore=this.db.createObjectStore(t,{keyPath:"_key"}),this.objStore.transaction.oncomplete=i=>{this._notifyWhenReady(i)}},this.request.onsuccess=s=>{this.db=s.target.result,this._notifyWhenReady(s)},this.request.onerror=s=>{console.error(s)},this._subscriptionsMap={},this._updateHandler=s=>{s.key===this.name&&this._subscriptionsMap[s.newValue]&&this._subscriptionsMap[s.newValue].forEach(async r=>{r(await this.read(s.newValue))})},this._localUpdateHandler=s=>{this._updateHandler(s.detail)},window.addEventListener("storage",this._updateHandler),window.addEventListener(this._updEventName,this._localUpdateHandler)}read(e){let s=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).get(e);return new Promise((i,r)=>{s.onsuccess=n=>{var o;(o=n.target.result)!=null&&o._value?i(n.target.result._value):(i(null),console.warn(`IDB: cannot read "${e}"`))},s.onerror=n=>{r(n)}})}write(e,t,s=!1){let i={_key:e,_value:t},n=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).put(i);return new Promise((o,l)=>{n.onsuccess=u=>{s||this._notifySubscribers(e),o(u.target.result)},n.onerror=u=>{l(u)}})}delete(e,t=!1){let i=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).delete(e);return new Promise((r,n)=>{i.onsuccess=o=>{t||this._notifySubscribers(e),r(o)},i.onerror=o=>{n(o)}})}getAll(){let t=this.db.transaction(this.storeName,"readwrite").objectStore(this.storeName).getAll();return new Promise((s,i)=>{t.onsuccess=r=>{let n=r.target.result;s(n.map(o=>o._value))},t.onerror=r=>{i(r)}})}subscribe(e,t){this._subscriptionsMap[e]||(this._subscriptionsMap[e]=new Set);let s=this._subscriptionsMap[e];return s.add(t),{remove:()=>{s.delete(t),s.size||delete this._subscriptionsMap[e]}}}stop(){window.removeEventListener("storage",this._updateHandler),this._subscriptionsMap=null,Z.clear(this.name)}},Z=class{static get readyEventName(){return Q}static open(e=Pt,t="store"){let s=e+"/"+t;return this._reg[s]||(this._reg[s]=new Rt(e,t)),this._reg[s]}static clear(e){window.indexedDB.deleteDatabase(e);for(let t in this._reg)t.split("/")[0]===e&&delete this._reg[t]}};M(Z,"_reg",Object.create(null));var tt="1.24.5";var et="blocks",st=tt;var It="https://ucarecdn.com",v=Object.freeze({"dev-mode":{},pubkey:{},uuid:{},src:{},lazy:{default:1},intersection:{},breakpoints:{},"cdn-cname":{default:It},"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 it=Object.create(null);for(let e in v)it[b+e]=v[e]?.default||"";var S=class extends B{cssInit$=it;$$(t){return this.$[b+t]}set$$(t){for(let s in t)this.$[b+s]=t[s]}sub$$(t,s){this.sub(b+t,i=>{i===null||i===""||s(i)})}analyticsParams(){return`-/@clib/${et}/${st}/uc-img/`}initAttributes(t){[...this.attributes].forEach(s=>{v[s.name]||t.setAttribute(s.name,s.value)})}initIntersection(t,s){let i={root:null,rootMargin:"0px"};this._isnObserver=new IntersectionObserver(r=>{r.forEach(n=>{n.isIntersecting&&(s(),this._isnObserver.unobserve(t))})},i),this._isnObserver.observe(t),this._observed||(this._observed=new Set),this._observed.add(t)}destroyCallback(){super.destroyCallback(),this._isnObserver&&(this._observed.forEach(t=>{this._isnObserver.unobserve(t)}),this._isnObserver=null),h.deleteCtx(this)}static get observedAttributes(){return Object.keys(v)}attributeChangedCallback(t,s,i){window.setTimeout(()=>{this.$[b+t]=i})}};var rt=e=>Object.entries(e).filter(([t,s])=>s!==void 0&&s!=="").map(([t,s])=>t==="cdn-operations"||t==="analytics"?s:`${t}/${s}`);var R=class extends S{_img=new Image;_imgPreview=new Image;_fmtAbs(t){return!t.includes("//")&&!N&&(t=new URL(t,document.baseURI).href),t}_validateSize(t){if(t?.trim()!==""){let s=t.match(/\d+/)[0],i=t.match(/[a-zA-Z]+/)[0],r=parseInt(s,10);if(Number(r)>k&&this.hasFormatJPG)return k+i;if(Number(r)>j&&!this.hasFormatJPG)return j+i}return t}_getCdnModifiers(t,s){let i={format:this.$$("format"),quality:this.$$("quality"),resize:this._validateSize(t),blur:s,"cdn-operations":this.$$("cdn-operations"),analytics:this.analyticsParams()};return F(...rt(i))}_getUrlBase(t="",s=""){if(this.$$("src").startsWith("data:")||this.$$("src").startsWith("blob:"))return this.$$("src");if(N&&this.$$("src")&&!this.$$("src").includes("//"))return this._proxyUrl(this.$$("src"));let i=this._getCdnModifiers(t,s);if(this.$$("src").startsWith(this.$$("cdn-cname")))return g(this.$$("src"),i);if(this.$$("cdn-cname")&&this.$$("uuid"))return this._proxyUrl(g(I(this.$$("cdn-cname"),this.$$("uuid")),i));if(this.$$("uuid"))return this._proxyUrl(g(I(this.$$("cdn-cname"),this.$$("uuid")),i));if(this.$$("proxy-cname"))return this._proxyUrl(g(this.$$("proxy-cname"),i,this._fmtAbs(this.$$("src"))));if(this.$$("pubkey"))return this._proxyUrl(g(`https://${this.$$("pubkey")}.ucr.io/`,i,this._fmtAbs(this.$$("src"))))}_proxyUrl(t){return this.$$("secure-delivery-proxy")?q(this.$$("secure-delivery-proxy"),{previewUrl:t},{transform:i=>window.encodeURIComponent(i)}):t}_getElSize(t,s=1,i=!0){let r=t.getBoundingClientRect(),n=s*Math.round(r.width),o=i?"":s*Math.round(r.height);return n||o?`${n||""}x${o||""}`:null}_setupEventProxy(t){let s=r=>{r.stopPropagation();let n=new Event(r.type,r);this.dispatchEvent(n)},i=["load","error"];for(let r of i)t.addEventListener(r,s)}get img(){return this.hasPreviewImage||(this._setupConfigForImage({elNode:this._img}),this.appendChild(this._img)),this._img}get currentImg(){return this.hasPreviewImage?{type:L.PREVIEW,img:this._imgPreview}:{type:L.MAIN,img:this.img}}get hasPreviewImage(){return this.$$("is-preview-blur")}get bgSelector(){return this.$$("is-background-for")}get breakpoints(){if(this.$$("breakpoints")){let t=W(this.$$("breakpoints"));return H(t.map(s=>parseInt(s,10)))}else return null}get hasFormatJPG(){return this.$$("format").toLowerCase()==="jpeg"}renderBg(t){let s=new Set;s.add(`url("${this._getUrlBase(this._getElSize(t))}") 1x`),this.$$("hi-res-support")&&s.add(`url("${this._getUrlBase(this._getElSize(t,2))}") ${2}x`),this.$$("ultra-res-support")&&s.add(`url("${this._getUrlBase(this._getElSize(t,3))}") ${3}x`);let i=`image-set(${[...s].join(", ")})`;t.style.setProperty("background-image",i),t.style.setProperty("background-image","-webkit-"+i)}getSrcset(){let t=new Set;return this.breakpoints?this.breakpoints.forEach(s=>{t.add(this._getUrlBase(s+"x")+` ${this._validateSize(s+"w")}`),this.$$("hi-res-support")&&t.add(this._getUrlBase(s*2+"x")+` ${this._validateSize(s*2+"w")}`),this.$$("ultra-res-support")&&t.add(this._getUrlBase(s*3+"x")+` ${this._validateSize(s*3+"w")}`)}):(t.add(this._getUrlBase(this._getElSize(this.currentImg.img))+" 1x"),this.$$("hi-res-support")&&t.add(this._getUrlBase(this._getElSize(this.currentImg.img,2))+" 2x"),this.$$("ultra-res-support")&&t.add(this._getUrlBase(this._getElSize(this.currentImg.img,3))+" 3x")),[...t].join()}getSrc(){return this._getUrlBase()}get srcUrlPreview(){return this._getUrlBase("100x","100")}renderBackground(){[...document.querySelectorAll(this.bgSelector)].forEach(t=>{this.$$("intersection")?this.initIntersection(t,()=>{this.renderBg(t)}):this.renderBg(t)})}_appendURL({elNode:t,src:s,srcset:i}){s&&(t.src=s),i&&(t.srcset=i)}_setupConfigForImage({elNode:t}){this._setupEventProxy(t),this.initAttributes(t)}loaderImage({src:t,srcset:s,elNode:i}){return new Promise((r,n)=>{this._setupConfigForImage({elNode:i}),i.setAttribute(D,""),i.addEventListener("load",()=>{i.removeAttribute(D),r(i)}),i.addEventListener("error",()=>{n(!1)}),this._appendURL({elNode:i,src:t,srcset:s})})}async renderImage(){if(this.$$("intersection")){this.hasPreviewImage&&(this._setupConfigForImage({elNode:this._imgPreview}),this.appendChild(this._imgPreview)),this.initIntersection(this.currentImg.img,async()=>{this.hasPreviewImage&&(this._imgPreview.src=this.srcUrlPreview);try{await this.loaderImage({src:this.getSrc(),srcset:this.getSrcset(),elNode:this._img}),this.hasPreviewImage&&await this._imgPreview.remove(),this.appendChild(this._img)}catch{this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}});return}try{this.hasPreviewImage&&(await this.loaderImage({src:this.srcUrlPreview,elNode:this._imgPreview}),this.appendChild(this._imgPreview)),await this.loaderImage({src:this.getSrc(),srcset:this.getSrcset(),elNode:this._img}),this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}catch{this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}}init(){this.bgSelector?this.renderBackground():this.renderImage()}};var O=class extends R{initCallback(){super.initCallback(),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")})}};O.reg("uc-img");export{O as Img};
|
|
26
|
+
var z=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var T=(r,s,t,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of F(s))!H.call(r,i)&&i!==t&&z(r,i,{get:()=>s[i],enumerable:!(e=N(s,i))||e.enumerable});return r},u=(r,s,t)=>(T(r,s,"default"),t&&T(t,s,"default"));var W=r=>{if(typeof r!="string"||!r)return"";let s=r.trim();return s.startsWith("-/")?s=s.slice(2):s.startsWith("/")&&(s=s.slice(1)),s.endsWith("/")&&(s=s.slice(0,s.length-1)),s},Q=(...r)=>r.filter(s=>typeof s=="string"&&!!s).map(s=>W(s)).join("/-/"),$=(...r)=>{let s=Q(...r);return s?`-/${s}/`:""};function S(r){let s=new URL(r),t=s.pathname+s.search+s.hash,e=t.lastIndexOf("http"),i=t.lastIndexOf("/"),n="";return e>=0?n=t.slice(e):i>=0&&(n=t.slice(i+1)),n}function G(r){let s=new URL(r),t=S(r),e=O(t)?U(t).pathname:t;return s.pathname=s.pathname.replace(e,""),s.search="",s.hash="",s.toString()}function O(r){return r.startsWith("http")}function U(r){let s=new URL(r);return{pathname:`${s.origin}${s.pathname??""}`,search:s.search??"",hash:s.hash??""}}var d=(r,s,t)=>{let e=new URL(G(r)),i=t??S(r),n=s??"";if(e.pathname.startsWith("//")&&(e.pathname=e.pathname.replace("//","/")),i&&O(i)){let a=U(i);e.pathname=`${e.pathname}${n}${a.pathname||""}`,e.search=a.search,e.hash=a.hash}else e.pathname=`${e.pathname}${n}${i||""}`;return e.toString()},_=(r,s)=>{let t=new URL(r);return t.pathname=`${s}/`,t.toString()};var j=(r,s=",")=>r.trim().split(s).map(t=>t.trim()).filter(t=>t.length>0);var q=r=>r;function L(r,s={},t={}){let{openToken:e="{{",closeToken:i="}}",transform:n=q}=t;for(let a in s){let l=s[a],c=l?.toString(),m=typeof c=="string"?n(c):String(c);r=r.replaceAll(e+a+i,m)}return r}var k=r=>[...new Set(r)];var p="--uc-img-",E="unresolved";var w=!window.location.host.trim()||window.location.host.includes(":")||window.location.hostname.includes("localhost"),x=3e3,C=5e3,P=Object.freeze({PREVIEW:"PREVIEW",MAIN:"MAIN"});var o={};u(o,ut);u(o,pt);import"@lit/reactive-element";import"lit-html";import*as ut from"lit-element/lit-element.js";import*as pt from"lit-html/is-server.js";var M="1.25.0-alpha.0";var R="blocks",A=M;var X=/\\([0-9a-fA-F]{1,6} ?)/g;function Y(r){return r.length<2?!1:(r[0]==='"'||r[0]==="'")&&(r[r.length-1]==='"'||r[r.length-1]==="'")}function Z(r){let s=r;return(s[0]==='"'||s[0]==="'")&&(s=s.slice(1)),(s[s.length-1]==='"'||s[s.length-1]==="'")&&(s=s.slice(0,-1)),s}function tt(r){let s="",t="";for(let e=0;e<r.length;e++){let i=r[e+1];r[e]==="\\"&&i==='"'?(s+='\\"',e++):r[e]==='"'&&t!=="\\"?s+='\\"':s+=r[e],t=r[e]??""}return s}function D(r){let s=r;Y(r)&&(s=Z(s),s=s.replace(X,(t,e)=>String.fromCodePoint(parseInt(e.trim(),16))),s=s.replaceAll(`\\
|
|
27
|
+
`,"\\n"),s=tt(s),s='"'+s+'"');try{return JSON.parse(s)}catch{return}}function B(r){class s extends r{constructor(){super(...arguments);this.cssDataCache=null;this.computedStyle=null}getCssData(i,n=!1){let a=this.cssDataCache??Object.create(null);if(!Object.keys(a).includes(i)||!a[i]){this.computedStyle||(this.computedStyle=window.getComputedStyle(this));let l=this.computedStyle.getPropertyValue(i).trim();try{a[i]=D(l)}catch(c){n||console.warn(`CSS Data error: ${i}`,c),a[i]=null}}return this.cssDataCache=a,a[i]}}return s}function K(r){class s extends r{static reg(e){let i=this,n=window.customElements.get(e);if(n){n!==i&&console.warn([`Element with tag name "${e}" 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(`
|
|
28
|
+
`));return}window.customElements.define(e,i)}}return s}var et="https://ucarecdn.com",g=Object.freeze({"dev-mode":{},pubkey:{},uuid:{},src:{},lazy:{default:1},intersection:{},breakpoints:{},"cdn-cname":{default:et},"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 h=class extends B(K(o.LitElement)){constructor(){super();this._state={};this._subscribers=new Map;this._isnObserver=null;this._observed=null;for(let t in g){let e=g[t];this._state[p+t]=e?.default||""}}createRenderRoot(){return this}$$(t){return this._state[p+t]}set$$(t){for(let e in t){let i=p+e,n=t[e];this._state[i]=n,this._notify(i,n)}}sub$$(t,e){let i=p+t;this._subscribers.has(i)||this._subscribers.set(i,new Set),this._subscribers.get(i).add(e);let n=this._state[i];n!==null&&n!==""&&e(n)}_notify(t,e){this._subscribers.has(t)&&this._subscribers.get(t).forEach(i=>{e===null||e===""||i(e)})}analyticsParams(){return`-/@clib/${R}/${A}/uc-img/`}initAttributes(t){Array.from(this.attributes).forEach(e=>{let i=e;g[i.name]||t.setAttribute(i.name,i.value)})}initIntersection(t,e){let i={root:null,rootMargin:"0px"};this._isnObserver=new IntersectionObserver(n=>{n.forEach(a=>{a.isIntersecting&&(e(),this._isnObserver.unobserve(t))})},i),this._isnObserver.observe(t),this._observed||(this._observed=new Set),this._observed.add(t)}connectedCallback(){super.connectedCallback(),this._initCssProperties()}_initCssProperties(){for(let t in g){let e=p+t,i=this.getCssData(e,!0);i!=null&&(this._state[e]=i)}}disconnectedCallback(){super.disconnectedCallback(),this._isnObserver&&(this._observed?.forEach(t=>{this._isnObserver?.unobserve(t)}),this._isnObserver=null),this._subscribers.clear()}static get observedAttributes(){return Object.keys(g)}attributeChangedCallback(t,e,i){window.setTimeout(()=>{let n=p+t;this._state[n]=i,this._notify(n,i)})}};var V=r=>Object.entries(r).filter(([s,t])=>t!==void 0&&t!=="").map(([s,t])=>s==="cdn-operations"||s==="analytics"?t:`${s}/${t}`);var y=class extends h{constructor(){super(...arguments);this._img=new Image;this._imgPreview=new Image}_fmtAbs(t){return!t.includes("//")&&!w&&(t=new URL(t,document.baseURI).href),t}_validateSize(t){if(t?.trim()!==""){let e=t,i=e.match(/\d+/)[0],n=e.match(/[a-zA-Z]+/)[0],a=parseInt(i,10);if(Number(a)>C&&this.hasFormatJPG)return C+n;if(Number(a)>x&&!this.hasFormatJPG)return x+n}return t}_getCdnModifiers(t,e){let i={format:this._getTypedCssValue("format"),quality:this._getTypedCssValue("quality"),resize:this._validateSize(t),blur:e,"cdn-operations":this._getTypedCssValue("cdn-operations")??void 0,analytics:this.analyticsParams()};return $(...V(i))}_getTypedCssValue(t){let e=this.$$(t);if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e}_getUrlBase(t="",e=""){let i=this.$$("src");if(i.startsWith("data:")||i.startsWith("blob:"))return i;if(w&&i&&!i.includes("//"))return this._proxyUrl(i);let n=this._getCdnModifiers(t,e),a=this.$$("cdn-cname"),l=a;if(i.startsWith(String(a)))return d(i,n);let c=this.$$("uuid");if(l&&c)return this._proxyUrl(d(_(l,c),n));if(c)return this._proxyUrl(d(_(l,c),n));let m=this.$$("proxy-cname");if(m)return this._proxyUrl(d(m,n,this._fmtAbs(i)));let I=this.$$("pubkey");if(I)return this._proxyUrl(d(`https://${I}.ucr.io/`,n,this._fmtAbs(i)))}_proxyUrl(t){let e=this.$$("secure-delivery-proxy");return e?L(e,{previewUrl:t},{transform:i=>window.encodeURIComponent(i)}):t}_getElSize(t,e=1,i=!0){let n=t.getBoundingClientRect(),a=e*Math.round(n.width),l=i?"":e*Math.round(n.height);return a||l?`${a||""}x${l||""}`:null}_setupEventProxy(t){let e=n=>{n.stopPropagation();let a=new Event(n.type,n);this.dispatchEvent(a)},i=["load","error"];for(let n of i)t.addEventListener(n,e)}get img(){return this.hasPreviewImage||(this._setupConfigForImage({elNode:this._img}),this.appendChild(this._img)),this._img}get currentImg(){return this.hasPreviewImage?{type:P.PREVIEW,img:this._imgPreview}:{type:P.MAIN,img:this.img}}get hasPreviewImage(){return this.$$("is-preview-blur")}get bgSelector(){return this.$$("is-background-for")}get breakpoints(){let t=this.$$("breakpoints");if(t){let e=j(t);return k(e.map(i=>parseInt(i,10)))}else return null}get hasFormatJPG(){return this.$$("format").toLowerCase()==="jpeg"}renderBg(t){let e=new Set;e.add(`url("${this._getUrlBase(this._getElSize(t))}") 1x`),this.$$("hi-res-support")&&e.add(`url("${this._getUrlBase(this._getElSize(t,2))}") ${2}x`),this.$$("ultra-res-support")&&e.add(`url("${this._getUrlBase(this._getElSize(t,3))}") ${3}x`);let i=`image-set(${[...e].join(", ")})`;t.style.setProperty("background-image",i),t.style.setProperty("background-image","-webkit-"+i)}getSrcset(){let t=new Set;return this.breakpoints?this.breakpoints.forEach(e=>{t.add(`${this._getUrlBase(`${e}x`)} ${this._validateSize(`${e}w`)}`),this.$$("hi-res-support")&&t.add(`${this._getUrlBase(`${e*2}x`)} ${this._validateSize(`${e*2}w`)}`),this.$$("ultra-res-support")&&t.add(`${this._getUrlBase(`${e*3}x`)} ${this._validateSize(`${e*3}w`)}`)}):(t.add(`${this._getUrlBase(this._getElSize(this.currentImg.img))} 1x`),this.$$("hi-res-support")&&t.add(`${this._getUrlBase(this._getElSize(this.currentImg.img,2))} 2x`),this.$$("ultra-res-support")&&t.add(`${this._getUrlBase(this._getElSize(this.currentImg.img,3))} 3x`)),[...t].join()}getSrc(){return this._getUrlBase()}get srcUrlPreview(){return this._getUrlBase("100x","100")}renderBackground(){let t=this.bgSelector;[...document.querySelectorAll(t)].forEach(e=>{this.$$("intersection")?this.initIntersection(e,()=>{this.renderBg(e)}):this.renderBg(e)})}_appendURL({elNode:t,src:e,srcset:i}){e&&(t.src=e),i&&(t.srcset=i)}_setupConfigForImage({elNode:t}){this._setupEventProxy(t),this.initAttributes(t)}loaderImage({src:t,srcset:e,elNode:i}){return new Promise((n,a)=>{this._setupConfigForImage({elNode:i}),i.setAttribute(E,""),i.addEventListener("load",()=>{i.removeAttribute(E),n(i)}),i.addEventListener("error",()=>{a(!1)}),this._appendURL({elNode:i,src:t,srcset:e})})}async renderImage(){if(this.$$("intersection")){this.hasPreviewImage&&(this._setupConfigForImage({elNode:this._imgPreview}),this.appendChild(this._imgPreview)),this.initIntersection(this.currentImg.img,async()=>{this.hasPreviewImage&&(this._imgPreview.src=this.srcUrlPreview);try{await this.loaderImage({src:this.getSrc(),srcset:this.getSrcset(),elNode:this._img}),this.hasPreviewImage&&await this._imgPreview.remove(),this.appendChild(this._img)}catch{this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}});return}try{this.hasPreviewImage&&(await this.loaderImage({src:this.srcUrlPreview,elNode:this._imgPreview}),this.appendChild(this._imgPreview)),await this.loaderImage({src:this.getSrc(),srcset:this.getSrcset(),elNode:this._img}),this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}catch{this.hasPreviewImage&&await this._imgPreview?.remove(),this.appendChild(this._img)}}init(){this.bgSelector?this.renderBackground():this.renderImage()}};var v=class extends y{connectedCallback(){super.connectedCallback(),this.sub$$("src",()=>{this.init()}),this.sub$$("uuid",()=>{this.init()}),this.sub$$("lazy",s=>{!this.$$("is-background-for")&&!this.$$("is-preview-blur")&&(this.img.loading=s?"lazy":"eager")})}};v.reg("uc-img");export{v as Img};
|