mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-08 14:38:28 +01:00
1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
|
{"version":3,"file":"ext-shapes.js","sources":["../../../../src/editor/extensions/ext-shapes/ext-shapes.js","../../../../src/editor/extensions/ext-shapes/locale/en.js","../../../../src/editor/extensions/ext-shapes/locale/fr.js","../../../../src/editor/extensions/ext-shapes/locale/tr.js","../../../../src/editor/extensions/ext-shapes/locale/zh-CN.js"],"sourcesContent":["/**\n * @file ext-shapes.js\n *\n * @license MIT\n *\n * @copyright 2010 Christian Tzurcanu, 2010 Alexis Deveria\n *\n */\nconst name = 'shapes'\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 const canv = svgEditor.svgCanvas\n const { $id, $click } = canv\n const svgroot = canv.getSvgRoot()\n let lastBBox = {}\n await loadExtensionTranslation(svgEditor)\n\n const modeId = 'shapelib'\n const startClientPos = {}\n\n let curShape\n let startX\n let startY\n\n return {\n callback () {\n if ($id('tool_shapelib') === null) {\n const extPath = svgEditor.configObj.curConfig.extPath\n const buttonTemplate = `\n <se-explorerbutton id=\"tool_shapelib\" title=\"${svgEditor.i18next.t(`${name}:buttons.0.title`)}\" lib=\"${extPath}/ext-shapes/shapelib/\"\n src=\"shapelib.svg\"></se-explorerbutton>\n `\n canv.insertChildAtIndex($id('tools_left'), buttonTemplate, 9)\n $click($id('tool_shapelib'), () => {\n if (this.leftPanel.updateLeftPanel('tool_shapelib')) {\n canv.setMode(modeId)\n }\n })\n }\n },\n mouseDown (opts) {\n const mode = canv.getMode()\n if (mode !== modeId) { return undefined }\n\n const currentD = document.getElementById('tool_shapelib').dataset.draw\n startX = opts.start_x\n const x = startX\n startY = opts.start_y\n const y = startY\n const curStyle = canv.getStyle()\n\n startClientPos.x = opts.event.clientX\n startClientPos.y = opts.event.clientY\n\n curShape = canv.addSVGElementsFromJson({\n element: 'path',\n curStyles: true,\n attr: {\n d: currentD,\n id: canv.getNextId(),\n opacity: curStyle.opacity / 2,\n style: 'pointer-events:none'\n }\n })\n\n curShape.setAttribute('transform', 'translate(' + x + ',' + y + ') scale(0.005) translate(' + -x + ',' + -y + ')')\n\n canv.recalculateDimensions(curShape)\n\n lastBBox = curShape.getBBox()\n\n return {\n started: true\n }\n },\n mouseMove (opts) {\n const mode = canv.getMode()\n if (mode !== modeId) { return }\n\n const zoom = canv.getZoom()\n const evt = opts.event\n\n const x = opts.mouse_x / zoom\n const y = opts.mouse_y / zoom\n\n const tlist = curShape.transform.baseVal\n const box = curShape.getBBox()\n const left = box.x; const top = box.y\n\n const newbox = {\n x: Math.min(startX, x),\n y: Math.min(startY, y),\n width: Math.abs(x - startX),\n height: Math.abs(y - startY)\n }\n\n let sx = (newbox.width / lastBBox.width) || 1\n let sy = (newbox.height / lastBBox.height) || 1\n\n // Not perfect, but mostly works...\n let tx = 0\n if (x < startX) {\n tx = lastBBox.width\n }\n let ty = 0\n if (y < startY) {\n ty = lastBBox.height\n }\n\n // update the transform list with translate,scale,translate\n const translateOrigin = svgroot.createSVGTransform
|