Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This pull request is an attempt to resolve the issue of IOS not loading images #442

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/dataurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/embed-webfonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function embedFonts(data: Metadata, options: Options): Promise<string> {

return fetchAsDataURL<[string, string]>(
url,
options.fetchRequestInit,
options.fetchFontRequestInit,
({ result }) => {
cssText = cssText.replace(loc, `url(${result})`)
return [loc, result]
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export async function toSvg<T extends HTMLElement>(
): Promise<string> {
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
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ export interface Options {
*
*/
fetchRequestInit?: RequestInit
/**
*
*the second parameter of window.fetch (Promise<Response> fetch(input[, init]))
* This would be used for fonts, thereby making it different from the Image urls of the parent project.
*/
fetchFontRequestInit?: RequestInit
}