- Linting: max-len, exponentiation operator

This commit is contained in:
Brett Zamir
2020-07-27 11:55:15 +08:00
parent ec32f5bc68
commit be5d353bc4
16 changed files with 188 additions and 57 deletions

View File

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

View File

@@ -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"');

View File

@@ -30,7 +30,12 @@ function handleSvgData (data, error) {
* @returns {void}
*/
function loadSvg () {
const svgexample = '<svg width="640" height="480" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><g><title>Layer 1</title><rect stroke-width="5" stroke="#000000" fill="#FF0000" id="svg_1" height="35" width="51" y="35" x="32"/><ellipse ry="15" rx="24" stroke-width="5" stroke="#000000" fill="#0000ff" id="svg_2" cy="60" cx="66"/></g></svg>';
const svgexample = '<svg width="640" height="480" xmlns:xlink="' +
'http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">' +
'<g><title>Layer 1</title><rect stroke-width="5" stroke="#000000" ' +
'fill="#FF0000" id="svg_1" height="35" width="51" y="35" x="32"/>' +
'<ellipse ry="15" rx="24" stroke-width="5" stroke="#000000" ' +
'fill="#0000ff" id="svg_2" cy="60" cx="66"/></g></svg>';
svgCanvas.setSvgString(svgexample);
}

View File

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

View File

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

View File

@@ -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 {
'<legend id="mathjax_legend">Mathematics Editor</legend>' +
'<label>' +
'<span id="mathjax_explication">Please type your mathematics in ' +
'<a href="https://en.wikipedia.org/wiki/Help:Displaying_a_formula" target="_blank">TeX</a> code.</span></label>' +
'<a href="https://en.wikipedia.org/wiki/Help:' +
'Displaying_a_formula" target="_blank">TeX</a> code.' +
'</span></label>' +
'<textarea id="mathjax_code_textarea" spellcheck="false"></textarea>' +
'</fieldset>' +
'</div>' +

View File

@@ -22,13 +22,21 @@ export default {
// Define and insert the base html element.
const propsWindowHtml =
'<div id="overview_window_content_pane" style="width:100%; word-wrap:break-word; display:inline-block; margin-top:20px;">' +
'<div id="overview_window_content" style="position:relative; left:12px; top:0px;">' +
'<div style="background-color:#A0A0A0; display:inline-block; overflow:visible;">' +
'<svg id="overviewMiniView" width="150" height="100" x="0" y="0" viewBox="0 0 4800 3600" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">' +
'<div id="overview_window_content_pane" style="width:100%; ' +
'word-wrap:break-word; display:inline-block; margin-top:20px;">' +
'<div id="overview_window_content" style="position:relative; ' +
'left:12px; top:0px;">' +
'<div style="background-color:#A0A0A0; display:inline-block; ' +
'overflow:visible;">' +
'<svg id="overviewMiniView" width="150" height="100" x="0" ' +
'y="0" viewBox="0 0 4800 3600" ' +
'xmlns="http://www.w3.org/2000/svg" ' +
'xmlns:xlink="http://www.w3.org/1999/xlink">' +
'<use x="0" y="0" xlink:href="#svgroot"> </use>' +
'</svg>' +
'<div id="overview_window_view_box" style="min-width:50px; min-height:50px; position:absolute; top:30px; left:30px; z-index:5; background-color:rgba(255,0,102,0.3);">' +
'<div id="overview_window_view_box" style="min-width:50px; ' +
'min-height:50px; position:absolute; top:30px; left:30px; ' +
'z-index:5; background-color:rgba(255,0,102,0.3);">' +
'</div>' +
'</div>' +
'</div>' +

View File

@@ -170,7 +170,11 @@ export default {
// TODO: Needs to be done after orig icon loads
setTimeout(function () {
// Create source save/cancel buttons
/* const save = */ $('#tool_source_save').clone().hide().attr('id', 'polygon_save').unbind().appendTo('#tool_source_back').click(function () {
/* const save = */ $('#tool_source_save').clone().hide().attr(
'id', 'polygon_save'
).unbind().appendTo(
'#tool_source_back'
).click(function () {
if (!editingitex) {
return;
}
@@ -188,7 +192,9 @@ export default {
// setSelectMode();
});
/* const cancel = */ $('#tool_source_cancel').clone().hide().attr('id', 'polygon_cancel').unbind().appendTo('#tool_source_back').click(function () {
/* const cancel = */ $('#tool_source_cancel').clone().hide().attr(
'id', 'polygon_cancel'
).unbind().appendTo('#tool_source_back').click(function () {
endChanges();
});
}, 3000);

View File

@@ -664,7 +664,9 @@ export default function jQueryPluginJGraduate ($) {
}
if (opac === null) opac = 1;
const pickerD = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
const pickerD = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,' +
'3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,' +
'2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
const pathbg = mkElem('path', {
d: pickerD,
@@ -802,7 +804,11 @@ export default function jQueryPluginJGraduate ($) {
} else {
const x = -cX * (scaleX - 1);
const y = -cY * (scaleY - 1);
curGradient.setAttribute('gradientTransform', rot + 'translate(' + x + ',' + y + ') scale(' + scaleX + ',' + scaleY + ')');
curGradient.setAttribute(
'gradientTransform',
rot + 'translate(' + x + ',' + y + ') scale(' +
scaleX + ',' + scaleY + ')'
);
// $('#ang').removeClass('dis');
}
}

View File

@@ -266,7 +266,10 @@ const svgElementToPdf = function (element, pdf, options) {
pdf.setLineWidth(k * Number.parseInt(node.getAttribute('stroke-width')));
}
const strokeColor = node.getAttribute('stroke');
if (attributeIsNotEmpty(strokeColor) && node.getAttribute('stroke-width') !== '0' && node.getAttribute('stroke-opacity') !== '0') {
if (attributeIsNotEmpty(strokeColor) &&
node.getAttribute('stroke-width') !== '0' &&
node.getAttribute('stroke-opacity') !== '0'
) {
const strokeRGB = new RGBColor(strokeColor);
if (strokeRGB.ok) {
// hasStrokeColor = true;

View File

@@ -476,7 +476,11 @@ editor.loadContentAndPrefs = function () {
} else if (window.widget) {
defaultPrefs[key] = window.widget.preferenceForKey(storeKey);
} else {
const result = document.cookie.match(new RegExp('(?:^|;\\s*)' + Utils.regexEscape(encodeURIComponent(storeKey)) + '=([^;]+)'));
const result = document.cookie.match(
new RegExp('(?:^|;\\s*)' + Utils.regexEscape(
encodeURIComponent(storeKey)
) + '=([^;]+)')
);
defaultPrefs[key] = result ? decodeURIComponent(result[1]) : '';
}
});
@@ -3602,7 +3606,10 @@ editor.init = function () {
str = '';
$.each(colorBlocks, function (i, e) {
if (e === 'chessboard') {
str += '<div class="color_block" data-bgcolor="' + e + '" style="background-image:url(data:image/gif;base64,R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+gq4jM3IFLJgpswNly/XkcBpIiVaInlLJr9FZWAQA7);"></div>';
str += '<div class="color_block" data-bgcolor="' + e +
'" style="background-image:url(data:image/gif;base64,' +
'R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+' +
'gq4jM3IFLJgpswNly/XkcBpIiVaInlLJr9FZWAQA7);"></div>';
} else {
str += '<div class="color_block" data-bgcolor="' + e + '" style="background-color:' + e + ';"></div>';
}

View File

@@ -294,7 +294,9 @@ export default function jQueryPluginSVGIcons ($) {
elems = $(svgdoc.firstChild).children(); // .getElementsByTagName('foreignContent');
if (!opts.no_img) {
const testSrc = dataPre + 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
const testSrc = dataPre +
'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zd' +
'mciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
testImg = $(new Image()).attr({
src: testSrc,