oasis-editor 0.0.81 → 0.0.83

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.
@@ -8,9 +8,9 @@
8
8
  */
9
9
  export type { EditorUnderlineStyle, EditorLigatures, EditorNumberSpacing, EditorNumberForm, EditorTextLanguage, EditorBorderStyle, EditorTabStop, EditorParagraphListStyle, EditorImageCrop, EditorImageFillMode, EditorImageFloatingPosition, EditorImageFloatingLayout, EditorImageRunData, EditorWrapPolygonPoint, EditorFieldData, EditorFieldChar, EditorFootnoteReferenceData, EditorEndnoteReferenceData, EditorRevision, EditorAsset, EditorFootnoteNumberFormat, EditorFootnoteRestart, EditorDocxWidthValue, EditorTableLayout, EditorTableRowHeightRule, } from './types/primitives.js';
10
10
  export type { EditorTextStyle, EditorParagraphStyle, EditorTableStyle, EditorTableConditionalFormat, EditorConditionalRowStyle, EditorNamedStyle, } from './types/styles.js';
11
- export type { EditorTextRun, EditorTextBoxShape, EditorTextBoxBody, EditorTextBoxData, EditorDropCap, EditorParagraphNode, EditorTableCellStyle, EditorTableCellNode, EditorTableRowStyle, EditorTableRowNode, EditorTableNode, EditorBlockNode, } from './types/nodes.js';
12
- export type { RunKind, RunVisitor } from './runKind.js';
13
- export { getRunKind, isInlineObjectRun, visitRun } from './runKind.js';
11
+ export type { EditorRunBase, EditorTextRun, EditorTextBoxShape, EditorTextBoxBody, EditorTextBoxData, EditorDropCap, EditorParagraphNode, EditorTableCellStyle, EditorTableCellNode, EditorTableRowStyle, EditorTableRowNode, EditorTableNode, EditorBlockNode, } from './types/nodes.js';
12
+ export type { RunKind, RunOfKind, RunVisitor } from './runKind.js';
13
+ export { getRunKind, isInlineObjectRun, visitRun, getRunImage, getRunTextBox, getRunField, getRunFieldChar, getRunFieldInstruction, getRunFootnoteReference, getRunEndnoteReference, getRunSym, } from './runKind.js';
14
14
  export type { EditorFootnote } from './types/documentFootnotes.js';
15
15
  export type { EditorEndnote } from './types/documentEndnotes.js';
16
16
  export type { EditorBookmark, EditorBookmarkAnchor, EditorBookmarks, } from './types/documentBookmarks.js';
@@ -1,40 +1,45 @@
1
- import { EditorTextRun } from './types/nodes.js';
1
+ import { EditorTextBoxData, EditorTextRun } from './types/nodes.js';
2
+ import { EditorFieldChar, EditorFieldData, EditorImageRunData, EditorFootnoteReferenceData, EditorEndnoteReferenceData } from './types/primitives.js';
2
3
 
3
4
  /**
4
- * Discriminated classification of an {@link EditorTextRun}.
5
- *
6
- * `EditorTextRun` is a flat bag of optional fields (`image`, `textBox`,
7
- * `field`, …) with no discriminant, so adding a new inline object means every
8
- * dispatch site has to remember to handle it (O1). `getRunKind` derives the
9
- * effective kind once, in the canonical precedence the DOCX serializer uses
10
- * (`export/docx/text/runXml.ts`), and `visitRun` turns that into an exhaustive
11
- * dispatch — a missing branch is a compile error.
12
- *
13
- * This is purely derived from the existing fields; it does not change the wire
14
- * shape. It is the safe first step before migrating `EditorTextRun` itself to a
15
- * discriminated union.
16
- */
17
- export type RunKind = "footnoteReference" | "endnoteReference" | "fieldChar" | "fieldInstruction" | "field" | "textBox" | "image" | "sym" | "text";
18
- /**
19
- * Classifies a run by its highest-precedence object field. The order mirrors
20
- * `serializeRun` so callers that switch on the kind agree with export.
5
+ * Discriminant of an {@link EditorTextRun}. `EditorTextRun` is a discriminated
6
+ * union keyed on `kind`; `getRunKind`/`visitRun` are thin helpers over it so
7
+ * dispatch stays in one place and adding a variant is a compile error (O1).
21
8
  */
