diff --git a/.eslintrc.js b/.eslintrc.js index 681f0768..ed2edc3a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,7 @@ module.exports = { "plugin:sonarjs/recommended", "eslint:recommended" ], - plugins: ["jsdoc", "promise", "html", "import", "sonarjs"], + plugins: [ "jsdoc", "promise", "html", "import", "sonarjs" ], parserOptions: { ecmaVersion: 2020, sourceType: "module" @@ -22,15 +22,19 @@ module.exports = { }, rules: { "node/no-unsupported-features/es-syntax": 0, - "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], - "sonarjs/cognitive-complexity": ["warn", 40], + "no-unused-vars": [ "error", { "argsIgnorePattern": "^_" } ], + "sonarjs/cognitive-complexity": [ "warn", 40 ], "sonarjs/no-duplicate-string": 0, "semi" : "error", + "no-trailing-spaces": "error", + "array-bracket-spacing": [ "error", "always" ], + "comma-spacing": "error", + "object-curly-spacing": [ "error", "always" ], }, overrides: [ { - files: [ 'cypress/**/*'], - extends: [ + files: [ 'cypress/**/*' ], + extends: [ "plugin:cypress/recommended" ], env: { @@ -42,12 +46,12 @@ module.exports = { }, rules: { // with ci, instrumented is not created before linter - "import/no-unresolved": [2, { ignore: ['instrumented'] }], + "import/no-unresolved": [ 2, { ignore: [ 'instrumented' ] } ], "node/no-missing-import": 0 } }, { - files: [ 'docs/**/*'], + files: [ 'docs/**/*' ], rules: { // md files have example that don't need a strict checking "no-undef": 0, "import/no-unresolved": 0, diff --git a/cypress/integration/ui/accessibility.js b/cypress/integration/ui/accessibility.js index 5ee13042..bb383668 100644 --- a/cypress/integration/ui/accessibility.js +++ b/cypress/integration/ui/accessibility.js @@ -13,10 +13,10 @@ describe('UI - Accessibility', function () { cy.configureAxe({ // Todo: Reenable when have time to fix // See https://www.deque.com/axe/axe-for-web/documentation/api-documentation/#user-content-parameters-1 - rules: [{ + rules: [ { id: 'meta-viewport', enabled: false - }] + } ] /* branding: { brand: String, @@ -32,10 +32,10 @@ describe('UI - Accessibility', function () { {}, { rules: { - 'label-title-only': {enabled: false}, - 'page-has-heading-one': {enabled: false}, - region: {enabled: false}, - 'scrollable-region-focusable': {enabled: false} + 'label-title-only': { enabled: false }, + 'page-has-heading-one': { enabled: false }, + region: { enabled: false }, + 'scrollable-region-focusable': { enabled: false } } } ); diff --git a/cypress/integration/ui/clipboard.js b/cypress/integration/ui/clipboard.js index d9bbb944..26d423b6 100644 --- a/cypress/integration/ui/clipboard.js +++ b/cypress/integration/ui/clipboard.js @@ -11,13 +11,13 @@ describe('UI - Clipboard', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 - `, {force: true, parseSpecialCharSequences: false}); + `, { force: true, parseSpecialCharSequences: false }); cy.get('#tool_source_save').click(); cy.get('#testCircle').should('exist'); cy.get('#svg_1').should('not.exist'); @@ -25,20 +25,20 @@ describe('UI - Clipboard', function () { // Copy. cy.get('#testCircle').click().rightclick(); - cy.get('#cmenu_canvas a[href="#copy"]').click({force: true}); + cy.get('#cmenu_canvas a[href="#copy"]').click({ force: true }); // Paste. // Scrollbars fail to recenter in Cypress test. Works fine in reality. // Thus forcing click is needed since workspace is mostly offscreen. - cy.get('#svgroot').rightclick({force: true}); - cy.get('#cmenu_canvas a[href="#paste"]').click({force: true}); + cy.get('#svgroot').rightclick({ force: true }); + cy.get('#cmenu_canvas a[href="#paste"]').click({ force: true }); cy.get('#testCircle').should('exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('not.exist'); // Cut. cy.get('#testCircle').click().rightclick(); - cy.get('#cmenu_canvas a[href="#cut"]').click({force: true}); + cy.get('#cmenu_canvas a[href="#cut"]').click({ force: true }); cy.get('#testCircle').should('not.exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('not.exist'); @@ -46,17 +46,17 @@ describe('UI - Clipboard', function () { // Paste. // Scrollbars fail to recenter in Cypress test. Works fine in reality. // Thus forcing click is needed since workspace is mostly offscreen. - cy.get('#svgroot').rightclick({force: true}); - cy.get('#cmenu_canvas a[href="#paste"]').click({force: true}); + cy.get('#svgroot').rightclick({ force: true }); + cy.get('#cmenu_canvas a[href="#paste"]').click({ force: true }); cy.get('#testCircle').should('not.exist'); cy.get('#svg_1').should('exist'); cy.get('#svg_2').should('exist'); // Delete. cy.get('#svg_2').click().rightclick(); - cy.get('#cmenu_canvas a[href="#delete"]').click({force: true}); + cy.get('#cmenu_canvas a[href="#delete"]').click({ force: true }); cy.get('#svg_1').click().rightclick(); - cy.get('#cmenu_canvas a[href="#delete"]').click({force: true}); + cy.get('#cmenu_canvas a[href="#delete"]').click({ force: true }); cy.get('#svg_1').should('not.exist'); cy.get('#svg_2').should('not.exist'); }); diff --git a/cypress/integration/ui/control-points.js b/cypress/integration/ui/control-points.js index 4f1fe7a3..0dcc6c3c 100644 --- a/cypress/integration/ui/control-points.js +++ b/cypress/integration/ui/control-points.js @@ -11,23 +11,23 @@ describe('UI - Control Points', function () { const randomOffset = () => 2 + Math.round(10 + Math.random() * 40); cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 - `, {force: true, parseSpecialCharSequences: false}); - cy.get('#tool_source_save').click({force: true}); + `, { force: true, parseSpecialCharSequences: false }); + cy.get('#tool_source_save').click({ force: true }); - cy.get('#svg_1').click({force: true}).click({force: true}); + cy.get('#svg_1').click({ force: true }).click({ force: true }); - cy.get('#pathpointgrip_0').trigger('mousedown', {which: 1, force: true}) - .trigger('mousemove', randomOffset(), randomOffset(), {force: true}) - .trigger('mouseup', {force: true}); - cy.get('#pathpointgrip_1').trigger('mousedown', {which: 1, force: true}) - .trigger('mousemove', randomOffset(), randomOffset(), {force: true}) - .trigger('mouseup', {force: true}); + cy.get('#pathpointgrip_0').trigger('mousedown', { which: 1, force: true }) + .trigger('mousemove', randomOffset(), randomOffset(), { force: true }) + .trigger('mouseup', { force: true }); + cy.get('#pathpointgrip_1').trigger('mousedown', { which: 1, force: true }) + .trigger('mousemove', randomOffset(), randomOffset(), { force: true }) + .trigger('mouseup', { force: true }); cy.get('#svg_1[d]').should('not.contain', 'NaN'); }); diff --git a/cypress/integration/ui/export.js b/cypress/integration/ui/export.js index 48d68ba2..f77877c8 100644 --- a/cypress/integration/ui/export.js +++ b/cypress/integration/ui/export.js @@ -14,7 +14,7 @@ describe('UI - Export tests', function () { it('Editor - No parameters: Export button clicking; dialog opens', () => { openMainMenu(); - cy.get('#tool_export').click({force: true}); + cy.get('#tool_export').click({ force: true }); cy.get('#dialog_content select'); }); }); diff --git a/cypress/integration/ui/issues/issue-359.js b/cypress/integration/ui/issues/issue-359.js index fed05e2f..d93fb5b9 100644 --- a/cypress/integration/ui/issues/issue-359.js +++ b/cypress/integration/ui/issues/issue-359.js @@ -11,13 +11,13 @@ describe('Fix issue 359', function () { it('can undo without throwing', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 - `, {parseSpecialCharSequences: false, force: true}); + `, { parseSpecialCharSequences: false, force: true }); cy.get('#tool_source_save').click(); cy.get('#tool_undo').click(); cy.get('#tool_redo').click(); // test also redo to make the test more comprehensive diff --git a/cypress/integration/ui/issues/issue-407.js b/cypress/integration/ui/issues/issue-407.js index 69e67875..a7597aed 100644 --- a/cypress/integration/ui/issues/issue-407.js +++ b/cypress/integration/ui/issues/issue-407.js @@ -11,7 +11,7 @@ describe('Fix issue 407', function () { it('can enter edit on text child', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 @@ -20,16 +20,16 @@ describe('Fix issue 407', function () { hello - `, {force: true, parseSpecialCharSequences: false}); + `, { force: true, parseSpecialCharSequences: false }); cy.get('#tool_source_save').click(); cy.get('#svg_1').click().dblclick(); cy.get('#a_text').should('exist'); cy.get('#a_text') - .trigger('mousedown', {which: 1, force: true}) - .trigger('mouseup', {force: true}) - .dblclick({force: true}); + .trigger('mousedown', { which: 1, force: true }) + .trigger('mouseup', { force: true }) + .dblclick({ force: true }); // svgedit use the #text text field to capture the text - cy.get('#text').type('1234', {force: true}); + cy.get('#text').type('1234', { force: true }); cy.get('#a_text').should('have.text', 'he1234llo'); }); }); diff --git a/cypress/integration/ui/issues/issue-408.js b/cypress/integration/ui/issues/issue-408.js index b7524235..fdf1bb32 100644 --- a/cypress/integration/ui/issues/issue-408.js +++ b/cypress/integration/ui/issues/issue-408.js @@ -11,7 +11,7 @@ describe('Fix issue 408', function () { it('should not throw when showing/saving svg content', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 @@ -20,7 +20,7 @@ describe('Fix issue 408', function () { - `, {force: true, parseSpecialCharSequences: false}); + `, { force: true, parseSpecialCharSequences: false }); cy.get('#tool_source_save').click(); cy.get('#svg_6').click().dblclick(); // change context cy.get('#tool_source').click(); // reopen tool_source diff --git a/cypress/integration/ui/issues/issue-423.js b/cypress/integration/ui/issues/issue-423.js index 005d2311..6ab956fc 100644 --- a/cypress/integration/ui/issues/issue-423.js +++ b/cypress/integration/ui/issues/issue-423.js @@ -11,7 +11,7 @@ describe('Fix issue 423', function () { it('should not throw when undoing the move', function () { cy.get('#tool_source').click(); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 @@ -22,12 +22,12 @@ describe('Fix issue 423', function () { - `, {parseSpecialCharSequences: false, force: true}); - cy.get('#tool_source_save').click({force: true}); + `, { parseSpecialCharSequences: false, force: true }); + cy.get('#tool_source_save').click({ force: true }); cy.get('#TANK1') - .trigger('mousedown', {force: true}) - .trigger('mousemove', 50, 0, {force: true}) - .trigger('mouseup', {force: true}); - cy.get('#tool_undo').click({force: true}); + .trigger('mousedown', { force: true }) + .trigger('mousemove', 50, 0, { force: true }) + .trigger('mouseup', { force: true }); + cy.get('#tool_undo').click({ force: true }); }); }); diff --git a/cypress/integration/ui/scenario.js b/cypress/integration/ui/scenario.js index e5566709..df1eec6a 100644 --- a/cypress/integration/ui/scenario.js +++ b/cypress/integration/ui/scenario.js @@ -12,97 +12,97 @@ describe('use various parts of svg-edit', function () { }); it('check tool_source', function () { - cy.get('#tool_source').click({force: true}); + cy.get('#tool_source').click({ force: true }); cy.get('#svg_source_textarea') - .type('{selectall}', {force: true}) + .type('{selectall}', { force: true }) .type(` Layer 1 - `, {force: true, parseSpecialCharSequences: false}); - cy.get('#tool_source_save').click({force: true}); + `, { force: true, parseSpecialCharSequences: false }); + cy.get('#tool_source_save').click({ force: true }); testSnapshot(); }); it('check tool_fhpath', function () { cy.get('#tool_fhpath') - .click({force: true}); + .click({ force: true }); cy.get('#rect') - .trigger('mousemove', 200, 200, {force: true}) - .trigger('mousedown', 200, 200, {force: true}) - .trigger('mousemove', 20, 20, {force: true}) - .trigger('mouseup', {force: true}); + .trigger('mousemove', 200, 200, { force: true }) + .trigger('mousedown', 200, 200, { force: true }) + .trigger('mousemove', 20, 20, { force: true }) + .trigger('mouseup', { force: true }); cy.get('#svgcontent').toMatchSnapshot(); }); it('check tool_text', function () { cy.get('#tool_text') - .click({force: true}); + .click({ force: true }); cy.get('#rect') - .trigger('mousedown', 46, 35, {force: true}) - .trigger('mouseup', {force: true}); + .trigger('mousedown', 46, 35, { force: true }) + .trigger('mouseup', { force: true }); // svgedit use the #text text field to capture the text - cy.get('#text').type('AB', {force: true}); + cy.get('#text').type('AB', { force: true }); testSnapshot(); }); it('check tool_clone', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_clone') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_italic', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_italic') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_bold', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_bold') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check change color', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('[data-rgb="#ffff00"]') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_text_anchor_start', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_text_anchor_start') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_text_anchor_middle', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_text_anchor_middle') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_text_anchor_end', function () { - cy.get('#svg_1').click({force: true}); + cy.get('#svg_1').click({ force: true }); cy.get('#tool_text_anchor_end') - .click({force: true}); + .click({ force: true }); testSnapshot(); }); it('check tool_star', function () { cy.get('#tool_star') - .click({force: true}); + .click({ force: true }); cy.get('#svgcontent') - .trigger('mousedown', 300, 150, {force: true}) - .trigger('mousemove', 300, 250, {force: true}) - .trigger('mouseup', {force: true}); + .trigger('mousedown', 300, 150, { force: true }) + .trigger('mousemove', 300, 250, { force: true }) + .trigger('mouseup', { force: true }); testSnapshot(); }); it('check tool_polygon', function () { cy.get('#tool_polygon') - .click({force: true}); + .click({ force: true }); cy.get('#svgcontent') - .trigger('mousedown', 350, 250, {force: true}) - .trigger('mousemove', 350, 370, {force: true}) - .trigger('mouseup', {force: true}); + .trigger('mousedown', 350, 250, { force: true }) + .trigger('mousemove', 350, 370, { force: true }) + .trigger('mouseup', { force: true }); testSnapshot(); }); }); diff --git a/cypress/integration/ui/tool-selection.js b/cypress/integration/ui/tool-selection.js index d96d37b2..c2e63289 100644 --- a/cypress/integration/ui/tool-selection.js +++ b/cypress/integration/ui/tool-selection.js @@ -11,7 +11,7 @@ describe('UI - Tool selection', function () { cy.get('#tools_rect') .should('not.have.attr', 'pressed'); cy.get('#tools_rect') - .trigger('click', {force: true}) + .trigger('click', { force: true }) .should('have.attr', 'pressed'); }); }); diff --git a/cypress/integration/unit/contextmenu.js b/cypress/integration/unit/contextmenu.js index ef3fce6d..63e15a2f 100644 --- a/cypress/integration/unit/contextmenu.js +++ b/cypress/integration/unit/contextmenu.js @@ -19,26 +19,26 @@ describe('contextmenu', function () { it('Test svgedit.contextmenu does not add invalid menu item', function () { assert.throws( - () => contextmenu.add({id: 'justanid'}), + () => contextmenu.add({ id: 'justanid' }), null, null, 'menu item with just an id is invalid' ); assert.throws( - () => contextmenu.add({id: 'idandlabel', label: 'anicelabel'}), + () => contextmenu.add({ id: 'idandlabel', label: 'anicelabel' }), null, null, 'menu item with just an id and label is invalid' ); assert.throws( - () => contextmenu.add({id: 'idandlabel', label: 'anicelabel', action: 'notafunction'}), + () => contextmenu.add({ id: 'idandlabel', label: 'anicelabel', action: 'notafunction' }), null, null, 'menu item with action that is not a function is invalid' ); }); it('Test svgedit.contextmenu adds valid menu item', function () { - const validItem = {id: 'valid', label: 'anicelabel', action () { /* empty fn */ }}; + const validItem = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }; contextmenu.add(validItem); assert.ok(contextmenu.hasCustomHandler('valid'), 'Valid menu item is added.'); @@ -46,8 +46,8 @@ describe('contextmenu', function () { }); it('Test svgedit.contextmenu rejects valid duplicate menu item id', function () { - const validItem1 = {id: 'valid', label: 'anicelabel', action () { /* empty fn */ }}; - const validItem2 = {id: 'valid', label: 'anicelabel', action () { /* empty fn */ }}; + const validItem1 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }; + const validItem2 = { id: 'valid', label: 'anicelabel', action () { /* empty fn */ } }; contextmenu.add(validItem1); assert.throws( diff --git a/cypress/integration/unit/coords.js b/cypress/integration/unit/coords.js index 51dd7ee0..22fcd23f 100644 --- a/cypress/integration/unit/coords.js +++ b/cypress/integration/unit/coords.js @@ -1,6 +1,6 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import * as coords from '../../../instrumented/svgcanvas/coords.js'; diff --git a/cypress/integration/unit/draw.js b/cypress/integration/unit/draw.js index 0bb610bf..f18338e5 100644 --- a/cypress/integration/unit/draw.js +++ b/cypress/integration/unit/draw.js @@ -1,6 +1,6 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as draw from '../../../instrumented/svgcanvas/draw.js'; import * as units from '../../../instrumented/common/units.js'; @@ -61,7 +61,7 @@ describe('draw.Drawing', function () { */ function createSVGElement (jsonMap) { const elem = document.createElementNS(NS.SVG, jsonMap.element); - Object.entries(jsonMap.attr).forEach(([attr, value]) => { + Object.entries(jsonMap.attr).forEach(([ attr, value ]) => { elem.setAttribute(attr, value); }); return elem; @@ -86,7 +86,7 @@ describe('draw.Drawing', function () { layer3.append(layer3Title); svgElem.append(layer3); - return [layer1, layer2, layer3]; + return [ layer1, layer2, layer3 ]; }; const createSomeElementsInGroup = function (group) { @@ -101,11 +101,11 @@ describe('draw.Drawing', function () { // }), createSVGElement({ element: 'rect', - attr: {x: '0', y: '1', width: '5', height: '10'} + attr: { x: '0', y: '1', width: '5', height: '10' } }), createSVGElement({ element: 'line', - attr: {x1: '0', y1: '1', x2: '5', y2: '6'} + attr: { x1: '0', y1: '1', x2: '5', y2: '6' } }) ); @@ -115,7 +115,7 @@ describe('draw.Drawing', function () { }); g.append(createSVGElement({ element: 'rect', - attr: {x: '0', y: '1', width: '5', height: '10'} + attr: { x: '0', y: '1', width: '5', height: '10' } })); group.append(g); return 4; diff --git a/cypress/integration/unit/history.js b/cypress/integration/unit/history.js index 11b00cd6..f9d13e2a 100644 --- a/cypress/integration/unit/history.js +++ b/cypress/integration/unit/history.js @@ -1,6 +1,6 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as transformlist from '../../../instrumented/svgcanvas/svgtransformlist.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import * as hstory from '../../../instrumented/svgcanvas/history.js'; @@ -402,7 +402,7 @@ describe('history', function () { it('Test ChangeElementCommand', function () { this.div1.setAttribute('title', 'new title'); let change = new hstory.ChangeElementCommand(this.div1, - {title: 'old title', class: 'foo'}); + { title: 'old title', class: 'foo' }); assert.ok(change.unapply); assert.ok(change.apply); assert.equal(typeof change.unapply, typeof function () { /* empty fn */ }); @@ -418,7 +418,7 @@ describe('history', function () { this.div1.textContent = 'inner text'; change = new hstory.ChangeElementCommand(this.div1, - {'#text': null}); + { '#text': null }); change.unapply(); assert.ok(!this.div1.textContent); @@ -428,7 +428,7 @@ describe('history', function () { this.div1.textContent = ''; change = new hstory.ChangeElementCommand(this.div1, - {'#text': 'old text'}); + { '#text': 'old text' }); change.unapply(); assert.equal(this.div1.textContent, 'old text'); @@ -457,7 +457,7 @@ describe('history', function () { gethrefvalue = '#newhref'; change = new hstory.ChangeElementCommand(rect, - {'#href': '#oldhref'}); + { '#href': '#oldhref' }); assert.equal(justCalled, 'getHref'); justCalled = null; @@ -472,7 +472,7 @@ describe('history', function () { const line = document.createElementNS(NS.SVG, 'line'); line.setAttribute('class', 'newClass'); - change = new hstory.ChangeElementCommand(line, {class: 'oldClass'}); + change = new hstory.ChangeElementCommand(line, { class: 'oldClass' }); assert.ok(change.unapply); assert.ok(change.apply); diff --git a/cypress/integration/unit/math.js b/cypress/integration/unit/math.js index 3852a2a0..deba647d 100644 --- a/cypress/integration/unit/math.js +++ b/cypress/integration/unit/math.js @@ -1,6 +1,6 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as math from '../../../instrumented/svgcanvas/math.js'; describe('math', function () { @@ -17,7 +17,7 @@ describe('math', function () { }); it('Test svgedit.math.transformPoint() function', function () { - const {transformPoint} = math; + const { transformPoint } = math; const m = svg.createSVGMatrix(); m.a = 1; m.b = 0; @@ -51,7 +51,7 @@ describe('math', function () { it('Test svgedit.math.matrixMultiply() function', function () { const mult = math.matrixMultiply; - const {isIdentity} = math; + const { isIdentity } = math; // translate there and back const tr1 = svg.createSVGMatrix().translate(100, 50), @@ -84,7 +84,7 @@ describe('math', function () { }); it('Test svgedit.math.transformBox() function', function () { - const {transformBox} = math; + const { transformBox } = math; const m = svg.createSVGMatrix(); m.a = 1; m.b = 0; diff --git a/cypress/integration/unit/path.js b/cypress/integration/unit/path.js index 2c82c12e..1636b79c 100644 --- a/cypress/integration/unit/path.js +++ b/cypress/integration/unit/path.js @@ -3,11 +3,11 @@ import 'pathseg'; import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import * as pathModule from '../../../instrumented/svgcanvas/path.js'; -import {Path, Segment} from '../../../instrumented/svgcanvas/path-method.js'; -import {init as unitsInit} from '../../../instrumented/common/units.js'; +import { Path, Segment } from '../../../instrumented/svgcanvas/path-method.js'; +import { init as unitsInit } from '../../../instrumented/common/units.js'; describe('path', function () { /** @@ -48,7 +48,7 @@ describe('path', function () { const path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 L10,11 L20,21Z'); - const [mockPathContext, mockUtilitiesContext] = getMockContexts(); + const [ mockPathContext, mockUtilitiesContext ] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); new Path(path); // eslint-disable-line no-new @@ -57,7 +57,7 @@ describe('path', function () { assert.equal(path.pathSegList.getItem(1).x, 10); assert.equal(path.pathSegList.getItem(1).y, 11); - pathModule.replacePathSeg(SVGPathSeg.PATHSEG_LINETO_REL, 1, [30, 31], path); + pathModule.replacePathSeg(SVGPathSeg.PATHSEG_LINETO_REL, 1, [ 30, 31 ], path); assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'l'); assert.equal(path.pathSegList.getItem(1).x, 30); @@ -68,7 +68,7 @@ describe('path', function () { const path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 L10,11 L20,21Z'); - const [mockPathContext, mockUtilitiesContext] = getMockContexts(); + const [ mockPathContext, mockUtilitiesContext ] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); new Path(path); // eslint-disable-line no-new @@ -78,7 +78,7 @@ describe('path', function () { assert.equal(path.pathSegList.getItem(1).y, 11); const segment = new Segment(1, path.pathSegList.getItem(1)); - segment.setType(SVGPathSeg.PATHSEG_LINETO_REL, [30, 31]); + segment.setType(SVGPathSeg.PATHSEG_LINETO_REL, [ 30, 31 ]); assert.equal(segment.item.pathSegTypeAsLetter, 'l'); assert.equal(segment.item.x, 30); assert.equal(segment.item.y, 31); @@ -96,7 +96,7 @@ describe('path', function () { path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z'); svg.append(path); - const [mockPathContext, mockUtilitiesContext] = getMockContexts(svg); + const [ mockPathContext, mockUtilitiesContext ] = getMockContexts(svg); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); const segment = new Segment(1, path.pathSegList.getItem(1)); @@ -110,7 +110,7 @@ describe('path', function () { assert.equal(path.pathSegList.getItem(1).x, 15); assert.equal(path.pathSegList.getItem(1).y, 16); - segment.setType(SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL, [30, 31, 32, 33, 34, 35]); + segment.setType(SVGPathSeg.PATHSEG_CURVETO_CUBIC_REL, [ 30, 31, 32, 33, 34, 35 ]); assert.equal(path.pathSegList.getItem(1).pathSegTypeAsLetter, 'c'); assert.equal(path.pathSegList.getItem(1).x1, 32); assert.equal(path.pathSegList.getItem(1).y1, 33); @@ -124,7 +124,7 @@ describe('path', function () { const path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 L10,11 L20,21Z'); - const [mockPathContext, mockUtilitiesContext] = getMockContexts(); + const [ mockPathContext, mockUtilitiesContext ] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); new Path(path); // eslint-disable-line no-new @@ -144,7 +144,7 @@ describe('path', function () { const path = document.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'M0,0 C11,12 13,14 15,16 Z'); - const [mockPathContext, mockUtilitiesContext] = getMockContexts(); + const [ mockPathContext, mockUtilitiesContext ] = getMockContexts(); pathModule.init(mockPathContext); utilities.init(mockUtilitiesContext); new Path(path); // eslint-disable-line no-new diff --git a/cypress/integration/unit/sanitize.js b/cypress/integration/unit/sanitize.js index 4ff4f853..45a95a98 100644 --- a/cypress/integration/unit/sanitize.js +++ b/cypress/integration/unit/sanitize.js @@ -1,6 +1,6 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as sanitize from '../../../instrumented/svgcanvas/sanitize.js'; describe('sanitize', function () { diff --git a/cypress/integration/unit/select.js b/cypress/integration/unit/select.js index 8d3b2672..0ee2a376 100644 --- a/cypress/integration/unit/select.js +++ b/cypress/integration/unit/select.js @@ -1,7 +1,7 @@ import '../../../instrumented/editor/jquery.min.js'; import * as select from '../../../instrumented/svgcanvas/select.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; describe('select', function () { const sandbox = document.createElement('div'); @@ -10,7 +10,7 @@ describe('select', function () { let svgroot; let svgcontent; const mockConfig = { - dimensions: [640, 480] + dimensions: [ 640, 480 ] }; const dataStorage = { _storage: new WeakMap(), @@ -33,7 +33,7 @@ describe('select', function () { } return ret; } - }; + }; /** * @implements {module:select.SVGFactory} @@ -41,7 +41,7 @@ describe('select', function () { const mockFactory = { createSVGElement (jsonMap) { const elem = document.createElementNS(NS.SVG, jsonMap.element); - Object.entries(jsonMap.attr).forEach(([attr, value]) => { + Object.entries(jsonMap.attr).forEach(([ attr, value ]) => { elem.setAttribute(attr, value); }); return elem; @@ -58,11 +58,11 @@ describe('select', function () { beforeEach(() => { svgroot = mockFactory.createSVGElement({ element: 'svg', - attr: {id: 'svgroot'} + attr: { id: 'svgroot' } }); svgcontent = mockFactory.createSVGElement({ element: 'svg', - attr: {id: 'svgcontent'} + attr: { id: 'svgcontent' } }); svgroot.append(svgcontent); diff --git a/cypress/integration/unit/svgtransformlist.js b/cypress/integration/unit/svgtransformlist.js index f5a35859..888b4a3e 100644 --- a/cypress/integration/unit/svgtransformlist.js +++ b/cypress/integration/unit/svgtransformlist.js @@ -1,8 +1,8 @@ import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as transformlist from '../../../instrumented/svgcanvas/svgtransformlist.js'; -import {disableSupportsNativeTransformLists} from '../../../instrumented/common/browser.js'; +import { disableSupportsNativeTransformLists } from '../../../instrumented/common/browser.js'; import almostEqualsPlugin from '../../support/assert-almostEquals.js'; import expectOutOfBoundsExceptionPlugin from '../../support/assert-expectOutOfBoundsException.js'; diff --git a/cypress/integration/unit/test1.js b/cypress/integration/unit/test1.js index fe073e37..64f2ee83 100644 --- a/cypress/integration/unit/test1.js +++ b/cypress/integration/unit/test1.js @@ -34,14 +34,14 @@ describe('Basic Module', function () { workarea.append(svgcanvas); const toolsLeft = document.createElement('div'); toolsLeft.id = 'tools_left'; - + svgEditor.append(workarea, toolsLeft); document.body.append(svgEditor); svgCanvas = new SvgCanvas( document.getElementById('svgcanvas'), { canvas_expansion: 3, - dimensions: [640, 480], + dimensions: [ 640, 480 ], initFill: { color: 'FF0000', // solid red opacity: 1 @@ -55,7 +55,7 @@ describe('Basic Module', function () { imgPath: '../editor/images/', langPath: 'locale/', extPath: 'extensions/', - extensions: ['ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js'], + extensions: [ 'ext-arrows.js', 'ext-connector.js', 'ext-eyedropper.js' ], initTool: 'select', wireframe: false } diff --git a/cypress/integration/unit/units.js b/cypress/integration/unit/units.js index b3e9e36e..6134ea55 100644 --- a/cypress/integration/unit/units.js +++ b/cypress/integration/unit/units.js @@ -51,7 +51,7 @@ describe('units', function () { assert.ok(units.shortFloat); assert.equal(typeof units.shortFloat, typeof function () { /* empty fn */ }); - const {shortFloat} = units; + const { shortFloat } = units; assert.equal(shortFloat(0.00000001), 0); assert.equal(shortFloat(1), 1); assert.equal(shortFloat(3.45678), 3.4568); @@ -63,7 +63,7 @@ describe('units', function () { assert.ok(units.isValidUnit); assert.equal(typeof units.isValidUnit, typeof function () { /* empty fn */ }); - const {isValidUnit} = units; + const { isValidUnit } = units; assert.ok(isValidUnit('0')); assert.ok(isValidUnit('1')); assert.ok(isValidUnit('1.1')); diff --git a/cypress/integration/unit/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js index c21108f0..433c1d44 100644 --- a/cypress/integration/unit/utilities-bbox.js +++ b/cypress/integration/unit/utilities-bbox.js @@ -3,7 +3,7 @@ import 'pathseg'; import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import * as transformlist from '../../../instrumented/svgcanvas/svgtransformlist.js'; import * as math from '../../../instrumented/svgcanvas/math.js'; @@ -20,7 +20,7 @@ describe('utilities bbox', function () { */ function mockCreateSVGElement (jsonMap) { const elem = document.createElementNS(NS.SVG, jsonMap.element); - Object.entries(jsonMap.attr).forEach(([attr, value]) => { + Object.entries(jsonMap.attr).forEach(([ attr, value ]) => { elem.setAttribute(attr, value); }); return elem; @@ -55,7 +55,7 @@ describe('utilities bbox', function () { const type = seg.pathSegType; if (type === 1) { continue; } const pts = []; - ['', 1, 2].forEach(function (n) { + [ '', 1, 2 ].forEach(function (n) { const x = seg['x' + n], y = seg['y' + n]; if (x !== undefined && y !== undefined) { const pt = math.transformPoint(x, y, m); @@ -82,7 +82,7 @@ describe('utilities bbox', function () { svgroot = mockCreateSVGElement({ element: 'svg', - attr: {id: 'svgroot'} + attr: { id: 'svgroot' } }); sandbox.append(svgroot); @@ -101,41 +101,41 @@ describe('utilities bbox', function () { }); it('Test getBBoxWithTransform and no transform', function () { - const {getBBoxWithTransform} = utilities; + const { getBBoxWithTransform } = utilities; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 L2,3'} + attr: { id: 'path', d: 'M0,1 L2,3' } }); svgroot.append(elem); let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 }); assert.equal(mockaddSVGElementFromJsonCallCount, 0); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); svgroot.append(elem); bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); assert.equal(mockaddSVGElementFromJsonCallCount, 0); elem.remove(); elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' } }); svgroot.append(elem); bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 }); assert.equal(mockaddSVGElementFromJsonCallCount, 0); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); const g = mockCreateSVGElement({ element: 'g', @@ -144,17 +144,17 @@ describe('utilities bbox', function () { g.append(elem); svgroot.append(g); bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); assert.equal(mockaddSVGElementFromJsonCallCount, 0); g.remove(); }); it.skip('Test getBBoxWithTransform and a rotation transform', function () { - const {getBBoxWithTransform} = utilities; + const { getBBoxWithTransform } = utilities; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10)'} + attr: { id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10)' } }); svgroot.append(elem); let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); @@ -166,7 +166,7 @@ describe('utilities bbox', function () { elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20)'} + attr: { id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20)' } }); svgroot.append(elem); bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); @@ -177,12 +177,12 @@ describe('utilities bbox', function () { assert.equal(mockaddSVGElementFromJsonCallCount, 1); elem.remove(); - const rect = {x: 10, y: 10, width: 10, height: 20}; + const rect = { x: 10, y: 10, width: 10, height: 20 }; const angle = 45; - const origin = {x: 15, y: 20}; // eslint-disable-line no-shadow + const origin = { x: 15, y: 20 }; // eslint-disable-line no-shadow elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')'} + 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; @@ -198,11 +198,11 @@ describe('utilities bbox', function () { // Same as previous but wrapped with g and the transform is with the g. elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect3', x: rect.x, y: rect.y, width: rect.width, height: rect.height} + attr: { id: 'rect3', x: rect.x, y: rect.y, width: rect.width, height: rect.height } }); const g = mockCreateSVGElement({ element: 'g', - attr: {transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')'} + attr: { transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ')' } }); g.append(elem); svgroot.append(g); @@ -217,7 +217,7 @@ describe('utilities bbox', function () { elem = mockCreateSVGElement({ element: 'ellipse', - attr: {id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100)'} + attr: { id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100)' } }); svgroot.append(elem); mockaddSVGElementFromJsonCallCount = 0; @@ -232,7 +232,7 @@ describe('utilities bbox', function () { }); it.skip('Test getBBoxWithTransform with rotation and matrix transforms', function () { - const {getBBoxWithTransform} = utilities; + const { getBBoxWithTransform } = utilities; let tx = 10; // tx right let ty = 10; // tx down @@ -241,7 +241,7 @@ describe('utilities bbox', function () { let matrix = 'matrix(1,0,0,1,' + txInRotatedSpace + ',' + tyInRotatedSpace + ')'; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10) ' + matrix} + attr: { id: 'path', d: 'M10,10 L20,20', transform: 'rotate(45 10,10) ' + matrix } }); svgroot.append(elem); let bbox = getBBoxWithTransform(elem, mockaddSVGElementFromJson, mockPathActions); @@ -256,7 +256,7 @@ describe('utilities bbox', function () { matrix = 'matrix(1,0,0,1,' + txInRotatedSpace + ',' + tyInRotatedSpace + ')'; elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '10', y: '10', width: '10', height: '20', transform: 'rotate(90 15,20) ' + matrix} + 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); @@ -266,9 +266,9 @@ describe('utilities bbox', function () { assert.close(bbox.height, 10, EPSILON); elem.remove(); - const rect = {x: 10, y: 10, width: 10, height: 20}; + const rect = { x: 10, y: 10, width: 10, height: 20 }; const angle = 45; - const origin = {x: 15, y: 20}; // eslint-disable-line no-shadow + const origin = { x: 15, y: 20 }; // eslint-disable-line no-shadow tx = 10; // tx right ty = 10; // tx down txInRotatedSpace = Math.sqrt(tx * tx + ty * ty); // translate in rotated 45 space. @@ -276,7 +276,7 @@ describe('utilities bbox', function () { matrix = 'matrix(1,0,0,1,' + txInRotatedSpace + ',' + tyInRotatedSpace + ')'; elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect2', x: rect.x, y: rect.y, width: rect.width, height: rect.height, transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ') ' + matrix} + 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); @@ -290,11 +290,11 @@ describe('utilities bbox', function () { // Same as previous but wrapped with g and the transform is with the g. elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect3', x: rect.x, y: rect.y, width: rect.width, height: rect.height} + attr: { id: 'rect3', x: rect.x, y: rect.y, width: rect.width, height: rect.height } }); const g = mockCreateSVGElement({ element: 'g', - attr: {transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ') ' + matrix} + attr: { transform: 'rotate(' + angle + ' ' + origin.x + ',' + origin.y + ') ' + matrix } }); g.append(elem); svgroot.append(g); @@ -307,7 +307,7 @@ describe('utilities bbox', function () { elem = mockCreateSVGElement({ element: 'ellipse', - attr: {id: 'ellipse1', cx: '100', cy: '100', rx: '50', ry: '50', transform: 'rotate(45 100,100) ' + matrix} + 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); @@ -320,39 +320,39 @@ describe('utilities bbox', function () { }); it('Test getStrokedBBox with stroke-width 10', function () { - const {getStrokedBBox} = utilities; + const { getStrokedBBox } = utilities; const strokeWidth = 10; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 L2,3', 'stroke-width': strokeWidth} + attr: { id: 'path', d: 'M0,1 L2,3', 'stroke-width': strokeWidth } }); svgroot.append(elem); - let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 2 + strokeWidth, height: 2 + strokeWidth}); + let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 2 + strokeWidth, height: 2 + strokeWidth }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth }); elem.remove(); elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': strokeWidth} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': strokeWidth } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 5 + strokeWidth}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 5 + strokeWidth }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': strokeWidth } }); const g = mockCreateSVGElement({ element: 'g', @@ -360,44 +360,44 @@ describe('utilities bbox', function () { }); g.append(elem); svgroot.append(g); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0 - strokeWidth / 2, y: 1 - strokeWidth / 2, width: 5 + strokeWidth, height: 10 + strokeWidth }); g.remove(); }); it("Test getStrokedBBox with stroke-width 'none'", function () { - const {getStrokedBBox} = utilities; + const { getStrokedBBox } = utilities; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 L2,3', 'stroke-width': 'none'} + attr: { id: 'path', d: 'M0,1 L2,3', 'stroke-width': 'none' } }); svgroot.append(elem); - let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2}); + let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none' } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); elem.remove(); elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': 'none'} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6', 'stroke-width': 'none' } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10', 'stroke-width': 'none' } }); const g = mockCreateSVGElement({ element: 'g', @@ -405,44 +405,44 @@ describe('utilities bbox', function () { }); g.append(elem); svgroot.append(g); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); g.remove(); }); it('Test getStrokedBBox with no stroke-width attribute', function () { - const {getStrokedBBox} = utilities; + const { getStrokedBBox } = utilities; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 L2,3'} + attr: { id: 'path', d: 'M0,1 L2,3' } }); svgroot.append(elem); - let bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 2, height: 2}); + let bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 2, height: 2 }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); elem.remove(); elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' } }); svgroot.append(elem); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); const g = mockCreateSVGElement({ element: 'g', @@ -450,8 +450,8 @@ describe('utilities bbox', function () { }); g.append(elem); svgroot.append(g); - bbox = getStrokedBBox([elem], mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + bbox = getStrokedBBox([ elem ], mockaddSVGElementFromJson, mockPathActions); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); g.remove(); }); @@ -473,7 +473,7 @@ describe('utilities bbox', function () { */ function rotatePoint (point, angle, origin) { // eslint-disable-line no-shadow if (!origin) { - origin = {x: 0, y: 0}; + origin = { x: 0, y: 0 }; } const x = point.x - origin.x; const y = point.y - origin.y; @@ -491,10 +491,10 @@ describe('utilities bbox', function () { * @returns {module:utilities.BBoxObject} */ function rotateRect (rect, angle, origin) { // eslint-disable-line no-shadow - const tl = rotatePoint({x: rect.x, y: rect.y}, angle, origin); - const tr = rotatePoint({x: rect.x + rect.width, y: rect.y}, angle, origin); - const br = rotatePoint({x: rect.x + rect.width, y: rect.y + rect.height}, angle, origin); - const bl = rotatePoint({x: rect.x, y: rect.y + rect.height}, angle, origin); + const tl = rotatePoint({ x: rect.x, y: rect.y }, angle, origin); + const tr = rotatePoint({ x: rect.x + rect.width, y: rect.y }, angle, origin); + const br = rotatePoint({ x: rect.x + rect.width, y: rect.y + rect.height }, angle, origin); + const bl = rotatePoint({ x: rect.x, y: rect.y + rect.height }, angle, origin); const minx = Math.min(tl.x, tr.x, bl.x, br.x); const maxx = Math.max(tl.x, tr.x, bl.x, br.x); diff --git a/cypress/integration/unit/utilities-performance.js b/cypress/integration/unit/utilities-performance.js index ef683ec0..bd737e4b 100644 --- a/cypress/integration/unit/utilities-performance.js +++ b/cypress/integration/unit/utilities-performance.js @@ -2,7 +2,7 @@ import 'pathseg'; import '../../../instrumented/editor/jquery.min.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import * as transformlist from '../../../instrumented/svgcanvas/svgtransformlist.js'; import * as math from '../../../instrumented/svgcanvas/math.js'; @@ -82,7 +82,7 @@ describe('utilities performance', function () { */ function mockCreateSVGElement (jsonMap) { const elem = document.createElementNS(NS.SVG, jsonMap.element); - Object.entries(jsonMap.attr).forEach(([attr, value]) => { + Object.entries(jsonMap.attr).forEach(([ attr, value ]) => { elem.setAttribute(attr, value); }); return elem; @@ -111,7 +111,7 @@ describe('utilities performance', function () { 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 {parentNode} = elem; + const { parentNode } = elem; parentNode.append(clone); } } @@ -135,7 +135,7 @@ describe('utilities performance', function () { continue; } const pts = []; - ['', 1, 2].forEach(function (n) { + [ '', 1, 2 ].forEach(function (n) { const x = seg['x' + n], y = seg['y' + n]; if (x !== undefined && y !== undefined) { @@ -183,8 +183,8 @@ describe('utilities performance', function () { // Pass2 svgCanvas.getStrokedBBox total ms 17, ave ms 0.2, min/max 0 23 it('Test svgCanvas.getStrokedBBox() performance with matrix transforms', function () { - const {getStrokedBBox} = utilities; - const {children} = currentLayer; + const { getStrokedBBox } = utilities; + const { children } = currentLayer; let lastTime, now, min = Number.MAX_VALUE, @@ -200,7 +200,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 ], mockaddSVGElementFromJson, mockPathActions); now = Date.now(); const delta = now - lastTime; lastTime = now; total += delta; min = Math.min(min, delta); @@ -220,7 +220,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 ], mockaddSVGElementFromJson, 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 e0190053..3e590bff 100644 --- a/cypress/integration/unit/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -3,7 +3,7 @@ import '../../../instrumented/editor/jquery.min.js'; import * as browser from '../../../instrumented/common/browser.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; -import {NS} from '../../../instrumented/common/namespaces.js'; +import { NS } from '../../../instrumented/common/namespaces.js'; describe('utilities', function () { /** @@ -13,7 +13,7 @@ describe('utilities', function () { */ function mockCreateSVGElement (jsonMap) { const elem = document.createElementNS(NS.SVG, jsonMap.element); - Object.entries(jsonMap.attr).forEach(([attr, value]) => { + Object.entries(jsonMap.attr).forEach(([ attr, value ]) => { elem.setAttribute(attr, value); }); return elem; @@ -28,7 +28,7 @@ describe('utilities', function () { svgroot.append(elem); return elem; } - const mockPathActions = {resetOrientation () { /* empty fn */ }}; + const mockPathActions = { resetOrientation () { /* empty fn */ } }; let mockHistorySubCommands = []; const mockHistory = { BatchCommand: class { @@ -92,7 +92,7 @@ describe('utilities', function () { svg = document.createElementNS(NS.SVG, 'svg'); svgroot = mockCreateSVGElement({ element: 'svg', - attr: {id: 'svgroot'} + attr: { id: 'svgroot' } }); sandbox.append(svgroot); document.body.append(sandbox); @@ -105,7 +105,7 @@ describe('utilities', function () { }); it('Test svgedit.utilities.toXml() function', function () { - const {toXml} = utilities; + const { toXml } = utilities; assert.equal(toXml('a'), 'a'); assert.equal(toXml('ABC_'), 'ABC_'); @@ -116,7 +116,7 @@ describe('utilities', function () { }); it('Test svgedit.utilities.fromXml() function', function () { - const {fromXml} = utilities; + const { fromXml } = utilities; assert.equal(fromXml('a'), 'a'); assert.equal(fromXml('ABC_'), 'ABC_'); @@ -127,7 +127,7 @@ describe('utilities', function () { }); it('Test svgedit.utilities.encode64() function', function () { - const {encode64} = utilities; + const { encode64 } = utilities; assert.equal(encode64('abcdef'), 'YWJjZGVm'); assert.equal(encode64('12345'), 'MTIzNDU='); @@ -136,7 +136,7 @@ describe('utilities', function () { }); it('Test svgedit.utilities.decode64() function', function () { - const {decode64} = utilities; + const { decode64 } = utilities; assert.equal(decode64('YWJjZGVm'), 'abcdef'); assert.equal(decode64('MTIzNDU='), '12345'); @@ -151,7 +151,7 @@ describe('utilities', function () { }); it('Test svgedit.utilities.bboxToObj() function', function () { - const {bboxToObj} = utilities; + const { bboxToObj } = utilities; const rect = svg.createSVGRect(); rect.x = 1; @@ -188,38 +188,38 @@ describe('utilities', function () { }); it('Test getPathDFromSegments', function () { - const {getPathDFromSegments} = utilities; + const { getPathDFromSegments } = utilities; const doc = utilities.text2xml(''); const path = doc.createElementNS(NS.SVG, 'path'); path.setAttribute('d', 'm0,0l5,0l0,5l-5,0l0,-5z'); let d = getPathDFromSegments([ - ['M', [1, 2]], - ['Z', []] + [ 'M', [ 1, 2 ] ], + [ 'Z', [] ] ]); assert.equal(d, 'M1,2 Z'); d = getPathDFromSegments([ - ['M', [1, 2]], - ['M', [3, 4]], - ['Z', []] + [ 'M', [ 1, 2 ] ], + [ 'M', [ 3, 4 ] ], + [ 'Z', [] ] ]); assert.equal(d, 'M1,2 M3,4 Z'); d = getPathDFromSegments([ - ['M', [1, 2]], - ['C', [3, 4, 5, 6]], - ['Z', []] + [ 'M', [ 1, 2 ] ], + [ 'C', [ 3, 4, 5, 6 ] ], + [ 'Z', [] ] ]); assert.equal(d, 'M1,2 C3,4 5,6 Z'); }); it('Test getPathDFromElement', function () { - const {getPathDFromElement} = utilities; + const { getPathDFromElement } = utilities; let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 Z'} + attr: { id: 'path', d: 'M0,1 Z' } }); svgroot.append(elem); assert.equal(getPathDFromElement(elem), 'M0,1 Z'); @@ -227,7 +227,7 @@ describe('utilities', function () { elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); svgroot.append(elem); assert.equal(getPathDFromElement(elem), 'M0,1 L5,1 L5,11 L0,11 L0,1 Z'); @@ -235,7 +235,7 @@ describe('utilities', function () { elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'roundrect', x: '0', y: '1', rx: '2', ry: '3', width: '10', height: '11'} + attr: { id: 'roundrect', x: '0', y: '1', rx: '2', ry: '3', width: '10', height: '11' } }); svgroot.append(elem); const closeEnough = /M0,13 C0,2.3\d* 0.9\d*,1 02,1 L8,1 C9.0\d*,1 10,2.3\d* 10,13 L10,9 C10,10.6\d* 9.08675799086758,12 8,12 L02,12 C0.9\d*,12 0,10.6\d* 0,9 L0,13 Z/; @@ -244,7 +244,7 @@ describe('utilities', function () { elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' } }); svgroot.append(elem); assert.equal(getPathDFromElement(elem), 'M0,1L5,6'); @@ -252,7 +252,7 @@ describe('utilities', function () { elem = mockCreateSVGElement({ element: 'circle', - attr: {id: 'circle', cx: '10', cy: '11', rx: '5', ry: '10'} + attr: { id: 'circle', cx: '10', cy: '11', rx: '5', ry: '10' } }); svgroot.append(elem); assert.equal(getPathDFromElement(elem), 'M5,11 C5,5.475138121546961 7.237569060773481,1 10,1 C102.7624309392265194,1 105,5.475138121546961 105,11 C105,115.524861878453039 102.7624309392265194,1110 10,1110 C7.237569060773481,1110 5,115.524861878453039 5,11 Z'); @@ -260,13 +260,13 @@ describe('utilities', function () { elem = mockCreateSVGElement({ element: 'polyline', - attr: {id: 'polyline', points: '0,1 5,1 5,11 0,11'} + attr: { id: 'polyline', points: '0,1 5,1 5,11 0,11' } }); svgroot.append(elem); assert.equal(getPathDFromElement(elem), 'M0,1 5,1 5,11 0,11'); elem.remove(); - assert.equal(getPathDFromElement({tagName: 'something unknown'}), undefined); + assert.equal(getPathDFromElement({ tagName: 'something unknown' }), undefined); }); it('Test getBBoxOfElementAsPath', function () { @@ -281,36 +281,36 @@ describe('utilities', function () { let elem = mockCreateSVGElement({ element: 'path', - attr: {id: 'path', d: 'M0,1 Z'} + attr: { id: 'path', d: 'M0,1 Z' } }); svgroot.append(elem); let bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 0, height: 0}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 0, height: 0 }); elem.remove(); elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + attr: { id: 'rect', x: '0', y: '1', width: '5', height: '10' } }); svgroot.append(elem); bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 10}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 10 }); elem.remove(); elem = mockCreateSVGElement({ element: 'line', - attr: {id: 'line', x1: '0', y1: '1', x2: '5', y2: '6'} + attr: { id: 'line', x1: '0', y1: '1', x2: '5', y2: '6' } }); svgroot.append(elem); bbox = getBBoxOfElementAsPath(elem, mockaddSVGElementFromJson, mockPathActions); - assert.deepEqual(bbox, {x: 0, y: 1, width: 5, height: 5}); + assert.deepEqual(bbox, { x: 0, y: 1, width: 5, height: 5 }); elem.remove(); // TODO: test element with transform. Need resetOrientation above to be working or mock it. }); it('Test convertToPath rect', function () { - const {convertToPath} = utilities; + const { convertToPath } = utilities; const attrs = { fill: 'red', stroke: 'white', @@ -320,7 +320,7 @@ describe('utilities', function () { const elem = mockCreateSVGElement({ element: 'rect', - attr: {id: 'rect', x: '0', y: '1', width: '5', height: '10'} + 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); @@ -337,7 +337,7 @@ describe('utilities', function () { }); it('Test convertToPath unknown element', function () { - const {convertToPath} = utilities; + const { convertToPath } = utilities; const attrs = { fill: 'red', stroke: 'white', diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index e9e3eab1..b0a4e8cc 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -11,6 +11,6 @@ // *********************************************************** require('@babel/register')({ - plugins: ['@babel/plugin-transform-modules-commonjs'] + plugins: [ '@babel/plugin-transform-modules-commonjs' ] }); module.exports = require('./main.js').default; diff --git a/cypress/support/assert-almostEquals.js b/cypress/support/assert-almostEquals.js index 08451b50..b2b42c73 100644 --- a/cypress/support/assert-almostEquals.js +++ b/cypress/support/assert-almostEquals.js @@ -12,7 +12,7 @@ const NEAR_ZERO = 5e-6; // 0.000005, Firefox fails at higher levels of precision function almostEquals (actual, expected, message) { message = message || (actual + ' did not equal ' + expected); const result = Math.abs(actual - expected) < NEAR_ZERO; - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** diff --git a/cypress/support/assert-close.js b/cypress/support/assert-close.js index 7b79341b..62c5df7d 100644 --- a/cypress/support/assert-close.js +++ b/cypress/support/assert-close.js @@ -25,7 +25,7 @@ function close (actual, expected, maxDifference, message) { const actualDiff = (actual === expected) ? 0 : Math.abs(actual - expected), result = actualDiff <= maxDifference; message = message || (actual + ' should be within ' + maxDifference + ' (inclusive) of ' + expected + (result ? '' : '. Actual: ' + actualDiff)); - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** @@ -55,7 +55,7 @@ function closePercent (actual, expected, maxPercentDifference, message) { } message = message || (actual + ' should be within ' + maxPercentDifference + '% (inclusive) of ' + expected + (result ? '' : '. Actual: ' + actualDiff + '%')); - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** @@ -74,7 +74,7 @@ function notClose (actual, expected, minDifference, message) { const actualDiff = Math.abs(actual - expected), result = actualDiff > minDifference; message = message || (actual + ' should not be within ' + minDifference + ' (exclusive) of ' + expected + (result ? '' : '. Actual: ' + actualDiff)); - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** @@ -104,7 +104,7 @@ function notClosePercent (actual, expected, minPercentDifference, message) { } message = message || (actual + ' should not be within ' + minPercentDifference + '% (exclusive) of ' + expected + (result ? '' : '. Actual: ' + actualDiff + '%')); - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** diff --git a/cypress/support/assert-expectOutOfBoundsException.js b/cypress/support/assert-expectOutOfBoundsException.js index 9285ecfc..de884e1f 100644 --- a/cypress/support/assert-expectOutOfBoundsException.js +++ b/cypress/support/assert-expectOutOfBoundsException.js @@ -19,7 +19,7 @@ function expectOutOfBoundsException (obj, fn, arg1) { } } const actual = result; - return {result, message, actual, expected}; + return { result, message, actual, expected }; } /** diff --git a/cypress/support/assertion-wrapper.js b/cypress/support/assertion-wrapper.js index 18670779..65a02776 100644 --- a/cypress/support/assertion-wrapper.js +++ b/cypress/support/assertion-wrapper.js @@ -6,7 +6,7 @@ function setAssertionMethods (_chai, _utils) { return (method) => { return (...args) => { - const {result, message, actual, expected} = method(...args); + const { result, message, actual, expected } = method(...args); const assertion = new _chai.Assertion(); assertion.assert(result, `Expected ${actual} to be ${expected}`, message); }; diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 0bbd68c7..2384dcbf 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -25,7 +25,7 @@ // Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... }) // remove the style attributes that is causing differences in snapshots -const ngAttributes = ['style']; +const ngAttributes = [ 'style' ]; Cypress.Commands.add( 'cleanSnapshot', diff --git a/cypress/support/ui-test-helper.js b/cypress/support/ui-test-helper.js index f91b9b2e..80ca022f 100644 --- a/cypress/support/ui-test-helper.js +++ b/cypress/support/ui-test-helper.js @@ -9,7 +9,7 @@ export const visitAndApproveStorage = () => { }; export const openMainMenu = () => { - return cy.get('#main_button').click({force: true}); + return cy.get('#main_button').click({ force: true }); }; export const openEditorPreferences = () => { diff --git a/demos/canvas.html b/demos/canvas.html index 321b03c6..d7f14b0e 100644 --- a/demos/canvas.html +++ b/demos/canvas.html @@ -28,17 +28,17 @@ import SvgCanvas from '../src/svgcanvas/svgcanvas.js'; const container = document.querySelector('#editorContainer'); -const {width, height} = {width: 500, height: 300}; +const { width, height } = { width: 500, height: 300 }; window.width = width; window.height = height; const config = { - initFill: {color: 'FFFFFF', opacity: 1}, - initStroke: {color: '000000', opacity: 1, width: 1}, - text: {stroke_width: 0, font_size: 24, font_family: 'serif'}, + initFill: { color: 'FFFFFF', opacity: 1 }, + initStroke: { color: '000000', opacity: 1, width: 1 }, + text: { stroke_width: 0, font_size: 24, font_family: 'serif' }, initOpacity: 1, imgPath: 'editor/images/', - dimensions: [width, height], + dimensions: [ width, height ], baseUnit: 'px' }; diff --git a/docs/jsdoc-config.js b/docs/jsdoc-config.js index e833febe..5461f541 100644 --- a/docs/jsdoc-config.js +++ b/docs/jsdoc-config.js @@ -2,7 +2,7 @@ 'use strict'; module.exports = { - plugins: ['plugins/markdown'], + plugins: [ 'plugins/markdown' ], markdown: { // tags: ['examples'] /* diff --git a/docs/tutorials/ConfigOptions.md b/docs/tutorials/ConfigOptions.md index 61d64124..c57e367d 100644 --- a/docs/tutorials/ConfigOptions.md +++ b/docs/tutorials/ConfigOptions.md @@ -43,7 +43,7 @@ repository editor code ```js svgEditor.setConfig({ - dimensions: [320, 240], + dimensions: [ 320, 240 ], canvas_expansion: 5, initFill: { color: '0000FF' @@ -160,7 +160,7 @@ To add your own stylesheets along with the default stylesheets, ensure `"@default"` is present in the array along with your own. For example: ```js -svgEditor.setConfig({stylesheets: ['@default', 'myStylesheet.css']}); +svgEditor.setConfig({ stylesheets: [ '@default', 'myStylesheet.css' ] }); ``` (In version 2.8, the CSS file `editor/custom.css` was included by default, diff --git a/docs/tutorials/ExtensionDocs.md b/docs/tutorials/ExtensionDocs.md index 9bdd182a..b25bc987 100644 --- a/docs/tutorials/ExtensionDocs.md +++ b/docs/tutorials/ExtensionDocs.md @@ -79,7 +79,7 @@ export default { init () { return { svgicons: 'extensions/helloworld-icon.xml', - buttons: [{ /* ... */ }], + buttons: [ { /* ... */ } ], mouseDown () { // ... }, @@ -139,7 +139,7 @@ property should follow the format naming conflicts in the non-modular version of SVGEdit. ```js -import {importSetGlobalDefault} from '../external/dynamic-import-polyfill/importModule.js'; +import { importSetGlobalDefault } from '../external/dynamic-import-polyfill/importModule.js'; // ... diff --git a/docs/versions/3.0.0.md b/docs/versions/3.0.0.md index be5a7c8e..8c7f58c0 100644 --- a/docs/versions/3.0.0.md +++ b/docs/versions/3.0.0.md @@ -119,7 +119,7 @@ these files). The default behavior is equivalent to this: ```js svgEditor.setConfig({ - stylesheets: ['@default', '../svgedit-custom.css'] + stylesheets: [ '@default', '../svgedit-custom.css' ] }); ``` diff --git a/rollup.config.js b/rollup.config.js index 8bdbd355..29a65765 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,16 +4,16 @@ // 'npm run build' import path from 'path'; -import {lstatSync, readdirSync} from 'fs'; +import { lstatSync, readdirSync } from 'fs'; import rimraf from 'rimraf'; import babel from '@rollup/plugin-babel'; import copy from 'rollup-plugin-copy'; -import {nodeResolve} from '@rollup/plugin-node-resolve'; +import { nodeResolve } from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import nodePolyfills from 'rollup-plugin-node-polyfills'; import url from '@rollup/plugin-url'; // for XML/SVG files import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'; -import {terser} from 'rollup-plugin-terser'; +import { terser } from 'rollup-plugin-terser'; // import progress from 'rollup-plugin-progress'; import filesize from 'rollup-plugin-filesize'; @@ -29,15 +29,15 @@ const getDirectories = (source) => { const extensionDirs = getDirectories('src/editor/extensions'); /** @todo should we support systemjs? */ -const dest = ['dist/editor' /* , 'dist/editor/system' */]; +const dest = [ 'dist/editor' ]; // remove existing distribution // eslint-disable-next-line no-console rimraf('./dist', () => console.info('recreating dist')); // config for svgedit core module -const config = [{ - input: ['src/editor/index.js'], +const config = [ { + input: [ 'src/editor/index.js' ], output: [ { format: 'es', @@ -95,13 +95,13 @@ const config = [{ dest: 'dist/editor/system' }, */ - {src: 'src/editor/images', dest}, - {src: 'src/editor/extensions/ext-shapes/shapelib', dest: dest.map((d) => `${d}/extensions/ext-shapes`)}, - {src: 'src/editor/embedapi.html', dest}, - {src: 'src/editor/embedapi.js', dest}, - {src: 'src/editor/browser-not-supported.html', dest}, - {src: 'src/editor/browser-not-supported.js', dest}, - {src: 'src/editor/svgedit.css', dest} + { src: 'src/editor/images', dest }, + { src: 'src/editor/extensions/ext-shapes/shapelib', dest: dest.map((d) => `${d}/extensions/ext-shapes`) }, + { src: 'src/editor/embedapi.html', dest }, + { src: 'src/editor/embedapi.js', dest }, + { src: 'src/editor/browser-not-supported.html', dest }, + { src: 'src/editor/browser-not-supported.js', dest }, + { src: 'src/editor/svgedit.css', dest } ] }), nodeResolve({ @@ -109,13 +109,13 @@ const config = [{ preferBuiltins: false }), commonjs(), - dynamicImportVars({include: `src/editor/locale.js`}), - babel({babelHelpers: 'bundled', exclude: [/\/core-js\//]}), // exclude core-js to avoid circular dependencies. + dynamicImportVars({ include: `src/editor/locale.js` }), + babel({ babelHelpers: 'bundled', exclude: [ /\/core-js\// ] }), // exclude core-js to avoid circular dependencies. nodePolyfills(), - terser({keep_fnames: true}), // keep_fnames is needed to avoid an error when calling extensions. + terser({ keep_fnames: true }), // keep_fnames is needed to avoid an error when calling extensions. filesize() ] -}]; +} ]; // config for dynamic extensions extensionDirs.forEach((extensionDir) => { @@ -141,7 +141,7 @@ extensionDirs.forEach((extensionDir) => { ], plugins: [ url({ - include: ['**/*.svg', '**/*.png', '**/*.jpg', '**/*.gif', '**/*.xml'], + include: [ '**/*.svg', '**/*.png', '**/*.jpg', '**/*.gif', '**/*.xml' ], limit: 0, fileName: '[name][extname]' }), @@ -149,11 +149,11 @@ extensionDirs.forEach((extensionDir) => { browser: true, preferBuiltins: true }), - commonjs({exclude: `src/editor/extensions/${extensionName}/${extensionName}.js`}), - dynamicImportVars({include: `src/editor/extensions/${extensionName}/${extensionName}.js`}), - babel({babelHelpers: 'bundled', exclude: [/\/core-js\//]}), + commonjs({ exclude: `src/editor/extensions/${extensionName}/${extensionName}.js` }), + dynamicImportVars({ include: `src/editor/extensions/${extensionName}/${extensionName}.js` }), + babel({ babelHelpers: 'bundled', exclude: [ /\/core-js\// ] }), nodePolyfills(), - terser({keep_fnames: true}) + terser({ keep_fnames: true }) ] } ); diff --git a/src/common/browser.js b/src/common/browser.js index 4b39472e..e83f1cc0 100644 --- a/src/common/browser.js +++ b/src/common/browser.js @@ -8,7 +8,7 @@ import 'pathseg'; -import {NS} from './namespaces.js'; +import { NS } from './namespaces.js'; const supportsSVG_ = (function () { return Boolean(document.createElementNS && document.createElementNS(NS.SVG, 'svg').createSVGRect); @@ -20,7 +20,7 @@ return Boolean(document.createElementNS && document.createElementNS(NS.SVG, 'svg */ export const supportsSvg = () => supportsSVG_; -const {userAgent} = navigator; +const { userAgent } = navigator; const svg = document.createElementNS(NS.SVG, 'svg'); // Note: Browser sniffing should only be used if no other detection method is possible diff --git a/src/common/namespaces.js b/src/common/namespaces.js index aa17b405..b85448dd 100644 --- a/src/common/namespaces.js +++ b/src/common/namespaces.js @@ -27,7 +27,7 @@ export const NS = { */ export const getReverseNS = function () { const reverseNS = {}; - Object.entries(NS).forEach(([name, URI]) => { + Object.entries(NS).forEach(([ name, URI ]) => { reverseNS[URI] = name.toLowerCase(); }); return reverseNS; diff --git a/src/common/units.js b/src/common/units.js index 128b3564..a80a4cb8 100644 --- a/src/common/units.js +++ b/src/common/units.js @@ -6,11 +6,11 @@ * @copyright 2010 Alexis Deveria, 2010 Jeff Schiller */ -import {NS} from './namespaces.js'; +import { NS } from './namespaces.js'; -const wAttrs = ['x', 'x1', 'cx', 'rx', 'width']; -const hAttrs = ['y', 'y1', 'cy', 'ry', 'height']; -const unitAttrs = ['r', 'radius', ...wAttrs, ...hAttrs]; +const wAttrs = [ 'x', 'x1', 'cx', 'rx', 'width' ]; +const hAttrs = [ 'y', 'y1', 'cy', 'ry', 'height' ]; +const unitAttrs = [ 'r', 'radius', ...wAttrs, ...hAttrs ]; // unused /* const unitNumMap = { @@ -202,14 +202,14 @@ export const setUnitAttr = function (elem, attr, val) { }; const attrsToConvert = { - line: ['x1', 'x2', 'y1', 'y2'], - circle: ['cx', 'cy', 'r'], - ellipse: ['cx', 'cy', 'rx', 'ry'], - foreignObject: ['x', 'y', 'width', 'height'], - rect: ['x', 'y', 'width', 'height'], - image: ['x', 'y', 'width', 'height'], - use: ['x', 'y', 'width', 'height'], - text: ['x', 'y'] + line: [ 'x1', 'x2', 'y1', 'y2' ], + circle: [ 'cx', 'cy', 'r' ], + ellipse: [ 'cx', 'cy', 'rx', 'ry' ], + foreignObject: [ 'x', 'y', 'width', 'height' ], + rect: [ 'x', 'y', 'width', 'height' ], + image: [ 'x', 'y', 'width', 'height' ], + use: [ 'x', 'y', 'width', 'height' ], + text: [ 'x', 'y' ] }; /** diff --git a/src/editor/ConfigObj.js b/src/editor/ConfigObj.js index 11d770e9..6a83d64d 100644 --- a/src/editor/ConfigObj.js +++ b/src/editor/ConfigObj.js @@ -1,6 +1,6 @@ // eslint-disable-next-line node/no-unpublished-import import deparam from 'deparam'; -import {mergeDeep} from './components/jgraduate/Util.js'; +import { mergeDeep } from './components/jgraduate/Util.js'; /** * Escapes special characters in a regular expression. @@ -126,7 +126,7 @@ export default class ConfigObj { imgPath: './images/', // DOCUMENT PROPERTIES // Change the following to a preference (already in the Document Properties dialog)? - dimensions: [640, 480], + dimensions: [ 640, 480 ], // EDITOR OPTIONS // Change the following to preferences (already in the Editor Options dialog)? gridSnapping: false, @@ -204,7 +204,7 @@ export default class ConfigObj { * @returns {void} */ setupCurPrefs () { - const curPrefs = {...this.defaultPrefs, ...this.curPrefs}; // Now safe to merge with priority for curPrefs in the event any are already set + const curPrefs = { ...this.defaultPrefs, ...this.curPrefs }; // Now safe to merge with priority for curPrefs in the event any are already set // Export updated prefs this.curPrefs = curPrefs; } @@ -213,11 +213,11 @@ export default class ConfigObj { * @returns {void} */ setupCurConfig () { - const curConfig = {...this.defaultConfig, ...this.curConfig}; // Now safe to merge with priority for curConfig in the event any are already set + const curConfig = { ...this.defaultConfig, ...this.curConfig }; // Now safe to merge with priority for curConfig in the event any are already set // Now deal with extensions and other array config if (!curConfig.noDefaultExtensions) { - curConfig.extensions = [...this.defaultExtensions]; + curConfig.extensions = [ ...this.defaultExtensions ]; } // Export updated config this.curConfig = curConfig; @@ -227,12 +227,12 @@ export default class ConfigObj { * @returns {void} */ loadFromURL () { - const {search, searchParams} = new URL(location); + const { search, searchParams } = new URL(location); if (search) { this.urldata = deparam(searchParams.toString()); - ['initStroke', 'initFill'].forEach((prop) => { + [ 'initStroke', 'initFill' ].forEach((prop) => { if (searchParams.has(`${prop}[color]`)) { // Restore back to original non-deparamed value to avoid color // strings being converted to numbers @@ -260,7 +260,7 @@ export default class ConfigObj { // security reasons, even for same-domain // ones given potential to interact in undesirable // ways with other script resources - ['userExtensions', 'imgPath'] + [ 'userExtensions', 'imgPath' ] .forEach(function (pathConfig) { if (this.urldata[pathConfig]) { delete this.urldata[pathConfig]; @@ -269,11 +269,11 @@ export default class ConfigObj { // Note: `source` and `url` (as with `storagePrompt` later) are not // set on config but are used below - this.setConfig(this.urldata, {overwrite: false}); + this.setConfig(this.urldata, { overwrite: false }); this.setupCurConfig(); if (!this.curConfig.preventURLContentLoading) { - let {source} = this.urldata; + let { source } = this.urldata; if (!source) { // urldata.source may have been null if it ended with '=' const src = searchParams.get('source'); if (src && src.startsWith('data:')) { @@ -396,7 +396,7 @@ export default class ConfigObj { cfgObj[key] = val; } }; - Object.entries(opts).forEach(([key, val]) => { + Object.entries(opts).forEach(([ key, val ]) => { // Only allow prefs defined in configObj.defaultPrefs or... if (this.defaultPrefs[key]) { if (cfgCfg.overwrite === false && ( @@ -410,11 +410,11 @@ export default class ConfigObj { } else { this.pref(key, val); } - } else if (['extensions', 'userExtensions', 'allowedOrigins'].includes(key)) { + } else if ([ 'extensions', 'userExtensions', 'allowedOrigins' ].includes(key)) { if (cfgCfg.overwrite === false && ( this.curConfig.preventAllURLConfig || - ['allowedOrigins'].includes(key) || + [ 'allowedOrigins' ].includes(key) || (key === 'extensions' && this.curConfig.lockExtensions) ) ) { diff --git a/src/editor/Editor.js b/src/editor/Editor.js index c09aa7b2..d8442f8b 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -52,7 +52,7 @@ class Editor extends EditorStartup { * @type {"ignore"|"waiting"|"closed"} */ this.storagePromptState = 'ignore'; - + this.svgCanvas = null; this.isReady = false; this.customExportImage = false; @@ -67,7 +67,7 @@ class Editor extends EditorStartup { this.configObj.preferences = false; this.canvMenu = null; // eslint-disable-next-line max-len - this.goodLangs = ['ar', 'cs', 'de', 'en', 'es', 'fa', 'fr', 'fy', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'zh-CN', 'zh-TW']; + this.goodLangs = [ 'ar', 'cs', 'de', 'en', 'es', 'fa', 'fr', 'fy', 'hi', 'it', 'ja', 'nl', 'pl', 'pt-BR', 'ro', 'ru', 'sk', 'sl', 'zh-CN', 'zh-TW' ]; const modKey = (isMac() ? 'meta+' : 'ctrl+'); this.shortcuts = [ // Shortcuts not associated with buttons @@ -79,26 +79,26 @@ class Editor extends EditorStartup { { key: 'shift+p', fn: () => { this.svgCanvas.cycleElement(1); } }, { key: 'tab', fn: () => { this.svgCanvas.cycleElement(0); } }, { key: 'shift+tab', fn: () => { this.svgCanvas.cycleElement(1); } }, - { key: [modKey + 'arrowup', true], fn: () => { this.zoomImage(2); } }, - { key: [modKey + 'arrowdown', true], fn: () => { this.zoomImage(0.5); } }, - { key: [modKey + ']', true], fn: () => { this.moveUpDownSelected('Up'); } }, - { key: [modKey + '[', true], fn: () => { this.moveUpDownSelected('Down'); } }, - { key: ['arrowup', true], fn: () => { this.moveSelected(0, -1); } }, - { key: ['arrowdown', true], fn: () => { this.moveSelected(0, 1); } }, - { key: ['arrowleft', true], fn: () => { this.moveSelected(-1, 0); } }, - { key: ['arrowright', true], fn: () => { this.moveSelected(1, 0); } }, + { key: [ modKey + 'arrowup', true ], fn: () => { this.zoomImage(2); } }, + { key: [ modKey + 'arrowdown', true ], fn: () => { this.zoomImage(0.5); } }, + { key: [ modKey + ']', true ], fn: () => { this.moveUpDownSelected('Up'); } }, + { key: [ modKey + '[', true ], fn: () => { this.moveUpDownSelected('Down'); } }, + { key: [ 'arrowup', true ], fn: () => { this.moveSelected(0, -1); } }, + { key: [ 'arrowdown', true ], fn: () => { this.moveSelected(0, 1); } }, + { key: [ 'arrowleft', true ], fn: () => { this.moveSelected(-1, 0); } }, + { key: [ 'arrowright', true ], fn: () => { this.moveSelected(1, 0); } }, { key: 'shift+arrowup', fn: () => { this.moveSelected(0, -10); } }, { key: 'shift+arrowdown', fn: () => { this.moveSelected(0, 10); } }, { key: 'shift+arrowleft', fn: () => { this.moveSelected(-10, 0); } }, { key: 'shift+arrowright', fn: () => { this.moveSelected(10, 0); } }, - { key: ['alt+arrowup', true], fn: () => { this.svgCanvas.cloneSelectedElements(0, -1); } }, - { key: ['alt+arrowdown', true], fn: () => { this.svgCanvas.cloneSelectedElements(0, 1); } }, - { key: ['alt+arrowleft', true], fn: () => { this.svgCanvas.cloneSelectedElements(-1, 0); } }, - { key: ['alt+arrowright', true], fn: () => { this.svgCanvas.cloneSelectedElements(1, 0); } }, - { key: ['alt+shift+arrowup', true], fn: () => { this.svgCanvas.cloneSelectedElements(0, -10); } }, - { key: ['alt+shift+arrowdown', true], fn: () => { this.svgCanvas.cloneSelectedElements(0, 10); } }, - { key: ['alt+shift+arrowleft', true], fn: () => { this.svgCanvas.cloneSelectedElements(-10, 0); } }, - { key: ['alt+shift+arrowright', true], fn: () => { this.svgCanvas.cloneSelectedElements(10, 0); } }, + { key: [ 'alt+arrowup', true ], fn: () => { this.svgCanvas.cloneSelectedElements(0, -1); } }, + { key: [ 'alt+arrowdown', true ], fn: () => { this.svgCanvas.cloneSelectedElements(0, 1); } }, + { key: [ 'alt+arrowleft', true ], fn: () => { this.svgCanvas.cloneSelectedElements(-1, 0); } }, + { key: [ 'alt+arrowright', true ], fn: () => { this.svgCanvas.cloneSelectedElements(1, 0); } }, + { key: [ 'alt+shift+arrowup', true ], fn: () => { this.svgCanvas.cloneSelectedElements(0, -10); } }, + { key: [ 'alt+shift+arrowdown', true ], fn: () => { this.svgCanvas.cloneSelectedElements(0, 10); } }, + { key: [ 'alt+shift+arrowleft', true ], fn: () => { this.svgCanvas.cloneSelectedElements(-10, 0); } }, + { key: [ 'alt+shift+arrowright', true ], fn: () => { this.svgCanvas.cloneSelectedElements(10, 0); } }, { key: 'a', fn: () => { this.svgCanvas.selectAllInCurrentLayer(); } }, { key: modKey + 'a', fn: () => { this.svgCanvas.selectAllInCurrentLayer(); } }, { key: modKey + 'x', fn: () => { this.cutSelected(); } }, @@ -294,7 +294,7 @@ class Editor extends EditorStartup { '4/Shift+4': 'tools_rect', '5/Shift+5': 'tools_ellipse' }; - Object.entries(keyAssocs).forEach(([keyval, sel]) => { + Object.entries(keyAssocs).forEach(([ keyval, sel ]) => { const parentsElements = this.getParents($id(sel), $id('main_menu')); const menu = (parentsElements.length); @@ -384,7 +384,7 @@ class Editor extends EditorStartup { this.exportWindow.location.href = data.bloburl || data.datauri; const done = this.configObj.pref('export_notice_done'); if (done !== 'all') { - let note = this.i18next.t('notification.saveFromBrowser', { type: data.type}); + let note = this.i18next.t('notification.saveFromBrowser', { type: data.type }); // Check if there are issues if (issues.length) { @@ -1083,7 +1083,7 @@ class Editor extends EditorStartup { resolve(cb()); return; } - this.callbacks.push([cb, resolve, reject]); + this.callbacks.push([ cb, resolve, reject ]); }); } @@ -1094,16 +1094,16 @@ class Editor extends EditorStartup { */ async runCallbacks() { try { - await Promise.all(this.callbacks.map(([cb]) => { + await Promise.all(this.callbacks.map(([ cb ]) => { return cb(); })); } catch (err) { - this.callbacks.forEach(([, , reject]) => { + this.callbacks.forEach(([ , , reject ]) => { reject(); }); throw err; } - this.callbacks.forEach(([, resolve]) => { + this.callbacks.forEach(([ , resolve ]) => { resolve(); }); this.isReady = true; diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index c7c3b453..367e3ec9 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -1,6 +1,6 @@ /* globals $ seConfirm seAlert */ import './touch.js'; -import {convertUnit} from '../common/units.js'; +import { convertUnit } from '../common/units.js'; import { putLocale } from './locale.js'; @@ -41,7 +41,7 @@ const readySignal = () => { } }; -const {$id} = SvgCanvas; +const { $id } = SvgCanvas; /** * @@ -118,7 +118,7 @@ class EditorStartup { this.layersPanel.init(); this.mainMenu.init(); - const {undoMgr} = this.svgCanvas; + const { undoMgr } = this.svgCanvas; this.workarea = document.getElementById('workarea'); this.canvMenu = document.getElementById('se-cmenu_canvas'); this.exportWindow = null; @@ -160,7 +160,7 @@ class EditorStartup { if (!data.output) { // Ignore Chrome return; } - const {exportWindowName} = data; + const { exportWindowName } = data; if (exportWindowName) { this.exportWindow = window.open('', this.exportWindowName); // A hack to get the window via JSON-able name without opening a new one } @@ -182,7 +182,7 @@ class EditorStartup { * @listens module:svgcanvas.SvgCanvas#event:updateCanvas * @returns {void} */ - function (win, {center, newCtr}) { + function (win, { center, newCtr }) { this.updateCanvas(center, newCtr); }.bind(this) ); @@ -279,7 +279,7 @@ class EditorStartup { let lastX = null, lastY = null, panning = false, keypan = false; - $id('svgcanvas').addEventListener('mouseup', function(evt) { + $id('svgcanvas').addEventListener('mouseup', function(evt) { if (panning === false) { return true; } wArea.scrollLeft -= (evt.clientX - lastX); @@ -290,9 +290,9 @@ class EditorStartup { if (evt.type === 'mouseup') { panning = false; } return false; - }); + }); // eslint-disable-next-line sonarjs/no-identical-functions - $id('svgcanvas').addEventListener('mousemove', function(evt) { + $id('svgcanvas').addEventListener('mousemove', function(evt) { if (panning === false) { return true; } wArea.scrollLeft -= (evt.clientX - lastX); @@ -322,10 +322,10 @@ class EditorStartup { if (e.target.nodeName !== 'BODY') return; if(e.code.toLowerCase() === 'space'){ this.svgCanvas.spaceKey = keypan = true; - e.preventDefault(); + e.preventDefault(); } else if((e.key.toLowerCase() === 'shift') && (this.svgCanvas.getMode() === 'zoom')){ this.workarea.style.cursor = zoomOutIcon; - e.preventDefault(); + e.preventDefault(); } else { return; } @@ -335,10 +335,10 @@ class EditorStartup { if (e.target.nodeName !== 'BODY') return; if(e.code.toLowerCase() === 'space'){ this.svgCanvas.spaceKey = keypan = false; - e.preventDefault(); + e.preventDefault(); } else if((e.key.toLowerCase() === 'shift') && (this.svgCanvas.getMode() === 'zoom')){ this.workarea.style.cursor = zoomInIcon; - e.preventDefault(); + e.preventDefault(); } else { return; } @@ -367,7 +367,7 @@ class EditorStartup { el.addEventListener("focus", (e) => { inp = e.currentTarget; this.uiContext = 'toolbars'; - this.workarea.addEventListener('mousedown', unfocus); + this.workarea.addEventListener('mousedown', unfocus); }); el.addEventListener("blur", () => { this.uiContext = 'canvas'; @@ -399,12 +399,12 @@ class EditorStartup { ); } const winWh = { - width: getWidth(), + width: getWidth(), height: getHeight() }; window.addEventListener('resize', () => { - Object.entries(winWh).forEach(([type, val]) => { + Object.entries(winWh).forEach(([ type, val ]) => { const curval = (type === 'width') ? window.innerWidth - 15 : window.innerHeight; this.workarea['scroll' + (type === 'width' ? 'Left' : 'Top')] -= (curval - val) / 2; winWh[type] = curval; @@ -619,14 +619,14 @@ class EditorStartup { editorObj.svgCanvas.alignSelectedElements('m', 'page'); editorObj.svgCanvas.alignSelectedElements('c', 'page'); // highlight imported element, otherwise we get strange empty selectbox - editorObj.svgCanvas.selectOnly([newElement]); + editorObj.svgCanvas.selectOnly([ newElement ]); document.getElementById('se-prompt-dialog').setAttribute('close', true); }; reader.readAsText(file); } else { // bitmap handling reader = new FileReader(); - reader.onloadend = function ({target: {result}}) { + reader.onloadend = function ({ target: { result } }) { /** * Insert the new image until we know its dimensions. * @param {Float} imageWidth @@ -646,7 +646,7 @@ class EditorStartup { } }); editorObj.svgCanvas.setHref(newImage, result); - editorObj.svgCanvas.selectOnly([newImage]); + editorObj.svgCanvas.selectOnly([ newImage ]); editorObj.svgCanvas.alignSelectedElements('m', 'page'); editorObj.svgCanvas.alignSelectedElements('c', 'page'); editorObj.topPanelHandlers.updateContextPanel(); @@ -715,8 +715,8 @@ class EditorStartup { */ // eslint-disable-next-line no-unsanitized/method const imported = await import(`./extensions/${encodeURIComponent(extname)}/${encodeURIComponent(extname)}.js`); - const {name = extname, init: initfn} = imported.default; - return this.addExtension(name, (initfn && initfn.bind(this)), {$, langParam: 'en'}); /** @todo change to current lng */ + const { name = extname, init: initfn } = imported.default; + return this.addExtension(name, (initfn && initfn.bind(this)), { $, langParam: 'en' }); /** @todo change to current lng */ } catch (err) { // Todo: Add config to alert any errors console.error('Extension failed to load: ' + extname + '; ', err); @@ -739,8 +739,8 @@ class EditorStartup { */ // eslint-disable-next-line no-unsanitized/method const imported = await import(encodeURI(extPathName)); - const {name, init: initfn} = imported.default; - return this.addExtension(name, (initfn && initfn.bind(this)), {$}); + const { name, init: initfn } = imported.default; + return this.addExtension(name, (initfn && initfn.bind(this)), { $ }); } catch (err) { // Todo: Add config to alert any errors console.error('Extension failed to load: ' + extPathName + '; ', err); @@ -790,9 +790,9 @@ class EditorStartup { * @fires module:svgcanvas.SvgCanvas#event:message * @returns {void} */ - messageListener ({data, origin}) { + messageListener ({ data, origin }) { // console.log('data, origin, extensionsAdded', data, origin, extensionsAdded); - const messageObj = {data, origin}; + const messageObj = { data, origin }; if (!this.extensionsAdded) { this.messageQueue.push(messageObj); } else { diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js index bb80ecf9..b07b0425 100644 --- a/src/editor/MainMenu.js +++ b/src/editor/MainMenu.js @@ -1,7 +1,7 @@ /* globals seConfirm, seAlert */ import SvgCanvas from "../svgcanvas/svgcanvas.js"; -import {convertUnit, isValidUnit} from '../common/units.js'; -import {isChrome} from '../common/browser.js'; +import { convertUnit, isValidUnit } from '../common/units.js'; +import { isChrome } from '../common/browser.js'; const { $id } = SvgCanvas; const homePage = 'https://github.com/SVG-Edit/svgedit'; @@ -26,7 +26,7 @@ class MainMenu { * @returns {void} */ async clickClear() { - const [x, y] = this.editor.configObj.curConfig.dimensions; + const [ x, y ] = this.editor.configObj.curConfig.dimensions; const ok = await seConfirm(this.editor.i18next.t('notification.QwantToClear')); if (ok === "Cancel") { return; @@ -183,7 +183,7 @@ class MainMenu {