@docx4j/core-ts 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +12 -0
  3. package/README.md +126 -0
  4. package/dist/index.d.mts +7 -0
  5. package/dist/index.mjs +10 -0
  6. package/dist/model/content/Body.d.mts +107 -0
  7. package/dist/model/content/Body.mjs +363 -0
  8. package/dist/model/content/Font.d.mts +46 -0
  9. package/dist/model/content/Font.mjs +50 -0
  10. package/dist/model/content/Paragraph.d.mts +99 -0
  11. package/dist/model/content/Paragraph.mjs +364 -0
  12. package/dist/model/content/Range.d.mts +34 -0
  13. package/dist/model/content/Range.mjs +94 -0
  14. package/dist/model/content/index.d.mts +7 -0
  15. package/dist/model/content/index.mjs +9 -0
  16. package/dist/model/content/search.d.mts +12 -0
  17. package/dist/model/content/search.mjs +68 -0
  18. package/dist/model/content/tree.d.mts +40 -0
  19. package/dist/model/content/tree.mjs +120 -0
  20. package/dist/model/index.d.mts +1 -0
  21. package/dist/model/index.mjs +2 -0
  22. package/dist/opc/ContentTypeManager.d.mts +37 -0
  23. package/dist/opc/ContentTypeManager.mjs +126 -0
  24. package/dist/opc/ContentTypes.d.mts +118 -0
  25. package/dist/opc/ContentTypes.mjs +139 -0
  26. package/dist/opc/FlatOpcPartStore.d.mts +42 -0
  27. package/dist/opc/FlatOpcPartStore.mjs +151 -0
  28. package/dist/opc/Load.d.mts +18 -0
  29. package/dist/opc/Load.mjs +123 -0
  30. package/dist/opc/PartName.d.mts +46 -0
  31. package/dist/opc/PartName.mjs +132 -0
  32. package/dist/opc/PartStore.d.mts +45 -0
  33. package/dist/opc/PartStore.mjs +54 -0
  34. package/dist/opc/Save.d.mts +9 -0
  35. package/dist/opc/Save.mjs +52 -0
  36. package/dist/opc/ZipPartStore.d.mts +32 -0
  37. package/dist/opc/ZipPartStore.mjs +117 -0
  38. package/dist/opc/exceptions.d.mts +17 -0
  39. package/dist/opc/exceptions.mjs +22 -0
  40. package/dist/opc/index.d.mts +12 -0
  41. package/dist/opc/index.mjs +13 -0
  42. package/dist/opc/mce/preprocessor.d.mts +15 -0
  43. package/dist/opc/mce/preprocessor.mjs +74 -0
  44. package/dist/opc/mce/understood.d.mts +1 -0
  45. package/dist/opc/mce/understood.mjs +98 -0
  46. package/dist/packages/OpcPackage.d.mts +62 -0
  47. package/dist/packages/OpcPackage.mjs +133 -0
  48. package/dist/packages/PresentationMLPackage.d.mts +12 -0
  49. package/dist/packages/PresentationMLPackage.mjs +39 -0
  50. package/dist/packages/SpreadsheetMLPackage.d.mts +12 -0
  51. package/dist/packages/SpreadsheetMLPackage.mjs +38 -0
  52. package/dist/packages/WordprocessingMLPackage.d.mts +49 -0
  53. package/dist/packages/WordprocessingMLPackage.mjs +130 -0
  54. package/dist/packages/index.d.mts +5 -0
  55. package/dist/packages/index.mjs +6 -0
  56. package/dist/packages/registry.d.mts +7 -0
  57. package/dist/packages/registry.mjs +18 -0
  58. package/dist/parts/BinaryPart.d.mts +38 -0
  59. package/dist/parts/BinaryPart.mjs +72 -0
  60. package/dist/parts/DefaultXmlPart.d.mts +29 -0
  61. package/dist/parts/DefaultXmlPart.mjs +63 -0
  62. package/dist/parts/Namespaces.d.mts +99 -0
  63. package/dist/parts/Namespaces.mjs +99 -0
  64. package/dist/parts/Part.d.mts +50 -0
  65. package/dist/parts/Part.mjs +68 -0
  66. package/dist/parts/PartRegistry.d.mts +20 -0
  67. package/dist/parts/PartRegistry.mjs +142 -0
  68. package/dist/parts/Parts.d.mts +13 -0
  69. package/dist/parts/Parts.mjs +28 -0
  70. package/dist/parts/RelationshipsPart.d.mts +66 -0
  71. package/dist/parts/RelationshipsPart.mjs +224 -0
  72. package/dist/parts/XmlPart.d.mts +46 -0
  73. package/dist/parts/XmlPart.mjs +87 -0
  74. package/dist/parts/customXml/index.d.mts +9 -0
  75. package/dist/parts/customXml/index.mjs +11 -0
  76. package/dist/parts/dml/index.d.mts +54 -0
  77. package/dist/parts/dml/index.mjs +83 -0
  78. package/dist/parts/docProps/index.d.mts +14 -0
  79. package/dist/parts/docProps/index.mjs +18 -0
  80. package/dist/parts/index.d.mts +14 -0
  81. package/dist/parts/index.mjs +15 -0
  82. package/dist/parts/pml/index.d.mts +53 -0
  83. package/dist/parts/pml/index.mjs +90 -0
  84. package/dist/parts/sml/index.d.mts +61 -0
  85. package/dist/parts/sml/index.mjs +107 -0
  86. package/dist/parts/wml/defaultStyles.d.mts +1 -0
  87. package/dist/parts/wml/defaultStyles.mjs +500 -0
  88. package/dist/parts/wml/index.d.mts +102 -0
  89. package/dist/parts/wml/index.mjs +213 -0
  90. package/dist/xml/dom.d.mts +22 -0
  91. package/dist/xml/dom.mjs +92 -0
  92. package/package.json +75 -0