9
+ export type RunKind = EditorTextRun["kind"];
10
+ /** The union member for a given run kind. */
11
+ export type RunOfKind<K extends RunKind> = Extract<EditorTextRun, {
12
+ kind: K;
13
+ }>;
14
+ /** Returns a run's discriminant. */
22
15
  export declare function getRunKind(run: EditorTextRun): RunKind;
23
16
  /** True for runs that carry an inline object replacement (image or text box). */
24
17
  export declare function isInlineObjectRun(run: EditorTextRun): boolean;
18
+ export declare function getRunImage(run: EditorTextRun): EditorImageRunData | undefined;
19
+ export declare function getRunTextBox(run: EditorTextRun): EditorTextBoxData | undefined;
20
+ export declare function getRunField(run: EditorTextRun): EditorFieldData | undefined;
21
+ export declare function getRunFieldChar(run: EditorTextRun): EditorFieldChar | undefined;
22
+ export declare function getRunFieldInstruction(run: EditorTextRun): string | undefined;
23
+ export declare function getRunFootnoteReference(run: EditorTextRun): EditorFootnoteReferenceData | undefined;
24
+ export declare function getRunEndnoteReference(run: EditorTextRun): EditorEndnoteReferenceData | undefined;
25
+ export declare function getRunSym(run: EditorTextRun): {
26
+ font: string;
27
+ char: string;
28
+ } | undefined;
25
29
  export interface RunVisitor<R> {
26
- text(run: EditorTextRun): R;
27
- image(run: EditorTextRun): R;
28
- textBox(run: EditorTextRun): R;
29
- field(run: EditorTextRun): R;
30
- fieldChar(run: EditorTextRun): R;
31
- fieldInstruction(run: EditorTextRun): R;
32
- footnoteReference(run: EditorTextRun): R;
33
- endnoteReference(run: EditorTextRun): R;
34
- sym(run: EditorTextRun): R;
30
+ text(run: RunOfKind<"text">): R;
31
+ image(run: RunOfKind<"image">): R;
32
+ textBox(run: RunOfKind<"textBox">): R;
33
+ field(run: RunOfKind<"field">): R;
34
+ fieldChar(run: RunOfKind<"fieldChar">): R;
35
+ fieldInstruction(run: RunOfKind<"fieldInstruction">): R;
36
+ footnoteReference(run: RunOfKind<"footnoteReference">): R;
37
+ endnoteReference(run: RunOfKind<"endnoteReference">): R;
38
+ sym(run: RunOfKind<"sym">): R;
35
39
  }
36
40
  /**
37
- * Exhaustive dispatch over a run's kind. Adding a `RunKind` variant forces every
41
+ * Exhaustive dispatch over a run's kind, narrowing the run to the matching union
42
+ * member inside each visitor method. Adding a `RunKind` variant forces every
38
43
  * `RunVisitor` to grow the matching method (compile error otherwise).
39
44
  */
40
45
  export declare function visitRun<R>(run: EditorTextRun, visitor: RunVisitor<R>): R;
@@ -58,41 +58,76 @@ export interface EditorTextBoxData {
58
58
  shape?: EditorTextBoxShape;
59
59
  body?: EditorTextBoxBody;
60
60
  }
