@poe-platform/safe-bash 0.1.762 → 0.1.764

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 (35) hide show
  1. package/dist/image-ast/index.browser.js +454 -208
  2. package/dist/image-ast/index.js +454 -208
  3. package/dist/pdf-ast/ast.d.ts +23 -0
  4. package/dist/pdf-ast/index.js +543 -244
  5. package/dist/safe-bash/chunks/{chunk-CRQDMBQA.js → chunk-FSH7QRIC.js} +10 -1
  6. package/dist/safe-bash/command-chunks/{chunk-D4GXXV65.js → chunk-B7YLGJRF.js} +2 -2
  7. package/dist/safe-bash/command-chunks/{chunk-P3Q2QSCA.js → chunk-G3IIEU2N.js} +457 -208
  8. package/dist/safe-bash/command-chunks/{chunk-F7MJRXQ2.js → chunk-RDPJGIQF.js} +1 -1
  9. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  10. package/dist/safe-bash/commands/python/llm-module.js +3 -1
  11. package/dist/safe-bash/commands/python/shell-module.js +7 -0
  12. package/dist/safe-bash/core.browser.js +33 -13
  13. package/dist/safe-bash/shell/runtime.js +44 -12
  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 +7476 -7338
  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 +454 -208
  22. package/dist/safe-bash-command-pdfinfo/index.js +541 -244
  23. package/dist/safe-bash-command-pdftk/index.js +454 -208
  24. package/dist/safe-bash-command-pdftoppm/index.js +541 -244
  25. package/dist/safe-bash-command-pdftotext/index.js +454 -208
  26. package/dist/safe-bash-command-qpdf/index.js +454 -208
  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 +514 -208
  30. package/dist/safe-bash-command-wkhtmltopdf/index.js +455 -208
  31. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.d.ts +14 -0
  32. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.js +62 -0
  33. package/dist/safe-playwright-cloudflare/browser-snapshot-scheduler.js +8 -1
  34. package/package.json +2 -2
  35. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +27 -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);
@@ -212256,6 +212332,184 @@ function downscaleImage(image, widthScale, heightScale) {
212256
212332
  }
212257
212333
  return image;
212258
212334
  }
