@courtifyai/docx-render 1.0.0 → 1.0.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.
@@ -1,847 +0,0 @@
1
- /**
2
- * DOCX 渲染器类型定义
3
- * 参考 docx-preview 架构,定义 DOCX 文档的数据模型
4
- */
5
-
6
- // ==================== DOM 元素类型 ====================
7
-
8
- export enum DomType {
9
- Document = 'document',
10
- Paragraph = 'paragraph',
11
- Run = 'run',
12
- Text = 'text',
13
- Break = 'break',
14
- Table = 'table',
15
- TableRow = 'tableRow',
16
- TableCell = 'tableCell',
17
- Hyperlink = 'hyperlink',
18
- Drawing = 'drawing',
19
- Image = 'image',
20
- BookmarkStart = 'bookmarkStart',
21
- BookmarkEnd = 'bookmarkEnd',
22
- Comment = 'comment',
23
- CommentRangeStart = 'commentRangeStart',
24
- CommentRangeEnd = 'commentRangeEnd',
25
- CommentReference = 'commentReference',
26
- Section = 'section',
27
- Header = 'header',
28
- Footer = 'footer',
29
- Tab = 'tab',
30
- Symbol = 'symbol',
31
- // 域相关
32
- SimpleField = 'simpleField',
33
- ComplexField = 'complexField',
34
- FieldInstruction = 'fieldInstruction',
35
- // 脚注/尾注
36
- Footnote = 'footnote',
37
- Endnote = 'endnote',
38
- FootnoteReference = 'footnoteReference',
39
- EndnoteReference = 'endnoteReference',
40
- }
41
-
42
- // ==================== 基础元素 ====================
43
-
44
- export interface IOpenXmlElement {
45
- type: DomType
46
- children?: IOpenXmlElement[]
47
- cssStyle?: Record<string, string>
48
- className?: string
49
- }
50
-
51
- export interface IDocumentElement extends IOpenXmlElement {
52
- type: DomType.Document
53
- children: IOpenXmlElement[]
54
- /** 文档默认 Section 属性 */
55
- sectionProps?: ISectionProperties
56
- /** 文档背景样式 */
57
- background?: Record<string, string>
58
- }
59
-
60
- // ==================== 段落和文本 ====================
61
-
62
- export interface IParagraphElement extends IOpenXmlElement {
63
- type: DomType.Paragraph
64
- props?: IParagraphProperties
65
- children: IOpenXmlElement[]
66
- }
67
-
68
- export interface IRunElement extends IOpenXmlElement {
69
- type: DomType.Run
70
- props?: IRunProperties
71
- children: IOpenXmlElement[]
72
- }
73
-
74
- export interface ITextElement extends IOpenXmlElement {
75
- type: DomType.Text
76
- text: string
77
- }
78
-
79
- export interface IBreakElement extends IOpenXmlElement {
80
- type: DomType.Break
81
- breakType?: 'page' | 'column' | 'line' | 'textWrapping' | 'lastRenderedPageBreak'
82
- }
83
-
84
- export interface ITabElement extends IOpenXmlElement {
85
- type: DomType.Tab
86
- }
87
-
88
- export interface ISymbolElement extends IOpenXmlElement {
89
- type: DomType.Symbol
90
- font?: string
91
- char?: string
92
- }
93
-
94
- // ==================== 域(Fields) ====================
95
-
96
- /**
97
- * 简单域 - 如 <w:fldSimple w:instr="PAGE">
98
- */
99
- export interface ISimpleFieldElement extends IOpenXmlElement {
100
- type: DomType.SimpleField
101
- instruction: string
102
- children: IOpenXmlElement[]
103
- }
104
-
105
- /**
106
- * 复杂域字符 - 如 <w:fldChar w:fldCharType="begin"/>
107
- */
108
- export interface IComplexFieldElement extends IOpenXmlElement {
109
- type: DomType.ComplexField
110
- charType: 'begin' | 'end' | 'separate' | string
111
- }
112
-
113
- /**
114
- * 域指令 - 如 <w:instrText>PAGE</w:instrText>
115
- */
116
- export interface IFieldInstructionElement extends IOpenXmlElement {
117
- type: DomType.FieldInstruction
118
- text: string
119
- }
120
-
121
- // ==================== 表格 ====================
122
-
123
- export interface ITableElement extends IOpenXmlElement {
124
- type: DomType.Table
125
- props?: ITableProperties
126
- columns?: ITableColumn[]
127
- children: ITableRowElement[]
128
- }
129
-
130
- export interface ITableColumn {
131
- width?: string
132
- }
133
-
134
- export interface ITableRowElement extends IOpenXmlElement {
135
- type: DomType.TableRow
136
- props?: ITableRowProperties
137
- children: ITableCellElement[]
138
- }
139
-
140
- export interface ITableCellElement extends IOpenXmlElement {
141
- type: DomType.TableCell
142
- props?: ITableCellProperties
143
- children: IOpenXmlElement[]
144
- }
145
-
146
- // ==================== 评论相关 ====================
147
-
148
- export interface ICommentElement extends IOpenXmlElement {
149
- type: DomType.Comment
150
- id: string
151
- author: string
152
- date: string
153
- initials?: string
154
- children: IOpenXmlElement[]
155
- rawText?: string // 原始文本内容,作为备用
156
- /** 段落 ID(用于关联 commentsExtended) */
157
- paraId?: string
158
- /** 父评论 ID(回复链) */
159
- parentId?: string
160
- /** 子评论列表(回复) */
161
- replies?: ICommentElement[]
162
- /** 是否已完成/解决 */
163
- done?: boolean
164
- }
165
-
166
- export interface ICommentRangeStart extends IOpenXmlElement {
167
- type: DomType.CommentRangeStart
168
- id: string
169
- }
170
-
171
- export interface ICommentRangeEnd extends IOpenXmlElement {
172
- type: DomType.CommentRangeEnd
173
- id: string
174
- }
175
-
176
- export interface ICommentReference extends IOpenXmlElement {
177
- type: DomType.CommentReference
178
- id: string
179
- }
180
-
181
- // ==================== 评论扩展(回复链) ====================
182
-
183
- /**
184
- * 扩展评论信息
185
- * 对应 word/commentsExtended.xml 中的 <w15:commentEx> 元素
186
- */
187
- export interface ICommentExtended {
188
- /** 段落 ID(关联评论内容) */
189
- paraId: string
190
- /** 父段落 ID(形成回复链) */
191
- paraIdParent?: string
192
- /** 是否已完成/解决 */
193
- done: boolean
194
- }
195
-
196
- // ==================== 图片和绘图 ====================
197
-
198
- export interface IDrawingElement extends IOpenXmlElement {
199
- type: DomType.Drawing
200
- children: IOpenXmlElement[]
201
- }
202
-
203
- export interface IImageElement extends IOpenXmlElement {
204
- type: DomType.Image
205
- src: string
206
- width?: string
207
- height?: string
208
- alt?: string
209
- }
210
-
211
- // ==================== 脚注/尾注 ====================
212
-
213
- /**
214
- * 脚注元素
215
- * 对应 word/footnotes.xml 中的 <w:footnote>
216
- */
217
- export interface IFootnoteElement extends IOpenXmlElement {
218
- type: DomType.Footnote
219
- /** 脚注 ID */
220
- id: string
221
- /** 脚注类型:normal | separator | continuationSeparator */
222
- noteType?: string
223
- /** 脚注内容 */
224
- children: IOpenXmlElement[]
225
- }
226
-
227
- /**
228
- * 尾注元素
229
- * 对应 word/endnotes.xml 中的 <w:endnote>
230
- */
231
- export interface IEndnoteElement extends IOpenXmlElement {
232
- type: DomType.Endnote
233
- /** 尾注 ID */
234
- id: string
235
- /** 尾注类型:normal | separator | continuationSeparator */
236
- noteType?: string
237
- /** 尾注内容 */
238
- children: IOpenXmlElement[]
239
- }
240
-
241
- /**
242
- * 脚注引用
243
- * 文档正文中引用脚注的元素,渲染为上标数字
244
- */
245
- export interface IFootnoteReference extends IOpenXmlElement {
246
- type: DomType.FootnoteReference
247
- /** 引用的脚注 ID */
248
- id: string
249
- }
250
-
251
- /**
252
- * 尾注引用
253
- * 文档正文中引用尾注的元素,渲染为上标数字
254
- */
255
- export interface IEndnoteReference extends IOpenXmlElement {
256
- type: DomType.EndnoteReference
257
- /** 引用的尾注 ID */
258
- id: string
259
- }
260
-
261
- // ==================== 书签 ====================
262
-
263
- /**
264
- * 书签开始标记
265
- * 对应 <w:bookmarkStart> 元素
266
- */
267
- export interface IBookmarkStartElement extends IOpenXmlElement {
268
- type: DomType.BookmarkStart
269
- /** 书签 ID(用于匹配 bookmarkEnd) */
270
- id: string
271
- /** 书签名称(用于超链接跳转) */
272
- name: string
273
- /** 表格中的起始列(可选) */
274
- colFirst?: number
275
- /** 表格中的结束列(可选) */
276
- colLast?: number
277
- }
278
-
279
- /**
280
- * 书签结束标记
281
- * 对应 <w:bookmarkEnd> 元素
282
- */
283
- export interface IBookmarkEndElement extends IOpenXmlElement {
284
- type: DomType.BookmarkEnd
285
- /** 书签 ID(用于匹配 bookmarkStart) */
286
- id: string
287
- }
288
-
289
- // ==================== 超链接 ====================
290
-
291
- export interface IHyperlinkElement extends IOpenXmlElement {
292
- type: DomType.Hyperlink
293
- href?: string
294
- anchor?: string
295
- children: IOpenXmlElement[]
296
- }
297
-
298
- // ==================== 节(Section)相关 ====================
299
-
300
- export enum SectionType {
301
- Continuous = 'continuous',
302
- NextPage = 'nextPage',
303
- NextColumn = 'nextColumn',
304
- EvenPage = 'evenPage',
305
- OddPage = 'oddPage',
306
- }
307
-
308
- export interface IPageSize {
309
- width?: string
310
- height?: string
311
- orientation?: 'portrait' | 'landscape'
312
- }
313
-
314
- export interface IPageMargins {
315
- top?: string
316
- right?: string
317
- bottom?: string
318
- left?: string
319
- header?: string
320
- footer?: string
321
- gutter?: string
322
- }
323
-
324
- export interface IPageNumber {
325
- start?: number
326
- format?: 'decimal' | 'lowerRoman' | 'upperRoman' | 'lowerLetter' | 'upperLetter' | string
327
- chapSep?: string
328
- chapStyle?: string
329
- }
330
-
331
- export interface IColumns {
332
- numberOfColumns?: number
333
- space?: string
334
- separator?: boolean
335
- equalWidth?: boolean
336
- columns?: IColumn[]
337
- }
338
-
339
- export interface IColumn {
340
- width?: string
341
- space?: string
342
- }
343
-
344
- export interface IHeaderFooterReference {
345
- id: string
346
- type: 'default' | 'first' | 'even'
347
- }
348
-
349
- export interface ISectionProperties {
350
- type?: SectionType | string
351
- pageSize?: IPageSize
352
- pageMargins?: IPageMargins
353
- pageNumber?: IPageNumber
354
- pageBorders?: IBorders
355
- columns?: IColumns
356
- headerRefs?: IHeaderFooterReference[]
357
- footerRefs?: IHeaderFooterReference[]
358
- titlePage?: boolean
359
- }
360
-
361
- export interface IHeaderElement extends IOpenXmlElement {
362
- type: DomType.Header
363
- children: IOpenXmlElement[]
364
- }
365
-
366
- export interface IFooterElement extends IOpenXmlElement {
367
- type: DomType.Footer
368
- children: IOpenXmlElement[]
369
- }
370
-
371
- // ==================== 样式属性 ====================
372
-
373
- export interface IParagraphProperties {
374
- styleId?: string
375
- justification?: 'left' | 'center' | 'right' | 'both'
376
- indentation?: {
377
- left?: string
378
- right?: string
379
- firstLine?: string
380
- hanging?: string
381
- }
382
- spacing?: {
383
- before?: string
384
- after?: string
385
- /** 行间距原始值(twip 单位),需配合 lineRule 解析 */
386
- line?: number
387
- /** 行间距规则:auto=倍数行距, atLeast=最小行高, exact=精确行高 */
388
- lineRule?: 'auto' | 'atLeast' | 'exact'
389
- }
390
- outlineLevel?: number
391
- /** @deprecated 使用 numbering 替代 */
392
- numberingId?: string
393
- /** @deprecated 使用 numbering 替代 */
394
- numberingLevel?: number
395
- /** 编号信息 */
396
- numbering?: IParagraphNumbering
397
- /** 段前分页 */
398
- pageBreakBefore?: boolean
399
- /** 段落所属 Section 属性(分节符) */
400
- sectionProps?: ISectionProperties
401
- /** 边框 */
402
- borders?: IBorders
403
- }
404
-
405
- export interface IRunProperties {
406
- styleId?: string
407
- bold?: boolean
408
- italic?: boolean
409
- /** 下划线样式 */
410
- underline?: TUnderlineStyle
411
- /** 单删除线 */
412
- strike?: boolean
413
- /** 双删除线 */
414
- dstrike?: boolean
415
- color?: string
416
- /** 主题颜色引用 */
417
- themeColor?: IThemeColorRef
418
- fontSize?: string
419
- fontFamily?: string
420
- /** 主题字体引用:major(标题)或 minor(正文) */
421
- themeFontFamily?: 'major' | 'minor'
422
- highlight?: string
423
- /** 上标/下标 */
424
- vertAlign?: 'superscript' | 'subscript'
425
- }
426
-
427
- /**
428
- * 下划线样式类型
429
- * 对应 OOXML 的 w:u@val 属性值
430
- */
431
- export type TUnderlineStyle =
432
- | 'single' // 单线
433
- | 'words' // 仅文字(词之间无下划线)
434
- | 'double' // 双线
435
- | 'thick' // 粗线
436
- | 'dotted' // 点线
437
- | 'dottedHeavy' // 粗点线
438
- | 'dash' // 虚线
439
- | 'dashedHeavy' // 粗虚线
440
- | 'dashLong' // 长虚线
441
- | 'dashLongHeavy'// 粗长虚线
442
- | 'dotDash' // 点划线
443
- | 'dashDotHeavy' // 粗点划线
444
- | 'dotDotDash' // 双点划线
445
- | 'dashDotDotHeavy' // 粗双点划线
446
- | 'wave' // 波浪线
447
- | 'wavyHeavy' // 粗波浪线
448
- | 'wavyDouble' // 双波浪线
449
- | 'none' // 无下划线
450
- | string // 其他自定义值
451
-
452
- export interface ITableProperties {
453
- width?: string
454
- widthType?: 'auto' | 'dxa' | 'pct'
455
- justification?: string
456
- borders?: IBorders
457
- cellMargin?: {
458
- top?: string
459
- bottom?: string
460
- left?: string
461
- right?: string
462
- }
463
- cellSpacing?: string
464
- }
465
-
466
- export interface ITableRowProperties {
467
- height?: string
468
- isHeader?: boolean
469
- }
470
-
471
- export interface ITableCellProperties {
472
- width?: string
473
- verticalAlign?: string
474
- gridSpan?: number
475
- verticalMerge?: 'restart' | 'continue'
476
- borders?: IBorders
477
- shading?: string
478
- }
479
-
480
- export interface IBorders {
481
- top?: IBorder
482
- bottom?: IBorder
483
- left?: IBorder
484
- right?: IBorder
485
- /** 表格内部水平边框(单元格之间的水平线) */
486
- insideH?: IBorder
487
- /** 表格内部垂直边框(单元格之间的垂直线) */
488
- insideV?: IBorder
489
- }
490
-
491
- export interface IBorder {
492
- /** 边框样式:single, dashed, dotted, double, nil, none 等 */
493
- style?: string
494
- /** 边框宽度(CSS 单位) */
495
- width?: string
496
- /** 边框颜色(#RRGGBB 格式) */
497
- color?: string
498
- }
499
-
500
- // ==================== 文档结构 ====================
501
-
502
- export interface IDocxDocument {
503
- /** 文档主体内容 */
504
- body: IDocumentElement
505
- /** 评论列表(包含回复链结构) */
506
- comments: ICommentElement[]
507
- /** 评论 Map(id -> comment) */
508
- commentMap: Map<string, ICommentElement>
509
- /** 顶级评论列表(不包含回复,回复在各自的 replies 数组中) */
510
- rootComments: ICommentElement[]
511
- /** 扩展评论 Map(paraId -> ICommentExtended) */
512
- commentsExtendedMap: Map<string, ICommentExtended>
513
- /** 样式定义 */
514
- styles: IStyleDefinition[]
515
- /** 样式 Map(styleId -> style)*/
516
- styleMap: Map<string, IStyleDefinition>
517
- /** 编号定义(numId -> INumberingDefinition) */
518
- numberings: INumberingDefinition[]
519
- /** 编号 Map(numId -> INumberingDefinition) */
520
- numberingMap: Map<string, INumberingDefinition>
521
- /** 抽象编号定义 */
522
- abstractNumberings: IAbstractNumbering[]
523
- /** 图片资源 */
524
- images: Map<string, string>
525
- /** 关系 */
526
- relationships: IRelationship[]
527
- /** 页眉(relationshipId -> IHeaderElement) */
528
- headers: Map<string, IHeaderElement>
529
- /** 页脚(relationshipId -> IFooterElement) */
530
- footers: Map<string, IFooterElement>
531
- /** 主题 */
532
- theme?: ITheme
533
- /** 脚注(id -> IFootnoteElement) */
534
- footnotes: Map<string, IFootnoteElement>
535
- /** 尾注(id -> IEndnoteElement) */
536
- endnotes: Map<string, IEndnoteElement>
537
- /** 字体表 */
538
- fontTable?: IFontTable
539
- /** 已加载的嵌入字体 */
540
- embeddedFonts: ILoadedEmbedFont[]
541
- /** 书签(name -> IBookmarkStartElement) */
542
- bookmarks: Map<string, IBookmarkStartElement>
543
- }
544
-
545
- export interface IStyleDefinition {
546
- id: string
547
- name?: string
548
- type: 'paragraph' | 'character' | 'table' | 'numbering'
549
- basedOn?: string
550
- paragraphProps?: IParagraphProperties
551
- runProps?: IRunProperties
552
- }
553
-
554
- export interface INumberingDefinition {
555
- id: string
556
- abstractNumId: string
557
- levels: INumberingLevel[]
558
- }
559
-
560
- export interface INumberingLevel {
561
- level: number
562
- /** 编号格式:decimal, lowerLetter, upperLetter, lowerRoman, upperRoman, bullet 等 */
563
- format: string
564
- /** 编号文本模板,如 "%1." "%1.%2." */
565
- text: string
566
- /** 起始值 */
567
- start: number
568
- /** 后缀类型:tab, space, nothing */
569
- suffix: string
570
- paragraphProps?: IParagraphProperties
571
- runProps?: IRunProperties
572
- /** 关联的段落样式名 */
573
- pStyleName?: string
574
- }
575
-
576
- /**
577
- * 抽象编号定义
578
- */
579
- export interface IAbstractNumbering {
580
- id: string
581
- name?: string
582
- /** 多级列表类型 */
583
- multiLevelType?: 'singleLevel' | 'multiLevel' | 'hybridMultilevel' | string
584
- levels: INumberingLevel[]
585
- /** 编号样式链接 */
586
- numberingStyleLink?: string
587
- styleLink?: string
588
- }
589
-
590
- /**
591
- * 段落中的编号引用
592
- */
593
- export interface IParagraphNumbering {
594
- /** 编号定义 ID */
595
- id: string
596
- /** 编号级别(0-8) */
597
- level: number
598
- }
599
-
600
- export interface IRelationship {
601
- id: string
602
- type: string
603
- target: string
604
- targetMode?: string
605
- }
606
-
607
- // ==================== 主题(Theme) ====================
608
-
609
- /**
610
- * 主题定义
611
- * 包含颜色方案和字体方案
612
- */
613
- export interface ITheme {
614
- /** 颜色方案 */
615
- colorScheme: IColorScheme
616
- /** 字体方案 */
617
- fontScheme: IFontScheme
618
- }
619
-
620
- /**
621
- * 颜色方案
622
- * 定义主题颜色映射
623
- */
624
- export interface IColorScheme {
625
- /** 方案名称 */
626
- name: string
627
- /** 颜色映射表 */
628
- colors: IThemeColors
629
- }
630
-
631
- /**
632
- * 主题颜色映射
633
- * OOXML 标准定义的 12 种主题颜色
634
- */
635
- export interface IThemeColors {
636
- /** 深色 1 (通常为黑色) */
637
- dk1?: string
638
- /** 浅色 1 (通常为白色) */
639
- lt1?: string
640
- /** 深色 2 */
641
- dk2?: string
642
- /** 浅色 2 */
643
- lt2?: string
644
- /** 强调色 1 */
645
- accent1?: string
646
- /** 强调色 2 */
647
- accent2?: string
648
- /** 强调色 3 */
649
- accent3?: string
650
- /** 强调色 4 */
651
- accent4?: string
652
- /** 强调色 5 */
653
- accent5?: string
654
- /** 强调色 6 */
655
- accent6?: string
656
- /** 超链接颜色 */
657
- hlink?: string
658
- /** 已访问超链接颜色 */
659
- folHlink?: string
660
- /** 其他自定义颜色 */
661
- [key: string]: string | undefined
662
- }
663
-
664
- /**
665
- * 字体方案
666
- */
667
- export interface IFontScheme {
668
- /** 方案名称 */
669
- name: string
670
- /** 主要字体(标题用) */
671
- majorFont: IFontInfo
672
- /** 次要字体(正文用) */
673
- minorFont: IFontInfo
674
- }
675
-
676
- /**
677
- * 字体信息
678
- */
679
- export interface IFontInfo {
680
- /** 拉丁字体 */
681
- latin?: string
682
- /** 东亚字体 */
683
- ea?: string
684
- /** 复杂文字字体 */
685
- cs?: string
686
- }
687
-
688
- /**
689
- * 主题颜色引用
690
- * 在 Run 属性中使用
691
- */
692
- export interface IThemeColorRef {
693
- /** 主题颜色名称 */
694
- themeColor: string
695
- /** 色调 (0-255, 值越大越亮) */
696
- themeTint?: number
697
- /** 阴影 (0-255, 值越大越暗) */
698
- themeShade?: number
699
- }
700
-
701
- // ==================== 渲染器配置 ====================
702
-
703
- export interface IRendererOptions {
704
- /** 渲染容器 */
705
- container: HTMLElement | string
706
- /** 是否渲染评论 */
707
- renderComments?: boolean
708
- /** 是否允许编辑评论 */
709
- enableCommentEdit?: boolean
710
- /** 是否显示评论连接线 */
711
- showCommentLines?: boolean
712
- /** 分页显示 */
713
- breakPages?: boolean
714
- /** 自定义类名前缀 */
715
- classNamePrefix?: string
716
- /** 评论点击回调 */
717
- onCommentClick?: (comment: ICommentElement) => void
718
- /** 评论变更回调 */
719
- onCommentChange?: (comment: ICommentElement, action: 'add' | 'update' | 'delete') => void
720
- }
721
-
722
- // ==================== XML 命名空间 ====================
723
-
724
- export const XML_NS = {
725
- W: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
726
- W14: 'http://schemas.microsoft.com/office/word/2010/wordml',
727
- W15: 'http://schemas.microsoft.com/office/word/2012/wordml',
728
- R: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
729
- A: 'http://schemas.openxmlformats.org/drawingml/2006/main',
730
- WP: 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
731
- PIC: 'http://schemas.openxmlformats.org/drawingml/2006/picture',
732
- } as const
733
-
734
- // ==================== 文件路径常量 ====================
735
-
736
- export const DOCX_PARTS = {
737
- DOCUMENT: 'word/document.xml',
738
- COMMENTS: 'word/comments.xml',
739
- COMMENTS_EXTENDED: 'word/commentsExtended.xml',
740
- STYLES: 'word/styles.xml',
741
- NUMBERING: 'word/numbering.xml',
742
- THEME: 'word/theme/theme1.xml',
743
- FOOTNOTES: 'word/footnotes.xml',
744
- ENDNOTES: 'word/endnotes.xml',
745
- FONT_TABLE: 'word/fontTable.xml',
746
- FONT_TABLE_RELS: 'word/_rels/fontTable.xml.rels',
747
- RELS: 'word/_rels/document.xml.rels',
748
- CONTENT_TYPES: '[Content_Types].xml',
749
- HEADER_PREFIX: 'word/header',
750
- FOOTER_PREFIX: 'word/footer',
751
- } as const
752
-
753
- // ==================== 字体表(Font Table) ====================
754
-
755
- /**
756
- * 嵌入字体类型
757
- */
758
- export type TEmbedFontType = 'regular' | 'bold' | 'italic' | 'boldItalic'
759
-
760
- /**
761
- * 嵌入字体引用
762
- * 对应 fontTable.xml 中的 embedRegular/embedBold/embedItalic/embedBoldItalic
763
- */
764
- export interface IEmbedFontRef {
765
- /** 字体文件的关系 ID(r:id) */
766
- id: string
767
- /** 字体解密密钥(w:fontKey) */
768
- key?: string
769
- /** 字体子集 URI */
770
- subsetted?: boolean
771
- /** 字体类型 */
772
- type: TEmbedFontType
773
- }
774
-
775
- /**
776
- * 字体声明
777
- * 对应 fontTable.xml 中的 <w:font> 元素
778
- */
779
- export interface IFontDeclaration {
780
- /** 字体名称 */
781
- name: string
782
- /** 替代字体名称(字体替换) */
783
- altName?: string
784
- /** 字体家族:roman, swiss, modern, script, decorative, auto */
785
- family?: string
786
- /** 字体字符集:00(ANSI), 02(Symbol), 80(Shift JIS), 等 */
787
- charset?: string
788
- /** Panose-1 字体分类编号 */
789
- panose1?: string
790
- /** 字体签名 */
791
- sig?: IFontSignature
792
- /** 嵌入字体引用 */
793
- embedFontRefs: IEmbedFontRef[]
794
- }
795
-
796
- /**
797
- * 字体签名
798
- * 描述字体支持的 Unicode 范围
799
- */
800
- export interface IFontSignature {
801
- usb0?: string
802
- usb1?: string
803
- usb2?: string
804
- usb3?: string
805
- csb0?: string
806
- csb1?: string
807
- }
808
-
809
- /**
810
- * 字体表
811
- * 包含文档中使用的所有字体声明
812
- */
813
- export interface IFontTable {
814
- /** 字体声明列表 */
815
- fonts: IFontDeclaration[]
816
- /** 字体名称到声明的映射 */
817
- fontMap: Map<string, IFontDeclaration>
818
- /** 字体替换映射(原字体名 -> 替代字体名) */
819
- substitutionMap: Map<string, string>
820
- }
821
-
822
- /**
823
- * 已加载的嵌入字体
824
- */
825
- export interface ILoadedEmbedFont {
826
- /** 原始字体名称 */
827
- fontName: string
828
- /** 字体类型 */
829
- type: TEmbedFontType
830
- /** 字体数据 URL(Data URI 或 Blob URL) */
831
- dataUrl: string
832
- /** 字体格式 */
833
- format: 'opentype' | 'truetype' | 'embedded-opentype'
834
- }
835
-
836
- // ==================== 关系类型常量 ====================
837
-
838
- export const RELATIONSHIP_TYPES = {
839
- IMAGE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
840
- HYPERLINK: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
841
- COMMENTS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
842
- STYLES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
843
- NUMBERING: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
844
- HEADER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header',
845
- FOOTER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
846
- FONT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/font',
847
- } as const