quill-image-compress 1.2.23 → 1.2.26
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -2
- package/dist/demo.min.js +1 -1
- package/dist/index.js +1 -1
- package/dist/quill.imageCompressor.min.js +1 -1
- package/package.json +5 -5
- package/types/ConsoleLogger.d.ts +9 -0
- package/types/downscaleImage.d.ts +2 -0
- package/types/file2b64.d.ts +1 -0
- package/types/index.d.ts +2 -1
- package/types/options.object.d.ts +12 -0
- package/types/options.validation.d.ts +3 -0
- package/types/quill.imageCompressor.d.ts +6 -14
- package/types/quill.imageDrop.d.ts +10 -0
- package/src/downscaleImage.js +0 -98
- package/src/file2b64.js +0 -16
- package/src/options.validation.js +0 -66
- package/src/quill.imageDrop.js +0 -100
package/README.md
CHANGED
@@ -45,6 +45,7 @@ const quill = new Quill(editor, {
|
|
45
45
|
imageType: 'image/jpeg', // default
|
46
46
|
debug: true, // default
|
47
47
|
suppressErrorLogging: false, // default
|
48
|
+
insertIntoEditor: undefined, // default
|
48
49
|
}
|
49
50
|
}
|
50
51
|
});
|
@@ -87,9 +88,28 @@ const quill = new Quill(editor, {
|
|
87
88
|
Image types contained in this array retain their original images, do not compress them.
|
88
89
|
- Values: ['image'/jpeg', 'image/webp']
|
89
90
|
|
91
|
+
- **[Function] insertIntoEditor**
|
92
|
+
Custom function to handle inserting the image. If you wanted to upload the image to a webserver rather than embedding with Base64, you could use this function.
|
93
|
+
- Example function, uploading to a webserver:
|
94
|
+
```js
|
95
|
+
insertIntoEditor: (imageBase64URL, imageBlob) => {
|
96
|
+
const formData = new FormData();
|
97
|
+
formData.append("file", imageBlob);
|
98
|
+
|
99
|
+
fetch("/upload", {method: "POST", body: formData})
|
100
|
+
.then(response => response.text())
|
101
|
+
.then(result => {
|
102
|
+
const range = editor.getSelection();
|
103
|
+
editor.insertEmbed(range.index, "image", `${result}`, "user");
|
104
|
+
})
|
105
|
+
.catch(error => {
|
106
|
+
console.error(error);
|
107
|
+
});
|
108
|
+
}
|
109
|
+
```
|
110
|
+
|
90
111
|
- **[Boolean] debug**
|
91
112
|
- Displays console logs: true/false
|
92
113
|
|
93
114
|
## Thanks
|
94
|
-
This project is based on [quill-image-uploader](https://github.com/NoelOConnell/quill-image-uploader), thanks mate!
|
95
|
-
|
115
|
+
This project is based on [quill-image-uploader](https://github.com/NoelOConnell/quill-image-uploader), thanks mate!
|
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=18)}([function(e,t,r){e.exports=r(8)},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,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){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){var n=r(11),o=r(12),i=r(13),a=r(15);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";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function u(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var i=!0,a=!1,u={prefixString:function(){return"</> quill-image-compress: "},get log(){return i?console.log.bind(console,this.prefixString()):function(){}},get error(){return a?function(){}:console.error.bind(console,this.prefixString())},get warn(){return a?function(){}:console.warn.bind(console,this.prefixString())}},s=r(7).ImageDrop,l=r(9).warnAboutOptions,c=r(2).file2b64,f=r(10).downscaleImage,p=function(){function e(e,t){var r=this;this.quill=e,this.range=null,this.options=t||{},i=!!t.debug,a=!!t.suppressErrorLogging,l(t);this.imageDrop=new s(e,(function(e){return n(r,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return u.log("onImageDrop",{dataUrl:e}),[4,this.downscaleImageFromUrl(e)];case 1:return t=r.sent(),this.insertToEditor(t),[2]}}))}))}),u),u.log("fileChanged",{options:t,quill:e,debug:i});var c=this.quill.getModule("toolbar");c?c.addHandler("image",(function(){return r.selectLocalImage()})):u.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var e;return n(this,void 0,void 0,(function(){var t,r,n,i;return o(this,(function(o){switch(o.label){case 0:return(t=null===(e=this.fileHolder)||void 0===e?void 0:e.files)&&t.length?(r=t[0],u.log("fileChanged",{file:r}),r?[4,c(r)]:[2]):[2];case 1:return n=o.sent(),[4,this.downscaleImageFromUrl(n)];case 2:return i=o.sent(),this.insertToEditor(i),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return n(this,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return[4,f(e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,u)];case 1:return t=r.sent(),u.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e){u.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")},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);u.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=p,window.imageCompressor=p,t.default=p},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(3),a=r.n(i),u=r(4),s=r.n(u),l=r(0),c=r.n(l),f=r(2).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("handleNewImageFiles",{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),n=r.length>0;if(this.logger.log("handlePaste",{hasImages:n,imageCount:r.length}),n)Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))&&this.logger.log("handlePaste also detected html"),e.preventDefault(),this.handleNewImageFiles(r)}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("getImageFiles",{mimeTypes:t.map((function(e){return e.type}))}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}))||[]}}]),e}()},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 L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(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 b(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 x(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,x(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:L}}function L(){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(b.prototype),u(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new b(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";function n(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(Logger.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&&(Logger.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&&(Logger.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/")||(Logger.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}r.r(t),r.d(t,"warnAboutOptions",(function(){return n}))},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,b,x;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,b=v.getContext("2d"),"image/jpeg"===i&&(b.fillStyle="#FFFFFF",b.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),b.drawImage(h,0,0,m,y),x=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",x);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(14);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(16),o=r.n(n),i=r(6),a=r.n(i);o.a.register("modules/imageCompressor",a.a);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 n="object"==typeof exports?t(require("Quill")):t(e.Quill);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=8)}([function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.file2b64=void 0,t.file2b64=function(e){return r(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){return t=new FileReader,n=new Promise((function(e,n){t.addEventListener("load",(function(){var r,i=null===(r=t.result)||void 0===r?void 0:r.toString();i?e(i):n("could not convert file to base64")}),!1)})),t.readAsDataURL(e),[2,n]}))}))}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var o=n(2),a=n(3),l=n(0),u=n(4),s=n(5),c=function(){function e(t,n){var l=this;this.quill=t,this.options=n||{};var u=!!n.debug,c=!!n.suppressErrorLogging;this.Logger=new s.ConsoleLogger(u,c),(0,a.warnAboutOptions)(n,this.Logger);this.imageDrop=new o.ImageDrop(t,(function(t){return r(l,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return this.Logger.log("onImageDrop",{dataUrl:t}),[4,this.downscaleImageFromUrl(t)];case 1:return n=r.sent(),this.insertToEditor(n,e.b64toBlob(n)),[2]}}))}))}),this.Logger),this.Logger.log("fileChanged",{options:n,quill:t,debug:u});var f=this.quill.getModule("toolbar");f?f.addHandler("image",(function(){return l.selectLocalImage()})):this.Logger.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.b64toBlob=function(e){for(var t=atob(e.split(",")[1]),n=e.slice(5).split(";")[0],r=new ArrayBuffer(t.length),i=new Uint8Array(r),o=0;o<t.length;o++)i[o]=t.charCodeAt(o);return new Blob([r],{type:n})},e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var t;return r(this,void 0,void 0,(function(){var n,r,o,a;return i(this,(function(i){switch(i.label){case 0:return(n=null===(t=this.fileHolder)||void 0===t?void 0:t.files)&&n.length?(r=n[0],this.Logger.log("fileChanged",{file:r}),r?[4,(0,l.file2b64)(r)]:[2]):[2];case 1:return o=i.sent(),[4,this.downscaleImageFromUrl(o)];case 2:return a=i.sent(),this.insertToEditor(a,e.b64toBlob(a)),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,(0,u.downscaleImage)(this.Logger,e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality)];case 1:return t=n.sent(),this.Logger.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e,t){if(this.options.insertIntoEditor)this.options.insertIntoEditor(e,t);else{this.Logger.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var n=this.range;if(!n)return;this.logFileSize(e),this.quill.insertEmbed(n.index,"image","".concat(e),"user"),n.index++,this.quill.setSelection(n,"api")}},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);this.Logger.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=c,window.imageCompressor=c,t.default=c},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.ImageDrop=void 0;var o=n(0),a=function(){function e(e,t,n){var r=this;this.quill=e,this.onNewDataUrl=t,this.logger=n,this.quill.root.addEventListener("drop",(function(e){return r.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return r.handlePaste(e)}),!1)}return e.prototype.handleDrop=function(e){return r(this,void 0,void 0,(function(){var t,n,r,a,c,f,g;return i(this,(function(i){switch(i.label){case 0:return e.preventDefault(),document.caretRangeFromPoint&&(t=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY),t&&n&&t.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)),[4,u(e)];case 1:return r=i.sent(),a=Array.from(r||[]).filter((function(e){return s(e.type)})),(c=null==a?void 0:a[0])?[4,(0,o.file2b64)(c)]:[3,3];case 2:return g=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,files:r,filesFiltered:a,firstImage:c,base64ImageSrc:g}),this.onNewDataUrl(g),[2];case 3:return[4,l(e)];case 4:return(f=i.sent())?[4,(0,o.file2b64)(f)]:[3,6];case 5:return g=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,blob:f,base64ImageSrc:g}),this.onNewDataUrl(g),[2];case 6:return[2]}}))}))},e.prototype.handlePaste=function(e){var t,n;return r(this,void 0,void 0,(function(){var r,a,l,u;return i(this,(function(i){switch(i.label){case 0:return r=Array.from((null===(t=null==e?void 0:e.clipboardData)||void 0===t?void 0:t.items)||[]),this.logger.log("handlePaste",{files:r,evt:e}),a=r.filter((function(e){return s(e.type)})),this.logger.log("handlePaste",{images:a,evt:e}),a.length?a.filter((function(e){return"text/html"!==e.type})).length?(e.preventDefault(),(l=null===(n=a.pop())||void 0===n?void 0:n.getAsFile())?[4,(0,o.file2b64)(l)]:[2]):(this.logger.log("handlePaste also detected html"),[2]):[2];case 1:return u=i.sent(),this.logger.log("handleNewImageFiles",{base64ImageSrc:u}),this.onNewDataUrl(u),[2]}}))}))},e}();function l(e){var t;return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=null===(t=e.dataTransfer)||void 0===t?void 0:t.getData("URL"))?[4,fetch(n)]:[3,3];case 1:return[4,r.sent().blob()];case 2:return[2,r.sent()];case 3:return[2]}}))}))}function u(e){var t;return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,null===(t=null==e?void 0:e.dataTransfer)||void 0===t?void 0:t.files]}))}))}function s(e){return!!e.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}t.ImageDrop=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.warnAboutOptions=void 0,t.warnAboutOptions=function(e,t){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(t.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&&(t.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&&(t.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/")||(t.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[]),e.insertIntoEditor&&"function"!=typeof e.insertIntoEditor&&(t.warn("quill.imageCompressor: [config error] 'insertIntoEditor' is required to be a \"function\", received: ".concat(e.insertIntoEditor," -> using default undefined")),e.insertIntoEditor=void 0)}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.downscaleImage=void 0,t.downscaleImage=function(e,t,n,o,a,l,u,s){return r(this,void 0,void 0,(function(){var r,c,f,g,d,p,h,m;return i(this,(function(i){switch(i.label){case 0:return r=t.split(";")[0].split(":")[1],a=a||"image/jpeg",s=s||.7,(c=new Image).src=t,[4,new Promise((function(e){c.onload=function(){e()}}))];case 1:return i.sent(),f=function(e,t,n,r){if(n&&r&&e<=n&&t<=r)return[e,t];if(n&&e>n){var i=n,o=Math.floor(t/e*i);if(r&&o>r){var a=r;return[Math.floor(e/t*a),a]}return[i,o]}if(r&&t>r){o=r;return[i=Math.floor(e/t*o),o]}return[t,e]}(c.width,c.height,n,o),g=f[0],d=f[1],(p=document.createElement("canvas")).width=g,p.height=d,h=p.getContext("2d"),"image/jpeg"===a&&(h.fillStyle="#FFFFFF",h.fillRect(0,0,c.width,c.height)),(null==u?void 0:u.includes(r))?[2,t]:((null==l?void 0:l.includes(r))&&(a=r),h.drawImage(c,0,0,g,d),m=p.toDataURL(a,s),e.log("downscaling image...",{args:{dataUrl:t,maxWidth:n,maxHeight:o,imageType:a,ignoreImageTypes:u,keepImageTypes:l,imageQuality:s},newHeight:d,newWidth:g}),[2,m])}}))}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ConsoleLogger=void 0;var r=function(){function e(e,t){this.debug=e,this.suppressErrorLogging=t}return e.prototype.prefixString=function(){return"</> quill-image-compress: "},Object.defineProperty(e.prototype,"log",{get:function(){return this.debug?console.log.bind(console,this.prefixString()):function(){}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.suppressErrorLogging?function(){}:console.error.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"warn",{get:function(){return this.suppressErrorLogging?function(){}:console.warn.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),e}();t.ConsoleLogger=r},function(t,n){t.exports=e},,function(e,t,n){"use strict";n.r(t);var r=n(6),i=n.n(r),o=n(1),a=n.n(o);i.a.register("modules/imageCompressor",a.a);console.log("Demo loaded...");new i.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}}})}])}));
|
package/dist/index.js
CHANGED
@@ -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=17)}([function(e,t,r){e.exports=r(8)},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,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){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){var n=r(11),o=r(12),i=r(13),a=r(15);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";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function u(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var i=!0,a=!1,u={prefixString:function(){return"</> quill-image-compress: "},get log(){return i?console.log.bind(console,this.prefixString()):function(){}},get error(){return a?function(){}:console.error.bind(console,this.prefixString())},get warn(){return a?function(){}:console.warn.bind(console,this.prefixString())}},s=r(7).ImageDrop,l=r(9).warnAboutOptions,c=r(2).file2b64,f=r(10).downscaleImage,p=function(){function e(e,t){var r=this;this.quill=e,this.range=null,this.options=t||{},i=!!t.debug,a=!!t.suppressErrorLogging,l(t);this.imageDrop=new s(e,(function(e){return n(r,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return u.log("onImageDrop",{dataUrl:e}),[4,this.downscaleImageFromUrl(e)];case 1:return t=r.sent(),this.insertToEditor(t),[2]}}))}))}),u),u.log("fileChanged",{options:t,quill:e,debug:i});var c=this.quill.getModule("toolbar");c?c.addHandler("image",(function(){return r.selectLocalImage()})):u.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var e;return n(this,void 0,void 0,(function(){var t,r,n,i;return o(this,(function(o){switch(o.label){case 0:return(t=null===(e=this.fileHolder)||void 0===e?void 0:e.files)&&t.length?(r=t[0],u.log("fileChanged",{file:r}),r?[4,c(r)]:[2]):[2];case 1:return n=o.sent(),[4,this.downscaleImageFromUrl(n)];case 2:return i=o.sent(),this.insertToEditor(i),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return n(this,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return[4,f(e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,u)];case 1:return t=r.sent(),u.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e){u.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")},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);u.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=p,window.imageCompressor=p,t.default=p},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(3),a=r.n(i),u=r(4),s=r.n(u),l=r(0),c=r.n(l),f=r(2).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("handleNewImageFiles",{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),n=r.length>0;if(this.logger.log("handlePaste",{hasImages:n,imageCount:r.length}),n)Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))&&this.logger.log("handlePaste also detected html"),e.preventDefault(),this.handleNewImageFiles(r)}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("getImageFiles",{mimeTypes:t.map((function(e){return e.type}))}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}))||[]}}]),e}()},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 L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(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(T([])));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 b(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 x(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,x(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 _(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 T(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:L}}function L(){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(b.prototype),u(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new b(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,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(_),!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),_(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;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:T(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";function n(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(Logger.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&&(Logger.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&&(Logger.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/")||(Logger.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}r.r(t),r.d(t,"warnAboutOptions",(function(){return n}))},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,b,x;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,b=v.getContext("2d"),"image/jpeg"===i&&(b.fillStyle="#FFFFFF",b.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),b.drawImage(h,0,0,m,y),x=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",x);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(14);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(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var o=n(r(6));t.imageCompressor=o.default}])}));
|
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 n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=7)}([function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.file2b64=void 0,t.file2b64=function(e){return r(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){return t=new FileReader,n=new Promise((function(e,n){t.addEventListener("load",(function(){var r,i=null===(r=t.result)||void 0===r?void 0:r.toString();i?e(i):n("could not convert file to base64")}),!1)})),t.readAsDataURL(e),[2,n]}))}))}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var o=n(2),a=n(3),l=n(0),u=n(4),s=n(5),c=function(){function e(t,n){var l=this;this.quill=t,this.options=n||{};var u=!!n.debug,c=!!n.suppressErrorLogging;this.Logger=new s.ConsoleLogger(u,c),(0,a.warnAboutOptions)(n,this.Logger);this.imageDrop=new o.ImageDrop(t,(function(t){return r(l,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return this.Logger.log("onImageDrop",{dataUrl:t}),[4,this.downscaleImageFromUrl(t)];case 1:return n=r.sent(),this.insertToEditor(n,e.b64toBlob(n)),[2]}}))}))}),this.Logger),this.Logger.log("fileChanged",{options:n,quill:t,debug:u});var f=this.quill.getModule("toolbar");f?f.addHandler("image",(function(){return l.selectLocalImage()})):this.Logger.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.b64toBlob=function(e){for(var t=atob(e.split(",")[1]),n=e.slice(5).split(";")[0],r=new ArrayBuffer(t.length),i=new Uint8Array(r),o=0;o<t.length;o++)i[o]=t.charCodeAt(o);return new Blob([r],{type:n})},e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var t;return r(this,void 0,void 0,(function(){var n,r,o,a;return i(this,(function(i){switch(i.label){case 0:return(n=null===(t=this.fileHolder)||void 0===t?void 0:t.files)&&n.length?(r=n[0],this.Logger.log("fileChanged",{file:r}),r?[4,(0,l.file2b64)(r)]:[2]):[2];case 1:return o=i.sent(),[4,this.downscaleImageFromUrl(o)];case 2:return a=i.sent(),this.insertToEditor(a,e.b64toBlob(a)),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,(0,u.downscaleImage)(this.Logger,e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality)];case 1:return t=n.sent(),this.Logger.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e,t){if(this.options.insertIntoEditor)this.options.insertIntoEditor(e,t);else{this.Logger.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var n=this.range;if(!n)return;this.logFileSize(e),this.quill.insertEmbed(n.index,"image","".concat(e),"user"),n.index++,this.quill.setSelection(n,"api")}},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);this.Logger.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=c,window.imageCompressor=c,t.default=c},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.ImageDrop=void 0;var o=n(0),a=function(){function e(e,t,n){var r=this;this.quill=e,this.onNewDataUrl=t,this.logger=n,this.quill.root.addEventListener("drop",(function(e){return r.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return r.handlePaste(e)}),!1)}return e.prototype.handleDrop=function(e){return r(this,void 0,void 0,(function(){var t,n,r,a,c,f,d;return i(this,(function(i){switch(i.label){case 0:return e.preventDefault(),document.caretRangeFromPoint&&(t=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY),t&&n&&t.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)),[4,u(e)];case 1:return r=i.sent(),a=Array.from(r||[]).filter((function(e){return s(e.type)})),(c=null==a?void 0:a[0])?[4,(0,o.file2b64)(c)]:[3,3];case 2:return d=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,files:r,filesFiltered:a,firstImage:c,base64ImageSrc:d}),this.onNewDataUrl(d),[2];case 3:return[4,l(e)];case 4:return(f=i.sent())?[4,(0,o.file2b64)(f)]:[3,6];case 5:return d=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,blob:f,base64ImageSrc:d}),this.onNewDataUrl(d),[2];case 6:return[2]}}))}))},e.prototype.handlePaste=function(e){var t,n;return r(this,void 0,void 0,(function(){var r,a,l,u;return i(this,(function(i){switch(i.label){case 0:return r=Array.from((null===(t=null==e?void 0:e.clipboardData)||void 0===t?void 0:t.items)||[]),this.logger.log("handlePaste",{files:r,evt:e}),a=r.filter((function(e){return s(e.type)})),this.logger.log("handlePaste",{images:a,evt:e}),a.length?a.filter((function(e){return"text/html"!==e.type})).length?(e.preventDefault(),(l=null===(n=a.pop())||void 0===n?void 0:n.getAsFile())?[4,(0,o.file2b64)(l)]:[2]):(this.logger.log("handlePaste also detected html"),[2]):[2];case 1:return u=i.sent(),this.logger.log("handleNewImageFiles",{base64ImageSrc:u}),this.onNewDataUrl(u),[2]}}))}))},e}();function l(e){var t;return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=null===(t=e.dataTransfer)||void 0===t?void 0:t.getData("URL"))?[4,fetch(n)]:[3,3];case 1:return[4,r.sent().blob()];case 2:return[2,r.sent()];case 3:return[2]}}))}))}function u(e){var t;return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,null===(t=null==e?void 0:e.dataTransfer)||void 0===t?void 0:t.files]}))}))}function s(e){return!!e.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}t.ImageDrop=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.warnAboutOptions=void 0,t.warnAboutOptions=function(e,t){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(t.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&&(t.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&&(t.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/")||(t.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[]),e.insertIntoEditor&&"function"!=typeof e.insertIntoEditor&&(t.warn("quill.imageCompressor: [config error] 'insertIntoEditor' is required to be a \"function\", received: ".concat(e.insertIntoEditor," -> using default undefined")),e.insertIntoEditor=void 0)}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.downscaleImage=void 0,t.downscaleImage=function(e,t,n,o,a,l,u,s){return r(this,void 0,void 0,(function(){var r,c,f,d,g,p,h,m;return i(this,(function(i){switch(i.label){case 0:return r=t.split(";")[0].split(":")[1],a=a||"image/jpeg",s=s||.7,(c=new Image).src=t,[4,new Promise((function(e){c.onload=function(){e()}}))];case 1:return i.sent(),f=function(e,t,n,r){if(n&&r&&e<=n&&t<=r)return[e,t];if(n&&e>n){var i=n,o=Math.floor(t/e*i);if(r&&o>r){var a=r;return[Math.floor(e/t*a),a]}return[i,o]}if(r&&t>r){o=r;return[i=Math.floor(e/t*o),o]}return[t,e]}(c.width,c.height,n,o),d=f[0],g=f[1],(p=document.createElement("canvas")).width=d,p.height=g,h=p.getContext("2d"),"image/jpeg"===a&&(h.fillStyle="#FFFFFF",h.fillRect(0,0,c.width,c.height)),(null==u?void 0:u.includes(r))?[2,t]:((null==l?void 0:l.includes(r))&&(a=r),h.drawImage(c,0,0,d,g),m=p.toDataURL(a,s),e.log("downscaling image...",{args:{dataUrl:t,maxWidth:n,maxHeight:o,imageType:a,ignoreImageTypes:u,keepImageTypes:l,imageQuality:s},newHeight:g,newWidth:d}),[2,m])}}))}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ConsoleLogger=void 0;var r=function(){function e(e,t){this.debug=e,this.suppressErrorLogging=t}return e.prototype.prefixString=function(){return"</> quill-image-compress: "},Object.defineProperty(e.prototype,"log",{get:function(){return this.debug?console.log.bind(console,this.prefixString()):function(){}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.suppressErrorLogging?function(){}:console.error.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"warn",{get:function(){return this.suppressErrorLogging?function(){}:console.warn.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),e}();t.ConsoleLogger=r},,function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var i=r(n(1));t.imageCompressor=i.default}])}));
|
@@ -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(8)},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,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){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){var n=r(11),o=r(12),i=r(13),a=r(15);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";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function u(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,u)}s((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var i=!0,a=!1,u={prefixString:function(){return"</> quill-image-compress: "},get log(){return i?console.log.bind(console,this.prefixString()):function(){}},get error(){return a?function(){}:console.error.bind(console,this.prefixString())},get warn(){return a?function(){}:console.warn.bind(console,this.prefixString())}},s=r(7).ImageDrop,l=r(9).warnAboutOptions,c=r(2).file2b64,f=r(10).downscaleImage,p=function(){function e(e,t){var r=this;this.quill=e,this.range=null,this.options=t||{},i=!!t.debug,a=!!t.suppressErrorLogging,l(t);this.imageDrop=new s(e,(function(e){return n(r,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return u.log("onImageDrop",{dataUrl:e}),[4,this.downscaleImageFromUrl(e)];case 1:return t=r.sent(),this.insertToEditor(t),[2]}}))}))}),u),u.log("fileChanged",{options:t,quill:e,debug:i});var c=this.quill.getModule("toolbar");c?c.addHandler("image",(function(){return r.selectLocalImage()})):u.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var e;return n(this,void 0,void 0,(function(){var t,r,n,i;return o(this,(function(o){switch(o.label){case 0:return(t=null===(e=this.fileHolder)||void 0===e?void 0:e.files)&&t.length?(r=t[0],u.log("fileChanged",{file:r}),r?[4,c(r)]:[2]):[2];case 1:return n=o.sent(),[4,this.downscaleImageFromUrl(n)];case 2:return i=o.sent(),this.insertToEditor(i),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return n(this,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return[4,f(e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality,u)];case 1:return t=r.sent(),u.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e){u.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")},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);u.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=p,window.imageCompressor=p,t.default=p},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(3),a=r.n(i),u=r(4),s=r.n(u),l=r(0),c=r.n(l),f=r(2).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("handleNewImageFiles",{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),n=r.length>0;if(this.logger.log("handlePaste",{hasImages:n,imageCount:r.length}),n)Array.from(e.clipboardData.items).some((function(e){return"text/html"===e.type}))&&this.logger.log("handlePaste also detected html"),e.preventDefault(),this.handleNewImageFiles(r)}}},{key:"getImageFiles",value:function(e){var t=Array.from(e);return this.logger.log("getImageFiles",{mimeTypes:t.map((function(e){return e.type}))}),t.filter((function(e){return!!e.type.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}))||[]}}]),e}()},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 L()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=x(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 b(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 x(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,x(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:L}}function L(){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(b.prototype),u(b.prototype,i,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new b(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";function n(e){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(Logger.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&&(Logger.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&&(Logger.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/")||(Logger.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(Logger.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[])}r.r(t),r.d(t,"warnAboutOptions",(function(){return n}))},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,b,x;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,b=v.getContext("2d"),"image/jpeg"===i&&(b.fillStyle="#FFFFFF",b.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),b.drawImage(h,0,0,m,y),x=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",x);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(14);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 n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/dist/",n(n.s=1)}([function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.file2b64=void 0,t.file2b64=function(e){return r(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){return t=new FileReader,n=new Promise((function(e,n){t.addEventListener("load",(function(){var r,i=null===(r=t.result)||void 0===r?void 0:r.toString();i?e(i):n("could not convert file to base64")}),!1)})),t.readAsDataURL(e),[2,n]}))}))}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.imageCompressor=void 0;var o=n(2),a=n(3),l=n(0),u=n(4),s=n(5),c=function(){function e(t,n){var l=this;this.quill=t,this.options=n||{};var u=!!n.debug,c=!!n.suppressErrorLogging;this.Logger=new s.ConsoleLogger(u,c),(0,a.warnAboutOptions)(n,this.Logger);this.imageDrop=new o.ImageDrop(t,(function(t){return r(l,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return this.Logger.log("onImageDrop",{dataUrl:t}),[4,this.downscaleImageFromUrl(t)];case 1:return n=r.sent(),this.insertToEditor(n,e.b64toBlob(n)),[2]}}))}))}),this.Logger),this.Logger.log("fileChanged",{options:n,quill:t,debug:u});var f=this.quill.getModule("toolbar");f?f.addHandler("image",(function(){return l.selectLocalImage()})):this.Logger.error("Quill toolbar module not found! need { toolbar: // options } in Quill.modules for image icon to sit in")}return e.b64toBlob=function(e){for(var t=atob(e.split(",")[1]),n=e.slice(5).split(";")[0],r=new ArrayBuffer(t.length),i=new Uint8Array(r),o=0;o<t.length;o++)i[o]=t.charCodeAt(o);return new Blob([r],{type:n})},e.prototype.selectLocalImage=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(){e.fileHolder&&document.body.removeChild(e.fileHolder)}))},e.prototype.fileChanged=function(){var t;return r(this,void 0,void 0,(function(){var n,r,o,a;return i(this,(function(i){switch(i.label){case 0:return(n=null===(t=this.fileHolder)||void 0===t?void 0:t.files)&&n.length?(r=n[0],this.Logger.log("fileChanged",{file:r}),r?[4,(0,l.file2b64)(r)]:[2]):[2];case 1:return o=i.sent(),[4,this.downscaleImageFromUrl(o)];case 2:return a=i.sent(),this.insertToEditor(a,e.b64toBlob(a)),[2]}}))}))},e.prototype.downscaleImageFromUrl=function(e){return r(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,(0,u.downscaleImage)(this.Logger,e,this.options.maxWidth,this.options.maxHeight,this.options.imageType,this.options.keepImageTypes,this.options.ignoreImageTypes,this.options.quality)];case 1:return t=n.sent(),this.Logger.log("downscaleImageFromUrl",{dataUrl:e,dataUrlCompressed:t}),[2,t]}}))}))},e.prototype.insertToEditor=function(e,t){if(this.options.insertIntoEditor)this.options.insertIntoEditor(e,t);else{this.Logger.log("insertToEditor",{url:e}),this.range=this.quill.getSelection();var n=this.range;if(!n)return;this.logFileSize(e),this.quill.insertEmbed(n.index,"image","".concat(e),"user"),n.index++,this.quill.setSelection(n,"api")}},e.prototype.logFileSize=function(e){var t=(Math.round(3*(e.length-"data:image/png;base64,".length)/4)/1024).toFixed(0);this.Logger.log("estimated img size: "+t+" kb")},e}();t.imageCompressor=c,window.imageCompressor=c,t.default=c},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.ImageDrop=void 0;var o=n(0),a=function(){function e(e,t,n){var r=this;this.quill=e,this.onNewDataUrl=t,this.logger=n,this.quill.root.addEventListener("drop",(function(e){return r.handleDrop(e)}),!1),this.quill.root.addEventListener("paste",(function(e){return r.handlePaste(e)}),!1)}return e.prototype.handleDrop=function(e){return r(this,void 0,void 0,(function(){var t,n,r,a,c,f,g;return i(this,(function(i){switch(i.label){case 0:return e.preventDefault(),document.caretRangeFromPoint&&(t=document.getSelection(),n=document.caretRangeFromPoint(e.clientX,e.clientY),t&&n&&t.setBaseAndExtent(n.startContainer,n.startOffset,n.startContainer,n.startOffset)),[4,u(e)];case 1:return r=i.sent(),a=Array.from(r||[]).filter((function(e){return s(e.type)})),(c=null==a?void 0:a[0])?[4,(0,o.file2b64)(c)]:[3,3];case 2:return g=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,files:r,filesFiltered:a,firstImage:c,base64ImageSrc:g}),this.onNewDataUrl(g),[2];case 3:return[4,l(e)];case 4:return(f=i.sent())?[4,(0,o.file2b64)(f)]:[3,6];case 5:return g=i.sent(),this.logger.log("handleNewImageFiles",{evt:e,blob:f,base64ImageSrc:g}),this.onNewDataUrl(g),[2];case 6:return[2]}}))}))},e.prototype.handlePaste=function(e){var t,n;return r(this,void 0,void 0,(function(){var r,a,l,u;return i(this,(function(i){switch(i.label){case 0:return r=Array.from((null===(t=null==e?void 0:e.clipboardData)||void 0===t?void 0:t.items)||[]),this.logger.log("handlePaste",{files:r,evt:e}),a=r.filter((function(e){return s(e.type)})),this.logger.log("handlePaste",{images:a,evt:e}),a.length?a.filter((function(e){return"text/html"!==e.type})).length?(e.preventDefault(),(l=null===(n=a.pop())||void 0===n?void 0:n.getAsFile())?[4,(0,o.file2b64)(l)]:[2]):(this.logger.log("handlePaste also detected html"),[2]):[2];case 1:return u=i.sent(),this.logger.log("handleNewImageFiles",{base64ImageSrc:u}),this.onNewDataUrl(u),[2]}}))}))},e}();function l(e){var t;return r(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return(n=null===(t=e.dataTransfer)||void 0===t?void 0:t.getData("URL"))?[4,fetch(n)]:[3,3];case 1:return[4,r.sent().blob()];case 2:return[2,r.sent()];case 3:return[2]}}))}))}function u(e){var t;return r(this,void 0,void 0,(function(){return i(this,(function(n){return[2,null===(t=null==e?void 0:e.dataTransfer)||void 0===t?void 0:t.files]}))}))}function s(e){return!!e.match(/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i)}t.ImageDrop=a},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.warnAboutOptions=void 0,t.warnAboutOptions=function(e,t){e.maxWidth=e.maxWidth||1e3,e.maxHeight=e.maxHeight||1e3,e.maxWidth&&"number"!=typeof e.maxWidth&&(t.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&&(t.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&&(t.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/")||(t.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||(e.keepImageTypes=[]),e.keepImageTypes&&!Array.isArray(e.keepImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'keepImageTypes' is required to be a \"array\", received: ".concat(e.keepImageTypes," -> using default []")),e.keepImageTypes=[]),e.ignoreImageTypes||(e.ignoreImageTypes=[]),e.ignoreImageTypes&&!Array.isArray(e.ignoreImageTypes)&&(t.warn("quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a \"array\", received: ".concat(e.ignoreImageTypes," -> using default []")),e.ignoreImageTypes=[]),e.insertIntoEditor&&"function"!=typeof e.insertIntoEditor&&(t.warn("quill.imageCompressor: [config error] 'insertIntoEditor' is required to be a \"function\", received: ".concat(e.insertIntoEditor," -> using default undefined")),e.insertIntoEditor=void 0)}},function(e,t,n){"use strict";var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function l(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,l)}u((r=r.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var n,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:l(0),throw:l(1),return:l(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function l(o){return function(l){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,r=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,l])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.downscaleImage=void 0,t.downscaleImage=function(e,t,n,o,a,l,u,s){return r(this,void 0,void 0,(function(){var r,c,f,g,d,p,h,m;return i(this,(function(i){switch(i.label){case 0:return r=t.split(";")[0].split(":")[1],a=a||"image/jpeg",s=s||.7,(c=new Image).src=t,[4,new Promise((function(e){c.onload=function(){e()}}))];case 1:return i.sent(),f=function(e,t,n,r){if(n&&r&&e<=n&&t<=r)return[e,t];if(n&&e>n){var i=n,o=Math.floor(t/e*i);if(r&&o>r){var a=r;return[Math.floor(e/t*a),a]}return[i,o]}if(r&&t>r){o=r;return[i=Math.floor(e/t*o),o]}return[t,e]}(c.width,c.height,n,o),g=f[0],d=f[1],(p=document.createElement("canvas")).width=g,p.height=d,h=p.getContext("2d"),"image/jpeg"===a&&(h.fillStyle="#FFFFFF",h.fillRect(0,0,c.width,c.height)),(null==u?void 0:u.includes(r))?[2,t]:((null==l?void 0:l.includes(r))&&(a=r),h.drawImage(c,0,0,g,d),m=p.toDataURL(a,s),e.log("downscaling image...",{args:{dataUrl:t,maxWidth:n,maxHeight:o,imageType:a,ignoreImageTypes:u,keepImageTypes:l,imageQuality:s},newHeight:d,newWidth:g}),[2,m])}}))}))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ConsoleLogger=void 0;var r=function(){function e(e,t){this.debug=e,this.suppressErrorLogging=t}return e.prototype.prefixString=function(){return"</> quill-image-compress: "},Object.defineProperty(e.prototype,"log",{get:function(){return this.debug?console.log.bind(console,this.prefixString()):function(){}},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.suppressErrorLogging?function(){}:console.error.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"warn",{get:function(){return this.suppressErrorLogging?function(){}:console.warn.bind(console,this.prefixString())},enumerable:!1,configurable:!0}),e}();t.ConsoleLogger=r}])}));
|
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.26",
|
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",
|
@@ -9,7 +9,7 @@
|
|
9
9
|
"license": "MIT",
|
10
10
|
"scripts": {
|
11
11
|
"watch": "webpack --watch --progress --mode development",
|
12
|
-
"start": "webpack-dev-server --hot --port 8001",
|
12
|
+
"start": "webpack-dev-server --hot --port 8001 --mode development",
|
13
13
|
"build-dev": "webpack --mode development",
|
14
14
|
"build": "webpack --mode production"
|
15
15
|
},
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"reduce"
|
30
30
|
],
|
31
31
|
"dependencies": {
|
32
|
-
"quill": "^1.
|
32
|
+
"quill": "^1.3.7"
|
33
33
|
},
|
34
34
|
"devDependencies": {
|
35
35
|
"@babel/core": "^7.8.7",
|
@@ -45,8 +45,8 @@
|
|
45
45
|
"ts-loader": "^8.0.11",
|
46
46
|
"typescript": "^4.1.2",
|
47
47
|
"uglifyjs-webpack-plugin": "^1.1.6",
|
48
|
-
"webpack": "^4.
|
49
|
-
"webpack-cli": "^3.
|
48
|
+
"webpack": "^4.46.0",
|
49
|
+
"webpack-cli": "^3.3.12",
|
50
50
|
"webpack-dev-server": "^3.1.14"
|
51
51
|
}
|
52
52
|
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export declare class ConsoleLogger {
|
2
|
+
private debug;
|
3
|
+
private suppressErrorLogging;
|
4
|
+
constructor(debug: boolean, suppressErrorLogging: boolean);
|
5
|
+
prefixString(): string;
|
6
|
+
get log(): (...args: any[]) => void;
|
7
|
+
get error(): (...args: any[]) => void;
|
8
|
+
get warn(): (...args: any[]) => void;
|
9
|
+
}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import { ConsoleLogger } from "ConsoleLogger";
|
2
|
+
export declare function downscaleImage(logger: ConsoleLogger, dataUrl: string, maxWidth?: number, maxHeight?: number, imageType?: string, keepImageTypes?: string[], ignoreImageTypes?: string[], imageQuality?: number): Promise<string>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function file2b64(file: Blob): Promise<string>;
|
package/types/index.d.ts
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
export declare type OptionsObject = {
|
2
|
+
validation?: boolean;
|
3
|
+
debug?: boolean;
|
4
|
+
suppressErrorLogging?: boolean;
|
5
|
+
maxWidth?: number;
|
6
|
+
maxHeight?: number;
|
7
|
+
imageType?: string;
|
8
|
+
keepImageTypes?: string[];
|
9
|
+
ignoreImageTypes?: string[];
|
10
|
+
quality?: number;
|
11
|
+
insertIntoEditor?: (base64URL: string, imageBlob: Blob) => void;
|
12
|
+
};
|
@@ -1,26 +1,18 @@
|
|
1
1
|
import Quill from "quill";
|
2
|
-
|
3
|
-
validation?: boolean;
|
4
|
-
debug?: boolean;
|
5
|
-
suppressErrorLogging?: boolean;
|
6
|
-
maxWidth?: boolean;
|
7
|
-
maxHeight?: boolean;
|
8
|
-
imageType?: boolean;
|
9
|
-
keepImageTypes?: boolean;
|
10
|
-
ignoreImageTypes?: boolean;
|
11
|
-
quality?: boolean;
|
12
|
-
};
|
2
|
+
import { OptionsObject } from "./options.object";
|
13
3
|
declare class imageCompressor {
|
14
4
|
private quill;
|
15
|
-
private range
|
5
|
+
private range?;
|
16
6
|
private options;
|
17
7
|
private imageDrop;
|
18
8
|
private fileHolder;
|
9
|
+
private Logger;
|
10
|
+
static b64toBlob(dataURI: string): Blob;
|
19
11
|
constructor(quill: Quill, options: OptionsObject);
|
20
12
|
selectLocalImage(): void;
|
21
13
|
fileChanged(): Promise<void>;
|
22
|
-
downscaleImageFromUrl(dataUrl: string): Promise<
|
23
|
-
insertToEditor(url: string): void;
|
14
|
+
downscaleImageFromUrl(dataUrl: string): Promise<string>;
|
15
|
+
insertToEditor(url: string, blob: Blob): void;
|
24
16
|
logFileSize(dataUrl: string): void;
|
25
17
|
}
|
26
18
|
export { imageCompressor };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import Quill from "quill";
|
2
|
+
import { ConsoleLogger } from "./ConsoleLogger";
|
3
|
+
export declare class ImageDrop {
|
4
|
+
private quill;
|
5
|
+
private onNewDataUrl;
|
6
|
+
private logger;
|
7
|
+
constructor(quill: Quill, onNewDataUrl: (dataUrl: string) => void, logger: ConsoleLogger);
|
8
|
+
private handleDrop;
|
9
|
+
private handlePaste;
|
10
|
+
}
|
package/src/downscaleImage.js
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
// Take an image URL, downscale it to the given width, and return a new image URL.
|
2
|
-
export async function downscaleImage(
|
3
|
-
dataUrl,
|
4
|
-
maxWidth,
|
5
|
-
maxHeight,
|
6
|
-
imageType,
|
7
|
-
keepImageTypes,
|
8
|
-
ignoreImageTypes,
|
9
|
-
imageQuality,
|
10
|
-
logger,
|
11
|
-
) {
|
12
|
-
"use strict";
|
13
|
-
// Input image values
|
14
|
-
const inputImageType = dataUrl.split(';')[0].split(':')[1];
|
15
|
-
|
16
|
-
// Provide default values
|
17
|
-
imageType = imageType || "image/jpeg";
|
18
|
-
imageQuality = imageQuality || 0.7;
|
19
|
-
|
20
|
-
// Create a temporary image so that we can compute the height of the downscaled image.
|
21
|
-
const image = new Image();
|
22
|
-
image.src = dataUrl;
|
23
|
-
await new Promise((resolve) => {
|
24
|
-
image.onload = () => {
|
25
|
-
resolve();
|
26
|
-
};
|
27
|
-
});
|
28
|
-
const [newWidth, newHeight] = getDimensions(
|
29
|
-
image.width,
|
30
|
-
image.height,
|
31
|
-
maxWidth,
|
32
|
-
maxHeight
|
33
|
-
);
|
34
|
-
|
35
|
-
// Create a temporary canvas to draw the downscaled image on.
|
36
|
-
const canvas = document.createElement("canvas");
|
37
|
-
canvas.width = newWidth;
|
38
|
-
canvas.height = newHeight;
|
39
|
-
|
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
|
-
}
|
47
|
-
|
48
|
-
// If the type is included in the ignore list, return the original
|
49
|
-
if (ignoreImageTypes.includes(inputImageType)) {
|
50
|
-
return dataUrl;
|
51
|
-
}
|
52
|
-
|
53
|
-
// If the type is included in keep type list, fix the image type
|
54
|
-
if (keepImageTypes.includes(inputImageType)) {
|
55
|
-
imageType = inputImageType;
|
56
|
-
}
|
57
|
-
|
58
|
-
// Draw the downscaled image on the canvas and return the new data URL.
|
59
|
-
ctx.drawImage(image, 0, 0, newWidth, newHeight);
|
60
|
-
const newDataUrl = canvas.toDataURL(imageType, imageQuality);
|
61
|
-
logger.log("downscaling image...", {
|
62
|
-
args: {
|
63
|
-
dataUrl,
|
64
|
-
maxWidth,
|
65
|
-
maxHeight,
|
66
|
-
imageType,
|
67
|
-
ignoreImageTypes,
|
68
|
-
keepImageTypes,
|
69
|
-
imageQuality,
|
70
|
-
},
|
71
|
-
newHeight,
|
72
|
-
newWidth,
|
73
|
-
});
|
74
|
-
return newDataUrl;
|
75
|
-
}
|
76
|
-
|
77
|
-
function getDimensions(inputWidth, inputHeight, maxWidth, maxHeight) {
|
78
|
-
if (inputWidth <= maxWidth && inputHeight <= maxHeight) {
|
79
|
-
return [inputWidth, inputHeight];
|
80
|
-
}
|
81
|
-
if (inputWidth > maxWidth) {
|
82
|
-
const newWidth = maxWidth;
|
83
|
-
const newHeight = Math.floor((inputHeight / inputWidth) * newWidth);
|
84
|
-
|
85
|
-
if (newHeight > maxHeight) {
|
86
|
-
const newHeight = maxHeight;
|
87
|
-
const newWidth = Math.floor((inputWidth / inputHeight) * newHeight);
|
88
|
-
return [newWidth, newHeight];
|
89
|
-
} else {
|
90
|
-
return [newWidth, newHeight];
|
91
|
-
}
|
92
|
-
}
|
93
|
-
if (inputHeight > maxHeight) {
|
94
|
-
const newHeight = maxHeight;
|
95
|
-
const newWidth = Math.floor((inputWidth / inputHeight) * newHeight);
|
96
|
-
return [newWidth, newHeight];
|
97
|
-
}
|
98
|
-
}
|
package/src/file2b64.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
export async function file2b64(file) {
|
2
|
-
const fileReader = new FileReader();
|
3
|
-
|
4
|
-
const promise = new Promise((resolve) => {
|
5
|
-
fileReader.addEventListener(
|
6
|
-
"load",
|
7
|
-
() => {
|
8
|
-
const base64ImageSrc = fileReader.result;
|
9
|
-
resolve(base64ImageSrc);
|
10
|
-
},
|
11
|
-
false
|
12
|
-
);
|
13
|
-
});
|
14
|
-
fileReader.readAsDataURL(file);
|
15
|
-
return promise;
|
16
|
-
}
|
@@ -1,66 +0,0 @@
|
|
1
|
-
export function warnAboutOptions(options) {
|
2
|
-
// Safe-ify Options
|
3
|
-
options.maxWidth = options.maxWidth || 1000;
|
4
|
-
options.maxHeight = options.maxHeight || 1000;
|
5
|
-
|
6
|
-
if (options.maxWidth && typeof options.maxWidth !== "number") {
|
7
|
-
Logger.warn(
|
8
|
-
`[config error] 'maxWidth' is required to be a "number" (in pixels),
|
9
|
-
received: ${options.maxWidth}
|
10
|
-
-> using default 1000`
|
11
|
-
);
|
12
|
-
options.maxWidth = 1000;
|
13
|
-
}
|
14
|
-
if (options.maxHeight && typeof options.maxHeight !== "number") {
|
15
|
-
Logger.warn(
|
16
|
-
`[config error] 'maxHeight' is required to be a "number" (in pixels),
|
17
|
-
received: ${options.maxHeight}
|
18
|
-
-> using default 1000`
|
19
|
-
);
|
20
|
-
options.maxHeight = 1000;
|
21
|
-
}
|
22
|
-
if (options.quality && typeof options.quality !== "number") {
|
23
|
-
Logger.warn(
|
24
|
-
`quill.imageCompressor: [config error] 'quality' is required to be a "number",
|
25
|
-
received: ${options.quality}
|
26
|
-
-> using default 0.7`
|
27
|
-
);
|
28
|
-
options.quality = 0.7;
|
29
|
-
}
|
30
|
-
if (
|
31
|
-
options.imageType &&
|
32
|
-
(typeof options.imageType !== "string" ||
|
33
|
-
!options.imageType.startsWith("image/"))
|
34
|
-
) {
|
35
|
-
Logger.warn(
|
36
|
-
`quill.imageCompressor: [config error] 'imageType' is required be in the form of "image/png" or "image/jpeg" etc ...,
|
37
|
-
received: ${options.imageType}
|
38
|
-
-> using default image/jpeg`
|
39
|
-
);
|
40
|
-
options.imageType = "image/jpeg";
|
41
|
-
}
|
42
|
-
if (!options.keepImageTypes) {
|
43
|
-
options.keepImageTypes = []
|
44
|
-
}
|
45
|
-
if (
|
46
|
-
options.keepImageTypes &&
|
47
|
-
(!Array.isArray(options.keepImageTypes))
|
48
|
-
) {
|
49
|
-
Logger.warn(
|
50
|
-
`quill.imageCompressor: [config error] 'keepImageTypes' is required to be a "array", received: ${options.keepImageTypes} -> using default []`
|
51
|
-
)
|
52
|
-
options.keepImageTypes = [];
|
53
|
-
}
|
54
|
-
if (!options.ignoreImageTypes) {
|
55
|
-
options.ignoreImageTypes = []
|
56
|
-
}
|
57
|
-
if (
|
58
|
-
options.ignoreImageTypes &&
|
59
|
-
(!Array.isArray(options.ignoreImageTypes))
|
60
|
-
) {
|
61
|
-
Logger.warn(
|
62
|
-
`quill.imageCompressor: [config error] 'ignoreImageTypes' is required to be a "array", received: ${options.ignoreImageTypes} -> using default []`
|
63
|
-
)
|
64
|
-
options.ignoreImageTypes = [];
|
65
|
-
}
|
66
|
-
}
|
package/src/quill.imageDrop.js
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
const { file2b64 } = require("./file2b64");
|
2
|
-
|
3
|
-
/*
|
4
|
-
From: https://github.com/kensnyder/quill-image-drop-module/blob/master/index.js
|
5
|
-
*/
|
6
|
-
export class ImageDrop {
|
7
|
-
constructor(quill, onNewDataUrl, logger) {
|
8
|
-
// save the quill reference
|
9
|
-
this.logger = logger;
|
10
|
-
this.quill = quill;
|
11
|
-
this.onNewDataUrl = onNewDataUrl;
|
12
|
-
// listen for drop and paste events
|
13
|
-
this.quill.root.addEventListener("drop", (e) => this.handleDrop(e), false);
|
14
|
-
this.quill.root.addEventListener(
|
15
|
-
"paste",
|
16
|
-
(e) => this.handlePaste(e),
|
17
|
-
false
|
18
|
-
);
|
19
|
-
}
|
20
|
-
|
21
|
-
async handleNewImageFiles(imageFiles) {
|
22
|
-
if (!Array.isArray(imageFiles)) {
|
23
|
-
return;
|
24
|
-
}
|
25
|
-
const firstImage = imageFiles.pop();
|
26
|
-
if (!firstImage) {
|
27
|
-
return;
|
28
|
-
}
|
29
|
-
const blob = firstImage.getAsFile ? firstImage.getAsFile() : firstImage;
|
30
|
-
const base64ImageSrc = await file2b64(blob);
|
31
|
-
this.logger.log("handleNewImageFiles", { base64ImageSrc });
|
32
|
-
this.onNewDataUrl(base64ImageSrc);
|
33
|
-
}
|
34
|
-
|
35
|
-
handleDrop(evt) {
|
36
|
-
evt.preventDefault();
|
37
|
-
const hasFiles =
|
38
|
-
evt.dataTransfer &&
|
39
|
-
evt.dataTransfer.files &&
|
40
|
-
evt.dataTransfer.files.length;
|
41
|
-
this.logger.log("handleDrop", { hasFiles });
|
42
|
-
if (!hasFiles) {
|
43
|
-
return;
|
44
|
-
}
|
45
|
-
if (document.caretRangeFromPoint) {
|
46
|
-
const selection = document.getSelection();
|
47
|
-
const range = document.caretRangeFromPoint(evt.clientX, evt.clientY);
|
48
|
-
if (selection && range) {
|
49
|
-
selection.setBaseAndExtent(
|
50
|
-
range.startContainer,
|
51
|
-
range.startOffset,
|
52
|
-
range.startContainer,
|
53
|
-
range.startOffset
|
54
|
-
);
|
55
|
-
}
|
56
|
-
}
|
57
|
-
const images = this.getImageFiles(evt.dataTransfer.files);
|
58
|
-
this.handleNewImageFiles(images);
|
59
|
-
}
|
60
|
-
|
61
|
-
handlePaste(evt) {
|
62
|
-
const hasItems =
|
63
|
-
evt.clipboardData &&
|
64
|
-
evt.clipboardData.items &&
|
65
|
-
!!evt.clipboardData.items.length;
|
66
|
-
this.logger.log("handlePaste", { hasItems });
|
67
|
-
if (!hasItems) {
|
68
|
-
return;
|
69
|
-
}
|
70
|
-
const images = this.getImageFiles(evt.clipboardData.items);
|
71
|
-
const hasImages = images.length > 0;
|
72
|
-
this.logger.log("handlePaste", { hasImages, imageCount: images.length });
|
73
|
-
if (!hasImages) {
|
74
|
-
return;
|
75
|
-
}
|
76
|
-
|
77
|
-
// Text pasted from word will contain both text/html and image/png.
|
78
|
-
const hasHtmlMixed = Array.from(evt.clipboardData.items).some(f => f.type === 'text/html');
|
79
|
-
if (hasHtmlMixed) {
|
80
|
-
this.logger.log("handlePaste also detected html");
|
81
|
-
}
|
82
|
-
|
83
|
-
evt.preventDefault();
|
84
|
-
this.handleNewImageFiles(images);
|
85
|
-
}
|
86
|
-
|
87
|
-
getImageFiles(filesList) {
|
88
|
-
const files = Array.from(filesList);
|
89
|
-
this.logger.log("getImageFiles", { mimeTypes: files.map(f => f.type) });
|
90
|
-
// check each file for an image
|
91
|
-
function isFileImage(file) {
|
92
|
-
const isImage = !!file.type.match(
|
93
|
-
/^image\/(gif|jpe?g|a?png|svg|webp|bmp)/i
|
94
|
-
);
|
95
|
-
return isImage;
|
96
|
-
}
|
97
|
-
const images = files.filter(isFileImage);
|
98
|
-
return images || [];
|
99
|
-
}
|
100
|
-
}
|