antosdk-apps/SVGEdit/svgedit/extensions/ext-grid/ext-grid.js.map

1 line
9.9 KiB
Plaintext
Raw Normal View History

2023-08-17 23:54:41 +02:00
{"version":3,"file":"ext-grid.js","sources":["../../../../src/editor/extensions/ext-grid/ext-grid.js","../../../../src/editor/extensions/ext-grid/locale/en.js","../../../../src/editor/extensions/ext-grid/locale/fr.js","../../../../src/editor/extensions/ext-grid/locale/tr.js","../../../../src/editor/extensions/ext-grid/locale/zh-CN.js"],"sourcesContent":["/**\n * @file ext-grid.js\n *\n * @license Apache-2.0\n *\n * @copyright 2010 Redou Mine, 2010 Alexis Deveria\n *\n */\n\nconst name = 'grid'\n\nconst loadExtensionTranslation = async function (svgEditor) {\n let translationModule\n const lang = svgEditor.configObj.pref('lang')\n try {\n translationModule = await import(`./locale/${lang}.js`)\n } catch (_error) {\n console.warn(`Missing translation (${lang}) for ${name} - using 'en'`)\n translationModule = await import('./locale/en.js')\n }\n svgEditor.i18next.addResourceBundle(lang, name, translationModule.default)\n}\n\nexport default {\n name,\n async init () {\n const svgEditor = this\n await loadExtensionTranslation(svgEditor)\n const { svgCanvas } = svgEditor\n const { $id, $click, NS } = svgCanvas\n const svgdoc = $id('svgcanvas').ownerDocument\n const { assignAttributes } = svgCanvas\n const hcanvas = document.createElement('canvas')\n const canvBG = $id('canvasBackground')\n const units = svgCanvas.getTypeMap() // Assumes prior `init()` call on `units.js` module\n const intervals = [0.01, 0.1, 1, 10, 100, 1000]\n let showGrid = svgEditor.configObj.curConfig.showGrid || false\n\n hcanvas.style.display = 'none'\n svgEditor.$svgEditor.appendChild(hcanvas)\n\n const canvasGrid = svgdoc.createElementNS(NS.SVG, 'svg')\n assignAttributes(canvasGrid, {\n id: 'canvasGrid',\n width: '100%',\n height: '100%',\n x: 0,\n y: 0,\n overflow: 'visible',\n display: 'none'\n })\n canvBG.appendChild(canvasGrid)\n const gridDefs = svgdoc.createElementNS(NS.SVG, 'defs')\n // grid-pattern\n const gridPattern = svgdoc.createElementNS(NS.SVG, 'pattern')\n assignAttributes(gridPattern, {\n id: 'gridpattern',\n patternUnits: 'userSpaceOnUse',\n x: 0, // -(value.strokeWidth / 2), // position for strokewidth\n y: 0, // -(value.strokeWidth / 2), // position for strokewidth\n width: 100,\n height: 100\n })\n\n const gridimg = svgdoc.createElementNS(NS.SVG, 'image')\n assignAttributes(gridimg, {\n x: 0,\n y: 0,\n width: 100,\n height: 100\n })\n gridPattern.append(gridimg)\n gridDefs.append(gridPattern)\n $id('canvasGrid').appendChild(gridDefs)\n\n // grid-box\n const gridBox = svgdoc.createElementNS(NS.SVG, 'rect')\n assignAttributes(gridBox, {\n width: '100%',\n height: '100%',\n x: 0,\n y: 0,\n 'stroke-width': 0,\n stroke: 'none',\n fill: 'url(#gridpattern)',\n style: 'pointer-events: none; display:visible;'\n })\n $id('canvasGrid').appendChild(gridBox)\n\n /**\n *\n * @param {Float} zoom\n * @returns {void}\n */\n const updateGrid = (zoom) => {\n // TODO: Try this with <line> elements, then compare performance difference\n const unit = units[svgEditor.configObj.curConfig.baseUnit] // 1 = 1px\n const uMulti = unit * zoom\n // Calculate the main number interval\n const rawM = 100 / uMulti\n let multi = 1\n intervals.some((num) => {\n multi = num\n return rawM <= num\n })\n const bigInt = multi * uMulti\n\n // Set the canvas size to the width of the container\n hcanvas.width = bigInt\n hcanvas.height = bigInt\n const ctx = hcanvas.getContext('2d')\n const curD = 0.5\n const part = bigInt / 10\n\n ctx.globalAlpha = 0.2\n ctx.strokeStyle = svgEditor.configObj.curConfig.gridColor\n for (let i = 1; i < 10; i++) {\n const subD = Math.round(part * i) + 0.5\n // const lineNum = (i % 2)?12:10;\n const lineNum = 0\n ctx.moveTo(subD, bigInt)\n ctx.lineTo(su