@poe-platform/safe-bash 0.1.763 → 0.1.765
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.
- package/dist/image-ast/index.browser.js +321 -162
- package/dist/image-ast/index.js +321 -162
- package/dist/pdf-ast/ast.d.ts +2 -0
- package/dist/pdf-ast/index.js +340 -173
- package/dist/safe-bash/chunks/{chunk-CRQDMBQA.js → chunk-FSH7QRIC.js} +10 -1
- package/dist/safe-bash/command-chunks/{chunk-4XHONGIU.js → chunk-DT4MFWV4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-S3G2B4OX.js → chunk-KO4PXCNL.js} +324 -162
- package/dist/safe-bash/command-chunks/{chunk-S5EX6UP5.js → chunk-SVL6HYQL.js} +1 -1
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/llm-module.js +3 -1
- package/dist/safe-bash/commands/python/shell-module.js +7 -0
- package/dist/safe-bash/core.browser.js +32 -12
- package/dist/safe-bash/shell/runtime.js +43 -11
- package/dist/safe-bash-command-ffmpeg/index.js +5800 -5693
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +321 -162
- package/dist/safe-bash-command-pdfinfo/index.js +338 -173
- package/dist/safe-bash-command-pdftk/index.js +321 -162
- package/dist/safe-bash-command-pdftoppm/index.js +338 -173
- package/dist/safe-bash-command-pdftotext/index.js +321 -162
- package/dist/safe-bash-command-qpdf/index.js +321 -162
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +373 -169
- package/dist/safe-bash-command-wkhtmltopdf/index.js +322 -162
- package/dist/safe-playwright-cloudflare/browser-snapshot-labels.d.ts +14 -0
- package/dist/safe-playwright-cloudflare/browser-snapshot-labels.js +62 -0
- package/dist/safe-playwright-cloudflare/browser-snapshot-scheduler.js +8 -1
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +24 -0
|
@@ -35704,11 +35704,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
35704
35704
|
} else if (operator === "d") {
|
|
35705
35705
|
const arrNode = ops[0]?.kind === "array" ? ops[0] : void 0;
|
|
35706
35706
|
if (arrNode) {
|
|
35707
|
-
const
|
|
35708
|
-
const nums = arrNode.items.map((it) => it.kind === "number" ? it.value * ctmScale : 0).filter((v) => v >= 0);
|
|
35707
|
+
const nums = arrNode.items.map((it) => it.kind === "number" ? it.value : 0).filter((v) => v >= 0);
|
|
35709
35708
|
const sum = nums.reduce((a, b) => a + b, 0);
|
|
35710
35709
|
st.dashArray = sum > 0 ? nums : void 0;
|
|
35711
|
-
st.dashPhase = num(1, 0)
|
|
35710
|
+
st.dashPhase = num(1, 0);
|
|
35712
35711
|
} else {
|
|
35713
35712
|
st.dashArray = void 0;
|
|
35714
35713
|
st.dashPhase = void 0;
|
|
@@ -36244,15 +36243,14 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36244
36243
|
break;
|
|
36245
36244
|
}
|
|
36246
36245
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
36247
|
-
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
36248
|
-
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
36249
36246
|
emit({ kind: "path", value: {
|
|
36250
36247
|
segments: transformedSegments,
|
|
36251
36248
|
fillColor: isFill && !evaluatedFillPattern ? st.fillColor : void 0,
|
|
36252
36249
|
fillAlpha: isFill && !evaluatedFillPattern ? st.fillAlpha : void 0,
|
|
36253
36250
|
strokeColor: isStroke ? st.strokeColor : void 0,
|
|
36254
36251
|
strokeAlpha: isStroke ? st.strokeAlpha : void 0,
|
|
36255
|
-
strokeWidth:
|
|
36252
|
+
strokeWidth: st.strokeWidth,
|
|
36253
|
+
...isStroke ? { strokeMatrix: [...st.ctm] } : {},
|
|
36256
36254
|
...st.lineCap !== 0 ? { lineCap: st.lineCap } : {},
|
|
36257
36255
|
...st.lineJoin !== 0 ? { lineJoin: st.lineJoin } : {},
|
|
36258
36256
|
...st.miterLimit !== 10 ? { miterLimit: st.miterLimit } : {},
|
|
@@ -36440,14 +36438,14 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
36440
36438
|
if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
|
|
36441
36439
|
const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
|
|
36442
36440
|
const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
|
|
36443
|
-
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
36444
36441
|
const paint = {
|
|
36445
36442
|
segments: transformedGlyphSegs,
|
|
36446
36443
|
fillColor: isFillGlyph ? st.fillColor : void 0,
|
|
36447
36444
|
fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
|
|
36448
36445
|
strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
|
|
36449
36446
|
strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
|
|
36450
|
-
strokeWidth: isStrokeGlyph ? st.strokeWidth
|
|
36447
|
+
strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
|
|
36448
|
+
...isStrokeGlyph ? { strokeMatrix: [...st.ctm] } : {},
|
|
36451
36449
|
fillRule: "nonzero",
|
|
36452
36450
|
...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
|
|
36453
36451
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
@@ -39389,6 +39387,184 @@ function downscaleImage(image, widthScale, heightScale) {
|
|
|
39389
39387
|
}
|
|
39390
39388
|
return image;
|
|
39391
39389
|
}
|
|
39390
|
+
var MAX_STROKE_VERTICES = 1e6;
|
|
39391
|
+
function dashSubpath(path, pattern, phase) {
|
|
39392
|
+
const cycle = pattern.reduce((sum, value) => sum + value, 0);
|
|
39393
|
+
if (!(cycle > 0)) return [path];
|
|
39394
|
+
let offset = (phase % cycle + cycle) % cycle, index = 0;
|
|
39395
|
+
while (offset > 0) {
|
|
39396
|
+
if (offset < pattern[index]) break;
|
|
39397
|
+
offset -= pattern[index];
|
|
39398
|
+
index = (index + 1) % pattern.length;
|
|
39399
|
+
}
|
|
39400
|
+
let remaining = pattern[index] - offset;
|
|
39401
|
+
const points = path.closed ? [...path.points, path.points[0]] : path.points;
|
|
39402
|
+
const result = [];
|
|
39403
|
+
let current = [];
|
|
39404
|
+
let steps = 0;
|
|
39405
|
+
const flush = () => {
|
|
39406
|
+
if (current.length) result.push({ points: current, closed: false });
|
|
39407
|
+
current = [];
|
|
39408
|
+
};
|
|
39409
|
+
const advance = (point) => {
|
|
39410
|
+
while (remaining <= 0) {
|
|
39411
|
+
if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
39412
|
+
if (index % 2 === 0) {
|
|
39413
|
+
if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
|
|
39414
|
+
flush();
|
|
39415
|
+
}
|
|
39416
|
+
index = (index + 1) % pattern.length;
|
|
39417
|
+
remaining = pattern[index];
|
|
39418
|
+
}
|
|
39419
|
+
};
|
|
39420
|
+
for (let i = 1; i < points.length; i++) {
|
|
39421
|
+
const start = points[i - 1], end = points[i];
|
|
39422
|
+
const dx = end[0] - start[0], dy = end[1] - start[1];
|
|
39423
|
+
const length = Math.hypot(dx, dy);
|
|
39424
|
+
if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
|
|
39425
|
+
throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
39426
|
+
}
|
|
39427
|
+
let distance = 0;
|
|
39428
|
+
while (distance < length) {
|
|
39429
|
+
const point = [start[0] + dx * distance / length, start[1] + dy * distance / length];
|
|
39430
|
+
advance(point);
|
|
39431
|
+
const step = Math.min(remaining, length - distance);
|
|
39432
|
+
if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
39433
|
+
distance += step;
|
|
39434
|
+
remaining -= step;
|
|
39435
|
+
if (index % 2 === 0) {
|
|
39436
|
+
if (!current.length) current.push(point);
|
|
39437
|
+
current.push([start[0] + dx * distance / length, start[1] + dy * distance / length]);
|
|
39438
|
+
}
|
|
39439
|
+
}
|
|
39440
|
+
}
|
|
39441
|
+
flush();
|
|
39442
|
+
if (path.closed && result.length) {
|
|
39443
|
+
const first = result[0], last = result[result.length - 1];
|
|
39444
|
+
const start = path.points[0];
|
|
39445
|
+
const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
|
|
39446
|
+
if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
|
|
39447
|
+
if (first === last) result[0] = { points: first.points, closed: true };
|
|
39448
|
+
else {
|
|
39449
|
+
result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
|
|
39450
|
+
result.pop();
|
|
39451
|
+
}
|
|
39452
|
+
}
|
|
39453
|
+
}
|
|
39454
|
+
return result;
|
|
39455
|
+
}
|
|
39456
|
+
function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
|
|
39457
|
+
const half = width / 2;
|
|
39458
|
+
const contours = [];
|
|
39459
|
+
const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
|
|
39460
|
+
let count = 0;
|
|
39461
|
+
let contour = [];
|
|
39462
|
+
const add = (x, y) => {
|
|
39463
|
+
if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
|
|
39464
|
+
contour.push([x, y]);
|
|
39465
|
+
};
|
|
39466
|
+
const arc = (point, dx1, dy1, dx2, dy2) => {
|
|
39467
|
+
let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
|
|
39468
|
+
const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
|
|
39469
|
+
const step = Math.acos(half / (half + 0.125)) * 2;
|
|
39470
|
+
add(point[0] + dx1, point[1] + dy1);
|
|
39471
|
+
if (step > 0) {
|
|
39472
|
+
if (!ccw) {
|
|
39473
|
+
if (a1 > a2) a2 += 2 * Math.PI;
|
|
39474
|
+
a2 -= step / 4;
|
|
39475
|
+
if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
|
|
39476
|
+
for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
|
|
39477
|
+
} else {
|
|
39478
|
+
if (a1 < a2) a2 -= 2 * Math.PI;
|
|
39479
|
+
a2 += step / 4;
|
|
39480
|
+
if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
|
|
39481
|
+
for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
|
|
39482
|
+
}
|
|
39483
|
+
}
|
|
39484
|
+
add(point[0] + dx2, point[1] + dy2);
|
|
39485
|
+
};
|
|
39486
|
+
const addCap = (point, next) => {
|
|
39487
|
+
const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
|
|
39488
|
+
const dx = half * (next[1] - point[1]) / length;
|
|
39489
|
+
const dy = half * (next[0] - point[0]) / length;
|
|
39490
|
+
if (cap !== 1) {
|
|
39491
|
+
const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
|
|
39492
|
+
add(point[0] - dx - sx, point[1] + dy - sy);
|
|
39493
|
+
add(point[0] + dx - sx, point[1] - dy - sy);
|
|
39494
|
+
} else {
|
|
39495
|
+
const angle = Math.atan2(dy, -dx);
|
|
39496
|
+
const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
|
|
39497
|
+
add(point[0] - dx, point[1] + dy);
|
|
39498
|
+
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));
|
|
39499
|
+
add(point[0] + dx, point[1] - dy);
|
|
39500
|
+
}
|
|
39501
|
+
};
|
|
39502
|
+
const addJoin = (prev, point, next) => {
|
|
39503
|
+
const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
|
|
39504
|
+
const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
|
|
39505
|
+
const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
|
|
39506
|
+
const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
|
|
39507
|
+
const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
|
|
39508
|
+
if (!inner && join === 1) {
|
|
39509
|
+
arc(point, dx1, -dy1, dx2, -dy2);
|
|
39510
|
+
return;
|
|
39511
|
+
}
|
|
39512
|
+
if (inner || join === 0) {
|
|
39513
|
+
const ax = prev[0] + dx1, ay = prev[1] - dy1;
|
|
39514
|
+
const bx = point[0] + dx1, by = point[1] - dy1;
|
|
39515
|
+
const cx = point[0] + dx2, cy = point[1] - dy2;
|
|
39516
|
+
const dx = next[0] + dx2, dy = next[1] - dy2;
|
|
39517
|
+
const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
|
|
39518
|
+
if (Math.abs(den) >= 1e-30) {
|
|
39519
|
+
const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
|
|
39520
|
+
const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
|
|
39521
|
+
if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
|
|
39522
|
+
add(x, y);
|
|
39523
|
+
return;
|
|
39524
|
+
}
|
|
39525
|
+
} else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
|
|
39526
|
+
add(bx, by);
|
|
39527
|
+
return;
|
|
39528
|
+
}
|
|
39529
|
+
}
|
|
39530
|
+
add(point[0] + dx1, point[1] - dy1);
|
|
39531
|
+
add(point[0] + dx2, point[1] - dy2);
|
|
39532
|
+
};
|
|
39533
|
+
for (const path of paths) {
|
|
39534
|
+
for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
|
|
39535
|
+
const points = [];
|
|
39536
|
+
for (const point of subpath.points) {
|
|
39537
|
+
const prev = points[points.length - 1];
|
|
39538
|
+
if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
|
|
39539
|
+
}
|
|
39540
|
+
let closed = subpath.closed;
|
|
39541
|
+
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();
|
|
39542
|
+
if (points.length < 3) closed = false;
|
|
39543
|
+
if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
|
|
39544
|
+
contour = [];
|
|
39545
|
+
const [x, y] = points[0];
|
|
39546
|
+
addCap([x, y], [x + 1, y]);
|
|
39547
|
+
addCap([x, y], [x - 1, y]);
|
|
39548
|
+
contours.push(contour);
|
|
39549
|
+
} else if (points.length >= 2) {
|
|
39550
|
+
contour = [];
|
|
39551
|
+
if (!closed) addCap(points[0], points[1]);
|
|
39552
|
+
for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
|
|
39553
|
+
addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
|
|
39554
|
+
}
|
|
39555
|
+
if (closed) {
|
|
39556
|
+
contours.push(contour);
|
|
39557
|
+
contour = [];
|
|
39558
|
+
} else addCap(points[points.length - 1], points[points.length - 2]);
|
|
39559
|
+
for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
|
|
39560
|
+
addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
|
|
39561
|
+
}
|
|
39562
|
+
contours.push(contour);
|
|
39563
|
+
}
|
|
39564
|
+
}
|
|
39565
|
+
}
|
|
39566
|
+
return contours;
|
|
39567
|
+
}
|
|
39392
39568
|
function decodePng(pngBytes) {
|
|
39393
39569
|
if (pngBytes.length < 24 || pngBytes[0] !== 137 || pngBytes[1] !== 80 || pngBytes[2] !== 78 || pngBytes[3] !== 71) {
|
|
39394
39570
|
throw new Error("Invalid PNG signature");
|
|
@@ -40083,111 +40259,116 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
|
|
|
40083
40259
|
rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
|
|
40084
40260
|
rgba[idx + 3] = Math.round(outA * 255);
|
|
40085
40261
|
}
|
|
40086
|
-
function
|
|
40087
|
-
const
|
|
40088
|
-
|
|
40089
|
-
|
|
40090
|
-
const
|
|
40091
|
-
|
|
40092
|
-
|
|
40093
|
-
|
|
40094
|
-
|
|
40095
|
-
|
|
40096
|
-
|
|
40097
|
-
|
|
40098
|
-
|
|
40099
|
-
|
|
40100
|
-
|
|
40101
|
-
|
|
40102
|
-
|
|
40103
|
-
|
|
40104
|
-
|
|
40105
|
-
|
|
40106
|
-
|
|
40107
|
-
|
|
40108
|
-
|
|
40109
|
-
|
|
40110
|
-
|
|
40111
|
-
|
|
40112
|
-
|
|
40113
|
-
|
|
40114
|
-
|
|
40115
|
-
|
|
40116
|
-
|
|
40117
|
-
|
|
40118
|
-
|
|
40119
|
-
|
|
40120
|
-
|
|
40121
|
-
|
|
40122
|
-
|
|
40123
|
-
|
|
40124
|
-
|
|
40125
|
-
|
|
40126
|
-
|
|
40262
|
+
function segmentsToScreenPaths(segments, pageHeight, scale, toScreen = (x, y) => [x * scale, (pageHeight - y) * scale]) {
|
|
40263
|
+
const paths = [];
|
|
40264
|
+
let points = [];
|
|
40265
|
+
let current = [0, 0];
|
|
40266
|
+
for (const segment of segments) {
|
|
40267
|
+
if (segment.kind === "move") {
|
|
40268
|
+
if (points.length) paths.push({ points, closed: false });
|
|
40269
|
+
current = toScreen(segment.x, segment.y);
|
|
40270
|
+
points = [current];
|
|
40271
|
+
} else if (segment.kind === "line") {
|
|
40272
|
+
if (!points.length) points = [current];
|
|
40273
|
+
current = toScreen(segment.x, segment.y);
|
|
40274
|
+
points.push(current);
|
|
40275
|
+
} else if (segment.kind === "cubic") {
|
|
40276
|
+
if (!points.length) points = [current];
|
|
40277
|
+
const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
|
|
40278
|
+
const end = toScreen(segment.x, segment.y);
|
|
40279
|
+
const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
|
|
40280
|
+
for (let i = 1; i < curve.length; i++) points.push(curve[i]);
|
|
40281
|
+
current = end;
|
|
40282
|
+
} else if (segment.kind === "close") {
|
|
40283
|
+
if (points.length) {
|
|
40284
|
+
paths.push({ points, closed: true });
|
|
40285
|
+
current = points[0];
|
|
40286
|
+
points = [];
|
|
40287
|
+
}
|
|
40288
|
+
} else if (segment.kind === "rect") {
|
|
40289
|
+
if (points.length) paths.push({ points, closed: false });
|
|
40290
|
+
const first = toScreen(segment.x, segment.y);
|
|
40291
|
+
paths.push({ points: [
|
|
40292
|
+
first,
|
|
40293
|
+
toScreen(segment.x + segment.width, segment.y),
|
|
40294
|
+
toScreen(segment.x + segment.width, segment.y + segment.height),
|
|
40295
|
+
toScreen(segment.x, segment.y + segment.height)
|
|
40296
|
+
], closed: true });
|
|
40297
|
+
current = first;
|
|
40298
|
+
points = [];
|
|
40299
|
+
}
|
|
40300
|
+
}
|
|
40301
|
+
if (points.length) paths.push({ points, closed: false });
|
|
40302
|
+
return paths;
|
|
40303
|
+
}
|
|
40304
|
+
function inverseStrokeMatrix(matrix) {
|
|
40305
|
+
const [a, b, c, d, e, f] = matrix;
|
|
40306
|
+
const det = a * d - b * c;
|
|
40307
|
+
if (!Number.isFinite(det) || det === 0) return void 0;
|
|
40308
|
+
return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
|
|
40309
|
+
}
|
|
40310
|
+
function prepareStroke(path, scale) {
|
|
40311
|
+
const matrix = path.strokeMatrix ? [...path.strokeMatrix] : [1, 0, 0, 1, 0, 0];
|
|
40312
|
+
const [a, b, c, d] = matrix;
|
|
40313
|
+
const area = Math.abs(a * d - b * c) * scale * scale;
|
|
40314
|
+
if (!(area > 0) || !Number.isFinite(area)) return void 0;
|
|
40315
|
+
const normX = Math.hypot(a, b) * scale, normY = Math.hypot(c, d) * scale;
|
|
40316
|
+
let width = path.strokeWidth || 1;
|
|
40317
|
+
const scaleX = path.strokeWidth === 0 ? normY / area : Math.max(1, normY / (width * area));
|
|
40318
|
+
const scaleY = path.strokeWidth === 0 ? normX / area : Math.max(1, normX / (width * area));
|
|
40319
|
+
let dashArray = path.dashArray, dashPhase = path.dashPhase ?? 0;
|
|
40320
|
+
if (scaleX === scaleY) {
|
|
40321
|
+
width *= scaleX;
|
|
40322
|
+
} else {
|
|
40323
|
+
matrix[0] *= scaleX;
|
|
40324
|
+
matrix[1] *= scaleX;
|
|
40325
|
+
matrix[2] *= scaleY;
|
|
40326
|
+
matrix[3] *= scaleY;
|
|
40327
|
+
if (dashArray?.length) {
|
|
40328
|
+
const dashScale = Math.max(scaleX, scaleY);
|
|
40329
|
+
dashArray = dashArray.map((value) => value / dashScale);
|
|
40330
|
+
dashPhase /= dashScale;
|
|
40331
|
+
}
|
|
40332
|
+
}
|
|
40333
|
+
return { matrix, width, dashArray, dashPhase };
|
|
40334
|
+
}
|
|
40335
|
+
function strokeEdges(path, pageHeight, scale) {
|
|
40336
|
+
const stroke = prepareStroke(path, scale);
|
|
40337
|
+
if (!stroke) return [];
|
|
40338
|
+
const inverse = inverseStrokeMatrix(stroke.matrix);
|
|
40339
|
+
if (!inverse) return [];
|
|
40340
|
+
const [a, b, c, d, e, f] = stroke.matrix;
|
|
40341
|
+
const strokeScale = scale * Math.hypot(a, b, c, d);
|
|
40342
|
+
const project = (x, y) => [
|
|
40343
|
+
(inverse[0] * x + inverse[2] * y + inverse[4]) * strokeScale,
|
|
40344
|
+
(inverse[1] * x + inverse[3] * y + inverse[5]) * strokeScale
|
|
40345
|
+
];
|
|
40346
|
+
const toScreen = ([x, y]) => [
|
|
40347
|
+
(a * x / strokeScale + c * y / strokeScale + e) * scale,
|
|
40348
|
+
(pageHeight - b * x / strokeScale - d * y / strokeScale - f) * scale
|
|
40349
|
+
];
|
|
40350
|
+
const contours = strokeOutlines(
|
|
40351
|
+
segmentsToScreenPaths(path.segments, pageHeight, scale, project),
|
|
40352
|
+
stroke.width * strokeScale,
|
|
40353
|
+
path.lineCap ?? 0,
|
|
40354
|
+
path.lineJoin ?? 0,
|
|
40355
|
+
path.miterLimit ?? 10,
|
|
40356
|
+
stroke.dashArray?.map((value) => Math.max(0, value * strokeScale)),
|
|
40357
|
+
stroke.dashPhase * strokeScale
|
|
40358
|
+
);
|
|
40359
|
+
return pathsToEdges(contours.map((points) => ({ points: points.map(toScreen), closed: true })));
|
|
40127
40360
|
}
|
|
40128
|
-
function
|
|
40361
|
+
function pathsToEdges(paths, closeSubpaths = false) {
|
|
40129
40362
|
const edges = [];
|
|
40130
|
-
|
|
40131
|
-
|
|
40132
|
-
|
|
40133
|
-
|
|
40134
|
-
|
|
40135
|
-
|
|
40136
|
-
|
|
40137
|
-
|
|
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;
|
|
40363
|
+
for (const { points, closed } of paths) {
|
|
40364
|
+
for (let i = 1; i < points.length; i++) {
|
|
40365
|
+
const a = points[i - 1], b = points[i];
|
|
40366
|
+
edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
|
|
40367
|
+
}
|
|
40368
|
+
if ((closed || closeSubpaths) && points.length > 1) {
|
|
40369
|
+
const a = points[points.length - 1], b = points[0];
|
|
40370
|
+
edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
|
|
40187
40371
|
}
|
|
40188
|
-
}
|
|
40189
|
-
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
40190
|
-
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
40191
40372
|
}
|
|
40192
40373
|
return edges;
|
|
40193
40374
|
}
|
|
@@ -40374,7 +40555,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
40374
40555
|
for (const clip of clips) {
|
|
40375
40556
|
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
40376
40557
|
const layer = new Uint8Array(width * height * 4);
|
|
40377
|
-
fillEdgesScanline4x4(layer, width, height,
|
|
40558
|
+
fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
40378
40559
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
40379
40560
|
}
|
|
40380
40561
|
cachedClips = clips;
|
|
@@ -40421,62 +40602,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
40421
40602
|
if (operation.kind === "path") {
|
|
40422
40603
|
const path = operation.value;
|
|
40423
40604
|
if (path.fillColor) {
|
|
40424
|
-
const edges =
|
|
40605
|
+
const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
|
|
40425
40606
|
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
40607
|
fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
|
|
40427
40608
|
}
|
|
40428
40609
|
if (path.strokeColor) {
|
|
40429
|
-
const
|
|
40430
|
-
const rawSw = path.strokeWidth * scale;
|
|
40431
|
-
const sw = Math.max(1, rawSw);
|
|
40610
|
+
const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
|
|
40432
40611
|
const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
|
|
40433
|
-
const
|
|
40434
|
-
const
|
|
40435
|
-
|
|
40436
|
-
|
|
40437
|
-
|
|
40438
|
-
|
|
40439
|
-
|
|
40440
|
-
|
|
40441
|
-
|
|
40442
|
-
|
|
40443
|
-
|
|
40444
|
-
|
|
40445
|
-
|
|
40446
|
-
|
|
40447
|
-
|
|
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
|
-
}
|
|
40612
|
+
const edges = strokeEdges(path, displayList.height, scale);
|
|
40613
|
+
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;
|
|
40614
|
+
fillEdgesScanline4x4(
|
|
40615
|
+
rgba,
|
|
40616
|
+
width,
|
|
40617
|
+
height,
|
|
40618
|
+
edges,
|
|
40619
|
+
path.strokeColor,
|
|
40620
|
+
strokeAlpha,
|
|
40621
|
+
"nonzero",
|
|
40622
|
+
clipScreen,
|
|
40623
|
+
original.kind === "glyph" ? aaTxt : aaVec,
|
|
40624
|
+
path.blendMode,
|
|
40625
|
+
clipMask
|
|
40626
|
+
);
|
|
40480
40627
|
}
|
|
40481
40628
|
} else if (operation.kind === "image") {
|
|
40482
40629
|
const img = operation.value;
|
|
@@ -43149,3 +43296,15 @@ export {
|
|
|
43149
43296
|
* Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
|
|
43150
43297
|
* See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
|
|
43151
43298
|
*/
|
|
43299
|
+
/*!
|
|
43300
|
+
* Anti-Grain Geometry - Version 2.3
|
|
43301
|
+
* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
43302
|
+
*
|
|
43303
|
+
* Permission to copy, use, modify, sell and distribute this software
|
|
43304
|
+
* is granted provided this copyright notice appears in all copies.
|
|
43305
|
+
* This software is provided "as is" without express or implied
|
|
43306
|
+
* warranty, and with no claim as to its suitability for any purpose.
|
|
43307
|
+
*
|
|
43308
|
+
* Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
|
|
43309
|
+
* See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
|
|
43310
|
+
*/
|