Closed claws closed 1 year ago
This is sort of strange, because you should not need the brokenPath2D when you have esm support, the brokenPath2D is a polyfill for old versions of Internet Explorer that cant draw SVG paths to the canvas, so it is strange to see that you get this behavior.
Have you tried having a look at the included esm sample? https://github.com/spatialillusions/milsymbol/blob/master/examples/es6-import/index.html Live version https://spatialillusions.com/milsymbol/examples/es6-import/
I can see that it isn't working as it should when you haven't loaded the necessary functions, but otherwise it works fine.
I did look at the esm example you pointed out. I used that same file in the sequence of steps I attached that show how to reproduce the problem I observe.
The live version you point out uses the package source code (index.esm.js
) not the bundled dist/milsymbol.esm.js
which is why it does not exhibit the problem. If you swap the live example to use the bundled version (dist/milsymbol.esm.js
) I think you would see exactly what I see.
I agree that the _brokenPath2D
should not be used when Path2D exists. However, the code in the asCanvas
function tries to write to the _brokenPath2D
property even when Path2D
exists. That is the root cause of the problem when using the bundled version (dist/milsymbol.esm.js
) of the package in which the ms
object is frozen.
Should be fixed in the version just published to NPM, otherwise let me know.
I'm trying to use the bundled ESM version of milsymbol (
dist/milsymbol.esm.js
) provided in the NPM package but I encounter an error when trying to create a milsymbol usingasCanvas
.The error I see is:
I have tried Chrome and Safari browser. I could not find any existing open issues that were similar.
After a little investigation I found that at the end of the
dist/milsymbol.esm.js
file there is a linelet milsymbol = Object.freeze(ms);
. Freeze prevents any modification to thems
object. So, later when the demo tries to run theasCanvas
function there is a line that confirms Path2D is working. The linems._brokenPath2D = !(data == "0,0,0,255");
fails because_brokenPath2D
is not an existing property ofms
and could not be modified even if it were.I'm relatively new to JavaScript development so perhaps the way I'm trying to use this package is not supported. I'd like to use the prebuilt bundled version if possible. I'm trying to use ES6 style imports.
Should I be able to use the
dist/milsymbol.esm.js
file provided in the milsymbol npm package?Below is the simplest way I can show you how to reproduce the issue I observe.
Fetch the milsymbol es6 example to use as a local demo.
Modify
index.html
file to use the bundled ESM filedist/milsymbol.esm.js
that comes in the milsymbol npm package.Change
index.html
line 55 from:to:
Install and run a simple web server to serve the
index.html
file.View results in your browser.
I expect to see 4 icons (two properly displayed and two with an upside down question mark). I see only one icon (the first SVG icon) and the browser Dev Tools shows the following error: