@zag-js/dom-query
Advanced tools
Comparing version 0.79.3 to 0.80.0
@@ -19,6 +19,18 @@ interface EventMap extends DocumentEventMap, WindowEventMap, HTMLElementEventMap { | ||
interface DataUrlOptions { | ||
/** | ||
* The type of the image | ||
*/ | ||
type: DataUrlType; | ||
/** | ||
* The quality of the image | ||
* @default 0.92 | ||
*/ | ||
quality?: number | undefined; | ||
/** | ||
* The background color of the canvas. | ||
* Useful when type is `image/jpeg` | ||
*/ | ||
background?: string | undefined; | ||
} | ||
declare function getDataUrl(svg: SVGElement | undefined | null, opts: DataUrlOptions): Promise<string>; | ||
declare function getDataUrl(svg: SVGSVGElement | undefined | null, opts: DataUrlOptions): Promise<string>; | ||
@@ -25,0 +37,0 @@ declare function getDocument(el: Element | Window | Node | Document | null | undefined): Document; |
@@ -72,3 +72,3 @@ 'use strict'; | ||
function getDataUrl(svg, opts) { | ||
const { type, quality = 0.92 } = opts; | ||
const { type, quality = 0.92, background } = opts; | ||
if (!svg) throw new Error("[zag-js > getDataUrl]: Could not find the svg element"); | ||
@@ -79,4 +79,5 @@ const win = getWindow(svg); | ||
const svgClone = svg.cloneNode(true); | ||
svgClone.setAttribute("viewBox", `0 0 ${svgBounds.width} ${svgBounds.height}`); | ||
svg.parentElement.appendChild(svgClone); | ||
if (!svgClone.hasAttribute("viewBox")) { | ||
svgClone.setAttribute("viewBox", `0 0 ${svgBounds.width} ${svgBounds.height}`); | ||
} | ||
const serializer = new win.XMLSerializer(); | ||
@@ -86,3 +87,6 @@ const source = '<?xml version="1.0" standalone="no"?>\r\n' + serializer.serializeToString(svgClone); | ||
if (type === "image/svg+xml") { | ||
return Promise.resolve(svgString); | ||
return Promise.resolve(svgString).then((str) => { | ||
svgClone.remove(); | ||
return str; | ||
}); | ||
} | ||
@@ -96,2 +100,6 @@ const dpr = win.devicePixelRatio || 1; | ||
const context = canvas.getContext("2d"); | ||
if (type === "image/jpeg" || background) { | ||
context.fillStyle = background || "white"; | ||
context.fillRect(0, 0, canvas.width, canvas.height); | ||
} | ||
return new Promise((resolve) => { | ||
@@ -98,0 +106,0 @@ image.onload = () => { |
{ | ||
"name": "@zag-js/dom-query", | ||
"version": "0.79.3", | ||
"version": "0.80.0", | ||
"description": "The dom helper library for zag.js machines", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79753
1702