feat: parse rich OneNote content resources

This commit is contained in:
2026-07-22 19:08:49 +02:00
parent 670310ea9e
commit c99615f5e6
13 changed files with 2671 additions and 6 deletions

View File

@@ -0,0 +1,204 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
import type { ParserDiagnostic } from '../model/diagnostics.js';
import type { FileDataBlobReference } from '../onestore/types.js';
export interface OneNoteColor {
kind: 'auto' | 'rgb' | 'rgba';
red?: number;
green?: number;
blue?: number;
alpha?: number;
}
/** Values are retained in the half-inch unit used by MS-ONE. */
export interface OneNoteLayout {
maxWidth?: number;
maxHeight?: number;
offsetHorizontal?: number;
offsetVertical?: number;
alignmentInParent?: number;
alignmentSelf?: number;
sizeSetByUser?: boolean;
}
export interface OneNoteTextStyle {
charset?: number;
bold?: boolean;
italic?: boolean;
underline?: boolean;
strikethrough?: boolean;
superscript?: boolean;
subscript?: boolean;
font?: string;
/** Font size in half-points. */
fontSize?: number;
fontColor?: OneNoteColor;
highlight?: OneNoteColor;
languageCode?: number;
mathFormatting?: boolean;
hyperlink?: boolean;
hyperlinkProtected?: boolean;
hidden?: boolean;
}
export interface OneNoteTextRun {
/** UTF-16 offsets into sourceText, matching MS-ONE character positions. */
start: number;
end: number;
text: string;
style: OneNoteTextStyle;
/** Present only for allow-listed URI schemes. */
href?: string;
}
export interface OneNoteTextBlock {
kind: 'text';
id: string;
sourceText: string;
/** Visible text with hidden hyperlink marker runs and NULs removed. */
text: string;
runs: OneNoteTextRun[];
paragraphStyle: OneNoteTextStyle;
paragraphAlignment?: 'left' | 'center' | 'right' | 'unknown';
paragraphSpaceBefore?: number;
paragraphSpaceAfter?: number;
paragraphLineSpacingExact?: number;
rightToLeft?: boolean;
layout: OneNoteLayout;
}
export interface OneNoteImageBlock {
kind: 'image';
id: string;
resourceId?: string;
filename?: string;
altText?: string;
ocrText?: string;
pictureWidth?: number;
pictureHeight?: number;
displayedPageNumber?: number;
href?: string;
isBackground: boolean;
layout: OneNoteLayout;
}
export interface OneNoteAttachmentBlock {
kind: 'attachment';
id: string;
resourceId?: string;
iconResourceId?: string;
/** Untrusted display metadata. It must not be used as a filesystem path. */
filename: string;
size?: number;
layout: OneNoteLayout;
}
export interface OneNoteTableCell {
id: string;
blocks: OneNoteContentBlock[];
backgroundColor?: OneNoteColor;
maxWidth?: number;
}
export interface OneNoteTableRow {
id: string;
cells: OneNoteTableCell[];
}
export interface OneNoteTableBlock {
kind: 'table';
id: string;
declaredRowCount?: number;
declaredColumnCount?: number;
rows: OneNoteTableRow[];
columnWidths: number[];
lockedColumns: boolean[];
bordersVisible: boolean;
layout: OneNoteLayout;
}
export interface OneNoteOutlineBlock {
kind: 'outline';
id: string;
childLevel?: number;
indents: number[];
layout: OneNoteLayout;
children: OneNoteContentBlock[];
}
export interface OneNoteOutlineElementBlock {
kind: 'outline-element';
id: string;
childLevel?: number;
contents: OneNoteContentBlock[];
children: OneNoteContentBlock[];
}
export interface OneNoteOutlineGroupBlock {
kind: 'outline-group';
id: string;
childLevel?: number;
children: OneNoteContentBlock[];
}
export interface OneNoteInkBlock {
kind: 'ink';
id: string;
supported: false;
description: string;
}
export interface OneNoteUnsupportedBlock {
kind: 'unsupported';
id: string;
sourceJcid: number;
description: string;
}
export type OneNoteContentBlock =
| OneNoteTextBlock
| OneNoteImageBlock
| OneNoteAttachmentBlock
| OneNoteTableBlock
| OneNoteOutlineBlock
| OneNoteOutlineElementBlock
| OneNoteOutlineGroupBlock
| OneNoteInkBlock
| OneNoteUnsupportedBlock;
export interface OneNoteResource {
id: string;
kind: 'image' | 'attachment';
sourceJcid: number;
extension?: string;
filename?: string;
mediaType: string;
browserRenderable: boolean;
size?: number;
/** A bounded view descriptor. Bytes are not copied during parsing. */
blob?: FileDataBlobReference;
availability: 'available' | 'external' | 'missing' | 'invalid';
}
export interface OneNotePageContentModel {
id: string;
title: string;
createdAt?: string;
updatedAt?: string;
level?: number;
text: string;
blocks: OneNoteContentBlock[];
}
/** Internal, non-serializable representation used by the worker integration. */
export interface OneNoteSectionContentModel {
sourceName: string;
sectionName: string;
pages: OneNotePageContentModel[];
resources: Map<string, OneNoteResource>;
diagnostics: ParserDiagnostic[];
}