@taloswork/ose-shared 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/skills/document/SKILL.md +143 -215
- package/skills/document/art-directions/base.css +27 -2
- package/skills/document/art-directions/cinematic-depth.css +3 -1
- package/skills/document/art-directions/collage-paper.css +5 -1
- package/skills/document/art-directions/editorial-cut.css +5 -1
- package/skills/document/art-directions/geometric-pop.css +6 -0
- package/skills/document/art-directions/gradient-mesh.css +5 -1
- package/skills/document/art-directions/illustrated-doodle.css +5 -0
- package/skills/document/art-directions/luxury-ornament.css +4 -1
- package/skills/document/art-directions/maximalist-blocks.css +6 -0
- package/skills/document/art-directions/technical-grid.css +4 -0
- package/skills/document/assets/fonts/fonts.json +2 -2
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
- package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
- package/skills/document/assets/pdf-fonts/README.md +35 -0
- package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
- package/skills/document/assets/tessdata/README.md +21 -0
- package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
- package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
- package/skills/document/bin/deck-build.cjs +2311 -41
- package/skills/document/bin/deck-chart.cjs +762 -0
- package/skills/document/bin/deck-plan.cjs +802 -0
- package/skills/document/bin/deck-qa.cjs +984 -249
- package/skills/document/bin/deck-scenario.cjs +1346 -0
- package/skills/document/bin/doc-convert.cjs +130 -39
- package/skills/document/bin/doc-fill.cjs +73121 -170
- package/skills/document/bin/doc-gen.cjs +625 -68
- package/skills/document/bin/doc-run.cjs +162 -24
- package/skills/document/bin/doc-scan.cjs +13 -0
- package/skills/document/bin/doc-text.cjs +13 -0
- package/skills/document/bin/doc-validate.cjs +718 -23
- package/skills/document/bin/doc-xml.cjs +9 -5
- package/skills/document/bin/docx-annotate.cjs +95 -19
- package/skills/document/bin/fontkit.cjs +1 -0
- package/skills/document/bin/html2pptx.cjs +1372 -121
- package/skills/document/bin/ocr-worker.cjs +1 -0
- package/skills/document/bin/ocr.cjs +131 -40
- package/skills/document/bin/pdf-form.cjs +674 -177
- package/skills/document/bin/pdf-images.cjs +13 -0
- package/skills/document/bin/pdf-ops.cjs +634 -199
- package/skills/document/bin/pdf-render.cjs +19 -3
- package/skills/document/bin/pdf-tables.cjs +13 -0
- package/skills/document/bin/pptx-clone.cjs +3 -3
- package/skills/document/bin/pptx-slide.cjs +3 -3
- package/skills/document/bin/xlsx-query.cjs +192 -61
- package/skills/document/bin-reference.md +56 -33
- package/skills/document/content-pipeline.md +129 -242
- package/skills/document/deck-design.md +355 -638
- package/skills/document/layouts/README.md +46 -33
- package/skills/document/layouts/capacity.json +1 -0
- package/skills/document/layouts/slots.json +1 -1
- package/skills/document/layouts/toc-panel.tpl +1 -1
- package/skills/document/motion/README.md +3 -2
- package/skills/document/office.md +3 -3
- package/skills/document/packs/board-brief/backdrop.html +2 -0
- package/skills/document/packs/board-brief/pack.css +2 -1
- package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
- package/skills/document/packs/mckinsey-photo/pack.css +2 -1
- package/skills/document/packs/press-room/backdrop.html +2 -0
- package/skills/document/packs/press-room/pack.css +2 -1
- package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
- package/skills/document/packs/prismatic-3d/pack.css +4 -1
- package/skills/document/pdf.md +53 -49
- package/skills/document/rewrite.md +241 -308
- package/skills/document/scenarios.json +1290 -0
- package/skills/document/scenarios.schema.json +103 -0
- package/skills/document/styles/README.md +15 -25
- package/skills/document/styles/_contract-defaults.css +25 -1
- package/skills/document/styles/anthropic/skin.css +6 -3
- package/skills/document/styles/apple/skin.css +4 -3
- package/skills/document/styles/bistro-warm/backdrop.html +2 -0
- package/skills/document/styles/bistro-warm/skin.css +4 -1
- package/skills/document/styles/black-gold/skin.css +6 -5
- package/skills/document/styles/bold-clash/backdrop.html +2 -0
- package/skills/document/styles/bold-clash/skin.css +2 -1
- package/skills/document/styles/branding/skin.css +4 -4
- package/skills/document/styles/campus-teal/backdrop.html +2 -0
- package/skills/document/styles/campus-teal/skin.css +2 -1
- package/skills/document/styles/cinereel/skin.css +7 -3
- package/skills/document/styles/clinic-care/backdrop.html +2 -0
- package/skills/document/styles/clinic-care/skin.css +2 -1
- package/skills/document/styles/cool/skin.css +6 -5
- package/skills/document/styles/dark-glass/backdrop.html +2 -0
- package/skills/document/styles/dark-glass/skin.css +2 -1
- package/skills/document/styles/gov-brief/backdrop.html +2 -0
- package/skills/document/styles/gov-brief/skin.css +2 -1
- package/skills/document/styles/grid-tech/backdrop.html +2 -0
- package/skills/document/styles/grid-tech/skin.css +2 -1
- package/skills/document/styles/hand-drawn/skin.css +3 -3
- package/skills/document/styles/ivory-gold/skin.css +7 -6
- package/skills/document/styles/legal-slate/backdrop.html +2 -0
- package/skills/document/styles/legal-slate/skin.css +2 -1
- package/skills/document/styles/magazine-ink/skin.css +4 -3
- package/skills/document/styles/mckinsey/skin.css +2 -1
- package/skills/document/styles/memphis/backdrop.html +2 -0
- package/skills/document/styles/memphis/skin.css +2 -1
- package/skills/document/styles/mono/skin.css +6 -2
- package/skills/document/styles/neon-cyber/backdrop.html +2 -0
- package/skills/document/styles/neon-cyber/skin.css +2 -1
- package/skills/document/styles/olive-gold/skin.css +7 -6
- package/skills/document/styles/organic-earth/backdrop.html +2 -0
- package/skills/document/styles/organic-earth/skin.css +2 -1
- package/skills/document/styles/pastel-saas/backdrop.html +2 -0
- package/skills/document/styles/pastel-saas/skin.css +2 -1
- package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
- package/skills/document/styles/portfolio-noir/skin.css +2 -1
- package/skills/document/styles/retro-press/backdrop.html +2 -0
- package/skills/document/styles/retro-press/skin.css +2 -1
- package/skills/document/styles/sport-arena/backdrop.html +2 -0
- package/skills/document/styles/sport-arena/skin.css +4 -1
- package/skills/document/styles/swiss-grid/skin.css +10 -5
- package/skills/document/styles/wedding-blush/backdrop.html +2 -0
- package/skills/document/styles/wedding-blush/skin.css +4 -1
- package/skills/document/theme-system.md +85 -77
- package/skills/document/themes/README.md +7 -5
- package/skills/document/vision.md +8 -5
- package/skills/document/xlsx.md +15 -25
- package/skills/cozy-static-svg/SKILL.md +0 -76
- package/skills/cozy-static-svg/references/approved-preview.png +0 -0
- package/skills/cozy-static-svg/references/cross-platform.md +0 -73
- package/skills/cozy-static-svg/references/moon_keeps_watch.svg +0 -229
- package/skills/cozy-static-svg/references/style-anchor.md +0 -271
- package/skills/cozy-static-svg/scripts/artkit.py +0 -321
- package/skills/cozy-static-svg/scripts/to_png.py +0 -333
|
@@ -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
|
|
747
|
-
if (
|
|
748
|
-
var byte1 =
|
|
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 (
|
|
752
|
-
var byte1 =
|
|
753
|
-
var byte2 =
|
|
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 (
|
|
757
|
-
var byte1 =
|
|
758
|
-
var byte2 =
|
|
759
|
-
var byte3 =
|
|
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 (
|
|
763
|
-
var byte1 =
|
|
764
|
-
var byte2 =
|
|
765
|
-
var byte3 =
|
|
766
|
-
var byte4 =
|
|
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(
|
|
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
|
|
783
|
-
if (
|
|
784
|
-
encoded.push(
|
|
782
|
+
var codePoint2 = input.codePointAt(idx);
|
|
783
|
+
if (codePoint2 < 65536) {
|
|
784
|
+
encoded.push(codePoint2);
|
|
785
785
|
idx += 1;
|
|
786
|
-
} else if (
|
|
787
|
-
encoded.push(exports2.highSurrogate(
|
|
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(
|
|
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(
|
|
795
|
-
return
|
|
794
|
+
exports2.isWithinBMP = function(codePoint2) {
|
|
795
|
+
return codePoint2 >= 0 && codePoint2 <= 65535;
|
|
796
796
|
};
|
|
797
|
-
exports2.hasSurrogates = function(
|
|
798
|
-
return
|
|
797
|
+
exports2.hasSurrogates = function(codePoint2) {
|
|
798
|
+
return codePoint2 >= 65536 && codePoint2 <= 1114111;
|
|
799
799
|
};
|
|
800
|
-
exports2.highSurrogate = function(
|
|
801
|
-
return Math.floor((
|
|
800
|
+
exports2.highSurrogate = function(codePoint2) {
|
|
801
|
+
return Math.floor((codePoint2 - 65536) / 1024) + 55296;
|
|
802
802
|
};
|
|
803
|
-
exports2.lowSurrogate = function(
|
|
804
|
-
return (
|
|
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(
|
|
846
|
-
return
|
|
845
|
+
var isHighSurrogate = function(codePoint2) {
|
|
846
|
+
return codePoint2 >= 55296 && codePoint2 <= 56319;
|
|
847
847
|
};
|
|
848
|
-
var isLowSurrogate = function(
|
|
849
|
-
return
|
|
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(
|
|
5431
|
-
return
|
|
5430
|
+
this.canEncodeUnicodeCodePoint = function(codePoint2) {
|
|
5431
|
+
return codePoint2 in _this.unicodeMappings;
|
|
5432
5432
|
};
|
|
5433
|
-
this.encodeUnicodeCodePoint = function(
|
|
5434
|
-
var mapped = _this.unicodeMappings[
|
|
5433
|
+
this.encodeUnicodeCodePoint = function(codePoint2) {
|
|
5434
|
+
var mapped = _this.unicodeMappings[codePoint2];
|
|
5435
5435
|
if (!mapped) {
|
|
5436
|
-
var str = String.fromCharCode(
|
|
5437
|
-
var hexCode = "0x" + utils_1.padStart(
|
|
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
|
}
|
|
@@ -6416,39 +6416,39 @@ var require_PDFArray = __commonJS({
|
|
|
6416
6416
|
var PDFObject_1 = tslib_1.__importDefault(require_PDFObject());
|
|
6417
6417
|
var CharCodes_1 = tslib_1.__importDefault(require_CharCodes());
|
|
6418
6418
|
var errors_1 = require_errors2();
|
|
6419
|
-
var
|
|
6419
|
+
var PDFArray2 = (
|
|
6420
6420
|
/** @class */
|
|
6421
6421
|
(function(_super) {
|
|
6422
|
-
tslib_1.__extends(
|
|
6423
|
-
function
|
|
6422
|
+
tslib_1.__extends(PDFArray3, _super);
|
|
6423
|
+
function PDFArray3(context) {
|
|
6424
6424
|
var _this = _super.call(this) || this;
|
|
6425
6425
|
_this.array = [];
|
|
6426
6426
|
_this.context = context;
|
|
6427
6427
|
return _this;
|
|
6428
6428
|
}
|
|
6429
|
-
|
|
6429
|
+
PDFArray3.prototype.size = function() {
|
|
6430
6430
|
return this.array.length;
|
|
6431
6431
|
};
|
|
6432
|
-
|
|
6432
|
+
PDFArray3.prototype.push = function(object) {
|
|
6433
6433
|
this.array.push(object);
|
|
6434
6434
|
};
|
|
6435
|
-
|
|
6435
|
+
PDFArray3.prototype.insert = function(index, object) {
|
|
6436
6436
|
this.array.splice(index, 0, object);
|
|
6437
6437
|
};
|
|
6438
|
-
|
|
6438
|
+
PDFArray3.prototype.indexOf = function(object) {
|
|
6439
6439
|
var index = this.array.indexOf(object);
|
|
6440
6440
|
return index === -1 ? void 0 : index;
|
|
6441
6441
|
};
|
|
6442
|
-
|
|
6442
|
+
PDFArray3.prototype.remove = function(index) {
|
|
6443
6443
|
this.array.splice(index, 1);
|
|
6444
6444
|
};
|
|
6445
|
-
|
|
6445
|
+
PDFArray3.prototype.set = function(idx, object) {
|
|
6446
6446
|
this.array[idx] = object;
|
|
6447
6447
|
};
|
|
6448
|
-
|
|
6448
|
+
PDFArray3.prototype.get = function(index) {
|
|
6449
6449
|
return this.array[index];
|
|
6450
6450
|
};
|
|
6451
|
-
|
|
6451
|
+
PDFArray3.prototype.lookupMaybe = function(index) {
|
|
6452
6452
|
var _a;
|
|
6453
6453
|
var types = [];
|
|
6454
6454
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -6456,7 +6456,7 @@ var require_PDFArray = __commonJS({
|
|
|
6456
6456
|
}
|
|
6457
6457
|
return (_a = this.context).lookupMaybe.apply(_a, tslib_1.__spreadArrays([this.get(index)], types));
|
|
6458
6458
|
};
|
|
6459
|
-
|
|
6459
|
+
PDFArray3.prototype.lookup = function(index) {
|
|
6460
6460
|
var _a;
|
|
6461
6461
|
var types = [];
|
|
6462
6462
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -6464,7 +6464,7 @@ var require_PDFArray = __commonJS({
|
|
|
6464
6464
|
}
|
|
6465
6465
|
return (_a = this.context).lookup.apply(_a, tslib_1.__spreadArrays([this.get(index)], types));
|
|
6466
6466
|
};
|
|
6467
|
-
|
|
6467
|
+
PDFArray3.prototype.asRectangle = function() {
|
|
6468
6468
|
if (this.size() !== 4)
|
|
6469
6469
|
throw new errors_1.PDFArrayIsNotRectangleError(this.size());
|
|
6470
6470
|
var lowerLeftX = this.lookup(0, PDFNumber_1.default).asNumber();
|
|
@@ -6477,17 +6477,17 @@ var require_PDFArray = __commonJS({
|
|
|
6477
6477
|
var height = upperRightY - lowerLeftY;
|
|
6478
6478
|
return { x, y, width, height };
|
|
6479
6479
|
};
|
|
6480
|
-
|
|
6480
|
+
PDFArray3.prototype.asArray = function() {
|
|
6481
6481
|
return this.array.slice();
|
|
6482
6482
|
};
|
|
6483
|
-
|
|
6484
|
-
var clone =
|
|
6483
|
+
PDFArray3.prototype.clone = function(context) {
|
|
6484
|
+
var clone = PDFArray3.withContext(context || this.context);
|
|
6485
6485
|
for (var idx = 0, len = this.size(); idx < len; idx++) {
|
|
6486
6486
|
clone.push(this.array[idx]);
|
|
6487
6487
|
}
|
|
6488
6488
|
return clone;
|
|
6489
6489
|
};
|
|
6490
|
-
|
|
6490
|
+
PDFArray3.prototype.toString = function() {
|
|
6491
6491
|
var arrayString = "[ ";
|
|
6492
6492
|
for (var idx = 0, len = this.size(); idx < len; idx++) {
|
|
6493
6493
|
arrayString += this.get(idx).toString();
|
|
@@ -6496,14 +6496,14 @@ var require_PDFArray = __commonJS({
|
|
|
6496
6496
|
arrayString += "]";
|
|
6497
6497
|
return arrayString;
|
|
6498
6498
|
};
|
|
6499
|
-
|
|
6499
|
+
PDFArray3.prototype.sizeInBytes = function() {
|
|
6500
6500
|
var size = 3;
|
|
6501
6501
|
for (var idx = 0, len = this.size(); idx < len; idx++) {
|
|
6502
6502
|
size += this.get(idx).sizeInBytes() + 1;
|
|
6503
6503
|
}
|
|
6504
6504
|
return size;
|
|
6505
6505
|
};
|
|
6506
|
-
|
|
6506
|
+
PDFArray3.prototype.copyBytesInto = function(buffer, offset) {
|
|
6507
6507
|
var initialOffset = offset;
|
|
6508
6508
|
buffer[offset++] = CharCodes_1.default.LeftSquareBracket;
|
|
6509
6509
|
buffer[offset++] = CharCodes_1.default.Space;
|
|
@@ -6514,7 +6514,7 @@ var require_PDFArray = __commonJS({
|
|
|
6514
6514
|
buffer[offset++] = CharCodes_1.default.RightSquareBracket;
|
|
6515
6515
|
return offset - initialOffset;
|
|
6516
6516
|
};
|
|
6517
|
-
|
|
6517
|
+
PDFArray3.prototype.scalePDFNumbers = function(x, y) {
|
|
6518
6518
|
for (var idx = 0, len = this.size(); idx < len; idx++) {
|
|
6519
6519
|
var el = this.lookup(idx);
|
|
6520
6520
|
if (el instanceof PDFNumber_1.default) {
|
|
@@ -6523,13 +6523,13 @@ var require_PDFArray = __commonJS({
|
|
|
6523
6523
|
}
|
|
6524
6524
|
}
|
|
6525
6525
|
};
|
|
6526
|
-
|
|
6527
|
-
return new
|
|
6526
|
+
PDFArray3.withContext = function(context) {
|
|
6527
|
+
return new PDFArray3(context);
|
|
6528
6528
|
};
|
|
6529
|
-
return
|
|
6529
|
+
return PDFArray3;
|
|
6530
6530
|
})(PDFObject_1.default)
|
|
6531
6531
|
);
|
|
6532
|
-
exports2.default =
|
|
6532
|
+
exports2.default = PDFArray2;
|
|
6533
6533
|
}
|
|
6534
6534
|
});
|
|
6535
6535
|
|
|
@@ -6673,11 +6673,11 @@ var require_PDFName = __commonJS({
|
|
|
6673
6673
|
};
|
|
6674
6674
|
var ENFORCER = {};
|
|
6675
6675
|
var pool = /* @__PURE__ */ new Map();
|
|
6676
|
-
var
|
|
6676
|
+
var PDFName2 = (
|
|
6677
6677
|
/** @class */
|
|
6678
6678
|
(function(_super) {
|
|
6679
|
-
tslib_1.__extends(
|
|
6680
|
-
function
|
|
6679
|
+
tslib_1.__extends(PDFName3, _super);
|
|
6680
|
+
function PDFName3(enforcer, name) {
|
|
6681
6681
|
var _this = this;
|
|
6682
6682
|
if (enforcer !== ENFORCER)
|
|
6683
6683
|
throw new errors_1.PrivateConstructorError("PDFName");
|
|
@@ -6691,7 +6691,7 @@ var require_PDFName = __commonJS({
|
|
|
6691
6691
|
_this.encodedName = encodedName;
|
|
6692
6692
|
return _this;
|
|
6693
6693
|
}
|
|
6694
|
-
|
|
6694
|
+
PDFName3.prototype.asBytes = function() {
|
|
6695
6695
|
var bytes = [];
|
|
6696
6696
|
var hex = "";
|
|
6697
6697
|
var escaped = false;
|
|
@@ -6723,67 +6723,67 @@ var require_PDFName = __commonJS({
|
|
|
6723
6723
|
}
|
|
6724
6724
|
return new Uint8Array(bytes);
|
|
6725
6725
|
};
|
|
6726
|
-
|
|
6726
|
+
PDFName3.prototype.decodeText = function() {
|
|
6727
6727
|
var bytes = this.asBytes();
|
|
6728
6728
|
return String.fromCharCode.apply(String, Array.from(bytes));
|
|
6729
6729
|
};
|
|
6730
|
-
|
|
6730
|
+
PDFName3.prototype.asString = function() {
|
|
6731
6731
|
return this.encodedName;
|
|
6732
6732
|
};
|
|
6733
|
-
|
|
6733
|
+
PDFName3.prototype.value = function() {
|
|
6734
6734
|
return this.encodedName;
|
|
6735
6735
|
};
|
|
6736
|
-
|
|
6736
|
+
PDFName3.prototype.clone = function() {
|
|
6737
6737
|
return this;
|
|
6738
6738
|
};
|
|
6739
|
-
|
|
6739
|
+
PDFName3.prototype.toString = function() {
|
|
6740
6740
|
return this.encodedName;
|
|
6741
6741
|
};
|
|
6742
|
-
|
|
6742
|
+
PDFName3.prototype.sizeInBytes = function() {
|
|
6743
6743
|
return this.encodedName.length;
|
|
6744
6744
|
};
|
|
6745
|
-
|
|
6745
|
+
PDFName3.prototype.copyBytesInto = function(buffer, offset) {
|
|
6746
6746
|
offset += utils_1.copyStringIntoBuffer(this.encodedName, buffer, offset);
|
|
6747
6747
|
return this.encodedName.length;
|
|
6748
6748
|
};
|
|
6749
|
-
|
|
6749
|
+
PDFName3.of = function(name) {
|
|
6750
6750
|
var decodedValue = decodeName(name);
|
|
6751
6751
|
var instance = pool.get(decodedValue);
|
|
6752
6752
|
if (!instance) {
|
|
6753
|
-
instance = new
|
|
6753
|
+
instance = new PDFName3(ENFORCER, decodedValue);
|
|
6754
6754
|
pool.set(decodedValue, instance);
|
|
6755
6755
|
}
|
|
6756
6756
|
return instance;
|
|
6757
6757
|
};
|
|
6758
|
-
|
|
6759
|
-
|
|
6760
|
-
|
|
6761
|
-
|
|
6762
|
-
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
|
|
6776
|
-
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6780
|
-
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
return
|
|
6758
|
+
PDFName3.Length = PDFName3.of("Length");
|
|
6759
|
+
PDFName3.FlateDecode = PDFName3.of("FlateDecode");
|
|
6760
|
+
PDFName3.Resources = PDFName3.of("Resources");
|
|
6761
|
+
PDFName3.Font = PDFName3.of("Font");
|
|
6762
|
+
PDFName3.XObject = PDFName3.of("XObject");
|
|
6763
|
+
PDFName3.ExtGState = PDFName3.of("ExtGState");
|
|
6764
|
+
PDFName3.Contents = PDFName3.of("Contents");
|
|
6765
|
+
PDFName3.Type = PDFName3.of("Type");
|
|
6766
|
+
PDFName3.Parent = PDFName3.of("Parent");
|
|
6767
|
+
PDFName3.MediaBox = PDFName3.of("MediaBox");
|
|
6768
|
+
PDFName3.Page = PDFName3.of("Page");
|
|
6769
|
+
PDFName3.Annots = PDFName3.of("Annots");
|
|
6770
|
+
PDFName3.TrimBox = PDFName3.of("TrimBox");
|
|
6771
|
+
PDFName3.ArtBox = PDFName3.of("ArtBox");
|
|
6772
|
+
PDFName3.BleedBox = PDFName3.of("BleedBox");
|
|
6773
|
+
PDFName3.CropBox = PDFName3.of("CropBox");
|
|
6774
|
+
PDFName3.Rotate = PDFName3.of("Rotate");
|
|
6775
|
+
PDFName3.Title = PDFName3.of("Title");
|
|
6776
|
+
PDFName3.Author = PDFName3.of("Author");
|
|
6777
|
+
PDFName3.Subject = PDFName3.of("Subject");
|
|
6778
|
+
PDFName3.Creator = PDFName3.of("Creator");
|
|
6779
|
+
PDFName3.Keywords = PDFName3.of("Keywords");
|
|
6780
|
+
PDFName3.Producer = PDFName3.of("Producer");
|
|
6781
|
+
PDFName3.CreationDate = PDFName3.of("CreationDate");
|
|
6782
|
+
PDFName3.ModDate = PDFName3.of("ModDate");
|
|
6783
|
+
return PDFName3;
|
|
6784
6784
|
})(PDFObject_1.default)
|
|
6785
6785
|
);
|
|
6786
|
-
exports2.default =
|
|
6786
|
+
exports2.default = PDFName2;
|
|
6787
6787
|
}
|
|
6788
6788
|
});
|
|
6789
6789
|
|
|
@@ -7108,11 +7108,11 @@ var require_PDFRef = __commonJS({
|
|
|
7108
7108
|
var utils_1 = require_utils2();
|
|
7109
7109
|
var ENFORCER = {};
|
|
7110
7110
|
var pool = /* @__PURE__ */ new Map();
|
|
7111
|
-
var
|
|
7111
|
+
var PDFRef2 = (
|
|
7112
7112
|
/** @class */
|
|
7113
7113
|
(function(_super) {
|
|
7114
|
-
tslib_1.__extends(
|
|
7115
|
-
function
|
|
7114
|
+
tslib_1.__extends(PDFRef3, _super);
|
|
7115
|
+
function PDFRef3(enforcer, objectNumber, generationNumber) {
|
|
7116
7116
|
var _this = this;
|
|
7117
7117
|
if (enforcer !== ENFORCER)
|
|
7118
7118
|
throw new errors_1.PrivateConstructorError("PDFRef");
|
|
@@ -7122,35 +7122,35 @@ var require_PDFRef = __commonJS({
|
|
|
7122
7122
|
_this.tag = objectNumber + " " + generationNumber + " R";
|
|
7123
7123
|
return _this;
|
|
7124
7124
|
}
|
|
7125
|
-
|
|
7125
|
+
PDFRef3.prototype.clone = function() {
|
|
7126
7126
|
return this;
|
|
7127
7127
|
};
|
|
7128
|
-
|
|
7128
|
+
PDFRef3.prototype.toString = function() {
|
|
7129
7129
|
return this.tag;
|
|
7130
7130
|
};
|
|
7131
|
-
|
|
7131
|
+
PDFRef3.prototype.sizeInBytes = function() {
|
|
7132
7132
|
return this.tag.length;
|
|
7133
7133
|
};
|
|
7134
|
-
|
|
7134
|
+
PDFRef3.prototype.copyBytesInto = function(buffer, offset) {
|
|
7135
7135
|
offset += utils_1.copyStringIntoBuffer(this.tag, buffer, offset);
|
|
7136
7136
|
return this.tag.length;
|
|
7137
7137
|
};
|
|
7138
|
-
|
|
7138
|
+
PDFRef3.of = function(objectNumber, generationNumber) {
|
|
7139
7139
|
if (generationNumber === void 0) {
|
|
7140
7140
|
generationNumber = 0;
|
|
7141
7141
|
}
|
|
7142
7142
|
var tag = objectNumber + " " + generationNumber + " R";
|
|
7143
7143
|
var instance = pool.get(tag);
|
|
7144
7144
|
if (!instance) {
|
|
7145
|
-
instance = new
|
|
7145
|
+
instance = new PDFRef3(ENFORCER, objectNumber, generationNumber);
|
|
7146
7146
|
pool.set(tag, instance);
|
|
7147
7147
|
}
|
|
7148
7148
|
return instance;
|
|
7149
7149
|
};
|
|
7150
|
-
return
|
|
7150
|
+
return PDFRef3;
|
|
7151
7151
|
})(PDFObject_1.default)
|
|
7152
7152
|
);
|
|
7153
|
-
exports2.default =
|
|
7153
|
+
exports2.default = PDFRef2;
|
|
7154
7154
|
}
|
|
7155
7155
|
});
|
|
7156
7156
|
|
|
@@ -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
|
|
8867
|
+
var StandardFontEmbedder2 = (
|
|
8868
8868
|
/** @class */
|
|
8869
8869
|
(function() {
|
|
8870
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8929
|
+
StandardFontEmbedder3.prototype.widthOfGlyph = function(glyphName) {
|
|
8930
8930
|
return this.font.getWidthOfGlyph(glyphName) || 250;
|
|
8931
8931
|
};
|
|
8932
|
-
|
|
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
|
|
8937
|
-
glyphs[idx] = this.encoding.encodeUnicodeCodePoint(
|
|
8936
|
+
var codePoint2 = utils_1.toCodePoint(codePoints[idx]);
|
|
8937
|
+
glyphs[idx] = this.encoding.encodeUnicodeCodePoint(codePoint2);
|
|
8938
8938
|
}
|
|
8939
8939
|
return glyphs;
|
|
8940
8940
|
};
|
|
8941
|
-
|
|
8942
|
-
return new
|
|
8941
|
+
StandardFontEmbedder3.for = function(fontName, customName) {
|
|
8942
|
+
return new StandardFontEmbedder3(fontName, customName);
|
|
8943
8943
|
};
|
|
8944
|
-
return
|
|
8944
|
+
return StandardFontEmbedder3;
|
|
8945
8945
|
})()
|
|
8946
8946
|
);
|
|
8947
|
-
exports2.default =
|
|
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],
|
|
8972
|
-
return glyphId + " " +
|
|
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(
|
|
8986
|
-
if (unicode_1.isWithinBMP(
|
|
8987
|
-
return cmapHexString(
|
|
8988
|
-
if (unicode_1.hasSurrogates(
|
|
8989
|
-
var hs = unicode_1.highSurrogate(
|
|
8990
|
-
var ls = unicode_1.lowSurrogate(
|
|
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(
|
|
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
|
|
9186
|
-
glyphs[idx] = _this.font.glyphForCodePoint(
|
|
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
|
|
17460
|
+
var EncryptedPDFError2 = (
|
|
17461
17461
|
/** @class */
|
|
17462
17462
|
(function(_super) {
|
|
17463
|
-
tslib_1.__extends(
|
|
17464
|
-
function
|
|
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
|
|
17470
|
+
return EncryptedPDFError3;
|
|
17471
17471
|
})(Error)
|
|
17472
17472
|
);
|
|
17473
|
-
exports2.EncryptedPDFError =
|
|
17473
|
+
exports2.EncryptedPDFError = EncryptedPDFError2;
|
|
17474
17474
|
var FontkitNotRegisteredError = (
|
|
17475
17475
|
/** @class */
|
|
17476
17476
|
(function(_super) {
|
|
@@ -19729,23 +19729,23 @@ var require_StandardFonts = __commonJS({
|
|
|
19729
19729
|
"use strict";
|
|
19730
19730
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
19731
19731
|
exports2.StandardFonts = void 0;
|
|
19732
|
-
var
|
|
19733
|
-
(function(
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
|
|
19744
|
-
|
|
19745
|
-
|
|
19746
|
-
|
|
19747
|
-
|
|
19748
|
-
})(
|
|
19732
|
+
var StandardFonts2;
|
|
19733
|
+
(function(StandardFonts3) {
|
|
19734
|
+
StandardFonts3["Courier"] = "Courier";
|
|
19735
|
+
StandardFonts3["CourierBold"] = "Courier-Bold";
|
|
19736
|
+
StandardFonts3["CourierOblique"] = "Courier-Oblique";
|
|
19737
|
+
StandardFonts3["CourierBoldOblique"] = "Courier-BoldOblique";
|
|
19738
|
+
StandardFonts3["Helvetica"] = "Helvetica";
|
|
19739
|
+
StandardFonts3["HelveticaBold"] = "Helvetica-Bold";
|
|
19740
|
+
StandardFonts3["HelveticaOblique"] = "Helvetica-Oblique";
|
|
19741
|
+
StandardFonts3["HelveticaBoldOblique"] = "Helvetica-BoldOblique";
|
|
19742
|
+
StandardFonts3["TimesRoman"] = "Times-Roman";
|
|
19743
|
+
StandardFonts3["TimesRomanBold"] = "Times-Bold";
|
|
19744
|
+
StandardFonts3["TimesRomanItalic"] = "Times-Italic";
|
|
19745
|
+
StandardFonts3["TimesRomanBoldItalic"] = "Times-BoldItalic";
|
|
19746
|
+
StandardFonts3["Symbol"] = "Symbol";
|
|
19747
|
+
StandardFonts3["ZapfDingbats"] = "ZapfDingbats";
|
|
19748
|
+
})(StandardFonts2 = exports2.StandardFonts || (exports2.StandardFonts = {}));
|
|
19749
19749
|
}
|
|
19750
19750
|
});
|
|
19751
19751
|
|
|
@@ -22015,20 +22015,490 @@ 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
|
+
renderPdfPages: () => renderPdfPages,
|
|
22047
|
+
scanPdfSignals: () => scanPdfSignals,
|
|
22048
|
+
textMathHint: () => textMathHint,
|
|
22049
|
+
textTableHint: () => textTableHint
|
|
22050
|
+
});
|
|
22051
|
+
function loadMupdf() {
|
|
22052
|
+
if (!_mupdf) {
|
|
22053
|
+
const deps = process.env.TALOS_SKILL_DEPS;
|
|
22054
|
+
const spec = deps ? (0, import_node_url.pathToFileURL)((0, import_node_path.join)(deps, "mupdf", "dist", "mupdf.js")).href : "mupdf";
|
|
22055
|
+
_mupdf = import(spec);
|
|
22056
|
+
}
|
|
22057
|
+
return _mupdf;
|
|
22058
|
+
}
|
|
22059
|
+
function textMathHint(text) {
|
|
22060
|
+
if (!text)
|
|
22061
|
+
return false;
|
|
22062
|
+
const hits = (text.match(MATH_CHARS) || []).length;
|
|
22063
|
+
return hits >= 3 || hits / Math.max(text.length, 1) > 0.02;
|
|
22064
|
+
}
|
|
22065
|
+
function textTableHint(text) {
|
|
22066
|
+
if (!text)
|
|
22067
|
+
return false;
|
|
22068
|
+
const gaps = (text.match(/ {2,}|\t/g) || []).length;
|
|
22069
|
+
return gaps >= 6;
|
|
22070
|
+
}
|
|
22071
|
+
async function openDoc(bytes) {
|
|
22072
|
+
const mupdf = await loadMupdf();
|
|
22073
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
22074
|
+
if (doc.needsPassword())
|
|
22075
|
+
throw new PdfEncryptedError();
|
|
22076
|
+
if (doc.countPages() === 0) {
|
|
22077
|
+
throw new Error("PDF has no readable pages (corrupt, encrypted, or empty)");
|
|
22078
|
+
}
|
|
22079
|
+
return { mupdf, doc };
|
|
22080
|
+
}
|
|
22081
|
+
async function analyzePdfDocument(bytes, options = {}) {
|
|
22082
|
+
const wantText = options.text !== false;
|
|
22083
|
+
const wantSignals = options.signals === true;
|
|
22084
|
+
const { doc } = await openDoc(bytes);
|
|
22085
|
+
const pageCount = doc.countPages();
|
|
22086
|
+
const signals = [];
|
|
22087
|
+
let out = "";
|
|
22088
|
+
for (let i = 0; i < pageCount; i++) {
|
|
22089
|
+
const page = doc.loadPage(i);
|
|
22090
|
+
if (wantText) {
|
|
22091
|
+
out += `
|
|
22092
|
+
[page ${i + 1}]
|
|
22093
|
+
${page.toStructuredText().asText()}`;
|
|
22094
|
+
}
|
|
22095
|
+
if (wantSignals) {
|
|
22096
|
+
signals.push(pageSignalsFrom(page, i + 1));
|
|
22097
|
+
}
|
|
22098
|
+
}
|
|
22099
|
+
return { text: wantText ? out.trim() : "", pageCount, signals };
|
|
22100
|
+
}
|
|
22101
|
+
async function extractPdfText(bytes) {
|
|
22102
|
+
const { text, pageCount } = await analyzePdfDocument(bytes, { text: true });
|
|
22103
|
+
return { text, pageCount };
|
|
22104
|
+
}
|
|
22105
|
+
function countVectorOperators(content) {
|
|
22106
|
+
let ops = 0;
|
|
22107
|
+
let curves = 0;
|
|
22108
|
+
let fills = 0;
|
|
22109
|
+
let i = 0;
|
|
22110
|
+
const n = content.length;
|
|
22111
|
+
while (i < n) {
|
|
22112
|
+
const ch = content[i];
|
|
22113
|
+
if (ch === "(") {
|
|
22114
|
+
let depth = 1;
|
|
22115
|
+
i++;
|
|
22116
|
+
while (i < n && depth > 0) {
|
|
22117
|
+
if (content[i] === "\\")
|
|
22118
|
+
i++;
|
|
22119
|
+
else if (content[i] === "(")
|
|
22120
|
+
depth++;
|
|
22121
|
+
else if (content[i] === ")")
|
|
22122
|
+
depth--;
|
|
22123
|
+
i++;
|
|
22124
|
+
}
|
|
22125
|
+
continue;
|
|
22126
|
+
}
|
|
22127
|
+
if (ch === "<" && content[i + 1] !== "<") {
|
|
22128
|
+
while (i < n && content[i] !== ">")
|
|
22129
|
+
i++;
|
|
22130
|
+
i++;
|
|
22131
|
+
continue;
|
|
22132
|
+
}
|
|
22133
|
+
if (ch === "I" && content[i + 1] === "D" && isDelimiter(content[i + 2])) {
|
|
22134
|
+
const end = content.indexOf("EI", i + 2);
|
|
22135
|
+
i = end === -1 ? n : end + 2;
|
|
22136
|
+
continue;
|
|
22137
|
+
}
|
|
22138
|
+
if (!isDelimiter(ch)) {
|
|
22139
|
+
const start = i;
|
|
22140
|
+
while (i < n && !isDelimiter(content[i]))
|
|
22141
|
+
i++;
|
|
22142
|
+
const token = content.slice(start, i);
|
|
22143
|
+
switch (token) {
|
|
22144
|
+
case "m":
|
|
22145
|
+
case "l":
|
|
22146
|
+
case "re":
|
|
22147
|
+
ops++;
|
|
22148
|
+
break;
|
|
22149
|
+
case "c":
|
|
22150
|
+
case "v":
|
|
22151
|
+
case "y":
|
|
22152
|
+
ops++;
|
|
22153
|
+
curves++;
|
|
22154
|
+
break;
|
|
22155
|
+
case "f":
|
|
22156
|
+
case "F":
|
|
22157
|
+
case "f*":
|
|
22158
|
+
fills++;
|
|
22159
|
+
break;
|
|
22160
|
+
case "B":
|
|
22161
|
+
case "B*":
|
|
22162
|
+
case "b":
|
|
22163
|
+
case "b*":
|
|
22164
|
+
fills++;
|
|
22165
|
+
break;
|
|
22166
|
+
default:
|
|
22167
|
+
break;
|
|
22168
|
+
}
|
|
22169
|
+
continue;
|
|
22170
|
+
}
|
|
22171
|
+
i++;
|
|
22172
|
+
}
|
|
22173
|
+
return { ops, curves, fills };
|
|
22174
|
+
}
|
|
22175
|
+
function isDelimiter(ch) {
|
|
22176
|
+
return ch === void 0 || ch === " " || ch === "\n" || ch === "\r" || ch === " " || ch === "\f" || ch === "\0" || ch === "[" || ch === "]" || ch === "/" || ch === "{" || ch === "}";
|
|
22177
|
+
}
|
|
22178
|
+
function pageContentStream(page) {
|
|
22179
|
+
try {
|
|
22180
|
+
const obj = page.getObject?.();
|
|
22181
|
+
const contents = obj?.get?.("Contents");
|
|
22182
|
+
if (!contents)
|
|
22183
|
+
return "";
|
|
22184
|
+
const streams = contents.isArray?.() && contents.get ? Array.from({ length: contents.length ?? 0 }, (_, i) => contents.get(i)) : [contents];
|
|
22185
|
+
let out = "";
|
|
22186
|
+
for (const stream of streams) {
|
|
22187
|
+
const buf = stream?.readStream?.();
|
|
22188
|
+
const bytes = buf?.asUint8Array?.();
|
|
22189
|
+
if (bytes)
|
|
22190
|
+
out += Buffer.from(bytes).toString("latin1");
|
|
22191
|
+
}
|
|
22192
|
+
return out;
|
|
22193
|
+
} catch {
|
|
22194
|
+
return "";
|
|
22195
|
+
}
|
|
22196
|
+
}
|
|
22197
|
+
function pageSignalsFrom(page, pageNumber) {
|
|
22198
|
+
const json = JSON.parse(page.toStructuredText("preserve-images").asJSON());
|
|
22199
|
+
const blocks = json.blocks ?? [];
|
|
22200
|
+
const text = blocks.flatMap((b) => (b.lines ?? []).map((l) => l.text ?? "")).join(" ");
|
|
22201
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
22202
|
+
const pageArea = Math.max((x1 - x0) * (y1 - y0), 1);
|
|
22203
|
+
const imgArea = blocks.filter((b) => b.type === "image").reduce((a, b) => a + Math.max((b.bbox?.w ?? 0) * (b.bbox?.h ?? 0), 0), 0);
|
|
22204
|
+
const vector = countVectorOperators(pageContentStream(page));
|
|
22205
|
+
return {
|
|
22206
|
+
page: pageNumber,
|
|
22207
|
+
textChars: text.trim().length,
|
|
22208
|
+
imageCoverage: Math.min(imgArea / pageArea, 1),
|
|
22209
|
+
vectorOps: vector.ops,
|
|
22210
|
+
vectorCurves: vector.curves,
|
|
22211
|
+
vectorFills: vector.fills,
|
|
22212
|
+
mathHint: textMathHint(text),
|
|
22213
|
+
tableHint: textTableHint(text)
|
|
22214
|
+
};
|
|
22215
|
+
}
|
|
22216
|
+
async function scanPdfSignals(bytes) {
|
|
22217
|
+
const { signals } = await analyzePdfDocument(bytes, { text: false, signals: true });
|
|
22218
|
+
return signals;
|
|
22219
|
+
}
|
|
22220
|
+
function median(nums) {
|
|
22221
|
+
if (!nums.length)
|
|
22222
|
+
return 0;
|
|
22223
|
+
const s = [...nums].sort((a, b) => a - b);
|
|
22224
|
+
return s[Math.floor(s.length / 2)];
|
|
22225
|
+
}
|
|
22226
|
+
async function extractPdfTables(bytes, pageNum, minColumns = 2) {
|
|
22227
|
+
const { doc } = await openDoc(bytes);
|
|
22228
|
+
const total = doc.countPages();
|
|
22229
|
+
const from = pageNum ? pageNum : 1;
|
|
22230
|
+
const to = pageNum ? pageNum : total;
|
|
22231
|
+
const out = [];
|
|
22232
|
+
for (let p = from; p <= to; p++) {
|
|
22233
|
+
if (p < 1 || p > total)
|
|
22234
|
+
continue;
|
|
22235
|
+
const json = JSON.parse(doc.loadPage(p - 1).toStructuredText().asJSON());
|
|
22236
|
+
const cells = [];
|
|
22237
|
+
for (const b of json.blocks ?? []) {
|
|
22238
|
+
if (b.type === "image")
|
|
22239
|
+
continue;
|
|
22240
|
+
for (const l of b.lines ?? []) {
|
|
22241
|
+
const text = (l.text ?? "").trim();
|
|
22242
|
+
if (!text)
|
|
22243
|
+
continue;
|
|
22244
|
+
cells.push({ text, x: l.bbox?.x ?? 0, y: l.bbox?.y ?? 0, h: l.bbox?.h ?? 12 });
|
|
22245
|
+
}
|
|
22246
|
+
}
|
|
22247
|
+
if (cells.length < 2)
|
|
22248
|
+
continue;
|
|
22249
|
+
const medH = median(cells.map((c) => c.h)) || 12;
|
|
22250
|
+
const rowTol = Math.max(4, medH * 0.6);
|
|
22251
|
+
const colTol = Math.max(6, medH * 0.9);
|
|
22252
|
+
const byY = [...cells].sort((a, b) => a.y - b.y);
|
|
22253
|
+
const rowGroups = [];
|
|
22254
|
+
let rowRef = Number.NEGATIVE_INFINITY;
|
|
22255
|
+
for (const c of byY) {
|
|
22256
|
+
if (c.y - rowRef > rowTol) {
|
|
22257
|
+
rowGroups.push([]);
|
|
22258
|
+
rowRef = c.y;
|
|
22259
|
+
}
|
|
22260
|
+
rowGroups[rowGroups.length - 1].push(c);
|
|
22261
|
+
}
|
|
22262
|
+
const colRefs = [];
|
|
22263
|
+
for (const x of cells.map((c) => c.x).sort((a, b) => a - b)) {
|
|
22264
|
+
if (!colRefs.length || x - colRefs[colRefs.length - 1] > colTol)
|
|
22265
|
+
colRefs.push(x);
|
|
22266
|
+
}
|
|
22267
|
+
const colIndex = (x) => {
|
|
22268
|
+
let best = 0, bd = Infinity;
|
|
22269
|
+
colRefs.forEach((r, i) => {
|
|
22270
|
+
const d = Math.abs(x - r);
|
|
22271
|
+
if (d < bd) {
|
|
22272
|
+
bd = d;
|
|
22273
|
+
best = i;
|
|
22274
|
+
}
|
|
22275
|
+
});
|
|
22276
|
+
return best;
|
|
22277
|
+
};
|
|
22278
|
+
const rows = [];
|
|
22279
|
+
for (const group of rowGroups) {
|
|
22280
|
+
const arr = Array(colRefs.length).fill("");
|
|
22281
|
+
for (const c of group.sort((a, b) => a.x - b.x)) {
|
|
22282
|
+
const i = colIndex(c.x);
|
|
22283
|
+
arr[i] = arr[i] ? `${arr[i]} ${c.text}` : c.text;
|
|
22284
|
+
}
|
|
22285
|
+
if (arr.filter((v) => v).length >= minColumns)
|
|
22286
|
+
rows.push(arr);
|
|
22287
|
+
}
|
|
22288
|
+
if (rows.length)
|
|
22289
|
+
out.push({ page: p, rows });
|
|
22290
|
+
}
|
|
22291
|
+
return out;
|
|
22292
|
+
}
|
|
22293
|
+
async function extractPdfTextLines(bytes) {
|
|
22294
|
+
const { doc } = await openDoc(bytes);
|
|
22295
|
+
const out = [];
|
|
22296
|
+
for (let p = 1; p <= doc.countPages(); p++) {
|
|
22297
|
+
const page = doc.loadPage(p - 1);
|
|
22298
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
22299
|
+
const json = JSON.parse(page.toStructuredText().asJSON());
|
|
22300
|
+
const lines = [];
|
|
22301
|
+
for (const b of json.blocks ?? []) {
|
|
22302
|
+
if (b.type === "image")
|
|
22303
|
+
continue;
|
|
22304
|
+
for (const l of b.lines ?? []) {
|
|
22305
|
+
const text = l.text ?? "";
|
|
22306
|
+
if (!text.trim() || !l.bbox)
|
|
22307
|
+
continue;
|
|
22308
|
+
lines.push({
|
|
22309
|
+
x: l.bbox.x ?? 0,
|
|
22310
|
+
y: l.bbox.y ?? 0,
|
|
22311
|
+
w: l.bbox.w ?? 0,
|
|
22312
|
+
h: l.bbox.h ?? 0,
|
|
22313
|
+
size: l.font?.size ?? 12,
|
|
22314
|
+
text
|
|
22315
|
+
});
|
|
22316
|
+
}
|
|
22317
|
+
}
|
|
22318
|
+
out.push({ page: p, width: x1 - x0, height: y1 - y0, lines });
|
|
22319
|
+
}
|
|
22320
|
+
return out;
|
|
22321
|
+
}
|
|
22322
|
+
async function renderPdfPages(bytes, pages, scale = 2, maxEdge) {
|
|
22323
|
+
const { mupdf, doc } = await openDoc(bytes);
|
|
22324
|
+
const total = doc.countPages();
|
|
22325
|
+
const wanted = pages === "all" ? Array.from({ length: total }, (_, i) => i + 1) : pages;
|
|
22326
|
+
const out = [];
|
|
22327
|
+
for (const p of wanted) {
|
|
22328
|
+
if (p < 1 || p > total)
|
|
22329
|
+
continue;
|
|
22330
|
+
const page = doc.loadPage(p - 1);
|
|
22331
|
+
const [x0, y0, x1, y1] = page.getBounds();
|
|
22332
|
+
const longest = Math.max(x1 - x0, y1 - y0);
|
|
22333
|
+
const s = maxEdge && longest > 0 ? Math.min(scale, maxEdge / longest) : scale;
|
|
22334
|
+
const pix = page.toPixmap(mupdf.Matrix.scale(s, s), mupdf.ColorSpace.DeviceRGB, false, true);
|
|
22335
|
+
out.push({ page: p, png: pix.asPNG() });
|
|
22336
|
+
}
|
|
22337
|
+
return out;
|
|
22338
|
+
}
|
|
22339
|
+
async function extractPdfImages(bytes, pages) {
|
|
22340
|
+
const { doc } = await openDoc(bytes);
|
|
22341
|
+
const total = doc.countPages();
|
|
22342
|
+
const wanted = pages && pages.length ? pages : Array.from({ length: total }, (_, i) => i + 1);
|
|
22343
|
+
const images = [];
|
|
22344
|
+
let skipped = 0;
|
|
22345
|
+
for (const p of wanted) {
|
|
22346
|
+
if (p < 1 || p > total)
|
|
22347
|
+
continue;
|
|
22348
|
+
const stext = doc.loadPage(p - 1).toStructuredText("preserve-images");
|
|
22349
|
+
let index = 0;
|
|
22350
|
+
stext.walk({
|
|
22351
|
+
onImageBlock(bbox, _matrix, image) {
|
|
22352
|
+
const slot = index++;
|
|
22353
|
+
try {
|
|
22354
|
+
const png = image.toPixmap().asPNG();
|
|
22355
|
+
images.push({
|
|
22356
|
+
page: p,
|
|
22357
|
+
index: slot,
|
|
22358
|
+
bbox: [bbox[0], bbox[1], bbox[2], bbox[3]],
|
|
22359
|
+
width: image.getWidth(),
|
|
22360
|
+
height: image.getHeight(),
|
|
22361
|
+
png
|
|
22362
|
+
});
|
|
22363
|
+
} catch {
|
|
22364
|
+
skipped++;
|
|
22365
|
+
}
|
|
22366
|
+
}
|
|
22367
|
+
});
|
|
22368
|
+
}
|
|
22369
|
+
return { images, skipped };
|
|
22370
|
+
}
|
|
22371
|
+
async function encryptPdf(bytes, userPassword, ownerPassword) {
|
|
22372
|
+
if (!userPassword)
|
|
22373
|
+
throw new Error("a non-empty user password is required");
|
|
22374
|
+
const { doc } = await openDoc(bytes);
|
|
22375
|
+
const opts = `encrypt=aes-256,user-password=${userPassword},owner-password=${ownerPassword || userPassword}`;
|
|
22376
|
+
return doc.saveToBuffer(opts).asUint8Array();
|
|
22377
|
+
}
|
|
22378
|
+
async function pdfNeedsPassword(bytes) {
|
|
22379
|
+
const mupdf = await loadMupdf();
|
|
22380
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
22381
|
+
return doc.needsPassword();
|
|
22382
|
+
}
|
|
22383
|
+
async function decryptPdf(bytes, password) {
|
|
22384
|
+
const mupdf = await loadMupdf();
|
|
22385
|
+
const doc = mupdf.Document.openDocument(bytes, "application/pdf");
|
|
22386
|
+
if (doc.needsPassword()) {
|
|
22387
|
+
if (doc.authenticatePassword(password) === 0)
|
|
22388
|
+
throw new Error("wrong password");
|
|
22389
|
+
}
|
|
22390
|
+
if (doc.countPages() === 0)
|
|
22391
|
+
throw new Error("PDF has no readable pages (corrupt or empty)");
|
|
22392
|
+
return doc.saveToBuffer("encrypt=none").asUint8Array();
|
|
22393
|
+
}
|
|
22394
|
+
var import_node_path, import_node_url, _mupdf, MATH_CHARS;
|
|
22395
|
+
var init_pdf_extract = __esm({
|
|
22396
|
+
"packages/core/dist/document/pdf-extract.js"() {
|
|
22397
|
+
"use strict";
|
|
22398
|
+
import_node_path = require("node:path");
|
|
22399
|
+
import_node_url = require("node:url");
|
|
22400
|
+
init_pdf_encrypted();
|
|
22401
|
+
_mupdf = null;
|
|
22402
|
+
MATH_CHARS = /[=∑∫√≤≥≠±∞πθλμσΩ×÷∂∇→←↔∈∉⊂⊃∀∃]/g;
|
|
22403
|
+
}
|
|
22404
|
+
});
|
|
22405
|
+
|
|
22018
22406
|
// apps/admin/data/skills.lib/document/bin-src/pdf-form.mjs
|
|
22019
|
-
var
|
|
22407
|
+
var import_promises2 = require("node:fs/promises");
|
|
22408
|
+
var import_node_path3 = require("node:path");
|
|
22020
22409
|
|
|
22021
22410
|
// packages/core/dist/document/pdf-form.js
|
|
22411
|
+
var import_pdf_lib3 = __toESM(require_cjs(), 1);
|
|
22412
|
+
|
|
22413
|
+
// packages/core/dist/document/pdf-lib-load.js
|
|
22022
22414
|
var import_pdf_lib = __toESM(require_cjs(), 1);
|
|
22415
|
+
init_pdf_encrypted();
|
|
22416
|
+
var isEncryptedError = (e) => e instanceof import_pdf_lib.EncryptedPDFError || /PDFDocument\.load` is encrypted/.test(String(e?.message));
|
|
22417
|
+
async function loadEditablePdf(bytes) {
|
|
22418
|
+
try {
|
|
22419
|
+
return await import_pdf_lib.PDFDocument.load(bytes);
|
|
22420
|
+
} catch (e) {
|
|
22421
|
+
if (!isEncryptedError(e))
|
|
22422
|
+
throw e;
|
|
22423
|
+
const { pdfNeedsPassword: pdfNeedsPassword2 } = await Promise.resolve().then(() => (init_pdf_extract(), pdf_extract_exports));
|
|
22424
|
+
const needsPassword = await pdfNeedsPassword2(bytes).catch(() => true);
|
|
22425
|
+
throw needsPassword ? new PdfEncryptedError() : new Error(OWNER_ONLY_PDF_MESSAGE);
|
|
22426
|
+
}
|
|
22427
|
+
}
|
|
22428
|
+
|
|
22429
|
+
// packages/core/dist/document/pdf-text-font.js
|
|
22430
|
+
var import_promises = require("node:fs/promises");
|
|
22431
|
+
var import_node_path2 = require("node:path");
|
|
22432
|
+
var import_pdf_lib2 = __toESM(require_cjs(), 1);
|
|
22433
|
+
async function loadFontkit() {
|
|
22434
|
+
const mod = await import("./fontkit.cjs");
|
|
22435
|
+
return mod.default?.create ? mod.default : mod;
|
|
22436
|
+
}
|
|
22437
|
+
var PDF_CJK_FONT_FILES = {
|
|
22438
|
+
regular: "NotoSansSC-PDF-Regular.ttf",
|
|
22439
|
+
bold: "NotoSansSC-PDF-Bold.ttf"
|
|
22440
|
+
};
|
|
22441
|
+
var LINE_BREAK = /\r\n|[\n\f\r\u000B\u0085\u2028\u2029]/;
|
|
22442
|
+
function encodableAs(std, text) {
|
|
22443
|
+
const enc = import_pdf_lib2.StandardFontEmbedder.for(std);
|
|
22444
|
+
try {
|
|
22445
|
+
for (const line of text.replace(/\t/g, " ").split(LINE_BREAK))
|
|
22446
|
+
enc.encodeText(line);
|
|
22447
|
+
return true;
|
|
22448
|
+
} catch {
|
|
22449
|
+
return false;
|
|
22450
|
+
}
|
|
22451
|
+
}
|
|
22452
|
+
function isWinAnsiText(texts) {
|
|
22453
|
+
return texts.every((t) => encodableAs(import_pdf_lib2.StandardFonts.Helvetica, t));
|
|
22454
|
+
}
|
|
22455
|
+
var codePoint = (cp) => `"${String.fromCodePoint(cp)}" (U+${cp.toString(16).toUpperCase().padStart(4, "0")})`;
|
|
22456
|
+
async function embedTextFont(doc, texts, opts = {}) {
|
|
22457
|
+
const bold = opts.weight === "bold";
|
|
22458
|
+
const std = bold ? import_pdf_lib2.StandardFonts.HelveticaBold : import_pdf_lib2.StandardFonts.Helvetica;
|
|
22459
|
+
if (texts.every((t) => encodableAs(std, t)))
|
|
22460
|
+
return doc.embedFont(std);
|
|
22461
|
+
if (!opts.fontDir) {
|
|
22462
|
+
const sample = [...texts.join("")].find((ch) => ch !== " " && !LINE_BREAK.test(ch) && !encodableAs(std, ch)) ?? "";
|
|
22463
|
+
throw new Error(`text has characters Helvetica cannot draw (e.g. ${codePoint(sample.codePointAt(0) ?? 0)}) and no CJK font directory was given`);
|
|
22464
|
+
}
|
|
22465
|
+
const used = /* @__PURE__ */ new Set();
|
|
22466
|
+
for (const t of texts) {
|
|
22467
|
+
for (const ch of t) {
|
|
22468
|
+
const cp = ch.codePointAt(0);
|
|
22469
|
+
if (cp >= 32 && !LINE_BREAK.test(ch) && cp !== 127)
|
|
22470
|
+
used.add(cp);
|
|
22471
|
+
}
|
|
22472
|
+
}
|
|
22473
|
+
const fontkit = await loadFontkit();
|
|
22474
|
+
const regularBytes = await (0, import_promises.readFile)((0, import_node_path2.join)(opts.fontDir, PDF_CJK_FONT_FILES.regular));
|
|
22475
|
+
const regular = fontkit.create(regularBytes);
|
|
22476
|
+
const missing = [...used].filter((cp) => !regular.hasGlyphForCodePoint(cp));
|
|
22477
|
+
if (missing.length) {
|
|
22478
|
+
const shown = missing.slice(0, 8).map(codePoint).join(", ");
|
|
22479
|
+
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)`);
|
|
22480
|
+
}
|
|
22481
|
+
let bytes = regularBytes;
|
|
22482
|
+
if (bold) {
|
|
22483
|
+
const boldBytes = await (0, import_promises.readFile)((0, import_node_path2.join)(opts.fontDir, PDF_CJK_FONT_FILES.bold));
|
|
22484
|
+
const boldFont = fontkit.create(boldBytes);
|
|
22485
|
+
if ([...used].every((cp) => boldFont.hasGlyphForCodePoint(cp)))
|
|
22486
|
+
bytes = boldBytes;
|
|
22487
|
+
}
|
|
22488
|
+
doc.registerFontkit(fontkit);
|
|
22489
|
+
return doc.embedFont(bytes, { subset: true });
|
|
22490
|
+
}
|
|
22491
|
+
|
|
22492
|
+
// packages/core/dist/document/pdf-form.js
|
|
22023
22493
|
function fieldType(f) {
|
|
22024
22494
|
return f.constructor.name.replace(/^PDF/, "").replace(/\d+$/, "");
|
|
22025
22495
|
}
|
|
22026
22496
|
async function listPdfFormFields(bytes) {
|
|
22027
|
-
const doc = await
|
|
22497
|
+
const doc = await loadEditablePdf(bytes);
|
|
22028
22498
|
return doc.getForm().getFields().map((f) => ({ name: f.getName(), type: fieldType(f) }));
|
|
22029
22499
|
}
|
|
22030
22500
|
async function fillPdfForm(bytes, values, opts = {}) {
|
|
22031
|
-
const doc = await
|
|
22501
|
+
const doc = await loadEditablePdf(bytes);
|
|
22032
22502
|
const form = doc.getForm();
|
|
22033
22503
|
const filled = [];
|
|
22034
22504
|
const skipped = [];
|
|
@@ -22060,12 +22530,38 @@ async function fillPdfForm(bytes, values, opts = {}) {
|
|
|
22060
22530
|
}
|
|
22061
22531
|
(ok ? filled : skipped).push(name);
|
|
22062
22532
|
}
|
|
22063
|
-
|
|
22064
|
-
|
|
22533
|
+
const texts = form.getFields().filter((f) => f.needsAppearancesUpdate()).flatMap(fieldTexts);
|
|
22534
|
+
const cjk = !isWinAnsiText(texts);
|
|
22535
|
+
if (cjk)
|
|
22536
|
+
form.updateFieldAppearances(await embedTextFont(doc, texts, opts));
|
|
22537
|
+
if (opts.flatten) {
|
|
22538
|
+
form.flatten({ updateFieldAppearances: !cjk });
|
|
22539
|
+
dropDanglingAnnots(doc);
|
|
22540
|
+
}
|
|
22065
22541
|
return { bytes: await doc.save(), filled, skipped };
|
|
22066
22542
|
}
|
|
22543
|
+
function fieldTexts(field) {
|
|
22544
|
+
const f = field;
|
|
22545
|
+
if (typeof f.getText === "function")
|
|
22546
|
+
return [f.getText() ?? ""];
|
|
22547
|
+
const sel = typeof f.getSelected === "function" ? f.getSelected() : void 0;
|
|
22548
|
+
return Array.isArray(sel) ? sel : [];
|
|
22549
|
+
}
|
|
22550
|
+
function dropDanglingAnnots(doc) {
|
|
22551
|
+
for (const page of doc.getPages()) {
|
|
22552
|
+
const raw = page.node.get(import_pdf_lib3.PDFName.of("Annots"));
|
|
22553
|
+
const annots = raw instanceof import_pdf_lib3.PDFRef ? doc.context.lookup(raw) : raw;
|
|
22554
|
+
if (!(annots instanceof import_pdf_lib3.PDFArray))
|
|
22555
|
+
continue;
|
|
22556
|
+
for (let i = annots.size() - 1; i >= 0; i--) {
|
|
22557
|
+
const ref = annots.get(i);
|
|
22558
|
+
if (ref instanceof import_pdf_lib3.PDFRef && doc.context.lookup(ref) === void 0)
|
|
22559
|
+
annots.remove(i);
|
|
22560
|
+
}
|
|
22561
|
+
}
|
|
22562
|
+
}
|
|
22067
22563
|
async function overlayPdfFormBoxes(bytes) {
|
|
22068
|
-
const doc = await
|
|
22564
|
+
const doc = await loadEditablePdf(bytes);
|
|
22069
22565
|
const pages = doc.getPages();
|
|
22070
22566
|
let boxes = 0;
|
|
22071
22567
|
for (const field of doc.getForm().getFields()) {
|
|
@@ -22078,7 +22574,7 @@ async function overlayPdfFormBoxes(bytes) {
|
|
|
22078
22574
|
y: rect.y,
|
|
22079
22575
|
width: rect.width,
|
|
22080
22576
|
height: rect.height,
|
|
22081
|
-
borderColor: (0,
|
|
22577
|
+
borderColor: (0, import_pdf_lib3.rgb)(1, 0, 0),
|
|
22082
22578
|
borderWidth: 1.5,
|
|
22083
22579
|
opacity: 0,
|
|
22084
22580
|
borderOpacity: 1
|
|
@@ -22092,6 +22588,7 @@ async function overlayPdfFormBoxes(bytes) {
|
|
|
22092
22588
|
}
|
|
22093
22589
|
|
|
22094
22590
|
// apps/admin/data/skills.lib/document/bin-src/pdf-form.mjs
|
|
22591
|
+
var fontDir = (0, import_node_path3.join)(__dirname, "..", "assets", "pdf-fonts");
|
|
22095
22592
|
function die(msg, code = 1) {
|
|
22096
22593
|
process.stderr.write(`pdf-form: ${msg}
|
|
22097
22594
|
`);
|
|
@@ -22104,7 +22601,7 @@ async function main() {
|
|
|
22104
22601
|
if (!inPdf) die("usage: pdf-form list <in.pdf>", 64);
|
|
22105
22602
|
let raw;
|
|
22106
22603
|
try {
|
|
22107
|
-
raw = await (0,
|
|
22604
|
+
raw = await (0, import_promises2.readFile)(inPdf);
|
|
22108
22605
|
} catch (e) {
|
|
22109
22606
|
die(`cannot read ${inPdf}: ${e.message}`);
|
|
22110
22607
|
}
|
|
@@ -22122,36 +22619,36 @@ async function main() {
|
|
|
22122
22619
|
if (!inPdf || !valuesPath || !outPdf) die("usage: pdf-form fill <in.pdf> <values.json> <out.pdf> [--flatten]", 64);
|
|
22123
22620
|
let raw, values;
|
|
22124
22621
|
try {
|
|
22125
|
-
raw = await (0,
|
|
22622
|
+
raw = await (0, import_promises2.readFile)(inPdf);
|
|
22126
22623
|
} catch (e) {
|
|
22127
22624
|
die(`cannot read ${inPdf}: ${e.message}`);
|
|
22128
22625
|
}
|
|
22129
22626
|
try {
|
|
22130
|
-
values = JSON.parse(await (0,
|
|
22627
|
+
values = JSON.parse(await (0, import_promises2.readFile)(valuesPath, "utf-8"));
|
|
22131
22628
|
} catch (e) {
|
|
22132
22629
|
die(`bad values json: ${e.message}`, 64);
|
|
22133
22630
|
}
|
|
22134
22631
|
let result;
|
|
22135
22632
|
try {
|
|
22136
|
-
result = await fillPdfForm(new Uint8Array(raw), values, { flatten: flag === "--flatten" });
|
|
22633
|
+
result = await fillPdfForm(new Uint8Array(raw), values, { flatten: flag === "--flatten", fontDir });
|
|
22137
22634
|
} catch (e) {
|
|
22138
22635
|
die(`fill failed: ${e.message}`);
|
|
22139
22636
|
}
|
|
22140
|
-
await (0,
|
|
22637
|
+
await (0, import_promises2.writeFile)(outPdf, Buffer.from(result.bytes));
|
|
22141
22638
|
process.stdout.write(JSON.stringify({ out: outPdf, filled: result.filled, skipped: result.skipped }, null, 2) + "\n");
|
|
22142
22639
|
return;
|
|
22143
22640
|
}
|
|
22144
22641
|
if (mode === "overlay") {
|
|
22145
22642
|
const [inPdf, out] = rest;
|
|
22146
22643
|
if (!inPdf || !out) die("usage: pdf-form overlay <filled.pdf> <out.pdf> (then pdf-render + LOOK)", 64);
|
|
22147
|
-
const bytes = new Uint8Array(await (0,
|
|
22644
|
+
const bytes = new Uint8Array(await (0, import_promises2.readFile)(inPdf).catch((e) => die(`cannot read ${inPdf}: ${e.message}`)));
|
|
22148
22645
|
let r;
|
|
22149
22646
|
try {
|
|
22150
22647
|
r = await overlayPdfFormBoxes(bytes);
|
|
22151
22648
|
} catch (e) {
|
|
22152
22649
|
die(e.message);
|
|
22153
22650
|
}
|
|
22154
|
-
await (0,
|
|
22651
|
+
await (0, import_promises2.writeFile)(out, Buffer.from(r.bytes));
|
|
22155
22652
|
process.stdout.write(JSON.stringify({ ok: true, out, boxes: r.boxes }) + "\n");
|
|
22156
22653
|
process.stderr.write("pdf-form: now pdf-render the page(s) and VISUALLY CHECK every value sits inside its red box\n");
|
|
22157
22654
|
return;
|