Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit b3e61f5

Browse files
brianokeefemarkdalgleish
authored andcommitted
feat(viewports): Add support for custom pixel densities (#25)
1 parent 57bfa9b commit b3e61f5

File tree

5 files changed

+1740
-30
lines changed

5 files changed

+1740
-30
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ $ html-sketchapp --viewports.Desktop 1024x768 --viewports.Mobile 320x568 --file
110110

111111
If multiple screen sizes are provided, the viewport name will be being appended to all symbol and text style names. For example, `Button/Primary` will be exported as `Button/Primary/Desktop` and `Button/Primary/Mobile`.
112112

113+
Optionally, you can set the pixel density for a given viewport by adding an `@` followed by the desired scaling factor to the end of the viewport's resolution. For example, you can simulate a 1.5x and 2x display like so:
114+
115+
```bash
116+
$ html-sketchapp --viewports.HigherDensity [email protected] --viewports.Retina 1024x768@2 --file sketch.html --out-dir dist
117+
```
118+
119+
If no scaling factor is provided, a default of `1` will be used.
120+
113121
### Puppeteer args
114122

115123
If you need to provide command line arguments to the browser instance via [Puppeteer](https://github.com/GoogleChrome/puppeteer), you can provide the `puppeteer-args` option.

bin/cli.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ require('yargs')
9696
for (const viewportName in viewports) {
9797
if (viewports.hasOwnProperty(viewportName)) {
9898
const viewport = viewports[viewportName];
99-
const [ width, height ] = viewport.split('x').map(x => parseInt(x, 10));
100-
await page.setViewport({ width, height });
99+
const [ size, scale ] = viewport.split('@');
100+
const [ width, height ] = size.split('x').map(x => parseInt(x, 10));
101+
const deviceScaleFactor = typeof scale === 'undefined' ? 1 : parseFloat(scale);
102+
await page.setViewport({ width, height, deviceScaleFactor });
101103
await page.evaluate(`generateAlmostSketch.snapshotTextStyles({ suffix: "${hasViewports ? `/${viewportName}` : ''}" })`);
102104
await page.evaluate(`generateAlmostSketch.snapshotSymbols({ suffix: "${hasViewports ? `/${viewportName}` : ''}" })`);
103105
}

0 commit comments

Comments
 (0)