diff --git a/src/common/utilities.js b/src/common/utilities.js index 3ce7b625..e30cf483 100644 --- a/src/common/utilities.js +++ b/src/common/utilities.js @@ -502,10 +502,10 @@ export const getPathBBox = function (path) { const getCalc = function (j, P1, P2, P3) { return function (t) { - return 1 - Math.pow(t, 3) * P0[j] + - 3 * 1 - Math.pow(t, 2) * t * P1[j] + - 3 * (1 - t) * Math.pow(t, 2) * P2[j] + - Math.pow(t, 3) * P3[j]; + return 1 - t ** 3 * P0[j] + + 3 * 1 - t ** 2 * t * P1[j] + + 3 * (1 - t) * t ** 2 * P2[j] + + t ** 3 * P3[j]; }; }; @@ -538,7 +538,7 @@ export const getPathBBox = function (path) { } continue; } - const b2ac = Math.pow(b, 2) - 4 * c * a; + const b2ac = b ** 2 - 4 * c * a; if (b2ac < 0) { continue; } const t1 = (-b + Math.sqrt(b2ac)) / (2 * a); if (t1 > 0 && t1 < 1) { bounds[j].push(calc(t1)); } @@ -888,7 +888,10 @@ export const getBBoxOfElementAsPath = function (elem, addSVGElementFromJson, pat * @param {module:path.EditorContext#addCommandToHistory|module:draw.DrawCanvasInit#addCommandToHistory} addCommandToHistory - see [canvas.addCommandToHistory]{@link module:svgcanvas~addCommandToHistory} * @returns {SVGPathElement|null} The converted path element or null if the DOM element was not recognized. */ -export const convertToPath = function (elem, attrs, addSVGElementFromJson, pathActions, clearSelection, addToSelection, hstry, addCommandToHistory) { +export const convertToPath = function ( + elem, attrs, addSVGElementFromJson, pathActions, + clearSelection, addToSelection, hstry, addCommandToHistory +) { const batchCmd = new hstry.BatchCommand('Convert element to Path'); // Any attribute on the element not covered by the passed-in attributes diff --git a/src/editor/canvg/canvg.js b/src/editor/canvg/canvg.js index 461c22e6..b1117328 100644 --- a/src/editor/canvg/canvg.js +++ b/src/editor/canvg/canvg.js @@ -637,7 +637,9 @@ function build (opts) { } }); - const data = svg.trim(svg.compressSpaces(v)).replace(/\)([a-zA-Z])/g, ') $1').replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/); + const data = svg.trim(svg.compressSpaces(v)).replace( + /\)([a-zA-Z])/g, ') $1' + ).replace(/\)(\s?,\s?)/g, ') ').split(/\s(?=[a-z])/); this.transforms = data.map((d) => { const type = svg.trim(d.split('(')[0]); const s = d.split('(')[1].replace(')', ''); @@ -688,10 +690,25 @@ function build (opts) { ctx.translate(-scaleMin * refX.toPixels('x'), -scaleMin * refY.toPixels('y')); } else { // align - if (align.startsWith('xMid') && ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) ctx.translate(width / 2.0 - desiredWidth / 2.0, 0); - if (align.endsWith('YMid') && ((meetOrSlice === 'meet' && scaleMin === scaleX) || (meetOrSlice === 'slice' && scaleMax === scaleX))) ctx.translate(0, height / 2.0 - desiredHeight / 2.0); - if (align.startsWith('xMax') && ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) ctx.translate(width - desiredWidth, 0); - if (align.endsWith('YMax') && ((meetOrSlice === 'meet' && scaleMin === scaleX) || (meetOrSlice === 'slice' && scaleMax === scaleX))) ctx.translate(0, height - desiredHeight); + if (align.startsWith('xMid') && + ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) { + ctx.translate(width / 2.0 - desiredWidth / 2.0, 0); + } + if (align.endsWith('YMid') && + ((meetOrSlice === 'meet' && scaleMin === scaleX) || (meetOrSlice === 'slice' && scaleMax === scaleX))) { + ctx.translate(0, height / 2.0 - desiredHeight / 2.0); + } + if (align.startsWith('xMax') && + ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) { + ctx.translate(width - desiredWidth, 0); + } + if (align.endsWith('YMax') && + ((meetOrSlice === 'meet' && scaleMin === scaleX) || + (meetOrSlice === 'slice' && scaleMax === scaleX) + ) + ) { + ctx.translate(0, height - desiredHeight); + } } // scale @@ -1634,19 +1651,37 @@ function build (opts) { // render me using a temporary svg element const tempSvg = new svg.Element.svg(); - tempSvg.attributes.viewBox = new svg.Property('viewBox', this.attribute('viewBox').value); - tempSvg.attributes.refX = new svg.Property('refX', this.attribute('refX').value); - tempSvg.attributes.refY = new svg.Property('refY', this.attribute('refY').value); - tempSvg.attributes.width = new svg.Property('width', this.attribute('markerWidth').value); - tempSvg.attributes.height = new svg.Property('height', this.attribute('markerHeight').value); - tempSvg.attributes.fill = new svg.Property('fill', this.attribute('fill').valueOrDefault('black')); - tempSvg.attributes.stroke = new svg.Property('stroke', this.attribute('stroke').valueOrDefault('none')); + tempSvg.attributes.viewBox = new svg.Property( + 'viewBox', this.attribute('viewBox').value + ); + tempSvg.attributes.refX = new svg.Property( + 'refX', this.attribute('refX').value + ); + tempSvg.attributes.refY = new svg.Property( + 'refY', this.attribute('refY').value + ); + tempSvg.attributes.width = new svg.Property( + 'width', this.attribute('markerWidth').value + ); + tempSvg.attributes.height = new svg.Property( + 'height', this.attribute('markerHeight').value + ); + tempSvg.attributes.fill = new svg.Property( + 'fill', this.attribute('fill').valueOrDefault('black') + ); + tempSvg.attributes.stroke = new svg.Property( + 'stroke', this.attribute('stroke').valueOrDefault('none') + ); tempSvg.children = this.children; tempSvg.render(ctx); ctx.restore(); - if (this.attribute('markerUnits').valueOrDefault('strokeWidth') === 'strokeWidth') ctx.scale(1 / ctx.lineWidth, 1 / ctx.lineWidth); - if (this.attribute('orient').valueOrDefault('auto') === 'auto') ctx.rotate(-angle); + if (this.attribute('markerUnits').valueOrDefault('strokeWidth') === + 'strokeWidth' + ) ctx.scale(1 / ctx.lineWidth, 1 / ctx.lineWidth); + if (this.attribute('orient').valueOrDefault('auto') === 'auto') { + ctx.rotate(-angle); + } ctx.translate(-point.x, -point.y); } }; @@ -2246,8 +2281,17 @@ function build (opts) { if (this.hasText) { // render as text element super.renderChildren(ctx); - const fontSize = new svg.Property('fontSize', svg.Font.Parse(svg.ctx.font).fontSize); - svg.Mouse.checkBoundingBox(this, new svg.BoundingBox(this.x, this.y - fontSize.toPixels('y'), this.x + this.measureText(ctx), this.y)); + const fontSize = new svg.Property( + 'fontSize', svg.Font.Parse(svg.ctx.font).fontSize + ); + svg.Mouse.checkBoundingBox( + this, new svg.BoundingBox( + this.x, + this.y - fontSize.toPixels('y'), + this.x + this.measureText(ctx), + this.y + ) + ); } else { // render as temporary group const g = new svg.Element.g(); @@ -2445,18 +2489,33 @@ function build (opts) { if (!isNullish(element)) { let tempSvg = element; if (element.type === 'symbol') { - // render me using a temporary svg element in symbol cases (https://www.w3.org/TR/SVG/struct.html#UseElement) + // render me using a temporary svg element in symbol cases + // (https://www.w3.org/TR/SVG/struct.html#UseElement) tempSvg = new svg.Element.svg(); tempSvg.type = 'svg'; - tempSvg.attributes.viewBox = new svg.Property('viewBox', element.attribute('viewBox').value); - tempSvg.attributes.preserveAspectRatio = new svg.Property('preserveAspectRatio', element.attribute('preserveAspectRatio').value); - tempSvg.attributes.overflow = new svg.Property('overflow', element.attribute('overflow').value); + tempSvg.attributes.viewBox = new svg.Property( + 'viewBox', element.attribute('viewBox').value + ); + tempSvg.attributes.preserveAspectRatio = new svg.Property( + 'preserveAspectRatio', element.attribute('preserveAspectRatio').value + ); + tempSvg.attributes.overflow = new svg.Property( + 'overflow', element.attribute('overflow').value + ); tempSvg.children = element.children; } if (tempSvg.type === 'svg') { // if symbol or svg, inherit width/height from me - if (this.attribute('width').hasValue()) tempSvg.attributes.width = new svg.Property('width', this.attribute('width').value); - if (this.attribute('height').hasValue()) tempSvg.attributes.height = new svg.Property('height', this.attribute('height').value); + if (this.attribute('width').hasValue()) { + tempSvg.attributes.width = new svg.Property( + 'width', this.attribute('width').value + ); + } + if (this.attribute('height').hasValue()) { + tempSvg.attributes.height = new svg.Property( + 'height', this.attribute('height').value + ); + } } const oldParent = tempSvg.parent; tempSvg.parent = null; @@ -2907,7 +2966,8 @@ function build (opts) { } }, 1000 / svg.FRAMERATE); // Todo: Replace with an image loading Promise utility? - return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new + // eslint-disable-next-line promise/avoid-new + return new Promise((resolve, reject) => { if (svg.ImagesLoaded()) { waitingForImages = false; draw(resolve); diff --git a/src/editor/contextmenu.js b/src/editor/contextmenu.js index 4513c31a..2a51f8da 100644 --- a/src/editor/contextmenu.js +++ b/src/editor/contextmenu.js @@ -44,7 +44,10 @@ const menuItemIsValid = function (menuItem) { export const add = function (menuItem) { // menuItem: {id, label, shortcut, action} if (!menuItemIsValid(menuItem)) { - throw new TypeError('Menu items must be defined and have at least properties: id, label, action, where action must be a function'); + throw new TypeError( + 'Menu items must be defined and have at least properties: ' + + 'id, label, action, where action must be a function' + ); } if (menuItem.id in contextMenuExtensions) { throw new Error('Cannot add extension "' + menuItem.id + '", an extension by that name already exists"'); diff --git a/src/editor/embedapi-dom.js b/src/editor/embedapi-dom.js index 3eb72974..802e7331 100644 --- a/src/editor/embedapi-dom.js +++ b/src/editor/embedapi-dom.js @@ -30,7 +30,12 @@ function handleSvgData (data, error) { * @returns {void} */ function loadSvg () { - const svgexample = ''; + const svgexample = ''; svgCanvas.setSvgString(svgexample); } diff --git a/src/editor/embedapi.js b/src/editor/embedapi.js index c1b4bfe0..dd6459c4 100644 --- a/src/editor/embedapi.js +++ b/src/editor/embedapi.js @@ -71,7 +71,11 @@ function messageListener (e) { e.source !== this.frame.contentWindow || (!allowedOrigins.includes('*') && !allowedOrigins.includes(e.origin)) ) { - console.log(`The origin ${e.origin} was not whitelisted as an origin from which responses may be received by this ${window.origin} script.`); // eslint-disable-line no-console + // eslint-disable-next-line no-console -- Info for developers + console.error( + `The origin ${e.origin} was not whitelisted as an origin from ` + + `which responses may be received by this ${window.origin} script.` + ); return; } addCallback(this, data); diff --git a/src/editor/extensions/ext-markers.js b/src/editor/extensions/ext-markers.js index c521eff1..ec8628e7 100644 --- a/src/editor/extensions/ext-markers.js +++ b/src/editor/extensions/ext-markers.js @@ -53,8 +53,11 @@ export default { rightarrow: {element: 'path', attr: {d: 'M100,50 L0,90 L30,50 L0,10 Z'}}, textmarker: - {element: 'text', attr: {x: 0, y: 0, 'stroke-width': 0, stroke: 'none', 'font-size': 75, 'font-family': 'serif', 'text-anchor': 'left', - 'xml:space': 'preserve'}}, + {element: 'text', attr: { + x: 0, y: 0, 'stroke-width': 0, stroke: 'none', + 'font-size': 75, 'font-family': 'serif', 'text-anchor': 'left', + 'xml:space': 'preserve' + }}, forwardslash: {element: 'path', attr: {d: 'M30,100 L70,0'}}, reverseslash: diff --git a/src/editor/extensions/ext-mathjax.js b/src/editor/extensions/ext-mathjax.js index 9f649b9b..f64568de 100644 --- a/src/editor/extensions/ext-mathjax.js +++ b/src/editor/extensions/ext-mathjax.js @@ -59,7 +59,9 @@ export default { mathjax: { embed_svg: 'Save as mathematics', embed_mathml: 'Save as figure', - svg_save_warning: 'The math will be transformed into a figure is manipulatable like everything else. You will not be able to manipulate the TeX-code anymore. ', + svg_save_warning: 'The math will be transformed into a figure is ' + + 'manipulatable like everything else. You will not be able to ' + + 'manipulate the TeX-code anymore.', mathml_save_warning: 'Advised. The math will be saved as a figure.', title: 'Mathematics code editor' } @@ -149,7 +151,9 @@ export default { '' + '' + + 'TeX code.' + + '' + '' + '' + '' + diff --git a/src/editor/extensions/ext-overview_window.js b/src/editor/extensions/ext-overview_window.js index 8910c79d..c2518af1 100644 --- a/src/editor/extensions/ext-overview_window.js +++ b/src/editor/extensions/ext-overview_window.js @@ -22,13 +22,21 @@ export default { // Define and insert the base html element. const propsWindowHtml = - '