svgedit/dist/editor/extensions/ext-grid.js

12 lines
3.9 KiB
JavaScript

function _AwaitValue(e){this.wrapped=e}function _AsyncGenerator(e){var t,n;function resume(t,n){try{var r=e[t](n),o=r.value,a=o instanceof _AwaitValue;Promise.resolve(a?o.wrapped:o).then((function(e){a?resume("return"===t?"return":"next",e):settle(r.done?"return":"normal",e)}),(function(e){resume("throw",e)}))}catch(e){settle("throw",e)}}function settle(e,r){switch(e){case"return":t.resolve({value:r,done:!0});break;case"throw":t.reject(r);break;default:t.resolve({value:r,done:!1})}(t=t.next)?resume(t.key,t.arg):n=null}this._invoke=function send(e,r){return new Promise((function(o,a){var i={key:e,arg:r,resolve:o,reject:a,next:null};n?n=n.next=i:(t=n=i,resume(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}"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-grid.js
*
* @license Apache-2.0
*
* @copyright 2010 Redou Mine, 2010 Alexis Deveria
*
*/
var e={name:"grid",init:function init(e){var t=this;return function _asyncToGenerator(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function _next(e){asyncGeneratorStep(a,r,o,_next,_throw,"next",e)}function _throw(e){asyncGeneratorStep(a,r,o,_next,_throw,"throw",e)}_next(void 0)}))}}(regeneratorRuntime.mark((function _callee(){var n,r,o,a,i,s,c,u,l,d,p,h,v,g,f,m,y,w,_,b,x,G;return regeneratorRuntime.wrap((function _callee$(k){for(;;)switch(k.prev=k.next){case 0:return x=function _gridUpdate(){g&&b(c.getZoom()),n("#canvasGrid").toggle(g),n("#view_grid").toggleClass("push_button_pressed tool_button")},b=function _updateGrid(e){var t=h[s.curConfig.baseUnit]*e,n=100/t,r=1;v.some((function(e){return r=e,n<=e}));var o=r*t;d.width=o,d.height=o;var a=d.getContext("2d"),i=.5,u=o/10;a.globalAlpha=.2,a.strokeStyle=s.curConfig.gridColor;for(var l=1;l<10;l++){var p=Math.round(u*l)+.5;a.moveTo(p,o),a.lineTo(p,0),a.moveTo(o,p),a.lineTo(0,p)}a.stroke(),a.beginPath(),a.globalAlpha=.5,a.moveTo(i,o),a.lineTo(i,0),a.moveTo(o,i),a.lineTo(0,i),a.stroke();var g=d.toDataURL("image/png");w.setAttribute("width",o),w.setAttribute("height",o),w.parentNode.setAttribute("width",o),w.parentNode.setAttribute("height",o),c.setHref(w,g)},n=e.$,r=e.NS,o=e.getTypeMap,a=e.importLocale,k.next=5,a();case 5:return i=k.sent,c=(s=t).canvas,u=document.getElementById("svgcanvas").ownerDocument,l=c.assignAttributes,d=document.createElement("canvas"),p=n("#canvasBackground"),h=o(),v=[.01,.1,1,10,100,1e3],g=s.curConfig.showGrid||!1,n(d).hide().appendTo("body"),f=u.createElementNS(r.SVG,"svg"),l(f,{id:"canvasGrid",width:"100%",height:"100%",x:0,y:0,overflow:"visible",display:"none"}),p.append(f),m=u.createElementNS(r.SVG,"defs"),y=u.createElementNS(r.SVG,"pattern"),l(y,{id:"gridpattern",patternUnits:"userSpaceOnUse",x:0,y:0,width:100,height:100}),w=u.createElementNS(r.SVG,"image"),l(w,{x:0,y:0,width:100,height:100}),y.append(w),m.append(y),n("#canvasGrid").append(m),_=u.createElementNS(r.SVG,"rect"),l(_,{width:"100%",height:"100%",x:0,y:0,"stroke-width":0,stroke:"none",fill:"url(#gridpattern)",style:"pointer-events: none; display:visible;"}),n("#canvasGrid").append(_),G=[{id:"view_grid",icon:"grid.png",type:"context",panel:"editor_panel",events:{click:function click(){s.curConfig.showGrid=g=!g,x()}}}],k.abrupt("return",{name:i.name,svgicons:"grid-icon.xml",zoomChanged:function zoomChanged(e){g&&b(e)},callback:function callback(){g&&x()},buttons:i.buttons.map((function(e,t){return Object.assign(G[t],e)}))});case 27:case"end":return k.stop()}}),_callee)})))()}};export default e;
//# sourceMappingURL=ext-grid.js.map