-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(PdfReader): add thumbnails rotate function #725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -127,35 +127,7 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => { | |||||||||||||||||
|
|
||||||||||||||||||
| eventBus.on("pagesloaded", async e => { | ||||||||||||||||||
| if (options.enableThumbnails) { | ||||||||||||||||||
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | ||||||||||||||||||
| pdfViewer.getPagesOverview().map(async (p, i) => { | ||||||||||||||||||
| const item = document.createElement("div"); | ||||||||||||||||||
| item.classList.add("bb-view-thumbnail-item"); | ||||||||||||||||||
| if (pdfViewer.currentPageNumber === i + 1) { | ||||||||||||||||||
| item.classList.add("active"); | ||||||||||||||||||
| } | ||||||||||||||||||
| item.setAttribute("data-bb-page", `${i + 1}`); | ||||||||||||||||||
| thumbnailsContainer.appendChild(item); | ||||||||||||||||||
|
|
||||||||||||||||||
| const page = await pdfViewer.pdfDocument.getPage(i + 1); | ||||||||||||||||||
| const canvas = await makeThumb(page); | ||||||||||||||||||
| const img = document.createElement("img"); | ||||||||||||||||||
| img.src = canvas.toDataURL(); | ||||||||||||||||||
| item.appendChild(img); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| EventHandler.on(thumbnailsContainer, "click", ".bb-view-thumbnail-item", e => { | ||||||||||||||||||
| const active = thumbnailsContainer.querySelector('.active'); | ||||||||||||||||||
| if (active) { | ||||||||||||||||||
| active.classList.remove('active'); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const item = e.delegateTarget; | ||||||||||||||||||
| item.classList.add("active"); | ||||||||||||||||||
|
|
||||||||||||||||||
| const index = parseInt(item.getAttribute("data-bb-page")) || 1; | ||||||||||||||||||
| pdfViewer.currentPageNumber = index; | ||||||||||||||||||
| }) | ||||||||||||||||||
| resetThumbnailsView(el, pdfViewer); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (options.triggerPagesLoaded === true) { | ||||||||||||||||||
|
|
@@ -232,6 +204,45 @@ const addEventListener = (el, pdfViewer, eventBus, invoke, options) => { | |||||||||||||||||
| thumbnailsEl.classList.toggle("show"); | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| eventBus.on("rotationchanging", evt => { | ||||||||||||||||||
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | ||||||||||||||||||
| if (thumbnailsContainer) { | ||||||||||||||||||
| thumbnailsContainer.style.setProperty('--thumb-rotate', `${evt.pagesRotation}deg`); | ||||||||||||||||||
|
Comment on lines
+209
to
+211
|
||||||||||||||||||
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | |
| if (thumbnailsContainer) { | |
| thumbnailsContainer.style.setProperty('--thumb-rotate', `${evt.pagesRotation}deg`); | |
| if (options.enableThumbnails) { | |
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | |
| if (thumbnailsContainer) { | |
| thumbnailsContainer.style.setProperty('--thumb-rotate', `${evt.pagesRotation}deg`); | |
| } |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resetThumbnailsView function doesn't clear existing thumbnails before recreating them. If this function is called multiple times (e.g., when rotation changes or PDF is reloaded), it will keep appending new thumbnails to the container, leading to duplicates.
Add thumbnailsContainer.innerHTML = ''; at the beginning of the function to clear existing content before regenerating thumbnails.
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | |
| const thumbnailsContainer = el.querySelector(".bb-view-thumbnails"); | |
| thumbnailsContainer.innerHTML = ''; |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The event handler is registered each time resetThumbnailsView is called, but it's never removed before re-registration. This will create duplicate event handlers if resetThumbnailsView is called multiple times (e.g., if the PDF is reloaded or thumbnails are regenerated).
Consider either:
- Removing the existing handler before registering a new one:
EventHandler.off(thumbnailsContainer, "click")beforeEventHandler.on(...) - Moving this event handler registration outside of
resetThumbnailsViewto ensure it's only registered once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for
--thumb-rotateis set to0(unitless), but it's used asrotate(var(--thumb-rotate))which expects a value with units. While CSS is lenient and treatsrotate(0)the same asrotate(0deg), for consistency and clarity, consider setting the default to0deginstead of0.