@lesjoursfr/html-to-image
Advanced tools
Comparing version 1.0.0 to 1.0.1
/// <reference types="node" /> | ||
import { URL } from "url"; | ||
interface OperationResult { | ||
error: string | undefined; | ||
result: "ok" | undefined; | ||
} | ||
export declare enum HtmlToImageOutputType { | ||
@@ -11,2 +7,10 @@ png = "png", | ||
} | ||
export interface HtmlToImageOptions { | ||
xvfb: boolean; | ||
xvfbArgs: string | undefined; | ||
} | ||
export interface OperationResult { | ||
error: string | undefined; | ||
result: "ok" | undefined; | ||
} | ||
export declare class HtmlToImage { | ||
@@ -17,5 +21,6 @@ url: URL; | ||
outputType: HtmlToImageOutputType; | ||
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType); | ||
options: HtmlToImageOptions; | ||
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType, options?: HtmlToImageOptions); | ||
private command; | ||
render(): Promise<OperationResult>; | ||
} | ||
export {}; |
@@ -9,2 +9,7 @@ "use strict"; | ||
const script = (0, path_1.resolve)(__dirname, "./electron.js"); | ||
var HtmlToImageOutputType; | ||
(function (HtmlToImageOutputType) { | ||
HtmlToImageOutputType["png"] = "png"; | ||
HtmlToImageOutputType["jpeg"] = "jpeg"; | ||
})(HtmlToImageOutputType || (exports.HtmlToImageOutputType = HtmlToImageOutputType = {})); | ||
function cleanOutput(std) { | ||
@@ -23,7 +28,2 @@ // We look for a line that contains a valid JSON string | ||
} | ||
var HtmlToImageOutputType; | ||
(function (HtmlToImageOutputType) { | ||
HtmlToImageOutputType["png"] = "png"; | ||
HtmlToImageOutputType["jpeg"] = "jpeg"; | ||
})(HtmlToImageOutputType || (exports.HtmlToImageOutputType = HtmlToImageOutputType = {})); | ||
class HtmlToImage { | ||
@@ -34,3 +34,4 @@ url; | ||
outputType; | ||
constructor(url, output, selector, outputType) { | ||
options; | ||
constructor(url, output, selector, outputType, options) { | ||
// Required options | ||
@@ -41,6 +42,13 @@ this.url = url; | ||
this.outputType = outputType ?? HtmlToImageOutputType.jpeg; | ||
this.options = options || { xvfb: false, xvfbArgs: undefined }; | ||
} | ||
command() { | ||
if (this.options.xvfb) { | ||
return `xvfb-run ${this.options.xvfbArgs || ""} node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`; | ||
} | ||
return `node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`; | ||
} | ||
async render() { | ||
// Render the Image | ||
const command = `node ${require.resolve("electron/cli.js")} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`; | ||
// Render the PDF | ||
const command = this.command(); | ||
const { stdout } = await execp(command); | ||
@@ -47,0 +55,0 @@ // Clean output |
{ | ||
"name": "@lesjoursfr/html-to-image", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A library to generate images from HTML.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -9,3 +9,13 @@ import { exec } from "child_process"; | ||
interface OperationResult { | ||
export enum HtmlToImageOutputType { | ||
png = "png", | ||
jpeg = "jpeg", | ||
} | ||
export interface HtmlToImageOptions { | ||
xvfb: boolean; | ||
xvfbArgs: string | undefined; | ||
} | ||
export interface OperationResult { | ||
error: string | undefined; | ||
@@ -28,7 +38,2 @@ result: "ok" | undefined; | ||
export enum HtmlToImageOutputType { | ||
png = "png", | ||
jpeg = "jpeg", | ||
} | ||
export class HtmlToImage { | ||
@@ -39,4 +44,11 @@ url: URL; | ||
outputType: HtmlToImageOutputType; | ||
options: HtmlToImageOptions; | ||
constructor(url: URL, output: string, selector: string, outputType?: HtmlToImageOutputType) { | ||
constructor( | ||
url: URL, | ||
output: string, | ||
selector: string, | ||
outputType?: HtmlToImageOutputType, | ||
options?: HtmlToImageOptions | ||
) { | ||
// Required options | ||
@@ -47,9 +59,20 @@ this.url = url; | ||
this.outputType = outputType ?? HtmlToImageOutputType.jpeg; | ||
this.options = options || { xvfb: false, xvfbArgs: undefined }; | ||
} | ||
async render(): Promise<OperationResult> { | ||
// Render the Image | ||
const command = `node ${require.resolve( | ||
private command(): string { | ||
if (this.options.xvfb) { | ||
return `xvfb-run ${this.options.xvfbArgs || ""} node ${require.resolve( | ||
"electron/cli.js" | ||
)} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`; | ||
} | ||
return `node ${require.resolve( | ||
"electron/cli.js" | ||
)} --no-sandbox ${script} --target ${this.url.toString()} --output ${this.output} --selector ${this.selector} --output-image-type ${this.outputType}`; | ||
} | ||
async render(): Promise<OperationResult> { | ||
// Render the PDF | ||
const command = this.command(); | ||
const { stdout } = await execp(command); | ||
@@ -56,0 +79,0 @@ |
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
14375
319