{"version":3,"file":"ext-polystar.js","sources":["../../../../src/editor/extensions/ext-polystar/ext-polystar.js","../../../../src/editor/extensions/ext-polystar/locale/en.js","../../../../src/editor/extensions/ext-polystar/locale/fr.js","../../../../src/editor/extensions/ext-polystar/locale/tr.js","../../../../src/editor/extensions/ext-polystar/locale/zh-CN.js"],"sourcesContent":["/**\n * @file ext-polystar.js\n *\n *\n * @copyright 2010 CloudCanvas, Inc. All rights reserved\n * @copyright 2021 Optimistik SAS, Inc. All rights reserved\n * @license MIT\n *\n */\n\nconst name = 'polystar'\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 const { ChangeElementCommand } = svgCanvas.history\n const addToHistory = (cmd) => { svgCanvas.undoMgr.addCommandToHistory(cmd) }\n const { $id, $click } = svgCanvas\n let selElems\n let started\n let newFO\n await loadExtensionTranslation(svgEditor)\n\n /**\n * @param {boolean} on true=display\n * @param {string} tool \"star\" or \"polygone\"\n * @returns {void}\n */\n const showPanel = (on, tool) => {\n if (on) {\n $id(`${tool}_panel`).style.removeProperty('display')\n } else {\n $id(`${tool}_panel`).style.display = 'none'\n }\n }\n\n /**\n *\n * @param {string} attr attribute to change\n * @param {string|Float} val new value\n * @returns {void}\n */\n const setAttr = (attr, val) => {\n svgCanvas.changeSelectedAttribute(attr, val)\n svgCanvas.call('changed', selElems)\n }\n\n /**\n * @param {Float} n angle\n * @return {Float} cotangeante\n */\n const cot = (n) => 1 / Math.tan(n)\n\n /**\n * @param {Float} n angle\n * @returns {Float} sec\n */\n const sec = (n) => 1 / Math.cos(n)\n\n return {\n name: svgEditor.i18next.t(`${name}:name`),\n // The callback should be used to load the DOM with the appropriate UI items\n callback () {\n // Add the button and its handler(s)\n // Note: the star extension needs to be loaded before the polygon extension\n const fbtitle = `${name}:title`\n const titleStar = `${name}:buttons.0.title`\n const titlePolygon = `${name}:buttons.1.title`\n const buttonTemplate = `\n