mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-27 12:38:22 +01:00
1 line
28 KiB
Plaintext
1 line
28 KiB
Plaintext
|
{"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 <se-flyingbutton id=\"tools_polygon\" title=\"${fbtitle}\">\n <se-button id=\"tool_star\" title=\"${titleStar}\" src=\"star.svg\">\n </se-button>\n <se-button id=\"tool_polygon\" title=\"${titlePolygon}\" src=\"polygon.svg\">\n </se-button>\n </se-flyingbutton>\n `\n svgCanvas.insertChildAtIndex($id('tools_left'), buttonTemplate, 10)\n // handler\n $click($id('tool_star'), () => {\n if (this.leftPanel.updateLeftPanel('tool_star')) {\n svgCanvas.setMode('star')\n showPanel(true, 'star')\n showPanel(false, 'polygon')\n }\n })\n $click($id('tool_polygon'), () => {\n if (this.leftPanel.updateLeftPanel('tool_polygon')) {\n svgCanvas.setMode('polygon')\n showPanel(true, 'polygon')\n showPanel(false, 'star')\n }\n })\n const label0 = `${name}:contextTools.0.label`\n const title0 = `${name}:contextTools.0.title`\n const label1 = `${name}:contextTools.1.label`\n const title1 = `${name}:contextTools.1.title`\n const label2 = `${name}:contextTools.2.label`\n const title2 = `${name}:contextTools.2.title`\n const label3 = `
|