@intentic/fileq 1.431.0 → 1.433.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.
Files changed (61) hide show
  1. package/NOTICE +58 -1
  2. package/README.md +22 -1
  3. package/bin/fileq-rg-pre +6 -2
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/app.js +4 -1
  6. package/dist/app.js.map +1 -1
  7. package/dist/commands/check.command.d.ts.map +1 -1
  8. package/dist/commands/check.command.js +12 -5
  9. package/dist/commands/check.command.js.map +1 -1
  10. package/dist/commands/derive.command.d.ts.map +1 -1
  11. package/dist/commands/derive.command.js +3 -2
  12. package/dist/commands/derive.command.js.map +1 -1
  13. package/dist/commands/read.command.d.ts.map +1 -1
  14. package/dist/commands/read.command.js +42 -7
  15. package/dist/commands/read.command.js.map +1 -1
  16. package/dist/commands/render.command.d.ts.map +1 -1
  17. package/dist/commands/render.command.js +23 -10
  18. package/dist/commands/render.command.js.map +1 -1
  19. package/dist/lib/derivers/docx-math-symbols.d.ts +14 -0
  20. package/dist/lib/derivers/docx-math-symbols.d.ts.map +1 -0
  21. package/dist/lib/derivers/docx-math-symbols.js +160 -0
  22. package/dist/lib/derivers/docx-math-symbols.js.map +1 -0
  23. package/dist/lib/derivers/docx-math.d.ts +15 -0
  24. package/dist/lib/derivers/docx-math.d.ts.map +1 -0
  25. package/dist/lib/derivers/docx-math.js +252 -0
  26. package/dist/lib/derivers/docx-math.js.map +1 -0
  27. package/dist/lib/derivers/docx.d.ts.map +1 -1
  28. package/dist/lib/derivers/docx.js +3 -2
  29. package/dist/lib/derivers/docx.js.map +1 -1
  30. package/dist/lib/derivers/pdf-furniture.d.ts.map +1 -1
  31. package/dist/lib/derivers/pdf-furniture.js +3 -0
  32. package/dist/lib/derivers/pdf-furniture.js.map +1 -1
  33. package/dist/lib/derivers/pdf-tables.d.ts +9 -0
  34. package/dist/lib/derivers/pdf-tables.d.ts.map +1 -0
  35. package/dist/lib/derivers/pdf-tables.js +319 -0
  36. package/dist/lib/derivers/pdf-tables.js.map +1 -0
  37. package/dist/lib/derivers/pdf.d.ts.map +1 -1
  38. package/dist/lib/derivers/pdf.js +3 -6
  39. package/dist/lib/derivers/pdf.js.map +1 -1
  40. package/dist/skill.d.ts.map +1 -1
  41. package/dist/skill.js +7 -2
  42. package/dist/skill.js.map +1 -1
  43. package/package.json +6 -6
  44. package/src/app.ts +4 -1
  45. package/src/cli.integration.test.ts +30 -8
  46. package/src/commands/check.command.ts +20 -5
  47. package/src/commands/derive.command.ts +3 -2
  48. package/src/commands/read.command.ts +56 -8
  49. package/src/commands/render.command.ts +33 -11
  50. package/src/derivers.integration.test.ts +104 -0
  51. package/src/lib/derivers/docx-math-symbols.ts +197 -0
  52. package/src/lib/derivers/docx-math.test.ts +131 -0
  53. package/src/lib/derivers/docx-math.ts +355 -0
  54. package/src/lib/derivers/docx.ts +5 -3
  55. package/src/lib/derivers/pdf-furniture.test.ts +9 -0
  56. package/src/lib/derivers/pdf-furniture.ts +5 -0
  57. package/src/lib/derivers/pdf-tables.test.ts +292 -0
  58. package/src/lib/derivers/pdf-tables.ts +465 -0
  59. package/src/lib/derivers/pdf.ts +5 -9
  60. package/src/render.integration.test.ts +5 -4
  61. package/src/skill.ts +7 -2
