pdfjs-vue3 0.1.0
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/LICENSE +177 -0
- package/README.md +3 -0
- package/dist/pdfjs-vue3.es.js +615 -0
- package/dist/pdfjs-vue3.umd.js +1 -0
- package/dist/style.css +1 -0
- package/package.json +41 -0
- package/types/PdfHost.vue.d.ts +78 -0
- package/types/index.d.ts +3 -0
- package/types/types.d.ts +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import { defineComponent, ref, watch, onMounted, openBlock, createElementBlock, computed, onBeforeUnmount, createElementVNode, createBlock, unref, createCommentVNode, renderSlot, toDisplayString, shallowRef, Fragment, renderList, withCtx, nextTick } from "vue";
|
|
2
|
+
import { renderTextLayer, getDocument, GlobalWorkerOptions } from "pdfjs-dist";
|
|
3
|
+
var ZoomType = /* @__PURE__ */ ((ZoomType2) => {
|
|
4
|
+
ZoomType2[ZoomType2["Auto"] = 0] = "Auto";
|
|
5
|
+
ZoomType2[ZoomType2["WidthFit"] = 1] = "WidthFit";
|
|
6
|
+
ZoomType2[ZoomType2["PageFit"] = 2] = "PageFit";
|
|
7
|
+
ZoomType2[ZoomType2["Custom"] = 3] = "Custom";
|
|
8
|
+
return ZoomType2;
|
|
9
|
+
})(ZoomType || {});
|
|
10
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
11
|
+
function isObject$2(value) {
|
|
12
|
+
var type = typeof value;
|
|
13
|
+
return value != null && (type == "object" || type == "function");
|
|
14
|
+
}
|
|
15
|
+
var isObject_1 = isObject$2;
|
|
16
|
+
var freeGlobal$1 = typeof commonjsGlobal == "object" && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
|
17
|
+
var _freeGlobal = freeGlobal$1;
|
|
18
|
+
var freeGlobal = _freeGlobal;
|
|
19
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
20
|
+
var root$2 = freeGlobal || freeSelf || Function("return this")();
|
|
21
|
+
var _root = root$2;
|
|
22
|
+
var root$1 = _root;
|
|
23
|
+
var now$1 = function() {
|
|
24
|
+
return root$1.Date.now();
|
|
25
|
+
};
|
|
26
|
+
var now_1 = now$1;
|
|
27
|
+
var reWhitespace = /\s/;
|
|
28
|
+
function trimmedEndIndex$1(string) {
|
|
29
|
+
var index = string.length;
|
|
30
|
+
while (index-- && reWhitespace.test(string.charAt(index))) {
|
|
31
|
+
}
|
|
32
|
+
return index;
|
|
33
|
+
}
|
|
34
|
+
var _trimmedEndIndex = trimmedEndIndex$1;
|
|
35
|
+
var trimmedEndIndex = _trimmedEndIndex;
|
|
36
|
+
var reTrimStart = /^\s+/;
|
|
37
|
+
function baseTrim$1(string) {
|
|
38
|
+
return string ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, "") : string;
|
|
39
|
+
}
|
|
40
|
+
var _baseTrim = baseTrim$1;
|
|
41
|
+
var root = _root;
|
|
42
|
+
var Symbol$3 = root.Symbol;
|
|
43
|
+
var _Symbol = Symbol$3;
|
|
44
|
+
var Symbol$2 = _Symbol;
|
|
45
|
+
var objectProto$1 = Object.prototype;
|
|
46
|
+
var hasOwnProperty = objectProto$1.hasOwnProperty;
|
|
47
|
+
var nativeObjectToString$1 = objectProto$1.toString;
|
|
48
|
+
var symToStringTag$1 = Symbol$2 ? Symbol$2.toStringTag : void 0;
|
|
49
|
+
function getRawTag$1(value) {
|
|
50
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag$1), tag = value[symToStringTag$1];
|
|
51
|
+
try {
|
|
52
|
+
value[symToStringTag$1] = void 0;
|
|
53
|
+
var unmasked = true;
|
|
54
|
+
} catch (e) {
|
|
55
|
+
}
|
|
56
|
+
var result = nativeObjectToString$1.call(value);
|
|
57
|
+
if (unmasked) {
|
|
58
|
+
if (isOwn) {
|
|
59
|
+
value[symToStringTag$1] = tag;
|
|
60
|
+
} else {
|
|
61
|
+
delete value[symToStringTag$1];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
var _getRawTag = getRawTag$1;
|
|
67
|
+
var objectProto = Object.prototype;
|
|
68
|
+
var nativeObjectToString = objectProto.toString;
|
|
69
|
+
function objectToString$1(value) {
|
|
70
|
+
return nativeObjectToString.call(value);
|
|
71
|
+
}
|
|
72
|
+
var _objectToString = objectToString$1;
|
|
73
|
+
var Symbol$1 = _Symbol, getRawTag = _getRawTag, objectToString = _objectToString;
|
|
74
|
+
var nullTag = "[object Null]", undefinedTag = "[object Undefined]";
|
|
75
|
+
var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : void 0;
|
|
76
|
+
function baseGetTag$1(value) {
|
|
77
|
+
if (value == null) {
|
|
78
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
79
|
+
}
|
|
80
|
+
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
81
|
+
}
|
|
82
|
+
var _baseGetTag = baseGetTag$1;
|
|
83
|
+
function isObjectLike$1(value) {
|
|
84
|
+
return value != null && typeof value == "object";
|
|
85
|
+
}
|
|
86
|
+
var isObjectLike_1 = isObjectLike$1;
|
|
87
|
+
var baseGetTag = _baseGetTag, isObjectLike = isObjectLike_1;
|
|
88
|
+
var symbolTag = "[object Symbol]";
|
|
89
|
+
function isSymbol$1(value) {
|
|
90
|
+
return typeof value == "symbol" || isObjectLike(value) && baseGetTag(value) == symbolTag;
|
|
91
|
+
}
|
|
92
|
+
var isSymbol_1 = isSymbol$1;
|
|
93
|
+
var baseTrim = _baseTrim, isObject$1 = isObject_1, isSymbol = isSymbol_1;
|
|
94
|
+
var NAN = 0 / 0;
|
|
95
|
+
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
|
|
96
|
+
var reIsBinary = /^0b[01]+$/i;
|
|
97
|
+
var reIsOctal = /^0o[0-7]+$/i;
|
|
98
|
+
var freeParseInt = parseInt;
|
|
99
|
+
function toNumber$1(value) {
|
|
100
|
+
if (typeof value == "number") {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (isSymbol(value)) {
|
|
104
|
+
return NAN;
|
|
105
|
+
}
|
|
106
|
+
if (isObject$1(value)) {
|
|
107
|
+
var other = typeof value.valueOf == "function" ? value.valueOf() : value;
|
|
108
|
+
value = isObject$1(other) ? other + "" : other;
|
|
109
|
+
}
|
|
110
|
+
if (typeof value != "string") {
|
|
111
|
+
return value === 0 ? value : +value;
|
|
112
|
+
}
|
|
113
|
+
value = baseTrim(value);
|
|
114
|
+
var isBinary = reIsBinary.test(value);
|
|
115
|
+
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
|
|
116
|
+
}
|
|
117
|
+
var toNumber_1 = toNumber$1;
|
|
118
|
+
var isObject = isObject_1, now = now_1, toNumber = toNumber_1;
|
|
119
|
+
var FUNC_ERROR_TEXT = "Expected a function";
|
|
120
|
+
var nativeMax = Math.max, nativeMin = Math.min;
|
|
121
|
+
function debounce(func, wait, options) {
|
|
122
|
+
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true;
|
|
123
|
+
if (typeof func != "function") {
|
|
124
|
+
throw new TypeError(FUNC_ERROR_TEXT);
|
|
125
|
+
}
|
|
126
|
+
wait = toNumber(wait) || 0;
|
|
127
|
+
if (isObject(options)) {
|
|
128
|
+
leading = !!options.leading;
|
|
129
|
+
maxing = "maxWait" in options;
|
|
130
|
+
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
|
|
131
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
132
|
+
}
|
|
133
|
+
function invokeFunc(time) {
|
|
134
|
+
var args = lastArgs, thisArg = lastThis;
|
|
135
|
+
lastArgs = lastThis = void 0;
|
|
136
|
+
lastInvokeTime = time;
|
|
137
|
+
result = func.apply(thisArg, args);
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
function leadingEdge(time) {
|
|
141
|
+
lastInvokeTime = time;
|
|
142
|
+
timerId = setTimeout(timerExpired, wait);
|
|
143
|
+
return leading ? invokeFunc(time) : result;
|
|
144
|
+
}
|
|
145
|
+
function remainingWait(time) {
|
|
146
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall;
|
|
147
|
+
return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
148
|
+
}
|
|
149
|
+
function shouldInvoke(time) {
|
|
150
|
+
var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime;
|
|
151
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
152
|
+
}
|
|
153
|
+
function timerExpired() {
|
|
154
|
+
var time = now();
|
|
155
|
+
if (shouldInvoke(time)) {
|
|
156
|
+
return trailingEdge(time);
|
|
157
|
+
}
|
|
158
|
+
timerId = setTimeout(timerExpired, remainingWait(time));
|
|
159
|
+
}
|
|
160
|
+
function trailingEdge(time) {
|
|
161
|
+
timerId = void 0;
|
|
162
|
+
if (trailing && lastArgs) {
|
|
163
|
+
return invokeFunc(time);
|
|
164
|
+
}
|
|
165
|
+
lastArgs = lastThis = void 0;
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function cancel() {
|
|
169
|
+
if (timerId !== void 0) {
|
|
170
|
+
clearTimeout(timerId);
|
|
171
|
+
}
|
|
172
|
+
lastInvokeTime = 0;
|
|
173
|
+
lastArgs = lastCallTime = lastThis = timerId = void 0;
|
|
174
|
+
}
|
|
175
|
+
function flush() {
|
|
176
|
+
return timerId === void 0 ? result : trailingEdge(now());
|
|
177
|
+
}
|
|
178
|
+
function debounced() {
|
|
179
|
+
var time = now(), isInvoking = shouldInvoke(time);
|
|
180
|
+
lastArgs = arguments;
|
|
181
|
+
lastThis = this;
|
|
182
|
+
lastCallTime = time;
|
|
183
|
+
if (isInvoking) {
|
|
184
|
+
if (timerId === void 0) {
|
|
185
|
+
return leadingEdge(lastCallTime);
|
|
186
|
+
}
|
|
187
|
+
if (maxing) {
|
|
188
|
+
clearTimeout(timerId);
|
|
189
|
+
timerId = setTimeout(timerExpired, wait);
|
|
190
|
+
return invokeFunc(lastCallTime);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (timerId === void 0) {
|
|
194
|
+
timerId = setTimeout(timerExpired, wait);
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
debounced.cancel = cancel;
|
|
199
|
+
debounced.flush = flush;
|
|
200
|
+
return debounced;
|
|
201
|
+
}
|
|
202
|
+
var debounce_1 = debounce;
|
|
203
|
+
var PdfPageText_vue_vue_type_style_index_0_lang = "";
|
|
204
|
+
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
205
|
+
props: {
|
|
206
|
+
viewport: null,
|
|
207
|
+
page: null
|
|
208
|
+
},
|
|
209
|
+
setup(__props) {
|
|
210
|
+
const props = __props;
|
|
211
|
+
const textContent = ref();
|
|
212
|
+
const rootEl = ref();
|
|
213
|
+
watch(() => props.page, async (page) => {
|
|
214
|
+
textContent.value = await page.getTextContent();
|
|
215
|
+
}, { immediate: true });
|
|
216
|
+
watch(() => [textContent.value, rootEl.value, props.viewport], () => {
|
|
217
|
+
renderText();
|
|
218
|
+
});
|
|
219
|
+
let renderTask = void 0;
|
|
220
|
+
function renderText() {
|
|
221
|
+
const el = rootEl.value;
|
|
222
|
+
const text = textContent.value;
|
|
223
|
+
const vp = props.viewport;
|
|
224
|
+
if (!el || !text || !vp)
|
|
225
|
+
return;
|
|
226
|
+
if (renderTask) {
|
|
227
|
+
renderTask.cancel();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
while (el.firstChild) {
|
|
231
|
+
el.removeChild(el.firstChild);
|
|
232
|
+
}
|
|
233
|
+
renderTask = renderTextLayer({
|
|
234
|
+
textContent: textContent.value,
|
|
235
|
+
container: el,
|
|
236
|
+
viewport: vp,
|
|
237
|
+
enhanceTextSelection: true
|
|
238
|
+
});
|
|
239
|
+
renderTask.promise.then(() => {
|
|
240
|
+
renderTask = void 0;
|
|
241
|
+
}).catch(() => {
|
|
242
|
+
renderTask = void 0;
|
|
243
|
+
}).finally(() => {
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
onMounted(() => {
|
|
247
|
+
renderText();
|
|
248
|
+
});
|
|
249
|
+
return (_ctx, _cache) => {
|
|
250
|
+
return openBlock(), createElementBlock("div", {
|
|
251
|
+
ref_key: "rootEl",
|
|
252
|
+
ref: rootEl,
|
|
253
|
+
class: "pdf-text-layer"
|
|
254
|
+
}, null, 512);
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
var PdfPage_vue_vue_type_style_index_0_lang = "";
|
|
259
|
+
const _hoisted_1 = { class: "pdf-page-layout" };
|
|
260
|
+
const _hoisted_2 = { class: "pdf-page-overlay" };
|
|
261
|
+
const _hoisted_3 = {
|
|
262
|
+
key: 0,
|
|
263
|
+
class: "pdf-page-number"
|
|
264
|
+
};
|
|
265
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
266
|
+
props: {
|
|
267
|
+
zoom: null,
|
|
268
|
+
zoomType: null,
|
|
269
|
+
hideText: { type: Boolean },
|
|
270
|
+
hideNumber: { type: Boolean },
|
|
271
|
+
viewport: null,
|
|
272
|
+
page: null,
|
|
273
|
+
observer: null
|
|
274
|
+
},
|
|
275
|
+
emits: ["update:zoom"],
|
|
276
|
+
setup(__props, { expose, emit: emits }) {
|
|
277
|
+
const props = __props;
|
|
278
|
+
const canvas = ref();
|
|
279
|
+
const rootEl = ref();
|
|
280
|
+
const inViewport = ref(false);
|
|
281
|
+
const maxAutoWidth = 1100;
|
|
282
|
+
expose({ rootEl, inViewport });
|
|
283
|
+
const baseScale = 96 / 72;
|
|
284
|
+
const pdfScale = computed(() => {
|
|
285
|
+
const { width: pageWidth, height: pageHeight } = props.page.getViewport({ scale: baseScale });
|
|
286
|
+
const { width: vpWidth, height: vpHeight } = props.viewport;
|
|
287
|
+
let wLimit = 0;
|
|
288
|
+
let newZoom = 1;
|
|
289
|
+
switch (props.zoomType) {
|
|
290
|
+
case ZoomType.Auto:
|
|
291
|
+
wLimit = Math.min(vpWidth, maxAutoWidth) - 40;
|
|
292
|
+
newZoom = wLimit / pageWidth;
|
|
293
|
+
return baseScale * newZoom;
|
|
294
|
+
case ZoomType.WidthFit:
|
|
295
|
+
wLimit = vpWidth - 40;
|
|
296
|
+
newZoom = wLimit / pageWidth;
|
|
297
|
+
return baseScale * newZoom;
|
|
298
|
+
case ZoomType.PageFit:
|
|
299
|
+
if (vpWidth > vpHeight) {
|
|
300
|
+
newZoom = vpHeight / pageHeight;
|
|
301
|
+
return baseScale * newZoom;
|
|
302
|
+
} else {
|
|
303
|
+
wLimit = vpWidth - 40;
|
|
304
|
+
newZoom = wLimit / pageWidth;
|
|
305
|
+
return baseScale * newZoom;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return baseScale * props.zoom;
|
|
309
|
+
});
|
|
310
|
+
const displayScale = computed(() => {
|
|
311
|
+
return pdfScale.value * ((window == null ? void 0 : window.devicePixelRatio) || 1);
|
|
312
|
+
});
|
|
313
|
+
const pdfViewport = computed(() => {
|
|
314
|
+
return props.page.getViewport({ scale: pdfScale.value });
|
|
315
|
+
});
|
|
316
|
+
const displayViewport = computed(() => {
|
|
317
|
+
return props.page.getViewport({ scale: displayScale.value });
|
|
318
|
+
});
|
|
319
|
+
watch(pdfScale, (newScale) => {
|
|
320
|
+
const newZoom = newScale / baseScale;
|
|
321
|
+
const delta = Math.abs(newZoom - props.zoom);
|
|
322
|
+
if (delta > 0.05) {
|
|
323
|
+
emits("update:zoom", newZoom);
|
|
324
|
+
}
|
|
325
|
+
}, { immediate: true });
|
|
326
|
+
let renderTask;
|
|
327
|
+
function renderPage() {
|
|
328
|
+
if (!props.page || !canvas.value)
|
|
329
|
+
return;
|
|
330
|
+
const page = props.page;
|
|
331
|
+
const pdfVP = pdfViewport.value;
|
|
332
|
+
const dispVP = displayViewport.value;
|
|
333
|
+
const canvasEl = canvas.value;
|
|
334
|
+
canvasEl.width = Math.ceil(dispVP.width);
|
|
335
|
+
canvasEl.height = Math.ceil(dispVP.height);
|
|
336
|
+
canvasEl.style.width = Math.floor(pdfVP.width) + "px";
|
|
337
|
+
canvasEl.style.height = Math.floor(pdfVP.height) + "px";
|
|
338
|
+
const context = canvasEl.getContext("2d");
|
|
339
|
+
if (!context || !inViewport.value)
|
|
340
|
+
return;
|
|
341
|
+
if (renderTask) {
|
|
342
|
+
renderTask.cancel();
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
console.debug(`rendering page ${page.pageNumber}`);
|
|
346
|
+
const renderContext = {
|
|
347
|
+
canvasContext: context,
|
|
348
|
+
viewport: displayViewport.value
|
|
349
|
+
};
|
|
350
|
+
renderTask = page.render(renderContext);
|
|
351
|
+
renderTask.promise.then(() => renderTask = void 0).catch(() => {
|
|
352
|
+
renderTask = void 0;
|
|
353
|
+
renderPage();
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
watch(() => [props.page, displayScale.value, inViewport.value], () => {
|
|
357
|
+
renderPage();
|
|
358
|
+
}, { immediate: true });
|
|
359
|
+
onMounted(() => {
|
|
360
|
+
var _a;
|
|
361
|
+
renderPage();
|
|
362
|
+
if (rootEl.value)
|
|
363
|
+
(_a = props.observer) == null ? void 0 : _a.observe(rootEl.value);
|
|
364
|
+
});
|
|
365
|
+
onBeforeUnmount(() => {
|
|
366
|
+
var _a;
|
|
367
|
+
if (rootEl.value)
|
|
368
|
+
(_a = props.observer) == null ? void 0 : _a.unobserve(rootEl.value);
|
|
369
|
+
});
|
|
370
|
+
return (_ctx, _cache) => {
|
|
371
|
+
return openBlock(), createElementBlock("div", {
|
|
372
|
+
ref_key: "rootEl",
|
|
373
|
+
ref: rootEl,
|
|
374
|
+
class: "pdf-page"
|
|
375
|
+
}, [
|
|
376
|
+
createElementVNode("div", _hoisted_1, [
|
|
377
|
+
createElementVNode("canvas", {
|
|
378
|
+
ref_key: "canvas",
|
|
379
|
+
ref: canvas
|
|
380
|
+
}, null, 512),
|
|
381
|
+
createElementVNode("div", _hoisted_2, [
|
|
382
|
+
!__props.hideText ? (openBlock(), createBlock(_sfc_main$3, {
|
|
383
|
+
key: 0,
|
|
384
|
+
viewport: unref(displayViewport),
|
|
385
|
+
page: __props.page
|
|
386
|
+
}, null, 8, ["viewport", "page"])) : createCommentVNode("", true),
|
|
387
|
+
renderSlot(_ctx.$slots, "default", {
|
|
388
|
+
width: unref(pdfViewport).width,
|
|
389
|
+
height: unref(pdfViewport).height
|
|
390
|
+
})
|
|
391
|
+
])
|
|
392
|
+
]),
|
|
393
|
+
!__props.hideNumber ? (openBlock(), createElementBlock("div", _hoisted_3, toDisplayString(__props.page.pageNumber), 1)) : createCommentVNode("", true)
|
|
394
|
+
], 512);
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
399
|
+
props: {
|
|
400
|
+
hideText: { type: Boolean },
|
|
401
|
+
hideNumber: { type: Boolean },
|
|
402
|
+
zoomType: null,
|
|
403
|
+
zoom: null,
|
|
404
|
+
viewport: null,
|
|
405
|
+
src: null
|
|
406
|
+
},
|
|
407
|
+
emits: ["error", "update:zoom"],
|
|
408
|
+
setup(__props, { emit: emits }) {
|
|
409
|
+
const props = __props;
|
|
410
|
+
const pdfDoc = shallowRef();
|
|
411
|
+
const pdfPages = shallowRef([]);
|
|
412
|
+
const observer = shallowRef();
|
|
413
|
+
const rootEl = ref();
|
|
414
|
+
const pageComps = ref([]);
|
|
415
|
+
function setPageComp(component) {
|
|
416
|
+
pageComps.value.push(component);
|
|
417
|
+
if (pageComps.value.length == 1)
|
|
418
|
+
component.inViewport = true;
|
|
419
|
+
}
|
|
420
|
+
function cleanupDoc() {
|
|
421
|
+
pdfPages.value.forEach((pg) => pg.cleanup());
|
|
422
|
+
pdfPages.value = [];
|
|
423
|
+
const doc = pdfDoc.value;
|
|
424
|
+
if (doc) {
|
|
425
|
+
doc.destroy();
|
|
426
|
+
pdfDoc.value = void 0;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
watch(() => props.src, (src) => {
|
|
430
|
+
cleanupDoc();
|
|
431
|
+
if (!src)
|
|
432
|
+
return;
|
|
433
|
+
getDocument(src).promise.then((doc) => {
|
|
434
|
+
pdfDoc.value = doc;
|
|
435
|
+
const tasks = [];
|
|
436
|
+
for (let i = 1; i <= doc.numPages; i++) {
|
|
437
|
+
tasks.push(doc.getPage(i));
|
|
438
|
+
}
|
|
439
|
+
Promise.all(tasks).then((pages) => {
|
|
440
|
+
if (doc === pdfDoc.value)
|
|
441
|
+
pdfPages.value = pages;
|
|
442
|
+
});
|
|
443
|
+
}).catch((err) => {
|
|
444
|
+
emits("error", err);
|
|
445
|
+
});
|
|
446
|
+
}, { immediate: true });
|
|
447
|
+
onMounted(() => {
|
|
448
|
+
observer.value = new IntersectionObserver(debounce_1((entries) => {
|
|
449
|
+
entries.forEach((entry) => {
|
|
450
|
+
const foundComp = pageComps.value.find((comp) => (comp == null ? void 0 : comp.rootEl) === entry.target);
|
|
451
|
+
if (foundComp) {
|
|
452
|
+
foundComp.inViewport = entry.isIntersecting;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}, 50), {
|
|
456
|
+
rootMargin: "0px"
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
onBeforeUnmount(() => {
|
|
460
|
+
var _a;
|
|
461
|
+
cleanupDoc();
|
|
462
|
+
(_a = observer.value) == null ? void 0 : _a.disconnect();
|
|
463
|
+
});
|
|
464
|
+
return (_ctx, _cache) => {
|
|
465
|
+
return openBlock(), createElementBlock("div", {
|
|
466
|
+
ref_key: "rootEl",
|
|
467
|
+
ref: rootEl
|
|
468
|
+
}, [
|
|
469
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(pdfPages), (page) => {
|
|
470
|
+
return openBlock(), createBlock(_sfc_main$2, {
|
|
471
|
+
ref_for: true,
|
|
472
|
+
ref: setPageComp,
|
|
473
|
+
key: page.pageNumber,
|
|
474
|
+
page,
|
|
475
|
+
"hide-number": __props.hideNumber,
|
|
476
|
+
"hide-text": __props.hideText,
|
|
477
|
+
"zoom-type": __props.zoomType,
|
|
478
|
+
zoom: __props.zoom,
|
|
479
|
+
"onUpdate:zoom": _cache[0] || (_cache[0] = ($event) => emits("update:zoom", $event)),
|
|
480
|
+
observer: unref(observer),
|
|
481
|
+
viewport: __props.viewport
|
|
482
|
+
}, {
|
|
483
|
+
default: withCtx(({ width, height }) => [
|
|
484
|
+
renderSlot(_ctx.$slots, "default", {
|
|
485
|
+
doc: unref(pdfDoc),
|
|
486
|
+
page,
|
|
487
|
+
width,
|
|
488
|
+
height
|
|
489
|
+
})
|
|
490
|
+
]),
|
|
491
|
+
_: 2
|
|
492
|
+
}, 1032, ["page", "hide-number", "hide-text", "zoom-type", "zoom", "observer", "viewport"]);
|
|
493
|
+
}), 128))
|
|
494
|
+
], 512);
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
var PdfHost_vue_vue_type_style_index_0_lang = "";
|
|
499
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
500
|
+
props: {
|
|
501
|
+
workerSrc: null,
|
|
502
|
+
sources: null,
|
|
503
|
+
zoomType: null,
|
|
504
|
+
zoom: null,
|
|
505
|
+
hideText: { type: Boolean },
|
|
506
|
+
hideNumber: { type: Boolean }
|
|
507
|
+
},
|
|
508
|
+
emits: ["update:zoom", "update:zoomType"],
|
|
509
|
+
setup(__props, { expose, emit: emits }) {
|
|
510
|
+
const props = __props;
|
|
511
|
+
const rootEl = ref();
|
|
512
|
+
expose({
|
|
513
|
+
zoomIn,
|
|
514
|
+
zoomOut
|
|
515
|
+
});
|
|
516
|
+
watch(() => props.workerSrc, (js) => {
|
|
517
|
+
if (js)
|
|
518
|
+
GlobalWorkerOptions.workerSrc = js;
|
|
519
|
+
}, { immediate: true });
|
|
520
|
+
function onMouseWheel(e) {
|
|
521
|
+
if (e.ctrlKey) {
|
|
522
|
+
e.preventDefault();
|
|
523
|
+
if (e.deltaY < 0) {
|
|
524
|
+
zoomIn();
|
|
525
|
+
} else {
|
|
526
|
+
zoomOut();
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function onKeydown(e) {
|
|
531
|
+
if (e.ctrlKey) {
|
|
532
|
+
if (e.key === "0" || e.which == 48) {
|
|
533
|
+
emits("update:zoomType", ZoomType.Auto);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
const viewport = ref({ width: 0, height: 0 });
|
|
538
|
+
const updateViewport = debounce_1(() => {
|
|
539
|
+
const root2 = rootEl.value;
|
|
540
|
+
if (root2) {
|
|
541
|
+
viewport.value = {
|
|
542
|
+
width: root2.offsetWidth,
|
|
543
|
+
height: root2.offsetHeight
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
}, 100);
|
|
547
|
+
function fitZoom(zoom) {
|
|
548
|
+
const overage = zoom % 0.25;
|
|
549
|
+
return Number((zoom - overage).toFixed(2));
|
|
550
|
+
}
|
|
551
|
+
function zoomIn() {
|
|
552
|
+
const proposed = fitZoom((props.zoom || 1) + 0.25);
|
|
553
|
+
emits("update:zoom", Math.min(proposed, 2));
|
|
554
|
+
emits("update:zoomType", ZoomType.Custom);
|
|
555
|
+
}
|
|
556
|
+
function zoomOut() {
|
|
557
|
+
const proposed = fitZoom((props.zoom || 1) - 0.25);
|
|
558
|
+
emits("update:zoom", Math.max(proposed, 0.25));
|
|
559
|
+
emits("update:zoomType", ZoomType.Custom);
|
|
560
|
+
}
|
|
561
|
+
watch(() => props.zoom, (newZoom, oldZoom) => {
|
|
562
|
+
const root2 = rootEl.value;
|
|
563
|
+
if (root2 && newZoom && oldZoom) {
|
|
564
|
+
const curTop = root2.scrollTop;
|
|
565
|
+
const curLeft = root2.scrollLeft;
|
|
566
|
+
const ratio = newZoom / oldZoom;
|
|
567
|
+
nextTick(() => {
|
|
568
|
+
root2.scrollTop = curTop * ratio;
|
|
569
|
+
root2.scrollLeft = curLeft * ratio;
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
onMounted(() => {
|
|
574
|
+
window.addEventListener("resize", updateViewport);
|
|
575
|
+
updateViewport();
|
|
576
|
+
});
|
|
577
|
+
onBeforeUnmount(() => {
|
|
578
|
+
window.removeEventListener("resize", updateViewport);
|
|
579
|
+
});
|
|
580
|
+
return (_ctx, _cache) => {
|
|
581
|
+
return openBlock(), createElementBlock("div", {
|
|
582
|
+
ref_key: "rootEl",
|
|
583
|
+
ref: rootEl,
|
|
584
|
+
onWheel: onMouseWheel,
|
|
585
|
+
onKeydown,
|
|
586
|
+
tabindex: "0",
|
|
587
|
+
class: "pdf-host"
|
|
588
|
+
}, [
|
|
589
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.sources, (src) => {
|
|
590
|
+
return openBlock(), createBlock(_sfc_main$1, {
|
|
591
|
+
viewport: viewport.value,
|
|
592
|
+
src,
|
|
593
|
+
"hide-number": !!__props.hideNumber,
|
|
594
|
+
"hide-text": !!__props.hideText,
|
|
595
|
+
"zoom-type": __props.zoomType || unref(ZoomType).Auto,
|
|
596
|
+
zoom: __props.zoom || 1,
|
|
597
|
+
"onUpdate:zoom": _cache[0] || (_cache[0] = ($event) => emits("update:zoom", $event))
|
|
598
|
+
}, {
|
|
599
|
+
default: withCtx(({ doc, page, width, height }) => [
|
|
600
|
+
renderSlot(_ctx.$slots, "page", {
|
|
601
|
+
doc,
|
|
602
|
+
page,
|
|
603
|
+
width,
|
|
604
|
+
height
|
|
605
|
+
})
|
|
606
|
+
]),
|
|
607
|
+
_: 2
|
|
608
|
+
}, 1032, ["viewport", "src", "hide-number", "hide-text", "zoom-type", "zoom"]);
|
|
609
|
+
}), 256)),
|
|
610
|
+
renderSlot(_ctx.$slots, "default")
|
|
611
|
+
], 544);
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
export { _sfc_main as PdfHost, ZoomType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(k,t){typeof exports=="object"&&typeof module!="undefined"?t(exports,require("vue"),require("pdfjs-dist")):typeof define=="function"&&define.amd?define(["exports","vue","pdfjs-dist"],t):(k=typeof globalThis!="undefined"?globalThis:k||self,t(k.pdfjsVue3={},k.Vue,k.pdfjsLib))})(this,function(k,t,B){"use strict";var z=(e=>(e[e.Auto=0]="Auto",e[e.WidthFit=1]="WidthFit",e[e.PageFit=2]="PageFit",e[e.Custom=3]="Custom",e))(z||{}),j=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function U(e){var r=typeof e;return e!=null&&(r=="object"||r=="function")}var O=U,H=typeof j=="object"&&j&&j.Object===Object&&j,D=H,K=D,q=typeof self=="object"&&self&&self.Object===Object&&self,X=K||q||Function("return this")(),P=X,Y=P,J=function(){return Y.Date.now()},Q=J,Z=/\s/;function ee(e){for(var r=e.length;r--&&Z.test(e.charAt(r)););return r}var te=ee,oe=te,ne=/^\s+/;function re(e){return e&&e.slice(0,oe(e)+1).replace(ne,"")}var ie=re,ae=P,le=ae.Symbol,N=le,M=N,V=Object.prototype,ce=V.hasOwnProperty,se=V.toString,E=M?M.toStringTag:void 0;function de(e){var r=ce.call(e,E),a=e[E];try{e[E]=void 0;var n=!0}catch{}var l=se.call(e);return n&&(r?e[E]=a:delete e[E]),l}var fe=de,ue=Object.prototype,me=ue.toString;function pe(e){return me.call(e)}var he=pe,I=N,ge=fe,be=he,ye="[object Null]",we="[object Undefined]",L=I?I.toStringTag:void 0;function ve(e){return e==null?e===void 0?we:ye:L&&L in Object(e)?ge(e):be(e)}var Te=ve;function xe(e){return e!=null&&typeof e=="object"}var ke=xe,ze=Te,Se=ke,Ee="[object Symbol]";function _e(e){return typeof e=="symbol"||Se(e)&&ze(e)==Ee}var je=_e,Be=ie,W=O,$e=je,F=0/0,Ce=/^[-+]0x[0-9a-f]+$/i,Oe=/^0b[01]+$/i,Pe=/^0o[0-7]+$/i,Ne=parseInt;function Me(e){if(typeof e=="number")return e;if($e(e))return F;if(W(e)){var r=typeof e.valueOf=="function"?e.valueOf():e;e=W(r)?r+"":r}if(typeof e!="string")return e===0?e:+e;e=Be(e);var a=Oe.test(e);return a||Pe.test(e)?Ne(e.slice(2),a?2:8):Ce.test(e)?F:+e}var Ve=Me,Ie=O,$=Q,A=Ve,Le="Expected a function",We=Math.max,Fe=Math.min;function Ae(e,r,a){var n,l,p,m,s,d,b=0,f=!1,c=!1,o=!0;if(typeof e!="function")throw new TypeError(Le);r=A(r)||0,Ie(a)&&(f=!!a.leading,c="maxWait"in a,p=c?We(A(a.maxWait)||0,r):p,o="trailing"in a?!!a.trailing:o);function i(h){var S=n,_=l;return n=l=void 0,b=h,m=e.apply(_,S),m}function y(h){return b=h,s=setTimeout(g,r),f?i(h):m}function u(h){var S=h-d,_=h-b,G=r-S;return c?Fe(G,p-_):G}function w(h){var S=h-d,_=h-b;return d===void 0||S>=r||S<0||c&&_>=p}function g(){var h=$();if(w(h))return v(h);s=setTimeout(g,u(h))}function v(h){return s=void 0,o&&n?i(h):(n=l=void 0,m)}function x(){s!==void 0&&clearTimeout(s),b=0,n=d=l=s=void 0}function T(){return s===void 0?m:v($())}function C(){var h=$(),S=w(h);if(n=arguments,l=this,d=h,S){if(s===void 0)return y(d);if(c)return clearTimeout(s),s=setTimeout(g,r),i(d)}return s===void 0&&(s=setTimeout(g,r)),m}return C.cancel=x,C.flush=T,C}var R=Ae,Xe="";const Re=t.defineComponent({props:{viewport:null,page:null},setup(e){const r=e,a=t.ref(),n=t.ref();t.watch(()=>r.page,async m=>{a.value=await m.getTextContent()},{immediate:!0}),t.watch(()=>[a.value,n.value,r.viewport],()=>{p()});let l;function p(){const m=n.value,s=a.value,d=r.viewport;if(!(!m||!s||!d)){if(l){l.cancel();return}for(;m.firstChild;)m.removeChild(m.firstChild);l=B.renderTextLayer({textContent:a.value,container:m,viewport:d,enhanceTextSelection:!0}),l.promise.then(()=>{l=void 0}).catch(()=>{l=void 0}).finally(()=>{})}}return t.onMounted(()=>{p()}),(m,s)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:n,class:"pdf-text-layer"},null,512))}});var Ye="";const Ge={class:"pdf-page-layout"},Ue={class:"pdf-page-overlay"},He={key:0,class:"pdf-page-number"},De=t.defineComponent({props:{zoom:null,zoomType:null,hideText:{type:Boolean},hideNumber:{type:Boolean},viewport:null,page:null,observer:null},emits:["update:zoom"],setup(e,{expose:r,emit:a}){const n=e,l=t.ref(),p=t.ref(),m=t.ref(!1),s=1100;r({rootEl:p,inViewport:m});const d=96/72,b=t.computed(()=>{const{width:u,height:w}=n.page.getViewport({scale:d}),{width:g,height:v}=n.viewport;let x=0,T=1;switch(n.zoomType){case z.Auto:return x=Math.min(g,s)-40,T=x/u,d*T;case z.WidthFit:return x=g-40,T=x/u,d*T;case z.PageFit:return g>v?(T=v/w,d*T):(x=g-40,T=x/u,d*T)}return d*n.zoom}),f=t.computed(()=>b.value*((window==null?void 0:window.devicePixelRatio)||1)),c=t.computed(()=>n.page.getViewport({scale:b.value})),o=t.computed(()=>n.page.getViewport({scale:f.value}));t.watch(b,u=>{const w=u/d;Math.abs(w-n.zoom)>.05&&a("update:zoom",w)},{immediate:!0});let i;function y(){if(!n.page||!l.value)return;const u=n.page,w=c.value,g=o.value,v=l.value;v.width=Math.ceil(g.width),v.height=Math.ceil(g.height),v.style.width=Math.floor(w.width)+"px",v.style.height=Math.floor(w.height)+"px";const x=v.getContext("2d");if(!x||!m.value)return;if(i){i.cancel();return}console.debug(`rendering page ${u.pageNumber}`);const T={canvasContext:x,viewport:o.value};i=u.render(T),i.promise.then(()=>i=void 0).catch(()=>{i=void 0,y()})}return t.watch(()=>[n.page,f.value,m.value],()=>{y()},{immediate:!0}),t.onMounted(()=>{var u;y(),p.value&&((u=n.observer)==null||u.observe(p.value))}),t.onBeforeUnmount(()=>{var u;p.value&&((u=n.observer)==null||u.unobserve(p.value))}),(u,w)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:p,class:"pdf-page"},[t.createElementVNode("div",Ge,[t.createElementVNode("canvas",{ref_key:"canvas",ref:l},null,512),t.createElementVNode("div",Ue,[e.hideText?t.createCommentVNode("",!0):(t.openBlock(),t.createBlock(Re,{key:0,viewport:t.unref(o),page:e.page},null,8,["viewport","page"])),t.renderSlot(u.$slots,"default",{width:t.unref(c).width,height:t.unref(c).height})])]),e.hideNumber?t.createCommentVNode("",!0):(t.openBlock(),t.createElementBlock("div",He,t.toDisplayString(e.page.pageNumber),1))],512))}}),Ke=t.defineComponent({props:{hideText:{type:Boolean},hideNumber:{type:Boolean},zoomType:null,zoom:null,viewport:null,src:null},emits:["error","update:zoom"],setup(e,{emit:r}){const a=e,n=t.shallowRef(),l=t.shallowRef([]),p=t.shallowRef(),m=t.ref(),s=t.ref([]);function d(f){s.value.push(f),s.value.length==1&&(f.inViewport=!0)}function b(){l.value.forEach(c=>c.cleanup()),l.value=[];const f=n.value;f&&(f.destroy(),n.value=void 0)}return t.watch(()=>a.src,f=>{b(),f&&B.getDocument(f).promise.then(c=>{n.value=c;const o=[];for(let i=1;i<=c.numPages;i++)o.push(c.getPage(i));Promise.all(o).then(i=>{c===n.value&&(l.value=i)})}).catch(c=>{r("error",c)})},{immediate:!0}),t.onMounted(()=>{p.value=new IntersectionObserver(R(f=>{f.forEach(c=>{const o=s.value.find(i=>(i==null?void 0:i.rootEl)===c.target);o&&(o.inViewport=c.isIntersecting)})},50),{rootMargin:"0px"})}),t.onBeforeUnmount(()=>{var f;b(),(f=p.value)==null||f.disconnect()}),(f,c)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:m},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(l),o=>(t.openBlock(),t.createBlock(De,{ref_for:!0,ref:d,key:o.pageNumber,page:o,"hide-number":e.hideNumber,"hide-text":e.hideText,"zoom-type":e.zoomType,zoom:e.zoom,"onUpdate:zoom":c[0]||(c[0]=i=>r("update:zoom",i)),observer:t.unref(p),viewport:e.viewport},{default:t.withCtx(({width:i,height:y})=>[t.renderSlot(f.$slots,"default",{doc:t.unref(n),page:o,width:i,height:y})]),_:2},1032,["page","hide-number","hide-text","zoom-type","zoom","observer","viewport"]))),128))],512))}});var Je="";const qe=t.defineComponent({props:{workerSrc:null,sources:null,zoomType:null,zoom:null,hideText:{type:Boolean},hideNumber:{type:Boolean}},emits:["update:zoom","update:zoomType"],setup(e,{expose:r,emit:a}){const n=e,l=t.ref();r({zoomIn:f,zoomOut:c}),t.watch(()=>n.workerSrc,o=>{o&&(B.GlobalWorkerOptions.workerSrc=o)},{immediate:!0});function p(o){o.ctrlKey&&(o.preventDefault(),o.deltaY<0?f():c())}function m(o){o.ctrlKey&&(o.key==="0"||o.which==48)&&a("update:zoomType",z.Auto)}const s=t.ref({width:0,height:0}),d=R(()=>{const o=l.value;o&&(s.value={width:o.offsetWidth,height:o.offsetHeight})},100);function b(o){const i=o%.25;return Number((o-i).toFixed(2))}function f(){const o=b((n.zoom||1)+.25);a("update:zoom",Math.min(o,2)),a("update:zoomType",z.Custom)}function c(){const o=b((n.zoom||1)-.25);a("update:zoom",Math.max(o,.25)),a("update:zoomType",z.Custom)}return t.watch(()=>n.zoom,(o,i)=>{const y=l.value;if(y&&o&&i){const u=y.scrollTop,w=y.scrollLeft,g=o/i;t.nextTick(()=>{y.scrollTop=u*g,y.scrollLeft=w*g})}}),t.onMounted(()=>{window.addEventListener("resize",d),d()}),t.onBeforeUnmount(()=>{window.removeEventListener("resize",d)}),(o,i)=>(t.openBlock(),t.createElementBlock("div",{ref_key:"rootEl",ref:l,onWheel:p,onKeydown:m,tabindex:"0",class:"pdf-host"},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(e.sources,y=>(t.openBlock(),t.createBlock(Ke,{viewport:s.value,src:y,"hide-number":!!e.hideNumber,"hide-text":!!e.hideText,"zoom-type":e.zoomType||t.unref(z).Auto,zoom:e.zoom||1,"onUpdate:zoom":i[0]||(i[0]=u=>a("update:zoom",u))},{default:t.withCtx(({doc:u,page:w,width:g,height:v})=>[t.renderSlot(o.$slots,"page",{doc:u,page:w,width:g,height:v})]),_:2},1032,["viewport","src","hide-number","hide-text","zoom-type","zoom"]))),256)),t.renderSlot(o.$slots,"default")],544))}});k.PdfHost=qe,k.ZoomType=z,Object.defineProperties(k,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.pdf-text-layer{position:absolute;text-align:initial;left:0;top:0;right:0;bottom:0;overflow:hidden;opacity:.2;line-height:1;text-size-adjust:none}.pdf-text-layer span,.pdf-text-layer br{color:transparent;position:absolute;white-space:pre;cursor:text;transform-origin:0% 0%}.pdf-text-layer span.markedContent{top:0;height:0}.pdf-text-layer .highlight{margin:-1px;padding:1px;background-color:#b400aa;border-radius:4px}.pdf-text-layer .highlight.appended{position:initial}.pdf-text-layer .highlight.begin{border-radius:4px 0 0 4px}.pdf-text-layer .highlight.end{border-radius:0 4px 4px 0}.pdf-text-layer .highlight.middle{border-radius:0}.pdf-text-layer .highlight.selected{background-color:#006400}.pdf-text-layer ::selection{background:rgb(0,153,255)}.pdf-text-layer br::selection{background:transparent}.pdf-text-layer .endOfContent{display:block;position:absolute;left:0;top:100%;right:0;bottom:0;z-index:-1;cursor:default;user-select:none}.pdf-text-layer .endOfContent.active{top:0}.pdf-page{margin:1rem auto;display:flex;flex-direction:column}.pdf-page-layout{position:relative;display:flex;margin-bottom:.5rem;margin:auto;background:#fff;filter:drop-shadow(0 1px 2px rgb(0 0 0 / .1)) drop-shadow(0 1px 1px rgb(0 0 0 / .06))}.pdf-page-number{text-align:center;line-height:1.5}.pdf-page-overlay{position:absolute;top:0;left:0;right:0;bottom:0}.pdf-host{height:100%;overflow:auto;padding:1rem 0;background:gainsboro}.pdf-host:focus{outline:none}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pdfjs-vue3",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Using pdfjs to display PDFs as a vue 3 component.",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist/pdfjs*",
|
|
7
|
+
"dist/style*",
|
|
8
|
+
"types/index*",
|
|
9
|
+
"types/types*",
|
|
10
|
+
"types/PdfHost*"
|
|
11
|
+
],
|
|
12
|
+
"types": "./types/index.d.ts",
|
|
13
|
+
"main": "./dist/pdfjs-vue3.umd.js",
|
|
14
|
+
"module": "./dist/pdfjs-vue3.es.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/pdfjs-vue3.es.js",
|
|
18
|
+
"require": "./dist/pdfjs-vue3.umd.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"build": "vite build && vue-tsc",
|
|
24
|
+
"preview": "vite preview"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"pdfjs-dist": "^2.13.216",
|
|
29
|
+
"vue": "^3.2.31"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@babel/types": "^7.17.0",
|
|
33
|
+
"@types/lodash": "^4.14.180",
|
|
34
|
+
"@types/node": "^17.0.23",
|
|
35
|
+
"@vitejs/plugin-vue": "^2.2.4",
|
|
36
|
+
"modern-normalize": "^1.1.0",
|
|
37
|
+
"typescript": "^4.6.3",
|
|
38
|
+
"vite": "^2.8.6",
|
|
39
|
+
"vue-tsc": "^0.33.9"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { PdfSource, ZoomType } from './types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
/**
|
|
4
|
+
* Pdfjs's worker script url. Must be set if haven't been set elsewhere.
|
|
5
|
+
*/
|
|
6
|
+
workerSrc?: string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Array of pdf sources to display.
|
|
9
|
+
*/
|
|
10
|
+
sources: PdfSource[];
|
|
11
|
+
/**
|
|
12
|
+
* Type of zoom used. Defaults to Auto.
|
|
13
|
+
*/
|
|
14
|
+
zoomType?: ZoomType | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Display zoom percentage if using custom zoom, defaults to 1 (100%).
|
|
17
|
+
*/
|
|
18
|
+
zoom?: number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Hides the selectable text layer.
|
|
21
|
+
*/
|
|
22
|
+
hideText?: boolean | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Hides page number display.
|
|
25
|
+
*/
|
|
26
|
+
hideNumber?: boolean | undefined;
|
|
27
|
+
}>, {
|
|
28
|
+
/**
|
|
29
|
+
* Try to increase zoom to the next level, up to 200%.
|
|
30
|
+
*/
|
|
31
|
+
zoomIn: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Try to decrease zoom to the next level, down to 25%.
|
|
34
|
+
*/
|
|
35
|
+
zoomOut: () => void;
|
|
36
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
37
|
+
"update:zoom": (zoom: number) => void;
|
|
38
|
+
} & {
|
|
39
|
+
"update:zoomType": (zoomType: ZoomType) => void;
|
|
40
|
+
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
41
|
+
/**
|
|
42
|
+
* Pdfjs's worker script url. Must be set if haven't been set elsewhere.
|
|
43
|
+
*/
|
|
44
|
+
workerSrc?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Array of pdf sources to display.
|
|
47
|
+
*/
|
|
48
|
+
sources: PdfSource[];
|
|
49
|
+
/**
|
|
50
|
+
* Type of zoom used. Defaults to Auto.
|
|
51
|
+
*/
|
|
52
|
+
zoomType?: ZoomType | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Display zoom percentage if using custom zoom, defaults to 1 (100%).
|
|
55
|
+
*/
|
|
56
|
+
zoom?: number | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Hides the selectable text layer.
|
|
59
|
+
*/
|
|
60
|
+
hideText?: boolean | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Hides page number display.
|
|
63
|
+
*/
|
|
64
|
+
hideNumber?: boolean | undefined;
|
|
65
|
+
}>>> & {
|
|
66
|
+
"onUpdate:zoom"?: ((zoom: number) => any) | undefined;
|
|
67
|
+
"onUpdate:zoomType"?: ((zoomType: ZoomType) => any) | undefined;
|
|
68
|
+
}, {}>;
|
|
69
|
+
export default _default;
|
|
70
|
+
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
71
|
+
declare type __VLS_TypePropsToRuntimeProps<T> = {
|
|
72
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
73
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
74
|
+
} : {
|
|
75
|
+
type: import('vue').PropType<T[K]>;
|
|
76
|
+
required: true;
|
|
77
|
+
};
|
|
78
|
+
};
|
package/types/index.d.ts
ADDED
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PDFDataRangeTransport } from 'pdfjs-dist';
|
|
2
|
+
import type { TypedArray, DocumentInitParameters } from 'pdfjs-dist/types/src/display/api';
|
|
3
|
+
/**
|
|
4
|
+
* Types of zooms supported in pdf display.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum ZoomType {
|
|
7
|
+
/**
|
|
8
|
+
* Auto zoom to fit width of host until a certain limit.
|
|
9
|
+
*/
|
|
10
|
+
Auto = 0,
|
|
11
|
+
/**
|
|
12
|
+
* Fits width of host with no limit.
|
|
13
|
+
*/
|
|
14
|
+
WidthFit = 1,
|
|
15
|
+
/**
|
|
16
|
+
* Fits whole page in the host.
|
|
17
|
+
*/
|
|
18
|
+
PageFit = 2,
|
|
19
|
+
/**
|
|
20
|
+
* Custom zoom value percentage.
|
|
21
|
+
*/
|
|
22
|
+
Custom = 3
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Source of pdf to display in the host.
|
|
26
|
+
*/
|
|
27
|
+
export declare type PdfSource = string | URL | PDFDataRangeTransport | TypedArray | DocumentInitParameters;
|