@productcloudos/editor 1.0.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.
- package/CHANGELOG.md +95 -0
- package/LICENSE +21 -0
- package/README.md +377 -0
- package/dist/pc-editor.esm.js +24820 -0
- package/dist/pc-editor.esm.js.map +1 -0
- package/dist/pc-editor.js +24877 -0
- package/dist/pc-editor.js.map +1 -0
- package/dist/pc-editor.min.js +2 -0
- package/dist/pc-editor.min.js.map +1 -0
- package/dist/types/lib/clipboard/ClipboardManager.d.ts +77 -0
- package/dist/types/lib/clipboard/ClipboardManager.d.ts.map +1 -0
- package/dist/types/lib/clipboard/HtmlConverter.d.ts +43 -0
- package/dist/types/lib/clipboard/HtmlConverter.d.ts.map +1 -0
- package/dist/types/lib/clipboard/index.d.ts +9 -0
- package/dist/types/lib/clipboard/index.d.ts.map +1 -0
- package/dist/types/lib/clipboard/types.d.ts +76 -0
- package/dist/types/lib/clipboard/types.d.ts.map +1 -0
- package/dist/types/lib/controls/BaseControl.d.ts +72 -0
- package/dist/types/lib/controls/BaseControl.d.ts.map +1 -0
- package/dist/types/lib/controls/index.d.ts +11 -0
- package/dist/types/lib/controls/index.d.ts.map +1 -0
- package/dist/types/lib/controls/rulers/HorizontalRuler.d.ts +55 -0
- package/dist/types/lib/controls/rulers/HorizontalRuler.d.ts.map +1 -0
- package/dist/types/lib/controls/rulers/RulerControl.d.ts +98 -0
- package/dist/types/lib/controls/rulers/RulerControl.d.ts.map +1 -0
- package/dist/types/lib/controls/rulers/VerticalRuler.d.ts +65 -0
- package/dist/types/lib/controls/rulers/VerticalRuler.d.ts.map +1 -0
- package/dist/types/lib/controls/rulers/index.d.ts +8 -0
- package/dist/types/lib/controls/rulers/index.d.ts.map +1 -0
- package/dist/types/lib/controls/rulers/types.d.ts +62 -0
- package/dist/types/lib/controls/rulers/types.d.ts.map +1 -0
- package/dist/types/lib/controls/types.d.ts +51 -0
- package/dist/types/lib/controls/types.d.ts.map +1 -0
- package/dist/types/lib/core/Document.d.ts +34 -0
- package/dist/types/lib/core/Document.d.ts.map +1 -0
- package/dist/types/lib/core/PCEditor.d.ts +761 -0
- package/dist/types/lib/core/PCEditor.d.ts.map +1 -0
- package/dist/types/lib/core/Page.d.ts +40 -0
- package/dist/types/lib/core/Page.d.ts.map +1 -0
- package/dist/types/lib/data/DataBinder.d.ts +11 -0
- package/dist/types/lib/data/DataBinder.d.ts.map +1 -0
- package/dist/types/lib/events/EventEmitter.d.ts +11 -0
- package/dist/types/lib/events/EventEmitter.d.ts.map +1 -0
- package/dist/types/lib/hit-test/HitTestManager.d.ts +81 -0
- package/dist/types/lib/hit-test/HitTestManager.d.ts.map +1 -0
- package/dist/types/lib/hit-test/index.d.ts +32 -0
- package/dist/types/lib/hit-test/index.d.ts.map +1 -0
- package/dist/types/lib/hit-test/types.d.ts +113 -0
- package/dist/types/lib/hit-test/types.d.ts.map +1 -0
- package/dist/types/lib/import/ContentAnalyzer.d.ts +76 -0
- package/dist/types/lib/import/ContentAnalyzer.d.ts.map +1 -0
- package/dist/types/lib/import/DocumentBuilder.d.ts +44 -0
- package/dist/types/lib/import/DocumentBuilder.d.ts.map +1 -0
- package/dist/types/lib/import/PDFImporter.d.ts +65 -0
- package/dist/types/lib/import/PDFImporter.d.ts.map +1 -0
- package/dist/types/lib/import/PDFParser.d.ts +46 -0
- package/dist/types/lib/import/PDFParser.d.ts.map +1 -0
- package/dist/types/lib/import/index.d.ts +9 -0
- package/dist/types/lib/import/index.d.ts.map +1 -0
- package/dist/types/lib/import/types.d.ts +182 -0
- package/dist/types/lib/import/types.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +16 -0
- package/dist/types/lib/index.d.ts.map +1 -0
- package/dist/types/lib/layout/FlowManager.d.ts +29 -0
- package/dist/types/lib/layout/FlowManager.d.ts.map +1 -0
- package/dist/types/lib/layout/LayoutEngine.d.ts +39 -0
- package/dist/types/lib/layout/LayoutEngine.d.ts.map +1 -0
- package/dist/types/lib/objects/BaseEmbeddedObject.d.ts +133 -0
- package/dist/types/lib/objects/BaseEmbeddedObject.d.ts.map +1 -0
- package/dist/types/lib/objects/EmbeddedObjectFactory.d.ts +57 -0
- package/dist/types/lib/objects/EmbeddedObjectFactory.d.ts.map +1 -0
- package/dist/types/lib/objects/ImageObject.d.ts +60 -0
- package/dist/types/lib/objects/ImageObject.d.ts.map +1 -0
- package/dist/types/lib/objects/TextBoxObject.d.ts +208 -0
- package/dist/types/lib/objects/TextBoxObject.d.ts.map +1 -0
- package/dist/types/lib/objects/index.d.ts +9 -0
- package/dist/types/lib/objects/index.d.ts.map +1 -0
- package/dist/types/lib/objects/table/TableCell.d.ts +165 -0
- package/dist/types/lib/objects/table/TableCell.d.ts.map +1 -0
- package/dist/types/lib/objects/table/TableCellMerger.d.ts +66 -0
- package/dist/types/lib/objects/table/TableCellMerger.d.ts.map +1 -0
- package/dist/types/lib/objects/table/TableObject.d.ts +434 -0
- package/dist/types/lib/objects/table/TableObject.d.ts.map +1 -0
- package/dist/types/lib/objects/table/TableResizeHandler.d.ts +80 -0
- package/dist/types/lib/objects/table/TableResizeHandler.d.ts.map +1 -0
- package/dist/types/lib/objects/table/TableRow.d.ts +65 -0
- package/dist/types/lib/objects/table/TableRow.d.ts.map +1 -0
- package/dist/types/lib/objects/table/index.d.ts +12 -0
- package/dist/types/lib/objects/table/index.d.ts.map +1 -0
- package/dist/types/lib/objects/table/types.d.ts +239 -0
- package/dist/types/lib/objects/table/types.d.ts.map +1 -0
- package/dist/types/lib/objects/types.d.ts +135 -0
- package/dist/types/lib/objects/types.d.ts.map +1 -0
- package/dist/types/lib/rendering/CanvasManager.d.ts +282 -0
- package/dist/types/lib/rendering/CanvasManager.d.ts.map +1 -0
- package/dist/types/lib/rendering/FlowingTextRenderer.d.ts +348 -0
- package/dist/types/lib/rendering/FlowingTextRenderer.d.ts.map +1 -0
- package/dist/types/lib/rendering/PDFGenerator.d.ts +103 -0
- package/dist/types/lib/rendering/PDFGenerator.d.ts.map +1 -0
- package/dist/types/lib/rendering/pdf-utils.d.ts +54 -0
- package/dist/types/lib/rendering/pdf-utils.d.ts.map +1 -0
- package/dist/types/lib/text/EditableTextRegion.d.ts +105 -0
- package/dist/types/lib/text/EditableTextRegion.d.ts.map +1 -0
- package/dist/types/lib/text/EmbeddedObjectManager.d.ts +97 -0
- package/dist/types/lib/text/EmbeddedObjectManager.d.ts.map +1 -0
- package/dist/types/lib/text/FieldFormatter.d.ts +26 -0
- package/dist/types/lib/text/FieldFormatter.d.ts.map +1 -0
- package/dist/types/lib/text/FlowingTextContent.d.ts +571 -0
- package/dist/types/lib/text/FlowingTextContent.d.ts.map +1 -0
- package/dist/types/lib/text/HyperlinkManager.d.ts +110 -0
- package/dist/types/lib/text/HyperlinkManager.d.ts.map +1 -0
- package/dist/types/lib/text/MarkdownParser.d.ts +55 -0
- package/dist/types/lib/text/MarkdownParser.d.ts.map +1 -0
- package/dist/types/lib/text/ParagraphFormatting.d.ts +123 -0
- package/dist/types/lib/text/ParagraphFormatting.d.ts.map +1 -0
- package/dist/types/lib/text/RegionManager.d.ts +75 -0
- package/dist/types/lib/text/RegionManager.d.ts.map +1 -0
- package/dist/types/lib/text/RepeatingSectionManager.d.ts +99 -0
- package/dist/types/lib/text/RepeatingSectionManager.d.ts.map +1 -0
- package/dist/types/lib/text/SubstitutionFieldManager.d.ts +153 -0
- package/dist/types/lib/text/SubstitutionFieldManager.d.ts.map +1 -0
- package/dist/types/lib/text/TextFormatting.d.ts +85 -0
- package/dist/types/lib/text/TextFormatting.d.ts.map +1 -0
- package/dist/types/lib/text/TextLayout.d.ts +126 -0
- package/dist/types/lib/text/TextLayout.d.ts.map +1 -0
- package/dist/types/lib/text/TextMeasurer.d.ts +107 -0
- package/dist/types/lib/text/TextMeasurer.d.ts.map +1 -0
- package/dist/types/lib/text/TextPositionCalculator.d.ts +72 -0
- package/dist/types/lib/text/TextPositionCalculator.d.ts.map +1 -0
- package/dist/types/lib/text/TextState.d.ts +236 -0
- package/dist/types/lib/text/TextState.d.ts.map +1 -0
- package/dist/types/lib/text/index.d.ts +27 -0
- package/dist/types/lib/text/index.d.ts.map +1 -0
- package/dist/types/lib/text/regions/BodyTextRegion.d.ts +68 -0
- package/dist/types/lib/text/regions/BodyTextRegion.d.ts.map +1 -0
- package/dist/types/lib/text/regions/FooterTextRegion.d.ts +68 -0
- package/dist/types/lib/text/regions/FooterTextRegion.d.ts.map +1 -0
- package/dist/types/lib/text/regions/HeaderTextRegion.d.ts +68 -0
- package/dist/types/lib/text/regions/HeaderTextRegion.d.ts.map +1 -0
- package/dist/types/lib/text/regions/index.d.ts +7 -0
- package/dist/types/lib/text/regions/index.d.ts.map +1 -0
- package/dist/types/lib/text/types.d.ts +268 -0
- package/dist/types/lib/text/types.d.ts.map +1 -0
- package/dist/types/lib/types/index.d.ts +206 -0
- package/dist/types/lib/types/index.d.ts.map +1 -0
- package/dist/types/lib/undo/index.d.ts +8 -0
- package/dist/types/lib/undo/index.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/ContentDiscovery.d.ts +101 -0
- package/dist/types/lib/undo/transaction/ContentDiscovery.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/FocusTracker.d.ts +49 -0
- package/dist/types/lib/undo/transaction/FocusTracker.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/MutationUndo.d.ts +57 -0
- package/dist/types/lib/undo/transaction/MutationUndo.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/ObjectMutationObserver.d.ts +79 -0
- package/dist/types/lib/undo/transaction/ObjectMutationObserver.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/TextMutationObserver.d.ts +60 -0
- package/dist/types/lib/undo/transaction/TextMutationObserver.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/TransactionManager.d.ts +148 -0
- package/dist/types/lib/undo/transaction/TransactionManager.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/index.d.ts +17 -0
- package/dist/types/lib/undo/transaction/index.d.ts.map +1 -0
- package/dist/types/lib/undo/transaction/types.d.ts +269 -0
- package/dist/types/lib/undo/transaction/types.d.ts.map +1 -0
- package/dist/types/lib/utils/blob-utils.d.ts +2 -0
- package/dist/types/lib/utils/blob-utils.d.ts.map +1 -0
- package/package.json +88 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { FlowedPage, FlowedLine, FlowedSubstitutionField, RepeatingSection, EditableTextRegion } from '../text';
|
|
2
|
+
import { Document } from '../core/Document';
|
|
3
|
+
import { Page } from '../core/Page';
|
|
4
|
+
import { Point, Rect, EditingSection } from '../types';
|
|
5
|
+
import { EventEmitter } from '../events/EventEmitter';
|
|
6
|
+
import { BaseEmbeddedObject, TableObject } from '../objects';
|
|
7
|
+
import { HitTestManager } from '../hit-test';
|
|
8
|
+
export declare class FlowingTextRenderer extends EventEmitter {
|
|
9
|
+
private document;
|
|
10
|
+
private flowedPages;
|
|
11
|
+
private headerFlowedPage;
|
|
12
|
+
private footerFlowedPage;
|
|
13
|
+
private _focusedRegion;
|
|
14
|
+
private selectedText;
|
|
15
|
+
private showControlCharacters;
|
|
16
|
+
private tableContinuations;
|
|
17
|
+
private pageTextOffsets;
|
|
18
|
+
private _hitTestManager;
|
|
19
|
+
constructor(document: Document);
|
|
20
|
+
/**
|
|
21
|
+
* Get the hit test manager for querying hit targets.
|
|
22
|
+
*/
|
|
23
|
+
get hitTestManager(): HitTestManager;
|
|
24
|
+
/**
|
|
25
|
+
* Set whether control characters are shown.
|
|
26
|
+
*/
|
|
27
|
+
setShowControlCharacters(show: boolean): void;
|
|
28
|
+
/**
|
|
29
|
+
* Find the cursor location (page, line) for a given text index in body content.
|
|
30
|
+
* Returns null if not found.
|
|
31
|
+
*/
|
|
32
|
+
private findCursorLocationInBody;
|
|
33
|
+
/**
|
|
34
|
+
* Find the cursor location (line) for a given text index in header/footer.
|
|
35
|
+
*/
|
|
36
|
+
private findCursorLocationInSection;
|
|
37
|
+
/**
|
|
38
|
+
* Calculate the cursor position for rendering.
|
|
39
|
+
* This is called on-demand during rendering instead of caching.
|
|
40
|
+
*/
|
|
41
|
+
private calculateCursorPosition;
|
|
42
|
+
/**
|
|
43
|
+
* Set the focused region.
|
|
44
|
+
* This replaces the old setActiveSection method.
|
|
45
|
+
* The region provides both the FlowingTextContent and section type.
|
|
46
|
+
*/
|
|
47
|
+
setFocusedRegion(region: EditableTextRegion | null): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get the focused region.
|
|
50
|
+
*/
|
|
51
|
+
getFocusedRegion(): EditableTextRegion | null;
|
|
52
|
+
/**
|
|
53
|
+
* Get the currently active section.
|
|
54
|
+
* Returns the section type derived from the focused region.
|
|
55
|
+
*/
|
|
56
|
+
getActiveSection(): EditingSection;
|
|
57
|
+
/**
|
|
58
|
+
* Get the FlowingTextContent for the focused region.
|
|
59
|
+
*/
|
|
60
|
+
private getActiveFlowingContent;
|
|
61
|
+
private setupFlowingContentListeners;
|
|
62
|
+
renderPageFlowingText(page: Page, ctx: CanvasRenderingContext2D, contentBounds: Rect): void;
|
|
63
|
+
/**
|
|
64
|
+
* Render header text content.
|
|
65
|
+
* @param page The page to get header bounds from
|
|
66
|
+
* @param ctx Canvas rendering context
|
|
67
|
+
* @param isActive Whether header is the active editing section
|
|
68
|
+
* @param region Optional region for unified rendering
|
|
69
|
+
* @param pageIndex The page index (for page number fields)
|
|
70
|
+
*/
|
|
71
|
+
renderHeaderText(page: Page, ctx: CanvasRenderingContext2D, isActive: boolean, region?: EditableTextRegion, pageIndex?: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* Render footer text content.
|
|
74
|
+
* @param page The page to get footer bounds from
|
|
75
|
+
* @param ctx Canvas rendering context
|
|
76
|
+
* @param isActive Whether footer is the active editing section
|
|
77
|
+
* @param region Optional region for unified rendering
|
|
78
|
+
* @param pageIndex The page index (for page number fields)
|
|
79
|
+
*/
|
|
80
|
+
renderFooterText(page: Page, ctx: CanvasRenderingContext2D, isActive: boolean, region?: EditableTextRegion, pageIndex?: number): void;
|
|
81
|
+
/**
|
|
82
|
+
* Unified click handler for any EditableTextRegion.
|
|
83
|
+
*
|
|
84
|
+
* @param region The text region that was clicked
|
|
85
|
+
* @param point Click point in canvas coordinates
|
|
86
|
+
* @param pageIndex The page index where the click occurred
|
|
87
|
+
* @param ctx Canvas context for text measurement
|
|
88
|
+
* @returns Object with textIndex and lineIndex if click was in text, or null
|
|
89
|
+
*/
|
|
90
|
+
handleRegionClick(region: EditableTextRegion, point: Point, pageIndex: number, ctx: CanvasRenderingContext2D): {
|
|
91
|
+
textIndex: number;
|
|
92
|
+
lineIndex: number;
|
|
93
|
+
} | null;
|
|
94
|
+
/**
|
|
95
|
+
* Get flowed lines for a region from the renderer's cache.
|
|
96
|
+
* This is the source of truth for flowed content.
|
|
97
|
+
*/
|
|
98
|
+
private getFlowedLinesForRegion;
|
|
99
|
+
/**
|
|
100
|
+
* Get available width for a region.
|
|
101
|
+
*/
|
|
102
|
+
private getAvailableWidthForRegion;
|
|
103
|
+
/**
|
|
104
|
+
* Unified rendering method for any EditableTextRegion.
|
|
105
|
+
* This can render body, header, footer, or text box content.
|
|
106
|
+
*
|
|
107
|
+
* @param region The text region to render
|
|
108
|
+
* @param ctx Canvas rendering context
|
|
109
|
+
* @param pageIndex The page index to render for
|
|
110
|
+
* @param options Rendering options
|
|
111
|
+
*/
|
|
112
|
+
renderRegion(region: EditableTextRegion, ctx: CanvasRenderingContext2D, pageIndex: number, options?: {
|
|
113
|
+
renderCursor?: boolean;
|
|
114
|
+
renderSelection?: boolean;
|
|
115
|
+
clipToBounds?: boolean;
|
|
116
|
+
}): void;
|
|
117
|
+
/**
|
|
118
|
+
* Render selection highlight for a region.
|
|
119
|
+
*/
|
|
120
|
+
private renderRegionSelection;
|
|
121
|
+
/**
|
|
122
|
+
* Render cursor for a region.
|
|
123
|
+
*/
|
|
124
|
+
private renderRegionCursor;
|
|
125
|
+
private flowTextForPage;
|
|
126
|
+
private renderFlowedPage;
|
|
127
|
+
/**
|
|
128
|
+
* Render relative-positioned objects at their calculated positions.
|
|
129
|
+
* These are rendered after all text so they appear on top.
|
|
130
|
+
*/
|
|
131
|
+
private renderRelativeObjects;
|
|
132
|
+
private renderFlowedLine;
|
|
133
|
+
/**
|
|
134
|
+
* Render a list marker (bullet or number) for a list item.
|
|
135
|
+
*/
|
|
136
|
+
private renderListMarker;
|
|
137
|
+
/**
|
|
138
|
+
* Render a page break indicator.
|
|
139
|
+
* When control characters are enabled: Dashed line with "Page Break" label.
|
|
140
|
+
* When control characters are disabled: Subtle single-pixel horizontal rule.
|
|
141
|
+
*/
|
|
142
|
+
private renderPageBreakIndicator;
|
|
143
|
+
/**
|
|
144
|
+
* Render a substitution field as styled text.
|
|
145
|
+
* Regular fields display as {{field: name}}.
|
|
146
|
+
* Page number fields display as the actual page number.
|
|
147
|
+
* Page count fields display as the total page count.
|
|
148
|
+
* Returns the new x position after rendering.
|
|
149
|
+
*
|
|
150
|
+
* Note: position.y is the TOP of the line, and line.baseline is the
|
|
151
|
+
* distance from the top to the text baseline.
|
|
152
|
+
*/
|
|
153
|
+
private renderSubstitutionField;
|
|
154
|
+
/**
|
|
155
|
+
* Render an embedded object.
|
|
156
|
+
* Returns the new x position after rendering.
|
|
157
|
+
*
|
|
158
|
+
* Note: position.y is the TOP of the line. Objects are vertically
|
|
159
|
+
* centered within the line height.
|
|
160
|
+
*/
|
|
161
|
+
private renderEmbeddedObject;
|
|
162
|
+
/**
|
|
163
|
+
* Render text content for table cells in a specific page slice.
|
|
164
|
+
* This handles proper positioning for cells within the slice, including
|
|
165
|
+
* header row repetition on continuation pages.
|
|
166
|
+
*/
|
|
167
|
+
private renderTableCellText;
|
|
168
|
+
/**
|
|
169
|
+
* Clear table continuation tracking.
|
|
170
|
+
* Call this when reflowing text to reset multi-page table state.
|
|
171
|
+
*/
|
|
172
|
+
clearTableContinuations(): void;
|
|
173
|
+
/**
|
|
174
|
+
* Check if there are pending table continuations for the next page.
|
|
175
|
+
*/
|
|
176
|
+
hasTableContinuations(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Get the Y offset for text content on a specific page.
|
|
179
|
+
* This accounts for table continuations that are rendered before text.
|
|
180
|
+
*/
|
|
181
|
+
getPageTextOffset(pageIndex: number): number;
|
|
182
|
+
/**
|
|
183
|
+
* Register a table slice as a hit target.
|
|
184
|
+
* Tables are registered per-slice since they can span multiple pages.
|
|
185
|
+
*/
|
|
186
|
+
private registerTableSliceHitTarget;
|
|
187
|
+
/**
|
|
188
|
+
* Update resize handle hit targets for selected objects.
|
|
189
|
+
* Call this when selection changes.
|
|
190
|
+
*/
|
|
191
|
+
updateResizeHandleTargets(selectedObjects: BaseEmbeddedObject[]): void;
|
|
192
|
+
/**
|
|
193
|
+
* Register resize handles for a regular (non-table) embedded object.
|
|
194
|
+
*/
|
|
195
|
+
private registerObjectResizeHandles;
|
|
196
|
+
/**
|
|
197
|
+
* Register resize handles for a table that may span multiple pages.
|
|
198
|
+
*/
|
|
199
|
+
private registerTableResizeHandles;
|
|
200
|
+
/**
|
|
201
|
+
* Update table divider hit targets for a focused table.
|
|
202
|
+
* Call this when table focus changes.
|
|
203
|
+
* @param table The focused table, or null to clear dividers
|
|
204
|
+
*/
|
|
205
|
+
updateTableDividerTargets(table: TableObject | null): void;
|
|
206
|
+
/**
|
|
207
|
+
* Render table continuations for a page that has no regular text flow content.
|
|
208
|
+
* This handles the case where a table spans more pages than the text flow creates.
|
|
209
|
+
*/
|
|
210
|
+
private renderTableContinuationsForPage;
|
|
211
|
+
/**
|
|
212
|
+
* Render table continuations at a specific Y position within a page.
|
|
213
|
+
* Used when there's both table continuations AND text content on the same page.
|
|
214
|
+
* Returns the total height consumed by the continuations.
|
|
215
|
+
*/
|
|
216
|
+
private renderTableContinuationsAtPosition;
|
|
217
|
+
/**
|
|
218
|
+
* Draw selection border and resize handles for an embedded object.
|
|
219
|
+
* @param sizeOverride Optional size to use instead of object.size (for sliced tables)
|
|
220
|
+
* @param slicePosition Position in multi-page sequence: 'only', 'first', 'middle', 'last'
|
|
221
|
+
* - 'only': single page, show all handles
|
|
222
|
+
* - 'first': first slice, show top + side handles
|
|
223
|
+
* - 'middle': middle slice, show side handles only
|
|
224
|
+
* - 'last': last slice, show bottom + side handles
|
|
225
|
+
*/
|
|
226
|
+
private drawEmbeddedObjectHandles;
|
|
227
|
+
/**
|
|
228
|
+
* Get the position of a resize handle.
|
|
229
|
+
*/
|
|
230
|
+
private getHandlePosition;
|
|
231
|
+
/**
|
|
232
|
+
* Convert formatting to CSS font string.
|
|
233
|
+
* Uses the same logic as TextMeasurer for consistency.
|
|
234
|
+
*/
|
|
235
|
+
private getFontString;
|
|
236
|
+
/**
|
|
237
|
+
* Calculate the X offset for a line based on its alignment.
|
|
238
|
+
*/
|
|
239
|
+
private getAlignmentOffset;
|
|
240
|
+
/**
|
|
241
|
+
* Check if the cursor is positioned right after a substitution field or embedded object.
|
|
242
|
+
* This is used to hide the cursor when a field/object is "selected".
|
|
243
|
+
*/
|
|
244
|
+
private isCursorAfterFieldOrObject;
|
|
245
|
+
private renderCursor;
|
|
246
|
+
private renderTextSelection;
|
|
247
|
+
private lineContainsSelection;
|
|
248
|
+
private getSelectionBoundsInLine;
|
|
249
|
+
/**
|
|
250
|
+
* Get the text index at a given point without moving the cursor.
|
|
251
|
+
* Returns null if the point is not within text content.
|
|
252
|
+
*/
|
|
253
|
+
getTextIndexAtPoint(point: Point, pageId: string): number | null;
|
|
254
|
+
private getTextIndexInLine;
|
|
255
|
+
private getInlineElementAtPoint;
|
|
256
|
+
/**
|
|
257
|
+
* Get an embedded object at a specific point in a line.
|
|
258
|
+
* Note: lineY is the TOP of the line (same as position.y in render methods).
|
|
259
|
+
* lineStartX is the content area's left edge (includes margin offset).
|
|
260
|
+
*/
|
|
261
|
+
getEmbeddedObjectAtPoint(line: FlowedLine, point: Point, lineY: number, lineStartX: number): BaseEmbeddedObject | null;
|
|
262
|
+
/**
|
|
263
|
+
* Get a substitution field at a specific point in a line.
|
|
264
|
+
* Note: lineY is the TOP of the line (same as position.y in render methods).
|
|
265
|
+
*/
|
|
266
|
+
getSubstitutionFieldAtPoint(line: FlowedLine, point: Point, lineY: number, lineStartX: number): FlowedSubstitutionField | null;
|
|
267
|
+
private getXPositionForTextIndex;
|
|
268
|
+
/**
|
|
269
|
+
* Count word gaps up to a certain text index for justify spacing calculation.
|
|
270
|
+
*/
|
|
271
|
+
private countWordGapsUpTo;
|
|
272
|
+
/**
|
|
273
|
+
* Move cursor vertically by visual lines, maintaining X position.
|
|
274
|
+
* Returns the new text index. At document boundaries, moves to start/end of text.
|
|
275
|
+
*/
|
|
276
|
+
moveCursorVertical(direction: -1 | 1, pageId: string): number | null;
|
|
277
|
+
/**
|
|
278
|
+
* Move cursor vertically within a single-page section (header/footer).
|
|
279
|
+
*/
|
|
280
|
+
private moveCursorVerticalInSection;
|
|
281
|
+
/**
|
|
282
|
+
* Calculate the cursor's X position relative to the section area (on-demand).
|
|
283
|
+
*/
|
|
284
|
+
private calculateCursorRelativeXForSection;
|
|
285
|
+
/**
|
|
286
|
+
* Calculate the cursor's X position relative to the content area (on-demand).
|
|
287
|
+
*/
|
|
288
|
+
private calculateCursorRelativeX;
|
|
289
|
+
/**
|
|
290
|
+
* Get the text index at a given visual X position on a line.
|
|
291
|
+
* The visualX is relative to the content area start (includes alignment offset).
|
|
292
|
+
* We subtract the target line's alignment offset to get X relative to text start.
|
|
293
|
+
*/
|
|
294
|
+
private getTextIndexAtVisualX;
|
|
295
|
+
setTextSelection(start: number, end: number): void;
|
|
296
|
+
clearTextSelection(): void;
|
|
297
|
+
getFlowedPagesForPage(pageId: string): FlowedPage[];
|
|
298
|
+
/**
|
|
299
|
+
* Get a complete snapshot of all flowed content for PDF export.
|
|
300
|
+
* Returns body pages, header, and footer content.
|
|
301
|
+
*/
|
|
302
|
+
getFlowedPagesSnapshot(): {
|
|
303
|
+
body: FlowedPage[];
|
|
304
|
+
header: FlowedPage | null;
|
|
305
|
+
footer: FlowedPage | null;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Render repeating section indicators for a page.
|
|
309
|
+
* @param sections All repeating sections
|
|
310
|
+
* @param pageIndex Current page index
|
|
311
|
+
* @param ctx Canvas rendering context
|
|
312
|
+
* @param contentBounds Content area bounds
|
|
313
|
+
* @param flowedPage The flowed page content
|
|
314
|
+
* @param pageBounds Full page bounds (including margins)
|
|
315
|
+
* @param selectedSectionId ID of the currently selected section (for visual feedback)
|
|
316
|
+
*/
|
|
317
|
+
renderRepeatingSectionIndicators(sections: RepeatingSection[], pageIndex: number, ctx: CanvasRenderingContext2D, contentBounds: Rect, flowedPage: FlowedPage, pageBounds: Rect, selectedSectionId?: string | null): void;
|
|
318
|
+
/**
|
|
319
|
+
* Render a single repeating section indicator.
|
|
320
|
+
*/
|
|
321
|
+
private renderSectionIndicator;
|
|
322
|
+
/**
|
|
323
|
+
* Draw the "Loop" label in a rounded rectangle.
|
|
324
|
+
* When not selected, draws an outlined rectangle.
|
|
325
|
+
* When selected, draws a filled rectangle.
|
|
326
|
+
*/
|
|
327
|
+
private drawLoopLabel;
|
|
328
|
+
/**
|
|
329
|
+
* Draw a rounded rectangle path.
|
|
330
|
+
*/
|
|
331
|
+
private roundRect;
|
|
332
|
+
/**
|
|
333
|
+
* Find the Y position for a text index on a flowed page.
|
|
334
|
+
* Returns the Y position at the TOP of the line containing the text index.
|
|
335
|
+
*/
|
|
336
|
+
private findLineYForTextIndex;
|
|
337
|
+
/**
|
|
338
|
+
* Check if a section spans across a flowed page (starts before and ends after).
|
|
339
|
+
*/
|
|
340
|
+
private sectionSpansPage;
|
|
341
|
+
/**
|
|
342
|
+
* Get a repeating section at a point (for click detection).
|
|
343
|
+
* Checks if the point is on the Loop label or vertical connector.
|
|
344
|
+
*/
|
|
345
|
+
getRepeatingSectionAtPoint(point: Point, sections: RepeatingSection[], _pageIndex: number, pageBounds: Rect, contentBounds: Rect, flowedPage: FlowedPage): RepeatingSection | null;
|
|
346
|
+
destroy(): void;
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=FlowingTextRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowingTextRenderer.d.ts","sourceRoot":"","sources":["../../../../src/lib/rendering/FlowingTextRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,EAEV,uBAAuB,EAEvB,gBAAgB,EAGhB,kBAAkB,EAInB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAiB,WAAW,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AA8B3D,qBAAa,mBAAoB,SAAQ,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,gBAAgB,CAA2B;IACnD,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,YAAY,CAA+C;IACnE,OAAO,CAAC,qBAAqB,CAAkB;IAE/C,OAAO,CAAC,kBAAkB,CAA6C;IAEvE,OAAO,CAAC,eAAe,CAAkC;IAEzD,OAAO,CAAC,eAAe,CAAwC;gBAEnD,QAAQ,EAAE,QAAQ;IAM9B;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,CAEnC;IAED;;OAEG;IACH,wBAAwB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI;IAQ7C;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAwChC;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAuBnC;;;OAGG;IACH,OAA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IACH,gCAAgC,CAC9B,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,wBAAwB,EAC7B,aAAa,EAAE,IAAI,EACnB,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,IAAI,EAChB,iBAAiB,GAAE,MAAM,GAAG,IAAW,GACtC,IAAI;IAcP;;OAEG;IACH,OAAO,CAAC,sBAAsB;IA+J9B;;;;OAIG;IACH,OAAO,CAAC,aAAa;IA0CrB;;OAEG;IACH,OAAO,CAAC,SAAS;IAoBjB;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAmC7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAUxB;;;OAGG;IACH,0BAA0B,CACxB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,IAAI,EAChB,aAAa,EAAE,IAAI,EACnB,UAAU,EAAE,UAAU,GACrB,gBAAgB,GAAG,IAAI;IA4D1B,OAAO,IAAI,IAAI;CAGhB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDFGenerator - Generates PDF documents from editor content.
|
|
3
|
+
*
|
|
4
|
+
* Renders content identically to canvas but excludes UI elements like:
|
|
5
|
+
* - Cursor, selection highlight, control characters
|
|
6
|
+
* - Grid lines, margin indicators, resize handles
|
|
7
|
+
* - Repeating section indicators, loop markers
|
|
8
|
+
*/
|
|
9
|
+
import { Document } from '../core/Document';
|
|
10
|
+
import { PDFExportOptions } from '../types';
|
|
11
|
+
import { FlowedPage } from '../text/types';
|
|
12
|
+
/**
|
|
13
|
+
* Snapshot of flowed content for PDF generation.
|
|
14
|
+
*/
|
|
15
|
+
export interface FlowedContentSnapshot {
|
|
16
|
+
body: FlowedPage[];
|
|
17
|
+
header: FlowedPage | null;
|
|
18
|
+
footer: FlowedPage | null;
|
|
19
|
+
}
|
|
20
|
+
export declare class PDFGenerator {
|
|
21
|
+
private fontCache;
|
|
22
|
+
/**
|
|
23
|
+
* Generate a PDF from the document.
|
|
24
|
+
*
|
|
25
|
+
* @param document The document to export
|
|
26
|
+
* @param flowedContent Snapshot of flowed text content
|
|
27
|
+
* @param options Export options
|
|
28
|
+
*/
|
|
29
|
+
generate(document: Document, flowedContent?: FlowedContentSnapshot, _options?: PDFExportOptions): Promise<Blob>;
|
|
30
|
+
/**
|
|
31
|
+
* Embed standard PDF fonts for all variants we might need.
|
|
32
|
+
*/
|
|
33
|
+
private embedStandardFonts;
|
|
34
|
+
/**
|
|
35
|
+
* Filter text to only include WinAnsi-compatible characters.
|
|
36
|
+
* Standard PDF fonts (Helvetica, Times, Courier) only support WinAnsi encoding.
|
|
37
|
+
* This replaces unsupported characters with a placeholder or removes them.
|
|
38
|
+
*/
|
|
39
|
+
private filterToWinAnsi;
|
|
40
|
+
/**
|
|
41
|
+
* Get a font from cache by formatting style.
|
|
42
|
+
*/
|
|
43
|
+
private getFont;
|
|
44
|
+
/**
|
|
45
|
+
* Render a flowed page to PDF.
|
|
46
|
+
*/
|
|
47
|
+
private renderFlowedPage;
|
|
48
|
+
/**
|
|
49
|
+
* Calculate alignment offset for a line.
|
|
50
|
+
*/
|
|
51
|
+
private getAlignmentOffset;
|
|
52
|
+
/**
|
|
53
|
+
* Render a substitution field (page number, data field value).
|
|
54
|
+
*/
|
|
55
|
+
private renderSubstitutionField;
|
|
56
|
+
/**
|
|
57
|
+
* Render an embedded object (image, text box, or table).
|
|
58
|
+
*/
|
|
59
|
+
private renderEmbeddedObject;
|
|
60
|
+
/**
|
|
61
|
+
* Render relative-positioned objects at their calculated positions.
|
|
62
|
+
* Called after all lines are rendered so objects appear on top.
|
|
63
|
+
*/
|
|
64
|
+
private renderRelativeObjects;
|
|
65
|
+
/**
|
|
66
|
+
* Render an image to PDF.
|
|
67
|
+
*/
|
|
68
|
+
private renderImage;
|
|
69
|
+
/**
|
|
70
|
+
* Embed an image from a data URL into the PDF document.
|
|
71
|
+
*/
|
|
72
|
+
private embedImageFromDataUrl;
|
|
73
|
+
/**
|
|
74
|
+
* Calculate image drawing parameters based on fit mode.
|
|
75
|
+
*/
|
|
76
|
+
private calculateImageDrawParams;
|
|
77
|
+
/**
|
|
78
|
+
* Draw a tiled image pattern to fill the box.
|
|
79
|
+
*/
|
|
80
|
+
private drawTiledImage;
|
|
81
|
+
/**
|
|
82
|
+
* Render a text box to PDF.
|
|
83
|
+
*/
|
|
84
|
+
private renderTextBox;
|
|
85
|
+
/**
|
|
86
|
+
* Render a table to PDF.
|
|
87
|
+
* Handles multi-page tables by checking rendered slice info.
|
|
88
|
+
*/
|
|
89
|
+
private renderTable;
|
|
90
|
+
/**
|
|
91
|
+
* Get the rows to render for a specific table slice.
|
|
92
|
+
* Handles header row repetition on continuation pages.
|
|
93
|
+
*
|
|
94
|
+
* Uses sliceIndex to look at all rendered pages and determine
|
|
95
|
+
* which data rows belong to this slice.
|
|
96
|
+
*/
|
|
97
|
+
private getTableRowsForSlice;
|
|
98
|
+
/**
|
|
99
|
+
* Render cell borders.
|
|
100
|
+
*/
|
|
101
|
+
private renderCellBorders;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=PDFGenerator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PDFGenerator.d.ts","sourceRoot":"","sources":["../../../../src/lib/rendering/PDFGenerator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAmC,MAAM,eAAe,CAAC;AAa5E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;CAC3B;AAOD,qBAAa,YAAY;IACvB,OAAO,CAAC,SAAS,CAAwB;IAEzC;;;;;;OAMG;IACG,QAAQ,CACZ,QAAQ,EAAE,QAAQ,EAClB,aAAa,CAAC,EAAE,qBAAqB,EACrC,QAAQ,CAAC,EAAE,gBAAgB,GAC1B,OAAO,CAAC,IAAI,CAAC;IA2FhB;;OAEG;YACW,kBAAkB;IAuBhC;;;;OAIG;IACH,OAAO,CAAC,eAAe;IA+BvB;;OAEG;IACH,OAAO,CAAC,OAAO;IASf;;OAEG;YACW,gBAAgB;IA4I9B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAmD/B;;OAEG;YACW,oBAAoB;IAkBlC;;;OAGG;YACW,qBAAqB;IAwBnC;;OAEG;YACW,WAAW;IA0DzB;;OAEG;YACW,qBAAqB;IA0BnC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAoDhC;;OAEG;IACH,OAAO,CAAC,cAAc;IAmCtB;;OAEG;YACW,aAAa;IAuE3B;;;OAGG;YACW,WAAW;IAuIzB;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAyE5B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CA+B1B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PDF utility functions for coordinate transformation and font mapping.
|
|
3
|
+
*/
|
|
4
|
+
import { StandardFonts, PDFFont, PDFPage, Color } from 'pdf-lib';
|
|
5
|
+
/**
|
|
6
|
+
* PDF uses bottom-left origin, canvas uses top-left.
|
|
7
|
+
* Transform Y coordinate from canvas space to PDF space.
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformY(y: number, pageHeight: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Transform a rectangle from canvas coordinates to PDF coordinates.
|
|
12
|
+
* Canvas: (x, y) is top-left corner
|
|
13
|
+
* PDF: (x, y) is bottom-left corner
|
|
14
|
+
*/
|
|
15
|
+
export declare function transformRect(x: number, y: number, width: number, height: number, pageHeight: number): {
|
|
16
|
+
x: number;
|
|
17
|
+
y: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Font weight/style variants for PDF standard fonts.
|
|
23
|
+
*/
|
|
24
|
+
export type FontVariant = 'normal' | 'bold' | 'italic' | 'boldItalic';
|
|
25
|
+
/**
|
|
26
|
+
* Get the StandardFonts enum value for a given font family and style.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getStandardFont(fontFamily: string, fontWeight?: string, fontStyle?: string): StandardFonts;
|
|
29
|
+
/**
|
|
30
|
+
* Create a unique font key for caching embedded fonts.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getFontKey(fontFamily: string, fontWeight?: string, fontStyle?: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Parse a CSS color string to pdf-lib Color.
|
|
35
|
+
* Supports hex (#RGB, #RRGGBB), rgb(), rgba(), and named colors.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseColor(cssColor: string): Color;
|
|
38
|
+
/**
|
|
39
|
+
* Draw text on a PDF page with proper positioning and formatting.
|
|
40
|
+
*/
|
|
41
|
+
export declare function drawText(page: PDFPage, text: string, x: number, y: number, font: PDFFont, fontSize: number, color: Color, pageHeight: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Draw a filled rectangle on a PDF page.
|
|
44
|
+
*/
|
|
45
|
+
export declare function drawFilledRect(page: PDFPage, x: number, y: number, width: number, height: number, color: Color, pageHeight: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Draw a stroked rectangle on a PDF page.
|
|
48
|
+
*/
|
|
49
|
+
export declare function drawStrokedRect(page: PDFPage, x: number, y: number, width: number, height: number, borderColor: Color, borderWidth: number, pageHeight: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Draw a line on a PDF page.
|
|
52
|
+
*/
|
|
53
|
+
export declare function drawLine(page: PDFPage, x1: number, y1: number, x2: number, y2: number, color: Color, thickness: number, pageHeight: number): void;
|
|
54
|
+
//# sourceMappingURL=pdf-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/rendering/pdf-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAEtE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAOzD;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,YAAY,CAAC;AAwEtE;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,aAAa,CAsBf;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9F;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK,CA+DlD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,MAAM,EACZ,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,GACjB,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,OAAO,EACb,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,GACjB,IAAI,CASN;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,OAAO,EACb,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,KAAK,EAClB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,IAAI,CAUN;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,IAAI,CAON"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Point, Rect } from '../types';
|
|
2
|
+
import { FlowedLine, FlowedPage } from './types';
|
|
3
|
+
import { FlowingTextContent } from './FlowingTextContent';
|
|
4
|
+
/**
|
|
5
|
+
* Types of editable text regions in the document.
|
|
6
|
+
*/
|
|
7
|
+
export type RegionType = 'body' | 'header' | 'footer' | 'textbox' | 'tablecell';
|
|
8
|
+
/**
|
|
9
|
+
* Interface for editable text regions.
|
|
10
|
+
* This abstraction unifies body, header, footer, and text box contexts
|
|
11
|
+
* so that interaction logic (click handling, cursor positioning, selection)
|
|
12
|
+
* can be shared across all of them.
|
|
13
|
+
*/
|
|
14
|
+
export interface EditableTextRegion {
|
|
15
|
+
/**
|
|
16
|
+
* Unique identifier for this region.
|
|
17
|
+
* For body/header/footer this is a fixed string.
|
|
18
|
+
* For text boxes this is the text box ID.
|
|
19
|
+
*/
|
|
20
|
+
readonly id: string;
|
|
21
|
+
/**
|
|
22
|
+
* The type of region.
|
|
23
|
+
*/
|
|
24
|
+
readonly type: RegionType;
|
|
25
|
+
/**
|
|
26
|
+
* The underlying FlowingTextContent that manages text state.
|
|
27
|
+
*/
|
|
28
|
+
readonly flowingContent: FlowingTextContent;
|
|
29
|
+
/**
|
|
30
|
+
* Get the bounds of this region on a specific page.
|
|
31
|
+
* @param pageIndex The page index (0-based)
|
|
32
|
+
* @returns The bounds in canvas coordinates, or null if not visible on this page
|
|
33
|
+
*/
|
|
34
|
+
getRegionBounds(pageIndex: number): Rect | null;
|
|
35
|
+
/**
|
|
36
|
+
* Convert a point from global (canvas) coordinates to local (region) coordinates.
|
|
37
|
+
* @param point Point in canvas coordinates
|
|
38
|
+
* @param pageIndex The page index
|
|
39
|
+
* @returns Point in region-local coordinates, or null if point is outside this region
|
|
40
|
+
*/
|
|
41
|
+
globalToLocal(point: Point, pageIndex: number): Point | null;
|
|
42
|
+
/**
|
|
43
|
+
* Convert a point from local (region) coordinates to global (canvas) coordinates.
|
|
44
|
+
* @param point Point in region-local coordinates
|
|
45
|
+
* @param pageIndex The page index
|
|
46
|
+
* @returns Point in canvas coordinates
|
|
47
|
+
*/
|
|
48
|
+
localToGlobal(point: Point, pageIndex: number): Point;
|
|
49
|
+
/**
|
|
50
|
+
* Get the flowed lines for this region on a specific page.
|
|
51
|
+
* @param pageIndex The page index
|
|
52
|
+
* @returns Array of flowed lines for this page
|
|
53
|
+
*/
|
|
54
|
+
getFlowedLines(pageIndex: number): FlowedLine[];
|
|
55
|
+
/**
|
|
56
|
+
* Get all flowed pages for this region.
|
|
57
|
+
* @returns Array of flowed pages
|
|
58
|
+
*/
|
|
59
|
+
getFlowedPages(): FlowedPage[];
|
|
60
|
+
/**
|
|
61
|
+
* Get the available width for text in this region.
|
|
62
|
+
* This is used for alignment calculations.
|
|
63
|
+
*/
|
|
64
|
+
getAvailableWidth(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Whether this region spans multiple pages.
|
|
67
|
+
* Body text can span pages; header/footer/textbox cannot.
|
|
68
|
+
*/
|
|
69
|
+
spansMultiplePages(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Get the number of pages this region spans.
|
|
72
|
+
* For single-page regions, returns 1.
|
|
73
|
+
*/
|
|
74
|
+
getPageCount(): number;
|
|
75
|
+
/**
|
|
76
|
+
* Check if a point is within this region.
|
|
77
|
+
* @param point Point in canvas coordinates
|
|
78
|
+
* @param pageIndex The page index
|
|
79
|
+
*/
|
|
80
|
+
containsPointInRegion(point: Point, pageIndex: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Trigger a reflow of text in this region.
|
|
83
|
+
* @param ctx Canvas context for text measurement
|
|
84
|
+
*/
|
|
85
|
+
reflow(ctx: CanvasRenderingContext2D): void;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Abstract base class providing common functionality for regions.
|
|
89
|
+
*/
|
|
90
|
+
export declare abstract class BaseTextRegion implements EditableTextRegion {
|
|
91
|
+
abstract readonly id: string;
|
|
92
|
+
abstract readonly type: RegionType;
|
|
93
|
+
abstract readonly flowingContent: FlowingTextContent;
|
|
94
|
+
abstract getRegionBounds(pageIndex: number): Rect | null;
|
|
95
|
+
abstract getFlowedLines(pageIndex: number): FlowedLine[];
|
|
96
|
+
abstract getFlowedPages(): FlowedPage[];
|
|
97
|
+
abstract getAvailableWidth(): number;
|
|
98
|
+
abstract spansMultiplePages(): boolean;
|
|
99
|
+
abstract reflow(ctx: CanvasRenderingContext2D): void;
|
|
100
|
+
globalToLocal(point: Point, pageIndex: number): Point | null;
|
|
101
|
+
localToGlobal(point: Point, pageIndex: number): Point;
|
|
102
|
+
getPageCount(): number;
|
|
103
|
+
containsPointInRegion(point: Point, pageIndex: number): boolean;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=EditableTextRegion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditableTextRegion.d.ts","sourceRoot":"","sources":["../../../../src/lib/text/EditableTextRegion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,kBAAkB,CAAC;IAE5C;;;;OAIG;IACH,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAEhD;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI,CAAC;IAE7D;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAAC;IAEtD;;;;OAIG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,EAAE,CAAC;IAEhD;;;OAGG;IACH,cAAc,IAAI,UAAU,EAAE,CAAC;IAE/B;;;OAGG;IACH,iBAAiB,IAAI,MAAM,CAAC;IAE5B;;;OAGG;IACH,kBAAkB,IAAI,OAAO,CAAC;IAE9B;;;OAGG;IACH,YA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