@zag-js/dom-query
Advanced tools
Comparing version 0.54.0 to 0.55.0
@@ -11,2 +11,9 @@ type Booleanish = boolean | "true" | "false"; | ||
type DataUrlType = "image/png" | "image/jpeg" | "image/svg+xml"; | ||
interface DataUrlOptions { | ||
type: DataUrlType; | ||
quality?: number; | ||
} | ||
declare function getDataUrl(svg: SVGElement | undefined | null, opts: DataUrlOptions): Promise<string>; | ||
declare function getDocument(el: Element | Window | Node | Document | null): Document; | ||
@@ -145,3 +152,3 @@ declare function getDocumentElement(el: Element | Node | Window | Document | null): HTMLElement; | ||
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => boolean; | ||
getById: <T_1 extends HTMLElement = HTMLElement>(ctx: ScopeContext, id: string) => T_1 | null; | ||
getById: <T_1 extends Element = HTMLElement>(ctx: ScopeContext, id: string) => T_1 | null; | ||
setValue: <T_2 extends { | ||
@@ -214,2 +221,2 @@ value: string; | ||
export { type InitialFocusOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type ScopeContext, type ScrollOptions, type ScrollPosition, type TypeaheadOptions, type TypeaheadState, ariaAttr, contains, createScope, dataAttr, defaultItemToId, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDocument, getDocumentElement, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getScrollPosition, getTabbableEdges, getTabbables, getWindow, indexOfId, isApple, isComposingEvent, isDocument, isDom, isDownloadingEvent, isEditableElement, isFirefox, isFocusable, isHTMLElement, isHiddenElement, isInView, isIos, isMac, isModKey, isNode, isOpeningInNewTab, isOverflowElement, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isValidTabEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, raf, scrollIntoView, set, setAttribute, setProperty, setStyle, visuallyHiddenStyle, waitForElement, waitForElements }; | ||
export { type DataUrlOptions, type DataUrlType, type InitialFocusOptions, type ItemToId, MAX_Z_INDEX, type ObserveAttributeOptions, type ObserveChildrenOptions, type OverflowAncestor, type ScopeContext, type ScrollOptions, type ScrollPosition, type TypeaheadOptions, type TypeaheadState, ariaAttr, contains, createScope, dataAttr, defaultItemToId, getActiveElement, getBeforeInputValue, getByText, getByTypeahead, getComputedStyle, getDataUrl, getDocument, getDocumentElement, getEventTarget, getFirstFocusable, getFirstTabbable, getFocusables, getInitialFocus, getLastTabbable, getNearestOverflowAncestor, getNextTabbable, getNodeName, getOverflowAncestors, getParentNode, getPlatform, getScrollPosition, getTabbableEdges, getTabbables, getWindow, indexOfId, isApple, isComposingEvent, isDocument, isDom, isDownloadingEvent, isEditableElement, isFirefox, isFocusable, isHTMLElement, isHiddenElement, isInView, isIos, isMac, isModKey, isNode, isOpeningInNewTab, isOverflowElement, isRootElement, isSafari, isSelfTarget, isShadowRoot, isTabbable, isTouchDevice, isValidTabEvent, isVisualViewport, isWebKit, isWindow, itemById, nextById, nextTick, observeAttributes, observeChildren, prevById, proxyTabFocus, query, queryAll, raf, scrollIntoView, set, setAttribute, setProperty, setStyle, visuallyHiddenStyle, waitForElement, waitForElements }; |
@@ -34,2 +34,3 @@ "use strict"; | ||
getComputedStyle: () => getComputedStyle, | ||
getDataUrl: () => getDataUrl, | ||
getDocument: () => getDocument, | ||
@@ -167,2 +168,32 @@ getDocumentElement: () => getDocumentElement, | ||
// src/data-url.ts | ||
function getDataUrl(svg, opts) { | ||
const { type, quality = 0.92 } = opts; | ||
if (!svg) | ||
throw new Error("[get-data-url]: could not find the svg element"); | ||
const win = getWindow(svg); | ||
const doc = win.document; | ||
const serializer = new win.XMLSerializer(); | ||
const source = '<?xml version="1.0" standalone="no"?>\r\n' + serializer.serializeToString(svg); | ||
const svgString = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(source); | ||
if (type === "image/svg+xml") { | ||
return Promise.resolve(svgString); | ||
} | ||
const svgBounds = svg.getBoundingClientRect(); | ||
const dpr = win.devicePixelRatio || 1; | ||
const canvas = doc.createElement("canvas"); | ||
const image = new win.Image(); | ||
image.src = svgString; | ||
canvas.width = svgBounds.width * dpr; | ||
canvas.height = svgBounds.height * dpr; | ||
const context = canvas.getContext("2d"); | ||
context.scale(dpr, dpr); | ||
return new Promise((resolve) => { | ||
image.onload = () => { | ||
context.drawImage(image, 0, 0); | ||
resolve(canvas.toDataURL(type, quality)); | ||
}; | ||
}); | ||
} | ||
// src/platform.ts | ||
@@ -825,2 +856,3 @@ var isDom = () => typeof document !== "undefined"; | ||
getComputedStyle, | ||
getDataUrl, | ||
getDocument, | ||
@@ -827,0 +859,0 @@ getDocumentElement, |
{ | ||
"name": "@zag-js/dom-query", | ||
"version": "0.54.0", | ||
"version": "0.55.0", | ||
"description": "The dom helper library for zag.js machines", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
export * from "./attrs" | ||
export * from "./constants" | ||
export * from "./contains" | ||
export * from "./data-url" | ||
export * from "./env" | ||
@@ -5,0 +6,0 @@ export * from "./event" |
@@ -14,3 +14,3 @@ import { getDocument } from "./env" | ||
isActiveElement: (ctx: ScopeContext, elem: HTMLElement | null) => elem === screen.getActiveElement(ctx), | ||
getById: <T extends HTMLElement = HTMLElement>(ctx: ScopeContext, id: string) => | ||
getById: <T extends Element = HTMLElement>(ctx: ScopeContext, id: string) => | ||
screen.getRootNode(ctx).getElementById(id) as T | null, | ||
@@ -17,0 +17,0 @@ setValue: <T extends { value: string }>(elem: T | null, value: string | number | null | undefined) => { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
211325
42
2705