61
- export interface EditorTextRun {
61
+ /**
62
+ * Fields shared by every run kind. `text` is always present (inline objects use
63
+ * the object-replacement character ``); `revision` can decorate a run of
64
+ * any kind (insert/delete tracking).
65
+ */
66
+ export interface EditorRunBase {
62
67
  id: string;
63
68
  text: string;
64
69
  styles?: EditorTextStyle;
65
- image?: EditorImageRunData;
66
- textBox?: EditorTextBoxData;
67
- field?: EditorFieldData;
68
- /**
69
- * Preserved complex-field control char (`w:fldChar`). Zero-length marker run;
70
- * see {@link EditorFieldChar}.
71
- */
72
- fieldChar?: EditorFieldChar;
73
- /** Preserved field instruction text (`w:instrText`). Zero-length marker run. */
74
- fieldInstruction?: string;
75
70
  revision?: EditorRevision;
76
- /**
77
- * Inline marker of a footnote whose body lives in
78
- * `EditorDocument.footnotes.items[footnoteReference.footnoteId]`.
79
- */
80
- footnoteReference?: EditorFootnoteReferenceData;
81
- /**
82
- * Inline marker of an endnote whose body lives in
83
- * `EditorDocument.endnotes.items[endnoteReference.endnoteId]`.
84
- */
85
- endnoteReference?: EditorEndnoteReferenceData;
86
- /**
87
- * Round-trip metadata for `w:sym` — a glyph from a named font.
88
- * `font` is the `w:font` attribute value; `char` is the 4-digit hex `w:char` value.
89
- * The character is also stored in `text` so the canvas can render it.
90
- */
91
- sym?: {
71
+ }
72
+ /**
73
+ * A run of text, optionally carrying one inline object. Discriminated by `kind`
74
+ * so adding a new inline object forces every dispatch site to handle it (a
75
+ * missing branch is a compile error) and invalid combinations (e.g. `image` +
76
+ * `textBox`) are unrepresentable (O1). The `kind` values mirror {@link RunKind}.
77
+ */
78
+ export type EditorTextRun = (EditorRunBase & {
79
+ kind: "text";
80
+ }) | (EditorRunBase & {
81
+ kind: "image";
82
+ image: EditorImageRunData;
83
+ }) | (EditorRunBase & {
84
+ kind: "textBox";
85
+ textBox: EditorTextBoxData;
86
+ }) | (EditorRunBase & {
87
+ kind: "field";
88
+ field: EditorFieldData;
89
+ })
90
+ /**
91
+ * Preserved complex-field control char (`w:fldChar`). Zero-length marker run;
92
+ * see {@link EditorFieldChar}.
93
+ */
94
+ | (EditorRunBase & {
95
+ kind: "fieldChar";
96
+ fieldChar: EditorFieldChar;
97
+ })
98
+ /** Preserved field instruction text (`w:instrText`). Zero-length marker run. */
99
+ | (EditorRunBase & {
100
+ kind: "fieldInstruction";
101
+ fieldInstruction: string;
102
+ })
103
+ /**
104
+ * Inline marker of a footnote whose body lives in
105
+ * `EditorDocument.footnotes.items[footnoteReference.footnoteId]`.
106
+ */
107
+ | (EditorRunBase & {
108
+ kind: "footnoteReference";
109
+ footnoteReference: EditorFootnoteReferenceData;
110
+ })
111
+ /**
112
+ * Inline marker of an endnote whose body lives in
113
+ * `EditorDocument.endnotes.items[endnoteReference.endnoteId]`.
114
+ */
115
+ | (EditorRunBase & {
116
+ kind: "endnoteReference";
117
+ endnoteReference: EditorEndnoteReferenceData;
118
+ })
119
+ /**
120
+ * Round-trip metadata for `w:sym` — a glyph from a named font. `font` is the
121
+ * `w:font` attribute value; `char` is the 4-digit hex `w:char` value. The
122
+ * character is also stored in `text` so the canvas can render it.
123
+ */
124
+ | (EditorRunBase & {
125
+ kind: "sym";
126
+ sym: {
92
127
  font: string;
93
128
  char: string;
94
129
  };
95
- }
130
+ });
96
131
  /**
97
132
  * A drop cap (Word's `w:framePr/@dropCap`): a large initial letter sunk into
98
133
  * the first lines of the paragraph, with body text wrapping around it. In OOXML