pdf搜索

This commit is contained in:
cwchen 2025-11-28 10:56:44 +08:00
parent f341e1822b
commit 5fa6511ee9
1 changed files with 43 additions and 8 deletions

View File

@ -515,7 +515,16 @@ export default {
try {
while (this.renderQueue.length) {
const pageNumber = this.renderQueue.shift()
// 使 requestIdleCallback
if (typeof window.requestIdleCallback === 'function') {
await new Promise((resolve) => {
window.requestIdleCallback(() => {
requestAnimationFrame(resolve)
}, { timeout: 100 })
})
} else {
await new Promise((resolve) => requestAnimationFrame(resolve))
}
await this.renderSinglePage(pageNumber)
}
} finally {
@ -551,9 +560,11 @@ export default {
const schedule = () => {
this.prefetchScheduled = true
if (typeof window.requestIdleCallback === 'function') {
this.prefetchHandle = window.requestIdleCallback(fetchNext, { timeout: 1000 })
//
this.prefetchHandle = window.requestIdleCallback(fetchNext, { timeout: 2000 })
} else {
this.prefetchHandle = window.setTimeout(fetchNext, 80)
//
this.prefetchHandle = window.setTimeout(fetchNext, 150)
}
}
schedule()
@ -565,10 +576,10 @@ export default {
this.isPrefetching = true
if (typeof window.requestIdleCallback === 'function') {
this.prefetchScheduled = true
this.prefetchHandle = window.requestIdleCallback(fetchNext, { timeout: 800 })
this.prefetchHandle = window.requestIdleCallback(fetchNext, { timeout: 1500 })
} else {
this.prefetchScheduled = true
this.prefetchHandle = window.setTimeout(fetchNext, 120)
this.prefetchHandle = window.setTimeout(fetchNext, 200)
}
},
@ -1211,11 +1222,19 @@ export default {
const options = {
root: this.$refs.pdfWrapper,
rootMargin: '120px 0px',
threshold: 0.01,
rootMargin: '200px 0px', //
threshold: [0, 0.1, 0.5, 1], // 使
}
this.observer = new IntersectionObserver((entries) => {
// 使 requestAnimationFrame IntersectionObserver
let rafScheduled = false
const pendingEntries = []
const processEntries = () => {
rafScheduled = false
const entries = [...pendingEntries]
pendingEntries.length = 0
entries.forEach((entry) => {
if (entry.isIntersecting) {
const page = Number(entry.target.dataset.page)
@ -1235,6 +1254,14 @@ export default {
}
}
})
}
this.observer = new IntersectionObserver((entries) => {
pendingEntries.push(...entries)
if (!rafScheduled) {
rafScheduled = true
requestAnimationFrame(processEntries)
}
}, options)
this.pageContainers.forEach((container) => this.observer.observe(container))
@ -1597,6 +1624,8 @@ export default {
scrollbar-gutter: stable both-edges;
-webkit-overflow-scrolling: touch;
overflow-x: auto;
/* 性能优化 */
will-change: scroll-position;
}
.pdf-page {
@ -1697,6 +1726,10 @@ export default {
.pdf-canvas {
display: block;
margin: 0 auto;
/* 性能优化 */
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
will-change: contents;
}
.textLayer {
@ -1708,6 +1741,8 @@ export default {
pointer-events: auto;
user-select: text;
-webkit-user-select: text;
/* 性能优化 */
will-change: contents;
}
.textLayer>span {