@bevel-software/platform-core-frontend 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.
Files changed (44) hide show
  1. package/THIRD-PARTY-NOTICES.md +670 -395
  2. package/package.json +6 -2
  3. package/src/lib/__tests__/api.test.ts +95 -0
  4. package/src/lib/api.ts +30 -2
  5. package/src/lib/clipboard.ts +25 -0
  6. package/src/modules/access/__tests__/useFileAccess.test.tsx +47 -0
  7. package/src/modules/access/hooks/useFileAccess.ts +23 -5
  8. package/src/modules/library/utils/clipboard.ts +4 -20
  9. package/src/modules/workspace/components/FileExplorer.tsx +6 -14
  10. package/src/modules/workspace/components/FileViewer.tsx +17 -4
  11. package/src/modules/workspace/components/KbPageHeader.tsx +1 -1
  12. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +3 -1
  13. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +17 -0
  14. package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +15 -0
  15. package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -2
  16. package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +88 -0
  17. package/src/modules/workspace/components/renderers/EmailRenderer.tsx +309 -0
  18. package/src/modules/workspace/components/renderers/LegacyOfficeRenderer.tsx +60 -0
  19. package/src/modules/workspace/components/renderers/PdfRenderer.tsx +261 -33
  20. package/src/modules/workspace/components/renderers/PptxRenderer.tsx +184 -0
  21. package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +195 -45
  22. package/src/modules/workspace/components/renderers/__tests__/DownloadFileButton.test.tsx +48 -0
  23. package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.test.tsx +176 -0
  24. package/src/modules/workspace/components/renderers/__tests__/PdfRenderer.test.tsx +214 -76
  25. package/src/modules/workspace/components/renderers/__tests__/PptxRenderer.test.tsx +125 -0
  26. package/src/modules/workspace/components/renderers/__tests__/XlsxRenderer.test.tsx +245 -0
  27. package/src/modules/workspace/components/renderers/__tests__/emailBody.test.ts +117 -0
  28. package/src/modules/workspace/components/renderers/__tests__/emailMessage.test.ts +404 -0
  29. package/src/modules/workspace/components/renderers/__tests__/pptxOutline.test.ts +448 -0
  30. package/src/modules/workspace/components/renderers/__tests__/readBodyCapped.test.ts +117 -0
  31. package/src/modules/workspace/components/renderers/__tests__/rendererLayout.test.ts +73 -7
  32. package/src/modules/workspace/components/renderers/__tests__/rendererSelection.test.tsx +107 -0
  33. package/src/modules/workspace/components/renderers/downloadFile.ts +33 -0
  34. package/src/modules/workspace/components/renderers/emailBody.ts +168 -0
  35. package/src/modules/workspace/components/renderers/emailMessage.ts +223 -0
  36. package/src/modules/workspace/components/renderers/emlMessage.ts +91 -0
  37. package/src/modules/workspace/components/renderers/htmlSandbox.ts +9 -2
  38. package/src/modules/workspace/components/renderers/index.ts +82 -6
  39. package/src/modules/workspace/components/renderers/lazyRenderer.tsx +9 -2
  40. package/src/modules/workspace/components/renderers/msgMessage.ts +219 -0
  41. package/src/modules/workspace/components/renderers/pptxOutline.ts +317 -0
  42. package/src/modules/workspace/components/renderers/readBodyCapped.ts +97 -0
  43. package/src/modules/workspace/components/renderers/xmlReading.ts +0 -0
  44. package/src/url-suffix-imports.d.ts +12 -0
@@ -4,19 +4,24 @@ import { MarkdownRenderer } from './MarkdownRenderer';
4
4
  import { TextRenderer } from './TextRenderer';
5
5
  import { ImageRenderer } from './ImageRenderer';
6
6
  import { HtmlRenderer } from './HtmlRenderer';
7
- import { PdfRenderer } from './PdfRenderer';
8
7
  import { CsvRenderer } from './CsvRenderer';
9
8
  import { ToolRenderer } from './ToolRenderer';
9
+ import { LegacyOfficeRenderer } from './LegacyOfficeRenderer';
10
10
  import { lazyRenderer } from './lazyRenderer';
11
11
 
12
12
  export type { FileRendererProps, RendererSaveState } from './types';
13
13
 
