- Linting (ESLint): Stricter rules (or switch to warning)

- Breaking internal API change: `updateGripCursor` moved to be class method of Selector rather than instance method
- Breaking internal API change: `subpathIsClosed` moved to be class method of `Path` rather than instance method
- Refactoring: Reuse utilities base64 encoder for SVG icons plugin
- Docs (JSDoc): Fix return of the `mouseUp` (can also be an object) and `mouseDown` (may also be a boolean) of `pathActions`; other JSDoc additions/improvements
This commit is contained in:
Brett Zamir
2018-11-07 14:51:50 +08:00
parent 901c9547fe
commit 7c470e9909
126 changed files with 2081 additions and 1373 deletions

View File

@@ -14,13 +14,24 @@ QUnit.log((details) => {
const currentLayer = document.getElementById('layer1');
/**
* Create an SVG element for a mock.
* @param {module:utilities.SVGElementJSON} jsonMap
* @returns {SVGElement}
*/
function mockCreateSVGElement (jsonMap) {
const elem = document.createElementNS(NS.SVG, jsonMap['element']);
for (const attr in jsonMap['attr']) {
elem.setAttribute(attr, jsonMap['attr'][attr]);
}
const elem = document.createElementNS(NS.SVG, jsonMap.element);
Object.entries(jsonMap.attr).forEach(([attr, value]) => {
elem.setAttribute(attr, value);
});
return elem;
}
/**
* Mock of {@link module:utilities.EditorContext#addSVGElementFromJson}.
* @param {module:utilities.SVGElementJSON} json
* @returns {SVGElement}
*/
function mockaddSVGElementFromJson (json) {
const elem = mockCreateSVGElement(json);
currentLayer.append(elem);
@@ -31,27 +42,28 @@ function mockaddSVGElementFromJson (json) {
const groupWithMatrixTransform = document.getElementById('svg_group_with_matrix_transform');
const textWithMatrixTransform = document.getElementById('svg_text_with_matrix_transform');
/**
* Toward performance testing, fill document with clones of element.
* @param {SVGElement} elem
* @param {Integer} count
* @returns {undefined}
*/
function fillDocumentByCloningElement (elem, count) {
const elemId = elem.getAttribute('id') + '-';
for (let index = 0; index < count; index++) {
const clone = elem.cloneNode(true); // t: deep clone
// Make sure you set a unique ID like a real document.
clone.setAttribute('id', elemId + index);
const parent = elem.parentNode;
parent.append(clone);
const {parentNode} = elem;
parentNode.append(clone);
}
}
QUnit.module('svgedit.utilities_performance', {
beforeEach () {
},
afterEach () {
}
});
QUnit.module('svgedit.utilities_performance');
const mockPathActions = {
resetOrientation (path) {
if (path == null || path.nodeName !== 'path') { return false; }
if (utilities.isNullish(path) || path.nodeName !== 'path') { return false; }
const tlist = transformlist.getTransformList(path);
const m = math.transformListToTransform(tlist).matrix;
tlist.clear();
@@ -64,10 +76,13 @@ const mockPathActions = {
for (let i = 0; i < len; ++i) {
const seg = segList.getItem(i);
const type = seg.pathSegType;
if (type === 1) { continue; }
if (type === 1) {
continue;
}
const pts = [];
['', 1, 2].forEach(function (n, j) {
const x = seg['x' + n], y = seg['y' + n];
const x = seg['x' + n],
y = seg['y' + n];
if (x !== undefined && y !== undefined) {
const pt = math.transformPoint(x, y, m);
pts.splice(pts.length, 0, pt.x, pt.y);
@@ -77,6 +92,7 @@ const mockPathActions = {
}
// utilities.reorientGrads(path, m);
return undefined;
}
};
@@ -144,11 +160,11 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
// The second pass is two to ten times faster.
setTimeout(function () {
const count = children.length;
const ct = children.length;
const start = lastTime = now = Date.now();
const strt = lastTime = now = Date.now();
// Skip the first child which is the title.
for (let index = 1; index < count; index++) {
for (let index = 1; index < ct; index++) {
const child = children[index];
/* const obj = */ getStrokedBBox([child], mockaddSVGElementFromJson, mockPathActions);
now = Date.now(); const delta = now - lastTime; lastTime = now;
@@ -157,10 +173,10 @@ QUnit.test('Test svgCanvas.getStrokedBBox() performance with matrix transforms',
max = Math.max(max, delta);
}
total = lastTime - start;
const ave = total / count;
assert.ok(ave < 2, 'svgedit.utilities.getStrokedBBox average execution time is less than 1 ms');
console.log('Pass2 svgCanvas.getStrokedBBox total ms ' + total + ', ave ms ' + ave.toFixed(1) + ',\t min/max ' + min + ' ' + max);
total = lastTime - strt;
const avg = total / ct;
assert.ok(avg < 2, 'svgedit.utilities.getStrokedBBox average execution time is less than 1 ms');
console.log('Pass2 svgCanvas.getStrokedBBox total ms ' + total + ', ave ms ' + avg.toFixed(1) + ',\t min/max ' + min + ' ' + max);
done();
});