mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-11-16 02:18:22 +01:00
1 line
9.1 KiB
Plaintext
1 line
9.1 KiB
Plaintext
|
{"version":3,"file":"ext-eyedropper.js","sources":["../../../../src/editor/extensions/ext-eyedropper/ext-eyedropper.js","../../../../src/editor/extensions/ext-eyedropper/locale/en.js","../../../../src/editor/extensions/ext-eyedropper/locale/fr.js","../../../../src/editor/extensions/ext-eyedropper/locale/tr.js","../../../../src/editor/extensions/ext-eyedropper/locale/zh-CN.js"],"sourcesContent":["/**\n * @file ext-eyedropper.js\n *\n * @license MIT\n *\n * @copyright 2010 Jeff Schiller\n * @copyright 2021 OptimistikSAS\n *\n */\n\nconst name = 'eyedropper'\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 { svgCanvas } = svgEditor\n await loadExtensionTranslation(svgEditor)\n const { ChangeElementCommand } = svgCanvas.history\n // svgdoc = S.svgroot.parentNode.ownerDocument,\n const addToHistory = (cmd) => { svgCanvas.undoMgr.addCommandToHistory(cmd) }\n const currentStyle = {\n fillPaint: 'red',\n fillOpacity: 1.0,\n strokePaint: 'black',\n strokeOpacity: 1.0,\n strokeWidth: 5,\n strokeDashArray: null,\n opacity: 1.0,\n strokeLinecap: 'butt',\n strokeLinejoin: 'miter'\n }\n const { $id, $click } = svgCanvas\n\n /**\n *\n * @param {module:svgcanvas.SvgCanvas#event:ext_selectedChanged|module:svgcanvas.SvgCanvas#event:ext_elementChanged} opts\n * @returns {void}\n */\n const getStyle = (opts) => {\n // if we are in eyedropper mode, we don't want to disable the eye-dropper tool\n const mode = svgCanvas.getMode()\n if (mode === 'eyedropper') { return }\n\n const tool = $id('tool_eyedropper')\n // enable-eye-dropper if one element is selected\n let elem = null\n if (!opts.multiselected && opts.elems[0] &&\n !['svg', 'g', 'use'].includes(opts.elems[0].nodeName)\n ) {\n elem = opts.elems[0]\n tool.classList.remove('disabled')\n // grab the current style\n currentStyle.fillPaint = elem.getAttribute('fill') || 'black'\n currentStyle.fillOpacity = elem.getAttribute('fill-opacity') || 1.0\n currentStyle.strokePaint = elem.getAttribute('stroke')\n currentStyle.strokeOpacity = elem.getAttribute('stroke-opacity') || 1.0\n currentStyle.strokeWidth = elem.getAttribute('stroke-width')\n currentStyle.strokeDashArray = elem.getAttribute('stroke-dasharray')\n currentStyle.strokeLinecap = elem.getAttribute('stroke-linecap')\n currentStyle.strokeLinejoin = elem.getAttribute('stroke-linejoin')\n currentStyle.opacity = elem.getAttribute('opacity') || 1.0\n // disable eye-dropper tool\n } else {\n tool.classList.add('disabled')\n }\n }\n\n return {\n name: svgEditor.i18next.t(`${name}:name`),\n callback () {\n // Add the button and its handler(s)\n const title = `${name}:buttons.0.title`\n const key = `${name}:buttons.0.key`\n const buttonTemplate = `\n <se-button id=\"tool_eyedropper\" title=\"${title}\" src=\"eye_dropper.svg\" shortcut=${key}></se-button>\n `\n svgCanvas.insertChildAtIndex($id('tools_left'), buttonTemplate, 12)\n $click($id('tool_eyedropper'), () => {\n if (this.leftPanel.updateLeftPanel('tool_eyedropper')) {\n svgCanvas.setMode('eyedropper')\n }\n })\n },\n // if we have selected an element, grab its paint and enable the eye dropper button\n selectedChanged: getStyle,\n elementChanged: getStyle,\n mouseDown (opts) {\n const mode = svgCanvas.getMode()\n if (mode === '
|