Clean up debugging code and refine error handling
Removed unnecessary `console.log` statements from `pdf-viewer.js` and `receiver-signature.js` to reduce console output in production. Simplified error handling in `pdf-viewer.js` for better clarity, including consolidating error logging and removing redundant handling for `RenderingCancelledException`. Deleted the `debugDumpViewerDom` function and its public API reference from `receiver-signature.js` as part of a cleanup effort to eliminate unused debugging utilities. Streamlined code related to event listener management in `pdf-viewer.js` while retaining core functionality.
This commit is contained in:
@@ -14,14 +14,9 @@ window.pdfViewer = {
|
|||||||
|
|
||||||
async initialize(canvasId, pdfDataUrl, dotNetRef) {
|
async initialize(canvasId, pdfDataUrl, dotNetRef) {
|
||||||
try {
|
try {
|
||||||
console.log('PDF.js initialization started for canvas:', canvasId);
|
|
||||||
|
|
||||||
// Store .NET reference for callbacks
|
|
||||||
this.dotNetReference = dotNetRef;
|
this.dotNetReference = dotNetRef;
|
||||||
|
|
||||||
// Wait for PDF.js to load
|
|
||||||
if (typeof window.pdfjsLib === 'undefined') {
|
if (typeof window.pdfjsLib === 'undefined') {
|
||||||
console.error('PDF.js library not loaded, waiting...');
|
|
||||||
await this.waitForPdfJs();
|
await this.waitForPdfJs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,32 +25,21 @@ window.pdfViewer = {
|
|||||||
|
|
||||||
this.canvas = document.getElementById(canvasId);
|
this.canvas = document.getElementById(canvasId);
|
||||||
if (!this.canvas) {
|
if (!this.canvas) {
|
||||||
console.error('Canvas element not found:', canvasId);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Canvas element found, loading PDF...');
|
|
||||||
|
|
||||||
this.ctx = this.canvas.getContext('2d');
|
this.ctx = this.canvas.getContext('2d');
|
||||||
|
|
||||||
// Attach mouse wheel event listener
|
|
||||||
this.attachWheelEvent();
|
this.attachWheelEvent();
|
||||||
|
|
||||||
// Load PDF from data URL
|
|
||||||
const uint8Array = this.base64ToUint8Array(pdfDataUrl);
|
const uint8Array = this.base64ToUint8Array(pdfDataUrl);
|
||||||
console.log('PDF data converted to Uint8Array, size:', uint8Array.length);
|
|
||||||
|
|
||||||
const loadingTask = pdfjsLib.getDocument({ data: uint8Array });
|
const loadingTask = pdfjsLib.getDocument({ data: uint8Array });
|
||||||
this.pdfDoc = await loadingTask.promise;
|
this.pdfDoc = await loadingTask.promise;
|
||||||
this.totalPages = this.pdfDoc.numPages;
|
this.totalPages = this.pdfDoc.numPages;
|
||||||
|
|
||||||
console.log('PDF loaded successfully, total pages:', this.totalPages);
|
|
||||||
|
|
||||||
// Render first page
|
|
||||||
await this.renderPage(this.pageNum);
|
await this.renderPage(this.pageNum);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error initializing PDF viewer:', error);
|
console.error('PDF viewer initialization failed:', error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -88,13 +72,11 @@ window.pdfViewer = {
|
|||||||
}, { passive: false });
|
}, { passive: false });
|
||||||
|
|
||||||
this.wheelEventAttached = true;
|
this.wheelEventAttached = true;
|
||||||
console.log('Wheel event listener attached to document body');
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async waitForPdfJs() {
|
async waitForPdfJs() {
|
||||||
for (let i = 0; i < 50; i++) {
|
for (let i = 0; i < 50; i++) {
|
||||||
if (typeof window.pdfjsLib !== 'undefined') {
|
if (typeof window.pdfjsLib !== 'undefined') {
|
||||||
console.log('PDF.js loaded after', i * 100, 'ms');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
await new Promise(resolve => setTimeout(resolve, 100));
|
||||||
@@ -136,8 +118,6 @@ window.pdfViewer = {
|
|||||||
const page = await this.pdfDoc.getPage(num);
|
const page = await this.pdfDoc.getPage(num);
|
||||||
const viewport = page.getViewport({ scale: this.scale });
|
const viewport = page.getViewport({ scale: this.scale });
|
||||||
|
|
||||||
console.log('Rendering page:', num, 'Viewport:', viewport.width, 'x', viewport.height);
|
|
||||||
|
|
||||||
this.canvas.height = viewport.height;
|
this.canvas.height = viewport.height;
|
||||||
this.canvas.width = viewport.width;
|
this.canvas.width = viewport.width;
|
||||||
|
|
||||||
@@ -147,15 +127,12 @@ window.pdfViewer = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (this.currentRenderTask) {
|
if (this.currentRenderTask) {
|
||||||
console.log('Cancelling previous render task');
|
|
||||||
this.currentRenderTask.cancel();
|
this.currentRenderTask.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentRenderTask = page.render(renderContext);
|
this.currentRenderTask = page.render(renderContext);
|
||||||
await this.currentRenderTask.promise;
|
await this.currentRenderTask.promise;
|
||||||
|
|
||||||
console.log('Page rendered successfully');
|
|
||||||
|
|
||||||
// Restore viewport center position AFTER rendering
|
// Restore viewport center position AFTER rendering
|
||||||
if (container && oldWidth > 0 && oldHeight > 0) {
|
if (container && oldWidth > 0 && oldHeight > 0) {
|
||||||
const scaleX = this.canvas.width / oldWidth;
|
const scaleX = this.canvas.width / oldWidth;
|
||||||
@@ -176,10 +153,8 @@ window.pdfViewer = {
|
|||||||
this.pageNumPending = null;
|
this.pageNumPending = null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === 'RenderingCancelledException') {
|
if (error.name !== 'RenderingCancelledException') {
|
||||||
console.log('Rendering cancelled, will render pending page');
|
console.error('Render error:', error);
|
||||||
} else {
|
|
||||||
console.error('Error rendering page:', error);
|
|
||||||
}
|
}
|
||||||
this.currentRenderTask = null;
|
this.currentRenderTask = null;
|
||||||
this.pageRendering = false;
|
this.pageRendering = false;
|
||||||
@@ -271,13 +246,9 @@ window.pdfViewer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
// Clean up event listeners
|
|
||||||
if (this.wheelEventAttached) {
|
if (this.wheelEventAttached) {
|
||||||
// Note: We can't remove the exact listener without keeping a reference
|
|
||||||
// but we can at least mark it as disposed
|
|
||||||
this.wheelEventAttached = false;
|
this.wheelEventAttached = false;
|
||||||
this.dotNetReference = null;
|
this.dotNetReference = null;
|
||||||
console.log('PDF viewer disposed');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -216,18 +216,6 @@ window.receiverSignature = (() => {
|
|||||||
overlayButtons.set(annotationId, { btn: wrapper, signed: isChecked });
|
overlayButtons.set(annotationId, { btn: wrapper, signed: isChecked });
|
||||||
}
|
}
|
||||||
|
|
||||||
function debugDumpViewerDom() {
|
|
||||||
const wrapper = document.querySelector(VIEWER_WRAPPER_SEL);
|
|
||||||
if (!wrapper) { console.warn('[annot] .receiver-viewer-wrapper not found'); return; }
|
|
||||||
console.group('[annot] viewer DOM snapshot');
|
|
||||||
const cs = new Set();
|
|
||||||
wrapper.querySelectorAll('*').forEach(el => el.classList.forEach(c => cs.add(c)));
|
|
||||||
console.log('classes:', [...cs].sort().join(', '));
|
|
||||||
console.log('scroll container:', document.querySelector(SCROLL_CONTAINER_SEL));
|
|
||||||
console.log('page images:', document.querySelectorAll(PAGE_IMG_SEL));
|
|
||||||
console.groupEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ?? Signature Pad ???????????????????????????????????????????????????????
|
// ?? Signature Pad ???????????????????????????????????????????????????????
|
||||||
|
|
||||||
function _pos(canvas, event) {
|
function _pos(canvas, event) {
|
||||||
@@ -332,7 +320,6 @@ window.receiverSignature = (() => {
|
|||||||
return {
|
return {
|
||||||
startTyped: startTyped,
|
startTyped: startTyped,
|
||||||
installAnnotationCheckboxes: installAnnotationCheckboxes,
|
installAnnotationCheckboxes: installAnnotationCheckboxes,
|
||||||
debugDumpViewerDom: debugDumpViewerDom,
|
|
||||||
initialize: initialize,
|
initialize: initialize,
|
||||||
initializeTyped: initializeTyped,
|
initializeTyped: initializeTyped,
|
||||||
initializeImage: initializeImage,
|
initializeImage: initializeImage,
|
||||||
|
|||||||
Reference in New Issue
Block a user