@wae/open-word 0.0.0-stage → 0.0.1

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.
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Stable error surface of `@wae/open-word`.
3
+ *
4
+ * Codes are contract, not prose: callers compare them, localize around them and
5
+ * never parse the message. A failure therefore keeps its code even when the
6
+ * text is translated.
7
+ */
8
+ /** Every stable code the authoring surface may report. */
9
+ export declare const errorCodes: readonly ["session/disposed", "session/argument-invalid", "session/budget-exceeded", "document/not-found", "document/revision-conflict", "object/not-found", "object/unsupported", "format/unsupported", "format/invalid", "capability/not-implemented"];
10
+ /** Union of {@link errorCodes}. */
11
+ export type OpenWordErrorCode = (typeof errorCodes)[number];
12
+ /** Optional locators a failure can carry so callers can point at the object. */
13
+ export interface OpenWordErrorDetails {
14
+ readonly revision?: number;
15
+ readonly documentId?: string;
16
+ readonly objectId?: string;
17
+ /** Document format involved in the failure, without the leading dot. */
18
+ readonly format?: string;
19
+ /** Authoring capability involved in the failure, e.g. `document.export`. */
20
+ readonly feature?: string;
21
+ }
22
+ /** Options accepted by {@link OpenWordError}. */
23
+ export interface OpenWordErrorOptions {
24
+ readonly recoverable?: boolean;
25
+ readonly details?: OpenWordErrorDetails;
26
+ readonly cause?: unknown;
27
+ }
28
+ /** Every failure thrown or rejected by this package. */
29
+ export declare class OpenWordError extends Error {
30
+ /** Stable, comparable code. */
31
+ readonly code: OpenWordErrorCode;
32
+ /** Whether retrying with different input or state can succeed. */
33
+ readonly recoverable: boolean;
34
+ /** Optional locators (`revision`, `documentId`, `objectId`, `format`, `feature`). */
35
+ readonly details: OpenWordErrorDetails;
36
+ constructor(code: OpenWordErrorCode, message: string, options?: OpenWordErrorOptions);
37
+ }
38
+ /**
39
+ * Reported by declared methods whose backing capability is not wired yet.
40
+ *
41
+ * The scaffold uses one code for every unimplemented entry point instead of
42
+ * inventing per-method placeholders; each method drops this rejection as it is
43
+ * implemented, and the code disappears with the last one.
44
+ */
45
+ export declare class NotImplementedError extends OpenWordError {
46
+ constructor(feature: string, message?: string);
47
+ }
48
+ /** Narrows an unknown thrown value to {@link OpenWordError}. */
49
+ export declare function isOpenWordError(value: unknown): value is OpenWordError;
package/dist/errors.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Stable error surface of `@wae/open-word`.
3
+ *
4
+ * Codes are contract, not prose: callers compare them, localize around them and
5
+ * never parse the message. A failure therefore keeps its code even when the
6
+ * text is translated.
7
+ */
8
+ /** Every stable code the authoring surface may report. */
9
+ export const errorCodes = [
10
+ 'session/disposed',
11
+ 'session/argument-invalid',
12
+ 'session/budget-exceeded',
13
+ 'document/not-found',
14
+ 'document/revision-conflict',
15
+ 'object/not-found',
16
+ 'object/unsupported',
17
+ 'format/unsupported',
18
+ 'format/invalid',
19
+ 'capability/not-implemented',
20
+ ];
21
+ /** Every failure thrown or rejected by this package. */
22
+ export class OpenWordError extends Error {
23
+ /** Stable, comparable code. */
24
+ code;
25
+ /** Whether retrying with different input or state can succeed. */
26
+ recoverable;
27
+ /** Optional locators (`revision`, `documentId`, `objectId`, `format`, `feature`). */
28
+ details;
29
+ constructor(code, message, options = {}) {
30
+ super(message, options.cause === undefined ? undefined : { cause: options.cause });
31
+ this.name = 'OpenWordError';
32
+ this.code = code;
33
+ this.recoverable = options.recoverable ?? false;
34
+ this.details = Object.freeze({ ...options.details });
35
+ }
36
+ }
37
+ /**
38
+ * Reported by declared methods whose backing capability is not wired yet.
39
+ *
40
+ * The scaffold uses one code for every unimplemented entry point instead of
41
+ * inventing per-method placeholders; each method drops this rejection as it is
42
+ * implemented, and the code disappears with the last one.
43
+ */
44
+ export class NotImplementedError extends OpenWordError {
45
+ constructor(feature, message = `\`${feature}\` is not implemented yet`) {
46
+ super('capability/not-implemented', message, { recoverable: false, details: { feature } });
47
+ this.name = 'NotImplementedError';
48
+ }
49
+ }
50
+ /** Narrows an unknown thrown value to {@link OpenWordError}. */
51
+ export function isOpenWordError(value) {
52
+ return value instanceof OpenWordError;
53
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Document format family.
3
+ *
4
+ * Word extensions encode two things at once: the container (`x` = OOXML,
5
+ * `m` = macro-enabled, none = 97-2003 binary) and the intended use (`dot*` =
6
+ * template). Open formats such as ODT, RTF, plain text, Markdown and HTML are
7
+ * grouped separately, and PDF is a fixed projection that never becomes an
8
+ * editable document.
9
+ *
10
+ * Classification is **not** a support claim. What the installed engine can read,
11
+ * write or render is reported by `OpenWord.capabilities()`; an extension listed
12
+ * here may still be `unsupported`.
13
+ */
14
+ /** Intent applied when the caller does not override it. */
15
+ export type DocumentIntent = 'edit' | 'template' | 'read';
16
+ /** Grouping used for capability reporting and user-facing wording. */
17
+ export type FormatFamily = 'core' | 'template' | 'legacy' | 'interchange' | 'plain' | 'markup' | 'fixed';
18
+ /** Container encoding behind an extension. */
19
+ export type FormatMarkup = 'ooxml' | 'binary' | 'odf' | 'text' | 'markdown' | 'html' | 'fixed';
20
+ /** What an extension can be consumed as. `none` means it never becomes a document. */
21
+ export type FormatOpenKind = 'document' | 'template' | 'none';
22
+ /** Every extension the product must classify. */
23
+ export declare const documentFormats: readonly ["docx", "docm", "dotx", "dotm", "doc", "rtf", "odt", "txt", "md", "html", "pdf"];
24
+ /** Union of {@link documentFormats}. */
25
+ export type DocumentFormat = (typeof documentFormats)[number];
26
+ /** What a format is, independent of whether it is implemented. */
27
+ export interface DocumentFormatInfo {
28
+ readonly format: DocumentFormat;
29
+ readonly family: FormatFamily;
30
+ readonly markup: FormatMarkup;
31
+ /** Whether the container may hold VBA macros. Such parts are never executed. */
32
+ readonly macroEnabled: boolean;
33
+ readonly opensAs: FormatOpenKind;
34
+ /** Intent applied to `open()` when the extension arrives without one. */
35
+ readonly defaultIntent: DocumentIntent | null;
36
+ }
37
+ type FormatRegistryEntry = Omit<DocumentFormatInfo, 'format'>;
38
+ /** Extension to classification. Values describe the format, never a capability. */
39
+ export declare const formatRegistry: Readonly<Record<DocumentFormat, FormatRegistryEntry>>;
40
+ /** Returns the full classification of one format. */
41
+ export declare function formatInfo(format: DocumentFormat): DocumentFormatInfo;
42
+ /** Extracts a classified extension from a path, ignoring case. */
43
+ export declare function formatFromPath(path: string): DocumentFormat | undefined;
44
+ /** Default open intent of a format, or `null` when it never opens as a document. */
45
+ export declare function defaultIntentFor(format: DocumentFormat): DocumentIntent | null;
46
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Document format family.
3
+ *
4
+ * Word extensions encode two things at once: the container (`x` = OOXML,
5
+ * `m` = macro-enabled, none = 97-2003 binary) and the intended use (`dot*` =
6
+ * template). Open formats such as ODT, RTF, plain text, Markdown and HTML are
7
+ * grouped separately, and PDF is a fixed projection that never becomes an
8
+ * editable document.
9
+ *
10
+ * Classification is **not** a support claim. What the installed engine can read,
11
+ * write or render is reported by `OpenWord.capabilities()`; an extension listed
12
+ * here may still be `unsupported`.
13
+ */
14
+ /** Every extension the product must classify. */
15
+ export const documentFormats = [
16
+ 'docx',
17
+ 'docm',
18
+ 'dotx',
19
+ 'dotm',
20
+ 'doc',
21
+ 'rtf',
22
+ 'odt',
23
+ 'txt',
24
+ 'md',
25
+ 'html',
26
+ 'pdf',
27
+ ];
28
+ /** Extension to classification. Values describe the format, never a capability. */
29
+ export const formatRegistry = Object.freeze({
30
+ docx: { family: 'core', markup: 'ooxml', macroEnabled: false, opensAs: 'document', defaultIntent: 'edit' },
31
+ docm: { family: 'core', markup: 'ooxml', macroEnabled: true, opensAs: 'document', defaultIntent: 'edit' },
32
+ dotx: { family: 'template', markup: 'ooxml', macroEnabled: false, opensAs: 'template', defaultIntent: 'template' },
33
+ dotm: { family: 'template', markup: 'ooxml', macroEnabled: true, opensAs: 'template', defaultIntent: 'template' },
34
+ doc: { family: 'legacy', markup: 'binary', macroEnabled: false, opensAs: 'none', defaultIntent: null },
35
+ rtf: { family: 'interchange', markup: 'text', macroEnabled: false, opensAs: 'document', defaultIntent: 'read' },
36
+ odt: { family: 'interchange', markup: 'odf', macroEnabled: false, opensAs: 'document', defaultIntent: 'edit' },
37
+ txt: { family: 'plain', markup: 'text', macroEnabled: false, opensAs: 'document', defaultIntent: 'read' },
38
+ md: { family: 'markup', markup: 'markdown', macroEnabled: false, opensAs: 'document', defaultIntent: 'read' },
39
+ html: { family: 'markup', markup: 'html', macroEnabled: false, opensAs: 'document', defaultIntent: 'read' },
40
+ pdf: { family: 'fixed', markup: 'fixed', macroEnabled: false, opensAs: 'none', defaultIntent: null },
41
+ });
42
+ /** Returns the full classification of one format. */
43
+ export function formatInfo(format) {
44
+ return { format, ...formatRegistry[format] };
45
+ }
46
+ /** Extracts a classified extension from a path, ignoring case. */
47
+ export function formatFromPath(path) {
48
+ const extension = path.slice(path.lastIndexOf('.') + 1).toLowerCase();
49
+ return documentFormats.includes(extension) ? extension : undefined;
50
+ }
51
+ /** Default open intent of a format, or `null` when it never opens as a document. */
52
+ export function defaultIntentFor(format) {
53
+ return formatRegistry[format].defaultIntent;
54
+ }
package/dist/gui.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * WebView host surface.
3
+ *
4
+ * The window is a WAE `WebViewHost` serving the built VMZ studio from
5
+ * `dist/gui`; the page talks to this process over the WebView IPC channel and
6
+ * every message maps onto the same N-API functions the CLI uses.
7
+ */
8
+ /** Lifecycle of one GUI host. */
9
+ export interface GuiStatus {
10
+ readonly state: 'open' | 'closed' | 'not_open' | 'failed';
11
+ readonly code: string | null;
12
+ readonly backend: string | null;
13
+ readonly platform: string;
14
+ readonly uptimeMs: number;
15
+ readonly message: string | null;
16
+ }
17
+ /** Result of asking for a window; failures keep the host detail. */
18
+ export interface GuiOpenResult {
19
+ readonly ok: boolean;
20
+ readonly status: GuiStatus;
21
+ readonly stage: string | null;
22
+ readonly hresult: number | null;
23
+ readonly attempted: readonly string[];
24
+ }
25
+ /** Result of closing a window; `closed` is false when nothing was open. */
26
+ export interface GuiCloseResult {
27
+ readonly closed: boolean;
28
+ readonly status: GuiStatus;
29
+ }
30
+ /** Arguments of {@link openGui}. */
31
+ export interface OpenGuiOptions {
32
+ readonly title?: string;
33
+ readonly contentDir?: string;
34
+ readonly width?: number;
35
+ readonly height?: number;
36
+ }
37
+ /** Terminal host status that is not a clean page close. */
38
+ export declare class GuiError extends Error {
39
+ readonly status: GuiStatus;
40
+ constructor(status: GuiStatus);
41
+ }
42
+ /** The GUI is staged next to the compiled CLI as `dist/gui`. */
43
+ export declare function defaultGuiContentDir(): string;
44
+ /** Opens the window, or focuses the live one. */
45
+ export declare function openGui(options?: OpenGuiOptions): GuiOpenResult;
46
+ /** Pumps the host loop once and reports the lifecycle state. */
47
+ export declare function pumpEvents(): GuiStatus;
48
+ /** Closes the window; distinguishes "already closed" from a failure. */
49
+ export declare function closeGui(): GuiCloseResult;
50
+ /** Reports whether the window is alive. */
51
+ export declare function isGuiOpen(): boolean;
52
+ /** Opens the window and pumps until it closes. */
53
+ export declare function runGui(options?: OpenGuiOptions, intervalMs?: number): Promise<GuiStatus>;
package/dist/gui.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * WebView host surface.
3
+ *
4
+ * The window is a WAE `WebViewHost` serving the built VMZ studio from
5
+ * `dist/gui`; the page talks to this process over the WebView IPC channel and
6
+ * every message maps onto the same N-API functions the CLI uses.
7
+ */
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+ import { NotImplementedError } from './errors.js';
12
+ import { nativeBinding } from './native.js';
13
+ const here = path.dirname(fileURLToPath(import.meta.url));
14
+ /** Terminal host status that is not a clean page close. */
15
+ export class GuiError extends Error {
16
+ status;
17
+ constructor(status) {
18
+ super(status.message ?? `OpenWord window ended with ${status.code ?? status.state}`);
19
+ this.name = 'GuiError';
20
+ this.status = status;
21
+ }
22
+ }
23
+ /** The GUI is staged next to the compiled CLI as `dist/gui`. */
24
+ export function defaultGuiContentDir() {
25
+ const dir = path.resolve(here, 'gui');
26
+ if (!fs.existsSync(path.join(dir, 'index.html'))) {
27
+ throw new Error(`GUI folder missing at ${dir}; run the UI build before opening the window`);
28
+ }
29
+ return dir;
30
+ }
31
+ function native(feature) {
32
+ const binding = nativeBinding();
33
+ if (!binding) {
34
+ throw new NotImplementedError(feature);
35
+ }
36
+ return binding;
37
+ }
38
+ /** Opens the window, or focuses the live one. */
39
+ export function openGui(options = {}) {
40
+ const binding = native('gui');
41
+ const raw = binding.openGui({
42
+ title: options.title ?? 'OpenWord',
43
+ contentDir: options.contentDir ?? defaultGuiContentDir(),
44
+ width: options.width,
45
+ height: options.height,
46
+ });
47
+ return JSON.parse(raw);
48
+ }
49
+ /** Pumps the host loop once and reports the lifecycle state. */
50
+ export function pumpEvents() {
51
+ return JSON.parse(native('gui').pumpEvents());
52
+ }
53
+ /** Closes the window; distinguishes "already closed" from a failure. */
54
+ export function closeGui() {
55
+ return JSON.parse(native('gui').closeGui());
56
+ }
57
+ /** Reports whether the window is alive. */
58
+ export function isGuiOpen() {
59
+ return native('gui').isGuiOpen();
60
+ }
61
+ /** Opens the window and pumps until it closes. */
62
+ export function runGui(options = {}, intervalMs = 16) {
63
+ const opened = openGui(options);
64
+ if (!opened.ok) {
65
+ return Promise.reject(new GuiError(opened.status));
66
+ }
67
+ return new Promise((resolve, reject) => {
68
+ const timer = setInterval(() => {
69
+ let status;
70
+ try {
71
+ status = pumpEvents();
72
+ }
73
+ catch (error) {
74
+ clearInterval(timer);
75
+ reject(error);
76
+ return;
77
+ }
78
+ if (status.state === 'open') {
79
+ return;
80
+ }
81
+ clearInterval(timer);
82
+ if (status.code === 'gui_closed') {
83
+ resolve(status);
84
+ }
85
+ else {
86
+ reject(new GuiError(status));
87
+ }
88
+ }, intervalMs);
89
+ });
90
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Authoring surface of `@wae/open-word`.
3
+ *
4
+ * Everything here is a declared contract: the session and format registry exist,
5
+ * while every capability rejects with `capability/not-implemented` until the
6
+ * shared engine lands. Document semantics, styles, templates, rendering and DOCX
7
+ * exchange belong upstream and are never re-implemented in this package.
8
+ */
9
+ export { OpenWord } from './open-word.js';
10
+ export { GuiError, closeGui, defaultGuiContentDir, isGuiOpen, openGui, pumpEvents, runGui } from './gui.js';
11
+ export type { GuiCloseResult, GuiOpenResult, GuiStatus, OpenGuiOptions } from './gui.js';
12
+ export { NotImplementedError, OpenWordError, errorCodes, isOpenWordError } from './errors.js';
13
+ export type { OpenWordErrorCode, OpenWordErrorDetails, OpenWordErrorOptions } from './errors.js';
14
+ export { defaultIntentFor, documentFormats, formatFromPath, formatInfo, formatRegistry } from './formats.js';
15
+ export type { DocumentFormat, DocumentFormatInfo, DocumentIntent, FormatFamily, FormatMarkup, FormatOpenKind, } from './formats.js';
16
+ export type * from './types.js';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Authoring surface of `@wae/open-word`.
3
+ *
4
+ * Everything here is a declared contract: the session and format registry exist,
5
+ * while every capability rejects with `capability/not-implemented` until the
6
+ * shared engine lands. Document semantics, styles, templates, rendering and DOCX
7
+ * exchange belong upstream and are never re-implemented in this package.
8
+ */
9
+ export { OpenWord } from './open-word.js';
10
+ export { GuiError, closeGui, defaultGuiContentDir, isGuiOpen, openGui, pumpEvents, runGui } from './gui.js';
11
+ export { NotImplementedError, OpenWordError, errorCodes, isOpenWordError } from './errors.js';
12
+ export { defaultIntentFor, documentFormats, formatFromPath, formatInfo, formatRegistry } from './formats.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Native addon discovery.
3
+ *
4
+ * The addon only maps values: document semantics, saving and export stay in the
5
+ * shared engine. An absent addon is a declarative state, so capability calls
6
+ * report `capability/not-implemented` instead of inventing a matrix.
7
+ */
8
+ /** Orthogonal exports of the built addon. Document calls return JSON; close returns a boolean. */
9
+ export interface NativeBinding {
10
+ version(): string;
11
+ capabilities(): string;
12
+ document_create(requestJson: string): string;
13
+ document_open(path: string): string;
14
+ document_save(handle: number, path: string, overwrite: boolean): string;
15
+ document_inspect(handle: number, checksJson?: string): string;
16
+ document_summary(handle: number): string;
17
+ document_outline(handle: number): string;
18
+ word_stats(handle: number): string;
19
+ document_find(handle: number, query: string, limit?: number): string;
20
+ document_replace(handle: number, requestJson: string): string;
21
+ document_edit(handle: number, requestJson: string): string;
22
+ document_undo(handle: number, steps?: number): string;
23
+ document_redo(handle: number, steps?: number): string;
24
+ document_merge(handle: number, path: string, mode?: string): string;
25
+ document_export(handle: number, format: string, target: string, overwrite?: boolean): string;
26
+ document_close(handle: number): boolean;
27
+ openGui(options?: {
28
+ title?: string;
29
+ contentDir?: string;
30
+ width?: number;
31
+ height?: number;
32
+ }): string;
33
+ pumpEvents(): string;
34
+ closeGui(): string;
35
+ isGuiOpen(): boolean;
36
+ }
37
+ /** Loads the addon once, or returns `undefined` when it is not installed. */
38
+ export declare function nativeBinding(): NativeBinding | undefined;
package/dist/native.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Native addon discovery.
3
+ *
4
+ * The addon only maps values: document semantics, saving and export stay in the
5
+ * shared engine. An absent addon is a declarative state, so capability calls
6
+ * report `capability/not-implemented` instead of inventing a matrix.
7
+ */
8
+ import { createRequire } from 'node:module';
9
+ const requireNative = createRequire(import.meta.url);
10
+ let cached;
11
+ /** Loads the addon once, or returns `undefined` when it is not installed. */
12
+ export function nativeBinding() {
13
+ if (cached === undefined) {
14
+ cached = load();
15
+ }
16
+ return cached ?? undefined;
17
+ }
18
+ function load() {
19
+ for (const candidate of candidates()) {
20
+ try {
21
+ return requireNative(candidate);
22
+ }
23
+ catch (error) {
24
+ if (candidate === explicitPath()) {
25
+ throw error;
26
+ }
27
+ if (!isModuleNotFound(error, candidate)) {
28
+ throw error;
29
+ }
30
+ }
31
+ }
32
+ return null;
33
+ }
34
+ function candidates() {
35
+ const explicit = explicitPath();
36
+ if (explicit) {
37
+ return [explicit];
38
+ }
39
+ return [`@wae/open-word-${process.platform}-${process.arch}`];
40
+ }
41
+ function explicitPath() {
42
+ const value = process.env.OPEN_WORD_NATIVE;
43
+ return value !== undefined && value.length > 0 ? value : undefined;
44
+ }
45
+ function isModuleNotFound(error, candidate) {
46
+ if (typeof error !== 'object' || error === null) {
47
+ return false;
48
+ }
49
+ const code = error.code;
50
+ // Node prints the resolved path, which uses the platform separator on
51
+ // Windows. Normalize it so a linked platform package without a built
52
+ // addon is still treated as "not installed" instead of a fatal error.
53
+ const message = error.message.replace(/\\/g, '/');
54
+ return code === 'MODULE_NOT_FOUND' && message.includes(candidate);
55
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * `new OpenWord(options?)` authoring session.
3
+ *
4
+ * The constructor is synchronous and opens nothing: no network, no disk scan,
5
+ * no window, no file. Native initialisation and imports happen inside the async
6
+ * methods, so a failure is always awaited and always carries a stable code.
7
+ */
8
+ import type { Document, DocumentCapabilities, DocumentCreateInput, DocumentOpenInput, DocumentOutline, EditOperation, EditOptions, EditReport, ExportFormat, ExportReport, FindHit, FindOptions, InspectOptions, InspectReport, MergeOptions, MergeResult, OpenWordOptions, RedoResult, ReplaceOptions, ReplaceReport, SaveOptions, SaveReport, StatsReport, UndoResult } from './types.js';
9
+ /** Authoring session. One instance manages one declared document surface. */
10
+ export declare class OpenWord {
11
+ /** BCP-47 tag used for diagnostics and default copy. */
12
+ readonly locale: string;
13
+ private closed;
14
+ private active;
15
+ private readonly handles;
16
+ constructor(options?: OpenWordOptions);
17
+ /** Whether {@link dispose} has run. */
18
+ get disposed(): boolean;
19
+ /**
20
+ * Format, checker, renderer and export disclosure for the installed engine.
21
+ * Read this instead of treating a method name as a capability.
22
+ */
23
+ capabilities(): Promise<DocumentCapabilities>;
24
+ /** Creates a document from a title and an optional template. */
25
+ create(options?: DocumentCreateInput): Promise<Document>;
26
+ /** Opens a native project or a document at a path. */
27
+ open(input: DocumentOpenInput): Promise<Document>;
28
+ /** Writes the active document to a native project path. */
29
+ save(target: string, options?: SaveOptions): Promise<SaveReport>;
30
+ /** Reports block, paragraph, heading, table, word and reading-time counts. */
31
+ stats(): Promise<StatsReport>;
32
+ /**
33
+ * Reads the nested heading outline of the active document.
34
+ *
35
+ * Every section appears once, nested under the closest preceding heading
36
+ * with a lower level. Each item carries its `section-N` id, heading level,
37
+ * title (`null` when empty), depth-first `blockIndex` and child items.
38
+ */
39
+ outline(): Promise<DocumentOutline>;
40
+ /** Exports the active document to one projection target. */
41
+ export(options: {
42
+ readonly format: ExportFormat;
43
+ readonly target: string;
44
+ readonly overwrite?: boolean;
45
+ }): Promise<ExportReport>;
46
+ /**
47
+ * Applies one atomic edit batch and returns the committed summary with one
48
+ * result per operation.
49
+ *
50
+ * `expectedRevision` rejects a batch written against an older revision with
51
+ * `document/revision-conflict` before anything mutates.
52
+ */
53
+ edit(operations: readonly EditOperation[], options?: EditOptions): Promise<EditReport>;
54
+ /**
55
+ * Undoes the last `steps` committed mutations (default 1).
56
+ *
57
+ * History is process-local and capped at 50 mutations; asking for more steps
58
+ * than are retained rejects with `session/argument-invalid` and changes
59
+ * nothing. A successful undo bumps the revision once.
60
+ */
61
+ undo(options?: {
62
+ readonly steps?: number;
63
+ }): Promise<UndoResult>;
64
+ /** Replays undone mutations, most recent first. */
65
+ redo(options?: {
66
+ readonly steps?: number;
67
+ }): Promise<RedoResult>;
68
+ /**
69
+ * Appends another document's blocks to the active document.
70
+ *
71
+ * The donor is opened through the same routing as `open()`, so `.docx`,
72
+ * `.md`, `.html`, `.rtf`, `.txt` and `.oword` are accepted; merging the
73
+ * file the document was opened from is allowed.
74
+ */
75
+ merge(path: string, options?: MergeOptions): Promise<MergeResult>;
76
+ /** Inspects an input through a transient handle that is always released. */
77
+ inspect(input: DocumentOpenInput, options?: InspectOptions): Promise<InspectReport>;
78
+ /**
79
+ * Finds text across section titles, paragraphs, list items and table cells.
80
+ *
81
+ * Offsets are character positions inside the matched block's plain text.
82
+ */
83
+ find(query: string, options?: FindOptions): Promise<readonly FindHit[]>;
84
+ /**
85
+ * Replaces `find` with `replacement` and reports the changed blocks.
86
+ *
87
+ * Matching is case-sensitive by default; `wholeWord` requires no word
88
+ * character on either side. A pass that finds nothing changes nothing, so
89
+ * it records no history entry. A committing pass advances the revision once
90
+ * and can be undone with `undo()`.
91
+ */
92
+ replace(find: string, replacement: string, options?: ReplaceOptions): Promise<ReplaceReport>;
93
+ /** Releases every tracked handle. Idempotent. */
94
+ dispose(): Promise<void>;
95
+ /** @internal Throws `document/not-found` when no document is active. */
96
+ private requireHandle;
97
+ /** @internal Throws `session/disposed` once the session is gone. */
98
+ assertActive(): void;
99
+ }