@@ -0,0 +1,99 @@
1
+ /** Relationship types and namespaces, as docx4j org.docx4j.openpackaging.parts.relationships.Namespaces. */
2
+ export const Namespaces = {
3
+ CONTENT_TYPES: 'http://schemas.openxmlformats.org/package/2006/content-types',
4
+ RELATIONSHIPS: 'http://schemas.openxmlformats.org/package/2006/relationships',
5
+ RELATIONSHIPS_OFFICEDOC: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships',
6
+ NS_WORD12: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
7
+ PKG_XML: 'http://schemas.microsoft.com/office/2006/xmlPackage',
8
+ MARKUP_COMPATIBILITY: 'http://schemas.openxmlformats.org/markup-compatibility/2006',
9
+ DIGITAL_SIGNATURE: 'http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/signature',
10
+ DIGITAL_SIGNATURE_CERTIFICATE: 'http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/certificate',
11
+ DIGITAL_SIGNATURE_ORIGIN: 'http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin',
12
+ PROPERTIES_CORE: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties',
13
+ PROPERTIES_EXTENDED: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties',
14
+ PROPERTIES_CUSTOM: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties',
15
+ PROPERTIES_COVERPAGE: 'http://schemas.microsoft.com/office/2006/coverPageProps',
16
+ IMAGE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
17
+ THUMBNAIL: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail',
18
+ METADATA_THUMBNAIL: 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail',
19
+ DOCUMENT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
20
+ DOCUMENT_STRICT: 'http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument',
21
+ HYPERLINK: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
22
+ CUSTOM_XML_DATA_STORAGE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml',
23
+ CUSTOM_XML_DATA_STORAGE_PROPERTIES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXmlProps',
24
+ WEB_SETTINGS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings',
25
+ SETTINGS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
26
+ STYLES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
27
+ THEME: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',
28
+ THEME_OVERRIDE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/themeOverride',
29
+ FONT_TABLE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
30
+ FONT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/font',
31
+ HEADER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header',
32
+ FOOTER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
33
+ GLOSSARY_DOCUMENT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/glossaryDocument',
34
+ NUMBERING: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
35
+ FOOTNOTES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes',
36
+ ENDNOTES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes',
37
+ COMMENTS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
38
+ COMMENTS_EXTENDED: 'http://schemas.microsoft.com/office/2011/relationships/commentsExtended',
39
+ COMMENTS_IDS: 'http://schemas.microsoft.com/office/2016/09/relationships/commentsIds',
40
+ COMMENTS_EXTENSIBLE: 'http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible',
41
+ OFFICE_2011_PEOPLE: 'http://schemas.microsoft.com/office/2011/relationships/people',
42
+ AF: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk',
43
+ SUBDOCUMENT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/subDocument',
44
+ ATTACHED_TEMPLATE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate',
45
+ VBA_PROJECT: 'http://schemas.microsoft.com/office/2006/relationships/vbaProject',
46
+ VBA_DATA_WORD: 'http://schemas.microsoft.com/office/2006/relationships/wordVbaData',
47
+ KEYMAP: 'http://schemas.microsoft.com/office/2006/relationships/keyMapCustomizations',
48
+ VBA_PROJECT_SIGNATURE: 'http://schemas.microsoft.com/office/2006/relationships/vbaProjectSignature',
49
+ OLE_OBJECT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject',
50
+ EMBEDDED_PKG: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/package',
51
+ ACTIVEX_XML_OBJECT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/control',
52
+ VML: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing',
53
+ CHART_EX: 'http://schemas.microsoft.com/office/2014/relationships/chartEx',
54
+ CHART_COLOR_STYLE: 'http://schemas.microsoft.com/office/2011/relationships/chartColorStyle',
55
+ CHART_STYLE: 'http://schemas.microsoft.com/office/2011/relationships/chartStyle',
56
+ DRAWINGML_DIAGRAM_DATA: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData',
57
+ DRAWINGML_DIAGRAM_LAYOUT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout',
58
+ DRAWINGML_DIAGRAM_COLORS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramColors',
59
+ DRAWINGML_DIAGRAM_STYLE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramQuickStyle',
60
+ DRAWINGML_DIAGRAM_LAYOUT_HEADER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayoutHeader',
61
+ DRAWINGML_DIAGRAM_DRAWING: 'http://schemas.microsoft.com/office/2007/relationships/diagramDrawing',
62
+ PRESENTATIONML_COMMENTS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
63
+ PRESENTATIONML_COMMENT_AUTHORS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/commentAuthors',
64
+ PRESENTATIONML_FONT_DATA: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/font',
65
+ PRESENTATIONML_MAIN: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
66
+ PRESENTATIONML_SLIDE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide',
67
+ PRESENTATIONML_SLIDE_MASTER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster',
68
+ PRESENTATIONML_SLIDE_LAYOUT: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout',
69
+ PRESENTATIONML_TABLE_STYLES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableStyles',
70
+ PRESENTATIONML_PRES_PROPS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/presProps',
71
+ PRESENTATIONML_VIEW_PROPS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/viewProps',
72
+ PRESENTATIONML_TAGS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/tags',
73
+ PRESENTATIONML_NOTES_SLIDE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide',
74
+ PRESENTATIONML_NOTES_MASTER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesMaster',
75
+ PRESENTATIONML_HANDOUT_MASTER: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/handoutMaster',
76
+ SPREADSHEETML_WORKBOOK: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument',
77
+ SPREADSHEETML_WORKSHEET: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',
78
+ SPREADSHEETML_CHARTSHEET: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet',
79
+ SPREADSHEETML_PRINTER_SETTINGS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings',
80
+ SPREADSHEETML_CALC_CHAIN: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain',
81
+ SPREADSHEETML_SHARED_STRINGS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',
82
+ SPREADSHEETML_STYLES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles',
83
+ SPREADSHEETML_DRAWING: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing',
84
+ SPREADSHEETML_CHART: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart',
85
+ CHART_USER_SHAPES: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartUserShapes',
86
+ SPREADSHEETML_COMMENTS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments',
87
+ SPREADSHEETML_PIVOT_TABLE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable',
88
+ SPREADSHEETML_QUERY_TABLE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/queryTable',
89
+ SPREADSHEETML_TABLE: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table',
90
+ SPREADSHEETML_CONNECTIONS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/connections',
91
+ SPREADSHEETML_PIVOT_CACHE_DEFINITION: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition',
92
+ SPREADSHEETML_PIVOT_CACHE_RECORDS: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheRecords',
93
+ SPREADSHEETML_EXTERNAL_LINK: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/externalLink',
94
+ WEB_EXTENSION_TASKPANES: 'http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11',
95
+ WEB_EXTENSION_WEBEXTENSION: 'http://schemas.microsoft.com/office/webextensions/webextension/2010/11',
96
+ XML_EVENTS: 'http://www.w3.org/2001/xml-events',
97
+ XFORMS: 'http://www.w3.org/2002/xforms',
98
+ XML_SCHEMA: 'http://www.w3.org/2001/XMLSchema',
99
+ };
@@ -0,0 +1,50 @@
1
+ import type { Relationship } from '@docx4j/generated-objects-ts/modules/org_docx4j_relationships';
2
+ import { PartName } from '../opc/PartName.mjs';
3
+ import type { RelationshipsPart, AddPartBehaviour } from './RelationshipsPart.mjs';
4
+ import type { OpcPackage } from '../packages/OpcPackage.mjs';
5
+ /** Something that owns a relationships part: a part or the package (docx4j Base). */
6
+ export interface RelationshipSource {
7
+ readonly partName: PartName;
8
+ readonly package: OpcPackage | undefined;
9
+ relationshipsPart: RelationshipsPart | undefined;
10
+ setPartShortcut(part: Part, relationshipType: string): boolean;
11
+ }
12
+ export declare function setRelationshipsPartFactory(factory: (source: RelationshipSource) => RelationshipsPart): void;
13
+ export declare function createRelationshipsPartFor(source: RelationshipSource): RelationshipsPart;
14
+ /**
15
+ * A part (docx4j org.docx4j.openpackaging.parts.Part): a name, a content type, the relationship
16
+ * type it is the target of, and its own relationships part if it has one.
17
+ */
18
+ export declare abstract class Part implements RelationshipSource {
19
+ partName: PartName;
20
+ contentType: string;
21
+ relationshipType: string;
22
+ /** The package this part belongs to; set when the part is added. */
23
+ package: OpcPackage | undefined;
24
+ /** This part's own relationships (`/word/_rels/document.xml.rels`), if any. */
25
+ relationshipsPart: RelationshipsPart | undefined;
26
+ /** The relationships part that first loaded this part. */
27
+ owningRelationshipPart: RelationshipsPart | undefined;
28
+ /** Every relationship that targets this part. */
29
+ readonly sourceRelationships: Relationship[];
30
+ constructor(partName: PartName | string, contentType: string, relationshipType: string);
31
+ /** Whether the zip entry should be deflated (false for already-compressed media). */
32
+ get compress(): boolean;
33
+ /** The first relationship that targets this part. */
34
+ get sourceRelationship(): Relationship | undefined;
35
+ /** This part's relationships part, created on demand when `createIfAbsent`. */
36
+ getRelationshipsPart(createIfAbsent?: boolean): RelationshipsPart | undefined;
37
+ /**
38
+ * Adds a part as a target of this one (docx4j Base.addTargetPart): registers it in the package,
39
+ * its content type in the content type manager, and a relationship in this part's relationships.
40
+ */
41
+ addTargetPart(target: Part, mode?: AddPartBehaviour, proposedRelId?: string): Relationship;
42
+ /** Subclasses keep typed references to well-known targets (styles, numbering, ...); returns true when one was set. */
43
+ setPartShortcut(_part: Part, _relationshipType: string): boolean;
44
+ /** The bytes this part was loaded from, if it came from a container. Undefined for new parts. */
45
+ protected loadSourceBytes(): Promise<Uint8Array | undefined>;
46
+ /** The bytes to write on save. Untouched parts come back from the source container unchanged. */
47
+ abstract getBytes(): Promise<Uint8Array>;
48
+ /** Whether the part carries content of its own (set or unmarshalled) rather than relying on the source container. */
49
+ abstract get isLoaded(): boolean;
50
+ }
@@ -0,0 +1,68 @@
1
+ import { PartName } from '../opc/PartName.mjs';
2
+ import { InvalidFormatException } from '../opc/exceptions.mjs';
3
+ /** Set by the RelationshipsPart module: avoids a runtime import cycle (Part <- XmlPart <- RelationshipsPart). */
4
+ let relationshipsPartFactory;
5
+ export function setRelationshipsPartFactory(factory) {
6
+ relationshipsPartFactory = factory;
7
+ }
8
+ export function createRelationshipsPartFor(source) {
9
+ if (!relationshipsPartFactory)
10
+ throw new Error('RelationshipsPart not initialised');
11
+ return relationshipsPartFactory(source);
12
+ }
13
+ /**
14
+ * A part (docx4j org.docx4j.openpackaging.parts.Part): a name, a content type, the relationship
15
+ * type it is the target of, and its own relationships part if it has one.
16
+ */
17
+ export class Part {
18
+ constructor(partName, contentType, relationshipType) {
19
+ /** Every relationship that targets this part. */
20
+ this.sourceRelationships = [];
21
+ this.partName = PartName.of(partName);
22
+ this.contentType = contentType;
23
+ this.relationshipType = relationshipType;
24
+ }
25
+ /** Whether the zip entry should be deflated (false for already-compressed media). */
26
+ get compress() {
27
+ return true;
28
+ }
29
+ /** The first relationship that targets this part. */
30
+ get sourceRelationship() {
31
+ return this.sourceRelationships[0];
32
+ }
33
+ /** This part's relationships part, created on demand when `createIfAbsent`. */
34
+ getRelationshipsPart(createIfAbsent = false) {
35
+ if (!this.relationshipsPart && createIfAbsent)
36
+ this.relationshipsPart = createRelationshipsPartFor(this);
37
+ return this.relationshipsPart;
38
+ }
39
+ /**
40
+ * Adds a part as a target of this one (docx4j Base.addTargetPart): registers it in the package,
41
+ * its content type in the content type manager, and a relationship in this part's relationships.
42
+ */
43
+ addTargetPart(target, mode, proposedRelId) {
44
+ if (!this.package)
45
+ throw new InvalidFormatException('Package not set; if you are adding part2 to part1, make sure part1 is added first.');
46
+ const rel = this.getRelationshipsPart(true).addPart(target, mode, proposedRelId);
47
+ this.setPartShortcut(target, target.relationshipType);
48
+ return rel;
49
+ }
50
+ /** Subclasses keep typed references to well-known targets (styles, numbering, ...); returns true when one was set. */
51
+ setPartShortcut(_part, _relationshipType) {
52
+ return false;
53
+ }
54
+ /** The bytes this part was loaded from, if it came from a container. Undefined for new parts. */
55
+ async loadSourceBytes() {
56
+ var _a;
57
+ const store = (_a = this.package) === null || _a === void 0 ? void 0 : _a.sourcePartStore;
58
+ if (!store)
59
+ return undefined;
60
+ const name = this.partName.storeName;
61
+ if (store.has(name))
62
+ return store.load(name);
63
+ const decoded = decodeURIComponent(name);
64
+ if (decoded !== name && store.has(decoded))
65
+ return store.load(decoded);
66
+ return undefined;
67
+ }
68
+ }
@@ -0,0 +1,20 @@
1
+ import type { Relationship } from '@docx4j/generated-objects-ts/modules/org_docx4j_relationships';
2
+ import { Part } from './Part.mjs';
3
+ import { PartName } from '../opc/PartName.mjs';
4
+ /** Creates a part for a name and content type. */
5
+ export type PartFactory = (partName: PartName, contentType: string) => Part;
6
+ /**
7
+ * Content type to part class (docx4j ContentTypeManager.newPartForContentType), with a first
8
+ * look at the relationship type for the generic content types (altChunk, embedded package, OLE,
9
+ * custom XML). Unknown XML becomes `DefaultXmlPart`, anything else `BinaryPart`.
10
+ */
11
+ export declare class PartRegistry {
12
+ private readonly byContentType;
13
+ private readonly byRelationshipType;
14
+ register(contentType: string, factory: PartFactory): this;
15
+ /** Consulted before the content type; for relationship types whose parts share a generic content type. */
16
+ registerForRelationship(relationshipType: string, factory: PartFactory): this;
17
+ createPart(partName: PartName, contentType: string | undefined, rel?: Relationship): Part;
18
+ }
19
+ /** docx4j's table. Extend with `register` for content types of your own. */
20
+ export declare const defaultPartRegistry: PartRegistry;
@@ -0,0 +1,142 @@
1
+ import { ContentTypes, IMAGE_CONTENT_TYPES_BY_EXTENSION, isXmlContentType } from '../opc/ContentTypes.mjs';
2
+ import { Namespaces } from './Namespaces.mjs';
3
+ import { BinaryPart, ImagePart, EmbeddedPackagePart, OleObjectBinaryPart, ObfuscatedFontPart, TrueTypeFontPart, AlternativeFormatInputPart } from './BinaryPart.mjs';
4
+ import { DefaultXmlPart, CustomXmlDataStoragePart } from './DefaultXmlPart.mjs';
5
+ import * as wml from './wml/index.mjs';
6
+ import * as dml from './dml/index.mjs';
7
+ import * as pml from './pml/index.mjs';
8
+ import * as sml from './sml/index.mjs';
9
+ import * as docProps from './docProps/index.mjs';
10
+ import * as customXml from './customXml/index.mjs';
11
+ /**
12
+ * Content type to part class (docx4j ContentTypeManager.newPartForContentType), with a first
13
+ * look at the relationship type for the generic content types (altChunk, embedded package, OLE,
14
+ * custom XML). Unknown XML becomes `DefaultXmlPart`, anything else `BinaryPart`.
15
+ */
16
+ export class PartRegistry {
17
+ constructor() {
18
+ this.byContentType = new Map();
19
+ this.byRelationshipType = new Map();
20
+ }
21
+ register(contentType, factory) {
22
+ this.byContentType.set(contentType, factory);
23
+ return this;
24
+ }
25
+ /** Consulted before the content type; for relationship types whose parts share a generic content type. */
26
+ registerForRelationship(relationshipType, factory) {
27
+ this.byRelationshipType.set(relationshipType, factory);
28
+ return this;
29
+ }
30
+ createPart(partName, contentType, rel) {
31
+ var _a;
32
+ const relType = rel === null || rel === void 0 ? void 0 : rel.type;
33
+ if (relType) {
34
+ const byRel = this.byRelationshipType.get(relType);
35
+ if (byRel)
36
+ return byRel(partName, contentType !== null && contentType !== void 0 ? contentType : ContentTypes.APPLICATION_XML);
37
+ }
38
+ if (contentType !== undefined) {
39
+ const factory = this.byContentType.get(contentType);
40
+ if (factory)
41
+ return factory(partName, contentType);
42
+ if (contentType.startsWith('image/'))
43
+ return new ImagePart(partName, contentType);
44
+ if (isXmlContentType(contentType) || partName.extension.toLowerCase() === 'xml') {
45
+ return new DefaultXmlPart(partName, contentType, relType !== null && relType !== void 0 ? relType : '');
46
+ }
47
+ return new BinaryPart(partName, contentType, relType !== null && relType !== void 0 ? relType : '');
48
+ }
49
+ // No content type registered: Word would reject the package; keep the bytes anyway.
50
+ if (relType === Namespaces.IMAGE) {
51
+ return new ImagePart(partName, (_a = IMAGE_CONTENT_TYPES_BY_EXTENSION[partName.extension.toLowerCase()]) !== null && _a !== void 0 ? _a : ContentTypes.OCTET_STREAM);
52
+ }
53
+ if (partName.extension.toLowerCase() === 'xml')
54
+ return new DefaultXmlPart(partName, ContentTypes.APPLICATION_XML, relType !== null && relType !== void 0 ? relType : '');
55
+ return new BinaryPart(partName, ContentTypes.OCTET_STREAM, relType !== null && relType !== void 0 ? relType : '');
56
+ }
57
+ }
58
+ /** docx4j's table. Extend with `register` for content types of your own. */
59
+ export const defaultPartRegistry = new PartRegistry()
60
+ .registerForRelationship(Namespaces.AF, (n, ct) => new AlternativeFormatInputPart(n, ct))
61
+ .registerForRelationship(Namespaces.EMBEDDED_PKG, (n, ct) => new EmbeddedPackagePart(n, ct))
62
+ .registerForRelationship(Namespaces.OLE_OBJECT, (n, ct) => new OleObjectBinaryPart(n, ct))
63
+ .registerForRelationship(Namespaces.CUSTOM_XML_DATA_STORAGE, (n, ct) => new CustomXmlDataStoragePart(n, ct))
64
+ .register(ContentTypes.WORDPROCESSINGML_DOCUMENT, (n, ct) => new wml.MainDocumentPart(n, ct))
65
+ .register(ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED, (n, ct) => new wml.MainDocumentPart(n, ct))
66
+ .register(ContentTypes.WORDPROCESSINGML_TEMPLATE, (n, ct) => new wml.MainDocumentPart(n, ct))
67
+ .register(ContentTypes.WORDPROCESSINGML_TEMPLATE_MACROENABLED, (n, ct) => new wml.MainDocumentPart(n, ct))
68
+ .register(ContentTypes.WORDPROCESSINGML_GLOSSARYDOCUMENT, (n) => new wml.GlossaryDocumentPart(n))
69
+ .register(ContentTypes.WORDPROCESSINGML_STYLES, (n) => new wml.StyleDefinitionsPart(n))
70
+ .register(ContentTypes.WORDPROCESSINGML_NUMBERING, (n) => new wml.NumberingDefinitionsPart(n))
71
+ .register(ContentTypes.WORDPROCESSINGML_FONTTABLE, (n) => new wml.FontTablePart(n))
72
+ .register(ContentTypes.WORDPROCESSINGML_SETTINGS, (n) => new wml.DocumentSettingsPart(n))
73
+ .register(ContentTypes.WORDPROCESSINGML_WEBSETTINGS, (n) => new wml.WebSettingsPart(n))
74
+ .register(ContentTypes.WORDPROCESSINGML_HEADER, (n) => new wml.HeaderPart(n))
75
+ .register(ContentTypes.WORDPROCESSINGML_FOOTER, (n) => new wml.FooterPart(n))
76
+ .register(ContentTypes.WORDPROCESSINGML_FOOTNOTES, (n) => new wml.FootnotesPart(n))
77
+ .register(ContentTypes.WORDPROCESSINGML_ENDNOTES, (n) => new wml.EndnotesPart(n))
78
+ .register(ContentTypes.WORDPROCESSINGML_COMMENTS, (n) => new wml.CommentsPart(n))
79
+ .register(ContentTypes.WORDPROCESSINGML_COMMENTS_EXTENDED, (n) => new wml.CommentsExtendedPart(n))
80
+ .register(ContentTypes.WORDPROCESSINGML_COMMENTS_IDS, (n) => new wml.CommentsIdsPart(n))
81
+ .register(ContentTypes.WORDPROCESSINGML_PEOPLE, (n) => new wml.PeoplePart(n))
82
+ .register(ContentTypes.MS_WORD_KEYMAP, (n) => new wml.KeyMapCustomizationsPart(n))
83
+ .register(ContentTypes.OFFICEDOCUMENT_VBA_DATA, (n) => new wml.VbaDataPart(n))
84
+ .register(ContentTypes.VML_DRAWING, (n) => new wml.VMLPart(n))
85
+ .register(ContentTypes.OFFICEDOCUMENT_THEME, (n) => new dml.ThemePart(n))
86
+ .register(ContentTypes.OFFICEDOCUMENT_THEME_OVERRIDE, (n) => new dml.ThemeOverridePart(n))
87
+ .register(ContentTypes.DRAWINGML_CHART, (n) => new dml.ChartPart(n))
88
+ .register(ContentTypes.DRAWINGML_CHART_SHAPES, (n) => new dml.ChartShapePart(n))
89
+ .register(ContentTypes.DRAWINGML_DRAWING, (n) => new dml.DrawingPart(n))
90
+ .register(ContentTypes.DRAWINGML_DIAGRAM_DATA, (n) => new dml.DiagramDataPart(n))
91
+ .register(ContentTypes.DRAWINGML_DIAGRAM_LAYOUT, (n) => new dml.DiagramLayoutPart(n))
92
+ .register(ContentTypes.DRAWINGML_DIAGRAM_LAYOUT_HEADER, (n) => new dml.DiagramLayoutHeaderPart(n))
93
+ .register(ContentTypes.DRAWINGML_DIAGRAM_STYLE, (n) => new dml.DiagramStylePart(n))
94
+ .register(ContentTypes.DRAWINGML_DIAGRAM_COLORS, (n) => new dml.DiagramColorsPart(n))
95
+ .register(ContentTypes.DRAWINGML_DIAGRAM_DRAWING, (n) => new dml.DiagramDrawingPart(n))
96
+ .register(ContentTypes.CHART_STYLE, (n) => new dml.ChartStylePart(n))
97
+ .register(ContentTypes.CHART_COLOR_STYLE, (n) => new dml.ChartColorStylePart(n))
98
+ .register(ContentTypes.CHART_EX, (n) => new dml.ChartExSpacePart(n))
99
+ .register(ContentTypes.PACKAGE_COREPROPERTIES, (n) => new docProps.DocPropsCorePart(n))
100
+ .register(ContentTypes.OFFICEDOCUMENT_EXTENDEDPROPERTIES, (n) => new docProps.DocPropsExtendedPart(n))
101
+ .register(ContentTypes.OFFICEDOCUMENT_CUSTOMPROPERTIES, (n) => new docProps.DocPropsCustomPart(n))
102
+ .register(ContentTypes.OFFICEDOCUMENT_CUSTOMXML_DATASTORAGEPROPERTIES, (n) => new customXml.CustomXmlDataStoragePropertiesPart(n))
103
+ .register(ContentTypes.OFFICEDOCUMENT_FONT, (n) => new ObfuscatedFontPart(n))
104
+ .register(ContentTypes.TRUETYPE_FONT, (n) => new TrueTypeFontPart(n))
105
+ .register(ContentTypes.OFFICEDOCUMENT_OLE_OBJECT, (n, ct) => new OleObjectBinaryPart(n, ct))
106
+ .register(ContentTypes.OFFICEDOCUMENT_ACTIVEX_OBJECT, (n, ct) => new OleObjectBinaryPart(n, ct))
107
+ .register(ContentTypes.PRESENTATIONML_MAIN, (n, ct) => new pml.MainPresentationPart(n, ct))
108
+ .register(ContentTypes.PRESENTATIONML_TEMPLATE, (n, ct) => new pml.MainPresentationPart(n, ct))
109
+ .register(ContentTypes.PRESENTATIONML_MACROENABLED, (n, ct) => new pml.MainPresentationPart(n, ct))
110
+ .register(ContentTypes.PRESENTATIONML_TEMPLATE_MACROENABLED, (n, ct) => new pml.MainPresentationPart(n, ct))
111
+ .register(ContentTypes.PRESENTATIONML_SLIDESHOW, (n, ct) => new pml.MainPresentationPart(n, ct))
112
+ .register(ContentTypes.PRESENTATIONML_SLIDE, (n) => new pml.SlidePart(n))
113
+ .register(ContentTypes.PRESENTATIONML_SLIDE_LAYOUT, (n) => new pml.SlideLayoutPart(n))
114
+ .register(ContentTypes.PRESENTATIONML_SLIDE_MASTER, (n) => new pml.SlideMasterPart(n))
115
+ .register(ContentTypes.PRESENTATIONML_NOTES_SLIDE, (n) => new pml.NotesSlidePart(n))
116
+ .register(ContentTypes.PRESENTATIONML_NOTES_MASTER, (n) => new pml.NotesMasterPart(n))
117
+ .register(ContentTypes.PRESENTATIONML_HANDOUT_MASTER, (n) => new pml.HandoutMasterPart(n))
118
+ .register(ContentTypes.PRESENTATIONML_PRES_PROPS, (n) => new pml.PresentationPropertiesPart(n))
119
+ .register(ContentTypes.PRESENTATIONML_VIEW_PROPS, (n) => new pml.ViewPropertiesPart(n))
120
+ .register(ContentTypes.PRESENTATIONML_TABLE_STYLES, (n) => new pml.TableStylesPart(n))
121
+ .register(ContentTypes.PRESENTATIONML_COMMENTS, (n) => new pml.PresentationCommentsPart(n))
122
+ .register(ContentTypes.PRESENTATIONML_COMMENT_AUTHORS, (n) => new pml.CommentAuthorsPart(n))
123
+ .register(ContentTypes.PRESENTATIONML_TAGS, (n) => new pml.TagsPart(n))
124
+ .register(ContentTypes.PRESENTATIONML_FONT_DATA, (n) => new pml.FontDataPart(n))
125
+ .register(ContentTypes.SPREADSHEETML_WORKBOOK, (n, ct) => new sml.WorkbookPart(n, ct))
126
+ .register(ContentTypes.SPREADSHEETML_WORKBOOK_MACROENABLED, (n, ct) => new sml.WorkbookPart(n, ct))
127
+ .register(ContentTypes.SPREADSHEETML_TEMPLATE, (n, ct) => new sml.WorkbookPart(n, ct))
128
+ .register(ContentTypes.SPREADSHEETML_TEMPLATE_MACROENABLED, (n, ct) => new sml.WorkbookPart(n, ct))
129
+ .register(ContentTypes.SPREADSHEETML_WORKSHEET, (n) => new sml.WorksheetPart(n))
130
+ .register(ContentTypes.SPREADSHEETML_CHARTSHEET, (n) => new sml.ChartsheetPart(n))
131
+ .register(ContentTypes.SPREADSHEETML_SHARED_STRINGS, (n) => new sml.SharedStringsPart(n))
132
+ .register(ContentTypes.SPREADSHEETML_STYLES, (n) => new sml.StylesPart(n))
133
+ .register(ContentTypes.SPREADSHEETML_CALC_CHAIN, (n) => new sml.CalcChainPart(n))
134
+ .register(ContentTypes.SPREADSHEETML_COMMENTS, (n) => new sml.SpreadsheetCommentsPart(n))
135
+ .register(ContentTypes.SPREADSHEETML_TABLE, (n) => new sml.TablePart(n))
136
+ .register(ContentTypes.SPREADSHEETML_PIVOT_TABLE, (n) => new sml.PivotTablePart(n))
137
+ .register(ContentTypes.SPREADSHEETML_PIVOT_CACHE_DEFINITION, (n) => new sml.PivotCacheDefinitionPart(n))
138
+ .register(ContentTypes.SPREADSHEETML_PIVOT_CACHE_RECORDS, (n) => new sml.PivotCacheRecordsPart(n))
139
+ .register(ContentTypes.SPREADSHEETML_QUERY_TABLE, (n) => new sml.QueryTablePart(n))
140
+ .register(ContentTypes.SPREADSHEETML_CONNECTIONS, (n) => new sml.ConnectionsPart(n))
141
+ .register(ContentTypes.SPREADSHEETML_EXTERNAL_LINK, (n) => new sml.ExternalLinkPart(n))
142
+ .register(ContentTypes.SPREADSHEETML_PRINTER_SETTINGS, (n) => new sml.PrinterSettingsPart(n));
@@ -0,0 +1,13 @@
1
+ import type { Part } from './Part.mjs';
2
+ import { PartName } from '../opc/PartName.mjs';
3
+ /** The parts of a package by name (docx4j Parts), case-insensitive. */
4
+ export declare class Parts implements Iterable<Part> {
5
+ private readonly map;
6
+ put(part: Part): void;
7
+ get(partName: PartName | string): Part | undefined;
8
+ has(partName: PartName | string): boolean;
9
+ remove(partName: PartName | string): boolean;
10
+ get size(): number;
11
+ values(): IterableIterator<Part>;
12
+ [Symbol.iterator](): IterableIterator<Part>;
13
+ }
@@ -0,0 +1,28 @@
1
+ import { PartName } from '../opc/PartName.mjs';
2
+ /** The parts of a package by name (docx4j Parts), case-insensitive. */
3
+ export class Parts {
4
+ constructor() {
5
+ this.map = new Map();
6
+ }
7
+ put(part) {
8
+ this.map.set(part.partName.key, part);
9
+ }
10
+ get(partName) {
11
+ return this.map.get(PartName.of(partName).key);
12
+ }
13
+ has(partName) {
14
+ return this.map.has(PartName.of(partName).key);
15
+ }
16
+ remove(partName) {
17
+ return this.map.delete(PartName.of(partName).key);
18
+ }
19
+ get size() {
20
+ return this.map.size;
21
+ }
22
+ values() {
23
+ return this.map.values();
24
+ }
25
+ [Symbol.iterator]() {
26
+ return this.map.values();
27
+ }
28
+ }
@@ -0,0 +1,66 @@
1
+ import type { Relationships, Relationship } from '@docx4j/generated-objects-ts/modules/org_docx4j_relationships';
2
+ import { XmlPart } from './XmlPart.mjs';
3
+ import { Part, type RelationshipSource } from './Part.mjs';
4
+ import { PartName } from '../opc/PartName.mjs';
5
+ /** What `addPart` does when a part of the same name is already in the package (docx4j AddPartBehaviour). */
6
+ export type AddPartBehaviour = 'OVERWRITE_IF_NAME_EXISTS' | 'REUSE_EXISTING' | 'RENAME_IF_NAME_EXISTS';
7
+ export declare const RELATIONSHIPS_ROOT: {
8
+ namespaceURI: "http://schemas.openxmlformats.org/package/2006/relationships";
9
+ localPart: string;
10
+ };
11
+ /**
12
+ * A relationships part (docx4j org.docx4j.openpackaging.parts.relationships.RelationshipsPart):
13
+ * `/_rels/.rels` for the package, `/word/_rels/document.xml.rels` for a part. Always unmarshalled
14
+ * (load walks it), hence always re-marshalled on save.
15
+ */
16
+ export declare class RelationshipsPart extends XmlPart<Relationships> {
17
+ /** The part (or package) whose relationships these are. */
18
+ sourceP: RelationshipSource | undefined;
19
+ private nextId;
20
+ constructor(source?: RelationshipSource, partName?: PartName | string);
21
+ /** The package relationships part, `/_rels/.rels`. */
22
+ static createPackageRels(): RelationshipsPart;
23
+ /** A part's own, empty, relationships part. */
24
+ static createRelationshipsPartForPart(source: RelationshipSource): RelationshipsPart;
25
+ /** The name of the part these relationships belong to; '/' for the package. */
26
+ get sourceName(): PartName;
27
+ get isPackageRelationshipPart(): boolean;
28
+ /** The relationships (docx4j getRelationships()); unmarshalled parts only. */
29
+ get relationships(): Relationships;
30
+ /** The list of relationships, the live array. */
31
+ get list(): Relationship[];
32
+ get size(): number;
33
+ getRelationshipById(id: string): Relationship | undefined;
34
+ getRelationshipByType(type: string): Relationship | undefined;
35
+ getRelationshipsByType(type: string): Relationship[];
36
+ /** The part a relationship targets; undefined for external targets and parts not in the package. */
37
+ getPart(rel: Relationship | string): Part | undefined;
38
+ /** The part name a relationship's target resolves to (internal targets only). */
39
+ resolveTarget(rel: Relationship): PartName;
40
+ /** The (first) relationship targeting a part. */
41
+ getRel(partName: PartName | string): Relationship | undefined;
42
+ isATarget(partName: PartName | string): boolean;
43
+ /** The next free `rIdN`. */
44
+ getNextId(): string;
45
+ /** Adds a relationship; allocates an id when it has none or its id is taken. Returns the id. */
46
+ addRelationship(rel: Relationship): string;
47
+ /** An external relationship (a hyperlink, a linked image). */
48
+ addExternalRelationship(type: string, target: string, relId?: string): Relationship;
49
+ /**
50
+ * Adds a part as a target (docx4j addPart): registers it in the package and its content type,
51
+ * writes a relationship whose target is relative to the source part, and returns that
52
+ * relationship. `mode` says what to do when the name is taken (default OVERWRITE_IF_NAME_EXISTS).
53
+ */
54
+ addPart(part: Part, mode?: AddPartBehaviour, relId?: string): Relationship;
55
+ /** Links a part into the package as the target of a relationship of this part (docx4j loadPart). */
56
+ loadPart(part: Part, sourceRelationship: Relationship): void;
57
+ /** Removes the relationship to a part, the part, and (recursively) the parts only it related to. Returns what was removed. */
58
+ removePart(partName: PartName | string): PartName[];
59
+ /** Removes every part these relationships target (docx4j removeParts), recursively. */
60
+ removeParts(): PartName[];
61
+ /** Removes a relationship, by object or by the part it targets. */
62
+ removeRelationship(rel: Relationship | PartName | string): void;
63
+ removeRelationshipsByType(type: string): void;
64
+ private newPartName;
65
+ }
66
+ export declare function isExternal(rel: Relationship): boolean;