@@ -0,0 +1,292 @@
1
+ import { type PositionedItem, pageText } from "./pdf-tables.js";
2
+
3
+ // pdf.js text items as a page hands them over, built by position: each glyph run is half its font size wide per
4
+ // character, the width pdf.js reports for a typical proportional font near enough for gaps to read as they would.
5
+ interface At {
6
+ readonly size?: number;
7
+ readonly eol?: boolean;
8
+ readonly width?: number;
9
+ readonly rotated?: boolean;
10
+ }
11
+
12
+ const item = (str: string, x: number, y: number, at: At = {}): PositionedItem => {
13
+ const size = at.size ?? 10;
14
+ return {
15
+ str,
16
+ transform: at.rotated === true ? [0, size, -size, 0, x, y] : [size, 0, 0, size, x, y],
17
+ width: at.width ?? str.length * size * 0.5,
18
+ height: size,
19
+ hasEOL: at.eol ?? false,
20
+ };
21
+ };
22
+
23
+ // One visual line of prose as one item ending the line, the way most producers draw running text.
24
+ const line = (text: string, x: number, y: number, size = 10): PositionedItem => item(text, x, y, { size, eol: true });
25
+
26
+ // The page as it read before tables: items in drawing order, a break where pdf.js saw one, spaces folded.
27
+ const plainJoin = (items: readonly PositionedItem[]): string =>
28
+ items
29
+ .map((each) => each.str + (each.hasEOL ? "\n" : ""))
30
+ .join("")
31
+ .replaceAll(/[ \t]+/g, " ")
32
+ .trim();
33
+
34
+ // A row of cells at the given x positions, the last one ending the line.
35
+ const row = (y: number, cells: readonly (readonly [number, string])[]): PositionedItem[] =>
36
+ cells.map(([x, text], index) => item(text, x, y, { eol: index === cells.length - 1 }));
37
+
38
+ const COLUMNS = [80, 170, 240, 310, 380] as const;
39
+
40
+ describe("pageText", () => {
41
+ test("a page of prose reads exactly as its items joined in drawing order", () => {
42
+ const items = [
43
+ line("Quarterly results", 72, 720, 14),
44
+ item("Revenue grew ", 72, 690),
45
+ item("in every region", 137, 690, { eol: true }),
46
+ line("and margins held through the year.", 72, 678),
47
+ item("", 72, 666, { eol: true }),
48
+ line("Outlook remains steady.", 72, 654),
49
+ ];
50
+ expect(pageText(items)).toBe(plainJoin(items));
51
+ });
52
+
53
+ test("a borderless table drawn column by column comes back row by row, each value under its own header", () => {
54
+ // Drawn the way the stream order scrambled it: every value of a column before the next column.
55
+ const header = row(620, [
56
+ [COLUMNS[0], "SKU"],
57
+ [COLUMNS[1], "Bin"],
58
+ [COLUMNS[2], "Expected"],
59
+ [COLUMNS[3], "Actual"],
60
+ [COLUMNS[4], "Status"],
61
+ ]);
62
+ const byColumn = [
63
+ item("SKU-1", COLUMNS[0], 596),
64
+ item("SKU-2", COLUMNS[0], 572),
65
+ item("A-12", COLUMNS[1], 596),
66
+ item("450", COLUMNS[2], 596),
67
+ item("780", COLUMNS[2], 572),
68
+ item("778", COLUMNS[3], 572),
69
+ item("OK", COLUMNS[4], 572, { eol: true }),
70
+ ];
71
+ const items = [line("Inventory", 72, 660), ...header, ...byColumn, line("Signed off by the warehouse lead.", 72, 540)];
72
+ expect(pageText(items)).toBe(
73
+ [
74
+ "Inventory",
75
+ "",
76
+ "| SKU | Bin | Expected | Actual | Status |",
77
+ "| --- | --- | --- | --- | --- |",
78
+ "| SKU-1 | A-12 | 450 | | |",
79
+ "| SKU-2 | | 780 | 778 | OK |",
80
+ "",
81
+ "Signed off by the warehouse lead.",
82
+ ].join("\n"),
83
+ );
84
+ });
85
+
86
+ test("the table sits where the drawing order first reaches it, and the prose around it keeps its order", () => {
87
+ const table = [
88
+ ...row(500, [
89
+ [80, "Item"],
90
+ [200, "Qty"],
91
+ [300, "Price"],
92
+ ]),
93
+ ...row(486, [
94
+ [80, "Bolt"],
95
+ [200, "4"],
96
+ [300, "$1.00"],
97
+ ]),
98
+ ];
99
+ // The closing line is drawn first though it sits lowest on the page.
100
+ const items = [line("Thank you for your order.", 72, 300), line("Order 1182", 72, 560), ...table];
101
+ expect(pageText(items)).toBe(
102
+ ["Thank you for your order.\nOrder 1182", "| Item | Qty | Price |\n| --- | --- | --- |\n| Bolt | 4 | $1.00 |"].join("\n\n"),
103
+ );
104
+ });
105
+
106
+ test("a two-field form and rows of two cells are no table: three columns must recur", () => {
107
+ const items = [
108
+ ...row(700, [
109
+ [72, "Name:"],
110
+ [180, "Universal Studios"],
111
+ ]),
112
+ ...row(688, [
113
+ [72, "Category:"],
114
+ [180, "Film Distributor"],
115
+ ]),
116
+ ...row(676, [
117
+ [72, "Customer ID:"],
118
+ [180, "CUST-98765"],
119
+ ]),
120
+ ];
121
+ expect(pageText(items)).toBe(plainJoin(items));
122
+ });
123
+
124
+ test("margin line numbers beside two columns of prose make no table", () => {
125
+ const left = "The method converges for every input we tried and is";
126
+ const right = "Results in Table 2 hold across the three data sets we";
127
+ const items = Array.from({ length: 8 }, (_, index) => {
128
+ const y = 700 - index * 12;
129
+ return [item(String(160 + index), 40, y), item(`${left} ${index}`, 72, y, { width: 220 }), item(`${right} ${index}`, 310, y, { width: 220, eol: true })];
130
+ }).flat();
131
+ expect(pageText(items)).toBe(plainJoin(items));
132
+ });
133
+
134
+ test("a cell's second line joins the table as its own row, and a line drawn over the gap between two rows stays out", () => {
135
+ const items = [
136
+ ...row(400, [
137
+ [50, "Ln"],
138
+ [100, "Title"],
139
+ [260, "Format"],
140
+ [330, "Rate"],
141
+ ]),
142
+ ...row(388, [
143
+ [50, "1"],
144
+ [100, "Holiday Spectacular"],
145
+ [260, "IMAX 3D"],
146
+ [330, "$250"],
147
+ ]),
148
+ item("(Runtime: 142 min)", 100, 378, { size: 8, eol: true }),
149
+ ...row(364, [
150
+ [50, "2"],
151
+ [100, "Winter Wonderland"],
152
+ [260, "Standard"],
153
+ [330, "$150"],
154
+ ]),
155
+ ...row(352, [
156
+ [50, "3"],
157
+ [100, "New Year Mystery"],
158
+ [260, "4DX"],
159
+ [330, "$300"],
160
+ ]),
161
+ // A footer printed across the table, between rows 2 and 3.
162
+ line("All showtimes are approximate and subject to change.", 50, 358, 6),
163
+ ];
164
+ expect(pageText(items)).toBe(
165
+ [
166
+ "| Ln | Title | Format | Rate |",
167
+ "| --- | --- | --- | --- |",
168
+ "| 1 | Holiday Spectacular | IMAX 3D | $250 |",
169
+ "| | (Runtime: 142 min) | | |",
170
+ "| 2 | Winter Wonderland | Standard | $150 |",
171
+ "| 3 | New Year Mystery | 4DX | $300 |",
172
+ "",
173
+ "All showtimes are approximate and subject to change.",
174
+ ].join("\n"),
175
+ );
176
+ });
177
+
178
+ test("a heading spanning a label and its value does not merge their columns", () => {
179
+ const items = [
180
+ ...row(500, [
181
+ [100, "Customer Information"],
182
+ [380, "Vehicle Information"],
183
+ ]),
184
+ ...row(486, [
185
+ [77, "Insured name"],
186
+ [158, "Gabriel Diaz"],
187
+ [310, "Year"],
188
+ [370, "2022"],
189
+ ]),
190
+ ...row(472, [
191
+ [77, "Claim #"],
192
+ [158, "SF-1008"],
193
+ [310, "Make"],
194
+ [370, "Jeep"],
195
+ ]),
196
+ ];
197
+ expect(pageText(items)).toBe(
198
+ [
199
+ // A spanning cell goes to the column it overlaps most.
200
+ "| | Customer Information | | Vehicle Information |",
201
+ "| --- | --- | --- | --- |",
202
+ "| Insured name | Gabriel Diaz | Year | 2022 |",
203
+ "| Claim # | SF-1008 | Make | Jeep |",
204
+ ].join("\n"),
205
+ );
206
+ });
207
+
208
+ test("right-aligned amounts of different lengths share their column", () => {
209
+ // Each amount ends at x = 400, so where it starts depends on how many digits it has.
210
+ const amount = (text: string, y: number): PositionedItem => item(text, 400 - text.length * 5, y, { eol: true });
211
+ const items = [
212
+ ...row(300, [
213
+ [72, "Account"],
214
+ [200, "Region"],
215
+ ]),
216
+ amount("Balance", 300),
217
+ ...row(288, [
218
+ [72, "Cash"],
219
+ [200, "EU"],
220
+ ]),
221
+ amount("1,250,000.00", 288),
222
+ ...row(276, [
223
+ [72, "Bonds"],
224
+ [200, "US"],
225
+ ]),
226
+ amount("75.10", 276),
227
+ ];
228
+ expect(pageText(items)).toBe(
229
+ ["| Account | Region | Balance |", "| --- | --- | --- |", "| Cash | EU | 1,250,000.00 |", "| Bonds | US | 75.10 |"].join("\n"),
230
+ );
231
+ });
232
+
233
+ test("on a two-column page a table in one column takes none of the other column's lines", () => {
234
+ const prose = (index: number): string => `Line ${index} of the left column runs on for quite a while here`;
235
+ const left = Array.from({ length: 10 }, (_, index) => item(prose(index), 54, 700 - index * 12, { width: 230, eol: true }));
236
+ const right = [
237
+ ...Array.from({ length: 6 }, (_, index) => item(`Right column line ${index} carries ordinary prose text too`, 310, 700 - index * 12, { width: 230, eol: true })),
238
+ ...row(628, [
239
+ [320, "Set"],
240
+ [400, "Naive"],
241
+ [460, "Flexible"],
242
+ ]),
243
+ ...row(616, [
244
+ [320, "Breast"],
245
+ [400, "95.9"],
246
+ [460, "96.7"],
247
+ ]),
248
+ ...row(604, [
249
+ [320, "Glass"],
250
+ [400, "61.9"],
251
+ [460, "83.8"],
252
+ ]),
253
+ ];
254
+ const text = pageText([...left, ...right]);
255
+ expect(text).toContain("| Set | Naive | Flexible |\n| --- | --- | --- |\n| Breast | 95.9 | 96.7 |\n| Glass | 61.9 | 83.8 |");
256
+ expect(text.startsWith(plainJoin(left))).toBe(true);
257
+ expect(text).not.toContain(`| ${prose(6)}`);
258
+ });
259
+
260
+ test("a pipe inside a cell is escaped so it cannot end the cell", () => {
261
+ const items = [
262
+ ...row(300, [
263
+ [72, "Flag"],
264
+ [160, "Meaning"],
265
+ [300, "Default"],
266
+ ]),
267
+ ...row(288, [
268
+ [72, "-a|-b"],
269
+ [160, "either"],
270
+ [300, "off"],
271
+ ]),
272
+ ];
273
+ expect(pageText(items)).toContain("| -a\\|-b | either | off |");
274
+ });
275
+
276
+ test("rotated text takes no part in a table", () => {
277
+ const items = [
278
+ ...row(300, [
279
+ [72, "A"],
280
+ [160, "B"],
281
+ [300, "C"],
282
+ ]),
283
+ item("DRAFT", 30, 280, { rotated: true }),
284
+ ...row(288, [
285
+ [72, "1"],
286
+ [160, "2"],
287
+ [300, "3"],
288
+ ]),
289
+ ];
290
+ expect(pageText(items)).toBe(["| A | B | C |\n| --- | --- | --- |\n| 1 | 2 | 3 |", "DRAFT"].join("\n\n"));
291
+ });
292
+ });