@reportwright/viewer 0.11.0 → 0.12.0

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.
@@ -26,7 +26,7 @@ import {
26
26
  } from "../chunk-3D43XGIN.js";
27
27
 
28
28
  // src/exporters/pdf.js
29
- import { PDFDocument, PDFName as PDFName3, PDFString as PDFString4, PDFHexString as PDFHexString4, PDFRawStream as PDFRawStream2, rgb as rgb2 } from "pdf-lib";
29
+ import { PDFDocument, PDFName as PDFName3, PDFString as PDFString4, PDFHexString as PDFHexString5, PDFRawStream as PDFRawStream2, rgb as rgb3 } from "pdf-lib";
30
30
  import fontkitModule from "@pdf-lib/fontkit";
31
31
 
32
32
  // src/exporters/pdfa.js
@@ -743,11 +743,8 @@ function pngProblem(b) {
743
743
  return null;
744
744
  }
745
745
 
746
- // src/exporters/pdf.js
747
- var fontkit = (
748
- /** @type {any} */
749
- fontkitModule.default || fontkitModule
750
- );
746
+ // src/exporters/pdfpaint.js
747
+ import { PDFHexString as PDFHexString4, rgb as rgb2 } from "pdf-lib";
751
748
  var colors = /* @__PURE__ */ new Map();
