@evotecit/officeimo 0.1.2 → 0.1.3
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/README.md +43 -49
- package/bundles/officeimo-canopyx.js +966 -122
- package/bundles/officeimo-canopyx.mjs +929 -92
- package/bundles/officeimo-csv.js +18 -15
- package/bundles/officeimo-csv.mjs +16 -13
- package/bundles/officeimo-datatables.js +168 -82
- package/bundles/officeimo-datatables.mjs +140 -54
- package/bundles/officeimo-pdf.js +148 -65
- package/bundles/officeimo-pdf.mjs +124 -41
- package/bundles/officeimo.js +168 -82
- package/bundles/officeimo.mjs +140 -54
- package/dist/csv/index.js +16 -13
- package/dist/integrations/canopyx/diagnostics.d.ts +3 -0
- package/dist/integrations/canopyx/diagnostics.js +17 -0
- package/dist/integrations/canopyx/grouping.d.ts +6 -0
- package/dist/integrations/canopyx/grouping.js +188 -0
- package/dist/integrations/canopyx/index.d.ts +2 -2
- package/dist/integrations/canopyx/index.js +72 -15
- package/dist/integrations/canopyx/metadata.d.ts +4 -0
- package/dist/integrations/canopyx/metadata.js +51 -0
- package/dist/integrations/canopyx/presentation.d.ts +8 -0
- package/dist/integrations/canopyx/presentation.js +40 -0
- package/dist/integrations/canopyx/rule-predicates.d.ts +3 -0
- package/dist/integrations/canopyx/rule-predicates.js +110 -0
- package/dist/integrations/canopyx/rules.d.ts +6 -0
- package/dist/integrations/canopyx/rules.js +176 -0
- package/dist/integrations/canopyx/source.js +24 -22
- package/dist/integrations/canopyx/types.d.ts +89 -8
- package/dist/integrations/canopyx/workbook.d.ts +6 -0
- package/dist/integrations/canopyx/workbook.js +52 -0
- package/dist/pdf/font-resources.js +33 -14
- package/dist/pdf/pages.js +60 -14
- package/dist/pdf/table-band-flow.js +7 -2
- package/dist/pdf/table-band-plan.js +9 -1
- package/dist/pdf/table-layout.js +6 -2
- package/dist/pdf/table-structure.js +9 -8
- package/package.json +1 -1
package/bundles/officeimo.mjs
CHANGED
|
@@ -5374,29 +5374,32 @@ const { captureCsvOptions } = _m52;
|
|
|
5374
5374
|
|
|
5375
5375
|
|
|
5376
5376
|
|
|
5377
|
-
function csvField(value, delimiter, protect, quote, booleanText
|
|
5378
|
-
|
|
5379
|
-
value = nullValue;
|
|
5377
|
+
function csvField(value, delimiter, protect, quote, booleanText) {
|
|
5378
|
+
const kind = typeof value;
|
|
5380
5379
|
let text;
|
|
5381
5380
|
if (value == null)
|
|
5382
5381
|
text = "";
|
|
5382
|
+
else if (kind === "string")
|
|
5383
|
+
text = value;
|
|
5384
|
+
else if (kind === "number") {
|
|
5385
|
+
text = Number.isFinite(value) ? String(value) : "";
|
|
5386
|
+
// Numeric text has no CSV delimiter, quote or line break to escape.
|
|
5387
|
+
return quote === "all" ? '"' + text + '"' : text;
|
|
5388
|
+
}
|
|
5389
|
+
else if (kind === "boolean")
|
|
5390
|
+
text = booleanText[value ? "true" : "false"];
|
|
5383
5391
|
else if (isDate(value))
|
|
5384
5392
|
text = Number.isFinite(value.getTime()) ? value.toISOString() : "";
|
|
5385
|
-
else if (typeof value === "boolean")
|
|
5386
|
-
text = booleanText[value ? "true" : "false"];
|
|
5387
|
-
else if (typeof value === "number")
|
|
5388
|
-
text = Number.isFinite(value) ? String(value) : "";
|
|
5389
|
-
else if (typeof value === "string")
|
|
5390
|
-
text = value;
|
|
5391
5393
|
else {
|
|
5392
5394
|
if (typeof value.then === "function")
|
|
5393
5395
|
void Promise.resolve(value).catch(() => { });
|
|
5394
5396
|
throw new TypeError("CSV cells and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
|
|
5395
5397
|
}
|
|
5396
|
-
|
|
5398
|
+
// Only ASCII spaces, controls and markers through @ can begin the protected prefix.
|
|
5399
|
+
if (protect && (kind === "string" || kind === "boolean") && text.charCodeAt(0) <= 64 && /^ *[=+\-@\t\r\n]/.test(text))
|
|
5397
5400
|
text = "'" + text;
|
|
5398
|
-
return quote === "all" || (quote === "strings" &&
|
|
5399
|
-
? '"' + text.replace(/"/g, '""') + '"' : text;
|
|
5401
|
+
return quote === "all" || (quote === "strings" && kind === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
|
|
5402
|
+
? '"' + (text.includes('"') ? text.replace(/"/g, '""') : text) + '"' : text;
|
|
5400
5403
|
}
|
|
5401
5404
|
async function writeCsvTo(rows, destination, configuration) {
|
|
5402
5405
|
const options = captureCsvOptions(configuration);
|
|
@@ -5448,7 +5451,7 @@ async function write(rows, sink, options) {
|
|
|
5448
5451
|
value = options.nullValue;
|
|
5449
5452
|
budget.cell(typeof value === "boolean" ? booleanText[value ? "true" : "false"] : value);
|
|
5450
5453
|
checkAbort(signal);
|
|
5451
|
-
text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText
|
|
5454
|
+
text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText);
|
|
5452
5455
|
if (text.length >= buffer.chunkSize || (i & 127) === 127 && taskYieldDue()) {
|
|
5453
5456
|
if (buffer.append(text))
|
|
5454
5457
|
return buffer.flush().then(() => record(values, header, i + 1, snapshot));
|
|
@@ -7141,7 +7144,8 @@ const { pdfNumber, unicodeHex } = _m59;
|
|
|
7141
7144
|
|
|
7142
7145
|
const { checkAbort, pause, taskYieldDue } = _m4;
|
|
7143
7146
|
|
|
7144
|
-
const
|
|
7147
|
+
const hexBytes = Object.freeze(Array.from({ length: 256 }, (_, byte) => byte.toString(16).padStart(2, "0")));
|
|
7148
|
+
function cidHex(cid) { return hexBytes[cid >>> 8] + hexBytes[cid & 255]; }
|
|
7145
7149
|
class PdfFontResource {
|
|
7146
7150
|
index;
|
|
7147
7151
|
bold;
|
|
@@ -7172,12 +7176,16 @@ class PdfFontResource {
|
|
|
7172
7176
|
width(scalar) {
|
|
7173
7177
|
if (this.shared)
|
|
7174
7178
|
return this.shared.width(scalar);
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7179
|
+
if (this.program) {
|
|
7180
|
+
const existing = this.mappings.get(scalar);
|
|
7181
|
+
if (existing)
|
|
7182
|
+
return existing.width;
|
|
7183
|
+
}
|
|
7184
|
+
else {
|
|
7185
|
+
const standard = this.standardWidths.get(scalar);
|
|
7186
|
+
if (standard !== undefined)
|
|
7187
|
+
return standard;
|
|
7188
|
+
}
|
|
7181
7189
|
const resolved = resolveScalar(scalar, this.program, this.bold);
|
|
7182
7190
|
if (!resolved.supported) {
|
|
7183
7191
|
if (resolved.code === "unpaired-surrogate")
|
|
@@ -7190,7 +7198,8 @@ class PdfFontResource {
|
|
|
7190
7198
|
}
|
|
7191
7199
|
if (this.mappings.size >= 65535)
|
|
7192
7200
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct Unicode scalars.");
|
|
7193
|
-
const
|
|
7201
|
+
const cid = this.mappings.size + 1;
|
|
7202
|
+
const mapping = { cid, hex: cidHex(cid), glyph: resolved.glyph, width: resolved.width, text: String.fromCodePoint(scalar) };
|
|
7194
7203
|
this.mappings.set(scalar, mapping);
|
|
7195
7204
|
return mapping.width;
|
|
7196
7205
|
}
|
|
@@ -7203,8 +7212,20 @@ class PdfFontResource {
|
|
|
7203
7212
|
let hex = "";
|
|
7204
7213
|
for (const char of text) {
|
|
7205
7214
|
const cp = char.codePointAt(0);
|
|
7206
|
-
this.
|
|
7207
|
-
|
|
7215
|
+
if (this.program) {
|
|
7216
|
+
let mapping = this.mappings.get(cp);
|
|
7217
|
+
// Layout normally registered the scalar already; validate only a newly painted scalar.
|
|
7218
|
+
if (!mapping) {
|
|
7219
|
+
this.width(cp);
|
|
7220
|
+
mapping = this.mappings.get(cp);
|
|
7221
|
+
}
|
|
7222
|
+
hex += mapping.hex;
|
|
7223
|
+
}
|
|
7224
|
+
else {
|
|
7225
|
+
if (!this.standardWidths.has(cp))
|
|
7226
|
+
this.width(cp);
|
|
7227
|
+
hex += hexBytes[standardCode(cp)];
|
|
7228
|
+
}
|
|
7208
7229
|
}
|
|
7209
7230
|
return "<" + hex + ">";
|
|
7210
7231
|
}
|
|
@@ -7219,10 +7240,11 @@ class PdfFontResource {
|
|
|
7219
7240
|
if (!mapping) {
|
|
7220
7241
|
if (this.mappings.size >= 65535)
|
|
7221
7242
|
throw new OfficeIMOError("RESOURCE_LIMIT", "A PDF font supports at most 65,535 distinct CID mappings.");
|
|
7222
|
-
|
|
7243
|
+
const cid = this.mappings.size + 1;
|
|
7244
|
+
mapping = { cid, hex: cidHex(cid), glyph, width: this.program.widths[glyph], text };
|
|
7223
7245
|
this.mappings.set(key, mapping);
|
|
7224
7246
|
}
|
|
7225
|
-
return "<" + mapping.
|
|
7247
|
+
return "<" + mapping.hex + ">";
|
|
7226
7248
|
}
|
|
7227
7249
|
async write(objects, compression) {
|
|
7228
7250
|
checkAbort(this.signal);
|
|
@@ -7271,7 +7293,7 @@ class PdfFontResource {
|
|
|
7271
7293
|
const batch = mapped.slice(i, i + 100);
|
|
7272
7294
|
cmap += batch.length + " beginbfchar\n";
|
|
7273
7295
|
for (const [, m] of batch)
|
|
7274
|
-
cmap += "<" + m.
|
|
7296
|
+
cmap += "<" + m.hex + "> <" + unicodeHex(m.text) + ">\n";
|
|
7275
7297
|
cmap += "endbfchar\n";
|
|
7276
7298
|
if (taskYieldDue())
|
|
7277
7299
|
await pause();
|
|
@@ -7322,7 +7344,7 @@ class PdfFontResources {
|
|
|
7322
7344
|
if (!found)
|
|
7323
7345
|
this.explicitSelections.set(explicit, selections);
|
|
7324
7346
|
}
|
|
7325
|
-
const key =
|
|
7347
|
+
const key = (bold ? 2 : 0) | (italic ? 1 : 0), existing = selections.get(key);
|
|
7326
7348
|
if (existing)
|
|
7327
7349
|
return existing;
|
|
7328
7350
|
const { font, syntheticBold, syntheticItalic } = explicit ? { font: explicit, syntheticBold: bold, syntheticItalic: italic } : selectFont(this.fonts, bold, italic);
|
|
@@ -7908,6 +7930,14 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
|
|
|
7908
7930
|
for (const row of rows) {
|
|
7909
7931
|
const cells = [];
|
|
7910
7932
|
for (const cell of row.cells) {
|
|
7933
|
+
// Ordinary data and leaf headings keep their captured width and lines in every band.
|
|
7934
|
+
// Look up their physical position without allocating another per-row column index.
|
|
7935
|
+
if (cell.span === 1) {
|
|
7936
|
+
const first = band.columns.indexOf(cell.first);
|
|
7937
|
+
if (first >= 0)
|
|
7938
|
+
cells.push({ ...cell, source: cell.source ?? cell, first });
|
|
7939
|
+
continue;
|
|
7940
|
+
}
|
|
7911
7941
|
for (let first = 0; first < band.columns.length;) {
|
|
7912
7942
|
const source = band.columns[first];
|
|
7913
7943
|
if (source < cell.first || source >= cell.first + cell.span) {
|
|
@@ -7918,7 +7948,7 @@ async function projectBandRows(rows, band, widths, settings, fonts) {
|
|
|
7918
7948
|
while (end < band.columns.length && band.columns[end] === band.columns[end - 1] + 1 && band.columns[end] < cell.first + cell.span)
|
|
7919
7949
|
end++;
|
|
7920
7950
|
const width = band.columns.slice(first, end).reduce((sum, index) => sum + widths[index], 0);
|
|
7921
|
-
const lines =
|
|
7951
|
+
const lines = await wrapPdfText(cell.captured, fonts, settings.fontSize, width - settings.padding * 2, settings, cell.style.wrapText !== false);
|
|
7922
7952
|
cells.push({ ...cell, source: cell.source ?? cell, first, span: end - first, width, lines,
|
|
7923
7953
|
lineHeight: lines.reduce((height, line) => Math.max(height, line.lineHeight), cell.font.lineHeight(settings.fontSize)) });
|
|
7924
7954
|
first = end;
|
|
@@ -8070,8 +8100,12 @@ class PdfTableLayout {
|
|
|
8070
8100
|
lines };
|
|
8071
8101
|
}
|
|
8072
8102
|
row(cells) {
|
|
8073
|
-
|
|
8074
|
-
|
|
8103
|
+
let lines = 1, lineHeight = this.lineHeight;
|
|
8104
|
+
for (let index = 0; index < cells.length; index++) {
|
|
8105
|
+
const cell = cells[index];
|
|
8106
|
+
lines = Math.max(lines, cell.lines.length);
|
|
8107
|
+
lineHeight = Math.max(lineHeight, cell.lineHeight);
|
|
8108
|
+
}
|
|
8075
8109
|
return { cells, lines, lineHeight, height: lines * lineHeight + this.settings.padding * 2 };
|
|
8076
8110
|
}
|
|
8077
8111
|
async headers() {
|
|
@@ -8224,7 +8258,7 @@ class PdfTableBandFlow {
|
|
|
8224
8258
|
await this.flush();
|
|
8225
8259
|
}
|
|
8226
8260
|
async row(row, allowFirstFragment = false) {
|
|
8227
|
-
const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight =
|
|
8261
|
+
const { padding, fontSize, options } = this.layout.settings, minimumLines = this.layout.minimumRowLines(row), minimumHeight = minimumLines * row.lineHeight + padding * 2;
|
|
8228
8262
|
if (minimumHeight > this.painter.firstFullCapacity + .001 || minimumHeight > this.painter.continuationCapacity + .001)
|
|
8229
8263
|
throw new RangeError("Repeated PDF identifiers must fit intact below the first and continued band headings/context.");
|
|
8230
8264
|
// Keep ordinary rows intact when they fit fresh. A kept heading/caption can deliberately
|
|
@@ -8258,9 +8292,14 @@ class PdfTableBandFlow {
|
|
|
8258
8292
|
let remaining = false;
|
|
8259
8293
|
const cells = rows[0].cells.map(cell => {
|
|
8260
8294
|
const source = this.layout.bands[index].columns[cell.first];
|
|
8261
|
-
const repeated = this.layout.repeatedColumn(source),
|
|
8295
|
+
const repeated = this.layout.repeatedColumn(source), reusable = cell.span === 1 && (cell.source?.span ?? 1) === 1 && (cell.rowSpan ?? 1) === 1 &&
|
|
8296
|
+
cell.height === undefined && first === 0 && (repeated || lines >= cell.lines.length);
|
|
8297
|
+
const visible = repeated || reusable ? cell.lines : cell.lines.slice(first, first + lines);
|
|
8262
8298
|
if (!repeated && (visible.length > 0 || cell.link !== undefined))
|
|
8263
8299
|
remaining = true;
|
|
8300
|
+
// A complete first fragment already owns these lines and their maximum font metrics.
|
|
8301
|
+
if (reusable)
|
|
8302
|
+
return cell;
|
|
8264
8303
|
const { height: _height, ...plain } = cell;
|
|
8265
8304
|
return { ...plain, lines: visible,
|
|
8266
8305
|
lineHeight: visible.reduce((value, line) => Math.max(value, line.lineHeight), cell.font.lineHeight(fontSize)),
|
|
@@ -8368,30 +8407,31 @@ class PdfTableStructure {
|
|
|
8368
8407
|
return row.cells.map(cell => this.cells.get(cell));
|
|
8369
8408
|
const rowId = this.structure.element("TR", parent);
|
|
8370
8409
|
this.rows.set(row, rowId);
|
|
8371
|
-
const headers = row.cells.map((cell, index) => rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex);
|
|
8372
8410
|
// Allocate in source order, then resolve every row header before associating even earlier data cells.
|
|
8373
8411
|
// Generated summary labels override detail roles so numeric subtotal cells never become row headers.
|
|
8374
8412
|
const ids = row.cells.map((cell, index) => {
|
|
8375
|
-
const
|
|
8413
|
+
const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
|
|
8414
|
+
const id = this.structure.element(header ? "TH" : "TD", rowId);
|
|
8376
8415
|
this.cells.set(cell, id);
|
|
8377
8416
|
return id;
|
|
8378
8417
|
});
|
|
8379
|
-
|
|
8418
|
+
let rowHeaders;
|
|
8380
8419
|
for (let index = 0; index < ids.length; index++)
|
|
8381
|
-
if (
|
|
8382
|
-
rowHeaders.push(await this.structure.identifier(ids[index]));
|
|
8420
|
+
if (rowHeaderIndex === undefined ? row.cells[index].rowHeader === true : index === rowHeaderIndex)
|
|
8421
|
+
(rowHeaders ??= []).push(await this.structure.identifier(ids[index]));
|
|
8383
8422
|
for (let index = 0; index < row.cells.length; index++) {
|
|
8384
8423
|
const cell = row.cells[index];
|
|
8385
|
-
if (!rowHeaders
|
|
8424
|
+
if (!rowHeaders && cell.span === 1 && (cell.rowSpan ?? 1) === 1) {
|
|
8386
8425
|
const attributes = this.ordinaryAttributes[cell.first] ??=
|
|
8387
8426
|
await this.structure.attributeReference(this.attributeDictionary(cell, this.associations(cell)));
|
|
8388
8427
|
this.structure.setAttributes(ids[index], attributes);
|
|
8389
8428
|
continue;
|
|
8390
8429
|
}
|
|
8391
8430
|
const associations = this.associations(cell);
|
|
8392
|
-
|
|
8431
|
+
const header = rowHeaderIndex === undefined ? cell.rowHeader === true : index === rowHeaderIndex;
|
|
8432
|
+
if (!header && rowHeaders)
|
|
8393
8433
|
associations.push(...rowHeaders);
|
|
8394
|
-
this.structure.setAttributes(ids[index], this.attributes(cell, associations,
|
|
8434
|
+
this.structure.setAttributes(ids[index], this.attributes(cell, associations, header ? "Row" : undefined));
|
|
8395
8435
|
}
|
|
8396
8436
|
return ids;
|
|
8397
8437
|
}
|
|
@@ -8575,7 +8615,8 @@ class PdfPages {
|
|
|
8575
8615
|
outlines;
|
|
8576
8616
|
references = [];
|
|
8577
8617
|
current = 0;
|
|
8578
|
-
commands =
|
|
8618
|
+
commands = "";
|
|
8619
|
+
commandParts = [];
|
|
8579
8620
|
commandBytes = 0;
|
|
8580
8621
|
annotations = [];
|
|
8581
8622
|
hyperlinks = 0;
|
|
@@ -8593,6 +8634,12 @@ class PdfPages {
|
|
|
8593
8634
|
pendingBookmarks = [];
|
|
8594
8635
|
pageNumberWidth = 0;
|
|
8595
8636
|
colors = new Map();
|
|
8637
|
+
textFont;
|
|
8638
|
+
textSize = 0;
|
|
8639
|
+
textColor = "";
|
|
8640
|
+
textPrefix = "";
|
|
8641
|
+
rectangleLefts;
|
|
8642
|
+
rectangleColumns = [];
|
|
8596
8643
|
externalObjects = new Map();
|
|
8597
8644
|
bandFlow;
|
|
8598
8645
|
bandCellBudget = false;
|
|
@@ -8659,7 +8706,7 @@ class PdfPages {
|
|
|
8659
8706
|
}
|
|
8660
8707
|
add(command) {
|
|
8661
8708
|
this.retainPageBytes(command.length);
|
|
8662
|
-
this.commands
|
|
8709
|
+
this.commands += command;
|
|
8663
8710
|
}
|
|
8664
8711
|
retainPageBytes(length) {
|
|
8665
8712
|
this.commandBytes += length;
|
|
@@ -8679,9 +8726,17 @@ class PdfPages {
|
|
|
8679
8726
|
return this.structure ? "/Artifact << /Type /" + type + " >> BDC\n" + command + "EMC\n" : command;
|
|
8680
8727
|
}
|
|
8681
8728
|
text(text, font, size, x, baseline, foreground = "111827", element) {
|
|
8682
|
-
const n = pdfNumber
|
|
8683
|
-
|
|
8684
|
-
|
|
8729
|
+
const n = pdfNumber;
|
|
8730
|
+
if (font !== this.textFont || size !== this.textSize || foreground !== this.textColor) {
|
|
8731
|
+
const shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(foreground);
|
|
8732
|
+
// Keep one prefix, independent of report size. Resource identity includes synthetic styling.
|
|
8733
|
+
this.textPrefix = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
|
|
8734
|
+
(font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ") + "1 0 " + n(shear) + " 1 ";
|
|
8735
|
+
this.textFont = font;
|
|
8736
|
+
this.textSize = size;
|
|
8737
|
+
this.textColor = foreground;
|
|
8738
|
+
}
|
|
8739
|
+
const command = this.textPrefix + n(x) + " " + n(baseline) + " Tm " + font.encode(text) + " Tj ET Q\n";
|
|
8685
8740
|
this.add(this.structure && element !== undefined ? this.structure.mark(element) + command + "EMC\n" : this.artifact(command, "Pagination"));
|
|
8686
8741
|
}
|
|
8687
8742
|
link(link, x, bottom, width, height, element) {
|
|
@@ -8711,8 +8766,8 @@ class PdfPages {
|
|
|
8711
8766
|
for (const segment of line.segments) {
|
|
8712
8767
|
const registered = marks?.get(segment), owner = registered?.owner ?? (segment.link && this.structure && element !== undefined ? this.structure.link(element, segment.link) : element);
|
|
8713
8768
|
if (segment.glyphs) {
|
|
8714
|
-
const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0;
|
|
8715
|
-
let cursor = x, command = "q " +
|
|
8769
|
+
const font = segment.font, n = pdfNumber, shear = font.syntheticItalic ? .213 : 0, rgb = this.rgb(segment.color ?? "111827");
|
|
8770
|
+
let cursor = x, command = "q " + rgb + " rg " + rgb + " RG\nBT /" + font.name + " " + n(size) + " Tf " +
|
|
8716
8771
|
(font.syntheticBold ? n(size * .025) + " w 2 Tr " : "0 Tr ");
|
|
8717
8772
|
for (const glyph of segment.glyphs) {
|
|
8718
8773
|
command += "1 0 " + n(shear) + " 1 " + n(cursor + (glyph.xOffset + shear * glyph.yOffset) * size / 1000) + " " + n(baseline + glyph.yOffset * size / 1000) + " Tm " + font.encodeGlyph(glyph.id, glyph.logicalText) + " Tj\n";
|
|
@@ -8760,7 +8815,8 @@ class PdfPages {
|
|
|
8760
8815
|
this.current = this.objects.reserve();
|
|
8761
8816
|
this.references.push(this.current);
|
|
8762
8817
|
}
|
|
8763
|
-
this.commands =
|
|
8818
|
+
this.commands = "";
|
|
8819
|
+
this.commandParts = [];
|
|
8764
8820
|
this.annotations = [];
|
|
8765
8821
|
this.commandBytes = 0;
|
|
8766
8822
|
this.bodyAdded = false;
|
|
@@ -8843,15 +8899,32 @@ class PdfPages {
|
|
|
8843
8899
|
if (!this.layout)
|
|
8844
8900
|
throw new Error("A table layout is required before drawing rows.");
|
|
8845
8901
|
this.bodyAdded = true;
|
|
8846
|
-
const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2;
|
|
8902
|
+
const { padding, fontSize } = this.settings, n = pdfNumber, height = lineCount * row.lineHeight + padding * 2, lefts = this.layout.lefts;
|
|
8903
|
+
// One geometry token per active physical column; table/band changes release the old tokens.
|
|
8904
|
+
if (this.rectangleLefts !== lefts) {
|
|
8905
|
+
this.rectangleLefts = lefts;
|
|
8906
|
+
this.rectangleColumns = [];
|
|
8907
|
+
}
|
|
8908
|
+
let rectangleHeight, rectangleBottom = "", rectangleHeightText = "";
|
|
8847
8909
|
for (const [index, cell] of row.cells.entries()) {
|
|
8848
8910
|
if (this.bandCellBudget)
|
|
8849
8911
|
this.settings.budget.cell(this.settings.budget.limits.maxTextCharacters === undefined ? "" :
|
|
8850
8912
|
(cell.height === undefined ? cell.lines.slice(firstLine, firstLine + lineCount) : cell.lines).map(line => line.text).join(""));
|
|
8851
|
-
const x =
|
|
8913
|
+
const x = lefts[cell.first], cellHeight = cell.height ?? height;
|
|
8914
|
+
if (cellHeight !== rectangleHeight) {
|
|
8915
|
+
rectangleBottom = n(this.y - cellHeight);
|
|
8916
|
+
rectangleHeightText = n(cellHeight);
|
|
8917
|
+
rectangleHeight = cellHeight;
|
|
8918
|
+
}
|
|
8919
|
+
let horizontal = this.rectangleColumns[cell.first];
|
|
8920
|
+
if (!horizontal || horizontal.x !== x || horizontal.width !== cell.width) {
|
|
8921
|
+
horizontal = { x, width: cell.width, left: n(x), widthText: n(cell.width) };
|
|
8922
|
+
this.rectangleColumns[cell.first] = horizontal;
|
|
8923
|
+
}
|
|
8924
|
+
const rectangle = horizontal.left + " " + rectangleBottom + " " + horizontal.widthText + " " + rectangleHeightText;
|
|
8852
8925
|
if (cell.style.background)
|
|
8853
|
-
this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " +
|
|
8854
|
-
this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " +
|
|
8926
|
+
this.add(this.artifact("q " + this.rgb(cell.style.background) + " rg " + rectangle + " re f Q\n"));
|
|
8927
|
+
this.add(this.artifact("q 0.82 0.85 0.89 RG 0.4 w " + rectangle + " re S Q\n"));
|
|
8855
8928
|
const element = elements?.[index], artifact = cell.semanticArtifact || repeated[index], owner = cell.link && this.structure && element !== undefined ? this.structure.link(element, cell.link) : element;
|
|
8856
8929
|
for (let line = firstLine; line < Math.min(cell.lines.length, cell.height ? cell.lines.length : firstLine + lineCount); line++) {
|
|
8857
8930
|
const text = cell.lines[line], left = cell.style.alignment === "right" ? cell.width - padding - text.width : cell.style.alignment === "center" ? (cell.width - text.width) / 2 : padding;
|
|
@@ -8861,6 +8934,7 @@ class PdfPages {
|
|
|
8861
8934
|
this.link(cell.link, x, this.y - cellHeight, cell.width, cellHeight, owner);
|
|
8862
8935
|
}
|
|
8863
8936
|
this.y -= row.structured ? row.height : height;
|
|
8937
|
+
this.sealCommands();
|
|
8864
8938
|
}
|
|
8865
8939
|
async block(rows) {
|
|
8866
8940
|
if (this.bandFlow)
|
|
@@ -9186,9 +9260,22 @@ class PdfPages {
|
|
|
9186
9260
|
marker: { line: item.marker, gap: item.markerGap, ...(label === undefined ? {} : { owner: label }) } });
|
|
9187
9261
|
await this.structure?.complete(li);
|
|
9188
9262
|
}
|
|
9263
|
+
sealCommands() {
|
|
9264
|
+
if (this.commands) {
|
|
9265
|
+
this.commandParts.push(this.commands);
|
|
9266
|
+
this.commands = "";
|
|
9267
|
+
}
|
|
9268
|
+
}
|
|
9269
|
+
takeCommands() {
|
|
9270
|
+
this.sealCommands();
|
|
9271
|
+
const content = this.commandParts.join("");
|
|
9272
|
+
// Encoding and awaited delivery own the page value; the next page starts independently.
|
|
9273
|
+
this.commandParts = [];
|
|
9274
|
+
return content;
|
|
9275
|
+
}
|
|
9189
9276
|
async finishPage() {
|
|
9190
9277
|
const contents = this.objects.reserve(), { page, options } = this.settings;
|
|
9191
|
-
await this.objects.stream(contents, this.
|
|
9278
|
+
await this.objects.stream(contents, this.takeCommands(), "", options.compression !== false);
|
|
9192
9279
|
const annotations = [];
|
|
9193
9280
|
for (const annotation of this.annotations) {
|
|
9194
9281
|
annotations.push(annotation.id);
|
|
@@ -9200,7 +9287,6 @@ class PdfPages {
|
|
|
9200
9287
|
(annotations.length ? " /Annots [" + annotations.map(id => id + " 0 R").join(" ") + "]" : "") + " >>");
|
|
9201
9288
|
if (this.structure)
|
|
9202
9289
|
await this.structure.finishPage();
|
|
9203
|
-
this.commands = [];
|
|
9204
9290
|
this.annotations = [];
|
|
9205
9291
|
this.commandBytes = 0;
|
|
9206
9292
|
this.current = 0;
|
package/dist/csv/index.js
CHANGED
|
@@ -10,29 +10,32 @@ import { captureBooleanText } from "../core/value-text.js";
|
|
|
10
10
|
import { captureCsvOptions } from "./options.js";
|
|
11
11
|
export { saveBlob } from "../core/index.js";
|
|
12
12
|
export { ExportCell } from "../core/presentation.js";
|
|
13
|
-
function csvField(value, delimiter, protect, quote, booleanText
|
|
14
|
-
|
|
15
|
-
value = nullValue;
|
|
13
|
+
function csvField(value, delimiter, protect, quote, booleanText) {
|
|
14
|
+
const kind = typeof value;
|
|
16
15
|
let text;
|
|
17
16
|
if (value == null)
|
|
18
17
|
text = "";
|
|
18
|
+
else if (kind === "string")
|
|
19
|
+
text = value;
|
|
20
|
+
else if (kind === "number") {
|
|
21
|
+
text = Number.isFinite(value) ? String(value) : "";
|
|
22
|
+
// Numeric text has no CSV delimiter, quote or line break to escape.
|
|
23
|
+
return quote === "all" ? '"' + text + '"' : text;
|
|
24
|
+
}
|
|
25
|
+
else if (kind === "boolean")
|
|
26
|
+
text = booleanText[value ? "true" : "false"];
|
|
19
27
|
else if (isDate(value))
|
|
20
28
|
text = Number.isFinite(value.getTime()) ? value.toISOString() : "";
|
|
21
|
-
else if (typeof value === "boolean")
|
|
22
|
-
text = booleanText[value ? "true" : "false"];
|
|
23
|
-
else if (typeof value === "number")
|
|
24
|
-
text = Number.isFinite(value) ? String(value) : "";
|
|
25
|
-
else if (typeof value === "string")
|
|
26
|
-
text = value;
|
|
27
29
|
else {
|
|
28
30
|
if (typeof value.then === "function")
|
|
29
31
|
void Promise.resolve(value).catch(() => { });
|
|
30
32
|
throw new TypeError("CSV cells and formatter results must be synchronous strings, numbers, booleans, Dates or null.");
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
// Only ASCII spaces, controls and markers through @ can begin the protected prefix.
|
|
35
|
+
if (protect && (kind === "string" || kind === "boolean") && text.charCodeAt(0) <= 64 && /^ *[=+\-@\t\r\n]/.test(text))
|
|
33
36
|
text = "'" + text;
|
|
34
|
-
return quote === "all" || (quote === "strings" &&
|
|
35
|
-
? '"' + text.replace(/"/g, '""') + '"' : text;
|
|
37
|
+
return quote === "all" || (quote === "strings" && kind === "string") || text.includes(delimiter) || /["\r\n]/.test(text)
|
|
38
|
+
? '"' + (text.includes('"') ? text.replace(/"/g, '""') : text) + '"' : text;
|
|
36
39
|
}
|
|
37
40
|
export async function writeCsvTo(rows, destination, configuration) {
|
|
38
41
|
const options = captureCsvOptions(configuration);
|
|
@@ -84,7 +87,7 @@ async function write(rows, sink, options) {
|
|
|
84
87
|
value = options.nullValue;
|
|
85
88
|
budget.cell(typeof value === "boolean" ? booleanText[value ? "true" : "false"] : value);
|
|
86
89
|
checkAbort(signal);
|
|
87
|
-
text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText
|
|
90
|
+
text += (i ? delimiter : "") + csvField(value, delimiter, protect, quote, booleanText);
|
|
88
91
|
if (text.length >= buffer.chunkSize || (i & 127) === 127 && taskYieldDue()) {
|
|
89
92
|
if (buffer.append(text))
|
|
90
93
|
return buffer.flush().then(() => record(values, header, i + 1, snapshot));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CanopyDiagnostic, CanopyFormat, CanopySourceOptions } from "./types.js";
|
|
2
|
+
/** One policy for capture diagnostics and unsupported adapter mappings; callbacks stay synchronous. */
|
|
3
|
+
export declare function canopyDiagnostics(format: CanopyFormat, options: CanopySourceOptions): (diagnostic: CanopyDiagnostic) => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** One policy for capture diagnostics and unsupported adapter mappings; callbacks stay synchronous. */
|
|
2
|
+
export function canopyDiagnostics(format, options) {
|
|
3
|
+
const policy = options.unsupportedPresentation ?? (format === "csv" ? "text" : "reject"), notify = options.onDiagnostic;
|
|
4
|
+
if (policy !== "reject" && policy !== "text")
|
|
5
|
+
throw new TypeError("unsupportedPresentation must be reject or text.");
|
|
6
|
+
if (notify !== undefined && typeof notify !== "function")
|
|
7
|
+
throw new TypeError("onDiagnostic must be a synchronous function.");
|
|
8
|
+
return diagnostic => {
|
|
9
|
+
if (policy === "reject")
|
|
10
|
+
throw new TypeError("Unsupported Canopy presentation: " + diagnostic.code + (diagnostic.columnId ? " (" + diagnostic.columnId + ")" : ""));
|
|
11
|
+
const result = notify?.(Object.freeze(diagnostic));
|
|
12
|
+
if (result && typeof result.then === "function") {
|
|
13
|
+
void Promise.resolve(result).catch(() => { });
|
|
14
|
+
throw new TypeError("onDiagnostic must be synchronous.");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GroupedReportSource } from "../../core/grouped-report.js";
|
|
2
|
+
import type { ExportLimits } from "../../core/index.js";
|
|
3
|
+
import type { CanopyCapture, CanopyDiagnostic, CanopyExport, CanopyFormat, CanopySourceOptions } from "./types.js";
|
|
4
|
+
/** Validate captured ranges, then use the owned grouping factory and its existing writers.
|
|
5
|
+
* Only ranges, labels and at most four active aggregate vectors are retained; no detail body is buffered. */
|
|
6
|
+
export declare function canopyGrouped(source: CanopyExport, request: CanopyCapture["request"], options: CanopySourceOptions, limits: ExportLimits | undefined, report: (diagnostic: CanopyDiagnostic) => void, format: CanopyFormat): GroupedReportSource | undefined;
|