@yudaocode/univer-pdfs 1.6.217 → 1.6.218

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -408,7 +408,9 @@ function createDefaultPdfUnitData(partial) {
408
408
  nativeTextSpansByPage: partial?.editState?.nativeTextSpansByPage ? import_core.Tools.deepClone(partial.editState.nativeTextSpansByPage) : partial?.metadata?.nativeTextSpansByPage ? import_core.Tools.deepClone(partial.metadata.nativeTextSpansByPage) : void 0
409
409
  },
410
410
  ...partial?.layers !== void 0 ? { layers: import_core.Tools.deepClone(partial.layers) } : {},
411
+ ...partial?.bookmarks !== void 0 ? { bookmarks: import_core.Tools.deepClone(partial.bookmarks) } : partial?.metadata?.bookmarks !== void 0 ? { bookmarks: import_core.Tools.deepClone(partial.metadata.bookmarks) } : {},
411
412
  ...partial?.attachments !== void 0 ? { attachments: import_core.Tools.deepClone(partial.attachments) } : {},
413
+ ...partial?.security !== void 0 ? { security: import_core.Tools.deepClone(partial.security) } : partial?.metadata?.security !== void 0 ? { security: import_core.Tools.deepClone(partial.metadata.security) } : {},
412
414
  ...partial?.securityPermissions !== void 0 ? { securityPermissions: import_core.Tools.deepClone(partial.securityPermissions) } : {},
413
415
  ...partial?.signatureEnvelope !== void 0 ? { signatureEnvelope: import_core.Tools.deepClone(partial.signatureEnvelope) } : {},
414
416
  ...partial?.pdfACompliant !== void 0 ? { pdfACompliant: partial.pdfACompliant } : {},
@@ -2711,7 +2713,7 @@ function fromPdfmeTemplate(template, options) {
2711
2713
 
2712
2714
  // src/exporter/pdf-exporter.ts
2713
2715
  var import_core3 = require("@univerjs/core");
2714
- var import_pdf_lib3 = require("pdf-lib");
2716
+ var import_pdf_lib4 = require("pdf-lib");
2715
2717
  var import_qrcode2 = __toESM(require("qrcode"));
2716
2718
 
2717
2719
  // src/exporter/pdf-2d-barcodes.ts
@@ -4891,8 +4893,1003 @@ function stripPdfPageNativeTextInRects(doc, page, stripRects) {
4891
4893
  return matchingOps.length;
4892
4894
  }
4893
4895
 
4894
- // src/exporter/pdf-svg-vector.ts
4896
+ // src/exporter/pdf-security.ts
4895
4897
  var import_pdf_lib2 = require("pdf-lib");
4898
+ var PdfSecurityError = class extends Error {
4899
+ constructor(code, message) {
4900
+ super(message);
4901
+ this.name = "PdfSecurityError";
4902
+ this.code = code;
4903
+ }
4904
+ };
4905
+ var PDF_PASSWORD_PADDING = new Uint8Array([
4906
+ 40,
4907
+ 191,
4908
+ 78,
4909
+ 94,
4910
+ 78,
4911
+ 117,
4912
+ 138,
4913
+ 65,
4914
+ 100,
4915
+ 0,
4916
+ 78,
4917
+ 86,
4918
+ 255,
4919
+ 250,
4920
+ 1,
4921
+ 8,
4922
+ 46,
4923
+ 46,
4924
+ 0,
4925
+ 182,
4926
+ 208,
4927
+ 104,
4928
+ 62,
4929
+ 128,
4930
+ 47,
4931
+ 12,
4932
+ 169,
4933
+ 254,
4934
+ 100,
4935
+ 83,
4936
+ 105,
4937
+ 122
4938
+ ]);
4939
+ var DEFAULT_ALL_PERMISSIONS = Object.freeze({
4940
+ print: true,
4941
+ highResPrint: true,
4942
+ modify: true,
4943
+ copy: true,
4944
+ annotate: true,
4945
+ fillForms: true,
4946
+ assemble: true
4947
+ });
4948
+ var MD5_SHIFTS = [
4949
+ 7,
4950
+ 12,
4951
+ 17,
4952
+ 22,
4953
+ 7,
4954
+ 12,
4955
+ 17,
4956
+ 22,
4957
+ 7,
4958
+ 12,
4959
+ 17,
4960
+ 22,
4961
+ 7,
4962
+ 12,
4963
+ 17,
4964
+ 22,
4965
+ 5,
4966
+ 9,
4967
+ 14,
4968
+ 20,
4969
+ 5,
4970
+ 9,
4971
+ 14,
4972
+ 20,
4973
+ 5,
4974
+ 9,
4975
+ 14,
4976
+ 20,
4977
+ 5,
4978
+ 9,
4979
+ 14,
4980
+ 20,
4981
+ 4,
4982
+ 11,
4983
+ 16,
4984
+ 23,
4985
+ 4,
4986
+ 11,
4987
+ 16,
4988
+ 23,
4989
+ 4,
4990
+ 11,
4991
+ 16,
4992
+ 23,
4993
+ 4,
4994
+ 11,
4995
+ 16,
4996
+ 23,
4997
+ 6,
4998
+ 10,
4999
+ 15,
5000
+ 21,
5001
+ 6,
5002
+ 10,
5003
+ 15,
5004
+ 21,
5005
+ 6,
5006
+ 10,
5007
+ 15,
5008
+ 21,
5009
+ 6,
5010
+ 10,
5011
+ 15,
5012
+ 21
5013
+ ];
5014
+ var MD5_K = (() => {
5015
+ const table = new Uint32Array(64);
5016
+ for (let i = 0; i < 64; i++) {
5017
+ table[i] = Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0;
5018
+ }
5019
+ return table;
5020
+ })();
5021
+ function rotl32(x, n) {
5022
+ return (x << n | x >>> 32 - n) >>> 0;
5023
+ }
5024
+ function md5Bytes(data) {
5025
+ const msgLen = data.byteLength;
5026
+ const rem = (msgLen + 9) % 64;
5027
+ const padZeroes = rem === 0 ? 0 : 64 - rem;
5028
+ const totalLen = msgLen + 9 + padZeroes;
5029
+ const buf = new Uint8Array(totalLen);
5030
+ buf.set(data, 0);
5031
+ buf[msgLen] = 128;
5032
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
5033
+ const bitLenLow = msgLen * 8 >>> 0;
5034
+ const bitLenHigh = Math.floor(msgLen * 8 / 4294967296) >>> 0;
5035
+ view.setUint32(totalLen - 8, bitLenLow, true);
5036
+ view.setUint32(totalLen - 4, bitLenHigh, true);
5037
+ let a0 = 1732584193;
5038
+ let b0 = 4023233417;
5039
+ let c0 = 2562383102;
5040
+ let d0 = 271733878;
5041
+ const M = new Uint32Array(16);
5042
+ for (let offset = 0; offset < totalLen; offset += 64) {
5043
+ for (let j = 0; j < 16; j++) {
5044
+ M[j] = view.getUint32(offset + j * 4, true);
5045
+ }
5046
+ let A = a0;
5047
+ let B = b0;
5048
+ let C = c0;
5049
+ let D = d0;
5050
+ for (let i = 0; i < 64; i++) {
5051
+ let F;
5052
+ let g;
5053
+ if (i < 16) {
5054
+ F = B & C | ~B & D;
5055
+ g = i;
5056
+ } else if (i < 32) {
5057
+ F = D & B | ~D & C;
5058
+ g = (5 * i + 1) % 16;
5059
+ } else if (i < 48) {
5060
+ F = B ^ C ^ D;
5061
+ g = (3 * i + 5) % 16;
5062
+ } else {
5063
+ F = C ^ (B | ~D);
5064
+ g = 7 * i % 16;
5065
+ }
5066
+ const sum = A + F + MD5_K[i] + M[g] >>> 0;
5067
+ A = D;
5068
+ D = C;
5069
+ C = B;
5070
+ B = B + rotl32(sum, MD5_SHIFTS[i]) >>> 0;
5071
+ }
5072
+ a0 = a0 + A >>> 0;
5073
+ b0 = b0 + B >>> 0;
5074
+ c0 = c0 + C >>> 0;
5075
+ d0 = d0 + D >>> 0;
5076
+ }
5077
+ const out = new Uint8Array(16);
5078
+ const outView = new DataView(out.buffer);
5079
+ outView.setUint32(0, a0, true);
5080
+ outView.setUint32(4, b0, true);
5081
+ outView.setUint32(8, c0, true);
5082
+ outView.setUint32(12, d0, true);
5083
+ return out;
5084
+ }
5085
+ function rc4Bytes(key, data) {
5086
+ const keyLen = key.byteLength;
5087
+ if (keyLen === 0) return data.slice();
5088
+ const S = new Uint8Array(256);
5089
+ for (let i2 = 0; i2 < 256; i2++) {
5090
+ S[i2] = i2;
5091
+ }
5092
+ let j = 0;
5093
+ for (let i2 = 0; i2 < 256; i2++) {
5094
+ j = j + S[i2] + key[i2 % keyLen] & 255;
5095
+ const tmp = S[i2];
5096
+ S[i2] = S[j];
5097
+ S[j] = tmp;
5098
+ }
5099
+ const out = new Uint8Array(data.byteLength);
5100
+ let i = 0;
5101
+ j = 0;
5102
+ for (let k = 0; k < data.byteLength; k++) {
5103
+ i = i + 1 & 255;
5104
+ j = j + S[i] & 255;
5105
+ const tmp = S[i];
5106
+ S[i] = S[j];
5107
+ S[j] = tmp;
5108
+ out[k] = data[k] ^ S[S[i] + S[j] & 255];
5109
+ }
5110
+ return out;
5111
+ }
5112
+ function bytesToHex(bytes) {
5113
+ let hex = "";
5114
+ for (let i = 0; i < bytes.byteLength; i++) {
5115
+ hex += bytes[i].toString(16).padStart(2, "0").toUpperCase();
5116
+ }
5117
+ return hex;
5118
+ }
5119
+ function hexToBytes(hexRaw) {
5120
+ const cleaned = hexRaw.replace(/\s+/g, "");
5121
+ const padded = cleaned.length % 2 === 1 ? `${cleaned}0` : cleaned;
5122
+ const out = new Uint8Array(padded.length / 2);
5123
+ for (let i = 0; i < out.byteLength; i++) {
5124
+ out[i] = parseInt(padded.slice(i * 2, i * 2 + 2), 16) || 0;
5125
+ }
5126
+ return out;
5127
+ }
5128
+ function encodePasswordToBytes(password) {
5129
+ if (!password) return new Uint8Array(0);
5130
+ let hasHighCodePoint = false;
5131
+ for (let i = 0; i < password.length; i++) {
5132
+ if (password.charCodeAt(i) > 255) {
5133
+ hasHighCodePoint = true;
5134
+ break;
5135
+ }
5136
+ }
5137
+ if (hasHighCodePoint) {
5138
+ return new TextEncoder().encode(password);
5139
+ }
5140
+ const out = new Uint8Array(password.length);
5141
+ for (let i = 0; i < password.length; i++) {
5142
+ out[i] = password.charCodeAt(i) & 255;
5143
+ }
5144
+ return out;
5145
+ }
5146
+ function padPdfPassword(password) {
5147
+ const raw = password instanceof Uint8Array ? password : encodePasswordToBytes(password);
5148
+ const out = new Uint8Array(32);
5149
+ const copyLen = Math.min(32, raw.byteLength);
5150
+ out.set(raw.subarray(0, copyLen), 0);
5151
+ if (copyLen < 32) {
5152
+ out.set(PDF_PASSWORD_PADDING.subarray(0, 32 - copyLen), copyLen);
5153
+ }
5154
+ return out;
5155
+ }
5156
+ function encodePdfPermissionFlags(permissions, revision = 3) {
5157
+ const allowPrint = permissions?.print !== false;
5158
+ const allowModify = permissions?.modify !== false;
5159
+ const allowCopy = permissions?.copy !== false;
5160
+ const allowAnnotate = permissions?.annotate !== false;
5161
+ const allowFillForms = permissions?.fillForms !== false;
5162
+ const allowAssemble = permissions?.assemble !== false;
5163
+ const allowHighResPrint = permissions?.highResPrint !== void 0 ? Boolean(permissions.highResPrint) : allowPrint;
5164
+ let mask = 4294963392 | 1 << 9;
5165
+ if (allowPrint) mask |= 1 << 2;
5166
+ if (allowModify) mask |= 1 << 3;
5167
+ if (allowCopy) mask |= 1 << 4;
5168
+ if (allowAnnotate) mask |= 1 << 5;
5169
+ if (revision >= 3) {
5170
+ if (allowFillForms) mask |= 1 << 8;
5171
+ if (allowAssemble) mask |= 1 << 10;
5172
+ if (allowHighResPrint && allowPrint) mask |= 1 << 11;
5173
+ } else {
5174
+ mask |= 1 << 8 | 1 << 10 | 1 << 11;
5175
+ }
5176
+ return mask | 0;
5177
+ }
5178
+ function decodePdfPermissionFlags(pMask, revision = 3) {
5179
+ const print = (pMask & 1 << 2) !== 0;
5180
+ const modify = (pMask & 1 << 3) !== 0;
5181
+ const copy = (pMask & 1 << 4) !== 0;
5182
+ const annotate = (pMask & 1 << 5) !== 0;
5183
+ const fillForms = revision >= 3 ? (pMask & 1 << 8) !== 0 : annotate;
5184
+ const assemble = revision >= 3 ? (pMask & 1 << 10) !== 0 : modify;
5185
+ const highResPrint = revision >= 3 ? print && (pMask & 1 << 11) !== 0 : print;
5186
+ return {
5187
+ print,
5188
+ highResPrint,
5189
+ modify,
5190
+ copy,
5191
+ annotate,
5192
+ fillForms,
5193
+ assemble
5194
+ };
5195
+ }
5196
+ function isPdfSecurityActive(security) {
5197
+ if (!security || security.enabled === false) return false;
5198
+ if (security.enabled === true) return true;
5199
+ if (security.userPassword && security.userPassword.length > 0) return true;
5200
+ if (security.ownerPassword && security.ownerPassword.length > 0) return true;
5201
+ if (security.permissions && Object.keys(security.permissions).length > 0) return true;
5202
+ return false;
5203
+ }
5204
+ function computeOwnerPasswordValue(userPassword, ownerPassword, revision, keyLengthBits) {
5205
+ const effectiveOwner = ownerPassword || userPassword || "";
5206
+ const ownerPad = padPdfPassword(effectiveOwner);
5207
+ let hash = md5Bytes(ownerPad);
5208
+ if (revision >= 3) {
5209
+ for (let i = 0; i < 50; i++) {
5210
+ hash = md5Bytes(hash);
5211
+ }
5212
+ }
5213
+ const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
5214
+ const userPad = padPdfPassword(userPassword);
5215
+ let encrypted = rc4Bytes(hash.subarray(0, keyByteLen), userPad);
5216
+ if (revision >= 3) {
5217
+ const derivedKey = new Uint8Array(keyByteLen);
5218
+ for (let iter = 1; iter <= 19; iter++) {
5219
+ for (let k = 0; k < keyByteLen; k++) {
5220
+ derivedKey[k] = hash[k] ^ iter;
5221
+ }
5222
+ encrypted = rc4Bytes(derivedKey, encrypted);
5223
+ }
5224
+ }
5225
+ return encrypted;
5226
+ }
5227
+ function computeFileEncryptionKeyFromPadded(paddedUserPassword, oValue, pFlagsSigned, fileId, revision, keyLengthBits) {
5228
+ const buf = new Uint8Array(32 + oValue.byteLength + 4 + fileId.byteLength);
5229
+ let offset = 0;
5230
+ buf.set(paddedUserPassword.subarray(0, 32), offset);
5231
+ offset += 32;
5232
+ buf.set(oValue, offset);
5233
+ offset += oValue.byteLength;
5234
+ buf[offset++] = pFlagsSigned & 255;
5235
+ buf[offset++] = pFlagsSigned >>> 8 & 255;
5236
+ buf[offset++] = pFlagsSigned >>> 16 & 255;
5237
+ buf[offset++] = pFlagsSigned >>> 24 & 255;
5238
+ buf.set(fileId, offset);
5239
+ let hash = md5Bytes(buf);
5240
+ const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
5241
+ if (revision >= 3) {
5242
+ for (let i = 0; i < 50; i++) {
5243
+ hash = md5Bytes(hash.subarray(0, keyByteLen));
5244
+ }
5245
+ }
5246
+ return hash.subarray(0, keyByteLen);
5247
+ }
5248
+ function computeUserPasswordValue(encryptionKey, fileId, revision) {
5249
+ if (revision === 2) {
5250
+ return rc4Bytes(encryptionKey, PDF_PASSWORD_PADDING);
5251
+ }
5252
+ const hashInput = new Uint8Array(32 + fileId.byteLength);
5253
+ hashInput.set(PDF_PASSWORD_PADDING, 0);
5254
+ hashInput.set(fileId, 32);
5255
+ let check = rc4Bytes(encryptionKey, md5Bytes(hashInput));
5256
+ const keyLen = encryptionKey.byteLength;
5257
+ const derivedKey = new Uint8Array(keyLen);
5258
+ for (let iter = 1; iter <= 19; iter++) {
5259
+ for (let k = 0; k < keyLen; k++) {
5260
+ derivedKey[k] = encryptionKey[k] ^ iter;
5261
+ }
5262
+ check = rc4Bytes(derivedKey, check);
5263
+ }
5264
+ const out = new Uint8Array(32);
5265
+ out.set(check.subarray(0, 16), 0);
5266
+ out.set(PDF_PASSWORD_PADDING.subarray(0, 16), 16);
5267
+ return out;
5268
+ }
5269
+ function authenticatePaddedUserPassword(paddedPassword, oValue, uValue, pFlagsSigned, fileId, revision, keyLengthBits) {
5270
+ const candidateKey = computeFileEncryptionKeyFromPadded(
5271
+ paddedPassword,
5272
+ oValue,
5273
+ pFlagsSigned,
5274
+ fileId,
5275
+ revision,
5276
+ keyLengthBits
5277
+ );
5278
+ const expectedU = computeUserPasswordValue(candidateKey, fileId, revision);
5279
+ const compareLen = revision >= 3 ? 16 : 32;
5280
+ if (uValue.byteLength < compareLen) return null;
5281
+ let diff = 0;
5282
+ for (let i = 0; i < compareLen; i++) {
5283
+ diff |= expectedU[i] ^ uValue[i];
5284
+ }
5285
+ return diff === 0 ? candidateKey : null;
5286
+ }
5287
+ function authenticateOwnerPassword(ownerPassword, oValue, uValue, pFlagsSigned, fileId, revision, keyLengthBits) {
5288
+ const ownerPad = padPdfPassword(ownerPassword);
5289
+ let hash = md5Bytes(ownerPad);
5290
+ if (revision >= 3) {
5291
+ for (let i = 0; i < 50; i++) {
5292
+ hash = md5Bytes(hash);
5293
+ }
5294
+ }
5295
+ const keyByteLen = revision >= 3 ? Math.max(5, Math.min(16, keyLengthBits >>> 3)) : 5;
5296
+ let recoveredUserPad;
5297
+ if (revision >= 3) {
5298
+ recoveredUserPad = oValue.slice(0, 32);
5299
+ const derivedKey = new Uint8Array(keyByteLen);
5300
+ for (let iter = 19; iter >= 0; iter--) {
5301
+ for (let k = 0; k < keyByteLen; k++) {
5302
+ derivedKey[k] = hash[k] ^ iter;
5303
+ }
5304
+ recoveredUserPad = rc4Bytes(derivedKey, recoveredUserPad);
5305
+ }
5306
+ } else {
5307
+ recoveredUserPad = rc4Bytes(hash.subarray(0, 5), oValue.subarray(0, 32));
5308
+ }
5309
+ return authenticatePaddedUserPassword(
5310
+ recoveredUserPad,
5311
+ oValue,
5312
+ uValue,
5313
+ pFlagsSigned,
5314
+ fileId,
5315
+ revision,
5316
+ keyLengthBits
5317
+ );
5318
+ }
5319
+ function buildObjectEncryptionKey(encryptionKey, objectNumber, generationNumber) {
5320
+ const n = encryptionKey.byteLength;
5321
+ const buf = new Uint8Array(n + 5);
5322
+ buf.set(encryptionKey, 0);
5323
+ buf[n] = objectNumber & 255;
5324
+ buf[n + 1] = objectNumber >>> 8 & 255;
5325
+ buf[n + 2] = objectNumber >>> 16 & 255;
5326
+ buf[n + 3] = generationNumber & 255;
5327
+ buf[n + 4] = generationNumber >>> 8 & 255;
5328
+ const digest = md5Bytes(buf);
5329
+ return digest.subarray(0, Math.min(n + 5, 16));
5330
+ }
5331
+ function decodePdfLiteralBodyBytes(body) {
5332
+ const bytes = [];
5333
+ for (let i = 0; i < body.length; i++) {
5334
+ const ch = body.charCodeAt(i) & 255;
5335
+ if (ch !== 92) {
5336
+ bytes.push(ch);
5337
+ continue;
5338
+ }
5339
+ if (i + 1 >= body.length) break;
5340
+ const next = body.charCodeAt(++i) & 255;
5341
+ if (next === 13) {
5342
+ if (i + 1 < body.length && (body.charCodeAt(i + 1) & 255) === 10) i++;
5343
+ } else if (next === 10) {
5344
+ } else if (next === 110) {
5345
+ bytes.push(10);
5346
+ } else if (next === 114) {
5347
+ bytes.push(13);
5348
+ } else if (next === 116) {
5349
+ bytes.push(9);
5350
+ } else if (next === 98) {
5351
+ bytes.push(8);
5352
+ } else if (next === 102) {
5353
+ bytes.push(12);
5354
+ } else if (next >= 48 && next <= 55) {
5355
+ let oct = String.fromCharCode(next);
5356
+ for (let k = 0; k < 2 && i + 1 < body.length; k++) {
5357
+ const peek = body.charCodeAt(i + 1) & 255;
5358
+ if (peek >= 48 && peek <= 55) {
5359
+ oct += String.fromCharCode(peek);
5360
+ i++;
5361
+ } else {
5362
+ break;
5363
+ }
5364
+ }
5365
+ bytes.push(parseInt(oct, 8) & 255);
5366
+ } else {
5367
+ bytes.push(next);
5368
+ }
5369
+ }
5370
+ return new Uint8Array(bytes);
5371
+ }
5372
+ function extractPdfStringRawBytes(strObj) {
5373
+ if (strObj instanceof import_pdf_lib2.PDFHexString) {
5374
+ return strObj.asBytes();
5375
+ }
5376
+ const serialized = strObj.asString();
5377
+ const inner = serialized.startsWith("(") && serialized.endsWith(")") ? serialized.slice(1, -1) : serialized;
5378
+ return decodePdfLiteralBodyBytes(inner);
5379
+ }
5380
+ function isSignatureDict(dict) {
5381
+ const typeVal = dict.get(import_pdf_lib2.PDFName.of("Type"));
5382
+ if (typeVal instanceof import_pdf_lib2.PDFName && typeVal.asString() === "/Sig") return true;
5383
+ const ftVal = dict.get(import_pdf_lib2.PDFName.of("FT"));
5384
+ if (ftVal instanceof import_pdf_lib2.PDFName && ftVal.asString() === "/Sig") return true;
5385
+ return false;
5386
+ }
5387
+ function transformPdfObjectStringsWithRc4(obj, objKey) {
5388
+ if (obj instanceof import_pdf_lib2.PDFHexString || obj instanceof import_pdf_lib2.PDFString) {
5389
+ const raw = extractPdfStringRawBytes(obj);
5390
+ const transformed = rc4Bytes(objKey, raw);
5391
+ return import_pdf_lib2.PDFHexString.of(bytesToHex(transformed));
5392
+ }
5393
+ if (obj instanceof import_pdf_lib2.PDFArray) {
5394
+ for (let i = 0; i < obj.size(); i++) {
5395
+ const item = obj.get(i);
5396
+ const next = transformPdfObjectStringsWithRc4(item, objKey);
5397
+ if (next !== item) {
5398
+ obj.set(i, next);
5399
+ }
5400
+ }
5401
+ return obj;
5402
+ }
5403
+ if (obj instanceof import_pdf_lib2.PDFDict) {
5404
+ const isSig = isSignatureDict(obj);
5405
+ for (const [key, val] of obj.entries()) {
5406
+ if (isSig && key.asString() === "/Contents") {
5407
+ continue;
5408
+ }
5409
+ const next = transformPdfObjectStringsWithRc4(val, objKey);
5410
+ if (next !== val) {
5411
+ obj.set(key, next);
5412
+ }
5413
+ }
5414
+ return obj;
5415
+ }
5416
+ return obj;
5417
+ }
5418
+ function extractOrCreateDocumentFileId(pdfDoc) {
5419
+ const existingId = pdfDoc.context.trailerInfo.ID;
5420
+ if (existingId) {
5421
+ const idArr = existingId instanceof import_pdf_lib2.PDFArray ? existingId : pdfDoc.context.lookupMaybe(existingId, import_pdf_lib2.PDFArray);
5422
+ if (idArr && idArr.size() > 0) {
5423
+ const first = idArr.get(0);
5424
+ if (first instanceof import_pdf_lib2.PDFHexString || first instanceof import_pdf_lib2.PDFString) {
5425
+ const bytes = extractPdfStringRawBytes(first);
5426
+ if (bytes.byteLength > 0) {
5427
+ const hex = bytesToHex(bytes);
5428
+ pdfDoc.context.trailerInfo.ID = pdfDoc.context.obj([
5429
+ import_pdf_lib2.PDFHexString.of(hex),
5430
+ import_pdf_lib2.PDFHexString.of(hex)
5431
+ ]);
5432
+ return bytes;
5433
+ }
5434
+ }
5435
+ }
5436
+ }
5437
+ const seedBytes = new Uint8Array(32);
5438
+ if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function") {
5439
+ globalThis.crypto.getRandomValues(seedBytes);
5440
+ } else {
5441
+ const fallbackText = `univer-pdf-${Date.now()}-${Math.random()}-${pdfDoc.getPageCount()}`;
5442
+ const enc = new TextEncoder().encode(fallbackText);
5443
+ seedBytes.set(enc.subarray(0, Math.min(32, enc.byteLength)));
5444
+ }
5445
+ const fileId = md5Bytes(seedBytes);
5446
+ const idHex = bytesToHex(fileId);
5447
+ pdfDoc.context.trailerInfo.ID = pdfDoc.context.obj([
5448
+ import_pdf_lib2.PDFHexString.of(idHex),
5449
+ import_pdf_lib2.PDFHexString.of(idHex)
5450
+ ]);
5451
+ return fileId;
5452
+ }
5453
+ async function applyPdfSecurityToDocument(pdfDoc, security) {
5454
+ if (security.enabled === false) return;
5455
+ await pdfDoc.flush();
5456
+ const keyLength = security.keyLength === 40 ? 40 : 128;
5457
+ const version = keyLength === 40 ? 1 : 2;
5458
+ const revision = keyLength === 40 ? 2 : 3;
5459
+ const userPassword = security.userPassword ?? "";
5460
+ const ownerPassword = security.ownerPassword && security.ownerPassword.length > 0 ? security.ownerPassword : userPassword.length > 0 ? userPassword : "univer-pdf-owner-guard";
5461
+ const fileId = extractOrCreateDocumentFileId(pdfDoc);
5462
+ const pSigned = encodePdfPermissionFlags(security.permissions, revision);
5463
+ const oBytes = computeOwnerPasswordValue(userPassword, ownerPassword, revision, keyLength);
5464
+ const encryptionKey = computeFileEncryptionKeyFromPadded(
5465
+ padPdfPassword(userPassword),
5466
+ oBytes,
5467
+ pSigned,
5468
+ fileId,
5469
+ revision,
5470
+ keyLength
5471
+ );
5472
+ const uBytes = computeUserPasswordValue(encryptionKey, fileId, revision);
5473
+ const idRef = pdfDoc.context.trailerInfo.ID instanceof import_pdf_lib2.PDFRef ? pdfDoc.context.trailerInfo.ID : null;
5474
+ for (const [ref, obj] of pdfDoc.context.enumerateIndirectObjects()) {
5475
+ if (idRef && ref.objectNumber === idRef.objectNumber && ref.generationNumber === idRef.generationNumber) {
5476
+ continue;
5477
+ }
5478
+ const objKey = buildObjectEncryptionKey(encryptionKey, ref.objectNumber, ref.generationNumber);
5479
+ if (obj instanceof import_pdf_lib2.PDFRawStream) {
5480
+ transformPdfObjectStringsWithRc4(obj.dict, objKey);
5481
+ const encryptedStream = rc4Bytes(objKey, obj.contents);
5482
+ obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(encryptedStream.byteLength));
5483
+ pdfDoc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, encryptedStream));
5484
+ } else if (obj instanceof import_pdf_lib2.PDFStream) {
5485
+ transformPdfObjectStringsWithRc4(obj.dict, objKey);
5486
+ const encodedContents = obj.getContents();
5487
+ const encryptedStream = rc4Bytes(objKey, encodedContents);
5488
+ obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(encryptedStream.byteLength));
5489
+ pdfDoc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, encryptedStream));
5490
+ } else {
5491
+ const next = transformPdfObjectStringsWithRc4(obj, objKey);
5492
+ if (next !== obj) {
5493
+ pdfDoc.context.assign(ref, next);
5494
+ }
5495
+ }
5496
+ }
5497
+ const encryptDict = pdfDoc.context.obj({
5498
+ Filter: import_pdf_lib2.PDFName.of("Standard"),
5499
+ V: import_pdf_lib2.PDFNumber.of(version),
5500
+ R: import_pdf_lib2.PDFNumber.of(revision),
5501
+ Length: import_pdf_lib2.PDFNumber.of(keyLength),
5502
+ P: import_pdf_lib2.PDFNumber.of(pSigned),
5503
+ O: import_pdf_lib2.PDFHexString.of(bytesToHex(oBytes)),
5504
+ U: import_pdf_lib2.PDFHexString.of(bytesToHex(uBytes))
5505
+ });
5506
+ const encryptRef = pdfDoc.context.register(encryptDict);
5507
+ pdfDoc.context.trailerInfo.Encrypt = encryptRef;
5508
+ }
5509
+ async function encryptPdfBytes(pdfBytes, security) {
5510
+ if (!security || security.enabled === false) {
5511
+ return pdfBytes.slice();
5512
+ }
5513
+ const cleanBytes = inspectPdfEncryption(pdfBytes).encrypted ? await decryptPdfBytes(pdfBytes, security.ownerPassword || security.userPassword || "") : pdfBytes;
5514
+ const pdfDoc = await import_pdf_lib2.PDFDocument.load(cleanBytes, { updateMetadata: false });
5515
+ await applyPdfSecurityToDocument(pdfDoc, security);
5516
+ return await pdfDoc.save({ useObjectStreams: false, updateFieldAppearances: false });
5517
+ }
5518
+ function bytesToLatin1(bytes) {
5519
+ let out = "";
5520
+ const chunk = 32768;
5521
+ for (let i = 0; i < bytes.byteLength; i += chunk) {
5522
+ out += String.fromCharCode(...bytes.subarray(i, i + chunk));
5523
+ }
5524
+ return out;
5525
+ }
5526
+ function extractBalancedPdfDict(text, startIdx) {
5527
+ const openIdx = text.indexOf("<<", startIdx);
5528
+ if (openIdx < 0) return null;
5529
+ let depth = 0;
5530
+ let inLiteral = false;
5531
+ let literalDepth = 0;
5532
+ for (let i = openIdx; i < text.length; i++) {
5533
+ const ch = text.charCodeAt(i);
5534
+ if (inLiteral) {
5535
+ if (ch === 92) {
5536
+ i++;
5537
+ continue;
5538
+ }
5539
+ if (ch === 40) literalDepth++;
5540
+ else if (ch === 41) {
5541
+ literalDepth--;
5542
+ if (literalDepth <= 0) {
5543
+ inLiteral = false;
5544
+ }
5545
+ }
5546
+ continue;
5547
+ }
5548
+ if (ch === 40) {
5549
+ inLiteral = true;
5550
+ literalDepth = 1;
5551
+ continue;
5552
+ }
5553
+ if (ch === 37) {
5554
+ while (i < text.length && text.charCodeAt(i) !== 10 && text.charCodeAt(i) !== 13) {
5555
+ i++;
5556
+ }
5557
+ continue;
5558
+ }
5559
+ if (ch === 60 && text.charCodeAt(i + 1) === 60) {
5560
+ depth++;
5561
+ i++;
5562
+ continue;
5563
+ }
5564
+ if (ch === 62 && text.charCodeAt(i + 1) === 62) {
5565
+ depth--;
5566
+ i++;
5567
+ if (depth === 0) {
5568
+ return text.slice(openIdx, i + 1);
5569
+ }
5570
+ }
5571
+ }
5572
+ return null;
5573
+ }
5574
+ function parsePdfStringTokenAfterKey(dictText, keyName) {
5575
+ const re = new RegExp(`\\/${keyName}(?![A-Za-z0-9_.+-])\\s*`);
5576
+ const match = re.exec(dictText);
5577
+ if (!match) return null;
5578
+ let pos = match.index + match[0].length;
5579
+ while (pos < dictText.length && /\s/.test(dictText[pos])) pos++;
5580
+ if (pos >= dictText.length) return null;
5581
+ if (dictText[pos] === "<" && dictText[pos + 1] !== "<") {
5582
+ const close = dictText.indexOf(">", pos + 1);
5583
+ if (close < 0) return null;
5584
+ return hexToBytes(dictText.slice(pos + 1, close));
5585
+ }
5586
+ if (dictText[pos] === "(") {
5587
+ let depth = 1;
5588
+ let i = pos + 1;
5589
+ while (i < dictText.length && depth > 0) {
5590
+ const ch = dictText.charCodeAt(i);
5591
+ if (ch === 92) {
5592
+ i += 2;
5593
+ continue;
5594
+ }
5595
+ if (ch === 40) depth++;
5596
+ else if (ch === 41) depth--;
5597
+ i++;
5598
+ }
5599
+ if (depth === 0) {
5600
+ return decodePdfLiteralBodyBytes(dictText.slice(pos + 1, i - 1));
5601
+ }
5602
+ }
5603
+ return null;
5604
+ }
5605
+ function parseFirstPdfArrayStringBytes(dictText, keyName) {
5606
+ const re = new RegExp(`\\/${keyName}(?![A-Za-z0-9_.+-])\\s*\\[`);
5607
+ const match = re.exec(dictText);
5608
+ if (!match) return null;
5609
+ let pos = match.index + match[0].length;
5610
+ while (pos < dictText.length && /\s/.test(dictText[pos])) pos++;
5611
+ if (pos >= dictText.length) return null;
5612
+ if (dictText[pos] === "<" && dictText[pos + 1] !== "<") {
5613
+ const close = dictText.indexOf(">", pos + 1);
5614
+ if (close >= 0) return hexToBytes(dictText.slice(pos + 1, close));
5615
+ } else if (dictText[pos] === "(") {
5616
+ let depth = 1;
5617
+ let i = pos + 1;
5618
+ while (i < dictText.length && depth > 0) {
5619
+ const ch = dictText.charCodeAt(i);
5620
+ if (ch === 92) {
5621
+ i += 2;
5622
+ continue;
5623
+ }
5624
+ if (ch === 40) depth++;
5625
+ else if (ch === 41) depth--;
5626
+ i++;
5627
+ }
5628
+ if (depth === 0) {
5629
+ return decodePdfLiteralBodyBytes(dictText.slice(pos + 1, i - 1));
5630
+ }
5631
+ }
5632
+ return null;
5633
+ }
5634
+ function parseRawEncryptFromPdfBytes(pdfBytes) {
5635
+ if (!pdfBytes || pdfBytes.byteLength < 16) return null;
5636
+ const rawText = bytesToLatin1(pdfBytes);
5637
+ let containerDict = null;
5638
+ let searchEnd = rawText.length;
5639
+ while (searchEnd > 0) {
5640
+ const trailerIdx = rawText.lastIndexOf("trailer", searchEnd - 1);
5641
+ if (trailerIdx < 0) break;
5642
+ const prevCh = trailerIdx > 0 ? rawText[trailerIdx - 1] : "\n";
5643
+ const afterCh = rawText[trailerIdx + 7] ?? " ";
5644
+ if (/[\s\r\n>]/.test(prevCh) && /[\s\r\n<]/.test(afterCh)) {
5645
+ const candidate = extractBalancedPdfDict(rawText, trailerIdx + 7);
5646
+ if (candidate && /\/Encrypt\b/.test(candidate)) {
5647
+ containerDict = candidate;
5648
+ break;
5649
+ }
5650
+ if (candidate && !containerDict) {
5651
+ containerDict = candidate;
5652
+ }
5653
+ }
5654
+ searchEnd = trailerIdx;
5655
+ }
5656
+ if (!containerDict || !/\/Encrypt\b/.test(containerDict)) {
5657
+ const xrefMatch = /<<[\s\S]{0,2048}?\/Type\s*\/XRef[\s\S]{0,2048}?>>/.exec(rawText);
5658
+ if (xrefMatch && /\/Encrypt\b/.test(xrefMatch[0])) {
5659
+ containerDict = xrefMatch[0];
5660
+ }
5661
+ }
5662
+ if (!containerDict || !/\/Encrypt\b/.test(containerDict)) {
5663
+ return null;
5664
+ }
5665
+ let encryptDictText = null;
5666
+ const refMatch = /\/Encrypt\s+(\d+)\s+(\d+)\s+R\b/.exec(containerDict);
5667
+ if (refMatch) {
5668
+ const objNum = refMatch[1];
5669
+ const genNum = refMatch[2];
5670
+ const objRe = new RegExp(`(?:^|[\\r\\n\\s])${objNum}\\s+${genNum}\\s+obj\\b`, "g");
5671
+ let lastObjMatch = null;
5672
+ let m;
5673
+ while ((m = objRe.exec(rawText)) !== null) {
5674
+ lastObjMatch = m;
5675
+ }
5676
+ if (lastObjMatch) {
5677
+ encryptDictText = extractBalancedPdfDict(rawText, lastObjMatch.index + lastObjMatch[0].length);
5678
+ }
5679
+ } else if (/\/Encrypt\s*<</.test(containerDict)) {
5680
+ const inlineIdx = containerDict.search(/\/Encrypt\s*<</);
5681
+ encryptDictText = extractBalancedPdfDict(containerDict, inlineIdx);
5682
+ }
5683
+ if (!encryptDictText) return null;
5684
+ const filterMatch = /\/Filter\s*\/([A-Za-z0-9_.+-]+)/.exec(encryptDictText);
5685
+ const vMatch = /\/V\s+(-?\d+)/.exec(encryptDictText);
5686
+ const rMatch = /\/R\s+(-?\d+)/.exec(encryptDictText);
5687
+ const lenMatch = /\/Length\s+(\d+)/.exec(encryptDictText);
5688
+ const pMatch = /\/P\s+(-?\d+)/.exec(encryptDictText);
5689
+ const filter = filterMatch ? filterMatch[1] : "Standard";
5690
+ const version = vMatch ? parseInt(vMatch[1], 10) : 1;
5691
+ const revision = rMatch ? parseInt(rMatch[1], 10) : version >= 2 ? 3 : 2;
5692
+ const keyLength = lenMatch ? parseInt(lenMatch[1], 10) : version >= 2 ? 128 : 40;
5693
+ const pSigned = pMatch ? parseInt(pMatch[1], 10) | 0 : -4;
5694
+ const oBytes = parsePdfStringTokenAfterKey(encryptDictText, "O") ?? new Uint8Array(0);
5695
+ const uBytes = parsePdfStringTokenAfterKey(encryptDictText, "U") ?? new Uint8Array(0);
5696
+ let fileId = parseFirstPdfArrayStringBytes(containerDict, "ID");
5697
+ if (!fileId) {
5698
+ const idRefMatch = /\/ID\s+(\d+)\s+(\d+)\s+R\b/.exec(containerDict);
5699
+ if (idRefMatch) {
5700
+ const idObjRe = new RegExp(`(?:^|[\\r\\n\\s])${idRefMatch[1]}\\s+${idRefMatch[2]}\\s+obj\\b([\\s\\S]{0,512}?)endobj`);
5701
+ const idObjM = idObjRe.exec(rawText);
5702
+ if (idObjM) {
5703
+ fileId = parseFirstPdfArrayStringBytes(`/ID ${idObjM[1]}`, "ID");
5704
+ }
5705
+ }
5706
+ }
5707
+ return {
5708
+ filter,
5709
+ version,
5710
+ revision,
5711
+ keyLength,
5712
+ pSigned,
5713
+ oBytes,
5714
+ uBytes,
5715
+ fileId: fileId ?? new Uint8Array(0)
5716
+ };
5717
+ }
5718
+ function extractEncryptMetadataFromDoc(doc) {
5719
+ const encEntry = doc.context.trailerInfo.Encrypt;
5720
+ if (!encEntry) return null;
5721
+ const encDict = encEntry instanceof import_pdf_lib2.PDFDict ? encEntry : doc.context.lookupMaybe(encEntry, import_pdf_lib2.PDFDict);
5722
+ if (!encDict) return null;
5723
+ const filterObj = encDict.get(import_pdf_lib2.PDFName.of("Filter"));
5724
+ const filter = filterObj instanceof import_pdf_lib2.PDFName ? filterObj.decodeText() : "Standard";
5725
+ const vObj = encDict.get(import_pdf_lib2.PDFName.of("V"));
5726
+ const version = vObj instanceof import_pdf_lib2.PDFNumber ? vObj.asNumber() : 1;
5727
+ const rObj = encDict.get(import_pdf_lib2.PDFName.of("R"));
5728
+ const revision = rObj instanceof import_pdf_lib2.PDFNumber ? rObj.asNumber() : version >= 2 ? 3 : 2;
5729
+ const lenObj = encDict.get(import_pdf_lib2.PDFName.of("Length"));
5730
+ const keyLength = lenObj instanceof import_pdf_lib2.PDFNumber ? lenObj.asNumber() : version >= 2 ? 128 : 40;
5731
+ const pObj = encDict.get(import_pdf_lib2.PDFName.of("P"));
5732
+ const pSigned = pObj instanceof import_pdf_lib2.PDFNumber ? pObj.asNumber() | 0 : -4;
5733
+ const oObj = encDict.get(import_pdf_lib2.PDFName.of("O"));
5734
+ const oBytes = oObj instanceof import_pdf_lib2.PDFHexString || oObj instanceof import_pdf_lib2.PDFString ? extractPdfStringRawBytes(oObj) : new Uint8Array(0);
5735
+ const uObj = encDict.get(import_pdf_lib2.PDFName.of("U"));
5736
+ const uBytes = uObj instanceof import_pdf_lib2.PDFHexString || uObj instanceof import_pdf_lib2.PDFString ? extractPdfStringRawBytes(uObj) : new Uint8Array(0);
5737
+ let fileId = new Uint8Array(0);
5738
+ const idEntry = doc.context.trailerInfo.ID;
5739
+ const idArr = idEntry instanceof import_pdf_lib2.PDFArray ? idEntry : doc.context.lookupMaybe(idEntry, import_pdf_lib2.PDFArray);
5740
+ if (idArr && idArr.size() > 0) {
5741
+ const first = idArr.get(0);
5742
+ if (first instanceof import_pdf_lib2.PDFHexString || first instanceof import_pdf_lib2.PDFString) {
5743
+ fileId = extractPdfStringRawBytes(first);
5744
+ }
5745
+ }
5746
+ return {
5747
+ filter,
5748
+ version,
5749
+ revision,
5750
+ keyLength,
5751
+ pSigned,
5752
+ oBytes,
5753
+ uBytes,
5754
+ fileId
5755
+ };
5756
+ }
5757
+ function inspectPdfEncryption(pdfBytes) {
5758
+ const meta = parseRawEncryptFromPdfBytes(pdfBytes);
5759
+ if (!meta) {
5760
+ return {
5761
+ encrypted: false,
5762
+ requiresOpenPassword: false,
5763
+ permissions: { ...DEFAULT_ALL_PERMISSIONS }
5764
+ };
5765
+ }
5766
+ let requiresOpenPassword = true;
5767
+ if (meta.filter === "Standard" && (meta.version === 1 || meta.version === 2) && (meta.revision === 2 || meta.revision === 3) && meta.oBytes.byteLength >= 32 && meta.uBytes.byteLength >= 16) {
5768
+ const emptyKey = authenticatePaddedUserPassword(
5769
+ padPdfPassword(""),
5770
+ meta.oBytes,
5771
+ meta.uBytes,
5772
+ meta.pSigned,
5773
+ meta.fileId,
5774
+ meta.revision,
5775
+ meta.keyLength
5776
+ );
5777
+ requiresOpenPassword = emptyKey === null;
5778
+ }
5779
+ return {
5780
+ encrypted: true,
5781
+ requiresOpenPassword,
5782
+ filter: meta.filter,
5783
+ version: meta.version,
5784
+ revision: meta.revision,
5785
+ keyLength: meta.keyLength,
5786
+ permissionFlagsRaw: meta.pSigned,
5787
+ permissions: decodePdfPermissionFlags(meta.pSigned, meta.revision)
5788
+ };
5789
+ }
5790
+ async function decryptPdfBytes(pdfBytes, password) {
5791
+ let meta = parseRawEncryptFromPdfBytes(pdfBytes);
5792
+ const doc = await import_pdf_lib2.PDFDocument.load(pdfBytes, {
5793
+ ignoreEncryption: true,
5794
+ updateMetadata: false
5795
+ });
5796
+ if (!meta && doc.isEncrypted) {
5797
+ meta = extractEncryptMetadataFromDoc(doc);
5798
+ }
5799
+ if (!meta) {
5800
+ return pdfBytes.slice();
5801
+ }
5802
+ if (meta.filter !== "Standard" || meta.version !== 1 && meta.version !== 2 || meta.revision !== 2 && meta.revision !== 3) {
5803
+ throw new PdfSecurityError(
5804
+ "PDF_UNSUPPORTED_ENCRYPTION",
5805
+ `Unsupported PDF encryption handler (Filter=/${meta.filter}, V=${meta.version}, R=${meta.revision}).`
5806
+ );
5807
+ }
5808
+ const rev = meta.revision;
5809
+ const emptyOpenKey = authenticatePaddedUserPassword(
5810
+ padPdfPassword(""),
5811
+ meta.oBytes,
5812
+ meta.uBytes,
5813
+ meta.pSigned,
5814
+ meta.fileId,
5815
+ rev,
5816
+ meta.keyLength
5817
+ );
5818
+ const requiresOpenPassword = emptyOpenKey === null;
5819
+ const candidatePw = password ?? "";
5820
+ if (requiresOpenPassword && candidatePw.length === 0) {
5821
+ throw new PdfSecurityError(
5822
+ "PDF_PASSWORD_REQUIRED",
5823
+ "Encrypted PDF document requires an open password."
5824
+ );
5825
+ }
5826
+ let encryptionKey = null;
5827
+ if (candidatePw.length === 0 && emptyOpenKey) {
5828
+ encryptionKey = emptyOpenKey;
5829
+ } else {
5830
+ encryptionKey = authenticatePaddedUserPassword(
5831
+ padPdfPassword(candidatePw),
5832
+ meta.oBytes,
5833
+ meta.uBytes,
5834
+ meta.pSigned,
5835
+ meta.fileId,
5836
+ rev,
5837
+ meta.keyLength
5838
+ );
5839
+ if (!encryptionKey) {
5840
+ encryptionKey = authenticateOwnerPassword(
5841
+ candidatePw,
5842
+ meta.oBytes,
5843
+ meta.uBytes,
5844
+ meta.pSigned,
5845
+ meta.fileId,
5846
+ rev,
5847
+ meta.keyLength
5848
+ );
5849
+ }
5850
+ }
5851
+ if (!encryptionKey) {
5852
+ throw new PdfSecurityError(
5853
+ "PDF_INVALID_PASSWORD",
5854
+ "Incorrect password for encrypted PDF document."
5855
+ );
5856
+ }
5857
+ const encryptRef = doc.context.trailerInfo.Encrypt instanceof import_pdf_lib2.PDFRef ? doc.context.trailerInfo.Encrypt : null;
5858
+ const idRef = doc.context.trailerInfo.ID instanceof import_pdf_lib2.PDFRef ? doc.context.trailerInfo.ID : null;
5859
+ for (const [ref, obj] of doc.context.enumerateIndirectObjects()) {
5860
+ if (encryptRef && ref.objectNumber === encryptRef.objectNumber && ref.generationNumber === encryptRef.generationNumber) {
5861
+ continue;
5862
+ }
5863
+ if (idRef && ref.objectNumber === idRef.objectNumber && ref.generationNumber === idRef.generationNumber) {
5864
+ continue;
5865
+ }
5866
+ const objKey = buildObjectEncryptionKey(encryptionKey, ref.objectNumber, ref.generationNumber);
5867
+ if (obj instanceof import_pdf_lib2.PDFRawStream) {
5868
+ transformPdfObjectStringsWithRc4(obj.dict, objKey);
5869
+ const decryptedStream = rc4Bytes(objKey, obj.contents);
5870
+ obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(decryptedStream.byteLength));
5871
+ doc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, decryptedStream));
5872
+ } else if (obj instanceof import_pdf_lib2.PDFStream) {
5873
+ transformPdfObjectStringsWithRc4(obj.dict, objKey);
5874
+ const decryptedStream = rc4Bytes(objKey, obj.getContents());
5875
+ obj.dict.set(import_pdf_lib2.PDFName.of("Length"), import_pdf_lib2.PDFNumber.of(decryptedStream.byteLength));
5876
+ doc.context.assign(ref, import_pdf_lib2.PDFRawStream.of(obj.dict, decryptedStream));
5877
+ } else {
5878
+ const next = transformPdfObjectStringsWithRc4(obj, objKey);
5879
+ if (next !== obj) {
5880
+ doc.context.assign(ref, next);
5881
+ }
5882
+ }
5883
+ }
5884
+ delete doc.context.trailerInfo.Encrypt;
5885
+ if (encryptRef) {
5886
+ doc.context.delete(encryptRef);
5887
+ }
5888
+ return await doc.save({ useObjectStreams: false, updateFieldAppearances: false });
5889
+ }
5890
+
5891
+ // src/exporter/pdf-svg-vector.ts
5892
+ var import_pdf_lib3 = require("pdf-lib");
4896
5893
  function parseObjectPositionRatios(objectPosition) {
4897
5894
  if (!objectPosition || !objectPosition.trim()) {
4898
5895
  return { ax: 0.5, ayTop: 0.5 };
@@ -4995,12 +5992,12 @@ function computeElementCenterTransformMatrix(box, angleDeg = 0, flipX = false, f
4995
5992
  function toPdfLibColor(parsed, colorType) {
4996
5993
  if (colorType === "cmyk" || parsed.sourceSpace === "cmyk") {
4997
5994
  if (typeof parsed.c === "number" && typeof parsed.m === "number" && typeof parsed.y === "number" && typeof parsed.k === "number") {
4998
- return (0, import_pdf_lib2.cmyk)(parsed.c, parsed.m, parsed.y, parsed.k);
5995
+ return (0, import_pdf_lib3.cmyk)(parsed.c, parsed.m, parsed.y, parsed.k);
4999
5996
  }
5000
5997
  const conv = rgbToCmyk(parsed.r, parsed.g, parsed.b);
5001
- return (0, import_pdf_lib2.cmyk)(conv.c, conv.m, conv.y, conv.k);
5998
+ return (0, import_pdf_lib3.cmyk)(conv.c, conv.m, conv.y, conv.k);
5002
5999
  }
5003
- return (0, import_pdf_lib2.rgb)(parsed.r, parsed.g, parsed.b);
6000
+ return (0, import_pdf_lib3.rgb)(parsed.r, parsed.g, parsed.b);
5004
6001
  }
5005
6002
  function multiplySvgMat(m1, m2) {
5006
6003
  return [
@@ -5536,7 +6533,7 @@ function drawVectorSvgOnPdfPage(pdfPage, pageHeight, left, top, width, height, s
5536
6533
  const ops = parseSvgToVectorCommands(svgXml, width, height, opacity);
5537
6534
  if (ops.length === 0) return 0;
5538
6535
  const pdfY = pageHeight - top - height;
5539
- pdfPage.pushOperators((0, import_pdf_lib2.pushGraphicsState)(), (0, import_pdf_lib2.rectangle)(left, pdfY, width, height), (0, import_pdf_lib2.clip)(), (0, import_pdf_lib2.endPath)());
6536
+ pdfPage.pushOperators((0, import_pdf_lib3.pushGraphicsState)(), (0, import_pdf_lib3.rectangle)(left, pdfY, width, height), (0, import_pdf_lib3.clip)(), (0, import_pdf_lib3.endPath)());
5540
6537
  try {
5541
6538
  for (const op of ops) {
5542
6539
  pdfPage.drawSvgPath(op.pathData, {
@@ -5551,7 +6548,7 @@ function drawVectorSvgOnPdfPage(pdfPage, pageHeight, left, top, width, height, s
5551
6548
  });
5552
6549
  }
5553
6550
  } finally {
5554
- pdfPage.pushOperators((0, import_pdf_lib2.popGraphicsState)());
6551
+ pdfPage.pushOperators((0, import_pdf_lib3.popGraphicsState)());
5555
6552
  }
5556
6553
  return ops.length;
5557
6554
  }
@@ -5884,8 +6881,8 @@ function registerSubsetType0FontInDoc(pdfDoc, fontBytes, usedCodePoints, fontTag
5884
6881
  Subtype: "CIDFontType2",
5885
6882
  BaseFont: fontTag,
5886
6883
  CIDSystemInfo: {
5887
- Registry: import_pdf_lib3.PDFString.of("Adobe"),
5888
- Ordering: import_pdf_lib3.PDFString.of("Identity"),
6884
+ Registry: import_pdf_lib4.PDFString.of("Adobe"),
6885
+ Ordering: import_pdf_lib4.PDFString.of("Identity"),
5889
6886
  Supplement: 0
5890
6887
  },
5891
6888
  FontDescriptor: fontDescriptorRef,
@@ -6281,8 +7278,8 @@ function initVectorCjkEmbedState(pdfDoc, snapshot, effectiveData, options, preRe
6281
7278
  Subtype: "CIDFontType2",
6282
7279
  BaseFont: "STSong-Light",
6283
7280
  CIDSystemInfo: {
6284
- Registry: import_pdf_lib3.PDFString.of("Adobe"),
6285
- Ordering: import_pdf_lib3.PDFString.of("GB1"),
7281
+ Registry: import_pdf_lib4.PDFString.of("Adobe"),
7282
+ Ordering: import_pdf_lib4.PDFString.of("GB1"),
6286
7283
  Supplement: 4
6287
7284
  },
6288
7285
  FontDescriptor: fontDescriptorRef,
@@ -6474,25 +7471,25 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
6474
7471
  }
6475
7472
  const fillOp = colorType === "cmyk" ? (() => {
6476
7473
  const cm = rgbToCmyk(color.r, color.g, color.b);
6477
- return (0, import_pdf_lib3.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
6478
- })() : (0, import_pdf_lib3.setFillingRgbColor)(color.r, color.g, color.b);
7474
+ return (0, import_pdf_lib4.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
7475
+ })() : (0, import_pdf_lib4.setFillingRgbColor)(color.r, color.g, color.b);
6479
7476
  const syntheticBoldOps = wantBold && !usedDedicatedBold ? [
6480
- import_pdf_lib3.PDFOperator.of("Tr", [import_pdf_lib3.PDFNumber.of(2)]),
6481
- (0, import_pdf_lib3.setLineWidth)(Math.max(0.25, fontSize * 0.032)),
7477
+ import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(2)]),
7478
+ (0, import_pdf_lib4.setLineWidth)(Math.max(0.25, fontSize * 0.032)),
6482
7479
  colorType === "cmyk" ? (() => {
6483
7480
  const cm = rgbToCmyk(color.r, color.g, color.b);
6484
- return (0, import_pdf_lib3.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
6485
- })() : (0, import_pdf_lib3.setStrokingRgbColor)(color.r, color.g, color.b)
7481
+ return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
7482
+ })() : (0, import_pdf_lib4.setStrokingRgbColor)(color.r, color.g, color.b)
6486
7483
  ] : [];
6487
7484
  const decoCol = toPdfLibColor(color, colorType);
6488
7485
  const decoThickness = Math.max(0.6, fontSize * 0.065);
6489
7486
  const applyClip = !noWrapSingleLine && width > 0 && height > 0;
6490
7487
  if (applyClip) {
6491
7488
  page.pushOperators(
6492
- (0, import_pdf_lib3.pushGraphicsState)(),
6493
- (0, import_pdf_lib3.rectangle)(left, pdfY, width, height),
6494
- (0, import_pdf_lib3.clip)(),
6495
- (0, import_pdf_lib3.endPath)()
7489
+ (0, import_pdf_lib4.pushGraphicsState)(),
7490
+ (0, import_pdf_lib4.rectangle)(left, pdfY, width, height),
7491
+ (0, import_pdf_lib4.clip)(),
7492
+ (0, import_pdf_lib4.endPath)()
6496
7493
  );
6497
7494
  }
6498
7495
  for (let i = 0; i < lines.length; i++) {
@@ -6520,25 +7517,25 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
6520
7517
  }
6521
7518
  const hexStr = encodeVectorCjkLineHex(line, state, activeSubset);
6522
7519
  const totalTc = charSpacing + extraJustifyTc;
6523
- const posOp = style?.italic ? import_pdf_lib3.PDFOperator.of("Tm", [
6524
- import_pdf_lib3.PDFNumber.of(1),
6525
- import_pdf_lib3.PDFNumber.of(0),
6526
- import_pdf_lib3.PDFNumber.of(0.2126),
6527
- import_pdf_lib3.PDFNumber.of(1),
6528
- import_pdf_lib3.PDFNumber.of(drawX),
6529
- import_pdf_lib3.PDFNumber.of(drawY)
6530
- ]) : (0, import_pdf_lib3.moveText)(drawX, drawY);
7520
+ const posOp = style?.italic ? import_pdf_lib4.PDFOperator.of("Tm", [
7521
+ import_pdf_lib4.PDFNumber.of(1),
7522
+ import_pdf_lib4.PDFNumber.of(0),
7523
+ import_pdf_lib4.PDFNumber.of(0.2126),
7524
+ import_pdf_lib4.PDFNumber.of(1),
7525
+ import_pdf_lib4.PDFNumber.of(drawX),
7526
+ import_pdf_lib4.PDFNumber.of(drawY)
7527
+ ]) : (0, import_pdf_lib4.moveText)(drawX, drawY);
6531
7528
  page.pushOperators(
6532
- (0, import_pdf_lib3.pushGraphicsState)(),
6533
- (0, import_pdf_lib3.beginText)(),
7529
+ (0, import_pdf_lib4.pushGraphicsState)(),
7530
+ (0, import_pdf_lib4.beginText)(),
6534
7531
  fillOp,
6535
7532
  ...syntheticBoldOps,
6536
- (0, import_pdf_lib3.setFontAndSize)(fontKey, fontSize),
6537
- ...totalTc !== 0 ? [(0, import_pdf_lib3.setCharacterSpacing)(totalTc)] : [],
7533
+ (0, import_pdf_lib4.setFontAndSize)(fontKey, fontSize),
7534
+ ...totalTc !== 0 ? [(0, import_pdf_lib4.setCharacterSpacing)(totalTc)] : [],
6538
7535
  posOp,
6539
- (0, import_pdf_lib3.showText)(import_pdf_lib3.PDFHexString.of(hexStr)),
6540
- (0, import_pdf_lib3.endText)(),
6541
- (0, import_pdf_lib3.popGraphicsState)()
7536
+ (0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
7537
+ (0, import_pdf_lib4.endText)(),
7538
+ (0, import_pdf_lib4.popGraphicsState)()
6542
7539
  );
6543
7540
  if (style?.underline) {
6544
7541
  const ulY = drawY - fontSize * 0.12;
@@ -6562,7 +7559,7 @@ function drawVectorCjkTextBox(page, pageHeight, text, left, top, width, height,
6562
7559
  }
6563
7560
  }
6564
7561
  if (applyClip) {
6565
- page.pushOperators((0, import_pdf_lib3.popGraphicsState)());
7562
+ page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
6566
7563
  }
6567
7564
  }
6568
7565
  function renderTextToPngBytesInBrowser(text, widthPt, heightPt, style) {
@@ -6880,21 +7877,21 @@ var STANDARD_FONT_CACHE = /* @__PURE__ */ new WeakMap();
6880
7877
  function resolveStandardPdfFont(fontFamily, bold, italic) {
6881
7878
  const fam = (fontFamily ?? "").toLowerCase();
6882
7879
  if (fam.includes("courier") || fam.includes("mono") || fam.includes("consolas")) {
6883
- if (bold && italic) return import_pdf_lib3.StandardFonts.CourierBoldOblique;
6884
- if (bold) return import_pdf_lib3.StandardFonts.CourierBold;
6885
- if (italic) return import_pdf_lib3.StandardFonts.CourierOblique;
6886
- return import_pdf_lib3.StandardFonts.Courier;
7880
+ if (bold && italic) return import_pdf_lib4.StandardFonts.CourierBoldOblique;
7881
+ if (bold) return import_pdf_lib4.StandardFonts.CourierBold;
7882
+ if (italic) return import_pdf_lib4.StandardFonts.CourierOblique;
7883
+ return import_pdf_lib4.StandardFonts.Courier;
6887
7884
  }
6888
7885
  if ((fam.includes("times") || fam.includes("serif") || fam.includes("georgia")) && !fam.includes("sans")) {
6889
- if (bold && italic) return import_pdf_lib3.StandardFonts.TimesRomanBoldItalic;
6890
- if (bold) return import_pdf_lib3.StandardFonts.TimesRomanBold;
6891
- if (italic) return import_pdf_lib3.StandardFonts.TimesRomanItalic;
6892
- return import_pdf_lib3.StandardFonts.TimesRoman;
7886
+ if (bold && italic) return import_pdf_lib4.StandardFonts.TimesRomanBoldItalic;
7887
+ if (bold) return import_pdf_lib4.StandardFonts.TimesRomanBold;
7888
+ if (italic) return import_pdf_lib4.StandardFonts.TimesRomanItalic;
7889
+ return import_pdf_lib4.StandardFonts.TimesRoman;
6893
7890
  }
6894
- if (bold && italic) return import_pdf_lib3.StandardFonts.HelveticaBoldOblique;
6895
- if (bold) return import_pdf_lib3.StandardFonts.HelveticaBold;
6896
- if (italic) return import_pdf_lib3.StandardFonts.HelveticaOblique;
6897
- return import_pdf_lib3.StandardFonts.Helvetica;
7891
+ if (bold && italic) return import_pdf_lib4.StandardFonts.HelveticaBoldOblique;
7892
+ if (bold) return import_pdf_lib4.StandardFonts.HelveticaBold;
7893
+ if (italic) return import_pdf_lib4.StandardFonts.HelveticaOblique;
7894
+ return import_pdf_lib4.StandardFonts.Helvetica;
6898
7895
  }
6899
7896
  async function getOrEmbedStandardFont(pdfDoc, fontName) {
6900
7897
  let docMap = STANDARD_FONT_CACHE.get(pdfDoc);
@@ -7037,10 +8034,10 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
7037
8034
  const applyAsciiClip = !extraOpts?.noWrapSingleLine && bgWidth > 0 && height > 0;
7038
8035
  if (applyAsciiClip) {
7039
8036
  page.pushOperators(
7040
- (0, import_pdf_lib3.pushGraphicsState)(),
7041
- (0, import_pdf_lib3.rectangle)(left, pdfY, bgWidth, height),
7042
- (0, import_pdf_lib3.clip)(),
7043
- (0, import_pdf_lib3.endPath)()
8037
+ (0, import_pdf_lib4.pushGraphicsState)(),
8038
+ (0, import_pdf_lib4.rectangle)(left, pdfY, bgWidth, height),
8039
+ (0, import_pdf_lib4.clip)(),
8040
+ (0, import_pdf_lib4.endPath)()
7044
8041
  );
7045
8042
  }
7046
8043
  for (let i = 0; i < wrappedLines.length; i++) {
@@ -7073,10 +8070,10 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
7073
8070
  }
7074
8071
  const totalTc = charSpacing + extraJustifyTc;
7075
8072
  if (totalTc !== 0 || extraWordSpacing !== 0) {
7076
- const ops = [(0, import_pdf_lib3.pushGraphicsState)()];
7077
- if (totalTc !== 0) ops.push((0, import_pdf_lib3.setCharacterSpacing)(totalTc));
8073
+ const ops = [(0, import_pdf_lib4.pushGraphicsState)()];
8074
+ if (totalTc !== 0) ops.push((0, import_pdf_lib4.setCharacterSpacing)(totalTc));
7078
8075
  if (extraWordSpacing !== 0) {
7079
- ops.push(import_pdf_lib3.PDFOperator.of("Tw", [import_pdf_lib3.PDFNumber.of(extraWordSpacing)]));
8076
+ ops.push(import_pdf_lib4.PDFOperator.of("Tw", [import_pdf_lib4.PDFNumber.of(extraWordSpacing)]));
7080
8077
  }
7081
8078
  page.pushOperators(...ops);
7082
8079
  page.drawText(lineText, {
@@ -7087,7 +8084,7 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
7087
8084
  color: pdfCol,
7088
8085
  opacity: color.a
7089
8086
  });
7090
- page.pushOperators((0, import_pdf_lib3.popGraphicsState)());
8087
+ page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
7091
8088
  } else {
7092
8089
  page.drawText(lineText, {
7093
8090
  x: drawX,
@@ -7120,7 +8117,7 @@ async function drawTextBox(pdfDoc, page, pageHeight, text, left, top, width, hei
7120
8117
  }
7121
8118
  }
7122
8119
  if (applyAsciiClip) {
7123
- page.pushOperators((0, import_pdf_lib3.popGraphicsState)());
8120
+ page.pushOperators((0, import_pdf_lib4.popGraphicsState)());
7124
8121
  }
7125
8122
  }
7126
8123
  function parseNumericCellValue(rawValue) {
@@ -7832,7 +8829,7 @@ async function drawRichOrColumnTextBox(pdfDoc, page, pageHeight, spans, left, to
7832
8829
  const key = `${code ? "C" : "S"}-${bold ? "B" : "N"}-${italic ? "I" : "R"}`;
7833
8830
  const existing = fontCache.get(key);
7834
8831
  if (existing) return existing;
7835
- const stdName = code ? bold && italic ? import_pdf_lib3.StandardFonts.CourierBoldOblique : bold ? import_pdf_lib3.StandardFonts.CourierBold : italic ? import_pdf_lib3.StandardFonts.CourierOblique : import_pdf_lib3.StandardFonts.Courier : bold && italic ? import_pdf_lib3.StandardFonts.HelveticaBoldOblique : bold ? import_pdf_lib3.StandardFonts.HelveticaBold : italic ? import_pdf_lib3.StandardFonts.HelveticaOblique : import_pdf_lib3.StandardFonts.Helvetica;
8832
+ const stdName = code ? bold && italic ? import_pdf_lib4.StandardFonts.CourierBoldOblique : bold ? import_pdf_lib4.StandardFonts.CourierBold : italic ? import_pdf_lib4.StandardFonts.CourierOblique : import_pdf_lib4.StandardFonts.Courier : bold && italic ? import_pdf_lib4.StandardFonts.HelveticaBoldOblique : bold ? import_pdf_lib4.StandardFonts.HelveticaBold : italic ? import_pdf_lib4.StandardFonts.HelveticaOblique : import_pdf_lib4.StandardFonts.Helvetica;
7836
8833
  const embedded = await pdfDoc.embedFont(stdName);
7837
8834
  fontCache.set(key, embedded);
7838
8835
  return embedded;
@@ -7885,34 +8882,34 @@ async function drawRichOrColumnTextBox(pdfDoc, page, pageHeight, spans, left, to
7885
8882
  const hexStr = encodeVectorCjkLineHex(seg.text, cjkState, activeSubset);
7886
8883
  const fillOp = colorType === "cmyk" ? (() => {
7887
8884
  const cm = rgbToCmyk(col.r, col.g, col.b);
7888
- return (0, import_pdf_lib3.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
7889
- })() : (0, import_pdf_lib3.setFillingRgbColor)(col.r, col.g, col.b);
8885
+ return (0, import_pdf_lib4.setFillingCmykColor)(cm.c, cm.m, cm.y, cm.k);
8886
+ })() : (0, import_pdf_lib4.setFillingRgbColor)(col.r, col.g, col.b);
7890
8887
  const boldOps = seg.bold && !usedDedicatedBold ? [
7891
- import_pdf_lib3.PDFOperator.of("Tr", [import_pdf_lib3.PDFNumber.of(2)]),
7892
- (0, import_pdf_lib3.setLineWidth)(Math.max(0.25, seg.fontSize * 0.032)),
8888
+ import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(2)]),
8889
+ (0, import_pdf_lib4.setLineWidth)(Math.max(0.25, seg.fontSize * 0.032)),
7893
8890
  colorType === "cmyk" ? (() => {
7894
8891
  const cm = rgbToCmyk(col.r, col.g, col.b);
7895
- return (0, import_pdf_lib3.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
7896
- })() : (0, import_pdf_lib3.setStrokingRgbColor)(col.r, col.g, col.b)
8892
+ return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
8893
+ })() : (0, import_pdf_lib4.setStrokingRgbColor)(col.r, col.g, col.b)
7897
8894
  ] : [];
7898
- const posOp = seg.italic ? import_pdf_lib3.PDFOperator.of("Tm", [
7899
- import_pdf_lib3.PDFNumber.of(1),
7900
- import_pdf_lib3.PDFNumber.of(0),
7901
- import_pdf_lib3.PDFNumber.of(0.2126),
7902
- import_pdf_lib3.PDFNumber.of(1),
7903
- import_pdf_lib3.PDFNumber.of(segX),
7904
- import_pdf_lib3.PDFNumber.of(baselineY)
7905
- ]) : (0, import_pdf_lib3.moveText)(segX, baselineY);
8895
+ const posOp = seg.italic ? import_pdf_lib4.PDFOperator.of("Tm", [
8896
+ import_pdf_lib4.PDFNumber.of(1),
8897
+ import_pdf_lib4.PDFNumber.of(0),
8898
+ import_pdf_lib4.PDFNumber.of(0.2126),
8899
+ import_pdf_lib4.PDFNumber.of(1),
8900
+ import_pdf_lib4.PDFNumber.of(segX),
8901
+ import_pdf_lib4.PDFNumber.of(baselineY)
8902
+ ]) : (0, import_pdf_lib4.moveText)(segX, baselineY);
7906
8903
  page.pushOperators(
7907
- (0, import_pdf_lib3.pushGraphicsState)(),
7908
- (0, import_pdf_lib3.beginText)(),
8904
+ (0, import_pdf_lib4.pushGraphicsState)(),
8905
+ (0, import_pdf_lib4.beginText)(),
7909
8906
  fillOp,
7910
8907
  ...boldOps,
7911
- (0, import_pdf_lib3.setFontAndSize)(fontKey, seg.fontSize),
8908
+ (0, import_pdf_lib4.setFontAndSize)(fontKey, seg.fontSize),
7912
8909
  posOp,
7913
- (0, import_pdf_lib3.showText)(import_pdf_lib3.PDFHexString.of(hexStr)),
7914
- (0, import_pdf_lib3.endText)(),
7915
- (0, import_pdf_lib3.popGraphicsState)()
8910
+ (0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
8911
+ (0, import_pdf_lib4.endText)(),
8912
+ (0, import_pdf_lib4.popGraphicsState)()
7916
8913
  );
7917
8914
  } else if (hasNonAscii(seg.text)) {
7918
8915
  const pngBytes = renderTextToPngBytesInBrowser(seg.text, Math.max(8, seg.widthPt + 4), seg.fontSize * 1.35, {
@@ -8052,10 +9049,11 @@ function attachPdfOutlinesTree(pdfDoc, bookmarks) {
8052
9049
  const selfRef = itemRefs[i];
8053
9050
  const clampedPageIdx = Math.max(0, Math.min(allPages.length - 1, Math.floor(item.pageIndex || 0)));
8054
9051
  const targetPage = allPages[clampedPageIdx];
8055
- const destY = item.topOffsetPt !== void 0 ? Math.round(Math.max(0, targetPage.getHeight() - item.topOffsetPt) * 100) / 100 : null;
8056
- const destArray = pdfDoc.context.obj([targetPage.ref, import_pdf_lib3.PDFName.of("XYZ"), null, destY, null]);
9052
+ const effectiveTopOffset = item.topPt ?? item.topOffsetPt;
9053
+ const destY = effectiveTopOffset !== void 0 ? Math.round(Math.max(0, targetPage.getHeight() - effectiveTopOffset) * 100) / 100 : null;
9054
+ const destArray = pdfDoc.context.obj([targetPage.ref, import_pdf_lib4.PDFName.of("XYZ"), null, destY, null]);
8057
9055
  const dictObj = {
8058
- Title: import_pdf_lib3.PDFHexString.fromText(item.title || "Bookmark"),
9056
+ Title: import_pdf_lib4.PDFHexString.fromText(item.title || "Bookmark"),
8059
9057
  Parent: parentRef,
8060
9058
  Dest: destArray
8061
9059
  };
@@ -8088,15 +9086,15 @@ function attachPdfOutlinesTree(pdfDoc, bookmarks) {
8088
9086
  Count: rootChain.totalCount
8089
9087
  })
8090
9088
  );
8091
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("Outlines"), outlinesRef);
9089
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Outlines"), outlinesRef);
8092
9090
  }
8093
9091
  function ensurePagePropertiesDict(pdfDoc, pdfPage) {
8094
9092
  pdfPage.node.normalize();
8095
9093
  const res = pdfPage.node.Resources();
8096
- let props = pdfDoc.context.lookupMaybe(res.get(import_pdf_lib3.PDFName.of("Properties")), import_pdf_lib3.PDFDict);
9094
+ let props = pdfDoc.context.lookupMaybe(res.get(import_pdf_lib4.PDFName.of("Properties")), import_pdf_lib4.PDFDict);
8097
9095
  if (!props) {
8098
9096
  props = pdfDoc.context.obj({});
8099
- res.set(import_pdf_lib3.PDFName.of("Properties"), props);
9097
+ res.set(import_pdf_lib4.PDFName.of("Properties"), props);
8100
9098
  }
8101
9099
  return props;
8102
9100
  }
@@ -8112,11 +9110,11 @@ function attachOptionalContentLayers(pdfDoc, layers) {
8112
9110
  const isPrint = layer.printable !== false;
8113
9111
  const ocgDict = pdfDoc.context.obj({
8114
9112
  Type: "OCG",
8115
- Name: import_pdf_lib3.PDFHexString.fromText(layer.name || layer.id),
8116
- Intent: [import_pdf_lib3.PDFName.of("View"), import_pdf_lib3.PDFName.of("Design")],
9113
+ Name: import_pdf_lib4.PDFHexString.fromText(layer.name || layer.id),
9114
+ Intent: [import_pdf_lib4.PDFName.of("View"), import_pdf_lib4.PDFName.of("Design")],
8117
9115
  Usage: {
8118
- View: { ViewState: import_pdf_lib3.PDFName.of(isVis ? "ON" : "OFF") },
8119
- Print: { PrintState: import_pdf_lib3.PDFName.of(isPrint ? "ON" : "OFF") }
9116
+ View: { ViewState: import_pdf_lib4.PDFName.of(isVis ? "ON" : "OFF") },
9117
+ Print: { PrintState: import_pdf_lib4.PDFName.of(isPrint ? "ON" : "OFF") }
8120
9118
  }
8121
9119
  });
8122
9120
  const ocgRef = pdfDoc.context.register(ocgDict);
@@ -8131,11 +9129,11 @@ function attachOptionalContentLayers(pdfDoc, layers) {
8131
9129
  });
8132
9130
  });
8133
9131
  pdfDoc.catalog.set(
8134
- import_pdf_lib3.PDFName.of("OCProperties"),
9132
+ import_pdf_lib4.PDFName.of("OCProperties"),
8135
9133
  pdfDoc.context.obj({
8136
9134
  OCGs: allRefs,
8137
9135
  D: {
8138
- BaseState: import_pdf_lib3.PDFName.of("ON"),
9136
+ BaseState: import_pdf_lib4.PDFName.of("ON"),
8139
9137
  ON: onRefs,
8140
9138
  OFF: offRefs,
8141
9139
  Order: allRefs,
@@ -8154,7 +9152,7 @@ function attachEmbeddedFileAttachments(pdfDoc, attachments) {
8154
9152
  const subtypeSafe = (att.mimeType || "application/octet-stream").replace(/\//g, "#2F");
8155
9153
  const efStream = pdfDoc.context.flateStream(fileBytes, {
8156
9154
  Type: "EmbeddedFile",
8157
- Subtype: import_pdf_lib3.PDFName.of(subtypeSafe),
9155
+ Subtype: import_pdf_lib4.PDFName.of(subtypeSafe),
8158
9156
  Params: {
8159
9157
  Size: fileBytes.byteLength
8160
9158
  }
@@ -8162,30 +9160,30 @@ function attachEmbeddedFileAttachments(pdfDoc, attachments) {
8162
9160
  const efRef = pdfDoc.context.register(efStream);
8163
9161
  const filespecObj = {
8164
9162
  Type: "Filespec",
8165
- F: import_pdf_lib3.PDFString.of((att.fileName || "attachment.bin").replace(/[^\x20-\x7E]/g, "_")),
8166
- UF: import_pdf_lib3.PDFHexString.fromText(att.fileName || "attachment.bin"),
9163
+ F: import_pdf_lib4.PDFString.of((att.fileName || "attachment.bin").replace(/[^\x20-\x7E]/g, "_")),
9164
+ UF: import_pdf_lib4.PDFHexString.fromText(att.fileName || "attachment.bin"),
8167
9165
  EF: {
8168
9166
  F: efRef,
8169
9167
  UF: efRef
8170
9168
  }
8171
9169
  };
8172
9170
  if (att.description) {
8173
- filespecObj.Desc = import_pdf_lib3.PDFHexString.fromText(att.description);
9171
+ filespecObj.Desc = import_pdf_lib4.PDFHexString.fromText(att.description);
8174
9172
  }
8175
9173
  const filespecRef = pdfDoc.context.register(pdfDoc.context.obj(filespecObj));
8176
- namesArr.push(import_pdf_lib3.PDFHexString.fromText(att.fileName || "attachment.bin"), filespecRef);
9174
+ namesArr.push(import_pdf_lib4.PDFHexString.fromText(att.fileName || "attachment.bin"), filespecRef);
8177
9175
  }
8178
9176
  const efTreeRef = pdfDoc.context.register(
8179
9177
  pdfDoc.context.obj({
8180
9178
  Names: namesArr
8181
9179
  })
8182
9180
  );
8183
- const existingNames = pdfDoc.context.lookupMaybe(pdfDoc.catalog.get(import_pdf_lib3.PDFName.of("Names")), import_pdf_lib3.PDFDict);
9181
+ const existingNames = pdfDoc.context.lookupMaybe(pdfDoc.catalog.get(import_pdf_lib4.PDFName.of("Names")), import_pdf_lib4.PDFDict);
8184
9182
  if (existingNames) {
8185
- existingNames.set(import_pdf_lib3.PDFName.of("EmbeddedFiles"), efTreeRef);
9183
+ existingNames.set(import_pdf_lib4.PDFName.of("EmbeddedFiles"), efTreeRef);
8186
9184
  } else {
8187
9185
  pdfDoc.catalog.set(
8188
- import_pdf_lib3.PDFName.of("Names"),
9186
+ import_pdf_lib4.PDFName.of("Names"),
8189
9187
  pdfDoc.context.obj({
8190
9188
  EmbeddedFiles: efTreeRef
8191
9189
  })
@@ -8229,7 +9227,7 @@ function attachPdfAComplianceMetadata(pdfDoc, snapshot, includePdfUa) {
8229
9227
  Length: xmpBytes.byteLength
8230
9228
  });
8231
9229
  const metadataRef = pdfDoc.context.register(metadataStream);
8232
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("Metadata"), metadataRef);
9230
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Metadata"), metadataRef);
8233
9231
  const srgbHeaderBytes = new TextEncoder().encode("sRGB IEC61966-2.1 ICC Output Profile");
8234
9232
  const iccStream = pdfDoc.context.flateStream(srgbHeaderBytes, {
8235
9233
  N: 3,
@@ -8240,13 +9238,13 @@ function attachPdfAComplianceMetadata(pdfDoc, snapshot, includePdfUa) {
8240
9238
  pdfDoc.context.obj({
8241
9239
  Type: "OutputIntent",
8242
9240
  S: "GTS_PDFA1",
8243
- OutputConditionIdentifier: import_pdf_lib3.PDFString.of("sRGB IEC61966-2.1"),
8244
- RegistryName: import_pdf_lib3.PDFString.of("http://www.color.org"),
8245
- Info: import_pdf_lib3.PDFString.of("sRGB IEC61966-2.1"),
9241
+ OutputConditionIdentifier: import_pdf_lib4.PDFString.of("sRGB IEC61966-2.1"),
9242
+ RegistryName: import_pdf_lib4.PDFString.of("http://www.color.org"),
9243
+ Info: import_pdf_lib4.PDFString.of("sRGB IEC61966-2.1"),
8246
9244
  DestOutputProfile: iccRef
8247
9245
  })
8248
9246
  );
8249
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("OutputIntents"), pdfDoc.context.obj([outputIntentRef]));
9247
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("OutputIntents"), pdfDoc.context.obj([outputIntentRef]));
8250
9248
  }
8251
9249
  function resolveElementStructRole(el) {
8252
9250
  switch (el.type) {
@@ -8278,9 +9276,9 @@ function resolveElementStructRole(el) {
8278
9276
  }
8279
9277
  }
8280
9278
  function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
8281
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("Lang"), import_pdf_lib3.PDFString.of(snapshot.locale ? String(snapshot.locale) : "zh-CN"));
8282
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("MarkInfo"), pdfDoc.context.obj({ Marked: import_pdf_lib3.PDFBool.True }));
8283
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("ViewerPreferences"), pdfDoc.context.obj({ DisplayDocTitle: import_pdf_lib3.PDFBool.True }));
9279
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("Lang"), import_pdf_lib4.PDFString.of(snapshot.locale ? String(snapshot.locale) : "zh-CN"));
9280
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("MarkInfo"), pdfDoc.context.obj({ Marked: import_pdf_lib4.PDFBool.True }));
9281
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("ViewerPreferences"), pdfDoc.context.obj({ DisplayDocTitle: import_pdf_lib4.PDFBool.True }));
8284
9282
  if (!snapshot.metadata?.sanitized && snapshot.name) {
8285
9283
  pdfDoc.setTitle(snapshot.name);
8286
9284
  }
@@ -8292,16 +9290,16 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
8292
9290
  const elemRef = pdfDoc.context.nextRef();
8293
9291
  const elemDict = {
8294
9292
  Type: "StructElem",
8295
- S: import_pdf_lib3.PDFName.of(item.role),
9293
+ S: import_pdf_lib4.PDFName.of(item.role),
8296
9294
  P: docElemRef,
8297
9295
  Pg: item.pageRef,
8298
- K: import_pdf_lib3.PDFNumber.of(item.mcid)
9296
+ K: import_pdf_lib4.PDFNumber.of(item.mcid)
8299
9297
  };
8300
9298
  if (item.altText) {
8301
- elemDict.Alt = import_pdf_lib3.PDFHexString.fromText(item.altText);
9299
+ elemDict.Alt = import_pdf_lib4.PDFHexString.fromText(item.altText);
8302
9300
  }
8303
9301
  if (item.title) {
8304
- elemDict.T = import_pdf_lib3.PDFHexString.fromText(item.title);
9302
+ elemDict.T = import_pdf_lib4.PDFHexString.fromText(item.title);
8305
9303
  }
8306
9304
  pdfDoc.context.assign(elemRef, pdfDoc.context.obj(elemDict));
8307
9305
  childElemRefs.push(elemRef);
@@ -8316,7 +9314,7 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
8316
9314
  docElemRef,
8317
9315
  pdfDoc.context.obj({
8318
9316
  Type: "StructElem",
8319
- S: import_pdf_lib3.PDFName.of("Document"),
9317
+ S: import_pdf_lib4.PDFName.of("Document"),
8320
9318
  P: structTreeRootRef,
8321
9319
  K: childElemRefs
8322
9320
  })
@@ -8324,7 +9322,7 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
8324
9322
  const numsList = [];
8325
9323
  for (let p = 0; p < totalPages; p++) {
8326
9324
  const refsForPage = (byPageMcid.get(p) ?? []).filter(Boolean);
8327
- numsList.push(import_pdf_lib3.PDFNumber.of(p), pdfDoc.context.obj(refsForPage));
9325
+ numsList.push(import_pdf_lib4.PDFNumber.of(p), pdfDoc.context.obj(refsForPage));
8328
9326
  }
8329
9327
  const parentTreeRef = pdfDoc.context.register(pdfDoc.context.obj({ Nums: numsList }));
8330
9328
  pdfDoc.context.assign(
@@ -8336,14 +9334,14 @@ function attachTaggedStructTreeRoot(pdfDoc, snapshot, items, totalPages) {
8336
9334
  ParentTreeNextKey: totalPages
8337
9335
  })
8338
9336
  );
8339
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("StructTreeRoot"), structTreeRootRef);
9337
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("StructTreeRoot"), structTreeRootRef);
8340
9338
  }
8341
9339
  function pruneUnreferencedObjectsAndCompressStreams(pdfDoc) {
8342
9340
  for (const [ref, obj] of pdfDoc.context.enumerateIndirectObjects()) {
8343
- if (obj instanceof import_pdf_lib3.PDFRawStream) {
8344
- const typeName = obj.dict.get(import_pdf_lib3.PDFName.of("Type"));
8345
- const isMetadata = typeName instanceof import_pdf_lib3.PDFName && typeName.decodeText() === "Metadata";
8346
- const hasFilter = Boolean(obj.dict.get(import_pdf_lib3.PDFName.of("Filter")));
9341
+ if (obj instanceof import_pdf_lib4.PDFRawStream) {
9342
+ const typeName = obj.dict.get(import_pdf_lib4.PDFName.of("Type"));
9343
+ const isMetadata = typeName instanceof import_pdf_lib4.PDFName && typeName.decodeText() === "Metadata";
9344
+ const hasFilter = Boolean(obj.dict.get(import_pdf_lib4.PDFName.of("Filter")));
8347
9345
  if (!isMetadata && !hasFilter && obj.contents.byteLength > 64) {
8348
9346
  const compressed = pdfDoc.context.flateStream(obj.contents);
8349
9347
  for (const [k, v] of obj.dict.entries()) {
@@ -8360,26 +9358,26 @@ function pruneUnreferencedObjectsAndCompressStreams(pdfDoc) {
8360
9358
  const refToString = (r) => `${r.objectNumber}:${r.generationNumber}`;
8361
9359
  const visit = (node) => {
8362
9360
  if (!node) return;
8363
- if (node instanceof import_pdf_lib3.PDFRef) {
9361
+ if (node instanceof import_pdf_lib4.PDFRef) {
8364
9362
  const key = refToString(node);
8365
9363
  if (reachable.has(key)) return;
8366
9364
  reachable.add(key);
8367
9365
  visit(pdfDoc.context.lookup(node));
8368
9366
  return;
8369
9367
  }
8370
- if (node instanceof import_pdf_lib3.PDFDict) {
9368
+ if (node instanceof import_pdf_lib4.PDFDict) {
8371
9369
  for (const [, val] of node.entries()) {
8372
9370
  visit(val);
8373
9371
  }
8374
9372
  return;
8375
9373
  }
8376
- if (node instanceof import_pdf_lib3.PDFArray) {
9374
+ if (node instanceof import_pdf_lib4.PDFArray) {
8377
9375
  for (let i = 0; i < node.size(); i++) {
8378
9376
  visit(node.get(i));
8379
9377
  }
8380
9378
  return;
8381
9379
  }
8382
- if (node instanceof import_pdf_lib3.PDFRawStream || node instanceof import_pdf_lib3.PDFStream) {
9380
+ if (node instanceof import_pdf_lib4.PDFRawStream || node instanceof import_pdf_lib4.PDFStream) {
8383
9381
  visit(node.dict);
8384
9382
  }
8385
9383
  };
@@ -8410,30 +9408,30 @@ async function drawInvisibleSearchableOcrSpans(pdfDoc, pdfPage, pageHeight, span
8410
9408
  const { fontKey } = getOrRegisterPageCjkFontKey(pdfPage, localCjkState);
8411
9409
  const hexStr = encodeVectorCjkLineHex(txt, localCjkState);
8412
9410
  pdfPage.pushOperators(
8413
- (0, import_pdf_lib3.pushGraphicsState)(),
8414
- (0, import_pdf_lib3.beginText)(),
8415
- import_pdf_lib3.PDFOperator.of("Tr", [import_pdf_lib3.PDFNumber.of(3)]),
8416
- (0, import_pdf_lib3.setFontAndSize)(fontKey, fs),
8417
- (0, import_pdf_lib3.moveText)(span.left, baselineY),
8418
- (0, import_pdf_lib3.showText)(import_pdf_lib3.PDFHexString.of(hexStr)),
8419
- (0, import_pdf_lib3.endText)(),
8420
- (0, import_pdf_lib3.popGraphicsState)()
9411
+ (0, import_pdf_lib4.pushGraphicsState)(),
9412
+ (0, import_pdf_lib4.beginText)(),
9413
+ import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(3)]),
9414
+ (0, import_pdf_lib4.setFontAndSize)(fontKey, fs),
9415
+ (0, import_pdf_lib4.moveText)(span.left, baselineY),
9416
+ (0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexStr)),
9417
+ (0, import_pdf_lib4.endText)(),
9418
+ (0, import_pdf_lib4.popGraphicsState)()
8421
9419
  );
8422
9420
  } else {
8423
9421
  if (!helvFont) {
8424
- helvFont = await pdfDoc.embedFont(import_pdf_lib3.StandardFonts.Helvetica);
9422
+ helvFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.Helvetica);
8425
9423
  }
8426
9424
  const fontKey = pdfPage.node.newFontDictionary("FOcr", helvFont.ref);
8427
9425
  const asciiHex = Array.from(txt).map((c) => (c.charCodeAt(0) & 255).toString(16).padStart(2, "0").toUpperCase()).join("");
8428
9426
  pdfPage.pushOperators(
8429
- (0, import_pdf_lib3.pushGraphicsState)(),
8430
- (0, import_pdf_lib3.beginText)(),
8431
- import_pdf_lib3.PDFOperator.of("Tr", [import_pdf_lib3.PDFNumber.of(3)]),
8432
- (0, import_pdf_lib3.setFontAndSize)(fontKey, fs),
8433
- (0, import_pdf_lib3.moveText)(span.left, baselineY),
8434
- (0, import_pdf_lib3.showText)(import_pdf_lib3.PDFHexString.of(asciiHex)),
8435
- (0, import_pdf_lib3.endText)(),
8436
- (0, import_pdf_lib3.popGraphicsState)()
9427
+ (0, import_pdf_lib4.pushGraphicsState)(),
9428
+ (0, import_pdf_lib4.beginText)(),
9429
+ import_pdf_lib4.PDFOperator.of("Tr", [import_pdf_lib4.PDFNumber.of(3)]),
9430
+ (0, import_pdf_lib4.setFontAndSize)(fontKey, fs),
9431
+ (0, import_pdf_lib4.moveText)(span.left, baselineY),
9432
+ (0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(asciiHex)),
9433
+ (0, import_pdf_lib4.endText)(),
9434
+ (0, import_pdf_lib4.popGraphicsState)()
8437
9435
  );
8438
9436
  }
8439
9437
  }
@@ -8502,7 +9500,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8502
9500
  const optimizeSize = Boolean(options?.optimizeSize);
8503
9501
  const preResolvedFonts = await resolveRenderFontsForExport(snapshot, effectiveData, options);
8504
9502
  throwIfExportAborted();
8505
- const pdfDoc = await import_pdf_lib3.PDFDocument.create();
9503
+ const pdfDoc = await import_pdf_lib4.PDFDocument.create();
8506
9504
  if (snapshot.metadata?.sanitized) {
8507
9505
  pdfDoc.setTitle("");
8508
9506
  pdfDoc.setAuthor("");
@@ -8541,7 +9539,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8541
9539
  };
8542
9540
  const ensureAcroHelvetica = async () => {
8543
9541
  if (!acroHelveticaFont) {
8544
- acroHelveticaFont = await getOrEmbedStandardFont(pdfDoc, import_pdf_lib3.StandardFonts.Helvetica);
9542
+ acroHelveticaFont = await getOrEmbedStandardFont(pdfDoc, import_pdf_lib4.StandardFonts.Helvetica);
8545
9543
  }
8546
9544
  return acroHelveticaFont;
8547
9545
  };
@@ -8702,7 +9700,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8702
9700
  if (!excludeBasePdf && snapshot.sourceDocumentRef?.dataUri) {
8703
9701
  try {
8704
9702
  const srcBytes = dataUriToBytes(snapshot.sourceDocumentRef.dataUri);
8705
- sourcePdfDoc = await import_pdf_lib3.PDFDocument.load(srcBytes);
9703
+ sourcePdfDoc = await import_pdf_lib4.PDFDocument.load(srcBytes);
8706
9704
  } catch {
8707
9705
  sourcePdfDoc = null;
8708
9706
  }
@@ -8916,21 +9914,21 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8916
9914
  const [copied] = await pdfDoc.copyPages(sourcePdfDoc, [pageMeta.sourcePageNumber - 1]);
8917
9915
  pdfPage = pdfDoc.addPage(copied);
8918
9916
  if (snapshot.metadata?.importedAcroFormBase) {
8919
- const existingAnnots = pdfDoc.context.lookupMaybe(pdfPage.node.get(import_pdf_lib3.PDFName.of("Annots")), import_pdf_lib3.PDFArray);
9917
+ const existingAnnots = pdfDoc.context.lookupMaybe(pdfPage.node.get(import_pdf_lib4.PDFName.of("Annots")), import_pdf_lib4.PDFArray);
8920
9918
  if (existingAnnots) {
8921
9919
  const filtered = [];
8922
9920
  for (let ai = 0; ai < existingAnnots.size(); ai++) {
8923
9921
  const aRef = existingAnnots.get(ai);
8924
- const aDict = pdfDoc.context.lookupMaybe(aRef, import_pdf_lib3.PDFDict);
8925
- const sub = aDict?.get(import_pdf_lib3.PDFName.of("Subtype"));
8926
- if (!(sub instanceof import_pdf_lib3.PDFName && sub.decodeText() === "Widget")) {
9922
+ const aDict = pdfDoc.context.lookupMaybe(aRef, import_pdf_lib4.PDFDict);
9923
+ const sub = aDict?.get(import_pdf_lib4.PDFName.of("Subtype"));
9924
+ if (!(sub instanceof import_pdf_lib4.PDFName && sub.decodeText() === "Widget")) {
8927
9925
  filtered.push(aRef);
8928
9926
  }
8929
9927
  }
8930
9928
  if (filtered.length > 0) {
8931
- pdfPage.node.set(import_pdf_lib3.PDFName.of("Annots"), pdfDoc.context.obj(filtered));
9929
+ pdfPage.node.set(import_pdf_lib4.PDFName.of("Annots"), pdfDoc.context.obj(filtered));
8932
9930
  } else {
8933
- pdfPage.node.delete(import_pdf_lib3.PDFName.of("Annots"));
9931
+ pdfPage.node.delete(import_pdf_lib4.PDFName.of("Annots"));
8934
9932
  }
8935
9933
  }
8936
9934
  }
@@ -8941,7 +9939,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8941
9939
  let size = pageMeta.pageSize ?? snapshot.document.pageSize;
8942
9940
  if (excludeBasePdf && snapshot.sourceDocumentRef?.dataUri && !pageMeta.pageSize) {
8943
9941
  try {
8944
- const tempSrc = await import_pdf_lib3.PDFDocument.load(dataUriToBytes(snapshot.sourceDocumentRef.dataUri));
9942
+ const tempSrc = await import_pdf_lib4.PDFDocument.load(dataUriToBytes(snapshot.sourceDocumentRef.dataUri));
8945
9943
  const pIdx0 = Math.max(0, (pageMeta.sourcePageNumber ?? 1) - 1);
8946
9944
  if (pIdx0 < tempSrc.getPageCount()) {
8947
9945
  const refSz = tempSrc.getPage(pIdx0).getSize();
@@ -8958,14 +9956,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8958
9956
  y: 0,
8959
9957
  width: size.width,
8960
9958
  height: size.height,
8961
- color: (0, import_pdf_lib3.rgb)(bgColor.r, bgColor.g, bgColor.b)
9959
+ color: (0, import_pdf_lib4.rgb)(bgColor.r, bgColor.g, bgColor.b)
8962
9960
  });
8963
9961
  }
8964
9962
  }
8965
9963
  const pageHeight = pdfPage.getHeight();
8966
9964
  const pageWidth = pdfPage.getWidth();
8967
9965
  if (pageMeta.rotation !== void 0) {
8968
- pdfPage.setRotation((0, import_pdf_lib3.degrees)(pageMeta.rotation));
9966
+ pdfPage.setRotation((0, import_pdf_lib4.degrees)(pageMeta.rotation));
8969
9967
  }
8970
9968
  if (pageMeta.cropBox) {
8971
9969
  const cb = pageMeta.cropBox;
@@ -8979,14 +9977,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
8979
9977
  y: pageHeight - sRect.top - sRect.height,
8980
9978
  width: sRect.width,
8981
9979
  height: sRect.height,
8982
- color: (0, import_pdf_lib3.rgb)(1, 1, 1),
9980
+ color: (0, import_pdf_lib4.rgb)(1, 1, 1),
8983
9981
  borderWidth: 0
8984
9982
  });
8985
9983
  }
8986
9984
  }
8987
9985
  if (accessibilityTagged) {
8988
- pdfPage.node.set(import_pdf_lib3.PDFName.of("StructParents"), import_pdf_lib3.PDFNumber.of(pIndex));
8989
- pdfPage.node.set(import_pdf_lib3.PDFName.of("Tabs"), import_pdf_lib3.PDFName.of("S"));
9986
+ pdfPage.node.set(import_pdf_lib4.PDFName.of("StructParents"), import_pdf_lib4.PDFNumber.of(pIndex));
9987
+ pdfPage.node.set(import_pdf_lib4.PDFName.of("Tabs"), import_pdf_lib4.PDFName.of("S"));
8990
9988
  }
8991
9989
  let nextPageMcid = 0;
8992
9990
  const activeDynamicRange = planItem.dynamicSplitRanges ? planItem.dynamicSplitRanges[chunkIndex] : void 0;
@@ -9041,9 +10039,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9041
10039
  let hasOpenCenterTransform = false;
9042
10040
  if (ocgEntry) {
9043
10041
  const propsDict = ensurePagePropertiesDict(pdfDoc, pdfPage);
9044
- propsDict.set(import_pdf_lib3.PDFName.of(ocgEntry.propName), ocgEntry.ocgRef);
10042
+ propsDict.set(import_pdf_lib4.PDFName.of(ocgEntry.propName), ocgEntry.ocgRef);
9045
10043
  pdfPage.pushOperators(
9046
- import_pdf_lib3.PDFOperator.of("BDC", [import_pdf_lib3.PDFName.of("OC"), import_pdf_lib3.PDFName.of(ocgEntry.propName)])
10044
+ import_pdf_lib4.PDFOperator.of("BDC", [import_pdf_lib4.PDFName.of("OC"), import_pdf_lib4.PDFName.of(ocgEntry.propName)])
9047
10045
  );
9048
10046
  openBdcCount++;
9049
10047
  }
@@ -9051,10 +10049,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9051
10049
  const mcid = nextPageMcid++;
9052
10050
  const mcPropName = `MC_${mcid}`;
9053
10051
  const propsDict = ensurePagePropertiesDict(pdfDoc, pdfPage);
9054
- propsDict.set(import_pdf_lib3.PDFName.of(mcPropName), pdfDoc.context.obj({ MCID: import_pdf_lib3.PDFNumber.of(mcid) }));
10052
+ propsDict.set(import_pdf_lib4.PDFName.of(mcPropName), pdfDoc.context.obj({ MCID: import_pdf_lib4.PDFNumber.of(mcid) }));
9055
10053
  const role = resolveElementStructRole(el);
9056
10054
  pdfPage.pushOperators(
9057
- import_pdf_lib3.PDFOperator.of("BDC", [import_pdf_lib3.PDFName.of(role), import_pdf_lib3.PDFName.of(mcPropName)])
10055
+ import_pdf_lib4.PDFOperator.of("BDC", [import_pdf_lib4.PDFName.of(role), import_pdf_lib4.PDFName.of(mcPropName)])
9058
10056
  );
9059
10057
  openBdcCount++;
9060
10058
  taggedStructItems.push({
@@ -9103,8 +10101,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9103
10101
  ) : null;
9104
10102
  if (centerMatrix) {
9105
10103
  pdfPage.pushOperators(
9106
- (0, import_pdf_lib3.pushGraphicsState)(),
9107
- (0, import_pdf_lib3.concatTransformationMatrix)(
10104
+ (0, import_pdf_lib4.pushGraphicsState)(),
10105
+ (0, import_pdf_lib4.concatTransformationMatrix)(
9108
10106
  centerMatrix[0],
9109
10107
  centerMatrix[1],
9110
10108
  centerMatrix[2],
@@ -9384,9 +10382,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9384
10382
  if (isMultiline) {
9385
10383
  tf.enableMultiline();
9386
10384
  }
9387
- if (textEl.style?.textAlign === "center") tf.setAlignment(import_pdf_lib3.TextAlignment.Center);
9388
- else if (textEl.style?.textAlign === "right") tf.setAlignment(import_pdf_lib3.TextAlignment.Right);
9389
- else tf.setAlignment(import_pdf_lib3.TextAlignment.Left);
10385
+ if (textEl.style?.textAlign === "center") tf.setAlignment(import_pdf_lib4.TextAlignment.Center);
10386
+ else if (textEl.style?.textAlign === "right") tf.setAlignment(import_pdf_lib4.TextAlignment.Right);
10387
+ else tf.setAlignment(import_pdf_lib4.TextAlignment.Left);
9390
10388
  const bg = parseHexColor(textEl.style?.backgroundColor) ?? { r: 1, g: 1, b: 1, a: 1 };
9391
10389
  const border = parseHexColor(textEl.style?.borderColor) ?? { r: 0.75, g: 0.82, b: 0.9, a: 1 };
9392
10390
  const txtCol = parseHexColor(textEl.style?.color) ?? { r: 0.12, g: 0.14, b: 0.16, a: 1 };
@@ -9397,11 +10395,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9397
10395
  y: pdfY,
9398
10396
  width,
9399
10397
  height,
9400
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10398
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9401
10399
  borderWidth: textEl.style?.borderWidth ?? 1,
9402
- borderColor: (0, import_pdf_lib3.rgb)(border.r, border.g, border.b),
9403
- backgroundColor: (0, import_pdf_lib3.rgb)(bg.r, bg.g, bg.b),
9404
- textColor: (0, import_pdf_lib3.rgb)(txtCol.r, txtCol.g, txtCol.b)
10400
+ borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
10401
+ backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
10402
+ textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
9405
10403
  });
9406
10404
  if (resolved) {
9407
10405
  tf.setText(resolved);
@@ -9409,9 +10407,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9409
10407
  if (textEl.locked) tf.enableReadOnly();
9410
10408
  if (textEl.required) tf.enableRequired();
9411
10409
  tf.acroField.dict.set(
9412
- import_pdf_lib3.PDFName.of("YudaoMeta"),
10410
+ import_pdf_lib4.PDFName.of("YudaoMeta"),
9413
10411
  pdfDoc.context.obj({
9414
- ElementType: import_pdf_lib3.PDFName.of("text"),
10412
+ ElementType: import_pdf_lib4.PDFName.of("text"),
9415
10413
  Left: left,
9416
10414
  Top: top,
9417
10415
  Width: width,
@@ -9431,10 +10429,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9431
10429
  txtCol
9432
10430
  });
9433
10431
  const daStr = `/FCjk ${fmtPdfNum(fsVal)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
9434
- tf.acroField.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10432
+ tf.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9435
10433
  for (const w of tf.acroField.getWidgets()) {
9436
- w.dict.set(import_pdf_lib3.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
9437
- w.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10434
+ w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
10435
+ w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9438
10436
  }
9439
10437
  } else {
9440
10438
  tf.defaultUpdateAppearances(await ensureAcroHelvetica());
@@ -9578,23 +10576,23 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9578
10576
  };
9579
10577
  const strokeOp = elColorType === "cmyk" ? (() => {
9580
10578
  const cm = rgbToCmyk(strokeCol.r, strokeCol.g, strokeCol.b);
9581
- return (0, import_pdf_lib3.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
9582
- })() : (0, import_pdf_lib3.setStrokingRgbColor)(strokeCol.r, strokeCol.g, strokeCol.b);
10579
+ return (0, import_pdf_lib4.setStrokingCmykColor)(cm.c, cm.m, cm.y, cm.k);
10580
+ })() : (0, import_pdf_lib4.setStrokingRgbColor)(strokeCol.r, strokeCol.g, strokeCol.b);
9583
10581
  const ellipse = computeCircleMarkBezierEllipse(
9584
10582
  { x: left, y: pdfY, width, height },
9585
10583
  cmEl.strokeWidthMm ?? 0.6
9586
10584
  );
9587
10585
  pdfPage.pushOperators(
9588
- (0, import_pdf_lib3.pushGraphicsState)(),
10586
+ (0, import_pdf_lib4.pushGraphicsState)(),
9589
10587
  strokeOp,
9590
- (0, import_pdf_lib3.setLineWidth)(ellipse.strokeWidthPt),
9591
- (0, import_pdf_lib3.moveTo)(ellipse.start[0], ellipse.start[1]),
10588
+ (0, import_pdf_lib4.setLineWidth)(ellipse.strokeWidthPt),
10589
+ (0, import_pdf_lib4.moveTo)(ellipse.start[0], ellipse.start[1]),
9592
10590
  ...ellipse.segments.map(
9593
- ([x1, y1, x2, y2, x3, y3]) => (0, import_pdf_lib3.appendBezierCurve)(x1, y1, x2, y2, x3, y3)
10591
+ ([x1, y1, x2, y2, x3, y3]) => (0, import_pdf_lib4.appendBezierCurve)(x1, y1, x2, y2, x3, y3)
9594
10592
  ),
9595
- (0, import_pdf_lib3.closePath)(),
9596
- (0, import_pdf_lib3.stroke)(),
9597
- (0, import_pdf_lib3.popGraphicsState)()
10593
+ (0, import_pdf_lib4.closePath)(),
10594
+ (0, import_pdf_lib4.stroke)(),
10595
+ (0, import_pdf_lib4.popGraphicsState)()
9598
10596
  );
9599
10597
  }
9600
10598
  } else if (el.type === "dateTime" /* DATE_TIME */) {
@@ -9615,9 +10613,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9615
10613
  usedAcroFieldNames
9616
10614
  );
9617
10615
  const tf = form.createTextField(fieldName);
9618
- if (dtAlign === "center") tf.setAlignment(import_pdf_lib3.TextAlignment.Center);
9619
- else if (dtAlign === "right") tf.setAlignment(import_pdf_lib3.TextAlignment.Right);
9620
- else tf.setAlignment(import_pdf_lib3.TextAlignment.Left);
10616
+ if (dtAlign === "center") tf.setAlignment(import_pdf_lib4.TextAlignment.Center);
10617
+ else if (dtAlign === "right") tf.setAlignment(import_pdf_lib4.TextAlignment.Right);
10618
+ else tf.setAlignment(import_pdf_lib4.TextAlignment.Left);
9621
10619
  const bg = parseHexColor(dtBgHex) ?? { r: 1, g: 1, b: 1, a: 1 };
9622
10620
  const border = parseHexColor(dtEl.style?.borderColor) ?? { r: 0.75, g: 0.82, b: 0.9, a: 1 };
9623
10621
  const txtCol = parseHexColor(dtColorHex) ?? { r: 0.11, g: 0.11, b: 0.12, a: 1 };
@@ -9627,11 +10625,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9627
10625
  y: pdfY,
9628
10626
  width,
9629
10627
  height,
9630
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10628
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9631
10629
  borderWidth: dtEl.style?.borderWidth ?? 1,
9632
- borderColor: (0, import_pdf_lib3.rgb)(border.r, border.g, border.b),
9633
- backgroundColor: (0, import_pdf_lib3.rgb)(bg.r, bg.g, bg.b),
9634
- textColor: (0, import_pdf_lib3.rgb)(txtCol.r, txtCol.g, txtCol.b)
10630
+ borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
10631
+ backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
10632
+ textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
9635
10633
  });
9636
10634
  if (formattedDt) {
9637
10635
  tf.setText(formattedDt);
@@ -9639,21 +10637,21 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9639
10637
  if (dtEl.locked) tf.enableReadOnly();
9640
10638
  if (dtEl.required) tf.enableRequired();
9641
10639
  tf.acroField.dict.set(
9642
- import_pdf_lib3.PDFName.of("TU"),
9643
- import_pdf_lib3.PDFHexString.fromText(
10640
+ import_pdf_lib4.PDFName.of("TU"),
10641
+ import_pdf_lib4.PDFHexString.fromText(
9644
10642
  `dateTime:${dtEl.dateKind || "date"}|${dtEl.format || "YYYY-MM-DD"}|${dtEl.locale || ""}`
9645
10643
  )
9646
10644
  );
9647
10645
  tf.acroField.dict.set(
9648
- import_pdf_lib3.PDFName.of("YudaoMeta"),
10646
+ import_pdf_lib4.PDFName.of("YudaoMeta"),
9649
10647
  pdfDoc.context.obj({
9650
- ElementType: import_pdf_lib3.PDFName.of("dateTime"),
9651
- DateKind: import_pdf_lib3.PDFString.of(dtEl.dateKind || "date"),
9652
- Format: import_pdf_lib3.PDFHexString.fromText(dtEl.format || "YYYY-MM-DD"),
9653
- ...dtEl.locale ? { Locale: import_pdf_lib3.PDFString.of(dtEl.locale) } : {},
9654
- RawValue: import_pdf_lib3.PDFHexString.fromText(rawDtVal),
10648
+ ElementType: import_pdf_lib4.PDFName.of("dateTime"),
10649
+ DateKind: import_pdf_lib4.PDFString.of(dtEl.dateKind || "date"),
10650
+ Format: import_pdf_lib4.PDFHexString.fromText(dtEl.format || "YYYY-MM-DD"),
10651
+ ...dtEl.locale ? { Locale: import_pdf_lib4.PDFString.of(dtEl.locale) } : {},
10652
+ RawValue: import_pdf_lib4.PDFHexString.fromText(rawDtVal),
9655
10653
  FontSize: dtFontSize,
9656
- Align: import_pdf_lib3.PDFString.of(dtAlign),
10654
+ Align: import_pdf_lib4.PDFString.of(dtAlign),
9657
10655
  ...dtEl.characterSpacing !== void 0 ? { CharacterSpacing: dtEl.characterSpacing } : {},
9658
10656
  Left: left,
9659
10657
  Top: top,
@@ -9674,10 +10672,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9674
10672
  txtCol
9675
10673
  });
9676
10674
  const daStr = `/FCjk ${fmtPdfNum(dtFontSize)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
9677
- tf.acroField.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10675
+ tf.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9678
10676
  for (const w of tf.acroField.getWidgets()) {
9679
- w.dict.set(import_pdf_lib3.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
9680
- w.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10677
+ w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
10678
+ w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9681
10679
  }
9682
10680
  } else {
9683
10681
  tf.defaultUpdateAppearances(await ensureAcroHelvetica());
@@ -9729,10 +10727,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9729
10727
  y: pdfY + (height - boxSz) / 2,
9730
10728
  width: boxSz,
9731
10729
  height: boxSz,
9732
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10730
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9733
10731
  borderWidth: 1,
9734
- borderColor: (0, import_pdf_lib3.rgb)(0.28, 0.33, 0.41),
9735
- backgroundColor: (0, import_pdf_lib3.rgb)(1, 1, 1)
10732
+ borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
10733
+ backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
9736
10734
  });
9737
10735
  if (isChecked) cb.check();
9738
10736
  else cb.uncheck();
@@ -9740,14 +10738,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9740
10738
  if (cbEl.required) cb.enableRequired();
9741
10739
  cb.defaultUpdateAppearances();
9742
10740
  cb.acroField.dict.set(
9743
- import_pdf_lib3.PDFName.of("TU"),
9744
- import_pdf_lib3.PDFHexString.fromText(cbEl.label || fieldName)
10741
+ import_pdf_lib4.PDFName.of("TU"),
10742
+ import_pdf_lib4.PDFHexString.fromText(cbEl.label || fieldName)
9745
10743
  );
9746
10744
  cb.acroField.dict.set(
9747
- import_pdf_lib3.PDFName.of("YudaoMeta"),
10745
+ import_pdf_lib4.PDFName.of("YudaoMeta"),
9748
10746
  pdfDoc.context.obj({
9749
- ElementType: import_pdf_lib3.PDFName.of("checkbox"),
9750
- Label: import_pdf_lib3.PDFHexString.fromText(cbEl.label || ""),
10747
+ ElementType: import_pdf_lib4.PDFName.of("checkbox"),
10748
+ Label: import_pdf_lib4.PDFHexString.fromText(cbEl.label || ""),
9751
10749
  BoxWidth: boxSz,
9752
10750
  Left: left,
9753
10751
  Top: top,
@@ -9777,8 +10775,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9777
10775
  y: pdfY + (height - boxSz) / 2,
9778
10776
  width: boxSz,
9779
10777
  height: boxSz,
9780
- color: isChecked ? (0, import_pdf_lib3.rgb)(0.15, 0.39, 0.92) : (0, import_pdf_lib3.rgb)(1, 1, 1),
9781
- borderColor: (0, import_pdf_lib3.rgb)(0.28, 0.33, 0.41),
10778
+ color: isChecked ? (0, import_pdf_lib4.rgb)(0.15, 0.39, 0.92) : (0, import_pdf_lib4.rgb)(1, 1, 1),
10779
+ borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
9782
10780
  borderWidth: 1
9783
10781
  });
9784
10782
  await drawTextBox(
@@ -9823,10 +10821,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9823
10821
  y: btnY,
9824
10822
  width: btnSz,
9825
10823
  height: btnSz,
9826
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10824
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9827
10825
  borderWidth: 1,
9828
- borderColor: (0, import_pdf_lib3.rgb)(0.28, 0.33, 0.41),
9829
- backgroundColor: (0, import_pdf_lib3.rgb)(1, 1, 1)
10826
+ borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
10827
+ backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
9830
10828
  });
9831
10829
  await drawTextBox(
9832
10830
  pdfDoc,
@@ -9851,10 +10849,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9851
10849
  y: btnY,
9852
10850
  width: btnSz,
9853
10851
  height: btnSz,
9854
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10852
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9855
10853
  borderWidth: 1,
9856
- borderColor: (0, import_pdf_lib3.rgb)(0.28, 0.33, 0.41),
9857
- backgroundColor: (0, import_pdf_lib3.rgb)(1, 1, 1)
10854
+ borderColor: (0, import_pdf_lib4.rgb)(0.28, 0.33, 0.41),
10855
+ backgroundColor: (0, import_pdf_lib4.rgb)(1, 1, 1)
9858
10856
  });
9859
10857
  await drawTextBox(
9860
10858
  pdfDoc,
@@ -9878,10 +10876,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9878
10876
  if (rgEl.required) rg.enableRequired();
9879
10877
  rg.defaultUpdateAppearances();
9880
10878
  rg.acroField.dict.set(
9881
- import_pdf_lib3.PDFName.of("YudaoMeta"),
10879
+ import_pdf_lib4.PDFName.of("YudaoMeta"),
9882
10880
  pdfDoc.context.obj({
9883
- ElementType: import_pdf_lib3.PDFName.of("radioGroup"),
9884
- Direction: import_pdf_lib3.PDFString.of(rgEl.direction || "horizontal"),
10881
+ ElementType: import_pdf_lib4.PDFName.of("radioGroup"),
10882
+ Direction: import_pdf_lib4.PDFString.of(rgEl.direction || "horizontal"),
9885
10883
  Left: left,
9886
10884
  Top: top,
9887
10885
  Width: width,
@@ -9937,11 +10935,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9937
10935
  y: pdfY,
9938
10936
  width,
9939
10937
  height,
9940
- rotate: (0, import_pdf_lib3.degrees)(rotDeg),
10938
+ rotate: (0, import_pdf_lib4.degrees)(rotDeg),
9941
10939
  borderWidth: selEl.style?.borderWidth ?? 1,
9942
- borderColor: (0, import_pdf_lib3.rgb)(border.r, border.g, border.b),
9943
- backgroundColor: (0, import_pdf_lib3.rgb)(bg.r, bg.g, bg.b),
9944
- textColor: (0, import_pdf_lib3.rgb)(txtCol.r, txtCol.g, txtCol.b)
10940
+ borderColor: (0, import_pdf_lib4.rgb)(border.r, border.g, border.b),
10941
+ backgroundColor: (0, import_pdf_lib4.rgb)(bg.r, bg.g, bg.b),
10942
+ textColor: (0, import_pdf_lib4.rgb)(txtCol.r, txtCol.g, txtCol.b)
9945
10943
  });
9946
10944
  if (curVal && baseOpts.includes(curVal)) {
9947
10945
  dd.select(curVal);
@@ -9949,10 +10947,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9949
10947
  if (selEl.locked) dd.enableReadOnly();
9950
10948
  if (selEl.required) dd.enableRequired();
9951
10949
  dd.acroField.dict.set(
9952
- import_pdf_lib3.PDFName.of("YudaoMeta"),
10950
+ import_pdf_lib4.PDFName.of("YudaoMeta"),
9953
10951
  pdfDoc.context.obj({
9954
- ElementType: import_pdf_lib3.PDFName.of("select"),
9955
- ...selEl.placeholder ? { Placeholder: import_pdf_lib3.PDFHexString.fromText(selEl.placeholder) } : {},
10952
+ ElementType: import_pdf_lib4.PDFName.of("select"),
10953
+ ...selEl.placeholder ? { Placeholder: import_pdf_lib4.PDFHexString.fromText(selEl.placeholder) } : {},
9956
10954
  Left: left,
9957
10955
  Top: top,
9958
10956
  Width: width,
@@ -9972,10 +10970,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
9972
10970
  txtCol
9973
10971
  });
9974
10972
  const daStr = `/FCjk ${fmtPdfNum(fsVal)} Tf ${fmtPdfNum(txtCol.r)} ${fmtPdfNum(txtCol.g)} ${fmtPdfNum(txtCol.b)} rg`;
9975
- dd.acroField.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10973
+ dd.acroField.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9976
10974
  for (const w of dd.acroField.getWidgets()) {
9977
- w.dict.set(import_pdf_lib3.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
9978
- w.dict.set(import_pdf_lib3.PDFName.of("DA"), import_pdf_lib3.PDFString.of(daStr));
10975
+ w.dict.set(import_pdf_lib4.PDFName.of("AP"), pdfDoc.context.obj({ N: apRef }));
10976
+ w.dict.set(import_pdf_lib4.PDFName.of("DA"), import_pdf_lib4.PDFString.of(daStr));
9979
10977
  }
9980
10978
  } else {
9981
10979
  dd.defaultUpdateAppearances(await ensureAcroHelvetica());
@@ -10015,8 +11013,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10015
11013
  Type: "Annot",
10016
11014
  Subtype: "Widget",
10017
11015
  FT: "Sig",
10018
- T: import_pdf_lib3.PDFHexString.fromText(fieldName),
10019
- TU: import_pdf_lib3.PDFHexString.fromText(sigEl.label || fieldName),
11016
+ T: import_pdf_lib4.PDFHexString.fromText(fieldName),
11017
+ TU: import_pdf_lib4.PDFHexString.fromText(sigEl.label || fieldName),
10020
11018
  Rect: [left, pdfY, left + width, pdfY + height],
10021
11019
  P: pdfPage.ref,
10022
11020
  F: 4,
@@ -10024,12 +11022,12 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10024
11022
  AP: { N: sigApRef },
10025
11023
  MK: { R: rotDeg },
10026
11024
  YudaoMeta: {
10027
- ElementType: import_pdf_lib3.PDFName.of("signature"),
10028
- Label: import_pdf_lib3.PDFHexString.fromText(sigEl.label || "Signature"),
10029
- ...sigEl.signerName ? { SignerName: import_pdf_lib3.PDFHexString.fromText(sigEl.signerName) } : {},
10030
- ...sigEl.signedAt ? { SignedAt: import_pdf_lib3.PDFString.of(sigEl.signedAt) } : {},
10031
- ...sigEl.reason ? { Reason: import_pdf_lib3.PDFHexString.fromText(sigEl.reason) } : {},
10032
- ...sigEl.signatureDataUri ? { SignatureDataUri: import_pdf_lib3.PDFString.of(sigEl.signatureDataUri) } : {},
11025
+ ElementType: import_pdf_lib4.PDFName.of("signature"),
11026
+ Label: import_pdf_lib4.PDFHexString.fromText(sigEl.label || "Signature"),
11027
+ ...sigEl.signerName ? { SignerName: import_pdf_lib4.PDFHexString.fromText(sigEl.signerName) } : {},
11028
+ ...sigEl.signedAt ? { SignedAt: import_pdf_lib4.PDFString.of(sigEl.signedAt) } : {},
11029
+ ...sigEl.reason ? { Reason: import_pdf_lib4.PDFHexString.fromText(sigEl.reason) } : {},
11030
+ ...sigEl.signatureDataUri ? { SignatureDataUri: import_pdf_lib4.PDFString.of(sigEl.signatureDataUri) } : {},
10033
11031
  Left: left,
10034
11032
  Top: top,
10035
11033
  Width: width,
@@ -10040,11 +11038,11 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10040
11038
  if (sigEl.signerName || sigEl.signatureDataUri) {
10041
11039
  sigWidgetObj.V = pdfDoc.context.obj({
10042
11040
  Type: "Sig",
10043
- Filter: import_pdf_lib3.PDFName.of("Adobe.PPKLite"),
10044
- SubFilter: import_pdf_lib3.PDFName.of("adbe.pkcs7.detached"),
10045
- Name: import_pdf_lib3.PDFHexString.fromText(sigEl.signerName || sigEl.label || "Signed"),
10046
- ...sigEl.signedAt ? { M: import_pdf_lib3.PDFString.of(sigEl.signedAt) } : {},
10047
- ...sigEl.reason ? { Reason: import_pdf_lib3.PDFHexString.fromText(sigEl.reason) } : {}
11041
+ Filter: import_pdf_lib4.PDFName.of("Adobe.PPKLite"),
11042
+ SubFilter: import_pdf_lib4.PDFName.of("adbe.pkcs7.detached"),
11043
+ Name: import_pdf_lib4.PDFHexString.fromText(sigEl.signerName || sigEl.label || "Signed"),
11044
+ ...sigEl.signedAt ? { M: import_pdf_lib4.PDFString.of(sigEl.signedAt) } : {},
11045
+ ...sigEl.reason ? { Reason: import_pdf_lib4.PDFHexString.fromText(sigEl.reason) } : {}
10048
11046
  });
10049
11047
  }
10050
11048
  const sigRef = pdfDoc.context.register(pdfDoc.context.obj(sigWidgetObj));
@@ -10056,8 +11054,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10056
11054
  y: pdfY,
10057
11055
  width,
10058
11056
  height,
10059
- color: (0, import_pdf_lib3.rgb)(0.98, 0.985, 0.995),
10060
- borderColor: (0, import_pdf_lib3.rgb)(0.55, 0.62, 0.72),
11057
+ color: (0, import_pdf_lib4.rgb)(0.98, 0.985, 0.995),
11058
+ borderColor: (0, import_pdf_lib4.rgb)(0.55, 0.62, 0.72),
10061
11059
  borderWidth: 0.9,
10062
11060
  borderDashArray: sigEl.signerName || sigEl.signatureDataUri ? void 0 : [3, 2]
10063
11061
  });
@@ -10065,7 +11063,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10065
11063
  start: { x: left + 6, y: pdfY + 8 },
10066
11064
  end: { x: left + Math.max(12, width - 6), y: pdfY + 8 },
10067
11065
  thickness: 0.65,
10068
- color: (0, import_pdf_lib3.rgb)(0.45, 0.52, 0.62)
11066
+ color: (0, import_pdf_lib4.rgb)(0.45, 0.52, 0.62)
10069
11067
  });
10070
11068
  if (sigEl.signatureDataUri) {
10071
11069
  const sigImgEntry = await embedImageWithMetaFromSrc(pdfDoc, sigEl.signatureDataUri);
@@ -10137,13 +11135,13 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10137
11135
  drawH
10138
11136
  );
10139
11137
  pdfPage.pushOperators(
10140
- (0, import_pdf_lib3.pushGraphicsState)(),
10141
- (0, import_pdf_lib3.rectangle)(clipX, clipY, clipW, clipH),
10142
- (0, import_pdf_lib3.clip)(),
10143
- (0, import_pdf_lib3.endPath)(),
10144
- (0, import_pdf_lib3.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
10145
- (0, import_pdf_lib3.drawObject)(imgKey),
10146
- (0, import_pdf_lib3.popGraphicsState)()
11138
+ (0, import_pdf_lib4.pushGraphicsState)(),
11139
+ (0, import_pdf_lib4.rectangle)(clipX, clipY, clipW, clipH),
11140
+ (0, import_pdf_lib4.clip)(),
11141
+ (0, import_pdf_lib4.endPath)(),
11142
+ (0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
11143
+ (0, import_pdf_lib4.drawObject)(imgKey),
11144
+ (0, import_pdf_lib4.popGraphicsState)()
10147
11145
  );
10148
11146
  } else if (img && exifOrientation !== 1) {
10149
11147
  const fitMode = el.fit ?? "contain";
@@ -10167,20 +11165,20 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10167
11165
  );
10168
11166
  if (placement2.needsClip) {
10169
11167
  pdfPage.pushOperators(
10170
- (0, import_pdf_lib3.pushGraphicsState)(),
10171
- (0, import_pdf_lib3.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
10172
- (0, import_pdf_lib3.clip)(),
10173
- (0, import_pdf_lib3.endPath)(),
10174
- (0, import_pdf_lib3.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
10175
- (0, import_pdf_lib3.drawObject)(imgKey),
10176
- (0, import_pdf_lib3.popGraphicsState)()
11168
+ (0, import_pdf_lib4.pushGraphicsState)(),
11169
+ (0, import_pdf_lib4.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
11170
+ (0, import_pdf_lib4.clip)(),
11171
+ (0, import_pdf_lib4.endPath)(),
11172
+ (0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
11173
+ (0, import_pdf_lib4.drawObject)(imgKey),
11174
+ (0, import_pdf_lib4.popGraphicsState)()
10177
11175
  );
10178
11176
  } else {
10179
11177
  pdfPage.pushOperators(
10180
- (0, import_pdf_lib3.pushGraphicsState)(),
10181
- (0, import_pdf_lib3.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
10182
- (0, import_pdf_lib3.drawObject)(imgKey),
10183
- (0, import_pdf_lib3.popGraphicsState)()
11178
+ (0, import_pdf_lib4.pushGraphicsState)(),
11179
+ (0, import_pdf_lib4.concatTransformationMatrix)(ma, mb, mc, md, me, mf),
11180
+ (0, import_pdf_lib4.drawObject)(imgKey),
11181
+ (0, import_pdf_lib4.popGraphicsState)()
10184
11182
  );
10185
11183
  }
10186
11184
  } else if (img) {
@@ -10194,10 +11192,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10194
11192
  );
10195
11193
  if (placement2.needsClip) {
10196
11194
  pdfPage.pushOperators(
10197
- (0, import_pdf_lib3.pushGraphicsState)(),
10198
- (0, import_pdf_lib3.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
10199
- (0, import_pdf_lib3.clip)(),
10200
- (0, import_pdf_lib3.endPath)()
11195
+ (0, import_pdf_lib4.pushGraphicsState)(),
11196
+ (0, import_pdf_lib4.rectangle)(placement2.clipX, placement2.clipY, placement2.clipWidth, placement2.clipHeight),
11197
+ (0, import_pdf_lib4.clip)(),
11198
+ (0, import_pdf_lib4.endPath)()
10201
11199
  );
10202
11200
  pdfPage.drawImage(img, {
10203
11201
  x: placement2.drawX,
@@ -10206,7 +11204,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10206
11204
  height: placement2.drawHeight,
10207
11205
  opacity: el.opacity
10208
11206
  });
10209
- pdfPage.pushOperators((0, import_pdf_lib3.popGraphicsState)());
11207
+ pdfPage.pushOperators((0, import_pdf_lib4.popGraphicsState)());
10210
11208
  } else {
10211
11209
  pdfPage.drawImage(img, {
10212
11210
  x: placement2.drawX,
@@ -10296,7 +11294,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10296
11294
  y: pdfY,
10297
11295
  width,
10298
11296
  height,
10299
- color: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b),
11297
+ color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
10300
11298
  opacity: op,
10301
11299
  borderWidth: 0
10302
11300
  });
@@ -10305,7 +11303,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10305
11303
  start: { x: left, y: pdfY + 1.5 },
10306
11304
  end: { x: left + width, y: pdfY + 1.5 },
10307
11305
  thickness: 1.5,
10308
- color: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b),
11306
+ color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
10309
11307
  opacity: op
10310
11308
  });
10311
11309
  } else if (annotType === "strikeout") {
@@ -10313,7 +11311,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10313
11311
  start: { x: left, y: pdfY + height / 2 },
10314
11312
  end: { x: left + width, y: pdfY + height / 2 },
10315
11313
  thickness: 1.5,
10316
- color: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b),
11314
+ color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
10317
11315
  opacity: op
10318
11316
  });
10319
11317
  } else if (annotType === "squiggly") {
@@ -10331,7 +11329,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10331
11329
  pdfPage.drawSvgPath(segments.join(" "), {
10332
11330
  x: left,
10333
11331
  y: pageHeight - top,
10334
- borderColor: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b),
11332
+ borderColor: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
10335
11333
  borderWidth: 1.3,
10336
11334
  borderOpacity: op
10337
11335
  });
@@ -10342,8 +11340,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10342
11340
  y: pdfY,
10343
11341
  width,
10344
11342
  height,
10345
- color: (0, import_pdf_lib3.rgb)(1, 0.97, 0.86),
10346
- borderColor: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b),
11343
+ color: (0, import_pdf_lib4.rgb)(1, 0.97, 0.86),
11344
+ borderColor: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b),
10347
11345
  borderWidth: 1.2,
10348
11346
  opacity: op
10349
11347
  });
@@ -10353,13 +11351,13 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10353
11351
  start: { x: lineLeft, y: pdfY + height * 0.65 },
10354
11352
  end: { x: lineRight, y: pdfY + height * 0.65 },
10355
11353
  thickness: 1,
10356
- color: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b)
11354
+ color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b)
10357
11355
  });
10358
11356
  pdfPage.drawLine({
10359
11357
  start: { x: lineLeft, y: pdfY + height * 0.4 },
10360
11358
  end: { x: lineLeft + (lineRight - lineLeft) * 0.72, y: pdfY + height * 0.4 },
10361
11359
  thickness: 1,
10362
- color: (0, import_pdf_lib3.rgb)(col.r, col.g, col.b)
11360
+ color: (0, import_pdf_lib4.rgb)(col.r, col.g, col.b)
10363
11361
  });
10364
11362
  }
10365
11363
  const pdfSubtype = annotType === "highlight" ? "Highlight" : annotType === "underline" ? "Underline" : annotType === "strikeout" ? "StrikeOut" : annotType === "squiggly" ? "Squiggly" : "Text";
@@ -10374,8 +11372,8 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10374
11372
  Rect: [left, pdfY, left + width, pdfY + height],
10375
11373
  C: [col.r, col.g, col.b],
10376
11374
  CA: op,
10377
- T: import_pdf_lib3.PDFHexString.fromText(annotEl.author || "Reviewer"),
10378
- Contents: import_pdf_lib3.PDFHexString.fromText(threadSummary)
11375
+ T: import_pdf_lib4.PDFHexString.fromText(annotEl.author || "Reviewer"),
11376
+ Contents: import_pdf_lib4.PDFHexString.fromText(threadSummary)
10379
11377
  };
10380
11378
  if (pdfSubtype !== "Text") {
10381
11379
  annotDictEntries.QuadPoints = [
@@ -10398,7 +11396,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10398
11396
  y: pdfY,
10399
11397
  width,
10400
11398
  height,
10401
- color: (0, import_pdf_lib3.rgb)(fill.r, fill.g, fill.b),
11399
+ color: (0, import_pdf_lib4.rgb)(fill.r, fill.g, fill.b),
10402
11400
  opacity: 1,
10403
11401
  borderWidth: 0
10404
11402
  });
@@ -10431,10 +11429,10 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10431
11429
  }
10432
11430
  } finally {
10433
11431
  if (hasOpenCenterTransform) {
10434
- pdfPage.pushOperators((0, import_pdf_lib3.popGraphicsState)());
11432
+ pdfPage.pushOperators((0, import_pdf_lib4.popGraphicsState)());
10435
11433
  }
10436
11434
  while (openBdcCount > 0) {
10437
- pdfPage.pushOperators(import_pdf_lib3.PDFOperator.of("EMC"));
11435
+ pdfPage.pushOperators(import_pdf_lib4.PDFOperator.of("EMC"));
10438
11436
  openBdcCount--;
10439
11437
  }
10440
11438
  }
@@ -10464,7 +11462,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10464
11462
  const batesFs = 8.5;
10465
11463
  const marginX = 18;
10466
11464
  if (!hasNonAscii(batesStr) && cjkState?.mode !== "subset-ttf") {
10467
- const batesFont = await pdfDoc.embedFont(import_pdf_lib3.StandardFonts.HelveticaBold);
11465
+ const batesFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
10468
11466
  const textW = batesFont.widthOfTextAtSize(batesStr, batesFs);
10469
11467
  const bx = pos === "topLeft" || pos === "bottomLeft" ? marginX : Math.max(marginX, pageWidth - marginX - textW);
10470
11468
  const by = pos === "bottomLeft" || pos === "bottomRight" ? 14 : Math.max(14, pageHeight - 14 - batesFs);
@@ -10473,7 +11471,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10473
11471
  y: by,
10474
11472
  size: batesFs,
10475
11473
  font: batesFont,
10476
- color: (0, import_pdf_lib3.rgb)(0.18, 0.22, 0.3)
11474
+ color: (0, import_pdf_lib4.rgb)(0.18, 0.22, 0.3)
10477
11475
  });
