minor es6 improvements

This commit is contained in:
JFH
2022-01-01 09:27:45 -03:00
parent b10f4be943
commit 82fab95988
14 changed files with 29 additions and 29 deletions

View File

@@ -12,7 +12,7 @@ let svgCanvas = null
* @param {module:blur.blurContext} blurContext * @param {module:blur.blurContext} blurContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -36,7 +36,7 @@ let svgCanvas = null
* @param {module:svgcanvas.SvgCanvas#event:pointsAdded} editorContext * @param {module:svgcanvas.SvgCanvas#event:pointsAdded} editorContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -754,7 +754,7 @@ let svgCanvas
* @param {module:draw.DrawCanvasInit} canvas * @param {module:draw.DrawCanvasInit} canvas
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -22,7 +22,7 @@ let svgCanvas = null
* @param {module:elem-get-set.elemContext} elemContext * @param {module:elem-get-set.elemContext} elemContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -25,7 +25,7 @@ let svgdoc_ = null
* @param {module:json.jsonContext} jsonContext * @param {module:json.jsonContext} jsonContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
svgdoc_ = canvas.getDOMDocument() svgdoc_ = canvas.getDOMDocument()
} }

View File

@@ -14,7 +14,7 @@ let svgCanvas = null
* @param {module:paste-elem.pasteContext} pasteContext * @param {module:paste-elem.pasteContext} pasteContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -26,7 +26,7 @@ let path = null
* @param {module:path-actions.svgCanvas} pathActionsContext * @param {module:path-actions.svgCanvas} pathActionsContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -23,7 +23,7 @@ let svgCanvas = null
* @param {module:path-actions.svgCanvas} pathMethodsContext * @param {module:path-actions.svgCanvas} pathMethodsContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -41,7 +41,7 @@ let svgCanvas
* @param {module:recalculate.EditorContext} editorContext * @param {module:recalculate.EditorContext} editorContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }
@@ -53,7 +53,7 @@ export const init = function (canvas) {
* @param {Float} ty - The translation's y value * @param {Float} ty - The translation's y value
* @returns {void} * @returns {void}
*/ */
export const updateClipPath = function (attr, tx, ty) { export const updateClipPath = (attr, tx, ty) => {
const path = getRefElem(attr).firstChild const path = getRefElem(attr).firstChild
const cpXform = path.transform.baseVal const cpXform = path.transform.baseVal
const newxlate = svgCanvas.getSvgRoot().createSVGTransform() const newxlate = svgCanvas.getSvgRoot().createSVGTransform()
@@ -71,7 +71,7 @@ export const updateClipPath = function (attr, tx, ty) {
* @param {Element} selected - The DOM element to recalculate * @param {Element} selected - The DOM element to recalculate
* @returns {Command} Undo command object with the resulting change * @returns {Command} Undo command object with the resulting change
*/ */
export const recalculateDimensions = function (selected) { export const recalculateDimensions = (selected) => {
if (!selected) return null if (!selected) return null
const svgroot = svgCanvas.getSvgRoot() const svgroot = svgCanvas.getSvgRoot()
const dataStorage = svgCanvas.getDataStorage() const dataStorage = svgCanvas.getDataStorage()
@@ -215,7 +215,7 @@ export const recalculateDimensions = function (selected) {
} // switch on element type to get initial values } // switch on element type to get initial values
if (attrs.length) { if (attrs.length) {
Array.prototype.forEach.call(attrs, function (attr) { Array.prototype.forEach.call(attrs, (attr) => {
changes[attr] = selected.getAttribute(attr) changes[attr] = selected.getAttribute(attr)
}) })
for (const [attr, val] of Object.entries(changes)) { for (const [attr, val] of Object.entries(changes)) {

View File

@@ -35,7 +35,7 @@ let svgCanvas = null
* @param {module:selected-elem.elementContext} elementContext * @param {module:selected-elem.elementContext} elementContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -26,7 +26,7 @@ let svgCanvas = null
* @param {module:selection.selectionContext} selectionContext * @param {module:selection.selectionContext} selectionContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }
@@ -37,7 +37,7 @@ export const init = function (canvas) {
* @type {module:draw.DrawCanvasInit#clearSelection|module:path.EditorContext#clearSelection} * @type {module:draw.DrawCanvasInit#clearSelection|module:path.EditorContext#clearSelection}
* @fires module:selection.SvgCanvas#event:selected * @fires module:selection.SvgCanvas#event:selected
*/ */
export const clearSelectionMethod = function (noCall) { export const clearSelectionMethod = (noCall) => {
const selectedElements = svgCanvas.getSelectedElements() const selectedElements = svgCanvas.getSelectedElements()
selectedElements.forEach((elem) => { selectedElements.forEach((elem) => {
if (!elem) { if (!elem) {
@@ -59,7 +59,7 @@ export const clearSelectionMethod = function (noCall) {
* @type {module:path.EditorContext#addToSelection} * @type {module:path.EditorContext#addToSelection}
* @fires module:selection.SvgCanvas#event:selected * @fires module:selection.SvgCanvas#event:selected
*/ */
export const addToSelectionMethod = function (elemsToAdd, showGrips) { export const addToSelectionMethod = (elemsToAdd, showGrips) => {
const selectedElements = svgCanvas.getSelectedElements() const selectedElements = svgCanvas.getSelectedElements()
if (!elemsToAdd.length) { if (!elemsToAdd.length) {
return return
@@ -115,7 +115,7 @@ export const addToSelectionMethod = function (elemsToAdd, showGrips) {
// make sure the elements are in the correct order // make sure the elements are in the correct order
// See: https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-compareDocumentPosition // See: https://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-compareDocumentPosition
selectedElements.sort(function (a, b) { selectedElements.sort((a, b) => {
if (a && b && a.compareDocumentPosition) { if (a && b && a.compareDocumentPosition) {
return 3 - (b.compareDocumentPosition(a) & 6) return 3 - (b.compareDocumentPosition(a) & 6)
} }
@@ -134,7 +134,7 @@ export const addToSelectionMethod = function (elemsToAdd, showGrips) {
* @name module:svgcanvas.SvgCanvas#getMouseTarget * @name module:svgcanvas.SvgCanvas#getMouseTarget
* @type {module:path.EditorContext#getMouseTarget} * @type {module:path.EditorContext#getMouseTarget}
*/ */
export const getMouseTargetMethod = function (evt) { export const getMouseTargetMethod = (evt) => {
if (!evt) { if (!evt) {
return null return null
} }
@@ -212,12 +212,12 @@ export const getMouseTargetMethod = function (evt) {
* @returns {GenericArray<module:svgcanvas.ExtensionStatus>|module:svgcanvas.ExtensionStatus|false} See {@tutorial ExtensionDocs} on the ExtensionStatus. * @returns {GenericArray<module:svgcanvas.ExtensionStatus>|module:svgcanvas.ExtensionStatus|false} See {@tutorial ExtensionDocs} on the ExtensionStatus.
*/ */
/* eslint-enable max-len */ /* eslint-enable max-len */
export const runExtensionsMethod = function ( export const runExtensionsMethod = (
action, action,
vars, vars,
returnArray, returnArray,
nameFilter nameFilter
) { ) => {
let result = returnArray ? [] : false let result = returnArray ? [] : false
for (const [name, ext] of Object.entries(svgCanvas.getExtensions())) { for (const [name, ext] of Object.entries(svgCanvas.getExtensions())) {
if (nameFilter && !nameFilter(name)) { if (nameFilter && !nameFilter(name)) {
@@ -245,7 +245,7 @@ export const runExtensionsMethod = function (
* @param {Element} parent - The parent DOM element to search within * @param {Element} parent - The parent DOM element to search within
* @returns {ElementAndBBox[]} An array with objects that include: * @returns {ElementAndBBox[]} An array with objects that include:
*/ */
export const getVisibleElementsAndBBoxes = function (parent) { export const getVisibleElementsAndBBoxes = (parent) => {
if (!parent) { if (!parent) {
const svgContent = svgCanvas.getSvgContent() const svgContent = svgCanvas.getSvgContent()
parent = svgContent.children // Prevent layers from being included parent = svgContent.children // Prevent layers from being included
@@ -272,7 +272,7 @@ export const getVisibleElementsAndBBoxes = function (parent) {
* @param {SVGRect} rect * @param {SVGRect} rect
* @returns {Element[]|NodeList} Bbox elements * @returns {Element[]|NodeList} Bbox elements
*/ */
export const getIntersectionListMethod = function (rect) { export const getIntersectionListMethod = (rect) => {
const zoom = svgCanvas.getZoom() const zoom = svgCanvas.getZoom()
if (!svgCanvas.getRubberBox()) { if (!svgCanvas.getRubberBox()) {
return null return null
@@ -335,7 +335,7 @@ export const getIntersectionListMethod = function (rect) {
* @param {Element} elem - SVG element to wrap * @param {Element} elem - SVG element to wrap
* @returns {void} * @returns {void}
*/ */
export const groupSvgElem = function (elem) { export const groupSvgElem = (elem) => {
const dataStorage = svgCanvas.getDataStorage() const dataStorage = svgCanvas.getDataStorage()
const g = document.createElementNS(NS.SVG, 'g') const g = document.createElementNS(NS.SVG, 'g')
elem.replaceWith(g) elem.replaceWith(g)
@@ -350,7 +350,7 @@ export const groupSvgElem = function (elem) {
* @param {XMLDocument} newDoc - The SVG DOM document * @param {XMLDocument} newDoc - The SVG DOM document
* @returns {void} * @returns {void}
*/ */
export const prepareSvg = function (newDoc) { export const prepareSvg = (newDoc) => {
svgCanvas.sanitizeSvg(newDoc.documentElement) svgCanvas.sanitizeSvg(newDoc.documentElement)
// convert paths into absolute commands // convert paths into absolute commands
@@ -371,7 +371,7 @@ export const prepareSvg = function (newDoc) {
* @fires module:svgcanvas.SvgCanvas#event:changed * @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {void} * @returns {void}
*/ */
export const setRotationAngle = function (val, preventUndo) { export const setRotationAngle = (val, preventUndo) => {
const selectedElements = svgCanvas.getSelectedElements() const selectedElements = svgCanvas.getSelectedElements()
// ensure val is the proper type // ensure val is the proper type
val = Number.parseFloat(val) val = Number.parseFloat(val)
@@ -441,7 +441,7 @@ export const setRotationAngle = function (val, preventUndo) {
* @fires module:svgcanvas.SvgCanvas#event:changed * @fires module:svgcanvas.SvgCanvas#event:changed
* @returns {void} * @returns {void}
*/ */
export const recalculateAllSelectedDimensions = function () { export const recalculateAllSelectedDimensions = () => {
const text = const text =
svgCanvas.getCurrentResizeMode() === 'none' ? 'position' : 'size' svgCanvas.getCurrentResizeMode() === 'none' ? 'position' : 'size'
const batchCmd = new BatchCommand(text) const batchCmd = new BatchCommand(text)

View File

@@ -41,7 +41,7 @@ let svgCanvas = null
* @param {module:svg-exec.SvgCanvas#init} svgContext * @param {module:svg-exec.SvgCanvas#init} svgContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -23,7 +23,7 @@ let svgCanvas = null
* @param {module:text-actions.svgCanvas} textActionsContext * @param {module:text-actions.svgCanvas} textActionsContext
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
} }

View File

@@ -80,7 +80,7 @@ let svgroot_ = null
* @param {module:utilities.EditorContext} canvas * @param {module:utilities.EditorContext} canvas
* @returns {void} * @returns {void}
*/ */
export const init = function (canvas) { export const init = (canvas) => {
svgCanvas = canvas svgCanvas = canvas
svgroot_ = canvas.getSvgRoot() svgroot_ = canvas.getSvgRoot()
} }