@p10node/office-engine 0.0.0-stage → 0.1.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 (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +65 -2
  3. package/dist/DocViewer-Cv4LaMB_.js +9342 -0
  4. package/dist/DocViewer-Cv4LaMB_.js.map +1 -0
  5. package/dist/THIRD_PARTY_LICENSES.txt +79 -0
  6. package/dist/assets/worker-CJfZ05I7.js.map +1 -0
  7. package/dist/collab-BzN1ZI-z.js +1984 -0
  8. package/dist/collab-BzN1ZI-z.js.map +1 -0
  9. package/dist/collab.js +2 -0
  10. package/dist/core.js +2 -0
  11. package/dist/default-worker-B5CGBnic.js +9193 -0
  12. package/dist/default-worker-B5CGBnic.js.map +1 -0
  13. package/dist/embed.js +83 -0
  14. package/dist/embed.js.map +1 -0
  15. package/dist/index.js +5 -0
  16. package/dist/office-engine.embed.js +33 -0
  17. package/dist/office-engine.worker.js +9092 -0
  18. package/dist/types/collab/codec.d.ts +3 -0
  19. package/dist/types/collab/docx.d.ts +166 -0
  20. package/dist/types/collab/hosts.d.ts +24 -0
  21. package/dist/types/collab/hub.d.ts +41 -0
  22. package/dist/types/collab/index.d.ts +43 -0
  23. package/dist/types/collab/pptx-ops.d.ts +60 -0
  24. package/dist/types/collab/pptx-worker.d.ts +35 -0
  25. package/dist/types/collab/pptx.d.ts +47 -0
  26. package/dist/types/collab/protocol.d.ts +76 -0
  27. package/dist/types/collab/react.d.ts +23 -0
  28. package/dist/types/collab/session.d.ts +115 -0
  29. package/dist/types/collab/transport.d.ts +47 -0
  30. package/dist/types/collab/xlsx-ops.d.ts +72 -0
  31. package/dist/types/collab/xlsx-worker.d.ts +29 -0
  32. package/dist/types/collab/xlsx.d.ts +51 -0
  33. package/dist/types/core/color.d.ts +25 -0
  34. package/dist/types/core/default-worker.d.ts +1 -0
  35. package/dist/types/core/docx/numbering.d.ts +33 -0
  36. package/dist/types/core/docx/parser.d.ts +126 -0
  37. package/dist/types/core/docx/spec.d.ts +4 -0
  38. package/dist/types/core/docx/styles.d.ts +63 -0
  39. package/dist/types/core/docx/types.d.ts +325 -0
  40. package/dist/types/core/docx/writer.d.ts +35 -0
  41. package/dist/types/core/fonts.d.ts +1 -0
  42. package/dist/types/core/index.d.ts +15 -0
  43. package/dist/types/core/opc.d.ts +56 -0
  44. package/dist/types/core/pptx/edit.d.ts +10 -0
  45. package/dist/types/core/pptx/parser.d.ts +52 -0
  46. package/dist/types/core/pptx/types.d.ts +238 -0
  47. package/dist/types/core/raw.d.ts +40 -0
  48. package/dist/types/core/source.d.ts +65 -0
  49. package/dist/types/core/theme.d.ts +11 -0
  50. package/dist/types/core/units.d.ts +7 -0
  51. package/dist/types/core/worker/client.d.ts +48 -0
  52. package/dist/types/core/worker/engine.d.ts +27 -0
  53. package/dist/types/core/worker/protocol.d.ts +112 -0
  54. package/dist/types/core/worker/worker.d.ts +1 -0
  55. package/dist/types/core/xlsx/calc.d.ts +31 -0
  56. package/dist/types/core/xlsx/editor.d.ts +95 -0
  57. package/dist/types/core/xlsx/formula/assist.d.ts +35 -0
  58. package/dist/types/core/xlsx/formula/catalog.d.ts +14 -0
  59. package/dist/types/core/xlsx/formula/dates.d.ts +23 -0
  60. package/dist/types/core/xlsx/formula/evaluate.d.ts +33 -0
  61. package/dist/types/core/xlsx/formula/fn-date.d.ts +2 -0
  62. package/dist/types/core/xlsx/formula/fn-logic.d.ts +3 -0
  63. package/dist/types/core/xlsx/formula/fn-lookup.d.ts +3 -0
  64. package/dist/types/core/xlsx/formula/fn-math.d.ts +3 -0
  65. package/dist/types/core/xlsx/formula/fn-stats.d.ts +3 -0
  66. package/dist/types/core/xlsx/formula/fn-text.d.ts +3 -0
  67. package/dist/types/core/xlsx/formula/fn.d.ts +64 -0
  68. package/dist/types/core/xlsx/formula/format.d.ts +5 -0
  69. package/dist/types/core/xlsx/formula/functions.d.ts +4 -0
  70. package/dist/types/core/xlsx/formula/index.d.ts +17 -0
  71. package/dist/types/core/xlsx/formula/lexer.d.ts +54 -0
  72. package/dist/types/core/xlsx/formula/parser.d.ts +53 -0
  73. package/dist/types/core/xlsx/formula/refs.d.ts +23 -0
  74. package/dist/types/core/xlsx/formula/transform.d.ts +21 -0
  75. package/dist/types/core/xlsx/formula/types.d.ts +59 -0
  76. package/dist/types/core/xlsx/formula/values.d.ts +49 -0
  77. package/dist/types/core/xlsx/numfmt.d.ts +11 -0
  78. package/dist/types/core/xlsx/structure.d.ts +31 -0
  79. package/dist/types/core/xlsx/styles.d.ts +17 -0
  80. package/dist/types/core/xlsx/types.d.ts +193 -0
  81. package/dist/types/core/xlsx/workbook.d.ts +94 -0
  82. package/dist/types/core/xml.d.ts +80 -0
  83. package/dist/types/core/zip.d.ts +35 -0
  84. package/dist/types/core/zipwrite.d.ts +9 -0
  85. package/dist/types/embed.d.ts +30 -0
  86. package/dist/types/index.d.ts +18 -0
  87. package/dist/types/react/DocViewer.d.ts +43 -0
  88. package/dist/types/react/common/ContextMenu.d.ts +21 -0
  89. package/dist/types/react/common/Dialog.d.ts +27 -0
  90. package/dist/types/react/common/Slots.d.ts +18 -0
  91. package/dist/types/react/common/Status.d.ts +6 -0
  92. package/dist/types/react/common/ZoomControl.d.ts +6 -0
  93. package/dist/types/react/common/hooks.d.ts +20 -0
  94. package/dist/types/react/docx/DocxEditor.d.ts +172 -0
  95. package/dist/types/react/docx/DocxToolbar.d.ts +18 -0
  96. package/dist/types/react/docx/DocxView.d.ts +8 -0
  97. package/dist/types/react/docx/FindBar.d.ts +22 -0
  98. package/dist/types/react/docx/html.d.ts +8 -0
  99. package/dist/types/react/docx/render.d.ts +24 -0
  100. package/dist/types/react/docx/tables.d.ts +20 -0
  101. package/dist/types/react/edit/Toolbar.d.ts +130 -0
  102. package/dist/types/react/edit/input.d.ts +81 -0
  103. package/dist/types/react/edit/rich.d.ts +40 -0
  104. package/dist/types/react/injectStyles.d.ts +4 -0
  105. package/dist/types/react/pptx/PptxEditor.d.ts +95 -0
  106. package/dist/types/react/pptx/PptxToolbar.d.ts +36 -0
  107. package/dist/types/react/pptx/PptxView.d.ts +24 -0
  108. package/dist/types/react/pptx/Presenter.d.ts +9 -0
  109. package/dist/types/react/pptx/Slide.d.ts +28 -0
  110. package/dist/types/react/pptx/geometry.d.ts +5 -0
  111. package/dist/types/react/useDocument.d.ts +11 -0
  112. package/dist/types/react/xlsx/XlsxToolbar.d.ts +27 -0
  113. package/dist/types/react/xlsx/XlsxView.d.ts +16 -0
  114. package/dist/types/react/xlsx/axis.d.ts +19 -0
  115. package/dist/xlsx-ops-CsjNpMI0.js +244 -0
  116. package/dist/xlsx-ops-CsjNpMI0.js.map +1 -0
  117. package/package.json +80 -4
@@ -0,0 +1,172 @@
1
+ import type { Block, CanonStyle, Paragraph, ParaDirty, ParaStyle, RunSet, RunStyle, StyleInfo } from '../../core/docx/types';
2
+ import type { DocumentClient } from '../../core/worker/client';
3
+ import { RichInput, type ReplaceOpts, type RichHost } from '../edit/input';
4
+ import { type RRun, type Sel } from '../edit/rich';
5
+ export interface DocState {
6
+ blocks: Block[];
7
+ heights: WeakMap<Block, number>;
8
+ dirty: Set<Block>;
9
+ /** leading blocks measured at least once */
10
+ frontier: number;
11
+ }
12
+ export interface FormatState {
13
+ b: boolean;
14
+ i: boolean;
15
+ u: boolean;
16
+ strike: boolean;
17
+ color?: string;
18
+ hl?: string;
19
+ sz?: number;
20
+ font?: string;
21
+ align?: string;
22
+ style?: string;
23
+ lst?: 'bullet' | 'number';
24
+ line?: number;
25
+ va?: 'sup' | 'sub';
26
+ link?: string;
27
+ /** caret inside a table cell */
28
+ inTable: boolean;
29
+ /** a single image is selected */
30
+ img?: {
31
+ w: number;
32
+ h: number;
33
+ alt?: string;
34
+ target: string;
35
+ pa: string;
36
+ o: number;
37
+ };
38
+ canUndo: boolean;
39
+ canRedo: boolean;
40
+ }
41
+ /** a model change: contiguous paragraphs replaced, or top-level blocks replaced */
42
+ export type DocxCommit = {
43
+ kind: 'paras';
44
+ before: Paragraph[];
45
+ next: Paragraph[];
46
+ } | {
47
+ kind: 'blocks';
48
+ bi: number;
49
+ before: Block[];
50
+ next: Block[];
51
+ };
52
+ export declare class DocxEditor implements RichHost<Paragraph> {
53
+ private client;
54
+ private st;
55
+ private changed;
56
+ readonly input: RichInput;
57
+ pendingSel: Sel | null;
58
+ styles: StyleInfo[];
59
+ private history;
60
+ private future;
61
+ private pend;
62
+ /** next id for new paragraphs / tables (a collaboration session gives each client its own range) */
63
+ nextPid: number;
64
+ private inflight;
65
+ onState?: (s: FormatState | null) => void;
66
+ /** image selection changed (overlay with resize handles) */
67
+ onImage?: (img: FormatState['img'] | null) => void;
68
+ /** style list changed (a built-in style was added to the document) */
69
+ onStyles?: (styles: StyleInfo[]) => void;
70
+ shortcut?: (e: KeyboardEvent) => boolean;
71
+ onDirty?: () => void;
72
+ /** paint format: run formatting copied from the caret, applied to the next selection */
73
+ painter: RunSet | null;
74
+ onPainter?: (on: boolean) => void;
75
+ /** every model change, after it was mirrored to the worker (collaboration hook) */
76
+ onCommit?: (c: DocxCommit) => void;
77
+ constructor(client: DocumentClient, st: DocState, changed: () => void);
78
+ private container;
79
+ para(pa: string): Paragraph | undefined;
80
+ span(a: string, b: string): string[] | null;
81
+ prev(pa: string): string | undefined;
82
+ next(pa: string): string | undefined;
83
+ cmp(a: string, b: string): number;
84
+ withRuns(p: Paragraph, runs: RRun[]): Paragraph;
85
+ private origOf;
86
+ defaultRun(p: Paragraph): Partial<RRun> | undefined;
87
+ split(p: Paragraph, left: RRun[], right: RRun[], atEnd: boolean): [Paragraph, Paragraph];
88
+ join(a: Paragraph, b: Paragraph, runs: RRun[]): Paragraph;
89
+ private splice;
90
+ replace(pas: string[], next: Paragraph[], sel: Sel, opts?: ReplaceOpts & {
91
+ history?: boolean;
92
+ want?: boolean;
93
+ }): void;
94
+ /** contiguous blocks sharing `pid` around index `near` */
95
+ private partsOf;
96
+ private commit;
97
+ get busy(): boolean;
98
+ private locate;
99
+ private put;
100
+ private applyResult;
101
+ /** current address of the first block of `list` (paragraphs by pid, tables by identity), `empty` for an empty list; undefined when gone */
102
+ private whereNow;
103
+ /** table undo / redo: paragraphs still in place keep their current text (edited since, maybe by collaborators) */
104
+ private keepCurrent;
105
+ undo(): void;
106
+ redo(): void;
107
+ get canUndo(): boolean;
108
+ get canRedo(): boolean;
109
+ pendingStyle(): Partial<RRun> | undefined;
110
+ clearPending(): void;
111
+ private selectedParas;
112
+ format(s: Partial<RunStyle>, d: RunSet, opts?: {
113
+ want?: boolean;
114
+ }): void;
115
+ toggle(key: 'b' | 'i' | 'u' | 'strike'): void;
116
+ setFont(name: string): void;
117
+ setSize(sz: number): void;
118
+ setColor(c: string | null): void;
119
+ setHighlight(c: string | null): void;
120
+ clearFormat(): void;
121
+ setPara(patch: ParaDirty, optimistic?: Partial<ParaStyle>, sel?: Sel | null): void;
122
+ toggleList(kind: 'bullet' | 'number'): void;
123
+ indent(dir: 1 | -1, sel?: Sel | null): void;
124
+ tab(sel: Sel, shift: boolean): boolean;
125
+ backspaceAtStart(pa: string, p: Paragraph): boolean;
126
+ /** content width (pt) of the page, for sizing new tables / images */
127
+ contentW: number;
128
+ /** document default font (CSS) / size, shown when a run inherits them */
129
+ defaultFont?: string;
130
+ defaultSz?: number;
131
+ private prevParaPid;
132
+ private tableSpec;
133
+ private commitTable;
134
+ private send;
135
+ /** Replaces top-level blocks (table insert/delete/restructure) with history + write-back. */
136
+ replaceBlocks(bi: number, count: number, next: Block[], sel: Sel | null, history?: boolean): void;
137
+ private emptyPara;
138
+ insertTable(rowsN: number, colsN: number): void;
139
+ /** Structural table edit at the caret's cell. */
140
+ tableOp(kind: 'rowAbove' | 'rowBelow' | 'colLeft' | 'colRight' | 'delRow' | 'delCol' | 'delTable'): void;
141
+ insertImages(files: Blob[], at?: Sel): Promise<void>;
142
+ setLink(url: string | null): Promise<void>;
143
+ /** applies `fn` to the text runs inside the selection */
144
+ private patchRuns;
145
+ insertPageBreak(): void;
146
+ /** scales the selected image (factor) or fits it to the page width */
147
+ resizeImage(f: number | 'fit'): void;
148
+ private patchObjects;
149
+ pasteRich(sel: Sel, data: DataTransfer): boolean;
150
+ /** applies a built-in style (Title, Heading 1…), creating it in the document when missing */
151
+ applyCanon(kind: CanonStyle): Promise<void>;
152
+ /** selects the inline object at (pa, o) */
153
+ selectObject(pa: string, o: number): void;
154
+ private imageSel;
155
+ private patchImage;
156
+ /** exact size in pt */
157
+ setImageSize(w: number, h: number): void;
158
+ /** natural pixel size of the picture → pt, limited to the text width */
159
+ imageOriginal(nw: number, nh: number): void;
160
+ setAltText(alt: string): void;
161
+ replaceImage(file: Blob): Promise<void>;
162
+ /** deletes the selection (or the selected object) */
163
+ deleteSelection(): void;
164
+ insertText(text: string): void;
165
+ /** copies the caret's character formatting; the next selection receives it */
166
+ copyFormat(): void;
167
+ /** applies the copied formatting to the current selection (after the mouse is released) */
168
+ applyPainter(): boolean;
169
+ state(sel?: Sel | null): FormatState | null;
170
+ private emitState;
171
+ onSelection(sel: Sel | null): void;
172
+ }
@@ -0,0 +1,18 @@
1
+ import type { StyleInfo } from '../../core/docx/types';
2
+ import type { DocxEditor } from './DocxEditor';
3
+ export interface ImageActions {
4
+ original: () => void;
5
+ replace: () => void;
6
+ alt: () => void;
7
+ download: () => void;
8
+ }
9
+ export declare function DocxToolbar(props: {
10
+ editor: DocxEditor;
11
+ styles: StyleInfo[];
12
+ onFind: () => void;
13
+ outline: boolean;
14
+ onOutline: () => void;
15
+ painter: boolean;
16
+ onLink: () => void;
17
+ image: ImageActions;
18
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { DocumentClient } from '../../core/worker/client';
2
+ import { type Zoom } from '../common/ZoomControl';
3
+ export interface DocxViewProps {
4
+ client: DocumentClient;
5
+ onStatus?: (s: string) => void;
6
+ initialZoom?: Zoom;
7
+ }
8
+ export declare function DocxView({ client, onStatus, initialZoom }: DocxViewProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface Match {
3
+ pa: string;
4
+ a: number;
5
+ b: number;
6
+ bi: number;
7
+ }
8
+ export declare function FindBar(props: {
9
+ query: string;
10
+ index: number;
11
+ count: number;
12
+ editable: boolean;
13
+ onQuery: (q: string) => void;
14
+ onNav: (d: 1 | -1) => void;
15
+ onClose: () => void;
16
+ onReplace: (text: string, all: boolean) => void;
17
+ placeholder?: string;
18
+ /** extra controls (match case…) under the search row */
19
+ options?: ReactNode;
20
+ /** open with the replace row visible */
21
+ replace?: boolean;
22
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import type { Inline } from '../../core/docx/types';
2
+ export interface PastedPara {
3
+ runs: Inline[];
4
+ heading?: number;
5
+ list?: 'bullet' | 'number';
6
+ }
7
+ /** Converts clipboard HTML (Word, Google Docs, web pages) into paragraphs of formatted runs. */
8
+ export declare function htmlToParas(html: string): PastedPara[];
@@ -0,0 +1,24 @@
1
+ import { type CSSProperties } from 'react';
2
+ import type { Block, RunStyle } from '../../core/docx/types';
3
+ import type { DocumentClient } from '../../core/worker/client';
4
+ export interface RenderCtx {
5
+ client: DocumentClient;
6
+ /** 0-based page index, -1 while measuring */
7
+ page: number;
8
+ pages: number;
9
+ measuring: boolean;
10
+ editable: boolean;
11
+ }
12
+ export declare function runCss(s: RunStyle | undefined): CSSProperties;
13
+ /** contextual spacing flags: 'b' drop space before, 'a' drop space after */
14
+ export type Spacing = '' | 'b' | 'a' | 'ba';
15
+ export declare function contextual(p: Block | undefined, prev: Block | undefined, next: Block | undefined): Spacing;
16
+ export interface BlockViewProps {
17
+ block: Block;
18
+ ctx: RenderCtx;
19
+ /** editable address (top-level: block index; table: block index used as prefix) */
20
+ pa?: string;
21
+ sp?: Spacing;
22
+ nested?: boolean;
23
+ }
24
+ export declare const BlockView: import("react").MemoExoticComponent<({ block, ctx, pa, sp, nested }: BlockViewProps) => import("react").JSX.Element>;
@@ -0,0 +1,20 @@
1
+ import type { Paragraph, Table, TableCell } from '../../core/docx/types';
2
+ export interface GridCell {
3
+ ri: number;
4
+ ci: number;
5
+ g: number;
6
+ cell: TableCell;
7
+ }
8
+ /** Grid positions of every cell (row spans occupy following rows). */
9
+ export declare function gridOf(t: Table): {
10
+ cells: GridCell[];
11
+ nCols: number;
12
+ at: (ri: number, g: number) => GridCell | undefined;
13
+ };
14
+ export type NewPara = (template: TableCell) => Paragraph;
15
+ export declare function insertRow(t: Table, ri: number, below: boolean, mk: NewPara): Table;
16
+ export declare function deleteRow(t: Table, ri: number): Table | null;
17
+ export declare function insertCol(t: Table, g0: number, right: boolean, mk: NewPara): Table;
18
+ export declare function deleteCol(t: Table, g: number): Table | null;
19
+ /** New table model (rows × cols) with simple single borders. */
20
+ export declare function newTable(rowsN: number, colsN: number, width: number, mk: () => Paragraph): Table;
@@ -0,0 +1,130 @@
1
+ import { type CSSProperties, type ReactNode, type RefObject } from 'react';
2
+ export declare function Icon({ name, size }: {
3
+ name: string;
4
+ size?: number;
5
+ }): import("react").JSX.Element;
6
+ /** closes a popup on outside mousedown (shadow-DOM safe: uses the composed path) */
7
+ export declare function useDismiss(ref: RefObject<HTMLElement | null>, open: boolean, close: () => void): void;
8
+ export declare function Btn(props: {
9
+ icon?: string;
10
+ label?: ReactNode;
11
+ title: string;
12
+ active?: boolean;
13
+ disabled?: boolean;
14
+ onClick: () => void;
15
+ wide?: boolean;
16
+ }): import("react").JSX.Element;
17
+ export declare const Sep: () => import("react").JSX.Element;
18
+ export interface DropOption<T> {
19
+ value: T;
20
+ label: string;
21
+ /** secondary text on the right (example, shortcut) */
22
+ hint?: string;
23
+ icon?: string;
24
+ /** label style (font / style previews) */
25
+ style?: CSSProperties;
26
+ disabled?: boolean;
27
+ /** separator above this option */
28
+ sep?: boolean;
29
+ }
30
+ /**
31
+ * Styled dropdown (listbox). Never takes focus from the editor: mouse down is prevented and,
32
+ * while open, keys are captured at the window (arrows, Enter, Escape, type-ahead).
33
+ */
34
+ export declare function Dropdown<T extends string | number>(props: {
35
+ title: string;
36
+ options: DropOption<T>[];
37
+ onChange: (v: T) => void;
38
+ /** selected value (check mark); omit for command menus */
39
+ value?: T | '';
40
+ placeholder?: string;
41
+ /** fixed trigger content (menus); null = icon only */
42
+ label?: ReactNode;
43
+ icon?: string;
44
+ width?: number;
45
+ menuWidth?: number;
46
+ disabled?: boolean;
47
+ /** popup aligned to the trigger's right edge */
48
+ alignRight?: boolean;
49
+ }): import("react").JSX.Element;
50
+ /** Value picker (fonts, styles, formats…). */
51
+ export declare function Select<T extends string | number>(props: {
52
+ value: T | '';
53
+ options: DropOption<T>[];
54
+ onChange: (v: T) => void;
55
+ title: string;
56
+ width?: number;
57
+ placeholder?: string;
58
+ menuWidth?: number;
59
+ disabled?: boolean;
60
+ }): import("react").JSX.Element;
61
+ /** Font size box: − [size] + with a list of common sizes (Google Docs style). */
62
+ export declare function SizeBox(props: {
63
+ value?: number;
64
+ placeholder?: number;
65
+ sizes?: number[];
66
+ onChange: (n: number) => void;
67
+ title?: string;
68
+ disabled?: boolean;
69
+ }): import("react").JSX.Element;
70
+ /**
71
+ * One-line toolbar: items that do not fit move into a "more" popover (like Google Docs).
72
+ * Item widths are measured once per set of items and cached for resizes.
73
+ */
74
+ export declare function ToolbarRow({ children }: {
75
+ children: ReactNode;
76
+ }): import("react").JSX.Element;
77
+ export declare function ColorBtn(props: {
78
+ icon: string;
79
+ title: string;
80
+ value?: string;
81
+ onPick: (c: string | null) => void;
82
+ palette?: string[];
83
+ noneLabel?: string;
84
+ }): import("react").JSX.Element;
85
+ export declare const FONTS: string[];
86
+ export declare const SIZES: number[];
87
+ /** Font picker options (each shown in its own face); keeps an unknown current font at the top. */
88
+ export declare function fontOptions(current?: string): DropOption<string>[];
89
+ /** Picks the first name of a CSS font stack. */
90
+ export declare function fontName(css: string | undefined): string;
91
+ export declare function download(blob: Blob, name: string): void;
92
+ /** Command menu: fixed label, items with optional icons. */
93
+ export declare function Menu(props: {
94
+ title: string;
95
+ label: string;
96
+ icon?: string;
97
+ items: {
98
+ value: string;
99
+ label: string;
100
+ icon?: string;
101
+ disabled?: boolean;
102
+ sep?: boolean;
103
+ hint?: string;
104
+ }[];
105
+ onPick: (v: string) => void;
106
+ width?: number;
107
+ }): import("react").JSX.Element;
108
+ /** Small popover anchored under a toolbar button. */
109
+ export declare function Pop(props: {
110
+ icon: string;
111
+ title: string;
112
+ children: (close: () => void) => ReactNode;
113
+ active?: boolean;
114
+ disabled?: boolean;
115
+ chevron?: boolean;
116
+ }): import("react").JSX.Element;
117
+ /** rows × cols picker for new tables */
118
+ export declare function GridPicker({ onPick }: {
119
+ onPick: (r: number, c: number) => void;
120
+ }): import("react").JSX.Element;
121
+ /** Inline text prompt (URL, sheet name…) inside a popover. */
122
+ export declare function PromptBox(props: {
123
+ placeholder: string;
124
+ initial?: string;
125
+ ok: string;
126
+ onOk: (v: string) => void;
127
+ extra?: ReactNode;
128
+ }): import("react").JSX.Element;
129
+ /** Opens the OS file picker (images by default). */
130
+ export declare function pickFiles(accept?: string, multiple?: boolean): Promise<File[]>;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Controlled contentEditable: the DOM is only a view. Every mutation is taken from
3
+ * `beforeinput` (cancelled) and applied to the model through a RichHost; IME
4
+ * composition (Vietnamese Telex/VNI, CJK…) is committed on `compositionend`.
5
+ */
6
+ import { type Pos, type RRun, type Sel } from './rich';
7
+ export interface RichPara {
8
+ runs: RRun[];
9
+ }
10
+ export interface ReplaceOpts {
11
+ label?: string;
12
+ /** rebuild paragraph DOM (after IME composition mutated it) */
13
+ remount?: boolean;
14
+ }
15
+ export interface RichHost<P extends RichPara = RichPara> {
16
+ para(pa: string): P | undefined;
17
+ /** inclusive list of paragraph addresses from a to b in one container, or null */
18
+ span(a: string, b: string): string[] | null;
19
+ prev(pa: string): string | undefined;
20
+ next(pa: string): string | undefined;
21
+ cmp(a: string, b: string): number;
22
+ /** replace contiguous paragraphs; `sel` is the selection afterwards */
23
+ replace(pas: string[], next: P[], sel: Sel, opts?: ReplaceOpts): void;
24
+ withRuns(p: P, runs: RRun[]): P;
25
+ split(p: P, left: RRun[], right: RRun[], atEnd: boolean): [P, P];
26
+ join(a: P, b: P, runs: RRun[]): P;
27
+ /** Backspace at offset 0 (e.g. leave a list); true when handled */
28
+ backspaceAtStart?(pa: string, p: P): boolean;
29
+ /** Tab inside a paragraph (e.g. indent list); true when handled */
30
+ tab?(sel: Sel, shift: boolean): boolean;
31
+ undo(): void;
32
+ redo(): void;
33
+ toggle?(key: 'b' | 'i' | 'u'): void;
34
+ shortcut?(e: KeyboardEvent): boolean;
35
+ /** style for text typed into an empty paragraph */
36
+ defaultRun?(p: P): Partial<RRun> | undefined;
37
+ /** paste with formatting / files; true when handled */
38
+ pasteRich?(sel: Sel, data: DataTransfer): boolean;
39
+ /** caret style for the next typed text (set after formatting a collapsed selection) */
40
+ pendingStyle?(): Partial<RRun> | undefined;
41
+ clearPending?(): void;
42
+ onSelection?(sel: Sel | null): void;
43
+ }
44
+ export declare function ordered(host: RichHost, s: Sel): [Pos, Pos];
45
+ export declare function opDelete(host: RichHost, sel: Sel, opts?: ReplaceOpts): void;
46
+ /**
47
+ * Inserts runs at the selection; `lines[i]` (i > 0) start new paragraphs.
48
+ * `props[i]` can adjust the paragraph created for line i (e.g. heading style from pasted HTML).
49
+ */
50
+ export declare function opInsertRuns(host: RichHost, sel: Sel, lines: RRun[][], opts?: ReplaceOpts, props?: ((p: RichPara) => RichPara)[]): void;
51
+ export declare function opInsert(host: RichHost, sel: Sel, text: string, opts?: ReplaceOpts): void;
52
+ export declare function opEnter(host: RichHost, sel: Sel): void;
53
+ export declare function opBackspace(host: RichHost, sel: Sel, word?: boolean): void;
54
+ export declare function opDeleteForward(host: RichHost, sel: Sel, word?: boolean): void;
55
+ export declare function posFromDom(root: HTMLElement, node: Node, offset: number): Pos | null;
56
+ export declare function domFromPos(root: HTMLElement, pos: Pos): [Node, number] | null;
57
+ /** Selection object that can see into the shadow root containing `node` (web component embeds). */
58
+ export declare function getSel(node: Node): Selection | null;
59
+ export declare class RichInput {
60
+ private host;
61
+ private root;
62
+ private composing;
63
+ private justComposed;
64
+ private raf;
65
+ lastSel: Sel | null;
66
+ constructor(host: RichHost);
67
+ attach(root: HTMLElement): void;
68
+ detach(): void;
69
+ get isComposing(): boolean;
70
+ readSel(): Sel | null;
71
+ /** current selection, falling back to the last known one (e.g. after focusing a toolbar control) */
72
+ sel(): Sel | null;
73
+ /** Applies a model selection to the DOM; false when its paragraph isn't rendered. */
74
+ restore(sel: Sel | null, focus?: boolean): boolean;
75
+ private rangeSel;
76
+ private onBeforeInput;
77
+ private onCompStart;
78
+ private onCompEnd;
79
+ private onKeyDown;
80
+ private onSelChange;
81
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Pure run-level text operations shared by the DOCX and PPTX editors.
3
+ * A run is either text ({ t: 'text', text }) or an atomic object counting as one character.
4
+ */
5
+ export interface RRun {
6
+ t: string;
7
+ text?: string;
8
+ s?: object;
9
+ d?: object;
10
+ src?: unknown;
11
+ href?: string;
12
+ lk?: string;
13
+ }
14
+ export interface Pos {
15
+ /** paragraph address (container path; last segment = index in container) */
16
+ pa: string;
17
+ o: number;
18
+ }
19
+ export interface Sel {
20
+ a: Pos;
21
+ f: Pos;
22
+ }
23
+ export declare const rlen: (r: RRun) => number;
24
+ export declare const plen: (runs: RRun[]) => number;
25
+ export declare const collapsed: (s: Sel) => boolean;
26
+ export declare const shiftPa: (pa: string, d: number) => string;
27
+ export declare function runsText(runs: RRun[]): string;
28
+ /** Merges adjacent identical text runs and drops empty ones. */
29
+ export declare function normalize<R extends RRun>(runs: R[]): R[];
30
+ /** Splits runs at offset o (text runs are cut). */
31
+ export declare function splitRuns<R extends RRun>(runs: R[], o: number): [R[], R[]];
32
+ export declare function sliceRuns<R extends RRun>(runs: R[], a: number, b: number): R[];
33
+ /** Text run whose style applies at offset o (left affinity). */
34
+ export declare function runAt<R extends RRun>(runs: R[], o: number): R | undefined;
35
+ export declare function insertText<R extends RRun>(runs: R[], o: number, text: string, style?: Partial<R>, fallback?: Partial<R>): R[];
36
+ export declare function deleteRange<R extends RRun>(runs: R[], a: number, b: number): R[];
37
+ export declare function formatRange<R extends RRun>(runs: R[], a: number, b: number, s: object, d: object): R[];
38
+ /** Previous grapheme boundary (surrogate pairs + combining marks). */
39
+ export declare function prevBoundary(text: string, o: number): number;
40
+ export declare function nextBoundary(text: string, o: number): number;
@@ -0,0 +1,4 @@
1
+ import css from './styles.css?inline';
2
+ /** Injects the viewer stylesheet once into a document or shadow root. */
3
+ export declare function injectStyles(target?: Document | ShadowRoot | undefined): void;
4
+ export { css as stylesText };
@@ -0,0 +1,95 @@
1
+ import type { PRunSet, SlideModel, TextBody, TPara, TRun } from '../../core/pptx/types';
2
+ import type { DocumentClient } from '../../core/worker/client';
3
+ import { RichInput, type ReplaceOpts, type RichHost } from '../edit/input';
4
+ import { type RRun, type Sel } from '../edit/rich';
5
+ type RunStyle = Omit<TRun, 'text' | 'br' | 'fld' | 'src' | 'href'>;
6
+ export interface EPara {
7
+ runs: RRun[];
8
+ base: TPara;
9
+ algn: TPara['algn'];
10
+ algnSet?: boolean;
11
+ /** paragraph changes made here (written back) */
12
+ pp?: {
13
+ lvl?: number;
14
+ bullet?: 'none' | 'bullet' | 'number';
15
+ lnPct?: number;
16
+ };
17
+ k?: number;
18
+ caret?: RRun;
19
+ }
20
+ export interface PptxFormat {
21
+ b: boolean;
22
+ i: boolean;
23
+ u: boolean;
24
+ strike: boolean;
25
+ sz?: number;
26
+ color?: string;
27
+ font?: string;
28
+ algn?: string;
29
+ hl?: string;
30
+ baseline?: number;
31
+ bullet?: 'none' | 'bullet' | 'number';
32
+ lvl: number;
33
+ lnPct?: number;
34
+ }
35
+ export declare function toTPara(p: EPara, num?: number): TPara;
36
+ /** Text editing of one shape on one slide. */
37
+ export declare class PptxEditor implements RichHost<EPara> {
38
+ private client;
39
+ readonly input: RichInput;
40
+ paras: EPara[];
41
+ body?: TextBody;
42
+ slide: number;
43
+ sid: number;
44
+ pendingSel: Sel | null;
45
+ private history;
46
+ private future;
47
+ private pend;
48
+ private timer;
49
+ private changedSinceCommit;
50
+ onChange?: () => void;
51
+ onCommitted?: (slide: number, model: SlideModel) => void;
52
+ onDirty?: () => void;
53
+ onState?: (s: PptxFormat | null) => void;
54
+ constructor(client: DocumentClient);
55
+ get active(): boolean;
56
+ begin(slide: number, sid: number, body: TextBody): void;
57
+ end(): void;
58
+ text(): TextBody | undefined;
59
+ para(pa: string): EPara;
60
+ span(a: string, b: string): string[];
61
+ prev(pa: string): string | undefined;
62
+ next(pa: string): string | undefined;
63
+ cmp(a: string, b: string): number;
64
+ withRuns(p: EPara, runs: RRun[]): EPara;
65
+ split(p: EPara, left: RRun[], right: RRun[]): [EPara, EPara];
66
+ join(a: EPara, _b: EPara, runs: RRun[]): EPara;
67
+ defaultRun(p: EPara): Partial<RRun> | undefined;
68
+ pendingStyle(): Partial<RRun> | undefined;
69
+ clearPending(): void;
70
+ replace(pas: string[], next: EPara[], sel: Sel, opts?: ReplaceOpts & {
71
+ history?: boolean;
72
+ }): void;
73
+ undo(): void;
74
+ redo(): void;
75
+ private restore;
76
+ commit(): void;
77
+ format(s: Partial<RunStyle>, d: PRunSet): void;
78
+ toggle(key: 'b' | 'i' | 'u' | 'strike'): void;
79
+ setSize(sz: number): void;
80
+ setColor(c: string | null): void;
81
+ setFont(name: string): void;
82
+ setAlign(algn: TPara['algn']): void;
83
+ /** applies a paragraph-level change to the selected paragraphs */
84
+ private paraOp;
85
+ toggleBullet(kind: 'bullet' | 'number'): void;
86
+ indentLevel(d: 1 | -1): void;
87
+ setLineSpacing(x: number): void;
88
+ setHighlight(c: string | null): void;
89
+ toggleBaseline(kind: 'sup' | 'sub'): void;
90
+ clearFormat(): void;
91
+ state(sel?: Sel | null): PptxFormat | null;
92
+ onSelection(sel: Sel | null): void;
93
+ shortcut?: (e: KeyboardEvent) => boolean;
94
+ }
95
+ export {};
@@ -0,0 +1,36 @@
1
+ import type { ShapeKind } from '../../core/pptx/types';
2
+ import { type DropOption } from '../edit/Toolbar';
3
+ import type { PptxEditor } from './PptxEditor';
4
+ export declare const SHAPES: DropOption<string>[];
5
+ export type Arrange = 'front' | 'forward' | 'backward' | 'back';
6
+ export type Rotate = 'cw' | 'ccw' | 'flipH' | 'flipV';
7
+ export type AlignTo = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';
8
+ export type SlideCmd = 'add' | 'duplicate' | 'delete' | 'up' | 'down' | 'hide';
9
+ export declare function PptxToolbar(props: {
10
+ editor: PptxEditor;
11
+ /** selected shape (not editing its text) */
12
+ shape: {
13
+ canText: boolean;
14
+ anchor?: 't' | 'ctr' | 'b';
15
+ } | null;
16
+ /** anchor of the text box being edited */
17
+ textAnchor?: 't' | 'ctr' | 'b';
18
+ canUndo: boolean;
19
+ onUndo: (redo: boolean) => void;
20
+ onInsert: (k: ShapeKind) => void;
21
+ onFill: (c: string | null) => void;
22
+ onLine: (p: {
23
+ color?: string | null;
24
+ w?: number;
25
+ dash?: string;
26
+ }) => void;
27
+ onArrange: (k: Arrange) => void;
28
+ onRotate: (k: Rotate) => void;
29
+ onAlign: (k: AlignTo) => void;
30
+ onAnchor: (a: 't' | 'ctr' | 'b') => void;
31
+ onDuplicate: () => void;
32
+ onDelete: () => void;
33
+ onBackground: (c: string | null) => void;
34
+ onSlide: (k: SlideCmd) => void;
35
+ onPresent: (fromStart: boolean) => void;
36
+ }): import("react").JSX.Element;