documentation-hub 5.7.2
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/.eslintrc.json +43 -0
- package/.github/workflows/build.yml +64 -0
- package/.github/workflows/ci.yml +39 -0
- package/.vscode/extensions.json +3 -0
- package/Current.md +97 -0
- package/DocHub_Image.png +0 -0
- package/README.md +666 -0
- package/USER_GUIDE.md +1173 -0
- package/Updater.md +311 -0
- package/build/256x256.png +0 -0
- package/build/512x512.png +0 -0
- package/build/app-update.yml +4 -0
- package/build/create-icon.js +208 -0
- package/build/icon.ico +0 -0
- package/build/icon.png +0 -0
- package/build/icon_1024x1024.png +0 -0
- package/dist/assets/Analytics-BpsG9895.js +1 -0
- package/dist/assets/Card-IAZin8kp.js +1 -0
- package/dist/assets/CurrentSession-B-rFkHvf.js +12 -0
- package/dist/assets/Dashboard-C_5gMb0q.js +1 -0
- package/dist/assets/Documents-CqZ25axS.js +1 -0
- package/dist/assets/Input-l89xwXBi.js +1 -0
- package/dist/assets/Reporting-DqdHJY_a.js +1 -0
- package/dist/assets/Search-XNbu5z_3.js +1 -0
- package/dist/assets/SessionManager-lH9hZfzH.js +1 -0
- package/dist/assets/Sessions-ClZOPYNc.js +1 -0
- package/dist/assets/Settings-DUEHGURa.js +11 -0
- package/dist/assets/index-8xUe8ptc.js +24 -0
- package/dist/assets/index-RYyJqF7O.css +1 -0
- package/dist/assets/path-BkOl0AGO.js +1 -0
- package/dist/assets/promises-ID_B9S-h.js +1 -0
- package/dist/assets/urlHelpers-TvgahX0r.js +1 -0
- package/dist/assets/useToast-yRSO1dkm.js +1 -0
- package/dist/assets/vendor-charts-RkGK5ROP.js +36 -0
- package/dist/assets/vendor-db-l0sNRNKZ.js +1 -0
- package/dist/assets/vendor-react-BVZ_anCF.js +4 -0
- package/dist/assets/vendor-search-Dw8P0qyA.js +1 -0
- package/dist/assets/vendor-ui-BU7NfluV.js +53 -0
- package/dist/electron/PowerAutomateApiService-LfW09ZGr.js +147 -0
- package/dist/electron/main-CXkNtyv-.js +19789 -0
- package/dist/electron/main.js +5 -0
- package/dist/electron/preload.js +1 -0
- package/dist/icon.png +0 -0
- package/dist/index.html +27 -0
- package/docs/CODEBASE_ANALYSIS_REPORT.md +309 -0
- package/docs/DEBUG_LOGGING_GUIDE.md +244 -0
- package/docs/README.md +115 -0
- package/docs/TOC_WIRING_GUIDE.md +344 -0
- package/docs/analysis/Bullet_Symbol_Bug_Analysis.md +136 -0
- package/docs/analysis/DOCXMLATER_ANALYSIS_SUMMARY.txt +169 -0
- package/docs/analysis/Document_Processing_Issues_Analysis.md +704 -0
- package/docs/analysis/FIELD_PRESERVATION_ANALYSIS.md +1200 -0
- package/docs/analysis/INDENTATION_PRESERVE_ANALYSIS.md +181 -0
- package/docs/analysis/INDENTATION_PRESERVE_IMPLEMENTATION.md +207 -0
- package/docs/analysis/List_Implementation.md +206 -0
- package/docs/analysis/List_Implementation_Accuracy_Report.md +366 -0
- package/docs/analysis/PROCESSING_OPTIONS_UI_UPDATES.md +220 -0
- package/docs/analysis/RefactorStyles.md +852 -0
- package/docs/analysis/STYLE_PARAMETER_ENHANCEMENT.md +143 -0
- package/docs/analysis/docxmlater-comparison-todo-2025-11-13.md +636 -0
- package/docs/analysis/docxmlater-implementation-analysis-2025-11-13.md +340 -0
- package/docs/analysis/docxmlater-template_ui-integration-analysis.md +263 -0
- package/docs/analysis/github-issues-to-create.md +237 -0
- package/docs/api/API_README.md +538 -0
- package/docs/api/API_REFERENCE.md +751 -0
- package/docs/api/TYPE_DEFINITIONS.md +869 -0
- package/docs/architecture/FONT_EMBEDDING_GUIDE.md +318 -0
- package/docs/architecture/docxmlater-functions-and-structure.md +726 -0
- package/docs/docxmlater-readme.md +1341 -0
- package/docs/fixes/EXECUTION_LOG_TEST_BASE.md +573 -0
- package/docs/fixes/HYPERLINK_TEXT_SANITIZATION.md +253 -0
- package/docs/fixes/README.md +37 -0
- package/docs/github-issues/issue-1-body.md +125 -0
- package/docs/github-issues/issue-10-body.md +850 -0
- package/docs/github-issues/issue-2-body.md +200 -0
- package/docs/github-issues/issue-3-body.md +270 -0
- package/docs/github-issues/issue-4-body.md +169 -0
- package/docs/github-issues/issue-5-body.md +173 -0
- package/docs/github-issues/issue-6-body.md +158 -0
- package/docs/github-issues/issue-7-body.md +171 -0
- package/docs/github-issues/issue-8-body.md +407 -0
- package/docs/github-issues/issue-9-body.md +515 -0
- package/docs/github-issues/issue-tracker.md +274 -0
- package/docs/github-issues/predictive-analysis-2025-10-18.md +2131 -0
- package/docs/implementation/List_Framework_Refactor_Plan.md +336 -0
- package/docs/implementation/PRIMARY_TEXT_COLOR_FEATURE.md +217 -0
- package/docs/implementation/RELEASE_PLAN_v2.1.0.md +362 -0
- package/docs/implementation/RefactorStyles.md +588 -0
- package/docs/implementation/implement-plan.md +489 -0
- package/docs/implementation/missing-helpers-implementation.md +391 -0
- package/docs/implementation/refactor-plan.md +520 -0
- package/docs/implementation/session-implementation-complete.md +233 -0
- package/docs/implementation/session-management-plan.md +250 -0
- package/docs/setup-checklist.md +77 -0
- package/docs/versions/changelog.md +345 -0
- package/electron/customUpdater.ts +656 -0
- package/electron/main.ts +2441 -0
- package/electron/memoryConfig.ts +187 -0
- package/electron/preload.ts +394 -0
- package/electron/proxyConfig.ts +340 -0
- package/electron/services/BackupService.ts +452 -0
- package/electron/services/DictionaryService.ts +402 -0
- package/electron/services/LocalDictionaryLookupService.ts +147 -0
- package/electron/services/PowerAutomateApiService.ts +231 -0
- package/electron/services/SharePointSyncService.ts +474 -0
- package/electron/windowsCertStore.ts +427 -0
- package/electron/zscalerConfig.ts +381 -0
- package/eslint.config.js +92 -0
- package/jest.config.js +52 -0
- package/package.json +214 -0
- package/postcss.config.mjs +6 -0
- package/public/icon.png +0 -0
- package/publish-release.ps1 +5 -0
- package/renovate.json +30 -0
- package/src/App.tsx +216 -0
- package/src/__mocks__/p-limit.js +12 -0
- package/src/__mocks__/styleMock.js +1 -0
- package/src/components/common/BugReportButton.tsx +44 -0
- package/src/components/common/BugReportDialog.tsx +193 -0
- package/src/components/common/Button.tsx +153 -0
- package/src/components/common/Card.tsx +86 -0
- package/src/components/common/ColorPickerDialog.tsx +177 -0
- package/src/components/common/ConfirmDialog.tsx +96 -0
- package/src/components/common/DebugConsole.tsx +275 -0
- package/src/components/common/EmptyState.tsx +183 -0
- package/src/components/common/ErrorBoundary.tsx +98 -0
- package/src/components/common/ErrorDetailsDialog.tsx +153 -0
- package/src/components/common/ErrorFallback.tsx +218 -0
- package/src/components/common/Input.tsx +109 -0
- package/src/components/common/Skeleton.tsx +184 -0
- package/src/components/common/SplashScreen.tsx +81 -0
- package/src/components/common/Toast.tsx +155 -0
- package/src/components/common/Tooltip.tsx +79 -0
- package/src/components/common/UpdateNotification.tsx +320 -0
- package/src/components/comparison/ComparisonWindow.tsx +374 -0
- package/src/components/comparison/SideBySideDiff.tsx +486 -0
- package/src/components/comparison/index.ts +8 -0
- package/src/components/document/DocumentUploader.tsx +288 -0
- package/src/components/document/HyperlinkPreview.tsx +430 -0
- package/src/components/document/HyperlinkService.md +1484 -0
- package/src/components/document/Hyperlink_Technical_Documentation.md +496 -0
- package/src/components/document/InlineChangesView.tsx +707 -0
- package/src/components/document/ProcessingProgress.tsx +303 -0
- package/src/components/document/ProcessingResults.tsx +256 -0
- package/src/components/document/TrackedChangesDetail.tsx +530 -0
- package/src/components/document/TrackedChangesPanel.tsx +546 -0
- package/src/components/document/VirtualDocumentList.tsx +240 -0
- package/src/components/editor/DocumentEditor.tsx +723 -0
- package/src/components/editor/DocumentEditorModal.tsx +640 -0
- package/src/components/editor/EditorQuickActions.tsx +502 -0
- package/src/components/editor/EditorToolbar.tsx +312 -0
- package/src/components/editor/TableEditor.tsx +926 -0
- package/src/components/editor/index.ts +18 -0
- package/src/components/layout/Header.tsx +190 -0
- package/src/components/layout/Sidebar.tsx +313 -0
- package/src/components/layout/TitleBar.tsx +190 -0
- package/src/components/navigation/CommandPalette.tsx +233 -0
- package/src/components/navigation/KeyboardShortcutsModal.tsx +173 -0
- package/src/components/sessions/ChangeItem.tsx +408 -0
- package/src/components/sessions/ChangeViewer.tsx +1155 -0
- package/src/components/sessions/DocumentComparisonModal.tsx +314 -0
- package/src/components/sessions/ProcessingOptions.tsx +297 -0
- package/src/components/sessions/ReplacementsTab.tsx +438 -0
- package/src/components/sessions/RevisionHandlingOptions.tsx +87 -0
- package/src/components/sessions/SessionManager.tsx +188 -0
- package/src/components/sessions/StylesEditor.tsx +1335 -0
- package/src/components/sessions/TabContainer.tsx +151 -0
- package/src/components/sessions/VirtualSessionList.tsx +157 -0
- package/src/components/sessions/sessionToProcessorManager.tsx +420 -0
- package/src/components/settings/CertificateManager.tsx +410 -0
- package/src/components/settings/SegmentedControl.tsx +88 -0
- package/src/components/settings/SettingRow.tsx +52 -0
- package/src/contexts/GlobalStatsContext.tsx +396 -0
- package/src/contexts/SessionContext.tsx +2129 -0
- package/src/contexts/ThemeContext.tsx +428 -0
- package/src/contexts/UserSettingsContext.tsx +290 -0
- package/src/contexts/__tests__/GlobalStatsContext.test.tsx +390 -0
- package/src/global.d.ts +273 -0
- package/src/hooks/useDocumentQueue.tsx +210 -0
- package/src/hooks/useToast.tsx +55 -0
- package/src/main.tsx +10 -0
- package/src/pages/Analytics.tsx +386 -0
- package/src/pages/CurrentSession.tsx +1174 -0
- package/src/pages/Dashboard.tsx +319 -0
- package/src/pages/Documents.tsx +317 -0
- package/src/pages/Projects.tsx +250 -0
- package/src/pages/Reporting.tsx +386 -0
- package/src/pages/Search.tsx +349 -0
- package/src/pages/Sessions.tsx +285 -0
- package/src/pages/Settings.tsx +2662 -0
- package/src/services/HyperlinkService.ts +1085 -0
- package/src/services/document/DocXMLaterProcessor.ts +617 -0
- package/src/services/document/DocumentProcessingComparison.ts +856 -0
- package/src/services/document/DocumentSnapshotService.ts +575 -0
- package/src/services/document/WordDocumentProcessor.ts +10509 -0
- package/src/services/document/__tests__/DocXMLaterProcessor.hyperlinks.test.md +311 -0
- package/src/services/document/__tests__/WordDocumentProcessor.integration.test.ts +515 -0
- package/src/services/document/__tests__/WordDocumentProcessor.test.ts +812 -0
- package/src/services/document/blanklines/BlankLineManager.ts +658 -0
- package/src/services/document/blanklines/__tests__/paragraphChecks.test.ts +281 -0
- package/src/services/document/blanklines/helpers/blankLineInsertion.ts +87 -0
- package/src/services/document/blanklines/helpers/blankLineSnapshot.ts +251 -0
- package/src/services/document/blanklines/helpers/clearCustom.ts +121 -0
- package/src/services/document/blanklines/helpers/contextChecks.ts +117 -0
- package/src/services/document/blanklines/helpers/imageChecks.ts +51 -0
- package/src/services/document/blanklines/helpers/paragraphChecks.ts +236 -0
- package/src/services/document/blanklines/helpers/removeBlanksBetweenListItems.ts +91 -0
- package/src/services/document/blanklines/helpers/removeTrailingBlanks.ts +35 -0
- package/src/services/document/blanklines/helpers/tableGuards.ts +21 -0
- package/src/services/document/blanklines/index.ts +67 -0
- package/src/services/document/blanklines/rules/additionRules.ts +337 -0
- package/src/services/document/blanklines/rules/indentationRules.ts +317 -0
- package/src/services/document/blanklines/rules/removalRules.ts +362 -0
- package/src/services/document/blanklines/rules/ruleTypes.ts +92 -0
- package/src/services/document/blanklines/types.ts +29 -0
- package/src/services/document/helpers/ImageBorderCropper.ts +377 -0
- package/src/services/document/helpers/__tests__/whitespace.test.ts +272 -0
- package/src/services/document/helpers/whitespace.ts +117 -0
- package/src/services/document/list/ListNormalizer.ts +947 -0
- package/src/services/document/list/index.ts +45 -0
- package/src/services/document/list/list-detection.ts +275 -0
- package/src/services/document/list/list-types.ts +162 -0
- package/src/services/document/processors/HyperlinkProcessor.ts +370 -0
- package/src/services/document/processors/ListProcessor.ts +257 -0
- package/src/services/document/processors/StructureProcessor.ts +176 -0
- package/src/services/document/processors/StyleProcessor.ts +389 -0
- package/src/services/document/processors/TableProcessor.ts +2238 -0
- package/src/services/document/processors/__tests__/HyperlinkProcessor.test.ts +314 -0
- package/src/services/document/processors/__tests__/ListProcessor.test.ts +291 -0
- package/src/services/document/processors/__tests__/StructureProcessor.test.ts +257 -0
- package/src/services/document/processors/__tests__/TableProcessor.hlp-tips-bullets.test.ts +459 -0
- package/src/services/document/processors/__tests__/TableProcessor.test.ts +1604 -0
- package/src/services/document/processors/index.ts +28 -0
- package/src/services/document/types/docx-processing.ts +310 -0
- package/src/services/editor/EditorActionHandlers.ts +901 -0
- package/src/services/editor/index.ts +13 -0
- package/src/setupTests.ts +47 -0
- package/src/styles/global.css +782 -0
- package/src/types/backup.ts +132 -0
- package/src/types/dictionary.ts +125 -0
- package/src/types/document-processing.ts +331 -0
- package/src/types/docxmlater-augments.d.ts +142 -0
- package/src/types/editor.ts +280 -0
- package/src/types/electron.ts +340 -0
- package/src/types/globalStats.ts +155 -0
- package/src/types/hyperlink.ts +471 -0
- package/src/types/operations.ts +354 -0
- package/src/types/session.ts +427 -0
- package/src/types/settings.ts +112 -0
- package/src/utils/MemoryMonitor.ts +248 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/colorConvert.ts +306 -0
- package/src/utils/diffUtils.ts +347 -0
- package/src/utils/documentUtils.ts +202 -0
- package/src/utils/electronGuard.ts +62 -0
- package/src/utils/indexedDB.ts +915 -0
- package/src/utils/logger.ts +717 -0
- package/src/utils/pathSecurity.ts +232 -0
- package/src/utils/pathValidator.ts +236 -0
- package/src/utils/processingTimeEstimator.ts +153 -0
- package/src/utils/safeJsonParse.ts +62 -0
- package/src/utils/textSanitizer.ts +162 -0
- package/src/utils/urlHelpers.ts +304 -0
- package/src/utils/urlPatterns.ts +198 -0
- package/src/utils/urlSanitizer.ts +152 -0
- package/src/vite-env.d.ts +11 -0
- package/tsconfig.electron.json +19 -0
- package/tsconfig.json +36 -0
- package/tsconfig.node.json +12 -0
- package/typedoc.json +45 -0
- package/vite.config.ts +152 -0
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
# TypeScript Type Definitions Guide
|
|
2
|
+
|
|
3
|
+
Complete reference for all TypeScript types, interfaces, and enums used in the Documentation Hub's DOCX processing API.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Core Types](#core-types)
|
|
8
|
+
- [Result Types](#result-types)
|
|
9
|
+
- [Style Types](#style-types)
|
|
10
|
+
- [Document Structure Types](#document-structure-types)
|
|
11
|
+
- [Processing Options](#processing-options)
|
|
12
|
+
- [Error Types](#error-types)
|
|
13
|
+
- [Helper Types](#helper-types)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Core Types
|
|
18
|
+
|
|
19
|
+
### ProcessorResult<T>
|
|
20
|
+
|
|
21
|
+
Generic result type for all processor operations. Provides consistent error handling across the API.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
interface ProcessorResult<T = any> {
|
|
25
|
+
success: boolean;
|
|
26
|
+
data?: T;
|
|
27
|
+
error?: string;
|
|
28
|
+
warnings?: string[];
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Properties:**
|
|
33
|
+
- `success` (boolean) - Indicates if the operation succeeded
|
|
34
|
+
- `data` (T, optional) - Result data if successful
|
|
35
|
+
- `error` (string, optional) - Error message if failed
|
|
36
|
+
- `warnings` (string[], optional) - Warning messages
|
|
37
|
+
|
|
38
|
+
**Example:**
|
|
39
|
+
```typescript
|
|
40
|
+
const result: ProcessorResult<Document> = await processor.loadFromFile('file.docx');
|
|
41
|
+
|
|
42
|
+
if (result.success) {
|
|
43
|
+
const doc = result.data; // TypeScript knows data exists
|
|
44
|
+
// Work with document...
|
|
45
|
+
} else {
|
|
46
|
+
console.error(result.error); // TypeScript knows error exists
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
### DocXMLaterOptions
|
|
53
|
+
|
|
54
|
+
Configuration options for the DocXMLaterProcessor.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
interface DocXMLaterOptions {
|
|
58
|
+
preserveFormatting?: boolean;
|
|
59
|
+
validateOutput?: boolean;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Properties:**
|
|
64
|
+
- `preserveFormatting` (boolean, optional, default: true) - Preserve existing formatting when applying styles
|
|
65
|
+
- `validateOutput` (boolean, optional, default: false) - Validate document structure before saving
|
|
66
|
+
|
|
67
|
+
**Example:**
|
|
68
|
+
```typescript
|
|
69
|
+
const processor = new DocXMLaterProcessor({
|
|
70
|
+
preserveFormatting: true,
|
|
71
|
+
validateOutput: false
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Result Types
|
|
78
|
+
|
|
79
|
+
### DocumentReadResult
|
|
80
|
+
|
|
81
|
+
Result type for document reading operations.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface DocumentReadResult extends ProcessorResult {
|
|
85
|
+
data?: DocxDocument;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Extends:** `ProcessorResult`
|
|
90
|
+
|
|
91
|
+
**Example:**
|
|
92
|
+
```typescript
|
|
93
|
+
const result: DocumentReadResult = await processor.readDocument('file.docx');
|
|
94
|
+
|
|
95
|
+
if (result.success && result.data) {
|
|
96
|
+
console.log(`Paragraphs: ${result.data.content.paragraphs.length}`);
|
|
97
|
+
console.log(`Tables: ${result.data.content.tables?.length || 0}`);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
### DocumentModifyResult
|
|
104
|
+
|
|
105
|
+
Result type for document modification operations.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface DocumentModifyResult extends ProcessorResult {
|
|
109
|
+
data?: Buffer;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Extends:** `ProcessorResult`
|
|
114
|
+
|
|
115
|
+
**Properties:**
|
|
116
|
+
- `data` (Buffer, optional) - Modified DOCX file as buffer
|
|
117
|
+
|
|
118
|
+
**Example:**
|
|
119
|
+
```typescript
|
|
120
|
+
const result: DocumentModifyResult = await processor.toBuffer(doc);
|
|
121
|
+
|
|
122
|
+
if (result.success && result.data) {
|
|
123
|
+
// result.data is a Buffer containing the DOCX file
|
|
124
|
+
await fs.writeFile('output.docx', result.data);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### StyleApplicationResult
|
|
131
|
+
|
|
132
|
+
Result type for style application operations.
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
interface StyleApplicationResult {
|
|
136
|
+
appliedCount: number;
|
|
137
|
+
skippedCount: number;
|
|
138
|
+
paragraphsModified: number[];
|
|
139
|
+
totalParagraphs: number;
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Properties:**
|
|
144
|
+
- `appliedCount` (number) - Number of paragraphs where style was applied
|
|
145
|
+
- `skippedCount` (number) - Number of paragraphs that didn't match criteria
|
|
146
|
+
- `paragraphsModified` (number[]) - Array of modified paragraph indices
|
|
147
|
+
- `totalParagraphs` (number) - Total number of paragraphs in document
|
|
148
|
+
|
|
149
|
+
**Example:**
|
|
150
|
+
```typescript
|
|
151
|
+
const result: ProcessorResult<StyleApplicationResult> = await processor.applyStyleToParagraphs(
|
|
152
|
+
doc,
|
|
153
|
+
'Heading1',
|
|
154
|
+
{ target: 'all' }
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
if (result.success && result.data) {
|
|
158
|
+
console.log(`Applied to ${result.data.appliedCount} of ${result.data.totalParagraphs} paragraphs`);
|
|
159
|
+
console.log(`Modified paragraphs:`, result.data.paragraphsModified);
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Style Types
|
|
166
|
+
|
|
167
|
+
### TextStyle
|
|
168
|
+
|
|
169
|
+
Text formatting properties for runs and paragraphs.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
interface TextStyle {
|
|
173
|
+
fontFamily?: string;
|
|
174
|
+
fontSize?: number;
|
|
175
|
+
bold?: boolean;
|
|
176
|
+
italic?: boolean;
|
|
177
|
+
underline?: boolean;
|
|
178
|
+
preserveBold?: boolean;
|
|
179
|
+
preserveItalic?: boolean;
|
|
180
|
+
preserveUnderline?: boolean;
|
|
181
|
+
color?: string;
|
|
182
|
+
highlight?: string;
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Properties:**
|
|
187
|
+
- `fontFamily` (string, optional) - Font name (e.g., "Arial", "Times New Roman")
|
|
188
|
+
- `fontSize` (number, optional) - Font size in points
|
|
189
|
+
- `bold` (boolean, optional) - Bold formatting
|
|
190
|
+
- `italic` (boolean, optional) - Italic formatting
|
|
191
|
+
- `underline` (boolean, optional) - Underline formatting
|
|
192
|
+
- `preserveBold` (boolean, optional) - Preserve existing bold (ignore bold property)
|
|
193
|
+
- `preserveItalic` (boolean, optional) - Preserve existing italic
|
|
194
|
+
- `preserveUnderline` (boolean, optional) - Preserve existing underline
|
|
195
|
+
- `color` (string, optional) - Text color in hex format (with or without #)
|
|
196
|
+
- `highlight` (string, optional) - Highlight color name
|
|
197
|
+
|
|
198
|
+
**Example:**
|
|
199
|
+
```typescript
|
|
200
|
+
const textStyle: TextStyle = {
|
|
201
|
+
fontFamily: 'Arial',
|
|
202
|
+
fontSize: 12,
|
|
203
|
+
bold: true,
|
|
204
|
+
color: '#FF0000', // Red text
|
|
205
|
+
highlight: 'yellow'
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
await processor.createParagraph(doc, 'Important Text', textStyle);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
### ParagraphStyle
|
|
214
|
+
|
|
215
|
+
Paragraph formatting properties for alignment, spacing, and indentation.
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
interface ParagraphStyle {
|
|
219
|
+
alignment?: 'left' | 'center' | 'right' | 'justify';
|
|
220
|
+
indentLeft?: number;
|
|
221
|
+
indentRight?: number;
|
|
222
|
+
indentFirstLine?: number;
|
|
223
|
+
spaceBefore?: number;
|
|
224
|
+
spaceAfter?: number;
|
|
225
|
+
lineSpacing?: number;
|
|
226
|
+
keepNext?: boolean;
|
|
227
|
+
keepLines?: boolean;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Properties:**
|
|
232
|
+
- `alignment` ('left'|'center'|'right'|'justify', optional) - Text alignment
|
|
233
|
+
- `indentLeft` (number, optional) - Left indentation in twips
|
|
234
|
+
- `indentRight` (number, optional) - Right indentation in twips
|
|
235
|
+
- `indentFirstLine` (number, optional) - First line indentation in twips
|
|
236
|
+
- `spaceBefore` (number, optional) - Space before paragraph in twips
|
|
237
|
+
- `spaceAfter` (number, optional) - Space after paragraph in twips
|
|
238
|
+
- `lineSpacing` (number, optional) - Line spacing in twips
|
|
239
|
+
- `keepNext` (boolean, optional) - Keep with next paragraph
|
|
240
|
+
- `keepLines` (boolean, optional) - Keep lines together
|
|
241
|
+
|
|
242
|
+
**Note:** 1 inch = 1440 twips, 1 point = 20 twips
|
|
243
|
+
|
|
244
|
+
**Example:**
|
|
245
|
+
```typescript
|
|
246
|
+
const processor = new DocXMLaterProcessor();
|
|
247
|
+
|
|
248
|
+
const paragraphStyle: ParagraphStyle = {
|
|
249
|
+
alignment: 'justify',
|
|
250
|
+
indentLeft: processor.inchesToTwips(0.5), // 0.5 inch = 720 twips
|
|
251
|
+
indentFirstLine: processor.inchesToTwips(0.25), // 0.25 inch = 360 twips
|
|
252
|
+
spaceBefore: processor.pointsToTwips(12), // 12 points = 240 twips
|
|
253
|
+
spaceAfter: processor.pointsToTwips(6), // 6 points = 120 twips
|
|
254
|
+
keepNext: true
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
await processor.createParagraph(doc, 'Formatted paragraph', paragraphStyle);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
### StyleApplication
|
|
263
|
+
|
|
264
|
+
Targeting criteria for applying styles to paragraphs.
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
interface StyleApplication {
|
|
268
|
+
target: 'all' | 'pattern' | 'indices';
|
|
269
|
+
styleId: string;
|
|
270
|
+
pattern?: string | RegExp;
|
|
271
|
+
indices?: number[];
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Properties:**
|
|
276
|
+
- `target` ('all'|'pattern'|'indices') - Target mode selector
|
|
277
|
+
- `'all'` - Apply to all paragraphs
|
|
278
|
+
- `'pattern'` - Apply to paragraphs matching pattern
|
|
279
|
+
- `'indices'` - Apply to specific paragraph indices
|
|
280
|
+
- `styleId` (string) - ID of the style to apply
|
|
281
|
+
- `pattern` (string | RegExp, optional) - Pattern to match (required if target='pattern')
|
|
282
|
+
- `indices` (number[], optional) - Paragraph indices (required if target='indices')
|
|
283
|
+
|
|
284
|
+
**Examples:**
|
|
285
|
+
```typescript
|
|
286
|
+
// Apply to all paragraphs
|
|
287
|
+
const applyAll: StyleApplication = {
|
|
288
|
+
target: 'all',
|
|
289
|
+
styleId: 'Normal'
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// Apply to paragraphs containing specific text
|
|
293
|
+
const applyPattern: StyleApplication = {
|
|
294
|
+
target: 'pattern',
|
|
295
|
+
styleId: 'Heading1',
|
|
296
|
+
pattern: /^Chapter \d+/i
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// Apply to specific paragraph indices
|
|
300
|
+
const applyIndices: StyleApplication = {
|
|
301
|
+
target: 'indices',
|
|
302
|
+
styleId: 'Title',
|
|
303
|
+
indices: [0, 5, 10]
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const result = await processor.applyStyleToParagraphs(doc, 'Heading1', applyPattern);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
### NumberingStyle
|
|
312
|
+
|
|
313
|
+
Numbering/list formatting properties.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
interface NumberingStyle {
|
|
317
|
+
level: number;
|
|
318
|
+
format: 'bullet' | 'decimal' | 'lowerLetter' | 'upperLetter' | 'lowerRoman' | 'upperRoman';
|
|
319
|
+
text?: string;
|
|
320
|
+
alignment?: 'left' | 'center' | 'right';
|
|
321
|
+
indentLeft?: number;
|
|
322
|
+
indentHanging?: number;
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**Properties:**
|
|
327
|
+
- `level` (number) - List level (0-8, total 9 levels)
|
|
328
|
+
- `format` (string) - Numbering format type
|
|
329
|
+
- `text` (string, optional) - For bullets, the character to use
|
|
330
|
+
- `alignment` ('left'|'center'|'right', optional) - Number alignment
|
|
331
|
+
- `indentLeft` (number, optional) - Left indentation in twips
|
|
332
|
+
- `indentHanging` (number, optional) - Hanging indentation in twips
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
## Document Structure Types
|
|
337
|
+
|
|
338
|
+
### DocxDocument
|
|
339
|
+
|
|
340
|
+
Complete document structure with all components.
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
interface DocxDocument {
|
|
344
|
+
styles: DocxStyles;
|
|
345
|
+
numbering: DocxNumbering;
|
|
346
|
+
fonts: DocxFonts;
|
|
347
|
+
content: DocxContent;
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Properties:**
|
|
352
|
+
- `styles` (DocxStyles) - Document styles
|
|
353
|
+
- `numbering` (DocxNumbering) - Numbering definitions
|
|
354
|
+
- `fonts` (DocxFonts) - Font definitions
|
|
355
|
+
- `content` (DocxContent) - Document content (paragraphs, tables)
|
|
356
|
+
|
|
357
|
+
**Example:**
|
|
358
|
+
```typescript
|
|
359
|
+
const result: DocumentReadResult = await processor.readDocument('file.docx');
|
|
360
|
+
|
|
361
|
+
if (result.success && result.data) {
|
|
362
|
+
const doc: DocxDocument = result.data;
|
|
363
|
+
|
|
364
|
+
// Access paragraphs
|
|
365
|
+
doc.content.paragraphs.forEach((para, index) => {
|
|
366
|
+
console.log(`Paragraph ${index}: ${para.text}`);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// Access tables
|
|
370
|
+
doc.content.tables?.forEach((table, index) => {
|
|
371
|
+
console.log(`Table ${index}: ${table.rows.length} rows`);
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
---
|
|
377
|
+
|
|
378
|
+
### Paragraph
|
|
379
|
+
|
|
380
|
+
Paragraph structure with text and formatting.
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
interface Paragraph {
|
|
384
|
+
text: string;
|
|
385
|
+
style?: string;
|
|
386
|
+
numbering?: {
|
|
387
|
+
id: string;
|
|
388
|
+
level: number;
|
|
389
|
+
};
|
|
390
|
+
runs?: Run[];
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Properties:**
|
|
395
|
+
- `text` (string) - Combined text from all runs
|
|
396
|
+
- `style` (string, optional) - Style name applied to paragraph
|
|
397
|
+
- `numbering` (object, optional) - Numbering/list information
|
|
398
|
+
- `runs` (Run[], optional) - Individual text runs with formatting
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
### Run
|
|
403
|
+
|
|
404
|
+
Text run with specific formatting.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
interface Run {
|
|
408
|
+
text: string;
|
|
409
|
+
style?: TextStyle;
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
**Properties:**
|
|
414
|
+
- `text` (string) - Text content
|
|
415
|
+
- `style` (TextStyle, optional) - Text formatting
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
### Table
|
|
420
|
+
|
|
421
|
+
Table structure with rows and cells.
|
|
422
|
+
|
|
423
|
+
```typescript
|
|
424
|
+
interface Table {
|
|
425
|
+
rows: TableRow[];
|
|
426
|
+
style?: string;
|
|
427
|
+
}
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**Properties:**
|
|
431
|
+
- `rows` (TableRow[]) - Array of table rows
|
|
432
|
+
- `style` (string, optional) - Table style name
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
436
|
+
### TableRow
|
|
437
|
+
|
|
438
|
+
Table row containing cells.
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
interface TableRow {
|
|
442
|
+
cells: TableCell[];
|
|
443
|
+
}
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
**Properties:**
|
|
447
|
+
- `cells` (TableCell[]) - Array of cells in the row
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
### TableCell
|
|
452
|
+
|
|
453
|
+
Table cell with content and formatting.
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
interface TableCell {
|
|
457
|
+
text: string;
|
|
458
|
+
colspan: number;
|
|
459
|
+
rowspan: number;
|
|
460
|
+
paragraphs: Paragraph[];
|
|
461
|
+
style?: any;
|
|
462
|
+
}
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
**Properties:**
|
|
466
|
+
- `text` (string) - Combined text from all paragraphs
|
|
467
|
+
- `colspan` (number) - Column span (1 = no merge, >1 = merged cells)
|
|
468
|
+
- `rowspan` (number) - Row span (1 = no merge, >1 = merged cells)
|
|
469
|
+
- `paragraphs` (Paragraph[]) - Detailed paragraph structure within cell
|
|
470
|
+
- `style` (any, optional) - Cell style (deprecated, kept for compatibility)
|
|
471
|
+
|
|
472
|
+
**Example:**
|
|
473
|
+
```typescript
|
|
474
|
+
const result = await processor.readDocument('file.docx');
|
|
475
|
+
|
|
476
|
+
if (result.success && result.data) {
|
|
477
|
+
result.data.content.tables?.forEach((table) => {
|
|
478
|
+
table.rows.forEach((row, rowIndex) => {
|
|
479
|
+
row.cells.forEach((cell, cellIndex) => {
|
|
480
|
+
console.log(`Cell [${rowIndex}][${cellIndex}]: ${cell.text}`);
|
|
481
|
+
console.log(` Colspan: ${cell.colspan}, Rowspan: ${cell.rowspan}`);
|
|
482
|
+
|
|
483
|
+
// Access cell paragraphs
|
|
484
|
+
cell.paragraphs.forEach((para, paraIndex) => {
|
|
485
|
+
console.log(` Paragraph ${paraIndex}: ${para.text}`);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
## Processing Options
|
|
496
|
+
|
|
497
|
+
### DocumentReadOptions
|
|
498
|
+
|
|
499
|
+
Options for reading document structure.
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
interface DocumentReadOptions {
|
|
503
|
+
parseStyles?: boolean;
|
|
504
|
+
parseNumbering?: boolean;
|
|
505
|
+
parseFonts?: boolean;
|
|
506
|
+
parseContent?: boolean;
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
**Properties:**
|
|
511
|
+
- `parseStyles` (boolean, optional) - Parse style definitions
|
|
512
|
+
- `parseNumbering` (boolean, optional) - Parse numbering definitions
|
|
513
|
+
- `parseFonts` (boolean, optional) - Parse font definitions
|
|
514
|
+
- `parseContent` (boolean, optional) - Parse document content
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
### DocumentModifyOptions
|
|
519
|
+
|
|
520
|
+
Options for modifying documents.
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
interface DocumentModifyOptions {
|
|
524
|
+
operation: DocumentOperation;
|
|
525
|
+
preserveFormatting?: boolean;
|
|
526
|
+
updateStyles?: boolean;
|
|
527
|
+
updateNumbering?: boolean;
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Properties:**
|
|
532
|
+
- `operation` (DocumentOperation) - Type of operation
|
|
533
|
+
- `preserveFormatting` (boolean, optional) - Preserve existing formatting
|
|
534
|
+
- `updateStyles` (boolean, optional) - Update style definitions
|
|
535
|
+
- `updateNumbering` (boolean, optional) - Update numbering definitions
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
539
|
+
### DocumentOperation
|
|
540
|
+
|
|
541
|
+
Enum for document operation types.
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
enum DocumentOperation {
|
|
545
|
+
CREATE = 'create',
|
|
546
|
+
READ = 'read',
|
|
547
|
+
MODIFY = 'modify',
|
|
548
|
+
MODIFY_TEMPLATE = 'modify_template',
|
|
549
|
+
MODIFY_XML = 'modify_xml',
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
**Values:**
|
|
554
|
+
- `CREATE` - Create new document
|
|
555
|
+
- `READ` - Read existing document
|
|
556
|
+
- `MODIFY` - Modify existing document
|
|
557
|
+
- `MODIFY_TEMPLATE` - Modify document template
|
|
558
|
+
- `MODIFY_XML` - Modify document XML
|
|
559
|
+
|
|
560
|
+
---
|
|
561
|
+
|
|
562
|
+
## Error Types
|
|
563
|
+
|
|
564
|
+
### DocxProcessingError
|
|
565
|
+
|
|
566
|
+
Custom error class for DOCX processing errors.
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
class DocxProcessingError extends Error {
|
|
570
|
+
constructor(
|
|
571
|
+
message: string,
|
|
572
|
+
public code: string,
|
|
573
|
+
public details?: any
|
|
574
|
+
) {
|
|
575
|
+
super(message);
|
|
576
|
+
this.name = 'DocxProcessingError';
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
**Properties:**
|
|
582
|
+
- `message` (string) - Error message
|
|
583
|
+
- `code` (string) - Error code from ErrorCode enum
|
|
584
|
+
- `details` (any, optional) - Additional error details
|
|
585
|
+
|
|
586
|
+
**Example:**
|
|
587
|
+
```typescript
|
|
588
|
+
try {
|
|
589
|
+
// DOCX processing...
|
|
590
|
+
} catch (error) {
|
|
591
|
+
if (error instanceof DocxProcessingError) {
|
|
592
|
+
console.error(`Error ${error.code}: ${error.message}`);
|
|
593
|
+
console.error('Details:', error.details);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
---
|
|
599
|
+
|
|
600
|
+
### ErrorCode
|
|
601
|
+
|
|
602
|
+
Enum for standardized error codes.
|
|
603
|
+
|
|
604
|
+
```typescript
|
|
605
|
+
enum ErrorCode {
|
|
606
|
+
INVALID_DOCX = 'INVALID_DOCX',
|
|
607
|
+
FILE_NOT_FOUND = 'FILE_NOT_FOUND',
|
|
608
|
+
PARSE_ERROR = 'PARSE_ERROR',
|
|
609
|
+
XML_ERROR = 'XML_ERROR',
|
|
610
|
+
STYLE_NOT_FOUND = 'STYLE_NOT_FOUND',
|
|
611
|
+
NUMBERING_NOT_FOUND = 'NUMBERING_NOT_FOUND',
|
|
612
|
+
UNSUPPORTED_OPERATION = 'UNSUPPORTED_OPERATION',
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
**Values:**
|
|
617
|
+
- `INVALID_DOCX` - Invalid or corrupted DOCX file
|
|
618
|
+
- `FILE_NOT_FOUND` - File does not exist
|
|
619
|
+
- `PARSE_ERROR` - Failed to parse document
|
|
620
|
+
- `XML_ERROR` - XML parsing or generation error
|
|
621
|
+
- `STYLE_NOT_FOUND` - Referenced style not found
|
|
622
|
+
- `NUMBERING_NOT_FOUND` - Referenced numbering not found
|
|
623
|
+
- `UNSUPPORTED_OPERATION` - Operation not supported
|
|
624
|
+
|
|
625
|
+
---
|
|
626
|
+
|
|
627
|
+
## Helper Types
|
|
628
|
+
|
|
629
|
+
### HyperlinkInfo
|
|
630
|
+
|
|
631
|
+
Information about a hyperlink extracted from a document.
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
interface HyperlinkInfo {
|
|
635
|
+
hyperlink: Hyperlink;
|
|
636
|
+
paragraph: Paragraph;
|
|
637
|
+
paragraphIndex: number;
|
|
638
|
+
url?: string;
|
|
639
|
+
text: string;
|
|
640
|
+
}
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
**Properties:**
|
|
644
|
+
- `hyperlink` (Hyperlink) - Hyperlink object instance
|
|
645
|
+
- `paragraph` (Paragraph) - Parent paragraph containing the hyperlink
|
|
646
|
+
- `paragraphIndex` (number) - Index of the paragraph in document
|
|
647
|
+
- `url` (string, optional) - Hyperlink URL
|
|
648
|
+
- `text` (string) - Display text (automatically sanitized)
|
|
649
|
+
|
|
650
|
+
**Example:**
|
|
651
|
+
```typescript
|
|
652
|
+
const hyperlinks: HyperlinkInfo[] = await processor.extractHyperlinks(doc);
|
|
653
|
+
|
|
654
|
+
hyperlinks.forEach((link) => {
|
|
655
|
+
console.log(`Text: ${link.text}`);
|
|
656
|
+
console.log(`URL: ${link.url}`);
|
|
657
|
+
console.log(`Paragraph: ${link.paragraphIndex}`);
|
|
658
|
+
});
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
### SearchResult
|
|
664
|
+
|
|
665
|
+
Result from text search operations.
|
|
666
|
+
|
|
667
|
+
```typescript
|
|
668
|
+
interface SearchResult {
|
|
669
|
+
text: string;
|
|
670
|
+
paragraphIndex: number;
|
|
671
|
+
runIndex: number;
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
**Properties:**
|
|
676
|
+
- `text` (string) - Matched text
|
|
677
|
+
- `paragraphIndex` (number) - Index of paragraph containing match
|
|
678
|
+
- `runIndex` (number) - Index of run within paragraph
|
|
679
|
+
|
|
680
|
+
**Example:**
|
|
681
|
+
```typescript
|
|
682
|
+
const results: SearchResult[] = await processor.findText(doc, 'important', {
|
|
683
|
+
caseSensitive: false
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
results.forEach((result) => {
|
|
687
|
+
console.log(`Found "${result.text}" in paragraph ${result.paragraphIndex}`);
|
|
688
|
+
});
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
---
|
|
692
|
+
|
|
693
|
+
### SizeEstimate
|
|
694
|
+
|
|
695
|
+
Document size estimation result.
|
|
696
|
+
|
|
697
|
+
```typescript
|
|
698
|
+
interface SizeEstimate {
|
|
699
|
+
totalEstimatedMB: number;
|
|
700
|
+
warning?: string;
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
**Properties:**
|
|
705
|
+
- `totalEstimatedMB` (number) - Estimated size in megabytes
|
|
706
|
+
- `warning` (string, optional) - Warning if size exceeds thresholds
|
|
707
|
+
|
|
708
|
+
---
|
|
709
|
+
|
|
710
|
+
### SizeStats
|
|
711
|
+
|
|
712
|
+
Detailed document statistics.
|
|
713
|
+
|
|
714
|
+
```typescript
|
|
715
|
+
interface SizeStats {
|
|
716
|
+
elements: {
|
|
717
|
+
paragraphs: number;
|
|
718
|
+
tables: number;
|
|
719
|
+
images: number;
|
|
720
|
+
hyperlinks: number;
|
|
721
|
+
};
|
|
722
|
+
size: {
|
|
723
|
+
totalEstimatedMB: number;
|
|
724
|
+
};
|
|
725
|
+
warnings?: string[];
|
|
726
|
+
}
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
**Properties:**
|
|
730
|
+
- `elements` (object) - Element counts
|
|
731
|
+
- `paragraphs` (number) - Number of paragraphs
|
|
732
|
+
- `tables` (number) - Number of tables
|
|
733
|
+
- `images` (number) - Number of images
|
|
734
|
+
- `hyperlinks` (number) - Number of hyperlinks
|
|
735
|
+
- `size` (object) - Size information
|
|
736
|
+
- `totalEstimatedMB` (number) - Estimated size in megabytes
|
|
737
|
+
- `warnings` (string[], optional) - Array of warning messages
|
|
738
|
+
|
|
739
|
+
**Example:**
|
|
740
|
+
```typescript
|
|
741
|
+
const stats: SizeStats = await processor.getSizeStats(doc);
|
|
742
|
+
|
|
743
|
+
console.log('Document Statistics:');
|
|
744
|
+
console.log(`- Paragraphs: ${stats.elements.paragraphs}`);
|
|
745
|
+
console.log(`- Tables: ${stats.elements.tables}`);
|
|
746
|
+
console.log(`- Images: ${stats.elements.images}`);
|
|
747
|
+
console.log(`- Hyperlinks: ${stats.elements.hyperlinks}`);
|
|
748
|
+
console.log(`- Size: ${stats.size.totalEstimatedMB.toFixed(2)} MB`);
|
|
749
|
+
|
|
750
|
+
if (stats.warnings) {
|
|
751
|
+
stats.warnings.forEach((warning) => console.warn(warning));
|
|
752
|
+
}
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
---
|
|
756
|
+
|
|
757
|
+
## Type Guards
|
|
758
|
+
|
|
759
|
+
### Type guard examples for safe type checking
|
|
760
|
+
|
|
761
|
+
```typescript
|
|
762
|
+
// Check if result succeeded
|
|
763
|
+
function isSuccess<T>(result: ProcessorResult<T>): result is ProcessorResult<T> & { success: true; data: T } {
|
|
764
|
+
return result.success === true && result.data !== undefined;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Usage
|
|
768
|
+
const result = await processor.loadFromFile('file.docx');
|
|
769
|
+
if (isSuccess(result)) {
|
|
770
|
+
const doc = result.data; // TypeScript knows data exists
|
|
771
|
+
// Work with document...
|
|
772
|
+
}
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
---
|
|
776
|
+
|
|
777
|
+
## Unit Conversion Constants
|
|
778
|
+
|
|
779
|
+
```typescript
|
|
780
|
+
// Constants used for unit conversion
|
|
781
|
+
const TWIPS_PER_INCH = 1440;
|
|
782
|
+
const TWIPS_PER_POINT = 20;
|
|
783
|
+
const POINTS_PER_INCH = 72;
|
|
784
|
+
|
|
785
|
+
// Helper functions
|
|
786
|
+
function inchesToTwips(inches: number): number {
|
|
787
|
+
return inches * TWIPS_PER_INCH;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
function pointsToTwips(points: number): number {
|
|
791
|
+
return points * TWIPS_PER_POINT;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
function twipsToPoints(twips: number): number {
|
|
795
|
+
return twips / TWIPS_PER_POINT;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function twipsToInches(twips: number): number {
|
|
799
|
+
return twips / TWIPS_PER_INCH;
|
|
800
|
+
}
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
---
|
|
804
|
+
|
|
805
|
+
## Best Practices
|
|
806
|
+
|
|
807
|
+
### 1. Always check result success
|
|
808
|
+
|
|
809
|
+
```typescript
|
|
810
|
+
const result = await processor.loadFromFile('file.docx');
|
|
811
|
+
if (!result.success) {
|
|
812
|
+
console.error('Error:', result.error);
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
const doc = result.data;
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
### 2. Use type guards for better type safety
|
|
819
|
+
|
|
820
|
+
```typescript
|
|
821
|
+
function processDocument(result: ProcessorResult<Document>): void {
|
|
822
|
+
if (result.success && result.data) {
|
|
823
|
+
// TypeScript knows result.data exists
|
|
824
|
+
const doc = result.data;
|
|
825
|
+
// Work with document...
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
### 3. Combine styles for flexibility
|
|
831
|
+
|
|
832
|
+
```typescript
|
|
833
|
+
const combinedStyle: TextStyle & ParagraphStyle = {
|
|
834
|
+
// Text formatting
|
|
835
|
+
fontFamily: 'Arial',
|
|
836
|
+
fontSize: 12,
|
|
837
|
+
bold: true,
|
|
838
|
+
color: '#0066CC',
|
|
839
|
+
|
|
840
|
+
// Paragraph formatting
|
|
841
|
+
alignment: 'left',
|
|
842
|
+
indentLeft: processor.inchesToTwips(0.5),
|
|
843
|
+
spaceBefore: processor.pointsToTwips(12)
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
await processor.createParagraph(doc, 'Formatted text', combinedStyle);
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
### 4. Use utility functions for units
|
|
850
|
+
|
|
851
|
+
```typescript
|
|
852
|
+
const processor = new DocXMLaterProcessor();
|
|
853
|
+
|
|
854
|
+
// Convert measurements
|
|
855
|
+
const halfInch = processor.inchesToTwips(0.5);
|
|
856
|
+
const twelvePoints = processor.pointsToTwips(12);
|
|
857
|
+
|
|
858
|
+
// Use in formatting
|
|
859
|
+
await processor.createParagraph(doc, 'Text', {
|
|
860
|
+
indentLeft: halfInch,
|
|
861
|
+
spaceBefore: twelvePoints
|
|
862
|
+
});
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
---
|
|
866
|
+
|
|
867
|
+
**Last Updated:** 2025-11-13
|
|
868
|
+
**Version:** 1.0.40
|
|
869
|
+
**Documentation Hub** | [GitHub](https://github.com/ItMeDiaTech/Documentation_Hub)
|