@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
|
@@ -48,11 +48,11 @@ import {
|
|
|
48
48
|
trimImage,
|
|
49
49
|
unflattenImage,
|
|
50
50
|
unpremultiplyRgbaImage
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-SVL6HYQL.js";
|
|
52
52
|
import {
|
|
53
53
|
PdfDocument,
|
|
54
54
|
encodePng
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-KO4PXCNL.js";
|
|
56
56
|
import {
|
|
57
57
|
createLuaFilterCapability
|
|
58
58
|
} from "./chunk-Y2KHC6TZ.js";
|
|
@@ -32212,11 +32212,10 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
32212
32212
|
} else if (operator === "d") {
|
|
32213
32213
|
const arrNode = ops[0]?.kind === "array" ? ops[0] : void 0;
|
|
32214
32214
|
if (arrNode) {
|
|
32215
|
-
const
|
|
32216
|
-
const nums = arrNode.items.map((it) => it.kind === "number" ? it.value * ctmScale : 0).filter((v) => v >= 0);
|
|
32215
|
+
const nums = arrNode.items.map((it) => it.kind === "number" ? it.value : 0).filter((v) => v >= 0);
|
|
32217
32216
|
const sum = nums.reduce((a, b) => a + b, 0);
|
|
32218
32217
|
st.dashArray = sum > 0 ? nums : void 0;
|
|
32219
|
-
st.dashPhase = num(1, 0)
|
|
32218
|
+
st.dashPhase = num(1, 0);
|
|
32220
32219
|
} else {
|
|
32221
32220
|
st.dashArray = void 0;
|
|
32222
32221
|
st.dashPhase = void 0;
|
|
@@ -32752,15 +32751,14 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
32752
32751
|
break;
|
|
32753
32752
|
}
|
|
32754
32753
|
const fillRule = node.paint.includes("*") ? "evenodd" : "nonzero";
|
|
32755
|
-
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
32756
|
-
const scaledStrokeWidth = st.strokeWidth === 0 ? 0 : st.strokeWidth * ctmScale;
|
|
32757
32754
|
emit({ kind: "path", value: {
|
|
32758
32755
|
segments: transformedSegments,
|
|
32759
32756
|
fillColor: isFill && !evaluatedFillPattern ? st.fillColor : void 0,
|
|
32760
32757
|
fillAlpha: isFill && !evaluatedFillPattern ? st.fillAlpha : void 0,
|
|
32761
32758
|
strokeColor: isStroke ? st.strokeColor : void 0,
|
|
32762
32759
|
strokeAlpha: isStroke ? st.strokeAlpha : void 0,
|
|
32763
|
-
strokeWidth:
|
|
32760
|
+
strokeWidth: st.strokeWidth,
|
|
32761
|
+
...isStroke ? { strokeMatrix: [...st.ctm] } : {},
|
|
32764
32762
|
...st.lineCap !== 0 ? { lineCap: st.lineCap } : {},
|
|
32765
32763
|
...st.lineJoin !== 0 ? { lineJoin: st.lineJoin } : {},
|
|
32766
32764
|
...st.miterLimit !== 10 ? { miterLimit: st.miterLimit } : {},
|
|
@@ -32948,14 +32946,14 @@ function evaluateContentStreamToDisplayList(params) {
|
|
|
32948
32946
|
if (st.textRenderMode >= 4 && st.textRenderMode <= 7) pendingTextClip.push(...transformedGlyphSegs);
|
|
32949
32947
|
const isFillGlyph = st.textRenderMode === 0 || st.textRenderMode === 2 || st.textRenderMode === 4 || st.textRenderMode === 6;
|
|
32950
32948
|
const isStrokeGlyph = st.textRenderMode === 1 || st.textRenderMode === 2 || st.textRenderMode === 5 || st.textRenderMode === 6;
|
|
32951
|
-
const ctmScale = Math.max(1e-6, Math.hypot(st.ctm[0], st.ctm[1]));
|
|
32952
32949
|
const paint = {
|
|
32953
32950
|
segments: transformedGlyphSegs,
|
|
32954
32951
|
fillColor: isFillGlyph ? st.fillColor : void 0,
|
|
32955
32952
|
fillAlpha: isFillGlyph ? st.fillAlpha : void 0,
|
|
32956
32953
|
strokeColor: isStrokeGlyph ? st.strokeColor : void 0,
|
|
32957
32954
|
strokeAlpha: isStrokeGlyph ? st.strokeAlpha : void 0,
|
|
32958
|
-
strokeWidth: isStrokeGlyph ? st.strokeWidth
|
|
32955
|
+
strokeWidth: isStrokeGlyph ? st.strokeWidth : 0,
|
|
32956
|
+
...isStrokeGlyph ? { strokeMatrix: [...st.ctm] } : {},
|
|
32959
32957
|
fillRule: "nonzero",
|
|
32960
32958
|
...st.blendMode && st.blendMode !== "Normal" ? { blendMode: st.blendMode } : {},
|
|
32961
32959
|
...st.clipRect ? { clipRect: [...st.clipRect] } : {}
|
|
@@ -34122,6 +34120,187 @@ function downscaleImage(image, widthScale, heightScale) {
|
|
|
34122
34120
|
return image;
|
|
34123
34121
|
}
|
|
34124
34122
|
|
|
34123
|
+
// packages/pdf-ast/src/render/stroke.ts
|
|
34124
|
+
init_buffer();
|
|
34125
|
+
var MAX_STROKE_VERTICES = 1e6;
|
|
34126
|
+
function dashSubpath(path, pattern, phase) {
|
|
34127
|
+
const cycle = pattern.reduce((sum, value) => sum + value, 0);
|
|
34128
|
+
if (!(cycle > 0)) return [path];
|
|
34129
|
+
let offset = (phase % cycle + cycle) % cycle, index = 0;
|
|
34130
|
+
while (offset > 0) {
|
|
34131
|
+
if (offset < pattern[index]) break;
|
|
34132
|
+
offset -= pattern[index];
|
|
34133
|
+
index = (index + 1) % pattern.length;
|
|
34134
|
+
}
|
|
34135
|
+
let remaining = pattern[index] - offset;
|
|
34136
|
+
const points = path.closed ? [...path.points, path.points[0]] : path.points;
|
|
34137
|
+
const result = [];
|
|
34138
|
+
let current = [];
|
|
34139
|
+
let steps = 0;
|
|
34140
|
+
const flush = () => {
|
|
34141
|
+
if (current.length) result.push({ points: current, closed: false });
|
|
34142
|
+
current = [];
|
|
34143
|
+
};
|
|
34144
|
+
const advance = (point) => {
|
|
34145
|
+
while (remaining <= 0) {
|
|
34146
|
+
if (++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
34147
|
+
if (index % 2 === 0) {
|
|
34148
|
+
if (pattern[index] === 0) result.push({ points: [point, point], closed: false });
|
|
34149
|
+
flush();
|
|
34150
|
+
}
|
|
34151
|
+
index = (index + 1) % pattern.length;
|
|
34152
|
+
remaining = pattern[index];
|
|
34153
|
+
}
|
|
34154
|
+
};
|
|
34155
|
+
for (let i = 1; i < points.length; i++) {
|
|
34156
|
+
const start = points[i - 1], end = points[i];
|
|
34157
|
+
const dx = end[0] - start[0], dy = end[1] - start[1];
|
|
34158
|
+
const length = Math.hypot(dx, dy);
|
|
34159
|
+
if (!Number.isFinite(length) || length / cycle * pattern.length > MAX_STROKE_VERTICES) {
|
|
34160
|
+
throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
34161
|
+
}
|
|
34162
|
+
let distance = 0;
|
|
34163
|
+
while (distance < length) {
|
|
34164
|
+
const point = [start[0] + dx * distance / length, start[1] + dy * distance / length];
|
|
34165
|
+
advance(point);
|
|
34166
|
+
const step = Math.min(remaining, length - distance);
|
|
34167
|
+
if (distance + step === distance || ++steps > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke dash expansion exceeds the vertex limit");
|
|
34168
|
+
distance += step;
|
|
34169
|
+
remaining -= step;
|
|
34170
|
+
if (index % 2 === 0) {
|
|
34171
|
+
if (!current.length) current.push(point);
|
|
34172
|
+
current.push([start[0] + dx * distance / length, start[1] + dy * distance / length]);
|
|
34173
|
+
}
|
|
34174
|
+
}
|
|
34175
|
+
}
|
|
34176
|
+
flush();
|
|
34177
|
+
if (path.closed && result.length) {
|
|
34178
|
+
const first = result[0], last = result[result.length - 1];
|
|
34179
|
+
const start = path.points[0];
|
|
34180
|
+
const firstPoint = first.points[0], lastPoint = last.points[last.points.length - 1];
|
|
34181
|
+
if (firstPoint[0] === start[0] && firstPoint[1] === start[1] && lastPoint[0] === start[0] && lastPoint[1] === start[1]) {
|
|
34182
|
+
if (first === last) result[0] = { points: first.points, closed: true };
|
|
34183
|
+
else {
|
|
34184
|
+
result[0] = { points: [...last.points, ...first.points.slice(1)], closed: false };
|
|
34185
|
+
result.pop();
|
|
34186
|
+
}
|
|
34187
|
+
}
|
|
34188
|
+
}
|
|
34189
|
+
return result;
|
|
34190
|
+
}
|
|
34191
|
+
function strokeOutlines(paths, width, cap, join, miterLimit, dashArray = [], dashPhase = 0) {
|
|
34192
|
+
const half = width / 2;
|
|
34193
|
+
const contours = [];
|
|
34194
|
+
const pattern = dashArray.length % 2 ? [...dashArray, ...dashArray] : dashArray;
|
|
34195
|
+
let count = 0;
|
|
34196
|
+
let contour = [];
|
|
34197
|
+
const add = (x, y) => {
|
|
34198
|
+
if (++count > MAX_STROKE_VERTICES) throw new PdfError("E_LIMIT", "Stroke outline exceeds the vertex limit");
|
|
34199
|
+
contour.push([x, y]);
|
|
34200
|
+
};
|
|
34201
|
+
const arc = (point, dx1, dy1, dx2, dy2) => {
|
|
34202
|
+
let a1 = Math.atan2(dy1, dx1), a2 = Math.atan2(dy2, dx2);
|
|
34203
|
+
const ccw = a1 - a2 > 0 && a1 - a2 < Math.PI;
|
|
34204
|
+
const step = Math.acos(half / (half + 0.125)) * 2;
|
|
34205
|
+
add(point[0] + dx1, point[1] + dy1);
|
|
34206
|
+
if (step > 0) {
|
|
34207
|
+
if (!ccw) {
|
|
34208
|
+
if (a1 > a2) a2 += 2 * Math.PI;
|
|
34209
|
+
a2 -= step / 4;
|
|
34210
|
+
if ((a2 - a1) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
|
|
34211
|
+
for (a1 += step; a1 < a2; a1 += step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
|
|
34212
|
+
} else {
|
|
34213
|
+
if (a1 < a2) a2 -= 2 * Math.PI;
|
|
34214
|
+
a2 += step / 4;
|
|
34215
|
+
if ((a1 - a2) / step > MAX_STROKE_VERTICES - count) throw new PdfError("E_LIMIT", "Stroke arc exceeds the vertex limit");
|
|
34216
|
+
for (a1 -= step; a1 > a2; a1 -= step) add(point[0] + half * Math.cos(a1), point[1] + half * Math.sin(a1));
|
|
34217
|
+
}
|
|
34218
|
+
}
|
|
34219
|
+
add(point[0] + dx2, point[1] + dy2);
|
|
34220
|
+
};
|
|
34221
|
+
const addCap = (point, next) => {
|
|
34222
|
+
const length = Math.hypot(next[0] - point[0], next[1] - point[1]);
|
|
34223
|
+
const dx = half * (next[1] - point[1]) / length;
|
|
34224
|
+
const dy = half * (next[0] - point[0]) / length;
|
|
34225
|
+
if (cap !== 1) {
|
|
34226
|
+
const sx = cap === 2 ? dy : 0, sy = cap === 2 ? dx : 0;
|
|
34227
|
+
add(point[0] - dx - sx, point[1] + dy - sy);
|
|
34228
|
+
add(point[0] + dx - sx, point[1] - dy - sy);
|
|
34229
|
+
} else {
|
|
34230
|
+
const angle = Math.atan2(dy, -dx);
|
|
34231
|
+
const step = Math.max(1e-3, Math.acos(half / (half + 0.125)) * 2);
|
|
34232
|
+
add(point[0] - dx, point[1] + dy);
|
|
34233
|
+
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));
|
|
34234
|
+
add(point[0] + dx, point[1] - dy);
|
|
34235
|
+
}
|
|
34236
|
+
};
|
|
34237
|
+
const addJoin = (prev, point, next) => {
|
|
34238
|
+
const len1 = Math.hypot(point[0] - prev[0], point[1] - prev[1]);
|
|
34239
|
+
const len2 = Math.hypot(next[0] - point[0], next[1] - point[1]);
|
|
34240
|
+
const dx1 = half * (point[1] - prev[1]) / len1, dy1 = half * (point[0] - prev[0]) / len1;
|
|
34241
|
+
const dx2 = half * (next[1] - point[1]) / len2, dy2 = half * (next[0] - point[0]) / len2;
|
|
34242
|
+
const inner = (next[0] - point[0]) * (point[1] - prev[1]) - (next[1] - point[1]) * (point[0] - prev[0]) > 0;
|
|
34243
|
+
if (!inner && join === 1) {
|
|
34244
|
+
arc(point, dx1, -dy1, dx2, -dy2);
|
|
34245
|
+
return;
|
|
34246
|
+
}
|
|
34247
|
+
if (inner || join === 0) {
|
|
34248
|
+
const ax = prev[0] + dx1, ay = prev[1] - dy1;
|
|
34249
|
+
const bx = point[0] + dx1, by = point[1] - dy1;
|
|
34250
|
+
const cx = point[0] + dx2, cy = point[1] - dy2;
|
|
34251
|
+
const dx = next[0] + dx2, dy = next[1] - dy2;
|
|
34252
|
+
const den = (bx - ax) * (dy - cy) - (by - ay) * (dx - cx);
|
|
34253
|
+
if (Math.abs(den) >= 1e-30) {
|
|
34254
|
+
const t = ((ay - cy) * (dx - cx) - (ax - cx) * (dy - cy)) / den;
|
|
34255
|
+
const x = ax + (bx - ax) * t, y = ay + (by - ay) * t;
|
|
34256
|
+
if (Math.hypot(x - point[0], y - point[1]) <= half * (inner ? 1.01 : miterLimit)) {
|
|
34257
|
+
add(x, y);
|
|
34258
|
+
return;
|
|
34259
|
+
}
|
|
34260
|
+
} else if ((bx - prev[0]) * dy1 - (prev[1] - by) * dx1 < 0 !== (bx - next[0]) * dy1 - (next[1] - by) * dx1 < 0) {
|
|
34261
|
+
add(bx, by);
|
|
34262
|
+
return;
|
|
34263
|
+
}
|
|
34264
|
+
}
|
|
34265
|
+
add(point[0] + dx1, point[1] - dy1);
|
|
34266
|
+
add(point[0] + dx2, point[1] - dy2);
|
|
34267
|
+
};
|
|
34268
|
+
for (const path of paths) {
|
|
34269
|
+
for (const subpath of pattern.length ? dashSubpath(path, pattern, dashPhase) : [path]) {
|
|
34270
|
+
const points = [];
|
|
34271
|
+
for (const point of subpath.points) {
|
|
34272
|
+
const prev = points[points.length - 1];
|
|
34273
|
+
if (!prev || Math.hypot(prev[0] - point[0], prev[1] - point[1]) > 1e-14) points.push(point);
|
|
34274
|
+
}
|
|
34275
|
+
let closed = subpath.closed;
|
|
34276
|
+
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();
|
|
34277
|
+
if (points.length < 3) closed = false;
|
|
34278
|
+
if (points.length === 1 && subpath.points.length > 1 && cap === 1) {
|
|
34279
|
+
contour = [];
|
|
34280
|
+
const [x, y] = points[0];
|
|
34281
|
+
addCap([x, y], [x + 1, y]);
|
|
34282
|
+
addCap([x, y], [x - 1, y]);
|
|
34283
|
+
contours.push(contour);
|
|
34284
|
+
} else if (points.length >= 2) {
|
|
34285
|
+
contour = [];
|
|
34286
|
+
if (!closed) addCap(points[0], points[1]);
|
|
34287
|
+
for (let i = closed ? 0 : 1; i < points.length - (closed ? 0 : 1); i++) {
|
|
34288
|
+
addJoin(points[(i + points.length - 1) % points.length], points[i], points[(i + 1) % points.length]);
|
|
34289
|
+
}
|
|
34290
|
+
if (closed) {
|
|
34291
|
+
contours.push(contour);
|
|
34292
|
+
contour = [];
|
|
34293
|
+
} else addCap(points[points.length - 1], points[points.length - 2]);
|
|
34294
|
+
for (let i = points.length - (closed ? 1 : 2); i >= (closed ? 0 : 1); i--) {
|
|
34295
|
+
addJoin(points[(i + 1) % points.length], points[i], points[(i + points.length - 1) % points.length]);
|
|
34296
|
+
}
|
|
34297
|
+
contours.push(contour);
|
|
34298
|
+
}
|
|
34299
|
+
}
|
|
34300
|
+
}
|
|
34301
|
+
return contours;
|
|
34302
|
+
}
|
|
34303
|
+
|
|
34125
34304
|
// packages/pdf-ast/src/render/raster.ts
|
|
34126
34305
|
function encodePng(bitmap) {
|
|
34127
34306
|
return encodeRgbaToPng(bitmap.width, bitmap.height, bitmap.data);
|
|
@@ -34820,111 +34999,116 @@ function blendPixel(rgba, width, height, px, py, color, alpha, blendMode, clipMa
|
|
|
34820
34999
|
rgba[idx + 2] = Math.round((effB * a + cbB * dstA * (1 - a)) / outA * 255);
|
|
34821
35000
|
rgba[idx + 3] = Math.round(outA * 255);
|
|
34822
35001
|
}
|
|
34823
|
-
function
|
|
34824
|
-
const
|
|
34825
|
-
|
|
34826
|
-
|
|
34827
|
-
const
|
|
34828
|
-
|
|
34829
|
-
|
|
34830
|
-
|
|
34831
|
-
|
|
34832
|
-
|
|
34833
|
-
|
|
34834
|
-
|
|
34835
|
-
|
|
34836
|
-
|
|
34837
|
-
|
|
34838
|
-
|
|
34839
|
-
|
|
34840
|
-
|
|
34841
|
-
|
|
34842
|
-
|
|
34843
|
-
|
|
34844
|
-
|
|
34845
|
-
|
|
34846
|
-
|
|
34847
|
-
|
|
34848
|
-
|
|
34849
|
-
|
|
34850
|
-
|
|
34851
|
-
|
|
34852
|
-
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
|
|
34859
|
-
|
|
34860
|
-
|
|
34861
|
-
|
|
34862
|
-
|
|
34863
|
-
|
|
35002
|
+
function segmentsToScreenPaths(segments, pageHeight, scale, toScreen = (x, y) => [x * scale, (pageHeight - y) * scale]) {
|
|
35003
|
+
const paths = [];
|
|
35004
|
+
let points = [];
|
|
35005
|
+
let current = [0, 0];
|
|
35006
|
+
for (const segment of segments) {
|
|
35007
|
+
if (segment.kind === "move") {
|
|
35008
|
+
if (points.length) paths.push({ points, closed: false });
|
|
35009
|
+
current = toScreen(segment.x, segment.y);
|
|
35010
|
+
points = [current];
|
|
35011
|
+
} else if (segment.kind === "line") {
|
|
35012
|
+
if (!points.length) points = [current];
|
|
35013
|
+
current = toScreen(segment.x, segment.y);
|
|
35014
|
+
points.push(current);
|
|
35015
|
+
} else if (segment.kind === "cubic") {
|
|
35016
|
+
if (!points.length) points = [current];
|
|
35017
|
+
const a = toScreen(segment.x1, segment.y1), b = toScreen(segment.x2, segment.y2);
|
|
35018
|
+
const end = toScreen(segment.x, segment.y);
|
|
35019
|
+
const curve = flattenCubic(current[0], current[1], a[0], a[1], b[0], b[1], end[0], end[1]);
|
|
35020
|
+
for (let i = 1; i < curve.length; i++) points.push(curve[i]);
|
|
35021
|
+
current = end;
|
|
35022
|
+
} else if (segment.kind === "close") {
|
|
35023
|
+
if (points.length) {
|
|
35024
|
+
paths.push({ points, closed: true });
|
|
35025
|
+
current = points[0];
|
|
35026
|
+
points = [];
|
|
35027
|
+
}
|
|
35028
|
+
} else if (segment.kind === "rect") {
|
|
35029
|
+
if (points.length) paths.push({ points, closed: false });
|
|
35030
|
+
const first = toScreen(segment.x, segment.y);
|
|
35031
|
+
paths.push({ points: [
|
|
35032
|
+
first,
|
|
35033
|
+
toScreen(segment.x + segment.width, segment.y),
|
|
35034
|
+
toScreen(segment.x + segment.width, segment.y + segment.height),
|
|
35035
|
+
toScreen(segment.x, segment.y + segment.height)
|
|
35036
|
+
], closed: true });
|
|
35037
|
+
current = first;
|
|
35038
|
+
points = [];
|
|
35039
|
+
}
|
|
35040
|
+
}
|
|
35041
|
+
if (points.length) paths.push({ points, closed: false });
|
|
35042
|
+
return paths;
|
|
35043
|
+
}
|
|
35044
|
+
function inverseStrokeMatrix(matrix) {
|
|
35045
|
+
const [a, b, c, d, e, f] = matrix;
|
|
35046
|
+
const det = a * d - b * c;
|
|
35047
|
+
if (!Number.isFinite(det) || det === 0) return void 0;
|
|
35048
|
+
return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
|
|
35049
|
+
}
|
|
35050
|
+
function prepareStroke(path, scale) {
|
|
35051
|
+
const matrix = path.strokeMatrix ? [...path.strokeMatrix] : [1, 0, 0, 1, 0, 0];
|
|
35052
|
+
const [a, b, c, d] = matrix;
|
|
35053
|
+
const area = Math.abs(a * d - b * c) * scale * scale;
|
|
35054
|
+
if (!(area > 0) || !Number.isFinite(area)) return void 0;
|
|
35055
|
+
const normX = Math.hypot(a, b) * scale, normY = Math.hypot(c, d) * scale;
|
|
35056
|
+
let width = path.strokeWidth || 1;
|
|
35057
|
+
const scaleX = path.strokeWidth === 0 ? normY / area : Math.max(1, normY / (width * area));
|
|
35058
|
+
const scaleY = path.strokeWidth === 0 ? normX / area : Math.max(1, normX / (width * area));
|
|
35059
|
+
let dashArray = path.dashArray, dashPhase = path.dashPhase ?? 0;
|
|
35060
|
+
if (scaleX === scaleY) {
|
|
35061
|
+
width *= scaleX;
|
|
35062
|
+
} else {
|
|
35063
|
+
matrix[0] *= scaleX;
|
|
35064
|
+
matrix[1] *= scaleX;
|
|
35065
|
+
matrix[2] *= scaleY;
|
|
35066
|
+
matrix[3] *= scaleY;
|
|
35067
|
+
if (dashArray?.length) {
|
|
35068
|
+
const dashScale = Math.max(scaleX, scaleY);
|
|
35069
|
+
dashArray = dashArray.map((value) => value / dashScale);
|
|
35070
|
+
dashPhase /= dashScale;
|
|
35071
|
+
}
|
|
35072
|
+
}
|
|
35073
|
+
return { matrix, width, dashArray, dashPhase };
|
|
35074
|
+
}
|
|
35075
|
+
function strokeEdges(path, pageHeight, scale) {
|
|
35076
|
+
const stroke = prepareStroke(path, scale);
|
|
35077
|
+
if (!stroke) return [];
|
|
35078
|
+
const inverse = inverseStrokeMatrix(stroke.matrix);
|
|
35079
|
+
if (!inverse) return [];
|
|
35080
|
+
const [a, b, c, d, e, f] = stroke.matrix;
|
|
35081
|
+
const strokeScale = scale * Math.hypot(a, b, c, d);
|
|
35082
|
+
const project = (x, y) => [
|
|
35083
|
+
(inverse[0] * x + inverse[2] * y + inverse[4]) * strokeScale,
|
|
35084
|
+
(inverse[1] * x + inverse[3] * y + inverse[5]) * strokeScale
|
|
35085
|
+
];
|
|
35086
|
+
const toScreen = ([x, y]) => [
|
|
35087
|
+
(a * x / strokeScale + c * y / strokeScale + e) * scale,
|
|
35088
|
+
(pageHeight - b * x / strokeScale - d * y / strokeScale - f) * scale
|
|
35089
|
+
];
|
|
35090
|
+
const contours = strokeOutlines(
|
|
35091
|
+
segmentsToScreenPaths(path.segments, pageHeight, scale, project),
|
|
35092
|
+
stroke.width * strokeScale,
|
|
35093
|
+
path.lineCap ?? 0,
|
|
35094
|
+
path.lineJoin ?? 0,
|
|
35095
|
+
path.miterLimit ?? 10,
|
|
35096
|
+
stroke.dashArray?.map((value) => Math.max(0, value * strokeScale)),
|
|
35097
|
+
stroke.dashPhase * strokeScale
|
|
35098
|
+
);
|
|
35099
|
+
return pathsToEdges(contours.map((points) => ({ points: points.map(toScreen), closed: true })));
|
|
34864
35100
|
}
|
|
34865
|
-
function
|
|
35101
|
+
function pathsToEdges(paths, closeSubpaths = false) {
|
|
34866
35102
|
const edges = [];
|
|
34867
|
-
|
|
34868
|
-
|
|
34869
|
-
|
|
34870
|
-
|
|
34871
|
-
|
|
34872
|
-
|
|
34873
|
-
|
|
34874
|
-
|
|
34875
|
-
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
34876
|
-
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
34877
|
-
}
|
|
34878
|
-
[curX, curY] = toScreen(seg.x, seg.y);
|
|
34879
|
-
startX = curX;
|
|
34880
|
-
startY = curY;
|
|
34881
|
-
hasOpenSubpath = false;
|
|
34882
|
-
} else if (seg.kind === "line") {
|
|
34883
|
-
const [nx, ny] = toScreen(seg.x, seg.y);
|
|
34884
|
-
edges.push({ x0: curX, y0: curY, x1: nx, y1: ny });
|
|
34885
|
-
curX = nx;
|
|
34886
|
-
curY = ny;
|
|
34887
|
-
hasOpenSubpath = true;
|
|
34888
|
-
} else if (seg.kind === "cubic") {
|
|
34889
|
-
const [p1x, p1y] = toScreen(seg.x1, seg.y1);
|
|
34890
|
-
const [p2x, p2y] = toScreen(seg.x2, seg.y2);
|
|
34891
|
-
const [p3x, p3y] = toScreen(seg.x, seg.y);
|
|
34892
|
-
const points = flattenCubic(curX, curY, p1x, p1y, p2x, p2y, p3x, p3y);
|
|
34893
|
-
let px = curX;
|
|
34894
|
-
let py = curY;
|
|
34895
|
-
for (let i = 1; i < points.length; i++) {
|
|
34896
|
-
const [qx, qy] = points[i];
|
|
34897
|
-
edges.push({ x0: px, y0: py, x1: qx, y1: qy });
|
|
34898
|
-
px = qx;
|
|
34899
|
-
py = qy;
|
|
34900
|
-
}
|
|
34901
|
-
curX = p3x;
|
|
34902
|
-
curY = p3y;
|
|
34903
|
-
hasOpenSubpath = true;
|
|
34904
|
-
} else if (seg.kind === "close") {
|
|
34905
|
-
if (curX !== startX || curY !== startY) {
|
|
34906
|
-
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
34907
|
-
curX = startX;
|
|
34908
|
-
curY = startY;
|
|
34909
|
-
}
|
|
34910
|
-
hasOpenSubpath = false;
|
|
34911
|
-
} else if (seg.kind === "rect") {
|
|
34912
|
-
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
34913
|
-
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
34914
|
-
}
|
|
34915
|
-
const [rx0, ry0] = toScreen(seg.x, seg.y);
|
|
34916
|
-
const [rx1, ry1] = toScreen(seg.x + seg.width, seg.y + seg.height);
|
|
34917
|
-
edges.push(
|
|
34918
|
-
{ x0: rx0, y0: ry0, x1: rx1, y1: ry0 },
|
|
34919
|
-
{ x0: rx1, y0: ry0, x1: rx1, y1: ry1 },
|
|
34920
|
-
{ x0: rx1, y0: ry1, x1: rx0, y1: ry1 },
|
|
34921
|
-
{ x0: rx0, y0: ry1, x1: rx0, y1: ry0 }
|
|
34922
|
-
);
|
|
34923
|
-
hasOpenSubpath = false;
|
|
35103
|
+
for (const { points, closed } of paths) {
|
|
35104
|
+
for (let i = 1; i < points.length; i++) {
|
|
35105
|
+
const a = points[i - 1], b = points[i];
|
|
35106
|
+
edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
|
|
35107
|
+
}
|
|
35108
|
+
if ((closed || closeSubpaths) && points.length > 1) {
|
|
35109
|
+
const a = points[points.length - 1], b = points[0];
|
|
35110
|
+
edges.push({ x0: a[0], y0: a[1], x1: b[0], y1: b[1] });
|
|
34924
35111
|
}
|
|
34925
|
-
}
|
|
34926
|
-
if (closeSubpaths && hasOpenSubpath && (curX !== startX || curY !== startY)) {
|
|
34927
|
-
edges.push({ x0: curX, y0: curY, x1: startX, y1: startY });
|
|
34928
35112
|
}
|
|
34929
35113
|
return edges;
|
|
34930
35114
|
}
|
|
@@ -35111,7 +35295,7 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
35111
35295
|
for (const clip of clips) {
|
|
35112
35296
|
const { segments, fillRule } = "segments" in clip ? clip : { segments: clip, fillRule: "nonzero" };
|
|
35113
35297
|
const layer = new Uint8Array(width * height * 4);
|
|
35114
|
-
fillEdgesScanline4x4(layer, width, height,
|
|
35298
|
+
fillEdgesScanline4x4(layer, width, height, pathsToEdges(segmentsToScreenPaths(segments, displayList.height, scale), true), { r: 1, g: 1, b: 1 }, 1, fillRule);
|
|
35115
35299
|
for (let i = 3; i < layer.length; i += 4) clipMask[i] = Math.round(clipMask[i] * layer[i] / 255);
|
|
35116
35300
|
}
|
|
35117
35301
|
cachedClips = clips;
|
|
@@ -35158,62 +35342,28 @@ function renderDisplayListToBitmap(displayList, options = {}) {
|
|
|
35158
35342
|
if (operation.kind === "path") {
|
|
35159
35343
|
const path = operation.value;
|
|
35160
35344
|
if (path.fillColor) {
|
|
35161
|
-
const edges =
|
|
35345
|
+
const edges = pathsToEdges(segmentsToScreenPaths(path.segments, displayList.height, scale), true);
|
|
35162
35346
|
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;
|
|
35163
35347
|
fillEdgesScanline4x4(rgba, width, height, edges, path.fillColor, path.fillAlpha ?? 1, path.fillRule ?? "nonzero", clipScreen, original.kind === "glyph" ? aaTxt : aaVec, path.blendMode, clipMask);
|
|
35164
35348
|
}
|
|
35165
35349
|
if (path.strokeColor) {
|
|
35166
|
-
const
|
|
35167
|
-
const rawSw = path.strokeWidth * scale;
|
|
35168
|
-
const sw = Math.max(1, rawSw);
|
|
35350
|
+
const rawSw = path.strokeWidth * scale * (path.strokeMatrix ? Math.hypot(path.strokeMatrix[0], path.strokeMatrix[1]) : 1);
|
|
35169
35351
|
const strokeAlpha = options.thinLineMode === "shape" && rawSw < 1 ? (path.strokeAlpha ?? 1) * Math.max(0.25, rawSw) : path.strokeAlpha ?? 1;
|
|
35170
|
-
const
|
|
35171
|
-
const
|
|
35172
|
-
|
|
35173
|
-
|
|
35174
|
-
|
|
35175
|
-
|
|
35176
|
-
|
|
35177
|
-
|
|
35178
|
-
|
|
35179
|
-
|
|
35180
|
-
|
|
35181
|
-
|
|
35182
|
-
|
|
35183
|
-
|
|
35184
|
-
|
|
35185
|
-
let dIdx = 0;
|
|
35186
|
-
while (dIdx < dashArr.length - 1 && cycleRem >= dashArr[dIdx]) {
|
|
35187
|
-
cycleRem -= dashArr[dIdx];
|
|
35188
|
-
dIdx++;
|
|
35189
|
-
}
|
|
35190
|
-
const segRemainInDash = Math.max(1e-4, dashArr[dIdx] - cycleRem);
|
|
35191
|
-
const step = Math.min(edgeLen - pos, segRemainInDash);
|
|
35192
|
-
if (dIdx % 2 === 0) {
|
|
35193
|
-
const t0 = pos / edgeLen;
|
|
35194
|
-
const t1 = (pos + step) / edgeLen;
|
|
35195
|
-
drawAntiAliasedSegment(
|
|
35196
|
-
rgba,
|
|
35197
|
-
width,
|
|
35198
|
-
height,
|
|
35199
|
-
e.x0 + dx * t0,
|
|
35200
|
-
e.y0 + dy * t0,
|
|
35201
|
-
e.x0 + dx * t1,
|
|
35202
|
-
e.y0 + dy * t1,
|
|
35203
|
-
sw,
|
|
35204
|
-
path.strokeColor,
|
|
35205
|
-
strokeAlpha,
|
|
35206
|
-
path.lineCap ?? 0,
|
|
35207
|
-
original.kind === "glyph" ? aaTxt : aaVec,
|
|
35208
|
-
path.blendMode,
|
|
35209
|
-
clipMask
|
|
35210
|
-
);
|
|
35211
|
-
}
|
|
35212
|
-
pos += step;
|
|
35213
|
-
dashDist = (dashDist + step) % dashCycle;
|
|
35214
|
-
}
|
|
35215
|
-
}
|
|
35216
|
-
}
|
|
35352
|
+
const edges = strokeEdges(path, displayList.height, scale);
|
|
35353
|
+
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;
|
|
35354
|
+
fillEdgesScanline4x4(
|
|
35355
|
+
rgba,
|
|
35356
|
+
width,
|
|
35357
|
+
height,
|
|
35358
|
+
edges,
|
|
35359
|
+
path.strokeColor,
|
|
35360
|
+
strokeAlpha,
|
|
35361
|
+
"nonzero",
|
|
35362
|
+
clipScreen,
|
|
35363
|
+
original.kind === "glyph" ? aaTxt : aaVec,
|
|
35364
|
+
path.blendMode,
|
|
35365
|
+
clipMask
|
|
35366
|
+
);
|
|
35217
35367
|
}
|
|
35218
35368
|
} else if (operation.kind === "image") {
|
|
35219
35369
|
const img = operation.value;
|
|
@@ -37474,3 +37624,15 @@ export {
|
|
|
37474
37624
|
* Copyright 2012 Mozilla Foundation. Licensed under Apache-2.0.
|
|
37475
37625
|
* See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
|
|
37476
37626
|
*/
|
|
37627
|
+
/*!
|
|
37628
|
+
* Anti-Grain Geometry - Version 2.3
|
|
37629
|
+
* Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
|
37630
|
+
*
|
|
37631
|
+
* Permission to copy, use, modify, sell and distribute this software
|
|
37632
|
+
* is granted provided this copyright notice appears in all copies.
|
|
37633
|
+
* This software is provided "as is" without express or implied
|
|
37634
|
+
* warranty, and with no claim as to its suitability for any purpose.
|
|
37635
|
+
*
|
|
37636
|
+
* Adapted from PDFium agg_math_stroke.h and agg_vcgen_stroke.cpp.
|
|
37637
|
+
* See THIRD_PARTY_NOTICES.md for the source revision and adaptations.
|
|
37638
|
+
*/
|
|
@@ -7,6 +7,7 @@ import asyncio
|
|
|
7
7
|
import copy
|
|
8
8
|
import inspect
|
|
9
9
|
import math
|
|
10
|
+
import os
|
|
10
11
|
from dataclasses import dataclass, field, replace
|
|
11
12
|
from typing import Any, AsyncIterator, Callable, Mapping, Optional, Protocol, Sequence, Union
|
|
12
13
|
|
|
@@ -49,7 +50,8 @@ class Attachment:
|
|
|
49
50
|
def payload(self):
|
|
50
51
|
if not isinstance(self.path, str) or not self.path or "\0" in self.path:
|
|
51
52
|
raise ValueError("Attachment requires an agent filesystem path")
|
|
52
|
-
|
|
53
|
+
path = self.path if os.path.isabs(self.path) else os.path.join(os.getcwd(), self.path)
|
|
54
|
+
result = {"path": path}
|
|
53
55
|
if self.mime_type is not None:
|
|
54
56
|
result["mimeType"] = self.mime_type
|
|
55
57
|
return result
|
|
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
import asyncio
|
|
5
5
|
import math
|
|
6
6
|
import inspect
|
|
7
|
+
import os
|
|
7
8
|
import subprocess
|
|
8
9
|
from dataclasses import dataclass
|
|
9
10
|
|
|
@@ -59,6 +60,12 @@ def _payload(args, *, shell=False, input=None, cwd=None, env=None, timeout=None,
|
|
|
59
60
|
elif not isinstance(input, (bytes, bytearray, memoryview)):
|
|
60
61
|
raise TypeError('Binary input must be bytes')
|
|
61
62
|
result['input'] = list(input)
|
|
63
|
+
# The host retains the original shell context; snapshot the current guest state.
|
|
64
|
+
if cwd is None:
|
|
65
|
+
cwd = os.getcwd()
|
|
66
|
+
elif cwd and not os.path.isabs(cwd):
|
|
67
|
+
cwd = os.path.join(os.getcwd(), cwd)
|
|
68
|
+
env = dict(os.environ if env is None else env)
|
|
62
69
|
result.update(cwd=cwd, env=env, timeout=timeout, max_output_bytes=max_output_bytes)
|
|
63
70
|
return result
|
|
64
71
|
|