@poe-platform/safe-bash 0.1.754 → 0.1.756

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 (52) hide show
  1. package/dist/image-ast/index.browser.js +39 -3
  2. package/dist/image-ast/index.js +39 -3
  3. package/dist/pdf-ast/canvas.d.ts +1 -0
  4. package/dist/pdf-ast/fonts/truetype.d.ts +1 -0
  5. package/dist/pdf-ast/index.js +39 -3
  6. package/dist/safe-bash/chunks/{chunk-3W6CRM25.js → chunk-CBVANNKK.js} +553 -289
  7. package/dist/safe-bash/chunks/{chunk-R2WG64VB.js → chunk-JCN3FXLP.js} +40 -4
  8. package/dist/safe-bash/chunks/{chunk-WNB4XH45.js → chunk-OSUXMC43.js} +3 -3
  9. package/dist/safe-bash/chunks/{chunk-37Y7GZTK.js → chunk-RSAWYAEH.js} +2 -2
  10. package/dist/safe-bash/chunks/{pdf-renderer-DHQDZC6N.js → pdf-renderer-CMF3CSVU.js} +3 -3
  11. package/dist/safe-bash/chunks/{src-S52LORVD.js → src-MXIKQCIC.js} +5 -3
  12. package/dist/safe-bash/command-chunks/{chunk-IJHV6I6X.js → chunk-3DOHQQJR.js} +8 -6
  13. package/dist/safe-bash/command-chunks/{chunk-PUOJAS3O.js → chunk-H2FQA4OU.js} +39 -3
  14. package/dist/safe-bash/command-chunks/chunk-IDR3WWKI.js +46 -0
  15. package/dist/safe-bash/command-chunks/{chunk-XAZ3NTJ4.js → chunk-KBBI4CSU.js} +2 -2
  16. package/dist/safe-bash/command-chunks/{chunk-YY7HJMBG.js → chunk-KOM3FNCE.js} +1 -37
  17. package/dist/safe-bash/command-chunks/chunk-QQOAK7JQ.js +888 -0
  18. package/dist/safe-bash/command-chunks/{chunk-BE4AM2JW.js → chunk-UGX6MXDD.js} +5 -3
  19. package/dist/safe-bash/command-chunks/{chunk-CM4SVTIA.js → chunk-WI35236J.js} +1 -1
  20. package/dist/safe-bash/commands/ssconvert/index.d.ts +1 -2
  21. package/dist/safe-bash/commands/ssconvert/index.js +6 -260
  22. package/dist/safe-bash/core.browser.js +5 -207
  23. package/dist/safe-bash-command-csvkit/index.js +277 -49
  24. package/dist/safe-bash-command-ffmpeg/index.js +1741 -1717
  25. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  26. package/dist/safe-bash-command-pandoc/command.js +3 -3
  27. package/dist/safe-bash-command-pandoc/index.js +3 -3
  28. package/dist/safe-bash-command-pdfimages/index.js +39 -3
  29. package/dist/safe-bash-command-pdfinfo/index.js +39 -3
  30. package/dist/safe-bash-command-pdftk/index.js +39 -3
  31. package/dist/safe-bash-command-pdftoppm/index.js +39 -3
  32. package/dist/safe-bash-command-pdftotext/index.js +39 -3
  33. package/dist/safe-bash-command-qpdf/index.js +39 -3
  34. package/dist/safe-bash-command-sips/index.js +2 -2
  35. package/dist/safe-bash-command-soffice/index.js +5 -4
  36. package/dist/safe-bash-command-ssconvert/formats/csv.js +4 -3
  37. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +4 -2
  38. package/dist/safe-bash-command-ssconvert/formats/xls.js +10 -666
  39. package/dist/safe-bash-command-ssconvert/index.d.ts +1 -0
  40. package/dist/safe-bash-command-ssconvert/index.js +706 -392
  41. package/dist/safe-bash-command-ssconvert/sync.d.ts +7 -0
  42. package/dist/safe-bash-command-timeout/index.js +1 -1
  43. package/dist/safe-bash-command-wkhtmltopdf/index.js +39 -3
  44. package/dist/spreadsheet-format-csv/text-export.d.ts +14 -0
  45. package/dist/spreadsheet-format-csv/text-export.js +2 -2
  46. package/dist/spreadsheet-format-xls/biff-binary.d.ts +7 -2
  47. package/dist/spreadsheet-format-xls/biff-binary.js +10 -1
  48. package/dist/spreadsheet-format-xls/biff-strings.d.ts +2 -3
  49. package/dist/spreadsheet-format-xls/biff-strings.js +14 -2
  50. package/package.json +2 -3
  51. package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +8 -1
  52. package/dist/safe-bash/command-chunks/chunk-MPUNHXWI.js +0 -205
