diff --git a/cypress/integration/ui/__snapshots__/scenario.js.snap b/cypress/integration/ui/__snapshots__/scenario.js.snap index c6f15fb9..db0a2bd4 100644 --- a/cypress/integration/ui/__snapshots__/scenario.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario.js.snap @@ -44,6 +44,7 @@ exports[`use various parts of svg-edit > check tool_text #0`] = ` font-size="24" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" x="46" xml:space="preserve" @@ -72,6 +73,7 @@ exports[`use various parts of svg-edit > check tool_clone #0`] = ` font-size="24" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" x="46" xml:space="preserve" @@ -85,6 +87,7 @@ exports[`use various parts of svg-edit > check tool_clone #0`] = ` font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" x="66" xml:space="preserve" @@ -114,6 +117,7 @@ exports[`use various parts of svg-edit > check tool_italic #0`] = ` font-style="italic" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" x="46" xml:space="preserve" @@ -127,6 +131,7 @@ exports[`use various parts of svg-edit > check tool_italic #0`] = ` font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="66" @@ -158,6 +163,7 @@ exports[`use various parts of svg-edit > check tool_bold #0`] = ` font-weight="bold" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" x="46" xml:space="preserve" @@ -171,6 +177,7 @@ exports[`use various parts of svg-edit > check tool_bold #0`] = ` font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="66" @@ -202,6 +209,7 @@ exports[`use various parts of svg-edit > check tool_text_change_x_y_coordinate # font-weight="bold" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -216,6 +224,7 @@ exports[`use various parts of svg-edit > check tool_text_change_x_y_coordinate # font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" x="91" xml:space="preserve" @@ -246,6 +255,7 @@ exports[`use various parts of svg-edit > check tool_text_change_font_size #0`] = font-weight="bold" id="svg_1" stroke="#000000" + stroke-width="0" text-anchor="middle" x="46" xml:space="preserve" @@ -259,6 +269,7 @@ exports[`use various parts of svg-edit > check tool_text_change_font_size #0`] = font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="91" @@ -290,7 +301,6 @@ exports[`use various parts of svg-edit > check tool_text_change_stroke_width #0` font-weight="bold" id="svg_1" stroke="#000000" - stroke-width="2" text-anchor="middle" x="46" xml:space="preserve" @@ -304,6 +314,7 @@ exports[`use various parts of svg-edit > check tool_text_change_stroke_width #0` font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="91" @@ -335,7 +346,6 @@ exports[`use various parts of svg-edit > check tool_text_change_stoke_fill_color font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" x="46" xml:space="preserve" @@ -349,6 +359,7 @@ exports[`use various parts of svg-edit > check tool_text_change_stoke_fill_color font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="91" @@ -380,7 +391,6 @@ exports[`use various parts of svg-edit > check tool_text_change_rotation #0`] = font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -395,8 +405,9 @@ exports[`use various parts of svg-edit > check tool_text_change_rotation #0`] = font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" - transform="rotate(25 91 72.25)" + transform="rotate(25 91 72)" x="91" xml:space="preserve" y="80" @@ -426,7 +437,6 @@ exports[`use various parts of svg-edit > check tool_text_change_blur #0`] = ` font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -442,8 +452,9 @@ exports[`use various parts of svg-edit > check tool_text_change_blur #0`] = ` font-size="24" id="svg_2" stroke="#000000" + stroke-width="0" text-anchor="middle" - transform="rotate(25 91 72.25)" + transform="rotate(25 91 72)" x="91" xml:space="preserve" y="80" @@ -478,7 +489,6 @@ exports[`use various parts of svg-edit > check tool_text_change_opacity #0`] = ` font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -495,8 +505,9 @@ exports[`use various parts of svg-edit > check tool_text_change_opacity #0`] = ` id="svg_2" opacity="0.5" stroke="#000000" + stroke-width="0" text-anchor="middle" - transform="rotate(25 91 72.25)" + transform="rotate(25 91 72)" x="91" xml:space="preserve" y="80" @@ -531,7 +542,6 @@ exports[`use various parts of svg-edit > check tool_text_align_to_page #0`] = ` font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -548,8 +558,9 @@ exports[`use various parts of svg-edit > check tool_text_align_to_page #0`] = ` id="svg_2" opacity="0.5" stroke="#000000" + stroke-width="0" text-anchor="middle" - transform="rotate(25 91 72.25)" + transform="rotate(25 91 72)" x="91" xml:space="preserve" y="80" @@ -584,7 +595,6 @@ exports[`use various parts of svg-edit > check tool_text_delete #0`] = ` font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" transform="matrix(1 0 0 1 0 0)" x="46" @@ -616,7 +626,6 @@ exports[`use various parts of svg-edit > check tool_text_change_font_family #0`] font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" x="46" xml:space="preserve" @@ -647,7 +656,6 @@ exports[`use various parts of svg-edit > check tool_text_decoration_underline #0 font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" text-decoration="underline" x="46" @@ -679,7 +687,6 @@ exports[`use various parts of svg-edit > check tool_text_decoration_linethrough font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" text-decoration="underline line-through" x="46" @@ -711,7 +718,6 @@ exports[`use various parts of svg-edit > check tool_text_decoration_overline #0` font-weight="bold" id="svg_1" stroke="#0000bf" - stroke-width="2" text-anchor="middle" text-decoration="underline line-through overline" x="46" diff --git a/src/svgcanvas/coords.js b/src/svgcanvas/coords.js index 496669fb..1b984514 100644 --- a/src/svgcanvas/coords.js +++ b/src/svgcanvas/coords.js @@ -62,7 +62,7 @@ export const remapElement = (selected, changes, m) => { ['fill', 'stroke'].forEach((type) => { const attrVal = selected.getAttribute(type) - if (attrVal && attrVal.startsWith('url(') && (m.a < 0 || m.d < 0)) { + if (attrVal?.startsWith('url(') && (m.a < 0 || m.d < 0)) { const grad = getRefElem(attrVal) const newgrad = grad.cloneNode(true) if (m.a < 0) { diff --git a/src/svgcanvas/jQuery.attr.js b/src/svgcanvas/jQuery.attr.js deleted file mode 100644 index 2383dc92..00000000 --- a/src/svgcanvas/jQuery.attr.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * A jQuery module to work with SVG attributes. - * @module jQueryAttr - * @license MIT - */ - -/** -* This fixes `$(...).attr()` to work as expected with SVG elements. -* Does not currently use `*AttributeNS()` since we rarely need that. -* Adds {@link external:jQuery.fn.attr}. -* See {@link https://api.jquery.com/attr/} for basic documentation of `.attr()`. -* -* Additional functionality: -* - When getting attributes, a string that's a number is returned as type number. -* - If an array is supplied as the first parameter, multiple values are returned -* as an object with values for each given attribute. -* @function module:jQueryAttr.jQueryAttr -* @param {external:jQuery} $ The jQuery object to which to add the plug-in -* @returns {external:jQuery} -*/ -export default function jQueryPluginSVG ($) { - const proxied = $.fn.attr - const svgns = 'http://www.w3.org/2000/svg' - /** - * @typedef {PlainObject} module:jQueryAttr.Attributes - */ - /** - * @function external:jQuery.fn.attr - * @param {string|string[]|PlainObject} key - * @param {string} value - * @returns {external:jQuery|module:jQueryAttr.Attributes} - */ - $.fn.attr = function (key, value) { - const len = this.length - if (!len) { return proxied.call(this, key, value) } - for (let i = 0; i < len; ++i) { - const elem = this[i] - // set/get SVG attribute - if (elem.namespaceURI === svgns) { - // Setting attribute - if (value !== undefined) { - elem.setAttribute(key, value) - } else if (Array.isArray(key)) { - // Getting attributes from array - const obj = {} - let j = key.length - - while (j--) { - const aname = key[j] - let attr = elem.getAttribute(aname) - // This returns a number when appropriate - if (attr || attr === '0') { - attr = isNaN(attr) ? attr : (attr - 0) - } - obj[aname] = attr - } - return obj - } - if (typeof key === 'object') { - // Setting attributes from object - for (const [name, val] of Object.entries(key)) { - elem.setAttribute(name, val) - } - // Getting attribute - } else { - let attr = elem.getAttribute(key) - if (attr || attr === '0') { - attr = isNaN(attr) ? attr : (attr - 0) - } - return attr - } - } else { - return proxied.call(this, key, value) - } - } - return this - } - return $ -}