752
749
  var col = (c) => {
753
750
  if (colors.has(c)) return colors.get(c);
@@ -762,6 +759,321 @@ var n4 = (v) => Math.round(v * 1e4) / 1e4;
762
759
  var hex4 = (id) => id.toString(16).padStart(4, "0");
763
760
  var KAPPA = 4 * ((Math.SQRT2 - 1) / 3);
764
761
  var cleanText = (t) => t.replace(/\t|\u0085|\u2028|\u2029/g, " ").replace(/[\b\v]/g, "");
762
+ function drawRun(c, run, x, y, size, pf, color, spans, texts) {
763
+ const f = pf.embedder.font;
764
+ const per = 1e3 / size;
765
+ const span = (text) => `/Span <</ActualText ${PDFHexString4.fromText(text).toString()}>> BDC
766
+ `;
767
+ c.et();
768
+ c.paint(color, null);
769
+ c.font(pf, size);
770
+ if (!run.rtl) c.s += span(run.text);
771
+ c.s += `BT ${n2(x)} ${n2(y)} Td
772
+ `;
773
+ let arr = "";
774
+ let pen = 0, rise = 0;
775
+ const flush = () => {
776
+ if (arr) c.s += `[${arr}] TJ
777
+ `;
778
+ arr = "";
779
+ };
780
+ const all = run.glyphs;
781
+ const adv = (id) => f.getGlyph(id).advanceWidth;
782
+ let g = all, quietAt = -1;
783
+ if (run.rtl) {
784
+ const hasBase = /* @__PURE__ */ new Set();
785
+ for (let i = 0; i < all.length; i += 4) if (adv(all[i]) > 0) hasBase.add(all[i + 3]);
786
+ const quiet = (i) => spans?.has(all[i + 3]) ? adv(all[i]) === 0 && hasBase.has(all[i + 3]) : texts?.get(all[i]) === "";
787
+ g = [];
788
+ for (const late of [false, true]) {
789
+ if (late) quietAt = g.length;
790
+ for (let i = 0; i < all.length; i += 4) if (quiet(i) === late) g.push(all[i], all[i + 1], all[i + 2], all[i + 3]);
791
+ }
792
+ if (quietAt === g.length) quietAt = -1;
793
+ }
794
+ const starts = run.rtl ? [...new Set(all.filter((_, i) => i % 4 === 3))].sort((a, b) => a - b) : [];
795
+ let inSpan = false;
796
+ for (let i = 0; i < g.length; i += 4) {
797
+ const id = g[i], gx = g[i + 1], gy = g[i + 2], cl = g[i + 3];
798
+ if (i === quietAt) {
799
+ flush();
800
+ c.s += span("");
801
+ inSpan = true;
802
+ } else if (run.rtl && spans?.has(cl) && (quietAt < 0 || i < quietAt) && (i === 0 || g[i - 1] !== cl)) {
803
+ flush();
804
+ c.s += span(run.text.slice(cl, starts[starts.indexOf(cl) + 1] ?? run.text.length));
805
+ inSpan = true;
806
+ }
807
+ if (gy !== rise) {
808
+ flush();
809
+ c.s += `${n4(gy)} Ts
810
+ `;
811
+ rise = gy;
812
+ }
813
+ const adj = Math.round((pen - gx) * per * 1e3) / 1e3;
814
+ if (id === 0 && c.tagged) pen = gx;
815
+ else {
816
+ arr += (adj ? `${adj}` : "") + `<${hex4(id)}>`;
817
+ pen = gx + adv(id) * size / f.unitsPerEm;
818
+ }
819
+ if (inSpan && (i + 4 >= g.length || (quietAt < 0 || i + 4 < quietAt) && g[i + 7] !== cl || i + 4 === quietAt)) {
820
+ flush();
821
+ c.s += "EMC\n";
822
+ inSpan = false;
823
+ }
824
+ }
825
+ flush();
826
+ if (rise) c.s += "0 Ts\n";
827
+ c.s += "ET\n";
828
+ if (!run.rtl) c.s += "EMC\n";
829
+ }
830
+ function glyphText(run, font, out, spans) {
831
+ const g = run.glyphs;
832
+ const starts = [...new Set(g.filter((_, i) => i % 4 === 3))].sort((a, b) => a - b);
833
+ for (let k = 0; k < starts.length; k++) {
834
+ const chars = [...run.text.slice(starts[k], starts[k + 1] ?? run.text.length)];
835
+ const ids = [];
836
+ for (let i = 0; i < g.length; i += 4) if (g[i + 3] === starts[k]) ids.push(g[i]);
837
+ const own = new Map(chars.map((ch) => [font.glyphForCodePoint(ch.codePointAt(0)).id, ch]));
838
+ const rest = chars.filter((ch) => !ids.includes(font.glyphForCodePoint(ch.codePointAt(0)).id)).join("");
839
+ const carrier = rest ? ids.find((id) => !own.has(id) && font.getGlyph(id).advanceWidth > 0) ?? ids.find((id) => !own.has(id)) : void 0;
840
+ let ok = !rest || carrier !== void 0;
841
+ const want = /* @__PURE__ */ new Map();
842
+ for (const id of ids) {
843
+ const t = own.get(id) ?? (id === carrier ? rest : "");
844
+ if (want.has(id) && want.get(id) !== t) ok = false;
845
+ want.set(id, t);
846
+ }
847
+ for (const [id, t] of want) {
848
+ if (!out.has(id)) out.set(id, t);
849
+ else if (out.get(id) !== t) ok = false;
850
+ }
851
+ if (!ok && run.rtl && spans) {
852
+ let s = spans.get(run);
853
+ if (!s) spans.set(run, s = /* @__PURE__ */ new Set());
854
+ s.add(starts[k]);
855
+ }
856
+ }
857
+ }
858
+ function insideClip(it, m) {
859
+ const k = it.clip, asc = m.asc * it.size, desc = m.desc * it.size;
860
+ return it.lines.every((l) => l.w != null && !l.runs && l.x >= k.x && l.x + l.w <= k.x + k.w && l.y - asc >= k.y && l.y + desc <= k.y + k.h);
861
+ }
862
+ var Content = class {
863
+ constructor(shared) {
864
+ this.shared = shared;
865
+ this._s = "";
866
+ this.bt = false;
867
+ this.tx = 0;
868
+ this.ty = 0;
869
+ this.st = { fill: "0 0 0", stroke: "0 0 0", lw: 1, dash: "[] 0", ca: 1, CA: 1, font: "", size: 0 };
870
+ this.saved = [];
871
+ this.lines = null;
872
+ this.tagged = false;
873
+ }
874
+ /**
875
+ * The operators so far. Any other drawing reads or appends to it, so the lines waiting are drawn first: the text
876
+ * of a table's cells stays in one text object (relative moves, which compress to little) instead of one per cell.
877
+ */
878
+ get s() {
879
+ this.flushLines();
880
+ return this._s;
881
+ }
882
+ set s(v) {
883
+ this._s = v;
884
+ }
885
+ /**
886
+ * A straight line. Untagged, it waits until something other than text is drawn (table borders between cell
887
+ * texts); collinear segments that touch, in the same stroke, become one (a row's border is one line).
888
+ * ponytail: lines move after the text drawn just after them; both are thin and do not cover each other.
889
+ */
890
+ line(stroke, w, dash, x1, y1, x2, y2) {
891
+ if (this.tagged) {
892
+ this.paint(null, stroke, w, dash);
893
+ this._s += `${n2(x1)} ${n2(y1)} m ${n2(x2)} ${n2(y2)} l S
894
+ `;
895
+ return;
896
+ }
897
+ const key = `${stroke.rgb}|${stroke.opacity}|${w}|${(dash || []).join(" ")}`;
898
+ if (this.lines && this.lines.key !== key) this.flushLines();
899
+ this.lines || (this.lines = { key, stroke, w, dash, segs: [] });
900
+ const segs = this.lines.segs, last = segs[segs.length - 1];
901
+ const eq = (a, b) => Math.abs(a - b) < 5e-3;
902
+ if (last && eq(last[1], y1) && eq(last[3], y2) && eq(y1, y2) && eq(last[2], x1)) last[2] = x2;
903
+ else if (last && eq(last[0], x1) && eq(last[2], x2) && eq(x1, x2) && eq(last[3], y1)) last[3] = y2;
904
+ else segs.push([x1, y1, x2, y2]);
905
+ }
906
+ flushLines() {
907
+ const L = this.lines;
908
+ if (!L) return;
909
+ this.lines = null;
910
+ this.et();
911
+ this.paint(null, L.stroke, L.w, L.dash);
912
+ const g = L.segs;
913
+ const dy = g.length > 2 ? Math.round((g[1][1] - g[0][1]) * 100) : 0;
914
+ if (dy && g.every((q, i) => q[1] === q[3] && n2(q[0]) === n2(g[0][0]) && n2(q[2]) === n2(g[0][2]) && Math.abs(q[1] - (g[0][1] + i * dy / 100)) < 0.01)) {
915
+ const one = `${n2(g[0][0])} ${n2(g[0][1])} m ${n2(g[0][2])} ${n2(g[0][1])} l S
916
+ `;
917
+ this._s += `q
918
+ ${one}${`1 0 0 1 0 ${dy / 100} cm ${one}`.repeat(g.length - 1)}Q
919
+ `;
920
+ return;
921
+ }
922
+ this._s += g.map(([a, b, c, d]) => `${n2(a)} ${n2(b)} m ${n2(c)} ${n2(d)} l`).join(" ") + " S\n";
923
+ }
924
+ q() {
925
+ this.et();
926
+ this._s += "q\n";
927
+ this.saved.push({ ...this.st });
928
+ }
929
+ Q() {
930
+ this.et();
931
+ this._s += "Q\n";
932
+ this.st = this.saved.pop();
933
+ }
934
+ /**
935
+ * A line of plain text at (x, y). Lines follow one another in one text object, each placed relative to the
936
+ * last (in whole hundredths, so nothing drifts): most of a table page is these.
937
+ * @param {string} str the glyphs, as a literal string's escaped body (array: a TJ array's body)
938
+ */
939
+ text(pf, size, color, x, y, str, array = false) {
940
+ this.setPaint(color, null);
941
+ this.setFont(pf, size);
942
+ const X = Math.round(x * 10) * 10, Y = Math.round(y * 10) * 10;
943
+ if (!this.bt) {
944
+ this._s += "BT\n";
945
+ this.bt = true;
946
+ this.tx = 0;
947
+ this.ty = 0;
948
+ }
949
+ this._s += array ? `${(X - this.tx) / 100} ${(Y - this.ty) / 100} Td [${str}] TJ
950
+ ` : `${(X - this.tx) / 100} ${(Y - this.ty) / 100} Td (${str}) Tj
951
+ `;
952
+ this.tx = X;
953
+ this.ty = Y;
954
+ }
955
+ /** end the open text object, if any: anything but text needs that (and draws the lines waiting) */
956
+ et() {
957
+ if (this.bt) {
958
+ this._s += "ET\n";
959
+ this.bt = false;
960
+ }
961
+ if (this.lines) this.flushLines();
962
+ }
963
+ lineWidth(w) {
964
+ if (this.lines) this.flushLines();
965
+ this.setLineWidth(w);
966
+ }
967
+ setLineWidth(w) {
968
+ if (this.st.lw !== w) {
969
+ this._s += `${n3(w)} w
970
+ `;
971
+ this.st.lw = w;
972
+ }
973
+ }
974
+ /** the graphics state that sets these opacities, or undefined when they are set already */
975
+ gsFor(ca, CA) {
976
+ return ca === this.st.ca && CA === this.st.CA ? void 0 : this.shared.gs(ca, CA);
977
+ }
978
+ alpha(ca, CA) {
979
+ if (this.lines) this.flushLines();
980
+ this.setAlpha(ca, CA);
981
+ }
982
+ setAlpha(ca, CA) {
983
+ const g = this.gsFor(ca, CA);
984
+ if (g) {
985
+ this._s += `/${g} gs
986
+ `;
987
+ this.st.ca = ca;
988
+ this.st.CA = CA;
989
+ }
990
+ }
991
+ /** set up to fill with fill and/or stroke with stroke (width w, dash); the lines waiting are drawn first */
992
+ paint(fill, stroke, w = 1, dash = null) {
993
+ if (this.lines) this.flushLines();
994
+ this.setPaint(fill, stroke, w, dash);
995
+ }
996
+ setPaint(fill, stroke, w = 1, dash = null) {
997
+ const st = this.st;
998
+ if (fill && fill.rgb !== st.fill) {
999
+ this._s += `${fill.rgb} rg
1000
+ `;
1001
+ st.fill = fill.rgb;
1002
+ }
1003
+ if (stroke) {
1004
+ if (stroke.rgb !== st.stroke) {
1005
+ this._s += `${stroke.rgb} RG
1006
+ `;
1007
+ st.stroke = stroke.rgb;
1008
+ }
1009
+ this.setLineWidth(w);
1010
+ const d = `[${(dash || []).map(n3).join(" ")}] 0`;
1011
+ if (d !== st.dash) {
1012
+ this._s += `${d} d
1013
+ `;
1014
+ st.dash = d;
1015
+ }
1016
+ }
1017
+ this.setAlpha(fill ? fill.opacity : st.ca, stroke ? stroke.opacity : st.CA);
1018
+ }
1019
+ font(pf, size) {
1020
+ if (this.lines) this.flushLines();
1021
+ this.setFont(pf, size);
1022
+ }
1023
+ setFont(pf, size) {
1024
+ const name = this.shared.font(pf);
1025
+ if (name !== this.st.font || size !== this.st.size) {
1026
+ this._s += `/${name} ${n3(size)} Tf
1027
+ `;
1028
+ this.st.font = name;
1029
+ this.st.size = size;
1030
+ }
1031
+ }
1032
+ };
1033
+ function latin1(s) {
1034
+ const B = (
1035
+ /** @type {any} */
1036
+ globalThis.Buffer
1037
+ );
1038
+ if (B) return B.from(s, "latin1");
1039
+ const out = new Uint8Array(s.length);
1040
+ for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
1041
+ return out;
1042
+ }
1043
+ async function deflate(bytes) {
1044
+ if (zslots.free > 0) zslots.free--;
1045
+ else await new Promise((ok) => zslots.wait.push(
1046
+ /** @type {() => void} */
1047
+ ok
1048
+ ));
1049
+ try {
1050
+ return await deflateNow(bytes);
1051
+ } finally {
1052
+ const next = zslots.wait.shift();
1053
+ if (next) next();
1054
+ else zslots.free++;
1055
+ }
1056
+ }
1057
+ var zslots = { free: 4, wait: (
1058
+ /** @type {(() => void)[]} */
1059
+ []
1060
+ ) };
1061
+ var NODE_ZLIB = (
1062
+ /** @type {any} */
1063
+ globalThis.process?.getBuiltinModule?.("node:zlib")
1064
+ );
1065
+ async function deflateNow(bytes) {
1066
+ const zlib = NODE_ZLIB;
1067
+ if (zlib) return new Promise((ok, fail) => zlib.deflate(bytes, { level: 9 }, (e, z) => e ? fail(e) : ok(z)));
1068
+ if (typeof CompressionStream === "undefined") return (await import("fflate")).zlibSync(bytes);
1069
+ return new Uint8Array(await new Response(new Blob([bytes]).stream().pipeThrough(new CompressionStream("deflate"))).arrayBuffer());
1070
+ }
1071
+
1072
+ // src/exporters/pdf.js
1073
+ var fontkit = (
1074
+ /** @type {any} */
1075
+ fontkitModule.default || fontkitModule
1076
+ );
765
1077
  function exportPdf(model, fontStore, opt = {}) {
766
1078
  return withDeadline(
767
1079
  pdfOf(model, fontStore, opt),
@@ -780,7 +1092,7 @@ async function pdfOf(model, fontStore, opt) {
780
1092
  doc.setCreator("ReportWright");
781
1093
  if (opt.author) doc.setAuthor(opt.author);
782
1094
  setInfoDates(doc, when);
783
- if (fileId) doc.context.trailerInfo.ID = doc.context.obj([PDFHexString4.of(fileId), PDFHexString4.of(fileId)]);
1095
+ if (fileId) doc.context.trailerInfo.ID = doc.context.obj([PDFHexString5.of(fileId), PDFHexString5.of(fileId)]);
784
1096
  const used = /* @__PURE__ */ new Map();
785
1097
  const shaped = /* @__PURE__ */ new Map();
786
1098
  const spans = /* @__PURE__ */ new WeakMap();
@@ -1027,7 +1339,7 @@ async function pdfOf(model, fontStore, opt) {
1027
1339
  const form = doc.getForm();
1028
1340
  const f = await font(fieldFont(it));
1029
1341
  const name = uniqueName(it.name);
1030
- const box = { x: it.x, y: H - it.y - it.h, width: it.w, height: it.h, borderColor: rgb2(0.61, 0.64, 0.69), borderWidth: 0.75, backgroundColor: rgb2(1, 1, 1) };
1342
+ const box = { x: it.x, y: H - it.y - it.h, width: it.w, height: it.h, borderColor: rgb3(0.61, 0.64, 0.69), borderWidth: 0.75, backgroundColor: rgb3(1, 1, 1) };
1031
1343
  let field;
1032
1344
  if (it.kind === "checkbox") {
1033
1345
  field = form.createCheckBox(name);
@@ -1084,7 +1396,7 @@ async function pdfOf(model, fontStore, opt) {
1084
1396
  if (it.required) field.enableRequired();
1085
1397
  if (it.readOnly) field.enableReadOnly();
1086
1398
  if (tags) {
1087
- field.acroField.dict.set(PDFName3.of("TU"), PDFHexString4.fromText(it.label || it.name || name));
1399
+ field.acroField.dict.set(PDFName3.of("TU"), PDFHexString5.fromText(it.label || it.name || name));
1088
1400
  const w = field.acroField.getWidgets()[0];
1089
1401
  const ref2 = w && doc.context.getObjectRef(w.dict);
1090
1402
  if (ref2) tags.annot(pi, ii, ref2, "field");
@@ -1158,7 +1470,7 @@ async function pdfOf(model, fontStore, opt) {
1158
1470
  const to = l.href ? { A: { Type: "Action", S: "URI", URI: pdfLiteral(asciiUrl(l.href)) } } : { Dest: dest(l.to) };
1159
1471
  if (!l.href && !to.Dest) continue;
1160
1472
  const annot = doc.context.obj({ Type: "Annot", Subtype: "Link", F: 4, Rect: l.rect, Border: [0, 0, 0], ...to });
1161
- if (tags) annot.set(PDFName3.of("Contents"), PDFHexString4.fromText(String(l.text || l.tip || l.href || "Link")));
1473
+ if (tags) annot.set(PDFName3.of("Contents"), PDFHexString5.fromText(String(l.text || l.tip || l.href || "Link")));
1162
1474
  const ref = doc.context.register(annot);
1163
1475
  if (tags) tags.annot(l.pi, l.ii, ref, "link");
1164
1476
  const annots = l.page.node.lookup(PDFName3.of("Annots"));
@@ -1185,122 +1497,26 @@ function coveredText(items, box) {
1185
1497
  for (const t of items) if (t.t === "text" && t.lines) {
1186
1498
  for (const l of t.lines) if (l.text?.trim() && l.x >= box.x && l.x <= box.x + box.w && l.y >= box.y && l.y <= box.y + box.h) lines.push(l);
1187
1499
  }
1188
- return lines.sort((a, b) => a.y - b.y || a.x - b.x).map((l) => l.text.trim()).join(" ");
1189
- }
1190
- function fixedDate(opt) {
1191
- if (opt.creationDate !== void 0) {
1192
- if (!(opt.creationDate instanceof Date) || Number.isNaN(opt.creationDate.getTime())) throw Object.assign(new Error("creationDate must be a valid Date"), { status: 400 });
1193
- return opt.creationDate;
1194
- }
1195
- const epoch = globalThis.process?.env?.SOURCE_DATE_EPOCH;
1196
- return epoch && /^\d+$/.test(epoch) ? new Date(Number(epoch) * 1e3) : null;
1197
- }
1198
- async function contentId(model, opt, when) {
1199
- const bytes = new TextEncoder().encode(JSON.stringify([{ ...model, stats: void 0 }, opt.title || "Report", opt.author || "", when.toISOString()]));
1200
- const digest = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes));
1201
- return Array.from(digest.subarray(0, 16), (b) => b.toString(16).padStart(2, "0")).join("").toUpperCase();
1202
- }
1203
- function fieldFont(it) {
1204
- for (const d of it.draw) if (d.t === "text") {
1205
- for (const l of d.lines) for (const r of l.runs || []) if (r.font !== it.font && r.text.trim()) return r.font;
1206
- }
1207
- return it.font;
1208
- }
1209
- function drawRun(c, run, x, y, size, pf, color, spans, texts) {
1210
- const f = pf.embedder.font;
1211
- const per = 1e3 / size;
1212
- const span = (text) => `/Span <</ActualText ${PDFHexString4.fromText(text).toString()}>> BDC
1213
- `;
1214
- c.et();
1215
- c.paint(color, null);
1216
- c.font(pf, size);
1217
- if (!run.rtl) c.s += span(run.text);
1218
- c.s += `BT ${n2(x)} ${n2(y)} Td
1219
- `;
1220
- let arr = "";
1221
- let pen = 0, rise = 0;
1222
- const flush = () => {
1223
- if (arr) c.s += `[${arr}] TJ
1224
- `;
1225
- arr = "";
1226
- };
1227
- const all = run.glyphs;
1228
- const adv = (id) => f.getGlyph(id).advanceWidth;
1229
- let g = all, quietAt = -1;
1230
- if (run.rtl) {
1231
- const hasBase = /* @__PURE__ */ new Set();
1232
- for (let i = 0; i < all.length; i += 4) if (adv(all[i]) > 0) hasBase.add(all[i + 3]);
1233
- const quiet = (i) => spans?.has(all[i + 3]) ? adv(all[i]) === 0 && hasBase.has(all[i + 3]) : texts?.get(all[i]) === "";
1234
- g = [];
1235
- for (const late of [false, true]) {
1236
- if (late) quietAt = g.length;
1237
- for (let i = 0; i < all.length; i += 4) if (quiet(i) === late) g.push(all[i], all[i + 1], all[i + 2], all[i + 3]);
1238
- }
1239
- if (quietAt === g.length) quietAt = -1;
1240
- }
1241
- const starts = run.rtl ? [...new Set(all.filter((_, i) => i % 4 === 3))].sort((a, b) => a - b) : [];
1242
- let inSpan = false;
1243
- for (let i = 0; i < g.length; i += 4) {
1244
- const id = g[i], gx = g[i + 1], gy = g[i + 2], cl = g[i + 3];
1245
- if (i === quietAt) {
1246
- flush();
1247
- c.s += span("");
1248
- inSpan = true;
1249
- } else if (run.rtl && spans?.has(cl) && (quietAt < 0 || i < quietAt) && (i === 0 || g[i - 1] !== cl)) {
1250
- flush();
1251
- c.s += span(run.text.slice(cl, starts[starts.indexOf(cl) + 1] ?? run.text.length));
1252
- inSpan = true;
1253
- }
1254
- if (gy !== rise) {
1255
- flush();
1256
- c.s += `${n4(gy)} Ts
1257
- `;
1258
- rise = gy;
1259
- }
1260
- const adj = Math.round((pen - gx) * per * 1e3) / 1e3;
1261
- if (id === 0 && c.tagged) pen = gx;
1262
- else {
1263
- arr += (adj ? `${adj}` : "") + `<${hex4(id)}>`;
1264
- pen = gx + adv(id) * size / f.unitsPerEm;
1265
- }
1266
- if (inSpan && (i + 4 >= g.length || (quietAt < 0 || i + 4 < quietAt) && g[i + 7] !== cl || i + 4 === quietAt)) {
1267
- flush();
1268
- c.s += "EMC\n";
1269
- inSpan = false;
1270
- }
1500
+ return lines.sort((a, b) => a.y - b.y || a.x - b.x).map((l) => l.text.trim()).join(" ");
1501
+ }
1502
+ function fixedDate(opt) {
1503
+ if (opt.creationDate !== void 0) {
1504
+ if (!(opt.creationDate instanceof Date) || Number.isNaN(opt.creationDate.getTime())) throw Object.assign(new Error("creationDate must be a valid Date"), { status: 400 });
1505
+ return opt.creationDate;
1271
1506
  }
1272
- flush();
1273
- if (rise) c.s += "0 Ts\n";
1274
- c.s += "ET\n";
1275
- if (!run.rtl) c.s += "EMC\n";
1507
+ const epoch = globalThis.process?.env?.SOURCE_DATE_EPOCH;
1508
+ return epoch && /^\d+$/.test(epoch) ? new Date(Number(epoch) * 1e3) : null;
1276
1509
  }
1277
- function glyphText(run, font, out, spans) {
1278
- const g = run.glyphs;
1279
- const starts = [...new Set(g.filter((_, i) => i % 4 === 3))].sort((a, b) => a - b);
1280
- for (let k = 0; k < starts.length; k++) {
1281
- const chars = [...run.text.slice(starts[k], starts[k + 1] ?? run.text.length)];
1282
- const ids = [];
1283
- for (let i = 0; i < g.length; i += 4) if (g[i + 3] === starts[k]) ids.push(g[i]);
1284
- const own = new Map(chars.map((ch) => [font.glyphForCodePoint(ch.codePointAt(0)).id, ch]));
1285
- const rest = chars.filter((ch) => !ids.includes(font.glyphForCodePoint(ch.codePointAt(0)).id)).join("");
1286
- const carrier = rest ? ids.find((id) => !own.has(id) && font.getGlyph(id).advanceWidth > 0) ?? ids.find((id) => !own.has(id)) : void 0;
1287
- let ok = !rest || carrier !== void 0;
1288
- const want = /* @__PURE__ */ new Map();
1289
- for (const id of ids) {
1290
- const t = own.get(id) ?? (id === carrier ? rest : "");
1291
- if (want.has(id) && want.get(id) !== t) ok = false;
1292
- want.set(id, t);
1293
- }
1294
- for (const [id, t] of want) {
1295
- if (!out.has(id)) out.set(id, t);
1296
- else if (out.get(id) !== t) ok = false;
1297
- }
1298
- if (!ok && run.rtl && spans) {
1299
- let s = spans.get(run);
1300
- if (!s) spans.set(run, s = /* @__PURE__ */ new Set());
1301
- s.add(starts[k]);
1302
- }
1510
+ async function contentId(model, opt, when) {
1511
+ const bytes = new TextEncoder().encode(JSON.stringify([{ ...model, stats: void 0 }, opt.title || "Report", opt.author || "", when.toISOString()]));
1512
+ const digest = new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256", bytes));
1513
+ return Array.from(digest.subarray(0, 16), (b) => b.toString(16).padStart(2, "0")).join("").toUpperCase();
1514
+ }
1515
+ function fieldFont(it) {
1516
+ for (const d of it.draw) if (d.t === "text") {
1517
+ for (const l of d.lines) for (const r of l.runs || []) if (r.font !== it.font && r.text.trim()) return r.font;
1303
1518
  }
1519
+ return it.font;
1304
1520
  }
1305
1521
  var pdfLiteral = (s) => PDFString4.of(String(s).replace(/[\\()]/g, "\\$&"));
1306
1522
  function plainEncoding(pf) {
@@ -1318,7 +1534,7 @@ function plainEncoding(pf) {
1318
1534
  }
1319
1535
  return hex2;
1320
1536
  };
1321
- e.encodeText = (text) => PDFHexString4.of(e.hexOf(text));
1537
+ e.encodeText = (text) => PDFHexString5.of(e.hexOf(text));
1322
1538
  e.widthOfTextAtSize = (text, size) => {
1323
1539
  let w = 0;
1324
1540
  for (const ch of text) w += f.glyphForCodePoint(
@@ -1409,7 +1625,7 @@ function addOutline(doc, bookmarks, dest) {
1409
1625
  if (!Dest) continue;
1410
1626
  const level = Math.max(0, Math.min(9, Number(b.level) || 0));
1411
1627
  while (stack[stack.length - 1].level >= level) stack.pop();
1412
- const node2 = { ref: ctx.nextRef(), level, kids: [], Title: PDFHexString4.fromText(b.label), Dest };
1628
+ const node2 = { ref: ctx.nextRef(), level, kids: [], Title: PDFHexString5.fromText(b.label), Dest };
1413
1629
  stack[stack.length - 1].kids.push(node2);
1414
1630
  stack.push(node2);
1415
1631
  }
@@ -1440,216 +1656,6 @@ function subsetTag(bytes) {
1440
1656
  }
1441
1657
  return tag;
1442
1658
  }
1443
- function insideClip(it, m) {
1444
- const k = it.clip, asc = m.asc * it.size, desc = m.desc * it.size;
1445
- return it.lines.every((l) => l.w != null && !l.runs && l.x >= k.x && l.x + l.w <= k.x + k.w && l.y - asc >= k.y && l.y + desc <= k.y + k.h);
1446
- }
1447
- var Content = class {
1448
- constructor(shared) {
1449
- this.shared = shared;
1450
- this._s = "";
1451
- this.bt = false;
1452
- this.tx = 0;
1453
- this.ty = 0;
1454
- this.st = { fill: "0 0 0", stroke: "0 0 0", lw: 1, dash: "[] 0", ca: 1, CA: 1, font: "", size: 0 };
1455
- this.saved = [];
1456
- this.lines = null;
1457
- this.tagged = false;
1458
- }
1459
- /**
1460
- * The operators so far. Any other drawing reads or appends to it, so the lines waiting are drawn first: the text
1461
- * of a table's cells stays in one text object (relative moves, which compress to little) instead of one per cell.
1462
- */
1463
- get s() {
1464
- this.flushLines();
1465
- return this._s;
1466
- }
1467
- set s(v) {
1468
- this._s = v;
1469
- }
1470
- /**
1471
- * A straight line. Untagged, it waits until something other than text is drawn (table borders between cell
1472
- * texts); collinear segments that touch, in the same stroke, become one (a row's border is one line).
1473
- * ponytail: lines move after the text drawn just after them; both are thin and do not cover each other.
1474
- */
1475
- line(stroke, w, dash, x1, y1, x2, y2) {
1476
- if (this.tagged) {
1477
- this.paint(null, stroke, w, dash);
1478
- this._s += `${n2(x1)} ${n2(y1)} m ${n2(x2)} ${n2(y2)} l S
1479
- `;
1480
- return;
1481
- }
1482
- const key = `${stroke.rgb}|${stroke.opacity}|${w}|${(dash || []).join(" ")}`;
1483
- if (this.lines && this.lines.key !== key) this.flushLines();
1484
- this.lines || (this.lines = { key, stroke, w, dash, segs: [] });
1485
- const segs = this.lines.segs, last = segs[segs.length - 1];
1486
- const eq = (a, b) => Math.abs(a - b) < 5e-3;
1487
- if (last && eq(last[1], y1) && eq(last[3], y2) && eq(y1, y2) && eq(last[2], x1)) last[2] = x2;
1488
- else if (last && eq(last[0], x1) && eq(last[2], x2) && eq(x1, x2) && eq(last[3], y1)) last[3] = y2;
1489
- else segs.push([x1, y1, x2, y2]);
1490
- }
1491
- flushLines() {
1492
- const L = this.lines;
1493
- if (!L) return;
1494
- this.lines = null;
1495
- this.et();
1496
- this.paint(null, L.stroke, L.w, L.dash);
1497
- const g = L.segs;
1498
- const dy = g.length > 2 ? Math.round((g[1][1] - g[0][1]) * 100) : 0;
1499
- if (dy && g.every((q, i) => q[1] === q[3] && n2(q[0]) === n2(g[0][0]) && n2(q[2]) === n2(g[0][2]) && Math.abs(q[1] - (g[0][1] + i * dy / 100)) < 0.01)) {
1500
- const one = `${n2(g[0][0])} ${n2(g[0][1])} m ${n2(g[0][2])} ${n2(g[0][1])} l S
1501
- `;
1502
- this._s += `q
1503
- ${one}${`1 0 0 1 0 ${dy / 100} cm ${one}`.repeat(g.length - 1)}Q
1504
- `;
1505
- return;
1506
- }
1507
- this._s += g.map(([a, b, c, d]) => `${n2(a)} ${n2(b)} m ${n2(c)} ${n2(d)} l`).join(" ") + " S\n";
1508
- }
1509
- q() {
1510
- this.et();
1511
- this._s += "q\n";
1512
- this.saved.push({ ...this.st });
1513
- }
1514
- Q() {
1515
- this.et();
1516
- this._s += "Q\n";
1517
- this.st = this.saved.pop();
1518
- }
1519
- /**
1520
- * A line of plain text at (x, y). Lines follow one another in one text object, each placed relative to the
1521
- * last (in whole hundredths, so nothing drifts): most of a table page is these.
1522
- * @param {string} str the glyphs, as a literal string's escaped body (array: a TJ array's body)
1523
- */
1524
- text(pf, size, color, x, y, str, array = false) {
1525
- this.setPaint(color, null);
1526
- this.setFont(pf, size);
1527
- const X = Math.round(x * 10) * 10, Y = Math.round(y * 10) * 10;
1528
- if (!this.bt) {
1529
- this._s += "BT\n";
1530
- this.bt = true;
1531
- this.tx = 0;
1532
- this.ty = 0;
1533
- }
1534
- this._s += array ? `${(X - this.tx) / 100} ${(Y - this.ty) / 100} Td [${str}] TJ
1535
- ` : `${(X - this.tx) / 100} ${(Y - this.ty) / 100} Td (${str}) Tj
1536
- `;
1537
- this.tx = X;
1538
- this.ty = Y;
1539
- }
1540
- /** end the open text object, if any: anything but text needs that (and draws the lines waiting) */
1541
- et() {
1542
- if (this.bt) {
1543
- this._s += "ET\n";
1544
- this.bt = false;
1545
- }
1546
- if (this.lines) this.flushLines();
1547
- }
1548
- lineWidth(w) {
1549
- if (this.lines) this.flushLines();
1550
- this.setLineWidth(w);
1551
- }
1552
- setLineWidth(w) {
1553
- if (this.st.lw !== w) {
1554
- this._s += `${n3(w)} w
1555
- `;
1556
- this.st.lw = w;
1557
- }
1558
- }
1559
- /** the graphics state that sets these opacities, or undefined when they are set already */
1560
- gsFor(ca, CA) {
1561
- return ca === this.st.ca && CA === this.st.CA ? void 0 : this.shared.gs(ca, CA);
1562
- }
1563
- alpha(ca, CA) {
1564
- if (this.lines) this.flushLines();
1565
- this.setAlpha(ca, CA);
1566
- }
1567
- setAlpha(ca, CA) {
1568
- const g = this.gsFor(ca, CA);
1569
- if (g) {
1570
- this._s += `/${g} gs
1571
- `;
1572
- this.st.ca = ca;
1573
- this.st.CA = CA;
1574
- }
1575
- }
1576
- /** set up to fill with fill and/or stroke with stroke (width w, dash); the lines waiting are drawn first */
1577
- paint(fill, stroke, w = 1, dash = null) {
1578
- if (this.lines) this.flushLines();
1579
- this.setPaint(fill, stroke, w, dash);
1580
- }
1581
- setPaint(fill, stroke, w = 1, dash = null) {
1582
- const st = this.st;
1583
- if (fill && fill.rgb !== st.fill) {
1584
- this._s += `${fill.rgb} rg
1585
- `;
1586
- st.fill = fill.rgb;
1587
- }
1588
- if (stroke) {
1589
- if (stroke.rgb !== st.stroke) {
1590
- this._s += `${stroke.rgb} RG
1591
- `;
1592
- st.stroke = stroke.rgb;
1593
- }
1594
- this.setLineWidth(w);
1595
- const d = `[${(dash || []).map(n3).join(" ")}] 0`;
1596
- if (d !== st.dash) {
1597
- this._s += `${d} d
1598
- `;
1599
- st.dash = d;
1600
- }
1601
- }
1602
- this.setAlpha(fill ? fill.opacity : st.ca, stroke ? stroke.opacity : st.CA);
1603
- }
1604
- font(pf, size) {
1605
- if (this.lines) this.flushLines();
1606
- this.setFont(pf, size);
1607
- }
1608
- setFont(pf, size) {
1609
- const name = this.shared.font(pf);
1610
- if (name !== this.st.font || size !== this.st.size) {
1611
- this._s += `/${name} ${n3(size)} Tf
1612
- `;
1613
- this.st.font = name;
1614
- this.st.size = size;
1615
- }
1616
- }
1617
- };
1618
- function latin1(s) {
1619
- const B = (
1620
- /** @type {any} */
1621
- globalThis.Buffer
1622
- );
1623
- if (B) return B.from(s, "latin1");
1624
- const out = new Uint8Array(s.length);
1625
- for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
1626
- return out;
1627
- }
1628
- async function deflate(bytes) {
1629
- if (zslots.free > 0) zslots.free--;
1630
- else await new Promise((ok) => zslots.wait.push(ok));
1631
- try {
1632
- return await deflateNow(bytes);
1633
- } finally {
1634
- const next = zslots.wait.shift();
1635
- if (next) next();
1636
- else zslots.free++;
1637
- }
1638
- }
1639
- var zslots = { free: 4, wait: (
1640
- /** @type {(() => void)[]} */
1641
- []
1642
- ) };
1643
- var NODE_ZLIB = (
1644
- /** @type {any} */
1645
- globalThis.process?.getBuiltinModule?.("node:zlib")
1646
- );
1647
- async function deflateNow(bytes) {
1648
- const zlib = NODE_ZLIB;
1649
- if (zlib) return new Promise((ok, fail) => zlib.deflate(bytes, { level: 9 }, (e, z) => e ? fail(e) : ok(z)));
1650
- if (typeof CompressionStream === "undefined") return (await import("fflate")).zlibSync(bytes);
1651
- return new Uint8Array(await new Response(new Blob([bytes]).stream().pipeThrough(new CompressionStream("deflate"))).arrayBuffer());
1652
- }
1653
1659
  function roundRect(x, y, w, h, r) {
1654
1660
  r = Math.min(r, w / 2, h / 2);
1655
1661
  return `M ${x + r} ${y} H ${x + w - r} A ${r} ${r} 0 0 1 ${x + w} ${y + r} V ${y + h - r} A ${r} ${r} 0 0 1 ${x + w - r} ${y + h} H ${x + r} A ${r} ${r} 0 0 1 ${x} ${y + h - r} V ${y + r} A ${r} ${r} 0 0 1 ${x + r} ${y} Z`;
@@ -1657,4 +1663,4 @@ function roundRect(x, y, w, h, r) {
1657
1663
  export {
1658
1664
  exportPdf
1659
1665
  };
1660
- //# sourceMappingURL=chunk-5X4ZSSJT.js.map
1666
+ //# sourceMappingURL=chunk-KBT6ZGGO.js.map