Files
svgedit/dist/editor/extensions/ext-foreignobject/ext-foreignobject.js
2020-09-06 08:32:10 +02:00

11 lines
5.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function asyncGeneratorStep(e,t,n,r,o,i,a){try{var c=e[i](a),s=c.value}catch(e){return void n(e)}c.done?t(s):Promise.resolve(s).then(r,o)}function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var i=e.apply(t,n);function _next(e){asyncGeneratorStep(i,r,o,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(i,r,o,_next,_throw,"throw",e)}_next(void 0)}))}}
/**
* @file ext-foreignobject.js
*
* @license Apache-2.0
*
* @copyright 2010 Jacques Distler, 2010 Alexis Deveria
*
*/var e={name:"foreignobject",init:function init(e){var t=this;return _asyncToGenerator(regeneratorRuntime.mark((function _callee2(){var n,r,o,i,a,c,s,l,u,g,f,_,d,h,v,p,m,b,x,y;return regeneratorRuntime.wrap((function _callee2$(w){for(;;)switch(w.prev=w.next){case 0:return b=function _setAttr(e,t){a.changeSelectedAttribute(e,t),a.call("changed",_)},m=function _showForeignEditor(){var e=_[0];if(e&&!v){v=!0,f(!0),e.removeAttribute("fill");var t=a.svgToString(e,0);r("#svg_source_textarea").val(t),r("#svg_source_editor").fadeIn(),u(),r("#svg_source_textarea").focus()}},p=function _setForeignString(e){var t=_[0];try{var n=o('<svg xmlns="'+i.SVG+'" xmlns:xlink="'+i.XLINK+'">'+e+"</svg>");a.sanitizeSvg(n.documentElement),t.replaceWith(c.importNode(n.documentElement.firstChild,!0)),a.call("changed",[t]),a.clearSelection()}catch(e){return console.log(e),!1}return!0},f=function _toggleSourceButtons(e){r("#tool_source_save, #tool_source_cancel").toggle(!e),r("#foreign_save, #foreign_cancel").toggle(e)},g=function _showPanel(e){var t=r("#fc_rules");t.length||(t=r('<style id="fc_rules"></style>').appendTo("head")),t.text(e?" #tool_topath { display: none !important; }":""),r("#foreignObject_panel").toggle(e)},n=t,r=e.$,o=e.text2xml,i=e.NS,a=n.canvas,c=e.svgroot.parentNode.ownerDocument,w.next=11,import("./locale/".concat(n.curPrefs.lang,".js"));case 11:return s=w.sent,l=s.default,u=function properlySourceSizeTextArea(){var e=r("#svg_source_container").height()-80;r("#svg_source_textarea").css("height",e)},v=!1,x=[{id:"tool_foreign",icon:"foreignobject-tool.png",type:"mode",events:{click:function click(){a.setMode("foreign")}}},{id:"edit_foreign",icon:"foreignobject-edit.png",type:"context",panel:"foreignObject_panel",events:{click:function click(){m()}}}],y=[{type:"input",panel:"foreignObject_panel",id:"foreign_width",size:3,events:{change:function change(){b("width",this.value)}}},{type:"input",panel:"foreignObject_panel",id:"foreign_height",events:{change:function change(){b("height",this.value)}}},{type:"input",panel:"foreignObject_panel",id:"foreign_font_size",size:2,defval:16,events:{change:function change(){b("font-size",this.value)}}}],w.abrupt("return",{name:l.name,svgicons:"foreignobject-icons.xml",buttons:l.buttons.map((function(e,t){return Object.assign(x[t],e)})),context_tools:l.contextTools.map((function(e,t){return Object.assign(y[t],e)})),callback:function callback(){r("#foreignObject_panel").hide();var e=function endChanges(){r("#svg_source_editor").hide(),v=!1,r("#svg_source_textarea").blur(),f(!1)};setTimeout((function(){r("#tool_source_save").clone().hide().attr("id","foreign_save").unbind().appendTo("#tool_source_back").click(_asyncToGenerator(regeneratorRuntime.mark((function _callee(){return regeneratorRuntime.wrap((function _callee$(t){for(;;)switch(t.prev=t.next){case 0:if(v){t.next=2;break}return t.abrupt("return");case 2:if(p(r("#svg_source_textarea").val())){t.next=11;break}return t.next=5,r.confirm("Errors found. Revert to original?");case 5:if(t.sent){t.next=8;break}return t.abrupt("return");case 8:e(),t.next=12;break;case 11:e();case 12:case"end":return t.stop()}}),_callee)})))),r("#tool_source_cancel").clone().hide().attr("id","foreign_cancel").unbind().appendTo("#tool_source_back").click((function(){e()}))}),3e3)},mouseDown:function mouseDown(e){if("foreign"===a.getMode()){d=!0,h=a.addSVGElementFromJson({element:"foreignObject",attr:{x:e.start_x,y:e.start_y,id:a.getNextId(),"font-size":16,width:"48",height:"20",style:"pointer-events:inherit"}});var t=c.createElementNS(i.MATH,"math");t.setAttributeNS(i.XMLNS,"xmlns",i.MATH),t.setAttribute("display","inline");var n=c.createElementNS(i.MATH,"mi");n.setAttribute("mathvariant","normal"),n.textContent="Φ";var r=c.createElementNS(i.MATH,"mo");r.textContent="";var o=c.createElementNS(i.MATH,"mi");return o.textContent="",t.append(n,r,o),h.append(t),{started:!0}}},mouseUp:function mouseUp(e){if("foreign"===a.getMode()&&d){var t=r(h).attr(["width","height"]),n="0"!==t.width||"0"!==t.height;return a.addToSelection([h],!0),{keep:n,element:h}}},selectedChanged:function selectedChanged(e){for(var t=(_=e.elems).length;t--;){var n=_[t];n&&"foreignObject"===n.tagName&&e.selectedElement&&!e.multiselected?(r("#foreign_font_size").val(n.getAttribute("font-size")),r("#foreign_width").val(n.getAttribute("width")),r("#foreign_height").val(n.getAttribute("height")),g(!0)):g(!1)}},elementChanged:function elementChanged(e){}});case 18:case"end":return w.stop()}}),_callee2)})))()}};export default e;
//# sourceMappingURL=ext-foreignobject.js.map