diff --git a/src/clone-node.ts b/src/clone-node.ts index 683f7f30..60c27883 100644 --- a/src/clone-node.ts +++ b/src/clone-node.ts @@ -170,7 +170,11 @@ function cloneSelectValue(nativeNode: T, clonedNode: T) { } } -function decorate(nativeNode: T, clonedNode: T, usePageCss?: boolean): T { +function decorate( + nativeNode: T, + clonedNode: T, + usePageCss?: boolean, +): T { if (isInstanceOfElement(clonedNode, Element)) { if (!usePageCss) cloneCSSStyle(nativeNode, clonedNode) if (!usePageCss) clonePseudoElements(nativeNode, clonedNode) diff --git a/src/index.ts b/src/index.ts index 323d6694..372ee105 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ import { Options } from './types' import { cloneNode } from './clone-node' -//import { embedImages } from './embed-images' +// import { embedImages } from './embed-images' import { applyStyle } from './apply-style' -//import { embedWebFonts, getWebFontCSS } from './embed-webfonts' +// import { embedWebFonts, getWebFontCSS } from './embed-webfonts' import { getImageSize, getPixelRatio, - createImage, canvasToBlob, nodeToDataURL, checkCanvasDimensions, getDimensionLimit, + svgUrlToImg, } from './util' export async function toSvg( @@ -19,10 +19,15 @@ 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) + // await embedImages(clonedNode, options) applyStyle(clonedNode, options) - const datauri = await nodeToDataURL(clonedNode, width, height, options.usePageCss) + const datauri = await nodeToDataURL( + clonedNode, + width, + height, + options, + ) return datauri } @@ -31,7 +36,7 @@ export async function toImage( options: Options = {}, ): Promise { const svg = await toSvg(node, options) - return createImage(svg) + return svgUrlToImg(svg, options) } export async function toCanvas( @@ -39,7 +44,7 @@ export async function toCanvas( options: Options = {}, ): Promise { const img = await toImage(node, options) - const { width, height } = getImageSize(node, options) + const { width, height } = getImageSize(node, options, img) const canvas = document.createElement('canvas') const context = canvas.getContext('2d')! const ratio = options.pixelRatio || getPixelRatio() @@ -70,7 +75,7 @@ export async function toCanvasList( options: Options = {}, ): Promise> { const img = await toImage(node, options) - const { width, height } = getImageSize(node, options) + const { width, height } = getImageSize(node, options, img) const ratio = options.pixelRatio || getPixelRatio() let canvasWidth = (options.canvasWidth || width) * ratio let canvasHeight = (options.canvasHeight || height) * ratio diff --git a/src/types.ts b/src/types.ts index d5616f42..2b4c20fd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -95,5 +95,10 @@ export interface Options { * Use a