parser_x.js 1.0.10 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parser_x.js +2 -2
- package/package.json +3 -2
- package/ofd_viewer_bak.txt +0 -744
package/ofd_viewer_bak.txt
DELETED
|
@@ -1,744 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE,
|
|
3
|
-
getVisibleElements, isPortraitOrientation, isValidRotation, isValidScrollMode, isValidSpreadMode, MAX_AUTO_SCALE,
|
|
4
|
-
MAX_SCALE,
|
|
5
|
-
MIN_SCALE,
|
|
6
|
-
RenderingStates,
|
|
7
|
-
SCROLLBAR_PADDING, ScrollMode, SpreadMode, VERTICAL_PADDING,
|
|
8
|
-
watchScroll
|
|
9
|
-
} from "./ui_utils";
|
|
10
|
-
import {getHighestPriority} from "./ofd_render_queue";
|
|
11
|
-
import {Ofd_Render} from "./ofd_render";
|
|
12
|
-
import {OfdCanvasRender} from "./ofd_canvas_render";
|
|
13
|
-
import {Ofd_Core_Helper} from "./ofd_core_helper";
|
|
14
|
-
|
|
15
|
-
class OfdViewer {
|
|
16
|
-
constructor(container, viewer, eventBus) {
|
|
17
|
-
|
|
18
|
-
this.coreHelper = new Ofd_Core_Helper()
|
|
19
|
-
this.ofdRender = new Ofd_Render(null, this.coreHelper)
|
|
20
|
-
this.ofdCanvasRender = new OfdCanvasRender(null, this.coreHelper)
|
|
21
|
-
this.eventBus = eventBus
|
|
22
|
-
this.container = container
|
|
23
|
-
this.viewer = viewer
|
|
24
|
-
this._currentScaleValue = DEFAULT_SCALE_VALUE
|
|
25
|
-
this.pageDIV = []
|
|
26
|
-
this._currentScale = 1
|
|
27
|
-
this._spreadMode = SpreadMode.NONE
|
|
28
|
-
this._scrollMode = ScrollMode.VERTICAL
|
|
29
|
-
this._pagesRotation = 0;
|
|
30
|
-
this.currentPage = 1
|
|
31
|
-
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
|
|
32
|
-
this.eventBus.dispatch("pagechanging", {
|
|
33
|
-
source: this,
|
|
34
|
-
pageNumber: 1,
|
|
35
|
-
pageLabel: null,
|
|
36
|
-
previous: 1,
|
|
37
|
-
});
|
|
38
|
-
this.eventBus._on("jumpPage", this.jumpPage.bind(this));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get currentScaleValue() {
|
|
42
|
-
return this._currentScaleValue;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
set currentScaleValue(val) {
|
|
46
|
-
if (!this.core) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
this._setScale(val, false);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getOfdCore() {
|
|
53
|
-
return this.core
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
emptyNode(node) {
|
|
57
|
-
if (node) {
|
|
58
|
-
while (node.firstChild) node.removeChild(node.firstChild);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
_scrollUpdate() {
|
|
63
|
-
if (this.pageCount === 0) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.updateView()
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
_getVisiblePages() {
|
|
70
|
-
// if (this.isInPresentationMode) {
|
|
71
|
-
// // The algorithm in `getVisibleElements` doesn't work in all browsers and
|
|
72
|
-
// // configurations (e.g. Chrome) when PresentationMode is active.
|
|
73
|
-
// return this._getCurrentVisiblePage();
|
|
74
|
-
// }
|
|
75
|
-
const views = this.pageDIV,
|
|
76
|
-
// this._scrollMode === ScrollMode.PAGE
|
|
77
|
-
// ? this.#scrollModePageState.pages
|
|
78
|
-
// : this._pages,
|
|
79
|
-
horizontal = false,
|
|
80
|
-
rtl = horizontal;
|
|
81
|
-
|
|
82
|
-
return getVisibleElements({
|
|
83
|
-
scrollEl: this.container,
|
|
84
|
-
views,
|
|
85
|
-
sortByVisibility: true,
|
|
86
|
-
horizontal,
|
|
87
|
-
rtl,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
renderHighestPriority(currentlyVisiblePages) {
|
|
92
|
-
if (this.forceRendering(currentlyVisiblePages)) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getScrollAhead(visible) {
|
|
98
|
-
if (!!visible.first && visible.first.id === 1) {
|
|
99
|
-
return true;
|
|
100
|
-
} else if (!!visible.last && visible.last.id === this.pageCount) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
switch (this._scrollMode) {
|
|
104
|
-
case ScrollMode.PAGE:
|
|
105
|
-
// return this.#scrollModePageState.scrollDown;
|
|
106
|
-
case ScrollMode.HORIZONTAL:
|
|
107
|
-
return scroll.right;
|
|
108
|
-
}
|
|
109
|
-
return scroll.down;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async forceRendering(currentlyVisiblePages) {
|
|
113
|
-
const visiblePages = currentlyVisiblePages || this._getVisiblePages();
|
|
114
|
-
const scrollAhead = this.getScrollAhead(visiblePages);
|
|
115
|
-
const preRenderExtra =
|
|
116
|
-
this._spreadMode !== SpreadMode.NONE &&
|
|
117
|
-
this._scrollMode !== ScrollMode.HORIZONTAL;
|
|
118
|
-
|
|
119
|
-
const pageView = getHighestPriority(
|
|
120
|
-
visiblePages,
|
|
121
|
-
this.pageDIV,
|
|
122
|
-
scrollAhead,
|
|
123
|
-
);
|
|
124
|
-
// this.#toggleLoadingIconSpinner(visiblePages.ids);
|
|
125
|
-
|
|
126
|
-
if (pageView && pageView.renderingState === RenderingStates.INITIAL) {
|
|
127
|
-
this.emptyNode(pageView.div.firstChild);
|
|
128
|
-
await this.ofdRender.renderPage(pageView.div.firstChild, 0, pageView.id - 1)
|
|
129
|
-
let that = this
|
|
130
|
-
for (let ele of document.getElementsByName(`seal_img_div_${pageView.id - 1}`)) {
|
|
131
|
-
ele.addEventListener('click', function () {
|
|
132
|
-
that.eventBus.dispatch("signatureclick", {
|
|
133
|
-
source: that,
|
|
134
|
-
pageRef: ele.dataset.pageRef,
|
|
135
|
-
signatureId: ele.dataset.signatureId,
|
|
136
|
-
});
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
pageView.renderingState = RenderingStates.FINISHED
|
|
142
|
-
this.renderHighestPriority()
|
|
143
|
-
// const ratio = 1;
|
|
144
|
-
// let canvas = document.createElement('canvas');
|
|
145
|
-
// const ctx = canvas.getContext("2d");
|
|
146
|
-
// canvas.style.height = pageView.div.firstChild.style.height;
|
|
147
|
-
// canvas.style.width = pageView.div.firstChild.style.width;
|
|
148
|
-
// canvas.width = pageView.div.firstChild.style.width.replace('px','')*ratio
|
|
149
|
-
// canvas.height = pageView.div.firstChild.style.height.replace('px','')*ratio
|
|
150
|
-
// const image = document.createElement("img");
|
|
151
|
-
// image.className = "thumbnailImage";
|
|
152
|
-
// image.style.width = pageView.div.firstChild.style.width;
|
|
153
|
-
// image.style.height = pageView.div.firstChild.style.height;
|
|
154
|
-
// pageView.div.firstChild.appendChild(image)
|
|
155
|
-
// this.ofdCanvasRender.renderPageByCanvas(canvas, ctx, 0, pageView.id - 1).then(r => {
|
|
156
|
-
// const dataURL = canvas.toDataURL();
|
|
157
|
-
// image.src = dataURL
|
|
158
|
-
// pageView.renderingState = RenderingStates.FINISHED
|
|
159
|
-
// this.renderHighestPriority()
|
|
160
|
-
// })
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
updateView() {
|
|
167
|
-
const visible = this._getVisiblePages();
|
|
168
|
-
const visiblePages = visible.views,
|
|
169
|
-
numVisiblePages = visiblePages.length;
|
|
170
|
-
|
|
171
|
-
if (numVisiblePages === 0) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
this.renderHighestPriority(visible)
|
|
175
|
-
// if (!this.isInPresentationMode) {
|
|
176
|
-
const isSimpleLayout = true
|
|
177
|
-
let currentId = this.currentPage;
|
|
178
|
-
let stillFullyVisible = false;
|
|
179
|
-
|
|
180
|
-
for (const page of visiblePages) {
|
|
181
|
-
if (page.percent < 100) {
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
if (page.id === currentId && isSimpleLayout) {
|
|
185
|
-
stillFullyVisible = true;
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (!stillFullyVisible) {
|
|
190
|
-
currentId = visiblePages[0].id;
|
|
191
|
-
}
|
|
192
|
-
this._setCurrentPageNumber(currentId);
|
|
193
|
-
// }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
logError(where, error) {
|
|
197
|
-
console.log("ofd." + where + ": " + error);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
showDocumentError(where, error) {
|
|
201
|
-
this.logError(where, error);
|
|
202
|
-
let div = document.createElement("div");
|
|
203
|
-
div.classList.add("error");
|
|
204
|
-
div.textContent = error;
|
|
205
|
-
this.emptyNode(this.viewer);
|
|
206
|
-
this.viewer.appendChild(div);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
resetPageScale() {
|
|
210
|
-
if (!this.core)
|
|
211
|
-
return
|
|
212
|
-
this.coreHelper.setDpi(96 * this._currentScale)
|
|
213
|
-
this.initDiv(this._pagesRotation)
|
|
214
|
-
this.updateView();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
initDiv(rotation, onlyRotation = false) {
|
|
218
|
-
let pagesDiv = this.viewer
|
|
219
|
-
let transX, transY;
|
|
220
|
-
if (!onlyRotation) {
|
|
221
|
-
this.pageDIV = []
|
|
222
|
-
this.emptyNode(pagesDiv);
|
|
223
|
-
for (let i = 0; i < this.pageCount; ++i) {
|
|
224
|
-
let div = document.createElement("div");
|
|
225
|
-
div.classList.add("page");
|
|
226
|
-
div.id = "page_" + i;
|
|
227
|
-
const width = this.coreHelper.pageRenderWidth(0, i, this.core);
|
|
228
|
-
const height = this.coreHelper.pageRenderHeight(0, i, this.core)
|
|
229
|
-
div.style.width = width + "px";
|
|
230
|
-
div.style.height = height + "px";
|
|
231
|
-
div.style.overflow = 'hidden';
|
|
232
|
-
div.style.position = 'relative'
|
|
233
|
-
let contentDiv = document.createElement("div");
|
|
234
|
-
switch (rotation) {
|
|
235
|
-
case 0:
|
|
236
|
-
div.style.width = width + "px";
|
|
237
|
-
div.style.height = height + "px";
|
|
238
|
-
transX = transY = 0;
|
|
239
|
-
break
|
|
240
|
-
case 90:
|
|
241
|
-
div.style.width = height + "px";
|
|
242
|
-
div.style.height = width + "px";
|
|
243
|
-
transX = transY = (width - height) / 2;
|
|
244
|
-
break
|
|
245
|
-
case 180:
|
|
246
|
-
div.style.width = width + "px";
|
|
247
|
-
div.style.height = height + "px";
|
|
248
|
-
transX = transY = 0;
|
|
249
|
-
break
|
|
250
|
-
case 270:
|
|
251
|
-
div.style.width = height + "px";
|
|
252
|
-
div.style.height = width + "px";
|
|
253
|
-
transX = transY = -(width - height) / 2;
|
|
254
|
-
break
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
contentDiv.style.width = width + "px";
|
|
258
|
-
contentDiv.style.height = height + "px";
|
|
259
|
-
contentDiv.style.overflow = 'hidden';
|
|
260
|
-
contentDiv.style.transform =
|
|
261
|
-
`rotate(${rotation}deg) ` +
|
|
262
|
-
`translate(${transX}px, ${transY}px)`;
|
|
263
|
-
div.appendChild(contentDiv)
|
|
264
|
-
pagesDiv.appendChild(div);
|
|
265
|
-
contentDiv.appendChild(this.initLoadingImg());
|
|
266
|
-
this.pageDIV[i] = {
|
|
267
|
-
div,
|
|
268
|
-
id: i + 1,
|
|
269
|
-
renderingState: RenderingStates.INITIAL,
|
|
270
|
-
scale: this._currentScale,
|
|
271
|
-
width,
|
|
272
|
-
height
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
} else {
|
|
276
|
-
for (let i = 0; i < this.pageCount; ++i) {
|
|
277
|
-
let div = this.pageDIV[i].div
|
|
278
|
-
let contentDiv = div.firstChild
|
|
279
|
-
const width = this.coreHelper.pageRenderWidth(0, i, this.core);
|
|
280
|
-
const height = this.coreHelper.pageRenderHeight(0, i, this.core);
|
|
281
|
-
switch (rotation) {
|
|
282
|
-
case 0:
|
|
283
|
-
div.style.width = width + "px";
|
|
284
|
-
div.style.height = height + "px";
|
|
285
|
-
transX = transY = 0;
|
|
286
|
-
break
|
|
287
|
-
case 90:
|
|
288
|
-
div.style.width = height + "px";
|
|
289
|
-
div.style.height = width + "px";
|
|
290
|
-
transX = transY = (width - height) / 2;
|
|
291
|
-
break
|
|
292
|
-
case 180:
|
|
293
|
-
div.style.width = width + "px";
|
|
294
|
-
div.style.height = height + "px";
|
|
295
|
-
transX = transY = 0;
|
|
296
|
-
break
|
|
297
|
-
case 270:
|
|
298
|
-
div.style.width = height + "px";
|
|
299
|
-
div.style.height = width + "px";
|
|
300
|
-
transX = transY = -(width - height) / 2;
|
|
301
|
-
break
|
|
302
|
-
}
|
|
303
|
-
contentDiv.style.width = width + "px";
|
|
304
|
-
contentDiv.style.height = height + "px";
|
|
305
|
-
contentDiv.style.overflow = 'hidden';
|
|
306
|
-
contentDiv.style.transform =
|
|
307
|
-
`rotate(${rotation}deg) ` +
|
|
308
|
-
`translate(${transX}px, ${transY}px)`;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
this.jumpPage({pageIndex: this.currentPage})
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
get currentPageNumber() {
|
|
315
|
-
return this.currentPage;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
_setCurrentPageNumber(val, resetCurrentPageView = false) {
|
|
319
|
-
if (this.currentPage === val) {
|
|
320
|
-
// if (resetCurrentPageView) {
|
|
321
|
-
// _resetCurrentPageView();
|
|
322
|
-
// }
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if (!(0 < val && val <= this.pageCount)) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
const previous = this.currentPage;
|
|
330
|
-
this.currentPage = val;
|
|
331
|
-
|
|
332
|
-
this.eventBus.dispatch("pagechanging", {
|
|
333
|
-
source: this,
|
|
334
|
-
pageNumber: val,
|
|
335
|
-
pageLabel: null,
|
|
336
|
-
previous,
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// if (resetCurrentPageView) {
|
|
340
|
-
// this._resetCurrentPageView();
|
|
341
|
-
// }
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
_scrollUpdate() {
|
|
346
|
-
if (this.pageCount === 0) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
this.updateView()
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
setRotation(rotation) {
|
|
353
|
-
rotation += this._pagesRotation
|
|
354
|
-
if (!isValidRotation(rotation)) {
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
rotation %= 360;
|
|
358
|
-
if (rotation < 0) {
|
|
359
|
-
rotation += 360;
|
|
360
|
-
}
|
|
361
|
-
if (this._pagesRotation === rotation) {
|
|
362
|
-
return; // The rotation didn't change.
|
|
363
|
-
}
|
|
364
|
-
if (!this.core)
|
|
365
|
-
return
|
|
366
|
-
this._pagesRotation = rotation
|
|
367
|
-
this.initDiv(this._pagesRotation, true)
|
|
368
|
-
this.updateView()
|
|
369
|
-
this._updateSpreadMode(/* pageNumber = */ this.currentPage);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
increaseScale(steps = 1) {
|
|
373
|
-
let newScale = this._currentScale;
|
|
374
|
-
do {
|
|
375
|
-
newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2);
|
|
376
|
-
newScale = Math.ceil(newScale * 10) / 10;
|
|
377
|
-
newScale = Math.min(MAX_SCALE, newScale);
|
|
378
|
-
} while (--steps > 0 && newScale < MAX_SCALE);
|
|
379
|
-
this._setScale(newScale)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Decrease the current zoom level one, or more, times.
|
|
384
|
-
* @param {number} [steps] - Defaults to zooming once.
|
|
385
|
-
*/
|
|
386
|
-
decreaseScale(steps = 1) {
|
|
387
|
-
let newScale = this._currentScale;
|
|
388
|
-
do {
|
|
389
|
-
newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2);
|
|
390
|
-
newScale = Math.floor(newScale * 10) / 10;
|
|
391
|
-
newScale = Math.max(MIN_SCALE, newScale);
|
|
392
|
-
} while (--steps > 0 && newScale > MIN_SCALE);
|
|
393
|
-
this._setScale(newScale)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
zoom(value) {
|
|
397
|
-
this._setScale(value)
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
_setScale(value, noScroll = false) {
|
|
401
|
-
let scale = parseFloat(value);
|
|
402
|
-
|
|
403
|
-
if (scale > 0) {
|
|
404
|
-
this._setScaleUpdatePages(scale, value, noScroll, /* preset = */ false);
|
|
405
|
-
} else {
|
|
406
|
-
const currentPage = this.pageDIV[0];
|
|
407
|
-
if (!currentPage) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
let hPadding = SCROLLBAR_PADDING,
|
|
411
|
-
vPadding = VERTICAL_PADDING;
|
|
412
|
-
|
|
413
|
-
// if (this.isInPresentationMode) {
|
|
414
|
-
// hPadding = vPadding = 4;
|
|
415
|
-
// } else if (this.removePageBorders) {
|
|
416
|
-
// hPadding = vPadding = 0;
|
|
417
|
-
// }
|
|
418
|
-
// if (this._scrollMode === ScrollMode.HORIZONTAL) {
|
|
419
|
-
// [hPadding, vPadding] = [vPadding, hPadding]; // Swap the padding values.
|
|
420
|
-
// }
|
|
421
|
-
const pageWidthScale =
|
|
422
|
-
(((this.container.clientWidth - hPadding) / currentPage.width) *
|
|
423
|
-
currentPage.scale) /
|
|
424
|
-
1;
|
|
425
|
-
const pageHeightScale =
|
|
426
|
-
((this.container.clientHeight - vPadding) / currentPage.height) *
|
|
427
|
-
currentPage.scale;
|
|
428
|
-
switch (value) {
|
|
429
|
-
case "page-actual":
|
|
430
|
-
scale = 1;
|
|
431
|
-
break;
|
|
432
|
-
case "page-width":
|
|
433
|
-
scale = pageWidthScale;
|
|
434
|
-
break;
|
|
435
|
-
case "page-height":
|
|
436
|
-
scale = pageHeightScale;
|
|
437
|
-
break;
|
|
438
|
-
case "page-fit":
|
|
439
|
-
scale = Math.min(pageWidthScale, pageHeightScale);
|
|
440
|
-
break;
|
|
441
|
-
case "auto":
|
|
442
|
-
// For pages in landscape mode, fit the page height to the viewer
|
|
443
|
-
// *unless* the page would thus become too wide to fit horizontally.
|
|
444
|
-
const horizontalScale = isPortraitOrientation(currentPage)
|
|
445
|
-
? pageWidthScale
|
|
446
|
-
: Math.min(pageHeightScale, pageWidthScale);
|
|
447
|
-
scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
|
|
448
|
-
break;
|
|
449
|
-
default:
|
|
450
|
-
console.error(`_setScale: "${value}" is an unknown zoom value.`);
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
this._setScaleUpdatePages(scale, value, noScroll, /* preset = */ true);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
isSameScale(newScale) {
|
|
458
|
-
return (
|
|
459
|
-
newScale === this._currentScale ||
|
|
460
|
-
Math.abs(newScale - this._currentScale) < 1e-15
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
_setScaleUpdatePages(newScale, newValue, noScroll = false, preset = false) {
|
|
465
|
-
this._currentScaleValue = newValue.toString();
|
|
466
|
-
if (this.isSameScale(newScale)) {
|
|
467
|
-
if (preset) {
|
|
468
|
-
this.eventBus.dispatch("scalechanging", {
|
|
469
|
-
source: this,
|
|
470
|
-
scale: newScale,
|
|
471
|
-
presetValue: newValue,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
this._currentScale = newScale;
|
|
477
|
-
this.resetPageScale()
|
|
478
|
-
this._updateSpreadMode(/* pageNumber = */ this.currentPage);
|
|
479
|
-
// if (!noScroll) {
|
|
480
|
-
// let page = this._currentPageNumber,
|
|
481
|
-
// dest;
|
|
482
|
-
// if (
|
|
483
|
-
// this._location &&
|
|
484
|
-
// !(this.isInPresentationMode || this.isChangingPresentationMode)
|
|
485
|
-
// ) {
|
|
486
|
-
// page = this._location.pageNumber;
|
|
487
|
-
// dest = [
|
|
488
|
-
// null,
|
|
489
|
-
// { name: "XYZ" },
|
|
490
|
-
// this._location.left,
|
|
491
|
-
// this._location.top,
|
|
492
|
-
// null,
|
|
493
|
-
// ];
|
|
494
|
-
// }
|
|
495
|
-
// this.scrollPageIntoView({
|
|
496
|
-
// pageNumber: page,
|
|
497
|
-
// destArray: dest,
|
|
498
|
-
// allowNegativeOffset: true,
|
|
499
|
-
// });
|
|
500
|
-
// }
|
|
501
|
-
//
|
|
502
|
-
this.eventBus.dispatch("scalechanging", {
|
|
503
|
-
source: this,
|
|
504
|
-
scale: newScale,
|
|
505
|
-
presetValue: preset ? newValue : undefined,
|
|
506
|
-
});
|
|
507
|
-
//
|
|
508
|
-
// if (this.defaultRenderingQueue) {
|
|
509
|
-
// this.update();
|
|
510
|
-
// }
|
|
511
|
-
//
|
|
512
|
-
// this.#previousContainerHeight = this.container.clientHeight;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
setSpreadMode(mode) {
|
|
516
|
-
if (this._spreadMode === mode) {
|
|
517
|
-
return; // The Spread mode didn't change.
|
|
518
|
-
}
|
|
519
|
-
if (!isValidSpreadMode(mode)) {
|
|
520
|
-
throw new Error(`Invalid spread mode: ${mode}`);
|
|
521
|
-
}
|
|
522
|
-
this._spreadMode = mode;
|
|
523
|
-
this.eventBus.dispatch("spreadmodechanged", {source: this, mode});
|
|
524
|
-
|
|
525
|
-
this._updateSpreadMode(/* pageNumber = */ this.currentPage);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
_updateSpreadMode(pageNumber = null) {
|
|
529
|
-
const pages = this.pageDIV;
|
|
530
|
-
|
|
531
|
-
if (this._scrollMode === ScrollMode.PAGE) {
|
|
532
|
-
// this.#ensurePageViewVisible();
|
|
533
|
-
} else {
|
|
534
|
-
// Temporarily remove all the pages from the DOM.
|
|
535
|
-
this.viewer.textContent = "";
|
|
536
|
-
|
|
537
|
-
if (this._spreadMode === SpreadMode.NONE) {
|
|
538
|
-
for (let i = 0, ii = pages.length; i < ii; ++i) {
|
|
539
|
-
this.viewer.appendChild(pages[i].div);
|
|
540
|
-
}
|
|
541
|
-
} else {
|
|
542
|
-
const parity = this._spreadMode - 1;
|
|
543
|
-
let spread = null;
|
|
544
|
-
for (let i = 0, ii = pages.length; i < ii; ++i) {
|
|
545
|
-
if (spread === null) {
|
|
546
|
-
spread = document.createElement("div");
|
|
547
|
-
spread.className = "spread";
|
|
548
|
-
this.viewer.appendChild(spread);
|
|
549
|
-
} else if (i % 2 === parity) {
|
|
550
|
-
spread = spread.cloneNode(false);
|
|
551
|
-
this.viewer.appendChild(spread);
|
|
552
|
-
}
|
|
553
|
-
spread.appendChild(pages[i].div);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (!pageNumber) {
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
// Non-numeric scale values can be sensitive to the scroll orientation.
|
|
562
|
-
// Call this before re-scrolling to the current page, to ensure that any
|
|
563
|
-
// changes in scale don't move the current page.
|
|
564
|
-
if (this._currentScale && isNaN(this._currentScale)) {
|
|
565
|
-
this._setScale(this._currentScale, true);
|
|
566
|
-
}
|
|
567
|
-
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
568
|
-
this.updateView();
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
setScrollMode(mode) {
|
|
572
|
-
if (this._scrollMode === mode) {
|
|
573
|
-
return; // The Scroll mode didn't change.
|
|
574
|
-
}
|
|
575
|
-
if (!isValidScrollMode(mode)) {
|
|
576
|
-
throw new Error(`Invalid scroll mode: ${mode}`);
|
|
577
|
-
}
|
|
578
|
-
if (this.pageCount > 15000) {
|
|
579
|
-
return; // Disabled for performance reasons.
|
|
580
|
-
}
|
|
581
|
-
this._previousScrollMode = this._scrollMode;
|
|
582
|
-
|
|
583
|
-
this._scrollMode = mode;
|
|
584
|
-
this.eventBus.dispatch("scrollmodechanged", {source: this, mode});
|
|
585
|
-
|
|
586
|
-
this._updateScrollMode(/* pageNumber = */ this.currentPage);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
_updateScrollMode(pageNumber = null) {
|
|
590
|
-
const scrollMode = this._scrollMode;
|
|
591
|
-
|
|
592
|
-
this.viewer.classList.toggle(
|
|
593
|
-
"scrollHorizontal",
|
|
594
|
-
scrollMode === ScrollMode.HORIZONTAL
|
|
595
|
-
);
|
|
596
|
-
this.viewer.classList.toggle("scrollWrapped", scrollMode === ScrollMode.WRAPPED);
|
|
597
|
-
|
|
598
|
-
if (!this.core) {
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (scrollMode === ScrollMode.PAGE) {
|
|
603
|
-
// this.#ensurePageViewVisible();
|
|
604
|
-
} else if (this._previousScrollMode === ScrollMode.PAGE) {
|
|
605
|
-
// Ensure that the current spreadMode is still applied correctly when
|
|
606
|
-
// the *previous* scrollMode was `ScrollMode.PAGE`.
|
|
607
|
-
this._updateSpreadMode();
|
|
608
|
-
}
|
|
609
|
-
// Non-numeric scale values can be sensitive to the scroll orientation.
|
|
610
|
-
// Call this before re-scrolling to the current page, to ensure that any
|
|
611
|
-
// changes in scale don't move the current page.
|
|
612
|
-
if (this._currentScale && isNaN(this._currentScale)) {
|
|
613
|
-
this._setScale(this._currentScale, true);
|
|
614
|
-
}
|
|
615
|
-
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
|
|
616
|
-
this.updateView();
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
firstPage() {
|
|
620
|
-
let ele = this.viewer.children.item(0);
|
|
621
|
-
ele.scrollIntoView(true);
|
|
622
|
-
// currentPage = 1;
|
|
623
|
-
return true;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
lastPage() {
|
|
627
|
-
let ele = this.viewer.children.item(this.pageCount - 1);
|
|
628
|
-
ele.scrollIntoView(true);
|
|
629
|
-
// currentPage = pageCount;
|
|
630
|
-
return true;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Go to the next page, taking scroll/spread-modes into account.
|
|
635
|
-
* @returns {boolean} Whether navigation occured.
|
|
636
|
-
*/
|
|
637
|
-
nextPage() {
|
|
638
|
-
const currentPageNumber = this.currentPage,
|
|
639
|
-
pagesCount = this.pageCount;
|
|
640
|
-
|
|
641
|
-
if (currentPageNumber >= pagesCount) {
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
let ele = this.viewer.children.item(currentPageNumber);
|
|
645
|
-
ele.scrollIntoView(true);
|
|
646
|
-
// const advance =
|
|
647
|
-
// this._getPageAdvance(currentPageNumber, /* previous = */ false) || 1;
|
|
648
|
-
// currentPage = Math.min(currentPageNumber, pagesCount);
|
|
649
|
-
return true;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
/**
|
|
653
|
-
* Go to the previous page, taking scroll/spread-modes into account.
|
|
654
|
-
* @returns {boolean} Whether navigation occured.
|
|
655
|
-
*/
|
|
656
|
-
previousPage() {
|
|
657
|
-
const currentPageNumber = this.currentPage;
|
|
658
|
-
|
|
659
|
-
if (currentPageNumber <= 1) {
|
|
660
|
-
return false;
|
|
661
|
-
}
|
|
662
|
-
let ele = this.viewer.children.item(currentPageNumber - 2);
|
|
663
|
-
ele.scrollIntoView(true);
|
|
664
|
-
// currentPage = Math.max(currentPageNumber-1, 1);
|
|
665
|
-
// console.log(currentPage)
|
|
666
|
-
return true;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
jumpPage(evt) {
|
|
671
|
-
let ele = this.viewer.children.item(evt.pageIndex - 1);
|
|
672
|
-
ele.scrollIntoView(true);
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
freeDocument() {
|
|
676
|
-
this.currentPage = 1
|
|
677
|
-
this.pageCount = 0;
|
|
678
|
-
this.pageDIV = [];
|
|
679
|
-
this.emptyNode(this.viewer);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
initLoadingImg() {
|
|
683
|
-
let img = new Image();
|
|
684
|
-
img.style.position = 'absolute';
|
|
685
|
-
img.style.left = 0;
|
|
686
|
-
img.style.right = 0;
|
|
687
|
-
img.style.margin = 'auto';
|
|
688
|
-
img.style.top = 0;
|
|
689
|
-
img.style.bottom = 0;
|
|
690
|
-
img.src = 'data:image/gif;base64,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';
|
|
691
|
-
img.draggable = false;
|
|
692
|
-
return img;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
setWaterText(text) {
|
|
696
|
-
this.coreHelper.setWaterText(text)
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
setOfdCore(core) {
|
|
700
|
-
this.core = core
|
|
701
|
-
this.ofdRender.setOfdCore(this.core)
|
|
702
|
-
this.ofdCanvasRender.setOfdCore(this.core)
|
|
703
|
-
this._spreadMode = SpreadMode.NONE
|
|
704
|
-
this._scrollMode = ScrollMode.VERTICAL
|
|
705
|
-
this._pagesRotation = 0;
|
|
706
|
-
this.pageCount = this.core.getOFDPageCount(0)
|
|
707
|
-
// initThumbnail(getOfdData(), eventbus)
|
|
708
|
-
this.eventBus.dispatch("pagechanging", {
|
|
709
|
-
source: this,
|
|
710
|
-
pageNumber: 1,
|
|
711
|
-
pageLabel: null,
|
|
712
|
-
previous: 1,
|
|
713
|
-
});
|
|
714
|
-
let pagesDiv = this.viewer;
|
|
715
|
-
pagesDiv.scrollTo(0, 0);
|
|
716
|
-
let hPadding = SCROLLBAR_PADDING,
|
|
717
|
-
vPadding = VERTICAL_PADDING
|
|
718
|
-
const pageWidth = this.container.clientWidth - hPadding;
|
|
719
|
-
const actualCoreHelper = new Ofd_Core_Helper(96);
|
|
720
|
-
const pageWidthScale =
|
|
721
|
-
(((this.container.clientWidth - hPadding) / actualCoreHelper.pageRenderWidth(0, 0, this.core)) *
|
|
722
|
-
1) /
|
|
723
|
-
1;
|
|
724
|
-
const horizontalScale = pageWidthScale;
|
|
725
|
-
let scale = Math.min(MAX_AUTO_SCALE, horizontalScale);
|
|
726
|
-
this._currentScale = scale
|
|
727
|
-
this.coreHelper.setDpi(96 * scale)
|
|
728
|
-
// let dpi = pageWidth / this.core.pageWidth(0, 0) * 25.4
|
|
729
|
-
// this.coreHelper.setDpi(dpi)
|
|
730
|
-
this.initDiv()
|
|
731
|
-
this.updateView();
|
|
732
|
-
this.eventBus.dispatch("scalechanging", {
|
|
733
|
-
source: this,
|
|
734
|
-
scale: scale,
|
|
735
|
-
presetValue: 'auto',
|
|
736
|
-
});
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
export {OfdViewer}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|