@poe-platform/safe-bash 0.1.763 → 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 (31) hide show
  1. package/dist/image-ast/index.browser.js +268 -153
  2. package/dist/image-ast/index.js +268 -153
  3. package/dist/pdf-ast/index.js +270 -153
  4. package/dist/safe-bash/chunks/{chunk-CRQDMBQA.js → chunk-FSH7QRIC.js} +10 -1
  5. package/dist/safe-bash/command-chunks/{chunk-4XHONGIU.js → chunk-B7YLGJRF.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-S3G2B4OX.js → chunk-G3IIEU2N.js} +271 -153
  7. package/dist/safe-bash/command-chunks/{chunk-S5EX6UP5.js → chunk-RDPJGIQF.js} +1 -1
  8. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  9. package/dist/safe-bash/commands/python/llm-module.js +3 -1
  10. package/dist/safe-bash/commands/python/shell-module.js +7 -0
  11. package/dist/safe-bash/core.browser.js +32 -12
  12. package/dist/safe-bash/shell/runtime.js +43 -11
  13. package/dist/safe-bash-command-ffmpeg/index.js +5649 -5565
  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 +268 -153
  18. package/dist/safe-bash-command-pdfinfo/index.js +268 -153
  19. package/dist/safe-bash-command-pdftk/index.js +268 -153
  20. package/dist/safe-bash-command-pdftoppm/index.js +268 -153
  21. package/dist/safe-bash-command-pdftotext/index.js +268 -153
  22. package/dist/safe-bash-command-qpdf/index.js +268 -153
  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 +265 -150
  26. package/dist/safe-bash-command-wkhtmltopdf/index.js +269 -153
  27. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.d.ts +14 -0
  28. package/dist/safe-playwright-cloudflare/browser-snapshot-labels.js +62 -0
  29. package/dist/safe-playwright-cloudflare/browser-snapshot-scheduler.js +8 -1
  30. package/package.json +2 -2
  31. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +14 -0
@@ -39389,6 +39389,184 @@ function downscaleImage(image, widthScale, heightScale) {
39389
39389
  }
39390
39390
  return image;
39391
39391
  }
