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

1 line
11 KiB
Plaintext

{"version":3,"file":"ext-star.js","sources":["../../../src/editor/extensions/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 {$, importLocale} = 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 const strings = await importLocale();\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","_this","canvas","importLocale","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":"+rCAQA,MAAe,CACbA,KAAM,OACAC,mBAAMC,wWAsBDC,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,IA1BpBJ,EADYW,EACUC,OAErBN,EAAmBX,EAAnBW,EAAGO,EAAgBlB,EAAhBkB,sBAWYA,kBAAhBC,SA0CAC,EAAU,CAAC,CACfC,GAAI,YACJC,KAAM,WACNC,KAAM,OACNC,SAAU,GACVC,OAAQ,CACNC,uBACEzB,GAAU,GACVI,EAAUsB,QAAQ,YAIlBC,EAAe,CAAC,CACpBL,KAAM,QACNM,MAAO,aACPR,GAAI,gBACJS,KAAM,EACNC,OAAQ,EACRN,OAAQ,CACNO,yBACE9B,EAAQ,QAAS+B,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,yBACE9B,EAAQ,cAAe+B,KAAKC,6BAK3B,CACLpC,KAAMqB,EAAQrB,KACdqC,SAAU,iBACVf,QAASD,EAAQC,QAAQgB,KAAI,SAACC,EAAQC,UAC7BC,OAAOC,OAAOpB,EAAQ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