@progress/kendo-pdfviewer-common 0.2.8 → 0.2.9-dev.202402161623
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/es/search.js +5 -5
- package/dist/es/utils.js +1 -1
- package/dist/es2015/search.js +5 -5
- package/dist/es2015/utils.js +1 -1
- package/dist/npm/scroller.js +1 -0
- package/dist/npm/search.js +6 -5
- package/dist/npm/utils.d.ts +4 -4
- package/dist/npm/utils.js +29 -18
- package/package.json +14 -8
package/dist/es/search.js
CHANGED
|
@@ -70,11 +70,11 @@ export class SearchService {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
escapeRegExp(text) {
|
|
73
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g,
|
|
73
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
74
74
|
}
|
|
75
75
|
search({ text, matchCase }) {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const escapedText = this.escapeRegExp(text);
|
|
77
|
+
const searchRegex = new RegExp(escapedText, matchCase ? 'g' : 'ig');
|
|
78
78
|
let match;
|
|
79
79
|
if (this.shouldTransformText()) {
|
|
80
80
|
this.transformTextForSearch();
|
|
@@ -203,9 +203,9 @@ export class SearchService {
|
|
|
203
203
|
const matches = Array.from(textContainer.querySelectorAll(toClassSelector(this.options.charClass +
|
|
204
204
|
'[' +
|
|
205
205
|
MATCH_INDEX_DATA_ATTR +
|
|
206
|
-
|
|
206
|
+
'=\'' +
|
|
207
207
|
this.state.activeMatchIndex +
|
|
208
|
-
|
|
208
|
+
'\']')));
|
|
209
209
|
matches.forEach((match) => {
|
|
210
210
|
wrapInnerElement(match, mark.cloneNode(true));
|
|
211
211
|
});
|
package/dist/es/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { saveAs } from '@progress/kendo-file-saver';
|
|
2
|
-
import { detectDesktopBrowser, detectMobileOS } from
|
|
2
|
+
import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
|
|
3
3
|
import { getDocument, renderTextLayer } from 'pdfjs-dist';
|
|
4
4
|
const MAX_CANVAS_WIDTH_HEIGHT_CHROME = 65535;
|
|
5
5
|
const MAX_CANVAS_AREA_CHROME_SAFARI = 268435456;
|
package/dist/es2015/search.js
CHANGED
|
@@ -70,11 +70,11 @@ export class SearchService {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
escapeRegExp(text) {
|
|
73
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g,
|
|
73
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
74
74
|
}
|
|
75
75
|
search({ text, matchCase }) {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
const escapedText = this.escapeRegExp(text);
|
|
77
|
+
const searchRegex = new RegExp(escapedText, matchCase ? 'g' : 'ig');
|
|
78
78
|
let match;
|
|
79
79
|
if (this.shouldTransformText()) {
|
|
80
80
|
this.transformTextForSearch();
|
|
@@ -203,9 +203,9 @@ export class SearchService {
|
|
|
203
203
|
const matches = Array.from(textContainer.querySelectorAll(toClassSelector(this.options.charClass +
|
|
204
204
|
'[' +
|
|
205
205
|
MATCH_INDEX_DATA_ATTR +
|
|
206
|
-
|
|
206
|
+
'=\'' +
|
|
207
207
|
this.state.activeMatchIndex +
|
|
208
|
-
|
|
208
|
+
'\']')));
|
|
209
209
|
matches.forEach((match) => {
|
|
210
210
|
wrapInnerElement(match, mark.cloneNode(true));
|
|
211
211
|
});
|
package/dist/es2015/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { saveAs } from '@progress/kendo-file-saver';
|
|
2
|
-
import { detectDesktopBrowser, detectMobileOS } from
|
|
2
|
+
import { detectDesktopBrowser, detectMobileOS } from '@progress/kendo-common';
|
|
3
3
|
import { getDocument, renderTextLayer } from 'pdfjs-dist';
|
|
4
4
|
const MAX_CANVAS_WIDTH_HEIGHT_CHROME = 65535;
|
|
5
5
|
const MAX_CANVAS_AREA_CHROME_SAFARI = 268435456;
|
package/dist/npm/scroller.js
CHANGED
package/dist/npm/search.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SearchService = void 0;
|
|
3
4
|
const unwrapElement = (element) => {
|
|
4
5
|
const parentElement = element.parentElement;
|
|
5
6
|
if (!element || !parentElement) {
|
|
@@ -72,11 +73,11 @@ class SearchService {
|
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
escapeRegExp(text) {
|
|
75
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g,
|
|
76
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
76
77
|
}
|
|
77
78
|
search({ text, matchCase }) {
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const escapedText = this.escapeRegExp(text);
|
|
80
|
+
const searchRegex = new RegExp(escapedText, matchCase ? 'g' : 'ig');
|
|
80
81
|
let match;
|
|
81
82
|
if (this.shouldTransformText()) {
|
|
82
83
|
this.transformTextForSearch();
|
|
@@ -205,9 +206,9 @@ class SearchService {
|
|
|
205
206
|
const matches = Array.from(textContainer.querySelectorAll(toClassSelector(this.options.charClass +
|
|
206
207
|
'[' +
|
|
207
208
|
MATCH_INDEX_DATA_ATTR +
|
|
208
|
-
|
|
209
|
+
'=\'' +
|
|
209
210
|
this.state.activeMatchIndex +
|
|
210
|
-
|
|
211
|
+
'\']')));
|
|
211
212
|
matches.forEach((match) => {
|
|
212
213
|
wrapInnerElement(match, mark.cloneNode(true));
|
|
213
214
|
});
|
package/dist/npm/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { TypedArray } from 'pdfjs-dist/types/src/display/api';
|
|
|
4
4
|
/**
|
|
5
5
|
* @hidden
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type DoneFn = (result: {
|
|
8
8
|
pdfPages: PDFPageProxy[];
|
|
9
9
|
pdfDoc: PDFDocumentProxy;
|
|
10
10
|
zoom: number;
|
|
@@ -12,7 +12,7 @@ export declare type DoneFn = (result: {
|
|
|
12
12
|
/**
|
|
13
13
|
* @hidden
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type ErrorFn = (e?: any) => void;
|
|
16
16
|
/**
|
|
17
17
|
* @hidden
|
|
18
18
|
*/
|
|
@@ -53,7 +53,7 @@ export declare const removeChildren: (dom: HTMLElement) => void;
|
|
|
53
53
|
* @hidden
|
|
54
54
|
*/
|
|
55
55
|
export declare const download: (options: {
|
|
56
|
-
pdf:
|
|
56
|
+
pdf: PDFDocumentProxy | null;
|
|
57
57
|
error: ErrorFn;
|
|
58
58
|
}, fileName: string, saveOptions: SaveOptions, onDownload: (blob: Blob, fileName: string, saveOptions: SaveOptions) => boolean) => void;
|
|
59
59
|
/**
|
|
@@ -67,7 +67,7 @@ export declare const reloadDocument: (params: PDFReloadParameters) => void;
|
|
|
67
67
|
/**
|
|
68
68
|
* @hidden
|
|
69
69
|
*/
|
|
70
|
-
export declare const print: (pages:
|
|
70
|
+
export declare const print: (pages: PDFPageProxy[], done: () => void, error: ErrorFn) => void;
|
|
71
71
|
/**
|
|
72
72
|
* @hidden
|
|
73
73
|
*/
|
package/dist/npm/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.currentPage = exports.scrollToPage = exports.calculateZoomLevel = exports.goToPreviousSearchMatch = exports.goToNextSearchMatch = exports.print = exports.reloadDocument = exports.loadPDF = exports.download = exports.removeChildren = exports.DEFAULT_ZOOM_LEVEL = void 0;
|
|
3
4
|
const kendo_file_saver_1 = require("@progress/kendo-file-saver");
|
|
4
5
|
const kendo_common_1 = require("@progress/kendo-common");
|
|
5
6
|
const pdfjs_dist_1 = require("pdfjs-dist");
|
|
@@ -13,12 +14,12 @@ const isIOS = () => /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.m
|
|
|
13
14
|
navigator.maxTouchPoints > 2 &&
|
|
14
15
|
/Macintosh/i.test(navigator.userAgent));
|
|
15
16
|
const isSafari = (userAgent) => {
|
|
16
|
-
return kendo_common_1.detectDesktopBrowser(userAgent).safari ||
|
|
17
|
-
(kendo_common_1.detectMobileOS(userAgent) && kendo_common_1.detectMobileOS(userAgent).browser === 'mobilesafari');
|
|
17
|
+
return (0, kendo_common_1.detectDesktopBrowser)(userAgent).safari ||
|
|
18
|
+
((0, kendo_common_1.detectMobileOS)(userAgent) && (0, kendo_common_1.detectMobileOS)(userAgent).browser === 'mobilesafari');
|
|
18
19
|
};
|
|
19
20
|
const isFirefox = (userAgent) => {
|
|
20
|
-
const desktopBrowser = kendo_common_1.detectDesktopBrowser(userAgent);
|
|
21
|
-
const mobileOS = kendo_common_1.detectMobileOS(userAgent);
|
|
21
|
+
const desktopBrowser = (0, kendo_common_1.detectDesktopBrowser)(userAgent);
|
|
22
|
+
const mobileOS = (0, kendo_common_1.detectMobileOS)(userAgent);
|
|
22
23
|
return (desktopBrowser && desktopBrowser.mozilla) || (mobileOS && mobileOS.browser === 'firefox');
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
@@ -50,28 +51,29 @@ const getDocumentParameters = (options) => {
|
|
|
50
51
|
/**
|
|
51
52
|
* @hidden
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
|
+
const removeChildren = (dom) => {
|
|
54
55
|
while (dom.firstChild) {
|
|
55
56
|
dom.removeChild(dom.firstChild);
|
|
56
57
|
}
|
|
57
58
|
};
|
|
59
|
+
exports.removeChildren = removeChildren;
|
|
58
60
|
const appendPage = (dom, page, index) => {
|
|
59
61
|
if (index === 0) {
|
|
60
|
-
exports.removeChildren(dom);
|
|
62
|
+
(0, exports.removeChildren)(dom);
|
|
61
63
|
}
|
|
62
64
|
dom.appendChild(page);
|
|
63
65
|
};
|
|
64
66
|
/**
|
|
65
67
|
* @hidden
|
|
66
68
|
*/
|
|
67
|
-
|
|
69
|
+
const download = (options, fileName = 'Document', saveOptions = {}, onDownload) => {
|
|
68
70
|
if (options.pdf) {
|
|
69
71
|
options.pdf
|
|
70
72
|
.getData()
|
|
71
73
|
.then((data) => new Blob([data], { type: 'application/pdf' }))
|
|
72
74
|
.then((blob) => {
|
|
73
75
|
if (!onDownload(blob, fileName, saveOptions)) {
|
|
74
|
-
kendo_file_saver_1.saveAs(blob, fileName, saveOptions);
|
|
76
|
+
(0, kendo_file_saver_1.saveAs)(blob, fileName, saveOptions);
|
|
75
77
|
}
|
|
76
78
|
})
|
|
77
79
|
.catch((reason) => {
|
|
@@ -79,13 +81,14 @@ exports.download = (options, fileName = 'Document', saveOptions = {}, onDownload
|
|
|
79
81
|
});
|
|
80
82
|
}
|
|
81
83
|
};
|
|
84
|
+
exports.download = download;
|
|
82
85
|
/**
|
|
83
86
|
* @hidden
|
|
84
87
|
*/
|
|
85
|
-
|
|
88
|
+
const loadPDF = (options) => {
|
|
86
89
|
const params = getDocumentParameters(options);
|
|
87
90
|
const { dom, zoom, done, error } = options;
|
|
88
|
-
pdfjs_dist_1.getDocument(params)
|
|
91
|
+
(0, pdfjs_dist_1.getDocument)(params)
|
|
89
92
|
.promise.then((pdfDoc) => {
|
|
90
93
|
const pages = [];
|
|
91
94
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
|
@@ -110,10 +113,11 @@ exports.loadPDF = (options) => {
|
|
|
110
113
|
options.error(reason);
|
|
111
114
|
});
|
|
112
115
|
};
|
|
116
|
+
exports.loadPDF = loadPDF;
|
|
113
117
|
/**
|
|
114
118
|
* @hidden
|
|
115
119
|
*/
|
|
116
|
-
|
|
120
|
+
const reloadDocument = (params) => {
|
|
117
121
|
const { pdfDoc, zoom, dom, done, error } = params;
|
|
118
122
|
const pages = [];
|
|
119
123
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
|
@@ -127,10 +131,11 @@ exports.reloadDocument = (params) => {
|
|
|
127
131
|
.then(done)
|
|
128
132
|
.catch(error);
|
|
129
133
|
};
|
|
134
|
+
exports.reloadDocument = reloadDocument;
|
|
130
135
|
/**
|
|
131
136
|
* @hidden
|
|
132
137
|
*/
|
|
133
|
-
|
|
138
|
+
const print = (pages, done, error) => {
|
|
134
139
|
const dom = document.createElement('div');
|
|
135
140
|
const dones = pages.map(() => false);
|
|
136
141
|
const scaleNum = scale();
|
|
@@ -144,6 +149,7 @@ exports.print = (pages, done, error) => {
|
|
|
144
149
|
}, error);
|
|
145
150
|
});
|
|
146
151
|
};
|
|
152
|
+
exports.print = print;
|
|
147
153
|
const openPrintDialog = (dom, width, height, done, onError) => {
|
|
148
154
|
const printDialog = window.open('', '', 'innerWidth=' +
|
|
149
155
|
width +
|
|
@@ -206,7 +212,7 @@ const renderPage = (page, zoom, error) => {
|
|
|
206
212
|
.promise.then(() => {
|
|
207
213
|
page.getTextContent().then((textContent) => {
|
|
208
214
|
const textLayer = createElement('div', 'k-text-layer', styles);
|
|
209
|
-
pdfjs_dist_1.renderTextLayer({
|
|
215
|
+
(0, pdfjs_dist_1.renderTextLayer)({
|
|
210
216
|
textContentSource: textContent,
|
|
211
217
|
container: textLayer,
|
|
212
218
|
viewport: viewport,
|
|
@@ -263,23 +269,25 @@ const scrollToSearchMatch = (matchElement, ref) => {
|
|
|
263
269
|
/**
|
|
264
270
|
* @hidden
|
|
265
271
|
*/
|
|
266
|
-
|
|
272
|
+
const goToNextSearchMatch = (ref) => {
|
|
267
273
|
ref.search.markNextMatch();
|
|
268
274
|
const matchElement = ref.search.getActiveMatchElement();
|
|
269
275
|
scrollToSearchMatch(matchElement, ref);
|
|
270
276
|
};
|
|
277
|
+
exports.goToNextSearchMatch = goToNextSearchMatch;
|
|
271
278
|
/**
|
|
272
279
|
* @hidden
|
|
273
280
|
*/
|
|
274
|
-
|
|
281
|
+
const goToPreviousSearchMatch = (ref) => {
|
|
275
282
|
ref.search.markPreviousMatch();
|
|
276
283
|
const matchElement = ref.search.getActiveMatchElement();
|
|
277
284
|
scrollToSearchMatch(matchElement, ref);
|
|
278
285
|
};
|
|
286
|
+
exports.goToPreviousSearchMatch = goToPreviousSearchMatch;
|
|
279
287
|
/**
|
|
280
288
|
* @hidden
|
|
281
289
|
*/
|
|
282
|
-
|
|
290
|
+
const calculateZoomLevel = (zoomLevel, zoomLevelType, currentZoom, dom) => {
|
|
283
291
|
const documentContainer = dom.closest('.k-pdf-viewer-canvas');
|
|
284
292
|
const page = dom.querySelector('.k-page');
|
|
285
293
|
const pageSize = { width: page.offsetWidth, height: page.offsetHeight };
|
|
@@ -297,13 +305,14 @@ exports.calculateZoomLevel = (zoomLevel, zoomLevelType, currentZoom, dom) => {
|
|
|
297
305
|
}
|
|
298
306
|
return calculatedZoomLevel;
|
|
299
307
|
};
|
|
308
|
+
exports.calculateZoomLevel = calculateZoomLevel;
|
|
300
309
|
/**
|
|
301
310
|
* Scrolls the PDFViewer document to the passed page number.
|
|
302
311
|
*
|
|
303
312
|
* @param rootElement The root HTML element of the PDFViewer component.
|
|
304
313
|
* @param pageNumber The page number.
|
|
305
314
|
*/
|
|
306
|
-
|
|
315
|
+
const scrollToPage = (rootElement, pageNumber) => {
|
|
307
316
|
const pages = rootElement.querySelectorAll('.k-page');
|
|
308
317
|
const page = pages[0];
|
|
309
318
|
if (page instanceof HTMLDivElement) {
|
|
@@ -315,13 +324,14 @@ exports.scrollToPage = (rootElement, pageNumber) => {
|
|
|
315
324
|
}
|
|
316
325
|
}
|
|
317
326
|
};
|
|
327
|
+
exports.scrollToPage = scrollToPage;
|
|
318
328
|
/**
|
|
319
329
|
* A function which gives you the page number of the document according to the scroll position.
|
|
320
330
|
*
|
|
321
331
|
* @param rootElement The root HTML element of the PDFViewer component.
|
|
322
332
|
* @returns The page number.
|
|
323
333
|
*/
|
|
324
|
-
|
|
334
|
+
const currentPage = (rootElement) => {
|
|
325
335
|
const scrollElement = rootElement.querySelector('.k-pdf-viewer-canvas');
|
|
326
336
|
const page = rootElement.querySelector('.k-page');
|
|
327
337
|
return scrollElement && page
|
|
@@ -330,6 +340,7 @@ exports.currentPage = (rootElement) => {
|
|
|
330
340
|
0.01)
|
|
331
341
|
: 0;
|
|
332
342
|
};
|
|
343
|
+
exports.currentPage = currentPage;
|
|
333
344
|
/**
|
|
334
345
|
* @hidden
|
|
335
346
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progress/kendo-pdfviewer-common",
|
|
3
3
|
"description": "Kendo UI TypeScript package exporting functions for PDFViewer component",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.9-dev.202402161623",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Kendo UI"
|
|
7
7
|
],
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "jest",
|
|
16
16
|
"test:ci": "jest",
|
|
17
17
|
"start": "gulp start",
|
|
18
|
-
"lint": "
|
|
18
|
+
"lint": "eslint .",
|
|
19
19
|
"api-check": "gulp api-check",
|
|
20
20
|
"build-package": "gulp build-ts-package",
|
|
21
21
|
"semantic-release": "semantic-release pre && semantic-prerelease publish --public && semantic-release post"
|
|
@@ -32,18 +32,23 @@
|
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@progress/kendo-draggable": "^3.0.0",
|
|
34
34
|
"@progress/kendo-file-saver": "^1.1.1",
|
|
35
|
-
"@progress/kendo-typescript-tasks": "^
|
|
35
|
+
"@progress/kendo-typescript-tasks": "^11.0.0",
|
|
36
36
|
"@progress/semantic-prerelease": "^3.0.0",
|
|
37
37
|
"@types/jasmine": "~2.2.0",
|
|
38
38
|
"@types/jest": "^23.3.14",
|
|
39
39
|
"cz-conventional-changelog": "^1.1.5",
|
|
40
|
+
"eslint": "^8.56.0",
|
|
41
|
+
"eslint-plugin-jest": "^27.8.0",
|
|
42
|
+
"eslint-plugin-jsdoc": "^48.1.0",
|
|
43
|
+
"eslint-plugin-typescript": "^0.14.0",
|
|
40
44
|
"ghooks": "^1.0.3",
|
|
41
45
|
"gulp": "^4.0.0",
|
|
42
|
-
"jest": "^
|
|
43
|
-
"jest-
|
|
46
|
+
"jest": "^29.7.0",
|
|
47
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
44
48
|
"semantic-release": "^6.3.6",
|
|
45
|
-
"ts-jest": "^
|
|
46
|
-
"typescript": "~
|
|
49
|
+
"ts-jest": "^29.1.2",
|
|
50
|
+
"typescript": "~5.1.3",
|
|
51
|
+
"typescript-eslint": "^7.0.1",
|
|
47
52
|
"validate-commit-msg": "^1.1.1"
|
|
48
53
|
},
|
|
49
54
|
"config": {
|
|
@@ -70,7 +75,8 @@
|
|
|
70
75
|
}
|
|
71
76
|
},
|
|
72
77
|
"jest": {
|
|
73
|
-
"preset": "jest
|
|
78
|
+
"preset": "ts-jest",
|
|
79
|
+
"testEnvironment": "jsdom"
|
|
74
80
|
},
|
|
75
81
|
"repository": {
|
|
76
82
|
"type": "git",
|