39392
+ var MAX_STROKE_VERTICES = 1e6;
39393
+ function dashSubpath(path, pattern, phase) {
39394
+ const cycle = pattern.reduce((sum, value) => sum + value, 0);
39395
+ if (!(cycle > 0)) return [path];
39396
+ let offset = (phase % cycle + cycle) % cycle, index = 0;
39397
+ while (offset > 0) {
39398
+ if (offset < pattern[index]) break;
39399
+ offset -= pattern[index];
39400
+ index = (index + 1) % pattern.length;
39401
+ }
39402
+ let remaining = pattern[index] - offset;
39403
+ const points = path.closed ? [...path.points, path.points[0]] : path.points;
39404
+ const result = [];
39405
+ let current = [];
39406
+ let steps = 0;
39407
+ const flush = () => {
39408
+ if (current.length) result.push({ points: current, closed: false });
39409
+ current = [];
39410
+ };
39411
+ const advance = (point) => {
39412
+ while (remaining <= 0) {
39413
+ if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
39414
+ if (index % 2 === 0) {
39415
+ if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
39416
+ flush();
39417
+ }
39418
+ index = (index + 1) % pattern.length;
39419
+ remaining = pattern[index];
39420
+ }
39421
+ };
39422
+ for (let i = 1; i < points.length; i++) {
39423
+ const start = points[i - 1], end = points[i];
39424
+ const dx = end[0] - start[0], dy = end[1] - start[1];
39425
+ const length = Math.hypot(dx, dy);
39426
+ if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
39427
+ throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
39428
+ }
39429
+ let distance = 0;
39430
+ while (distance < length) {
39431
+ const point = [start[0] + dx * distance / length, start[1] + dy * distance / length];
39432
+ advance(point);
39433
+ const step = Math.min(remaining, length - distance);
39434
+ if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
39435
+ distance += step;
39436
+ remaining -= step;
39437
+ if (index % 2 === 0) {
39438
+ if (!current.length) current.push(point);
39439
+ current.push([start[0] + dx * distance / length, start[1] + dy * distance / length]);
39440
+ }
39441
+ }
39442
+ }
39443
+ flush();
39444
+ if (path.closed && result.length) {
39445
+ const first = result[0], last = result[result.length - 1];
39446
+ const start = path.points[0];
39447
+ const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
39448
+ if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
39449
+ if (first === last) result[0] = { points: first.points, closed: true };
39450
+ else {
39451
+ result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
39452
+ result.pop();
39453
+ }
39454
+ }
39455
+ }
39456
+ return result;
39457
+ }
39458
+ function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
39459
+ const half = width / 2;
39460
+ const contours = [];
39461
+ const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
39462
+ let count = 0;
39463
+ let contour = [];
39464
+ const add = (x, y) => {
39465
+ if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
39466
+ contour.push([x, y]);
39467
+ };
39468
+ const arc = (point, dx1, dy1, dx2, dy2) => {
39469
+ let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
39470
+ const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
39471
+ const step = Math.acos(half / (half + 0.125)) * 2;
39472
+ add(point[0] + dx1, point[1] + dy1);
39473
+ if (step > 0) {
39474
+ if (!ccw) {
39475
+ if (a1 > a2) a2 += 2 * Math.PI;
39476
+ a2 -= step / 4;
39477
+ if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
39478
+ for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
39479
+ } else {
39480
+ if (a1 < a2) a2 -= 2 * Math.PI;
39481
+ a2 += step / 4;
39482
+ if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
39483
+ for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
39484
+ }
39485
+ }
39486
+ add(point[0] + dx2, point[1] + dy2);
39487
+ };
39488
+ const addCap = (point, next) => {
39489
+ const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
39490
+ const dx = half * (next[1] - point[1]) / length;
39491
+ const dy = half * (next[0] - point[0]) / length;
39492
+ if (cap !== 1) {
39493
+ const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
39494
+ add(point[0] - dx - sx, point[1] + dy - sy);
39495
+ add(point[0] + dx - sx, point[1] - dy - sy);
39496
+ } else {
39497
+ const angle = Math.atan2(dy, -dx);
39498
+ const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
39499
+ add(point[0] - dx, point[1] + dy);
39500
+ for (let a = angle + step; a < angle + Math.PI - step / 4; a += step) add(point[0] + half * Math.cos(a), point[1] + half * Math.sin(a));
39501
+ add(point[0] + dx, point[1] - dy);
39502
+ }
39503
+ };
39504
+ const addJoin = (prev, point, next) => {
39505
+ const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
39506
+ const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
39507
+ const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
39508
+ const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
39509
+ const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
39510
+ if (!inner && join === 1) {
39511
+ arc(point, dx1, -dy1, dx2, -dy2);
39512
+ return;
39513
+ }
39514
+ if (inner || join === 0) {
39515
+ const ax = prev[0] + dx1, ay = prev[1] - dy1;
39516
+ const bx = point[0] + dx1, by = point[1] - dy1;
39517
+ const cx = point[0] + dx2, cy = point[1] - dy2;
39518
+ const dx = next[0] + dx2, dy = next[1] - dy2;
39519
+ const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
39520
+ if (Math.abs(den) >= 1e-30) {
39521
+ const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
39522
+ const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
39523
+ if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
39524
+ add(x, y);
39525
+ return;
39526
+ }
39527
+ } else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
39528
+ add(bx, by);
39529
+ return;
39530
+ }
39531
+ }
39532
+ add(point[0] + dx1, point[1] - dy1);
39533
+ add(point[0] + dx2, point[1] - dy2);
39534
+ };
39535
+ for (const path of paths) {
39536
+ for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
39537
+ const points = [];
39538
+ for (const point of subpath.points) {
39539
+ const prev = points[points.length - 1];
39540
+ if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
39541
+ }
39542
+ let closed = subpath.closed;
39543
+ 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();
39544
+ if (points.length < 3) closed = false;
39545
+ if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
39546
+ contour = [];
39547
+ const [x, y] = points[0];
39548
+ addCap([x, y], [x + 1, y]);
39549
+ addCap([x, y], [x - 1, y]);
39550
+ contours.push(contour);
39551
+ } else if (points.length >= 2) {
39552
+ contour = [];
39553
+ if (!closed) addCap(points[0], points[1]);
39554
+ for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
39555
+ addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
39556
+ }
39557
+ if (closed) {
39558
+ contours.push(contour);
39559
+ contour = [];
39560
+ } else addCap(points[points.length - 1], points[points.length - 2]);
39561
+ for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
39562
+ addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
39563
+ }
39564
+ contours.push(contour);
39565
+ }
39566
+ }
39567
+ }
39568
+ return contours;
39569
+ }
39392
39570
  function decodePng(pngBytes) {
39393
39571
  if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
39394
39572
  throw new Error("Invalid PNG signature");
@@ -40083,111 +40261,60 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
40083
40261
  rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
40084
40262
  rgba[idx + 3] = Math.round(outA * 255);
40085
40263
  }
