@poe-platform/safe-bash 0.1.773 → 0.1.775

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 +754 -162
  2. package/dist/image-ast/index.js +754 -162
  3. package/dist/pdf-ast/index.js +754 -162
  4. package/dist/pdf-ast/vendor/pdfjs-fonts.d.mts +12 -0
  5. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +702 -0
  6. package/dist/safe-bash/command-chunks/{chunk-B2MM5DIT.js → chunk-3444RZLY.js} +754 -162
  7. package/dist/safe-bash/command-chunks/{chunk-G3NVK25P.js → chunk-QLYJUVVM.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-5VXZSNM2.js → chunk-ZY6PMCW5.js} +2 -2
  9. package/dist/safe-bash/core.browser.js +63 -7
  10. package/dist/safe-bash/shell/runtime.js +17 -9
  11. package/dist/safe-bash/shell/sync-posix-regex.d.ts +3 -0
  12. package/dist/safe-bash/shell/sync-posix-regex.js +48 -0
  13. package/dist/safe-bash-command-ffmpeg/index.js +7249 -7039
  14. package/dist/safe-bash-command-gpg/index.js +28 -7
  15. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  16. package/dist/safe-bash-command-openssl/index.js +24 -6
  17. package/dist/safe-bash-command-pandoc/command.js +3 -3
  18. package/dist/safe-bash-command-pandoc/index.js +3 -3
  19. package/dist/safe-bash-command-pdfimages/index.js +754 -162
  20. package/dist/safe-bash-command-pdfinfo/index.js +754 -162
  21. package/dist/safe-bash-command-pdftk/index.js +754 -162
  22. package/dist/safe-bash-command-pdftoppm/index.js +754 -162
  23. package/dist/safe-bash-command-pdftotext/index.js +754 -162
  24. package/dist/safe-bash-command-qpdf/index.js +754 -162
  25. package/dist/safe-bash-command-sips/index.js +2 -2
  26. package/dist/safe-bash-command-soffice/index.js +1 -1
  27. package/dist/safe-bash-command-ssconvert/index.js +754 -162
  28. package/dist/safe-bash-command-ssh/index.js +124 -23
  29. package/dist/safe-bash-command-wkhtmltopdf/index.js +760 -162
  30. package/package.json +2 -2
  31. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +29 -0
@@ -144,6 +144,11 @@ var FONT_IDENTITY_MATRIX = [1e-3, 0, 0, 1e-3, 0, 0];
144
144
  var LINE_FACTOR = 1.35;
145
145
  var LINE_DESCENT_FACTOR = 0.35;
146
146
  var BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
147
+ var MeshFigureType = {
148
+ TRIANGLES: 1,
149
+ LATTICE: 2,
150
+ PATCH: 3
151
+ };
147
152
  var VerbosityLevel = {
148
153
  ERRORS: 0,
149
154
  WARNINGS: 1,
@@ -21937,6 +21942,702 @@ function buildPostScriptJsFunction(source, domain, range, forceInterpreter = fal
21937
21942
  }
21938
21943
  return PSStackBasedInterpreter.build(program, domain, range);
21939
21944
  }
