@poe-platform/safe-bash 0.1.761 → 0.1.763

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.
Files changed (32) hide show
  1. package/dist/image-ast/index.browser.js +255 -62
  2. package/dist/image-ast/index.js +255 -62
  3. package/dist/pdf-ast/ast.d.ts +23 -0
  4. package/dist/pdf-ast/index.js +344 -98
  5. package/dist/safe-bash/command-chunks/{chunk-6VX5ZQL5.js → chunk-4XHONGIU.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-OSMLVM7P.js → chunk-S3G2B4OX.js} +258 -62
  7. package/dist/safe-bash/command-chunks/{chunk-GR725WRX.js → chunk-S5EX6UP5.js} +1 -1
  8. package/dist/safe-bash/commands/csvcut/index.d.ts +1 -1
  9. package/dist/safe-bash/commands/csvcut/index.js +3 -1
  10. package/dist/safe-bash/commands/csvgrep/index.d.ts +1 -1
  11. package/dist/safe-bash/commands/csvgrep/index.js +3 -1
  12. package/dist/safe-bash/core.browser.js +8 -6
  13. package/dist/safe-bash/shell/runtime.js +5 -5
  14. package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
  15. package/dist/safe-bash-checksum-engine/index.js +5 -1
  16. package/dist/safe-bash-command-ffmpeg/index.js +7942 -7853
  17. package/dist/safe-bash-command-gh/index.js +174 -105
  18. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  19. package/dist/safe-bash-command-pandoc/command.js +3 -3
  20. package/dist/safe-bash-command-pandoc/index.js +3 -3
  21. package/dist/safe-bash-command-pdfimages/index.js +255 -62
  22. package/dist/safe-bash-command-pdfinfo/index.js +342 -98
  23. package/dist/safe-bash-command-pdftk/index.js +255 -62
  24. package/dist/safe-bash-command-pdftoppm/index.js +342 -98
  25. package/dist/safe-bash-command-pdftotext/index.js +255 -62
  26. package/dist/safe-bash-command-qpdf/index.js +255 -62
  27. package/dist/safe-bash-command-sips/index.js +2 -2
  28. package/dist/safe-bash-command-soffice/index.js +1 -1
  29. package/dist/safe-bash-command-ssconvert/index.js +318 -65
  30. package/dist/safe-bash-command-wkhtmltopdf/index.js +255 -62
  31. package/package.json +2 -2
  32. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +23 -0
