quill-image-compress 1.2.17 → 1.2.18
Sign up to get free protection for your applications and to get access to all the features.
package/dist/demo.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("Quill"));else if("function"==typeof define&&define.amd)define(["Quill"],t);else{var r="object"==typeof exports?t(require("Quill")):t(e.Quill);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=16)}([function(e,t,r){e.exports=r(7)},function(e,t){function r(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function u(e){r(a,o,i,u,s,"next",e)}function s(e){r(a,o,i,u,s,"throw",e)}u(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"file2b64",(function(){return u}));var n=r(1),o=r.n(n),i=r(0),a=r.n(i);function u(e){return s.apply(this,arguments)}function s(){return(s=o()(a.a.mark((function e(t){var r,n;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new FileReader,n=new Promise((function(e){r.addEventListener("load",(function(){var t=r.result;e(t)}),!1)})),r.readAsDataURL(t),e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}},function(e,t,r){var n=r(10),o=r(11),i=r(12),a=r(14);e.exports=function(e,t){return n(e)||o(e,t)||i(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"imageCompressor",(function(){return y}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l);var f=!0,p=!1,h={prefixString:function(){return"</> quill-image-compress: "},get log(){return f?console.log.bind(console,this.prefixString()):function(){}},get error(){return p?function(){}:console.error.bind(console,this.prefixString())},get warn(){return p?function(){}:console.warn.bind(console,this.prefixString())}},d=r(8).ImageDrop,g=r(4).file2b64,m=r(9).downscaleImage,y=function(){function e(t,r){var n=this;a()(this,e),this.quill=t,this.range=null,this.options=r,f=r&&r.debug,p=r&&r.suppressErrorLogging;var i=function(){var e=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return h.log("onImageDrop",{dataUrl:t}),e.next=3,n.downscaleImageFromUrl(t);case 3:r=e.sent,n.insertToEditor(r);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();this.imageDrop=new d(t,i,h),function(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(h.warn("[config error] 'maxWidth' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxWidth,"\n-> using default 1000")),e.maxWidth=1e3),e.maxHeight&&"number"!=typeof e.maxHeight&&(h.warn("[config error] 'maxHeight' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxHeight,"\n-> using default 1000")),e.maxHeight=1e3),e.quality&&"number"!=typeof e.quality&&(h.warn("quill.imageCompressor: [config error] 'quality' is required to be a \"number\", \nreceived: ".concat(e.quality,"\n-> using default 0.7")),e.quality=.7),!e.imageType||"string"==typeof e.imageType&&e.imageType.startsWith("image/")||(h.warn('quill.imageCompressor: [config error] \'imageType\' is required be in the form of "image/png" or "image/jpeg" etc ..., \nreceived: '.concat(e.imageType,"\n-> using default image/jpeg")),e.imageType="image/jpeg"),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}(r),h.log("fileChanged",{options:r,quill:t,debug:f});var u=this.quill.getModule("toolbar");u?u.addHandler("image",(function(){return n.selectLocalImage()})):h.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}var t,r;return s()(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=function(){return e.fileChanged()},document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:(r=o()(c.a.mark((function e(){var t,r,n;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.fileHolder.files[0],h.log("fileChanged",{file:t}),t){e.next=4;break}return e.abrupt("return");case 4:return e.next=6,g(t);case 6:return r=e.sent,e.next=9,this.downscaleImageFromUrl(r);case 9:n=e.sent,this.insertToEditor(n);case 11:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"downscaleImageFromUrl",value:(t=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(t,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,h);case 2:return r=e.sent,h.log("downscaleImageFromUrl",{dataUrl:t,dataUrlCompressed:r}),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"insertToEditor",value:function(e){h.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var t=this.range;this.logFileSize(e),this.quill.insertEmbed(t.index,"image","".concat(e),"user"),t.index++,this.quill.setSelection(t,"api")}},{key:"logFileSize",value:function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);h.log("estimated img size: "+t+" kb")}}]),e}();window.imageCompressor=y,t.default=y},function(e,t,r){var n=function(e){"use strict";var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof f?t:f,i=Object.create(o.prototype),a=new I(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===c)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===c)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,a),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var c={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==t&&r.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function v(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var s=l(e[o],e,i);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(s.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function I(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function _(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},v(x.prototype),u(x.prototype,i,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},v(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=_,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:_(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(e,t,r){"use strict";r.r(t),r.d(t,"ImageDrop",(function(){return p}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l),f=r(4).file2b64,p=function(){function e(t,r,n){var o=this;a()(this,e),this.logger=n,this.quill=t,this.onNewDataUrl=r,this.quill.root.addEventListener("drop",(function(e){return o.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return o.handlePaste(e)}),!1)}var t;return s()(e,[{key:"handleNewImageFiles",value:(t=o()(c.a.mark((function e(t){var r,n,o;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Array.isArray(t)){e.next=2;break}return e.abrupt("return");case 2:if(r=t.pop()){e.next=5;break}return e.abrupt("return");case 5:return n=r.getAsFile?r.getAsFile():r,e.next=8,f(n);case 8:o=e.sent,this.logger.log("handlePaste",{base64ImageSrc:o}),this.onNewDataUrl(o);case 11:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"handleDrop",value:function(e){e.preventDefault();var t=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length;if(this.logger.log("handleDrop",{hasFiles:t}),t){if(document.caretRangeFromPoint){var r=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY);r&&n&&r.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)}var o=this.getImageFiles(e.dataTransfer.files);this.handleNewImageFiles(o)}}},{key:"handlePaste",value:function(e){var t=e.clipboardData&&e.clipboardData.items&&!!e.clipboardData.items.length;if(this.logger.log("handlePaste",{hasItems:t}),t){var r=this.getImageFiles(e.clipboardData.items);0!==r.length&&(Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))?this.logger.log("detected html, not handling"):(e.preventDefault(),this.handleNewImageFiles(r)))}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("readFiles",{files:t}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)}))||[]}}]),e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"downscaleImage",(function(){return l}));var n=r(5),o=r.n(n),i=r(1),a=r.n(i),u=r(0),s=r.n(u);function l(e,t,r,n,o,i,a,u){return c.apply(this,arguments)}function c(){return(c=a()(s.a.mark((function e(t,r,n,i,a,u,l,c){var p,h,d,g,m,y,v,x,b;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return p=t.split(";")[0].split(":")[1],i=i||"image/jpeg",l=l||.7,(h=new Image).src=t,e.next=7,new Promise((function(e){h.onload=function(){e()}}));case 7:if(d=f(h.width,h.height,r,n),g=o()(d,2),m=g[0],y=g[1],(v=document.createElement("canvas")).width=m,v.height=y,x=v.getContext("2d"),!u.includes(p)){e.next=14;break}return e.abrupt("return",t);case 14:return a.includes(p)&&(i=p),x.drawImage(h,0,0,m,y),b=v.toDataURL(i,l),c.log("downscaling image...",{args:{dataUrl:t,maxWidth:r,maxHeight:n,imageType:i,ignoreImageTypes:u,keepImageTypes:a,imageQuality:l},newHeight:y,newWidth:m}),e.abrupt("return",b);case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(e,t,r,n){if(e<=r&&t<=n)return[e,t];if(e>r){var o=r,i=Math.floor(t/e*o);if(i>n){var a=n;return[Math.floor(e/t*a),a]}return[o,i]}if(t>n){var u=n;return[Math.floor(e/t*u),u]}}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){var n=r(13);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t);var n=r(15),o=r.n(n),i=r(6);o.a.register("modules/imageCompressor",i.default);console.log("Demo loaded...");new o.a("#editor",{theme:"snow",modules:{toolbar:{container:[[{header:[1,2,3,!1]}],["bold","italic"],["clean"],["image"]]},imageCompressor:{quality:.9,maxWidth:200,maxHeight:200,imageType:"image/png",debug:!0}}})}])}));
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("Quill"));else if("function"==typeof define&&define.amd)define(["Quill"],t);else{var r="object"==typeof exports?t(require("Quill")):t(e.Quill);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(e){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=16)}([function(e,t,r){e.exports=r(7)},function(e,t){function r(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function u(e){r(a,o,i,u,s,"next",e)}function s(e){r(a,o,i,u,s,"throw",e)}u(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"file2b64",(function(){return u}));var n=r(1),o=r.n(n),i=r(0),a=r.n(i);function u(e){return s.apply(this,arguments)}function s(){return(s=o()(a.a.mark((function e(t){var r,n;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new FileReader,n=new Promise((function(e){r.addEventListener("load",(function(){var t=r.result;e(t)}),!1)})),r.readAsDataURL(t),e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}},function(e,t,r){var n=r(10),o=r(11),i=r(12),a=r(14);e.exports=function(e,t){return n(e)||o(e,t)||i(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"imageCompressor",(function(){return y}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l);var f=!0,p=!1,h={prefixString:function(){return"</> quill-image-compress: "},get log(){return f?console.log.bind(console,this.prefixString()):function(){}},get error(){return p?function(){}:console.error.bind(console,this.prefixString())},get warn(){return p?function(){}:console.warn.bind(console,this.prefixString())}},d=r(8).ImageDrop,g=r(4).file2b64,m=r(9).downscaleImage,y=function(){function e(t,r){var n=this;a()(this,e),this.quill=t,this.range=null,this.options=r,f=r&&r.debug,p=r&&r.suppressErrorLogging;var i=function(){var e=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return h.log("onImageDrop",{dataUrl:t}),e.next=3,n.downscaleImageFromUrl(t);case 3:r=e.sent,n.insertToEditor(r);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();this.imageDrop=new d(t,i,h),function(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(h.warn("[config error] 'maxWidth' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxWidth,"\n-> using default 1000")),e.maxWidth=1e3),e.maxHeight&&"number"!=typeof e.maxHeight&&(h.warn("[config error] 'maxHeight' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxHeight,"\n-> using default 1000")),e.maxHeight=1e3),e.quality&&"number"!=typeof e.quality&&(h.warn("quill.imageCompressor: [config error] 'quality' is required to be a \"number\", \nreceived: ".concat(e.quality,"\n-> using default 0.7")),e.quality=.7),!e.imageType||"string"==typeof e.imageType&&e.imageType.startsWith("image/")||(h.warn('quill.imageCompressor: [config error] \'imageType\' is required be in the form of "image/png" or "image/jpeg" etc ..., \nreceived: '.concat(e.imageType,"\n-> using default image/jpeg")),e.imageType="image/jpeg"),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}(r),h.log("fileChanged",{options:r,quill:t,debug:f});var u=this.quill.getModule("toolbar");u?u.addHandler("image",(function(){return n.selectLocalImage()})):h.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}var t,r;return s()(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=function(){return e.fileChanged()},document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:(r=o()(c.a.mark((function e(){var t,r,n;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.fileHolder.files[0],h.log("fileChanged",{file:t}),t){e.next=4;break}return e.abrupt("return");case 4:return e.next=6,g(t);case 6:return r=e.sent,e.next=9,this.downscaleImageFromUrl(r);case 9:n=e.sent,this.insertToEditor(n);case 11:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"downscaleImageFromUrl",value:(t=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(t,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,h);case 2:return r=e.sent,h.log("downscaleImageFromUrl",{dataUrl:t,dataUrlCompressed:r}),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"insertToEditor",value:function(e){h.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var t=this.range;this.logFileSize(e),this.quill.insertEmbed(t.index,"image","".concat(e),"user"),t.index++,this.quill.setSelection(t,"api")}},{key:"logFileSize",value:function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);h.log("estimated img size: "+t+" kb")}}]),e}();window.imageCompressor=y,t.default=y},function(e,t,r){var n=function(e){"use strict";var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof f?t:f,i=Object.create(o.prototype),a=new I(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===c)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===c)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,a),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var c={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==t&&r.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function v(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var s=l(e[o],e,i);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(s.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function I(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function _(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},v(x.prototype),u(x.prototype,i,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},v(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=_,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:_(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(e,t,r){"use strict";r.r(t),r.d(t,"ImageDrop",(function(){return p}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l),f=r(4).file2b64,p=function(){function e(t,r,n){var o=this;a()(this,e),this.logger=n,this.quill=t,this.onNewDataUrl=r,this.quill.root.addEventListener("drop",(function(e){return o.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return o.handlePaste(e)}),!1)}var t;return s()(e,[{key:"handleNewImageFiles",value:(t=o()(c.a.mark((function e(t){var r,n,o;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Array.isArray(t)){e.next=2;break}return e.abrupt("return");case 2:if(r=t.pop()){e.next=5;break}return e.abrupt("return");case 5:return n=r.getAsFile?r.getAsFile():r,e.next=8,f(n);case 8:o=e.sent,this.logger.log("handlePaste",{base64ImageSrc:o}),this.onNewDataUrl(o);case 11:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"handleDrop",value:function(e){e.preventDefault();var t=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length;if(this.logger.log("handleDrop",{hasFiles:t}),t){if(document.caretRangeFromPoint){var r=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY);r&&n&&r.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)}var o=this.getImageFiles(e.dataTransfer.files);this.handleNewImageFiles(o)}}},{key:"handlePaste",value:function(e){var t=e.clipboardData&&e.clipboardData.items&&!!e.clipboardData.items.length;if(this.logger.log("handlePaste",{hasItems:t}),t){var r=this.getImageFiles(e.clipboardData.items);0!==r.length&&(Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))?this.logger.log("detected html, not handling"):(e.preventDefault(),this.handleNewImageFiles(r)))}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("readFiles",{files:t}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)}))||[]}}]),e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"downscaleImage",(function(){return l}));var n=r(5),o=r.n(n),i=r(1),a=r.n(i),u=r(0),s=r.n(u);function l(e,t,r,n,o,i,a,u){return c.apply(this,arguments)}function c(){return(c=a()(s.a.mark((function e(t,r,n,i,a,u,l,c){var p,h,d,g,m,y,v,x,b;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return p=t.split(";")[0].split(":")[1],i=i||"image/jpeg",l=l||.7,(h=new Image).src=t,e.next=7,new Promise((function(e){h.onload=function(){e()}}));case 7:if(d=f(h.width,h.height,r,n),g=o()(d,2),m=g[0],y=g[1],(v=document.createElement("canvas")).width=m,v.height=y,x=v.getContext("2d"),"image/jpeg"===i&&(x.fillStyle="#FFFFFF",x.fillRect(0,0,h.width,h.height)),!u.includes(p)){e.next=15;break}return e.abrupt("return",t);case 15:return a.includes(p)&&(i=p),x.drawImage(h,0,0,m,y),b=v.toDataURL(i,l),c.log("downscaling image...",{args:{dataUrl:t,maxWidth:r,maxHeight:n,imageType:i,ignoreImageTypes:u,keepImageTypes:a,imageQuality:l},newHeight:y,newWidth:m}),e.abrupt("return",b);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(e,t,r,n){if(e<=r&&t<=n)return[e,t];if(e>r){var o=r,i=Math.floor(t/e*o);if(i>n){var a=n;return[Math.floor(e/t*a),a]}return[o,i]}if(t>n){var u=n;return[Math.floor(e/t*u),u]}}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){var n=r(13);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t);var n=r(15),o=r.n(n),i=r(6);o.a.register("modules/imageCompressor",i.default);console.log("Demo loaded...");new o.a("#editor",{theme:"snow",modules:{toolbar:{container:[[{header:[1,2,3,!1]}],["bold","italic"],["clean"],["image"]]},imageCompressor:{quality:.9,maxWidth:200,maxHeight:200,imageType:"image/png",debug:!0}}})}])}));
|
@@ -1 +1 @@
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=6)}([function(e,t,r){e.exports=r(7)},function(e,t){function r(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function u(e){r(a,o,i,u,s,"next",e)}function s(e){r(a,o,i,u,s,"throw",e)}u(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"file2b64",(function(){return u}));var n=r(1),o=r.n(n),i=r(0),a=r.n(i);function u(e){return s.apply(this,arguments)}function s(){return(s=o()(a.a.mark((function e(t){var r,n;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new FileReader,n=new Promise((function(e){r.addEventListener("load",(function(){var t=r.result;e(t)}),!1)})),r.readAsDataURL(t),e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}},function(e,t,r){var n=r(10),o=r(11),i=r(12),a=r(14);e.exports=function(e,t){return n(e)||o(e,t)||i(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"imageCompressor",(function(){return y}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l);var f=!0,p=!1,h={prefixString:function(){return"</> quill-image-compress: "},get log(){return f?console.log.bind(console,this.prefixString()):function(){}},get error(){return p?function(){}:console.error.bind(console,this.prefixString())},get warn(){return p?function(){}:console.warn.bind(console,this.prefixString())}},d=r(8).ImageDrop,g=r(4).file2b64,m=r(9).downscaleImage,y=function(){function e(t,r){var n=this;a()(this,e),this.quill=t,this.range=null,this.options=r,f=r&&r.debug,p=r&&r.suppressErrorLogging;var i=function(){var e=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return h.log("onImageDrop",{dataUrl:t}),e.next=3,n.downscaleImageFromUrl(t);case 3:r=e.sent,n.insertToEditor(r);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();this.imageDrop=new d(t,i,h),function(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(h.warn("[config error] 'maxWidth' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxWidth,"\n-> using default 1000")),e.maxWidth=1e3),e.maxHeight&&"number"!=typeof e.maxHeight&&(h.warn("[config error] 'maxHeight' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxHeight,"\n-> using default 1000")),e.maxHeight=1e3),e.quality&&"number"!=typeof e.quality&&(h.warn("quill.imageCompressor: [config error] 'quality' is required to be a \"number\", \nreceived: ".concat(e.quality,"\n-> using default 0.7")),e.quality=.7),!e.imageType||"string"==typeof e.imageType&&e.imageType.startsWith("image/")||(h.warn('quill.imageCompressor: [config error] \'imageType\' is required be in the form of "image/png" or "image/jpeg" etc ..., \nreceived: '.concat(e.imageType,"\n-> using default image/jpeg")),e.imageType="image/jpeg"),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}(r),h.log("fileChanged",{options:r,quill:t,debug:f});var u=this.quill.getModule("toolbar");u?u.addHandler("image",(function(){return n.selectLocalImage()})):h.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}var t,r;return s()(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=function(){return e.fileChanged()},document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:(r=o()(c.a.mark((function e(){var t,r,n;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.fileHolder.files[0],h.log("fileChanged",{file:t}),t){e.next=4;break}return e.abrupt("return");case 4:return e.next=6,g(t);case 6:return r=e.sent,e.next=9,this.downscaleImageFromUrl(r);case 9:n=e.sent,this.insertToEditor(n);case 11:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"downscaleImageFromUrl",value:(t=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(t,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,h);case 2:return r=e.sent,h.log("downscaleImageFromUrl",{dataUrl:t,dataUrlCompressed:r}),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"insertToEditor",value:function(e){h.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var t=this.range;this.logFileSize(e),this.quill.insertEmbed(t.index,"image","".concat(e),"user"),t.index++,this.quill.setSelection(t,"api")}},{key:"logFileSize",value:function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);h.log("estimated img size: "+t+" kb")}}]),e}();window.imageCompressor=y,t.default=y},function(e,t,r){var n=function(e){"use strict";var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof f?t:f,i=Object.create(o.prototype),a=new T(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===c)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===c)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,a),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var c={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==t&&r.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function v(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var s=l(e[o],e,i);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(s.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function _(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},v(x.prototype),u(x.prototype,i,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},v(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=_,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(I),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:_(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(e,t,r){"use strict";r.r(t),r.d(t,"ImageDrop",(function(){return p}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l),f=r(4).file2b64,p=function(){function e(t,r,n){var o=this;a()(this,e),this.logger=n,this.quill=t,this.onNewDataUrl=r,this.quill.root.addEventListener("drop",(function(e){return o.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return o.handlePaste(e)}),!1)}var t;return s()(e,[{key:"handleNewImageFiles",value:(t=o()(c.a.mark((function e(t){var r,n,o;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Array.isArray(t)){e.next=2;break}return e.abrupt("return");case 2:if(r=t.pop()){e.next=5;break}return e.abrupt("return");case 5:return n=r.getAsFile?r.getAsFile():r,e.next=8,f(n);case 8:o=e.sent,this.logger.log("handlePaste",{base64ImageSrc:o}),this.onNewDataUrl(o);case 11:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"handleDrop",value:function(e){e.preventDefault();var t=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length;if(this.logger.log("handleDrop",{hasFiles:t}),t){if(document.caretRangeFromPoint){var r=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY);r&&n&&r.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)}var o=this.getImageFiles(e.dataTransfer.files);this.handleNewImageFiles(o)}}},{key:"handlePaste",value:function(e){var t=e.clipboardData&&e.clipboardData.items&&!!e.clipboardData.items.length;if(this.logger.log("handlePaste",{hasItems:t}),t){var r=this.getImageFiles(e.clipboardData.items);0!==r.length&&(Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))?this.logger.log("detected html, not handling"):(e.preventDefault(),this.handleNewImageFiles(r)))}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("readFiles",{files:t}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)}))||[]}}]),e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"downscaleImage",(function(){return l}));var n=r(5),o=r.n(n),i=r(1),a=r.n(i),u=r(0),s=r.n(u);function l(e,t,r,n,o,i,a,u){return c.apply(this,arguments)}function c(){return(c=a()(s.a.mark((function e(t,r,n,i,a,u,l,c){var p,h,d,g,m,y,v,x,b;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return p=t.split(";")[0].split(":")[1],i=i||"image/jpeg",l=l||.7,(h=new Image).src=t,e.next=7,new Promise((function(e){h.onload=function(){e()}}));case 7:if(d=f(h.width,h.height,r,n),g=o()(d,2),m=g[0],y=g[1],(v=document.createElement("canvas")).width=m,v.height=y,x=v.getContext("2d"),!u.includes(p)){e.next=14;break}return e.abrupt("return",t);case 14:return a.includes(p)&&(i=p),x.drawImage(h,0,0,m,y),b=v.toDataURL(i,l),c.log("downscaling image...",{args:{dataUrl:t,maxWidth:r,maxHeight:n,imageType:i,ignoreImageTypes:u,keepImageTypes:a,imageQuality:l},newHeight:y,newWidth:m}),e.abrupt("return",b);case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(e,t,r,n){if(e<=r&&t<=n)return[e,t];if(e>r){var o=r,i=Math.floor(t/e*o);if(i>n){var a=n;return[Math.floor(e/t*a),a]}return[o,i]}if(t>n){var u=n;return[Math.floor(e/t*u),u]}}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){var n=r(13);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports}])}));
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(window,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="/dist/",r(r.s=6)}([function(e,t,r){e.exports=r(7)},function(e,t){function r(e,t,r,n,o,i,a){try{var u=e[i](a),s=u.value}catch(e){return void r(e)}u.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(o,i){var a=e.apply(t,n);function u(e){r(a,o,i,u,s,"next",e)}function s(e){r(a,o,i,u,s,"throw",e)}u(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.exports=function(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"file2b64",(function(){return u}));var n=r(1),o=r.n(n),i=r(0),a=r.n(i);function u(e){return s.apply(this,arguments)}function s(){return(s=o()(a.a.mark((function e(t){var r,n;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=new FileReader,n=new Promise((function(e){r.addEventListener("load",(function(){var t=r.result;e(t)}),!1)})),r.readAsDataURL(t),e.abrupt("return",n);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}},function(e,t,r){var n=r(10),o=r(11),i=r(12),a=r(14);e.exports=function(e,t){return n(e)||o(e,t)||i(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){"use strict";r.r(t),r.d(t,"imageCompressor",(function(){return y}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l);var f=!0,p=!1,h={prefixString:function(){return"</> quill-image-compress: "},get log(){return f?console.log.bind(console,this.prefixString()):function(){}},get error(){return p?function(){}:console.error.bind(console,this.prefixString())},get warn(){return p?function(){}:console.warn.bind(console,this.prefixString())}},d=r(8).ImageDrop,g=r(4).file2b64,m=r(9).downscaleImage,y=function(){function e(t,r){var n=this;a()(this,e),this.quill=t,this.range=null,this.options=r,f=r&&r.debug,p=r&&r.suppressErrorLogging;var i=function(){var e=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return h.log("onImageDrop",{dataUrl:t}),e.next=3,n.downscaleImageFromUrl(t);case 3:r=e.sent,n.insertToEditor(r);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();this.imageDrop=new d(t,i,h),function(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(h.warn("[config error] 'maxWidth' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxWidth,"\n-> using default 1000")),e.maxWidth=1e3),e.maxHeight&&"number"!=typeof e.maxHeight&&(h.warn("[config error] 'maxHeight' is required to be a \"number\" (in pixels), \nreceived: ".concat(e.maxHeight,"\n-> using default 1000")),e.maxHeight=1e3),e.quality&&"number"!=typeof e.quality&&(h.warn("quill.imageCompressor: [config error] 'quality' is required to be a \"number\", \nreceived: ".concat(e.quality,"\n-> using default 0.7")),e.quality=.7),!e.imageType||"string"==typeof e.imageType&&e.imageType.startsWith("image/")||(h.warn('quill.imageCompressor: [config error] \'imageType\' is required be in the form of "image/png" or "image/jpeg" etc ..., \nreceived: '.concat(e.imageType,"\n-> using default image/jpeg")),e.imageType="image/jpeg"),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(h.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}(r),h.log("fileChanged",{options:r,quill:t,debug:f});var u=this.quill.getModule("toolbar");u?u.addHandler("image",(function(){return n.selectLocalImage()})):h.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}var t,r;return s()(e,[{key:"selectLocalImage",value:function(){var e=this;this.range=this.quill.getSelection(),this.fileHolder=document.createElement("input"),this.fileHolder.setAttribute("type","file"),this.fileHolder.setAttribute("accept","image/*"),this.fileHolder.setAttribute("style","visibility:hidden"),this.fileHolder.onchange=function(){return e.fileChanged()},document.body.appendChild(this.fileHolder),this.fileHolder.click(),window.requestAnimationFrame((function(){document.body.removeChild(e.fileHolder)}))}},{key:"fileChanged",value:(r=o()(c.a.mark((function e(){var t,r,n;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.fileHolder.files[0],h.log("fileChanged",{file:t}),t){e.next=4;break}return e.abrupt("return");case 4:return e.next=6,g(t);case 6:return r=e.sent,e.next=9,this.downscaleImageFromUrl(r);case 9:n=e.sent,this.insertToEditor(n);case 11:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"downscaleImageFromUrl",value:(t=o()(c.a.mark((function e(t){var r;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,m(t,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,h);case 2:return r=e.sent,h.log("downscaleImageFromUrl",{dataUrl:t,dataUrlCompressed:r}),e.abrupt("return",r);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"insertToEditor",value:function(e){h.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var t=this.range;this.logFileSize(e),this.quill.insertEmbed(t.index,"image","".concat(e),"user"),t.index++,this.quill.setSelection(t,"api")}},{key:"logFileSize",value:function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);h.log("estimated img size: "+t+" kb")}}]),e}();window.imageCompressor=y,t.default=y},function(e,t,r){var n=function(e){"use strict";var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function s(e,t,r,n){var o=t&&t.prototype instanceof f?t:f,i=Object.create(o.prototype),a=new T(n||[]);return i._invoke=function(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=b(a,r);if(u){if(u===c)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(e,t,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===c)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(e,r,a),i}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=s;var c={};function f(){}function p(){}function h(){}var d={};u(d,o,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==t&&r.call(m,o)&&(d=m);var y=h.prototype=f.prototype=Object.create(d);function v(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function x(e,t){var n;this._invoke=function(o,i){function a(){return new t((function(n,a){!function n(o,i,a,u){var s=l(e[o],e,i);if("throw"!==s.type){var c=s.arg,f=c.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,a,u)}),(function(e){n("throw",e,a,u)})):t.resolve(f).then((function(e){c.value=e,a(c)}),(function(e){return n("throw",e,a,u)}))}u(s.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,b(e,t),"throw"===t.method))return c;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return c}var n=l(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,c;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,c):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,c)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function _(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=h,u(y,"constructor",h),u(h,"constructor",p),p.displayName=u(h,a,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,u(e,a,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},v(x.prototype),u(x.prototype,i,(function(){return this})),e.AsyncIterator=x,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new x(s(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},v(y),u(y,a,"Generator"),u(y,o,(function(){return this})),u(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=_,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(I),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=r.call(i,"catchLoc"),s=r.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=e,a.arg=t,i?(this.method="next",this.next=i.finallyLoc,c):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),c},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),I(r),c}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:_(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),c}},e}(e.exports);try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},function(e,t,r){"use strict";r.r(t),r.d(t,"ImageDrop",(function(){return p}));var n=r(1),o=r.n(n),i=r(2),a=r.n(i),u=r(3),s=r.n(u),l=r(0),c=r.n(l),f=r(4).file2b64,p=function(){function e(t,r,n){var o=this;a()(this,e),this.logger=n,this.quill=t,this.onNewDataUrl=r,this.quill.root.addEventListener("drop",(function(e){return o.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return o.handlePaste(e)}),!1)}var t;return s()(e,[{key:"handleNewImageFiles",value:(t=o()(c.a.mark((function e(t){var r,n,o;return c.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Array.isArray(t)){e.next=2;break}return e.abrupt("return");case 2:if(r=t.pop()){e.next=5;break}return e.abrupt("return");case 5:return n=r.getAsFile?r.getAsFile():r,e.next=8,f(n);case 8:o=e.sent,this.logger.log("handlePaste",{base64ImageSrc:o}),this.onNewDataUrl(o);case 11:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"handleDrop",value:function(e){e.preventDefault();var t=e.dataTransfer&&e.dataTransfer.files&&e.dataTransfer.files.length;if(this.logger.log("handleDrop",{hasFiles:t}),t){if(document.caretRangeFromPoint){var r=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY);r&&n&&r.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)}var o=this.getImageFiles(e.dataTransfer.files);this.handleNewImageFiles(o)}}},{key:"handlePaste",value:function(e){var t=e.clipboardData&&e.clipboardData.items&&!!e.clipboardData.items.length;if(this.logger.log("handlePaste",{hasItems:t}),t){var r=this.getImageFiles(e.clipboardData.items);0!==r.length&&(Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))?this.logger.log("detected html, not handling"):(e.preventDefault(),this.handleNewImageFiles(r)))}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("readFiles",{files:t}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp|vnd\.microsoft\.icon)/i)}))||[]}}]),e}()},function(e,t,r){"use strict";r.r(t),r.d(t,"downscaleImage",(function(){return l}));var n=r(5),o=r.n(n),i=r(1),a=r.n(i),u=r(0),s=r.n(u);function l(e,t,r,n,o,i,a,u){return c.apply(this,arguments)}function c(){return(c=a()(s.a.mark((function e(t,r,n,i,a,u,l,c){var p,h,d,g,m,y,v,x,b;return s.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return p=t.split(";")[0].split(":")[1],i=i||"image/jpeg",l=l||.7,(h=new Image).src=t,e.next=7,new Promise((function(e){h.onload=function(){e()}}));case 7:if(d=f(h.width,h.height,r,n),g=o()(d,2),m=g[0],y=g[1],(v=document.createElement("canvas")).width=m,v.height=y,x=v.getContext("2d"),"image/jpeg"===i&&(x.fillStyle="#FFFFFF",x.fillRect(0,0,h.width,h.height)),!u.includes(p)){e.next=15;break}return e.abrupt("return",t);case 15:return a.includes(p)&&(i=p),x.drawImage(h,0,0,m,y),b=v.toDataURL(i,l),c.log("downscaling image...",{args:{dataUrl:t,maxWidth:r,maxHeight:n,imageType:i,ignoreImageTypes:u,keepImageTypes:a,imageQuality:l},newHeight:y,newWidth:m}),e.abrupt("return",b);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(e,t,r,n){if(e<=r&&t<=n)return[e,t];if(e>r){var o=r,i=Math.floor(t/e*o);if(i>n){var a=n;return[Math.floor(e/t*a),a]}return[o,i]}if(t>n){var u=n;return[Math.floor(e/t*u),u]}}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i=[],a=!0,u=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){u=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(u)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t,r){var n=r(13);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports}])}));
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "quill-image-compress",
|
3
3
|
"description": "A Quill rich text editor Module which compresses images uploaded to the editor",
|
4
|
-
"version": "1.2.
|
4
|
+
"version": "1.2.18",
|
5
5
|
"main": "dist/quill.imageCompressor.min.js",
|
6
6
|
"homepage": "https://benwinding.github.io/quill-image-compress/src/demo.html",
|
7
7
|
"repository": "https://github.com/benwinding/quill-image-compress",
|
package/src/downscaleImage.js
CHANGED
@@ -37,8 +37,13 @@ export async function downscaleImage(
|
|
37
37
|
canvas.width = newWidth;
|
38
38
|
canvas.height = newHeight;
|
39
39
|
|
40
|
-
// Draw the downscaled image on the canvas and return the new data URL.
|
41
40
|
const ctx = canvas.getContext("2d");
|
41
|
+
|
42
|
+
// If the type is an jpeg, draw a white background first.
|
43
|
+
if (imageType === "image/jpeg") {
|
44
|
+
ctx.fillStyle = "#FFFFFF";
|
45
|
+
ctx.fillRect(0, 0, image.width, image.height);
|
46
|
+
}
|
42
47
|
|
43
48
|
// If the type is included in the ignore list, return the original
|
44
49
|
if (ignoreImageTypes.includes(inputImageType)) {
|
@@ -50,6 +55,7 @@ export async function downscaleImage(
|
|
50
55
|
imageType = inputImageType;
|
51
56
|
}
|
52
57
|
|
58
|
+
// Draw the downscaled image on the canvas and return the new data URL.
|
53
59
|
ctx.drawImage(image, 0, 0, newWidth, newHeight);
|
54
60
|
const newDataUrl = canvas.toDataURL(imageType, imageQuality);
|
55
61
|
logger.log("downscaling image...", {
|