14
14
  /**
15
- * `.xlsx` and `.docx` are code-split: their parsers (xlsx ~141 KB gzip,
16
- * mammoth ~119 KB) were 27% of the eager bundle for file types most sessions
17
- * never open. `lazyRenderer` carries its own Suspense fallback and error
18
- * boundary, so these stay plain `ComponentType<FileRendererProps>` values and
15
+ * The document viewers are code-split: their parsers (xlsx ~141 KB gzip,
16
+ * mammoth ~119 KB, pdf.js ~340 KB + its worker as a separate asset, jszip
17
+ * ~28 KB) would otherwise sit in the eager bundle for file types most
18
+ * sessions never open — pdf.js alone would grow it by more than a third.
19
+ * `lazyRenderer` carries its own Suspense fallback and error boundary, so
20
+ * these stay plain `ComponentType<FileRendererProps>` values and
19
21
  * `getFileRenderer()`'s contract is unchanged.
22
+ *
23
+ * (`LegacyOfficeRenderer` stays eager on purpose: it parses nothing — it is
24
+ * a note and a Download button, smaller than the lazy plumbing would be.)
20
25
  */
21
26
  const XlsxRenderer = lazyRenderer('spreadsheet', () =>
22
27
  import('./XlsxRenderer').then((m) => ({ default: m.XlsxRenderer })),
@@ -24,6 +29,17 @@ const XlsxRenderer = lazyRenderer('spreadsheet', () =>
24
29
  const DocxRenderer = lazyRenderer('document', () =>
25
30
  import('./DocxRenderer').then((m) => ({ default: m.DocxRenderer })),
26
31
  );
32
+ const PdfRenderer = lazyRenderer('PDF', () =>
33
+ import('./PdfRenderer').then((m) => ({ default: m.PdfRenderer })),
34
+ );
35
+ const PptxRenderer = lazyRenderer('presentation', () =>
36
+ import('./PptxRenderer').then((m) => ({ default: m.PptxRenderer })),
37
+ );
38
+ // The email viewer's own chunk is small (postal-mime is tiny) but it defers
39
+ // per-format again inside: the `.msg` path alone pulls the CFB machinery.
40
+ const EmailRenderer = lazyRenderer('email', () =>
41
+ import('./EmailRenderer').then((m) => ({ default: m.EmailRenderer })),
42
+ );
27
43
 
28
44
  const renderersByExtension: Record<string, ComponentType<FileRendererProps>> = {
29
45
  '.md': MarkdownRenderer,
@@ -40,6 +56,25 @@ const renderersByExtension: Record<string, ComponentType<FileRendererProps>> = {
40
56
  '.pdf': PdfRenderer,
41
57
  '.docx': DocxRenderer,
42
58
  '.xlsx': XlsxRenderer,
59
+ '.pptx': PptxRenderer,
60
+ // Pre-2007 Office binaries: nothing in the browser parses these, so the
61
+ // viewer says so and offers Download — never the text fallback, which
62
+ // would print megabytes of undecodable bytes.
63
+ '.doc': LegacyOfficeRenderer,
64
+ '.ppt': LegacyOfficeRenderer,
65
+ '.xls': LegacyOfficeRenderer,
66
+ // OpenDocument files: agents read them fine (the backend extracts their
67
+ // text), but the browser has no viewer for them yet — the same no-preview
68
+ // note (with ODF-honest copy: download, no convert hint) beats the text
69
+ // fallback garbling a zip.
70
+ '.odt': LegacyOfficeRenderer,
71
+ '.odp': LegacyOfficeRenderer,
72
+ '.ods': LegacyOfficeRenderer,
73
+ // Email files: headers + plain-text body + attachment names, parsed
74
+ // client-side — never the text fallback (a .msg is binary CFB, and a raw
75
+ // .eml is MIME plumbing nobody wants to scroll).
76
+ '.eml': EmailRenderer,
77
+ '.msg': EmailRenderer,
43
78
  '.csv': CsvRenderer,
44
79
  '.tool': ToolRenderer,
45
80
  };
@@ -75,6 +110,11 @@ export function getFileRenderer(filePath: string): ComponentType<FileRendererPro
75
110
  */
76
111
  export type RendererLayout = 'prose' | 'full-bleed';
77
112
 
113
+ // NOT here, deliberately: `.docx` (mammoth's HTML is prose), `.pptx` (the
114
+ // outline view is a text document), `.eml`/`.msg` (headers + a text body —
115
+ // a letter, the prose measure's home turf), and the legacy `.doc`/`.ppt`/
116
+ // `.xls` plus ODF `.odt`/`.odp`/`.ods` (a one-paragraph note) — all
117
+ // documents, all on the prose measure.
78
118
  const FULL_BLEED_EXTENSIONS = new Set([
79
119
  '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp', '.ico',
80
120
  '.pdf',
@@ -105,11 +145,47 @@ export function getRendererLayout(filePath: string): RendererLayout {
105
145
  * picture. Nobody reading a diagram wants to be told it is 4,812 characters of
106
146
  * XML, and the buffer the count would come from was never displayed.
107
147
  */
148
+ // `.eml` IS here for the `.svg` reason: its bytes happen to be text, but the
149
+ // renderer fetches the raw endpoint and parses the MIME itself — the text
150
+ // buffer a character count would come from is never displayed.
108
151
  const BINARY_EXTENSIONS = new Set([
109
152
  '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp', '.ico',
110
- '.pdf', '.docx', '.xlsx', '.zip',
153
+ '.pdf', '.docx', '.xlsx', '.pptx', '.doc', '.ppt', '.xls', '.zip',
154
+ '.odt', '.odp', '.ods', '.eml', '.msg',
111
155
  ]);
112
156
 
113
157
  export function isBinaryFile(filePath: string): boolean {
114
158
  return BINARY_EXTENSIONS.has(filePath.slice(filePath.lastIndexOf('.')).toLowerCase());
115
159
  }
160
+
161
+ /**
162
+ * Files whose page must not offer the WRITE action (Edit / Propose changes).
163
+ *
164
+ * These routes render a no-preview note (`LegacyOfficeRenderer`), a read-only
165
+ * parsed view (`EmailRenderer`), or a rendered-but-not-editable one (a docx as
166
+ * HTML, a workbook as a grid, a deck as an outline, a PDF as pages, an image
167
+ * as a picture). There is no editing surface behind
168
+ * the button, so clicking Edit would acquire the file lock, flip the page
169
+ * into an edit mode the renderer ignores, and — worst — imply that saving
170
+ * text over a binary document (or a message snapshot) is a thing that can be
171
+ * done. `FileViewer` suppresses both the pane bar's write action and the
172
+ * header's for these extensions.
173
+ */
174
+ const VIEW_ONLY_EXTENSIONS = new Set([
175
+ // No preview at all (LegacyOfficeRenderer) or a read-only parsed view.
176
+ '.doc', '.ppt', '.xls', '.odt', '.odp', '.ods', '.eml', '.msg',
177
+ // No dedicated route: a .zip lands on the TEXT FALLBACK, whose buffer is
178
+ // undecodable archive bytes. The surface can technically edit, but saving
179
+ // that buffer back would corrupt the archive — no lock, no write action.
180
+ '.zip',
181
+ // Rendered, but by a viewer with no editing surface either: a docx renders
182
+ // as HTML, a spreadsheet as a grid, a deck as an outline, a PDF as pages, an
183
+ // image as a picture. Edit would have acquired the lock and flipped the page
184
+ // into a mode every one of these renderers ignores.
185
+ '.docx', '.xlsx', '.pptx', '.pdf',
186
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.bmp', '.ico',
187
+ ]);
188
+
189
+ export function isViewOnlyFile(filePath: string): boolean {
190
+ return VIEW_ONLY_EXTENSIONS.has(filePath.slice(filePath.lastIndexOf('.')).toLowerCase());
191
+ }
@@ -32,7 +32,7 @@ export function lazyRenderer(
32
32
  // again. Only a new lazy component can actually re-run the import.
33
33
  const first = lazy(loader);
34
34
 
35
- return function LazyRenderer(props: FileRendererProps) {
35
+ function LazyRenderer(props: FileRendererProps) {
36
36
  const [attempt, setAttempt] = useState(0);
37
37
 
38
38
  // Attempt 0 reuses the shared component so the common path is unchanged:
@@ -55,5 +55,12 @@ export function lazyRenderer(
55
55
  </Suspense>
56
56
  </ChunkErrorBoundary>
57
57
  );
58
- };
58
+ }
59
+
60
+ // Names the wrapper after what it loads. Every wrapper is otherwise the
61
+ // same anonymous `LazyRenderer`, and the selection tests (and React
62
+ // DevTools) need to tell "the PDF viewer" from "the spreadsheet viewer"
63
+ // WITHOUT importing the heavy chunks they exist to defer.
64
+ LazyRenderer.displayName = `LazyRenderer(${label})`;
65
+ return LazyRenderer;
59
66
  }
@@ -0,0 +1,219 @@
1
+ import * as XLSX from 'xlsx';
2
+ import {
3
+ MAX_EMAIL_BYTES,
4
+ htmlToEmailText,
5
+ inlineBudgeted,
6
+ isInlineImagePart,
7
+ isoDate,
8
+ mailboxText,
9
+ referencedContentIds,
10
+ type EmailAttachmentView,
11
+ type EmailBodySource,
12
+ type EmailMessageView,
13
+ } from './emailMessage';
14
+
15
+ /**
16
+ * Client-side `.msg` (Outlook item) → `EmailMessageView`.
17
+ *
18
+ * The backend reads `.msg` through `@kenjiuno/msgreader`; that library does
19
+ * NOT load in the browser (its iconv-lite dependency needs Node's `Buffer`
20
+ * at import time — verified by bundling for a browser target). So this is a
21
+ * hand-rolled twin in the `pptxOutline.ts` tradition: the container is CFB
22
+ * (the OLE compound file), which SheetJS — already in the bundle for the
23
+ * spreadsheet viewer — parses via `XLSX.CFB`, and the handful of MAPI
24
+ * property streams an email viewer needs are read directly:
25
+ *
26
+ * `__substg1.0_<tag><type>` string/binary properties
27
+ * `__recip_version1.0_#NNNNNNNN/` one storage per recipient
28
+ * `__attach_version1.0_#NNNNNNNN/` one storage per attachment
29
+ * `__properties_version1.0` fixed 16-byte records (typed values)
30
+ *
31
+ * Type suffixes: `001F` = UTF-16LE string, `001E` = 8-bit string (decoded as
32
+ * windows-1252 — the overwhelmingly common ANSI codepage; an exotic codepage
33
+ * degrades to mojibake, never a crash), `0102` = binary. Body preference
34
+ * mirrors the backend: plain text (1000), then HTML (1013) stripped to text,
35
+ * then the honest RTF-only degradation when only compressed RTF (1009) exists.
36
+ *
37
+ * Throws an `Error` reading "could not be parsed as a .msg (…)" — shown
38
+ * verbatim by the caller — for non-CFB bytes and CFB files with no MAPI
39
+ * streams at all.
40
+ */
41
+ export function parseMsgMessage(bytes: ArrayBuffer): EmailMessageView {
42
+ if (bytes.byteLength > MAX_EMAIL_BYTES) {
43
+ throw new Error(
44
+ `could not be parsed as a .msg (the file is ${bytes.byteLength} bytes — over the 50 MB limit)`,
45
+ );
46
+ }
47
+ let streams: Map<string, Uint8Array>;
48
+ try {
49
+ streams = cfbStreams(new Uint8Array(bytes));
50
+ } catch (err) {
51
+ throw new Error(`could not be parsed as a .msg (${(err as Error).message})`);
52
+ }
53
+ const hasMapi = [...streams.keys()].some(
54
+ (p) => p.includes('__substg1.0_') || p.endsWith('__properties_version1.0'),
55
+ );
56
+ if (!hasMapi) {
57
+ throw new Error('could not be parsed as a .msg (not an Outlook message file)');
58
+ }
59
+
60
+ // A message may carry an EMPTY plain-text property beside a real HTML body.
61
+ // Treating '' as the body hid the HTML and claimed bodySource 'text', so the
62
+ // viewer showed nothing at all. Blank is absent, exactly as extract-msg reads it.
63
+ const text = blankToUndefined(stringProp(streams, '', '1000'));
64
+ const html = blankToUndefined(stringProp(streams, '', '1013') ?? binaryUtf8(streams, '', '1013'));
65
+ const hasRtf = streams.has('__substg1.0_10090102');
66
+ const body = (text ?? (html !== undefined ? htmlToEmailText(html) : '')).replace(/\s+$/, '');
67
+ const bodySource: EmailBodySource =
68
+ text !== undefined ? 'text' : html !== undefined ? 'html' : hasRtf ? 'rtf-only' : 'none';
69
+
70
+ const recipients = storageDirs(streams, '__recip_version1.0_#').map((dir) => ({
71
+ text: mailboxText(stringProp(streams, dir, '3001'), stringProp(streams, dir, '39FE') ?? stringProp(streams, dir, '3003')),
72
+ type: recipientType(streams.get(`${dir}__properties_version1.0`)),
73
+ }));
74
+ const listOf = (type: 'to' | 'cc' | 'bcc'): string | undefined => {
75
+ const s = recipients
76
+ .filter((r) => r.type === type)
77
+ .map((r) => r.text)
78
+ .filter((t): t is string => t !== undefined)
79
+ .join(', ');
80
+ return s === '' ? undefined : s;
81
+ };
82
+
83
+ return {
84
+ from: mailboxText(
85
+ stringProp(streams, '', '0C1A'),
86
+ stringProp(streams, '', '5D01') ?? stringProp(streams, '', '0C1F'),
87
+ ),
88
+ to: listOf('to'),
89
+ cc: listOf('cc'),
90
+ bcc: listOf('bcc'),
91
+ subject: stringProp(streams, '', '0037'),
92
+ date: messageDate(streams.get('__properties_version1.0')),
93
+ body,
94
+ bodyHtml: html,
95
+ bodySource,
96
+ attachments: inlineBudgeted(
97
+ storageDirs(streams, '__attach_version1.0_#').map((dir): EmailAttachmentView => {
98
+ const content = streams.get(`${dir}__substg1.0_37010102`);
99
+ const mimeType = stringProp(streams, dir, '370E');
100
+ // PidTagAttachContentId (0x3712) — what an HTML body's `cid:` names.
101
+ const contentId = stringProp(streams, dir, '3712')?.replace(/^<|>$/g, '');
102
+ return {
103
+ name:
104
+ stringProp(streams, dir, '3707') ??
105
+ stringProp(streams, dir, '3704') ??
106
+ stringProp(streams, dir, '3001') ??
107
+ 'unnamed attachment',
108
+ mimeType,
109
+ sizeBytes: content?.byteLength,
110
+ contentId,
111
+ bytes:
112
+ content && isInlineImagePart(mimeType, contentId, content.byteLength) ? content : undefined,
113
+ };
114
+ }),
115
+ referencedContentIds(html),
116
+ ),
117
+ };
118
+ }
119
+
120
+ // ── CFB access (SheetJS `XLSX.CFB` is typed loosely — shape pinned here) ───
121
+
122
+ interface CfbEntry {
123
+ content?: Uint8Array | number[] | null;
124
+ }
125
+ interface CfbContainer {
126
+ FullPaths: string[];
127
+ FileIndex: CfbEntry[];
128
+ }
129
+ interface CfbModule {
130
+ read(data: Uint8Array, opts: { type: 'array' }): CfbContainer;
131
+ }
132
+
133
+ /** Every stream in the container, keyed by its path RELATIVE to the root storage. */
134
+ function cfbStreams(bytes: Uint8Array): Map<string, Uint8Array> {
135
+ const cfb = (XLSX.CFB as unknown as CfbModule).read(bytes, { type: 'array' });
136
+ const out = new Map<string, Uint8Array>();
137
+ cfb.FullPaths.forEach((fullPath, i) => {
138
+ const content = cfb.FileIndex[i]?.content;
139
+ if (content == null || fullPath.endsWith('/')) return; // storage, not a stream
140
+ // 'Root Entry/__substg1.0_0037001F' → '__substg1.0_0037001F'
141
+ const rel = fullPath.slice(fullPath.indexOf('/') + 1);
142
+ out.set(rel, content instanceof Uint8Array ? content : Uint8Array.from(content));
143
+ });
144
+ return out;
145
+ }
146
+
147
+ /** The numbered `__recip_…`/`__attach_…` storage prefixes present, in index order. */
148
+ function storageDirs(streams: Map<string, Uint8Array>, prefix: string): string[] {
149
+ const dirs = new Set<string>();
150
+ for (const path of streams.keys()) {
151
+ if (path.startsWith(prefix)) dirs.add(path.slice(0, prefix.length + 8) + '/');
152
+ }
153
+ return [...dirs].sort();
154
+ }
155
+
156
+ /** A string property: the UTF-16LE variant (`001F`) preferred, the 8-bit one (`001E`) as fallback. */
157
+ function stringProp(streams: Map<string, Uint8Array>, dir: string, id: string): string | undefined {
158
+ const unicode = streams.get(`${dir}__substg1.0_${id}001F`);
159
+ if (unicode !== undefined) return decodeText(unicode, 'utf-16le');
160
+ const ansi = streams.get(`${dir}__substg1.0_${id}001E`);
161
+ return ansi !== undefined ? decodeText(ansi, 'windows-1252') : undefined;
162
+ }
163
+
164
+ /** A binary (`0102`) property decoded as UTF-8 — how the HTML body is usually stored. */
165
+ function binaryUtf8(streams: Map<string, Uint8Array>, dir: string, id: string): string | undefined {
166
+ const raw = streams.get(`${dir}__substg1.0_${id}0102`);
167
+ return raw !== undefined && raw.byteLength > 0 ? decodeText(raw, 'utf-8') : undefined;
168
+ }
169
+
170
+ function decodeText(bytes: Uint8Array, encoding: string): string {
171
+ const s = new TextDecoder(encoding).decode(bytes);
172
+ // MAPI string streams may carry a trailing NUL terminator.
173
+ return s.replace(/\0+$/, '');
174
+ }
175
+
176
+ /**
177
+ * One typed value out of a `__properties_version1.0` stream: `headerLen`
178
+ * bytes of header, then 16-byte records — property tag (u32 LE), flags,
179
+ * 8 value bytes.
180
+ */
181
+ function propertyValue(stream: Uint8Array | undefined, headerLen: number, tag: number): DataView | undefined {
182
+ if (stream === undefined) return undefined;
183
+ const dv = new DataView(stream.buffer, stream.byteOffset, stream.byteLength);
184
+ for (let i = headerLen; i + 16 <= stream.byteLength; i += 16) {
185
+ if (dv.getUint32(i, true) === tag) return new DataView(stream.buffer, stream.byteOffset + i + 8, 8);
186
+ }
187
+ return undefined;
188
+ }
189
+
190
+ /**
191
+ * `PidTagRecipientType` (0x0C15, PT_LONG): 1 = to, 2 = cc, 3 = bcc. Untyped
192
+ * counts as `to`. The raw value may carry MAPI flag bits — `MAPI_SUBMITTED`
193
+ * (0x80000000) or `MAPI_P1` (0x10000000) on a resubmitted message — so the
194
+ * base type is masked out first (e.g. 0x10000002 is still `cc`), matching the
195
+ * backend's `extract-msg.ts` `recipientBucket`.
196
+ */
197
+ function recipientType(props: Uint8Array | undefined): 'to' | 'cc' | 'bcc' {
198
+ const value = propertyValue(props, 8, 0x0c150003)?.getUint32(0, true);
199
+ if (value === undefined) return 'to';
200
+ const base = value & 0x0fffffff; // strip MAPI_SUBMITTED (0x80000000) / MAPI_P1 (0x10000000)
201
+ return base === 2 ? 'cc' : base === 3 ? 'bcc' : 'to';
202
+ }
203
+
204
+ /** The sent (0x0039) or delivered (0x0E06) PT_SYSTIME from the root properties stream, as ISO. */
205
+ function messageDate(props: Uint8Array | undefined): string | undefined {
206
+ // The root storage's properties stream has a 32-byte header.
207
+ const value = propertyValue(props, 32, 0x00390040) ?? propertyValue(props, 32, 0x0e060040);
208
+ if (value === undefined) return undefined;
209
+ // FILETIME: 100ns ticks since 1601-01-01, little-endian u64.
210
+ const ticks = value.getUint32(4, true) * 2 ** 32 + value.getUint32(0, true);
211
+ const ms = ticks / 10000 - 11644473600000;
212
+ return Number.isFinite(ms) ? isoDate(new Date(ms).toISOString()) : undefined;
213
+ }
214
+
215
+
216
+ /** '' and whitespace-only property values mean the property is not there. */
217
+ function blankToUndefined(value: string | undefined): string | undefined {
218
+ return value !== undefined && value.trim() !== '' ? value : undefined;
219
+ }