@editorjs/image
Advanced tools
Comparing version 2.9.3 to 2.10.0
@@ -1,3 +0,3 @@ | ||
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.image-tool{--bg-color: #cdd1e0;--front-color: #388ae5;--border-color: #e8e8eb}.image-tool__image{border-radius:3px;overflow:hidden;margin-bottom:10px}.image-tool__image-picture{max-width:100%;vertical-align:bottom;display:block}.image-tool__image-preloader{width:50px;height:50px;border-radius:50%;background-size:cover;margin:auto;position:relative;background-color:var(--bg-color);background-position:center center}.image-tool__image-preloader:after{content:"";position:absolute;z-index:3;width:60px;height:60px;border-radius:50%;border:2px solid var(--bg-color);border-top-color:var(--front-color);left:50%;top:50%;margin-top:-30px;margin-left:-30px;animation:image-preloader-spin 2s infinite linear;box-sizing:border-box}.image-tool__caption[contentEditable=true][data-placeholder]:before{position:absolute!important;content:attr(data-placeholder);color:#707684;font-weight:400;display:none}.image-tool__caption[contentEditable=true][data-placeholder]:empty:before{display:block}.image-tool__caption[contentEditable=true][data-placeholder]:empty:focus:before{display:none}.image-tool--empty .image-tool__image,.image-tool--empty .image-tool__caption,.image-tool--loading .image-tool__caption{display:none}.image-tool .cdx-button{display:flex;align-items:center;justify-content:center}.image-tool .cdx-button svg{height:auto;margin:0 6px 0 0}.image-tool--filled .cdx-button,.image-tool--filled .image-tool__image-preloader{display:none}.image-tool--loading .image-tool__image{min-height:200px;display:flex;border:1px solid var(--border-color);background-color:#fff}.image-tool--loading .image-tool__image-picture,.image-tool--loading .cdx-button{display:none}.image-tool--withBorder .image-tool__image{border:1px solid var(--border-color)}.image-tool--withBackground .image-tool__image{padding:15px;background:var(--bg-color)}.image-tool--withBackground .image-tool__image-picture{max-width:60%;margin:0 auto}.image-tool--stretched .image-tool__image-picture{width:100%}@keyframes image-preloader-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}')),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})(); | ||
(function(F,M){typeof exports=="object"&&typeof module<"u"?module.exports=M():typeof define=="function"&&define.amd?define(M):(F=typeof globalThis<"u"?globalThis:F||self,F.ImageTool=M())})(this,function(){"use strict";const F='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 19V19C9.13623 19 8.20435 19 7.46927 18.6955C6.48915 18.2895 5.71046 17.5108 5.30448 16.5307C5 15.7956 5 14.8638 5 13V12C5 9.19108 5 7.78661 5.67412 6.77772C5.96596 6.34096 6.34096 5.96596 6.77772 5.67412C7.78661 5 9.19108 5 12 5H13.5C14.8956 5 15.5933 5 16.1611 5.17224C17.4395 5.56004 18.44 6.56046 18.8278 7.83886C19 8.40666 19 9.10444 19 10.5V10.5"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 13V16M16 19V16M19 16H16M16 16H13"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6.5 17.5L17.5 6.5"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.9919 10.5H19.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.9919 19H11.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13L13 5"/></svg>',M='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.9919 9.5H19.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.5 5H14.5096"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M14.625 5H15C17.2091 5 19 6.79086 19 9V9.375"/><path stroke="currentColor" stroke-width="2" d="M9.375 5L9 5C6.79086 5 5 6.79086 5 9V9.375"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.3725 5H9.38207"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 9.5H5.00957"/><path stroke="currentColor" stroke-width="2" d="M9.375 19H9C6.79086 19 5 17.2091 5 15V14.625"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.3725 19H9.38207"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 14.55H5.00957"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 13V16M16 19V16M19 16H16M16 16H13"/></svg>',H='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><rect width="14" height="14" x="5" y="5" stroke="currentColor" stroke-width="2" rx="4"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.13968 15.32L8.69058 11.5661C9.02934 11.2036 9.48873 11 9.96774 11C10.4467 11 10.9061 11.2036 11.2449 11.5661L15.3871 16M13.5806 14.0664L15.0132 12.533C15.3519 12.1705 15.8113 11.9668 16.2903 11.9668C16.7693 11.9668 17.2287 12.1705 17.5675 12.533L18.841 13.9634"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.7778 9.33331H13.7867"/></svg>',x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9L20 12L17 15"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 12H20"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 9L4 12L7 15"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 12H10"/></svg>';function S(C,a=null,r={}){const c=document.createElement(C);Array.isArray(a)?c.classList.add(...a):a!==null&&c.classList.add(a);for(const i in r)r.hasOwnProperty(i)&&(c[i]=r[i]);return c}var O=(C=>(C.Empty="empty",C.Uploading="uploading",C.Filled="filled",C))(O||{});class U{constructor({api:a,config:r,onSelectFile:c,readOnly:i}){this.api=a,this.config=r,this.onSelectFile=c,this.readOnly=i,this.nodes={wrapper:S("div",[this.CSS.baseClass,this.CSS.wrapper]),imageContainer:S("div",[this.CSS.imageContainer]),fileButton:this.createFileButton(),imageEl:void 0,imagePreloader:S("div",this.CSS.imagePreloader),caption:S("div",[this.CSS.input,this.CSS.caption],{contentEditable:!this.readOnly})},this.nodes.caption.dataset.placeholder=this.config.captionPlaceholder,this.nodes.imageContainer.appendChild(this.nodes.imagePreloader),this.nodes.wrapper.appendChild(this.nodes.imageContainer),this.nodes.wrapper.appendChild(this.nodes.caption),this.nodes.wrapper.appendChild(this.nodes.fileButton)}applyTune(a,r){this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${a}`,r)}render(a){return a.file===void 0||Object.keys(a.file).length===0?this.toggleStatus("empty"):this.toggleStatus("uploading"),this.nodes.wrapper}showPreloader(a){this.nodes.imagePreloader.style.backgroundImage=`url(${a})`,this.toggleStatus("uploading")}hidePreloader(){this.nodes.imagePreloader.style.backgroundImage="",this.toggleStatus("empty")}fillImage(a){const r=/\.mp4$/.test(a)?"VIDEO":"IMG",c={src:a};let i="load";r==="VIDEO"&&(c.autoplay=!0,c.loop=!0,c.muted=!0,c.playsinline=!0,i="loadeddata"),this.nodes.imageEl=S(r,this.CSS.imageEl,c),this.nodes.imageEl.addEventListener(i,()=>{this.toggleStatus("filled"),this.nodes.imagePreloader!==void 0&&(this.nodes.imagePreloader.style.backgroundImage="")}),this.nodes.imageContainer.appendChild(this.nodes.imageEl)}fillCaption(a){this.nodes.caption!==void 0&&(this.nodes.caption.innerHTML=a)}get CSS(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,wrapper:"image-tool",imageContainer:"image-tool__image",imagePreloader:"image-tool__image-preloader",imageEl:"image-tool__image-picture",caption:"image-tool__caption"}}createFileButton(){const a=S("div",[this.CSS.button]);return a.innerHTML=this.config.buttonContent??`${H} ${this.api.i18n.t("Select an Image")}`,a.addEventListener("click",()=>{this.onSelectFile()}),a}toggleStatus(a){for(const r in O)Object.prototype.hasOwnProperty.call(O,r)&&this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${O[r]}`,a===O[r])}}function D(C){return C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C.default:C}var I={exports:{}};(function(C,a){(function(r,c){C.exports=c()})(window,function(){return function(r){var c={};function i(o){if(c[o])return c[o].exports;var n=c[o]={i:o,l:!1,exports:{}};return r[o].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=r,i.c=c,i.d=function(o,n,d){i.o(o,n)||Object.defineProperty(o,n,{enumerable:!0,get:d})},i.r=function(o){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},i.t=function(o,n){if(1&n&&(o=i(o)),8&n||4&n&&typeof o=="object"&&o&&o.__esModule)return o;var d=Object.create(null);if(i.r(d),Object.defineProperty(d,"default",{enumerable:!0,value:o}),2&n&&typeof o!="string")for(var b in o)i.d(d,b,(function(u){return o[u]}).bind(null,b));return d},i.n=function(o){var n=o&&o.__esModule?function(){return o.default}:function(){return o};return i.d(n,"a",n),n},i.o=function(o,n){return Object.prototype.hasOwnProperty.call(o,n)},i.p="",i(i.s=3)}([function(r,c){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch{typeof window=="object"&&(i=window)}r.exports=i},function(r,c,i){(function(o){var n=i(2),d=setTimeout;function b(){}function u(e){if(!(this instanceof u))throw new TypeError("Promises must be constructed via new");if(typeof e!="function")throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],t(e,this)}function f(e,l){for(;e._state===3;)e=e._value;e._state!==0?(e._handled=!0,u._immediateFn(function(){var s=e._state===1?l.onFulfilled:l.onRejected;if(s!==null){var g;try{g=s(e._value)}catch(m){return void y(l.promise,m)}p(l.promise,g)}else(e._state===1?p:y)(l.promise,e._value)})):e._deferreds.push(l)}function p(e,l){try{if(l===e)throw new TypeError("A promise cannot be resolved with itself.");if(l&&(typeof l=="object"||typeof l=="function")){var s=l.then;if(l instanceof u)return e._state=3,e._value=l,void w(e);if(typeof s=="function")return void t((g=s,m=l,function(){g.apply(m,arguments)}),e)}e._state=1,e._value=l,w(e)}catch(h){y(e,h)}var g,m}function y(e,l){e._state=2,e._value=l,w(e)}function w(e){e._state===2&&e._deferreds.length===0&&u._immediateFn(function(){e._handled||u._unhandledRejectionFn(e._value)});for(var l=0,s=e._deferreds.length;l<s;l++)f(e,e._deferreds[l]);e._deferreds=null}function v(e,l,s){this.onFulfilled=typeof e=="function"?e:null,this.onRejected=typeof l=="function"?l:null,this.promise=s}function t(e,l){var s=!1;try{e(function(g){s||(s=!0,p(l,g))},function(g){s||(s=!0,y(l,g))})}catch(g){if(s)return;s=!0,y(l,g)}}u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,l){var s=new this.constructor(b);return f(this,new v(e,l,s)),s},u.prototype.finally=n.a,u.all=function(e){return new u(function(l,s){if(!e||e.length===void 0)throw new TypeError("Promise.all accepts an array");var g=Array.prototype.slice.call(e);if(g.length===0)return l([]);var m=g.length;function h(T,E){try{if(E&&(typeof E=="object"||typeof E=="function")){var j=E.then;if(typeof j=="function")return void j.call(E,function(R){h(T,R)},s)}g[T]=E,--m==0&&l(g)}catch(R){s(R)}}for(var k=0;k<g.length;k++)h(k,g[k])})},u.resolve=function(e){return e&&typeof e=="object"&&e.constructor===u?e:new u(function(l){l(e)})},u.reject=function(e){return new u(function(l,s){s(e)})},u.race=function(e){return new u(function(l,s){for(var g=0,m=e.length;g<m;g++)e[g].then(l,s)})},u._immediateFn=typeof o=="function"&&function(e){o(e)}||function(e){d(e,0)},u._unhandledRejectionFn=function(e){typeof console<"u"&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},c.a=u}).call(this,i(5).setImmediate)},function(r,c,i){c.a=function(o){var n=this.constructor;return this.then(function(d){return n.resolve(o()).then(function(){return d})},function(d){return n.resolve(o()).then(function(){return n.reject(d)})})}},function(r,c,i){function o(t){return(o=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}i(4);var n,d,b,u,f,p,y,w=i(8),v=(d=function(t){return new Promise(function(e,l){t=u(t),(t=f(t)).beforeSend&&t.beforeSend();var s=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");s.open(t.method,t.url),s.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(t.headers).forEach(function(m){var h=t.headers[m];s.setRequestHeader(m,h)});var g=t.ratio;s.upload.addEventListener("progress",function(m){var h=Math.round(m.loaded/m.total*100),k=Math.ceil(h*g/100);t.progress(Math.min(k,100))},!1),s.addEventListener("progress",function(m){var h=Math.round(m.loaded/m.total*100),k=Math.ceil(h*(100-g)/100)+g;t.progress(Math.min(k,100))},!1),s.onreadystatechange=function(){if(s.readyState===4){var m=s.response;try{m=JSON.parse(m)}catch{}var h=w.parseHeaders(s.getAllResponseHeaders()),k={body:m,code:s.status,headers:h};y(s.status)?e(k):l(k)}},s.send(t.data)})},b=function(t){return t.method="POST",d(t)},u=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(t.url&&typeof t.url!="string")throw new Error("Url must be a string");if(t.url=t.url||"",t.method&&typeof t.method!="string")throw new Error("`method` must be a string or null");if(t.method=t.method?t.method.toUpperCase():"GET",t.headers&&o(t.headers)!=="object")throw new Error("`headers` must be an object or null");if(t.headers=t.headers||{},t.type&&(typeof t.type!="string"||!Object.values(n).includes(t.type)))throw new Error("`type` must be taken from module's «contentType» library");if(t.progress&&typeof t.progress!="function")throw new Error("`progress` must be a function or null");if(t.progress=t.progress||function(e){},t.beforeSend=t.beforeSend||function(e){},t.ratio&&typeof t.ratio!="number")throw new Error("`ratio` must be a number");if(t.ratio<0||t.ratio>100)throw new Error("`ratio` must be in a 0-100 interval");if(t.ratio=t.ratio||90,t.accept&&typeof t.accept!="string")throw new Error("`accept` must be a string with a list of allowed mime-types");if(t.accept=t.accept||"*/*",t.multiple&&typeof t.multiple!="boolean")throw new Error("`multiple` must be a true or false");if(t.multiple=t.multiple||!1,t.fieldName&&typeof t.fieldName!="string")throw new Error("`fieldName` must be a string");return t.fieldName=t.fieldName||"files",t},f=function(t){switch(t.method){case"GET":var e=p(t.data,n.URLENCODED);delete t.data,t.url=/\?/.test(t.url)?t.url+"&"+e:t.url+"?"+e;break;case"POST":case"PUT":case"DELETE":case"UPDATE":var l=function(){return(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).type||n.JSON}(t);(w.isFormData(t.data)||w.isFormElement(t.data))&&(l=n.FORM),t.data=p(t.data,l),l!==v.contentType.FORM&&(t.headers["content-type"]=l)}return t},p=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};switch(arguments.length>1?arguments[1]:void 0){case n.URLENCODED:return w.urlEncode(t);case n.JSON:return w.jsonEncode(t);case n.FORM:return w.formEncode(t);default:return t}},y=function(t){return t>=200&&t<300},{contentType:n={URLENCODED:"application/x-www-form-urlencoded; charset=utf-8",FORM:"multipart/form-data",JSON:"application/json; charset=utf-8"},request:d,get:function(t){return t.method="GET",d(t)},post:b,transport:function(t){return t=u(t),w.selectFiles(t).then(function(e){for(var l=new FormData,s=0;s<e.length;s++)l.append(t.fieldName,e[s],e[s].name);w.isObject(t.data)&&Object.keys(t.data).forEach(function(m){var h=t.data[m];l.append(m,h)});var g=t.beforeSend;return t.beforeSend=function(){return g(e)},t.data=l,b(t)})},selectFiles:function(t){return delete(t=u(t)).beforeSend,w.selectFiles(t)}});r.exports=v},function(r,c,i){i.r(c);var o=i(1);window.Promise=window.Promise||o.a},function(r,c,i){(function(o){var n=o!==void 0&&o||typeof self<"u"&&self||window,d=Function.prototype.apply;function b(u,f){this._id=u,this._clearFn=f}c.setTimeout=function(){return new b(d.call(setTimeout,n,arguments),clearTimeout)},c.setInterval=function(){return new b(d.call(setInterval,n,arguments),clearInterval)},c.clearTimeout=c.clearInterval=function(u){u&&u.close()},b.prototype.unref=b.prototype.ref=function(){},b.prototype.close=function(){this._clearFn.call(n,this._id)},c.enroll=function(u,f){clearTimeout(u._idleTimeoutId),u._idleTimeout=f},c.unenroll=function(u){clearTimeout(u._idleTimeoutId),u._idleTimeout=-1},c._unrefActive=c.active=function(u){clearTimeout(u._idleTimeoutId);var f=u._idleTimeout;f>=0&&(u._idleTimeoutId=setTimeout(function(){u._onTimeout&&u._onTimeout()},f))},i(6),c.setImmediate=typeof self<"u"&&self.setImmediate||o!==void 0&&o.setImmediate||this&&this.setImmediate,c.clearImmediate=typeof self<"u"&&self.clearImmediate||o!==void 0&&o.clearImmediate||this&&this.clearImmediate}).call(this,i(0))},function(r,c,i){(function(o,n){(function(d,b){if(!d.setImmediate){var u,f,p,y,w,v=1,t={},e=!1,l=d.document,s=Object.getPrototypeOf&&Object.getPrototypeOf(d);s=s&&s.setTimeout?s:d,{}.toString.call(d.process)==="[object process]"?u=function(h){n.nextTick(function(){m(h)})}:function(){if(d.postMessage&&!d.importScripts){var h=!0,k=d.onmessage;return d.onmessage=function(){h=!1},d.postMessage("","*"),d.onmessage=k,h}}()?(y="setImmediate$"+Math.random()+"$",w=function(h){h.source===d&&typeof h.data=="string"&&h.data.indexOf(y)===0&&m(+h.data.slice(y.length))},d.addEventListener?d.addEventListener("message",w,!1):d.attachEvent("onmessage",w),u=function(h){d.postMessage(y+h,"*")}):d.MessageChannel?((p=new MessageChannel).port1.onmessage=function(h){m(h.data)},u=function(h){p.port2.postMessage(h)}):l&&"onreadystatechange"in l.createElement("script")?(f=l.documentElement,u=function(h){var k=l.createElement("script");k.onreadystatechange=function(){m(h),k.onreadystatechange=null,f.removeChild(k),k=null},f.appendChild(k)}):u=function(h){setTimeout(m,0,h)},s.setImmediate=function(h){typeof h!="function"&&(h=new Function(""+h));for(var k=new Array(arguments.length-1),T=0;T<k.length;T++)k[T]=arguments[T+1];var E={callback:h,args:k};return t[v]=E,u(v),v++},s.clearImmediate=g}function g(h){delete t[h]}function m(h){if(e)setTimeout(m,0,h);else{var k=t[h];if(k){e=!0;try{(function(T){var E=T.callback,j=T.args;switch(j.length){case 0:E();break;case 1:E(j[0]);break;case 2:E(j[0],j[1]);break;case 3:E(j[0],j[1],j[2]);break;default:E.apply(b,j)}})(k)}finally{g(h),e=!1}}}}})(typeof self>"u"?o===void 0?this:o:self)}).call(this,i(0),i(7))},function(r,c){var i,o,n=r.exports={};function d(){throw new Error("setTimeout has not been defined")}function b(){throw new Error("clearTimeout has not been defined")}function u(s){if(i===setTimeout)return setTimeout(s,0);if((i===d||!i)&&setTimeout)return i=setTimeout,setTimeout(s,0);try{return i(s,0)}catch{try{return i.call(null,s,0)}catch{return i.call(this,s,0)}}}(function(){try{i=typeof setTimeout=="function"?setTimeout:d}catch{i=d}try{o=typeof clearTimeout=="function"?clearTimeout:b}catch{o=b}})();var f,p=[],y=!1,w=-1;function v(){y&&f&&(y=!1,f.length?p=f.concat(p):w=-1,p.length&&t())}function t(){if(!y){var s=u(v);y=!0;for(var g=p.length;g;){for(f=p,p=[];++w<g;)f&&f[w].run();w=-1,g=p.length}f=null,y=!1,function(m){if(o===clearTimeout)return clearTimeout(m);if((o===b||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(m);try{o(m)}catch{try{return o.call(null,m)}catch{return o.call(this,m)}}}(s)}}function e(s,g){this.fun=s,this.array=g}function l(){}n.nextTick=function(s){var g=new Array(arguments.length-1);if(arguments.length>1)for(var m=1;m<arguments.length;m++)g[m-1]=arguments[m];p.push(new e(s,g)),p.length!==1||y||u(t)},e.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=l,n.addListener=l,n.once=l,n.off=l,n.removeListener=l,n.removeAllListeners=l,n.emit=l,n.prependListener=l,n.prependOnceListener=l,n.listeners=function(s){return[]},n.binding=function(s){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(s){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},function(r,c,i){function o(d,b){for(var u=0;u<b.length;u++){var f=b[u];f.enumerable=f.enumerable||!1,f.configurable=!0,"value"in f&&(f.writable=!0),Object.defineProperty(d,f.key,f)}}var n=i(9);r.exports=function(){function d(){(function(p,y){if(!(p instanceof y))throw new TypeError("Cannot call a class as a function")})(this,d)}var b,u,f;return b=d,f=[{key:"urlEncode",value:function(p){return n(p)}},{key:"jsonEncode",value:function(p){return JSON.stringify(p)}},{key:"formEncode",value:function(p){if(this.isFormData(p))return p;if(this.isFormElement(p))return new FormData(p);if(this.isObject(p)){var y=new FormData;return Object.keys(p).forEach(function(w){var v=p[w];y.append(w,v)}),y}throw new Error("`data` must be an instance of Object, FormData or <FORM> HTMLElement")}},{key:"isObject",value:function(p){return Object.prototype.toString.call(p)==="[object Object]"}},{key:"isFormData",value:function(p){return p instanceof FormData}},{key:"isFormElement",value:function(p){return p instanceof HTMLFormElement}},{key:"selectFiles",value:function(){var p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return new Promise(function(y,w){var v=document.createElement("INPUT");v.type="file",p.multiple&&v.setAttribute("multiple","multiple"),p.accept&&v.setAttribute("accept",p.accept),v.style.display="none",document.body.appendChild(v),v.addEventListener("change",function(t){var e=t.target.files;y(e),document.body.removeChild(v)},!1),v.click()})}},{key:"parseHeaders",value:function(p){var y=p.trim().split(/[\r\n]+/),w={};return y.forEach(function(v){var t=v.split(": "),e=t.shift(),l=t.join(": ");e&&(w[e]=l)}),w}}],(u=null)&&o(b.prototype,u),f&&o(b,f),d}()},function(r,c){var i=function(n){return encodeURIComponent(n).replace(/[!'()*]/g,escape).replace(/%20/g,"+")},o=function(n,d,b,u){return d=d||null,b=b||"&",u=u||null,n?function(f){for(var p=new Array,y=0;y<f.length;y++)f[y]&&p.push(f[y]);return p}(Object.keys(n).map(function(f){var p,y,w=f;if(u&&(w=u+"["+w+"]"),typeof n[f]=="object"&&n[f]!==null)p=o(n[f],null,b,w);else{d&&(y=w,w=!isNaN(parseFloat(y))&&isFinite(y)?d+Number(w):w);var v=n[f];v=(v=(v=(v=v===!0?"1":v)===!1?"0":v)===0?"0":v)||"",p=i(w)+"="+i(v)}return p})).join(b).replace(/[!'()*]/g,""):""};r.exports=o}])})})(I);var B=I.exports;const _=D(B);function L(C){return C!==void 0&&typeof C.then=="function"}class q{constructor({config:a,onUpload:r,onError:c}){this.config=a,this.onUpload=r,this.onError=c}uploadSelectedFile({onPreview:a}){const r=function(i){const o=new FileReader;o.readAsDataURL(i),o.onload=n=>{a(n.target.result)}};let c;if(this.config.uploader&&typeof this.config.uploader.uploadByFile=="function"){const i=this.config.uploader.uploadByFile;c=_.selectFiles({accept:this.config.types??"image/*"}).then(o=>{r(o[0]);const n=i(o[0]);return L(n)||console.warn("Custom uploader method uploadByFile should return a Promise"),n})}else c=_.transport({url:this.config.endpoints.byFile,data:this.config.additionalRequestData,accept:this.config.types??"image/*",headers:this.config.additionalRequestHeaders,beforeSend:i=>{r(i[0])},fieldName:this.config.field??"image"}).then(i=>i.body);c.then(i=>{this.onUpload(i)}).catch(i=>{this.onError(i)})}uploadByUrl(a){let r;this.config.uploader&&typeof this.config.uploader.uploadByUrl=="function"?(r=this.config.uploader.uploadByUrl(a),L(r)||console.warn("Custom uploader method uploadByUrl should return a Promise")):r=_.post({url:this.config.endpoints.byUrl,data:Object.assign({url:a},this.config.additionalRequestData),type:_.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(c=>c.body),r.then(c=>{this.onUpload(c)}).catch(c=>{this.onError(c)})}uploadByFile(a,{onPreview:r}){const c=new FileReader;c.readAsDataURL(a),c.onload=o=>{r(o.target.result)};let i;if(this.config.uploader&&typeof this.config.uploader.uploadByFile=="function")i=this.config.uploader.uploadByFile(a),L(i)||console.warn("Custom uploader method uploadByFile should return a Promise");else{const o=new FormData;o.append(this.config.field??"image",a),this.config.additionalRequestData&&Object.keys(this.config.additionalRequestData).length&&Object.entries(this.config.additionalRequestData).forEach(([n,d])=>{o.append(n,d)}),i=_.post({url:this.config.endpoints.byFile,data:o,type:_.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(n=>n.body)}i.then(o=>{this.onUpload(o)}).catch(o=>{this.onError(o)})}}/** | ||
(function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.image-tool{--bg-color: #cdd1e0;--front-color: #388ae5;--border-color: #e8e8eb}.image-tool__image{border-radius:3px;overflow:hidden;margin-bottom:10px}.image-tool__image-picture{max-width:100%;vertical-align:bottom;display:block}.image-tool__image-preloader{width:50px;height:50px;border-radius:50%;background-size:cover;margin:auto;position:relative;background-color:var(--bg-color);background-position:center center}.image-tool__image-preloader:after{content:"";position:absolute;z-index:3;width:60px;height:60px;border-radius:50%;border:2px solid var(--bg-color);border-top-color:var(--front-color);left:50%;top:50%;margin-top:-30px;margin-left:-30px;animation:image-preloader-spin 2s infinite linear;box-sizing:border-box}.image-tool__caption{display:none}.image-tool__caption[contentEditable=true][data-placeholder]:before{position:absolute!important;content:attr(data-placeholder);color:#707684;font-weight:400;display:none}.image-tool__caption[contentEditable=true][data-placeholder]:empty:before{display:block}.image-tool__caption[contentEditable=true][data-placeholder]:empty:focus:before{display:none}.image-tool--empty .image-tool__image,.image-tool--empty .image-tool__caption,.image-tool--loading .image-tool__caption{display:none}.image-tool .cdx-button{display:flex;align-items:center;justify-content:center}.image-tool .cdx-button svg{height:auto;margin:0 6px 0 0}.image-tool--filled .cdx-button,.image-tool--filled .image-tool__image-preloader{display:none}.image-tool--loading .image-tool__image{min-height:200px;display:flex;border:1px solid var(--border-color);background-color:#fff}.image-tool--loading .image-tool__image-picture,.image-tool--loading .cdx-button{display:none}.image-tool--withBorder .image-tool__image{border:1px solid var(--border-color)}.image-tool--withBackground .image-tool__image{padding:15px;background:var(--bg-color)}.image-tool--withBackground .image-tool__image-picture{max-width:60%;margin:0 auto}.image-tool--stretched .image-tool__image-picture{width:100%}.image-tool--caption .image-tool__caption{display:block}@keyframes image-preloader-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}')),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})(); | ||
(function(S,F){typeof exports=="object"&&typeof module<"u"?module.exports=F():typeof define=="function"&&define.amd?define(F):(S=typeof globalThis<"u"?globalThis:S||self,S.ImageTool=F())})(this,function(){"use strict";const S='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 19V19C9.13623 19 8.20435 19 7.46927 18.6955C6.48915 18.2895 5.71046 17.5108 5.30448 16.5307C5 15.7956 5 14.8638 5 13V12C5 9.19108 5 7.78661 5.67412 6.77772C5.96596 6.34096 6.34096 5.96596 6.77772 5.67412C7.78661 5 9.19108 5 12 5H13.5C14.8956 5 15.5933 5 16.1611 5.17224C17.4395 5.56004 18.44 6.56046 18.8278 7.83886C19 8.40666 19 9.10444 19 10.5V10.5"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 13V16M16 19V16M19 16H16M16 16H13"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6.5 17.5L17.5 6.5"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.9919 10.5H19.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.9919 19H11.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13L13 5"/></svg>',F='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.9919 9.5H19.0015"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14.5 5H14.5096"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M14.625 5H15C17.2091 5 19 6.79086 19 9V9.375"/><path stroke="currentColor" stroke-width="2" d="M9.375 5L9 5C6.79086 5 5 6.79086 5 9V9.375"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.3725 5H9.38207"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 9.5H5.00957"/><path stroke="currentColor" stroke-width="2" d="M9.375 19H9C6.79086 19 5 17.2091 5 15V14.625"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.3725 19H9.38207"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 14.55H5.00957"/><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M16 13V16M16 19V16M19 16H16M16 16H13"/></svg>',R='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><rect width="14" height="14" x="5" y="5" stroke="currentColor" stroke-width="2" rx="4"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.13968 15.32L8.69058 11.5661C9.02934 11.2036 9.48873 11 9.96774 11C10.4467 11 10.9061 11.2036 11.2449 11.5661L15.3871 16M13.5806 14.0664L15.0132 12.533C15.3519 12.1705 15.8113 11.9668 16.2903 11.9668C16.7693 11.9668 17.2287 12.1705 17.5675 12.533L18.841 13.9634"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.7778 9.33331H13.7867"/></svg>',x='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9L20 12L17 15"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 12H20"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 9L4 12L7 15"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 12H10"/></svg>',B='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M8 9V7.2C8 7.08954 8.08954 7 8.2 7L12 7M16 9V7.2C16 7.08954 15.9105 7 15.8 7L12 7M12 7L12 17M12 17H10M12 17H14"/></svg>';function M(C,i=null,a={}){const s=document.createElement(C);Array.isArray(i)?s.classList.add(...i):i!==null&&s.classList.add(i);for(const r in a)a.hasOwnProperty(r)&&(s[r]=a[r]);return s}var O=(C=>(C.Empty="empty",C.Uploading="uploading",C.Filled="filled",C))(O||{});class U{constructor({api:i,config:a,onSelectFile:s,readOnly:r}){this.api=i,this.config=a,this.onSelectFile=s,this.readOnly=r,this.nodes={wrapper:M("div",[this.CSS.baseClass,this.CSS.wrapper]),imageContainer:M("div",[this.CSS.imageContainer]),fileButton:this.createFileButton(),imageEl:void 0,imagePreloader:M("div",this.CSS.imagePreloader),caption:M("div",[this.CSS.input,this.CSS.caption],{contentEditable:!this.readOnly})},this.nodes.caption.dataset.placeholder=this.config.captionPlaceholder,this.nodes.imageContainer.appendChild(this.nodes.imagePreloader),this.nodes.wrapper.appendChild(this.nodes.imageContainer),this.nodes.wrapper.appendChild(this.nodes.caption),this.nodes.wrapper.appendChild(this.nodes.fileButton)}applyTune(i,a){this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${i}`,a)}render(i){return i.file===void 0||Object.keys(i.file).length===0?this.toggleStatus("empty"):this.toggleStatus("uploading"),this.nodes.wrapper}showPreloader(i){this.nodes.imagePreloader.style.backgroundImage=`url(${i})`,this.toggleStatus("uploading")}hidePreloader(){this.nodes.imagePreloader.style.backgroundImage="",this.toggleStatus("empty")}fillImage(i){const a=/\.mp4$/.test(i)?"VIDEO":"IMG",s={src:i};let r="load";a==="VIDEO"&&(s.autoplay=!0,s.loop=!0,s.muted=!0,s.playsinline=!0,r="loadeddata"),this.nodes.imageEl=M(a,this.CSS.imageEl,s),this.nodes.imageEl.addEventListener(r,()=>{this.toggleStatus("filled"),this.nodes.imagePreloader!==void 0&&(this.nodes.imagePreloader.style.backgroundImage="")}),this.nodes.imageContainer.appendChild(this.nodes.imageEl)}fillCaption(i){this.nodes.caption!==void 0&&(this.nodes.caption.innerHTML=i)}get CSS(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,wrapper:"image-tool",imageContainer:"image-tool__image",imagePreloader:"image-tool__image-preloader",imageEl:"image-tool__image-picture",caption:"image-tool__caption"}}createFileButton(){const i=M("div",[this.CSS.button]);return i.innerHTML=this.config.buttonContent??`${R} ${this.api.i18n.t("Select an Image")}`,i.addEventListener("click",()=>{this.onSelectFile()}),i}toggleStatus(i){for(const a in O)Object.prototype.hasOwnProperty.call(O,a)&&this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${O[a]}`,i===O[a])}}function D(C){return C&&C.__esModule&&Object.prototype.hasOwnProperty.call(C,"default")?C.default:C}var I={exports:{}};(function(C,i){(function(a,s){C.exports=s()})(window,function(){return function(a){var s={};function r(e){if(s[e])return s[e].exports;var o=s[e]={i:e,l:!1,exports:{}};return a[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=a,r.c=s,r.d=function(e,o,d){r.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:d})},r.r=function(e){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,o){if(1&o&&(e=r(e)),8&o||4&o&&typeof e=="object"&&e&&e.__esModule)return e;var d=Object.create(null);if(r.r(d),Object.defineProperty(d,"default",{enumerable:!0,value:e}),2&o&&typeof e!="string")for(var v in e)r.d(d,v,(function(l){return e[l]}).bind(null,v));return d},r.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(o,"a",o),o},r.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},r.p="",r(r.s=3)}([function(a,s){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch{typeof window=="object"&&(r=window)}a.exports=r},function(a,s,r){(function(e){var o=r(2),d=setTimeout;function v(){}function l(n){if(!(this instanceof l))throw new TypeError("Promises must be constructed via new");if(typeof n!="function")throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],t(n,this)}function f(n,c){for(;n._state===3;)n=n._value;n._state!==0?(n._handled=!0,l._immediateFn(function(){var u=n._state===1?c.onFulfilled:c.onRejected;if(u!==null){var g;try{g=u(n._value)}catch(m){return void y(c.promise,m)}p(c.promise,g)}else(n._state===1?p:y)(c.promise,n._value)})):n._deferreds.push(c)}function p(n,c){try{if(c===n)throw new TypeError("A promise cannot be resolved with itself.");if(c&&(typeof c=="object"||typeof c=="function")){var u=c.then;if(c instanceof l)return n._state=3,n._value=c,void w(n);if(typeof u=="function")return void t((g=u,m=c,function(){g.apply(m,arguments)}),n)}n._state=1,n._value=c,w(n)}catch(h){y(n,h)}var g,m}function y(n,c){n._state=2,n._value=c,w(n)}function w(n){n._state===2&&n._deferreds.length===0&&l._immediateFn(function(){n._handled||l._unhandledRejectionFn(n._value)});for(var c=0,u=n._deferreds.length;c<u;c++)f(n,n._deferreds[c]);n._deferreds=null}function b(n,c,u){this.onFulfilled=typeof n=="function"?n:null,this.onRejected=typeof c=="function"?c:null,this.promise=u}function t(n,c){var u=!1;try{n(function(g){u||(u=!0,p(c,g))},function(g){u||(u=!0,y(c,g))})}catch(g){if(u)return;u=!0,y(c,g)}}l.prototype.catch=function(n){return this.then(null,n)},l.prototype.then=function(n,c){var u=new this.constructor(v);return f(this,new b(n,c,u)),u},l.prototype.finally=o.a,l.all=function(n){return new l(function(c,u){if(!n||n.length===void 0)throw new TypeError("Promise.all accepts an array");var g=Array.prototype.slice.call(n);if(g.length===0)return c([]);var m=g.length;function h(E,T){try{if(T&&(typeof T=="object"||typeof T=="function")){var j=T.then;if(typeof j=="function")return void j.call(T,function(H){h(E,H)},u)}g[E]=T,--m==0&&c(g)}catch(H){u(H)}}for(var k=0;k<g.length;k++)h(k,g[k])})},l.resolve=function(n){return n&&typeof n=="object"&&n.constructor===l?n:new l(function(c){c(n)})},l.reject=function(n){return new l(function(c,u){u(n)})},l.race=function(n){return new l(function(c,u){for(var g=0,m=n.length;g<m;g++)n[g].then(c,u)})},l._immediateFn=typeof e=="function"&&function(n){e(n)}||function(n){d(n,0)},l._unhandledRejectionFn=function(n){typeof console<"u"&&console&&console.warn("Possible Unhandled Promise Rejection:",n)},s.a=l}).call(this,r(5).setImmediate)},function(a,s,r){s.a=function(e){var o=this.constructor;return this.then(function(d){return o.resolve(e()).then(function(){return d})},function(d){return o.resolve(e()).then(function(){return o.reject(d)})})}},function(a,s,r){function e(t){return(e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(t)}r(4);var o,d,v,l,f,p,y,w=r(8),b=(d=function(t){return new Promise(function(n,c){t=l(t),(t=f(t)).beforeSend&&t.beforeSend();var u=window.XMLHttpRequest?new window.XMLHttpRequest:new window.ActiveXObject("Microsoft.XMLHTTP");u.open(t.method,t.url),u.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(t.headers).forEach(function(m){var h=t.headers[m];u.setRequestHeader(m,h)});var g=t.ratio;u.upload.addEventListener("progress",function(m){var h=Math.round(m.loaded/m.total*100),k=Math.ceil(h*g/100);t.progress(Math.min(k,100))},!1),u.addEventListener("progress",function(m){var h=Math.round(m.loaded/m.total*100),k=Math.ceil(h*(100-g)/100)+g;t.progress(Math.min(k,100))},!1),u.onreadystatechange=function(){if(u.readyState===4){var m=u.response;try{m=JSON.parse(m)}catch{}var h=w.parseHeaders(u.getAllResponseHeaders()),k={body:m,code:u.status,headers:h};y(u.status)?n(k):c(k)}},u.send(t.data)})},v=function(t){return t.method="POST",d(t)},l=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(t.url&&typeof t.url!="string")throw new Error("Url must be a string");if(t.url=t.url||"",t.method&&typeof t.method!="string")throw new Error("`method` must be a string or null");if(t.method=t.method?t.method.toUpperCase():"GET",t.headers&&e(t.headers)!=="object")throw new Error("`headers` must be an object or null");if(t.headers=t.headers||{},t.type&&(typeof t.type!="string"||!Object.values(o).includes(t.type)))throw new Error("`type` must be taken from module's «contentType» library");if(t.progress&&typeof t.progress!="function")throw new Error("`progress` must be a function or null");if(t.progress=t.progress||function(n){},t.beforeSend=t.beforeSend||function(n){},t.ratio&&typeof t.ratio!="number")throw new Error("`ratio` must be a number");if(t.ratio<0||t.ratio>100)throw new Error("`ratio` must be in a 0-100 interval");if(t.ratio=t.ratio||90,t.accept&&typeof t.accept!="string")throw new Error("`accept` must be a string with a list of allowed mime-types");if(t.accept=t.accept||"*/*",t.multiple&&typeof t.multiple!="boolean")throw new Error("`multiple` must be a true or false");if(t.multiple=t.multiple||!1,t.fieldName&&typeof t.fieldName!="string")throw new Error("`fieldName` must be a string");return t.fieldName=t.fieldName||"files",t},f=function(t){switch(t.method){case"GET":var n=p(t.data,o.URLENCODED);delete t.data,t.url=/\?/.test(t.url)?t.url+"&"+n:t.url+"?"+n;break;case"POST":case"PUT":case"DELETE":case"UPDATE":var c=function(){return(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}).type||o.JSON}(t);(w.isFormData(t.data)||w.isFormElement(t.data))&&(c=o.FORM),t.data=p(t.data,c),c!==b.contentType.FORM&&(t.headers["content-type"]=c)}return t},p=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};switch(arguments.length>1?arguments[1]:void 0){case o.URLENCODED:return w.urlEncode(t);case o.JSON:return w.jsonEncode(t);case o.FORM:return w.formEncode(t);default:return t}},y=function(t){return t>=200&&t<300},{contentType:o={URLENCODED:"application/x-www-form-urlencoded; charset=utf-8",FORM:"multipart/form-data",JSON:"application/json; charset=utf-8"},request:d,get:function(t){return t.method="GET",d(t)},post:v,transport:function(t){return t=l(t),w.selectFiles(t).then(function(n){for(var c=new FormData,u=0;u<n.length;u++)c.append(t.fieldName,n[u],n[u].name);w.isObject(t.data)&&Object.keys(t.data).forEach(function(m){var h=t.data[m];c.append(m,h)});var g=t.beforeSend;return t.beforeSend=function(){return g(n)},t.data=c,v(t)})},selectFiles:function(t){return delete(t=l(t)).beforeSend,w.selectFiles(t)}});a.exports=b},function(a,s,r){r.r(s);var e=r(1);window.Promise=window.Promise||e.a},function(a,s,r){(function(e){var o=e!==void 0&&e||typeof self<"u"&&self||window,d=Function.prototype.apply;function v(l,f){this._id=l,this._clearFn=f}s.setTimeout=function(){return new v(d.call(setTimeout,o,arguments),clearTimeout)},s.setInterval=function(){return new v(d.call(setInterval,o,arguments),clearInterval)},s.clearTimeout=s.clearInterval=function(l){l&&l.close()},v.prototype.unref=v.prototype.ref=function(){},v.prototype.close=function(){this._clearFn.call(o,this._id)},s.enroll=function(l,f){clearTimeout(l._idleTimeoutId),l._idleTimeout=f},s.unenroll=function(l){clearTimeout(l._idleTimeoutId),l._idleTimeout=-1},s._unrefActive=s.active=function(l){clearTimeout(l._idleTimeoutId);var f=l._idleTimeout;f>=0&&(l._idleTimeoutId=setTimeout(function(){l._onTimeout&&l._onTimeout()},f))},r(6),s.setImmediate=typeof self<"u"&&self.setImmediate||e!==void 0&&e.setImmediate||this&&this.setImmediate,s.clearImmediate=typeof self<"u"&&self.clearImmediate||e!==void 0&&e.clearImmediate||this&&this.clearImmediate}).call(this,r(0))},function(a,s,r){(function(e,o){(function(d,v){if(!d.setImmediate){var l,f,p,y,w,b=1,t={},n=!1,c=d.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(d);u=u&&u.setTimeout?u:d,{}.toString.call(d.process)==="[object process]"?l=function(h){o.nextTick(function(){m(h)})}:function(){if(d.postMessage&&!d.importScripts){var h=!0,k=d.onmessage;return d.onmessage=function(){h=!1},d.postMessage("","*"),d.onmessage=k,h}}()?(y="setImmediate$"+Math.random()+"$",w=function(h){h.source===d&&typeof h.data=="string"&&h.data.indexOf(y)===0&&m(+h.data.slice(y.length))},d.addEventListener?d.addEventListener("message",w,!1):d.attachEvent("onmessage",w),l=function(h){d.postMessage(y+h,"*")}):d.MessageChannel?((p=new MessageChannel).port1.onmessage=function(h){m(h.data)},l=function(h){p.port2.postMessage(h)}):c&&"onreadystatechange"in c.createElement("script")?(f=c.documentElement,l=function(h){var k=c.createElement("script");k.onreadystatechange=function(){m(h),k.onreadystatechange=null,f.removeChild(k),k=null},f.appendChild(k)}):l=function(h){setTimeout(m,0,h)},u.setImmediate=function(h){typeof h!="function"&&(h=new Function(""+h));for(var k=new Array(arguments.length-1),E=0;E<k.length;E++)k[E]=arguments[E+1];var T={callback:h,args:k};return t[b]=T,l(b),b++},u.clearImmediate=g}function g(h){delete t[h]}function m(h){if(n)setTimeout(m,0,h);else{var k=t[h];if(k){n=!0;try{(function(E){var T=E.callback,j=E.args;switch(j.length){case 0:T();break;case 1:T(j[0]);break;case 2:T(j[0],j[1]);break;case 3:T(j[0],j[1],j[2]);break;default:T.apply(v,j)}})(k)}finally{g(h),n=!1}}}}})(typeof self>"u"?e===void 0?this:e:self)}).call(this,r(0),r(7))},function(a,s){var r,e,o=a.exports={};function d(){throw new Error("setTimeout has not been defined")}function v(){throw new Error("clearTimeout has not been defined")}function l(u){if(r===setTimeout)return setTimeout(u,0);if((r===d||!r)&&setTimeout)return r=setTimeout,setTimeout(u,0);try{return r(u,0)}catch{try{return r.call(null,u,0)}catch{return r.call(this,u,0)}}}(function(){try{r=typeof setTimeout=="function"?setTimeout:d}catch{r=d}try{e=typeof clearTimeout=="function"?clearTimeout:v}catch{e=v}})();var f,p=[],y=!1,w=-1;function b(){y&&f&&(y=!1,f.length?p=f.concat(p):w=-1,p.length&&t())}function t(){if(!y){var u=l(b);y=!0;for(var g=p.length;g;){for(f=p,p=[];++w<g;)f&&f[w].run();w=-1,g=p.length}f=null,y=!1,function(m){if(e===clearTimeout)return clearTimeout(m);if((e===v||!e)&&clearTimeout)return e=clearTimeout,clearTimeout(m);try{e(m)}catch{try{return e.call(null,m)}catch{return e.call(this,m)}}}(u)}}function n(u,g){this.fun=u,this.array=g}function c(){}o.nextTick=function(u){var g=new Array(arguments.length-1);if(arguments.length>1)for(var m=1;m<arguments.length;m++)g[m-1]=arguments[m];p.push(new n(u,g)),p.length!==1||y||l(t)},n.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=c,o.addListener=c,o.once=c,o.off=c,o.removeListener=c,o.removeAllListeners=c,o.emit=c,o.prependListener=c,o.prependOnceListener=c,o.listeners=function(u){return[]},o.binding=function(u){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(u){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(a,s,r){function e(d,v){for(var l=0;l<v.length;l++){var f=v[l];f.enumerable=f.enumerable||!1,f.configurable=!0,"value"in f&&(f.writable=!0),Object.defineProperty(d,f.key,f)}}var o=r(9);a.exports=function(){function d(){(function(p,y){if(!(p instanceof y))throw new TypeError("Cannot call a class as a function")})(this,d)}var v,l,f;return v=d,f=[{key:"urlEncode",value:function(p){return o(p)}},{key:"jsonEncode",value:function(p){return JSON.stringify(p)}},{key:"formEncode",value:function(p){if(this.isFormData(p))return p;if(this.isFormElement(p))return new FormData(p);if(this.isObject(p)){var y=new FormData;return Object.keys(p).forEach(function(w){var b=p[w];y.append(w,b)}),y}throw new Error("`data` must be an instance of Object, FormData or <FORM> HTMLElement")}},{key:"isObject",value:function(p){return Object.prototype.toString.call(p)==="[object Object]"}},{key:"isFormData",value:function(p){return p instanceof FormData}},{key:"isFormElement",value:function(p){return p instanceof HTMLFormElement}},{key:"selectFiles",value:function(){var p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return new Promise(function(y,w){var b=document.createElement("INPUT");b.type="file",p.multiple&&b.setAttribute("multiple","multiple"),p.accept&&b.setAttribute("accept",p.accept),b.style.display="none",document.body.appendChild(b),b.addEventListener("change",function(t){var n=t.target.files;y(n),document.body.removeChild(b)},!1),b.click()})}},{key:"parseHeaders",value:function(p){var y=p.trim().split(/[\r\n]+/),w={};return y.forEach(function(b){var t=b.split(": "),n=t.shift(),c=t.join(": ");n&&(w[n]=c)}),w}}],(l=null)&&e(v.prototype,l),f&&e(v,f),d}()},function(a,s){var r=function(o){return encodeURIComponent(o).replace(/[!'()*]/g,escape).replace(/%20/g,"+")},e=function(o,d,v,l){return d=d||null,v=v||"&",l=l||null,o?function(f){for(var p=new Array,y=0;y<f.length;y++)f[y]&&p.push(f[y]);return p}(Object.keys(o).map(function(f){var p,y,w=f;if(l&&(w=l+"["+w+"]"),typeof o[f]=="object"&&o[f]!==null)p=e(o[f],null,v,w);else{d&&(y=w,w=!isNaN(parseFloat(y))&&isFinite(y)?d+Number(w):w);var b=o[f];b=(b=(b=(b=b===!0?"1":b)===!1?"0":b)===0?"0":b)||"",p=r(w)+"="+r(b)}return p})).join(v).replace(/[!'()*]/g,""):""};a.exports=e}])})})(I);var q=I.exports;const _=D(q);function L(C){return C!==void 0&&typeof C.then=="function"}class A{constructor({config:i,onUpload:a,onError:s}){this.config=i,this.onUpload=a,this.onError=s}uploadSelectedFile({onPreview:i}){const a=function(r){const e=new FileReader;e.readAsDataURL(r),e.onload=o=>{i(o.target.result)}};let s;if(this.config.uploader&&typeof this.config.uploader.uploadByFile=="function"){const r=this.config.uploader.uploadByFile;s=_.selectFiles({accept:this.config.types??"image/*"}).then(e=>{a(e[0]);const o=r(e[0]);return L(o)||console.warn("Custom uploader method uploadByFile should return a Promise"),o})}else s=_.transport({url:this.config.endpoints.byFile,data:this.config.additionalRequestData,accept:this.config.types??"image/*",headers:this.config.additionalRequestHeaders,beforeSend:r=>{a(r[0])},fieldName:this.config.field??"image"}).then(r=>r.body);s.then(r=>{this.onUpload(r)}).catch(r=>{this.onError(r)})}uploadByUrl(i){let a;this.config.uploader&&typeof this.config.uploader.uploadByUrl=="function"?(a=this.config.uploader.uploadByUrl(i),L(a)||console.warn("Custom uploader method uploadByUrl should return a Promise")):a=_.post({url:this.config.endpoints.byUrl,data:Object.assign({url:i},this.config.additionalRequestData),type:_.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(s=>s.body),a.then(s=>{this.onUpload(s)}).catch(s=>{this.onError(s)})}uploadByFile(i,{onPreview:a}){const s=new FileReader;s.readAsDataURL(i),s.onload=e=>{a(e.target.result)};let r;if(this.config.uploader&&typeof this.config.uploader.uploadByFile=="function")r=this.config.uploader.uploadByFile(i),L(r)||console.warn("Custom uploader method uploadByFile should return a Promise");else{const e=new FormData;e.append(this.config.field??"image",i),this.config.additionalRequestData&&Object.keys(this.config.additionalRequestData).length&&Object.entries(this.config.additionalRequestData).forEach(([o,d])=>{e.append(o,d)}),r=_.post({url:this.config.endpoints.byFile,data:e,type:_.contentType.JSON,headers:this.config.additionalRequestHeaders}).then(o=>o.body)}r.then(e=>{this.onUpload(e)}).catch(e=>{this.onError(e)})}}/** | ||
* Image Tool for the Editor.js | ||
@@ -13,3 +13,2 @@ * @author CodeX <team@codex.so> | ||
* 3) ui.ts — module for UI manipulations: render, showing preloader, etc | ||
* 4) tunes.js — working with Block Tunes: render buttons, handle clicks | ||
* | ||
@@ -32,2 +31,2 @@ * For debug purposes there is a testing server | ||
* }, | ||
*/class P{constructor({data:a,config:r,api:c,readOnly:i,block:o}){this.api=c,this.readOnly=i,this.block=o,this.config={endpoints:r.endpoints,additionalRequestData:r.additionalRequestData,additionalRequestHeaders:r.additionalRequestHeaders,field:r.field,types:r.types,captionPlaceholder:this.api.i18n.t(r.captionPlaceholder??"Caption"),buttonContent:r.buttonContent,uploader:r.uploader,actions:r.actions},this.uploader=new q({config:this.config,onUpload:n=>this.onUpload(n),onError:n=>this.uploadingFailed(n)}),this.ui=new U({api:c,config:this.config,onSelectFile:()=>{this.uploader.uploadSelectedFile({onPreview:n=>{this.ui.showPreloader(n)}})},readOnly:i}),this._data={caption:"",withBorder:!1,withBackground:!1,stretched:!1,file:{url:""}},this.data=a}static get isReadOnlySupported(){return!0}static get toolbox(){return{icon:H,title:"Image"}}static get tunes(){return[{name:"withBorder",icon:M,title:"With border",toggle:!0},{name:"stretched",icon:x,title:"Stretch image",toggle:!0},{name:"withBackground",icon:F,title:"With background",toggle:!0}]}render(){return this.ui.render(this.data)}validate(a){return!!a.file.url}save(){const a=this.ui.nodes.caption;return this._data.caption=a.innerHTML,this.data}renderSettings(){return P.tunes.concat(this.config.actions||[]).map(r=>({icon:r.icon,label:this.api.i18n.t(r.title),name:r.name,toggle:r.toggle,isActive:this.data[r.name],onActivate:()=>{if(typeof r.action=="function"){r.action(r.name);return}this.tuneToggled(r.name)}}))}appendCallback(){this.ui.nodes.fileButton.click()}static get pasteConfig(){return{tags:[{img:{src:!0}}],patterns:{image:/https?:\/\/\S+\.(gif|jpe?g|tiff|png|svg|webp)(\?[a-z0-9=]*)?$/i},files:{mimeTypes:["image/*"]}}}async onPaste(a){switch(a.type){case"tag":{const r=a.detail.data;if(/^blob:/.test(r.src)){const i=await(await fetch(r.src)).blob();this.uploadFile(i);break}this.uploadUrl(r.src);break}case"pattern":{const r=a.detail.data;this.uploadUrl(r);break}case"file":{const r=a.detail.file;this.uploadFile(r);break}}}set data(a){this.image=a.file,this._data.caption=a.caption||"",this.ui.fillCaption(this._data.caption),P.tunes.forEach(({name:r})=>{const c=typeof a[r]<"u"?a[r]===!0||a[r]==="true":!1;this.setTune(r,c)})}get data(){return this._data}set image(a){this._data.file=a||{url:""},a&&a.url&&this.ui.fillImage(a.url)}onUpload(a){a.success&&a.file?this.image=a.file:this.uploadingFailed("incorrect response: "+JSON.stringify(a))}uploadingFailed(a){console.log("Image Tool: uploading failed because of",a),this.api.notifier.show({message:this.api.i18n.t("Couldn’t upload image. Please try another."),style:"error"}),this.ui.hidePreloader()}tuneToggled(a){this.setTune(a,!this._data[a])}setTune(a,r){this._data[a]=r,this.ui.applyTune(a,r),a==="stretched"&&Promise.resolve().then(()=>{this.block.stretched=r}).catch(c=>{console.error(c)})}uploadFile(a){this.uploader.uploadByFile(a,{onPreview:r=>{this.ui.showPreloader(r)}})}uploadUrl(a){this.ui.showPreloader(a),this.uploader.uploadByUrl(a)}}return P}); | ||
*/class P{constructor({data:i,config:a,api:s,readOnly:r,block:e}){this.api=s,this.block=e,this.config={endpoints:a.endpoints,additionalRequestData:a.additionalRequestData,additionalRequestHeaders:a.additionalRequestHeaders,field:a.field,types:a.types,captionPlaceholder:this.api.i18n.t(a.captionPlaceholder??"Caption"),buttonContent:a.buttonContent,uploader:a.uploader,actions:a.actions,features:a.features||{}},this.uploader=new A({config:this.config,onUpload:o=>this.onUpload(o),onError:o=>this.uploadingFailed(o)}),this.ui=new U({api:s,config:this.config,onSelectFile:()=>{this.uploader.uploadSelectedFile({onPreview:o=>{this.ui.showPreloader(o)}})},readOnly:r}),this._data={caption:"",withBorder:!1,withBackground:!1,stretched:!1,file:{url:""}},this.data=i}static get isReadOnlySupported(){return!0}static get toolbox(){return{icon:R,title:"Image"}}static get tunes(){return[{name:"withBorder",icon:F,title:"With border",toggle:!0},{name:"stretched",icon:x,title:"Stretch image",toggle:!0},{name:"withBackground",icon:S,title:"With background",toggle:!0}]}render(){var i,a,s;return(((i=this.config.features)==null?void 0:i.caption)===!0||((a=this.config.features)==null?void 0:a.caption)===void 0||((s=this.config.features)==null?void 0:s.caption)==="optional"&&this.data.caption)&&this.ui.applyTune("caption",!0),this.ui.render(this.data)}validate(i){return!!i.file.url}save(){const i=this.ui.nodes.caption;return this._data.caption=i.innerHTML,this.data}renderSettings(){var r;const i=P.tunes.concat(this.config.actions||[]),a={border:"withBorder",background:"withBackground",stretch:"stretched",caption:"caption"};return((r=this.config.features)==null?void 0:r.caption)==="optional"&&i.push({name:"caption",icon:B,title:"With caption",toggle:!0}),i.filter(e=>{var d,v;const o=Object.keys(a).find(l=>a[l]===e.name);return o==="caption"?((d=this.config.features)==null?void 0:d.caption)!==!1:o==null||((v=this.config.features)==null?void 0:v[o])!==!1}).map(e=>({icon:e.icon,label:this.api.i18n.t(e.title),name:e.name,toggle:e.toggle,isActive:this.data[e.name],onActivate:()=>{if(typeof e.action=="function"){e.action(e.name);return}this.tuneToggled(e.name)}}))}appendCallback(){this.ui.nodes.fileButton.click()}static get pasteConfig(){return{tags:[{img:{src:!0}}],patterns:{image:/https?:\/\/\S+\.(gif|jpe?g|tiff|png|svg|webp)(\?[a-z0-9=]*)?$/i},files:{mimeTypes:["image/*"]}}}async onPaste(i){switch(i.type){case"tag":{const a=i.detail.data;if(/^blob:/.test(a.src)){const r=await(await fetch(a.src)).blob();this.uploadFile(r);break}this.uploadUrl(a.src);break}case"pattern":{const a=i.detail.data;this.uploadUrl(a);break}case"file":{const a=i.detail.file;this.uploadFile(a);break}}}set data(i){this.image=i.file,this._data.caption=i.caption||"",this.ui.fillCaption(this._data.caption),P.tunes.forEach(({name:a})=>{const s=typeof i[a]<"u"?i[a]===!0||i[a]==="true":!1;this.setTune(a,s)})}get data(){return this._data}set image(i){this._data.file=i||{url:""},i&&i.url&&this.ui.fillImage(i.url)}onUpload(i){i.success&&i.file?this.image=i.file:this.uploadingFailed("incorrect response: "+JSON.stringify(i))}uploadingFailed(i){console.log("Image Tool: uploading failed because of",i),this.api.notifier.show({message:this.api.i18n.t("Couldn’t upload image. Please try another."),style:"error"}),this.ui.hidePreloader()}tuneToggled(i){this.setTune(i,!this._data[i]),i==="caption"&&!this._data[i]&&(this._data.caption="",this.ui.fillCaption(""))}setTune(i,a){this._data[i]=a,this.ui.applyTune(i,a),i==="stretched"&&Promise.resolve().then(()=>{this.block.stretched=a}).catch(s=>{console.error(s)})}uploadFile(i){this.uploader.uploadByFile(i,{onPreview:a=>{this.ui.showPreloader(a)}})}uploadUrl(i){this.ui.showPreloader(i),this.uploader.uploadByUrl(i)}}return P}); |
@@ -15,6 +15,2 @@ import { TunesMenuConfig } from '@editorjs/editorjs/types/tools'; | ||
/** | ||
* Flag indicating read-only mode | ||
*/ | ||
private readOnly; | ||
/** | ||
* Current Block API instance | ||
@@ -21,0 +17,0 @@ */ |
@@ -91,2 +91,24 @@ import { HTMLPasteEventDetail } from '@editorjs/editorjs'; | ||
/** | ||
* @description Allows to enable or disable features. | ||
*/ | ||
export type FeaturesConfig = { | ||
/** | ||
* Flag to enable/disable tune - background. | ||
*/ | ||
background?: boolean; | ||
/** | ||
* Flag to enable/disable tune - border. | ||
*/ | ||
border?: boolean; | ||
/** | ||
* Flag to enable/disable caption. | ||
* Can be set to 'optional' to allow users to toggle via block tunes. | ||
*/ | ||
caption?: boolean | 'optional'; | ||
/** | ||
* Flag to enable/disable tune - stretched | ||
*/ | ||
stretch?: boolean; | ||
}; | ||
/** | ||
* | ||
@@ -150,2 +172,6 @@ * @description Config supported by Tool | ||
actions?: ActionConfig[]; | ||
/** | ||
* Tunes to be enabled. | ||
*/ | ||
features?: FeaturesConfig; | ||
} | ||
@@ -152,0 +178,0 @@ /** |
{ | ||
"name": "@editorjs/image", | ||
"version": "2.9.3", | ||
"version": "2.10.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "codex editor", |
@@ -15,3 +15,3 @@  | ||
- Pasting files and screenshots from Clipboard | ||
- Allows adding a border, and a background | ||
- Allows adding a border, a background and a caption | ||
- Allows stretching an image to the container's full-width | ||
@@ -87,2 +87,3 @@ | ||
| actions | `array` | Array with custom actions to show in the tool's settings menu. See details below. | | ||
| features | `object` | Allows you to enable/disable additional features such as border, background tunes and caption. See details below. | | ||
@@ -101,2 +102,4 @@ Note that if you don't implement your custom uploader methods, the `endpoints` param is required. | ||
4. Add caption | ||
Add extra setting-buttons by adding them to the `actions`-array in the configuration: | ||
@@ -119,2 +122,13 @@ ```js | ||
You can disable features such as border, background tunes and caption by defining `features` in the configuration: | ||
```js | ||
features: { | ||
border: false, | ||
caption: 'optional', | ||
stretch: false | ||
} | ||
``` | ||
**_NOTE:_** set caption to `optional` in order to configure caption as a tune. | ||
## Output data | ||
@@ -143,3 +157,3 @@ | ||
"withBackground" : false, | ||
"stretched" : true | ||
"stretched" : true, | ||
} | ||
@@ -146,0 +160,0 @@ } |
Sorry, the diff of this file is not supported yet
103472
1809
298