/**
 * @file ext-grid.js
 *
 * @license Apache-2.0
 *
 * @copyright 2010 Redou Mine, 2010 Alexis Deveria
 *
 */
const e="grid",loadExtensionTranslation=async function(t){let c;const u=t.configObj.pref("lang");try{c=await function __variableDynamicImportRuntime0__(e){switch(e){case"./locale/en.js":return Promise.resolve().then((function(){return n}));case"./locale/fr.js":return Promise.resolve().then((function(){return o}));case"./locale/pl.js":return Promise.resolve().then((function(){return r}));case"./locale/sv.js":return Promise.resolve().then((function(){return i}));case"./locale/tr.js":return Promise.resolve().then((function(){return a}));case"./locale/uk.js":return Promise.resolve().then((function(){return s}));case"./locale/zh-CN.js":return Promise.resolve().then((function(){return l}));default:return new Promise((function(t,n){("function"==typeof queueMicrotask?queueMicrotask:setTimeout)(n.bind(null,new Error("Unknown variable dynamic import: "+e)))}))}}(`./locale/${u}.js`)}catch(t){console.warn(`Missing translation (${u}) for ${e} - using 'en'`),c=await Promise.resolve().then((function(){return n}))}t.i18next.addResourceBundle(u,e,c.default)};var t={name:e,async init(){const t=this;await loadExtensionTranslation(t);const{svgCanvas:n}=t,{$id:o,$click:r,NS:i}=n,a=o("svgcanvas").ownerDocument,{assignAttributes:s}=n,l=document.createElement("canvas"),c=o("canvasBackground"),u=n.getTypeMap(),d=[.01,.1,1,10,100,1e3];let f=t.configObj.curConfig.showGrid||!1;l.style.display="none",t.$svgEditor.appendChild(l);const h=a.createElementNS(i.SVG,"svg");s(h,{id:"canvasGrid",width:"100%",height:"100%",x:0,y:0,overflow:"visible",display:"none"}),c.appendChild(h);const p=a.createElementNS(i.SVG,"defs"),g=a.createElementNS(i.SVG,"pattern");s(g,{id:"gridpattern",patternUnits:"userSpaceOnUse",x:0,y:0,width:100,height:100});const m=a.createElementNS(i.SVG,"image");s(m,{x:0,y:0,width:100,height:100}),g.append(m),p.append(g),o("canvasGrid").appendChild(p);const b=a.createElementNS(i.SVG,"rect");s(b,{width:"100%",height:"100%",x:0,y:0,"stroke-width":0,stroke:"none",fill:"url(#gridpattern)",style:"pointer-events: none; display:visible;"}),o("canvasGrid").appendChild(b);const updateGrid=e=>{const o=u[t.configObj.curConfig.baseUnit]*e,r=100/o;let i=1;d.some((e=>(i=e,r<=e)));const a=i*o;l.width=a,l.height=a;const s=l.getContext("2d"),c=.5,f=a/10;s.globalAlpha=.2,s.strokeStyle=t.configObj.curConfig.gridColor;for(let e=1;e<10;e++){const t=Math.round(f*e)+.5,n=0;s.moveTo(t,a),s.lineTo(t,n),s.moveTo(a,t),s.lineTo(n,t)}s.stroke(),s.beginPath(),s.globalAlpha=.5,s.moveTo(c,a),s.lineTo(c,0),s.moveTo(a,c),s.lineTo(0,c),s.stroke();const h=l.toDataURL("image/png");m.setAttribute("width",a),m.setAttribute("height",a),m.parentNode.setAttribute("width",a),m.parentNode.setAttribute("height",a),n.setHref(m,h)},gridUpdate=()=>{f&&updateGrid(n.getZoom()),o("canvasGrid").style.display=f?"block":"none",o("view_grid").pressed=f};return{name:t.i18next.t(`${e}:name`),zoomChanged(e){f&&updateGrid(e)},callback(){const n=document.createElement("template"),i=`${e}:buttons.0.title`;n.innerHTML=`\n          <se-button id="view_grid" title="${i}" src="grid.svg"></se-button>\n        `,o("editor_panel").append(n.content.cloneNode(!0)),r(o("view_grid"),(()=>{t.configObj.curConfig.showGrid=f=!f,gridUpdate()})),f&&gridUpdate()}}}},n=Object.freeze({__proto__:null,default:{name:"View Grid",buttons:[{title:"Show/Hide Grid"}]}}),o=Object.freeze({__proto__:null,default:{name:"Grille",buttons:[{title:"Afficher/Cacher Grille"}]}}),r=Object.freeze({__proto__:null,default:{name:"Widok siatki",buttons:[{title:"Pokaż/Ukryj siatkę"}]}}),i=Object.freeze({__proto__:null,default:{name:"Visa rutnät",buttons:[{title:"Visa/dölj rutnät"}]}}),a=Object.freeze({__proto__:null,default:{name:"Izgarayı Görüntüle",buttons:[{title:"Izgara Göster/Gizle"}]}}),s=Object.freeze({__proto__:null,default:{name:"Сітка",buttons:[{title:"Показати/Заковати Сітку"}]}}),l=Object.freeze({__proto__:null,default:{name:"网格视图",buttons:[{title:"显示/隐藏网格"}]}});export{t as default};
//# sourceMappingURL=ext-grid.js.map
