{"version":3,"file":"ext-helloworld.js","sources":["../../../src/editor/extensions/ext-helloworld.js"],"sourcesContent":["/**\n * @file ext-helloworld.js\n *\n * @license MIT\n *\n * @copyright 2010 Alexis Deveria\n *\n */\n\n/**\n* This is a very basic SVG-Edit extension. It adds a \"Hello World\" button in\n* the left (\"mode\") panel. Clicking on the button, and then the canvas\n* will show the user the point on the canvas that was clicked on.\n*/\nexport default {\n name: 'helloworld',\n async init ({$, importLocale}) {\n // See `/editor/extensions/ext-locale/helloworld/`\n const strings = await importLocale();\n const svgEditor = this;\n const svgCanvas = svgEditor.canvas;\n return {\n name: strings.name,\n // For more notes on how to make an icon file, see the source of\n // the helloworld-icon.xml\n svgicons: 'helloworld-icon.xml',\n\n // Multiple buttons can be added in this array\n buttons: [{\n // Must match the icon ID in helloworld-icon.xml\n id: 'hello_world',\n\n // Fallback, e.g., for `file:///` access\n icon: 'helloworld.png',\n\n // This indicates that the button will be added to the \"mode\"\n // button panel on the left side\n type: 'mode',\n\n // Tooltip text\n title: strings.buttons[0].title,\n\n // Events\n events: {\n click () {\n // The action taken when the button is clicked on.\n // For \"mode\" buttons, any other button will\n // automatically be de-pressed.\n svgCanvas.setMode('hello_world');\n }\n }\n }],\n // This is triggered when the main mouse button is pressed down\n // on the editor canvas (not the tool panels)\n mouseDown () {\n // Check the mode on mousedown\n if (svgCanvas.getMode() === 'hello_world') {\n // The returned object must include \"started\" with\n // a value of true in order for mouseUp to be triggered\n return {started: true};\n }\n return undefined;\n },\n\n // This is triggered from anywhere, but \"started\" must have been set\n // to true (see above). Note that \"opts\" is an object with event info\n mouseUp (opts) {\n // Check the mode on mouseup\n if (svgCanvas.getMode() === 'hello_world') {\n const zoom = svgCanvas.getZoom();\n\n // Get the actual coordinate by dividing by the zoom value\n const x = opts.mouse_x / zoom;\n const y = opts.mouse_y / zoom;\n\n // We do our own formatting\n let {text} = strings;\n [\n ['x', x],\n ['y', y]\n ].forEach(([prop, val]) => {\n text = text.replace('{' + prop + '}', val);\n });\n\n // Show the text using the custom alert function\n $.alert(text);\n }\n }\n };\n }\n};\n"],"names":["name","init","$","importLocale","strings","svgCanvas","_this","canvas","svgicons","buttons","id","icon","type","title","events","click","setMode","mouseDown","getMode","started","mouseUp","opts","zoom","getZoom","x","mouse_x","y","mouse_y","text","forEach","prop","val","replace","alert"],"mappings":";;;;;;;;;AAcA,MAAe,CACbA,KAAM,aACAC,qdAAOC,IAAAA,EAAGC,IAAAA,sBAEQA,kBAAhBC,SAEAC,EADYC,EACUC,yBACrB,CACLP,KAAMI,EAAQJ,KAGdQ,SAAU,sBAGVC,QAAS,CAAC,CAERC,GAAI,cAGJC,KAAM,iBAINC,KAAM,OAGNC,MAAOT,EAAQK,QAAQ,GAAGI,MAG1BC,OAAQ,CACNC,uBAIEV,EAAUW,QAAQ,mBAMxBC,kCAE8B,gBAAxBZ,EAAUa,gBAGL,CAACC,SAAS,IAOrBC,yBAASC,MAEqB,gBAAxBhB,EAAUa,UAA6B,KACnCI,EAAOjB,EAAUkB,UAGjBC,EAAIH,EAAKI,QAAUH,EACnBI,EAAIL,EAAKM,QAAUL,EAGpBM,EAAQxB,EAARwB,MAEH,CAAC,IAAKJ,GACN,CAAC,IAAKE,IACNG,SAAQ,sCAAEC,OAAMC,OAChBH,EAAOA,EAAKI,QAAQ,IAAMF,EAAO,IAAKC,MAIxC7B,EAAE+B,MAAML"}