@taloswork/ose-shared 0.1.11 → 0.1.13

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 (159) hide show
  1. package/package.json +3 -3
  2. package/skills/document/SKILL.md +135 -219
  3. package/skills/document/art-directions/base.css +27 -2
  4. package/skills/document/art-directions/cinematic-depth.css +3 -1
  5. package/skills/document/art-directions/collage-paper.css +5 -1
  6. package/skills/document/art-directions/editorial-cut.css +5 -1
  7. package/skills/document/art-directions/geometric-pop.css +6 -0
  8. package/skills/document/art-directions/gradient-mesh.css +5 -1
  9. package/skills/document/art-directions/illustrated-doodle.css +5 -0
  10. package/skills/document/art-directions/luxury-ornament.css +4 -1
  11. package/skills/document/art-directions/maximalist-blocks.css +6 -0
  12. package/skills/document/art-directions/technical-grid.css +4 -0
  13. package/skills/document/assets/fonts/fonts.json +2 -2
  14. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
  15. package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
  16. package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
  17. package/skills/document/assets/pdf-fonts/README.md +35 -0
  18. package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
  19. package/skills/document/assets/tessdata/README.md +21 -0
  20. package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
  21. package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
  22. package/skills/document/bin/deck-build.cjs +12563 -83
  23. package/skills/document/bin/deck-chart.cjs +771 -0
  24. package/skills/document/bin/deck-plan.cjs +12414 -0
  25. package/skills/document/bin/deck-qa.cjs +1075 -266
  26. package/skills/document/bin/deck-scenario.cjs +1363 -0
  27. package/skills/document/bin/deck-styles.cjs +1604 -0
  28. package/skills/document/bin/doc-convert.cjs +308 -292
  29. package/skills/document/bin/doc-fill.cjs +73264 -192
  30. package/skills/document/bin/doc-gen.cjs +2491 -312
  31. package/skills/document/bin/doc-run.cjs +162 -24
  32. package/skills/document/bin/doc-scan.cjs +13 -0
  33. package/skills/document/bin/doc-text.cjs +13 -0
  34. package/skills/document/bin/doc-validate.cjs +838 -68
  35. package/skills/document/bin/doc-xml.cjs +9 -5
  36. package/skills/document/bin/docx-annotate.cjs +95 -19
  37. package/skills/document/bin/docx-defaults.cjs +9907 -0
  38. package/skills/document/bin/fontkit.cjs +1 -0
  39. package/skills/document/bin/html2pptx.cjs +36622 -31394
  40. package/skills/document/bin/ocr-worker.cjs +1 -0
  41. package/skills/document/bin/ocr.cjs +131 -40
  42. package/skills/document/bin/pdf-form.cjs +682 -177
  43. package/skills/document/bin/pdf-images.cjs +13 -0
  44. package/skills/document/bin/pdf-ops.cjs +642 -199
  45. package/skills/document/bin/pdf-render.cjs +19 -3
  46. package/skills/document/bin/pdf-tables.cjs +13 -0
  47. package/skills/document/bin/pptx-clone.cjs +3 -3
  48. package/skills/document/bin/pptx-notes.cjs +10038 -0
  49. package/skills/document/bin/pptx-slide.cjs +3 -3
  50. package/skills/document/bin/pptx-tokenize.cjs +19 -4
  51. package/skills/document/bin/template-skin.cjs +10910 -0
  52. package/skills/document/bin/xlsx-query.cjs +192 -61
  53. package/skills/document/bin-reference.md +61 -33
  54. package/skills/document/catalog.json +33 -32
  55. package/skills/document/content-pipeline.md +179 -257
  56. package/skills/document/deck-design.md +378 -638
  57. package/skills/document/generated-visuals.md +99 -0
  58. package/skills/document/layouts/MAINTAINERS.md +33 -0
  59. package/skills/document/layouts/README.md +49 -36
  60. package/skills/document/layouts/big-stat.tpl +1 -1
  61. package/skills/document/layouts/capacity.json +1 -0
  62. package/skills/document/layouts/cards-3.tpl +1 -1
  63. package/skills/document/layouts/chart-full.tpl +1 -1
  64. package/skills/document/layouts/chart-kpi.tpl +1 -1
  65. package/skills/document/layouts/comparison.tpl +1 -1
  66. package/skills/document/layouts/data-table.tpl +1 -1
  67. package/skills/document/layouts/funnel.tpl +1 -1
  68. package/skills/document/layouts/gantt.tpl +1 -1
  69. package/skills/document/layouts/hub-flow.tpl +4 -0
  70. package/skills/document/layouts/icon-row.tpl +1 -1
  71. package/skills/document/layouts/image-grid.tpl +1 -1
  72. package/skills/document/layouts/matrix-2x2.tpl +1 -1
  73. package/skills/document/layouts/mock-qa.tpl +4 -0
  74. package/skills/document/layouts/profiles.json +2 -2
  75. package/skills/document/layouts/pyramid.tpl +1 -1
  76. package/skills/document/layouts/radar.tpl +1 -1
  77. package/skills/document/layouts/ring-progress.tpl +1 -1
  78. package/skills/document/layouts/slots.json +1 -1
  79. package/skills/document/layouts/steps-vertical.tpl +1 -1
  80. package/skills/document/layouts/steps.tpl +1 -1
  81. package/skills/document/layouts/three-kpi.tpl +1 -1
  82. package/skills/document/layouts/timeline.tpl +1 -1
  83. package/skills/document/layouts/toc-panel.tpl +2 -2
  84. package/skills/document/layouts/two-kpi.tpl +2 -2
  85. package/skills/document/layouts/versus.tpl +1 -1
  86. package/skills/document/motion/README.md +3 -2
  87. package/skills/document/office.md +3 -3
  88. package/skills/document/packs/README.md +1 -1
  89. package/skills/document/packs/board-brief/backdrop.html +2 -0
  90. package/skills/document/packs/board-brief/pack.css +2 -1
  91. package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
  92. package/skills/document/packs/mckinsey-photo/pack.css +2 -1
  93. package/skills/document/packs/press-room/backdrop.html +2 -0
  94. package/skills/document/packs/press-room/pack.css +2 -1
  95. package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
  96. package/skills/document/packs/prismatic-3d/pack.css +4 -1
  97. package/skills/document/pdf.md +60 -43
  98. package/skills/document/rewrite.md +257 -309
  99. package/skills/document/scenarios.json +1307 -0
  100. package/skills/document/scenarios.schema.json +104 -0
  101. package/skills/document/styles/README.md +15 -25
  102. package/skills/document/styles/_backdrops/rimlight.html +3 -2
  103. package/skills/document/styles/_contract-defaults.css +31 -2
  104. package/skills/document/styles/_samples/_groups/biz-premium.webp +0 -0
  105. package/skills/document/styles/_samples/mckinsey.webp +0 -0
  106. package/skills/document/styles/anthropic/skin.css +6 -3
  107. package/skills/document/styles/apple/skin.css +4 -3
  108. package/skills/document/styles/bistro-warm/backdrop.html +2 -0
  109. package/skills/document/styles/bistro-warm/skin.css +4 -1
  110. package/skills/document/styles/black-gold/skin.css +6 -5
  111. package/skills/document/styles/bold-clash/backdrop.html +2 -0
  112. package/skills/document/styles/bold-clash/skin.css +2 -1
  113. package/skills/document/styles/branding/skin.css +4 -4
  114. package/skills/document/styles/campus-teal/backdrop.html +2 -0
  115. package/skills/document/styles/campus-teal/skin.css +2 -1
  116. package/skills/document/styles/cinereel/skin.css +7 -3
  117. package/skills/document/styles/clinic-care/backdrop.html +2 -0
  118. package/skills/document/styles/clinic-care/skin.css +2 -1
  119. package/skills/document/styles/cool/skin.css +6 -5
  120. package/skills/document/styles/dark-glass/backdrop.html +2 -0
  121. package/skills/document/styles/dark-glass/skin.css +2 -1
  122. package/skills/document/styles/gov-brief/backdrop.html +2 -0
  123. package/skills/document/styles/gov-brief/skin.css +2 -1
  124. package/skills/document/styles/grid-tech/backdrop.html +2 -0
  125. package/skills/document/styles/grid-tech/skin.css +2 -1
  126. package/skills/document/styles/hand-drawn/skin.css +3 -3
  127. package/skills/document/styles/ivory-gold/skin.css +7 -6
  128. package/skills/document/styles/legal-slate/backdrop.html +2 -0
  129. package/skills/document/styles/legal-slate/skin.css +2 -1
  130. package/skills/document/styles/magazine-ink/skin.css +4 -3
  131. package/skills/document/styles/mckinsey/backdrop.html +7 -5
  132. package/skills/document/styles/mckinsey/skin.css +2 -1
  133. package/skills/document/styles/memphis/backdrop.html +2 -0
  134. package/skills/document/styles/memphis/skin.css +2 -1
  135. package/skills/document/styles/mono/skin.css +6 -2
  136. package/skills/document/styles/neon-cyber/backdrop.html +2 -0
  137. package/skills/document/styles/neon-cyber/skin.css +2 -1
  138. package/skills/document/styles/olive-gold/skin.css +7 -6
  139. package/skills/document/styles/organic-earth/backdrop.html +2 -0
  140. package/skills/document/styles/organic-earth/skin.css +2 -1
  141. package/skills/document/styles/pastel-saas/backdrop.html +2 -0
  142. package/skills/document/styles/pastel-saas/skin.css +2 -1
  143. package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
  144. package/skills/document/styles/portfolio-noir/skin.css +2 -1
  145. package/skills/document/styles/retro-press/backdrop.html +2 -0
  146. package/skills/document/styles/retro-press/skin.css +2 -1
  147. package/skills/document/styles/sport-arena/backdrop.html +2 -0
  148. package/skills/document/styles/sport-arena/skin.css +4 -1
  149. package/skills/document/styles/swiss-grid/skin.css +10 -5
  150. package/skills/document/styles/wedding-blush/backdrop.html +2 -0
  151. package/skills/document/styles/wedding-blush/skin.css +4 -1
  152. package/skills/document/theme-system.md +85 -77
  153. package/skills/document/themes/README.md +7 -5
  154. package/skills/document/vision.md +8 -5
  155. package/skills/document/xlsx.md +15 -25
  156. package/skills/grill-me/SKILL.md +6 -0
  157. package/skills/grill-me/agents/openai.yaml +5 -0
  158. package/skills/grilling/SKILL.md +28 -0
  159. package/skills/grilling/agents/openai.yaml +3 -0
