puppeteer-render-text
Advanced tools
Comparing version 1.0.0 to 1.0.1
21
index.js
@@ -56,3 +56,3 @@ 'use strict' | ||
const { fontFamily } = style | ||
const { fontFamily = '' } = style | ||
@@ -63,2 +63,8 @@ if (loadGoogleFont && !fontFamily) { | ||
const fonts = loadFontFamily | ||
? [ loadFontFamily ] | ||
: loadGoogleFont | ||
? fontFamily.split(',').map((font) => font.trim()) | ||
: [ ] | ||
const fontHeader = loadFontFamily | ||
@@ -68,13 +74,16 @@ ? observer : ( | ||
${observer} | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=${fontFamily.replace(/ /g, '+')}"> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=${fonts.map((font) => font.replace(/ /g, '+')).join('|')}"> | ||
` : '' | ||
) | ||
const fontLoader = loadFontFamily || loadGoogleFont ? ` | ||
var font = new FontFaceObserver('${loadFontFamily || fontFamily}'); | ||
font.load().then(ready); | ||
` : 'ready();' | ||
const fontsToLoad = fonts.map((font) => `new FontFaceObserver('${font}')`) | ||
const fontLoader = fontsToLoad.length | ||
? `Promise.all([ ${fontsToLoad.join(', ')} ].map((f) => f.load())).then(ready);` | ||
: 'ready();' | ||
const html = ` | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
${inject.head || ''} | ||
@@ -81,0 +90,0 @@ ${fontHeader} |
@@ -113,1 +113,23 @@ 'use strict' | ||
}) | ||
test('"puppeteer-render-text 😊" html with multiple google fonts', async (t) => { | ||
const output0 = tempy.file({ extension: 'png' }) | ||
await renderText({ | ||
text: 'puppeteer-<span style="font-family: \'Permanent Marker\'">render</span>-<span style="color: red">text</span> 😊', | ||
output: output0, | ||
style: { | ||
fontFamily: 'Gloria Hallelujah, Permanent Marker', | ||
fontSize: 40 | ||
}, | ||
loadGoogleFont: true | ||
}) | ||
const image0 = await sharp(output0).metadata() | ||
t.true(inDelta(image0.width, 502, 5)) | ||
t.true(inDelta(image0.height, 79, 3)) | ||
t.is(image0.channels, 4) | ||
t.is(image0.format, 'png') | ||
await rmfr(output0) | ||
}) |
{ | ||
"name": "puppeteer-render-text", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Robust text renderer using headless chrome.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,2 +7,6 @@ # puppeteer-render-text | ||
<p align="center"> | ||
<img width="502" alt="Logo" src="https://cdn.rawgit.com/transitive-bullshit/puppeteer-render-text/master/media/logo.png"> | ||
</p> | ||
## Why? | ||
@@ -78,3 +82,3 @@ | ||
### [renderText](https://github.com/transitive-bullshit/puppeteer-render-text/blob/4047853f4343ada45c331dee7fded3e90d481d34/index.js#L40-L155) | ||
### [renderText](https://github.com/transitive-bullshit/puppeteer-render-text/blob/78fc727089da2932a8364ac7ba6550fed891e215/index.js#L40-L164) | ||
@@ -81,0 +85,0 @@ Renders the given text / html via puppeteer. |
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
34813
10
265
109