10478
11476
  } else {
10479
11477
  const boxW = Math.min(220, pageWidth - marginX * 2);
@@ -10509,7 +11507,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10509
11507
  const wmRgb = parseHexColor(wmCfg?.color) ?? { r: 0.4, g: 0.45, b: 0.55 };
10510
11508
  const isTiled = wmCfg?.tiled !== false;
10511
11509
  if (!hasNonAscii(watermarkText)) {
10512
- const wmFont = await pdfDoc.embedFont(import_pdf_lib3.StandardFonts.HelveticaBold);
11510
+ const wmFont = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
10513
11511
  if (isTiled) {
10514
11512
  for (let wy = 90; wy < pageHeight - 40; wy += 180) {
10515
11513
  for (let wx = 50; wx < pageWidth2 - 40; wx += 220) {
@@ -10518,9 +11516,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10518
11516
  y: wy,
10519
11517
  size: wmSize,
10520
11518
  font: wmFont,
10521
- color: (0, import_pdf_lib3.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
11519
+ color: (0, import_pdf_lib4.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
10522
11520
  opacity: wmOpacity,
10523
- rotate: (0, import_pdf_lib3.degrees)(wmAngle)
11521
+ rotate: (0, import_pdf_lib4.degrees)(wmAngle)
10524
11522
  });
10525
11523
  }
10526
11524
  }
@@ -10530,9 +11528,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10530
11528
  y: Math.max(40, pageHeight * 0.45),
10531
11529
  size: wmSize * 1.5,
10532
11530
  font: wmFont,
10533
- color: (0, import_pdf_lib3.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
11531
+ color: (0, import_pdf_lib4.rgb)(wmRgb.r, wmRgb.g, wmRgb.b),
10534
11532
  opacity: wmOpacity,
10535
- rotate: (0, import_pdf_lib3.degrees)(wmAngle)
11533
+ rotate: (0, import_pdf_lib4.degrees)(wmAngle)
10536
11534
  });
10537
11535
  }
10538
11536
  } else if (cjkState) {
@@ -10541,14 +11539,14 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10541
11539
  for (let wy = 90; wy < pageHeight - 40; wy += isTiled ? 185 : pageHeight) {
10542
11540
  for (let wx = 45; wx < pageWidth2 - 50; wx += isTiled ? 225 : pageWidth2) {
10543
11541
  pdfPage.pushOperators(
10544
- (0, import_pdf_lib3.pushGraphicsState)(),
10545
- (0, import_pdf_lib3.beginText)(),
10546
- (0, import_pdf_lib3.setFillingRgbColor)(0.78, 0.81, 0.86),
10547
- (0, import_pdf_lib3.setFontAndSize)(fontKey, wmSize),
10548
- (0, import_pdf_lib3.rotateAndSkewTextDegreesAndTranslate)(wmAngle, 0, 0, wx, wy),
10549
- (0, import_pdf_lib3.showText)(import_pdf_lib3.PDFHexString.of(hexWm)),
10550
- (0, import_pdf_lib3.endText)(),
10551
- (0, import_pdf_lib3.popGraphicsState)()
11542
+ (0, import_pdf_lib4.pushGraphicsState)(),
11543
+ (0, import_pdf_lib4.beginText)(),
11544
+ (0, import_pdf_lib4.setFillingRgbColor)(0.78, 0.81, 0.86),
11545
+ (0, import_pdf_lib4.setFontAndSize)(fontKey, wmSize),
11546
+ (0, import_pdf_lib4.rotateAndSkewTextDegreesAndTranslate)(wmAngle, 0, 0, wx, wy),
11547
+ (0, import_pdf_lib4.showText)(import_pdf_lib4.PDFHexString.of(hexWm)),
11548
+ (0, import_pdf_lib4.endText)(),
11549
+ (0, import_pdf_lib4.popGraphicsState)()
10552
11550
  );
10553
11551
  }
10554
11552
  }
@@ -10570,7 +11568,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10570
11568
  width: 170,
10571
11569
  height: 30,
10572
11570
  opacity: 0.15,
10573
- rotate: (0, import_pdf_lib3.degrees)(26)
11571
+ rotate: (0, import_pdf_lib4.degrees)(26)
10574
11572
  });
