{"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.strokeWidth); }\n if (currentStyle.strokeDashArray) { change(target, 'stroke-dasharray', currentStyle.strokeDashArray); }\n if (currentStyle.opacity) { change(target, 'opacity', currentStyle.opacity); }\n if (currentStyle.strokeLinecap) { change(target, 'stroke-linecap', currentStyle.strokeLinecap); }\n if (currentStyle.strokeLinejoin) { change(target, 'stroke-linejoin', currentStyle.strokeLinejoin); }\n\n addToHistory(new ChangeElementCommand(target, changes));\n }\n }\n }\n };\n }\n};\n"],"names":["name","init","S","getStyle","opts","svgCanvas","getMode","tool","$","elem","multiselected","elems","includes","nodeName","addClass","removeClass","currentStyle","fillPaint","getAttribute","fillOpacity","strokePaint","strokeOpacity","strokeWidth","strokeDashArray","strokeLinecap","strokeLinejoin","opacity","svgEditor","_this","import","curPrefs","lang","strings","ChangeElementCommand","canvas","addToHistory","cmd","undoMgr","addCommandToHistory","buttons","id","icon","type","events","click","setMode","svgicons","map","button","i","Object","assign","selectedChanged","elementChanged","mouseDown","target","event","changes","change","attrname","newvalue","setAttribute"],"mappings":";;;;;;;;;AASA,MAAe,CACbA,KAAM,aACAC,mBAAMC,0WAsBDC,oGAAAA,qBAAUC,MAGJ,eADAC,EAAUC,eAGjBC,EAAOC,EAAE,oBAEXC,EAAO,KACNL,EAAKM,gBAAiBN,EAAKO,MAAM,IACnC,CAAC,MAAO,IAAK,OAAOC,SAASR,EAAKO,MAAM,GAAGE,UAgB5CN,EAAKO,SAAS,aAddL,EAAOL,EAAKO,MAAM,GAClBJ,EAAKQ,YAAY,YAEjBC,EAAaC,UAAYR,EAAKS,aAAa,SAAW,QACtDF,EAAaG,YAAcV,EAAKS,aAAa,iBAAmB,EAChEF,EAAaI,YAAcX,EAAKS,aAAa,UAC7CF,EAAaK,cAAgBZ,EAAKS,aAAa,mBAAqB,EACpEF,EAAaM,YAAcb,EAAKS,aAAa,gBAC7CF,EAAaO,gBAAkBd,EAAKS,aAAa,oBACjDF,EAAaQ,cAAgBf,EAAKS,aAAa,kBAC/CF,EAAaS,eAAiBhB,EAAKS,aAAa,mBAChDF,EAAaU,QAAUjB,EAAKS,aAAa,YAAc,KA3CrDS,EAAYC,WAEeC,0BAAmBF,EAAUG,SAASC,oCAAvDC,YACTxB,EAA2BN,EAA3BM,EAAGyB,EAAwB/B,EAAxB+B,qBAER5B,EAAYsB,EAAUO,OACtBC,EAAe,SAAfA,aAAyBC,GAAO/B,EAAUgC,QAAQC,oBAAoBF,IACtEpB,EAAe,CACbC,UAAW,MAAOE,YAAa,EAC/BC,YAAa,QAASC,cAAe,EACrCC,YAAa,EAAGC,gBAAiB,KACjCG,QAAS,EACTF,cAAe,OACfC,eAAgB,SAqCdc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