diff --git a/cypress/integration/unit/utilities-bbox.js b/cypress/integration/unit/utilities-bbox.js
index 9e475390..b76310c3 100644
--- a/cypress/integration/unit/utilities-bbox.js
+++ b/cypress/integration/unit/utilities-bbox.js
@@ -476,10 +476,7 @@ describe('utilities bbox', function () {
* @param {module:math.XYObject} origin
* @returns {module:math.XYObject}
*/
- function rotatePoint (point, angle, origin) {
- if (!origin) {
- origin = { x: 0, y: 0 }
- }
+ function rotatePoint (point, angle, origin = { x: 0, y: 0 }) {
const x = point.x - origin.x
const y = point.y - origin.y
const theta = radians(angle)
diff --git a/src/common/units.js b/src/common/units.js
index 7c33da82..b7933a3b 100644
--- a/src/common/units.js
+++ b/src/common/units.js
@@ -98,7 +98,7 @@ export const init = function (elementContainer) {
* @function module:units.getTypeMap
* @returns {module:units.TypeMap} The unit object with values for each unit
*/
-export const getTypeMap = function () {
+export const getTypeMap = () => {
return typeMap_
}
@@ -118,7 +118,7 @@ export const getTypeMap = function () {
* @returns {Float|string} If a string/number was given, returns a Float. If an array, return a string
* with comma-separated floats
*/
-export const shortFloat = function (val) {
+export const shortFloat = (val) => {
const digits = elementContainer_.getRoundDigits()
if (!isNaN(val)) {
return Number(Number(val).toFixed(digits))
@@ -136,7 +136,7 @@ export const shortFloat = function (val) {
* @param {"em"|"ex"|"in"|"cm"|"mm"|"pt"|"pc"|"px"|"%"} [unit]
* @returns {Float}
*/
-export const convertUnit = function (val, unit) {
+export const convertUnit = (val, unit) => {
unit = unit || elementContainer_.getBaseUnit()
// baseVal.convertToSpecifiedUnits(unitNumMap[unit]);
// const val = baseVal.valueInSpecifiedUnits;
@@ -153,38 +153,7 @@ export const convertUnit = function (val, unit) {
* @param {string} val - Attribute value to convert
* @returns {void}
*/
-export const setUnitAttr = function (elem, attr, val) {
- // if (!isNaN(val)) {
- // New value is a number, so check currently used unit
- // const oldVal = elem.getAttribute(attr);
-
- // Enable this for alternate mode
- // if (oldVal !== null && (isNaN(oldVal) || elementContainer_.getBaseUnit() !== 'px')) {
- // // Old value was a number, so get unit, then convert
- // let unit;
- // if (oldVal.substr(-1) === '%') {
- // const res = getResolution();
- // unit = '%';
- // val *= 100;
- // if (wAttrs.includes(attr)) {
- // val = val / res.w;
- // } else if (hAttrs.includes(attr)) {
- // val = val / res.h;
- // } else {
- // return val / Math.sqrt((res.w*res.w) + (res.h*res.h))/Math.sqrt(2);
- // }
- // } else {
- // if (elementContainer_.getBaseUnit() !== 'px') {
- // unit = elementContainer_.getBaseUnit();
- // } else {
- // unit = oldVal.substr(-2);
- // }
- // val = val / typeMap_[unit];
- // }
- //
- // val += unit;
- // }
- // }
+export const setUnitAttr = (elem, attr, val) => {
elem.setAttribute(attr, val)
}
@@ -205,7 +174,7 @@ const attrsToConvert = {
* @param {Element} element - A DOM element whose attributes should be converted
* @returns {void}
*/
-export const convertAttrs = function (element) {
+export const convertAttrs = (element) => {
const elName = element.tagName
const unit = elementContainer_.getBaseUnit()
const attrs = attrsToConvert[elName]
@@ -228,7 +197,7 @@ export const convertAttrs = function (element) {
* @param {string} val - Attribute value to convert
* @returns {Float} The converted number
*/
-export const convertToNum = function (attr, val) {
+export const convertToNum = (attr, val) => {
// Return a number if that's what it already is
if (!isNaN(val)) { return val - 0 }
if (val.substr(-1) === '%') {
diff --git a/src/editor/ConfigObj.js b/src/editor/ConfigObj.js
index 50889a88..62c373c2 100644
--- a/src/editor/ConfigObj.js
+++ b/src/editor/ConfigObj.js
@@ -291,7 +291,7 @@ export default class ConfigObj {
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:')) {
+ if (src?.startsWith('data:')) {
source = src
}
}
diff --git a/src/editor/Editor.js b/src/editor/Editor.js
index 6cbf16c5..3d0a8265 100644
--- a/src/editor/Editor.js
+++ b/src/editor/Editor.js
@@ -29,7 +29,7 @@ import LayersPanel from './panels/LayersPanel.js'
import MainMenu from './MainMenu.js'
import { getParentsUntil } from './components/jgraduate/Util.js'
-const { $id, $qa, isNullish, decode64, blankPageObjectURL } = SvgCanvas
+const { $id, $qa, decode64, blankPageObjectURL } = SvgCanvas
/**
*
@@ -487,8 +487,8 @@ class Editor extends EditorStartup {
}
const isNode = mode === 'pathedit'
// if this.elems[1] is present, then we have more than one element
- this.selectedElement = (elems.length === 1 || isNullish(elems[1]) ? elems[0] : null)
- this.multiselected = (elems.length >= 2 && !isNullish(elems[1]))
+ this.selectedElement = (elems.length === 1 || !elems[1] ? elems[0] : null)
+ this.multiselected = (elems.length >= 2 && elems[1])
if (this.selectedElement && !isNode) {
this.topPanel.update()
} // if (elem)
@@ -520,7 +520,7 @@ class Editor extends EditorStartup {
return
}
- this.multiselected = (elems.length >= 2 && !isNullish(elems[1]))
+ this.multiselected = (elems.length >= 2 && elems[1])
// Only updating fields for single elements for now
if (!this.multiselected) {
switch (mode) {
@@ -552,7 +552,7 @@ class Editor extends EditorStartup {
}
elems.forEach((elem) => {
- const isSvgElem = (elem && elem.tagName === 'svg')
+ const isSvgElem = (elem?.tagName === 'svg')
if (isSvgElem || this.svgCanvas.isLayer(elem)) {
this.layersPanel.populateLayers()
// if the element changed was the svg, then it could be a resolution change
@@ -561,8 +561,7 @@ class Editor extends EditorStartup {
}
// Update selectedElement if element is no longer part of the image.
// This occurs for the text elements in Firefox
- } else if (elem && this.selectedElement && isNullish(this.selectedElement.parentNode)) {
- // || elem && elem.tagName == "path" && !multiselected) { // This was added in r1430, but not sure why
+ } else if (elem && !this.selectedElement?.parentNode) {
this.selectedElement = elem
}
})
diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js
index 7d5173eb..a8e6504a 100644
--- a/src/editor/MainMenu.js
+++ b/src/editor/MainMenu.js
@@ -167,7 +167,7 @@ class MainMenu {
${loadingImage}
`
- if (typeof URL !== 'undefined' && URL.createObjectURL) {
+ if (URL?.createObjectURL) {
const blob = new Blob([popHTML], { type: 'text/html' })
popURL = URL.createObjectURL(blob)
} else {
diff --git a/src/editor/components/jgraduate/jQuery.jGraduate.js b/src/editor/components/jgraduate/jQuery.jGraduate.js
index b100b8de..b2564918 100644
--- a/src/editor/components/jgraduate/jQuery.jGraduate.js
+++ b/src/editor/components/jgraduate/jQuery.jGraduate.js
@@ -127,7 +127,7 @@ function setAttrs (elem, attrs) {
} else {
Object.entries(attrs).forEach(([aname, val]) => {
const prop = elem[aname]
- if (prop && prop.constructor === 'SVGLength') {
+ if (prop?.constructor === 'SVGLength') {
prop.baseVal.value = val
} else {
elem.setAttribute(aname, val)
diff --git a/src/editor/components/seMenu.js b/src/editor/components/seMenu.js
index b51e7bd6..6728a811 100644
--- a/src/editor/components/seMenu.js
+++ b/src/editor/components/seMenu.js
@@ -112,19 +112,6 @@ export class SeMenu extends HTMLElement {
set src (value) {
this.setAttribute('src', value)
}
- /**
- * @function connectedCallback
- * @returns {void}
- */
- /* connectedCallback () {
- this.$menu.addEventListener('openedchange', (e) => {
- e.preventDefault();
- const selectedItem = e?.detail?.closeResult;
- if (selectedItem !== undefined && selectedItem?.id !== undefined) {
- document.getElementById(selectedItem.id).click();
- }
- });
- } */
}
// Register
diff --git a/src/editor/extensions/ext-imagelib/ext-imagelib.js b/src/editor/extensions/ext-imagelib/ext-imagelib.js
index 6be807d9..93d3be3d 100644
--- a/src/editor/extensions/ext-imagelib/ext-imagelib.js
+++ b/src/editor/extensions/ext-imagelib/ext-imagelib.js
@@ -269,7 +269,7 @@ export default {
curMeta = pending[id]
let title
if (svgStr) {
- if (curMeta && curMeta.name) {
+ if (curMeta?.name) {
title = curMeta.name
} else {
// Try to find a title
@@ -299,7 +299,7 @@ export default {
submit.removeAttribute('disabled')
}
} else {
- if (curMeta && curMeta.preview_url) {
+ if (curMeta?.preview_url) {
title = curMeta.name || ''
entry = document.createElement('span')
const img = document.createElement('img')
diff --git a/src/editor/extensions/ext-polystar/ext-polystar.js b/src/editor/extensions/ext-polystar/ext-polystar.js
index 1d7dcadb..17571d61 100644
--- a/src/editor/extensions/ext-polystar/ext-polystar.js
+++ b/src/editor/extensions/ext-polystar/ext-polystar.js
@@ -421,7 +421,7 @@ export default {
let i = selElems.length
while (i--) {
const elem = selElems[i]
- if (elem && elem.getAttribute('shape') === 'star') {
+ if (elem?.getAttribute('shape') === 'star') {
if (opts.selectedElement && !opts.multiselected) {
$id('starNumPoints').value = elem.getAttribute('point')
$id('radialShift').value = elem.getAttribute('radialshift')
@@ -429,7 +429,7 @@ export default {
} else {
showPanel(false, 'star')
}
- } else if (elem && elem.getAttribute('shape') === 'regularPoly') {
+ } else if (elem?.getAttribute('shape') === 'regularPoly') {
if (opts.selectedElement && !opts.multiselected) {
$id('polySides').value = elem.getAttribute('sides')
showPanel(true, 'polygon')
diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js
index faa84768..1e3f98df 100644
--- a/src/editor/panels/TopPanel.js
+++ b/src/editor/panels/TopPanel.js
@@ -187,7 +187,7 @@ class TopPanel {
? this.editor.configObj.curConfig.baseUnit
: null
- const isNode = currentMode === 'pathedit' // elem ? (elem.id && elem.id.startsWith('pathpointgrip')) : false;
+ const isNode = currentMode === 'pathedit'
const menuItems = document.getElementById('se-cmenu_canvas')
this.hideTool('selected_panel')
this.hideTool('multiselected_panel')
diff --git a/src/svgcanvas/coords.js b/src/svgcanvas/coords.js
index c86bd6d3..1b984514 100644
--- a/src/svgcanvas/coords.js
+++ b/src/svgcanvas/coords.js
@@ -45,7 +45,7 @@ export const init = (canvas) => {
* @name module:coords.remapElement
* @type {module:path.EditorContext#remapElement}
*/
-export const remapElement = function (selected, changes, m) {
+export const remapElement = (selected, changes, m) => {
const remap = (x, y) => transformPoint(x, y, m)
const scalew = (w) => m.a * w
const scaleh = (h) => m.d * h
@@ -62,7 +62,7 @@ export const remapElement = function (selected, changes, m) {
['fill', 'stroke'].forEach((type) => {
const attrVal = selected.getAttribute(type)
- if (attrVal && attrVal.startsWith('url(') && (m.a < 0 || m.d < 0)) {
+ if (attrVal?.startsWith('url(') && (m.a < 0 || m.d < 0)) {
const grad = getRefElem(attrVal)
const newgrad = grad.cloneNode(true)
if (m.a < 0) {
diff --git a/src/svgcanvas/draw.js b/src/svgcanvas/draw.js
index 997c4963..0faf6d77 100644
--- a/src/svgcanvas/draw.js
+++ b/src/svgcanvas/draw.js
@@ -482,7 +482,7 @@ export class Drawing {
for (let i = 0; i < numchildren; ++i) {
const child = this.svgElem_.childNodes.item(i)
// for each g, find its layer name
- if (child && child.nodeType === 1) {
+ if (child?.nodeType === 1) {
if (child.tagName === 'g') {
childgroups = true
const name = findLayerNameInGroup(child)
diff --git a/src/svgcanvas/elem-get-set.js b/src/svgcanvas/elem-get-set.js
index 2d237a53..28a9a7ce 100644
--- a/src/svgcanvas/elem-get-set.js
+++ b/src/svgcanvas/elem-get-set.js
@@ -91,7 +91,7 @@ export const setGroupTitleMethod = (val) => {
const batchCmd = new BatchCommand('Set Label')
let title
- if (!val.length) {
+ if (val.length === 0) {
// Remove title element
const tsNextSibling = ts.nextSibling
batchCmd.addSubCommand(new RemoveElementCommand(ts[0], tsNextSibling, elem))
@@ -175,7 +175,7 @@ export const setResolutionMethod = (x, y) => {
const visEls = getVisibleElements()
svgCanvas.addToSelection(visEls)
const dx = []; const dy = []
- visEls.forEach(function (_item, _i) {
+ visEls.forEach((_item, _i) => {
dx.push(bbox.x * -1)
dy.push(bbox.y * -1)
})
@@ -245,7 +245,7 @@ export const setBBoxZoomMethod = (val, editorW, editorH) => {
const selectedElements = svgCanvas.getSelectedElements()
let spacer = 0.85
let bb
- const calcZoom = function (bb) {
+ const calcZoom = (bb) => {
if (!bb) { return false }
const wZoom = Math.round((editorW / bb.width) * 100 * spacer) / 100
const hZoom = Math.round((editorH / bb.height) * 100 * spacer) / 100
@@ -267,7 +267,7 @@ export const setBBoxZoomMethod = (val, editorW, editorH) => {
switch (val) {
case 'selection': {
if (!selectedElements[0]) { return undefined }
- const selectedElems = selectedElements.map(function (n, _) {
+ const selectedElems = selectedElements.map((n, _) => {
if (n) {
return n
}
@@ -304,7 +304,7 @@ export const setZoomMethod = (zoomLevel) => {
const res = svgCanvas.getResolution()
svgCanvas.getSvgContent().setAttribute('viewBox', '0 0 ' + res.w / zoomLevel + ' ' + res.h / zoomLevel)
svgCanvas.setZoom(zoomLevel)
- selectedElements.forEach(function (elem) {
+ selectedElements.forEach((elem) => {
if (!elem) { return }
svgCanvas.selectorManager.requestSelector(elem).resize()
})
@@ -321,7 +321,7 @@ export const setZoomMethod = (zoomLevel) => {
* @fires module:elem-get-set.SvgCanvas#event:changed
* @returns {void}
*/
-export const setColorMethod = function (type, val, preventUndo) {
+export const setColorMethod = (type, val, preventUndo) => {
const selectedElements = svgCanvas.getSelectedElements()
svgCanvas.setCurShape(type, val)
svgCanvas.setCurProperties(type + '_paint', { type: 'solidColor' })
@@ -426,7 +426,7 @@ export const findDuplicateGradient = (grad) => {
}
let diff = false
- radAttrs.forEach(function (attr) {
+ radAttrs.forEach((attr) => {
if (gradAttrs[attr] !== ogAttrs[attr]) { diff = true }
})
@@ -548,7 +548,7 @@ export const setStrokeAttrMethod = (attr, val) => {
const elem = selectedElements[i]
if (elem) {
if (elem.tagName === 'g') {
- walkTree(elem, function (e) { if (e.nodeName !== 'g') { elems.push(e) } })
+ walkTree(elem, (e) => { if (e.nodeName !== 'g') { elems.push(e) } })
} else {
elems.push(elem)
}
@@ -708,7 +708,7 @@ export const setFontFamilyMethod = (val) => {
const selectedElements = svgCanvas.getSelectedElements()
svgCanvas.setCurText('font_family', val)
svgCanvas.changeSelectedAttribute('font-family', val)
- if (selectedElements[0] && !selectedElements[0].textContent) {
+ if (!selectedElements[0]?.textContent) {
svgCanvas.textActions.setCursor()
}
}
@@ -750,7 +750,7 @@ export const setFontSizeMethod = (val) => {
const selectedElements = svgCanvas.getSelectedElements()
svgCanvas.setCurText('font_size', val)
svgCanvas.changeSelectedAttribute('font-size', val)
- if (selectedElements[0] && !selectedElements[0].textContent) {
+ if (!selectedElements[0]?.textContent) {
svgCanvas.textActions.setCursor()
}
}
@@ -762,7 +762,6 @@ export const setFontSizeMethod = (val) => {
export const getTextMethod = () => {
const selectedElements = svgCanvas.getSelectedElements()
const selected = selectedElements[0]
- if (!selected) { return '' }
return (selected) ? selected.textContent : ''
}
@@ -895,9 +894,6 @@ export const setRectRadiusMethod = (val) => {
*/
export const makeHyperlinkMethod = (url) => {
svgCanvas.groupSelectedElements('a', url)
-
- // TODO: If element is a single "g", convert to "a"
- // if (selectedElements.length > 1 && selectedElements[1]) {
}
/**
@@ -918,7 +914,7 @@ export const removeHyperlinkMethod = () => {
* @param {Integer} newType - New segment type. See {@link https://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathSeg} for list
* @returns {void}
*/
-export const setSegTypeMethod = function (newType) {
+export const setSegTypeMethod = (newType) => {
svgCanvas.pathActions.setSegType(newType)
}
diff --git a/src/svgcanvas/event.js b/src/svgcanvas/event.js
index e0149841..97ef3642 100644
--- a/src/svgcanvas/event.js
+++ b/src/svgcanvas/event.js
@@ -6,7 +6,7 @@
*/
import {
assignAttributes, cleanupElement, getElement, getRotationAngle, snapToGrid, walkTree,
- isNullish, preventClickDefault, setHref, getBBox
+ preventClickDefault, setHref, getBBox
} from './utilities.js'
import {
convertAttrs
@@ -465,7 +465,7 @@ const mouseMoveEvent = (evt) => {
({ x, y } = xya)
}
- if (svgCanvas.getRubberBox() && svgCanvas.getRubberBox().getAttribute('display') !== 'none') {
+ if (svgCanvas.getRubberBox()?.getAttribute('display') !== 'none') {
realX *= zoom
realY *= zoom
assignAttributes(svgCanvas.getRubberBox(), {
@@ -482,15 +482,6 @@ const mouseMoveEvent = (evt) => {
case 'textedit': {
x *= zoom
y *= zoom
- // if (svgCanvas.getRubberBox() && svgCanvas.getRubberBox().getAttribute('display') !== 'none') {
- // assignAttributes(svgCanvas.getRubberBox(), {
- // x: Math.min(svgCanvas.getStartX(), x),
- // y: Math.min(svgCanvas.getStartY(), y),
- // width: Math.abs(x - svgCanvas.getStartX()),
- // height: Math.abs(y - svgCanvas.getStartY())
- // }, 100);
- // }
-
svgCanvas.textActions.mouseMove(mouseX, mouseY)
break
@@ -638,7 +629,7 @@ const mouseUpEvent = (evt) => {
// no change in position/size, so maybe we should move to pathedit
} else {
t = evt.target
- if (selectedElements[0].nodeName === 'path' && isNullish(selectedElements[1])) {
+ if (selectedElements[0].nodeName === 'path' && !selectedElements[1]) {
svgCanvas.pathActions.select(selectedElements[0])
// if it was a path
// else, if it was selected and this is a shift-click, remove it from selection
@@ -832,8 +823,8 @@ const mouseUpEvent = (evt) => {
// then go to Select mode.
// WebKit returns when the canvas is clicked, Firefox/Opera return