1 line
6.7 KiB
Plaintext
1 line
6.7 KiB
Plaintext
{"version":3,"file":"ext-shapes.js","sources":["../../../../src/editor/extensions/ext-shapes/ext-shapes.js"],"sourcesContent":["/**\n * @file ext-shapes.js\n *\n * @license MIT\n *\n * @copyright 2010 Christian Tzurcanu, 2010 Alexis Deveria\n *\n */\n\nexport default {\n name: 'shapes',\n init ({$}) {\n const svgEditor = this;\n const canv = svgEditor.svgCanvas;\n const svgroot = canv.getRootElem();\n let lastBBox = {};\n\n const modeId = 'shapelib';\n const startClientPos = {};\n\n let curShape;\n let startX;\n let startY;\n\n const events = {\n id: 'tool_shapelib',\n click () {\n canv.setMode(modeId);\n }\n };\n\n return {\n events,\n callback () {\n // should later register the event\n },\n mouseDown (opts) {\n const mode = canv.getMode();\n if (mode !== modeId) { return undefined; }\n\n const currentD = document.getElementById('tool_shapelib').dataset.draw;\n startX = opts.start_x;\n const x = startX;\n startY = opts.start_y;\n const y = startY;\n const curStyle = canv.getStyle();\n\n startClientPos.x = opts.event.clientX;\n startClientPos.y = opts.event.clientY;\n\n curShape = canv.addSVGElementFromJson({\n element: 'path',\n curStyles: true,\n attr: {\n d: currentD,\n id: canv.getNextId(),\n opacity: curStyle.opacity / 2,\n style: 'pointer-events:none'\n }\n });\n\n /*\n // Make sure shape uses absolute values\n if ((/[a-z]/).test(currentD)) {\n currentD = curLib.data[curShapeId] = canv.pathActions.convertPath(curShape);\n curShape.setAttribute('d', currentD);\n canv.pathActions.fixEnd(curShape);\n }\n */\n curShape.setAttribute('transform', 'translate(' + x + ',' + y + ') scale(0.005) translate(' + -x + ',' + -y + ')');\n\n canv.recalculateDimensions(curShape);\n\n canv.getTransformList(curShape);\n\n lastBBox = curShape.getBBox();\n\n return {\n started: true\n };\n },\n mouseMove (opts) {\n const mode = canv.getMode();\n if (mode !== modeId) { return; }\n\n const zoom = canv.getZoom();\n const evt = opts.event;\n\n const x = opts.mouse_x / zoom;\n const y = opts.mouse_y / zoom;\n\n const tlist = canv.getTransformList(curShape),\n box = curShape.getBBox(),\n left = box.x, top = box.y;\n\n const newbox = {\n x: Math.min(startX, x),\n y: Math.min(startY, y),\n width: Math.abs(x - startX),\n height: Math.abs(y - startY)\n };\n\n let sx = (newbox.width / lastBBox.width) || 1;\n let sy = (newbox.height / lastBBox.height) || 1;\n\n // Not perfect, but mostly works...\n let tx = 0;\n if (x < startX) {\n tx = lastBBox.width;\n }\n let ty = 0;\n if (y < startY) {\n ty = lastBBox.height;\n }\n\n // update the transform list with translate,scale,translate\n const translateOrigin = svgroot.createSVGTransform(),\n scale = svgroot.createSVGTransform(),\n translateBack = svgroot.createSVGTransform();\n\n translateOrigin.setTranslate(-(left + tx), -(top + ty));\n if (!evt.shiftKey) {\n const max = Math.min(Math.abs(sx), Math.abs(sy));\n\n sx = max * (sx < 0 ? -1 : 1);\n sy = max * (sy < 0 ? -1 : 1);\n }\n scale.setScale(sx, sy);\n\n translateBack.setTranslate(left + tx, top + ty);\n tlist.appendItem(translateBack);\n tlist.appendItem(scale);\n tlist.appendItem(translateOrigin);\n\n canv.recalculateDimensions(curShape);\n\n lastBBox = curShape.getBBox();\n },\n mouseUp (opts) {\n const mode = canv.getMode();\n if (mode !== modeId) { return undefined; }\n\n const keepObject = (opts.event.clientX !== startClientPos.x && opts.event.clientY !== startClientPos.y);\n\n return {\n keep: keepObject,\n element: curShape,\n started: false\n };\n }\n };\n }\n};\n"],"names":["name","init","$","curShape","startX","startY","canv","this","svgCanvas","svgroot","getRootElem","lastBBox","modeId","startClientPos","events","id","click","setMode","callback","mouseDown","opts","getMode","currentD","document","getElementById","dataset","draw","x","start_x","y","start_y","curStyle","getStyle","event","clientX","clientY","addSVGElementFromJson","element","curStyles","attr","d","getNextId","opacity","style","setAttribute","recalculateDimensions","getTransformList","getBBox","started","mouseMove","zoom","getZoom","evt","mouse_x","mouse_y","tlist","box","left","top","newbox","Math","min","abs","sx","width","sy","height","tx","ty","translateOrigin","createSVGTransform","scale","translateBack","setTranslate","shiftKey","max","setScale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