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

1 line
11 KiB
Plaintext

{"version":3,"file":"ext-star.js","sources":["../../../../src/editor/extensions/ext-star/ext-star.js"],"sourcesContent":["/**\n * @file ext-star.js\n *\n *\n * @copyright 2010 CloudCanvas, Inc. All rights reserved\n *\n */\n\nexport default {\n name: 'star',\n async init (S) {\n const svgEditor = this;\n const svgCanvas = svgEditor.canvas;\n\n const {$} = S; // {svgcontent},\n let\n selElems,\n // editingitex = false,\n // svgdoc = S.svgroot.parentNode.ownerDocument,\n started,\n newFO;\n // edg = 0,\n // newFOG, newFOGParent, newDef, newImageName, newMaskID,\n // undoCommand = 'Not image',\n // modeChangeG, ccZoom, wEl, hEl, wOffset, hOffset, ccRgbEl, brushW, brushH;\n // eslint-disable-next-line node/no-unsupported-features/es-syntax\n const {default: strings} = await import(`./locale/${svgEditor.curPrefs.lang}.js`);\n\n /**\n *\n * @param {boolean} on\n * @returns {void}\n */\n function showPanel (on) {\n let fcRules = $('#fc_rules');\n if (!fcRules.length) {\n fcRules = $('<style id=\"fc_rules\"></style>').appendTo('head');\n }\n fcRules.text(!on ? '' : ' #tool_topath { display: none !important; }');\n $('#star_panel').toggle(on);\n }\n\n /*\n function toggleSourceButtons(on){\n $('#star_save, #star_cancel').toggle(on);\n }\n */\n\n /**\n *\n * @param {string} attr\n * @param {string|Float} val\n * @returns {void}\n */\n function setAttr (attr, val) {\n svgCanvas.changeSelectedAttribute(attr, val);\n svgCanvas.call('changed', selElems);\n }\n\n /*\n function cot(n){\n return 1 / Math.tan(n);\n }\n\n function sec(n){\n return 1 / Math.cos(n);\n }\n */\n const buttons = [{\n id: 'tool_star',\n icon: 'star.png',\n type: 'mode',\n position: 12,\n events: {\n click () {\n showPanel(true);\n svgCanvas.setMode('star');\n }\n }\n }];\n const contextTools = [{\n type: 'input',\n panel: 'star_panel',\n id: 'starNumPoints',\n size: 3,\n defval: 5,\n events: {\n change () {\n setAttr('point', this.value);\n }\n }\n }, {\n type: 'input',\n panel: 'star_panel',\n id: 'starRadiusMulitplier',\n size: 3,\n defval: 2.5\n }, {\n type: 'input',\n panel: 'star_panel',\n id: 'radialShift',\n size: 3,\n defval: 0,\n events: {\n change () {\n setAttr('radialshift', this.value);\n }\n }\n }];\n\n return {\n name: strings.name,\n svgicons: 'star-icons.svg',\n buttons: strings.buttons.map((button, i) => {\n return Object.assign(buttons[i], button);\n }),\n context_tools: strings.contextTools.map((contextTool, i) => {\n return Object.assign(contextTools[i], contextTool);\n }),\n callback () {\n $('#star_panel').hide();\n // const endChanges = function(){};\n },\n mouseDown (opts) {\n const rgb = svgCanvas.getColor('fill');\n // const ccRgbEl = rgb.substring(1, rgb.length);\n const sRgb = svgCanvas.getColor('stroke');\n // const ccSRgbEl = sRgb.substring(1, rgb.length);\n const sWidth = svgCanvas.getStrokeWidth();\n\n if (svgCanvas.getMode() === 'star') {\n started = true;\n\n newFO = svgCanvas.addSVGElementFromJson({\n element: 'polygon',\n attr: {\n cx: opts.start_x,\n cy: opts.start_y,\n id: svgCanvas.getNextId(),\n shape: 'star',\n point: document.getElementById('starNumPoints').value,\n r: 0,\n radialshift: document.getElementById('radialShift').value,\n r2: 0,\n orient: 'point',\n fill: rgb,\n strokecolor: sRgb,\n strokeWidth: sWidth\n }\n });\n return {\n started: true\n };\n }\n return undefined;\n },\n mouseMove (opts) {\n if (!started) {\n return undefined;\n }\n if (svgCanvas.getMode() === 'star') {\n const c = $(newFO).attr(['cx', 'cy', 'point', 'orient', 'fill', 'strokecolor', 'strokeWidth', 'radialshift']);\n\n let x = opts.mouse_x;\n let y = opts.mouse_y;\n const {cx, cy, fill, strokecolor, strokeWidth, radialshift, point, orient} = c,\n circumradius = (Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy))) / 1.5,\n inradius = circumradius / document.getElementById('starRadiusMulitplier').value;\n newFO.setAttribute('r', circumradius);\n newFO.setAttribute('r2', inradius);\n\n let polyPoints = '';\n for (let s = 0; point >= s; s++) {\n let angle = 2.0 * Math.PI * (s / point);\n if (orient === 'point') {\n angle -= (Math.PI / 2);\n } else if (orient === 'edge') {\n angle = (angle + (Math.PI / point)) - (Math.PI / 2);\n }\n\n x = (circumradius * Math.cos(angle)) + cx;\n y = (circumradius * Math.sin(angle)) + cy;\n\n polyPoints += x + ',' + y + ' ';\n\n if (!isNaN(inradius)) {\n angle = (2.0 * Math.PI * (s / point)) + (Math.PI / point);\n if (orient === 'point') {\n angle -= (Math.PI / 2);\n } else if (orient === 'edge') {\n angle = (angle + (Math.PI / point)) - (Math.PI / 2);\n }\n angle += radialshift;\n\n x = (inradius * Math.cos(angle)) + cx;\n y = (inradius * Math.sin(angle)) + cy;\n\n polyPoints += x + ',' + y + ' ';\n }\n }\n newFO.setAttribute('points', polyPoints);\n newFO.setAttribute('fill', fill);\n newFO.setAttribute('stroke', strokecolor);\n newFO.setAttribute('stroke-width', strokeWidth);\n /* const shape = */ newFO.getAttribute('shape');\n\n return {\n started: true\n };\n }\n return undefined;\n },\n mouseUp () {\n if (svgCanvas.getMode() === 'star') {\n const attrs = $(newFO).attr(['r']);\n // svgCanvas.addToSelection([newFO], true);\n return {\n keep: (attrs.r !== '0'),\n element: newFO\n };\n }\n return undefined;\n },\n selectedChanged (opts) {\n // Use this to update the current selected elements\n selElems = opts.elems;\n\n let i = selElems.length;\n while (i--) {\n const elem = selElems[i];\n if (elem && elem.getAttribute('shape') === 'star') {\n if (opts.selectedElement && !opts.multiselected) {\n // $('#starRadiusMulitplier').val(elem.getAttribute('r2'));\n $('#starNumPoints').val(elem.getAttribute('point'));\n $('#radialShift').val(elem.getAttribute('radialshift'));\n showPanel(true);\n } else {\n showPanel(false);\n }\n } else {\n showPanel(false);\n }\n }\n },\n elementChanged (opts) {\n // const elem = opts.elems[0];\n }\n };\n }\n};\n"],"names":["name","init","S","showPanel","setAttr","attr","val","svgCanvas","changeSelectedAttribute","call","selElems","on","fcRules","$","length","appendTo","text","toggle","svgEditor","_this","canvas","import","curPrefs","lang","strings","buttons","id","icon","type","position","events","click","setMode","contextTools","panel","size","defval","change","this","value","svgicons","map","button","i","Object","assign","context_tools","contextTool","callback","hide","mouseDown","opts","rgb","getColor","sRgb","sWidth","getStrokeWidth","getMode","started","newFO","addSVGElementFromJson","element","cx","start_x","cy","start_y","getNextId","shape","point","document","getElementById","r","radialshift","r2","orient","fill","strokecolor","strokeWidth","mouseMove","c","x","mouse_x","y","mouse_y","circumradius","Math","sqrt","inradius","setAttribute","polyPoints","s","angle","PI","cos","sin","isNaN","getAttribute","mouseUp","keep","selectedChanged","elems","elem","selectedElement","multiselected","elementChanged"],"mappings":"0IAQA,MAAe,CACbA,KAAM,OACAC,mBAAMC,0WAuBDC,EAqBAC,sGAAAA,oBAASC,EAAMC,GACtBC,EAAUC,wBAAwBH,EAAMC,GACxCC,EAAUE,KAAK,UAAWC,IAvBnBP,sBAAWQ,OACdC,EAAUC,EAAE,aACXD,EAAQE,SACXF,EAAUC,EAAE,iCAAiCE,SAAS,SAExDH,EAAQI,KAAML,EAAU,8CAAL,IACnBE,EAAE,eAAeI,OAAON,IA3BpBJ,GADAW,EAAYC,GACUC,OAErBP,EAAKX,EAALW,WAY0BQ,0BAAmBH,EAAUI,SAASC,oCAAvDC,YA0CVC,EAAU,CAAC,CACfC,GAAI,YACJC,KAAM,WACNC,KAAM,OACNC,SAAU,GACVC,OAAQ,CACNC,uBACE5B,GAAU,GACVI,EAAUyB,QAAQ,YAIlBC,EAAe,CAAC,CACpBL,KAAM,QACNM,MAAO,aACPR,GAAI,gBACJS,KAAM,EACNC,OAAQ,EACRN,OAAQ,CACNO,yBACEjC,EAAQ,QAASkC,KAAKC,UAGzB,CACDX,KAAM,QACNM,MAAO,aACPR,GAAI,uBACJS,KAAM,EACNC,OAAQ,KACP,CACDR,KAAM,QACNM,MAAO,aACPR,GAAI,cACJS,KAAM,EACNC,OAAQ,EACRN,OAAQ,CACNO,yBACEjC,EAAQ,cAAekC,KAAKC,6BAK3B,CACLvC,KAAMwB,EAAQxB,KACdw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