- Linting: max-len, exponentiation operator

master
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

@ -502,10 +502,10 @@ export const getPathBBox = function (path) {
const getCalc = function (j, P1, P2, P3) { const getCalc = function (j, P1, P2, P3) {
return function (t) { return function (t) {
return 1 - Math.pow(t, 3) * P0[j] + return 1 - t ** 3 * P0[j] +
3 * 1 - Math.pow(t, 2) * t * P1[j] + 3 * 1 - t ** 2 * t * P1[j] +
3 * (1 - t) * Math.pow(t, 2) * P2[j] + 3 * (1 - t) * t ** 2 * P2[j] +
Math.pow(t, 3) * P3[j]; t ** 3 * P3[j];
}; };
}; };
@ -538,7 +538,7 @@ export const getPathBBox = function (path) {
} }
continue; continue;
} }
const b2ac = Math.pow(b, 2) - 4 * c * a; const b2ac = b ** 2 - 4 * c * a;
if (b2ac < 0) { continue; } if (b2ac < 0) { continue; }
const t1 = (-b + Math.sqrt(b2ac)) / (2 * a); const t1 = (-b + Math.sqrt(b2ac)) / (2 * a);
if (t1 > 0 && t1 < 1) { bounds[j].push(calc(t1)); } 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} * @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. * @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'); const batchCmd = new hstry.BatchCommand('Convert element to Path');
// Any attribute on the element not covered by the passed-in attributes // Any attribute on the element not covered by the passed-in attributes

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) => { this.transforms = data.map((d) => {
const type = svg.trim(d.split('(')[0]); const type = svg.trim(d.split('(')[0]);
const s = d.split('(')[1].replace(')', ''); const s = d.split('(')[1].replace(')', '');
@ -688,10 +690,25 @@ function build (opts) {
ctx.translate(-scaleMin * refX.toPixels('x'), -scaleMin * refY.toPixels('y')); ctx.translate(-scaleMin * refX.toPixels('x'), -scaleMin * refY.toPixels('y'));
} else { } else {
// align // align
if (align.startsWith('xMid') && ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) ctx.translate(width / 2.0 - desiredWidth / 2.0, 0); if (align.startsWith('xMid') &&
if (align.endsWith('YMid') && ((meetOrSlice === 'meet' && scaleMin === scaleX) || (meetOrSlice === 'slice' && scaleMax === scaleX))) ctx.translate(0, height / 2.0 - desiredHeight / 2.0); ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) {
if (align.startsWith('xMax') && ((meetOrSlice === 'meet' && scaleMin === scaleY) || (meetOrSlice === 'slice' && scaleMax === scaleY))) ctx.translate(width - desiredWidth, 0); ctx.translate(width / 2.0 - desiredWidth / 2.0, 0);
if (align.endsWith('YMax') && ((meetOrSlice === 'meet' && scaleMin === scaleX) || (meetOrSlice === 'slice' && scaleMax === scaleX))) ctx.translate(0, height - desiredHeight); }
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 // scale
@ -1634,19 +1651,37 @@ function build (opts) {
// render me using a temporary svg element // render me using a temporary svg element
const tempSvg = new svg.Element.svg(); const tempSvg = new svg.Element.svg();
tempSvg.attributes.viewBox = new svg.Property('viewBox', this.attribute('viewBox').value); tempSvg.attributes.viewBox = new svg.Property(
tempSvg.attributes.refX = new svg.Property('refX', this.attribute('refX').value); 'viewBox', this.attribute('viewBox').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.refX = new svg.Property(
tempSvg.attributes.height = new svg.Property('height', this.attribute('markerHeight').value); 'refX', this.attribute('refX').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.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.children = this.children;
tempSvg.render(ctx); tempSvg.render(ctx);
ctx.restore(); ctx.restore();
if (this.attribute('markerUnits').valueOrDefault('strokeWidth') === 'strokeWidth') ctx.scale(1 / ctx.lineWidth, 1 / ctx.lineWidth); if (this.attribute('markerUnits').valueOrDefault('strokeWidth') ===
if (this.attribute('orient').valueOrDefault('auto') === 'auto') ctx.rotate(-angle); '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); ctx.translate(-point.x, -point.y);
} }
}; };
@ -2246,8 +2281,17 @@ function build (opts) {
if (this.hasText) { if (this.hasText) {
// render as text element // render as text element
super.renderChildren(ctx); super.renderChildren(ctx);
const fontSize = new svg.Property('fontSize', svg.Font.Parse(svg.ctx.font).fontSize); const fontSize = new svg.Property(
svg.Mouse.checkBoundingBox(this, new svg.BoundingBox(this.x, this.y - fontSize.toPixels('y'), this.x + this.measureText(ctx), this.y)); '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 { } else {
// render as temporary group // render as temporary group
const g = new svg.Element.g(); const g = new svg.Element.g();
@ -2445,18 +2489,33 @@ function build (opts) {
if (!isNullish(element)) { if (!isNullish(element)) {
let tempSvg = element; let tempSvg = element;
if (element.type === 'symbol') { 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 = new svg.Element.svg();
tempSvg.type = 'svg'; tempSvg.type = 'svg';
tempSvg.attributes.viewBox = new svg.Property('viewBox', element.attribute('viewBox').value); tempSvg.attributes.viewBox = new svg.Property(
tempSvg.attributes.preserveAspectRatio = new svg.Property('preserveAspectRatio', element.attribute('preserveAspectRatio').value); 'viewBox', element.attribute('viewBox').value
tempSvg.attributes.overflow = new svg.Property('overflow', element.attribute('overflow').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; tempSvg.children = element.children;
} }
if (tempSvg.type === 'svg') { if (tempSvg.type === 'svg') {
// if symbol or svg, inherit width/height from me // 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('width').hasValue()) {
if (this.attribute('height').hasValue()) tempSvg.attributes.height = new svg.Property('height', this.attribute('height').value); 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; const oldParent = tempSvg.parent;
tempSvg.parent = null; tempSvg.parent = null;
@ -2907,7 +2966,8 @@ function build (opts) {
} }
}, 1000 / svg.FRAMERATE); }, 1000 / svg.FRAMERATE);
// Todo: Replace with an image loading Promise utility? // 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()) { if (svg.ImagesLoaded()) {
waitingForImages = false; waitingForImages = false;
draw(resolve); draw(resolve);

View File

@ -44,7 +44,10 @@ const menuItemIsValid = function (menuItem) {
export const add = function (menuItem) { export const add = function (menuItem) {
// menuItem: {id, label, shortcut, action} // menuItem: {id, label, shortcut, action}
if (!menuItemIsValid(menuItem)) { 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) { if (menuItem.id in contextMenuExtensions) {
throw new Error('Cannot add extension "' + menuItem.id + '", an extension by that name already exists"'); 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} * @returns {void}
*/ */
function loadSvg () { 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); svgCanvas.setSvgString(svgexample);
} }

View File

@ -71,7 +71,11 @@ function messageListener (e) {
e.source !== this.frame.contentWindow || e.source !== this.frame.contentWindow ||
(!allowedOrigins.includes('*') && !allowedOrigins.includes(e.origin)) (!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; return;
} }
addCallback(this, data); addCallback(this, data);

View File

@ -53,8 +53,11 @@ export default {
rightarrow: rightarrow:
{element: 'path', attr: {d: 'M100,50 L0,90 L30,50 L0,10 Z'}}, {element: 'path', attr: {d: 'M100,50 L0,90 L30,50 L0,10 Z'}},
textmarker: textmarker:
{element: 'text', attr: {x: 0, y: 0, 'stroke-width': 0, stroke: 'none', 'font-size': 75, 'font-family': 'serif', 'text-anchor': 'left', {element: 'text', attr: {
'xml:space': 'preserve'}}, x: 0, y: 0, 'stroke-width': 0, stroke: 'none',
'font-size': 75, 'font-family': 'serif', 'text-anchor': 'left',
'xml:space': 'preserve'
}},
forwardslash: forwardslash:
{element: 'path', attr: {d: 'M30,100 L70,0'}}, {element: 'path', attr: {d: 'M30,100 L70,0'}},
reverseslash: reverseslash:

View File

@ -59,7 +59,9 @@ export default {
mathjax: { mathjax: {
embed_svg: 'Save as mathematics', embed_svg: 'Save as mathematics',
embed_mathml: 'Save as figure', 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.', mathml_save_warning: 'Advised. The math will be saved as a figure.',
title: 'Mathematics code editor' title: 'Mathematics code editor'
} }
@ -149,7 +151,9 @@ export default {
'<legend id="mathjax_legend">Mathematics Editor</legend>' + '<legend id="mathjax_legend">Mathematics Editor</legend>' +
'<label>' + '<label>' +
'<span id="mathjax_explication">Please type your mathematics in ' + '<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>' + '<textarea id="mathjax_code_textarea" spellcheck="false"></textarea>' +
'</fieldset>' + '</fieldset>' +
'</div>' + '</div>' +

View File

@ -22,13 +22,21 @@ export default {
// Define and insert the base html element. // Define and insert the base html element.
const propsWindowHtml = 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_pane" style="width:100%; ' +
'<div id="overview_window_content" style="position:relative; left:12px; top:0px;">' + 'word-wrap:break-word; display:inline-block; margin-top:20px;">' +
'<div style="background-color:#A0A0A0; display:inline-block; overflow:visible;">' + '<div id="overview_window_content" style="position:relative; ' +
'<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">' + '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>' + '<use x="0" y="0" xlink:href="#svgroot"> </use>' +
'</svg>' + '</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>' + '</div>' +
'</div>' + '</div>' +

View File

@ -170,7 +170,11 @@ export default {
// TODO: Needs to be done after orig icon loads // TODO: Needs to be done after orig icon loads
setTimeout(function () { setTimeout(function () {
// Create source save/cancel buttons // 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) { if (!editingitex) {
return; return;
} }
@ -188,7 +192,9 @@ export default {
// setSelectMode(); // 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(); endChanges();
}); });
}, 3000); }, 3000);

View File

@ -664,7 +664,9 @@ export default function jQueryPluginJGraduate ($) {
} }
if (opac === null) opac = 1; 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', { const pathbg = mkElem('path', {
d: pickerD, d: pickerD,
@ -802,7 +804,11 @@ export default function jQueryPluginJGraduate ($) {
} else { } else {
const x = -cX * (scaleX - 1); const x = -cX * (scaleX - 1);
const y = -cY * (scaleY - 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'); // $('#ang').removeClass('dis');
} }
} }

View File

@ -266,7 +266,10 @@ const svgElementToPdf = function (element, pdf, options) {
pdf.setLineWidth(k * Number.parseInt(node.getAttribute('stroke-width'))); pdf.setLineWidth(k * Number.parseInt(node.getAttribute('stroke-width')));
} }
const strokeColor = node.getAttribute('stroke'); 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); const strokeRGB = new RGBColor(strokeColor);
if (strokeRGB.ok) { if (strokeRGB.ok) {
// hasStrokeColor = true; // hasStrokeColor = true;

View File

@ -476,7 +476,11 @@ editor.loadContentAndPrefs = function () {
} else if (window.widget) { } else if (window.widget) {
defaultPrefs[key] = window.widget.preferenceForKey(storeKey); defaultPrefs[key] = window.widget.preferenceForKey(storeKey);
} else { } 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]) : ''; defaultPrefs[key] = result ? decodeURIComponent(result[1]) : '';
} }
}); });
@ -3602,7 +3606,10 @@ editor.init = function () {
str = ''; str = '';
$.each(colorBlocks, function (i, e) { $.each(colorBlocks, function (i, e) {
if (e === 'chessboard') { 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 { } else {
str += '<div class="color_block" data-bgcolor="' + e + '" style="background-color:' + e + ';"></div>'; 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'); elems = $(svgdoc.firstChild).children(); // .getElementsByTagName('foreignContent');
if (!opts.no_img) { if (!opts.no_img) {
const testSrc = dataPre + 'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D'; const testSrc = dataPre +
'PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zd' +
'mciIHdpZHRoPSIyNzUiIGhlaWdodD0iMjc1Ij48L3N2Zz4%3D';
testImg = $(new Image()).attr({ testImg = $(new Image()).attr({
src: testSrc, src: testSrc,

View File

@ -161,7 +161,11 @@ export function importModule (url, atts = {}, {returnDefault = false} = {}) {
script.addEventListener('error', scriptOnError); script.addEventListener('error', scriptOnError);
script.addEventListener('load', scriptOnLoad); script.addEventListener('load', scriptOnLoad);
const absURL = toAbsoluteURL(url); const absURL = toAbsoluteURL(url);
const loader = `import * as m from '${absURL.replace(/'/g, "\\'")}'; window.${vector} = ${returnDefault ? 'm.default || ' : ''}m;`; // export Module const loader = `import * as m from '${
absURL.replace(/'/g, "\\'")
}'; window.${vector} = ${
returnDefault ? 'm.default || ' : ''
}m;`; // export Module
const blob = new Blob([loader], {type: 'text/javascript'}); const blob = new Blob([loader], {type: 'text/javascript'});
script.src = URL.createObjectURL(blob); script.src = URL.createObjectURL(blob);

View File

@ -151,7 +151,9 @@ export const sanitizeSvg = function (node) {
const attrNsURI = attr.namespaceURI; const attrNsURI = attr.namespaceURI;
// Check that an attribute with the correct localName in the correct namespace is on // Check that an attribute with the correct localName in the correct namespace is on
// our whitelist or is a namespace declaration for one of our allowed namespaces // our whitelist or is a namespace declaration for one of our allowed namespaces
if (!({}.hasOwnProperty.call(allowedAttrsNS, attrLocalName) && attrNsURI === allowedAttrsNS[attrLocalName] && attrNsURI !== NS.XMLNS) && if (!({}.hasOwnProperty.call(allowedAttrsNS, attrLocalName) &&
attrNsURI === allowedAttrsNS[attrLocalName] && attrNsURI !== NS.XMLNS
) &&
!(attrNsURI === NS.XMLNS && REVERSE_NS[attr.value])) { !(attrNsURI === NS.XMLNS && REVERSE_NS[attr.value])) {
// TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist. // TODO(codedread): Programmatically add the se: attributes to the NS-aware whitelist.
// Bypassing the whitelist to allow se: prefixes. // Bypassing the whitelist to allow se: prefixes.

View File

@ -156,7 +156,8 @@ const svgdoc = container.ownerDocument;
const svgroot = svgdoc.importNode( const svgroot = svgdoc.importNode(
text2xml( text2xml(
'<svg id="svgroot" xmlns="' + NS.SVG + '" xlinkns="' + NS.XLINK + '" ' + '<svg id="svgroot" xmlns="' + NS.SVG + '" xlinkns="' + NS.XLINK + '" ' +
'width="' + dimensions[0] + '" height="' + dimensions[1] + '" x="' + dimensions[0] + '" y="' + dimensions[1] + '" overflow="visible">' + 'width="' + dimensions[0] + '" height="' + dimensions[1] +
'" x="' + dimensions[0] + '" y="' + dimensions[1] + '" overflow="visible">' +
'<defs>' + '<defs>' +
'<filter id="canvashadow" filterUnits="objectBoundingBox">' + '<filter id="canvashadow" filterUnits="objectBoundingBox">' +
'<feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>' + '<feGaussianBlur in="SourceAlpha" stdDeviation="4" result="blur"/>' +
@ -2433,7 +2434,9 @@ const mouseMove = function (evt) {
bSpline = getBsplinePoint(nextParameter); bSpline = getBsplinePoint(nextParameter);
nextPos = bSpline; nextPos = bSpline;
bSpline = getBsplinePoint(parameter); bSpline = getBsplinePoint(parameter);
sumDistance += Math.sqrt((nextPos.x - bSpline.x) * (nextPos.x - bSpline.x) + (nextPos.y - bSpline.y) * (nextPos.y - bSpline.y)); sumDistance += Math.sqrt((nextPos.x - bSpline.x) *
(nextPos.x - bSpline.x) + (nextPos.y - bSpline.y) *
(nextPos.y - bSpline.y));
if (sumDistance > THRESHOLD_DIST) { if (sumDistance > THRESHOLD_DIST) {
sumDistance -= THRESHOLD_DIST; sumDistance -= THRESHOLD_DIST;
@ -3841,7 +3844,8 @@ this.svgToString = function (elem, indent) {
*/ */
this.embedImage = function (src) { this.embedImage = function (src) {
// Todo: Remove this Promise in favor of making an async/await `Image.load` utility // Todo: Remove this Promise in favor of making an async/await `Image.load` utility
return new Promise(function (resolve, reject) { // eslint-disable-line promise/avoid-new // eslint-disable-next-line promise/avoid-new
return new Promise(function (resolve, reject) {
// load in the image and once it's loaded, get the dimensions // load in the image and once it's loaded, get the dimensions
$(new Image()).load(function (response, status, xhr) { $(new Image()).load(function (response, status, xhr) {
if (status === 'error') { if (status === 'error') {
@ -3999,7 +4003,8 @@ this.rasterExport = async function (imgType, quality, exportWindowName, opts = {
await canvg(c, svg); await canvg(c, svg);
// Todo: Make async/await utility in place of `toBlob`, so we can remove this constructor // Todo: Make async/await utility in place of `toBlob`, so we can remove this constructor
return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new // eslint-disable-next-line promise/avoid-new
return new Promise((resolve, reject) => {
const dataURLType = type.toLowerCase(); const dataURLType = type.toLowerCase();
const datauri = quality const datauri = quality
? c.toDataURL('image/' + dataURLType, quality) ? c.toDataURL('image/' + dataURLType, quality)
@ -6148,7 +6153,10 @@ this.convertToPath = function (elem, getBBox) {
opacity: curShape.opacity, opacity: curShape.opacity,
visibility: 'hidden' visibility: 'hidden'
}; };
return convertToPath(elem, attrs, addSVGElementFromJson, pathActions, clearSelection, addToSelection, hstry, addCommandToHistory); return convertToPath(
elem, attrs, addSVGElementFromJson, pathActions,
clearSelection, addToSelection, hstry, addCommandToHistory
);
}; };
/** /**
@ -7263,7 +7271,10 @@ this.setBackground = function (color, url) {
}); });
const div = document.createElement('div'); const div = document.createElement('div');
assignAttributes(div, { assignAttributes(div, {
style: 'pointer-events:none;width:100%;height:100%;background-image:url(data:image/gif;base64,R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+gq4jM3IFLJgpswNly/XkcBpIiVaInlLJr9FZWAQA7);' style: 'pointer-events:none;width:100%;height:100%;' +
'background-image:url(data:image/gif;base64,' +
'R0lGODlhEAAQAIAAAP///9bW1iH5BAAAAAAALAAAAAAQABAAAAIfjG+' +
'gq4jM3IFLJgpswNly/XkcBpIiVaInlLJr9FZWAQA7);'
}); });
bgPattern.appendChild(div); bgPattern.appendChild(div);
bg.append(bgPattern); bg.append(bgPattern);