@@ -209075,14 +209075,18 @@ function evaluateContentStreamToDisplayList(params) {
209075
209075
  const paths = [];
209076
209076
  const images = [];
209077
209077
  const operations = [];
209078
+ let capturedOperations;
209079
+ let insideSoftMask = false;
209078
209080
  const emit = (operation) => {
209079
- const { clipPaths, clipImages } = curState();
209080
- if (clipPaths || clipImages) operation = { ...operation, value: {
209081
+ const { clipPaths, clipImages, softMask } = curState();
209082
+ if (clipPaths || clipImages || softMask) operation = { ...operation, value: {
209081
209083
  ...operation.value,
209082
209084
  ...clipPaths ? { clipPaths } : {},
209083
- ...clipImages ? { clipImages } : {}
209085
+ ...clipImages ? { clipImages } : {},
209086
+ ...softMask ? { softMask } : {}
209084
209087
  } };
209085
- operations.push(operation);
209088
+ (capturedOperations ?? operations).push(operation);
209089
+ if (insideSoftMask) return;
209086
209090
  switch (operation.kind) {
209087
209091
  case "path":
209088
209092
  paths.push(operation.value);
@@ -209188,7 +209192,7 @@ function evaluateContentStreamToDisplayList(params) {
209188
209192
  );
209189
209193
  return { r: kClamp(r), g: kClamp(g), b: kClamp(b3) };
209190
209194
  };
209191
- const applyStateOperator = (st, operator, ops, activeResources) => {
209195
+ const applyStateOperator = (st, operator, ops, activeResources, activeFonts, depth) => {
209192
209196
  const num = (i, fb = 0) => ops[i]?.kind === "number" ? ops[i].value : fb;
209193
209197
  if (operator === "cm") {
209194
209198
  const m = [num(0, 1), num(1, 0), num(2, 0), num(3, 1), num(4, 0), num(5, 0)];
@@ -209271,6 +209275,46 @@ function evaluateContentStreamToDisplayList(params) {
209271
209275
  const extDict = params.cosDoc.resolveDict(dictGet(activeResources, "ExtGState"));
209272
209276
  const gsDict = extDict ? params.cosDoc.resolveDict(dictGet(extDict, ops[0].decoded)) : void 0;
209273
209277
  if (gsDict) {
209278
+ const mask = params.cosDoc.resolve(dictGet(gsDict, "SMask"));
209279
+ if (mask?.kind === "name" && mask.decoded === "None") {
209280
+ st.softMask = void 0;
209281
+ } else if (mask?.kind === "dict") {
209282
+ const subtype = params.cosDoc.resolve(dictGet(mask, "S"));
209283
+ const form = params.cosDoc.resolve(dictGet(mask, "G"));
209284
+ if (form?.kind === "stream" && subtype?.kind === "name" && (subtype.decoded === "Alpha" || subtype.decoded === "Luminosity")) {
209285
+ if (depth >= 8) throw new PdfError2("E_LIMIT", "Soft-mask nesting exceeds the form depth limit");
209286
+ const parentOperations = capturedOperations;
209287
+ const parentInsideSoftMask = insideSoftMask;
209288
+ const savedTextState = { pendingTextClip, hasTextClip, activeTm, activeTlm };
209289
+ const captured = [];
209290
+ capturedOperations = captured;
209291
+ insideSoftMask = true;
209292
+ const maskState = { ...st, softMask: void 0, fillAlpha: 1, strokeAlpha: 1, blendMode: "Normal" };
209293
+ delete maskState.clipPaths;
209294
+ delete maskState.clipImages;
209295
+ delete maskState.clipRect;
209296
+ stateStack.push(maskState);
209297
+ try {
209298
+ paintForm(form, activeResources, activeFonts, depth, void 0, void 0, true);
209299
+ } finally {
209300
+ stateStack.pop();
209301
+ capturedOperations = parentOperations;
209302
+ insideSoftMask = parentInsideSoftMask;
209303
+ ({ pendingTextClip, hasTextClip, activeTm, activeTlm } = savedTextState);
209304
+ }
209305
+ const group = params.cosDoc.resolveDict(dictGet(form.dict, "Group"));
209306
+ const colorSpace = group ? dictGet(group, "CS") : void 0;
209307
+ const bc = params.cosDoc.resolveArray(dictGet(mask, "BC"));
209308
+ const components22 = bc?.items.map((item) => {
209309
+ const value3 = params.cosDoc.resolve(item);
209310
+ return value3?.kind === "number" ? value3.value : 0;
209311
+ });
209312
+ const [r, g, b3] = components22 ? convertColorSpaceComponentsToRgb(params.cosDoc, colorSpace, "DeviceRGB", components22, activeResources) : [0, 0, 0];
209313
+ const transfer = params.cosDoc.resolve(dictGet(mask, "TR"));
209314
+ const transferMap = transfer?.kind === "dict" || transfer?.kind === "stream" ? Uint8Array.from({ length: 256 }, (_, i) => Math.floor(kClamp(Math.fround(evalShadingFunctionToComponents(params.cosDoc, transfer, Math.fround(i / 255))[0] ?? 0)) * 255)) : void 0;
209315
+ st.softMask = { subtype: subtype.decoded, operations: captured, backdrop: { r, g, b: b3 }, transferMap };
209316
+ }
209317
+ }
209274
209318
  const bmNode = params.cosDoc.resolve(dictGet(gsDict, "BM"));
209275
209319
  if (bmNode?.kind === "name") {
209276
209320
  st.blendMode = bmNode.decoded === "Compatible" ? "Normal" : bmNode.decoded;
@@ -209357,6 +209401,84 @@ function evaluateContentStreamToDisplayList(params) {
209357
209401
  ] }], void 0, void 0, resources, activeFonts, depth);
209358
209402
  stateStack.pop();
209359
209403
  };
209404
+ const paintForm = (form, activeResources, activeFonts, depth, mcid, actualText, maskGroup = false) => {
209405
+ const st = curState();
209406
+ const group = params.cosDoc.resolveDict(dictGet(form.dict, "Group"));
209407
+ const groupType = group ? params.cosDoc.resolve(dictGet(group, "S")) : void 0;
209408
+ const isolated = group ? params.cosDoc.resolve(dictGet(group, "I")) : void 0;
209409
+ const isolate = !maskGroup && groupType?.kind === "name" && groupType.decoded === "Transparency" && isolated?.kind === "boolean" && isolated.value;
209410
+ const formStreamBytes = params.cosDoc.decodeStream(form);
209411
+ const formNodes = parseContentStream(formStreamBytes);
209412
+ const formResDict = params.cosDoc.resolveDict(dictGet(form.dict, "Resources")) ?? activeResources;
209413
+ const formFonts = new Map(activeFonts);
209414
+ for (const [k, v] of resolvePageFonts(params.cosDoc, formResDict).entries()) {
209415
+ formFonts.set(k, v);
209416
+ }
209417
+ let nextCtm = [...st.ctm];
209418
+ const matArr = params.cosDoc.resolveArray(dictGet(form.dict, "Matrix"));
209419
+ if (matArr && matArr.items.length >= 6) {
209420
+ const mn = (idx, fb = 0) => {
209421
+ const resolved = params.cosDoc.resolve(matArr.items[idx]);
209422
+ return resolved?.kind === "number" ? resolved.value : fb;
209423
+ };
209424
+ const formMat = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
209425
+ nextCtm = multiplyMatrices(formMat, nextCtm);
209426
+ }
209427
+ let nextClip = !isolate && st.clipRect ? [...st.clipRect] : void 0;
209428
+ let nextClipPaths = isolate ? void 0 : st.clipPaths;
209429
+ const bboxArr = params.cosDoc.resolveArray(dictGet(form.dict, "BBox"));
209430
+ if (bboxArr && bboxArr.items.length >= 4) {
209431
+ const bn = (idx, fb = 0) => {
209432
+ const resolved = params.cosDoc.resolve(bboxArr.items[idx]);
209433
+ return resolved?.kind === "number" ? resolved.value : fb;
209434
+ };
209435
+ const bx0 = bn(0, 0), by0 = bn(1, 0), bx1 = bn(2, 0), by1 = bn(3, 0);
209436
+ const pts = [
209437
+ transformPoint(nextCtm, bx0, by0),
209438
+ transformPoint(nextCtm, bx1, by0),
209439
+ transformPoint(nextCtm, bx1, by1),
209440
+ transformPoint(nextCtm, bx0, by1)
209441
+ ];
209442
+ nextClipPaths = [...nextClipPaths ?? [], [
209443
+ ...pts.map(([x, y], index2) => ({ kind: index2 === 0 ? "move" : "line", x, y })),
209444
+ { kind: "close" }
209445
+ ]];
209446
+ const fMinX = Math.min(...pts.map((p2) => p2[0]));
209447
+ const fMinY = Math.min(...pts.map((p2) => p2[1]));
209448
+ const fMaxX = Math.max(...pts.map((p2) => p2[0]));
209449
+ const fMaxY = Math.max(...pts.map((p2) => p2[1]));
209450
+ if (fMaxX > fMinX && fMaxY > fMinY) {
209451
+ nextClip = nextClip ? [
209452
+ Math.max(nextClip[0], fMinX),
209453
+ Math.max(nextClip[1], fMinY),
209454
+ Math.min(nextClip[2], fMaxX),
209455
+ Math.min(nextClip[3], fMaxY)
209456
+ ] : [fMinX, fMinY, fMaxX, fMaxY];
209457
+ }
209458
+ }
209459
+ const parentOperations = capturedOperations;
209460
+ const children8 = [];
209461
+ const nextState = { ...st, ctm: nextCtm };
209462
+ if (isolate) {
209463
+ capturedOperations = children8;
209464
+ nextState.fillAlpha = nextState.strokeAlpha = 1;
209465
+ nextState.blendMode = "Normal";
209466
+ nextState.softMask = void 0;
209467
+ delete nextState.clipImages;
209468
+ delete nextState.clipPaths;
209469
+ delete nextState.clipRect;
209470
+ }
209471
+ if (nextClip) nextState.clipRect = nextClip;
209472
+ if (nextClipPaths) nextState.clipPaths = nextClipPaths;
209473
+ stateStack.push(nextState);
209474
+ try {
209475
+ walkNodes(formNodes, mcid, actualText, formResDict, formFonts, depth + 1);
209476
+ } finally {
209477
+ stateStack.pop();
209478
+ capturedOperations = parentOperations;
209479
+ }
209480
+ if (isolate) emit({ kind: "group", value: { operations: children8, alpha: st.fillAlpha, blendMode: st.blendMode, clipRect: st.clipRect } });
209481
+ };
209360
209482
  const walkNodes = (nodes, mcid, actualText, activeResources = params.resourcesDict, activeFonts = fonts, depth = 0) => {
209361
209483
  for (const node3 of nodes) {
209362
209484
  switch (node3.kind) {
@@ -209401,7 +209523,7 @@ function evaluateContentStreamToDisplayList(params) {
209401
209523
  break;
209402
209524
  }
209403
209525
  case "state-op": {
209404
- applyStateOperator(curState(), node3.operator, node3.operands, activeResources);
209526
+ applyStateOperator(curState(), node3.operator, node3.operands, activeResources, activeFonts, depth);
209405
209527
  break;
209406
209528
  }
209407
209529
  case "path-op": {
@@ -209687,53 +209809,7 @@ function evaluateContentStreamToDisplayList(params) {
209687
209809
  ...st.clipRect ? { clipRect: [...st.clipRect] } : {}
209688
209810
  }, patternMask, activeResources, activeFonts, depth);
209689
209811
  } else if (sub === "Form" && depth < 8) {
209690
- const formStreamBytes = params.cosDoc.decodeStream(xobjNode);
209691
- const formNodes = parseContentStream(formStreamBytes);
209692
- const formResDict = params.cosDoc.resolveDict(dictGet(xobjNode.dict, "Resources")) ?? activeResources;
209693
- const formFonts = new Map(activeFonts);
209694
- for (const [k, v] of resolvePageFonts(params.cosDoc, formResDict).entries()) {
209695
- formFonts.set(k, v);
209696
- }
209697
- let nextCtm = [...st.ctm];
209698
- const matArr = params.cosDoc.resolveArray(dictGet(xobjNode.dict, "Matrix"));
209699
- if (matArr && matArr.items.length >= 6) {
209700
- const mn = (idx, fb = 0) => {
209701
- const resolved = params.cosDoc.resolve(matArr.items[idx]);
209702
- return resolved?.kind === "number" ? resolved.value : fb;
209703
- };
209704
- const formMat = [mn(0, 1), mn(1, 0), mn(2, 0), mn(3, 1), mn(4, 0), mn(5, 0)];
209705
- nextCtm = multiplyMatrices(formMat, nextCtm);
209706
- }
209707
- let nextClip = st.clipRect ? [...st.clipRect] : void 0;
209708
- const bboxArr = params.cosDoc.resolveArray(dictGet(xobjNode.dict, "BBox"));
209709
- if (bboxArr && bboxArr.items.length >= 4) {
209710
- const bn = (idx, fb = 0) => {
209711
- const resolved = params.cosDoc.resolve(bboxArr.items[idx]);
209712
- return resolved?.kind === "number" ? resolved.value : fb;
209713
- };
209714
- const bx0 = bn(0, 0), by0 = bn(1, 0), bx1 = bn(2, 0), by1 = bn(3, 0);
209715
- const pts = [
209716
- transformPoint(nextCtm, bx0, by0),
209717
- transformPoint(nextCtm, bx1, by0),
209718
- transformPoint(nextCtm, bx0, by1),
209719
- transformPoint(nextCtm, bx1, by1)
209720
- ];
209721
- const fMinX = Math.min(...pts.map((p2) => p2[0]));
209722
- const fMinY = Math.min(...pts.map((p2) => p2[1]));
209723
- const fMaxX = Math.max(...pts.map((p2) => p2[0]));
209724
- const fMaxY = Math.max(...pts.map((p2) => p2[1]));
209725
- if (fMaxX > fMinX && fMaxY > fMinY) {
209726
- nextClip = nextClip ? [
209727
- Math.max(nextClip[0], fMinX),
209728
- Math.max(nextClip[1], fMinY),
209729
- Math.min(nextClip[2], fMaxX),
209730
- Math.min(nextClip[3], fMaxY)
209731
- ] : [fMinX, fMinY, fMaxX, fMaxY];
209732
- }
209733
- }
209734
- stateStack.push({ ...st, ctm: nextCtm, ...nextClip ? { clipRect: nextClip } : {} });
209735
- walkNodes(formNodes, mcid, actualText, formResDict, formFonts, depth + 1);
209736
- if (stateStack.length > 1) stateStack.pop();
209812
+ paintForm(xobjNode, activeResources, activeFonts, depth, mcid, actualText);
209737
209813
  }
209738
209814
  }
209739
209815
  }
@@ -209952,7 +210028,7 @@ function evaluateContentStreamToDisplayList(params) {
209952
210028
  st.textRenderMode = cmd.mode;
209953
210029
  break;
209954
210030
  case "state-op":
209955
- applyStateOperator(st, cmd.operator, cmd.operands, activeResources);
210031
+ applyStateOperator(st, cmd.operator, cmd.operands, activeResources, activeFonts, depth);
209956
210032
  break;
209957
210033
  case "show-text":
209958
210034
  emitTokenBytes(cmd.token.bytes);
@@ -212215,6 +212291,47 @@ function flattenCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
212215
212291
  points.push([x4, y4]);
212216
212292
  return points;
212217
212293
  }
212294
+ function sampleImageLinear(image, x, y, out) {
212295
+ x = Math.max(0, Math.min(image.width - 1, x));
212296
+ y = Math.max(0, Math.min(image.height - 1, y));
212297
+ const x0 = Math.floor(x), y0 = Math.floor(y);
212298
+ const fx = x - x0, fy = y - y0;
212299
+ out.fill(0);
212300
+ for (let j = 0; j < 2; j++) {
212301
+ for (let i = 0; i < 2; i++) {
212302
+ const offset = (Math.min(image.height - 1, y0 + j) * image.width + Math.min(image.width - 1, x0 + i)) * 4;
212303
+ const alpha = image.data[offset + 3] * (i ? fx : 1 - fx) * (j ? fy : 1 - fy);
212304
+ out[0] = out[0] + image.data[offset] * alpha;
212305
+ out[1] = out[1] + image.data[offset + 1] * alpha;
212306
+ out[2] = out[2] + image.data[offset + 2] * alpha;
212307
+ out[3] = out[3] + alpha;
212308
+ }
212309
+ }
212310
+ if (out[3] > 0) {
212311
+ out[0] = out[0] / out[3];
212312
+ out[1] = out[1] / out[3];
212313
+ out[2] = out[2] / out[3];
212314
+ }
212315
+ }
212316
+ function downscaleImage(image, widthScale, heightScale) {
212317
+ const sample2 = new Float64Array(4);
212318
+ while (widthScale > 2 && image.width > 1 || heightScale > 2 && image.height > 1) {
212319
+ const width2 = widthScale > 2 ? Math.ceil(image.width / 2) : image.width;
212320
+ const height = heightScale > 2 ? Math.ceil(image.height / 2) : image.height;
212321
+ const data3 = new Uint8Array(width2 * height * 4);
212322
+ for (let y = 0; y < height; y++) {
212323
+ for (let x = 0; x < width2; x++) {
212324
+ sampleImageLinear(image, (x + 0.5) * image.width / width2 - 0.5, (y + 0.5) * image.height / height - 0.5, sample2);
212325
+ const offset = (y * width2 + x) * 4;
212326
+ for (let c4 = 0; c4 < 4; c4++) data3[offset + c4] = Math.round(sample2[c4]);
212327
+ }
212328
+ }
212329
+ widthScale /= image.width / width2;
212330
+ heightScale /= image.height / height;
212331
+ image = { width: width2, height, data: data3 };
212332
+ }
212333
+ return image;
212334
+ }
212218
212335
  function decodePng2(pngBytes) {
212219
212336
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
212220
212337
  throw new Error("Invalid PNG signature");
@@ -213124,6 +213241,30 @@ function paintOperations(displayList) {
213124
213241
  ...displayList.glyphs.map((value3) => ({ kind: "glyph", value: value3 }))
213125
213242
  ];
213126
213243
  }
213244
+ function renderSoftMask(mask, displayList, scale2) {
213245
+ const bitmap = renderDisplayListToBitmap({
213246
+ ...displayList,
213247
+ rotation: 0,
213248
+ glyphs: [],
213249
+ paths: [],
213250
+ images: [],
213251
+ operations: mask.operations
213252
+ }, { scale: scale2, transparent: true });
213253
+ const { data: data3 } = bitmap;
213254
+ for (let i = 0; i < data3.length; i += 4) {
213255
+ let value3 = data3[i + 3];
213256
+ if (mask.subtype === "Luminosity") {
213257
+ const alpha = value3 / 255;
213258
+ const r = Math.round(data3[i] * alpha + mask.backdrop.r * 255 * (1 - alpha));
213259
+ const g = Math.round(data3[i + 1] * alpha + mask.backdrop.g * 255 * (1 - alpha));
213260
+ const b3 = Math.round(data3[i + 2] * alpha + mask.backdrop.b * 255 * (1 - alpha));
213261
+ value3 = Math.round(pdfLum(r, g, b3));
213262
+ }
213263
+ data3[i] = data3[i + 1] = data3[i + 2] = 0;
213264
+ data3[i + 3] = mask.transferMap?.[value3] ?? value3;
213265
+ }
213266
+ return bitmap;
213267
+ }
213127
213268
  function renderDisplayListToBitmap(displayList, options = {}) {
213128
213269
  const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
213129
213270
  const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
@@ -213147,10 +213288,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213147
213288
  const aaTxt = options.antialiasText !== false;
213148
213289
  let cachedClips;
213149
213290
  let cachedClipMask;
213291
+ let cachedSoftMask;
213292
+ let cachedSoftMaskPixels;
213150
213293
  const imageClipMasks = /* @__PURE__ */ new Map();
213151
213294
  for (const original of paintOperations(displayList)) {
213152
213295
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
213153
- const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
213296
+ let operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
213297
+ if (operation.kind === "group") {
213298
+ const group = operation.value;
213299
+ const bitmap = renderDisplayListToBitmap({ ...displayList, rotation: 0, operations: group.operations }, { ...options, scale: scale2, dpiX: void 0, dpiY: void 0, cropRect: void 0, transparent: true });
213300
+ for (let i = 3; i < bitmap.data.length; i += 4) bitmap.data[i] = Math.round(bitmap.data[i] * group.alpha);
213301
+ operation = { kind: "image", value: {
213302
+ name: "TransparencyGroup",
213303
+ width: bitmap.width,
213304
+ height: bitmap.height,
213305
+ decodedRgba: bitmap.data,
213306
+ matrix: [bitmap.width / scale2, 0, 0, bitmap.height / scale2, 0, displayList.height - bitmap.height / scale2],
213307
+ colorSpace: "DeviceRGB",
213308
+ bitsPerComponent: 8,
213309
+ blendMode: group.blendMode,
213310
+ clipRect: group.clipRect
213311
+ } };
213312
+ }
213154
213313
  const clips = original.value.clipPaths;
213155
213314
  let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
213156
213315
  if (clips && !clipMask) {
@@ -213164,6 +213323,19 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213164
213323
  cachedClips = clips;
213165
213324
  cachedClipMask = clipMask;
213166
213325
  }
213326
+ const softMask = original.value.softMask;
213327
+ if (softMask) {
213328
+ if (softMask !== cachedSoftMask) {
213329
+ cachedSoftMaskPixels = renderSoftMask(softMask, displayList, scale2).data;
213330
+ cachedSoftMask = softMask;
213331
+ }
213332
+ if (clipMask) {
213333
+ clipMask = clipMask.slice();
213334
+ for (let i = 3; i < clipMask.length; i += 4) clipMask[i] = Math.round(clipMask[i] * cachedSoftMaskPixels[i] / 255);
213335
+ } else {
213336
+ clipMask = cachedSoftMaskPixels;
213337
+ }
213338
+ }
213167
213339
  const imageClips = original.value.clipImages;
213168
213340
  if (imageClips) {
213169
213341
  let imageMask = imageClipMasks.get(imageClips);
@@ -213267,6 +213439,17 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213267
213439
  const maxPx = Math.min(width2 - 1, clipMaxPx, Math.ceil(Math.max(...cornersPx)) - 1);
213268
213440
  const minPy = Math.max(0, clipMinPy, Math.floor(Math.min(...cornersPy)));
213269
213441
  const maxPy = Math.min(height - 1, clipMaxPy, Math.ceil(Math.max(...cornersPy)) - 1);
213442
+ if (minPx > maxPx || minPy > maxPy) continue;
213443
+ const source = downscaleImage(
213444
+ { width: img.width, height: img.height, data: img.decodedRgba },
213445
+ Math.hypot(d2, c4) * img.width / Math.abs(det * scale2),
213446
+ Math.hypot(b3, a3) * img.height / Math.abs(det * scale2)
213447
+ );
213448
+ const ax = a3 * scale2 / img.width, ay = b3 * scale2 / img.width;
213449
+ const bx = c4 * scale2 / img.height, by = d2 * scale2 / img.height;
213450
+ const s1 = ax * ax + ay * ay, s2 = bx * bx + by * by, cross = ax * bx + ay * by;
213451
+ const smooth = Math.fround((s1 + s2 + Math.hypot(s1 - s2, 2 * cross)) / 2) <= 1;
213452
+ const sample2 = new Float64Array(4);
213270
213453
  for (let py = minPy; py <= maxPy; py++) {
213271
213454
  const yPdf = displayList.height - (py + 0.5) / scale2;
213272
213455
  if (img.clipRect && (yPdf < img.clipRect[1] || yPdf > img.clipRect[3])) continue;
@@ -213278,9 +213461,14 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213278
213461
  const u = (d2 * dxPdf - c4 * dyPdf) / det;
213279
213462
  const v = (-b3 * dxPdf + a3 * dyPdf) / det;
213280
213463
  if (u < 0 || u > 1 || v < 0 || v > 1) continue;
213281
- const sx = Math.min(img.width - 1, Math.max(0, Math.floor(u * img.width)));
213282
- const sy = Math.min(img.height - 1, Math.max(0, Math.floor((1 - v) * img.height)));
213283
- const sIdx = (sy * img.width + sx) * 4;
213464
+ if (smooth) {
213465
+ sampleImageLinear(source, u * source.width - 0.5, (1 - v) * source.height - 0.5, sample2);
213466
+ } else {
213467
+ const sx = Math.min(source.width - 1, Math.max(0, Math.floor(u * source.width)));
213468
+ const sy = Math.min(source.height - 1, Math.max(0, Math.floor((1 - v) * source.height)));
213469
+ const sIdx = (sy * source.width + sx) * 4;
213470
+ for (let c22 = 0; c22 < 4; c22++) sample2[c22] = source.data[sIdx + c22];
213471
+ }
213284
213472
  blendPixel(
213285
213473
  rgba,
213286
213474
  width2,
@@ -213288,11 +213476,11 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213288
213476
  px,
213289
213477
  py,
213290
213478
  {
213291
- r: img.decodedRgba[sIdx] / 255,
213292
- g: img.decodedRgba[sIdx + 1] / 255,
213293
- b: img.decodedRgba[sIdx + 2] / 255
213479
+ r: sample2[0] / 255,
213480
+ g: sample2[1] / 255,
213481
+ b: sample2[2] / 255
213294
213482
  },
213295
- img.decodedRgba[sIdx + 3] / 255,
213483
+ sample2[3] / 255,
213296
213484
  img.blendMode,
213297
213485
  clipMask
213298
213486
  );
@@ -231877,6 +232065,7 @@ function compile(pattern, host) {
231877
232065
  let assertion;
231878
232066
  let behind = false;
231879
232067
  let atomic = false;
232068
+ let resetCaptures = false;
231880
232069
  let capture = pattern[at] === "?" ? void 0 : ++captures;
231881
232070
  if (pattern[at] === "?") {
231882
232071
  at++;
@@ -231885,6 +232074,37 @@ function compile(pattern, host) {
231885
232074
  else if (pattern[at] === ">") {
231886
232075
  at++;
231887
232076
  atomic = true;
232077
+ } else if (pattern[at] === "|") {
232078
+ at++;
232079
+ resetCaptures = true;
232080
+ } else if (pattern[at] === "(") {
232081
+ at++;
232082
+ let condition;
232083
+ if (pattern[at] === "?" && (pattern[at + 1] === "=" || pattern[at + 1] === "!" || pattern[at + 1] === "<" && (pattern[at + 2] === "=" || pattern[at + 2] === "!"))) {
232084
+ condition = { kind: "assertion", node: group({ ...mode }) };
232085
+ } else {
232086
+ const indices = [];
232087
+ if (pattern[at] === "<" || pattern[at] === "'") {
232088
+ const closing = pattern[at++] === "<" ? ">" : "'";
232089
+ namedReferences.push({ name: identifier(closing), indices });
232090
+ } else {
232091
+ if (!(pattern[at] >= "1" && pattern[at] <= "9"))
232092
+ return unsupported8();
232093
+ const index2 = integer7();
232094
+ if (index2 > 2147483647)
232095
+ return unsupported8();
232096
+ indices.push(index2);
232097
+ }
232098
+ if (pattern[at++] !== ")")
232099
+ return unsupported8();
232100
+ condition = { kind: "participation", indices };
232101
+ }
232102
+ const yes = sequence(mode);
232103
+ const no = pattern[at] === "|" ? (at++, sequence(mode)) : node3({ kind: "sequence", nodes: [] });
232104
+ if (pattern[at++] !== ")")
232105
+ return unsupported8();
232106
+ depth--;
232107
+ return node3({ kind: "conditional", condition, yes, no });
231888
232108
  } else if (pattern[at] === "=" || pattern[at] === "!")
231889
232109
  assertion = pattern[at++] === "!";
231890
232110
  else if (pattern[at] === "<" && (pattern[at + 1] === "=" || pattern[at + 1] === "!")) {
@@ -231952,7 +232172,7 @@ function compile(pattern, host) {
231952
232172
  return unsupported8("embedded modifier grammar");
231953
232173
  }
231954
232174
  }
231955
- const inner = alternative(mode);
232175
+ const inner = alternative(mode, resetCaptures);
231956
232176
  if (pattern[at++] !== ")")
231957
232177
  return unsupported8();
231958
232178
  depth--;
@@ -231987,7 +232207,7 @@ function compile(pattern, host) {
231987
232207
  } else {
231988
232208
  min = Infinity;
231989
232209
  max = 0;
231990
- for (const child7 of value3.nodes) {
232210
+ for (const child7 of value3.kind === "conditional" ? [value3.yes, value3.no] : value3.nodes) {
231991
232211
  const width2 = widthRange(child7);
231992
232212
  min = Math.min(min, width2.min);
231993
232213
  max = Math.max(max, width2.max);
@@ -232087,12 +232307,18 @@ function compile(pattern, host) {
232087
232307
  }
232088
232308
  return node3({ kind: "sequence", nodes: result3 });
232089
232309
  }
232090
- function alternative(mode) {
232310
+ function alternative(mode, resetCaptures = false) {
232311
+ const firstCapture = captures;
232091
232312
  const result3 = [sequence(mode)];
232313
+ let lastCapture = captures;
232092
232314
  while (pattern[at] === "|") {
232093
232315
  at++;
232316
+ if (resetCaptures)
232317
+ captures = firstCapture;
232094
232318
  result3.push(sequence(mode));
232319
+ lastCapture = Math.max(lastCapture, captures);
232095
232320
  }
232321
+ captures = lastCapture;
232096
232322
  return result3.length === 1 ? result3[0] : node3({ kind: "alternative", nodes: result3 });
232097
232323
  }
232098
232324
  const result2 = alternative(flags);
@@ -232144,6 +232370,23 @@ function* match2(node3, source, state, host) {
232144
232370
  return;
232145
232371
  }
232146
232372
  yield { ...state, position: position + length };
232373
+ } else if (node3.kind === "conditional") {
232374
+ let branch;
232375
+ if (node3.condition.kind === "participation") {
232376
+ for (const index2 of node3.condition.indices) {
232377
+ host.tick();
232378
+ if (state.captures[index2] !== void 0) {
232379
+ branch = state;
232380
+ break;
232381
+ }
232382
+ }
232383
+ } else {
232384
+ const inner = match2(node3.condition.node, source, state, host), result2 = inner.next();
232385
+ inner.return(void 0);
232386
+ if (!result2.done)
232387
+ branch = result2.value;
232388
+ }
232389
+ yield* match2(branch === void 0 ? node3.no : node3.yes, source, branch ?? state, host);
232147
232390
  } else if (node3.kind === "capture") {
232148
232391
  for (const result2 of match2(node3.node, source, state, host)) {
232149
232392
  const captures = [];
@@ -232219,6 +232462,11 @@ function* match2(node3, source, state, host) {
232219
232462
  host.tick();
232220
232463
  nested.push(descendant);
232221
232464
  }
232465
+ else if (child7.kind === "conditional") {
232466
+ nested.push(child7.yes, child7.no);
232467
+ if (child7.condition.kind === "assertion")
232468
+ nested.push(child7.condition.node);
232469
+ }
232222
232470
  }
232223
232471
  if (cleared.size) {
232224
232472
  const captures = [];
@@ -234018,6 +234266,11 @@ export {
234018
234266
  * Adapted from PDFium third_party/agg23/agg_curves.cpp, curve4_div.
234019
234267
  * See THIRD_PARTY_NOTICES.md for the pinned revision and adaptations.
234020
234268
  */
234269
+ /*!
234270
+ * Staged image reduction adapted from Mozilla PDF.js CanvasGraphics._scaleImage.
234271
+ * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
234272
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
234273
+ */
234021
234274
  /*! Bundled license information:
234022
234275
 
234023
234276
  tslib/tslib.js: