| 1 |
/** |
| 2 |
* @licstart The following is the entire license notice for the |
| 3 |
* JavaScript code in this page |
| 4 |
* |
| 5 |
* Copyright 2024 Mozilla Foundation |
| 6 |
* |
| 7 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
* you may not use this file except in compliance with the License. |
| 9 |
* You may obtain a copy of the License at |
| 10 |
* |
| 11 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
* |
| 13 |
* Unless required by applicable law or agreed to in writing, software |
| 14 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
* See the License for the specific language governing permissions and |
| 17 |
* limitations under the License. |
| 18 |
* |
| 19 |
* @licend The above is the entire license notice for the |
| 20 |
* JavaScript code in this page |
| 21 |
*/ |
| 22 |
|
| 23 |
/** |
| 24 |
* pdfjsVersion = 5.3.31 |
| 25 |
* pdfjsBuild = 47ad820d9 |
| 26 |
*/ |
| 27 |
/******/ var __webpack_modules__ = ({ |
| 28 |
|
| 29 |
/***/ 34: |
| 30 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 31 |
|
| 32 |
|
| 33 |
var isCallable = __webpack_require__(4901); |
| 34 |
|
| 35 |
module.exports = function (it) { |
| 36 |
return typeof it == 'object' ? it !== null : isCallable(it); |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
/***/ }), |
| 41 |
|
| 42 |
/***/ 81: |
| 43 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 44 |
|
| 45 |
|
| 46 |
var call = __webpack_require__(9565); |
| 47 |
var aCallable = __webpack_require__(9306); |
| 48 |
var anObject = __webpack_require__(8551); |
| 49 |
var tryToString = __webpack_require__(6823); |
| 50 |
var getIteratorMethod = __webpack_require__(851); |
| 51 |
|
| 52 |
var $TypeError = TypeError; |
| 53 |
|
| 54 |
module.exports = function (argument, usingIterator) { |
| 55 |
var iteratorMethod = arguments.length < 2 ? getIteratorMethod(argument) : usingIterator; |
| 56 |
if (aCallable(iteratorMethod)) return anObject(call(iteratorMethod, argument)); |
| 57 |
throw new $TypeError(tryToString(argument) + ' is not iterable'); |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
/***/ }), |
| 62 |
|
| 63 |
/***/ 283: |
| 64 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 65 |
|
| 66 |
|
| 67 |
var uncurryThis = __webpack_require__(9504); |
| 68 |
var fails = __webpack_require__(9039); |
| 69 |
var isCallable = __webpack_require__(4901); |
| 70 |
var hasOwn = __webpack_require__(9297); |
| 71 |
var DESCRIPTORS = __webpack_require__(3724); |
| 72 |
var CONFIGURABLE_FUNCTION_NAME = (__webpack_require__(350).CONFIGURABLE); |
| 73 |
var inspectSource = __webpack_require__(3706); |
| 74 |
var InternalStateModule = __webpack_require__(1181); |
| 75 |
|
| 76 |
var enforceInternalState = InternalStateModule.enforce; |
| 77 |
var getInternalState = InternalStateModule.get; |
| 78 |
var $String = String; |
| 79 |
// eslint-disable-next-line es/no-object-defineproperty -- safe |
| 80 |
var defineProperty = Object.defineProperty; |
| 81 |
var stringSlice = uncurryThis(''.slice); |
| 82 |
var replace = uncurryThis(''.replace); |
| 83 |
var join = uncurryThis([].join); |
| 84 |
|
| 85 |
var CONFIGURABLE_LENGTH = DESCRIPTORS && !fails(function () { |
| 86 |
return defineProperty(function () { /* empty */ }, 'length', { value: 8 }).length !== 8; |
| 87 |
}); |
| 88 |
|
| 89 |
var TEMPLATE = String(String).split('String'); |
| 90 |
|
| 91 |
var makeBuiltIn = module.exports = function (value, name, options) { |
| 92 |
if (stringSlice($String(name), 0, 7) === 'Symbol(') { |
| 93 |
name = '[' + replace($String(name), /^Symbol\(([^)]*)\).*$/, '$1') + ']'; |
| 94 |
} |
| 95 |
if (options && options.getter) name = 'get ' + name; |
| 96 |
if (options && options.setter) name = 'set ' + name; |
| 97 |
if (!hasOwn(value, 'name') || (CONFIGURABLE_FUNCTION_NAME && value.name !== name)) { |
| 98 |
if (DESCRIPTORS) defineProperty(value, 'name', { value: name, configurable: true }); |
| 99 |
else value.name = name; |
| 100 |
} |
| 101 |
if (CONFIGURABLE_LENGTH && options && hasOwn(options, 'arity') && value.length !== options.arity) { |
| 102 |
defineProperty(value, 'length', { value: options.arity }); |
| 103 |
} |
| 104 |
try { |
| 105 |
if (options && hasOwn(options, 'constructor') && options.constructor) { |
| 106 |
if (DESCRIPTORS) defineProperty(value, 'prototype', { writable: false }); |
| 107 |
// in V8 ~ Chrome 53, prototypes of some methods, like `Array.prototype.values`, are non-writable |
| 108 |
} else if (value.prototype) value.prototype = undefined; |
| 109 |
} catch (error) { /* empty */ } |
| 110 |
var state = enforceInternalState(value); |
| 111 |
if (!hasOwn(state, 'source')) { |
| 112 |
state.source = join(TEMPLATE, typeof name == 'string' ? name : ''); |
| 113 |
} return value; |
| 114 |
}; |
| 115 |
|
| 116 |
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative |
| 117 |
// eslint-disable-next-line no-extend-native -- required |
| 118 |
Function.prototype.toString = makeBuiltIn(function toString() { |
| 119 |
return isCallable(this) && getInternalState(this).source || inspectSource(this); |
| 120 |
}, 'toString'); |
| 121 |
|
| 122 |
|
| 123 |
/***/ }), |
| 124 |
|
| 125 |
/***/ 350: |
| 126 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 127 |
|
| 128 |
|
| 129 |
var DESCRIPTORS = __webpack_require__(3724); |
| 130 |
var hasOwn = __webpack_require__(9297); |
| 131 |
|
| 132 |
var FunctionPrototype = Function.prototype; |
| 133 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 134 |
var getDescriptor = DESCRIPTORS && Object.getOwnPropertyDescriptor; |
| 135 |
|
| 136 |
var EXISTS = hasOwn(FunctionPrototype, 'name'); |
| 137 |
// additional protection from minified / mangled / dropped function names |
| 138 |
var PROPER = EXISTS && (function something() { /* empty */ }).name === 'something'; |
| 139 |
var CONFIGURABLE = EXISTS && (!DESCRIPTORS || (DESCRIPTORS && getDescriptor(FunctionPrototype, 'name').configurable)); |
| 140 |
|
| 141 |
module.exports = { |
| 142 |
EXISTS: EXISTS, |
| 143 |
PROPER: PROPER, |
| 144 |
CONFIGURABLE: CONFIGURABLE |
| 145 |
}; |
| 146 |
|
| 147 |
|
| 148 |
/***/ }), |
| 149 |
|
| 150 |
/***/ 397: |
| 151 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 152 |
|
| 153 |
|
| 154 |
var getBuiltIn = __webpack_require__(7751); |
| 155 |
|
| 156 |
module.exports = getBuiltIn('document', 'documentElement'); |
| 157 |
|
| 158 |
|
| 159 |
/***/ }), |
| 160 |
|
| 161 |
/***/ 421: |
| 162 |
/***/ ((module) => { |
| 163 |
|
| 164 |
|
| 165 |
module.exports = {}; |
| 166 |
|
| 167 |
|
| 168 |
/***/ }), |
| 169 |
|
| 170 |
/***/ 507: |
| 171 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 172 |
|
| 173 |
|
| 174 |
var call = __webpack_require__(9565); |
| 175 |
|
| 176 |
module.exports = function (record, fn, ITERATOR_INSTEAD_OF_RECORD) { |
| 177 |
var iterator = ITERATOR_INSTEAD_OF_RECORD ? record : record.iterator; |
| 178 |
var next = record.next; |
| 179 |
var step, result; |
| 180 |
while (!(step = call(next, iterator)).done) { |
| 181 |
result = fn(step.value); |
| 182 |
if (result !== undefined) return result; |
| 183 |
} |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
/***/ }), |
| 188 |
|
| 189 |
/***/ 616: |
| 190 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 191 |
|
| 192 |
|
| 193 |
var fails = __webpack_require__(9039); |
| 194 |
|
| 195 |
module.exports = !fails(function () { |
| 196 |
// eslint-disable-next-line es/no-function-prototype-bind -- safe |
| 197 |
var test = (function () { /* empty */ }).bind(); |
| 198 |
// eslint-disable-next-line no-prototype-builtins -- safe |
| 199 |
return typeof test != 'function' || test.hasOwnProperty('prototype'); |
| 200 |
}); |
| 201 |
|
| 202 |
|
| 203 |
/***/ }), |
| 204 |
|
| 205 |
/***/ 655: |
| 206 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 207 |
|
| 208 |
|
| 209 |
var classof = __webpack_require__(6955); |
| 210 |
|
| 211 |
var $String = String; |
| 212 |
|
| 213 |
module.exports = function (argument) { |
| 214 |
if (classof(argument) === 'Symbol') throw new TypeError('Cannot convert a Symbol value to a string'); |
| 215 |
return $String(argument); |
| 216 |
}; |
| 217 |
|
| 218 |
|
| 219 |
/***/ }), |
| 220 |
|
| 221 |
/***/ 679: |
| 222 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 223 |
|
| 224 |
|
| 225 |
var isPrototypeOf = __webpack_require__(1625); |
| 226 |
|
| 227 |
var $TypeError = TypeError; |
| 228 |
|
| 229 |
module.exports = function (it, Prototype) { |
| 230 |
if (isPrototypeOf(Prototype, it)) return it; |
| 231 |
throw new $TypeError('Incorrect invocation'); |
| 232 |
}; |
| 233 |
|
| 234 |
|
| 235 |
/***/ }), |
| 236 |
|
| 237 |
/***/ 741: |
| 238 |
/***/ ((module) => { |
| 239 |
|
| 240 |
|
| 241 |
var ceil = Math.ceil; |
| 242 |
var floor = Math.floor; |
| 243 |
|
| 244 |
// `Math.trunc` method |
| 245 |
// https://tc39.es/ecma262/#sec-math.trunc |
| 246 |
// eslint-disable-next-line es/no-math-trunc -- safe |
| 247 |
module.exports = Math.trunc || function trunc(x) { |
| 248 |
var n = +x; |
| 249 |
return (n > 0 ? floor : ceil)(n); |
| 250 |
}; |
| 251 |
|
| 252 |
|
| 253 |
/***/ }), |
| 254 |
|
| 255 |
/***/ 757: |
| 256 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 257 |
|
| 258 |
|
| 259 |
var getBuiltIn = __webpack_require__(7751); |
| 260 |
var isCallable = __webpack_require__(4901); |
| 261 |
var isPrototypeOf = __webpack_require__(1625); |
| 262 |
var USE_SYMBOL_AS_UID = __webpack_require__(7040); |
| 263 |
|
| 264 |
var $Object = Object; |
| 265 |
|
| 266 |
module.exports = USE_SYMBOL_AS_UID ? function (it) { |
| 267 |
return typeof it == 'symbol'; |
| 268 |
} : function (it) { |
| 269 |
var $Symbol = getBuiltIn('Symbol'); |
| 270 |
return isCallable($Symbol) && isPrototypeOf($Symbol.prototype, $Object(it)); |
| 271 |
}; |
| 272 |
|
| 273 |
|
| 274 |
/***/ }), |
| 275 |
|
| 276 |
/***/ 851: |
| 277 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 278 |
|
| 279 |
|
| 280 |
var classof = __webpack_require__(6955); |
| 281 |
var getMethod = __webpack_require__(5966); |
| 282 |
var isNullOrUndefined = __webpack_require__(4117); |
| 283 |
var Iterators = __webpack_require__(6269); |
| 284 |
var wellKnownSymbol = __webpack_require__(8227); |
| 285 |
|
| 286 |
var ITERATOR = wellKnownSymbol('iterator'); |
| 287 |
|
| 288 |
module.exports = function (it) { |
| 289 |
if (!isNullOrUndefined(it)) return getMethod(it, ITERATOR) |
| 290 |
|| getMethod(it, '@@iterator') |
| 291 |
|| Iterators[classof(it)]; |
| 292 |
}; |
| 293 |
|
| 294 |
|
| 295 |
/***/ }), |
| 296 |
|
| 297 |
/***/ 1072: |
| 298 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 299 |
|
| 300 |
|
| 301 |
var internalObjectKeys = __webpack_require__(1828); |
| 302 |
var enumBugKeys = __webpack_require__(8727); |
| 303 |
|
| 304 |
// `Object.keys` method |
| 305 |
// https://tc39.es/ecma262/#sec-object.keys |
| 306 |
// eslint-disable-next-line es/no-object-keys -- safe |
| 307 |
module.exports = Object.keys || function keys(O) { |
| 308 |
return internalObjectKeys(O, enumBugKeys); |
| 309 |
}; |
| 310 |
|
| 311 |
|
| 312 |
/***/ }), |
| 313 |
|
| 314 |
/***/ 1148: |
| 315 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 316 |
|
| 317 |
|
| 318 |
var $ = __webpack_require__(6518); |
| 319 |
var call = __webpack_require__(9565); |
| 320 |
var iterate = __webpack_require__(2652); |
| 321 |
var aCallable = __webpack_require__(9306); |
| 322 |
var anObject = __webpack_require__(8551); |
| 323 |
var getIteratorDirect = __webpack_require__(1767); |
| 324 |
var iteratorClose = __webpack_require__(9539); |
| 325 |
var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549); |
| 326 |
|
| 327 |
var everyWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('every', TypeError); |
| 328 |
|
| 329 |
// `Iterator.prototype.every` method |
| 330 |
// https://tc39.es/ecma262/#sec-iterator.prototype.every |
| 331 |
$({ target: 'Iterator', proto: true, real: true, forced: everyWithoutClosingOnEarlyError }, { |
| 332 |
every: function every(predicate) { |
| 333 |
anObject(this); |
| 334 |
try { |
| 335 |
aCallable(predicate); |
| 336 |
} catch (error) { |
| 337 |
iteratorClose(this, 'throw', error); |
| 338 |
} |
| 339 |
|
| 340 |
if (everyWithoutClosingOnEarlyError) return call(everyWithoutClosingOnEarlyError, this, predicate); |
| 341 |
|
| 342 |
var record = getIteratorDirect(this); |
| 343 |
var counter = 0; |
| 344 |
return !iterate(record, function (value, stop) { |
| 345 |
if (!predicate(value, counter++)) return stop(); |
| 346 |
}, { IS_RECORD: true, INTERRUPTED: true }).stopped; |
| 347 |
} |
| 348 |
}); |
| 349 |
|
| 350 |
|
| 351 |
/***/ }), |
| 352 |
|
| 353 |
/***/ 1181: |
| 354 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 355 |
|
| 356 |
|
| 357 |
var NATIVE_WEAK_MAP = __webpack_require__(8622); |
| 358 |
var globalThis = __webpack_require__(4576); |
| 359 |
var isObject = __webpack_require__(34); |
| 360 |
var createNonEnumerableProperty = __webpack_require__(6699); |
| 361 |
var hasOwn = __webpack_require__(9297); |
| 362 |
var shared = __webpack_require__(7629); |
| 363 |
var sharedKey = __webpack_require__(6119); |
| 364 |
var hiddenKeys = __webpack_require__(421); |
| 365 |
|
| 366 |
var OBJECT_ALREADY_INITIALIZED = 'Object already initialized'; |
| 367 |
var TypeError = globalThis.TypeError; |
| 368 |
var WeakMap = globalThis.WeakMap; |
| 369 |
var set, get, has; |
| 370 |
|
| 371 |
var enforce = function (it) { |
| 372 |
return has(it) ? get(it) : set(it, {}); |
| 373 |
}; |
| 374 |
|
| 375 |
var getterFor = function (TYPE) { |
| 376 |
return function (it) { |
| 377 |
var state; |
| 378 |
if (!isObject(it) || (state = get(it)).type !== TYPE) { |
| 379 |
throw new TypeError('Incompatible receiver, ' + TYPE + ' required'); |
| 380 |
} return state; |
| 381 |
}; |
| 382 |
}; |
| 383 |
|
| 384 |
if (NATIVE_WEAK_MAP || shared.state) { |
| 385 |
var store = shared.state || (shared.state = new WeakMap()); |
| 386 |
/* eslint-disable no-self-assign -- prototype methods protection */ |
| 387 |
store.get = store.get; |
| 388 |
store.has = store.has; |
| 389 |
store.set = store.set; |
| 390 |
/* eslint-enable no-self-assign -- prototype methods protection */ |
| 391 |
set = function (it, metadata) { |
| 392 |
if (store.has(it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED); |
| 393 |
metadata.facade = it; |
| 394 |
store.set(it, metadata); |
| 395 |
return metadata; |
| 396 |
}; |
| 397 |
get = function (it) { |
| 398 |
return store.get(it) || {}; |
| 399 |
}; |
| 400 |
has = function (it) { |
| 401 |
return store.has(it); |
| 402 |
}; |
| 403 |
} else { |
| 404 |
var STATE = sharedKey('state'); |
| 405 |
hiddenKeys[STATE] = true; |
| 406 |
set = function (it, metadata) { |
| 407 |
if (hasOwn(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED); |
| 408 |
metadata.facade = it; |
| 409 |
createNonEnumerableProperty(it, STATE, metadata); |
| 410 |
return metadata; |
| 411 |
}; |
| 412 |
get = function (it) { |
| 413 |
return hasOwn(it, STATE) ? it[STATE] : {}; |
| 414 |
}; |
| 415 |
has = function (it) { |
| 416 |
return hasOwn(it, STATE); |
| 417 |
}; |
| 418 |
} |
| 419 |
|
| 420 |
module.exports = { |
| 421 |
set: set, |
| 422 |
get: get, |
| 423 |
has: has, |
| 424 |
enforce: enforce, |
| 425 |
getterFor: getterFor |
| 426 |
}; |
| 427 |
|
| 428 |
|
| 429 |
/***/ }), |
| 430 |
|
| 431 |
/***/ 1291: |
| 432 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 433 |
|
| 434 |
|
| 435 |
var trunc = __webpack_require__(741); |
| 436 |
|
| 437 |
// `ToIntegerOrInfinity` abstract operation |
| 438 |
// https://tc39.es/ecma262/#sec-tointegerorinfinity |
| 439 |
module.exports = function (argument) { |
| 440 |
var number = +argument; |
| 441 |
// eslint-disable-next-line no-self-compare -- NaN check |
| 442 |
return number !== number || number === 0 ? 0 : trunc(number); |
| 443 |
}; |
| 444 |
|
| 445 |
|
| 446 |
/***/ }), |
| 447 |
|
| 448 |
/***/ 1548: |
| 449 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 450 |
|
| 451 |
|
| 452 |
var globalThis = __webpack_require__(4576); |
| 453 |
var fails = __webpack_require__(9039); |
| 454 |
var V8 = __webpack_require__(9519); |
| 455 |
var ENVIRONMENT = __webpack_require__(4215); |
| 456 |
|
| 457 |
var structuredClone = globalThis.structuredClone; |
| 458 |
|
| 459 |
module.exports = !!structuredClone && !fails(function () { |
| 460 |
// prevent V8 ArrayBufferDetaching protector cell invalidation and performance degradation |
| 461 |
// https://github.com/zloirock/core-js/issues/679 |
| 462 |
if ((ENVIRONMENT === 'DENO' && V8 > 92) || (ENVIRONMENT === 'NODE' && V8 > 94) || (ENVIRONMENT === 'BROWSER' && V8 > 97)) return false; |
| 463 |
var buffer = new ArrayBuffer(8); |
| 464 |
var clone = structuredClone(buffer, { transfer: [buffer] }); |
| 465 |
return buffer.byteLength !== 0 || clone.byteLength !== 8; |
| 466 |
}); |
| 467 |
|
| 468 |
|
| 469 |
/***/ }), |
| 470 |
|
| 471 |
/***/ 1625: |
| 472 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 473 |
|
| 474 |
|
| 475 |
var uncurryThis = __webpack_require__(9504); |
| 476 |
|
| 477 |
module.exports = uncurryThis({}.isPrototypeOf); |
| 478 |
|
| 479 |
|
| 480 |
/***/ }), |
| 481 |
|
| 482 |
/***/ 1698: |
| 483 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 484 |
|
| 485 |
|
| 486 |
var $ = __webpack_require__(6518); |
| 487 |
var union = __webpack_require__(4204); |
| 488 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 489 |
|
| 490 |
// `Set.prototype.union` method |
| 491 |
// https://tc39.es/ecma262/#sec-set.prototype.union |
| 492 |
$({ target: 'Set', proto: true, real: true, forced: !setMethodAcceptSetLike('union') }, { |
| 493 |
union: union |
| 494 |
}); |
| 495 |
|
| 496 |
|
| 497 |
/***/ }), |
| 498 |
|
| 499 |
/***/ 1701: |
| 500 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 501 |
|
| 502 |
|
| 503 |
var $ = __webpack_require__(6518); |
| 504 |
var call = __webpack_require__(9565); |
| 505 |
var aCallable = __webpack_require__(9306); |
| 506 |
var anObject = __webpack_require__(8551); |
| 507 |
var getIteratorDirect = __webpack_require__(1767); |
| 508 |
var createIteratorProxy = __webpack_require__(9462); |
| 509 |
var callWithSafeIterationClosing = __webpack_require__(6319); |
| 510 |
var iteratorClose = __webpack_require__(9539); |
| 511 |
var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549); |
| 512 |
var IS_PURE = __webpack_require__(6395); |
| 513 |
|
| 514 |
var mapWithoutClosingOnEarlyError = !IS_PURE && iteratorHelperWithoutClosingOnEarlyError('map', TypeError); |
| 515 |
|
| 516 |
var IteratorProxy = createIteratorProxy(function () { |
| 517 |
var iterator = this.iterator; |
| 518 |
var result = anObject(call(this.next, iterator)); |
| 519 |
var done = this.done = !!result.done; |
| 520 |
if (!done) return callWithSafeIterationClosing(iterator, this.mapper, [result.value, this.counter++], true); |
| 521 |
}); |
| 522 |
|
| 523 |
// `Iterator.prototype.map` method |
| 524 |
// https://tc39.es/ecma262/#sec-iterator.prototype.map |
| 525 |
$({ target: 'Iterator', proto: true, real: true, forced: IS_PURE || mapWithoutClosingOnEarlyError }, { |
| 526 |
map: function map(mapper) { |
| 527 |
anObject(this); |
| 528 |
try { |
| 529 |
aCallable(mapper); |
| 530 |
} catch (error) { |
| 531 |
iteratorClose(this, 'throw', error); |
| 532 |
} |
| 533 |
|
| 534 |
if (mapWithoutClosingOnEarlyError) return call(mapWithoutClosingOnEarlyError, this, mapper); |
| 535 |
|
| 536 |
return new IteratorProxy(getIteratorDirect(this), { |
| 537 |
mapper: mapper |
| 538 |
}); |
| 539 |
} |
| 540 |
}); |
| 541 |
|
| 542 |
|
| 543 |
/***/ }), |
| 544 |
|
| 545 |
/***/ 1767: |
| 546 |
/***/ ((module) => { |
| 547 |
|
| 548 |
|
| 549 |
// `GetIteratorDirect(obj)` abstract operation |
| 550 |
// https://tc39.es/proposal-iterator-helpers/#sec-getiteratordirect |
| 551 |
module.exports = function (obj) { |
| 552 |
return { |
| 553 |
iterator: obj, |
| 554 |
next: obj.next, |
| 555 |
done: false |
| 556 |
}; |
| 557 |
}; |
| 558 |
|
| 559 |
|
| 560 |
/***/ }), |
| 561 |
|
| 562 |
/***/ 1828: |
| 563 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 564 |
|
| 565 |
|
| 566 |
var uncurryThis = __webpack_require__(9504); |
| 567 |
var hasOwn = __webpack_require__(9297); |
| 568 |
var toIndexedObject = __webpack_require__(5397); |
| 569 |
var indexOf = (__webpack_require__(9617).indexOf); |
| 570 |
var hiddenKeys = __webpack_require__(421); |
| 571 |
|
| 572 |
var push = uncurryThis([].push); |
| 573 |
|
| 574 |
module.exports = function (object, names) { |
| 575 |
var O = toIndexedObject(object); |
| 576 |
var i = 0; |
| 577 |
var result = []; |
| 578 |
var key; |
| 579 |
for (key in O) !hasOwn(hiddenKeys, key) && hasOwn(O, key) && push(result, key); |
| 580 |
// Don't enum bug & hidden keys |
| 581 |
while (names.length > i) if (hasOwn(O, key = names[i++])) { |
| 582 |
~indexOf(result, key) || push(result, key); |
| 583 |
} |
| 584 |
return result; |
| 585 |
}; |
| 586 |
|
| 587 |
|
| 588 |
/***/ }), |
| 589 |
|
| 590 |
/***/ 2106: |
| 591 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 592 |
|
| 593 |
|
| 594 |
var makeBuiltIn = __webpack_require__(283); |
| 595 |
var defineProperty = __webpack_require__(4913); |
| 596 |
|
| 597 |
module.exports = function (target, name, descriptor) { |
| 598 |
if (descriptor.get) makeBuiltIn(descriptor.get, name, { getter: true }); |
| 599 |
if (descriptor.set) makeBuiltIn(descriptor.set, name, { setter: true }); |
| 600 |
return defineProperty.f(target, name, descriptor); |
| 601 |
}; |
| 602 |
|
| 603 |
|
| 604 |
/***/ }), |
| 605 |
|
| 606 |
/***/ 2140: |
| 607 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 608 |
|
| 609 |
|
| 610 |
var wellKnownSymbol = __webpack_require__(8227); |
| 611 |
|
| 612 |
var TO_STRING_TAG = wellKnownSymbol('toStringTag'); |
| 613 |
var test = {}; |
| 614 |
|
| 615 |
test[TO_STRING_TAG] = 'z'; |
| 616 |
|
| 617 |
module.exports = String(test) === '[object z]'; |
| 618 |
|
| 619 |
|
| 620 |
/***/ }), |
| 621 |
|
| 622 |
/***/ 2195: |
| 623 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 624 |
|
| 625 |
|
| 626 |
var uncurryThis = __webpack_require__(9504); |
| 627 |
|
| 628 |
var toString = uncurryThis({}.toString); |
| 629 |
var stringSlice = uncurryThis(''.slice); |
| 630 |
|
| 631 |
module.exports = function (it) { |
| 632 |
return stringSlice(toString(it), 8, -1); |
| 633 |
}; |
| 634 |
|
| 635 |
|
| 636 |
/***/ }), |
| 637 |
|
| 638 |
/***/ 2211: |
| 639 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 640 |
|
| 641 |
|
| 642 |
var fails = __webpack_require__(9039); |
| 643 |
|
| 644 |
module.exports = !fails(function () { |
| 645 |
function F() { /* empty */ } |
| 646 |
F.prototype.constructor = null; |
| 647 |
// eslint-disable-next-line es/no-object-getprototypeof -- required for testing |
| 648 |
return Object.getPrototypeOf(new F()) !== F.prototype; |
| 649 |
}); |
| 650 |
|
| 651 |
|
| 652 |
/***/ }), |
| 653 |
|
| 654 |
/***/ 2222: |
| 655 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 656 |
|
| 657 |
|
| 658 |
var $ = __webpack_require__(6518); |
| 659 |
var getBuiltIn = __webpack_require__(7751); |
| 660 |
var fails = __webpack_require__(9039); |
| 661 |
var validateArgumentsLength = __webpack_require__(2812); |
| 662 |
var toString = __webpack_require__(655); |
| 663 |
var USE_NATIVE_URL = __webpack_require__(7416); |
| 664 |
|
| 665 |
var URL = getBuiltIn('URL'); |
| 666 |
|
| 667 |
// https://github.com/nodejs/node/issues/47505 |
| 668 |
// https://github.com/denoland/deno/issues/18893 |
| 669 |
var THROWS_WITHOUT_ARGUMENTS = USE_NATIVE_URL && fails(function () { |
| 670 |
URL.canParse(); |
| 671 |
}); |
| 672 |
|
| 673 |
// Bun ~ 1.0.30 bug |
| 674 |
// https://github.com/oven-sh/bun/issues/9250 |
| 675 |
var WRONG_ARITY = fails(function () { |
| 676 |
return URL.canParse.length !== 1; |
| 677 |
}); |
| 678 |
|
| 679 |
// `URL.canParse` method |
| 680 |
// https://url.spec.whatwg.org/#dom-url-canparse |
| 681 |
$({ target: 'URL', stat: true, forced: !THROWS_WITHOUT_ARGUMENTS || WRONG_ARITY }, { |
| 682 |
canParse: function canParse(url) { |
| 683 |
var length = validateArgumentsLength(arguments.length, 1); |
| 684 |
var urlString = toString(url); |
| 685 |
var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]); |
| 686 |
try { |
| 687 |
return !!new URL(urlString, base); |
| 688 |
} catch (error) { |
| 689 |
return false; |
| 690 |
} |
| 691 |
} |
| 692 |
}); |
| 693 |
|
| 694 |
|
| 695 |
/***/ }), |
| 696 |
|
| 697 |
/***/ 2360: |
| 698 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 699 |
|
| 700 |
|
| 701 |
/* global ActiveXObject -- old IE, WSH */ |
| 702 |
var anObject = __webpack_require__(8551); |
| 703 |
var definePropertiesModule = __webpack_require__(6801); |
| 704 |
var enumBugKeys = __webpack_require__(8727); |
| 705 |
var hiddenKeys = __webpack_require__(421); |
| 706 |
var html = __webpack_require__(397); |
| 707 |
var documentCreateElement = __webpack_require__(4055); |
| 708 |
var sharedKey = __webpack_require__(6119); |
| 709 |
|
| 710 |
var GT = '>'; |
| 711 |
var LT = '<'; |
| 712 |
var PROTOTYPE = 'prototype'; |
| 713 |
var SCRIPT = 'script'; |
| 714 |
var IE_PROTO = sharedKey('IE_PROTO'); |
| 715 |
|
| 716 |
var EmptyConstructor = function () { /* empty */ }; |
| 717 |
|
| 718 |
var scriptTag = function (content) { |
| 719 |
return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT; |
| 720 |
}; |
| 721 |
|
| 722 |
// Create object with fake `null` prototype: use ActiveX Object with cleared prototype |
| 723 |
var NullProtoObjectViaActiveX = function (activeXDocument) { |
| 724 |
activeXDocument.write(scriptTag('')); |
| 725 |
activeXDocument.close(); |
| 726 |
var temp = activeXDocument.parentWindow.Object; |
| 727 |
// eslint-disable-next-line no-useless-assignment -- avoid memory leak |
| 728 |
activeXDocument = null; |
| 729 |
return temp; |
| 730 |
}; |
| 731 |
|
| 732 |
// Create object with fake `null` prototype: use iframe Object with cleared prototype |
| 733 |
var NullProtoObjectViaIFrame = function () { |
| 734 |
// Thrash, waste and sodomy: IE GC bug |
| 735 |
var iframe = documentCreateElement('iframe'); |
| 736 |
var JS = 'java' + SCRIPT + ':'; |
| 737 |
var iframeDocument; |
| 738 |
iframe.style.display = 'none'; |
| 739 |
html.appendChild(iframe); |
| 740 |
// https://github.com/zloirock/core-js/issues/475 |
| 741 |
iframe.src = String(JS); |
| 742 |
iframeDocument = iframe.contentWindow.document; |
| 743 |
iframeDocument.open(); |
| 744 |
iframeDocument.write(scriptTag('document.F=Object')); |
| 745 |
iframeDocument.close(); |
| 746 |
return iframeDocument.F; |
| 747 |
}; |
| 748 |
|
| 749 |
// Check for document.domain and active x support |
| 750 |
// No need to use active x approach when document.domain is not set |
| 751 |
// see https://github.com/es-shims/es5-shim/issues/150 |
| 752 |
// variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346 |
| 753 |
// avoid IE GC bug |
| 754 |
var activeXDocument; |
| 755 |
var NullProtoObject = function () { |
| 756 |
try { |
| 757 |
activeXDocument = new ActiveXObject('htmlfile'); |
| 758 |
} catch (error) { /* ignore */ } |
| 759 |
NullProtoObject = typeof document != 'undefined' |
| 760 |
? document.domain && activeXDocument |
| 761 |
? NullProtoObjectViaActiveX(activeXDocument) // old IE |
| 762 |
: NullProtoObjectViaIFrame() |
| 763 |
: NullProtoObjectViaActiveX(activeXDocument); // WSH |
| 764 |
var length = enumBugKeys.length; |
| 765 |
while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]]; |
| 766 |
return NullProtoObject(); |
| 767 |
}; |
| 768 |
|
| 769 |
hiddenKeys[IE_PROTO] = true; |
| 770 |
|
| 771 |
// `Object.create` method |
| 772 |
// https://tc39.es/ecma262/#sec-object.create |
| 773 |
// eslint-disable-next-line es/no-object-create -- safe |
| 774 |
module.exports = Object.create || function create(O, Properties) { |
| 775 |
var result; |
| 776 |
if (O !== null) { |
| 777 |
EmptyConstructor[PROTOTYPE] = anObject(O); |
| 778 |
result = new EmptyConstructor(); |
| 779 |
EmptyConstructor[PROTOTYPE] = null; |
| 780 |
// add "__proto__" for Object.getPrototypeOf polyfill |
| 781 |
result[IE_PROTO] = O; |
| 782 |
} else result = NullProtoObject(); |
| 783 |
return Properties === undefined ? result : definePropertiesModule.f(result, Properties); |
| 784 |
}; |
| 785 |
|
| 786 |
|
| 787 |
/***/ }), |
| 788 |
|
| 789 |
/***/ 2475: |
| 790 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 791 |
|
| 792 |
|
| 793 |
var $ = __webpack_require__(6518); |
| 794 |
var isSupersetOf = __webpack_require__(8527); |
| 795 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 796 |
|
| 797 |
var INCORRECT = !setMethodAcceptSetLike('isSupersetOf', function (result) { |
| 798 |
return !result; |
| 799 |
}); |
| 800 |
|
| 801 |
// `Set.prototype.isSupersetOf` method |
| 802 |
// https://tc39.es/ecma262/#sec-set.prototype.issupersetof |
| 803 |
$({ target: 'Set', proto: true, real: true, forced: INCORRECT }, { |
| 804 |
isSupersetOf: isSupersetOf |
| 805 |
}); |
| 806 |
|
| 807 |
|
| 808 |
/***/ }), |
| 809 |
|
| 810 |
/***/ 2489: |
| 811 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 812 |
|
| 813 |
|
| 814 |
var $ = __webpack_require__(6518); |
| 815 |
var call = __webpack_require__(9565); |
| 816 |
var aCallable = __webpack_require__(9306); |
| 817 |
var anObject = __webpack_require__(8551); |
| 818 |
var getIteratorDirect = __webpack_require__(1767); |
| 819 |
var createIteratorProxy = __webpack_require__(9462); |
| 820 |
var callWithSafeIterationClosing = __webpack_require__(6319); |
| 821 |
var IS_PURE = __webpack_require__(6395); |
| 822 |
var iteratorClose = __webpack_require__(9539); |
| 823 |
var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549); |
| 824 |
|
| 825 |
var filterWithoutClosingOnEarlyError = !IS_PURE && iteratorHelperWithoutClosingOnEarlyError('filter', TypeError); |
| 826 |
|
| 827 |
var IteratorProxy = createIteratorProxy(function () { |
| 828 |
var iterator = this.iterator; |
| 829 |
var predicate = this.predicate; |
| 830 |
var next = this.next; |
| 831 |
var result, done, value; |
| 832 |
while (true) { |
| 833 |
result = anObject(call(next, iterator)); |
| 834 |
done = this.done = !!result.done; |
| 835 |
if (done) return; |
| 836 |
value = result.value; |
| 837 |
if (callWithSafeIterationClosing(iterator, predicate, [value, this.counter++], true)) return value; |
| 838 |
} |
| 839 |
}); |
| 840 |
|
| 841 |
// `Iterator.prototype.filter` method |
| 842 |
// https://tc39.es/ecma262/#sec-iterator.prototype.filter |
| 843 |
$({ target: 'Iterator', proto: true, real: true, forced: IS_PURE || filterWithoutClosingOnEarlyError }, { |
| 844 |
filter: function filter(predicate) { |
| 845 |
anObject(this); |
| 846 |
try { |
| 847 |
aCallable(predicate); |
| 848 |
} catch (error) { |
| 849 |
iteratorClose(this, 'throw', error); |
| 850 |
} |
| 851 |
|
| 852 |
if (filterWithoutClosingOnEarlyError) return call(filterWithoutClosingOnEarlyError, this, predicate); |
| 853 |
|
| 854 |
return new IteratorProxy(getIteratorDirect(this), { |
| 855 |
predicate: predicate |
| 856 |
}); |
| 857 |
} |
| 858 |
}); |
| 859 |
|
| 860 |
|
| 861 |
/***/ }), |
| 862 |
|
| 863 |
/***/ 2529: |
| 864 |
/***/ ((module) => { |
| 865 |
|
| 866 |
|
| 867 |
// `CreateIterResultObject` abstract operation |
| 868 |
// https://tc39.es/ecma262/#sec-createiterresultobject |
| 869 |
module.exports = function (value, done) { |
| 870 |
return { value: value, done: done }; |
| 871 |
}; |
| 872 |
|
| 873 |
|
| 874 |
/***/ }), |
| 875 |
|
| 876 |
/***/ 2652: |
| 877 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 878 |
|
| 879 |
|
| 880 |
var bind = __webpack_require__(6080); |
| 881 |
var call = __webpack_require__(9565); |
| 882 |
var anObject = __webpack_require__(8551); |
| 883 |
var tryToString = __webpack_require__(6823); |
| 884 |
var isArrayIteratorMethod = __webpack_require__(4209); |
| 885 |
var lengthOfArrayLike = __webpack_require__(6198); |
| 886 |
var isPrototypeOf = __webpack_require__(1625); |
| 887 |
var getIterator = __webpack_require__(81); |
| 888 |
var getIteratorMethod = __webpack_require__(851); |
| 889 |
var iteratorClose = __webpack_require__(9539); |
| 890 |
|
| 891 |
var $TypeError = TypeError; |
| 892 |
|
| 893 |
var Result = function (stopped, result) { |
| 894 |
this.stopped = stopped; |
| 895 |
this.result = result; |
| 896 |
}; |
| 897 |
|
| 898 |
var ResultPrototype = Result.prototype; |
| 899 |
|
| 900 |
module.exports = function (iterable, unboundFunction, options) { |
| 901 |
var that = options && options.that; |
| 902 |
var AS_ENTRIES = !!(options && options.AS_ENTRIES); |
| 903 |
var IS_RECORD = !!(options && options.IS_RECORD); |
| 904 |
var IS_ITERATOR = !!(options && options.IS_ITERATOR); |
| 905 |
var INTERRUPTED = !!(options && options.INTERRUPTED); |
| 906 |
var fn = bind(unboundFunction, that); |
| 907 |
var iterator, iterFn, index, length, result, next, step; |
| 908 |
|
| 909 |
var stop = function (condition) { |
| 910 |
if (iterator) iteratorClose(iterator, 'normal', condition); |
| 911 |
return new Result(true, condition); |
| 912 |
}; |
| 913 |
|
| 914 |
var callFn = function (value) { |
| 915 |
if (AS_ENTRIES) { |
| 916 |
anObject(value); |
| 917 |
return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]); |
| 918 |
} return INTERRUPTED ? fn(value, stop) : fn(value); |
| 919 |
}; |
| 920 |
|
| 921 |
if (IS_RECORD) { |
| 922 |
iterator = iterable.iterator; |
| 923 |
} else if (IS_ITERATOR) { |
| 924 |
iterator = iterable; |
| 925 |
} else { |
| 926 |
iterFn = getIteratorMethod(iterable); |
| 927 |
if (!iterFn) throw new $TypeError(tryToString(iterable) + ' is not iterable'); |
| 928 |
// optimisation for array iterators |
| 929 |
if (isArrayIteratorMethod(iterFn)) { |
| 930 |
for (index = 0, length = lengthOfArrayLike(iterable); length > index; index++) { |
| 931 |
result = callFn(iterable[index]); |
| 932 |
if (result && isPrototypeOf(ResultPrototype, result)) return result; |
| 933 |
} return new Result(false); |
| 934 |
} |
| 935 |
iterator = getIterator(iterable, iterFn); |
| 936 |
} |
| 937 |
|
| 938 |
next = IS_RECORD ? iterable.next : iterator.next; |
| 939 |
while (!(step = call(next, iterator)).done) { |
| 940 |
try { |
| 941 |
result = callFn(step.value); |
| 942 |
} catch (error) { |
| 943 |
iteratorClose(iterator, 'throw', error); |
| 944 |
} |
| 945 |
if (typeof result == 'object' && result && isPrototypeOf(ResultPrototype, result)) return result; |
| 946 |
} return new Result(false); |
| 947 |
}; |
| 948 |
|
| 949 |
|
| 950 |
/***/ }), |
| 951 |
|
| 952 |
/***/ 2777: |
| 953 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 954 |
|
| 955 |
|
| 956 |
var call = __webpack_require__(9565); |
| 957 |
var isObject = __webpack_require__(34); |
| 958 |
var isSymbol = __webpack_require__(757); |
| 959 |
var getMethod = __webpack_require__(5966); |
| 960 |
var ordinaryToPrimitive = __webpack_require__(4270); |
| 961 |
var wellKnownSymbol = __webpack_require__(8227); |
| 962 |
|
| 963 |
var $TypeError = TypeError; |
| 964 |
var TO_PRIMITIVE = wellKnownSymbol('toPrimitive'); |
| 965 |
|
| 966 |
// `ToPrimitive` abstract operation |
| 967 |
// https://tc39.es/ecma262/#sec-toprimitive |
| 968 |
module.exports = function (input, pref) { |
| 969 |
if (!isObject(input) || isSymbol(input)) return input; |
| 970 |
var exoticToPrim = getMethod(input, TO_PRIMITIVE); |
| 971 |
var result; |
| 972 |
if (exoticToPrim) { |
| 973 |
if (pref === undefined) pref = 'default'; |
| 974 |
result = call(exoticToPrim, input, pref); |
| 975 |
if (!isObject(result) || isSymbol(result)) return result; |
| 976 |
throw new $TypeError("Can't convert object to primitive value"); |
| 977 |
} |
| 978 |
if (pref === undefined) pref = 'number'; |
| 979 |
return ordinaryToPrimitive(input, pref); |
| 980 |
}; |
| 981 |
|
| 982 |
|
| 983 |
/***/ }), |
| 984 |
|
| 985 |
/***/ 2787: |
| 986 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 987 |
|
| 988 |
|
| 989 |
var hasOwn = __webpack_require__(9297); |
| 990 |
var isCallable = __webpack_require__(4901); |
| 991 |
var toObject = __webpack_require__(8981); |
| 992 |
var sharedKey = __webpack_require__(6119); |
| 993 |
var CORRECT_PROTOTYPE_GETTER = __webpack_require__(2211); |
| 994 |
|
| 995 |
var IE_PROTO = sharedKey('IE_PROTO'); |
| 996 |
var $Object = Object; |
| 997 |
var ObjectPrototype = $Object.prototype; |
| 998 |
|
| 999 |
// `Object.getPrototypeOf` method |
| 1000 |
// https://tc39.es/ecma262/#sec-object.getprototypeof |
| 1001 |
// eslint-disable-next-line es/no-object-getprototypeof -- safe |
| 1002 |
module.exports = CORRECT_PROTOTYPE_GETTER ? $Object.getPrototypeOf : function (O) { |
| 1003 |
var object = toObject(O); |
| 1004 |
if (hasOwn(object, IE_PROTO)) return object[IE_PROTO]; |
| 1005 |
var constructor = object.constructor; |
| 1006 |
if (isCallable(constructor) && object instanceof constructor) { |
| 1007 |
return constructor.prototype; |
| 1008 |
} return object instanceof $Object ? ObjectPrototype : null; |
| 1009 |
}; |
| 1010 |
|
| 1011 |
|
| 1012 |
/***/ }), |
| 1013 |
|
| 1014 |
/***/ 2796: |
| 1015 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1016 |
|
| 1017 |
|
| 1018 |
var fails = __webpack_require__(9039); |
| 1019 |
var isCallable = __webpack_require__(4901); |
| 1020 |
|
| 1021 |
var replacement = /#|\.prototype\./; |
| 1022 |
|
| 1023 |
var isForced = function (feature, detection) { |
| 1024 |
var value = data[normalize(feature)]; |
| 1025 |
return value === POLYFILL ? true |
| 1026 |
: value === NATIVE ? false |
| 1027 |
: isCallable(detection) ? fails(detection) |
| 1028 |
: !!detection; |
| 1029 |
}; |
| 1030 |
|
| 1031 |
var normalize = isForced.normalize = function (string) { |
| 1032 |
return String(string).replace(replacement, '.').toLowerCase(); |
| 1033 |
}; |
| 1034 |
|
| 1035 |
var data = isForced.data = {}; |
| 1036 |
var NATIVE = isForced.NATIVE = 'N'; |
| 1037 |
var POLYFILL = isForced.POLYFILL = 'P'; |
| 1038 |
|
| 1039 |
module.exports = isForced; |
| 1040 |
|
| 1041 |
|
| 1042 |
/***/ }), |
| 1043 |
|
| 1044 |
/***/ 2812: |
| 1045 |
/***/ ((module) => { |
| 1046 |
|
| 1047 |
|
| 1048 |
var $TypeError = TypeError; |
| 1049 |
|
| 1050 |
module.exports = function (passed, required) { |
| 1051 |
if (passed < required) throw new $TypeError('Not enough arguments'); |
| 1052 |
return passed; |
| 1053 |
}; |
| 1054 |
|
| 1055 |
|
| 1056 |
/***/ }), |
| 1057 |
|
| 1058 |
/***/ 2839: |
| 1059 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1060 |
|
| 1061 |
|
| 1062 |
var globalThis = __webpack_require__(4576); |
| 1063 |
|
| 1064 |
var navigator = globalThis.navigator; |
| 1065 |
var userAgent = navigator && navigator.userAgent; |
| 1066 |
|
| 1067 |
module.exports = userAgent ? String(userAgent) : ''; |
| 1068 |
|
| 1069 |
|
| 1070 |
/***/ }), |
| 1071 |
|
| 1072 |
/***/ 3238: |
| 1073 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1074 |
|
| 1075 |
|
| 1076 |
var globalThis = __webpack_require__(4576); |
| 1077 |
var NATIVE_ARRAY_BUFFER = __webpack_require__(7811); |
| 1078 |
var arrayBufferByteLength = __webpack_require__(7394); |
| 1079 |
|
| 1080 |
var DataView = globalThis.DataView; |
| 1081 |
|
| 1082 |
module.exports = function (O) { |
| 1083 |
if (!NATIVE_ARRAY_BUFFER || arrayBufferByteLength(O) !== 0) return false; |
| 1084 |
try { |
| 1085 |
// eslint-disable-next-line no-new -- thrower |
| 1086 |
new DataView(O); |
| 1087 |
return false; |
| 1088 |
} catch (error) { |
| 1089 |
return true; |
| 1090 |
} |
| 1091 |
}; |
| 1092 |
|
| 1093 |
|
| 1094 |
/***/ }), |
| 1095 |
|
| 1096 |
/***/ 3392: |
| 1097 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1098 |
|
| 1099 |
|
| 1100 |
var uncurryThis = __webpack_require__(9504); |
| 1101 |
|
| 1102 |
var id = 0; |
| 1103 |
var postfix = Math.random(); |
| 1104 |
var toString = uncurryThis(1.0.toString); |
| 1105 |
|
| 1106 |
module.exports = function (key) { |
| 1107 |
return 'Symbol(' + (key === undefined ? '' : key) + ')_' + toString(++id + postfix, 36); |
| 1108 |
}; |
| 1109 |
|
| 1110 |
|
| 1111 |
/***/ }), |
| 1112 |
|
| 1113 |
/***/ 3440: |
| 1114 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1115 |
|
| 1116 |
|
| 1117 |
var aSet = __webpack_require__(7080); |
| 1118 |
var SetHelpers = __webpack_require__(4402); |
| 1119 |
var clone = __webpack_require__(9286); |
| 1120 |
var size = __webpack_require__(5170); |
| 1121 |
var getSetRecord = __webpack_require__(3789); |
| 1122 |
var iterateSet = __webpack_require__(8469); |
| 1123 |
var iterateSimple = __webpack_require__(507); |
| 1124 |
|
| 1125 |
var has = SetHelpers.has; |
| 1126 |
var remove = SetHelpers.remove; |
| 1127 |
|
| 1128 |
// `Set.prototype.difference` method |
| 1129 |
// https://github.com/tc39/proposal-set-methods |
| 1130 |
module.exports = function difference(other) { |
| 1131 |
var O = aSet(this); |
| 1132 |
var otherRec = getSetRecord(other); |
| 1133 |
var result = clone(O); |
| 1134 |
if (size(O) <= otherRec.size) iterateSet(O, function (e) { |
| 1135 |
if (otherRec.includes(e)) remove(result, e); |
| 1136 |
}); |
| 1137 |
else iterateSimple(otherRec.getIterator(), function (e) { |
| 1138 |
if (has(O, e)) remove(result, e); |
| 1139 |
}); |
| 1140 |
return result; |
| 1141 |
}; |
| 1142 |
|
| 1143 |
|
| 1144 |
/***/ }), |
| 1145 |
|
| 1146 |
/***/ 3579: |
| 1147 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1148 |
|
| 1149 |
|
| 1150 |
var $ = __webpack_require__(6518); |
| 1151 |
var call = __webpack_require__(9565); |
| 1152 |
var iterate = __webpack_require__(2652); |
| 1153 |
var aCallable = __webpack_require__(9306); |
| 1154 |
var anObject = __webpack_require__(8551); |
| 1155 |
var getIteratorDirect = __webpack_require__(1767); |
| 1156 |
var iteratorClose = __webpack_require__(9539); |
| 1157 |
var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549); |
| 1158 |
|
| 1159 |
var someWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('some', TypeError); |
| 1160 |
|
| 1161 |
// `Iterator.prototype.some` method |
| 1162 |
// https://tc39.es/ecma262/#sec-iterator.prototype.some |
| 1163 |
$({ target: 'Iterator', proto: true, real: true, forced: someWithoutClosingOnEarlyError }, { |
| 1164 |
some: function some(predicate) { |
| 1165 |
anObject(this); |
| 1166 |
try { |
| 1167 |
aCallable(predicate); |
| 1168 |
} catch (error) { |
| 1169 |
iteratorClose(this, 'throw', error); |
| 1170 |
} |
| 1171 |
|
| 1172 |
if (someWithoutClosingOnEarlyError) return call(someWithoutClosingOnEarlyError, this, predicate); |
| 1173 |
|
| 1174 |
var record = getIteratorDirect(this); |
| 1175 |
var counter = 0; |
| 1176 |
return iterate(record, function (value, stop) { |
| 1177 |
if (predicate(value, counter++)) return stop(); |
| 1178 |
}, { IS_RECORD: true, INTERRUPTED: true }).stopped; |
| 1179 |
} |
| 1180 |
}); |
| 1181 |
|
| 1182 |
|
| 1183 |
/***/ }), |
| 1184 |
|
| 1185 |
/***/ 3650: |
| 1186 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1187 |
|
| 1188 |
|
| 1189 |
var aSet = __webpack_require__(7080); |
| 1190 |
var SetHelpers = __webpack_require__(4402); |
| 1191 |
var clone = __webpack_require__(9286); |
| 1192 |
var getSetRecord = __webpack_require__(3789); |
| 1193 |
var iterateSimple = __webpack_require__(507); |
| 1194 |
|
| 1195 |
var add = SetHelpers.add; |
| 1196 |
var has = SetHelpers.has; |
| 1197 |
var remove = SetHelpers.remove; |
| 1198 |
|
| 1199 |
// `Set.prototype.symmetricDifference` method |
| 1200 |
// https://github.com/tc39/proposal-set-methods |
| 1201 |
module.exports = function symmetricDifference(other) { |
| 1202 |
var O = aSet(this); |
| 1203 |
var keysIter = getSetRecord(other).getIterator(); |
| 1204 |
var result = clone(O); |
| 1205 |
iterateSimple(keysIter, function (e) { |
| 1206 |
if (has(O, e)) remove(result, e); |
| 1207 |
else add(result, e); |
| 1208 |
}); |
| 1209 |
return result; |
| 1210 |
}; |
| 1211 |
|
| 1212 |
|
| 1213 |
/***/ }), |
| 1214 |
|
| 1215 |
/***/ 3706: |
| 1216 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1217 |
|
| 1218 |
|
| 1219 |
var uncurryThis = __webpack_require__(9504); |
| 1220 |
var isCallable = __webpack_require__(4901); |
| 1221 |
var store = __webpack_require__(7629); |
| 1222 |
|
| 1223 |
var functionToString = uncurryThis(Function.toString); |
| 1224 |
|
| 1225 |
// this helper broken in `[email protected]`, so we can't use `shared` helper |
| 1226 |
if (!isCallable(store.inspectSource)) { |
| 1227 |
store.inspectSource = function (it) { |
| 1228 |
return functionToString(it); |
| 1229 |
}; |
| 1230 |
} |
| 1231 |
|
| 1232 |
module.exports = store.inspectSource; |
| 1233 |
|
| 1234 |
|
| 1235 |
/***/ }), |
| 1236 |
|
| 1237 |
/***/ 3717: |
| 1238 |
/***/ ((__unused_webpack_module, exports) => { |
| 1239 |
|
| 1240 |
|
| 1241 |
// eslint-disable-next-line es/no-object-getownpropertysymbols -- safe |
| 1242 |
exports.f = Object.getOwnPropertySymbols; |
| 1243 |
|
| 1244 |
|
| 1245 |
/***/ }), |
| 1246 |
|
| 1247 |
/***/ 3724: |
| 1248 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1249 |
|
| 1250 |
|
| 1251 |
var fails = __webpack_require__(9039); |
| 1252 |
|
| 1253 |
// Detect IE8's incomplete defineProperty implementation |
| 1254 |
module.exports = !fails(function () { |
| 1255 |
// eslint-disable-next-line es/no-object-defineproperty -- required for testing |
| 1256 |
return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] !== 7; |
| 1257 |
}); |
| 1258 |
|
| 1259 |
|
| 1260 |
/***/ }), |
| 1261 |
|
| 1262 |
/***/ 3789: |
| 1263 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1264 |
|
| 1265 |
|
| 1266 |
var aCallable = __webpack_require__(9306); |
| 1267 |
var anObject = __webpack_require__(8551); |
| 1268 |
var call = __webpack_require__(9565); |
| 1269 |
var toIntegerOrInfinity = __webpack_require__(1291); |
| 1270 |
var getIteratorDirect = __webpack_require__(1767); |
| 1271 |
|
| 1272 |
var INVALID_SIZE = 'Invalid size'; |
| 1273 |
var $RangeError = RangeError; |
| 1274 |
var $TypeError = TypeError; |
| 1275 |
var max = Math.max; |
| 1276 |
|
| 1277 |
var SetRecord = function (set, intSize) { |
| 1278 |
this.set = set; |
| 1279 |
this.size = max(intSize, 0); |
| 1280 |
this.has = aCallable(set.has); |
| 1281 |
this.keys = aCallable(set.keys); |
| 1282 |
}; |
| 1283 |
|
| 1284 |
SetRecord.prototype = { |
| 1285 |
getIterator: function () { |
| 1286 |
return getIteratorDirect(anObject(call(this.keys, this.set))); |
| 1287 |
}, |
| 1288 |
includes: function (it) { |
| 1289 |
return call(this.has, this.set, it); |
| 1290 |
} |
| 1291 |
}; |
| 1292 |
|
| 1293 |
// `GetSetRecord` abstract operation |
| 1294 |
// https://tc39.es/proposal-set-methods/#sec-getsetrecord |
| 1295 |
module.exports = function (obj) { |
| 1296 |
anObject(obj); |
| 1297 |
var numSize = +obj.size; |
| 1298 |
// NOTE: If size is undefined, then numSize will be NaN |
| 1299 |
// eslint-disable-next-line no-self-compare -- NaN check |
| 1300 |
if (numSize !== numSize) throw new $TypeError(INVALID_SIZE); |
| 1301 |
var intSize = toIntegerOrInfinity(numSize); |
| 1302 |
if (intSize < 0) throw new $RangeError(INVALID_SIZE); |
| 1303 |
return new SetRecord(obj, intSize); |
| 1304 |
}; |
| 1305 |
|
| 1306 |
|
| 1307 |
/***/ }), |
| 1308 |
|
| 1309 |
/***/ 3838: |
| 1310 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1311 |
|
| 1312 |
|
| 1313 |
var aSet = __webpack_require__(7080); |
| 1314 |
var size = __webpack_require__(5170); |
| 1315 |
var iterate = __webpack_require__(8469); |
| 1316 |
var getSetRecord = __webpack_require__(3789); |
| 1317 |
|
| 1318 |
// `Set.prototype.isSubsetOf` method |
| 1319 |
// https://tc39.github.io/proposal-set-methods/#Set.prototype.isSubsetOf |
| 1320 |
module.exports = function isSubsetOf(other) { |
| 1321 |
var O = aSet(this); |
| 1322 |
var otherRec = getSetRecord(other); |
| 1323 |
if (size(O) > otherRec.size) return false; |
| 1324 |
return iterate(O, function (e) { |
| 1325 |
if (!otherRec.includes(e)) return false; |
| 1326 |
}, true) !== false; |
| 1327 |
}; |
| 1328 |
|
| 1329 |
|
| 1330 |
/***/ }), |
| 1331 |
|
| 1332 |
/***/ 3853: |
| 1333 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1334 |
|
| 1335 |
|
| 1336 |
var $ = __webpack_require__(6518); |
| 1337 |
var isDisjointFrom = __webpack_require__(4449); |
| 1338 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 1339 |
|
| 1340 |
var INCORRECT = !setMethodAcceptSetLike('isDisjointFrom', function (result) { |
| 1341 |
return !result; |
| 1342 |
}); |
| 1343 |
|
| 1344 |
// `Set.prototype.isDisjointFrom` method |
| 1345 |
// https://tc39.es/ecma262/#sec-set.prototype.isdisjointfrom |
| 1346 |
$({ target: 'Set', proto: true, real: true, forced: INCORRECT }, { |
| 1347 |
isDisjointFrom: isDisjointFrom |
| 1348 |
}); |
| 1349 |
|
| 1350 |
|
| 1351 |
/***/ }), |
| 1352 |
|
| 1353 |
/***/ 4055: |
| 1354 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1355 |
|
| 1356 |
|
| 1357 |
var globalThis = __webpack_require__(4576); |
| 1358 |
var isObject = __webpack_require__(34); |
| 1359 |
|
| 1360 |
var document = globalThis.document; |
| 1361 |
// typeof document.createElement is 'object' in old IE |
| 1362 |
var EXISTS = isObject(document) && isObject(document.createElement); |
| 1363 |
|
| 1364 |
module.exports = function (it) { |
| 1365 |
return EXISTS ? document.createElement(it) : {}; |
| 1366 |
}; |
| 1367 |
|
| 1368 |
|
| 1369 |
/***/ }), |
| 1370 |
|
| 1371 |
/***/ 4114: |
| 1372 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1373 |
|
| 1374 |
|
| 1375 |
var $ = __webpack_require__(6518); |
| 1376 |
var toObject = __webpack_require__(8981); |
| 1377 |
var lengthOfArrayLike = __webpack_require__(6198); |
| 1378 |
var setArrayLength = __webpack_require__(4527); |
| 1379 |
var doesNotExceedSafeInteger = __webpack_require__(6837); |
| 1380 |
var fails = __webpack_require__(9039); |
| 1381 |
|
| 1382 |
var INCORRECT_TO_LENGTH = fails(function () { |
| 1383 |
return [].push.call({ length: 0x100000000 }, 1) !== 4294967297; |
| 1384 |
}); |
| 1385 |
|
| 1386 |
// V8 <= 121 and Safari <= 15.4; FF < 23 throws InternalError |
| 1387 |
// https://bugs.chromium.org/p/v8/issues/detail?id=12681 |
| 1388 |
var properErrorOnNonWritableLength = function () { |
| 1389 |
try { |
| 1390 |
// eslint-disable-next-line es/no-object-defineproperty -- safe |
| 1391 |
Object.defineProperty([], 'length', { writable: false }).push(); |
| 1392 |
} catch (error) { |
| 1393 |
return error instanceof TypeError; |
| 1394 |
} |
| 1395 |
}; |
| 1396 |
|
| 1397 |
var FORCED = INCORRECT_TO_LENGTH || !properErrorOnNonWritableLength(); |
| 1398 |
|
| 1399 |
// `Array.prototype.push` method |
| 1400 |
// https://tc39.es/ecma262/#sec-array.prototype.push |
| 1401 |
$({ target: 'Array', proto: true, arity: 1, forced: FORCED }, { |
| 1402 |
// eslint-disable-next-line no-unused-vars -- required for `.length` |
| 1403 |
push: function push(item) { |
| 1404 |
var O = toObject(this); |
| 1405 |
var len = lengthOfArrayLike(O); |
| 1406 |
var argCount = arguments.length; |
| 1407 |
doesNotExceedSafeInteger(len + argCount); |
| 1408 |
for (var i = 0; i < argCount; i++) { |
| 1409 |
O[len] = arguments[i]; |
| 1410 |
len++; |
| 1411 |
} |
| 1412 |
setArrayLength(O, len); |
| 1413 |
return len; |
| 1414 |
} |
| 1415 |
}); |
| 1416 |
|
| 1417 |
|
| 1418 |
/***/ }), |
| 1419 |
|
| 1420 |
/***/ 4117: |
| 1421 |
/***/ ((module) => { |
| 1422 |
|
| 1423 |
|
| 1424 |
// we can't use just `it == null` since of `document.all` special case |
| 1425 |
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot-aec |
| 1426 |
module.exports = function (it) { |
| 1427 |
return it === null || it === undefined; |
| 1428 |
}; |
| 1429 |
|
| 1430 |
|
| 1431 |
/***/ }), |
| 1432 |
|
| 1433 |
/***/ 4204: |
| 1434 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1435 |
|
| 1436 |
|
| 1437 |
var aSet = __webpack_require__(7080); |
| 1438 |
var add = (__webpack_require__(4402).add); |
| 1439 |
var clone = __webpack_require__(9286); |
| 1440 |
var getSetRecord = __webpack_require__(3789); |
| 1441 |
var iterateSimple = __webpack_require__(507); |
| 1442 |
|
| 1443 |
// `Set.prototype.union` method |
| 1444 |
// https://github.com/tc39/proposal-set-methods |
| 1445 |
module.exports = function union(other) { |
| 1446 |
var O = aSet(this); |
| 1447 |
var keysIter = getSetRecord(other).getIterator(); |
| 1448 |
var result = clone(O); |
| 1449 |
iterateSimple(keysIter, function (it) { |
| 1450 |
add(result, it); |
| 1451 |
}); |
| 1452 |
return result; |
| 1453 |
}; |
| 1454 |
|
| 1455 |
|
| 1456 |
/***/ }), |
| 1457 |
|
| 1458 |
/***/ 4209: |
| 1459 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1460 |
|
| 1461 |
|
| 1462 |
var wellKnownSymbol = __webpack_require__(8227); |
| 1463 |
var Iterators = __webpack_require__(6269); |
| 1464 |
|
| 1465 |
var ITERATOR = wellKnownSymbol('iterator'); |
| 1466 |
var ArrayPrototype = Array.prototype; |
| 1467 |
|
| 1468 |
// check on default Array iterator |
| 1469 |
module.exports = function (it) { |
| 1470 |
return it !== undefined && (Iterators.Array === it || ArrayPrototype[ITERATOR] === it); |
| 1471 |
}; |
| 1472 |
|
| 1473 |
|
| 1474 |
/***/ }), |
| 1475 |
|
| 1476 |
/***/ 4215: |
| 1477 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1478 |
|
| 1479 |
|
| 1480 |
/* global Bun, Deno -- detection */ |
| 1481 |
var globalThis = __webpack_require__(4576); |
| 1482 |
var userAgent = __webpack_require__(2839); |
| 1483 |
var classof = __webpack_require__(2195); |
| 1484 |
|
| 1485 |
var userAgentStartsWith = function (string) { |
| 1486 |
return userAgent.slice(0, string.length) === string; |
| 1487 |
}; |
| 1488 |
|
| 1489 |
module.exports = (function () { |
| 1490 |
if (userAgentStartsWith('Bun/')) return 'BUN'; |
| 1491 |
if (userAgentStartsWith('Cloudflare-Workers')) return 'CLOUDFLARE'; |
| 1492 |
if (userAgentStartsWith('Deno/')) return 'DENO'; |
| 1493 |
if (userAgentStartsWith('Node.js/')) return 'NODE'; |
| 1494 |
if (globalThis.Bun && typeof Bun.version == 'string') return 'BUN'; |
| 1495 |
if (globalThis.Deno && typeof Deno.version == 'object') return 'DENO'; |
| 1496 |
if (classof(globalThis.process) === 'process') return 'NODE'; |
| 1497 |
if (globalThis.window && globalThis.document) return 'BROWSER'; |
| 1498 |
return 'REST'; |
| 1499 |
})(); |
| 1500 |
|
| 1501 |
|
| 1502 |
/***/ }), |
| 1503 |
|
| 1504 |
/***/ 4270: |
| 1505 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1506 |
|
| 1507 |
|
| 1508 |
var call = __webpack_require__(9565); |
| 1509 |
var isCallable = __webpack_require__(4901); |
| 1510 |
var isObject = __webpack_require__(34); |
| 1511 |
|
| 1512 |
var $TypeError = TypeError; |
| 1513 |
|
| 1514 |
// `OrdinaryToPrimitive` abstract operation |
| 1515 |
// https://tc39.es/ecma262/#sec-ordinarytoprimitive |
| 1516 |
module.exports = function (input, pref) { |
| 1517 |
var fn, val; |
| 1518 |
if (pref === 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val; |
| 1519 |
if (isCallable(fn = input.valueOf) && !isObject(val = call(fn, input))) return val; |
| 1520 |
if (pref !== 'string' && isCallable(fn = input.toString) && !isObject(val = call(fn, input))) return val; |
| 1521 |
throw new $TypeError("Can't convert object to primitive value"); |
| 1522 |
}; |
| 1523 |
|
| 1524 |
|
| 1525 |
/***/ }), |
| 1526 |
|
| 1527 |
/***/ 4376: |
| 1528 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1529 |
|
| 1530 |
|
| 1531 |
var classof = __webpack_require__(2195); |
| 1532 |
|
| 1533 |
// `IsArray` abstract operation |
| 1534 |
// https://tc39.es/ecma262/#sec-isarray |
| 1535 |
// eslint-disable-next-line es/no-array-isarray -- safe |
| 1536 |
module.exports = Array.isArray || function isArray(argument) { |
| 1537 |
return classof(argument) === 'Array'; |
| 1538 |
}; |
| 1539 |
|
| 1540 |
|
| 1541 |
/***/ }), |
| 1542 |
|
| 1543 |
/***/ 4402: |
| 1544 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1545 |
|
| 1546 |
|
| 1547 |
var uncurryThis = __webpack_require__(9504); |
| 1548 |
|
| 1549 |
// eslint-disable-next-line es/no-set -- safe |
| 1550 |
var SetPrototype = Set.prototype; |
| 1551 |
|
| 1552 |
module.exports = { |
| 1553 |
// eslint-disable-next-line es/no-set -- safe |
| 1554 |
Set: Set, |
| 1555 |
add: uncurryThis(SetPrototype.add), |
| 1556 |
has: uncurryThis(SetPrototype.has), |
| 1557 |
remove: uncurryThis(SetPrototype['delete']), |
| 1558 |
proto: SetPrototype |
| 1559 |
}; |
| 1560 |
|
| 1561 |
|
| 1562 |
/***/ }), |
| 1563 |
|
| 1564 |
/***/ 4449: |
| 1565 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1566 |
|
| 1567 |
|
| 1568 |
var aSet = __webpack_require__(7080); |
| 1569 |
var has = (__webpack_require__(4402).has); |
| 1570 |
var size = __webpack_require__(5170); |
| 1571 |
var getSetRecord = __webpack_require__(3789); |
| 1572 |
var iterateSet = __webpack_require__(8469); |
| 1573 |
var iterateSimple = __webpack_require__(507); |
| 1574 |
var iteratorClose = __webpack_require__(9539); |
| 1575 |
|
| 1576 |
// `Set.prototype.isDisjointFrom` method |
| 1577 |
// https://tc39.github.io/proposal-set-methods/#Set.prototype.isDisjointFrom |
| 1578 |
module.exports = function isDisjointFrom(other) { |
| 1579 |
var O = aSet(this); |
| 1580 |
var otherRec = getSetRecord(other); |
| 1581 |
if (size(O) <= otherRec.size) return iterateSet(O, function (e) { |
| 1582 |
if (otherRec.includes(e)) return false; |
| 1583 |
}, true) !== false; |
| 1584 |
var iterator = otherRec.getIterator(); |
| 1585 |
return iterateSimple(iterator, function (e) { |
| 1586 |
if (has(O, e)) return iteratorClose(iterator, 'normal', false); |
| 1587 |
}) !== false; |
| 1588 |
}; |
| 1589 |
|
| 1590 |
|
| 1591 |
/***/ }), |
| 1592 |
|
| 1593 |
/***/ 4483: |
| 1594 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1595 |
|
| 1596 |
|
| 1597 |
var globalThis = __webpack_require__(4576); |
| 1598 |
var getBuiltInNodeModule = __webpack_require__(9429); |
| 1599 |
var PROPER_STRUCTURED_CLONE_TRANSFER = __webpack_require__(1548); |
| 1600 |
|
| 1601 |
var structuredClone = globalThis.structuredClone; |
| 1602 |
var $ArrayBuffer = globalThis.ArrayBuffer; |
| 1603 |
var $MessageChannel = globalThis.MessageChannel; |
| 1604 |
var detach = false; |
| 1605 |
var WorkerThreads, channel, buffer, $detach; |
| 1606 |
|
| 1607 |
if (PROPER_STRUCTURED_CLONE_TRANSFER) { |
| 1608 |
detach = function (transferable) { |
| 1609 |
structuredClone(transferable, { transfer: [transferable] }); |
| 1610 |
}; |
| 1611 |
} else if ($ArrayBuffer) try { |
| 1612 |
if (!$MessageChannel) { |
| 1613 |
WorkerThreads = getBuiltInNodeModule('worker_threads'); |
| 1614 |
if (WorkerThreads) $MessageChannel = WorkerThreads.MessageChannel; |
| 1615 |
} |
| 1616 |
|
| 1617 |
if ($MessageChannel) { |
| 1618 |
channel = new $MessageChannel(); |
| 1619 |
buffer = new $ArrayBuffer(2); |
| 1620 |
|
| 1621 |
$detach = function (transferable) { |
| 1622 |
channel.port1.postMessage(null, [transferable]); |
| 1623 |
}; |
| 1624 |
|
| 1625 |
if (buffer.byteLength === 2) { |
| 1626 |
$detach(buffer); |
| 1627 |
if (buffer.byteLength === 0) detach = $detach; |
| 1628 |
} |
| 1629 |
} |
| 1630 |
} catch (error) { /* empty */ } |
| 1631 |
|
| 1632 |
module.exports = detach; |
| 1633 |
|
| 1634 |
|
| 1635 |
/***/ }), |
| 1636 |
|
| 1637 |
/***/ 4495: |
| 1638 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1639 |
|
| 1640 |
|
| 1641 |
/* eslint-disable es/no-symbol -- required for testing */ |
| 1642 |
var V8_VERSION = __webpack_require__(9519); |
| 1643 |
var fails = __webpack_require__(9039); |
| 1644 |
var globalThis = __webpack_require__(4576); |
| 1645 |
|
| 1646 |
var $String = globalThis.String; |
| 1647 |
|
| 1648 |
// eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing |
| 1649 |
module.exports = !!Object.getOwnPropertySymbols && !fails(function () { |
| 1650 |
var symbol = Symbol('symbol detection'); |
| 1651 |
// Chrome 38 Symbol has incorrect toString conversion |
| 1652 |
// `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances |
| 1653 |
// nb: Do not call `String` directly to avoid this being optimized out to `symbol+''` which will, |
| 1654 |
// of course, fail. |
| 1655 |
return !$String(symbol) || !(Object(symbol) instanceof Symbol) || |
| 1656 |
// Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances |
| 1657 |
!Symbol.sham && V8_VERSION && V8_VERSION < 41; |
| 1658 |
}); |
| 1659 |
|
| 1660 |
|
| 1661 |
/***/ }), |
| 1662 |
|
| 1663 |
/***/ 4527: |
| 1664 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1665 |
|
| 1666 |
|
| 1667 |
var DESCRIPTORS = __webpack_require__(3724); |
| 1668 |
var isArray = __webpack_require__(4376); |
| 1669 |
|
| 1670 |
var $TypeError = TypeError; |
| 1671 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 1672 |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 1673 |
|
| 1674 |
// Safari < 13 does not throw an error in this case |
| 1675 |
var SILENT_ON_NON_WRITABLE_LENGTH_SET = DESCRIPTORS && !function () { |
| 1676 |
// makes no sense without proper strict mode support |
| 1677 |
if (this !== undefined) return true; |
| 1678 |
try { |
| 1679 |
// eslint-disable-next-line es/no-object-defineproperty -- safe |
| 1680 |
Object.defineProperty([], 'length', { writable: false }).length = 1; |
| 1681 |
} catch (error) { |
| 1682 |
return error instanceof TypeError; |
| 1683 |
} |
| 1684 |
}(); |
| 1685 |
|
| 1686 |
module.exports = SILENT_ON_NON_WRITABLE_LENGTH_SET ? function (O, length) { |
| 1687 |
if (isArray(O) && !getOwnPropertyDescriptor(O, 'length').writable) { |
| 1688 |
throw new $TypeError('Cannot set read only .length'); |
| 1689 |
} return O.length = length; |
| 1690 |
} : function (O, length) { |
| 1691 |
return O.length = length; |
| 1692 |
}; |
| 1693 |
|
| 1694 |
|
| 1695 |
/***/ }), |
| 1696 |
|
| 1697 |
/***/ 4549: |
| 1698 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1699 |
|
| 1700 |
|
| 1701 |
var globalThis = __webpack_require__(4576); |
| 1702 |
|
| 1703 |
// https://github.com/tc39/ecma262/pull/3467 |
| 1704 |
module.exports = function (METHOD_NAME, ExpectedError) { |
| 1705 |
var Iterator = globalThis.Iterator; |
| 1706 |
var IteratorPrototype = Iterator && Iterator.prototype; |
| 1707 |
var method = IteratorPrototype && IteratorPrototype[METHOD_NAME]; |
| 1708 |
|
| 1709 |
var CLOSED = false; |
| 1710 |
|
| 1711 |
if (method) try { |
| 1712 |
method.call({ |
| 1713 |
next: function () { return { done: true }; }, |
| 1714 |
'return': function () { CLOSED = true; } |
| 1715 |
}, -1); |
| 1716 |
} catch (error) { |
| 1717 |
// https://bugs.webkit.org/show_bug.cgi?id=291195 |
| 1718 |
if (!(error instanceof ExpectedError)) CLOSED = false; |
| 1719 |
} |
| 1720 |
|
| 1721 |
if (!CLOSED) return method; |
| 1722 |
}; |
| 1723 |
|
| 1724 |
|
| 1725 |
/***/ }), |
| 1726 |
|
| 1727 |
/***/ 4576: |
| 1728 |
/***/ (function(module) { |
| 1729 |
|
| 1730 |
|
| 1731 |
var check = function (it) { |
| 1732 |
return it && it.Math === Math && it; |
| 1733 |
}; |
| 1734 |
|
| 1735 |
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 |
| 1736 |
module.exports = |
| 1737 |
// eslint-disable-next-line es/no-global-this -- safe |
| 1738 |
check(typeof globalThis == 'object' && globalThis) || |
| 1739 |
check(typeof window == 'object' && window) || |
| 1740 |
// eslint-disable-next-line no-restricted-globals -- safe |
| 1741 |
check(typeof self == 'object' && self) || |
| 1742 |
check(typeof global == 'object' && global) || |
| 1743 |
check(typeof this == 'object' && this) || |
| 1744 |
// eslint-disable-next-line no-new-func -- fallback |
| 1745 |
(function () { return this; })() || Function('return this')(); |
| 1746 |
|
| 1747 |
|
| 1748 |
/***/ }), |
| 1749 |
|
| 1750 |
/***/ 4603: |
| 1751 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1752 |
|
| 1753 |
|
| 1754 |
var defineBuiltIn = __webpack_require__(6840); |
| 1755 |
var uncurryThis = __webpack_require__(9504); |
| 1756 |
var toString = __webpack_require__(655); |
| 1757 |
var validateArgumentsLength = __webpack_require__(2812); |
| 1758 |
|
| 1759 |
var $URLSearchParams = URLSearchParams; |
| 1760 |
var URLSearchParamsPrototype = $URLSearchParams.prototype; |
| 1761 |
var append = uncurryThis(URLSearchParamsPrototype.append); |
| 1762 |
var $delete = uncurryThis(URLSearchParamsPrototype['delete']); |
| 1763 |
var forEach = uncurryThis(URLSearchParamsPrototype.forEach); |
| 1764 |
var push = uncurryThis([].push); |
| 1765 |
var params = new $URLSearchParams('a=1&a=2&b=3'); |
| 1766 |
|
| 1767 |
params['delete']('a', 1); |
| 1768 |
// `undefined` case is a Chromium 117 bug |
| 1769 |
// https://bugs.chromium.org/p/v8/issues/detail?id=14222 |
| 1770 |
params['delete']('b', undefined); |
| 1771 |
|
| 1772 |
if (params + '' !== 'a=2') { |
| 1773 |
defineBuiltIn(URLSearchParamsPrototype, 'delete', function (name /* , value */) { |
| 1774 |
var length = arguments.length; |
| 1775 |
var $value = length < 2 ? undefined : arguments[1]; |
| 1776 |
if (length && $value === undefined) return $delete(this, name); |
| 1777 |
var entries = []; |
| 1778 |
forEach(this, function (v, k) { // also validates `this` |
| 1779 |
push(entries, { key: k, value: v }); |
| 1780 |
}); |
| 1781 |
validateArgumentsLength(length, 1); |
| 1782 |
var key = toString(name); |
| 1783 |
var value = toString($value); |
| 1784 |
var index = 0; |
| 1785 |
var dindex = 0; |
| 1786 |
var found = false; |
| 1787 |
var entriesLength = entries.length; |
| 1788 |
var entry; |
| 1789 |
while (index < entriesLength) { |
| 1790 |
entry = entries[index++]; |
| 1791 |
if (found || entry.key === key) { |
| 1792 |
found = true; |
| 1793 |
$delete(this, entry.key); |
| 1794 |
} else dindex++; |
| 1795 |
} |
| 1796 |
while (dindex < entriesLength) { |
| 1797 |
entry = entries[dindex++]; |
| 1798 |
if (!(entry.key === key && entry.value === value)) append(this, entry.key, entry.value); |
| 1799 |
} |
| 1800 |
}, { enumerable: true, unsafe: true }); |
| 1801 |
} |
| 1802 |
|
| 1803 |
|
| 1804 |
/***/ }), |
| 1805 |
|
| 1806 |
/***/ 4628: |
| 1807 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1808 |
|
| 1809 |
|
| 1810 |
var $ = __webpack_require__(6518); |
| 1811 |
var newPromiseCapabilityModule = __webpack_require__(6043); |
| 1812 |
|
| 1813 |
// `Promise.withResolvers` method |
| 1814 |
// https://tc39.es/ecma262/#sec-promise.withResolvers |
| 1815 |
$({ target: 'Promise', stat: true }, { |
| 1816 |
withResolvers: function withResolvers() { |
| 1817 |
var promiseCapability = newPromiseCapabilityModule.f(this); |
| 1818 |
return { |
| 1819 |
promise: promiseCapability.promise, |
| 1820 |
resolve: promiseCapability.resolve, |
| 1821 |
reject: promiseCapability.reject |
| 1822 |
}; |
| 1823 |
} |
| 1824 |
}); |
| 1825 |
|
| 1826 |
|
| 1827 |
/***/ }), |
| 1828 |
|
| 1829 |
/***/ 4659: |
| 1830 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1831 |
|
| 1832 |
|
| 1833 |
var DESCRIPTORS = __webpack_require__(3724); |
| 1834 |
var definePropertyModule = __webpack_require__(4913); |
| 1835 |
var createPropertyDescriptor = __webpack_require__(6980); |
| 1836 |
|
| 1837 |
module.exports = function (object, key, value) { |
| 1838 |
if (DESCRIPTORS) definePropertyModule.f(object, key, createPropertyDescriptor(0, value)); |
| 1839 |
else object[key] = value; |
| 1840 |
}; |
| 1841 |
|
| 1842 |
|
| 1843 |
/***/ }), |
| 1844 |
|
| 1845 |
/***/ 4901: |
| 1846 |
/***/ ((module) => { |
| 1847 |
|
| 1848 |
|
| 1849 |
// https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot |
| 1850 |
var documentAll = typeof document == 'object' && document.all; |
| 1851 |
|
| 1852 |
// `IsCallable` abstract operation |
| 1853 |
// https://tc39.es/ecma262/#sec-iscallable |
| 1854 |
// eslint-disable-next-line unicorn/no-typeof-undefined -- required for testing |
| 1855 |
module.exports = typeof documentAll == 'undefined' && documentAll !== undefined ? function (argument) { |
| 1856 |
return typeof argument == 'function' || argument === documentAll; |
| 1857 |
} : function (argument) { |
| 1858 |
return typeof argument == 'function'; |
| 1859 |
}; |
| 1860 |
|
| 1861 |
|
| 1862 |
/***/ }), |
| 1863 |
|
| 1864 |
/***/ 4913: |
| 1865 |
/***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 1866 |
|
| 1867 |
|
| 1868 |
var DESCRIPTORS = __webpack_require__(3724); |
| 1869 |
var IE8_DOM_DEFINE = __webpack_require__(5917); |
| 1870 |
var V8_PROTOTYPE_DEFINE_BUG = __webpack_require__(8686); |
| 1871 |
var anObject = __webpack_require__(8551); |
| 1872 |
var toPropertyKey = __webpack_require__(6969); |
| 1873 |
|
| 1874 |
var $TypeError = TypeError; |
| 1875 |
// eslint-disable-next-line es/no-object-defineproperty -- safe |
| 1876 |
var $defineProperty = Object.defineProperty; |
| 1877 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 1878 |
var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 1879 |
var ENUMERABLE = 'enumerable'; |
| 1880 |
var CONFIGURABLE = 'configurable'; |
| 1881 |
var WRITABLE = 'writable'; |
| 1882 |
|
| 1883 |
// `Object.defineProperty` method |
| 1884 |
// https://tc39.es/ecma262/#sec-object.defineproperty |
| 1885 |
exports.f = DESCRIPTORS ? V8_PROTOTYPE_DEFINE_BUG ? function defineProperty(O, P, Attributes) { |
| 1886 |
anObject(O); |
| 1887 |
P = toPropertyKey(P); |
| 1888 |
anObject(Attributes); |
| 1889 |
if (typeof O === 'function' && P === 'prototype' && 'value' in Attributes && WRITABLE in Attributes && !Attributes[WRITABLE]) { |
| 1890 |
var current = $getOwnPropertyDescriptor(O, P); |
| 1891 |
if (current && current[WRITABLE]) { |
| 1892 |
O[P] = Attributes.value; |
| 1893 |
Attributes = { |
| 1894 |
configurable: CONFIGURABLE in Attributes ? Attributes[CONFIGURABLE] : current[CONFIGURABLE], |
| 1895 |
enumerable: ENUMERABLE in Attributes ? Attributes[ENUMERABLE] : current[ENUMERABLE], |
| 1896 |
writable: false |
| 1897 |
}; |
| 1898 |
} |
| 1899 |
} return $defineProperty(O, P, Attributes); |
| 1900 |
} : $defineProperty : function defineProperty(O, P, Attributes) { |
| 1901 |
anObject(O); |
| 1902 |
P = toPropertyKey(P); |
| 1903 |
anObject(Attributes); |
| 1904 |
if (IE8_DOM_DEFINE) try { |
| 1905 |
return $defineProperty(O, P, Attributes); |
| 1906 |
} catch (error) { /* empty */ } |
| 1907 |
if ('get' in Attributes || 'set' in Attributes) throw new $TypeError('Accessors not supported'); |
| 1908 |
if ('value' in Attributes) O[P] = Attributes.value; |
| 1909 |
return O; |
| 1910 |
}; |
| 1911 |
|
| 1912 |
|
| 1913 |
/***/ }), |
| 1914 |
|
| 1915 |
/***/ 4916: |
| 1916 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 1917 |
|
| 1918 |
|
| 1919 |
var getBuiltIn = __webpack_require__(7751); |
| 1920 |
|
| 1921 |
var createSetLike = function (size) { |
| 1922 |
return { |
| 1923 |
size: size, |
| 1924 |
has: function () { |
| 1925 |
return false; |
| 1926 |
}, |
| 1927 |
keys: function () { |
| 1928 |
return { |
| 1929 |
next: function () { |
| 1930 |
return { done: true }; |
| 1931 |
} |
| 1932 |
}; |
| 1933 |
} |
| 1934 |
}; |
| 1935 |
}; |
| 1936 |
|
| 1937 |
var createSetLikeWithInfinitySize = function (size) { |
| 1938 |
return { |
| 1939 |
size: size, |
| 1940 |
has: function () { |
| 1941 |
return true; |
| 1942 |
}, |
| 1943 |
keys: function () { |
| 1944 |
throw new Error('e'); |
| 1945 |
} |
| 1946 |
}; |
| 1947 |
}; |
| 1948 |
|
| 1949 |
module.exports = function (name, callback) { |
| 1950 |
var Set = getBuiltIn('Set'); |
| 1951 |
try { |
| 1952 |
new Set()[name](createSetLike(0)); |
| 1953 |
try { |
| 1954 |
// late spec change, early WebKit ~ Safari 17 implementation does not pass it |
| 1955 |
// https://github.com/tc39/proposal-set-methods/pull/88 |
| 1956 |
// also covered engines with |
| 1957 |
// https://bugs.webkit.org/show_bug.cgi?id=272679 |
| 1958 |
new Set()[name](createSetLike(-1)); |
| 1959 |
return false; |
| 1960 |
} catch (error2) { |
| 1961 |
if (!callback) return true; |
| 1962 |
// early V8 implementation bug |
| 1963 |
// https://issues.chromium.org/issues/351332634 |
| 1964 |
try { |
| 1965 |
new Set()[name](createSetLikeWithInfinitySize(-Infinity)); |
| 1966 |
return false; |
| 1967 |
} catch (error) { |
| 1968 |
var set = new Set(); |
| 1969 |
set.add(1); |
| 1970 |
set.add(2); |
| 1971 |
return callback(set[name](createSetLikeWithInfinitySize(Infinity))); |
| 1972 |
} |
| 1973 |
} |
| 1974 |
} catch (error) { |
| 1975 |
return false; |
| 1976 |
} |
| 1977 |
}; |
| 1978 |
|
| 1979 |
|
| 1980 |
/***/ }), |
| 1981 |
|
| 1982 |
/***/ 5024: |
| 1983 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 1984 |
|
| 1985 |
|
| 1986 |
var $ = __webpack_require__(6518); |
| 1987 |
var symmetricDifference = __webpack_require__(3650); |
| 1988 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 1989 |
|
| 1990 |
// `Set.prototype.symmetricDifference` method |
| 1991 |
// https://tc39.es/ecma262/#sec-set.prototype.symmetricdifference |
| 1992 |
$({ target: 'Set', proto: true, real: true, forced: !setMethodAcceptSetLike('symmetricDifference') }, { |
| 1993 |
symmetricDifference: symmetricDifference |
| 1994 |
}); |
| 1995 |
|
| 1996 |
|
| 1997 |
/***/ }), |
| 1998 |
|
| 1999 |
/***/ 5031: |
| 2000 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2001 |
|
| 2002 |
|
| 2003 |
var getBuiltIn = __webpack_require__(7751); |
| 2004 |
var uncurryThis = __webpack_require__(9504); |
| 2005 |
var getOwnPropertyNamesModule = __webpack_require__(8480); |
| 2006 |
var getOwnPropertySymbolsModule = __webpack_require__(3717); |
| 2007 |
var anObject = __webpack_require__(8551); |
| 2008 |
|
| 2009 |
var concat = uncurryThis([].concat); |
| 2010 |
|
| 2011 |
// all object keys, includes non-enumerable and symbols |
| 2012 |
module.exports = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) { |
| 2013 |
var keys = getOwnPropertyNamesModule.f(anObject(it)); |
| 2014 |
var getOwnPropertySymbols = getOwnPropertySymbolsModule.f; |
| 2015 |
return getOwnPropertySymbols ? concat(keys, getOwnPropertySymbols(it)) : keys; |
| 2016 |
}; |
| 2017 |
|
| 2018 |
|
| 2019 |
/***/ }), |
| 2020 |
|
| 2021 |
/***/ 5169: |
| 2022 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2023 |
|
| 2024 |
|
| 2025 |
var isDetached = __webpack_require__(3238); |
| 2026 |
|
| 2027 |
var $TypeError = TypeError; |
| 2028 |
|
| 2029 |
module.exports = function (it) { |
| 2030 |
if (isDetached(it)) throw new $TypeError('ArrayBuffer is detached'); |
| 2031 |
return it; |
| 2032 |
}; |
| 2033 |
|
| 2034 |
|
| 2035 |
/***/ }), |
| 2036 |
|
| 2037 |
/***/ 5170: |
| 2038 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2039 |
|
| 2040 |
|
| 2041 |
var uncurryThisAccessor = __webpack_require__(6706); |
| 2042 |
var SetHelpers = __webpack_require__(4402); |
| 2043 |
|
| 2044 |
module.exports = uncurryThisAccessor(SetHelpers.proto, 'size', 'get') || function (set) { |
| 2045 |
return set.size; |
| 2046 |
}; |
| 2047 |
|
| 2048 |
|
| 2049 |
/***/ }), |
| 2050 |
|
| 2051 |
/***/ 5397: |
| 2052 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2053 |
|
| 2054 |
|
| 2055 |
// toObject with fallback for non-array-like ES3 strings |
| 2056 |
var IndexedObject = __webpack_require__(7055); |
| 2057 |
var requireObjectCoercible = __webpack_require__(7750); |
| 2058 |
|
| 2059 |
module.exports = function (it) { |
| 2060 |
return IndexedObject(requireObjectCoercible(it)); |
| 2061 |
}; |
| 2062 |
|
| 2063 |
|
| 2064 |
/***/ }), |
| 2065 |
|
| 2066 |
/***/ 5610: |
| 2067 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2068 |
|
| 2069 |
|
| 2070 |
var toIntegerOrInfinity = __webpack_require__(1291); |
| 2071 |
|
| 2072 |
var max = Math.max; |
| 2073 |
var min = Math.min; |
| 2074 |
|
| 2075 |
// Helper for a popular repeating case of the spec: |
| 2076 |
// Let integer be ? ToInteger(index). |
| 2077 |
// If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length). |
| 2078 |
module.exports = function (index, length) { |
| 2079 |
var integer = toIntegerOrInfinity(index); |
| 2080 |
return integer < 0 ? max(integer + length, 0) : min(integer, length); |
| 2081 |
}; |
| 2082 |
|
| 2083 |
|
| 2084 |
/***/ }), |
| 2085 |
|
| 2086 |
/***/ 5636: |
| 2087 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2088 |
|
| 2089 |
|
| 2090 |
var globalThis = __webpack_require__(4576); |
| 2091 |
var uncurryThis = __webpack_require__(9504); |
| 2092 |
var uncurryThisAccessor = __webpack_require__(6706); |
| 2093 |
var toIndex = __webpack_require__(7696); |
| 2094 |
var notDetached = __webpack_require__(5169); |
| 2095 |
var arrayBufferByteLength = __webpack_require__(7394); |
| 2096 |
var detachTransferable = __webpack_require__(4483); |
| 2097 |
var PROPER_STRUCTURED_CLONE_TRANSFER = __webpack_require__(1548); |
| 2098 |
|
| 2099 |
var structuredClone = globalThis.structuredClone; |
| 2100 |
var ArrayBuffer = globalThis.ArrayBuffer; |
| 2101 |
var DataView = globalThis.DataView; |
| 2102 |
var min = Math.min; |
| 2103 |
var ArrayBufferPrototype = ArrayBuffer.prototype; |
| 2104 |
var DataViewPrototype = DataView.prototype; |
| 2105 |
var slice = uncurryThis(ArrayBufferPrototype.slice); |
| 2106 |
var isResizable = uncurryThisAccessor(ArrayBufferPrototype, 'resizable', 'get'); |
| 2107 |
var maxByteLength = uncurryThisAccessor(ArrayBufferPrototype, 'maxByteLength', 'get'); |
| 2108 |
var getInt8 = uncurryThis(DataViewPrototype.getInt8); |
| 2109 |
var setInt8 = uncurryThis(DataViewPrototype.setInt8); |
| 2110 |
|
| 2111 |
module.exports = (PROPER_STRUCTURED_CLONE_TRANSFER || detachTransferable) && function (arrayBuffer, newLength, preserveResizability) { |
| 2112 |
var byteLength = arrayBufferByteLength(arrayBuffer); |
| 2113 |
var newByteLength = newLength === undefined ? byteLength : toIndex(newLength); |
| 2114 |
var fixedLength = !isResizable || !isResizable(arrayBuffer); |
| 2115 |
var newBuffer; |
| 2116 |
notDetached(arrayBuffer); |
| 2117 |
if (PROPER_STRUCTURED_CLONE_TRANSFER) { |
| 2118 |
arrayBuffer = structuredClone(arrayBuffer, { transfer: [arrayBuffer] }); |
| 2119 |
if (byteLength === newByteLength && (preserveResizability || fixedLength)) return arrayBuffer; |
| 2120 |
} |
| 2121 |
if (byteLength >= newByteLength && (!preserveResizability || fixedLength)) { |
| 2122 |
newBuffer = slice(arrayBuffer, 0, newByteLength); |
| 2123 |
} else { |
| 2124 |
var options = preserveResizability && !fixedLength && maxByteLength ? { maxByteLength: maxByteLength(arrayBuffer) } : undefined; |
| 2125 |
newBuffer = new ArrayBuffer(newByteLength, options); |
| 2126 |
var a = new DataView(arrayBuffer); |
| 2127 |
var b = new DataView(newBuffer); |
| 2128 |
var copyLength = min(newByteLength, byteLength); |
| 2129 |
for (var i = 0; i < copyLength; i++) setInt8(b, i, getInt8(a, i)); |
| 2130 |
} |
| 2131 |
if (!PROPER_STRUCTURED_CLONE_TRANSFER) detachTransferable(arrayBuffer); |
| 2132 |
return newBuffer; |
| 2133 |
}; |
| 2134 |
|
| 2135 |
|
| 2136 |
/***/ }), |
| 2137 |
|
| 2138 |
/***/ 5745: |
| 2139 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2140 |
|
| 2141 |
|
| 2142 |
var store = __webpack_require__(7629); |
| 2143 |
|
| 2144 |
module.exports = function (key, value) { |
| 2145 |
return store[key] || (store[key] = value || {}); |
| 2146 |
}; |
| 2147 |
|
| 2148 |
|
| 2149 |
/***/ }), |
| 2150 |
|
| 2151 |
/***/ 5781: |
| 2152 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2153 |
|
| 2154 |
|
| 2155 |
var $ = __webpack_require__(6518); |
| 2156 |
var getBuiltIn = __webpack_require__(7751); |
| 2157 |
var validateArgumentsLength = __webpack_require__(2812); |
| 2158 |
var toString = __webpack_require__(655); |
| 2159 |
var USE_NATIVE_URL = __webpack_require__(7416); |
| 2160 |
|
| 2161 |
var URL = getBuiltIn('URL'); |
| 2162 |
|
| 2163 |
// `URL.parse` method |
| 2164 |
// https://url.spec.whatwg.org/#dom-url-canparse |
| 2165 |
$({ target: 'URL', stat: true, forced: !USE_NATIVE_URL }, { |
| 2166 |
parse: function parse(url) { |
| 2167 |
var length = validateArgumentsLength(arguments.length, 1); |
| 2168 |
var urlString = toString(url); |
| 2169 |
var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]); |
| 2170 |
try { |
| 2171 |
return new URL(urlString, base); |
| 2172 |
} catch (error) { |
| 2173 |
return null; |
| 2174 |
} |
| 2175 |
} |
| 2176 |
}); |
| 2177 |
|
| 2178 |
|
| 2179 |
/***/ }), |
| 2180 |
|
| 2181 |
/***/ 5876: |
| 2182 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2183 |
|
| 2184 |
|
| 2185 |
var $ = __webpack_require__(6518); |
| 2186 |
var isSubsetOf = __webpack_require__(3838); |
| 2187 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 2188 |
|
| 2189 |
var INCORRECT = !setMethodAcceptSetLike('isSubsetOf', function (result) { |
| 2190 |
return result; |
| 2191 |
}); |
| 2192 |
|
| 2193 |
// `Set.prototype.isSubsetOf` method |
| 2194 |
// https://tc39.es/ecma262/#sec-set.prototype.issubsetof |
| 2195 |
$({ target: 'Set', proto: true, real: true, forced: INCORRECT }, { |
| 2196 |
isSubsetOf: isSubsetOf |
| 2197 |
}); |
| 2198 |
|
| 2199 |
|
| 2200 |
/***/ }), |
| 2201 |
|
| 2202 |
/***/ 5917: |
| 2203 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2204 |
|
| 2205 |
|
| 2206 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2207 |
var fails = __webpack_require__(9039); |
| 2208 |
var createElement = __webpack_require__(4055); |
| 2209 |
|
| 2210 |
// Thanks to IE8 for its funny defineProperty |
| 2211 |
module.exports = !DESCRIPTORS && !fails(function () { |
| 2212 |
// eslint-disable-next-line es/no-object-defineproperty -- required for testing |
| 2213 |
return Object.defineProperty(createElement('div'), 'a', { |
| 2214 |
get: function () { return 7; } |
| 2215 |
}).a !== 7; |
| 2216 |
}); |
| 2217 |
|
| 2218 |
|
| 2219 |
/***/ }), |
| 2220 |
|
| 2221 |
/***/ 5966: |
| 2222 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2223 |
|
| 2224 |
|
| 2225 |
var aCallable = __webpack_require__(9306); |
| 2226 |
var isNullOrUndefined = __webpack_require__(4117); |
| 2227 |
|
| 2228 |
// `GetMethod` abstract operation |
| 2229 |
// https://tc39.es/ecma262/#sec-getmethod |
| 2230 |
module.exports = function (V, P) { |
| 2231 |
var func = V[P]; |
| 2232 |
return isNullOrUndefined(func) ? undefined : aCallable(func); |
| 2233 |
}; |
| 2234 |
|
| 2235 |
|
| 2236 |
/***/ }), |
| 2237 |
|
| 2238 |
/***/ 6043: |
| 2239 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2240 |
|
| 2241 |
|
| 2242 |
var aCallable = __webpack_require__(9306); |
| 2243 |
|
| 2244 |
var $TypeError = TypeError; |
| 2245 |
|
| 2246 |
var PromiseCapability = function (C) { |
| 2247 |
var resolve, reject; |
| 2248 |
this.promise = new C(function ($$resolve, $$reject) { |
| 2249 |
if (resolve !== undefined || reject !== undefined) throw new $TypeError('Bad Promise constructor'); |
| 2250 |
resolve = $$resolve; |
| 2251 |
reject = $$reject; |
| 2252 |
}); |
| 2253 |
this.resolve = aCallable(resolve); |
| 2254 |
this.reject = aCallable(reject); |
| 2255 |
}; |
| 2256 |
|
| 2257 |
// `NewPromiseCapability` abstract operation |
| 2258 |
// https://tc39.es/ecma262/#sec-newpromisecapability |
| 2259 |
module.exports.f = function (C) { |
| 2260 |
return new PromiseCapability(C); |
| 2261 |
}; |
| 2262 |
|
| 2263 |
|
| 2264 |
/***/ }), |
| 2265 |
|
| 2266 |
/***/ 6080: |
| 2267 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2268 |
|
| 2269 |
|
| 2270 |
var uncurryThis = __webpack_require__(7476); |
| 2271 |
var aCallable = __webpack_require__(9306); |
| 2272 |
var NATIVE_BIND = __webpack_require__(616); |
| 2273 |
|
| 2274 |
var bind = uncurryThis(uncurryThis.bind); |
| 2275 |
|
| 2276 |
// optional / simple context binding |
| 2277 |
module.exports = function (fn, that) { |
| 2278 |
aCallable(fn); |
| 2279 |
return that === undefined ? fn : NATIVE_BIND ? bind(fn, that) : function (/* ...args */) { |
| 2280 |
return fn.apply(that, arguments); |
| 2281 |
}; |
| 2282 |
}; |
| 2283 |
|
| 2284 |
|
| 2285 |
/***/ }), |
| 2286 |
|
| 2287 |
/***/ 6119: |
| 2288 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2289 |
|
| 2290 |
|
| 2291 |
var shared = __webpack_require__(5745); |
| 2292 |
var uid = __webpack_require__(3392); |
| 2293 |
|
| 2294 |
var keys = shared('keys'); |
| 2295 |
|
| 2296 |
module.exports = function (key) { |
| 2297 |
return keys[key] || (keys[key] = uid(key)); |
| 2298 |
}; |
| 2299 |
|
| 2300 |
|
| 2301 |
/***/ }), |
| 2302 |
|
| 2303 |
/***/ 6193: |
| 2304 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2305 |
|
| 2306 |
|
| 2307 |
var ENVIRONMENT = __webpack_require__(4215); |
| 2308 |
|
| 2309 |
module.exports = ENVIRONMENT === 'NODE'; |
| 2310 |
|
| 2311 |
|
| 2312 |
/***/ }), |
| 2313 |
|
| 2314 |
/***/ 6198: |
| 2315 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2316 |
|
| 2317 |
|
| 2318 |
var toLength = __webpack_require__(8014); |
| 2319 |
|
| 2320 |
// `LengthOfArrayLike` abstract operation |
| 2321 |
// https://tc39.es/ecma262/#sec-lengthofarraylike |
| 2322 |
module.exports = function (obj) { |
| 2323 |
return toLength(obj.length); |
| 2324 |
}; |
| 2325 |
|
| 2326 |
|
| 2327 |
/***/ }), |
| 2328 |
|
| 2329 |
/***/ 6269: |
| 2330 |
/***/ ((module) => { |
| 2331 |
|
| 2332 |
|
| 2333 |
module.exports = {}; |
| 2334 |
|
| 2335 |
|
| 2336 |
/***/ }), |
| 2337 |
|
| 2338 |
/***/ 6279: |
| 2339 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2340 |
|
| 2341 |
|
| 2342 |
var defineBuiltIn = __webpack_require__(6840); |
| 2343 |
|
| 2344 |
module.exports = function (target, src, options) { |
| 2345 |
for (var key in src) defineBuiltIn(target, key, src[key], options); |
| 2346 |
return target; |
| 2347 |
}; |
| 2348 |
|
| 2349 |
|
| 2350 |
/***/ }), |
| 2351 |
|
| 2352 |
/***/ 6319: |
| 2353 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2354 |
|
| 2355 |
|
| 2356 |
var anObject = __webpack_require__(8551); |
| 2357 |
var iteratorClose = __webpack_require__(9539); |
| 2358 |
|
| 2359 |
// call something on iterator step with safe closing on error |
| 2360 |
module.exports = function (iterator, fn, value, ENTRIES) { |
| 2361 |
try { |
| 2362 |
return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value); |
| 2363 |
} catch (error) { |
| 2364 |
iteratorClose(iterator, 'throw', error); |
| 2365 |
} |
| 2366 |
}; |
| 2367 |
|
| 2368 |
|
| 2369 |
/***/ }), |
| 2370 |
|
| 2371 |
/***/ 6395: |
| 2372 |
/***/ ((module) => { |
| 2373 |
|
| 2374 |
|
| 2375 |
module.exports = false; |
| 2376 |
|
| 2377 |
|
| 2378 |
/***/ }), |
| 2379 |
|
| 2380 |
/***/ 6518: |
| 2381 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2382 |
|
| 2383 |
|
| 2384 |
var globalThis = __webpack_require__(4576); |
| 2385 |
var getOwnPropertyDescriptor = (__webpack_require__(7347).f); |
| 2386 |
var createNonEnumerableProperty = __webpack_require__(6699); |
| 2387 |
var defineBuiltIn = __webpack_require__(6840); |
| 2388 |
var defineGlobalProperty = __webpack_require__(9433); |
| 2389 |
var copyConstructorProperties = __webpack_require__(7740); |
| 2390 |
var isForced = __webpack_require__(2796); |
| 2391 |
|
| 2392 |
/* |
| 2393 |
options.target - name of the target object |
| 2394 |
options.global - target is the global object |
| 2395 |
options.stat - export as static methods of target |
| 2396 |
options.proto - export as prototype methods of target |
| 2397 |
options.real - real prototype method for the `pure` version |
| 2398 |
options.forced - export even if the native feature is available |
| 2399 |
options.bind - bind methods to the target, required for the `pure` version |
| 2400 |
options.wrap - wrap constructors to preventing global pollution, required for the `pure` version |
| 2401 |
options.unsafe - use the simple assignment of property instead of delete + defineProperty |
| 2402 |
options.sham - add a flag to not completely full polyfills |
| 2403 |
options.enumerable - export as enumerable property |
| 2404 |
options.dontCallGetSet - prevent calling a getter on target |
| 2405 |
options.name - the .name of the function if it does not match the key |
| 2406 |
*/ |
| 2407 |
module.exports = function (options, source) { |
| 2408 |
var TARGET = options.target; |
| 2409 |
var GLOBAL = options.global; |
| 2410 |
var STATIC = options.stat; |
| 2411 |
var FORCED, target, key, targetProperty, sourceProperty, descriptor; |
| 2412 |
if (GLOBAL) { |
| 2413 |
target = globalThis; |
| 2414 |
} else if (STATIC) { |
| 2415 |
target = globalThis[TARGET] || defineGlobalProperty(TARGET, {}); |
| 2416 |
} else { |
| 2417 |
target = globalThis[TARGET] && globalThis[TARGET].prototype; |
| 2418 |
} |
| 2419 |
if (target) for (key in source) { |
| 2420 |
sourceProperty = source[key]; |
| 2421 |
if (options.dontCallGetSet) { |
| 2422 |
descriptor = getOwnPropertyDescriptor(target, key); |
| 2423 |
targetProperty = descriptor && descriptor.value; |
| 2424 |
} else targetProperty = target[key]; |
| 2425 |
FORCED = isForced(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); |
| 2426 |
// contained in target |
| 2427 |
if (!FORCED && targetProperty !== undefined) { |
| 2428 |
if (typeof sourceProperty == typeof targetProperty) continue; |
| 2429 |
copyConstructorProperties(sourceProperty, targetProperty); |
| 2430 |
} |
| 2431 |
// add a flag to not completely full polyfills |
| 2432 |
if (options.sham || (targetProperty && targetProperty.sham)) { |
| 2433 |
createNonEnumerableProperty(sourceProperty, 'sham', true); |
| 2434 |
} |
| 2435 |
defineBuiltIn(target, key, sourceProperty, options); |
| 2436 |
} |
| 2437 |
}; |
| 2438 |
|
| 2439 |
|
| 2440 |
/***/ }), |
| 2441 |
|
| 2442 |
/***/ 6573: |
| 2443 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2444 |
|
| 2445 |
|
| 2446 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2447 |
var defineBuiltInAccessor = __webpack_require__(2106); |
| 2448 |
var isDetached = __webpack_require__(3238); |
| 2449 |
|
| 2450 |
var ArrayBufferPrototype = ArrayBuffer.prototype; |
| 2451 |
|
| 2452 |
// `ArrayBuffer.prototype.detached` getter |
| 2453 |
// https://tc39.es/ecma262/#sec-get-arraybuffer.prototype.detached |
| 2454 |
if (DESCRIPTORS && !('detached' in ArrayBufferPrototype)) { |
| 2455 |
defineBuiltInAccessor(ArrayBufferPrototype, 'detached', { |
| 2456 |
configurable: true, |
| 2457 |
get: function detached() { |
| 2458 |
return isDetached(this); |
| 2459 |
} |
| 2460 |
}); |
| 2461 |
} |
| 2462 |
|
| 2463 |
|
| 2464 |
/***/ }), |
| 2465 |
|
| 2466 |
/***/ 6699: |
| 2467 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2468 |
|
| 2469 |
|
| 2470 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2471 |
var definePropertyModule = __webpack_require__(4913); |
| 2472 |
var createPropertyDescriptor = __webpack_require__(6980); |
| 2473 |
|
| 2474 |
module.exports = DESCRIPTORS ? function (object, key, value) { |
| 2475 |
return definePropertyModule.f(object, key, createPropertyDescriptor(1, value)); |
| 2476 |
} : function (object, key, value) { |
| 2477 |
object[key] = value; |
| 2478 |
return object; |
| 2479 |
}; |
| 2480 |
|
| 2481 |
|
| 2482 |
/***/ }), |
| 2483 |
|
| 2484 |
/***/ 6706: |
| 2485 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2486 |
|
| 2487 |
|
| 2488 |
var uncurryThis = __webpack_require__(9504); |
| 2489 |
var aCallable = __webpack_require__(9306); |
| 2490 |
|
| 2491 |
module.exports = function (object, key, method) { |
| 2492 |
try { |
| 2493 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 2494 |
return uncurryThis(aCallable(Object.getOwnPropertyDescriptor(object, key)[method])); |
| 2495 |
} catch (error) { /* empty */ } |
| 2496 |
}; |
| 2497 |
|
| 2498 |
|
| 2499 |
/***/ }), |
| 2500 |
|
| 2501 |
/***/ 6801: |
| 2502 |
/***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 2503 |
|
| 2504 |
|
| 2505 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2506 |
var V8_PROTOTYPE_DEFINE_BUG = __webpack_require__(8686); |
| 2507 |
var definePropertyModule = __webpack_require__(4913); |
| 2508 |
var anObject = __webpack_require__(8551); |
| 2509 |
var toIndexedObject = __webpack_require__(5397); |
| 2510 |
var objectKeys = __webpack_require__(1072); |
| 2511 |
|
| 2512 |
// `Object.defineProperties` method |
| 2513 |
// https://tc39.es/ecma262/#sec-object.defineproperties |
| 2514 |
// eslint-disable-next-line es/no-object-defineproperties -- safe |
| 2515 |
exports.f = DESCRIPTORS && !V8_PROTOTYPE_DEFINE_BUG ? Object.defineProperties : function defineProperties(O, Properties) { |
| 2516 |
anObject(O); |
| 2517 |
var props = toIndexedObject(Properties); |
| 2518 |
var keys = objectKeys(Properties); |
| 2519 |
var length = keys.length; |
| 2520 |
var index = 0; |
| 2521 |
var key; |
| 2522 |
while (length > index) definePropertyModule.f(O, key = keys[index++], props[key]); |
| 2523 |
return O; |
| 2524 |
}; |
| 2525 |
|
| 2526 |
|
| 2527 |
/***/ }), |
| 2528 |
|
| 2529 |
/***/ 6823: |
| 2530 |
/***/ ((module) => { |
| 2531 |
|
| 2532 |
|
| 2533 |
var $String = String; |
| 2534 |
|
| 2535 |
module.exports = function (argument) { |
| 2536 |
try { |
| 2537 |
return $String(argument); |
| 2538 |
} catch (error) { |
| 2539 |
return 'Object'; |
| 2540 |
} |
| 2541 |
}; |
| 2542 |
|
| 2543 |
|
| 2544 |
/***/ }), |
| 2545 |
|
| 2546 |
/***/ 6837: |
| 2547 |
/***/ ((module) => { |
| 2548 |
|
| 2549 |
|
| 2550 |
var $TypeError = TypeError; |
| 2551 |
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991 |
| 2552 |
|
| 2553 |
module.exports = function (it) { |
| 2554 |
if (it > MAX_SAFE_INTEGER) throw $TypeError('Maximum allowed index exceeded'); |
| 2555 |
return it; |
| 2556 |
}; |
| 2557 |
|
| 2558 |
|
| 2559 |
/***/ }), |
| 2560 |
|
| 2561 |
/***/ 6840: |
| 2562 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2563 |
|
| 2564 |
|
| 2565 |
var isCallable = __webpack_require__(4901); |
| 2566 |
var definePropertyModule = __webpack_require__(4913); |
| 2567 |
var makeBuiltIn = __webpack_require__(283); |
| 2568 |
var defineGlobalProperty = __webpack_require__(9433); |
| 2569 |
|
| 2570 |
module.exports = function (O, key, value, options) { |
| 2571 |
if (!options) options = {}; |
| 2572 |
var simple = options.enumerable; |
| 2573 |
var name = options.name !== undefined ? options.name : key; |
| 2574 |
if (isCallable(value)) makeBuiltIn(value, name, options); |
| 2575 |
if (options.global) { |
| 2576 |
if (simple) O[key] = value; |
| 2577 |
else defineGlobalProperty(key, value); |
| 2578 |
} else { |
| 2579 |
try { |
| 2580 |
if (!options.unsafe) delete O[key]; |
| 2581 |
else if (O[key]) simple = true; |
| 2582 |
} catch (error) { /* empty */ } |
| 2583 |
if (simple) O[key] = value; |
| 2584 |
else definePropertyModule.f(O, key, { |
| 2585 |
value: value, |
| 2586 |
enumerable: false, |
| 2587 |
configurable: !options.nonConfigurable, |
| 2588 |
writable: !options.nonWritable |
| 2589 |
}); |
| 2590 |
} return O; |
| 2591 |
}; |
| 2592 |
|
| 2593 |
|
| 2594 |
/***/ }), |
| 2595 |
|
| 2596 |
/***/ 6955: |
| 2597 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2598 |
|
| 2599 |
|
| 2600 |
var TO_STRING_TAG_SUPPORT = __webpack_require__(2140); |
| 2601 |
var isCallable = __webpack_require__(4901); |
| 2602 |
var classofRaw = __webpack_require__(2195); |
| 2603 |
var wellKnownSymbol = __webpack_require__(8227); |
| 2604 |
|
| 2605 |
var TO_STRING_TAG = wellKnownSymbol('toStringTag'); |
| 2606 |
var $Object = Object; |
| 2607 |
|
| 2608 |
// ES3 wrong here |
| 2609 |
var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) === 'Arguments'; |
| 2610 |
|
| 2611 |
// fallback for IE11 Script Access Denied error |
| 2612 |
var tryGet = function (it, key) { |
| 2613 |
try { |
| 2614 |
return it[key]; |
| 2615 |
} catch (error) { /* empty */ } |
| 2616 |
}; |
| 2617 |
|
| 2618 |
// getting tag from ES6+ `Object.prototype.toString` |
| 2619 |
module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function (it) { |
| 2620 |
var O, tag, result; |
| 2621 |
return it === undefined ? 'Undefined' : it === null ? 'Null' |
| 2622 |
// @@toStringTag case |
| 2623 |
: typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == 'string' ? tag |
| 2624 |
// builtinTag case |
| 2625 |
: CORRECT_ARGUMENTS ? classofRaw(O) |
| 2626 |
// ES3 arguments fallback |
| 2627 |
: (result = classofRaw(O)) === 'Object' && isCallable(O.callee) ? 'Arguments' : result; |
| 2628 |
}; |
| 2629 |
|
| 2630 |
|
| 2631 |
/***/ }), |
| 2632 |
|
| 2633 |
/***/ 6969: |
| 2634 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2635 |
|
| 2636 |
|
| 2637 |
var toPrimitive = __webpack_require__(2777); |
| 2638 |
var isSymbol = __webpack_require__(757); |
| 2639 |
|
| 2640 |
// `ToPropertyKey` abstract operation |
| 2641 |
// https://tc39.es/ecma262/#sec-topropertykey |
| 2642 |
module.exports = function (argument) { |
| 2643 |
var key = toPrimitive(argument, 'string'); |
| 2644 |
return isSymbol(key) ? key : key + ''; |
| 2645 |
}; |
| 2646 |
|
| 2647 |
|
| 2648 |
/***/ }), |
| 2649 |
|
| 2650 |
/***/ 6980: |
| 2651 |
/***/ ((module) => { |
| 2652 |
|
| 2653 |
|
| 2654 |
module.exports = function (bitmap, value) { |
| 2655 |
return { |
| 2656 |
enumerable: !(bitmap & 1), |
| 2657 |
configurable: !(bitmap & 2), |
| 2658 |
writable: !(bitmap & 4), |
| 2659 |
value: value |
| 2660 |
}; |
| 2661 |
}; |
| 2662 |
|
| 2663 |
|
| 2664 |
/***/ }), |
| 2665 |
|
| 2666 |
/***/ 7040: |
| 2667 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2668 |
|
| 2669 |
|
| 2670 |
/* eslint-disable es/no-symbol -- required for testing */ |
| 2671 |
var NATIVE_SYMBOL = __webpack_require__(4495); |
| 2672 |
|
| 2673 |
module.exports = NATIVE_SYMBOL && |
| 2674 |
!Symbol.sham && |
| 2675 |
typeof Symbol.iterator == 'symbol'; |
| 2676 |
|
| 2677 |
|
| 2678 |
/***/ }), |
| 2679 |
|
| 2680 |
/***/ 7055: |
| 2681 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2682 |
|
| 2683 |
|
| 2684 |
var uncurryThis = __webpack_require__(9504); |
| 2685 |
var fails = __webpack_require__(9039); |
| 2686 |
var classof = __webpack_require__(2195); |
| 2687 |
|
| 2688 |
var $Object = Object; |
| 2689 |
var split = uncurryThis(''.split); |
| 2690 |
|
| 2691 |
// fallback for non-array-like ES3 and non-enumerable old V8 strings |
| 2692 |
module.exports = fails(function () { |
| 2693 |
// throws an error in rhino, see https://github.com/mozilla/rhino/issues/346 |
| 2694 |
// eslint-disable-next-line no-prototype-builtins -- safe |
| 2695 |
return !$Object('z').propertyIsEnumerable(0); |
| 2696 |
}) ? function (it) { |
| 2697 |
return classof(it) === 'String' ? split(it, '') : $Object(it); |
| 2698 |
} : $Object; |
| 2699 |
|
| 2700 |
|
| 2701 |
/***/ }), |
| 2702 |
|
| 2703 |
/***/ 7080: |
| 2704 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2705 |
|
| 2706 |
|
| 2707 |
var has = (__webpack_require__(4402).has); |
| 2708 |
|
| 2709 |
// Perform ? RequireInternalSlot(M, [[SetData]]) |
| 2710 |
module.exports = function (it) { |
| 2711 |
has(it); |
| 2712 |
return it; |
| 2713 |
}; |
| 2714 |
|
| 2715 |
|
| 2716 |
/***/ }), |
| 2717 |
|
| 2718 |
/***/ 7347: |
| 2719 |
/***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 2720 |
|
| 2721 |
|
| 2722 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2723 |
var call = __webpack_require__(9565); |
| 2724 |
var propertyIsEnumerableModule = __webpack_require__(8773); |
| 2725 |
var createPropertyDescriptor = __webpack_require__(6980); |
| 2726 |
var toIndexedObject = __webpack_require__(5397); |
| 2727 |
var toPropertyKey = __webpack_require__(6969); |
| 2728 |
var hasOwn = __webpack_require__(9297); |
| 2729 |
var IE8_DOM_DEFINE = __webpack_require__(5917); |
| 2730 |
|
| 2731 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 2732 |
var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 2733 |
|
| 2734 |
// `Object.getOwnPropertyDescriptor` method |
| 2735 |
// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor |
| 2736 |
exports.f = DESCRIPTORS ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) { |
| 2737 |
O = toIndexedObject(O); |
| 2738 |
P = toPropertyKey(P); |
| 2739 |
if (IE8_DOM_DEFINE) try { |
| 2740 |
return $getOwnPropertyDescriptor(O, P); |
| 2741 |
} catch (error) { /* empty */ } |
| 2742 |
if (hasOwn(O, P)) return createPropertyDescriptor(!call(propertyIsEnumerableModule.f, O, P), O[P]); |
| 2743 |
}; |
| 2744 |
|
| 2745 |
|
| 2746 |
/***/ }), |
| 2747 |
|
| 2748 |
/***/ 7394: |
| 2749 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2750 |
|
| 2751 |
|
| 2752 |
var globalThis = __webpack_require__(4576); |
| 2753 |
var uncurryThisAccessor = __webpack_require__(6706); |
| 2754 |
var classof = __webpack_require__(2195); |
| 2755 |
|
| 2756 |
var ArrayBuffer = globalThis.ArrayBuffer; |
| 2757 |
var TypeError = globalThis.TypeError; |
| 2758 |
|
| 2759 |
// Includes |
| 2760 |
// - Perform ? RequireInternalSlot(O, [[ArrayBufferData]]). |
| 2761 |
// - If IsSharedArrayBuffer(O) is true, throw a TypeError exception. |
| 2762 |
module.exports = ArrayBuffer && uncurryThisAccessor(ArrayBuffer.prototype, 'byteLength', 'get') || function (O) { |
| 2763 |
if (classof(O) !== 'ArrayBuffer') throw new TypeError('ArrayBuffer expected'); |
| 2764 |
return O.byteLength; |
| 2765 |
}; |
| 2766 |
|
| 2767 |
|
| 2768 |
/***/ }), |
| 2769 |
|
| 2770 |
/***/ 7416: |
| 2771 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2772 |
|
| 2773 |
|
| 2774 |
var fails = __webpack_require__(9039); |
| 2775 |
var wellKnownSymbol = __webpack_require__(8227); |
| 2776 |
var DESCRIPTORS = __webpack_require__(3724); |
| 2777 |
var IS_PURE = __webpack_require__(6395); |
| 2778 |
|
| 2779 |
var ITERATOR = wellKnownSymbol('iterator'); |
| 2780 |
|
| 2781 |
module.exports = !fails(function () { |
| 2782 |
// eslint-disable-next-line unicorn/relative-url-style -- required for testing |
| 2783 |
var url = new URL('b?a=1&b=2&c=3', 'https://a'); |
| 2784 |
var params = url.searchParams; |
| 2785 |
var params2 = new URLSearchParams('a=1&a=2&b=3'); |
| 2786 |
var result = ''; |
| 2787 |
url.pathname = 'c%20d'; |
| 2788 |
params.forEach(function (value, key) { |
| 2789 |
params['delete']('b'); |
| 2790 |
result += key + value; |
| 2791 |
}); |
| 2792 |
params2['delete']('a', 2); |
| 2793 |
// `undefined` case is a Chromium 117 bug |
| 2794 |
// https://bugs.chromium.org/p/v8/issues/detail?id=14222 |
| 2795 |
params2['delete']('b', undefined); |
| 2796 |
return (IS_PURE && (!url.toJSON || !params2.has('a', 1) || params2.has('a', 2) || !params2.has('a', undefined) || params2.has('b'))) |
| 2797 |
|| (!params.size && (IS_PURE || !DESCRIPTORS)) |
| 2798 |
|| !params.sort |
| 2799 |
|| url.href !== 'https://a/c%20d?a=1&c=3' |
| 2800 |
|| params.get('c') !== '3' |
| 2801 |
|| String(new URLSearchParams('?a=1')) !== 'a=1' |
| 2802 |
|| !params[ITERATOR] |
| 2803 |
// throws in Edge |
| 2804 |
|| new URL('https://a@b').username !== 'a' |
| 2805 |
|| new URLSearchParams(new URLSearchParams('a=b')).get('a') !== 'b' |
| 2806 |
// not punycoded in Edge |
| 2807 |
|| new URL('https://тест').host !== 'xn--e1aybc' |
| 2808 |
// not escaped in Chrome 62- |
| 2809 |
|| new URL('https://a#б').hash !== '#%D0%B1' |
| 2810 |
// fails in Chrome 66- |
| 2811 |
|| result !== 'a1c3' |
| 2812 |
// throws in Safari |
| 2813 |
|| new URL('https://x', undefined).host !== 'x'; |
| 2814 |
}); |
| 2815 |
|
| 2816 |
|
| 2817 |
/***/ }), |
| 2818 |
|
| 2819 |
/***/ 7476: |
| 2820 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2821 |
|
| 2822 |
|
| 2823 |
var classofRaw = __webpack_require__(2195); |
| 2824 |
var uncurryThis = __webpack_require__(9504); |
| 2825 |
|
| 2826 |
module.exports = function (fn) { |
| 2827 |
// Nashorn bug: |
| 2828 |
// https://github.com/zloirock/core-js/issues/1128 |
| 2829 |
// https://github.com/zloirock/core-js/issues/1130 |
| 2830 |
if (classofRaw(fn) === 'Function') return uncurryThis(fn); |
| 2831 |
}; |
| 2832 |
|
| 2833 |
|
| 2834 |
/***/ }), |
| 2835 |
|
| 2836 |
/***/ 7566: |
| 2837 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2838 |
|
| 2839 |
|
| 2840 |
var defineBuiltIn = __webpack_require__(6840); |
| 2841 |
var uncurryThis = __webpack_require__(9504); |
| 2842 |
var toString = __webpack_require__(655); |
| 2843 |
var validateArgumentsLength = __webpack_require__(2812); |
| 2844 |
|
| 2845 |
var $URLSearchParams = URLSearchParams; |
| 2846 |
var URLSearchParamsPrototype = $URLSearchParams.prototype; |
| 2847 |
var getAll = uncurryThis(URLSearchParamsPrototype.getAll); |
| 2848 |
var $has = uncurryThis(URLSearchParamsPrototype.has); |
| 2849 |
var params = new $URLSearchParams('a=1'); |
| 2850 |
|
| 2851 |
// `undefined` case is a Chromium 117 bug |
| 2852 |
// https://bugs.chromium.org/p/v8/issues/detail?id=14222 |
| 2853 |
if (params.has('a', 2) || !params.has('a', undefined)) { |
| 2854 |
defineBuiltIn(URLSearchParamsPrototype, 'has', function has(name /* , value */) { |
| 2855 |
var length = arguments.length; |
| 2856 |
var $value = length < 2 ? undefined : arguments[1]; |
| 2857 |
if (length && $value === undefined) return $has(this, name); |
| 2858 |
var values = getAll(this, name); // also validates `this` |
| 2859 |
validateArgumentsLength(length, 1); |
| 2860 |
var value = toString($value); |
| 2861 |
var index = 0; |
| 2862 |
while (index < values.length) { |
| 2863 |
if (values[index++] === value) return true; |
| 2864 |
} return false; |
| 2865 |
}, { enumerable: true, unsafe: true }); |
| 2866 |
} |
| 2867 |
|
| 2868 |
|
| 2869 |
/***/ }), |
| 2870 |
|
| 2871 |
/***/ 7588: |
| 2872 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2873 |
|
| 2874 |
|
| 2875 |
var $ = __webpack_require__(6518); |
| 2876 |
var call = __webpack_require__(9565); |
| 2877 |
var iterate = __webpack_require__(2652); |
| 2878 |
var aCallable = __webpack_require__(9306); |
| 2879 |
var anObject = __webpack_require__(8551); |
| 2880 |
var getIteratorDirect = __webpack_require__(1767); |
| 2881 |
var iteratorClose = __webpack_require__(9539); |
| 2882 |
var iteratorHelperWithoutClosingOnEarlyError = __webpack_require__(4549); |
| 2883 |
|
| 2884 |
var forEachWithoutClosingOnEarlyError = iteratorHelperWithoutClosingOnEarlyError('forEach', TypeError); |
| 2885 |
|
| 2886 |
// `Iterator.prototype.forEach` method |
| 2887 |
// https://tc39.es/ecma262/#sec-iterator.prototype.foreach |
| 2888 |
$({ target: 'Iterator', proto: true, real: true, forced: forEachWithoutClosingOnEarlyError }, { |
| 2889 |
forEach: function forEach(fn) { |
| 2890 |
anObject(this); |
| 2891 |
try { |
| 2892 |
aCallable(fn); |
| 2893 |
} catch (error) { |
| 2894 |
iteratorClose(this, 'throw', error); |
| 2895 |
} |
| 2896 |
|
| 2897 |
if (forEachWithoutClosingOnEarlyError) return call(forEachWithoutClosingOnEarlyError, this, fn); |
| 2898 |
|
| 2899 |
var record = getIteratorDirect(this); |
| 2900 |
var counter = 0; |
| 2901 |
iterate(record, function (value) { |
| 2902 |
fn(value, counter++); |
| 2903 |
}, { IS_RECORD: true }); |
| 2904 |
} |
| 2905 |
}); |
| 2906 |
|
| 2907 |
|
| 2908 |
/***/ }), |
| 2909 |
|
| 2910 |
/***/ 7629: |
| 2911 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2912 |
|
| 2913 |
|
| 2914 |
var IS_PURE = __webpack_require__(6395); |
| 2915 |
var globalThis = __webpack_require__(4576); |
| 2916 |
var defineGlobalProperty = __webpack_require__(9433); |
| 2917 |
|
| 2918 |
var SHARED = '__core-js_shared__'; |
| 2919 |
var store = module.exports = globalThis[SHARED] || defineGlobalProperty(SHARED, {}); |
| 2920 |
|
| 2921 |
(store.versions || (store.versions = [])).push({ |
| 2922 |
version: '3.42.0', |
| 2923 |
mode: IS_PURE ? 'pure' : 'global', |
| 2924 |
copyright: '© 2014-2025 Denis Pushkarev (zloirock.ru)', |
| 2925 |
license: 'https://github.com/zloirock/core-js/blob/v3.42.0/LICENSE', |
| 2926 |
source: 'https://github.com/zloirock/core-js' |
| 2927 |
}); |
| 2928 |
|
| 2929 |
|
| 2930 |
/***/ }), |
| 2931 |
|
| 2932 |
/***/ 7642: |
| 2933 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 2934 |
|
| 2935 |
|
| 2936 |
var $ = __webpack_require__(6518); |
| 2937 |
var difference = __webpack_require__(3440); |
| 2938 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 2939 |
|
| 2940 |
var INCORRECT = !setMethodAcceptSetLike('difference', function (result) { |
| 2941 |
return result.size === 0; |
| 2942 |
}); |
| 2943 |
|
| 2944 |
// `Set.prototype.difference` method |
| 2945 |
// https://tc39.es/ecma262/#sec-set.prototype.difference |
| 2946 |
$({ target: 'Set', proto: true, real: true, forced: INCORRECT }, { |
| 2947 |
difference: difference |
| 2948 |
}); |
| 2949 |
|
| 2950 |
|
| 2951 |
/***/ }), |
| 2952 |
|
| 2953 |
/***/ 7657: |
| 2954 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 2955 |
|
| 2956 |
|
| 2957 |
var fails = __webpack_require__(9039); |
| 2958 |
var isCallable = __webpack_require__(4901); |
| 2959 |
var isObject = __webpack_require__(34); |
| 2960 |
var create = __webpack_require__(2360); |
| 2961 |
var getPrototypeOf = __webpack_require__(2787); |
| 2962 |
var defineBuiltIn = __webpack_require__(6840); |
| 2963 |
var wellKnownSymbol = __webpack_require__(8227); |
| 2964 |
var IS_PURE = __webpack_require__(6395); |
| 2965 |
|
| 2966 |
var ITERATOR = wellKnownSymbol('iterator'); |
| 2967 |
var BUGGY_SAFARI_ITERATORS = false; |
| 2968 |
|
| 2969 |
// `%IteratorPrototype%` object |
| 2970 |
// https://tc39.es/ecma262/#sec-%iteratorprototype%-object |
| 2971 |
var IteratorPrototype, PrototypeOfArrayIteratorPrototype, arrayIterator; |
| 2972 |
|
| 2973 |
/* eslint-disable es/no-array-prototype-keys -- safe */ |
| 2974 |
if ([].keys) { |
| 2975 |
arrayIterator = [].keys(); |
| 2976 |
// Safari 8 has buggy iterators w/o `next` |
| 2977 |
if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS = true; |
| 2978 |
else { |
| 2979 |
PrototypeOfArrayIteratorPrototype = getPrototypeOf(getPrototypeOf(arrayIterator)); |
| 2980 |
if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype = PrototypeOfArrayIteratorPrototype; |
| 2981 |
} |
| 2982 |
} |
| 2983 |
|
| 2984 |
var NEW_ITERATOR_PROTOTYPE = !isObject(IteratorPrototype) || fails(function () { |
| 2985 |
var test = {}; |
| 2986 |
// FF44- legacy iterators case |
| 2987 |
return IteratorPrototype[ITERATOR].call(test) !== test; |
| 2988 |
}); |
| 2989 |
|
| 2990 |
if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype = {}; |
| 2991 |
else if (IS_PURE) IteratorPrototype = create(IteratorPrototype); |
| 2992 |
|
| 2993 |
// `%IteratorPrototype%[@@iterator]()` method |
| 2994 |
// https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator |
| 2995 |
if (!isCallable(IteratorPrototype[ITERATOR])) { |
| 2996 |
defineBuiltIn(IteratorPrototype, ITERATOR, function () { |
| 2997 |
return this; |
| 2998 |
}); |
| 2999 |
} |
| 3000 |
|
| 3001 |
module.exports = { |
| 3002 |
IteratorPrototype: IteratorPrototype, |
| 3003 |
BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS |
| 3004 |
}; |
| 3005 |
|
| 3006 |
|
| 3007 |
/***/ }), |
| 3008 |
|
| 3009 |
/***/ 7696: |
| 3010 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3011 |
|
| 3012 |
|
| 3013 |
var toIntegerOrInfinity = __webpack_require__(1291); |
| 3014 |
var toLength = __webpack_require__(8014); |
| 3015 |
|
| 3016 |
var $RangeError = RangeError; |
| 3017 |
|
| 3018 |
// `ToIndex` abstract operation |
| 3019 |
// https://tc39.es/ecma262/#sec-toindex |
| 3020 |
module.exports = function (it) { |
| 3021 |
if (it === undefined) return 0; |
| 3022 |
var number = toIntegerOrInfinity(it); |
| 3023 |
var length = toLength(number); |
| 3024 |
if (number !== length) throw new $RangeError('Wrong length or index'); |
| 3025 |
return length; |
| 3026 |
}; |
| 3027 |
|
| 3028 |
|
| 3029 |
/***/ }), |
| 3030 |
|
| 3031 |
/***/ 7740: |
| 3032 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3033 |
|
| 3034 |
|
| 3035 |
var hasOwn = __webpack_require__(9297); |
| 3036 |
var ownKeys = __webpack_require__(5031); |
| 3037 |
var getOwnPropertyDescriptorModule = __webpack_require__(7347); |
| 3038 |
var definePropertyModule = __webpack_require__(4913); |
| 3039 |
|
| 3040 |
module.exports = function (target, source, exceptions) { |
| 3041 |
var keys = ownKeys(source); |
| 3042 |
var defineProperty = definePropertyModule.f; |
| 3043 |
var getOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f; |
| 3044 |
for (var i = 0; i < keys.length; i++) { |
| 3045 |
var key = keys[i]; |
| 3046 |
if (!hasOwn(target, key) && !(exceptions && hasOwn(exceptions, key))) { |
| 3047 |
defineProperty(target, key, getOwnPropertyDescriptor(source, key)); |
| 3048 |
} |
| 3049 |
} |
| 3050 |
}; |
| 3051 |
|
| 3052 |
|
| 3053 |
/***/ }), |
| 3054 |
|
| 3055 |
/***/ 7750: |
| 3056 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3057 |
|
| 3058 |
|
| 3059 |
var isNullOrUndefined = __webpack_require__(4117); |
| 3060 |
|
| 3061 |
var $TypeError = TypeError; |
| 3062 |
|
| 3063 |
// `RequireObjectCoercible` abstract operation |
| 3064 |
// https://tc39.es/ecma262/#sec-requireobjectcoercible |
| 3065 |
module.exports = function (it) { |
| 3066 |
if (isNullOrUndefined(it)) throw new $TypeError("Can't call method on " + it); |
| 3067 |
return it; |
| 3068 |
}; |
| 3069 |
|
| 3070 |
|
| 3071 |
/***/ }), |
| 3072 |
|
| 3073 |
/***/ 7751: |
| 3074 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3075 |
|
| 3076 |
|
| 3077 |
var globalThis = __webpack_require__(4576); |
| 3078 |
var isCallable = __webpack_require__(4901); |
| 3079 |
|
| 3080 |
var aFunction = function (argument) { |
| 3081 |
return isCallable(argument) ? argument : undefined; |
| 3082 |
}; |
| 3083 |
|
| 3084 |
module.exports = function (namespace, method) { |
| 3085 |
return arguments.length < 2 ? aFunction(globalThis[namespace]) : globalThis[namespace] && globalThis[namespace][method]; |
| 3086 |
}; |
| 3087 |
|
| 3088 |
|
| 3089 |
/***/ }), |
| 3090 |
|
| 3091 |
/***/ 7811: |
| 3092 |
/***/ ((module) => { |
| 3093 |
|
| 3094 |
|
| 3095 |
// eslint-disable-next-line es/no-typed-arrays -- safe |
| 3096 |
module.exports = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefined'; |
| 3097 |
|
| 3098 |
|
| 3099 |
/***/ }), |
| 3100 |
|
| 3101 |
/***/ 7936: |
| 3102 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3103 |
|
| 3104 |
|
| 3105 |
var $ = __webpack_require__(6518); |
| 3106 |
var $transfer = __webpack_require__(5636); |
| 3107 |
|
| 3108 |
// `ArrayBuffer.prototype.transferToFixedLength` method |
| 3109 |
// https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfertofixedlength |
| 3110 |
if ($transfer) $({ target: 'ArrayBuffer', proto: true }, { |
| 3111 |
transferToFixedLength: function transferToFixedLength() { |
| 3112 |
return $transfer(this, arguments.length ? arguments[0] : undefined, false); |
| 3113 |
} |
| 3114 |
}); |
| 3115 |
|
| 3116 |
|
| 3117 |
/***/ }), |
| 3118 |
|
| 3119 |
/***/ 8004: |
| 3120 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3121 |
|
| 3122 |
|
| 3123 |
var $ = __webpack_require__(6518); |
| 3124 |
var fails = __webpack_require__(9039); |
| 3125 |
var intersection = __webpack_require__(8750); |
| 3126 |
var setMethodAcceptSetLike = __webpack_require__(4916); |
| 3127 |
|
| 3128 |
var INCORRECT = !setMethodAcceptSetLike('intersection', function (result) { |
| 3129 |
return result.size === 2 && result.has(1) && result.has(2); |
| 3130 |
}) || fails(function () { |
| 3131 |
// eslint-disable-next-line es/no-array-from, es/no-set, es/no-set-prototype-intersection -- testing |
| 3132 |
return String(Array.from(new Set([1, 2, 3]).intersection(new Set([3, 2])))) !== '3,2'; |
| 3133 |
}); |
| 3134 |
|
| 3135 |
// `Set.prototype.intersection` method |
| 3136 |
// https://tc39.es/ecma262/#sec-set.prototype.intersection |
| 3137 |
$({ target: 'Set', proto: true, real: true, forced: INCORRECT }, { |
| 3138 |
intersection: intersection |
| 3139 |
}); |
| 3140 |
|
| 3141 |
|
| 3142 |
/***/ }), |
| 3143 |
|
| 3144 |
/***/ 8014: |
| 3145 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3146 |
|
| 3147 |
|
| 3148 |
var toIntegerOrInfinity = __webpack_require__(1291); |
| 3149 |
|
| 3150 |
var min = Math.min; |
| 3151 |
|
| 3152 |
// `ToLength` abstract operation |
| 3153 |
// https://tc39.es/ecma262/#sec-tolength |
| 3154 |
module.exports = function (argument) { |
| 3155 |
var len = toIntegerOrInfinity(argument); |
| 3156 |
return len > 0 ? min(len, 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991 |
| 3157 |
}; |
| 3158 |
|
| 3159 |
|
| 3160 |
/***/ }), |
| 3161 |
|
| 3162 |
/***/ 8100: |
| 3163 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3164 |
|
| 3165 |
|
| 3166 |
var $ = __webpack_require__(6518); |
| 3167 |
var $transfer = __webpack_require__(5636); |
| 3168 |
|
| 3169 |
// `ArrayBuffer.prototype.transfer` method |
| 3170 |
// https://tc39.es/proposal-arraybuffer-transfer/#sec-arraybuffer.prototype.transfer |
| 3171 |
if ($transfer) $({ target: 'ArrayBuffer', proto: true }, { |
| 3172 |
transfer: function transfer() { |
| 3173 |
return $transfer(this, arguments.length ? arguments[0] : undefined, true); |
| 3174 |
} |
| 3175 |
}); |
| 3176 |
|
| 3177 |
|
| 3178 |
/***/ }), |
| 3179 |
|
| 3180 |
/***/ 8111: |
| 3181 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3182 |
|
| 3183 |
|
| 3184 |
var $ = __webpack_require__(6518); |
| 3185 |
var globalThis = __webpack_require__(4576); |
| 3186 |
var anInstance = __webpack_require__(679); |
| 3187 |
var anObject = __webpack_require__(8551); |
| 3188 |
var isCallable = __webpack_require__(4901); |
| 3189 |
var getPrototypeOf = __webpack_require__(2787); |
| 3190 |
var defineBuiltInAccessor = __webpack_require__(2106); |
| 3191 |
var createProperty = __webpack_require__(4659); |
| 3192 |
var fails = __webpack_require__(9039); |
| 3193 |
var hasOwn = __webpack_require__(9297); |
| 3194 |
var wellKnownSymbol = __webpack_require__(8227); |
| 3195 |
var IteratorPrototype = (__webpack_require__(7657).IteratorPrototype); |
| 3196 |
var DESCRIPTORS = __webpack_require__(3724); |
| 3197 |
var IS_PURE = __webpack_require__(6395); |
| 3198 |
|
| 3199 |
var CONSTRUCTOR = 'constructor'; |
| 3200 |
var ITERATOR = 'Iterator'; |
| 3201 |
var TO_STRING_TAG = wellKnownSymbol('toStringTag'); |
| 3202 |
|
| 3203 |
var $TypeError = TypeError; |
| 3204 |
var NativeIterator = globalThis[ITERATOR]; |
| 3205 |
|
| 3206 |
// FF56- have non-standard global helper `Iterator` |
| 3207 |
var FORCED = IS_PURE |
| 3208 |
|| !isCallable(NativeIterator) |
| 3209 |
|| NativeIterator.prototype !== IteratorPrototype |
| 3210 |
// FF44- non-standard `Iterator` passes previous tests |
| 3211 |
|| !fails(function () { NativeIterator({}); }); |
| 3212 |
|
| 3213 |
var IteratorConstructor = function Iterator() { |
| 3214 |
anInstance(this, IteratorPrototype); |
| 3215 |
if (getPrototypeOf(this) === IteratorPrototype) throw new $TypeError('Abstract class Iterator not directly constructable'); |
| 3216 |
}; |
| 3217 |
|
| 3218 |
var defineIteratorPrototypeAccessor = function (key, value) { |
| 3219 |
if (DESCRIPTORS) { |
| 3220 |
defineBuiltInAccessor(IteratorPrototype, key, { |
| 3221 |
configurable: true, |
| 3222 |
get: function () { |
| 3223 |
return value; |
| 3224 |
}, |
| 3225 |
set: function (replacement) { |
| 3226 |
anObject(this); |
| 3227 |
if (this === IteratorPrototype) throw new $TypeError("You can't redefine this property"); |
| 3228 |
if (hasOwn(this, key)) this[key] = replacement; |
| 3229 |
else createProperty(this, key, replacement); |
| 3230 |
} |
| 3231 |
}); |
| 3232 |
} else IteratorPrototype[key] = value; |
| 3233 |
}; |
| 3234 |
|
| 3235 |
if (!hasOwn(IteratorPrototype, TO_STRING_TAG)) defineIteratorPrototypeAccessor(TO_STRING_TAG, ITERATOR); |
| 3236 |
|
| 3237 |
if (FORCED || !hasOwn(IteratorPrototype, CONSTRUCTOR) || IteratorPrototype[CONSTRUCTOR] === Object) { |
| 3238 |
defineIteratorPrototypeAccessor(CONSTRUCTOR, IteratorConstructor); |
| 3239 |
} |
| 3240 |
|
| 3241 |
IteratorConstructor.prototype = IteratorPrototype; |
| 3242 |
|
| 3243 |
// `Iterator` constructor |
| 3244 |
// https://tc39.es/ecma262/#sec-iterator |
| 3245 |
$({ global: true, constructor: true, forced: FORCED }, { |
| 3246 |
Iterator: IteratorConstructor |
| 3247 |
}); |
| 3248 |
|
| 3249 |
|
| 3250 |
/***/ }), |
| 3251 |
|
| 3252 |
/***/ 8227: |
| 3253 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3254 |
|
| 3255 |
|
| 3256 |
var globalThis = __webpack_require__(4576); |
| 3257 |
var shared = __webpack_require__(5745); |
| 3258 |
var hasOwn = __webpack_require__(9297); |
| 3259 |
var uid = __webpack_require__(3392); |
| 3260 |
var NATIVE_SYMBOL = __webpack_require__(4495); |
| 3261 |
var USE_SYMBOL_AS_UID = __webpack_require__(7040); |
| 3262 |
|
| 3263 |
var Symbol = globalThis.Symbol; |
| 3264 |
var WellKnownSymbolsStore = shared('wks'); |
| 3265 |
var createWellKnownSymbol = USE_SYMBOL_AS_UID ? Symbol['for'] || Symbol : Symbol && Symbol.withoutSetter || uid; |
| 3266 |
|
| 3267 |
module.exports = function (name) { |
| 3268 |
if (!hasOwn(WellKnownSymbolsStore, name)) { |
| 3269 |
WellKnownSymbolsStore[name] = NATIVE_SYMBOL && hasOwn(Symbol, name) |
| 3270 |
? Symbol[name] |
| 3271 |
: createWellKnownSymbol('Symbol.' + name); |
| 3272 |
} return WellKnownSymbolsStore[name]; |
| 3273 |
}; |
| 3274 |
|
| 3275 |
|
| 3276 |
/***/ }), |
| 3277 |
|
| 3278 |
/***/ 8235: |
| 3279 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3280 |
|
| 3281 |
|
| 3282 |
var uncurryThis = __webpack_require__(9504); |
| 3283 |
var hasOwn = __webpack_require__(9297); |
| 3284 |
|
| 3285 |
var $SyntaxError = SyntaxError; |
| 3286 |
var $parseInt = parseInt; |
| 3287 |
var fromCharCode = String.fromCharCode; |
| 3288 |
var at = uncurryThis(''.charAt); |
| 3289 |
var slice = uncurryThis(''.slice); |
| 3290 |
var exec = uncurryThis(/./.exec); |
| 3291 |
|
| 3292 |
var codePoints = { |
| 3293 |
'\\"': '"', |
| 3294 |
'\\\\': '\\', |
| 3295 |
'\\/': '/', |
| 3296 |
'\\b': '\b', |
| 3297 |
'\\f': '\f', |
| 3298 |
'\\n': '\n', |
| 3299 |
'\\r': '\r', |
| 3300 |
'\\t': '\t' |
| 3301 |
}; |
| 3302 |
|
| 3303 |
var IS_4_HEX_DIGITS = /^[\da-f]{4}$/i; |
| 3304 |
// eslint-disable-next-line regexp/no-control-character -- safe |
| 3305 |
var IS_C0_CONTROL_CODE = /^[\u0000-\u001F]$/; |
| 3306 |
|
| 3307 |
module.exports = function (source, i) { |
| 3308 |
var unterminated = true; |
| 3309 |
var value = ''; |
| 3310 |
while (i < source.length) { |
| 3311 |
var chr = at(source, i); |
| 3312 |
if (chr === '\\') { |
| 3313 |
var twoChars = slice(source, i, i + 2); |
| 3314 |
if (hasOwn(codePoints, twoChars)) { |
| 3315 |
value += codePoints[twoChars]; |
| 3316 |
i += 2; |
| 3317 |
} else if (twoChars === '\\u') { |
| 3318 |
i += 2; |
| 3319 |
var fourHexDigits = slice(source, i, i + 4); |
| 3320 |
if (!exec(IS_4_HEX_DIGITS, fourHexDigits)) throw new $SyntaxError('Bad Unicode escape at: ' + i); |
| 3321 |
value += fromCharCode($parseInt(fourHexDigits, 16)); |
| 3322 |
i += 4; |
| 3323 |
} else throw new $SyntaxError('Unknown escape sequence: "' + twoChars + '"'); |
| 3324 |
} else if (chr === '"') { |
| 3325 |
unterminated = false; |
| 3326 |
i++; |
| 3327 |
break; |
| 3328 |
} else { |
| 3329 |
if (exec(IS_C0_CONTROL_CODE, chr)) throw new $SyntaxError('Bad control character in string literal at: ' + i); |
| 3330 |
value += chr; |
| 3331 |
i++; |
| 3332 |
} |
| 3333 |
} |
| 3334 |
if (unterminated) throw new $SyntaxError('Unterminated string at: ' + i); |
| 3335 |
return { value: value, end: i }; |
| 3336 |
}; |
| 3337 |
|
| 3338 |
|
| 3339 |
/***/ }), |
| 3340 |
|
| 3341 |
/***/ 8335: |
| 3342 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3343 |
|
| 3344 |
|
| 3345 |
var $ = __webpack_require__(6518); |
| 3346 |
var DESCRIPTORS = __webpack_require__(3724); |
| 3347 |
var globalThis = __webpack_require__(4576); |
| 3348 |
var getBuiltIn = __webpack_require__(7751); |
| 3349 |
var uncurryThis = __webpack_require__(9504); |
| 3350 |
var call = __webpack_require__(9565); |
| 3351 |
var isCallable = __webpack_require__(4901); |
| 3352 |
var isObject = __webpack_require__(34); |
| 3353 |
var isArray = __webpack_require__(4376); |
| 3354 |
var hasOwn = __webpack_require__(9297); |
| 3355 |
var toString = __webpack_require__(655); |
| 3356 |
var lengthOfArrayLike = __webpack_require__(6198); |
| 3357 |
var createProperty = __webpack_require__(4659); |
| 3358 |
var fails = __webpack_require__(9039); |
| 3359 |
var parseJSONString = __webpack_require__(8235); |
| 3360 |
var NATIVE_SYMBOL = __webpack_require__(4495); |
| 3361 |
|
| 3362 |
var JSON = globalThis.JSON; |
| 3363 |
var Number = globalThis.Number; |
| 3364 |
var SyntaxError = globalThis.SyntaxError; |
| 3365 |
var nativeParse = JSON && JSON.parse; |
| 3366 |
var enumerableOwnProperties = getBuiltIn('Object', 'keys'); |
| 3367 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 3368 |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 3369 |
var at = uncurryThis(''.charAt); |
| 3370 |
var slice = uncurryThis(''.slice); |
| 3371 |
var exec = uncurryThis(/./.exec); |
| 3372 |
var push = uncurryThis([].push); |
| 3373 |
|
| 3374 |
var IS_DIGIT = /^\d$/; |
| 3375 |
var IS_NON_ZERO_DIGIT = /^[1-9]$/; |
| 3376 |
var IS_NUMBER_START = /^[\d-]$/; |
| 3377 |
var IS_WHITESPACE = /^[\t\n\r ]$/; |
| 3378 |
|
| 3379 |
var PRIMITIVE = 0; |
| 3380 |
var OBJECT = 1; |
| 3381 |
|
| 3382 |
var $parse = function (source, reviver) { |
| 3383 |
source = toString(source); |
| 3384 |
var context = new Context(source, 0, ''); |
| 3385 |
var root = context.parse(); |
| 3386 |
var value = root.value; |
| 3387 |
var endIndex = context.skip(IS_WHITESPACE, root.end); |
| 3388 |
if (endIndex < source.length) { |
| 3389 |
throw new SyntaxError('Unexpected extra character: "' + at(source, endIndex) + '" after the parsed data at: ' + endIndex); |
| 3390 |
} |
| 3391 |
return isCallable(reviver) ? internalize({ '': value }, '', reviver, root) : value; |
| 3392 |
}; |
| 3393 |
|
| 3394 |
var internalize = function (holder, name, reviver, node) { |
| 3395 |
var val = holder[name]; |
| 3396 |
var unmodified = node && val === node.value; |
| 3397 |
var context = unmodified && typeof node.source == 'string' ? { source: node.source } : {}; |
| 3398 |
var elementRecordsLen, keys, len, i, P; |
| 3399 |
if (isObject(val)) { |
| 3400 |
var nodeIsArray = isArray(val); |
| 3401 |
var nodes = unmodified ? node.nodes : nodeIsArray ? [] : {}; |
| 3402 |
if (nodeIsArray) { |
| 3403 |
elementRecordsLen = nodes.length; |
| 3404 |
len = lengthOfArrayLike(val); |
| 3405 |
for (i = 0; i < len; i++) { |
| 3406 |
internalizeProperty(val, i, internalize(val, '' + i, reviver, i < elementRecordsLen ? nodes[i] : undefined)); |
| 3407 |
} |
| 3408 |
} else { |
| 3409 |
keys = enumerableOwnProperties(val); |
| 3410 |
len = lengthOfArrayLike(keys); |
| 3411 |
for (i = 0; i < len; i++) { |
| 3412 |
P = keys[i]; |
| 3413 |
internalizeProperty(val, P, internalize(val, P, reviver, hasOwn(nodes, P) ? nodes[P] : undefined)); |
| 3414 |
} |
| 3415 |
} |
| 3416 |
} |
| 3417 |
return call(reviver, holder, name, val, context); |
| 3418 |
}; |
| 3419 |
|
| 3420 |
var internalizeProperty = function (object, key, value) { |
| 3421 |
if (DESCRIPTORS) { |
| 3422 |
var descriptor = getOwnPropertyDescriptor(object, key); |
| 3423 |
if (descriptor && !descriptor.configurable) return; |
| 3424 |
} |
| 3425 |
if (value === undefined) delete object[key]; |
| 3426 |
else createProperty(object, key, value); |
| 3427 |
}; |
| 3428 |
|
| 3429 |
var Node = function (value, end, source, nodes) { |
| 3430 |
this.value = value; |
| 3431 |
this.end = end; |
| 3432 |
this.source = source; |
| 3433 |
this.nodes = nodes; |
| 3434 |
}; |
| 3435 |
|
| 3436 |
var Context = function (source, index) { |
| 3437 |
this.source = source; |
| 3438 |
this.index = index; |
| 3439 |
}; |
| 3440 |
|
| 3441 |
// https://www.json.org/json-en.html |
| 3442 |
Context.prototype = { |
| 3443 |
fork: function (nextIndex) { |
| 3444 |
return new Context(this.source, nextIndex); |
| 3445 |
}, |
| 3446 |
parse: function () { |
| 3447 |
var source = this.source; |
| 3448 |
var i = this.skip(IS_WHITESPACE, this.index); |
| 3449 |
var fork = this.fork(i); |
| 3450 |
var chr = at(source, i); |
| 3451 |
if (exec(IS_NUMBER_START, chr)) return fork.number(); |
| 3452 |
switch (chr) { |
| 3453 |
case '{': |
| 3454 |
return fork.object(); |
| 3455 |
case '[': |
| 3456 |
return fork.array(); |
| 3457 |
case '"': |
| 3458 |
return fork.string(); |
| 3459 |
case 't': |
| 3460 |
return fork.keyword(true); |
| 3461 |
case 'f': |
| 3462 |
return fork.keyword(false); |
| 3463 |
case 'n': |
| 3464 |
return fork.keyword(null); |
| 3465 |
} throw new SyntaxError('Unexpected character: "' + chr + '" at: ' + i); |
| 3466 |
}, |
| 3467 |
node: function (type, value, start, end, nodes) { |
| 3468 |
return new Node(value, end, type ? null : slice(this.source, start, end), nodes); |
| 3469 |
}, |
| 3470 |
object: function () { |
| 3471 |
var source = this.source; |
| 3472 |
var i = this.index + 1; |
| 3473 |
var expectKeypair = false; |
| 3474 |
var object = {}; |
| 3475 |
var nodes = {}; |
| 3476 |
while (i < source.length) { |
| 3477 |
i = this.until(['"', '}'], i); |
| 3478 |
if (at(source, i) === '}' && !expectKeypair) { |
| 3479 |
i++; |
| 3480 |
break; |
| 3481 |
} |
| 3482 |
// Parsing the key |
| 3483 |
var result = this.fork(i).string(); |
| 3484 |
var key = result.value; |
| 3485 |
i = result.end; |
| 3486 |
i = this.until([':'], i) + 1; |
| 3487 |
// Parsing value |
| 3488 |
i = this.skip(IS_WHITESPACE, i); |
| 3489 |
result = this.fork(i).parse(); |
| 3490 |
createProperty(nodes, key, result); |
| 3491 |
createProperty(object, key, result.value); |
| 3492 |
i = this.until([',', '}'], result.end); |
| 3493 |
var chr = at(source, i); |
| 3494 |
if (chr === ',') { |
| 3495 |
expectKeypair = true; |
| 3496 |
i++; |
| 3497 |
} else if (chr === '}') { |
| 3498 |
i++; |
| 3499 |
break; |
| 3500 |
} |
| 3501 |
} |
| 3502 |
return this.node(OBJECT, object, this.index, i, nodes); |
| 3503 |
}, |
| 3504 |
array: function () { |
| 3505 |
var source = this.source; |
| 3506 |
var i = this.index + 1; |
| 3507 |
var expectElement = false; |
| 3508 |
var array = []; |
| 3509 |
var nodes = []; |
| 3510 |
while (i < source.length) { |
| 3511 |
i = this.skip(IS_WHITESPACE, i); |
| 3512 |
if (at(source, i) === ']' && !expectElement) { |
| 3513 |
i++; |
| 3514 |
break; |
| 3515 |
} |
| 3516 |
var result = this.fork(i).parse(); |
| 3517 |
push(nodes, result); |
| 3518 |
push(array, result.value); |
| 3519 |
i = this.until([',', ']'], result.end); |
| 3520 |
if (at(source, i) === ',') { |
| 3521 |
expectElement = true; |
| 3522 |
i++; |
| 3523 |
} else if (at(source, i) === ']') { |
| 3524 |
i++; |
| 3525 |
break; |
| 3526 |
} |
| 3527 |
} |
| 3528 |
return this.node(OBJECT, array, this.index, i, nodes); |
| 3529 |
}, |
| 3530 |
string: function () { |
| 3531 |
var index = this.index; |
| 3532 |
var parsed = parseJSONString(this.source, this.index + 1); |
| 3533 |
return this.node(PRIMITIVE, parsed.value, index, parsed.end); |
| 3534 |
}, |
| 3535 |
number: function () { |
| 3536 |
var source = this.source; |
| 3537 |
var startIndex = this.index; |
| 3538 |
var i = startIndex; |
| 3539 |
if (at(source, i) === '-') i++; |
| 3540 |
if (at(source, i) === '0') i++; |
| 3541 |
else if (exec(IS_NON_ZERO_DIGIT, at(source, i))) i = this.skip(IS_DIGIT, i + 1); |
| 3542 |
else throw new SyntaxError('Failed to parse number at: ' + i); |
| 3543 |
if (at(source, i) === '.') i = this.skip(IS_DIGIT, i + 1); |
| 3544 |
if (at(source, i) === 'e' || at(source, i) === 'E') { |
| 3545 |
i++; |
| 3546 |
if (at(source, i) === '+' || at(source, i) === '-') i++; |
| 3547 |
var exponentStartIndex = i; |
| 3548 |
i = this.skip(IS_DIGIT, i); |
| 3549 |
if (exponentStartIndex === i) throw new SyntaxError("Failed to parse number's exponent value at: " + i); |
| 3550 |
} |
| 3551 |
return this.node(PRIMITIVE, Number(slice(source, startIndex, i)), startIndex, i); |
| 3552 |
}, |
| 3553 |
keyword: function (value) { |
| 3554 |
var keyword = '' + value; |
| 3555 |
var index = this.index; |
| 3556 |
var endIndex = index + keyword.length; |
| 3557 |
if (slice(this.source, index, endIndex) !== keyword) throw new SyntaxError('Failed to parse value at: ' + index); |
| 3558 |
return this.node(PRIMITIVE, value, index, endIndex); |
| 3559 |
}, |
| 3560 |
skip: function (regex, i) { |
| 3561 |
var source = this.source; |
| 3562 |
for (; i < source.length; i++) if (!exec(regex, at(source, i))) break; |
| 3563 |
return i; |
| 3564 |
}, |
| 3565 |
until: function (array, i) { |
| 3566 |
i = this.skip(IS_WHITESPACE, i); |
| 3567 |
var chr = at(this.source, i); |
| 3568 |
for (var j = 0; j < array.length; j++) if (array[j] === chr) return i; |
| 3569 |
throw new SyntaxError('Unexpected character: "' + chr + '" at: ' + i); |
| 3570 |
} |
| 3571 |
}; |
| 3572 |
|
| 3573 |
var NO_SOURCE_SUPPORT = fails(function () { |
| 3574 |
var unsafeInt = '9007199254740993'; |
| 3575 |
var source; |
| 3576 |
nativeParse(unsafeInt, function (key, value, context) { |
| 3577 |
source = context.source; |
| 3578 |
}); |
| 3579 |
return source !== unsafeInt; |
| 3580 |
}); |
| 3581 |
|
| 3582 |
var PROPER_BASE_PARSE = NATIVE_SYMBOL && !fails(function () { |
| 3583 |
// Safari 9 bug |
| 3584 |
return 1 / nativeParse('-0 \t') !== -Infinity; |
| 3585 |
}); |
| 3586 |
|
| 3587 |
// `JSON.parse` method |
| 3588 |
// https://tc39.es/ecma262/#sec-json.parse |
| 3589 |
// https://github.com/tc39/proposal-json-parse-with-source |
| 3590 |
$({ target: 'JSON', stat: true, forced: NO_SOURCE_SUPPORT }, { |
| 3591 |
parse: function parse(text, reviver) { |
| 3592 |
return PROPER_BASE_PARSE && !isCallable(reviver) ? nativeParse(text) : $parse(text, reviver); |
| 3593 |
} |
| 3594 |
}); |
| 3595 |
|
| 3596 |
|
| 3597 |
/***/ }), |
| 3598 |
|
| 3599 |
/***/ 8469: |
| 3600 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3601 |
|
| 3602 |
|
| 3603 |
var uncurryThis = __webpack_require__(9504); |
| 3604 |
var iterateSimple = __webpack_require__(507); |
| 3605 |
var SetHelpers = __webpack_require__(4402); |
| 3606 |
|
| 3607 |
var Set = SetHelpers.Set; |
| 3608 |
var SetPrototype = SetHelpers.proto; |
| 3609 |
var forEach = uncurryThis(SetPrototype.forEach); |
| 3610 |
var keys = uncurryThis(SetPrototype.keys); |
| 3611 |
var next = keys(new Set()).next; |
| 3612 |
|
| 3613 |
module.exports = function (set, fn, interruptible) { |
| 3614 |
return interruptible ? iterateSimple({ iterator: keys(set), next: next }, fn) : forEach(set, fn); |
| 3615 |
}; |
| 3616 |
|
| 3617 |
|
| 3618 |
/***/ }), |
| 3619 |
|
| 3620 |
/***/ 8480: |
| 3621 |
/***/ ((__unused_webpack_module, exports, __webpack_require__) => { |
| 3622 |
|
| 3623 |
|
| 3624 |
var internalObjectKeys = __webpack_require__(1828); |
| 3625 |
var enumBugKeys = __webpack_require__(8727); |
| 3626 |
|
| 3627 |
var hiddenKeys = enumBugKeys.concat('length', 'prototype'); |
| 3628 |
|
| 3629 |
// `Object.getOwnPropertyNames` method |
| 3630 |
// https://tc39.es/ecma262/#sec-object.getownpropertynames |
| 3631 |
// eslint-disable-next-line es/no-object-getownpropertynames -- safe |
| 3632 |
exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { |
| 3633 |
return internalObjectKeys(O, hiddenKeys); |
| 3634 |
}; |
| 3635 |
|
| 3636 |
|
| 3637 |
/***/ }), |
| 3638 |
|
| 3639 |
/***/ 8527: |
| 3640 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3641 |
|
| 3642 |
|
| 3643 |
var aSet = __webpack_require__(7080); |
| 3644 |
var has = (__webpack_require__(4402).has); |
| 3645 |
var size = __webpack_require__(5170); |
| 3646 |
var getSetRecord = __webpack_require__(3789); |
| 3647 |
var iterateSimple = __webpack_require__(507); |
| 3648 |
var iteratorClose = __webpack_require__(9539); |
| 3649 |
|
| 3650 |
// `Set.prototype.isSupersetOf` method |
| 3651 |
// https://tc39.github.io/proposal-set-methods/#Set.prototype.isSupersetOf |
| 3652 |
module.exports = function isSupersetOf(other) { |
| 3653 |
var O = aSet(this); |
| 3654 |
var otherRec = getSetRecord(other); |
| 3655 |
if (size(O) < otherRec.size) return false; |
| 3656 |
var iterator = otherRec.getIterator(); |
| 3657 |
return iterateSimple(iterator, function (e) { |
| 3658 |
if (!has(O, e)) return iteratorClose(iterator, 'normal', false); |
| 3659 |
}) !== false; |
| 3660 |
}; |
| 3661 |
|
| 3662 |
|
| 3663 |
/***/ }), |
| 3664 |
|
| 3665 |
/***/ 8551: |
| 3666 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3667 |
|
| 3668 |
|
| 3669 |
var isObject = __webpack_require__(34); |
| 3670 |
|
| 3671 |
var $String = String; |
| 3672 |
var $TypeError = TypeError; |
| 3673 |
|
| 3674 |
// `Assert: Type(argument) is Object` |
| 3675 |
module.exports = function (argument) { |
| 3676 |
if (isObject(argument)) return argument; |
| 3677 |
throw new $TypeError($String(argument) + ' is not an object'); |
| 3678 |
}; |
| 3679 |
|
| 3680 |
|
| 3681 |
/***/ }), |
| 3682 |
|
| 3683 |
/***/ 8622: |
| 3684 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3685 |
|
| 3686 |
|
| 3687 |
var globalThis = __webpack_require__(4576); |
| 3688 |
var isCallable = __webpack_require__(4901); |
| 3689 |
|
| 3690 |
var WeakMap = globalThis.WeakMap; |
| 3691 |
|
| 3692 |
module.exports = isCallable(WeakMap) && /native code/.test(String(WeakMap)); |
| 3693 |
|
| 3694 |
|
| 3695 |
/***/ }), |
| 3696 |
|
| 3697 |
/***/ 8686: |
| 3698 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3699 |
|
| 3700 |
|
| 3701 |
var DESCRIPTORS = __webpack_require__(3724); |
| 3702 |
var fails = __webpack_require__(9039); |
| 3703 |
|
| 3704 |
// V8 ~ Chrome 36- |
| 3705 |
// https://bugs.chromium.org/p/v8/issues/detail?id=3334 |
| 3706 |
module.exports = DESCRIPTORS && fails(function () { |
| 3707 |
// eslint-disable-next-line es/no-object-defineproperty -- required for testing |
| 3708 |
return Object.defineProperty(function () { /* empty */ }, 'prototype', { |
| 3709 |
value: 42, |
| 3710 |
writable: false |
| 3711 |
}).prototype !== 42; |
| 3712 |
}); |
| 3713 |
|
| 3714 |
|
| 3715 |
/***/ }), |
| 3716 |
|
| 3717 |
/***/ 8721: |
| 3718 |
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => { |
| 3719 |
|
| 3720 |
|
| 3721 |
var DESCRIPTORS = __webpack_require__(3724); |
| 3722 |
var uncurryThis = __webpack_require__(9504); |
| 3723 |
var defineBuiltInAccessor = __webpack_require__(2106); |
| 3724 |
|
| 3725 |
var URLSearchParamsPrototype = URLSearchParams.prototype; |
| 3726 |
var forEach = uncurryThis(URLSearchParamsPrototype.forEach); |
| 3727 |
|
| 3728 |
// `URLSearchParams.prototype.size` getter |
| 3729 |
// https://github.com/whatwg/url/pull/734 |
| 3730 |
if (DESCRIPTORS && !('size' in URLSearchParamsPrototype)) { |
| 3731 |
defineBuiltInAccessor(URLSearchParamsPrototype, 'size', { |
| 3732 |
get: function size() { |
| 3733 |
var count = 0; |
| 3734 |
forEach(this, function () { count++; }); |
| 3735 |
return count; |
| 3736 |
}, |
| 3737 |
configurable: true, |
| 3738 |
enumerable: true |
| 3739 |
}); |
| 3740 |
} |
| 3741 |
|
| 3742 |
|
| 3743 |
/***/ }), |
| 3744 |
|
| 3745 |
/***/ 8727: |
| 3746 |
/***/ ((module) => { |
| 3747 |
|
| 3748 |
|
| 3749 |
// IE8- don't enum bug keys |
| 3750 |
module.exports = [ |
| 3751 |
'constructor', |
| 3752 |
'hasOwnProperty', |
| 3753 |
'isPrototypeOf', |
| 3754 |
'propertyIsEnumerable', |
| 3755 |
'toLocaleString', |
| 3756 |
'toString', |
| 3757 |
'valueOf' |
| 3758 |
]; |
| 3759 |
|
| 3760 |
|
| 3761 |
/***/ }), |
| 3762 |
|
| 3763 |
/***/ 8750: |
| 3764 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3765 |
|
| 3766 |
|
| 3767 |
var aSet = __webpack_require__(7080); |
| 3768 |
var SetHelpers = __webpack_require__(4402); |
| 3769 |
var size = __webpack_require__(5170); |
| 3770 |
var getSetRecord = __webpack_require__(3789); |
| 3771 |
var iterateSet = __webpack_require__(8469); |
| 3772 |
var iterateSimple = __webpack_require__(507); |
| 3773 |
|
| 3774 |
var Set = SetHelpers.Set; |
| 3775 |
var add = SetHelpers.add; |
| 3776 |
var has = SetHelpers.has; |
| 3777 |
|
| 3778 |
// `Set.prototype.intersection` method |
| 3779 |
// https://github.com/tc39/proposal-set-methods |
| 3780 |
module.exports = function intersection(other) { |
| 3781 |
var O = aSet(this); |
| 3782 |
var otherRec = getSetRecord(other); |
| 3783 |
var result = new Set(); |
| 3784 |
|
| 3785 |
if (size(O) > otherRec.size) { |
| 3786 |
iterateSimple(otherRec.getIterator(), function (e) { |
| 3787 |
if (has(O, e)) add(result, e); |
| 3788 |
}); |
| 3789 |
} else { |
| 3790 |
iterateSet(O, function (e) { |
| 3791 |
if (otherRec.includes(e)) add(result, e); |
| 3792 |
}); |
| 3793 |
} |
| 3794 |
|
| 3795 |
return result; |
| 3796 |
}; |
| 3797 |
|
| 3798 |
|
| 3799 |
/***/ }), |
| 3800 |
|
| 3801 |
/***/ 8773: |
| 3802 |
/***/ ((__unused_webpack_module, exports) => { |
| 3803 |
|
| 3804 |
|
| 3805 |
var $propertyIsEnumerable = {}.propertyIsEnumerable; |
| 3806 |
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe |
| 3807 |
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 3808 |
|
| 3809 |
// Nashorn ~ JDK8 bug |
| 3810 |
var NASHORN_BUG = getOwnPropertyDescriptor && !$propertyIsEnumerable.call({ 1: 2 }, 1); |
| 3811 |
|
| 3812 |
// `Object.prototype.propertyIsEnumerable` method implementation |
| 3813 |
// https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable |
| 3814 |
exports.f = NASHORN_BUG ? function propertyIsEnumerable(V) { |
| 3815 |
var descriptor = getOwnPropertyDescriptor(this, V); |
| 3816 |
return !!descriptor && descriptor.enumerable; |
| 3817 |
} : $propertyIsEnumerable; |
| 3818 |
|
| 3819 |
|
| 3820 |
/***/ }), |
| 3821 |
|
| 3822 |
/***/ 8981: |
| 3823 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3824 |
|
| 3825 |
|
| 3826 |
var requireObjectCoercible = __webpack_require__(7750); |
| 3827 |
|
| 3828 |
var $Object = Object; |
| 3829 |
|
| 3830 |
// `ToObject` abstract operation |
| 3831 |
// https://tc39.es/ecma262/#sec-toobject |
| 3832 |
module.exports = function (argument) { |
| 3833 |
return $Object(requireObjectCoercible(argument)); |
| 3834 |
}; |
| 3835 |
|
| 3836 |
|
| 3837 |
/***/ }), |
| 3838 |
|
| 3839 |
/***/ 9039: |
| 3840 |
/***/ ((module) => { |
| 3841 |
|
| 3842 |
|
| 3843 |
module.exports = function (exec) { |
| 3844 |
try { |
| 3845 |
return !!exec(); |
| 3846 |
} catch (error) { |
| 3847 |
return true; |
| 3848 |
} |
| 3849 |
}; |
| 3850 |
|
| 3851 |
|
| 3852 |
/***/ }), |
| 3853 |
|
| 3854 |
/***/ 9286: |
| 3855 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3856 |
|
| 3857 |
|
| 3858 |
var SetHelpers = __webpack_require__(4402); |
| 3859 |
var iterate = __webpack_require__(8469); |
| 3860 |
|
| 3861 |
var Set = SetHelpers.Set; |
| 3862 |
var add = SetHelpers.add; |
| 3863 |
|
| 3864 |
module.exports = function (set) { |
| 3865 |
var result = new Set(); |
| 3866 |
iterate(set, function (it) { |
| 3867 |
add(result, it); |
| 3868 |
}); |
| 3869 |
return result; |
| 3870 |
}; |
| 3871 |
|
| 3872 |
|
| 3873 |
/***/ }), |
| 3874 |
|
| 3875 |
/***/ 9297: |
| 3876 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3877 |
|
| 3878 |
|
| 3879 |
var uncurryThis = __webpack_require__(9504); |
| 3880 |
var toObject = __webpack_require__(8981); |
| 3881 |
|
| 3882 |
var hasOwnProperty = uncurryThis({}.hasOwnProperty); |
| 3883 |
|
| 3884 |
// `HasOwnProperty` abstract operation |
| 3885 |
// https://tc39.es/ecma262/#sec-hasownproperty |
| 3886 |
// eslint-disable-next-line es/no-object-hasown -- safe |
| 3887 |
module.exports = Object.hasOwn || function hasOwn(it, key) { |
| 3888 |
return hasOwnProperty(toObject(it), key); |
| 3889 |
}; |
| 3890 |
|
| 3891 |
|
| 3892 |
/***/ }), |
| 3893 |
|
| 3894 |
/***/ 9306: |
| 3895 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3896 |
|
| 3897 |
|
| 3898 |
var isCallable = __webpack_require__(4901); |
| 3899 |
var tryToString = __webpack_require__(6823); |
| 3900 |
|
| 3901 |
var $TypeError = TypeError; |
| 3902 |
|
| 3903 |
// `Assert: IsCallable(argument) is true` |
| 3904 |
module.exports = function (argument) { |
| 3905 |
if (isCallable(argument)) return argument; |
| 3906 |
throw new $TypeError(tryToString(argument) + ' is not a function'); |
| 3907 |
}; |
| 3908 |
|
| 3909 |
|
| 3910 |
/***/ }), |
| 3911 |
|
| 3912 |
/***/ 9429: |
| 3913 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3914 |
|
| 3915 |
|
| 3916 |
var globalThis = __webpack_require__(4576); |
| 3917 |
var IS_NODE = __webpack_require__(6193); |
| 3918 |
|
| 3919 |
module.exports = function (name) { |
| 3920 |
if (IS_NODE) { |
| 3921 |
try { |
| 3922 |
return globalThis.process.getBuiltinModule(name); |
| 3923 |
} catch (error) { /* empty */ } |
| 3924 |
try { |
| 3925 |
// eslint-disable-next-line no-new-func -- safe |
| 3926 |
return Function('return require("' + name + '")')(); |
| 3927 |
} catch (error) { /* empty */ } |
| 3928 |
} |
| 3929 |
}; |
| 3930 |
|
| 3931 |
|
| 3932 |
/***/ }), |
| 3933 |
|
| 3934 |
/***/ 9433: |
| 3935 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3936 |
|
| 3937 |
|
| 3938 |
var globalThis = __webpack_require__(4576); |
| 3939 |
|
| 3940 |
// eslint-disable-next-line es/no-object-defineproperty -- safe |
| 3941 |
var defineProperty = Object.defineProperty; |
| 3942 |
|
| 3943 |
module.exports = function (key, value) { |
| 3944 |
try { |
| 3945 |
defineProperty(globalThis, key, { value: value, configurable: true, writable: true }); |
| 3946 |
} catch (error) { |
| 3947 |
globalThis[key] = value; |
| 3948 |
} return value; |
| 3949 |
}; |
| 3950 |
|
| 3951 |
|
| 3952 |
/***/ }), |
| 3953 |
|
| 3954 |
/***/ 9462: |
| 3955 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 3956 |
|
| 3957 |
|
| 3958 |
var call = __webpack_require__(9565); |
| 3959 |
var create = __webpack_require__(2360); |
| 3960 |
var createNonEnumerableProperty = __webpack_require__(6699); |
| 3961 |
var defineBuiltIns = __webpack_require__(6279); |
| 3962 |
var wellKnownSymbol = __webpack_require__(8227); |
| 3963 |
var InternalStateModule = __webpack_require__(1181); |
| 3964 |
var getMethod = __webpack_require__(5966); |
| 3965 |
var IteratorPrototype = (__webpack_require__(7657).IteratorPrototype); |
| 3966 |
var createIterResultObject = __webpack_require__(2529); |
| 3967 |
var iteratorClose = __webpack_require__(9539); |
| 3968 |
|
| 3969 |
var TO_STRING_TAG = wellKnownSymbol('toStringTag'); |
| 3970 |
var ITERATOR_HELPER = 'IteratorHelper'; |
| 3971 |
var WRAP_FOR_VALID_ITERATOR = 'WrapForValidIterator'; |
| 3972 |
var setInternalState = InternalStateModule.set; |
| 3973 |
|
| 3974 |
var createIteratorProxyPrototype = function (IS_ITERATOR) { |
| 3975 |
var getInternalState = InternalStateModule.getterFor(IS_ITERATOR ? WRAP_FOR_VALID_ITERATOR : ITERATOR_HELPER); |
| 3976 |
|
| 3977 |
return defineBuiltIns(create(IteratorPrototype), { |
| 3978 |
next: function next() { |
| 3979 |
var state = getInternalState(this); |
| 3980 |
// for simplification: |
| 3981 |
// for `%WrapForValidIteratorPrototype%.next` or with `state.returnHandlerResult` our `nextHandler` returns `IterResultObject` |
| 3982 |
// for `%IteratorHelperPrototype%.next` - just a value |
| 3983 |
if (IS_ITERATOR) return state.nextHandler(); |
| 3984 |
if (state.done) return createIterResultObject(undefined, true); |
| 3985 |
try { |
| 3986 |
var result = state.nextHandler(); |
| 3987 |
return state.returnHandlerResult ? result : createIterResultObject(result, state.done); |
| 3988 |
} catch (error) { |
| 3989 |
state.done = true; |
| 3990 |
throw error; |
| 3991 |
} |
| 3992 |
}, |
| 3993 |
'return': function () { |
| 3994 |
var state = getInternalState(this); |
| 3995 |
var iterator = state.iterator; |
| 3996 |
state.done = true; |
| 3997 |
if (IS_ITERATOR) { |
| 3998 |
var returnMethod = getMethod(iterator, 'return'); |
| 3999 |
return returnMethod ? call(returnMethod, iterator) : createIterResultObject(undefined, true); |
| 4000 |
} |
| 4001 |
if (state.inner) try { |
| 4002 |
iteratorClose(state.inner.iterator, 'normal'); |
| 4003 |
} catch (error) { |
| 4004 |
return iteratorClose(iterator, 'throw', error); |
| 4005 |
} |
| 4006 |
if (iterator) iteratorClose(iterator, 'normal'); |
| 4007 |
return createIterResultObject(undefined, true); |
| 4008 |
} |
| 4009 |
}); |
| 4010 |
}; |
| 4011 |
|
| 4012 |
var WrapForValidIteratorPrototype = createIteratorProxyPrototype(true); |
| 4013 |
var IteratorHelperPrototype = createIteratorProxyPrototype(false); |
| 4014 |
|
| 4015 |
createNonEnumerableProperty(IteratorHelperPrototype, TO_STRING_TAG, 'Iterator Helper'); |
| 4016 |
|
| 4017 |
module.exports = function (nextHandler, IS_ITERATOR, RETURN_HANDLER_RESULT) { |
| 4018 |
var IteratorProxy = function Iterator(record, state) { |
| 4019 |
if (state) { |
| 4020 |
state.iterator = record.iterator; |
| 4021 |
state.next = record.next; |
| 4022 |
} else state = record; |
| 4023 |
state.type = IS_ITERATOR ? WRAP_FOR_VALID_ITERATOR : ITERATOR_HELPER; |
| 4024 |
state.returnHandlerResult = !!RETURN_HANDLER_RESULT; |
| 4025 |
state.nextHandler = nextHandler; |
| 4026 |
state.counter = 0; |
| 4027 |
state.done = false; |
| 4028 |
setInternalState(this, state); |
| 4029 |
}; |
| 4030 |
|
| 4031 |
IteratorProxy.prototype = IS_ITERATOR ? WrapForValidIteratorPrototype : IteratorHelperPrototype; |
| 4032 |
|
| 4033 |
return IteratorProxy; |
| 4034 |
}; |
| 4035 |
|
| 4036 |
|
| 4037 |
/***/ }), |
| 4038 |
|
| 4039 |
/***/ 9504: |
| 4040 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 4041 |
|
| 4042 |
|
| 4043 |
var NATIVE_BIND = __webpack_require__(616); |
| 4044 |
|
| 4045 |
var FunctionPrototype = Function.prototype; |
| 4046 |
var call = FunctionPrototype.call; |
| 4047 |
// eslint-disable-next-line es/no-function-prototype-bind -- safe |
| 4048 |
var uncurryThisWithBind = NATIVE_BIND && FunctionPrototype.bind.bind(call, call); |
| 4049 |
|
| 4050 |
module.exports = NATIVE_BIND ? uncurryThisWithBind : function (fn) { |
| 4051 |
return function () { |
| 4052 |
return call.apply(fn, arguments); |
| 4053 |
}; |
| 4054 |
}; |
| 4055 |
|
| 4056 |
|
| 4057 |
/***/ }), |
| 4058 |
|
| 4059 |
/***/ 9519: |
| 4060 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 4061 |
|
| 4062 |
|
| 4063 |
var globalThis = __webpack_require__(4576); |
| 4064 |
var userAgent = __webpack_require__(2839); |
| 4065 |
|
| 4066 |
var process = globalThis.process; |
| 4067 |
var Deno = globalThis.Deno; |
| 4068 |
var versions = process && process.versions || Deno && Deno.version; |
| 4069 |
var v8 = versions && versions.v8; |
| 4070 |
var match, version; |
| 4071 |
|
| 4072 |
if (v8) { |
| 4073 |
match = v8.split('.'); |
| 4074 |
// in old Chrome, versions of V8 isn't V8 = Chrome / 10 |
| 4075 |
// but their correct versions are not interesting for us |
| 4076 |
version = match[0] > 0 && match[0] < 4 ? 1 : +(match[0] + match[1]); |
| 4077 |
} |
| 4078 |
|
| 4079 |
// BrowserFS NodeJS `process` polyfill incorrectly set `.v8` to `0.0` |
| 4080 |
// so check `userAgent` even if `.v8` exists, but 0 |
| 4081 |
if (!version && userAgent) { |
| 4082 |
match = userAgent.match(/Edge\/(\d+)/); |
| 4083 |
if (!match || match[1] >= 74) { |
| 4084 |
match = userAgent.match(/Chrome\/(\d+)/); |
| 4085 |
if (match) version = +match[1]; |
| 4086 |
} |
| 4087 |
} |
| 4088 |
|
| 4089 |
module.exports = version; |
| 4090 |
|
| 4091 |
|
| 4092 |
/***/ }), |
| 4093 |
|
| 4094 |
/***/ 9539: |
| 4095 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 4096 |
|
| 4097 |
|
| 4098 |
var call = __webpack_require__(9565); |
| 4099 |
var anObject = __webpack_require__(8551); |
| 4100 |
var getMethod = __webpack_require__(5966); |
| 4101 |
|
| 4102 |
module.exports = function (iterator, kind, value) { |
| 4103 |
var innerResult, innerError; |
| 4104 |
anObject(iterator); |
| 4105 |
try { |
| 4106 |
innerResult = getMethod(iterator, 'return'); |
| 4107 |
if (!innerResult) { |
| 4108 |
if (kind === 'throw') throw value; |
| 4109 |
return value; |
| 4110 |
} |
| 4111 |
innerResult = call(innerResult, iterator); |
| 4112 |
} catch (error) { |
| 4113 |
innerError = true; |
| 4114 |
innerResult = error; |
| 4115 |
} |
| 4116 |
if (kind === 'throw') throw value; |
| 4117 |
if (innerError) throw innerResult; |
| 4118 |
anObject(innerResult); |
| 4119 |
return value; |
| 4120 |
}; |
| 4121 |
|
| 4122 |
|
| 4123 |
/***/ }), |
| 4124 |
|
| 4125 |
/***/ 9565: |
| 4126 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 4127 |
|
| 4128 |
|
| 4129 |
var NATIVE_BIND = __webpack_require__(616); |
| 4130 |
|
| 4131 |
var call = Function.prototype.call; |
| 4132 |
// eslint-disable-next-line es/no-function-prototype-bind -- safe |
| 4133 |
module.exports = NATIVE_BIND ? call.bind(call) : function () { |
| 4134 |
return call.apply(call, arguments); |
| 4135 |
}; |
| 4136 |
|
| 4137 |
|
| 4138 |
/***/ }), |
| 4139 |
|
| 4140 |
/***/ 9617: |
| 4141 |
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { |
| 4142 |
|
| 4143 |
|
| 4144 |
var toIndexedObject = __webpack_require__(5397); |
| 4145 |
var toAbsoluteIndex = __webpack_require__(5610); |
| 4146 |
var lengthOfArrayLike = __webpack_require__(6198); |
| 4147 |
|
| 4148 |
// `Array.prototype.{ indexOf, includes }` methods implementation |
| 4149 |
var createMethod = function (IS_INCLUDES) { |
| 4150 |
return function ($this, el, fromIndex) { |
| 4151 |
var O = toIndexedObject($this); |
| 4152 |
var length = lengthOfArrayLike(O); |
| 4153 |
if (length === 0) return !IS_INCLUDES && -1; |
| 4154 |
var index = toAbsoluteIndex(fromIndex, length); |
| 4155 |
var value; |
| 4156 |
// Array#includes uses SameValueZero equality algorithm |
| 4157 |
// eslint-disable-next-line no-self-compare -- NaN check |
| 4158 |
if (IS_INCLUDES && el !== el) while (length > index) { |
| 4159 |
value = O[index++]; |
| 4160 |
// eslint-disable-next-line no-self-compare -- NaN check |
| 4161 |
if (value !== value) return true; |
| 4162 |
// Array#indexOf ignores holes, Array#includes - not |
| 4163 |
} else for (;length > index; index++) { |
| 4164 |
if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0; |
| 4165 |
} return !IS_INCLUDES && -1; |
| 4166 |
}; |
| 4167 |
}; |
| 4168 |
|
| 4169 |
module.exports = { |
| 4170 |
// `Array.prototype.includes` method |
| 4171 |
// https://tc39.es/ecma262/#sec-array.prototype.includes |
| 4172 |
includes: createMethod(true), |
| 4173 |
// `Array.prototype.indexOf` method |
| 4174 |
// https://tc39.es/ecma262/#sec-array.prototype.indexof |
| 4175 |
indexOf: createMethod(false) |
| 4176 |
}; |
| 4177 |
|
| 4178 |
|
| 4179 |
/***/ }) |
| 4180 |
|
| 4181 |
/******/ }); |
| 4182 |
/************************************************************************/ |
| 4183 |
/******/ // The module cache |
| 4184 |
/******/ var __webpack_module_cache__ = {}; |
| 4185 |
/******/ |
| 4186 |
/******/ // The require function |
| 4187 |
/******/ function __webpack_require__(moduleId) { |
| 4188 |
/******/ // Check if module is in cache |
| 4189 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 4190 |
/******/ if (cachedModule !== undefined) { |
| 4191 |
/******/ return cachedModule.exports; |
| 4192 |
/******/ } |
| 4193 |
/******/ // Create a new module (and put it into the cache) |
| 4194 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 4195 |
/******/ // no module.id needed |
| 4196 |
/******/ // no module.loaded needed |
| 4197 |
/******/ exports: {} |
| 4198 |
/******/ }; |
| 4199 |
/******/ |
| 4200 |
/******/ // Execute the module function |
| 4201 |
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 4202 |
/******/ |
| 4203 |
/******/ // Return the exports of the module |
| 4204 |
/******/ return module.exports; |
| 4205 |
/******/ } |
| 4206 |
/******/ |
| 4207 |
/************************************************************************/ |
| 4208 |
var __webpack_exports__ = {}; |
| 4209 |
|
| 4210 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.push.js |
| 4211 |
var es_array_push = __webpack_require__(4114); |
| 4212 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.difference.v2.js |
| 4213 |
var es_set_difference_v2 = __webpack_require__(7642); |
| 4214 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.intersection.v2.js |
| 4215 |
var es_set_intersection_v2 = __webpack_require__(8004); |
| 4216 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-disjoint-from.v2.js |
| 4217 |
var es_set_is_disjoint_from_v2 = __webpack_require__(3853); |
| 4218 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-subset-of.v2.js |
| 4219 |
var es_set_is_subset_of_v2 = __webpack_require__(5876); |
| 4220 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.is-superset-of.v2.js |
| 4221 |
var es_set_is_superset_of_v2 = __webpack_require__(2475); |
| 4222 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.symmetric-difference.v2.js |
| 4223 |
var es_set_symmetric_difference_v2 = __webpack_require__(5024); |
| 4224 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.set.union.v2.js |
| 4225 |
var es_set_union_v2 = __webpack_require__(1698); |
| 4226 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.delete.js |
| 4227 |
var web_url_search_params_delete = __webpack_require__(4603); |
| 4228 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.has.js |
| 4229 |
var web_url_search_params_has = __webpack_require__(7566); |
| 4230 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/web.url-search-params.size.js |
| 4231 |
var web_url_search_params_size = __webpack_require__(8721); |
| 4232 |
;// ./web/pdfjs.js |
| 4233 |
const { |
| 4234 |
AbortException, |
| 4235 |
AnnotationEditorLayer, |
| 4236 |
AnnotationEditorParamsType, |
| 4237 |
AnnotationEditorType, |
| 4238 |
AnnotationEditorUIManager, |
| 4239 |
AnnotationLayer, |
| 4240 |
AnnotationMode, |
| 4241 |
AnnotationType, |
| 4242 |
build, |
| 4243 |
ColorPicker, |
| 4244 |
createValidAbsoluteUrl, |
| 4245 |
DOMSVGFactory, |
| 4246 |
DrawLayer, |
| 4247 |
FeatureTest, |
| 4248 |
fetchData, |
| 4249 |
getDocument, |
| 4250 |
getFilenameFromUrl, |
| 4251 |
getPdfFilenameFromUrl: pdfjs_getPdfFilenameFromUrl, |
| 4252 |
getUuid, |
| 4253 |
getXfaPageViewport, |
| 4254 |
GlobalWorkerOptions, |
| 4255 |
ImageKind, |
| 4256 |
InvalidPDFException, |
| 4257 |
isDataScheme, |
| 4258 |
isPdfFile, |
| 4259 |
isValidExplicitDest, |
| 4260 |
MathClamp, |
| 4261 |
noContextMenu, |
| 4262 |
normalizeUnicode, |
| 4263 |
OPS, |
| 4264 |
OutputScale, |
| 4265 |
PasswordResponses, |
| 4266 |
PDFDataRangeTransport, |
| 4267 |
PDFDateString, |
| 4268 |
PDFWorker, |
| 4269 |
PermissionFlag, |
| 4270 |
PixelsPerInch, |
| 4271 |
RenderingCancelledException, |
| 4272 |
ResponseException, |
| 4273 |
setLayerDimensions, |
| 4274 |
shadow, |
| 4275 |
SignatureExtractor, |
| 4276 |
stopEvent, |
| 4277 |
SupportedImageMimeTypes, |
| 4278 |
TextLayer, |
| 4279 |
TouchManager, |
| 4280 |
updateUrlHash, |
| 4281 |
Util, |
| 4282 |
VerbosityLevel, |
| 4283 |
version, |
| 4284 |
XfaLayer |
| 4285 |
} = globalThis.pdfjsLib; |
| 4286 |
|
| 4287 |
;// ./web/ui_utils.js |
| 4288 |
|
| 4289 |
|
| 4290 |
|
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
|
| 4299 |
|
| 4300 |
const DEFAULT_SCALE_VALUE = "auto"; |
| 4301 |
const DEFAULT_SCALE = 1.0; |
| 4302 |
const DEFAULT_SCALE_DELTA = 1.1; |
| 4303 |
const MIN_SCALE = 0.1; |
| 4304 |
const MAX_SCALE = 10.0; |
| 4305 |
const UNKNOWN_SCALE = 0; |
| 4306 |
const MAX_AUTO_SCALE = 1.25; |
| 4307 |
const SCROLLBAR_PADDING = 40; |
| 4308 |
const VERTICAL_PADDING = 5; |
| 4309 |
const RenderingStates = { |
| 4310 |
INITIAL: 0, |
| 4311 |
RUNNING: 1, |
| 4312 |
PAUSED: 2, |
| 4313 |
FINISHED: 3 |
| 4314 |
}; |
| 4315 |
const PresentationModeState = { |
| 4316 |
UNKNOWN: 0, |
| 4317 |
NORMAL: 1, |
| 4318 |
CHANGING: 2, |
| 4319 |
FULLSCREEN: 3 |
| 4320 |
}; |
| 4321 |
const SidebarView = { |
| 4322 |
UNKNOWN: -1, |
| 4323 |
NONE: 0, |
| 4324 |
THUMBS: 1, |
| 4325 |
OUTLINE: 2, |
| 4326 |
ATTACHMENTS: 3, |
| 4327 |
LAYERS: 4 |
| 4328 |
}; |
| 4329 |
const TextLayerMode = { |
| 4330 |
DISABLE: 0, |
| 4331 |
ENABLE: 1, |
| 4332 |
ENABLE_PERMISSIONS: 2 |
| 4333 |
}; |
| 4334 |
const ScrollMode = { |
| 4335 |
UNKNOWN: -1, |
| 4336 |
VERTICAL: 0, |
| 4337 |
HORIZONTAL: 1, |
| 4338 |
WRAPPED: 2, |
| 4339 |
PAGE: 3 |
| 4340 |
}; |
| 4341 |
const SpreadMode = { |
| 4342 |
UNKNOWN: -1, |
| 4343 |
NONE: 0, |
| 4344 |
ODD: 1, |
| 4345 |
EVEN: 2 |
| 4346 |
}; |
| 4347 |
const CursorTool = { |
| 4348 |
SELECT: 0, |
| 4349 |
HAND: 1, |
| 4350 |
ZOOM: 2 |
| 4351 |
}; |
| 4352 |
const AutoPrintRegExp = /\bprint\s*\(/; |
| 4353 |
function scrollIntoView(element, spot, scrollMatches = false) { |
| 4354 |
let parent = element.offsetParent; |
| 4355 |
if (!parent) { |
| 4356 |
console.error("offsetParent is not set -- cannot scroll"); |
| 4357 |
return; |
| 4358 |
} |
| 4359 |
let offsetY = element.offsetTop + element.clientTop; |
| 4360 |
let offsetX = element.offsetLeft + element.clientLeft; |
| 4361 |
while (parent.clientHeight === parent.scrollHeight && parent.clientWidth === parent.scrollWidth || scrollMatches && (parent.classList.contains("markedContent") || getComputedStyle(parent).overflow === "hidden")) { |
| 4362 |
offsetY += parent.offsetTop; |
| 4363 |
offsetX += parent.offsetLeft; |
| 4364 |
parent = parent.offsetParent; |
| 4365 |
if (!parent) { |
| 4366 |
return; |
| 4367 |
} |
| 4368 |
} |
| 4369 |
if (spot) { |
| 4370 |
if (spot.top !== undefined) { |
| 4371 |
offsetY += spot.top; |
| 4372 |
} |
| 4373 |
if (spot.left !== undefined) { |
| 4374 |
offsetX += spot.left; |
| 4375 |
parent.scrollLeft = offsetX; |
| 4376 |
} |
| 4377 |
} |
| 4378 |
parent.scrollTop = offsetY; |
| 4379 |
} |
| 4380 |
function watchScroll(viewAreaElement, callback, abortSignal = undefined) { |
| 4381 |
const debounceScroll = function (evt) { |
| 4382 |
if (rAF) { |
| 4383 |
return; |
| 4384 |
} |
| 4385 |
rAF = window.requestAnimationFrame(function viewAreaElementScrolled() { |
| 4386 |
rAF = null; |
| 4387 |
const currentX = viewAreaElement.scrollLeft; |
| 4388 |
const lastX = state.lastX; |
| 4389 |
if (currentX !== lastX) { |
| 4390 |
state.right = currentX > lastX; |
| 4391 |
} |
| 4392 |
state.lastX = currentX; |
| 4393 |
const currentY = viewAreaElement.scrollTop; |
| 4394 |
const lastY = state.lastY; |
| 4395 |
if (currentY !== lastY) { |
| 4396 |
state.down = currentY > lastY; |
| 4397 |
} |
| 4398 |
state.lastY = currentY; |
| 4399 |
callback(state); |
| 4400 |
}); |
| 4401 |
}; |
| 4402 |
const state = { |
| 4403 |
right: true, |
| 4404 |
down: true, |
| 4405 |
lastX: viewAreaElement.scrollLeft, |
| 4406 |
lastY: viewAreaElement.scrollTop, |
| 4407 |
_eventHandler: debounceScroll |
| 4408 |
}; |
| 4409 |
let rAF = null; |
| 4410 |
viewAreaElement.addEventListener("scroll", debounceScroll, { |
| 4411 |
useCapture: true, |
| 4412 |
signal: abortSignal |
| 4413 |
}); |
| 4414 |
abortSignal?.addEventListener("abort", () => window.cancelAnimationFrame(rAF), { |
| 4415 |
once: true |
| 4416 |
}); |
| 4417 |
return state; |
| 4418 |
} |
| 4419 |
function parseQueryString(query) { |
| 4420 |
const params = new Map(); |
| 4421 |
for (const [key, value] of new URLSearchParams(query)) { |
| 4422 |
params.set(key.toLowerCase(), value); |
| 4423 |
} |
| 4424 |
return params; |
| 4425 |
} |
| 4426 |
const InvisibleCharsRegExp = /[\x00-\x1F]/g; |
| 4427 |
function removeNullCharacters(str, replaceInvisible = false) { |
| 4428 |
if (!InvisibleCharsRegExp.test(str)) { |
| 4429 |
return str; |
| 4430 |
} |
| 4431 |
if (replaceInvisible) { |
| 4432 |
return str.replaceAll(InvisibleCharsRegExp, m => m === "\x00" ? "" : " "); |
| 4433 |
} |
| 4434 |
return str.replaceAll("\x00", ""); |
| 4435 |
} |
| 4436 |
function binarySearchFirstItem(items, condition, start = 0) { |
| 4437 |
let minIndex = start; |
| 4438 |
let maxIndex = items.length - 1; |
| 4439 |
if (maxIndex < 0 || !condition(items[maxIndex])) { |
| 4440 |
return items.length; |
| 4441 |
} |
| 4442 |
if (condition(items[minIndex])) { |
| 4443 |
return minIndex; |
| 4444 |
} |
| 4445 |
while (minIndex < maxIndex) { |
| 4446 |
const currentIndex = minIndex + maxIndex >> 1; |
| 4447 |
const currentItem = items[currentIndex]; |
| 4448 |
if (condition(currentItem)) { |
| 4449 |
maxIndex = currentIndex; |
| 4450 |
} else { |
| 4451 |
minIndex = currentIndex + 1; |
| 4452 |
} |
| 4453 |
} |
| 4454 |
return minIndex; |
| 4455 |
} |
| 4456 |
function approximateFraction(x) { |
| 4457 |
if (Math.floor(x) === x) { |
| 4458 |
return [x, 1]; |
| 4459 |
} |
| 4460 |
const xinv = 1 / x; |
| 4461 |
const limit = 8; |
| 4462 |
if (xinv > limit) { |
| 4463 |
return [1, limit]; |
| 4464 |
} else if (Math.floor(xinv) === xinv) { |
| 4465 |
return [1, xinv]; |
| 4466 |
} |
| 4467 |
const x_ = x > 1 ? xinv : x; |
| 4468 |
let a = 0, |
| 4469 |
b = 1, |
| 4470 |
c = 1, |
| 4471 |
d = 1; |
| 4472 |
while (true) { |
| 4473 |
const p = a + c, |
| 4474 |
q = b + d; |
| 4475 |
if (q > limit) { |
| 4476 |
break; |
| 4477 |
} |
| 4478 |
if (x_ <= p / q) { |
| 4479 |
c = p; |
| 4480 |
d = q; |
| 4481 |
} else { |
| 4482 |
a = p; |
| 4483 |
b = q; |
| 4484 |
} |
| 4485 |
} |
| 4486 |
let result; |
| 4487 |
if (x_ - a / b < c / d - x_) { |
| 4488 |
result = x_ === x ? [a, b] : [b, a]; |
| 4489 |
} else { |
| 4490 |
result = x_ === x ? [c, d] : [d, c]; |
| 4491 |
} |
| 4492 |
return result; |
| 4493 |
} |
| 4494 |
function floorToDivide(x, div) { |
| 4495 |
return x - x % div; |
| 4496 |
} |
| 4497 |
function getPageSizeInches({ |
| 4498 |
view, |
| 4499 |
userUnit, |
| 4500 |
rotate |
| 4501 |
}) { |
| 4502 |
const [x1, y1, x2, y2] = view; |
| 4503 |
const changeOrientation = rotate % 180 !== 0; |
| 4504 |
const width = (x2 - x1) / 72 * userUnit; |
| 4505 |
const height = (y2 - y1) / 72 * userUnit; |
| 4506 |
return { |
| 4507 |
width: changeOrientation ? height : width, |
| 4508 |
height: changeOrientation ? width : height |
| 4509 |
}; |
| 4510 |
} |
| 4511 |
function backtrackBeforeAllVisibleElements(index, views, top) { |
| 4512 |
if (index < 2) { |
| 4513 |
return index; |
| 4514 |
} |
| 4515 |
let elt = views[index].div; |
| 4516 |
let pageTop = elt.offsetTop + elt.clientTop; |
| 4517 |
if (pageTop >= top) { |
| 4518 |
elt = views[index - 1].div; |
| 4519 |
pageTop = elt.offsetTop + elt.clientTop; |
| 4520 |
} |
| 4521 |
for (let i = index - 2; i >= 0; --i) { |
| 4522 |
elt = views[i].div; |
| 4523 |
if (elt.offsetTop + elt.clientTop + elt.clientHeight <= pageTop) { |
| 4524 |
break; |
| 4525 |
} |
| 4526 |
index = i; |
| 4527 |
} |
| 4528 |
return index; |
| 4529 |
} |
| 4530 |
function getVisibleElements({ |
| 4531 |
scrollEl, |
| 4532 |
views, |
| 4533 |
sortByVisibility = false, |
| 4534 |
horizontal = false, |
| 4535 |
rtl = false |
| 4536 |
}) { |
| 4537 |
const top = scrollEl.scrollTop, |
| 4538 |
bottom = top + scrollEl.clientHeight; |
| 4539 |
const left = scrollEl.scrollLeft, |
| 4540 |
right = left + scrollEl.clientWidth; |
| 4541 |
function isElementBottomAfterViewTop(view) { |
| 4542 |
const element = view.div; |
| 4543 |
const elementBottom = element.offsetTop + element.clientTop + element.clientHeight; |
| 4544 |
return elementBottom > top; |
| 4545 |
} |
| 4546 |
function isElementNextAfterViewHorizontally(view) { |
| 4547 |
const element = view.div; |
| 4548 |
const elementLeft = element.offsetLeft + element.clientLeft; |
| 4549 |
const elementRight = elementLeft + element.clientWidth; |
| 4550 |
return rtl ? elementLeft < right : elementRight > left; |
| 4551 |
} |
| 4552 |
const visible = [], |
| 4553 |
ids = new Set(), |
| 4554 |
numViews = views.length; |
| 4555 |
let firstVisibleElementInd = binarySearchFirstItem(views, horizontal ? isElementNextAfterViewHorizontally : isElementBottomAfterViewTop); |
| 4556 |
if (firstVisibleElementInd > 0 && firstVisibleElementInd < numViews && !horizontal) { |
| 4557 |
firstVisibleElementInd = backtrackBeforeAllVisibleElements(firstVisibleElementInd, views, top); |
| 4558 |
} |
| 4559 |
let lastEdge = horizontal ? right : -1; |
| 4560 |
for (let i = firstVisibleElementInd; i < numViews; i++) { |
| 4561 |
const view = views[i], |
| 4562 |
element = view.div; |
| 4563 |
const currentWidth = element.offsetLeft + element.clientLeft; |
| 4564 |
const currentHeight = element.offsetTop + element.clientTop; |
| 4565 |
const viewWidth = element.clientWidth, |
| 4566 |
viewHeight = element.clientHeight; |
| 4567 |
const viewRight = currentWidth + viewWidth; |
| 4568 |
const viewBottom = currentHeight + viewHeight; |
| 4569 |
if (lastEdge === -1) { |
| 4570 |
if (viewBottom >= bottom) { |
| 4571 |
lastEdge = viewBottom; |
| 4572 |
} |
| 4573 |
} else if ((horizontal ? currentWidth : currentHeight) > lastEdge) { |
| 4574 |
break; |
| 4575 |
} |
| 4576 |
if (viewBottom <= top || currentHeight >= bottom || viewRight <= left || currentWidth >= right) { |
| 4577 |
continue; |
| 4578 |
} |
| 4579 |
const minY = Math.max(0, top - currentHeight); |
| 4580 |
const minX = Math.max(0, left - currentWidth); |
| 4581 |
const hiddenHeight = minY + Math.max(0, viewBottom - bottom); |
| 4582 |
const hiddenWidth = minX + Math.max(0, viewRight - right); |
| 4583 |
const fractionHeight = (viewHeight - hiddenHeight) / viewHeight, |
| 4584 |
fractionWidth = (viewWidth - hiddenWidth) / viewWidth; |
| 4585 |
const percent = fractionHeight * fractionWidth * 100 | 0; |
| 4586 |
visible.push({ |
| 4587 |
id: view.id, |
| 4588 |
x: currentWidth, |
| 4589 |
y: currentHeight, |
| 4590 |
visibleArea: percent === 100 ? null : { |
| 4591 |
minX, |
| 4592 |
minY, |
| 4593 |
maxX: Math.min(viewRight, right) - currentWidth, |
| 4594 |
maxY: Math.min(viewBottom, bottom) - currentHeight |
| 4595 |
}, |
| 4596 |
view, |
| 4597 |
percent, |
| 4598 |
widthPercent: fractionWidth * 100 | 0 |
| 4599 |
}); |
| 4600 |
ids.add(view.id); |
| 4601 |
} |
| 4602 |
const first = visible[0], |
| 4603 |
last = visible.at(-1); |
| 4604 |
if (sortByVisibility) { |
| 4605 |
visible.sort(function (a, b) { |
| 4606 |
const pc = a.percent - b.percent; |
| 4607 |
if (Math.abs(pc) > 0.001) { |
| 4608 |
return -pc; |
| 4609 |
} |
| 4610 |
return a.id - b.id; |
| 4611 |
}); |
| 4612 |
} |
| 4613 |
return { |
| 4614 |
first, |
| 4615 |
last, |
| 4616 |
views: visible, |
| 4617 |
ids |
| 4618 |
}; |
| 4619 |
} |
| 4620 |
function normalizeWheelEventDirection(evt) { |
| 4621 |
let delta = Math.hypot(evt.deltaX, evt.deltaY); |
| 4622 |
const angle = Math.atan2(evt.deltaY, evt.deltaX); |
| 4623 |
if (-0.25 * Math.PI < angle && angle < 0.75 * Math.PI) { |
| 4624 |
delta = -delta; |
| 4625 |
} |
| 4626 |
return delta; |
| 4627 |
} |
| 4628 |
function normalizeWheelEventDelta(evt) { |
| 4629 |
const deltaMode = evt.deltaMode; |
| 4630 |
let delta = normalizeWheelEventDirection(evt); |
| 4631 |
const MOUSE_PIXELS_PER_LINE = 30; |
| 4632 |
const MOUSE_LINES_PER_PAGE = 30; |
| 4633 |
if (deltaMode === WheelEvent.DOM_DELTA_PIXEL) { |
| 4634 |
delta /= MOUSE_PIXELS_PER_LINE * MOUSE_LINES_PER_PAGE; |
| 4635 |
} else if (deltaMode === WheelEvent.DOM_DELTA_LINE) { |
| 4636 |
delta /= MOUSE_LINES_PER_PAGE; |
| 4637 |
} |
| 4638 |
return delta; |
| 4639 |
} |
| 4640 |
function isValidRotation(angle) { |
| 4641 |
return Number.isInteger(angle) && angle % 90 === 0; |
| 4642 |
} |
| 4643 |
function isValidScrollMode(mode) { |
| 4644 |
return Number.isInteger(mode) && Object.values(ScrollMode).includes(mode) && mode !== ScrollMode.UNKNOWN; |
| 4645 |
} |
| 4646 |
function isValidSpreadMode(mode) { |
| 4647 |
return Number.isInteger(mode) && Object.values(SpreadMode).includes(mode) && mode !== SpreadMode.UNKNOWN; |
| 4648 |
} |
| 4649 |
function isPortraitOrientation(size) { |
| 4650 |
return size.width <= size.height; |
| 4651 |
} |
| 4652 |
const animationStarted = new Promise(function (resolve) { |
| 4653 |
window.requestAnimationFrame(resolve); |
| 4654 |
}); |
| 4655 |
const docStyle = document.documentElement.style; |
| 4656 |
class ProgressBar { |
| 4657 |
#classList = null; |
| 4658 |
#disableAutoFetchTimeout = null; |
| 4659 |
#percent = 0; |
| 4660 |
#style = null; |
| 4661 |
#visible = true; |
| 4662 |
constructor(bar) { |
| 4663 |
this.#classList = bar.classList; |
| 4664 |
this.#style = bar.style; |
| 4665 |
} |
| 4666 |
get percent() { |
| 4667 |
return this.#percent; |
| 4668 |
} |
| 4669 |
set percent(val) { |
| 4670 |
this.#percent = MathClamp(val, 0, 100); |
| 4671 |
if (isNaN(val)) { |
| 4672 |
this.#classList.add("indeterminate"); |
| 4673 |
return; |
| 4674 |
} |
| 4675 |
this.#classList.remove("indeterminate"); |
| 4676 |
this.#style.setProperty("--progressBar-percent", `${this.#percent}%`); |
| 4677 |
} |
| 4678 |
setWidth(viewer) { |
| 4679 |
if (!viewer) { |
| 4680 |
return; |
| 4681 |
} |
| 4682 |
const container = viewer.parentNode; |
| 4683 |
const scrollbarWidth = container.offsetWidth - viewer.offsetWidth; |
| 4684 |
if (scrollbarWidth > 0) { |
| 4685 |
this.#style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`); |
| 4686 |
} |
| 4687 |
} |
| 4688 |
setDisableAutoFetch(delay = 5000) { |
| 4689 |
if (this.#percent === 100 || isNaN(this.#percent)) { |
| 4690 |
return; |
| 4691 |
} |
| 4692 |
if (this.#disableAutoFetchTimeout) { |
| 4693 |
clearTimeout(this.#disableAutoFetchTimeout); |
| 4694 |
} |
| 4695 |
this.show(); |
| 4696 |
this.#disableAutoFetchTimeout = setTimeout(() => { |
| 4697 |
this.#disableAutoFetchTimeout = null; |
| 4698 |
this.hide(); |
| 4699 |
}, delay); |
| 4700 |
} |
| 4701 |
hide() { |
| 4702 |
if (!this.#visible) { |
| 4703 |
return; |
| 4704 |
} |
| 4705 |
this.#visible = false; |
| 4706 |
this.#classList.add("hidden"); |
| 4707 |
} |
| 4708 |
show() { |
| 4709 |
if (this.#visible) { |
| 4710 |
return; |
| 4711 |
} |
| 4712 |
this.#visible = true; |
| 4713 |
this.#classList.remove("hidden"); |
| 4714 |
} |
| 4715 |
} |
| 4716 |
function getActiveOrFocusedElement() { |
| 4717 |
let curRoot = document; |
| 4718 |
let curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus"); |
| 4719 |
while (curActiveOrFocused?.shadowRoot) { |
| 4720 |
curRoot = curActiveOrFocused.shadowRoot; |
| 4721 |
curActiveOrFocused = curRoot.activeElement || curRoot.querySelector(":focus"); |
| 4722 |
} |
| 4723 |
return curActiveOrFocused; |
| 4724 |
} |
| 4725 |
function apiPageLayoutToViewerModes(layout) { |
| 4726 |
let scrollMode = ScrollMode.VERTICAL, |
| 4727 |
spreadMode = SpreadMode.NONE; |
| 4728 |
switch (layout) { |
| 4729 |
case "SinglePage": |
| 4730 |
scrollMode = ScrollMode.PAGE; |
| 4731 |
break; |
| 4732 |
case "OneColumn": |
| 4733 |
break; |
| 4734 |
case "TwoPageLeft": |
| 4735 |
scrollMode = ScrollMode.PAGE; |
| 4736 |
case "TwoColumnLeft": |
| 4737 |
spreadMode = SpreadMode.ODD; |
| 4738 |
break; |
| 4739 |
case "TwoPageRight": |
| 4740 |
scrollMode = ScrollMode.PAGE; |
| 4741 |
case "TwoColumnRight": |
| 4742 |
spreadMode = SpreadMode.EVEN; |
| 4743 |
break; |
| 4744 |
} |
| 4745 |
return { |
| 4746 |
scrollMode, |
| 4747 |
spreadMode |
| 4748 |
}; |
| 4749 |
} |
| 4750 |
function apiPageModeToSidebarView(mode) { |
| 4751 |
switch (mode) { |
| 4752 |
case "UseNone": |
| 4753 |
return SidebarView.NONE; |
| 4754 |
case "UseThumbs": |
| 4755 |
return SidebarView.THUMBS; |
| 4756 |
case "UseOutlines": |
| 4757 |
return SidebarView.OUTLINE; |
| 4758 |
case "UseAttachments": |
| 4759 |
return SidebarView.ATTACHMENTS; |
| 4760 |
case "UseOC": |
| 4761 |
return SidebarView.LAYERS; |
| 4762 |
} |
| 4763 |
return SidebarView.NONE; |
| 4764 |
} |
| 4765 |
function toggleCheckedBtn(button, toggle, view = null) { |
| 4766 |
button.classList.toggle("toggled", toggle); |
| 4767 |
button.setAttribute("aria-checked", toggle); |
| 4768 |
view?.classList.toggle("hidden", !toggle); |
| 4769 |
} |
| 4770 |
function toggleExpandedBtn(button, toggle, view = null) { |
| 4771 |
button.classList.toggle("toggled", toggle); |
| 4772 |
button.setAttribute("aria-expanded", toggle); |
| 4773 |
view?.classList.toggle("hidden", !toggle); |
| 4774 |
} |
| 4775 |
const calcRound = function () { |
| 4776 |
const e = document.createElement("div"); |
| 4777 |
e.style.width = "round(down, calc(1.6666666666666665 * 792px), 1px)"; |
| 4778 |
return e.style.width === "calc(1320px)" ? Math.fround : x => x; |
| 4779 |
}(); |
| 4780 |
|
| 4781 |
;// ./web/app_options.js |
| 4782 |
{ |
| 4783 |
var compatParams = new Map(); |
| 4784 |
const { |
| 4785 |
maxTouchPoints, |
| 4786 |
platform, |
| 4787 |
userAgent |
| 4788 |
} = navigator; |
| 4789 |
const isAndroid = /Android/.test(userAgent); |
| 4790 |
const isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent) || platform === "MacIntel" && maxTouchPoints > 1; |
| 4791 |
(function () { |
| 4792 |
if (isIOS || isAndroid) { |
| 4793 |
compatParams.set("maxCanvasPixels", 5242880); |
| 4794 |
} |
| 4795 |
})(); |
| 4796 |
(function () { |
| 4797 |
if (isAndroid) { |
| 4798 |
compatParams.set("useSystemFonts", false); |
| 4799 |
} |
| 4800 |
})(); |
| 4801 |
} |
| 4802 |
const OptionKind = { |
| 4803 |
BROWSER: 0x01, |
| 4804 |
VIEWER: 0x02, |
| 4805 |
API: 0x04, |
| 4806 |
WORKER: 0x08, |
| 4807 |
EVENT_DISPATCH: 0x10, |
| 4808 |
PREFERENCE: 0x80 |
| 4809 |
}; |
| 4810 |
const Type = { |
| 4811 |
BOOLEAN: 0x01, |
| 4812 |
NUMBER: 0x02, |
| 4813 |
OBJECT: 0x04, |
| 4814 |
STRING: 0x08, |
| 4815 |
UNDEFINED: 0x10 |
| 4816 |
}; |
| 4817 |
const defaultOptions = { |
| 4818 |
allowedGlobalEvents: { |
| 4819 |
value: null, |
| 4820 |
kind: OptionKind.BROWSER |
| 4821 |
}, |
| 4822 |
canvasMaxAreaInBytes: { |
| 4823 |
value: -1, |
| 4824 |
kind: OptionKind.BROWSER + OptionKind.API |
| 4825 |
}, |
| 4826 |
isInAutomation: { |
| 4827 |
value: false, |
| 4828 |
kind: OptionKind.BROWSER |
| 4829 |
}, |
| 4830 |
localeProperties: { |
| 4831 |
value: { |
| 4832 |
lang: navigator.language || "en-US" |
| 4833 |
}, |
| 4834 |
kind: OptionKind.BROWSER |
| 4835 |
}, |
| 4836 |
maxCanvasDim: { |
| 4837 |
value: 32767, |
| 4838 |
kind: OptionKind.BROWSER + OptionKind.VIEWER |
| 4839 |
}, |
| 4840 |
nimbusDataStr: { |
| 4841 |
value: "", |
| 4842 |
kind: OptionKind.BROWSER |
| 4843 |
}, |
| 4844 |
supportsCaretBrowsingMode: { |
| 4845 |
value: false, |
| 4846 |
kind: OptionKind.BROWSER |
| 4847 |
}, |
| 4848 |
supportsDocumentFonts: { |
| 4849 |
value: true, |
| 4850 |
kind: OptionKind.BROWSER |
| 4851 |
}, |
| 4852 |
supportsIntegratedFind: { |
| 4853 |
value: false, |
| 4854 |
kind: OptionKind.BROWSER |
| 4855 |
}, |
| 4856 |
supportsMouseWheelZoomCtrlKey: { |
| 4857 |
value: true, |
| 4858 |
kind: OptionKind.BROWSER |
| 4859 |
}, |
| 4860 |
supportsMouseWheelZoomMetaKey: { |
| 4861 |
value: true, |
| 4862 |
kind: OptionKind.BROWSER |
| 4863 |
}, |
| 4864 |
supportsPinchToZoom: { |
| 4865 |
value: true, |
| 4866 |
kind: OptionKind.BROWSER |
| 4867 |
}, |
| 4868 |
supportsPrinting: { |
| 4869 |
value: true, |
| 4870 |
kind: OptionKind.BROWSER |
| 4871 |
}, |
| 4872 |
toolbarDensity: { |
| 4873 |
value: 0, |
| 4874 |
kind: OptionKind.BROWSER + OptionKind.EVENT_DISPATCH |
| 4875 |
}, |
| 4876 |
altTextLearnMoreUrl: { |
| 4877 |
value: "", |
| 4878 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4879 |
}, |
| 4880 |
annotationEditorMode: { |
| 4881 |
value: 0, |
| 4882 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4883 |
}, |
| 4884 |
annotationMode: { |
| 4885 |
value: 2, |
| 4886 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4887 |
}, |
| 4888 |
capCanvasAreaFactor: { |
| 4889 |
value: 200, |
| 4890 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4891 |
}, |
| 4892 |
cursorToolOnLoad: { |
| 4893 |
value: 0, |
| 4894 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4895 |
}, |
| 4896 |
debuggerSrc: { |
| 4897 |
value: "./debugger.js?v=1.29.11", |
| 4898 |
kind: OptionKind.VIEWER |
| 4899 |
}, |
| 4900 |
defaultZoomDelay: { |
| 4901 |
value: 400, |
| 4902 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4903 |
}, |
| 4904 |
defaultZoomValue: { |
| 4905 |
value: "", |
| 4906 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4907 |
}, |
| 4908 |
disableHistory: { |
| 4909 |
value: false, |
| 4910 |
kind: OptionKind.VIEWER |
| 4911 |
}, |
| 4912 |
disablePageLabels: { |
| 4913 |
value: false, |
| 4914 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4915 |
}, |
| 4916 |
enableAltText: { |
| 4917 |
value: false, |
| 4918 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4919 |
}, |
| 4920 |
enableAltTextModelDownload: { |
| 4921 |
value: true, |
| 4922 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE + OptionKind.EVENT_DISPATCH |
| 4923 |
}, |
| 4924 |
enableAutoLinking: { |
| 4925 |
value: true, |
| 4926 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4927 |
}, |
| 4928 |
enableDetailCanvas: { |
| 4929 |
value: true, |
| 4930 |
kind: OptionKind.VIEWER |
| 4931 |
}, |
| 4932 |
enableGuessAltText: { |
| 4933 |
value: true, |
| 4934 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE + OptionKind.EVENT_DISPATCH |
| 4935 |
}, |
| 4936 |
enableHighlightFloatingButton: { |
| 4937 |
value: false, |
| 4938 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4939 |
}, |
| 4940 |
enableNewAltTextWhenAddingImage: { |
| 4941 |
value: true, |
| 4942 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4943 |
}, |
| 4944 |
enablePermissions: { |
| 4945 |
value: false, |
| 4946 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4947 |
}, |
| 4948 |
enablePrintAutoRotate: { |
| 4949 |
value: true, |
| 4950 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4951 |
}, |
| 4952 |
enableScripting: { |
| 4953 |
value: true, |
| 4954 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4955 |
}, |
| 4956 |
enableSignatureEditor: { |
| 4957 |
value: false, |
| 4958 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4959 |
}, |
| 4960 |
enableUpdatedAddImage: { |
| 4961 |
value: false, |
| 4962 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4963 |
}, |
| 4964 |
externalLinkRel: { |
| 4965 |
value: "noopener noreferrer nofollow", |
| 4966 |
kind: OptionKind.VIEWER |
| 4967 |
}, |
| 4968 |
externalLinkTarget: { |
| 4969 |
value: 0, |
| 4970 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4971 |
}, |
| 4972 |
highlightEditorColors: { |
| 4973 |
value: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", |
| 4974 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4975 |
}, |
| 4976 |
historyUpdateUrl: { |
| 4977 |
value: false, |
| 4978 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4979 |
}, |
| 4980 |
ignoreDestinationZoom: { |
| 4981 |
value: false, |
| 4982 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4983 |
}, |
| 4984 |
imageResourcesPath: { |
| 4985 |
value: "./images/", |
| 4986 |
kind: OptionKind.VIEWER |
| 4987 |
}, |
| 4988 |
maxCanvasPixels: { |
| 4989 |
value: 2 ** 25, |
| 4990 |
kind: OptionKind.VIEWER |
| 4991 |
}, |
| 4992 |
minDurationToUpdateCanvas: { |
| 4993 |
value: 500, |
| 4994 |
kind: OptionKind.VIEWER |
| 4995 |
}, |
| 4996 |
forcePageColors: { |
| 4997 |
value: false, |
| 4998 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 4999 |
}, |
| 5000 |
pageColorsBackground: { |
| 5001 |
value: "Canvas", |
| 5002 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5003 |
}, |
| 5004 |
pageColorsForeground: { |
| 5005 |
value: "CanvasText", |
| 5006 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5007 |
}, |
| 5008 |
pdfBugEnabled: { |
| 5009 |
value: false, |
| 5010 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5011 |
}, |
| 5012 |
printResolution: { |
| 5013 |
value: 150, |
| 5014 |
kind: OptionKind.VIEWER |
| 5015 |
}, |
| 5016 |
sidebarViewOnLoad: { |
| 5017 |
value: -1, |
| 5018 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5019 |
}, |
| 5020 |
scrollModeOnLoad: { |
| 5021 |
value: -1, |
| 5022 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5023 |
}, |
| 5024 |
spreadModeOnLoad: { |
| 5025 |
value: -1, |
| 5026 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5027 |
}, |
| 5028 |
textLayerMode: { |
| 5029 |
value: 1, |
| 5030 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5031 |
}, |
| 5032 |
viewerCssTheme: { |
| 5033 |
value: 0, |
| 5034 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5035 |
}, |
| 5036 |
viewOnLoad: { |
| 5037 |
value: 0, |
| 5038 |
kind: OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5039 |
}, |
| 5040 |
cMapPacked: { |
| 5041 |
value: true, |
| 5042 |
kind: OptionKind.API |
| 5043 |
}, |
| 5044 |
cMapUrl: { |
| 5045 |
value: "../web/cmaps/", |
| 5046 |
kind: OptionKind.API |
| 5047 |
}, |
| 5048 |
disableAutoFetch: { |
| 5049 |
value: false, |
| 5050 |
kind: OptionKind.API + OptionKind.PREFERENCE |
| 5051 |
}, |
| 5052 |
disableFontFace: { |
| 5053 |
value: false, |
| 5054 |
kind: OptionKind.API + OptionKind.PREFERENCE |
| 5055 |
}, |
| 5056 |
disableRange: { |
| 5057 |
value: false, |
| 5058 |
kind: OptionKind.API + OptionKind.PREFERENCE |
| 5059 |
}, |
| 5060 |
disableStream: { |
| 5061 |
value: false, |
| 5062 |
kind: OptionKind.API + OptionKind.PREFERENCE |
| 5063 |
}, |
| 5064 |
docBaseUrl: { |
| 5065 |
value: "", |
| 5066 |
kind: OptionKind.API |
| 5067 |
}, |
| 5068 |
enableHWA: { |
| 5069 |
value: true, |
| 5070 |
kind: OptionKind.API + OptionKind.VIEWER + OptionKind.PREFERENCE |
| 5071 |
}, |
| 5072 |
enableXfa: { |
| 5073 |
value: true, |
| 5074 |
kind: OptionKind.API + OptionKind.PREFERENCE |
| 5075 |
}, |
| 5076 |
fontExtraProperties: { |
| 5077 |
value: false, |
| 5078 |
kind: OptionKind.API |
| 5079 |
}, |
| 5080 |
iccUrl: { |
| 5081 |
value: "../web/iccs/", |
| 5082 |
kind: OptionKind.API |
| 5083 |
}, |
| 5084 |
isEvalSupported: { |
| 5085 |
value: true, |
| 5086 |
kind: OptionKind.API |
| 5087 |
}, |
| 5088 |
isOffscreenCanvasSupported: { |
| 5089 |
value: true, |
| 5090 |
kind: OptionKind.API |
| 5091 |
}, |
| 5092 |
maxImageSize: { |
| 5093 |
value: -1, |
| 5094 |
kind: OptionKind.API |
| 5095 |
}, |
| 5096 |
pdfBug: { |
| 5097 |
value: false, |
| 5098 |
kind: OptionKind.API |
| 5099 |
}, |
| 5100 |
standardFontDataUrl: { |
| 5101 |
value: "../web/standard_fonts/", |
| 5102 |
kind: OptionKind.API |
| 5103 |
}, |
| 5104 |
useSystemFonts: { |
| 5105 |
value: undefined, |
| 5106 |
kind: OptionKind.API, |
| 5107 |
type: Type.BOOLEAN + Type.UNDEFINED |
| 5108 |
}, |
| 5109 |
verbosity: { |
| 5110 |
value: 1, |
| 5111 |
kind: OptionKind.API |
| 5112 |
}, |
| 5113 |
wasmUrl: { |
| 5114 |
value: "../web/wasm/", |
| 5115 |
kind: OptionKind.API |
| 5116 |
}, |
| 5117 |
workerPort: { |
| 5118 |
value: null, |
| 5119 |
kind: OptionKind.WORKER |
| 5120 |
}, |
| 5121 |
workerSrc: { |
| 5122 |
value: "../build/pdf.worker.js?v=1.29.11", |
| 5123 |
kind: OptionKind.WORKER |
| 5124 |
} |
| 5125 |
}; |
| 5126 |
{ |
| 5127 |
defaultOptions.defaultUrl = { |
| 5128 |
value: "", |
| 5129 |
kind: OptionKind.VIEWER |
| 5130 |
}; |
| 5131 |
defaultOptions.sandboxBundleSrc = { |
| 5132 |
value: "../build/pdf.sandbox.js?v=1.29.11", |
| 5133 |
kind: OptionKind.VIEWER |
| 5134 |
}; |
| 5135 |
defaultOptions.enableFakeMLManager = { |
| 5136 |
value: true, |
| 5137 |
kind: OptionKind.VIEWER |
| 5138 |
}; |
| 5139 |
} |
| 5140 |
{ |
| 5141 |
defaultOptions.disablePreferences = { |
| 5142 |
value: false, |
| 5143 |
kind: OptionKind.VIEWER |
| 5144 |
}; |
| 5145 |
} |
| 5146 |
class AppOptions { |
| 5147 |
static eventBus; |
| 5148 |
static #opts = new Map(); |
| 5149 |
static { |
| 5150 |
for (const name in defaultOptions) { |
| 5151 |
this.#opts.set(name, defaultOptions[name].value); |
| 5152 |
} |
| 5153 |
for (const [name, value] of compatParams) { |
| 5154 |
this.#opts.set(name, value); |
| 5155 |
} |
| 5156 |
this._hasInvokedSet = false; |
| 5157 |
this._checkDisablePreferences = () => { |
| 5158 |
if (this.get("disablePreferences")) { |
| 5159 |
return true; |
| 5160 |
} |
| 5161 |
if (this._hasInvokedSet) { |
| 5162 |
console.warn("The Preferences may override manually set AppOptions; " + 'please use the "disablePreferences"-option to prevent that.'); |
| 5163 |
} |
| 5164 |
return false; |
| 5165 |
}; |
| 5166 |
} |
| 5167 |
static get(name) { |
| 5168 |
return this.#opts.get(name); |
| 5169 |
} |
| 5170 |
static getAll(kind = null, defaultOnly = false) { |
| 5171 |
const options = Object.create(null); |
| 5172 |
for (const name in defaultOptions) { |
| 5173 |
const defaultOpt = defaultOptions[name]; |
| 5174 |
if (kind && !(kind & defaultOpt.kind)) { |
| 5175 |
continue; |
| 5176 |
} |
| 5177 |
options[name] = !defaultOnly ? this.#opts.get(name) : defaultOpt.value; |
| 5178 |
} |
| 5179 |
return options; |
| 5180 |
} |
| 5181 |
static set(name, value) { |
| 5182 |
this.setAll({ |
| 5183 |
[name]: value |
| 5184 |
}); |
| 5185 |
} |
| 5186 |
static setAll(options, prefs = false) { |
| 5187 |
this._hasInvokedSet ||= true; |
| 5188 |
let events; |
| 5189 |
for (const name in options) { |
| 5190 |
const defaultOpt = defaultOptions[name], |
| 5191 |
userOpt = options[name]; |
| 5192 |
if (!defaultOpt || !(typeof userOpt === typeof defaultOpt.value || Type[(typeof userOpt).toUpperCase()] & defaultOpt.type)) { |
| 5193 |
continue; |
| 5194 |
} |
| 5195 |
const { |
| 5196 |
kind |
| 5197 |
} = defaultOpt; |
| 5198 |
if (prefs && !(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) { |
| 5199 |
continue; |
| 5200 |
} |
| 5201 |
if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) { |
| 5202 |
(events ||= new Map()).set(name, userOpt); |
| 5203 |
} |
| 5204 |
this.#opts.set(name, userOpt); |
| 5205 |
} |
| 5206 |
if (events) { |
| 5207 |
for (const [name, value] of events) { |
| 5208 |
this.eventBus.dispatch(name.toLowerCase(), { |
| 5209 |
source: this, |
| 5210 |
value |
| 5211 |
}); |
| 5212 |
} |
| 5213 |
} |
| 5214 |
} |
| 5215 |
} |
| 5216 |
|
| 5217 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/esnext.json.parse.js |
| 5218 |
var esnext_json_parse = __webpack_require__(8335); |
| 5219 |
;// ./web/pdf_link_service.js |
| 5220 |
|
| 5221 |
|
| 5222 |
|
| 5223 |
|
| 5224 |
const DEFAULT_LINK_REL = "noopener noreferrer nofollow"; |
| 5225 |
const LinkTarget = { |
| 5226 |
NONE: 0, |
| 5227 |
SELF: 1, |
| 5228 |
BLANK: 2, |
| 5229 |
PARENT: 3, |
| 5230 |
TOP: 4 |
| 5231 |
}; |
| 5232 |
class PDFLinkService { |
| 5233 |
externalLinkEnabled = true; |
| 5234 |
constructor({ |
| 5235 |
eventBus, |
| 5236 |
externalLinkTarget = null, |
| 5237 |
externalLinkRel = null, |
| 5238 |
ignoreDestinationZoom = false |
| 5239 |
} = {}) { |
| 5240 |
this.eventBus = eventBus; |
| 5241 |
this.externalLinkTarget = externalLinkTarget; |
| 5242 |
this.externalLinkRel = externalLinkRel; |
| 5243 |
this._ignoreDestinationZoom = ignoreDestinationZoom; |
| 5244 |
this.baseUrl = null; |
| 5245 |
this.pdfDocument = null; |
| 5246 |
this.pdfViewer = null; |
| 5247 |
this.pdfHistory = null; |
| 5248 |
} |
| 5249 |
setDocument(pdfDocument, baseUrl = null) { |
| 5250 |
this.baseUrl = baseUrl; |
| 5251 |
this.pdfDocument = pdfDocument; |
| 5252 |
} |
| 5253 |
setViewer(pdfViewer) { |
| 5254 |
this.pdfViewer = pdfViewer; |
| 5255 |
} |
| 5256 |
setHistory(pdfHistory) { |
| 5257 |
this.pdfHistory = pdfHistory; |
| 5258 |
} |
| 5259 |
get pagesCount() { |
| 5260 |
return this.pdfDocument ? this.pdfDocument.numPages : 0; |
| 5261 |
} |
| 5262 |
get page() { |
| 5263 |
return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1; |
| 5264 |
} |
| 5265 |
set page(value) { |
| 5266 |
if (this.pdfDocument) { |
| 5267 |
this.pdfViewer.currentPageNumber = value; |
| 5268 |
} |
| 5269 |
} |
| 5270 |
get rotation() { |
| 5271 |
return this.pdfDocument ? this.pdfViewer.pagesRotation : 0; |
| 5272 |
} |
| 5273 |
set rotation(value) { |
| 5274 |
if (this.pdfDocument) { |
| 5275 |
this.pdfViewer.pagesRotation = value; |
| 5276 |
} |
| 5277 |
} |
| 5278 |
get isInPresentationMode() { |
| 5279 |
return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false; |
| 5280 |
} |
| 5281 |
async goToDestination(dest) { |
| 5282 |
if (!this.pdfDocument) { |
| 5283 |
return; |
| 5284 |
} |
| 5285 |
let namedDest, explicitDest, pageNumber; |
| 5286 |
if (typeof dest === "string") { |
| 5287 |
namedDest = dest; |
| 5288 |
explicitDest = await this.pdfDocument.getDestination(dest); |
| 5289 |
} else { |
| 5290 |
namedDest = null; |
| 5291 |
explicitDest = await dest; |
| 5292 |
} |
| 5293 |
if (!Array.isArray(explicitDest)) { |
| 5294 |
console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`); |
| 5295 |
return; |
| 5296 |
} |
| 5297 |
const [destRef] = explicitDest; |
| 5298 |
if (destRef && typeof destRef === "object") { |
| 5299 |
pageNumber = this.pdfDocument.cachedPageNumber(destRef); |
| 5300 |
if (!pageNumber) { |
| 5301 |
try { |
| 5302 |
pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1; |
| 5303 |
} catch { |
| 5304 |
console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`); |
| 5305 |
return; |
| 5306 |
} |
| 5307 |
} |
| 5308 |
} else if (Number.isInteger(destRef)) { |
| 5309 |
pageNumber = destRef + 1; |
| 5310 |
} |
| 5311 |
if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) { |
| 5312 |
console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`); |
| 5313 |
return; |
| 5314 |
} |
| 5315 |
if (this.pdfHistory) { |
| 5316 |
this.pdfHistory.pushCurrentPosition(); |
| 5317 |
this.pdfHistory.push({ |
| 5318 |
namedDest, |
| 5319 |
explicitDest, |
| 5320 |
pageNumber |
| 5321 |
}); |
| 5322 |
} |
| 5323 |
this.pdfViewer.scrollPageIntoView({ |
| 5324 |
pageNumber, |
| 5325 |
destArray: explicitDest, |
| 5326 |
ignoreDestinationZoom: this._ignoreDestinationZoom |
| 5327 |
}); |
| 5328 |
} |
| 5329 |
goToPage(val) { |
| 5330 |
if (!this.pdfDocument) { |
| 5331 |
return; |
| 5332 |
} |
| 5333 |
const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0; |
| 5334 |
if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) { |
| 5335 |
console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`); |
| 5336 |
return; |
| 5337 |
} |
| 5338 |
if (this.pdfHistory) { |
| 5339 |
this.pdfHistory.pushCurrentPosition(); |
| 5340 |
this.pdfHistory.pushPage(pageNumber); |
| 5341 |
} |
| 5342 |
this.pdfViewer.scrollPageIntoView({ |
| 5343 |
pageNumber |
| 5344 |
}); |
| 5345 |
} |
| 5346 |
addLinkAttributes(link, url, newWindow = false) { |
| 5347 |
if (!url || typeof url !== "string") { |
| 5348 |
throw new Error('A valid "url" parameter must provided.'); |
| 5349 |
} |
| 5350 |
const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget, |
| 5351 |
rel = this.externalLinkRel; |
| 5352 |
if (this.externalLinkEnabled) { |
| 5353 |
link.href = link.title = url; |
| 5354 |
} else { |
| 5355 |
link.href = ""; |
| 5356 |
link.title = `Disabled: ${url}`; |
| 5357 |
link.onclick = () => false; |
| 5358 |
} |
| 5359 |
let targetStr = ""; |
| 5360 |
switch (target) { |
| 5361 |
case LinkTarget.NONE: |
| 5362 |
break; |
| 5363 |
case LinkTarget.SELF: |
| 5364 |
targetStr = "_self"; |
| 5365 |
break; |
| 5366 |
case LinkTarget.BLANK: |
| 5367 |
targetStr = "_blank"; |
| 5368 |
break; |
| 5369 |
case LinkTarget.PARENT: |
| 5370 |
targetStr = "_parent"; |
| 5371 |
break; |
| 5372 |
case LinkTarget.TOP: |
| 5373 |
targetStr = "_top"; |
| 5374 |
break; |
| 5375 |
} |
| 5376 |
link.target = targetStr; |
| 5377 |
link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL; |
| 5378 |
} |
| 5379 |
getDestinationHash(dest) { |
| 5380 |
if (typeof dest === "string") { |
| 5381 |
if (dest.length > 0) { |
| 5382 |
return this.getAnchorUrl("#" + escape(dest)); |
| 5383 |
} |
| 5384 |
} else if (Array.isArray(dest)) { |
| 5385 |
const str = JSON.stringify(dest); |
| 5386 |
if (str.length > 0) { |
| 5387 |
return this.getAnchorUrl("#" + escape(str)); |
| 5388 |
} |
| 5389 |
} |
| 5390 |
return this.getAnchorUrl(""); |
| 5391 |
} |
| 5392 |
getAnchorUrl(anchor) { |
| 5393 |
return this.baseUrl ? this.baseUrl + anchor : anchor; |
| 5394 |
} |
| 5395 |
setHash(hash) { |
| 5396 |
if (!this.pdfDocument) { |
| 5397 |
return; |
| 5398 |
} |
| 5399 |
let pageNumber, dest; |
| 5400 |
if (hash.includes("=")) { |
| 5401 |
const params = parseQueryString(hash); |
| 5402 |
if (params.has("search")) { |
| 5403 |
const query = params.get("search").replaceAll('"', ""), |
| 5404 |
phrase = params.get("phrase") === "true"; |
| 5405 |
this.eventBus.dispatch("findfromurlhash", { |
| 5406 |
source: this, |
| 5407 |
query: phrase ? query : query.match(/\S+/g) |
| 5408 |
}); |
| 5409 |
} |
| 5410 |
if (params.has("page")) { |
| 5411 |
pageNumber = params.get("page") | 0 || 1; |
| 5412 |
} |
| 5413 |
if (params.has("zoom")) { |
| 5414 |
const zoomArgs = params.get("zoom").split(","); |
| 5415 |
const zoomArg = zoomArgs[0]; |
| 5416 |
const zoomArgNumber = parseFloat(zoomArg); |
| 5417 |
if (!zoomArg.includes("Fit")) { |
| 5418 |
dest = [null, { |
| 5419 |
name: "XYZ" |
| 5420 |
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg]; |
| 5421 |
} else if (zoomArg === "Fit" || zoomArg === "FitB") { |
| 5422 |
dest = [null, { |
| 5423 |
name: zoomArg |
| 5424 |
}]; |
| 5425 |
} else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") { |
| 5426 |
dest = [null, { |
| 5427 |
name: zoomArg |
| 5428 |
}, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null]; |
| 5429 |
} else if (zoomArg === "FitR") { |
| 5430 |
if (zoomArgs.length !== 5) { |
| 5431 |
console.error('PDFLinkService.setHash: Not enough parameters for "FitR".'); |
| 5432 |
} else { |
| 5433 |
dest = [null, { |
| 5434 |
name: zoomArg |
| 5435 |
}, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0]; |
| 5436 |
} |
| 5437 |
} else { |
| 5438 |
console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`); |
| 5439 |
} |
| 5440 |
} |
| 5441 |
if (dest) { |
| 5442 |
this.pdfViewer.scrollPageIntoView({ |
| 5443 |
pageNumber: pageNumber || this.page, |
| 5444 |
destArray: dest, |
| 5445 |
allowNegativeOffset: true |
| 5446 |
}); |
| 5447 |
} else if (pageNumber) { |
| 5448 |
this.page = pageNumber; |
| 5449 |
} |
| 5450 |
if (params.has("pagemode")) { |
| 5451 |
this.eventBus.dispatch("pagemode", { |
| 5452 |
source: this, |
| 5453 |
mode: params.get("pagemode") |
| 5454 |
}); |
| 5455 |
} |
| 5456 |
if (params.has("nameddest")) { |
| 5457 |
this.goToDestination(params.get("nameddest")); |
| 5458 |
} |
| 5459 |
return; |
| 5460 |
} |
| 5461 |
dest = unescape(hash); |
| 5462 |
try { |
| 5463 |
dest = JSON.parse(dest); |
| 5464 |
if (!Array.isArray(dest)) { |
| 5465 |
dest = dest.toString(); |
| 5466 |
} |
| 5467 |
} catch {} |
| 5468 |
if (typeof dest === "string" || isValidExplicitDest(dest)) { |
| 5469 |
this.goToDestination(dest); |
| 5470 |
return; |
| 5471 |
} |
| 5472 |
console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`); |
| 5473 |
} |
| 5474 |
executeNamedAction(action) { |
| 5475 |
if (!this.pdfDocument) { |
| 5476 |
return; |
| 5477 |
} |
| 5478 |
switch (action) { |
| 5479 |
case "GoBack": |
| 5480 |
this.pdfHistory?.back(); |
| 5481 |
break; |
| 5482 |
case "GoForward": |
| 5483 |
this.pdfHistory?.forward(); |
| 5484 |
break; |
| 5485 |
case "NextPage": |
| 5486 |
this.pdfViewer.nextPage(); |
| 5487 |
break; |
| 5488 |
case "PrevPage": |
| 5489 |
this.pdfViewer.previousPage(); |
| 5490 |
break; |
| 5491 |
case "LastPage": |
| 5492 |
this.page = this.pagesCount; |
| 5493 |
break; |
| 5494 |
case "FirstPage": |
| 5495 |
this.page = 1; |
| 5496 |
break; |
| 5497 |
default: |
| 5498 |
break; |
| 5499 |
} |
| 5500 |
this.eventBus.dispatch("namedaction", { |
| 5501 |
source: this, |
| 5502 |
action |
| 5503 |
}); |
| 5504 |
} |
| 5505 |
async executeSetOCGState(action) { |
| 5506 |
if (!this.pdfDocument) { |
| 5507 |
return; |
| 5508 |
} |
| 5509 |
const pdfDocument = this.pdfDocument, |
| 5510 |
optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise; |
| 5511 |
if (pdfDocument !== this.pdfDocument) { |
| 5512 |
return; |
| 5513 |
} |
| 5514 |
optionalContentConfig.setOCGState(action); |
| 5515 |
this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig); |
| 5516 |
} |
| 5517 |
} |
| 5518 |
class SimpleLinkService extends PDFLinkService { |
| 5519 |
setDocument(pdfDocument, baseUrl = null) {} |
| 5520 |
} |
| 5521 |
|
| 5522 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.constructor.js |
| 5523 |
var es_iterator_constructor = __webpack_require__(8111); |
| 5524 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.some.js |
| 5525 |
var es_iterator_some = __webpack_require__(3579); |
| 5526 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.promise.with-resolvers.js |
| 5527 |
var es_promise_with_resolvers = __webpack_require__(4628); |
| 5528 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/web.url.parse.js |
| 5529 |
var web_url_parse = __webpack_require__(5781); |
| 5530 |
;// ./web/event_utils.js |
| 5531 |
|
| 5532 |
|
| 5533 |
const WaitOnType = { |
| 5534 |
EVENT: "event", |
| 5535 |
TIMEOUT: "timeout" |
| 5536 |
}; |
| 5537 |
async function waitOnEventOrTimeout({ |
| 5538 |
target, |
| 5539 |
name, |
| 5540 |
delay = 0 |
| 5541 |
}) { |
| 5542 |
if (typeof target !== "object" || !(name && typeof name === "string") || !(Number.isInteger(delay) && delay >= 0)) { |
| 5543 |
throw new Error("waitOnEventOrTimeout - invalid parameters."); |
| 5544 |
} |
| 5545 |
const { |
| 5546 |
promise, |
| 5547 |
resolve |
| 5548 |
} = Promise.withResolvers(); |
| 5549 |
const ac = new AbortController(); |
| 5550 |
function handler(type) { |
| 5551 |
ac.abort(); |
| 5552 |
clearTimeout(timeout); |
| 5553 |
resolve(type); |
| 5554 |
} |
| 5555 |
const evtMethod = target instanceof EventBus ? "_on" : "addEventListener"; |
| 5556 |
target[evtMethod](name, handler.bind(null, WaitOnType.EVENT), { |
| 5557 |
signal: ac.signal |
| 5558 |
}); |
| 5559 |
const timeout = setTimeout(handler.bind(null, WaitOnType.TIMEOUT), delay); |
| 5560 |
return promise; |
| 5561 |
} |
| 5562 |
class EventBus { |
| 5563 |
#listeners = Object.create(null); |
| 5564 |
on(eventName, listener, options = null) { |
| 5565 |
this._on(eventName, listener, { |
| 5566 |
external: true, |
| 5567 |
once: options?.once, |
| 5568 |
signal: options?.signal |
| 5569 |
}); |
| 5570 |
} |
| 5571 |
off(eventName, listener, options = null) { |
| 5572 |
this._off(eventName, listener); |
| 5573 |
} |
| 5574 |
dispatch(eventName, data) { |
| 5575 |
const eventListeners = this.#listeners[eventName]; |
| 5576 |
if (!eventListeners || eventListeners.length === 0) { |
| 5577 |
return; |
| 5578 |
} |
| 5579 |
let externalListeners; |
| 5580 |
for (const { |
| 5581 |
listener, |
| 5582 |
external, |
| 5583 |
once |
| 5584 |
} of eventListeners.slice(0)) { |
| 5585 |
if (once) { |
| 5586 |
this._off(eventName, listener); |
| 5587 |
} |
| 5588 |
if (external) { |
| 5589 |
(externalListeners ||= []).push(listener); |
| 5590 |
continue; |
| 5591 |
} |
| 5592 |
listener(data); |
| 5593 |
} |
| 5594 |
if (externalListeners) { |
| 5595 |
for (const listener of externalListeners) { |
| 5596 |
listener(data); |
| 5597 |
} |
| 5598 |
externalListeners = null; |
| 5599 |
} |
| 5600 |
} |
| 5601 |
_on(eventName, listener, options = null) { |
| 5602 |
let rmAbort = null; |
| 5603 |
if (options?.signal instanceof AbortSignal) { |
| 5604 |
const { |
| 5605 |
signal |
| 5606 |
} = options; |
| 5607 |
if (signal.aborted) { |
| 5608 |
console.error("Cannot use an `aborted` signal."); |
| 5609 |
return; |
| 5610 |
} |
| 5611 |
const onAbort = () => this._off(eventName, listener); |
| 5612 |
rmAbort = () => signal.removeEventListener("abort", onAbort); |
| 5613 |
signal.addEventListener("abort", onAbort); |
| 5614 |
} |
| 5615 |
const eventListeners = this.#listeners[eventName] ||= []; |
| 5616 |
eventListeners.push({ |
| 5617 |
listener, |
| 5618 |
external: options?.external === true, |
| 5619 |
once: options?.once === true, |
| 5620 |
rmAbort |
| 5621 |
}); |
| 5622 |
} |
| 5623 |
_off(eventName, listener, options = null) { |
| 5624 |
const eventListeners = this.#listeners[eventName]; |
| 5625 |
if (!eventListeners) { |
| 5626 |
return; |
| 5627 |
} |
| 5628 |
for (let i = 0, ii = eventListeners.length; i < ii; i++) { |
| 5629 |
const evt = eventListeners[i]; |
| 5630 |
if (evt.listener === listener) { |
| 5631 |
evt.rmAbort?.(); |
| 5632 |
eventListeners.splice(i, 1); |
| 5633 |
return; |
| 5634 |
} |
| 5635 |
} |
| 5636 |
} |
| 5637 |
} |
| 5638 |
class FirefoxEventBus extends EventBus { |
| 5639 |
#externalServices; |
| 5640 |
#globalEventNames; |
| 5641 |
#isInAutomation; |
| 5642 |
constructor(globalEventNames, externalServices, isInAutomation) { |
| 5643 |
super(); |
| 5644 |
this.#globalEventNames = globalEventNames; |
| 5645 |
this.#externalServices = externalServices; |
| 5646 |
this.#isInAutomation = isInAutomation; |
| 5647 |
} |
| 5648 |
dispatch(eventName, data) { |
| 5649 |
throw new Error("Not implemented: FirefoxEventBus.dispatch"); |
| 5650 |
} |
| 5651 |
} |
| 5652 |
|
| 5653 |
;// ./web/external_services.js |
| 5654 |
class BaseExternalServices { |
| 5655 |
updateFindControlState(data) {} |
| 5656 |
updateFindMatchesCount(data) {} |
| 5657 |
initPassiveLoading() {} |
| 5658 |
reportTelemetry(data) {} |
| 5659 |
async createL10n() { |
| 5660 |
throw new Error("Not implemented: createL10n"); |
| 5661 |
} |
| 5662 |
createScripting() { |
| 5663 |
throw new Error("Not implemented: createScripting"); |
| 5664 |
} |
| 5665 |
createSignatureStorage() { |
| 5666 |
throw new Error("Not implemented: createSignatureStorage"); |
| 5667 |
} |
| 5668 |
updateEditorStates(data) { |
| 5669 |
throw new Error("Not implemented: updateEditorStates"); |
| 5670 |
} |
| 5671 |
dispatchGlobalEvent(_event) {} |
| 5672 |
} |
| 5673 |
|
| 5674 |
;// ./web/preferences.js |
| 5675 |
|
| 5676 |
class BasePreferences { |
| 5677 |
#defaults = Object.freeze({ |
| 5678 |
altTextLearnMoreUrl: "", |
| 5679 |
annotationEditorMode: 0, |
| 5680 |
annotationMode: 2, |
| 5681 |
capCanvasAreaFactor: 200, |
| 5682 |
cursorToolOnLoad: 0, |
| 5683 |
defaultZoomDelay: 400, |
| 5684 |
defaultZoomValue: "", |
| 5685 |
disablePageLabels: false, |
| 5686 |
enableAltText: false, |
| 5687 |
enableAltTextModelDownload: true, |
| 5688 |
enableAutoLinking: true, |
| 5689 |
enableGuessAltText: true, |
| 5690 |
enableHighlightFloatingButton: false, |
| 5691 |
enableNewAltTextWhenAddingImage: true, |
| 5692 |
enablePermissions: false, |
| 5693 |
enablePrintAutoRotate: true, |
| 5694 |
enableScripting: true, |
| 5695 |
enableSignatureEditor: false, |
| 5696 |
enableUpdatedAddImage: false, |
| 5697 |
externalLinkTarget: 0, |
| 5698 |
highlightEditorColors: "yellow=#FFFF98,green=#53FFBC,blue=#80EBFF,pink=#FFCBE6,red=#FF4F5F", |
| 5699 |
historyUpdateUrl: false, |
| 5700 |
ignoreDestinationZoom: false, |
| 5701 |
forcePageColors: false, |
| 5702 |
pageColorsBackground: "Canvas", |
| 5703 |
pageColorsForeground: "CanvasText", |
| 5704 |
pdfBugEnabled: false, |
| 5705 |
sidebarViewOnLoad: -1, |
| 5706 |
scrollModeOnLoad: -1, |
| 5707 |
spreadModeOnLoad: -1, |
| 5708 |
textLayerMode: 1, |
| 5709 |
viewerCssTheme: 0, |
| 5710 |
viewOnLoad: 0, |
| 5711 |
disableAutoFetch: false, |
| 5712 |
disableFontFace: false, |
| 5713 |
disableRange: false, |
| 5714 |
disableStream: false, |
| 5715 |
enableHWA: true, |
| 5716 |
enableXfa: true |
| 5717 |
}); |
| 5718 |
#initializedPromise = null; |
| 5719 |
constructor() { |
| 5720 |
this.#initializedPromise = this._readFromStorage(this.#defaults).then(({ |
| 5721 |
browserPrefs, |
| 5722 |
prefs |
| 5723 |
}) => { |
| 5724 |
if (AppOptions._checkDisablePreferences()) { |
| 5725 |
return; |
| 5726 |
} |
| 5727 |
AppOptions.setAll({ |
| 5728 |
...browserPrefs, |
| 5729 |
...prefs |
| 5730 |
}, true); |
| 5731 |
}); |
| 5732 |
} |
| 5733 |
async _writeToStorage(prefObj) { |
| 5734 |
throw new Error("Not implemented: _writeToStorage"); |
| 5735 |
} |
| 5736 |
async _readFromStorage(prefObj) { |
| 5737 |
throw new Error("Not implemented: _readFromStorage"); |
| 5738 |
} |
| 5739 |
async reset() { |
| 5740 |
await this.#initializedPromise; |
| 5741 |
AppOptions.setAll(this.#defaults, true); |
| 5742 |
await this._writeToStorage(this.#defaults); |
| 5743 |
} |
| 5744 |
async set(name, value) { |
| 5745 |
await this.#initializedPromise; |
| 5746 |
AppOptions.setAll({ |
| 5747 |
[name]: value |
| 5748 |
}, true); |
| 5749 |
await this._writeToStorage(AppOptions.getAll(OptionKind.PREFERENCE)); |
| 5750 |
} |
| 5751 |
async get(name) { |
| 5752 |
await this.#initializedPromise; |
| 5753 |
return AppOptions.get(name); |
| 5754 |
} |
| 5755 |
get initializedPromise() { |
| 5756 |
return this.#initializedPromise; |
| 5757 |
} |
| 5758 |
} |
| 5759 |
|
| 5760 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.map.js |
| 5761 |
var es_iterator_map = __webpack_require__(1701); |
| 5762 |
;// ./node_modules/@fluent/bundle/esm/types.js |
| 5763 |
class FluentType { |
| 5764 |
constructor(value) { |
| 5765 |
this.value = value; |
| 5766 |
} |
| 5767 |
valueOf() { |
| 5768 |
return this.value; |
| 5769 |
} |
| 5770 |
} |
| 5771 |
class FluentNone extends FluentType { |
| 5772 |
constructor(value = "???") { |
| 5773 |
super(value); |
| 5774 |
} |
| 5775 |
toString(scope) { |
| 5776 |
return `{${this.value}}`; |
| 5777 |
} |
| 5778 |
} |
| 5779 |
class FluentNumber extends FluentType { |
| 5780 |
constructor(value, opts = {}) { |
| 5781 |
super(value); |
| 5782 |
this.opts = opts; |
| 5783 |
} |
| 5784 |
toString(scope) { |
| 5785 |
if (scope) { |
| 5786 |
try { |
| 5787 |
const nf = scope.memoizeIntlObject(Intl.NumberFormat, this.opts); |
| 5788 |
return nf.format(this.value); |
| 5789 |
} catch (err) { |
| 5790 |
scope.reportError(err); |
| 5791 |
} |
| 5792 |
} |
| 5793 |
return this.value.toString(10); |
| 5794 |
} |
| 5795 |
} |
| 5796 |
class FluentDateTime extends FluentType { |
| 5797 |
static supportsValue(value) { |
| 5798 |
if (typeof value === "number") return true; |
| 5799 |
if (value instanceof Date) return true; |
| 5800 |
if (value instanceof FluentType) return FluentDateTime.supportsValue(value.valueOf()); |
| 5801 |
if ("Temporal" in globalThis) { |
| 5802 |
const _Temporal = globalThis.Temporal; |
| 5803 |
if (value instanceof _Temporal.Instant || value instanceof _Temporal.PlainDateTime || value instanceof _Temporal.PlainDate || value instanceof _Temporal.PlainMonthDay || value instanceof _Temporal.PlainTime || value instanceof _Temporal.PlainYearMonth) { |
| 5804 |
return true; |
| 5805 |
} |
| 5806 |
} |
| 5807 |
return false; |
| 5808 |
} |
| 5809 |
constructor(value, opts = {}) { |
| 5810 |
if (value instanceof FluentDateTime) { |
| 5811 |
opts = { |
| 5812 |
...value.opts, |
| 5813 |
...opts |
| 5814 |
}; |
| 5815 |
value = value.value; |
| 5816 |
} else if (value instanceof FluentType) { |
| 5817 |
value = value.valueOf(); |
| 5818 |
} |
| 5819 |
if (typeof value === "object" && "calendarId" in value && opts.calendar === undefined) { |
| 5820 |
opts = { |
| 5821 |
...opts, |
| 5822 |
calendar: value.calendarId |
| 5823 |
}; |
| 5824 |
} |
| 5825 |
super(value); |
| 5826 |
this.opts = opts; |
| 5827 |
} |
| 5828 |
[Symbol.toPrimitive](hint) { |
| 5829 |
return hint === "string" ? this.toString() : this.toNumber(); |
| 5830 |
} |
| 5831 |
toNumber() { |
| 5832 |
const value = this.value; |
| 5833 |
if (typeof value === "number") return value; |
| 5834 |
if (value instanceof Date) return value.getTime(); |
| 5835 |
if ("epochMilliseconds" in value) { |
| 5836 |
return value.epochMilliseconds; |
| 5837 |
} |
| 5838 |
if ("toZonedDateTime" in value) { |
| 5839 |
return value.toZonedDateTime("UTC").epochMilliseconds; |
| 5840 |
} |
| 5841 |
throw new TypeError("Unwrapping a non-number value as a number"); |
| 5842 |
} |
| 5843 |
toString(scope) { |
| 5844 |
if (scope) { |
| 5845 |
try { |
| 5846 |
const dtf = scope.memoizeIntlObject(Intl.DateTimeFormat, this.opts); |
| 5847 |
return dtf.format(this.value); |
| 5848 |
} catch (err) { |
| 5849 |
scope.reportError(err); |
| 5850 |
} |
| 5851 |
} |
| 5852 |
if (typeof this.value === "number" || this.value instanceof Date) { |
| 5853 |
return new Date(this.value).toISOString(); |
| 5854 |
} |
| 5855 |
return this.value.toString(); |
| 5856 |
} |
| 5857 |
} |
| 5858 |
;// ./node_modules/@fluent/bundle/esm/resolver.js |
| 5859 |
|
| 5860 |
|
| 5861 |
const MAX_PLACEABLES = 100; |
| 5862 |
const FSI = "\u2068"; |
| 5863 |
const PDI = "\u2069"; |
| 5864 |
function match(scope, selector, key) { |
| 5865 |
if (key === selector) { |
| 5866 |
return true; |
| 5867 |
} |
| 5868 |
if (key instanceof FluentNumber && selector instanceof FluentNumber && key.value === selector.value) { |
| 5869 |
return true; |
| 5870 |
} |
| 5871 |
if (selector instanceof FluentNumber && typeof key === "string") { |
| 5872 |
let category = scope.memoizeIntlObject(Intl.PluralRules, selector.opts).select(selector.value); |
| 5873 |
if (key === category) { |
| 5874 |
return true; |
| 5875 |
} |
| 5876 |
} |
| 5877 |
return false; |
| 5878 |
} |
| 5879 |
function getDefault(scope, variants, star) { |
| 5880 |
if (variants[star]) { |
| 5881 |
return resolvePattern(scope, variants[star].value); |
| 5882 |
} |
| 5883 |
scope.reportError(new RangeError("No default")); |
| 5884 |
return new FluentNone(); |
| 5885 |
} |
| 5886 |
function getArguments(scope, args) { |
| 5887 |
const positional = []; |
| 5888 |
const named = Object.create(null); |
| 5889 |
for (const arg of args) { |
| 5890 |
if (arg.type === "narg") { |
| 5891 |
named[arg.name] = resolveExpression(scope, arg.value); |
| 5892 |
} else { |
| 5893 |
positional.push(resolveExpression(scope, arg)); |
| 5894 |
} |
| 5895 |
} |
| 5896 |
return { |
| 5897 |
positional, |
| 5898 |
named |
| 5899 |
}; |
| 5900 |
} |
| 5901 |
function resolveExpression(scope, expr) { |
| 5902 |
switch (expr.type) { |
| 5903 |
case "str": |
| 5904 |
return expr.value; |
| 5905 |
case "num": |
| 5906 |
return new FluentNumber(expr.value, { |
| 5907 |
minimumFractionDigits: expr.precision |
| 5908 |
}); |
| 5909 |
case "var": |
| 5910 |
return resolveVariableReference(scope, expr); |
| 5911 |
case "mesg": |
| 5912 |
return resolveMessageReference(scope, expr); |
| 5913 |
case "term": |
| 5914 |
return resolveTermReference(scope, expr); |
| 5915 |
case "func": |
| 5916 |
return resolveFunctionReference(scope, expr); |
| 5917 |
case "select": |
| 5918 |
return resolveSelectExpression(scope, expr); |
| 5919 |
default: |
| 5920 |
return new FluentNone(); |
| 5921 |
} |
| 5922 |
} |
| 5923 |
function resolveVariableReference(scope, { |
| 5924 |
name |
| 5925 |
}) { |
| 5926 |
let arg; |
| 5927 |
if (scope.params) { |
| 5928 |
if (Object.prototype.hasOwnProperty.call(scope.params, name)) { |
| 5929 |
arg = scope.params[name]; |
| 5930 |
} else { |
| 5931 |
return new FluentNone(`$${name}`); |
| 5932 |
} |
| 5933 |
} else if (scope.args && Object.prototype.hasOwnProperty.call(scope.args, name)) { |
| 5934 |
arg = scope.args[name]; |
| 5935 |
} else { |
| 5936 |
scope.reportError(new ReferenceError(`Unknown variable: $${name}`)); |
| 5937 |
return new FluentNone(`$${name}`); |
| 5938 |
} |
| 5939 |
if (arg instanceof FluentType) { |
| 5940 |
return arg; |
| 5941 |
} |
| 5942 |
switch (typeof arg) { |
| 5943 |
case "string": |
| 5944 |
return arg; |
| 5945 |
case "number": |
| 5946 |
return new FluentNumber(arg); |
| 5947 |
case "object": |
| 5948 |
if (FluentDateTime.supportsValue(arg)) { |
| 5949 |
return new FluentDateTime(arg); |
| 5950 |
} |
| 5951 |
default: |
| 5952 |
scope.reportError(new TypeError(`Variable type not supported: $${name}, ${typeof arg}`)); |
| 5953 |
return new FluentNone(`$${name}`); |
| 5954 |
} |
| 5955 |
} |
| 5956 |
function resolveMessageReference(scope, { |
| 5957 |
name, |
| 5958 |
attr |
| 5959 |
}) { |
| 5960 |
const message = scope.bundle._messages.get(name); |
| 5961 |
if (!message) { |
| 5962 |
scope.reportError(new ReferenceError(`Unknown message: ${name}`)); |
| 5963 |
return new FluentNone(name); |
| 5964 |
} |
| 5965 |
if (attr) { |
| 5966 |
const attribute = message.attributes[attr]; |
| 5967 |
if (attribute) { |
| 5968 |
return resolvePattern(scope, attribute); |
| 5969 |
} |
| 5970 |
scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`)); |
| 5971 |
return new FluentNone(`${name}.${attr}`); |
| 5972 |
} |
| 5973 |
if (message.value) { |
| 5974 |
return resolvePattern(scope, message.value); |
| 5975 |
} |
| 5976 |
scope.reportError(new ReferenceError(`No value: ${name}`)); |
| 5977 |
return new FluentNone(name); |
| 5978 |
} |
| 5979 |
function resolveTermReference(scope, { |
| 5980 |
name, |
| 5981 |
attr, |
| 5982 |
args |
| 5983 |
}) { |
| 5984 |
const id = `-${name}`; |
| 5985 |
const term = scope.bundle._terms.get(id); |
| 5986 |
if (!term) { |
| 5987 |
scope.reportError(new ReferenceError(`Unknown term: ${id}`)); |
| 5988 |
return new FluentNone(id); |
| 5989 |
} |
| 5990 |
if (attr) { |
| 5991 |
const attribute = term.attributes[attr]; |
| 5992 |
if (attribute) { |
| 5993 |
scope.params = getArguments(scope, args).named; |
| 5994 |
const resolved = resolvePattern(scope, attribute); |
| 5995 |
scope.params = null; |
| 5996 |
return resolved; |
| 5997 |
} |
| 5998 |
scope.reportError(new ReferenceError(`Unknown attribute: ${attr}`)); |
| 5999 |
return new FluentNone(`${id}.${attr}`); |
| 6000 |
} |
| 6001 |
scope.params = getArguments(scope, args).named; |
| 6002 |
const resolved = resolvePattern(scope, term.value); |
| 6003 |
scope.params = null; |
| 6004 |
return resolved; |
| 6005 |
} |
| 6006 |
function resolveFunctionReference(scope, { |
| 6007 |
name, |
| 6008 |
args |
| 6009 |
}) { |
| 6010 |
let func = scope.bundle._functions[name]; |
| 6011 |
if (!func) { |
| 6012 |
scope.reportError(new ReferenceError(`Unknown function: ${name}()`)); |
| 6013 |
return new FluentNone(`${name}()`); |
| 6014 |
} |
| 6015 |
if (typeof func !== "function") { |
| 6016 |
scope.reportError(new TypeError(`Function ${name}() is not callable`)); |
| 6017 |
return new FluentNone(`${name}()`); |
| 6018 |
} |
| 6019 |
try { |
| 6020 |
let resolved = getArguments(scope, args); |
| 6021 |
return func(resolved.positional, resolved.named); |
| 6022 |
} catch (err) { |
| 6023 |
scope.reportError(err); |
| 6024 |
return new FluentNone(`${name}()`); |
| 6025 |
} |
| 6026 |
} |
| 6027 |
function resolveSelectExpression(scope, { |
| 6028 |
selector, |
| 6029 |
variants, |
| 6030 |
star |
| 6031 |
}) { |
| 6032 |
let sel = resolveExpression(scope, selector); |
| 6033 |
if (sel instanceof FluentNone) { |
| 6034 |
return getDefault(scope, variants, star); |
| 6035 |
} |
| 6036 |
for (const variant of variants) { |
| 6037 |
const key = resolveExpression(scope, variant.key); |
| 6038 |
if (match(scope, sel, key)) { |
| 6039 |
return resolvePattern(scope, variant.value); |
| 6040 |
} |
| 6041 |
} |
| 6042 |
return getDefault(scope, variants, star); |
| 6043 |
} |
| 6044 |
function resolveComplexPattern(scope, ptn) { |
| 6045 |
if (scope.dirty.has(ptn)) { |
| 6046 |
scope.reportError(new RangeError("Cyclic reference")); |
| 6047 |
return new FluentNone(); |
| 6048 |
} |
| 6049 |
scope.dirty.add(ptn); |
| 6050 |
const result = []; |
| 6051 |
const useIsolating = scope.bundle._useIsolating && ptn.length > 1; |
| 6052 |
for (const elem of ptn) { |
| 6053 |
if (typeof elem === "string") { |
| 6054 |
result.push(scope.bundle._transform(elem)); |
| 6055 |
continue; |
| 6056 |
} |
| 6057 |
scope.placeables++; |
| 6058 |
if (scope.placeables > MAX_PLACEABLES) { |
| 6059 |
scope.dirty.delete(ptn); |
| 6060 |
throw new RangeError(`Too many placeables expanded: ${scope.placeables}, ` + `max allowed is ${MAX_PLACEABLES}`); |
| 6061 |
} |
| 6062 |
if (useIsolating) { |
| 6063 |
result.push(FSI); |
| 6064 |
} |
| 6065 |
result.push(resolveExpression(scope, elem).toString(scope)); |
| 6066 |
if (useIsolating) { |
| 6067 |
result.push(PDI); |
| 6068 |
} |
| 6069 |
} |
| 6070 |
scope.dirty.delete(ptn); |
| 6071 |
return result.join(""); |
| 6072 |
} |
| 6073 |
function resolvePattern(scope, value) { |
| 6074 |
if (typeof value === "string") { |
| 6075 |
return scope.bundle._transform(value); |
| 6076 |
} |
| 6077 |
return resolveComplexPattern(scope, value); |
| 6078 |
} |
| 6079 |
;// ./node_modules/@fluent/bundle/esm/scope.js |
| 6080 |
|
| 6081 |
class Scope { |
| 6082 |
constructor(bundle, errors, args) { |
| 6083 |
this.dirty = new WeakSet(); |
| 6084 |
this.params = null; |
| 6085 |
this.placeables = 0; |
| 6086 |
this.bundle = bundle; |
| 6087 |
this.errors = errors; |
| 6088 |
this.args = args; |
| 6089 |
} |
| 6090 |
reportError(error) { |
| 6091 |
if (!this.errors || !(error instanceof Error)) { |
| 6092 |
throw error; |
| 6093 |
} |
| 6094 |
this.errors.push(error); |
| 6095 |
} |
| 6096 |
memoizeIntlObject(ctor, opts) { |
| 6097 |
let cache = this.bundle._intls.get(ctor); |
| 6098 |
if (!cache) { |
| 6099 |
cache = {}; |
| 6100 |
this.bundle._intls.set(ctor, cache); |
| 6101 |
} |
| 6102 |
let id = JSON.stringify(opts); |
| 6103 |
if (!cache[id]) { |
| 6104 |
cache[id] = new ctor(this.bundle.locales, opts); |
| 6105 |
} |
| 6106 |
return cache[id]; |
| 6107 |
} |
| 6108 |
} |
| 6109 |
;// ./node_modules/@fluent/bundle/esm/builtins.js |
| 6110 |
|
| 6111 |
function values(opts, allowed) { |
| 6112 |
const unwrapped = Object.create(null); |
| 6113 |
for (const [name, opt] of Object.entries(opts)) { |
| 6114 |
if (allowed.includes(name)) { |
| 6115 |
unwrapped[name] = opt.valueOf(); |
| 6116 |
} |
| 6117 |
} |
| 6118 |
return unwrapped; |
| 6119 |
} |
| 6120 |
const NUMBER_ALLOWED = ["unitDisplay", "currencyDisplay", "useGrouping", "minimumIntegerDigits", "minimumFractionDigits", "maximumFractionDigits", "minimumSignificantDigits", "maximumSignificantDigits"]; |
| 6121 |
function NUMBER(args, opts) { |
| 6122 |
let arg = args[0]; |
| 6123 |
if (arg instanceof FluentNone) { |
| 6124 |
return new FluentNone(`NUMBER(${arg.valueOf()})`); |
| 6125 |
} |
| 6126 |
if (arg instanceof FluentNumber) { |
| 6127 |
return new FluentNumber(arg.valueOf(), { |
| 6128 |
...arg.opts, |
| 6129 |
...values(opts, NUMBER_ALLOWED) |
| 6130 |
}); |
| 6131 |
} |
| 6132 |
if (arg instanceof FluentDateTime) { |
| 6133 |
return new FluentNumber(arg.toNumber(), { |
| 6134 |
...values(opts, NUMBER_ALLOWED) |
| 6135 |
}); |
| 6136 |
} |
| 6137 |
throw new TypeError("Invalid argument to NUMBER"); |
| 6138 |
} |
| 6139 |
const DATETIME_ALLOWED = ["dateStyle", "timeStyle", "fractionalSecondDigits", "dayPeriod", "hour12", "weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"]; |
| 6140 |
function DATETIME(args, opts) { |
| 6141 |
let arg = args[0]; |
| 6142 |
if (arg instanceof FluentNone) { |
| 6143 |
return new FluentNone(`DATETIME(${arg.valueOf()})`); |
| 6144 |
} |
| 6145 |
if (arg instanceof FluentDateTime || arg instanceof FluentNumber) { |
| 6146 |
return new FluentDateTime(arg, values(opts, DATETIME_ALLOWED)); |
| 6147 |
} |
| 6148 |
throw new TypeError("Invalid argument to DATETIME"); |
| 6149 |
} |
| 6150 |
;// ./node_modules/@fluent/bundle/esm/memoizer.js |
| 6151 |
const cache = new Map(); |
| 6152 |
function getMemoizerForLocale(locales) { |
| 6153 |
const stringLocale = Array.isArray(locales) ? locales.join(" ") : locales; |
| 6154 |
let memoizer = cache.get(stringLocale); |
| 6155 |
if (memoizer === undefined) { |
| 6156 |
memoizer = new Map(); |
| 6157 |
cache.set(stringLocale, memoizer); |
| 6158 |
} |
| 6159 |
return memoizer; |
| 6160 |
} |
| 6161 |
;// ./node_modules/@fluent/bundle/esm/bundle.js |
| 6162 |
|
| 6163 |
|
| 6164 |
|
| 6165 |
|
| 6166 |
|
| 6167 |
|
| 6168 |
class FluentBundle { |
| 6169 |
constructor(locales, { |
| 6170 |
functions, |
| 6171 |
useIsolating = true, |
| 6172 |
transform = v => v |
| 6173 |
} = {}) { |
| 6174 |
this._terms = new Map(); |
| 6175 |
this._messages = new Map(); |
| 6176 |
this.locales = Array.isArray(locales) ? locales : [locales]; |
| 6177 |
this._functions = { |
| 6178 |
NUMBER: NUMBER, |
| 6179 |
DATETIME: DATETIME, |
| 6180 |
...functions |
| 6181 |
}; |
| 6182 |
this._useIsolating = useIsolating; |
| 6183 |
this._transform = transform; |
| 6184 |
this._intls = getMemoizerForLocale(locales); |
| 6185 |
} |
| 6186 |
hasMessage(id) { |
| 6187 |
return this._messages.has(id); |
| 6188 |
} |
| 6189 |
getMessage(id) { |
| 6190 |
return this._messages.get(id); |
| 6191 |
} |
| 6192 |
addResource(res, { |
| 6193 |
allowOverrides = false |
| 6194 |
} = {}) { |
| 6195 |
const errors = []; |
| 6196 |
for (let i = 0; i < res.body.length; i++) { |
| 6197 |
let entry = res.body[i]; |
| 6198 |
if (entry.id.startsWith("-")) { |
| 6199 |
if (allowOverrides === false && this._terms.has(entry.id)) { |
| 6200 |
errors.push(new Error(`Attempt to override an existing term: "${entry.id}"`)); |
| 6201 |
continue; |
| 6202 |
} |
| 6203 |
this._terms.set(entry.id, entry); |
| 6204 |
} else { |
| 6205 |
if (allowOverrides === false && this._messages.has(entry.id)) { |
| 6206 |
errors.push(new Error(`Attempt to override an existing message: "${entry.id}"`)); |
| 6207 |
continue; |
| 6208 |
} |
| 6209 |
this._messages.set(entry.id, entry); |
| 6210 |
} |
| 6211 |
} |
| 6212 |
return errors; |
| 6213 |
} |
| 6214 |
formatPattern(pattern, args = null, errors = null) { |
| 6215 |
if (typeof pattern === "string") { |
| 6216 |
return this._transform(pattern); |
| 6217 |
} |
| 6218 |
let scope = new Scope(this, errors, args); |
| 6219 |
try { |
| 6220 |
let value = resolveComplexPattern(scope, pattern); |
| 6221 |
return value.toString(scope); |
| 6222 |
} catch (err) { |
| 6223 |
if (scope.errors && err instanceof Error) { |
| 6224 |
scope.errors.push(err); |
| 6225 |
return new FluentNone().toString(scope); |
| 6226 |
} |
| 6227 |
throw err; |
| 6228 |
} |
| 6229 |
} |
| 6230 |
} |
| 6231 |
;// ./node_modules/@fluent/bundle/esm/resource.js |
| 6232 |
|
| 6233 |
const RE_MESSAGE_START = /^(-?[a-zA-Z][\w-]*) *= */gm; |
| 6234 |
const RE_ATTRIBUTE_START = /\.([a-zA-Z][\w-]*) *= */y; |
| 6235 |
const RE_VARIANT_START = /\*?\[/y; |
| 6236 |
const RE_NUMBER_LITERAL = /(-?[0-9]+(?:\.([0-9]+))?)/y; |
| 6237 |
const RE_IDENTIFIER = /([a-zA-Z][\w-]*)/y; |
| 6238 |
const RE_REFERENCE = /([$-])?([a-zA-Z][\w-]*)(?:\.([a-zA-Z][\w-]*))?/y; |
| 6239 |
const RE_FUNCTION_NAME = /^[A-Z][A-Z0-9_-]*$/; |
| 6240 |
const RE_TEXT_RUN = /([^{}\n\r]+)/y; |
| 6241 |
const RE_STRING_RUN = /([^\\"\n\r]*)/y; |
| 6242 |
const RE_STRING_ESCAPE = /\\([\\"])/y; |
| 6243 |
const RE_UNICODE_ESCAPE = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{6})/y; |
| 6244 |
const RE_LEADING_NEWLINES = /^\n+/; |
| 6245 |
const RE_TRAILING_SPACES = / +$/; |
| 6246 |
const RE_BLANK_LINES = / *\r?\n/g; |
| 6247 |
const RE_INDENT = /( *)$/; |
| 6248 |
const TOKEN_BRACE_OPEN = /{\s*/y; |
| 6249 |
const TOKEN_BRACE_CLOSE = /\s*}/y; |
| 6250 |
const TOKEN_BRACKET_OPEN = /\[\s*/y; |
| 6251 |
const TOKEN_BRACKET_CLOSE = /\s*] */y; |
| 6252 |
const TOKEN_PAREN_OPEN = /\s*\(\s*/y; |
| 6253 |
const TOKEN_ARROW = /\s*->\s*/y; |
| 6254 |
const TOKEN_COLON = /\s*:\s*/y; |
| 6255 |
const TOKEN_COMMA = /\s*,?\s*/y; |
| 6256 |
const TOKEN_BLANK = /\s+/y; |
| 6257 |
class FluentResource { |
| 6258 |
constructor(source) { |
| 6259 |
this.body = []; |
| 6260 |
RE_MESSAGE_START.lastIndex = 0; |
| 6261 |
let cursor = 0; |
| 6262 |
while (true) { |
| 6263 |
let next = RE_MESSAGE_START.exec(source); |
| 6264 |
if (next === null) { |
| 6265 |
break; |
| 6266 |
} |
| 6267 |
cursor = RE_MESSAGE_START.lastIndex; |
| 6268 |
try { |
| 6269 |
this.body.push(parseMessage(next[1])); |
| 6270 |
} catch (err) { |
| 6271 |
if (err instanceof SyntaxError) { |
| 6272 |
continue; |
| 6273 |
} |
| 6274 |
throw err; |
| 6275 |
} |
| 6276 |
} |
| 6277 |
function test(re) { |
| 6278 |
re.lastIndex = cursor; |
| 6279 |
return re.test(source); |
| 6280 |
} |
| 6281 |
function consumeChar(char, errorClass) { |
| 6282 |
if (source[cursor] === char) { |
| 6283 |
cursor++; |
| 6284 |
return true; |
| 6285 |
} |
| 6286 |
if (errorClass) { |
| 6287 |
throw new errorClass(`Expected ${char}`); |
| 6288 |
} |
| 6289 |
return false; |
| 6290 |
} |
| 6291 |
function consumeToken(re, errorClass) { |
| 6292 |
if (test(re)) { |
| 6293 |
cursor = re.lastIndex; |
| 6294 |
return true; |
| 6295 |
} |
| 6296 |
if (errorClass) { |
| 6297 |
throw new errorClass(`Expected ${re.toString()}`); |
| 6298 |
} |
| 6299 |
return false; |
| 6300 |
} |
| 6301 |
function match(re) { |
| 6302 |
re.lastIndex = cursor; |
| 6303 |
let result = re.exec(source); |
| 6304 |
if (result === null) { |
| 6305 |
throw new SyntaxError(`Expected ${re.toString()}`); |
| 6306 |
} |
| 6307 |
cursor = re.lastIndex; |
| 6308 |
return result; |
| 6309 |
} |
| 6310 |
function match1(re) { |
| 6311 |
return match(re)[1]; |
| 6312 |
} |
| 6313 |
function parseMessage(id) { |
| 6314 |
let value = parsePattern(); |
| 6315 |
let attributes = parseAttributes(); |
| 6316 |
if (value === null && Object.keys(attributes).length === 0) { |
| 6317 |
throw new SyntaxError("Expected message value or attributes"); |
| 6318 |
} |
| 6319 |
return { |
| 6320 |
id, |
| 6321 |
value, |
| 6322 |
attributes |
| 6323 |
}; |
| 6324 |
} |
| 6325 |
function parseAttributes() { |
| 6326 |
let attrs = Object.create(null); |
| 6327 |
while (test(RE_ATTRIBUTE_START)) { |
| 6328 |
let name = match1(RE_ATTRIBUTE_START); |
| 6329 |
let value = parsePattern(); |
| 6330 |
if (value === null) { |
| 6331 |
throw new SyntaxError("Expected attribute value"); |
| 6332 |
} |
| 6333 |
attrs[name] = value; |
| 6334 |
} |
| 6335 |
return attrs; |
| 6336 |
} |
| 6337 |
function parsePattern() { |
| 6338 |
let first; |
| 6339 |
if (test(RE_TEXT_RUN)) { |
| 6340 |
first = match1(RE_TEXT_RUN); |
| 6341 |
} |
| 6342 |
if (source[cursor] === "{" || source[cursor] === "}") { |
| 6343 |
return parsePatternElements(first ? [first] : [], Infinity); |
| 6344 |
} |
| 6345 |
let indent = parseIndent(); |
| 6346 |
if (indent) { |
| 6347 |
if (first) { |
| 6348 |
return parsePatternElements([first, indent], indent.length); |
| 6349 |
} |
| 6350 |
indent.value = trim(indent.value, RE_LEADING_NEWLINES); |
| 6351 |
return parsePatternElements([indent], indent.length); |
| 6352 |
} |
| 6353 |
if (first) { |
| 6354 |
return trim(first, RE_TRAILING_SPACES); |
| 6355 |
} |
| 6356 |
return null; |
| 6357 |
} |
| 6358 |
function parsePatternElements(elements = [], commonIndent) { |
| 6359 |
while (true) { |
| 6360 |
if (test(RE_TEXT_RUN)) { |
| 6361 |
elements.push(match1(RE_TEXT_RUN)); |
| 6362 |
continue; |
| 6363 |
} |
| 6364 |
if (source[cursor] === "{") { |
| 6365 |
elements.push(parsePlaceable()); |
| 6366 |
continue; |
| 6367 |
} |
| 6368 |
if (source[cursor] === "}") { |
| 6369 |
throw new SyntaxError("Unbalanced closing brace"); |
| 6370 |
} |
| 6371 |
let indent = parseIndent(); |
| 6372 |
if (indent) { |
| 6373 |
elements.push(indent); |
| 6374 |
commonIndent = Math.min(commonIndent, indent.length); |
| 6375 |
continue; |
| 6376 |
} |
| 6377 |
break; |
| 6378 |
} |
| 6379 |
let lastIndex = elements.length - 1; |
| 6380 |
let lastElement = elements[lastIndex]; |
| 6381 |
if (typeof lastElement === "string") { |
| 6382 |
elements[lastIndex] = trim(lastElement, RE_TRAILING_SPACES); |
| 6383 |
} |
| 6384 |
let baked = []; |
| 6385 |
for (let element of elements) { |
| 6386 |
if (element instanceof Indent) { |
| 6387 |
element = element.value.slice(0, element.value.length - commonIndent); |
| 6388 |
} |
| 6389 |
if (element) { |
| 6390 |
baked.push(element); |
| 6391 |
} |
| 6392 |
} |
| 6393 |
return baked; |
| 6394 |
} |
| 6395 |
function parsePlaceable() { |
| 6396 |
consumeToken(TOKEN_BRACE_OPEN, SyntaxError); |
| 6397 |
let selector = parseInlineExpression(); |
| 6398 |
if (consumeToken(TOKEN_BRACE_CLOSE)) { |
| 6399 |
return selector; |
| 6400 |
} |
| 6401 |
if (consumeToken(TOKEN_ARROW)) { |
| 6402 |
let variants = parseVariants(); |
| 6403 |
consumeToken(TOKEN_BRACE_CLOSE, SyntaxError); |
| 6404 |
return { |
| 6405 |
type: "select", |
| 6406 |
selector, |
| 6407 |
...variants |
| 6408 |
}; |
| 6409 |
} |
| 6410 |
throw new SyntaxError("Unclosed placeable"); |
| 6411 |
} |
| 6412 |
function parseInlineExpression() { |
| 6413 |
if (source[cursor] === "{") { |
| 6414 |
return parsePlaceable(); |
| 6415 |
} |
| 6416 |
if (test(RE_REFERENCE)) { |
| 6417 |
let [, sigil, name, attr = null] = match(RE_REFERENCE); |
| 6418 |
if (sigil === "$") { |
| 6419 |
return { |
| 6420 |
type: "var", |
| 6421 |
name |
| 6422 |
}; |
| 6423 |
} |
| 6424 |
if (consumeToken(TOKEN_PAREN_OPEN)) { |
| 6425 |
let args = parseArguments(); |
| 6426 |
if (sigil === "-") { |
| 6427 |
return { |
| 6428 |
type: "term", |
| 6429 |
name, |
| 6430 |
attr, |
| 6431 |
args |
| 6432 |
}; |
| 6433 |
} |
| 6434 |
if (RE_FUNCTION_NAME.test(name)) { |
| 6435 |
return { |
| 6436 |
type: "func", |
| 6437 |
name, |
| 6438 |
args |
| 6439 |
}; |
| 6440 |
} |
| 6441 |
throw new SyntaxError("Function names must be all upper-case"); |
| 6442 |
} |
| 6443 |
if (sigil === "-") { |
| 6444 |
return { |
| 6445 |
type: "term", |
| 6446 |
name, |
| 6447 |
attr, |
| 6448 |
args: [] |
| 6449 |
}; |
| 6450 |
} |
| 6451 |
return { |
| 6452 |
type: "mesg", |
| 6453 |
name, |
| 6454 |
attr |
| 6455 |
}; |
| 6456 |
} |
| 6457 |
return parseLiteral(); |
| 6458 |
} |
| 6459 |
function parseArguments() { |
| 6460 |
let args = []; |
| 6461 |
while (true) { |
| 6462 |
switch (source[cursor]) { |
| 6463 |
case ")": |
| 6464 |
cursor++; |
| 6465 |
return args; |
| 6466 |
case undefined: |
| 6467 |
throw new SyntaxError("Unclosed argument list"); |
| 6468 |
} |
| 6469 |
args.push(parseArgument()); |
| 6470 |
consumeToken(TOKEN_COMMA); |
| 6471 |
} |
| 6472 |
} |
| 6473 |
function parseArgument() { |
| 6474 |
let expr = parseInlineExpression(); |
| 6475 |
if (expr.type !== "mesg") { |
| 6476 |
return expr; |
| 6477 |
} |
| 6478 |
if (consumeToken(TOKEN_COLON)) { |
| 6479 |
return { |
| 6480 |
type: "narg", |
| 6481 |
name: expr.name, |
| 6482 |
value: parseLiteral() |
| 6483 |
}; |
| 6484 |
} |
| 6485 |
return expr; |
| 6486 |
} |
| 6487 |
function parseVariants() { |
| 6488 |
let variants = []; |
| 6489 |
let count = 0; |
| 6490 |
let star; |
| 6491 |
while (test(RE_VARIANT_START)) { |
| 6492 |
if (consumeChar("*")) { |
| 6493 |
star = count; |
| 6494 |
} |
| 6495 |
let key = parseVariantKey(); |
| 6496 |
let value = parsePattern(); |
| 6497 |
if (value === null) { |
| 6498 |
throw new SyntaxError("Expected variant value"); |
| 6499 |
} |
| 6500 |
variants[count++] = { |
| 6501 |
key, |
| 6502 |
value |
| 6503 |
}; |
| 6504 |
} |
| 6505 |
if (count === 0) { |
| 6506 |
return null; |
| 6507 |
} |
| 6508 |
if (star === undefined) { |
| 6509 |
throw new SyntaxError("Expected default variant"); |
| 6510 |
} |
| 6511 |
return { |
| 6512 |
variants, |
| 6513 |
star |
| 6514 |
}; |
| 6515 |
} |
| 6516 |
function parseVariantKey() { |
| 6517 |
consumeToken(TOKEN_BRACKET_OPEN, SyntaxError); |
| 6518 |
let key; |
| 6519 |
if (test(RE_NUMBER_LITERAL)) { |
| 6520 |
key = parseNumberLiteral(); |
| 6521 |
} else { |
| 6522 |
key = { |
| 6523 |
type: "str", |
| 6524 |
value: match1(RE_IDENTIFIER) |
| 6525 |
}; |
| 6526 |
} |
| 6527 |
consumeToken(TOKEN_BRACKET_CLOSE, SyntaxError); |
| 6528 |
return key; |
| 6529 |
} |
| 6530 |
function parseLiteral() { |
| 6531 |
if (test(RE_NUMBER_LITERAL)) { |
| 6532 |
return parseNumberLiteral(); |
| 6533 |
} |
| 6534 |
if (source[cursor] === '"') { |
| 6535 |
return parseStringLiteral(); |
| 6536 |
} |
| 6537 |
throw new SyntaxError("Invalid expression"); |
| 6538 |
} |
| 6539 |
function parseNumberLiteral() { |
| 6540 |
let [, value, fraction = ""] = match(RE_NUMBER_LITERAL); |
| 6541 |
let precision = fraction.length; |
| 6542 |
return { |
| 6543 |
type: "num", |
| 6544 |
value: parseFloat(value), |
| 6545 |
precision |
| 6546 |
}; |
| 6547 |
} |
| 6548 |
function parseStringLiteral() { |
| 6549 |
consumeChar('"', SyntaxError); |
| 6550 |
let value = ""; |
| 6551 |
while (true) { |
| 6552 |
value += match1(RE_STRING_RUN); |
| 6553 |
if (source[cursor] === "\\") { |
| 6554 |
value += parseEscapeSequence(); |
| 6555 |
continue; |
| 6556 |
} |
| 6557 |
if (consumeChar('"')) { |
| 6558 |
return { |
| 6559 |
type: "str", |
| 6560 |
value |
| 6561 |
}; |
| 6562 |
} |
| 6563 |
throw new SyntaxError("Unclosed string literal"); |
| 6564 |
} |
| 6565 |
} |
| 6566 |
function parseEscapeSequence() { |
| 6567 |
if (test(RE_STRING_ESCAPE)) { |
| 6568 |
return match1(RE_STRING_ESCAPE); |
| 6569 |
} |
| 6570 |
if (test(RE_UNICODE_ESCAPE)) { |
| 6571 |
let [, codepoint4, codepoint6] = match(RE_UNICODE_ESCAPE); |
| 6572 |
let codepoint = parseInt(codepoint4 || codepoint6, 16); |
| 6573 |
return codepoint <= 0xd7ff || 0xe000 <= codepoint ? String.fromCodePoint(codepoint) : "�"; |
| 6574 |
} |
| 6575 |
throw new SyntaxError("Unknown escape sequence"); |
| 6576 |
} |
| 6577 |
function parseIndent() { |
| 6578 |
let start = cursor; |
| 6579 |
consumeToken(TOKEN_BLANK); |
| 6580 |
switch (source[cursor]) { |
| 6581 |
case ".": |
| 6582 |
case "[": |
| 6583 |
case "*": |
| 6584 |
case "}": |
| 6585 |
case undefined: |
| 6586 |
return false; |
| 6587 |
case "{": |
| 6588 |
return makeIndent(source.slice(start, cursor)); |
| 6589 |
} |
| 6590 |
if (source[cursor - 1] === " ") { |
| 6591 |
return makeIndent(source.slice(start, cursor)); |
| 6592 |
} |
| 6593 |
return false; |
| 6594 |
} |
| 6595 |
function trim(text, re) { |
| 6596 |
return text.replace(re, ""); |
| 6597 |
} |
| 6598 |
function makeIndent(blank) { |
| 6599 |
let value = blank.replace(RE_BLANK_LINES, "\n"); |
| 6600 |
let length = RE_INDENT.exec(blank)[1].length; |
| 6601 |
return new Indent(value, length); |
| 6602 |
} |
| 6603 |
} |
| 6604 |
} |
| 6605 |
class Indent { |
| 6606 |
constructor(value, length) { |
| 6607 |
this.value = value; |
| 6608 |
this.length = length; |
| 6609 |
} |
| 6610 |
} |
| 6611 |
;// ./node_modules/@fluent/bundle/esm/index.js |
| 6612 |
|
| 6613 |
|
| 6614 |
|
| 6615 |
;// ./node_modules/@fluent/dom/esm/overlay.js |
| 6616 |
|
| 6617 |
|
| 6618 |
const reOverlay = /<|&#?\w+;/; |
| 6619 |
const TEXT_LEVEL_ELEMENTS = { |
| 6620 |
"http://www.w3.org/1999/xhtml": ["em", "strong", "small", "s", "cite", "q", "dfn", "abbr", "data", "time", "code", "var", "samp", "kbd", "sub", "sup", "i", "b", "u", "mark", "bdi", "bdo", "span", "br", "wbr"] |
| 6621 |
}; |
| 6622 |
const LOCALIZABLE_ATTRIBUTES = { |
| 6623 |
"http://www.w3.org/1999/xhtml": { |
| 6624 |
global: ["title", "aria-description", "aria-label", "aria-valuetext"], |
| 6625 |
a: ["download"], |
| 6626 |
area: ["download", "alt"], |
| 6627 |
input: ["alt", "placeholder"], |
| 6628 |
menuitem: ["label"], |
| 6629 |
menu: ["label"], |
| 6630 |
optgroup: ["label"], |
| 6631 |
option: ["label"], |
| 6632 |
track: ["label"], |
| 6633 |
img: ["alt"], |
| 6634 |
textarea: ["placeholder"], |
| 6635 |
th: ["abbr"] |
| 6636 |
}, |
| 6637 |
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul": { |
| 6638 |
global: ["accesskey", "aria-label", "aria-valuetext", "label", "title", "tooltiptext"], |
| 6639 |
description: ["value"], |
| 6640 |
key: ["key", "keycode"], |
| 6641 |
label: ["value"], |
| 6642 |
textbox: ["placeholder", "value"] |
| 6643 |
} |
| 6644 |
}; |
| 6645 |
function translateElement(element, translation) { |
| 6646 |
const { |
| 6647 |
value |
| 6648 |
} = translation; |
| 6649 |
if (typeof value === "string") { |
| 6650 |
if (element.localName === "title" && element.namespaceURI === "http://www.w3.org/1999/xhtml") { |
| 6651 |
element.textContent = value; |
| 6652 |
} else if (!reOverlay.test(value)) { |
| 6653 |
element.textContent = value; |
| 6654 |
} else { |
| 6655 |
const templateElement = element.ownerDocument.createElementNS("http://www.w3.org/1999/xhtml", "template"); |
| 6656 |
templateElement.innerHTML = value; |
| 6657 |
overlayChildNodes(templateElement.content, element); |
| 6658 |
} |
| 6659 |
} |
| 6660 |
overlayAttributes(translation, element); |
| 6661 |
} |
| 6662 |
function overlayChildNodes(fromFragment, toElement) { |
| 6663 |
for (const childNode of fromFragment.childNodes) { |
| 6664 |
if (childNode.nodeType === childNode.TEXT_NODE) { |
| 6665 |
continue; |
| 6666 |
} |
| 6667 |
if (childNode.hasAttribute("data-l10n-name")) { |
| 6668 |
const sanitized = getNodeForNamedElement(toElement, childNode); |
| 6669 |
fromFragment.replaceChild(sanitized, childNode); |
| 6670 |
continue; |
| 6671 |
} |
| 6672 |
if (isElementAllowed(childNode)) { |
| 6673 |
const sanitized = createSanitizedElement(childNode); |
| 6674 |
fromFragment.replaceChild(sanitized, childNode); |
| 6675 |
continue; |
| 6676 |
} |
| 6677 |
console.warn(`An element of forbidden type "${childNode.localName}" was found in ` + "the translation. Only safe text-level elements and elements with " + "data-l10n-name are allowed."); |
| 6678 |
fromFragment.replaceChild(createTextNodeFromTextContent(childNode), childNode); |
| 6679 |
} |
| 6680 |
toElement.textContent = ""; |
| 6681 |
toElement.appendChild(fromFragment); |
| 6682 |
} |
| 6683 |
function hasAttribute(attributes, name) { |
| 6684 |
if (!attributes) { |
| 6685 |
return false; |
| 6686 |
} |
| 6687 |
for (let attr of attributes) { |
| 6688 |
if (attr.name === name) { |
| 6689 |
return true; |
| 6690 |
} |
| 6691 |
} |
| 6692 |
return false; |
| 6693 |
} |
| 6694 |
function overlayAttributes(fromElement, toElement) { |
| 6695 |
const explicitlyAllowed = toElement.hasAttribute("data-l10n-attrs") ? toElement.getAttribute("data-l10n-attrs").split(",").map(i => i.trim()) : null; |
| 6696 |
for (const attr of Array.from(toElement.attributes)) { |
| 6697 |
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && !hasAttribute(fromElement.attributes, attr.name)) { |
| 6698 |
toElement.removeAttribute(attr.name); |
| 6699 |
} |
| 6700 |
} |
| 6701 |
if (!fromElement.attributes) { |
| 6702 |
return; |
| 6703 |
} |
| 6704 |
for (const attr of Array.from(fromElement.attributes)) { |
| 6705 |
if (isAttrNameLocalizable(attr.name, toElement, explicitlyAllowed) && toElement.getAttribute(attr.name) !== attr.value) { |
| 6706 |
toElement.setAttribute(attr.name, attr.value); |
| 6707 |
} |
| 6708 |
} |
| 6709 |
} |
| 6710 |
function getNodeForNamedElement(sourceElement, translatedChild) { |
| 6711 |
const childName = translatedChild.getAttribute("data-l10n-name"); |
| 6712 |
const sourceChild = sourceElement.querySelector(`[data-l10n-name="${childName}"]`); |
| 6713 |
if (!sourceChild) { |
| 6714 |
console.warn(`An element named "${childName}" wasn't found in the source.`); |
| 6715 |
return createTextNodeFromTextContent(translatedChild); |
| 6716 |
} |
| 6717 |
if (sourceChild.localName !== translatedChild.localName) { |
| 6718 |
console.warn(`An element named "${childName}" was found in the translation ` + `but its type ${translatedChild.localName} didn't match the ` + `element found in the source (${sourceChild.localName}).`); |
| 6719 |
return createTextNodeFromTextContent(translatedChild); |
| 6720 |
} |
| 6721 |
sourceElement.removeChild(sourceChild); |
| 6722 |
const clone = sourceChild.cloneNode(false); |
| 6723 |
return shallowPopulateUsing(translatedChild, clone); |
| 6724 |
} |
| 6725 |
function createSanitizedElement(element) { |
| 6726 |
const clone = element.ownerDocument.createElement(element.localName); |
| 6727 |
return shallowPopulateUsing(element, clone); |
| 6728 |
} |
| 6729 |
function createTextNodeFromTextContent(element) { |
| 6730 |
return element.ownerDocument.createTextNode(element.textContent); |
| 6731 |
} |
| 6732 |
function isElementAllowed(element) { |
| 6733 |
const allowed = TEXT_LEVEL_ELEMENTS[element.namespaceURI]; |
| 6734 |
return allowed && allowed.includes(element.localName); |
| 6735 |
} |
| 6736 |
function isAttrNameLocalizable(name, element, explicitlyAllowed = null) { |
| 6737 |
if (explicitlyAllowed && explicitlyAllowed.includes(name)) { |
| 6738 |
return true; |
| 6739 |
} |
| 6740 |
const allowed = LOCALIZABLE_ATTRIBUTES[element.namespaceURI]; |
| 6741 |
if (!allowed) { |
| 6742 |
return false; |
| 6743 |
} |
| 6744 |
const attrName = name.toLowerCase(); |
| 6745 |
const elemName = element.localName; |
| 6746 |
if (allowed.global.includes(attrName)) { |
| 6747 |
return true; |
| 6748 |
} |
| 6749 |
if (!allowed[elemName]) { |
| 6750 |
return false; |
| 6751 |
} |
| 6752 |
if (allowed[elemName].includes(attrName)) { |
| 6753 |
return true; |
| 6754 |
} |
| 6755 |
if (element.namespaceURI === "http://www.w3.org/1999/xhtml" && elemName === "input" && attrName === "value") { |
| 6756 |
const type = element.type.toLowerCase(); |
| 6757 |
if (type === "submit" || type === "button" || type === "reset") { |
| 6758 |
return true; |
| 6759 |
} |
| 6760 |
} |
| 6761 |
return false; |
| 6762 |
} |
| 6763 |
function shallowPopulateUsing(fromElement, toElement) { |
| 6764 |
toElement.textContent = fromElement.textContent; |
| 6765 |
overlayAttributes(fromElement, toElement); |
| 6766 |
return toElement; |
| 6767 |
} |
| 6768 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.filter.js |
| 6769 |
var es_iterator_filter = __webpack_require__(2489); |
| 6770 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.for-each.js |
| 6771 |
var es_iterator_for_each = __webpack_require__(7588); |
| 6772 |
;// ./node_modules/cached-iterable/src/cached_iterable.js |
| 6773 |
class CachedIterable extends Array { |
| 6774 |
static from(iterable) { |
| 6775 |
if (iterable instanceof this) { |
| 6776 |
return iterable; |
| 6777 |
} |
| 6778 |
return new this(iterable); |
| 6779 |
} |
| 6780 |
} |
| 6781 |
;// ./node_modules/cached-iterable/src/cached_sync_iterable.js |
| 6782 |
|
| 6783 |
|
| 6784 |
class CachedSyncIterable extends CachedIterable { |
| 6785 |
constructor(iterable) { |
| 6786 |
super(); |
| 6787 |
if (Symbol.iterator in Object(iterable)) { |
| 6788 |
this.iterator = iterable[Symbol.iterator](); |
| 6789 |
} else { |
| 6790 |
throw new TypeError("Argument must implement the iteration protocol."); |
| 6791 |
} |
| 6792 |
} |
| 6793 |
[Symbol.iterator]() { |
| 6794 |
const cached = this; |
| 6795 |
let cur = 0; |
| 6796 |
return { |
| 6797 |
next() { |
| 6798 |
if (cached.length <= cur) { |
| 6799 |
cached.push(cached.iterator.next()); |
| 6800 |
} |
| 6801 |
return cached[cur++]; |
| 6802 |
} |
| 6803 |
}; |
| 6804 |
} |
| 6805 |
touchNext(count = 1) { |
| 6806 |
let idx = 0; |
| 6807 |
while (idx++ < count) { |
| 6808 |
const last = this[this.length - 1]; |
| 6809 |
if (last && last.done) { |
| 6810 |
break; |
| 6811 |
} |
| 6812 |
this.push(this.iterator.next()); |
| 6813 |
} |
| 6814 |
return this[this.length - 1]; |
| 6815 |
} |
| 6816 |
} |
| 6817 |
;// ./node_modules/cached-iterable/src/cached_async_iterable.js |
| 6818 |
|
| 6819 |
|
| 6820 |
class CachedAsyncIterable extends CachedIterable { |
| 6821 |
constructor(iterable) { |
| 6822 |
super(); |
| 6823 |
if (Symbol.asyncIterator in Object(iterable)) { |
| 6824 |
this.iterator = iterable[Symbol.asyncIterator](); |
| 6825 |
} else if (Symbol.iterator in Object(iterable)) { |
| 6826 |
this.iterator = iterable[Symbol.iterator](); |
| 6827 |
} else { |
| 6828 |
throw new TypeError("Argument must implement the iteration protocol."); |
| 6829 |
} |
| 6830 |
} |
| 6831 |
[Symbol.asyncIterator]() { |
| 6832 |
const cached = this; |
| 6833 |
let cur = 0; |
| 6834 |
return { |
| 6835 |
async next() { |
| 6836 |
if (cached.length <= cur) { |
| 6837 |
cached.push(cached.iterator.next()); |
| 6838 |
} |
| 6839 |
return cached[cur++]; |
| 6840 |
} |
| 6841 |
}; |
| 6842 |
} |
| 6843 |
async touchNext(count = 1) { |
| 6844 |
let idx = 0; |
| 6845 |
while (idx++ < count) { |
| 6846 |
const last = this[this.length - 1]; |
| 6847 |
if (last && (await last).done) { |
| 6848 |
break; |
| 6849 |
} |
| 6850 |
this.push(this.iterator.next()); |
| 6851 |
} |
| 6852 |
return this[this.length - 1]; |
| 6853 |
} |
| 6854 |
} |
| 6855 |
;// ./node_modules/cached-iterable/src/index.js |
| 6856 |
|
| 6857 |
|
| 6858 |
;// ./node_modules/@fluent/dom/esm/localization.js |
| 6859 |
|
| 6860 |
|
| 6861 |
|
| 6862 |
|
| 6863 |
|
| 6864 |
|
| 6865 |
|
| 6866 |
|
| 6867 |
|
| 6868 |
|
| 6869 |
|
| 6870 |
|
| 6871 |
class Localization { |
| 6872 |
constructor(resourceIds = [], generateBundles) { |
| 6873 |
this.resourceIds = resourceIds; |
| 6874 |
this.generateBundles = generateBundles; |
| 6875 |
this.onChange(true); |
| 6876 |
} |
| 6877 |
addResourceIds(resourceIds, eager = false) { |
| 6878 |
this.resourceIds.push(...resourceIds); |
| 6879 |
this.onChange(eager); |
| 6880 |
return this.resourceIds.length; |
| 6881 |
} |
| 6882 |
removeResourceIds(resourceIds) { |
| 6883 |
this.resourceIds = this.resourceIds.filter(r => !resourceIds.includes(r)); |
| 6884 |
this.onChange(); |
| 6885 |
return this.resourceIds.length; |
| 6886 |
} |
| 6887 |
async formatWithFallback(keys, method) { |
| 6888 |
const translations = []; |
| 6889 |
let hasAtLeastOneBundle = false; |
| 6890 |
for await (const bundle of this.bundles) { |
| 6891 |
hasAtLeastOneBundle = true; |
| 6892 |
const missingIds = keysFromBundle(method, bundle, keys, translations); |
| 6893 |
if (missingIds.size === 0) { |
| 6894 |
break; |
| 6895 |
} |
| 6896 |
if (typeof console !== "undefined") { |
| 6897 |
const locale = bundle.locales[0]; |
| 6898 |
const ids = Array.from(missingIds).join(", "); |
| 6899 |
console.warn(`[fluent] Missing translations in ${locale}: ${ids}`); |
| 6900 |
} |
| 6901 |
} |
| 6902 |
if (!hasAtLeastOneBundle && typeof console !== "undefined") { |
| 6903 |
console.warn(`[fluent] Request for keys failed because no resource bundles got generated. |
| 6904 |
keys: ${JSON.stringify(keys)}. |
| 6905 |
resourceIds: ${JSON.stringify(this.resourceIds)}.`); |
| 6906 |
} |
| 6907 |
return translations; |
| 6908 |
} |
| 6909 |
formatMessages(keys) { |
| 6910 |
return this.formatWithFallback(keys, messageFromBundle); |
| 6911 |
} |
| 6912 |
formatValues(keys) { |
| 6913 |
return this.formatWithFallback(keys, valueFromBundle); |
| 6914 |
} |
| 6915 |
async formatValue(id, args) { |
| 6916 |
const [val] = await this.formatValues([{ |
| 6917 |
id, |
| 6918 |
args |
| 6919 |
}]); |
| 6920 |
return val; |
| 6921 |
} |
| 6922 |
handleEvent() { |
| 6923 |
this.onChange(); |
| 6924 |
} |
| 6925 |
onChange(eager = false) { |
| 6926 |
this.bundles = CachedAsyncIterable.from(this.generateBundles(this.resourceIds)); |
| 6927 |
if (eager) { |
| 6928 |
this.bundles.touchNext(2); |
| 6929 |
} |
| 6930 |
} |
| 6931 |
} |
| 6932 |
function valueFromBundle(bundle, errors, message, args) { |
| 6933 |
if (message.value) { |
| 6934 |
return bundle.formatPattern(message.value, args, errors); |
| 6935 |
} |
| 6936 |
return null; |
| 6937 |
} |
| 6938 |
function messageFromBundle(bundle, errors, message, args) { |
| 6939 |
const formatted = { |
| 6940 |
value: null, |
| 6941 |
attributes: null |
| 6942 |
}; |
| 6943 |
if (message.value) { |
| 6944 |
formatted.value = bundle.formatPattern(message.value, args, errors); |
| 6945 |
} |
| 6946 |
let attrNames = Object.keys(message.attributes); |
| 6947 |
if (attrNames.length > 0) { |
| 6948 |
formatted.attributes = new Array(attrNames.length); |
| 6949 |
for (let [i, name] of attrNames.entries()) { |
| 6950 |
let value = bundle.formatPattern(message.attributes[name], args, errors); |
| 6951 |
formatted.attributes[i] = { |
| 6952 |
name, |
| 6953 |
value |
| 6954 |
}; |
| 6955 |
} |
| 6956 |
} |
| 6957 |
return formatted; |
| 6958 |
} |
| 6959 |
function keysFromBundle(method, bundle, keys, translations) { |
| 6960 |
const messageErrors = []; |
| 6961 |
const missingIds = new Set(); |
| 6962 |
keys.forEach(({ |
| 6963 |
id, |
| 6964 |
args |
| 6965 |
}, i) => { |
| 6966 |
if (translations[i] !== undefined) { |
| 6967 |
return; |
| 6968 |
} |
| 6969 |
let message = bundle.getMessage(id); |
| 6970 |
if (message) { |
| 6971 |
messageErrors.length = 0; |
| 6972 |
translations[i] = method(bundle, messageErrors, message, args); |
| 6973 |
if (messageErrors.length > 0 && typeof console !== "undefined") { |
| 6974 |
const locale = bundle.locales[0]; |
| 6975 |
const errors = messageErrors.join(", "); |
| 6976 |
console.warn(`[fluent][resolver] errors in ${locale}/${id}: ${errors}.`); |
| 6977 |
} |
| 6978 |
} else { |
| 6979 |
missingIds.add(id); |
| 6980 |
} |
| 6981 |
}); |
| 6982 |
return missingIds; |
| 6983 |
} |
| 6984 |
;// ./node_modules/@fluent/dom/esm/dom_localization.js |
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
|
| 6991 |
|
| 6992 |
|
| 6993 |
|
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
const L10NID_ATTR_NAME = "data-l10n-id"; |
| 6999 |
const L10NARGS_ATTR_NAME = "data-l10n-args"; |
| 7000 |
const L10N_ELEMENT_QUERY = `[${L10NID_ATTR_NAME}]`; |
| 7001 |
class DOMLocalization extends Localization { |
| 7002 |
constructor(resourceIds, generateBundles) { |
| 7003 |
super(resourceIds, generateBundles); |
| 7004 |
this.roots = new Set(); |
| 7005 |
this.pendingrAF = null; |
| 7006 |
this.pendingElements = new Set(); |
| 7007 |
this.windowElement = null; |
| 7008 |
this.mutationObserver = null; |
| 7009 |
this.observerConfig = { |
| 7010 |
attributes: true, |
| 7011 |
characterData: false, |
| 7012 |
childList: true, |
| 7013 |
subtree: true, |
| 7014 |
attributeFilter: [L10NID_ATTR_NAME, L10NARGS_ATTR_NAME] |
| 7015 |
}; |
| 7016 |
} |
| 7017 |
onChange(eager = false) { |
| 7018 |
super.onChange(eager); |
| 7019 |
if (this.roots) { |
| 7020 |
this.translateRoots(); |
| 7021 |
} |
| 7022 |
} |
| 7023 |
setAttributes(element, id, args) { |
| 7024 |
element.setAttribute(L10NID_ATTR_NAME, id); |
| 7025 |
if (args) { |
| 7026 |
element.setAttribute(L10NARGS_ATTR_NAME, JSON.stringify(args)); |
| 7027 |
} else { |
| 7028 |
element.removeAttribute(L10NARGS_ATTR_NAME); |
| 7029 |
} |
| 7030 |
return element; |
| 7031 |
} |
| 7032 |
getAttributes(element) { |
| 7033 |
return { |
| 7034 |
id: element.getAttribute(L10NID_ATTR_NAME), |
| 7035 |
args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null) |
| 7036 |
}; |
| 7037 |
} |
| 7038 |
connectRoot(newRoot) { |
| 7039 |
for (const root of this.roots) { |
| 7040 |
if (root === newRoot || root.contains(newRoot) || newRoot.contains(root)) { |
| 7041 |
throw new Error("Cannot add a root that overlaps with existing root."); |
| 7042 |
} |
| 7043 |
} |
| 7044 |
if (this.windowElement) { |
| 7045 |
if (this.windowElement !== newRoot.ownerDocument.defaultView) { |
| 7046 |
throw new Error(`Cannot connect a root: |
| 7047 |
DOMLocalization already has a root from a different window.`); |
| 7048 |
} |
| 7049 |
} else { |
| 7050 |
this.windowElement = newRoot.ownerDocument.defaultView; |
| 7051 |
this.mutationObserver = new this.windowElement.MutationObserver(mutations => this.translateMutations(mutations)); |
| 7052 |
} |
| 7053 |
this.roots.add(newRoot); |
| 7054 |
this.mutationObserver.observe(newRoot, this.observerConfig); |
| 7055 |
} |
| 7056 |
disconnectRoot(root) { |
| 7057 |
this.roots.delete(root); |
| 7058 |
this.pauseObserving(); |
| 7059 |
if (this.roots.size === 0) { |
| 7060 |
this.mutationObserver = null; |
| 7061 |
if (this.windowElement && this.pendingrAF) { |
| 7062 |
this.windowElement.cancelAnimationFrame(this.pendingrAF); |
| 7063 |
} |
| 7064 |
this.windowElement = null; |
| 7065 |
this.pendingrAF = null; |
| 7066 |
this.pendingElements.clear(); |
| 7067 |
return true; |
| 7068 |
} |
| 7069 |
this.resumeObserving(); |
| 7070 |
return false; |
| 7071 |
} |
| 7072 |
translateRoots() { |
| 7073 |
const roots = Array.from(this.roots); |
| 7074 |
return Promise.all(roots.map(root => this.translateFragment(root))); |
| 7075 |
} |
| 7076 |
pauseObserving() { |
| 7077 |
if (!this.mutationObserver) { |
| 7078 |
return; |
| 7079 |
} |
| 7080 |
this.translateMutations(this.mutationObserver.takeRecords()); |
| 7081 |
this.mutationObserver.disconnect(); |
| 7082 |
} |
| 7083 |
resumeObserving() { |
| 7084 |
if (!this.mutationObserver) { |
| 7085 |
return; |
| 7086 |
} |
| 7087 |
for (const root of this.roots) { |
| 7088 |
this.mutationObserver.observe(root, this.observerConfig); |
| 7089 |
} |
| 7090 |
} |
| 7091 |
translateMutations(mutations) { |
| 7092 |
for (const mutation of mutations) { |
| 7093 |
switch (mutation.type) { |
| 7094 |
case "attributes": |
| 7095 |
if (mutation.target.hasAttribute("data-l10n-id")) { |
| 7096 |
this.pendingElements.add(mutation.target); |
| 7097 |
} |
| 7098 |
break; |
| 7099 |
case "childList": |
| 7100 |
for (const addedNode of mutation.addedNodes) { |
| 7101 |
if (addedNode.nodeType === addedNode.ELEMENT_NODE) { |
| 7102 |
if (addedNode.childElementCount) { |
| 7103 |
for (const element of this.getTranslatables(addedNode)) { |
| 7104 |
this.pendingElements.add(element); |
| 7105 |
} |
| 7106 |
} else if (addedNode.hasAttribute(L10NID_ATTR_NAME)) { |
| 7107 |
this.pendingElements.add(addedNode); |
| 7108 |
} |
| 7109 |
} |
| 7110 |
} |
| 7111 |
break; |
| 7112 |
} |
| 7113 |
} |
| 7114 |
if (this.pendingElements.size > 0) { |
| 7115 |
if (this.pendingrAF === null) { |
| 7116 |
this.pendingrAF = this.windowElement.requestAnimationFrame(() => { |
| 7117 |
this.translateElements(Array.from(this.pendingElements)); |
| 7118 |
this.pendingElements.clear(); |
| 7119 |
this.pendingrAF = null; |
| 7120 |
}); |
| 7121 |
} |
| 7122 |
} |
| 7123 |
} |
| 7124 |
translateFragment(frag) { |
| 7125 |
return this.translateElements(this.getTranslatables(frag)); |
| 7126 |
} |
| 7127 |
async translateElements(elements) { |
| 7128 |
if (!elements.length) { |
| 7129 |
return undefined; |
| 7130 |
} |
| 7131 |
const keys = elements.map(this.getKeysForElement); |
| 7132 |
const translations = await this.formatMessages(keys); |
| 7133 |
return this.applyTranslations(elements, translations); |
| 7134 |
} |
| 7135 |
applyTranslations(elements, translations) { |
| 7136 |
this.pauseObserving(); |
| 7137 |
for (let i = 0; i < elements.length; i++) { |
| 7138 |
if (translations[i] !== undefined) { |
| 7139 |
translateElement(elements[i], translations[i]); |
| 7140 |
} |
| 7141 |
} |
| 7142 |
this.resumeObserving(); |
| 7143 |
} |
| 7144 |
getTranslatables(element) { |
| 7145 |
const nodes = Array.from(element.querySelectorAll(L10N_ELEMENT_QUERY)); |
| 7146 |
if (typeof element.hasAttribute === "function" && element.hasAttribute(L10NID_ATTR_NAME)) { |
| 7147 |
nodes.push(element); |
| 7148 |
} |
| 7149 |
return nodes; |
| 7150 |
} |
| 7151 |
getKeysForElement(element) { |
| 7152 |
return { |
| 7153 |
id: element.getAttribute(L10NID_ATTR_NAME), |
| 7154 |
args: JSON.parse(element.getAttribute(L10NARGS_ATTR_NAME) || null) |
| 7155 |
}; |
| 7156 |
} |
| 7157 |
} |
| 7158 |
;// ./node_modules/@fluent/dom/esm/index.js |
| 7159 |
|
| 7160 |
|
| 7161 |
;// ./web/l10n.js |
| 7162 |
|
| 7163 |
|
| 7164 |
|
| 7165 |
|
| 7166 |
|
| 7167 |
|
| 7168 |
|
| 7169 |
|
| 7170 |
|
| 7171 |
class L10n { |
| 7172 |
#dir; |
| 7173 |
#elements; |
| 7174 |
#lang; |
| 7175 |
#l10n; |
| 7176 |
constructor({ |
| 7177 |
lang, |
| 7178 |
isRTL |
| 7179 |
}, l10n = null) { |
| 7180 |
this.#lang = L10n.#fixupLangCode(lang); |
| 7181 |
this.#l10n = l10n; |
| 7182 |
this.#dir = isRTL ?? L10n.#isRTL(this.#lang) ? "rtl" : "ltr"; |
| 7183 |
} |
| 7184 |
_setL10n(l10n) { |
| 7185 |
this.#l10n = l10n; |
| 7186 |
} |
| 7187 |
getLanguage() { |
| 7188 |
return this.#lang; |
| 7189 |
} |
| 7190 |
getDirection() { |
| 7191 |
return this.#dir; |
| 7192 |
} |
| 7193 |
async get(ids, args = null, fallback) { |
| 7194 |
if (Array.isArray(ids)) { |
| 7195 |
ids = ids.map(id => ({ |
| 7196 |
id |
| 7197 |
})); |
| 7198 |
const messages = await this.#l10n.formatMessages(ids); |
| 7199 |
return messages.map(message => message.value); |
| 7200 |
} |
| 7201 |
const messages = await this.#l10n.formatMessages([{ |
| 7202 |
id: ids, |
| 7203 |
args |
| 7204 |
}]); |
| 7205 |
return messages[0]?.value || fallback; |
| 7206 |
} |
| 7207 |
async translate(element) { |
| 7208 |
(this.#elements ||= new Set()).add(element); |
| 7209 |
try { |
| 7210 |
this.#l10n.connectRoot(element); |
| 7211 |
await this.#l10n.translateRoots(); |
| 7212 |
} catch {} |
| 7213 |
} |
| 7214 |
async translateOnce(element) { |
| 7215 |
try { |
| 7216 |
await this.#l10n.translateElements([element]); |
| 7217 |
} catch (ex) { |
| 7218 |
console.error("translateOnce:", ex); |
| 7219 |
} |
| 7220 |
} |
| 7221 |
async destroy() { |
| 7222 |
if (this.#elements) { |
| 7223 |
for (const element of this.#elements) { |
| 7224 |
this.#l10n.disconnectRoot(element); |
| 7225 |
} |
| 7226 |
this.#elements.clear(); |
| 7227 |
this.#elements = null; |
| 7228 |
} |
| 7229 |
this.#l10n.pauseObserving(); |
| 7230 |
} |
| 7231 |
pause() { |
| 7232 |
this.#l10n.pauseObserving(); |
| 7233 |
} |
| 7234 |
resume() { |
| 7235 |
this.#l10n.resumeObserving(); |
| 7236 |
} |
| 7237 |
static #fixupLangCode(langCode) { |
| 7238 |
langCode = langCode?.toLowerCase() || "en-us"; |
| 7239 |
const PARTIAL_LANG_CODES = { |
| 7240 |
en: "en-us", |
| 7241 |
es: "es-es", |
| 7242 |
fy: "fy-nl", |
| 7243 |
ga: "ga-ie", |
| 7244 |
gu: "gu-in", |
| 7245 |
hi: "hi-in", |
| 7246 |
hy: "hy-am", |
| 7247 |
nb: "nb-no", |
| 7248 |
ne: "ne-np", |
| 7249 |
nn: "nn-no", |
| 7250 |
pa: "pa-in", |
| 7251 |
pt: "pt-pt", |
| 7252 |
sv: "sv-se", |
| 7253 |
zh: "zh-cn" |
| 7254 |
}; |
| 7255 |
return PARTIAL_LANG_CODES[langCode] || langCode; |
| 7256 |
} |
| 7257 |
static #isRTL(lang) { |
| 7258 |
const shortCode = lang.split("-", 1)[0]; |
| 7259 |
return ["ar", "he", "fa", "ps", "ur"].includes(shortCode); |
| 7260 |
} |
| 7261 |
} |
| 7262 |
const GenericL10n = null; |
| 7263 |
|
| 7264 |
;// ./web/genericl10n.js |
| 7265 |
|
| 7266 |
|
| 7267 |
|
| 7268 |
|
| 7269 |
|
| 7270 |
|
| 7271 |
|
| 7272 |
|
| 7273 |
|
| 7274 |
|
| 7275 |
function PLATFORM() { |
| 7276 |
const { |
| 7277 |
isAndroid, |
| 7278 |
isLinux, |
| 7279 |
isMac, |
| 7280 |
isWindows |
| 7281 |
} = FeatureTest.platform; |
| 7282 |
if (isLinux) { |
| 7283 |
return "linux"; |
| 7284 |
} |
| 7285 |
if (isWindows) { |
| 7286 |
return "windows"; |
| 7287 |
} |
| 7288 |
if (isMac) { |
| 7289 |
return "macos"; |
| 7290 |
} |
| 7291 |
if (isAndroid) { |
| 7292 |
return "android"; |
| 7293 |
} |
| 7294 |
return "other"; |
| 7295 |
} |
| 7296 |
function createBundle(lang, text) { |
| 7297 |
const resource = new FluentResource(text); |
| 7298 |
const bundle = new FluentBundle(lang, { |
| 7299 |
functions: { |
| 7300 |
PLATFORM |
| 7301 |
} |
| 7302 |
}); |
| 7303 |
const errors = bundle.addResource(resource); |
| 7304 |
if (errors.length) { |
| 7305 |
console.error("L10n errors", errors); |
| 7306 |
} |
| 7307 |
return bundle; |
| 7308 |
} |
| 7309 |
class genericl10n_GenericL10n extends L10n { |
| 7310 |
constructor(lang) { |
| 7311 |
super({ |
| 7312 |
lang |
| 7313 |
}); |
| 7314 |
const generateBundles = !lang ? genericl10n_GenericL10n.#generateBundlesFallback.bind(genericl10n_GenericL10n, this.getLanguage()) : genericl10n_GenericL10n.#generateBundles.bind(genericl10n_GenericL10n, "en-us", this.getLanguage()); |
| 7315 |
this._setL10n(new DOMLocalization([], generateBundles)); |
| 7316 |
} |
| 7317 |
static async *#generateBundles(defaultLang, baseLang) { |
| 7318 |
const { |
| 7319 |
baseURL, |
| 7320 |
paths |
| 7321 |
} = await this.#getPaths(); |
| 7322 |
const langs = [baseLang]; |
| 7323 |
if (defaultLang !== baseLang) { |
| 7324 |
const shortLang = baseLang.split("-", 1)[0]; |
| 7325 |
if (shortLang !== baseLang) { |
| 7326 |
langs.push(shortLang); |
| 7327 |
} |
| 7328 |
langs.push(defaultLang); |
| 7329 |
} |
| 7330 |
const bundles = langs.map(lang => [lang, this.#createBundle(lang, baseURL, paths)]); |
| 7331 |
for (const [lang, bundlePromise] of bundles) { |
| 7332 |
const bundle = await bundlePromise; |
| 7333 |
if (bundle) { |
| 7334 |
yield bundle; |
| 7335 |
} else if (lang === "en-us") { |
| 7336 |
yield this.#createBundleFallback(lang); |
| 7337 |
} |
| 7338 |
} |
| 7339 |
} |
| 7340 |
static async #createBundle(lang, baseURL, paths) { |
| 7341 |
const path = paths[lang]; |
| 7342 |
if (!path) { |
| 7343 |
return null; |
| 7344 |
} |
| 7345 |
const url = new URL(path, baseURL); |
| 7346 |
const text = await fetchData(url, "text"); |
| 7347 |
return createBundle(lang, text); |
| 7348 |
} |
| 7349 |
static async #getPaths() { |
| 7350 |
try { |
| 7351 |
const { |
| 7352 |
href |
| 7353 |
} = document.querySelector(`link[type="application/l10n"]`); |
| 7354 |
const paths = await fetchData(href, "json"); |
| 7355 |
return { |
| 7356 |
baseURL: href.substring(0, href.lastIndexOf("/") + 1) || "./", |
| 7357 |
paths |
| 7358 |
}; |
| 7359 |
} catch {} |
| 7360 |
return { |
| 7361 |
baseURL: "./", |
| 7362 |
paths: Object.create(null) |
| 7363 |
}; |
| 7364 |
} |
| 7365 |
static async *#generateBundlesFallback(lang) { |
| 7366 |
yield this.#createBundleFallback(lang); |
| 7367 |
} |
| 7368 |
static async #createBundleFallback(lang) { |
| 7369 |
const text = "pdfjs-previous-button =\n .title = Previous Page\npdfjs-previous-button-label = Previous\npdfjs-next-button =\n .title = Next Page\npdfjs-next-button-label = Next\npdfjs-page-input =\n .title = Page\npdfjs-of-pages = of { $pagesCount }\npdfjs-page-of-pages = ({ $pageNumber } of { $pagesCount })\npdfjs-zoom-out-button =\n .title = Zoom Out\npdfjs-zoom-out-button-label = Zoom Out\npdfjs-zoom-in-button =\n .title = Zoom In\npdfjs-zoom-in-button-label = Zoom In\npdfjs-zoom-select =\n .title = Zoom\npdfjs-presentation-mode-button =\n .title = Switch to Presentation Mode\npdfjs-presentation-mode-button-label = Presentation Mode\npdfjs-open-file-button =\n .title = Open File\npdfjs-open-file-button-label = Open\npdfjs-print-button =\n .title = Print\npdfjs-print-button-label = Print\npdfjs-save-button =\n .title = Save\npdfjs-save-button-label = Save\npdfjs-download-button =\n .title = Download\npdfjs-download-button-label = Download\npdfjs-bookmark-button =\n .title = Current Page (View URL from Current Page)\npdfjs-bookmark-button-label = Current Page\npdfjs-tools-button =\n .title = Tools\npdfjs-tools-button-label = Tools\npdfjs-first-page-button =\n .title = Go to First Page\npdfjs-first-page-button-label = Go to First Page\npdfjs-last-page-button =\n .title = Go to Last Page\npdfjs-last-page-button-label = Go to Last Page\npdfjs-page-rotate-cw-button =\n .title = Rotate Clockwise\npdfjs-page-rotate-cw-button-label = Rotate Clockwise\npdfjs-page-rotate-ccw-button =\n .title = Rotate Counterclockwise\npdfjs-page-rotate-ccw-button-label = Rotate Counterclockwise\npdfjs-cursor-text-select-tool-button =\n .title = Enable Text Selection Tool\npdfjs-cursor-text-select-tool-button-label = Text Selection Tool\npdfjs-cursor-hand-tool-button =\n .title = Enable Hand Tool\npdfjs-cursor-hand-tool-button-label = Hand Tool\npdfjs-scroll-page-button =\n .title = Use Page Scrolling\npdfjs-scroll-page-button-label = Page Scrolling\npdfjs-scroll-vertical-button =\n .title = Use Vertical Scrolling\npdfjs-scroll-vertical-button-label = Vertical Scrolling\npdfjs-scroll-horizontal-button =\n .title = Use Horizontal Scrolling\npdfjs-scroll-horizontal-button-label = Horizontal Scrolling\npdfjs-scroll-wrapped-button =\n .title = Use Wrapped Scrolling\npdfjs-scroll-wrapped-button-label = Wrapped Scrolling\npdfjs-spread-none-button =\n .title = Do not join page spreads\npdfjs-spread-none-button-label = No Spreads\npdfjs-spread-odd-button =\n .title = Join page spreads starting with odd-numbered pages\npdfjs-spread-odd-button-label = Odd Spreads\npdfjs-spread-even-button =\n .title = Join page spreads starting with even-numbered pages\npdfjs-spread-even-button-label = Even Spreads\npdfjs-document-properties-button =\n .title = Document Properties\u2026\npdfjs-document-properties-button-label = Document Properties\u2026\npdfjs-document-properties-file-name = File name:\npdfjs-document-properties-file-size = File size:\npdfjs-document-properties-size-kb = { NUMBER($kb, maximumSignificantDigits: 3) } KB ({ $b } bytes)\npdfjs-document-properties-size-mb = { NUMBER($mb, maximumSignificantDigits: 3) } MB ({ $b } bytes)\npdfjs-document-properties-title = Title:\npdfjs-document-properties-author = Author:\npdfjs-document-properties-subject = Subject:\npdfjs-document-properties-keywords = Keywords:\npdfjs-document-properties-creation-date = Creation Date:\npdfjs-document-properties-modification-date = Modification Date:\npdfjs-document-properties-date-time-string = { DATETIME($dateObj, dateStyle: \"short\", timeStyle: \"medium\") }\npdfjs-document-properties-creator = Creator:\npdfjs-document-properties-producer = PDF Producer:\npdfjs-document-properties-version = PDF Version:\npdfjs-document-properties-page-count = Page Count:\npdfjs-document-properties-page-size = Page Size:\npdfjs-document-properties-page-size-unit-inches = in\npdfjs-document-properties-page-size-unit-millimeters = mm\npdfjs-document-properties-page-size-orientation-portrait = portrait\npdfjs-document-properties-page-size-orientation-landscape = landscape\npdfjs-document-properties-page-size-name-a-three = A3\npdfjs-document-properties-page-size-name-a-four = A4\npdfjs-document-properties-page-size-name-letter = Letter\npdfjs-document-properties-page-size-name-legal = Legal\npdfjs-document-properties-page-size-dimension-string = { $width } \xD7 { $height } { $unit } ({ $orientation })\npdfjs-document-properties-page-size-dimension-name-string = { $width } \xD7 { $height } { $unit } ({ $name }, { $orientation })\npdfjs-document-properties-linearized = Fast Web View:\npdfjs-document-properties-linearized-yes = Yes\npdfjs-document-properties-linearized-no = No\npdfjs-document-properties-close-button = Close\npdfjs-print-progress-message = Preparing document for printing\u2026\npdfjs-print-progress-percent = { $progress }%\npdfjs-print-progress-close-button = Cancel\npdfjs-printing-not-supported = Warning: Printing is not fully supported by this browser.\npdfjs-printing-not-ready = Warning: The PDF is not fully loaded for printing.\npdfjs-toggle-sidebar-button =\n .title = Toggle Sidebar\npdfjs-toggle-sidebar-notification-button =\n .title = Toggle Sidebar (document contains outline/attachments/layers)\npdfjs-toggle-sidebar-button-label = Toggle Sidebar\npdfjs-document-outline-button =\n .title = Show Document Outline (double-click to expand/collapse all items)\npdfjs-document-outline-button-label = Document Outline\npdfjs-attachments-button =\n .title = Show Attachments\npdfjs-attachments-button-label = Attachments\npdfjs-layers-button =\n .title = Show Layers (double-click to reset all layers to the default state)\npdfjs-layers-button-label = Layers\npdfjs-thumbs-button =\n .title = Show Thumbnails\npdfjs-thumbs-button-label = Thumbnails\npdfjs-current-outline-item-button =\n .title = Find Current Outline Item\npdfjs-current-outline-item-button-label = Current Outline Item\npdfjs-findbar-button =\n .title = Find in Document\npdfjs-findbar-button-label = Find\npdfjs-additional-layers = Additional Layers\npdfjs-thumb-page-title =\n .title = Page { $page }\npdfjs-thumb-page-canvas =\n .aria-label = Thumbnail of Page { $page }\npdfjs-find-input =\n .title = Find\n .placeholder = Find in document\u2026\npdfjs-find-previous-button =\n .title = Find the previous occurrence of the phrase\npdfjs-find-previous-button-label = Previous\npdfjs-find-next-button =\n .title = Find the next occurrence of the phrase\npdfjs-find-next-button-label = Next\npdfjs-find-highlight-checkbox = Highlight All\npdfjs-find-match-case-checkbox-label = Match Case\npdfjs-find-match-diacritics-checkbox-label = Match Diacritics\npdfjs-find-entire-word-checkbox-label = Whole Words\npdfjs-find-reached-top = Reached top of document, continued from bottom\npdfjs-find-reached-bottom = Reached end of document, continued from top\npdfjs-find-match-count =\n { $total ->\n [one] { $current } of { $total } match\n *[other] { $current } of { $total } matches\n }\npdfjs-find-match-count-limit =\n { $limit ->\n [one] More than { $limit } match\n *[other] More than { $limit } matches\n }\npdfjs-find-not-found = Phrase not found\npdfjs-page-scale-width = Page Width\npdfjs-page-scale-fit = Page Fit\npdfjs-page-scale-auto = Automatic Zoom\npdfjs-page-scale-actual = Actual Size\npdfjs-page-scale-percent = { $scale }%\npdfjs-page-landmark =\n .aria-label = Page { $page }\npdfjs-loading-error = An error occurred while loading the PDF.\npdfjs-invalid-file-error = Invalid or corrupted PDF file.\npdfjs-missing-file-error = Missing PDF file.\npdfjs-unexpected-response-error = Unexpected server response.\npdfjs-rendering-error = An error occurred while rendering the page.\npdfjs-annotation-date-time-string = { DATETIME($dateObj, dateStyle: \"short\", timeStyle: \"medium\") }\npdfjs-text-annotation-type =\n .alt = [{ $type } Annotation]\npdfjs-password-label = Enter the password to open this PDF file.\npdfjs-password-invalid = Invalid password. Please try again.\npdfjs-password-ok-button = OK\npdfjs-password-cancel-button = Cancel\npdfjs-web-fonts-disabled = Web fonts are disabled: unable to use embedded PDF fonts.\npdfjs-editor-free-text-button =\n .title = Text\npdfjs-editor-free-text-button-label = Text\npdfjs-editor-ink-button =\n .title = Draw\npdfjs-editor-ink-button-label = Draw\npdfjs-editor-stamp-button =\n .title = Add or edit images\npdfjs-editor-stamp-button-label = Add or edit images\npdfjs-editor-highlight-button =\n .title = Highlight\npdfjs-editor-highlight-button-label = Highlight\npdfjs-highlight-floating-button1 =\n .title = Highlight\n .aria-label = Highlight\npdfjs-highlight-floating-button-label = Highlight\npdfjs-editor-signature-button =\n .title = Add signature\npdfjs-editor-signature-button-label = Add signature\npdfjs-editor-highlight-editor =\n .aria-label = Highlight editor\npdfjs-editor-ink-editor =\n .aria-label = Drawing editor\npdfjs-editor-signature-editor1 =\n .aria-description = Signature editor: { $description }\npdfjs-editor-stamp-editor =\n .aria-label = Image editor\npdfjs-editor-remove-ink-button =\n .title = Remove drawing\npdfjs-editor-remove-freetext-button =\n .title = Remove text\npdfjs-editor-remove-stamp-button =\n .title = Remove image\npdfjs-editor-remove-highlight-button =\n .title = Remove highlight\npdfjs-editor-remove-signature-button =\n .title = Remove signature\npdfjs-editor-free-text-color-input = Color\npdfjs-editor-free-text-size-input = Size\npdfjs-editor-ink-color-input = Color\npdfjs-editor-ink-thickness-input = Thickness\npdfjs-editor-ink-opacity-input = Opacity\npdfjs-editor-stamp-add-image-button =\n .title = Add image\npdfjs-editor-stamp-add-image-button-label = Add image\npdfjs-editor-free-highlight-thickness-input = Thickness\npdfjs-editor-free-highlight-thickness-title =\n .title = Change thickness when highlighting items other than text\npdfjs-editor-add-signature-container =\n .aria-label = Signature controls and saved signatures\npdfjs-editor-signature-add-signature-button =\n .title = Add new signature\npdfjs-editor-signature-add-signature-button-label = Add new signature\npdfjs-editor-add-saved-signature-button =\n .title = Saved signature: { $description }\npdfjs-free-text2 =\n .aria-label = Text Editor\n .default-content = Start typing\u2026\npdfjs-editor-alt-text-button =\n .aria-label = Alt text\npdfjs-editor-alt-text-button-label = Alt text\npdfjs-editor-alt-text-edit-button =\n .aria-label = Edit alt text\npdfjs-editor-alt-text-dialog-label = Choose an option\npdfjs-editor-alt-text-dialog-description = Alt text (alternative text) helps when people can\u2019t see the image or when it doesn\u2019t load.\npdfjs-editor-alt-text-add-description-label = Add a description\npdfjs-editor-alt-text-add-description-description = Aim for 1-2 sentences that describe the subject, setting, or actions.\npdfjs-editor-alt-text-mark-decorative-label = Mark as decorative\npdfjs-editor-alt-text-mark-decorative-description = This is used for ornamental images, like borders or watermarks.\npdfjs-editor-alt-text-cancel-button = Cancel\npdfjs-editor-alt-text-save-button = Save\npdfjs-editor-alt-text-decorative-tooltip = Marked as decorative\npdfjs-editor-alt-text-textarea =\n .placeholder = For example, \u201CA young man sits down at a table to eat a meal\u201D\npdfjs-editor-resizer-top-left =\n .aria-label = Top left corner \u2014 resize\npdfjs-editor-resizer-top-middle =\n .aria-label = Top middle \u2014 resize\npdfjs-editor-resizer-top-right =\n .aria-label = Top right corner \u2014 resize\npdfjs-editor-resizer-middle-right =\n .aria-label = Middle right \u2014 resize\npdfjs-editor-resizer-bottom-right =\n .aria-label = Bottom right corner \u2014 resize\npdfjs-editor-resizer-bottom-middle =\n .aria-label = Bottom middle \u2014 resize\npdfjs-editor-resizer-bottom-left =\n .aria-label = Bottom left corner \u2014 resize\npdfjs-editor-resizer-middle-left =\n .aria-label = Middle left \u2014 resize\npdfjs-editor-highlight-colorpicker-label = Highlight color\npdfjs-editor-colorpicker-button =\n .title = Change color\npdfjs-editor-colorpicker-dropdown =\n .aria-label = Color choices\npdfjs-editor-colorpicker-yellow =\n .title = Yellow\npdfjs-editor-colorpicker-green =\n .title = Green\npdfjs-editor-colorpicker-blue =\n .title = Blue\npdfjs-editor-colorpicker-pink =\n .title = Pink\npdfjs-editor-colorpicker-red =\n .title = Red\npdfjs-editor-highlight-show-all-button-label = Show all\npdfjs-editor-highlight-show-all-button =\n .title = Show all\npdfjs-editor-new-alt-text-dialog-edit-label = Edit alt text (image description)\npdfjs-editor-new-alt-text-dialog-add-label = Add alt text (image description)\npdfjs-editor-new-alt-text-textarea =\n .placeholder = Write your description here\u2026\npdfjs-editor-new-alt-text-description = Short description for people who can\u2019t see the image or when the image doesn\u2019t load.\npdfjs-editor-new-alt-text-disclaimer1 = This alt text was created automatically and may be inaccurate.\npdfjs-editor-new-alt-text-disclaimer-learn-more-url = Learn more\npdfjs-editor-new-alt-text-create-automatically-button-label = Create alt text automatically\npdfjs-editor-new-alt-text-not-now-button = Not now\npdfjs-editor-new-alt-text-error-title = Couldn\u2019t create alt text automatically\npdfjs-editor-new-alt-text-error-description = Please write your own alt text or try again later.\npdfjs-editor-new-alt-text-error-close-button = Close\npdfjs-editor-new-alt-text-ai-model-downloading-progress = Downloading alt text AI model ({ $downloadedSize } of { $totalSize } MB)\n .aria-valuetext = Downloading alt text AI model ({ $downloadedSize } of { $totalSize } MB)\npdfjs-editor-new-alt-text-added-button =\n .aria-label = Alt text added\npdfjs-editor-new-alt-text-added-button-label = Alt text added\npdfjs-editor-new-alt-text-missing-button =\n .aria-label = Missing alt text\npdfjs-editor-new-alt-text-missing-button-label = Missing alt text\npdfjs-editor-new-alt-text-to-review-button =\n .aria-label = Review alt text\npdfjs-editor-new-alt-text-to-review-button-label = Review alt text\npdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer = Created automatically: { $generatedAltText }\npdfjs-image-alt-text-settings-button =\n .title = Image alt text settings\npdfjs-image-alt-text-settings-button-label = Image alt text settings\npdfjs-editor-alt-text-settings-dialog-label = Image alt text settings\npdfjs-editor-alt-text-settings-automatic-title = Automatic alt text\npdfjs-editor-alt-text-settings-create-model-button-label = Create alt text automatically\npdfjs-editor-alt-text-settings-create-model-description = Suggests descriptions to help people who can\u2019t see the image or when the image doesn\u2019t load.\npdfjs-editor-alt-text-settings-download-model-label = Alt text AI model ({ $totalSize } MB)\npdfjs-editor-alt-text-settings-ai-model-description = Runs locally on your device so your data stays private. Required for automatic alt text.\npdfjs-editor-alt-text-settings-delete-model-button = Delete\npdfjs-editor-alt-text-settings-download-model-button = Download\npdfjs-editor-alt-text-settings-downloading-model-button = Downloading\u2026\npdfjs-editor-alt-text-settings-editor-title = Alt text editor\npdfjs-editor-alt-text-settings-show-dialog-button-label = Show alt text editor right away when adding an image\npdfjs-editor-alt-text-settings-show-dialog-description = Helps you make sure all your images have alt text.\npdfjs-editor-alt-text-settings-close-button = Close\npdfjs-editor-undo-bar-message-highlight = Highlight removed\npdfjs-editor-undo-bar-message-freetext = Text removed\npdfjs-editor-undo-bar-message-ink = Drawing removed\npdfjs-editor-undo-bar-message-stamp = Image removed\npdfjs-editor-undo-bar-message-signature = Signature removed\npdfjs-editor-undo-bar-message-multiple =\n { $count ->\n [one] { $count } annotation removed\n *[other] { $count } annotations removed\n }\npdfjs-editor-undo-bar-undo-button =\n .title = Undo\npdfjs-editor-undo-bar-undo-button-label = Undo\npdfjs-editor-undo-bar-close-button =\n .title = Close\npdfjs-editor-undo-bar-close-button-label = Close\npdfjs-editor-add-signature-dialog-label = This modal allows the user to create a signature to add to a PDF document. The user can edit the name (which also serves as the alt text), and optionally save the signature for repeated use.\npdfjs-editor-add-signature-dialog-title = Add a signature\npdfjs-editor-add-signature-type-button = Type\n .title = Type\npdfjs-editor-add-signature-draw-button = Draw\n .title = Draw\npdfjs-editor-add-signature-image-button = Image\n .title = Image\npdfjs-editor-add-signature-type-input =\n .aria-label = Type your signature\n .placeholder = Type your signature\npdfjs-editor-add-signature-draw-placeholder = Draw your signature\npdfjs-editor-add-signature-draw-thickness-range-label = Thickness\npdfjs-editor-add-signature-draw-thickness-range =\n .title = Drawing thickness: { $thickness }\npdfjs-editor-add-signature-image-placeholder = Drag a file here to upload\npdfjs-editor-add-signature-image-browse-link =\n { PLATFORM() ->\n [macos] Or choose image files\n *[other] Or browse image files\n }\npdfjs-editor-add-signature-description-label = Description (alt text)\npdfjs-editor-add-signature-description-input =\n .title = Description (alt text)\npdfjs-editor-add-signature-description-default-when-drawing = Signature\npdfjs-editor-add-signature-clear-button-label = Clear signature\npdfjs-editor-add-signature-clear-button =\n .title = Clear signature\npdfjs-editor-add-signature-save-checkbox = Save signature\npdfjs-editor-add-signature-save-warning-message = You\u2019ve reached the limit of 5 saved signatures. Remove one to save more.\npdfjs-editor-add-signature-image-upload-error-title = Couldn\u2019t upload image\npdfjs-editor-add-signature-image-upload-error-description = Check your network connection or try another image.\npdfjs-editor-add-signature-error-close-button = Close\npdfjs-editor-add-signature-cancel-button = Cancel\npdfjs-editor-add-signature-add-button = Add\npdfjs-editor-delete-signature-button1 =\n .title = Remove saved signature\npdfjs-editor-delete-signature-button-label1 = Remove saved signature\npdfjs-editor-add-signature-edit-button-label = Edit description\npdfjs-editor-edit-signature-dialog-title = Edit description\npdfjs-editor-edit-signature-update-button = Update"; |
| 7370 |
return createBundle(lang, text); |
| 7371 |
} |
| 7372 |
} |
| 7373 |
|
| 7374 |
;// ./web/generic_scripting.js |
| 7375 |
|
| 7376 |
async function docProperties(pdfDocument) { |
| 7377 |
const url = "", |
| 7378 |
baseUrl = ""; |
| 7379 |
const { |
| 7380 |
info, |
| 7381 |
metadata, |
| 7382 |
contentDispositionFilename, |
| 7383 |
contentLength |
| 7384 |
} = await pdfDocument.getMetadata(); |
| 7385 |
return { |
| 7386 |
...info, |
| 7387 |
baseURL: baseUrl, |
| 7388 |
filesize: contentLength || (await pdfDocument.getDownloadInfo()).length, |
| 7389 |
filename: contentDispositionFilename || getPdfFilenameFromUrl(url), |
| 7390 |
metadata: metadata?.getRaw(), |
| 7391 |
authors: metadata?.get("dc:creator"), |
| 7392 |
numPages: pdfDocument.numPages, |
| 7393 |
URL: url |
| 7394 |
}; |
| 7395 |
} |
| 7396 |
class GenericScripting { |
| 7397 |
constructor(sandboxBundleSrc) { |
| 7398 |
this._ready = new Promise((resolve, reject) => { |
| 7399 |
const sandbox = import( |
| 7400 |
/*webpackIgnore: true*/ |
| 7401 |
/*@vite-ignore*/ |
| 7402 |
sandboxBundleSrc); |
| 7403 |
sandbox.then(pdfjsSandbox => { |
| 7404 |
resolve(pdfjsSandbox.QuickJSSandbox()); |
| 7405 |
}).catch(reject); |
| 7406 |
}); |
| 7407 |
} |
| 7408 |
async createSandbox(data) { |
| 7409 |
const sandbox = await this._ready; |
| 7410 |
sandbox.create(data); |
| 7411 |
} |
| 7412 |
async dispatchEventInSandbox(event) { |
| 7413 |
const sandbox = await this._ready; |
| 7414 |
setTimeout(() => sandbox.dispatchEvent(event), 0); |
| 7415 |
} |
| 7416 |
async destroySandbox() { |
| 7417 |
const sandbox = await this._ready; |
| 7418 |
sandbox.nukeSandbox(); |
| 7419 |
} |
| 7420 |
} |
| 7421 |
|
| 7422 |
;// ./web/generic_signature_storage.js |
| 7423 |
|
| 7424 |
|
| 7425 |
const KEY_STORAGE = "pdfjs.signature"; |
| 7426 |
class SignatureStorage { |
| 7427 |
#eventBus; |
| 7428 |
#signatures = null; |
| 7429 |
#signal = null; |
| 7430 |
constructor(eventBus, signal) { |
| 7431 |
this.#eventBus = eventBus; |
| 7432 |
this.#signal = signal; |
| 7433 |
} |
| 7434 |
#save() { |
| 7435 |
localStorage.setItem(KEY_STORAGE, JSON.stringify(Object.fromEntries(this.#signatures))); |
| 7436 |
} |
| 7437 |
async getAll() { |
| 7438 |
if (this.#signal) { |
| 7439 |
window.addEventListener("storage", ({ |
| 7440 |
key |
| 7441 |
}) => { |
| 7442 |
if (key === KEY_STORAGE) { |
| 7443 |
this.#signatures = null; |
| 7444 |
this.#eventBus?.dispatch("storedsignatureschanged", { |
| 7445 |
source: this |
| 7446 |
}); |
| 7447 |
} |
| 7448 |
}, { |
| 7449 |
signal: this.#signal |
| 7450 |
}); |
| 7451 |
this.#signal = null; |
| 7452 |
} |
| 7453 |
if (!this.#signatures) { |
| 7454 |
this.#signatures = new Map(); |
| 7455 |
const data = localStorage.getItem(KEY_STORAGE); |
| 7456 |
if (data) { |
| 7457 |
for (const [key, value] of Object.entries(JSON.parse(data))) { |
| 7458 |
this.#signatures.set(key, value); |
| 7459 |
} |
| 7460 |
} |
| 7461 |
} |
| 7462 |
return this.#signatures; |
| 7463 |
} |
| 7464 |
async isFull() { |
| 7465 |
return (await this.size()) === 5; |
| 7466 |
} |
| 7467 |
async size() { |
| 7468 |
return (await this.getAll()).size; |
| 7469 |
} |
| 7470 |
async create(data) { |
| 7471 |
if (await this.isFull()) { |
| 7472 |
return null; |
| 7473 |
} |
| 7474 |
const uuid = getUuid(); |
| 7475 |
this.#signatures.set(uuid, data); |
| 7476 |
this.#save(); |
| 7477 |
return uuid; |
| 7478 |
} |
| 7479 |
async delete(uuid) { |
| 7480 |
const signatures = await this.getAll(); |
| 7481 |
if (!signatures.has(uuid)) { |
| 7482 |
return false; |
| 7483 |
} |
| 7484 |
signatures.delete(uuid); |
| 7485 |
this.#save(); |
| 7486 |
return true; |
| 7487 |
} |
| 7488 |
} |
| 7489 |
|
| 7490 |
;// ./web/genericcom.js |
| 7491 |
|
| 7492 |
|
| 7493 |
|
| 7494 |
|
| 7495 |
|
| 7496 |
|
| 7497 |
|
| 7498 |
|
| 7499 |
function initCom(app) {} |
| 7500 |
class Preferences extends BasePreferences { |
| 7501 |
async _writeToStorage(prefObj) { |
| 7502 |
localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj)); |
| 7503 |
} |
| 7504 |
async _readFromStorage(prefObj) { |
| 7505 |
return { |
| 7506 |
prefs: JSON.parse(localStorage.getItem("pdfjs.preferences")) |
| 7507 |
}; |
| 7508 |
} |
| 7509 |
} |
| 7510 |
class ExternalServices extends BaseExternalServices { |
| 7511 |
async createL10n() { |
| 7512 |
return new genericl10n_GenericL10n(AppOptions.get("localeProperties")?.lang); |
| 7513 |
} |
| 7514 |
createScripting() { |
| 7515 |
return new GenericScripting(AppOptions.get("sandboxBundleSrc")); |
| 7516 |
} |
| 7517 |
createSignatureStorage(eventBus, signal) { |
| 7518 |
return new SignatureStorage(eventBus, signal); |
| 7519 |
} |
| 7520 |
} |
| 7521 |
class MLManager { |
| 7522 |
async isEnabledFor(_name) { |
| 7523 |
return false; |
| 7524 |
} |
| 7525 |
async deleteModel(_service) { |
| 7526 |
return null; |
| 7527 |
} |
| 7528 |
isReady(_name) { |
| 7529 |
return false; |
| 7530 |
} |
| 7531 |
guess(_data) {} |
| 7532 |
toggleService(_name, _enabled) {} |
| 7533 |
} |
| 7534 |
|
| 7535 |
;// ./web/new_alt_text_manager.js |
| 7536 |
|
| 7537 |
|
| 7538 |
|
| 7539 |
|
| 7540 |
|
| 7541 |
|
| 7542 |
|
| 7543 |
|
| 7544 |
|
| 7545 |
|
| 7546 |
class NewAltTextManager { |
| 7547 |
#boundCancel = this.#cancel.bind(this); |
| 7548 |
#createAutomaticallyButton; |
| 7549 |
#currentEditor = null; |
| 7550 |
#cancelButton; |
| 7551 |
#descriptionContainer; |
| 7552 |
#dialog; |
| 7553 |
#disclaimer; |
| 7554 |
#downloadModel; |
| 7555 |
#downloadModelDescription; |
| 7556 |
#eventBus; |
| 7557 |
#firstTime = false; |
| 7558 |
#guessedAltText; |
| 7559 |
#hasAI = null; |
| 7560 |
#isEditing = null; |
| 7561 |
#imagePreview; |
| 7562 |
#imageData; |
| 7563 |
#isAILoading = false; |
| 7564 |
#wasAILoading = false; |
| 7565 |
#learnMore; |
| 7566 |
#notNowButton; |
| 7567 |
#overlayManager; |
| 7568 |
#textarea; |
| 7569 |
#title; |
| 7570 |
#uiManager; |
| 7571 |
#previousAltText = null; |
| 7572 |
constructor({ |
| 7573 |
descriptionContainer, |
| 7574 |
dialog, |
| 7575 |
imagePreview, |
| 7576 |
cancelButton, |
| 7577 |
disclaimer, |
| 7578 |
notNowButton, |
| 7579 |
saveButton, |
| 7580 |
textarea, |
| 7581 |
learnMore, |
| 7582 |
errorCloseButton, |
| 7583 |
createAutomaticallyButton, |
| 7584 |
downloadModel, |
| 7585 |
downloadModelDescription, |
| 7586 |
title |
| 7587 |
}, overlayManager, eventBus) { |
| 7588 |
this.#cancelButton = cancelButton; |
| 7589 |
this.#createAutomaticallyButton = createAutomaticallyButton; |
| 7590 |
this.#descriptionContainer = descriptionContainer; |
| 7591 |
this.#dialog = dialog; |
| 7592 |
this.#disclaimer = disclaimer; |
| 7593 |
this.#notNowButton = notNowButton; |
| 7594 |
this.#imagePreview = imagePreview; |
| 7595 |
this.#textarea = textarea; |
| 7596 |
this.#learnMore = learnMore; |
| 7597 |
this.#title = title; |
| 7598 |
this.#downloadModel = downloadModel; |
| 7599 |
this.#downloadModelDescription = downloadModelDescription; |
| 7600 |
this.#overlayManager = overlayManager; |
| 7601 |
this.#eventBus = eventBus; |
| 7602 |
dialog.addEventListener("close", this.#close.bind(this)); |
| 7603 |
dialog.addEventListener("contextmenu", event => { |
| 7604 |
if (event.target !== this.#textarea) { |
| 7605 |
event.preventDefault(); |
| 7606 |
} |
| 7607 |
}); |
| 7608 |
cancelButton.addEventListener("click", this.#boundCancel); |
| 7609 |
notNowButton.addEventListener("click", this.#boundCancel); |
| 7610 |
saveButton.addEventListener("click", this.#save.bind(this)); |
| 7611 |
errorCloseButton.addEventListener("click", () => { |
| 7612 |
this.#toggleError(false); |
| 7613 |
}); |
| 7614 |
createAutomaticallyButton.addEventListener("click", async () => { |
| 7615 |
const checked = createAutomaticallyButton.getAttribute("aria-pressed") !== "true"; |
| 7616 |
this.#currentEditor._reportTelemetry({ |
| 7617 |
action: "pdfjs.image.alt_text.ai_generation_check", |
| 7618 |
data: { |
| 7619 |
status: checked |
| 7620 |
} |
| 7621 |
}); |
| 7622 |
if (this.#uiManager) { |
| 7623 |
this.#uiManager.setPreference("enableGuessAltText", checked); |
| 7624 |
await this.#uiManager.mlManager.toggleService("altText", checked); |
| 7625 |
} |
| 7626 |
this.#toggleGuessAltText(checked, false); |
| 7627 |
}); |
| 7628 |
textarea.addEventListener("focus", () => { |
| 7629 |
this.#wasAILoading = this.#isAILoading; |
| 7630 |
this.#toggleLoading(false); |
| 7631 |
this.#toggleTitleAndDisclaimer(); |
| 7632 |
}); |
| 7633 |
textarea.addEventListener("blur", () => { |
| 7634 |
if (!textarea.value) { |
| 7635 |
this.#toggleLoading(this.#wasAILoading); |
| 7636 |
} |
| 7637 |
this.#toggleTitleAndDisclaimer(); |
| 7638 |
}); |
| 7639 |
textarea.addEventListener("input", () => { |
| 7640 |
this.#toggleTitleAndDisclaimer(); |
| 7641 |
}); |
| 7642 |
eventBus._on("enableguessalttext", ({ |
| 7643 |
value |
| 7644 |
}) => { |
| 7645 |
this.#toggleGuessAltText(value, false); |
| 7646 |
}); |
| 7647 |
this.#overlayManager.register(dialog); |
| 7648 |
this.#learnMore.addEventListener("click", () => { |
| 7649 |
this.#currentEditor._reportTelemetry({ |
| 7650 |
action: "pdfjs.image.alt_text.info", |
| 7651 |
data: { |
| 7652 |
topic: "alt_text" |
| 7653 |
} |
| 7654 |
}); |
| 7655 |
}); |
| 7656 |
} |
| 7657 |
#toggleLoading(value) { |
| 7658 |
if (!this.#uiManager || this.#isAILoading === value) { |
| 7659 |
return; |
| 7660 |
} |
| 7661 |
this.#isAILoading = value; |
| 7662 |
this.#descriptionContainer.classList.toggle("loading", value); |
| 7663 |
} |
| 7664 |
#toggleError(value) { |
| 7665 |
if (!this.#uiManager) { |
| 7666 |
return; |
| 7667 |
} |
| 7668 |
this.#dialog.classList.toggle("error", value); |
| 7669 |
} |
| 7670 |
async #toggleGuessAltText(value, isInitial = false) { |
| 7671 |
if (!this.#uiManager) { |
| 7672 |
return; |
| 7673 |
} |
| 7674 |
this.#dialog.classList.toggle("aiDisabled", !value); |
| 7675 |
this.#createAutomaticallyButton.setAttribute("aria-pressed", value); |
| 7676 |
if (value) { |
| 7677 |
const { |
| 7678 |
altTextLearnMoreUrl |
| 7679 |
} = this.#uiManager.mlManager; |
| 7680 |
if (altTextLearnMoreUrl) { |
| 7681 |
this.#learnMore.href = altTextLearnMoreUrl; |
| 7682 |
} |
| 7683 |
this.#mlGuessAltText(isInitial); |
| 7684 |
} else { |
| 7685 |
this.#toggleLoading(false); |
| 7686 |
this.#isAILoading = false; |
| 7687 |
this.#toggleTitleAndDisclaimer(); |
| 7688 |
} |
| 7689 |
} |
| 7690 |
#toggleNotNow() { |
| 7691 |
this.#notNowButton.classList.toggle("hidden", !this.#firstTime); |
| 7692 |
this.#cancelButton.classList.toggle("hidden", this.#firstTime); |
| 7693 |
} |
| 7694 |
#toggleAI(value) { |
| 7695 |
if (!this.#uiManager || this.#hasAI === value) { |
| 7696 |
return; |
| 7697 |
} |
| 7698 |
this.#hasAI = value; |
| 7699 |
this.#dialog.classList.toggle("noAi", !value); |
| 7700 |
this.#toggleTitleAndDisclaimer(); |
| 7701 |
} |
| 7702 |
#toggleTitleAndDisclaimer() { |
| 7703 |
const visible = this.#isAILoading || this.#guessedAltText && this.#guessedAltText === this.#textarea.value; |
| 7704 |
this.#disclaimer.hidden = !visible; |
| 7705 |
const isEditing = this.#isAILoading || !!this.#textarea.value; |
| 7706 |
if (this.#isEditing === isEditing) { |
| 7707 |
return; |
| 7708 |
} |
| 7709 |
this.#isEditing = isEditing; |
| 7710 |
this.#title.setAttribute("data-l10n-id", isEditing ? "pdfjs-editor-new-alt-text-dialog-edit-label" : "pdfjs-editor-new-alt-text-dialog-add-label"); |
| 7711 |
} |
| 7712 |
async #mlGuessAltText(isInitial) { |
| 7713 |
if (this.#isAILoading) { |
| 7714 |
return; |
| 7715 |
} |
| 7716 |
if (this.#textarea.value) { |
| 7717 |
return; |
| 7718 |
} |
| 7719 |
if (isInitial && this.#previousAltText !== null) { |
| 7720 |
return; |
| 7721 |
} |
| 7722 |
this.#guessedAltText = this.#currentEditor.guessedAltText; |
| 7723 |
if (this.#previousAltText === null && this.#guessedAltText) { |
| 7724 |
this.#addAltText(this.#guessedAltText); |
| 7725 |
return; |
| 7726 |
} |
| 7727 |
this.#toggleLoading(true); |
| 7728 |
this.#toggleTitleAndDisclaimer(); |
| 7729 |
let hasError = false; |
| 7730 |
try { |
| 7731 |
const altText = await this.#currentEditor.mlGuessAltText(this.#imageData, false); |
| 7732 |
if (altText) { |
| 7733 |
this.#guessedAltText = altText; |
| 7734 |
this.#wasAILoading = this.#isAILoading; |
| 7735 |
if (this.#isAILoading) { |
| 7736 |
this.#addAltText(altText); |
| 7737 |
} |
| 7738 |
} |
| 7739 |
} catch (e) { |
| 7740 |
console.error(e); |
| 7741 |
hasError = true; |
| 7742 |
} |
| 7743 |
this.#toggleLoading(false); |
| 7744 |
this.#toggleTitleAndDisclaimer(); |
| 7745 |
if (hasError && this.#uiManager) { |
| 7746 |
this.#toggleError(true); |
| 7747 |
} |
| 7748 |
} |
| 7749 |
#addAltText(altText) { |
| 7750 |
if (!this.#uiManager || this.#textarea.value) { |
| 7751 |
return; |
| 7752 |
} |
| 7753 |
this.#textarea.value = altText; |
| 7754 |
this.#toggleTitleAndDisclaimer(); |
| 7755 |
} |
| 7756 |
#setProgress() { |
| 7757 |
this.#downloadModel.classList.toggle("hidden", false); |
| 7758 |
const callback = async ({ |
| 7759 |
detail: { |
| 7760 |
finished, |
| 7761 |
total, |
| 7762 |
totalLoaded |
| 7763 |
} |
| 7764 |
}) => { |
| 7765 |
const ONE_MEGA_BYTES = 1e6; |
| 7766 |
totalLoaded = Math.min(0.99 * total, totalLoaded); |
| 7767 |
const totalSize = this.#downloadModelDescription.ariaValueMax = Math.round(total / ONE_MEGA_BYTES); |
| 7768 |
const downloadedSize = this.#downloadModelDescription.ariaValueNow = Math.round(totalLoaded / ONE_MEGA_BYTES); |
| 7769 |
this.#downloadModelDescription.setAttribute("data-l10n-args", JSON.stringify({ |
| 7770 |
totalSize, |
| 7771 |
downloadedSize |
| 7772 |
})); |
| 7773 |
if (!finished) { |
| 7774 |
return; |
| 7775 |
} |
| 7776 |
this.#eventBus._off("loadaiengineprogress", callback); |
| 7777 |
this.#downloadModel.classList.toggle("hidden", true); |
| 7778 |
this.#toggleAI(true); |
| 7779 |
if (!this.#uiManager) { |
| 7780 |
return; |
| 7781 |
} |
| 7782 |
const { |
| 7783 |
mlManager |
| 7784 |
} = this.#uiManager; |
| 7785 |
mlManager.toggleService("altText", true); |
| 7786 |
this.#toggleGuessAltText(await mlManager.isEnabledFor("altText"), true); |
| 7787 |
}; |
| 7788 |
this.#eventBus._on("loadaiengineprogress", callback); |
| 7789 |
} |
| 7790 |
async editAltText(uiManager, editor, firstTime) { |
| 7791 |
if (this.#currentEditor || !editor) { |
| 7792 |
return; |
| 7793 |
} |
| 7794 |
if (firstTime && editor.hasAltTextData()) { |
| 7795 |
editor.altTextFinish(); |
| 7796 |
return; |
| 7797 |
} |
| 7798 |
this.#firstTime = firstTime; |
| 7799 |
let { |
| 7800 |
mlManager |
| 7801 |
} = uiManager; |
| 7802 |
let hasAI = !!mlManager; |
| 7803 |
this.#toggleTitleAndDisclaimer(); |
| 7804 |
if (mlManager && !mlManager.isReady("altText")) { |
| 7805 |
hasAI = false; |
| 7806 |
if (mlManager.hasProgress) { |
| 7807 |
this.#setProgress(); |
| 7808 |
} else { |
| 7809 |
mlManager = null; |
| 7810 |
} |
| 7811 |
} else { |
| 7812 |
this.#downloadModel.classList.toggle("hidden", true); |
| 7813 |
} |
| 7814 |
const isAltTextEnabledPromise = mlManager?.isEnabledFor("altText"); |
| 7815 |
this.#currentEditor = editor; |
| 7816 |
this.#uiManager = uiManager; |
| 7817 |
this.#uiManager.removeEditListeners(); |
| 7818 |
({ |
| 7819 |
altText: this.#previousAltText |
| 7820 |
} = editor.altTextData); |
| 7821 |
this.#textarea.value = this.#previousAltText ?? ""; |
| 7822 |
const AI_MAX_IMAGE_DIMENSION = 224; |
| 7823 |
const MAX_PREVIEW_DIMENSION = 180; |
| 7824 |
let canvas, width, height; |
| 7825 |
if (mlManager) { |
| 7826 |
({ |
| 7827 |
canvas, |
| 7828 |
width, |
| 7829 |
height, |
| 7830 |
imageData: this.#imageData |
| 7831 |
} = editor.copyCanvas(AI_MAX_IMAGE_DIMENSION, MAX_PREVIEW_DIMENSION, true)); |
| 7832 |
if (hasAI) { |
| 7833 |
this.#toggleGuessAltText(await isAltTextEnabledPromise, true); |
| 7834 |
} |
| 7835 |
} else { |
| 7836 |
({ |
| 7837 |
canvas, |
| 7838 |
width, |
| 7839 |
height |
| 7840 |
} = editor.copyCanvas(AI_MAX_IMAGE_DIMENSION, MAX_PREVIEW_DIMENSION, false)); |
| 7841 |
} |
| 7842 |
canvas.setAttribute("role", "presentation"); |
| 7843 |
const { |
| 7844 |
style |
| 7845 |
} = canvas; |
| 7846 |
style.width = `${width}px`; |
| 7847 |
style.height = `${height}px`; |
| 7848 |
this.#imagePreview.append(canvas); |
| 7849 |
this.#toggleNotNow(); |
| 7850 |
this.#toggleAI(hasAI); |
| 7851 |
this.#toggleError(false); |
| 7852 |
try { |
| 7853 |
await this.#overlayManager.open(this.#dialog); |
| 7854 |
} catch (ex) { |
| 7855 |
this.#close(); |
| 7856 |
throw ex; |
| 7857 |
} |
| 7858 |
} |
| 7859 |
#cancel() { |
| 7860 |
this.#currentEditor.altTextData = { |
| 7861 |
cancel: true |
| 7862 |
}; |
| 7863 |
const altText = this.#textarea.value.trim(); |
| 7864 |
this.#currentEditor._reportTelemetry({ |
| 7865 |
action: "pdfjs.image.alt_text.dismiss", |
| 7866 |
data: { |
| 7867 |
alt_text_type: altText ? "present" : "empty", |
| 7868 |
flow: this.#firstTime ? "image_add" : "alt_text_edit" |
| 7869 |
} |
| 7870 |
}); |
| 7871 |
this.#currentEditor._reportTelemetry({ |
| 7872 |
action: "pdfjs.image.image_added", |
| 7873 |
data: { |
| 7874 |
alt_text_modal: true, |
| 7875 |
alt_text_type: "skipped" |
| 7876 |
} |
| 7877 |
}); |
| 7878 |
this.#finish(); |
| 7879 |
} |
| 7880 |
#finish() { |
| 7881 |
this.#overlayManager.closeIfActive(this.#dialog); |
| 7882 |
} |
| 7883 |
#close() { |
| 7884 |
const canvas = this.#imagePreview.firstChild; |
| 7885 |
canvas.remove(); |
| 7886 |
canvas.width = canvas.height = 0; |
| 7887 |
this.#imageData = null; |
| 7888 |
this.#toggleLoading(false); |
| 7889 |
this.#uiManager?.addEditListeners(); |
| 7890 |
this.#currentEditor.altTextFinish(); |
| 7891 |
this.#uiManager?.setSelected(this.#currentEditor); |
| 7892 |
this.#currentEditor = null; |
| 7893 |
this.#uiManager = null; |
| 7894 |
} |
| 7895 |
#extractWords(text) { |
| 7896 |
return new Set(text.toLowerCase().split(/[^\p{L}\p{N}]+/gu).filter(x => !!x)); |
| 7897 |
} |
| 7898 |
#save() { |
| 7899 |
const altText = this.#textarea.value.trim(); |
| 7900 |
this.#currentEditor.altTextData = { |
| 7901 |
altText, |
| 7902 |
decorative: false |
| 7903 |
}; |
| 7904 |
this.#currentEditor.altTextData.guessedAltText = this.#guessedAltText; |
| 7905 |
if (this.#guessedAltText && this.#guessedAltText !== altText) { |
| 7906 |
const guessedWords = this.#extractWords(this.#guessedAltText); |
| 7907 |
const words = this.#extractWords(altText); |
| 7908 |
this.#currentEditor._reportTelemetry({ |
| 7909 |
action: "pdfjs.image.alt_text.user_edit", |
| 7910 |
data: { |
| 7911 |
total_words: guessedWords.size, |
| 7912 |
words_removed: guessedWords.difference(words).size, |
| 7913 |
words_added: words.difference(guessedWords).size |
| 7914 |
} |
| 7915 |
}); |
| 7916 |
} |
| 7917 |
this.#currentEditor._reportTelemetry({ |
| 7918 |
action: "pdfjs.image.image_added", |
| 7919 |
data: { |
| 7920 |
alt_text_modal: true, |
| 7921 |
alt_text_type: altText ? "present" : "empty" |
| 7922 |
} |
| 7923 |
}); |
| 7924 |
this.#currentEditor._reportTelemetry({ |
| 7925 |
action: "pdfjs.image.alt_text.save", |
| 7926 |
data: { |
| 7927 |
alt_text_type: altText ? "present" : "empty", |
| 7928 |
flow: this.#firstTime ? "image_add" : "alt_text_edit" |
| 7929 |
} |
| 7930 |
}); |
| 7931 |
this.#finish(); |
| 7932 |
} |
| 7933 |
destroy() { |
| 7934 |
this.#uiManager = null; |
| 7935 |
this.#finish(); |
| 7936 |
} |
| 7937 |
} |
| 7938 |
class ImageAltTextSettings { |
| 7939 |
#aiModelSettings; |
| 7940 |
#createModelButton; |
| 7941 |
#downloadModelButton; |
| 7942 |
#dialog; |
| 7943 |
#eventBus; |
| 7944 |
#mlManager; |
| 7945 |
#overlayManager; |
| 7946 |
#showAltTextDialogButton; |
| 7947 |
constructor({ |
| 7948 |
dialog, |
| 7949 |
createModelButton, |
| 7950 |
aiModelSettings, |
| 7951 |
learnMore, |
| 7952 |
closeButton, |
| 7953 |
deleteModelButton, |
| 7954 |
downloadModelButton, |
| 7955 |
showAltTextDialogButton |
| 7956 |
}, overlayManager, eventBus, mlManager) { |
| 7957 |
this.#dialog = dialog; |
| 7958 |
this.#aiModelSettings = aiModelSettings; |
| 7959 |
this.#createModelButton = createModelButton; |
| 7960 |
this.#downloadModelButton = downloadModelButton; |
| 7961 |
this.#showAltTextDialogButton = showAltTextDialogButton; |
| 7962 |
this.#overlayManager = overlayManager; |
| 7963 |
this.#eventBus = eventBus; |
| 7964 |
this.#mlManager = mlManager; |
| 7965 |
const { |
| 7966 |
altTextLearnMoreUrl |
| 7967 |
} = mlManager; |
| 7968 |
if (altTextLearnMoreUrl) { |
| 7969 |
learnMore.href = altTextLearnMoreUrl; |
| 7970 |
} |
| 7971 |
dialog.addEventListener("contextmenu", noContextMenu); |
| 7972 |
createModelButton.addEventListener("click", async e => { |
| 7973 |
const checked = this.#togglePref("enableGuessAltText", e); |
| 7974 |
await mlManager.toggleService("altText", checked); |
| 7975 |
this.#reportTelemetry({ |
| 7976 |
type: "stamp", |
| 7977 |
action: "pdfjs.image.alt_text.settings_ai_generation_check", |
| 7978 |
data: { |
| 7979 |
status: checked |
| 7980 |
} |
| 7981 |
}); |
| 7982 |
}); |
| 7983 |
showAltTextDialogButton.addEventListener("click", e => { |
| 7984 |
const checked = this.#togglePref("enableNewAltTextWhenAddingImage", e); |
| 7985 |
this.#reportTelemetry({ |
| 7986 |
type: "stamp", |
| 7987 |
action: "pdfjs.image.alt_text.settings_edit_alt_text_check", |
| 7988 |
data: { |
| 7989 |
status: checked |
| 7990 |
} |
| 7991 |
}); |
| 7992 |
}); |
| 7993 |
deleteModelButton.addEventListener("click", this.#delete.bind(this, true)); |
| 7994 |
downloadModelButton.addEventListener("click", this.#download.bind(this, true)); |
| 7995 |
closeButton.addEventListener("click", this.#finish.bind(this)); |
| 7996 |
learnMore.addEventListener("click", () => { |
| 7997 |
this.#reportTelemetry({ |
| 7998 |
type: "stamp", |
| 7999 |
action: "pdfjs.image.alt_text.info", |
| 8000 |
data: { |
| 8001 |
topic: "ai_generation" |
| 8002 |
} |
| 8003 |
}); |
| 8004 |
}); |
| 8005 |
eventBus._on("enablealttextmodeldownload", ({ |
| 8006 |
value |
| 8007 |
}) => { |
| 8008 |
if (value) { |
| 8009 |
this.#download(false); |
| 8010 |
} else { |
| 8011 |
this.#delete(false); |
| 8012 |
} |
| 8013 |
}); |
| 8014 |
this.#overlayManager.register(dialog); |
| 8015 |
} |
| 8016 |
#reportTelemetry(data) { |
| 8017 |
this.#eventBus.dispatch("reporttelemetry", { |
| 8018 |
source: this, |
| 8019 |
details: { |
| 8020 |
type: "editing", |
| 8021 |
data |
| 8022 |
} |
| 8023 |
}); |
| 8024 |
} |
| 8025 |
async #download(isFromUI = false) { |
| 8026 |
if (isFromUI) { |
| 8027 |
this.#downloadModelButton.disabled = true; |
| 8028 |
const span = this.#downloadModelButton.firstChild; |
| 8029 |
span.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-settings-downloading-model-button"); |
| 8030 |
await this.#mlManager.downloadModel("altText"); |
| 8031 |
span.setAttribute("data-l10n-id", "pdfjs-editor-alt-text-settings-download-model-button"); |
| 8032 |
this.#createModelButton.disabled = false; |
| 8033 |
this.#setPref("enableGuessAltText", true); |
| 8034 |
this.#mlManager.toggleService("altText", true); |
| 8035 |
this.#setPref("enableAltTextModelDownload", true); |
| 8036 |
this.#downloadModelButton.disabled = false; |
| 8037 |
} |
| 8038 |
this.#aiModelSettings.classList.toggle("download", false); |
| 8039 |
this.#createModelButton.setAttribute("aria-pressed", true); |
| 8040 |
} |
| 8041 |
async #delete(isFromUI = false) { |
| 8042 |
if (isFromUI) { |
| 8043 |
await this.#mlManager.deleteModel("altText"); |
| 8044 |
this.#setPref("enableGuessAltText", false); |
| 8045 |
this.#setPref("enableAltTextModelDownload", false); |
| 8046 |
} |
| 8047 |
this.#aiModelSettings.classList.toggle("download", true); |
| 8048 |
this.#createModelButton.disabled = true; |
| 8049 |
this.#createModelButton.setAttribute("aria-pressed", false); |
| 8050 |
} |
| 8051 |
async open({ |
| 8052 |
enableGuessAltText, |
| 8053 |
enableNewAltTextWhenAddingImage |
| 8054 |
}) { |
| 8055 |
const { |
| 8056 |
enableAltTextModelDownload |
| 8057 |
} = this.#mlManager; |
| 8058 |
this.#createModelButton.disabled = !enableAltTextModelDownload; |
| 8059 |
this.#createModelButton.setAttribute("aria-pressed", enableAltTextModelDownload && enableGuessAltText); |
| 8060 |
this.#showAltTextDialogButton.setAttribute("aria-pressed", enableNewAltTextWhenAddingImage); |
| 8061 |
this.#aiModelSettings.classList.toggle("download", !enableAltTextModelDownload); |
| 8062 |
await this.#overlayManager.open(this.#dialog); |
| 8063 |
this.#reportTelemetry({ |
| 8064 |
type: "stamp", |
| 8065 |
action: "pdfjs.image.alt_text.settings_displayed" |
| 8066 |
}); |
| 8067 |
} |
| 8068 |
#togglePref(name, { |
| 8069 |
target |
| 8070 |
}) { |
| 8071 |
const checked = target.getAttribute("aria-pressed") !== "true"; |
| 8072 |
this.#setPref(name, checked); |
| 8073 |
target.setAttribute("aria-pressed", checked); |
| 8074 |
return checked; |
| 8075 |
} |
| 8076 |
#setPref(name, value) { |
| 8077 |
this.#eventBus.dispatch("setpreference", { |
| 8078 |
source: this, |
| 8079 |
name, |
| 8080 |
value |
| 8081 |
}); |
| 8082 |
} |
| 8083 |
#finish() { |
| 8084 |
this.#overlayManager.closeIfActive(this.#dialog); |
| 8085 |
} |
| 8086 |
} |
| 8087 |
|
| 8088 |
;// ./web/alt_text_manager.js |
| 8089 |
|
| 8090 |
class AltTextManager { |
| 8091 |
#clickAC = null; |
| 8092 |
#currentEditor = null; |
| 8093 |
#cancelButton; |
| 8094 |
#dialog; |
| 8095 |
#eventBus; |
| 8096 |
#hasUsedPointer = false; |
| 8097 |
#optionDescription; |
| 8098 |
#optionDecorative; |
| 8099 |
#overlayManager; |
| 8100 |
#saveButton; |
| 8101 |
#textarea; |
| 8102 |
#uiManager; |
| 8103 |
#previousAltText = null; |
| 8104 |
#resizeAC = null; |
| 8105 |
#svgElement = null; |
| 8106 |
#rectElement = null; |
| 8107 |
#container; |
| 8108 |
#telemetryData = null; |
| 8109 |
constructor({ |
| 8110 |
dialog, |
| 8111 |
optionDescription, |
| 8112 |
optionDecorative, |
| 8113 |
textarea, |
| 8114 |
cancelButton, |
| 8115 |
saveButton |
| 8116 |
}, container, overlayManager, eventBus) { |
| 8117 |
this.#dialog = dialog; |
| 8118 |
this.#optionDescription = optionDescription; |
| 8119 |
this.#optionDecorative = optionDecorative; |
| 8120 |
this.#textarea = textarea; |
| 8121 |
this.#cancelButton = cancelButton; |
| 8122 |
this.#saveButton = saveButton; |
| 8123 |
this.#overlayManager = overlayManager; |
| 8124 |
this.#eventBus = eventBus; |
| 8125 |
this.#container = container; |
| 8126 |
const onUpdateUIState = this.#updateUIState.bind(this); |
| 8127 |
dialog.addEventListener("close", this.#close.bind(this)); |
| 8128 |
dialog.addEventListener("contextmenu", event => { |
| 8129 |
if (event.target !== this.#textarea) { |
| 8130 |
event.preventDefault(); |
| 8131 |
} |
| 8132 |
}); |
| 8133 |
cancelButton.addEventListener("click", this.#finish.bind(this)); |
| 8134 |
saveButton.addEventListener("click", this.#save.bind(this)); |
| 8135 |
optionDescription.addEventListener("change", onUpdateUIState); |
| 8136 |
optionDecorative.addEventListener("change", onUpdateUIState); |
| 8137 |
this.#overlayManager.register(dialog); |
| 8138 |
} |
| 8139 |
#createSVGElement() { |
| 8140 |
if (this.#svgElement) { |
| 8141 |
return; |
| 8142 |
} |
| 8143 |
const svgFactory = new DOMSVGFactory(); |
| 8144 |
const svg = this.#svgElement = svgFactory.createElement("svg"); |
| 8145 |
svg.setAttribute("width", "0"); |
| 8146 |
svg.setAttribute("height", "0"); |
| 8147 |
const defs = svgFactory.createElement("defs"); |
| 8148 |
svg.append(defs); |
| 8149 |
const mask = svgFactory.createElement("mask"); |
| 8150 |
defs.append(mask); |
| 8151 |
mask.setAttribute("id", "alttext-manager-mask"); |
| 8152 |
mask.setAttribute("maskContentUnits", "objectBoundingBox"); |
| 8153 |
let rect = svgFactory.createElement("rect"); |
| 8154 |
mask.append(rect); |
| 8155 |
rect.setAttribute("fill", "white"); |
| 8156 |
rect.setAttribute("width", "1"); |
| 8157 |
rect.setAttribute("height", "1"); |
| 8158 |
rect.setAttribute("x", "0"); |
| 8159 |
rect.setAttribute("y", "0"); |
| 8160 |
rect = this.#rectElement = svgFactory.createElement("rect"); |
| 8161 |
mask.append(rect); |
| 8162 |
rect.setAttribute("fill", "black"); |
| 8163 |
this.#dialog.append(svg); |
| 8164 |
} |
| 8165 |
async editAltText(uiManager, editor) { |
| 8166 |
if (this.#currentEditor || !editor) { |
| 8167 |
return; |
| 8168 |
} |
| 8169 |
this.#createSVGElement(); |
| 8170 |
this.#hasUsedPointer = false; |
| 8171 |
this.#clickAC = new AbortController(); |
| 8172 |
const clickOpts = { |
| 8173 |
signal: this.#clickAC.signal |
| 8174 |
}, |
| 8175 |
onClick = this.#onClick.bind(this); |
| 8176 |
for (const element of [this.#optionDescription, this.#optionDecorative, this.#textarea, this.#saveButton, this.#cancelButton]) { |
| 8177 |
element.addEventListener("click", onClick, clickOpts); |
| 8178 |
} |
| 8179 |
const { |
| 8180 |
altText, |
| 8181 |
decorative |
| 8182 |
} = editor.altTextData; |
| 8183 |
if (decorative === true) { |
| 8184 |
this.#optionDecorative.checked = true; |
| 8185 |
this.#optionDescription.checked = false; |
| 8186 |
} else { |
| 8187 |
this.#optionDecorative.checked = false; |
| 8188 |
this.#optionDescription.checked = true; |
| 8189 |
} |
| 8190 |
this.#previousAltText = this.#textarea.value = altText?.trim() || ""; |
| 8191 |
this.#updateUIState(); |
| 8192 |
this.#currentEditor = editor; |
| 8193 |
this.#uiManager = uiManager; |
| 8194 |
this.#uiManager.removeEditListeners(); |
| 8195 |
this.#resizeAC = new AbortController(); |
| 8196 |
this.#eventBus._on("resize", this.#setPosition.bind(this), { |
| 8197 |
signal: this.#resizeAC.signal |
| 8198 |
}); |
| 8199 |
try { |
| 8200 |
await this.#overlayManager.open(this.#dialog); |
| 8201 |
this.#setPosition(); |
| 8202 |
} catch (ex) { |
| 8203 |
this.#close(); |
| 8204 |
throw ex; |
| 8205 |
} |
| 8206 |
} |
| 8207 |
#setPosition() { |
| 8208 |
if (!this.#currentEditor) { |
| 8209 |
return; |
| 8210 |
} |
| 8211 |
const dialog = this.#dialog; |
| 8212 |
const { |
| 8213 |
style |
| 8214 |
} = dialog; |
| 8215 |
const { |
| 8216 |
x: containerX, |
| 8217 |
y: containerY, |
| 8218 |
width: containerW, |
| 8219 |
height: containerH |
| 8220 |
} = this.#container.getBoundingClientRect(); |
| 8221 |
const { |
| 8222 |
innerWidth: windowW, |
| 8223 |
innerHeight: windowH |
| 8224 |
} = window; |
| 8225 |
const { |
| 8226 |
width: dialogW, |
| 8227 |
height: dialogH |
| 8228 |
} = dialog.getBoundingClientRect(); |
| 8229 |
const { |
| 8230 |
x, |
| 8231 |
y, |
| 8232 |
width, |
| 8233 |
height |
| 8234 |
} = this.#currentEditor.getClientDimensions(); |
| 8235 |
const MARGIN = 10; |
| 8236 |
const isLTR = this.#uiManager.direction === "ltr"; |
| 8237 |
const xs = Math.max(x, containerX); |
| 8238 |
const xe = Math.min(x + width, containerX + containerW); |
| 8239 |
const ys = Math.max(y, containerY); |
| 8240 |
const ye = Math.min(y + height, containerY + containerH); |
| 8241 |
this.#rectElement.setAttribute("width", `${(xe - xs) / windowW}`); |
| 8242 |
this.#rectElement.setAttribute("height", `${(ye - ys) / windowH}`); |
| 8243 |
this.#rectElement.setAttribute("x", `${xs / windowW}`); |
| 8244 |
this.#rectElement.setAttribute("y", `${ys / windowH}`); |
| 8245 |
let left = null; |
| 8246 |
let top = Math.max(y, 0); |
| 8247 |
top += Math.min(windowH - (top + dialogH), 0); |
| 8248 |
if (isLTR) { |
| 8249 |
if (x + width + MARGIN + dialogW < windowW) { |
| 8250 |
left = x + width + MARGIN; |
| 8251 |
} else if (x > dialogW + MARGIN) { |
| 8252 |
left = x - dialogW - MARGIN; |
| 8253 |
} |
| 8254 |
} else if (x > dialogW + MARGIN) { |
| 8255 |
left = x - dialogW - MARGIN; |
| 8256 |
} else if (x + width + MARGIN + dialogW < windowW) { |
| 8257 |
left = x + width + MARGIN; |
| 8258 |
} |
| 8259 |
if (left === null) { |
| 8260 |
top = null; |
| 8261 |
left = Math.max(x, 0); |
| 8262 |
left += Math.min(windowW - (left + dialogW), 0); |
| 8263 |
if (y > dialogH + MARGIN) { |
| 8264 |
top = y - dialogH - MARGIN; |
| 8265 |
} else if (y + height + MARGIN + dialogH < windowH) { |
| 8266 |
top = y + height + MARGIN; |
| 8267 |
} |
| 8268 |
} |
| 8269 |
if (top !== null) { |
| 8270 |
dialog.classList.add("positioned"); |
| 8271 |
if (isLTR) { |
| 8272 |
style.left = `${left}px`; |
| 8273 |
} else { |
| 8274 |
style.right = `${windowW - left - dialogW}px`; |
| 8275 |
} |
| 8276 |
style.top = `${top}px`; |
| 8277 |
} else { |
| 8278 |
dialog.classList.remove("positioned"); |
| 8279 |
style.left = ""; |
| 8280 |
style.top = ""; |
| 8281 |
} |
| 8282 |
} |
| 8283 |
#finish() { |
| 8284 |
this.#overlayManager.closeIfActive(this.#dialog); |
| 8285 |
} |
| 8286 |
#close() { |
| 8287 |
this.#currentEditor._reportTelemetry(this.#telemetryData || { |
| 8288 |
action: "alt_text_cancel", |
| 8289 |
alt_text_keyboard: !this.#hasUsedPointer |
| 8290 |
}); |
| 8291 |
this.#telemetryData = null; |
| 8292 |
this.#removeOnClickListeners(); |
| 8293 |
this.#uiManager?.addEditListeners(); |
| 8294 |
this.#resizeAC?.abort(); |
| 8295 |
this.#resizeAC = null; |
| 8296 |
this.#currentEditor.altTextFinish(); |
| 8297 |
this.#currentEditor = null; |
| 8298 |
this.#uiManager = null; |
| 8299 |
} |
| 8300 |
#updateUIState() { |
| 8301 |
this.#textarea.disabled = this.#optionDecorative.checked; |
| 8302 |
} |
| 8303 |
#save() { |
| 8304 |
const altText = this.#textarea.value.trim(); |
| 8305 |
const decorative = this.#optionDecorative.checked; |
| 8306 |
this.#currentEditor.altTextData = { |
| 8307 |
altText, |
| 8308 |
decorative |
| 8309 |
}; |
| 8310 |
this.#telemetryData = { |
| 8311 |
action: "alt_text_save", |
| 8312 |
alt_text_description: !!altText, |
| 8313 |
alt_text_edit: !!this.#previousAltText && this.#previousAltText !== altText, |
| 8314 |
alt_text_decorative: decorative, |
| 8315 |
alt_text_keyboard: !this.#hasUsedPointer |
| 8316 |
}; |
| 8317 |
this.#finish(); |
| 8318 |
} |
| 8319 |
#onClick(evt) { |
| 8320 |
if (evt.detail === 0) { |
| 8321 |
return; |
| 8322 |
} |
| 8323 |
this.#hasUsedPointer = true; |
| 8324 |
this.#removeOnClickListeners(); |
| 8325 |
} |
| 8326 |
#removeOnClickListeners() { |
| 8327 |
this.#clickAC?.abort(); |
| 8328 |
this.#clickAC = null; |
| 8329 |
} |
| 8330 |
destroy() { |
| 8331 |
this.#uiManager = null; |
| 8332 |
this.#finish(); |
| 8333 |
this.#svgElement?.remove(); |
| 8334 |
this.#svgElement = this.#rectElement = null; |
| 8335 |
} |
| 8336 |
} |
| 8337 |
|
| 8338 |
;// ./web/annotation_editor_params.js |
| 8339 |
|
| 8340 |
class AnnotationEditorParams { |
| 8341 |
constructor(options, eventBus) { |
| 8342 |
this.eventBus = eventBus; |
| 8343 |
this.#bindListeners(options); |
| 8344 |
} |
| 8345 |
#bindListeners({ |
| 8346 |
editorFreeTextFontSize, |
| 8347 |
editorFreeTextColor, |
| 8348 |
editorInkColor, |
| 8349 |
editorInkThickness, |
| 8350 |
editorInkOpacity, |
| 8351 |
editorStampAddImage, |
| 8352 |
editorFreeHighlightThickness, |
| 8353 |
editorHighlightShowAll, |
| 8354 |
editorSignatureAddSignature |
| 8355 |
}) { |
| 8356 |
const { |
| 8357 |
eventBus |
| 8358 |
} = this; |
| 8359 |
const dispatchEvent = (typeStr, value) => { |
| 8360 |
eventBus.dispatch("switchannotationeditorparams", { |
| 8361 |
source: this, |
| 8362 |
type: AnnotationEditorParamsType[typeStr], |
| 8363 |
value |
| 8364 |
}); |
| 8365 |
}; |
| 8366 |
editorFreeTextFontSize.addEventListener("input", function () { |
| 8367 |
dispatchEvent("FREETEXT_SIZE", this.valueAsNumber); |
| 8368 |
}); |
| 8369 |
editorFreeTextColor.addEventListener("input", function () { |
| 8370 |
dispatchEvent("FREETEXT_COLOR", this.value); |
| 8371 |
}); |
| 8372 |
editorInkColor.addEventListener("input", function () { |
| 8373 |
dispatchEvent("INK_COLOR", this.value); |
| 8374 |
}); |
| 8375 |
editorInkThickness.addEventListener("input", function () { |
| 8376 |
dispatchEvent("INK_THICKNESS", this.valueAsNumber); |
| 8377 |
}); |
| 8378 |
editorInkOpacity.addEventListener("input", function () { |
| 8379 |
dispatchEvent("INK_OPACITY", this.valueAsNumber); |
| 8380 |
}); |
| 8381 |
editorStampAddImage.addEventListener("click", () => { |
| 8382 |
eventBus.dispatch("reporttelemetry", { |
| 8383 |
source: this, |
| 8384 |
details: { |
| 8385 |
type: "editing", |
| 8386 |
data: { |
| 8387 |
action: "pdfjs.image.add_image_click" |
| 8388 |
} |
| 8389 |
} |
| 8390 |
}); |
| 8391 |
dispatchEvent("CREATE"); |
| 8392 |
}); |
| 8393 |
editorFreeHighlightThickness.addEventListener("input", function () { |
| 8394 |
dispatchEvent("HIGHLIGHT_THICKNESS", this.valueAsNumber); |
| 8395 |
}); |
| 8396 |
editorHighlightShowAll.addEventListener("click", function () { |
| 8397 |
const checked = this.getAttribute("aria-pressed") === "true"; |
| 8398 |
this.setAttribute("aria-pressed", !checked); |
| 8399 |
dispatchEvent("HIGHLIGHT_SHOW_ALL", !checked); |
| 8400 |
}); |
| 8401 |
editorSignatureAddSignature.addEventListener("click", () => { |
| 8402 |
dispatchEvent("CREATE"); |
| 8403 |
}); |
| 8404 |
eventBus._on("annotationeditorparamschanged", evt => { |
| 8405 |
for (const [type, value] of evt.details) { |
| 8406 |
switch (type) { |
| 8407 |
case AnnotationEditorParamsType.FREETEXT_SIZE: |
| 8408 |
editorFreeTextFontSize.value = value; |
| 8409 |
break; |
| 8410 |
case AnnotationEditorParamsType.FREETEXT_COLOR: |
| 8411 |
editorFreeTextColor.value = value; |
| 8412 |
break; |
| 8413 |
case AnnotationEditorParamsType.INK_COLOR: |
| 8414 |
editorInkColor.value = value; |
| 8415 |
break; |
| 8416 |
case AnnotationEditorParamsType.INK_THICKNESS: |
| 8417 |
editorInkThickness.value = value; |
| 8418 |
break; |
| 8419 |
case AnnotationEditorParamsType.INK_OPACITY: |
| 8420 |
editorInkOpacity.value = value; |
| 8421 |
break; |
| 8422 |
case AnnotationEditorParamsType.HIGHLIGHT_DEFAULT_COLOR: |
| 8423 |
eventBus.dispatch("mainhighlightcolorpickerupdatecolor", { |
| 8424 |
source: this, |
| 8425 |
value |
| 8426 |
}); |
| 8427 |
break; |
| 8428 |
case AnnotationEditorParamsType.HIGHLIGHT_THICKNESS: |
| 8429 |
editorFreeHighlightThickness.value = value; |
| 8430 |
break; |
| 8431 |
case AnnotationEditorParamsType.HIGHLIGHT_FREE: |
| 8432 |
editorFreeHighlightThickness.disabled = !value; |
| 8433 |
break; |
| 8434 |
case AnnotationEditorParamsType.HIGHLIGHT_SHOW_ALL: |
| 8435 |
editorHighlightShowAll.setAttribute("aria-pressed", value); |
| 8436 |
break; |
| 8437 |
} |
| 8438 |
} |
| 8439 |
}); |
| 8440 |
} |
| 8441 |
} |
| 8442 |
|
| 8443 |
;// ./web/caret_browsing.js |
| 8444 |
|
| 8445 |
const PRECISION = 1e-1; |
| 8446 |
class CaretBrowsingMode { |
| 8447 |
#mainContainer; |
| 8448 |
#toolBarHeight = 0; |
| 8449 |
#viewerContainer; |
| 8450 |
constructor(abortSignal, mainContainer, viewerContainer, toolbarContainer) { |
| 8451 |
this.#mainContainer = mainContainer; |
| 8452 |
this.#viewerContainer = viewerContainer; |
| 8453 |
if (!toolbarContainer) { |
| 8454 |
return; |
| 8455 |
} |
| 8456 |
this.#toolBarHeight = toolbarContainer.getBoundingClientRect().height; |
| 8457 |
const toolbarObserver = new ResizeObserver(entries => { |
| 8458 |
for (const entry of entries) { |
| 8459 |
if (entry.target === toolbarContainer) { |
| 8460 |
this.#toolBarHeight = Math.floor(entry.borderBoxSize[0].blockSize); |
| 8461 |
break; |
| 8462 |
} |
| 8463 |
} |
| 8464 |
}); |
| 8465 |
toolbarObserver.observe(toolbarContainer); |
| 8466 |
abortSignal.addEventListener("abort", () => toolbarObserver.disconnect(), { |
| 8467 |
once: true |
| 8468 |
}); |
| 8469 |
} |
| 8470 |
#isOnSameLine(rect1, rect2) { |
| 8471 |
const top1 = rect1.y; |
| 8472 |
const bot1 = rect1.bottom; |
| 8473 |
const mid1 = rect1.y + rect1.height / 2; |
| 8474 |
const top2 = rect2.y; |
| 8475 |
const bot2 = rect2.bottom; |
| 8476 |
const mid2 = rect2.y + rect2.height / 2; |
| 8477 |
return top1 <= mid2 && mid2 <= bot1 || top2 <= mid1 && mid1 <= bot2; |
| 8478 |
} |
| 8479 |
#isUnderOver(rect, x, y, isUp) { |
| 8480 |
const midY = rect.y + rect.height / 2; |
| 8481 |
return (isUp ? y >= midY : y <= midY) && rect.x - PRECISION <= x && x <= rect.right + PRECISION; |
| 8482 |
} |
| 8483 |
#isVisible(rect) { |
| 8484 |
return rect.top >= this.#toolBarHeight && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth); |
| 8485 |
} |
| 8486 |
#getCaretPosition(selection, isUp) { |
| 8487 |
const { |
| 8488 |
focusNode, |
| 8489 |
focusOffset |
| 8490 |
} = selection; |
| 8491 |
const range = document.createRange(); |
| 8492 |
range.setStart(focusNode, focusOffset); |
| 8493 |
range.setEnd(focusNode, focusOffset); |
| 8494 |
const rect = range.getBoundingClientRect(); |
| 8495 |
return [rect.x, isUp ? rect.top : rect.bottom]; |
| 8496 |
} |
| 8497 |
static #caretPositionFromPoint(x, y) { |
| 8498 |
if (!document.caretPositionFromPoint) { |
| 8499 |
const { |
| 8500 |
startContainer: offsetNode, |
| 8501 |
startOffset: offset |
| 8502 |
} = document.caretRangeFromPoint(x, y); |
| 8503 |
return { |
| 8504 |
offsetNode, |
| 8505 |
offset |
| 8506 |
}; |
| 8507 |
} |
| 8508 |
return document.caretPositionFromPoint(x, y); |
| 8509 |
} |
| 8510 |
#setCaretPositionHelper(selection, caretX, select, element, rect) { |
| 8511 |
rect ||= element.getBoundingClientRect(); |
| 8512 |
if (caretX <= rect.x + PRECISION) { |
| 8513 |
if (select) { |
| 8514 |
selection.extend(element.firstChild, 0); |
| 8515 |
} else { |
| 8516 |
selection.setPosition(element.firstChild, 0); |
| 8517 |
} |
| 8518 |
return; |
| 8519 |
} |
| 8520 |
if (rect.right - PRECISION <= caretX) { |
| 8521 |
const { |
| 8522 |
lastChild |
| 8523 |
} = element; |
| 8524 |
if (select) { |
| 8525 |
selection.extend(lastChild, lastChild.length); |
| 8526 |
} else { |
| 8527 |
selection.setPosition(lastChild, lastChild.length); |
| 8528 |
} |
| 8529 |
return; |
| 8530 |
} |
| 8531 |
const midY = rect.y + rect.height / 2; |
| 8532 |
let caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY); |
| 8533 |
let parentElement = caretPosition.offsetNode?.parentElement; |
| 8534 |
if (parentElement && parentElement !== element) { |
| 8535 |
const elementsAtPoint = document.elementsFromPoint(caretX, midY); |
| 8536 |
const savedVisibilities = []; |
| 8537 |
for (const el of elementsAtPoint) { |
| 8538 |
if (el === element) { |
| 8539 |
break; |
| 8540 |
} |
| 8541 |
const { |
| 8542 |
style |
| 8543 |
} = el; |
| 8544 |
savedVisibilities.push([el, style.visibility]); |
| 8545 |
style.visibility = "hidden"; |
| 8546 |
} |
| 8547 |
caretPosition = CaretBrowsingMode.#caretPositionFromPoint(caretX, midY); |
| 8548 |
parentElement = caretPosition.offsetNode?.parentElement; |
| 8549 |
for (const [el, visibility] of savedVisibilities) { |
| 8550 |
el.style.visibility = visibility; |
| 8551 |
} |
| 8552 |
} |
| 8553 |
if (parentElement !== element) { |
| 8554 |
if (select) { |
| 8555 |
selection.extend(element.firstChild, 0); |
| 8556 |
} else { |
| 8557 |
selection.setPosition(element.firstChild, 0); |
| 8558 |
} |
| 8559 |
return; |
| 8560 |
} |
| 8561 |
if (select) { |
| 8562 |
selection.extend(caretPosition.offsetNode, caretPosition.offset); |
| 8563 |
} else { |
| 8564 |
selection.setPosition(caretPosition.offsetNode, caretPosition.offset); |
| 8565 |
} |
| 8566 |
} |
| 8567 |
#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX) { |
| 8568 |
if (this.#isVisible(newLineElementRect)) { |
| 8569 |
this.#setCaretPositionHelper(selection, caretX, select, newLineElement, newLineElementRect); |
| 8570 |
return; |
| 8571 |
} |
| 8572 |
this.#mainContainer.addEventListener("scrollend", this.#setCaretPositionHelper.bind(this, selection, caretX, select, newLineElement, null), { |
| 8573 |
once: true |
| 8574 |
}); |
| 8575 |
newLineElement.scrollIntoView(); |
| 8576 |
} |
| 8577 |
#getNodeOnNextPage(textLayer, isUp) { |
| 8578 |
while (true) { |
| 8579 |
const page = textLayer.closest(".page"); |
| 8580 |
const pageNumber = parseInt(page.getAttribute("data-page-number")); |
| 8581 |
const nextPage = isUp ? pageNumber - 1 : pageNumber + 1; |
| 8582 |
textLayer = this.#viewerContainer.querySelector(`.page[data-page-number="${nextPage}"] .textLayer`); |
| 8583 |
if (!textLayer) { |
| 8584 |
return null; |
| 8585 |
} |
| 8586 |
const walker = document.createTreeWalker(textLayer, NodeFilter.SHOW_TEXT); |
| 8587 |
const node = isUp ? walker.lastChild() : walker.firstChild(); |
| 8588 |
if (node) { |
| 8589 |
return node; |
| 8590 |
} |
| 8591 |
} |
| 8592 |
} |
| 8593 |
moveCaret(isUp, select) { |
| 8594 |
const selection = document.getSelection(); |
| 8595 |
if (selection.rangeCount === 0) { |
| 8596 |
return; |
| 8597 |
} |
| 8598 |
const { |
| 8599 |
focusNode |
| 8600 |
} = selection; |
| 8601 |
const focusElement = focusNode.nodeType !== Node.ELEMENT_NODE ? focusNode.parentElement : focusNode; |
| 8602 |
const root = focusElement.closest(".textLayer"); |
| 8603 |
if (!root) { |
| 8604 |
return; |
| 8605 |
} |
| 8606 |
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT); |
| 8607 |
walker.currentNode = focusNode; |
| 8608 |
const focusRect = focusElement.getBoundingClientRect(); |
| 8609 |
let newLineElement = null; |
| 8610 |
const nodeIterator = (isUp ? walker.previousSibling : walker.nextSibling).bind(walker); |
| 8611 |
while (nodeIterator()) { |
| 8612 |
const element = walker.currentNode.parentElement; |
| 8613 |
if (!this.#isOnSameLine(focusRect, element.getBoundingClientRect())) { |
| 8614 |
newLineElement = element; |
| 8615 |
break; |
| 8616 |
} |
| 8617 |
} |
| 8618 |
if (!newLineElement) { |
| 8619 |
const node = this.#getNodeOnNextPage(root, isUp); |
| 8620 |
if (!node) { |
| 8621 |
return; |
| 8622 |
} |
| 8623 |
if (select) { |
| 8624 |
const lastNode = (isUp ? walker.firstChild() : walker.lastChild()) || focusNode; |
| 8625 |
selection.extend(lastNode, isUp ? 0 : lastNode.length); |
| 8626 |
const range = document.createRange(); |
| 8627 |
range.setStart(node, isUp ? node.length : 0); |
| 8628 |
range.setEnd(node, isUp ? node.length : 0); |
| 8629 |
selection.addRange(range); |
| 8630 |
return; |
| 8631 |
} |
| 8632 |
const [caretX] = this.#getCaretPosition(selection, isUp); |
| 8633 |
const { |
| 8634 |
parentElement |
| 8635 |
} = node; |
| 8636 |
this.#setCaretPosition(select, selection, parentElement, parentElement.getBoundingClientRect(), caretX); |
| 8637 |
return; |
| 8638 |
} |
| 8639 |
const [caretX, caretY] = this.#getCaretPosition(selection, isUp); |
| 8640 |
const newLineElementRect = newLineElement.getBoundingClientRect(); |
| 8641 |
if (this.#isUnderOver(newLineElementRect, caretX, caretY, isUp)) { |
| 8642 |
this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX); |
| 8643 |
return; |
| 8644 |
} |
| 8645 |
while (nodeIterator()) { |
| 8646 |
const element = walker.currentNode.parentElement; |
| 8647 |
const elementRect = element.getBoundingClientRect(); |
| 8648 |
if (!this.#isOnSameLine(newLineElementRect, elementRect)) { |
| 8649 |
break; |
| 8650 |
} |
| 8651 |
if (this.#isUnderOver(elementRect, caretX, caretY, isUp)) { |
| 8652 |
this.#setCaretPosition(select, selection, element, elementRect, caretX); |
| 8653 |
return; |
| 8654 |
} |
| 8655 |
} |
| 8656 |
this.#setCaretPosition(select, selection, newLineElement, newLineElementRect, caretX); |
| 8657 |
} |
| 8658 |
} |
| 8659 |
|
| 8660 |
;// ./web/download_manager.js |
| 8661 |
|
| 8662 |
|
| 8663 |
|
| 8664 |
|
| 8665 |
function download(blobUrl, filename) { |
| 8666 |
const a = document.createElement("a"); |
| 8667 |
if (!a.click) { |
| 8668 |
throw new Error('DownloadManager: "a.click()" is not supported.'); |
| 8669 |
} |
| 8670 |
a.href = blobUrl; |
| 8671 |
a.target = "_parent"; |
| 8672 |
if ("download" in a) { |
| 8673 |
a.download = filename; |
| 8674 |
} |
| 8675 |
(document.body || document.documentElement).append(a); |
| 8676 |
a.click(); |
| 8677 |
a.remove(); |
| 8678 |
} |
| 8679 |
class DownloadManager { |
| 8680 |
#openBlobUrls = new WeakMap(); |
| 8681 |
downloadData(data, filename, contentType) { |
| 8682 |
const blobUrl = URL.createObjectURL(new Blob([data], { |
| 8683 |
type: contentType |
| 8684 |
})); |
| 8685 |
download(blobUrl, filename); |
| 8686 |
} |
| 8687 |
openOrDownloadData(data, filename, dest = null) { |
| 8688 |
const isPdfData = isPdfFile(filename); |
| 8689 |
const contentType = isPdfData ? "application/pdf" : ""; |
| 8690 |
if (isPdfData) { |
| 8691 |
let blobUrl = this.#openBlobUrls.get(data); |
| 8692 |
if (!blobUrl) { |
| 8693 |
blobUrl = URL.createObjectURL(new Blob([data], { |
| 8694 |
type: contentType |
| 8695 |
})); |
| 8696 |
this.#openBlobUrls.set(data, blobUrl); |
| 8697 |
} |
| 8698 |
let viewerUrl; |
| 8699 |
viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename); |
| 8700 |
if (dest) { |
| 8701 |
viewerUrl += `#${escape(dest)}`; |
| 8702 |
} |
| 8703 |
try { |
| 8704 |
window.open(viewerUrl); |
| 8705 |
return true; |
| 8706 |
} catch (ex) { |
| 8707 |
console.error("openOrDownloadData:", ex); |
| 8708 |
URL.revokeObjectURL(blobUrl); |
| 8709 |
this.#openBlobUrls.delete(data); |
| 8710 |
} |
| 8711 |
} |
| 8712 |
this.downloadData(data, filename, contentType); |
| 8713 |
return false; |
| 8714 |
} |
| 8715 |
download(data, url, filename) { |
| 8716 |
let blobUrl; |
| 8717 |
if (data) { |
| 8718 |
blobUrl = URL.createObjectURL(new Blob([data], { |
| 8719 |
type: "application/pdf" |
| 8720 |
})); |
| 8721 |
} else { |
| 8722 |
if (!createValidAbsoluteUrl(url, "http://example.com")) { |
| 8723 |
console.error(`download - not a valid URL: ${url}`); |
| 8724 |
return; |
| 8725 |
} |
| 8726 |
blobUrl = url + "#pdfjs.action=download"; |
| 8727 |
} |
| 8728 |
download(blobUrl, filename); |
| 8729 |
} |
| 8730 |
} |
| 8731 |
|
| 8732 |
;// ./web/editor_undo_bar.js |
| 8733 |
|
| 8734 |
class EditorUndoBar { |
| 8735 |
#closeButton = null; |
| 8736 |
#container; |
| 8737 |
#eventBus = null; |
| 8738 |
#focusTimeout = null; |
| 8739 |
#initController = null; |
| 8740 |
isOpen = false; |
| 8741 |
#message; |
| 8742 |
#showController = null; |
| 8743 |
#undoButton; |
| 8744 |
static #l10nMessages = Object.freeze({ |
| 8745 |
highlight: "pdfjs-editor-undo-bar-message-highlight", |
| 8746 |
freetext: "pdfjs-editor-undo-bar-message-freetext", |
| 8747 |
stamp: "pdfjs-editor-undo-bar-message-stamp", |
| 8748 |
ink: "pdfjs-editor-undo-bar-message-ink", |
| 8749 |
signature: "pdfjs-editor-undo-bar-message-signature", |
| 8750 |
_multiple: "pdfjs-editor-undo-bar-message-multiple" |
| 8751 |
}); |
| 8752 |
constructor({ |
| 8753 |
container, |
| 8754 |
message, |
| 8755 |
undoButton, |
| 8756 |
closeButton |
| 8757 |
}, eventBus) { |
| 8758 |
this.#container = container; |
| 8759 |
this.#message = message; |
| 8760 |
this.#undoButton = undoButton; |
| 8761 |
this.#closeButton = closeButton; |
| 8762 |
this.#eventBus = eventBus; |
| 8763 |
} |
| 8764 |
destroy() { |
| 8765 |
this.#initController?.abort(); |
| 8766 |
this.#initController = null; |
| 8767 |
this.hide(); |
| 8768 |
} |
| 8769 |
show(undoAction, messageData) { |
| 8770 |
if (!this.#initController) { |
| 8771 |
this.#initController = new AbortController(); |
| 8772 |
const opts = { |
| 8773 |
signal: this.#initController.signal |
| 8774 |
}; |
| 8775 |
const boundHide = this.hide.bind(this); |
| 8776 |
this.#container.addEventListener("contextmenu", noContextMenu, opts); |
| 8777 |
this.#closeButton.addEventListener("click", boundHide, opts); |
| 8778 |
this.#eventBus._on("beforeprint", boundHide, opts); |
| 8779 |
this.#eventBus._on("download", boundHide, opts); |
| 8780 |
} |
| 8781 |
this.hide(); |
| 8782 |
if (typeof messageData === "string") { |
| 8783 |
this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages[messageData]); |
| 8784 |
} else { |
| 8785 |
this.#message.setAttribute("data-l10n-id", EditorUndoBar.#l10nMessages._multiple); |
| 8786 |
this.#message.setAttribute("data-l10n-args", JSON.stringify({ |
| 8787 |
count: messageData |
| 8788 |
})); |
| 8789 |
} |
| 8790 |
this.isOpen = true; |
| 8791 |
this.#container.hidden = false; |
| 8792 |
this.#showController = new AbortController(); |
| 8793 |
this.#undoButton.addEventListener("click", () => { |
| 8794 |
undoAction(); |
| 8795 |
this.hide(); |
| 8796 |
}, { |
| 8797 |
signal: this.#showController.signal |
| 8798 |
}); |
| 8799 |
this.#focusTimeout = setTimeout(() => { |
| 8800 |
this.#container.focus(); |
| 8801 |
this.#focusTimeout = null; |
| 8802 |
}, 100); |
| 8803 |
} |
| 8804 |
hide() { |
| 8805 |
if (!this.isOpen) { |
| 8806 |
return; |
| 8807 |
} |
| 8808 |
this.isOpen = false; |
| 8809 |
this.#container.hidden = true; |
| 8810 |
this.#showController?.abort(); |
| 8811 |
this.#showController = null; |
| 8812 |
if (this.#focusTimeout) { |
| 8813 |
clearTimeout(this.#focusTimeout); |
| 8814 |
this.#focusTimeout = null; |
| 8815 |
} |
| 8816 |
} |
| 8817 |
} |
| 8818 |
|
| 8819 |
;// ./web/overlay_manager.js |
| 8820 |
class OverlayManager { |
| 8821 |
#overlays = new WeakMap(); |
| 8822 |
#active = null; |
| 8823 |
get active() { |
| 8824 |
return this.#active; |
| 8825 |
} |
| 8826 |
async register(dialog, canForceClose = false) { |
| 8827 |
if (typeof dialog !== "object") { |
| 8828 |
throw new Error("Not enough parameters."); |
| 8829 |
} else if (this.#overlays.has(dialog)) { |
| 8830 |
throw new Error("The overlay is already registered."); |
| 8831 |
} |
| 8832 |
this.#overlays.set(dialog, { |
| 8833 |
canForceClose |
| 8834 |
}); |
| 8835 |
dialog.addEventListener("cancel", ({ |
| 8836 |
target |
| 8837 |
}) => { |
| 8838 |
if (this.#active === target) { |
| 8839 |
this.#active = null; |
| 8840 |
} |
| 8841 |
}); |
| 8842 |
} |
| 8843 |
async open(dialog) { |
| 8844 |
if (!this.#overlays.has(dialog)) { |
| 8845 |
throw new Error("The overlay does not exist."); |
| 8846 |
} else if (this.#active) { |
| 8847 |
if (this.#active === dialog) { |
| 8848 |
throw new Error("The overlay is already active."); |
| 8849 |
} else if (this.#overlays.get(dialog).canForceClose) { |
| 8850 |
await this.close(); |
| 8851 |
} else { |
| 8852 |
throw new Error("Another overlay is currently active."); |
| 8853 |
} |
| 8854 |
} |
| 8855 |
this.#active = dialog; |
| 8856 |
dialog.showModal(); |
| 8857 |
} |
| 8858 |
async close(dialog = this.#active) { |
| 8859 |
if (!this.#overlays.has(dialog)) { |
| 8860 |
throw new Error("The overlay does not exist."); |
| 8861 |
} else if (!this.#active) { |
| 8862 |
throw new Error("The overlay is currently not active."); |
| 8863 |
} else if (this.#active !== dialog) { |
| 8864 |
throw new Error("Another overlay is currently active."); |
| 8865 |
} |
| 8866 |
dialog.close(); |
| 8867 |
this.#active = null; |
| 8868 |
} |
| 8869 |
async closeIfActive(dialog) { |
| 8870 |
if (this.#active === dialog) { |
| 8871 |
await this.close(dialog); |
| 8872 |
} |
| 8873 |
} |
| 8874 |
} |
| 8875 |
|
| 8876 |
;// ./web/password_prompt.js |
| 8877 |
|
| 8878 |
|
| 8879 |
class PasswordPrompt { |
| 8880 |
#activeCapability = null; |
| 8881 |
#updateCallback = null; |
| 8882 |
#reason = null; |
| 8883 |
constructor(options, overlayManager, isViewerEmbedded = false) { |
| 8884 |
this.dialog = options.dialog; |
| 8885 |
this.label = options.label; |
| 8886 |
this.input = options.input; |
| 8887 |
this.submitButton = options.submitButton; |
| 8888 |
this.cancelButton = options.cancelButton; |
| 8889 |
this.overlayManager = overlayManager; |
| 8890 |
this._isViewerEmbedded = isViewerEmbedded; |
| 8891 |
this.submitButton.addEventListener("click", this.#verify.bind(this)); |
| 8892 |
this.cancelButton.addEventListener("click", this.close.bind(this)); |
| 8893 |
this.input.addEventListener("keydown", e => { |
| 8894 |
if (e.keyCode === 13) { |
| 8895 |
this.#verify(); |
| 8896 |
} |
| 8897 |
}); |
| 8898 |
this.overlayManager.register(this.dialog, true); |
| 8899 |
this.dialog.addEventListener("close", this.#cancel.bind(this)); |
| 8900 |
} |
| 8901 |
async open() { |
| 8902 |
await this.#activeCapability?.promise; |
| 8903 |
this.#activeCapability = Promise.withResolvers(); |
| 8904 |
try { |
| 8905 |
await this.overlayManager.open(this.dialog); |
| 8906 |
} catch (ex) { |
| 8907 |
this.#activeCapability.resolve(); |
| 8908 |
throw ex; |
| 8909 |
} |
| 8910 |
const passwordIncorrect = this.#reason === PasswordResponses.INCORRECT_PASSWORD; |
| 8911 |
if (!this._isViewerEmbedded || passwordIncorrect) { |
| 8912 |
this.input.focus(); |
| 8913 |
} |
| 8914 |
this.label.setAttribute("data-l10n-id", passwordIncorrect ? "pdfjs-password-invalid" : "pdfjs-password-label"); |
| 8915 |
} |
| 8916 |
async close() { |
| 8917 |
this.overlayManager.closeIfActive(this.dialog); |
| 8918 |
} |
| 8919 |
#verify() { |
| 8920 |
const password = this.input.value; |
| 8921 |
if (password?.length > 0) { |
| 8922 |
this.#invokeCallback(password); |
| 8923 |
} |
| 8924 |
} |
| 8925 |
#cancel() { |
| 8926 |
this.#invokeCallback(new Error("PasswordPrompt cancelled.")); |
| 8927 |
this.#activeCapability.resolve(); |
| 8928 |
} |
| 8929 |
#invokeCallback(password) { |
| 8930 |
if (!this.#updateCallback) { |
| 8931 |
return; |
| 8932 |
} |
| 8933 |
this.close(); |
| 8934 |
this.input.value = ""; |
| 8935 |
this.#updateCallback(password); |
| 8936 |
this.#updateCallback = null; |
| 8937 |
} |
| 8938 |
async setUpdateCallback(updateCallback, reason) { |
| 8939 |
if (this.#activeCapability) { |
| 8940 |
await this.#activeCapability.promise; |
| 8941 |
} |
| 8942 |
this.#updateCallback = updateCallback; |
| 8943 |
this.#reason = reason; |
| 8944 |
} |
| 8945 |
} |
| 8946 |
|
| 8947 |
;// ./web/base_tree_viewer.js |
| 8948 |
|
| 8949 |
const TREEITEM_OFFSET_TOP = -100; |
| 8950 |
const TREEITEM_SELECTED_CLASS = "selected"; |
| 8951 |
class BaseTreeViewer { |
| 8952 |
constructor(options) { |
| 8953 |
this.container = options.container; |
| 8954 |
this.eventBus = options.eventBus; |
| 8955 |
this._l10n = options.l10n; |
| 8956 |
this.reset(); |
| 8957 |
} |
| 8958 |
reset() { |
| 8959 |
this._pdfDocument = null; |
| 8960 |
this._lastToggleIsShow = true; |
| 8961 |
this._currentTreeItem = null; |
| 8962 |
this.container.textContent = ""; |
| 8963 |
this.container.classList.remove("treeWithDeepNesting"); |
| 8964 |
} |
| 8965 |
_dispatchEvent(count) { |
| 8966 |
throw new Error("Not implemented: _dispatchEvent"); |
| 8967 |
} |
| 8968 |
_bindLink(element, params) { |
| 8969 |
throw new Error("Not implemented: _bindLink"); |
| 8970 |
} |
| 8971 |
_normalizeTextContent(str) { |
| 8972 |
return removeNullCharacters(str, true) || "\u2013"; |
| 8973 |
} |
| 8974 |
_addToggleButton(div, hidden = false) { |
| 8975 |
const toggler = document.createElement("div"); |
| 8976 |
toggler.className = "treeItemToggler"; |
| 8977 |
if (hidden) { |
| 8978 |
toggler.classList.add("treeItemsHidden"); |
| 8979 |
} |
| 8980 |
toggler.onclick = evt => { |
| 8981 |
evt.stopPropagation(); |
| 8982 |
toggler.classList.toggle("treeItemsHidden"); |
| 8983 |
if (evt.shiftKey) { |
| 8984 |
const shouldShowAll = !toggler.classList.contains("treeItemsHidden"); |
| 8985 |
this._toggleTreeItem(div, shouldShowAll); |
| 8986 |
} |
| 8987 |
}; |
| 8988 |
div.prepend(toggler); |
| 8989 |
} |
| 8990 |
_toggleTreeItem(root, show = false) { |
| 8991 |
this._l10n.pause(); |
| 8992 |
this._lastToggleIsShow = show; |
| 8993 |
for (const toggler of root.querySelectorAll(".treeItemToggler")) { |
| 8994 |
toggler.classList.toggle("treeItemsHidden", !show); |
| 8995 |
} |
| 8996 |
this._l10n.resume(); |
| 8997 |
} |
| 8998 |
_toggleAllTreeItems() { |
| 8999 |
this._toggleTreeItem(this.container, !this._lastToggleIsShow); |
| 9000 |
} |
| 9001 |
_finishRendering(fragment, count, hasAnyNesting = false) { |
| 9002 |
if (hasAnyNesting) { |
| 9003 |
this.container.classList.add("treeWithDeepNesting"); |
| 9004 |
this._lastToggleIsShow = !fragment.querySelector(".treeItemsHidden"); |
| 9005 |
} |
| 9006 |
this._l10n.pause(); |
| 9007 |
this.container.append(fragment); |
| 9008 |
this._l10n.resume(); |
| 9009 |
this._dispatchEvent(count); |
| 9010 |
} |
| 9011 |
render(params) { |
| 9012 |
throw new Error("Not implemented: render"); |
| 9013 |
} |
| 9014 |
_updateCurrentTreeItem(treeItem = null) { |
| 9015 |
if (this._currentTreeItem) { |
| 9016 |
this._currentTreeItem.classList.remove(TREEITEM_SELECTED_CLASS); |
| 9017 |
this._currentTreeItem = null; |
| 9018 |
} |
| 9019 |
if (treeItem) { |
| 9020 |
treeItem.classList.add(TREEITEM_SELECTED_CLASS); |
| 9021 |
this._currentTreeItem = treeItem; |
| 9022 |
} |
| 9023 |
} |
| 9024 |
_scrollToCurrentTreeItem(treeItem) { |
| 9025 |
if (!treeItem) { |
| 9026 |
return; |
| 9027 |
} |
| 9028 |
this._l10n.pause(); |
| 9029 |
let currentNode = treeItem.parentNode; |
| 9030 |
while (currentNode && currentNode !== this.container) { |
| 9031 |
if (currentNode.classList.contains("treeItem")) { |
| 9032 |
const toggler = currentNode.firstElementChild; |
| 9033 |
toggler?.classList.remove("treeItemsHidden"); |
| 9034 |
} |
| 9035 |
currentNode = currentNode.parentNode; |
| 9036 |
} |
| 9037 |
this._l10n.resume(); |
| 9038 |
this._updateCurrentTreeItem(treeItem); |
| 9039 |
this.container.scrollTo(treeItem.offsetLeft, treeItem.offsetTop + TREEITEM_OFFSET_TOP); |
| 9040 |
} |
| 9041 |
} |
| 9042 |
|
| 9043 |
;// ./web/pdf_attachment_viewer.js |
| 9044 |
|
| 9045 |
|
| 9046 |
|
| 9047 |
class PDFAttachmentViewer extends BaseTreeViewer { |
| 9048 |
constructor(options) { |
| 9049 |
super(options); |
| 9050 |
this.downloadManager = options.downloadManager; |
| 9051 |
this.eventBus._on("fileattachmentannotation", this.#appendAttachment.bind(this)); |
| 9052 |
} |
| 9053 |
reset(keepRenderedCapability = false) { |
| 9054 |
super.reset(); |
| 9055 |
this._attachments = null; |
| 9056 |
if (!keepRenderedCapability) { |
| 9057 |
this._renderedCapability = Promise.withResolvers(); |
| 9058 |
} |
| 9059 |
this._pendingDispatchEvent = false; |
| 9060 |
} |
| 9061 |
async _dispatchEvent(attachmentsCount) { |
| 9062 |
this._renderedCapability.resolve(); |
| 9063 |
if (attachmentsCount === 0 && !this._pendingDispatchEvent) { |
| 9064 |
this._pendingDispatchEvent = true; |
| 9065 |
await waitOnEventOrTimeout({ |
| 9066 |
target: this.eventBus, |
| 9067 |
name: "annotationlayerrendered", |
| 9068 |
delay: 1000 |
| 9069 |
}); |
| 9070 |
if (!this._pendingDispatchEvent) { |
| 9071 |
return; |
| 9072 |
} |
| 9073 |
} |
| 9074 |
this._pendingDispatchEvent = false; |
| 9075 |
this.eventBus.dispatch("attachmentsloaded", { |
| 9076 |
source: this, |
| 9077 |
attachmentsCount |
| 9078 |
}); |
| 9079 |
} |
| 9080 |
_bindLink(element, { |
| 9081 |
content, |
| 9082 |
description, |
| 9083 |
filename |
| 9084 |
}) { |
| 9085 |
if (description) { |
| 9086 |
element.title = description; |
| 9087 |
} |
| 9088 |
element.onclick = () => { |
| 9089 |
this.downloadManager.openOrDownloadData(content, filename); |
| 9090 |
return false; |
| 9091 |
}; |
| 9092 |
} |
| 9093 |
render({ |
| 9094 |
attachments, |
| 9095 |
keepRenderedCapability = false |
| 9096 |
}) { |
| 9097 |
if (this._attachments) { |
| 9098 |
this.reset(keepRenderedCapability); |
| 9099 |
} |
| 9100 |
this._attachments = attachments || null; |
| 9101 |
if (!attachments) { |
| 9102 |
this._dispatchEvent(0); |
| 9103 |
return; |
| 9104 |
} |
| 9105 |
const fragment = document.createDocumentFragment(); |
| 9106 |
let attachmentsCount = 0; |
| 9107 |
for (const name in attachments) { |
| 9108 |
const item = attachments[name]; |
| 9109 |
const div = document.createElement("div"); |
| 9110 |
div.className = "treeItem"; |
| 9111 |
const element = document.createElement("a"); |
| 9112 |
this._bindLink(element, item); |
| 9113 |
element.textContent = this._normalizeTextContent(item.filename); |
| 9114 |
div.append(element); |
| 9115 |
fragment.append(div); |
| 9116 |
attachmentsCount++; |
| 9117 |
} |
| 9118 |
this._finishRendering(fragment, attachmentsCount); |
| 9119 |
} |
| 9120 |
#appendAttachment(item) { |
| 9121 |
const renderedPromise = this._renderedCapability.promise; |
| 9122 |
renderedPromise.then(() => { |
| 9123 |
if (renderedPromise !== this._renderedCapability.promise) { |
| 9124 |
return; |
| 9125 |
} |
| 9126 |
const attachments = this._attachments || Object.create(null); |
| 9127 |
for (const name in attachments) { |
| 9128 |
if (item.filename === name) { |
| 9129 |
return; |
| 9130 |
} |
| 9131 |
} |
| 9132 |
attachments[item.filename] = item; |
| 9133 |
this.render({ |
| 9134 |
attachments, |
| 9135 |
keepRenderedCapability: true |
| 9136 |
}); |
| 9137 |
}); |
| 9138 |
} |
| 9139 |
} |
| 9140 |
|
| 9141 |
;// ./web/grab_to_pan.js |
| 9142 |
|
| 9143 |
const CSS_CLASS_GRAB = "grab-to-pan-grab"; |
| 9144 |
class GrabToPan { |
| 9145 |
#activateAC = null; |
| 9146 |
#mouseDownAC = null; |
| 9147 |
#scrollAC = null; |
| 9148 |
constructor({ |
| 9149 |
element |
| 9150 |
}) { |
| 9151 |
this.element = element; |
| 9152 |
this.document = element.ownerDocument; |
| 9153 |
const overlay = this.overlay = document.createElement("div"); |
| 9154 |
overlay.className = "grab-to-pan-grabbing"; |
| 9155 |
} |
| 9156 |
activate() { |
| 9157 |
if (!this.#activateAC) { |
| 9158 |
this.#activateAC = new AbortController(); |
| 9159 |
this.element.addEventListener("mousedown", this.#onMouseDown.bind(this), { |
| 9160 |
capture: true, |
| 9161 |
signal: this.#activateAC.signal |
| 9162 |
}); |
| 9163 |
this.element.classList.add(CSS_CLASS_GRAB); |
| 9164 |
} |
| 9165 |
} |
| 9166 |
deactivate() { |
| 9167 |
if (this.#activateAC) { |
| 9168 |
this.#activateAC.abort(); |
| 9169 |
this.#activateAC = null; |
| 9170 |
this.#endPan(); |
| 9171 |
this.element.classList.remove(CSS_CLASS_GRAB); |
| 9172 |
} |
| 9173 |
} |
| 9174 |
toggle() { |
| 9175 |
if (this.#activateAC) { |
| 9176 |
this.deactivate(); |
| 9177 |
} else { |
| 9178 |
this.activate(); |
| 9179 |
} |
| 9180 |
} |
| 9181 |
ignoreTarget(node) { |
| 9182 |
return node.matches("a[href], a[href] *, input, textarea, button, button *, select, option"); |
| 9183 |
} |
| 9184 |
#onMouseDown(event) { |
| 9185 |
if (event.button !== 0 || this.ignoreTarget(event.target)) { |
| 9186 |
return; |
| 9187 |
} |
| 9188 |
if (event.originalTarget) { |
| 9189 |
try { |
| 9190 |
event.originalTarget.tagName; |
| 9191 |
} catch { |
| 9192 |
return; |
| 9193 |
} |
| 9194 |
} |
| 9195 |
this.scrollLeftStart = this.element.scrollLeft; |
| 9196 |
this.scrollTopStart = this.element.scrollTop; |
| 9197 |
this.clientXStart = event.clientX; |
| 9198 |
this.clientYStart = event.clientY; |
| 9199 |
this.#mouseDownAC = new AbortController(); |
| 9200 |
const boundEndPan = this.#endPan.bind(this), |
| 9201 |
mouseOpts = { |
| 9202 |
capture: true, |
| 9203 |
signal: this.#mouseDownAC.signal |
| 9204 |
}; |
| 9205 |
this.document.addEventListener("mousemove", this.#onMouseMove.bind(this), mouseOpts); |
| 9206 |
this.document.addEventListener("mouseup", boundEndPan, mouseOpts); |
| 9207 |
this.#scrollAC = new AbortController(); |
| 9208 |
this.element.addEventListener("scroll", boundEndPan, { |
| 9209 |
capture: true, |
| 9210 |
signal: this.#scrollAC.signal |
| 9211 |
}); |
| 9212 |
stopEvent(event); |
| 9213 |
const focusedElement = document.activeElement; |
| 9214 |
if (focusedElement && !focusedElement.contains(event.target)) { |
| 9215 |
focusedElement.blur(); |
| 9216 |
} |
| 9217 |
} |
| 9218 |
#onMouseMove(event) { |
| 9219 |
this.#scrollAC?.abort(); |
| 9220 |
this.#scrollAC = null; |
| 9221 |
if (!(event.buttons & 1)) { |
| 9222 |
this.#endPan(); |
| 9223 |
return; |
| 9224 |
} |
| 9225 |
const xDiff = event.clientX - this.clientXStart; |
| 9226 |
const yDiff = event.clientY - this.clientYStart; |
| 9227 |
this.element.scrollTo({ |
| 9228 |
top: this.scrollTopStart - yDiff, |
| 9229 |
left: this.scrollLeftStart - xDiff, |
| 9230 |
behavior: "instant" |
| 9231 |
}); |
| 9232 |
if (!this.overlay.parentNode) { |
| 9233 |
document.body.append(this.overlay); |
| 9234 |
} |
| 9235 |
} |
| 9236 |
#endPan() { |
| 9237 |
this.#mouseDownAC?.abort(); |
| 9238 |
this.#mouseDownAC = null; |
| 9239 |
this.#scrollAC?.abort(); |
| 9240 |
this.#scrollAC = null; |
| 9241 |
this.overlay.remove(); |
| 9242 |
} |
| 9243 |
} |
| 9244 |
|
| 9245 |
;// ./web/pdf_cursor_tools.js |
| 9246 |
|
| 9247 |
|
| 9248 |
|
| 9249 |
class PDFCursorTools { |
| 9250 |
#active = CursorTool.SELECT; |
| 9251 |
#prevActive = null; |
| 9252 |
constructor({ |
| 9253 |
container, |
| 9254 |
eventBus, |
| 9255 |
cursorToolOnLoad = CursorTool.SELECT |
| 9256 |
}) { |
| 9257 |
this.container = container; |
| 9258 |
this.eventBus = eventBus; |
| 9259 |
this.#addEventListeners(); |
| 9260 |
Promise.resolve().then(() => { |
| 9261 |
this.switchTool(cursorToolOnLoad); |
| 9262 |
}); |
| 9263 |
} |
| 9264 |
get activeTool() { |
| 9265 |
return this.#active; |
| 9266 |
} |
| 9267 |
switchTool(tool) { |
| 9268 |
if (this.#prevActive !== null) { |
| 9269 |
return; |
| 9270 |
} |
| 9271 |
this.#switchTool(tool); |
| 9272 |
} |
| 9273 |
#switchTool(tool, disabled = false) { |
| 9274 |
if (tool === this.#active) { |
| 9275 |
if (this.#prevActive !== null) { |
| 9276 |
this.eventBus.dispatch("cursortoolchanged", { |
| 9277 |
source: this, |
| 9278 |
tool, |
| 9279 |
disabled |
| 9280 |
}); |
| 9281 |
} |
| 9282 |
return; |
| 9283 |
} |
| 9284 |
const disableActiveTool = () => { |
| 9285 |
switch (this.#active) { |
| 9286 |
case CursorTool.SELECT: |
| 9287 |
break; |
| 9288 |
case CursorTool.HAND: |
| 9289 |
this._handTool.deactivate(); |
| 9290 |
break; |
| 9291 |
case CursorTool.ZOOM: |
| 9292 |
} |
| 9293 |
}; |
| 9294 |
switch (tool) { |
| 9295 |
case CursorTool.SELECT: |
| 9296 |
disableActiveTool(); |
| 9297 |
break; |
| 9298 |
case CursorTool.HAND: |
| 9299 |
disableActiveTool(); |
| 9300 |
this._handTool.activate(); |
| 9301 |
break; |
| 9302 |
case CursorTool.ZOOM: |
| 9303 |
default: |
| 9304 |
console.error(`switchTool: "${tool}" is an unsupported value.`); |
| 9305 |
return; |
| 9306 |
} |
| 9307 |
this.#active = tool; |
| 9308 |
this.eventBus.dispatch("cursortoolchanged", { |
| 9309 |
source: this, |
| 9310 |
tool, |
| 9311 |
disabled |
| 9312 |
}); |
| 9313 |
} |
| 9314 |
#addEventListeners() { |
| 9315 |
this.eventBus._on("switchcursortool", evt => { |
| 9316 |
if (!evt.reset) { |
| 9317 |
this.switchTool(evt.tool); |
| 9318 |
} else if (this.#prevActive !== null) { |
| 9319 |
annotationEditorMode = AnnotationEditorType.NONE; |
| 9320 |
presentationModeState = PresentationModeState.NORMAL; |
| 9321 |
enableActive(); |
| 9322 |
} |
| 9323 |
}); |
| 9324 |
let annotationEditorMode = AnnotationEditorType.NONE, |
| 9325 |
presentationModeState = PresentationModeState.NORMAL; |
| 9326 |
const disableActive = () => { |
| 9327 |
this.#prevActive ??= this.#active; |
| 9328 |
this.#switchTool(CursorTool.SELECT, true); |
| 9329 |
}; |
| 9330 |
const enableActive = () => { |
| 9331 |
if (this.#prevActive !== null && annotationEditorMode === AnnotationEditorType.NONE && presentationModeState === PresentationModeState.NORMAL) { |
| 9332 |
this.#switchTool(this.#prevActive); |
| 9333 |
this.#prevActive = null; |
| 9334 |
} |
| 9335 |
}; |
| 9336 |
this.eventBus._on("annotationeditormodechanged", ({ |
| 9337 |
mode |
| 9338 |
}) => { |
| 9339 |
annotationEditorMode = mode; |
| 9340 |
if (mode === AnnotationEditorType.NONE) { |
| 9341 |
enableActive(); |
| 9342 |
} else { |
| 9343 |
disableActive(); |
| 9344 |
} |
| 9345 |
}); |
| 9346 |
this.eventBus._on("presentationmodechanged", ({ |
| 9347 |
state |
| 9348 |
}) => { |
| 9349 |
presentationModeState = state; |
| 9350 |
if (state === PresentationModeState.NORMAL) { |
| 9351 |
enableActive(); |
| 9352 |
} else if (state === PresentationModeState.FULLSCREEN) { |
| 9353 |
disableActive(); |
| 9354 |
} |
| 9355 |
}); |
| 9356 |
} |
| 9357 |
get _handTool() { |
| 9358 |
return shadow(this, "_handTool", new GrabToPan({ |
| 9359 |
element: this.container |
| 9360 |
})); |
| 9361 |
} |
| 9362 |
} |
| 9363 |
|
| 9364 |
;// ./web/pdf_document_properties.js |
| 9365 |
|
| 9366 |
|
| 9367 |
|
| 9368 |
const NON_METRIC_LOCALES = ["en-us", "en-lr", "my"]; |
| 9369 |
const US_PAGE_NAMES = { |
| 9370 |
"8.5x11": "pdfjs-document-properties-page-size-name-letter", |
| 9371 |
"8.5x14": "pdfjs-document-properties-page-size-name-legal" |
| 9372 |
}; |
| 9373 |
const METRIC_PAGE_NAMES = { |
| 9374 |
"297x420": "pdfjs-document-properties-page-size-name-a-three", |
| 9375 |
"210x297": "pdfjs-document-properties-page-size-name-a-four" |
| 9376 |
}; |
| 9377 |
function getPageName(size, isPortrait, pageNames) { |
| 9378 |
const width = isPortrait ? size.width : size.height; |
| 9379 |
const height = isPortrait ? size.height : size.width; |
| 9380 |
return pageNames[`${width}x${height}`]; |
| 9381 |
} |
| 9382 |
class PDFDocumentProperties { |
| 9383 |
#fieldData = null; |
| 9384 |
constructor({ |
| 9385 |
dialog, |
| 9386 |
fields, |
| 9387 |
closeButton |
| 9388 |
}, overlayManager, eventBus, l10n, fileNameLookup, titleLookup) { |
| 9389 |
this.dialog = dialog; |
| 9390 |
this.fields = fields; |
| 9391 |
this.overlayManager = overlayManager; |
| 9392 |
this.l10n = l10n; |
| 9393 |
this._fileNameLookup = fileNameLookup; |
| 9394 |
this._titleLookup = titleLookup; |
| 9395 |
this.#reset(); |
| 9396 |
closeButton.addEventListener("click", this.close.bind(this)); |
| 9397 |
this.overlayManager.register(this.dialog); |
| 9398 |
eventBus._on("pagechanging", evt => { |
| 9399 |
this._currentPageNumber = evt.pageNumber; |
| 9400 |
}); |
| 9401 |
eventBus._on("rotationchanging", evt => { |
| 9402 |
this._pagesRotation = evt.pagesRotation; |
| 9403 |
}); |
| 9404 |
} |
| 9405 |
async open() { |
| 9406 |
await Promise.all([this.overlayManager.open(this.dialog), this._dataAvailableCapability.promise]); |
| 9407 |
const currentPageNumber = this._currentPageNumber; |
| 9408 |
const pagesRotation = this._pagesRotation; |
| 9409 |
if (this.#fieldData && currentPageNumber === this.#fieldData._currentPageNumber && pagesRotation === this.#fieldData._pagesRotation) { |
| 9410 |
this.#updateUI(); |
| 9411 |
return; |
| 9412 |
} |
| 9413 |
const [{ |
| 9414 |
info, |
| 9415 |
metadata, |
| 9416 |
contentLength |
| 9417 |
}, pdfPage] = await Promise.all([this.pdfDocument.getMetadata(), this.pdfDocument.getPage(currentPageNumber)]); |
| 9418 |
const [fileName, fileSize, title, creationDate, modificationDate, pageSize, isLinearized] = await Promise.all([this._fileNameLookup(), this.#parseFileSize(contentLength), this._titleLookup(), this.#parseDate(metadata?.get("xmp:createdate"), info.CreationDate), this.#parseDate(metadata?.get("xmp:modifydate"), info.ModDate), this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation), this.#parseLinearization(info.IsLinearized)]); |
| 9419 |
this.#fieldData = Object.freeze({ |
| 9420 |
fileName, |
| 9421 |
fileSize, |
| 9422 |
title, |
| 9423 |
author: metadata?.get("dc:creator")?.join("\n") || info.Author, |
| 9424 |
subject: metadata?.get("dc:subject")?.join("\n") || info.Subject, |
| 9425 |
keywords: metadata?.get("pdf:keywords") || info.Keywords, |
| 9426 |
creationDate, |
| 9427 |
modificationDate, |
| 9428 |
creator: metadata?.get("xmp:creatortool") || info.Creator, |
| 9429 |
producer: metadata?.get("pdf:producer") || info.Producer, |
| 9430 |
version: info.PDFFormatVersion, |
| 9431 |
pageCount: this.pdfDocument.numPages, |
| 9432 |
pageSize, |
| 9433 |
linearized: isLinearized, |
| 9434 |
_currentPageNumber: currentPageNumber, |
| 9435 |
_pagesRotation: pagesRotation |
| 9436 |
}); |
| 9437 |
this.#updateUI(); |
| 9438 |
const { |
| 9439 |
length |
| 9440 |
} = await this.pdfDocument.getDownloadInfo(); |
| 9441 |
if (contentLength === length) { |
| 9442 |
return; |
| 9443 |
} |
| 9444 |
const data = Object.assign(Object.create(null), this.#fieldData); |
| 9445 |
data.fileSize = await this.#parseFileSize(length); |
| 9446 |
this.#fieldData = Object.freeze(data); |
| 9447 |
this.#updateUI(); |
| 9448 |
} |
| 9449 |
async close() { |
| 9450 |
this.overlayManager.close(this.dialog); |
| 9451 |
} |
| 9452 |
setDocument(pdfDocument) { |
| 9453 |
if (this.pdfDocument) { |
| 9454 |
this.#reset(); |
| 9455 |
this.#updateUI(); |
| 9456 |
} |
| 9457 |
if (!pdfDocument) { |
| 9458 |
return; |
| 9459 |
} |
| 9460 |
this.pdfDocument = pdfDocument; |
| 9461 |
this._dataAvailableCapability.resolve(); |
| 9462 |
} |
| 9463 |
#reset() { |
| 9464 |
this.pdfDocument = null; |
| 9465 |
this.#fieldData = null; |
| 9466 |
this._dataAvailableCapability = Promise.withResolvers(); |
| 9467 |
this._currentPageNumber = 1; |
| 9468 |
this._pagesRotation = 0; |
| 9469 |
} |
| 9470 |
#updateUI() { |
| 9471 |
if (this.#fieldData && this.overlayManager.active !== this.dialog) { |
| 9472 |
return; |
| 9473 |
} |
| 9474 |
for (const id in this.fields) { |
| 9475 |
const content = this.#fieldData?.[id]; |
| 9476 |
this.fields[id].textContent = content || content === 0 ? content : "-"; |
| 9477 |
} |
| 9478 |
} |
| 9479 |
async #parseFileSize(b = 0) { |
| 9480 |
const kb = b / 1024, |
| 9481 |
mb = kb / 1024; |
| 9482 |
return kb ? this.l10n.get(mb >= 1 ? "pdfjs-document-properties-size-mb" : "pdfjs-document-properties-size-kb", { |
| 9483 |
mb, |
| 9484 |
kb, |
| 9485 |
b |
| 9486 |
}) : undefined; |
| 9487 |
} |
| 9488 |
async #parsePageSize(pageSizeInches, pagesRotation) { |
| 9489 |
if (!pageSizeInches) { |
| 9490 |
return undefined; |
| 9491 |
} |
| 9492 |
if (pagesRotation % 180 !== 0) { |
| 9493 |
pageSizeInches = { |
| 9494 |
width: pageSizeInches.height, |
| 9495 |
height: pageSizeInches.width |
| 9496 |
}; |
| 9497 |
} |
| 9498 |
const isPortrait = isPortraitOrientation(pageSizeInches), |
| 9499 |
nonMetric = NON_METRIC_LOCALES.includes(this.l10n.getLanguage()); |
| 9500 |
let sizeInches = { |
| 9501 |
width: Math.round(pageSizeInches.width * 100) / 100, |
| 9502 |
height: Math.round(pageSizeInches.height * 100) / 100 |
| 9503 |
}; |
| 9504 |
let sizeMillimeters = { |
| 9505 |
width: Math.round(pageSizeInches.width * 25.4 * 10) / 10, |
| 9506 |
height: Math.round(pageSizeInches.height * 25.4 * 10) / 10 |
| 9507 |
}; |
| 9508 |
let nameId = getPageName(sizeInches, isPortrait, US_PAGE_NAMES) || getPageName(sizeMillimeters, isPortrait, METRIC_PAGE_NAMES); |
| 9509 |
if (!nameId && !(Number.isInteger(sizeMillimeters.width) && Number.isInteger(sizeMillimeters.height))) { |
| 9510 |
const exactMillimeters = { |
| 9511 |
width: pageSizeInches.width * 25.4, |
| 9512 |
height: pageSizeInches.height * 25.4 |
| 9513 |
}; |
| 9514 |
const intMillimeters = { |
| 9515 |
width: Math.round(sizeMillimeters.width), |
| 9516 |
height: Math.round(sizeMillimeters.height) |
| 9517 |
}; |
| 9518 |
if (Math.abs(exactMillimeters.width - intMillimeters.width) < 0.1 && Math.abs(exactMillimeters.height - intMillimeters.height) < 0.1) { |
| 9519 |
nameId = getPageName(intMillimeters, isPortrait, METRIC_PAGE_NAMES); |
| 9520 |
if (nameId) { |
| 9521 |
sizeInches = { |
| 9522 |
width: Math.round(intMillimeters.width / 25.4 * 100) / 100, |
| 9523 |
height: Math.round(intMillimeters.height / 25.4 * 100) / 100 |
| 9524 |
}; |
| 9525 |
sizeMillimeters = intMillimeters; |
| 9526 |
} |
| 9527 |
} |
| 9528 |
} |
| 9529 |
const [{ |
| 9530 |
width, |
| 9531 |
height |
| 9532 |
}, unit, name, orientation] = await Promise.all([nonMetric ? sizeInches : sizeMillimeters, this.l10n.get(nonMetric ? "pdfjs-document-properties-page-size-unit-inches" : "pdfjs-document-properties-page-size-unit-millimeters"), nameId && this.l10n.get(nameId), this.l10n.get(isPortrait ? "pdfjs-document-properties-page-size-orientation-portrait" : "pdfjs-document-properties-page-size-orientation-landscape")]); |
| 9533 |
return this.l10n.get(name ? "pdfjs-document-properties-page-size-dimension-name-string" : "pdfjs-document-properties-page-size-dimension-string", { |
| 9534 |
width, |
| 9535 |
height, |
| 9536 |
unit, |
| 9537 |
name, |
| 9538 |
orientation |
| 9539 |
}); |
| 9540 |
} |
| 9541 |
async #parseDate(metadataDate, infoDate) { |
| 9542 |
const dateObj = Date.parse(metadataDate) || PDFDateString.toDateObject(infoDate); |
| 9543 |
return dateObj ? this.l10n.get("pdfjs-document-properties-date-time-string", { |
| 9544 |
dateObj: dateObj.valueOf() |
| 9545 |
}) : undefined; |
| 9546 |
} |
| 9547 |
#parseLinearization(isLinearized) { |
| 9548 |
return this.l10n.get(isLinearized ? "pdfjs-document-properties-linearized-yes" : "pdfjs-document-properties-linearized-no"); |
| 9549 |
} |
| 9550 |
} |
| 9551 |
|
| 9552 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.detached.js |
| 9553 |
var es_array_buffer_detached = __webpack_require__(6573); |
| 9554 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.transfer.js |
| 9555 |
var es_array_buffer_transfer = __webpack_require__(8100); |
| 9556 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.array-buffer.transfer-to-fixed-length.js |
| 9557 |
var es_array_buffer_transfer_to_fixed_length = __webpack_require__(7936); |
| 9558 |
;// ./web/pdf_find_utils.js |
| 9559 |
|
| 9560 |
const CharacterType = { |
| 9561 |
SPACE: 0, |
| 9562 |
ALPHA_LETTER: 1, |
| 9563 |
PUNCT: 2, |
| 9564 |
HAN_LETTER: 3, |
| 9565 |
KATAKANA_LETTER: 4, |
| 9566 |
HIRAGANA_LETTER: 5, |
| 9567 |
HALFWIDTH_KATAKANA_LETTER: 6, |
| 9568 |
THAI_LETTER: 7 |
| 9569 |
}; |
| 9570 |
function isAlphabeticalScript(charCode) { |
| 9571 |
return charCode < 0x2e80; |
| 9572 |
} |
| 9573 |
function isAscii(charCode) { |
| 9574 |
return (charCode & 0xff80) === 0; |
| 9575 |
} |
| 9576 |
function isAsciiAlpha(charCode) { |
| 9577 |
return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a; |
| 9578 |
} |
| 9579 |
function isAsciiDigit(charCode) { |
| 9580 |
return charCode >= 0x30 && charCode <= 0x39; |
| 9581 |
} |
| 9582 |
function isAsciiSpace(charCode) { |
| 9583 |
return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a; |
| 9584 |
} |
| 9585 |
function isHan(charCode) { |
| 9586 |
return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff; |
| 9587 |
} |
| 9588 |
function isKatakana(charCode) { |
| 9589 |
return charCode >= 0x30a0 && charCode <= 0x30ff; |
| 9590 |
} |
| 9591 |
function isHiragana(charCode) { |
| 9592 |
return charCode >= 0x3040 && charCode <= 0x309f; |
| 9593 |
} |
| 9594 |
function isHalfwidthKatakana(charCode) { |
| 9595 |
return charCode >= 0xff60 && charCode <= 0xff9f; |
| 9596 |
} |
| 9597 |
function isThai(charCode) { |
| 9598 |
return (charCode & 0xff80) === 0x0e00; |
| 9599 |
} |
| 9600 |
function getCharacterType(charCode) { |
| 9601 |
if (isAlphabeticalScript(charCode)) { |
| 9602 |
if (isAscii(charCode)) { |
| 9603 |
if (isAsciiSpace(charCode)) { |
| 9604 |
return CharacterType.SPACE; |
| 9605 |
} else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) { |
| 9606 |
return CharacterType.ALPHA_LETTER; |
| 9607 |
} |
| 9608 |
return CharacterType.PUNCT; |
| 9609 |
} else if (isThai(charCode)) { |
| 9610 |
return CharacterType.THAI_LETTER; |
| 9611 |
} else if (charCode === 0xa0) { |
| 9612 |
return CharacterType.SPACE; |
| 9613 |
} |
| 9614 |
return CharacterType.ALPHA_LETTER; |
| 9615 |
} |
| 9616 |
if (isHan(charCode)) { |
| 9617 |
return CharacterType.HAN_LETTER; |
| 9618 |
} else if (isKatakana(charCode)) { |
| 9619 |
return CharacterType.KATAKANA_LETTER; |
| 9620 |
} else if (isHiragana(charCode)) { |
| 9621 |
return CharacterType.HIRAGANA_LETTER; |
| 9622 |
} else if (isHalfwidthKatakana(charCode)) { |
| 9623 |
return CharacterType.HALFWIDTH_KATAKANA_LETTER; |
| 9624 |
} |
| 9625 |
return CharacterType.ALPHA_LETTER; |
| 9626 |
} |
| 9627 |
let NormalizeWithNFKC; |
| 9628 |
function getNormalizeWithNFKC() { |
| 9629 |
NormalizeWithNFKC ||= ` ¨ª¯²-µ¸-º¼-¾IJ-ijĿ-ŀʼnſDŽ-njDZ-dzʰ-ʸ˘-˝ˠ-ˤʹͺ;΄-΅·ϐ-ϖϰ-ϲϴ-ϵϹևٵ-ٸक़-य़ড়-ঢ়য়ਲ਼ਸ਼ਖ਼-ਜ਼ਫ਼ଡ଼-ଢ଼ำຳໜ-ໝ༌གྷཌྷདྷབྷཛྷཀྵჼᴬ-ᴮᴰ-ᴺᴼ-ᵍᵏ-ᵪᵸᶛ-ᶿẚ-ẛάέήίόύώΆ᾽-῁ΈΉ῍-῏ΐΊ῝-῟ΰΎ῭-`ΌΏ´-῾ - ‑‗․-… ″-‴‶-‷‼‾⁇-⁉⁗ ⁰-ⁱ⁴-₎ₐ-ₜ₨℀-℃℅-ℇ℉-ℓℕ-№ℙ-ℝ℠-™ℤΩℨK-ℭℯ-ℱℳ-ℹ℻-⅀ⅅ-ⅉ⅐-ⅿ↉∬-∭∯-∰〈-〉①-⓪⨌⩴-⩶⫝̸ⱼ-ⱽⵯ⺟⻳⼀-⿕ 〶〸-〺゛-゜ゟヿㄱ-ㆎ㆒-㆟㈀-㈞㈠-㉇㉐-㉾㊀-㏿ꚜ-ꚝꝰꟲ-ꟴꟸ-ꟹꭜ-ꭟꭩ豈-嗀塚晴凞-羽蘒諸逸-都飯-舘並-龎ff-stﬓ-ﬗיִײַ-זּטּ-לּמּנּ-סּףּ-פּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-﷼︐-︙︰-﹄﹇-﹒﹔-﹦﹨-﹫ﹰ-ﹲﹴﹶ-ﻼ!-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ¢-₩`; |
| 9630 |
return NormalizeWithNFKC; |
| 9631 |
} |
| 9632 |
|
| 9633 |
;// ./web/pdf_find_controller.js |
| 9634 |
|
| 9635 |
|
| 9636 |
|
| 9637 |
|
| 9638 |
|
| 9639 |
|
| 9640 |
|
| 9641 |
|
| 9642 |
|
| 9643 |
|
| 9644 |
|
| 9645 |
|
| 9646 |
|
| 9647 |
|
| 9648 |
|
| 9649 |
|
| 9650 |
|
| 9651 |
|
| 9652 |
const FindState = { |
| 9653 |
FOUND: 0, |
| 9654 |
NOT_FOUND: 1, |
| 9655 |
WRAPPED: 2, |
| 9656 |
PENDING: 3 |
| 9657 |
}; |
| 9658 |
const FIND_TIMEOUT = 250; |
| 9659 |
const MATCH_SCROLL_OFFSET_TOP = -50; |
| 9660 |
const MATCH_SCROLL_OFFSET_LEFT = -400; |
| 9661 |
const CHARACTERS_TO_NORMALIZE = { |
| 9662 |
"\u2010": "-", |
| 9663 |
"\u2018": "'", |
| 9664 |
"\u2019": "'", |
| 9665 |
"\u201A": "'", |
| 9666 |
"\u201B": "'", |
| 9667 |
"\u201C": '"', |
| 9668 |
"\u201D": '"', |
| 9669 |
"\u201E": '"', |
| 9670 |
"\u201F": '"', |
| 9671 |
"\u00BC": "1/4", |
| 9672 |
"\u00BD": "1/2", |
| 9673 |
"\u00BE": "3/4" |
| 9674 |
}; |
| 9675 |
const DIACRITICS_EXCEPTION = new Set([0x3099, 0x309a, 0x094d, 0x09cd, 0x0a4d, 0x0acd, 0x0b4d, 0x0bcd, 0x0c4d, 0x0ccd, 0x0d3b, 0x0d3c, 0x0d4d, 0x0dca, 0x0e3a, 0x0eba, 0x0f84, 0x1039, 0x103a, 0x1714, 0x1734, 0x17d2, 0x1a60, 0x1b44, 0x1baa, 0x1bab, 0x1bf2, 0x1bf3, 0x2d7f, 0xa806, 0xa82c, 0xa8c4, 0xa953, 0xa9c0, 0xaaf6, 0xabed, 0x0c56, 0x0f71, 0x0f72, 0x0f7a, 0x0f7b, 0x0f7c, 0x0f7d, 0x0f80, 0x0f74]); |
| 9676 |
let DIACRITICS_EXCEPTION_STR; |
| 9677 |
const DIACRITICS_REG_EXP = /\p{M}+/gu; |
| 9678 |
const SPECIAL_CHARS_REG_EXP = /([.*+?^${}()|[\]\\])|(\p{P})|(\s+)|(\p{M})|(\p{L})/gu; |
| 9679 |
const NOT_DIACRITIC_FROM_END_REG_EXP = /([^\p{M}])\p{M}*$/u; |
| 9680 |
const NOT_DIACRITIC_FROM_START_REG_EXP = /^\p{M}*([^\p{M}])/u; |
| 9681 |
const SYLLABLES_REG_EXP = /[\uAC00-\uD7AF\uFA6C\uFACF-\uFAD1\uFAD5-\uFAD7]+/g; |
| 9682 |
const SYLLABLES_LENGTHS = new Map(); |
| 9683 |
const FIRST_CHAR_SYLLABLES_REG_EXP = "[\\u1100-\\u1112\\ud7a4-\\ud7af\\ud84a\\ud84c\\ud850\\ud854\\ud857\\ud85f]"; |
| 9684 |
const NFKC_CHARS_TO_NORMALIZE = new Map(); |
| 9685 |
let noSyllablesRegExp = null; |
| 9686 |
let withSyllablesRegExp = null; |
| 9687 |
function normalize(text) { |
| 9688 |
const syllablePositions = []; |
| 9689 |
let m; |
| 9690 |
while ((m = SYLLABLES_REG_EXP.exec(text)) !== null) { |
| 9691 |
let { |
| 9692 |
index |
| 9693 |
} = m; |
| 9694 |
for (const char of m[0]) { |
| 9695 |
let len = SYLLABLES_LENGTHS.get(char); |
| 9696 |
if (!len) { |
| 9697 |
len = char.normalize("NFD").length; |
| 9698 |
SYLLABLES_LENGTHS.set(char, len); |
| 9699 |
} |
| 9700 |
syllablePositions.push([len, index++]); |
| 9701 |
} |
| 9702 |
} |
| 9703 |
const hasSyllables = syllablePositions.length > 0; |
| 9704 |
let normalizationRegex; |
| 9705 |
if (!hasSyllables && noSyllablesRegExp) { |
| 9706 |
normalizationRegex = noSyllablesRegExp; |
| 9707 |
} else if (hasSyllables && withSyllablesRegExp) { |
| 9708 |
normalizationRegex = withSyllablesRegExp; |
| 9709 |
} else { |
| 9710 |
const replace = Object.keys(CHARACTERS_TO_NORMALIZE).join(""); |
| 9711 |
const toNormalizeWithNFKC = getNormalizeWithNFKC(); |
| 9712 |
const CJK = "(?:\\p{Ideographic}|[\u3040-\u30FF])"; |
| 9713 |
const HKDiacritics = "(?:\u3099|\u309A)"; |
| 9714 |
const BrokenWord = `\\p{Ll}-\\n(?=\\p{Ll})|\\p{Lu}-\\n(?=\\p{L})`; |
| 9715 |
const regexps = [`[${replace}]`, `[${toNormalizeWithNFKC}]`, `${HKDiacritics}\\n`, "\\p{M}+(?:-\\n)?", `${BrokenWord}`, "\\S-\\n", `${CJK}\\n`, "\\n", hasSyllables ? FIRST_CHAR_SYLLABLES_REG_EXP : "\\u0000"]; |
| 9716 |
normalizationRegex = new RegExp(regexps.map(r => `(${r})`).join("|"), "gum"); |
| 9717 |
if (hasSyllables) { |
| 9718 |
withSyllablesRegExp = normalizationRegex; |
| 9719 |
} else { |
| 9720 |
noSyllablesRegExp = normalizationRegex; |
| 9721 |
} |
| 9722 |
} |
| 9723 |
const rawDiacriticsPositions = []; |
| 9724 |
while ((m = DIACRITICS_REG_EXP.exec(text)) !== null) { |
| 9725 |
rawDiacriticsPositions.push([m[0].length, m.index]); |
| 9726 |
} |
| 9727 |
let normalized = text.normalize("NFD"); |
| 9728 |
const positions = [0, 0]; |
| 9729 |
let rawDiacriticsIndex = 0; |
| 9730 |
let syllableIndex = 0; |
| 9731 |
let shift = 0; |
| 9732 |
let shiftOrigin = 0; |
| 9733 |
let eol = 0; |
| 9734 |
let hasDiacritics = false; |
| 9735 |
normalized = normalized.replace(normalizationRegex, (match, p1, p2, p3, p4, p5, p6, p7, p8, p9, i) => { |
| 9736 |
i -= shiftOrigin; |
| 9737 |
if (p1) { |
| 9738 |
const replacement = CHARACTERS_TO_NORMALIZE[p1]; |
| 9739 |
const jj = replacement.length; |
| 9740 |
for (let j = 1; j < jj; j++) { |
| 9741 |
positions.push(i - shift + j, shift - j); |
| 9742 |
} |
| 9743 |
shift -= jj - 1; |
| 9744 |
return replacement; |
| 9745 |
} |
| 9746 |
if (p2) { |
| 9747 |
let replacement = NFKC_CHARS_TO_NORMALIZE.get(p2); |
| 9748 |
if (!replacement) { |
| 9749 |
replacement = p2.normalize("NFKC"); |
| 9750 |
NFKC_CHARS_TO_NORMALIZE.set(p2, replacement); |
| 9751 |
} |
| 9752 |
const jj = replacement.length; |
| 9753 |
for (let j = 1; j < jj; j++) { |
| 9754 |
positions.push(i - shift + j, shift - j); |
| 9755 |
} |
| 9756 |
shift -= jj - 1; |
| 9757 |
return replacement; |
| 9758 |
} |
| 9759 |
if (p3) { |
| 9760 |
hasDiacritics = true; |
| 9761 |
if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) { |
| 9762 |
++rawDiacriticsIndex; |
| 9763 |
} else { |
| 9764 |
positions.push(i - 1 - shift + 1, shift - 1); |
| 9765 |
shift -= 1; |
| 9766 |
shiftOrigin += 1; |
| 9767 |
} |
| 9768 |
positions.push(i - shift + 1, shift); |
| 9769 |
shiftOrigin += 1; |
| 9770 |
eol += 1; |
| 9771 |
return p3.charAt(0); |
| 9772 |
} |
| 9773 |
if (p4) { |
| 9774 |
const hasTrailingDashEOL = p4.endsWith("\n"); |
| 9775 |
const len = hasTrailingDashEOL ? p4.length - 2 : p4.length; |
| 9776 |
hasDiacritics = true; |
| 9777 |
let jj = len; |
| 9778 |
if (i + eol === rawDiacriticsPositions[rawDiacriticsIndex]?.[1]) { |
| 9779 |
jj -= rawDiacriticsPositions[rawDiacriticsIndex][0]; |
| 9780 |
++rawDiacriticsIndex; |
| 9781 |
} |
| 9782 |
for (let j = 1; j <= jj; j++) { |
| 9783 |
positions.push(i - 1 - shift + j, shift - j); |
| 9784 |
} |
| 9785 |
shift -= jj; |
| 9786 |
shiftOrigin += jj; |
| 9787 |
if (hasTrailingDashEOL) { |
| 9788 |
i += len - 1; |
| 9789 |
positions.push(i - shift + 1, 1 + shift); |
| 9790 |
shift += 1; |
| 9791 |
shiftOrigin += 1; |
| 9792 |
eol += 1; |
| 9793 |
return p4.slice(0, len); |
| 9794 |
} |
| 9795 |
return p4; |
| 9796 |
} |
| 9797 |
if (p5) { |
| 9798 |
const len = p5.length - 2; |
| 9799 |
positions.push(i - shift + len, 1 + shift); |
| 9800 |
shift += 1; |
| 9801 |
shiftOrigin += 1; |
| 9802 |
eol += 1; |
| 9803 |
return p5.slice(0, -2); |
| 9804 |
} |
| 9805 |
if (p6) { |
| 9806 |
shiftOrigin += 1; |
| 9807 |
eol += 1; |
| 9808 |
return p6.slice(0, -1); |
| 9809 |
} |
| 9810 |
if (p7) { |
| 9811 |
const len = p7.length - 1; |
| 9812 |
positions.push(i - shift + len, shift); |
| 9813 |
shiftOrigin += 1; |
| 9814 |
eol += 1; |
| 9815 |
return p7.slice(0, -1); |
| 9816 |
} |
| 9817 |
if (p8) { |
| 9818 |
positions.push(i - shift + 1, shift - 1); |
| 9819 |
shift -= 1; |
| 9820 |
shiftOrigin += 1; |
| 9821 |
eol += 1; |
| 9822 |
return " "; |
| 9823 |
} |
| 9824 |
if (i + eol === syllablePositions[syllableIndex]?.[1]) { |
| 9825 |
const newCharLen = syllablePositions[syllableIndex][0] - 1; |
| 9826 |
++syllableIndex; |
| 9827 |
for (let j = 1; j <= newCharLen; j++) { |
| 9828 |
positions.push(i - (shift - j), shift - j); |
| 9829 |
} |
| 9830 |
shift -= newCharLen; |
| 9831 |
shiftOrigin += newCharLen; |
| 9832 |
} |
| 9833 |
return p9; |
| 9834 |
}); |
| 9835 |
positions.push(normalized.length, shift); |
| 9836 |
const starts = new Uint32Array(positions.length >> 1); |
| 9837 |
const shifts = new Int32Array(positions.length >> 1); |
| 9838 |
for (let i = 0, ii = positions.length; i < ii; i += 2) { |
| 9839 |
starts[i >> 1] = positions[i]; |
| 9840 |
shifts[i >> 1] = positions[i + 1]; |
| 9841 |
} |
| 9842 |
return [normalized, [starts, shifts], hasDiacritics]; |
| 9843 |
} |
| 9844 |
function getOriginalIndex(diffs, pos, len) { |
| 9845 |
if (!diffs) { |
| 9846 |
return [pos, len]; |
| 9847 |
} |
| 9848 |
const [starts, shifts] = diffs; |
| 9849 |
const start = pos; |
| 9850 |
const end = pos + len - 1; |
| 9851 |
let i = binarySearchFirstItem(starts, x => x >= start); |
| 9852 |
if (starts[i] > start) { |
| 9853 |
--i; |
| 9854 |
} |
| 9855 |
let j = binarySearchFirstItem(starts, x => x >= end, i); |
| 9856 |
if (starts[j] > end) { |
| 9857 |
--j; |
| 9858 |
} |
| 9859 |
const oldStart = start + shifts[i]; |
| 9860 |
const oldEnd = end + shifts[j]; |
| 9861 |
const oldLen = oldEnd + 1 - oldStart; |
| 9862 |
return [oldStart, oldLen]; |
| 9863 |
} |
| 9864 |
class PDFFindController { |
| 9865 |
#state = null; |
| 9866 |
#updateMatchesCountOnProgress = true; |
| 9867 |
#visitedPagesCount = 0; |
| 9868 |
constructor({ |
| 9869 |
linkService, |
| 9870 |
eventBus, |
| 9871 |
updateMatchesCountOnProgress = true |
| 9872 |
}) { |
| 9873 |
this._linkService = linkService; |
| 9874 |
this._eventBus = eventBus; |
| 9875 |
this.#updateMatchesCountOnProgress = updateMatchesCountOnProgress; |
| 9876 |
this.onIsPageVisible = null; |
| 9877 |
this.#reset(); |
| 9878 |
eventBus._on("find", this.#onFind.bind(this)); |
| 9879 |
eventBus._on("findbarclose", this.#onFindBarClose.bind(this)); |
| 9880 |
} |
| 9881 |
get highlightMatches() { |
| 9882 |
return this._highlightMatches; |
| 9883 |
} |
| 9884 |
get pageMatches() { |
| 9885 |
return this._pageMatches; |
| 9886 |
} |
| 9887 |
get pageMatchesLength() { |
| 9888 |
return this._pageMatchesLength; |
| 9889 |
} |
| 9890 |
get selected() { |
| 9891 |
return this._selected; |
| 9892 |
} |
| 9893 |
get state() { |
| 9894 |
return this.#state; |
| 9895 |
} |
| 9896 |
setDocument(pdfDocument) { |
| 9897 |
if (this._pdfDocument) { |
| 9898 |
this.#reset(); |
| 9899 |
} |
| 9900 |
if (!pdfDocument) { |
| 9901 |
return; |
| 9902 |
} |
| 9903 |
this._pdfDocument = pdfDocument; |
| 9904 |
this._firstPageCapability.resolve(); |
| 9905 |
} |
| 9906 |
#onFind(state) { |
| 9907 |
if (!state) { |
| 9908 |
return; |
| 9909 |
} |
| 9910 |
const pdfDocument = this._pdfDocument; |
| 9911 |
const { |
| 9912 |
type |
| 9913 |
} = state; |
| 9914 |
if (this.#state === null || this.#shouldDirtyMatch(state)) { |
| 9915 |
this._dirtyMatch = true; |
| 9916 |
} |
| 9917 |
this.#state = state; |
| 9918 |
if (type !== "highlightallchange") { |
| 9919 |
this.#updateUIState(FindState.PENDING); |
| 9920 |
} |
| 9921 |
this._firstPageCapability.promise.then(() => { |
| 9922 |
if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { |
| 9923 |
return; |
| 9924 |
} |
| 9925 |
this.#extractText(); |
| 9926 |
const findbarClosed = !this._highlightMatches; |
| 9927 |
const pendingTimeout = !!this._findTimeout; |
| 9928 |
if (this._findTimeout) { |
| 9929 |
clearTimeout(this._findTimeout); |
| 9930 |
this._findTimeout = null; |
| 9931 |
} |
| 9932 |
if (!type) { |
| 9933 |
this._findTimeout = setTimeout(() => { |
| 9934 |
this.#nextMatch(); |
| 9935 |
this._findTimeout = null; |
| 9936 |
}, FIND_TIMEOUT); |
| 9937 |
} else if (this._dirtyMatch) { |
| 9938 |
this.#nextMatch(); |
| 9939 |
} else if (type === "again") { |
| 9940 |
this.#nextMatch(); |
| 9941 |
if (findbarClosed && this.#state.highlightAll) { |
| 9942 |
this.#updateAllPages(); |
| 9943 |
} |
| 9944 |
} else if (type === "highlightallchange") { |
| 9945 |
if (pendingTimeout) { |
| 9946 |
this.#nextMatch(); |
| 9947 |
} else { |
| 9948 |
this._highlightMatches = true; |
| 9949 |
} |
| 9950 |
this.#updateAllPages(); |
| 9951 |
} else { |
| 9952 |
this.#nextMatch(); |
| 9953 |
} |
| 9954 |
}); |
| 9955 |
} |
| 9956 |
scrollMatchIntoView({ |
| 9957 |
element = null, |
| 9958 |
selectedLeft = 0, |
| 9959 |
pageIndex = -1, |
| 9960 |
matchIndex = -1 |
| 9961 |
}) { |
| 9962 |
if (!this._scrollMatches || !element) { |
| 9963 |
return; |
| 9964 |
} else if (matchIndex === -1 || matchIndex !== this._selected.matchIdx) { |
| 9965 |
return; |
| 9966 |
} else if (pageIndex === -1 || pageIndex !== this._selected.pageIdx) { |
| 9967 |
return; |
| 9968 |
} |
| 9969 |
this._scrollMatches = false; |
| 9970 |
const spot = { |
| 9971 |
top: MATCH_SCROLL_OFFSET_TOP, |
| 9972 |
left: selectedLeft + MATCH_SCROLL_OFFSET_LEFT |
| 9973 |
}; |
| 9974 |
scrollIntoView(element, spot, true); |
| 9975 |
} |
| 9976 |
#reset() { |
| 9977 |
this._highlightMatches = false; |
| 9978 |
this._scrollMatches = false; |
| 9979 |
this._pdfDocument = null; |
| 9980 |
this._pageMatches = []; |
| 9981 |
this._pageMatchesLength = []; |
| 9982 |
this.#visitedPagesCount = 0; |
| 9983 |
this.#state = null; |
| 9984 |
this._selected = { |
| 9985 |
pageIdx: -1, |
| 9986 |
matchIdx: -1 |
| 9987 |
}; |
| 9988 |
this._offset = { |
| 9989 |
pageIdx: null, |
| 9990 |
matchIdx: null, |
| 9991 |
wrapped: false |
| 9992 |
}; |
| 9993 |
this._extractTextPromises = []; |
| 9994 |
this._pageContents = []; |
| 9995 |
this._pageDiffs = []; |
| 9996 |
this._hasDiacritics = []; |
| 9997 |
this._matchesCountTotal = 0; |
| 9998 |
this._pagesToSearch = null; |
| 9999 |
this._pendingFindMatches = new Set(); |
| 10000 |
this._resumePageIdx = null; |
| 10001 |
this._dirtyMatch = false; |
| 10002 |
clearTimeout(this._findTimeout); |
| 10003 |
this._findTimeout = null; |
| 10004 |
this._firstPageCapability = Promise.withResolvers(); |
| 10005 |
} |
| 10006 |
get #query() { |
| 10007 |
const { |
| 10008 |
query |
| 10009 |
} = this.#state; |
| 10010 |
if (typeof query === "string") { |
| 10011 |
if (query !== this._rawQuery) { |
| 10012 |
this._rawQuery = query; |
| 10013 |
[this._normalizedQuery] = normalize(query); |
| 10014 |
} |
| 10015 |
return this._normalizedQuery; |
| 10016 |
} |
| 10017 |
return (query || []).filter(q => !!q).map(q => normalize(q)[0]); |
| 10018 |
} |
| 10019 |
#shouldDirtyMatch(state) { |
| 10020 |
const newQuery = state.query, |
| 10021 |
prevQuery = this.#state.query; |
| 10022 |
const newType = typeof newQuery, |
| 10023 |
prevType = typeof prevQuery; |
| 10024 |
if (newType !== prevType) { |
| 10025 |
return true; |
| 10026 |
} |
| 10027 |
if (newType === "string") { |
| 10028 |
if (newQuery !== prevQuery) { |
| 10029 |
return true; |
| 10030 |
} |
| 10031 |
} else if (JSON.stringify(newQuery) !== JSON.stringify(prevQuery)) { |
| 10032 |
return true; |
| 10033 |
} |
| 10034 |
switch (state.type) { |
| 10035 |
case "again": |
| 10036 |
const pageNumber = this._selected.pageIdx + 1; |
| 10037 |
const linkService = this._linkService; |
| 10038 |
return pageNumber >= 1 && pageNumber <= linkService.pagesCount && pageNumber !== linkService.page && !(this.onIsPageVisible?.(pageNumber) ?? true); |
| 10039 |
case "highlightallchange": |
| 10040 |
return false; |
| 10041 |
} |
| 10042 |
return true; |
| 10043 |
} |
| 10044 |
#isEntireWord(content, startIdx, length) { |
| 10045 |
let match = content.slice(0, startIdx).match(NOT_DIACRITIC_FROM_END_REG_EXP); |
| 10046 |
if (match) { |
| 10047 |
const first = content.charCodeAt(startIdx); |
| 10048 |
const limit = match[1].charCodeAt(0); |
| 10049 |
if (getCharacterType(first) === getCharacterType(limit)) { |
| 10050 |
return false; |
| 10051 |
} |
| 10052 |
} |
| 10053 |
match = content.slice(startIdx + length).match(NOT_DIACRITIC_FROM_START_REG_EXP); |
| 10054 |
if (match) { |
| 10055 |
const last = content.charCodeAt(startIdx + length - 1); |
| 10056 |
const limit = match[1].charCodeAt(0); |
| 10057 |
if (getCharacterType(last) === getCharacterType(limit)) { |
| 10058 |
return false; |
| 10059 |
} |
| 10060 |
} |
| 10061 |
return true; |
| 10062 |
} |
| 10063 |
#convertToRegExpString(query, hasDiacritics) { |
| 10064 |
const { |
| 10065 |
matchDiacritics |
| 10066 |
} = this.#state; |
| 10067 |
let isUnicode = false; |
| 10068 |
query = query.replaceAll(SPECIAL_CHARS_REG_EXP, (match, p1, p2, p3, p4, p5) => { |
| 10069 |
if (p1) { |
| 10070 |
return `[ ]*\\${p1}[ ]*`; |
| 10071 |
} |
| 10072 |
if (p2) { |
| 10073 |
return `[ ]*${p2}[ ]*`; |
| 10074 |
} |
| 10075 |
if (p3) { |
| 10076 |
return "[ ]+"; |
| 10077 |
} |
| 10078 |
if (matchDiacritics) { |
| 10079 |
return p4 || p5; |
| 10080 |
} |
| 10081 |
if (p4) { |
| 10082 |
return DIACRITICS_EXCEPTION.has(p4.charCodeAt(0)) ? p4 : ""; |
| 10083 |
} |
| 10084 |
if (hasDiacritics) { |
| 10085 |
isUnicode = true; |
| 10086 |
return `${p5}\\p{M}*`; |
| 10087 |
} |
| 10088 |
return p5; |
| 10089 |
}); |
| 10090 |
const trailingSpaces = "[ ]*"; |
| 10091 |
if (query.endsWith(trailingSpaces)) { |
| 10092 |
query = query.slice(0, query.length - trailingSpaces.length); |
| 10093 |
} |
| 10094 |
if (matchDiacritics) { |
| 10095 |
if (hasDiacritics) { |
| 10096 |
DIACRITICS_EXCEPTION_STR ||= String.fromCharCode(...DIACRITICS_EXCEPTION); |
| 10097 |
isUnicode = true; |
| 10098 |
query = `${query}(?=[${DIACRITICS_EXCEPTION_STR}]|[^\\p{M}]|$)`; |
| 10099 |
} |
| 10100 |
} |
| 10101 |
return [isUnicode, query]; |
| 10102 |
} |
| 10103 |
#calculateMatch(pageIndex) { |
| 10104 |
if (!this.#state) { |
| 10105 |
return; |
| 10106 |
} |
| 10107 |
const query = this.#query; |
| 10108 |
if (query.length === 0) { |
| 10109 |
return; |
| 10110 |
} |
| 10111 |
const pageContent = this._pageContents[pageIndex]; |
| 10112 |
const matcherResult = this.match(query, pageContent, pageIndex); |
| 10113 |
const matches = this._pageMatches[pageIndex] = []; |
| 10114 |
const matchesLength = this._pageMatchesLength[pageIndex] = []; |
| 10115 |
const diffs = this._pageDiffs[pageIndex]; |
| 10116 |
matcherResult?.forEach(({ |
| 10117 |
index, |
| 10118 |
length |
| 10119 |
}) => { |
| 10120 |
const [matchPos, matchLen] = getOriginalIndex(diffs, index, length); |
| 10121 |
if (matchLen) { |
| 10122 |
matches.push(matchPos); |
| 10123 |
matchesLength.push(matchLen); |
| 10124 |
} |
| 10125 |
}); |
| 10126 |
if (this.#state.highlightAll) { |
| 10127 |
this.#updatePage(pageIndex); |
| 10128 |
} |
| 10129 |
if (this._resumePageIdx === pageIndex) { |
| 10130 |
this._resumePageIdx = null; |
| 10131 |
this.#nextPageMatch(); |
| 10132 |
} |
| 10133 |
const pageMatchesCount = matches.length; |
| 10134 |
this._matchesCountTotal += pageMatchesCount; |
| 10135 |
if (this.#updateMatchesCountOnProgress) { |
| 10136 |
if (pageMatchesCount > 0) { |
| 10137 |
this.#updateUIResultsCount(); |
| 10138 |
} |
| 10139 |
} else if (++this.#visitedPagesCount === this._linkService.pagesCount) { |
| 10140 |
this.#updateUIResultsCount(); |
| 10141 |
} |
| 10142 |
} |
| 10143 |
match(query, pageContent, pageIndex) { |
| 10144 |
const hasDiacritics = this._hasDiacritics[pageIndex]; |
| 10145 |
let isUnicode = false; |
| 10146 |
if (typeof query === "string") { |
| 10147 |
[isUnicode, query] = this.#convertToRegExpString(query, hasDiacritics); |
| 10148 |
} else { |
| 10149 |
query = query.sort().reverse().map(q => { |
| 10150 |
const [isUnicodePart, queryPart] = this.#convertToRegExpString(q, hasDiacritics); |
| 10151 |
isUnicode ||= isUnicodePart; |
| 10152 |
return `(${queryPart})`; |
| 10153 |
}).join("|"); |
| 10154 |
} |
| 10155 |
if (!query) { |
| 10156 |
return undefined; |
| 10157 |
} |
| 10158 |
const { |
| 10159 |
caseSensitive, |
| 10160 |
entireWord |
| 10161 |
} = this.#state; |
| 10162 |
const flags = `g${isUnicode ? "u" : ""}${caseSensitive ? "" : "i"}`; |
| 10163 |
query = new RegExp(query, flags); |
| 10164 |
const matches = []; |
| 10165 |
let match; |
| 10166 |
while ((match = query.exec(pageContent)) !== null) { |
| 10167 |
if (entireWord && !this.#isEntireWord(pageContent, match.index, match[0].length)) { |
| 10168 |
continue; |
| 10169 |
} |
| 10170 |
matches.push({ |
| 10171 |
index: match.index, |
| 10172 |
length: match[0].length |
| 10173 |
}); |
| 10174 |
} |
| 10175 |
return matches; |
| 10176 |
} |
| 10177 |
#extractText() { |
| 10178 |
if (this._extractTextPromises.length > 0) { |
| 10179 |
return; |
| 10180 |
} |
| 10181 |
let deferred = Promise.resolve(); |
| 10182 |
const textOptions = { |
| 10183 |
disableNormalization: true |
| 10184 |
}; |
| 10185 |
const pdfDoc = this._pdfDocument; |
| 10186 |
for (let i = 0, ii = this._linkService.pagesCount; i < ii; i++) { |
| 10187 |
const { |
| 10188 |
promise, |
| 10189 |
resolve |
| 10190 |
} = Promise.withResolvers(); |
| 10191 |
this._extractTextPromises[i] = promise; |
| 10192 |
deferred = deferred.then(async () => { |
| 10193 |
if (pdfDoc !== this._pdfDocument) { |
| 10194 |
resolve(); |
| 10195 |
return; |
| 10196 |
} |
| 10197 |
await pdfDoc.getPage(i + 1).then(pdfPage => pdfPage.getTextContent(textOptions)).then(textContent => { |
| 10198 |
const strBuf = []; |
| 10199 |
for (const textItem of textContent.items) { |
| 10200 |
strBuf.push(textItem.str); |
| 10201 |
if (textItem.hasEOL) { |
| 10202 |
strBuf.push("\n"); |
| 10203 |
} |
| 10204 |
} |
| 10205 |
[this._pageContents[i], this._pageDiffs[i], this._hasDiacritics[i]] = normalize(strBuf.join("")); |
| 10206 |
resolve(); |
| 10207 |
}, reason => { |
| 10208 |
console.error(`Unable to get text content for page ${i + 1}`, reason); |
| 10209 |
this._pageContents[i] = ""; |
| 10210 |
this._pageDiffs[i] = null; |
| 10211 |
this._hasDiacritics[i] = false; |
| 10212 |
resolve(); |
| 10213 |
}); |
| 10214 |
}); |
| 10215 |
} |
| 10216 |
} |
| 10217 |
#updatePage(index) { |
| 10218 |
if (this._scrollMatches && this._selected.pageIdx === index) { |
| 10219 |
this._linkService.page = index + 1; |
| 10220 |
} |
| 10221 |
this._eventBus.dispatch("updatetextlayermatches", { |
| 10222 |
source: this, |
| 10223 |
pageIndex: index |
| 10224 |
}); |
| 10225 |
} |
| 10226 |
#updateAllPages() { |
| 10227 |
this._eventBus.dispatch("updatetextlayermatches", { |
| 10228 |
source: this, |
| 10229 |
pageIndex: -1 |
| 10230 |
}); |
| 10231 |
} |
| 10232 |
#nextMatch() { |
| 10233 |
const previous = this.#state.findPrevious; |
| 10234 |
const currentPageIndex = this._linkService.page - 1; |
| 10235 |
const numPages = this._linkService.pagesCount; |
| 10236 |
this._highlightMatches = true; |
| 10237 |
if (this._dirtyMatch) { |
| 10238 |
this._dirtyMatch = false; |
| 10239 |
this._selected.pageIdx = this._selected.matchIdx = -1; |
| 10240 |
this._offset.pageIdx = currentPageIndex; |
| 10241 |
this._offset.matchIdx = null; |
| 10242 |
this._offset.wrapped = false; |
| 10243 |
this._resumePageIdx = null; |
| 10244 |
this._pageMatches.length = 0; |
| 10245 |
this._pageMatchesLength.length = 0; |
| 10246 |
this.#visitedPagesCount = 0; |
| 10247 |
this._matchesCountTotal = 0; |
| 10248 |
this.#updateAllPages(); |
| 10249 |
for (let i = 0; i < numPages; i++) { |
| 10250 |
if (this._pendingFindMatches.has(i)) { |
| 10251 |
continue; |
| 10252 |
} |
| 10253 |
this._pendingFindMatches.add(i); |
| 10254 |
this._extractTextPromises[i].then(() => { |
| 10255 |
this._pendingFindMatches.delete(i); |
| 10256 |
this.#calculateMatch(i); |
| 10257 |
}); |
| 10258 |
} |
| 10259 |
} |
| 10260 |
const query = this.#query; |
| 10261 |
if (query.length === 0) { |
| 10262 |
this.#updateUIState(FindState.FOUND); |
| 10263 |
return; |
| 10264 |
} |
| 10265 |
if (this._resumePageIdx) { |
| 10266 |
return; |
| 10267 |
} |
| 10268 |
const offset = this._offset; |
| 10269 |
this._pagesToSearch = numPages; |
| 10270 |
if (offset.matchIdx !== null) { |
| 10271 |
const numPageMatches = this._pageMatches[offset.pageIdx].length; |
| 10272 |
if (!previous && offset.matchIdx + 1 < numPageMatches || previous && offset.matchIdx > 0) { |
| 10273 |
offset.matchIdx = previous ? offset.matchIdx - 1 : offset.matchIdx + 1; |
| 10274 |
this.#updateMatch(true); |
| 10275 |
return; |
| 10276 |
} |
| 10277 |
this.#advanceOffsetPage(previous); |
| 10278 |
} |
| 10279 |
this.#nextPageMatch(); |
| 10280 |
} |
| 10281 |
#matchesReady(matches) { |
| 10282 |
const offset = this._offset; |
| 10283 |
const numMatches = matches.length; |
| 10284 |
const previous = this.#state.findPrevious; |
| 10285 |
if (numMatches) { |
| 10286 |
offset.matchIdx = previous ? numMatches - 1 : 0; |
| 10287 |
this.#updateMatch(true); |
| 10288 |
return true; |
| 10289 |
} |
| 10290 |
this.#advanceOffsetPage(previous); |
| 10291 |
if (offset.wrapped) { |
| 10292 |
offset.matchIdx = null; |
| 10293 |
if (this._pagesToSearch < 0) { |
| 10294 |
this.#updateMatch(false); |
| 10295 |
return true; |
| 10296 |
} |
| 10297 |
} |
| 10298 |
return false; |
| 10299 |
} |
| 10300 |
#nextPageMatch() { |
| 10301 |
if (this._resumePageIdx !== null) { |
| 10302 |
console.error("There can only be one pending page."); |
| 10303 |
} |
| 10304 |
let matches = null; |
| 10305 |
do { |
| 10306 |
const pageIdx = this._offset.pageIdx; |
| 10307 |
matches = this._pageMatches[pageIdx]; |
| 10308 |
if (!matches) { |
| 10309 |
this._resumePageIdx = pageIdx; |
| 10310 |
break; |
| 10311 |
} |
| 10312 |
} while (!this.#matchesReady(matches)); |
| 10313 |
} |
| 10314 |
#advanceOffsetPage(previous) { |
| 10315 |
const offset = this._offset; |
| 10316 |
const numPages = this._linkService.pagesCount; |
| 10317 |
offset.pageIdx = previous ? offset.pageIdx - 1 : offset.pageIdx + 1; |
| 10318 |
offset.matchIdx = null; |
| 10319 |
this._pagesToSearch--; |
| 10320 |
if (offset.pageIdx >= numPages || offset.pageIdx < 0) { |
| 10321 |
offset.pageIdx = previous ? numPages - 1 : 0; |
| 10322 |
offset.wrapped = true; |
| 10323 |
} |
| 10324 |
} |
| 10325 |
#updateMatch(found = false) { |
| 10326 |
let state = FindState.NOT_FOUND; |
| 10327 |
const wrapped = this._offset.wrapped; |
| 10328 |
this._offset.wrapped = false; |
| 10329 |
if (found) { |
| 10330 |
const previousPage = this._selected.pageIdx; |
| 10331 |
this._selected.pageIdx = this._offset.pageIdx; |
| 10332 |
this._selected.matchIdx = this._offset.matchIdx; |
| 10333 |
state = wrapped ? FindState.WRAPPED : FindState.FOUND; |
| 10334 |
if (previousPage !== -1 && previousPage !== this._selected.pageIdx) { |
| 10335 |
this.#updatePage(previousPage); |
| 10336 |
} |
| 10337 |
} |
| 10338 |
this.#updateUIState(state, this.#state.findPrevious); |
| 10339 |
if (this._selected.pageIdx !== -1) { |
| 10340 |
this._scrollMatches = true; |
| 10341 |
this.#updatePage(this._selected.pageIdx); |
| 10342 |
} |
| 10343 |
} |
| 10344 |
#onFindBarClose(evt) { |
| 10345 |
const pdfDocument = this._pdfDocument; |
| 10346 |
this._firstPageCapability.promise.then(() => { |
| 10347 |
if (!this._pdfDocument || pdfDocument && this._pdfDocument !== pdfDocument) { |
| 10348 |
return; |
| 10349 |
} |
| 10350 |
if (this._findTimeout) { |
| 10351 |
clearTimeout(this._findTimeout); |
| 10352 |
this._findTimeout = null; |
| 10353 |
} |
| 10354 |
if (this._resumePageIdx) { |
| 10355 |
this._resumePageIdx = null; |
| 10356 |
this._dirtyMatch = true; |
| 10357 |
} |
| 10358 |
this.#updateUIState(FindState.FOUND); |
| 10359 |
this._highlightMatches = false; |
| 10360 |
this.#updateAllPages(); |
| 10361 |
}); |
| 10362 |
} |
| 10363 |
#requestMatchesCount() { |
| 10364 |
const { |
| 10365 |
pageIdx, |
| 10366 |
matchIdx |
| 10367 |
} = this._selected; |
| 10368 |
let current = 0, |
| 10369 |
total = this._matchesCountTotal; |
| 10370 |
if (matchIdx !== -1) { |
| 10371 |
for (let i = 0; i < pageIdx; i++) { |
| 10372 |
current += this._pageMatches[i]?.length || 0; |
| 10373 |
} |
| 10374 |
current += matchIdx + 1; |
| 10375 |
} |
| 10376 |
if (current < 1 || current > total) { |
| 10377 |
current = total = 0; |
| 10378 |
} |
| 10379 |
return { |
| 10380 |
current, |
| 10381 |
total |
| 10382 |
}; |
| 10383 |
} |
| 10384 |
#updateUIResultsCount() { |
| 10385 |
this._eventBus.dispatch("updatefindmatchescount", { |
| 10386 |
source: this, |
| 10387 |
matchesCount: this.#requestMatchesCount() |
| 10388 |
}); |
| 10389 |
} |
| 10390 |
#updateUIState(state, previous = false) { |
| 10391 |
if (!this.#updateMatchesCountOnProgress && (this.#visitedPagesCount !== this._linkService.pagesCount || state === FindState.PENDING)) { |
| 10392 |
return; |
| 10393 |
} |
| 10394 |
this._eventBus.dispatch("updatefindcontrolstate", { |
| 10395 |
source: this, |
| 10396 |
state, |
| 10397 |
previous, |
| 10398 |
entireWord: this.#state?.entireWord ?? null, |
| 10399 |
matchesCount: this.#requestMatchesCount(), |
| 10400 |
rawQuery: this.#state?.query ?? null |
| 10401 |
}); |
| 10402 |
} |
| 10403 |
} |
| 10404 |
|
| 10405 |
;// ./web/pdf_find_bar.js |
| 10406 |
|
| 10407 |
|
| 10408 |
const MATCHES_COUNT_LIMIT = 1000; |
| 10409 |
class PDFFindBar { |
| 10410 |
#mainContainer; |
| 10411 |
#resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this)); |
| 10412 |
constructor(options, mainContainer, eventBus) { |
| 10413 |
this.opened = false; |
| 10414 |
this.bar = options.bar; |
| 10415 |
this.toggleButton = options.toggleButton; |
| 10416 |
this.findField = options.findField; |
| 10417 |
this.highlightAll = options.highlightAllCheckbox; |
| 10418 |
this.caseSensitive = options.caseSensitiveCheckbox; |
| 10419 |
this.matchDiacritics = options.matchDiacriticsCheckbox; |
| 10420 |
this.entireWord = options.entireWordCheckbox; |
| 10421 |
this.findMsg = options.findMsg; |
| 10422 |
this.findResultsCount = options.findResultsCount; |
| 10423 |
this.findPreviousButton = options.findPreviousButton; |
| 10424 |
this.findNextButton = options.findNextButton; |
| 10425 |
this.eventBus = eventBus; |
| 10426 |
this.#mainContainer = mainContainer; |
| 10427 |
const checkedInputs = new Map([[this.highlightAll, "highlightallchange"], [this.caseSensitive, "casesensitivitychange"], [this.entireWord, "entirewordchange"], [this.matchDiacritics, "diacriticmatchingchange"]]); |
| 10428 |
this.toggleButton.addEventListener("click", () => { |
| 10429 |
this.toggle(); |
| 10430 |
}); |
| 10431 |
this.findField.addEventListener("input", () => { |
| 10432 |
this.dispatchEvent(""); |
| 10433 |
}); |
| 10434 |
this.bar.addEventListener("keydown", ({ |
| 10435 |
keyCode, |
| 10436 |
shiftKey, |
| 10437 |
target |
| 10438 |
}) => { |
| 10439 |
switch (keyCode) { |
| 10440 |
case 13: |
| 10441 |
if (target === this.findField) { |
| 10442 |
this.dispatchEvent("again", shiftKey); |
| 10443 |
} else if (checkedInputs.has(target)) { |
| 10444 |
target.checked = !target.checked; |
| 10445 |
this.dispatchEvent(checkedInputs.get(target)); |
| 10446 |
} |
| 10447 |
break; |
| 10448 |
case 27: |
| 10449 |
this.close(); |
| 10450 |
break; |
| 10451 |
} |
| 10452 |
}); |
| 10453 |
this.findPreviousButton.addEventListener("click", () => { |
| 10454 |
this.dispatchEvent("again", true); |
| 10455 |
}); |
| 10456 |
this.findNextButton.addEventListener("click", () => { |
| 10457 |
this.dispatchEvent("again", false); |
| 10458 |
}); |
| 10459 |
for (const [elem, evtName] of checkedInputs) { |
| 10460 |
elem.addEventListener("click", () => { |
| 10461 |
this.dispatchEvent(evtName); |
| 10462 |
}); |
| 10463 |
} |
| 10464 |
} |
| 10465 |
reset() { |
| 10466 |
this.updateUIState(); |
| 10467 |
} |
| 10468 |
dispatchEvent(type, findPrev = false) { |
| 10469 |
this.eventBus.dispatch("find", { |
| 10470 |
source: this, |
| 10471 |
type, |
| 10472 |
query: this.findField.value, |
| 10473 |
caseSensitive: this.caseSensitive.checked, |
| 10474 |
entireWord: this.entireWord.checked, |
| 10475 |
highlightAll: this.highlightAll.checked, |
| 10476 |
findPrevious: findPrev, |
| 10477 |
matchDiacritics: this.matchDiacritics.checked |
| 10478 |
}); |
| 10479 |
} |
| 10480 |
updateUIState(state, previous, matchesCount) { |
| 10481 |
const { |
| 10482 |
findField, |
| 10483 |
findMsg |
| 10484 |
} = this; |
| 10485 |
let findMsgId = "", |
| 10486 |
status = ""; |
| 10487 |
switch (state) { |
| 10488 |
case FindState.FOUND: |
| 10489 |
break; |
| 10490 |
case FindState.PENDING: |
| 10491 |
status = "pending"; |
| 10492 |
break; |
| 10493 |
case FindState.NOT_FOUND: |
| 10494 |
findMsgId = "pdfjs-find-not-found"; |
| 10495 |
status = "notFound"; |
| 10496 |
break; |
| 10497 |
case FindState.WRAPPED: |
| 10498 |
findMsgId = previous ? "pdfjs-find-reached-top" : "pdfjs-find-reached-bottom"; |
| 10499 |
break; |
| 10500 |
} |
| 10501 |
findField.setAttribute("data-status", status); |
| 10502 |
findField.setAttribute("aria-invalid", state === FindState.NOT_FOUND); |
| 10503 |
findMsg.setAttribute("data-status", status); |
| 10504 |
if (findMsgId) { |
| 10505 |
findMsg.setAttribute("data-l10n-id", findMsgId); |
| 10506 |
} else { |
| 10507 |
findMsg.removeAttribute("data-l10n-id"); |
| 10508 |
findMsg.textContent = ""; |
| 10509 |
} |
| 10510 |
this.updateResultsCount(matchesCount); |
| 10511 |
} |
| 10512 |
updateResultsCount({ |
| 10513 |
current = 0, |
| 10514 |
total = 0 |
| 10515 |
} = {}) { |
| 10516 |
const { |
| 10517 |
findResultsCount |
| 10518 |
} = this; |
| 10519 |
if (total > 0) { |
| 10520 |
const limit = MATCHES_COUNT_LIMIT; |
| 10521 |
findResultsCount.setAttribute("data-l10n-id", total > limit ? "pdfjs-find-match-count-limit" : "pdfjs-find-match-count"); |
| 10522 |
findResultsCount.setAttribute("data-l10n-args", JSON.stringify({ |
| 10523 |
limit, |
| 10524 |
current, |
| 10525 |
total |
| 10526 |
})); |
| 10527 |
} else { |
| 10528 |
findResultsCount.removeAttribute("data-l10n-id"); |
| 10529 |
findResultsCount.textContent = ""; |
| 10530 |
} |
| 10531 |
} |
| 10532 |
open() { |
| 10533 |
if (!this.opened) { |
| 10534 |
this.#resizeObserver.observe(this.#mainContainer); |
| 10535 |
this.#resizeObserver.observe(this.bar); |
| 10536 |
this.opened = true; |
| 10537 |
toggleExpandedBtn(this.toggleButton, true, this.bar); |
| 10538 |
} |
| 10539 |
this.findField.select(); |
| 10540 |
this.findField.focus(); |
| 10541 |
} |
| 10542 |
close() { |
| 10543 |
if (!this.opened) { |
| 10544 |
return; |
| 10545 |
} |
| 10546 |
this.#resizeObserver.disconnect(); |
| 10547 |
this.opened = false; |
| 10548 |
toggleExpandedBtn(this.toggleButton, false, this.bar); |
| 10549 |
this.eventBus.dispatch("findbarclose", { |
| 10550 |
source: this |
| 10551 |
}); |
| 10552 |
} |
| 10553 |
toggle() { |
| 10554 |
if (this.opened) { |
| 10555 |
this.close(); |
| 10556 |
} else { |
| 10557 |
this.open(); |
| 10558 |
} |
| 10559 |
} |
| 10560 |
#resizeObserverCallback() { |
| 10561 |
const { |
| 10562 |
bar |
| 10563 |
} = this; |
| 10564 |
bar.classList.remove("wrapContainers"); |
| 10565 |
const findbarHeight = bar.clientHeight; |
| 10566 |
const inputContainerHeight = bar.firstElementChild.clientHeight; |
| 10567 |
if (findbarHeight > inputContainerHeight) { |
| 10568 |
bar.classList.add("wrapContainers"); |
| 10569 |
} |
| 10570 |
} |
| 10571 |
} |
| 10572 |
|
| 10573 |
;// ./web/pdf_history.js |
| 10574 |
|
| 10575 |
|
| 10576 |
|
| 10577 |
const HASH_CHANGE_TIMEOUT = 1000; |
| 10578 |
const POSITION_UPDATED_THRESHOLD = 50; |
| 10579 |
const UPDATE_VIEWAREA_TIMEOUT = 1000; |
| 10580 |
function getCurrentHash() { |
| 10581 |
return document.location.hash; |
| 10582 |
} |
| 10583 |
class PDFHistory { |
| 10584 |
#eventAbortController = null; |
| 10585 |
constructor({ |
| 10586 |
linkService, |
| 10587 |
eventBus |
| 10588 |
}) { |
| 10589 |
this.linkService = linkService; |
| 10590 |
this.eventBus = eventBus; |
| 10591 |
this._initialized = false; |
| 10592 |
this._fingerprint = ""; |
| 10593 |
this.reset(); |
| 10594 |
this.eventBus._on("pagesinit", () => { |
| 10595 |
this._isPagesLoaded = false; |
| 10596 |
this.eventBus._on("pagesloaded", evt => { |
| 10597 |
this._isPagesLoaded = !!evt.pagesCount; |
| 10598 |
}, { |
| 10599 |
once: true |
| 10600 |
}); |
| 10601 |
}); |
| 10602 |
} |
| 10603 |
initialize({ |
| 10604 |
fingerprint, |
| 10605 |
resetHistory = false, |
| 10606 |
updateUrl = false |
| 10607 |
}) { |
| 10608 |
if (!fingerprint || typeof fingerprint !== "string") { |
| 10609 |
console.error('PDFHistory.initialize: The "fingerprint" must be a non-empty string.'); |
| 10610 |
return; |
| 10611 |
} |
| 10612 |
if (this._initialized) { |
| 10613 |
this.reset(); |
| 10614 |
} |
| 10615 |
const reInitialized = this._fingerprint !== "" && this._fingerprint !== fingerprint; |
| 10616 |
this._fingerprint = fingerprint; |
| 10617 |
this._updateUrl = updateUrl === true; |
| 10618 |
this._initialized = true; |
| 10619 |
this.#bindEvents(); |
| 10620 |
const state = window.history.state; |
| 10621 |
this._popStateInProgress = false; |
| 10622 |
this._blockHashChange = 0; |
| 10623 |
this._currentHash = getCurrentHash(); |
| 10624 |
this._numPositionUpdates = 0; |
| 10625 |
this._uid = this._maxUid = 0; |
| 10626 |
this._destination = null; |
| 10627 |
this._position = null; |
| 10628 |
if (!this.#isValidState(state, true) || resetHistory) { |
| 10629 |
const { |
| 10630 |
hash, |
| 10631 |
page, |
| 10632 |
rotation |
| 10633 |
} = this.#parseCurrentHash(true); |
| 10634 |
if (!hash || reInitialized || resetHistory) { |
| 10635 |
this.#pushOrReplaceState(null, true); |
| 10636 |
return; |
| 10637 |
} |
| 10638 |
this.#pushOrReplaceState({ |
| 10639 |
hash, |
| 10640 |
page, |
| 10641 |
rotation |
| 10642 |
}, true); |
| 10643 |
return; |
| 10644 |
} |
| 10645 |
const destination = state.destination; |
| 10646 |
this.#updateInternalState(destination, state.uid, true); |
| 10647 |
if (destination.rotation !== undefined) { |
| 10648 |
this._initialRotation = destination.rotation; |
| 10649 |
} |
| 10650 |
if (destination.dest) { |
| 10651 |
this._initialBookmark = JSON.stringify(destination.dest); |
| 10652 |
this._destination.page = null; |
| 10653 |
} else if (destination.hash) { |
| 10654 |
this._initialBookmark = destination.hash; |
| 10655 |
} else if (destination.page) { |
| 10656 |
this._initialBookmark = `page=${destination.page}`; |
| 10657 |
} |
| 10658 |
} |
| 10659 |
reset() { |
| 10660 |
if (this._initialized) { |
| 10661 |
this.#pageHide(); |
| 10662 |
this._initialized = false; |
| 10663 |
this.#unbindEvents(); |
| 10664 |
} |
| 10665 |
if (this._updateViewareaTimeout) { |
| 10666 |
clearTimeout(this._updateViewareaTimeout); |
| 10667 |
this._updateViewareaTimeout = null; |
| 10668 |
} |
| 10669 |
this._initialBookmark = null; |
| 10670 |
this._initialRotation = null; |
| 10671 |
} |
| 10672 |
push({ |
| 10673 |
namedDest = null, |
| 10674 |
explicitDest, |
| 10675 |
pageNumber |
| 10676 |
}) { |
| 10677 |
if (!this._initialized) { |
| 10678 |
return; |
| 10679 |
} |
| 10680 |
if (namedDest && typeof namedDest !== "string") { |
| 10681 |
console.error("PDFHistory.push: " + `"${namedDest}" is not a valid namedDest parameter.`); |
| 10682 |
return; |
| 10683 |
} else if (!Array.isArray(explicitDest)) { |
| 10684 |
console.error("PDFHistory.push: " + `"${explicitDest}" is not a valid explicitDest parameter.`); |
| 10685 |
return; |
| 10686 |
} else if (!this.#isValidPage(pageNumber)) { |
| 10687 |
if (pageNumber !== null || this._destination) { |
| 10688 |
console.error("PDFHistory.push: " + `"${pageNumber}" is not a valid pageNumber parameter.`); |
| 10689 |
return; |
| 10690 |
} |
| 10691 |
} |
| 10692 |
const hash = namedDest || JSON.stringify(explicitDest); |
| 10693 |
if (!hash) { |
| 10694 |
return; |
| 10695 |
} |
| 10696 |
let forceReplace = false; |
| 10697 |
if (this._destination && (isDestHashesEqual(this._destination.hash, hash) || isDestArraysEqual(this._destination.dest, explicitDest))) { |
| 10698 |
if (this._destination.page) { |
| 10699 |
return; |
| 10700 |
} |
| 10701 |
forceReplace = true; |
| 10702 |
} |
| 10703 |
if (this._popStateInProgress && !forceReplace) { |
| 10704 |
return; |
| 10705 |
} |
| 10706 |
this.#pushOrReplaceState({ |
| 10707 |
dest: explicitDest, |
| 10708 |
hash, |
| 10709 |
page: pageNumber, |
| 10710 |
rotation: this.linkService.rotation |
| 10711 |
}, forceReplace); |
| 10712 |
if (!this._popStateInProgress) { |
| 10713 |
this._popStateInProgress = true; |
| 10714 |
Promise.resolve().then(() => { |
| 10715 |
this._popStateInProgress = false; |
| 10716 |
}); |
| 10717 |
} |
| 10718 |
} |
| 10719 |
pushPage(pageNumber) { |
| 10720 |
if (!this._initialized) { |
| 10721 |
return; |
| 10722 |
} |
| 10723 |
if (!this.#isValidPage(pageNumber)) { |
| 10724 |
console.error(`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`); |
| 10725 |
return; |
| 10726 |
} |
| 10727 |
if (this._destination?.page === pageNumber) { |
| 10728 |
return; |
| 10729 |
} |
| 10730 |
if (this._popStateInProgress) { |
| 10731 |
return; |
| 10732 |
} |
| 10733 |
this.#pushOrReplaceState({ |
| 10734 |
dest: null, |
| 10735 |
hash: `page=${pageNumber}`, |
| 10736 |
page: pageNumber, |
| 10737 |
rotation: this.linkService.rotation |
| 10738 |
}); |
| 10739 |
if (!this._popStateInProgress) { |
| 10740 |
this._popStateInProgress = true; |
| 10741 |
Promise.resolve().then(() => { |
| 10742 |
this._popStateInProgress = false; |
| 10743 |
}); |
| 10744 |
} |
| 10745 |
} |
| 10746 |
pushCurrentPosition() { |
| 10747 |
if (!this._initialized || this._popStateInProgress) { |
| 10748 |
return; |
| 10749 |
} |
| 10750 |
this.#tryPushCurrentPosition(); |
| 10751 |
} |
| 10752 |
back() { |
| 10753 |
if (!this._initialized || this._popStateInProgress) { |
| 10754 |
return; |
| 10755 |
} |
| 10756 |
const state = window.history.state; |
| 10757 |
if (this.#isValidState(state) && state.uid > 0) { |
| 10758 |
window.history.back(); |
| 10759 |
} |
| 10760 |
} |
| 10761 |
forward() { |
| 10762 |
if (!this._initialized || this._popStateInProgress) { |
| 10763 |
return; |
| 10764 |
} |
| 10765 |
const state = window.history.state; |
| 10766 |
if (this.#isValidState(state) && state.uid < this._maxUid) { |
| 10767 |
window.history.forward(); |
| 10768 |
} |
| 10769 |
} |
| 10770 |
get popStateInProgress() { |
| 10771 |
return this._initialized && (this._popStateInProgress || this._blockHashChange > 0); |
| 10772 |
} |
| 10773 |
get initialBookmark() { |
| 10774 |
return this._initialized ? this._initialBookmark : null; |
| 10775 |
} |
| 10776 |
get initialRotation() { |
| 10777 |
return this._initialized ? this._initialRotation : null; |
| 10778 |
} |
| 10779 |
#pushOrReplaceState(destination, forceReplace = false) { |
| 10780 |
const shouldReplace = forceReplace || !this._destination; |
| 10781 |
const newState = { |
| 10782 |
fingerprint: this._fingerprint, |
| 10783 |
uid: shouldReplace ? this._uid : this._uid + 1, |
| 10784 |
destination |
| 10785 |
}; |
| 10786 |
this.#updateInternalState(destination, newState.uid); |
| 10787 |
let newUrl; |
| 10788 |
if (this._updateUrl && destination?.hash) { |
| 10789 |
const { |
| 10790 |
href, |
| 10791 |
protocol |
| 10792 |
} = document.location; |
| 10793 |
if (protocol !== "file:") { |
| 10794 |
newUrl = updateUrlHash(href, destination.hash); |
| 10795 |
} |
| 10796 |
} |
| 10797 |
if (shouldReplace) { |
| 10798 |
window.history.replaceState(newState, "", newUrl); |
| 10799 |
} else { |
| 10800 |
window.history.pushState(newState, "", newUrl); |
| 10801 |
} |
| 10802 |
} |
| 10803 |
#tryPushCurrentPosition(temporary = false) { |
| 10804 |
if (!this._position) { |
| 10805 |
return; |
| 10806 |
} |
| 10807 |
let position = this._position; |
| 10808 |
if (temporary) { |
| 10809 |
position = Object.assign(Object.create(null), this._position); |
| 10810 |
position.temporary = true; |
| 10811 |
} |
| 10812 |
if (!this._destination) { |
| 10813 |
this.#pushOrReplaceState(position); |
| 10814 |
return; |
| 10815 |
} |
| 10816 |
if (this._destination.temporary) { |
| 10817 |
this.#pushOrReplaceState(position, true); |
| 10818 |
return; |
| 10819 |
} |
| 10820 |
if (this._destination.hash === position.hash) { |
| 10821 |
return; |
| 10822 |
} |
| 10823 |
if (!this._destination.page && (POSITION_UPDATED_THRESHOLD <= 0 || this._numPositionUpdates <= POSITION_UPDATED_THRESHOLD)) { |
| 10824 |
return; |
| 10825 |
} |
| 10826 |
let forceReplace = false; |
| 10827 |
if (this._destination.page >= position.first && this._destination.page <= position.page) { |
| 10828 |
if (this._destination.dest !== undefined || !this._destination.first) { |
| 10829 |
return; |
| 10830 |
} |
| 10831 |
forceReplace = true; |
| 10832 |
} |
| 10833 |
this.#pushOrReplaceState(position, forceReplace); |
| 10834 |
} |
| 10835 |
#isValidPage(val) { |
| 10836 |
return Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount; |
| 10837 |
} |
| 10838 |
#isValidState(state, checkReload = false) { |
| 10839 |
if (!state) { |
| 10840 |
return false; |
| 10841 |
} |
| 10842 |
if (state.fingerprint !== this._fingerprint) { |
| 10843 |
if (checkReload) { |
| 10844 |
if (typeof state.fingerprint !== "string" || state.fingerprint.length !== this._fingerprint.length) { |
| 10845 |
return false; |
| 10846 |
} |
| 10847 |
const [perfEntry] = performance.getEntriesByType("navigation"); |
| 10848 |
if (perfEntry?.type !== "reload") { |
| 10849 |
return false; |
| 10850 |
} |
| 10851 |
} else { |
| 10852 |
return false; |
| 10853 |
} |
| 10854 |
} |
| 10855 |
if (!Number.isInteger(state.uid) || state.uid < 0) { |
| 10856 |
return false; |
| 10857 |
} |
| 10858 |
if (state.destination === null || typeof state.destination !== "object") { |
| 10859 |
return false; |
| 10860 |
} |
| 10861 |
return true; |
| 10862 |
} |
| 10863 |
#updateInternalState(destination, uid, removeTemporary = false) { |
| 10864 |
if (this._updateViewareaTimeout) { |
| 10865 |
clearTimeout(this._updateViewareaTimeout); |
| 10866 |
this._updateViewareaTimeout = null; |
| 10867 |
} |
| 10868 |
if (removeTemporary && destination?.temporary) { |
| 10869 |
delete destination.temporary; |
| 10870 |
} |
| 10871 |
this._destination = destination; |
| 10872 |
this._uid = uid; |
| 10873 |
this._maxUid = Math.max(this._maxUid, uid); |
| 10874 |
this._numPositionUpdates = 0; |
| 10875 |
} |
| 10876 |
#parseCurrentHash(checkNameddest = false) { |
| 10877 |
const hash = unescape(getCurrentHash()).substring(1); |
| 10878 |
const params = parseQueryString(hash); |
| 10879 |
const nameddest = params.get("nameddest") || ""; |
| 10880 |
let page = params.get("page") | 0; |
| 10881 |
if (!this.#isValidPage(page) || checkNameddest && nameddest.length > 0) { |
| 10882 |
page = null; |
| 10883 |
} |
| 10884 |
return { |
| 10885 |
hash, |
| 10886 |
page, |
| 10887 |
rotation: this.linkService.rotation |
| 10888 |
}; |
| 10889 |
} |
| 10890 |
#updateViewarea({ |
| 10891 |
location |
| 10892 |
}) { |
| 10893 |
if (this._updateViewareaTimeout) { |
| 10894 |
clearTimeout(this._updateViewareaTimeout); |
| 10895 |
this._updateViewareaTimeout = null; |
| 10896 |
} |
| 10897 |
this._position = { |
| 10898 |
hash: location.pdfOpenParams.substring(1), |
| 10899 |
page: this.linkService.page, |
| 10900 |
first: location.pageNumber, |
| 10901 |
rotation: location.rotation |
| 10902 |
}; |
| 10903 |
if (this._popStateInProgress) { |
| 10904 |
return; |
| 10905 |
} |
| 10906 |
if (POSITION_UPDATED_THRESHOLD > 0 && this._isPagesLoaded && this._destination && !this._destination.page) { |
| 10907 |
this._numPositionUpdates++; |
| 10908 |
} |
| 10909 |
if (UPDATE_VIEWAREA_TIMEOUT > 0) { |
| 10910 |
this._updateViewareaTimeout = setTimeout(() => { |
| 10911 |
if (!this._popStateInProgress) { |
| 10912 |
this.#tryPushCurrentPosition(true); |
| 10913 |
} |
| 10914 |
this._updateViewareaTimeout = null; |
| 10915 |
}, UPDATE_VIEWAREA_TIMEOUT); |
| 10916 |
} |
| 10917 |
} |
| 10918 |
#popState({ |
| 10919 |
state |
| 10920 |
}) { |
| 10921 |
const newHash = getCurrentHash(), |
| 10922 |
hashChanged = this._currentHash !== newHash; |
| 10923 |
this._currentHash = newHash; |
| 10924 |
if (!state) { |
| 10925 |
this._uid++; |
| 10926 |
const { |
| 10927 |
hash, |
| 10928 |
page, |
| 10929 |
rotation |
| 10930 |
} = this.#parseCurrentHash(); |
| 10931 |
this.#pushOrReplaceState({ |
| 10932 |
hash, |
| 10933 |
page, |
| 10934 |
rotation |
| 10935 |
}, true); |
| 10936 |
return; |
| 10937 |
} |
| 10938 |
if (!this.#isValidState(state)) { |
| 10939 |
return; |
| 10940 |
} |
| 10941 |
this._popStateInProgress = true; |
| 10942 |
if (hashChanged) { |
| 10943 |
this._blockHashChange++; |
| 10944 |
waitOnEventOrTimeout({ |
| 10945 |
target: window, |
| 10946 |
name: "hashchange", |
| 10947 |
delay: HASH_CHANGE_TIMEOUT |
| 10948 |
}).then(() => { |
| 10949 |
this._blockHashChange--; |
| 10950 |
}); |
| 10951 |
} |
| 10952 |
const destination = state.destination; |
| 10953 |
this.#updateInternalState(destination, state.uid, true); |
| 10954 |
if (isValidRotation(destination.rotation)) { |
| 10955 |
this.linkService.rotation = destination.rotation; |
| 10956 |
} |
| 10957 |
if (destination.dest) { |
| 10958 |
this.linkService.goToDestination(destination.dest); |
| 10959 |
} else if (destination.hash) { |
| 10960 |
this.linkService.setHash(destination.hash); |
| 10961 |
} else if (destination.page) { |
| 10962 |
this.linkService.page = destination.page; |
| 10963 |
} |
| 10964 |
Promise.resolve().then(() => { |
| 10965 |
this._popStateInProgress = false; |
| 10966 |
}); |
| 10967 |
} |
| 10968 |
#pageHide() { |
| 10969 |
if (!this._destination || this._destination.temporary) { |
| 10970 |
this.#tryPushCurrentPosition(); |
| 10971 |
} |
| 10972 |
} |
| 10973 |
#bindEvents() { |
| 10974 |
if (this.#eventAbortController) { |
| 10975 |
return; |
| 10976 |
} |
| 10977 |
this.#eventAbortController = new AbortController(); |
| 10978 |
const { |
| 10979 |
signal |
| 10980 |
} = this.#eventAbortController; |
| 10981 |
this.eventBus._on("updateviewarea", this.#updateViewarea.bind(this), { |
| 10982 |
signal |
| 10983 |
}); |
| 10984 |
window.addEventListener("popstate", this.#popState.bind(this), { |
| 10985 |
signal |
| 10986 |
}); |
| 10987 |
window.addEventListener("pagehide", this.#pageHide.bind(this), { |
| 10988 |
signal |
| 10989 |
}); |
| 10990 |
} |
| 10991 |
#unbindEvents() { |
| 10992 |
this.#eventAbortController?.abort(); |
| 10993 |
this.#eventAbortController = null; |
| 10994 |
} |
| 10995 |
} |
| 10996 |
function isDestHashesEqual(destHash, pushHash) { |
| 10997 |
if (typeof destHash !== "string" || typeof pushHash !== "string") { |
| 10998 |
return false; |
| 10999 |
} |
| 11000 |
if (destHash === pushHash) { |
| 11001 |
return true; |
| 11002 |
} |
| 11003 |
const nameddest = parseQueryString(destHash).get("nameddest"); |
| 11004 |
if (nameddest === pushHash) { |
| 11005 |
return true; |
| 11006 |
} |
| 11007 |
return false; |
| 11008 |
} |
| 11009 |
function isDestArraysEqual(firstDest, secondDest) { |
| 11010 |
function isEntryEqual(first, second) { |
| 11011 |
if (typeof first !== typeof second) { |
| 11012 |
return false; |
| 11013 |
} |
| 11014 |
if (Array.isArray(first) || Array.isArray(second)) { |
| 11015 |
return false; |
| 11016 |
} |
| 11017 |
if (first !== null && typeof first === "object" && second !== null) { |
| 11018 |
if (Object.keys(first).length !== Object.keys(second).length) { |
| 11019 |
return false; |
| 11020 |
} |
| 11021 |
for (const key in first) { |
| 11022 |
if (!isEntryEqual(first[key], second[key])) { |
| 11023 |
return false; |
| 11024 |
} |
| 11025 |
} |
| 11026 |
return true; |
| 11027 |
} |
| 11028 |
return first === second || Number.isNaN(first) && Number.isNaN(second); |
| 11029 |
} |
| 11030 |
if (!(Array.isArray(firstDest) && Array.isArray(secondDest))) { |
| 11031 |
return false; |
| 11032 |
} |
| 11033 |
if (firstDest.length !== secondDest.length) { |
| 11034 |
return false; |
| 11035 |
} |
| 11036 |
for (let i = 0, ii = firstDest.length; i < ii; i++) { |
| 11037 |
if (!isEntryEqual(firstDest[i], secondDest[i])) { |
| 11038 |
return false; |
| 11039 |
} |
| 11040 |
} |
| 11041 |
return true; |
| 11042 |
} |
| 11043 |
|
| 11044 |
;// ./web/pdf_layer_viewer.js |
| 11045 |
|
| 11046 |
|
| 11047 |
class PDFLayerViewer extends BaseTreeViewer { |
| 11048 |
constructor(options) { |
| 11049 |
super(options); |
| 11050 |
this.eventBus._on("optionalcontentconfigchanged", evt => { |
| 11051 |
this.#updateLayers(evt.promise); |
| 11052 |
}); |
| 11053 |
this.eventBus._on("resetlayers", () => { |
| 11054 |
this.#updateLayers(); |
| 11055 |
}); |
| 11056 |
this.eventBus._on("togglelayerstree", this._toggleAllTreeItems.bind(this)); |
| 11057 |
} |
| 11058 |
reset() { |
| 11059 |
super.reset(); |
| 11060 |
this._optionalContentConfig = null; |
| 11061 |
this._optionalContentVisibility?.clear(); |
| 11062 |
this._optionalContentVisibility = null; |
| 11063 |
} |
| 11064 |
_dispatchEvent(layersCount) { |
| 11065 |
this.eventBus.dispatch("layersloaded", { |
| 11066 |
source: this, |
| 11067 |
layersCount |
| 11068 |
}); |
| 11069 |
} |
| 11070 |
_bindLink(element, { |
| 11071 |
groupId, |
| 11072 |
input |
| 11073 |
}) { |
| 11074 |
const setVisibility = () => { |
| 11075 |
const visible = input.checked; |
| 11076 |
this._optionalContentConfig.setVisibility(groupId, visible); |
| 11077 |
const cached = this._optionalContentVisibility.get(groupId); |
| 11078 |
if (cached) { |
| 11079 |
cached.visible = visible; |
| 11080 |
} |
| 11081 |
this.eventBus.dispatch("optionalcontentconfig", { |
| 11082 |
source: this, |
| 11083 |
promise: Promise.resolve(this._optionalContentConfig) |
| 11084 |
}); |
| 11085 |
}; |
| 11086 |
element.onclick = evt => { |
| 11087 |
if (evt.target === input) { |
| 11088 |
setVisibility(); |
| 11089 |
return true; |
| 11090 |
} else if (evt.target !== element) { |
| 11091 |
return true; |
| 11092 |
} |
| 11093 |
input.checked = !input.checked; |
| 11094 |
setVisibility(); |
| 11095 |
return false; |
| 11096 |
}; |
| 11097 |
} |
| 11098 |
_setNestedName(element, { |
| 11099 |
name = null |
| 11100 |
}) { |
| 11101 |
if (typeof name === "string") { |
| 11102 |
element.textContent = this._normalizeTextContent(name); |
| 11103 |
return; |
| 11104 |
} |
| 11105 |
element.setAttribute("data-l10n-id", "pdfjs-additional-layers"); |
| 11106 |
element.style.fontStyle = "italic"; |
| 11107 |
this._l10n.translateOnce(element); |
| 11108 |
} |
| 11109 |
_addToggleButton(div, { |
| 11110 |
name = null |
| 11111 |
}) { |
| 11112 |
super._addToggleButton(div, name === null); |
| 11113 |
} |
| 11114 |
_toggleAllTreeItems() { |
| 11115 |
if (!this._optionalContentConfig) { |
| 11116 |
return; |
| 11117 |
} |
| 11118 |
super._toggleAllTreeItems(); |
| 11119 |
} |
| 11120 |
render({ |
| 11121 |
optionalContentConfig, |
| 11122 |
pdfDocument |
| 11123 |
}) { |
| 11124 |
if (this._optionalContentConfig) { |
| 11125 |
this.reset(); |
| 11126 |
} |
| 11127 |
this._optionalContentConfig = optionalContentConfig || null; |
| 11128 |
this._pdfDocument = pdfDocument || null; |
| 11129 |
const groups = optionalContentConfig?.getOrder(); |
| 11130 |
if (!groups) { |
| 11131 |
this._dispatchEvent(0); |
| 11132 |
return; |
| 11133 |
} |
| 11134 |
this._optionalContentVisibility = new Map(); |
| 11135 |
const fragment = document.createDocumentFragment(), |
| 11136 |
queue = [{ |
| 11137 |
parent: fragment, |
| 11138 |
groups |
| 11139 |
}]; |
| 11140 |
let layersCount = 0, |
| 11141 |
hasAnyNesting = false; |
| 11142 |
while (queue.length > 0) { |
| 11143 |
const levelData = queue.shift(); |
| 11144 |
for (const groupId of levelData.groups) { |
| 11145 |
const div = document.createElement("div"); |
| 11146 |
div.className = "treeItem"; |
| 11147 |
const element = document.createElement("a"); |
| 11148 |
div.append(element); |
| 11149 |
if (typeof groupId === "object") { |
| 11150 |
hasAnyNesting = true; |
| 11151 |
this._addToggleButton(div, groupId); |
| 11152 |
this._setNestedName(element, groupId); |
| 11153 |
const itemsDiv = document.createElement("div"); |
| 11154 |
itemsDiv.className = "treeItems"; |
| 11155 |
div.append(itemsDiv); |
| 11156 |
queue.push({ |
| 11157 |
parent: itemsDiv, |
| 11158 |
groups: groupId.order |
| 11159 |
}); |
| 11160 |
} else { |
| 11161 |
const group = optionalContentConfig.getGroup(groupId); |
| 11162 |
const input = document.createElement("input"); |
| 11163 |
this._bindLink(element, { |
| 11164 |
groupId, |
| 11165 |
input |
| 11166 |
}); |
| 11167 |
input.type = "checkbox"; |
| 11168 |
input.checked = group.visible; |
| 11169 |
this._optionalContentVisibility.set(groupId, { |
| 11170 |
input, |
| 11171 |
visible: input.checked |
| 11172 |
}); |
| 11173 |
const label = document.createElement("label"); |
| 11174 |
label.textContent = this._normalizeTextContent(group.name); |
| 11175 |
label.append(input); |
| 11176 |
element.append(label); |
| 11177 |
layersCount++; |
| 11178 |
} |
| 11179 |
levelData.parent.append(div); |
| 11180 |
} |
| 11181 |
} |
| 11182 |
this._finishRendering(fragment, layersCount, hasAnyNesting); |
| 11183 |
} |
| 11184 |
async #updateLayers(promise = null) { |
| 11185 |
if (!this._optionalContentConfig) { |
| 11186 |
return; |
| 11187 |
} |
| 11188 |
const pdfDocument = this._pdfDocument; |
| 11189 |
const optionalContentConfig = await (promise || pdfDocument.getOptionalContentConfig({ |
| 11190 |
intent: "display" |
| 11191 |
})); |
| 11192 |
if (pdfDocument !== this._pdfDocument) { |
| 11193 |
return; |
| 11194 |
} |
| 11195 |
if (promise) { |
| 11196 |
for (const [groupId, cached] of this._optionalContentVisibility) { |
| 11197 |
const group = optionalContentConfig.getGroup(groupId); |
| 11198 |
if (group && cached.visible !== group.visible) { |
| 11199 |
cached.input.checked = cached.visible = !cached.visible; |
| 11200 |
} |
| 11201 |
} |
| 11202 |
return; |
| 11203 |
} |
| 11204 |
this.eventBus.dispatch("optionalcontentconfig", { |
| 11205 |
source: this, |
| 11206 |
promise: Promise.resolve(optionalContentConfig) |
| 11207 |
}); |
| 11208 |
this.render({ |
| 11209 |
optionalContentConfig, |
| 11210 |
pdfDocument: this._pdfDocument |
| 11211 |
}); |
| 11212 |
} |
| 11213 |
} |
| 11214 |
|
| 11215 |
;// ./web/pdf_outline_viewer.js |
| 11216 |
|
| 11217 |
|
| 11218 |
|
| 11219 |
|
| 11220 |
class PDFOutlineViewer extends BaseTreeViewer { |
| 11221 |
constructor(options) { |
| 11222 |
super(options); |
| 11223 |
this.linkService = options.linkService; |
| 11224 |
this.downloadManager = options.downloadManager; |
| 11225 |
this.eventBus._on("toggleoutlinetree", this._toggleAllTreeItems.bind(this)); |
| 11226 |
this.eventBus._on("currentoutlineitem", this._currentOutlineItem.bind(this)); |
| 11227 |
this.eventBus._on("pagechanging", evt => { |
| 11228 |
this._currentPageNumber = evt.pageNumber; |
| 11229 |
}); |
| 11230 |
this.eventBus._on("pagesloaded", evt => { |
| 11231 |
this._isPagesLoaded = !!evt.pagesCount; |
| 11232 |
this._currentOutlineItemCapability?.resolve(this._isPagesLoaded); |
| 11233 |
}); |
| 11234 |
this.eventBus._on("sidebarviewchanged", evt => { |
| 11235 |
this._sidebarView = evt.view; |
| 11236 |
}); |
| 11237 |
} |
| 11238 |
reset() { |
| 11239 |
super.reset(); |
| 11240 |
this._outline = null; |
| 11241 |
this._pageNumberToDestHashCapability = null; |
| 11242 |
this._currentPageNumber = 1; |
| 11243 |
this._isPagesLoaded = null; |
| 11244 |
this._currentOutlineItemCapability?.resolve(false); |
| 11245 |
this._currentOutlineItemCapability = null; |
| 11246 |
} |
| 11247 |
_dispatchEvent(outlineCount) { |
| 11248 |
this._currentOutlineItemCapability = Promise.withResolvers(); |
| 11249 |
if (outlineCount === 0 || this._pdfDocument?.loadingParams.disableAutoFetch) { |
| 11250 |
this._currentOutlineItemCapability.resolve(false); |
| 11251 |
} else if (this._isPagesLoaded !== null) { |
| 11252 |
this._currentOutlineItemCapability.resolve(this._isPagesLoaded); |
| 11253 |
} |
| 11254 |
this.eventBus.dispatch("outlineloaded", { |
| 11255 |
source: this, |
| 11256 |
outlineCount, |
| 11257 |
currentOutlineItemPromise: this._currentOutlineItemCapability.promise |
| 11258 |
}); |
| 11259 |
} |
| 11260 |
_bindLink(element, { |
| 11261 |
url, |
| 11262 |
newWindow, |
| 11263 |
action, |
| 11264 |
attachment, |
| 11265 |
dest, |
| 11266 |
setOCGState |
| 11267 |
}) { |
| 11268 |
const { |
| 11269 |
linkService |
| 11270 |
} = this; |
| 11271 |
if (url) { |
| 11272 |
linkService.addLinkAttributes(element, url, newWindow); |
| 11273 |
return; |
| 11274 |
} |
| 11275 |
if (action) { |
| 11276 |
element.href = linkService.getAnchorUrl(""); |
| 11277 |
element.onclick = () => { |
| 11278 |
linkService.executeNamedAction(action); |
| 11279 |
return false; |
| 11280 |
}; |
| 11281 |
return; |
| 11282 |
} |
| 11283 |
if (attachment) { |
| 11284 |
element.href = linkService.getAnchorUrl(""); |
| 11285 |
element.onclick = () => { |
| 11286 |
this.downloadManager.openOrDownloadData(attachment.content, attachment.filename); |
| 11287 |
return false; |
| 11288 |
}; |
| 11289 |
return; |
| 11290 |
} |
| 11291 |
if (setOCGState) { |
| 11292 |
element.href = linkService.getAnchorUrl(""); |
| 11293 |
element.onclick = () => { |
| 11294 |
linkService.executeSetOCGState(setOCGState); |
| 11295 |
return false; |
| 11296 |
}; |
| 11297 |
return; |
| 11298 |
} |
| 11299 |
element.href = linkService.getDestinationHash(dest); |
| 11300 |
element.onclick = evt => { |
| 11301 |
this._updateCurrentTreeItem(evt.target.parentNode); |
| 11302 |
if (dest) { |
| 11303 |
linkService.goToDestination(dest); |
| 11304 |
} |
| 11305 |
return false; |
| 11306 |
}; |
| 11307 |
} |
| 11308 |
_setStyles(element, { |
| 11309 |
bold, |
| 11310 |
italic |
| 11311 |
}) { |
| 11312 |
if (bold) { |
| 11313 |
element.style.fontWeight = "bold"; |
| 11314 |
} |
| 11315 |
if (italic) { |
| 11316 |
element.style.fontStyle = "italic"; |
| 11317 |
} |
| 11318 |
} |
| 11319 |
_addToggleButton(div, { |
| 11320 |
count, |
| 11321 |
items |
| 11322 |
}) { |
| 11323 |
let hidden = false; |
| 11324 |
if (count < 0) { |
| 11325 |
let totalCount = items.length; |
| 11326 |
if (totalCount > 0) { |
| 11327 |
const queue = [...items]; |
| 11328 |
while (queue.length > 0) { |
| 11329 |
const { |
| 11330 |
count: nestedCount, |
| 11331 |
items: nestedItems |
| 11332 |
} = queue.shift(); |
| 11333 |
if (nestedCount > 0 && nestedItems.length > 0) { |
| 11334 |
totalCount += nestedItems.length; |
| 11335 |
queue.push(...nestedItems); |
| 11336 |
} |
| 11337 |
} |
| 11338 |
} |
| 11339 |
if (Math.abs(count) === totalCount) { |
| 11340 |
hidden = true; |
| 11341 |
} |
| 11342 |
} |
| 11343 |
super._addToggleButton(div, hidden); |
| 11344 |
} |
| 11345 |
_toggleAllTreeItems() { |
| 11346 |
if (!this._outline) { |
| 11347 |
return; |
| 11348 |
} |
| 11349 |
super._toggleAllTreeItems(); |
| 11350 |
} |
| 11351 |
render({ |
| 11352 |
outline, |
| 11353 |
pdfDocument |
| 11354 |
}) { |
| 11355 |
if (this._outline) { |
| 11356 |
this.reset(); |
| 11357 |
} |
| 11358 |
this._outline = outline || null; |
| 11359 |
this._pdfDocument = pdfDocument || null; |
| 11360 |
if (!outline) { |
| 11361 |
this._dispatchEvent(0); |
| 11362 |
return; |
| 11363 |
} |
| 11364 |
const fragment = document.createDocumentFragment(); |
| 11365 |
const queue = [{ |
| 11366 |
parent: fragment, |
| 11367 |
items: outline |
| 11368 |
}]; |
| 11369 |
let outlineCount = 0, |
| 11370 |
hasAnyNesting = false; |
| 11371 |
while (queue.length > 0) { |
| 11372 |
const levelData = queue.shift(); |
| 11373 |
for (const item of levelData.items) { |
| 11374 |
const div = document.createElement("div"); |
| 11375 |
div.className = "treeItem"; |
| 11376 |
const element = document.createElement("a"); |
| 11377 |
this._bindLink(element, item); |
| 11378 |
this._setStyles(element, item); |
| 11379 |
element.textContent = this._normalizeTextContent(item.title); |
| 11380 |
div.append(element); |
| 11381 |
if (item.items.length > 0) { |
| 11382 |
hasAnyNesting = true; |
| 11383 |
this._addToggleButton(div, item); |
| 11384 |
const itemsDiv = document.createElement("div"); |
| 11385 |
itemsDiv.className = "treeItems"; |
| 11386 |
div.append(itemsDiv); |
| 11387 |
queue.push({ |
| 11388 |
parent: itemsDiv, |
| 11389 |
items: item.items |
| 11390 |
}); |
| 11391 |
} |
| 11392 |
levelData.parent.append(div); |
| 11393 |
outlineCount++; |
| 11394 |
} |
| 11395 |
} |
| 11396 |
this._finishRendering(fragment, outlineCount, hasAnyNesting); |
| 11397 |
} |
| 11398 |
async _currentOutlineItem() { |
| 11399 |
if (!this._isPagesLoaded) { |
| 11400 |
throw new Error("_currentOutlineItem: All pages have not been loaded."); |
| 11401 |
} |
| 11402 |
if (!this._outline || !this._pdfDocument) { |
| 11403 |
return; |
| 11404 |
} |
| 11405 |
const pageNumberToDestHash = await this._getPageNumberToDestHash(this._pdfDocument); |
| 11406 |
if (!pageNumberToDestHash) { |
| 11407 |
return; |
| 11408 |
} |
| 11409 |
this._updateCurrentTreeItem(null); |
| 11410 |
if (this._sidebarView !== SidebarView.OUTLINE) { |
| 11411 |
return; |
| 11412 |
} |
| 11413 |
for (let i = this._currentPageNumber; i > 0; i--) { |
| 11414 |
const destHash = pageNumberToDestHash.get(i); |
| 11415 |
if (!destHash) { |
| 11416 |
continue; |
| 11417 |
} |
| 11418 |
const linkElement = this.container.querySelector(`a[href="${destHash}"]`); |
| 11419 |
if (!linkElement) { |
| 11420 |
continue; |
| 11421 |
} |
| 11422 |
this._scrollToCurrentTreeItem(linkElement.parentNode); |
| 11423 |
break; |
| 11424 |
} |
| 11425 |
} |
| 11426 |
async _getPageNumberToDestHash(pdfDocument) { |
| 11427 |
if (this._pageNumberToDestHashCapability) { |
| 11428 |
return this._pageNumberToDestHashCapability.promise; |
| 11429 |
} |
| 11430 |
this._pageNumberToDestHashCapability = Promise.withResolvers(); |
| 11431 |
const pageNumberToDestHash = new Map(), |
| 11432 |
pageNumberNesting = new Map(); |
| 11433 |
const queue = [{ |
| 11434 |
nesting: 0, |
| 11435 |
items: this._outline |
| 11436 |
}]; |
| 11437 |
while (queue.length > 0) { |
| 11438 |
const levelData = queue.shift(), |
| 11439 |
currentNesting = levelData.nesting; |
| 11440 |
for (const { |
| 11441 |
dest, |
| 11442 |
items |
| 11443 |
} of levelData.items) { |
| 11444 |
let explicitDest, pageNumber; |
| 11445 |
if (typeof dest === "string") { |
| 11446 |
explicitDest = await pdfDocument.getDestination(dest); |
| 11447 |
if (pdfDocument !== this._pdfDocument) { |
| 11448 |
return null; |
| 11449 |
} |
| 11450 |
} else { |
| 11451 |
explicitDest = dest; |
| 11452 |
} |
| 11453 |
if (Array.isArray(explicitDest)) { |
| 11454 |
const [destRef] = explicitDest; |
| 11455 |
if (destRef && typeof destRef === "object") { |
| 11456 |
pageNumber = pdfDocument.cachedPageNumber(destRef); |
| 11457 |
} else if (Number.isInteger(destRef)) { |
| 11458 |
pageNumber = destRef + 1; |
| 11459 |
} |
| 11460 |
if (Number.isInteger(pageNumber) && (!pageNumberToDestHash.has(pageNumber) || currentNesting > pageNumberNesting.get(pageNumber))) { |
| 11461 |
const destHash = this.linkService.getDestinationHash(dest); |
| 11462 |
pageNumberToDestHash.set(pageNumber, destHash); |
| 11463 |
pageNumberNesting.set(pageNumber, currentNesting); |
| 11464 |
} |
| 11465 |
} |
| 11466 |
if (items.length > 0) { |
| 11467 |
queue.push({ |
| 11468 |
nesting: currentNesting + 1, |
| 11469 |
items |
| 11470 |
}); |
| 11471 |
} |
| 11472 |
} |
| 11473 |
} |
| 11474 |
this._pageNumberToDestHashCapability.resolve(pageNumberToDestHash.size > 0 ? pageNumberToDestHash : null); |
| 11475 |
return this._pageNumberToDestHashCapability.promise; |
| 11476 |
} |
| 11477 |
} |
| 11478 |
|
| 11479 |
;// ./web/pdf_presentation_mode.js |
| 11480 |
|
| 11481 |
|
| 11482 |
const DELAY_BEFORE_HIDING_CONTROLS = 3000; |
| 11483 |
const ACTIVE_SELECTOR = "pdfPresentationMode"; |
| 11484 |
const CONTROLS_SELECTOR = "pdfPresentationModeControls"; |
| 11485 |
const MOUSE_SCROLL_COOLDOWN_TIME = 50; |
| 11486 |
const PAGE_SWITCH_THRESHOLD = 0.1; |
| 11487 |
const SWIPE_MIN_DISTANCE_THRESHOLD = 50; |
| 11488 |
const SWIPE_ANGLE_THRESHOLD = Math.PI / 6; |
| 11489 |
class PDFPresentationMode { |
| 11490 |
#state = PresentationModeState.UNKNOWN; |
| 11491 |
#args = null; |
| 11492 |
#fullscreenChangeAbortController = null; |
| 11493 |
#windowAbortController = null; |
| 11494 |
constructor({ |
| 11495 |
container, |
| 11496 |
pdfViewer, |
| 11497 |
eventBus |
| 11498 |
}) { |
| 11499 |
this.container = container; |
| 11500 |
this.pdfViewer = pdfViewer; |
| 11501 |
this.eventBus = eventBus; |
| 11502 |
this.contextMenuOpen = false; |
| 11503 |
this.mouseScrollTimeStamp = 0; |
| 11504 |
this.mouseScrollDelta = 0; |
| 11505 |
this.touchSwipeState = null; |
| 11506 |
} |
| 11507 |
async request() { |
| 11508 |
const { |
| 11509 |
container, |
| 11510 |
pdfViewer |
| 11511 |
} = this; |
| 11512 |
if (this.active || !pdfViewer.pagesCount || !container.requestFullscreen) { |
| 11513 |
return false; |
| 11514 |
} |
| 11515 |
this.#addFullscreenChangeListeners(); |
| 11516 |
this.#notifyStateChange(PresentationModeState.CHANGING); |
| 11517 |
const promise = container.requestFullscreen(); |
| 11518 |
this.#args = { |
| 11519 |
pageNumber: pdfViewer.currentPageNumber, |
| 11520 |
scaleValue: pdfViewer.currentScaleValue, |
| 11521 |
scrollMode: pdfViewer.scrollMode, |
| 11522 |
spreadMode: null, |
| 11523 |
annotationEditorMode: null |
| 11524 |
}; |
| 11525 |
if (pdfViewer.spreadMode !== SpreadMode.NONE && !(pdfViewer.pageViewsReady && pdfViewer.hasEqualPageSizes)) { |
| 11526 |
console.warn("Ignoring Spread modes when entering PresentationMode, " + "since the document may contain varying page sizes."); |
| 11527 |
this.#args.spreadMode = pdfViewer.spreadMode; |
| 11528 |
} |
| 11529 |
if (pdfViewer.annotationEditorMode !== AnnotationEditorType.DISABLE) { |
| 11530 |
this.#args.annotationEditorMode = pdfViewer.annotationEditorMode; |
| 11531 |
} |
| 11532 |
try { |
| 11533 |
await promise; |
| 11534 |
pdfViewer.focus(); |
| 11535 |
return true; |
| 11536 |
} catch { |
| 11537 |
this.#removeFullscreenChangeListeners(); |
| 11538 |
this.#notifyStateChange(PresentationModeState.NORMAL); |
| 11539 |
} |
| 11540 |
return false; |
| 11541 |
} |
| 11542 |
get active() { |
| 11543 |
return this.#state === PresentationModeState.CHANGING || this.#state === PresentationModeState.FULLSCREEN; |
| 11544 |
} |
| 11545 |
#mouseWheel(evt) { |
| 11546 |
if (!this.active) { |
| 11547 |
return; |
| 11548 |
} |
| 11549 |
evt.preventDefault(); |
| 11550 |
const delta = normalizeWheelEventDelta(evt); |
| 11551 |
const currentTime = Date.now(); |
| 11552 |
const storedTime = this.mouseScrollTimeStamp; |
| 11553 |
if (currentTime > storedTime && currentTime - storedTime < MOUSE_SCROLL_COOLDOWN_TIME) { |
| 11554 |
return; |
| 11555 |
} |
| 11556 |
if (this.mouseScrollDelta > 0 && delta < 0 || this.mouseScrollDelta < 0 && delta > 0) { |
| 11557 |
this.#resetMouseScrollState(); |
| 11558 |
} |
| 11559 |
this.mouseScrollDelta += delta; |
| 11560 |
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) { |
| 11561 |
const totalDelta = this.mouseScrollDelta; |
| 11562 |
this.#resetMouseScrollState(); |
| 11563 |
const success = totalDelta > 0 ? this.pdfViewer.previousPage() : this.pdfViewer.nextPage(); |
| 11564 |
if (success) { |
| 11565 |
this.mouseScrollTimeStamp = currentTime; |
| 11566 |
} |
| 11567 |
} |
| 11568 |
} |
| 11569 |
#notifyStateChange(state) { |
| 11570 |
this.#state = state; |
| 11571 |
this.eventBus.dispatch("presentationmodechanged", { |
| 11572 |
source: this, |
| 11573 |
state |
| 11574 |
}); |
| 11575 |
} |
| 11576 |
#enter() { |
| 11577 |
this.#notifyStateChange(PresentationModeState.FULLSCREEN); |
| 11578 |
this.container.classList.add(ACTIVE_SELECTOR); |
| 11579 |
setTimeout(() => { |
| 11580 |
this.pdfViewer.scrollMode = ScrollMode.PAGE; |
| 11581 |
if (this.#args.spreadMode !== null) { |
| 11582 |
this.pdfViewer.spreadMode = SpreadMode.NONE; |
| 11583 |
} |
| 11584 |
this.pdfViewer.currentPageNumber = this.#args.pageNumber; |
| 11585 |
this.pdfViewer.currentScaleValue = "page-fit"; |
| 11586 |
if (this.#args.annotationEditorMode !== null) { |
| 11587 |
this.pdfViewer.annotationEditorMode = { |
| 11588 |
mode: AnnotationEditorType.NONE |
| 11589 |
}; |
| 11590 |
} |
| 11591 |
}, 0); |
| 11592 |
this.#addWindowListeners(); |
| 11593 |
this.#showControls(); |
| 11594 |
this.contextMenuOpen = false; |
| 11595 |
document.getSelection().empty(); |
| 11596 |
} |
| 11597 |
#exit() { |
| 11598 |
const pageNumber = this.pdfViewer.currentPageNumber; |
| 11599 |
this.container.classList.remove(ACTIVE_SELECTOR); |
| 11600 |
setTimeout(() => { |
| 11601 |
this.#removeFullscreenChangeListeners(); |
| 11602 |
this.#notifyStateChange(PresentationModeState.NORMAL); |
| 11603 |
this.pdfViewer.scrollMode = this.#args.scrollMode; |
| 11604 |
if (this.#args.spreadMode !== null) { |
| 11605 |
this.pdfViewer.spreadMode = this.#args.spreadMode; |
| 11606 |
} |
| 11607 |
this.pdfViewer.currentScaleValue = this.#args.scaleValue; |
| 11608 |
this.pdfViewer.currentPageNumber = pageNumber; |
| 11609 |
if (this.#args.annotationEditorMode !== null) { |
| 11610 |
this.pdfViewer.annotationEditorMode = { |
| 11611 |
mode: this.#args.annotationEditorMode |
| 11612 |
}; |
| 11613 |
} |
| 11614 |
this.#args = null; |
| 11615 |
}, 0); |
| 11616 |
this.#removeWindowListeners(); |
| 11617 |
this.#hideControls(); |
| 11618 |
this.#resetMouseScrollState(); |
| 11619 |
this.contextMenuOpen = false; |
| 11620 |
} |
| 11621 |
#mouseDown(evt) { |
| 11622 |
if (this.contextMenuOpen) { |
| 11623 |
this.contextMenuOpen = false; |
| 11624 |
evt.preventDefault(); |
| 11625 |
return; |
| 11626 |
} |
| 11627 |
if (evt.button !== 0) { |
| 11628 |
return; |
| 11629 |
} |
| 11630 |
if (evt.target.href && evt.target.parentNode?.hasAttribute("data-internal-link")) { |
| 11631 |
return; |
| 11632 |
} |
| 11633 |
evt.preventDefault(); |
| 11634 |
if (evt.shiftKey) { |
| 11635 |
this.pdfViewer.previousPage(); |
| 11636 |
} else { |
| 11637 |
this.pdfViewer.nextPage(); |
| 11638 |
} |
| 11639 |
} |
| 11640 |
#contextMenu() { |
| 11641 |
this.contextMenuOpen = true; |
| 11642 |
} |
| 11643 |
#showControls() { |
| 11644 |
if (this.controlsTimeout) { |
| 11645 |
clearTimeout(this.controlsTimeout); |
| 11646 |
} else { |
| 11647 |
this.container.classList.add(CONTROLS_SELECTOR); |
| 11648 |
} |
| 11649 |
this.controlsTimeout = setTimeout(() => { |
| 11650 |
this.container.classList.remove(CONTROLS_SELECTOR); |
| 11651 |
delete this.controlsTimeout; |
| 11652 |
}, DELAY_BEFORE_HIDING_CONTROLS); |
| 11653 |
} |
| 11654 |
#hideControls() { |
| 11655 |
if (!this.controlsTimeout) { |
| 11656 |
return; |
| 11657 |
} |
| 11658 |
clearTimeout(this.controlsTimeout); |
| 11659 |
this.container.classList.remove(CONTROLS_SELECTOR); |
| 11660 |
delete this.controlsTimeout; |
| 11661 |
} |
| 11662 |
#resetMouseScrollState() { |
| 11663 |
this.mouseScrollTimeStamp = 0; |
| 11664 |
this.mouseScrollDelta = 0; |
| 11665 |
} |
| 11666 |
#touchSwipe(evt) { |
| 11667 |
if (!this.active) { |
| 11668 |
return; |
| 11669 |
} |
| 11670 |
if (evt.touches.length > 1) { |
| 11671 |
this.touchSwipeState = null; |
| 11672 |
return; |
| 11673 |
} |
| 11674 |
switch (evt.type) { |
| 11675 |
case "touchstart": |
| 11676 |
this.touchSwipeState = { |
| 11677 |
startX: evt.touches[0].pageX, |
| 11678 |
startY: evt.touches[0].pageY, |
| 11679 |
endX: evt.touches[0].pageX, |
| 11680 |
endY: evt.touches[0].pageY |
| 11681 |
}; |
| 11682 |
break; |
| 11683 |
case "touchmove": |
| 11684 |
if (this.touchSwipeState === null) { |
| 11685 |
return; |
| 11686 |
} |
| 11687 |
this.touchSwipeState.endX = evt.touches[0].pageX; |
| 11688 |
this.touchSwipeState.endY = evt.touches[0].pageY; |
| 11689 |
evt.preventDefault(); |
| 11690 |
break; |
| 11691 |
case "touchend": |
| 11692 |
if (this.touchSwipeState === null) { |
| 11693 |
return; |
| 11694 |
} |
| 11695 |
let delta = 0; |
| 11696 |
const dx = this.touchSwipeState.endX - this.touchSwipeState.startX; |
| 11697 |
const dy = this.touchSwipeState.endY - this.touchSwipeState.startY; |
| 11698 |
const absAngle = Math.abs(Math.atan2(dy, dx)); |
| 11699 |
if (Math.abs(dx) > SWIPE_MIN_DISTANCE_THRESHOLD && (absAngle <= SWIPE_ANGLE_THRESHOLD || absAngle >= Math.PI - SWIPE_ANGLE_THRESHOLD)) { |
| 11700 |
delta = dx; |
| 11701 |
} else if (Math.abs(dy) > SWIPE_MIN_DISTANCE_THRESHOLD && Math.abs(absAngle - Math.PI / 2) <= SWIPE_ANGLE_THRESHOLD) { |
| 11702 |
delta = dy; |
| 11703 |
} |
| 11704 |
if (delta > 0) { |
| 11705 |
this.pdfViewer.previousPage(); |
| 11706 |
} else if (delta < 0) { |
| 11707 |
this.pdfViewer.nextPage(); |
| 11708 |
} |
| 11709 |
break; |
| 11710 |
} |
| 11711 |
} |
| 11712 |
#addWindowListeners() { |
| 11713 |
if (this.#windowAbortController) { |
| 11714 |
return; |
| 11715 |
} |
| 11716 |
this.#windowAbortController = new AbortController(); |
| 11717 |
const { |
| 11718 |
signal |
| 11719 |
} = this.#windowAbortController; |
| 11720 |
const touchSwipeBind = this.#touchSwipe.bind(this); |
| 11721 |
window.addEventListener("mousemove", this.#showControls.bind(this), { |
| 11722 |
signal |
| 11723 |
}); |
| 11724 |
window.addEventListener("mousedown", this.#mouseDown.bind(this), { |
| 11725 |
signal |
| 11726 |
}); |
| 11727 |
window.addEventListener("wheel", this.#mouseWheel.bind(this), { |
| 11728 |
passive: false, |
| 11729 |
signal |
| 11730 |
}); |
| 11731 |
window.addEventListener("keydown", this.#resetMouseScrollState.bind(this), { |
| 11732 |
signal |
| 11733 |
}); |
| 11734 |
window.addEventListener("contextmenu", this.#contextMenu.bind(this), { |
| 11735 |
signal |
| 11736 |
}); |
| 11737 |
window.addEventListener("touchstart", touchSwipeBind, { |
| 11738 |
signal |
| 11739 |
}); |
| 11740 |
window.addEventListener("touchmove", touchSwipeBind, { |
| 11741 |
signal |
| 11742 |
}); |
| 11743 |
window.addEventListener("touchend", touchSwipeBind, { |
| 11744 |
signal |
| 11745 |
}); |
| 11746 |
} |
| 11747 |
#removeWindowListeners() { |
| 11748 |
this.#windowAbortController?.abort(); |
| 11749 |
this.#windowAbortController = null; |
| 11750 |
} |
| 11751 |
#addFullscreenChangeListeners() { |
| 11752 |
if (this.#fullscreenChangeAbortController) { |
| 11753 |
return; |
| 11754 |
} |
| 11755 |
this.#fullscreenChangeAbortController = new AbortController(); |
| 11756 |
window.addEventListener("fullscreenchange", () => { |
| 11757 |
if (document.fullscreenElement) { |
| 11758 |
this.#enter(); |
| 11759 |
} else { |
| 11760 |
this.#exit(); |
| 11761 |
} |
| 11762 |
}, { |
| 11763 |
signal: this.#fullscreenChangeAbortController.signal |
| 11764 |
}); |
| 11765 |
} |
| 11766 |
#removeFullscreenChangeListeners() { |
| 11767 |
this.#fullscreenChangeAbortController?.abort(); |
| 11768 |
this.#fullscreenChangeAbortController = null; |
| 11769 |
} |
| 11770 |
} |
| 11771 |
|
| 11772 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/es.iterator.every.js |
| 11773 |
var es_iterator_every = __webpack_require__(1148); |
| 11774 |
;// ./web/xfa_layer_builder.js |
| 11775 |
|
| 11776 |
class XfaLayerBuilder { |
| 11777 |
constructor({ |
| 11778 |
pdfPage, |
| 11779 |
annotationStorage = null, |
| 11780 |
linkService, |
| 11781 |
xfaHtml = null |
| 11782 |
}) { |
| 11783 |
this.pdfPage = pdfPage; |
| 11784 |
this.annotationStorage = annotationStorage; |
| 11785 |
this.linkService = linkService; |
| 11786 |
this.xfaHtml = xfaHtml; |
| 11787 |
this.div = null; |
| 11788 |
this._cancelled = false; |
| 11789 |
} |
| 11790 |
async render({ |
| 11791 |
viewport, |
| 11792 |
intent = "display" |
| 11793 |
}) { |
| 11794 |
if (intent === "print") { |
| 11795 |
const parameters = { |
| 11796 |
viewport: viewport.clone({ |
| 11797 |
dontFlip: true |
| 11798 |
}), |
| 11799 |
div: this.div, |
| 11800 |
xfaHtml: this.xfaHtml, |
| 11801 |
annotationStorage: this.annotationStorage, |
| 11802 |
linkService: this.linkService, |
| 11803 |
intent |
| 11804 |
}; |
| 11805 |
this.div = document.createElement("div"); |
| 11806 |
parameters.div = this.div; |
| 11807 |
return XfaLayer.render(parameters); |
| 11808 |
} |
| 11809 |
const xfaHtml = await this.pdfPage.getXfa(); |
| 11810 |
if (this._cancelled || !xfaHtml) { |
| 11811 |
return { |
| 11812 |
textDivs: [] |
| 11813 |
}; |
| 11814 |
} |
| 11815 |
const parameters = { |
| 11816 |
viewport: viewport.clone({ |
| 11817 |
dontFlip: true |
| 11818 |
}), |
| 11819 |
div: this.div, |
| 11820 |
xfaHtml, |
| 11821 |
annotationStorage: this.annotationStorage, |
| 11822 |
linkService: this.linkService, |
| 11823 |
intent |
| 11824 |
}; |
| 11825 |
if (this.div) { |
| 11826 |
return XfaLayer.update(parameters); |
| 11827 |
} |
| 11828 |
this.div = document.createElement("div"); |
| 11829 |
parameters.div = this.div; |
| 11830 |
return XfaLayer.render(parameters); |
| 11831 |
} |
| 11832 |
cancel() { |
| 11833 |
this._cancelled = true; |
| 11834 |
} |
| 11835 |
hide() { |
| 11836 |
if (!this.div) { |
| 11837 |
return; |
| 11838 |
} |
| 11839 |
this.div.hidden = true; |
| 11840 |
} |
| 11841 |
} |
| 11842 |
|
| 11843 |
;// ./web/print_utils.js |
| 11844 |
|
| 11845 |
|
| 11846 |
|
| 11847 |
function getXfaHtmlForPrinting(printContainer, pdfDocument) { |
| 11848 |
const xfaHtml = pdfDocument.allXfaHtml; |
| 11849 |
const linkService = new SimpleLinkService(); |
| 11850 |
const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100; |
| 11851 |
for (const xfaPage of xfaHtml.children) { |
| 11852 |
const page = document.createElement("div"); |
| 11853 |
page.className = "xfaPrintedPage"; |
| 11854 |
printContainer.append(page); |
| 11855 |
const builder = new XfaLayerBuilder({ |
| 11856 |
pdfPage: null, |
| 11857 |
annotationStorage: pdfDocument.annotationStorage, |
| 11858 |
linkService, |
| 11859 |
xfaHtml: xfaPage |
| 11860 |
}); |
| 11861 |
const viewport = getXfaPageViewport(xfaPage, { |
| 11862 |
scale |
| 11863 |
}); |
| 11864 |
builder.render({ |
| 11865 |
viewport, |
| 11866 |
intent: "print" |
| 11867 |
}); |
| 11868 |
page.append(builder.div); |
| 11869 |
} |
| 11870 |
} |
| 11871 |
|
| 11872 |
;// ./web/pdf_print_service.js |
| 11873 |
|
| 11874 |
|
| 11875 |
|
| 11876 |
|
| 11877 |
|
| 11878 |
|
| 11879 |
|
| 11880 |
|
| 11881 |
let activeService = null; |
| 11882 |
let dialog = null; |
| 11883 |
let overlayManager = null; |
| 11884 |
let viewerApp = { |
| 11885 |
initialized: false |
| 11886 |
}; |
| 11887 |
function renderPage(activeServiceOnEntry, pdfDocument, pageNumber, size, printResolution, optionalContentConfigPromise, printAnnotationStoragePromise) { |
| 11888 |
const scratchCanvas = activeService.scratchCanvas; |
| 11889 |
const PRINT_UNITS = printResolution / PixelsPerInch.PDF; |
| 11890 |
scratchCanvas.width = Math.floor(size.width * PRINT_UNITS); |
| 11891 |
scratchCanvas.height = Math.floor(size.height * PRINT_UNITS); |
| 11892 |
const ctx = scratchCanvas.getContext("2d"); |
| 11893 |
ctx.save(); |
| 11894 |
ctx.fillStyle = "rgb(255, 255, 255)"; |
| 11895 |
ctx.fillRect(0, 0, scratchCanvas.width, scratchCanvas.height); |
| 11896 |
ctx.restore(); |
| 11897 |
return Promise.all([pdfDocument.getPage(pageNumber), printAnnotationStoragePromise]).then(function ([pdfPage, printAnnotationStorage]) { |
| 11898 |
const renderContext = { |
| 11899 |
canvasContext: ctx, |
| 11900 |
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0], |
| 11901 |
viewport: pdfPage.getViewport({ |
| 11902 |
scale: 1, |
| 11903 |
rotation: size.rotation |
| 11904 |
}), |
| 11905 |
intent: "print", |
| 11906 |
annotationMode: AnnotationMode.ENABLE_STORAGE, |
| 11907 |
optionalContentConfigPromise, |
| 11908 |
printAnnotationStorage |
| 11909 |
}; |
| 11910 |
const renderTask = pdfPage.render(renderContext); |
| 11911 |
return renderTask.promise.catch(reason => { |
| 11912 |
if (!(reason instanceof RenderingCancelledException)) { |
| 11913 |
console.error(reason); |
| 11914 |
} |
| 11915 |
throw reason; |
| 11916 |
}); |
| 11917 |
}); |
| 11918 |
} |
| 11919 |
class PDFPrintService { |
| 11920 |
constructor({ |
| 11921 |
pdfDocument, |
| 11922 |
pagesOverview, |
| 11923 |
printContainer, |
| 11924 |
printResolution, |
| 11925 |
printAnnotationStoragePromise = null |
| 11926 |
}) { |
| 11927 |
this.pdfDocument = pdfDocument; |
| 11928 |
this.pagesOverview = pagesOverview; |
| 11929 |
this.printContainer = printContainer; |
| 11930 |
this._printResolution = printResolution || 150; |
| 11931 |
this._optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({ |
| 11932 |
intent: "print" |
| 11933 |
}); |
| 11934 |
this._printAnnotationStoragePromise = printAnnotationStoragePromise || Promise.resolve(); |
| 11935 |
this.currentPage = -1; |
| 11936 |
this.scratchCanvas = document.createElement("canvas"); |
| 11937 |
} |
| 11938 |
layout() { |
| 11939 |
this.throwIfInactive(); |
| 11940 |
const body = document.querySelector("body"); |
| 11941 |
body.setAttribute("data-pdfjsprinting", true); |
| 11942 |
const { |
| 11943 |
width, |
| 11944 |
height |
| 11945 |
} = this.pagesOverview[0]; |
| 11946 |
const hasEqualPageSizes = this.pagesOverview.every(size => size.width === width && size.height === height); |
| 11947 |
if (!hasEqualPageSizes) { |
| 11948 |
console.warn("Not all pages have the same size. The printed result may be incorrect!"); |
| 11949 |
} |
| 11950 |
this.pageStyleSheet = document.createElement("style"); |
| 11951 |
this.pageStyleSheet.textContent = `@page { size: ${width}pt ${height}pt;}`; |
| 11952 |
body.append(this.pageStyleSheet); |
| 11953 |
} |
| 11954 |
destroy() { |
| 11955 |
if (activeService !== this) { |
| 11956 |
return; |
| 11957 |
} |
| 11958 |
this.printContainer.textContent = ""; |
| 11959 |
const body = document.querySelector("body"); |
| 11960 |
body.removeAttribute("data-pdfjsprinting"); |
| 11961 |
if (this.pageStyleSheet) { |
| 11962 |
this.pageStyleSheet.remove(); |
| 11963 |
this.pageStyleSheet = null; |
| 11964 |
} |
| 11965 |
this.scratchCanvas.width = this.scratchCanvas.height = 0; |
| 11966 |
this.scratchCanvas = null; |
| 11967 |
activeService = null; |
| 11968 |
ensureOverlay().then(function () { |
| 11969 |
overlayManager.closeIfActive(dialog); |
| 11970 |
}); |
| 11971 |
} |
| 11972 |
renderPages() { |
| 11973 |
if (this.pdfDocument.isPureXfa) { |
| 11974 |
getXfaHtmlForPrinting(this.printContainer, this.pdfDocument); |
| 11975 |
return Promise.resolve(); |
| 11976 |
} |
| 11977 |
const pageCount = this.pagesOverview.length; |
| 11978 |
const renderNextPage = (resolve, reject) => { |
| 11979 |
this.throwIfInactive(); |
| 11980 |
if (++this.currentPage >= pageCount) { |
| 11981 |
renderProgress(pageCount, pageCount); |
| 11982 |
resolve(); |
| 11983 |
return; |
| 11984 |
} |
| 11985 |
const index = this.currentPage; |
| 11986 |
renderProgress(index, pageCount); |
| 11987 |
renderPage(this, this.pdfDocument, index + 1, this.pagesOverview[index], this._printResolution, this._optionalContentConfigPromise, this._printAnnotationStoragePromise).then(this.useRenderedPage.bind(this)).then(function () { |
| 11988 |
renderNextPage(resolve, reject); |
| 11989 |
}, reject); |
| 11990 |
}; |
| 11991 |
return new Promise(renderNextPage); |
| 11992 |
} |
| 11993 |
useRenderedPage() { |
| 11994 |
this.throwIfInactive(); |
| 11995 |
const img = document.createElement("img"); |
| 11996 |
this.scratchCanvas.toBlob(blob => { |
| 11997 |
img.src = URL.createObjectURL(blob); |
| 11998 |
}); |
| 11999 |
const wrapper = document.createElement("div"); |
| 12000 |
wrapper.className = "printedPage"; |
| 12001 |
wrapper.append(img); |
| 12002 |
this.printContainer.append(wrapper); |
| 12003 |
const { |
| 12004 |
promise, |
| 12005 |
resolve, |
| 12006 |
reject |
| 12007 |
} = Promise.withResolvers(); |
| 12008 |
img.onload = resolve; |
| 12009 |
img.onerror = reject; |
| 12010 |
promise.catch(() => {}).then(() => { |
| 12011 |
URL.revokeObjectURL(img.src); |
| 12012 |
}); |
| 12013 |
return promise; |
| 12014 |
} |
| 12015 |
performPrint() { |
| 12016 |
this.throwIfInactive(); |
| 12017 |
return new Promise(resolve => { |
| 12018 |
setTimeout(() => { |
| 12019 |
if (!this.active) { |
| 12020 |
resolve(); |
| 12021 |
return; |
| 12022 |
} |
| 12023 |
print.call(window); |
| 12024 |
setTimeout(resolve, 20); |
| 12025 |
}, 0); |
| 12026 |
}); |
| 12027 |
} |
| 12028 |
get active() { |
| 12029 |
return this === activeService; |
| 12030 |
} |
| 12031 |
throwIfInactive() { |
| 12032 |
if (!this.active) { |
| 12033 |
throw new Error("This print request was cancelled or completed."); |
| 12034 |
} |
| 12035 |
} |
| 12036 |
} |
| 12037 |
const print = window.print; |
| 12038 |
window.print = function () { |
| 12039 |
if (activeService) { |
| 12040 |
console.warn("Ignored window.print() because of a pending print job."); |
| 12041 |
return; |
| 12042 |
} |
| 12043 |
ensureOverlay().then(function () { |
| 12044 |
if (activeService) { |
| 12045 |
overlayManager.open(dialog); |
| 12046 |
} |
| 12047 |
}); |
| 12048 |
try { |
| 12049 |
dispatchEvent("beforeprint"); |
| 12050 |
} finally { |
| 12051 |
if (!activeService) { |
| 12052 |
console.error("Expected print service to be initialized."); |
| 12053 |
ensureOverlay().then(function () { |
| 12054 |
overlayManager.closeIfActive(dialog); |
| 12055 |
}); |
| 12056 |
} else { |
| 12057 |
const activeServiceOnEntry = activeService; |
| 12058 |
activeService.renderPages().then(() => activeServiceOnEntry.performPrint()).catch(() => {}).then(() => { |
| 12059 |
if (activeServiceOnEntry.active) { |
| 12060 |
abort(); |
| 12061 |
} |
| 12062 |
}); |
| 12063 |
} |
| 12064 |
} |
| 12065 |
}; |
| 12066 |
function dispatchEvent(eventType) { |
| 12067 |
const event = new CustomEvent(eventType, { |
| 12068 |
bubbles: false, |
| 12069 |
cancelable: false, |
| 12070 |
detail: "custom" |
| 12071 |
}); |
| 12072 |
window.dispatchEvent(event); |
| 12073 |
} |
| 12074 |
function abort() { |
| 12075 |
if (activeService) { |
| 12076 |
activeService.destroy(); |
| 12077 |
dispatchEvent("afterprint"); |
| 12078 |
} |
| 12079 |
} |
| 12080 |
function renderProgress(index, total) { |
| 12081 |
dialog ||= document.getElementById("printServiceDialog"); |
| 12082 |
const progress = Math.round(100 * index / total); |
| 12083 |
const progressBar = dialog.querySelector("progress"); |
| 12084 |
const progressPerc = dialog.querySelector(".relative-progress"); |
| 12085 |
progressBar.value = progress; |
| 12086 |
progressPerc.setAttribute("data-l10n-args", JSON.stringify({ |
| 12087 |
progress |
| 12088 |
})); |
| 12089 |
} |
| 12090 |
window.addEventListener("keydown", function (event) { |
| 12091 |
if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) { |
| 12092 |
window.print(); |
| 12093 |
event.preventDefault(); |
| 12094 |
event.stopImmediatePropagation(); |
| 12095 |
} |
| 12096 |
}, true); |
| 12097 |
if ("onbeforeprint" in window) { |
| 12098 |
const stopPropagationIfNeeded = function (event) { |
| 12099 |
if (event.detail !== "custom") { |
| 12100 |
event.stopImmediatePropagation(); |
| 12101 |
} |
| 12102 |
}; |
| 12103 |
window.addEventListener("beforeprint", stopPropagationIfNeeded); |
| 12104 |
window.addEventListener("afterprint", stopPropagationIfNeeded); |
| 12105 |
} |
| 12106 |
let overlayPromise; |
| 12107 |
function ensureOverlay() { |
| 12108 |
if (!overlayPromise) { |
| 12109 |
overlayManager = viewerApp.overlayManager; |
| 12110 |
if (!overlayManager) { |
| 12111 |
throw new Error("The overlay manager has not yet been initialized."); |
| 12112 |
} |
| 12113 |
dialog ||= document.getElementById("printServiceDialog"); |
| 12114 |
overlayPromise = overlayManager.register(dialog, true); |
| 12115 |
document.getElementById("printCancel").onclick = abort; |
| 12116 |
dialog.addEventListener("close", abort); |
| 12117 |
} |
| 12118 |
return overlayPromise; |
| 12119 |
} |
| 12120 |
class PDFPrintServiceFactory { |
| 12121 |
static initGlobals(app) { |
| 12122 |
viewerApp = app; |
| 12123 |
} |
| 12124 |
static get supportsPrinting() { |
| 12125 |
return shadow(this, "supportsPrinting", true); |
| 12126 |
} |
| 12127 |
static createPrintService(params) { |
| 12128 |
if (activeService) { |
| 12129 |
throw new Error("The print service is created and active."); |
| 12130 |
} |
| 12131 |
return activeService = new PDFPrintService(params); |
| 12132 |
} |
| 12133 |
} |
| 12134 |
|
| 12135 |
;// ./web/pdf_rendering_queue.js |
| 12136 |
|
| 12137 |
|
| 12138 |
const CLEANUP_TIMEOUT = 30000; |
| 12139 |
class PDFRenderingQueue { |
| 12140 |
constructor() { |
| 12141 |
this.pdfViewer = null; |
| 12142 |
this.pdfThumbnailViewer = null; |
| 12143 |
this.onIdle = null; |
| 12144 |
this.highestPriorityPage = null; |
| 12145 |
this.idleTimeout = null; |
| 12146 |
this.printing = false; |
| 12147 |
this.isThumbnailViewEnabled = false; |
| 12148 |
Object.defineProperty(this, "hasViewer", { |
| 12149 |
value: () => !!this.pdfViewer |
| 12150 |
}); |
| 12151 |
} |
| 12152 |
setViewer(pdfViewer) { |
| 12153 |
this.pdfViewer = pdfViewer; |
| 12154 |
} |
| 12155 |
setThumbnailViewer(pdfThumbnailViewer) { |
| 12156 |
this.pdfThumbnailViewer = pdfThumbnailViewer; |
| 12157 |
} |
| 12158 |
isHighestPriority(view) { |
| 12159 |
return this.highestPriorityPage === view.renderingId; |
| 12160 |
} |
| 12161 |
renderHighestPriority(currentlyVisiblePages) { |
| 12162 |
if (this.idleTimeout) { |
| 12163 |
clearTimeout(this.idleTimeout); |
| 12164 |
this.idleTimeout = null; |
| 12165 |
} |
| 12166 |
if (this.pdfViewer.forceRendering(currentlyVisiblePages)) { |
| 12167 |
return; |
| 12168 |
} |
| 12169 |
if (this.isThumbnailViewEnabled && this.pdfThumbnailViewer?.forceRendering()) { |
| 12170 |
return; |
| 12171 |
} |
| 12172 |
if (this.printing) { |
| 12173 |
return; |
| 12174 |
} |
| 12175 |
if (this.onIdle) { |
| 12176 |
this.idleTimeout = setTimeout(this.onIdle.bind(this), CLEANUP_TIMEOUT); |
| 12177 |
} |
| 12178 |
} |
| 12179 |
getHighestPriority(visible, views, scrolledDown, preRenderExtra = false, ignoreDetailViews = false) { |
| 12180 |
const visibleViews = visible.views, |
| 12181 |
numVisible = visibleViews.length; |
| 12182 |
if (numVisible === 0) { |
| 12183 |
return null; |
| 12184 |
} |
| 12185 |
for (let i = 0; i < numVisible; i++) { |
| 12186 |
const view = visibleViews[i].view; |
| 12187 |
if (!this.isViewFinished(view)) { |
| 12188 |
return view; |
| 12189 |
} |
| 12190 |
} |
| 12191 |
if (!ignoreDetailViews) { |
| 12192 |
for (let i = 0; i < numVisible; i++) { |
| 12193 |
const { |
| 12194 |
detailView |
| 12195 |
} = visibleViews[i].view; |
| 12196 |
if (detailView && !this.isViewFinished(detailView)) { |
| 12197 |
return detailView; |
| 12198 |
} |
| 12199 |
} |
| 12200 |
} |
| 12201 |
const firstId = visible.first.id, |
| 12202 |
lastId = visible.last.id; |
| 12203 |
if (lastId - firstId + 1 > numVisible) { |
| 12204 |
const visibleIds = visible.ids; |
| 12205 |
for (let i = 1, ii = lastId - firstId; i < ii; i++) { |
| 12206 |
const holeId = scrolledDown ? firstId + i : lastId - i; |
| 12207 |
if (visibleIds.has(holeId)) { |
| 12208 |
continue; |
| 12209 |
} |
| 12210 |
const holeView = views[holeId - 1]; |
| 12211 |
if (!this.isViewFinished(holeView)) { |
| 12212 |
return holeView; |
| 12213 |
} |
| 12214 |
} |
| 12215 |
} |
| 12216 |
let preRenderIndex = scrolledDown ? lastId : firstId - 2; |
| 12217 |
let preRenderView = views[preRenderIndex]; |
| 12218 |
if (preRenderView && !this.isViewFinished(preRenderView)) { |
| 12219 |
return preRenderView; |
| 12220 |
} |
| 12221 |
if (preRenderExtra) { |
| 12222 |
preRenderIndex += scrolledDown ? 1 : -1; |
| 12223 |
preRenderView = views[preRenderIndex]; |
| 12224 |
if (preRenderView && !this.isViewFinished(preRenderView)) { |
| 12225 |
return preRenderView; |
| 12226 |
} |
| 12227 |
} |
| 12228 |
return null; |
| 12229 |
} |
| 12230 |
isViewFinished(view) { |
| 12231 |
return view.renderingState === RenderingStates.FINISHED; |
| 12232 |
} |
| 12233 |
renderView(view) { |
| 12234 |
switch (view.renderingState) { |
| 12235 |
case RenderingStates.FINISHED: |
| 12236 |
return false; |
| 12237 |
case RenderingStates.PAUSED: |
| 12238 |
this.highestPriorityPage = view.renderingId; |
| 12239 |
view.resume(); |
| 12240 |
break; |
| 12241 |
case RenderingStates.RUNNING: |
| 12242 |
this.highestPriorityPage = view.renderingId; |
| 12243 |
break; |
| 12244 |
case RenderingStates.INITIAL: |
| 12245 |
this.highestPriorityPage = view.renderingId; |
| 12246 |
view.draw().finally(() => { |
| 12247 |
this.renderHighestPriority(); |
| 12248 |
}).catch(reason => { |
| 12249 |
if (reason instanceof RenderingCancelledException) { |
| 12250 |
return; |
| 12251 |
} |
| 12252 |
console.error("renderView:", reason); |
| 12253 |
}); |
| 12254 |
break; |
| 12255 |
} |
| 12256 |
return true; |
| 12257 |
} |
| 12258 |
} |
| 12259 |
|
| 12260 |
;// ./web/pdf_scripting_manager.js |
| 12261 |
|
| 12262 |
|
| 12263 |
|
| 12264 |
|
| 12265 |
|
| 12266 |
|
| 12267 |
|
| 12268 |
|
| 12269 |
|
| 12270 |
|
| 12271 |
class PDFScriptingManager { |
| 12272 |
#closeCapability = null; |
| 12273 |
#destroyCapability = null; |
| 12274 |
#docProperties = null; |
| 12275 |
#eventAbortController = null; |
| 12276 |
#eventBus = null; |
| 12277 |
#externalServices = null; |
| 12278 |
#pdfDocument = null; |
| 12279 |
#pdfViewer = null; |
| 12280 |
#ready = false; |
| 12281 |
#scripting = null; |
| 12282 |
#willPrintCapability = null; |
| 12283 |
constructor({ |
| 12284 |
eventBus, |
| 12285 |
externalServices = null, |
| 12286 |
docProperties = null |
| 12287 |
}) { |
| 12288 |
this.#eventBus = eventBus; |
| 12289 |
this.#externalServices = externalServices; |
| 12290 |
this.#docProperties = docProperties; |
| 12291 |
} |
| 12292 |
setViewer(pdfViewer) { |
| 12293 |
this.#pdfViewer = pdfViewer; |
| 12294 |
} |
| 12295 |
async setDocument(pdfDocument) { |
| 12296 |
if (this.#pdfDocument) { |
| 12297 |
await this.#destroyScripting(); |
| 12298 |
} |
| 12299 |
this.#pdfDocument = pdfDocument; |
| 12300 |
if (!pdfDocument) { |
| 12301 |
return; |
| 12302 |
} |
| 12303 |
const [objects, calculationOrder, docActions] = await Promise.all([pdfDocument.getFieldObjects(), pdfDocument.getCalculationOrderIds(), pdfDocument.getJSActions()]); |
| 12304 |
if (!objects && !docActions) { |
| 12305 |
await this.#destroyScripting(); |
| 12306 |
return; |
| 12307 |
} |
| 12308 |
if (pdfDocument !== this.#pdfDocument) { |
| 12309 |
return; |
| 12310 |
} |
| 12311 |
try { |
| 12312 |
this.#scripting = this.#initScripting(); |
| 12313 |
} catch (error) { |
| 12314 |
console.error("setDocument:", error); |
| 12315 |
await this.#destroyScripting(); |
| 12316 |
return; |
| 12317 |
} |
| 12318 |
const eventBus = this.#eventBus; |
| 12319 |
this.#eventAbortController = new AbortController(); |
| 12320 |
const { |
| 12321 |
signal |
| 12322 |
} = this.#eventAbortController; |
| 12323 |
eventBus._on("updatefromsandbox", event => { |
| 12324 |
if (event?.source === window) { |
| 12325 |
this.#updateFromSandbox(event.detail); |
| 12326 |
} |
| 12327 |
}, { |
| 12328 |
signal |
| 12329 |
}); |
| 12330 |
eventBus._on("dispatcheventinsandbox", event => { |
| 12331 |
this.#scripting?.dispatchEventInSandbox(event.detail); |
| 12332 |
}, { |
| 12333 |
signal |
| 12334 |
}); |
| 12335 |
eventBus._on("pagechanging", ({ |
| 12336 |
pageNumber, |
| 12337 |
previous |
| 12338 |
}) => { |
| 12339 |
if (pageNumber === previous) { |
| 12340 |
return; |
| 12341 |
} |
| 12342 |
this.#dispatchPageClose(previous); |
| 12343 |
this.#dispatchPageOpen(pageNumber); |
| 12344 |
}, { |
| 12345 |
signal |
| 12346 |
}); |
| 12347 |
eventBus._on("pagerendered", ({ |
| 12348 |
pageNumber |
| 12349 |
}) => { |
| 12350 |
if (!this._pageOpenPending.has(pageNumber)) { |
| 12351 |
return; |
| 12352 |
} |
| 12353 |
if (pageNumber !== this.#pdfViewer.currentPageNumber) { |
| 12354 |
return; |
| 12355 |
} |
| 12356 |
this.#dispatchPageOpen(pageNumber); |
| 12357 |
}, { |
| 12358 |
signal |
| 12359 |
}); |
| 12360 |
eventBus._on("pagesdestroy", async () => { |
| 12361 |
await this.#dispatchPageClose(this.#pdfViewer.currentPageNumber); |
| 12362 |
await this.#scripting?.dispatchEventInSandbox({ |
| 12363 |
id: "doc", |
| 12364 |
name: "WillClose" |
| 12365 |
}); |
| 12366 |
this.#closeCapability?.resolve(); |
| 12367 |
}, { |
| 12368 |
signal |
| 12369 |
}); |
| 12370 |
try { |
| 12371 |
const docProperties = await this.#docProperties(pdfDocument); |
| 12372 |
if (pdfDocument !== this.#pdfDocument) { |
| 12373 |
return; |
| 12374 |
} |
| 12375 |
await this.#scripting.createSandbox({ |
| 12376 |
objects, |
| 12377 |
calculationOrder, |
| 12378 |
appInfo: { |
| 12379 |
platform: navigator.platform, |
| 12380 |
language: navigator.language |
| 12381 |
}, |
| 12382 |
docInfo: { |
| 12383 |
...docProperties, |
| 12384 |
actions: docActions |
| 12385 |
} |
| 12386 |
}); |
| 12387 |
eventBus.dispatch("sandboxcreated", { |
| 12388 |
source: this |
| 12389 |
}); |
| 12390 |
} catch (error) { |
| 12391 |
console.error("setDocument:", error); |
| 12392 |
await this.#destroyScripting(); |
| 12393 |
return; |
| 12394 |
} |
| 12395 |
await this.#scripting?.dispatchEventInSandbox({ |
| 12396 |
id: "doc", |
| 12397 |
name: "Open" |
| 12398 |
}); |
| 12399 |
await this.#dispatchPageOpen(this.#pdfViewer.currentPageNumber, true); |
| 12400 |
Promise.resolve().then(() => { |
| 12401 |
if (pdfDocument === this.#pdfDocument) { |
| 12402 |
this.#ready = true; |
| 12403 |
} |
| 12404 |
}); |
| 12405 |
} |
| 12406 |
async dispatchWillSave() { |
| 12407 |
return this.#scripting?.dispatchEventInSandbox({ |
| 12408 |
id: "doc", |
| 12409 |
name: "WillSave" |
| 12410 |
}); |
| 12411 |
} |
| 12412 |
async dispatchDidSave() { |
| 12413 |
return this.#scripting?.dispatchEventInSandbox({ |
| 12414 |
id: "doc", |
| 12415 |
name: "DidSave" |
| 12416 |
}); |
| 12417 |
} |
| 12418 |
async dispatchWillPrint() { |
| 12419 |
if (!this.#scripting) { |
| 12420 |
return; |
| 12421 |
} |
| 12422 |
await this.#willPrintCapability?.promise; |
| 12423 |
this.#willPrintCapability = Promise.withResolvers(); |
| 12424 |
try { |
| 12425 |
await this.#scripting.dispatchEventInSandbox({ |
| 12426 |
id: "doc", |
| 12427 |
name: "WillPrint" |
| 12428 |
}); |
| 12429 |
} catch (ex) { |
| 12430 |
this.#willPrintCapability.resolve(); |
| 12431 |
this.#willPrintCapability = null; |
| 12432 |
throw ex; |
| 12433 |
} |
| 12434 |
await this.#willPrintCapability.promise; |
| 12435 |
} |
| 12436 |
async dispatchDidPrint() { |
| 12437 |
return this.#scripting?.dispatchEventInSandbox({ |
| 12438 |
id: "doc", |
| 12439 |
name: "DidPrint" |
| 12440 |
}); |
| 12441 |
} |
| 12442 |
get destroyPromise() { |
| 12443 |
return this.#destroyCapability?.promise || null; |
| 12444 |
} |
| 12445 |
get ready() { |
| 12446 |
return this.#ready; |
| 12447 |
} |
| 12448 |
get _pageOpenPending() { |
| 12449 |
return shadow(this, "_pageOpenPending", new Set()); |
| 12450 |
} |
| 12451 |
get _visitedPages() { |
| 12452 |
return shadow(this, "_visitedPages", new Map()); |
| 12453 |
} |
| 12454 |
async #updateFromSandbox(detail) { |
| 12455 |
const pdfViewer = this.#pdfViewer; |
| 12456 |
const isInPresentationMode = pdfViewer.isInPresentationMode || pdfViewer.isChangingPresentationMode; |
| 12457 |
const { |
| 12458 |
id, |
| 12459 |
siblings, |
| 12460 |
command, |
| 12461 |
value |
| 12462 |
} = detail; |
| 12463 |
if (!id) { |
| 12464 |
switch (command) { |
| 12465 |
case "clear": |
| 12466 |
console.clear(); |
| 12467 |
break; |
| 12468 |
case "error": |
| 12469 |
console.error(value); |
| 12470 |
break; |
| 12471 |
case "layout": |
| 12472 |
if (!isInPresentationMode) { |
| 12473 |
const modes = apiPageLayoutToViewerModes(value); |
| 12474 |
pdfViewer.spreadMode = modes.spreadMode; |
| 12475 |
} |
| 12476 |
break; |
| 12477 |
case "page-num": |
| 12478 |
pdfViewer.currentPageNumber = value + 1; |
| 12479 |
break; |
| 12480 |
case "print": |
| 12481 |
await pdfViewer.pagesPromise; |
| 12482 |
this.#eventBus.dispatch("print", { |
| 12483 |
source: this |
| 12484 |
}); |
| 12485 |
break; |
| 12486 |
case "println": |
| 12487 |
console.log(value); |
| 12488 |
break; |
| 12489 |
case "zoom": |
| 12490 |
if (!isInPresentationMode) { |
| 12491 |
pdfViewer.currentScaleValue = value; |
| 12492 |
} |
| 12493 |
break; |
| 12494 |
case "SaveAs": |
| 12495 |
this.#eventBus.dispatch("download", { |
| 12496 |
source: this |
| 12497 |
}); |
| 12498 |
break; |
| 12499 |
case "FirstPage": |
| 12500 |
pdfViewer.currentPageNumber = 1; |
| 12501 |
break; |
| 12502 |
case "LastPage": |
| 12503 |
pdfViewer.currentPageNumber = pdfViewer.pagesCount; |
| 12504 |
break; |
| 12505 |
case "NextPage": |
| 12506 |
pdfViewer.nextPage(); |
| 12507 |
break; |
| 12508 |
case "PrevPage": |
| 12509 |
pdfViewer.previousPage(); |
| 12510 |
break; |
| 12511 |
case "ZoomViewIn": |
| 12512 |
if (!isInPresentationMode) { |
| 12513 |
pdfViewer.increaseScale(); |
| 12514 |
} |
| 12515 |
break; |
| 12516 |
case "ZoomViewOut": |
| 12517 |
if (!isInPresentationMode) { |
| 12518 |
pdfViewer.decreaseScale(); |
| 12519 |
} |
| 12520 |
break; |
| 12521 |
case "WillPrintFinished": |
| 12522 |
this.#willPrintCapability?.resolve(); |
| 12523 |
this.#willPrintCapability = null; |
| 12524 |
break; |
| 12525 |
} |
| 12526 |
return; |
| 12527 |
} |
| 12528 |
if (isInPresentationMode && detail.focus) { |
| 12529 |
return; |
| 12530 |
} |
| 12531 |
delete detail.id; |
| 12532 |
delete detail.siblings; |
| 12533 |
const ids = siblings ? [id, ...siblings] : [id]; |
| 12534 |
for (const elementId of ids) { |
| 12535 |
const element = document.querySelector(`[data-element-id="${elementId}"]`); |
| 12536 |
if (element) { |
| 12537 |
element.dispatchEvent(new CustomEvent("updatefromsandbox", { |
| 12538 |
detail |
| 12539 |
})); |
| 12540 |
} else { |
| 12541 |
this.#pdfDocument?.annotationStorage.setValue(elementId, detail); |
| 12542 |
} |
| 12543 |
} |
| 12544 |
} |
| 12545 |
async #dispatchPageOpen(pageNumber, initialize = false) { |
| 12546 |
const pdfDocument = this.#pdfDocument, |
| 12547 |
visitedPages = this._visitedPages; |
| 12548 |
if (initialize) { |
| 12549 |
this.#closeCapability = Promise.withResolvers(); |
| 12550 |
} |
| 12551 |
if (!this.#closeCapability) { |
| 12552 |
return; |
| 12553 |
} |
| 12554 |
const pageView = this.#pdfViewer.getPageView(pageNumber - 1); |
| 12555 |
if (pageView?.renderingState !== RenderingStates.FINISHED) { |
| 12556 |
this._pageOpenPending.add(pageNumber); |
| 12557 |
return; |
| 12558 |
} |
| 12559 |
this._pageOpenPending.delete(pageNumber); |
| 12560 |
const actionsPromise = (async () => { |
| 12561 |
const actions = await (!visitedPages.has(pageNumber) ? pageView.pdfPage?.getJSActions() : null); |
| 12562 |
if (pdfDocument !== this.#pdfDocument) { |
| 12563 |
return; |
| 12564 |
} |
| 12565 |
await this.#scripting?.dispatchEventInSandbox({ |
| 12566 |
id: "page", |
| 12567 |
name: "PageOpen", |
| 12568 |
pageNumber, |
| 12569 |
actions |
| 12570 |
}); |
| 12571 |
})(); |
| 12572 |
visitedPages.set(pageNumber, actionsPromise); |
| 12573 |
} |
| 12574 |
async #dispatchPageClose(pageNumber) { |
| 12575 |
const pdfDocument = this.#pdfDocument, |
| 12576 |
visitedPages = this._visitedPages; |
| 12577 |
if (!this.#closeCapability) { |
| 12578 |
return; |
| 12579 |
} |
| 12580 |
if (this._pageOpenPending.has(pageNumber)) { |
| 12581 |
return; |
| 12582 |
} |
| 12583 |
const actionsPromise = visitedPages.get(pageNumber); |
| 12584 |
if (!actionsPromise) { |
| 12585 |
return; |
| 12586 |
} |
| 12587 |
visitedPages.set(pageNumber, null); |
| 12588 |
await actionsPromise; |
| 12589 |
if (pdfDocument !== this.#pdfDocument) { |
| 12590 |
return; |
| 12591 |
} |
| 12592 |
await this.#scripting?.dispatchEventInSandbox({ |
| 12593 |
id: "page", |
| 12594 |
name: "PageClose", |
| 12595 |
pageNumber |
| 12596 |
}); |
| 12597 |
} |
| 12598 |
#initScripting() { |
| 12599 |
this.#destroyCapability = Promise.withResolvers(); |
| 12600 |
if (this.#scripting) { |
| 12601 |
throw new Error("#initScripting: Scripting already exists."); |
| 12602 |
} |
| 12603 |
return this.#externalServices.createScripting(); |
| 12604 |
} |
| 12605 |
async #destroyScripting() { |
| 12606 |
if (!this.#scripting) { |
| 12607 |
this.#pdfDocument = null; |
| 12608 |
this.#destroyCapability?.resolve(); |
| 12609 |
return; |
| 12610 |
} |
| 12611 |
if (this.#closeCapability) { |
| 12612 |
await Promise.race([this.#closeCapability.promise, new Promise(resolve => { |
| 12613 |
setTimeout(resolve, 1000); |
| 12614 |
})]).catch(() => {}); |
| 12615 |
this.#closeCapability = null; |
| 12616 |
} |
| 12617 |
this.#pdfDocument = null; |
| 12618 |
try { |
| 12619 |
await this.#scripting.destroySandbox(); |
| 12620 |
} catch {} |
| 12621 |
this.#willPrintCapability?.reject(new Error("Scripting destroyed.")); |
| 12622 |
this.#willPrintCapability = null; |
| 12623 |
this.#eventAbortController?.abort(); |
| 12624 |
this.#eventAbortController = null; |
| 12625 |
this._pageOpenPending.clear(); |
| 12626 |
this._visitedPages.clear(); |
| 12627 |
this.#scripting = null; |
| 12628 |
this.#ready = false; |
| 12629 |
this.#destroyCapability?.resolve(); |
| 12630 |
} |
| 12631 |
} |
| 12632 |
|
| 12633 |
;// ./web/pdf_sidebar.js |
| 12634 |
|
| 12635 |
const SIDEBAR_WIDTH_VAR = "--sidebar-width"; |
| 12636 |
const SIDEBAR_MIN_WIDTH = 200; |
| 12637 |
const SIDEBAR_RESIZING_CLASS = "sidebarResizing"; |
| 12638 |
const UI_NOTIFICATION_CLASS = "pdfSidebarNotification"; |
| 12639 |
class PDFSidebar { |
| 12640 |
#isRTL = false; |
| 12641 |
#mouseAC = null; |
| 12642 |
#outerContainerWidth = null; |
| 12643 |
#width = null; |
| 12644 |
constructor({ |
| 12645 |
elements, |
| 12646 |
eventBus, |
| 12647 |
l10n |
| 12648 |
}) { |
| 12649 |
this.isOpen = false; |
| 12650 |
this.active = SidebarView.THUMBS; |
| 12651 |
this.isInitialViewSet = false; |
| 12652 |
this.isInitialEventDispatched = false; |
| 12653 |
this.onToggled = null; |
| 12654 |
this.onUpdateThumbnails = null; |
| 12655 |
this.outerContainer = elements.outerContainer; |
| 12656 |
this.sidebarContainer = elements.sidebarContainer; |
| 12657 |
this.toggleButton = elements.toggleButton; |
| 12658 |
this.resizer = elements.resizer; |
| 12659 |
this.thumbnailButton = elements.thumbnailButton; |
| 12660 |
this.outlineButton = elements.outlineButton; |
| 12661 |
this.attachmentsButton = elements.attachmentsButton; |
| 12662 |
this.layersButton = elements.layersButton; |
| 12663 |
this.thumbnailView = elements.thumbnailView; |
| 12664 |
this.outlineView = elements.outlineView; |
| 12665 |
this.attachmentsView = elements.attachmentsView; |
| 12666 |
this.layersView = elements.layersView; |
| 12667 |
this._currentOutlineItemButton = elements.currentOutlineItemButton; |
| 12668 |
this.eventBus = eventBus; |
| 12669 |
this.#isRTL = l10n.getDirection() === "rtl"; |
| 12670 |
this.#addEventListeners(); |
| 12671 |
} |
| 12672 |
reset() { |
| 12673 |
this.isInitialViewSet = false; |
| 12674 |
this.isInitialEventDispatched = false; |
| 12675 |
this.#hideUINotification(true); |
| 12676 |
this.switchView(SidebarView.THUMBS); |
| 12677 |
this.outlineButton.disabled = false; |
| 12678 |
this.attachmentsButton.disabled = false; |
| 12679 |
this.layersButton.disabled = false; |
| 12680 |
this._currentOutlineItemButton.disabled = true; |
| 12681 |
} |
| 12682 |
get visibleView() { |
| 12683 |
return this.isOpen ? this.active : SidebarView.NONE; |
| 12684 |
} |
| 12685 |
setInitialView(view = SidebarView.NONE) { |
| 12686 |
if (this.isInitialViewSet) { |
| 12687 |
return; |
| 12688 |
} |
| 12689 |
this.isInitialViewSet = true; |
| 12690 |
if (view === SidebarView.NONE || view === SidebarView.UNKNOWN) { |
| 12691 |
this.#dispatchEvent(); |
| 12692 |
return; |
| 12693 |
} |
| 12694 |
this.switchView(view, true); |
| 12695 |
if (!this.isInitialEventDispatched) { |
| 12696 |
this.#dispatchEvent(); |
| 12697 |
} |
| 12698 |
} |
| 12699 |
switchView(view, forceOpen = false) { |
| 12700 |
const isViewChanged = view !== this.active; |
| 12701 |
let forceRendering = false; |
| 12702 |
switch (view) { |
| 12703 |
case SidebarView.NONE: |
| 12704 |
if (this.isOpen) { |
| 12705 |
this.close(); |
| 12706 |
} |
| 12707 |
return; |
| 12708 |
case SidebarView.THUMBS: |
| 12709 |
if (this.isOpen && isViewChanged) { |
| 12710 |
forceRendering = true; |
| 12711 |
} |
| 12712 |
break; |
| 12713 |
case SidebarView.OUTLINE: |
| 12714 |
if (this.outlineButton.disabled) { |
| 12715 |
return; |
| 12716 |
} |
| 12717 |
break; |
| 12718 |
case SidebarView.ATTACHMENTS: |
| 12719 |
if (this.attachmentsButton.disabled) { |
| 12720 |
return; |
| 12721 |
} |
| 12722 |
break; |
| 12723 |
case SidebarView.LAYERS: |
| 12724 |
if (this.layersButton.disabled) { |
| 12725 |
return; |
| 12726 |
} |
| 12727 |
break; |
| 12728 |
default: |
| 12729 |
console.error(`PDFSidebar.switchView: "${view}" is not a valid view.`); |
| 12730 |
return; |
| 12731 |
} |
| 12732 |
this.active = view; |
| 12733 |
toggleCheckedBtn(this.thumbnailButton, view === SidebarView.THUMBS, this.thumbnailView); |
| 12734 |
toggleCheckedBtn(this.outlineButton, view === SidebarView.OUTLINE, this.outlineView); |
| 12735 |
toggleCheckedBtn(this.attachmentsButton, view === SidebarView.ATTACHMENTS, this.attachmentsView); |
| 12736 |
toggleCheckedBtn(this.layersButton, view === SidebarView.LAYERS, this.layersView); |
| 12737 |
if (forceOpen && !this.isOpen) { |
| 12738 |
this.open(); |
| 12739 |
return; |
| 12740 |
} |
| 12741 |
if (forceRendering) { |
| 12742 |
this.onUpdateThumbnails(); |
| 12743 |
this.onToggled(); |
| 12744 |
} |
| 12745 |
if (isViewChanged) { |
| 12746 |
this.#dispatchEvent(); |
| 12747 |
} |
| 12748 |
} |
| 12749 |
open() { |
| 12750 |
if (this.isOpen) { |
| 12751 |
return; |
| 12752 |
} |
| 12753 |
this.isOpen = true; |
| 12754 |
toggleExpandedBtn(this.toggleButton, true); |
| 12755 |
this.outerContainer.classList.add("sidebarMoving", "sidebarOpen"); |
| 12756 |
if (this.active === SidebarView.THUMBS) { |
| 12757 |
this.onUpdateThumbnails(); |
| 12758 |
} |
| 12759 |
this.onToggled(); |
| 12760 |
this.#dispatchEvent(); |
| 12761 |
this.#hideUINotification(); |
| 12762 |
} |
| 12763 |
close(evt = null) { |
| 12764 |
if (!this.isOpen) { |
| 12765 |
return; |
| 12766 |
} |
| 12767 |
this.isOpen = false; |
| 12768 |
toggleExpandedBtn(this.toggleButton, false); |
| 12769 |
this.outerContainer.classList.add("sidebarMoving"); |
| 12770 |
this.outerContainer.classList.remove("sidebarOpen"); |
| 12771 |
this.onToggled(); |
| 12772 |
this.#dispatchEvent(); |
| 12773 |
if (evt?.detail > 0) { |
| 12774 |
this.toggleButton.blur(); |
| 12775 |
} |
| 12776 |
} |
| 12777 |
toggle(evt = null) { |
| 12778 |
if (this.isOpen) { |
| 12779 |
this.close(evt); |
| 12780 |
} else { |
| 12781 |
this.open(); |
| 12782 |
} |
| 12783 |
} |
| 12784 |
#dispatchEvent() { |
| 12785 |
if (this.isInitialViewSet) { |
| 12786 |
this.isInitialEventDispatched ||= true; |
| 12787 |
} |
| 12788 |
this.eventBus.dispatch("sidebarviewchanged", { |
| 12789 |
source: this, |
| 12790 |
view: this.visibleView |
| 12791 |
}); |
| 12792 |
} |
| 12793 |
#showUINotification() { |
| 12794 |
this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-notification-button"); |
| 12795 |
if (!this.isOpen) { |
| 12796 |
this.toggleButton.classList.add(UI_NOTIFICATION_CLASS); |
| 12797 |
} |
| 12798 |
} |
| 12799 |
#hideUINotification(reset = false) { |
| 12800 |
if (this.isOpen || reset) { |
| 12801 |
this.toggleButton.classList.remove(UI_NOTIFICATION_CLASS); |
| 12802 |
} |
| 12803 |
if (reset) { |
| 12804 |
this.toggleButton.setAttribute("data-l10n-id", "pdfjs-toggle-sidebar-button"); |
| 12805 |
} |
| 12806 |
} |
| 12807 |
#addEventListeners() { |
| 12808 |
const { |
| 12809 |
eventBus, |
| 12810 |
outerContainer |
| 12811 |
} = this; |
| 12812 |
this.sidebarContainer.addEventListener("transitionend", evt => { |
| 12813 |
if (evt.target === this.sidebarContainer) { |
| 12814 |
outerContainer.classList.remove("sidebarMoving"); |
| 12815 |
eventBus.dispatch("resize", { |
| 12816 |
source: this |
| 12817 |
}); |
| 12818 |
} |
| 12819 |
}); |
| 12820 |
this.toggleButton.addEventListener("click", evt => { |
| 12821 |
this.toggle(evt); |
| 12822 |
}); |
| 12823 |
this.thumbnailButton.addEventListener("click", () => { |
| 12824 |
this.switchView(SidebarView.THUMBS); |
| 12825 |
}); |
| 12826 |
this.outlineButton.addEventListener("click", () => { |
| 12827 |
this.switchView(SidebarView.OUTLINE); |
| 12828 |
}); |
| 12829 |
this.outlineButton.addEventListener("dblclick", () => { |
| 12830 |
eventBus.dispatch("toggleoutlinetree", { |
| 12831 |
source: this |
| 12832 |
}); |
| 12833 |
}); |
| 12834 |
this.attachmentsButton.addEventListener("click", () => { |
| 12835 |
this.switchView(SidebarView.ATTACHMENTS); |
| 12836 |
}); |
| 12837 |
this.layersButton.addEventListener("click", () => { |
| 12838 |
this.switchView(SidebarView.LAYERS); |
| 12839 |
}); |
| 12840 |
this.layersButton.addEventListener("dblclick", () => { |
| 12841 |
eventBus.dispatch("resetlayers", { |
| 12842 |
source: this |
| 12843 |
}); |
| 12844 |
}); |
| 12845 |
this._currentOutlineItemButton.addEventListener("click", () => { |
| 12846 |
eventBus.dispatch("currentoutlineitem", { |
| 12847 |
source: this |
| 12848 |
}); |
| 12849 |
}); |
| 12850 |
const onTreeLoaded = (count, button, view) => { |
| 12851 |
button.disabled = !count; |
| 12852 |
if (count) { |
| 12853 |
this.#showUINotification(); |
| 12854 |
} else if (this.active === view) { |
| 12855 |
this.switchView(SidebarView.THUMBS); |
| 12856 |
} |
| 12857 |
}; |
| 12858 |
eventBus._on("outlineloaded", evt => { |
| 12859 |
onTreeLoaded(evt.outlineCount, this.outlineButton, SidebarView.OUTLINE); |
| 12860 |
evt.currentOutlineItemPromise.then(enabled => { |
| 12861 |
if (!this.isInitialViewSet) { |
| 12862 |
return; |
| 12863 |
} |
| 12864 |
this._currentOutlineItemButton.disabled = !enabled; |
| 12865 |
}); |
| 12866 |
}); |
| 12867 |
eventBus._on("attachmentsloaded", evt => { |
| 12868 |
onTreeLoaded(evt.attachmentsCount, this.attachmentsButton, SidebarView.ATTACHMENTS); |
| 12869 |
}); |
| 12870 |
eventBus._on("layersloaded", evt => { |
| 12871 |
onTreeLoaded(evt.layersCount, this.layersButton, SidebarView.LAYERS); |
| 12872 |
}); |
| 12873 |
eventBus._on("presentationmodechanged", evt => { |
| 12874 |
if (evt.state === PresentationModeState.NORMAL && this.visibleView === SidebarView.THUMBS) { |
| 12875 |
this.onUpdateThumbnails(); |
| 12876 |
} |
| 12877 |
}); |
| 12878 |
this.resizer.addEventListener("mousedown", evt => { |
| 12879 |
if (evt.button !== 0) { |
| 12880 |
return; |
| 12881 |
} |
| 12882 |
outerContainer.classList.add(SIDEBAR_RESIZING_CLASS); |
| 12883 |
this.#mouseAC = new AbortController(); |
| 12884 |
const opts = { |
| 12885 |
signal: this.#mouseAC.signal |
| 12886 |
}; |
| 12887 |
window.addEventListener("mousemove", this.#mouseMove.bind(this), opts); |
| 12888 |
window.addEventListener("mouseup", this.#mouseUp.bind(this), opts); |
| 12889 |
window.addEventListener("blur", this.#mouseUp.bind(this), opts); |
| 12890 |
}); |
| 12891 |
eventBus._on("resize", evt => { |
| 12892 |
if (evt.source !== window) { |
| 12893 |
return; |
| 12894 |
} |
| 12895 |
this.#outerContainerWidth = null; |
| 12896 |
if (!this.#width) { |
| 12897 |
return; |
| 12898 |
} |
| 12899 |
if (!this.isOpen) { |
| 12900 |
this.#updateWidth(this.#width); |
| 12901 |
return; |
| 12902 |
} |
| 12903 |
outerContainer.classList.add(SIDEBAR_RESIZING_CLASS); |
| 12904 |
const updated = this.#updateWidth(this.#width); |
| 12905 |
Promise.resolve().then(() => { |
| 12906 |
outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS); |
| 12907 |
if (updated) { |
| 12908 |
eventBus.dispatch("resize", { |
| 12909 |
source: this |
| 12910 |
}); |
| 12911 |
} |
| 12912 |
}); |
| 12913 |
}); |
| 12914 |
} |
| 12915 |
get outerContainerWidth() { |
| 12916 |
return this.#outerContainerWidth ||= this.outerContainer.clientWidth; |
| 12917 |
} |
| 12918 |
#updateWidth(width = 0) { |
| 12919 |
const maxWidth = Math.floor(this.outerContainerWidth / 2); |
| 12920 |
if (width > maxWidth) { |
| 12921 |
width = maxWidth; |
| 12922 |
} |
| 12923 |
if (width < SIDEBAR_MIN_WIDTH) { |
| 12924 |
width = SIDEBAR_MIN_WIDTH; |
| 12925 |
} |
| 12926 |
if (width === this.#width) { |
| 12927 |
return false; |
| 12928 |
} |
| 12929 |
this.#width = width; |
| 12930 |
docStyle.setProperty(SIDEBAR_WIDTH_VAR, `${width}px`); |
| 12931 |
return true; |
| 12932 |
} |
| 12933 |
#mouseMove(evt) { |
| 12934 |
let width = evt.clientX; |
| 12935 |
if (this.#isRTL) { |
| 12936 |
width = this.outerContainerWidth - width; |
| 12937 |
} |
| 12938 |
this.#updateWidth(width); |
| 12939 |
} |
| 12940 |
#mouseUp(evt) { |
| 12941 |
this.outerContainer.classList.remove(SIDEBAR_RESIZING_CLASS); |
| 12942 |
this.eventBus.dispatch("resize", { |
| 12943 |
source: this |
| 12944 |
}); |
| 12945 |
this.#mouseAC?.abort(); |
| 12946 |
this.#mouseAC = null; |
| 12947 |
} |
| 12948 |
} |
| 12949 |
|
| 12950 |
;// ./web/pdf_thumbnail_view.js |
| 12951 |
|
| 12952 |
|
| 12953 |
|
| 12954 |
const DRAW_UPSCALE_FACTOR = 2; |
| 12955 |
const MAX_NUM_SCALING_STEPS = 3; |
| 12956 |
const THUMBNAIL_WIDTH = 98; |
| 12957 |
function zeroCanvas(c) { |
| 12958 |
c.width = 0; |
| 12959 |
c.height = 0; |
| 12960 |
} |
| 12961 |
class TempImageFactory { |
| 12962 |
static #tempCanvas = null; |
| 12963 |
static getCanvas(width, height) { |
| 12964 |
const tempCanvas = this.#tempCanvas ||= document.createElement("canvas"); |
| 12965 |
tempCanvas.width = width; |
| 12966 |
tempCanvas.height = height; |
| 12967 |
const ctx = tempCanvas.getContext("2d", { |
| 12968 |
alpha: false |
| 12969 |
}); |
| 12970 |
ctx.save(); |
| 12971 |
ctx.fillStyle = "rgb(255, 255, 255)"; |
| 12972 |
ctx.fillRect(0, 0, width, height); |
| 12973 |
ctx.restore(); |
| 12974 |
return [tempCanvas, tempCanvas.getContext("2d")]; |
| 12975 |
} |
| 12976 |
static destroyCanvas() { |
| 12977 |
if (this.#tempCanvas) { |
| 12978 |
zeroCanvas(this.#tempCanvas); |
| 12979 |
} |
| 12980 |
this.#tempCanvas = null; |
| 12981 |
} |
| 12982 |
} |
| 12983 |
class PDFThumbnailView { |
| 12984 |
constructor({ |
| 12985 |
container, |
| 12986 |
eventBus, |
| 12987 |
id, |
| 12988 |
defaultViewport, |
| 12989 |
optionalContentConfigPromise, |
| 12990 |
linkService, |
| 12991 |
renderingQueue, |
| 12992 |
maxCanvasPixels, |
| 12993 |
maxCanvasDim, |
| 12994 |
pageColors, |
| 12995 |
enableHWA |
| 12996 |
}) { |
| 12997 |
this.id = id; |
| 12998 |
this.renderingId = "thumbnail" + id; |
| 12999 |
this.pageLabel = null; |
| 13000 |
this.pdfPage = null; |
| 13001 |
this.rotation = 0; |
| 13002 |
this.viewport = defaultViewport; |
| 13003 |
this.pdfPageRotate = defaultViewport.rotation; |
| 13004 |
this._optionalContentConfigPromise = optionalContentConfigPromise || null; |
| 13005 |
this.maxCanvasPixels = maxCanvasPixels ?? AppOptions.get("maxCanvasPixels"); |
| 13006 |
this.maxCanvasDim = maxCanvasDim || AppOptions.get("maxCanvasDim"); |
| 13007 |
this.pageColors = pageColors || null; |
| 13008 |
this.enableHWA = enableHWA || false; |
| 13009 |
this.eventBus = eventBus; |
| 13010 |
this.linkService = linkService; |
| 13011 |
this.renderingQueue = renderingQueue; |
| 13012 |
this.renderTask = null; |
| 13013 |
this.renderingState = RenderingStates.INITIAL; |
| 13014 |
this.resume = null; |
| 13015 |
const anchor = document.createElement("a"); |
| 13016 |
anchor.href = linkService.getAnchorUrl("#page=" + id); |
| 13017 |
anchor.setAttribute("data-l10n-id", "pdfjs-thumb-page-title"); |
| 13018 |
anchor.setAttribute("data-l10n-args", this.#pageL10nArgs); |
| 13019 |
anchor.onclick = function () { |
| 13020 |
linkService.goToPage(id); |
| 13021 |
return false; |
| 13022 |
}; |
| 13023 |
this.anchor = anchor; |
| 13024 |
const div = document.createElement("div"); |
| 13025 |
div.className = "thumbnail"; |
| 13026 |
div.setAttribute("data-page-number", this.id); |
| 13027 |
this.div = div; |
| 13028 |
this.#updateDims(); |
| 13029 |
const img = document.createElement("div"); |
| 13030 |
img.className = "thumbnailImage"; |
| 13031 |
this._placeholderImg = img; |
| 13032 |
div.append(img); |
| 13033 |
anchor.append(div); |
| 13034 |
container.append(anchor); |
| 13035 |
} |
| 13036 |
#updateDims() { |
| 13037 |
const { |
| 13038 |
width, |
| 13039 |
height |
| 13040 |
} = this.viewport; |
| 13041 |
const ratio = width / height; |
| 13042 |
this.canvasWidth = THUMBNAIL_WIDTH; |
| 13043 |
this.canvasHeight = this.canvasWidth / ratio | 0; |
| 13044 |
this.scale = this.canvasWidth / width; |
| 13045 |
const { |
| 13046 |
style |
| 13047 |
} = this.div; |
| 13048 |
style.setProperty("--thumbnail-width", `${this.canvasWidth}px`); |
| 13049 |
style.setProperty("--thumbnail-height", `${this.canvasHeight}px`); |
| 13050 |
} |
| 13051 |
setPdfPage(pdfPage) { |
| 13052 |
this.pdfPage = pdfPage; |
| 13053 |
this.pdfPageRotate = pdfPage.rotate; |
| 13054 |
const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 13055 |
this.viewport = pdfPage.getViewport({ |
| 13056 |
scale: 1, |
| 13057 |
rotation: totalRotation |
| 13058 |
}); |
| 13059 |
this.reset(); |
| 13060 |
} |
| 13061 |
reset() { |
| 13062 |
this.cancelRendering(); |
| 13063 |
this.renderingState = RenderingStates.INITIAL; |
| 13064 |
this.div.removeAttribute("data-loaded"); |
| 13065 |
this.image?.replaceWith(this._placeholderImg); |
| 13066 |
this.#updateDims(); |
| 13067 |
if (this.image) { |
| 13068 |
this.image.removeAttribute("src"); |
| 13069 |
delete this.image; |
| 13070 |
} |
| 13071 |
} |
| 13072 |
update({ |
| 13073 |
rotation = null |
| 13074 |
}) { |
| 13075 |
if (typeof rotation === "number") { |
| 13076 |
this.rotation = rotation; |
| 13077 |
} |
| 13078 |
const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 13079 |
this.viewport = this.viewport.clone({ |
| 13080 |
scale: 1, |
| 13081 |
rotation: totalRotation |
| 13082 |
}); |
| 13083 |
this.reset(); |
| 13084 |
} |
| 13085 |
cancelRendering() { |
| 13086 |
if (this.renderTask) { |
| 13087 |
this.renderTask.cancel(); |
| 13088 |
this.renderTask = null; |
| 13089 |
} |
| 13090 |
this.resume = null; |
| 13091 |
} |
| 13092 |
#getPageDrawContext(upscaleFactor = 1, enableHWA = this.enableHWA) { |
| 13093 |
const canvas = document.createElement("canvas"); |
| 13094 |
const ctx = canvas.getContext("2d", { |
| 13095 |
alpha: false, |
| 13096 |
willReadFrequently: !enableHWA |
| 13097 |
}); |
| 13098 |
const outputScale = new OutputScale(); |
| 13099 |
const width = upscaleFactor * this.canvasWidth, |
| 13100 |
height = upscaleFactor * this.canvasHeight; |
| 13101 |
outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim); |
| 13102 |
canvas.width = width * outputScale.sx | 0; |
| 13103 |
canvas.height = height * outputScale.sy | 0; |
| 13104 |
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null; |
| 13105 |
return { |
| 13106 |
ctx, |
| 13107 |
canvas, |
| 13108 |
transform |
| 13109 |
}; |
| 13110 |
} |
| 13111 |
#convertCanvasToImage(canvas) { |
| 13112 |
if (this.renderingState !== RenderingStates.FINISHED) { |
| 13113 |
throw new Error("#convertCanvasToImage: Rendering has not finished."); |
| 13114 |
} |
| 13115 |
const reducedCanvas = this.#reduceImage(canvas); |
| 13116 |
const image = document.createElement("img"); |
| 13117 |
image.className = "thumbnailImage"; |
| 13118 |
image.setAttribute("data-l10n-id", "pdfjs-thumb-page-canvas"); |
| 13119 |
image.setAttribute("data-l10n-args", this.#pageL10nArgs); |
| 13120 |
image.src = reducedCanvas.toDataURL(); |
| 13121 |
this.image = image; |
| 13122 |
this.div.setAttribute("data-loaded", true); |
| 13123 |
this._placeholderImg.replaceWith(image); |
| 13124 |
zeroCanvas(reducedCanvas); |
| 13125 |
} |
| 13126 |
async draw() { |
| 13127 |
if (this.renderingState !== RenderingStates.INITIAL) { |
| 13128 |
console.error("Must be in new state before drawing"); |
| 13129 |
return; |
| 13130 |
} |
| 13131 |
const { |
| 13132 |
pageColors, |
| 13133 |
pdfPage |
| 13134 |
} = this; |
| 13135 |
if (!pdfPage) { |
| 13136 |
this.renderingState = RenderingStates.FINISHED; |
| 13137 |
throw new Error("pdfPage is not loaded"); |
| 13138 |
} |
| 13139 |
this.renderingState = RenderingStates.RUNNING; |
| 13140 |
const { |
| 13141 |
ctx, |
| 13142 |
canvas, |
| 13143 |
transform |
| 13144 |
} = this.#getPageDrawContext(DRAW_UPSCALE_FACTOR); |
| 13145 |
const drawViewport = this.viewport.clone({ |
| 13146 |
scale: DRAW_UPSCALE_FACTOR * this.scale |
| 13147 |
}); |
| 13148 |
const renderContinueCallback = cont => { |
| 13149 |
if (!this.renderingQueue.isHighestPriority(this)) { |
| 13150 |
this.renderingState = RenderingStates.PAUSED; |
| 13151 |
this.resume = () => { |
| 13152 |
this.renderingState = RenderingStates.RUNNING; |
| 13153 |
cont(); |
| 13154 |
}; |
| 13155 |
return; |
| 13156 |
} |
| 13157 |
cont(); |
| 13158 |
}; |
| 13159 |
const renderContext = { |
| 13160 |
canvasContext: ctx, |
| 13161 |
transform, |
| 13162 |
viewport: drawViewport, |
| 13163 |
optionalContentConfigPromise: this._optionalContentConfigPromise, |
| 13164 |
pageColors |
| 13165 |
}; |
| 13166 |
const renderTask = this.renderTask = pdfPage.render(renderContext); |
| 13167 |
renderTask.onContinue = renderContinueCallback; |
| 13168 |
let error = null; |
| 13169 |
try { |
| 13170 |
await renderTask.promise; |
| 13171 |
} catch (e) { |
| 13172 |
if (e instanceof RenderingCancelledException) { |
| 13173 |
zeroCanvas(canvas); |
| 13174 |
return; |
| 13175 |
} |
| 13176 |
error = e; |
| 13177 |
} finally { |
| 13178 |
if (renderTask === this.renderTask) { |
| 13179 |
this.renderTask = null; |
| 13180 |
} |
| 13181 |
} |
| 13182 |
this.renderingState = RenderingStates.FINISHED; |
| 13183 |
this.#convertCanvasToImage(canvas); |
| 13184 |
zeroCanvas(canvas); |
| 13185 |
this.eventBus.dispatch("thumbnailrendered", { |
| 13186 |
source: this, |
| 13187 |
pageNumber: this.id, |
| 13188 |
pdfPage |
| 13189 |
}); |
| 13190 |
if (error) { |
| 13191 |
throw error; |
| 13192 |
} |
| 13193 |
} |
| 13194 |
setImage(pageView) { |
| 13195 |
if (this.renderingState !== RenderingStates.INITIAL) { |
| 13196 |
return; |
| 13197 |
} |
| 13198 |
const { |
| 13199 |
thumbnailCanvas: canvas, |
| 13200 |
pdfPage, |
| 13201 |
scale |
| 13202 |
} = pageView; |
| 13203 |
if (!canvas) { |
| 13204 |
return; |
| 13205 |
} |
| 13206 |
if (!this.pdfPage) { |
| 13207 |
this.setPdfPage(pdfPage); |
| 13208 |
} |
| 13209 |
if (scale < this.scale) { |
| 13210 |
return; |
| 13211 |
} |
| 13212 |
this.renderingState = RenderingStates.FINISHED; |
| 13213 |
this.#convertCanvasToImage(canvas); |
| 13214 |
} |
| 13215 |
#getReducedImageDims(canvas) { |
| 13216 |
const width = canvas.width << MAX_NUM_SCALING_STEPS, |
| 13217 |
height = canvas.height << MAX_NUM_SCALING_STEPS; |
| 13218 |
const outputScale = new OutputScale(); |
| 13219 |
outputScale.sx = outputScale.sy = 1; |
| 13220 |
outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim); |
| 13221 |
return [width * outputScale.sx | 0, height * outputScale.sy | 0]; |
| 13222 |
} |
| 13223 |
#reduceImage(img) { |
| 13224 |
const { |
| 13225 |
ctx, |
| 13226 |
canvas |
| 13227 |
} = this.#getPageDrawContext(1, true); |
| 13228 |
if (img.width <= 2 * canvas.width) { |
| 13229 |
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height); |
| 13230 |
return canvas; |
| 13231 |
} |
| 13232 |
let [reducedWidth, reducedHeight] = this.#getReducedImageDims(canvas); |
| 13233 |
const [reducedImage, reducedImageCtx] = TempImageFactory.getCanvas(reducedWidth, reducedHeight); |
| 13234 |
while (reducedWidth > img.width || reducedHeight > img.height) { |
| 13235 |
reducedWidth >>= 1; |
| 13236 |
reducedHeight >>= 1; |
| 13237 |
} |
| 13238 |
reducedImageCtx.drawImage(img, 0, 0, img.width, img.height, 0, 0, reducedWidth, reducedHeight); |
| 13239 |
while (reducedWidth > 2 * canvas.width) { |
| 13240 |
reducedImageCtx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, reducedWidth >> 1, reducedHeight >> 1); |
| 13241 |
reducedWidth >>= 1; |
| 13242 |
reducedHeight >>= 1; |
| 13243 |
} |
| 13244 |
ctx.drawImage(reducedImage, 0, 0, reducedWidth, reducedHeight, 0, 0, canvas.width, canvas.height); |
| 13245 |
return canvas; |
| 13246 |
} |
| 13247 |
get #pageL10nArgs() { |
| 13248 |
return JSON.stringify({ |
| 13249 |
page: this.pageLabel ?? this.id |
| 13250 |
}); |
| 13251 |
} |
| 13252 |
setPageLabel(label) { |
| 13253 |
this.pageLabel = typeof label === "string" ? label : null; |
| 13254 |
this.anchor.setAttribute("data-l10n-args", this.#pageL10nArgs); |
| 13255 |
if (this.renderingState !== RenderingStates.FINISHED) { |
| 13256 |
return; |
| 13257 |
} |
| 13258 |
this.image?.setAttribute("data-l10n-args", this.#pageL10nArgs); |
| 13259 |
} |
| 13260 |
} |
| 13261 |
|
| 13262 |
;// ./web/pdf_thumbnail_viewer.js |
| 13263 |
|
| 13264 |
|
| 13265 |
|
| 13266 |
const THUMBNAIL_SCROLL_MARGIN = -19; |
| 13267 |
const THUMBNAIL_SELECTED_CLASS = "selected"; |
| 13268 |
class PDFThumbnailViewer { |
| 13269 |
constructor({ |
| 13270 |
container, |
| 13271 |
eventBus, |
| 13272 |
linkService, |
| 13273 |
renderingQueue, |
| 13274 |
maxCanvasPixels, |
| 13275 |
maxCanvasDim, |
| 13276 |
pageColors, |
| 13277 |
abortSignal, |
| 13278 |
enableHWA |
| 13279 |
}) { |
| 13280 |
this.container = container; |
| 13281 |
this.eventBus = eventBus; |
| 13282 |
this.linkService = linkService; |
| 13283 |
this.renderingQueue = renderingQueue; |
| 13284 |
this.maxCanvasPixels = maxCanvasPixels; |
| 13285 |
this.maxCanvasDim = maxCanvasDim; |
| 13286 |
this.pageColors = pageColors || null; |
| 13287 |
this.enableHWA = enableHWA || false; |
| 13288 |
this.scroll = watchScroll(this.container, this.#scrollUpdated.bind(this), abortSignal); |
| 13289 |
this.#resetView(); |
| 13290 |
} |
| 13291 |
#scrollUpdated() { |
| 13292 |
this.renderingQueue.renderHighestPriority(); |
| 13293 |
} |
| 13294 |
getThumbnail(index) { |
| 13295 |
return this._thumbnails[index]; |
| 13296 |
} |
| 13297 |
#getVisibleThumbs() { |
| 13298 |
return getVisibleElements({ |
| 13299 |
scrollEl: this.container, |
| 13300 |
views: this._thumbnails |
| 13301 |
}); |
| 13302 |
} |
| 13303 |
scrollThumbnailIntoView(pageNumber) { |
| 13304 |
if (!this.pdfDocument) { |
| 13305 |
return; |
| 13306 |
} |
| 13307 |
const thumbnailView = this._thumbnails[pageNumber - 1]; |
| 13308 |
if (!thumbnailView) { |
| 13309 |
console.error('scrollThumbnailIntoView: Invalid "pageNumber" parameter.'); |
| 13310 |
return; |
| 13311 |
} |
| 13312 |
if (pageNumber !== this._currentPageNumber) { |
| 13313 |
const prevThumbnailView = this._thumbnails[this._currentPageNumber - 1]; |
| 13314 |
prevThumbnailView.div.classList.remove(THUMBNAIL_SELECTED_CLASS); |
| 13315 |
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS); |
| 13316 |
} |
| 13317 |
const { |
| 13318 |
first, |
| 13319 |
last, |
| 13320 |
views |
| 13321 |
} = this.#getVisibleThumbs(); |
| 13322 |
if (views.length > 0) { |
| 13323 |
let shouldScroll = false; |
| 13324 |
if (pageNumber <= first.id || pageNumber >= last.id) { |
| 13325 |
shouldScroll = true; |
| 13326 |
} else { |
| 13327 |
for (const { |
| 13328 |
id, |
| 13329 |
percent |
| 13330 |
} of views) { |
| 13331 |
if (id !== pageNumber) { |
| 13332 |
continue; |
| 13333 |
} |
| 13334 |
shouldScroll = percent < 100; |
| 13335 |
break; |
| 13336 |
} |
| 13337 |
} |
| 13338 |
if (shouldScroll) { |
| 13339 |
scrollIntoView(thumbnailView.div, { |
| 13340 |
top: THUMBNAIL_SCROLL_MARGIN |
| 13341 |
}); |
| 13342 |
} |
| 13343 |
} |
| 13344 |
this._currentPageNumber = pageNumber; |
| 13345 |
} |
| 13346 |
get pagesRotation() { |
| 13347 |
return this._pagesRotation; |
| 13348 |
} |
| 13349 |
set pagesRotation(rotation) { |
| 13350 |
if (!isValidRotation(rotation)) { |
| 13351 |
throw new Error("Invalid thumbnails rotation angle."); |
| 13352 |
} |
| 13353 |
if (!this.pdfDocument) { |
| 13354 |
return; |
| 13355 |
} |
| 13356 |
if (this._pagesRotation === rotation) { |
| 13357 |
return; |
| 13358 |
} |
| 13359 |
this._pagesRotation = rotation; |
| 13360 |
const updateArgs = { |
| 13361 |
rotation |
| 13362 |
}; |
| 13363 |
for (const thumbnail of this._thumbnails) { |
| 13364 |
thumbnail.update(updateArgs); |
| 13365 |
} |
| 13366 |
} |
| 13367 |
cleanup() { |
| 13368 |
for (const thumbnail of this._thumbnails) { |
| 13369 |
if (thumbnail.renderingState !== RenderingStates.FINISHED) { |
| 13370 |
thumbnail.reset(); |
| 13371 |
} |
| 13372 |
} |
| 13373 |
TempImageFactory.destroyCanvas(); |
| 13374 |
} |
| 13375 |
#resetView() { |
| 13376 |
this._thumbnails = []; |
| 13377 |
this._currentPageNumber = 1; |
| 13378 |
this._pageLabels = null; |
| 13379 |
this._pagesRotation = 0; |
| 13380 |
this.container.textContent = ""; |
| 13381 |
} |
| 13382 |
setDocument(pdfDocument) { |
| 13383 |
if (this.pdfDocument) { |
| 13384 |
this.#cancelRendering(); |
| 13385 |
this.#resetView(); |
| 13386 |
} |
| 13387 |
this.pdfDocument = pdfDocument; |
| 13388 |
if (!pdfDocument) { |
| 13389 |
return; |
| 13390 |
} |
| 13391 |
const firstPagePromise = pdfDocument.getPage(1); |
| 13392 |
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({ |
| 13393 |
intent: "display" |
| 13394 |
}); |
| 13395 |
firstPagePromise.then(firstPdfPage => { |
| 13396 |
const pagesCount = pdfDocument.numPages; |
| 13397 |
const viewport = firstPdfPage.getViewport({ |
| 13398 |
scale: 1 |
| 13399 |
}); |
| 13400 |
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
| 13401 |
const thumbnail = new PDFThumbnailView({ |
| 13402 |
container: this.container, |
| 13403 |
eventBus: this.eventBus, |
| 13404 |
id: pageNum, |
| 13405 |
defaultViewport: viewport.clone(), |
| 13406 |
optionalContentConfigPromise, |
| 13407 |
linkService: this.linkService, |
| 13408 |
renderingQueue: this.renderingQueue, |
| 13409 |
maxCanvasPixels: this.maxCanvasPixels, |
| 13410 |
maxCanvasDim: this.maxCanvasDim, |
| 13411 |
pageColors: this.pageColors, |
| 13412 |
enableHWA: this.enableHWA |
| 13413 |
}); |
| 13414 |
this._thumbnails.push(thumbnail); |
| 13415 |
} |
| 13416 |
this._thumbnails[0]?.setPdfPage(firstPdfPage); |
| 13417 |
const thumbnailView = this._thumbnails[this._currentPageNumber - 1]; |
| 13418 |
thumbnailView.div.classList.add(THUMBNAIL_SELECTED_CLASS); |
| 13419 |
}).catch(reason => { |
| 13420 |
console.error("Unable to initialize thumbnail viewer", reason); |
| 13421 |
}); |
| 13422 |
} |
| 13423 |
#cancelRendering() { |
| 13424 |
for (const thumbnail of this._thumbnails) { |
| 13425 |
thumbnail.cancelRendering(); |
| 13426 |
} |
| 13427 |
} |
| 13428 |
setPageLabels(labels) { |
| 13429 |
if (!this.pdfDocument) { |
| 13430 |
return; |
| 13431 |
} |
| 13432 |
if (!labels) { |
| 13433 |
this._pageLabels = null; |
| 13434 |
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) { |
| 13435 |
this._pageLabels = null; |
| 13436 |
console.error("PDFThumbnailViewer_setPageLabels: Invalid page labels."); |
| 13437 |
} else { |
| 13438 |
this._pageLabels = labels; |
| 13439 |
} |
| 13440 |
for (let i = 0, ii = this._thumbnails.length; i < ii; i++) { |
| 13441 |
this._thumbnails[i].setPageLabel(this._pageLabels?.[i] ?? null); |
| 13442 |
} |
| 13443 |
} |
| 13444 |
async #ensurePdfPageLoaded(thumbView) { |
| 13445 |
if (thumbView.pdfPage) { |
| 13446 |
return thumbView.pdfPage; |
| 13447 |
} |
| 13448 |
try { |
| 13449 |
const pdfPage = await this.pdfDocument.getPage(thumbView.id); |
| 13450 |
if (!thumbView.pdfPage) { |
| 13451 |
thumbView.setPdfPage(pdfPage); |
| 13452 |
} |
| 13453 |
return pdfPage; |
| 13454 |
} catch (reason) { |
| 13455 |
console.error("Unable to get page for thumb view", reason); |
| 13456 |
return null; |
| 13457 |
} |
| 13458 |
} |
| 13459 |
#getScrollAhead(visible) { |
| 13460 |
if (visible.first?.id === 1) { |
| 13461 |
return true; |
| 13462 |
} else if (visible.last?.id === this._thumbnails.length) { |
| 13463 |
return false; |
| 13464 |
} |
| 13465 |
return this.scroll.down; |
| 13466 |
} |
| 13467 |
forceRendering() { |
| 13468 |
const visibleThumbs = this.#getVisibleThumbs(); |
| 13469 |
const scrollAhead = this.#getScrollAhead(visibleThumbs); |
| 13470 |
const thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, this._thumbnails, scrollAhead, false, true); |
| 13471 |
if (thumbView) { |
| 13472 |
this.#ensurePdfPageLoaded(thumbView).then(() => { |
| 13473 |
this.renderingQueue.renderView(thumbView); |
| 13474 |
}); |
| 13475 |
return true; |
| 13476 |
} |
| 13477 |
return false; |
| 13478 |
} |
| 13479 |
} |
| 13480 |
|
| 13481 |
;// ./web/annotation_editor_layer_builder.js |
| 13482 |
|
| 13483 |
|
| 13484 |
class AnnotationEditorLayerBuilder { |
| 13485 |
#annotationLayer = null; |
| 13486 |
#drawLayer = null; |
| 13487 |
#onAppend = null; |
| 13488 |
#structTreeLayer = null; |
| 13489 |
#textLayer = null; |
| 13490 |
#uiManager; |
| 13491 |
constructor(options) { |
| 13492 |
this.pdfPage = options.pdfPage; |
| 13493 |
this.accessibilityManager = options.accessibilityManager; |
| 13494 |
this.l10n = options.l10n; |
| 13495 |
this.l10n ||= new genericl10n_GenericL10n(); |
| 13496 |
this.annotationEditorLayer = null; |
| 13497 |
this.div = null; |
| 13498 |
this._cancelled = false; |
| 13499 |
this.#uiManager = options.uiManager; |
| 13500 |
this.#annotationLayer = options.annotationLayer || null; |
| 13501 |
this.#textLayer = options.textLayer || null; |
| 13502 |
this.#drawLayer = options.drawLayer || null; |
| 13503 |
this.#onAppend = options.onAppend || null; |
| 13504 |
this.#structTreeLayer = options.structTreeLayer || null; |
| 13505 |
} |
| 13506 |
async render({ |
| 13507 |
viewport, |
| 13508 |
intent = "display" |
| 13509 |
}) { |
| 13510 |
if (intent !== "display") { |
| 13511 |
return; |
| 13512 |
} |
| 13513 |
if (this._cancelled) { |
| 13514 |
return; |
| 13515 |
} |
| 13516 |
const clonedViewport = viewport.clone({ |
| 13517 |
dontFlip: true |
| 13518 |
}); |
| 13519 |
if (this.div) { |
| 13520 |
this.annotationEditorLayer.update({ |
| 13521 |
viewport: clonedViewport |
| 13522 |
}); |
| 13523 |
this.show(); |
| 13524 |
return; |
| 13525 |
} |
| 13526 |
const div = this.div = document.createElement("div"); |
| 13527 |
div.className = "annotationEditorLayer"; |
| 13528 |
div.hidden = true; |
| 13529 |
div.dir = this.#uiManager.direction; |
| 13530 |
this.#onAppend?.(div); |
| 13531 |
this.annotationEditorLayer = new AnnotationEditorLayer({ |
| 13532 |
uiManager: this.#uiManager, |
| 13533 |
div, |
| 13534 |
structTreeLayer: this.#structTreeLayer, |
| 13535 |
accessibilityManager: this.accessibilityManager, |
| 13536 |
pageIndex: this.pdfPage.pageNumber - 1, |
| 13537 |
l10n: this.l10n, |
| 13538 |
viewport: clonedViewport, |
| 13539 |
annotationLayer: this.#annotationLayer, |
| 13540 |
textLayer: this.#textLayer, |
| 13541 |
drawLayer: this.#drawLayer |
| 13542 |
}); |
| 13543 |
const parameters = { |
| 13544 |
viewport: clonedViewport, |
| 13545 |
div, |
| 13546 |
annotations: null, |
| 13547 |
intent |
| 13548 |
}; |
| 13549 |
this.annotationEditorLayer.render(parameters); |
| 13550 |
this.show(); |
| 13551 |
} |
| 13552 |
cancel() { |
| 13553 |
this._cancelled = true; |
| 13554 |
if (!this.div) { |
| 13555 |
return; |
| 13556 |
} |
| 13557 |
this.annotationEditorLayer.destroy(); |
| 13558 |
} |
| 13559 |
hide() { |
| 13560 |
if (!this.div) { |
| 13561 |
return; |
| 13562 |
} |
| 13563 |
this.annotationEditorLayer.pause(true); |
| 13564 |
this.div.hidden = true; |
| 13565 |
} |
| 13566 |
show() { |
| 13567 |
if (!this.div || this.annotationEditorLayer.isInvisible) { |
| 13568 |
return; |
| 13569 |
} |
| 13570 |
this.div.hidden = false; |
| 13571 |
this.annotationEditorLayer.pause(false); |
| 13572 |
} |
| 13573 |
} |
| 13574 |
|
| 13575 |
;// ./web/annotation_layer_builder.js |
| 13576 |
|
| 13577 |
|
| 13578 |
|
| 13579 |
|
| 13580 |
|
| 13581 |
class AnnotationLayerBuilder { |
| 13582 |
#annotations = null; |
| 13583 |
#externalHide = false; |
| 13584 |
#onAppend = null; |
| 13585 |
#eventAbortController = null; |
| 13586 |
#linksInjected = false; |
| 13587 |
constructor({ |
| 13588 |
pdfPage, |
| 13589 |
linkService, |
| 13590 |
downloadManager, |
| 13591 |
annotationStorage = null, |
| 13592 |
imageResourcesPath = "", |
| 13593 |
renderForms = true, |
| 13594 |
enableScripting = false, |
| 13595 |
hasJSActionsPromise = null, |
| 13596 |
fieldObjectsPromise = null, |
| 13597 |
annotationCanvasMap = null, |
| 13598 |
accessibilityManager = null, |
| 13599 |
annotationEditorUIManager = null, |
| 13600 |
onAppend = null |
| 13601 |
}) { |
| 13602 |
this.pdfPage = pdfPage; |
| 13603 |
this.linkService = linkService; |
| 13604 |
this.downloadManager = downloadManager; |
| 13605 |
this.imageResourcesPath = imageResourcesPath; |
| 13606 |
this.renderForms = renderForms; |
| 13607 |
this.annotationStorage = annotationStorage; |
| 13608 |
this.enableScripting = enableScripting; |
| 13609 |
this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false); |
| 13610 |
this._fieldObjectsPromise = fieldObjectsPromise || Promise.resolve(null); |
| 13611 |
this._annotationCanvasMap = annotationCanvasMap; |
| 13612 |
this._accessibilityManager = accessibilityManager; |
| 13613 |
this._annotationEditorUIManager = annotationEditorUIManager; |
| 13614 |
this.#onAppend = onAppend; |
| 13615 |
this.annotationLayer = null; |
| 13616 |
this.div = null; |
| 13617 |
this._cancelled = false; |
| 13618 |
this._eventBus = linkService.eventBus; |
| 13619 |
} |
| 13620 |
async render({ |
| 13621 |
viewport, |
| 13622 |
intent = "display", |
| 13623 |
structTreeLayer = null |
| 13624 |
}) { |
| 13625 |
if (this.div) { |
| 13626 |
if (this._cancelled || !this.annotationLayer) { |
| 13627 |
return; |
| 13628 |
} |
| 13629 |
this.annotationLayer.update({ |
| 13630 |
viewport: viewport.clone({ |
| 13631 |
dontFlip: true |
| 13632 |
}) |
| 13633 |
}); |
| 13634 |
return; |
| 13635 |
} |
| 13636 |
const [annotations, hasJSActions, fieldObjects] = await Promise.all([this.pdfPage.getAnnotations({ |
| 13637 |
intent |
| 13638 |
}), this._hasJSActionsPromise, this._fieldObjectsPromise]); |
| 13639 |
if (this._cancelled) { |
| 13640 |
return; |
| 13641 |
} |
| 13642 |
const div = this.div = document.createElement("div"); |
| 13643 |
div.className = "annotationLayer"; |
| 13644 |
this.#onAppend?.(div); |
| 13645 |
if (annotations.length === 0) { |
| 13646 |
this.#annotations = annotations; |
| 13647 |
this.hide(true); |
| 13648 |
return; |
| 13649 |
} |
| 13650 |
this.#initAnnotationLayer(viewport, structTreeLayer); |
| 13651 |
await this.annotationLayer.render({ |
| 13652 |
annotations, |
| 13653 |
imageResourcesPath: this.imageResourcesPath, |
| 13654 |
renderForms: this.renderForms, |
| 13655 |
linkService: this.linkService, |
| 13656 |
downloadManager: this.downloadManager, |
| 13657 |
annotationStorage: this.annotationStorage, |
| 13658 |
enableScripting: this.enableScripting, |
| 13659 |
hasJSActions, |
| 13660 |
fieldObjects |
| 13661 |
}); |
| 13662 |
this.#annotations = annotations; |
| 13663 |
if (this.linkService.isInPresentationMode) { |
| 13664 |
this.#updatePresentationModeState(PresentationModeState.FULLSCREEN); |
| 13665 |
} |
| 13666 |
if (!this.#eventAbortController) { |
| 13667 |
this.#eventAbortController = new AbortController(); |
| 13668 |
this._eventBus?._on("presentationmodechanged", evt => { |
| 13669 |
this.#updatePresentationModeState(evt.state); |
| 13670 |
}, { |
| 13671 |
signal: this.#eventAbortController.signal |
| 13672 |
}); |
| 13673 |
} |
| 13674 |
} |
| 13675 |
#initAnnotationLayer(viewport, structTreeLayer) { |
| 13676 |
this.annotationLayer = new AnnotationLayer({ |
| 13677 |
div: this.div, |
| 13678 |
accessibilityManager: this._accessibilityManager, |
| 13679 |
annotationCanvasMap: this._annotationCanvasMap, |
| 13680 |
annotationEditorUIManager: this._annotationEditorUIManager, |
| 13681 |
page: this.pdfPage, |
| 13682 |
viewport: viewport.clone({ |
| 13683 |
dontFlip: true |
| 13684 |
}), |
| 13685 |
structTreeLayer |
| 13686 |
}); |
| 13687 |
} |
| 13688 |
cancel() { |
| 13689 |
this._cancelled = true; |
| 13690 |
this.#eventAbortController?.abort(); |
| 13691 |
this.#eventAbortController = null; |
| 13692 |
} |
| 13693 |
hide(internal = false) { |
| 13694 |
this.#externalHide = !internal; |
| 13695 |
if (!this.div) { |
| 13696 |
return; |
| 13697 |
} |
| 13698 |
this.div.hidden = true; |
| 13699 |
} |
| 13700 |
hasEditableAnnotations() { |
| 13701 |
return !!this.annotationLayer?.hasEditableAnnotations(); |
| 13702 |
} |
| 13703 |
async injectLinkAnnotations({ |
| 13704 |
inferredLinks, |
| 13705 |
viewport, |
| 13706 |
structTreeLayer = null |
| 13707 |
}) { |
| 13708 |
if (this.#annotations === null) { |
| 13709 |
throw new Error("`render` method must be called before `injectLinkAnnotations`."); |
| 13710 |
} |
| 13711 |
if (this._cancelled || this.#linksInjected) { |
| 13712 |
return; |
| 13713 |
} |
| 13714 |
this.#linksInjected = true; |
| 13715 |
const newLinks = this.#annotations.length ? this.#checkInferredLinks(inferredLinks) : inferredLinks; |
| 13716 |
if (!newLinks.length) { |
| 13717 |
return; |
| 13718 |
} |
| 13719 |
if (!this.annotationLayer) { |
| 13720 |
this.#initAnnotationLayer(viewport, structTreeLayer); |
| 13721 |
setLayerDimensions(this.div, viewport); |
| 13722 |
} |
| 13723 |
await this.annotationLayer.addLinkAnnotations(newLinks, this.linkService); |
| 13724 |
if (!this.#externalHide) { |
| 13725 |
this.div.hidden = false; |
| 13726 |
} |
| 13727 |
} |
| 13728 |
#updatePresentationModeState(state) { |
| 13729 |
if (!this.div) { |
| 13730 |
return; |
| 13731 |
} |
| 13732 |
let disableFormElements = false; |
| 13733 |
switch (state) { |
| 13734 |
case PresentationModeState.FULLSCREEN: |
| 13735 |
disableFormElements = true; |
| 13736 |
break; |
| 13737 |
case PresentationModeState.NORMAL: |
| 13738 |
break; |
| 13739 |
default: |
| 13740 |
return; |
| 13741 |
} |
| 13742 |
for (const section of this.div.childNodes) { |
| 13743 |
if (section.hasAttribute("data-internal-link")) { |
| 13744 |
continue; |
| 13745 |
} |
| 13746 |
section.inert = disableFormElements; |
| 13747 |
} |
| 13748 |
} |
| 13749 |
#checkInferredLinks(inferredLinks) { |
| 13750 |
function annotationRects(annot) { |
| 13751 |
if (!annot.quadPoints) { |
| 13752 |
return [annot.rect]; |
| 13753 |
} |
| 13754 |
const rects = []; |
| 13755 |
for (let i = 2, ii = annot.quadPoints.length; i < ii; i += 8) { |
| 13756 |
const trX = annot.quadPoints[i]; |
| 13757 |
const trY = annot.quadPoints[i + 1]; |
| 13758 |
const blX = annot.quadPoints[i + 2]; |
| 13759 |
const blY = annot.quadPoints[i + 3]; |
| 13760 |
rects.push([blX, blY, trX, trY]); |
| 13761 |
} |
| 13762 |
return rects; |
| 13763 |
} |
| 13764 |
function intersectAnnotations(annot1, annot2) { |
| 13765 |
const intersections = []; |
| 13766 |
const annot1Rects = annotationRects(annot1); |
| 13767 |
const annot2Rects = annotationRects(annot2); |
| 13768 |
for (const rect1 of annot1Rects) { |
| 13769 |
for (const rect2 of annot2Rects) { |
| 13770 |
const intersection = Util.intersect(rect1, rect2); |
| 13771 |
if (intersection) { |
| 13772 |
intersections.push(intersection); |
| 13773 |
} |
| 13774 |
} |
| 13775 |
} |
| 13776 |
return intersections; |
| 13777 |
} |
| 13778 |
function areaRects(rects) { |
| 13779 |
let totalArea = 0; |
| 13780 |
for (const rect of rects) { |
| 13781 |
totalArea += Math.abs((rect[2] - rect[0]) * (rect[3] - rect[1])); |
| 13782 |
} |
| 13783 |
return totalArea; |
| 13784 |
} |
| 13785 |
return inferredLinks.filter(link => { |
| 13786 |
let linkAreaRects; |
| 13787 |
for (const annotation of this.#annotations) { |
| 13788 |
if (annotation.annotationType !== AnnotationType.LINK || !annotation.url) { |
| 13789 |
continue; |
| 13790 |
} |
| 13791 |
const intersections = intersectAnnotations(annotation, link); |
| 13792 |
if (intersections.length === 0) { |
| 13793 |
continue; |
| 13794 |
} |
| 13795 |
linkAreaRects ??= areaRects(annotationRects(link)); |
| 13796 |
if (areaRects(intersections) / linkAreaRects > 0.5) { |
| 13797 |
return false; |
| 13798 |
} |
| 13799 |
} |
| 13800 |
return true; |
| 13801 |
}); |
| 13802 |
} |
| 13803 |
} |
| 13804 |
|
| 13805 |
// EXTERNAL MODULE: ./node_modules/core-js/modules/web.url.can-parse.js |
| 13806 |
var web_url_can_parse = __webpack_require__(2222); |
| 13807 |
;// ./web/autolinker.js |
| 13808 |
|
| 13809 |
|
| 13810 |
|
| 13811 |
|
| 13812 |
|
| 13813 |
|
| 13814 |
function DOMRectToPDF({ |
| 13815 |
width, |
| 13816 |
height, |
| 13817 |
left, |
| 13818 |
top |
| 13819 |
}, pdfPageView) { |
| 13820 |
if (width === 0 || height === 0) { |
| 13821 |
return null; |
| 13822 |
} |
| 13823 |
const pageBox = pdfPageView.textLayer.div.getBoundingClientRect(); |
| 13824 |
const bottomLeft = pdfPageView.getPagePoint(left - pageBox.left, top - pageBox.top); |
| 13825 |
const topRight = pdfPageView.getPagePoint(left - pageBox.left + width, top - pageBox.top + height); |
| 13826 |
return Util.normalizeRect([bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]]); |
| 13827 |
} |
| 13828 |
function calculateLinkPosition(range, pdfPageView) { |
| 13829 |
const rangeRects = range.getClientRects(); |
| 13830 |
if (rangeRects.length === 1) { |
| 13831 |
return { |
| 13832 |
rect: DOMRectToPDF(rangeRects[0], pdfPageView) |
| 13833 |
}; |
| 13834 |
} |
| 13835 |
const rect = [Infinity, Infinity, -Infinity, -Infinity]; |
| 13836 |
const quadPoints = []; |
| 13837 |
let i = 0; |
| 13838 |
for (const domRect of rangeRects) { |
| 13839 |
const normalized = DOMRectToPDF(domRect, pdfPageView); |
| 13840 |
if (normalized === null) { |
| 13841 |
continue; |
| 13842 |
} |
| 13843 |
quadPoints[i] = quadPoints[i + 4] = normalized[0]; |
| 13844 |
quadPoints[i + 1] = quadPoints[i + 3] = normalized[3]; |
| 13845 |
quadPoints[i + 2] = quadPoints[i + 6] = normalized[2]; |
| 13846 |
quadPoints[i + 5] = quadPoints[i + 7] = normalized[1]; |
| 13847 |
Util.rectBoundingBox(...normalized, rect); |
| 13848 |
i += 8; |
| 13849 |
} |
| 13850 |
return { |
| 13851 |
quadPoints, |
| 13852 |
rect |
| 13853 |
}; |
| 13854 |
} |
| 13855 |
function textPosition(container, offset) { |
| 13856 |
let currentContainer = container; |
| 13857 |
do { |
| 13858 |
if (currentContainer.nodeType === Node.TEXT_NODE) { |
| 13859 |
const currentLength = currentContainer.textContent.length; |
| 13860 |
if (offset <= currentLength) { |
| 13861 |
return [currentContainer, offset]; |
| 13862 |
} |
| 13863 |
offset -= currentLength; |
| 13864 |
} else if (currentContainer.firstChild) { |
| 13865 |
currentContainer = currentContainer.firstChild; |
| 13866 |
continue; |
| 13867 |
} |
| 13868 |
while (!currentContainer.nextSibling && currentContainer !== container) { |
| 13869 |
currentContainer = currentContainer.parentNode; |
| 13870 |
} |
| 13871 |
if (currentContainer !== container) { |
| 13872 |
currentContainer = currentContainer.nextSibling; |
| 13873 |
} |
| 13874 |
} while (currentContainer !== container); |
| 13875 |
throw new Error("Offset is bigger than container's contents length."); |
| 13876 |
} |
| 13877 |
function createLinkAnnotation({ |
| 13878 |
url, |
| 13879 |
index, |
| 13880 |
length |
| 13881 |
}, pdfPageView, id) { |
| 13882 |
const highlighter = pdfPageView._textHighlighter; |
| 13883 |
const [{ |
| 13884 |
begin, |
| 13885 |
end |
| 13886 |
}] = highlighter._convertMatches([index], [length]); |
| 13887 |
const range = new Range(); |
| 13888 |
range.setStart(...textPosition(highlighter.textDivs[begin.divIdx], begin.offset)); |
| 13889 |
range.setEnd(...textPosition(highlighter.textDivs[end.divIdx], end.offset)); |
| 13890 |
return { |
| 13891 |
id: `inferred_link_${id}`, |
| 13892 |
unsafeUrl: url, |
| 13893 |
url, |
| 13894 |
annotationType: AnnotationType.LINK, |
| 13895 |
rotation: 0, |
| 13896 |
...calculateLinkPosition(range, pdfPageView), |
| 13897 |
borderStyle: null |
| 13898 |
}; |
| 13899 |
} |
| 13900 |
class Autolinker { |
| 13901 |
static #index = 0; |
| 13902 |
static #regex; |
| 13903 |
static findLinks(text) { |
| 13904 |
this.#regex ??= /\b(?:https?:\/\/|mailto:|www\.)(?:[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]|\/|[\0-\x08\x0E-\x1F!-Z\\\^-\x9F\xA1-\u167F\u1681-\u1FFF\u200B-\u2027\u202A-\u202E\u2030-\u205E\u2060-\u2FFF\u3001-\uFEFE\uFF00-\u{10FFFF}]+[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}])+|\b[\0-\x08\x0E-\x1F!-'\*-;=\?A-Z\\\^-z\|~-\x9F\xA1-\u0F39\u0F3E-\u167F\u1681-\u169A\u169D-\u1FFF\u200B-\u2019\u201B-\u201D\u201F-\u2027\u202A-\u202E\u2030-\u2044\u2047-\u205E\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2E21\u2E2A-\u2E41\u2E43-\u2E54\u2E5D-\u2FFF\u3001-\u3007\u3012\u3013\u301C\u3020-\uFD3D\uFD40-\uFE16\uFE19-\uFE34\uFE45\uFE46\uFE49-\uFE58\uFE5F-\uFEFE\uFF00-\uFF07\uFF0A-\uFF3A\uFF3C\uFF3E-\uFF5A\uFF5C\uFF5E\uFF61\uFF64-\u{10FFFF}]+@([\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]+(?:\.[\0-\x08\x0E-\x1F\$\+0-9=A-Z\^`-z\|~-\x9F\xA2-\xA6\xA8-\xAA\xAC-\xB5\xB8-\xBA\xBC-\xBE\xC0-\u037D\u037F-\u0386\u0388-\u0559\u0560-\u0588\u058B-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7-\u05F2\u05F5-\u0608\u060B\u060E-\u061A\u061C\u0620-\u0669\u066E-\u06D3\u06D5-\u06FF\u070E-\u07F6\u07FA-\u082F\u083F-\u085D\u085F-\u0963\u0966-\u096F\u0971-\u09FC\u09FE-\u0A75\u0A77-\u0AEF\u0AF1-\u0C76\u0C78-\u0C83\u0C85-\u0DF3\u0DF5-\u0E4E\u0E50-\u0E59\u0E5C-\u0F03\u0F13\u0F15-\u0F39\u0F3E-\u0F84\u0F86-\u0FCF\u0FD5-\u0FD8\u0FDB-\u1049\u1050-\u10FA\u10FC-\u135F\u1369-\u13FF\u1401-\u166D\u166F-\u167F\u1681-\u169A\u169D-\u16EA\u16EE-\u1734\u1737-\u17D3\u17D7\u17DB-\u17FF\u180B-\u1943\u1946-\u1A1D\u1A20-\u1A9F\u1AA7\u1AAE-\u1B4D\u1B50-\u1B59\u1B61-\u1B7C\u1B80-\u1BFB\u1C00-\u1C3A\u1C40-\u1C7D\u1C80-\u1CBF\u1CC8-\u1CD2\u1CD4-\u1FFF\u200B-\u200F\u202A-\u202E\u2044\u2052\u2060-\u207C\u207F-\u208C\u208F-\u2307\u230C-\u2328\u232B-\u2767\u2776-\u27C4\u27C7-\u27E5\u27F0-\u2982\u2999-\u29D7\u29DC-\u29FB\u29FE-\u2CF8\u2CFD\u2D00-\u2D6F\u2D71-\u2DFF\u2E2F\u2E50\u2E51\u2E5E-\u2FFF\u3004-\u3007\u3012\u3013\u3020-\u302F\u3031-\u303C\u303E-\u309F\u30A1-\u30FA\u30FC-\uA4FD\uA500-\uA60C\uA610-\uA672\uA674-\uA67D\uA67F-\uA6F1\uA6F8-\uA873\uA878-\uA8CD\uA8D0-\uA8F7\uA8FB\uA8FD-\uA92D\uA930-\uA95E\uA960-\uA9C0\uA9CE-\uA9DD\uA9E0-\uAA5B\uAA60-\uAADD\uAAE0-\uAAEF\uAAF2-\uABEA\uABEC-\uFD3D\uFD40-\uFE0F\uFE1A-\uFE2F\uFE53\uFE62\uFE64-\uFE67\uFE69\uFE6C-\uFEFE\uFF00\uFF04\uFF0B\uFF10-\uFF19\uFF1C-\uFF1E\uFF21-\uFF3A\uFF3E\uFF40-\uFF5A\uFF5C\uFF5E\uFF66-\u{100FF}\u{10103}-\u{1039E}\u{103A0}-\u{103CF}\u{103D1}-\u{1056E}\u{10570}-\u{10856}\u{10858}-\u{1091E}\u{10920}-\u{1093E}\u{10940}-\u{10A4F}\u{10A59}-\u{10A7E}\u{10A80}-\u{10AEF}\u{10AF7}-\u{10B38}\u{10B40}-\u{10B98}\u{10B9D}-\u{10D6D}\u{10D6F}-\u{10EAC}\u{10EAE}-\u{10F54}\u{10F5A}-\u{10F85}\u{10F8A}-\u{11046}\u{1104E}-\u{110BA}\u{110BD}\u{110C2}-\u{1113F}\u{11144}-\u{11173}\u{11176}-\u{111C4}\u{111C9}-\u{111CC}\u{111CE}-\u{111DA}\u{111DC}\u{111E0}-\u{11237}\u{1123E}-\u{112A8}\u{112AA}-\u{113D3}\u{113D6}\u{113D9}-\u{1144A}\u{11450}-\u{11459}\u{1145C}\u{1145E}-\u{114C5}\u{114C7}-\u{115C0}\u{115D8}-\u{11640}\u{11644}-\u{1165F}\u{1166D}-\u{116B8}\u{116BA}-\u{1173B}\u{1173F}-\u{1183A}\u{1183C}-\u{11943}\u{11947}-\u{119E1}\u{119E3}-\u{11A3E}\u{11A47}-\u{11A99}\u{11A9D}\u{11AA3}-\u{11AFF}\u{11B0A}-\u{11BE0}\u{11BE2}-\u{11C40}\u{11C46}-\u{11C6F}\u{11C72}-\u{11EF6}\u{11EF9}-\u{11F42}\u{11F50}-\u{11FFE}\u{12000}-\u{1246F}\u{12475}-\u{12FF0}\u{12FF3}-\u{16A6D}\u{16A70}-\u{16AF4}\u{16AF6}-\u{16B36}\u{16B3C}-\u{16B43}\u{16B45}-\u{16D6C}\u{16D70}-\u{16E96}\u{16E9B}-\u{16FE1}\u{16FE3}-\u{1BC9E}\u{1BCA0}-\u{1DA86}\u{1DA8C}-\u{1E5FE}\u{1E600}-\u{1E95D}\u{1E960}-\u{10FFFF}]+)+)/gmu; |
| 13905 |
const [normalizedText, diffs] = normalize(text); |
| 13906 |
const matches = normalizedText.matchAll(this.#regex); |
| 13907 |
const links = []; |
| 13908 |
for (const match of matches) { |
| 13909 |
const [url, emailDomain] = match; |
| 13910 |
let raw; |
| 13911 |
if (url.startsWith("www.") || url.startsWith("http://") || url.startsWith("https://")) { |
| 13912 |
raw = url; |
| 13913 |
} else if (URL.canParse(`http://${emailDomain}`)) { |
| 13914 |
raw = url.startsWith("mailto:") ? url : `mailto:${url}`; |
| 13915 |
} else { |
| 13916 |
continue; |
| 13917 |
} |
| 13918 |
const absoluteURL = createValidAbsoluteUrl(raw, null, { |
| 13919 |
addDefaultProtocol: true |
| 13920 |
}); |
| 13921 |
if (absoluteURL) { |
| 13922 |
const [index, length] = getOriginalIndex(diffs, match.index, url.length); |
| 13923 |
links.push({ |
| 13924 |
url: absoluteURL.href, |
| 13925 |
index, |
| 13926 |
length |
| 13927 |
}); |
| 13928 |
} |
| 13929 |
} |
| 13930 |
return links; |
| 13931 |
} |
| 13932 |
static processLinks(pdfPageView) { |
| 13933 |
return this.findLinks(pdfPageView._textHighlighter.textContentItemsStr.join("\n")).map(link => createLinkAnnotation(link, pdfPageView, this.#index++)); |
| 13934 |
} |
| 13935 |
} |
| 13936 |
|
| 13937 |
;// ./web/base_pdf_page_view.js |
| 13938 |
|
| 13939 |
|
| 13940 |
class BasePDFPageView { |
| 13941 |
#enableHWA = false; |
| 13942 |
#loadingId = null; |
| 13943 |
#minDurationToUpdateCanvas = 0; |
| 13944 |
#renderError = null; |
| 13945 |
#renderingState = RenderingStates.INITIAL; |
| 13946 |
#showCanvas = null; |
| 13947 |
#startTime = 0; |
| 13948 |
#tempCanvas = null; |
| 13949 |
canvas = null; |
| 13950 |
div = null; |
| 13951 |
eventBus = null; |
| 13952 |
id = null; |
| 13953 |
pageColors = null; |
| 13954 |
renderingQueue = null; |
| 13955 |
renderTask = null; |
| 13956 |
resume = null; |
| 13957 |
constructor(options) { |
| 13958 |
this.#enableHWA = #enableHWA in options ? options.#enableHWA : options.enableHWA || false; |
| 13959 |
this.eventBus = options.eventBus; |
| 13960 |
this.id = options.id; |
| 13961 |
this.pageColors = options.pageColors || null; |
| 13962 |
this.renderingQueue = options.renderingQueue; |
| 13963 |
this.#minDurationToUpdateCanvas = options.minDurationToUpdateCanvas ?? 500; |
| 13964 |
} |
| 13965 |
get renderingState() { |
| 13966 |
return this.#renderingState; |
| 13967 |
} |
| 13968 |
set renderingState(state) { |
| 13969 |
if (state === this.#renderingState) { |
| 13970 |
return; |
| 13971 |
} |
| 13972 |
this.#renderingState = state; |
| 13973 |
if (this.#loadingId) { |
| 13974 |
clearTimeout(this.#loadingId); |
| 13975 |
this.#loadingId = null; |
| 13976 |
} |
| 13977 |
switch (state) { |
| 13978 |
case RenderingStates.PAUSED: |
| 13979 |
this.div.classList.remove("loading"); |
| 13980 |
this.#startTime = 0; |
| 13981 |
this.#showCanvas?.(false); |
| 13982 |
break; |
| 13983 |
case RenderingStates.RUNNING: |
| 13984 |
this.div.classList.add("loadingIcon"); |
| 13985 |
this.#loadingId = setTimeout(() => { |
| 13986 |
this.div.classList.add("loading"); |
| 13987 |
this.#loadingId = null; |
| 13988 |
}, 0); |
| 13989 |
this.#startTime = Date.now(); |
| 13990 |
break; |
| 13991 |
case RenderingStates.INITIAL: |
| 13992 |
case RenderingStates.FINISHED: |
| 13993 |
this.div.classList.remove("loadingIcon", "loading"); |
| 13994 |
this.#startTime = 0; |
| 13995 |
break; |
| 13996 |
} |
| 13997 |
} |
| 13998 |
_createCanvas(onShow, hideUntilComplete = false) { |
| 13999 |
const { |
| 14000 |
pageColors |
| 14001 |
} = this; |
| 14002 |
const hasHCM = !!(pageColors?.background && pageColors?.foreground); |
| 14003 |
const prevCanvas = this.canvas; |
| 14004 |
const updateOnFirstShow = !prevCanvas && !hasHCM && !hideUntilComplete; |
| 14005 |
let canvas = this.canvas = document.createElement("canvas"); |
| 14006 |
this.#showCanvas = isLastShow => { |
| 14007 |
if (updateOnFirstShow) { |
| 14008 |
let tempCanvas = this.#tempCanvas; |
| 14009 |
if (!isLastShow && this.#minDurationToUpdateCanvas > 0) { |
| 14010 |
if (Date.now() - this.#startTime < this.#minDurationToUpdateCanvas) { |
| 14011 |
return; |
| 14012 |
} |
| 14013 |
if (!tempCanvas) { |
| 14014 |
tempCanvas = this.#tempCanvas = canvas; |
| 14015 |
canvas = this.canvas = canvas.cloneNode(false); |
| 14016 |
onShow(canvas); |
| 14017 |
} |
| 14018 |
} |
| 14019 |
if (tempCanvas) { |
| 14020 |
const ctx = canvas.getContext("2d", { |
| 14021 |
alpha: false |
| 14022 |
}); |
| 14023 |
ctx.drawImage(tempCanvas, 0, 0); |
| 14024 |
if (isLastShow) { |
| 14025 |
this.#resetTempCanvas(); |
| 14026 |
} else { |
| 14027 |
this.#startTime = Date.now(); |
| 14028 |
} |
| 14029 |
return; |
| 14030 |
} |
| 14031 |
onShow(canvas); |
| 14032 |
this.#showCanvas = null; |
| 14033 |
return; |
| 14034 |
} |
| 14035 |
if (!isLastShow) { |
| 14036 |
return; |
| 14037 |
} |
| 14038 |
if (prevCanvas) { |
| 14039 |
prevCanvas.replaceWith(canvas); |
| 14040 |
prevCanvas.width = prevCanvas.height = 0; |
| 14041 |
} else { |
| 14042 |
onShow(canvas); |
| 14043 |
} |
| 14044 |
}; |
| 14045 |
const ctx = canvas.getContext("2d", { |
| 14046 |
alpha: false, |
| 14047 |
willReadFrequently: !this.#enableHWA |
| 14048 |
}); |
| 14049 |
return { |
| 14050 |
canvas, |
| 14051 |
prevCanvas, |
| 14052 |
ctx |
| 14053 |
}; |
| 14054 |
} |
| 14055 |
#renderContinueCallback = cont => { |
| 14056 |
this.#showCanvas?.(false); |
| 14057 |
if (this.renderingQueue && !this.renderingQueue.isHighestPriority(this)) { |
| 14058 |
this.renderingState = RenderingStates.PAUSED; |
| 14059 |
this.resume = () => { |
| 14060 |
this.renderingState = RenderingStates.RUNNING; |
| 14061 |
cont(); |
| 14062 |
}; |
| 14063 |
return; |
| 14064 |
} |
| 14065 |
cont(); |
| 14066 |
}; |
| 14067 |
_resetCanvas() { |
| 14068 |
const { |
| 14069 |
canvas |
| 14070 |
} = this; |
| 14071 |
if (!canvas) { |
| 14072 |
return; |
| 14073 |
} |
| 14074 |
canvas.remove(); |
| 14075 |
canvas.width = canvas.height = 0; |
| 14076 |
this.canvas = null; |
| 14077 |
this.#resetTempCanvas(); |
| 14078 |
} |
| 14079 |
#resetTempCanvas() { |
| 14080 |
if (this.#tempCanvas) { |
| 14081 |
this.#tempCanvas.width = this.#tempCanvas.height = 0; |
| 14082 |
this.#tempCanvas = null; |
| 14083 |
} |
| 14084 |
} |
| 14085 |
async _drawCanvas(options, onCancel, onFinish) { |
| 14086 |
const renderTask = this.renderTask = this.pdfPage.render(options); |
| 14087 |
renderTask.onContinue = this.#renderContinueCallback; |
| 14088 |
renderTask.onError = error => { |
| 14089 |
if (error instanceof RenderingCancelledException) { |
| 14090 |
onCancel(); |
| 14091 |
this.#renderError = null; |
| 14092 |
} |
| 14093 |
}; |
| 14094 |
let error = null; |
| 14095 |
try { |
| 14096 |
await renderTask.promise; |
| 14097 |
this.#showCanvas?.(true); |
| 14098 |
} catch (e) { |
| 14099 |
if (e instanceof RenderingCancelledException) { |
| 14100 |
return; |
| 14101 |
} |
| 14102 |
error = e; |
| 14103 |
this.#showCanvas?.(true); |
| 14104 |
} finally { |
| 14105 |
this.#renderError = error; |
| 14106 |
if (renderTask === this.renderTask) { |
| 14107 |
this.renderTask = null; |
| 14108 |
} |
| 14109 |
} |
| 14110 |
this.renderingState = RenderingStates.FINISHED; |
| 14111 |
onFinish(renderTask); |
| 14112 |
if (error) { |
| 14113 |
throw error; |
| 14114 |
} |
| 14115 |
} |
| 14116 |
cancelRendering({ |
| 14117 |
cancelExtraDelay = 0 |
| 14118 |
} = {}) { |
| 14119 |
if (this.renderTask) { |
| 14120 |
this.renderTask.cancel(cancelExtraDelay); |
| 14121 |
this.renderTask = null; |
| 14122 |
} |
| 14123 |
this.resume = null; |
| 14124 |
} |
| 14125 |
dispatchPageRender() { |
| 14126 |
this.eventBus.dispatch("pagerender", { |
| 14127 |
source: this, |
| 14128 |
pageNumber: this.id |
| 14129 |
}); |
| 14130 |
} |
| 14131 |
dispatchPageRendered(cssTransform, isDetailView) { |
| 14132 |
this.eventBus.dispatch("pagerendered", { |
| 14133 |
source: this, |
| 14134 |
pageNumber: this.id, |
| 14135 |
cssTransform, |
| 14136 |
isDetailView, |
| 14137 |
timestamp: performance.now(), |
| 14138 |
error: this.#renderError |
| 14139 |
}); |
| 14140 |
} |
| 14141 |
} |
| 14142 |
|
| 14143 |
;// ./web/draw_layer_builder.js |
| 14144 |
|
| 14145 |
class DrawLayerBuilder { |
| 14146 |
#drawLayer = null; |
| 14147 |
constructor(options) { |
| 14148 |
this.pageIndex = options.pageIndex; |
| 14149 |
} |
| 14150 |
async render({ |
| 14151 |
intent = "display" |
| 14152 |
}) { |
| 14153 |
if (intent !== "display" || this.#drawLayer || this._cancelled) { |
| 14154 |
return; |
| 14155 |
} |
| 14156 |
this.#drawLayer = new DrawLayer({ |
| 14157 |
pageIndex: this.pageIndex |
| 14158 |
}); |
| 14159 |
} |
| 14160 |
cancel() { |
| 14161 |
this._cancelled = true; |
| 14162 |
if (!this.#drawLayer) { |
| 14163 |
return; |
| 14164 |
} |
| 14165 |
this.#drawLayer.destroy(); |
| 14166 |
this.#drawLayer = null; |
| 14167 |
} |
| 14168 |
setParent(parent) { |
| 14169 |
this.#drawLayer?.setParent(parent); |
| 14170 |
} |
| 14171 |
getDrawLayer() { |
| 14172 |
return this.#drawLayer; |
| 14173 |
} |
| 14174 |
} |
| 14175 |
|
| 14176 |
;// ./web/pdf_page_detail_view.js |
| 14177 |
|
| 14178 |
|
| 14179 |
|
| 14180 |
class PDFPageDetailView extends BasePDFPageView { |
| 14181 |
#detailArea = null; |
| 14182 |
renderingCancelled = false; |
| 14183 |
constructor({ |
| 14184 |
pageView |
| 14185 |
}) { |
| 14186 |
super(pageView); |
| 14187 |
this.pageView = pageView; |
| 14188 |
this.renderingId = "detail" + this.id; |
| 14189 |
this.div = pageView.div; |
| 14190 |
} |
| 14191 |
setPdfPage(pdfPage) { |
| 14192 |
this.pageView.setPdfPage(pdfPage); |
| 14193 |
} |
| 14194 |
get pdfPage() { |
| 14195 |
return this.pageView.pdfPage; |
| 14196 |
} |
| 14197 |
get renderingState() { |
| 14198 |
return super.renderingState; |
| 14199 |
} |
| 14200 |
set renderingState(value) { |
| 14201 |
this.renderingCancelled = false; |
| 14202 |
super.renderingState = value; |
| 14203 |
} |
| 14204 |
reset({ |
| 14205 |
keepCanvas = false |
| 14206 |
} = {}) { |
| 14207 |
const renderingCancelled = this.renderingCancelled || this.renderingState === RenderingStates.RUNNING || this.renderingState === RenderingStates.PAUSED; |
| 14208 |
this.cancelRendering(); |
| 14209 |
this.renderingState = RenderingStates.INITIAL; |
| 14210 |
this.renderingCancelled = renderingCancelled; |
| 14211 |
if (!keepCanvas) { |
| 14212 |
this._resetCanvas(); |
| 14213 |
} |
| 14214 |
} |
| 14215 |
#shouldRenderDifferentArea(visibleArea) { |
| 14216 |
if (!this.#detailArea) { |
| 14217 |
return true; |
| 14218 |
} |
| 14219 |
const minDetailX = this.#detailArea.minX; |
| 14220 |
const minDetailY = this.#detailArea.minY; |
| 14221 |
const maxDetailX = this.#detailArea.width + minDetailX; |
| 14222 |
const maxDetailY = this.#detailArea.height + minDetailY; |
| 14223 |
if (visibleArea.minX < minDetailX || visibleArea.minY < minDetailY || visibleArea.maxX > maxDetailX || visibleArea.maxY > maxDetailY) { |
| 14224 |
return true; |
| 14225 |
} |
| 14226 |
const { |
| 14227 |
width: maxWidth, |
| 14228 |
height: maxHeight, |
| 14229 |
scale |
| 14230 |
} = this.pageView.viewport; |
| 14231 |
if (this.#detailArea.scale !== scale) { |
| 14232 |
return true; |
| 14233 |
} |
| 14234 |
const paddingLeftSize = visibleArea.minX - minDetailX; |
| 14235 |
const paddingRightSize = maxDetailX - visibleArea.maxX; |
| 14236 |
const paddingTopSize = visibleArea.minY - minDetailY; |
| 14237 |
const paddingBottomSize = maxDetailY - visibleArea.maxY; |
| 14238 |
const MOVEMENT_THRESHOLD = 0.5; |
| 14239 |
const ratio = (1 + MOVEMENT_THRESHOLD) / MOVEMENT_THRESHOLD; |
| 14240 |
if (minDetailX > 0 && paddingRightSize / paddingLeftSize > ratio || maxDetailX < maxWidth && paddingLeftSize / paddingRightSize > ratio || minDetailY > 0 && paddingBottomSize / paddingTopSize > ratio || maxDetailY < maxHeight && paddingTopSize / paddingBottomSize > ratio) { |
| 14241 |
return true; |
| 14242 |
} |
| 14243 |
return false; |
| 14244 |
} |
| 14245 |
update({ |
| 14246 |
visibleArea = null, |
| 14247 |
underlyingViewUpdated = false |
| 14248 |
} = {}) { |
| 14249 |
if (underlyingViewUpdated) { |
| 14250 |
this.cancelRendering(); |
| 14251 |
this.renderingState = RenderingStates.INITIAL; |
| 14252 |
return; |
| 14253 |
} |
| 14254 |
if (!this.#shouldRenderDifferentArea(visibleArea)) { |
| 14255 |
return; |
| 14256 |
} |
| 14257 |
const { |
| 14258 |
viewport, |
| 14259 |
maxCanvasPixels, |
| 14260 |
capCanvasAreaFactor |
| 14261 |
} = this.pageView; |
| 14262 |
const visibleWidth = visibleArea.maxX - visibleArea.minX; |
| 14263 |
const visibleHeight = visibleArea.maxY - visibleArea.minY; |
| 14264 |
const visiblePixels = visibleWidth * visibleHeight * OutputScale.pixelRatio ** 2; |
| 14265 |
const maxDetailToVisibleLinearRatio = Math.sqrt(OutputScale.capPixels(maxCanvasPixels, capCanvasAreaFactor) / visiblePixels); |
| 14266 |
const maxOverflowScale = (maxDetailToVisibleLinearRatio - 1) / 2; |
| 14267 |
let overflowScale = Math.min(1, maxOverflowScale); |
| 14268 |
if (overflowScale < 0) { |
| 14269 |
overflowScale = 0; |
| 14270 |
} |
| 14271 |
const overflowWidth = visibleWidth * overflowScale; |
| 14272 |
const overflowHeight = visibleHeight * overflowScale; |
| 14273 |
const minX = Math.max(0, visibleArea.minX - overflowWidth); |
| 14274 |
const maxX = Math.min(viewport.width, visibleArea.maxX + overflowWidth); |
| 14275 |
const minY = Math.max(0, visibleArea.minY - overflowHeight); |
| 14276 |
const maxY = Math.min(viewport.height, visibleArea.maxY + overflowHeight); |
| 14277 |
const width = maxX - minX; |
| 14278 |
const height = maxY - minY; |
| 14279 |
this.#detailArea = { |
| 14280 |
minX, |
| 14281 |
minY, |
| 14282 |
width, |
| 14283 |
height, |
| 14284 |
scale: viewport.scale |
| 14285 |
}; |
| 14286 |
this.reset({ |
| 14287 |
keepCanvas: true |
| 14288 |
}); |
| 14289 |
} |
| 14290 |
async draw() { |
| 14291 |
if (this.pageView.detailView !== this) { |
| 14292 |
return undefined; |
| 14293 |
} |
| 14294 |
const hideUntilComplete = this.pageView.renderingState === RenderingStates.FINISHED || this.renderingState === RenderingStates.FINISHED; |
| 14295 |
if (this.renderingState !== RenderingStates.INITIAL) { |
| 14296 |
console.error("Must be in new state before drawing"); |
| 14297 |
this.reset(); |
| 14298 |
} |
| 14299 |
const { |
| 14300 |
div, |
| 14301 |
pdfPage, |
| 14302 |
viewport |
| 14303 |
} = this.pageView; |
| 14304 |
if (!pdfPage) { |
| 14305 |
this.renderingState = RenderingStates.FINISHED; |
| 14306 |
throw new Error("pdfPage is not loaded"); |
| 14307 |
} |
| 14308 |
this.renderingState = RenderingStates.RUNNING; |
| 14309 |
const canvasWrapper = this.pageView._ensureCanvasWrapper(); |
| 14310 |
const { |
| 14311 |
canvas, |
| 14312 |
prevCanvas, |
| 14313 |
ctx |
| 14314 |
} = this._createCanvas(newCanvas => { |
| 14315 |
if (canvasWrapper.firstElementChild?.tagName === "CANVAS") { |
| 14316 |
canvasWrapper.firstElementChild.after(newCanvas); |
| 14317 |
} else { |
| 14318 |
canvasWrapper.prepend(newCanvas); |
| 14319 |
} |
| 14320 |
}, hideUntilComplete); |
| 14321 |
canvas.setAttribute("aria-hidden", "true"); |
| 14322 |
const { |
| 14323 |
width, |
| 14324 |
height |
| 14325 |
} = viewport; |
| 14326 |
const area = this.#detailArea; |
| 14327 |
const { |
| 14328 |
pixelRatio |
| 14329 |
} = OutputScale; |
| 14330 |
const transform = [pixelRatio, 0, 0, pixelRatio, -area.minX * pixelRatio, -area.minY * pixelRatio]; |
| 14331 |
canvas.width = area.width * pixelRatio; |
| 14332 |
canvas.height = area.height * pixelRatio; |
| 14333 |
const { |
| 14334 |
style |
| 14335 |
} = canvas; |
| 14336 |
style.width = `${area.width * 100 / width}%`; |
| 14337 |
style.height = `${area.height * 100 / height}%`; |
| 14338 |
style.top = `${area.minY * 100 / height}%`; |
| 14339 |
style.left = `${area.minX * 100 / width}%`; |
| 14340 |
const renderingPromise = this._drawCanvas(this.pageView._getRenderingContext(ctx, transform), () => { |
| 14341 |
this.canvas?.remove(); |
| 14342 |
this.canvas = prevCanvas; |
| 14343 |
}, () => { |
| 14344 |
this.dispatchPageRendered(false, true); |
| 14345 |
}); |
| 14346 |
div.setAttribute("data-loaded", true); |
| 14347 |
this.dispatchPageRender(); |
| 14348 |
return renderingPromise; |
| 14349 |
} |
| 14350 |
} |
| 14351 |
|
| 14352 |
;// ./web/struct_tree_layer_builder.js |
| 14353 |
|
| 14354 |
|
| 14355 |
const PDF_ROLE_TO_HTML_ROLE = { |
| 14356 |
Document: null, |
| 14357 |
DocumentFragment: null, |
| 14358 |
Part: "group", |
| 14359 |
Sect: "group", |
| 14360 |
Div: "group", |
| 14361 |
Aside: "note", |
| 14362 |
NonStruct: "none", |
| 14363 |
P: null, |
| 14364 |
H: "heading", |
| 14365 |
Title: null, |
| 14366 |
FENote: "note", |
| 14367 |
Sub: "group", |
| 14368 |
Lbl: null, |
| 14369 |
Span: null, |
| 14370 |
Em: null, |
| 14371 |
Strong: null, |
| 14372 |
Link: "link", |
| 14373 |
Annot: "note", |
| 14374 |
Form: "form", |
| 14375 |
Ruby: null, |
| 14376 |
RB: null, |
| 14377 |
RT: null, |
| 14378 |
RP: null, |
| 14379 |
Warichu: null, |
| 14380 |
WT: null, |
| 14381 |
WP: null, |
| 14382 |
L: "list", |
| 14383 |
LI: "listitem", |
| 14384 |
LBody: null, |
| 14385 |
Table: "table", |
| 14386 |
TR: "row", |
| 14387 |
TH: "columnheader", |
| 14388 |
TD: "cell", |
| 14389 |
THead: "columnheader", |
| 14390 |
TBody: null, |
| 14391 |
TFoot: null, |
| 14392 |
Caption: null, |
| 14393 |
Figure: "figure", |
| 14394 |
Formula: null, |
| 14395 |
Artifact: null |
| 14396 |
}; |
| 14397 |
const HEADING_PATTERN = /^H(\d+)$/; |
| 14398 |
class StructTreeLayerBuilder { |
| 14399 |
#promise; |
| 14400 |
#treeDom = null; |
| 14401 |
#treePromise; |
| 14402 |
#elementAttributes = new Map(); |
| 14403 |
#rawDims; |
| 14404 |
#elementsToAddToTextLayer = null; |
| 14405 |
constructor(pdfPage, rawDims) { |
| 14406 |
this.#promise = pdfPage.getStructTree(); |
| 14407 |
this.#rawDims = rawDims; |
| 14408 |
} |
| 14409 |
async render() { |
| 14410 |
if (this.#treePromise) { |
| 14411 |
return this.#treePromise; |
| 14412 |
} |
| 14413 |
const { |
| 14414 |
promise, |
| 14415 |
resolve, |
| 14416 |
reject |
| 14417 |
} = Promise.withResolvers(); |
| 14418 |
this.#treePromise = promise; |
| 14419 |
try { |
| 14420 |
this.#treeDom = this.#walk(await this.#promise); |
| 14421 |
} catch (ex) { |
| 14422 |
reject(ex); |
| 14423 |
} |
| 14424 |
this.#promise = null; |
| 14425 |
this.#treeDom?.classList.add("structTree"); |
| 14426 |
resolve(this.#treeDom); |
| 14427 |
return promise; |
| 14428 |
} |
| 14429 |
async getAriaAttributes(annotationId) { |
| 14430 |
try { |
| 14431 |
await this.render(); |
| 14432 |
return this.#elementAttributes.get(annotationId); |
| 14433 |
} catch {} |
| 14434 |
return null; |
| 14435 |
} |
| 14436 |
hide() { |
| 14437 |
if (this.#treeDom && !this.#treeDom.hidden) { |
| 14438 |
this.#treeDom.hidden = true; |
| 14439 |
} |
| 14440 |
} |
| 14441 |
show() { |
| 14442 |
if (this.#treeDom?.hidden) { |
| 14443 |
this.#treeDom.hidden = false; |
| 14444 |
} |
| 14445 |
} |
| 14446 |
#setAttributes(structElement, htmlElement) { |
| 14447 |
const { |
| 14448 |
alt, |
| 14449 |
id, |
| 14450 |
lang |
| 14451 |
} = structElement; |
| 14452 |
if (alt !== undefined) { |
| 14453 |
let added = false; |
| 14454 |
const label = removeNullCharacters(alt); |
| 14455 |
for (const child of structElement.children) { |
| 14456 |
if (child.type === "annotation") { |
| 14457 |
let attrs = this.#elementAttributes.get(child.id); |
| 14458 |
if (!attrs) { |
| 14459 |
attrs = new Map(); |
| 14460 |
this.#elementAttributes.set(child.id, attrs); |
| 14461 |
} |
| 14462 |
attrs.set("aria-label", label); |
| 14463 |
added = true; |
| 14464 |
} |
| 14465 |
} |
| 14466 |
if (!added) { |
| 14467 |
htmlElement.setAttribute("aria-label", label); |
| 14468 |
} |
| 14469 |
} |
| 14470 |
if (id !== undefined) { |
| 14471 |
htmlElement.setAttribute("aria-owns", id); |
| 14472 |
} |
| 14473 |
if (lang !== undefined) { |
| 14474 |
htmlElement.setAttribute("lang", removeNullCharacters(lang, true)); |
| 14475 |
} |
| 14476 |
} |
| 14477 |
#addImageInTextLayer(node, element) { |
| 14478 |
const { |
| 14479 |
alt, |
| 14480 |
bbox, |
| 14481 |
children |
| 14482 |
} = node; |
| 14483 |
const child = children?.[0]; |
| 14484 |
if (!this.#rawDims || !alt || !bbox || child?.type !== "content") { |
| 14485 |
return false; |
| 14486 |
} |
| 14487 |
const { |
| 14488 |
id |
| 14489 |
} = child; |
| 14490 |
if (!id) { |
| 14491 |
return false; |
| 14492 |
} |
| 14493 |
element.setAttribute("aria-owns", id); |
| 14494 |
const img = document.createElement("span"); |
| 14495 |
(this.#elementsToAddToTextLayer ||= new Map()).set(id, img); |
| 14496 |
img.setAttribute("role", "img"); |
| 14497 |
img.setAttribute("aria-label", removeNullCharacters(alt)); |
| 14498 |
const { |
| 14499 |
pageHeight, |
| 14500 |
pageX, |
| 14501 |
pageY |
| 14502 |
} = this.#rawDims; |
| 14503 |
const calc = "calc(var(--total-scale-factor) *"; |
| 14504 |
const { |
| 14505 |
style |
| 14506 |
} = img; |
| 14507 |
style.width = `${calc}${bbox[2] - bbox[0]}px)`; |
| 14508 |
style.height = `${calc}${bbox[3] - bbox[1]}px)`; |
| 14509 |
style.left = `${calc}${bbox[0] - pageX}px)`; |
| 14510 |
style.top = `${calc}${pageHeight - bbox[3] + pageY}px)`; |
| 14511 |
return true; |
| 14512 |
} |
| 14513 |
addElementsToTextLayer() { |
| 14514 |
if (!this.#elementsToAddToTextLayer) { |
| 14515 |
return; |
| 14516 |
} |
| 14517 |
for (const [id, img] of this.#elementsToAddToTextLayer) { |
| 14518 |
document.getElementById(id)?.append(img); |
| 14519 |
} |
| 14520 |
this.#elementsToAddToTextLayer.clear(); |
| 14521 |
this.#elementsToAddToTextLayer = null; |
| 14522 |
} |
| 14523 |
#walk(node) { |
| 14524 |
if (!node) { |
| 14525 |
return null; |
| 14526 |
} |
| 14527 |
const element = document.createElement("span"); |
| 14528 |
if ("role" in node) { |
| 14529 |
const { |
| 14530 |
role |
| 14531 |
} = node; |
| 14532 |
const match = role.match(HEADING_PATTERN); |
| 14533 |
if (match) { |
| 14534 |
element.setAttribute("role", "heading"); |
| 14535 |
element.setAttribute("aria-level", match[1]); |
| 14536 |
} else if (PDF_ROLE_TO_HTML_ROLE[role]) { |
| 14537 |
element.setAttribute("role", PDF_ROLE_TO_HTML_ROLE[role]); |
| 14538 |
} |
| 14539 |
if (role === "Figure" && this.#addImageInTextLayer(node, element)) { |
| 14540 |
return element; |
| 14541 |
} |
| 14542 |
} |
| 14543 |
this.#setAttributes(node, element); |
| 14544 |
if (node.children) { |
| 14545 |
if (node.children.length === 1 && "id" in node.children[0]) { |
| 14546 |
this.#setAttributes(node.children[0], element); |
| 14547 |
} else { |
| 14548 |
for (const kid of node.children) { |
| 14549 |
element.append(this.#walk(kid)); |
| 14550 |
} |
| 14551 |
} |
| 14552 |
} |
| 14553 |
return element; |
| 14554 |
} |
| 14555 |
} |
| 14556 |
|
| 14557 |
;// ./web/text_accessibility.js |
| 14558 |
|
| 14559 |
|
| 14560 |
|
| 14561 |
class TextAccessibilityManager { |
| 14562 |
#enabled = false; |
| 14563 |
#textChildren = null; |
| 14564 |
#textNodes = new Map(); |
| 14565 |
#waitingElements = new Map(); |
| 14566 |
setTextMapping(textDivs) { |
| 14567 |
this.#textChildren = textDivs; |
| 14568 |
} |
| 14569 |
static #compareElementPositions(e1, e2) { |
| 14570 |
const rect1 = e1.getBoundingClientRect(); |
| 14571 |
const rect2 = e2.getBoundingClientRect(); |
| 14572 |
if (rect1.width === 0 && rect1.height === 0) { |
| 14573 |
return +1; |
| 14574 |
} |
| 14575 |
if (rect2.width === 0 && rect2.height === 0) { |
| 14576 |
return -1; |
| 14577 |
} |
| 14578 |
const top1 = rect1.y; |
| 14579 |
const bot1 = rect1.y + rect1.height; |
| 14580 |
const mid1 = rect1.y + rect1.height / 2; |
| 14581 |
const top2 = rect2.y; |
| 14582 |
const bot2 = rect2.y + rect2.height; |
| 14583 |
const mid2 = rect2.y + rect2.height / 2; |
| 14584 |
if (mid1 <= top2 && mid2 >= bot1) { |
| 14585 |
return -1; |
| 14586 |
} |
| 14587 |
if (mid2 <= top1 && mid1 >= bot2) { |
| 14588 |
return +1; |
| 14589 |
} |
| 14590 |
const centerX1 = rect1.x + rect1.width / 2; |
| 14591 |
const centerX2 = rect2.x + rect2.width / 2; |
| 14592 |
return centerX1 - centerX2; |
| 14593 |
} |
| 14594 |
enable() { |
| 14595 |
if (this.#enabled) { |
| 14596 |
throw new Error("TextAccessibilityManager is already enabled."); |
| 14597 |
} |
| 14598 |
if (!this.#textChildren) { |
| 14599 |
throw new Error("Text divs and strings have not been set."); |
| 14600 |
} |
| 14601 |
this.#enabled = true; |
| 14602 |
this.#textChildren = this.#textChildren.slice(); |
| 14603 |
this.#textChildren.sort(TextAccessibilityManager.#compareElementPositions); |
| 14604 |
if (this.#textNodes.size > 0) { |
| 14605 |
const textChildren = this.#textChildren; |
| 14606 |
for (const [id, nodeIndex] of this.#textNodes) { |
| 14607 |
const element = document.getElementById(id); |
| 14608 |
if (!element) { |
| 14609 |
this.#textNodes.delete(id); |
| 14610 |
continue; |
| 14611 |
} |
| 14612 |
this.#addIdToAriaOwns(id, textChildren[nodeIndex]); |
| 14613 |
} |
| 14614 |
} |
| 14615 |
for (const [element, isRemovable] of this.#waitingElements) { |
| 14616 |
this.addPointerInTextLayer(element, isRemovable); |
| 14617 |
} |
| 14618 |
this.#waitingElements.clear(); |
| 14619 |
} |
| 14620 |
disable() { |
| 14621 |
if (!this.#enabled) { |
| 14622 |
return; |
| 14623 |
} |
| 14624 |
this.#waitingElements.clear(); |
| 14625 |
this.#textChildren = null; |
| 14626 |
this.#enabled = false; |
| 14627 |
} |
| 14628 |
removePointerInTextLayer(element) { |
| 14629 |
if (!this.#enabled) { |
| 14630 |
this.#waitingElements.delete(element); |
| 14631 |
return; |
| 14632 |
} |
| 14633 |
const children = this.#textChildren; |
| 14634 |
if (!children || children.length === 0) { |
| 14635 |
return; |
| 14636 |
} |
| 14637 |
const { |
| 14638 |
id |
| 14639 |
} = element; |
| 14640 |
const nodeIndex = this.#textNodes.get(id); |
| 14641 |
if (nodeIndex === undefined) { |
| 14642 |
return; |
| 14643 |
} |
| 14644 |
const node = children[nodeIndex]; |
| 14645 |
this.#textNodes.delete(id); |
| 14646 |
let owns = node.getAttribute("aria-owns"); |
| 14647 |
if (owns?.includes(id)) { |
| 14648 |
owns = owns.split(" ").filter(x => x !== id).join(" "); |
| 14649 |
if (owns) { |
| 14650 |
node.setAttribute("aria-owns", owns); |
| 14651 |
} else { |
| 14652 |
node.removeAttribute("aria-owns"); |
| 14653 |
node.setAttribute("role", "presentation"); |
| 14654 |
} |
| 14655 |
} |
| 14656 |
} |
| 14657 |
#addIdToAriaOwns(id, node) { |
| 14658 |
const owns = node.getAttribute("aria-owns"); |
| 14659 |
if (!owns?.includes(id)) { |
| 14660 |
node.setAttribute("aria-owns", owns ? `${owns} ${id}` : id); |
| 14661 |
} |
| 14662 |
node.removeAttribute("role"); |
| 14663 |
} |
| 14664 |
addPointerInTextLayer(element, isRemovable) { |
| 14665 |
const { |
| 14666 |
id |
| 14667 |
} = element; |
| 14668 |
if (!id) { |
| 14669 |
return null; |
| 14670 |
} |
| 14671 |
if (!this.#enabled) { |
| 14672 |
this.#waitingElements.set(element, isRemovable); |
| 14673 |
return null; |
| 14674 |
} |
| 14675 |
if (isRemovable) { |
| 14676 |
this.removePointerInTextLayer(element); |
| 14677 |
} |
| 14678 |
const children = this.#textChildren; |
| 14679 |
if (!children || children.length === 0) { |
| 14680 |
return null; |
| 14681 |
} |
| 14682 |
const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(element, node) < 0); |
| 14683 |
const nodeIndex = Math.max(0, index - 1); |
| 14684 |
const child = children[nodeIndex]; |
| 14685 |
this.#addIdToAriaOwns(id, child); |
| 14686 |
this.#textNodes.set(id, nodeIndex); |
| 14687 |
const parent = child.parentNode; |
| 14688 |
return parent?.classList.contains("markedContent") ? parent.id : null; |
| 14689 |
} |
| 14690 |
moveElementInDOM(container, element, contentElement, isRemovable) { |
| 14691 |
const id = this.addPointerInTextLayer(contentElement, isRemovable); |
| 14692 |
if (!container.hasChildNodes()) { |
| 14693 |
container.append(element); |
| 14694 |
return id; |
| 14695 |
} |
| 14696 |
const children = Array.from(container.childNodes).filter(node => node !== element); |
| 14697 |
if (children.length === 0) { |
| 14698 |
return id; |
| 14699 |
} |
| 14700 |
const elementToCompare = contentElement || element; |
| 14701 |
const index = binarySearchFirstItem(children, node => TextAccessibilityManager.#compareElementPositions(elementToCompare, node) < 0); |
| 14702 |
if (index === 0) { |
| 14703 |
children[0].before(element); |
| 14704 |
} else { |
| 14705 |
children[index - 1].after(element); |
| 14706 |
} |
| 14707 |
return id; |
| 14708 |
} |
| 14709 |
} |
| 14710 |
|
| 14711 |
;// ./web/text_highlighter.js |
| 14712 |
|
| 14713 |
class TextHighlighter { |
| 14714 |
#eventAbortController = null; |
| 14715 |
constructor({ |
| 14716 |
findController, |
| 14717 |
eventBus, |
| 14718 |
pageIndex |
| 14719 |
}) { |
| 14720 |
this.findController = findController; |
| 14721 |
this.matches = []; |
| 14722 |
this.eventBus = eventBus; |
| 14723 |
this.pageIdx = pageIndex; |
| 14724 |
this.textDivs = null; |
| 14725 |
this.textContentItemsStr = null; |
| 14726 |
this.enabled = false; |
| 14727 |
} |
| 14728 |
setTextMapping(divs, texts) { |
| 14729 |
this.textDivs = divs; |
| 14730 |
this.textContentItemsStr = texts; |
| 14731 |
} |
| 14732 |
enable() { |
| 14733 |
if (!this.textDivs || !this.textContentItemsStr) { |
| 14734 |
throw new Error("Text divs and strings have not been set."); |
| 14735 |
} |
| 14736 |
if (this.enabled) { |
| 14737 |
throw new Error("TextHighlighter is already enabled."); |
| 14738 |
} |
| 14739 |
this.enabled = true; |
| 14740 |
if (!this.#eventAbortController) { |
| 14741 |
this.#eventAbortController = new AbortController(); |
| 14742 |
this.eventBus._on("updatetextlayermatches", evt => { |
| 14743 |
if (evt.pageIndex === this.pageIdx || evt.pageIndex === -1) { |
| 14744 |
this._updateMatches(); |
| 14745 |
} |
| 14746 |
}, { |
| 14747 |
signal: this.#eventAbortController.signal |
| 14748 |
}); |
| 14749 |
} |
| 14750 |
this._updateMatches(); |
| 14751 |
} |
| 14752 |
disable() { |
| 14753 |
if (!this.enabled) { |
| 14754 |
return; |
| 14755 |
} |
| 14756 |
this.enabled = false; |
| 14757 |
this.#eventAbortController?.abort(); |
| 14758 |
this.#eventAbortController = null; |
| 14759 |
this._updateMatches(true); |
| 14760 |
} |
| 14761 |
_convertMatches(matches, matchesLength) { |
| 14762 |
if (!matches) { |
| 14763 |
return []; |
| 14764 |
} |
| 14765 |
const { |
| 14766 |
textContentItemsStr |
| 14767 |
} = this; |
| 14768 |
let i = 0, |
| 14769 |
iIndex = 0; |
| 14770 |
const end = textContentItemsStr.length - 1; |
| 14771 |
const result = []; |
| 14772 |
for (let m = 0, mm = matches.length; m < mm; m++) { |
| 14773 |
let matchIdx = matches[m]; |
| 14774 |
while (i !== end && matchIdx >= iIndex + textContentItemsStr[i].length) { |
| 14775 |
iIndex += textContentItemsStr[i].length; |
| 14776 |
i++; |
| 14777 |
} |
| 14778 |
if (i === textContentItemsStr.length) { |
| 14779 |
console.error("Could not find a matching mapping"); |
| 14780 |
} |
| 14781 |
const match = { |
| 14782 |
begin: { |
| 14783 |
divIdx: i, |
| 14784 |
offset: matchIdx - iIndex |
| 14785 |
} |
| 14786 |
}; |
| 14787 |
matchIdx += matchesLength[m]; |
| 14788 |
while (i !== end && matchIdx > iIndex + textContentItemsStr[i].length) { |
| 14789 |
iIndex += textContentItemsStr[i].length; |
| 14790 |
i++; |
| 14791 |
} |
| 14792 |
match.end = { |
| 14793 |
divIdx: i, |
| 14794 |
offset: matchIdx - iIndex |
| 14795 |
}; |
| 14796 |
result.push(match); |
| 14797 |
} |
| 14798 |
return result; |
| 14799 |
} |
| 14800 |
_renderMatches(matches) { |
| 14801 |
if (matches.length === 0) { |
| 14802 |
return; |
| 14803 |
} |
| 14804 |
const { |
| 14805 |
findController, |
| 14806 |
pageIdx |
| 14807 |
} = this; |
| 14808 |
const { |
| 14809 |
textContentItemsStr, |
| 14810 |
textDivs |
| 14811 |
} = this; |
| 14812 |
const isSelectedPage = pageIdx === findController.selected.pageIdx; |
| 14813 |
const selectedMatchIdx = findController.selected.matchIdx; |
| 14814 |
const highlightAll = findController.state.highlightAll; |
| 14815 |
let prevEnd = null; |
| 14816 |
const infinity = { |
| 14817 |
divIdx: -1, |
| 14818 |
offset: undefined |
| 14819 |
}; |
| 14820 |
function beginText(begin, className) { |
| 14821 |
const divIdx = begin.divIdx; |
| 14822 |
textDivs[divIdx].textContent = ""; |
| 14823 |
return appendTextToDiv(divIdx, 0, begin.offset, className); |
| 14824 |
} |
| 14825 |
function appendTextToDiv(divIdx, fromOffset, toOffset, className) { |
| 14826 |
let div = textDivs[divIdx]; |
| 14827 |
if (div.nodeType === Node.TEXT_NODE) { |
| 14828 |
const span = document.createElement("span"); |
| 14829 |
div.before(span); |
| 14830 |
span.append(div); |
| 14831 |
textDivs[divIdx] = span; |
| 14832 |
div = span; |
| 14833 |
} |
| 14834 |
const content = textContentItemsStr[divIdx].substring(fromOffset, toOffset); |
| 14835 |
const node = document.createTextNode(content); |
| 14836 |
if (className) { |
| 14837 |
const span = document.createElement("span"); |
| 14838 |
span.className = `${className} appended`; |
| 14839 |
span.append(node); |
| 14840 |
div.append(span); |
| 14841 |
if (className.includes("selected")) { |
| 14842 |
const { |
| 14843 |
left |
| 14844 |
} = span.getClientRects()[0]; |
| 14845 |
const parentLeft = div.getBoundingClientRect().left; |
| 14846 |
return left - parentLeft; |
| 14847 |
} |
| 14848 |
return 0; |
| 14849 |
} |
| 14850 |
div.append(node); |
| 14851 |
return 0; |
| 14852 |
} |
| 14853 |
let i0 = selectedMatchIdx, |
| 14854 |
i1 = i0 + 1; |
| 14855 |
if (highlightAll) { |
| 14856 |
i0 = 0; |
| 14857 |
i1 = matches.length; |
| 14858 |
} else if (!isSelectedPage) { |
| 14859 |
return; |
| 14860 |
} |
| 14861 |
let lastDivIdx = -1; |
| 14862 |
let lastOffset = -1; |
| 14863 |
for (let i = i0; i < i1; i++) { |
| 14864 |
const match = matches[i]; |
| 14865 |
const begin = match.begin; |
| 14866 |
if (begin.divIdx === lastDivIdx && begin.offset === lastOffset) { |
| 14867 |
continue; |
| 14868 |
} |
| 14869 |
lastDivIdx = begin.divIdx; |
| 14870 |
lastOffset = begin.offset; |
| 14871 |
const end = match.end; |
| 14872 |
const isSelected = isSelectedPage && i === selectedMatchIdx; |
| 14873 |
const highlightSuffix = isSelected ? " selected" : ""; |
| 14874 |
let selectedLeft = 0; |
| 14875 |
if (!prevEnd || begin.divIdx !== prevEnd.divIdx) { |
| 14876 |
if (prevEnd !== null) { |
| 14877 |
appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); |
| 14878 |
} |
| 14879 |
beginText(begin); |
| 14880 |
} else { |
| 14881 |
appendTextToDiv(prevEnd.divIdx, prevEnd.offset, begin.offset); |
| 14882 |
} |
| 14883 |
if (begin.divIdx === end.divIdx) { |
| 14884 |
selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, end.offset, "highlight" + highlightSuffix); |
| 14885 |
} else { |
| 14886 |
selectedLeft = appendTextToDiv(begin.divIdx, begin.offset, infinity.offset, "highlight begin" + highlightSuffix); |
| 14887 |
for (let n0 = begin.divIdx + 1, n1 = end.divIdx; n0 < n1; n0++) { |
| 14888 |
textDivs[n0].className = "highlight middle" + highlightSuffix; |
| 14889 |
} |
| 14890 |
beginText(end, "highlight end" + highlightSuffix); |
| 14891 |
} |
| 14892 |
prevEnd = end; |
| 14893 |
if (isSelected) { |
| 14894 |
findController.scrollMatchIntoView({ |
| 14895 |
element: textDivs[begin.divIdx], |
| 14896 |
selectedLeft, |
| 14897 |
pageIndex: pageIdx, |
| 14898 |
matchIndex: selectedMatchIdx |
| 14899 |
}); |
| 14900 |
} |
| 14901 |
} |
| 14902 |
if (prevEnd) { |
| 14903 |
appendTextToDiv(prevEnd.divIdx, prevEnd.offset, infinity.offset); |
| 14904 |
} |
| 14905 |
} |
| 14906 |
_updateMatches(reset = false) { |
| 14907 |
if (!this.enabled && !reset) { |
| 14908 |
return; |
| 14909 |
} |
| 14910 |
const { |
| 14911 |
findController, |
| 14912 |
matches, |
| 14913 |
pageIdx |
| 14914 |
} = this; |
| 14915 |
const { |
| 14916 |
textContentItemsStr, |
| 14917 |
textDivs |
| 14918 |
} = this; |
| 14919 |
let clearedUntilDivIdx = -1; |
| 14920 |
for (const match of matches) { |
| 14921 |
const begin = Math.max(clearedUntilDivIdx, match.begin.divIdx); |
| 14922 |
for (let n = begin, end = match.end.divIdx; n <= end; n++) { |
| 14923 |
const div = textDivs[n]; |
| 14924 |
div.textContent = textContentItemsStr[n]; |
| 14925 |
div.className = ""; |
| 14926 |
} |
| 14927 |
clearedUntilDivIdx = match.end.divIdx + 1; |
| 14928 |
} |
| 14929 |
if (!findController?.highlightMatches || reset) { |
| 14930 |
return; |
| 14931 |
} |
| 14932 |
const pageMatches = findController.pageMatches[pageIdx] || null; |
| 14933 |
const pageMatchesLength = findController.pageMatchesLength[pageIdx] || null; |
| 14934 |
this.matches = this._convertMatches(pageMatches, pageMatchesLength); |
| 14935 |
this._renderMatches(this.matches); |
| 14936 |
} |
| 14937 |
} |
| 14938 |
|
| 14939 |
;// ./web/text_layer_builder.js |
| 14940 |
|
| 14941 |
|
| 14942 |
|
| 14943 |
|
| 14944 |
|
| 14945 |
|
| 14946 |
|
| 14947 |
|
| 14948 |
|
| 14949 |
|
| 14950 |
|
| 14951 |
class TextLayerBuilder { |
| 14952 |
#enablePermissions = false; |
| 14953 |
#onAppend = null; |
| 14954 |
#renderingDone = false; |
| 14955 |
#textLayer = null; |
| 14956 |
static #textLayers = new Map(); |
| 14957 |
static #selectionChangeAbortController = null; |
| 14958 |
constructor({ |
| 14959 |
pdfPage, |
| 14960 |
highlighter = null, |
| 14961 |
accessibilityManager = null, |
| 14962 |
enablePermissions = false, |
| 14963 |
onAppend = null |
| 14964 |
}) { |
| 14965 |
this.pdfPage = pdfPage; |
| 14966 |
this.highlighter = highlighter; |
| 14967 |
this.accessibilityManager = accessibilityManager; |
| 14968 |
this.#enablePermissions = enablePermissions === true; |
| 14969 |
this.#onAppend = onAppend; |
| 14970 |
this.div = document.createElement("div"); |
| 14971 |
this.div.tabIndex = 0; |
| 14972 |
this.div.className = "textLayer"; |
| 14973 |
} |
| 14974 |
async render({ |
| 14975 |
viewport, |
| 14976 |
textContentParams = null |
| 14977 |
}) { |
| 14978 |
if (this.#renderingDone && this.#textLayer) { |
| 14979 |
this.#textLayer.update({ |
| 14980 |
viewport, |
| 14981 |
onBefore: this.hide.bind(this) |
| 14982 |
}); |
| 14983 |
this.show(); |
| 14984 |
return; |
| 14985 |
} |
| 14986 |
this.cancel(); |
| 14987 |
this.#textLayer = new TextLayer({ |
| 14988 |
textContentSource: this.pdfPage.streamTextContent(textContentParams || { |
| 14989 |
includeMarkedContent: true, |
| 14990 |
disableNormalization: true |
| 14991 |
}), |
| 14992 |
container: this.div, |
| 14993 |
viewport |
| 14994 |
}); |
| 14995 |
const { |
| 14996 |
textDivs, |
| 14997 |
textContentItemsStr |
| 14998 |
} = this.#textLayer; |
| 14999 |
this.highlighter?.setTextMapping(textDivs, textContentItemsStr); |
| 15000 |
this.accessibilityManager?.setTextMapping(textDivs); |
| 15001 |
await this.#textLayer.render(); |
| 15002 |
this.#renderingDone = true; |
| 15003 |
const endOfContent = document.createElement("div"); |
| 15004 |
endOfContent.className = "endOfContent"; |
| 15005 |
this.div.append(endOfContent); |
| 15006 |
this.#bindMouse(endOfContent); |
| 15007 |
this.#onAppend?.(this.div); |
| 15008 |
this.highlighter?.enable(); |
| 15009 |
this.accessibilityManager?.enable(); |
| 15010 |
} |
| 15011 |
hide() { |
| 15012 |
if (!this.div.hidden && this.#renderingDone) { |
| 15013 |
this.highlighter?.disable(); |
| 15014 |
this.div.hidden = true; |
| 15015 |
} |
| 15016 |
} |
| 15017 |
show() { |
| 15018 |
if (this.div.hidden && this.#renderingDone) { |
| 15019 |
this.div.hidden = false; |
| 15020 |
this.highlighter?.enable(); |
| 15021 |
} |
| 15022 |
} |
| 15023 |
cancel() { |
| 15024 |
this.#textLayer?.cancel(); |
| 15025 |
this.#textLayer = null; |
| 15026 |
this.highlighter?.disable(); |
| 15027 |
this.accessibilityManager?.disable(); |
| 15028 |
TextLayerBuilder.#removeGlobalSelectionListener(this.div); |
| 15029 |
} |
| 15030 |
#bindMouse(end) { |
| 15031 |
const { |
| 15032 |
div |
| 15033 |
} = this; |
| 15034 |
div.addEventListener("mousedown", () => { |
| 15035 |
div.classList.add("selecting"); |
| 15036 |
}); |
| 15037 |
div.addEventListener("copy", event => { |
| 15038 |
if (!this.#enablePermissions) { |
| 15039 |
const selection = document.getSelection(); |
| 15040 |
event.clipboardData.setData("text/plain", removeNullCharacters(normalizeUnicode(selection.toString()))); |
| 15041 |
} |
| 15042 |
stopEvent(event); |
| 15043 |
}); |
| 15044 |
TextLayerBuilder.#textLayers.set(div, end); |
| 15045 |
TextLayerBuilder.#enableGlobalSelectionListener(); |
| 15046 |
} |
| 15047 |
static #removeGlobalSelectionListener(textLayerDiv) { |
| 15048 |
this.#textLayers.delete(textLayerDiv); |
| 15049 |
if (this.#textLayers.size === 0) { |
| 15050 |
this.#selectionChangeAbortController?.abort(); |
| 15051 |
this.#selectionChangeAbortController = null; |
| 15052 |
} |
| 15053 |
} |
| 15054 |
static #enableGlobalSelectionListener() { |
| 15055 |
if (this.#selectionChangeAbortController) { |
| 15056 |
return; |
| 15057 |
} |
| 15058 |
this.#selectionChangeAbortController = new AbortController(); |
| 15059 |
const { |
| 15060 |
signal |
| 15061 |
} = this.#selectionChangeAbortController; |
| 15062 |
const reset = (end, textLayer) => { |
| 15063 |
textLayer.append(end); |
| 15064 |
end.style.width = ""; |
| 15065 |
end.style.height = ""; |
| 15066 |
textLayer.classList.remove("selecting"); |
| 15067 |
}; |
| 15068 |
let isPointerDown = false; |
| 15069 |
document.addEventListener("pointerdown", () => { |
| 15070 |
isPointerDown = true; |
| 15071 |
}, { |
| 15072 |
signal |
| 15073 |
}); |
| 15074 |
document.addEventListener("pointerup", () => { |
| 15075 |
isPointerDown = false; |
| 15076 |
this.#textLayers.forEach(reset); |
| 15077 |
}, { |
| 15078 |
signal |
| 15079 |
}); |
| 15080 |
window.addEventListener("blur", () => { |
| 15081 |
isPointerDown = false; |
| 15082 |
this.#textLayers.forEach(reset); |
| 15083 |
}, { |
| 15084 |
signal |
| 15085 |
}); |
| 15086 |
document.addEventListener("keyup", () => { |
| 15087 |
if (!isPointerDown) { |
| 15088 |
this.#textLayers.forEach(reset); |
| 15089 |
} |
| 15090 |
}, { |
| 15091 |
signal |
| 15092 |
}); |
| 15093 |
var isFirefox, prevRange; |
| 15094 |
document.addEventListener("selectionchange", () => { |
| 15095 |
const selection = document.getSelection(); |
| 15096 |
if (selection.rangeCount === 0) { |
| 15097 |
this.#textLayers.forEach(reset); |
| 15098 |
return; |
| 15099 |
} |
| 15100 |
const activeTextLayers = new Set(); |
| 15101 |
for (let i = 0; i < selection.rangeCount; i++) { |
| 15102 |
const range = selection.getRangeAt(i); |
| 15103 |
for (const textLayerDiv of this.#textLayers.keys()) { |
| 15104 |
if (!activeTextLayers.has(textLayerDiv) && range.intersectsNode(textLayerDiv)) { |
| 15105 |
activeTextLayers.add(textLayerDiv); |
| 15106 |
} |
| 15107 |
} |
| 15108 |
} |
| 15109 |
for (const [textLayerDiv, endDiv] of this.#textLayers) { |
| 15110 |
if (activeTextLayers.has(textLayerDiv)) { |
| 15111 |
textLayerDiv.classList.add("selecting"); |
| 15112 |
} else { |
| 15113 |
reset(endDiv, textLayerDiv); |
| 15114 |
} |
| 15115 |
} |
| 15116 |
isFirefox ??= getComputedStyle(this.#textLayers.values().next().value).getPropertyValue("-moz-user-select") === "none"; |
| 15117 |
if (isFirefox) { |
| 15118 |
return; |
| 15119 |
} |
| 15120 |
const range = selection.getRangeAt(0); |
| 15121 |
const modifyStart = prevRange && (range.compareBoundaryPoints(Range.END_TO_END, prevRange) === 0 || range.compareBoundaryPoints(Range.START_TO_END, prevRange) === 0); |
| 15122 |
let anchor = modifyStart ? range.startContainer : range.endContainer; |
| 15123 |
if (anchor.nodeType === Node.TEXT_NODE) { |
| 15124 |
anchor = anchor.parentNode; |
| 15125 |
} |
| 15126 |
if (!modifyStart && range.endOffset === 0) { |
| 15127 |
do { |
| 15128 |
while (!anchor.previousSibling) { |
| 15129 |
anchor = anchor.parentNode; |
| 15130 |
} |
| 15131 |
anchor = anchor.previousSibling; |
| 15132 |
} while (!anchor.childNodes.length); |
| 15133 |
} |
| 15134 |
const parentTextLayer = anchor.parentElement?.closest(".textLayer"); |
| 15135 |
const endDiv = this.#textLayers.get(parentTextLayer); |
| 15136 |
if (endDiv) { |
| 15137 |
endDiv.style.width = parentTextLayer.style.width; |
| 15138 |
endDiv.style.height = parentTextLayer.style.height; |
| 15139 |
anchor.parentElement.insertBefore(endDiv, modifyStart ? anchor : anchor.nextSibling); |
| 15140 |
} |
| 15141 |
prevRange = range.cloneRange(); |
| 15142 |
}, { |
| 15143 |
signal |
| 15144 |
}); |
| 15145 |
} |
| 15146 |
} |
| 15147 |
|
| 15148 |
;// ./web/pdf_page_view.js |
| 15149 |
|
| 15150 |
|
| 15151 |
|
| 15152 |
|
| 15153 |
|
| 15154 |
|
| 15155 |
|
| 15156 |
|
| 15157 |
|
| 15158 |
|
| 15159 |
|
| 15160 |
|
| 15161 |
|
| 15162 |
|
| 15163 |
|
| 15164 |
|
| 15165 |
|
| 15166 |
const DEFAULT_LAYER_PROPERTIES = null; |
| 15167 |
const LAYERS_ORDER = new Map([["canvasWrapper", 0], ["textLayer", 1], ["annotationLayer", 2], ["annotationEditorLayer", 3], ["xfaLayer", 3]]); |
| 15168 |
class PDFPageView extends BasePDFPageView { |
| 15169 |
#annotationMode = AnnotationMode.ENABLE_FORMS; |
| 15170 |
#canvasWrapper = null; |
| 15171 |
#enableAutoLinking = true; |
| 15172 |
#hasRestrictedScaling = false; |
| 15173 |
#isEditing = false; |
| 15174 |
#layerProperties = null; |
| 15175 |
#needsRestrictedScaling = false; |
| 15176 |
#originalViewport = null; |
| 15177 |
#previousRotation = null; |
| 15178 |
#scaleRoundX = 1; |
| 15179 |
#scaleRoundY = 1; |
| 15180 |
#textLayerMode = TextLayerMode.ENABLE; |
| 15181 |
#userUnit = 1; |
| 15182 |
#useThumbnailCanvas = { |
| 15183 |
directDrawing: true, |
| 15184 |
initialOptionalContent: true, |
| 15185 |
regularAnnotations: true |
| 15186 |
}; |
| 15187 |
#layers = [null, null, null, null]; |
| 15188 |
constructor(options) { |
| 15189 |
super(options); |
| 15190 |
const container = options.container; |
| 15191 |
const defaultViewport = options.defaultViewport; |
| 15192 |
this.renderingId = "page" + this.id; |
| 15193 |
this.#layerProperties = options.layerProperties || DEFAULT_LAYER_PROPERTIES; |
| 15194 |
this.pdfPage = null; |
| 15195 |
this.pageLabel = null; |
| 15196 |
this.rotation = 0; |
| 15197 |
this.scale = options.scale || DEFAULT_SCALE; |
| 15198 |
this.viewport = defaultViewport; |
| 15199 |
this.pdfPageRotate = defaultViewport.rotation; |
| 15200 |
this._optionalContentConfigPromise = options.optionalContentConfigPromise || null; |
| 15201 |
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE; |
| 15202 |
this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS; |
| 15203 |
this.imageResourcesPath = options.imageResourcesPath || ""; |
| 15204 |
this.enableDetailCanvas = options.enableDetailCanvas ?? true; |
| 15205 |
this.maxCanvasPixels = options.maxCanvasPixels ?? AppOptions.get("maxCanvasPixels"); |
| 15206 |
this.maxCanvasDim = options.maxCanvasDim || AppOptions.get("maxCanvasDim"); |
| 15207 |
this.capCanvasAreaFactor = options.capCanvasAreaFactor ?? AppOptions.get("capCanvasAreaFactor"); |
| 15208 |
this.#enableAutoLinking = options.enableAutoLinking !== false; |
| 15209 |
this.l10n = options.l10n; |
| 15210 |
this.l10n ||= new genericl10n_GenericL10n(); |
| 15211 |
this._isStandalone = !this.renderingQueue?.hasViewer(); |
| 15212 |
this._container = container; |
| 15213 |
this._annotationCanvasMap = null; |
| 15214 |
this.annotationLayer = null; |
| 15215 |
this.annotationEditorLayer = null; |
| 15216 |
this.textLayer = null; |
| 15217 |
this.xfaLayer = null; |
| 15218 |
this.structTreeLayer = null; |
| 15219 |
this.drawLayer = null; |
| 15220 |
this.detailView = null; |
| 15221 |
const div = document.createElement("div"); |
| 15222 |
div.className = "page"; |
| 15223 |
div.setAttribute("data-page-number", this.id); |
| 15224 |
div.setAttribute("role", "region"); |
| 15225 |
div.setAttribute("data-l10n-id", "pdfjs-page-landmark"); |
| 15226 |
div.setAttribute("data-l10n-args", JSON.stringify({ |
| 15227 |
page: this.id |
| 15228 |
})); |
| 15229 |
this.div = div; |
| 15230 |
this.#setDimensions(); |
| 15231 |
container?.append(div); |
| 15232 |
if (this._isStandalone) { |
| 15233 |
container?.style.setProperty("--scale-factor", this.scale * PixelsPerInch.PDF_TO_CSS_UNITS); |
| 15234 |
if (this.pageColors?.background) { |
| 15235 |
container?.style.setProperty("--page-bg-color", this.pageColors.background); |
| 15236 |
} |
| 15237 |
const { |
| 15238 |
optionalContentConfigPromise |
| 15239 |
} = options; |
| 15240 |
if (optionalContentConfigPromise) { |
| 15241 |
optionalContentConfigPromise.then(optionalContentConfig => { |
| 15242 |
if (optionalContentConfigPromise !== this._optionalContentConfigPromise) { |
| 15243 |
return; |
| 15244 |
} |
| 15245 |
this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility; |
| 15246 |
}); |
| 15247 |
} |
| 15248 |
if (!options.l10n) { |
| 15249 |
this.l10n.translate(this.div); |
| 15250 |
} |
| 15251 |
} |
| 15252 |
} |
| 15253 |
#addLayer(div, name) { |
| 15254 |
const pos = LAYERS_ORDER.get(name); |
| 15255 |
const oldDiv = this.#layers[pos]; |
| 15256 |
this.#layers[pos] = div; |
| 15257 |
if (oldDiv) { |
| 15258 |
oldDiv.replaceWith(div); |
| 15259 |
return; |
| 15260 |
} |
| 15261 |
for (let i = pos - 1; i >= 0; i--) { |
| 15262 |
const layer = this.#layers[i]; |
| 15263 |
if (layer) { |
| 15264 |
layer.after(div); |
| 15265 |
return; |
| 15266 |
} |
| 15267 |
} |
| 15268 |
this.div.prepend(div); |
| 15269 |
} |
| 15270 |
#setDimensions() { |
| 15271 |
const { |
| 15272 |
div, |
| 15273 |
viewport |
| 15274 |
} = this; |
| 15275 |
if (viewport.userUnit !== this.#userUnit) { |
| 15276 |
if (viewport.userUnit !== 1) { |
| 15277 |
div.style.setProperty("--user-unit", viewport.userUnit); |
| 15278 |
} else { |
| 15279 |
div.style.removeProperty("--user-unit"); |
| 15280 |
} |
| 15281 |
this.#userUnit = viewport.userUnit; |
| 15282 |
} |
| 15283 |
if (this.pdfPage) { |
| 15284 |
if (this.#previousRotation === viewport.rotation) { |
| 15285 |
return; |
| 15286 |
} |
| 15287 |
this.#previousRotation = viewport.rotation; |
| 15288 |
} |
| 15289 |
setLayerDimensions(div, viewport, true, false); |
| 15290 |
} |
| 15291 |
setPdfPage(pdfPage) { |
| 15292 |
if (this._isStandalone && (this.pageColors?.foreground === "CanvasText" || this.pageColors?.background === "Canvas")) { |
| 15293 |
this._container?.style.setProperty("--hcm-highlight-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight")); |
| 15294 |
this._container?.style.setProperty("--hcm-highlight-selected-filter", pdfPage.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "Highlight")); |
| 15295 |
} |
| 15296 |
this.pdfPage = pdfPage; |
| 15297 |
this.pdfPageRotate = pdfPage.rotate; |
| 15298 |
const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 15299 |
this.viewport = pdfPage.getViewport({ |
| 15300 |
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS, |
| 15301 |
rotation: totalRotation |
| 15302 |
}); |
| 15303 |
this.#setDimensions(); |
| 15304 |
this.reset(); |
| 15305 |
} |
| 15306 |
destroy() { |
| 15307 |
this.reset(); |
| 15308 |
this.pdfPage?.cleanup(); |
| 15309 |
} |
| 15310 |
hasEditableAnnotations() { |
| 15311 |
return !!this.annotationLayer?.hasEditableAnnotations(); |
| 15312 |
} |
| 15313 |
get _textHighlighter() { |
| 15314 |
return shadow(this, "_textHighlighter", new TextHighlighter({ |
| 15315 |
pageIndex: this.id - 1, |
| 15316 |
eventBus: this.eventBus, |
| 15317 |
findController: this.#layerProperties.findController |
| 15318 |
})); |
| 15319 |
} |
| 15320 |
#dispatchLayerRendered(name, error) { |
| 15321 |
this.eventBus.dispatch(name, { |
| 15322 |
source: this, |
| 15323 |
pageNumber: this.id, |
| 15324 |
error |
| 15325 |
}); |
| 15326 |
} |
| 15327 |
async #renderAnnotationLayer() { |
| 15328 |
let error = null; |
| 15329 |
try { |
| 15330 |
await this.annotationLayer.render({ |
| 15331 |
viewport: this.viewport, |
| 15332 |
intent: "display", |
| 15333 |
structTreeLayer: this.structTreeLayer |
| 15334 |
}); |
| 15335 |
} catch (ex) { |
| 15336 |
console.error("#renderAnnotationLayer:", ex); |
| 15337 |
error = ex; |
| 15338 |
} finally { |
| 15339 |
this.#dispatchLayerRendered("annotationlayerrendered", error); |
| 15340 |
} |
| 15341 |
} |
| 15342 |
async #renderAnnotationEditorLayer() { |
| 15343 |
let error = null; |
| 15344 |
try { |
| 15345 |
await this.annotationEditorLayer.render({ |
| 15346 |
viewport: this.viewport, |
| 15347 |
intent: "display" |
| 15348 |
}); |
| 15349 |
} catch (ex) { |
| 15350 |
console.error("#renderAnnotationEditorLayer:", ex); |
| 15351 |
error = ex; |
| 15352 |
} finally { |
| 15353 |
this.#dispatchLayerRendered("annotationeditorlayerrendered", error); |
| 15354 |
} |
| 15355 |
} |
| 15356 |
async #renderDrawLayer() { |
| 15357 |
try { |
| 15358 |
await this.drawLayer.render({ |
| 15359 |
intent: "display" |
| 15360 |
}); |
| 15361 |
} catch (ex) { |
| 15362 |
console.error("#renderDrawLayer:", ex); |
| 15363 |
} |
| 15364 |
} |
| 15365 |
async #renderXfaLayer() { |
| 15366 |
let error = null; |
| 15367 |
try { |
| 15368 |
const result = await this.xfaLayer.render({ |
| 15369 |
viewport: this.viewport, |
| 15370 |
intent: "display" |
| 15371 |
}); |
| 15372 |
if (result?.textDivs && this._textHighlighter) { |
| 15373 |
this.#buildXfaTextContentItems(result.textDivs); |
| 15374 |
} |
| 15375 |
} catch (ex) { |
| 15376 |
console.error("#renderXfaLayer:", ex); |
| 15377 |
error = ex; |
| 15378 |
} finally { |
| 15379 |
if (this.xfaLayer?.div) { |
| 15380 |
this.l10n.pause(); |
| 15381 |
this.#addLayer(this.xfaLayer.div, "xfaLayer"); |
| 15382 |
this.l10n.resume(); |
| 15383 |
} |
| 15384 |
this.#dispatchLayerRendered("xfalayerrendered", error); |
| 15385 |
} |
| 15386 |
} |
| 15387 |
async #renderTextLayer() { |
| 15388 |
if (!this.textLayer) { |
| 15389 |
return; |
| 15390 |
} |
| 15391 |
let error = null; |
| 15392 |
try { |
| 15393 |
await this.textLayer.render({ |
| 15394 |
viewport: this.viewport |
| 15395 |
}); |
| 15396 |
} catch (ex) { |
| 15397 |
if (ex instanceof AbortException) { |
| 15398 |
return; |
| 15399 |
} |
| 15400 |
console.error("#renderTextLayer:", ex); |
| 15401 |
error = ex; |
| 15402 |
} |
| 15403 |
this.#dispatchLayerRendered("textlayerrendered", error); |
| 15404 |
this.#renderStructTreeLayer(); |
| 15405 |
} |
| 15406 |
async #renderStructTreeLayer() { |
| 15407 |
if (!this.textLayer) { |
| 15408 |
return; |
| 15409 |
} |
| 15410 |
const treeDom = await this.structTreeLayer?.render(); |
| 15411 |
if (treeDom) { |
| 15412 |
this.l10n.pause(); |
| 15413 |
this.structTreeLayer?.addElementsToTextLayer(); |
| 15414 |
if (this.canvas && treeDom.parentNode !== this.canvas) { |
| 15415 |
this.canvas.append(treeDom); |
| 15416 |
} |
| 15417 |
this.l10n.resume(); |
| 15418 |
} |
| 15419 |
this.structTreeLayer?.show(); |
| 15420 |
} |
| 15421 |
async #buildXfaTextContentItems(textDivs) { |
| 15422 |
const text = await this.pdfPage.getTextContent(); |
| 15423 |
const items = []; |
| 15424 |
for (const item of text.items) { |
| 15425 |
items.push(item.str); |
| 15426 |
} |
| 15427 |
this._textHighlighter.setTextMapping(textDivs, items); |
| 15428 |
this._textHighlighter.enable(); |
| 15429 |
} |
| 15430 |
async #injectLinkAnnotations(textLayerPromise) { |
| 15431 |
let error = null; |
| 15432 |
try { |
| 15433 |
await textLayerPromise; |
| 15434 |
if (!this.annotationLayer) { |
| 15435 |
return; |
| 15436 |
} |
| 15437 |
await this.annotationLayer.injectLinkAnnotations({ |
| 15438 |
inferredLinks: Autolinker.processLinks(this), |
| 15439 |
viewport: this.viewport, |
| 15440 |
structTreeLayer: this.structTreeLayer |
| 15441 |
}); |
| 15442 |
} catch (ex) { |
| 15443 |
console.error("#injectLinkAnnotations:", ex); |
| 15444 |
error = ex; |
| 15445 |
} |
| 15446 |
} |
| 15447 |
_resetCanvas() { |
| 15448 |
super._resetCanvas(); |
| 15449 |
this.#originalViewport = null; |
| 15450 |
} |
| 15451 |
reset({ |
| 15452 |
keepAnnotationLayer = false, |
| 15453 |
keepAnnotationEditorLayer = false, |
| 15454 |
keepXfaLayer = false, |
| 15455 |
keepTextLayer = false, |
| 15456 |
keepCanvasWrapper = false, |
| 15457 |
preserveDetailViewState = false |
| 15458 |
} = {}) { |
| 15459 |
this.cancelRendering({ |
| 15460 |
keepAnnotationLayer, |
| 15461 |
keepAnnotationEditorLayer, |
| 15462 |
keepXfaLayer, |
| 15463 |
keepTextLayer |
| 15464 |
}); |
| 15465 |
this.renderingState = RenderingStates.INITIAL; |
| 15466 |
const div = this.div; |
| 15467 |
const childNodes = div.childNodes, |
| 15468 |
annotationLayerNode = keepAnnotationLayer && this.annotationLayer?.div || null, |
| 15469 |
annotationEditorLayerNode = keepAnnotationEditorLayer && this.annotationEditorLayer?.div || null, |
| 15470 |
xfaLayerNode = keepXfaLayer && this.xfaLayer?.div || null, |
| 15471 |
textLayerNode = keepTextLayer && this.textLayer?.div || null, |
| 15472 |
canvasWrapperNode = keepCanvasWrapper && this.#canvasWrapper || null; |
| 15473 |
for (let i = childNodes.length - 1; i >= 0; i--) { |
| 15474 |
const node = childNodes[i]; |
| 15475 |
switch (node) { |
| 15476 |
case annotationLayerNode: |
| 15477 |
case annotationEditorLayerNode: |
| 15478 |
case xfaLayerNode: |
| 15479 |
case textLayerNode: |
| 15480 |
case canvasWrapperNode: |
| 15481 |
continue; |
| 15482 |
} |
| 15483 |
node.remove(); |
| 15484 |
const layerIndex = this.#layers.indexOf(node); |
| 15485 |
if (layerIndex >= 0) { |
| 15486 |
this.#layers[layerIndex] = null; |
| 15487 |
} |
| 15488 |
} |
| 15489 |
div.removeAttribute("data-loaded"); |
| 15490 |
if (annotationLayerNode) { |
| 15491 |
this.annotationLayer.hide(); |
| 15492 |
} |
| 15493 |
if (annotationEditorLayerNode) { |
| 15494 |
this.annotationEditorLayer.hide(); |
| 15495 |
} |
| 15496 |
if (xfaLayerNode) { |
| 15497 |
this.xfaLayer.hide(); |
| 15498 |
} |
| 15499 |
if (textLayerNode) { |
| 15500 |
this.textLayer.hide(); |
| 15501 |
} |
| 15502 |
this.structTreeLayer?.hide(); |
| 15503 |
if (!keepCanvasWrapper && this.#canvasWrapper) { |
| 15504 |
this.#canvasWrapper = null; |
| 15505 |
this._resetCanvas(); |
| 15506 |
} |
| 15507 |
if (!preserveDetailViewState) { |
| 15508 |
this.detailView?.reset({ |
| 15509 |
keepCanvas: keepCanvasWrapper |
| 15510 |
}); |
| 15511 |
if (!keepCanvasWrapper) { |
| 15512 |
this.detailView = null; |
| 15513 |
} |
| 15514 |
} |
| 15515 |
} |
| 15516 |
toggleEditingMode(isEditing) { |
| 15517 |
this.#isEditing = isEditing; |
| 15518 |
if (!this.hasEditableAnnotations()) { |
| 15519 |
return; |
| 15520 |
} |
| 15521 |
this.reset({ |
| 15522 |
keepAnnotationLayer: true, |
| 15523 |
keepAnnotationEditorLayer: true, |
| 15524 |
keepXfaLayer: true, |
| 15525 |
keepTextLayer: true, |
| 15526 |
keepCanvasWrapper: true |
| 15527 |
}); |
| 15528 |
} |
| 15529 |
updateVisibleArea(visibleArea) { |
| 15530 |
if (this.enableDetailCanvas) { |
| 15531 |
if (this.#needsRestrictedScaling && this.maxCanvasPixels > 0 && visibleArea) { |
| 15532 |
this.detailView ??= new PDFPageDetailView({ |
| 15533 |
pageView: this |
| 15534 |
}); |
| 15535 |
this.detailView.update({ |
| 15536 |
visibleArea |
| 15537 |
}); |
| 15538 |
} else if (this.detailView) { |
| 15539 |
this.detailView.reset(); |
| 15540 |
this.detailView = null; |
| 15541 |
} |
| 15542 |
} |
| 15543 |
} |
| 15544 |
update({ |
| 15545 |
scale = 0, |
| 15546 |
rotation = null, |
| 15547 |
optionalContentConfigPromise = null, |
| 15548 |
drawingDelay = -1 |
| 15549 |
}) { |
| 15550 |
this.scale = scale || this.scale; |
| 15551 |
if (typeof rotation === "number") { |
| 15552 |
this.rotation = rotation; |
| 15553 |
} |
| 15554 |
if (optionalContentConfigPromise instanceof Promise) { |
| 15555 |
this._optionalContentConfigPromise = optionalContentConfigPromise; |
| 15556 |
optionalContentConfigPromise.then(optionalContentConfig => { |
| 15557 |
if (optionalContentConfigPromise !== this._optionalContentConfigPromise) { |
| 15558 |
return; |
| 15559 |
} |
| 15560 |
this.#useThumbnailCanvas.initialOptionalContent = optionalContentConfig.hasInitialVisibility; |
| 15561 |
}); |
| 15562 |
} |
| 15563 |
this.#useThumbnailCanvas.directDrawing = true; |
| 15564 |
const totalRotation = (this.rotation + this.pdfPageRotate) % 360; |
| 15565 |
this.viewport = this.viewport.clone({ |
| 15566 |
scale: this.scale * PixelsPerInch.PDF_TO_CSS_UNITS, |
| 15567 |
rotation: totalRotation |
| 15568 |
}); |
| 15569 |
this.#setDimensions(); |
| 15570 |
if (this._isStandalone) { |
| 15571 |
this._container?.style.setProperty("--scale-factor", this.viewport.scale); |
| 15572 |
} |
| 15573 |
this.#computeScale(); |
| 15574 |
if (this.canvas) { |
| 15575 |
const onlyCssZoom = this.#hasRestrictedScaling && this.#needsRestrictedScaling; |
| 15576 |
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000; |
| 15577 |
if (postponeDrawing || onlyCssZoom) { |
| 15578 |
if (postponeDrawing && !onlyCssZoom && this.renderingState !== RenderingStates.FINISHED) { |
| 15579 |
this.cancelRendering({ |
| 15580 |
keepAnnotationLayer: true, |
| 15581 |
keepAnnotationEditorLayer: true, |
| 15582 |
keepXfaLayer: true, |
| 15583 |
keepTextLayer: true, |
| 15584 |
cancelExtraDelay: drawingDelay |
| 15585 |
}); |
| 15586 |
this.renderingState = RenderingStates.FINISHED; |
| 15587 |
this.#useThumbnailCanvas.directDrawing = false; |
| 15588 |
} |
| 15589 |
this.cssTransform({ |
| 15590 |
redrawAnnotationLayer: true, |
| 15591 |
redrawAnnotationEditorLayer: true, |
| 15592 |
redrawXfaLayer: true, |
| 15593 |
redrawTextLayer: !postponeDrawing, |
| 15594 |
hideTextLayer: postponeDrawing |
| 15595 |
}); |
| 15596 |
if (!postponeDrawing) { |
| 15597 |
this.detailView?.update({ |
| 15598 |
underlyingViewUpdated: true |
| 15599 |
}); |
| 15600 |
this.dispatchPageRendered(true, false); |
| 15601 |
} |
| 15602 |
return; |
| 15603 |
} |
| 15604 |
} |
| 15605 |
this.cssTransform({}); |
| 15606 |
this.reset({ |
| 15607 |
keepAnnotationLayer: true, |
| 15608 |
keepAnnotationEditorLayer: true, |
| 15609 |
keepXfaLayer: true, |
| 15610 |
keepTextLayer: true, |
| 15611 |
keepCanvasWrapper: true, |
| 15612 |
preserveDetailViewState: true |
| 15613 |
}); |
| 15614 |
this.detailView?.update({ |
| 15615 |
underlyingViewUpdated: true |
| 15616 |
}); |
| 15617 |
} |
| 15618 |
#computeScale() { |
| 15619 |
const { |
| 15620 |
width, |
| 15621 |
height |
| 15622 |
} = this.viewport; |
| 15623 |
const outputScale = this.outputScale = new OutputScale(); |
| 15624 |
if (this.maxCanvasPixels === 0) { |
| 15625 |
const invScale = 1 / this.scale; |
| 15626 |
outputScale.sx *= invScale; |
| 15627 |
outputScale.sy *= invScale; |
| 15628 |
this.#needsRestrictedScaling = true; |
| 15629 |
} else { |
| 15630 |
this.#needsRestrictedScaling = outputScale.limitCanvas(width, height, this.maxCanvasPixels, this.maxCanvasDim, this.capCanvasAreaFactor); |
| 15631 |
} |
| 15632 |
} |
| 15633 |
cancelRendering({ |
| 15634 |
keepAnnotationLayer = false, |
| 15635 |
keepAnnotationEditorLayer = false, |
| 15636 |
keepXfaLayer = false, |
| 15637 |
keepTextLayer = false, |
| 15638 |
cancelExtraDelay = 0 |
| 15639 |
} = {}) { |
| 15640 |
super.cancelRendering({ |
| 15641 |
cancelExtraDelay |
| 15642 |
}); |
| 15643 |
if (this.textLayer && (!keepTextLayer || !this.textLayer.div)) { |
| 15644 |
this.textLayer.cancel(); |
| 15645 |
this.textLayer = null; |
| 15646 |
} |
| 15647 |
if (this.annotationLayer && (!keepAnnotationLayer || !this.annotationLayer.div)) { |
| 15648 |
this.annotationLayer.cancel(); |
| 15649 |
this.annotationLayer = null; |
| 15650 |
this._annotationCanvasMap = null; |
| 15651 |
} |
| 15652 |
if (this.structTreeLayer && !this.textLayer) { |
| 15653 |
this.structTreeLayer = null; |
| 15654 |
} |
| 15655 |
if (this.annotationEditorLayer && (!keepAnnotationEditorLayer || !this.annotationEditorLayer.div)) { |
| 15656 |
if (this.drawLayer) { |
| 15657 |
this.drawLayer.cancel(); |
| 15658 |
this.drawLayer = null; |
| 15659 |
} |
| 15660 |
this.annotationEditorLayer.cancel(); |
| 15661 |
this.annotationEditorLayer = null; |
| 15662 |
} |
| 15663 |
if (this.xfaLayer && (!keepXfaLayer || !this.xfaLayer.div)) { |
| 15664 |
this.xfaLayer.cancel(); |
| 15665 |
this.xfaLayer = null; |
| 15666 |
this._textHighlighter?.disable(); |
| 15667 |
} |
| 15668 |
} |
| 15669 |
cssTransform({ |
| 15670 |
redrawAnnotationLayer = false, |
| 15671 |
redrawAnnotationEditorLayer = false, |
| 15672 |
redrawXfaLayer = false, |
| 15673 |
redrawTextLayer = false, |
| 15674 |
hideTextLayer = false |
| 15675 |
}) { |
| 15676 |
const { |
| 15677 |
canvas |
| 15678 |
} = this; |
| 15679 |
if (!canvas) { |
| 15680 |
return; |
| 15681 |
} |
| 15682 |
const originalViewport = this.#originalViewport; |
| 15683 |
if (this.viewport !== originalViewport) { |
| 15684 |
const relativeRotation = (360 + this.viewport.rotation - originalViewport.rotation) % 360; |
| 15685 |
if (relativeRotation === 90 || relativeRotation === 270) { |
| 15686 |
const { |
| 15687 |
width, |
| 15688 |
height |
| 15689 |
} = this.viewport; |
| 15690 |
const scaleX = height / width; |
| 15691 |
const scaleY = width / height; |
| 15692 |
canvas.style.transform = `rotate(${relativeRotation}deg) scale(${scaleX},${scaleY})`; |
| 15693 |
} else { |
| 15694 |
canvas.style.transform = relativeRotation === 0 ? "" : `rotate(${relativeRotation}deg)`; |
| 15695 |
} |
| 15696 |
} |
| 15697 |
if (redrawAnnotationLayer && this.annotationLayer) { |
| 15698 |
this.#renderAnnotationLayer(); |
| 15699 |
} |
| 15700 |
if (redrawAnnotationEditorLayer && this.annotationEditorLayer) { |
| 15701 |
if (this.drawLayer) { |
| 15702 |
this.#renderDrawLayer(); |
| 15703 |
} |
| 15704 |
this.#renderAnnotationEditorLayer(); |
| 15705 |
} |
| 15706 |
if (redrawXfaLayer && this.xfaLayer) { |
| 15707 |
this.#renderXfaLayer(); |
| 15708 |
} |
| 15709 |
if (this.textLayer) { |
| 15710 |
if (hideTextLayer) { |
| 15711 |
this.textLayer.hide(); |
| 15712 |
this.structTreeLayer?.hide(); |
| 15713 |
} else if (redrawTextLayer) { |
| 15714 |
this.#renderTextLayer(); |
| 15715 |
} |
| 15716 |
} |
| 15717 |
} |
| 15718 |
get width() { |
| 15719 |
return this.viewport.width; |
| 15720 |
} |
| 15721 |
get height() { |
| 15722 |
return this.viewport.height; |
| 15723 |
} |
| 15724 |
getPagePoint(x, y) { |
| 15725 |
return this.viewport.convertToPdfPoint(x, y); |
| 15726 |
} |
| 15727 |
_ensureCanvasWrapper() { |
| 15728 |
let canvasWrapper = this.#canvasWrapper; |
| 15729 |
if (!canvasWrapper) { |
| 15730 |
canvasWrapper = this.#canvasWrapper = document.createElement("div"); |
| 15731 |
canvasWrapper.classList.add("canvasWrapper"); |
| 15732 |
this.#addLayer(canvasWrapper, "canvasWrapper"); |
| 15733 |
} |
| 15734 |
return canvasWrapper; |
| 15735 |
} |
| 15736 |
_getRenderingContext(canvasContext, transform) { |
| 15737 |
return { |
| 15738 |
canvasContext, |
| 15739 |
transform, |
| 15740 |
viewport: this.viewport, |
| 15741 |
annotationMode: this.#annotationMode, |
| 15742 |
optionalContentConfigPromise: this._optionalContentConfigPromise, |
| 15743 |
annotationCanvasMap: this._annotationCanvasMap, |
| 15744 |
pageColors: this.pageColors, |
| 15745 |
isEditing: this.#isEditing |
| 15746 |
}; |
| 15747 |
} |
| 15748 |
async draw() { |
| 15749 |
if (this.renderingState !== RenderingStates.INITIAL) { |
| 15750 |
console.error("Must be in new state before drawing"); |
| 15751 |
this.reset(); |
| 15752 |
} |
| 15753 |
const { |
| 15754 |
div, |
| 15755 |
l10n, |
| 15756 |
pdfPage, |
| 15757 |
viewport |
| 15758 |
} = this; |
| 15759 |
if (!pdfPage) { |
| 15760 |
this.renderingState = RenderingStates.FINISHED; |
| 15761 |
throw new Error("pdfPage is not loaded"); |
| 15762 |
} |
| 15763 |
this.renderingState = RenderingStates.RUNNING; |
| 15764 |
const canvasWrapper = this._ensureCanvasWrapper(); |
| 15765 |
if (!this.textLayer && this.#textLayerMode !== TextLayerMode.DISABLE && !pdfPage.isPureXfa) { |
| 15766 |
this._accessibilityManager ||= new TextAccessibilityManager(); |
| 15767 |
this.textLayer = new TextLayerBuilder({ |
| 15768 |
pdfPage, |
| 15769 |
highlighter: this._textHighlighter, |
| 15770 |
accessibilityManager: this._accessibilityManager, |
| 15771 |
enablePermissions: this.#textLayerMode === TextLayerMode.ENABLE_PERMISSIONS, |
| 15772 |
onAppend: textLayerDiv => { |
| 15773 |
this.l10n.pause(); |
| 15774 |
this.#addLayer(textLayerDiv, "textLayer"); |
| 15775 |
this.l10n.resume(); |
| 15776 |
} |
| 15777 |
}); |
| 15778 |
} |
| 15779 |
if (!this.annotationLayer && this.#annotationMode !== AnnotationMode.DISABLE) { |
| 15780 |
const { |
| 15781 |
annotationStorage, |
| 15782 |
annotationEditorUIManager, |
| 15783 |
downloadManager, |
| 15784 |
enableScripting, |
| 15785 |
fieldObjectsPromise, |
| 15786 |
hasJSActionsPromise, |
| 15787 |
linkService |
| 15788 |
} = this.#layerProperties; |
| 15789 |
this._annotationCanvasMap ||= new Map(); |
| 15790 |
this.annotationLayer = new AnnotationLayerBuilder({ |
| 15791 |
pdfPage, |
| 15792 |
annotationStorage, |
| 15793 |
imageResourcesPath: this.imageResourcesPath, |
| 15794 |
renderForms: this.#annotationMode === AnnotationMode.ENABLE_FORMS, |
| 15795 |
linkService, |
| 15796 |
downloadManager, |
| 15797 |
enableScripting, |
| 15798 |
hasJSActionsPromise, |
| 15799 |
fieldObjectsPromise, |
| 15800 |
annotationCanvasMap: this._annotationCanvasMap, |
| 15801 |
accessibilityManager: this._accessibilityManager, |
| 15802 |
annotationEditorUIManager, |
| 15803 |
onAppend: annotationLayerDiv => { |
| 15804 |
this.#addLayer(annotationLayerDiv, "annotationLayer"); |
| 15805 |
} |
| 15806 |
}); |
| 15807 |
} |
| 15808 |
const { |
| 15809 |
width, |
| 15810 |
height |
| 15811 |
} = viewport; |
| 15812 |
this.#originalViewport = viewport; |
| 15813 |
const { |
| 15814 |
canvas, |
| 15815 |
prevCanvas, |
| 15816 |
ctx |
| 15817 |
} = this._createCanvas(newCanvas => { |
| 15818 |
canvasWrapper.prepend(newCanvas); |
| 15819 |
}); |
| 15820 |
canvas.setAttribute("role", "presentation"); |
| 15821 |
if (!this.outputScale) { |
| 15822 |
this.#computeScale(); |
| 15823 |
} |
| 15824 |
const { |
| 15825 |
outputScale |
| 15826 |
} = this; |
| 15827 |
this.#hasRestrictedScaling = this.#needsRestrictedScaling; |
| 15828 |
const sfx = approximateFraction(outputScale.sx); |
| 15829 |
const sfy = approximateFraction(outputScale.sy); |
| 15830 |
const canvasWidth = canvas.width = floorToDivide(calcRound(width * outputScale.sx), sfx[0]); |
| 15831 |
const canvasHeight = canvas.height = floorToDivide(calcRound(height * outputScale.sy), sfy[0]); |
| 15832 |
const pageWidth = floorToDivide(calcRound(width), sfx[1]); |
| 15833 |
const pageHeight = floorToDivide(calcRound(height), sfy[1]); |
| 15834 |
outputScale.sx = canvasWidth / pageWidth; |
| 15835 |
outputScale.sy = canvasHeight / pageHeight; |
| 15836 |
if (this.#scaleRoundX !== sfx[1]) { |
| 15837 |
div.style.setProperty("--scale-round-x", `${sfx[1]}px`); |
| 15838 |
this.#scaleRoundX = sfx[1]; |
| 15839 |
} |
| 15840 |
if (this.#scaleRoundY !== sfy[1]) { |
| 15841 |
div.style.setProperty("--scale-round-y", `${sfy[1]}px`); |
| 15842 |
this.#scaleRoundY = sfy[1]; |
| 15843 |
} |
| 15844 |
const transform = outputScale.scaled ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0] : null; |
| 15845 |
const resultPromise = this._drawCanvas(this._getRenderingContext(ctx, transform), () => { |
| 15846 |
prevCanvas?.remove(); |
| 15847 |
this._resetCanvas(); |
| 15848 |
}, renderTask => { |
| 15849 |
this.#useThumbnailCanvas.regularAnnotations = !renderTask.separateAnnots; |
| 15850 |
this.dispatchPageRendered(false, false); |
| 15851 |
}).then(async () => { |
| 15852 |
this.structTreeLayer ||= new StructTreeLayerBuilder(pdfPage, viewport.rawDims); |
| 15853 |
const textLayerPromise = this.#renderTextLayer(); |
| 15854 |
if (this.annotationLayer) { |
| 15855 |
await this.#renderAnnotationLayer(); |
| 15856 |
if (this.#enableAutoLinking && this.annotationLayer && this.textLayer) { |
| 15857 |
await this.#injectLinkAnnotations(textLayerPromise); |
| 15858 |
} |
| 15859 |
} |
| 15860 |
const { |
| 15861 |
annotationEditorUIManager |
| 15862 |
} = this.#layerProperties; |
| 15863 |
if (!annotationEditorUIManager) { |
| 15864 |
return; |
| 15865 |
} |
| 15866 |
this.drawLayer ||= new DrawLayerBuilder({ |
| 15867 |
pageIndex: this.id |
| 15868 |
}); |
| 15869 |
await this.#renderDrawLayer(); |
| 15870 |
this.drawLayer.setParent(canvasWrapper); |
| 15871 |
this.annotationEditorLayer ||= new AnnotationEditorLayerBuilder({ |
| 15872 |
uiManager: annotationEditorUIManager, |
| 15873 |
pdfPage, |
| 15874 |
l10n, |
| 15875 |
structTreeLayer: this.structTreeLayer, |
| 15876 |
accessibilityManager: this._accessibilityManager, |
| 15877 |
annotationLayer: this.annotationLayer?.annotationLayer, |
| 15878 |
textLayer: this.textLayer, |
| 15879 |
drawLayer: this.drawLayer.getDrawLayer(), |
| 15880 |
onAppend: annotationEditorLayerDiv => { |
| 15881 |
this.#addLayer(annotationEditorLayerDiv, "annotationEditorLayer"); |
| 15882 |
} |
| 15883 |
}); |
| 15884 |
this.#renderAnnotationEditorLayer(); |
| 15885 |
}); |
| 15886 |
if (pdfPage.isPureXfa) { |
| 15887 |
if (!this.xfaLayer) { |
| 15888 |
const { |
| 15889 |
annotationStorage, |
| 15890 |
linkService |
| 15891 |
} = this.#layerProperties; |
| 15892 |
this.xfaLayer = new XfaLayerBuilder({ |
| 15893 |
pdfPage, |
| 15894 |
annotationStorage, |
| 15895 |
linkService |
| 15896 |
}); |
| 15897 |
} |
| 15898 |
this.#renderXfaLayer(); |
| 15899 |
} |
| 15900 |
div.setAttribute("data-loaded", true); |
| 15901 |
this.dispatchPageRender(); |
| 15902 |
return resultPromise; |
| 15903 |
} |
| 15904 |
setPageLabel(label) { |
| 15905 |
this.pageLabel = typeof label === "string" ? label : null; |
| 15906 |
this.div.setAttribute("data-l10n-args", JSON.stringify({ |
| 15907 |
page: this.pageLabel ?? this.id |
| 15908 |
})); |
| 15909 |
if (this.pageLabel !== null) { |
| 15910 |
this.div.setAttribute("data-page-label", this.pageLabel); |
| 15911 |
} else { |
| 15912 |
this.div.removeAttribute("data-page-label"); |
| 15913 |
} |
| 15914 |
} |
| 15915 |
get thumbnailCanvas() { |
| 15916 |
const { |
| 15917 |
directDrawing, |
| 15918 |
initialOptionalContent, |
| 15919 |
regularAnnotations |
| 15920 |
} = this.#useThumbnailCanvas; |
| 15921 |
return directDrawing && initialOptionalContent && regularAnnotations ? this.canvas : null; |
| 15922 |
} |
| 15923 |
} |
| 15924 |
|
| 15925 |
;// ./web/pdf_viewer.js |
| 15926 |
|
| 15927 |
|
| 15928 |
|
| 15929 |
|
| 15930 |
|
| 15931 |
|
| 15932 |
|
| 15933 |
|
| 15934 |
|
| 15935 |
|
| 15936 |
|
| 15937 |
|
| 15938 |
|
| 15939 |
|
| 15940 |
|
| 15941 |
|
| 15942 |
|
| 15943 |
|
| 15944 |
|
| 15945 |
const DEFAULT_CACHE_SIZE = 10; |
| 15946 |
const PagesCountLimit = { |
| 15947 |
FORCE_SCROLL_MODE_PAGE: 10000, |
| 15948 |
FORCE_LAZY_PAGE_INIT: 5000, |
| 15949 |
PAUSE_EAGER_PAGE_INIT: 250 |
| 15950 |
}; |
| 15951 |
function isValidAnnotationEditorMode(mode) { |
| 15952 |
return Object.values(AnnotationEditorType).includes(mode) && mode !== AnnotationEditorType.DISABLE; |
| 15953 |
} |
| 15954 |
class PDFPageViewBuffer { |
| 15955 |
#buf = new Set(); |
| 15956 |
#size = 0; |
| 15957 |
constructor(size) { |
| 15958 |
this.#size = size; |
| 15959 |
} |
| 15960 |
push(view) { |
| 15961 |
const buf = this.#buf; |
| 15962 |
if (buf.has(view)) { |
| 15963 |
buf.delete(view); |
| 15964 |
} |
| 15965 |
buf.add(view); |
| 15966 |
if (buf.size > this.#size) { |
| 15967 |
this.#destroyFirstView(); |
| 15968 |
} |
| 15969 |
} |
| 15970 |
resize(newSize, idsToKeep = null) { |
| 15971 |
this.#size = newSize; |
| 15972 |
const buf = this.#buf; |
| 15973 |
if (idsToKeep) { |
| 15974 |
const ii = buf.size; |
| 15975 |
let i = 1; |
| 15976 |
for (const view of buf) { |
| 15977 |
if (idsToKeep.has(view.id)) { |
| 15978 |
buf.delete(view); |
| 15979 |
buf.add(view); |
| 15980 |
} |
| 15981 |
if (++i > ii) { |
| 15982 |
break; |
| 15983 |
} |
| 15984 |
} |
| 15985 |
} |
| 15986 |
while (buf.size > this.#size) { |
| 15987 |
this.#destroyFirstView(); |
| 15988 |
} |
| 15989 |
} |
| 15990 |
has(view) { |
| 15991 |
return this.#buf.has(view); |
| 15992 |
} |
| 15993 |
[Symbol.iterator]() { |
| 15994 |
return this.#buf.keys(); |
| 15995 |
} |
| 15996 |
#destroyFirstView() { |
| 15997 |
const firstView = this.#buf.keys().next().value; |
| 15998 |
firstView?.destroy(); |
| 15999 |
this.#buf.delete(firstView); |
| 16000 |
} |
| 16001 |
} |
| 16002 |
class PDFViewer { |
| 16003 |
#buffer = null; |
| 16004 |
#altTextManager = null; |
| 16005 |
#annotationEditorHighlightColors = null; |
| 16006 |
#annotationEditorMode = AnnotationEditorType.NONE; |
| 16007 |
#annotationEditorUIManager = null; |
| 16008 |
#annotationMode = AnnotationMode.ENABLE_FORMS; |
| 16009 |
#containerTopLeft = null; |
| 16010 |
#editorUndoBar = null; |
| 16011 |
#enableHWA = false; |
| 16012 |
#enableHighlightFloatingButton = false; |
| 16013 |
#enablePermissions = false; |
| 16014 |
#enableUpdatedAddImage = false; |
| 16015 |
#enableNewAltTextWhenAddingImage = false; |
| 16016 |
#enableAutoLinking = true; |
| 16017 |
#eventAbortController = null; |
| 16018 |
#minDurationToUpdateCanvas = 0; |
| 16019 |
#mlManager = null; |
| 16020 |
#scrollTimeoutId = null; |
| 16021 |
#switchAnnotationEditorModeAC = null; |
| 16022 |
#switchAnnotationEditorModeTimeoutId = null; |
| 16023 |
#getAllTextInProgress = false; |
| 16024 |
#hiddenCopyElement = null; |
| 16025 |
#interruptCopyCondition = false; |
| 16026 |
#previousContainerHeight = 0; |
| 16027 |
#resizeObserver = new ResizeObserver(this.#resizeObserverCallback.bind(this)); |
| 16028 |
#scrollModePageState = null; |
| 16029 |
#scaleTimeoutId = null; |
| 16030 |
#signatureManager = null; |
| 16031 |
#supportsPinchToZoom = true; |
| 16032 |
#textLayerMode = TextLayerMode.ENABLE; |
| 16033 |
constructor(options) { |
| 16034 |
const viewerVersion = "5.3.31"; |
| 16035 |
if (version !== viewerVersion) { |
| 16036 |
throw new Error(`The API version "${version}" does not match the Viewer version "${viewerVersion}".`); |
| 16037 |
} |
| 16038 |
this.container = options.container; |
| 16039 |
this.viewer = options.viewer || options.container.firstElementChild; |
| 16040 |
if (this.container?.tagName !== "DIV" || this.viewer?.tagName !== "DIV") { |
| 16041 |
throw new Error("Invalid `container` and/or `viewer` option."); |
| 16042 |
} |
| 16043 |
if (this.container.offsetParent && getComputedStyle(this.container).position !== "absolute") { |
| 16044 |
throw new Error("The `container` must be absolutely positioned."); |
| 16045 |
} |
| 16046 |
this.#resizeObserver.observe(this.container); |
| 16047 |
this.eventBus = options.eventBus; |
| 16048 |
this.linkService = options.linkService || new SimpleLinkService(); |
| 16049 |
this.downloadManager = options.downloadManager || null; |
| 16050 |
this.findController = options.findController || null; |
| 16051 |
this.#altTextManager = options.altTextManager || null; |
| 16052 |
this.#signatureManager = options.signatureManager || null; |
| 16053 |
this.#editorUndoBar = options.editorUndoBar || null; |
| 16054 |
if (this.findController) { |
| 16055 |
this.findController.onIsPageVisible = pageNumber => this._getVisiblePages().ids.has(pageNumber); |
| 16056 |
} |
| 16057 |
this._scriptingManager = options.scriptingManager || null; |
| 16058 |
this.#textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE; |
| 16059 |
this.#annotationMode = options.annotationMode ?? AnnotationMode.ENABLE_FORMS; |
| 16060 |
this.#annotationEditorMode = options.annotationEditorMode ?? AnnotationEditorType.NONE; |
| 16061 |
this.#annotationEditorHighlightColors = options.annotationEditorHighlightColors || null; |
| 16062 |
this.#enableHighlightFloatingButton = options.enableHighlightFloatingButton === true; |
| 16063 |
this.#enableUpdatedAddImage = options.enableUpdatedAddImage === true; |
| 16064 |
this.#enableNewAltTextWhenAddingImage = options.enableNewAltTextWhenAddingImage === true; |
| 16065 |
this.imageResourcesPath = options.imageResourcesPath || ""; |
| 16066 |
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false; |
| 16067 |
this.removePageBorders = options.removePageBorders || false; |
| 16068 |
this.maxCanvasPixels = options.maxCanvasPixels; |
| 16069 |
this.maxCanvasDim = options.maxCanvasDim; |
| 16070 |
this.capCanvasAreaFactor = options.capCanvasAreaFactor; |
| 16071 |
this.enableDetailCanvas = options.enableDetailCanvas ?? true; |
| 16072 |
this.l10n = options.l10n; |
| 16073 |
this.l10n ||= new genericl10n_GenericL10n(); |
| 16074 |
this.#enablePermissions = options.enablePermissions || false; |
| 16075 |
this.pageColors = options.pageColors || null; |
| 16076 |
this.#mlManager = options.mlManager || null; |
| 16077 |
this.#enableHWA = options.enableHWA || false; |
| 16078 |
this.#supportsPinchToZoom = options.supportsPinchToZoom !== false; |
| 16079 |
this.#enableAutoLinking = options.enableAutoLinking !== false; |
| 16080 |
this.#minDurationToUpdateCanvas = options.minDurationToUpdateCanvas ?? 500; |
| 16081 |
this.defaultRenderingQueue = !options.renderingQueue; |
| 16082 |
if (this.defaultRenderingQueue) { |
| 16083 |
this.renderingQueue = new PDFRenderingQueue(); |
| 16084 |
this.renderingQueue.setViewer(this); |
| 16085 |
} else { |
| 16086 |
this.renderingQueue = options.renderingQueue; |
| 16087 |
} |
| 16088 |
const { |
| 16089 |
abortSignal |
| 16090 |
} = options; |
| 16091 |
abortSignal?.addEventListener("abort", () => { |
| 16092 |
this.#resizeObserver.disconnect(); |
| 16093 |
this.#resizeObserver = null; |
| 16094 |
}, { |
| 16095 |
once: true |
| 16096 |
}); |
| 16097 |
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this), abortSignal); |
| 16098 |
this.presentationModeState = PresentationModeState.UNKNOWN; |
| 16099 |
this._resetView(); |
| 16100 |
if (this.removePageBorders) { |
| 16101 |
this.viewer.classList.add("removePageBorders"); |
| 16102 |
} |
| 16103 |
this.#updateContainerHeightCss(); |
| 16104 |
this.eventBus._on("thumbnailrendered", ({ |
| 16105 |
pageNumber, |
| 16106 |
pdfPage |
| 16107 |
}) => { |
| 16108 |
const pageView = this._pages[pageNumber - 1]; |
| 16109 |
if (!this.#buffer.has(pageView)) { |
| 16110 |
pdfPage?.cleanup(); |
| 16111 |
} |
| 16112 |
}); |
| 16113 |
if (!options.l10n) { |
| 16114 |
this.l10n.translate(this.container); |
| 16115 |
} |
| 16116 |
} |
| 16117 |
get pagesCount() { |
| 16118 |
return this._pages.length; |
| 16119 |
} |
| 16120 |
getPageView(index) { |
| 16121 |
return this._pages[index]; |
| 16122 |
} |
| 16123 |
getCachedPageViews() { |
| 16124 |
return new Set(this.#buffer); |
| 16125 |
} |
| 16126 |
get pageViewsReady() { |
| 16127 |
return this._pages.every(pageView => pageView?.pdfPage); |
| 16128 |
} |
| 16129 |
get renderForms() { |
| 16130 |
return this.#annotationMode === AnnotationMode.ENABLE_FORMS; |
| 16131 |
} |
| 16132 |
get enableScripting() { |
| 16133 |
return !!this._scriptingManager; |
| 16134 |
} |
| 16135 |
get currentPageNumber() { |
| 16136 |
return this._currentPageNumber; |
| 16137 |
} |
| 16138 |
set currentPageNumber(val) { |
| 16139 |
if (!Number.isInteger(val)) { |
| 16140 |
throw new Error("Invalid page number."); |
| 16141 |
} |
| 16142 |
if (!this.pdfDocument) { |
| 16143 |
return; |
| 16144 |
} |
| 16145 |
if (!this._setCurrentPageNumber(val, true)) { |
| 16146 |
console.error(`currentPageNumber: "${val}" is not a valid page.`); |
| 16147 |
} |
| 16148 |
} |
| 16149 |
_setCurrentPageNumber(val, resetCurrentPageView = false) { |
| 16150 |
if (this._currentPageNumber === val) { |
| 16151 |
if (resetCurrentPageView) { |
| 16152 |
this.#resetCurrentPageView(); |
| 16153 |
} |
| 16154 |
return true; |
| 16155 |
} |
| 16156 |
if (!(0 < val && val <= this.pagesCount)) { |
| 16157 |
return false; |
| 16158 |
} |
| 16159 |
const previous = this._currentPageNumber; |
| 16160 |
this._currentPageNumber = val; |
| 16161 |
this.eventBus.dispatch("pagechanging", { |
| 16162 |
source: this, |
| 16163 |
pageNumber: val, |
| 16164 |
pageLabel: this._pageLabels?.[val - 1] ?? null, |
| 16165 |
previous |
| 16166 |
}); |
| 16167 |
if (resetCurrentPageView) { |
| 16168 |
this.#resetCurrentPageView(); |
| 16169 |
} |
| 16170 |
return true; |
| 16171 |
} |
| 16172 |
get currentPageLabel() { |
| 16173 |
return this._pageLabels?.[this._currentPageNumber - 1] ?? null; |
| 16174 |
} |
| 16175 |
set currentPageLabel(val) { |
| 16176 |
if (!this.pdfDocument) { |
| 16177 |
return; |
| 16178 |
} |
| 16179 |
let page = val | 0; |
| 16180 |
if (this._pageLabels) { |
| 16181 |
const i = this._pageLabels.indexOf(val); |
| 16182 |
if (i >= 0) { |
| 16183 |
page = i + 1; |
| 16184 |
} |
| 16185 |
} |
| 16186 |
if (!this._setCurrentPageNumber(page, true)) { |
| 16187 |
console.error(`currentPageLabel: "${val}" is not a valid page.`); |
| 16188 |
} |
| 16189 |
} |
| 16190 |
get currentScale() { |
| 16191 |
return this._currentScale !== UNKNOWN_SCALE ? this._currentScale : DEFAULT_SCALE; |
| 16192 |
} |
| 16193 |
set currentScale(val) { |
| 16194 |
if (isNaN(val)) { |
| 16195 |
throw new Error("Invalid numeric scale."); |
| 16196 |
} |
| 16197 |
if (!this.pdfDocument) { |
| 16198 |
return; |
| 16199 |
} |
| 16200 |
this.#setScale(val, { |
| 16201 |
noScroll: false |
| 16202 |
}); |
| 16203 |
} |
| 16204 |
get currentScaleValue() { |
| 16205 |
return this._currentScaleValue; |
| 16206 |
} |
| 16207 |
set currentScaleValue(val) { |
| 16208 |
if (!this.pdfDocument) { |
| 16209 |
return; |
| 16210 |
} |
| 16211 |
this.#setScale(val, { |
| 16212 |
noScroll: false |
| 16213 |
}); |
| 16214 |
} |
| 16215 |
get pagesRotation() { |
| 16216 |
return this._pagesRotation; |
| 16217 |
} |
| 16218 |
set pagesRotation(rotation) { |
| 16219 |
if (!isValidRotation(rotation)) { |
| 16220 |
throw new Error("Invalid pages rotation angle."); |
| 16221 |
} |
| 16222 |
if (!this.pdfDocument) { |
| 16223 |
return; |
| 16224 |
} |
| 16225 |
rotation %= 360; |
| 16226 |
if (rotation < 0) { |
| 16227 |
rotation += 360; |
| 16228 |
} |
| 16229 |
if (this._pagesRotation === rotation) { |
| 16230 |
return; |
| 16231 |
} |
| 16232 |
this._pagesRotation = rotation; |
| 16233 |
const pageNumber = this._currentPageNumber; |
| 16234 |
this.refresh(true, { |
| 16235 |
rotation |
| 16236 |
}); |
| 16237 |
if (this._currentScaleValue) { |
| 16238 |
this.#setScale(this._currentScaleValue, { |
| 16239 |
noScroll: true |
| 16240 |
}); |
| 16241 |
} |
| 16242 |
this.eventBus.dispatch("rotationchanging", { |
| 16243 |
source: this, |
| 16244 |
pagesRotation: rotation, |
| 16245 |
pageNumber |
| 16246 |
}); |
| 16247 |
if (this.defaultRenderingQueue) { |
| 16248 |
this.update(); |
| 16249 |
} |
| 16250 |
} |
| 16251 |
get firstPagePromise() { |
| 16252 |
return this.pdfDocument ? this._firstPageCapability.promise : null; |
| 16253 |
} |
| 16254 |
get onePageRendered() { |
| 16255 |
return this.pdfDocument ? this._onePageRenderedCapability.promise : null; |
| 16256 |
} |
| 16257 |
get pagesPromise() { |
| 16258 |
return this.pdfDocument ? this._pagesCapability.promise : null; |
| 16259 |
} |
| 16260 |
get _layerProperties() { |
| 16261 |
const self = this; |
| 16262 |
return shadow(this, "_layerProperties", { |
| 16263 |
get annotationEditorUIManager() { |
| 16264 |
return self.#annotationEditorUIManager; |
| 16265 |
}, |
| 16266 |
get annotationStorage() { |
| 16267 |
return self.pdfDocument?.annotationStorage; |
| 16268 |
}, |
| 16269 |
get downloadManager() { |
| 16270 |
return self.downloadManager; |
| 16271 |
}, |
| 16272 |
get enableScripting() { |
| 16273 |
return !!self._scriptingManager; |
| 16274 |
}, |
| 16275 |
get fieldObjectsPromise() { |
| 16276 |
return self.pdfDocument?.getFieldObjects(); |
| 16277 |
}, |
| 16278 |
get findController() { |
| 16279 |
return self.findController; |
| 16280 |
}, |
| 16281 |
get hasJSActionsPromise() { |
| 16282 |
return self.pdfDocument?.hasJSActions(); |
| 16283 |
}, |
| 16284 |
get linkService() { |
| 16285 |
return self.linkService; |
| 16286 |
} |
| 16287 |
}); |
| 16288 |
} |
| 16289 |
#initializePermissions(permissions) { |
| 16290 |
const params = { |
| 16291 |
annotationEditorMode: this.#annotationEditorMode, |
| 16292 |
annotationMode: this.#annotationMode, |
| 16293 |
textLayerMode: this.#textLayerMode |
| 16294 |
}; |
| 16295 |
if (!permissions) { |
| 16296 |
return params; |
| 16297 |
} |
| 16298 |
if (!permissions.includes(PermissionFlag.COPY) && this.#textLayerMode === TextLayerMode.ENABLE) { |
| 16299 |
params.textLayerMode = TextLayerMode.ENABLE_PERMISSIONS; |
| 16300 |
} |
| 16301 |
if (!permissions.includes(PermissionFlag.MODIFY_CONTENTS)) { |
| 16302 |
params.annotationEditorMode = AnnotationEditorType.DISABLE; |
| 16303 |
} |
| 16304 |
if (!permissions.includes(PermissionFlag.MODIFY_ANNOTATIONS) && !permissions.includes(PermissionFlag.FILL_INTERACTIVE_FORMS) && this.#annotationMode === AnnotationMode.ENABLE_FORMS) { |
| 16305 |
params.annotationMode = AnnotationMode.ENABLE; |
| 16306 |
} |
| 16307 |
return params; |
| 16308 |
} |
| 16309 |
async #onePageRenderedOrForceFetch(signal) { |
| 16310 |
if (document.visibilityState === "hidden" || !this.container.offsetParent || this._getVisiblePages().views.length === 0) { |
| 16311 |
return; |
| 16312 |
} |
| 16313 |
const hiddenCapability = Promise.withResolvers(), |
| 16314 |
ac = new AbortController(); |
| 16315 |
document.addEventListener("visibilitychange", () => { |
| 16316 |
if (document.visibilityState === "hidden") { |
| 16317 |
hiddenCapability.resolve(); |
| 16318 |
} |
| 16319 |
}, { |
| 16320 |
signal: AbortSignal.any([signal, ac.signal]) |
| 16321 |
}); |
| 16322 |
await Promise.race([this._onePageRenderedCapability.promise, hiddenCapability.promise]); |
| 16323 |
ac.abort(); |
| 16324 |
} |
| 16325 |
async getAllText() { |
| 16326 |
const texts = []; |
| 16327 |
const buffer = []; |
| 16328 |
for (let pageNum = 1, pagesCount = this.pdfDocument.numPages; pageNum <= pagesCount; ++pageNum) { |
| 16329 |
if (this.#interruptCopyCondition) { |
| 16330 |
return null; |
| 16331 |
} |
| 16332 |
buffer.length = 0; |
| 16333 |
const page = await this.pdfDocument.getPage(pageNum); |
| 16334 |
const { |
| 16335 |
items |
| 16336 |
} = await page.getTextContent(); |
| 16337 |
for (const item of items) { |
| 16338 |
if (item.str) { |
| 16339 |
buffer.push(item.str); |
| 16340 |
} |
| 16341 |
if (item.hasEOL) { |
| 16342 |
buffer.push("\n"); |
| 16343 |
} |
| 16344 |
} |
| 16345 |
texts.push(removeNullCharacters(buffer.join(""))); |
| 16346 |
} |
| 16347 |
return texts.join("\n"); |
| 16348 |
} |
| 16349 |
#copyCallback(textLayerMode, event) { |
| 16350 |
const selection = document.getSelection(); |
| 16351 |
const { |
| 16352 |
focusNode, |
| 16353 |
anchorNode |
| 16354 |
} = selection; |
| 16355 |
if (anchorNode && focusNode && selection.containsNode(this.#hiddenCopyElement)) { |
| 16356 |
if (this.#getAllTextInProgress || textLayerMode === TextLayerMode.ENABLE_PERMISSIONS) { |
| 16357 |
stopEvent(event); |
| 16358 |
return; |
| 16359 |
} |
| 16360 |
this.#getAllTextInProgress = true; |
| 16361 |
const { |
| 16362 |
classList |
| 16363 |
} = this.viewer; |
| 16364 |
classList.add("copyAll"); |
| 16365 |
const ac = new AbortController(); |
| 16366 |
window.addEventListener("keydown", ev => this.#interruptCopyCondition = ev.key === "Escape", { |
| 16367 |
signal: ac.signal |
| 16368 |
}); |
| 16369 |
this.getAllText().then(async text => { |
| 16370 |
if (text !== null) { |
| 16371 |
await navigator.clipboard.writeText(text); |
| 16372 |
} |
| 16373 |
}).catch(reason => { |
| 16374 |
console.warn(`Something goes wrong when extracting the text: ${reason.message}`); |
| 16375 |
}).finally(() => { |
| 16376 |
this.#getAllTextInProgress = false; |
| 16377 |
this.#interruptCopyCondition = false; |
| 16378 |
ac.abort(); |
| 16379 |
classList.remove("copyAll"); |
| 16380 |
}); |
| 16381 |
stopEvent(event); |
| 16382 |
} |
| 16383 |
} |
| 16384 |
setDocument(pdfDocument) { |
| 16385 |
if (this.pdfDocument) { |
| 16386 |
this.eventBus.dispatch("pagesdestroy", { |
| 16387 |
source: this |
| 16388 |
}); |
| 16389 |
this._cancelRendering(); |
| 16390 |
this._resetView(); |
| 16391 |
this.findController?.setDocument(null); |
| 16392 |
this._scriptingManager?.setDocument(null); |
| 16393 |
this.#annotationEditorUIManager?.destroy(); |
| 16394 |
this.#annotationEditorUIManager = null; |
| 16395 |
} |
| 16396 |
this.pdfDocument = pdfDocument; |
| 16397 |
if (!pdfDocument) { |
| 16398 |
return; |
| 16399 |
} |
| 16400 |
const pagesCount = pdfDocument.numPages; |
| 16401 |
const firstPagePromise = pdfDocument.getPage(1); |
| 16402 |
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig({ |
| 16403 |
intent: "display" |
| 16404 |
}); |
| 16405 |
const permissionsPromise = this.#enablePermissions ? pdfDocument.getPermissions() : Promise.resolve(); |
| 16406 |
const { |
| 16407 |
eventBus, |
| 16408 |
pageColors, |
| 16409 |
viewer |
| 16410 |
} = this; |
| 16411 |
this.#eventAbortController = new AbortController(); |
| 16412 |
const { |
| 16413 |
signal |
| 16414 |
} = this.#eventAbortController; |
| 16415 |
if (pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) { |
| 16416 |
console.warn("Forcing PAGE-scrolling for performance reasons, given the length of the document."); |
| 16417 |
const mode = this._scrollMode = ScrollMode.PAGE; |
| 16418 |
eventBus.dispatch("scrollmodechanged", { |
| 16419 |
source: this, |
| 16420 |
mode |
| 16421 |
}); |
| 16422 |
} |
| 16423 |
this._pagesCapability.promise.then(() => { |
| 16424 |
eventBus.dispatch("pagesloaded", { |
| 16425 |
source: this, |
| 16426 |
pagesCount |
| 16427 |
}); |
| 16428 |
}, () => {}); |
| 16429 |
const onBeforeDraw = evt => { |
| 16430 |
const pageView = this._pages[evt.pageNumber - 1]; |
| 16431 |
if (!pageView) { |
| 16432 |
return; |
| 16433 |
} |
| 16434 |
this.#buffer.push(pageView); |
| 16435 |
}; |
| 16436 |
eventBus._on("pagerender", onBeforeDraw, { |
| 16437 |
signal |
| 16438 |
}); |
| 16439 |
const onAfterDraw = evt => { |
| 16440 |
if (evt.cssTransform || evt.isDetailView) { |
| 16441 |
return; |
| 16442 |
} |
| 16443 |
this._onePageRenderedCapability.resolve({ |
| 16444 |
timestamp: evt.timestamp |
| 16445 |
}); |
| 16446 |
eventBus._off("pagerendered", onAfterDraw); |
| 16447 |
}; |
| 16448 |
eventBus._on("pagerendered", onAfterDraw, { |
| 16449 |
signal |
| 16450 |
}); |
| 16451 |
Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => { |
| 16452 |
if (pdfDocument !== this.pdfDocument) { |
| 16453 |
return; |
| 16454 |
} |
| 16455 |
this._firstPageCapability.resolve(firstPdfPage); |
| 16456 |
this._optionalContentConfigPromise = optionalContentConfigPromise; |
| 16457 |
const { |
| 16458 |
annotationEditorMode, |
| 16459 |
annotationMode, |
| 16460 |
textLayerMode |
| 16461 |
} = this.#initializePermissions(permissions); |
| 16462 |
if (textLayerMode !== TextLayerMode.DISABLE) { |
| 16463 |
const element = this.#hiddenCopyElement = document.createElement("div"); |
| 16464 |
element.id = "hiddenCopyElement"; |
| 16465 |
viewer.before(element); |
| 16466 |
} |
| 16467 |
if (annotationEditorMode !== AnnotationEditorType.DISABLE) { |
| 16468 |
const mode = annotationEditorMode; |
| 16469 |
if (pdfDocument.isPureXfa) { |
| 16470 |
console.warn("Warning: XFA-editing is not implemented."); |
| 16471 |
} else if (isValidAnnotationEditorMode(mode)) { |
| 16472 |
this.#annotationEditorUIManager = new AnnotationEditorUIManager(this.container, viewer, this.#altTextManager, this.#signatureManager, eventBus, pdfDocument, pageColors, this.#annotationEditorHighlightColors, this.#enableHighlightFloatingButton, this.#enableUpdatedAddImage, this.#enableNewAltTextWhenAddingImage, this.#mlManager, this.#editorUndoBar, this.#supportsPinchToZoom); |
| 16473 |
eventBus.dispatch("annotationeditoruimanager", { |
| 16474 |
source: this, |
| 16475 |
uiManager: this.#annotationEditorUIManager |
| 16476 |
}); |
| 16477 |
if (mode !== AnnotationEditorType.NONE) { |
| 16478 |
this.#preloadEditingData(mode); |
| 16479 |
this.#annotationEditorUIManager.updateMode(mode); |
| 16480 |
} |
| 16481 |
} else { |
| 16482 |
console.error(`Invalid AnnotationEditor mode: ${mode}`); |
| 16483 |
} |
| 16484 |
} |
| 16485 |
const viewerElement = this._scrollMode === ScrollMode.PAGE ? null : viewer; |
| 16486 |
const scale = this.currentScale; |
| 16487 |
const viewport = firstPdfPage.getViewport({ |
| 16488 |
scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS |
| 16489 |
}); |
| 16490 |
viewer.style.setProperty("--scale-factor", viewport.scale); |
| 16491 |
if (pageColors?.background) { |
| 16492 |
viewer.style.setProperty("--page-bg-color", pageColors.background); |
| 16493 |
} |
| 16494 |
if (pageColors?.foreground === "CanvasText" || pageColors?.background === "Canvas") { |
| 16495 |
viewer.style.setProperty("--hcm-highlight-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight", "CanvasText", "Canvas", "HighlightText", "Highlight")); |
| 16496 |
viewer.style.setProperty("--hcm-highlight-selected-filter", pdfDocument.filterFactory.addHighlightHCMFilter("highlight_selected", "CanvasText", "Canvas", "HighlightText", "ButtonText")); |
| 16497 |
} |
| 16498 |
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) { |
| 16499 |
const pageView = new PDFPageView({ |
| 16500 |
container: viewerElement, |
| 16501 |
eventBus, |
| 16502 |
id: pageNum, |
| 16503 |
scale, |
| 16504 |
defaultViewport: viewport.clone(), |
| 16505 |
optionalContentConfigPromise, |
| 16506 |
renderingQueue: this.renderingQueue, |
| 16507 |
textLayerMode, |
| 16508 |
annotationMode, |
| 16509 |
imageResourcesPath: this.imageResourcesPath, |
| 16510 |
maxCanvasPixels: this.maxCanvasPixels, |
| 16511 |
maxCanvasDim: this.maxCanvasDim, |
| 16512 |
capCanvasAreaFactor: this.capCanvasAreaFactor, |
| 16513 |
enableDetailCanvas: this.enableDetailCanvas, |
| 16514 |
pageColors, |
| 16515 |
l10n: this.l10n, |
| 16516 |
layerProperties: this._layerProperties, |
| 16517 |
enableHWA: this.#enableHWA, |
| 16518 |
enableAutoLinking: this.#enableAutoLinking, |
| 16519 |
minDurationToUpdateCanvas: this.#minDurationToUpdateCanvas |
| 16520 |
}); |
| 16521 |
this._pages.push(pageView); |
| 16522 |
} |
| 16523 |
this._pages[0]?.setPdfPage(firstPdfPage); |
| 16524 |
if (this._scrollMode === ScrollMode.PAGE) { |
| 16525 |
this.#ensurePageViewVisible(); |
| 16526 |
} else if (this._spreadMode !== SpreadMode.NONE) { |
| 16527 |
this._updateSpreadMode(); |
| 16528 |
} |
| 16529 |
this.#onePageRenderedOrForceFetch(signal).then(async () => { |
| 16530 |
if (pdfDocument !== this.pdfDocument) { |
| 16531 |
return; |
| 16532 |
} |
| 16533 |
this.findController?.setDocument(pdfDocument); |
| 16534 |
this._scriptingManager?.setDocument(pdfDocument); |
| 16535 |
if (this.#hiddenCopyElement) { |
| 16536 |
document.addEventListener("copy", this.#copyCallback.bind(this, textLayerMode), { |
| 16537 |
signal |
| 16538 |
}); |
| 16539 |
} |
| 16540 |
if (this.#annotationEditorUIManager) { |
| 16541 |
eventBus.dispatch("annotationeditormodechanged", { |
| 16542 |
source: this, |
| 16543 |
mode: this.#annotationEditorMode |
| 16544 |
}); |
| 16545 |
} |
| 16546 |
if (pdfDocument.loadingParams.disableAutoFetch || pagesCount > PagesCountLimit.FORCE_LAZY_PAGE_INIT) { |
| 16547 |
this._pagesCapability.resolve(); |
| 16548 |
return; |
| 16549 |
} |
| 16550 |
let getPagesLeft = pagesCount - 1; |
| 16551 |
if (getPagesLeft <= 0) { |
| 16552 |
this._pagesCapability.resolve(); |
| 16553 |
return; |
| 16554 |
} |
| 16555 |
for (let pageNum = 2; pageNum <= pagesCount; ++pageNum) { |
| 16556 |
const promise = pdfDocument.getPage(pageNum).then(pdfPage => { |
| 16557 |
const pageView = this._pages[pageNum - 1]; |
| 16558 |
if (!pageView.pdfPage) { |
| 16559 |
pageView.setPdfPage(pdfPage); |
| 16560 |
} |
| 16561 |
if (--getPagesLeft === 0) { |
| 16562 |
this._pagesCapability.resolve(); |
| 16563 |
} |
| 16564 |
}, reason => { |
| 16565 |
console.error(`Unable to get page ${pageNum} to initialize viewer`, reason); |
| 16566 |
if (--getPagesLeft === 0) { |
| 16567 |
this._pagesCapability.resolve(); |
| 16568 |
} |
| 16569 |
}); |
| 16570 |
if (pageNum % PagesCountLimit.PAUSE_EAGER_PAGE_INIT === 0) { |
| 16571 |
await promise; |
| 16572 |
} |
| 16573 |
} |
| 16574 |
}); |
| 16575 |
eventBus.dispatch("pagesinit", { |
| 16576 |
source: this |
| 16577 |
}); |
| 16578 |
pdfDocument.getMetadata().then(({ |
| 16579 |
info |
| 16580 |
}) => { |
| 16581 |
if (pdfDocument !== this.pdfDocument) { |
| 16582 |
return; |
| 16583 |
} |
| 16584 |
if (info.Language) { |
| 16585 |
viewer.lang = info.Language; |
| 16586 |
} |
| 16587 |
}); |
| 16588 |
if (this.defaultRenderingQueue) { |
| 16589 |
this.update(); |
| 16590 |
} |
| 16591 |
}).catch(reason => { |
| 16592 |
console.error("Unable to initialize viewer", reason); |
| 16593 |
this._pagesCapability.reject(reason); |
| 16594 |
}); |
| 16595 |
} |
| 16596 |
setPageLabels(labels) { |
| 16597 |
if (!this.pdfDocument) { |
| 16598 |
return; |
| 16599 |
} |
| 16600 |
if (!labels) { |
| 16601 |
this._pageLabels = null; |
| 16602 |
} else if (!(Array.isArray(labels) && this.pdfDocument.numPages === labels.length)) { |
| 16603 |
this._pageLabels = null; |
| 16604 |
console.error(`setPageLabels: Invalid page labels.`); |
| 16605 |
} else { |
| 16606 |
this._pageLabels = labels; |
| 16607 |
} |
| 16608 |
for (let i = 0, ii = this._pages.length; i < ii; i++) { |
| 16609 |
this._pages[i].setPageLabel(this._pageLabels?.[i] ?? null); |
| 16610 |
} |
| 16611 |
} |
| 16612 |
_resetView() { |
| 16613 |
this._pages = []; |
| 16614 |
this._currentPageNumber = 1; |
| 16615 |
this._currentScale = UNKNOWN_SCALE; |
| 16616 |
this._currentScaleValue = null; |
| 16617 |
this._pageLabels = null; |
| 16618 |
this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE); |
| 16619 |
this._location = null; |
| 16620 |
this._pagesRotation = 0; |
| 16621 |
this._optionalContentConfigPromise = null; |
| 16622 |
this._firstPageCapability = Promise.withResolvers(); |
| 16623 |
this._onePageRenderedCapability = Promise.withResolvers(); |
| 16624 |
this._pagesCapability = Promise.withResolvers(); |
| 16625 |
this._scrollMode = ScrollMode.VERTICAL; |
| 16626 |
this._previousScrollMode = ScrollMode.UNKNOWN; |
| 16627 |
this._spreadMode = SpreadMode.NONE; |
| 16628 |
this.#scrollModePageState = { |
| 16629 |
previousPageNumber: 1, |
| 16630 |
scrollDown: true, |
| 16631 |
pages: [] |
| 16632 |
}; |
| 16633 |
this.#eventAbortController?.abort(); |
| 16634 |
this.#eventAbortController = null; |
| 16635 |
this.viewer.textContent = ""; |
| 16636 |
this._updateScrollMode(); |
| 16637 |
this.viewer.removeAttribute("lang"); |
| 16638 |
this.#hiddenCopyElement?.remove(); |
| 16639 |
this.#hiddenCopyElement = null; |
| 16640 |
this.#cleanupTimeouts(); |
| 16641 |
this.#cleanupSwitchAnnotationEditorMode(); |
| 16642 |
} |
| 16643 |
#ensurePageViewVisible() { |
| 16644 |
if (this._scrollMode !== ScrollMode.PAGE) { |
| 16645 |
throw new Error("#ensurePageViewVisible: Invalid scrollMode value."); |
| 16646 |
} |
| 16647 |
const pageNumber = this._currentPageNumber, |
| 16648 |
state = this.#scrollModePageState, |
| 16649 |
viewer = this.viewer; |
| 16650 |
viewer.textContent = ""; |
| 16651 |
state.pages.length = 0; |
| 16652 |
if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) { |
| 16653 |
const pageView = this._pages[pageNumber - 1]; |
| 16654 |
viewer.append(pageView.div); |
| 16655 |
state.pages.push(pageView); |
| 16656 |
} else { |
| 16657 |
const pageIndexSet = new Set(), |
| 16658 |
parity = this._spreadMode - 1; |
| 16659 |
if (parity === -1) { |
| 16660 |
pageIndexSet.add(pageNumber - 1); |
| 16661 |
} else if (pageNumber % 2 !== parity) { |
| 16662 |
pageIndexSet.add(pageNumber - 1); |
| 16663 |
pageIndexSet.add(pageNumber); |
| 16664 |
} else { |
| 16665 |
pageIndexSet.add(pageNumber - 2); |
| 16666 |
pageIndexSet.add(pageNumber - 1); |
| 16667 |
} |
| 16668 |
const spread = document.createElement("div"); |
| 16669 |
spread.className = "spread"; |
| 16670 |
if (this.isInPresentationMode) { |
| 16671 |
const dummyPage = document.createElement("div"); |
| 16672 |
dummyPage.className = "dummyPage"; |
| 16673 |
spread.append(dummyPage); |
| 16674 |
} |
| 16675 |
for (const i of pageIndexSet) { |
| 16676 |
const pageView = this._pages[i]; |
| 16677 |
if (!pageView) { |
| 16678 |
continue; |
| 16679 |
} |
| 16680 |
spread.append(pageView.div); |
| 16681 |
state.pages.push(pageView); |
| 16682 |
} |
| 16683 |
viewer.append(spread); |
| 16684 |
} |
| 16685 |
state.scrollDown = pageNumber >= state.previousPageNumber; |
| 16686 |
state.previousPageNumber = pageNumber; |
| 16687 |
} |
| 16688 |
_scrollUpdate() { |
| 16689 |
if (this.pagesCount === 0) { |
| 16690 |
return; |
| 16691 |
} |
| 16692 |
if (this.#scrollTimeoutId) { |
| 16693 |
clearTimeout(this.#scrollTimeoutId); |
| 16694 |
} |
| 16695 |
this.#scrollTimeoutId = setTimeout(() => { |
| 16696 |
this.#scrollTimeoutId = null; |
| 16697 |
this.update(); |
| 16698 |
}, 100); |
| 16699 |
this.update(); |
| 16700 |
} |
| 16701 |
#scrollIntoView(pageView, pageSpot = null) { |
| 16702 |
const { |
| 16703 |
div, |
| 16704 |
id |
| 16705 |
} = pageView; |
| 16706 |
if (this._currentPageNumber !== id) { |
| 16707 |
this._setCurrentPageNumber(id); |
| 16708 |
} |
| 16709 |
if (this._scrollMode === ScrollMode.PAGE) { |
| 16710 |
this.#ensurePageViewVisible(); |
| 16711 |
this.update(); |
| 16712 |
} |
| 16713 |
if (!pageSpot && !this.isInPresentationMode) { |
| 16714 |
const left = div.offsetLeft + div.clientLeft, |
| 16715 |
right = left + div.clientWidth; |
| 16716 |
const { |
| 16717 |
scrollLeft, |
| 16718 |
clientWidth |
| 16719 |
} = this.container; |
| 16720 |
if (this._scrollMode === ScrollMode.HORIZONTAL || left < scrollLeft || right > scrollLeft + clientWidth) { |
| 16721 |
pageSpot = { |
| 16722 |
left: 0, |
| 16723 |
top: 0 |
| 16724 |
}; |
| 16725 |
} |
| 16726 |
} |
| 16727 |
scrollIntoView(div, pageSpot); |
| 16728 |
if (!this._currentScaleValue && this._location) { |
| 16729 |
this._location = null; |
| 16730 |
} |
| 16731 |
} |
| 16732 |
#isSameScale(newScale) { |
| 16733 |
return newScale === this._currentScale || Math.abs(newScale - this._currentScale) < 1e-15; |
| 16734 |
} |
| 16735 |
#setScaleUpdatePages(newScale, newValue, { |
| 16736 |
noScroll = false, |
| 16737 |
preset = false, |
| 16738 |
drawingDelay = -1, |
| 16739 |
origin = null |
| 16740 |
}) { |
| 16741 |
this._currentScaleValue = newValue.toString(); |
| 16742 |
if (this.#isSameScale(newScale)) { |
| 16743 |
if (preset) { |
| 16744 |
this.eventBus.dispatch("scalechanging", { |
| 16745 |
source: this, |
| 16746 |
scale: newScale, |
| 16747 |
presetValue: newValue |
| 16748 |
}); |
| 16749 |
} |
| 16750 |
return; |
| 16751 |
} |
| 16752 |
this.viewer.style.setProperty("--scale-factor", newScale * PixelsPerInch.PDF_TO_CSS_UNITS); |
| 16753 |
const postponeDrawing = drawingDelay >= 0 && drawingDelay < 1000; |
| 16754 |
this.refresh(true, { |
| 16755 |
scale: newScale, |
| 16756 |
drawingDelay: postponeDrawing ? drawingDelay : -1 |
| 16757 |
}); |
| 16758 |
if (postponeDrawing) { |
| 16759 |
this.#scaleTimeoutId = setTimeout(() => { |
| 16760 |
this.#scaleTimeoutId = null; |
| 16761 |
this.refresh(); |
| 16762 |
}, drawingDelay); |
| 16763 |
} |
| 16764 |
const previousScale = this._currentScale; |
| 16765 |
this._currentScale = newScale; |
| 16766 |
if (!noScroll) { |
| 16767 |
let page = this._currentPageNumber, |
| 16768 |
dest; |
| 16769 |
if (this._location && !(this.isInPresentationMode || this.isChangingPresentationMode)) { |
| 16770 |
page = this._location.pageNumber; |
| 16771 |
dest = [null, { |
| 16772 |
name: "XYZ" |
| 16773 |
}, this._location.left, this._location.top, null]; |
| 16774 |
} |
| 16775 |
this.scrollPageIntoView({ |
| 16776 |
pageNumber: page, |
| 16777 |
destArray: dest, |
| 16778 |
allowNegativeOffset: true |
| 16779 |
}); |
| 16780 |
if (Array.isArray(origin)) { |
| 16781 |
const scaleDiff = newScale / previousScale - 1; |
| 16782 |
const [top, left] = this.containerTopLeft; |
| 16783 |
this.container.scrollLeft += (origin[0] - left) * scaleDiff; |
| 16784 |
this.container.scrollTop += (origin[1] - top) * scaleDiff; |
| 16785 |
} |
| 16786 |
} |
| 16787 |
this.eventBus.dispatch("scalechanging", { |
| 16788 |
source: this, |
| 16789 |
scale: newScale, |
| 16790 |
presetValue: preset ? newValue : undefined |
| 16791 |
}); |
| 16792 |
if (this.defaultRenderingQueue) { |
| 16793 |
this.update(); |
| 16794 |
} |
| 16795 |
} |
| 16796 |
get #pageWidthScaleFactor() { |
| 16797 |
if (this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL) { |
| 16798 |
return 2; |
| 16799 |
} |
| 16800 |
return 1; |
| 16801 |
} |
| 16802 |
#setScale(value, options) { |
| 16803 |
let scale = parseFloat(value); |
| 16804 |
if (scale > 0) { |
| 16805 |
options.preset = false; |
| 16806 |
this.#setScaleUpdatePages(scale, value, options); |
| 16807 |
} else { |
| 16808 |
const currentPage = this._pages[this._currentPageNumber - 1]; |
| 16809 |
if (!currentPage) { |
| 16810 |
return; |
| 16811 |
} |
| 16812 |
let hPadding = SCROLLBAR_PADDING, |
| 16813 |
vPadding = VERTICAL_PADDING; |
| 16814 |
if (this.isInPresentationMode) { |
| 16815 |
hPadding = vPadding = 4; |
| 16816 |
if (this._spreadMode !== SpreadMode.NONE) { |
| 16817 |
hPadding *= 2; |
| 16818 |
} |
| 16819 |
} else if (this.removePageBorders) { |
| 16820 |
hPadding = vPadding = 0; |
| 16821 |
} else if (this._scrollMode === ScrollMode.HORIZONTAL) { |
| 16822 |
[hPadding, vPadding] = [vPadding, hPadding]; |
| 16823 |
} |
| 16824 |
const pageWidthScale = (this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor; |
| 16825 |
const pageHeightScale = (this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale; |
| 16826 |
switch (value) { |
| 16827 |
case "page-actual": |
| 16828 |
scale = 1; |
| 16829 |
break; |
| 16830 |
case "page-width": |
| 16831 |
scale = pageWidthScale; |
| 16832 |
break; |
| 16833 |
case "page-height": |
| 16834 |
scale = pageHeightScale; |
| 16835 |
break; |
| 16836 |
case "page-fit": |
| 16837 |
scale = Math.min(pageWidthScale, pageHeightScale); |
| 16838 |
break; |
| 16839 |
case "auto": |
| 16840 |
const horizontalScale = isPortraitOrientation(currentPage) ? pageWidthScale : Math.min(pageHeightScale, pageWidthScale); |
| 16841 |
scale = Math.min(MAX_AUTO_SCALE, horizontalScale); |
| 16842 |
break; |
| 16843 |
default: |
| 16844 |
console.error(`#setScale: "${value}" is an unknown zoom value.`); |
| 16845 |
return; |
| 16846 |
} |
| 16847 |
options.preset = true; |
| 16848 |
this.#setScaleUpdatePages(scale, value, options); |
| 16849 |
} |
| 16850 |
} |
| 16851 |
#resetCurrentPageView() { |
| 16852 |
const pageView = this._pages[this._currentPageNumber - 1]; |
| 16853 |
if (this.isInPresentationMode) { |
| 16854 |
this.#setScale(this._currentScaleValue, { |
| 16855 |
noScroll: true |
| 16856 |
}); |
| 16857 |
} |
| 16858 |
this.#scrollIntoView(pageView); |
| 16859 |
} |
| 16860 |
pageLabelToPageNumber(label) { |
| 16861 |
if (!this._pageLabels) { |
| 16862 |
return null; |
| 16863 |
} |
| 16864 |
const i = this._pageLabels.indexOf(label); |
| 16865 |
if (i < 0) { |
| 16866 |
return null; |
| 16867 |
} |
| 16868 |
return i + 1; |
| 16869 |
} |
| 16870 |
scrollPageIntoView({ |
| 16871 |
pageNumber, |
| 16872 |
destArray = null, |
| 16873 |
allowNegativeOffset = false, |
| 16874 |
ignoreDestinationZoom = false |
| 16875 |
}) { |
| 16876 |
if (!this.pdfDocument) { |
| 16877 |
return; |
| 16878 |
} |
| 16879 |
const pageView = Number.isInteger(pageNumber) && this._pages[pageNumber - 1]; |
| 16880 |
if (!pageView) { |
| 16881 |
console.error(`scrollPageIntoView: "${pageNumber}" is not a valid pageNumber parameter.`); |
| 16882 |
return; |
| 16883 |
} |
| 16884 |
if (this.isInPresentationMode || !destArray) { |
| 16885 |
this._setCurrentPageNumber(pageNumber, true); |
| 16886 |
return; |
| 16887 |
} |
| 16888 |
let x = 0, |
| 16889 |
y = 0; |
| 16890 |
let width = 0, |
| 16891 |
height = 0, |
| 16892 |
widthScale, |
| 16893 |
heightScale; |
| 16894 |
const changeOrientation = pageView.rotation % 180 !== 0; |
| 16895 |
const pageWidth = (changeOrientation ? pageView.height : pageView.width) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS; |
| 16896 |
const pageHeight = (changeOrientation ? pageView.width : pageView.height) / pageView.scale / PixelsPerInch.PDF_TO_CSS_UNITS; |
| 16897 |
let scale = 0; |
| 16898 |
switch (destArray[1].name) { |
| 16899 |
case "XYZ": |
| 16900 |
x = destArray[2]; |
| 16901 |
y = destArray[3]; |
| 16902 |
scale = destArray[4]; |
| 16903 |
x = x !== null ? x : 0; |
| 16904 |
y = y !== null ? y : pageHeight; |
| 16905 |
break; |
| 16906 |
case "Fit": |
| 16907 |
case "FitB": |
| 16908 |
scale = "page-fit"; |
| 16909 |
break; |
| 16910 |
case "FitH": |
| 16911 |
case "FitBH": |
| 16912 |
y = destArray[2]; |
| 16913 |
scale = "page-width"; |
| 16914 |
if (y === null && this._location) { |
| 16915 |
x = this._location.left; |
| 16916 |
y = this._location.top; |
| 16917 |
} else if (typeof y !== "number" || y < 0) { |
| 16918 |
y = pageHeight; |
| 16919 |
} |
| 16920 |
break; |
| 16921 |
case "FitV": |
| 16922 |
case "FitBV": |
| 16923 |
x = destArray[2]; |
| 16924 |
width = pageWidth; |
| 16925 |
height = pageHeight; |
| 16926 |
scale = "page-height"; |
| 16927 |
break; |
| 16928 |
case "FitR": |
| 16929 |
x = destArray[2]; |
| 16930 |
y = destArray[3]; |
| 16931 |
width = destArray[4] - x; |
| 16932 |
height = destArray[5] - y; |
| 16933 |
let hPadding = SCROLLBAR_PADDING, |
| 16934 |
vPadding = VERTICAL_PADDING; |
| 16935 |
if (this.removePageBorders) { |
| 16936 |
hPadding = vPadding = 0; |
| 16937 |
} |
| 16938 |
widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS; |
| 16939 |
heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS; |
| 16940 |
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale)); |
| 16941 |
break; |
| 16942 |
default: |
| 16943 |
console.error(`scrollPageIntoView: "${destArray[1].name}" is not a valid destination type.`); |
| 16944 |
return; |
| 16945 |
} |
| 16946 |
if (!ignoreDestinationZoom) { |
| 16947 |
if (scale && scale !== this._currentScale) { |
| 16948 |
this.currentScaleValue = scale; |
| 16949 |
} else if (this._currentScale === UNKNOWN_SCALE) { |
| 16950 |
this.currentScaleValue = DEFAULT_SCALE_VALUE; |
| 16951 |
} |
| 16952 |
} |
| 16953 |
if (scale === "page-fit" && !destArray[4]) { |
| 16954 |
this.#scrollIntoView(pageView); |
| 16955 |
return; |
| 16956 |
} |
| 16957 |
const boundingRect = [pageView.viewport.convertToViewportPoint(x, y), pageView.viewport.convertToViewportPoint(x + width, y + height)]; |
| 16958 |
let left = Math.min(boundingRect[0][0], boundingRect[1][0]); |
| 16959 |
let top = Math.min(boundingRect[0][1], boundingRect[1][1]); |
| 16960 |
if (!allowNegativeOffset) { |
| 16961 |
left = Math.max(left, 0); |
| 16962 |
top = Math.max(top, 0); |
| 16963 |
} |
| 16964 |
this.#scrollIntoView(pageView, { |
| 16965 |
left, |
| 16966 |
top |
| 16967 |
}); |
| 16968 |
} |
| 16969 |
_updateLocation(firstPage) { |
| 16970 |
const currentScale = this._currentScale; |
| 16971 |
const currentScaleValue = this._currentScaleValue; |
| 16972 |
const normalizedScaleValue = parseFloat(currentScaleValue) === currentScale ? Math.round(currentScale * 10000) / 100 : currentScaleValue; |
| 16973 |
const pageNumber = firstPage.id; |
| 16974 |
const currentPageView = this._pages[pageNumber - 1]; |
| 16975 |
const container = this.container; |
| 16976 |
const topLeft = currentPageView.getPagePoint(container.scrollLeft - firstPage.x, container.scrollTop - firstPage.y); |
| 16977 |
const intLeft = Math.round(topLeft[0]); |
| 16978 |
const intTop = Math.round(topLeft[1]); |
| 16979 |
let pdfOpenParams = `#page=${pageNumber}`; |
| 16980 |
if (!this.isInPresentationMode) { |
| 16981 |
pdfOpenParams += `&zoom=${normalizedScaleValue},${intLeft},${intTop}`; |
| 16982 |
} |
| 16983 |
this._location = { |
| 16984 |
pageNumber, |
| 16985 |
scale: normalizedScaleValue, |
| 16986 |
top: intTop, |
| 16987 |
left: intLeft, |
| 16988 |
rotation: this._pagesRotation, |
| 16989 |
pdfOpenParams |
| 16990 |
}; |
| 16991 |
} |
| 16992 |
update() { |
| 16993 |
const visible = this._getVisiblePages(); |
| 16994 |
const visiblePages = visible.views, |
| 16995 |
numVisiblePages = visiblePages.length; |
| 16996 |
if (numVisiblePages === 0) { |
| 16997 |
return; |
| 16998 |
} |
| 16999 |
const newCacheSize = Math.max(DEFAULT_CACHE_SIZE, 2 * numVisiblePages + 1); |
| 17000 |
this.#buffer.resize(newCacheSize, visible.ids); |
| 17001 |
for (const { |
| 17002 |
view, |
| 17003 |
visibleArea |
| 17004 |
} of visiblePages) { |
| 17005 |
view.updateVisibleArea(visibleArea); |
| 17006 |
} |
| 17007 |
for (const view of this.#buffer) { |
| 17008 |
if (!visible.ids.has(view.id)) { |
| 17009 |
view.updateVisibleArea(null); |
| 17010 |
} |
| 17011 |
} |
| 17012 |
this.renderingQueue.renderHighestPriority(visible); |
| 17013 |
const isSimpleLayout = this._spreadMode === SpreadMode.NONE && (this._scrollMode === ScrollMode.PAGE || this._scrollMode === ScrollMode.VERTICAL); |
| 17014 |
const currentId = this._currentPageNumber; |
| 17015 |
let stillFullyVisible = false; |
| 17016 |
for (const page of visiblePages) { |
| 17017 |
if (page.percent < 100) { |
| 17018 |
break; |
| 17019 |
} |
| 17020 |
if (page.id === currentId && isSimpleLayout) { |
| 17021 |
stillFullyVisible = true; |
| 17022 |
break; |
| 17023 |
} |
| 17024 |
} |
| 17025 |
this._setCurrentPageNumber(stillFullyVisible ? currentId : visiblePages[0].id); |
| 17026 |
this._updateLocation(visible.first); |
| 17027 |
this.eventBus.dispatch("updateviewarea", { |
| 17028 |
source: this, |
| 17029 |
location: this._location |
| 17030 |
}); |
| 17031 |
} |
| 17032 |
#switchToEditAnnotationMode() { |
| 17033 |
const visible = this._getVisiblePages(); |
| 17034 |
const pagesToRefresh = []; |
| 17035 |
const { |
| 17036 |
ids, |
| 17037 |
views |
| 17038 |
} = visible; |
| 17039 |
for (const page of views) { |
| 17040 |
const { |
| 17041 |
view |
| 17042 |
} = page; |
| 17043 |
if (!view.hasEditableAnnotations()) { |
| 17044 |
ids.delete(view.id); |
| 17045 |
continue; |
| 17046 |
} |
| 17047 |
pagesToRefresh.push(page); |
| 17048 |
} |
| 17049 |
if (pagesToRefresh.length === 0) { |
| 17050 |
return null; |
| 17051 |
} |
| 17052 |
this.renderingQueue.renderHighestPriority({ |
| 17053 |
first: pagesToRefresh[0], |
| 17054 |
last: pagesToRefresh.at(-1), |
| 17055 |
views: pagesToRefresh, |
| 17056 |
ids |
| 17057 |
}); |
| 17058 |
return ids; |
| 17059 |
} |
| 17060 |
containsElement(element) { |
| 17061 |
return this.container.contains(element); |
| 17062 |
} |
| 17063 |
focus() { |
| 17064 |
this.container.focus(); |
| 17065 |
} |
| 17066 |
get _isContainerRtl() { |
| 17067 |
return getComputedStyle(this.container).direction === "rtl"; |
| 17068 |
} |
| 17069 |
get isInPresentationMode() { |
| 17070 |
return this.presentationModeState === PresentationModeState.FULLSCREEN; |
| 17071 |
} |
| 17072 |
get isChangingPresentationMode() { |
| 17073 |
return this.presentationModeState === PresentationModeState.CHANGING; |
| 17074 |
} |
| 17075 |
get isHorizontalScrollbarEnabled() { |
| 17076 |
return this.isInPresentationMode ? false : this.container.scrollWidth > this.container.clientWidth; |
| 17077 |
} |
| 17078 |
get isVerticalScrollbarEnabled() { |
| 17079 |
return this.isInPresentationMode ? false : this.container.scrollHeight > this.container.clientHeight; |
| 17080 |
} |
| 17081 |
_getVisiblePages() { |
| 17082 |
const views = this._scrollMode === ScrollMode.PAGE ? this.#scrollModePageState.pages : this._pages, |
| 17083 |
horizontal = this._scrollMode === ScrollMode.HORIZONTAL, |
| 17084 |
rtl = horizontal && this._isContainerRtl; |
| 17085 |
return getVisibleElements({ |
| 17086 |
scrollEl: this.container, |
| 17087 |
views, |
| 17088 |
sortByVisibility: true, |
| 17089 |
horizontal, |
| 17090 |
rtl |
| 17091 |
}); |
| 17092 |
} |
| 17093 |
cleanup() { |
| 17094 |
for (const pageView of this._pages) { |
| 17095 |
if (pageView.renderingState !== RenderingStates.FINISHED) { |
| 17096 |
pageView.reset(); |
| 17097 |
} |
| 17098 |
} |
| 17099 |
} |
| 17100 |
_cancelRendering() { |
| 17101 |
for (const pageView of this._pages) { |
| 17102 |
pageView.cancelRendering(); |
| 17103 |
} |
| 17104 |
} |
| 17105 |
async #ensurePdfPageLoaded(pageView) { |
| 17106 |
if (pageView.pdfPage) { |
| 17107 |
return pageView.pdfPage; |
| 17108 |
} |
| 17109 |
try { |
| 17110 |
const pdfPage = await this.pdfDocument.getPage(pageView.id); |
| 17111 |
if (!pageView.pdfPage) { |
| 17112 |
pageView.setPdfPage(pdfPage); |
| 17113 |
} |
| 17114 |
return pdfPage; |
| 17115 |
} catch (reason) { |
| 17116 |
console.error("Unable to get page for page view", reason); |
| 17117 |
return null; |
| 17118 |
} |
| 17119 |
} |
| 17120 |
#getScrollAhead(visible) { |
| 17121 |
if (visible.first?.id === 1) { |
| 17122 |
return true; |
| 17123 |
} else if (visible.last?.id === this.pagesCount) { |
| 17124 |
return false; |
| 17125 |
} |
| 17126 |
switch (this._scrollMode) { |
| 17127 |
case ScrollMode.PAGE: |
| 17128 |
return this.#scrollModePageState.scrollDown; |
| 17129 |
case ScrollMode.HORIZONTAL: |
| 17130 |
return this.scroll.right; |
| 17131 |
} |
| 17132 |
return this.scroll.down; |
| 17133 |
} |
| 17134 |
forceRendering(currentlyVisiblePages) { |
| 17135 |
const visiblePages = currentlyVisiblePages || this._getVisiblePages(); |
| 17136 |
const scrollAhead = this.#getScrollAhead(visiblePages); |
| 17137 |
const preRenderExtra = this._spreadMode !== SpreadMode.NONE && this._scrollMode !== ScrollMode.HORIZONTAL; |
| 17138 |
const ignoreDetailViews = this.#scaleTimeoutId !== null || this.#scrollTimeoutId !== null && visiblePages.views.some(page => page.detailView?.renderingCancelled); |
| 17139 |
const pageView = this.renderingQueue.getHighestPriority(visiblePages, this._pages, scrollAhead, preRenderExtra, ignoreDetailViews); |
| 17140 |
if (pageView) { |
| 17141 |
this.#ensurePdfPageLoaded(pageView).then(() => { |
| 17142 |
this.renderingQueue.renderView(pageView); |
| 17143 |
}); |
| 17144 |
return true; |
| 17145 |
} |
| 17146 |
return false; |
| 17147 |
} |
| 17148 |
get hasEqualPageSizes() { |
| 17149 |
const firstPageView = this._pages[0]; |
| 17150 |
for (let i = 1, ii = this._pages.length; i < ii; ++i) { |
| 17151 |
const pageView = this._pages[i]; |
| 17152 |
if (pageView.width !== firstPageView.width || pageView.height !== firstPageView.height) { |
| 17153 |
return false; |
| 17154 |
} |
| 17155 |
} |
| 17156 |
return true; |
| 17157 |
} |
| 17158 |
getPagesOverview() { |
| 17159 |
let initialOrientation; |
| 17160 |
return this._pages.map(pageView => { |
| 17161 |
const viewport = pageView.pdfPage.getViewport({ |
| 17162 |
scale: 1 |
| 17163 |
}); |
| 17164 |
const orientation = isPortraitOrientation(viewport); |
| 17165 |
if (initialOrientation === undefined) { |
| 17166 |
initialOrientation = orientation; |
| 17167 |
} else if (this.enablePrintAutoRotate && orientation !== initialOrientation) { |
| 17168 |
return { |
| 17169 |
width: viewport.height, |
| 17170 |
height: viewport.width, |
| 17171 |
rotation: (viewport.rotation - 90) % 360 |
| 17172 |
}; |
| 17173 |
} |
| 17174 |
return { |
| 17175 |
width: viewport.width, |
| 17176 |
height: viewport.height, |
| 17177 |
rotation: viewport.rotation |
| 17178 |
}; |
| 17179 |
}); |
| 17180 |
} |
| 17181 |
get optionalContentConfigPromise() { |
| 17182 |
if (!this.pdfDocument) { |
| 17183 |
return Promise.resolve(null); |
| 17184 |
} |
| 17185 |
if (!this._optionalContentConfigPromise) { |
| 17186 |
console.error("optionalContentConfigPromise: Not initialized yet."); |
| 17187 |
return this.pdfDocument.getOptionalContentConfig({ |
| 17188 |
intent: "display" |
| 17189 |
}); |
| 17190 |
} |
| 17191 |
return this._optionalContentConfigPromise; |
| 17192 |
} |
| 17193 |
set optionalContentConfigPromise(promise) { |
| 17194 |
if (!(promise instanceof Promise)) { |
| 17195 |
throw new Error(`Invalid optionalContentConfigPromise: ${promise}`); |
| 17196 |
} |
| 17197 |
if (!this.pdfDocument) { |
| 17198 |
return; |
| 17199 |
} |
| 17200 |
if (!this._optionalContentConfigPromise) { |
| 17201 |
return; |
| 17202 |
} |
| 17203 |
this._optionalContentConfigPromise = promise; |
| 17204 |
this.refresh(false, { |
| 17205 |
optionalContentConfigPromise: promise |
| 17206 |
}); |
| 17207 |
this.eventBus.dispatch("optionalcontentconfigchanged", { |
| 17208 |
source: this, |
| 17209 |
promise |
| 17210 |
}); |
| 17211 |
} |
| 17212 |
get scrollMode() { |
| 17213 |
return this._scrollMode; |
| 17214 |
} |
| 17215 |
set scrollMode(mode) { |
| 17216 |
if (this._scrollMode === mode) { |
| 17217 |
return; |
| 17218 |
} |
| 17219 |
if (!isValidScrollMode(mode)) { |
| 17220 |
throw new Error(`Invalid scroll mode: ${mode}`); |
| 17221 |
} |
| 17222 |
if (this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE) { |
| 17223 |
return; |
| 17224 |
} |
| 17225 |
this._previousScrollMode = this._scrollMode; |
| 17226 |
this._scrollMode = mode; |
| 17227 |
this.eventBus.dispatch("scrollmodechanged", { |
| 17228 |
source: this, |
| 17229 |
mode |
| 17230 |
}); |
| 17231 |
this._updateScrollMode(this._currentPageNumber); |
| 17232 |
} |
| 17233 |
_updateScrollMode(pageNumber = null) { |
| 17234 |
const scrollMode = this._scrollMode, |
| 17235 |
viewer = this.viewer; |
| 17236 |
viewer.classList.toggle("scrollHorizontal", scrollMode === ScrollMode.HORIZONTAL); |
| 17237 |
viewer.classList.toggle("scrollWrapped", scrollMode === ScrollMode.WRAPPED); |
| 17238 |
if (!this.pdfDocument || !pageNumber) { |
| 17239 |
return; |
| 17240 |
} |
| 17241 |
if (scrollMode === ScrollMode.PAGE) { |
| 17242 |
this.#ensurePageViewVisible(); |
| 17243 |
} else if (this._previousScrollMode === ScrollMode.PAGE) { |
| 17244 |
this._updateSpreadMode(); |
| 17245 |
} |
| 17246 |
if (this._currentScaleValue && isNaN(this._currentScaleValue)) { |
| 17247 |
this.#setScale(this._currentScaleValue, { |
| 17248 |
noScroll: true |
| 17249 |
}); |
| 17250 |
} |
| 17251 |
this._setCurrentPageNumber(pageNumber, true); |
| 17252 |
this.update(); |
| 17253 |
} |
| 17254 |
get spreadMode() { |
| 17255 |
return this._spreadMode; |
| 17256 |
} |
| 17257 |
set spreadMode(mode) { |
| 17258 |
if (this._spreadMode === mode) { |
| 17259 |
return; |
| 17260 |
} |
| 17261 |
if (!isValidSpreadMode(mode)) { |
| 17262 |
throw new Error(`Invalid spread mode: ${mode}`); |
| 17263 |
} |
| 17264 |
this._spreadMode = mode; |
| 17265 |
this.eventBus.dispatch("spreadmodechanged", { |
| 17266 |
source: this, |
| 17267 |
mode |
| 17268 |
}); |
| 17269 |
this._updateSpreadMode(this._currentPageNumber); |
| 17270 |
} |
| 17271 |
_updateSpreadMode(pageNumber = null) { |
| 17272 |
if (!this.pdfDocument) { |
| 17273 |
return; |
| 17274 |
} |
| 17275 |
const viewer = this.viewer, |
| 17276 |
pages = this._pages; |
| 17277 |
if (this._scrollMode === ScrollMode.PAGE) { |
| 17278 |
this.#ensurePageViewVisible(); |
| 17279 |
} else { |
| 17280 |
viewer.textContent = ""; |
| 17281 |
if (this._spreadMode === SpreadMode.NONE) { |
| 17282 |
for (const pageView of this._pages) { |
| 17283 |
viewer.append(pageView.div); |
| 17284 |
} |
| 17285 |
} else { |
| 17286 |
const parity = this._spreadMode - 1; |
| 17287 |
let spread = null; |
| 17288 |
for (let i = 0, ii = pages.length; i < ii; ++i) { |
| 17289 |
if (spread === null) { |
| 17290 |
spread = document.createElement("div"); |
| 17291 |
spread.className = "spread"; |
| 17292 |
viewer.append(spread); |
| 17293 |
} else if (i % 2 === parity) { |
| 17294 |
spread = spread.cloneNode(false); |
| 17295 |
viewer.append(spread); |
| 17296 |
} |
| 17297 |
spread.append(pages[i].div); |
| 17298 |
} |
| 17299 |
} |
| 17300 |
} |
| 17301 |
if (!pageNumber) { |
| 17302 |
return; |
| 17303 |
} |
| 17304 |
if (this._currentScaleValue && isNaN(this._currentScaleValue)) { |
| 17305 |
this.#setScale(this._currentScaleValue, { |
| 17306 |
noScroll: true |
| 17307 |
}); |
| 17308 |
} |
| 17309 |
this._setCurrentPageNumber(pageNumber, true); |
| 17310 |
this.update(); |
| 17311 |
} |
| 17312 |
_getPageAdvance(currentPageNumber, previous = false) { |
| 17313 |
switch (this._scrollMode) { |
| 17314 |
case ScrollMode.WRAPPED: |
| 17315 |
{ |
| 17316 |
const { |
| 17317 |
views |
| 17318 |
} = this._getVisiblePages(), |
| 17319 |
pageLayout = new Map(); |
| 17320 |
for (const { |
| 17321 |
id, |
| 17322 |
y, |
| 17323 |
percent, |
| 17324 |
widthPercent |
| 17325 |
} of views) { |
| 17326 |
if (percent === 0 || widthPercent < 100) { |
| 17327 |
continue; |
| 17328 |
} |
| 17329 |
let yArray = pageLayout.get(y); |
| 17330 |
if (!yArray) { |
| 17331 |
pageLayout.set(y, yArray ||= []); |
| 17332 |
} |
| 17333 |
yArray.push(id); |
| 17334 |
} |
| 17335 |
for (const yArray of pageLayout.values()) { |
| 17336 |
const currentIndex = yArray.indexOf(currentPageNumber); |
| 17337 |
if (currentIndex === -1) { |
| 17338 |
continue; |
| 17339 |
} |
| 17340 |
const numPages = yArray.length; |
| 17341 |
if (numPages === 1) { |
| 17342 |
break; |
| 17343 |
} |
| 17344 |
if (previous) { |
| 17345 |
for (let i = currentIndex - 1, ii = 0; i >= ii; i--) { |
| 17346 |
const currentId = yArray[i], |
| 17347 |
expectedId = yArray[i + 1] - 1; |
| 17348 |
if (currentId < expectedId) { |
| 17349 |
return currentPageNumber - expectedId; |
| 17350 |
} |
| 17351 |
} |
| 17352 |
} else { |
| 17353 |
for (let i = currentIndex + 1, ii = numPages; i < ii; i++) { |
| 17354 |
const currentId = yArray[i], |
| 17355 |
expectedId = yArray[i - 1] + 1; |
| 17356 |
if (currentId > expectedId) { |
| 17357 |
return expectedId - currentPageNumber; |
| 17358 |
} |
| 17359 |
} |
| 17360 |
} |
| 17361 |
if (previous) { |
| 17362 |
const firstId = yArray[0]; |
| 17363 |
if (firstId < currentPageNumber) { |
| 17364 |
return currentPageNumber - firstId + 1; |
| 17365 |
} |
| 17366 |
} else { |
| 17367 |
const lastId = yArray[numPages - 1]; |
| 17368 |
if (lastId > currentPageNumber) { |
| 17369 |
return lastId - currentPageNumber + 1; |
| 17370 |
} |
| 17371 |
} |
| 17372 |
break; |
| 17373 |
} |
| 17374 |
break; |
| 17375 |
} |
| 17376 |
case ScrollMode.HORIZONTAL: |
| 17377 |
{ |
| 17378 |
break; |
| 17379 |
} |
| 17380 |
case ScrollMode.PAGE: |
| 17381 |
case ScrollMode.VERTICAL: |
| 17382 |
{ |
| 17383 |
if (this._spreadMode === SpreadMode.NONE) { |
| 17384 |
break; |
| 17385 |
} |
| 17386 |
const parity = this._spreadMode - 1; |
| 17387 |
if (previous && currentPageNumber % 2 !== parity) { |
| 17388 |
break; |
| 17389 |
} else if (!previous && currentPageNumber % 2 === parity) { |
| 17390 |
break; |
| 17391 |
} |
| 17392 |
const { |
| 17393 |
views |
| 17394 |
} = this._getVisiblePages(), |
| 17395 |
expectedId = previous ? currentPageNumber - 1 : currentPageNumber + 1; |
| 17396 |
for (const { |
| 17397 |
id, |
| 17398 |
percent, |
| 17399 |
widthPercent |
| 17400 |
} of views) { |
| 17401 |
if (id !== expectedId) { |
| 17402 |
continue; |
| 17403 |
} |
| 17404 |
if (percent > 0 && widthPercent === 100) { |
| 17405 |
return 2; |
| 17406 |
} |
| 17407 |
break; |
| 17408 |
} |
| 17409 |
break; |
| 17410 |
} |
| 17411 |
} |
| 17412 |
return 1; |
| 17413 |
} |
| 17414 |
nextPage() { |
| 17415 |
const currentPageNumber = this._currentPageNumber, |
| 17416 |
pagesCount = this.pagesCount; |
| 17417 |
if (currentPageNumber >= pagesCount) { |
| 17418 |
return false; |
| 17419 |
} |
| 17420 |
const advance = this._getPageAdvance(currentPageNumber, false) || 1; |
| 17421 |
this.currentPageNumber = Math.min(currentPageNumber + advance, pagesCount); |
| 17422 |
return true; |
| 17423 |
} |
| 17424 |
previousPage() { |
| 17425 |
const currentPageNumber = this._currentPageNumber; |
| 17426 |
if (currentPageNumber <= 1) { |
| 17427 |
return false; |
| 17428 |
} |
| 17429 |
const advance = this._getPageAdvance(currentPageNumber, true) || 1; |
| 17430 |
this.currentPageNumber = Math.max(currentPageNumber - advance, 1); |
| 17431 |
return true; |
| 17432 |
} |
| 17433 |
updateScale({ |
| 17434 |
drawingDelay, |
| 17435 |
scaleFactor = null, |
| 17436 |
steps = null, |
| 17437 |
origin |
| 17438 |
}) { |
| 17439 |
if (steps === null && scaleFactor === null) { |
| 17440 |
throw new Error("Invalid updateScale options: either `steps` or `scaleFactor` must be provided."); |
| 17441 |
} |
| 17442 |
if (!this.pdfDocument) { |
| 17443 |
return; |
| 17444 |
} |
| 17445 |
let newScale = this._currentScale; |
| 17446 |
if (scaleFactor > 0 && scaleFactor !== 1) { |
| 17447 |
newScale = Math.round(newScale * scaleFactor * 100) / 100; |
| 17448 |
} else if (steps) { |
| 17449 |
const delta = steps > 0 ? DEFAULT_SCALE_DELTA : 1 / DEFAULT_SCALE_DELTA; |
| 17450 |
const round = steps > 0 ? Math.ceil : Math.floor; |
| 17451 |
steps = Math.abs(steps); |
| 17452 |
do { |
| 17453 |
newScale = round((newScale * delta).toFixed(2) * 10) / 10; |
| 17454 |
} while (--steps > 0); |
| 17455 |
} |
| 17456 |
newScale = MathClamp(newScale, MIN_SCALE, MAX_SCALE); |
| 17457 |
this.#setScale(newScale, { |
| 17458 |
noScroll: false, |
| 17459 |
drawingDelay, |
| 17460 |
origin |
| 17461 |
}); |
| 17462 |
} |
| 17463 |
increaseScale(options = {}) { |
| 17464 |
this.updateScale({ |
| 17465 |
...options, |
| 17466 |
steps: options.steps ?? 1 |
| 17467 |
}); |
| 17468 |
} |
| 17469 |
decreaseScale(options = {}) { |
| 17470 |
this.updateScale({ |
| 17471 |
...options, |
| 17472 |
steps: -(options.steps ?? 1) |
| 17473 |
}); |
| 17474 |
} |
| 17475 |
#updateContainerHeightCss(height = this.container.clientHeight) { |
| 17476 |
if (height !== this.#previousContainerHeight) { |
| 17477 |
this.#previousContainerHeight = height; |
| 17478 |
docStyle.setProperty("--viewer-container-height", `${height}px`); |
| 17479 |
} |
| 17480 |
} |
| 17481 |
#resizeObserverCallback(entries) { |
| 17482 |
for (const entry of entries) { |
| 17483 |
if (entry.target === this.container) { |
| 17484 |
this.#updateContainerHeightCss(Math.floor(entry.borderBoxSize[0].blockSize)); |
| 17485 |
this.#containerTopLeft = null; |
| 17486 |
break; |
| 17487 |
} |
| 17488 |
} |
| 17489 |
} |
| 17490 |
get containerTopLeft() { |
| 17491 |
return this.#containerTopLeft ||= [this.container.offsetTop, this.container.offsetLeft]; |
| 17492 |
} |
| 17493 |
#cleanupTimeouts() { |
| 17494 |
if (this.#scaleTimeoutId !== null) { |
| 17495 |
clearTimeout(this.#scaleTimeoutId); |
| 17496 |
this.#scaleTimeoutId = null; |
| 17497 |
} |
| 17498 |
if (this.#scrollTimeoutId !== null) { |
| 17499 |
clearTimeout(this.#scrollTimeoutId); |
| 17500 |
this.#scrollTimeoutId = null; |
| 17501 |
} |
| 17502 |
} |
| 17503 |
#cleanupSwitchAnnotationEditorMode() { |
| 17504 |
this.#switchAnnotationEditorModeAC?.abort(); |
| 17505 |
this.#switchAnnotationEditorModeAC = null; |
| 17506 |
if (this.#switchAnnotationEditorModeTimeoutId !== null) { |
| 17507 |
clearTimeout(this.#switchAnnotationEditorModeTimeoutId); |
| 17508 |
this.#switchAnnotationEditorModeTimeoutId = null; |
| 17509 |
} |
| 17510 |
} |
| 17511 |
#preloadEditingData(mode) { |
| 17512 |
switch (mode) { |
| 17513 |
case AnnotationEditorType.STAMP: |
| 17514 |
this.#mlManager?.loadModel("altText"); |
| 17515 |
break; |
| 17516 |
case AnnotationEditorType.SIGNATURE: |
| 17517 |
this.#signatureManager?.loadSignatures(); |
| 17518 |
break; |
| 17519 |
} |
| 17520 |
} |
| 17521 |
get annotationEditorMode() { |
| 17522 |
return this.#annotationEditorUIManager ? this.#annotationEditorMode : AnnotationEditorType.DISABLE; |
| 17523 |
} |
| 17524 |
set annotationEditorMode({ |
| 17525 |
mode, |
| 17526 |
editId = null, |
| 17527 |
isFromKeyboard = false |
| 17528 |
}) { |
| 17529 |
if (!this.#annotationEditorUIManager) { |
| 17530 |
throw new Error(`The AnnotationEditor is not enabled.`); |
| 17531 |
} |
| 17532 |
if (this.#annotationEditorMode === mode) { |
| 17533 |
return; |
| 17534 |
} |
| 17535 |
if (!isValidAnnotationEditorMode(mode)) { |
| 17536 |
throw new Error(`Invalid AnnotationEditor mode: ${mode}`); |
| 17537 |
} |
| 17538 |
if (!this.pdfDocument) { |
| 17539 |
return; |
| 17540 |
} |
| 17541 |
this.#preloadEditingData(mode); |
| 17542 |
const { |
| 17543 |
eventBus, |
| 17544 |
pdfDocument |
| 17545 |
} = this; |
| 17546 |
const updater = async () => { |
| 17547 |
this.#cleanupSwitchAnnotationEditorMode(); |
| 17548 |
this.#annotationEditorMode = mode; |
| 17549 |
await this.#annotationEditorUIManager.updateMode(mode, editId, isFromKeyboard); |
| 17550 |
if (mode !== this.#annotationEditorMode || pdfDocument !== this.pdfDocument) { |
| 17551 |
return; |
| 17552 |
} |
| 17553 |
eventBus.dispatch("annotationeditormodechanged", { |
| 17554 |
source: this, |
| 17555 |
mode |
| 17556 |
}); |
| 17557 |
}; |
| 17558 |
if (mode === AnnotationEditorType.NONE || this.#annotationEditorMode === AnnotationEditorType.NONE) { |
| 17559 |
const isEditing = mode !== AnnotationEditorType.NONE; |
| 17560 |
if (!isEditing) { |
| 17561 |
this.pdfDocument.annotationStorage.resetModifiedIds(); |
| 17562 |
} |
| 17563 |
for (const pageView of this._pages) { |
| 17564 |
pageView.toggleEditingMode(isEditing); |
| 17565 |
} |
| 17566 |
const idsToRefresh = this.#switchToEditAnnotationMode(); |
| 17567 |
if (isEditing && idsToRefresh) { |
| 17568 |
this.#cleanupSwitchAnnotationEditorMode(); |
| 17569 |
this.#switchAnnotationEditorModeAC = new AbortController(); |
| 17570 |
const signal = AbortSignal.any([this.#eventAbortController.signal, this.#switchAnnotationEditorModeAC.signal]); |
| 17571 |
eventBus._on("pagerendered", ({ |
| 17572 |
pageNumber |
| 17573 |
}) => { |
| 17574 |
idsToRefresh.delete(pageNumber); |
| 17575 |
if (idsToRefresh.size === 0) { |
| 17576 |
this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0); |
| 17577 |
} |
| 17578 |
}, { |
| 17579 |
signal |
| 17580 |
}); |
| 17581 |
return; |
| 17582 |
} |
| 17583 |
} |
| 17584 |
updater(); |
| 17585 |
} |
| 17586 |
refresh(noUpdate = false, updateArgs = Object.create(null)) { |
| 17587 |
if (!this.pdfDocument) { |
| 17588 |
return; |
| 17589 |
} |
| 17590 |
for (const pageView of this._pages) { |
| 17591 |
pageView.update(updateArgs); |
| 17592 |
} |
| 17593 |
this.#cleanupTimeouts(); |
| 17594 |
if (!noUpdate) { |
| 17595 |
this.update(); |
| 17596 |
} |
| 17597 |
} |
| 17598 |
} |
| 17599 |
|
| 17600 |
;// ./web/secondary_toolbar.js |
| 17601 |
|
| 17602 |
|
| 17603 |
|
| 17604 |
class SecondaryToolbar { |
| 17605 |
#opts; |
| 17606 |
constructor(options, eventBus) { |
| 17607 |
this.#opts = options; |
| 17608 |
const buttons = [{ |
| 17609 |
element: options.presentationModeButton, |
| 17610 |
eventName: "presentationmode", |
| 17611 |
close: true |
| 17612 |
}, { |
| 17613 |
element: options.printButton, |
| 17614 |
eventName: "print", |
| 17615 |
close: true |
| 17616 |
}, { |
| 17617 |
element: options.downloadButton, |
| 17618 |
eventName: "download", |
| 17619 |
close: true |
| 17620 |
}, { |
| 17621 |
element: options.viewBookmarkButton, |
| 17622 |
eventName: null, |
| 17623 |
close: true |
| 17624 |
}, { |
| 17625 |
element: options.firstPageButton, |
| 17626 |
eventName: "firstpage", |
| 17627 |
close: true |
| 17628 |
}, { |
| 17629 |
element: options.lastPageButton, |
| 17630 |
eventName: "lastpage", |
| 17631 |
close: true |
| 17632 |
}, { |
| 17633 |
element: options.pageRotateCwButton, |
| 17634 |
eventName: "rotatecw", |
| 17635 |
close: false |
| 17636 |
}, { |
| 17637 |
element: options.pageRotateCcwButton, |
| 17638 |
eventName: "rotateccw", |
| 17639 |
close: false |
| 17640 |
}, { |
| 17641 |
element: options.cursorSelectToolButton, |
| 17642 |
eventName: "switchcursortool", |
| 17643 |
eventDetails: { |
| 17644 |
tool: CursorTool.SELECT |
| 17645 |
}, |
| 17646 |
close: true |
| 17647 |
}, { |
| 17648 |
element: options.cursorHandToolButton, |
| 17649 |
eventName: "switchcursortool", |
| 17650 |
eventDetails: { |
| 17651 |
tool: CursorTool.HAND |
| 17652 |
}, |
| 17653 |
close: true |
| 17654 |
}, { |
| 17655 |
element: options.scrollPageButton, |
| 17656 |
eventName: "switchscrollmode", |
| 17657 |
eventDetails: { |
| 17658 |
mode: ScrollMode.PAGE |
| 17659 |
}, |
| 17660 |
close: true |
| 17661 |
}, { |
| 17662 |
element: options.scrollVerticalButton, |
| 17663 |
eventName: "switchscrollmode", |
| 17664 |
eventDetails: { |
| 17665 |
mode: ScrollMode.VERTICAL |
| 17666 |
}, |
| 17667 |
close: true |
| 17668 |
}, { |
| 17669 |
element: options.scrollHorizontalButton, |
| 17670 |
eventName: "switchscrollmode", |
| 17671 |
eventDetails: { |
| 17672 |
mode: ScrollMode.HORIZONTAL |
| 17673 |
}, |
| 17674 |
close: true |
| 17675 |
}, { |
| 17676 |
element: options.scrollWrappedButton, |
| 17677 |
eventName: "switchscrollmode", |
| 17678 |
eventDetails: { |
| 17679 |
mode: ScrollMode.WRAPPED |
| 17680 |
}, |
| 17681 |
close: true |
| 17682 |
}, { |
| 17683 |
element: options.spreadNoneButton, |
| 17684 |
eventName: "switchspreadmode", |
| 17685 |
eventDetails: { |
| 17686 |
mode: SpreadMode.NONE |
| 17687 |
}, |
| 17688 |
close: true |
| 17689 |
}, { |
| 17690 |
element: options.spreadOddButton, |
| 17691 |
eventName: "switchspreadmode", |
| 17692 |
eventDetails: { |
| 17693 |
mode: SpreadMode.ODD |
| 17694 |
}, |
| 17695 |
close: true |
| 17696 |
}, { |
| 17697 |
element: options.spreadEvenButton, |
| 17698 |
eventName: "switchspreadmode", |
| 17699 |
eventDetails: { |
| 17700 |
mode: SpreadMode.EVEN |
| 17701 |
}, |
| 17702 |
close: true |
| 17703 |
}, { |
| 17704 |
element: options.imageAltTextSettingsButton, |
| 17705 |
eventName: "imagealttextsettings", |
| 17706 |
close: true |
| 17707 |
}, { |
| 17708 |
element: options.documentPropertiesButton, |
| 17709 |
eventName: "documentproperties", |
| 17710 |
close: true |
| 17711 |
}]; |
| 17712 |
buttons.push({ |
| 17713 |
element: options.openFileButton, |
| 17714 |
eventName: "openfile", |
| 17715 |
close: true |
| 17716 |
}); |
| 17717 |
this.eventBus = eventBus; |
| 17718 |
this.opened = false; |
| 17719 |
this.#bindListeners(buttons); |
| 17720 |
this.reset(); |
| 17721 |
} |
| 17722 |
get isOpen() { |
| 17723 |
return this.opened; |
| 17724 |
} |
| 17725 |
setPageNumber(pageNumber) { |
| 17726 |
this.pageNumber = pageNumber; |
| 17727 |
this.#updateUIState(); |
| 17728 |
} |
| 17729 |
setPagesCount(pagesCount) { |
| 17730 |
this.pagesCount = pagesCount; |
| 17731 |
this.#updateUIState(); |
| 17732 |
} |
| 17733 |
reset() { |
| 17734 |
this.pageNumber = 0; |
| 17735 |
this.pagesCount = 0; |
| 17736 |
this.#updateUIState(); |
| 17737 |
this.eventBus.dispatch("switchcursortool", { |
| 17738 |
source: this, |
| 17739 |
reset: true |
| 17740 |
}); |
| 17741 |
this.#scrollModeChanged({ |
| 17742 |
mode: ScrollMode.VERTICAL |
| 17743 |
}); |
| 17744 |
this.#spreadModeChanged({ |
| 17745 |
mode: SpreadMode.NONE |
| 17746 |
}); |
| 17747 |
} |
| 17748 |
#updateUIState() { |
| 17749 |
const { |
| 17750 |
firstPageButton, |
| 17751 |
lastPageButton, |
| 17752 |
pageRotateCwButton, |
| 17753 |
pageRotateCcwButton |
| 17754 |
} = this.#opts; |
| 17755 |
firstPageButton.disabled = this.pageNumber <= 1; |
| 17756 |
lastPageButton.disabled = this.pageNumber >= this.pagesCount; |
| 17757 |
pageRotateCwButton.disabled = this.pagesCount === 0; |
| 17758 |
pageRotateCcwButton.disabled = this.pagesCount === 0; |
| 17759 |
} |
| 17760 |
#bindListeners(buttons) { |
| 17761 |
const { |
| 17762 |
eventBus |
| 17763 |
} = this; |
| 17764 |
const { |
| 17765 |
toggleButton |
| 17766 |
} = this.#opts; |
| 17767 |
toggleButton.addEventListener("click", this.toggle.bind(this)); |
| 17768 |
for (const { |
| 17769 |
element, |
| 17770 |
eventName, |
| 17771 |
close, |
| 17772 |
eventDetails |
| 17773 |
} of buttons) { |
| 17774 |
element.addEventListener("click", evt => { |
| 17775 |
if (eventName !== null) { |
| 17776 |
eventBus.dispatch(eventName, { |
| 17777 |
source: this, |
| 17778 |
...eventDetails |
| 17779 |
}); |
| 17780 |
} |
| 17781 |
if (close) { |
| 17782 |
this.close(); |
| 17783 |
} |
| 17784 |
eventBus.dispatch("reporttelemetry", { |
| 17785 |
source: this, |
| 17786 |
details: { |
| 17787 |
type: "buttons", |
| 17788 |
data: { |
| 17789 |
id: element.id |
| 17790 |
} |
| 17791 |
} |
| 17792 |
}); |
| 17793 |
}); |
| 17794 |
} |
| 17795 |
eventBus._on("cursortoolchanged", this.#cursorToolChanged.bind(this)); |
| 17796 |
eventBus._on("scrollmodechanged", this.#scrollModeChanged.bind(this)); |
| 17797 |
eventBus._on("spreadmodechanged", this.#spreadModeChanged.bind(this)); |
| 17798 |
} |
| 17799 |
#cursorToolChanged({ |
| 17800 |
tool, |
| 17801 |
disabled |
| 17802 |
}) { |
| 17803 |
const { |
| 17804 |
cursorSelectToolButton, |
| 17805 |
cursorHandToolButton |
| 17806 |
} = this.#opts; |
| 17807 |
toggleCheckedBtn(cursorSelectToolButton, tool === CursorTool.SELECT); |
| 17808 |
toggleCheckedBtn(cursorHandToolButton, tool === CursorTool.HAND); |
| 17809 |
cursorSelectToolButton.disabled = disabled; |
| 17810 |
cursorHandToolButton.disabled = disabled; |
| 17811 |
} |
| 17812 |
#scrollModeChanged({ |
| 17813 |
mode |
| 17814 |
}) { |
| 17815 |
const { |
| 17816 |
scrollPageButton, |
| 17817 |
scrollVerticalButton, |
| 17818 |
scrollHorizontalButton, |
| 17819 |
scrollWrappedButton, |
| 17820 |
spreadNoneButton, |
| 17821 |
spreadOddButton, |
| 17822 |
spreadEvenButton |
| 17823 |
} = this.#opts; |
| 17824 |
toggleCheckedBtn(scrollPageButton, mode === ScrollMode.PAGE); |
| 17825 |
toggleCheckedBtn(scrollVerticalButton, mode === ScrollMode.VERTICAL); |
| 17826 |
toggleCheckedBtn(scrollHorizontalButton, mode === ScrollMode.HORIZONTAL); |
| 17827 |
toggleCheckedBtn(scrollWrappedButton, mode === ScrollMode.WRAPPED); |
| 17828 |
const forceScrollModePage = this.pagesCount > PagesCountLimit.FORCE_SCROLL_MODE_PAGE; |
| 17829 |
scrollPageButton.disabled = forceScrollModePage; |
| 17830 |
scrollVerticalButton.disabled = forceScrollModePage; |
| 17831 |
scrollHorizontalButton.disabled = forceScrollModePage; |
| 17832 |
scrollWrappedButton.disabled = forceScrollModePage; |
| 17833 |
const isHorizontal = mode === ScrollMode.HORIZONTAL; |
| 17834 |
spreadNoneButton.disabled = isHorizontal; |
| 17835 |
spreadOddButton.disabled = isHorizontal; |
| 17836 |
spreadEvenButton.disabled = isHorizontal; |
| 17837 |
} |
| 17838 |
#spreadModeChanged({ |
| 17839 |
mode |
| 17840 |
}) { |
| 17841 |
const { |
| 17842 |
spreadNoneButton, |
| 17843 |
spreadOddButton, |
| 17844 |
spreadEvenButton |
| 17845 |
} = this.#opts; |
| 17846 |
toggleCheckedBtn(spreadNoneButton, mode === SpreadMode.NONE); |
| 17847 |
toggleCheckedBtn(spreadOddButton, mode === SpreadMode.ODD); |
| 17848 |
toggleCheckedBtn(spreadEvenButton, mode === SpreadMode.EVEN); |
| 17849 |
} |
| 17850 |
open() { |
| 17851 |
if (this.opened) { |
| 17852 |
return; |
| 17853 |
} |
| 17854 |
this.opened = true; |
| 17855 |
const { |
| 17856 |
toggleButton, |
| 17857 |
toolbar |
| 17858 |
} = this.#opts; |
| 17859 |
toggleExpandedBtn(toggleButton, true, toolbar); |
| 17860 |
} |
| 17861 |
close() { |
| 17862 |
if (!this.opened) { |
| 17863 |
return; |
| 17864 |
} |
| 17865 |
this.opened = false; |
| 17866 |
const { |
| 17867 |
toggleButton, |
| 17868 |
toolbar |
| 17869 |
} = this.#opts; |
| 17870 |
toggleExpandedBtn(toggleButton, false, toolbar); |
| 17871 |
} |
| 17872 |
toggle() { |
| 17873 |
if (this.opened) { |
| 17874 |
this.close(); |
| 17875 |
} else { |
| 17876 |
this.open(); |
| 17877 |
} |
| 17878 |
} |
| 17879 |
} |
| 17880 |
|
| 17881 |
;// ./web/signature_manager.js |
| 17882 |
|
| 17883 |
|
| 17884 |
|
| 17885 |
|
| 17886 |
const DEFAULT_HEIGHT_IN_PAGE = 40; |
| 17887 |
class SignatureManager { |
| 17888 |
#addButton; |
| 17889 |
#tabsToAltText = null; |
| 17890 |
#clearButton; |
| 17891 |
#clearDescription; |
| 17892 |
#currentEditor; |
| 17893 |
#description; |
| 17894 |
#dialog; |
| 17895 |
#drawCurves = null; |
| 17896 |
#drawPlaceholder; |
| 17897 |
#drawPath = null; |
| 17898 |
#drawPathString = ""; |
| 17899 |
#drawPoints = null; |
| 17900 |
#drawSVG; |
| 17901 |
#drawThickness; |
| 17902 |
#errorBar; |
| 17903 |
#extractedSignatureData = null; |
| 17904 |
#imagePath = null; |
| 17905 |
#imagePicker; |
| 17906 |
#imagePickerLink; |
| 17907 |
#imagePlaceholder; |
| 17908 |
#imageSVG; |
| 17909 |
#saveCheckbox; |
| 17910 |
#saveContainer; |
| 17911 |
#tabButtons; |
| 17912 |
#addSignatureToolbarButton; |
| 17913 |
#loadSignaturesPromise = null; |
| 17914 |
#typeInput; |
| 17915 |
#currentTab = null; |
| 17916 |
#currentTabAC = null; |
| 17917 |
#hasDescriptionChanged = false; |
| 17918 |
#eventBus; |
| 17919 |
#l10n; |
| 17920 |
#overlayManager; |
| 17921 |
#editDescriptionDialog; |
| 17922 |
#signatureStorage; |
| 17923 |
#uiManager = null; |
| 17924 |
static #l10nDescription = null; |
| 17925 |
constructor({ |
| 17926 |
dialog, |
| 17927 |
panels, |
| 17928 |
typeButton, |
| 17929 |
typeInput, |
| 17930 |
drawButton, |
| 17931 |
drawPlaceholder, |
| 17932 |
drawSVG, |
| 17933 |
drawThickness, |
| 17934 |
imageButton, |
| 17935 |
imageSVG, |
| 17936 |
imagePlaceholder, |
| 17937 |
imagePicker, |
| 17938 |
imagePickerLink, |
| 17939 |
description, |
| 17940 |
clearButton, |
| 17941 |
cancelButton, |
| 17942 |
addButton, |
| 17943 |
errorCloseButton, |
| 17944 |
errorBar, |
| 17945 |
saveCheckbox, |
| 17946 |
saveContainer |
| 17947 |
}, editSignatureElements, addSignatureToolbarButton, overlayManager, l10n, signatureStorage, eventBus) { |
| 17948 |
this.#addButton = addButton; |
| 17949 |
this.#clearButton = clearButton; |
| 17950 |
this.#clearDescription = description.lastElementChild; |
| 17951 |
this.#description = description.firstElementChild; |
| 17952 |
this.#dialog = dialog; |
| 17953 |
this.#drawSVG = drawSVG; |
| 17954 |
this.#drawPlaceholder = drawPlaceholder; |
| 17955 |
this.#drawThickness = drawThickness; |
| 17956 |
this.#errorBar = errorBar; |
| 17957 |
this.#imageSVG = imageSVG; |
| 17958 |
this.#imagePlaceholder = imagePlaceholder; |
| 17959 |
this.#imagePicker = imagePicker; |
| 17960 |
this.#imagePickerLink = imagePickerLink; |
| 17961 |
this.#overlayManager = overlayManager; |
| 17962 |
this.#saveCheckbox = saveCheckbox; |
| 17963 |
this.#saveContainer = saveContainer; |
| 17964 |
this.#addSignatureToolbarButton = addSignatureToolbarButton; |
| 17965 |
this.#typeInput = typeInput; |
| 17966 |
this.#l10n = l10n; |
| 17967 |
this.#signatureStorage = signatureStorage; |
| 17968 |
this.#eventBus = eventBus; |
| 17969 |
this.#editDescriptionDialog = new EditDescriptionDialog(editSignatureElements, overlayManager); |
| 17970 |
SignatureManager.#l10nDescription ||= Object.freeze({ |
| 17971 |
signature: "pdfjs-editor-add-signature-description-default-when-drawing" |
| 17972 |
}); |
| 17973 |
dialog.addEventListener("close", this.#close.bind(this)); |
| 17974 |
dialog.addEventListener("contextmenu", e => { |
| 17975 |
const { |
| 17976 |
target |
| 17977 |
} = e; |
| 17978 |
if (target !== this.#typeInput && target !== this.#description) { |
| 17979 |
e.preventDefault(); |
| 17980 |
} |
| 17981 |
}); |
| 17982 |
dialog.addEventListener("drop", e => { |
| 17983 |
stopEvent(e); |
| 17984 |
}); |
| 17985 |
cancelButton.addEventListener("click", this.#cancel.bind(this)); |
| 17986 |
addButton.addEventListener("click", this.#add.bind(this)); |
| 17987 |
clearButton.addEventListener("click", () => { |
| 17988 |
this.#reportTelemetry({ |
| 17989 |
type: "signature", |
| 17990 |
action: "pdfjs.signature.clear", |
| 17991 |
data: { |
| 17992 |
type: this.#currentTab |
| 17993 |
} |
| 17994 |
}); |
| 17995 |
this.#initTab(null); |
| 17996 |
}, { |
| 17997 |
passive: true |
| 17998 |
}); |
| 17999 |
this.#description.addEventListener("input", () => { |
| 18000 |
this.#clearDescription.disabled = this.#description.value === ""; |
| 18001 |
}, { |
| 18002 |
passive: true |
| 18003 |
}); |
| 18004 |
this.#clearDescription.addEventListener("click", () => { |
| 18005 |
this.#description.value = ""; |
| 18006 |
this.#clearDescription.disabled = true; |
| 18007 |
}, { |
| 18008 |
passive: true |
| 18009 |
}); |
| 18010 |
errorCloseButton.addEventListener("click", () => { |
| 18011 |
errorBar.hidden = true; |
| 18012 |
}, { |
| 18013 |
passive: true |
| 18014 |
}); |
| 18015 |
this.#initTabButtons(typeButton, drawButton, imageButton, panels); |
| 18016 |
imagePicker.accept = SupportedImageMimeTypes.join(","); |
| 18017 |
eventBus._on("storedsignatureschanged", this.#signaturesChanged.bind(this)); |
| 18018 |
overlayManager.register(dialog); |
| 18019 |
} |
| 18020 |
#initTabButtons(typeButton, drawButton, imageButton, panels) { |
| 18021 |
const buttons = this.#tabButtons = new Map([["type", typeButton], ["draw", drawButton], ["image", imageButton]]); |
| 18022 |
const tabCallback = e => { |
| 18023 |
for (const [name, button] of buttons) { |
| 18024 |
if (button === e.target) { |
| 18025 |
button.setAttribute("aria-selected", true); |
| 18026 |
button.setAttribute("tabindex", 0); |
| 18027 |
panels.setAttribute("data-selected", name); |
| 18028 |
this.#initTab(name); |
| 18029 |
} else { |
| 18030 |
button.setAttribute("aria-selected", false); |
| 18031 |
button.setAttribute("tabindex", -1); |
| 18032 |
} |
| 18033 |
} |
| 18034 |
}; |
| 18035 |
const buttonsArray = Array.from(buttons.values()); |
| 18036 |
for (let i = 0, ii = buttonsArray.length; i < ii; i++) { |
| 18037 |
const button = buttonsArray[i]; |
| 18038 |
button.addEventListener("click", tabCallback, { |
| 18039 |
passive: true |
| 18040 |
}); |
| 18041 |
button.addEventListener("keydown", ({ |
| 18042 |
key |
| 18043 |
}) => { |
| 18044 |
if (key !== "ArrowLeft" && key !== "ArrowRight") { |
| 18045 |
return; |
| 18046 |
} |
| 18047 |
buttonsArray[i + (key === "ArrowLeft" ? -1 : 1)]?.focus(); |
| 18048 |
}, { |
| 18049 |
passive: true |
| 18050 |
}); |
| 18051 |
} |
| 18052 |
} |
| 18053 |
#resetCommon() { |
| 18054 |
this.#hasDescriptionChanged = false; |
| 18055 |
this.#description.value = ""; |
| 18056 |
if (this.#currentTab) { |
| 18057 |
this.#tabsToAltText.get(this.#currentTab).value = ""; |
| 18058 |
} |
| 18059 |
} |
| 18060 |
#resetTab(name) { |
| 18061 |
switch (name) { |
| 18062 |
case "type": |
| 18063 |
this.#typeInput.value = ""; |
| 18064 |
break; |
| 18065 |
case "draw": |
| 18066 |
this.#drawCurves = null; |
| 18067 |
this.#drawPoints = null; |
| 18068 |
this.#drawPathString = ""; |
| 18069 |
this.#drawPath?.remove(); |
| 18070 |
this.#drawPath = null; |
| 18071 |
this.#drawPlaceholder.hidden = false; |
| 18072 |
this.#drawThickness.value = 1; |
| 18073 |
break; |
| 18074 |
case "image": |
| 18075 |
this.#imagePlaceholder.hidden = false; |
| 18076 |
this.#imagePath?.remove(); |
| 18077 |
this.#imagePath = null; |
| 18078 |
break; |
| 18079 |
} |
| 18080 |
} |
| 18081 |
#initTab(name) { |
| 18082 |
if (name && this.#currentTab === name) { |
| 18083 |
return; |
| 18084 |
} |
| 18085 |
if (this.#currentTab) { |
| 18086 |
this.#tabsToAltText.get(this.#currentTab).value = this.#description.value; |
| 18087 |
} |
| 18088 |
if (name) { |
| 18089 |
this.#currentTab = name; |
| 18090 |
} |
| 18091 |
this.#errorBar.hidden = true; |
| 18092 |
const reset = !name; |
| 18093 |
if (reset) { |
| 18094 |
this.#resetCommon(); |
| 18095 |
} else { |
| 18096 |
this.#description.value = this.#tabsToAltText.get(this.#currentTab).value; |
| 18097 |
} |
| 18098 |
this.#clearDescription.disabled = this.#description.value === ""; |
| 18099 |
this.#currentTabAC?.abort(); |
| 18100 |
this.#currentTabAC = new AbortController(); |
| 18101 |
switch (this.#currentTab) { |
| 18102 |
case "type": |
| 18103 |
this.#initTypeTab(reset); |
| 18104 |
break; |
| 18105 |
case "draw": |
| 18106 |
this.#initDrawTab(reset); |
| 18107 |
break; |
| 18108 |
case "image": |
| 18109 |
this.#initImageTab(reset); |
| 18110 |
break; |
| 18111 |
} |
| 18112 |
} |
| 18113 |
#disableButtons(value) { |
| 18114 |
this.#saveCheckbox.disabled = this.#clearButton.disabled = this.#addButton.disabled = this.#description.disabled = !value; |
| 18115 |
} |
| 18116 |
#initTypeTab(reset) { |
| 18117 |
if (reset) { |
| 18118 |
this.#resetTab("type"); |
| 18119 |
} |
| 18120 |
this.#disableButtons(this.#typeInput.value); |
| 18121 |
const { |
| 18122 |
signal |
| 18123 |
} = this.#currentTabAC; |
| 18124 |
const options = { |
| 18125 |
passive: true, |
| 18126 |
signal |
| 18127 |
}; |
| 18128 |
this.#typeInput.addEventListener("input", () => { |
| 18129 |
const { |
| 18130 |
value |
| 18131 |
} = this.#typeInput; |
| 18132 |
if (!this.#hasDescriptionChanged) { |
| 18133 |
this.#tabsToAltText.get("type").default = this.#description.value = value; |
| 18134 |
this.#clearDescription.disabled = value === ""; |
| 18135 |
} |
| 18136 |
this.#disableButtons(value); |
| 18137 |
}, options); |
| 18138 |
this.#description.addEventListener("input", () => { |
| 18139 |
this.#hasDescriptionChanged = this.#typeInput.value !== this.#description.value; |
| 18140 |
}, options); |
| 18141 |
} |
| 18142 |
#initDrawTab(reset) { |
| 18143 |
if (reset) { |
| 18144 |
this.#resetTab("draw"); |
| 18145 |
} |
| 18146 |
this.#disableButtons(this.#drawPath); |
| 18147 |
const { |
| 18148 |
signal |
| 18149 |
} = this.#currentTabAC; |
| 18150 |
const options = { |
| 18151 |
signal |
| 18152 |
}; |
| 18153 |
let currentPointerId = NaN; |
| 18154 |
const drawCallback = e => { |
| 18155 |
const { |
| 18156 |
pointerId |
| 18157 |
} = e; |
| 18158 |
if (!isNaN(currentPointerId) && currentPointerId !== pointerId) { |
| 18159 |
return; |
| 18160 |
} |
| 18161 |
currentPointerId = pointerId; |
| 18162 |
e.preventDefault(); |
| 18163 |
this.#drawSVG.setPointerCapture(pointerId); |
| 18164 |
const { |
| 18165 |
width: drawWidth, |
| 18166 |
height: drawHeight |
| 18167 |
} = this.#drawSVG.getBoundingClientRect(); |
| 18168 |
let { |
| 18169 |
offsetX, |
| 18170 |
offsetY |
| 18171 |
} = e; |
| 18172 |
offsetX = Math.round(offsetX); |
| 18173 |
offsetY = Math.round(offsetY); |
| 18174 |
if (e.target === this.#drawPlaceholder) { |
| 18175 |
this.#drawPlaceholder.hidden = true; |
| 18176 |
} |
| 18177 |
if (!this.#drawCurves) { |
| 18178 |
this.#drawCurves = { |
| 18179 |
width: drawWidth, |
| 18180 |
height: drawHeight, |
| 18181 |
thickness: parseInt(this.#drawThickness.value), |
| 18182 |
curves: [] |
| 18183 |
}; |
| 18184 |
this.#disableButtons(true); |
| 18185 |
const svgFactory = new DOMSVGFactory(); |
| 18186 |
const path = this.#drawPath = svgFactory.createElement("path"); |
| 18187 |
path.setAttribute("stroke-width", this.#drawThickness.value); |
| 18188 |
this.#drawSVG.append(path); |
| 18189 |
this.#drawSVG.addEventListener("pointerdown", drawCallback, options); |
| 18190 |
this.#drawPlaceholder.removeEventListener("pointerdown", drawCallback); |
| 18191 |
if (this.#description.value === "") { |
| 18192 |
this.#l10n.get(SignatureManager.#l10nDescription.signature).then(description => { |
| 18193 |
this.#tabsToAltText.get("draw").default = description; |
| 18194 |
this.#description.value ||= description; |
| 18195 |
this.#clearDescription.disabled = this.#description.value === ""; |
| 18196 |
}); |
| 18197 |
} |
| 18198 |
} |
| 18199 |
this.#drawPoints = [offsetX, offsetY]; |
| 18200 |
this.#drawCurves.curves.push({ |
| 18201 |
points: this.#drawPoints |
| 18202 |
}); |
| 18203 |
this.#drawPathString += `M ${offsetX} ${offsetY}`; |
| 18204 |
this.#drawPath.setAttribute("d", this.#drawPathString); |
| 18205 |
const finishDrawAC = new AbortController(); |
| 18206 |
const listenerDrawOptions = { |
| 18207 |
signal: AbortSignal.any([signal, finishDrawAC.signal]) |
| 18208 |
}; |
| 18209 |
this.#drawSVG.addEventListener("contextmenu", noContextMenu, listenerDrawOptions); |
| 18210 |
this.#drawSVG.addEventListener("pointermove", evt => { |
| 18211 |
evt.preventDefault(); |
| 18212 |
let { |
| 18213 |
offsetX: x, |
| 18214 |
offsetY: y |
| 18215 |
} = evt; |
| 18216 |
x = Math.round(x); |
| 18217 |
y = Math.round(y); |
| 18218 |
const drawPoints = this.#drawPoints; |
| 18219 |
if (x < 0 || y < 0 || x > drawWidth || y > drawHeight || x === drawPoints.at(-2) && y === drawPoints.at(-1)) { |
| 18220 |
return; |
| 18221 |
} |
| 18222 |
if (drawPoints.length >= 4) { |
| 18223 |
const [x1, y1, x2, y2] = drawPoints.slice(-4); |
| 18224 |
this.#drawPathString += `C${(x1 + 5 * x2) / 6} ${(y1 + 5 * y2) / 6} ${(5 * x2 + x) / 6} ${(5 * y2 + y) / 6} ${(x2 + x) / 2} ${(y2 + y) / 2}`; |
| 18225 |
} else { |
| 18226 |
this.#drawPathString += `L${x} ${y}`; |
| 18227 |
} |
| 18228 |
drawPoints.push(x, y); |
| 18229 |
this.#drawPath.setAttribute("d", this.#drawPathString); |
| 18230 |
}, listenerDrawOptions); |
| 18231 |
this.#drawSVG.addEventListener("pointerup", evt => { |
| 18232 |
const { |
| 18233 |
pointerId: pId |
| 18234 |
} = evt; |
| 18235 |
if (!isNaN(currentPointerId) && currentPointerId !== pId) { |
| 18236 |
return; |
| 18237 |
} |
| 18238 |
currentPointerId = NaN; |
| 18239 |
evt.preventDefault(); |
| 18240 |
this.#drawSVG.releasePointerCapture(pId); |
| 18241 |
finishDrawAC.abort(); |
| 18242 |
if (this.#drawPoints.length === 2) { |
| 18243 |
this.#drawPathString += `L${this.#drawPoints[0]} ${this.#drawPoints[1]}`; |
| 18244 |
this.#drawPath.setAttribute("d", this.#drawPathString); |
| 18245 |
} |
| 18246 |
}, listenerDrawOptions); |
| 18247 |
}; |
| 18248 |
if (this.#drawCurves) { |
| 18249 |
this.#drawSVG.addEventListener("pointerdown", drawCallback, options); |
| 18250 |
} else { |
| 18251 |
this.#drawPlaceholder.addEventListener("pointerdown", drawCallback, options); |
| 18252 |
} |
| 18253 |
this.#drawThickness.addEventListener("input", () => { |
| 18254 |
const { |
| 18255 |
value: thickness |
| 18256 |
} = this.#drawThickness; |
| 18257 |
this.#drawThickness.setAttribute("data-l10n-args", JSON.stringify({ |
| 18258 |
thickness |
| 18259 |
})); |
| 18260 |
if (!this.#drawCurves) { |
| 18261 |
return; |
| 18262 |
} |
| 18263 |
this.#drawPath.setAttribute("stroke-width", thickness); |
| 18264 |
this.#drawCurves.thickness = thickness; |
| 18265 |
}, options); |
| 18266 |
} |
| 18267 |
#initImageTab(reset) { |
| 18268 |
if (reset) { |
| 18269 |
this.#resetTab("image"); |
| 18270 |
} |
| 18271 |
this.#disableButtons(this.#imagePath); |
| 18272 |
const { |
| 18273 |
signal |
| 18274 |
} = this.#currentTabAC; |
| 18275 |
const options = { |
| 18276 |
signal |
| 18277 |
}; |
| 18278 |
const passiveOptions = { |
| 18279 |
passive: true, |
| 18280 |
signal |
| 18281 |
}; |
| 18282 |
this.#imagePickerLink.addEventListener("keydown", e => { |
| 18283 |
const { |
| 18284 |
key |
| 18285 |
} = e; |
| 18286 |
if (key === "Enter" || key === " ") { |
| 18287 |
stopEvent(e); |
| 18288 |
this.#imagePicker.click(); |
| 18289 |
} |
| 18290 |
}, options); |
| 18291 |
this.#imagePicker.addEventListener("click", () => { |
| 18292 |
this.#dialog.classList.toggle("waiting", true); |
| 18293 |
}, passiveOptions); |
| 18294 |
this.#imagePicker.addEventListener("change", async () => { |
| 18295 |
const file = this.#imagePicker.files?.[0]; |
| 18296 |
if (!file || !SupportedImageMimeTypes.includes(file.type)) { |
| 18297 |
this.#errorBar.hidden = false; |
| 18298 |
this.#dialog.classList.toggle("waiting", false); |
| 18299 |
return; |
| 18300 |
} |
| 18301 |
await this.#extractSignature(file); |
| 18302 |
}, passiveOptions); |
| 18303 |
this.#imagePicker.addEventListener("cancel", () => { |
| 18304 |
this.#dialog.classList.toggle("waiting", false); |
| 18305 |
}, passiveOptions); |
| 18306 |
this.#imagePlaceholder.addEventListener("dragover", e => { |
| 18307 |
const { |
| 18308 |
dataTransfer |
| 18309 |
} = e; |
| 18310 |
for (const { |
| 18311 |
type |
| 18312 |
} of dataTransfer.items) { |
| 18313 |
if (!SupportedImageMimeTypes.includes(type)) { |
| 18314 |
continue; |
| 18315 |
} |
| 18316 |
dataTransfer.dropEffect = dataTransfer.effectAllowed === "copy" ? "copy" : "move"; |
| 18317 |
stopEvent(e); |
| 18318 |
return; |
| 18319 |
} |
| 18320 |
dataTransfer.dropEffect = "none"; |
| 18321 |
}, options); |
| 18322 |
this.#imagePlaceholder.addEventListener("drop", e => { |
| 18323 |
const { |
| 18324 |
dataTransfer: { |
| 18325 |
files |
| 18326 |
} |
| 18327 |
} = e; |
| 18328 |
if (!files?.length) { |
| 18329 |
return; |
| 18330 |
} |
| 18331 |
for (const file of files) { |
| 18332 |
if (SupportedImageMimeTypes.includes(file.type)) { |
| 18333 |
this.#extractSignature(file); |
| 18334 |
break; |
| 18335 |
} |
| 18336 |
} |
| 18337 |
stopEvent(e); |
| 18338 |
this.#dialog.classList.toggle("waiting", true); |
| 18339 |
}, options); |
| 18340 |
} |
| 18341 |
async #extractSignature(file) { |
| 18342 |
let data; |
| 18343 |
try { |
| 18344 |
data = await this.#uiManager.imageManager.getFromFile(file); |
| 18345 |
} catch (e) { |
| 18346 |
console.error("SignatureManager.#extractSignature.", e); |
| 18347 |
} |
| 18348 |
if (!data) { |
| 18349 |
this.#errorBar.hidden = false; |
| 18350 |
this.#dialog.classList.toggle("waiting", false); |
| 18351 |
return; |
| 18352 |
} |
| 18353 |
const { |
| 18354 |
outline |
| 18355 |
} = this.#extractedSignatureData = this.#currentEditor.getFromImage(data.bitmap); |
| 18356 |
if (!outline) { |
| 18357 |
this.#dialog.classList.toggle("waiting", false); |
| 18358 |
return; |
| 18359 |
} |
| 18360 |
this.#imagePlaceholder.hidden = true; |
| 18361 |
this.#disableButtons(true); |
| 18362 |
const svgFactory = new DOMSVGFactory(); |
| 18363 |
const path = this.#imagePath = svgFactory.createElement("path"); |
| 18364 |
this.#imageSVG.setAttribute("viewBox", outline.viewBox); |
| 18365 |
this.#imageSVG.setAttribute("preserveAspectRatio", "xMidYMid meet"); |
| 18366 |
this.#imageSVG.append(path); |
| 18367 |
path.setAttribute("d", outline.toSVGPath()); |
| 18368 |
this.#tabsToAltText.get("image").default = file.name; |
| 18369 |
if (this.#description.value === "") { |
| 18370 |
this.#description.value = file.name || ""; |
| 18371 |
this.#clearDescription.disabled = this.#description.value === ""; |
| 18372 |
} |
| 18373 |
this.#dialog.classList.toggle("waiting", false); |
| 18374 |
} |
| 18375 |
#getOutlineForType() { |
| 18376 |
return this.#currentEditor.getFromText(this.#typeInput.value, window.getComputedStyle(this.#typeInput)); |
| 18377 |
} |
| 18378 |
#getOutlineForDraw() { |
| 18379 |
const { |
| 18380 |
width, |
| 18381 |
height |
| 18382 |
} = this.#drawSVG.getBoundingClientRect(); |
| 18383 |
return this.#currentEditor.getDrawnSignature(this.#drawCurves, width, height); |
| 18384 |
} |
| 18385 |
#reportTelemetry(data) { |
| 18386 |
this.#eventBus.dispatch("reporttelemetry", { |
| 18387 |
source: this, |
| 18388 |
details: { |
| 18389 |
type: "editing", |
| 18390 |
data |
| 18391 |
} |
| 18392 |
}); |
| 18393 |
} |
| 18394 |
#addToolbarButton(signatureData, uuid, description) { |
| 18395 |
const { |
| 18396 |
curves, |
| 18397 |
areContours, |
| 18398 |
thickness, |
| 18399 |
width, |
| 18400 |
height |
| 18401 |
} = signatureData; |
| 18402 |
const maxDim = Math.max(width, height); |
| 18403 |
const outlineData = SignatureExtractor.processDrawnLines({ |
| 18404 |
lines: { |
| 18405 |
curves, |
| 18406 |
thickness, |
| 18407 |
width, |
| 18408 |
height |
| 18409 |
}, |
| 18410 |
pageWidth: maxDim, |
| 18411 |
pageHeight: maxDim, |
| 18412 |
rotation: 0, |
| 18413 |
innerMargin: 0, |
| 18414 |
mustSmooth: false, |
| 18415 |
areContours |
| 18416 |
}); |
| 18417 |
if (!outlineData) { |
| 18418 |
return; |
| 18419 |
} |
| 18420 |
const { |
| 18421 |
outline |
| 18422 |
} = outlineData; |
| 18423 |
const svgFactory = new DOMSVGFactory(); |
| 18424 |
const div = document.createElement("div"); |
| 18425 |
const button = document.createElement("button"); |
| 18426 |
button.addEventListener("click", () => { |
| 18427 |
this.#eventBus.dispatch("switchannotationeditorparams", { |
| 18428 |
source: this, |
| 18429 |
type: AnnotationEditorParamsType.CREATE, |
| 18430 |
value: { |
| 18431 |
signatureData: { |
| 18432 |
lines: { |
| 18433 |
curves, |
| 18434 |
thickness, |
| 18435 |
width, |
| 18436 |
height |
| 18437 |
}, |
| 18438 |
mustSmooth: false, |
| 18439 |
areContours, |
| 18440 |
description, |
| 18441 |
uuid, |
| 18442 |
heightInPage: DEFAULT_HEIGHT_IN_PAGE |
| 18443 |
} |
| 18444 |
} |
| 18445 |
}); |
| 18446 |
}); |
| 18447 |
div.append(button); |
| 18448 |
div.classList.add("toolbarAddSignatureButtonContainer"); |
| 18449 |
const svg = svgFactory.create(1, 1, true); |
| 18450 |
button.append(svg); |
| 18451 |
const span = document.createElement("span"); |
| 18452 |
span.ariaHidden = true; |
| 18453 |
button.append(span); |
| 18454 |
button.classList.add("toolbarAddSignatureButton"); |
| 18455 |
button.type = "button"; |
| 18456 |
span.textContent = description; |
| 18457 |
button.setAttribute("data-l10n-id", "pdfjs-editor-add-saved-signature-button"); |
| 18458 |
button.setAttribute("data-l10n-args", JSON.stringify({ |
| 18459 |
description |
| 18460 |
})); |
| 18461 |
button.tabIndex = 0; |
| 18462 |
const path = svgFactory.createElement("path"); |
| 18463 |
svg.append(path); |
| 18464 |
svg.setAttribute("viewBox", outline.viewBox); |
| 18465 |
svg.setAttribute("preserveAspectRatio", "xMidYMid meet"); |
| 18466 |
if (areContours) { |
| 18467 |
path.classList.add("contours"); |
| 18468 |
} |
| 18469 |
path.setAttribute("d", outline.toSVGPath()); |
| 18470 |
const deleteButton = document.createElement("button"); |
| 18471 |
div.append(deleteButton); |
| 18472 |
deleteButton.classList.add("toolbarButton", "deleteButton"); |
| 18473 |
deleteButton.setAttribute("data-l10n-id", "pdfjs-editor-delete-signature-button1"); |
| 18474 |
deleteButton.type = "button"; |
| 18475 |
deleteButton.tabIndex = 0; |
| 18476 |
deleteButton.addEventListener("click", async () => { |
| 18477 |
if (await this.#signatureStorage.delete(uuid)) { |
| 18478 |
div.remove(); |
| 18479 |
this.#reportTelemetry({ |
| 18480 |
type: "signature", |
| 18481 |
action: "pdfjs.signature.delete_saved", |
| 18482 |
data: { |
| 18483 |
savedCount: await this.#signatureStorage.size() |
| 18484 |
} |
| 18485 |
}); |
| 18486 |
} |
| 18487 |
}); |
| 18488 |
const deleteSpan = document.createElement("span"); |
| 18489 |
deleteButton.append(deleteSpan); |
| 18490 |
deleteSpan.setAttribute("data-l10n-id", "pdfjs-editor-delete-signature-button-label1"); |
| 18491 |
this.#addSignatureToolbarButton.before(div); |
| 18492 |
} |
| 18493 |
async #signaturesChanged() { |
| 18494 |
const parent = this.#addSignatureToolbarButton.parentElement; |
| 18495 |
while (parent.firstElementChild !== this.#addSignatureToolbarButton) { |
| 18496 |
parent.firstElementChild.remove(); |
| 18497 |
} |
| 18498 |
this.#loadSignaturesPromise = null; |
| 18499 |
await this.loadSignatures(true); |
| 18500 |
} |
| 18501 |
getSignature(params) { |
| 18502 |
return this.open(params); |
| 18503 |
} |
| 18504 |
async loadSignatures(reload = false) { |
| 18505 |
if (!this.#addSignatureToolbarButton || !reload && this.#addSignatureToolbarButton.previousElementSibling || !this.#signatureStorage) { |
| 18506 |
return; |
| 18507 |
} |
| 18508 |
if (!this.#loadSignaturesPromise) { |
| 18509 |
this.#loadSignaturesPromise = this.#signatureStorage.getAll().then(async signatures => [signatures, await Promise.all(Array.from(signatures.values(), ({ |
| 18510 |
signatureData |
| 18511 |
}) => SignatureExtractor.decompressSignature(signatureData)))]); |
| 18512 |
if (!reload) { |
| 18513 |
return; |
| 18514 |
} |
| 18515 |
} |
| 18516 |
const [signatures, signaturesData] = await this.#loadSignaturesPromise; |
| 18517 |
this.#loadSignaturesPromise = null; |
| 18518 |
let i = 0; |
| 18519 |
for (const [uuid, { |
| 18520 |
description |
| 18521 |
}] of signatures) { |
| 18522 |
const data = signaturesData[i++]; |
| 18523 |
if (!data) { |
| 18524 |
continue; |
| 18525 |
} |
| 18526 |
data.curves = data.outlines.map(points => ({ |
| 18527 |
points |
| 18528 |
})); |
| 18529 |
delete data.outlines; |
| 18530 |
this.#addToolbarButton(data, uuid, description); |
| 18531 |
} |
| 18532 |
} |
| 18533 |
async renderEditButton(editor) { |
| 18534 |
const button = document.createElement("button"); |
| 18535 |
button.classList.add("altText", "editDescription"); |
| 18536 |
button.tabIndex = 0; |
| 18537 |
button.title = editor.description; |
| 18538 |
const span = document.createElement("span"); |
| 18539 |
button.append(span); |
| 18540 |
span.setAttribute("data-l10n-id", "pdfjs-editor-add-signature-edit-button-label"); |
| 18541 |
button.addEventListener("click", () => { |
| 18542 |
this.#editDescriptionDialog.open(editor); |
| 18543 |
}, { |
| 18544 |
passive: true |
| 18545 |
}); |
| 18546 |
return button; |
| 18547 |
} |
| 18548 |
async open({ |
| 18549 |
uiManager, |
| 18550 |
editor |
| 18551 |
}) { |
| 18552 |
this.#tabsToAltText ||= new Map(this.#tabButtons.keys().map(name => [name, { |
| 18553 |
value: "", |
| 18554 |
default: "" |
| 18555 |
}])); |
| 18556 |
this.#uiManager = uiManager; |
| 18557 |
this.#currentEditor = editor; |
| 18558 |
this.#uiManager.removeEditListeners(); |
| 18559 |
const isStorageFull = await this.#signatureStorage.isFull(); |
| 18560 |
this.#saveContainer.classList.toggle("fullStorage", isStorageFull); |
| 18561 |
this.#saveCheckbox.checked = !isStorageFull; |
| 18562 |
await this.#overlayManager.open(this.#dialog); |
| 18563 |
const tabType = this.#tabButtons.get("type"); |
| 18564 |
tabType.focus(); |
| 18565 |
tabType.click(); |
| 18566 |
} |
| 18567 |
#cancel() { |
| 18568 |
this.#finish(); |
| 18569 |
} |
| 18570 |
#finish() { |
| 18571 |
this.#overlayManager.closeIfActive(this.#dialog); |
| 18572 |
} |
| 18573 |
#close() { |
| 18574 |
if (this.#currentEditor._drawId === null) { |
| 18575 |
this.#currentEditor.remove(); |
| 18576 |
} |
| 18577 |
this.#uiManager?.addEditListeners(); |
| 18578 |
this.#currentTabAC?.abort(); |
| 18579 |
this.#currentTabAC = null; |
| 18580 |
this.#uiManager = null; |
| 18581 |
this.#currentEditor = null; |
| 18582 |
this.#resetCommon(); |
| 18583 |
for (const [name] of this.#tabButtons) { |
| 18584 |
this.#resetTab(name); |
| 18585 |
} |
| 18586 |
this.#disableButtons(false); |
| 18587 |
this.#currentTab = null; |
| 18588 |
this.#tabsToAltText = null; |
| 18589 |
} |
| 18590 |
async #add() { |
| 18591 |
let data; |
| 18592 |
const type = this.#currentTab; |
| 18593 |
switch (type) { |
| 18594 |
case "type": |
| 18595 |
data = this.#getOutlineForType(); |
| 18596 |
break; |
| 18597 |
case "draw": |
| 18598 |
data = this.#getOutlineForDraw(); |
| 18599 |
break; |
| 18600 |
case "image": |
| 18601 |
data = this.#extractedSignatureData; |
| 18602 |
break; |
| 18603 |
} |
| 18604 |
let uuid = null; |
| 18605 |
const description = this.#description.value; |
| 18606 |
if (this.#saveCheckbox.checked) { |
| 18607 |
const { |
| 18608 |
newCurves, |
| 18609 |
areContours, |
| 18610 |
thickness, |
| 18611 |
width, |
| 18612 |
height |
| 18613 |
} = data; |
| 18614 |
const signatureData = await SignatureExtractor.compressSignature({ |
| 18615 |
outlines: newCurves, |
| 18616 |
areContours, |
| 18617 |
thickness, |
| 18618 |
width, |
| 18619 |
height |
| 18620 |
}); |
| 18621 |
uuid = await this.#signatureStorage.create({ |
| 18622 |
description, |
| 18623 |
signatureData |
| 18624 |
}); |
| 18625 |
if (uuid) { |
| 18626 |
this.#addToolbarButton({ |
| 18627 |
curves: newCurves.map(points => ({ |
| 18628 |
points |
| 18629 |
})), |
| 18630 |
areContours, |
| 18631 |
thickness, |
| 18632 |
width, |
| 18633 |
height |
| 18634 |
}, uuid, description); |
| 18635 |
} else { |
| 18636 |
console.warn("SignatureManager.add: cannot save the signature."); |
| 18637 |
} |
| 18638 |
} |
| 18639 |
const altText = this.#tabsToAltText.get(type); |
| 18640 |
this.#reportTelemetry({ |
| 18641 |
type: "signature", |
| 18642 |
action: "pdfjs.signature.created", |
| 18643 |
data: { |
| 18644 |
type, |
| 18645 |
saved: !!uuid, |
| 18646 |
savedCount: await this.#signatureStorage.size(), |
| 18647 |
descriptionChanged: description !== altText.default |
| 18648 |
} |
| 18649 |
}); |
| 18650 |
this.#currentEditor.addSignature(data, DEFAULT_HEIGHT_IN_PAGE, this.#description.value, uuid); |
| 18651 |
this.#finish(); |
| 18652 |
} |
| 18653 |
destroy() { |
| 18654 |
this.#uiManager = null; |
| 18655 |
this.#finish(); |
| 18656 |
} |
| 18657 |
} |
| 18658 |
class EditDescriptionDialog { |
| 18659 |
#currentEditor; |
| 18660 |
#previousDescription; |
| 18661 |
#description; |
| 18662 |
#dialog; |
| 18663 |
#overlayManager; |
| 18664 |
#signatureSVG; |
| 18665 |
#uiManager; |
| 18666 |
constructor({ |
| 18667 |
dialog, |
| 18668 |
description, |
| 18669 |
cancelButton, |
| 18670 |
updateButton, |
| 18671 |
editSignatureView |
| 18672 |
}, overlayManager) { |
| 18673 |
const descriptionInput = this.#description = description.firstElementChild; |
| 18674 |
this.#signatureSVG = editSignatureView; |
| 18675 |
this.#dialog = dialog; |
| 18676 |
this.#overlayManager = overlayManager; |
| 18677 |
dialog.addEventListener("close", this.#close.bind(this)); |
| 18678 |
dialog.addEventListener("contextmenu", e => { |
| 18679 |
if (e.target !== this.#description) { |
| 18680 |
e.preventDefault(); |
| 18681 |
} |
| 18682 |
}); |
| 18683 |
cancelButton.addEventListener("click", this.#cancel.bind(this)); |
| 18684 |
updateButton.addEventListener("click", this.#update.bind(this)); |
| 18685 |
const clearDescription = description.lastElementChild; |
| 18686 |
clearDescription.addEventListener("click", () => { |
| 18687 |
descriptionInput.value = ""; |
| 18688 |
clearDescription.disabled = true; |
| 18689 |
updateButton.disabled = this.#previousDescription === ""; |
| 18690 |
}); |
| 18691 |
descriptionInput.addEventListener("input", () => { |
| 18692 |
const { |
| 18693 |
value |
| 18694 |
} = descriptionInput; |
| 18695 |
clearDescription.disabled = value === ""; |
| 18696 |
updateButton.disabled = value === this.#previousDescription; |
| 18697 |
editSignatureView.setAttribute("aria-label", value); |
| 18698 |
}, { |
| 18699 |
passive: true |
| 18700 |
}); |
| 18701 |
overlayManager.register(dialog); |
| 18702 |
} |
| 18703 |
async open(editor) { |
| 18704 |
this.#uiManager = editor._uiManager; |
| 18705 |
this.#currentEditor = editor; |
| 18706 |
this.#previousDescription = this.#description.value = editor.description; |
| 18707 |
this.#description.dispatchEvent(new Event("input")); |
| 18708 |
this.#uiManager.removeEditListeners(); |
| 18709 |
const { |
| 18710 |
areContours, |
| 18711 |
outline |
| 18712 |
} = editor.getSignaturePreview(); |
| 18713 |
const svgFactory = new DOMSVGFactory(); |
| 18714 |
const path = svgFactory.createElement("path"); |
| 18715 |
this.#signatureSVG.append(path); |
| 18716 |
this.#signatureSVG.setAttribute("viewBox", outline.viewBox); |
| 18717 |
path.setAttribute("d", outline.toSVGPath()); |
| 18718 |
if (areContours) { |
| 18719 |
path.classList.add("contours"); |
| 18720 |
} |
| 18721 |
await this.#overlayManager.open(this.#dialog); |
| 18722 |
} |
| 18723 |
async #update() { |
| 18724 |
this.#currentEditor._reportTelemetry({ |
| 18725 |
action: "pdfjs.signature.edit_description", |
| 18726 |
data: { |
| 18727 |
hasBeenChanged: true |
| 18728 |
} |
| 18729 |
}); |
| 18730 |
this.#currentEditor.description = this.#description.value; |
| 18731 |
this.#finish(); |
| 18732 |
} |
| 18733 |
#cancel() { |
| 18734 |
this.#currentEditor._reportTelemetry({ |
| 18735 |
action: "pdfjs.signature.edit_description", |
| 18736 |
data: { |
| 18737 |
hasBeenChanged: false |
| 18738 |
} |
| 18739 |
}); |
| 18740 |
this.#finish(); |
| 18741 |
} |
| 18742 |
#finish() { |
| 18743 |
this.#overlayManager.closeIfActive(this.#dialog); |
| 18744 |
} |
| 18745 |
#close() { |
| 18746 |
this.#uiManager?.addEditListeners(); |
| 18747 |
this.#uiManager = null; |
| 18748 |
this.#currentEditor = null; |
| 18749 |
this.#signatureSVG.firstElementChild.remove(); |
| 18750 |
} |
| 18751 |
} |
| 18752 |
|
| 18753 |
;// ./web/toolbar.js |
| 18754 |
|
| 18755 |
|
| 18756 |
class Toolbar { |
| 18757 |
#colorPicker = null; |
| 18758 |
#opts; |
| 18759 |
constructor(options, eventBus, toolbarDensity = 0) { |
| 18760 |
this.#opts = options; |
| 18761 |
this.eventBus = eventBus; |
| 18762 |
const buttons = [{ |
| 18763 |
element: options.previous, |
| 18764 |
eventName: "previouspage" |
| 18765 |
}, { |
| 18766 |
element: options.next, |
| 18767 |
eventName: "nextpage" |
| 18768 |
}, { |
| 18769 |
element: options.zoomIn, |
| 18770 |
eventName: "zoomin" |
| 18771 |
}, { |
| 18772 |
element: options.zoomOut, |
| 18773 |
eventName: "zoomout" |
| 18774 |
}, { |
| 18775 |
element: options.print, |
| 18776 |
eventName: "print" |
| 18777 |
}, { |
| 18778 |
element: options.download, |
| 18779 |
eventName: "download" |
| 18780 |
}, { |
| 18781 |
element: options.editorFreeTextButton, |
| 18782 |
eventName: "switchannotationeditormode", |
| 18783 |
eventDetails: { |
| 18784 |
get mode() { |
| 18785 |
const { |
| 18786 |
classList |
| 18787 |
} = options.editorFreeTextButton; |
| 18788 |
return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.FREETEXT; |
| 18789 |
} |
| 18790 |
} |
| 18791 |
}, { |
| 18792 |
element: options.editorHighlightButton, |
| 18793 |
eventName: "switchannotationeditormode", |
| 18794 |
eventDetails: { |
| 18795 |
get mode() { |
| 18796 |
const { |
| 18797 |
classList |
| 18798 |
} = options.editorHighlightButton; |
| 18799 |
return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.HIGHLIGHT; |
| 18800 |
} |
| 18801 |
} |
| 18802 |
}, { |
| 18803 |
element: options.editorInkButton, |
| 18804 |
eventName: "switchannotationeditormode", |
| 18805 |
eventDetails: { |
| 18806 |
get mode() { |
| 18807 |
const { |
| 18808 |
classList |
| 18809 |
} = options.editorInkButton; |
| 18810 |
return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.INK; |
| 18811 |
} |
| 18812 |
} |
| 18813 |
}, { |
| 18814 |
element: options.editorStampButton, |
| 18815 |
eventName: "switchannotationeditormode", |
| 18816 |
eventDetails: { |
| 18817 |
get mode() { |
| 18818 |
const { |
| 18819 |
classList |
| 18820 |
} = options.editorStampButton; |
| 18821 |
return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.STAMP; |
| 18822 |
} |
| 18823 |
}, |
| 18824 |
telemetry: { |
| 18825 |
type: "editing", |
| 18826 |
data: { |
| 18827 |
action: "pdfjs.image.icon_click" |
| 18828 |
} |
| 18829 |
} |
| 18830 |
}, { |
| 18831 |
element: options.editorSignatureButton, |
| 18832 |
eventName: "switchannotationeditormode", |
| 18833 |
eventDetails: { |
| 18834 |
get mode() { |
| 18835 |
const { |
| 18836 |
classList |
| 18837 |
} = options.editorSignatureButton; |
| 18838 |
return classList.contains("toggled") ? AnnotationEditorType.NONE : AnnotationEditorType.SIGNATURE; |
| 18839 |
} |
| 18840 |
} |
| 18841 |
}]; |
| 18842 |
this.#bindListeners(buttons); |
| 18843 |
this.#updateToolbarDensity({ |
| 18844 |
value: toolbarDensity |
| 18845 |
}); |
| 18846 |
this.reset(); |
| 18847 |
} |
| 18848 |
#updateToolbarDensity({ |
| 18849 |
value |
| 18850 |
}) { |
| 18851 |
let name = "normal"; |
| 18852 |
switch (value) { |
| 18853 |
case 1: |
| 18854 |
name = "compact"; |
| 18855 |
break; |
| 18856 |
case 2: |
| 18857 |
name = "touch"; |
| 18858 |
break; |
| 18859 |
} |
| 18860 |
document.documentElement.setAttribute("data-toolbar-density", name); |
| 18861 |
} |
| 18862 |
setPageNumber(pageNumber, pageLabel) { |
| 18863 |
this.pageNumber = pageNumber; |
| 18864 |
this.pageLabel = pageLabel; |
| 18865 |
this.#updateUIState(false); |
| 18866 |
} |
| 18867 |
setPagesCount(pagesCount, hasPageLabels) { |
| 18868 |
this.pagesCount = pagesCount; |
| 18869 |
this.hasPageLabels = hasPageLabels; |
| 18870 |
this.#updateUIState(true); |
| 18871 |
} |
| 18872 |
setPageScale(pageScaleValue, pageScale) { |
| 18873 |
this.pageScaleValue = (pageScaleValue || pageScale).toString(); |
| 18874 |
this.pageScale = pageScale; |
| 18875 |
this.#updateUIState(false); |
| 18876 |
} |
| 18877 |
reset() { |
| 18878 |
this.#colorPicker = null; |
| 18879 |
this.pageNumber = 0; |
| 18880 |
this.pageLabel = null; |
| 18881 |
this.hasPageLabels = false; |
| 18882 |
this.pagesCount = 0; |
| 18883 |
this.pageScaleValue = DEFAULT_SCALE_VALUE; |
| 18884 |
this.pageScale = DEFAULT_SCALE; |
| 18885 |
this.#updateUIState(true); |
| 18886 |
this.updateLoadingIndicatorState(); |
| 18887 |
this.#editorModeChanged({ |
| 18888 |
mode: AnnotationEditorType.DISABLE |
| 18889 |
}); |
| 18890 |
} |
| 18891 |
#bindListeners(buttons) { |
| 18892 |
const { |
| 18893 |
eventBus |
| 18894 |
} = this; |
| 18895 |
const { |
| 18896 |
editorHighlightColorPicker, |
| 18897 |
editorHighlightButton, |
| 18898 |
pageNumber, |
| 18899 |
scaleSelect |
| 18900 |
} = this.#opts; |
| 18901 |
const self = this; |
| 18902 |
for (const { |
| 18903 |
element, |
| 18904 |
eventName, |
| 18905 |
eventDetails, |
| 18906 |
telemetry |
| 18907 |
} of buttons) { |
| 18908 |
element.addEventListener("click", evt => { |
| 18909 |
if (eventName !== null) { |
| 18910 |
eventBus.dispatch(eventName, { |
| 18911 |
source: this, |
| 18912 |
...eventDetails, |
| 18913 |
isFromKeyboard: evt.detail === 0 |
| 18914 |
}); |
| 18915 |
} |
| 18916 |
if (telemetry) { |
| 18917 |
eventBus.dispatch("reporttelemetry", { |
| 18918 |
source: this, |
| 18919 |
details: telemetry |
| 18920 |
}); |
| 18921 |
} |
| 18922 |
}); |
| 18923 |
} |
| 18924 |
pageNumber.addEventListener("click", function () { |
| 18925 |
this.select(); |
| 18926 |
}); |
| 18927 |
pageNumber.addEventListener("change", function () { |
| 18928 |
eventBus.dispatch("pagenumberchanged", { |
| 18929 |
source: self, |
| 18930 |
value: this.value |
| 18931 |
}); |
| 18932 |
}); |
| 18933 |
scaleSelect.addEventListener("change", function () { |
| 18934 |
if (this.value === "custom") { |
| 18935 |
return; |
| 18936 |
} |
| 18937 |
eventBus.dispatch("scalechanged", { |
| 18938 |
source: self, |
| 18939 |
value: this.value |
| 18940 |
}); |
| 18941 |
}); |
| 18942 |
scaleSelect.addEventListener("click", function ({ |
| 18943 |
target |
| 18944 |
}) { |
| 18945 |
if (this.value === self.pageScaleValue && target.tagName.toUpperCase() === "OPTION") { |
| 18946 |
this.blur(); |
| 18947 |
} |
| 18948 |
}); |
| 18949 |
scaleSelect.oncontextmenu = noContextMenu; |
| 18950 |
eventBus._on("annotationeditormodechanged", this.#editorModeChanged.bind(this)); |
| 18951 |
eventBus._on("showannotationeditorui", ({ |
| 18952 |
mode |
| 18953 |
}) => { |
| 18954 |
switch (mode) { |
| 18955 |
case AnnotationEditorType.HIGHLIGHT: |
| 18956 |
editorHighlightButton.click(); |
| 18957 |
break; |
| 18958 |
} |
| 18959 |
}); |
| 18960 |
eventBus._on("toolbardensity", this.#updateToolbarDensity.bind(this)); |
| 18961 |
if (editorHighlightColorPicker) { |
| 18962 |
eventBus._on("annotationeditoruimanager", ({ |
| 18963 |
uiManager |
| 18964 |
}) => { |
| 18965 |
const cp = this.#colorPicker = new ColorPicker({ |
| 18966 |
uiManager |
| 18967 |
}); |
| 18968 |
uiManager.setMainHighlightColorPicker(cp); |
| 18969 |
editorHighlightColorPicker.append(cp.renderMainDropdown()); |
| 18970 |
}); |
| 18971 |
eventBus._on("mainhighlightcolorpickerupdatecolor", ({ |
| 18972 |
value |
| 18973 |
}) => { |
| 18974 |
this.#colorPicker?.updateColor(value); |
| 18975 |
}); |
| 18976 |
} |
| 18977 |
} |
| 18978 |
#editorModeChanged({ |
| 18979 |
mode |
| 18980 |
}) { |
| 18981 |
const { |
| 18982 |
editorFreeTextButton, |
| 18983 |
editorFreeTextParamsToolbar, |
| 18984 |
editorHighlightButton, |
| 18985 |
editorHighlightParamsToolbar, |
| 18986 |
editorInkButton, |
| 18987 |
editorInkParamsToolbar, |
| 18988 |
editorStampButton, |
| 18989 |
editorStampParamsToolbar, |
| 18990 |
editorSignatureButton, |
| 18991 |
editorSignatureParamsToolbar |
| 18992 |
} = this.#opts; |
| 18993 |
toggleExpandedBtn(editorFreeTextButton, mode === AnnotationEditorType.FREETEXT, editorFreeTextParamsToolbar); |
| 18994 |
toggleExpandedBtn(editorHighlightButton, mode === AnnotationEditorType.HIGHLIGHT, editorHighlightParamsToolbar); |
| 18995 |
toggleExpandedBtn(editorInkButton, mode === AnnotationEditorType.INK, editorInkParamsToolbar); |
| 18996 |
toggleExpandedBtn(editorStampButton, mode === AnnotationEditorType.STAMP, editorStampParamsToolbar); |
| 18997 |
toggleExpandedBtn(editorSignatureButton, mode === AnnotationEditorType.SIGNATURE, editorSignatureParamsToolbar); |
| 18998 |
const isDisable = mode === AnnotationEditorType.DISABLE; |
| 18999 |
editorFreeTextButton.disabled = isDisable; |
| 19000 |
editorHighlightButton.disabled = isDisable; |
| 19001 |
editorInkButton.disabled = isDisable; |
| 19002 |
editorStampButton.disabled = isDisable; |
| 19003 |
editorSignatureButton.disabled = isDisable; |
| 19004 |
} |
| 19005 |
#updateUIState(resetNumPages = false) { |
| 19006 |
const { |
| 19007 |
pageNumber, |
| 19008 |
pagesCount, |
| 19009 |
pageScaleValue, |
| 19010 |
pageScale |
| 19011 |
} = this; |
| 19012 |
const opts = this.#opts; |
| 19013 |
if (resetNumPages) { |
| 19014 |
if (this.hasPageLabels) { |
| 19015 |
opts.pageNumber.type = "text"; |
| 19016 |
opts.numPages.setAttribute("data-l10n-id", "pdfjs-page-of-pages"); |
| 19017 |
} else { |
| 19018 |
opts.pageNumber.type = "number"; |
| 19019 |
opts.numPages.setAttribute("data-l10n-id", "pdfjs-of-pages"); |
| 19020 |
opts.numPages.setAttribute("data-l10n-args", JSON.stringify({ |
| 19021 |
pagesCount |
| 19022 |
})); |
| 19023 |
} |
| 19024 |
opts.pageNumber.max = pagesCount; |
| 19025 |
} |
| 19026 |
if (this.hasPageLabels) { |
| 19027 |
opts.pageNumber.value = this.pageLabel; |
| 19028 |
opts.numPages.setAttribute("data-l10n-args", JSON.stringify({ |
| 19029 |
pageNumber, |
| 19030 |
pagesCount |
| 19031 |
})); |
| 19032 |
} else { |
| 19033 |
opts.pageNumber.value = pageNumber; |
| 19034 |
} |
| 19035 |
opts.previous.disabled = pageNumber <= 1; |
| 19036 |
opts.next.disabled = pageNumber >= pagesCount; |
| 19037 |
opts.zoomOut.disabled = pageScale <= MIN_SCALE; |
| 19038 |
opts.zoomIn.disabled = pageScale >= MAX_SCALE; |
| 19039 |
let predefinedValueFound = false; |
| 19040 |
for (const option of opts.scaleSelect.options) { |
| 19041 |
if (option.value !== pageScaleValue) { |
| 19042 |
option.selected = false; |
| 19043 |
continue; |
| 19044 |
} |
| 19045 |
option.selected = true; |
| 19046 |
predefinedValueFound = true; |
| 19047 |
} |
| 19048 |
if (!predefinedValueFound) { |
| 19049 |
opts.customScaleOption.selected = true; |
| 19050 |
opts.customScaleOption.setAttribute("data-l10n-args", JSON.stringify({ |
| 19051 |
scale: Math.round(pageScale * 10000) / 100 |
| 19052 |
})); |
| 19053 |
} |
| 19054 |
} |
| 19055 |
updateLoadingIndicatorState(loading = false) { |
| 19056 |
const { |
| 19057 |
pageNumber |
| 19058 |
} = this.#opts; |
| 19059 |
pageNumber.classList.toggle("loading", loading); |
| 19060 |
} |
| 19061 |
} |
| 19062 |
|
| 19063 |
;// ./web/view_history.js |
| 19064 |
|
| 19065 |
|
| 19066 |
const DEFAULT_VIEW_HISTORY_CACHE_SIZE = 20; |
| 19067 |
class ViewHistory { |
| 19068 |
constructor(fingerprint, cacheSize = DEFAULT_VIEW_HISTORY_CACHE_SIZE) { |
| 19069 |
this.fingerprint = fingerprint; |
| 19070 |
this.cacheSize = cacheSize; |
| 19071 |
this._initializedPromise = this._readFromStorage().then(databaseStr => { |
| 19072 |
const database = JSON.parse(databaseStr || "{}"); |
| 19073 |
let index = -1; |
| 19074 |
if (!Array.isArray(database.files)) { |
| 19075 |
database.files = []; |
| 19076 |
} else { |
| 19077 |
while (database.files.length >= this.cacheSize) { |
| 19078 |
database.files.shift(); |
| 19079 |
} |
| 19080 |
for (let i = 0, ii = database.files.length; i < ii; i++) { |
| 19081 |
const branch = database.files[i]; |
| 19082 |
if (branch.fingerprint === this.fingerprint) { |
| 19083 |
index = i; |
| 19084 |
break; |
| 19085 |
} |
| 19086 |
} |
| 19087 |
} |
| 19088 |
if (index === -1) { |
| 19089 |
index = database.files.push({ |
| 19090 |
fingerprint: this.fingerprint |
| 19091 |
}) - 1; |
| 19092 |
} |
| 19093 |
this.file = database.files[index]; |
| 19094 |
this.database = database; |
| 19095 |
}); |
| 19096 |
} |
| 19097 |
async _writeToStorage() { |
| 19098 |
const databaseStr = JSON.stringify(this.database); |
| 19099 |
localStorage.setItem("pdfjs.history", databaseStr); |
| 19100 |
} |
| 19101 |
async _readFromStorage() { |
| 19102 |
return localStorage.getItem("pdfjs.history"); |
| 19103 |
} |
| 19104 |
async set(name, val) { |
| 19105 |
await this._initializedPromise; |
| 19106 |
this.file[name] = val; |
| 19107 |
return this._writeToStorage(); |
| 19108 |
} |
| 19109 |
async setMultiple(properties) { |
| 19110 |
await this._initializedPromise; |
| 19111 |
for (const name in properties) { |
| 19112 |
this.file[name] = properties[name]; |
| 19113 |
} |
| 19114 |
return this._writeToStorage(); |
| 19115 |
} |
| 19116 |
async get(name, defaultValue) { |
| 19117 |
await this._initializedPromise; |
| 19118 |
const val = this.file[name]; |
| 19119 |
return val !== undefined ? val : defaultValue; |
| 19120 |
} |
| 19121 |
async getMultiple(properties) { |
| 19122 |
await this._initializedPromise; |
| 19123 |
const values = Object.create(null); |
| 19124 |
for (const name in properties) { |
| 19125 |
const val = this.file[name]; |
| 19126 |
values[name] = val !== undefined ? val : properties[name]; |
| 19127 |
} |
| 19128 |
return values; |
| 19129 |
} |
| 19130 |
} |
| 19131 |
|
| 19132 |
;// ./web/app.js |
| 19133 |
|
| 19134 |
|
| 19135 |
|
| 19136 |
|
| 19137 |
|
| 19138 |
|
| 19139 |
|
| 19140 |
|
| 19141 |
|
| 19142 |
|
| 19143 |
|
| 19144 |
|
| 19145 |
|
| 19146 |
|
| 19147 |
|
| 19148 |
|
| 19149 |
|
| 19150 |
|
| 19151 |
|
| 19152 |
|
| 19153 |
|
| 19154 |
|
| 19155 |
|
| 19156 |
|
| 19157 |
|
| 19158 |
|
| 19159 |
|
| 19160 |
|
| 19161 |
|
| 19162 |
|
| 19163 |
|
| 19164 |
|
| 19165 |
|
| 19166 |
|
| 19167 |
|
| 19168 |
|
| 19169 |
|
| 19170 |
|
| 19171 |
|
| 19172 |
|
| 19173 |
|
| 19174 |
|
| 19175 |
|
| 19176 |
|
| 19177 |
|
| 19178 |
|
| 19179 |
|
| 19180 |
|
| 19181 |
|
| 19182 |
|
| 19183 |
const FORCE_PAGES_LOADED_TIMEOUT = 10000; |
| 19184 |
const ViewOnLoad = { |
| 19185 |
UNKNOWN: -1, |
| 19186 |
PREVIOUS: 0, |
| 19187 |
INITIAL: 1 |
| 19188 |
}; |
| 19189 |
const PDFViewerApplication = { |
| 19190 |
initialBookmark: document.location.hash.substring(1), |
| 19191 |
_initializedCapability: { |
| 19192 |
...Promise.withResolvers(), |
| 19193 |
settled: false |
| 19194 |
}, |
| 19195 |
appConfig: null, |
| 19196 |
pdfDocument: null, |
| 19197 |
pdfLoadingTask: null, |
| 19198 |
printService: null, |
| 19199 |
pdfViewer: null, |
| 19200 |
pdfThumbnailViewer: null, |
| 19201 |
pdfRenderingQueue: null, |
| 19202 |
pdfPresentationMode: null, |
| 19203 |
pdfDocumentProperties: null, |
| 19204 |
pdfLinkService: null, |
| 19205 |
pdfHistory: null, |
| 19206 |
pdfSidebar: null, |
| 19207 |
pdfOutlineViewer: null, |
| 19208 |
pdfAttachmentViewer: null, |
| 19209 |
pdfLayerViewer: null, |
| 19210 |
pdfCursorTools: null, |
| 19211 |
pdfScriptingManager: null, |
| 19212 |
store: null, |
| 19213 |
downloadManager: null, |
| 19214 |
overlayManager: null, |
| 19215 |
preferences: new Preferences(), |
| 19216 |
toolbar: null, |
| 19217 |
secondaryToolbar: null, |
| 19218 |
eventBus: null, |
| 19219 |
l10n: null, |
| 19220 |
annotationEditorParams: null, |
| 19221 |
imageAltTextSettings: null, |
| 19222 |
isInitialViewSet: false, |
| 19223 |
isViewerEmbedded: window.parent !== window, |
| 19224 |
url: "", |
| 19225 |
baseUrl: "", |
| 19226 |
mlManager: null, |
| 19227 |
_downloadUrl: "", |
| 19228 |
_eventBusAbortController: null, |
| 19229 |
_windowAbortController: null, |
| 19230 |
_globalAbortController: new AbortController(), |
| 19231 |
documentInfo: null, |
| 19232 |
metadata: null, |
| 19233 |
_contentDispositionFilename: null, |
| 19234 |
_contentLength: null, |
| 19235 |
_saveInProgress: false, |
| 19236 |
_wheelUnusedTicks: 0, |
| 19237 |
_wheelUnusedFactor: 1, |
| 19238 |
_touchManager: null, |
| 19239 |
_touchUnusedTicks: 0, |
| 19240 |
_touchUnusedFactor: 1, |
| 19241 |
_PDFBug: null, |
| 19242 |
_hasAnnotationEditors: false, |
| 19243 |
_title: document.title, |
| 19244 |
_printAnnotationStoragePromise: null, |
| 19245 |
_isCtrlKeyDown: false, |
| 19246 |
_caretBrowsing: null, |
| 19247 |
_isScrolling: false, |
| 19248 |
editorUndoBar: null, |
| 19249 |
async initialize(appConfig) { |
| 19250 |
this.appConfig = appConfig; |
| 19251 |
try { |
| 19252 |
await this.preferences.initializedPromise; |
| 19253 |
} catch (ex) { |
| 19254 |
console.error("initialize:", ex); |
| 19255 |
} |
| 19256 |
if (AppOptions.get("pdfBugEnabled")) { |
| 19257 |
await this._parseHashParams(); |
| 19258 |
} |
| 19259 |
let mode; |
| 19260 |
switch (AppOptions.get("viewerCssTheme")) { |
| 19261 |
case 1: |
| 19262 |
mode = "light"; |
| 19263 |
break; |
| 19264 |
case 2: |
| 19265 |
mode = "dark"; |
| 19266 |
break; |
| 19267 |
} |
| 19268 |
if (mode) { |
| 19269 |
docStyle.setProperty("color-scheme", mode); |
| 19270 |
} |
| 19271 |
this.l10n = await this.externalServices.createL10n(); |
| 19272 |
document.getElementsByTagName("html")[0].dir = this.l10n.getDirection(); |
| 19273 |
this.l10n.translate(appConfig.appContainer || document.documentElement); |
| 19274 |
if (this.isViewerEmbedded && AppOptions.get("externalLinkTarget") === LinkTarget.NONE) { |
| 19275 |
AppOptions.set("externalLinkTarget", LinkTarget.TOP); |
| 19276 |
} |
| 19277 |
await this._initializeViewerComponents(); |
| 19278 |
this.bindEvents(); |
| 19279 |
this.bindWindowEvents(); |
| 19280 |
this._initializedCapability.settled = true; |
| 19281 |
this._initializedCapability.resolve(); |
| 19282 |
}, |
| 19283 |
async _parseHashParams() { |
| 19284 |
const hash = document.location.hash.substring(1); |
| 19285 |
if (!hash) { |
| 19286 |
return; |
| 19287 |
} |
| 19288 |
const { |
| 19289 |
mainContainer, |
| 19290 |
viewerContainer |
| 19291 |
} = this.appConfig, |
| 19292 |
params = parseQueryString(hash); |
| 19293 |
const loadPDFBug = async () => { |
| 19294 |
if (this._PDFBug) { |
| 19295 |
return; |
| 19296 |
} |
| 19297 |
const { |
| 19298 |
PDFBug |
| 19299 |
} = await import( |
| 19300 |
/*webpackIgnore: true*/ |
| 19301 |
/*@vite-ignore*/ |
| 19302 |
AppOptions.get("debuggerSrc")); |
| 19303 |
this._PDFBug = PDFBug; |
| 19304 |
}; |
| 19305 |
if (params.get("disableworker") === "true") { |
| 19306 |
try { |
| 19307 |
GlobalWorkerOptions.workerSrc ||= AppOptions.get("workerSrc"); |
| 19308 |
await import( |
| 19309 |
/*webpackIgnore: true*/ |
| 19310 |
/*@vite-ignore*/ |
| 19311 |
PDFWorker.workerSrc); |
| 19312 |
AppOptions.set("workerPort", null); |
| 19313 |
} catch (ex) { |
| 19314 |
console.error("_parseHashParams:", ex); |
| 19315 |
} |
| 19316 |
} |
| 19317 |
if (params.has("textlayer")) { |
| 19318 |
switch (params.get("textlayer")) { |
| 19319 |
case "off": |
| 19320 |
AppOptions.set("textLayerMode", TextLayerMode.DISABLE); |
| 19321 |
break; |
| 19322 |
case "visible": |
| 19323 |
case "shadow": |
| 19324 |
case "hover": |
| 19325 |
viewerContainer.classList.add(`textLayer-${params.get("textlayer")}`); |
| 19326 |
try { |
| 19327 |
await loadPDFBug(); |
| 19328 |
this._PDFBug.loadCSS(); |
| 19329 |
} catch (ex) { |
| 19330 |
console.error("_parseHashParams:", ex); |
| 19331 |
} |
| 19332 |
break; |
| 19333 |
} |
| 19334 |
} |
| 19335 |
if (params.has("pdfbug")) { |
| 19336 |
const enabled = params.get("pdfbug").split(","); |
| 19337 |
try { |
| 19338 |
await loadPDFBug(); |
| 19339 |
this._PDFBug.init(mainContainer, enabled); |
| 19340 |
} catch (ex) { |
| 19341 |
console.error("_parseHashParams:", ex); |
| 19342 |
} |
| 19343 |
const debugOpts = { |
| 19344 |
pdfBug: true, |
| 19345 |
fontExtraProperties: true |
| 19346 |
}; |
| 19347 |
if (globalThis.StepperManager?.enabled) { |
| 19348 |
debugOpts.minDurationToUpdateCanvas = 0; |
| 19349 |
} |
| 19350 |
AppOptions.setAll(debugOpts); |
| 19351 |
} |
| 19352 |
if (params.has("locale")) { |
| 19353 |
AppOptions.set("localeProperties", { |
| 19354 |
lang: params.get("locale") |
| 19355 |
}); |
| 19356 |
} |
| 19357 |
const opts = { |
| 19358 |
disableAutoFetch: x => x === "true", |
| 19359 |
disableFontFace: x => x === "true", |
| 19360 |
disableHistory: x => x === "true", |
| 19361 |
disableRange: x => x === "true", |
| 19362 |
disableStream: x => x === "true", |
| 19363 |
verbosity: x => x | 0 |
| 19364 |
}; |
| 19365 |
for (const name in opts) { |
| 19366 |
const check = opts[name], |
| 19367 |
key = name.toLowerCase(); |
| 19368 |
if (params.has(key)) { |
| 19369 |
AppOptions.set(name, check(params.get(key))); |
| 19370 |
} |
| 19371 |
} |
| 19372 |
}, |
| 19373 |
async _initializeViewerComponents() { |
| 19374 |
const { |
| 19375 |
appConfig, |
| 19376 |
externalServices, |
| 19377 |
l10n, |
| 19378 |
mlManager |
| 19379 |
} = this; |
| 19380 |
const abortSignal = this._globalAbortController.signal; |
| 19381 |
const eventBus = new EventBus(); |
| 19382 |
this.eventBus = AppOptions.eventBus = eventBus; |
| 19383 |
mlManager?.setEventBus(eventBus, abortSignal); |
| 19384 |
const overlayManager = this.overlayManager = new OverlayManager(); |
| 19385 |
const renderingQueue = this.pdfRenderingQueue = new PDFRenderingQueue(); |
| 19386 |
renderingQueue.onIdle = this._cleanup.bind(this); |
| 19387 |
const linkService = this.pdfLinkService = new PDFLinkService({ |
| 19388 |
eventBus, |
| 19389 |
externalLinkTarget: AppOptions.get("externalLinkTarget"), |
| 19390 |
externalLinkRel: AppOptions.get("externalLinkRel"), |
| 19391 |
ignoreDestinationZoom: AppOptions.get("ignoreDestinationZoom") |
| 19392 |
}); |
| 19393 |
const downloadManager = this.downloadManager = new DownloadManager(); |
| 19394 |
const findController = this.findController = new PDFFindController({ |
| 19395 |
linkService, |
| 19396 |
eventBus, |
| 19397 |
updateMatchesCountOnProgress: true |
| 19398 |
}); |
| 19399 |
const pdfScriptingManager = this.pdfScriptingManager = new PDFScriptingManager({ |
| 19400 |
eventBus, |
| 19401 |
externalServices, |
| 19402 |
docProperties: this._scriptingDocProperties.bind(this) |
| 19403 |
}); |
| 19404 |
const container = appConfig.mainContainer, |
| 19405 |
viewer = appConfig.viewerContainer; |
| 19406 |
const annotationEditorMode = AppOptions.get("annotationEditorMode"); |
| 19407 |
const pageColors = AppOptions.get("forcePageColors") || window.matchMedia("(forced-colors: active)").matches ? { |
| 19408 |
background: AppOptions.get("pageColorsBackground"), |
| 19409 |
foreground: AppOptions.get("pageColorsForeground") |
| 19410 |
} : null; |
| 19411 |
let altTextManager; |
| 19412 |
if (AppOptions.get("enableUpdatedAddImage")) { |
| 19413 |
altTextManager = appConfig.newAltTextDialog ? new NewAltTextManager(appConfig.newAltTextDialog, overlayManager, eventBus) : null; |
| 19414 |
} else { |
| 19415 |
altTextManager = appConfig.altTextDialog ? new AltTextManager(appConfig.altTextDialog, container, overlayManager, eventBus) : null; |
| 19416 |
} |
| 19417 |
if (appConfig.editorUndoBar) { |
| 19418 |
this.editorUndoBar = new EditorUndoBar(appConfig.editorUndoBar, eventBus); |
| 19419 |
} |
| 19420 |
const signatureManager = AppOptions.get("enableSignatureEditor") && appConfig.addSignatureDialog ? new SignatureManager(appConfig.addSignatureDialog, appConfig.editSignatureDialog, appConfig.annotationEditorParams?.editorSignatureAddSignature || null, overlayManager, l10n, externalServices.createSignatureStorage(eventBus, abortSignal), eventBus) : null; |
| 19421 |
const enableHWA = AppOptions.get("enableHWA"), |
| 19422 |
maxCanvasPixels = AppOptions.get("maxCanvasPixels"), |
| 19423 |
maxCanvasDim = AppOptions.get("maxCanvasDim"), |
| 19424 |
capCanvasAreaFactor = AppOptions.get("capCanvasAreaFactor"); |
| 19425 |
const pdfViewer = this.pdfViewer = new PDFViewer({ |
| 19426 |
container, |
| 19427 |
viewer, |
| 19428 |
eventBus, |
| 19429 |
renderingQueue, |
| 19430 |
linkService, |
| 19431 |
downloadManager, |
| 19432 |
altTextManager, |
| 19433 |
signatureManager, |
| 19434 |
editorUndoBar: this.editorUndoBar, |
| 19435 |
findController, |
| 19436 |
scriptingManager: AppOptions.get("enableScripting") && pdfScriptingManager, |
| 19437 |
l10n, |
| 19438 |
textLayerMode: AppOptions.get("textLayerMode"), |
| 19439 |
annotationMode: AppOptions.get("annotationMode"), |
| 19440 |
annotationEditorMode, |
| 19441 |
annotationEditorHighlightColors: AppOptions.get("highlightEditorColors"), |
| 19442 |
enableHighlightFloatingButton: AppOptions.get("enableHighlightFloatingButton"), |
| 19443 |
enableUpdatedAddImage: AppOptions.get("enableUpdatedAddImage"), |
| 19444 |
enableNewAltTextWhenAddingImage: AppOptions.get("enableNewAltTextWhenAddingImage"), |
| 19445 |
imageResourcesPath: AppOptions.get("imageResourcesPath"), |
| 19446 |
enablePrintAutoRotate: AppOptions.get("enablePrintAutoRotate"), |
| 19447 |
maxCanvasPixels, |
| 19448 |
maxCanvasDim, |
| 19449 |
capCanvasAreaFactor, |
| 19450 |
enableDetailCanvas: AppOptions.get("enableDetailCanvas"), |
| 19451 |
enablePermissions: AppOptions.get("enablePermissions"), |
| 19452 |
pageColors, |
| 19453 |
mlManager, |
| 19454 |
abortSignal, |
| 19455 |
enableHWA, |
| 19456 |
supportsPinchToZoom: this.supportsPinchToZoom, |
| 19457 |
enableAutoLinking: AppOptions.get("enableAutoLinking"), |
| 19458 |
minDurationToUpdateCanvas: AppOptions.get("minDurationToUpdateCanvas") |
| 19459 |
}); |
| 19460 |
renderingQueue.setViewer(pdfViewer); |
| 19461 |
linkService.setViewer(pdfViewer); |
| 19462 |
pdfScriptingManager.setViewer(pdfViewer); |
| 19463 |
if (appConfig.sidebar?.thumbnailView) { |
| 19464 |
this.pdfThumbnailViewer = new PDFThumbnailViewer({ |
| 19465 |
container: appConfig.sidebar.thumbnailView, |
| 19466 |
eventBus, |
| 19467 |
renderingQueue, |
| 19468 |
linkService, |
| 19469 |
maxCanvasPixels, |
| 19470 |
maxCanvasDim, |
| 19471 |
pageColors, |
| 19472 |
abortSignal, |
| 19473 |
enableHWA |
| 19474 |
}); |
| 19475 |
renderingQueue.setThumbnailViewer(this.pdfThumbnailViewer); |
| 19476 |
} |
| 19477 |
if (!this.isViewerEmbedded && !AppOptions.get("disableHistory")) { |
| 19478 |
this.pdfHistory = new PDFHistory({ |
| 19479 |
linkService, |
| 19480 |
eventBus |
| 19481 |
}); |
| 19482 |
linkService.setHistory(this.pdfHistory); |
| 19483 |
} |
| 19484 |
if (!this.supportsIntegratedFind && appConfig.findBar) { |
| 19485 |
this.findBar = new PDFFindBar(appConfig.findBar, appConfig.principalContainer, eventBus); |
| 19486 |
} |
| 19487 |
if (appConfig.annotationEditorParams) { |
| 19488 |
if (annotationEditorMode !== AnnotationEditorType.DISABLE) { |
| 19489 |
const editorSignatureButton = appConfig.toolbar?.editorSignatureButton; |
| 19490 |
if (editorSignatureButton && AppOptions.get("enableSignatureEditor")) { |
| 19491 |
editorSignatureButton.parentElement.hidden = false; |
| 19492 |
} |
| 19493 |
this.annotationEditorParams = new AnnotationEditorParams(appConfig.annotationEditorParams, eventBus); |
| 19494 |
} else { |
| 19495 |
for (const id of ["editorModeButtons", "editorModeSeparator"]) { |
| 19496 |
document.getElementById(id)?.classList.add("hidden"); |
| 19497 |
} |
| 19498 |
} |
| 19499 |
} |
| 19500 |
if (mlManager && appConfig.secondaryToolbar?.imageAltTextSettingsButton) { |
| 19501 |
this.imageAltTextSettings = new ImageAltTextSettings(appConfig.altTextSettingsDialog, overlayManager, eventBus, mlManager); |
| 19502 |
} |
| 19503 |
if (appConfig.documentProperties) { |
| 19504 |
this.pdfDocumentProperties = new PDFDocumentProperties(appConfig.documentProperties, overlayManager, eventBus, l10n, () => this._docFilename, () => this._docTitle); |
| 19505 |
} |
| 19506 |
if (appConfig.secondaryToolbar?.cursorHandToolButton) { |
| 19507 |
this.pdfCursorTools = new PDFCursorTools({ |
| 19508 |
container, |
| 19509 |
eventBus, |
| 19510 |
cursorToolOnLoad: AppOptions.get("cursorToolOnLoad") |
| 19511 |
}); |
| 19512 |
} |
| 19513 |
if (appConfig.toolbar) { |
| 19514 |
this.toolbar = new Toolbar(appConfig.toolbar, eventBus, AppOptions.get("toolbarDensity")); |
| 19515 |
} |
| 19516 |
if (appConfig.secondaryToolbar) { |
| 19517 |
if (AppOptions.get("enableAltText")) { |
| 19518 |
appConfig.secondaryToolbar.imageAltTextSettingsButton?.classList.remove("hidden"); |
| 19519 |
appConfig.secondaryToolbar.imageAltTextSettingsSeparator?.classList.remove("hidden"); |
| 19520 |
} |
| 19521 |
this.secondaryToolbar = new SecondaryToolbar(appConfig.secondaryToolbar, eventBus); |
| 19522 |
} |
| 19523 |
if (this.supportsFullscreen && appConfig.secondaryToolbar?.presentationModeButton) { |
| 19524 |
this.pdfPresentationMode = new PDFPresentationMode({ |
| 19525 |
container, |
| 19526 |
pdfViewer, |
| 19527 |
eventBus |
| 19528 |
}); |
| 19529 |
} |
| 19530 |
if (appConfig.passwordOverlay) { |
| 19531 |
this.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay, overlayManager, this.isViewerEmbedded); |
| 19532 |
} |
| 19533 |
if (appConfig.sidebar?.outlineView) { |
| 19534 |
this.pdfOutlineViewer = new PDFOutlineViewer({ |
| 19535 |
container: appConfig.sidebar.outlineView, |
| 19536 |
eventBus, |
| 19537 |
l10n, |
| 19538 |
linkService, |
| 19539 |
downloadManager |
| 19540 |
}); |
| 19541 |
} |
| 19542 |
if (appConfig.sidebar?.attachmentsView) { |
| 19543 |
this.pdfAttachmentViewer = new PDFAttachmentViewer({ |
| 19544 |
container: appConfig.sidebar.attachmentsView, |
| 19545 |
eventBus, |
| 19546 |
l10n, |
| 19547 |
downloadManager |
| 19548 |
}); |
| 19549 |
} |
| 19550 |
if (appConfig.sidebar?.layersView) { |
| 19551 |
this.pdfLayerViewer = new PDFLayerViewer({ |
| 19552 |
container: appConfig.sidebar.layersView, |
| 19553 |
eventBus, |
| 19554 |
l10n |
| 19555 |
}); |
| 19556 |
} |
| 19557 |
if (appConfig.sidebar) { |
| 19558 |
this.pdfSidebar = new PDFSidebar({ |
| 19559 |
elements: appConfig.sidebar, |
| 19560 |
eventBus, |
| 19561 |
l10n |
| 19562 |
}); |
| 19563 |
this.pdfSidebar.onToggled = this.forceRendering.bind(this); |
| 19564 |
this.pdfSidebar.onUpdateThumbnails = () => { |
| 19565 |
for (const pageView of pdfViewer.getCachedPageViews()) { |
| 19566 |
if (pageView.renderingState === RenderingStates.FINISHED) { |
| 19567 |
this.pdfThumbnailViewer.getThumbnail(pageView.id - 1)?.setImage(pageView); |
| 19568 |
} |
| 19569 |
} |
| 19570 |
this.pdfThumbnailViewer.scrollThumbnailIntoView(pdfViewer.currentPageNumber); |
| 19571 |
}; |
| 19572 |
} |
| 19573 |
}, |
| 19574 |
async run(config) { |
| 19575 |
await this.initialize(config); |
| 19576 |
const { |
| 19577 |
appConfig, |
| 19578 |
eventBus |
| 19579 |
} = this; |
| 19580 |
let file; |
| 19581 |
const queryString = document.location.search.substring(1); |
| 19582 |
const params = parseQueryString(queryString); |
| 19583 |
file = params.get("file") ?? AppOptions.get("defaultUrl"); |
| 19584 |
validateFileURL(file); |
| 19585 |
const fileInput = this._openFileInput = document.createElement("input"); |
| 19586 |
fileInput.id = "fileInput"; |
| 19587 |
fileInput.hidden = true; |
| 19588 |
fileInput.type = "file"; |
| 19589 |
fileInput.value = null; |
| 19590 |
document.body.append(fileInput); |
| 19591 |
fileInput.addEventListener("change", function (evt) { |
| 19592 |
const { |
| 19593 |
files |
| 19594 |
} = evt.target; |
| 19595 |
if (!files || files.length === 0) { |
| 19596 |
return; |
| 19597 |
} |
| 19598 |
eventBus.dispatch("fileinputchange", { |
| 19599 |
source: this, |
| 19600 |
fileInput: evt.target |
| 19601 |
}); |
| 19602 |
}); |
| 19603 |
appConfig.mainContainer.addEventListener("dragover", function (evt) { |
| 19604 |
for (const item of evt.dataTransfer.items) { |
| 19605 |
if (item.type === "application/pdf") { |
| 19606 |
evt.dataTransfer.dropEffect = evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move"; |
| 19607 |
stopEvent(evt); |
| 19608 |
return; |
| 19609 |
} |
| 19610 |
} |
| 19611 |
}); |
| 19612 |
appConfig.mainContainer.addEventListener("drop", function (evt) { |
| 19613 |
if (evt.dataTransfer.files?.[0].type !== "application/pdf") { |
| 19614 |
return; |
| 19615 |
} |
| 19616 |
stopEvent(evt); |
| 19617 |
eventBus.dispatch("fileinputchange", { |
| 19618 |
source: this, |
| 19619 |
fileInput: evt.dataTransfer |
| 19620 |
}); |
| 19621 |
}); |
| 19622 |
if (!AppOptions.get("supportsDocumentFonts")) { |
| 19623 |
AppOptions.set("disableFontFace", true); |
| 19624 |
this.l10n.get("pdfjs-web-fonts-disabled").then(msg => { |
| 19625 |
console.warn(msg); |
| 19626 |
}); |
| 19627 |
} |
| 19628 |
if (!this.supportsPrinting) { |
| 19629 |
appConfig.toolbar?.print?.classList.add("hidden"); |
| 19630 |
appConfig.secondaryToolbar?.printButton.classList.add("hidden"); |
| 19631 |
} |
| 19632 |
if (!this.supportsFullscreen) { |
| 19633 |
appConfig.secondaryToolbar?.presentationModeButton.classList.add("hidden"); |
| 19634 |
} |
| 19635 |
if (this.supportsIntegratedFind) { |
| 19636 |
appConfig.findBar?.toggleButton?.classList.add("hidden"); |
| 19637 |
} |
| 19638 |
if (file) { |
| 19639 |
this.open({ |
| 19640 |
url: file |
| 19641 |
}); |
| 19642 |
} else { |
| 19643 |
this._hideViewBookmark(); |
| 19644 |
} |
| 19645 |
}, |
| 19646 |
get externalServices() { |
| 19647 |
return shadow(this, "externalServices", new ExternalServices()); |
| 19648 |
}, |
| 19649 |
get initialized() { |
| 19650 |
return this._initializedCapability.settled; |
| 19651 |
}, |
| 19652 |
get initializedPromise() { |
| 19653 |
return this._initializedCapability.promise; |
| 19654 |
}, |
| 19655 |
updateZoom(steps, scaleFactor, origin) { |
| 19656 |
if (this.pdfViewer.isInPresentationMode) { |
| 19657 |
return; |
| 19658 |
} |
| 19659 |
this.pdfViewer.updateScale({ |
| 19660 |
drawingDelay: AppOptions.get("defaultZoomDelay"), |
| 19661 |
steps, |
| 19662 |
scaleFactor, |
| 19663 |
origin |
| 19664 |
}); |
| 19665 |
}, |
| 19666 |
zoomIn() { |
| 19667 |
this.updateZoom(1); |
| 19668 |
}, |
| 19669 |
zoomOut() { |
| 19670 |
this.updateZoom(-1); |
| 19671 |
}, |
| 19672 |
zoomReset() { |
| 19673 |
if (this.pdfViewer.isInPresentationMode) { |
| 19674 |
return; |
| 19675 |
} |
| 19676 |
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; |
| 19677 |
}, |
| 19678 |
touchPinchCallback(origin, prevDistance, distance) { |
| 19679 |
if (this.supportsPinchToZoom) { |
| 19680 |
const newScaleFactor = this._accumulateFactor(this.pdfViewer.currentScale, distance / prevDistance, "_touchUnusedFactor"); |
| 19681 |
this.updateZoom(null, newScaleFactor, origin); |
| 19682 |
} else { |
| 19683 |
const PIXELS_PER_LINE_SCALE = 30; |
| 19684 |
const ticks = this._accumulateTicks((distance - prevDistance) / PIXELS_PER_LINE_SCALE, "_touchUnusedTicks"); |
| 19685 |
this.updateZoom(ticks, null, origin); |
| 19686 |
} |
| 19687 |
}, |
| 19688 |
touchPinchEndCallback() { |
| 19689 |
this._touchUnusedTicks = 0; |
| 19690 |
this._touchUnusedFactor = 1; |
| 19691 |
}, |
| 19692 |
get pagesCount() { |
| 19693 |
return this.pdfDocument ? this.pdfDocument.numPages : 0; |
| 19694 |
}, |
| 19695 |
get page() { |
| 19696 |
return this.pdfViewer.currentPageNumber; |
| 19697 |
}, |
| 19698 |
set page(val) { |
| 19699 |
this.pdfViewer.currentPageNumber = val; |
| 19700 |
}, |
| 19701 |
get supportsPrinting() { |
| 19702 |
return shadow(this, "supportsPrinting", AppOptions.get("supportsPrinting") && PDFPrintServiceFactory.supportsPrinting); |
| 19703 |
}, |
| 19704 |
get supportsFullscreen() { |
| 19705 |
return shadow(this, "supportsFullscreen", document.fullscreenEnabled); |
| 19706 |
}, |
| 19707 |
get supportsPinchToZoom() { |
| 19708 |
return shadow(this, "supportsPinchToZoom", AppOptions.get("supportsPinchToZoom")); |
| 19709 |
}, |
| 19710 |
get supportsIntegratedFind() { |
| 19711 |
return shadow(this, "supportsIntegratedFind", AppOptions.get("supportsIntegratedFind")); |
| 19712 |
}, |
| 19713 |
get loadingBar() { |
| 19714 |
const barElement = document.getElementById("loadingBar"); |
| 19715 |
const bar = barElement ? new ProgressBar(barElement) : null; |
| 19716 |
return shadow(this, "loadingBar", bar); |
| 19717 |
}, |
| 19718 |
get supportsMouseWheelZoomCtrlKey() { |
| 19719 |
return shadow(this, "supportsMouseWheelZoomCtrlKey", AppOptions.get("supportsMouseWheelZoomCtrlKey")); |
| 19720 |
}, |
| 19721 |
get supportsMouseWheelZoomMetaKey() { |
| 19722 |
return shadow(this, "supportsMouseWheelZoomMetaKey", AppOptions.get("supportsMouseWheelZoomMetaKey")); |
| 19723 |
}, |
| 19724 |
get supportsCaretBrowsingMode() { |
| 19725 |
return AppOptions.get("supportsCaretBrowsingMode"); |
| 19726 |
}, |
| 19727 |
moveCaret(isUp, select) { |
| 19728 |
this._caretBrowsing ||= new CaretBrowsingMode(this._globalAbortController.signal, this.appConfig.mainContainer, this.appConfig.viewerContainer, this.appConfig.toolbar?.container); |
| 19729 |
this._caretBrowsing.moveCaret(isUp, select); |
| 19730 |
}, |
| 19731 |
setTitleUsingUrl(url = "", downloadUrl = null) { |
| 19732 |
this.url = url; |
| 19733 |
this.baseUrl = updateUrlHash(url, "", true); |
| 19734 |
if (downloadUrl) { |
| 19735 |
this._downloadUrl = downloadUrl === url ? this.baseUrl : updateUrlHash(downloadUrl, "", true); |
| 19736 |
} |
| 19737 |
if (isDataScheme(url)) { |
| 19738 |
this._hideViewBookmark(); |
| 19739 |
} |
| 19740 |
let title = pdfjs_getPdfFilenameFromUrl(url, ""); |
| 19741 |
if (!title) { |
| 19742 |
try { |
| 19743 |
title = decodeURIComponent(getFilenameFromUrl(url)); |
| 19744 |
} catch {} |
| 19745 |
} |
| 19746 |
this.setTitle(title || url); |
| 19747 |
}, |
| 19748 |
setTitle(title = this._title) { |
| 19749 |
this._title = title; |
| 19750 |
if (this.isViewerEmbedded) { |
| 19751 |
return; |
| 19752 |
} |
| 19753 |
const editorIndicator = this._hasAnnotationEditors && !this.pdfRenderingQueue.printing; |
| 19754 |
document.title = `${editorIndicator ? "* " : ""}${title}`; |
| 19755 |
}, |
| 19756 |
get _docFilename() { |
| 19757 |
return this._contentDispositionFilename || pdfjs_getPdfFilenameFromUrl(this.url); |
| 19758 |
}, |
| 19759 |
get _docTitle() { |
| 19760 |
const { |
| 19761 |
documentInfo, |
| 19762 |
metadata |
| 19763 |
} = this; |
| 19764 |
const title = metadata?.get("dc:title"); |
| 19765 |
if (title) { |
| 19766 |
if (title !== "Untitled" && !/[\uFFF0-\uFFFF]/g.test(title)) { |
| 19767 |
return title; |
| 19768 |
} |
| 19769 |
} |
| 19770 |
return documentInfo.Title; |
| 19771 |
}, |
| 19772 |
_hideViewBookmark() { |
| 19773 |
const { |
| 19774 |
secondaryToolbar |
| 19775 |
} = this.appConfig; |
| 19776 |
secondaryToolbar?.viewBookmarkButton.classList.add("hidden"); |
| 19777 |
if (secondaryToolbar?.presentationModeButton.classList.contains("hidden")) { |
| 19778 |
document.getElementById("viewBookmarkSeparator")?.classList.add("hidden"); |
| 19779 |
} |
| 19780 |
}, |
| 19781 |
async close() { |
| 19782 |
this._unblockDocumentLoadEvent(); |
| 19783 |
this._hideViewBookmark(); |
| 19784 |
if (!this.pdfLoadingTask) { |
| 19785 |
return; |
| 19786 |
} |
| 19787 |
if (this.pdfDocument?.annotationStorage.size > 0 && this._annotationStorageModified) { |
| 19788 |
try { |
| 19789 |
await this.save(); |
| 19790 |
} catch {} |
| 19791 |
} |
| 19792 |
const promises = []; |
| 19793 |
promises.push(this.pdfLoadingTask.destroy()); |
| 19794 |
this.pdfLoadingTask = null; |
| 19795 |
if (this.pdfDocument) { |
| 19796 |
this.pdfDocument = null; |
| 19797 |
this.pdfThumbnailViewer?.setDocument(null); |
| 19798 |
this.pdfViewer.setDocument(null); |
| 19799 |
this.pdfLinkService.setDocument(null); |
| 19800 |
this.pdfDocumentProperties?.setDocument(null); |
| 19801 |
} |
| 19802 |
this.pdfLinkService.externalLinkEnabled = true; |
| 19803 |
this.store = null; |
| 19804 |
this.isInitialViewSet = false; |
| 19805 |
this.url = ""; |
| 19806 |
this.baseUrl = ""; |
| 19807 |
this._downloadUrl = ""; |
| 19808 |
this.documentInfo = null; |
| 19809 |
this.metadata = null; |
| 19810 |
this._contentDispositionFilename = null; |
| 19811 |
this._contentLength = null; |
| 19812 |
this._saveInProgress = false; |
| 19813 |
this._hasAnnotationEditors = false; |
| 19814 |
promises.push(this.pdfScriptingManager.destroyPromise, this.passwordPrompt.close()); |
| 19815 |
this.setTitle(); |
| 19816 |
this.pdfSidebar?.reset(); |
| 19817 |
this.pdfOutlineViewer?.reset(); |
| 19818 |
this.pdfAttachmentViewer?.reset(); |
| 19819 |
this.pdfLayerViewer?.reset(); |
| 19820 |
this.pdfHistory?.reset(); |
| 19821 |
this.findBar?.reset(); |
| 19822 |
this.toolbar?.reset(); |
| 19823 |
this.secondaryToolbar?.reset(); |
| 19824 |
this._PDFBug?.cleanup(); |
| 19825 |
await Promise.all(promises); |
| 19826 |
}, |
| 19827 |
async open(args) { |
| 19828 |
if (this.pdfLoadingTask) { |
| 19829 |
await this.close(); |
| 19830 |
} |
| 19831 |
const workerParams = AppOptions.getAll(OptionKind.WORKER); |
| 19832 |
Object.assign(GlobalWorkerOptions, workerParams); |
| 19833 |
if (args.url) { |
| 19834 |
this.setTitleUsingUrl(args.originalUrl || args.url, args.url); |
| 19835 |
} |
| 19836 |
const apiParams = AppOptions.getAll(OptionKind.API); |
| 19837 |
const loadingTask = getDocument({ |
| 19838 |
...apiParams, |
| 19839 |
...args |
| 19840 |
}); |
| 19841 |
this.pdfLoadingTask = loadingTask; |
| 19842 |
loadingTask.onPassword = (updateCallback, reason) => { |
| 19843 |
if (this.isViewerEmbedded) { |
| 19844 |
this._unblockDocumentLoadEvent(); |
| 19845 |
} |
| 19846 |
this.pdfLinkService.externalLinkEnabled = false; |
| 19847 |
this.passwordPrompt.setUpdateCallback(updateCallback, reason); |
| 19848 |
this.passwordPrompt.open(); |
| 19849 |
}; |
| 19850 |
loadingTask.onProgress = ({ |
| 19851 |
loaded, |
| 19852 |
total |
| 19853 |
}) => { |
| 19854 |
this.progress(loaded / total); |
| 19855 |
}; |
| 19856 |
return loadingTask.promise.then(pdfDocument => { |
| 19857 |
this.load(pdfDocument); |
| 19858 |
}, reason => { |
| 19859 |
if (loadingTask !== this.pdfLoadingTask) { |
| 19860 |
return undefined; |
| 19861 |
} |
| 19862 |
let key = "pdfjs-loading-error"; |
| 19863 |
if (reason instanceof InvalidPDFException) { |
| 19864 |
key = "pdfjs-invalid-file-error"; |
| 19865 |
} else if (reason instanceof ResponseException) { |
| 19866 |
key = reason.missing ? "pdfjs-missing-file-error" : "pdfjs-unexpected-response-error"; |
| 19867 |
} |
| 19868 |
return this._documentError(key, { |
| 19869 |
message: reason.message |
| 19870 |
}).then(() => { |
| 19871 |
throw reason; |
| 19872 |
}); |
| 19873 |
}); |
| 19874 |
}, |
| 19875 |
async download() { |
| 19876 |
let data; |
| 19877 |
try { |
| 19878 |
data = await (this.pdfDocument ? this.pdfDocument.getData() : this.pdfLoadingTask.getData()); |
| 19879 |
} catch {} |
| 19880 |
this.downloadManager.download(data, this._downloadUrl, this._docFilename); |
| 19881 |
}, |
| 19882 |
async save() { |
| 19883 |
if (this._saveInProgress) { |
| 19884 |
return; |
| 19885 |
} |
| 19886 |
this._saveInProgress = true; |
| 19887 |
await this.pdfScriptingManager.dispatchWillSave(); |
| 19888 |
try { |
| 19889 |
const data = await this.pdfDocument.saveDocument(); |
| 19890 |
this.downloadManager.download(data, this._downloadUrl, this._docFilename); |
| 19891 |
} catch (reason) { |
| 19892 |
console.error(`Error when saving the document:`, reason); |
| 19893 |
await this.download(); |
| 19894 |
} finally { |
| 19895 |
await this.pdfScriptingManager.dispatchDidSave(); |
| 19896 |
this._saveInProgress = false; |
| 19897 |
} |
| 19898 |
if (this._hasAnnotationEditors) { |
| 19899 |
this.externalServices.reportTelemetry({ |
| 19900 |
type: "editing", |
| 19901 |
data: { |
| 19902 |
type: "save", |
| 19903 |
stats: this.pdfDocument?.annotationStorage.editorStats |
| 19904 |
} |
| 19905 |
}); |
| 19906 |
} |
| 19907 |
}, |
| 19908 |
async downloadOrSave() { |
| 19909 |
const { |
| 19910 |
classList |
| 19911 |
} = this.appConfig.appContainer; |
| 19912 |
classList.add("wait"); |
| 19913 |
await (this.pdfDocument?.annotationStorage.size > 0 ? this.save() : this.download()); |
| 19914 |
classList.remove("wait"); |
| 19915 |
}, |
| 19916 |
async _documentError(key, moreInfo = null) { |
| 19917 |
this._unblockDocumentLoadEvent(); |
| 19918 |
const message = await this._otherError(key || "pdfjs-loading-error", moreInfo); |
| 19919 |
this.eventBus.dispatch("documenterror", { |
| 19920 |
source: this, |
| 19921 |
message, |
| 19922 |
reason: moreInfo?.message ?? null |
| 19923 |
}); |
| 19924 |
}, |
| 19925 |
async _otherError(key, moreInfo = null) { |
| 19926 |
const message = await this.l10n.get(key); |
| 19927 |
const moreInfoText = [`PDF.js v${version || "?"} (build: ${build || "?"})`]; |
| 19928 |
if (moreInfo) { |
| 19929 |
moreInfoText.push(`Message: ${moreInfo.message}`); |
| 19930 |
if (moreInfo.stack) { |
| 19931 |
moreInfoText.push(`Stack: ${moreInfo.stack}`); |
| 19932 |
} else { |
| 19933 |
if (moreInfo.filename) { |
| 19934 |
moreInfoText.push(`File: ${moreInfo.filename}`); |
| 19935 |
} |
| 19936 |
if (moreInfo.lineNumber) { |
| 19937 |
moreInfoText.push(`Line: ${moreInfo.lineNumber}`); |
| 19938 |
} |
| 19939 |
} |
| 19940 |
} |
| 19941 |
console.error(`${message}\n\n${moreInfoText.join("\n")}`); |
| 19942 |
return message; |
| 19943 |
}, |
| 19944 |
progress(level) { |
| 19945 |
const percent = Math.round(level * 100); |
| 19946 |
if (!this.loadingBar || percent <= this.loadingBar.percent) { |
| 19947 |
return; |
| 19948 |
} |
| 19949 |
this.loadingBar.percent = percent; |
| 19950 |
if (this.pdfDocument?.loadingParams.disableAutoFetch ?? AppOptions.get("disableAutoFetch")) { |
| 19951 |
this.loadingBar.setDisableAutoFetch(); |
| 19952 |
} |
| 19953 |
}, |
| 19954 |
load(pdfDocument) { |
| 19955 |
this.pdfDocument = pdfDocument; |
| 19956 |
pdfDocument.getDownloadInfo().then(({ |
| 19957 |
length |
| 19958 |
}) => { |
| 19959 |
this._contentLength = length; |
| 19960 |
this.loadingBar?.hide(); |
| 19961 |
firstPagePromise.then(() => { |
| 19962 |
this.eventBus.dispatch("documentloaded", { |
| 19963 |
source: this |
| 19964 |
}); |
| 19965 |
}); |
| 19966 |
}); |
| 19967 |
const pageLayoutPromise = pdfDocument.getPageLayout().catch(() => {}); |
| 19968 |
const pageModePromise = pdfDocument.getPageMode().catch(() => {}); |
| 19969 |
const openActionPromise = pdfDocument.getOpenAction().catch(() => {}); |
| 19970 |
this.toolbar?.setPagesCount(pdfDocument.numPages, false); |
| 19971 |
this.secondaryToolbar?.setPagesCount(pdfDocument.numPages); |
| 19972 |
this.pdfLinkService.setDocument(pdfDocument); |
| 19973 |
this.pdfDocumentProperties?.setDocument(pdfDocument); |
| 19974 |
const pdfViewer = this.pdfViewer; |
| 19975 |
pdfViewer.setDocument(pdfDocument); |
| 19976 |
const { |
| 19977 |
firstPagePromise, |
| 19978 |
onePageRendered, |
| 19979 |
pagesPromise |
| 19980 |
} = pdfViewer; |
| 19981 |
this.pdfThumbnailViewer?.setDocument(pdfDocument); |
| 19982 |
const storedPromise = (this.store = new ViewHistory(pdfDocument.fingerprints[0])).getMultiple({ |
| 19983 |
page: null, |
| 19984 |
zoom: DEFAULT_SCALE_VALUE, |
| 19985 |
scrollLeft: "0", |
| 19986 |
scrollTop: "0", |
| 19987 |
rotation: null, |
| 19988 |
sidebarView: SidebarView.UNKNOWN, |
| 19989 |
scrollMode: ScrollMode.UNKNOWN, |
| 19990 |
spreadMode: SpreadMode.UNKNOWN |
| 19991 |
}).catch(() => {}); |
| 19992 |
firstPagePromise.then(pdfPage => { |
| 19993 |
this.loadingBar?.setWidth(this.appConfig.viewerContainer); |
| 19994 |
this._initializeAnnotationStorageCallbacks(pdfDocument); |
| 19995 |
Promise.all([animationStarted, storedPromise, pageLayoutPromise, pageModePromise, openActionPromise]).then(async ([timeStamp, stored, pageLayout, pageMode, openAction]) => { |
| 19996 |
const viewOnLoad = AppOptions.get("viewOnLoad"); |
| 19997 |
this._initializePdfHistory({ |
| 19998 |
fingerprint: pdfDocument.fingerprints[0], |
| 19999 |
viewOnLoad, |
| 20000 |
initialDest: openAction?.dest |
| 20001 |
}); |
| 20002 |
const initialBookmark = this.initialBookmark; |
| 20003 |
const zoom = AppOptions.get("defaultZoomValue"); |
| 20004 |
let hash = zoom ? `zoom=${zoom}` : null; |
| 20005 |
let rotation = null; |
| 20006 |
let sidebarView = AppOptions.get("sidebarViewOnLoad"); |
| 20007 |
let scrollMode = AppOptions.get("scrollModeOnLoad"); |
| 20008 |
let spreadMode = AppOptions.get("spreadModeOnLoad"); |
| 20009 |
if (stored?.page && viewOnLoad !== ViewOnLoad.INITIAL) { |
| 20010 |
hash = `page=${stored.page}&zoom=${zoom || stored.zoom},` + `${stored.scrollLeft},${stored.scrollTop}`; |
| 20011 |
rotation = parseInt(stored.rotation, 10); |
| 20012 |
if (sidebarView === SidebarView.UNKNOWN) { |
| 20013 |
sidebarView = stored.sidebarView | 0; |
| 20014 |
} |
| 20015 |
if (scrollMode === ScrollMode.UNKNOWN) { |
| 20016 |
scrollMode = stored.scrollMode | 0; |
| 20017 |
} |
| 20018 |
if (spreadMode === SpreadMode.UNKNOWN) { |
| 20019 |
spreadMode = stored.spreadMode | 0; |
| 20020 |
} |
| 20021 |
} |
| 20022 |
if (pageMode && sidebarView === SidebarView.UNKNOWN) { |
| 20023 |
sidebarView = apiPageModeToSidebarView(pageMode); |
| 20024 |
} |
| 20025 |
if (pageLayout && scrollMode === ScrollMode.UNKNOWN && spreadMode === SpreadMode.UNKNOWN) { |
| 20026 |
const modes = apiPageLayoutToViewerModes(pageLayout); |
| 20027 |
spreadMode = modes.spreadMode; |
| 20028 |
} |
| 20029 |
this.setInitialView(hash, { |
| 20030 |
rotation, |
| 20031 |
sidebarView, |
| 20032 |
scrollMode, |
| 20033 |
spreadMode |
| 20034 |
}); |
| 20035 |
this.eventBus.dispatch("documentinit", { |
| 20036 |
source: this |
| 20037 |
}); |
| 20038 |
if (!this.isViewerEmbedded) { |
| 20039 |
pdfViewer.focus(); |
| 20040 |
} |
| 20041 |
await Promise.race([pagesPromise, new Promise(resolve => { |
| 20042 |
setTimeout(resolve, FORCE_PAGES_LOADED_TIMEOUT); |
| 20043 |
})]); |
| 20044 |
if (!initialBookmark && !hash) { |
| 20045 |
return; |
| 20046 |
} |
| 20047 |
if (pdfViewer.hasEqualPageSizes) { |
| 20048 |
return; |
| 20049 |
} |
| 20050 |
this.initialBookmark = initialBookmark; |
| 20051 |
pdfViewer.currentScaleValue = pdfViewer.currentScaleValue; |
| 20052 |
this.setInitialView(hash); |
| 20053 |
}).catch(() => { |
| 20054 |
this.setInitialView(); |
| 20055 |
}).then(function () { |
| 20056 |
pdfViewer.update(); |
| 20057 |
}); |
| 20058 |
}); |
| 20059 |
pagesPromise.then(() => { |
| 20060 |
this._unblockDocumentLoadEvent(); |
| 20061 |
this._initializeAutoPrint(pdfDocument, openActionPromise); |
| 20062 |
}, reason => { |
| 20063 |
this._documentError("pdfjs-loading-error", { |
| 20064 |
message: reason.message |
| 20065 |
}); |
| 20066 |
}); |
| 20067 |
onePageRendered.then(data => { |
| 20068 |
this.externalServices.reportTelemetry({ |
| 20069 |
type: "pageInfo", |
| 20070 |
timestamp: data.timestamp |
| 20071 |
}); |
| 20072 |
if (this.pdfOutlineViewer) { |
| 20073 |
pdfDocument.getOutline().then(outline => { |
| 20074 |
if (pdfDocument !== this.pdfDocument) { |
| 20075 |
return; |
| 20076 |
} |
| 20077 |
this.pdfOutlineViewer.render({ |
| 20078 |
outline, |
| 20079 |
pdfDocument |
| 20080 |
}); |
| 20081 |
}); |
| 20082 |
} |
| 20083 |
if (this.pdfAttachmentViewer) { |
| 20084 |
pdfDocument.getAttachments().then(attachments => { |
| 20085 |
if (pdfDocument !== this.pdfDocument) { |
| 20086 |
return; |
| 20087 |
} |
| 20088 |
this.pdfAttachmentViewer.render({ |
| 20089 |
attachments |
| 20090 |
}); |
| 20091 |
}); |
| 20092 |
} |
| 20093 |
if (this.pdfLayerViewer) { |
| 20094 |
pdfViewer.optionalContentConfigPromise.then(optionalContentConfig => { |
| 20095 |
if (pdfDocument !== this.pdfDocument) { |
| 20096 |
return; |
| 20097 |
} |
| 20098 |
this.pdfLayerViewer.render({ |
| 20099 |
optionalContentConfig, |
| 20100 |
pdfDocument |
| 20101 |
}); |
| 20102 |
}); |
| 20103 |
} |
| 20104 |
}); |
| 20105 |
this._initializePageLabels(pdfDocument); |
| 20106 |
this._initializeMetadata(pdfDocument); |
| 20107 |
}, |
| 20108 |
async _scriptingDocProperties(pdfDocument) { |
| 20109 |
if (!this.documentInfo) { |
| 20110 |
await new Promise(resolve => { |
| 20111 |
this.eventBus._on("metadataloaded", resolve, { |
| 20112 |
once: true |
| 20113 |
}); |
| 20114 |
}); |
| 20115 |
if (pdfDocument !== this.pdfDocument) { |
| 20116 |
return null; |
| 20117 |
} |
| 20118 |
} |
| 20119 |
if (!this._contentLength) { |
| 20120 |
await new Promise(resolve => { |
| 20121 |
this.eventBus._on("documentloaded", resolve, { |
| 20122 |
once: true |
| 20123 |
}); |
| 20124 |
}); |
| 20125 |
if (pdfDocument !== this.pdfDocument) { |
| 20126 |
return null; |
| 20127 |
} |
| 20128 |
} |
| 20129 |
return { |
| 20130 |
...this.documentInfo, |
| 20131 |
baseURL: this.baseUrl, |
| 20132 |
filesize: this._contentLength, |
| 20133 |
filename: this._docFilename, |
| 20134 |
metadata: this.metadata?.getRaw(), |
| 20135 |
authors: this.metadata?.get("dc:creator"), |
| 20136 |
numPages: this.pagesCount, |
| 20137 |
URL: this.url |
| 20138 |
}; |
| 20139 |
}, |
| 20140 |
async _initializeAutoPrint(pdfDocument, openActionPromise) { |
| 20141 |
const [openAction, jsActions] = await Promise.all([openActionPromise, this.pdfViewer.enableScripting ? null : pdfDocument.getJSActions()]); |
| 20142 |
if (pdfDocument !== this.pdfDocument) { |
| 20143 |
return; |
| 20144 |
} |
| 20145 |
let triggerAutoPrint = openAction?.action === "Print"; |
| 20146 |
if (jsActions) { |
| 20147 |
console.warn("Warning: JavaScript support is not enabled"); |
| 20148 |
for (const name in jsActions) { |
| 20149 |
if (triggerAutoPrint) { |
| 20150 |
break; |
| 20151 |
} |
| 20152 |
switch (name) { |
| 20153 |
case "WillClose": |
| 20154 |
case "WillSave": |
| 20155 |
case "DidSave": |
| 20156 |
case "WillPrint": |
| 20157 |
case "DidPrint": |
| 20158 |
continue; |
| 20159 |
} |
| 20160 |
triggerAutoPrint = jsActions[name].some(js => AutoPrintRegExp.test(js)); |
| 20161 |
} |
| 20162 |
} |
| 20163 |
if (triggerAutoPrint) { |
| 20164 |
this.triggerPrinting(); |
| 20165 |
} |
| 20166 |
}, |
| 20167 |
async _initializeMetadata(pdfDocument) { |
| 20168 |
const { |
| 20169 |
info, |
| 20170 |
metadata, |
| 20171 |
contentDispositionFilename, |
| 20172 |
contentLength |
| 20173 |
} = await pdfDocument.getMetadata(); |
| 20174 |
if (pdfDocument !== this.pdfDocument) { |
| 20175 |
return; |
| 20176 |
} |
| 20177 |
this.documentInfo = info; |
| 20178 |
this.metadata = metadata; |
| 20179 |
this._contentDispositionFilename ??= contentDispositionFilename; |
| 20180 |
this._contentLength ??= contentLength; |
| 20181 |
console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(metadata?.get("pdf:producer") || info.Producer || "-").trim()} / ` + `${(metadata?.get("xmp:creatortool") || info.Creator || "-").trim()}` + `] (PDF.js: ${version || "?"} [${build || "?"}])`); |
| 20182 |
const pdfTitle = this._docTitle; |
| 20183 |
if (pdfTitle) { |
| 20184 |
this.setTitle(`${pdfTitle} - ${this._contentDispositionFilename || this._title}`); |
| 20185 |
} else if (this._contentDispositionFilename) { |
| 20186 |
this.setTitle(this._contentDispositionFilename); |
| 20187 |
} |
| 20188 |
if (info.IsXFAPresent && !info.IsAcroFormPresent && !pdfDocument.isPureXfa) { |
| 20189 |
if (pdfDocument.loadingParams.enableXfa) { |
| 20190 |
console.warn("Warning: XFA Foreground documents are not supported"); |
| 20191 |
} else { |
| 20192 |
console.warn("Warning: XFA support is not enabled"); |
| 20193 |
} |
| 20194 |
} else if ((info.IsAcroFormPresent || info.IsXFAPresent) && !this.pdfViewer.renderForms) { |
| 20195 |
console.warn("Warning: Interactive form support is not enabled"); |
| 20196 |
} |
| 20197 |
if (info.IsSignaturesPresent) { |
| 20198 |
console.warn("Warning: Digital signatures validation is not supported"); |
| 20199 |
} |
| 20200 |
this.eventBus.dispatch("metadataloaded", { |
| 20201 |
source: this |
| 20202 |
}); |
| 20203 |
}, |
| 20204 |
async _initializePageLabels(pdfDocument) { |
| 20205 |
const labels = await pdfDocument.getPageLabels(); |
| 20206 |
if (pdfDocument !== this.pdfDocument) { |
| 20207 |
return; |
| 20208 |
} |
| 20209 |
if (!labels || AppOptions.get("disablePageLabels")) { |
| 20210 |
return; |
| 20211 |
} |
| 20212 |
const numLabels = labels.length; |
| 20213 |
let standardLabels = 0, |
| 20214 |
emptyLabels = 0; |
| 20215 |
for (let i = 0; i < numLabels; i++) { |
| 20216 |
const label = labels[i]; |
| 20217 |
if (label === (i + 1).toString()) { |
| 20218 |
standardLabels++; |
| 20219 |
} else if (label === "") { |
| 20220 |
emptyLabels++; |
| 20221 |
} else { |
| 20222 |
break; |
| 20223 |
} |
| 20224 |
} |
| 20225 |
if (standardLabels >= numLabels || emptyLabels >= numLabels) { |
| 20226 |
return; |
| 20227 |
} |
| 20228 |
const { |
| 20229 |
pdfViewer, |
| 20230 |
pdfThumbnailViewer, |
| 20231 |
toolbar |
| 20232 |
} = this; |
| 20233 |
pdfViewer.setPageLabels(labels); |
| 20234 |
pdfThumbnailViewer?.setPageLabels(labels); |
| 20235 |
toolbar?.setPagesCount(numLabels, true); |
| 20236 |
toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); |
| 20237 |
}, |
| 20238 |
_initializePdfHistory({ |
| 20239 |
fingerprint, |
| 20240 |
viewOnLoad, |
| 20241 |
initialDest = null |
| 20242 |
}) { |
| 20243 |
if (!this.pdfHistory) { |
| 20244 |
return; |
| 20245 |
} |
| 20246 |
this.pdfHistory.initialize({ |
| 20247 |
fingerprint, |
| 20248 |
resetHistory: viewOnLoad === ViewOnLoad.INITIAL, |
| 20249 |
updateUrl: AppOptions.get("historyUpdateUrl") |
| 20250 |
}); |
| 20251 |
if (this.pdfHistory.initialBookmark) { |
| 20252 |
this.initialBookmark = this.pdfHistory.initialBookmark; |
| 20253 |
this.initialRotation = this.pdfHistory.initialRotation; |
| 20254 |
} |
| 20255 |
if (initialDest && !this.initialBookmark && viewOnLoad === ViewOnLoad.UNKNOWN) { |
| 20256 |
this.initialBookmark = JSON.stringify(initialDest); |
| 20257 |
this.pdfHistory.push({ |
| 20258 |
explicitDest: initialDest, |
| 20259 |
pageNumber: null |
| 20260 |
}); |
| 20261 |
} |
| 20262 |
}, |
| 20263 |
_initializeAnnotationStorageCallbacks(pdfDocument) { |
| 20264 |
if (pdfDocument !== this.pdfDocument) { |
| 20265 |
return; |
| 20266 |
} |
| 20267 |
const { |
| 20268 |
annotationStorage |
| 20269 |
} = pdfDocument; |
| 20270 |
annotationStorage.onSetModified = () => { |
| 20271 |
window.addEventListener("beforeunload", beforeUnload); |
| 20272 |
this._annotationStorageModified = true; |
| 20273 |
}; |
| 20274 |
annotationStorage.onResetModified = () => { |
| 20275 |
window.removeEventListener("beforeunload", beforeUnload); |
| 20276 |
delete this._annotationStorageModified; |
| 20277 |
}; |
| 20278 |
annotationStorage.onAnnotationEditor = typeStr => { |
| 20279 |
this._hasAnnotationEditors = !!typeStr; |
| 20280 |
this.setTitle(); |
| 20281 |
}; |
| 20282 |
}, |
| 20283 |
setInitialView(storedHash, { |
| 20284 |
rotation, |
| 20285 |
sidebarView, |
| 20286 |
scrollMode, |
| 20287 |
spreadMode |
| 20288 |
} = {}) { |
| 20289 |
const setRotation = angle => { |
| 20290 |
if (isValidRotation(angle)) { |
| 20291 |
this.pdfViewer.pagesRotation = angle; |
| 20292 |
} |
| 20293 |
}; |
| 20294 |
const setViewerModes = (scroll, spread) => { |
| 20295 |
if (isValidScrollMode(scroll)) { |
| 20296 |
this.pdfViewer.scrollMode = scroll; |
| 20297 |
} |
| 20298 |
if (isValidSpreadMode(spread)) { |
| 20299 |
this.pdfViewer.spreadMode = spread; |
| 20300 |
} |
| 20301 |
}; |
| 20302 |
this.isInitialViewSet = true; |
| 20303 |
this.pdfSidebar?.setInitialView(sidebarView); |
| 20304 |
setViewerModes(scrollMode, spreadMode); |
| 20305 |
if (this.initialBookmark) { |
| 20306 |
setRotation(this.initialRotation); |
| 20307 |
delete this.initialRotation; |
| 20308 |
this.pdfLinkService.setHash(this.initialBookmark); |
| 20309 |
this.initialBookmark = null; |
| 20310 |
} else if (storedHash) { |
| 20311 |
setRotation(rotation); |
| 20312 |
this.pdfLinkService.setHash(storedHash); |
| 20313 |
} |
| 20314 |
this.toolbar?.setPageNumber(this.pdfViewer.currentPageNumber, this.pdfViewer.currentPageLabel); |
| 20315 |
this.secondaryToolbar?.setPageNumber(this.pdfViewer.currentPageNumber); |
| 20316 |
if (!this.pdfViewer.currentScaleValue) { |
| 20317 |
this.pdfViewer.currentScaleValue = DEFAULT_SCALE_VALUE; |
| 20318 |
} |
| 20319 |
}, |
| 20320 |
_cleanup() { |
| 20321 |
if (!this.pdfDocument) { |
| 20322 |
return; |
| 20323 |
} |
| 20324 |
this.pdfViewer.cleanup(); |
| 20325 |
this.pdfThumbnailViewer?.cleanup(); |
| 20326 |
this.pdfDocument.cleanup(AppOptions.get("fontExtraProperties")); |
| 20327 |
}, |
| 20328 |
forceRendering() { |
| 20329 |
this.pdfRenderingQueue.printing = !!this.printService; |
| 20330 |
this.pdfRenderingQueue.isThumbnailViewEnabled = this.pdfSidebar?.visibleView === SidebarView.THUMBS; |
| 20331 |
this.pdfRenderingQueue.renderHighestPriority(); |
| 20332 |
}, |
| 20333 |
beforePrint() { |
| 20334 |
this._printAnnotationStoragePromise = this.pdfScriptingManager.dispatchWillPrint().catch(() => {}).then(() => this.pdfDocument?.annotationStorage.print); |
| 20335 |
if (this.printService) { |
| 20336 |
return; |
| 20337 |
} |
| 20338 |
if (!this.supportsPrinting) { |
| 20339 |
this._otherError("pdfjs-printing-not-supported"); |
| 20340 |
return; |
| 20341 |
} |
| 20342 |
if (!this.pdfViewer.pageViewsReady) { |
| 20343 |
this.l10n.get("pdfjs-printing-not-ready").then(msg => { |
| 20344 |
window.alert(msg); |
| 20345 |
}); |
| 20346 |
return; |
| 20347 |
} |
| 20348 |
this.printService = PDFPrintServiceFactory.createPrintService({ |
| 20349 |
pdfDocument: this.pdfDocument, |
| 20350 |
pagesOverview: this.pdfViewer.getPagesOverview(), |
| 20351 |
printContainer: this.appConfig.printContainer, |
| 20352 |
printResolution: AppOptions.get("printResolution"), |
| 20353 |
printAnnotationStoragePromise: this._printAnnotationStoragePromise |
| 20354 |
}); |
| 20355 |
this.forceRendering(); |
| 20356 |
this.setTitle(); |
| 20357 |
this.printService.layout(); |
| 20358 |
if (this._hasAnnotationEditors) { |
| 20359 |
this.externalServices.reportTelemetry({ |
| 20360 |
type: "editing", |
| 20361 |
data: { |
| 20362 |
type: "print", |
| 20363 |
stats: this.pdfDocument?.annotationStorage.editorStats |
| 20364 |
} |
| 20365 |
}); |
| 20366 |
} |
| 20367 |
}, |
| 20368 |
afterPrint() { |
| 20369 |
if (this._printAnnotationStoragePromise) { |
| 20370 |
this._printAnnotationStoragePromise.then(() => { |
| 20371 |
this.pdfScriptingManager.dispatchDidPrint(); |
| 20372 |
}); |
| 20373 |
this._printAnnotationStoragePromise = null; |
| 20374 |
} |
| 20375 |
if (this.printService) { |
| 20376 |
this.printService.destroy(); |
| 20377 |
this.printService = null; |
| 20378 |
this.pdfDocument?.annotationStorage.resetModified(); |
| 20379 |
} |
| 20380 |
this.forceRendering(); |
| 20381 |
this.setTitle(); |
| 20382 |
}, |
| 20383 |
rotatePages(delta) { |
| 20384 |
this.pdfViewer.pagesRotation += delta; |
| 20385 |
}, |
| 20386 |
requestPresentationMode() { |
| 20387 |
this.pdfPresentationMode?.request(); |
| 20388 |
}, |
| 20389 |
triggerPrinting() { |
| 20390 |
if (this.supportsPrinting) { |
| 20391 |
window.print(); |
| 20392 |
} |
| 20393 |
}, |
| 20394 |
bindEvents() { |
| 20395 |
if (this._eventBusAbortController) { |
| 20396 |
return; |
| 20397 |
} |
| 20398 |
const ac = this._eventBusAbortController = new AbortController(); |
| 20399 |
const opts = { |
| 20400 |
signal: ac.signal |
| 20401 |
}; |
| 20402 |
const { |
| 20403 |
eventBus, |
| 20404 |
externalServices, |
| 20405 |
pdfDocumentProperties, |
| 20406 |
pdfViewer, |
| 20407 |
preferences |
| 20408 |
} = this; |
| 20409 |
eventBus._on("resize", onResize.bind(this), opts); |
| 20410 |
eventBus._on("hashchange", onHashchange.bind(this), opts); |
| 20411 |
eventBus._on("beforeprint", this.beforePrint.bind(this), opts); |
| 20412 |
eventBus._on("afterprint", this.afterPrint.bind(this), opts); |
| 20413 |
eventBus._on("pagerender", onPageRender.bind(this), opts); |
| 20414 |
eventBus._on("pagerendered", onPageRendered.bind(this), opts); |
| 20415 |
eventBus._on("updateviewarea", onUpdateViewarea.bind(this), opts); |
| 20416 |
eventBus._on("pagechanging", onPageChanging.bind(this), opts); |
| 20417 |
eventBus._on("scalechanging", onScaleChanging.bind(this), opts); |
| 20418 |
eventBus._on("rotationchanging", onRotationChanging.bind(this), opts); |
| 20419 |
eventBus._on("sidebarviewchanged", onSidebarViewChanged.bind(this), opts); |
| 20420 |
eventBus._on("pagemode", onPageMode.bind(this), opts); |
| 20421 |
eventBus._on("namedaction", onNamedAction.bind(this), opts); |
| 20422 |
eventBus._on("presentationmodechanged", evt => pdfViewer.presentationModeState = evt.state, opts); |
| 20423 |
eventBus._on("presentationmode", this.requestPresentationMode.bind(this), opts); |
| 20424 |
eventBus._on("switchannotationeditormode", evt => pdfViewer.annotationEditorMode = evt, opts); |
| 20425 |
eventBus._on("print", this.triggerPrinting.bind(this), opts); |
| 20426 |
eventBus._on("download", this.downloadOrSave.bind(this), opts); |
| 20427 |
eventBus._on("firstpage", () => this.page = 1, opts); |
| 20428 |
eventBus._on("lastpage", () => this.page = this.pagesCount, opts); |
| 20429 |
eventBus._on("nextpage", () => pdfViewer.nextPage(), opts); |
| 20430 |
eventBus._on("previouspage", () => pdfViewer.previousPage(), opts); |
| 20431 |
eventBus._on("zoomin", this.zoomIn.bind(this), opts); |
| 20432 |
eventBus._on("zoomout", this.zoomOut.bind(this), opts); |
| 20433 |
eventBus._on("zoomreset", this.zoomReset.bind(this), opts); |
| 20434 |
eventBus._on("pagenumberchanged", onPageNumberChanged.bind(this), opts); |
| 20435 |
eventBus._on("scalechanged", evt => pdfViewer.currentScaleValue = evt.value, opts); |
| 20436 |
eventBus._on("rotatecw", this.rotatePages.bind(this, 90), opts); |
| 20437 |
eventBus._on("rotateccw", this.rotatePages.bind(this, -90), opts); |
| 20438 |
eventBus._on("optionalcontentconfig", evt => pdfViewer.optionalContentConfigPromise = evt.promise, opts); |
| 20439 |
eventBus._on("switchscrollmode", evt => pdfViewer.scrollMode = evt.mode, opts); |
| 20440 |
eventBus._on("scrollmodechanged", onViewerModesChanged.bind(this, "scrollMode"), opts); |
| 20441 |
eventBus._on("switchspreadmode", evt => pdfViewer.spreadMode = evt.mode, opts); |
| 20442 |
eventBus._on("spreadmodechanged", onViewerModesChanged.bind(this, "spreadMode"), opts); |
| 20443 |
eventBus._on("imagealttextsettings", onImageAltTextSettings.bind(this), opts); |
| 20444 |
eventBus._on("documentproperties", () => pdfDocumentProperties?.open(), opts); |
| 20445 |
eventBus._on("findfromurlhash", onFindFromUrlHash.bind(this), opts); |
| 20446 |
eventBus._on("updatefindmatchescount", onUpdateFindMatchesCount.bind(this), opts); |
| 20447 |
eventBus._on("updatefindcontrolstate", onUpdateFindControlState.bind(this), opts); |
| 20448 |
eventBus._on("fileinputchange", onFileInputChange.bind(this), opts); |
| 20449 |
eventBus._on("openfile", onOpenFile.bind(this), opts); |
| 20450 |
}, |
| 20451 |
bindWindowEvents() { |
| 20452 |
if (this._windowAbortController) { |
| 20453 |
return; |
| 20454 |
} |
| 20455 |
this._windowAbortController = new AbortController(); |
| 20456 |
const { |
| 20457 |
eventBus, |
| 20458 |
appConfig: { |
| 20459 |
mainContainer |
| 20460 |
}, |
| 20461 |
pdfViewer, |
| 20462 |
_windowAbortController: { |
| 20463 |
signal |
| 20464 |
} |
| 20465 |
} = this; |
| 20466 |
this._touchManager = new TouchManager({ |
| 20467 |
container: window, |
| 20468 |
isPinchingDisabled: () => pdfViewer.isInPresentationMode, |
| 20469 |
isPinchingStopped: () => this.overlayManager?.active, |
| 20470 |
onPinching: this.touchPinchCallback.bind(this), |
| 20471 |
onPinchEnd: this.touchPinchEndCallback.bind(this), |
| 20472 |
signal |
| 20473 |
}); |
| 20474 |
function addWindowResolutionChange(evt = null) { |
| 20475 |
if (evt) { |
| 20476 |
pdfViewer.refresh(); |
| 20477 |
} |
| 20478 |
const mediaQueryList = window.matchMedia(`(resolution: ${OutputScale.pixelRatio}dppx)`); |
| 20479 |
mediaQueryList.addEventListener("change", addWindowResolutionChange, { |
| 20480 |
once: true, |
| 20481 |
signal |
| 20482 |
}); |
| 20483 |
} |
| 20484 |
addWindowResolutionChange(); |
| 20485 |
window.addEventListener("wheel", onWheel.bind(this), { |
| 20486 |
passive: false, |
| 20487 |
signal |
| 20488 |
}); |
| 20489 |
window.addEventListener("click", onClick.bind(this), { |
| 20490 |
signal |
| 20491 |
}); |
| 20492 |
window.addEventListener("keydown", onKeyDown.bind(this), { |
| 20493 |
signal |
| 20494 |
}); |
| 20495 |
window.addEventListener("keyup", onKeyUp.bind(this), { |
| 20496 |
signal |
| 20497 |
}); |
| 20498 |
window.addEventListener("resize", () => eventBus.dispatch("resize", { |
| 20499 |
source: window |
| 20500 |
}), { |
| 20501 |
signal |
| 20502 |
}); |
| 20503 |
window.addEventListener("hashchange", () => { |
| 20504 |
eventBus.dispatch("hashchange", { |
| 20505 |
source: window, |
| 20506 |
hash: document.location.hash.substring(1) |
| 20507 |
}); |
| 20508 |
}, { |
| 20509 |
signal |
| 20510 |
}); |
| 20511 |
window.addEventListener("beforeprint", () => eventBus.dispatch("beforeprint", { |
| 20512 |
source: window |
| 20513 |
}), { |
| 20514 |
signal |
| 20515 |
}); |
| 20516 |
window.addEventListener("afterprint", () => eventBus.dispatch("afterprint", { |
| 20517 |
source: window |
| 20518 |
}), { |
| 20519 |
signal |
| 20520 |
}); |
| 20521 |
window.addEventListener("updatefromsandbox", evt => { |
| 20522 |
eventBus.dispatch("updatefromsandbox", { |
| 20523 |
source: window, |
| 20524 |
detail: evt.detail |
| 20525 |
}); |
| 20526 |
}, { |
| 20527 |
signal |
| 20528 |
}); |
| 20529 |
if (!("onscrollend" in document.documentElement)) { |
| 20530 |
return; |
| 20531 |
} |
| 20532 |
({ |
| 20533 |
scrollTop: this._lastScrollTop, |
| 20534 |
scrollLeft: this._lastScrollLeft |
| 20535 |
} = mainContainer); |
| 20536 |
const scrollend = () => { |
| 20537 |
({ |
| 20538 |
scrollTop: this._lastScrollTop, |
| 20539 |
scrollLeft: this._lastScrollLeft |
| 20540 |
} = mainContainer); |
| 20541 |
this._isScrolling = false; |
| 20542 |
mainContainer.addEventListener("scroll", scroll, { |
| 20543 |
passive: true, |
| 20544 |
signal |
| 20545 |
}); |
| 20546 |
mainContainer.removeEventListener("scrollend", scrollend); |
| 20547 |
mainContainer.removeEventListener("blur", scrollend); |
| 20548 |
}; |
| 20549 |
const scroll = () => { |
| 20550 |
if (this._isCtrlKeyDown) { |
| 20551 |
return; |
| 20552 |
} |
| 20553 |
if (this._lastScrollTop === mainContainer.scrollTop && this._lastScrollLeft === mainContainer.scrollLeft) { |
| 20554 |
return; |
| 20555 |
} |
| 20556 |
mainContainer.removeEventListener("scroll", scroll); |
| 20557 |
this._isScrolling = true; |
| 20558 |
mainContainer.addEventListener("scrollend", scrollend, { |
| 20559 |
signal |
| 20560 |
}); |
| 20561 |
mainContainer.addEventListener("blur", scrollend, { |
| 20562 |
signal |
| 20563 |
}); |
| 20564 |
}; |
| 20565 |
mainContainer.addEventListener("scroll", scroll, { |
| 20566 |
passive: true, |
| 20567 |
signal |
| 20568 |
}); |
| 20569 |
}, |
| 20570 |
unbindEvents() { |
| 20571 |
this._eventBusAbortController?.abort(); |
| 20572 |
this._eventBusAbortController = null; |
| 20573 |
}, |
| 20574 |
unbindWindowEvents() { |
| 20575 |
this._windowAbortController?.abort(); |
| 20576 |
this._windowAbortController = null; |
| 20577 |
this._touchManager = null; |
| 20578 |
}, |
| 20579 |
async testingClose() { |
| 20580 |
this.unbindEvents(); |
| 20581 |
this.unbindWindowEvents(); |
| 20582 |
this._globalAbortController?.abort(); |
| 20583 |
this._globalAbortController = null; |
| 20584 |
this.findBar?.close(); |
| 20585 |
await Promise.all([this.l10n?.destroy(), this.close()]); |
| 20586 |
}, |
| 20587 |
_accumulateTicks(ticks, prop) { |
| 20588 |
if (this[prop] > 0 && ticks < 0 || this[prop] < 0 && ticks > 0) { |
| 20589 |
this[prop] = 0; |
| 20590 |
} |
| 20591 |
this[prop] += ticks; |
| 20592 |
const wholeTicks = Math.trunc(this[prop]); |
| 20593 |
this[prop] -= wholeTicks; |
| 20594 |
return wholeTicks; |
| 20595 |
}, |
| 20596 |
_accumulateFactor(previousScale, factor, prop) { |
| 20597 |
if (factor === 1) { |
| 20598 |
return 1; |
| 20599 |
} |
| 20600 |
if (this[prop] > 1 && factor < 1 || this[prop] < 1 && factor > 1) { |
| 20601 |
this[prop] = 1; |
| 20602 |
} |
| 20603 |
const newFactor = Math.floor(previousScale * factor * this[prop] * 100) / (100 * previousScale); |
| 20604 |
this[prop] = factor / newFactor; |
| 20605 |
return newFactor; |
| 20606 |
}, |
| 20607 |
_unblockDocumentLoadEvent() { |
| 20608 |
document.blockUnblockOnload?.(false); |
| 20609 |
this._unblockDocumentLoadEvent = () => {}; |
| 20610 |
}, |
| 20611 |
get scriptingReady() { |
| 20612 |
return this.pdfScriptingManager.ready; |
| 20613 |
} |
| 20614 |
}; |
| 20615 |
initCom(PDFViewerApplication); |
| 20616 |
{ |
| 20617 |
PDFPrintServiceFactory.initGlobals(PDFViewerApplication); |
| 20618 |
} |
| 20619 |
{ |
| 20620 |
const HOSTED_VIEWER_ORIGINS = new Set(["null", "http://mozilla.github.io", "https://mozilla.github.io"]); |
| 20621 |
var validateFileURL = function (file) { |
| 20622 |
if (!file) { |
| 20623 |
return; |
| 20624 |
} |
| 20625 |
const viewerOrigin = URL.parse(window.location)?.origin || "null"; |
| 20626 |
if (HOSTED_VIEWER_ORIGINS.has(viewerOrigin)) { |
| 20627 |
return; |
| 20628 |
} |
| 20629 |
const fileOrigin = URL.parse(file, window.location)?.origin; |
| 20630 |
if (fileOrigin === viewerOrigin) { |
| 20631 |
return; |
| 20632 |
} |
| 20633 |
const ex = new Error("file origin does not match viewer's"); |
| 20634 |
PDFViewerApplication._documentError("pdfjs-loading-error", { |
| 20635 |
message: ex.message |
| 20636 |
}); |
| 20637 |
throw ex; |
| 20638 |
}; |
| 20639 |
var onFileInputChange = function (evt) { |
| 20640 |
if (this.pdfViewer?.isInPresentationMode) { |
| 20641 |
return; |
| 20642 |
} |
| 20643 |
const file = evt.fileInput.files[0]; |
| 20644 |
this.open({ |
| 20645 |
url: URL.createObjectURL(file), |
| 20646 |
originalUrl: file.name |
| 20647 |
}); |
| 20648 |
}; |
| 20649 |
var onOpenFile = function (evt) { |
| 20650 |
this._openFileInput?.click(); |
| 20651 |
}; |
| 20652 |
} |
| 20653 |
function onPageRender({ |
| 20654 |
pageNumber |
| 20655 |
}) { |
| 20656 |
if (pageNumber === this.page) { |
| 20657 |
this.toolbar?.updateLoadingIndicatorState(true); |
| 20658 |
} |
| 20659 |
} |
| 20660 |
function onPageRendered({ |
| 20661 |
pageNumber, |
| 20662 |
isDetailView, |
| 20663 |
error |
| 20664 |
}) { |
| 20665 |
if (pageNumber === this.page) { |
| 20666 |
this.toolbar?.updateLoadingIndicatorState(false); |
| 20667 |
} |
| 20668 |
if (!isDetailView && this.pdfSidebar?.visibleView === SidebarView.THUMBS) { |
| 20669 |
const pageView = this.pdfViewer.getPageView(pageNumber - 1); |
| 20670 |
const thumbnailView = this.pdfThumbnailViewer?.getThumbnail(pageNumber - 1); |
| 20671 |
if (pageView) { |
| 20672 |
thumbnailView?.setImage(pageView); |
| 20673 |
} |
| 20674 |
} |
| 20675 |
if (error) { |
| 20676 |
this._otherError("pdfjs-rendering-error", error); |
| 20677 |
} |
| 20678 |
} |
| 20679 |
function onPageMode({ |
| 20680 |
mode |
| 20681 |
}) { |
| 20682 |
let view; |
| 20683 |
switch (mode) { |
| 20684 |
case "thumbs": |
| 20685 |
view = SidebarView.THUMBS; |
| 20686 |
break; |
| 20687 |
case "bookmarks": |
| 20688 |
case "outline": |
| 20689 |
view = SidebarView.OUTLINE; |
| 20690 |
break; |
| 20691 |
case "attachments": |
| 20692 |
view = SidebarView.ATTACHMENTS; |
| 20693 |
break; |
| 20694 |
case "layers": |
| 20695 |
view = SidebarView.LAYERS; |
| 20696 |
break; |
| 20697 |
case "none": |
| 20698 |
view = SidebarView.NONE; |
| 20699 |
break; |
| 20700 |
default: |
| 20701 |
console.error('Invalid "pagemode" hash parameter: ' + mode); |
| 20702 |
return; |
| 20703 |
} |
| 20704 |
this.pdfSidebar?.switchView(view, true); |
| 20705 |
} |
| 20706 |
function onNamedAction(evt) { |
| 20707 |
switch (evt.action) { |
| 20708 |
case "GoToPage": |
| 20709 |
this.appConfig.toolbar?.pageNumber.select(); |
| 20710 |
break; |
| 20711 |
case "Find": |
| 20712 |
if (!this.supportsIntegratedFind) { |
| 20713 |
this.findBar?.toggle(); |
| 20714 |
} |
| 20715 |
break; |
| 20716 |
case "Print": |
| 20717 |
this.triggerPrinting(); |
| 20718 |
break; |
| 20719 |
case "SaveAs": |
| 20720 |
this.downloadOrSave(); |
| 20721 |
break; |
| 20722 |
} |
| 20723 |
} |
| 20724 |
function onSidebarViewChanged({ |
| 20725 |
view |
| 20726 |
}) { |
| 20727 |
this.pdfRenderingQueue.isThumbnailViewEnabled = view === SidebarView.THUMBS; |
| 20728 |
if (this.isInitialViewSet) { |
| 20729 |
this.store?.set("sidebarView", view).catch(() => {}); |
| 20730 |
} |
| 20731 |
} |
| 20732 |
function onUpdateViewarea({ |
| 20733 |
location |
| 20734 |
}) { |
| 20735 |
if (this.isInitialViewSet) { |
| 20736 |
this.store?.setMultiple({ |
| 20737 |
page: location.pageNumber, |
| 20738 |
zoom: location.scale, |
| 20739 |
scrollLeft: location.left, |
| 20740 |
scrollTop: location.top, |
| 20741 |
rotation: location.rotation |
| 20742 |
}).catch(() => {}); |
| 20743 |
} |
| 20744 |
if (this.appConfig.secondaryToolbar) { |
| 20745 |
this.appConfig.secondaryToolbar.viewBookmarkButton.href = this.pdfLinkService.getAnchorUrl(location.pdfOpenParams); |
| 20746 |
} |
| 20747 |
} |
| 20748 |
function onViewerModesChanged(name, evt) { |
| 20749 |
if (this.isInitialViewSet && !this.pdfViewer.isInPresentationMode) { |
| 20750 |
this.store?.set(name, evt.mode).catch(() => {}); |
| 20751 |
} |
| 20752 |
} |
| 20753 |
function onResize() { |
| 20754 |
const { |
| 20755 |
pdfDocument, |
| 20756 |
pdfViewer, |
| 20757 |
pdfRenderingQueue |
| 20758 |
} = this; |
| 20759 |
if (pdfRenderingQueue.printing && window.matchMedia("print").matches) { |
| 20760 |
return; |
| 20761 |
} |
| 20762 |
if (!pdfDocument) { |
| 20763 |
return; |
| 20764 |
} |
| 20765 |
const currentScaleValue = pdfViewer.currentScaleValue; |
| 20766 |
if (currentScaleValue === "auto" || currentScaleValue === "page-fit" || currentScaleValue === "page-width") { |
| 20767 |
pdfViewer.currentScaleValue = currentScaleValue; |
| 20768 |
} |
| 20769 |
pdfViewer.update(); |
| 20770 |
} |
| 20771 |
function onHashchange(evt) { |
| 20772 |
const hash = evt.hash; |
| 20773 |
if (!hash) { |
| 20774 |
return; |
| 20775 |
} |
| 20776 |
if (!this.isInitialViewSet) { |
| 20777 |
this.initialBookmark = hash; |
| 20778 |
} else if (!this.pdfHistory?.popStateInProgress) { |
| 20779 |
this.pdfLinkService.setHash(hash); |
| 20780 |
} |
| 20781 |
} |
| 20782 |
function onPageNumberChanged(evt) { |
| 20783 |
const { |
| 20784 |
pdfViewer |
| 20785 |
} = this; |
| 20786 |
if (evt.value !== "") { |
| 20787 |
this.pdfLinkService.goToPage(evt.value); |
| 20788 |
} |
| 20789 |
if (evt.value !== pdfViewer.currentPageNumber.toString() && evt.value !== pdfViewer.currentPageLabel) { |
| 20790 |
this.toolbar?.setPageNumber(pdfViewer.currentPageNumber, pdfViewer.currentPageLabel); |
| 20791 |
} |
| 20792 |
} |
| 20793 |
function onImageAltTextSettings() { |
| 20794 |
this.imageAltTextSettings?.open({ |
| 20795 |
enableGuessAltText: AppOptions.get("enableGuessAltText"), |
| 20796 |
enableNewAltTextWhenAddingImage: AppOptions.get("enableNewAltTextWhenAddingImage") |
| 20797 |
}); |
| 20798 |
} |
| 20799 |
function onFindFromUrlHash(evt) { |
| 20800 |
this.eventBus.dispatch("find", { |
| 20801 |
source: evt.source, |
| 20802 |
type: "", |
| 20803 |
query: evt.query, |
| 20804 |
caseSensitive: false, |
| 20805 |
entireWord: false, |
| 20806 |
highlightAll: true, |
| 20807 |
findPrevious: false, |
| 20808 |
matchDiacritics: true |
| 20809 |
}); |
| 20810 |
} |
| 20811 |
function onUpdateFindMatchesCount({ |
| 20812 |
matchesCount |
| 20813 |
}) { |
| 20814 |
if (this.supportsIntegratedFind) { |
| 20815 |
this.externalServices.updateFindMatchesCount(matchesCount); |
| 20816 |
} else { |
| 20817 |
this.findBar?.updateResultsCount(matchesCount); |
| 20818 |
} |
| 20819 |
} |
| 20820 |
function onUpdateFindControlState({ |
| 20821 |
state, |
| 20822 |
previous, |
| 20823 |
entireWord, |
| 20824 |
matchesCount, |
| 20825 |
rawQuery |
| 20826 |
}) { |
| 20827 |
if (this.supportsIntegratedFind) { |
| 20828 |
this.externalServices.updateFindControlState({ |
| 20829 |
result: state, |
| 20830 |
findPrevious: previous, |
| 20831 |
entireWord, |
| 20832 |
matchesCount, |
| 20833 |
rawQuery |
| 20834 |
}); |
| 20835 |
} else { |
| 20836 |
this.findBar?.updateUIState(state, previous, matchesCount); |
| 20837 |
} |
| 20838 |
} |
| 20839 |
function onScaleChanging(evt) { |
| 20840 |
this.toolbar?.setPageScale(evt.presetValue, evt.scale); |
| 20841 |
this.pdfViewer.update(); |
| 20842 |
} |
| 20843 |
function onRotationChanging(evt) { |
| 20844 |
if (this.pdfThumbnailViewer) { |
| 20845 |
this.pdfThumbnailViewer.pagesRotation = evt.pagesRotation; |
| 20846 |
} |
| 20847 |
this.forceRendering(); |
| 20848 |
this.pdfViewer.currentPageNumber = evt.pageNumber; |
| 20849 |
} |
| 20850 |
function onPageChanging({ |
| 20851 |
pageNumber, |
| 20852 |
pageLabel |
| 20853 |
}) { |
| 20854 |
this.toolbar?.setPageNumber(pageNumber, pageLabel); |
| 20855 |
this.secondaryToolbar?.setPageNumber(pageNumber); |
| 20856 |
if (this.pdfSidebar?.visibleView === SidebarView.THUMBS) { |
| 20857 |
this.pdfThumbnailViewer?.scrollThumbnailIntoView(pageNumber); |
| 20858 |
} |
| 20859 |
const currentPage = this.pdfViewer.getPageView(pageNumber - 1); |
| 20860 |
this.toolbar?.updateLoadingIndicatorState(currentPage?.renderingState === RenderingStates.RUNNING); |
| 20861 |
} |
| 20862 |
function onWheel(evt) { |
| 20863 |
const { |
| 20864 |
pdfViewer, |
| 20865 |
supportsMouseWheelZoomCtrlKey, |
| 20866 |
supportsMouseWheelZoomMetaKey, |
| 20867 |
supportsPinchToZoom |
| 20868 |
} = this; |
| 20869 |
if (pdfViewer.isInPresentationMode) { |
| 20870 |
return; |
| 20871 |
} |
| 20872 |
const deltaMode = evt.deltaMode; |
| 20873 |
let scaleFactor = Math.exp(-evt.deltaY / 100); |
| 20874 |
const isBuiltInMac = false; |
| 20875 |
const isPinchToZoom = evt.ctrlKey && !this._isCtrlKeyDown && deltaMode === WheelEvent.DOM_DELTA_PIXEL && evt.deltaX === 0 && (Math.abs(scaleFactor - 1) < 0.05 || isBuiltInMac) && evt.deltaZ === 0; |
| 20876 |
const origin = [evt.clientX, evt.clientY]; |
| 20877 |
if (isPinchToZoom || evt.ctrlKey && supportsMouseWheelZoomCtrlKey || evt.metaKey && supportsMouseWheelZoomMetaKey) { |
| 20878 |
evt.preventDefault(); |
| 20879 |
if (this._isScrolling || document.visibilityState === "hidden" || this.overlayManager.active) { |
| 20880 |
return; |
| 20881 |
} |
| 20882 |
if (isPinchToZoom && supportsPinchToZoom) { |
| 20883 |
scaleFactor = this._accumulateFactor(pdfViewer.currentScale, scaleFactor, "_wheelUnusedFactor"); |
| 20884 |
this.updateZoom(null, scaleFactor, origin); |
| 20885 |
} else { |
| 20886 |
const delta = normalizeWheelEventDirection(evt); |
| 20887 |
let ticks = 0; |
| 20888 |
if (deltaMode === WheelEvent.DOM_DELTA_LINE || deltaMode === WheelEvent.DOM_DELTA_PAGE) { |
| 20889 |
ticks = Math.abs(delta) >= 1 ? Math.sign(delta) : this._accumulateTicks(delta, "_wheelUnusedTicks"); |
| 20890 |
} else { |
| 20891 |
const PIXELS_PER_LINE_SCALE = 30; |
| 20892 |
ticks = this._accumulateTicks(delta / PIXELS_PER_LINE_SCALE, "_wheelUnusedTicks"); |
| 20893 |
} |
| 20894 |
this.updateZoom(ticks, null, origin); |
| 20895 |
} |
| 20896 |
} |
| 20897 |
} |
| 20898 |
function closeSecondaryToolbar({ |
| 20899 |
target |
| 20900 |
}) { |
| 20901 |
if (!this.secondaryToolbar?.isOpen) { |
| 20902 |
return; |
| 20903 |
} |
| 20904 |
const { |
| 20905 |
toolbar, |
| 20906 |
secondaryToolbar |
| 20907 |
} = this.appConfig; |
| 20908 |
if (this.pdfViewer.containsElement(target) || toolbar?.container.contains(target) && !secondaryToolbar?.toolbar.contains(target) && !secondaryToolbar?.toggleButton.contains(target)) { |
| 20909 |
this.secondaryToolbar.close(); |
| 20910 |
} |
| 20911 |
} |
| 20912 |
function closeEditorUndoBar(evt) { |
| 20913 |
if (!this.editorUndoBar?.isOpen) { |
| 20914 |
return; |
| 20915 |
} |
| 20916 |
if (this.appConfig.secondaryToolbar?.toolbar.contains(evt.target)) { |
| 20917 |
this.editorUndoBar.hide(); |
| 20918 |
} |
| 20919 |
} |
| 20920 |
function onClick(evt) { |
| 20921 |
closeSecondaryToolbar.call(this, evt); |
| 20922 |
closeEditorUndoBar.call(this, evt); |
| 20923 |
} |
| 20924 |
function onKeyUp(evt) { |
| 20925 |
if (evt.key === "Control") { |
| 20926 |
this._isCtrlKeyDown = false; |
| 20927 |
} |
| 20928 |
} |
| 20929 |
function onKeyDown(evt) { |
| 20930 |
this._isCtrlKeyDown = evt.key === "Control"; |
| 20931 |
if (this.editorUndoBar?.isOpen && evt.keyCode !== 9 && evt.keyCode !== 16 && !((evt.keyCode === 13 || evt.keyCode === 32) && getActiveOrFocusedElement() === this.appConfig.editorUndoBar.undoButton)) { |
| 20932 |
this.editorUndoBar.hide(); |
| 20933 |
} |
| 20934 |
if (this.overlayManager.active) { |
| 20935 |
return; |
| 20936 |
} |
| 20937 |
const { |
| 20938 |
eventBus, |
| 20939 |
pdfViewer |
| 20940 |
} = this; |
| 20941 |
const isViewerInPresentationMode = pdfViewer.isInPresentationMode; |
| 20942 |
let handled = false, |
| 20943 |
ensureViewerFocused = false; |
| 20944 |
const cmd = (evt.ctrlKey ? 1 : 0) | (evt.altKey ? 2 : 0) | (evt.shiftKey ? 4 : 0) | (evt.metaKey ? 8 : 0); |
| 20945 |
if (cmd === 1 || cmd === 8 || cmd === 5 || cmd === 12) { |
| 20946 |
switch (evt.keyCode) { |
| 20947 |
case 70: |
| 20948 |
if (!this.supportsIntegratedFind && !evt.shiftKey) { |
| 20949 |
this.findBar?.open(); |
| 20950 |
handled = true; |
| 20951 |
} |
| 20952 |
break; |
| 20953 |
case 71: |
| 20954 |
if (!this.supportsIntegratedFind) { |
| 20955 |
const { |
| 20956 |
state |
| 20957 |
} = this.findController; |
| 20958 |
if (state) { |
| 20959 |
const newState = { |
| 20960 |
source: window, |
| 20961 |
type: "again", |
| 20962 |
findPrevious: cmd === 5 || cmd === 12 |
| 20963 |
}; |
| 20964 |
eventBus.dispatch("find", { |
| 20965 |
...state, |
| 20966 |
...newState |
| 20967 |
}); |
| 20968 |
} |
| 20969 |
handled = true; |
| 20970 |
} |
| 20971 |
break; |
| 20972 |
case 61: |
| 20973 |
case 107: |
| 20974 |
case 187: |
| 20975 |
case 171: |
| 20976 |
this.zoomIn(); |
| 20977 |
handled = true; |
| 20978 |
break; |
| 20979 |
case 173: |
| 20980 |
case 109: |
| 20981 |
case 189: |
| 20982 |
this.zoomOut(); |
| 20983 |
handled = true; |
| 20984 |
break; |
| 20985 |
case 48: |
| 20986 |
case 96: |
| 20987 |
if (!isViewerInPresentationMode) { |
| 20988 |
setTimeout(() => { |
| 20989 |
this.zoomReset(); |
| 20990 |
}); |
| 20991 |
handled = false; |
| 20992 |
} |
| 20993 |
break; |
| 20994 |
case 38: |
| 20995 |
if (isViewerInPresentationMode || this.page > 1) { |
| 20996 |
this.page = 1; |
| 20997 |
handled = true; |
| 20998 |
ensureViewerFocused = true; |
| 20999 |
} |
| 21000 |
break; |
| 21001 |
case 40: |
| 21002 |
if (isViewerInPresentationMode || this.page < this.pagesCount) { |
| 21003 |
this.page = this.pagesCount; |
| 21004 |
handled = true; |
| 21005 |
ensureViewerFocused = true; |
| 21006 |
} |
| 21007 |
break; |
| 21008 |
} |
| 21009 |
} |
| 21010 |
if (cmd === 1 || cmd === 8) { |
| 21011 |
switch (evt.keyCode) { |
| 21012 |
case 83: |
| 21013 |
eventBus.dispatch("download", { |
| 21014 |
source: window |
| 21015 |
}); |
| 21016 |
handled = true; |
| 21017 |
break; |
| 21018 |
case 79: |
| 21019 |
{ |
| 21020 |
eventBus.dispatch("openfile", { |
| 21021 |
source: window |
| 21022 |
}); |
| 21023 |
handled = true; |
| 21024 |
} |
| 21025 |
break; |
| 21026 |
} |
| 21027 |
} |
| 21028 |
if (cmd === 3 || cmd === 10) { |
| 21029 |
switch (evt.keyCode) { |
| 21030 |
case 80: |
| 21031 |
this.requestPresentationMode(); |
| 21032 |
handled = true; |
| 21033 |
this.externalServices.reportTelemetry({ |
| 21034 |
type: "buttons", |
| 21035 |
data: { |
| 21036 |
id: "presentationModeKeyboard" |
| 21037 |
} |
| 21038 |
}); |
| 21039 |
break; |
| 21040 |
case 71: |
| 21041 |
if (this.appConfig.toolbar) { |
| 21042 |
this.appConfig.toolbar.pageNumber.select(); |
| 21043 |
handled = true; |
| 21044 |
} |
| 21045 |
break; |
| 21046 |
} |
| 21047 |
} |
| 21048 |
if (handled) { |
| 21049 |
if (ensureViewerFocused && !isViewerInPresentationMode) { |
| 21050 |
pdfViewer.focus(); |
| 21051 |
} |
| 21052 |
evt.preventDefault(); |
| 21053 |
return; |
| 21054 |
} |
| 21055 |
const curElement = getActiveOrFocusedElement(); |
| 21056 |
const curElementTagName = curElement?.tagName.toUpperCase(); |
| 21057 |
if (curElementTagName === "INPUT" || curElementTagName === "TEXTAREA" || curElementTagName === "SELECT" || curElementTagName === "BUTTON" && (evt.keyCode === 13 || evt.keyCode === 32) || curElement?.isContentEditable) { |
| 21058 |
if (evt.keyCode !== 27) { |
| 21059 |
return; |
| 21060 |
} |
| 21061 |
} |
| 21062 |
if (cmd === 0) { |
| 21063 |
let turnPage = 0, |
| 21064 |
turnOnlyIfPageFit = false; |
| 21065 |
switch (evt.keyCode) { |
| 21066 |
case 38: |
| 21067 |
if (this.supportsCaretBrowsingMode) { |
| 21068 |
this.moveCaret(true, false); |
| 21069 |
handled = true; |
| 21070 |
break; |
| 21071 |
} |
| 21072 |
case 33: |
| 21073 |
if (pdfViewer.isVerticalScrollbarEnabled) { |
| 21074 |
turnOnlyIfPageFit = true; |
| 21075 |
} |
| 21076 |
turnPage = -1; |
| 21077 |
break; |
| 21078 |
case 8: |
| 21079 |
if (!isViewerInPresentationMode) { |
| 21080 |
turnOnlyIfPageFit = true; |
| 21081 |
} |
| 21082 |
turnPage = -1; |
| 21083 |
break; |
| 21084 |
case 37: |
| 21085 |
if (this.supportsCaretBrowsingMode) { |
| 21086 |
return; |
| 21087 |
} |
| 21088 |
if (pdfViewer.isHorizontalScrollbarEnabled) { |
| 21089 |
turnOnlyIfPageFit = true; |
| 21090 |
} |
| 21091 |
case 75: |
| 21092 |
case 80: |
| 21093 |
turnPage = -1; |
| 21094 |
break; |
| 21095 |
case 27: |
| 21096 |
if (this.secondaryToolbar?.isOpen) { |
| 21097 |
this.secondaryToolbar.close(); |
| 21098 |
handled = true; |
| 21099 |
} |
| 21100 |
if (!this.supportsIntegratedFind && this.findBar?.opened) { |
| 21101 |
this.findBar.close(); |
| 21102 |
handled = true; |
| 21103 |
} |
| 21104 |
break; |
| 21105 |
case 40: |
| 21106 |
if (this.supportsCaretBrowsingMode) { |
| 21107 |
this.moveCaret(false, false); |
| 21108 |
handled = true; |
| 21109 |
break; |
| 21110 |
} |
| 21111 |
case 34: |
| 21112 |
if (pdfViewer.isVerticalScrollbarEnabled) { |
| 21113 |
turnOnlyIfPageFit = true; |
| 21114 |
} |
| 21115 |
turnPage = 1; |
| 21116 |
break; |
| 21117 |
case 13: |
| 21118 |
case 32: |
| 21119 |
if (!isViewerInPresentationMode) { |
| 21120 |
turnOnlyIfPageFit = true; |
| 21121 |
} |
| 21122 |
turnPage = 1; |
| 21123 |
break; |
| 21124 |
case 39: |
| 21125 |
if (this.supportsCaretBrowsingMode) { |
| 21126 |
return; |
| 21127 |
} |
| 21128 |
if (pdfViewer.isHorizontalScrollbarEnabled) { |
| 21129 |
turnOnlyIfPageFit = true; |
| 21130 |
} |
| 21131 |
case 74: |
| 21132 |
case 78: |
| 21133 |
turnPage = 1; |
| 21134 |
break; |
| 21135 |
case 36: |
| 21136 |
if (isViewerInPresentationMode || this.page > 1) { |
| 21137 |
this.page = 1; |
| 21138 |
handled = true; |
| 21139 |
ensureViewerFocused = true; |
| 21140 |
} |
| 21141 |
break; |
| 21142 |
case 35: |
| 21143 |
if (isViewerInPresentationMode || this.page < this.pagesCount) { |
| 21144 |
this.page = this.pagesCount; |
| 21145 |
handled = true; |
| 21146 |
ensureViewerFocused = true; |
| 21147 |
} |
| 21148 |
break; |
| 21149 |
case 83: |
| 21150 |
this.pdfCursorTools?.switchTool(CursorTool.SELECT); |
| 21151 |
break; |
| 21152 |
case 72: |
| 21153 |
this.pdfCursorTools?.switchTool(CursorTool.HAND); |
| 21154 |
break; |
| 21155 |
case 82: |
| 21156 |
this.rotatePages(90); |
| 21157 |
break; |
| 21158 |
case 115: |
| 21159 |
this.pdfSidebar?.toggle(); |
| 21160 |
break; |
| 21161 |
} |
| 21162 |
if (turnPage !== 0 && (!turnOnlyIfPageFit || pdfViewer.currentScaleValue === "page-fit")) { |
| 21163 |
if (turnPage > 0) { |
| 21164 |
pdfViewer.nextPage(); |
| 21165 |
} else { |
| 21166 |
pdfViewer.previousPage(); |
| 21167 |
} |
| 21168 |
handled = true; |
| 21169 |
} |
| 21170 |
} |
| 21171 |
if (cmd === 4) { |
| 21172 |
switch (evt.keyCode) { |
| 21173 |
case 13: |
| 21174 |
case 32: |
| 21175 |
if (!isViewerInPresentationMode && pdfViewer.currentScaleValue !== "page-fit") { |
| 21176 |
break; |
| 21177 |
} |
| 21178 |
pdfViewer.previousPage(); |
| 21179 |
handled = true; |
| 21180 |
break; |
| 21181 |
case 38: |
| 21182 |
this.moveCaret(true, true); |
| 21183 |
handled = true; |
| 21184 |
break; |
| 21185 |
case 40: |
| 21186 |
this.moveCaret(false, true); |
| 21187 |
handled = true; |
| 21188 |
break; |
| 21189 |
case 82: |
| 21190 |
this.rotatePages(-90); |
| 21191 |
break; |
| 21192 |
} |
| 21193 |
} |
| 21194 |
if (!handled && !isViewerInPresentationMode) { |
| 21195 |
if (evt.keyCode >= 33 && evt.keyCode <= 40 || evt.keyCode === 32 && curElementTagName !== "BUTTON") { |
| 21196 |
ensureViewerFocused = true; |
| 21197 |
} |
| 21198 |
} |
| 21199 |
if (ensureViewerFocused && !pdfViewer.containsElement(curElement)) { |
| 21200 |
pdfViewer.focus(); |
| 21201 |
} |
| 21202 |
if (handled) { |
| 21203 |
evt.preventDefault(); |
| 21204 |
} |
| 21205 |
} |
| 21206 |
function beforeUnload(evt) { |
| 21207 |
evt.preventDefault(); |
| 21208 |
evt.returnValue = ""; |
| 21209 |
return false; |
| 21210 |
} |
| 21211 |
|
| 21212 |
;// ./web/viewer.js |
| 21213 |
|
| 21214 |
|
| 21215 |
|
| 21216 |
|
| 21217 |
const AppConstants = { |
| 21218 |
LinkTarget: LinkTarget, |
| 21219 |
RenderingStates: RenderingStates, |
| 21220 |
ScrollMode: ScrollMode, |
| 21221 |
SpreadMode: SpreadMode |
| 21222 |
}; |
| 21223 |
window.PDFViewerApplication = PDFViewerApplication; |
| 21224 |
window.PDFViewerApplicationConstants = AppConstants; |
| 21225 |
window.PDFViewerApplicationOptions = AppOptions; |
| 21226 |
function getViewerConfiguration() { |
| 21227 |
return { |
| 21228 |
appContainer: document.body, |
| 21229 |
principalContainer: document.getElementById("mainContainer"), |
| 21230 |
mainContainer: document.getElementById("viewerContainer"), |
| 21231 |
viewerContainer: document.getElementById("viewer"), |
| 21232 |
toolbar: { |
| 21233 |
container: document.getElementById("toolbarContainer"), |
| 21234 |
numPages: document.getElementById("numPages"), |
| 21235 |
pageNumber: document.getElementById("pageNumber"), |
| 21236 |
scaleSelect: document.getElementById("scaleSelect"), |
| 21237 |
customScaleOption: document.getElementById("customScaleOption"), |
| 21238 |
previous: document.getElementById("previous"), |
| 21239 |
next: document.getElementById("next"), |
| 21240 |
zoomIn: document.getElementById("zoomInButton"), |
| 21241 |
zoomOut: document.getElementById("zoomOutButton"), |
| 21242 |
print: document.getElementById("printButton"), |
| 21243 |
editorFreeTextButton: document.getElementById("editorFreeTextButton"), |
| 21244 |
editorFreeTextParamsToolbar: document.getElementById("editorFreeTextParamsToolbar"), |
| 21245 |
editorHighlightButton: document.getElementById("editorHighlightButton"), |
| 21246 |
editorHighlightParamsToolbar: document.getElementById("editorHighlightParamsToolbar"), |
| 21247 |
editorHighlightColorPicker: document.getElementById("editorHighlightColorPicker"), |
| 21248 |
editorInkButton: document.getElementById("editorInkButton"), |
| 21249 |
editorInkParamsToolbar: document.getElementById("editorInkParamsToolbar"), |
| 21250 |
editorStampButton: document.getElementById("editorStampButton"), |
| 21251 |
editorStampParamsToolbar: document.getElementById("editorStampParamsToolbar"), |
| 21252 |
editorSignatureButton: document.getElementById("editorSignatureButton"), |
| 21253 |
editorSignatureParamsToolbar: document.getElementById("editorSignatureParamsToolbar"), |
| 21254 |
download: document.getElementById("downloadButton") |
| 21255 |
}, |
| 21256 |
secondaryToolbar: { |
| 21257 |
toolbar: document.getElementById("secondaryToolbar"), |
| 21258 |
toggleButton: document.getElementById("secondaryToolbarToggleButton"), |
| 21259 |
presentationModeButton: document.getElementById("presentationMode"), |
| 21260 |
openFileButton: document.getElementById("secondaryOpenFile"), |
| 21261 |
printButton: document.getElementById("secondaryPrint"), |
| 21262 |
downloadButton: document.getElementById("secondaryDownload"), |
| 21263 |
viewBookmarkButton: document.getElementById("viewBookmark"), |
| 21264 |
firstPageButton: document.getElementById("firstPage"), |
| 21265 |
lastPageButton: document.getElementById("lastPage"), |
| 21266 |
pageRotateCwButton: document.getElementById("pageRotateCw"), |
| 21267 |
pageRotateCcwButton: document.getElementById("pageRotateCcw"), |
| 21268 |
cursorSelectToolButton: document.getElementById("cursorSelectTool"), |
| 21269 |
cursorHandToolButton: document.getElementById("cursorHandTool"), |
| 21270 |
scrollPageButton: document.getElementById("scrollPage"), |
| 21271 |
scrollVerticalButton: document.getElementById("scrollVertical"), |
| 21272 |
scrollHorizontalButton: document.getElementById("scrollHorizontal"), |
| 21273 |
scrollWrappedButton: document.getElementById("scrollWrapped"), |
| 21274 |
spreadNoneButton: document.getElementById("spreadNone"), |
| 21275 |
spreadOddButton: document.getElementById("spreadOdd"), |
| 21276 |
spreadEvenButton: document.getElementById("spreadEven"), |
| 21277 |
imageAltTextSettingsButton: document.getElementById("imageAltTextSettings"), |
| 21278 |
imageAltTextSettingsSeparator: document.getElementById("imageAltTextSettingsSeparator"), |
| 21279 |
documentPropertiesButton: document.getElementById("documentProperties") |
| 21280 |
}, |
| 21281 |
sidebar: { |
| 21282 |
outerContainer: document.getElementById("outerContainer"), |
| 21283 |
sidebarContainer: document.getElementById("sidebarContainer"), |
| 21284 |
toggleButton: document.getElementById("sidebarToggleButton"), |
| 21285 |
resizer: document.getElementById("sidebarResizer"), |
| 21286 |
thumbnailButton: document.getElementById("viewThumbnail"), |
| 21287 |
outlineButton: document.getElementById("viewOutline"), |
| 21288 |
attachmentsButton: document.getElementById("viewAttachments"), |
| 21289 |
layersButton: document.getElementById("viewLayers"), |
| 21290 |
thumbnailView: document.getElementById("thumbnailView"), |
| 21291 |
outlineView: document.getElementById("outlineView"), |
| 21292 |
attachmentsView: document.getElementById("attachmentsView"), |
| 21293 |
layersView: document.getElementById("layersView"), |
| 21294 |
currentOutlineItemButton: document.getElementById("currentOutlineItem") |
| 21295 |
}, |
| 21296 |
findBar: { |
| 21297 |
bar: document.getElementById("findbar"), |
| 21298 |
toggleButton: document.getElementById("viewFindButton"), |
| 21299 |
findField: document.getElementById("findInput"), |
| 21300 |
highlightAllCheckbox: document.getElementById("findHighlightAll"), |
| 21301 |
caseSensitiveCheckbox: document.getElementById("findMatchCase"), |
| 21302 |
matchDiacriticsCheckbox: document.getElementById("findMatchDiacritics"), |
| 21303 |
entireWordCheckbox: document.getElementById("findEntireWord"), |
| 21304 |
findMsg: document.getElementById("findMsg"), |
| 21305 |
findResultsCount: document.getElementById("findResultsCount"), |
| 21306 |
findPreviousButton: document.getElementById("findPreviousButton"), |
| 21307 |
findNextButton: document.getElementById("findNextButton") |
| 21308 |
}, |
| 21309 |
passwordOverlay: { |
| 21310 |
dialog: document.getElementById("passwordDialog"), |
| 21311 |
label: document.getElementById("passwordText"), |
| 21312 |
input: document.getElementById("password"), |
| 21313 |
submitButton: document.getElementById("passwordSubmit"), |
| 21314 |
cancelButton: document.getElementById("passwordCancel") |
| 21315 |
}, |
| 21316 |
documentProperties: { |
| 21317 |
dialog: document.getElementById("documentPropertiesDialog"), |
| 21318 |
closeButton: document.getElementById("documentPropertiesClose"), |
| 21319 |
fields: { |
| 21320 |
fileName: document.getElementById("fileNameField"), |
| 21321 |
fileSize: document.getElementById("fileSizeField"), |
| 21322 |
title: document.getElementById("titleField"), |
| 21323 |
author: document.getElementById("authorField"), |
| 21324 |
subject: document.getElementById("subjectField"), |
| 21325 |
keywords: document.getElementById("keywordsField"), |
| 21326 |
creationDate: document.getElementById("creationDateField"), |
| 21327 |
modificationDate: document.getElementById("modificationDateField"), |
| 21328 |
creator: document.getElementById("creatorField"), |
| 21329 |
producer: document.getElementById("producerField"), |
| 21330 |
version: document.getElementById("versionField"), |
| 21331 |
pageCount: document.getElementById("pageCountField"), |
| 21332 |
pageSize: document.getElementById("pageSizeField"), |
| 21333 |
linearized: document.getElementById("linearizedField") |
| 21334 |
} |
| 21335 |
}, |
| 21336 |
altTextDialog: { |
| 21337 |
dialog: document.getElementById("altTextDialog"), |
| 21338 |
optionDescription: document.getElementById("descriptionButton"), |
| 21339 |
optionDecorative: document.getElementById("decorativeButton"), |
| 21340 |
textarea: document.getElementById("descriptionTextarea"), |
| 21341 |
cancelButton: document.getElementById("altTextCancel"), |
| 21342 |
saveButton: document.getElementById("altTextSave") |
| 21343 |
}, |
| 21344 |
newAltTextDialog: { |
| 21345 |
dialog: document.getElementById("newAltTextDialog"), |
| 21346 |
title: document.getElementById("newAltTextTitle"), |
| 21347 |
descriptionContainer: document.getElementById("newAltTextDescriptionContainer"), |
| 21348 |
textarea: document.getElementById("newAltTextDescriptionTextarea"), |
| 21349 |
disclaimer: document.getElementById("newAltTextDisclaimer"), |
| 21350 |
learnMore: document.getElementById("newAltTextLearnMore"), |
| 21351 |
imagePreview: document.getElementById("newAltTextImagePreview"), |
| 21352 |
createAutomatically: document.getElementById("newAltTextCreateAutomatically"), |
| 21353 |
createAutomaticallyButton: document.getElementById("newAltTextCreateAutomaticallyButton"), |
| 21354 |
downloadModel: document.getElementById("newAltTextDownloadModel"), |
| 21355 |
downloadModelDescription: document.getElementById("newAltTextDownloadModelDescription"), |
| 21356 |
error: document.getElementById("newAltTextError"), |
| 21357 |
errorCloseButton: document.getElementById("newAltTextCloseButton"), |
| 21358 |
cancelButton: document.getElementById("newAltTextCancel"), |
| 21359 |
notNowButton: document.getElementById("newAltTextNotNow"), |
| 21360 |
saveButton: document.getElementById("newAltTextSave") |
| 21361 |
}, |
| 21362 |
altTextSettingsDialog: { |
| 21363 |
dialog: document.getElementById("altTextSettingsDialog"), |
| 21364 |
createModelButton: document.getElementById("createModelButton"), |
| 21365 |
aiModelSettings: document.getElementById("aiModelSettings"), |
| 21366 |
learnMore: document.getElementById("altTextSettingsLearnMore"), |
| 21367 |
deleteModelButton: document.getElementById("deleteModelButton"), |
| 21368 |
downloadModelButton: document.getElementById("downloadModelButton"), |
| 21369 |
showAltTextDialogButton: document.getElementById("showAltTextDialogButton"), |
| 21370 |
altTextSettingsCloseButton: document.getElementById("altTextSettingsCloseButton"), |
| 21371 |
closeButton: document.getElementById("altTextSettingsCloseButton") |
| 21372 |
}, |
| 21373 |
addSignatureDialog: { |
| 21374 |
dialog: document.getElementById("addSignatureDialog"), |
| 21375 |
panels: document.getElementById("addSignatureActionContainer"), |
| 21376 |
typeButton: document.getElementById("addSignatureTypeButton"), |
| 21377 |
typeInput: document.getElementById("addSignatureTypeInput"), |
| 21378 |
drawButton: document.getElementById("addSignatureDrawButton"), |
| 21379 |
drawSVG: document.getElementById("addSignatureDraw"), |
| 21380 |
drawPlaceholder: document.getElementById("addSignatureDrawPlaceholder"), |
| 21381 |
drawThickness: document.getElementById("addSignatureDrawThickness"), |
| 21382 |
imageButton: document.getElementById("addSignatureImageButton"), |
| 21383 |
imageSVG: document.getElementById("addSignatureImage"), |
| 21384 |
imagePlaceholder: document.getElementById("addSignatureImagePlaceholder"), |
| 21385 |
imagePicker: document.getElementById("addSignatureFilePicker"), |
| 21386 |
imagePickerLink: document.getElementById("addSignatureImageBrowse"), |
| 21387 |
description: document.getElementById("addSignatureDescription"), |
| 21388 |
clearButton: document.getElementById("clearSignatureButton"), |
| 21389 |
saveContainer: document.getElementById("addSignatureSaveContainer"), |
| 21390 |
saveCheckbox: document.getElementById("addSignatureSaveCheckbox"), |
| 21391 |
errorBar: document.getElementById("addSignatureError"), |
| 21392 |
errorCloseButton: document.getElementById("addSignatureErrorCloseButton"), |
| 21393 |
cancelButton: document.getElementById("addSignatureCancelButton"), |
| 21394 |
addButton: document.getElementById("addSignatureAddButton") |
| 21395 |
}, |
| 21396 |
editSignatureDialog: { |
| 21397 |
dialog: document.getElementById("editSignatureDescriptionDialog"), |
| 21398 |
description: document.getElementById("editSignatureDescription"), |
| 21399 |
editSignatureView: document.getElementById("editSignatureView"), |
| 21400 |
cancelButton: document.getElementById("editSignatureCancelButton"), |
| 21401 |
updateButton: document.getElementById("editSignatureUpdateButton") |
| 21402 |
}, |
| 21403 |
annotationEditorParams: { |
| 21404 |
editorFreeTextFontSize: document.getElementById("editorFreeTextFontSize"), |
| 21405 |
editorFreeTextColor: document.getElementById("editorFreeTextColor"), |
| 21406 |
editorInkColor: document.getElementById("editorInkColor"), |
| 21407 |
editorInkThickness: document.getElementById("editorInkThickness"), |
| 21408 |
editorInkOpacity: document.getElementById("editorInkOpacity"), |
| 21409 |
editorStampAddImage: document.getElementById("editorStampAddImage"), |
| 21410 |
editorSignatureAddSignature: document.getElementById("editorSignatureAddSignature"), |
| 21411 |
editorFreeHighlightThickness: document.getElementById("editorFreeHighlightThickness"), |
| 21412 |
editorHighlightShowAll: document.getElementById("editorHighlightShowAll") |
| 21413 |
}, |
| 21414 |
printContainer: document.getElementById("printContainer"), |
| 21415 |
editorUndoBar: { |
| 21416 |
container: document.getElementById("editorUndoBar"), |
| 21417 |
message: document.getElementById("editorUndoBarMessage"), |
| 21418 |
undoButton: document.getElementById("editorUndoBarUndoButton"), |
| 21419 |
closeButton: document.getElementById("editorUndoBarCloseButton") |
| 21420 |
} |
| 21421 |
}; |
| 21422 |
} |
| 21423 |
function webViewerLoad() { |
| 21424 |
const config = getViewerConfiguration(); |
| 21425 |
const event = new CustomEvent("webviewerloaded", { |
| 21426 |
bubbles: true, |
| 21427 |
cancelable: true, |
| 21428 |
detail: { |
| 21429 |
source: window |
| 21430 |
} |
| 21431 |
}); |
| 21432 |
try { |
| 21433 |
parent.document.dispatchEvent(event); |
| 21434 |
} catch (ex) { |
| 21435 |
console.error("webviewerloaded:", ex); |
| 21436 |
document.dispatchEvent(event); |
| 21437 |
} |
| 21438 |
PDFViewerApplication.run(config); |
| 21439 |
} |
| 21440 |
document.blockUnblockOnload?.(true); |
| 21441 |
if (document.readyState === "interactive" || document.readyState === "complete") { |
| 21442 |
webViewerLoad(); |
| 21443 |
} else { |
| 21444 |
document.addEventListener("DOMContentLoaded", webViewerLoad, true); |
| 21445 |
} |
| 21446 |
|
| 21447 |
export { PDFViewerApplication, AppConstants as PDFViewerApplicationConstants, AppOptions as PDFViewerApplicationOptions }; |
| 21448 |
|
| 21449 |
//# sourceMappingURL=viewer.js.map |