@bevel-software/platform-core-backend 0.11.2 → 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.
- package/THIRD-PARTY-NOTICES.md +1163 -425
- package/dist/core/create-core-server.js +1 -1
- package/dist/core/create-core-server.js.map +1 -1
- package/dist/core/create-core-services.d.ts +2 -0
- package/dist/core/create-core-services.d.ts.map +1 -1
- package/dist/core/create-core-services.js +5 -0
- package/dist/core/create-core-services.js.map +1 -1
- package/dist/core-config.d.ts +7 -0
- package/dist/core-config.d.ts.map +1 -1
- package/dist/core-config.js +9 -0
- package/dist/core-config.js.map +1 -1
- package/dist/modules/code-mode/code-mode.tool.d.ts.map +1 -1
- package/dist/modules/code-mode/code-mode.tool.js +7 -1
- package/dist/modules/code-mode/code-mode.tool.js.map +1 -1
- package/dist/modules/workspace/file-readers/doc-extract.service.d.ts +71 -0
- package/dist/modules/workspace/file-readers/doc-extract.service.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/doc-extract.service.js +90 -0
- package/dist/modules/workspace/file-readers/doc-extract.service.js.map +1 -0
- package/dist/modules/workspace/file-readers/doc-extract.types.d.ts +55 -0
- package/dist/modules/workspace/file-readers/doc-extract.types.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/doc-extract.types.js +34 -0
- package/dist/modules/workspace/file-readers/doc-extract.types.js.map +1 -0
- package/dist/modules/workspace/file-readers/document-reader.d.ts +32 -0
- package/dist/modules/workspace/file-readers/document-reader.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/document-reader.js +59 -0
- package/dist/modules/workspace/file-readers/document-reader.js.map +1 -0
- package/dist/modules/workspace/file-readers/email-reader.d.ts +15 -0
- package/dist/modules/workspace/file-readers/email-reader.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/email-reader.js +19 -0
- package/dist/modules/workspace/file-readers/email-reader.js.map +1 -0
- package/dist/modules/workspace/file-readers/email-text.d.ts +51 -0
- package/dist/modules/workspace/file-readers/email-text.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/email-text.js +151 -0
- package/dist/modules/workspace/file-readers/email-text.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-docx.d.ts +13 -0
- package/dist/modules/workspace/file-readers/extract-docx.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-docx.js +67 -0
- package/dist/modules/workspace/file-readers/extract-docx.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-eml.d.ts +18 -0
- package/dist/modules/workspace/file-readers/extract-eml.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-eml.js +87 -0
- package/dist/modules/workspace/file-readers/extract-eml.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-msg.d.ts +17 -0
- package/dist/modules/workspace/file-readers/extract-msg.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-msg.js +121 -0
- package/dist/modules/workspace/file-readers/extract-msg.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-odp.d.ts +13 -0
- package/dist/modules/workspace/file-readers/extract-odp.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-odp.js +60 -0
- package/dist/modules/workspace/file-readers/extract-odp.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-ods.d.ts +10 -0
- package/dist/modules/workspace/file-readers/extract-ods.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-ods.js +173 -0
- package/dist/modules/workspace/file-readers/extract-ods.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-odt.d.ts +17 -0
- package/dist/modules/workspace/file-readers/extract-odt.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-odt.js +45 -0
- package/dist/modules/workspace/file-readers/extract-odt.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-pdf.d.ts +3 -0
- package/dist/modules/workspace/file-readers/extract-pdf.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-pdf.js +176 -0
- package/dist/modules/workspace/file-readers/extract-pdf.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-pptx.d.ts +37 -0
- package/dist/modules/workspace/file-readers/extract-pptx.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-pptx.js +288 -0
- package/dist/modules/workspace/file-readers/extract-pptx.js.map +1 -0
- package/dist/modules/workspace/file-readers/extract-xlsx.d.ts +10 -0
- package/dist/modules/workspace/file-readers/extract-xlsx.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extract-xlsx.js +98 -0
- package/dist/modules/workspace/file-readers/extract-xlsx.js.map +1 -0
- package/dist/modules/workspace/file-readers/extraction-cache.d.ts +61 -0
- package/dist/modules/workspace/file-readers/extraction-cache.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/extraction-cache.js +135 -0
- package/dist/modules/workspace/file-readers/extraction-cache.js.map +1 -0
- package/dist/modules/workspace/file-readers/file-reader.d.ts +76 -0
- package/dist/modules/workspace/file-readers/file-reader.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/file-reader.js +55 -0
- package/dist/modules/workspace/file-readers/file-reader.js.map +1 -0
- package/dist/modules/workspace/file-readers/file-reader.registry.d.ts +13 -0
- package/dist/modules/workspace/file-readers/file-reader.registry.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/file-reader.registry.js +41 -0
- package/dist/modules/workspace/file-readers/file-reader.registry.js.map +1 -0
- package/dist/modules/workspace/file-readers/image-read.d.ts +35 -0
- package/dist/modules/workspace/file-readers/image-read.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/image-read.js +108 -0
- package/dist/modules/workspace/file-readers/image-read.js.map +1 -0
- package/dist/modules/workspace/file-readers/image-reader.d.ts +19 -0
- package/dist/modules/workspace/file-readers/image-reader.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/image-reader.js +30 -0
- package/dist/modules/workspace/file-readers/image-reader.js.map +1 -0
- package/dist/modules/workspace/file-readers/odf-text.d.ts +26 -0
- package/dist/modules/workspace/file-readers/odf-text.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/odf-text.js +116 -0
- package/dist/modules/workspace/file-readers/odf-text.js.map +1 -0
- package/dist/modules/workspace/file-readers/ooxml-text.d.ts +172 -0
- package/dist/modules/workspace/file-readers/ooxml-text.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/ooxml-text.js +439 -0
- package/dist/modules/workspace/file-readers/ooxml-text.js.map +1 -0
- package/dist/modules/workspace/file-readers/text-reader.d.ts +47 -0
- package/dist/modules/workspace/file-readers/text-reader.d.ts.map +1 -0
- package/dist/modules/workspace/file-readers/text-reader.js +117 -0
- package/dist/modules/workspace/file-readers/text-reader.js.map +1 -0
- package/dist/modules/workspace/workspace.tools.d.ts +2 -1
- package/dist/modules/workspace/workspace.tools.d.ts.map +1 -1
- package/dist/modules/workspace/workspace.tools.js +158 -15
- package/dist/modules/workspace/workspace.tools.js.map +1 -1
- package/package.json +9 -4
- package/src/core/create-core-server.ts +1 -1
- package/src/core/create-core-services.ts +6 -0
- package/src/core-config.ts +9 -0
- package/src/modules/code-mode/__tests__/code-mode.tool.test.ts +30 -0
- package/src/modules/code-mode/code-mode.tool.ts +7 -1
- package/src/modules/tool-helpers/__tests__/phase4-tools.test.ts +2 -1
- package/src/modules/workspace/__tests__/workspace.tools.test.ts +500 -2
- package/src/modules/workspace/file-readers/__tests__/doc-extract.test.ts +1658 -0
- package/src/modules/workspace/file-readers/__tests__/email-extract.test.ts +485 -0
- package/src/modules/workspace/file-readers/__tests__/file-reader.registry.test.ts +97 -0
- package/src/modules/workspace/file-readers/__tests__/image-read.test.ts +100 -0
- package/src/modules/workspace/file-readers/doc-extract.service.ts +104 -0
- package/src/modules/workspace/file-readers/doc-extract.types.ts +63 -0
- package/src/modules/workspace/file-readers/document-reader.ts +64 -0
- package/src/modules/workspace/file-readers/email-reader.ts +21 -0
- package/src/modules/workspace/file-readers/email-text.ts +193 -0
- package/src/modules/workspace/file-readers/extract-docx.ts +67 -0
- package/src/modules/workspace/file-readers/extract-eml.ts +92 -0
- package/src/modules/workspace/file-readers/extract-msg.ts +134 -0
- package/src/modules/workspace/file-readers/extract-odp.ts +63 -0
- package/src/modules/workspace/file-readers/extract-ods.ts +182 -0
- package/src/modules/workspace/file-readers/extract-odt.ts +48 -0
- package/src/modules/workspace/file-readers/extract-pdf.ts +178 -0
- package/src/modules/workspace/file-readers/extract-pptx.ts +302 -0
- package/src/modules/workspace/file-readers/extract-xlsx.ts +96 -0
- package/src/modules/workspace/file-readers/extraction-cache.ts +142 -0
- package/src/modules/workspace/file-readers/file-reader.registry.ts +45 -0
- package/src/modules/workspace/file-readers/file-reader.ts +104 -0
- package/src/modules/workspace/file-readers/image-read.ts +122 -0
- package/src/modules/workspace/file-readers/image-reader.ts +39 -0
- package/src/modules/workspace/file-readers/odf-text.ts +123 -0
- package/src/modules/workspace/file-readers/ooxml-text.ts +477 -0
- package/src/modules/workspace/file-readers/text-reader.ts +131 -0
- package/src/modules/workspace/workspace.tools.ts +174 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-msg.d.ts","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-msg.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAI5D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAsBvD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import MsgReaderImport from '@kenjiuno/msgreader';
|
|
2
|
+
import { emailExtraction, htmlToEmailText } from './email-text.js';
|
|
3
|
+
import { MAX_DOC_PART_BYTES } from './ooxml-text.js';
|
|
4
|
+
/**
|
|
5
|
+
* Extract a `.msg` (Outlook item, CFB container) email into the shared email
|
|
6
|
+
* text shape (see `email-text.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Parsing is `@kenjiuno/msgreader` (HiraokaHyperTools, Apache-2.0) — the
|
|
9
|
+
* maintained MAPI/CFB reader. It never throws for bad content of its own
|
|
10
|
+
* accord: unparseable bytes come back as `{ dataType: null, error }`, which
|
|
11
|
+
* maps onto the typed could-not-be-parsed failure here.
|
|
12
|
+
*
|
|
13
|
+
* Body preference mirrors `.eml`: the plain-text `PidTagBody` first, an HTML
|
|
14
|
+
* body stripped to text second. An Outlook item whose body exists ONLY as
|
|
15
|
+
* compressed RTF is degraded honestly — the extraction says
|
|
16
|
+
* "[body is RTF; no plain-text part]" instead of pretending to decode RTF.
|
|
17
|
+
*/
|
|
18
|
+
export function extractMsg(bytes) {
|
|
19
|
+
if (bytes.length > MAX_DOC_PART_BYTES) {
|
|
20
|
+
return {
|
|
21
|
+
ok: false,
|
|
22
|
+
message: `could not be extracted as a .msg (the file is ${bytes.length} bytes — over the ${MAX_DOC_PART_BYTES}-byte (50 MB) extraction limit)`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let fields;
|
|
26
|
+
try {
|
|
27
|
+
// DataView over the Buffer's exact region — no copy, and msgreader never
|
|
28
|
+
// sees bytes outside the file.
|
|
29
|
+
fields = new MsgReader(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)).getFileData();
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return { ok: false, message: `could not be parsed as a .msg (${err.message})` };
|
|
33
|
+
}
|
|
34
|
+
if (fields.dataType !== 'msg') {
|
|
35
|
+
return {
|
|
36
|
+
ok: false,
|
|
37
|
+
message: `could not be parsed as a .msg (${fields.error ?? 'not an Outlook message file'})`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { ok: true, ...emailExtraction(msgModel(fields)) };
|
|
41
|
+
}
|
|
42
|
+
/** msgreader's field data, shaped into the format-independent email model. */
|
|
43
|
+
function msgModel(fields) {
|
|
44
|
+
const recipients = fields.recipients ?? [];
|
|
45
|
+
const text = fields.body !== undefined && fields.body.trim() !== '' ? fields.body : undefined;
|
|
46
|
+
const html = htmlBody(fields);
|
|
47
|
+
const body = text ?? (html !== undefined ? htmlToEmailText(html) : '');
|
|
48
|
+
const bodySource = text !== undefined ? 'text' : html !== undefined ? 'html' : fields.compressedRtf !== undefined ? 'rtf-only' : 'none';
|
|
49
|
+
const date = fields.clientSubmitTime ?? fields.messageDeliveryTime;
|
|
50
|
+
return {
|
|
51
|
+
from: mailboxText(fields.senderName, fields.senderSmtpAddress ?? fields.senderEmail),
|
|
52
|
+
to: recipientList(recipients, 'to'),
|
|
53
|
+
cc: recipientList(recipients, 'cc'),
|
|
54
|
+
bcc: recipientList(recipients, 'bcc'),
|
|
55
|
+
subject: fields.subject,
|
|
56
|
+
date: date !== undefined ? isoDate(date) : undefined,
|
|
57
|
+
body: body.replace(/\s+$/, ''),
|
|
58
|
+
bodySource,
|
|
59
|
+
attachments: (fields.attachments ?? []).map((a) => ({
|
|
60
|
+
name: a.fileName ?? a.fileNameShort ?? a.name ?? 'unnamed attachment',
|
|
61
|
+
mimeType: a.attachMimeTag,
|
|
62
|
+
sizeBytes: a.contentLength,
|
|
63
|
+
})),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** The HTML body, whichever MAPI property carries it (string, or utf-8 bytes). */
|
|
67
|
+
function htmlBody(fields) {
|
|
68
|
+
if (fields.bodyHtml !== undefined && fields.bodyHtml.trim() !== '')
|
|
69
|
+
return fields.bodyHtml;
|
|
70
|
+
if (fields.html instanceof Uint8Array && fields.html.length > 0) {
|
|
71
|
+
return Buffer.from(fields.html).toString('utf8');
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/** `Name <addr>` / `Name` / `addr` — whatever the message carries. */
|
|
76
|
+
function mailboxText(name, address) {
|
|
77
|
+
const n = name?.trim() ?? '';
|
|
78
|
+
const a = address?.trim() ?? '';
|
|
79
|
+
if (n !== '' && a !== '' && n !== a)
|
|
80
|
+
return `${n} <${a}>`;
|
|
81
|
+
if (a !== '')
|
|
82
|
+
return a;
|
|
83
|
+
return n !== '' ? n : undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The bucket a recipient belongs to. msgreader maps the MAPI `PidTagRecipientType`
|
|
87
|
+
* values 1/2/3 to these strings itself (lib/MsgReader.js, the `recipType` case)
|
|
88
|
+
* — but ONLY those three: any other raw PT_LONG value, e.g. `MAPI_TO | MAPI_P1`
|
|
89
|
+
* (0x10000001) on a resubmitted message, leaks through as a NUMBER despite the
|
|
90
|
+
* `'to' | 'cc' | 'bcc'` typing. Mask the resubmit/submitted flag bits and remap
|
|
91
|
+
* so such a recipient keeps its line instead of vanishing; anything else
|
|
92
|
+
* (including untyped) counts as `to`, matching the frontend's `msgMessage.ts`.
|
|
93
|
+
*/
|
|
94
|
+
function recipientBucket(recipType) {
|
|
95
|
+
if (recipType === 'to' || recipType === 'cc' || recipType === 'bcc')
|
|
96
|
+
return recipType;
|
|
97
|
+
if (typeof recipType === 'number') {
|
|
98
|
+
const base = recipType & 0x0fffffff; // strip MAPI_SUBMITTED (0x80000000) / MAPI_P1 (0x10000000)
|
|
99
|
+
if (base === 2)
|
|
100
|
+
return 'cc';
|
|
101
|
+
if (base === 3)
|
|
102
|
+
return 'bcc';
|
|
103
|
+
}
|
|
104
|
+
return 'to';
|
|
105
|
+
}
|
|
106
|
+
/** The comma-joined mailboxes of one recipient type. Untyped recipients count as `to`. */
|
|
107
|
+
function recipientList(recipients, type) {
|
|
108
|
+
const s = recipients
|
|
109
|
+
.filter((r) => recipientBucket(r.recipType) === type)
|
|
110
|
+
.map((r) => mailboxText(r.name, r.smtpAddress ?? r.email))
|
|
111
|
+
.filter((t) => t !== undefined)
|
|
112
|
+
.join(', ');
|
|
113
|
+
return s === '' ? undefined : s;
|
|
114
|
+
}
|
|
115
|
+
/** msgreader emits RFC-1123 GMT strings; normalize to ISO, keep raw when unparseable. */
|
|
116
|
+
function isoDate(value) {
|
|
117
|
+
const d = new Date(value);
|
|
118
|
+
return Number.isNaN(d.getTime()) ? value : d.toISOString();
|
|
119
|
+
}
|
|
120
|
+
const MsgReader = MsgReaderImport.default ?? MsgReaderImport;
|
|
121
|
+
//# sourceMappingURL=extract-msg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-msg.js","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-msg.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,eAAe,EAAyC,MAAM,iBAAiB,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,IAAI,KAAK,CAAC,MAAM,GAAG,kBAAkB,EAAE,CAAC;QACtC,OAAO;YACL,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,iDAAiD,KAAK,CAAC,MAAM,qBAAqB,kBAAkB,iCAAiC;SAC/I,CAAC;IACJ,CAAC;IACD,IAAI,MAAkB,CAAC;IACvB,IAAI,CAAC;QACH,yEAAyE;QACzE,+BAA+B;QAC/B,MAAM,GAAG,IAAI,SAAS,CAAC,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACvG,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,kCAAmC,GAAa,CAAC,OAAO,GAAG,EAAE,CAAC;IAC7F,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;QAC9B,OAAO;YACL,EAAE,EAAE,KAAK;YACT,OAAO,EAAE,kCAAkC,MAAM,CAAC,KAAK,IAAI,6BAA6B,GAAG;SAC5F,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAA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CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC7D,CAAC;AASD,MAAM,SAAS,GACZ,eAA2D,CAAC,OAAO,IAAI,eAAe,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExtractResult } from './doc-extract.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the text of a `.odp` (OpenDocument Presentation) deck.
|
|
4
|
+
*
|
|
5
|
+
* Slides are the `<draw:page>` elements of `content.xml`, in DOCUMENT order —
|
|
6
|
+
* ODF orders slides in the file itself, so unlike pptx there is no numeric
|
|
7
|
+
* filename sort. Each slide is emitted under a `[slide N]` marker (N = 1-based
|
|
8
|
+
* position); speaker notes (`<presentation:notes>` inside the page) follow
|
|
9
|
+
* under `[slide N notes]` when non-empty. Within a slide, each `<text:p>` in
|
|
10
|
+
* its frames is a line; spans concatenate with no separator.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractOdp(bytes: Buffer): ExtractResult;
|
|
13
|
+
//# sourceMappingURL=extract-odp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-odp.d.ts","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-odp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAI5D;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAmCvD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { odfParagraphLines, readOdfContentXml } from './odf-text.js';
|
|
2
|
+
import { localBlocks, localElementBlocks, removeLocalElements } from './ooxml-text.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extract the text of a `.odp` (OpenDocument Presentation) deck.
|
|
5
|
+
*
|
|
6
|
+
* Slides are the `<draw:page>` elements of `content.xml`, in DOCUMENT order —
|
|
7
|
+
* ODF orders slides in the file itself, so unlike pptx there is no numeric
|
|
8
|
+
* filename sort. Each slide is emitted under a `[slide N]` marker (N = 1-based
|
|
9
|
+
* position); speaker notes (`<presentation:notes>` inside the page) follow
|
|
10
|
+
* under `[slide N notes]` when non-empty. Within a slide, each `<text:p>` in
|
|
11
|
+
* its frames is a line; spans concatenate with no separator.
|
|
12
|
+
*/
|
|
13
|
+
export function extractOdp(bytes) {
|
|
14
|
+
const content = readOdfContentXml(bytes, '.odp');
|
|
15
|
+
if (!content.ok)
|
|
16
|
+
return content;
|
|
17
|
+
const pages = drawPageBlocks(content.xml);
|
|
18
|
+
if (pages.length === 0) {
|
|
19
|
+
return { ok: false, message: 'could not be parsed as a .odp (no draw:page elements in content.xml)' };
|
|
20
|
+
}
|
|
21
|
+
const lines = [];
|
|
22
|
+
let anyNotes = false;
|
|
23
|
+
pages.forEach((page, i) => {
|
|
24
|
+
// Split the notes part out FIRST so its paragraphs don't render as slide text.
|
|
25
|
+
// Notes read by the parser and matched on their LOCAL name: a comment that
|
|
26
|
+
// resembled `<presentation:notes>` used to be emitted as real speaker notes,
|
|
27
|
+
// and a deck binding the presentation namespace to another prefix had none.
|
|
28
|
+
const notesXml = localBlocks(page, 'notes')[0] ?? '';
|
|
29
|
+
// The slide's own text is the page with the notes ELEMENTS removed by
|
|
30
|
+
// their parsed boundaries — global string replacement of the notes BODY
|
|
31
|
+
// also deleted slide text that happened to serialize identically to it.
|
|
32
|
+
const slideXml = removeLocalElements(page, ['notes']);
|
|
33
|
+
lines.push(`[slide ${i + 1}]`);
|
|
34
|
+
lines.push(...odfParagraphLines(slideXml));
|
|
35
|
+
const noteLines = odfParagraphLines(notesXml);
|
|
36
|
+
if (noteLines.length > 0) {
|
|
37
|
+
anyNotes = true;
|
|
38
|
+
lines.push(`[slide ${i + 1} notes]`);
|
|
39
|
+
lines.push(...noteLines);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
ok: true,
|
|
44
|
+
summary: `${pages.length} slide${pages.length === 1 ? '' : 's'}${anyNotes ? ' + notes' : ''}; layout, images and formatting omitted`,
|
|
45
|
+
text: lines.join('\n'),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The `<draw:page>…</draw:page>` bodies in document order (pages never nest).
|
|
50
|
+
* A SELF-CLOSING `<draw:page/>` is a legal, fully blank slide — it yields ''
|
|
51
|
+
* so the deck's numbering (and a deliberately blank deck) stays correct.
|
|
52
|
+
*/
|
|
53
|
+
function drawPageBlocks(xml) {
|
|
54
|
+
// The shared quote-aware scanner: a `/>` INSIDE a quoted attribute value (a
|
|
55
|
+
// page name like `a/>b`) is part of the value, never the self-closing
|
|
56
|
+
// delimiter, and a page whose close tag is missing costs one scan of the
|
|
57
|
+
// document rather than one per opener (see `xmlElementBlocks`).
|
|
58
|
+
return localElementBlocks(xml, ['page']).map((e) => e.body ?? '');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=extract-odp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-odp.js","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-odp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEvF;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAEhC,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,sEAAsE,EAAE,CAAC;IACxG,CAAC;IA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jC,4EAA4E;IAC5E,sEAAsE;IACtE,yEAAyE;IACzE,gEAAgE;IAChE,OAAO,kBAAkB,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ExtractResult } from './doc-extract.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract a `.ods` (OpenDocument Spreadsheet) workbook: per `<table:table>`
|
|
4
|
+
* (sheet) a `[sheet: Name]` marker (the `table:name` attribute), then the rows
|
|
5
|
+
* as tab-separated cell text. A cell's text is its `<text:p>` content
|
|
6
|
+
* (multiple paragraphs join with a space — a newline would break the row
|
|
7
|
+
* line); covered cells (under a merge) render empty.
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractOds(bytes: Buffer): ExtractResult;
|
|
10
|
+
//# sourceMappingURL=extract-ods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-ods.d.ts","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-ods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAyB5D;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAqBvD"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { attrByLocalName, decodeXmlEntities, localElementBlocks, localName, walkLocalElementBlocks, } from './ooxml-text.js';
|
|
2
|
+
import { odfParagraphBlocks, odfParagraphText, readOdfContentXml, } from './odf-text.js';
|
|
3
|
+
/**
|
|
4
|
+
* Per-sheet extraction caps — the SAME bounds as the xlsx extractor. ODF is
|
|
5
|
+
* fond of `table:number-columns-repeated="16384"` (or a million empty trailing
|
|
6
|
+
* rows) to pad a sheet to the grid, so repeats are expanded BOUNDED and the
|
|
7
|
+
* extraction says when it truncated (a `[sheet truncated …]` line right under
|
|
8
|
+
* the sheet marker). Trailing EMPTY cells/rows are trimmed before their
|
|
9
|
+
* repeats are applied at all, so grid padding never counts as truncation.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_ROWS_PER_SHEET = 10_000;
|
|
12
|
+
const MAX_COLS_PER_SHEET = 200;
|
|
13
|
+
/**
|
|
14
|
+
* Extract a `.ods` (OpenDocument Spreadsheet) workbook: per `<table:table>`
|
|
15
|
+
* (sheet) a `[sheet: Name]` marker (the `table:name` attribute), then the rows
|
|
16
|
+
* as tab-separated cell text. A cell's text is its `<text:p>` content
|
|
17
|
+
* (multiple paragraphs join with a space — a newline would break the row
|
|
18
|
+
* line); covered cells (under a merge) render empty.
|
|
19
|
+
*/
|
|
20
|
+
export function extractOds(bytes) {
|
|
21
|
+
const content = readOdfContentXml(bytes, '.ods');
|
|
22
|
+
if (!content.ok)
|
|
23
|
+
return content;
|
|
24
|
+
const tables = tableBlocks(content.xml);
|
|
25
|
+
if (tables.length === 0) {
|
|
26
|
+
return { ok: false, message: 'could not be parsed as a .ods (no table:table elements in content.xml)' };
|
|
27
|
+
}
|
|
28
|
+
const lines = [];
|
|
29
|
+
for (const table of tables) {
|
|
30
|
+
lines.push(`[sheet: ${table.name}]`);
|
|
31
|
+
const { rows, truncated } = expandRows(table.xml);
|
|
32
|
+
if (truncated.length > 0)
|
|
33
|
+
lines.push(`[sheet truncated to the ${truncated.join(' and ')}]`);
|
|
34
|
+
lines.push(...rows.map((cells) => cells.join('\t')));
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
ok: true,
|
|
38
|
+
summary: `${tables.length} sheet${tables.length === 1 ? '' : 's'}, rows as tab-separated values; formulas, formatting and charts omitted`,
|
|
39
|
+
text: lines.join('\n'),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The `<table:table>` blocks with their decoded `table:name`, in document
|
|
44
|
+
* order. Non-greedy close — a nested table (legal in ODF text documents, not
|
|
45
|
+
* produced by spreadsheets) would end the outer block early, degrading
|
|
46
|
+
* grouping but never crashing.
|
|
47
|
+
*/
|
|
48
|
+
function tableBlocks(xml) {
|
|
49
|
+
// Read by the parser and matched on the LOCAL name: a comment or CDATA
|
|
50
|
+
// section holding a table-looking fragment used to answer as a real sheet,
|
|
51
|
+
// and a document binding the table namespace to another prefix had none.
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const table of localElementBlocks(xml, ['table'])) {
|
|
54
|
+
const raw = attrByLocalName(table.attributes, 'name');
|
|
55
|
+
out.push({
|
|
56
|
+
// Control separators become spaces: a name holding an encoded newline
|
|
57
|
+
// or tab (` `) would corrupt the `[sheet: …]` marker's own line and
|
|
58
|
+
// the TSV structure under it.
|
|
59
|
+
name: raw ? decodeXmlEntities(raw).replace(/[\t\n\r]+/g, ' ') : `Sheet${out.length + 1}`,
|
|
60
|
+
xml: table.body ?? '',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Expand a sheet's rows with BOUNDED repeat handling, INCREMENTALLY — a row's
|
|
67
|
+
* expansion lands in the capped output as it parses, so the caps bound memory
|
|
68
|
+
* as well as output (materializing every row's cells before consulting the
|
|
69
|
+
* cap let an accepted ODS allocate its whole expansion first):
|
|
70
|
+
*
|
|
71
|
+
* - all-empty rows are buffered as a COUNT (with their
|
|
72
|
+
* `table:number-rows-repeated` applied) and flushed only when a non-empty
|
|
73
|
+
* row follows, so a million-row empty tail simply disappears,
|
|
74
|
+
* - once the row cap is hit, the remaining rows are never parsed at all.
|
|
75
|
+
*
|
|
76
|
+
* `truncated` lists what the caps cut (mirrors the xlsx extractor's note).
|
|
77
|
+
*/
|
|
78
|
+
function expandRows(tableXml) {
|
|
79
|
+
// The shared quote-aware scanner as a WALK, not an array: materializing
|
|
80
|
+
// every row block before consulting the cap let a sheet of >10k explicit
|
|
81
|
+
// rows allocate them all first. Each row lands here as it parses, and the
|
|
82
|
+
// visitor's `true` stops the scan at the cap — a self-closing row WITH
|
|
83
|
+
// attributes is still a row, a `/>` inside a quoted attribute value is not
|
|
84
|
+
// a delimiter, and an UNCLOSED row costs one scan of the sheet rather than
|
|
85
|
+
// one per opener (see `xmlElementBlocks`).
|
|
86
|
+
const rows = [];
|
|
87
|
+
let pendingEmpty = 0;
|
|
88
|
+
let rowsTruncated = false;
|
|
89
|
+
let colsTruncated = false;
|
|
90
|
+
walkLocalElementBlocks(tableXml, ['table-row'], (row) => {
|
|
91
|
+
const repeat = repeatCount(attrByLocalName(row.attributes, 'number-rows-repeated'));
|
|
92
|
+
const cells = expandCells(row.body ?? '');
|
|
93
|
+
if (cells.cells.length === 0) {
|
|
94
|
+
// Empty rows are interior padding until a non-empty row proves it —
|
|
95
|
+
// trailing ones are dropped with their repeats (grid padding, not data).
|
|
96
|
+
pendingEmpty += repeat;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (cells.truncated)
|
|
100
|
+
colsTruncated = true;
|
|
101
|
+
for (; pendingEmpty > 0 && rows.length < MAX_ROWS_PER_SHEET; pendingEmpty--)
|
|
102
|
+
rows.push([]);
|
|
103
|
+
let i = 0;
|
|
104
|
+
for (; i < repeat && rows.length < MAX_ROWS_PER_SHEET; i++)
|
|
105
|
+
rows.push(cells.cells);
|
|
106
|
+
if (pendingEmpty > 0 || i < repeat) {
|
|
107
|
+
// The cap cut real content (a sheet that merely FILLS it is not truncated).
|
|
108
|
+
rowsTruncated = true;
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
});
|
|
113
|
+
const truncated = [];
|
|
114
|
+
if (rowsTruncated)
|
|
115
|
+
truncated.push(`first ${MAX_ROWS_PER_SHEET} rows`);
|
|
116
|
+
if (colsTruncated)
|
|
117
|
+
truncated.push(`first ${MAX_COLS_PER_SHEET} columns`);
|
|
118
|
+
return { rows, truncated };
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* One row's cell texts: `<table:table-cell>` / `<table:covered-table-cell>`
|
|
122
|
+
* in order, expanded INCREMENTALLY like the rows above — trailing EMPTY cells
|
|
123
|
+
* are buffered as a count (their `table:number-columns-repeated` never
|
|
124
|
+
* expands) and the parse stops at the column cap.
|
|
125
|
+
*/
|
|
126
|
+
function expandCells(rowXml) {
|
|
127
|
+
// Same walking scanner as the rows above — a row spelling a million
|
|
128
|
+
// explicit cells stops parsing at the column cap too.
|
|
129
|
+
const cells = [];
|
|
130
|
+
let pendingEmpty = 0;
|
|
131
|
+
let truncated = false;
|
|
132
|
+
walkLocalElementBlocks(rowXml, ['table-cell', 'covered-table-cell'], (cell) => {
|
|
133
|
+
const repeat = repeatCount(attrByLocalName(cell.attributes, 'number-columns-repeated'));
|
|
134
|
+
// Covered cells carry no own text anyway. Element-produced newlines/tabs
|
|
135
|
+
// INSIDE a cell (<text:line-break/>, <text:tab/>) become single spaces:
|
|
136
|
+
// the extraction's contract is one row per line with tab-separated cells,
|
|
137
|
+
// and a literal \n or \t inside a cell's text would silently break both.
|
|
138
|
+
// A COVERED cell is the hidden half of a merge: the visible cell carries
|
|
139
|
+
// the text. Such a cell may still hold stale content, and emitting it put
|
|
140
|
+
// a value in the grid where the sheet shows none.
|
|
141
|
+
const text = localName(cell.name) === 'covered-table-cell'
|
|
142
|
+
? ''
|
|
143
|
+
: odfParagraphBlocks(cell.body ?? '')
|
|
144
|
+
.map(odfParagraphText)
|
|
145
|
+
.join(' ')
|
|
146
|
+
.replace(/[\t\n\r]+/g, ' ');
|
|
147
|
+
if (text === '') {
|
|
148
|
+
pendingEmpty += repeat;
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
for (; pendingEmpty > 0 && cells.length < MAX_COLS_PER_SHEET; pendingEmpty--)
|
|
152
|
+
cells.push('');
|
|
153
|
+
let i = 0;
|
|
154
|
+
for (; i < repeat && cells.length < MAX_COLS_PER_SHEET; i++)
|
|
155
|
+
cells.push(text);
|
|
156
|
+
if (pendingEmpty > 0 || i < repeat) {
|
|
157
|
+
// The cap cut real content (a row that merely FILLS it is not truncated).
|
|
158
|
+
truncated = true;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
});
|
|
163
|
+
return { cells, truncated };
|
|
164
|
+
}
|
|
165
|
+
/** A `…-repeated="N"` attribute value, clamped to a sane positive integer. */
|
|
166
|
+
function repeatCount(raw) {
|
|
167
|
+
// Decoded first: the block scanner hands attribute values RAW, and a repeat
|
|
168
|
+
// legally written with character references (`10`) must count as
|
|
169
|
+
// 10, not silently fall back to 1.
|
|
170
|
+
const n = raw !== undefined ? parseInt(decodeXmlEntities(raw), 10) : 1;
|
|
171
|
+
return Number.isFinite(n) && n >= 1 ? n : 1;
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=extract-ods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-ods.js","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-ods.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEvB;;;;;;;GAOG;AACH,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAEhC,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,MAAM,CAAC,MAAM,KAA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0 +1,17 @@
|
|
|
1
|
+
import type { ExtractResult } from './doc-extract.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the BODY text of a `.odt` (OpenDocument Text) document.
|
|
4
|
+
*
|
|
5
|
+
* An odt is a zip whose main part is `content.xml`; the body lives under
|
|
6
|
+
* `<office:text>`. Headers/footers are skipped like docx — in ODF they live in
|
|
7
|
+
* `styles.xml`, which is never opened, so reading `content.xml` alone IS the
|
|
8
|
+
* body-only extraction.
|
|
9
|
+
*
|
|
10
|
+
* Paragraphs (`<text:p>`) and headings (`<text:h>`, heading text as its own
|
|
11
|
+
* line) become lines in document order; `<text:span>` runs inside concatenate
|
|
12
|
+
* with NO separator, and the ODF whitespace elements (`<text:tab/>`,
|
|
13
|
+
* `<text:line-break/>`, `<text:s text:c="N"/>`) render as real characters —
|
|
14
|
+
* see `odfParagraphText`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractOdt(bytes: Buffer): ExtractResult;
|
|
17
|
+
//# sourceMappingURL=extract-odt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-odt.d.ts","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-odt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAI5D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CA6BvD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { localBlocks, removeLocalElements } from './ooxml-text.js';
|
|
2
|
+
import { odfParagraphBlocks, odfParagraphText, readOdfContentXml } from './odf-text.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extract the BODY text of a `.odt` (OpenDocument Text) document.
|
|
5
|
+
*
|
|
6
|
+
* An odt is a zip whose main part is `content.xml`; the body lives under
|
|
7
|
+
* `<office:text>`. Headers/footers are skipped like docx — in ODF they live in
|
|
8
|
+
* `styles.xml`, which is never opened, so reading `content.xml` alone IS the
|
|
9
|
+
* body-only extraction.
|
|
10
|
+
*
|
|
11
|
+
* Paragraphs (`<text:p>`) and headings (`<text:h>`, heading text as its own
|
|
12
|
+
* line) become lines in document order; `<text:span>` runs inside concatenate
|
|
13
|
+
* with NO separator, and the ODF whitespace elements (`<text:tab/>`,
|
|
14
|
+
* `<text:line-break/>`, `<text:s text:c="N"/>`) render as real characters —
|
|
15
|
+
* see `odfParagraphText`.
|
|
16
|
+
*/
|
|
17
|
+
export function extractOdt(bytes) {
|
|
18
|
+
const content = readOdfContentXml(bytes, '.odt');
|
|
19
|
+
if (!content.ok)
|
|
20
|
+
return content;
|
|
21
|
+
// Table cells contain their own <text:p>, so the flat paragraph scan renders
|
|
22
|
+
// table text too (one line per cell paragraph, like the raw document order).
|
|
23
|
+
// The text BODY, read by the parser and matched on its LOCAL name: a
|
|
24
|
+
// comment mentioning `</office:text>` used to terminate the body early and
|
|
25
|
+
// drop every paragraph after it, and an ODT binding the office namespace to
|
|
26
|
+
// another prefix had no body at all.
|
|
27
|
+
const body = localBlocks(content.xml, 'text')[0] ?? content.xml;
|
|
28
|
+
// Tracked-change bookkeeping is not body text: `<text:tracked-changes>`
|
|
29
|
+
// stores every DELETION's content as ordinary paragraphs, so the flat scan
|
|
30
|
+
// below would read deleted text back in as document lines. Removed by its
|
|
31
|
+
// parsed element boundaries before the paragraph walk.
|
|
32
|
+
// `<office:annotation>` is a COMMENT on the document, stored as ordinary
|
|
33
|
+
// paragraphs: read flat, a reviewer's note came back as a document line.
|
|
34
|
+
const visible = removeLocalElements(body, ['tracked-changes', 'annotation']);
|
|
35
|
+
const lines = odfParagraphBlocks(visible).map(odfParagraphText);
|
|
36
|
+
const paragraphs = lines.length;
|
|
37
|
+
while (lines.length > 0 && lines[lines.length - 1].trim() === '')
|
|
38
|
+
lines.pop();
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
summary: `${paragraphs} paragraph${paragraphs === 1 ? '' : 's'}; layout, images and formatting omitted`,
|
|
42
|
+
text: lines.join('\n'),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=extract-odt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-odt.js","sourceRoot":"","sources":["../../../../src/modules/workspace/file-readers/extract-odt.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAExF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAEhC,6EAA6E;IAC7E,6EAA6E;IAC7E,qEAAqE;IACrE,2EAA2E;IAC3E,4EAA4E;IAC5E,qCAAqC;IACrC,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC;IAEhE,wEAAwE;IACxE,2EAA2E;IAC3E,0EAA0E;IAC1E,uDAAuD;IACvD,yEAAyE;IACzE,yEAAyE;IACzE,MAAM,OAAO,GAAG,mBAAmB,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC,CAAC;IAE7E,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAChE,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;IAChC,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE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