es6 refactor
This commit is contained in:
@@ -224,14 +224,12 @@ export const convertAttrs = function (element) {
|
|||||||
const attrs = attrsToConvert[elName];
|
const attrs = attrsToConvert[elName];
|
||||||
if (!attrs) { return; }
|
if (!attrs) { return; }
|
||||||
|
|
||||||
const len = attrs.length;
|
attrs.forEach( (attr) => {
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
const attr = attrs[i];
|
|
||||||
const cur = element.getAttribute(attr);
|
const cur = element.getAttribute(attr);
|
||||||
if (cur && !isNaN(cur)) {
|
if (cur && !isNaN(cur)) {
|
||||||
element.setAttribute(attr, (cur / typeMap_[unit]) + unit);
|
element.setAttribute(attr, (cur / typeMap_[unit]) + unit);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -136,11 +136,7 @@ export default {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Should only occur in FF which formats points attr as "n,n n,n", so just split
|
// Should only occur in FF which formats points attr as "n,n n,n", so just split
|
||||||
const ptArr = elem.getAttribute('points').split(' ');
|
const ptArr = elem.getAttribute('points').split(' ');
|
||||||
for (let i = 0; i < ptArr.length; i++) {
|
ptArr[pos] = x + ',' + y;
|
||||||
if (i === pos) {
|
|
||||||
ptArr[i] = x + ',' + y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elem.setAttribute('points', ptArr.join(' '));
|
elem.setAttribute('points', ptArr.join(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +204,7 @@ export default {
|
|||||||
let addThis;
|
let addThis;
|
||||||
// Grab the ends
|
// Grab the ends
|
||||||
const parts = [];
|
const parts = [];
|
||||||
[ 'start', 'end' ].forEach(function (pos, i) {
|
[ 'start', 'end' ].forEach( (pos, i) => {
|
||||||
const key = 'c_' + pos;
|
const key = 'c_' + pos;
|
||||||
let part = dataStorage.get(ethis, key);
|
let part = dataStorage.get(ethis, key);
|
||||||
if (part === null || part === undefined) { // Does this ever return nullish values?
|
if (part === null || part === undefined) { // Does this ever return nullish values?
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default {
|
|||||||
$id("sidepanel_content").insertAdjacentHTML( 'beforeend', propsWindowHtml );
|
$id("sidepanel_content").insertAdjacentHTML( 'beforeend', propsWindowHtml );
|
||||||
|
|
||||||
// Define dynamic animation of the view box.
|
// Define dynamic animation of the view box.
|
||||||
const updateViewBox = function () {
|
const updateViewBox = () => {
|
||||||
const { workarea } = svgEditor;
|
const { workarea } = svgEditor;
|
||||||
const portHeight = parseFloat(getComputedStyle(workarea, null).height.replace("px", ""));
|
const portHeight = parseFloat(getComputedStyle(workarea, null).height.replace("px", ""));
|
||||||
const portWidth = parseFloat(getComputedStyle(workarea, null).width.replace("px", ""));
|
const portWidth = parseFloat(getComputedStyle(workarea, null).width.replace("px", ""));
|
||||||
|
|||||||
@@ -51,11 +51,11 @@ export const init = function (editorContext) {
|
|||||||
* @type {module:path.EditorContext#remapElement}
|
* @type {module:path.EditorContext#remapElement}
|
||||||
*/
|
*/
|
||||||
export const remapElement = function (selected, changes, m) {
|
export const remapElement = function (selected, changes, m) {
|
||||||
const remap = function (x, y) { return transformPoint(x, y, m); };
|
const remap = (x, y) => transformPoint(x, y, m);
|
||||||
const scalew = function (w) { return m.a * w; };
|
const scalew = (w) => m.a * w;
|
||||||
const scaleh = function (h) { return m.d * h; };
|
const scaleh = (h) => m.d * h;
|
||||||
const doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg';
|
const doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg';
|
||||||
const finishUp = function () {
|
const finishUp = () => {
|
||||||
if (doSnapping) {
|
if (doSnapping) {
|
||||||
Object.entries(changes).forEach(([ o, value ]) => {
|
Object.entries(changes).forEach(([ o, value ]) => {
|
||||||
changes[o] = snapToGrid(value);
|
changes[o] = snapToGrid(value);
|
||||||
@@ -65,8 +65,7 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
};
|
};
|
||||||
const box = getBBox(selected);
|
const box = getBBox(selected);
|
||||||
|
|
||||||
for (let i = 0; i < 2; i++) {
|
[ 'fill', 'stroke' ].forEach( (type) => {
|
||||||
const type = i === 0 ? 'fill' : 'stroke';
|
|
||||||
const attrVal = selected.getAttribute(type);
|
const attrVal = selected.getAttribute(type);
|
||||||
if (attrVal && attrVal.startsWith('url(') && (m.a < 0 || m.d < 0)) {
|
if (attrVal && attrVal.startsWith('url(') && (m.a < 0 || m.d < 0)) {
|
||||||
const grad = getRefElem(attrVal);
|
const grad = getRefElem(attrVal);
|
||||||
@@ -90,7 +89,7 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
findDefs().append(newgrad);
|
findDefs().append(newgrad);
|
||||||
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
|
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
const elName = selected.tagName;
|
const elName = selected.tagName;
|
||||||
if (elName === 'g' || elName === 'text' || elName === 'tspan' || elName === 'use') {
|
if (elName === 'g' || elName === 'text' || elName === 'tspan' || elName === 'use') {
|
||||||
@@ -181,20 +180,17 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
break;
|
break;
|
||||||
} case 'polyline':
|
} case 'polyline':
|
||||||
case 'polygon': {
|
case 'polygon': {
|
||||||
const len = changes.points.length;
|
changes.points.forEach( (pt) => {
|
||||||
for (let i = 0; i < len; ++i) {
|
|
||||||
const pt = changes.points[i];
|
|
||||||
const { x, y } = remap(pt.x, pt.y);
|
const { x, y } = remap(pt.x, pt.y);
|
||||||
changes.points[i].x = x;
|
pt.x = x;
|
||||||
changes.points[i].y = y;
|
pt.y = y;
|
||||||
}
|
});
|
||||||
|
|
||||||
// const len = changes.points.length;
|
// const len = changes.points.length;
|
||||||
let pstr = '';
|
let pstr = '';
|
||||||
for (let i = 0; i < len; ++i) {
|
changes.points.forEach( (pt) => {
|
||||||
const pt = changes.points[i];
|
|
||||||
pstr += pt.x + ',' + pt.y + ' ';
|
pstr += pt.x + ',' + pt.y + ' ';
|
||||||
}
|
});
|
||||||
selected.setAttribute('points', pstr);
|
selected.setAttribute('points', pstr);
|
||||||
break;
|
break;
|
||||||
} case 'path': {
|
} case 'path': {
|
||||||
@@ -221,9 +217,12 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
|
|
||||||
len = changes.d.length;
|
len = changes.d.length;
|
||||||
const firstseg = changes.d[0];
|
const firstseg = changes.d[0];
|
||||||
const currentpt = remap(firstseg.x, firstseg.y);
|
let currentpt;
|
||||||
changes.d[0].x = currentpt.x;
|
if (len > 0) {
|
||||||
changes.d[0].y = currentpt.y;
|
currentpt = remap(firstseg.x, firstseg.y);
|
||||||
|
changes.d[0].x = currentpt.x;
|
||||||
|
changes.d[0].y = currentpt.y;
|
||||||
|
}
|
||||||
for (let i = 1; i < len; ++i) {
|
for (let i = 1; i < len; ++i) {
|
||||||
const seg = changes.d[i];
|
const seg = changes.d[i];
|
||||||
const { type } = seg;
|
const { type } = seg;
|
||||||
@@ -256,9 +255,7 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
} // for each segment
|
} // for each segment
|
||||||
|
|
||||||
let dstr = '';
|
let dstr = '';
|
||||||
len = changes.d.length;
|
changes.d.forEach( (seg) => {
|
||||||
for (let i = 0; i < len; ++i) {
|
|
||||||
const seg = changes.d[i];
|
|
||||||
const { type } = seg;
|
const { type } = seg;
|
||||||
dstr += pathMap[type];
|
dstr += pathMap[type];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -297,7 +294,7 @@ export const remapElement = function (selected, changes, m) {
|
|||||||
dstr += seg.x2 + ',' + seg.y2 + ' ' + seg.x + ',' + seg.y + ' ';
|
dstr += seg.x2 + ',' + seg.y2 + ' ' + seg.x + ',' + seg.y + ' ';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
selected.setAttribute('d', dstr);
|
selected.setAttribute('d', dstr);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user