@@ -10,7 +10,7 @@ export interface SnapParams {
10
10
// TODO Deno puppeteer types
11
11
export type PuppeteerLaunchOptions = any ;
12
12
13
- export async function snap ( snaps : SnapParams [ ] , options ?: { snapServerUrl ?: string , puppeteerLaunchOptions ?: PuppeteerLaunchOptions } ) {
13
+ export async function snap ( snaps : SnapParams [ ] , options ?: { snapServerUrl ?: string , theme ?: any , puppeteerLaunchOptions ?: PuppeteerLaunchOptions } ) {
14
14
const { listen, abort} = startServer ( ) ;
15
15
16
16
const browser = await puppeteer . launch ( options ?. puppeteerLaunchOptions || {
@@ -23,14 +23,24 @@ export async function snap(snaps: SnapParams[], options?: {snapServerUrl?: strin
23
23
const page = await browser . newPage ( ) ;
24
24
25
25
for ( let textCase of snaps ) {
26
- page . setViewport ( { deviceScaleFactor : 3 , width : 1080 , height : 30 , ...textCase . viewport } ) ;
26
+ const viewPort = { deviceScaleFactor : 3 , width : 1080 , height : 30 , ...textCase . viewport } ;
27
+ // TODO handle headless looking different
28
+ // if(typeof options?.puppeteerLaunchOptions?.headless === "boolean" && !options.puppeteerLaunchOptions.headless) {
29
+ // viewPort.width += 15;
30
+ // }
31
+ page . setViewport ( viewPort ) ;
32
+
33
+ let postData : any = { text : encodeURI ( textCase . content ) } ;
34
+ if ( options ?. theme ) {
35
+ postData . theme = JSON . stringify ( options . theme ) ;
36
+ }
27
37
28
38
await page . setRequestInterception ( true ) ;
29
39
30
40
page . once ( "request" , async interceptedRequest => {
31
41
await interceptedRequest . continue ( {
32
42
method : "POST" ,
33
- postData : `{"text": " ${ encodeURI ( textCase . content ) } "}` ,
43
+ postData : JSON . stringify ( postData ) ,
34
44
headers : {
35
45
...interceptedRequest . headers ( ) ,
36
46
"Content-Type" : "application/json"
0 commit comments