Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jfhenon committed Aug 25, 2023
1 parent de5b3c1 commit f15d740
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/unit/test1.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-len, no-console */
import SvgCanvas from '../../../packages/svgcanvas/svgcanvas.js'
import SvgCanvas from '../../../packages/svgcanvas'

describe('Basic Module', function () {
// helper functions
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/unit/units.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as units from '.../../../packages/svgcanvas/core/units.js'
import * as units from '../../../packages/svgcanvas/core/units.js'

describe('units', function () {
/**
Expand Down
64 changes: 27 additions & 37 deletions packages/svgcanvas/core/svg-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* @copyright 2011 Jeff Schiller
*/

import { jsPDF as JsPDF } from 'jspdf/dist/jspdf.es.min.js'
import 'svg2pdf.js/dist/svg2pdf.es.js'
import { jsPDF as JsPDF } from 'jspdf'
import 'svg2pdf.js'
import html2canvas from 'html2canvas'
import * as hstry from './history.js'
import {
Expand All @@ -23,7 +23,11 @@ import {
getBBox as utilsGetBBox,
hashCode
} from './utilities.js'
import { transformPoint, transformListToTransform, getTransformList } from './math.js'
import {
transformPoint,
transformListToTransform,
getTransformList
} from './math.js'
import { convertUnit, shortFloat, convertToNum } from './units.js'
import { isGecko, isChrome, isWebkit } from '../common/browser.js'
import * as pathModule from './path.js'
Expand Down Expand Up @@ -90,7 +94,7 @@ const svgCanvasToString = () => {

// Unwrap gsvg if it has no special attributes (only id and style)
const gsvgElems = svgCanvas.getSvgContent().querySelectorAll('g[data-gsvg]')
Array.prototype.forEach.call(gsvgElems, (element) => {
Array.prototype.forEach.call(gsvgElems, element => {
const attrs = element.attributes
let len = attrs.length
for (let i = 0; i < len; i++) {
Expand All @@ -109,7 +113,7 @@ const svgCanvasToString = () => {

// Rewrap gsvg
if (nakedSvgs.length) {
Array.prototype.forEach.call(nakedSvgs, (el) => {
Array.prototype.forEach.call(nakedSvgs, el => {
svgCanvas.groupSvgElem(el)
})
}
Expand Down Expand Up @@ -162,26 +166,14 @@ const svgToString = (elem, indent) => {
// }
if (curConfig.dynamicOutput) {
vb = elem.getAttribute('viewBox')
out.push(
' viewBox="' +
vb +
'" xmlns="' +
NS.SVG +
'"'
)
out.push(' viewBox="' + vb + '" xmlns="' + NS.SVG + '"')
} else {
if (unit !== 'px') {
res.w = convertUnit(res.w, unit) + unit
res.h = convertUnit(res.h, unit) + unit
}
out.push(
' width="' +
res.w +
'" height="' +
res.h +
'" xmlns="' +
NS.SVG +
'"'
' width="' + res.w + '" height="' + res.h + '" xmlns="' + NS.SVG + '"'
)
}

Expand All @@ -191,7 +183,7 @@ const svgToString = (elem, indent) => {
const csElements = elem.querySelectorAll('*')
const cElements = Array.prototype.slice.call(csElements)
cElements.push(elem)
Array.prototype.forEach.call(cElements, (el) => {
Array.prototype.forEach.call(cElements, el => {
// const el = this;
// for some elements have no attribute
const uri = el.namespaceURI
Expand Down Expand Up @@ -441,7 +433,7 @@ const setSvgString = (xmlString, preventUndo) => {

// change image href vals if possible
const elements = content.querySelectorAll('image')
Array.prototype.forEach.call(elements, (image) => {
Array.prototype.forEach.call(elements, image => {
preventClickDefault(image)
const val = svgCanvas.getHref(image)
if (val) {
Expand Down Expand Up @@ -487,7 +479,7 @@ const setSvgString = (xmlString, preventUndo) => {

// Wrap child SVGs in group elements
const svgElements = content.querySelectorAll('svg')
Array.prototype.forEach.call(svgElements, (element) => {
Array.prototype.forEach.call(svgElements, element => {
// Skip if it's in a <defs>
if (getClosest(element.parentNode, 'defs')) {
return
Expand All @@ -511,7 +503,7 @@ const setSvgString = (xmlString, preventUndo) => {
const findElems = content.querySelectorAll(
'linearGradient, radialGradient, pattern'
)
Array.prototype.forEach.call(findElems, (ele) => {
Array.prototype.forEach.call(findElems, ele => {
svgDefs.appendChild(ele)
})
}
Expand All @@ -538,7 +530,7 @@ const setSvgString = (xmlString, preventUndo) => {
attrs.height = vb[3]
// handle content that doesn't have a viewBox
} else {
;['width', 'height'].forEach((dim) => {
;['width', 'height'].forEach(dim => {
// Set to 100 if not given
const val = content.getAttribute(dim) || '100%'
if (String(val).substr(-1) === '%') {
Expand All @@ -555,9 +547,9 @@ const setSvgString = (xmlString, preventUndo) => {

// Give ID for any visible layer children missing one
const chiElems = content.children
Array.prototype.forEach.call(chiElems, (chiElem) => {
Array.prototype.forEach.call(chiElems, chiElem => {
const visElems = chiElem.querySelectorAll(svgCanvas.getVisElems())
Array.prototype.forEach.call(visElems, (elem) => {
Array.prototype.forEach.call(visElems, elem => {
if (!elem.id) {
elem.id = svgCanvas.getNextId()
}
Expand Down Expand Up @@ -696,7 +688,7 @@ const importSvgString = (xmlString, preserveDimension) => {
const elements = svg.querySelectorAll(
'linearGradient, radialGradient, pattern'
)
Array.prototype.forEach.call(elements, (el) => {
Array.prototype.forEach.call(elements, el => {
defs.appendChild(el)
})
}
Expand Down Expand Up @@ -766,7 +758,7 @@ const importSvgString = (xmlString, preserveDimension) => {
* @param {string} src - The path/URL of the image
* @returns {Promise<string|false>} Resolves to a Data URL (string|false)
*/
const embedImage = (src) => {
const embedImage = src => {
// Todo: Remove this Promise in favor of making an async/await `Image.load` utility
return new Promise((resolve, reject) => {
// load in the image and once it's loaded, get the dimensions
Expand Down Expand Up @@ -1011,7 +1003,7 @@ const exportPDF = async (
* @param {Element} g - The parent element of the tree to give unique IDs
* @returns {void}
*/
const uniquifyElemsMethod = (g) => {
const uniquifyElemsMethod = g => {
const ids = {}
// TODO: Handle markers and connectors. These are not yet re-identified properly
// as their referring elements do not get remapped.
Expand All @@ -1031,7 +1023,7 @@ const uniquifyElemsMethod = (g) => {
'use'
]

walkTree(g, (n) => {
walkTree(g, n => {
// if it's an element node
if (n.nodeType === 1) {
// and the element has an ID
Expand All @@ -1046,7 +1038,7 @@ const uniquifyElemsMethod = (g) => {

// now search for all attributes on this element that might refer
// to other elements
svgCanvas.getrefAttrs().forEach((attr) => {
svgCanvas.getrefAttrs().forEach(attr => {
const attrnode = n.getAttributeNode(attr)
if (attrnode) {
// the incoming file has been sanitized, so we should be able to safely just strip off the leading #
Expand Down Expand Up @@ -1115,7 +1107,7 @@ const uniquifyElemsMethod = (g) => {
* @param {Element} parent
* @returns {void}
*/
const setUseDataMethod = (parent) => {
const setUseDataMethod = parent => {
let elems = parent

if (parent.tagName !== 'use') {
Expand Down Expand Up @@ -1210,17 +1202,15 @@ const removeUnusedDefElemsMethod = () => {
* @param {Element} elem
* @returns {void}
*/
const convertGradientsMethod = (elem) => {
const convertGradientsMethod = elem => {
let elems = elem.querySelectorAll('linearGradient, radialGradient')
if (!elems.length && isWebkit()) {
// Bug in webkit prevents regular *Gradient selector search
elems = Array.prototype.filter.call(elem.querySelectorAll('*'), (
curThis
) => {
elems = Array.prototype.filter.call(elem.querySelectorAll('*'), curThis => {
return curThis.tagName.includes('Gradient')
})
}
Array.prototype.forEach.call(elems, (grad) => {
Array.prototype.forEach.call(elems, grad => {
if (grad.getAttribute('gradientUnits') === 'userSpaceOnUse') {
const svgContent = svgCanvas.getSvgContent()
// TODO: Support more than one element with this ref by duplicating parent grad
Expand Down

0 comments on commit f15d740

Please sign in to comment.