|
|
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
|
|
} from "@design.estate/dees-element";
|
|
|
|
|
import { demoFunc } from "./viewer.demo.js";
|
|
|
|
|
import { DeDocument } from "./document.js";
|
|
|
|
|
import "./page.js"; // Import DePage for thumbnail rendering
|
|
|
|
|
|
|
|
|
|
import "@design.estate/dees-catalog";
|
|
|
|
|
|
|
|
|
|
@@ -88,6 +89,25 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
@state()
|
|
|
|
|
accessor displayZoom: number = 100;
|
|
|
|
|
|
|
|
|
|
@state()
|
|
|
|
|
accessor currentPageDisplay: string = "1 / 1";
|
|
|
|
|
|
|
|
|
|
// Sidebar state
|
|
|
|
|
@state()
|
|
|
|
|
accessor showThumbnails: boolean = true;
|
|
|
|
|
|
|
|
|
|
@state()
|
|
|
|
|
accessor sidebarWidth: number = 140;
|
|
|
|
|
|
|
|
|
|
@state()
|
|
|
|
|
accessor isResizingSidebar: boolean = false;
|
|
|
|
|
|
|
|
|
|
@state()
|
|
|
|
|
accessor thumbnailPages: number[] = [];
|
|
|
|
|
|
|
|
|
|
// Zoom animation
|
|
|
|
|
private zoomAnimationId: number | null = null;
|
|
|
|
|
|
|
|
|
|
public static styles = [
|
|
|
|
|
cssManager.defaultStyles,
|
|
|
|
|
css`
|
|
|
|
|
@@ -104,6 +124,124 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
--dropdown-shadow: ${cssManager.bdTheme("0 4px 16px rgba(0,0,0,0.15)", "0 4px 16px rgba(0,0,0,0.4)")};
|
|
|
|
|
--slider-track: ${cssManager.bdTheme("#ddd", "#444")};
|
|
|
|
|
--slider-fill: ${cssManager.bdTheme("#0066cc", "#4d9fff")};
|
|
|
|
|
--sidebar-min-width: 100px;
|
|
|
|
|
--sidebar-max-width: 300px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sidebar Styles */
|
|
|
|
|
.sidebar {
|
|
|
|
|
position: absolute;
|
|
|
|
|
left: 0;
|
|
|
|
|
top: var(--toolbar-height);
|
|
|
|
|
bottom: 0;
|
|
|
|
|
background: var(--toolbar-bg);
|
|
|
|
|
backdrop-filter: blur(12px);
|
|
|
|
|
-webkit-backdrop-filter: blur(12px);
|
|
|
|
|
border-right: 1px solid var(--toolbar-border);
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
z-index: 50;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar--collapsed {
|
|
|
|
|
width: 0 !important;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
border-right: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar--resizing {
|
|
|
|
|
transition: none !important;
|
|
|
|
|
user-select: none;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar__header {
|
|
|
|
|
padding: 10px 12px;
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
color: var(--text-secondary);
|
|
|
|
|
border-bottom: 1px solid var(--toolbar-border);
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
letter-spacing: 0.5px;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar__thumbnails {
|
|
|
|
|
flex: 1;
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
overflow-x: hidden;
|
|
|
|
|
padding: 8px;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: 12px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 4px;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
padding: 4px;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
transition: background 0.15s ease;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail:hover {
|
|
|
|
|
background: var(--button-hover);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail--active {
|
|
|
|
|
background: var(--button-active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail--active .thumbnail__preview {
|
|
|
|
|
outline: 2px solid var(--accent-color);
|
|
|
|
|
outline-offset: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail__preview {
|
|
|
|
|
width: 100%;
|
|
|
|
|
aspect-ratio: 210 / 297;
|
|
|
|
|
background: ${cssManager.bdTheme("#fff", "#2a2a2a")};
|
|
|
|
|
box-shadow: ${cssManager.bdTheme("0 1px 4px rgba(0,0,0,0.15)", "0 1px 4px rgba(0,0,0,0.4)")};
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
position: relative;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.thumbnail__label {
|
|
|
|
|
font-size: 11px;
|
|
|
|
|
color: var(--text-secondary);
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar__resize-handle {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
right: -4px;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 8px;
|
|
|
|
|
cursor: ew-resize;
|
|
|
|
|
background: transparent;
|
|
|
|
|
z-index: 60;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar__resize-handle::after {
|
|
|
|
|
content: '';
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 3px;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 2px;
|
|
|
|
|
background: transparent;
|
|
|
|
|
transition: background 0.15s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar__resize-handle:hover::after,
|
|
|
|
|
.sidebar--resizing .sidebar__resize-handle::after {
|
|
|
|
|
background: var(--accent-color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.maincontainer {
|
|
|
|
|
@@ -194,7 +332,7 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
color: var(--text-primary);
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
min-width: 80px;
|
|
|
|
|
width: 90px; /* Fixed width to prevent reflow - fits "Fit Width" */
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
transition: all 0.15s ease;
|
|
|
|
|
}
|
|
|
|
|
@@ -322,6 +460,25 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
gap: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fit-buttons {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.page-nav {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 2px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.page-indicator {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
color: var(--text-secondary);
|
|
|
|
|
min-width: 45px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.spacing-slider-container {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
@@ -391,6 +548,11 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
overflow-y: scroll;
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
overscroll-behavior: contain;
|
|
|
|
|
transition: left 0.2s ease;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.viewport--with-sidebar {
|
|
|
|
|
left: var(--current-sidebar-width, 140px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.viewport--centered {
|
|
|
|
|
@@ -407,12 +569,25 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
.spacing-slider-container {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
/* Collapse sidebar by default on tablet */
|
|
|
|
|
.sidebar {
|
|
|
|
|
width: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
.sidebar--collapsed {
|
|
|
|
|
width: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
.viewport--with-sidebar {
|
|
|
|
|
left: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
`),
|
|
|
|
|
// Phone styles
|
|
|
|
|
cssManager.cssForPhone(css`
|
|
|
|
|
.zoom-slider-container {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.fit-buttons {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
.spacing-label {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
@@ -428,13 +603,30 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
.controls__section {
|
|
|
|
|
gap: 2px;
|
|
|
|
|
}
|
|
|
|
|
/* Hide sidebar and toggle on phone */
|
|
|
|
|
.sidebar {
|
|
|
|
|
display: none !important;
|
|
|
|
|
}
|
|
|
|
|
.sidebar-toggle {
|
|
|
|
|
display: none !important;
|
|
|
|
|
}
|
|
|
|
|
.viewport--with-sidebar {
|
|
|
|
|
left: 0 !important;
|
|
|
|
|
}
|
|
|
|
|
`),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public render(): TemplateResult {
|
|
|
|
|
const viewportClasses = [
|
|
|
|
|
"viewport",
|
|
|
|
|
this.zoomMode !== "auto" ? "viewport--centered" : "",
|
|
|
|
|
this.showThumbnails ? "viewport--with-sidebar" : "",
|
|
|
|
|
].filter(Boolean).join(" ");
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div class="maincontainer">
|
|
|
|
|
<div class="viewport ${this.zoomMode !== "auto" ? "viewport--centered" : ""}">
|
|
|
|
|
<div class="maincontainer" style="--current-sidebar-width: ${this.sidebarWidth}px;">
|
|
|
|
|
${this.renderSidebar()}
|
|
|
|
|
<div class="${viewportClasses}">
|
|
|
|
|
${this.letterData
|
|
|
|
|
? html`
|
|
|
|
|
<dedocument-dedocument
|
|
|
|
|
@@ -455,9 +647,77 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private renderSidebar(): TemplateResult {
|
|
|
|
|
const sidebarClasses = [
|
|
|
|
|
"sidebar",
|
|
|
|
|
!this.showThumbnails ? "sidebar--collapsed" : "",
|
|
|
|
|
this.isResizingSidebar ? "sidebar--resizing" : "",
|
|
|
|
|
].filter(Boolean).join(" ");
|
|
|
|
|
|
|
|
|
|
const thumbnailScale = this.getThumbnailScale();
|
|
|
|
|
const currentPage = this.getCurrentPage();
|
|
|
|
|
|
|
|
|
|
return html`
|
|
|
|
|
<div class="${sidebarClasses}" style="width: ${this.sidebarWidth}px;">
|
|
|
|
|
<div class="sidebar__header">Pages</div>
|
|
|
|
|
<div class="sidebar__thumbnails">
|
|
|
|
|
${this.thumbnailPages.map(
|
|
|
|
|
(_, i) => html`
|
|
|
|
|
<div
|
|
|
|
|
class="thumbnail ${currentPage === i + 1 ? "thumbnail--active" : ""}"
|
|
|
|
|
@click=${() => this.scrollToPage(i + 1)}
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
class="thumbnail__preview"
|
|
|
|
|
style="--thumbnail-scale: ${thumbnailScale};"
|
|
|
|
|
>
|
|
|
|
|
<div style="
|
|
|
|
|
width: ${plugins.shared.A4_WIDTH}px;
|
|
|
|
|
height: ${plugins.shared.A4_HEIGHT}px;
|
|
|
|
|
transform: scale(${thumbnailScale});
|
|
|
|
|
transform-origin: top left;
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
">
|
|
|
|
|
<dedocument-page
|
|
|
|
|
.letterData=${this.letterData}
|
|
|
|
|
.documentSettings=${this.documentSettings}
|
|
|
|
|
.pageNumber=${i + 1}
|
|
|
|
|
.pageTotalNumber=${this.thumbnailPages.length}
|
|
|
|
|
></dedocument-page>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="thumbnail__label">${i + 1}</span>
|
|
|
|
|
</div>
|
|
|
|
|
`
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
|
|
|
|
class="sidebar__resize-handle"
|
|
|
|
|
@mousedown=${this.startSidebarResize}
|
|
|
|
|
></div>
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getThumbnailScale(): number {
|
|
|
|
|
const previewWidth = this.sidebarWidth - 24; // Account for padding
|
|
|
|
|
return previewWidth / plugins.shared.A4_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private renderZoomControls(): TemplateResult {
|
|
|
|
|
return html`
|
|
|
|
|
<div class="controls__section">
|
|
|
|
|
<!-- Sidebar Toggle Button -->
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button sidebar-toggle ${this.showThumbnails ? "controls__button--active" : ""}"
|
|
|
|
|
@click=${() => this.toggleThumbnails()}
|
|
|
|
|
title="Toggle Thumbnails"
|
|
|
|
|
>
|
|
|
|
|
<dees-icon icon="lucide:panelLeft"></dees-icon>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<div class="controls__divider sidebar-toggle"></div>
|
|
|
|
|
|
|
|
|
|
<!-- Zoom Out Button -->
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button"
|
|
|
|
|
@@ -501,6 +761,29 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
|
|
|
|
|
<div class="controls__divider"></div>
|
|
|
|
|
|
|
|
|
|
<!-- Fit Buttons -->
|
|
|
|
|
<div class="fit-buttons">
|
|
|
|
|
<!-- Fit Width Button -->
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button ${this.zoomMode === "fit-width" ? "controls__button--active" : ""}"
|
|
|
|
|
@click=${() => this.handleZoomPreset("fit-width")}
|
|
|
|
|
title="Fit Width"
|
|
|
|
|
>
|
|
|
|
|
<dees-icon icon="lucide:arrowLeftRight"></dees-icon>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<!-- Fit Page Button -->
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button ${this.zoomMode === "fit-page" ? "controls__button--active" : ""}"
|
|
|
|
|
@click=${() => this.handleZoomPreset("fit-page")}
|
|
|
|
|
title="Fit Page"
|
|
|
|
|
>
|
|
|
|
|
<dees-icon icon="lucide:expand"></dees-icon>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="controls__divider"></div>
|
|
|
|
|
|
|
|
|
|
<!-- Zoom Slider -->
|
|
|
|
|
<div class="zoom-slider-container">
|
|
|
|
|
<input
|
|
|
|
|
@@ -553,6 +836,27 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
|
|
|
|
|
<div class="controls__divider"></div>
|
|
|
|
|
|
|
|
|
|
<!-- Page Navigation -->
|
|
|
|
|
<div class="page-nav">
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button"
|
|
|
|
|
@click=${() => this.handlePreviousPage()}
|
|
|
|
|
title="Previous Page"
|
|
|
|
|
>
|
|
|
|
|
<dees-icon icon="lucide:chevronUp"></dees-icon>
|
|
|
|
|
</button>
|
|
|
|
|
<span class="page-indicator">${this.currentPageDisplay}</span>
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button"
|
|
|
|
|
@click=${() => this.handleNextPage()}
|
|
|
|
|
title="Next Page"
|
|
|
|
|
>
|
|
|
|
|
<dees-icon icon="lucide:chevronDown"></dees-icon>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="controls__divider"></div>
|
|
|
|
|
|
|
|
|
|
<!-- Print Button -->
|
|
|
|
|
<button
|
|
|
|
|
class="controls__button"
|
|
|
|
|
@@ -604,31 +908,69 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
this.updateDisplayZoom();
|
|
|
|
|
} else if (value === "fit-width") {
|
|
|
|
|
// Calculate zoom to fit page width to viewport width
|
|
|
|
|
this.calculateFitWidth();
|
|
|
|
|
this.calculateFitWidth(true);
|
|
|
|
|
} else if (value === "fit-page") {
|
|
|
|
|
// Calculate zoom to fit entire page in viewport
|
|
|
|
|
this.calculateFitPage();
|
|
|
|
|
this.calculateFitPage(true);
|
|
|
|
|
} else {
|
|
|
|
|
this.zoomLevel = value;
|
|
|
|
|
this.displayZoom = value;
|
|
|
|
|
// Animate to numeric preset
|
|
|
|
|
this.animateZoomTo(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleZoomStep(delta: number): void {
|
|
|
|
|
const current = this.zoomLevel ?? this.displayZoom;
|
|
|
|
|
const newZoom = Math.min(400, Math.max(25, current + delta));
|
|
|
|
|
this.zoomLevel = newZoom;
|
|
|
|
|
this.displayZoom = newZoom;
|
|
|
|
|
this.animateZoomTo(newZoom);
|
|
|
|
|
this.zoomMode = newZoom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleZoomSlider(e: Event): void {
|
|
|
|
|
// Cancel any running animation when user takes manual control
|
|
|
|
|
if (this.zoomAnimationId !== null) {
|
|
|
|
|
cancelAnimationFrame(this.zoomAnimationId);
|
|
|
|
|
this.zoomAnimationId = null;
|
|
|
|
|
}
|
|
|
|
|
const value = parseInt((e.target as HTMLInputElement).value, 10);
|
|
|
|
|
this.zoomLevel = value;
|
|
|
|
|
this.displayZoom = value;
|
|
|
|
|
this.zoomMode = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Animate zoom level to target value
|
|
|
|
|
* @param targetZoom - Target zoom percentage
|
|
|
|
|
* @param duration - Animation duration in ms (default: 200)
|
|
|
|
|
*/
|
|
|
|
|
private animateZoomTo(targetZoom: number, duration: number = 200): void {
|
|
|
|
|
// Cancel any existing animation
|
|
|
|
|
if (this.zoomAnimationId !== null) {
|
|
|
|
|
cancelAnimationFrame(this.zoomAnimationId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const startZoom = this.zoomLevel ?? this.displayZoom;
|
|
|
|
|
const startTime = performance.now();
|
|
|
|
|
const easeOutCubic = (t: number) => 1 - Math.pow(1 - t, 3);
|
|
|
|
|
|
|
|
|
|
const animate = (currentTime: number) => {
|
|
|
|
|
const elapsed = currentTime - startTime;
|
|
|
|
|
const progress = Math.min(elapsed / duration, 1);
|
|
|
|
|
const easedProgress = easeOutCubic(progress);
|
|
|
|
|
|
|
|
|
|
const currentZoom = startZoom + (targetZoom - startZoom) * easedProgress;
|
|
|
|
|
this.zoomLevel = Math.round(currentZoom);
|
|
|
|
|
this.displayZoom = this.zoomLevel;
|
|
|
|
|
|
|
|
|
|
if (progress < 1) {
|
|
|
|
|
this.zoomAnimationId = requestAnimationFrame(animate);
|
|
|
|
|
} else {
|
|
|
|
|
this.zoomAnimationId = null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.zoomAnimationId = requestAnimationFrame(animate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleSpacingPreset(value: number): void {
|
|
|
|
|
this.pageGap = value;
|
|
|
|
|
}
|
|
|
|
|
@@ -637,6 +979,65 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
this.pageGap = parseInt((e.target as HTMLInputElement).value, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
// SIDEBAR METHODS
|
|
|
|
|
// ============================================
|
|
|
|
|
|
|
|
|
|
private startSidebarResize(e: MouseEvent): void {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
this.isResizingSidebar = true;
|
|
|
|
|
|
|
|
|
|
const startX = e.clientX;
|
|
|
|
|
const startWidth = this.sidebarWidth;
|
|
|
|
|
|
|
|
|
|
const onMouseMove = (moveEvent: MouseEvent) => {
|
|
|
|
|
const delta = moveEvent.clientX - startX;
|
|
|
|
|
const newWidth = Math.min(300, Math.max(100, startWidth + delta));
|
|
|
|
|
this.sidebarWidth = newWidth;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMouseUp = () => {
|
|
|
|
|
this.isResizingSidebar = false;
|
|
|
|
|
document.removeEventListener("mousemove", onMouseMove);
|
|
|
|
|
document.removeEventListener("mouseup", onMouseUp);
|
|
|
|
|
document.body.style.cursor = "";
|
|
|
|
|
document.body.style.userSelect = "";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
document.addEventListener("mousemove", onMouseMove);
|
|
|
|
|
document.addEventListener("mouseup", onMouseUp);
|
|
|
|
|
document.body.style.cursor = "ew-resize";
|
|
|
|
|
document.body.style.userSelect = "none";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateThumbnailPages(): void {
|
|
|
|
|
const pageCount = this.getPageCount();
|
|
|
|
|
if (pageCount !== this.thumbnailPages.length) {
|
|
|
|
|
this.thumbnailPages = Array.from({ length: pageCount }, (_, i) => i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handlePreviousPage(): void {
|
|
|
|
|
const current = this.getCurrentPage();
|
|
|
|
|
if (current > 1) {
|
|
|
|
|
this.scrollToPage(current - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private handleNextPage(): void {
|
|
|
|
|
const current = this.getCurrentPage();
|
|
|
|
|
const total = this.getPageCount();
|
|
|
|
|
if (current < total) {
|
|
|
|
|
this.scrollToPage(current + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updatePageIndicator(): void {
|
|
|
|
|
const current = this.getCurrentPage();
|
|
|
|
|
const total = this.getPageCount();
|
|
|
|
|
this.currentPageDisplay = `${current} / ${total || 1}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async handlePrint(): Promise<void> {
|
|
|
|
|
// Create a print-specific container - hidden on screen, visible only in print
|
|
|
|
|
const printContainer = document.createElement("div");
|
|
|
|
|
@@ -723,19 +1124,24 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
setTimeout(cleanup, 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private calculateFitWidth(): void {
|
|
|
|
|
private calculateFitWidth(animate: boolean = false): void {
|
|
|
|
|
const viewport = this.shadowRoot?.querySelector(".viewport");
|
|
|
|
|
if (!viewport) return;
|
|
|
|
|
|
|
|
|
|
// Account for padding and scrollbar width
|
|
|
|
|
const viewportWidth = viewport.clientWidth - 32 - 16;
|
|
|
|
|
const scale = viewportWidth / plugins.shared.A4_WIDTH;
|
|
|
|
|
const targetZoom = Math.round(scale * 100);
|
|
|
|
|
|
|
|
|
|
this.zoomLevel = Math.round(scale * 100);
|
|
|
|
|
this.displayZoom = this.zoomLevel;
|
|
|
|
|
if (animate) {
|
|
|
|
|
this.animateZoomTo(targetZoom);
|
|
|
|
|
} else {
|
|
|
|
|
this.zoomLevel = targetZoom;
|
|
|
|
|
this.displayZoom = targetZoom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private calculateFitPage(): void {
|
|
|
|
|
private calculateFitPage(animate: boolean = false): void {
|
|
|
|
|
const viewport = this.shadowRoot?.querySelector(".viewport");
|
|
|
|
|
if (!viewport) return;
|
|
|
|
|
|
|
|
|
|
@@ -750,9 +1156,14 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
const scaleByHeight = viewportHeight / plugins.shared.A4_HEIGHT;
|
|
|
|
|
const scaleByWidth = viewportWidth / plugins.shared.A4_WIDTH;
|
|
|
|
|
const scale = Math.min(scaleByHeight, scaleByWidth);
|
|
|
|
|
const targetZoom = Math.round(scale * 100);
|
|
|
|
|
|
|
|
|
|
this.zoomLevel = Math.round(scale * 100);
|
|
|
|
|
this.displayZoom = this.zoomLevel;
|
|
|
|
|
if (animate) {
|
|
|
|
|
this.animateZoomTo(targetZoom);
|
|
|
|
|
} else {
|
|
|
|
|
this.zoomLevel = targetZoom;
|
|
|
|
|
this.displayZoom = targetZoom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private updateDisplayZoom(): void {
|
|
|
|
|
@@ -771,8 +1182,16 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
super.updated(changedProperties);
|
|
|
|
|
|
|
|
|
|
if (changedProperties.has("letterData")) {
|
|
|
|
|
// Update display zoom after document renders
|
|
|
|
|
setTimeout(() => this.updateDisplayZoom(), 100);
|
|
|
|
|
// Update display zoom, page indicator, and thumbnails after document renders
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.updateDisplayZoom();
|
|
|
|
|
this.updatePageIndicator();
|
|
|
|
|
this.updateThumbnailPages();
|
|
|
|
|
}, 100);
|
|
|
|
|
// Additional delay to ensure all pages are rendered
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.updateThumbnailPages();
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -791,9 +1210,10 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
setTimeout(() => this.updateDisplayZoom(), 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle viewport resize to update display zoom in auto mode
|
|
|
|
|
// Handle viewport resize and scroll
|
|
|
|
|
const viewport = this.shadowRoot?.querySelector(".viewport");
|
|
|
|
|
if (viewport) {
|
|
|
|
|
// Resize observer for zoom updates
|
|
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
|
|
if (this.zoomMode === "auto" || this.zoomMode === "fit-width") {
|
|
|
|
|
this.updateDisplayZoom();
|
|
|
|
|
@@ -801,7 +1221,22 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
});
|
|
|
|
|
resizeObserver.observe(viewport);
|
|
|
|
|
this.registerGarbageFunction(() => resizeObserver.disconnect());
|
|
|
|
|
|
|
|
|
|
// Scroll listener for page indicator and thumbnail highlighting
|
|
|
|
|
const scrollHandler = () => {
|
|
|
|
|
this.updatePageIndicator();
|
|
|
|
|
// Trigger re-render to update active thumbnail
|
|
|
|
|
this.requestUpdate();
|
|
|
|
|
};
|
|
|
|
|
viewport.addEventListener("scroll", scrollHandler, { passive: true });
|
|
|
|
|
this.registerGarbageFunction(() => viewport.removeEventListener("scroll", scrollHandler));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initial page indicator and thumbnail update
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.updatePageIndicator();
|
|
|
|
|
this.updateThumbnailPages();
|
|
|
|
|
}, 300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================
|
|
|
|
|
@@ -896,27 +1331,100 @@ export class DeDocumentViewer extends DeesElement {
|
|
|
|
|
* @param smooth - Whether to use smooth scrolling (default: true)
|
|
|
|
|
*/
|
|
|
|
|
public scrollToPage(pageNumber: number, smooth: boolean = true): void {
|
|
|
|
|
const viewport = this.shadowRoot?.querySelector(".viewport");
|
|
|
|
|
const doc = this.shadowRoot?.querySelector("dedocument-dedocument");
|
|
|
|
|
if (!doc) return;
|
|
|
|
|
if (!viewport || !doc) return;
|
|
|
|
|
|
|
|
|
|
const pages = doc.shadowRoot?.querySelectorAll("dedocument-page");
|
|
|
|
|
if (!pages || pages.length === 0) return;
|
|
|
|
|
|
|
|
|
|
const targetIndex = Math.min(Math.max(0, pageNumber - 1), pages.length - 1);
|
|
|
|
|
const targetPage = pages[targetIndex];
|
|
|
|
|
const targetPage = pages[targetIndex] as HTMLElement;
|
|
|
|
|
|
|
|
|
|
if (targetPage) {
|
|
|
|
|
targetPage.scrollIntoView({
|
|
|
|
|
behavior: smooth ? "smooth" : "instant",
|
|
|
|
|
block: "start",
|
|
|
|
|
});
|
|
|
|
|
// Calculate scroll position relative to viewport
|
|
|
|
|
// Account for the document's position within the viewport
|
|
|
|
|
const docRect = doc.getBoundingClientRect();
|
|
|
|
|
const pageRect = targetPage.getBoundingClientRect();
|
|
|
|
|
const pageOffsetFromDoc = pageRect.top - docRect.top;
|
|
|
|
|
|
|
|
|
|
// Scroll to the page position with fast custom animation
|
|
|
|
|
if (smooth) {
|
|
|
|
|
this.animateScrollTo(viewport, pageOffsetFromDoc, 250);
|
|
|
|
|
} else {
|
|
|
|
|
viewport.scrollTop = pageOffsetFromDoc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Animate scroll to target position
|
|
|
|
|
* @param element - The scrollable element
|
|
|
|
|
* @param targetTop - Target scroll position
|
|
|
|
|
* @param duration - Animation duration in ms (default: 150)
|
|
|
|
|
*/
|
|
|
|
|
private animateScrollTo(element: Element, targetTop: number, duration: number = 150): void {
|
|
|
|
|
const startTop = element.scrollTop;
|
|
|
|
|
const distance = targetTop - startTop;
|
|
|
|
|
const startTime = performance.now();
|
|
|
|
|
const easeOutCubic = (t: number) => 1 - Math.pow(1 - t, 3);
|
|
|
|
|
|
|
|
|
|
const step = (currentTime: number) => {
|
|
|
|
|
const elapsed = currentTime - startTime;
|
|
|
|
|
const progress = Math.min(elapsed / duration, 1);
|
|
|
|
|
const easedProgress = easeOutCubic(progress);
|
|
|
|
|
|
|
|
|
|
element.scrollTop = startTop + distance * easedProgress;
|
|
|
|
|
|
|
|
|
|
if (progress < 1) {
|
|
|
|
|
requestAnimationFrame(step);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
requestAnimationFrame(step);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Trigger the print dialog
|
|
|
|
|
*/
|
|
|
|
|
public async print(): Promise<void> {
|
|
|
|
|
await this.handlePrint();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle the thumbnails sidebar visibility
|
|
|
|
|
*/
|
|
|
|
|
public toggleThumbnails(): void {
|
|
|
|
|
this.showThumbnails = !this.showThumbnails;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set whether the thumbnails sidebar is visible
|
|
|
|
|
* @param visible - Whether the sidebar should be visible
|
|
|
|
|
*/
|
|
|
|
|
public setThumbnailsVisible(visible: boolean): void {
|
|
|
|
|
this.showThumbnails = visible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get whether the thumbnails sidebar is visible
|
|
|
|
|
*/
|
|
|
|
|
public getThumbnailsVisible(): boolean {
|
|
|
|
|
return this.showThumbnails;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the sidebar width
|
|
|
|
|
* @param width - Width in pixels (100-300)
|
|
|
|
|
*/
|
|
|
|
|
public setSidebarWidth(width: number): void {
|
|
|
|
|
this.sidebarWidth = Math.min(300, Math.max(100, width));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current sidebar width
|
|
|
|
|
*/
|
|
|
|
|
public getSidebarWidth(): number {
|
|
|
|
|
return this.sidebarWidth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|