@@ -28,8 +28,8 @@ import {
28
28
  thresholdImage,
29
29
  tintImage,
30
30
  trimImage
31
- } from "../safe-bash/command-chunks/chunk-CM4SVTIA.js";
32
- import "../safe-bash/command-chunks/chunk-PUOJAS3O.js";
31
+ } from "../safe-bash/command-chunks/chunk-WI35236J.js";
32
+ import "../safe-bash/command-chunks/chunk-H2FQA4OU.js";
33
33
  import {
34
34
  init_buffer
35
35
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -2,11 +2,11 @@ import {
2
2
  createPandocCommand,
3
3
  createPandocCommands,
4
4
  pandocCommands
5
- } from "../safe-bash/command-chunks/chunk-XAZ3NTJ4.js";
5
+ } from "../safe-bash/command-chunks/chunk-KBBI4CSU.js";
6
6
  import "../safe-bash/command-chunks/chunk-MKQVQMXO.js";
7
7
  import "../safe-bash/command-chunks/chunk-RDV7UCYZ.js";
8
- import "../safe-bash/command-chunks/chunk-CM4SVTIA.js";
9
- import "../safe-bash/command-chunks/chunk-PUOJAS3O.js";
8
+ import "../safe-bash/command-chunks/chunk-WI35236J.js";
9
+ import "../safe-bash/command-chunks/chunk-H2FQA4OU.js";
10
10
  import "../safe-bash/command-chunks/chunk-Y2KHC6TZ.js";
11
11
  import "../safe-bash/command-chunks/chunk-YGYOVXTO.js";
12
12
  import "../safe-bash/command-chunks/chunk-I5GLTNVH.js";
@@ -21,11 +21,11 @@ import {
21
21
  readDocument,
22
22
  resolveConversionArgs,
23
23
  writeDocument
24
- } from "../safe-bash/command-chunks/chunk-XAZ3NTJ4.js";
24
+ } from "../safe-bash/command-chunks/chunk-KBBI4CSU.js";
25
25
  import "../safe-bash/command-chunks/chunk-MKQVQMXO.js";
26
26
  import "../safe-bash/command-chunks/chunk-RDV7UCYZ.js";
27
- import "../safe-bash/command-chunks/chunk-CM4SVTIA.js";
28
- import "../safe-bash/command-chunks/chunk-PUOJAS3O.js";
27
+ import "../safe-bash/command-chunks/chunk-WI35236J.js";
28
+ import "../safe-bash/command-chunks/chunk-H2FQA4OU.js";
29
29
  import {
30
30
  createLuaFilterCapability
31
31
  } from "../safe-bash/command-chunks/chunk-Y2KHC6TZ.js";
@@ -26665,17 +26665,22 @@ function parseTrueTypeFont(bytes) {
26665
26665
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26666
26666
  let format4Offset = 0;
26667
26667
  let format12Offset = 0;
26668
+ let format4IsSymbolic = false;
26669
+ let format12IsSymbolic = false;
26668
26670
  for (let i = 0; i < cmapNumTables; i++) {
26669
26671
  const rec = cmapOffset + 4 + i * 8;
26670
26672
  if (rec + 8 > bytes.byteLength) break;
26671
26673
  const platformID = readU16(view, rec);
26674
+ const encodingID = readU16(view, rec + 2);
26672
26675
  const subOffset = cmapOffset + readU32(view, rec + 4);
26673
26676
  if (subOffset + 4 > bytes.byteLength) continue;
26674
26677
  const fmt = readU16(view, subOffset);
26675
26678
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26676
26679
  format12Offset = subOffset;
26680
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26677
26681
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26678
26682
  format4Offset = subOffset;
26683
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26679
26684
  }
26680
26685
  }