21945
+
21946
+ // src/core/pattern.js
21947
+ var ShadingType = {
21948
+ FUNCTION_BASED: 1,
21949
+ AXIAL: 2,
21950
+ RADIAL: 3,
21951
+ FREE_FORM_MESH: 4,
21952
+ LATTICE_FORM_MESH: 5,
21953
+ COONS_PATCH_MESH: 6,
21954
+ TENSOR_PATCH_MESH: 7
21955
+ };
21956
+ var BaseShading = class _BaseShading {
21957
+ // A small number to offset the first/last color stops so we can insert ones
21958
+ // to support extend. Number.MIN_VALUE is too small and breaks the extend.
21959
+ static SMALL_NUMBER = 1e-6;
21960
+ constructor() {
21961
+ if ((typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) && this.constructor === _BaseShading) {
21962
+ unreachable("Cannot initialize BaseShading.");
21963
+ }
21964
+ }
21965
+ getIR() {
21966
+ unreachable("Abstract method `getIR` called.");
21967
+ }
21968
+ };
21969
+ function meshUpdateBounds(self) {
21970
+ let minX = self.coords[0][0], minY = self.coords[0][1], maxX = minX, maxY = minY;
21971
+ for (let i = 1, ii = self.coords.length; i < ii; i++) {
21972
+ const x = self.coords[i][0], y = self.coords[i][1];
21973
+ minX = minX > x ? x : minX;
21974
+ minY = minY > y ? y : minY;
21975
+ maxX = maxX < x ? x : maxX;
21976
+ maxY = maxY < y ? y : maxY;
21977
+ }
21978
+ self.bounds = [minX, minY, maxX, maxY];
21979
+ }
21980
+ function meshPackData(self) {
21981
+ let i, j, ii;
21982
+ const coords = self.coords;
21983
+ const coordsPacked = new Float32Array(coords.length * 2);
21984
+ for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
21985
+ const xy = coords[i];
21986
+ coordsPacked[j++] = xy[0];
21987
+ coordsPacked[j++] = xy[1];
21988
+ }
21989
+ self.coords = coordsPacked;
21990
+ const colors = self.colors;
21991
+ const colorsPacked = new Uint8Array(colors.length * 4);
21992
+ for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
21993
+ const c = colors[i];
21994
+ colorsPacked[j++] = c[0];
21995
+ colorsPacked[j++] = c[1];
21996
+ colorsPacked[j++] = c[2];
21997
+ j++;
21998
+ }
21999
+ self.colors = colorsPacked;
22000
+ for (const figure of self.figures) {
22001
+ figure.coords = new Uint32Array(figure.coords);
22002
+ figure.colors = new Uint32Array(figure.colors);
22003
+ }
22004
+ }
22005
+ function buildMeshVertexData(coords, colors, figures) {
22006
+ let vertexCount = 0;
22007
+ for (const figure of figures) {
22008
+ if (figure.type === MeshFigureType.TRIANGLES) {
22009
+ vertexCount += figure.coords.length;
22010
+ } else if (figure.type === MeshFigureType.LATTICE) {
22011
+ const vpr = figure.verticesPerRow;
22012
+ vertexCount += (Math.floor(figure.coords.length / vpr) - 1) * (vpr - 1) * 6;
22013
+ }
22014
+ }
22015
+ const posData = new Float32Array(vertexCount * 2);
22016
+ const colData = new Uint8Array(vertexCount * 4);
22017
+ let pOff = 0, cOff = 0;
22018
+ const addVertex = (pi, ci) => {
22019
+ posData[pOff++] = coords[pi * 2];
22020
+ posData[pOff++] = coords[pi * 2 + 1];
22021
+ colData[cOff++] = colors[ci * 4];
22022
+ colData[cOff++] = colors[ci * 4 + 1];
22023
+ colData[cOff++] = colors[ci * 4 + 2];
22024
+ cOff++;
22025
+ };
22026
+ for (const figure of figures) {
22027
+ const ps = figure.coords;
22028
+ const cs = figure.colors;
22029
+ if (figure.type === MeshFigureType.TRIANGLES) {
22030
+ for (let i = 0, ii = ps.length; i < ii; i++) {
22031
+ addVertex(ps[i], cs[i]);
22032
+ }
22033
+ } else if (figure.type === MeshFigureType.LATTICE) {
22034
+ const vpr = figure.verticesPerRow;
22035
+ const rows = Math.floor(ps.length / vpr) - 1;
22036
+ const cols = vpr - 1;
22037
+ for (let i = 0; i < rows; i++) {
22038
+ let q = i * vpr;
22039
+ for (let j = 0; j < cols; j++, q++) {
22040
+ addVertex(ps[q], cs[q]);
22041
+ addVertex(ps[q + 1], cs[q + 1]);
22042
+ addVertex(ps[q + vpr], cs[q + vpr]);
22043
+ addVertex(ps[q + vpr + 1], cs[q + vpr + 1]);
22044
+ addVertex(ps[q + 1], cs[q + 1]);
22045
+ addVertex(ps[q + vpr], cs[q + vpr]);
22046
+ }
22047
+ }
22048
+ }
22049
+ }
22050
+ return { posData, colData, vertexCount };
22051
+ }
22052
+ var MeshStreamReader = class {
22053
+ constructor(stream, context) {
22054
+ this.stream = stream;
22055
+ this.context = context;
22056
+ this.buffer = 0;
22057
+ this.bufferLength = 0;
22058
+ const numComps = context.numComps;
22059
+ this.tmpCompsBuf = new Float32Array(numComps);
22060
+ const csNumComps = context.colorSpace.numComps;
22061
+ this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) : this.tmpCompsBuf;
22062
+ }
22063
+ get hasData() {
22064
+ if (this.stream.end) {
22065
+ return this.stream.pos < this.stream.end;
22066
+ }
22067
+ if (this.bufferLength > 0) {
22068
+ return true;
22069
+ }
22070
+ const nextByte = this.stream.getByte();
22071
+ if (nextByte < 0) {
22072
+ return false;
22073
+ }
22074
+ this.buffer = nextByte;
22075
+ this.bufferLength = 8;
22076
+ return true;
22077
+ }
22078
+ readBits(n) {
22079
+ const { stream } = this;
22080
+ let { buffer, bufferLength } = this;
22081
+ if (n === 32) {
22082
+ if (bufferLength === 0) {
22083
+ return stream.getInt32() >>> 0;
22084
+ }
22085
+ buffer = buffer << 24 | stream.getByte() << 16 | stream.getByte() << 8 | stream.getByte();
22086
+ const nextByte = stream.getByte();
22087
+ this.buffer = nextByte & (1 << bufferLength) - 1;
22088
+ return (buffer << 8 - bufferLength | (nextByte & 255) >> bufferLength) >>> 0;
22089
+ }
22090
+ if (n === 8 && bufferLength === 0) {
22091
+ return stream.getByte();
22092
+ }
22093
+ while (bufferLength < n) {
22094
+ buffer = buffer << 8 | stream.getByte();
22095
+ bufferLength += 8;
22096
+ }
22097
+ bufferLength -= n;
22098
+ this.bufferLength = bufferLength;
22099
+ this.buffer = buffer & (1 << bufferLength) - 1;
22100
+ return buffer >> bufferLength;
22101
+ }
22102
+ align() {
22103
+ this.buffer = 0;
22104
+ this.bufferLength = 0;
22105
+ }
22106
+ readFlag() {
22107
+ return this.readBits(this.context.bitsPerFlag);
22108
+ }
22109
+ readCoordinate() {
22110
+ const { bitsPerCoordinate, decode } = this.context;
22111
+ const xi = this.readBits(bitsPerCoordinate);
22112
+ const yi = this.readBits(bitsPerCoordinate);
22113
+ const scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) : 23283064365386963e-26;
22114
+ return [
22115
+ xi * scale * (decode[1] - decode[0]) + decode[0],
22116
+ yi * scale * (decode[3] - decode[2]) + decode[2]
22117
+ ];
22118
+ }
22119
+ readComponents() {
22120
+ const { bitsPerComponent, colorFn, colorSpace, decode, numComps } = this.context;
22121
+ const scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) : 23283064365386963e-26;
22122
+ const components = this.tmpCompsBuf;
22123
+ for (let i = 0, j = 4; i < numComps; i++, j += 2) {
22124
+ const ci = this.readBits(bitsPerComponent);
22125
+ components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
22126
+ }
22127
+ const color = this.tmpCsCompsBuf;
22128
+ colorFn?.(components, 0, color, 0);
22129
+ return colorSpace.getRgb(color, 0);
22130
+ }
22131
+ };
22132
+ var bCache = null;
22133
+ function getB(count) {
22134
+ if (bCache?.has(count)) return bCache.get(count);
22135
+ const values = Array.from({ length: count + 1 }, (_, i) => {
22136
+ const t = i / count, t_ = 1 - t;
22137
+ return new Float32Array([
22138
+ t_ ** 3,
22139
+ 3 * t * t_ ** 2,
22140
+ 3 * t ** 2 * t_,
22141
+ t ** 3
22142
+ ]);
22143
+ });
22144
+ (bCache ??= /* @__PURE__ */ new Map()).set(count, values);
22145
+ return values;
22146
+ }
22147
+ var MeshShading = class _MeshShading extends BaseShading {
22148
+ static MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
22149
+ static MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
22150
+ // Count of triangles per entire mesh bounds.
22151
+ static TRIANGLE_DENSITY = 20;
22152
+ constructor(shadingType, stream, context, rowVertices) {
22153
+ super();
22154
+ this.shadingType = shadingType;
22155
+ this.bbox = this.background = null;
22156
+ this.coords = [];
22157
+ this.colors = [];
22158
+ this.figures = [];
22159
+ const reader = new MeshStreamReader(stream, context);
22160
+ let patchMesh = false;
22161
+ switch (this.shadingType) {
22162
+ case ShadingType.FREE_FORM_MESH:
22163
+ this._decodeType4Shading(reader);
22164
+ break;
22165
+ case ShadingType.LATTICE_FORM_MESH:
22166
+ const verticesPerRow = rowVertices | 0;
22167
+ if (verticesPerRow < 2) {
22168
+ throw new FormatError("Invalid VerticesPerRow");
22169
+ }
22170
+ this._decodeType5Shading(reader, verticesPerRow);
22171
+ break;
22172
+ case ShadingType.COONS_PATCH_MESH:
22173
+ this._decodeType6Shading(reader);
22174
+ patchMesh = true;
22175
+ break;
22176
+ case ShadingType.TENSOR_PATCH_MESH:
22177
+ this._decodeType7Shading(reader);
22178
+ patchMesh = true;
22179
+ break;
22180
+ default:
22181
+ unreachable("Unsupported mesh type.");
22182
+ break;
22183
+ }
22184
+ if (patchMesh) {
22185
+ this._updateBounds();
22186
+ for (let i = 0, ii = this.figures.length; i < ii; i++) {
22187
+ this._buildFigureFromPatch(i);
22188
+ }
22189
+ }
22190
+ this._updateBounds();
22191
+ this._packData();
22192
+ }
22193
+ _decodeType4Shading(reader) {
22194
+ const coords = this.coords;
22195
+ const colors = this.colors;
22196
+ const operators = [];
22197
+ const ps = [];
22198
+ let verticesLeft = 0;
22199
+ while (reader.hasData) {
22200
+ const f = reader.readFlag();
22201
+ const coord = reader.readCoordinate();
22202
+ const color = reader.readComponents();
22203
+ if (verticesLeft === 0) {
22204
+ if (!(0 <= f && f <= 2)) {
22205
+ throw new FormatError("Unknown type4 flag");
22206
+ }
22207
+ switch (f) {
22208
+ case 0:
22209
+ verticesLeft = 3;
22210
+ break;
22211
+ case 1:
22212
+ ps.push(ps.at(-2), ps.at(-1));
22213
+ verticesLeft = 1;
22214
+ break;
22215
+ case 2:
22216
+ ps.push(ps.at(-3), ps.at(-1));
22217
+ verticesLeft = 1;
22218
+ break;
22219
+ }
22220
+ operators.push(f);
22221
+ }
22222
+ ps.push(coords.length);
22223
+ coords.push(coord);
22224
+ colors.push(color);
22225
+ verticesLeft--;
22226
+ reader.align();
22227
+ }
22228
+ this.figures.push({
22229
+ type: MeshFigureType.TRIANGLES,
22230
+ coords: new Int32Array(ps),
22231
+ colors: new Int32Array(ps)
22232
+ });
22233
+ }
22234
+ _decodeType5Shading(reader, verticesPerRow) {
22235
+ const coords = this.coords;
22236
+ const colors = this.colors;
22237
+ const ps = [];
22238
+ while (reader.hasData) {
22239
+ const coord = reader.readCoordinate();
22240
+ const color = reader.readComponents();
22241
+ ps.push(coords.length);
22242
+ coords.push(coord);
22243
+ colors.push(color);
22244
+ }
22245
+ this.figures.push({
22246
+ type: MeshFigureType.LATTICE,
22247
+ coords: new Int32Array(ps),
22248
+ colors: new Int32Array(ps),
22249
+ verticesPerRow
22250
+ });
22251
+ }
22252
+ _decodeType6Shading(reader) {
22253
+ const coords = this.coords;
22254
+ const colors = this.colors;
22255
+ const ps = new Int32Array(16);
22256
+ const cs = new Int32Array(4);
22257
+ while (reader.hasData) {
22258
+ const f = reader.readFlag();
22259
+ if (!(0 <= f && f <= 3)) {
22260
+ throw new FormatError("Unknown type6 flag");
22261
+ }
22262
+ const pi = coords.length;
22263
+ for (let i = 0, ii = f !== 0 ? 8 : 12; i < ii; i++) {
22264
+ coords.push(reader.readCoordinate());
22265
+ }
22266
+ const ci = colors.length;
22267
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
22268
+ colors.push(reader.readComponents());
22269
+ }
22270
+ let tmp1, tmp2, tmp3, tmp4;
22271
+ switch (f) {
22272
+ // prettier-ignore
22273
+ case 0:
22274
+ ps[12] = pi + 3;
22275
+ ps[13] = pi + 4;
22276
+ ps[14] = pi + 5;
22277
+ ps[15] = pi + 6;
22278
+ ps[8] = pi + 2;
22279
+ ps[11] = pi + 7;
22280
+ ps[4] = pi + 1;
22281
+ ps[7] = pi + 8;
22282
+ ps[0] = pi;
22283
+ ps[1] = pi + 11;
22284
+ ps[2] = pi + 10;
22285
+ ps[3] = pi + 9;
22286
+ cs[2] = ci + 1;
22287
+ cs[3] = ci + 2;
22288
+ cs[0] = ci;
22289
+ cs[1] = ci + 3;
22290
+ break;
22291
+ // prettier-ignore
22292
+ case 1:
22293
+ tmp1 = ps[12];
22294
+ tmp2 = ps[13];
22295
+ tmp3 = ps[14];
22296
+ tmp4 = ps[15];
22297
+ ps[12] = tmp4;
22298
+ ps[13] = pi + 0;
22299
+ ps[14] = pi + 1;
22300
+ ps[15] = pi + 2;
22301
+ ps[8] = tmp3;
22302
+ ps[11] = pi + 3;
22303
+ ps[4] = tmp2;
22304
+ ps[7] = pi + 4;
22305
+ ps[0] = tmp1;
22306
+ ps[1] = pi + 7;
22307
+ ps[2] = pi + 6;
22308
+ ps[3] = pi + 5;
22309
+ tmp1 = cs[2];
22310
+ tmp2 = cs[3];
22311
+ cs[2] = tmp2;
22312
+ cs[3] = ci;
22313
+ cs[0] = tmp1;
22314
+ cs[1] = ci + 1;
22315
+ break;
22316
+ // prettier-ignore
22317
+ case 2:
22318
+ tmp1 = ps[15];
22319
+ tmp2 = ps[11];
22320
+ ps[12] = ps[3];
22321
+ ps[13] = pi + 0;
22322
+ ps[14] = pi + 1;
22323
+ ps[15] = pi + 2;
22324
+ ps[8] = ps[7];
22325
+ ps[11] = pi + 3;
22326
+ ps[4] = tmp2;
22327
+ ps[7] = pi + 4;
22328
+ ps[0] = tmp1;
22329
+ ps[1] = pi + 7;
22330
+ ps[2] = pi + 6;
22331
+ ps[3] = pi + 5;
22332
+ tmp1 = cs[3];
22333
+ cs[2] = cs[1];
22334
+ cs[3] = ci;
22335
+ cs[0] = tmp1;
22336
+ cs[1] = ci + 1;
22337
+ break;
22338
+ // prettier-ignore
22339
+ case 3:
22340
+ ps[12] = ps[0];
22341
+ ps[13] = pi + 0;
22342
+ ps[14] = pi + 1;
22343
+ ps[15] = pi + 2;
22344
+ ps[8] = ps[1];
22345
+ ps[11] = pi + 3;
22346
+ ps[4] = ps[2];
22347
+ ps[7] = pi + 4;
22348
+ ps[0] = ps[3];
22349
+ ps[1] = pi + 7;
22350
+ ps[2] = pi + 6;
22351
+ ps[3] = pi + 5;
22352
+ cs[2] = cs[0];
22353
+ cs[3] = ci;
22354
+ cs[0] = cs[1];
22355
+ cs[1] = ci + 1;
22356
+ break;
22357
+ }
22358
+ ps[5] = coords.length;
22359
+ coords.push([
22360
+ (-4 * coords[ps[0]][0] - coords[ps[15]][0] + 6 * (coords[ps[4]][0] + coords[ps[1]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
22361
+ (-4 * coords[ps[0]][1] - coords[ps[15]][1] + 6 * (coords[ps[4]][1] + coords[ps[1]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
22362
+ ]);
22363
+ ps[6] = coords.length;
22364
+ coords.push([
22365
+ (-4 * coords[ps[3]][0] - coords[ps[12]][0] + 6 * (coords[ps[2]][0] + coords[ps[7]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
22366
+ (-4 * coords[ps[3]][1] - coords[ps[12]][1] + 6 * (coords[ps[2]][1] + coords[ps[7]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
22367
+ ]);
22368
+ ps[9] = coords.length;
22369
+ coords.push([
22370
+ (-4 * coords[ps[12]][0] - coords[ps[3]][0] + 6 * (coords[ps[8]][0] + coords[ps[13]][0]) - 2 * (coords[ps[0]][0] + coords[ps[15]][0]) + 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
22371
+ (-4 * coords[ps[12]][1] - coords[ps[3]][1] + 6 * (coords[ps[8]][1] + coords[ps[13]][1]) - 2 * (coords[ps[0]][1] + coords[ps[15]][1]) + 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
22372
+ ]);
22373
+ ps[10] = coords.length;
22374
+ coords.push([
22375
+ (-4 * coords[ps[15]][0] - coords[ps[0]][0] + 6 * (coords[ps[11]][0] + coords[ps[14]][0]) - 2 * (coords[ps[12]][0] + coords[ps[3]][0]) + 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
22376
+ (-4 * coords[ps[15]][1] - coords[ps[0]][1] + 6 * (coords[ps[11]][1] + coords[ps[14]][1]) - 2 * (coords[ps[12]][1] + coords[ps[3]][1]) + 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
22377
+ ]);
22378
+ this.figures.push({
22379
+ type: MeshFigureType.PATCH,
22380
+ coords: new Int32Array(ps),
22381
+ // making copies of ps and cs
22382
+ colors: new Int32Array(cs)
22383
+ });
22384
+ }
22385
+ }
22386
+ _decodeType7Shading(reader) {
22387
+ const coords = this.coords;
22388
+ const colors = this.colors;
22389
+ const ps = new Int32Array(16);
22390
+ const cs = new Int32Array(4);
22391
+ while (reader.hasData) {
22392
+ const f = reader.readFlag();
22393
+ if (!(0 <= f && f <= 3)) {
22394
+ throw new FormatError("Unknown type7 flag");
22395
+ }
22396
+ const pi = coords.length;
22397
+ for (let i = 0, ii = f !== 0 ? 12 : 16; i < ii; i++) {
22398
+ coords.push(reader.readCoordinate());
22399
+ }
22400
+ const ci = colors.length;
22401
+ for (let i = 0, ii = f !== 0 ? 2 : 4; i < ii; i++) {
22402
+ colors.push(reader.readComponents());
22403
+ }
22404
+ let tmp1, tmp2, tmp3, tmp4;
22405
+ switch (f) {
22406
+ // prettier-ignore
22407
+ case 0:
22408
+ ps[12] = pi + 3;
22409
+ ps[13] = pi + 4;
22410
+ ps[14] = pi + 5;
22411
+ ps[15] = pi + 6;
22412
+ ps[8] = pi + 2;
22413
+ ps[9] = pi + 13;
22414
+ ps[10] = pi + 14;
22415
+ ps[11] = pi + 7;
22416
+ ps[4] = pi + 1;
22417
+ ps[5] = pi + 12;
22418
+ ps[6] = pi + 15;
22419
+ ps[7] = pi + 8;
22420
+ ps[0] = pi;
22421
+ ps[1] = pi + 11;
22422
+ ps[2] = pi + 10;
22423
+ ps[3] = pi + 9;
22424
+ cs[2] = ci + 1;
22425
+ cs[3] = ci + 2;
22426
+ cs[0] = ci;
22427
+ cs[1] = ci + 3;
22428
+ break;
22429
+ // prettier-ignore
22430
+ case 1:
22431
+ tmp1 = ps[12];
22432
+ tmp2 = ps[13];
22433
+ tmp3 = ps[14];
22434
+ tmp4 = ps[15];
22435
+ ps[12] = tmp4;
22436
+ ps[13] = pi + 0;
22437
+ ps[14] = pi + 1;
22438
+ ps[15] = pi + 2;
22439
+ ps[8] = tmp3;
22440
+ ps[9] = pi + 9;
22441
+ ps[10] = pi + 10;
22442
+ ps[11] = pi + 3;
22443
+ ps[4] = tmp2;
22444
+ ps[5] = pi + 8;
22445
+ ps[6] = pi + 11;
22446
+ ps[7] = pi + 4;
22447
+ ps[0] = tmp1;
22448
+ ps[1] = pi + 7;
22449
+ ps[2] = pi + 6;
22450
+ ps[3] = pi + 5;
22451
+ tmp1 = cs[2];
22452
+ tmp2 = cs[3];
22453
+ cs[2] = tmp2;
22454
+ cs[3] = ci;
22455
+ cs[0] = tmp1;
22456
+ cs[1] = ci + 1;
22457
+ break;
22458
+ // prettier-ignore
22459
+ case 2:
22460
+ tmp1 = ps[15];
22461
+ tmp2 = ps[11];
22462
+ ps[12] = ps[3];
22463
+ ps[13] = pi + 0;
22464
+ ps[14] = pi + 1;
22465
+ ps[15] = pi + 2;
22466
+ ps[8] = ps[7];
22467
+ ps[9] = pi + 9;
22468
+ ps[10] = pi + 10;
22469
+ ps[11] = pi + 3;
22470
+ ps[4] = tmp2;
22471
+ ps[5] = pi + 8;
22472
+ ps[6] = pi + 11;
22473
+ ps[7] = pi + 4;
22474
+ ps[0] = tmp1;
22475
+ ps[1] = pi + 7;
22476
+ ps[2] = pi + 6;
22477
+ ps[3] = pi + 5;
22478
+ tmp1 = cs[3];
22479
+ cs[2] = cs[1];
22480
+ cs[3] = ci;
22481
+ cs[0] = tmp1;
22482
+ cs[1] = ci + 1;
22483
+ break;
22484
+ // prettier-ignore
22485
+ case 3:
22486
+ ps[12] = ps[0];
22487
+ ps[13] = pi + 0;
22488
+ ps[14] = pi + 1;
22489
+ ps[15] = pi + 2;
22490
+ ps[8] = ps[1];
22491
+ ps[9] = pi + 9;
22492
+ ps[10] = pi + 10;
22493
+ ps[11] = pi + 3;
22494
+ ps[4] = ps[2];
22495
+ ps[5] = pi + 8;
22496
+ ps[6] = pi + 11;
22497
+ ps[7] = pi + 4;
22498
+ ps[0] = ps[3];
22499
+ ps[1] = pi + 7;
22500
+ ps[2] = pi + 6;
22501
+ ps[3] = pi + 5;
22502
+ cs[2] = cs[0];
22503
+ cs[3] = ci;
22504
+ cs[0] = cs[1];
22505
+ cs[1] = ci + 1;
22506
+ break;
22507
+ }
22508
+ this.figures.push({
22509
+ type: MeshFigureType.PATCH,
22510
+ coords: new Int32Array(ps),
22511
+ // making copies of ps and cs
22512
+ colors: new Int32Array(cs)
22513
+ });
22514
+ }
22515
+ }
22516
+ _buildFigureFromPatch(index) {
22517
+ const figure = this.figures[index];
22518
+ assert(
22519
+ figure.type === MeshFigureType.PATCH,
22520
+ "Unexpected patch mesh figure"
22521
+ );
22522
+ const coords = this.coords, colors = this.colors;
22523
+ const pi = figure.coords;
22524
+ const ci = figure.colors;
22525
+ const figureMinX = Math.min(
22526
+ coords[pi[0]][0],
22527
+ coords[pi[3]][0],
22528
+ coords[pi[12]][0],
22529
+ coords[pi[15]][0]
22530
+ );
22531
+ const figureMinY = Math.min(
22532
+ coords[pi[0]][1],
22533
+ coords[pi[3]][1],
22534
+ coords[pi[12]][1],
22535
+ coords[pi[15]][1]
22536
+ );
22537
+ const figureMaxX = Math.max(
22538
+ coords[pi[0]][0],
22539
+ coords[pi[3]][0],
22540
+ coords[pi[12]][0],
22541
+ coords[pi[15]][0]
22542
+ );
22543
+ const figureMaxY = Math.max(
22544
+ coords[pi[0]][1],
22545
+ coords[pi[3]][1],
22546
+ coords[pi[12]][1],
22547
+ coords[pi[15]][1]
22548
+ );
22549
+ let splitXBy = Math.ceil(
22550
+ (figureMaxX - figureMinX) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[2] - this.bounds[0])
22551
+ );
22552
+ splitXBy = MathClamp(
22553
+ splitXBy,
22554
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
22555
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
22556
+ );
22557
+ let splitYBy = Math.ceil(
22558
+ (figureMaxY - figureMinY) * _MeshShading.TRIANGLE_DENSITY / (this.bounds[3] - this.bounds[1])
22559
+ );
22560
+ splitYBy = MathClamp(
22561
+ splitYBy,
22562
+ _MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
22563
+ _MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
22564
+ );
22565
+ const verticesPerRow = splitXBy + 1;
22566
+ const figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
22567
+ const figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
22568
+ let k = 0;
22569
+ const cl = new Uint8Array(3), cr = new Uint8Array(3);
22570
+ const c0 = colors[ci[0]], c1 = colors[ci[1]], c2 = colors[ci[2]], c3 = colors[ci[3]];
22571
+ const bRow = getB(splitYBy), bCol = getB(splitXBy);
22572
+ for (let row = 0; row <= splitYBy; row++) {
22573
+ cl[0] = (c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy | 0;
22574
+ cl[1] = (c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy | 0;
22575
+ cl[2] = (c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy | 0;
22576
+ cr[0] = (c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy | 0;
22577
+ cr[1] = (c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy | 0;
22578
+ cr[2] = (c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy | 0;
22579
+ for (let col = 0; col <= splitXBy; col++, k++) {
22580
+ if ((row === 0 || row === splitYBy) && (col === 0 || col === splitXBy)) {
22581
+ continue;
22582
+ }
22583
+ let x = 0, y = 0;
22584
+ let q = 0;
22585
+ for (let i = 0; i <= 3; i++) {
22586
+ for (let j = 0; j <= 3; j++, q++) {
22587
+ const m = bRow[row][i] * bCol[col][j];
22588
+ x += coords[pi[q]][0] * m;
22589
+ y += coords[pi[q]][1] * m;
22590
+ }
22591
+ }
22592
+ figureCoords[k] = coords.length;
22593
+ coords.push([x, y]);
22594
+ figureColors[k] = colors.length;
22595
+ const newColor = new Uint8Array(3);
22596
+ newColor[0] = (cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy | 0;
22597
+ newColor[1] = (cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy | 0;
22598
+ newColor[2] = (cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy | 0;
22599
+ colors.push(newColor);
22600
+ }
22601
+ }
22602
+ figureCoords[0] = pi[0];
22603
+ figureColors[0] = ci[0];
22604
+ figureCoords[splitXBy] = pi[3];
22605
+ figureColors[splitXBy] = ci[1];
22606
+ figureCoords[verticesPerRow * splitYBy] = pi[12];
22607
+ figureColors[verticesPerRow * splitYBy] = ci[2];
22608
+ figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
22609
+ figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
22610
+ this.figures[index] = {
22611
+ type: MeshFigureType.LATTICE,
22612
+ coords: figureCoords,
22613
+ colors: figureColors,
22614
+ verticesPerRow
22615
+ };
22616
+ }
22617
+ _updateBounds() {
22618
+ meshUpdateBounds(this);
22619
+ }
22620
+ _packData() {
22621
+ meshPackData(this);
22622
+ }
22623
+ getIR() {
22624
+ const { posData, colData, vertexCount } = buildMeshVertexData(
22625
+ this.coords,
22626
+ this.colors,
22627
+ this.figures
22628
+ );
22629
+ return [
22630
+ "Mesh",
22631
+ this.shadingType,
22632
+ posData,
22633
+ colData,
22634
+ vertexCount,
22635
+ this.bounds,
22636
+ this.bbox,
22637
+ this.background
22638
+ ];
22639
+ }
22640
+ };
21940
22641
  export {
21941
22642
  CFFCompiler,
21942
22643
  CFFParser,
@@ -21951,6 +22652,7 @@ export {
21951
22652
  FlateStream,
21952
22653
  LabCS,
21953
22654
  MacStandardGlyphOrdering,
22655
+ MeshShading,
21954
22656
  Name,
21955
22657
  PDF17,
21956
22658
  PDF20,