2021-09-24 14:32:38 +02:00
|
|
|
<template>
|
2022-02-09 18:19:02 +01:00
|
|
|
<div ref="wrapper" :style="{ height: height + 'px', width: width + 'px' }" class="relative">
|
2021-09-26 22:34:08 +02:00
|
|
|
<div v-if="noValidCovers" class="absolute top-0 left-0 w-full h-full flex items-center justify-center box-shadow-book" :style="{ padding: `${sizeMultiplier}rem` }">
|
2021-09-24 14:32:38 +02:00
|
|
|
<p :style="{ fontSize: sizeMultiplier + 'rem' }">{{ name }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
2021-12-02 22:49:03 +01:00
|
|
|
id: String,
|
2021-09-24 14:32:38 +02:00
|
|
|
name: String,
|
|
|
|
bookItems: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
|
|
|
width: Number,
|
2021-10-30 03:42:28 +02:00
|
|
|
height: Number,
|
2021-12-02 22:49:03 +01:00
|
|
|
bookCoverAspectRatio: Number
|
2021-09-24 14:32:38 +02:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
noValidCovers: false,
|
2021-10-29 02:34:29 +02:00
|
|
|
coverDiv: null,
|
|
|
|
isHovering: false,
|
2021-10-30 03:42:28 +02:00
|
|
|
coverWrapperEl: null,
|
2021-10-29 02:34:29 +02:00
|
|
|
coverImageEls: [],
|
|
|
|
coverWidth: 0,
|
|
|
|
offsetIncrement: 0,
|
2021-10-30 03:42:28 +02:00
|
|
|
isFannedOut: false,
|
|
|
|
isDetached: false,
|
2021-11-04 23:35:59 +01:00
|
|
|
isAttaching: false,
|
2021-12-02 22:49:03 +01:00
|
|
|
isInit: false
|
2021-09-24 14:32:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
bookItems: {
|
|
|
|
immediate: true,
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
// ensure wrapper is initialized
|
|
|
|
this.$nextTick(this.init)
|
|
|
|
}
|
|
|
|
}
|
2022-04-30 00:43:46 +02:00
|
|
|
},
|
|
|
|
width: {
|
|
|
|
handler(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.isInit = false
|
|
|
|
this.$nextTick(this.init)
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 14:32:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
sizeMultiplier() {
|
2021-12-02 22:49:03 +01:00
|
|
|
if (this.bookCoverAspectRatio === 1) return this.width / (120 * 1.6 * 2)
|
|
|
|
return this.width / 240
|
2021-10-30 03:42:28 +02:00
|
|
|
},
|
2021-12-01 03:02:40 +01:00
|
|
|
store() {
|
|
|
|
return this.$store || this.$nuxt.$store
|
|
|
|
},
|
|
|
|
router() {
|
|
|
|
return this.$router || this.$nuxt.$router
|
2021-09-24 14:32:38 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getCoverUrl(book) {
|
2022-03-14 01:34:31 +01:00
|
|
|
return this.store.getters['globals/getLibraryItemCoverSrc'](book, '')
|
2021-09-24 14:32:38 +02:00
|
|
|
},
|
2021-10-29 02:34:29 +02:00
|
|
|
async buildCoverImg(coverData, bgCoverWidth, offsetLeft, zIndex, forceCoverBg = false) {
|
|
|
|
var src = coverData.coverUrl
|
|
|
|
|
2021-09-24 14:32:38 +02:00
|
|
|
var showCoverBg =
|
|
|
|
forceCoverBg ||
|
|
|
|
(await new Promise((resolve) => {
|
|
|
|
var image = new Image()
|
|
|
|
|
|
|
|
image.onload = () => {
|
|
|
|
var { naturalWidth, naturalHeight } = image
|
|
|
|
var aspectRatio = naturalHeight / naturalWidth
|
2021-12-02 22:49:03 +01:00
|
|
|
var arDiff = Math.abs(aspectRatio - this.bookCoverAspectRatio)
|
2021-09-24 14:32:38 +02:00
|
|
|
|
|
|
|
// If image aspect ratio is <= 1.45 or >= 1.75 then use cover bg, otherwise stretch to fit
|
|
|
|
if (arDiff > 0.15) {
|
|
|
|
resolve(true)
|
|
|
|
} else {
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
image.onerror = (err) => {
|
|
|
|
console.error(err)
|
|
|
|
resolve(false)
|
|
|
|
}
|
|
|
|
image.src = src
|
|
|
|
}))
|
|
|
|
|
|
|
|
var imgdiv = document.createElement('div')
|
|
|
|
imgdiv.style.height = this.height + 'px'
|
|
|
|
imgdiv.style.width = bgCoverWidth + 'px'
|
|
|
|
imgdiv.style.left = offsetLeft + 'px'
|
2021-10-29 02:34:29 +02:00
|
|
|
imgdiv.style.zIndex = zIndex
|
|
|
|
imgdiv.dataset.audiobookId = coverData.id
|
|
|
|
imgdiv.dataset.volumeNumber = coverData.volumeNumber || ''
|
|
|
|
imgdiv.className = 'absolute top-0 box-shadow-book transition-transform'
|
|
|
|
imgdiv.style.boxShadow = '4px 0px 4px #11111166'
|
2021-09-24 14:32:38 +02:00
|
|
|
// imgdiv.style.transform = 'skew(0deg, 15deg)'
|
|
|
|
|
|
|
|
if (showCoverBg) {
|
|
|
|
var coverbgwrapper = document.createElement('div')
|
2021-12-04 00:05:13 +01:00
|
|
|
coverbgwrapper.className = 'absolute top-0 left-0 w-full h-full overflow-hidden rounded-sm bg-primary'
|
2021-09-24 14:32:38 +02:00
|
|
|
|
|
|
|
var coverbg = document.createElement('div')
|
2021-12-04 00:05:13 +01:00
|
|
|
coverbg.className = 'absolute cover-bg'
|
2021-09-24 14:32:38 +02:00
|
|
|
coverbg.style.backgroundImage = `url("${src}")`
|
|
|
|
|
|
|
|
coverbgwrapper.appendChild(coverbg)
|
|
|
|
imgdiv.appendChild(coverbgwrapper)
|
|
|
|
}
|
|
|
|
|
|
|
|
var img = document.createElement('img')
|
|
|
|
img.src = src
|
2024-12-12 23:51:36 +01:00
|
|
|
img.alt = `${this.name}, ${this.$strings.LabelCover}`
|
|
|
|
img.ariaHidden = true
|
2021-09-24 14:32:38 +02:00
|
|
|
img.className = 'absolute top-0 left-0 w-full h-full'
|
|
|
|
img.style.objectFit = showCoverBg ? 'contain' : 'cover'
|
|
|
|
|
|
|
|
imgdiv.appendChild(img)
|
|
|
|
return imgdiv
|
|
|
|
},
|
2021-10-30 03:42:28 +02:00
|
|
|
createSeriesNameCover(offsetLeft) {
|
|
|
|
var imgdiv = document.createElement('div')
|
|
|
|
imgdiv.style.height = this.height + 'px'
|
2021-12-02 22:49:03 +01:00
|
|
|
imgdiv.style.width = this.height / this.bookCoverAspectRatio + 'px'
|
2021-10-30 03:42:28 +02:00
|
|
|
imgdiv.style.left = offsetLeft + 'px'
|
|
|
|
imgdiv.className = 'absolute top-0 box-shadow-book transition-transform flex items-center justify-center'
|
|
|
|
imgdiv.style.boxShadow = '4px 0px 4px #11111166'
|
|
|
|
imgdiv.style.backgroundColor = '#111'
|
|
|
|
|
|
|
|
var innerP = document.createElement('p')
|
|
|
|
innerP.textContent = this.name
|
2023-02-11 22:02:56 +01:00
|
|
|
innerP.className = 'text-sm text-white'
|
2021-10-30 03:42:28 +02:00
|
|
|
imgdiv.appendChild(innerP)
|
|
|
|
|
|
|
|
return imgdiv
|
|
|
|
},
|
2021-09-24 14:32:38 +02:00
|
|
|
async init() {
|
2021-12-02 22:49:03 +01:00
|
|
|
if (this.isInit) return
|
|
|
|
this.isInit = true
|
|
|
|
|
2021-09-24 14:32:38 +02:00
|
|
|
if (this.coverDiv) {
|
|
|
|
this.coverDiv.remove()
|
|
|
|
this.coverDiv = null
|
|
|
|
}
|
2021-10-29 02:34:29 +02:00
|
|
|
var validCovers = this.bookItems
|
|
|
|
.map((bookItem) => {
|
|
|
|
return {
|
|
|
|
id: bookItem.id,
|
|
|
|
coverUrl: this.getCoverUrl(bookItem)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter((b) => b.coverUrl !== '')
|
2021-09-24 14:32:38 +02:00
|
|
|
if (!validCovers.length) {
|
|
|
|
this.noValidCovers = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.noValidCovers = false
|
|
|
|
|
2022-02-09 18:19:02 +01:00
|
|
|
validCovers = validCovers.slice(0, 10)
|
2022-01-25 12:10:51 +01:00
|
|
|
|
2021-09-24 14:32:38 +02:00
|
|
|
var coverWidth = this.width
|
|
|
|
var widthPer = this.width
|
|
|
|
if (validCovers.length > 1) {
|
2021-12-02 22:49:03 +01:00
|
|
|
coverWidth = this.height / this.bookCoverAspectRatio
|
2021-09-24 14:32:38 +02:00
|
|
|
widthPer = (this.width - coverWidth) / (validCovers.length - 1)
|
|
|
|
}
|
2021-10-29 02:34:29 +02:00
|
|
|
this.coverWidth = coverWidth
|
|
|
|
this.offsetIncrement = widthPer
|
2021-09-24 14:32:38 +02:00
|
|
|
|
|
|
|
var outerdiv = document.createElement('div')
|
2021-12-02 22:49:03 +01:00
|
|
|
outerdiv.id = `group-cover-${this.id}`
|
2021-10-30 03:42:28 +02:00
|
|
|
this.coverWrapperEl = outerdiv
|
2021-12-02 22:49:03 +01:00
|
|
|
outerdiv.className = 'w-full h-full relative box-shadow-book'
|
2021-09-24 14:32:38 +02:00
|
|
|
|
2021-10-29 02:34:29 +02:00
|
|
|
var coverImageEls = []
|
2021-10-30 03:42:28 +02:00
|
|
|
var offsetLeft = 0
|
2021-09-24 14:32:38 +02:00
|
|
|
for (let i = 0; i < validCovers.length; i++) {
|
2021-10-30 03:42:28 +02:00
|
|
|
offsetLeft = widthPer * i
|
2021-10-29 02:34:29 +02:00
|
|
|
var zIndex = validCovers.length - i
|
|
|
|
var img = await this.buildCoverImg(validCovers[i], coverWidth, offsetLeft, zIndex, validCovers.length === 1)
|
2021-09-24 14:32:38 +02:00
|
|
|
outerdiv.appendChild(img)
|
2021-10-29 02:34:29 +02:00
|
|
|
coverImageEls.push(img)
|
2021-09-24 14:32:38 +02:00
|
|
|
}
|
2021-10-30 03:42:28 +02:00
|
|
|
|
2021-10-29 02:34:29 +02:00
|
|
|
this.coverImageEls = coverImageEls
|
2021-09-24 14:32:38 +02:00
|
|
|
|
|
|
|
if (this.$refs.wrapper) {
|
|
|
|
this.coverDiv = outerdiv
|
|
|
|
this.$refs.wrapper.appendChild(outerdiv)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-02-09 18:19:02 +01:00
|
|
|
mounted() {},
|
2021-10-30 03:42:28 +02:00
|
|
|
beforeDestroy() {
|
|
|
|
if (this.coverWrapperEl) this.coverWrapperEl.remove()
|
2021-12-02 22:49:03 +01:00
|
|
|
if (this.coverImageEls && this.coverImageEls.length) {
|
|
|
|
this.coverImageEls.forEach((el) => el.remove())
|
|
|
|
}
|
|
|
|
if (this.coverDiv) this.coverDiv.remove()
|
2021-10-30 03:42:28 +02:00
|
|
|
}
|
2021-09-24 14:32:38 +02:00
|
|
|
}
|
2022-01-27 23:27:18 +01:00
|
|
|
</script>
|