@chialab/pdfjs-lib 1.0.0-alpha.4 → 1.0.0-alpha.40
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/README.md +15 -7
- package/dist/browser/NodeUtilsStabs-MUAXKISB.js +19 -0
- package/dist/browser/chunk-3ZTAZS2X.js +25 -0
- package/dist/browser/{chunk-DYHYQ33L.js → chunk-AQCSGHG6.js} +1578 -83
- package/dist/browser/index.js +8181 -4159
- package/dist/browser/openjpeg-QOD5OH7M.js +9 -0
- package/dist/browser/qcms_bg-Q7BRLLZG.js +9 -0
- package/dist/browser/worker.js +8390 -7851
- package/dist/index.d.ts +10 -1
- package/dist/lib/AnnotationData.d.ts +12 -8
- package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
- package/dist/lib/Canvas.d.ts +2 -7
- package/dist/lib/CanvasGraphics.d.ts +1 -0
- package/dist/lib/NodeCanvasFactory.d.ts +9 -0
- package/dist/lib/NodeFilterFactory.d.ts +10 -0
- package/dist/lib/NodeUtils.d.ts +24 -0
- package/dist/lib/Path2D.d.ts +9 -49
- package/dist/lib/StandardFontDataFactory.d.ts +2 -2
- package/dist/lib/StructTreePage.d.ts +5 -0
- package/dist/lib/Svg.d.ts +144 -0
- package/dist/lib/SvgCanvasContext.d.ts +38 -24
- package/dist/lib/TextLayer.d.ts +56 -17
- package/dist/lib/WasmFactory.d.ts +5 -0
- package/dist/lib/utils.d.ts +26 -3
- package/dist/node/NodeUtils-WQF223ZR.js +20 -0
- package/dist/node/chunk-5N6O7ENF.js +2065 -0
- package/dist/node/chunk-QUZQQXZM.js +1225 -0
- package/dist/node/chunk-SW5MJNUM.js +2090 -0
- package/dist/node/index.js +7309 -4996
- package/dist/node/openjpeg-JTQTBXER.js +9 -0
- package/dist/node/qcms_bg-T4RSHPOQ.js +9 -0
- package/dist/node/worker.js +8399 -7858
- package/dist/pdf.js/external/openjpeg/openjpeg.d.ts +2 -0
- package/dist/pdf.js/external/qcms/qcms.d.ts +92 -0
- package/dist/pdf.js/external/qcms/qcms_utils.d.ts +14 -0
- package/dist/pdf.js/src/core/arithmetic_decoder.d.ts +21 -0
- package/dist/pdf.js/src/core/ascii_85_stream.d.ts +8 -0
- package/dist/pdf.js/src/core/ascii_hex_stream.d.ts +8 -0
- package/dist/pdf.js/src/core/base_stream.d.ts +32 -0
- package/dist/pdf.js/src/core/bidi.d.ts +4 -0
- package/dist/pdf.js/src/core/binary_cmap.d.ts +3 -0
- package/dist/pdf.js/src/core/ccitt.d.ts +72 -0
- package/dist/pdf.js/src/core/ccitt_stream.d.ts +9 -0
- package/dist/pdf.js/src/core/cff_font.d.ts +15 -0
- package/dist/pdf.js/src/core/cff_parser.d.ts +166 -0
- package/dist/pdf.js/src/core/charsets.d.ts +3 -0
- package/dist/pdf.js/src/core/cmap.d.ts +37 -0
- package/dist/pdf.js/src/core/colorspace.d.ts +177 -0
- package/dist/pdf.js/src/core/colorspace_utils.d.ts +21 -0
- package/dist/pdf.js/src/core/core_utils.d.ts +140 -0
- package/dist/pdf.js/src/core/decode_stream.d.ts +25 -0
- package/dist/pdf.js/src/core/encodings.d.ts +7 -0
- package/dist/pdf.js/src/core/flate_stream.d.ts +15 -0
- package/dist/pdf.js/src/core/font_renderer.d.ts +34 -0
- package/dist/pdf.js/src/core/fonts.d.ts +98 -0
- package/dist/pdf.js/src/core/fonts_utils.d.ts +32 -0
- package/dist/pdf.js/src/core/glyf.d.ts +44 -0
- package/dist/pdf.js/src/core/glyphlist.d.ts +2 -0
- package/dist/pdf.js/src/core/icc_colorspace.d.ts +22 -0
- package/dist/pdf.js/src/core/jbig2.d.ts +12 -0
- package/dist/pdf.js/src/core/jbig2_stream.d.ts +17 -0
- package/dist/pdf.js/src/core/jpeg_stream.d.ts +25 -0
- package/dist/pdf.js/src/core/jpg.d.ts +62 -0
- package/dist/pdf.js/src/core/jpx.d.ts +35 -0
- package/dist/pdf.js/src/core/jpx_stream.d.ts +17 -0
- package/dist/pdf.js/src/core/lzw_stream.d.ts +21 -0
- package/dist/pdf.js/src/core/metrics.d.ts +2 -0
- package/dist/pdf.js/src/core/name_number_tree.d.ts +21 -0
- package/dist/pdf.js/src/core/opentype_file_builder.d.ts +12 -0
- package/dist/pdf.js/src/core/parser.d.ts +81 -0
- package/dist/pdf.js/src/core/predictor_stream.d.ts +15 -0
- package/dist/pdf.js/src/core/primitives.d.ts +78 -0
- package/dist/pdf.js/src/core/run_length_stream.d.ts +7 -0
- package/dist/pdf.js/src/core/standard_fonts.d.ts +18 -0
- package/dist/pdf.js/src/core/stream.d.ts +21 -0
- package/dist/pdf.js/src/core/struct_tree.d.ts +92 -0
- package/dist/pdf.js/src/core/to_unicode_map.d.ts +21 -0
- package/dist/pdf.js/src/core/type1_font.d.ts +17 -0
- package/dist/pdf.js/src/core/type1_parser.d.ts +29 -0
- package/dist/pdf.js/src/core/unicode.d.ts +5 -0
- package/dist/pdf.js/src/display/annotation_layer.d.ts +35 -5
- package/dist/pdf.js/src/display/annotation_storage.d.ts +3 -8
- package/dist/pdf.js/src/display/api.d.ts +86 -77
- package/dist/pdf.js/src/display/api_utils.d.ts +13 -0
- package/dist/pdf.js/src/display/canvas.d.ts +88 -94
- package/dist/pdf.js/src/display/canvas_dependency_tracker.d.ts +160 -0
- package/dist/pdf.js/src/display/display_utils.d.ts +34 -1
- package/dist/pdf.js/src/display/draw_layer.d.ts +2 -2
- package/dist/pdf.js/src/display/editor/alt_text.d.ts +1 -1
- package/dist/pdf.js/src/display/editor/annotation_editor_layer.d.ts +10 -8
- package/dist/pdf.js/src/display/editor/color_picker.d.ts +20 -1
- package/dist/pdf.js/src/display/editor/comment.d.ts +47 -0
- package/dist/pdf.js/src/display/editor/draw.d.ts +8 -8
- package/dist/pdf.js/src/display/editor/drawers/freedraw.d.ts +4 -3
- package/dist/pdf.js/src/display/editor/drawers/highlight.d.ts +2 -1
- package/dist/pdf.js/src/display/editor/drawers/signaturedraw.d.ts +13 -13
- package/dist/pdf.js/src/display/editor/editor.d.ts +117 -16
- package/dist/pdf.js/src/display/editor/freetext.d.ts +11 -7
- package/dist/pdf.js/src/display/editor/highlight.d.ts +9 -3
- package/dist/pdf.js/src/display/editor/ink.d.ts +6 -0
- package/dist/pdf.js/src/display/editor/signature.d.ts +3 -5
- package/dist/pdf.js/src/display/editor/stamp.d.ts +4 -3
- package/dist/pdf.js/src/display/editor/toolbar.d.ts +8 -3
- package/dist/pdf.js/src/display/editor/tools.d.ts +36 -12
- package/dist/pdf.js/src/display/font_loader.d.ts +27 -1
- package/dist/pdf.js/src/display/metadata.d.ts +1 -2
- package/dist/pdf.js/src/display/optional_content_config.d.ts +1 -1
- package/dist/pdf.js/src/display/pattern_helper.d.ts +6 -4
- package/dist/pdf.js/src/display/pdf_objects.d.ts +40 -0
- package/dist/pdf.js/src/display/text_layer.d.ts +9 -9
- package/dist/pdf.js/src/display/touch_manager.d.ts +5 -1
- package/dist/pdf.js/src/display/worker_options.d.ts +2 -2
- package/dist/pdf.js/src/pdf.d.ts +9 -1
- package/dist/pdf.js/src/shared/obj-bin-transform.d.ts +64 -0
- package/dist/pdf.js/src/shared/scripting_utils.d.ts +2 -0
- package/dist/pdf.js/src/shared/util.d.ts +129 -102
- package/dist/pdf.js/web/comment_manager.d.ts +20 -0
- package/dist/pdf.js/web/interfaces.d.ts +7 -0
- package/dist/pdf.js/web/text_accessibility.d.ts +1 -1
- package/package.json +12 -3
- package/dist/node/chunk-KTTVPO2G.js +0 -1775
- package/dist/pdf.js/src/display/node_utils.d.ts +0 -32
|
@@ -0,0 +1,2065 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbortException,
|
|
3
|
+
FeatureTest,
|
|
4
|
+
ImageKind,
|
|
5
|
+
InvalidPDFException,
|
|
6
|
+
PasswordException,
|
|
7
|
+
ResponseException,
|
|
8
|
+
UnknownErrorException,
|
|
9
|
+
assert,
|
|
10
|
+
unreachable,
|
|
11
|
+
warn
|
|
12
|
+
} from "./chunk-QUZQQXZM.js";
|
|
13
|
+
import {
|
|
14
|
+
__privateAdd,
|
|
15
|
+
__privateGet,
|
|
16
|
+
__privateMethod,
|
|
17
|
+
__privateSet,
|
|
18
|
+
__publicField
|
|
19
|
+
} from "./chunk-7MW5RQZ5.js";
|
|
20
|
+
|
|
21
|
+
// src/lib/polyfills.ts
|
|
22
|
+
if (!Array.prototype.at) {
|
|
23
|
+
Object.defineProperty(Array.prototype, "at", {
|
|
24
|
+
value: function at(index) {
|
|
25
|
+
return this[index >= 0 ? index : this.length + index];
|
|
26
|
+
},
|
|
27
|
+
enumerable: false
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!Promise.withResolvers) {
|
|
31
|
+
Promise.withResolvers = function withResolvers() {
|
|
32
|
+
let resolve;
|
|
33
|
+
let reject;
|
|
34
|
+
const promise = new this((res, rej) => {
|
|
35
|
+
resolve = res;
|
|
36
|
+
reject = rej;
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
resolve,
|
|
40
|
+
reject,
|
|
41
|
+
promise
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (!("try" in Promise)) {
|
|
46
|
+
Object.defineProperty(Promise, "try", {
|
|
47
|
+
value: function tryFn(fn, ...args) {
|
|
48
|
+
return new this(
|
|
49
|
+
(resolve, reject) => {
|
|
50
|
+
try {
|
|
51
|
+
resolve(fn(...args));
|
|
52
|
+
} catch (error) {
|
|
53
|
+
reject(error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
enumerable: false
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/pdf.js/src/shared/message_handler.js
|
|
63
|
+
var CallbackKind = {
|
|
64
|
+
DATA: 1,
|
|
65
|
+
ERROR: 2
|
|
66
|
+
};
|
|
67
|
+
var StreamKind = {
|
|
68
|
+
CANCEL: 1,
|
|
69
|
+
CANCEL_COMPLETE: 2,
|
|
70
|
+
CLOSE: 3,
|
|
71
|
+
ENQUEUE: 4,
|
|
72
|
+
ERROR: 5,
|
|
73
|
+
PULL: 6,
|
|
74
|
+
PULL_COMPLETE: 7,
|
|
75
|
+
START_COMPLETE: 8
|
|
76
|
+
};
|
|
77
|
+
function onFn() {
|
|
78
|
+
}
|
|
79
|
+
function wrapReason(ex) {
|
|
80
|
+
if (ex instanceof AbortException || ex instanceof InvalidPDFException || ex instanceof PasswordException || ex instanceof ResponseException || ex instanceof UnknownErrorException) {
|
|
81
|
+
return ex;
|
|
82
|
+
}
|
|
83
|
+
if (!(ex instanceof Error || typeof ex === "object" && ex !== null)) {
|
|
84
|
+
unreachable(
|
|
85
|
+
'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
switch (ex.name) {
|
|
89
|
+
case "AbortException":
|
|
90
|
+
return new AbortException(ex.message);
|
|
91
|
+
case "InvalidPDFException":
|
|
92
|
+
return new InvalidPDFException(ex.message);
|
|
93
|
+
case "PasswordException":
|
|
94
|
+
return new PasswordException(ex.message, ex.code);
|
|
95
|
+
case "ResponseException":
|
|
96
|
+
return new ResponseException(ex.message, ex.status, ex.missing);
|
|
97
|
+
case "UnknownErrorException":
|
|
98
|
+
return new UnknownErrorException(ex.message, ex.details);
|
|
99
|
+
}
|
|
100
|
+
return new UnknownErrorException(ex.message, ex.toString());
|
|
101
|
+
}
|
|
102
|
+
var _messageAC, _MessageHandler_instances, onMessage_fn, createStreamSink_fn, processStreamMessage_fn, deleteStreamController_fn;
|
|
103
|
+
var MessageHandler = class {
|
|
104
|
+
constructor(sourceName, targetName, comObj) {
|
|
105
|
+
__privateAdd(this, _MessageHandler_instances);
|
|
106
|
+
__privateAdd(this, _messageAC, new AbortController());
|
|
107
|
+
this.sourceName = sourceName;
|
|
108
|
+
this.targetName = targetName;
|
|
109
|
+
this.comObj = comObj;
|
|
110
|
+
this.callbackId = 1;
|
|
111
|
+
this.streamId = 1;
|
|
112
|
+
this.streamSinks = /* @__PURE__ */ Object.create(null);
|
|
113
|
+
this.streamControllers = /* @__PURE__ */ Object.create(null);
|
|
114
|
+
this.callbackCapabilities = /* @__PURE__ */ Object.create(null);
|
|
115
|
+
this.actionHandler = /* @__PURE__ */ Object.create(null);
|
|
116
|
+
comObj.addEventListener("message", __privateMethod(this, _MessageHandler_instances, onMessage_fn).bind(this), {
|
|
117
|
+
signal: __privateGet(this, _messageAC).signal
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
on(actionName, handler) {
|
|
121
|
+
if (false) {
|
|
122
|
+
assert(
|
|
123
|
+
typeof handler === "function",
|
|
124
|
+
'MessageHandler.on: Expected "handler" to be a function.'
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
const ah = this.actionHandler;
|
|
128
|
+
if (ah[actionName]) {
|
|
129
|
+
throw new Error(`There is already an actionName called "${actionName}"`);
|
|
130
|
+
}
|
|
131
|
+
ah[actionName] = handler;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
135
|
+
* @param {string} actionName - Action to call.
|
|
136
|
+
* @param {JSON} data - JSON data to send.
|
|
137
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
138
|
+
*/
|
|
139
|
+
send(actionName, data, transfers) {
|
|
140
|
+
this.comObj.postMessage(
|
|
141
|
+
{
|
|
142
|
+
sourceName: this.sourceName,
|
|
143
|
+
targetName: this.targetName,
|
|
144
|
+
action: actionName,
|
|
145
|
+
data
|
|
146
|
+
},
|
|
147
|
+
transfers
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
152
|
+
* Expects that the other side will callback with the response.
|
|
153
|
+
* @param {string} actionName - Action to call.
|
|
154
|
+
* @param {JSON} data - JSON data to send.
|
|
155
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
156
|
+
* @returns {Promise} Promise to be resolved with response data.
|
|
157
|
+
*/
|
|
158
|
+
sendWithPromise(actionName, data, transfers) {
|
|
159
|
+
const callbackId = this.callbackId++;
|
|
160
|
+
const capability = Promise.withResolvers();
|
|
161
|
+
this.callbackCapabilities[callbackId] = capability;
|
|
162
|
+
try {
|
|
163
|
+
this.comObj.postMessage(
|
|
164
|
+
{
|
|
165
|
+
sourceName: this.sourceName,
|
|
166
|
+
targetName: this.targetName,
|
|
167
|
+
action: actionName,
|
|
168
|
+
callbackId,
|
|
169
|
+
data
|
|
170
|
+
},
|
|
171
|
+
transfers
|
|
172
|
+
);
|
|
173
|
+
} catch (ex) {
|
|
174
|
+
capability.reject(ex);
|
|
175
|
+
}
|
|
176
|
+
return capability.promise;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Sends a message to the comObj to invoke the action with the supplied data.
|
|
180
|
+
* Expect that the other side will callback to signal 'start_complete'.
|
|
181
|
+
* @param {string} actionName - Action to call.
|
|
182
|
+
* @param {JSON} data - JSON data to send.
|
|
183
|
+
* @param {Object} queueingStrategy - Strategy to signal backpressure based on
|
|
184
|
+
* internal queue.
|
|
185
|
+
* @param {Array} [transfers] - List of transfers/ArrayBuffers.
|
|
186
|
+
* @returns {ReadableStream} ReadableStream to read data in chunks.
|
|
187
|
+
*/
|
|
188
|
+
sendWithStream(actionName, data, queueingStrategy, transfers) {
|
|
189
|
+
const streamId = this.streamId++, sourceName = this.sourceName, targetName = this.targetName, comObj = this.comObj;
|
|
190
|
+
return new ReadableStream(
|
|
191
|
+
{
|
|
192
|
+
start: (controller) => {
|
|
193
|
+
const startCapability = Promise.withResolvers();
|
|
194
|
+
this.streamControllers[streamId] = {
|
|
195
|
+
controller,
|
|
196
|
+
startCall: startCapability,
|
|
197
|
+
pullCall: null,
|
|
198
|
+
cancelCall: null,
|
|
199
|
+
isClosed: false
|
|
200
|
+
};
|
|
201
|
+
comObj.postMessage(
|
|
202
|
+
{
|
|
203
|
+
sourceName,
|
|
204
|
+
targetName,
|
|
205
|
+
action: actionName,
|
|
206
|
+
streamId,
|
|
207
|
+
data,
|
|
208
|
+
desiredSize: controller.desiredSize
|
|
209
|
+
},
|
|
210
|
+
transfers
|
|
211
|
+
);
|
|
212
|
+
return startCapability.promise;
|
|
213
|
+
},
|
|
214
|
+
pull: (controller) => {
|
|
215
|
+
const pullCapability = Promise.withResolvers();
|
|
216
|
+
this.streamControllers[streamId].pullCall = pullCapability;
|
|
217
|
+
comObj.postMessage({
|
|
218
|
+
sourceName,
|
|
219
|
+
targetName,
|
|
220
|
+
stream: StreamKind.PULL,
|
|
221
|
+
streamId,
|
|
222
|
+
desiredSize: controller.desiredSize
|
|
223
|
+
});
|
|
224
|
+
return pullCapability.promise;
|
|
225
|
+
},
|
|
226
|
+
cancel: (reason) => {
|
|
227
|
+
assert(reason instanceof Error, "cancel must have a valid reason");
|
|
228
|
+
const cancelCapability = Promise.withResolvers();
|
|
229
|
+
this.streamControllers[streamId].cancelCall = cancelCapability;
|
|
230
|
+
this.streamControllers[streamId].isClosed = true;
|
|
231
|
+
comObj.postMessage({
|
|
232
|
+
sourceName,
|
|
233
|
+
targetName,
|
|
234
|
+
stream: StreamKind.CANCEL,
|
|
235
|
+
streamId,
|
|
236
|
+
reason: wrapReason(reason)
|
|
237
|
+
});
|
|
238
|
+
return cancelCapability.promise;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
queueingStrategy
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
destroy() {
|
|
245
|
+
__privateGet(this, _messageAC)?.abort();
|
|
246
|
+
__privateSet(this, _messageAC, null);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
_messageAC = new WeakMap();
|
|
250
|
+
_MessageHandler_instances = new WeakSet();
|
|
251
|
+
onMessage_fn = function({ data }) {
|
|
252
|
+
if (data.targetName !== this.sourceName) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (data.stream) {
|
|
256
|
+
__privateMethod(this, _MessageHandler_instances, processStreamMessage_fn).call(this, data);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (data.callback) {
|
|
260
|
+
const callbackId = data.callbackId;
|
|
261
|
+
const capability = this.callbackCapabilities[callbackId];
|
|
262
|
+
if (!capability) {
|
|
263
|
+
throw new Error(`Cannot resolve callback ${callbackId}`);
|
|
264
|
+
}
|
|
265
|
+
delete this.callbackCapabilities[callbackId];
|
|
266
|
+
if (data.callback === CallbackKind.DATA) {
|
|
267
|
+
capability.resolve(data.data);
|
|
268
|
+
} else if (data.callback === CallbackKind.ERROR) {
|
|
269
|
+
capability.reject(wrapReason(data.reason));
|
|
270
|
+
} else {
|
|
271
|
+
throw new Error("Unexpected callback case");
|
|
272
|
+
}
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const action = this.actionHandler[data.action];
|
|
276
|
+
if (!action) {
|
|
277
|
+
throw new Error(`Unknown action from worker: ${data.action}`);
|
|
278
|
+
}
|
|
279
|
+
if (data.callbackId) {
|
|
280
|
+
const sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
|
|
281
|
+
Promise.try(action, data.data).then(
|
|
282
|
+
function(result) {
|
|
283
|
+
comObj.postMessage({
|
|
284
|
+
sourceName,
|
|
285
|
+
targetName,
|
|
286
|
+
callback: CallbackKind.DATA,
|
|
287
|
+
callbackId: data.callbackId,
|
|
288
|
+
data: result
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
function(reason) {
|
|
292
|
+
comObj.postMessage({
|
|
293
|
+
sourceName,
|
|
294
|
+
targetName,
|
|
295
|
+
callback: CallbackKind.ERROR,
|
|
296
|
+
callbackId: data.callbackId,
|
|
297
|
+
reason: wrapReason(reason)
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (data.streamId) {
|
|
304
|
+
__privateMethod(this, _MessageHandler_instances, createStreamSink_fn).call(this, data);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
action(data.data);
|
|
308
|
+
};
|
|
309
|
+
createStreamSink_fn = function(data) {
|
|
310
|
+
const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
|
|
311
|
+
const self = this, action = this.actionHandler[data.action];
|
|
312
|
+
const streamSink = {
|
|
313
|
+
enqueue(chunk, size = 1, transfers) {
|
|
314
|
+
if (this.isCancelled) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const lastDesiredSize = this.desiredSize;
|
|
318
|
+
this.desiredSize -= size;
|
|
319
|
+
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
|
320
|
+
this.sinkCapability = Promise.withResolvers();
|
|
321
|
+
this.ready = this.sinkCapability.promise;
|
|
322
|
+
}
|
|
323
|
+
comObj.postMessage(
|
|
324
|
+
{
|
|
325
|
+
sourceName,
|
|
326
|
+
targetName,
|
|
327
|
+
stream: StreamKind.ENQUEUE,
|
|
328
|
+
streamId,
|
|
329
|
+
chunk
|
|
330
|
+
},
|
|
331
|
+
transfers
|
|
332
|
+
);
|
|
333
|
+
},
|
|
334
|
+
close() {
|
|
335
|
+
if (this.isCancelled) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
this.isCancelled = true;
|
|
339
|
+
comObj.postMessage({
|
|
340
|
+
sourceName,
|
|
341
|
+
targetName,
|
|
342
|
+
stream: StreamKind.CLOSE,
|
|
343
|
+
streamId
|
|
344
|
+
});
|
|
345
|
+
delete self.streamSinks[streamId];
|
|
346
|
+
},
|
|
347
|
+
error(reason) {
|
|
348
|
+
assert(reason instanceof Error, "error must have a valid reason");
|
|
349
|
+
if (this.isCancelled) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
this.isCancelled = true;
|
|
353
|
+
comObj.postMessage({
|
|
354
|
+
sourceName,
|
|
355
|
+
targetName,
|
|
356
|
+
stream: StreamKind.ERROR,
|
|
357
|
+
streamId,
|
|
358
|
+
reason: wrapReason(reason)
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
sinkCapability: Promise.withResolvers(),
|
|
362
|
+
onPull: null,
|
|
363
|
+
onCancel: null,
|
|
364
|
+
isCancelled: false,
|
|
365
|
+
desiredSize: data.desiredSize,
|
|
366
|
+
ready: null
|
|
367
|
+
};
|
|
368
|
+
streamSink.sinkCapability.resolve();
|
|
369
|
+
streamSink.ready = streamSink.sinkCapability.promise;
|
|
370
|
+
this.streamSinks[streamId] = streamSink;
|
|
371
|
+
Promise.try(action, data.data, streamSink).then(
|
|
372
|
+
function() {
|
|
373
|
+
comObj.postMessage({
|
|
374
|
+
sourceName,
|
|
375
|
+
targetName,
|
|
376
|
+
stream: StreamKind.START_COMPLETE,
|
|
377
|
+
streamId,
|
|
378
|
+
success: true
|
|
379
|
+
});
|
|
380
|
+
},
|
|
381
|
+
function(reason) {
|
|
382
|
+
comObj.postMessage({
|
|
383
|
+
sourceName,
|
|
384
|
+
targetName,
|
|
385
|
+
stream: StreamKind.START_COMPLETE,
|
|
386
|
+
streamId,
|
|
387
|
+
reason: wrapReason(reason)
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
};
|
|
392
|
+
processStreamMessage_fn = function(data) {
|
|
393
|
+
const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
|
|
394
|
+
const streamController = this.streamControllers[streamId], streamSink = this.streamSinks[streamId];
|
|
395
|
+
switch (data.stream) {
|
|
396
|
+
case StreamKind.START_COMPLETE:
|
|
397
|
+
if (data.success) {
|
|
398
|
+
streamController.startCall.resolve();
|
|
399
|
+
} else {
|
|
400
|
+
streamController.startCall.reject(wrapReason(data.reason));
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
case StreamKind.PULL_COMPLETE:
|
|
404
|
+
if (data.success) {
|
|
405
|
+
streamController.pullCall.resolve();
|
|
406
|
+
} else {
|
|
407
|
+
streamController.pullCall.reject(wrapReason(data.reason));
|
|
408
|
+
}
|
|
409
|
+
break;
|
|
410
|
+
case StreamKind.PULL:
|
|
411
|
+
if (!streamSink) {
|
|
412
|
+
comObj.postMessage({
|
|
413
|
+
sourceName,
|
|
414
|
+
targetName,
|
|
415
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
416
|
+
streamId,
|
|
417
|
+
success: true
|
|
418
|
+
});
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
|
|
422
|
+
streamSink.sinkCapability.resolve();
|
|
423
|
+
}
|
|
424
|
+
streamSink.desiredSize = data.desiredSize;
|
|
425
|
+
Promise.try(streamSink.onPull || onFn).then(
|
|
426
|
+
function() {
|
|
427
|
+
comObj.postMessage({
|
|
428
|
+
sourceName,
|
|
429
|
+
targetName,
|
|
430
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
431
|
+
streamId,
|
|
432
|
+
success: true
|
|
433
|
+
});
|
|
434
|
+
},
|
|
435
|
+
function(reason) {
|
|
436
|
+
comObj.postMessage({
|
|
437
|
+
sourceName,
|
|
438
|
+
targetName,
|
|
439
|
+
stream: StreamKind.PULL_COMPLETE,
|
|
440
|
+
streamId,
|
|
441
|
+
reason: wrapReason(reason)
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
);
|
|
445
|
+
break;
|
|
446
|
+
case StreamKind.ENQUEUE:
|
|
447
|
+
assert(streamController, "enqueue should have stream controller");
|
|
448
|
+
if (streamController.isClosed) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
streamController.controller.enqueue(data.chunk);
|
|
452
|
+
break;
|
|
453
|
+
case StreamKind.CLOSE:
|
|
454
|
+
assert(streamController, "close should have stream controller");
|
|
455
|
+
if (streamController.isClosed) {
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
streamController.isClosed = true;
|
|
459
|
+
streamController.controller.close();
|
|
460
|
+
__privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
|
|
461
|
+
break;
|
|
462
|
+
case StreamKind.ERROR:
|
|
463
|
+
assert(streamController, "error should have stream controller");
|
|
464
|
+
streamController.controller.error(wrapReason(data.reason));
|
|
465
|
+
__privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
|
|
466
|
+
break;
|
|
467
|
+
case StreamKind.CANCEL_COMPLETE:
|
|
468
|
+
if (data.success) {
|
|
469
|
+
streamController.cancelCall.resolve();
|
|
470
|
+
} else {
|
|
471
|
+
streamController.cancelCall.reject(wrapReason(data.reason));
|
|
472
|
+
}
|
|
473
|
+
__privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
|
|
474
|
+
break;
|
|
475
|
+
case StreamKind.CANCEL:
|
|
476
|
+
if (!streamSink) {
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
const dataReason = wrapReason(data.reason);
|
|
480
|
+
Promise.try(streamSink.onCancel || onFn, dataReason).then(
|
|
481
|
+
function() {
|
|
482
|
+
comObj.postMessage({
|
|
483
|
+
sourceName,
|
|
484
|
+
targetName,
|
|
485
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
|
486
|
+
streamId,
|
|
487
|
+
success: true
|
|
488
|
+
});
|
|
489
|
+
},
|
|
490
|
+
function(reason) {
|
|
491
|
+
comObj.postMessage({
|
|
492
|
+
sourceName,
|
|
493
|
+
targetName,
|
|
494
|
+
stream: StreamKind.CANCEL_COMPLETE,
|
|
495
|
+
streamId,
|
|
496
|
+
reason: wrapReason(reason)
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
);
|
|
500
|
+
streamSink.sinkCapability.reject(dataReason);
|
|
501
|
+
streamSink.isCancelled = true;
|
|
502
|
+
delete this.streamSinks[streamId];
|
|
503
|
+
break;
|
|
504
|
+
default:
|
|
505
|
+
throw new Error("Unexpected stream case");
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
deleteStreamController_fn = async function(streamController, streamId) {
|
|
509
|
+
await Promise.allSettled([
|
|
510
|
+
streamController.startCall?.promise,
|
|
511
|
+
streamController.pullCall?.promise,
|
|
512
|
+
streamController.cancelCall?.promise
|
|
513
|
+
]);
|
|
514
|
+
delete this.streamControllers[streamId];
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
// src/pdf.js/src/shared/obj-bin-transform.js
|
|
518
|
+
var _buffer, _view, _decoder, _CssFontInfo_instances, readString_fn;
|
|
519
|
+
var _CssFontInfo = class _CssFontInfo {
|
|
520
|
+
constructor(buffer) {
|
|
521
|
+
__privateAdd(this, _CssFontInfo_instances);
|
|
522
|
+
__privateAdd(this, _buffer);
|
|
523
|
+
__privateAdd(this, _view);
|
|
524
|
+
__privateAdd(this, _decoder);
|
|
525
|
+
__privateSet(this, _buffer, buffer);
|
|
526
|
+
__privateSet(this, _view, new DataView(__privateGet(this, _buffer)));
|
|
527
|
+
__privateSet(this, _decoder, new TextDecoder());
|
|
528
|
+
}
|
|
529
|
+
static write(info) {
|
|
530
|
+
const encoder = new TextEncoder();
|
|
531
|
+
const encodedStrings = {};
|
|
532
|
+
let stringsLength = 0;
|
|
533
|
+
for (const prop of _CssFontInfo.strings) {
|
|
534
|
+
const encoded = encoder.encode(info[prop]);
|
|
535
|
+
encodedStrings[prop] = encoded;
|
|
536
|
+
stringsLength += 4 + encoded.length;
|
|
537
|
+
}
|
|
538
|
+
const buffer = new ArrayBuffer(stringsLength);
|
|
539
|
+
const data = new Uint8Array(buffer);
|
|
540
|
+
const view = new DataView(buffer);
|
|
541
|
+
let offset = 0;
|
|
542
|
+
for (const prop of _CssFontInfo.strings) {
|
|
543
|
+
const encoded = encodedStrings[prop];
|
|
544
|
+
const length = encoded.length;
|
|
545
|
+
view.setUint32(offset, length);
|
|
546
|
+
data.set(encoded, offset + 4);
|
|
547
|
+
offset += 4 + length;
|
|
548
|
+
}
|
|
549
|
+
assert(offset === buffer.byteLength, "CssFontInfo.write: Buffer overflow");
|
|
550
|
+
return buffer;
|
|
551
|
+
}
|
|
552
|
+
get fontFamily() {
|
|
553
|
+
return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 0);
|
|
554
|
+
}
|
|
555
|
+
get fontWeight() {
|
|
556
|
+
return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 1);
|
|
557
|
+
}
|
|
558
|
+
get italicAngle() {
|
|
559
|
+
return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 2);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
_buffer = new WeakMap();
|
|
563
|
+
_view = new WeakMap();
|
|
564
|
+
_decoder = new WeakMap();
|
|
565
|
+
_CssFontInfo_instances = new WeakSet();
|
|
566
|
+
readString_fn = function(index) {
|
|
567
|
+
assert(index < _CssFontInfo.strings.length, "Invalid string index");
|
|
568
|
+
let offset = 0;
|
|
569
|
+
for (let i = 0; i < index; i++) {
|
|
570
|
+
offset += __privateGet(this, _view).getUint32(offset) + 4;
|
|
571
|
+
}
|
|
572
|
+
const length = __privateGet(this, _view).getUint32(offset);
|
|
573
|
+
return __privateGet(this, _decoder).decode(
|
|
574
|
+
new Uint8Array(__privateGet(this, _buffer), offset + 4, length)
|
|
575
|
+
);
|
|
576
|
+
};
|
|
577
|
+
__publicField(_CssFontInfo, "strings", ["fontFamily", "fontWeight", "italicAngle"]);
|
|
578
|
+
var CssFontInfo = _CssFontInfo;
|
|
579
|
+
var _buffer2, _view2, _decoder2, _SystemFontInfo_instances, readString_fn2;
|
|
580
|
+
var _SystemFontInfo = class _SystemFontInfo {
|
|
581
|
+
constructor(buffer) {
|
|
582
|
+
__privateAdd(this, _SystemFontInfo_instances);
|
|
583
|
+
__privateAdd(this, _buffer2);
|
|
584
|
+
__privateAdd(this, _view2);
|
|
585
|
+
__privateAdd(this, _decoder2);
|
|
586
|
+
__privateSet(this, _buffer2, buffer);
|
|
587
|
+
__privateSet(this, _view2, new DataView(__privateGet(this, _buffer2)));
|
|
588
|
+
__privateSet(this, _decoder2, new TextDecoder());
|
|
589
|
+
}
|
|
590
|
+
static write(info) {
|
|
591
|
+
const encoder = new TextEncoder();
|
|
592
|
+
const encodedStrings = {};
|
|
593
|
+
let stringsLength = 0;
|
|
594
|
+
for (const prop of _SystemFontInfo.strings) {
|
|
595
|
+
const encoded = encoder.encode(info[prop]);
|
|
596
|
+
encodedStrings[prop] = encoded;
|
|
597
|
+
stringsLength += 4 + encoded.length;
|
|
598
|
+
}
|
|
599
|
+
stringsLength += 4;
|
|
600
|
+
let encodedStyleStyle, encodedStyleWeight, lengthEstimate = 1 + stringsLength;
|
|
601
|
+
if (info.style) {
|
|
602
|
+
encodedStyleStyle = encoder.encode(info.style.style);
|
|
603
|
+
encodedStyleWeight = encoder.encode(info.style.weight);
|
|
604
|
+
lengthEstimate += 4 + encodedStyleStyle.length + 4 + encodedStyleWeight.length;
|
|
605
|
+
}
|
|
606
|
+
const buffer = new ArrayBuffer(lengthEstimate);
|
|
607
|
+
const data = new Uint8Array(buffer);
|
|
608
|
+
const view = new DataView(buffer);
|
|
609
|
+
let offset = 0;
|
|
610
|
+
view.setUint8(offset++, info.guessFallback ? 1 : 0);
|
|
611
|
+
view.setUint32(offset, 0);
|
|
612
|
+
offset += 4;
|
|
613
|
+
stringsLength = 0;
|
|
614
|
+
for (const prop of _SystemFontInfo.strings) {
|
|
615
|
+
const encoded = encodedStrings[prop];
|
|
616
|
+
const length = encoded.length;
|
|
617
|
+
stringsLength += 4 + length;
|
|
618
|
+
view.setUint32(offset, length);
|
|
619
|
+
data.set(encoded, offset + 4);
|
|
620
|
+
offset += 4 + length;
|
|
621
|
+
}
|
|
622
|
+
view.setUint32(offset - stringsLength - 4, stringsLength);
|
|
623
|
+
if (info.style) {
|
|
624
|
+
view.setUint32(offset, encodedStyleStyle.length);
|
|
625
|
+
data.set(encodedStyleStyle, offset + 4);
|
|
626
|
+
offset += 4 + encodedStyleStyle.length;
|
|
627
|
+
view.setUint32(offset, encodedStyleWeight.length);
|
|
628
|
+
data.set(encodedStyleWeight, offset + 4);
|
|
629
|
+
offset += 4 + encodedStyleWeight.length;
|
|
630
|
+
}
|
|
631
|
+
assert(
|
|
632
|
+
offset <= buffer.byteLength,
|
|
633
|
+
"SubstitionInfo.write: Buffer overflow"
|
|
634
|
+
);
|
|
635
|
+
return buffer.transferToFixedLength(offset);
|
|
636
|
+
}
|
|
637
|
+
get guessFallback() {
|
|
638
|
+
return __privateGet(this, _view2).getUint8(0) !== 0;
|
|
639
|
+
}
|
|
640
|
+
get css() {
|
|
641
|
+
return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 0);
|
|
642
|
+
}
|
|
643
|
+
get loadedName() {
|
|
644
|
+
return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 1);
|
|
645
|
+
}
|
|
646
|
+
get baseFontName() {
|
|
647
|
+
return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 2);
|
|
648
|
+
}
|
|
649
|
+
get src() {
|
|
650
|
+
return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 3);
|
|
651
|
+
}
|
|
652
|
+
get style() {
|
|
653
|
+
let offset = 1;
|
|
654
|
+
offset += 4 + __privateGet(this, _view2).getUint32(offset);
|
|
655
|
+
const styleLength = __privateGet(this, _view2).getUint32(offset);
|
|
656
|
+
const style = __privateGet(this, _decoder2).decode(
|
|
657
|
+
new Uint8Array(__privateGet(this, _buffer2), offset + 4, styleLength)
|
|
658
|
+
);
|
|
659
|
+
offset += 4 + styleLength;
|
|
660
|
+
const weightLength = __privateGet(this, _view2).getUint32(offset);
|
|
661
|
+
const weight = __privateGet(this, _decoder2).decode(
|
|
662
|
+
new Uint8Array(__privateGet(this, _buffer2), offset + 4, weightLength)
|
|
663
|
+
);
|
|
664
|
+
return { style, weight };
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
_buffer2 = new WeakMap();
|
|
668
|
+
_view2 = new WeakMap();
|
|
669
|
+
_decoder2 = new WeakMap();
|
|
670
|
+
_SystemFontInfo_instances = new WeakSet();
|
|
671
|
+
readString_fn2 = function(index) {
|
|
672
|
+
assert(index < _SystemFontInfo.strings.length, "Invalid string index");
|
|
673
|
+
let offset = 5;
|
|
674
|
+
for (let i = 0; i < index; i++) {
|
|
675
|
+
offset += __privateGet(this, _view2).getUint32(offset) + 4;
|
|
676
|
+
}
|
|
677
|
+
const length = __privateGet(this, _view2).getUint32(offset);
|
|
678
|
+
return __privateGet(this, _decoder2).decode(
|
|
679
|
+
new Uint8Array(__privateGet(this, _buffer2), offset + 4, length)
|
|
680
|
+
);
|
|
681
|
+
};
|
|
682
|
+
__publicField(_SystemFontInfo, "strings", ["css", "loadedName", "baseFontName", "src"]);
|
|
683
|
+
var SystemFontInfo = _SystemFontInfo;
|
|
684
|
+
var _OFFSET_NUMBERS, _OFFSET_BBOX, _OFFSET_FONT_MATRIX, _OFFSET_DEFAULT_VMETRICS, _OFFSET_STRINGS, _buffer3, _decoder3, _view3, _FontInfo_instances, readBoolean_fn, readNumber_fn, readString_fn3;
|
|
685
|
+
var _FontInfo = class _FontInfo {
|
|
686
|
+
constructor({ data, extra }) {
|
|
687
|
+
__privateAdd(this, _FontInfo_instances);
|
|
688
|
+
__privateAdd(this, _buffer3);
|
|
689
|
+
__privateAdd(this, _decoder3);
|
|
690
|
+
__privateAdd(this, _view3);
|
|
691
|
+
__privateSet(this, _buffer3, data);
|
|
692
|
+
__privateSet(this, _decoder3, new TextDecoder());
|
|
693
|
+
__privateSet(this, _view3, new DataView(__privateGet(this, _buffer3)));
|
|
694
|
+
if (extra) {
|
|
695
|
+
Object.assign(this, extra);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
get black() {
|
|
699
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 0);
|
|
700
|
+
}
|
|
701
|
+
get bold() {
|
|
702
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 1);
|
|
703
|
+
}
|
|
704
|
+
get disableFontFace() {
|
|
705
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 2);
|
|
706
|
+
}
|
|
707
|
+
get fontExtraProperties() {
|
|
708
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 3);
|
|
709
|
+
}
|
|
710
|
+
get isInvalidPDFjsFont() {
|
|
711
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 4);
|
|
712
|
+
}
|
|
713
|
+
get isType3Font() {
|
|
714
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 5);
|
|
715
|
+
}
|
|
716
|
+
get italic() {
|
|
717
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 6);
|
|
718
|
+
}
|
|
719
|
+
get missingFile() {
|
|
720
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 7);
|
|
721
|
+
}
|
|
722
|
+
get remeasure() {
|
|
723
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 8);
|
|
724
|
+
}
|
|
725
|
+
get vertical() {
|
|
726
|
+
return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 9);
|
|
727
|
+
}
|
|
728
|
+
get ascent() {
|
|
729
|
+
return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 0);
|
|
730
|
+
}
|
|
731
|
+
get defaultWidth() {
|
|
732
|
+
return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 1);
|
|
733
|
+
}
|
|
734
|
+
get descent() {
|
|
735
|
+
return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 2);
|
|
736
|
+
}
|
|
737
|
+
get bbox() {
|
|
738
|
+
let offset = __privateGet(_FontInfo, _OFFSET_BBOX);
|
|
739
|
+
const numCoords = __privateGet(this, _view3).getUint8(offset);
|
|
740
|
+
if (numCoords === 0) {
|
|
741
|
+
return void 0;
|
|
742
|
+
}
|
|
743
|
+
offset += 1;
|
|
744
|
+
const bbox = [];
|
|
745
|
+
for (let i = 0; i < 4; i++) {
|
|
746
|
+
bbox.push(__privateGet(this, _view3).getInt16(offset, true));
|
|
747
|
+
offset += 2;
|
|
748
|
+
}
|
|
749
|
+
return bbox;
|
|
750
|
+
}
|
|
751
|
+
get fontMatrix() {
|
|
752
|
+
let offset = __privateGet(_FontInfo, _OFFSET_FONT_MATRIX);
|
|
753
|
+
const numPoints = __privateGet(this, _view3).getUint8(offset);
|
|
754
|
+
if (numPoints === 0) {
|
|
755
|
+
return void 0;
|
|
756
|
+
}
|
|
757
|
+
offset += 1;
|
|
758
|
+
const fontMatrix = [];
|
|
759
|
+
for (let i = 0; i < 6; i++) {
|
|
760
|
+
fontMatrix.push(__privateGet(this, _view3).getFloat64(offset, true));
|
|
761
|
+
offset += 8;
|
|
762
|
+
}
|
|
763
|
+
return fontMatrix;
|
|
764
|
+
}
|
|
765
|
+
get defaultVMetrics() {
|
|
766
|
+
let offset = __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS);
|
|
767
|
+
const numMetrics = __privateGet(this, _view3).getUint8(offset);
|
|
768
|
+
if (numMetrics === 0) {
|
|
769
|
+
return void 0;
|
|
770
|
+
}
|
|
771
|
+
offset += 1;
|
|
772
|
+
const defaultVMetrics = [];
|
|
773
|
+
for (let i = 0; i < 3; i++) {
|
|
774
|
+
defaultVMetrics.push(__privateGet(this, _view3).getInt16(offset, true));
|
|
775
|
+
offset += 2;
|
|
776
|
+
}
|
|
777
|
+
return defaultVMetrics;
|
|
778
|
+
}
|
|
779
|
+
get fallbackName() {
|
|
780
|
+
return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 0);
|
|
781
|
+
}
|
|
782
|
+
get loadedName() {
|
|
783
|
+
return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 1);
|
|
784
|
+
}
|
|
785
|
+
get mimetype() {
|
|
786
|
+
return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 2);
|
|
787
|
+
}
|
|
788
|
+
get name() {
|
|
789
|
+
return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 3);
|
|
790
|
+
}
|
|
791
|
+
get data() {
|
|
792
|
+
let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
|
|
793
|
+
const stringsLength = __privateGet(this, _view3).getUint32(offset);
|
|
794
|
+
offset += 4 + stringsLength;
|
|
795
|
+
const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
796
|
+
offset += 4 + systemFontInfoLength;
|
|
797
|
+
const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
798
|
+
offset += 4 + cssFontInfoLength;
|
|
799
|
+
const length = __privateGet(this, _view3).getUint32(offset);
|
|
800
|
+
if (length === 0) {
|
|
801
|
+
return void 0;
|
|
802
|
+
}
|
|
803
|
+
return new Uint8Array(__privateGet(this, _buffer3), offset + 4, length);
|
|
804
|
+
}
|
|
805
|
+
clearData() {
|
|
806
|
+
let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
|
|
807
|
+
const stringsLength = __privateGet(this, _view3).getUint32(offset);
|
|
808
|
+
offset += 4 + stringsLength;
|
|
809
|
+
const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
810
|
+
offset += 4 + systemFontInfoLength;
|
|
811
|
+
const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
812
|
+
offset += 4 + cssFontInfoLength;
|
|
813
|
+
const length = __privateGet(this, _view3).getUint32(offset);
|
|
814
|
+
const data = new Uint8Array(__privateGet(this, _buffer3), offset + 4, length);
|
|
815
|
+
data.fill(0);
|
|
816
|
+
__privateGet(this, _view3).setUint32(offset, 0);
|
|
817
|
+
}
|
|
818
|
+
get cssFontInfo() {
|
|
819
|
+
let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
|
|
820
|
+
const stringsLength = __privateGet(this, _view3).getUint32(offset);
|
|
821
|
+
offset += 4 + stringsLength;
|
|
822
|
+
const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
823
|
+
offset += 4 + systemFontInfoLength;
|
|
824
|
+
const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
825
|
+
if (cssFontInfoLength === 0) {
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
const cssFontInfoData = new Uint8Array(cssFontInfoLength);
|
|
829
|
+
cssFontInfoData.set(
|
|
830
|
+
new Uint8Array(__privateGet(this, _buffer3), offset + 4, cssFontInfoLength)
|
|
831
|
+
);
|
|
832
|
+
return new CssFontInfo(cssFontInfoData.buffer);
|
|
833
|
+
}
|
|
834
|
+
get systemFontInfo() {
|
|
835
|
+
let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
|
|
836
|
+
const stringsLength = __privateGet(this, _view3).getUint32(offset);
|
|
837
|
+
offset += 4 + stringsLength;
|
|
838
|
+
const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
|
|
839
|
+
if (systemFontInfoLength === 0) {
|
|
840
|
+
return null;
|
|
841
|
+
}
|
|
842
|
+
const systemFontInfoData = new Uint8Array(systemFontInfoLength);
|
|
843
|
+
systemFontInfoData.set(
|
|
844
|
+
new Uint8Array(__privateGet(this, _buffer3), offset + 4, systemFontInfoLength)
|
|
845
|
+
);
|
|
846
|
+
return new SystemFontInfo(systemFontInfoData.buffer);
|
|
847
|
+
}
|
|
848
|
+
static write(font) {
|
|
849
|
+
const systemFontInfoBuffer = font.systemFontInfo ? SystemFontInfo.write(font.systemFontInfo) : null;
|
|
850
|
+
const cssFontInfoBuffer = font.cssFontInfo ? CssFontInfo.write(font.cssFontInfo) : null;
|
|
851
|
+
const encoder = new TextEncoder();
|
|
852
|
+
const encodedStrings = {};
|
|
853
|
+
let stringsLength = 0;
|
|
854
|
+
for (const prop of _FontInfo.strings) {
|
|
855
|
+
encodedStrings[prop] = encoder.encode(font[prop]);
|
|
856
|
+
stringsLength += 4 + encodedStrings[prop].length;
|
|
857
|
+
}
|
|
858
|
+
const lengthEstimate = __privateGet(_FontInfo, _OFFSET_STRINGS) + 4 + stringsLength + 4 + (systemFontInfoBuffer ? systemFontInfoBuffer.byteLength : 0) + 4 + (cssFontInfoBuffer ? cssFontInfoBuffer.byteLength : 0) + 4 + (font.data ? font.data.length : 0);
|
|
859
|
+
const buffer = new ArrayBuffer(lengthEstimate);
|
|
860
|
+
const data = new Uint8Array(buffer);
|
|
861
|
+
const view = new DataView(buffer);
|
|
862
|
+
let offset = 0;
|
|
863
|
+
const numBools = _FontInfo.bools.length;
|
|
864
|
+
let boolByte = 0, boolBit = 0;
|
|
865
|
+
for (let i = 0; i < numBools; i++) {
|
|
866
|
+
const value = font[_FontInfo.bools[i]];
|
|
867
|
+
const bits = value === void 0 ? 0 : value ? 2 : 1;
|
|
868
|
+
boolByte |= bits << boolBit;
|
|
869
|
+
boolBit += 2;
|
|
870
|
+
if (boolBit === 8 || i === numBools - 1) {
|
|
871
|
+
view.setUint8(offset++, boolByte);
|
|
872
|
+
boolByte = 0;
|
|
873
|
+
boolBit = 0;
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
assert(
|
|
877
|
+
offset === __privateGet(_FontInfo, _OFFSET_NUMBERS),
|
|
878
|
+
"FontInfo.write: Boolean properties offset mismatch"
|
|
879
|
+
);
|
|
880
|
+
for (const prop of _FontInfo.numbers) {
|
|
881
|
+
view.setFloat64(offset, font[prop]);
|
|
882
|
+
offset += 8;
|
|
883
|
+
}
|
|
884
|
+
assert(
|
|
885
|
+
offset === __privateGet(_FontInfo, _OFFSET_BBOX),
|
|
886
|
+
"FontInfo.write: Number properties offset mismatch"
|
|
887
|
+
);
|
|
888
|
+
if (font.bbox) {
|
|
889
|
+
view.setUint8(offset++, 4);
|
|
890
|
+
for (const coord of font.bbox) {
|
|
891
|
+
view.setInt16(offset, coord, true);
|
|
892
|
+
offset += 2;
|
|
893
|
+
}
|
|
894
|
+
} else {
|
|
895
|
+
view.setUint8(offset++, 0);
|
|
896
|
+
offset += 2 * 4;
|
|
897
|
+
}
|
|
898
|
+
assert(
|
|
899
|
+
offset === __privateGet(_FontInfo, _OFFSET_FONT_MATRIX),
|
|
900
|
+
"FontInfo.write: BBox properties offset mismatch"
|
|
901
|
+
);
|
|
902
|
+
if (font.fontMatrix) {
|
|
903
|
+
view.setUint8(offset++, 6);
|
|
904
|
+
for (const point of font.fontMatrix) {
|
|
905
|
+
view.setFloat64(offset, point, true);
|
|
906
|
+
offset += 8;
|
|
907
|
+
}
|
|
908
|
+
} else {
|
|
909
|
+
view.setUint8(offset++, 0);
|
|
910
|
+
offset += 8 * 6;
|
|
911
|
+
}
|
|
912
|
+
assert(
|
|
913
|
+
offset === __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS),
|
|
914
|
+
"FontInfo.write: FontMatrix properties offset mismatch"
|
|
915
|
+
);
|
|
916
|
+
if (font.defaultVMetrics) {
|
|
917
|
+
view.setUint8(offset++, 1);
|
|
918
|
+
for (const metric of font.defaultVMetrics) {
|
|
919
|
+
view.setInt16(offset, metric, true);
|
|
920
|
+
offset += 2;
|
|
921
|
+
}
|
|
922
|
+
} else {
|
|
923
|
+
view.setUint8(offset++, 0);
|
|
924
|
+
offset += 3 * 2;
|
|
925
|
+
}
|
|
926
|
+
assert(
|
|
927
|
+
offset === __privateGet(_FontInfo, _OFFSET_STRINGS),
|
|
928
|
+
"FontInfo.write: DefaultVMetrics properties offset mismatch"
|
|
929
|
+
);
|
|
930
|
+
view.setUint32(__privateGet(_FontInfo, _OFFSET_STRINGS), 0);
|
|
931
|
+
offset += 4;
|
|
932
|
+
for (const prop of _FontInfo.strings) {
|
|
933
|
+
const encoded = encodedStrings[prop];
|
|
934
|
+
const length = encoded.length;
|
|
935
|
+
view.setUint32(offset, length);
|
|
936
|
+
data.set(encoded, offset + 4);
|
|
937
|
+
offset += 4 + length;
|
|
938
|
+
}
|
|
939
|
+
view.setUint32(
|
|
940
|
+
__privateGet(_FontInfo, _OFFSET_STRINGS),
|
|
941
|
+
offset - __privateGet(_FontInfo, _OFFSET_STRINGS) - 4
|
|
942
|
+
);
|
|
943
|
+
if (!systemFontInfoBuffer) {
|
|
944
|
+
view.setUint32(offset, 0);
|
|
945
|
+
offset += 4;
|
|
946
|
+
} else {
|
|
947
|
+
const length = systemFontInfoBuffer.byteLength;
|
|
948
|
+
view.setUint32(offset, length);
|
|
949
|
+
assert(
|
|
950
|
+
offset + 4 + length <= buffer.byteLength,
|
|
951
|
+
"FontInfo.write: Buffer overflow at systemFontInfo"
|
|
952
|
+
);
|
|
953
|
+
data.set(new Uint8Array(systemFontInfoBuffer), offset + 4);
|
|
954
|
+
offset += 4 + length;
|
|
955
|
+
}
|
|
956
|
+
if (!cssFontInfoBuffer) {
|
|
957
|
+
view.setUint32(offset, 0);
|
|
958
|
+
offset += 4;
|
|
959
|
+
} else {
|
|
960
|
+
const length = cssFontInfoBuffer.byteLength;
|
|
961
|
+
view.setUint32(offset, length);
|
|
962
|
+
assert(
|
|
963
|
+
offset + 4 + length <= buffer.byteLength,
|
|
964
|
+
"FontInfo.write: Buffer overflow at cssFontInfo"
|
|
965
|
+
);
|
|
966
|
+
data.set(new Uint8Array(cssFontInfoBuffer), offset + 4);
|
|
967
|
+
offset += 4 + length;
|
|
968
|
+
}
|
|
969
|
+
if (font.data === void 0) {
|
|
970
|
+
view.setUint32(offset, 0);
|
|
971
|
+
offset += 4;
|
|
972
|
+
} else {
|
|
973
|
+
view.setUint32(offset, font.data.length);
|
|
974
|
+
data.set(font.data, offset + 4);
|
|
975
|
+
offset += 4 + font.data.length;
|
|
976
|
+
}
|
|
977
|
+
assert(offset <= buffer.byteLength, "FontInfo.write: Buffer overflow");
|
|
978
|
+
return buffer.transferToFixedLength(offset);
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
_OFFSET_NUMBERS = new WeakMap();
|
|
982
|
+
_OFFSET_BBOX = new WeakMap();
|
|
983
|
+
_OFFSET_FONT_MATRIX = new WeakMap();
|
|
984
|
+
_OFFSET_DEFAULT_VMETRICS = new WeakMap();
|
|
985
|
+
_OFFSET_STRINGS = new WeakMap();
|
|
986
|
+
_buffer3 = new WeakMap();
|
|
987
|
+
_decoder3 = new WeakMap();
|
|
988
|
+
_view3 = new WeakMap();
|
|
989
|
+
_FontInfo_instances = new WeakSet();
|
|
990
|
+
readBoolean_fn = function(index) {
|
|
991
|
+
assert(index < _FontInfo.bools.length, "Invalid boolean index");
|
|
992
|
+
const byteOffset = Math.floor(index / 4);
|
|
993
|
+
const bitOffset = index * 2 % 8;
|
|
994
|
+
const value = __privateGet(this, _view3).getUint8(byteOffset) >> bitOffset & 3;
|
|
995
|
+
return value === 0 ? void 0 : value === 2;
|
|
996
|
+
};
|
|
997
|
+
readNumber_fn = function(index) {
|
|
998
|
+
assert(index < _FontInfo.numbers.length, "Invalid number index");
|
|
999
|
+
return __privateGet(this, _view3).getFloat64(__privateGet(_FontInfo, _OFFSET_NUMBERS) + index * 8);
|
|
1000
|
+
};
|
|
1001
|
+
readString_fn3 = function(index) {
|
|
1002
|
+
assert(index < _FontInfo.strings.length, "Invalid string index");
|
|
1003
|
+
let offset = __privateGet(_FontInfo, _OFFSET_STRINGS) + 4;
|
|
1004
|
+
for (let i = 0; i < index; i++) {
|
|
1005
|
+
offset += __privateGet(this, _view3).getUint32(offset) + 4;
|
|
1006
|
+
}
|
|
1007
|
+
const length = __privateGet(this, _view3).getUint32(offset);
|
|
1008
|
+
const stringData = new Uint8Array(length);
|
|
1009
|
+
stringData.set(new Uint8Array(__privateGet(this, _buffer3), offset + 4, length));
|
|
1010
|
+
return __privateGet(this, _decoder3).decode(stringData);
|
|
1011
|
+
};
|
|
1012
|
+
__publicField(_FontInfo, "bools", [
|
|
1013
|
+
"black",
|
|
1014
|
+
"bold",
|
|
1015
|
+
"disableFontFace",
|
|
1016
|
+
"fontExtraProperties",
|
|
1017
|
+
"isInvalidPDFjsFont",
|
|
1018
|
+
"isType3Font",
|
|
1019
|
+
"italic",
|
|
1020
|
+
"missingFile",
|
|
1021
|
+
"remeasure",
|
|
1022
|
+
"vertical"
|
|
1023
|
+
]);
|
|
1024
|
+
__publicField(_FontInfo, "numbers", ["ascent", "defaultWidth", "descent"]);
|
|
1025
|
+
__publicField(_FontInfo, "strings", ["fallbackName", "loadedName", "mimetype", "name"]);
|
|
1026
|
+
__privateAdd(_FontInfo, _OFFSET_NUMBERS, Math.ceil(_FontInfo.bools.length * 2 / 8));
|
|
1027
|
+
__privateAdd(_FontInfo, _OFFSET_BBOX, __privateGet(_FontInfo, _OFFSET_NUMBERS) + _FontInfo.numbers.length * 8);
|
|
1028
|
+
__privateAdd(_FontInfo, _OFFSET_FONT_MATRIX, __privateGet(_FontInfo, _OFFSET_BBOX) + 1 + 2 * 4);
|
|
1029
|
+
__privateAdd(_FontInfo, _OFFSET_DEFAULT_VMETRICS, __privateGet(_FontInfo, _OFFSET_FONT_MATRIX) + 1 + 8 * 6);
|
|
1030
|
+
__privateAdd(_FontInfo, _OFFSET_STRINGS, __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS) + 1 + 2 * 3);
|
|
1031
|
+
var FontInfo = _FontInfo;
|
|
1032
|
+
|
|
1033
|
+
// src/pdf.js/src/core/bidi.js
|
|
1034
|
+
var baseTypes = [
|
|
1035
|
+
"BN",
|
|
1036
|
+
"BN",
|
|
1037
|
+
"BN",
|
|
1038
|
+
"BN",
|
|
1039
|
+
"BN",
|
|
1040
|
+
"BN",
|
|
1041
|
+
"BN",
|
|
1042
|
+
"BN",
|
|
1043
|
+
"BN",
|
|
1044
|
+
"S",
|
|
1045
|
+
"B",
|
|
1046
|
+
"S",
|
|
1047
|
+
"WS",
|
|
1048
|
+
"B",
|
|
1049
|
+
"BN",
|
|
1050
|
+
"BN",
|
|
1051
|
+
"BN",
|
|
1052
|
+
"BN",
|
|
1053
|
+
"BN",
|
|
1054
|
+
"BN",
|
|
1055
|
+
"BN",
|
|
1056
|
+
"BN",
|
|
1057
|
+
"BN",
|
|
1058
|
+
"BN",
|
|
1059
|
+
"BN",
|
|
1060
|
+
"BN",
|
|
1061
|
+
"BN",
|
|
1062
|
+
"BN",
|
|
1063
|
+
"B",
|
|
1064
|
+
"B",
|
|
1065
|
+
"B",
|
|
1066
|
+
"S",
|
|
1067
|
+
"WS",
|
|
1068
|
+
"ON",
|
|
1069
|
+
"ON",
|
|
1070
|
+
"ET",
|
|
1071
|
+
"ET",
|
|
1072
|
+
"ET",
|
|
1073
|
+
"ON",
|
|
1074
|
+
"ON",
|
|
1075
|
+
"ON",
|
|
1076
|
+
"ON",
|
|
1077
|
+
"ON",
|
|
1078
|
+
"ES",
|
|
1079
|
+
"CS",
|
|
1080
|
+
"ES",
|
|
1081
|
+
"CS",
|
|
1082
|
+
"CS",
|
|
1083
|
+
"EN",
|
|
1084
|
+
"EN",
|
|
1085
|
+
"EN",
|
|
1086
|
+
"EN",
|
|
1087
|
+
"EN",
|
|
1088
|
+
"EN",
|
|
1089
|
+
"EN",
|
|
1090
|
+
"EN",
|
|
1091
|
+
"EN",
|
|
1092
|
+
"EN",
|
|
1093
|
+
"CS",
|
|
1094
|
+
"ON",
|
|
1095
|
+
"ON",
|
|
1096
|
+
"ON",
|
|
1097
|
+
"ON",
|
|
1098
|
+
"ON",
|
|
1099
|
+
"ON",
|
|
1100
|
+
"L",
|
|
1101
|
+
"L",
|
|
1102
|
+
"L",
|
|
1103
|
+
"L",
|
|
1104
|
+
"L",
|
|
1105
|
+
"L",
|
|
1106
|
+
"L",
|
|
1107
|
+
"L",
|
|
1108
|
+
"L",
|
|
1109
|
+
"L",
|
|
1110
|
+
"L",
|
|
1111
|
+
"L",
|
|
1112
|
+
"L",
|
|
1113
|
+
"L",
|
|
1114
|
+
"L",
|
|
1115
|
+
"L",
|
|
1116
|
+
"L",
|
|
1117
|
+
"L",
|
|
1118
|
+
"L",
|
|
1119
|
+
"L",
|
|
1120
|
+
"L",
|
|
1121
|
+
"L",
|
|
1122
|
+
"L",
|
|
1123
|
+
"L",
|
|
1124
|
+
"L",
|
|
1125
|
+
"L",
|
|
1126
|
+
"ON",
|
|
1127
|
+
"ON",
|
|
1128
|
+
"ON",
|
|
1129
|
+
"ON",
|
|
1130
|
+
"ON",
|
|
1131
|
+
"ON",
|
|
1132
|
+
"L",
|
|
1133
|
+
"L",
|
|
1134
|
+
"L",
|
|
1135
|
+
"L",
|
|
1136
|
+
"L",
|
|
1137
|
+
"L",
|
|
1138
|
+
"L",
|
|
1139
|
+
"L",
|
|
1140
|
+
"L",
|
|
1141
|
+
"L",
|
|
1142
|
+
"L",
|
|
1143
|
+
"L",
|
|
1144
|
+
"L",
|
|
1145
|
+
"L",
|
|
1146
|
+
"L",
|
|
1147
|
+
"L",
|
|
1148
|
+
"L",
|
|
1149
|
+
"L",
|
|
1150
|
+
"L",
|
|
1151
|
+
"L",
|
|
1152
|
+
"L",
|
|
1153
|
+
"L",
|
|
1154
|
+
"L",
|
|
1155
|
+
"L",
|
|
1156
|
+
"L",
|
|
1157
|
+
"L",
|
|
1158
|
+
"ON",
|
|
1159
|
+
"ON",
|
|
1160
|
+
"ON",
|
|
1161
|
+
"ON",
|
|
1162
|
+
"BN",
|
|
1163
|
+
"BN",
|
|
1164
|
+
"BN",
|
|
1165
|
+
"BN",
|
|
1166
|
+
"BN",
|
|
1167
|
+
"BN",
|
|
1168
|
+
"B",
|
|
1169
|
+
"BN",
|
|
1170
|
+
"BN",
|
|
1171
|
+
"BN",
|
|
1172
|
+
"BN",
|
|
1173
|
+
"BN",
|
|
1174
|
+
"BN",
|
|
1175
|
+
"BN",
|
|
1176
|
+
"BN",
|
|
1177
|
+
"BN",
|
|
1178
|
+
"BN",
|
|
1179
|
+
"BN",
|
|
1180
|
+
"BN",
|
|
1181
|
+
"BN",
|
|
1182
|
+
"BN",
|
|
1183
|
+
"BN",
|
|
1184
|
+
"BN",
|
|
1185
|
+
"BN",
|
|
1186
|
+
"BN",
|
|
1187
|
+
"BN",
|
|
1188
|
+
"BN",
|
|
1189
|
+
"BN",
|
|
1190
|
+
"BN",
|
|
1191
|
+
"BN",
|
|
1192
|
+
"BN",
|
|
1193
|
+
"BN",
|
|
1194
|
+
"BN",
|
|
1195
|
+
"CS",
|
|
1196
|
+
"ON",
|
|
1197
|
+
"ET",
|
|
1198
|
+
"ET",
|
|
1199
|
+
"ET",
|
|
1200
|
+
"ET",
|
|
1201
|
+
"ON",
|
|
1202
|
+
"ON",
|
|
1203
|
+
"ON",
|
|
1204
|
+
"ON",
|
|
1205
|
+
"L",
|
|
1206
|
+
"ON",
|
|
1207
|
+
"ON",
|
|
1208
|
+
"BN",
|
|
1209
|
+
"ON",
|
|
1210
|
+
"ON",
|
|
1211
|
+
"ET",
|
|
1212
|
+
"ET",
|
|
1213
|
+
"EN",
|
|
1214
|
+
"EN",
|
|
1215
|
+
"ON",
|
|
1216
|
+
"L",
|
|
1217
|
+
"ON",
|
|
1218
|
+
"ON",
|
|
1219
|
+
"ON",
|
|
1220
|
+
"EN",
|
|
1221
|
+
"L",
|
|
1222
|
+
"ON",
|
|
1223
|
+
"ON",
|
|
1224
|
+
"ON",
|
|
1225
|
+
"ON",
|
|
1226
|
+
"ON",
|
|
1227
|
+
"L",
|
|
1228
|
+
"L",
|
|
1229
|
+
"L",
|
|
1230
|
+
"L",
|
|
1231
|
+
"L",
|
|
1232
|
+
"L",
|
|
1233
|
+
"L",
|
|
1234
|
+
"L",
|
|
1235
|
+
"L",
|
|
1236
|
+
"L",
|
|
1237
|
+
"L",
|
|
1238
|
+
"L",
|
|
1239
|
+
"L",
|
|
1240
|
+
"L",
|
|
1241
|
+
"L",
|
|
1242
|
+
"L",
|
|
1243
|
+
"L",
|
|
1244
|
+
"L",
|
|
1245
|
+
"L",
|
|
1246
|
+
"L",
|
|
1247
|
+
"L",
|
|
1248
|
+
"L",
|
|
1249
|
+
"L",
|
|
1250
|
+
"ON",
|
|
1251
|
+
"L",
|
|
1252
|
+
"L",
|
|
1253
|
+
"L",
|
|
1254
|
+
"L",
|
|
1255
|
+
"L",
|
|
1256
|
+
"L",
|
|
1257
|
+
"L",
|
|
1258
|
+
"L",
|
|
1259
|
+
"L",
|
|
1260
|
+
"L",
|
|
1261
|
+
"L",
|
|
1262
|
+
"L",
|
|
1263
|
+
"L",
|
|
1264
|
+
"L",
|
|
1265
|
+
"L",
|
|
1266
|
+
"L",
|
|
1267
|
+
"L",
|
|
1268
|
+
"L",
|
|
1269
|
+
"L",
|
|
1270
|
+
"L",
|
|
1271
|
+
"L",
|
|
1272
|
+
"L",
|
|
1273
|
+
"L",
|
|
1274
|
+
"L",
|
|
1275
|
+
"L",
|
|
1276
|
+
"L",
|
|
1277
|
+
"L",
|
|
1278
|
+
"L",
|
|
1279
|
+
"L",
|
|
1280
|
+
"L",
|
|
1281
|
+
"L",
|
|
1282
|
+
"ON",
|
|
1283
|
+
"L",
|
|
1284
|
+
"L",
|
|
1285
|
+
"L",
|
|
1286
|
+
"L",
|
|
1287
|
+
"L",
|
|
1288
|
+
"L",
|
|
1289
|
+
"L",
|
|
1290
|
+
"L"
|
|
1291
|
+
];
|
|
1292
|
+
var arabicTypes = [
|
|
1293
|
+
"AN",
|
|
1294
|
+
"AN",
|
|
1295
|
+
"AN",
|
|
1296
|
+
"AN",
|
|
1297
|
+
"AN",
|
|
1298
|
+
"AN",
|
|
1299
|
+
"ON",
|
|
1300
|
+
"ON",
|
|
1301
|
+
"AL",
|
|
1302
|
+
"ET",
|
|
1303
|
+
"ET",
|
|
1304
|
+
"AL",
|
|
1305
|
+
"CS",
|
|
1306
|
+
"AL",
|
|
1307
|
+
"ON",
|
|
1308
|
+
"ON",
|
|
1309
|
+
"NSM",
|
|
1310
|
+
"NSM",
|
|
1311
|
+
"NSM",
|
|
1312
|
+
"NSM",
|
|
1313
|
+
"NSM",
|
|
1314
|
+
"NSM",
|
|
1315
|
+
"NSM",
|
|
1316
|
+
"NSM",
|
|
1317
|
+
"NSM",
|
|
1318
|
+
"NSM",
|
|
1319
|
+
"NSM",
|
|
1320
|
+
"AL",
|
|
1321
|
+
"AL",
|
|
1322
|
+
"",
|
|
1323
|
+
"AL",
|
|
1324
|
+
"AL",
|
|
1325
|
+
"AL",
|
|
1326
|
+
"AL",
|
|
1327
|
+
"AL",
|
|
1328
|
+
"AL",
|
|
1329
|
+
"AL",
|
|
1330
|
+
"AL",
|
|
1331
|
+
"AL",
|
|
1332
|
+
"AL",
|
|
1333
|
+
"AL",
|
|
1334
|
+
"AL",
|
|
1335
|
+
"AL",
|
|
1336
|
+
"AL",
|
|
1337
|
+
"AL",
|
|
1338
|
+
"AL",
|
|
1339
|
+
"AL",
|
|
1340
|
+
"AL",
|
|
1341
|
+
"AL",
|
|
1342
|
+
"AL",
|
|
1343
|
+
"AL",
|
|
1344
|
+
"AL",
|
|
1345
|
+
"AL",
|
|
1346
|
+
"AL",
|
|
1347
|
+
"AL",
|
|
1348
|
+
"AL",
|
|
1349
|
+
"AL",
|
|
1350
|
+
"AL",
|
|
1351
|
+
"AL",
|
|
1352
|
+
"AL",
|
|
1353
|
+
"AL",
|
|
1354
|
+
"AL",
|
|
1355
|
+
"AL",
|
|
1356
|
+
"AL",
|
|
1357
|
+
"AL",
|
|
1358
|
+
"AL",
|
|
1359
|
+
"AL",
|
|
1360
|
+
"AL",
|
|
1361
|
+
"AL",
|
|
1362
|
+
"AL",
|
|
1363
|
+
"AL",
|
|
1364
|
+
"AL",
|
|
1365
|
+
"AL",
|
|
1366
|
+
"AL",
|
|
1367
|
+
"AL",
|
|
1368
|
+
"NSM",
|
|
1369
|
+
"NSM",
|
|
1370
|
+
"NSM",
|
|
1371
|
+
"NSM",
|
|
1372
|
+
"NSM",
|
|
1373
|
+
"NSM",
|
|
1374
|
+
"NSM",
|
|
1375
|
+
"NSM",
|
|
1376
|
+
"NSM",
|
|
1377
|
+
"NSM",
|
|
1378
|
+
"NSM",
|
|
1379
|
+
"NSM",
|
|
1380
|
+
"NSM",
|
|
1381
|
+
"NSM",
|
|
1382
|
+
"NSM",
|
|
1383
|
+
"NSM",
|
|
1384
|
+
"NSM",
|
|
1385
|
+
"NSM",
|
|
1386
|
+
"NSM",
|
|
1387
|
+
"NSM",
|
|
1388
|
+
"NSM",
|
|
1389
|
+
"AN",
|
|
1390
|
+
"AN",
|
|
1391
|
+
"AN",
|
|
1392
|
+
"AN",
|
|
1393
|
+
"AN",
|
|
1394
|
+
"AN",
|
|
1395
|
+
"AN",
|
|
1396
|
+
"AN",
|
|
1397
|
+
"AN",
|
|
1398
|
+
"AN",
|
|
1399
|
+
"ET",
|
|
1400
|
+
"AN",
|
|
1401
|
+
"AN",
|
|
1402
|
+
"AL",
|
|
1403
|
+
"AL",
|
|
1404
|
+
"AL",
|
|
1405
|
+
"NSM",
|
|
1406
|
+
"AL",
|
|
1407
|
+
"AL",
|
|
1408
|
+
"AL",
|
|
1409
|
+
"AL",
|
|
1410
|
+
"AL",
|
|
1411
|
+
"AL",
|
|
1412
|
+
"AL",
|
|
1413
|
+
"AL",
|
|
1414
|
+
"AL",
|
|
1415
|
+
"AL",
|
|
1416
|
+
"AL",
|
|
1417
|
+
"AL",
|
|
1418
|
+
"AL",
|
|
1419
|
+
"AL",
|
|
1420
|
+
"AL",
|
|
1421
|
+
"AL",
|
|
1422
|
+
"AL",
|
|
1423
|
+
"AL",
|
|
1424
|
+
"AL",
|
|
1425
|
+
"AL",
|
|
1426
|
+
"AL",
|
|
1427
|
+
"AL",
|
|
1428
|
+
"AL",
|
|
1429
|
+
"AL",
|
|
1430
|
+
"AL",
|
|
1431
|
+
"AL",
|
|
1432
|
+
"AL",
|
|
1433
|
+
"AL",
|
|
1434
|
+
"AL",
|
|
1435
|
+
"AL",
|
|
1436
|
+
"AL",
|
|
1437
|
+
"AL",
|
|
1438
|
+
"AL",
|
|
1439
|
+
"AL",
|
|
1440
|
+
"AL",
|
|
1441
|
+
"AL",
|
|
1442
|
+
"AL",
|
|
1443
|
+
"AL",
|
|
1444
|
+
"AL",
|
|
1445
|
+
"AL",
|
|
1446
|
+
"AL",
|
|
1447
|
+
"AL",
|
|
1448
|
+
"AL",
|
|
1449
|
+
"AL",
|
|
1450
|
+
"AL",
|
|
1451
|
+
"AL",
|
|
1452
|
+
"AL",
|
|
1453
|
+
"AL",
|
|
1454
|
+
"AL",
|
|
1455
|
+
"AL",
|
|
1456
|
+
"AL",
|
|
1457
|
+
"AL",
|
|
1458
|
+
"AL",
|
|
1459
|
+
"AL",
|
|
1460
|
+
"AL",
|
|
1461
|
+
"AL",
|
|
1462
|
+
"AL",
|
|
1463
|
+
"AL",
|
|
1464
|
+
"AL",
|
|
1465
|
+
"AL",
|
|
1466
|
+
"AL",
|
|
1467
|
+
"AL",
|
|
1468
|
+
"AL",
|
|
1469
|
+
"AL",
|
|
1470
|
+
"AL",
|
|
1471
|
+
"AL",
|
|
1472
|
+
"AL",
|
|
1473
|
+
"AL",
|
|
1474
|
+
"AL",
|
|
1475
|
+
"AL",
|
|
1476
|
+
"AL",
|
|
1477
|
+
"AL",
|
|
1478
|
+
"AL",
|
|
1479
|
+
"AL",
|
|
1480
|
+
"AL",
|
|
1481
|
+
"AL",
|
|
1482
|
+
"AL",
|
|
1483
|
+
"AL",
|
|
1484
|
+
"AL",
|
|
1485
|
+
"AL",
|
|
1486
|
+
"AL",
|
|
1487
|
+
"AL",
|
|
1488
|
+
"AL",
|
|
1489
|
+
"AL",
|
|
1490
|
+
"AL",
|
|
1491
|
+
"AL",
|
|
1492
|
+
"AL",
|
|
1493
|
+
"AL",
|
|
1494
|
+
"AL",
|
|
1495
|
+
"AL",
|
|
1496
|
+
"AL",
|
|
1497
|
+
"AL",
|
|
1498
|
+
"AL",
|
|
1499
|
+
"AL",
|
|
1500
|
+
"AL",
|
|
1501
|
+
"AL",
|
|
1502
|
+
"AL",
|
|
1503
|
+
"AL",
|
|
1504
|
+
"AL",
|
|
1505
|
+
"AL",
|
|
1506
|
+
"AL",
|
|
1507
|
+
"NSM",
|
|
1508
|
+
"NSM",
|
|
1509
|
+
"NSM",
|
|
1510
|
+
"NSM",
|
|
1511
|
+
"NSM",
|
|
1512
|
+
"NSM",
|
|
1513
|
+
"NSM",
|
|
1514
|
+
"AN",
|
|
1515
|
+
"ON",
|
|
1516
|
+
"NSM",
|
|
1517
|
+
"NSM",
|
|
1518
|
+
"NSM",
|
|
1519
|
+
"NSM",
|
|
1520
|
+
"NSM",
|
|
1521
|
+
"NSM",
|
|
1522
|
+
"AL",
|
|
1523
|
+
"AL",
|
|
1524
|
+
"NSM",
|
|
1525
|
+
"NSM",
|
|
1526
|
+
"ON",
|
|
1527
|
+
"NSM",
|
|
1528
|
+
"NSM",
|
|
1529
|
+
"NSM",
|
|
1530
|
+
"NSM",
|
|
1531
|
+
"AL",
|
|
1532
|
+
"AL",
|
|
1533
|
+
"EN",
|
|
1534
|
+
"EN",
|
|
1535
|
+
"EN",
|
|
1536
|
+
"EN",
|
|
1537
|
+
"EN",
|
|
1538
|
+
"EN",
|
|
1539
|
+
"EN",
|
|
1540
|
+
"EN",
|
|
1541
|
+
"EN",
|
|
1542
|
+
"EN",
|
|
1543
|
+
"AL",
|
|
1544
|
+
"AL",
|
|
1545
|
+
"AL",
|
|
1546
|
+
"AL",
|
|
1547
|
+
"AL",
|
|
1548
|
+
"AL"
|
|
1549
|
+
];
|
|
1550
|
+
function isOdd(i) {
|
|
1551
|
+
return (i & 1) !== 0;
|
|
1552
|
+
}
|
|
1553
|
+
function isEven(i) {
|
|
1554
|
+
return (i & 1) === 0;
|
|
1555
|
+
}
|
|
1556
|
+
function findUnequal(arr, start, value) {
|
|
1557
|
+
let j, jj;
|
|
1558
|
+
for (j = start, jj = arr.length; j < jj; ++j) {
|
|
1559
|
+
if (arr[j] !== value) {
|
|
1560
|
+
return j;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
return j;
|
|
1564
|
+
}
|
|
1565
|
+
function reverseValues(arr, start, end) {
|
|
1566
|
+
for (let i = start, j = end - 1; i < j; ++i, --j) {
|
|
1567
|
+
const temp = arr[i];
|
|
1568
|
+
arr[i] = arr[j];
|
|
1569
|
+
arr[j] = temp;
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
function createBidiText(str, isLTR, vertical = false) {
|
|
1573
|
+
let dir = "ltr";
|
|
1574
|
+
if (vertical) {
|
|
1575
|
+
dir = "ttb";
|
|
1576
|
+
} else if (!isLTR) {
|
|
1577
|
+
dir = "rtl";
|
|
1578
|
+
}
|
|
1579
|
+
return { str, dir };
|
|
1580
|
+
}
|
|
1581
|
+
var chars = [];
|
|
1582
|
+
var types = [];
|
|
1583
|
+
function bidi(str, startLevel = -1, vertical = false) {
|
|
1584
|
+
let isLTR = true;
|
|
1585
|
+
const strLength = str.length;
|
|
1586
|
+
if (strLength === 0 || vertical) {
|
|
1587
|
+
return createBidiText(str, isLTR, vertical);
|
|
1588
|
+
}
|
|
1589
|
+
chars.length = strLength;
|
|
1590
|
+
types.length = strLength;
|
|
1591
|
+
let numBidi = 0;
|
|
1592
|
+
let i, ii;
|
|
1593
|
+
for (i = 0; i < strLength; ++i) {
|
|
1594
|
+
chars[i] = str.charAt(i);
|
|
1595
|
+
const charCode = str.charCodeAt(i);
|
|
1596
|
+
let charType = "L";
|
|
1597
|
+
if (charCode <= 255) {
|
|
1598
|
+
charType = baseTypes[charCode];
|
|
1599
|
+
} else if (1424 <= charCode && charCode <= 1524) {
|
|
1600
|
+
charType = "R";
|
|
1601
|
+
} else if (1536 <= charCode && charCode <= 1791) {
|
|
1602
|
+
charType = arabicTypes[charCode & 255];
|
|
1603
|
+
if (!charType) {
|
|
1604
|
+
warn("Bidi: invalid Unicode character " + charCode.toString(16));
|
|
1605
|
+
}
|
|
1606
|
+
} else if (1792 <= charCode && charCode <= 2220 || 64336 <= charCode && charCode <= 65023 || 65136 <= charCode && charCode <= 65279) {
|
|
1607
|
+
charType = "AL";
|
|
1608
|
+
}
|
|
1609
|
+
if (charType === "R" || charType === "AL" || charType === "AN") {
|
|
1610
|
+
numBidi++;
|
|
1611
|
+
}
|
|
1612
|
+
types[i] = charType;
|
|
1613
|
+
}
|
|
1614
|
+
if (numBidi === 0) {
|
|
1615
|
+
isLTR = true;
|
|
1616
|
+
return createBidiText(str, isLTR);
|
|
1617
|
+
}
|
|
1618
|
+
if (startLevel === -1) {
|
|
1619
|
+
if (numBidi / strLength < 0.3 && strLength > 4) {
|
|
1620
|
+
isLTR = true;
|
|
1621
|
+
startLevel = 0;
|
|
1622
|
+
} else {
|
|
1623
|
+
isLTR = false;
|
|
1624
|
+
startLevel = 1;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
const levels = [];
|
|
1628
|
+
for (i = 0; i < strLength; ++i) {
|
|
1629
|
+
levels[i] = startLevel;
|
|
1630
|
+
}
|
|
1631
|
+
const e = isOdd(startLevel) ? "R" : "L";
|
|
1632
|
+
const sor = e;
|
|
1633
|
+
const eor = sor;
|
|
1634
|
+
let lastType = sor;
|
|
1635
|
+
for (i = 0; i < strLength; ++i) {
|
|
1636
|
+
if (types[i] === "NSM") {
|
|
1637
|
+
types[i] = lastType;
|
|
1638
|
+
} else {
|
|
1639
|
+
lastType = types[i];
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
lastType = sor;
|
|
1643
|
+
let t;
|
|
1644
|
+
for (i = 0; i < strLength; ++i) {
|
|
1645
|
+
t = types[i];
|
|
1646
|
+
if (t === "EN") {
|
|
1647
|
+
types[i] = lastType === "AL" ? "AN" : "EN";
|
|
1648
|
+
} else if (t === "R" || t === "L" || t === "AL") {
|
|
1649
|
+
lastType = t;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
for (i = 0; i < strLength; ++i) {
|
|
1653
|
+
t = types[i];
|
|
1654
|
+
if (t === "AL") {
|
|
1655
|
+
types[i] = "R";
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
for (i = 1; i < strLength - 1; ++i) {
|
|
1659
|
+
if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
|
|
1660
|
+
types[i] = "EN";
|
|
1661
|
+
}
|
|
1662
|
+
if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
|
|
1663
|
+
types[i] = types[i - 1];
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
for (i = 0; i < strLength; ++i) {
|
|
1667
|
+
if (types[i] === "EN") {
|
|
1668
|
+
for (let j = i - 1; j >= 0; --j) {
|
|
1669
|
+
if (types[j] !== "ET") {
|
|
1670
|
+
break;
|
|
1671
|
+
}
|
|
1672
|
+
types[j] = "EN";
|
|
1673
|
+
}
|
|
1674
|
+
for (let j = i + 1; j < strLength; ++j) {
|
|
1675
|
+
if (types[j] !== "ET") {
|
|
1676
|
+
break;
|
|
1677
|
+
}
|
|
1678
|
+
types[j] = "EN";
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
for (i = 0; i < strLength; ++i) {
|
|
1683
|
+
t = types[i];
|
|
1684
|
+
if (t === "WS" || t === "ES" || t === "ET" || t === "CS") {
|
|
1685
|
+
types[i] = "ON";
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
lastType = sor;
|
|
1689
|
+
for (i = 0; i < strLength; ++i) {
|
|
1690
|
+
t = types[i];
|
|
1691
|
+
if (t === "EN") {
|
|
1692
|
+
types[i] = lastType === "L" ? "L" : "EN";
|
|
1693
|
+
} else if (t === "R" || t === "L") {
|
|
1694
|
+
lastType = t;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
for (i = 0; i < strLength; ++i) {
|
|
1698
|
+
if (types[i] === "ON") {
|
|
1699
|
+
const end = findUnequal(types, i + 1, "ON");
|
|
1700
|
+
let before = sor;
|
|
1701
|
+
if (i > 0) {
|
|
1702
|
+
before = types[i - 1];
|
|
1703
|
+
}
|
|
1704
|
+
let after = eor;
|
|
1705
|
+
if (end + 1 < strLength) {
|
|
1706
|
+
after = types[end + 1];
|
|
1707
|
+
}
|
|
1708
|
+
if (before !== "L") {
|
|
1709
|
+
before = "R";
|
|
1710
|
+
}
|
|
1711
|
+
if (after !== "L") {
|
|
1712
|
+
after = "R";
|
|
1713
|
+
}
|
|
1714
|
+
if (before === after) {
|
|
1715
|
+
types.fill(before, i, end);
|
|
1716
|
+
}
|
|
1717
|
+
i = end - 1;
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
for (i = 0; i < strLength; ++i) {
|
|
1721
|
+
if (types[i] === "ON") {
|
|
1722
|
+
types[i] = e;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
for (i = 0; i < strLength; ++i) {
|
|
1726
|
+
t = types[i];
|
|
1727
|
+
if (isEven(levels[i])) {
|
|
1728
|
+
if (t === "R") {
|
|
1729
|
+
levels[i] += 1;
|
|
1730
|
+
} else if (t === "AN" || t === "EN") {
|
|
1731
|
+
levels[i] += 2;
|
|
1732
|
+
}
|
|
1733
|
+
} else if (
|
|
1734
|
+
/* isOdd && */
|
|
1735
|
+
t === "L" || t === "AN" || t === "EN"
|
|
1736
|
+
) {
|
|
1737
|
+
levels[i] += 1;
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
let highestLevel = -1;
|
|
1741
|
+
let lowestOddLevel = 99;
|
|
1742
|
+
let level;
|
|
1743
|
+
for (i = 0, ii = levels.length; i < ii; ++i) {
|
|
1744
|
+
level = levels[i];
|
|
1745
|
+
if (highestLevel < level) {
|
|
1746
|
+
highestLevel = level;
|
|
1747
|
+
}
|
|
1748
|
+
if (lowestOddLevel > level && isOdd(level)) {
|
|
1749
|
+
lowestOddLevel = level;
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
for (level = highestLevel; level >= lowestOddLevel; --level) {
|
|
1753
|
+
let start = -1;
|
|
1754
|
+
for (i = 0, ii = levels.length; i < ii; ++i) {
|
|
1755
|
+
if (levels[i] < level) {
|
|
1756
|
+
if (start >= 0) {
|
|
1757
|
+
reverseValues(chars, start, i);
|
|
1758
|
+
start = -1;
|
|
1759
|
+
}
|
|
1760
|
+
} else if (start < 0) {
|
|
1761
|
+
start = i;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
if (start >= 0) {
|
|
1765
|
+
reverseValues(chars, start, levels.length);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
for (i = 0, ii = chars.length; i < ii; ++i) {
|
|
1769
|
+
const ch = chars[i];
|
|
1770
|
+
if (ch === "<" || ch === ">") {
|
|
1771
|
+
chars[i] = "";
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
return createBidiText(chars.join(""), isLTR);
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
// src/pdf.js/src/shared/scripting_utils.js
|
|
1778
|
+
function makeColorComp(n) {
|
|
1779
|
+
return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
|
|
1780
|
+
}
|
|
1781
|
+
function scaleAndClamp(x) {
|
|
1782
|
+
return Math.max(0, Math.min(255, 255 * x));
|
|
1783
|
+
}
|
|
1784
|
+
var ColorConverters = class {
|
|
1785
|
+
static CMYK_G([c, y, m, k]) {
|
|
1786
|
+
return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
|
|
1787
|
+
}
|
|
1788
|
+
static G_CMYK([g]) {
|
|
1789
|
+
return ["CMYK", 0, 0, 0, 1 - g];
|
|
1790
|
+
}
|
|
1791
|
+
static G_RGB([g]) {
|
|
1792
|
+
return ["RGB", g, g, g];
|
|
1793
|
+
}
|
|
1794
|
+
static G_rgb([g]) {
|
|
1795
|
+
g = scaleAndClamp(g);
|
|
1796
|
+
return [g, g, g];
|
|
1797
|
+
}
|
|
1798
|
+
static G_HTML([g]) {
|
|
1799
|
+
const G = makeColorComp(g);
|
|
1800
|
+
return `#${G}${G}${G}`;
|
|
1801
|
+
}
|
|
1802
|
+
static RGB_G([r, g, b]) {
|
|
1803
|
+
return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
|
|
1804
|
+
}
|
|
1805
|
+
static RGB_rgb(color) {
|
|
1806
|
+
return color.map(scaleAndClamp);
|
|
1807
|
+
}
|
|
1808
|
+
static RGB_HTML(color) {
|
|
1809
|
+
return `#${color.map(makeColorComp).join("")}`;
|
|
1810
|
+
}
|
|
1811
|
+
static T_HTML() {
|
|
1812
|
+
return "#00000000";
|
|
1813
|
+
}
|
|
1814
|
+
static T_rgb() {
|
|
1815
|
+
return [null];
|
|
1816
|
+
}
|
|
1817
|
+
static CMYK_RGB([c, y, m, k]) {
|
|
1818
|
+
return [
|
|
1819
|
+
"RGB",
|
|
1820
|
+
1 - Math.min(1, c + k),
|
|
1821
|
+
1 - Math.min(1, m + k),
|
|
1822
|
+
1 - Math.min(1, y + k)
|
|
1823
|
+
];
|
|
1824
|
+
}
|
|
1825
|
+
static CMYK_rgb([c, y, m, k]) {
|
|
1826
|
+
return [
|
|
1827
|
+
scaleAndClamp(1 - Math.min(1, c + k)),
|
|
1828
|
+
scaleAndClamp(1 - Math.min(1, m + k)),
|
|
1829
|
+
scaleAndClamp(1 - Math.min(1, y + k))
|
|
1830
|
+
];
|
|
1831
|
+
}
|
|
1832
|
+
static CMYK_HTML(components) {
|
|
1833
|
+
const rgb = this.CMYK_RGB(components).slice(1);
|
|
1834
|
+
return this.RGB_HTML(rgb);
|
|
1835
|
+
}
|
|
1836
|
+
static RGB_CMYK([r, g, b]) {
|
|
1837
|
+
const c = 1 - r;
|
|
1838
|
+
const m = 1 - g;
|
|
1839
|
+
const y = 1 - b;
|
|
1840
|
+
const k = Math.min(c, m, y);
|
|
1841
|
+
return ["CMYK", c, m, y, k];
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1844
|
+
var DateFormats = [
|
|
1845
|
+
"m/d",
|
|
1846
|
+
"m/d/yy",
|
|
1847
|
+
"mm/dd/yy",
|
|
1848
|
+
"mm/yy",
|
|
1849
|
+
"d-mmm",
|
|
1850
|
+
"d-mmm-yy",
|
|
1851
|
+
"dd-mmm-yy",
|
|
1852
|
+
"yy-mm-dd",
|
|
1853
|
+
"mmm-yy",
|
|
1854
|
+
"mmmm-yy",
|
|
1855
|
+
"mmm d, yyyy",
|
|
1856
|
+
"mmmm d, yyyy",
|
|
1857
|
+
"m/d/yy h:MM tt",
|
|
1858
|
+
"m/d/yy HH:MM"
|
|
1859
|
+
];
|
|
1860
|
+
var TimeFormats = ["HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt"];
|
|
1861
|
+
|
|
1862
|
+
// src/pdf.js/src/shared/murmurhash3.js
|
|
1863
|
+
var SEED = 3285377520;
|
|
1864
|
+
var MASK_HIGH = 4294901760;
|
|
1865
|
+
var MASK_LOW = 65535;
|
|
1866
|
+
var MurmurHash3_64 = class {
|
|
1867
|
+
constructor(seed) {
|
|
1868
|
+
this.h1 = seed ? seed & 4294967295 : SEED;
|
|
1869
|
+
this.h2 = seed ? seed & 4294967295 : SEED;
|
|
1870
|
+
}
|
|
1871
|
+
update(input) {
|
|
1872
|
+
let data, length;
|
|
1873
|
+
if (typeof input === "string") {
|
|
1874
|
+
data = new Uint8Array(input.length * 2);
|
|
1875
|
+
length = 0;
|
|
1876
|
+
for (let i = 0, ii = input.length; i < ii; i++) {
|
|
1877
|
+
const code = input.charCodeAt(i);
|
|
1878
|
+
if (code <= 255) {
|
|
1879
|
+
data[length++] = code;
|
|
1880
|
+
} else {
|
|
1881
|
+
data[length++] = code >>> 8;
|
|
1882
|
+
data[length++] = code & 255;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
1886
|
+
data = input.slice();
|
|
1887
|
+
length = data.byteLength;
|
|
1888
|
+
} else {
|
|
1889
|
+
throw new Error("Invalid data format, must be a string or TypedArray.");
|
|
1890
|
+
}
|
|
1891
|
+
const blockCounts = length >> 2;
|
|
1892
|
+
const tailLength = length - blockCounts * 4;
|
|
1893
|
+
const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
|
|
1894
|
+
let k1 = 0, k2 = 0;
|
|
1895
|
+
let h1 = this.h1, h2 = this.h2;
|
|
1896
|
+
const C1 = 3432918353, C2 = 461845907;
|
|
1897
|
+
const C1_LOW = C1 & MASK_LOW, C2_LOW = C2 & MASK_LOW;
|
|
1898
|
+
for (let i = 0; i < blockCounts; i++) {
|
|
1899
|
+
if (i & 1) {
|
|
1900
|
+
k1 = dataUint32[i];
|
|
1901
|
+
k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
|
1902
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
1903
|
+
k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
|
1904
|
+
h1 ^= k1;
|
|
1905
|
+
h1 = h1 << 13 | h1 >>> 19;
|
|
1906
|
+
h1 = h1 * 5 + 3864292196;
|
|
1907
|
+
} else {
|
|
1908
|
+
k2 = dataUint32[i];
|
|
1909
|
+
k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
|
|
1910
|
+
k2 = k2 << 15 | k2 >>> 17;
|
|
1911
|
+
k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
|
|
1912
|
+
h2 ^= k2;
|
|
1913
|
+
h2 = h2 << 13 | h2 >>> 19;
|
|
1914
|
+
h2 = h2 * 5 + 3864292196;
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
k1 = 0;
|
|
1918
|
+
switch (tailLength) {
|
|
1919
|
+
case 3:
|
|
1920
|
+
k1 ^= data[blockCounts * 4 + 2] << 16;
|
|
1921
|
+
/* falls through */
|
|
1922
|
+
case 2:
|
|
1923
|
+
k1 ^= data[blockCounts * 4 + 1] << 8;
|
|
1924
|
+
/* falls through */
|
|
1925
|
+
case 1:
|
|
1926
|
+
k1 ^= data[blockCounts * 4];
|
|
1927
|
+
k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
|
|
1928
|
+
k1 = k1 << 15 | k1 >>> 17;
|
|
1929
|
+
k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
|
|
1930
|
+
if (blockCounts & 1) {
|
|
1931
|
+
h1 ^= k1;
|
|
1932
|
+
} else {
|
|
1933
|
+
h2 ^= k1;
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
this.h1 = h1;
|
|
1937
|
+
this.h2 = h2;
|
|
1938
|
+
}
|
|
1939
|
+
hexdigest() {
|
|
1940
|
+
let h1 = this.h1, h2 = this.h2;
|
|
1941
|
+
h1 ^= h2 >>> 1;
|
|
1942
|
+
h1 = h1 * 3981806797 & MASK_HIGH | h1 * 36045 & MASK_LOW;
|
|
1943
|
+
h2 = h2 * 4283543511 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 2950163797 & MASK_HIGH) >>> 16;
|
|
1944
|
+
h1 ^= h2 >>> 1;
|
|
1945
|
+
h1 = h1 * 444984403 & MASK_HIGH | h1 * 60499 & MASK_LOW;
|
|
1946
|
+
h2 = h2 * 3301882366 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 3120437893 & MASK_HIGH) >>> 16;
|
|
1947
|
+
h1 ^= h2 >>> 1;
|
|
1948
|
+
return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
|
|
1952
|
+
// src/pdf.js/src/shared/image_utils.js
|
|
1953
|
+
function convertToRGBA(params) {
|
|
1954
|
+
switch (params.kind) {
|
|
1955
|
+
case ImageKind.GRAYSCALE_1BPP:
|
|
1956
|
+
return convertBlackAndWhiteToRGBA(params);
|
|
1957
|
+
case ImageKind.RGB_24BPP:
|
|
1958
|
+
return convertRGBToRGBA(params);
|
|
1959
|
+
}
|
|
1960
|
+
return null;
|
|
1961
|
+
}
|
|
1962
|
+
function convertBlackAndWhiteToRGBA({
|
|
1963
|
+
src,
|
|
1964
|
+
srcPos = 0,
|
|
1965
|
+
dest,
|
|
1966
|
+
width,
|
|
1967
|
+
height,
|
|
1968
|
+
nonBlackColor = 4294967295,
|
|
1969
|
+
inverseDecode = false
|
|
1970
|
+
}) {
|
|
1971
|
+
const black = FeatureTest.isLittleEndian ? 4278190080 : 255;
|
|
1972
|
+
const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
|
|
1973
|
+
const widthInSource = width >> 3;
|
|
1974
|
+
const widthRemainder = width & 7;
|
|
1975
|
+
const srcLength = src.length;
|
|
1976
|
+
dest = new Uint32Array(dest.buffer);
|
|
1977
|
+
let destPos = 0;
|
|
1978
|
+
for (let i = 0; i < height; i++) {
|
|
1979
|
+
for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
|
|
1980
|
+
const elem2 = srcPos < srcLength ? src[srcPos] : 255;
|
|
1981
|
+
dest[destPos++] = elem2 & 128 ? oneMapping : zeroMapping;
|
|
1982
|
+
dest[destPos++] = elem2 & 64 ? oneMapping : zeroMapping;
|
|
1983
|
+
dest[destPos++] = elem2 & 32 ? oneMapping : zeroMapping;
|
|
1984
|
+
dest[destPos++] = elem2 & 16 ? oneMapping : zeroMapping;
|
|
1985
|
+
dest[destPos++] = elem2 & 8 ? oneMapping : zeroMapping;
|
|
1986
|
+
dest[destPos++] = elem2 & 4 ? oneMapping : zeroMapping;
|
|
1987
|
+
dest[destPos++] = elem2 & 2 ? oneMapping : zeroMapping;
|
|
1988
|
+
dest[destPos++] = elem2 & 1 ? oneMapping : zeroMapping;
|
|
1989
|
+
}
|
|
1990
|
+
if (widthRemainder === 0) {
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
const elem = srcPos < srcLength ? src[srcPos++] : 255;
|
|
1994
|
+
for (let j = 0; j < widthRemainder; j++) {
|
|
1995
|
+
dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
return { srcPos, destPos };
|
|
1999
|
+
}
|
|
2000
|
+
function convertRGBToRGBA({
|
|
2001
|
+
src,
|
|
2002
|
+
srcPos = 0,
|
|
2003
|
+
dest,
|
|
2004
|
+
destPos = 0,
|
|
2005
|
+
width,
|
|
2006
|
+
height
|
|
2007
|
+
}) {
|
|
2008
|
+
let i = 0;
|
|
2009
|
+
const len = width * height * 3;
|
|
2010
|
+
const len32 = len >> 2;
|
|
2011
|
+
const src32 = new Uint32Array(src.buffer, srcPos, len32);
|
|
2012
|
+
if (FeatureTest.isLittleEndian) {
|
|
2013
|
+
for (; i < len32 - 2; i += 3, destPos += 4) {
|
|
2014
|
+
const s1 = src32[i];
|
|
2015
|
+
const s2 = src32[i + 1];
|
|
2016
|
+
const s3 = src32[i + 2];
|
|
2017
|
+
dest[destPos] = s1 | 4278190080;
|
|
2018
|
+
dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 4278190080;
|
|
2019
|
+
dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 4278190080;
|
|
2020
|
+
dest[destPos + 3] = s3 >>> 8 | 4278190080;
|
|
2021
|
+
}
|
|
2022
|
+
for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
|
|
2023
|
+
dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 4278190080;
|
|
2024
|
+
}
|
|
2025
|
+
} else {
|
|
2026
|
+
for (; i < len32 - 2; i += 3, destPos += 4) {
|
|
2027
|
+
const s1 = src32[i];
|
|
2028
|
+
const s2 = src32[i + 1];
|
|
2029
|
+
const s3 = src32[i + 2];
|
|
2030
|
+
dest[destPos] = s1 | 255;
|
|
2031
|
+
dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 255;
|
|
2032
|
+
dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 255;
|
|
2033
|
+
dest[destPos + 3] = s3 << 8 | 255;
|
|
2034
|
+
}
|
|
2035
|
+
for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
|
|
2036
|
+
dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 255;
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return { srcPos: srcPos + len, destPos };
|
|
2040
|
+
}
|
|
2041
|
+
function grayToRGBA(src, dest) {
|
|
2042
|
+
if (FeatureTest.isLittleEndian) {
|
|
2043
|
+
for (let i = 0, ii = src.length; i < ii; i++) {
|
|
2044
|
+
dest[i] = src[i] * 65793 | 4278190080;
|
|
2045
|
+
}
|
|
2046
|
+
} else {
|
|
2047
|
+
for (let i = 0, ii = src.length; i < ii; i++) {
|
|
2048
|
+
dest[i] = src[i] * 16843008 | 255;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
export {
|
|
2054
|
+
MurmurHash3_64,
|
|
2055
|
+
wrapReason,
|
|
2056
|
+
MessageHandler,
|
|
2057
|
+
convertToRGBA,
|
|
2058
|
+
convertBlackAndWhiteToRGBA,
|
|
2059
|
+
grayToRGBA,
|
|
2060
|
+
FontInfo,
|
|
2061
|
+
bidi,
|
|
2062
|
+
ColorConverters,
|
|
2063
|
+
DateFormats,
|
|
2064
|
+
TimeFormats
|
|
2065
|
+
};
|