svgedit/dist/editor/system/extensions/ext-imagelib/ext-imagelib.js

10 lines
8.1 KiB
JavaScript
Raw Normal View History

2020-09-06 06:32:10 +00:00
System.register([],(function(e,t){"use strict";return{execute:function(){function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function asyncGeneratorStep(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function _next(e){asyncGeneratorStep(o,n,i,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(o,n,i,_next,_throw,"throw",e)}_next(void 0)}))}}
/**
* @file ext-imagelib.js
*
* @license MIT
*
* @copyright 2010 Alexis Deveria
*
*/e("default",{name:"imagelib",init:function init(e){var r=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var n,i,o,a,s,c,p,l,u,d,b,m,g,h,f,v,x,w,_,y,k,S;return regeneratorRuntime.wrap((function _callee2$(T){for(;;)switch(T.prev=T.next){case 0:return k=function _showBrowser(){var e=n("#imgbrowse");if(e.length)n("#imgbrowse_holder").show();else{n("<div id=imgbrowse_holder><div id=imgbrowse class=toolbar_button></div></div>").insertAfter("#svg_docprops"),e=n("#imgbrowse");var t=c.select_lib,r=n("<ul id=imglib_opts>").appendTo(e),i=n('<iframe src="javascript:0"/>').prependTo(e).hide().wrap("<div id=lib_framewrap>"),o=n("<h1>").prependTo(e).text(t).css({position:"absolute",top:0,left:0,width:"100%"}),a=n("<button>"+p.common.cancel+"</button>").appendTo(e).on("click touchend",(function(){n("#imgbrowse_holder").hide()})).css({position:"absolute",top:5,right:-10}),s=n("<span>").css({position:"absolute",top:5,left:10}).appendTo(e),l=n("<button hidden>"+c.show_list+"</button>").appendTo(s).on("click touchend",(function(){i.attr("src","about:blank").hide(),r.show(),o.text(t),l.hide()})).css({"margin-right":5}).hide();n("<select><option value=s>"+c.import_single+"</option><option value=m>"+c.import_multi+"</option><option value=o>"+c.open+"</option></select>").appendTo(s).change((function(){switch(g=n(this).val()){case"s":case"o":y(!1);break;case"m":y(!0)}})).css({"margin-top":10}),a.prepend(n.getSvgIcon("cancel",!0)),l.prepend(n.getSvgIcon("tool_imagelib",!0)),c.imgLibs.forEach((function(e){var t=e.name,a=e.url,s=e.description;n("<li>").appendTo(r).text(t).on("click touchend",(function(){i.attr("src",a).show(),o.text(t),r.hide(),l.show()})).append("<span>".concat(s,"</span>"))}))}},y=function _toggleMulti(e){n("#lib_framewrap, #imglib_opts").css({right:e?200:10}),v||(v=n("<div id=imglib_preview>").css({position:"absolute",top:45,right:10,width:180,bottom:45,background:"#fff",overflow:"auto"}).insertAfter("#lib_framewrap"),x=n("<button disabled>Import selected</button>").appendTo("#imgbrowse").on("click touchend",(function(){n.each(h,(function(e){var t=this[0],r=this[1];"svg"===t?l.importSvgString(r):b(r),l.moveSelectedElements(20*e,20*e,!1)})),v.empty(),h=[],n("#imgbrowse_holder").hide()})).css({position:"absolute",bottom:10,right:-10})),v.toggle(e),x.toggle(e)},_=function _onMessage3(){return(_=_asyncToGenerator(regeneratorRuntime.mark((function _callee(e){var t,r,s,c,w,_,y,k,S,T,A,E,B,G,I,L,R;return regeneratorRuntime.wrap((function _callee$(j){for(;;)switch(j.prev=j.next){case 0:if(t=e.origin,(r=e.data)&&["string","object"].includes(_typeof(r))){j.next=3;break}return j.abrupt("return");case 3:if(j.prev=3,"imagelib"===(r="object"===_typeof(r)?r:JSON.parse(r)).namespace){j.next=7;break}return j.abrupt("return");case 7:if(u.includes("*")||u.includes(t)){j.next=10;break}return console.log("Origin ".concat(t," not whitelisted for posting to ").concat(window.origin)),j.abrupt("return");case 10:if(_="href"in r,(w="name"in r)||!f){j.next=15;break}return f=!1,j.abrupt("return");case 15:_&&(s=r.href,r=r.data),n("#dialog_box").hide(),c=w?"meta":r.charAt(0),j.next=28;break;case 20:if(j.prev=20,j.t0=j.catch(3),"string"!=typeof r){j.next=28;break}if("{"===(y=r.charAt(0))||!f){j.next=27;break}return f=!1,j.abrupt("return");case 27:"|"===y&&(k=r.indexOf("|",1),s=r.substr(1,k-1),r=r.substr(k+1),c=r.charAt(0));case 28:j.t1=c,j.next="meta"===j.t1?31:"<"===j.t1?47:"d"===j.t1?49:60;break;case 31:if(f=!1,m[(T=r).id]=T,B=T.name||"file",G=p.notification.retrieving.replace("%s",B),"m"===g){j.next=43;break}return j.next=39,n.process_cancel(G);case 39:f=!0,n("#dialog_box").hide(),j.next=46;break;case 43:S=n("<div>").text(G).data("id",T.id),v.append(S),T.entry=S;case 46:return j.abrupt("return");case 47:return A=!0,j.abrupt("break",62);case 49:if(!r.startsWith("data:image/svg+xml")){j.next=57;break}return"data:image/svg+xml;base64,",I=r.substring("data:image/svg+xml;base64,".length),r=i(I),A=!0,j.abrupt("break",62);case 57:if(!r.startsWith("data:image/")){j.next=60;break}return E=!0,j.abrupt("break",62);case 60:return"m