diff --git a/packages/mindplot/src/components/ImageIcon.js b/packages/mindplot/src/components/ImageIcon.js index 0de0c5ae..fa73ccc8 100644 --- a/packages/mindplot/src/components/ImageIcon.js +++ b/packages/mindplot/src/components/ImageIcon.js @@ -38,7 +38,7 @@ class ImageIcon extends Icon { // Build graph image representation ... const iconType = iconModel.getIconType(); - const imgUrl = ImageIcon._getImageUrl(iconType); + const imgUrl = ImageIcon.getImageUrl(iconType); super(imgUrl); this._topicId = topic.getId(); @@ -53,13 +53,13 @@ class ImageIcon extends Icon { const newIconType = ImageIcon._getNextFamilyIconId(iconTypeClick); iconModel.setIconType(newIconType); - me._image.setHref(ImageIcon._getImageUrl(newIconType)); + me._image.setHref(ImageIcon.getImageUrl(newIconType)); }); this._image.setCursor('pointer'); } } - static _getImageUrl(iconId) { + static getImageUrl(iconId) { let result = images[`${iconId}.svg`]; if (!result) { result = images[`${iconId}.png`]; diff --git a/packages/mindplot/src/components/Workspace.js b/packages/mindplot/src/components/Workspace.js index 8ab2b716..d4490dcf 100644 --- a/packages/mindplot/src/components/Workspace.js +++ b/packages/mindplot/src/components/Workspace.js @@ -16,7 +16,7 @@ * limitations under the License. */ import { $assert, $defined } from '@wisemapping/core-js'; -import { Workspace as Workspace2D, Toolkit } from '@wisemapping/web2d'; +import { Workspace as Workspace2D } from '@wisemapping/web2d'; class Workspace { constructor(screenManager, zoom, isReadOnly) { @@ -64,7 +64,7 @@ class Workspace { fillColor: 'transparent', strokeWidth: 0, }; - Toolkit.init(); + return new Workspace2D(workspaceProfile); } diff --git a/packages/mindplot/src/components/export/SVGExporter.ts b/packages/mindplot/src/components/export/SVGExporter.ts index d67da42e..c3daf1ae 100644 --- a/packages/mindplot/src/components/export/SVGExporter.ts +++ b/packages/mindplot/src/components/export/SVGExporter.ts @@ -1,5 +1,6 @@ import { Mindmap } from "../.."; +import ImageIcon from "../ImageIcon"; import Exporter from "./Exporter"; class SVGExporter implements Exporter { @@ -10,11 +11,13 @@ class SVGExporter implements Exporter { export(): string { // Replace all images for in-line images ... - const imagesElements:HTMLCollection = this.svgElement.children + const imagesElements: HTMLCollection = this.svgElement.getElementsByTagName('image'); console.log(imagesElements.length); - Array.from(imagesElements).forEach((image) => { - console.log(image); + const image = ImageIcon.getImageUrl('face_smile'); + Array.from(imagesElements).forEach((image) => { + const imgValue = image.attributes['xlink:href'].value; + console.log(image.attributes); }); return ""; diff --git a/packages/mindplot/src/components/widget/IconPanel.js b/packages/mindplot/src/components/widget/IconPanel.js index 98e832ba..73f9dc01 100644 --- a/packages/mindplot/src/components/widget/IconPanel.js +++ b/packages/mindplot/src/components/widget/IconPanel.js @@ -43,7 +43,7 @@ class IconPanel extends ToolbarPaneItem { const iconId = familyIcons[j]; const img = $('') .attr('id', iconId) - .attr('src', ImageIcon._getImageUrl(iconId)) + .attr('src', ImageIcon.getImageUrl(iconId)) .attr('class', 'panelIcon'); familyContent.append(img); diff --git a/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts b/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts index 8db9d781..c2937b04 100644 --- a/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts +++ b/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts @@ -5,22 +5,31 @@ import XMLSerializerFactory from '../../../src/components/persistence/XMLSeriali import SVGExporter from '../../../src/components/export/SVGExporter'; test('mindplot generation of simple maps', () => { - const parser = new DOMParser(); - - // Load DOM ... - const mapStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'), { encoding: 'utf-8' }); - const mapDocument = parser.parseFromString(mapStream.toString(), 'text/xml') + // Load mindmap DOM ... + const mindmapPath = path.resolve(__dirname, './samples/welcome.xml'); + const mapDocument = parseXMLFile(mindmapPath, 'text/xml'); // Convert to mindmap ... const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDocument); const mindmap: Mindmap = serializer.loadFromDom(mapDocument, 'welcome'); // Load SVG ... - const svgStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.svg'), { encoding: 'utf-8' }); - const svgDocument = parser.parseFromString(svgStream.toString(), 'application/xml') - console.log(svgDocument); + const svgPath = path.resolve(__dirname, './samples/welcome.svg'); + const svgDocument = parseXMLFile(svgPath, 'image/svg+xml'); // Inspect ... const exporter = new SVGExporter(mindmap, svgDocument.documentElement); console.log(exporter.export()); + + function parseXMLFile(filePath: fs.PathOrFileDescriptor, mimeType: DOMParserSupportedType) { + const parser = new DOMParser(); + const stream = fs.readFileSync(filePath, { encoding: 'utf-8' }); + const xmlDoc = parser.parseFromString(stream.toString(), mimeType); + + // Is there any parsing error ?. + if (xmlDoc.getElementsByTagName("parsererror").length > 0) { + 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 95409e1c..46e95f1d 100644 --- a/packages/mindplot/test/unit/export/samples/welcome.svg +++ b/packages/mindplot/test/unit/export/samples/welcome.svg @@ -1,4 +1,4 @@ - + diff --git a/packages/mindplot/webpack.common.js b/packages/mindplot/webpack.common.js index 188df7a0..f654a0b1 100644 --- a/packages/mindplot/webpack.common.js +++ b/packages/mindplot/webpack.common.js @@ -5,7 +5,6 @@ module.exports = { output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js', - publicPath: '', library: { type: 'umd', }, @@ -35,8 +34,8 @@ module.exports = { exclude: '/node_modules/', }, { - test: /\.(png|svg|jpg|jpeg|gif)$/i, - type: 'asset/resource', + test: /\.(png|svg)$/i, + type: 'asset/inline', }, ], }, diff --git a/packages/web2d/src/index.js b/packages/web2d/src/index.js index a0bf3975..73aada6b 100644 --- a/packages/web2d/src/index.js +++ b/packages/web2d/src/index.js @@ -17,7 +17,6 @@ */ import Workspace from './components/Workspace'; -import Toolkit from './components/Toolkit'; import Elipse from './components/Elipse'; import Line from './components/Line'; import PolyLine from './components/PolyLine'; @@ -42,6 +41,5 @@ export { PolyLine, Rect, Text, - Toolkit, Workspace, }; diff --git a/packages/web2d/test/playground/arrow.js b/packages/web2d/test/playground/arrow.js index 8d8aadcc..a1eb9e29 100644 --- a/packages/web2d/test/playground/arrow.js +++ b/packages/web2d/test/playground/arrow.js @@ -1,22 +1,20 @@ import $ from 'jquery'; import { - Toolkit, Workspace, Arrow, Point, + Workspace, Arrow, Point, } from '../../src'; -Toolkit.init(); - -const overflowWorkspace = new Workspace({ fillColor: 'green' }); -overflowWorkspace.setSize('200px', '200px'); +const workspace = new Workspace({ fillColor: 'green' }); +workspace.setSize('200px', '200px'); const arrow = new Arrow(); arrow.setFrom(50, 50); arrow.setControlPoint(new Point(-50, 0)); -overflowWorkspace.append(arrow); +workspace.append(arrow); const arrow2 = new Arrow(); arrow2.setFrom(100, 50); arrow2.setControlPoint(new Point(50, 50)); -overflowWorkspace.append(arrow2); +workspace.append(arrow2); -overflowWorkspace.addItAsChildTo($('#overflowExample').first()); +workspace.addItAsChildTo($('#overflowExample').first()); diff --git a/packages/web2d/test/playground/curvedLine.js b/packages/web2d/test/playground/curvedLine.js index 265a84c6..8ffd34bd 100644 --- a/packages/web2d/test/playground/curvedLine.js +++ b/packages/web2d/test/playground/curvedLine.js @@ -1,19 +1,17 @@ import $ from 'jquery'; import { - Toolkit, Workspace, CurvedLine, Point, + Workspace, CurvedLine, Point, } from '../../src'; -Toolkit.init(); - -const overflowWorkspace = new Workspace({ fillColor: 'green' }); -overflowWorkspace.setSize('400px', '400px'); +const workspace = new Workspace({ fillColor: 'green' }); +workspace.setSize('400px', '400px'); const line1 = new CurvedLine(); line1.setStyle(CurvedLine.SIMPLE_LINE); line1.setFrom(200, 200); line1.setTo(100, 100); line1.setSrcControlPoint(new Point(-100, 0)); line1.setDestControlPoint(new Point(100, 0)); -overflowWorkspace.append(line1); +workspace.append(line1); const line2 = new CurvedLine(); line2.setStyle(CurvedLine.NICE_LINE); @@ -21,6 +19,6 @@ line2.setFrom(0, 0); line2.setTo(150, 90); line2.setSrcControlPoint(new Point(100, 0)); line2.setDestControlPoint(new Point(-100, 0)); -overflowWorkspace.append(line2); +workspace.append(line2); -overflowWorkspace.addItAsChildTo($('#overflowExample').first()); \ No newline at end of file +workspace.addItAsChildTo($('#overflowExample').first()); \ No newline at end of file diff --git a/packages/web2d/test/playground/events.js b/packages/web2d/test/playground/events.js index c338b49b..f272a5a1 100644 --- a/packages/web2d/test/playground/events.js +++ b/packages/web2d/test/playground/events.js @@ -1,7 +1,7 @@ /* eslint-disable no-alert */ import $ from 'jquery'; import { - Toolkit, Workspace, Elipse, + Workspace, Elipse, } from '../../src'; global.$ = $; @@ -55,7 +55,6 @@ MultipleEventHandler.prototype.unRegisterOneListener = function unRegisterOneLis } }; -Toolkit.init(); // Workspace with CoordOrigin(100,100); const workspace = new Workspace(); diff --git a/packages/web2d/test/playground/font.js b/packages/web2d/test/playground/font.js index 041105b1..442acb00 100644 --- a/packages/web2d/test/playground/font.js +++ b/packages/web2d/test/playground/font.js @@ -25,14 +25,14 @@ function multiline(text, family, elemId) { } function alignments(text, family, elemId) { - const overflowWorkspace = new Workspace(); - overflowWorkspace.setSize('260px', '240px'); - overflowWorkspace.setCoordSize('260', '240'); - overflowWorkspace.setCoordOrigin(0, 0); + const workspace = new Workspace(); + workspace.setSize('260px', '240px'); + workspace.setCoordSize('260', '240'); + workspace.setCoordOrigin(0, 0); ['center', 'left', 'right'].forEach((align, i) => { const wText = new Text(); - overflowWorkspace.append(wText); + workspace.append(wText); wText.setText(text); wText.setFont(family, 8, 'bold'); @@ -41,11 +41,9 @@ function alignments(text, family, elemId) { wText.setTextAlignment(align); }); - overflowWorkspace.addItAsChildTo($(`#${elemId}`)); + workspace.addItAsChildTo($(`#${elemId}`)); } -Toolkit.init(); - // Multine tests ... ['Arial', 'Tahoma', 'Verdana', 'Times'].forEach((family, i) => { multiline('This multine text.\nLine 1 :)\nLine2', family, `multi${i}`); diff --git a/packages/web2d/test/playground/group.js b/packages/web2d/test/playground/group.js index 7440dd64..5c57d09c 100644 --- a/packages/web2d/test/playground/group.js +++ b/packages/web2d/test/playground/group.js @@ -6,8 +6,6 @@ import { global.$ = $; -Toolkit.init(); - const basicTest = () => { const workspace = new Workspace(); workspace.setSize('150px', '150px'); diff --git a/packages/web2d/test/playground/image.html b/packages/web2d/test/playground/image.html new file mode 100644 index 00000000..150360b3 --- /dev/null +++ b/packages/web2d/test/playground/image.html @@ -0,0 +1,33 @@ + + + + + + + + + + Image Tests + + + + + + Load URL Images in PNG and SVG + + + + + + + Load Inline PNG and SVG + + + + + + + + + + \ No newline at end of file diff --git a/packages/web2d/test/playground/image.js b/packages/web2d/test/playground/image.js new file mode 100644 index 00000000..235a6499 --- /dev/null +++ b/packages/web2d/test/playground/image.js @@ -0,0 +1,28 @@ +import $ from 'jquery'; +import svgResource from './resources/logo-icon.svg'; +import pngResource from './resources/logo-icon.png'; + +import { + Workspace, Image, +} from '../../src'; + +// URL Based image test ... +const workspace = new Workspace({ fillColor: 'light-gray' }); +workspace.setSize('200px', '100px'); + +// Add SVG Image ... +const svgImage = new Image(); +svgImage.setHref(svgResource); +svgImage.setSize(80, 120); +workspace.append(svgImage); + +// Add PNG Image ... +const pngImage = new Image(); +pngImage.setHref(pngResource); +pngImage.setSize(60, 120); +pngImage.setPosition(80, 0); +workspace.append(pngImage); + +workspace.addItAsChildTo($('#urlImage').first()); + +// Embedded image test ... diff --git a/packages/web2d/test/playground/index.html b/packages/web2d/test/playground/index.html index 161e95c8..f9207e23 100644 --- a/packages/web2d/test/playground/index.html +++ b/packages/web2d/test/playground/index.html @@ -24,6 +24,8 @@ Shapes Text Workspace + Image +