Open duncanmak opened 1 year ago
The problem seems to be the import of fontkit - that's a dependency of svgdom.
Maybe the import has to be changed 🤔. Not sure tho. Usually people just use the package by installing into hide modules
Deno also has npm support, so I tried it: Some types don't import the same (probably another bug)
import { SVG, registerWindow, Rect } from "npm:@svgdotjs/svg.js@3.2.0";
import svgdom from "npm:svgdom@0.1.14";
Deno.test("svg", () => {
const window = svgdom.createSVGWindow();
const document = window.document;
// register window and document
registerWindow(window, document);
// create canvas
const canvas = SVG(document.documentElement);
// canvas.rect(100, 100);
new Rect().size(100, 100).addTo(canvas);
console.log('hello', canvas.svg());
assertEquals(canvas.svg(), "");
});
It seems a little better, but I think the same problem is still there:
❯ deno test .\tests\canvas.test.ts
ok | 0 passed | 0 failed (875ms)
error: Could not find npm package 'iconv-lite' referenced by 'fontkit@1.9.0'.
Maybe using fontkit 2.0.0 will make this work better?
I just made this PR: https://github.com/svgdotjs/svgdom/pull/107
I wonder if that's the trick to solve the issue I mentioned here.
Looks like this is also necessary for svgdom to work in Deno:
Adding an explicit import of iconv-lite seems to be a workaround for now (modified version of @duncanmak 's example):
import "npm:iconv-lite@0.6.3";
import { SVG, registerWindow, Rect } from "npm:@svgdotjs/svg.js@3.2.0";
import * as svgdom from "npm:svgdom@0.1.14";
import { assertEquals } from "https://deno.land/std@0.201.0/assert/mod.ts";
Deno.test("svg", () => {
const window = svgdom.createSVGWindow();
const document = window.document;
registerWindow(window, document);
const canvas = SVG(document.documentElement);
new Rect().size(100, 100).addTo(canvas);
assertEquals(
canvas.svg(),
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs"><rect width="100" height="100"></rect></svg>'
);
});
My code looks like this:
I get this error:
Is there a problem with the ESM file?