svgedit/dist/editor/extensions/ext-eyedropper/ext-eyedropper.js.map

1 line
6.9 KiB
Plaintext
Raw Normal View History

2020-09-06 06:32:10 +00:00
{"version":3,"file":"ext-eyedropper.js","sources":["../../../../src/editor/extensions/ext-eyedropper/ext-eyedropper.js"],"sourcesContent":["/**\n * @file ext-eyedropper.js\n *\n * @license MIT\n *\n * @copyright 2010 Jeff Schiller\n *\n */\n\nexport default {\n name: 'eyedropper',\n async init (S) {\n const svgEditor = this;\n // eslint-disable-next-line node/no-unsupported-features/es-syntax\n const {default: strings} = await import(`./locale/${svgEditor.curPrefs.lang}.js`);\n const {$, ChangeElementCommand} = S, // , svgcontent,\n // svgdoc = S.svgroot.parentNode.ownerDocument,\n svgCanvas = svgEditor.canvas,\n addToHistory = function (cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); },\n currentStyle = {\n fillPaint: 'red', fillOpacity: 1.0,\n strokePaint: 'black', strokeOpacity: 1.0,\n strokeWidth: 5, strokeDashArray: null,\n opacity: 1.0,\n strokeLinecap: 'butt',\n strokeLinejoin: 'miter'\n };\n\n /**\n *\n * @param {module:svgcanvas.SvgCanvas#event:ext_selectedChanged|module:svgcanvas.SvgCanvas#event:ext_elementChanged} opts\n * @returns {void}\n */\n function 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 = $('#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.removeClass('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.addClass('disabled');\n }\n }\n\n const buttons = [\n {\n id: 'tool_eyedropper',\n icon: 'eyedropper.png',\n type: 'mode',\n events: {\n click () {\n svgCanvas.setMode('eyedropper');\n }\n }\n }\n ];\n\n return {\n name: strings.name,\n svgicons: 'eyedropper-icon.xml',\n buttons: strings.buttons.map((button, i) => {\n return Object.assign(buttons[i], button);\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\n mouseDown (opts) {\n const mode = svgCanvas.getMode();\n if (mode === 'eyedropper') {\n const e = opts.event;\n const {target} = e;\n if (!['svg', 'g', 'use'].includes(target.nodeName)) {\n const changes = {};\n\n const change = function (elem, attrname, newvalue) {\n changes[attrname] = elem.getAttribute(attrname);\n elem.setAttribute(attrname, newvalue);\n };\n\n if (currentStyle.fillPaint) { change(target, 'fill', currentStyle.fillPaint); }\n if (currentStyle.fillOpacity) { change(target, 'fill-opacity', currentStyle.fillOpacity); }\n if (currentStyle.strokePaint) { change(target, 'stroke', currentStyle.strokePaint); }\n if (currentStyle.strokeOpacity) { change(target, 'stroke-opacity', currentStyle.strokeOpacity); }\n if (currentStyle.strokeWidth) { change(target, 'stroke-width', currentStyle.strokeWidt