10575
11573
  }
10576
11574
  }
@@ -10594,7 +11592,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10594
11592
  }
10595
11593
  return void 0;
10596
11594
  };
10597
- return walk(snapshot.metadata?.bookmarks);
11595
+ return walk(snapshot.bookmarks ?? snapshot.metadata?.bookmarks);
10598
11596
  };
10599
11597
  for (const linkItem of deferredLinkAnnotations) {
10600
11598
  const hostPage = allPages[linkItem.hostPageIndex];
@@ -10609,9 +11607,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10609
11607
  const targetPage = allPages[clampedIdx];
10610
11608
  const destArr = pdfDoc.context.obj([
10611
11609
  targetPage.ref,
10612
- import_pdf_lib3.PDFName.of("XYZ"),
10613
- import_pdf_lib3.PDFNumber.of(elDest.x),
10614
- import_pdf_lib3.PDFNumber.of(elDest.topY),
11610
+ import_pdf_lib4.PDFName.of("XYZ"),
11611
+ import_pdf_lib4.PDFNumber.of(elDest.x),
11612
+ import_pdf_lib4.PDFNumber.of(elDest.topY),
10615
11613
  null
10616
11614
  ]);
10617
11615
  const actionDict = pdfDoc.context.obj({
@@ -10640,9 +11638,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10640
11638
  const targetPage = allPages[clampedIdx];
10641
11639
  const destArr = pdfDoc.context.obj([
10642
11640
  targetPage.ref,
10643
- import_pdf_lib3.PDFName.of("XYZ"),
10644
- import_pdf_lib3.PDFNumber.of(0),
10645
- import_pdf_lib3.PDFNumber.of(targetPage.getHeight()),
11641
+ import_pdf_lib4.PDFName.of("XYZ"),
11642
+ import_pdf_lib4.PDFNumber.of(0),
11643
+ import_pdf_lib4.PDFNumber.of(targetPage.getHeight()),
10646
11644
  null
10647
11645
  ]);
10648
11646
  const actionDict = pdfDoc.context.obj({
@@ -10670,7 +11668,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10670
11668
  const actionDict = pdfDoc.context.obj({
10671
11669
  Type: "Action",
10672
11670
  S: "URI",
10673
- URI: import_pdf_lib3.PDFString.of(trimmedUrl)
11671
+ URI: import_pdf_lib4.PDFString.of(trimmedUrl)
10674
11672
  });
10675
11673
  const linkAnnot = pdfDoc.context.obj({
10676
11674
  Type: "Annot",
@@ -10683,7 +11681,7 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10683
11681
  } else if (typeof linkItem.linkPageIndex === "number" && linkItem.linkPageIndex >= 0 && allPages.length > 0) {
10684
11682
  const clampedIdx = Math.min(allPages.length - 1, Math.floor(linkItem.linkPageIndex));
10685
11683
  const targetPage = allPages[clampedIdx];
10686
- const destArr = pdfDoc.context.obj([targetPage.ref, import_pdf_lib3.PDFName.of("XYZ"), null, null, null]);
11684
+ const destArr = pdfDoc.context.obj([targetPage.ref, import_pdf_lib4.PDFName.of("XYZ"), null, null, null]);
10687
11685
  const linkAnnot = pdfDoc.context.obj({
10688
11686
  Type: "Annot",
10689
11687
  Subtype: "Link",
@@ -10695,8 +11693,9 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10695
11693
  }
10696
11694
  }
10697
11695
  }
10698
- if (snapshot.metadata?.bookmarks && snapshot.metadata.bookmarks.length > 0) {
10699
- attachPdfOutlinesTree(pdfDoc, snapshot.metadata.bookmarks);
11696
+ const effectiveBookmarks = snapshot.bookmarks ?? snapshot.metadata?.bookmarks;
11697
+ if (effectiveBookmarks && effectiveBookmarks.length > 0) {
11698
+ attachPdfOutlinesTree(pdfDoc, effectiveBookmarks);
10700
11699
  }
10701
11700
  const attachments = snapshot.attachments ?? snapshot.metadata?.attachments ?? [];
10702
11701
  if (attachments.length > 0) {
@@ -10708,28 +11707,28 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10708
11707
  const pieceDict = {};
10709
11708
  if (sigEnv) {
10710
11709
  pieceDict.UniverSignature = {
10711
- LastModified: import_pdf_lib3.PDFString.of(sigEnv.signedAt || (/* @__PURE__ */ new Date()).toISOString()),
11710
+ LastModified: import_pdf_lib4.PDFString.of(sigEnv.signedAt || (/* @__PURE__ */ new Date()).toISOString()),
10712
11711
  Private: pdfDoc.context.obj({
10713
- Algorithm: import_pdf_lib3.PDFName.of("SHA-256"),
10714
- Signer: import_pdf_lib3.PDFHexString.fromText(sigEnv.signerName),
10715
- CertificateSubject: import_pdf_lib3.PDFHexString.fromText(sigEnv.certificateSubject),
10716
- ContentDigest: import_pdf_lib3.PDFString.of(sigEnv.contentDigestHex),
10717
- EnvelopeDigest: import_pdf_lib3.PDFString.of(sigEnv.envelopeDigestHex)
11712
+ Algorithm: import_pdf_lib4.PDFName.of("SHA-256"),
11713
+ Signer: import_pdf_lib4.PDFHexString.fromText(sigEnv.signerName),
11714
+ CertificateSubject: import_pdf_lib4.PDFHexString.fromText(sigEnv.certificateSubject),
11715
+ ContentDigest: import_pdf_lib4.PDFString.of(sigEnv.contentDigestHex),
11716
+ EnvelopeDigest: import_pdf_lib4.PDFString.of(sigEnv.envelopeDigestHex)
10718
11717
  })
10719
11718
  };
10720
11719
  }
10721
11720
  if (secPerms) {
10722
11721
  pieceDict.UniverSecurity = {
10723
- LastModified: import_pdf_lib3.PDFString.of((/* @__PURE__ */ new Date()).toISOString()),
11722
+ LastModified: import_pdf_lib4.PDFString.of((/* @__PURE__ */ new Date()).toISOString()),
10724
11723
  Private: pdfDoc.context.obj({
10725
- AllowPrint: secPerms.allowPrint !== false ? import_pdf_lib3.PDFBool.True : import_pdf_lib3.PDFBool.False,
10726
- AllowCopy: secPerms.allowCopy !== false ? import_pdf_lib3.PDFBool.True : import_pdf_lib3.PDFBool.False,
10727
- AllowModify: secPerms.allowModify !== false ? import_pdf_lib3.PDFBool.True : import_pdf_lib3.PDFBool.False,
10728
- ...secPerms.openPasswordHash ? { OpenPasswordHash: import_pdf_lib3.PDFString.of(secPerms.openPasswordHash) } : {}
11724
+ AllowPrint: secPerms.allowPrint !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
11725
+ AllowCopy: secPerms.allowCopy !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
11726
+ AllowModify: secPerms.allowModify !== false ? import_pdf_lib4.PDFBool.True : import_pdf_lib4.PDFBool.False,
11727
+ ...secPerms.openPasswordHash ? { OpenPasswordHash: import_pdf_lib4.PDFString.of(secPerms.openPasswordHash) } : {}
10729
11728
  })
10730
11729
  };
10731
11730
  }
10732
- pdfDoc.catalog.set(import_pdf_lib3.PDFName.of("PieceInfo"), pdfDoc.context.obj(pieceDict));
11731
+ pdfDoc.catalog.set(import_pdf_lib4.PDFName.of("PieceInfo"), pdfDoc.context.obj(pieceDict));
10733
11732
  }
10734
11733
  if (accessibilityTagged) {
10735
11734
  attachTaggedStructTreeRoot(pdfDoc, snapshot, taggedStructItems, totalPhysicalPages);
@@ -10740,40 +11739,49 @@ async function exportPdfBytes(snapshot, runtimeData, options) {
10740
11739
  if (interactiveForm && hasAnyAcroWidget) {
10741
11740
  const acroDict = pdfDoc.getForm().acroForm.dict;
10742
11741
  const helv = await ensureAcroHelvetica();
10743
- let drDict = pdfDoc.context.lookupMaybe(acroDict.get(import_pdf_lib3.PDFName.of("DR")), import_pdf_lib3.PDFDict);
11742
+ let drDict = pdfDoc.context.lookupMaybe(acroDict.get(import_pdf_lib4.PDFName.of("DR")), import_pdf_lib4.PDFDict);
10744
11743
  if (!drDict) {
10745
11744
  drDict = pdfDoc.context.obj({});
10746
- acroDict.set(import_pdf_lib3.PDFName.of("DR"), drDict);
11745
+ acroDict.set(import_pdf_lib4.PDFName.of("DR"), drDict);
10747
11746
  }
10748
- let fontDict = pdfDoc.context.lookupMaybe(drDict.get(import_pdf_lib3.PDFName.of("Font")), import_pdf_lib3.PDFDict);
11747
+ let fontDict = pdfDoc.context.lookupMaybe(drDict.get(import_pdf_lib4.PDFName.of("Font")), import_pdf_lib4.PDFDict);
10749
11748
  if (!fontDict) {
10750
11749
  fontDict = pdfDoc.context.obj({});
10751
- drDict.set(import_pdf_lib3.PDFName.of("Font"), fontDict);
11750
+ drDict.set(import_pdf_lib4.PDFName.of("Font"), fontDict);
10752
11751
  }
10753
- fontDict.set(import_pdf_lib3.PDFName.of("Helv"), helv.ref);
11752
+ fontDict.set(import_pdf_lib4.PDFName.of("Helv"), helv.ref);
10754
11753
  if (acroCjkState) {
10755
- fontDict.set(import_pdf_lib3.PDFName.of("FCjk"), acroCjkState.type0FontRef);
11754
+ fontDict.set(import_pdf_lib4.PDFName.of("FCjk"), acroCjkState.type0FontRef);
10756
11755
  }
10757
11756
  acroDict.set(
10758
- import_pdf_lib3.PDFName.of("DA"),
10759
- import_pdf_lib3.PDFString.of(acroCjkState ? "/FCjk 11 Tf 0 0 0 rg" : "/Helv 11 Tf 0 0 0 rg")
11757
+ import_pdf_lib4.PDFName.of("DA"),
11758
+ import_pdf_lib4.PDFString.of(acroCjkState ? "/FCjk 11 Tf 0 0 0 rg" : "/Helv 11 Tf 0 0 0 rg")
10760
11759
  );
10761
- acroDict.delete(import_pdf_lib3.PDFName.of("NeedAppearances"));
11760
+ acroDict.delete(import_pdf_lib4.PDFName.of("NeedAppearances"));
10762
11761
  }
10763
11762
  if (optimizeSize) {
10764
11763
  pruneUnreferencedObjectsAndCompressStreams(pdfDoc);
10765
11764
  }
11765
+ const effectiveSecurity = options?.security ?? snapshot.security ?? snapshot.metadata?.security;
11766
+ const shouldEncrypt = isPdfSecurityActive(effectiveSecurity);
10766
11767
  throwIfExportAborted();
11768
+ if (shouldEncrypt && !options?.diagnosticGridOverlay) {
11769
+ await applyPdfSecurityToDocument(pdfDoc, effectiveSecurity);
11770
+ const encryptedSavedBytes = interactiveForm && hasAnyAcroWidget ? await pdfDoc.save({ useObjectStreams: false, updateFieldAppearances: false }) : await pdfDoc.save({ useObjectStreams: false });
11771
+ throwIfExportAborted();
11772
+ return encryptedSavedBytes;
11773
+ }
10767
11774
  const savedPdfBytes = interactiveForm && hasAnyAcroWidget ? await pdfDoc.save({ updateFieldAppearances: false }) : await pdfDoc.save();
10768
11775
  throwIfExportAborted();
10769
11776
  if (options?.diagnosticGridOverlay) {
10770
11777
  const gridOpts = typeof options.diagnosticGridOverlay === "object" ? options.diagnosticGridOverlay : void 0;
10771
- return await overlayDiagnosticGridOnPdfBytes(savedPdfBytes, snapshot, gridOpts);
11778
+ const overlaidBytes = await overlayDiagnosticGridOnPdfBytes(savedPdfBytes, snapshot, gridOpts);
11779
+ return shouldEncrypt ? await encryptPdfBytes(overlaidBytes, effectiveSecurity) : overlaidBytes;
10772
11780
  }
10773
11781
  return savedPdfBytes;
10774
11782
  }
10775
11783
  async function overlayDiagnosticGridOnPdfBytes(pdfBytes, snapshot, options) {
10776
- const pdfDoc = await import_pdf_lib3.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
11784
+ const pdfDoc = await import_pdf_lib4.PDFDocument.load(pdfBytes, { ignoreEncryption: true });
10777
11785
  const pages = pdfDoc.getPages();
10778
11786
  if (pages.length === 0) {
10779
11787
  return await pdfDoc.save({ updateFieldAppearances: false });
@@ -10785,14 +11793,14 @@ async function overlayDiagnosticGridOnPdfBytes(pdfBytes, snapshot, options) {
10785
11793
  const showElementBounds = options?.showElementBounds !== false;
10786
11794
  const showElementLabels = options?.showElementLabels !== false;
10787
11795
  const gridOpacity = Math.max(0.05, Math.min(1, options?.gridOpacity ?? 0.35));
10788
- const fontRegular = await pdfDoc.embedFont(import_pdf_lib3.StandardFonts.Helvetica);
10789
- const fontBold = await pdfDoc.embedFont(import_pdf_lib3.StandardFonts.HelveticaBold);
11796
+ const fontRegular = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.Helvetica);
11797
+ const fontBold = await pdfDoc.embedFont(import_pdf_lib4.StandardFonts.HelveticaBold);
10790
11798
  let lazyCjkState = null;
10791
- const minorCol = (0, import_pdf_lib3.rgb)(0.49, 0.525, 0.596);
10792
- const majorCol = (0, import_pdf_lib3.rgb)(0.173, 0.325, 0.945);
10793
- const rulerTextCol = (0, import_pdf_lib3.rgb)(0.192, 0.212, 0.247);
10794
- const boxCol = (0, import_pdf_lib3.rgb)(0.173, 0.325, 0.945);
10795
- const badgeBgCol = (0, import_pdf_lib3.rgb)(0.953, 0.961, 1);
11799
+ const minorCol = (0, import_pdf_lib4.rgb)(0.49, 0.525, 0.596);
11800
+ const majorCol = (0, import_pdf_lib4.rgb)(0.173, 0.325, 0.945);
11801
+ const rulerTextCol = (0, import_pdf_lib4.rgb)(0.192, 0.212, 0.247);
11802
+ const boxCol = (0, import_pdf_lib4.rgb)(0.173, 0.325, 0.945);
11803
+ const badgeBgCol = (0, import_pdf_lib4.rgb)(0.953, 0.961, 1);
10796
11804
  const staticEls = unitSnapshot?.document?.metadata?.staticSchemaElements ?? unitSnapshot?.metadata?.staticSchemaElements ?? [];
10797
11805
  for (let pIdx = 0; pIdx < pages.length; pIdx++) {
10798
11806
  const page = pages[pIdx];