fix lgtm warnings and other minor fixes

This commit is contained in:
JFH
2021-12-30 23:18:43 -03:00
parent 88207acc98
commit ff34764955
17 changed files with 62 additions and 84 deletions

View File

@@ -37,7 +37,7 @@ describe('utilities bbox', function () {
} }
const mockPathActions = { const mockPathActions = {
resetOrientation (pth) { resetOrientation (pth) {
if (utilities.isNullish(pth) || pth.nodeName !== 'path') { return false } if (pth?.nodeName !== 'path') { return false }
const tlist = pth.transform.baseVal const tlist = pth.transform.baseVal
const m = math.transformListToTransform(tlist).matrix const m = math.transformListToTransform(tlist).matrix
tlist.clear() tlist.clear()

View File

@@ -116,7 +116,7 @@ describe('utilities performance', function () {
const mockPathActions = { const mockPathActions = {
resetOrientation (path) { resetOrientation (path) {
if (utilities.isNullish(path) || path.nodeName !== 'path') { return false } if (path?.nodeName !== 'path') { return false }
const tlist = path.transform.baseVal const tlist = path.transform.baseVal
const m = math.transformListToTransform(tlist).matrix const m = math.transformListToTransform(tlist).matrix
tlist.clear() tlist.clear()

View File

@@ -102,7 +102,7 @@ class Editor extends EditorStartup {
{ {
key: ['delete/backspace', true], key: ['delete/backspace', true],
fn: () => { fn: () => {
if (!isNullish(this.selectedElement) || this.multiselected) { this.svgCanvas.deleteSelectedElements() } if (this.selectedElement || this.multiselected) { this.svgCanvas.deleteSelectedElements() }
} }
}, },
{ key: 'a', fn: () => { this.svgCanvas.selectAllInCurrentLayer() } }, { key: 'a', fn: () => { this.svgCanvas.selectAllInCurrentLayer() } },
@@ -489,9 +489,9 @@ class Editor extends EditorStartup {
// if this.elems[1] is present, then we have more than one element // 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.selectedElement = (elems.length === 1 || isNullish(elems[1]) ? elems[0] : null)
this.multiselected = (elems.length >= 2 && !isNullish(elems[1])) this.multiselected = (elems.length >= 2 && !isNullish(elems[1]))
if (!isNullish(this.selectedElement) && !isNode) { if (this.selectedElement && !isNode) {
this.topPanel.update() this.topPanel.update()
} // if (!isNullish(elem)) } // if (elem)
// Deal with pathedit mode // Deal with pathedit mode
this.topPanel.togglePathEditMode(isNode, elems) this.topPanel.togglePathEditMode(isNode, elems)
@@ -742,7 +742,7 @@ class Editor extends EditorStartup {
* @returns {void} * @returns {void}
*/ */
cutSelected () { cutSelected () {
if (!isNullish(this.selectedElement) || this.multiselected) { if (this.selectedElement || this.multiselected) {
this.svgCanvas.cutSelectedElements() this.svgCanvas.cutSelectedElements()
} }
} }
@@ -752,7 +752,7 @@ class Editor extends EditorStartup {
* @returns {void} * @returns {void}
*/ */
copySelected () { copySelected () {
if (!isNullish(this.selectedElement) || this.multiselected) { if (this.selectedElement || this.multiselected) {
this.svgCanvas.copySelectedElements() this.svgCanvas.copySelectedElements()
} }
} }
@@ -774,7 +774,7 @@ class Editor extends EditorStartup {
* @returns {void} * @returns {void}
*/ */
moveUpDownSelected (dir) { moveUpDownSelected (dir) {
if (!isNullish(this.selectedElement)) { if (this.selectedElement) {
this.svgCanvas.moveUpDownSelected(dir) this.svgCanvas.moveUpDownSelected(dir)
} }
} }
@@ -785,7 +785,7 @@ class Editor extends EditorStartup {
* @returns {void} * @returns {void}
*/ */
moveSelected (dx, dy) { moveSelected (dx, dy) {
if (!isNullish(this.selectedElement) || this.multiselected) { if (this.selectedElement || this.multiselected) {
if (this.configObj.curConfig.gridSnapping) { if (this.configObj.curConfig.gridSnapping) {
// Use grid snap value regardless of zoom level // Use grid snap value regardless of zoom level
const multi = this.svgCanvas.getZoom() * this.configObj.curConfig.snappingStep const multi = this.svgCanvas.getZoom() * this.configObj.curConfig.snappingStep
@@ -818,7 +818,7 @@ class Editor extends EditorStartup {
* @returns {void} * @returns {void}
*/ */
rotateSelected (cw, step) { rotateSelected (cw, step) {
if (isNullish(this.selectedElement) || this.multiselected) { return } if (!this.selectedElement || this.multiselected) { return }
if (!cw) { step *= -1 } if (!cw) { step *= -1 }
const angle = Number.parseFloat($id('angle').value) + step const angle = Number.parseFloat($id('angle').value) + step
this.svgCanvas.setRotationAngle(angle) this.svgCanvas.setRotationAngle(angle)

View File

@@ -11,14 +11,6 @@ function toFixedNumeric (value, precision) {
if (precision === undefined) precision = 0 if (precision === undefined) precision = 0
return Math.round(value * (10 ** precision)) / (10 ** precision) return Math.round(value * (10 ** precision)) / (10 ** precision)
} }
/**
* Whether a value is `null` or `undefined`.
* @param {any} val
* @returns {boolean}
*/
const isNullish = (val) => {
return val === null || val === undefined
}
/** /**
* Controls for all the input elements for the typing in color values. * Controls for all the input elements for the typing in color values.
*/ */
@@ -39,7 +31,7 @@ export default class ColorValuePicker {
* @returns {Event|false|void} * @returns {Event|false|void}
*/ */
function keyDown (e) { function keyDown (e) {
if (e.target.value === '' && e.target !== hex && ((!isNullish(bindedHex) && e.target !== bindedHex) || isNullish(bindedHex))) return undefined if (e.target.value === '' && e.target !== hex && ((bindedHex && e.target !== bindedHex) || !bindedHex)) return undefined
if (!validateKey(e)) return e if (!validateKey(e)) return e
switch (e.target) { switch (e.target) {
case red: case red:
@@ -137,8 +129,8 @@ export default class ColorValuePicker {
*/ */
function keyUp (e) { function keyUp (e) {
if (e.target.value === '' && e.target !== hex && if (e.target.value === '' && e.target !== hex &&
((!isNullish(bindedHex) && e.target !== bindedHex) || ((bindedHex && e.target !== bindedHex) ||
isNullish(bindedHex))) return undefined !bindedHex)) return undefined
if (!validateKey(e)) return e if (!validateKey(e)) return e
switch (e.target) { switch (e.target) {
case red: case red:
@@ -181,7 +173,7 @@ export default class ColorValuePicker {
break break
case ahex: case ahex:
ahex.value = ahex.value.replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 2) ahex.value = ahex.value.replace(/[^a-fA-F\d]/g, '').toLowerCase().substring(0, 2)
color.val('a', !isNullish(ahex.value) ? Number.parseInt(ahex.value, 16) : null, e.target) color.val('a', ahex.value ? Number.parseInt(ahex.value, 16) : null, e.target)
break break
} }
return undefined return undefined
@@ -192,7 +184,7 @@ export default class ColorValuePicker {
* @returns {void} * @returns {void}
*/ */
function blur (e) { function blur (e) {
if (!isNullish(color.value)) { if (color.value) {
switch (e.target) { switch (e.target) {
case red: case red:
color.value = 'r' color.value = 'r'
@@ -274,16 +266,16 @@ export default class ColorValuePicker {
*/ */
function colorChanged (ui, context) { function colorChanged (ui, context) {
const all = ui.val('all') const all = ui.val('all')
if (context !== red) red.value = (!isNullish(all) ? all.r : '') if (context !== red) red.value = (all ? all.r : '')
if (context !== green) green.value = (!isNullish(all) ? all.g : '') if (context !== green) green.value = (all ? all.g : '')
if (context !== blue) blue.value = (!isNullish(all) ? all.b : '') if (context !== blue) blue.value = (all ? all.b : '')
if (alpha && context !== alpha) alpha.value = (!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : '') if (alpha && context !== alpha) alpha.value = (all ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : '')
if (context !== hue) hue.value = (!isNullish(all) ? all.h : '') if (context !== hue) hue.value = (all ? all.h : '')
if (context !== saturation) saturation.value = (!isNullish(all) ? all.s : '') if (context !== saturation) saturation.value = (all ? all.s : '')
if (context !== value) value.value = (!isNullish(all) ? all.v : '') if (context !== value) value.value = (all ? all.v : '')
if (context !== hex && ((bindedHex && context !== bindedHex) || !bindedHex)) hex.value = (!isNullish(all) ? all.hex : '') if (context !== hex && ((bindedHex && context !== bindedHex) || !bindedHex)) hex.value = (all ? all.hex : '')
if (bindedHex && context !== bindedHex && context !== hex) bindedHex.value = (!isNullish(all) ? all.hex : '') if (bindedHex && context !== bindedHex && context !== hex) bindedHex.value = (all ? all.hex : '')
if (ahex && context !== ahex) ahex.value = (!isNullish(all) ? all.ahex.substring(6) : '') if (ahex && context !== ahex) ahex.value = (all ? all.ahex.substring(6) : '')
} }
/** /**
* Unbind all events and null objects. * Unbind all events and null objects.

View File

@@ -1337,34 +1337,34 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
</tr> </tr>
<tr class="Hue"> <tr class="Hue">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_hue_radio')}"><input type="radio" value="h"${settings.color.mode === 'h' ? ' checked="checked"' : ''}/>H:</label></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_hue_radio')}"><input type="radio" value="h"${settings.color.mode === 'h' ? ' checked="checked"' : ''}/>H:</label></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.h : ''}" title="${i18next.t('config.jpicker_tooltip_hue_textbox')}"/>&nbsp;&deg;</td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.h : ''}" title="${i18next.t('config.jpicker_tooltip_hue_textbox')}"/>&nbsp;&deg;</td>
</tr> </tr>
<tr class="Saturation"> <tr class="Saturation">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_saturation_radio')}"><input type="radio" value="s"${settings.color.mode === 's' ? ' checked="checked"' : ''}/>S:</label></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_saturation_radio')}"><input type="radio" value="s"${settings.color.mode === 's' ? ' checked="checked"' : ''}/>S:</label></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.s : ''}" title="${i18next.t('config.jpicker_tooltip_saturation_textbox')}"/>&nbsp;%</td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.s : ''}" title="${i18next.t('config.jpicker_tooltip_saturation_textbox')}"/>&nbsp;%</td>
</tr> </tr>
<tr class="Value"> <tr class="Value">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_value_radio')}"><input type="radio" value="v"${settings.color.mode === 'v' ? ' checked="checked"' : ''}/>V:</label><br/><br/></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_value_radio')}"><input type="radio" value="v"${settings.color.mode === 'v' ? ' checked="checked"' : ''}/>V:</label><br/><br/></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.v : ''}" title="${i18next.t('config.jpicker_tooltip_value_textbox')}"/>&nbsp;%<br/><br/></td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.v : ''}" title="${i18next.t('config.jpicker_tooltip_value_textbox')}"/>&nbsp;%<br/><br/></td>
</tr> </tr>
<tr class="Red"> <tr class="Red">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_red_radio')}"><input type="radio" value="r"${settings.color.mode === 'r' ? ' checked="checked"' : ''}/>R:</label></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_red_radio')}"><input type="radio" value="r"${settings.color.mode === 'r' ? ' checked="checked"' : ''}/>R:</label></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.r : ''}" title="${i18next.t('config.jpicker_tooltip_red_textbox')}"/></td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.r : ''}" title="${i18next.t('config.jpicker_tooltip_red_textbox')}"/></td>
</tr> </tr>
<tr class="Green"> <tr class="Green">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_green_radio')}"><input type="radio" value="g"${settings.color.mode === 'g' ? ' checked="checked"' : ''}/>G:</label></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_green_radio')}"><input type="radio" value="g"${settings.color.mode === 'g' ? ' checked="checked"' : ''}/>G:</label></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.g : ''}" title="${i18next.t('config.jpicker_tooltip_green_textbox')}"/></td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.g : ''}" title="${i18next.t('config.jpicker_tooltip_green_textbox')}"/></td>
</tr> </tr>
<tr class="Blue"> <tr class="Blue">
<td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_blue_radio')}"><input type="radio" value="b"${settings.color.mode === 'b' ? ' checked="checked"' : ''}/>B:</label></td> <td class="Radio"><label title="${i18next.t('config.jpicker_tooltip_blue_radio')}"><input type="radio" value="b"${settings.color.mode === 'b' ? ' checked="checked"' : ''}/>B:</label></td>
<td class="Text"><input type="text" maxlength="3" value="${!isNullish(all) ? all.b : ''}" title="${i18next.t('config.jpicker_tooltip_blue_textbox')}"/></td> <td class="Text"><input type="text" maxlength="3" value="${all ? all.b : ''}" title="${i18next.t('config.jpicker_tooltip_blue_textbox')}"/></td>
</tr> </tr>
<tr class="Alpha"> <tr class="Alpha">
<td class="Radio">${win.alphaSupport ? `<label title="${i18next.t('config.jpicker_tooltip_alpha_radio')}"><input type="radio" value="a"${settings.color.mode === 'a' ? ' checked="checked"' : ''}/>A:</label>` : '&nbsp;'}</td> <td class="Radio">${win.alphaSupport ? `<label title="${i18next.t('config.jpicker_tooltip_alpha_radio')}"><input type="radio" value="a"${settings.color.mode === 'a' ? ' checked="checked"' : ''}/>A:</label>` : '&nbsp;'}</td>
<td class="Text">${win.alphaSupport ? `<input type="text" maxlength="${3 + win.alphaPrecision}" value="${!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, win.alphaPrecision) : ''}" title="${i18next.t('config.jpicker_tooltip_alpha_textbox')}"/>&nbsp;%` : '&nbsp;'}</td> <td class="Text">${win.alphaSupport ? `<input type="text" maxlength="${3 + win.alphaPrecision}" value="${all ? toFixedNumeric((all.a * 100) / 255, win.alphaPrecision) : ''}" title="${i18next.t('config.jpicker_tooltip_alpha_textbox')}"/>&nbsp;%` : '&nbsp;'}</td>
</tr> </tr>
<tr class="Hex"> <tr class="Hex">
<td colspan="2" class="Text"><label title="${i18next.t('config.jpicker_tooltip_hex_textbox')}">#:<input type="text" maxlength="6" class="Hex" value="${!isNullish(all) ? all.hex : ''}"/></label>${win.alphaSupport ? `<input type="text" maxlength="2" class="AHex" value="${!isNullish(all) ? all.ahex.substring(6) : ''}" title="${i18next.t('config.jpicker_tooltip_hex_alpha')}"/></td>` : '&nbsp;'} <td colspan="2" class="Text"><label title="${i18next.t('config.jpicker_tooltip_hex_textbox')}">#:<input type="text" maxlength="6" class="Hex" value="${all ? all.hex : ''}"/></label>${win.alphaSupport ? `<input type="text" maxlength="2" class="AHex" value="${all ? all.ahex.substring(6) : ''}" title="${i18next.t('config.jpicker_tooltip_hex_alpha')}"/></td>` : '&nbsp;'}
</tr> </tr>
</tbody></table>` </tbody></table>`
if (win.expandable) { if (win.expandable) {
@@ -1455,7 +1455,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
win.expandable && win.bindToInput ? win.input : null, win.expandable && win.bindToInput ? win.input : null,
win.alphaPrecision win.alphaPrecision
) )
const hex = !isNullish(all) ? all.hex : null const hex = all ? all.hex : null
const preview = tbody.querySelector('#Preview') const preview = tbody.querySelector('#Preview')
const button = tbody.querySelector('#Button') const button = tbody.querySelector('#Button')
activePreview = preview.querySelector('#Active') activePreview = preview.querySelector('#Active')
@@ -1523,7 +1523,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
iconColor.style.backgroundColor = (hex && '#' + hex) || 'transparent' iconColor.style.backgroundColor = (hex && '#' + hex) || 'transparent'
iconAlpha = that.icon.querySelector('.Alpha') iconAlpha = that.icon.querySelector('.Alpha')
setImg.call(that, iconAlpha, images.clientPath + 'bar-opacity.png') setImg.call(that, iconAlpha, images.clientPath + 'bar-opacity.png')
setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (!isNullish(all) ? all.a : 0)) * 100) / 255, 4)) setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (all ? all.a : 0)) * 100) / 255, 4))
iconImage = that.icon.querySelector('.Image') iconImage = that.icon.querySelector('.Image')
iconImage.style.backgroundImage = 'url(\'' + images.clientPath + images.picker.file + '\')' iconImage.style.backgroundImage = 'url(\'' + images.clientPath + images.picker.file + '\')'
iconImage.addEventListener('click', iconImageClicked) iconImage.addEventListener('click', iconImageClicked)
@@ -1531,7 +1531,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
win.input.style.backgroundColor = (hex && '#' + hex) || 'transparent' win.input.style.backgroundColor = (hex && '#' + hex) || 'transparent'
win.input.style.color = isNullish(all) || all.v > 75 ? '#000000' : '#ffffff' win.input.style.color = isNullish(all) || all.v > 75 ? '#000000' : '#ffffff'
} }
const moveBar = tbody.querySelector('.Move') moveBar = tbody.querySelector('.Move')
moveBar.addEventListener('mousedown', moveBarMouseDown) moveBar.addEventListener('mousedown', moveBarMouseDown)
color.active.bind(expandableColorChanged) color.active.bind(expandableColorChanged)
} else { } else {
@@ -1658,7 +1658,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc
let iconColor = null // iconColor for popup icon let iconColor = null // iconColor for popup icon
let iconAlpha = null // iconAlpha for popup icon let iconAlpha = null // iconAlpha for popup icon
let iconImage = null // iconImage popup icon let iconImage = null // iconImage popup icon
const moveBar = null // drag bar let moveBar = null // drag bar
Object.assign(that, { Object.assign(that, {
// public properties, methods, and callbacks // public properties, methods, and callbacks
commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK" commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK"

View File

@@ -233,9 +233,7 @@ export default {
} }
// Else fall through // Else fall through
default: default:
// TODO: See if there's a way to base64 encode the binary data stream // TODO: See if there's a way to base64 encode the binary data stream
// const str = 'data:;base64,' + svgedit.utilities.encode64(response, true);
// Assume it's raw image data // Assume it's raw image data
// importImage(str); // importImage(str);

View File

@@ -56,11 +56,7 @@ class BottomPanel {
break break
default: default:
{ {
const zoomlevel = Number(value) / 100 const zoomlevel = Number(value) > 0.1 ? Number(value) > 0.1 : 0.1
if (zoomlevel < 0.001) {
value = 0.1
return
}
const zoom = this.editor.svgCanvas.getZoom() const zoom = this.editor.svgCanvas.getZoom()
const { workarea } = this.editor const { workarea } = this.editor
this.editor.zoomChanged(window, { this.editor.zoomChanged(window, {

View File

@@ -409,7 +409,7 @@ class TopPanel {
'#group' '#group'
) )
// if (!isNullish(elem)) // if (elem)
} else if (this.multiselected) { } else if (this.multiselected) {
this.displayTool('multiselected_panel') this.displayTool('multiselected_panel')
menuItems.setAttribute('enablemenuitems', '#group') menuItems.setAttribute('enablemenuitems', '#group')

View File

@@ -24,10 +24,6 @@ const pathMap = [
* @function module:coords.EditorContext#getGridSnapping * @function module:coords.EditorContext#getGridSnapping
* @returns {boolean} * @returns {boolean}
*/ */
/**
* @function module:coords.EditorContext#getDrawing
* @returns {module:draw.Drawing}
*/
/** /**
* @function module:coords.EditorContext#getSvgRoot * @function module:coords.EditorContext#getSvgRoot
* @returns {SVGSVGElement} * @returns {SVGSVGElement}
@@ -84,7 +80,7 @@ export const remapElement = function (selected, changes, m) {
newgrad.setAttribute('y1', -(y1 - 1)) newgrad.setAttribute('y1', -(y1 - 1))
newgrad.setAttribute('y2', -(y2 - 1)) newgrad.setAttribute('y2', -(y2 - 1))
} }
newgrad.id = svgCanvas.getDrawing().getNextId() newgrad.id = svgCanvas.getCurrentDrawing().getNextId()
findDefs().append(newgrad) findDefs().append(newgrad)
selected.setAttribute(type, 'url(#' + newgrad.id + ')') selected.setAttribute(type, 'url(#' + newgrad.id + ')')
} }

View File

@@ -18,7 +18,7 @@ const dataStorage = {
}, },
remove: function (element, key) { remove: function (element, key) {
const ret = this._storage.get(element).delete(key) const ret = this._storage.get(element).delete(key)
if (!this._storage.get(element).size === 0) { if (this._storage.get(element).size === 0) {
this._storage.delete(element) this._storage.delete(element)
} }
return ret return ret

View File

@@ -6,7 +6,7 @@
* @copyright 2010 Jeff Schiller * @copyright 2010 Jeff Schiller
*/ */
import { getHref, setHref, getRotationAngle, isNullish, getBBox } from './utilities.js' import { getHref, setHref, getRotationAngle, getBBox } from './utilities.js'
/** /**
* Group: Undo/Redo history management. * Group: Undo/Redo history management.
@@ -255,7 +255,7 @@ export class RemoveElementCommand extends Command {
*/ */
unapply (handler) { unapply (handler) {
super.unapply(handler, () => { super.unapply(handler, () => {
if (isNullish(this.nextSibling) && window.console) { if (!this.nextSibling && window.console) {
console.error('Reference element was lost') 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` this.parent.insertBefore(this.elem, this.nextSibling) // Don't use `before` or `prepend` as `this.nextSibling` may be `null`
@@ -581,7 +581,7 @@ export class UndoManager {
const oldValues = new Array(i); const elements = new Array(i) const oldValues = new Array(i); const elements = new Array(i)
while (i--) { while (i--) {
const elem = elems[i] const elem = elems[i]
if (isNullish(elem)) { continue } if (!elem) { continue }
elements[i] = elem elements[i] = elem
oldValues[i] = elem.getAttribute(attrName) oldValues[i] = elem.getAttribute(attrName)
} }
@@ -606,7 +606,7 @@ export class UndoManager {
let i = changeset.elements.length let i = changeset.elements.length
while (i--) { while (i--) {
const elem = changeset.elements[i] const elem = changeset.elements[i]
if (isNullish(elem)) { continue } if (!elem) { continue }
const changes = {} const changes = {}
changes[attrName] = changeset.oldValues[i] changes[attrName] = changeset.oldValues[i]
if (changes[attrName] !== elem.getAttribute(attrName)) { if (changes[attrName] !== elem.getAttribute(attrName)) {

View File

@@ -7,7 +7,7 @@
*/ */
import { NS } from './namespaces.js' import { NS } from './namespaces.js'
import { toXml, walkTree, isNullish } from './utilities.js' import { toXml, walkTree } from './utilities.js'
/** /**
* This class encapsulates the concept of a layer in the drawing. It can be constructed with * This class encapsulates the concept of a layer in the drawing. It can be constructed with
@@ -114,7 +114,7 @@ class Layer {
*/ */
getOpacity () { getOpacity () {
const opacity = this.group_.getAttribute('opacity') const opacity = this.group_.getAttribute('opacity')
if (isNullish(opacity)) { if (!opacity) {
return 1 return 1
} }
return Number.parseFloat(opacity) return Number.parseFloat(opacity)
@@ -218,7 +218,7 @@ Layer.CLASS_REGEX = new RegExp('(\\s|^)' + Layer.CLASS_NAME + '(\\s|$)')
*/ */
function addLayerClass (elem) { function addLayerClass (elem) {
const classes = elem.getAttribute('class') const classes = elem.getAttribute('class')
if (isNullish(classes) || !classes.length) { if (!classes || !classes.length) {
elem.setAttribute('class', Layer.CLASS_NAME) elem.setAttribute('class', Layer.CLASS_NAME)
} else if (!Layer.CLASS_REGEX.test(classes)) { } else if (!Layer.CLASS_REGEX.test(classes)) {
elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME) elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME)

View File

@@ -14,7 +14,7 @@ import {
transformListToTransform transformListToTransform
} from './math.js' } from './math.js'
import { import {
assignAttributes, getElement, getRotationAngle, snapToGrid, isNullish, assignAttributes, getElement, getRotationAngle, snapToGrid,
getBBox getBBox
} from './utilities.js' } from './utilities.js'
@@ -541,7 +541,7 @@ export const pathActionsMethod = (function () {
// Start selection box // Start selection box
if (!path.dragging) { if (!path.dragging) {
let rubberBox = svgCanvas.getRubberBox() let rubberBox = svgCanvas.getRubberBox()
if (isNullish(rubberBox)) { if (!rubberBox) {
rubberBox = svgCanvas.setRubberBox( rubberBox = svgCanvas.setRubberBox(
svgCanvas.selectorManager.getRubberBandBox() svgCanvas.selectorManager.getRubberBandBox()
) )
@@ -875,7 +875,7 @@ export const pathActionsMethod = (function () {
* @returns {false|void} * @returns {false|void}
*/ */
resetOrientation (pth) { resetOrientation (pth) {
if (isNullish(pth) || pth.nodeName !== 'path') { return false } if (pth?.nodeName !== 'path') { return false }
const tlist = pth.transform.baseVal const tlist = pth.transform.baseVal
const m = transformListToTransform(tlist).matrix const m = transformListToTransform(tlist).matrix
tlist.clear() tlist.clear()
@@ -1007,7 +1007,7 @@ export const pathActionsMethod = (function () {
return true return true
}) })
if (isNullish(openPt)) { if (!openPt) {
// Single path, so close last seg // Single path, so close last seg
openPt = path.segs.length - 1 openPt = path.segs.length - 1
} }

View File

@@ -12,7 +12,7 @@ import {
transformPoint, getMatrix transformPoint, getMatrix
} from './math.js' } from './math.js'
import { import {
assignAttributes, getRotationAngle, isNullish, assignAttributes, getRotationAngle,
getElement getElement
} from './utilities.js' } from './utilities.js'
@@ -635,7 +635,7 @@ export class Path {
seg.next.prev = seg seg.next.prev = seg
seg.mate = segs[startI] seg.mate = segs[startI]
seg.addGrip() seg.addGrip()
if (isNullish(this.first_seg)) { if (!this.first_seg) {
this.first_seg = seg this.first_seg = seg
} }
} else if (!nextSeg) { } else if (!nextSeg) {
@@ -907,7 +907,7 @@ export class Path {
*/ */
selectPt (pt, ctrlNum) { selectPt (pt, ctrlNum) {
this.clearSelection() this.clearSelection()
if (isNullish(pt)) { if (!pt) {
this.eachSeg(function (i) { this.eachSeg(function (i) {
// 'this' is the segment here. // 'this' is the segment here.
if (this.prev) { if (this.prev) {

View File

@@ -10,7 +10,7 @@ import { shortFloat } from '../common/units.js'
import { transformPoint } from './math.js' import { transformPoint } from './math.js'
import { import {
getRotationAngle, getBBox, getRotationAngle, getBBox,
getRefElem, findDefs, isNullish, getRefElem, findDefs,
getBBox as utilsGetBBox getBBox as utilsGetBBox
} from './utilities.js' } from './utilities.js'
import { import {
@@ -209,10 +209,6 @@ export let path = null
* @param {string} cm The mode * @param {string} cm The mode
* @returns {string} The same mode as passed in * @returns {string} The same mode as passed in
*/ */
/**
* @function module:path.EditorContext#getDrawnPath
* @returns {SVGPathElement|null}
*/
/** /**
* @function module:path.EditorContext#setDrawnPath * @function module:path.EditorContext#setDrawnPath
* @param {SVGPathElement|null} dp * @param {SVGPathElement|null} dp
@@ -501,7 +497,7 @@ export const recalcRotatedPath = () => {
const rvals = getRotVals(seg.x, seg.y) const rvals = getRotVals(seg.x, seg.y)
const points = [rvals.x, rvals.y] const points = [rvals.x, rvals.y]
if (!isNullish(seg.x1) && !isNullish(seg.x2)) { if (seg.x1 && seg.x2) {
const cVals1 = getRotVals(seg.x1, seg.y1) const cVals1 = getRotVals(seg.x1, seg.y1)
const cVals2 = getRotVals(seg.x2, seg.y2) const cVals2 = getRotVals(seg.x2, seg.y2)
points.splice(points.length, 0, cVals1.x, cVals1.y, cVals2.x, cVals2.y) points.splice(points.length, 0, cVals1.x, cVals1.y, cVals2.x, cVals2.y)

View File

@@ -6,7 +6,7 @@
import { NS } from './namespaces.js' import { NS } from './namespaces.js'
import { convertToNum } from '../common/units.js' import { convertToNum } from '../common/units.js'
import { getRotationAngle, getHref, getBBox, getRefElem, isNullish } from './utilities.js' import { getRotationAngle, getHref, getBBox, getRefElem } from './utilities.js'
import { BatchCommand, ChangeElementCommand } from './history.js' import { BatchCommand, ChangeElementCommand } from './history.js'
import { remapElement } from './coords.js' import { remapElement } from './coords.js'
import { import {
@@ -231,7 +231,7 @@ export const recalculateDimensions = function (selected) {
// if we haven't created an initial array in polygon/polyline/path, then // if we haven't created an initial array in polygon/polyline/path, then
// make a copy of initial values and include the transform // make a copy of initial values and include the transform
if (isNullish(initial)) { if (!initial) {
initial = mergeDeep({}, changes) initial = mergeDeep({}, changes)
for (const [attr, val] of Object.entries(initial)) { for (const [attr, val] of Object.entries(initial)) {
initial[attr] = convertToNum(attr, val) initial[attr] = convertToNum(attr, val)

View File

@@ -7,7 +7,7 @@
*/ */
import { isTouch, isWebkit } from '../common/browser.js' // , isOpera import { isTouch, isWebkit } from '../common/browser.js' // , isOpera
import { getRotationAngle, getBBox, getStrokedBBox, isNullish } from './utilities.js' import { getRotationAngle, getBBox, getStrokedBBox } from './utilities.js'
import { transformListToTransform, transformBox, transformPoint } from './math.js' import { transformListToTransform, transformBox, transformPoint } from './math.js'
let svgCanvas let svgCanvas
@@ -439,7 +439,7 @@ export class SelectorManager {
* @returns {void} * @returns {void}
*/ */
releaseSelector (elem) { releaseSelector (elem) {
if (isNullish(elem)) { return } if (!elem) { return }
const N = this.selectors.length const N = this.selectors.length
const sel = this.selectorMap[elem.id] const sel = this.selectorMap[elem.id]
if (sel && !sel.locked) { if (sel && !sel.locked) {