upgrade eslint and associated fixes

don't keep ie() by the way
This commit is contained in:
JFH
2020-12-19 20:42:18 +01:00
parent dca89321d4
commit 047e55c7be
25 changed files with 346 additions and 352 deletions

View File

@@ -30,7 +30,6 @@ const svg = document.createElementNS(NS.SVG, 'svg');
const isOpera_ = Boolean(window.opera);
const isWebkit_ = userAgent.includes('AppleWebKit');
const isGecko_ = userAgent.includes('Gecko/');
const isIE_ = userAgent.includes('MSIE');
const isChrome_ = userAgent.includes('Chrome/');
const isWindows_ = userAgent.includes('Windows');
const isMac_ = userAgent.includes('Macintosh');
@@ -165,11 +164,6 @@ export const isWebkit = () => isWebkit_;
* @returns {boolean}
*/
export const isGecko = () => isGecko_;
/**
* @function module:browser.isIE
* @returns {boolean}
*/
export const isIE = () => isIE_;
/**
* @function module:browser.isChrome
* @returns {boolean}

View File

@@ -230,13 +230,8 @@ export const convertAttrs = function (element) {
for (let i = 0; i < len; i++) {
const attr = attrs[i];
const cur = element.getAttribute(attr);
if (cur) {
if (!isNaN(cur)) {
element.setAttribute(attr, (cur / typeMap_[unit]) + unit);
}
// else {
// Convert existing?
// }
if (cur && !isNaN(cur)) {
element.setAttribute(attr, (cur / typeMap_[unit]) + unit);
}
}
};

View File

@@ -679,10 +679,8 @@ export const getBBox = function (elem) {
} else {
// Check if element is child of a foreignObject
const fo = $(selected).closest('foreignObject');
if (fo.length) {
if (fo[0].getBBox) {
ret = fo[0].getBBox();
}
if (fo.length && fo[0].getBBox) {
ret = fo[0].getBBox();
}
}
}

View File

@@ -168,6 +168,7 @@ export class ExplorerButton extends HTMLElement {
)).join('');
await this.updateLib(lib[0]);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
break;
@@ -307,6 +308,7 @@ export class ExplorerButton extends HTMLElement {
return `<se-button data-shape="${key}"src="data:image/svg+xml;base64,${encoded}"></se-button>`;
}).join('');
} catch (error) {
// eslint-disable-next-line no-console
console.error(`could not read file:${libDir}${lib}.json`, error);
}
}

View File

@@ -1,6 +1,5 @@
/* eslint-disable node/no-unpublished-import */
import 'elix/define/Dialog.js';
import {isValidUnit} from '../../common/units.js';
const template = document.createElement('template');
template.innerHTML = `
@@ -485,7 +484,7 @@ export class SeEditPrefsDialog extends HTMLElement {
*/
connectedCallback () {
const onCancelHandler = (ev) => {
const closeEvent = new CustomEvent('change', { detail: {
const closeEvent = new CustomEvent('change', {detail: {
dialog: 'closed'
}});
this.dispatchEvent(closeEvent);

View File

@@ -344,7 +344,7 @@ export class SeImgPropDialog extends HTMLElement {
if (this.$imageOptRef.getAttribute('checked') === 'true') {
saveOpt = 'ref';
}
const closeEvent = new CustomEvent('change', { detail: {
const closeEvent = new CustomEvent('change', {detail: {
title: this.$canvasTitle.value,
w: this.$canvasWidth.value,
h: this.$canvasHeight.value,
@@ -357,7 +357,7 @@ export class SeImgPropDialog extends HTMLElement {
this.dispatchEvent(closeEvent);
};
const onCancelHandler = (ev) => {
const closeEvent = new CustomEvent('change', { detail: {
const closeEvent = new CustomEvent('change', {detail: {
dialog: 'closed'
}});
this.$canvasWidth.removeAttribute('disabled');

View File

@@ -1,2 +1,2 @@
import './imagePropertiesDialog.js';
import './editorPreferencesDialog.js';
import './editorPreferencesDialog.js';

View File

@@ -641,10 +641,8 @@ export default {
},
toolButtonStateUpdate (opts) {
const button = document.getElementById('mode_connect');
if (opts.nostroke) {
if (button.pressed === true) {
svgEditor.clickSelect();
}
if (opts.nostroke && button.pressed === true) {
svgEditor.clickSelect();
}
button.disabled = opts.nostroke;
}

View File

@@ -8,7 +8,7 @@
*/
export default {
name: 'overview_window',
init ({$, isChrome, isIE}) {
init ({$, isChrome}) {
const overviewWindowGlobals = {};
// Disabled in Chrome 48-, see https://github.com/SVG-Edit/svgedit/issues/26 and
// https://code.google.com/p/chromium/issues/detail?id=565120.
@@ -77,18 +77,8 @@ export default {
const viewWidth = $('#svgroot').attr('width');
const viewHeight = $('#svgroot').attr('height');
let viewX = 640;
let viewY = 480;
if (isIE()) {
// This has only been tested with Firefox 10 and IE 9 (without chrome frame).
// I am not sure if if is Firefox or IE that is being non compliant here.
// Either way the one that is noncompliant may become more compliant later.
// TAG:HACK
// TAG:VERSION_DEPENDENT
// TAG:BROWSER_SNIFFING
viewX = 0;
viewY = 0;
}
const viewX = 640;
const viewY = 480;
const svgWidthOld = $('#overviewMiniView').attr('width');
const svgHeightNew = viewHeight / viewWidth * svgWidthOld;

View File

@@ -143,5 +143,4 @@ try { // try clause to avoid js to complain if XDOMAIN undefined
// eslint-disable-next-line no-console
console.info('xdomain config activated');
}
} catch (error) {
}
} catch (error) {}

View File

@@ -616,10 +616,10 @@ export default function jQueryPluginJGraduate ($) {
this.value = 1.0;
}
if (!(attr[0] === 'f' && !showFocus)) {
if ((isRadial && curType === 'radialGradient') || (!isRadial && curType === 'linearGradient')) {
curGradient.setAttribute(attr, this.value);
}
if (!(attr[0] === 'f' &&
!showFocus) &&
((isRadial && curType === 'radialGradient') || (!isRadial && curType === 'linearGradient'))) {
curGradient.setAttribute(attr, this.value);
}
const $elem = isRadial

View File

@@ -398,16 +398,11 @@ editor.init = () => {
const blurval = svgCanvas.getBlur(elem) * 10;
$id('blur').value = blurval;
if (svgCanvas.addedNew) {
if (elname === 'image' && svgCanvas.getMode() === 'image') {
// Prompt for URL if not a data URL
if (!svgCanvas.getHref(elem).startsWith('data:')) {
/* await */ promptImgURL({cancelDeletes: true});
}
}
/* else if (elname == 'text') {
// TODO: Do something here for new text
} */
if (svgCanvas.addedNew &&
elname === 'image' &&
svgCanvas.getMode() === 'image' &&
!svgCanvas.getHref(elem).startsWith('data:')) {
/* await */ promptImgURL({cancelDeletes: true});
}
if (!isNode && currentMode !== 'pathedit') {
@@ -493,11 +488,9 @@ editor.init = () => {
$('#g_panel').show();
}
if (elem.parentNode.tagName === 'a') {
if (!$(elem).siblings().length) {
$('#a_panel').show();
linkHref = svgCanvas.getHref(elem.parentNode);
}
if (elem.parentNode.tagName === 'a' && !$(elem).siblings().length) {
$('#a_panel').show();
linkHref = svgCanvas.getHref(elem.parentNode);
}
// Hide/show the make_link buttons
@@ -1283,14 +1276,8 @@ editor.init = () => {
// if elems[1] is present, then we have more than one element
selectedElement = (elems.length === 1 || Utils.isNullish(elems[1]) ? elems[0] : null);
multiselected = (elems.length >= 2 && !Utils.isNullish(elems[1]));
if (!Utils.isNullish(selectedElement)) {
// unless we're already in always set the mode of the editor to select because
// upon creation of a text element the editor is switched into
// select mode and this event fires - we need our UI to be in sync
if (!isNode) {
updateToolbar();
}
if (!Utils.isNullish(selectedElement) && !isNode) {
updateToolbar();
} // if (!Utils.isNullish(elem))
// Deal with pathedit mode
@@ -1546,11 +1533,9 @@ editor.init = () => {
}
let cbCalled = false;
if (ext.langReady) {
if (editor.langChanged) { // We check for this since the "lang" pref could have been set by storage
const lang = editor.pref('lang');
await ext.langReady({lang});
}
if (ext.langReady && editor.langChanged) { // We check for this since the "lang" pref could have been set by storage
const lang = editor.pref('lang');
await ext.langReady({lang});
}
/**

View File

@@ -71,34 +71,27 @@ export const remapElement = function (selected, changes, m) {
for (let i = 0; i < 2; i++) {
const type = i === 0 ? 'fill' : 'stroke';
const attrVal = selected.getAttribute(type);
if (attrVal && attrVal.startsWith('url(')) {
if (m.a < 0 || m.d < 0) {
const grad = getRefElem(attrVal);
const newgrad = grad.cloneNode(true);
if (m.a < 0) {
// flip x
const x1 = newgrad.getAttribute('x1');
const x2 = newgrad.getAttribute('x2');
newgrad.setAttribute('x1', -(x1 - 1));
newgrad.setAttribute('x2', -(x2 - 1));
}
if (m.d < 0) {
// flip y
const y1 = newgrad.getAttribute('y1');
const y2 = newgrad.getAttribute('y2');
newgrad.setAttribute('y1', -(y1 - 1));
newgrad.setAttribute('y2', -(y2 - 1));
}
newgrad.id = editorContext_.getDrawing().getNextId();
findDefs().append(newgrad);
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
if (attrVal && attrVal.startsWith('url(') && (m.a < 0 || m.d < 0)) {
const grad = getRefElem(attrVal);
const newgrad = grad.cloneNode(true);
if (m.a < 0) {
// flip x
const x1 = newgrad.getAttribute('x1');
const x2 = newgrad.getAttribute('x2');
newgrad.setAttribute('x1', -(x1 - 1));
newgrad.setAttribute('x2', -(x2 - 1));
}
// Not really working :(
// if (selected.tagName === 'path') {
// reorientGrads(selected, m);
// }
if (m.d < 0) {
// flip y
const y1 = newgrad.getAttribute('y1');
const y2 = newgrad.getAttribute('y2');
newgrad.setAttribute('y1', -(y1 - 1));
newgrad.setAttribute('y2', -(y2 - 1));
}
newgrad.id = editorContext_.getDrawing().getNextId();
findDefs().append(newgrad);
selected.setAttribute(type, 'url(#' + newgrad.id + ')');
}
}

View File

@@ -620,10 +620,8 @@ export const mouseUpEvent = function (evt) {
eventContext_.getCanvas().pathActions.select(selectedElements[0]);
// if it was a path
// else, if it was selected and this is a shift-click, remove it from selection
} else if (evt.shiftKey) {
if (tempJustSelected !== t) {
eventContext_.getCanvas().removeFromSelection([t]);
}
} else if (evt.shiftKey && tempJustSelected !== t) {
eventContext_.getCanvas().removeFromSelection([t]);
}
} // no change in mouse position

View File

@@ -260,10 +260,8 @@ export class RemoveElementCommand extends Command {
unapply (handler) {
super.unapply(handler, () => {
removeElementFromListMap(this.elem);
if (isNullish(this.nextSibling)) {
if (window.console) {
console.error('Reference element was lost');
}
if (isNullish(this.nextSibling) && window.console) {
console.error('Reference element was lost');
}
this.parent.insertBefore(this.elem, this.nextSibling); // Don't use `before` or `prepend` as `this.nextSibling` may be `null`
});

View File

@@ -1134,20 +1134,18 @@ export const pathActionsMethod = (function () {
cleanup();
break;
}
} else if (item.pathSegType === 2) {
if (len > 0) {
const prevType = segList.getItem(len - 1).pathSegType;
// Path has M M
if (prevType === 2) {
remItems(len - 1, 1);
cleanup();
break;
} else if (item.pathSegType === 2 && len > 0) {
const prevType = segList.getItem(len - 1).pathSegType;
// Path has M M
if (prevType === 2) {
remItems(len - 1, 1);
cleanup();
break;
// Entire path ends with Z M
} else if (prevType === 1 && segList.numberOfItems - 1 === len) {
remItems(len, 1);
cleanup();
break;
}
} else if (prevType === 1 && segList.numberOfItems - 1 === len) {
remItems(len, 1);
cleanup();
break;
}
}
}

View File

@@ -1012,10 +1012,8 @@ export class Path {
if (!Array.isArray(indexes)) { indexes = [indexes]; }
indexes.forEach((index) => {
const seg = this.segs[index];
if (seg.ptgrip) {
if (!this.selected_pts.includes(index) && index >= 0) {
this.selected_pts.push(index);
}
if (seg.ptgrip && !this.selected_pts.includes(index) && index >= 0) {
this.selected_pts.push(index);
}
});
this.selected_pts.sort();

View File

@@ -107,10 +107,8 @@ export const recalculateDimensions = function (selected) {
tlist.removeItem(k);
}
// remove zero-degree rotations
} else if (xform.type === 4) {
if (xform.angle === 0) {
tlist.removeItem(k);
}
} else if (xform.type === 4 && xform.angle === 0) {
tlist.removeItem(k);
}
}
// End here if all it has is a rotation

View File

@@ -204,13 +204,10 @@ export const sanitizeSvg = function (node) {
const href = getHref(node);
if (href &&
['filter', 'linearGradient', 'pattern',
'radialGradient', 'textPath', 'use'].includes(node.nodeName)) {
// TODO: we simply check if the first character is a #, is this bullet-proof?
if (href[0] !== '#') {
// remove the attribute (but keep the element)
setHref(node, '');
node.removeAttributeNS(NS.XLINK, 'href');
}
'radialGradient', 'textPath', 'use'].includes(node.nodeName) && href[0] !== '#') {
// remove the attribute (but keep the element)
setHref(node, '');
node.removeAttributeNS(NS.XLINK, 'href');
}
// Safari crashes on a <use> without a xlink:href, so we just remove the node here

View File

@@ -284,15 +284,6 @@ export const getIntersectionListMethod = function (rect) {
}
let resultList = null;
if (!selectionContext_.isIE()) {
if (typeof selectionContext_.getSVGRoot().getIntersectionList === 'function') {
// Offset the bbox of the rubber box by the offset of the svgcontent element.
rubberBBox.x += Number.parseInt(selectionContext_.getSVGContent().getAttribute('x'));
rubberBBox.y += Number.parseInt(selectionContext_.getSVGContent().getAttribute('y'));
resultList = selectionContext_.getSVGRoot().getIntersectionList(rubberBBox, parent);
}
}
if (isNullish(resultList) || typeof resultList.item !== 'function') {
resultList = [];

View File

@@ -181,12 +181,10 @@ export const svgToString = function (elem, indent) {
if (attr.nodeName.startsWith('xmlns:')) { continue; }
// only serialize attributes we don't use internally
if (attrVal !== '' && !attrNames.includes(attr.localName)) {
if (!attr.namespaceURI || nsMap[attr.namespaceURI]) {
out.push(' ');
out.push(attr.nodeName); out.push('="');
out.push(attrVal); out.push('"');
}
if (attrVal !== '' && !attrNames.includes(attr.localName) && (!attr.namespaceURI || nsMap[attr.namespaceURI])) {
out.push(' ');
out.push(attr.nodeName); out.push('="');
out.push(attrVal); out.push('"');
}
}
} else {
@@ -487,10 +485,8 @@ export const importSvgString = function (xmlString) {
let useExisting = false;
// Look for symbol and make sure symbol exists in image
if (svgContext_.getImportIds(uid)) {
if ($(svgContext_.getImportIds(uid).symbol).parents('#svgroot').length) {
useExisting = true;
}
if (svgContext_.getImportIds(uid) && $(svgContext_.getImportIds(uid).symbol).parents('#svgroot').length) {
useExisting = true;
}
const batchCmd = new BatchCommand('Import Image');

View File

@@ -93,7 +93,7 @@ import {
uniquifyElemsMethod, removeUnusedDefElemsMethod, convertGradientsMethod
} from './svg-exec.js';
import {
isChrome, isIE, isWebkit
isChrome, isWebkit
} from '../common/browser.js'; // , supportsEditableText
import {
getTransformList, SVGTransformList as SVGEditTransformList
@@ -590,7 +590,6 @@ class SvgCanvas {
getExtensions () { return extensions; },
setExtensions (key, value) { extensions[key] = value; },
getCurrentZoom,
isIE,
getRubberBox () { return rubberBox; },
setCurBBoxes (value) { curBBoxes = value; },
getCurBBoxes (value) { return curBBoxes; },
@@ -2678,7 +2677,6 @@ class SvgCanvas {
* @property {module:history.HistoryCommand} InsertElementCommand
* @property {module:browser.isChrome} isChrome
* @property {module:math.isIdentity} isIdentity
* @property {module:browser.isIE} isIE
* @property {module:svgcanvas~logMatrix} logMatrix
* @property {module:history.HistoryCommand} MoveElementCommand
* @property {module:namespaces.NS} NS
@@ -2721,7 +2719,6 @@ class SvgCanvas {
InsertElementCommand,
isChrome,
isIdentity,
isIE,
logMatrix,
MoveElementCommand,
NS,

View File

@@ -208,12 +208,11 @@ export const changeSelectedAttributeNoUndoMethod = function (attr, newValue, ele
// Use the Firefox ffClone hack for text elements with gradients or
// where other text attributes are changed.
if (isGecko() && elem.nodeName === 'text' && (/rotate/).test(elem.getAttribute('transform'))) {
if (
String(newValue).startsWith('url') || (['font-size', 'font-family', 'x', 'y'].includes(attr) && elem.textContent)
) {
elem = ffClone(elem);
}
if (isGecko() &&
elem.nodeName === 'text' &&
(/rotate/).test(elem.getAttribute('transform')) &&
(String(newValue).startsWith('url') || (['font-size', 'font-family', 'x', 'y'].includes(attr) && elem.textContent))) {
elem = ffClone(elem);
}
// Timeout needed for Opera & Firefox
// codedread: it is now possible for this function to be called with elements