mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Improve layout for vertical writing
- Make horizontal padding grow with `gap` - Make `maxColumnWidth` limit inline width, not horizontal width
This commit is contained in:
+23
-12
@@ -357,6 +357,7 @@ export class Paginator {
|
|||||||
this.createOverlayer = createOverlayer
|
this.createOverlayer = createOverlayer
|
||||||
Object.assign(this.#element.style, {
|
Object.assign(this.#element.style, {
|
||||||
boxSizing: 'border-box',
|
boxSizing: 'border-box',
|
||||||
|
display: 'flex',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
@@ -377,7 +378,6 @@ export class Paginator {
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
margin: 'auto',
|
margin: 'auto',
|
||||||
position: 'relative',
|
|
||||||
})
|
})
|
||||||
this.#maxSizeContainer.append(this.#container)
|
this.#maxSizeContainer.append(this.#container)
|
||||||
Object.assign(this.#container.style, {
|
Object.assign(this.#container.style, {
|
||||||
@@ -389,6 +389,7 @@ export class Paginator {
|
|||||||
const marginalStyle = {
|
const marginalStyle = {
|
||||||
position: 'absolute', left: '0', right: '0',
|
position: 'absolute', left: '0', right: '0',
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
|
margin: 'auto',
|
||||||
}
|
}
|
||||||
Object.assign(this.#header.style, marginalStyle)
|
Object.assign(this.#header.style, marginalStyle)
|
||||||
Object.assign(this.#footer.style, marginalStyle)
|
Object.assign(this.#footer.style, marginalStyle)
|
||||||
@@ -430,6 +431,7 @@ export class Paginator {
|
|||||||
this.#element.style.padding = '0'
|
this.#element.style.padding = '0'
|
||||||
this.#container.style.overflow ='scroll'
|
this.#container.style.overflow ='scroll'
|
||||||
this.#maxSizeContainer.style.maxWidth = 'none'
|
this.#maxSizeContainer.style.maxWidth = 'none'
|
||||||
|
this.#maxSizeContainer.style.maxHeight = 'none'
|
||||||
const columnWidth = this.layout.maxColumnWidth
|
const columnWidth = this.layout.maxColumnWidth
|
||||||
|
|
||||||
const { width, height } = this.#container.getBoundingClientRect()
|
const { width, height } = this.#container.getBoundingClientRect()
|
||||||
@@ -444,7 +446,9 @@ export class Paginator {
|
|||||||
return { flow, margin, gap, columnWidth }
|
return { flow, margin, gap, columnWidth }
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#maxSizeContainer.style.maxWidth = `${maxColumns * maxColumnWidth}px`
|
const maxSize = `${maxColumns * maxColumnWidth}px`
|
||||||
|
this.#maxSizeContainer.style.maxWidth = vertical ? 'none' : maxSize
|
||||||
|
this.#maxSizeContainer.style.maxHeight = vertical ? maxSize : 'none'
|
||||||
|
|
||||||
if (this.#shouldUpdateGap) {
|
if (this.#shouldUpdateGap) {
|
||||||
this.#shouldUpdateGap = false
|
this.#shouldUpdateGap = false
|
||||||
@@ -452,12 +456,16 @@ export class Paginator {
|
|||||||
const size = vertical ? height : width
|
const size = vertical ? height : width
|
||||||
const gap = Math.trunc(gape * size)
|
const gap = Math.trunc(gape * size)
|
||||||
|
|
||||||
const paddingH = `${vertical ? gap : gap / 2}px`
|
const paddingH = `${vertical
|
||||||
const paddingV = `${vertical ? margin - gap / 2 : margin}px`
|
? Math.min(margin, Math.trunc(gape * width))
|
||||||
|
: gap / 2}px`
|
||||||
|
const paddingV = `${vertical
|
||||||
|
? Math.max(margin - gap / 2, gap / 2)
|
||||||
|
: margin}px`
|
||||||
this.#gap = gap
|
this.#gap = gap
|
||||||
this.#element.style.padding = `${paddingV} ${paddingH}`
|
this.#element.style.padding = `${paddingV} ${paddingH}`
|
||||||
this.#header.style.top = `-${paddingV}`
|
this.#header.style.padding = `0 ${paddingH}`
|
||||||
this.#footer.style.bottom = `-${paddingV}`
|
this.#footer.style.padding = `0 ${paddingH}`
|
||||||
|
|
||||||
const newRect = this.#container.getBoundingClientRect()
|
const newRect = this.#container.getBoundingClientRect()
|
||||||
const newSize = vertical ? newRect.height : newRect.width
|
const newSize = vertical ? newRect.height : newRect.width
|
||||||
@@ -476,16 +484,19 @@ export class Paginator {
|
|||||||
this.#element.setAttribute('dir', rtl ? 'rtl' : 'ltr')
|
this.#element.setAttribute('dir', rtl ? 'rtl' : 'ltr')
|
||||||
this.#container.style.overflow ='hidden'
|
this.#container.style.overflow ='hidden'
|
||||||
|
|
||||||
|
const marginalDivisor = vertical
|
||||||
|
? Math.min(2, Math.ceil(width / maxColumnWidth))
|
||||||
|
: divisor
|
||||||
const marginalStyle = {
|
const marginalStyle = {
|
||||||
|
maxWidth: vertical ? 'none' : maxSize,
|
||||||
height: `${margin}px`,
|
height: `${margin}px`,
|
||||||
gridTemplateColumns: `repeat(${divisor}, 1fr)`,
|
gridTemplateColumns: `repeat(${marginalDivisor}, 1fr)`,
|
||||||
gap: `${gap}px`,
|
gap: `${gap}px`,
|
||||||
padding: `0 ${gap / 2}px`,
|
|
||||||
}
|
}
|
||||||
Object.assign(this.#header.style, marginalStyle)
|
Object.assign(this.#header.style, marginalStyle, { top: 0 })
|
||||||
Object.assign(this.#footer.style, marginalStyle)
|
Object.assign(this.#footer.style, marginalStyle, { bottom: 0 })
|
||||||
const heads = makeMarginals(divisor)
|
const heads = makeMarginals(marginalDivisor)
|
||||||
const feet = makeMarginals(divisor)
|
const feet = makeMarginals(marginalDivisor)
|
||||||
this.heads = heads.map(el => el.children[0])
|
this.heads = heads.map(el => el.children[0])
|
||||||
this.feet = feet.map(el => el.children[0])
|
this.feet = feet.map(el => el.children[0])
|
||||||
this.#header.replaceChildren(...heads)
|
this.#header.replaceChildren(...heads)
|
||||||
|
|||||||
Reference in New Issue
Block a user