@poe-platform/safe-bash 0.1.762 → 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 (28) hide show
  1. package/dist/image-ast/index.browser.js +186 -55
  2. package/dist/image-ast/index.js +186 -55
  3. package/dist/pdf-ast/ast.d.ts +23 -0
  4. package/dist/pdf-ast/index.js +273 -91
  5. package/dist/safe-bash/command-chunks/{chunk-D4GXXV65.js → chunk-4XHONGIU.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-P3Q2QSCA.js → chunk-S3G2B4OX.js} +186 -55
  7. package/dist/safe-bash/command-chunks/{chunk-F7MJRXQ2.js → chunk-S5EX6UP5.js} +1 -1
  8. package/dist/safe-bash/core.browser.js +1 -1
  9. package/dist/safe-bash/shell/runtime.js +1 -1
  10. package/dist/safe-bash-checksum-engine/index.d.ts +1 -1
  11. package/dist/safe-bash-checksum-engine/index.js +5 -1
  12. package/dist/safe-bash-command-ffmpeg/index.js +7486 -7432
  13. package/dist/safe-bash-command-gh/index.js +174 -105
  14. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  15. package/dist/safe-bash-command-pandoc/command.js +3 -3
  16. package/dist/safe-bash-command-pandoc/index.js +3 -3
  17. package/dist/safe-bash-command-pdfimages/index.js +186 -55
  18. package/dist/safe-bash-command-pdfinfo/index.js +273 -91
  19. package/dist/safe-bash-command-pdftk/index.js +186 -55
  20. package/dist/safe-bash-command-pdftoppm/index.js +273 -91
  21. package/dist/safe-bash-command-pdftotext/index.js +186 -55
  22. package/dist/safe-bash-command-qpdf/index.js +186 -55
  23. package/dist/safe-bash-command-sips/index.js +2 -2
  24. package/dist/safe-bash-command-soffice/index.js +1 -1
  25. package/dist/safe-bash-command-ssconvert/index.js +249 -58
  26. package/dist/safe-bash-command-wkhtmltopdf/index.js +186 -55
  27. package/package.json +2 -2
  28. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +13 -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);
@@ -213165,6 +213241,30 @@ function paintOperations(displayList) {
213165
213241
  ...displayList.glyphs.map((value3) => ({ kind: "glyph", value: value3 }))
213166
213242
  ];
213167
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
+ }
213168
213268
  function renderDisplayListToBitmap(displayList, options = {}) {
213169
213269
  const baseScale = options.scale ?? (options.dpi ? options.dpi / 72 : 1.5);
213170
213270
  const scaleX = options.dpiX !== void 0 ? options.dpiX / 72 : baseScale;
@@ -213188,10 +213288,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213188
213288
  const aaTxt = options.antialiasText !== false;
213189
213289
  let cachedClips;
213190
213290
  let cachedClipMask;
213291
+ let cachedSoftMask;
213292
+ let cachedSoftMaskPixels;
213191
213293
  const imageClipMasks = /* @__PURE__ */ new Map();
213192
213294
  for (const original of paintOperations(displayList)) {
213193
213295
  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;
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
+ }
213195
213313
  const clips = original.value.clipPaths;
213196
213314
  let clipMask = clips && clips === cachedClips ? cachedClipMask : void 0;
213197
213315
  if (clips && !clipMask) {
@@ -213205,6 +213323,19 @@ function renderDisplayListToBitmap(displayList, options = {}) {
213205
213323
  cachedClips = clips;
213206
213324
  cachedClipMask = clipMask;
213207
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
+ }
213208
213339
  const imageClips = original.value.clipImages;
213209
213340
  if (imageClips) {
213210
213341
  let imageMask = imageClipMasks.get(imageClips);
@@ -231934,6 +232065,7 @@ function compile(pattern, host) {
231934
232065
  let assertion;
231935
232066
  let behind = false;
231936
232067
  let atomic = false;
232068
+ let resetCaptures = false;
231937
232069
  let capture = pattern[at] === "?" ? void 0 : ++captures;
231938
232070
  if (pattern[at] === "?") {
231939
232071
  at++;
@@ -231942,6 +232074,37 @@ function compile(pattern, host) {
231942
232074
  else if (pattern[at] === ">") {
231943
232075
  at++;
231944
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 });
231945
232108
  } else if (pattern[at] === "=" || pattern[at] === "!")
231946
232109
  assertion = pattern[at++] === "!";
231947
232110
  else if (pattern[at] === "<" && (pattern[at + 1] === "=" || pattern[at + 1] === "!")) {
@@ -232009,7 +232172,7 @@ function compile(pattern, host) {
232009
232172
  return unsupported8("embedded modifier grammar");
232010
232173
  }
232011
232174
  }
232012
- const inner = alternative(mode);
232175
+ const inner = alternative(mode, resetCaptures);
232013
232176
  if (pattern[at++] !== ")")
232014
232177
  return unsupported8();
232015
232178
  depth--;
@@ -232044,7 +232207,7 @@ function compile(pattern, host) {
232044
232207
  } else {
232045
232208
  min = Infinity;
232046
232209
  max = 0;
232047
- for (const child7 of value3.nodes) {
232210
+ for (const child7 of value3.kind === "conditional" ? [value3.yes, value3.no] : value3.nodes) {
232048
232211
  const width2 = widthRange(child7);
232049
232212
  min = Math.min(min, width2.min);
232050
232213
  max = Math.max(max, width2.max);
@@ -232144,12 +232307,18 @@ function compile(pattern, host) {
232144
232307
  }
232145
232308
  return node3({ kind: "sequence", nodes: result3 });
232146
232309
  }
232147
- function alternative(mode) {
232310
+ function alternative(mode, resetCaptures = false) {
232311
+ const firstCapture = captures;
232148
232312
  const result3 = [sequence(mode)];
232313
+ let lastCapture = captures;
232149
232314
  while (pattern[at] === "|") {
232150
232315
  at++;
232316
+ if (resetCaptures)
232317
+ captures = firstCapture;
232151
232318
  result3.push(sequence(mode));
232319
+ lastCapture = Math.max(lastCapture, captures);
232152
232320
  }
232321
+ captures = lastCapture;
232153
232322
  return result3.length === 1 ? result3[0] : node3({ kind: "alternative", nodes: result3 });
232154
232323
  }
232155
232324
  const result2 = alternative(flags);
@@ -232201,6 +232370,23 @@ function* match2(node3, source, state, host) {
232201
232370
  return;
232202
232371
  }
232203
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);
232204
232390
  } else if (node3.kind === "capture") {
232205
232391
  for (const result2 of match2(node3.node, source, state, host)) {
232206
232392
  const captures = [];
@@ -232276,6 +232462,11 @@ function* match2(node3, source, state, host) {
232276
232462
  host.tick();
232277
232463
  nested.push(descendant);
232278
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
+ }
232279
232470
  }
232280
232471
  if (cleared.size) {
232281
232472
  const captures = [];