SVG-Edit / svgedit

Powerful SVG-Editor for your browser
MIT License
6.33k stars 1.52k forks source link

Make SvgCanvas class accessible from bundle #964

Closed delmohf closed 2 months ago

delmohf commented 2 months ago

I'm using the bundle version of svgedit (as a package npm i svgedit), and I wanna use convertUnit utility which was defined in the module packages/svgcanvas/core/units.js and attached to SvgCanvas class so I thought it should be used as below:

import SvgCanvas from '@svgedit/svgcanvas';
SvgCanvas.convertUnit(38, 'cm');

but the following error arised:

image

getRoundDigits (or even getBaseUnit if I just call SvgCanvas.convertUnit(38)) is a method of SvgCanvas instance created by EditorStartup during initialization and consequently injected to the module units.js.

The problem is that the instance of SvgCanvas is actually in the bundle, not in @svgedit/svgcanvas.

I fixed this issue in a simple way, just re-exporting SvgCanvas from Editor.js as show in this pull request but there could be other ways.

delmohf commented 2 months ago

I found that utility function convertUnit was not added to svgCanvas instance which looks like the proper behaviour because the opposite operation convertToNum was indeed added so check my PR #965 which seems a more suitable solution.