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

11 lines
4.0 KiB
JavaScript

System.register([],(function(e){"use strict";return{execute:function(){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,i=o instanceof _AwaitValue;Promise.resolve(i?o.wrapped:o).then((function(e){i?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,i){var a={key:e,arg:r,resolve:o,reject:i,next:null};n?n=n.next=a:(t=n=a,resume(e,r))}))},"function"!=typeof e.return&&(this.return=void 0)}function asyncGeneratorStep(e,t,n,r,o,i,a){try{var s=e[i](a),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
*
*/
e("default",{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 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)}))}}(regeneratorRuntime.mark((function _callee(){var n,r,o,i,a,s,c,u,l,d,p,h,v,g,f,m,y,w,_,b,x,G;return regeneratorRuntime.wrap((function _callee$(S){for(;;)switch(S.prev=S.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 i=d.getContext("2d"),a=.5,u=o/10;i.globalAlpha=.2,i.strokeStyle=s.curConfig.gridColor;for(var l=1;l<10;l++){var p=Math.round(u*l)+.5;i.moveTo(p,o),i.lineTo(p,0),i.moveTo(o,p),i.lineTo(0,p)}i.stroke(),i.beginPath(),i.globalAlpha=.5,i.moveTo(a,o),i.lineTo(a,0),i.moveTo(o,a),i.lineTo(0,a),i.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,i=e.importLocale,S.next=5,i();case 5:return a=S.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()}}}],S.abrupt("return",{name:a.name,svgicons:"grid-icon.xml",zoomChanged:function zoomChanged(e){g&&b(e)},callback:function callback(){g&&x()},buttons:a.buttons.map((function(e,t){return Object.assign(G[t],e)}))});case 27:case"end":return S.stop()}}),_callee)})))()}})}}}));