Merge branch 'master' of https://github.com/SVG-Edit/svgedit into issues/374
This commit is contained in:
@@ -528,6 +528,19 @@ export const mouseMoveEvent = function (evt) {
|
||||
});
|
||||
}; // mouseMove()
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export const mouseOutEvent = function () {
|
||||
const svgCanvas = eventContext_.getCanvas();
|
||||
const { $id } = svgCanvas;
|
||||
if(eventContext_.getCurrentMode() !== 'select' && eventContext_.getStarted()) {
|
||||
const event = new Event("mouseup");
|
||||
$id('svgcanvas').dispatchEvent(event);
|
||||
}
|
||||
};
|
||||
|
||||
// - in create mode, the element's opacity is set properly, we create an InsertElementCommand
|
||||
// and store it on the Undo stack
|
||||
// - in move/resize mode, the element's attributes which were affected by the move/resize are
|
||||
|
||||
@@ -571,16 +571,19 @@ export const pushGroupProperty = function (g, undoable) {
|
||||
// Clone the group's filter
|
||||
gfilter = drawing.copyElem(gfilter);
|
||||
findDefs().append(gfilter);
|
||||
|
||||
// const filterElem = getRefElem(gfilter);
|
||||
const blurElem = getFeGaussianBlur(gfilter);
|
||||
// Change this in future for different filters
|
||||
const suffix = (blurElem?.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
|
||||
gfilter.id = elem.id + '_' + suffix;
|
||||
elementContext_.changeSelectedAttribute('filter', 'url(#' + gfilter.id + ')', [ elem ]);
|
||||
}
|
||||
} else {
|
||||
gfilter = getRefElem(elem.getAttribute('filter'));
|
||||
}
|
||||
// const filterElem = getRefElem(gfilter);
|
||||
const blurElem = getFeGaussianBlur(gfilter);
|
||||
// Change this in future for different filters
|
||||
const suffix = (blurElem?.tagName === 'feGaussianBlur') ? 'blur' : 'filter';
|
||||
gfilter.id = elem.id + '_' + suffix;
|
||||
elementContext_.changeSelectedAttribute('filter', 'url(#' + gfilter.id + ')', [ elem ]);
|
||||
|
||||
// Update blur value
|
||||
if (cblur) {
|
||||
|
||||
@@ -368,6 +368,28 @@ export const setSvgString = function (xmlString, preventUndo) {
|
||||
svgCanvas.embedImage(val);
|
||||
}
|
||||
});
|
||||
// Duplicate id replace changes
|
||||
const nodes = content.querySelectorAll('[id]');
|
||||
const ids = {};
|
||||
const totalNodes = nodes.length;
|
||||
|
||||
for(let i=0; i<totalNodes; i++) {
|
||||
const currentId = nodes[i].id ? nodes[i].id : "undefined";
|
||||
if(isNaN(ids[currentId])) {
|
||||
ids[currentId] = 0;
|
||||
}
|
||||
ids[currentId]++;
|
||||
}
|
||||
|
||||
Object.entries(ids).forEach(([ key, value ]) => {
|
||||
if (value > 1) {
|
||||
const nodes = content.querySelectorAll('[id="'+key+'"]');
|
||||
for(let i=1; i<nodes.length; i++) {
|
||||
nodes[i].setAttribute('id', svgCanvas.getNextId());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Wrap child SVGs in group elements
|
||||
const svgElements = content.querySelectorAll('svg');
|
||||
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
init as textActionsInit, textActionsMethod
|
||||
} from './text-actions.js';
|
||||
import {
|
||||
init as eventInit, mouseMoveEvent, mouseUpEvent,
|
||||
init as eventInit, mouseMoveEvent, mouseUpEvent, mouseOutEvent,
|
||||
dblClickEvent, mouseDownEvent, DOMMouseScrollEvent
|
||||
} from './event.js';
|
||||
import { init as jsonInit, getJsonFromSvgElements, addSVGElementsFromJson } from './json.js';
|
||||
@@ -1313,6 +1313,7 @@ class SvgCanvas {
|
||||
* @returns {void}
|
||||
*/
|
||||
const mouseUp = mouseUpEvent;
|
||||
const mouseOut = mouseOutEvent;
|
||||
|
||||
const dblClick = dblClickEvent;
|
||||
|
||||
@@ -1329,6 +1330,7 @@ class SvgCanvas {
|
||||
container.addEventListener('click', handleLinkInCanvas);
|
||||
container.addEventListener('dblclick', dblClick);
|
||||
container.addEventListener('mouseup', mouseUp);
|
||||
container.addEventListener('mouseleave', mouseOut);
|
||||
|
||||
// TODO(rafaelcastrocouto): User preference for shift key and zoom factor
|
||||
container.addEventListener('mousewheel', DOMMouseScrollEvent);
|
||||
|
||||
@@ -98,6 +98,24 @@ export const getUndoManager = function () {
|
||||
// // Ok to replace above with this? `sib.before(elem);`
|
||||
// }
|
||||
// }
|
||||
if (cmd.elem.tagName === 'text'){
|
||||
const [ dx, dy ] = [ cmd.newValues.x - cmd.oldValues.x,
|
||||
cmd.newValues.y - cmd.oldValues.y ];
|
||||
|
||||
const tspans = cmd.elem.children;
|
||||
|
||||
for (let i = 0; i < tspans.length; i++){
|
||||
let x = +tspans[i].getAttribute('x');
|
||||
let y = +tspans[i].getAttribute('y');
|
||||
|
||||
const unapply = (eventType === EventTypes.AFTER_UNAPPLY);
|
||||
x = unapply? x - dx: x + dx;
|
||||
y = unapply? y - dy: y + dy;
|
||||
|
||||
tspans[i].setAttribute('x', x);
|
||||
tspans[i].setAttribute('y', y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user