11 lines
9.3 KiB
JavaScript
11 lines
9.3 KiB
JavaScript
System.register([],(function(e){"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 _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,r;function resume(t,r){try{var n=e[t](r),o=n.value,i=o instanceof _AwaitValue;Promise.resolve(i?o.wrapped:o).then((function(e){i?resume("return"===t?"return":"next",e):settle(n.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,n){switch(e){case"return":t.resolve({value:n,done:!0});break;case"throw":t.reject(n);break;default:t.resolve({value:n,done:!1})}(t=t.next)?resume(t.key,t.arg):r=null}this._invoke=function send(e,n){return new Promise((function(o,i){var a={key:e,arg:n,resolve:o,reject:i,next:null};r?r=r.next=a:(t=r=a,resume(e,n))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function _next(e){asyncGeneratorStep(i,n,o,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(i,n,o,_next,_throw,"throw",e)}_next(void 0)}))}}"function"==typeof Symbol&&Symbol.asyncIterator&&(_AsyncGenerator.prototype[Symbol.asyncIterator]=function(){return this}),_AsyncGenerator.prototype.next=function(e){return this._invoke("next",e)},_AsyncGenerator.prototype.throw=function(e){return this._invoke("throw",e)},_AsyncGenerator.prototype.return=function(e){return this._invoke("return",e)};
|
|
/**
|
|
* @file ext-imagelib.js
|
|
*
|
|
* @license MIT
|
|
*
|
|
* @copyright 2010 Alexis Deveria
|
|
*
|
|
*/
|
|
e("default",{name:"imagelib",init:function init(e){var t=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var r,n,o,i,a,s,c,u,p,l,d,m,b,g,h,f,v,w,x,_,y,k,S;return regeneratorRuntime.wrap((function _callee2$(A){for(;;)switch(A.prev=A.next){case 0:return k=function _showBrowser(){var e=r("#imgbrowse");if(e.length)r("#imgbrowse_holder").show();else{r("<div id=imgbrowse_holder><div id=imgbrowse class=toolbar_button></div></div>").insertAfter("#svg_docprops"),e=r("#imgbrowse");var t=a.select_lib,n=r("<ul id=imglib_opts>").appendTo(e),o=r('<iframe src="javascript:0"/>').prependTo(e).hide().wrap("<div id=lib_framewrap>"),i=r("<h1>").prependTo(e).text(t).css({position:"absolute",top:0,left:0,width:"100%"}),s=r("<button>"+u.common.cancel+"</button>").appendTo(e).on("click touchend",(function(){r("#imgbrowse_holder").hide()})).css({position:"absolute",top:5,right:-10}),c=r("<span>").css({position:"absolute",top:5,left:10}).appendTo(e),p=r("<button hidden>"+a.show_list+"</button>").appendTo(c).on("click touchend",(function(){o.attr("src","about:blank").hide(),n.show(),i.text(t),p.hide()})).css({"margin-right":5}).hide();r("<select><option value=s>"+a.import_single+"</option><option value=m>"+a.import_multi+"</option><option value=o>"+a.open+"</option></select>").appendTo(c).change((function(){switch(g=r(this).val()){case"s":case"o":y(!1);break;case"m":y(!0)}})).css({"margin-top":10}),s.prepend(r.getSvgIcon("cancel",!0)),p.prepend(r.getSvgIcon("tool_imagelib",!0)),a.imgLibs.forEach((function(e){var t=e.name,a=e.url,s=e.description;r("<li>").appendTo(n).text(t).on("click touchend",(function(){o.attr("src",a).show(),i.text(t),n.hide(),p.show()})).append("<span>".concat(s,"</span>"))}))}},y=function _toggleMulti(e){r("#lib_framewrap, #imglib_opts").css({right:e?200:10}),v||(v=r("<div id=imglib_preview>").css({position:"absolute",top:45,right:10,width:180,bottom:45,background:"#fff",overflow:"auto"}).insertAfter("#lib_framewrap"),w=r("<button disabled>Import selected</button>").appendTo("#imgbrowse").on("click touchend",(function(){r.each(h,(function(e){var t=this[0],r=this[1];"svg"===t?p.importSvgString(r):m(r),p.moveSelectedElements(20*e,20*e,!1)})),v.empty(),h=[],r("#imgbrowse_holder").hide()})).css({position:"absolute",bottom:10,right:-10})),v.toggle(e),w.toggle(e)},_=function _onMessage3(){return(_=_asyncToGenerator(regeneratorRuntime.mark((function _callee(e){var t,o,a,s,x,_,y,k,S,A,T,E,G,I,L,B,j;return regeneratorRuntime.wrap((function _callee$(P){for(;;)switch(P.prev=P.next){case 0:if(t=e.origin,(o=e.data)&&["string","object"].includes(_typeof(o))){P.next=3;break}return P.abrupt("return");case 3:if(P.prev=3,"imagelib"===(o="object"===_typeof(o)?o:JSON.parse(o)).namespace){P.next=7;break}return P.abrupt("return");case 7:if(l.includes("*")||l.includes(t)){P.next=10;break}return console.log("Origin ".concat(t," not whitelisted for posting to ").concat(window.origin)),P.abrupt("return");case 10:if(_="href"in o,(x="name"in o)||!f){P.next=15;break}return f=!1,P.abrupt("return");case 15:_&&(a=o.href,o=o.data),r("#dialog_box").hide(),s=x?"meta":o.charAt(0),P.next=28;break;case 20:if(P.prev=20,P.t0=P.catch(3),"string"!=typeof o){P.next=28;break}if("{"===(y=o.charAt(0))||!f){P.next=27;break}return f=!1,P.abrupt("return");case 27:"|"===y&&(k=o.indexOf("|",1),a=o.substr(1,k-1),o=o.substr(k+1),s=o.charAt(0));case 28:P.t1=s,P.next="meta"===P.t1?31:"<"===P.t1?47:"d"===P.t1?49:60;break;case 31:if(f=!1,b[(A=o).id]=A,G=A.name||"file",I=u.notification.retrieving.replace("%s",G),"m"===g){P.next=43;break}return P.next=39,r.process_cancel(I);case 39:f=!0,r("#dialog_box").hide(),P.next=46;break;case 43:S=r("<div>").text(I).data("id",A.id),v.append(S),A.entry=S;case 46:return P.abrupt("return");case 47:return T=!0,P.abrupt("break",62);case 49:if(!o.startsWith("data:image/svg+xml")){P.next=57;break}return"data:image/svg+xml;base64,",L=o.substring("data:image/svg+xml;base64,".length),o=n(L),T=!0,P.abrupt("break",62);case 57:if(!o.startsWith("data:image/")){P.next=60;break}return E=!0,P.abrupt("break",62);case 60:return"m"!==g?d():b[a].entry.remove(),P.abrupt("return");case 62:P.t2=g,P.next="s"===P.t2?65:"m"===P.t2?68:"o"===P.t2?72:83;break;case 65:return T?p.importSvgString(o):E&&m(o),d(),P.abrupt("break",83);case 68:return h.push([T?"svg":"img",o]),A=b[a],T?(A&&A.name?B=A.name:(j=(new DOMParser).parseFromString(i(o),"text/xml").documentElement,B=r(j).children("title").first().text()||"(SVG #"+o.length+")"),A?v.children().each((function(){r(this).data("id")===a&&(A.preview_url?r(this).html(r("<span>").append(r("<img>").attr("src",A.preview_url),B)):r(this).text(B),w.removeAttr("disabled"))})):(v.append(r("<div>").text(B)),w.removeAttr("disabled"))):(A&&A.preview_url?(B=A.name||"",S=r("<span>").append(r("<img>").attr("src",A.preview_url),B)):S=r("<img>").attr("src",o),A?v.children().each((function(){r(this).data("id")===a&&(r(this).html(S),w.removeAttr("disabled"))})):(v.append(r("<div>").append(S)),w.removeAttr("disabled"))),P.abrupt("break",83);case 72:if(T){P.next=74;break}return P.abrupt("break",83);case 74:return d(),P.next=77,c.openPrep();case 77:if(P.sent){P.next=80;break}return P.abrupt("return");case 80:return p.clear(),p.setSvgString(o),P.abrupt("break",83);case 83:case"end":return P.stop()}}),_callee,null,[[3,20]])})))).apply(this,arguments)},x=function _onMessage2(e){return _.apply(this,arguments)},m=function _importImage(e){var t=p.addSVGElementFromJson({element:"image",attr:{x:0,y:0,width:0,height:0,id:p.getNextId(),style:"pointer-events:inherit"}});p.clearSelection(),p.addToSelection([t]),p.setImageURL(e)},d=function _closeBrowser(){r("#imgbrowse_holder").hide(),document.activeElement.blur()},r=e.$,n=e.decode64,o=e.importLocale,i=e.dropXMLInternalSubset,A.next=9,o();case 9:return a=A.sent,s=!("svgEditor"in window)||!window.svgEditor||!1!==window.svgEditor.modules,u=(c=t).uiStrings,p=c.canvas,a.imgLibs=a.imgLibs.map((function(e){var t=e.name,r=e.url,n=e.description;return{name:t,url:r=r.replace(/\{modularVersion\}/g,s?a.moduleEnding||"-es":""),description:n}})),l=a.imgLibs.map((function(e){var t=e.url;try{return new URL(t).origin}catch(e){return location.origin}})),b={},g="s",h=[],f=!1,window.addEventListener("message",x,!0),S=[{id:"tool_imagelib",type:"app_menu",icon:"imagelib.png",position:4,events:{mouseup:k}}],A.abrupt("return",{svgicons:"ext-imagelib.xml",buttons:a.buttons.map((function(e,t){return Object.assign(S[t],e)})),callback:function callback(){r("<style>").text("#imgbrowse_holder {position: absolute;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, .5);z-index: 5;}#imgbrowse {position: absolute;top: 25px;left: 25px;right: 25px;bottom: 25px;min-width: 300px;min-height: 200px;background: #B0B0B0;border: 1px outset #777;}#imgbrowse h1 {font-size: 20px;margin: .4em;text-align: center;}#lib_framewrap,#imgbrowse > ul {position: absolute;top: 45px;left: 10px;right: 10px;bottom: 10px;background: white;margin: 0;padding: 0;}#imgbrowse > ul {overflow: auto;}#imgbrowse > div {border: 1px solid #666;}#imglib_preview > div {padding: 5px;font-size: 12px;}#imglib_preview img {display: block;margin: 0 auto;max-height: 100px;}#imgbrowse li {list-style: none;padding: .5em;background: #E8E8E8;border-bottom: 1px solid #B0B0B0;line-height: 1.2em;font-style: sans-serif;}#imgbrowse li > span {color: #666;font-size: 15px;display: block;}#imgbrowse li:hover {background: #FFC;cursor: pointer;}#imgbrowse iframe {width: 100%;height: 100%;border: 0;}").appendTo("head")}});case 22:case"end":return A.stop()}}),_callee2)})))()}})}}}));
|