From 2e96b38f5c310b2ba340c0469fede43ccebc6255 Mon Sep 17 00:00:00 2001 From: Urama Charles Date: Tue, 5 Dec 2023 09:50:35 +0100 Subject: [PATCH 1/4] This is to correct the error with IOS not loading images --- src/embed-webfonts.ts | 2 +- src/types.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/embed-webfonts.ts b/src/embed-webfonts.ts index 42c73da6..4c11f9bf 100644 --- a/src/embed-webfonts.ts +++ b/src/embed-webfonts.ts @@ -37,7 +37,7 @@ async function embedFonts(data: Metadata, options: Options): Promise { return fetchAsDataURL<[string, string]>( url, - options.fetchRequestInit, + options.fetchFontRequestInit, ({ result }) => { cssText = cssText.replace(loc, `url(${result})`) return [loc, result] diff --git a/src/types.ts b/src/types.ts index b511363f..a2d64a24 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,4 +91,10 @@ export interface Options { * */ fetchRequestInit?: RequestInit + /** + * + *the second parameter of window.fetch (Promise fetch(input[, init])) + * This would be used for fonts, thereby making it different from the Image urls of the parent project. + */ + fetchFontRequestInit?: RequestInit } From dbd99f085156c369dd070e675e10434fea0c6450 Mon Sep 17 00:00:00 2001 From: Urama Charles Date: Tue, 5 Dec 2023 09:52:22 +0100 Subject: [PATCH 2/4] This is to correct the error with IOS not loading images --- src/embed-webfonts.ts | 2 +- src/types.ts | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/embed-webfonts.ts b/src/embed-webfonts.ts index 4c11f9bf..42c73da6 100644 --- a/src/embed-webfonts.ts +++ b/src/embed-webfonts.ts @@ -37,7 +37,7 @@ async function embedFonts(data: Metadata, options: Options): Promise { return fetchAsDataURL<[string, string]>( url, - options.fetchFontRequestInit, + options.fetchRequestInit, ({ result }) => { cssText = cssText.replace(loc, `url(${result})`) return [loc, result] diff --git a/src/types.ts b/src/types.ts index a2d64a24..b511363f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,10 +91,4 @@ export interface Options { * */ fetchRequestInit?: RequestInit - /** - * - *the second parameter of window.fetch (Promise fetch(input[, init])) - * This would be used for fonts, thereby making it different from the Image urls of the parent project. - */ - fetchFontRequestInit?: RequestInit } From de875e4ca1f25752d4b50fb721448842afa5b964 Mon Sep 17 00:00:00 2001 From: Urama Charles Date: Tue, 5 Dec 2023 09:53:58 +0100 Subject: [PATCH 3/4] This is to correct the error with IOS not loading images --- src/embed-webfonts.ts | 2 +- src/types.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/embed-webfonts.ts b/src/embed-webfonts.ts index 42c73da6..4c11f9bf 100644 --- a/src/embed-webfonts.ts +++ b/src/embed-webfonts.ts @@ -37,7 +37,7 @@ async function embedFonts(data: Metadata, options: Options): Promise { return fetchAsDataURL<[string, string]>( url, - options.fetchRequestInit, + options.fetchFontRequestInit, ({ result }) => { cssText = cssText.replace(loc, `url(${result})`) return [loc, result] diff --git a/src/types.ts b/src/types.ts index b511363f..7395f69b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -91,4 +91,10 @@ export interface Options { * */ fetchRequestInit?: RequestInit + /** + * + *the second parameter of window.fetch (Promise fetch(input[, init])) + * This would be used for fonts, thereby making it different from the Image urls of the parent project. + */ + fetchFontRequestInit?: RequestInit } From 0fb224261833201c29ddbfcaf05911e2cc341e33 Mon Sep 17 00:00:00 2001 From: Urama Charles Date: Wed, 6 Dec 2023 16:30:47 +0100 Subject: [PATCH 4/4] To return the cached file only if the cacheBurst is false --- src/dataurl.ts | 9 +++++---- src/index.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dataurl.ts b/src/dataurl.ts index 13bc8b43..dbe1cc9b 100644 --- a/src/dataurl.ts +++ b/src/dataurl.ts @@ -69,14 +69,15 @@ export async function resourceToDataURL( options.includeQueryParams, ) - if (cache[cacheKey] != null) { - return cache[cacheKey] - } - + // ref: https://developer.mozilla.org/en/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Bypassing_the_cache if (options.cacheBust) { // eslint-disable-next-line no-param-reassign resourceUrl += (/\?/.test(resourceUrl) ? '&' : '?') + new Date().getTime() + }else{ + if (cache[cacheKey] != null) { + return cache[cacheKey] + } } let dataURL: string diff --git a/src/index.ts b/src/index.ts index 2de59a30..0e66907e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,8 +18,8 @@ export async function toSvg( ): Promise { const { width, height } = getImageSize(node, options) const clonedNode = (await cloneNode(node, options, true)) as HTMLElement - await embedWebFonts(clonedNode, options) await embedImages(clonedNode, options) + await embedWebFonts(clonedNode, options) applyStyle(clonedNode, options) const datauri = await nodeToDataURL(clonedNode, width, height) return datauri