From ddd6d9bde0b444943fd868c26aa0d1d38462835a Mon Sep 17 00:00:00 2001 From: agriyadev5 Date: Mon, 30 Aug 2021 18:03:22 +0530 Subject: [PATCH 01/16] #631 rulers id not found , so we removed --- src/editor/MainMenu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js index bac71306..c7068ffb 100644 --- a/src/editor/MainMenu.js +++ b/src/editor/MainMenu.js @@ -120,7 +120,6 @@ class MainMenu { this.editor.configObj.curConfig.snappingStep = gridsnappingstep; this.editor.configObj.curConfig.gridColor = gridcolor; this.editor.configObj.curConfig.showRulers = showrulers; - $id('rulers').style.display = (this.editor.configObj.curConfig.showRulers) ? 'block' : 'none'; if (this.editor.configObj.curConfig.showRulers) { this.editor.rulers.updateRulers(); } From 6579c7e6601dc18e06450cd967675d4790be2ea2 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Tue, 31 Aug 2021 12:30:44 +0200 Subject: [PATCH 02/16] fix issue with subpath --- src/svgcanvas/path-actions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index b4a1c6e0..d8a07faa 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -446,7 +446,6 @@ export const pathActionsMethod = (function () { if (path.matrix) { pathActionsContext_.recalcRotatedPath(); } - init(); pathActionsMethod.toEditMode(path.elem); path.selectPt(); return false; From 69e5d7a0fab465b31bccf69d1e3278e13fdd3dd8 Mon Sep 17 00:00:00 2001 From: bluetwelve <82043995+bluetwelve@users.noreply.github.com> Date: Wed, 1 Sep 2021 20:52:31 -0400 Subject: [PATCH 03/16] Update path-actions.js replace deprecated code to set the display attribute of the control points --- src/svgcanvas/path-actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index d8a07faa..e91a0875 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -861,7 +861,7 @@ export const pathActionsMethod = (function () { const pathpointgripContainer = getElem('pathpointgrip_container'); const elements = pathpointgripContainer.querySelectorAll('*'); Array.prototype.forEach.call(elements, function(el){ - el.style.display = 'none'; + el.setAttribute('display', 'none'); }); firstCtrl = null; editorContext_.setDrawnPath(null); From 0c49e7641c85a031d14e054c94f785f77f549c7f Mon Sep 17 00:00:00 2001 From: bluetwelve <82043995+bluetwelve@users.noreply.github.com> Date: Wed, 1 Sep 2021 20:56:02 -0400 Subject: [PATCH 04/16] replace out of date code to set display attribute --- src/svgcanvas/path-method.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svgcanvas/path-method.js b/src/svgcanvas/path-method.js index d17c0e7a..4a5c04ee 100644 --- a/src/svgcanvas/path-method.js +++ b/src/svgcanvas/path-method.js @@ -640,7 +640,7 @@ export class Path { const pointGripContainer = getGripContainerMethod(); const elements = pointGripContainer.querySelectorAll('*'); Array.prototype.forEach.call(elements, function(el){ - el.style.display = 'none'; + el.setAttribute('display', 'none'); }); const segList = this.elem.pathSegList; From 314904b1f48aaadf80f730a2bbbce37e7629e2cd Mon Sep 17 00:00:00 2001 From: bluetwelve <82043995+bluetwelve@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:25:22 -0400 Subject: [PATCH 05/16] setPathContext function added --- src/svgcanvas/path-method.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/svgcanvas/path-method.js b/src/svgcanvas/path-method.js index 4a5c04ee..1c5c439c 100644 --- a/src/svgcanvas/path-method.js +++ b/src/svgcanvas/path-method.js @@ -629,6 +629,10 @@ export class Path { this.init(); } + setPathContext() { + pathMethodsContext_.setPathObj(this); + } + /** * Reset path data. * @returns {module:path.Path} From 2bdaab1d869d4e8047f273747bd19cb72e24eef8 Mon Sep 17 00:00:00 2001 From: bluetwelve <82043995+bluetwelve@users.noreply.github.com> Date: Fri, 3 Sep 2021 11:31:18 -0400 Subject: [PATCH 06/16] call setPathContext when path is selected... or enters edit mode --- src/svgcanvas/path-actions.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index e91a0875..852c90bd 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -757,6 +757,7 @@ export const pathActionsMethod = (function () { path = pathActionsContext_.getPath_(element); editorContext_.setCurrentMode('pathedit'); editorContext_.clearSelection(); + path.setPathContext(); path.show(true).update(); path.oldbbox = utilsGetBBox(path.elem); subpath = false; @@ -770,6 +771,7 @@ export const pathActionsMethod = (function () { editorContext_ = pathActionsContext_.getEditorContext(); const selPath = (elem === path.elem); editorContext_.setCurrentMode('select'); + path.setPathContext(); path.show(false); currentPath = false; editorContext_.clearSelection(); From d4d933820e3d099e55206a245a7f3d73287f21d6 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:32:22 +0200 Subject: [PATCH 07/16] fix several ui issues --- src/editor/EditorStartup.js | 2 +- src/editor/MainMenu.js | 2 +- src/editor/components/index.js | 2 + src/editor/components/seButton.js | 2 +- src/editor/components/seInput.js | 1 + src/editor/components/seList.js | 6 +- src/editor/components/seSelect.js | 149 +++++++++++++++++++++++++++ src/editor/components/seSpinInput.js | 1 + src/editor/panels/BottomPanel.js | 11 +- src/editor/panels/TopPanel.js | 43 ++++---- src/editor/svgedit.css | 22 ++-- src/svgcanvas/path-actions.js | 2 +- 12 files changed, 198 insertions(+), 45 deletions(-) create mode 100644 src/editor/components/seSelect.js diff --git a/src/editor/EditorStartup.js b/src/editor/EditorStartup.js index 1476ee80..39cb8121 100644 --- a/src/editor/EditorStartup.js +++ b/src/editor/EditorStartup.js @@ -249,7 +249,7 @@ class EditorStartup { }); $id('seg_type').addEventListener('change', (evt) => { - this.svgCanvas.setSegType(evt.currentTarget.value); + this.svgCanvas.setSegType(evt.detail.value); }); const addListenerMulti = (element, eventNames, listener)=> { diff --git a/src/editor/MainMenu.js b/src/editor/MainMenu.js index c7068ffb..37bac189 100644 --- a/src/editor/MainMenu.js +++ b/src/editor/MainMenu.js @@ -289,7 +289,7 @@ class MainMenu { `; - $id('tools_top').prepend(template.content.cloneNode(true)); + this.editor.$svgEditor.append(template.content.cloneNode(true)); // register action to main menu entries /** diff --git a/src/editor/components/index.js b/src/editor/components/index.js index 8f16e993..e59f23c2 100644 --- a/src/editor/components/index.js +++ b/src/editor/components/index.js @@ -10,3 +10,5 @@ import './seMenuItem.js'; import './seList.js'; import './seListItem.js'; import './seColorPicker.js'; +import './seSelect'; + diff --git a/src/editor/components/seButton.js b/src/editor/components/seButton.js index f6e5478a..2b91e39f 100644 --- a/src/editor/components/seButton.js +++ b/src/editor/components/seButton.js @@ -10,7 +10,7 @@ template.innerHTML = ` { height: 24px; width: 24px; - margin: 2px 1px 4px; + margin: 4px 1px 4px; padding: 3px; background-color: var(--icon-bg-color); cursor: pointer; diff --git a/src/editor/components/seInput.js b/src/editor/components/seInput.js index e19e1dbf..19f03594 100644 --- a/src/editor/components/seInput.js +++ b/src/editor/components/seInput.js @@ -23,6 +23,7 @@ template.innerHTML = ` elix-input { background-color: var(--input-color); border-radius: 3px; + height: 24px; }
diff --git a/src/editor/components/seList.js b/src/editor/components/seList.js index 7f573115..4b903a9b 100644 --- a/src/editor/components/seList.js +++ b/src/editor/components/seList.js @@ -11,7 +11,11 @@ elix-dropdown-list:hover { background-color: var(--icon-bg-color-hover); } -::part(popup-toggle) { +elix-dropdown-list::part(value) { + background-color: var(--main-bg-color); +} + +elix-dropdown-list::part(popup-toggle) { display: none; } ::slotted(*) { diff --git a/src/editor/components/seSelect.js b/src/editor/components/seSelect.js new file mode 100644 index 00000000..d1fc629f --- /dev/null +++ b/src/editor/components/seSelect.js @@ -0,0 +1,149 @@ +const template = document.createElement('template'); +template.innerHTML = ` + + + + +`; +/** + * @class SeList + */ +export class SeSelect extends HTMLElement { + /** + * @function constructor + */ + constructor () { + super(); + // create the shadowDom and insert the template + this._shadowRoot = this.attachShadow({ mode: 'open' }); + this._shadowRoot.append(template.content.cloneNode(true)); + this.$select = this._shadowRoot.querySelector('select'); + this.$label = this._shadowRoot.querySelector('label'); + } + /** + * @function observedAttributes + * @returns {any} observed + */ + static get observedAttributes () { + return [ 'label', 'width', 'height', 'options', 'values' ]; + } + + /** + * @function attributeChangedCallback + * @param {string} name + * @param {string} oldValue + * @param {string} newValue + * @returns {void} + */ + attributeChangedCallback (name, oldValue, newValue) { + let options; + if (oldValue === newValue) return; + switch (name) { + case 'label': + this.$label.textContent = newValue; + break; + case 'height': + this.$select.style.height = newValue; + break; + case 'width': + this.$select.style.width = newValue; + break; + case 'options': + options = newValue.split(','); + options.forEach((option) => { + const optionNode = document.createElement("OPTION"); + const text = document.createTextNode(option); + optionNode.appendChild(text); + this.$select.appendChild(optionNode); + }); + break; + case 'values': + options = newValue.split(' '); + options.forEach((option, index) => { + this.$select.children[index].setAttribute('value', option); + }); + break; + default: + // eslint-disable-next-line no-console + console.error(`unknown attribute: ${name}`); + break; + } + } + /** + * @function get + * @returns {any} + */ + get label () { + return this.getAttribute('label'); + } + + /** + * @function set + * @returns {void} + */ + set label (value) { + this.setAttribute('label', value); + } + /** + * @function get + * @returns {any} + */ + get width () { + return this.getAttribute('width'); + } + + /** + * @function set + * @returns {void} + */ + set width (value) { + this.setAttribute('width', value); + } + /** + * @function get + * @returns {any} + */ + get height () { + return this.getAttribute('height'); + } + + /** + * @function set + * @returns {void} + */ + set height (value) { + this.setAttribute('height', value); + } + /** + * @function connectedCallback + * @returns {void} + */ + connectedCallback () { + const currentObj = this; + this.$select.addEventListener('change', () => { + const value = this.$select.value; + const closeEvent = new CustomEvent('change', { detail: { value } }); + currentObj.dispatchEvent(closeEvent); + currentObj.value = value; + }); + } +} + +// Register +customElements.define('se-select', SeSelect); diff --git a/src/editor/components/seSpinInput.js b/src/editor/components/seSpinInput.js index 24c82ed8..694bbfad 100644 --- a/src/editor/components/seSpinInput.js +++ b/src/editor/components/seSpinInput.js @@ -14,6 +14,7 @@ template.innerHTML = ` img { position: relative; right: -4px; + top: 2px; } span { bottom: -0.5em; diff --git a/src/editor/panels/BottomPanel.js b/src/editor/panels/BottomPanel.js index 4fd14c87..801742e3 100644 --- a/src/editor/panels/BottomPanel.js +++ b/src/editor/panels/BottomPanel.js @@ -186,13 +186,10 @@ class BottomPanel { - - - ... - - - - - . - - .. - + + diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index 34928a31..e1709e72 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -920,12 +920,13 @@ class TopPanel { - - ${i18next.t('tools.selected_objects')} - ${i18next.t('tools.largest_object')} - ${i18next.t('tools.smallest_object')} - ${i18next.t('tools.page')} - + +
@@ -976,16 +977,17 @@ class TopPanel {
- - ${i18next.t('properties.serif')} - ${i18next.t('properties.sans_serif')} - ${i18next.t('properties.cursive')} - ${i18next.t('properties.fantasy')} - ${i18next.t('properties.monospace')} - ${i18next.t('properties.courier')} - ${i18next.t('properties.helvetica')} - ${i18next.t('properties.times')} - + +
@@ -1025,10 +1027,11 @@ class TopPanel {
- + + diff --git a/src/editor/svgedit.css b/src/editor/svgedit.css index 510b5974..f79e705b 100644 --- a/src/editor/svgedit.css +++ b/src/editor/svgedit.css @@ -18,12 +18,12 @@ .svg_editor { display: grid; grid-template-rows: auto 15px 1fr 40px; - grid-template-columns: 34px 15px 1fr 15px; + grid-template-columns: 34px 15px 50px 1fr 15px; grid-template-areas: - "top top top top" - "left corner rulerX side" - "left rulerY workarea side" - "left bottom bottom bottom"; + "main main main top top" + "left corner rulerX rulerX side" + "left rulerY workarea workarea side" + "left bottom bottom bottom bottom"; font-size: 8pt; background: var(--main-bg-color); font-family: Verdana, Helvetica, Arial; @@ -33,12 +33,7 @@ height: 100%; } -.svg_editor.open { - grid-template-columns: 34px 15px 1fr 150px; -} - /* on smaller screen, allow 2 lines for the toolbar */ - @media screen and (max-width:1250px) { .svg_editor { grid-template-rows: minmax(80px, auto) 15px 1fr 40px; @@ -186,6 +181,7 @@ hr { —————————————————————————————*/ #main_button { + grid-area: main; color: #fff; border-radius: 3px; padding-block: 2px; @@ -299,8 +295,7 @@ hr { display: flex; flex-direction: row; flex-wrap: wrap; - /* leave space for the main menu */ - position: relative; + align-items: flex-start; background-color: var(--main-bg-color); } @@ -325,11 +320,12 @@ hr { width: 3px; } -#tools_bottom se-list { +#tools_bottom se-list, #tools_bottom se-select { margin-bottom: 8px; } + /*—————————————————————————————*/ #tools_left { diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index 852c90bd..39e40878 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -1179,7 +1179,7 @@ export const pathActionsMethod = (function () { * @returns {void} */ setSegType (v) { - path.setSegType(v); + path?.setSegType(v); }, /** * @param {string} attr From 9fe15e1d1623f0e88ef9d294b11ca809508bd668 Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Sat, 4 Sep 2021 19:42:46 +0200 Subject: [PATCH 08/16] Update TopPanel.js --- src/editor/panels/TopPanel.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index e1709e72..5535d7d1 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -985,7 +985,8 @@ class TopPanel { ${i18next.t('properties.monospace')}, ${i18next.t('properties.courier')}, ${i18next.t('properties.helvetica')}, - ${i18next.t('properties.times')} " + ${i18next.t('properties.times')}" + values="Serif Sans-serif Cursive Fantasy Monospace Courier Helvetica Times" > Date: Sun, 5 Sep 2021 11:01:59 +0200 Subject: [PATCH 09/16] fix test --- cypress/integration/ui/scenario.js | 4 +--- cypress/integration/ui/scenario3.js | 2 +- src/editor/ConfigObj.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cypress/integration/ui/scenario.js b/cypress/integration/ui/scenario.js index 51424509..4412b614 100644 --- a/cypress/integration/ui/scenario.js +++ b/cypress/integration/ui/scenario.js @@ -182,9 +182,7 @@ describe('use various parts of svg-edit', function () { }); it('check tool_text_change_font_family', function () { cy.get('#svg_1').click({ force: true }); - cy.get('#tool_font_family').shadow().find('elix-dropdown-list').eq(0).invoke('attr', 'opened', 'opened'); - cy.get('#tool_font_family').find('se-list-item').eq(6).shadow().find('elix-option').eq(0) - .click({ force: true }); + cy.get('#tool_font_family').shadow().find('select').select("Serif"); cy.get('#svgcontent').toMatchSnapshot(); }); }); diff --git a/cypress/integration/ui/scenario3.js b/cypress/integration/ui/scenario3.js index ca548f87..a8aaebf7 100644 --- a/cypress/integration/ui/scenario3.js +++ b/cypress/integration/ui/scenario3.js @@ -56,7 +56,7 @@ describe('use all parts of svg-edit', function () { it('check tool_path_change_seg_type', function () { cy.get('#svg_1').click({ force: true }); cy.get('#svg_1').dblclick({ force: true }); - cy.get('#seg_type').select('6').should('have.value', '6'); + cy.get('#seg_type').shadow().find('select').select('6').should('have.value', '6'); cy.get('#ctrlpointgrip_3c1') .trigger('mousedown', { force: true }) .trigger('mousemove', 130, 175, { force: true }) diff --git a/src/editor/ConfigObj.js b/src/editor/ConfigObj.js index b406d107..f4095ba6 100644 --- a/src/editor/ConfigObj.js +++ b/src/editor/ConfigObj.js @@ -122,7 +122,7 @@ export default class ConfigObj { text: { stroke_width: 0, font_size: 24, - font_family: 'serif' + font_family: 'Serif' }, initOpacity: 1, initTool: 'select', From 3b6af37f4754f2d024eda3c4e15a6c8671679d2d Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Sun, 5 Sep 2021 16:40:30 +0200 Subject: [PATCH 10/16] Update svgedit.css --- src/editor/svgedit.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/editor/svgedit.css b/src/editor/svgedit.css index f79e705b..212e58ac 100644 --- a/src/editor/svgedit.css +++ b/src/editor/svgedit.css @@ -1,6 +1,6 @@ :root { --main-bg-color: #72797A; - --text-color: #000000; + --text-color: #ffffff; --border-color: #808080; --canvas-bg-color: #B2B2B2; --link-color: #19c; @@ -40,6 +40,11 @@ } } +/* class to open the right panel */ +.svg_editor.open { + grid-template-columns: 34px 15px 50px 1fr 150px; +} + #svgroot { user-select: none; position: absolute; From e8d59904f7152b51d369bd8cf2ad1b5d9a73c17b Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Wed, 8 Sep 2021 22:33:13 +0200 Subject: [PATCH 11/16] fix visual issues --- src/editor/components/seSelect.js | 15 +++++++++++++++ src/editor/svgedit.css | 6 +++++- src/svgcanvas/utilities.js | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/editor/components/seSelect.js b/src/editor/components/seSelect.js index d1fc629f..a8833523 100644 --- a/src/editor/components/seSelect.js +++ b/src/editor/components/seSelect.js @@ -130,6 +130,21 @@ export class SeSelect extends HTMLElement { set height (value) { this.setAttribute('height', value); } + /** + * @function get + * @returns {any} + */ + get value () { + return this.$select.value; + } + + /** + * @function set + * @returns {void} + */ + set value (value) { + this.$select.value = value; + } /** * @function connectedCallback * @returns {void} diff --git a/src/editor/svgedit.css b/src/editor/svgedit.css index 212e58ac..18b3a95d 100644 --- a/src/editor/svgedit.css +++ b/src/editor/svgedit.css @@ -329,7 +329,11 @@ hr { margin-bottom: 8px; } - +#zoom { + color: var(--text-color); + background-color: var(--main-bg-color); + border: none; +} /*—————————————————————————————*/ diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index d068d5a7..d63bab24 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -1049,7 +1049,7 @@ export const getStrokedBBox = function (elems, addSVGElementFromJson, pathAction }); // This shouldn't ever happen... - if (fullBb === undefined) { return null; } + if (!fullBb) { return null; } // fullBb doesn't include the stoke, so this does no good! // if (elems.length == 1) return fullBb; From e92ccd044487cb71c72a22e5a561b91441914bfb Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 20 Sep 2021 08:24:18 +0200 Subject: [PATCH 12/16] Path Box widely supported, Replace/Insert in Path are deprecated (but polyfilled) --- cypress/integration/unit/utilities.js | 15 ---- src/common/browser.js | 56 -------------- src/editor/Editor.js | 3 +- src/editor/extensions/ext-imagelib/index.js | 3 +- src/editor/panels/TopPanel.js | 3 +- src/svgcanvas/blur-event.js | 1 - src/svgcanvas/utilities.js | 86 ++------------------- 7 files changed, 10 insertions(+), 157 deletions(-) diff --git a/cypress/integration/unit/utilities.js b/cypress/integration/unit/utilities.js index c30ea97e..61c83152 100644 --- a/cypress/integration/unit/utilities.js +++ b/cypress/integration/unit/utilities.js @@ -1,5 +1,4 @@ /* eslint-disable max-len */ -import * as browser from '../../../instrumented/common/browser.js'; import * as utilities from '../../../instrumented/svgcanvas/utilities.js'; import { NS } from '../../../instrumented/common/namespaces.js'; @@ -161,19 +160,6 @@ describe('utilities', function () { assert.equal(utilities.getUrlFromAttr('url("#foo")'), '#foo'); }); - it('Test getPathBBox', function () { - if (browser.supportsPathBBox()) { - return; - } - const doc = utilities.text2xml(''); - const path = doc.createElementNS(NS.SVG, 'path'); - path.setAttribute('d', 'm0,0l5,0l0,5l-5,0l0,-5z'); - const bb = utilities.getPathBBox(path); - assert.equal(typeof bb, 'object', 'BBox returned object'); - assert.ok(bb.x && !isNaN(bb.x)); - assert.ok(bb.y && !isNaN(bb.y)); - }); - it('Test getPathDFromSegments', function () { const { getPathDFromSegments } = utilities; @@ -226,7 +212,6 @@ describe('utilities', function () { }); svgroot.append(elem); const closeEnough = /M0,4 C0,2.3\d* 0.9\d*,1 2,1 L8,1 C9.0\d*,1 10,2.3\d* 10,4 L10,9 C10,10.6\d* 9.0\d*,12 8,12 L2,12 C0.9\d*,12 0,10.6\d* 0,9 L0,4 Z/; - console.log(getPathDFromElement(elem), closeEnough); assert.equal(closeEnough.test(getPathDFromElement(elem)), true); elem.remove(); diff --git a/src/common/browser.js b/src/common/browser.js index 003a9756..86499d55 100644 --- a/src/common/browser.js +++ b/src/common/browser.js @@ -6,8 +6,6 @@ * @copyright 2010 Jeff Schiller, 2010 Alexis Deveria */ -import 'pathseg'; - import { NS } from './namespaces.js'; const { userAgent } = navigator; @@ -19,31 +17,6 @@ const isChrome_ = userAgent.includes('Chrome/'); const isMac_ = userAgent.includes('Macintosh'); const isTouch_ = 'ontouchstart' in window; -// segList functions (for FF1.5 and 2.0) -const supportsPathReplaceItem_ = (function () { - const path = document.createElementNS(NS.SVG, 'path'); - path.setAttribute('d', 'M0,0 10,10'); - const seglist = path.pathSegList; - const seg = path.createSVGPathSegLinetoAbs(5, 5); - try { - seglist.replaceItem(seg, 1); - return true; - }catch (err) {/* empty */} - return false; -}()); - -const supportsPathInsertItemBefore_ = (function () { - const path = document.createElementNS(NS.SVG, 'path'); - path.setAttribute('d', 'M0,0 10,10'); - const seglist = path.pathSegList; - const seg = path.createSVGPathSegLinetoAbs(5, 5); - try { - seglist.insertItemBefore(seg, 1); - return true; - }catch (err) {/* empty */} - return false; -}()); - // text character positioning (for IE9 and now Chrome) const supportsGoodTextCharPos_ = (function () { const svgroot = document.createElementNS(NS.SVG, 'svg'); @@ -64,17 +37,6 @@ const supportsGoodTextCharPos_ = (function () { } }()); -const supportsPathBBox_ = (function () { - const svgcontent = document.createElementNS(NS.SVG, 'svg'); - document.documentElement.append(svgcontent); - const path = document.createElementNS(NS.SVG, 'path'); - path.setAttribute('d', 'M0,0 C0,0 10,10 10,0'); - svgcontent.append(path); - const bbox = path.getBBox(); - svgcontent.remove(); - return (bbox.height > 4 && bbox.height < 5); -}()); - // Support for correct bbox sizing on groups with horizontal/vertical lines const supportsHVLineContainerBBox_ = (function () { const svgcontent = document.createElementNS(NS.SVG, 'svg'); @@ -127,24 +89,6 @@ export const isMac = () => isMac_; */ export const isTouch = () => isTouch_; -/** - * @function module:browser.supportsPathReplaceItem - * @returns {boolean} -*/ -export const supportsPathReplaceItem = () => supportsPathReplaceItem_; - -/** - * @function module:browser.supportsPathInsertItemBefore - * @returns {boolean} -*/ -export const supportsPathInsertItemBefore = () => supportsPathInsertItemBefore_; - -/** - * @function module:browser.supportsPathBBox - * @returns {boolean} -*/ -export const supportsPathBBox = () => supportsPathBBox_; - /** * @function module:browser.supportsHVLineContainerBBox * @returns {boolean} diff --git a/src/editor/Editor.js b/src/editor/Editor.js index c5e58ff8..249a0404 100644 --- a/src/editor/Editor.js +++ b/src/editor/Editor.js @@ -365,7 +365,8 @@ class Editor extends EditorStartup { const { workarea } = this; const cnvs = $id("svgcanvas"); - let w = parseFloat(getComputedStyle(workarea, null).width.replace("px", "")); let h = parseFloat(getComputedStyle(workarea, null).height.replace("px", "")); + let w = parseFloat(getComputedStyle(workarea, null).width.replace("px", "")); + let h = parseFloat(getComputedStyle(workarea, null).height.replace("px", "")); const wOrig = w; const hOrig = h; const oldCtr = { x: workarea.scrollLeft + wOrig / 2, diff --git a/src/editor/extensions/ext-imagelib/index.js b/src/editor/extensions/ext-imagelib/index.js index eac794e4..d7b13351 100644 --- a/src/editor/extensions/ext-imagelib/index.js +++ b/src/editor/extensions/ext-imagelib/index.js @@ -48,8 +48,7 @@ Array.prototype.forEach.call(atags, function (aEle) { post({ href, data }); return data; }) - // eslint-disable-next-line no-console - .catch( (error) => console.log(error)); + .catch( (error) => console.error(error)); } return false; }); diff --git a/src/editor/panels/TopPanel.js b/src/editor/panels/TopPanel.js index 5535d7d1..d132b36e 100644 --- a/src/editor/panels/TopPanel.js +++ b/src/editor/panels/TopPanel.js @@ -782,8 +782,7 @@ class TopPanel { editor.svgCanvas.setMode('select'); editor.svgCanvas.selectOnly(editor.svgCanvas.getSelectedElems(), true); }, (error) => { - // eslint-disable-next-line no-console - console.log("error =", error); + console.error("error =", error); seAlert(editor.i18next.t('tools.no_embed')); editor.svgCanvas.deleteSelectedElements(); }); diff --git a/src/svgcanvas/blur-event.js b/src/svgcanvas/blur-event.js index f3208c01..9897ece1 100644 --- a/src/svgcanvas/blur-event.js +++ b/src/svgcanvas/blur-event.js @@ -44,7 +44,6 @@ export const setBlurNoUndo = function (val) { blurContext_.changeSelectedAttributeNoUndoMethod('filter', 'url(#' + elem.id + '_blur)'); } if (blurContext_.isWebkit()) { - // console.log('e', elem); elem.removeAttribute('filter'); elem.setAttribute('filter', 'url(#' + elem.id + '_blur)'); } diff --git a/src/svgcanvas/utilities.js b/src/svgcanvas/utilities.js index d63bab24..fac3250d 100644 --- a/src/svgcanvas/utilities.js +++ b/src/svgcanvas/utilities.js @@ -12,13 +12,10 @@ import { hasMatrixTransform, transformListToTransform, transformBox } from './math.js'; import { - isWebkit, supportsHVLineContainerBBox, supportsPathBBox + isWebkit, supportsHVLineContainerBBox } from '../common/browser.js'; import { getClosest, mergeDeep } from '../editor/components/jgraduate/Util.js'; -// String used to encode base64. -const KEYSTR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - // Much faster than running getBBox() every time const visElems = 'a,circle,ellipse,foreignObject,g,image,line,path,polygon,polyline,rect,svg,text,tspan,use,clipPath'; const visElemsArr = visElems.split(','); @@ -137,41 +134,7 @@ export const toXml = function (str) { export function encode64(input) { // base64 strings are 4/3 larger than the original string input = encodeUTF8(input); // convert non-ASCII characters - // input = convertToXMLReferences(input); - if (window.btoa) { - return window.btoa(input); // Use native if available - } - const output = new Array(Math.floor((input.length + 2) / 3) * 4); - - let i = 0; - let p = 0; - do { - const chr1 = input.charCodeAt(i++); - const chr2 = input.charCodeAt(i++); - const chr3 = input.charCodeAt(i++); - - /* eslint-disable no-bitwise */ - const enc1 = chr1 >> 2; - const enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - - let enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - let enc4 = chr3 & 63; - /* eslint-enable no-bitwise */ - - if (Number.isNaN(chr2)) { - enc3 = 64; - enc4 = 64; - } else if (Number.isNaN(chr3)) { - enc4 = 64; - } - - output[p++] = KEYSTR.charAt(enc1); - output[p++] = KEYSTR.charAt(enc2); - output[p++] = KEYSTR.charAt(enc3); - output[p++] = KEYSTR.charAt(enc4); - } while (i < input.length); - - return output.join(''); + return window.btoa(input); // Use native if available } /** @@ -181,38 +144,7 @@ export function encode64(input) { * @returns {string} Decoded output */ export function decode64(input) { - if (window.atob) { - return decodeUTF8(window.atob(input)); - } - - // remove all characters that are not A-Z, a-z, 0-9, +, /, or = - input = input.replace(/[^A-Za-z\d+/=]/g, ''); - - let output = ''; - let i = 0; - - do { - const enc1 = KEYSTR.indexOf(input.charAt(i++)); - const enc2 = KEYSTR.indexOf(input.charAt(i++)); - const enc3 = KEYSTR.indexOf(input.charAt(i++)); - const enc4 = KEYSTR.indexOf(input.charAt(i++)); - - /* eslint-disable no-bitwise */ - const chr1 = (enc1 << 2) | (enc2 >> 4); - const chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - const chr3 = ((enc3 & 3) << 6) | enc4; - /* eslint-enable no-bitwise */ - - output += String.fromCharCode(chr1); - - if (enc3 !== 64) { - output += String.fromCharCode(chr2); - } - if (enc4 !== 64) { - output += String.fromCharCode(chr3); - } - } while (i < input.length); - return decodeUTF8(output); + return decodeUTF8(window.atob(input)); } /** @@ -315,17 +247,13 @@ export const text2xml = function (sXML) { let out; let dXML; try { - dXML = (window.DOMParser) ? new DOMParser() : new window.ActiveXObject('Microsoft.XMLDOM'); + dXML = new DOMParser(); dXML.async = false; } catch (e) { throw new Error('XML Parser could not be instantiated'); } try { - if (dXML.loadXML) { - out = (dXML.loadXML(sXML)) ? dXML : false; - } else { - out = dXML.parseFromString(sXML, 'text/xml'); - } + out = dXML.parseFromString(sXML, 'text/xml'); } catch (e2) { throw new Error('Error parsing XML string'); } return out; }; @@ -618,9 +546,7 @@ export const getBBox = function (elem) { } break; case 'path': - if (!supportsPathBBox()) { - ret = getPathBBox(selected); - } else if (selected.getBBox) { + if (selected.getBBox) { ret = selected.getBBox(); } break; From 049627eed3cf3ab38a0921ce886f21f10a5c737f Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 20 Sep 2021 08:24:29 +0200 Subject: [PATCH 13/16] fix path issue --- src/svgcanvas/path-actions.js | 81 +++++++++++++++++++---------------- src/svgcanvas/path-method.js | 57 ++---------------------- src/svgcanvas/path.js | 16 +------ src/svgcanvas/selection.js | 4 +- src/svgcanvas/svgcanvas.js | 13 +----- 5 files changed, 53 insertions(+), 118 deletions(-) diff --git a/src/svgcanvas/path-actions.js b/src/svgcanvas/path-actions.js index 39e40878..db99df0e 100644 --- a/src/svgcanvas/path-actions.js +++ b/src/svgcanvas/path-actions.js @@ -17,9 +17,6 @@ import { assignAttributes, getElem, getRotationAngle, snapToGrid, isNullish, getBBox as utilsGetBBox } from './utilities.js'; -import { - isWebkit -} from '../common/browser.js'; let pathActionsContext_ = null; let editorContext_ = null; @@ -61,22 +58,24 @@ export const convertPath = function (pth, toRel) { let x2 = seg.x2 || 0; let y2 = seg.y2 || 0; - const type = seg.pathSegType; - const pathMap = pathActionsContext_.getPathMap(); - let letter = pathMap[type][toRel ? 'toLowerCase' : 'toUpperCase'](); + // const type = seg.pathSegType; + // const pathMap = pathActionsContext_.getPathMap(); + // let letter = pathMap[type][toRel ? 'toLowerCase' : 'toUpperCase'](); + let letter = seg.pathSegTypeAsLetter; - switch (type) { - case 1: // z,Z closepath (Z/z) + switch (letter) { + case 'z': // z,Z closepath (Z/z) + case 'Z': d += 'z'; if (lastM && !toRel) { curx = lastM[0]; cury = lastM[1]; } break; - case 12: // absolute horizontal line (H) + case 'H': // absolute horizontal line (H) x -= curx; // Fallthrough - case 13: // relative horizontal line (h) + case 'h': // relative horizontal line (h) if (toRel) { y = 0; curx += x; @@ -90,10 +89,10 @@ export const convertPath = function (pth, toRel) { // Convert to "line" for easier editing d += pathDSegment(letter, [ [ x, y ] ]); break; - case 14: // absolute vertical line (V) + case 'V': // absolute vertical line (V) y -= cury; // Fallthrough - case 15: // relative vertical line (v) + case 'v': // relative vertical line (v) if (toRel) { x = 0; cury += y; @@ -107,71 +106,81 @@ export const convertPath = function (pth, toRel) { // Convert to "line" for easier editing d += pathDSegment(letter, [ [ x, y ] ]); break; - case 2: // absolute move (M) - case 4: // absolute line (L) - case 18: // absolute smooth quad (T) - case 10: // absolute elliptical arc (A) + case 'M': // absolute move (M) + case 'L': // absolute line (L) + case 'T': // absolute smooth quad (T) x -= curx; y -= cury; // Fallthrough - case 5: // relative line (l) - case 3: // relative move (m) - case 19: // relative smooth quad (t) + case 'l': // relative line (l) + case 'm': // relative move (m) + case 't': // relative smooth quad (t) if (toRel) { curx += x; cury += y; + letter = letter.toLowerCase(); } else { x += curx; y += cury; curx = x; cury = y; + letter = letter.toUpperCase(); } - if (type === 2 || type === 3) { lastM = [ curx, cury ]; } + if (letter === 'm' || letter === 'M') { lastM = [ curx, cury ]; } d += pathDSegment(letter, [ [ x, y ] ]); break; - case 6: // absolute cubic (C) + case 'C': // absolute cubic (C) x -= curx; x1 -= curx; x2 -= curx; y -= cury; y1 -= cury; y2 -= cury; // Fallthrough - case 7: // relative cubic (c) + case 'c': // relative cubic (c) if (toRel) { curx += x; cury += y; + letter = 'c'; } else { x += curx; x1 += curx; x2 += curx; y += cury; y1 += cury; y2 += cury; curx = x; cury = y; + letter = 'C'; } d += pathDSegment(letter, [ [ x1, y1 ], [ x2, y2 ], [ x, y ] ]); break; - case 8: // absolute quad (Q) + case 'Q': // absolute quad (Q) x -= curx; x1 -= curx; y -= cury; y1 -= cury; // Fallthrough - case 9: // relative quad (q) + case 'q': // relative quad (q) if (toRel) { curx += x; cury += y; + letter = 'q'; } else { x += curx; x1 += curx; y += cury; y1 += cury; curx = x; cury = y; + letter = 'Q'; } d += pathDSegment(letter, [ [ x1, y1 ], [ x, y ] ]); break; - // Fallthrough - case 11: // relative elliptical arc (a) + case 'A': + x -= curx; + y -= cury; + // fallthrough + case 'a': // relative elliptical arc (a) if (toRel) { curx += x; cury += y; + letter = 'a'; } else { x += curx; y += cury; curx = x; cury = y; + letter = 'A'; } d += pathDSegment(letter, [ [ seg.r1, seg.r2 ] ], [ seg.angle, @@ -179,19 +188,21 @@ export const convertPath = function (pth, toRel) { (seg.sweepFlag ? 1 : 0) ], [ x, y ]); break; - case 16: // absolute smooth cubic (S) + case 'S': // absolute smooth cubic (S) x -= curx; x2 -= curx; y -= cury; y2 -= cury; // Fallthrough - case 17: // relative smooth cubic (s) + case 's': // relative smooth cubic (s) if (toRel) { curx += x; cury += y; + letter = 's'; } else { x += curx; x2 += curx; y += cury; y2 += cury; curx = x; cury = y; + letter = 'S'; } d += pathDSegment(letter, [ [ x2, y2 ], [ x, y ] ]); break; @@ -1027,8 +1038,8 @@ export const pathActionsMethod = (function () { list.appendItem(newseg); list.appendItem(closer); } else { - pathActionsContext_.insertItemBefore(elem, closer, openPt); - pathActionsContext_.insertItemBefore(elem, newseg, openPt); + list.insertItemBefore(closer, openPt); + list.insertItemBefore(newseg, openPt); } path.init().selectPt(openPt + 1); @@ -1074,7 +1085,7 @@ export const pathActionsMethod = (function () { let num = (index - lastM) - 1; while (num--) { - pathActionsContext_.insertItemBefore(elem, list.getItem(lastM), zSeg); + list.insertItemBefore(list.getItem(lastM), zSeg); } const pt = list.getItem(lastM); @@ -1213,24 +1224,22 @@ export const pathActionsMethod = (function () { let lastM; for (let i = 0; i < len; ++i) { const item = segList.getItem(i); - if (item.pathSegType === 2) { + if (item.pathSegType === 2) { // 2 => M segment type (move to) lastM = item; } - if (item.pathSegType === 1) { + if (item.pathSegType === 1) { // 1 => Z segment type (close path) const prev = segList.getItem(i - 1); if (prev.x !== lastM.x || prev.y !== lastM.y) { // Add an L segment here const newseg = elem.createSVGPathSegLinetoAbs(lastM.x, lastM.y); - pathActionsContext_.insertItemBefore(elem, newseg, i); + segList.insertItemBefore(newseg, i); // Can this be done better? pathActionsMethod.fixEnd(elem); break; } } } - editorContext_ = pathActionsContext_.getEditorContext(); - if (isWebkit()) { editorContext_.resetD(elem); } }, // Can't seem to use `@borrows` here, so using `@see` /** diff --git a/src/svgcanvas/path-method.js b/src/svgcanvas/path-method.js index 1c5c439c..17767a8c 100644 --- a/src/svgcanvas/path-method.js +++ b/src/svgcanvas/path-method.js @@ -15,9 +15,6 @@ import { assignAttributes, getRotationAngle, isNullish, getElem } from './utilities.js'; -import { - supportsPathInsertItemBefore, supportsPathReplaceItem, isWebkit -} from '../common/browser.js'; let pathMethodsContext_ = null; let editorContext_ = null; @@ -31,35 +28,6 @@ export const init = function (pathMethodsContext) { pathMethodsContext_ = pathMethodsContext; }; -/** -* @function module:path.insertItemBefore -* @param {Element} elem -* @param {Segment} newseg -* @param {Integer} index -* @returns {void} -*/ -export const insertItemBeforeMethod = function (elem, newseg, index) { - // Support insertItemBefore on paths for FF2 - const list = elem.pathSegList; - - if (supportsPathInsertItemBefore()) { - list.insertItemBefore(newseg, index); - return; - } - const len = list.numberOfItems; - const arr = []; - for (let i = 0; i < len; i++) { - const curSeg = list.getItem(i); - arr.push(curSeg); - } - list.clear(); - for (let i = 0; i < len; i++) { - if (i === index) { // index + 1 - list.appendItem(newseg); - } - list.appendItem(arr[i]); - } -}; /* eslint-disable max-len */ /** * @function module:path.ptObjToArr @@ -324,25 +292,7 @@ export const replacePathSegMethod = function (type, index, pts, elem) { const func = 'createSVGPathSeg' + pathFuncs[type]; const seg = pth[func](...pts); - if (supportsPathReplaceItem()) { - pth.pathSegList.replaceItem(seg, index); - } else { - const segList = pth.pathSegList; - const len = segList.numberOfItems; - const arr = []; - for (let i = 0; i < len; i++) { - const curSeg = segList.getItem(i); - arr.push(curSeg); - } - segList.clear(); - for (let i = 0; i < len; i++) { - if (i === index) { - segList.appendItem(seg); - } else { - segList.appendItem(arr[i]); - } - } - } + pth.pathSegList.replaceItem(seg, index); }; /** * @function module:path.getSegSelector @@ -775,8 +725,8 @@ export class Path { break; } } - - insertItemBeforeMethod(this.elem, newseg, index); + const list = this.elem.pathSegList; + list.insertItemBefore(newseg, index); } /** @@ -1005,7 +955,6 @@ export class Path { * @returns {void} */ endChanges (text) { - if (isWebkit()) { editorContext_.resetD(this.elem); } const cmd = new ChangeElementCommand(this.elem, { d: this.last_d }, text); editorContext_.endChanges({ cmd, elem: this.elem }); } diff --git a/src/svgcanvas/path.js b/src/svgcanvas/path.js index f5399591..3f2bb1f9 100644 --- a/src/svgcanvas/path.js +++ b/src/svgcanvas/path.js @@ -14,7 +14,7 @@ import { getBBox as utilsGetBBox } from './utilities.js'; import { - init as pathMethodInit, insertItemBeforeMethod, ptObjToArrMethod, getGripPtMethod, + init as pathMethodInit, ptObjToArrMethod, getGripPtMethod, getPointFromGripMethod, addPointGripMethod, getGripContainerMethod, addCtrlGripMethod, getCtrlLineMethod, getPointGripMethod, getControlPointsMethod, replacePathSegMethod, getSegSelectorMethod, Path @@ -103,11 +103,6 @@ let editorContext_ = null; * If the event is "changed", an array of `Element`s is passed; if "selected", a single-item array of `Element` is passed. * @returns {void} */ -/** - * @function module:path.EditorContext#resetD - * @param {SVGPathElement} p - * @returns {void} -*/ /** * Note: This doesn't round to an integer necessarily. * @function module:path.EditorContext#round @@ -263,14 +258,6 @@ pathMethodInit( } ); -/** -* @function module:path.insertItemBefore -* @param {Element} elem -* @param {Segment} newseg -* @param {Integer} index -* @returns {void} -*/ -export const insertItemBefore = insertItemBeforeMethod; /* eslint-disable max-len */ /** * @function module:path.ptObjToArr @@ -801,7 +788,6 @@ pathActionsInit( addCtrlGrip, getCtrlLine, replacePathSeg, - insertItemBefore, getPointFromGrip, getGripPt, getPath_, diff --git a/src/svgcanvas/selection.js b/src/svgcanvas/selection.js index 40e71bf6..4fcde8b0 100644 --- a/src/svgcanvas/selection.js +++ b/src/svgcanvas/selection.js @@ -324,12 +324,14 @@ export const groupSvgElem = function (elem) { * @returns {void} */ export const prepareSvg = function (newDoc) { + svgCanvas.sanitizeSvg(newDoc.documentElement); // convert paths into absolute commands const paths = [ ...newDoc.getElementsByTagNameNS(NS.SVG, 'path') ]; paths.forEach((path) => { - path.setAttribute('d', svgCanvas.pathActions.convertPath(path)); + const convertedPath = svgCanvas.pathActions.convertPath(path); + path.setAttribute('d', convertedPath); svgCanvas.pathActions.fixEnd(path); }); }; diff --git a/src/svgcanvas/svgcanvas.js b/src/svgcanvas/svgcanvas.js index 5549a060..9ee3140e 100644 --- a/src/svgcanvas/svgcanvas.js +++ b/src/svgcanvas/svgcanvas.js @@ -9,7 +9,7 @@ */ import { Canvg as canvg } from 'canvg'; -import 'pathseg'; +import 'pathseg'; // SVGPathSeg Polyfill (see https://github.com/progers/pathseg) import * as pathModule from './path.js'; import * as hstry from './history.js'; @@ -668,16 +668,6 @@ class SvgCanvas { * @see module:path.pathActions */ canvas.pathActions = pathActions; - /** -* @type {module:path.EditorContext#resetD} -*/ - function resetD(p) { - if (typeof pathActions.convertPath === 'function') { - p.setAttribute('d', pathActions.convertPath(p)); - } else if (typeof pathActions.convertPaths === 'function') { - p.setAttribute('d', pathActions.convertPaths(p)); - } - } pathModule.init( /** * @implements {module:path.EditorContext} @@ -686,7 +676,6 @@ class SvgCanvas { selectorManager, // Ok since not changing canvas, // Ok since not changing call, - resetD, round, clearSelection, addToSelection, From 627092f2646c85f6b01f9d89081be3a87494e9dd Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 20 Sep 2021 08:53:01 +0200 Subject: [PATCH 14/16] Update draw.js --- cypress/integration/unit/draw.js | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/integration/unit/draw.js b/cypress/integration/unit/draw.js index 2828ca05..4c1c0021 100644 --- a/cypress/integration/unit/draw.js +++ b/cypress/integration/unit/draw.js @@ -1,3 +1,4 @@ +import 'pathseg'; import { NS } from '../../../instrumented/common/namespaces.js'; import * as draw from '../../../instrumented/svgcanvas/draw.js'; import * as units from '../../../instrumented/common/units.js'; From 91e61503b6880963c05c0533a3edb7389ea4ac8e Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 20 Sep 2021 09:08:56 +0200 Subject: [PATCH 15/16] fix issue with clone layer --- src/editor/extensions/ext-shapes/ext-shapes.js | 8 -------- src/editor/panels/LayersPanel.js | 2 +- src/svgcanvas/copy-elem.js | 9 --------- 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/editor/extensions/ext-shapes/ext-shapes.js b/src/editor/extensions/ext-shapes/ext-shapes.js index 246d43c7..b94f254a 100644 --- a/src/editor/extensions/ext-shapes/ext-shapes.js +++ b/src/editor/extensions/ext-shapes/ext-shapes.js @@ -82,14 +82,6 @@ export default { } }); - /* - // Make sure shape uses absolute values - if ((/[a-z]/).test(currentD)) { - currentD = curLib.data[curShapeId] = canv.pathActions.convertPath(curShape); - curShape.setAttribute('d', currentD); - canv.pathActions.fixEnd(curShape); - } - */ curShape.setAttribute('transform', 'translate(' + x + ',' + y + ') scale(0.005) translate(' + -x + ',' + -y + ')'); canv.recalculateDimensions(curShape); diff --git a/src/editor/panels/LayersPanel.js b/src/editor/panels/LayersPanel.js index 04c59820..31995bfa 100644 --- a/src/editor/panels/LayersPanel.js +++ b/src/editor/panels/LayersPanel.js @@ -11,7 +11,7 @@ class LayersPanel { * @param {PlainObject} editor */ constructor(editor) { - this.updateContextPanel = editor.topPanel.updateContextPanel; + this.updateContextPanel = editor.topPanel.updateContextPanel.bind(editor.topPanel); this.editor = editor; } diff --git a/src/svgcanvas/copy-elem.js b/src/svgcanvas/copy-elem.js index b1eeacc4..cc3f0d38 100644 --- a/src/svgcanvas/copy-elem.js +++ b/src/svgcanvas/copy-elem.js @@ -1,5 +1,3 @@ -import { isWebkit } from '../common/browser.js'; -import { convertPath } from './path.js'; import { preventClickDefault } from './utilities.js'; /** @@ -19,13 +17,6 @@ export const copyElem = function (el, getNextId) { newEl.removeAttribute('id'); newEl.id = getNextId(); - // Opera's "d" value needs to be reset for Opera/Win/non-EN - // Also needed for webkit (else does not keep curved segments on clone) - if (isWebkit() && el.nodeName === 'path') { - const fixedD = convertPath(el); - newEl.setAttribute('d', fixedD); - } - // now create copies of all children el.childNodes.forEach(function(child){ switch (child.nodeType) { From 22cb5f6bf3f10430ddc87593769ef5aeda17834d Mon Sep 17 00:00:00 2001 From: JFH <20402845+jfhenon@users.noreply.github.com> Date: Mon, 20 Sep 2021 09:35:08 +0200 Subject: [PATCH 16/16] Update scenario3.js.snap --- cypress/integration/ui/__snapshots__/scenario3.js.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cypress/integration/ui/__snapshots__/scenario3.js.snap b/cypress/integration/ui/__snapshots__/scenario3.js.snap index 597286a4..c2ba6d17 100644 --- a/cypress/integration/ui/__snapshots__/scenario3.js.snap +++ b/cypress/integration/ui/__snapshots__/scenario3.js.snap @@ -67,7 +67,7 @@ exports[`use all parts of svg-edit > check tool_path_change_node_xy #0`] = ` fill="#FF0000" stroke="#000000" stroke-width="5" - d="M75,75L150,100L125,200L75,75z" + d="M 75 75 L 150 100 L 125 200 L 75 75 z" id="svg_1" fill-opacity="1" stroke-opacity="1" @@ -94,7 +94,7 @@ exports[`use all parts of svg-edit > check tool_path_change_seg_type #0`] = ` fill="#FF0000" stroke="#000000" stroke-width="5" - d="M75,75L150,100L125,200C235.33333,330.33333 91.66667,116.66667 75,75z" + d="M 75 75 L 150 100 L 125 200 C 235.33333333333331 330.33333333333337 91.66666666666667 116.66666666666666 75 75 z" id="svg_1" fill-opacity="1" stroke-opacity="1" @@ -121,7 +121,7 @@ exports[`use all parts of svg-edit > check tool_path_change_clone_node #0`] = ` fill="#FF0000" stroke="#000000" stroke-width="5" - d="M201,246L150,100L125,200C180.16666,265.16666 297.83333,415.33333 273.625,373C249.41667,330.66667 209.33334,266.83334 201,246z" + d="M 201 246 L 150 100 L 125 200 C 180.16666666666666 265.1666666666667 297.8333333333333 415.33333333333337 273.625 373 C 249.41666666666669 330.66666666666663 209.33333333333334 266.8333333333333 201 246 z" id="svg_1" fill-opacity="1" stroke-opacity="1" @@ -148,7 +148,7 @@ exports[`use all parts of svg-edit > check tool_path_openclose #0`] = ` fill="#FF0000" stroke="#000000" stroke-width="5" - d="M201,246L150,100L125,200C180.16666,265.16666 297.83333,415.33333 273.625,373C249.41667,330.66667 209.33334,266.83334 201,246z" + d="M 201 246 L 150 100 L 125 200 C 180.16666666666666 265.1666666666667 297.8333333333333 415.33333333333337 273.625 373 C 249.41666666666669 330.66666666666663 209.33333333333334 266.8333333333333 201 246 z" id="svg_1" fill-opacity="1" stroke-opacity="1"