Replace viewport units in CSS

In theory it could do something much more complicated. But it seems
better to just say "vh and vw are not supported", and this would just
be failing more gracefully.

I mean, the spec itself says,

> Keep in mind that some Reading Systems will not support all desired
> features of CSS. In particular, the following are known to be
> problematic [...] Pagination is sometimes done using columns, which
> can result in incorrect values for viewport sizes.

Fixes #1
This commit is contained in:
John Factotum
2022-10-22 21:50:47 +00:00
committed by GitHub
parent 21bf6499a4
commit 37ccb74238
+6 -1
View File
@@ -530,7 +530,12 @@ class Loader {
/@import\s*["']([^"'\n]*?)["']/gi,
(_, url) => this.loadHref(url, href, parents)
.then(url => `@import "${url}"`))
return replacedImports.replaceAll('-epub-', '')
const w = window?.innerWidth ?? 800
const h = window?.innerHeight ?? 600
const replacedVwVh = replacedImports
.replace(/(\d*\.?\d+)vw/g, (_, d) => parseFloat(d) * w / 100 + 'px')
.replace(/(\d*\.?\d+)vh/g, (_, d) => parseFloat(d) * h / 100 + 'px')
return replacedVwVh.replaceAll('-epub-', '')
}
// find & replace all possible relative paths for all assets without parsing
replaceString(str, href, parents = []) {