212335
+ var MAX_STROKE_VERTICES = 1e6;
212336
+ function dashSubpath(path2, pattern, phase) {
212337
+ const cycle = pattern.reduce((sum2, value3) => sum2 + value3, 0);
212338
+ if (!(cycle > 0)) return [path2];
212339
+ let offset = (phase % cycle + cycle) % cycle, index2 = 0;
212340
+ while (offset > 0) {
212341
+ if (offset < pattern[index2]) break;
212342
+ offset -= pattern[index2];
212343
+ index2 = (index2 + 1) % pattern.length;
212344
+ }
212345
+ let remaining = pattern[index2] - offset;
212346
+ const points = path2.closed ? [...path2.points, path2.points[0]] : path2.points;
212347
+ const result2 = [];
212348
+ let current = [];
212349
+ let steps = 0;
212350
+ const flush = () => {
212351
+ if (current.length) result2.push({ points: current, closed: false });
212352
+ current = [];
212353
+ };
212354
+ const advance2 = (point) => {
212355
+ while (remaining <= 0) {
212356
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError2("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
212357
+ if (index2 % 2 === 0) {
212358
+ if (pattern[index2] === 0) result2.push({ points: [point, point], closed: false });
212359
+ flush();
212360
+ }
212361
+ index2 = (index2 + 1) % pattern.length;
212362
+ remaining = pattern[index2];
212363
+ }
212364
+ };
212365
+ for (let i = 1; i < points.length; i++) {
212366
+ const start = points[i - 1], end2 = points[i];
212367
+ const dx = end2[0] - start[0], dy = end2[1] - start[1];
212368
+ const length = Math.hypot(dx, dy);
212369
+ if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
212370
+ throw new PdfError2("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
212371
+ }
212372
+ let distance2 = 0;
212373
+ while (distance2 < length) {
212374
+ const point = [start[0] + dx * distance2 / length, start[1] + dy * distance2 / length];
212375
+ advance2(point);
212376
+ const step = Math.min(remaining, length - distance2);
212377
+ if (distance2 + step === distance2 || ++steps > MAX_STROKE_VERTICES) throw new PdfError2("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
212378
+ distance2 += step;
212379
+ remaining -= step;
212380
+ if (index2 % 2 === 0) {
212381
+ if (!current.length) current.push(point);
212382
+ current.push([start[0] + dx * distance2 / length, start[1] + dy * distance2 / length]);
212383
+ }
212384
+ }
212385
+ }
212386
+ flush();
212387
+ if (path2.closed && result2.length) {
212388
+ const first = result2[0], last = result2[result2.length - 1];
212389
+ const start = path2.points[0];
212390
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
212391
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
212392
+ if (first === last) result2[0] = { points: first.points, closed: true };
212393
+ else {
212394
+ result2[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
212395
+ result2.pop();
212396
+ }
212397
+ }
212398
+ }
212399
+ return result2;
212400
+ }
212401
+ function strokeOutlines(paths, width2, cap, join3, miterLimit, dashArray = [], dashPhase = 0) {
212402
+ const half = width2 / 2;
212403
+ const contours = [];
212404
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
212405
+ let count = 0;
212406
+ let contour = [];
212407
+ const add5 = (x, y) => {
212408
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError2("E_LIMIT", "Stroke outline exceeds the vertex limit");
212409
+ contour.push([x, y]);
212410
+ };
212411
+ const arc = (point, dx1, dy1, dx2, dy2) => {
212412
+ let a1 = Math.atan2(dy1, dx1), a22 = Math.atan2(dy2, dx2);
212413
+ const ccw = a1 - a22 > 0 && a1 - a22 < Math.PI;
212414
+ const step = Math.acos(half / (half + 0.125)) * 2;
212415
+ add5(point[0] + dx1, point[1] + dy1);
212416
+ if (step > 0) {
212417
+ if (!ccw) {
212418
+ if (a1 > a22) a22 += 2 * Math.PI;
212419
+ a22 -= step / 4;
212420
+ if ((a22 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError2("E_LIMIT", "Stroke arc exceeds the vertex limit");
212421
+ for (a1 += step; a1 < a22; a1 += step) add5(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
212422
+ } else {
212423
+ if (a1 < a22) a22 -= 2 * Math.PI;
212424
+ a22 += step / 4;
212425
+ if ((a1 - a22) / step > MAX_STROKE_VERTICES - count) throw new PdfError2("E_LIMIT", "Stroke arc exceeds the vertex limit");
212426
+ for (a1 -= step; a1 > a22; a1 -= step) add5(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
212427
+ }
212428
+ }
212429
+ add5(point[0] + dx2, point[1] + dy2);
212430
+ };
212431
+ const addCap = (point, next) => {
212432
+ const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
212433
+ const dx = half * (next[1] - point[1]) / length;
212434
+ const dy = half * (next[0] - point[0]) / length;
212435
+ if (cap !== 1) {
212436
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
212437
+ add5(point[0] - dx - sx, point[1] + dy - sy);
212438
+ add5(point[0] + dx - sx, point[1] - dy - sy);
212439
+ } else {
212440
+ const angle = Math.atan2(dy, -dx);
212441
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
212442
+ add5(point[0] - dx, point[1] + dy);
212443
+ for (let a3 = angle + step; a3 < angle + Math.PI - step / 4; a3 += step) add5(point[0] + half * Math.cos(a3), point[1] + half * Math.sin(a3));
212444
+ add5(point[0] + dx, point[1] - dy);
212445
+ }
212446
+ };
212447
+ const addJoin = (prev, point, next) => {
212448
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
212449
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
212450
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
212451
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
212452
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
212453
+ if (!inner && join3 === 1) {
212454
+ arc(point, dx1, -dy1, dx2, -dy2);
212455
+ return;
212456
+ }
212457
+ if (inner || join3 === 0) {
212458
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
212459
+ const bx = point[0] + dx1, by = point[1] - dy1;
212460
+ const cx = point[0] + dx2, cy = point[1] - dy2;
212461
+ const dx = next[0] + dx2, dy = next[1] - dy2;
212462
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
212463
+ if (Math.abs(den) >= 1e-30) {
212464
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
212465
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
212466
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
212467
+ add5(x, y);
212468
+ return;
212469
+ }
212470
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
212471
+ add5(bx, by);
212472
+ return;
212473
+ }
212474
+ }
212475
+ add5(point[0] + dx1, point[1] - dy1);
212476
+ add5(point[0] + dx2, point[1] - dy2);
212477
+ };
212478
+ for (const path2 of paths) {
212479
+ for (const subpath of pattern.length ? dashSubpath(path2, pattern, dashPhase) : [path2]) {
212480
+ const points = [];
212481
+ for (const point of subpath.points) {
212482
+ const prev = points[points.length - 1];
212483
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
212484
+ }
212485
+ let closed = subpath.closed;
212486
+ if (closed && points.length > 1 && Math.hypot(points[0][0] - points[points.length - 1][0], points[0][1] - points[points.length - 1][1]) <= 1e-14) points.pop();
212487
+ if (points.length < 3) closed = false;
212488
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
212489
+ contour = [];
212490
+ const [x, y] = points[0];
212491
+ addCap([x, y], [x + 1, y]);
212492
+ addCap([x, y], [x - 1, y]);
212493
+ contours.push(contour);
212494
+ } else if (points.length >= 2) {
212495
+ contour = [];
212496
+ if (!closed) addCap(points[0], points[1]);
212497
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
212498
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
212499
+ }
212500
+ if (closed) {
212501
+ contours.push(contour);
212502
+ contour = [];
212503
+ } else addCap(points[points.length - 1], points[points.length - 2]);
212504
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
212505
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
212506
+ }
212507
+ contours.push(contour);
212508
+ }
212509
+ }
212510
+ }
212511
+ return contours;
212512
+ }
212259
212513
  function decodePng2(pngBytes) {
212260
212514
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
212261
212515
  throw new Error("Invalid PNG signature");
@@ -212950,111 +213204,60 @@ function blendPixel(rgba, width2, height, px, py, color5, alpha, blendMode, clip
212950
213204
  rgba[idx + 2] = Math.round((effB * a3 + cbB * dstA * (1 - a3)) / outA * 255);
212951
213205
  rgba[idx + 3] = Math.round(outA * 255);
212952
213206
  }
212953
- function drawAntiAliasedSegment(rgba, width2, height, x0, y0, x1, y1, strokeWidth, color5, alpha = 1, lineCap = 0, antialias = true, blendMode, clipMask) {
212954
- const halfW = Math.max(0.6, strokeWidth * 0.5);
212955
- const dx = x1 - x0;
212956
- const dy = y1 - y0;
212957
- const lenSq = dx * dx + dy * dy;
212958
- const segLen = Math.sqrt(lenSq);
212959
- const pad = lineCap === 2 ? halfW + 2 : halfW + 1;
212960
- const minX = Math.max(0, Math.floor(Math.min(x0, x1) - pad));
212961
- const maxX = Math.min(width2 - 1, Math.ceil(Math.max(x0, x1) + pad));
212962
- const minY = Math.max(0, Math.floor(Math.min(y0, y1) - pad));
212963
- const maxY = Math.min(height - 1, Math.ceil(Math.max(y0, y1) + pad));
212964
- for (let py = minY; py <= maxY; py++) {
212965
- for (let px = minX; px <= maxX; px++) {
212966
- const cx = px + 0.5;
212967
- const cy = py + 0.5;
212968
- if (segLen > 1e-6 && (lineCap === 0 || lineCap === 2)) {
212969
- const ux = dx / segLen;
212970
- const uy = dy / segLen;
212971
- const along = (cx - x0) * ux + (cy - y0) * uy;
212972
- const perp = Math.abs(-(cx - x0) * uy + (cy - y0) * ux);
212973
- const minAlong = lineCap === 2 ? -halfW : 0;
212974
- const maxAlong = lineCap === 2 ? segLen + halfW : segLen;
212975
- const overAlong = along < minAlong ? minAlong - along : along > maxAlong ? along - maxAlong : 0;
212976
- const dist2 = overAlong > 0 ? Math.max(perp, halfW + overAlong) : perp;
212977
- if (dist2 <= halfW + 0.75) {
212978
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist2)) : dist2 <= halfW + 0.25 ? 1 : 0;
212979
- blendPixel(rgba, width2, height, px, py, color5, cov * alpha, blendMode, clipMask);
212980
- }
212981
- continue;
212982
- }
212983
- let t = lenSq > 1e-6 ? ((cx - x0) * dx + (cy - y0) * dy) / lenSq : 0;
212984
- t = Math.max(0, Math.min(1, t));
212985
- const projX = x0 + t * dx;
212986
- const projY = y0 + t * dy;
212987
- const dist = Math.hypot(cx - projX, cy - projY);
212988
- if (dist <= halfW + 0.75) {
212989
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist)) : dist <= halfW + 0.25 ? 1 : 0;
212990
- blendPixel(rgba, width2, height, px, py, color5, cov * alpha, blendMode, clipMask);
212991
- }
213207
+ function segmentsToScreenPaths(segments, pageHeight, scale2) {
213208
+ const paths = [];
213209
+ let points = [];
213210
+ let current = [0, 0];
213211
+ const toScreen = (x, y) => [x * scale2, (pageHeight - y) * scale2];
213212
+ for (const segment of segments) {
213213
+ if (segment.kind === "move") {
213214
+ if (points.length) paths.push({ points, closed: false });
213215
+ current = toScreen(segment.x, segment.y);
213216
+ points = [current];
213217
+ } else if (segment.kind === "line") {
213218
+ if (!points.length) points = [current];
213219
+ current = toScreen(segment.x, segment.y);
213220
+ points.push(current);
213221
+ } else if (segment.kind === "cubic") {
213222
+ if (!points.length) points = [current];
213223
+ const a3 = toScreen(segment.x1, segment.y1), b3 = toScreen(segment.x2, segment.y2);
213224
+ const end2 = toScreen(segment.x, segment.y);
213225
+ const curve = flattenCubic(current[0], current[1], a3[0], a3[1], b3[0], b3[1], end2[0], end2[1]);
213226
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
213227
+ current = end2;
213228
+ } else if (segment.kind === "close") {
213229
+ if (points.length) {
213230
+ paths.push({ points, closed: true });
213231
+ current = points[0];
213232
+ points = [];
213233
+ }
213234
+ } else if (segment.kind === "rect") {
213235
+ if (points.length) paths.push({ points, closed: false });
213236
+ const first = toScreen(segment.x, segment.y);
213237
+ paths.push({ points: [
213238
+ first,
213239
+ toScreen(segment.x + segment.width, segment.y),
213240
+ toScreen(segment.x + segment.width, segment.y + segment.height),
213241
+ toScreen(segment.x, segment.y + segment.height)
213242
+ ], closed: true });
213243
+ current = first;
213244
+ points = [];
212992
213245
  }
212993
213246
  }
213247
+ if (points.length) paths.push({ points, closed: false });
213248
+ return paths;
212994
213249
  }
212995
- function segmentsToScreenEdges(segments, pageHeight, scale2, closeSubpaths = false) {
213250
+ function pathsToEdges(paths, closeSubpaths = false) {
212996
213251
  const edges2 = [];
212997
- let curX = 0;
212998
- let curY = 0;
212999
- let startX = 0;
213000
- let startY = 0;
213001
- let hasOpenSubpath = false;
213002
- const toScreen = (x, y) => [x * scale2, (pageHeight - y) * scale2];
213003
- for (const seg of segments) {
213004
- if (seg.kind === "move") {
213005
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
213006
- edges2.push({ x0: curX, y0: curY, x1: startX, y1: startY });
213007
- }
213008
- [curX, curY] = toScreen(seg.x, seg.y);
213009
- startX = curX;
213010
- startY = curY;
213011
- hasOpenSubpath = false;
213012
- } else if (seg.kind === "line") {
213013
- const [nx, ny] = toScreen(seg.x, seg.y);
213014
- edges2.push({ x0: curX, y0: curY, x1: nx, y1: ny });
213015
- curX = nx;
213016
- curY = ny;
213017
- hasOpenSubpath = true;
213018
- } else if (seg.kind === "cubic") {
213019
- const [p1x, p1y] = toScreen(seg.x1, seg.y1);
213020
- const [p2x, p2y] = toScreen(seg.x2, seg.y2);
213021
- const [p3x, p3y] = toScreen(seg.x, seg.y);
213022
- const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
213023
- let px = curX;
213024
- let py = curY;
213025
- for (let i = 1; i < points.length; i++) {
213026
- const [qx, qy] = points[i];
213027
- edges2.push({ x0: px, y0: py, x1: qx, y1: qy });
213028
- px = qx;
213029
- py = qy;
213030
- }
213031
- curX = p3x;
213032
- curY = p3y;
213033
- hasOpenSubpath = true;
213034
- } else if (seg.kind === "close") {
213035
- if (curX !== startX || curY !== startY) {
213036
- edges2.push({ x0: curX, y0: curY, x1: startX, y1: startY });
213037
- curX = startX;
213038
- curY = startY;
213039
- }
213040
- hasOpenSubpath = false;
213041
- } else if (seg.kind === "rect") {
213042
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
213043
- edges2.push({ x0: curX, y0: curY, x1: startX, y1: startY });
213044
- }
213045
- const [rx0, ry0] = toScreen(seg.x, seg.y);
213046
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
213047
- edges2.push(
213048
- { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
213049
- { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
213050
- { x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
213051
- { x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
213052
- );
213053
- hasOpenSubpath = false;
213252
+ for (const { points, closed } of paths) {
213253
+ for (let i = 1; i < points.length; i++) {
213254
+ const a3 = points[i - 1], b3 = points[i];
213255
+ edges2.push({ x0: a3[0], y0: a3[1], x1: b3[0], y1: b3[1] });
213256
+ }
213257
+ if ((closed || closeSubpaths) && points.length > 1) {
213258
+ const a3 = points[points.length - 1], b3 = points[0];
213259
+ edges2.push({ x0: a3[0], y0: a3[1], x1: b3[0], y1: b3[1] });
213054
213260
  }
213055
- }
213056
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
213057
- edges2.push({ x0: curX, y0: curY, x1: startX, y1: startY });
213058
213261
  }
213059
213262
  return edges2;
213060
213263
  }
@@ -213165,6 +213368,30 @@ function paintOperations(displayList) {
213165
213368
  ...displayList.glyphs.map((value3) => ({ kind: "glyph", value: value3 }))
213166
213369
  ];
213167
213370
  }
213371
+ function renderSoftMask(mask, displayList, scale2) {
213372
+ const bitmap = renderDisplayListToBitmap({
213373
+ ...displayList,
213374
+ rotation: 0,
213375
+ glyphs: [],
213376
+ paths: [],
213377
+ images: [],
213378
+ operations: mask.operations
213379
+ }, { scale: scale2, transparent: true });
213380
+ const { data: data3 } = bitmap;
213381
+ for (let i = 0; i < data3.length; i += 4) {
213382
+ let value3 = data3[i + 3];
213383
+ if (mask.subtype === "Luminosity") {
213384
+ const alpha = value3 / 255;
213385
+ const r = Math.round(data3[i] * alpha + mask.backdrop.r * 255 * (1 - alpha));
213386
+ const g = Math.round(data3[i + 1] * alpha + mask.backdrop.g * 255 * (1 - alpha));
213387
+ const b3 = Math.round(data3[i + 2] * alpha + mask.backdrop.b * 255 * (1 - alpha));
213388
+ value3 = Math.round(pdfLum(r, g, b3));
213389
+ }
213390
+ data3[i] = data3[i + 1] = data3[i + 2] = 0;
213391
+ data3[i + 3] = mask.transferMap?.[value3] ?? value3;
213392
+ }
213393
+ return bitmap;
213394
+ }
213168
213395
  function renderDisplayListToBitmap(displayList, options = {}) {
213169
213396
  const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
213170
213397
  const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
@@ -213188,10 +213415,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213188
213415
  const aaTxt = options.antialiasText !== false;
213189
213416
  let cachedClips;
213190
213417
  let cachedClipMask;
213418
+ let cachedSoftMask;
213419
+ let cachedSoftMaskPixels;
213191
213420
  const imageClipMasks = /* @__PURE__ */ new Map();
213192
213421
  for (const original of paintOperations(displayList)) {
213193
213422
  if (original.kind === "glyph" && (original.value.renderMode === 3 || !original.value.outline && !original.value.unicode.trim())) continue;
213194
- const operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
213423
+ let operation = original.kind === "glyph" ? { kind: "path", value: glyphPaint(original.value) } : original;
213424
+ if (operation.kind === "group") {
213425
+ const group = operation.value;
213426
+ const bitmap = renderDisplayListToBitmap({ ...displayList, rotation: 0, operations: group.operations }, { ...options, scale: scale2, dpiX: void 0, dpiY: void 0, cropRect: void 0, transparent: true });
213427
+ for (let i = 3; i < bitmap.data.length; i += 4) bitmap.data[i] = Math.round(bitmap.data[i] * group.alpha);
213428
+ operation = { kind: "image", value: {
213429
+ name: "TransparencyGroup",
213430
+ width: bitmap.width,
213431
+ height: bitmap.height,
213432
+ decodedRgba: bitmap.data,
213433
+ matrix: [bitmap.width / scale2, 0, 0, bitmap.height / scale2, 0, displayList.height - bitmap.height / scale2],
213434
+ colorSpace: "DeviceRGB",
213435
+ bitsPerComponent: 8,
213436
+ blendMode: group.blendMode,
213437
+ clipRect: group.clipRect
213438
+ } };
213439
+ }
213195
213440
  const clips = original.value.clipPaths;
213196
213441
  let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
213197
213442
  if (clips && !clipMask) {
@@ -213199,12 +213444,25 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213199
213444
  for (const clip2 of clips) {
213200
213445
  const { segments, fillRule } = "segments" in clip2 ? clip2 : { segments: clip2, fillRule: "nonzero" };
213201
213446
  const layer = new Uint8Array(width2 * height * 4);
213202
- fillEdgesScanline4x4(layer, width2, height, segmentsToScreenEdges(segments, displayList.height, scale2, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
213447
+ fillEdgesScanline4x4(layer, width2, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale2), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
213203
213448
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
213204
213449
  }
213205
213450
  cachedClips = clips;
213206
213451
  cachedClipMask = clipMask;
213207
213452
  }
213453
+ const softMask = original.value.softMask;
213454
+ if (softMask) {
213455
+ if (softMask !== cachedSoftMask) {
213456
+ cachedSoftMaskPixels = renderSoftMask(softMask, displayList, scale2).data;
213457
+ cachedSoftMask = softMask;
213458
+ }
213459
+ if (clipMask) {
213460
+ clipMask = clipMask.slice();
213461
+ for (let i = 3; i < clipMask.length; i += 4) clipMask[i] = Math.round(clipMask[i] * cachedSoftMaskPixels[i] / 255);
213462
+ } else {
213463
+ clipMask = cachedSoftMaskPixels;
213464
+ }
213465
+ }
213208
213466
  const imageClips = original.value.clipImages;
213209
213467
  if (imageClips) {
213210
213468
  let imageMask = imageClipMasks.get(imageClips);
@@ -213233,62 +213491,38 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213233
213491
  if (operation.kind === "path") {
213234
213492
  const path2 = operation.value;
213235
213493
  if (path2.fillColor) {
213236
- const edges2 = segmentsToScreenEdges(path2.segments, displayList.height, scale2, true);
213494
+ const edges2 = pathsToEdges(segmentsToScreenPaths(path2.segments, displayList.height, scale2), true);
213237
213495
  const clipScreen = path2.clipRect ? [path2.clipRect[0] * scale2, (displayList.height - path2.clipRect[3]) * scale2, path2.clipRect[2] * scale2, (displayList.height - path2.clipRect[1]) * scale2] : void 0;
213238
213496
  fillEdgesScanline4x4(rgba, width2, height, edges2, path2.fillColor, path2.fillAlpha ?? 1, path2.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path2.blendMode, clipMask);
213239
213497
  }
213240
213498
  if (path2.strokeColor) {
213241
- const edges2 = segmentsToScreenEdges(path2.segments, displayList.height, scale2, false);
213242
213499
  const rawSw = path2.strokeWidth * scale2;
213243
213500
  const sw = Math.max(1, rawSw);
213244
213501
  const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path2.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path2.strokeAlpha ?? 1;
213245
- const dashArr = path2.dashArray && path2.dashArray.length > 0 ? path2.dashArray.map((d2) => Math.max(0, d2 * scale2)) : void 0;
213246
- const dashCycle = dashArr ? dashArr.reduce((a3, b3) => a3 + b3, 0) : 0;
213247
- let dashDist = (path2.dashPhase ?? 0) * scale2 % (dashCycle || 1);
213248
- if (dashDist < 0) dashDist += dashCycle;
213249
- for (const e of edges2) {
213250
- if (!dashArr || dashCycle <= 1e-4) {
213251
- drawAntiAliasedSegment(rgba, width2, height, e.x0, e.y0, e.x1, e.y1, sw, path2.strokeColor, strokeAlpha, path2.lineCap ?? 0, original.kind === "glyph" ? aaTxt : aaVec, path2.blendMode, clipMask);
213252
- } else {
213253
- const dx = e.x1 - e.x0;
213254
- const dy = e.y1 - e.y0;
213255
- const edgeLen = Math.hypot(dx, dy);
213256
- if (edgeLen <= 1e-4) continue;
213257
- let pos = 0;
213258
- while (pos < edgeLen) {
213259
- let cycleRem = dashDist % dashCycle;
213260
- let dIdx = 0;
213261
- while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
213262
- cycleRem -= dashArr[dIdx];
213263
- dIdx++;
213264
- }
213265
- const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
213266
- const step = Math.min(edgeLen - pos, segRemainInDash);
213267
- if (dIdx % 2 === 0) {
213268
- const t0 = pos / edgeLen;
213269
- const t1 = (pos + step) / edgeLen;
213270
- drawAntiAliasedSegment(
213271
- rgba,
213272
- width2,
213273
- height,
213274
- e.x0 + dx * t0,
213275
- e.y0 + dy * t0,
213276
- e.x0 + dx * t1,
213277
- e.y0 + dy * t1,
213278
- sw,
213279
- path2.strokeColor,
213280
- strokeAlpha,
213281
- path2.lineCap ?? 0,
213282
- original.kind === "glyph" ? aaTxt : aaVec,
213283
- path2.blendMode,
213284
- clipMask
213285
- );
213286
- }
213287
- pos += step;
213288
- dashDist = (dashDist + step) % dashCycle;
213289
- }
213290
- }
213291
- }
213502
+ const contours = strokeOutlines(
213503
+ segmentsToScreenPaths(path2.segments, displayList.height, scale2),
213504
+ sw,
213505
+ path2.lineCap ?? 0,
213506
+ path2.lineJoin ?? 0,
213507
+ path2.miterLimit ?? 10,
213508
+ path2.dashArray?.map((value3) => Math.max(0, value3 * scale2)),
213509
+ (path2.dashPhase ?? 0) * scale2
213510
+ );
213511
+ const edges2 = pathsToEdges(contours.map((points) => ({ points, closed: true })));
213512
+ const clipScreen = path2.clipRect ? [path2.clipRect[0] * scale2, (displayList.height - path2.clipRect[3]) * scale2, path2.clipRect[2] * scale2, (displayList.height - path2.clipRect[1]) * scale2] : void 0;
213513
+ fillEdgesScanline4x4(
213514
+ rgba,
213515
+ width2,
213516
+ height,
213517
+ edges2,
213518
+ path2.strokeColor,
213519
+ strokeAlpha,
213520
+ "nonzero",
213521
+ clipScreen,
213522
+ original.kind === "glyph" ? aaTxt : aaVec,
213523
+ path2.blendMode,
213524
+ clipMask
213525
+ );
213292
213526
  }
213293
213527
  } else if (operation.kind === "image") {
213294
213528
  const img = operation.value;
@@ -231934,6 +232168,7 @@ function compile(pattern, host) {
231934
232168
  let assertion;
231935
232169
  let behind = false;
231936
232170
  let atomic = false;
232171
+ let resetCaptures = false;
231937
232172
  let capture = pattern[at] === "?" ? void 0 : ++captures;
231938
232173
  if (pattern[at] === "?") {
231939
232174
  at++;
@@ -231942,6 +232177,37 @@ function compile(pattern, host) {
231942
232177
  else if (pattern[at] === ">") {
231943
232178
  at++;
231944
232179
  atomic = true;
232180
+ } else if (pattern[at] === "|") {
232181
+ at++;
232182
+ resetCaptures = true;
232183
+ } else if (pattern[at] === "(") {
232184
+ at++;
232185
+ let condition;
232186
+ if (pattern[at] === "?" && (pattern[at + 1] === "=" || pattern[at + 1] === "!" || pattern[at + 1] === "<" && (pattern[at + 2] === "=" || pattern[at + 2] === "!"))) {
232187
+ condition = { kind: "assertion", node: group({ ...mode }) };
232188
+ } else {
232189
+ const indices = [];
232190
+ if (pattern[at] === "<" || pattern[at] === "'") {
232191
+ const closing = pattern[at++] === "<" ? ">" : "'";
232192
+ namedReferences.push({ name: identifier(closing), indices });
232193
+ } else {
232194
+ if (!(pattern[at] >= "1" && pattern[at] <= "9"))
232195
+ return unsupported8();
232196
+ const index2 = integer7();
232197
+ if (index2 > 2147483647)
232198
+ return unsupported8();
232199
+ indices.push(index2);
232200
+ }
232201
+ if (pattern[at++] !== ")")
232202
+ return unsupported8();
232203
+ condition = { kind: "participation", indices };
232204
+ }
232205
+ const yes = sequence(mode);
232206
+ const no = pattern[at] === "|" ? (at++, sequence(mode)) : node3({ kind: "sequence", nodes: [] });
232207
+ if (pattern[at++] !== ")")
232208
+ return unsupported8();
232209
+ depth--;
232210
+ return node3({ kind: "conditional", condition, yes, no });
231945
232211
  } else if (pattern[at] === "=" || pattern[at] === "!")
231946
232212
  assertion = pattern[at++] === "!";
231947
232213
  else if (pattern[at] === "<" && (pattern[at + 1] === "=" || pattern[at + 1] === "!")) {
@@ -232009,7 +232275,7 @@ function compile(pattern, host) {
232009
232275
  return unsupported8("embedded modifier grammar");
232010
232276
  }
232011
232277
  }
232012
- const inner = alternative(mode);
232278
+ const inner = alternative(mode, resetCaptures);
232013
232279
  if (pattern[at++] !== ")")
232014
232280
  return unsupported8();
232015
232281
  depth--;
@@ -232044,7 +232310,7 @@ function compile(pattern, host) {
232044
232310
  } else {
232045
232311
  min = Infinity;
232046
232312
  max = 0;
232047
- for (const child7 of value3.nodes) {
232313
+ for (const child7 of value3.kind === "conditional" ? [value3.yes, value3.no] : value3.nodes) {
232048
232314
  const width2 = widthRange(child7);
232049
232315
  min = Math.min(min, width2.min);
232050
232316
  max = Math.max(max, width2.max);
@@ -232144,12 +232410,18 @@ function compile(pattern, host) {
232144
232410
  }
232145
232411
  return node3({ kind: "sequence", nodes: result3 });
232146
232412
  }
232147
- function alternative(mode) {
232413
+ function alternative(mode, resetCaptures = false) {
232414
+ const firstCapture = captures;
232148
232415
  const result3 = [sequence(mode)];
232416
+ let lastCapture = captures;
232149
232417
  while (pattern[at] === "|") {
232150
232418
  at++;
232419
+ if (resetCaptures)
232420
+ captures = firstCapture;
232151
232421
  result3.push(sequence(mode));
232422
+ lastCapture = Math.max(lastCapture, captures);
232152
232423
  }
232424
+ captures = lastCapture;
232153
232425
  return result3.length === 1 ? result3[0] : node3({ kind: "alternative", nodes: result3 });
232154
232426
  }
232155
232427
  const result2 = alternative(flags);
@@ -232201,6 +232473,23 @@ function* match2(node3, source, state, host) {
232201
232473
  return;
232202
232474
  }
232203
232475
  yield { ...state, position: position + length };
232476
+ } else if (node3.kind === "conditional") {
232477
+ let branch;
232478
+ if (node3.condition.kind === "participation") {
232479
+ for (const index2 of node3.condition.indices) {
232480
+ host.tick();
232481
+ if (state.captures[index2] !== void 0) {
232482
+ branch = state;
232483
+ break;
232484
+ }
232485
+ }
232486
+ } else {
232487
+ const inner = match2(node3.condition.node, source, state, host), result2 = inner.next();
232488
+ inner.return(void 0);
232489
+ if (!result2.done)
232490
+ branch = result2.value;
232491
+ }
232492
+ yield* match2(branch === void 0 ? node3.no : node3.yes, source, branch ?? state, host);
232204
232493
  } else if (node3.kind === "capture") {
232205
232494
  for (const result2 of match2(node3.node, source, state, host)) {
232206
232495
  const captures = [];
@@ -232276,6 +232565,11 @@ function* match2(node3, source, state, host) {
232276
232565
  host.tick();
232277
232566
  nested.push(descendant);
232278
232567
  }
232568
+ else if (child7.kind === "conditional") {
232569
+ nested.push(child7.yes, child7.no);
232570
+ if (child7.condition.kind === "assertion")
232571
+ nested.push(child7.condition.node);
232572
+ }
232279
232573
  }
232280
232574
  if (cleared.size) {
232281
232575
  const captures = [];
@@ -234080,6 +234374,18 @@ export {
234080
234374
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
234081
234375
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
234082
234376
  */
234377
+ /*!
234378
+ * Anti-Grain Geometry - Version 2.3
234379
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
234380
+ *
234381
+ * Permission to copy, use, modify, sell and distribute this software
234382
+ * is granted provided this copyright notice appears in all copies.
234383
+ * This software is provided "as is" without express or implied
234384
+ * warranty, and with no claim as to its suitability for any purpose.
234385
+ *
234386
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
234387
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
234388
+ */
234083
234389
  /*! Bundled license information:
234084
234390
 
234085
234391
  tslib/tslib.js: