Skip to content

Commit

Permalink
feat: 1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunchang committed Apr 28, 2024
1 parent d455d63 commit 455235c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.6 - 2024-04-28

### Features

* fetch options


## 1.0.5 - 2024-04-09

### Features
Expand Down
10 changes: 5 additions & 5 deletions lib/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ declare global {
* Images that reference another SVG are inlined by inlining the embedded SVG into the output SVG.
* Note: The passed element needs to be attached to a document with a window (`defaultView`) for this so that `getComputedStyle()` can be used.
*/
export async function inlineResources(element: Element): Promise<void> {
export async function inlineResources(element: Element, fetchOptions?: RequestInit): Promise<void> {
await Promise.all([
...[...element.children].map(inlineResources),
...[...element.children].map(child => inlineResources(child, fetchOptions)),
(async () => {
if (isSVGImageElement(element)) {
const elementHref = element.getAttribute('href') || element.getAttribute('xlink:href')
assert(elementHref, 'Expected <image> element to have an href or xlink:href attribute')
const blob = await withTimeout(10000, `Timeout fetching ${elementHref}`, () =>
fetchResource(elementHref))
fetchResource(elementHref, fetchOptions))
if (blob.type === 'image/svg+xml') {
// If the image is an SVG, inline it into the output SVG.
// Some tools (e.g. Figma) do not support nested SVG.
Expand Down Expand Up @@ -137,10 +137,10 @@ async function inlineCssFontUrlArgumentNode(
}
}

export async function fetchResource(url: string): Promise<Blob> {
export async function fetchResource(url: string, options?: RequestInit): Promise<Blob> {
assert(url, 'No URL passed')
const headers = new Headers()
const response = await fetch(url, { headers })
const response = await fetch(url, { headers, ...options })
if (!response.ok)
throw new Error(response.statusText)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dom2svg",
"type": "module",
"version": "1.0.5",
"version": "1.0.6",
"description": "Take SVG screenshots of DOM elements",
"author": "xiashui",
"license": "MIT",
Expand Down

0 comments on commit 455235c

Please sign in to comment.