From 11ee55067c784540e27735d2a1f006a86720dcc6 Mon Sep 17 00:00:00 2001
From: JFH <20402845+jfhenon@users.noreply.github.com>
Date: Sat, 25 Dec 2021 17:25:12 -0300
Subject: [PATCH] refactor (incomplete)
---
cypress/integration/unit/coords.js | 2 +-
cypress/integration/unit/draw.js | 4 +-
cypress/integration/unit/path.js | 6 +-
cypress/integration/unit/recalculate.js | 4 +-
cypress/integration/unit/select.js | 14 +-
cypress/integration/unit/test1.js | 22 +-
cypress/integration/unit/utilities-bbox.js | 84 +-
.../integration/unit/utilities-performance.js | 8 +-
cypress/integration/unit/utilities.js | 16 +-
demos/canvas.html | 2 +-
src/common/browser.js | 8 +-
src/editor/Editor.js | 4 +-
src/editor/Rulers.js | 2 +-
.../ext-eyedropper/ext-eyedropper.js | 2 +-
.../extensions/ext-imagelib/ext-imagelib.js | 2 +-
.../extensions/ext-markers/ext-markers.js | 8 +-
.../extensions/ext-opensave/ext-opensave.js | 2 +-
.../extensions/ext-polystar/ext-polystar.js | 4 +-
.../extensions/ext-shapes/ext-shapes.js | 4 +-
.../extensions/ext-storage/ext-storage.js | 6 +-
.../extensions/ext-storage/storageDialog.js | 2 +-
src/editor/panels/TopPanel.js | 2 +-
src/svgcanvas/blur-event.js | 74 +-
src/svgcanvas/clear.js | 20 +-
src/svgcanvas/coords.js | 18 +-
src/svgcanvas/draw.js | 88 +-
src/svgcanvas/elem-get-set.js | 232 +--
src/svgcanvas/event.js | 625 ++++---
src/svgcanvas/json.js | 16 +-
src/svgcanvas/paste-elem.js | 28 +-
src/svgcanvas/path-actions.js | 218 ++-
src/svgcanvas/path-method.js | 59 +-
src/svgcanvas/path.js | 72 +-
src/svgcanvas/recalculate.js | 42 +-
src/svgcanvas/select.js | 59 +-
src/svgcanvas/selected-elem.js | 196 +-
src/svgcanvas/selection.js | 66 +-
src/svgcanvas/svg-exec.js | 140 +-
src/svgcanvas/svgcanvas.js | 1595 +++++------------
src/svgcanvas/text-actions.js | 72 +-
src/svgcanvas/undo.js | 60 +-
src/svgcanvas/utilities.js | 64 +-
42 files changed, 1626 insertions(+), 2326 deletions(-)
diff --git a/cypress/integration/unit/coords.js b/cypress/integration/unit/coords.js
index 42f66334..bee9e241 100644
--- a/cypress/integration/unit/coords.js
+++ b/cypress/integration/unit/coords.js
@@ -27,7 +27,7 @@ describe('coords', function () {
* @implements {module:utilities.EditorContext}
*/
{
- getSVGRoot: () => { return this.svg; },
+ getSvgRoot: () => { return this.svg; },
getDOMDocument () { return null; },
getDOMContainer () { return null; }
}
diff --git a/cypress/integration/unit/draw.js b/cypress/integration/unit/draw.js
index 507c67be..17fb5850 100644
--- a/cypress/integration/unit/draw.js
+++ b/cypress/integration/unit/draw.js
@@ -138,8 +138,8 @@ describe('draw.Drawing', function () {
svgN.setAttributeNS(NS.XMLNS, 'xmlns:se', NS.SE);
svgN.setAttributeNS(NS.SE, 'se:nonce', NONCE);
- const svgcontent = document.createElementNS(NS.SVG, 'svg');
- currentDrawing_ = new draw.Drawing(svgcontent, idprefix);
+ const svgContent = document.createElementNS(NS.SVG, 'svg');
+ currentDrawing_ = new draw.Drawing(svgContent, idprefix);
});
it('Test draw module', function () {
diff --git a/cypress/integration/unit/path.js b/cypress/integration/unit/path.js
index 36572008..56ac516e 100644
--- a/cypress/integration/unit/path.js
+++ b/cypress/integration/unit/path.js
@@ -27,8 +27,8 @@ describe('path', function () {
* @implements {module:path.EditorContext}
*/
{
- getSVGRoot () { return svg; },
- getCurrentZoom () { return 1; }
+ getSvgRoot () { return svg; },
+ getZoom () { return 1; }
},
/**
* @implements {module:utilities.EditorContext}
@@ -36,7 +36,7 @@ describe('path', function () {
{
getDOMDocument () { return svg; },
getDOMContainer () { return svg; },
- getSVGRoot () { return svg; }
+ getSvgRoot () { return svg; }
}
];
}
diff --git a/cypress/integration/unit/recalculate.js b/cypress/integration/unit/recalculate.js
index 7531e488..28290aeb 100644
--- a/cypress/integration/unit/recalculate.js
+++ b/cypress/integration/unit/recalculate.js
@@ -50,7 +50,7 @@ describe('recalculate', function () {
* @implements {module:utilities.EditorContext}
*/
{
- getSVGRoot() { return svg; },
+ getSvgRoot() { return svg; },
getDOMDocument() { return null; },
getDOMContainer() { return null; },
getDataStorage() { return dataStorage; }
@@ -75,7 +75,7 @@ describe('recalculate', function () {
* @implements {module:recalculate.EditorContext}
*/
{
- getSVGRoot() { return svg; },
+ getSvgRoot() { return svg; },
getStartTransform() { return ''; },
setStartTransform() { /* empty fn */ },
getDataStorage() { return dataStorage; }
diff --git a/cypress/integration/unit/select.js b/cypress/integration/unit/select.js
index 1fc91ba5..bd37c9fd 100644
--- a/cypress/integration/unit/select.js
+++ b/cypress/integration/unit/select.js
@@ -6,7 +6,7 @@ describe('select', function () {
sandbox.id = 'sandbox';
let svgroot;
- let svgcontent;
+ let svgContent;
const mockConfig = {
dimensions: [ 640, 480 ]
};
@@ -45,7 +45,7 @@ describe('select', function () {
return elem;
},
svgRoot () { return svgroot; },
- svgContent () { return svgcontent; },
+ svgContent () { return svgContent; },
getDataStorage () { return dataStorage; }
};
@@ -58,13 +58,13 @@ describe('select', function () {
element: 'svg',
attr: { id: 'svgroot' }
});
- svgcontent = mockFactory.createSVGElement({
+ svgContent = mockFactory.createSVGElement({
element: 'svg',
attr: { id: 'svgcontent' }
});
- svgroot.append(svgcontent);
- /* const rect = */ svgcontent.append(
+ svgroot.append(svgContent);
+ /* const rect = */ svgContent.append(
mockFactory.createSVGElement({
element: 'rect',
attr: {
@@ -114,7 +114,7 @@ describe('select', function () {
// Verify non-existence of Selector DOM nodes
assert.equal(svgroot.childNodes.length, 1);
- assert.equal(svgroot.childNodes.item(0), svgcontent);
+ assert.equal(svgroot.childNodes.item(0), svgContent);
assert.ok(!svgroot.querySelector('#selectorParentGroup'));
select.init(mockConfig, mockFactory);
@@ -127,7 +127,7 @@ describe('select', function () {
assert.equal(cb.id, 'canvasBackground');
assert.ok(svgroot.childNodes.item(1));
- assert.equal(svgroot.childNodes.item(1), svgcontent);
+ assert.equal(svgroot.childNodes.item(1), svgContent);
// Verify existence of selectorParentGroup.
const spg = svgroot.childNodes.item(2);
diff --git a/cypress/integration/unit/test1.js b/cypress/integration/unit/test1.js
index cba8bf26..1d4e05e2 100644
--- a/cypress/integration/unit/test1.js
+++ b/cypress/integration/unit/test1.js
@@ -208,10 +208,10 @@ describe('Basic Module', function () {
''
);
- const svgcontent = document.getElementById('svgcontent');
- const circles = svgcontent.getElementsByTagNameNS(svgns, 'circle');
- const rects = svgcontent.getElementsByTagNameNS(svgns, 'rect');
- const ellipses = svgcontent.getElementsByTagNameNS(svgns, 'ellipse');
+ const svgContent = document.getElementById('svgcontent');
+ const circles = svgContent.getElementsByTagNameNS(svgns, 'circle');
+ const rects = svgContent.getElementsByTagNameNS(svgns, 'rect');
+ const ellipses = svgContent.getElementsByTagNameNS(svgns, 'ellipse');
assert.equal(circles.length, 2, 'Found two circles upon importing');
assert.equal(rects.length, 1, 'Found one rectangle upon importing');
assert.equal(ellipses.length, 1, 'Found one ellipse upon importing');
@@ -242,13 +242,13 @@ describe('Basic Module', function () {
''
);
- const svgcontent = document.getElementById('svgcontent');
- const circles = svgcontent.getElementsByTagNameNS(svgns, 'circle');
- const rects = svgcontent.getElementsByTagNameNS(svgns, 'rect');
- // ellipses = svgcontent.getElementsByTagNameNS(svgns, 'ellipse'),
- const defs = svgcontent.getElementsByTagNameNS(svgns, 'defs');
- // grads = svgcontent.getElementsByTagNameNS(svgns, 'linearGradient'),
- const uses = svgcontent.getElementsByTagNameNS(svgns, 'use');
+ const svgContent = document.getElementById('svgcontent');
+ const circles = svgContent.getElementsByTagNameNS(svgns, 'circle');
+ const rects = svgContent.getElementsByTagNameNS(svgns, 'rect');
+ // ellipses = svgContent.getElementsByTagNameNS(svgns, 'ellipse'),
+ const defs = svgContent.getElementsByTagNameNS(svgns, 'defs');
+ // grads = svgContent.getElementsByTagNameNS(svgns, 'linearGradient'),
+ const uses = svgContent.getElementsByTagNameNS(svgns, 'use');
assert.notEqual(circles.item(0).id, 'svg_1', 'Circle not re-identified');
assert.notEqual(rects.item(0).id, 'svg_3', 'Rectangle not re-identified');
// TODO: determine why this test fails in WebKit browsers
diff --git a/cypress/integration/unit/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js
index 11e7a757..68ac4511 100644
--- a/cypress/integration/unit/utilities-bbox.js
+++ b/cypress/integration/unit/utilities-bbox.js
@@ -21,17 +21,17 @@ describe('utilities bbox', function () {
});
return elem;
}
- let mockaddSVGElementFromJsonCallCount = 0;
+ let mockaddSVGElemensFromJsonCallCount = 0;
/**
- * Mock of {@link module:utilities.EditorContext#addSVGElementFromJson}.
+ * Mock of {@link module:utilities.EditorContext#addSVGElemensFromJson}.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
- function mockaddSVGElementFromJson (json) {
+ function mockaddSVGElemensFromJson (json) {
const elem = mockCreateSVGElement(json);
svgroot.append(elem);
- mockaddSVGElementFromJsonCallCount++;
+ mockaddSVGElemensFromJsonCallCount++;
return elem;
}
const mockPathActions = {
@@ -83,7 +83,7 @@ describe('utilities bbox', function () {
sandbox.append(svgroot);
path.init(null);
- mockaddSVGElementFromJsonCallCount = 0;
+ mockaddSVGElemensFromJsonCallCount = 0;
});
it('Test svgedit.utilities package', function () {
@@ -102,9 +102,9 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M0,1 L2,3' }
});
svgroot.append(elem);
- let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 });
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
elem.remove();
elem = mockCreateSVGElement({
@@ -112,9 +112,9 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
elem.remove();
elem = mockCreateSVGElement({
@@ -122,9 +122,9 @@ describe('utilities bbox', function () {
attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 });
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
elem.remove();
elem = mockCreateSVGElement({
@@ -137,9 +137,9 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
g.remove();
});
@@ -151,7 +151,7 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10)' }
});
svgroot.append(elem);
- let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, 10, EPSILON);
assert.close(bbox.y, 10, EPSILON);
assert.close(bbox.width, 0, EPSILON);
@@ -163,12 +163,12 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20)' }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, 5, EPSILON);
assert.close(bbox.y, 15, EPSILON);
assert.close(bbox.width, 20, EPSILON);
assert.close(bbox.height, 10, EPSILON);
- assert.equal(mockaddSVGElementFromJsonCallCount, 1);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 1);
elem.remove();
const rect = { x: 10, y: 10, width: 10, height: 20 };
@@ -179,14 +179,14 @@ describe('utilities bbox', function () {
attr: { id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')' }
});
svgroot.append(elem);
- mockaddSVGElementFromJsonCallCount = 0;
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ mockaddSVGElemensFromJsonCallCount = 0;
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
const r2 = rotateRect(rect, angle, origin);
assert.close(bbox.x, r2.x, EPSILON, 'rect2 x is ' + r2.x);
assert.close(bbox.y, r2.y, EPSILON, 'rect2 y is ' + r2.y);
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
assert.close(bbox.height, r2.height, EPSILON, 'rect2 height is ' + r2.height);
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
elem.remove();
// Same as previous but wrapped with g and the transform is with the g.
@@ -200,13 +200,13 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- mockaddSVGElementFromJsonCallCount = 0;
- bbox = getBBoxWithTransform(g, mockaddSVGElementFromJson, mockPathActions);
+ mockaddSVGElemensFromJsonCallCount = 0;
+ bbox = getBBoxWithTransform(g, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, r2.x, EPSILON, 'rect2 x is ' + r2.x);
assert.close(bbox.y, r2.y, EPSILON, 'rect2 y is ' + r2.y);
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
assert.close(bbox.height, r2.height, EPSILON, 'rect2 height is ' + r2.height);
- assert.equal(mockaddSVGElementFromJsonCallCount, 0);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 0);
g.remove();
elem = mockCreateSVGElement({
@@ -214,14 +214,14 @@ describe('utilities bbox', function () {
attr: { id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100)' }
});
svgroot.append(elem);
- mockaddSVGElementFromJsonCallCount = 0;
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ mockaddSVGElemensFromJsonCallCount = 0;
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
/** @todo: Review these test the BBox algorithm is using the bezier control points to calculate the bounding box. Should be 50, 50, 100, 100. */
// assert.ok(bbox.x > 45 && bbox.x <= 50);
assert.ok(bbox.y > 45 && bbox.y <= 50);
// assert.ok(bbox.width >= 100 && bbox.width < 110);
// assert.ok(bbox.height >= 100 && bbox.height < 110);
- assert.equal(mockaddSVGElementFromJsonCallCount, 1);
+ assert.equal(mockaddSVGElemensFromJsonCallCount, 1);
elem.remove();
});
@@ -238,7 +238,7 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10) ' + matrix }
});
svgroot.append(elem);
- let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, 10 + tx, EPSILON);
assert.close(bbox.y, 10 + ty, EPSILON);
assert.close(bbox.width, 0, EPSILON);
@@ -253,7 +253,7 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20) ' + matrix }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, 5 + tx, EPSILON);
assert.close(bbox.y, 15 + ty, EPSILON);
assert.close(bbox.width, 20, EPSILON);
@@ -273,7 +273,7 @@ describe('utilities bbox', function () {
attr: { id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ') ' + matrix }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
const r2 = rotateRect(rect, angle, origin);
assert.close(bbox.x, r2.x + tx, EPSILON, 'rect2 x is ' + r2.x);
assert.close(bbox.y, r2.y + ty, EPSILON, 'rect2 y is ' + r2.y);
@@ -292,7 +292,7 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- bbox = getBBoxWithTransform(g, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(g, mockaddSVGElemensFromJson, mockPathActions);
assert.close(bbox.x, r2.x + tx, EPSILON, 'rect2 x is ' + r2.x);
assert.close(bbox.y, r2.y + ty, EPSILON, 'rect2 y is ' + r2.y);
assert.close(bbox.width, r2.width, EPSILON, 'rect2 width is' + r2.width);
@@ -304,7 +304,7 @@ describe('utilities bbox', function () {
attr: { id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100) ' + matrix }
});
svgroot.append(elem);
- bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxWithTransform(elem, mockaddSVGElemensFromJson, mockPathActions);
/** @todo: the BBox algorithm is using the bezier control points to calculate the bounding box. Should be 50, 50, 100, 100. */
// assert.ok(bbox.x > 45 + tx && bbox.x <= 50 + tx);
assert.ok(bbox.y > 45 + ty && bbox.y <= 50 + ty);
@@ -322,7 +322,7 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M0,1 L2,3', 'stroke-width': strokeWidth }
});
svgroot.append(elem);
- let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 2 + strokeWidth, height: 2 + strokeWidth });
elem.remove();
@@ -331,7 +331,7 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth });
elem.remove();
@@ -340,7 +340,7 @@ describe('utilities bbox', function () {
attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': strokeWidth }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 5 + strokeWidth });
elem.remove();
@@ -354,7 +354,7 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth });
g.remove();
});
@@ -367,7 +367,7 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M0,1 L2,3', 'stroke-width': 'none' }
});
svgroot.append(elem);
- let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 });
elem.remove();
@@ -376,7 +376,7 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none' }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
elem.remove();
@@ -385,7 +385,7 @@ describe('utilities bbox', function () {
attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': 'none' }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 });
elem.remove();
@@ -399,7 +399,7 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
g.remove();
});
@@ -412,7 +412,7 @@ describe('utilities bbox', function () {
attr: { id: 'path', d: 'M0,1 L2,3' }
});
svgroot.append(elem);
- let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 });
elem.remove();
@@ -421,7 +421,7 @@ describe('utilities bbox', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
elem.remove();
@@ -430,7 +430,7 @@ describe('utilities bbox', function () {
attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' }
});
svgroot.append(elem);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 });
elem.remove();
@@ -444,7 +444,7 @@ describe('utilities bbox', function () {
});
g.append(elem);
svgroot.append(g);
- bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions);
+ bbox = getStrokedBBox([ elem ], mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
g.remove();
});
diff --git a/cypress/integration/unit/utilities-performance.js b/cypress/integration/unit/utilities-performance.js
index 0265f0d6..72ab0efa 100644
--- a/cypress/integration/unit/utilities-performance.js
+++ b/cypress/integration/unit/utilities-performance.js
@@ -87,11 +87,11 @@ describe('utilities performance', function () {
}
/**
- * Mock of {@link module:utilities.EditorContext#addSVGElementFromJson}.
+ * Mock of {@link module:utilities.EditorContext#addSVGElemensFromJson}.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
- function mockaddSVGElementFromJson (json) {
+ function mockaddSVGElemensFromJson (json) {
const elem = mockCreateSVGElement(json);
currentLayer.append(elem);
return elem;
@@ -198,7 +198,7 @@ describe('utilities performance', function () {
// Skip the first child which is the title.
for (let index = 1; index < count; index++) {
const child = children[index];
- /* const obj = */ getStrokedBBox([ child ], mockaddSVGElementFromJson, mockPathActions);
+ /* const obj = */ getStrokedBBox([ child ], mockaddSVGElemensFromJson, mockPathActions);
now = Date.now(); const delta = now - lastTime; lastTime = now;
total += delta;
min = Math.min(min, delta);
@@ -218,7 +218,7 @@ describe('utilities performance', function () {
// Skip the first child which is the title.
for (let index = 1; index < ct; index++) {
const child = children[index];
- /* const obj = */ getStrokedBBox([ child ], mockaddSVGElementFromJson, mockPathActions);
+ /* const obj = */ getStrokedBBox([ child ], mockaddSVGElemensFromJson, mockPathActions);
now = Date.now(); const delta = now - lastTime; lastTime = now;
total += delta;
min = Math.min(min, delta);
diff --git a/cypress/integration/unit/utilities.js b/cypress/integration/unit/utilities.js
index d925f3a7..aa1616cc 100644
--- a/cypress/integration/unit/utilities.js
+++ b/cypress/integration/unit/utilities.js
@@ -19,7 +19,7 @@ describe('utilities', function () {
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
- function mockaddSVGElementFromJson (json) {
+ function mockaddSVGElemensFromJson (json) {
const elem = mockCreateSVGElement(json);
svgroot.append(elem);
return elem;
@@ -245,8 +245,8 @@ describe('utilities', function () {
* Wrap `utilities.getBBoxOfElementAsPath` to convert bbox to object for testing.
* @type {module:utilities.getBBoxOfElementAsPath}
*/
- function getBBoxOfElementAsPath (elem, addSVGElementFromJson, pathActions) {
- const bbox = utilities.getBBoxOfElementAsPath(elem, addSVGElementFromJson, pathActions);
+ function getBBoxOfElementAsPath (elem, addSVGElemensFromJson, pathActions) {
+ const bbox = utilities.getBBoxOfElementAsPath(elem, addSVGElemensFromJson, pathActions);
return utilities.bboxToObj(bbox); // need this for assert.equal() to work.
}
@@ -255,7 +255,7 @@ describe('utilities', function () {
attr: { id: 'path', d: 'M0,1 Z' }
});
svgroot.append(elem);
- let bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
+ let bbox = getBBoxOfElementAsPath(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 0, height: 0 });
elem.remove();
@@ -264,7 +264,7 @@ describe('utilities', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' }
});
svgroot.append(elem);
- bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxOfElementAsPath(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 });
elem.remove();
@@ -273,7 +273,7 @@ describe('utilities', function () {
attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' }
});
svgroot.append(elem);
- bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions);
+ bbox = getBBoxOfElementAsPath(elem, mockaddSVGElemensFromJson, mockPathActions);
assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 });
elem.remove();
@@ -294,7 +294,7 @@ describe('utilities', function () {
attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' }
});
svgroot.append(elem);
- const path = convertToPath(elem, attrs, mockaddSVGElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
+ const path = convertToPath(elem, attrs, mockaddSVGElemensFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
assert.equal(path.getAttribute('d'), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z');
assert.equal(path.getAttribute('visibilituy'), null);
assert.equal(path.id, 'rect');
@@ -322,7 +322,7 @@ describe('utilities', function () {
getAttribute () { return ''; },
parentNode: svgroot
};
- const path = convertToPath(elem, attrs, mockaddSVGElementFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
+ const path = convertToPath(elem, attrs, mockaddSVGElemensFromJson, mockPathActions, mockClearSelection, mockAddToSelection, mockHistory, mockAddCommandToHistory);
assert.equal(path, null);
assert.equal(elem.parentNode, svgroot);
assert.equal(mockHistorySubCommands.length, 0);
diff --git a/demos/canvas.html b/demos/canvas.html
index 3d149e80..0a903806 100644
--- a/demos/canvas.html
+++ b/demos/canvas.html
@@ -50,7 +50,7 @@ window.canvas = new SvgCanvas(container, config);
canvas.updateCanvas(width, height);
window.fill = function (colour) {
- canvas.getSelectedElems().forEach((el) => {
+ canvas.getSelectedElements().forEach((el) => {
el.setAttribute('fill', colour);
});
};
diff --git a/src/common/browser.js b/src/common/browser.js
index 00e3b4b7..8d5c8131 100644
--- a/src/common/browser.js
+++ b/src/common/browser.js
@@ -20,13 +20,13 @@ const isTouch_ = 'ontouchstart' in window;
// text character positioning (for IE9 and now Chrome)
const supportsGoodTextCharPos_ = (function () {
const svgroot = document.createElementNS(NSSVG, 'svg');
- const svgcontent = document.createElementNS(NSSVG, 'svg');
+ const svgContent = document.createElementNS(NSSVG, 'svg');
document.documentElement.append(svgroot);
- svgcontent.setAttribute('x', 5);
- svgroot.append(svgcontent);
+ svgContent.setAttribute('x', 5);
+ svgroot.append(svgContent);
const text = document.createElementNS(NSSVG, 'text');
text.textContent = 'a';
- svgcontent.append(text);
+ svgContent.append(text);
try { // Chrome now fails here
const pos = text.getStartPositionOfChar(0).x;
return (pos === 0);
diff --git a/src/editor/Editor.js b/src/editor/Editor.js
index daf39569..bf39d3a6 100644
--- a/src/editor/Editor.js
+++ b/src/editor/Editor.js
@@ -729,7 +729,7 @@ class Editor extends EditorStartup {
multiplier = multiplier ? resolution.zoom * multiplier : 1;
// setResolution(res.w * multiplier, res.h * multiplier, true);
$id('zoom').value = (multiplier * 100).toFixed(1);
- this.svgCanvas.setZoom(multiplier);
+ this.svgCanvas.setCurrentZoom(multiplier);
this.zoomDone();
this.updateCanvas(true);
}
@@ -1116,7 +1116,7 @@ class Editor extends EditorStartup {
if (!this.svgCanvas) {
throw new Error('Extension added too early');
}
- return this.svgCanvas.addExtension.call(this, name, initfn, initArgs);
+ return this.svgCanvas.addExtension( name, initfn, initArgs);
}
}
diff --git a/src/editor/Rulers.js b/src/editor/Rulers.js
index 46048137..75bd7f6a 100644
--- a/src/editor/Rulers.js
+++ b/src/editor/Rulers.js
@@ -58,7 +58,7 @@ class Rulers {
let d; let i;
const limit = 30000;
- const contentElem = this.svgCanvas.getContentElem();
+ const contentElem = this.svgCanvas.getSvgContent();
const units = getTypeMap();
const unit = units[this.editor.configObj.curConfig.baseUnit]; // 1 = 1px
diff --git a/src/editor/extensions/ext-eyedropper/ext-eyedropper.js b/src/editor/extensions/ext-eyedropper/ext-eyedropper.js
index 366ae9e0..32ccda77 100644
--- a/src/editor/extensions/ext-eyedropper/ext-eyedropper.js
+++ b/src/editor/extensions/ext-eyedropper/ext-eyedropper.js
@@ -28,7 +28,7 @@ export default {
async init(S) {
const svgEditor = this;
await loadExtensionTranslation(svgEditor);
- const { ChangeElementCommand } = S; // , svgcontent,
+ const { ChangeElementCommand } = S;
// svgdoc = S.svgroot.parentNode.ownerDocument,
const { svgCanvas } = svgEditor;
const addToHistory = function (cmd) { svgCanvas.undoMgr.addCommandToHistory(cmd); };
diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js
index 7901866c..941ef901 100644
--- a/src/editor/extensions/ext-imagelib/ext-imagelib.js
+++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js
@@ -71,7 +71,7 @@ export default {
* @returns {void}
*/
const importImage = (url) => {
- const newImage = svgCanvas.addSVGElementFromJson({
+ const newImage = svgCanvas.addSVGElemensFromJson({
element: 'image',
attr: {
x: 0,
diff --git a/src/editor/extensions/ext-markers/ext-markers.js b/src/editor/extensions/ext-markers/ext-markers.js
index d1c0592b..227f67de 100644
--- a/src/editor/extensions/ext-markers/ext-markers.js
+++ b/src/editor/extensions/ext-markers/ext-markers.js
@@ -32,7 +32,7 @@ export default {
async init (S) {
const svgEditor = this;
const { svgCanvas } = svgEditor;
- const { $id, addSVGElementFromJson: addElem } = svgCanvas;
+ const { $id, addSVGElemensFromJson: addElem } = svgCanvas;
const mtypes = [ 'start', 'mid', 'end' ];
const markerElems = [ 'line', 'path', 'polyline', 'polygon' ];
@@ -99,7 +99,7 @@ export default {
* @returns {SVGMarkerElement}
*/
const addMarker = (id, seType) => {
- const selElems = svgCanvas.getSelectedElems();
+ const selElems = svgCanvas.getSelectedElements();
let marker = svgCanvas.getElem(id);
if (marker) { return undefined; }
if (seType === '' || seType === 'nomarker') { return undefined; }
@@ -200,7 +200,7 @@ export default {
* @returns {void}
*/
const setMarker = (pos, markerType) => {
- const selElems = svgCanvas.getSelectedElems();
+ const selElems = svgCanvas.getSelectedElements();
if (selElems.length === 0) return;
const markerName = 'marker-' + pos;
const el = selElems[0];
@@ -252,7 +252,7 @@ export default {
* @returns {void}
*/
const updateReferences = (el) => {
- const selElems = svgCanvas.getSelectedElems();
+ const selElems = svgCanvas.getSelectedElements();
mtypes.forEach((pos) => {
const markerName = 'marker-' + pos;
const marker = getLinked(el, markerName);
diff --git a/src/editor/extensions/ext-opensave/ext-opensave.js b/src/editor/extensions/ext-opensave/ext-opensave.js
index 9894ffa1..d5b986ac 100644
--- a/src/editor/extensions/ext-opensave/ext-opensave.js
+++ b/src/editor/extensions/ext-opensave/ext-opensave.js
@@ -83,7 +83,7 @@ export default {
* @returns {void}
*/
const insertNewImage = (imageWidth, imageHeight) => {
- const newImage = this.svgCanvas.addSVGElementFromJson({
+ const newImage = this.svgCanvas.addSVGElemensFromJson({
element: 'image',
attr: {
x: 0,
diff --git a/src/editor/extensions/ext-polystar/ext-polystar.js b/src/editor/extensions/ext-polystar/ext-polystar.js
index 1451f444..9ecfdd15 100644
--- a/src/editor/extensions/ext-polystar/ext-polystar.js
+++ b/src/editor/extensions/ext-polystar/ext-polystar.js
@@ -246,7 +246,7 @@ export default {
const sRgb = svgCanvas.getColor("stroke");
const sWidth = svgCanvas.getStrokeWidth();
started = true;
- newFO = svgCanvas.addSVGElementFromJson({
+ newFO = svgCanvas.addSVGElemensFromJson({
element: "polygon",
attr: {
cx: opts.start_x,
@@ -275,7 +275,7 @@ export default {
// ccSRgbEl = sRgb.substring(1, rgb.length);
const sWidth = svgCanvas.getStrokeWidth();
started = true;
- newFO = svgCanvas.addSVGElementFromJson({
+ newFO = svgCanvas.addSVGElemensFromJson({
element: "polygon",
attr: {
cx: opts.start_x,
diff --git a/src/editor/extensions/ext-shapes/ext-shapes.js b/src/editor/extensions/ext-shapes/ext-shapes.js
index 129695d1..ec46064e 100644
--- a/src/editor/extensions/ext-shapes/ext-shapes.js
+++ b/src/editor/extensions/ext-shapes/ext-shapes.js
@@ -27,7 +27,7 @@ export default {
const svgEditor = this;
const canv = svgEditor.svgCanvas;
const { $id } = canv;
- const svgroot = canv.getRootElem();
+ const svgroot = canv.getSvgRoot();
let lastBBox = {};
await loadExtensionTranslation(svgEditor);
@@ -67,7 +67,7 @@ export default {
startClientPos.x = opts.event.clientX;
startClientPos.y = opts.event.clientY;
- curShape = canv.addSVGElementFromJson({
+ curShape = canv.addSVGElemensFromJson({
element: 'path',
curStyles: true,
attr: {
diff --git a/src/editor/extensions/ext-storage/ext-storage.js b/src/editor/extensions/ext-storage/ext-storage.js
index dc3136d0..9d6b8ab6 100644
--- a/src/editor/extensions/ext-storage/ext-storage.js
+++ b/src/editor/extensions/ext-storage/ext-storage.js
@@ -100,7 +100,7 @@ export default {
} else {
removeStoragePrefCookie();
if (svgEditor.configObj.curConfig.emptyStorageOnDecline && e?.detail?.checkbox) {
- this.setSVGContentStorage('');
+ this.setSvgContentStorage('');
Object.keys(svgEditor.curPrefs).forEach((name) => {
name = 'svg-edit-' + name;
if (svgEditor.storage) {
@@ -128,7 +128,7 @@ export default {
* @param {string} val
* @returns {void}
*/
- function setSVGContentStorage (val) {
+ function setSvgContentStorage (val) {
if (storage) {
const name = 'svgedit-' + svgEditor.configObj.curConfig.canvasName;
if (!val) {
@@ -155,7 +155,7 @@ export default {
return;
}
if ((/(?:^|;\s*)svgeditstore=prefsAndContent/).test(document.cookie)) {
- setSVGContentStorage(svgCanvas.getSvgString());
+ setSvgContentStorage(svgCanvas.getSvgString());
}
svgEditor.setConfig({ no_save_warning: true }); // No need for explicit saving at all once storage is on
diff --git a/src/editor/extensions/ext-storage/storageDialog.js b/src/editor/extensions/ext-storage/storageDialog.js
index b2807a9e..d106fde4 100644
--- a/src/editor/extensions/ext-storage/storageDialog.js
+++ b/src/editor/extensions/ext-storage/storageDialog.js
@@ -139,7 +139,7 @@ export class SeStorageDialog extends HTMLElement {
* @param {string} val
* @returns {void}
*/
- setSVGContentStorage (val) {
+ setSvgContentStorage (val) {
if (this.storage) {
const name = 'svgedit-' + this.configObj.curConfig.canvasName;
if (!val) {
diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js
index 4b336841..3a21cdca 100644
--- a/src/editor/panels/TopPanel.js
+++ b/src/editor/panels/TopPanel.js
@@ -780,7 +780,7 @@ class TopPanel {
.then(() => {
// switch into "select" mode if we've clicked on an element
editor.svgCanvas.setMode('select');
- editor.svgCanvas.selectOnly(editor.svgCanvas.getSelectedElems(), true);
+ editor.svgCanvas.selectOnly(editor.svgCanvas.getSelectedElements(), true);
}, (error) => {
console.error("error =", error);
seAlert(editor.i18next.t('tools.no_embed'));
diff --git a/src/svgcanvas/blur-event.js b/src/svgcanvas/blur-event.js
index 9897ece1..320b910c 100644
--- a/src/svgcanvas/blur-event.js
+++ b/src/svgcanvas/blur-event.js
@@ -10,15 +10,15 @@ const {
InsertElementCommand, ChangeElementCommand, BatchCommand
} = hstry;
-let blurContext_ = null;
+let svgCanvas = null;
/**
* @function module:blur.init
* @param {module:blur.blurContext} blurContext
* @returns {void}
*/
-export const init = function (blurContext) {
- blurContext_ = blurContext;
+export const init = function (canvas) {
+ svgCanvas = canvas;
};
/**
@@ -28,28 +28,28 @@ export const init = function (blurContext) {
* @returns {void}
*/
export const setBlurNoUndo = function (val) {
- const selectedElements = blurContext_.getSelectedElements();
- if (!blurContext_.getFilter()) {
- blurContext_.getCanvas().setBlur(val);
+ const selectedElements = svgCanvas.getSelectedElements();
+ if (!svgCanvas.getFilter()) {
+ svgCanvas.setBlur(val);
return;
}
if (val === 0) {
// Don't change the StdDev, as that will hide the element.
// Instead, just remove the value for "filter"
- blurContext_.changeSelectedAttributeNoUndoMethod('filter', '');
- blurContext_.setFilterHidden(true);
+ svgCanvas.changeSelectedAttributeNoUndoMethod('filter', '');
+ svgCanvas.setFilterHidden(true);
} else {
const elem = selectedElements[0];
- if (blurContext_.getFilterHidden()) {
- blurContext_.changeSelectedAttributeNoUndoMethod('filter', 'url(#' + elem.id + '_blur)');
+ if (svgCanvas.getFilterHidden()) {
+ svgCanvas.changeSelectedAttributeNoUndoMethod('filter', 'url(#' + elem.id + '_blur)');
}
- if (blurContext_.isWebkit()) {
+ if (svgCanvas.isWebkit()) {
elem.removeAttribute('filter');
elem.setAttribute('filter', 'url(#' + elem.id + '_blur)');
}
- const filter = blurContext_.getFilter();
- blurContext_.changeSelectedAttributeNoUndoMethod('stdDeviation', val, [ filter.firstChild ]);
- blurContext_.getCanvas().setBlurOffsets(filter, val);
+ const filter = svgCanvas.getFilter();
+ svgCanvas.changeSelectedAttributeNoUndoMethod('stdDeviation', val, [ filter.firstChild ]);
+ svgCanvas.setBlurOffsets(filter, val);
}
};
@@ -58,11 +58,11 @@ export const setBlurNoUndo = function (val) {
* @returns {void}
*/
function finishChange () {
- const bCmd = blurContext_.getCanvas().undoMgr.finishUndoableChange();
- blurContext_.getCurCommand().addSubCommand(bCmd);
- blurContext_.addCommandToHistory(blurContext_.getCurCommand());
- blurContext_.setCurCommand(null);
- blurContext_.setFilter(null);
+ const bCmd = svgCanvas.undoMgr.finishUndoableChange();
+ svgCanvas.getCurCommand().addSubCommand(bCmd);
+ svgCanvas.addCommandToHistory(svgCanvas.getCurCommand());
+ svgCanvas.setCurCommand(null);
+ svgCanvas.setFilter(null);
}
/**
@@ -76,14 +76,14 @@ function finishChange () {
export const setBlurOffsets = function (filterElem, stdDev) {
if (stdDev > 3) {
// TODO: Create algorithm here where size is based on expected blur
- blurContext_.getCanvas().assignAttributes(filterElem, {
+ svgCanvas.assignAttributes(filterElem, {
x: '-50%',
y: '-50%',
width: '200%',
height: '200%'
}, 100);
// Removing these attributes hides text in Chrome (see Issue 579)
- } else if (!blurContext_.isWebkit()) {
+ } else if (!svgCanvas.isWebkit()) {
filterElem.removeAttribute('x');
filterElem.removeAttribute('y');
filterElem.removeAttribute('width');
@@ -99,8 +99,8 @@ export const setBlurOffsets = function (filterElem, stdDev) {
* @returns {void}
*/
export const setBlur = function (val, complete) {
- const selectedElements = blurContext_.getSelectedElements();
- if (blurContext_.getCurCommand()) {
+ const selectedElements = svgCanvas.getSelectedElements();
+ if (svgCanvas.getCurCommand()) {
finishChange();
return;
}
@@ -108,35 +108,35 @@ export const setBlur = function (val, complete) {
// Looks for associated blur, creates one if not found
const elem = selectedElements[0];
const elemId = elem.id;
- blurContext_.setFilter(blurContext_.getCanvas().getElem(elemId + '_blur'));
+ svgCanvas.setFilter(svgCanvas.getElem(elemId + '_blur'));
val -= 0;
const batchCmd = new BatchCommand();
// Blur found!
- if (blurContext_.getFilter()) {
+ if (svgCanvas.getFilter()) {
if (val === 0) {
- blurContext_.setFilter(null);
+ svgCanvas.setFilter(null);
}
} else {
// Not found, so create
- const newblur = blurContext_.getCanvas().addSVGElementFromJson({ element: 'feGaussianBlur',
+ const newblur = svgCanvas.addSVGElemensFromJson({ element: 'feGaussianBlur',
attr: {
in: 'SourceGraphic',
stdDeviation: val
}
});
- blurContext_.setFilter(blurContext_.getCanvas().addSVGElementFromJson({ element: 'filter',
+ svgCanvas.setFilter(svgCanvas.addSVGElemensFromJson({ element: 'filter',
attr: {
id: elemId + '_blur'
}
}));
- blurContext_.getFilter().append(newblur);
- blurContext_.getCanvas().findDefs().append(blurContext_.getFilter());
+ svgCanvas.getFilter().append(newblur);
+ svgCanvas.findDefs().append(svgCanvas.getFilter());
- batchCmd.addSubCommand(new InsertElementCommand(blurContext_.getFilter()));
+ batchCmd.addSubCommand(new InsertElementCommand(svgCanvas.getFilter()));
}
const changes = { filter: elem.getAttribute('filter') };
@@ -147,14 +147,14 @@ export const setBlur = function (val, complete) {
return;
}
- blurContext_.changeSelectedAttributeMethod('filter', 'url(#' + elemId + '_blur)');
+ svgCanvas.changeSelectedAttributeMethod('filter', 'url(#' + elemId + '_blur)');
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
- blurContext_.getCanvas().setBlurOffsets(blurContext_.getFilter(), val);
- const filter = blurContext_.getFilter();
- blurContext_.setCurCommand(batchCmd);
- blurContext_.getCanvas().undoMgr.beginUndoableChange('stdDeviation', [ filter ? filter.firstChild : null ]);
+ svgCanvas.setBlurOffsets(svgCanvas.getFilter(), val);
+ const filter = svgCanvas.getFilter();
+ svgCanvas.setCurCommand(batchCmd);
+ svgCanvas.undoMgr.beginUndoableChange('stdDeviation', [ filter ? filter.firstChild : null ]);
if (complete) {
- blurContext_.getCanvas().setBlurNoUndo(val);
+ svgCanvas.setBlurNoUndo(val);
finishChange();
}
};
diff --git a/src/svgcanvas/clear.js b/src/svgcanvas/clear.js
index 36faac3a..dd51b01f 100644
--- a/src/svgcanvas/clear.js
+++ b/src/svgcanvas/clear.js
@@ -6,27 +6,27 @@
*/
import { NS } from './namespaces.js';
-let clearContext_ = null;
+let svgCanvas = null;
/**
* @function module:clear.init
* @param {module:clear.SvgCanvas#init} clearContext
* @returns {void}
*/
-export const init = function (clearContext) {
- clearContext_ = clearContext;
+export const init = (canvas) => {
+ svgCanvas = canvas;
};
-export const clearSvgContentElementInit = function () {
- const curConfig = clearContext_.getCurConfig();
+export const clearSvgContentElementInit = () => {
+ const curConfig = svgCanvas.getCurConfig();
const { dimensions } = curConfig;
- const el = clearContext_.getSVGContent();
- // empty()
+ const el = svgCanvas.getSvgContent();
+ // empty
while(el.firstChild)
el.removeChild(el.firstChild);
// TODO: Clear out all other attributes first?
- const pel = clearContext_.getSVGRoot();
+ const pel = svgCanvas.getSvgRoot();
el.setAttribute('id', 'svgcontent');
el.setAttribute('width', dimensions[0]);
el.setAttribute('height', dimensions[1]);
@@ -39,6 +39,6 @@ export const clearSvgContentElementInit = function () {
pel.appendChild(el);
// TODO: make this string optional and set by the client
- const comment = clearContext_.getDOMDocument().createComment(' Created with SVG-edit - https://github.com/SVG-Edit/svgedit');
- clearContext_.getSVGContent().append(comment);
+ const comment = svgCanvas.getDOMDocument().createComment(' Created with SVG-edit - https://github.com/SVG-Edit/svgedit');
+ svgCanvas.getSvgContent().append(comment);
};
diff --git a/src/svgcanvas/coords.js b/src/svgcanvas/coords.js
index 7d63f49f..167f3945 100644
--- a/src/svgcanvas/coords.js
+++ b/src/svgcanvas/coords.js
@@ -29,19 +29,19 @@ const pathMap = [
* @returns {module:draw.Drawing}
*/
/**
- * @function module:coords.EditorContext#getSVGRoot
+ * @function module:coords.EditorContext#getSvgRoot
* @returns {SVGSVGElement}
*/
-let editorContext_ = null;
+let svgCanvas = null;
/**
* @function module:coords.init
* @param {module:svgcanvas.SvgCanvas#event:pointsAdded} editorContext
* @returns {void}
*/
-export const init = function (editorContext) {
- editorContext_ = editorContext;
+export const init = function (canvas) {
+ svgCanvas = canvas;
};
/**
@@ -53,7 +53,7 @@ export const remapElement = function (selected, changes, m) {
const remap = (x, y) => transformPoint(x, y, m);
const scalew = (w) => m.a * w;
const scaleh = (h) => m.d * h;
- const doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg';
+ const doSnapping = svgCanvas.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg';
const finishUp = () => {
if (doSnapping) {
Object.entries(changes).forEach(([ o, value ]) => {
@@ -84,7 +84,7 @@ export const remapElement = function (selected, changes, m) {
newgrad.setAttribute('y1', -(y1 - 1));
newgrad.setAttribute('y2', -(y2 - 1));
}
- newgrad.id = editorContext_.getDrawing().getNextId();
+ newgrad.id = svgCanvas.getDrawing().getNextId();
findDefs().append(newgrad);
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
}
@@ -103,7 +103,7 @@ export const remapElement = function (selected, changes, m) {
} else {
// we just absorb all matrices into the element and don't do any remapping
const chlist = selected.transform.baseVal;
- const mt = editorContext_.getSVGRoot().createSVGTransform();
+ const mt = svgCanvas.getSvgRoot().createSVGTransform();
mt.setMatrix(matrixMultiply(transformListToTransform(chlist).matrix, m));
chlist.clear();
chlist.appendItem(mt);
@@ -120,7 +120,7 @@ export const remapElement = function (selected, changes, m) {
if (elName === 'image' && (m.a < 0 || m.d < 0)) {
// Convert to matrix
const chlist = selected.transform.baseVal;
- const mt = editorContext_.getSVGRoot().createSVGTransform();
+ const mt = svgCanvas.getSvgRoot().createSVGTransform();
mt.setMatrix(matrixMultiply(transformListToTransform(chlist).matrix, m));
chlist.clear();
chlist.appendItem(mt);
@@ -171,7 +171,7 @@ export const remapElement = function (selected, changes, m) {
finishUp();
break;
} case 'g': {
- const dataStorage = editorContext_.getDataStorage();
+ const dataStorage = svgCanvas.getDataStorage();
const gsvg = dataStorage.get(selected, 'gsvg');
if (gsvg) {
assignAttributes(gsvg, changes, 1000, true);
diff --git a/src/svgcanvas/draw.js b/src/svgcanvas/draw.js
index b213e1ea..bf090259 100644
--- a/src/svgcanvas/draw.js
+++ b/src/svgcanvas/draw.js
@@ -37,7 +37,7 @@ let disabledElems = [];
* @returns {module:history.HistoryRecordingService}
*/
function historyRecordingService (hrService) {
- return hrService || new HistoryRecordingService(canvas_.undoMgr);
+ return hrService || new HistoryRecordingService(svgCanvas.undoMgr);
}
/**
@@ -720,7 +720,7 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
* @returns {Element[]} the array with selected DOM elements
*/
/**
- * @function module:draw.DrawCanvasInit#getSVGContent
+ * @function module:draw.DrawCanvasInit#getSvgContent
* @returns {SVGSVGElement}
*/
/**
@@ -747,18 +747,18 @@ export const randomizeIds = function (enableRandomization, currentDrawing) {
* @returns {void}
*/
/**
- * @function module:draw.DrawCanvasInit#changeSVGContent
+ * @function module:draw.DrawCanvasInit#changeSvgContent
* @returns {void}
*/
-let canvas_;
+let svgCanvas;
/**
* @function module:draw.init
* @param {module:draw.DrawCanvasInit} canvas
* @returns {void}
*/
export const init = function (canvas) {
- canvas_ = canvas;
+ svgCanvas = canvas;
};
/**
@@ -768,7 +768,7 @@ export const init = function (canvas) {
*/
export const identifyLayers = function () {
leaveContext();
- canvas_.getCurrentDrawing().identifyLayers();
+ svgCanvas.getCurrentDrawing().identifyLayers();
};
/**
@@ -782,12 +782,12 @@ export const identifyLayers = function () {
* @returns {void}
*/
export const createLayer = function (name, hrService) {
- const newLayer = canvas_.getCurrentDrawing().createLayer(
+ const newLayer = svgCanvas.getCurrentDrawing().createLayer(
name,
historyRecordingService(hrService)
);
- canvas_.clearSelection();
- canvas_.call('changed', [ newLayer ]);
+ svgCanvas.clearSelection();
+ svgCanvas.call('changed', [ newLayer ]);
};
/**
@@ -802,11 +802,11 @@ export const createLayer = function (name, hrService) {
*/
export const cloneLayer = function (name, hrService) {
// Clone the current layer and make the cloned layer the new current layer
- const newLayer = canvas_.getCurrentDrawing().cloneLayer(name, historyRecordingService(hrService));
+ const newLayer = svgCanvas.getCurrentDrawing().cloneLayer(name, historyRecordingService(hrService));
- canvas_.clearSelection();
+ svgCanvas.clearSelection();
leaveContext();
- canvas_.call('changed', [ newLayer ]);
+ svgCanvas.call('changed', [ newLayer ]);
};
/**
@@ -817,17 +817,17 @@ export const cloneLayer = function (name, hrService) {
* @returns {boolean} `true` if an old layer group was found to delete
*/
export const deleteCurrentLayer = function () {
- let currentLayer = canvas_.getCurrentDrawing().getCurrentLayer();
+ let currentLayer = svgCanvas.getCurrentDrawing().getCurrentLayer();
const { nextSibling } = currentLayer;
const parent = currentLayer.parentNode;
- currentLayer = canvas_.getCurrentDrawing().deleteCurrentLayer();
+ currentLayer = svgCanvas.getCurrentDrawing().deleteCurrentLayer();
if (currentLayer) {
const batchCmd = new BatchCommand('Delete Layer');
// store in our Undo History
batchCmd.addSubCommand(new RemoveElementCommand(currentLayer, nextSibling, parent));
- canvas_.addCommandToHistory(batchCmd);
- canvas_.clearSelection();
- canvas_.call('changed', [ parent ]);
+ svgCanvas.addCommandToHistory(batchCmd);
+ svgCanvas.clearSelection();
+ svgCanvas.call('changed', [ parent ]);
return true;
}
return false;
@@ -841,9 +841,9 @@ export const deleteCurrentLayer = function () {
* @returns {boolean} true if the current layer was switched, otherwise false
*/
export const setCurrentLayer = function (name) {
- const result = canvas_.getCurrentDrawing().setCurrentLayer(toXml(name));
+ const result = svgCanvas.getCurrentDrawing().setCurrentLayer(toXml(name));
if (result) {
- canvas_.clearSelection();
+ svgCanvas.clearSelection();
}
return result;
};
@@ -858,12 +858,12 @@ export const setCurrentLayer = function (name) {
* @returns {boolean} Whether the rename succeeded
*/
export const renameCurrentLayer = function (newName) {
- const drawing = canvas_.getCurrentDrawing();
+ const drawing = svgCanvas.getCurrentDrawing();
const layer = drawing.getCurrentLayer();
if (layer) {
const result = drawing.setCurrentLayerName(newName, historyRecordingService());
if (result) {
- canvas_.call('changed', [ layer ]);
+ svgCanvas.call('changed', [ layer ]);
return true;
}
}
@@ -880,10 +880,10 @@ export const renameCurrentLayer = function (newName) {
* @returns {boolean} `true` if the current layer position was changed, `false` otherwise.
*/
export const setCurrentLayerPosition = function (newPos) {
- const drawing = canvas_.getCurrentDrawing();
+ const drawing = svgCanvas.getCurrentDrawing();
const result = drawing.setCurrentLayerPosition(newPos);
if (result) {
- canvas_.addCommandToHistory(new MoveElementCommand(result.currentGroup, result.oldNextSibling, canvas_.getSVGContent()));
+ svgCanvas.addCommandToHistory(new MoveElementCommand(result.currentGroup, result.oldNextSibling, svgCanvas.getSvgContent()));
return true;
}
return false;
@@ -898,19 +898,19 @@ export const setCurrentLayerPosition = function (newPos) {
* @returns {boolean} true if the layer's visibility was set, false otherwise
*/
export const setLayerVisibility = function (layerName, bVisible) {
- const drawing = canvas_.getCurrentDrawing();
+ const drawing = svgCanvas.getCurrentDrawing();
const prevVisibility = drawing.getLayerVisibility(layerName);
const layer = drawing.setLayerVisibility(layerName, bVisible);
if (layer) {
const oldDisplay = prevVisibility ? 'inline' : 'none';
- canvas_.addCommandToHistory(new ChangeElementCommand(layer, { display: oldDisplay }, 'Layer Visibility'));
+ svgCanvas.addCommandToHistory(new ChangeElementCommand(layer, { display: oldDisplay }, 'Layer Visibility'));
} else {
return false;
}
if (layer === drawing.getCurrentLayer()) {
- canvas_.clearSelection();
- canvas_.pathActions.clear();
+ svgCanvas.clearSelection();
+ svgCanvas.pathActions.clear();
}
// call('changed', [selected]);
return true;
@@ -925,14 +925,14 @@ export const setLayerVisibility = function (layerName, bVisible) {
*/
export const moveSelectedToLayer = function (layerName) {
// find the layer
- const drawing = canvas_.getCurrentDrawing();
+ const drawing = svgCanvas.getCurrentDrawing();
const layer = drawing.getLayerByName(layerName);
if (!layer) { return false; }
const batchCmd = new BatchCommand('Move Elements to Layer');
// loop for each selected element and move it
- const selElems = canvas_.getSelectedElements();
+ const selElems = svgCanvas.getSelectedElements();
let i = selElems.length;
while (i--) {
const elem = selElems[i];
@@ -944,7 +944,7 @@ export const moveSelectedToLayer = function (layerName) {
batchCmd.addSubCommand(new MoveElementCommand(elem, oldNextSibling, oldLayer));
}
- canvas_.addCommandToHistory(batchCmd);
+ svgCanvas.addCommandToHistory(batchCmd);
return true;
};
@@ -955,10 +955,10 @@ export const moveSelectedToLayer = function (layerName) {
* @returns {void}
*/
export const mergeLayer = function (hrService) {
- canvas_.getCurrentDrawing().mergeLayer(historyRecordingService(hrService));
- canvas_.clearSelection();
+ svgCanvas.getCurrentDrawing().mergeLayer(historyRecordingService(hrService));
+ svgCanvas.clearSelection();
leaveContext();
- canvas_.changeSVGContent();
+ svgCanvas.changeSvgContent();
};
/**
@@ -967,10 +967,10 @@ export const mergeLayer = function (hrService) {
* @returns {void}
*/
export const mergeAllLayers = function (hrService) {
- canvas_.getCurrentDrawing().mergeAllLayers(historyRecordingService(hrService));
- canvas_.clearSelection();
+ svgCanvas.getCurrentDrawing().mergeAllLayers(historyRecordingService(hrService));
+ svgCanvas.clearSelection();
leaveContext();
- canvas_.changeSVGContent();
+ svgCanvas.changeSvgContent();
};
/**
@@ -982,7 +982,7 @@ export const mergeAllLayers = function (hrService) {
*/
export const leaveContext = function () {
const len = disabledElems.length;
- const dataStorage = canvas_.getDataStorage();
+ const dataStorage = svgCanvas.getDataStorage();
if (len) {
for (let i = 0; i < len; i++) {
const elem = disabledElems[i];
@@ -995,10 +995,10 @@ export const leaveContext = function () {
elem.setAttribute('style', 'pointer-events: inherit');
}
disabledElems = [];
- canvas_.clearSelection(true);
- canvas_.call('contextset', null);
+ svgCanvas.clearSelection(true);
+ svgCanvas.call('contextset', null);
}
- canvas_.setCurrentGroup(null);
+ svgCanvas.setCurrentGroup(null);
};
/**
@@ -1009,14 +1009,14 @@ export const leaveContext = function () {
* @returns {void}
*/
export const setContext = function (elem) {
- const dataStorage = canvas_.getDataStorage();
+ const dataStorage = svgCanvas.getDataStorage();
leaveContext();
if (typeof elem === 'string') {
elem = getElem(elem);
}
// Edit inside this group
- canvas_.setCurrentGroup(elem);
+ svgCanvas.setCurrentGroup(elem);
// Disable other elements
const parentsUntil = getParentsUntil(elem, '#svgcontent');
@@ -1038,8 +1038,8 @@ export const setContext = function (elem) {
curthis.setAttribute('style', 'pointer-events: none');
disabledElems.push(curthis);
});
- canvas_.clearSelection();
- canvas_.call('contextset', canvas_.getCurrentGroup());
+ svgCanvas.clearSelection();
+ svgCanvas.call('contextset', svgCanvas.getCurrentGroup());
};
/**
diff --git a/src/svgcanvas/elem-get-set.js b/src/svgcanvas/elem-get-set.js
index c7198042..47250d89 100644
--- a/src/svgcanvas/elem-get-set.js
+++ b/src/svgcanvas/elem-get-set.js
@@ -21,15 +21,15 @@ const {
ChangeElementCommand, BatchCommand
} = hstry;
-let elemContext_ = null;
+let svgCanvas = null;
/**
* @function module:elem-get-set.init
* @param {module:elem-get-set.elemContext} elemContext
* @returns {void}
*/
-export const init = function (elemContext) {
- elemContext_ = elemContext;
+export const init = function (canvas) {
+ svgCanvas = canvas;
};
/**
@@ -37,14 +37,14 @@ export const init = function (elemContext) {
* @returns {DimensionsAndZoom} The current dimensions and zoom level in an object
*/
export const getResolutionMethod = function () {
- const currentZoom = elemContext_.getCurrentZoom();
- const w = elemContext_.getSVGContent().getAttribute('width') / currentZoom;
- const h = elemContext_.getSVGContent().getAttribute('height') / currentZoom;
+ const zoom = svgCanvas.getZoom();
+ const w = svgCanvas.getSvgContent().getAttribute('width') / zoom;
+ const h = svgCanvas.getSvgContent().getAttribute('height') / zoom;
return {
w,
h,
- zoom: currentZoom
+ zoom
};
};
@@ -55,8 +55,8 @@ export const getResolutionMethod = function () {
* `undefined` if no element is passed nd there are no selected elements.
*/
export const getTitleMethod = function (elem) {
- const selectedElements = elemContext_.getSelectedElements();
- const dataStorage = elemContext_.getDataStorage();
+ const selectedElements = svgCanvas.getSelectedElements();
+ const dataStorage = svgCanvas.getDataStorage();
elem = elem || selectedElements[0];
if (!elem) { return undefined; }
if (dataStorage.has(elem, 'gsvg')) {
@@ -81,8 +81,8 @@ export const getTitleMethod = function (elem) {
* @returns {void}
*/
export const setGroupTitleMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
- const dataStorage = elemContext_.getDataStorage();
+ const selectedElements = svgCanvas.getSelectedElements();
+ const dataStorage = svgCanvas.getDataStorage();
let elem = selectedElements[0];
if (dataStorage.has(elem, 'gsvg')) {
elem = dataStorage.get(elem, 'gsvg');
@@ -105,13 +105,13 @@ export const setGroupTitleMethod = function (val) {
title.textContent = val;
} else {
// Add title element
- title = elemContext_.getDOMDocument().createElementNS(NS.SVG, 'title');
+ title = svgCanvas.getDOMDocument().createElementNS(NS.SVG, 'title');
title.textContent = val;
elem.insertBefore(title, elem.firstChild);
batchCmd.addSubCommand(new InsertElementCommand(title));
}
- elemContext_.addCommandToHistory(batchCmd);
+ svgCanvas.addCommandToHistory(batchCmd);
};
/**
@@ -122,7 +122,7 @@ export const setGroupTitleMethod = function (val) {
* @returns {void}
*/
export const setDocumentTitleMethod = function (newTitle) {
- const childs = elemContext_.getSVGContent().childNodes;
+ const childs = svgCanvas.getSvgContent().childNodes;
let docTitle = false; let oldTitle = '';
const batchCmd = new BatchCommand('Change Image Title');
@@ -135,9 +135,9 @@ export const setDocumentTitleMethod = function (newTitle) {
}
}
if (!docTitle) {
- docTitle = elemContext_.getDOMDocument().createElementNS(NS.SVG, 'title');
- elemContext_.getSVGContent().insertBefore(docTitle, elemContext_.getSVGContent().firstChild);
- // svgcontent.firstChild.before(docTitle); // Ok to replace above with this?
+ docTitle = svgCanvas.getDOMDocument().createElementNS(NS.SVG, 'title');
+ svgCanvas.getSvgContent().insertBefore(docTitle, svgCanvas.getSvgContent().firstChild);
+ // svgContent.firstChild.before(docTitle); // Ok to replace above with this?
}
if (newTitle.length) {
@@ -147,7 +147,7 @@ export const setDocumentTitleMethod = function (newTitle) {
docTitle.remove();
}
batchCmd.addSubCommand(new ChangeElementCommand(docTitle, { '#text': oldTitle }));
- elemContext_.addCommandToHistory(batchCmd);
+ svgCanvas.addCommandToHistory(batchCmd);
};
/**
@@ -161,8 +161,8 @@ export const setDocumentTitleMethod = function (newTitle) {
* It will fail on "fit to content" option with no content to fit to.
*/
export const setResolutionMethod = function (x, y) {
- const currentZoom = elemContext_.getCurrentZoom();
- const res = elemContext_.getCanvas().getResolution();
+ const zoom = svgCanvas.getZoom();
+ const res = svgCanvas.getResolution();
const { w, h } = res;
let batchCmd;
@@ -173,16 +173,16 @@ export const setResolutionMethod = function (x, y) {
if (bbox) {
batchCmd = new BatchCommand('Fit Canvas to Content');
const visEls = getVisibleElements();
- elemContext_.getCanvas().addToSelection(visEls);
+ svgCanvas.addToSelection(visEls);
const dx = []; const dy = [];
visEls.forEach(function(_item, _i){
dx.push(bbox.x * -1);
dy.push(bbox.y * -1);
});
- const cmd = elemContext_.getCanvas().moveSelectedElements(dx, dy, true);
+ const cmd = svgCanvas.moveSelectedElements(dx, dy, true);
batchCmd.addSubCommand(cmd);
- elemContext_.getCanvas().clearSelection();
+ svgCanvas.clearSelection();
x = Math.round(bbox.width);
y = Math.round(bbox.height);
@@ -198,18 +198,18 @@ export const setResolutionMethod = function (x, y) {
x = convertToNum('width', x);
y = convertToNum('height', y);
- elemContext_.getSVGContent().setAttribute('width', x);
- elemContext_.getSVGContent().setAttribute('height', y);
+ svgCanvas.getSvgContent().setAttribute('width', x);
+ svgCanvas.getSvgContent().setAttribute('height', y);
this.contentW = x;
this.contentH = y;
- batchCmd.addSubCommand(new ChangeElementCommand(elemContext_.getSVGContent(), { width: w, height: h }));
+ batchCmd.addSubCommand(new ChangeElementCommand(svgCanvas.getSvgContent(), { width: w, height: h }));
- elemContext_.getSVGContent().setAttribute('viewBox', [ 0, 0, x / currentZoom, y / currentZoom ].join(' '));
- batchCmd.addSubCommand(new ChangeElementCommand(elemContext_.getSVGContent(), { viewBox: [ '0 0', w, h ].join(' ') }));
+ svgCanvas.getSvgContent().setAttribute('viewBox', [ 0, 0, x / zoom, y / zoom ].join(' '));
+ batchCmd.addSubCommand(new ChangeElementCommand(svgCanvas.getSvgContent(), { viewBox: [ '0 0', w, h ].join(' ') }));
- elemContext_.addCommandToHistory(batchCmd);
- elemContext_.call('changed', [ elemContext_.getSVGContent() ]);
+ svgCanvas.addCommandToHistory(batchCmd);
+ svgCanvas.call('changed', [ svgCanvas.getSvgContent() ]);
}
return true;
};
@@ -222,7 +222,7 @@ export const setResolutionMethod = function (x, y) {
*/
export const getEditorNSMethod = function (add) {
if (add) {
- elemContext_.getSVGContent().setAttribute('xmlns:se', NS.SE);
+ svgCanvas.getSvgContent().setAttribute('xmlns:se', NS.SE);
}
return NS.SE;
};
@@ -241,8 +241,8 @@ export const getEditorNSMethod = function (add) {
* @returns {module:elem-get-set.ZoomAndBBox|void}
*/
export const setBBoxZoomMethod = function (val, editorW, editorH) {
- const currentZoom = elemContext_.getCurrentZoom();
- const selectedElements = elemContext_.getSelectedElements();
+ const zoom = svgCanvas.getZoom();
+ const selectedElements = svgCanvas.getSelectedElements();
let spacer = 0.85;
let bb;
const calcZoom = function (bb) {
@@ -250,16 +250,16 @@ export const setBBoxZoomMethod = function (val, editorW, editorH) {
const wZoom = Math.round((editorW / bb.width) * 100 * spacer) / 100;
const hZoom = Math.round((editorH / bb.height) * 100 * spacer) / 100;
const zoom = Math.min(wZoom, hZoom);
- elemContext_.getCanvas().setZoom(zoom);
+ svgCanvas.setZoom(zoom);
return { zoom, bbox: bb };
};
if (typeof val === 'object') {
bb = val;
if (bb.width === 0 || bb.height === 0) {
- const newzoom = bb.zoom ? bb.zoom : currentZoom * bb.factor;
- elemContext_.getCanvas().setZoom(newzoom);
- return { zoom: currentZoom, bbox: bb };
+ const newzoom = bb.zoom ? bb.zoom : zoom * bb.factor;
+ svgCanvas.setZoom(newzoom);
+ return { zoom: zoom, bbox: bb };
}
return calcZoom(bb);
}
@@ -276,7 +276,7 @@ export const setBBoxZoomMethod = function (val, editorW, editorH) {
bb = getStrokedBBoxDefaultVisible(selectedElems);
break;
} case 'canvas': {
- const res = elemContext_.getCanvas().getResolution();
+ const res = svgCanvas.getResolution();
spacer = 0.95;
bb = { width: res.w, height: res.h, x: 0, y: 0 };
break;
@@ -284,7 +284,7 @@ export const setBBoxZoomMethod = function (val, editorW, editorH) {
bb = getStrokedBBoxDefaultVisible();
break;
case 'layer':
- bb = getStrokedBBoxDefaultVisible(getVisibleElements(elemContext_.getCanvas().getCurrentDrawing().getCurrentLayer()));
+ bb = getStrokedBBoxDefaultVisible(getVisibleElements(svgCanvas.getCurrentDrawing().getCurrentLayer()));
break;
default:
return undefined;
@@ -300,16 +300,16 @@ export const setBBoxZoomMethod = function (val, editorW, editorH) {
* @returns {void}
*/
export const setZoomMethod = function (zoomLevel) {
- const selectedElements = elemContext_.getSelectedElements();
- const res = elemContext_.getCanvas().getResolution();
- elemContext_.getSVGContent().setAttribute('viewBox', '0 0 ' + res.w / zoomLevel + ' ' + res.h / zoomLevel);
- elemContext_.setCurrentZoom(zoomLevel);
+ const selectedElements = svgCanvas.getSelectedElements();
+ const res = svgCanvas.getResolution();
+ svgCanvas.getSvgContent().setAttribute('viewBox', '0 0 ' + res.w / zoomLevel + ' ' + res.h / zoomLevel);
+ svgCanvas.setZoom(zoomLevel);
selectedElements.forEach(function(elem){
if (!elem) { return; }
- elemContext_.getCanvas().selectorManager.requestSelector(elem).resize();
+ svgCanvas.selectorManager.requestSelector(elem).resize();
});
- elemContext_.getCanvas().pathActions.zoomChange();
- elemContext_.getCanvas().runExtensions('zoomChanged', zoomLevel);
+ svgCanvas.pathActions.zoomChange();
+ svgCanvas.runExtensions('zoomChanged', zoomLevel);
};
/**
@@ -322,9 +322,9 @@ export const setZoomMethod = function (zoomLevel) {
* @returns {void}
*/
export const setColorMethod = function (type, val, preventUndo) {
- const selectedElements = elemContext_.getSelectedElements();
- elemContext_.setCurShape(type, val);
- elemContext_.setCurProperties(type + '_paint', { type: 'solidColor' });
+ const selectedElements = svgCanvas.getSelectedElements();
+ svgCanvas.setCurShape(type, val);
+ svgCanvas.setCurProperties(type + '_paint', { type: 'solidColor' });
const elems = [];
/**
*
@@ -353,10 +353,10 @@ export const setColorMethod = function (type, val, preventUndo) {
}
if (elems.length > 0) {
if (!preventUndo) {
- elemContext_.getCanvas().changeSelectedAttribute(type, val, elems);
- elemContext_.call('changed', elems);
+ svgCanvas.changeSelectedAttribute(type, val, elems);
+ svgCanvas.call('changed', elems);
} else {
- elemContext_.changeSelectedAttributeNoUndoMethod(type, val, elems);
+ svgCanvas.changeSelectedAttributeNoUndoMethod(type, val, elems);
}
}
};
@@ -368,9 +368,9 @@ export const setColorMethod = function (type, val, preventUndo) {
* @returns {void}
*/
export const setGradientMethod = function (type) {
- if (!elemContext_.getCurProperties(type + '_paint') ||
- elemContext_.getCurProperties(type + '_paint').type === 'solidColor') { return; }
- const canvas = elemContext_.getCanvas();
+ if (!svgCanvas.getCurProperties(type + '_paint') ||
+ svgCanvas.getCurProperties(type + '_paint').type === 'solidColor') { return; }
+ const canvas = svgCanvas;
let grad = canvas[type + 'Grad'];
// find out if there is a duplicate gradient already in the defs
const duplicateGrad = findDuplicateGradient(grad);
@@ -378,14 +378,14 @@ export const setGradientMethod = function (type) {
// no duplicate found, so import gradient into defs
if (!duplicateGrad) {
// const origGrad = grad;
- grad = elemContext_.getDOMDocument().importNode(grad, true);
+ grad = svgCanvas.getDOMDocument().importNode(grad, true);
defs.append(grad);
// get next id and set it on the grad
- grad.id = elemContext_.getCanvas().getNextId();
+ grad.id = svgCanvas.getNextId();
} else { // use existing gradient
grad = duplicateGrad;
}
- elemContext_.getCanvas().setColor(type, 'url(#' + grad.id + ')');
+ svgCanvas.setColor(type, 'url(#' + grad.id + ')');
};
/**
@@ -474,15 +474,15 @@ export const setPaintMethod = function (type, paint) {
this.setPaintOpacity(type, p.alpha / 100, true);
// now set the current paint object
- elemContext_.setCurProperties(type + '_paint', p);
+ svgCanvas.setCurProperties(type + '_paint', p);
switch (p.type) {
case 'solidColor':
this.setColor(type, p.solidColor !== 'none' ? '#' + p.solidColor : 'none');
break;
case 'linearGradient':
case 'radialGradient':
- elemContext_.setCanvas(type + 'Grad', p[p.type]);
- elemContext_.getCanvas().setGradient(type);
+ svgCanvas.setCanvas(type + 'Grad', p[p.type]);
+ svgCanvas.setGradient(type);
break;
}
};
@@ -495,12 +495,12 @@ export const setPaintMethod = function (type, paint) {
* @returns {void}
*/
export const setStrokeWidthMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
- if (val === 0 && [ 'line', 'path' ].includes(elemContext_.getCanvas().getMode())) {
- elemContext_.getCanvas().setStrokeWidth(1);
+ const selectedElements = svgCanvas.getSelectedElements();
+ if (val === 0 && [ 'line', 'path' ].includes(svgCanvas.getMode())) {
+ svgCanvas.setStrokeWidth(1);
return;
}
- elemContext_.setCurProperties('stroke_width', val);
+ svgCanvas.setCurProperties('stroke_width', val);
const elems = [];
/**
@@ -525,8 +525,8 @@ export const setStrokeWidthMethod = function (val) {
}
}
if (elems.length > 0) {
- elemContext_.getCanvas().changeSelectedAttribute('stroke-width', val, elems);
- elemContext_.call('changed', selectedElements);
+ svgCanvas.changeSelectedAttribute('stroke-width', val, elems);
+ svgCanvas.call('changed', selectedElements);
}
};
@@ -539,8 +539,8 @@ export const setStrokeWidthMethod = function (val) {
* @returns {void}
*/
export const setStrokeAttrMethod = function (attr, val) {
- const selectedElements = elemContext_.getSelectedElements();
- elemContext_.setCurShape(attr.replace('-', '_'), val);
+ const selectedElements = svgCanvas.getSelectedElements();
+ svgCanvas.setCurShape(attr.replace('-', '_'), val);
const elems = [];
let i = selectedElements.length;
@@ -555,8 +555,8 @@ export const setStrokeAttrMethod = function (attr, val) {
}
}
if (elems.length > 0) {
- elemContext_.getCanvas().changeSelectedAttribute(attr, val, elems);
- elemContext_.call('changed', selectedElements);
+ svgCanvas.changeSelectedAttribute(attr, val, elems);
+ svgCanvas.call('changed', selectedElements);
}
};
/**
@@ -565,7 +565,7 @@ export const setStrokeAttrMethod = function (attr, val) {
* @returns {boolean} Indicates whether or not element is bold
*/
export const getBoldMethod = function () {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
// should only have one element selected
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'text' &&
@@ -582,14 +582,14 @@ export const getBoldMethod = function () {
* @returns {void}
*/
export const setBoldMethod = function (b) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'text' &&
isNullish(selectedElements[1])) {
- elemContext_.getCanvas().changeSelectedAttribute('font-weight', b ? 'bold' : 'normal');
+ svgCanvas.changeSelectedAttribute('font-weight', b ? 'bold' : 'normal');
}
if (!selectedElements[0].textContent) {
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.textActions.setCursor();
}
};
@@ -599,7 +599,7 @@ export const setBoldMethod = function (b) {
* @returns {boolean} Indicates whether or not element is italic
*/
export const getItalicMethod = function () {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'text' &&
isNullish(selectedElements[1])) {
@@ -615,14 +615,14 @@ export const getItalicMethod = function () {
* @returns {void}
*/
export const setItalicMethod = function (i) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'text' &&
isNullish(selectedElements[1])) {
- elemContext_.getCanvas().changeSelectedAttribute('font-style', i ? 'italic' : 'normal');
+ svgCanvas.changeSelectedAttribute('font-style', i ? 'italic' : 'normal');
}
if (!selectedElements[0].textContent) {
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.textActions.setCursor();
}
};
@@ -632,14 +632,14 @@ export const setItalicMethod = function (i) {
* @returns {void}
*/
export const setTextAnchorMethod = function (value) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'text' &&
isNullish(selectedElements[1])) {
- elemContext_.getCanvas().changeSelectedAttribute('text-anchor', value);
+ svgCanvas.changeSelectedAttribute('text-anchor', value);
}
if (!selectedElements[0].textContent) {
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.textActions.setCursor();
}
};
@@ -648,7 +648,7 @@ export const setTextAnchorMethod = function (value) {
* @returns {string} The current font family
*/
export const getFontFamilyMethod = function () {
- return elemContext_.getCurText('font_family');
+ return svgCanvas.getCurText('font_family');
};
/**
@@ -658,11 +658,11 @@ export const getFontFamilyMethod = function () {
* @returns {void}
*/
export const setFontFamilyMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
- elemContext_.setCurText('font_family', val);
- elemContext_.getCanvas().changeSelectedAttribute('font-family', val);
+ const selectedElements = svgCanvas.getSelectedElements();
+ svgCanvas.setCurText('font_family', val);
+ svgCanvas.changeSelectedAttribute('font-family', val);
if (selectedElements[0] && !selectedElements[0].textContent) {
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.textActions.setCursor();
}
};
@@ -673,8 +673,8 @@ export const setFontFamilyMethod = function (val) {
* @returns {void}
*/
export const setFontColorMethod = function (val) {
- elemContext_.setCurText('fill', val);
- elemContext_.getCanvas().changeSelectedAttribute('fill', val);
+ svgCanvas.setCurText('fill', val);
+ svgCanvas.changeSelectedAttribute('fill', val);
};
/**
@@ -682,7 +682,7 @@ export const setFontColorMethod = function (val) {
* @returns {string} The current font color
*/
export const getFontColorMethod = function () {
- return elemContext_.getCurText('fill');
+ return svgCanvas.getCurText('fill');
};
/**
@@ -690,7 +690,7 @@ export const getFontColorMethod = function () {
* @returns {Float} The current font size
*/
export const getFontSizeMethod = function () {
- return elemContext_.getCurText('font_size');
+ return svgCanvas.getCurText('font_size');
};
/**
@@ -700,11 +700,11 @@ export const getFontSizeMethod = function () {
* @returns {void}
*/
export const setFontSizeMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
- elemContext_.setCurText('font_size', val);
- elemContext_.getCanvas().changeSelectedAttribute('font-size', val);
+ const selectedElements = svgCanvas.getSelectedElements();
+ svgCanvas.setCurText('font_size', val);
+ svgCanvas.changeSelectedAttribute('font-size', val);
if (!selectedElements[0].textContent) {
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.textActions.setCursor();
}
};
@@ -713,7 +713,7 @@ export const setFontSizeMethod = function (val) {
* @returns {string} The current text (`textContent`) of the selected element
*/
export const getTextMethod = function () {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (isNullish(selected)) { return ''; }
return (selected) ? selected.textContent : '';
@@ -726,9 +726,9 @@ export const getTextMethod = function () {
* @returns {void}
*/
export const setTextContentMethod = function (val) {
- elemContext_.getCanvas().changeSelectedAttribute('#text', val);
- elemContext_.getCanvas().textActions.init(val);
- elemContext_.getCanvas().textActions.setCursor();
+ svgCanvas.changeSelectedAttribute('#text', val);
+ svgCanvas.textActions.init(val);
+ svgCanvas.textActions.setCursor();
};
/**
@@ -740,7 +740,7 @@ export const setTextContentMethod = function (val) {
* @returns {void}
*/
export const setImageURLMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const elem = selectedElements[0];
if (!elem) { return; }
@@ -772,11 +772,11 @@ export const setImageURLMethod = function (val) {
elem.setAttribute('width', this.width);
elem.setAttribute('height', this.height);
- elemContext_.getCanvas().selectorManager.requestSelector(elem).resize();
+ svgCanvas.selectorManager.requestSelector(elem).resize();
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
- elemContext_.addCommandToHistory(batchCmd);
- elemContext_.call('changed', [ elem ]);
+ svgCanvas.addCommandToHistory(batchCmd);
+ svgCanvas.call('changed', [ elem ]);
};
img.src = val;
};
@@ -788,7 +788,7 @@ export const setImageURLMethod = function (val) {
* @returns {void}
*/
export const setLinkURLMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
let elem = selectedElements[0];
if (!elem) { return; }
if (elem.tagName !== 'a') {
@@ -812,7 +812,7 @@ export const setLinkURLMethod = function (val) {
'#href': curHref
}));
- elemContext_.addCommandToHistory(batchCmd);
+ svgCanvas.addCommandToHistory(batchCmd);
};
/**
@@ -824,15 +824,15 @@ export const setLinkURLMethod = function (val) {
* @returns {void}
*/
export const setRectRadiusMethod = function (val) {
- const selectedElements = elemContext_.getSelectedElements();
+ const selectedElements = svgCanvas.getSelectedElements();
const selected = selectedElements[0];
if (!isNullish(selected) && selected.tagName === 'rect') {
const r = Number(selected.getAttribute('rx'));
if (r !== val) {
selected.setAttribute('rx', val);
selected.setAttribute('ry', val);
- elemContext_.addCommandToHistory(new ChangeElementCommand(selected, { rx: r, ry: r }, 'Radius'));
- elemContext_.call('changed', [ selected ]);
+ svgCanvas.addCommandToHistory(new ChangeElementCommand(selected, { rx: r, ry: r }, 'Radius'));
+ svgCanvas.call('changed', [ selected ]);
}
}
};
@@ -844,7 +844,7 @@ export const setRectRadiusMethod = function (val) {
* @returns {void}
*/
export const makeHyperlinkMethod = function (url) {
- elemContext_.getCanvas().groupSelectedElements('a', url);
+ svgCanvas.groupSelectedElements('a', url);
// TODO: If element is a single "g", convert to "a"
// if (selectedElements.length > 1 && selectedElements[1]) {
@@ -855,7 +855,7 @@ export const makeHyperlinkMethod = function (url) {
* @returns {void}
*/
export const removeHyperlinkMethod = function () {
- elemContext_.getCanvas().ungroupSelectedElement();
+ svgCanvas.ungroupSelectedElement();
};
/**
@@ -869,7 +869,7 @@ export const removeHyperlinkMethod = function () {
* @returns {void}
*/
export const setSegTypeMethod = function (newType) {
- elemContext_.getCanvas().pathActions.setSegType(newType);
+ svgCanvas.pathActions.setSegType(newType);
};
/**
@@ -887,8 +887,8 @@ export const setBackgroundMethod = function (color, url) {
border.setAttribute('fill', color === 'chessboard' ? '#fff' : color);
if (color === 'chessboard') {
if (!bgPattern) {
- bgPattern = elemContext_.getDOMDocument().createElementNS(NS.SVG, 'foreignObject');
- elemContext_.getCanvas().assignAttributes(bgPattern, {
+ bgPattern = svgCanvas.getDOMDocument().createElementNS(NS.SVG, 'foreignObject');
+ svgCanvas.assignAttributes(bgPattern, {
id: 'background_pattern',
width: '100%',
height: '100%',
@@ -896,7 +896,7 @@ export const setBackgroundMethod = function (color, url) {
style: 'pointer-events:none'
});
const div = document.createElement('div');
- elemContext_.getCanvas().assignAttributes(div, {
+ svgCanvas.assignAttributes(div, {
style: 'pointer-events:none;width:100%;height:100%;' +
'background-image:url(data:image/gif;base64,' +
'R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+' +
@@ -910,8 +910,8 @@ export const setBackgroundMethod = function (color, url) {
}
if (url) {
if (!bgImg) {
- bgImg = elemContext_.getDOMDocument().createElementNS(NS.SVG, 'image');
- elemContext_.getCanvas().assignAttributes(bgImg, {
+ bgImg = svgCanvas.getDOMDocument().createElementNS(NS.SVG, 'image');
+ svgCanvas.assignAttributes(bgImg, {
id: 'background_image',
width: '100%',
height: '100%',
diff --git a/src/svgcanvas/event.js b/src/svgcanvas/event.js
index 4d5a3c34..10b93cce 100644
--- a/src/svgcanvas/event.js
+++ b/src/svgcanvas/event.js
@@ -23,23 +23,23 @@ const {
InsertElementCommand
} = hstry;
-let eventContext_ = null;
+let svgCanvas = null;
/**
* @function module:undo.init
* @param {module:undo.eventContext} eventContext
* @returns {void}
*/
-export const init = function (eventContext) {
- eventContext_ = eventContext;
+export const init = (canvas) => {
+ svgCanvas = canvas;
};
-export const getBsplinePoint = function (t) {
+export const getBsplinePoint = (t) => {
const spline = { x: 0, y: 0 };
- const p0 = { x: eventContext_.getControllPoint2('x'), y: eventContext_.getControllPoint2('y') };
- const p1 = { x: eventContext_.getControllPoint1('x'), y: eventContext_.getControllPoint1('y') };
- const p2 = { x: eventContext_.getStart('x'), y: eventContext_.getStart('y') };
- const p3 = { x: eventContext_.getEnd('x'), y: eventContext_.getEnd('y') };
+ const p0 = { x: svgCanvas.getControllPoint2('x'), y: svgCanvas.getControllPoint2('y') };
+ const p1 = { x: svgCanvas.getControllPoint1('x'), y: svgCanvas.getControllPoint1('y') };
+ const p2 = { x: svgCanvas.getStart('x'), y: svgCanvas.getStart('y') };
+ const p3 = { x: svgCanvas.getEnd('x'), y: svgCanvas.getEnd('y') };
const S = 1.0 / 6.0;
const t2 = t * t;
const t3 = t2 * t;
@@ -77,13 +77,12 @@ export const getBsplinePoint = function (t) {
* @fires module:svgcanvas.SvgCanvas#event:ext_mouseMove
* @returns {void}
*/
-export const mouseMoveEvent = function (evt) {
- const selectedElements = eventContext_.getSelectedElements();
- const currentZoom = eventContext_.getCurrentZoom();
- const svgRoot = eventContext_.getSVGRoot();
- const svgCanvas = eventContext_.getCanvas();
+export const mouseMoveEvent = (evt) => {
+ const selectedElements = svgCanvas.getSelectedElements();
+ const zoom = svgCanvas.getZoom();
+ const svgRoot = svgCanvas.getSvgRoot();
- if (!eventContext_.getStarted()) { return; }
+ if (!svgCanvas.getStarted()) { return; }
if (evt.button === 1 || svgCanvas.spaceKey) { return; }
let i;
@@ -96,32 +95,32 @@ export const mouseMoveEvent = function (evt) {
let angle;
let box;
let selected = selectedElements[0];
- const pt = transformPoint(evt.clientX, evt.clientY, eventContext_.getrootSctm());
- const mouseX = pt.x * currentZoom;
- const mouseY = pt.y * currentZoom;
- const shape = getElem(eventContext_.getId());
+ const pt = transformPoint(evt.clientX, evt.clientY, svgCanvas.getrootSctm());
+ const mouseX = pt.x * zoom;
+ const mouseY = pt.y * zoom;
+ const shape = getElem(svgCanvas.getId());
- let realX = mouseX / currentZoom;
+ let realX = mouseX / zoom;
let x = realX;
- let realY = mouseY / currentZoom;
+ let realY = mouseY / zoom;
let y = realY;
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
x = snapToGrid(x);
y = snapToGrid(y);
}
evt.preventDefault();
let tlist;
- switch (eventContext_.getCurrentMode()) {
+ switch (svgCanvas.getCurrentMode()) {
case 'select': {
// we temporarily use a translate on the element(s) being dragged
// this transform is removed upon mousing up and the element is
// relocated to the new location
if (selectedElements[0] !== null) {
- dx = x - eventContext_.getStartX();
- dy = y - eventContext_.getStartY();
- if (eventContext_.getCurConfig().gridSnapping) {
+ dx = x - svgCanvas.getStartX();
+ dy = y - svgCanvas.getStartY();
+ if (svgCanvas.getCurConfig().gridSnapping) {
dx = snapToGrid(dx);
dy = snapToGrid(dy);
}
@@ -155,13 +154,13 @@ export const mouseMoveEvent = function (evt) {
}
break;
} case 'multiselect': {
- realX *= currentZoom;
- realY *= currentZoom;
- assignAttributes(eventContext_.getRubberBox(), {
- x: Math.min(eventContext_.getRStartX(), realX),
- y: Math.min(eventContext_.getRStartY(), realY),
- width: Math.abs(realX - eventContext_.getRStartX()),
- height: Math.abs(realY - eventContext_.getRStartY())
+ realX *= zoom;
+ realY *= zoom;
+ assignAttributes(svgCanvas.getRubberBox(), {
+ x: Math.min(svgCanvas.getRStartX(), realX),
+ y: Math.min(svgCanvas.getRStartY(), realY),
+ width: Math.abs(realX - svgCanvas.getRStartX()),
+ height: Math.abs(realY - svgCanvas.getRStartY())
}, 100);
// for each selected:
@@ -169,7 +168,7 @@ export const mouseMoveEvent = function (evt) {
// - if newList doesn't contain selected, remove it from selected
// - for any newList that was not in selectedElements, add it to selected
const elemsToRemove = selectedElements.slice(); const elemsToAdd = [];
- const newList = eventContext_.getIntersectionList();
+ const newList = svgCanvas.getIntersectionList();
// For every element in the intersection, add if not present in selectedElements.
len = newList.length;
@@ -201,14 +200,14 @@ export const mouseMoveEvent = function (evt) {
// the shape's coordinates
tlist = selected.transform.baseVal;
const hasMatrix = hasMatrixTransform(tlist);
- box = hasMatrix ? eventContext_.getInitBbox() : getBBox(selected);
+ box = hasMatrix ? svgCanvas.getInitBbox() : getBBox(selected);
let left = box.x;
let top = box.y;
let { width, height } = box;
- dx = (x - eventContext_.getStartX());
- dy = (y - eventContext_.getStartY());
+ dx = (x - svgCanvas.getStartX());
+ dy = (y - svgCanvas.getStartY());
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
dx = snapToGrid(dx);
dy = snapToGrid(dy);
height = snapToGrid(height);
@@ -226,10 +225,10 @@ export const mouseMoveEvent = function (evt) {
// if not stretching in y direction, set dy to 0
// if not stretching in x direction, set dx to 0
- if (!eventContext_.getCurrentResizeMode().includes('n') && !eventContext_.getCurrentResizeMode().includes('s')) {
+ if (!svgCanvas.getCurrentResizeMode().includes('n') && !svgCanvas.getCurrentResizeMode().includes('s')) {
dy = 0;
}
- if (!eventContext_.getCurrentResizeMode().includes('e') && !eventContext_.getCurrentResizeMode().includes('w')) {
+ if (!svgCanvas.getCurrentResizeMode().includes('e') && !svgCanvas.getCurrentResizeMode().includes('w')) {
dx = 0;
}
@@ -238,13 +237,13 @@ export const mouseMoveEvent = function (evt) {
let sy = height ? (height + dy) / height : 1;
let sx = width ? (width + dx) / width : 1;
// if we are dragging on the north side, then adjust the scale factor and ty
- if (eventContext_.getCurrentResizeMode().includes('n')) {
+ if (svgCanvas.getCurrentResizeMode().includes('n')) {
sy = height ? (height - dy) / height : 1;
ty = height;
}
// if we dragging on the east side, then adjust the scale factor and tx
- if (eventContext_.getCurrentResizeMode().includes('w')) {
+ if (svgCanvas.getCurrentResizeMode().includes('w')) {
sx = width ? (width - dx) / width : 1;
tx = width;
}
@@ -254,7 +253,7 @@ export const mouseMoveEvent = function (evt) {
const scale = svgRoot.createSVGTransform();
const translateBack = svgRoot.createSVGTransform();
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
left = snapToGrid(left);
tx = snapToGrid(tx);
top = snapToGrid(top);
@@ -287,13 +286,13 @@ export const mouseMoveEvent = function (evt) {
break;
} case 'zoom': {
- realX *= currentZoom;
- realY *= currentZoom;
- assignAttributes(eventContext_.getRubberBox(), {
- x: Math.min(eventContext_.getRStartX() * currentZoom, realX),
- y: Math.min(eventContext_.getRStartY() * currentZoom, realY),
- width: Math.abs(realX - eventContext_.getRStartX() * currentZoom),
- height: Math.abs(realY - eventContext_.getRStartY() * currentZoom)
+ realX *= zoom;
+ realY *= zoom;
+ assignAttributes(svgCanvas.getRubberBox(), {
+ x: Math.min(svgCanvas.getRStartX() * zoom, realX),
+ y: Math.min(svgCanvas.getRStartY() * zoom, realY),
+ width: Math.abs(realX - svgCanvas.getRStartX() * zoom),
+ height: Math.abs(realY - svgCanvas.getRStartY() * zoom)
}, 100);
break;
} case 'text': {
@@ -303,7 +302,7 @@ export const mouseMoveEvent = function (evt) {
}, 1000);
break;
} case 'line': {
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
x = snapToGrid(x);
y = snapToGrid(y);
}
@@ -312,7 +311,7 @@ export const mouseMoveEvent = function (evt) {
let y2 = y;
if (evt.shiftKey) {
- xya = snapToAngle(eventContext_.getStartX(), eventContext_.getStartY(), x2, y2);
+ xya = snapToAngle(svgCanvas.getStartX(), svgCanvas.getStartY(), x2, y2);
x2 = xya.x;
y2 = xya.y;
}
@@ -327,21 +326,21 @@ export const mouseMoveEvent = function (evt) {
case 'rect':
// fall through
case 'image': {
- const square = (eventContext_.getCurrentMode() === 'square') || evt.shiftKey;
+ const square = (svgCanvas.getCurrentMode() === 'square') || evt.shiftKey;
let
- w = Math.abs(x - eventContext_.getStartX());
- let h = Math.abs(y - eventContext_.getStartY());
+ w = Math.abs(x - svgCanvas.getStartX());
+ let h = Math.abs(y - svgCanvas.getStartY());
let newX; let newY;
if (square) {
w = h = Math.max(w, h);
- newX = eventContext_.getStartX() < x ? eventContext_.getStartX() : eventContext_.getStartX() - w;
- newY = eventContext_.getStartY() < y ? eventContext_.getStartY() : eventContext_.getStartY() - h;
+ newX = svgCanvas.getStartX() < x ? svgCanvas.getStartX() : svgCanvas.getStartX() - w;
+ newY = svgCanvas.getStartY() < y ? svgCanvas.getStartY() : svgCanvas.getStartY() - h;
} else {
- newX = Math.min(eventContext_.getStartX(), x);
- newY = Math.min(eventContext_.getStartY(), y);
+ newX = Math.min(svgCanvas.getStartX(), x);
+ newY = Math.min(svgCanvas.getStartY(), y);
}
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
w = snapToGrid(w);
h = snapToGrid(h);
newX = snapToGrid(newX);
@@ -360,7 +359,7 @@ export const mouseMoveEvent = function (evt) {
cx = Number(shape.getAttribute('cx'));
cy = Number(shape.getAttribute('cy'));
let rad = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
rad = snapToGrid(rad);
}
shape.setAttribute('r', rad);
@@ -368,7 +367,7 @@ export const mouseMoveEvent = function (evt) {
} case 'ellipse': {
cx = Number(shape.getAttribute('cx'));
cy = Number(shape.getAttribute('cy'));
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
x = snapToGrid(x);
cx = snapToGrid(cx);
y = snapToGrid(y);
@@ -381,96 +380,96 @@ export const mouseMoveEvent = function (evt) {
}
case 'fhellipse':
case 'fhrect': {
- eventContext_.setFreehand('minx', Math.min(realX, eventContext_.getFreehand('minx')));
- eventContext_.setFreehand('maxx', Math.max(realX, eventContext_.getFreehand('maxx')));
- eventContext_.setFreehand('miny', Math.min(realY, eventContext_.getFreehand('miny')));
- eventContext_.setFreehand('maxy', Math.max(realY, eventContext_.getFreehand('maxy')));
+ svgCanvas.setFreehand('minx', Math.min(realX, svgCanvas.getFreehand('minx')));
+ svgCanvas.setFreehand('maxx', Math.max(realX, svgCanvas.getFreehand('maxx')));
+ svgCanvas.setFreehand('miny', Math.min(realY, svgCanvas.getFreehand('miny')));
+ svgCanvas.setFreehand('maxy', Math.max(realY, svgCanvas.getFreehand('maxy')));
}
// Fallthrough
case 'fhpath': {
// dAttr += + realX + ',' + realY + ' ';
// shape.setAttribute('points', dAttr);
- eventContext_.setEnd('x', realX);
- eventContext_.setEnd('y', realY);
- if (eventContext_.getControllPoint2('x') && eventContext_.getControllPoint2('y')) {
- for (i = 0; i < eventContext_.getStepCount() - 1; i++) {
- eventContext_.setParameter(i / eventContext_.getStepCount());
- eventContext_.setNextParameter((i + 1) / eventContext_.getStepCount());
- eventContext_.setbSpline(getBsplinePoint(eventContext_.getNextParameter()));
- eventContext_.setNextPos({ x: eventContext_.getbSpline('x'), y: eventContext_.getbSpline('y') });
- eventContext_.setbSpline(getBsplinePoint(eventContext_.getParameter()));
- eventContext_.setSumDistance(
- eventContext_.getSumDistance() + Math.sqrt((eventContext_.getNextPos('x') -
- eventContext_.getbSpline('x')) * (eventContext_.getNextPos('x') -
- eventContext_.getbSpline('x')) + (eventContext_.getNextPos('y') -
- eventContext_.getbSpline('y')) * (eventContext_.getNextPos('y') - eventContext_.getbSpline('y')))
+ svgCanvas.setEnd('x', realX);
+ svgCanvas.setEnd('y', realY);
+ if (svgCanvas.getControllPoint2('x') && svgCanvas.getControllPoint2('y')) {
+ for (i = 0; i < svgCanvas.getStepCount() - 1; i++) {
+ svgCanvas.setParameter(i / svgCanvas.getStepCount());
+ svgCanvas.setNextParameter((i + 1) / svgCanvas.getStepCount());
+ svgCanvas.setbSpline(getBsplinePoint(svgCanvas.getNextParameter()));
+ svgCanvas.setNextPos({ x: svgCanvas.getbSpline('x'), y: svgCanvas.getbSpline('y') });
+ svgCanvas.setbSpline(getBsplinePoint(svgCanvas.getParameter()));
+ svgCanvas.setSumDistance(
+ svgCanvas.getSumDistance() + Math.sqrt((svgCanvas.getNextPos('x') -
+ svgCanvas.getbSpline('x')) * (svgCanvas.getNextPos('x') -
+ svgCanvas.getbSpline('x')) + (svgCanvas.getNextPos('y') -
+ svgCanvas.getbSpline('y')) * (svgCanvas.getNextPos('y') - svgCanvas.getbSpline('y')))
);
- if (eventContext_.getSumDistance() > eventContext_.getThreSholdDist()) {
- eventContext_.setSumDistance(eventContext_.getSumDistance() - eventContext_.getThreSholdDist());
+ if (svgCanvas.getSumDistance() > svgCanvas.getThreSholdDist()) {
+ svgCanvas.setSumDistance(svgCanvas.getSumDistance() - svgCanvas.getThreSholdDist());
// Faster than completely re-writing the points attribute.
- const point = eventContext_.getSVGContent().createSVGPoint();
- point.x = eventContext_.getbSpline('x');
- point.y = eventContext_.getbSpline('y');
+ const point = svgCanvas.getSvgContent().createSVGPoint();
+ point.x = svgCanvas.getbSpline('x');
+ point.y = svgCanvas.getbSpline('y');
shape.points.appendItem(point);
}
}
}
- eventContext_.setControllPoint2('x', eventContext_.getControllPoint1('x'));
- eventContext_.setControllPoint2('y', eventContext_.getControllPoint1('y'));
- eventContext_.setControllPoint1('x', eventContext_.getStart('x'));
- eventContext_.setControllPoint1('y', eventContext_.getStart('y'));
- eventContext_.setStart({ x: eventContext_.getEnd('x'), y: eventContext_.getEnd('y') });
+ svgCanvas.setControllPoint2('x', svgCanvas.getControllPoint1('x'));
+ svgCanvas.setControllPoint2('y', svgCanvas.getControllPoint1('y'));
+ svgCanvas.setControllPoint1('x', svgCanvas.getStart('x'));
+ svgCanvas.setControllPoint1('y', svgCanvas.getStart('y'));
+ svgCanvas.setStart({ x: svgCanvas.getEnd('x'), y: svgCanvas.getEnd('y') });
break;
// update path stretch line coordinates
} case 'path':
// fall through
case 'pathedit': {
- x *= currentZoom;
- y *= currentZoom;
+ x *= zoom;
+ y *= zoom;
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
x = snapToGrid(x);
y = snapToGrid(y);
- eventContext_.setStartX(snapToGrid(eventContext_.getStartX()));
- eventContext_.setStartY(snapToGrid(eventContext_.getStartY()));
+ svgCanvas.setStartX(snapToGrid(svgCanvas.getStartX()));
+ svgCanvas.setStartY(snapToGrid(svgCanvas.getStartY()));
}
if (evt.shiftKey) {
const { path } = pathModule;
let x1; let y1;
if (path) {
- x1 = path.dragging ? path.dragging[0] : eventContext_.getStartX();
- y1 = path.dragging ? path.dragging[1] : eventContext_.getStartY();
+ x1 = path.dragging ? path.dragging[0] : svgCanvas.getStartX();
+ y1 = path.dragging ? path.dragging[1] : svgCanvas.getStartY();
} else {
- x1 = eventContext_.getStartX();
- y1 = eventContext_.getStartY();
+ x1 = svgCanvas.getStartX();
+ y1 = svgCanvas.getStartY();
}
xya = snapToAngle(x1, y1, x, y);
({ x, y } = xya);
}
- if (eventContext_.getRubberBox() && eventContext_.getRubberBox().getAttribute('display') !== 'none') {
- realX *= currentZoom;
- realY *= currentZoom;
- assignAttributes(eventContext_.getRubberBox(), {
- x: Math.min(eventContext_.getRStartX() * currentZoom, realX),
- y: Math.min(eventContext_.getRStartY() * currentZoom, realY),
- width: Math.abs(realX - eventContext_.getRStartX() * currentZoom),
- height: Math.abs(realY - eventContext_.getRStartY() * currentZoom)
+ if (svgCanvas.getRubberBox() && svgCanvas.getRubberBox().getAttribute('display') !== 'none') {
+ realX *= zoom;
+ realY *= zoom;
+ assignAttributes(svgCanvas.getRubberBox(), {
+ x: Math.min(svgCanvas.getRStartX() * zoom, realX),
+ y: Math.min(svgCanvas.getRStartY() * zoom, realY),
+ width: Math.abs(realX - svgCanvas.getRStartX() * zoom),
+ height: Math.abs(realY - svgCanvas.getRStartY() * zoom)
}, 100);
}
svgCanvas.pathActions.mouseMove(x, y);
break;
} case 'textedit': {
- x *= currentZoom;
- y *= currentZoom;
- // if (eventContext_.getRubberBox() && eventContext_.getRubberBox().getAttribute('display') !== 'none') {
- // assignAttributes(eventContext_.getRubberBox(), {
- // x: Math.min(eventContext_.getStartX(), x),
- // y: Math.min(eventContext_.getStartY(), y),
- // width: Math.abs(x - eventContext_.getStartX()),
- // height: Math.abs(y - eventContext_.getStartY())
+ x *= zoom;
+ y *= zoom;
+ // if (svgCanvas.getRubberBox() && svgCanvas.getRubberBox().getAttribute('display') !== 'none') {
+ // assignAttributes(svgCanvas.getRubberBox(), {
+ // x: Math.min(svgCanvas.getStartX(), x),
+ // y: Math.min(svgCanvas.getStartY(), y),
+ // width: Math.abs(x - svgCanvas.getStartX()),
+ // height: Math.abs(y - svgCanvas.getStartY())
// }, 100);
// }
@@ -486,7 +485,7 @@ export const mouseMoveEvent = function (evt) {
cx = center.x;
cy = center.y;
angle = ((Math.atan2(cy - y, cx - x) * (180 / Math.PI)) - 90) % 360;
- if (eventContext_.getCurConfig().gridSnapping) {
+ if (svgCanvas.getCurConfig().gridSnapping) {
angle = snapToGrid(angle);
}
if (evt.shiftKey) { // restrict rotations to nice angles (WRS)
@@ -522,10 +521,9 @@ export const mouseMoveEvent = function (evt) {
*
* @returns {void}
*/
-export const mouseOutEvent = function () {
- const svgCanvas = eventContext_.getCanvas();
+export const mouseOutEvent = () => {
const { $id } = svgCanvas;
- if(eventContext_.getCurrentMode() !== 'select' && eventContext_.getStarted()) {
+ if(svgCanvas.getCurrentMode() !== 'select' && svgCanvas.getStarted()) {
const event = new Event("mouseup");
$id('svgcanvas').dispatchEvent(event);
}
@@ -544,39 +542,38 @@ export const mouseOutEvent = function () {
* @fires module:svgcanvas.SvgCanvas#event:ext_mouseUp
* @returns {void}
*/
-export const mouseUpEvent = function (evt) {
- const selectedElements = eventContext_.getSelectedElements();
- const currentZoom = eventContext_.getCurrentZoom();
- const svgCanvas = eventContext_.getCanvas();
+export const mouseUpEvent = (evt) => {
+ const selectedElements = svgCanvas.getSelectedElements();
+ const zoom = svgCanvas.getZoom();
if (evt.button === 2) { return; }
- const tempJustSelected = eventContext_.getJustSelected();
- eventContext_.setJustSelected(null);
- if (!eventContext_.getStarted()) { return; }
- const pt = transformPoint(evt.clientX, evt.clientY, eventContext_.getrootSctm());
- const mouseX = pt.x * currentZoom;
- const mouseY = pt.y * currentZoom;
- const x = mouseX / currentZoom;
- const y = mouseY / currentZoom;
+ const tempJustSelected = svgCanvas.getJustSelected();
+ svgCanvas.setJustSelected(null);
+ if (!svgCanvas.getStarted()) { return; }
+ const pt = transformPoint(evt.clientX, evt.clientY, svgCanvas.getrootSctm());
+ const mouseX = pt.x * zoom;
+ const mouseY = pt.y * zoom;
+ const x = mouseX / zoom;
+ const y = mouseY / zoom;
- let element = getElem(eventContext_.getId());
+ let element = getElem(svgCanvas.getId());
let keep = false;
const realX = x;
const realY = y;
// TODO: Make true when in multi-unit mode
- const useUnit = false; // (eventContext_.getCurConfig().baseUnit !== 'px');
- eventContext_.setStarted(false);
+ const useUnit = false; // (svgCanvas.getCurConfig().baseUnit !== 'px');
+ svgCanvas.setStarted(false);
let t;
- switch (eventContext_.getCurrentMode()) {
+ switch (svgCanvas.getCurrentMode()) {
// intentionally fall-through to select here
case 'resize':
case 'multiselect':
- if (eventContext_.getRubberBox()) {
- eventContext_.getRubberBox().setAttribute('display', 'none');
- eventContext_.setCurBBoxes([]);
+ if (svgCanvas.getRubberBox()) {
+ svgCanvas.getRubberBox().setAttribute('display', 'none');
+ svgCanvas.setCurBBoxes([]);
}
- eventContext_.setCurrentMode('select');
+ svgCanvas.setCurrentMode('select');
// Fallthrough
case 'select':
if (selectedElements[0]) {
@@ -591,26 +588,26 @@ export const mouseUpEvent = function (evt) {
case 'foreignObject':
break;
default:
- eventContext_.setCurProperties('fill', selected.getAttribute('fill'));
- eventContext_.setCurProperties('fill_opacity', selected.getAttribute('fill-opacity'));
- eventContext_.setCurProperties('stroke', selected.getAttribute('stroke'));
- eventContext_.setCurProperties('stroke_opacity', selected.getAttribute('stroke-opacity'));
- eventContext_.setCurProperties('stroke_width', selected.getAttribute('stroke-width'));
- eventContext_.setCurProperties('stroke_dasharray', selected.getAttribute('stroke-dasharray'));
- eventContext_.setCurProperties('stroke_linejoin', selected.getAttribute('stroke-linejoin'));
- eventContext_.setCurProperties('stroke_linecap', selected.getAttribute('stroke-linecap'));
+ svgCanvas.setCurProperties('fill', selected.getAttribute('fill'));
+ svgCanvas.setCurProperties('fill_opacity', selected.getAttribute('fill-opacity'));
+ svgCanvas.setCurProperties('stroke', selected.getAttribute('stroke'));
+ svgCanvas.setCurProperties('stroke_opacity', selected.getAttribute('stroke-opacity'));
+ svgCanvas.setCurProperties('stroke_width', selected.getAttribute('stroke-width'));
+ svgCanvas.setCurProperties('stroke_dasharray', selected.getAttribute('stroke-dasharray'));
+ svgCanvas.setCurProperties('stroke_linejoin', selected.getAttribute('stroke-linejoin'));
+ svgCanvas.setCurProperties('stroke_linecap', selected.getAttribute('stroke-linecap'));
}
if (selected.tagName === 'text') {
- eventContext_.setCurText('font_size', selected.getAttribute('font-size'));
- eventContext_.setCurText('font_family', selected.getAttribute('font-family'));
+ svgCanvas.setCurText('font_size', selected.getAttribute('font-size'));
+ svgCanvas.setCurText('font_family', selected.getAttribute('font-family'));
}
svgCanvas.selectorManager.requestSelector(selected).showGrips(true);
}
// always recalculate dimensions to strip off stray identity transforms
svgCanvas.recalculateAllSelectedDimensions();
// if it was being dragged/resized
- if (realX !== eventContext_.getRStartX() || realY !== eventContext_.getRStartY()) {
+ if (realX !== svgCanvas.getRStartX() || realY !== svgCanvas.getRStartY()) {
const len = selectedElements.length;
for (let i = 0; i < len; ++i) {
if (isNullish(selectedElements[i])) { break; }
@@ -631,7 +628,7 @@ export const mouseUpEvent = function (evt) {
const elem = selectedElements[0];
if (elem) {
elem.removeAttribute('style');
- walkTree(elem, function (el) {
+ walkTree(elem, (el) => {
el.removeAttribute('style');
});
}
@@ -639,15 +636,15 @@ export const mouseUpEvent = function (evt) {
}
return;
case 'zoom': {
- if (!isNullish(eventContext_.getRubberBox())) {
- eventContext_.getRubberBox().setAttribute('display', 'none');
+ if (!isNullish(svgCanvas.getRubberBox())) {
+ svgCanvas.getRubberBox().setAttribute('display', 'none');
}
const factor = evt.shiftKey ? 0.5 : 2;
svgCanvas.call('zoomed', {
- x: Math.min(eventContext_.getRStartX(), realX),
- y: Math.min(eventContext_.getRStartY(), realY),
- width: Math.abs(realX - eventContext_.getRStartX()),
- height: Math.abs(realY - eventContext_.getRStartY()),
+ x: Math.min(svgCanvas.getRStartX(), realX),
+ y: Math.min(svgCanvas.getRStartY(), realY),
+ width: Math.abs(realX - svgCanvas.getRStartX()),
+ height: Math.abs(realY - svgCanvas.getRStartY()),
factor
});
return;
@@ -656,14 +653,14 @@ export const mouseUpEvent = function (evt) {
// causes problems.
// Webkit ignores how we set the points attribute with commas and uses space
// to separate all coordinates, see https://bugs.webkit.org/show_bug.cgi?id=29870
- eventContext_.setSumDistance(0);
- eventContext_.setControllPoint2('x', 0);
- eventContext_.setControllPoint2('y', 0);
- eventContext_.setControllPoint1('x', 0);
- eventContext_.setControllPoint1('y', 0);
- eventContext_.setStart({ x: 0, y: 0 });
- eventContext_.setEnd('x', 0);
- eventContext_.setEnd('y', 0);
+ svgCanvas.setSumDistance(0);
+ svgCanvas.setControllPoint2('x', 0);
+ svgCanvas.setControllPoint2('y', 0);
+ svgCanvas.setControllPoint1('x', 0);
+ svgCanvas.setControllPoint1('y', 0);
+ svgCanvas.setStart({ x: 0, y: 0 });
+ svgCanvas.setEnd('x', 0);
+ svgCanvas.setEnd('y', 0);
const coords = element.getAttribute('points');
const commaIndex = coords.indexOf(',');
keep = commaIndex >= 0 ? coords.includes(',', commaIndex + 1) : coords.includes(' ', coords.indexOf(' ') + 1);
@@ -686,7 +683,7 @@ export const mouseUpEvent = function (evt) {
const width = element.getAttribute('width');
const height = element.getAttribute('height');
// Image should be kept regardless of size (use inherit dimensions later)
- keep = (width || height) || eventContext_.getCurrentMode() === 'image';
+ keep = (width || height) || svgCanvas.getCurrentMode() === 'image';
}
break;
case 'circle':
@@ -699,17 +696,17 @@ export const mouseUpEvent = function (evt) {
}
break;
case 'fhellipse':
- if ((eventContext_.getFreehand('maxx') - eventContext_.getFreehand('minx')) > 0 &&
- (eventContext_.getFreehand('maxy') - eventContext_.getFreehand('miny')) > 0) {
- element = svgCanvas.addSVGElementFromJson({
+ if ((svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')) > 0 &&
+ (svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')) > 0) {
+ element = svgCanvas.addSVGElemensFromJson({
element: 'ellipse',
curStyles: true,
attr: {
- cx: (eventContext_.getFreehand('minx') + eventContext_.getFreehand('maxx')) / 2,
- cy: (eventContext_.getFreehand('miny') + eventContext_.getFreehand('maxy')) / 2,
- rx: (eventContext_.getFreehand('maxx') - eventContext_.getFreehand('minx')) / 2,
- ry: (eventContext_.getFreehand('maxy') - eventContext_.getFreehand('miny')) / 2,
- id: eventContext_.getId()
+ cx: (svgCanvas.getFreehand('minx') + svgCanvas.getFreehand('maxx')) / 2,
+ cy: (svgCanvas.getFreehand('miny') + svgCanvas.getFreehand('maxy')) / 2,
+ rx: (svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')) / 2,
+ ry: (svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')) / 2,
+ id: svgCanvas.getId()
}
});
svgCanvas.call('changed', [ element ]);
@@ -717,17 +714,17 @@ export const mouseUpEvent = function (evt) {
}
break;
case 'fhrect':
- if ((eventContext_.getFreehand('maxx') - eventContext_.getFreehand('minx')) > 0 &&
- (eventContext_.getFreehand('maxy') - eventContext_.getFreehand('miny')) > 0) {
- element = svgCanvas.addSVGElementFromJson({
+ if ((svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')) > 0 &&
+ (svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')) > 0) {
+ element = svgCanvas.addSVGElemensFromJson({
element: 'rect',
curStyles: true,
attr: {
- x: eventContext_.getFreehand('minx'),
- y: eventContext_.getFreehand('miny'),
- width: (eventContext_.getFreehand('maxx') - eventContext_.getFreehand('minx')),
- height: (eventContext_.getFreehand('maxy') - eventContext_.getFreehand('miny')),
- id: eventContext_.getId()
+ x: svgCanvas.getFreehand('minx'),
+ y: svgCanvas.getFreehand('miny'),
+ width: (svgCanvas.getFreehand('maxx') - svgCanvas.getFreehand('minx')),
+ height: (svgCanvas.getFreehand('maxy') - svgCanvas.getFreehand('miny')),
+ id: svgCanvas.getId()
}
});
svgCanvas.call('changed', [ element ]);
@@ -743,7 +740,7 @@ export const mouseUpEvent = function (evt) {
// set element to null here so that it is not removed nor finalized
element = null;
// continue to be set to true so that mouseMove happens
- eventContext_.setStarted(true);
+ svgCanvas.setStarted(true);
const res = svgCanvas.pathActions.mouseUp(evt, element, mouseX, mouseY);
({ element } = res);
@@ -762,10 +759,10 @@ export const mouseUpEvent = function (evt) {
case 'rotate': {
keep = true;
element = null;
- eventContext_.setCurrentMode('select');
+ svgCanvas.setCurrentMode('select');
const batchCmd = svgCanvas.undoMgr.finishUndoableChange();
if (!batchCmd.isEmpty()) {
- eventContext_.addCommandToHistory(batchCmd);
+ svgCanvas.addCommandToHistory(batchCmd);
}
// perform recalculation to weed out any stray identity transforms that might get stuck
svgCanvas.recalculateAllSelectedDimensions();
@@ -794,12 +791,12 @@ export const mouseUpEvent = function (evt) {
if (r) {
keep = r.keep || keep;
({ element } = r);
- eventContext_.setStarted(r.started || eventContext_.getStarted());
+ svgCanvas.setStarted(r.started || svgCanvas.getStarted());
}
});
if (!keep && !isNullish(element)) {
- svgCanvas.getCurrentDrawing().releaseId(eventContext_.getId());
+ svgCanvas.getCurrentDrawing().releaseId(svgCanvas.getId());
element.remove();
element = null;
@@ -814,7 +811,7 @@ export const mouseUpEvent = function (evt) {
// if we are not in the middle of creating a path, and we've clicked on some shape,
// then go to Select mode.
// WebKit returns
when the canvas is clicked, Firefox/Opera return