26681
26686
  if (format12Offset > 0) {
@@ -26964,6 +26969,7 @@ function parseTrueTypeFont(bytes) {
26964
26969
  numGlyphs,
26965
26970
  isCff: renderCffGlyph !== void 0,
26966
26971
  hasCmap: cmap !== void 0,
26972
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
26967
26973
  glyphNames,
26968
26974
  getGlyphId(codePoint) {
26969
26975
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -34893,7 +34899,13 @@ function resolvePageFonts(doc, resourcesDict) {
34893
34899
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
34894
34900
  } else {
34895
34901
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
34896
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34902
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
34903
+ simpleToGid = /* @__PURE__ */ new Map();
34904
+ for (let code = 0; code < 256; code++) {
34905
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
34906
+ if (gid > 0) simpleToGid.set(code, gid);
34907
+ }
34908
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34897
34909
  simpleToGid = /* @__PURE__ */ new Map();
34898
34910
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
34899
34911
  for (let code = 0; code < 256; code++) {
@@ -38470,7 +38482,7 @@ var PdfPage = class {
38470
38482
  this.cachedContentAst = parseContentStream(bytes);
38471
38483
  this.isolatedInitialStream = false;
38472
38484
  const stm = cosStream(bytes, { compress });
38473
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38485
+ this.replaceContentStream(stm);
38474
38486
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38475
38487
  }
38476
38488
  getIsolatedContentAst() {
@@ -38487,9 +38499,33 @@ var PdfPage = class {
38487
38499
  this.cachedContentAst = [...nodes];
38488
38500
  const bytes = serializeContentAst(this.cachedContentAst);
38489
38501
  const streamObj = cosStream(bytes, { compress });
38490
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38502
+ this.replaceContentStream(streamObj);
38491
38503
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38492
38504
  }
38505
+ replaceContentStream(stream) {
38506
+ const contents = dictGet(this.pageDict, "Contents");
38507
+ if (contents?.kind === "ref") {
38508
+ let references = 0;
38509
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38510
+ const visited = /* @__PURE__ */ new Set();
38511
+ while (pending.length > 0 && references < 2) {
38512
+ const node = pending.pop();
38513
+ if (node.kind === "ref") {
38514
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38515
+ } else if (!visited.has(node)) {
38516
+ visited.add(node);
38517
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38518
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38519
+ else if (node.kind === "stream") pending.push(node.dict);
38520
+ }
38521
+ }
38522
+ if (references === 1) {
38523
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38524
+ return;
38525
+ }
38526
+ }
38527
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38528
+ }
38493
38529
  drawText(text, options) {
38494
38530
  const size = options.size ?? options.fontSize ?? 12;
38495
38531
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -26859,17 +26859,22 @@ function parseTrueTypeFont(bytes) {
26859
26859
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26860
26860
  let format4Offset = 0;
26861
26861
  let format12Offset = 0;
26862
+ let format4IsSymbolic = false;
26863
+ let format12IsSymbolic = false;
26862
26864
  for (let i = 0; i < cmapNumTables; i++) {
26863
26865
  const rec = cmapOffset + 4 + i * 8;
26864
26866
  if (rec + 8 > bytes.byteLength) break;
26865
26867
  const platformID = readU16(view, rec);
26868
+ const encodingID = readU16(view, rec + 2);
26866
26869
  const subOffset = cmapOffset + readU32(view, rec + 4);
26867
26870
  if (subOffset + 4 > bytes.byteLength) continue;
26868
26871
  const fmt = readU16(view, subOffset);
26869
26872
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26870
26873
  format12Offset = subOffset;
26874
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26871
26875
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26872
26876
  format4Offset = subOffset;
26877
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26873
26878
  }
26874
26879
  }
26875
26880
  if (format12Offset > 0) {
@@ -27158,6 +27163,7 @@ function parseTrueTypeFont(bytes) {
27158
27163
  numGlyphs,
27159
27164
  isCff: renderCffGlyph !== void 0,
27160
27165
  hasCmap: cmap !== void 0,
27166
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
27161
27167
  glyphNames,
27162
27168
  getGlyphId(codePoint) {
27163
27169
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -35087,7 +35093,13 @@ function resolvePageFonts(doc, resourcesDict) {
35087
35093
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
35088
35094
  } else {
35089
35095
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
35090
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
35096
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
35097
+ simpleToGid = /* @__PURE__ */ new Map();
35098
+ for (let code = 0; code < 256; code++) {
35099
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
35100
+ if (gid > 0) simpleToGid.set(code, gid);
35101
+ }
35102
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
35091
35103
  simpleToGid = /* @__PURE__ */ new Map();
35092
35104
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
35093
35105
  for (let code = 0; code < 256; code++) {
@@ -38664,7 +38676,7 @@ var PdfPage = class {
38664
38676
  this.cachedContentAst = parseContentStream(bytes);
38665
38677
  this.isolatedInitialStream = false;
38666
38678
  const stm = cosStream(bytes, { compress });
38667
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38679
+ this.replaceContentStream(stm);
38668
38680
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38669
38681
  }
38670
38682
  getIsolatedContentAst() {
@@ -38681,9 +38693,33 @@ var PdfPage = class {
38681
38693
  this.cachedContentAst = [...nodes];
38682
38694
  const bytes = serializeContentAst(this.cachedContentAst);
38683
38695
  const streamObj = cosStream(bytes, { compress });
38684
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38696
+ this.replaceContentStream(streamObj);
38685
38697
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38686
38698
  }
38699
+ replaceContentStream(stream) {
38700
+ const contents = dictGet(this.pageDict, "Contents");
38701
+ if (contents?.kind === "ref") {
38702
+ let references = 0;
38703
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38704
+ const visited = /* @__PURE__ */ new Set();
38705
+ while (pending.length > 0 && references < 2) {
38706
+ const node = pending.pop();
38707
+ if (node.kind === "ref") {
38708
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38709
+ } else if (!visited.has(node)) {
38710
+ visited.add(node);
38711
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38712
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38713
+ else if (node.kind === "stream") pending.push(node.dict);
38714
+ }
38715
+ }
38716
+ if (references === 1) {
38717
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38718
+ return;
38719
+ }
38720
+ }
38721
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38722
+ }
38687
38723
  drawText(text, options) {
38688
38724
  const size = options.size ?? options.fontSize ?? 12;
38689
38725
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -26665,17 +26665,22 @@ function parseTrueTypeFont(bytes) {
26665
26665
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26666
26666
  let format4Offset = 0;
26667
26667
  let format12Offset = 0;
26668
+ let format4IsSymbolic = false;
26669
+ let format12IsSymbolic = false;
26668
26670
  for (let i = 0; i < cmapNumTables; i++) {
26669
26671
  const rec = cmapOffset + 4 + i * 8;
26670
26672
  if (rec + 8 > bytes.byteLength) break;
26671
26673
  const platformID = readU16(view, rec);
26674
+ const encodingID = readU16(view, rec + 2);
26672
26675
  const subOffset = cmapOffset + readU32(view, rec + 4);
26673
26676
  if (subOffset + 4 > bytes.byteLength) continue;
26674
26677
  const fmt = readU16(view, subOffset);
26675
26678
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26676
26679
  format12Offset = subOffset;
26680
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26677
26681
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26678
26682
  format4Offset = subOffset;
26683
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26679
26684
  }
26680
26685
  }
26681
26686
  if (format12Offset > 0) {
@@ -26964,6 +26969,7 @@ function parseTrueTypeFont(bytes) {
26964
26969
  numGlyphs,
26965
26970
  isCff: renderCffGlyph !== void 0,
26966
26971
  hasCmap: cmap !== void 0,
26972
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
26967
26973
  glyphNames,
26968
26974
  getGlyphId(codePoint) {
26969
26975
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -34548,7 +34554,13 @@ function resolvePageFonts(doc, resourcesDict) {
34548
34554
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
34549
34555
  } else {
34550
34556
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
34551
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34557
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
34558
+ simpleToGid = /* @__PURE__ */ new Map();
34559
+ for (let code = 0; code < 256; code++) {
34560
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
34561
+ if (gid > 0) simpleToGid.set(code, gid);
34562
+ }
34563
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34552
34564
  simpleToGid = /* @__PURE__ */ new Map();
34553
34565
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
34554
34566
  for (let code = 0; code < 256; code++) {
@@ -38689,7 +38701,7 @@ var PdfPage = class {
38689
38701
  this.cachedContentAst = parseContentStream(bytes);
38690
38702
  this.isolatedInitialStream = false;
38691
38703
  const stm = cosStream(bytes, { compress });
38692
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38704
+ this.replaceContentStream(stm);
38693
38705
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38694
38706
  }
38695
38707
  getIsolatedContentAst() {
@@ -38706,9 +38718,33 @@ var PdfPage = class {
38706
38718
  this.cachedContentAst = [...nodes];
38707
38719
  const bytes = serializeContentAst(this.cachedContentAst);
38708
38720
  const streamObj = cosStream(bytes, { compress });
38709
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38721
+ this.replaceContentStream(streamObj);
38710
38722
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38711
38723
  }
38724
+ replaceContentStream(stream) {
38725
+ const contents = dictGet(this.pageDict, "Contents");
38726
+ if (contents?.kind === "ref") {
38727
+ let references = 0;
38728
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38729
+ const visited = /* @__PURE__ */ new Set();
38730
+ while (pending.length > 0 && references < 2) {
38731
+ const node = pending.pop();
38732
+ if (node.kind === "ref") {
38733
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38734
+ } else if (!visited.has(node)) {
38735
+ visited.add(node);
38736
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38737
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38738
+ else if (node.kind === "stream") pending.push(node.dict);
38739
+ }
38740
+ }
38741
+ if (references === 1) {
38742
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38743
+ return;
38744
+ }
38745
+ }
38746
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38747
+ }
38712
38748
  drawText(text, options) {
38713
38749
  const size = options.size ?? options.fontSize ?? 12;
38714
38750
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -26859,17 +26859,22 @@ function parseTrueTypeFont(bytes) {
26859
26859
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26860
26860
  let format4Offset = 0;
26861
26861
  let format12Offset = 0;
26862
+ let format4IsSymbolic = false;
26863
+ let format12IsSymbolic = false;
26862
26864
  for (let i = 0; i < cmapNumTables; i++) {
26863
26865
  const rec = cmapOffset + 4 + i * 8;
26864
26866
  if (rec + 8 > bytes.byteLength) break;
26865
26867
  const platformID = readU16(view, rec);
26868
+ const encodingID = readU16(view, rec + 2);
26866
26869
  const subOffset = cmapOffset + readU32(view, rec + 4);
26867
26870
  if (subOffset + 4 > bytes.byteLength) continue;
26868
26871
  const fmt = readU16(view, subOffset);
26869
26872
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26870
26873
  format12Offset = subOffset;
26874
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26871
26875
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26872
26876
  format4Offset = subOffset;
26877
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26873
26878
  }
26874
26879
  }
26875
26880
  if (format12Offset > 0) {
@@ -27158,6 +27163,7 @@ function parseTrueTypeFont(bytes) {
27158
27163
  numGlyphs,
27159
27164
  isCff: renderCffGlyph !== void 0,
27160
27165
  hasCmap: cmap !== void 0,
27166
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
27161
27167
  glyphNames,
27162
27168
  getGlyphId(codePoint) {
27163
27169
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -34742,7 +34748,13 @@ function resolvePageFonts(doc, resourcesDict) {
34742
34748
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
34743
34749
  } else {
34744
34750
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
34745
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34751
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
34752
+ simpleToGid = /* @__PURE__ */ new Map();
34753
+ for (let code = 0; code < 256; code++) {
34754
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
34755
+ if (gid > 0) simpleToGid.set(code, gid);
34756
+ }
34757
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34746
34758
  simpleToGid = /* @__PURE__ */ new Map();
34747
34759
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
34748
34760
  for (let code = 0; code < 256; code++) {
@@ -38319,7 +38331,7 @@ var PdfPage = class {
38319
38331
  this.cachedContentAst = parseContentStream(bytes);
38320
38332
  this.isolatedInitialStream = false;
38321
38333
  const stm = cosStream(bytes, { compress });
38322
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38334
+ this.replaceContentStream(stm);
38323
38335
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38324
38336
  }
38325
38337
  getIsolatedContentAst() {
@@ -38336,9 +38348,33 @@ var PdfPage = class {
38336
38348
  this.cachedContentAst = [...nodes];
38337
38349
  const bytes = serializeContentAst(this.cachedContentAst);
38338
38350
  const streamObj = cosStream(bytes, { compress });
38339
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38351
+ this.replaceContentStream(streamObj);
38340
38352
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38341
38353
  }
38354
+ replaceContentStream(stream) {
38355
+ const contents = dictGet(this.pageDict, "Contents");
38356
+ if (contents?.kind === "ref") {
38357
+ let references = 0;
38358
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38359
+ const visited = /* @__PURE__ */ new Set();
38360
+ while (pending.length > 0 && references < 2) {
38361
+ const node = pending.pop();
38362
+ if (node.kind === "ref") {
38363
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38364
+ } else if (!visited.has(node)) {
38365
+ visited.add(node);
38366
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38367
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38368
+ else if (node.kind === "stream") pending.push(node.dict);
38369
+ }
38370
+ }
38371
+ if (references === 1) {
38372
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38373
+ return;
38374
+ }
38375
+ }
38376
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38377
+ }
38342
38378
  drawText(text, options) {
38343
38379
  const size = options.size ?? options.fontSize ?? 12;
38344
38380
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -26665,17 +26665,22 @@ function parseTrueTypeFont(bytes) {
26665
26665
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26666
26666
  let format4Offset = 0;
26667
26667
  let format12Offset = 0;
26668
+ let format4IsSymbolic = false;
26669
+ let format12IsSymbolic = false;
26668
26670
  for (let i = 0; i < cmapNumTables; i++) {
26669
26671
  const rec = cmapOffset + 4 + i * 8;
26670
26672
  if (rec + 8 > bytes.byteLength) break;
26671
26673
  const platformID = readU16(view, rec);
26674
+ const encodingID = readU16(view, rec + 2);
26672
26675
  const subOffset = cmapOffset + readU32(view, rec + 4);
26673
26676
  if (subOffset + 4 > bytes.byteLength) continue;
26674
26677
  const fmt = readU16(view, subOffset);
26675
26678
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26676
26679
  format12Offset = subOffset;
26680
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26677
26681
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26678
26682
  format4Offset = subOffset;
26683
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26679
26684
  }
26680
26685
  }
26681
26686
  if (format12Offset > 0) {
@@ -26964,6 +26969,7 @@ function parseTrueTypeFont(bytes) {
26964
26969
  numGlyphs,
26965
26970
  isCff: renderCffGlyph !== void 0,
26966
26971
  hasCmap: cmap !== void 0,
26972
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
26967
26973
  glyphNames,
26968
26974
  getGlyphId(codePoint) {
26969
26975
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -34893,7 +34899,13 @@ function resolvePageFonts(doc, resourcesDict) {
34893
34899
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
34894
34900
  } else {
34895
34901
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
34896
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34902
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
34903
+ simpleToGid = /* @__PURE__ */ new Map();
34904
+ for (let code = 0; code < 256; code++) {
34905
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
34906
+ if (gid > 0) simpleToGid.set(code, gid);
34907
+ }
34908
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34897
34909
  simpleToGid = /* @__PURE__ */ new Map();
34898
34910
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
34899
34911
  for (let code = 0; code < 256; code++) {
@@ -38470,7 +38482,7 @@ var PdfPage = class {
38470
38482
  this.cachedContentAst = parseContentStream(bytes);
38471
38483
  this.isolatedInitialStream = false;
38472
38484
  const stm = cosStream(bytes, { compress });
38473
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38485
+ this.replaceContentStream(stm);
38474
38486
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38475
38487
  }
38476
38488
  getIsolatedContentAst() {
@@ -38487,9 +38499,33 @@ var PdfPage = class {
38487
38499
  this.cachedContentAst = [...nodes];
38488
38500
  const bytes = serializeContentAst(this.cachedContentAst);
38489
38501
  const streamObj = cosStream(bytes, { compress });
38490
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38502
+ this.replaceContentStream(streamObj);
38491
38503
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38492
38504
  }
38505
+ replaceContentStream(stream) {
38506
+ const contents = dictGet(this.pageDict, "Contents");
38507
+ if (contents?.kind === "ref") {
38508
+ let references = 0;
38509
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38510
+ const visited = /* @__PURE__ */ new Set();
38511
+ while (pending.length > 0 && references < 2) {
38512
+ const node = pending.pop();
38513
+ if (node.kind === "ref") {
38514
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38515
+ } else if (!visited.has(node)) {
38516
+ visited.add(node);
38517
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38518
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38519
+ else if (node.kind === "stream") pending.push(node.dict);
38520
+ }
38521
+ }
38522
+ if (references === 1) {
38523
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38524
+ return;
38525
+ }
38526
+ }
38527
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38528
+ }
38493
38529
  drawText(text, options) {
38494
38530
  const size = options.size ?? options.fontSize ?? 12;
38495
38531
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -26665,17 +26665,22 @@ function parseTrueTypeFont(bytes) {
26665
26665
  const cmapNumTables = cmap ? readU16(view, cmapOffset + 2) : 0;
26666
26666
  let format4Offset = 0;
26667
26667
  let format12Offset = 0;
26668
+ let format4IsSymbolic = false;
26669
+ let format12IsSymbolic = false;
26668
26670
  for (let i = 0; i < cmapNumTables; i++) {
26669
26671
  const rec = cmapOffset + 4 + i * 8;
26670
26672
  if (rec + 8 > bytes.byteLength) break;
26671
26673
  const platformID = readU16(view, rec);
26674
+ const encodingID = readU16(view, rec + 2);
26672
26675
  const subOffset = cmapOffset + readU32(view, rec + 4);
26673
26676
  if (subOffset + 4 > bytes.byteLength) continue;
26674
26677
  const fmt = readU16(view, subOffset);
26675
26678
  if (fmt === 12 && (platformID === 3 || platformID === 0)) {
26676
26679
  format12Offset = subOffset;
26680
+ format12IsSymbolic = platformID === 3 && encodingID === 0;
26677
26681
  } else if (fmt === 4 && (platformID === 3 || platformID === 0)) {
26678
26682
  format4Offset = subOffset;
26683
+ format4IsSymbolic = platformID === 3 && encodingID === 0;
26679
26684
  }
26680
26685
  }
26681
26686
  if (format12Offset > 0) {
@@ -26964,6 +26969,7 @@ function parseTrueTypeFont(bytes) {
26964
26969
  numGlyphs,
26965
26970
  isCff: renderCffGlyph !== void 0,
26966
26971
  hasCmap: cmap !== void 0,
26972
+ isSymbolicCmap: format12Offset > 0 ? format12IsSymbolic : format4IsSymbolic,
26967
26973
  glyphNames,
26968
26974
  getGlyphId(codePoint) {
26969
26975
  return codePointToGlyph.get(codePoint) ?? 0;
@@ -34548,7 +34554,13 @@ function resolvePageFonts(doc, resourcesDict) {
34548
34554
  embeddedCff = parseEmbeddedCffFont(doc.decodeStream(program), baseEncoding?.kind === "name" ? baseEncoding.decoded : void 0, glyphNames);
34549
34555
  } else {
34550
34556
  embeddedTrueType = parseTrueTypeFont(doc.decodeStream(program));
34551
- if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34557
+ if (subtype !== "Type0" && embeddedTrueType.isSymbolicCmap) {
34558
+ simpleToGid = /* @__PURE__ */ new Map();
34559
+ for (let code = 0; code < 256; code++) {
34560
+ const gid = embeddedTrueType.getGlyphId(61440 + code) || embeddedTrueType.getGlyphId(code);
34561
+ if (gid > 0) simpleToGid.set(code, gid);
34562
+ }
34563
+ } else if (subtype !== "Type0" && !embeddedTrueType.hasCmap) {
34552
34564
  simpleToGid = /* @__PURE__ */ new Map();
34553
34565
  const encoding = baseEncoding?.kind === "name" ? getEncoding(baseEncoding.decoded) : void 0;
34554
34566
  for (let code = 0; code < 256; code++) {
@@ -38235,7 +38247,7 @@ var PdfPage = class {
38235
38247
  this.cachedContentAst = parseContentStream(bytes);
38236
38248
  this.isolatedInitialStream = false;
38237
38249
  const stm = cosStream(bytes, { compress });
38238
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stm));
38250
+ this.replaceContentStream(stm);
38239
38251
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38240
38252
  }
38241
38253
  getIsolatedContentAst() {
@@ -38252,9 +38264,33 @@ var PdfPage = class {
38252
38264
  this.cachedContentAst = [...nodes];
38253
38265
  const bytes = serializeContentAst(this.cachedContentAst);
38254
38266
  const streamObj = cosStream(bytes, { compress });
38255
- dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(streamObj));
38267
+ this.replaceContentStream(streamObj);
38256
38268
  this.cachedContentsNode = dictGet(this.pageDict, "Contents");
38257
38269
  }
38270
+ replaceContentStream(stream) {
38271
+ const contents = dictGet(this.pageDict, "Contents");
38272
+ if (contents?.kind === "ref") {
38273
+ let references = 0;
38274
+ const pending = [...this.cosDoc.objects.values()].map((object) => object.value);
38275
+ const visited = /* @__PURE__ */ new Set();
38276
+ while (pending.length > 0 && references < 2) {
38277
+ const node = pending.pop();
38278
+ if (node.kind === "ref") {
38279
+ if (node.objectNumber === contents.objectNumber && node.generationNumber === contents.generationNumber) references++;
38280
+ } else if (!visited.has(node)) {
38281
+ visited.add(node);
38282
+ if (node.kind === "array") for (const item of node.items) pending.push(item);
38283
+ else if (node.kind === "dict") for (const entry of node.entries) pending.push(entry.value);
38284
+ else if (node.kind === "stream") pending.push(node.dict);
38285
+ }
38286
+ }
38287
+ if (references === 1) {
38288
+ this.cosDoc.setObject(contents.objectNumber, stream, contents.generationNumber);
38289
+ return;
38290
+ }
38291
+ }
38292
+ dictSet(this.pageDict, "Contents", this.cosDoc.allocateObject(stream));
38293
+ }
38258
38294
  drawText(text, options) {
38259
38295
  const size = options.size ?? options.fontSize ?? 12;
38260
38296
  const color = options.color ?? { r: 0, g: 0, b: 0 };
@@ -11,8 +11,8 @@ import {
11
11
  readImageMetadata,
12
12
  resizeImage,
13
13
  rotateImage
14
- } from "../safe-bash/command-chunks/chunk-CM4SVTIA.js";
15
- import "../safe-bash/command-chunks/chunk-PUOJAS3O.js";
14
+ } from "../safe-bash/command-chunks/chunk-WI35236J.js";
15
+ import "../safe-bash/command-chunks/chunk-H2FQA4OU.js";
16
16
  import {
17
17
  init_buffer
18
18
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -6,9 +6,9 @@ import {
6
6
  } from "../safe-bash/command-chunks/chunk-DKQ5REXF.js";
7
7
  import {
8
8
  csvFormat
9
- } from "../safe-bash/command-chunks/chunk-IJHV6I6X.js";
10
- import "../safe-bash/command-chunks/chunk-BE4AM2JW.js";
11
- import "../safe-bash/command-chunks/chunk-YY7HJMBG.js";
9
+ } from "../safe-bash/command-chunks/chunk-3DOHQQJR.js";
10
+ import "../safe-bash/command-chunks/chunk-UGX6MXDD.js";
11
+ import "../safe-bash/command-chunks/chunk-IDR3WWKI.js";
12
12
  import "../safe-bash/command-chunks/chunk-6AIOGLZO.js";
13
13
  import "../safe-bash/command-chunks/chunk-JRNLDPLI.js";
14
14
  import {
@@ -18,6 +18,7 @@ import "../safe-bash/command-chunks/chunk-S4J6MSLY.js";
18
18
  import "../safe-bash/command-chunks/chunk-REYTQLLB.js";
19
19
  import "../safe-bash/command-chunks/chunk-5VSGEE6J.js";
20
20
  import "../safe-bash/command-chunks/chunk-SG3ZDZCX.js";
21
+ import "../safe-bash/command-chunks/chunk-KOM3FNCE.js";
21
22
  import "../safe-bash/command-chunks/chunk-CT3FB722.js";
22
23
  import "../safe-bash/command-chunks/chunk-6X2OX6IJ.js";
23
24
  import "../safe-bash/command-chunks/chunk-WOPU2VWF.js";
@@ -30,7 +31,7 @@ import {
30
31
  PdfDocument,
31
32
  decodeFlate,
32
33
  rgb
33
- } from "../safe-bash/command-chunks/chunk-PUOJAS3O.js";
34
+ } from "../safe-bash/command-chunks/chunk-H2FQA4OU.js";
34
35
  import {
35
36
  init_buffer
36
37
  } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  csvFormat
3
- } from "../../safe-bash/command-chunks/chunk-IJHV6I6X.js";
4
- import "../../safe-bash/command-chunks/chunk-BE4AM2JW.js";
5
- import "../../safe-bash/command-chunks/chunk-YY7HJMBG.js";
3
+ } from "../../safe-bash/command-chunks/chunk-3DOHQQJR.js";
4
+ import "../../safe-bash/command-chunks/chunk-UGX6MXDD.js";
5
+ import "../../safe-bash/command-chunks/chunk-IDR3WWKI.js";
6
6
  import "../../safe-bash/command-chunks/chunk-6AIOGLZO.js";
7
7
  import "../../safe-bash/command-chunks/chunk-JRNLDPLI.js";
8
8
  import "../../safe-bash/command-chunks/chunk-S4J6MSLY.js";
9
9
  import "../../safe-bash/command-chunks/chunk-REYTQLLB.js";
10
+ import "../../safe-bash/command-chunks/chunk-KOM3FNCE.js";
10
11
  import "../../safe-bash/command-chunks/chunk-A6NFLWZI.js";
11
12
  import "../../safe-bash/command-chunks/chunk-4HQ7WYSI.js";
12
13
  import "../../safe-bash/command-chunks/chunk-F5MORDSU.js";
@@ -1,7 +1,9 @@
1
1
  import {
2
- encodingName,
2
+ encodingName
3
+ } from "../../safe-bash/command-chunks/chunk-IDR3WWKI.js";
4
+ import {
3
5
  singleByteTables
4
- } from "../../safe-bash/command-chunks/chunk-YY7HJMBG.js";
6
+ } from "../../safe-bash/command-chunks/chunk-KOM3FNCE.js";
5
7
  import {
6
8
  SsconvertError,
7
9
  excelGrammar,