40086
- function drawAntiAliasedSegment(rgba, width, height, x0, y0, x1, y1, strokeWidth, color, alpha = 1, lineCap = 0, antialias = true, blendMode, clipMask) {
40087
- const halfW = Math.max(0.6, strokeWidth * 0.5);
40088
- const dx = x1 - x0;
40089
- const dy = y1 - y0;
40090
- const lenSq = dx * dx + dy * dy;
40091
- const segLen = Math.sqrt(lenSq);
40092
- const pad = lineCap === 2 ? halfW + 2 : halfW + 1;
40093
- const minX = Math.max(0, Math.floor(Math.min(x0, x1) - pad));
40094
- const maxX = Math.min(width - 1, Math.ceil(Math.max(x0, x1) + pad));
40095
- const minY = Math.max(0, Math.floor(Math.min(y0, y1) - pad));
40096
- const maxY = Math.min(height - 1, Math.ceil(Math.max(y0, y1) + pad));
40097
- for (let py = minY; py <= maxY; py++) {
40098
- for (let px = minX; px <= maxX; px++) {
40099
- const cx = px + 0.5;
40100
- const cy = py + 0.5;
40101
- if (segLen > 1e-6 && (lineCap === 0 || lineCap === 2)) {
40102
- const ux = dx / segLen;
40103
- const uy = dy / segLen;
40104
- const along = (cx - x0) * ux + (cy - y0) * uy;
40105
- const perp = Math.abs(-(cx - x0) * uy + (cy - y0) * ux);
40106
- const minAlong = lineCap === 2 ? -halfW : 0;
40107
- const maxAlong = lineCap === 2 ? segLen + halfW : segLen;
40108
- const overAlong = along < minAlong ? minAlong - along : along > maxAlong ? along - maxAlong : 0;
40109
- const dist2 = overAlong > 0 ? Math.max(perp, halfW + overAlong) : perp;
40110
- if (dist2 <= halfW + 0.75) {
40111
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist2)) : dist2 <= halfW + 0.25 ? 1 : 0;
40112
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
40113
- }
40114
- continue;
40115
- }
40116
- let t = lenSq > 1e-6 ? ((cx - x0) * dx + (cy - y0) * dy) / lenSq : 0;
40117
- t = Math.max(0, Math.min(1, t));
40118
- const projX = x0 + t * dx;
40119
- const projY = y0 + t * dy;
40120
- const dist = Math.hypot(cx - projX, cy - projY);
40121
- if (dist <= halfW + 0.75) {
40122
- const cov = antialias ? Math.max(0, Math.min(1, halfW + 0.5 - dist)) : dist <= halfW + 0.25 ? 1 : 0;
40123
- blendPixel(rgba, width, height, px, py, color, cov * alpha, blendMode, clipMask);
40124
- }
40125
- }
40126
- }
40127
- }
40128
- function segmentsToScreenEdges(segments, pageHeight, scale, closeSubpaths = false) {
40129
- const edges = [];
40130
- let curX = 0;
40131
- let curY = 0;
40132
- let startX = 0;
40133
- let startY = 0;
40134
- let hasOpenSubpath = false;
40264
+ function segmentsToScreenPaths(segments, pageHeight, scale) {
40265
+ const paths = [];
40266
+ let points = [];
40267
+ let current = [0, 0];
40135
40268
  const toScreen = (x, y) => [x * scale, (pageHeight - y) * scale];
40136
- for (const seg of segments) {
40137
- if (seg.kind === "move") {
40138
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40139
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40140
- }
40141
- [curX, curY] = toScreen(seg.x, seg.y);
40142
- startX = curX;
40143
- startY = curY;
40144
- hasOpenSubpath = false;
40145
- } else if (seg.kind === "line") {
40146
- const [nx, ny] = toScreen(seg.x, seg.y);
40147
- edges.push({ x0: curX, y0: curY, x1: nx, y1: ny });
40148
- curX = nx;
40149
- curY = ny;
40150
- hasOpenSubpath = true;
40151
- } else if (seg.kind === "cubic") {
40152
- const [p1x, p1y] = toScreen(seg.x1, seg.y1);
40153
- const [p2x, p2y] = toScreen(seg.x2, seg.y2);
40154
- const [p3x, p3y] = toScreen(seg.x, seg.y);
40155
- const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
40156
- let px = curX;
40157
- let py = curY;
40158
- for (let i = 1; i < points.length; i++) {
40159
- const [qx, qy] = points[i];
40160
- edges.push({ x0: px, y0: py, x1: qx, y1: qy });
40161
- px = qx;
40162
- py = qy;
40163
- }
40164
- curX = p3x;
40165
- curY = p3y;
40166
- hasOpenSubpath = true;
40167
- } else if (seg.kind === "close") {
40168
- if (curX !== startX || curY !== startY) {
40169
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40170
- curX = startX;
40171
- curY = startY;
40172
- }
40173
- hasOpenSubpath = false;
40174
- } else if (seg.kind === "rect") {
40175
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40176
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40177
- }
40178
- const [rx0, ry0] = toScreen(seg.x, seg.y);
40179
- const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
40180
- edges.push(
40181
- { x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
40182
- { x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
40183
- { x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
40184
- { x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
40185
- );
40186
- hasOpenSubpath = false;
40269
+ for (const segment of segments) {
40270
+ if (segment.kind === "move") {
40271
+ if (points.length) paths.push({ points, closed: false });
40272
+ current = toScreen(segment.x, segment.y);
40273
+ points = [current];
40274
+ } else if (segment.kind === "line") {
40275
+ if (!points.length) points = [current];
40276
+ current = toScreen(segment.x, segment.y);
40277
+ points.push(current);
40278
+ } else if (segment.kind === "cubic") {
40279
+ if (!points.length) points = [current];
40280
+ const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
40281
+ const end = toScreen(segment.x, segment.y);
40282
+ const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
40283
+ for (let i = 1; i < curve.length; i++) points.push(curve[i]);
40284
+ current = end;
40285
+ } else if (segment.kind === "close") {
40286
+ if (points.length) {
40287
+ paths.push({ points, closed: true });
40288
+ current = points[0];
40289
+ points = [];
40290
+ }
40291
+ } else if (segment.kind === "rect") {
40292
+ if (points.length) paths.push({ points, closed: false });
40293
+ const first = toScreen(segment.x, segment.y);
40294
+ paths.push({ points: [
40295
+ first,
40296
+ toScreen(segment.x + segment.width, segment.y),
40297
+ toScreen(segment.x + segment.width, segment.y + segment.height),
40298
+ toScreen(segment.x, segment.y + segment.height)
40299
+ ], closed: true });
40300
+ current = first;
40301
+ points = [];
40302
+ }
40303
+ }
40304
+ if (points.length) paths.push({ points, closed: false });
40305
+ return paths;
40306
+ }
40307
+ function pathsToEdges(paths, closeSubpaths = false) {
40308
+ const edges = [];
40309
+ for (const { points, closed } of paths) {
40310
+ for (let i = 1; i < points.length; i++) {
40311
+ const a = points[i - 1], b = points[i];
40312
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
40313
+ }
40314
+ if ((closed || closeSubpaths) && points.length > 1) {
40315
+ const a = points[points.length - 1], b = points[0];
40316
+ edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
40187
40317
  }
40188
- }
40189
- if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
40190
- edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
40191
40318
  }
40192
40319
  return edges;
40193
40320
  }
@@ -40374,7 +40501,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40374
40501
  for (const clip of clips) {
40375
40502
  const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
40376
40503
  const layer = new Uint8Array(width * height * 4);
40377
- fillEdgesScanline4x4(layer, width, height, segmentsToScreenEdges(segments, displayList.height, scale, true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40504
+ fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
40378
40505
  for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
40379
40506
  }
40380
40507
  cachedClips = clips;
@@ -40421,62 +40548,38 @@ function renderDisplayListToBitmap(displayList, options = {}) {
40421
40548
  if (operation.kind === "path") {
40422
40549
  const path = operation.value;
40423
40550
  if (path.fillColor) {
40424
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, true);
40551
+ const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
40425
40552
  const clipScreen = path.clipRect ? [path.clipRect[0] * scale, (displayList.height - path.clipRect[3]) * scale, path.clipRect[2] * scale, (displayList.height - path.clipRect[1]) * scale] : void 0;
40426
40553
  fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
40427
40554
  }
40428
40555
  if (path.strokeColor) {
40429
- const edges = segmentsToScreenEdges(path.segments, displayList.height, scale, false);
40430
40556
  const rawSw = path.strokeWidth * scale;
40431
40557
  const sw = Math.max(1, rawSw);
40432
40558
  const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
40433
- const dashArr = path.dashArray && path.dashArray.length > 0 ? path.dashArray.map((d) => Math.max(0, d * scale)) : void 0;
40434
- const dashCycle = dashArr ? dashArr.reduce((a, b) => a + b, 0) : 0;
40435
- let dashDist = (path.dashPhase ?? 0) * scale % (dashCycle || 1);
40436
- if (dashDist < 0) dashDist += dashCycle;
40437
- for (const e of edges) {
40438
- if (!dashArr || dashCycle <= 1e-4) {
40439
- drawAntiAliasedSegment(rgba, width, height, e.x0, e.y0, e.x1, e.y1, sw, path.strokeColor, strokeAlpha, path.lineCap ?? 0, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
40440
- } else {
40441
- const dx = e.x1 - e.x0;
40442
- const dy = e.y1 - e.y0;
40443
- const edgeLen = Math.hypot(dx, dy);
40444
- if (edgeLen <= 1e-4) continue;
40445
- let pos = 0;
40446
- while (pos < edgeLen) {
40447
- let cycleRem = dashDist % dashCycle;
40448
- let dIdx = 0;
40449
- while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
40450
- cycleRem -= dashArr[dIdx];
40451
- dIdx++;
40452
- }
40453
- const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
40454
- const step = Math.min(edgeLen - pos, segRemainInDash);
40455
- if (dIdx % 2 === 0) {
40456
- const t0 = pos / edgeLen;
40457
- const t1 = (pos + step) / edgeLen;
40458
- drawAntiAliasedSegment(
40459
- rgba,
40460
- width,
40461
- height,
40462
- e.x0 + dx * t0,
40463
- e.y0 + dy * t0,
40464
- e.x0 + dx * t1,
40465
- e.y0 + dy * t1,
40466
- sw,
40467
- path.strokeColor,
40468
- strokeAlpha,
40469
- path.lineCap ?? 0,
40470
- original.kind === "glyph" ? aaTxt : aaVec,
40471
- path.blendMode,
40472
- clipMask
40473
- );
40474
- }
40475
- pos += step;
40476
- dashDist = (dashDist + step) % dashCycle;
40477
- }
40478
- }
40479
- }
40559
+ const contours = strokeOutlines(
40560
+ segmentsToScreenPaths(path.segments, displayList.height, scale),
40561
+ sw,
40562
+ path.lineCap ?? 0,
40563
+ path.lineJoin ?? 0,
40564
+ path.miterLimit ?? 10,
40565
+ path.dashArray?.map((value) => Math.max(0, value * scale)),
40566
+ (path.dashPhase ?? 0) * scale
40567
+ );
40568
+ const edges = pathsToEdges(contours.map((points) => ({ points, closed: true })));
40569
+ const clipScreen = path.clipRect ? [path.clipRect[0] * scale, (displayList.height - path.clipRect[3]) * scale, path.clipRect[2] * scale, (displayList.height - path.clipRect[1]) * scale] : void 0;
40570
+ fillEdgesScanline4x4(
40571
+ rgba,
40572
+ width,
40573
+ height,
40574
+ edges,
40575
+ path.strokeColor,
40576
+ strokeAlpha,
40577
+ "nonzero",
40578
+ clipScreen,
40579
+ original.kind === "glyph" ? aaTxt : aaVec,
40580
+ path.blendMode,
40581
+ clipMask
40582
+ );
40480
40583
  }
40481
40584
  } else if (operation.kind === "image") {
40482
40585
  const img = operation.value;
@@ -43149,3 +43252,15 @@ export {
43149
43252
  * Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
43150
43253
  * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43151
43254
  */
43255
+ /*!
43256
+ * Anti-Grain Geometry - Version 2.3
43257
+ * Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
43258
+ *
43259
+ * Permission to copy, use, modify, sell and distribute this software
43260
+ * is granted provided this copyright notice appears in all copies.
43261
+ * This software is provided "as is" without express or implied
43262
+ * warranty, and with no claim as to its suitability for any purpose.
43263
+ *
43264
+ * Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
43265
+ * See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
43266
+ */