@effing/canvas 0.28.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,11 +26,24 @@ function cachedLoadImage(cache, src) {
26
26
  if (Buffer.isBuffer(src)) return loadImage(src);
27
27
  let entry = cache.get(src);
28
28
  if (!entry) {
29
- entry = loadImage(src);
29
+ entry = isRemoteUrl(src) ? loadRemoteImage(src) : loadImage(src);
30
30
  cache.set(src, entry);
31
31
  }
32
32
  return entry;
33
33
  }
34
+ function isRemoteUrl(src) {
35
+ return src.startsWith("http://") || src.startsWith("https://");
36
+ }
37
+ async function loadRemoteImage(url) {
38
+ const response = await fetch(url);
39
+ if (!response.ok) {
40
+ throw new Error(
41
+ `Failed to fetch image ${url}: ${response.status} ${response.statusText}`
42
+ );
43
+ }
44
+ const buffer = Buffer.from(await response.arrayBuffer());
45
+ return loadImage(buffer);
46
+ }
34
47
 
35
48
  // src/jsx/style/compute.ts
36
49
  var ROOT_FONT_SIZE = 16;