fix a test case issue

master
JFH 2022-01-05 18:00:02 -03:00
parent 958832de9c
commit 1049fd7146
4 changed files with 38 additions and 42 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)
}
@ -914,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)
}

View File

@ -104,7 +104,7 @@ export const dropXMLInternalSubset = (str) => {
* @param {string} str - The string to be converted
* @returns {string} The converted string
*/
export const toXml = function (str) {
export const toXml = (str) => {
// ' is ok in XML, but not HTML
// > does not normally need escaping, though it can if within a CDATA expression (and preceded by "]]")
return str
@ -159,7 +159,7 @@ export function decodeUTF8 (argString) {
* @param {string} argString
* @returns {string}
*/
export const encodeUTF8 = function (argString) {
export const encodeUTF8 = (argString) => {
return unescape(encodeURIComponent(argString))
}
@ -169,7 +169,7 @@ export const encodeUTF8 = function (argString) {
* @param {string} dataurl
* @returns {string} object URL or empty string
*/
export const dataURLToObjectURL = function (dataurl) {
export const dataURLToObjectURL = (dataurl) => {
if (typeof Uint8Array === 'undefined' || typeof Blob === 'undefined' || typeof URL === 'undefined' || !URL.createObjectURL) {
return ''
}
@ -196,7 +196,7 @@ export const dataURLToObjectURL = function (dataurl) {
* @param {Blob} blob A Blob object or File object
* @returns {string} object URL or empty string
*/
export const createObjectURL = function (blob) {
export const createObjectURL = (blob) => {
if (!blob || typeof URL === 'undefined' || !URL.createObjectURL) {
return ''
}
@ -206,7 +206,7 @@ export const createObjectURL = function (blob) {
/**
* @property {string} blankPageObjectURL
*/
export const blankPageObjectURL = (function () {
export const blankPageObjectURL = (() => {
if (typeof Blob === 'undefined') {
return ''
}
@ -220,7 +220,7 @@ export const blankPageObjectURL = (function () {
* @param {string} input
* @returns {string} Decimal numeric character references
*/
export const convertToXMLReferences = function (input) {
export const convertToXMLReferences = (input) => {
let output = '';
[...input].forEach((ch) => {
const c = ch.charCodeAt()
@ -237,7 +237,7 @@ export const convertToXMLReferences = function (input) {
* @throws {Error}
* @returns {XMLDocument}
*/
export const text2xml = function (sXML) {
export const text2xml = (sXML) => {
if (sXML.includes('<svg:svg')) {
sXML = sXML.replace(/<(\/?)svg:/g, '<$1').replace('xmlns:svg', 'xmlns')
}
@ -269,7 +269,7 @@ export const text2xml = function (sXML) {
* @param {SVGRect} bbox - a SVGRect
* @returns {module:utilities.BBoxObject} An object with properties names x, y, width, height.
*/
export const bboxToObj = function ({ x, y, width, height }) {
export const bboxToObj = ({ x, y, width, height }) => {
return { x, y, width, height }
}
@ -286,7 +286,7 @@ export const bboxToObj = function ({ x, y, width, height }) {
* @param {module:utilities.TreeWalker} cbFn - Callback function to run on each element
* @returns {void}
*/
export const walkTree = function (elem, cbFn) {
export const walkTree = (elem, cbFn) => {
if (elem?.nodeType === 1) {
cbFn(elem)
let i = elem.childNodes.length
@ -304,8 +304,8 @@ export const walkTree = function (elem, cbFn) {
* @param {module:utilities.TreeWalker} cbFn - Callback function to run on each element
* @returns {void}
*/
export const walkTreePost = function (elem, cbFn) {
if (elem && elem.nodeType === 1) {
export const walkTreePost = (elem, cbFn) => {
if (elem?.nodeType === 1) {
let i = elem.childNodes.length
while (i--) {
walkTree(elem.childNodes.item(i), cbFn)
@ -862,7 +862,7 @@ export const getBBoxWithTransform = function (elem, addSVGElementsFromJson, path
* @todo This is problematic with large stroke-width and, for example, a single
* horizontal line. The calculated BBox extends way beyond left and right sides.
*/
function getStrokeOffsetForBBox (elem) {
const getStrokeOffsetForBBox = (elem) => {
const sw = elem.getAttribute('stroke-width')
return (!isNaN(sw) && elem.getAttribute('stroke') !== 'none') ? sw / 2 : 0
}
@ -883,11 +883,11 @@ function getStrokeOffsetForBBox (elem) {
* @param {module:path.pathActions} pathActions - If a transform exists, pathActions.resetOrientation() is used. See: canvas.pathActions.
* @returns {module:utilities.BBoxObject|module:math.TransformedBox|DOMRect} A single bounding box object
*/
export const getStrokedBBox = function (elems, addSVGElementsFromJson, pathActions) {
export const getStrokedBBox = (elems, addSVGElementsFromJson, pathActions) => {
if (!elems || !elems.length) { return false }
let fullBb
elems.forEach(function (elem) {
elems.forEach((elem) => {
if (fullBb) { return }
if (!elem.parentNode) { return }
fullBb = getBBoxWithTransform(elem, addSVGElementsFromJson, pathActions)
@ -912,7 +912,7 @@ export const getStrokedBBox = function (elems, addSVGElementsFromJson, pathActio
maxX += offset
maxY += offset
} else {
elems.forEach(function (elem) {
elems.forEach((elem) => {
const curBb = getBBoxWithTransform(elem, addSVGElementsFromJson, pathActions)
if (curBb) {
const offset = getStrokeOffsetForBBox(elem)
@ -942,7 +942,7 @@ export const getStrokedBBox = function (elems, addSVGElementsFromJson, pathActio
* @param {Element} parentElement - The parent DOM element to search within
* @returns {Element[]} All "visible" elements.
*/
export const getVisibleElements = function (parentElement) {
export const getVisibleElements = (parentElement) => {
if (!parentElement) {
const svgContent = svgCanvas.getSvgContent()
parentElement = svgContent.children[0] // Prevent layers from being included
@ -965,7 +965,7 @@ export const getVisibleElements = function (parentElement) {
* @param {Element[]} elems - Array with DOM elements to check
* @returns {module:utilities.BBoxObject} A single bounding box object
*/
export const getStrokedBBoxDefaultVisible = function (elems) {
export const getStrokedBBoxDefaultVisible = (elems) => {
if (!elems) { elems = getVisibleElements() }
return getStrokedBBox(
elems,
@ -999,7 +999,7 @@ export const getRotationAngleFromTransformList = (tlist, toRad) => {
* @param {boolean} [toRad=false] - When true returns the value in radians rather than degrees
* @returns {Float} The angle in degrees or radians
*/
export let getRotationAngle = function (elem, toRad) {
export let getRotationAngle = (elem, toRad) => {
const selected = elem || svgCanvas.getSelectedElements()[0]
// find the rotation transform (if any) and set it
const tlist = selected.transform?.baseVal
@ -1012,7 +1012,7 @@ export let getRotationAngle = function (elem, toRad) {
* @param {string} attrVal - The attribute value as a string
* @returns {Element} Reference element
*/
export const getRefElem = function (attrVal) {
export const getRefElem = (attrVal) => {
return getElement(getUrlFromAttr(attrVal).substr(1))
}
/**
@ -1021,7 +1021,7 @@ export const getRefElem = function (attrVal) {
* @param {any} Element
* @returns {any} Reference element
*/
export const getFeGaussianBlur = function (ele) {
export const getFeGaussianBlur = (ele) => {
if (ele?.firstChild?.tagName === 'feGaussianBlur') {
return ele.firstChild
} else {
@ -1056,12 +1056,12 @@ export const getElement = (id) => {
* @param {boolean} [unitCheck=false] - Boolean to indicate the need to use units.setUnitAttr
* @returns {void}
*/
export const assignAttributes = function (elem, attrs, suspendLength, unitCheck) {
export const assignAttributes = (elem, attrs, suspendLength, unitCheck) => {
for (const [key, value] of Object.entries(attrs)) {
const ns = (key.substr(0, 4) === 'xml:'
? NS.XML
: key.substr(0, 6) === 'xlink:' ? NS.XLINK : null)
if (!value) {
if (value === undefined) {
if (ns) {
elem.removeAttributeNS(ns, key)
} else {
@ -1085,7 +1085,7 @@ export const assignAttributes = function (elem, attrs, suspendLength, unitCheck)
* @param {Element} element - DOM element to clean up
* @returns {void}
*/
export const cleanupElement = function (element) {
export const cleanupElement = (element) => {
const defaults = {
'fill-opacity': 1,
'stop-opacity': 1,
@ -1119,7 +1119,7 @@ export const cleanupElement = function (element) {
* @param {Float} value
* @returns {Integer}
*/
export const snapToGrid = function (value) {
export const snapToGrid = (value) => {
const unit = svgCanvas.getBaseUnit()
let stepSize = svgCanvas.getSnappingStep()
if (unit !== 'px') {
@ -1135,8 +1135,8 @@ export const snapToGrid = function (value) {
* @param {Element} img - The DOM element to prevent the click on
* @returns {void}
*/
export const preventClickDefault = function (img) {
img.addEventListener('click', function (e) {
export const preventClickDefault = (img) => {
img.addEventListener('click', (e) => {
e.preventDefault()
})
}
@ -1178,9 +1178,8 @@ export const stringToHTML = (str) => {
return doc.body.firstChild
}
export const insertChildAtIndex = function (parent, child, index) {
export const insertChildAtIndex = (parent, child, index = 0) => {
const doc = stringToHTML(child)
if (!index) index = 0
if (index >= parent.children.length) {
parent.appendChild(doc)
} else {