mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Mitigate fixed-layout exception on render when there's no available source for blankWidth and blankHeight (#70)
This commit is contained in:
+7
-4
@@ -106,18 +106,19 @@ export class FixedLayout extends HTMLElement {
|
|||||||
#render(side = this.#side) {
|
#render(side = this.#side) {
|
||||||
if (!side) return
|
if (!side) return
|
||||||
const left = this.#left ?? {}
|
const left = this.#left ?? {}
|
||||||
const right = this.#center ?? this.#right
|
const right = this.#center ?? this.#right ?? {}
|
||||||
const target = side === 'left' ? left : right
|
const target = side === 'left' ? left : right
|
||||||
const { width, height } = this.getBoundingClientRect()
|
const { width, height } = this.getBoundingClientRect()
|
||||||
const portrait = this.spread !== 'both' && this.spread !== 'portrait'
|
const portrait = this.spread !== 'both' && this.spread !== 'portrait'
|
||||||
&& height > width
|
&& height > width
|
||||||
this.#portrait = portrait
|
this.#portrait = portrait
|
||||||
const blankWidth = left.width ?? right.width
|
const blankWidth = left.width ?? right.width ?? 0
|
||||||
const blankHeight = left.height ?? right.height
|
const blankHeight = left.height ?? right.height ?? 0
|
||||||
|
|
||||||
const scale = typeof this.#zoom === 'number' && !isNaN(this.#zoom)
|
const scale = typeof this.#zoom === 'number' && !isNaN(this.#zoom)
|
||||||
? this.#zoom
|
? this.#zoom
|
||||||
: this.#zoom === 'fit-width' ? (portrait || this.#center
|
: (this.#zoom === 'fit-width'
|
||||||
|
? (portrait || this.#center
|
||||||
? width / (target.width ?? blankWidth)
|
? width / (target.width ?? blankWidth)
|
||||||
: width / ((left.width ?? blankWidth) + (right.width ?? blankWidth)))
|
: width / ((left.width ?? blankWidth) + (right.width ?? blankWidth)))
|
||||||
: (portrait || this.#center
|
: (portrait || this.#center
|
||||||
@@ -129,9 +130,11 @@ export class FixedLayout extends HTMLElement {
|
|||||||
height / Math.max(
|
height / Math.max(
|
||||||
left.height ?? blankHeight,
|
left.height ?? blankHeight,
|
||||||
right.height ?? blankHeight)))
|
right.height ?? blankHeight)))
|
||||||
|
) || 1;
|
||||||
|
|
||||||
const transform = frame => {
|
const transform = frame => {
|
||||||
let { element, iframe, width, height, blank, onZoom } = frame
|
let { element, iframe, width, height, blank, onZoom } = frame
|
||||||
|
if (!iframe) return;
|
||||||
if (onZoom) onZoom({ doc: frame.iframe.contentDocument, scale })
|
if (onZoom) onZoom({ doc: frame.iframe.contentDocument, scale })
|
||||||
const iframeScale = onZoom ? scale : 1
|
const iframeScale = onZoom ? scale : 1
|
||||||
Object.assign(iframe.style, {
|
Object.assign(iframe.style, {
|
||||||
|
|||||||
Reference in New Issue
Block a user