@file-viewer/renderer-ofd 2.0.11

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.
@@ -0,0 +1,12 @@
1
+ /* Copyright 2017 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ */
6
+
7
+ // The upstream JBig2 decoder ships legacy polyfills through CommonJS require().
8
+ // This project targets modern browsers through Vite, so the compatibility layer is kept
9
+ // intentionally small to avoid pulling core-js into the lazy OFD chunk.
10
+ if (!globalThis._pdfjsCompatibilityChecked) {
11
+ globalThis._pdfjsCompatibilityChecked = true;
12
+ }
@@ -0,0 +1,180 @@
1
+ /* Copyright 2019 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /* eslint no-var: error */
16
+
17
+ import { assert, BaseException, warn } from "./util.js";
18
+
19
+ function getLookupTableFactory(initializer) {
20
+ let lookup;
21
+ return function () {
22
+ if (initializer) {
23
+ lookup = Object.create(null);
24
+ initializer(lookup);
25
+ initializer = null;
26
+ }
27
+ return lookup;
28
+ };
29
+ }
30
+
31
+ class MissingDataException extends BaseException {
32
+ constructor(begin, end) {
33
+ super(`Missing data [${begin}, ${end})`);
34
+ this.begin = begin;
35
+ this.end = end;
36
+ }
37
+ }
38
+
39
+ class XRefEntryException extends BaseException {}
40
+
41
+ class XRefParseException extends BaseException {}
42
+
43
+ /**
44
+ * Get the value of an inheritable property.
45
+ *
46
+ * If the PDF specification explicitly lists a property in a dictionary as
47
+ * inheritable, then the value of the property may be present in the dictionary
48
+ * itself or in one or more parents of the dictionary.
49
+ *
50
+ * If the key is not found in the tree, `undefined` is returned. Otherwise,
51
+ * the value for the key is returned or, if `stopWhenFound` is `false`, a list
52
+ * of values is returned. To avoid infinite loops, the traversal is stopped when
53
+ * the loop limit is reached.
54
+ *
55
+ * @param {Dict} dict - Dictionary from where to start the traversal.
56
+ * @param {string} key - The key of the property to find the value for.
57
+ * @param {boolean} getArray - Whether or not the value should be fetched as an
58
+ * array. The default value is `false`.
59
+ * @param {boolean} stopWhenFound - Whether or not to stop the traversal when
60
+ * the key is found. If set to `false`, we always walk up the entire parent
61
+ * chain, for example to be able to find `\Resources` placed on multiple
62
+ * levels of the tree. The default value is `true`.
63
+ */
64
+ function getInheritableProperty({
65
+ dict,
66
+ key,
67
+ getArray = false,
68
+ stopWhenFound = true,
69
+ }) {
70
+ const LOOP_LIMIT = 100;
71
+ let loopCount = 0;
72
+ let values;
73
+
74
+ while (dict) {
75
+ const value = getArray ? dict.getArray(key) : dict.get(key);
76
+ if (value !== undefined) {
77
+ if (stopWhenFound) {
78
+ return value;
79
+ }
80
+ if (!values) {
81
+ values = [];
82
+ }
83
+ values.push(value);
84
+ }
85
+ if (++loopCount > LOOP_LIMIT) {
86
+ warn(`getInheritableProperty: maximum loop count exceeded for "${key}"`);
87
+ break;
88
+ }
89
+ dict = dict.get("Parent");
90
+ }
91
+ return values;
92
+ }
93
+
94
+ // prettier-ignore
95
+ const ROMAN_NUMBER_MAP = [
96
+ "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM",
97
+ "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
98
+ "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"
99
+ ];
100
+
101
+ /**
102
+ * Converts positive integers to (upper case) Roman numerals.
103
+ * @param {number} number - The number that should be converted.
104
+ * @param {boolean} lowerCase - Indicates if the result should be converted
105
+ * to lower case letters. The default value is `false`.
106
+ * @returns {string} The resulting Roman number.
107
+ */
108
+ function toRomanNumerals(number, lowerCase = false) {
109
+ assert(
110
+ Number.isInteger(number) && number > 0,
111
+ "The number should be a positive integer."
112
+ );
113
+ const romanBuf = [];
114
+ let pos;
115
+ // Thousands
116
+ while (number >= 1000) {
117
+ number -= 1000;
118
+ romanBuf.push("M");
119
+ }
120
+ // Hundreds
121
+ pos = (number / 100) | 0;
122
+ number %= 100;
123
+ romanBuf.push(ROMAN_NUMBER_MAP[pos]);
124
+ // Tens
125
+ pos = (number / 10) | 0;
126
+ number %= 10;
127
+ romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
128
+ // Ones
129
+ romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
130
+
131
+ const romanStr = romanBuf.join("");
132
+ return lowerCase ? romanStr.toLowerCase() : romanStr;
133
+ }
134
+
135
+ // Calculate the base 2 logarithm of the number `x`. This differs from the
136
+ // native function in the sense that it returns the ceiling value and that it
137
+ // returns 0 instead of `Infinity`/`NaN` for `x` values smaller than/equal to 0.
138
+ function log2(x) {
139
+ if (x <= 0) {
140
+ return 0;
141
+ }
142
+ return Math.ceil(Math.log2(x));
143
+ }
144
+
145
+ function readInt8(data, offset) {
146
+ return (data[offset] << 24) >> 24;
147
+ }
148
+
149
+ function readUint16(data, offset) {
150
+ return (data[offset] << 8) | data[offset + 1];
151
+ }
152
+
153
+ function readUint32(data, offset) {
154
+ return (
155
+ ((data[offset] << 24) |
156
+ (data[offset + 1] << 16) |
157
+ (data[offset + 2] << 8) |
158
+ data[offset + 3]) >>>
159
+ 0
160
+ );
161
+ }
162
+
163
+ // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
164
+ function isWhiteSpace(ch) {
165
+ return ch === 0x20 || ch === 0x09 || ch === 0x0d || ch === 0x0a;
166
+ }
167
+
168
+ export {
169
+ getLookupTableFactory,
170
+ MissingDataException,
171
+ XRefEntryException,
172
+ XRefParseException,
173
+ getInheritableProperty,
174
+ toRomanNumerals,
175
+ log2,
176
+ readInt8,
177
+ readUint16,
178
+ readUint32,
179
+ isWhiteSpace,
180
+ };
@@ -0,0 +1,27 @@
1
+ /* Copyright 2018 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /* globals process */
16
+
17
+ // NW.js / Electron is a browser context, but copies some Node.js objects; see
18
+ // http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
19
+ // https://www.electronjs.org/docs/api/process#processversionselectron-readonly
20
+ // https://www.electronjs.org/docs/api/process#processtype-readonly
21
+ const isNodeJS =
22
+ typeof process === "object" &&
23
+ process + "" === "[object process]" &&
24
+ !process.versions.nw &&
25
+ !(process.versions.electron && process.type && process.type !== "browser");
26
+
27
+ export { isNodeJS };