Skip to content

Commit

Permalink
Fix page breaks
Browse files Browse the repository at this point in the history
Replace `page-break-*` with `-webkit-column-break-*`.

See johnfactotum/foliate#962 (comment)
  • Loading branch information
johnfactotum authored Feb 21, 2023
1 parent 07a8b76 commit b804995
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,15 @@ class Loader {
.then(url => `@import "${url}"`))
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-', '')
return replacedImports
// unprefix as most of the props are (only) supported unprefixed
.replace(/-epub-/gi, '')
// replace vw and vh as they cause problems with layout
.replace(/(\d*\.?\d+)vw/gi, (_, d) => parseFloat(d) * w / 100 + 'px')
.replace(/(\d*\.?\d+)vh/gi, (_, d) => parseFloat(d) * h / 100 + 'px')
// `page-break-*` unsupported in columns; replace with `column-break-*`
.replace(/page-break-(after|before|inside)/gi, (_, x) =>
`-webkit-column-break-${x}`)
}
// find & replace all possible relative paths for all assets without parsing
replaceString(str, href, parents = []) {
Expand Down

0 comments on commit b804995

Please sign in to comment.