@@ -743,31 +743,31 @@ var require_unicode = __commonJS({
743
743
  if (byteOrderMark)
744
744
  encoded.push(239, 187, 191);
745
745
  for (var idx = 0, len = input.length; idx < len; ) {
746
- var codePoint = input.codePointAt(idx);
747
- if (codePoint < 128) {
748
- var byte1 = codePoint & 127;
746
+ var codePoint2 = input.codePointAt(idx);
747
+ if (codePoint2 < 128) {
748
+ var byte1 = codePoint2 & 127;
749
749
  encoded.push(byte1);
750
750
  idx += 1;
751
- } else if (codePoint < 2048) {
752
- var byte1 = codePoint >> 6 & 31 | 192;
753
- var byte2 = codePoint & 63 | 128;
751
+ } else if (codePoint2 < 2048) {
752
+ var byte1 = codePoint2 >> 6 & 31 | 192;
753
+ var byte2 = codePoint2 & 63 | 128;
754
754
  encoded.push(byte1, byte2);
755
755
  idx += 1;
756
- } else if (codePoint < 65536) {
757
- var byte1 = codePoint >> 12 & 15 | 224;
758
- var byte2 = codePoint >> 6 & 63 | 128;
759
- var byte3 = codePoint & 63 | 128;
756
+ } else if (codePoint2 < 65536) {
757
+ var byte1 = codePoint2 >> 12 & 15 | 224;
758
+ var byte2 = codePoint2 >> 6 & 63 | 128;
759
+ var byte3 = codePoint2 & 63 | 128;
760
760
  encoded.push(byte1, byte2, byte3);
761
761
  idx += 1;
762
- } else if (codePoint < 1114112) {
763
- var byte1 = codePoint >> 18 & 7 | 240;
764
- var byte2 = codePoint >> 12 & 63 | 128;
765
- var byte3 = codePoint >> 6 & 63 | 128;
766
- var byte4 = codePoint >> 0 & 63 | 128;
762
+ } else if (codePoint2 < 1114112) {
763
+ var byte1 = codePoint2 >> 18 & 7 | 240;
764
+ var byte2 = codePoint2 >> 12 & 63 | 128;
765
+ var byte3 = codePoint2 >> 6 & 63 | 128;
766
+ var byte4 = codePoint2 >> 0 & 63 | 128;
767
767
  encoded.push(byte1, byte2, byte3, byte4);
768
768
  idx += 2;
769
769
  } else
770
- throw new Error("Invalid code point: 0x" + strings_1.toHexString(codePoint));
770
+ throw new Error("Invalid code point: 0x" + strings_1.toHexString(codePoint2));
771
771
  }
772
772
  return new Uint8Array(encoded);
773
773
  };
@@ -779,29 +779,29 @@ var require_unicode = __commonJS({
779
779
  if (byteOrderMark)
780
780
  encoded.push(65279);
781
781
  for (var idx = 0, len = input.length; idx < len; ) {
782
- var codePoint = input.codePointAt(idx);
783
- if (codePoint < 65536) {
784
- encoded.push(codePoint);
782
+ var codePoint2 = input.codePointAt(idx);
783
+ if (codePoint2 < 65536) {
784
+ encoded.push(codePoint2);
785
785
  idx += 1;
786
- } else if (codePoint < 1114112) {
787
- encoded.push(exports2.highSurrogate(codePoint), exports2.lowSurrogate(codePoint));
786
+ } else if (codePoint2 < 1114112) {
787
+ encoded.push(exports2.highSurrogate(codePoint2), exports2.lowSurrogate(codePoint2));
788
788
  idx += 2;
789
789
  } else
790
- throw new Error("Invalid code point: 0x" + strings_1.toHexString(codePoint));
790
+ throw new Error("Invalid code point: 0x" + strings_1.toHexString(codePoint2));
791
791
  }
792
792
  return new Uint16Array(encoded);
793
793
  };
794
- exports2.isWithinBMP = function(codePoint) {
795
- return codePoint >= 0 && codePoint <= 65535;
794
+ exports2.isWithinBMP = function(codePoint2) {
795
+ return codePoint2 >= 0 && codePoint2 <= 65535;
796
796
  };
797
- exports2.hasSurrogates = function(codePoint) {
798
- return codePoint >= 65536 && codePoint <= 1114111;
797
+ exports2.hasSurrogates = function(codePoint2) {
798
+ return codePoint2 >= 65536 && codePoint2 <= 1114111;
799
799
  };
800
- exports2.highSurrogate = function(codePoint) {
801
- return Math.floor((codePoint - 65536) / 1024) + 55296;
800
+ exports2.highSurrogate = function(codePoint2) {
801
+ return Math.floor((codePoint2 - 65536) / 1024) + 55296;
802
802
  };
803
- exports2.lowSurrogate = function(codePoint) {
804
- return (codePoint - 65536) % 1024 + 56320;
803
+ exports2.lowSurrogate = function(codePoint2) {
804
+ return (codePoint2 - 65536) % 1024 + 56320;
805
805
  };
806
806
  var ByteOrder;
807
807
  (function(ByteOrder2) {
@@ -842,11 +842,11 @@ var require_unicode = __commonJS({
842
842
  codePoints.push(REPLACEMENT);
843
843
  return String.fromCodePoint.apply(String, codePoints);
844
844
  };
845
- var isHighSurrogate = function(codePoint) {
846
- return codePoint >= 55296 && codePoint <= 56319;
845
+ var isHighSurrogate = function(codePoint2) {
846
+ return codePoint2 >= 55296 && codePoint2 <= 56319;
847
847
  };
848
- var isLowSurrogate = function(codePoint) {
849
- return codePoint >= 56320 && codePoint <= 57343;
848
+ var isLowSurrogate = function(codePoint2) {
849
+ return codePoint2 >= 56320 && codePoint2 <= 57343;
850
850
  };
851
851
  var decodeValues = function(first, second, byteOrder) {
852
852
  if (byteOrder === ByteOrder.LittleEndian)
@@ -5427,14 +5427,14 @@ var require_Encoding = __commonJS({
5427
5427
  /* @__PURE__ */ (function() {
5428
5428
  function Encoding2(name, unicodeMappings) {
5429
5429
  var _this = this;
5430
- this.canEncodeUnicodeCodePoint = function(codePoint) {
5431
- return codePoint in _this.unicodeMappings;
5430
+ this.canEncodeUnicodeCodePoint = function(codePoint2) {
5431
+ return codePoint2 in _this.unicodeMappings;
5432
5432
  };
5433
- this.encodeUnicodeCodePoint = function(codePoint) {
5434
- var mapped = _this.unicodeMappings[codePoint];
5433
+ this.encodeUnicodeCodePoint = function(codePoint2) {
5434
+ var mapped = _this.unicodeMappings[codePoint2];
5435
5435
  if (!mapped) {
5436
- var str = String.fromCharCode(codePoint);
5437
- var hexCode = "0x" + utils_1.padStart(codePoint.toString(16), 4, "0");
5436
+ var str = String.fromCharCode(codePoint2);
5437
+ var hexCode = "0x" + utils_1.padStart(codePoint2.toString(16), 4, "0");
5438
5438
  var msg = _this.name + ' cannot encode "' + str + '" (' + hexCode + ")";
5439
5439
  throw new Error(msg);
5440
5440
  }
@@ -8864,16 +8864,16 @@ var require_StandardFontEmbedder = __commonJS({
8864
8864
  var standard_fonts_1 = require_lib();
8865
8865
  var PDFHexString_1 = tslib_1.__importDefault(require_PDFHexString());
8866
8866
  var utils_1 = require_utils2();
8867
- var StandardFontEmbedder = (
8867
+ var StandardFontEmbedder2 = (
8868
8868
  /** @class */
8869
8869
  (function() {
8870
- function StandardFontEmbedder2(fontName, customName) {
8870
+ function StandardFontEmbedder3(fontName, customName) {
8871
8871
  this.encoding = fontName === standard_fonts_1.FontNames.ZapfDingbats ? standard_fonts_1.Encodings.ZapfDingbats : fontName === standard_fonts_1.FontNames.Symbol ? standard_fonts_1.Encodings.Symbol : standard_fonts_1.Encodings.WinAnsi;
8872
8872
  this.font = standard_fonts_1.Font.load(fontName);
8873
8873
  this.fontName = this.font.FontName;
8874
8874
  this.customName = customName;
8875
8875
  }
8876
- StandardFontEmbedder2.prototype.encodeText = function(text) {
8876
+ StandardFontEmbedder3.prototype.encodeText = function(text) {
8877
8877
  var glyphs = this.encodeTextAsGlyphs(text);
8878
8878
  var hexCodes = new Array(glyphs.length);
8879
8879
  for (var idx = 0, len = glyphs.length; idx < len; idx++) {
@@ -8881,7 +8881,7 @@ var require_StandardFontEmbedder = __commonJS({
8881
8881
  }
8882
8882
  return PDFHexString_1.default.of(hexCodes.join(""));
8883
8883
  };
8884
- StandardFontEmbedder2.prototype.widthOfTextAtSize = function(text, size) {
8884
+ StandardFontEmbedder3.prototype.widthOfTextAtSize = function(text, size) {
8885
8885
  var glyphs = this.encodeTextAsGlyphs(text);
8886
8886
  var totalWidth = 0;
8887
8887
  for (var idx = 0, len = glyphs.length; idx < len; idx++) {
@@ -8893,7 +8893,7 @@ var require_StandardFontEmbedder = __commonJS({
8893
8893
  var scale = size / 1e3;
8894
8894
  return totalWidth * scale;
8895
8895
  };
8896
- StandardFontEmbedder2.prototype.heightOfFontAtSize = function(size, options) {
8896
+ StandardFontEmbedder3.prototype.heightOfFontAtSize = function(size, options) {
8897
8897
  if (options === void 0) {
8898
8898
  options = {};
8899
8899
  }
@@ -8906,13 +8906,13 @@ var require_StandardFontEmbedder = __commonJS({
8906
8906
  height += Descender || 0;
8907
8907
  return height / 1e3 * size;
8908
8908
  };
8909
- StandardFontEmbedder2.prototype.sizeOfFontAtHeight = function(height) {
8909
+ StandardFontEmbedder3.prototype.sizeOfFontAtHeight = function(height) {
8910
8910
  var _a = this.font, Ascender = _a.Ascender, Descender = _a.Descender, FontBBox = _a.FontBBox;
8911
8911
  var yTop = Ascender || FontBBox[3];
8912
8912
  var yBottom = Descender || FontBBox[1];
8913
8913
  return 1e3 * height / (yTop - yBottom);
8914
8914
  };
8915
- StandardFontEmbedder2.prototype.embedIntoContext = function(context, ref) {
8915
+ StandardFontEmbedder3.prototype.embedIntoContext = function(context, ref) {
8916
8916
  var fontDict = context.obj({
8917
8917
  Type: "Font",
8918
8918
  Subtype: "Type1",
@@ -8926,25 +8926,25 @@ var require_StandardFontEmbedder = __commonJS({
8926
8926
  return context.register(fontDict);
8927
8927
  }
8928
8928
  };
8929
- StandardFontEmbedder2.prototype.widthOfGlyph = function(glyphName) {
8929
+ StandardFontEmbedder3.prototype.widthOfGlyph = function(glyphName) {
8930
8930
  return this.font.getWidthOfGlyph(glyphName) || 250;
8931
8931
  };
8932
- StandardFontEmbedder2.prototype.encodeTextAsGlyphs = function(text) {
8932
+ StandardFontEmbedder3.prototype.encodeTextAsGlyphs = function(text) {
8933
8933
  var codePoints = Array.from(text);
8934
8934
  var glyphs = new Array(codePoints.length);
8935
8935
  for (var idx = 0, len = codePoints.length; idx < len; idx++) {
8936
- var codePoint = utils_1.toCodePoint(codePoints[idx]);
8937
- glyphs[idx] = this.encoding.encodeUnicodeCodePoint(codePoint);
8936
+ var codePoint2 = utils_1.toCodePoint(codePoints[idx]);
8937
+ glyphs[idx] = this.encoding.encodeUnicodeCodePoint(codePoint2);
8938
8938
  }
8939
8939
  return glyphs;
8940
8940
  };
8941
- StandardFontEmbedder2.for = function(fontName, customName) {
8942
- return new StandardFontEmbedder2(fontName, customName);
8941
+ StandardFontEmbedder3.for = function(fontName, customName) {
8942
+ return new StandardFontEmbedder3(fontName, customName);
8943
8943
  };
8944
- return StandardFontEmbedder2;
8944
+ return StandardFontEmbedder3;
8945
8945
  })()
8946
8946
  );
8947
- exports2.default = StandardFontEmbedder;
8947
+ exports2.default = StandardFontEmbedder2;
8948
8948
  }
8949
8949
  });
8950
8950
 
@@ -8968,8 +8968,8 @@ var require_CMap = __commonJS({
8968
8968
  };
8969
8969
  var fillCmapTemplate = function(bfChars) {
8970
8970
  return "/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo <<\n /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000><ffff>\nendcodespacerange\n" + bfChars.length + " beginbfchar\n" + bfChars.map(function(_a) {
8971
- var glyphId = _a[0], codePoint = _a[1];
8972
- return glyphId + " " + codePoint;
8971
+ var glyphId = _a[0], codePoint2 = _a[1];
8972
+ return glyphId + " " + codePoint2;
8973
8973
  }).join("\n") + "\nendbfchar\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend";
8974
8974
  };
8975
8975
  var cmapHexFormat = function() {
@@ -8982,15 +8982,15 @@ var require_CMap = __commonJS({
8982
8982
  var cmapHexString = function(value) {
8983
8983
  return utils_1.toHexStringOfMinLength(value, 4);
8984
8984
  };
8985
- var cmapCodePointFormat = function(codePoint) {
8986
- if (unicode_1.isWithinBMP(codePoint))
8987
- return cmapHexString(codePoint);
8988
- if (unicode_1.hasSurrogates(codePoint)) {
8989
- var hs = unicode_1.highSurrogate(codePoint);
8990
- var ls = unicode_1.lowSurrogate(codePoint);
8985
+ var cmapCodePointFormat = function(codePoint2) {
8986
+ if (unicode_1.isWithinBMP(codePoint2))
8987
+ return cmapHexString(codePoint2);
8988
+ if (unicode_1.hasSurrogates(codePoint2)) {
8989
+ var hs = unicode_1.highSurrogate(codePoint2);
8990
+ var ls = unicode_1.lowSurrogate(codePoint2);
8991
8991
  return "" + cmapHexString(hs) + cmapHexString(ls);
8992
8992
  }
8993
- var hex = utils_1.toHexString(codePoint);
8993
+ var hex = utils_1.toHexString(codePoint2);
8994
8994
  var msg = "0x" + hex + " is not a valid UTF-8 or UTF-16 codepoint.";
8995
8995
  throw new Error(msg);
8996
8996
  };
@@ -9182,8 +9182,8 @@ var require_CustomFontEmbedder = __commonJS({
9182
9182
  this.allGlyphsInFontSortedById = function() {
9183
9183
  var glyphs = new Array(_this.font.characterSet.length);
9184
9184
  for (var idx = 0, len = glyphs.length; idx < len; idx++) {
9185
- var codePoint = _this.font.characterSet[idx];
9186
- glyphs[idx] = _this.font.glyphForCodePoint(codePoint);
9185
+ var codePoint2 = _this.font.characterSet[idx];
9186
+ glyphs[idx] = _this.font.glyphForCodePoint(codePoint2);
9187
9187
  }
9188
9188
  return utils_1.sortedUniq(glyphs.sort(utils_1.byAscendingId), function(g) {
9189
9189
  return g.id;
@@ -17457,20 +17457,20 @@ var require_errors3 = __commonJS({
17457
17457
  Object.defineProperty(exports2, "__esModule", { value: true });
17458
17458
  exports2.InvalidMaxLengthError = exports2.ExceededMaxLengthError = exports2.CombedTextLayoutError = exports2.RichTextFieldReadError = exports2.FieldExistsAsNonTerminalError = exports2.InvalidFieldNamePartError = exports2.FieldAlreadyExistsError = exports2.MissingOnValueCheckError = exports2.UnexpectedFieldTypeError = exports2.NoSuchFieldError = exports2.RemovePageFromEmptyDocumentError = exports2.ForeignPageError = exports2.FontkitNotRegisteredError = exports2.EncryptedPDFError = void 0;
17459
17459
  var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports));
17460
- var EncryptedPDFError = (
17460
+ var EncryptedPDFError2 = (
17461
17461
  /** @class */
17462
17462
  (function(_super) {
17463
- tslib_1.__extends(EncryptedPDFError2, _super);
17464
- function EncryptedPDFError2() {
17463
+ tslib_1.__extends(EncryptedPDFError3, _super);
17464
+ function EncryptedPDFError3() {
17465
17465
  var _this = this;
17466
17466
  var msg = "Input document to `PDFDocument.load` is encrypted. You can use `PDFDocument.load(..., { ignoreEncryption: true })` if you wish to load the document anyways.";
17467
17467
  _this = _super.call(this, msg) || this;
17468
17468
  return _this;
17469
17469
  }
17470
- return EncryptedPDFError2;
17470
+ return EncryptedPDFError3;
17471
17471
  })(Error)
17472
17472
  );
17473
- exports2.EncryptedPDFError = EncryptedPDFError;
17473
+ exports2.EncryptedPDFError = EncryptedPDFError2;
17474
17474
  var FontkitNotRegisteredError = (
17475
17475
  /** @class */
17476
17476
  (function(_super) {
@@ -20399,10 +20399,10 @@ var require_PDFDocument = __commonJS({
20399
20399
  var PDFEmbeddedFile_1 = tslib_1.__importDefault(require_PDFEmbeddedFile());
20400
20400
  var PDFJavaScript_1 = tslib_1.__importDefault(require_PDFJavaScript());
20401
20401
  var JavaScriptEmbedder_1 = tslib_1.__importDefault(require_JavaScriptEmbedder());
20402
- var PDFDocument2 = (
20402
+ var PDFDocument3 = (
20403
20403
  /** @class */
20404
20404
  (function() {
20405
- function PDFDocument3(context, ignoreEncryption, updateMetadata) {
20405
+ function PDFDocument4(context, ignoreEncryption, updateMetadata) {
20406
20406
  var _this = this;
20407
20407
  this.defaultWordBreaks = [" "];
20408
20408
  this.computePages = function() {
@@ -20441,7 +20441,7 @@ var require_PDFDocument = __commonJS({
20441
20441
  if (updateMetadata)
20442
20442
  this.updateInfoDict();
20443
20443
  }
20444
- PDFDocument3.load = function(pdf, options) {
20444
+ PDFDocument4.load = function(pdf, options) {
20445
20445
  if (options === void 0) {
20446
20446
  options = {};
20447
20447
  }
@@ -20459,12 +20459,12 @@ var require_PDFDocument = __commonJS({
20459
20459
  return [4, core_1.PDFParser.forBytesWithOptions(bytes, parseSpeed, throwOnInvalidObject, capNumbers).parseDocument()];
20460
20460
  case 1:
20461
20461
  context = _f.sent();
20462
- return [2, new PDFDocument3(context, ignoreEncryption, updateMetadata)];
20462
+ return [2, new PDFDocument4(context, ignoreEncryption, updateMetadata)];
20463
20463
  }
20464
20464
  });
20465
20465
  });
20466
20466
  };
20467
- PDFDocument3.create = function(options) {
20467
+ PDFDocument4.create = function(options) {
20468
20468
  if (options === void 0) {
20469
20469
  options = {};
20470
20470
  }
@@ -20477,14 +20477,14 @@ var require_PDFDocument = __commonJS({
20477
20477
  pageTreeRef = context.register(pageTree);
20478
20478
  catalog = core_1.PDFCatalog.withContextAndPages(context, pageTreeRef);
20479
20479
  context.trailerInfo.Root = context.register(catalog);
20480
- return [2, new PDFDocument3(context, false, updateMetadata)];
20480
+ return [2, new PDFDocument4(context, false, updateMetadata)];
20481
20481
  });
20482
20482
  });
20483
20483
  };
20484
- PDFDocument3.prototype.registerFontkit = function(fontkit) {
20484
+ PDFDocument4.prototype.registerFontkit = function(fontkit) {
20485
20485
  this.fontkit = fontkit;
20486
20486
  };
20487
- PDFDocument3.prototype.getForm = function() {
20487
+ PDFDocument4.prototype.getForm = function() {
20488
20488
  var form = this.formCache.access();
20489
20489
  if (form.hasXFA()) {
20490
20490
  console.warn("Removing XFA form data as pdf-lib does not support reading or writing XFA");
@@ -20492,63 +20492,63 @@ var require_PDFDocument = __commonJS({
20492
20492
  }
20493
20493
  return form;
20494
20494
  };
20495
- PDFDocument3.prototype.getTitle = function() {
20495
+ PDFDocument4.prototype.getTitle = function() {
20496
20496
  var title = this.getInfoDict().lookup(core_1.PDFName.Title);
20497
20497
  if (!title)
20498
20498
  return void 0;
20499
20499
  assertIsLiteralOrHexString(title);
20500
20500
  return title.decodeText();
20501
20501
  };
20502
- PDFDocument3.prototype.getAuthor = function() {
20502
+ PDFDocument4.prototype.getAuthor = function() {
20503
20503
  var author = this.getInfoDict().lookup(core_1.PDFName.Author);
20504
20504
  if (!author)
20505
20505
  return void 0;
20506
20506
  assertIsLiteralOrHexString(author);
20507
20507
  return author.decodeText();
20508
20508
  };
20509
- PDFDocument3.prototype.getSubject = function() {
20509
+ PDFDocument4.prototype.getSubject = function() {
20510
20510
  var subject = this.getInfoDict().lookup(core_1.PDFName.Subject);
20511
20511
  if (!subject)
20512
20512
  return void 0;
20513
20513
  assertIsLiteralOrHexString(subject);
20514
20514
  return subject.decodeText();
20515
20515
  };
20516
- PDFDocument3.prototype.getKeywords = function() {
20516
+ PDFDocument4.prototype.getKeywords = function() {
20517
20517
  var keywords = this.getInfoDict().lookup(core_1.PDFName.Keywords);
20518
20518
  if (!keywords)
20519
20519
  return void 0;
20520
20520
  assertIsLiteralOrHexString(keywords);
20521
20521
  return keywords.decodeText();
20522
20522
  };
20523
- PDFDocument3.prototype.getCreator = function() {
20523
+ PDFDocument4.prototype.getCreator = function() {
20524
20524
  var creator = this.getInfoDict().lookup(core_1.PDFName.Creator);
20525
20525
  if (!creator)
20526
20526
  return void 0;
20527
20527
  assertIsLiteralOrHexString(creator);
20528
20528
  return creator.decodeText();
20529
20529
  };
20530
- PDFDocument3.prototype.getProducer = function() {
20530
+ PDFDocument4.prototype.getProducer = function() {
20531
20531
  var producer = this.getInfoDict().lookup(core_1.PDFName.Producer);
20532
20532
  if (!producer)
20533
20533
  return void 0;
20534
20534
  assertIsLiteralOrHexString(producer);
20535
20535
  return producer.decodeText();
20536
20536
  };
20537
- PDFDocument3.prototype.getCreationDate = function() {
20537
+ PDFDocument4.prototype.getCreationDate = function() {
20538
20538
  var creationDate = this.getInfoDict().lookup(core_1.PDFName.CreationDate);
20539
20539
  if (!creationDate)
20540
20540
  return void 0;
20541
20541
  assertIsLiteralOrHexString(creationDate);
20542
20542
  return creationDate.decodeDate();
20543
20543
  };
20544
- PDFDocument3.prototype.getModificationDate = function() {
20544
+ PDFDocument4.prototype.getModificationDate = function() {
20545
20545
  var modificationDate = this.getInfoDict().lookup(core_1.PDFName.ModDate);
20546
20546
  if (!modificationDate)
20547
20547
  return void 0;
20548
20548
  assertIsLiteralOrHexString(modificationDate);
20549
20549
  return modificationDate.decodeDate();
20550
20550
  };
20551
- PDFDocument3.prototype.setTitle = function(title, options) {
20551
+ PDFDocument4.prototype.setTitle = function(title, options) {
20552
20552
  utils_1.assertIs(title, "title", ["string"]);
20553
20553
  var key = core_1.PDFName.of("Title");
20554
20554
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(title));
@@ -20557,63 +20557,63 @@ var require_PDFDocument = __commonJS({
20557
20557
  prefs.setDisplayDocTitle(true);
20558
20558
  }
20559
20559
  };
20560
- PDFDocument3.prototype.setAuthor = function(author) {
20560
+ PDFDocument4.prototype.setAuthor = function(author) {
20561
20561
  utils_1.assertIs(author, "author", ["string"]);
20562
20562
  var key = core_1.PDFName.of("Author");
20563
20563
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(author));
20564
20564
  };
20565
- PDFDocument3.prototype.setSubject = function(subject) {
20565
+ PDFDocument4.prototype.setSubject = function(subject) {
20566
20566
  utils_1.assertIs(subject, "author", ["string"]);
20567
20567
  var key = core_1.PDFName.of("Subject");
20568
20568
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(subject));
20569
20569
  };
20570
- PDFDocument3.prototype.setKeywords = function(keywords) {
20570
+ PDFDocument4.prototype.setKeywords = function(keywords) {
20571
20571
  utils_1.assertIs(keywords, "keywords", [Array]);
20572
20572
  var key = core_1.PDFName.of("Keywords");
20573
20573
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(keywords.join(" ")));
20574
20574
  };
20575
- PDFDocument3.prototype.setCreator = function(creator) {
20575
+ PDFDocument4.prototype.setCreator = function(creator) {
20576
20576
  utils_1.assertIs(creator, "creator", ["string"]);
20577
20577
  var key = core_1.PDFName.of("Creator");
20578
20578
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(creator));
20579
20579
  };
20580
- PDFDocument3.prototype.setProducer = function(producer) {
20580
+ PDFDocument4.prototype.setProducer = function(producer) {
20581
20581
  utils_1.assertIs(producer, "creator", ["string"]);
20582
20582
  var key = core_1.PDFName.of("Producer");
20583
20583
  this.getInfoDict().set(key, core_1.PDFHexString.fromText(producer));
20584
20584
  };
20585
- PDFDocument3.prototype.setLanguage = function(language) {
20585
+ PDFDocument4.prototype.setLanguage = function(language) {
20586
20586
  utils_1.assertIs(language, "language", ["string"]);
20587
20587
  var key = core_1.PDFName.of("Lang");
20588
20588
  this.catalog.set(key, core_1.PDFString.of(language));
20589
20589
  };
20590
- PDFDocument3.prototype.setCreationDate = function(creationDate) {
20590
+ PDFDocument4.prototype.setCreationDate = function(creationDate) {
20591
20591
  utils_1.assertIs(creationDate, "creationDate", [[Date, "Date"]]);
20592
20592
  var key = core_1.PDFName.of("CreationDate");
20593
20593
  this.getInfoDict().set(key, core_1.PDFString.fromDate(creationDate));
20594
20594
  };
20595
- PDFDocument3.prototype.setModificationDate = function(modificationDate) {
20595
+ PDFDocument4.prototype.setModificationDate = function(modificationDate) {
20596
20596
  utils_1.assertIs(modificationDate, "modificationDate", [[Date, "Date"]]);
20597
20597
  var key = core_1.PDFName.of("ModDate");
20598
20598
  this.getInfoDict().set(key, core_1.PDFString.fromDate(modificationDate));
20599
20599
  };
20600
- PDFDocument3.prototype.getPageCount = function() {
20600
+ PDFDocument4.prototype.getPageCount = function() {
20601
20601
  if (this.pageCount === void 0)
20602
20602
  this.pageCount = this.getPages().length;
20603
20603
  return this.pageCount;
20604
20604
  };
20605
- PDFDocument3.prototype.getPages = function() {
20605
+ PDFDocument4.prototype.getPages = function() {
20606
20606
  return this.pageCache.access();
20607
20607
  };
20608
- PDFDocument3.prototype.getPage = function(index) {
20608
+ PDFDocument4.prototype.getPage = function(index) {
20609
20609
  var pages = this.getPages();
20610
20610
  utils_1.assertRange(index, "index", 0, pages.length - 1);
20611
20611
  return pages[index];
20612
20612
  };
20613
- PDFDocument3.prototype.getPageIndices = function() {
20613
+ PDFDocument4.prototype.getPageIndices = function() {
20614
20614
  return utils_1.range(0, this.getPageCount());
20615
20615
  };
20616
- PDFDocument3.prototype.removePage = function(index) {
20616
+ PDFDocument4.prototype.removePage = function(index) {
20617
20617
  var pageCount = this.getPageCount();
20618
20618
  if (this.pageCount === 0)
20619
20619
  throw new errors_1.RemovePageFromEmptyDocumentError();
@@ -20621,11 +20621,11 @@ var require_PDFDocument = __commonJS({
20621
20621
  this.catalog.removeLeafNode(index);
20622
20622
  this.pageCount = pageCount - 1;
20623
20623
  };
20624
- PDFDocument3.prototype.addPage = function(page) {
20624
+ PDFDocument4.prototype.addPage = function(page) {
20625
20625
  utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
20626
20626
  return this.insertPage(this.getPageCount(), page);
20627
20627
  };
20628
- PDFDocument3.prototype.insertPage = function(index, page) {
20628
+ PDFDocument4.prototype.insertPage = function(index, page) {
20629
20629
  var pageCount = this.getPageCount();
20630
20630
  utils_1.assertRange(index, "index", 0, pageCount);
20631
20631
  utils_1.assertIs(page, "page", ["undefined", [PDFPage_1.default, "PDFPage"], Array]);
@@ -20643,13 +20643,13 @@ var require_PDFDocument = __commonJS({
20643
20643
  this.pageCount = pageCount + 1;
20644
20644
  return page;
20645
20645
  };
20646
- PDFDocument3.prototype.copyPages = function(srcDoc, indices) {
20646
+ PDFDocument4.prototype.copyPages = function(srcDoc, indices) {
20647
20647
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20648
20648
  var copier, srcPages, copiedPages, idx, len, srcPage, copiedPage, ref;
20649
20649
  return tslib_1.__generator(this, function(_a) {
20650
20650
  switch (_a.label) {
20651
20651
  case 0:
20652
- utils_1.assertIs(srcDoc, "srcDoc", [[PDFDocument3, "PDFDocument"]]);
20652
+ utils_1.assertIs(srcDoc, "srcDoc", [[PDFDocument4, "PDFDocument"]]);
20653
20653
  utils_1.assertIs(indices, "indices", [Array]);
20654
20654
  return [4, srcDoc.flush()];
20655
20655
  case 1:
@@ -20668,13 +20668,13 @@ var require_PDFDocument = __commonJS({
20668
20668
  });
20669
20669
  });
20670
20670
  };
20671
- PDFDocument3.prototype.copy = function() {
20671
+ PDFDocument4.prototype.copy = function() {
20672
20672
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20673
20673
  var pdfCopy, contentPages, idx, len;
20674
20674
  return tslib_1.__generator(this, function(_a) {
20675
20675
  switch (_a.label) {
20676
20676
  case 0:
20677
- return [4, PDFDocument3.create()];
20677
+ return [4, PDFDocument4.create()];
20678
20678
  case 1:
20679
20679
  pdfCopy = _a.sent();
20680
20680
  return [4, pdfCopy.copyPages(this, this.getPageIndices())];
@@ -20710,7 +20710,7 @@ var require_PDFDocument = __commonJS({
20710
20710
  });
20711
20711
  });
20712
20712
  };
20713
- PDFDocument3.prototype.addJavaScript = function(name, script) {
20713
+ PDFDocument4.prototype.addJavaScript = function(name, script) {
20714
20714
  utils_1.assertIs(name, "name", ["string"]);
20715
20715
  utils_1.assertIs(script, "script", ["string"]);
20716
20716
  var embedder = JavaScriptEmbedder_1.default.for(script, name);
@@ -20718,7 +20718,7 @@ var require_PDFDocument = __commonJS({
20718
20718
  var javaScript = PDFJavaScript_1.default.of(ref, this, embedder);
20719
20719
  this.javaScripts.push(javaScript);
20720
20720
  };
20721
- PDFDocument3.prototype.attach = function(attachment, name, options) {
20721
+ PDFDocument4.prototype.attach = function(attachment, name, options) {
20722
20722
  if (options === void 0) {
20723
20723
  options = {};
20724
20724
  }
@@ -20746,7 +20746,7 @@ var require_PDFDocument = __commonJS({
20746
20746
  });
20747
20747
  });
20748
20748
  };
20749
- PDFDocument3.prototype.embedFont = function(font, options) {
20749
+ PDFDocument4.prototype.embedFont = function(font, options) {
20750
20750
  if (options === void 0) {
20751
20751
  options = {};
20752
20752
  }
@@ -20789,7 +20789,7 @@ var require_PDFDocument = __commonJS({
20789
20789
  });
20790
20790
  });
20791
20791
  };
20792
- PDFDocument3.prototype.embedStandardFont = function(font, customName) {
20792
+ PDFDocument4.prototype.embedStandardFont = function(font, customName) {
20793
20793
  utils_1.assertIs(font, "font", ["string"]);
20794
20794
  if (!utils_1.isStandardFont(font)) {
20795
20795
  throw new TypeError("`font` must be one of type `StandardFonts`");
@@ -20800,7 +20800,7 @@ var require_PDFDocument = __commonJS({
20800
20800
  this.fonts.push(pdfFont);
20801
20801
  return pdfFont;
20802
20802
  };
20803
- PDFDocument3.prototype.embedJpg = function(jpg) {
20803
+ PDFDocument4.prototype.embedJpg = function(jpg) {
20804
20804
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20805
20805
  var bytes, embedder, ref, pdfImage;
20806
20806
  return tslib_1.__generator(this, function(_a) {
@@ -20819,7 +20819,7 @@ var require_PDFDocument = __commonJS({
20819
20819
  });
20820
20820
  });
20821
20821
  };
20822
- PDFDocument3.prototype.embedPng = function(png) {
20822
+ PDFDocument4.prototype.embedPng = function(png) {
20823
20823
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20824
20824
  var bytes, embedder, ref, pdfImage;
20825
20825
  return tslib_1.__generator(this, function(_a) {
@@ -20838,7 +20838,7 @@ var require_PDFDocument = __commonJS({
20838
20838
  });
20839
20839
  });
20840
20840
  };
20841
- PDFDocument3.prototype.embedPdf = function(pdf, indices) {
20841
+ PDFDocument4.prototype.embedPdf = function(pdf, indices) {
20842
20842
  if (indices === void 0) {
20843
20843
  indices = [0];
20844
20844
  }
@@ -20851,14 +20851,14 @@ var require_PDFDocument = __commonJS({
20851
20851
  "string",
20852
20852
  Uint8Array,
20853
20853
  ArrayBuffer,
20854
- [PDFDocument3, "PDFDocument"]
20854
+ [PDFDocument4, "PDFDocument"]
20855
20855
  ]);
20856
20856
  utils_1.assertIs(indices, "indices", [Array]);
20857
- if (!(pdf instanceof PDFDocument3)) return [3, 1];
20857
+ if (!(pdf instanceof PDFDocument4)) return [3, 1];
20858
20858
  _a = pdf;
20859
20859
  return [3, 3];
20860
20860
  case 1:
20861
- return [4, PDFDocument3.load(pdf)];
20861
+ return [4, PDFDocument4.load(pdf)];
20862
20862
  case 2:
20863
20863
  _a = _b.sent();
20864
20864
  _b.label = 3;
@@ -20870,7 +20870,7 @@ var require_PDFDocument = __commonJS({
20870
20870
  });
20871
20871
  });
20872
20872
  };
20873
- PDFDocument3.prototype.embedPage = function(page, boundingBox, transformationMatrix) {
20873
+ PDFDocument4.prototype.embedPage = function(page, boundingBox, transformationMatrix) {
20874
20874
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20875
20875
  var embeddedPage;
20876
20876
  return tslib_1.__generator(this, function(_a) {
@@ -20885,7 +20885,7 @@ var require_PDFDocument = __commonJS({
20885
20885
  });
20886
20886
  });
20887
20887
  };
20888
- PDFDocument3.prototype.embedPages = function(pages, boundingBoxes, transformationMatrices) {
20888
+ PDFDocument4.prototype.embedPages = function(pages, boundingBoxes, transformationMatrices) {
20889
20889
  if (boundingBoxes === void 0) {
20890
20890
  boundingBoxes = [];
20891
20891
  }
@@ -20935,7 +20935,7 @@ var require_PDFDocument = __commonJS({
20935
20935
  });
20936
20936
  });
20937
20937
  };
20938
- PDFDocument3.prototype.flush = function() {
20938
+ PDFDocument4.prototype.flush = function() {
20939
20939
  return tslib_1.__awaiter(this, void 0, void 0, function() {
20940
20940
  return tslib_1.__generator(this, function(_a) {
20941
20941
  switch (_a.label) {
@@ -20963,7 +20963,7 @@ var require_PDFDocument = __commonJS({
20963
20963
  });
20964
20964
  });
20965
20965
  };
20966
- PDFDocument3.prototype.save = function(options) {
20966
+ PDFDocument4.prototype.save = function(options) {
20967
20967
  if (options === void 0) {
20968
20968
  options = {};
20969
20969
  }
@@ -20993,7 +20993,7 @@ var require_PDFDocument = __commonJS({
20993
20993
  });
20994
20994
  });
20995
20995
  };
20996
- PDFDocument3.prototype.saveAsBase64 = function(options) {
20996
+ PDFDocument4.prototype.saveAsBase64 = function(options) {
20997
20997
  if (options === void 0) {
20998
20998
  options = {};
20999
20999
  }
@@ -21013,7 +21013,7 @@ var require_PDFDocument = __commonJS({
21013
21013
  });
21014
21014
  });
21015
21015
  };
21016
- PDFDocument3.prototype.findPageForAnnotationRef = function(ref) {
21016
+ PDFDocument4.prototype.findPageForAnnotationRef = function(ref) {
21017
21017
  var pages = this.getPages();
21018
21018
  for (var idx = 0, len = pages.length; idx < len; idx++) {
21019
21019
  var page = pages[idx];
@@ -21024,7 +21024,7 @@ var require_PDFDocument = __commonJS({
21024
21024
  }
21025
21025
  return void 0;
21026
21026
  };
21027
- PDFDocument3.prototype.embedAll = function(embeddables) {
21027
+ PDFDocument4.prototype.embedAll = function(embeddables) {
21028
21028
  return tslib_1.__awaiter(this, void 0, void 0, function() {
21029
21029
  var idx, len;
21030
21030
  return tslib_1.__generator(this, function(_a) {
@@ -21050,7 +21050,7 @@ var require_PDFDocument = __commonJS({
21050
21050
  });
21051
21051
  });
21052
21052
  };
21053
- PDFDocument3.prototype.updateInfoDict = function() {
21053
+ PDFDocument4.prototype.updateInfoDict = function() {
21054
21054
  var pdfLib = "pdf-lib (https://github.com/Hopding/pdf-lib)";
21055
21055
  var now = /* @__PURE__ */ new Date();
21056
21056
  var info = this.getInfoDict();
@@ -21061,7 +21061,7 @@ var require_PDFDocument = __commonJS({
21061
21061
  if (!info.get(core_1.PDFName.of("CreationDate")))
21062
21062
  this.setCreationDate(now);
21063
21063
  };
21064
- PDFDocument3.prototype.getInfoDict = function() {
21064
+ PDFDocument4.prototype.getInfoDict = function() {
21065
21065
  var existingInfo = this.context.lookup(this.context.trailerInfo.Info);
21066
21066
  if (existingInfo instanceof core_1.PDFDict)
21067
21067
  return existingInfo;
@@ -21069,15 +21069,15 @@ var require_PDFDocument = __commonJS({
21069
21069
  this.context.trailerInfo.Info = this.context.register(newInfo);
21070
21070
  return newInfo;
21071
21071
  };
21072
- PDFDocument3.prototype.assertFontkit = function() {
21072
+ PDFDocument4.prototype.assertFontkit = function() {
21073
21073
  if (!this.fontkit)
21074
21074
  throw new errors_1.FontkitNotRegisteredError();
21075
21075
  return this.fontkit;
21076
21076
  };
21077
- return PDFDocument3;
21077
+ return PDFDocument4;
21078
21078
  })()
21079
21079
  );
21080
- exports2.default = PDFDocument2;
21080
+ exports2.default = PDFDocument3;
21081
21081
  function assertIsLiteralOrHexString(pdfObject) {
21082
21082
  if (!(pdfObject instanceof core_1.PDFHexString) && !(pdfObject instanceof core_1.PDFString)) {
21083
21083
  throw new core_1.UnexpectedObjectTypeError([core_1.PDFHexString, core_1.PDFString], pdfObject);
@@ -22015,47 +22015,522 @@ var require_cjs = __commonJS({
22015
22015
  }
22016
22016
  });
22017
22017
 
22018
+ // packages/core/dist/document/pdf-encrypted.js
22019
+ var ENCRYPTED_PDF_MESSAGE, OWNER_ONLY_PDF_MESSAGE, PdfEncryptedError;
22020
+ var init_pdf_encrypted = __esm({
22021
+ "packages/core/dist/document/pdf-encrypted.js"() {
22022
+ "use strict";
22023
+ ENCRYPTED_PDF_MESSAGE = "PDF is password-protected (encrypted); decrypt first: pdf-ops decrypt <in> <password> <out>";
22024
+ OWNER_ONLY_PDF_MESSAGE = 'PDF is encrypted with an owner password only (it opens without a password, but cannot be edited encrypted); remove the encryption first: pdf-ops decrypt <in> "" <out>';
22025
+ PdfEncryptedError = class extends Error {
22026
+ constructor() {
22027
+ super(ENCRYPTED_PDF_MESSAGE);
22028
+ this.name = "PdfEncryptedError";
22029
+ }
22030
+ };
22031
+ }
22032
+ });
22033
+
22034
+ // packages/core/dist/document/pdf-extract.js
22035
+ var pdf_extract_exports = {};
22036
+ __export(pdf_extract_exports, {
22037
+ analyzePdfDocument: () => analyzePdfDocument,
22038
+ countVectorOperators: () => countVectorOperators,
22039
+ decryptPdf: () => decryptPdf,
22040
+ encryptPdf: () => encryptPdf,
22041
+ extractPdfImages: () => extractPdfImages,
22042
+ extractPdfTables: () => extractPdfTables,
22043
+ extractPdfText: () => extractPdfText,
22044
+ extractPdfTextLines: () => extractPdfTextLines,
22045
+ pdfNeedsPassword: () => pdfNeedsPassword,
22046
+ pngPixels: () => pngPixels,
22047
+ renderPdfPages: () => renderPdfPages,
22048
+ scanPdfSignals: () => scanPdfSignals,
22049
+ textMathHint: () => textMathHint,
22050
+ textTableHint: () => textTableHint
22051
+ });
22052
+ function loadMupdf() {
22053
+ if (!_mupdf) {
22054
+ const deps = process.env.TALOS_SKILL_DEPS;
22055
+ const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
22056
+ _mupdf = import(spec);
22057
+ }
22058
+ return _mupdf;
22059
+ }
22060
+ function textMathHint(text) {
22061
+ if (!text)
22062
+ return false;
22063
+ const hits = (text.match(MATH_CHARS) || []).length;
22064
+ return hits >= 3 || hits / Math.max(text.length, 1) > 0.02;
22065
+ }
22066
+ function textTableHint(text) {
22067
+ if (!text)
22068
+ return false;
22069
+ const gaps = (text.match(/ {2,}|\t/g) || []).length;
22070
+ return gaps >= 6;
22071
+ }
22072
+ async function openDoc(bytes) {
22073
+ const mupdf = await loadMupdf();
22074
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
22075
+ if (doc.needsPassword())
22076
+ throw new PdfEncryptedError();
22077
+ if (doc.countPages() === 0) {
22078
+ throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
22079
+ }
22080
+ return { mupdf, doc };
22081
+ }
22082
+ async function analyzePdfDocument(bytes, options = {}) {
22083
+ const wantText = options.text !== false;
22084
+ const wantSignals = options.signals === true;
22085
+ const { doc } = await openDoc(bytes);
22086
+ const pageCount = doc.countPages();
22087
+ const signals = [];
22088
+ let out = "";
22089
+ for (let i = 0; i < pageCount; i++) {
22090
+ const page = doc.loadPage(i);
22091
+ if (wantText) {
22092
+ out += `
22093
+ [page ${i + 1}]
22094
+ ${page.toStructuredText().asText()}`;
22095
+ }
22096
+ if (wantSignals) {
22097
+ signals.push(pageSignalsFrom(page, i + 1));
22098
+ }
22099
+ }
22100
+ return { text: wantText ? out.trim() : "", pageCount, signals };
22101
+ }
22102
+ async function extractPdfText(bytes) {
22103
+ const { text, pageCount } = await analyzePdfDocument(bytes, { text: true });
22104
+ return { text, pageCount };
22105
+ }
22106
+ function countVectorOperators(content) {
22107
+ let ops = 0;
22108
+ let curves = 0;
22109
+ let fills = 0;
22110
+ let i = 0;
22111
+ const n = content.length;
22112
+ while (i < n) {
22113
+ const ch = content[i];
22114
+ if (ch === "(") {
22115
+ let depth = 1;
22116
+ i++;
22117
+ while (i < n && depth > 0) {
22118
+ if (content[i] === "\\")
22119
+ i++;
22120
+ else if (content[i] === "(")
22121
+ depth++;
22122
+ else if (content[i] === ")")
22123
+ depth--;
22124
+ i++;
22125
+ }
22126
+ continue;
22127
+ }
22128
+ if (ch === "<" && content[i + 1] !== "<") {
22129
+ while (i < n && content[i] !== ">")
22130
+ i++;
22131
+ i++;
22132
+ continue;
22133
+ }
22134
+ if (ch === "I" && content[i + 1] === "D" && isDelimiter(content[i + 2])) {
22135
+ const end = content.indexOf("EI", i + 2);
22136
+ i = end === -1 ? n : end + 2;
22137
+ continue;
22138
+ }
22139
+ if (!isDelimiter(ch)) {
22140
+ const start = i;
22141
+ while (i < n && !isDelimiter(content[i]))
22142
+ i++;
22143
+ const token = content.slice(start, i);
22144
+ switch (token) {
22145
+ case "m":
22146
+ case "l":
22147
+ case "re":
22148
+ ops++;
22149
+ break;
22150
+ case "c":
22151
+ case "v":
22152
+ case "y":
22153
+ ops++;
22154
+ curves++;
22155
+ break;
22156
+ case "f":
22157
+ case "F":
22158
+ case "f*":
22159
+ fills++;
22160
+ break;
22161
+ case "B":
22162
+ case "B*":
22163
+ case "b":
22164
+ case "b*":
22165
+ fills++;
22166
+ break;
22167
+ default:
22168
+ break;
22169
+ }
22170
+ continue;
22171
+ }
22172
+ i++;
22173
+ }
22174
+ return { ops, curves, fills };
22175
+ }
22176
+ function isDelimiter(ch) {
22177
+ return ch === void 0 || ch === " " || ch === "\n" || ch === "\r" || ch === " " || ch === "\f" || ch === "\0" || ch === "[" || ch === "]" || ch === "/" || ch === "{" || ch === "}";
22178
+ }
22179
+ function pageContentStream(page) {
22180
+ try {
22181
+ const obj = page.getObject?.();
22182
+ const contents = obj?.get?.("Contents");
22183
+ if (!contents)
22184
+ return "";
22185
+ const streams = contents.isArray?.() && contents.get ? Array.from({ length: contents.length ?? 0 }, (_, i) => contents.get(i)) : [contents];
22186
+ let out = "";
22187
+ for (const stream of streams) {
22188
+ const buf = stream?.readStream?.();
22189
+ const bytes = buf?.asUint8Array?.();
22190
+ if (bytes)
22191
+ out += Buffer.from(bytes).toString("latin1");
22192
+ }
22193
+ return out;
22194
+ } catch {
22195
+ return "";
22196
+ }
22197
+ }
22198
+ function pageSignalsFrom(page, pageNumber) {
22199
+ const json = JSON.parse(page.toStructuredText("preserve-images").asJSON());
22200
+ const blocks = json.blocks ?? [];
22201
+ const text = blocks.flatMap((b) => (b.lines ?? []).map((l) => l.text ?? "")).join(" ");
22202
+ const [x0, y0, x1, y1] = page.getBounds();
22203
+ const pageArea = Math.max((x1 - x0) * (y1 - y0), 1);
22204
+ const imgArea = blocks.filter((b) => b.type === "image").reduce((a, b) => a + Math.max((b.bbox?.w ?? 0) * (b.bbox?.h ?? 0), 0), 0);
22205
+ const vector = countVectorOperators(pageContentStream(page));
22206
+ return {
22207
+ page: pageNumber,
22208
+ textChars: text.trim().length,
22209
+ imageCoverage: Math.min(imgArea / pageArea, 1),
22210
+ vectorOps: vector.ops,
22211
+ vectorCurves: vector.curves,
22212
+ vectorFills: vector.fills,
22213
+ mathHint: textMathHint(text),
22214
+ tableHint: textTableHint(text)
22215
+ };
22216
+ }
22217
+ async function scanPdfSignals(bytes) {
22218
+ const { signals } = await analyzePdfDocument(bytes, { text: false, signals: true });
22219
+ return signals;
22220
+ }
22221
+ function median(nums) {
22222
+ if (!nums.length)
22223
+ return 0;
22224
+ const s = [...nums].sort((a, b) => a - b);
22225
+ return s[Math.floor(s.length / 2)];
22226
+ }
22227
+ async function extractPdfTables(bytes, pageNum, minColumns = 2) {
22228
+ const { doc } = await openDoc(bytes);
22229
+ const total = doc.countPages();
22230
+ const from = pageNum ? pageNum : 1;
22231
+ const to = pageNum ? pageNum : total;
22232
+ const out = [];
22233
+ for (let p = from; p <= to; p++) {
22234
+ if (p < 1 || p > total)
22235
+ continue;
22236
+ const json = JSON.parse(doc.loadPage(p - 1).toStructuredText().asJSON());
22237
+ const cells = [];
22238
+ for (const b of json.blocks ?? []) {
22239
+ if (b.type === "image")
22240
+ continue;
22241
+ for (const l of b.lines ?? []) {
22242
+ const text = (l.text ?? "").trim();
22243
+ if (!text)
22244
+ continue;
22245
+ cells.push({ text, x: l.bbox?.x ?? 0, y: l.bbox?.y ?? 0, h: l.bbox?.h ?? 12 });
22246
+ }
22247
+ }
22248
+ if (cells.length < 2)
22249
+ continue;
22250
+ const medH = median(cells.map((c) => c.h)) || 12;
22251
+ const rowTol = Math.max(4, medH * 0.6);
22252
+ const colTol = Math.max(6, medH * 0.9);
22253
+ const byY = [...cells].sort((a, b) => a.y - b.y);
22254
+ const rowGroups = [];
22255
+ let rowRef = Number.NEGATIVE_INFINITY;
22256
+ for (const c of byY) {
22257
+ if (c.y - rowRef > rowTol) {
22258
+ rowGroups.push([]);
22259
+ rowRef = c.y;
22260
+ }
22261
+ rowGroups[rowGroups.length - 1].push(c);
22262
+ }
22263
+ const colRefs = [];
22264
+ for (const x of cells.map((c) => c.x).sort((a, b) => a - b)) {
22265
+ if (!colRefs.length || x - colRefs[colRefs.length - 1] > colTol)
22266
+ colRefs.push(x);
22267
+ }
22268
+ const colIndex = (x) => {
22269
+ let best = 0, bd = Infinity;
22270
+ colRefs.forEach((r, i) => {
22271
+ const d = Math.abs(x - r);
22272
+ if (d < bd) {
22273
+ bd = d;
22274
+ best = i;
22275
+ }
22276
+ });
22277
+ return best;
22278
+ };
22279
+ const rows = [];
22280
+ for (const group of rowGroups) {
22281
+ const arr = Array(colRefs.length).fill("");
22282
+ for (const c of group.sort((a, b) => a.x - b.x)) {
22283
+ const i = colIndex(c.x);
22284
+ arr[i] = arr[i] ? `${arr[i]} ${c.text}` : c.text;
22285
+ }
22286
+ if (arr.filter((v) => v).length >= minColumns)
22287
+ rows.push(arr);
22288
+ }
22289
+ if (rows.length)
22290
+ out.push({ page: p, rows });
22291
+ }
22292
+ return out;
22293
+ }
22294
+ async function extractPdfTextLines(bytes) {
22295
+ const { doc } = await openDoc(bytes);
22296
+ const out = [];
22297
+ for (let p = 1; p <= doc.countPages(); p++) {
22298
+ const page = doc.loadPage(p - 1);
22299
+ const [x0, y0, x1, y1] = page.getBounds();
22300
+ const json = JSON.parse(page.toStructuredText().asJSON());
22301
+ const lines = [];
22302
+ for (const b of json.blocks ?? []) {
22303
+ if (b.type === "image")
22304
+ continue;
22305
+ for (const l of b.lines ?? []) {
22306
+ const text = l.text ?? "";
22307
+ if (!text.trim() || !l.bbox)
22308
+ continue;
22309
+ lines.push({
22310
+ x: l.bbox.x ?? 0,
22311
+ y: l.bbox.y ?? 0,
22312
+ w: l.bbox.w ?? 0,
22313
+ h: l.bbox.h ?? 0,
22314
+ size: l.font?.size ?? 12,
22315
+ text
22316
+ });
22317
+ }
22318
+ }
22319
+ out.push({ page: p, width: x1 - x0, height: y1 - y0, lines });
22320
+ }
22321
+ return out;
22322
+ }
22323
+ async function renderPdfPages(bytes, pages, scale = 2, maxEdge) {
22324
+ const { mupdf, doc } = await openDoc(bytes);
22325
+ const total = doc.countPages();
22326
+ const wanted = pages === "all" ? Array.from({ length: total }, (_, i) => i + 1) : pages;
22327
+ const out = [];
22328
+ for (const p of wanted) {
22329
+ if (p < 1 || p > total)
22330
+ continue;
22331
+ const page = doc.loadPage(p - 1);
22332
+ const [x0, y0, x1, y1] = page.getBounds();
22333
+ const longest = Math.max(x1 - x0, y1 - y0);
22334
+ const s = maxEdge && longest > 0 ? Math.min(scale, maxEdge / longest) : scale;
22335
+ const pix = page.toPixmap(mupdf.Matrix.scale(s, s), mupdf.ColorSpace.DeviceRGB, false, true);
22336
+ out.push({ page: p, png: pix.asPNG() });
22337
+ }
22338
+ return out;
22339
+ }
22340
+ async function pngPixels(png) {
22341
+ const mupdf = await loadMupdf();
22342
+ const pix = new mupdf.Image(png).toPixmap();
22343
+ const width = pix.getWidth(), height = pix.getHeight();
22344
+ const channels = pix.getStride() / width;
22345
+ return { width, height, channels, data: pix.getPixels() };
22346
+ }
22347
+ async function extractPdfImages(bytes, pages) {
22348
+ const { doc } = await openDoc(bytes);
22349
+ const total = doc.countPages();
22350
+ const wanted = pages && pages.length ? pages : Array.from({ length: total }, (_, i) => i + 1);
22351
+ const images = [];
22352
+ let skipped = 0;
22353
+ for (const p of wanted) {
22354
+ if (p < 1 || p > total)
22355
+ continue;
22356
+ const stext = doc.loadPage(p - 1).toStructuredText("preserve-images");
22357
+ let index = 0;
22358
+ stext.walk({
22359
+ onImageBlock(bbox, _matrix, image) {
22360
+ const slot = index++;
22361
+ try {
22362
+ const png = image.toPixmap().asPNG();
22363
+ images.push({
22364
+ page: p,
22365
+ index: slot,
22366
+ bbox: [bbox[0], bbox[1], bbox[2], bbox[3]],
22367
+ width: image.getWidth(),
22368
+ height: image.getHeight(),
22369
+ png
22370
+ });
22371
+ } catch {
22372
+ skipped++;
22373
+ }
22374
+ }
22375
+ });
22376
+ }
22377
+ return { images, skipped };
22378
+ }
22379
+ async function encryptPdf(bytes, userPassword, ownerPassword) {
22380
+ if (!userPassword)
22381
+ throw new Error("a non-empty user password is required");
22382
+ const { doc } = await openDoc(bytes);
22383
+ const opts = `encrypt=aes-256,user-password=${userPassword},owner-password=${ownerPassword || userPassword}`;
22384
+ return doc.saveToBuffer(opts).asUint8Array();
22385
+ }
22386
+ async function pdfNeedsPassword(bytes) {
22387
+ const mupdf = await loadMupdf();
22388
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
22389
+ return doc.needsPassword();
22390
+ }
22391
+ async function decryptPdf(bytes, password) {
22392
+ const mupdf = await loadMupdf();
22393
+ const doc = mupdf.Document.openDocument(bytes, "application/pdf");
22394
+ if (doc.needsPassword()) {
22395
+ if (doc.authenticatePassword(password) === 0)
22396
+ throw new Error("wrong password");
22397
+ }
22398
+ if (doc.countPages() === 0)
22399
+ throw new Error("PDF has no readable pages (corrupt or empty)");
22400
+ return doc.saveToBuffer("encrypt=none").asUint8Array();
22401
+ }
22402
+ var import_node_path, import_node_url, _mupdf, MATH_CHARS;
22403
+ var init_pdf_extract = __esm({
22404
+ "packages/core/dist/document/pdf-extract.js"() {
22405
+ "use strict";
22406
+ import_node_path = require("node:path");
22407
+ import_node_url = require("node:url");
22408
+ init_pdf_encrypted();
22409
+ _mupdf = null;
22410
+ MATH_CHARS = /[=∑∫√≤≥≠±∞πθλμσΩ×÷∂∇→←↔∈∉⊂⊃∀∃]/g;
22411
+ }
22412
+ });
22413
+
22018
22414
  // apps/admin/data/skills.lib/document/bin-src/pdf-ops.mjs
22019
- var import_promises = require("node:fs/promises");
22415
+ var import_promises2 = require("node:fs/promises");
22416
+ var import_node_path3 = require("node:path");
22020
22417
 
22021
22418
  // packages/core/dist/document/pdf-ops.js
22419
+ var import_pdf_lib3 = __toESM(require_cjs(), 1);
22420
+
22421
+ // packages/core/dist/document/pdf-lib-load.js
22022
22422
  var import_pdf_lib = __toESM(require_cjs(), 1);
22423
+ init_pdf_encrypted();
22424
+ var isEncryptedError = (e) => e instanceof import_pdf_lib.EncryptedPDFError || /PDFDocument\.load` is encrypted/.test(String(e?.message));
22425
+ async function loadEditablePdf(bytes) {
22426
+ try {
22427
+ return await import_pdf_lib.PDFDocument.load(bytes);
22428
+ } catch (e) {
22429
+ if (!isEncryptedError(e))
22430
+ throw e;
22431
+ const { pdfNeedsPassword: pdfNeedsPassword2 } = await Promise.resolve().then(() => (init_pdf_extract(), pdf_extract_exports));
22432
+ const needsPassword = await pdfNeedsPassword2(bytes).catch(() => true);
22433
+ throw needsPassword ? new PdfEncryptedError() : new Error(OWNER_ONLY_PDF_MESSAGE);
22434
+ }
22435
+ }
22436
+
22437
+ // packages/core/dist/document/pdf-text-font.js
22438
+ var import_promises = require("node:fs/promises");
22439
+ var import_node_path2 = require("node:path");
22440
+ var import_pdf_lib2 = __toESM(require_cjs(), 1);
22441
+ async function loadFontkit() {
22442
+ const mod = await import("./fontkit.cjs");
22443
+ return mod.default?.create ? mod.default : mod;
22444
+ }
22445
+ var PDF_CJK_FONT_FILES = {
22446
+ regular: "NotoSansSC-PDF-Regular.ttf",
22447
+ bold: "NotoSansSC-PDF-Bold.ttf"
22448
+ };
22449
+ var LINE_BREAK = /\r\n|[\n\f\r\u000B\u0085\u2028\u2029]/;
22450
+ function encodableAs(std, text) {
22451
+ const enc = import_pdf_lib2.StandardFontEmbedder.for(std);
22452
+ try {
22453
+ for (const line of text.replace(/\t/g, " ").split(LINE_BREAK))
22454
+ enc.encodeText(line);
22455
+ return true;
22456
+ } catch {
22457
+ return false;
22458
+ }
22459
+ }
22460
+ var codePoint = (cp) => `"${String.fromCodePoint(cp)}" (U+${cp.toString(16).toUpperCase().padStart(4, "0")})`;
22461
+ async function embedTextFont(doc, texts, opts = {}) {
22462
+ const bold = opts.weight === "bold";
22463
+ const std = bold ? import_pdf_lib2.StandardFonts.HelveticaBold : import_pdf_lib2.StandardFonts.Helvetica;
22464
+ if (texts.every((t) => encodableAs(std, t)))
22465
+ return doc.embedFont(std);
22466
+ if (!opts.fontDir) {
22467
+ const sample = [...texts.join("")].find((ch) => ch !== " " && !LINE_BREAK.test(ch) && !encodableAs(std, ch)) ?? "";
22468
+ throw new Error(`text has characters Helvetica cannot draw (e.g. ${codePoint(sample.codePointAt(0) ?? 0)}) and no CJK font directory was given`);
22469
+ }
22470
+ const used = /* @__PURE__ */ new Set();
22471
+ for (const t of texts) {
22472
+ for (const ch of t) {
22473
+ const cp = ch.codePointAt(0);
22474
+ if (cp >= 32 && !LINE_BREAK.test(ch) && cp !== 127)
22475
+ used.add(cp);
22476
+ }
22477
+ }
22478
+ const fontkit = await loadFontkit();
22479
+ const regularBytes = await (0, import_promises.readFile)((0, import_node_path2.join)(opts.fontDir, PDF_CJK_FONT_FILES.regular));
22480
+ const regular = fontkit.create(regularBytes);
22481
+ const missing = [...used].filter((cp) => !regular.hasGlyphForCodePoint(cp));
22482
+ if (missing.length) {
22483
+ const shown = missing.slice(0, 8).map(codePoint).join(", ");
22484
+ throw new Error(`the bundled CJK font has no glyph for ${shown}${missing.length > 8 ? ` and ${missing.length - 8} more` : ""} \u2014 remove or replace those characters (it covers Chinese \u2014 all CJK Unified Ideographs \u2014 plus Latin, punctuation and full-width forms; emoji and rare extension characters are not included)`);
22485
+ }
22486
+ let bytes = regularBytes;
22487
+ if (bold) {
22488
+ const boldBytes = await (0, import_promises.readFile)((0, import_node_path2.join)(opts.fontDir, PDF_CJK_FONT_FILES.bold));
22489
+ const boldFont = fontkit.create(boldBytes);
22490
+ if ([...used].every((cp) => boldFont.hasGlyphForCodePoint(cp)))
22491
+ bytes = boldBytes;
22492
+ }
22493
+ doc.registerFontkit(fontkit);
22494
+ return doc.embedFont(bytes, { subset: true });
22495
+ }
22496
+
22497
+ // packages/core/dist/document/pdf-ops.js
22023
22498
  async function mergePdfs(pdfs) {
22024
22499
  if (pdfs.length === 0)
22025
22500
  throw new Error("merge needs at least one input PDF");
22026
- const out = await import_pdf_lib.PDFDocument.create();
22501
+ const out = await import_pdf_lib3.PDFDocument.create();
22027
22502
  for (const bytes of pdfs) {
22028
- const src = await import_pdf_lib.PDFDocument.load(bytes);
22503
+ const src = await loadEditablePdf(bytes);
22029
22504
  const pages = await out.copyPages(src, src.getPageIndices());
22030
22505
  pages.forEach((p) => out.addPage(p));
22031
22506
  }
22032
22507
  return out.save();
22033
22508
  }
22034
22509
  async function splitPdf(bytes, from, to) {
22035
- const src = await import_pdf_lib.PDFDocument.load(bytes);
22510
+ const src = await loadEditablePdf(bytes);
22036
22511
  const total = src.getPageCount();
22037
22512
  const idx = [];
22038
22513
  for (let p = Math.max(1, from); p <= Math.min(to, total); p++)
22039
22514
  idx.push(p - 1);
22040
22515
  if (!idx.length)
22041
22516
  throw new Error(`page range ${from}-${to} is empty (document has ${total} pages)`);
22042
- const out = await import_pdf_lib.PDFDocument.create();
22517
+ const out = await import_pdf_lib3.PDFDocument.create();
22043
22518
  const pages = await out.copyPages(src, idx);
22044
22519
  pages.forEach((p) => out.addPage(p));
22045
22520
  return out.save();
22046
22521
  }
22047
22522
  async function rotatePdf(bytes, deg, pages) {
22048
- const doc = await import_pdf_lib.PDFDocument.load(bytes);
22523
+ const doc = await loadEditablePdf(bytes);
22049
22524
  const all = doc.getPages();
22050
22525
  const targets = pages ? pages.map((p) => all[p - 1]).filter(Boolean) : all;
22051
22526
  for (const pg of targets) {
22052
- pg.setRotation((0, import_pdf_lib.degrees)(((pg.getRotation().angle + deg) % 360 + 360) % 360));
22527
+ pg.setRotation((0, import_pdf_lib3.degrees)(((pg.getRotation().angle + deg) % 360 + 360) % 360));
22053
22528
  }
22054
22529
  return doc.save();
22055
22530
  }
22056
- async function stampPdfText(bytes, stamps) {
22057
- const doc = await import_pdf_lib.PDFDocument.load(bytes);
22058
- const font = await doc.embedFont(import_pdf_lib.StandardFonts.Helvetica);
22531
+ async function stampPdfText(bytes, stamps, opts = {}) {
22532
+ const doc = await loadEditablePdf(bytes);
22533
+ const font = await embedTextFont(doc, stamps.map((s) => String(s.text)), opts);
22059
22534
  const pages = doc.getPages();
22060
22535
  let stamped = 0;
22061
22536
  for (const s of stamps) {
@@ -22063,76 +22538,44 @@ async function stampPdfText(bytes, stamps) {
22063
22538
  if (!pg)
22064
22539
  continue;
22065
22540
  const g = s.grey ?? 0;
22066
- pg.drawText(String(s.text), { x: s.x, y: s.y, size: s.size ?? 11, font, color: (0, import_pdf_lib.rgb)(g, g, g) });
22541
+ pg.drawText(String(s.text), { x: s.x, y: s.y, size: s.size ?? 11, font, color: (0, import_pdf_lib3.rgb)(g, g, g) });
22067
22542
  stamped++;
22068
22543
  }
22069
22544
  return { bytes: await doc.save(), stamped };
22070
22545
  }
22071
- async function watermarkPdf(bytes, text) {
22072
- const doc = await import_pdf_lib.PDFDocument.load(bytes);
22073
- const font = await doc.embedFont(import_pdf_lib.StandardFonts.HelveticaBold);
22546
+ async function watermarkPdf(bytes, text, opts = {}) {
22547
+ const doc = await loadEditablePdf(bytes);
22548
+ const font = await embedTextFont(doc, [text], { ...opts, weight: "bold" });
22074
22549
  const size = 48;
22550
+ const angle = Math.PI / 4;
22551
+ const halfW = font.widthOfTextAtSize(text, size) / 2;
22552
+ const halfH = font.heightAtSize(size, { descender: false }) / 2;
22553
+ const dx = halfW * Math.cos(angle) - halfH * Math.sin(angle);
22554
+ const dy = halfW * Math.sin(angle) + halfH * Math.cos(angle);
22075
22555
  for (const pg of doc.getPages()) {
22076
- const { width, height } = pg.getSize();
22556
+ const box = pg.getMediaBox();
22077
22557
  pg.drawText(text, {
22078
- x: width / 2 - text.length * size / 4,
22079
- y: height / 2,
22558
+ x: box.x + box.width / 2 - dx,
22559
+ y: box.y + box.height / 2 - dy,
22080
22560
  size,
22081
22561
  font,
22082
- color: (0, import_pdf_lib.rgb)(0.6, 0.6, 0.6),
22562
+ color: (0, import_pdf_lib3.rgb)(0.6, 0.6, 0.6),
22083
22563
  opacity: 0.3,
22084
- rotate: (0, import_pdf_lib.degrees)(45)
22564
+ rotate: (0, import_pdf_lib3.degrees)(45)
22085
22565
  });
22086
22566
  }
22087
22567
  return doc.save();
22088
22568
  }
22089
22569
 
22090
- // packages/core/dist/document/pdf-extract.js
22091
- var import_node_path = require("node:path");
22092
- var import_node_url = require("node:url");
22093
- var _mupdf = null;
22094
- function loadMupdf() {
22095
- if (!_mupdf) {
22096
- const deps = process.env.TALOS_SKILL_DEPS;
22097
- const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
22098
- _mupdf = import(spec);
22099
- }
22100
- return _mupdf;
22101
- }
22102
- async function openDoc(bytes) {
22103
- const mupdf = await loadMupdf();
22104
- const doc = mupdf.Document.openDocument(bytes, "application/pdf");
22105
- if (doc.countPages() === 0) {
22106
- throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
22107
- }
22108
- return { mupdf, doc };
22109
- }
22110
- async function encryptPdf(bytes, userPassword, ownerPassword) {
22111
- if (!userPassword)
22112
- throw new Error("a non-empty user password is required");
22113
- const { doc } = await openDoc(bytes);
22114
- const opts = `encrypt=aes-256,user-password=${userPassword},owner-password=${ownerPassword || userPassword}`;
22115
- return doc.saveToBuffer(opts).asUint8Array();
22116
- }
22117
- async function decryptPdf(bytes, password) {
22118
- const mupdf = await loadMupdf();
22119
- const doc = mupdf.Document.openDocument(bytes, "application/pdf");
22120
- if (doc.needsPassword()) {
22121
- if (doc.authenticatePassword(password) === 0)
22122
- throw new Error("wrong password");
22123
- }
22124
- if (doc.countPages() === 0)
22125
- throw new Error("PDF has no readable pages (corrupt or empty)");
22126
- return doc.saveToBuffer("encrypt=none").asUint8Array();
22127
- }
22128
-
22129
22570
  // apps/admin/data/skills.lib/document/bin-src/pdf-ops.mjs
22571
+ init_pdf_extract();
22572
+ var fontDir = (0, import_node_path3.join)(__dirname, "..", "assets", "pdf-fonts");
22130
22573
  function die(msg, code = 1) {
22131
22574
  process.stderr.write(`pdf-ops: ${msg}
22132
22575
  `);
22133
22576
  process.exit(code);
22134
22577
  }
22135
- var load = async (p) => new Uint8Array(await (0, import_promises.readFile)(p).catch((e) => die(`cannot read ${p}: ${e.message}`)));
22578
+ var load = async (p) => new Uint8Array(await (0, import_promises2.readFile)(p).catch((e) => die(`cannot read ${p}: ${e.message}`)));
22136
22579
  function parsePages(spec) {
22137
22580
  const out = [];
22138
22581
  for (const part of spec.split(",")) {
@@ -22151,7 +22594,7 @@ async function main() {
22151
22594
  const [out, ...ins] = rest;
22152
22595
  if (!out || ins.length < 1) die("usage: pdf-ops merge <out.pdf> <in1.pdf> ...", 64);
22153
22596
  const bytes = await mergePdfs(await Promise.all(ins.map(load)));
22154
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22597
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22155
22598
  process.stdout.write(`merged ${ins.length} \u2192 ${out}
22156
22599
  `);
22157
22600
  return;
@@ -22161,7 +22604,7 @@ async function main() {
22161
22604
  if (!inPdf || !range || !out) die("usage: pdf-ops split <in.pdf> <from-to> <out.pdf>", 64);
22162
22605
  const m = /^(\d+)-(\d+)$/.exec(range) || die(`bad range: ${range} (use from-to)`, 64);
22163
22606
  const bytes = await splitPdf(await load(inPdf), Number(m[1]), Number(m[2]));
22164
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22607
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22165
22608
  process.stdout.write(`wrote ${out}
22166
22609
  `);
22167
22610
  return;
@@ -22170,7 +22613,7 @@ async function main() {
22170
22613
  const [inPdf, deg, out, pages] = rest;
22171
22614
  if (!inPdf || !deg || !out) die("usage: pdf-ops rotate <in.pdf> <deg> <out.pdf> [pages]", 64);
22172
22615
  const bytes = await rotatePdf(await load(inPdf), Number(deg), pages ? parsePages(pages) : void 0);
22173
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22616
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22174
22617
  process.stdout.write(`wrote ${out}
22175
22618
  `);
22176
22619
  return;
@@ -22178,8 +22621,8 @@ async function main() {
22178
22621
  if (mode === "watermark") {
22179
22622
  const [inPdf, text, out] = rest;
22180
22623
  if (!inPdf || !text || !out) die("usage: pdf-ops watermark <in.pdf> <text> <out.pdf>", 64);
22181
- const bytes = await watermarkPdf(await load(inPdf), text);
22182
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22624
+ const bytes = await watermarkPdf(await load(inPdf), text, { fontDir });
22625
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22183
22626
  process.stdout.write(`wrote ${out}
22184
22627
  `);
22185
22628
  return;
@@ -22189,13 +22632,13 @@ async function main() {
22189
22632
  if (!inPdf || !stampsPath || !out) die("usage: pdf-ops stamp <in.pdf> <stamps.json> <out.pdf>", 64);
22190
22633
  let stamps;
22191
22634
  try {
22192
- stamps = JSON.parse(await (0, import_promises.readFile)(stampsPath, "utf8"));
22635
+ stamps = JSON.parse(await (0, import_promises2.readFile)(stampsPath, "utf8"));
22193
22636
  } catch (e) {
22194
22637
  die(`bad stamps json: ${e.message}`, 64);
22195
22638
  }
22196
22639
  if (!Array.isArray(stamps)) die("stamps json must be an array of {page,x,y,text}", 64);
22197
- const r = await stampPdfText(await load(inPdf), stamps);
22198
- await (0, import_promises.writeFile)(out, Buffer.from(r.bytes));
22640
+ const r = await stampPdfText(await load(inPdf), stamps, { fontDir });
22641
+ await (0, import_promises2.writeFile)(out, Buffer.from(r.bytes));
22199
22642
  process.stdout.write(JSON.stringify({ ok: true, out, stamped: r.stamped }) + "\n");
22200
22643
  return;
22201
22644
  }
@@ -22203,15 +22646,15 @@ async function main() {
22203
22646
  const [inPdf, out, userPw, ownerPw] = rest;
22204
22647
  if (!inPdf || !out || !userPw) die("usage: pdf-ops encrypt <in.pdf> <out.pdf> <user-password> [owner-password]", 64);
22205
22648
  const bytes = await encryptPdf(await load(inPdf), userPw, ownerPw);
22206
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22649
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22207
22650
  process.stdout.write(JSON.stringify({ ok: true, out, encryption: "aes-256" }) + "\n");
22208
22651
  return;
22209
22652
  }
22210
22653
  if (mode === "decrypt") {
22211
22654
  const [inPdf, pw, out] = rest;
22212
- if (!inPdf || !pw || !out) die("usage: pdf-ops decrypt <in.pdf> <password> <out.pdf>", 64);
22655
+ if (!inPdf || pw === void 0 || !out) die("usage: pdf-ops decrypt <in.pdf> <password> <out.pdf>", 64);
22213
22656
  const bytes = await decryptPdf(await load(inPdf), pw);
22214
- await (0, import_promises.writeFile)(out, Buffer.from(bytes));
22657
+ await (0, import_promises2.writeFile)(out, Buffer.from(bytes));
22215
22658
  process.stdout.write(JSON.stringify({ ok: true, out, encryption: "none" }) + "\n");
22216
22659
  return;
22217
22660
  }