From f774a8a0c968326e1abbbf8766cd22900147e0d5 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 30 Dec 2021 15:03:59 -0800 Subject: [PATCH] Fix web2d patch issue --- .../src/components/PersistenceManager.js | 4 +- .../src/components/export/SVGExporter.ts | 15 +++-- .../persistence/XMLSerializerBeta.js | 14 +---- .../persistence/XMLSerializerPela.js | 12 ---- .../unit/export/SVGExporterTestSuite.test.ts | 5 +- .../test/unit/export/samples/welcome.svg | 55 ++++++++++--------- packages/web2d/src/components/Text.js | 2 +- packages/web2d/src/components/Toolkit.js | 4 -- .../src/components/peer/svg/ArrowPeer.js | 2 +- .../src/components/peer/svg/CurvedLinePeer.js | 24 ++++---- .../src/components/peer/svg/ElementPeer.js | 8 +-- .../web2d/src/components/peer/svg/Font.js | 2 +- .../src/components/peer/svg/GroupPeer.js | 4 +- .../web2d/src/components/peer/svg/RectPeer.js | 7 ++- .../src/components/peer/svg/WorkspacePeer.js | 5 +- .../components/peer/utils/TransformUtils.js | 4 +- 16 files changed, 72 insertions(+), 95 deletions(-) diff --git a/packages/mindplot/src/components/PersistenceManager.js b/packages/mindplot/src/components/PersistenceManager.js index 92fcc19e..e53fb370 100644 --- a/packages/mindplot/src/components/PersistenceManager.js +++ b/packages/mindplot/src/components/PersistenceManager.js @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { $assert, innerXML } from '@wisemapping/core-js'; +import { $assert } from '@wisemapping/core-js'; import XMLSerializerFactory from './persistence/XMLSerializerFactory'; class PersistenceManager { @@ -29,7 +29,7 @@ class PersistenceManager { const serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap); const domMap = serializer.toXML(mindmap); - const mapXml = innerXML(domMap); + const mapXml = new XMLSerializer().serializeToString(domMap); const pref = JSON.stringify(editorProperties); try { diff --git a/packages/mindplot/src/components/export/SVGExporter.ts b/packages/mindplot/src/components/export/SVGExporter.ts index c3daf1ae..14c1b9a1 100644 --- a/packages/mindplot/src/components/export/SVGExporter.ts +++ b/packages/mindplot/src/components/export/SVGExporter.ts @@ -1,6 +1,5 @@ import { Mindmap } from "../.."; -import ImageIcon from "../ImageIcon"; import Exporter from "./Exporter"; class SVGExporter implements Exporter { @@ -12,14 +11,14 @@ class SVGExporter implements Exporter { export(): string { // Replace all images for in-line images ... const imagesElements: HTMLCollection = this.svgElement.getElementsByTagName('image'); - console.log(imagesElements.length); + let result:string = new XMLSerializer().serializeToString(this.svgElement); - const image = ImageIcon.getImageUrl('face_smile'); - Array.from(imagesElements).forEach((image) => { - const imgValue = image.attributes['xlink:href'].value; - console.log(image.attributes); - }); - return ""; + // Are namespace declared ?. Otherwise, force the declaration ... + if(result.indexOf('xmlns=')!=-1){ + result.replace(' { // Inspect ... const exporter = new SVGExporter(mindmap, svgDocument.documentElement); - console.log(exporter.export()); + console.log('Exported map:' + exporter.export()); + function parseXMLFile(filePath: fs.PathOrFileDescriptor, mimeType: DOMParserSupportedType) { const parser = new DOMParser(); @@ -28,8 +29,10 @@ test('mindplot generation of simple maps', () => { // Is there any parsing error ?. if (xmlDoc.getElementsByTagName("parsererror").length > 0) { + console.log(new XMLSerializer().serializeToString(xmlDoc)); throw new Error(`Unexpected error parsing: ${filePath}. Error: ${new XMLSerializer().serializeToString(xmlDoc)}`); } + return xmlDoc; } }); diff --git a/packages/mindplot/test/unit/export/samples/welcome.svg b/packages/mindplot/test/unit/export/samples/welcome.svg index 46e95f1d..d0060a40 100644 --- a/packages/mindplot/test/unit/export/samples/welcome.svg +++ b/packages/mindplot/test/unit/export/samples/welcome.svg @@ -1,6 +1,6 @@ - + - + @@ -29,7 +29,7 @@ - + @@ -41,19 +41,20 @@ Welcome To WiseMapping - + - - - - - 5 min tutorial video ? - Follow the link ! + + + + + 5 min tutorial video ? + Follow the link ! - - - + + + + @@ -64,7 +65,7 @@ Try it Now! - + @@ -112,7 +113,7 @@ Links to Sites - + @@ -159,7 +160,7 @@ Icons - + @@ -170,7 +171,7 @@ History Changes - + @@ -181,7 +182,7 @@ Mind Mapping - + @@ -228,7 +229,7 @@ Productivity - + @@ -239,7 +240,7 @@ Share your ideas - + @@ -268,7 +269,7 @@ Install In Your Server - + @@ -279,8 +280,8 @@ Open Source - - + + @@ -291,7 +292,7 @@ Download - + @@ -302,7 +303,7 @@ Collaborate - + @@ -331,7 +332,7 @@ Share for Edition - + @@ -339,5 +340,5 @@ - + \ No newline at end of file diff --git a/packages/web2d/src/components/Text.js b/packages/web2d/src/components/Text.js index bfadc459..1df94ce6 100644 --- a/packages/web2d/src/components/Text.js +++ b/packages/web2d/src/components/Text.js @@ -90,7 +90,7 @@ class Text extends ElementClass { } getHeight() { - return parseInt(this.peer.getHeight(), 10); + return Number.parseInt(this.peer.getHeight(), 10); } getFontHeight() { diff --git a/packages/web2d/src/components/Toolkit.js b/packages/web2d/src/components/Toolkit.js index 067ca6c7..22bdf3d4 100644 --- a/packages/web2d/src/components/Toolkit.js +++ b/packages/web2d/src/components/Toolkit.js @@ -31,10 +31,6 @@ import VerdanaFont from './peer/svg/VerdanaFont'; import TahomaFont from './peer/svg/TahomaFont'; class Toolkit { - static init() { - - } - static createWorkspace(element) { return new WorkspacePeer(element); } diff --git a/packages/web2d/src/components/peer/svg/ArrowPeer.js b/packages/web2d/src/components/peer/svg/ArrowPeer.js index e3d15a9d..ae84416e 100644 --- a/packages/web2d/src/components/peer/svg/ArrowPeer.js +++ b/packages/web2d/src/components/peer/svg/ArrowPeer.js @@ -104,7 +104,7 @@ class ArrowPeer extends ElementPeer { yp = x3 === 0 ? l * Math.sign(y3) : mp * xp; const path = `M${this._fromPoint.x},${this._fromPoint.y} ` - + `L${x + this._fromPoint.x},${y + this._fromPoint.y}M${this._fromPoint.x},${this._fromPoint.y + + `L${x + this._fromPoint.x},${y + this._fromPoint.y} M${this._fromPoint.x},${this._fromPoint.y } ` + `L${xp + this._fromPoint.x},${yp + this._fromPoint.y}`; this._native.setAttribute('d', path); diff --git a/packages/web2d/src/components/peer/svg/CurvedLinePeer.js b/packages/web2d/src/components/peer/svg/CurvedLinePeer.js index 923b232b..ffc41236 100644 --- a/packages/web2d/src/components/peer/svg/CurvedLinePeer.js +++ b/packages/web2d/src/components/peer/svg/CurvedLinePeer.js @@ -37,8 +37,8 @@ class CurvedLinePeer extends ElementPeer { const change = this._control1.x !== control.x || this._control1.y !== control.y; if ($defined(control.x)) { this._control1 = control; - this._control1.x = Number.parseInt(this._control1.x, 10); - this._control1.y = Number.parseInt(this._control1.y, 10); + this._control1.x = Number.parseFloat(this._control1.x, 10); + this._control1.y = Number.parseFloat(this._control1.y, 10); } if (change) { this._updatePath(); @@ -50,8 +50,8 @@ class CurvedLinePeer extends ElementPeer { const change = this._control2.x !== control.x || this._control2.y !== control.y; if ($defined(control.x)) { this._control2 = control; - this._control2.x = Number.parseInt(this._control2.x, 10); - this._control2.y = Number.parseInt(this._control2.y, 10); + this._control2.x = Number.parseFloat(this._control2.x, 10); + this._control2.y = Number.parseFloat(this._control2.y, 10); } if (change) this._updatePath(); } @@ -77,16 +77,16 @@ class CurvedLinePeer extends ElementPeer { } setFrom(x1, y1) { - const change = this._x1 !== parseInt(x1, 10) || this._y1 !== parseInt(y1, 10); - this._x1 = Number.parseInt(x1, 10); - this._y1 = Number.parseInt(y1, 10); + const change = this._x1 !== Number.parseFloat(x1, 10) || this._y1 !== Number.parseFloat(y1, 10); + this._x1 = Number.parseFloat(x1, 10); + this._y1 = Number.parseFloat(y1, 10); if (change) this._updatePath(); } setTo(x2, y2) { - const change = this._x2 !== parseInt(x2, 10) || this._y2 !== parseInt(y2, 10); - this._x2 = Number.parseInt(x2, 10); - this._y2 = Number.parseInt(y2, 10); + const change = this._x2 !== Number.parseFloat(x2, 10) || this._y2 !== parseFloat(y2, 10); + this._x2 = Number.parseFloat(x2, 10); + this._y2 = Number.parseFloat(y2, 10); if (change) this._updatePath(); } @@ -196,8 +196,8 @@ class CurvedLinePeer extends ElementPeer { const y2 = m * (x2 - tarPos.x) + tarPos.y; return [ - new Point(Number.toFixed(-srcPos.x + x1, 5), Number.toFixed(-srcPos.y + y1), 5), - new Point(Number.toFixed(-tarPos.x + x2, 5), Number.toFixed(-tarPos.y + y2, 5)), + new Point(-srcPos.x + x1, -srcPos.y + y1), + new Point(-tarPos.x + x2, -tarPos.y + y2), ]; } diff --git a/packages/web2d/src/components/peer/svg/ElementPeer.js b/packages/web2d/src/components/peer/svg/ElementPeer.js index fa8759f4..9b9de31d 100644 --- a/packages/web2d/src/components/peer/svg/ElementPeer.js +++ b/packages/web2d/src/components/peer/svg/ElementPeer.js @@ -120,13 +120,13 @@ class ElementPeer { } setSize(width, height) { - if ($defined(width) && this._size.width !== parseInt(width, 10)) { - this._size.width = parseInt(width, 10); + if ($defined(width) && this._size.width !== Number.parseFloat(width, 10)) { + this._size.width = Number.parseFloat(width, 10); this._native.setAttribute('width', this._size.width); } - if ($defined(height) && this._size.height !== parseInt(height, 10)) { - this._size.height = parseInt(height, 10); + if ($defined(height) && this._size.height !== Number.parseFloat(height, 10)) { + this._size.height = Number.parseFloat(height, 10); this._native.setAttribute('height', this._size.height); } diff --git a/packages/web2d/src/components/peer/svg/Font.js b/packages/web2d/src/components/peer/svg/Font.js index c5b88a3c..0d341805 100644 --- a/packages/web2d/src/components/peer/svg/Font.js +++ b/packages/web2d/src/components/peer/svg/Font.js @@ -57,7 +57,7 @@ class Font { } getSize() { - return parseInt(this._size, 10); + return Number.parseInt(this._size, 10); } getStyle() { diff --git a/packages/web2d/src/components/peer/svg/GroupPeer.js b/packages/web2d/src/components/peer/svg/GroupPeer.js index a799b9fa..1f052f8d 100644 --- a/packages/web2d/src/components/peer/svg/GroupPeer.js +++ b/packages/web2d/src/components/peer/svg/GroupPeer.js @@ -132,11 +132,11 @@ class GroupPeer extends ElementPeer { setPosition(x, y) { const change = x !== this._position.x || y !== this._position.y; if ($defined(x)) { - this._position.x = parseInt(x, 10); + this._position.x = Number.parseFloat(x, 10); } if ($defined(y)) { - this._position.y = parseInt(y, 10); + this._position.y = Number.parseFloat(y, 10); } if (change) { this.updateTransform(); diff --git a/packages/web2d/src/components/peer/svg/RectPeer.js b/packages/web2d/src/components/peer/svg/RectPeer.js index 71e224af..6a5d17bf 100644 --- a/packages/web2d/src/components/peer/svg/RectPeer.js +++ b/packages/web2d/src/components/peer/svg/RectPeer.js @@ -31,22 +31,23 @@ class RectPeer extends ElementPeer { setPosition(x, y) { if ($defined(x)) { - this._native.setAttribute('x', parseInt(x, 10)); + this._native.setAttribute('x', Number.parseFloat(x, 10)); } if ($defined(y)) { - this._native.setAttribute('y', parseInt(y, 10)); + this._native.setAttribute('y', Number.parseFloat(y, 10)); } } getPosition() { const x = this._native.getAttribute('x'); const y = this._native.getAttribute('y'); - return { x: parseInt(x, 10), y: parseInt(y, 10) }; + return { x: Number.parseFloat(x, 10), y: Number.parseFloat(y, 10) }; } setSize(width, height) { super.setSize(width, height); const min = width < height ? width : height; + if ($defined(this._arc)) { // Transform percentages to SVG format. const arc = (min / 2) * this._arc; diff --git a/packages/web2d/src/components/peer/svg/WorkspacePeer.js b/packages/web2d/src/components/peer/svg/WorkspacePeer.js index 21201dcc..2632a335 100644 --- a/packages/web2d/src/components/peer/svg/WorkspacePeer.js +++ b/packages/web2d/src/components/peer/svg/WorkspacePeer.js @@ -51,16 +51,17 @@ class WorkspacePeer extends ElementPeer { setCoordSize(width, height) { const viewBox = this._native.getAttribute('viewBox'); + let coords = [0, 0, 0, 0]; if (viewBox != null) { coords = viewBox.split(/ /); } if ($defined(width)) { - coords[2] = width; + coords[2] = width.toFixed(5); } if ($defined(height)) { - coords[3] = height; + coords[3] = height.toFixed(5); } this._native.setAttribute('viewBox', coords.join(' ')); diff --git a/packages/web2d/src/components/peer/utils/TransformUtils.js b/packages/web2d/src/components/peer/utils/TransformUtils.js index 06b65762..96a2b209 100644 --- a/packages/web2d/src/components/peer/utils/TransformUtils.js +++ b/packages/web2d/src/components/peer/utils/TransformUtils.js @@ -25,8 +25,8 @@ const TransformUtil = { const coordSize = current.getCoordSize(); const size = current.getSize(); - width *= parseInt(size.width, 10) / coordSize.width; - height *= parseInt(size.height, 10) / coordSize.height; + width *= Number.parseFloat(size.width, 10) / coordSize.width; + height *= Number.parseFloat(size.height, 10) / coordSize.height; current = current.getParent(); } return { width, height };