mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 15:58:49 +01:00
This commit is contained in:
parent
b1b84bb5e2
commit
5ad353f238
16 changed files with 1677 additions and 1006 deletions
|
|
@ -440,6 +440,11 @@ export class Asset extends Model {
|
|||
<input id="editorInkColor">
|
||||
<input id="editorInkThickness">
|
||||
<input id="editorInkOpacity">
|
||||
<input id="download">
|
||||
<input id="secondaryDownload">
|
||||
<input id="editorFreeText">
|
||||
<input id="openFile">
|
||||
<input id="editorInk">
|
||||
</div>
|
||||
</div> <!-- outerContainer -->
|
||||
<div id="printContainer"></div>`;
|
||||
|
|
|
|||
|
|
@ -688,7 +688,7 @@ class PDFViewerApplication {
|
|||
get loadingBar() {
|
||||
// NOTE
|
||||
const bar = new ProgressBar(this.appConfig.appContainer.querySelector("#loadingBar"))
|
||||
return shadow(this, 'loadingBar', bar)
|
||||
return shadow(this, "loadingBar", bar);
|
||||
}
|
||||
|
||||
get supportedMouseWheelZoomModifierKeys() {
|
||||
|
|
@ -894,7 +894,11 @@ class PDFViewerApplication {
|
|||
}
|
||||
// Set the necessary API parameters, using all the available options.
|
||||
const apiParams = AppOptions.getAll(OptionKind.API);
|
||||
const params = { ...apiParams, ...args };
|
||||
const params = {
|
||||
canvasMaxAreaInBytes: this.externalServices.canvasMaxAreaInBytes,
|
||||
...apiParams,
|
||||
...args,
|
||||
};
|
||||
|
||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||
params.docBaseUrl ||= document.URL.split("#")[0];
|
||||
|
|
@ -930,18 +934,18 @@ class PDFViewerApplication {
|
|||
return undefined; // Ignore errors for previously opened PDF files.
|
||||
}
|
||||
|
||||
// NOTE
|
||||
let key = 'loadingError'
|
||||
let key = "loadingError";
|
||||
if (reason instanceof InvalidPDFException) {
|
||||
key = 'invalidFileError'
|
||||
key = "invalidFileError";
|
||||
} else if (reason instanceof MissingPDFException) {
|
||||
key = 'missingFileError'
|
||||
key = "missingFileError";
|
||||
} else if (reason instanceof UnexpectedResponseException) {
|
||||
key = 'unexpectedResponseError'
|
||||
key = "unexpectedResponseError";
|
||||
}
|
||||
// NOTE
|
||||
this._documentError(window.siyuan.languages[key], {message: reason?.message})
|
||||
throw reason
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1114,20 +1118,17 @@ class PDFViewerApplication {
|
|||
this.toolbar?.setPagesCount(pdfDocument.numPages, false);
|
||||
this.secondaryToolbar?.setPagesCount(pdfDocument.numPages);
|
||||
|
||||
let baseDocumentUrl;
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
baseDocumentUrl = null;
|
||||
} else if (PDFJSDev.test("MOZCENTRAL")) {
|
||||
baseDocumentUrl = this.baseUrl;
|
||||
} else if (PDFJSDev.test("CHROME")) {
|
||||
baseDocumentUrl = location.href.split("#")[0];
|
||||
}
|
||||
if (baseDocumentUrl && isDataScheme(baseDocumentUrl)) {
|
||||
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
|
||||
const baseUrl = location.href.split("#")[0];
|
||||
// Ignore "data:"-URLs for performance reasons, even though it may cause
|
||||
// internal links to not work perfectly in all cases (see bug 1803050).
|
||||
baseDocumentUrl = null;
|
||||
this.pdfLinkService.setDocument(
|
||||
pdfDocument,
|
||||
isDataScheme(baseUrl) ? null : baseUrl
|
||||
);
|
||||
} else {
|
||||
this.pdfLinkService.setDocument(pdfDocument);
|
||||
}
|
||||
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
||||
this.pdfDocumentProperties?.setDocument(pdfDocument);
|
||||
|
||||
const pdfViewer = this.pdfViewer;
|
||||
|
|
@ -2121,7 +2122,7 @@ async function loadFakeWorker() {
|
|||
|
||||
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
|
||||
// NOTE
|
||||
window.pdfjsWorker = await import(`${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=3.4.120`)
|
||||
window.pdfjsWorker = await import(`${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=3.5.141`)
|
||||
return;
|
||||
}
|
||||
await loadScript(PDFWorker.workerSrc);
|
||||
|
|
@ -2202,23 +2203,19 @@ function webViewerInitialized(pdf) {
|
|||
|
||||
if (!pdf.supportsDocumentFonts) {
|
||||
AppOptions.set("disableFontFace", true);
|
||||
// NOTE
|
||||
console.warn('Web fonts are disabled: unable to use embedded PDF fonts.')
|
||||
}
|
||||
|
||||
if (!pdf.supportsPrinting) {
|
||||
// NOTE
|
||||
appConfig.toolbar?.print.classList.add("fn__hidden");
|
||||
appConfig.secondaryToolbar?.printButton.classList.add("fn__hidden");
|
||||
}
|
||||
|
||||
if (!pdf.supportsFullscreen) {
|
||||
// NOTE
|
||||
appConfig.secondaryToolbar?.presentationModeButton.classList.add("fn__hidden");
|
||||
}
|
||||
|
||||
if (pdf.supportsIntegratedFind) {
|
||||
// NOTE
|
||||
appConfig.toolbar?.viewFind.classList.add("fn__hidden");
|
||||
}
|
||||
|
||||
|
|
@ -2488,23 +2485,21 @@ function webViewerHashchange(evt) {
|
|||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
// eslint-disable-next-line no-var
|
||||
var webViewerFileInputChange = function (evt) {
|
||||
// NOTE
|
||||
// if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
|
||||
// return; // Opening a new PDF file isn't supported in Presentation Mode.
|
||||
// }
|
||||
// const file = evt.fileInput.files[0];
|
||||
//
|
||||
// PDFViewerApplication.open({
|
||||
// url: URL.createObjectURL(file),
|
||||
// originalUrl: file.name,
|
||||
// });
|
||||
if (PDFViewerApplication.pdfViewer?.isInPresentationMode) {
|
||||
return; // Opening a new PDF file isn't supported in Presentation Mode.
|
||||
}
|
||||
const file = evt.fileInput.files[0];
|
||||
|
||||
PDFViewerApplication.open({
|
||||
url: URL.createObjectURL(file),
|
||||
originalUrl: file.name,
|
||||
});
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
var webViewerOpenFile = function (evt) {
|
||||
// NOTE
|
||||
// const fileInput = PDFViewerApplication.appConfig.openFileInput;
|
||||
// fileInput.click();
|
||||
const fileInput = PDFViewerApplication.appConfig.openFileInput;
|
||||
fileInput.click();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -2640,12 +2635,12 @@ function webViewerPageNumberChanged(evt) {
|
|||
// Ensure that the page number input displays the correct value, even if the
|
||||
// value entered by the user was invalid (e.g. a floating point number).
|
||||
if (
|
||||
evt.value !== pdfViewer.currentPageNumber.toString() &&
|
||||
evt.value !== pdfViewer.currentPageLabel
|
||||
evt.value !== pdfViewer.currentPageNumber.toString() &&
|
||||
evt.value !== pdfViewer.currentPageLabel
|
||||
) {
|
||||
pdfInstance.toolbar?.setPageNumber(
|
||||
pdfViewer.currentPageNumber,
|
||||
pdfViewer.currentPageLabel
|
||||
pdfViewer.currentPageNumber,
|
||||
pdfViewer.currentPageLabel
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -3102,7 +3097,7 @@ function webViewerTouchMove(evt) {
|
|||
}
|
||||
}
|
||||
|
||||
pdfInstance._centerAtPos(
|
||||
PDFViewerApplication._centerAtPos(
|
||||
previousScale,
|
||||
(page0X + page1X) / 2,
|
||||
(page0Y + page1Y) / 2
|
||||
|
|
@ -3132,8 +3127,8 @@ function webViewerClick(evt) {
|
|||
return
|
||||
}
|
||||
|
||||
// 点击后证快捷键可正常使用,select 也可正常使用 https://github.com/siyuan-note/siyuan/issues/7869
|
||||
if (evt.target.tagName !== "SELECT") {
|
||||
// 点击后证快捷键可正常使用,select 等也可正常使用 https://github.com/siyuan-note/siyuan/issues/7869
|
||||
if (!["SELECT", "TEXTAREA", "INPUT"].includes(evt.target.tagName)) {
|
||||
pdfInstance.pdfViewer.focus();
|
||||
}
|
||||
|
||||
|
|
@ -3142,9 +3137,9 @@ function webViewerClick(evt) {
|
|||
}
|
||||
const appConfig = pdfInstance.appConfig;
|
||||
if (
|
||||
pdfInstance.pdfViewer.containsElement(evt.target) ||
|
||||
(appConfig.toolbar?.container.contains(evt.target) &&
|
||||
!appConfig.secondaryToolbar.toggleButton.contains(evt.target)) // NOTE
|
||||
pdfInstance.pdfViewer.containsElement(evt.target) ||
|
||||
(appConfig.toolbar?.container.contains(evt.target) &&
|
||||
!appConfig.secondaryToolbar.toggleButton.contains(evt.target)) // NOTE
|
||||
) {
|
||||
pdfInstance.secondaryToolbar.close();
|
||||
}
|
||||
|
|
@ -3160,6 +3155,7 @@ function webViewerKeyUp(evt) {
|
|||
if (evt.key === "Control") {
|
||||
pdfInstance._isCtrlKeyDown = false;
|
||||
}
|
||||
// 快捷键高亮取消
|
||||
if (evt.keyCode === 68 && pdfInstance.appConfig.toolbar.rectAnno.classList.contains('toggled')) {
|
||||
pdfInstance.appConfig.toolbar.rectAnno.dispatchEvent(
|
||||
new MouseEvent('click'))
|
||||
|
|
@ -3260,7 +3256,7 @@ function webViewerKeyDown(evt) {
|
|||
isViewerInPresentationMode ||
|
||||
pdfInstance.page < pdfInstance.pagesCount
|
||||
) {
|
||||
pdfInstance.page = pdfInstance.pagesCount;
|
||||
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
|
||||
handled = true;
|
||||
ensureViewerFocused = true;
|
||||
}
|
||||
|
|
@ -3519,9 +3515,9 @@ const PDFPrintServiceFactory = {
|
|||
},
|
||||
};
|
||||
|
||||
// NOTE
|
||||
export {
|
||||
PDFPrintServiceFactory,
|
||||
PDFViewerApplication,
|
||||
// NOTE
|
||||
webViewerPageNumberChanged,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -279,7 +279,7 @@ const defaultOptions = {
|
|||
workerSrc: {
|
||||
/** @type {string} */
|
||||
// NOTE
|
||||
value: `${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=3.4.120`,
|
||||
value: `${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=3.5.141`,
|
||||
kind: OptionKind.WORKER,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ function formatL10nValue(text, args) {
|
|||
if (!args) {
|
||||
return text;
|
||||
}
|
||||
return text.replace(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
||||
return text.replaceAll(/\{\{\s*(\w+)\s*\}\}/g, (all, name) => {
|
||||
return name in args ? args[name] : "{{" + name + "}}";
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,21 +289,26 @@ function normalize(text) {
|
|||
// "X-\n" is removed because an hyphen at the end of a line
|
||||
// with not a space before is likely here to mark a break
|
||||
// in a word.
|
||||
// The \n isn't in the original text so here y = i, n = 1 and o = 2.
|
||||
positions.push([i - shift + 1, 1 + shift]);
|
||||
// If X is encoded with UTF-32 then it can have a length greater than 1.
|
||||
// The \n isn't in the original text so here y = i, n = X.len - 2 and
|
||||
// o = X.len - 1.
|
||||
const len = p5.length - 2;
|
||||
positions.push([i - shift + len, 1 + shift]);
|
||||
shift += 1;
|
||||
shiftOrigin += 1;
|
||||
eol += 1;
|
||||
return p5.charAt(0);
|
||||
return p5.slice(0, -2);
|
||||
}
|
||||
|
||||
if (p6) {
|
||||
// An ideographic at the end of a line doesn't imply adding an extra
|
||||
// white space.
|
||||
positions.push([i - shift + 1, shift]);
|
||||
// A CJK can be encoded in UTF-32, hence their length isn't always 1.
|
||||
const len = p6.length - 1;
|
||||
positions.push([i - shift + len, shift]);
|
||||
shiftOrigin += 1;
|
||||
eol += 1;
|
||||
return p6.charAt(0);
|
||||
return p6.slice(0, -1);
|
||||
}
|
||||
|
||||
if (p7) {
|
||||
|
|
@ -364,7 +369,7 @@ function getOriginalIndex(diffs, pos, len) {
|
|||
* @typedef {Object} PDFFindControllerOptions
|
||||
* @property {IPDFLinkService} linkService - The navigation/linking service.
|
||||
* @property {EventBus} eventBus - The application event bus.
|
||||
* @property {boolean} updateMatchesCountOnProgress - True if the matches
|
||||
* @property {boolean} [updateMatchesCountOnProgress] - True if the matches
|
||||
* count must be updated on progress or only when the last page is reached.
|
||||
* The default value is `true`.
|
||||
*/
|
||||
|
|
@ -658,7 +663,7 @@ class PDFFindController {
|
|||
#convertToRegExpString(query, hasDiacritics) {
|
||||
const { matchDiacritics } = this._state;
|
||||
let isUnicode = false;
|
||||
query = query.replace(
|
||||
query = query.replaceAll(
|
||||
SPECIAL_CHARS_REG_EXP,
|
||||
(
|
||||
match,
|
||||
|
|
|
|||
|
|
@ -336,7 +336,7 @@ class PDFLinkService {
|
|||
* @returns {string} The hyperlink to the PDF object.
|
||||
*/
|
||||
getAnchorUrl(anchor) {
|
||||
return (this.baseUrl || "") + anchor;
|
||||
return this.baseUrl ? this.baseUrl + anchor : anchor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -352,7 +352,7 @@ class PDFLinkService {
|
|||
if (params.has("search")) {
|
||||
this.eventBus.dispatch("findfromurlhash", {
|
||||
source: this,
|
||||
query: params.get("search").replace(/"/g, ""),
|
||||
query: params.get("search").replaceAll('"', ""),
|
||||
phraseSearch: params.get("phrase") === "true",
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -606,14 +606,13 @@ class PDFPageView {
|
|||
isScalingRestricted = true;
|
||||
}
|
||||
}
|
||||
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000;
|
||||
const onlyCssZoom =
|
||||
this.useOnlyCssZoom || (this.hasRestrictedScaling && isScalingRestricted);
|
||||
const postponeDrawing =
|
||||
!onlyCssZoom && drawingDelay >= 0 && drawingDelay < 1000;
|
||||
|
||||
if (this.canvas) {
|
||||
if (
|
||||
postponeDrawing ||
|
||||
this.useOnlyCssZoom ||
|
||||
(this.hasRestrictedScaling && isScalingRestricted)
|
||||
) {
|
||||
if (postponeDrawing || onlyCssZoom) {
|
||||
if (
|
||||
postponeDrawing &&
|
||||
this.renderingState !== RenderingStates.FINISHED
|
||||
|
|
@ -758,10 +757,7 @@ class PDFPageView {
|
|||
scaleX = height / width;
|
||||
scaleY = width / height;
|
||||
}
|
||||
|
||||
if (absRotation !== 0) {
|
||||
target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
|
||||
}
|
||||
target.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX}, ${scaleY})`;
|
||||
}
|
||||
|
||||
if (redrawAnnotationLayer && this.annotationLayer) {
|
||||
|
|
@ -1001,8 +997,14 @@ class PDFPageView {
|
|||
// is complete when `!this.renderingQueue`, to prevent black flickering.
|
||||
canvas.hidden = true;
|
||||
let isCanvasHidden = true;
|
||||
const showCanvas = function () {
|
||||
if (isCanvasHidden) {
|
||||
const hasHCM = !!(
|
||||
this.pageColors?.background && this.pageColors?.foreground
|
||||
);
|
||||
const showCanvas = function (isLastShow) {
|
||||
// In HCM, a final filter is applied on the canvas which means that
|
||||
// before it's applied we've normal colors. Consequently, to avoid to have
|
||||
// a final flash we just display it once all the drawing is done.
|
||||
if (isCanvasHidden && (!hasHCM || isLastShow)) {
|
||||
canvas.hidden = false;
|
||||
isCanvasHidden = false;
|
||||
}
|
||||
|
|
@ -1063,7 +1065,7 @@ class PDFPageView {
|
|||
};
|
||||
const renderTask = this.pdfPage.render(renderContext);
|
||||
renderTask.onContinue = function (cont) {
|
||||
showCanvas();
|
||||
showCanvas(false);
|
||||
if (result.onRenderContinue) {
|
||||
result.onRenderContinue(cont);
|
||||
} else {
|
||||
|
|
@ -1073,7 +1075,7 @@ class PDFPageView {
|
|||
|
||||
renderTask.promise.then(
|
||||
function () {
|
||||
showCanvas();
|
||||
showCanvas(true);
|
||||
renderCapability.resolve();
|
||||
},
|
||||
function (error) {
|
||||
|
|
@ -1081,7 +1083,7 @@ class PDFPageView {
|
|||
// a black canvas if rendering was cancelled before the `onContinue`-
|
||||
// callback had been invoked at least once.
|
||||
if (!(error instanceof RenderingCancelledException)) {
|
||||
showCanvas();
|
||||
showCanvas(true);
|
||||
}
|
||||
renderCapability.reject(error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ class PDFSidebarResizer {
|
|||
_updateWidth(width = 0) {
|
||||
// Prevent the sidebar from becoming too narrow, or from occupying more
|
||||
// than half of the available viewer width.
|
||||
// NOTE
|
||||
const maxWidth = Math.floor(this.outerContainerWidth / 3 * 2);
|
||||
const maxWidth = Math.floor(this.outerContainerWidth / 2);
|
||||
if (width > maxWidth) {
|
||||
width = maxWidth;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ class PDFViewer {
|
|||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
this._setScale(val, { noScroll: false });
|
||||
this.#setScale(val, { noScroll: false });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -472,7 +472,7 @@ class PDFViewer {
|
|||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
this._setScale(val, { noScroll: false });
|
||||
this.#setScale(val, { noScroll: false });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -509,7 +509,7 @@ class PDFViewer {
|
|||
// Prevent errors in case the rotation changes *before* the scale has been
|
||||
// set to a non-default value.
|
||||
if (this._currentScaleValue) {
|
||||
this._setScale(this._currentScaleValue, { noScroll: true });
|
||||
this.#setScale(this._currentScaleValue, { noScroll: true });
|
||||
}
|
||||
|
||||
this.eventBus.dispatch("rotationchanging", {
|
||||
|
|
@ -1079,7 +1079,7 @@ class PDFViewer {
|
|||
);
|
||||
}
|
||||
|
||||
_setScaleUpdatePages(
|
||||
#setScaleUpdatePages(
|
||||
newScale,
|
||||
newValue,
|
||||
{ noScroll = false, preset = false, drawingDelay = -1 }
|
||||
|
|
@ -1151,10 +1151,7 @@ class PDFViewer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
get _pageWidthScaleFactor() {
|
||||
get #pageWidthScaleFactor() {
|
||||
if (
|
||||
this._spreadMode !== SpreadMode.NONE &&
|
||||
this._scrollMode !== ScrollMode.HORIZONTAL
|
||||
|
|
@ -1164,12 +1161,12 @@ class PDFViewer {
|
|||
return 1;
|
||||
}
|
||||
|
||||
_setScale(value, options) {
|
||||
#setScale(value, options) {
|
||||
let scale = parseFloat(value);
|
||||
|
||||
if (scale > 0) {
|
||||
options.preset = false;
|
||||
this._setScaleUpdatePages(scale, value, options);
|
||||
this.#setScaleUpdatePages(scale, value, options);
|
||||
} else {
|
||||
const currentPage = this._pages[this._currentPageNumber - 1];
|
||||
if (!currentPage) {
|
||||
|
|
@ -1198,7 +1195,7 @@ class PDFViewer {
|
|||
const pageWidthScale =
|
||||
(((this.container.clientWidth - hPadding) / currentPage.width) *
|
||||
currentPage.scale) /
|
||||
this._pageWidthScaleFactor;
|
||||
this.#pageWidthScaleFactor;
|
||||
const pageHeightScale =
|
||||
((this.container.clientHeight - vPadding) / currentPage.height) *
|
||||
currentPage.scale;
|
||||
|
|
@ -1224,11 +1221,11 @@ class PDFViewer {
|
|||
scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
|
||||
break;
|
||||
default:
|
||||
console.error(`_setScale: "${value}" is an unknown zoom value.`);
|
||||
console.error(`#setScale: "${value}" is an unknown zoom value.`);
|
||||
return;
|
||||
}
|
||||
options.preset = true;
|
||||
this._setScaleUpdatePages(scale, value, options);
|
||||
this.#setScaleUpdatePages(scale, value, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1240,7 +1237,7 @@ class PDFViewer {
|
|||
|
||||
if (this.isInPresentationMode) {
|
||||
// Fixes the case when PDF has different page sizes.
|
||||
this._setScale(this._currentScaleValue, { noScroll: true });
|
||||
this.#setScale(this._currentScaleValue, { noScroll: true });
|
||||
}
|
||||
this.#scrollIntoView(pageView);
|
||||
}
|
||||
|
|
@ -1795,7 +1792,7 @@ class PDFViewer {
|
|||
// Call this before re-scrolling to the current page, to ensure that any
|
||||
// changes in scale don't move the current page.
|
||||
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
||||
this._setScale(this._currentScaleValue, { noScroll: true });
|
||||
this.#setScale(this._currentScaleValue, { noScroll: true });
|
||||
}
|
||||
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
||||
this.update();
|
||||
|
|
@ -1867,7 +1864,7 @@ class PDFViewer {
|
|||
// Call this before re-scrolling to the current page, to ensure that any
|
||||
// changes in scale don't move the current page.
|
||||
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
|
||||
this._setScale(this._currentScaleValue, { noScroll: true });
|
||||
this.#setScale(this._currentScaleValue, { noScroll: true });
|
||||
}
|
||||
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
||||
this.update();
|
||||
|
|
@ -1972,7 +1969,7 @@ class PDFViewer {
|
|||
|
||||
/**
|
||||
* Go to the next page, taking scroll/spread-modes into account.
|
||||
* @returns {boolean} Whether navigation occured.
|
||||
* @returns {boolean} Whether navigation occurred.
|
||||
*/
|
||||
nextPage() {
|
||||
const currentPageNumber = this._currentPageNumber,
|
||||
|
|
@ -1990,7 +1987,7 @@ class PDFViewer {
|
|||
|
||||
/**
|
||||
* Go to the previous page, taking scroll/spread-modes into account.
|
||||
* @returns {boolean} Whether navigation occured.
|
||||
* @returns {boolean} Whether navigation occurred.
|
||||
*/
|
||||
previousPage() {
|
||||
const currentPageNumber = this._currentPageNumber;
|
||||
|
|
@ -2006,83 +2003,58 @@ class PDFViewer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Increase the current zoom level one, or more, times.
|
||||
* @param {Object|null} [options]
|
||||
* @typedef {Object} ChangeScaleOptions
|
||||
* @property {number} [drawingDelay]
|
||||
* @property {number} [scaleFactor]
|
||||
* @property {number} [steps]
|
||||
*/
|
||||
increaseScale(options = null) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
||||
typeof options === "number"
|
||||
) {
|
||||
console.error(
|
||||
"The `increaseScale` method-signature was updated, please use an object instead."
|
||||
);
|
||||
options = { steps: options };
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the current zoom level one, or more, times.
|
||||
* @param {ChangeScaleOptions} [options]
|
||||
*/
|
||||
increaseScale({ drawingDelay, scaleFactor, steps } = {}) {
|
||||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
options ||= Object.create(null);
|
||||
|
||||
let newScale = this._currentScale;
|
||||
if (options.scaleFactor > 1) {
|
||||
newScale = Math.min(
|
||||
MAX_SCALE,
|
||||
Math.round(newScale * options.scaleFactor * 100) / 100
|
||||
);
|
||||
if (scaleFactor > 1) {
|
||||
newScale = Math.round(newScale * scaleFactor * 100) / 100;
|
||||
} else {
|
||||
let steps = options.steps ?? 1;
|
||||
steps ??= 1;
|
||||
do {
|
||||
newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
||||
newScale = Math.ceil(newScale * 10) / 10;
|
||||
newScale = Math.min(MAX_SCALE, newScale);
|
||||
newScale =
|
||||
Math.ceil((newScale * DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
|
||||
} while (--steps > 0 && newScale < MAX_SCALE);
|
||||
}
|
||||
|
||||
options.noScroll = false;
|
||||
this._setScale(newScale, options);
|
||||
this.#setScale(Math.min(MAX_SCALE, newScale), {
|
||||
noScroll: false,
|
||||
drawingDelay,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the current zoom level one, or more, times.
|
||||
* @param {Object|null} [options]
|
||||
* @param {ChangeScaleOptions} [options]
|
||||
*/
|
||||
decreaseScale(options = null) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
|
||||
typeof options === "number"
|
||||
) {
|
||||
console.error(
|
||||
"The `decreaseScale` method-signature was updated, please use an object instead."
|
||||
);
|
||||
options = { steps: options };
|
||||
}
|
||||
|
||||
decreaseScale({ drawingDelay, scaleFactor, steps } = {}) {
|
||||
if (!this.pdfDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
options ||= Object.create(null);
|
||||
|
||||
let newScale = this._currentScale;
|
||||
if (options.scaleFactor > 0 && options.scaleFactor < 1) {
|
||||
newScale = Math.max(
|
||||
MIN_SCALE,
|
||||
Math.round(newScale * options.scaleFactor * 100) / 100
|
||||
);
|
||||
if (scaleFactor > 0 && scaleFactor < 1) {
|
||||
newScale = Math.round(newScale * scaleFactor * 100) / 100;
|
||||
} else {
|
||||
let steps = options.steps ?? 1;
|
||||
steps ??= 1;
|
||||
do {
|
||||
newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
||||
newScale = Math.floor(newScale * 10) / 10;
|
||||
newScale = Math.max(MIN_SCALE, newScale);
|
||||
newScale =
|
||||
Math.floor((newScale / DEFAULT_SCALE_DELTA).toFixed(2) * 10) / 10;
|
||||
} while (--steps > 0 && newScale > MIN_SCALE);
|
||||
}
|
||||
|
||||
options.noScroll = false;
|
||||
this._setScale(newScale, options);
|
||||
this.#setScale(Math.max(MIN_SCALE, newScale), {
|
||||
noScroll: false,
|
||||
drawingDelay,
|
||||
});
|
||||
}
|
||||
|
||||
#updateContainerHeightCss(height = this.container.clientHeight) {
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@
|
|||
|
||||
const {addScriptSync} = require('../../protyle/util/addScript')
|
||||
const {Constants} = require('../../constants')
|
||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/pdf/pdf.js?v=3.4.120`, 'pdfjsScript')
|
||||
addScriptSync(`${Constants.PROTYLE_CDN}/js/pdf/pdf.js?v=3.5.141`, 'pdfjsScript')
|
||||
module.exports = window["pdfjs-dist/build/pdf"];
|
||||
|
|
|
|||
|
|
@ -59,9 +59,8 @@ class SecondaryToolbar {
|
|||
eventName: "presentationmode",
|
||||
close: true,
|
||||
},
|
||||
// NOTE
|
||||
// { element: options.printButton, eventName: "print", close: true },
|
||||
// { element: options.downloadButton, eventName: "download", close: true },
|
||||
{ element: options.printButton, eventName: "print", close: true },
|
||||
{ element: options.downloadButton, eventName: "download", close: true },
|
||||
{ element: options.viewBookmarkButton, eventName: null, close: true },
|
||||
{ element: options.firstPageButton, eventName: "firstpage", close: true },
|
||||
{ element: options.lastPageButton, eventName: "lastpage", close: true },
|
||||
|
|
@ -205,11 +204,7 @@ class SecondaryToolbar {
|
|||
for (const { element, eventName, close, eventDetails } of this.buttons) {
|
||||
element.addEventListener("click", evt => {
|
||||
if (eventName !== null) {
|
||||
const details = { source: this };
|
||||
for (const property in eventDetails) {
|
||||
details[property] = eventDetails[property];
|
||||
}
|
||||
this.eventBus.dispatch(eventName, details);
|
||||
this.eventBus.dispatch(eventName, { source: this, ...eventDetails });
|
||||
}
|
||||
if (close) {
|
||||
this.close();
|
||||
|
|
|
|||
|
|
@ -63,38 +63,36 @@ class Toolbar {
|
|||
{ element: options.next, eventName: "nextpage" },
|
||||
{ element: options.zoomIn, eventName: "zoomin" },
|
||||
{ element: options.zoomOut, eventName: "zoomout" },
|
||||
// NOTE
|
||||
// { element: options.print, eventName: "print" },
|
||||
// { element: options.download, eventName: "download" },
|
||||
// {
|
||||
// element: options.editorFreeTextButton,
|
||||
// eventName: "switchannotationeditormode",
|
||||
// eventDetails: {
|
||||
// get mode() {
|
||||
// const { classList } = options.editorFreeTextButton;
|
||||
// return classList.contains("toggled")
|
||||
// ? AnnotationEditorType.NONE
|
||||
// : AnnotationEditorType.FREETEXT;
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// element: options.editorInkButton,
|
||||
// eventName: "switchannotationeditormode",
|
||||
// eventDetails: {
|
||||
// get mode() {
|
||||
// const { classList } = options.editorInkButton;
|
||||
// return classList.contains("toggled")
|
||||
// ? AnnotationEditorType.NONE
|
||||
// : AnnotationEditorType.INK;
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
{ element: options.print, eventName: "print" },
|
||||
{ element: options.download, eventName: "download" },
|
||||
{
|
||||
element: options.editorFreeTextButton,
|
||||
eventName: "switchannotationeditormode",
|
||||
eventDetails: {
|
||||
get mode() {
|
||||
const { classList } = options.editorFreeTextButton;
|
||||
return classList.contains("toggled")
|
||||
? AnnotationEditorType.NONE
|
||||
: AnnotationEditorType.FREETEXT;
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
element: options.editorInkButton,
|
||||
eventName: "switchannotationeditormode",
|
||||
eventDetails: {
|
||||
get mode() {
|
||||
const { classList } = options.editorInkButton;
|
||||
return classList.contains("toggled")
|
||||
? AnnotationEditorType.NONE
|
||||
: AnnotationEditorType.INK;
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
// NOTE
|
||||
// if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
// this.buttons.push({ element: options.openFile, eventName: "openfile" });
|
||||
// }
|
||||
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||
this.buttons.push({ element: options.openFile, eventName: "openfile" });
|
||||
}
|
||||
this.items = {
|
||||
numPages: options.numPages,
|
||||
pageNumber: options.pageNumber,
|
||||
|
|
@ -152,13 +150,7 @@ class Toolbar {
|
|||
for (const { element, eventName, eventDetails } of this.buttons) {
|
||||
element.addEventListener("click", evt => {
|
||||
if (eventName !== null) {
|
||||
const details = { source: this };
|
||||
if (eventDetails) {
|
||||
for (const property in eventDetails) {
|
||||
details[property] = eventDetails[property];
|
||||
}
|
||||
}
|
||||
this.eventBus.dispatch(eventName, details);
|
||||
this.eventBus.dispatch(eventName, { source: this, ...eventDetails });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,6 @@ function parseQueryString(query) {
|
|||
return params;
|
||||
}
|
||||
|
||||
const NullCharactersRegExp = /\x00/g;
|
||||
const InvisibleCharactersRegExp = /[\x01-\x1F]/g;
|
||||
|
||||
/**
|
||||
|
|
@ -224,9 +223,9 @@ function removeNullCharacters(str, replaceInvisible = false) {
|
|||
return str;
|
||||
}
|
||||
if (replaceInvisible) {
|
||||
str = str.replace(InvisibleCharactersRegExp, " ");
|
||||
str = str.replaceAll(InvisibleCharactersRegExp, " ");
|
||||
}
|
||||
return str.replace(NullCharactersRegExp, "");
|
||||
return str.replaceAll("\x00", "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -706,7 +705,6 @@ class ProgressBar {
|
|||
|
||||
#visible = true;
|
||||
|
||||
// NOTE
|
||||
constructor(bar) {
|
||||
this.#classList = bar.classList;
|
||||
this.#style = bar.style;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
|
||||
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
|
||||
import { AppOptions } from "./app_options.js";
|
||||
import { LinkTarget } from "./pdf_link_service.js";
|
||||
import { PDFViewerApplication } from "./app.js";
|
||||
import { initAnno } from "../anno";
|
||||
|
|
@ -169,7 +168,7 @@ function getViewerConfiguration(element) {
|
|||
? element.querySelector("#fileInput")
|
||||
: null,
|
||||
debuggerScriptPath: "./debugger.js",
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// NOTE
|
||||
|
|
|
|||
823
app/stage/protyle/js/pdf/pdf.js
vendored
823
app/stage/protyle/js/pdf/pdf.js
vendored
File diff suppressed because it is too large
Load diff
1493
app/stage/protyle/js/pdf/pdf.worker.js
vendored
1493
app/stage/protyle/js/pdf/pdf.worker.js
vendored
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue