@docx4j/core-ts 0.3.2 → 0.5.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 (72) hide show
  1. package/README.md +8 -3
  2. package/dist/html/convert.d.mts +116 -0
  3. package/dist/html/convert.mjs +565 -0
  4. package/dist/html/elements.d.mts +19 -0
  5. package/dist/html/elements.mjs +182 -0
  6. package/dist/html/index.d.mts +2 -0
  7. package/dist/html/index.mjs +4 -0
  8. package/dist/model/content/Body.d.mts +13 -1
  9. package/dist/model/content/Body.mjs +97 -19
  10. package/dist/model/content/Comment.mjs +7 -0
  11. package/dist/model/content/InlinePicture.d.mts +89 -10
  12. package/dist/model/content/InlinePicture.mjs +245 -35
  13. package/dist/model/content/List.mjs +10 -1
  14. package/dist/model/content/Paragraph.d.mts +28 -5
  15. package/dist/model/content/Paragraph.mjs +77 -37
  16. package/dist/model/content/Range.d.mts +18 -2
  17. package/dist/model/content/Range.mjs +194 -64
  18. package/dist/model/content/Table.d.mts +38 -0
  19. package/dist/model/content/Table.mjs +80 -2
  20. package/dist/model/content/TrackedChange.d.mts +129 -3
  21. package/dist/model/content/TrackedChange.mjs +577 -12
  22. package/dist/model/content/binder.d.mts +2 -1
  23. package/dist/model/content/binder.mjs +48 -1
  24. package/dist/model/content/index.d.mts +4 -3
  25. package/dist/model/content/index.mjs +3 -2
  26. package/dist/model/content/relationships.d.mts +30 -0
  27. package/dist/model/content/relationships.mjs +133 -0
  28. package/dist/model/content/stylesFacade.d.mts +4 -2
  29. package/dist/model/content/stylesFacade.mjs +20 -6
  30. package/dist/model/content/tableColumns.d.mts +48 -0
  31. package/dist/model/content/tableColumns.mjs +484 -0
  32. package/dist/model/content/tree.d.mts +52 -2
  33. package/dist/model/content/tree.mjs +48 -3
  34. package/dist/model/customxml/CustomXmlPartCollection.d.mts +6 -1
  35. package/dist/model/customxml/CustomXmlPartCollection.mjs +19 -3
  36. package/dist/model/customxml/bindings.d.mts +5 -2
  37. package/dist/model/customxml/bindings.mjs +21 -6
  38. package/dist/model/customxml/index.d.mts +3 -0
  39. package/dist/model/customxml/index.mjs +3 -0
  40. package/dist/model/customxml/opendope.d.mts +32 -0
  41. package/dist/model/customxml/opendope.mjs +56 -0
  42. package/dist/model/customxml/pictures.d.mts +57 -0
  43. package/dist/model/customxml/pictures.mjs +192 -0
  44. package/dist/model/customxml/xhtml.d.mts +42 -0
  45. package/dist/model/customxml/xhtml.mjs +162 -0
  46. package/dist/model/fonts/families.generated.mjs +2 -2
  47. package/dist/model/fonts/registry.mjs +7 -1
  48. package/dist/model/fonts/substitutions.generated.mjs +2 -2
  49. package/dist/model/fonts/themes.generated.mjs +1 -1
  50. package/dist/model/listnumbering/definitions.mjs +18 -0
  51. package/dist/model/properties/PropertyResolver.d.mts +27 -6
  52. package/dist/model/properties/PropertyResolver.mjs +83 -16
  53. package/dist/model/properties/catalogue.d.mts +15 -1
  54. package/dist/model/properties/catalogue.mjs +80 -27
  55. package/dist/model/properties/table.d.mts +16 -2
  56. package/dist/model/properties/table.mjs +13 -3
  57. package/dist/opc/Load.d.mts +9 -2
  58. package/dist/opc/index.d.mts +2 -2
  59. package/dist/opc/index.mjs +2 -2
  60. package/dist/opc/mce/preprocessor.d.mts +62 -6
  61. package/dist/opc/mce/preprocessor.mjs +142 -35
  62. package/dist/opc/mce/understood.d.mts +10 -0
  63. package/dist/opc/mce/understood.mjs +25 -3
  64. package/dist/packages/OpcPackage.d.mts +7 -0
  65. package/dist/packages/OpcPackage.mjs +15 -3
  66. package/dist/packages/WordprocessingMLPackage.d.mts +35 -2
  67. package/dist/packages/WordprocessingMLPackage.mjs +99 -2
  68. package/dist/parts/XmlPart.d.mts +26 -5
  69. package/dist/parts/XmlPart.mjs +67 -18
  70. package/dist/parts/wml/knownStyles.d.mts +1 -0
  71. package/dist/parts/wml/knownStyles.mjs +2233 -0
  72. package/package.json +7 -2
package/README.md CHANGED
@@ -43,10 +43,15 @@ const ooxml = await pkg.saveFlatOpc(); // pkg:package, for insertOo
43
43
  ```
44
44
 
45
45
  A part that is never touched is written back byte for byte; `getContents()` (or a view over
46
- it) marks a part for re-marshalling. `mc:AlternateContent` is resolved when a part is
47
- unmarshalled, as Word does on open (`{ mcePreprocess: false }` to keep it). Subpaths
46
+ it) marks a part for re-marshalling. `mc:AlternateContent` is kept with every branch, as docx4j
47
+ keeps it: the content API reads the branch Word would (the first `mc:Choice` whose namespaces are
48
+ understood, else the `mc:Fallback`), an edit lands in every branch, and a save writes them all
49
+ (`{ mcePreprocess: true }` resolves the element when a part is unmarshalled instead, as Word does on
50
+ open). Subpaths
48
51
  `@docx4j/core-ts/opc`, `/parts`, `/packages` and `/model` give the layers separately,
49
- `/office-js` the `Word` shim (below), and `/node` the one Node-only piece (the unzipped-directory
52
+ `/office-js` the `Word` shim (below), `/html` HTML to WordprocessingML (a converter to an
53
+ intermediate form and a builder from it, CR-005 section 8; the HTML parser is yours, a browser's
54
+ `DOMParser` by default), and `/node` the one Node-only piece (the unzipped-directory
50
55
  container; nothing else in the package imports a `node:` builtin, so a browser or add-in bundle
51
56
  never sees one).
52
57
 
@@ -0,0 +1,116 @@
1
+ /** The '#RRGGBB' of one of Word's sixteen highlight names, or undefined for anything else (`mso-highlight` is read through it). */
2
+ export declare function highlightHexOf(name: string): string | undefined;
3
+ /** The highlight name for one of the sixteen colours, by its '#RRGGBB'. */
4
+ export declare function highlightNameOf(hex: string): string | undefined;
5
+ /** A web or mail address a link may keep (`http`, `https`, `mailto`), trimmed; anything else undefined. */
6
+ export declare function webAddress(url: string): string | undefined;
7
+ export interface PasteRun {
8
+ text: string;
9
+ bold?: true;
10
+ italic?: true;
11
+ underline?: true;
12
+ strike?: true;
13
+ vertAlign?: 'superscript' | 'subscript';
14
+ /** The first family of `font-family`, when it is a name and not a generic. */
15
+ fontName?: string;
16
+ /** Points. */
17
+ fontSize?: number;
18
+ /** '#RRGGBB', or 'auto' for `windowtext`. */
19
+ color?: string;
20
+ /** '#RRGGBB' of one of Word's highlight names (`mso-highlight`, else a `background` naming one). */
21
+ highlight?: string;
22
+ /** A character style id of the document (Markdown's inline code, `HTMLCode`). */
23
+ style?: string;
24
+ /** A link's address (Markdown's links): a relationship made before the transaction, the text in Word's look. */
25
+ link?: string;
26
+ }
27
+ export type PasteInline = PasteRun | {
28
+ br: true;
29
+ } | {
30
+ tab: true;
31
+ };
32
+ export interface PasteList {
33
+ /** Word's `lfoN`, or the list element's own key: one definition per key. */
34
+ key: string;
35
+ level: number;
36
+ bullet: boolean;
37
+ }
38
+ export interface PasteParagraph {
39
+ kind: 'paragraph';
40
+ /** A style id of the document, or null for the default. */
41
+ style: string | null;
42
+ list?: PasteList;
43
+ /** `w:jc` from `text-align` or the `align` attribute. */
44
+ jc?: string;
45
+ /** Twips from `margin-left`, `margin-right` and `text-indent` (a negative one a hanging indent). */
46
+ ind?: {
47
+ start?: number;
48
+ end?: number;
49
+ firstLine?: number;
50
+ hanging?: number;
51
+ };
52
+ /** Twips from `margin-top`; `margin-bottom` and `line-height` are dropped and counted. */
53
+ spacing?: {
54
+ before: number;
55
+ };
56
+ inlines: PasteInline[];
57
+ }
58
+ export interface PasteCell {
59
+ blocks: PasteBlock[];
60
+ colspan: number;
61
+ rowspan: number;
62
+ /** Twips, when the cell said. */
63
+ width?: number;
64
+ }
65
+ export interface PasteTable {
66
+ kind: 'table';
67
+ rows: PasteCell[][];
68
+ /** The document's table grid style, when it has one. */
69
+ style: string | null;
70
+ /** The first row repeated at the top of each page (`w:tblHeader`): a Markdown table's header row. */
71
+ headerRow?: boolean;
72
+ }
73
+ export type PasteBlock = PasteParagraph | PasteTable;
74
+ export interface PasteReport {
75
+ paragraphs: number;
76
+ lists: number;
77
+ tables: number;
78
+ /** What was dropped, by kind, with how many times. */
79
+ dropped: Record<string, number>;
80
+ /** Built-in styles the paste names that the document lacked: a caller splices them in from the defaults (`styles.ensure`) before building, else the paragraphs stay plain. */
81
+ stylesWanted: string[];
82
+ }
83
+ export interface PasteResult {
84
+ blocks: PasteBlock[];
85
+ report: PasteReport;
86
+ }
87
+ /** What the converter asks of the document: its styles, by id and by name. */
88
+ export interface StyleLookup {
89
+ /** The style id for a name (`heading 1`, `Title`), case-insensitively, or undefined. */
90
+ idFor(name: string): string | undefined;
91
+ hasId(id: string): boolean;
92
+ }
93
+ /** The lookup over the document's paragraph and character styles, plus the table style ids the caller found (the styles list carries no table styles). */
94
+ /** A style's id and name, as a document's styles part lists them. */
95
+ export interface StyleNaming {
96
+ id: string;
97
+ name: string;
98
+ }
99
+ export declare function styleLookupOf(entries: readonly StyleNaming[], tableStyleIds?: readonly string[]): StyleLookup;
100
+ /** Word's `CF_HTML` header (`Version:`, `StartHTML:` and the rest) precedes `<html` in a saved capture; a browser hands the markup alone. */
101
+ export declare function clipboardMarkup(text: string): string;
102
+ /**
103
+ * True when the HTML is a terminal's screen (ED-005 section 12.67): inline content only, every
104
+ * piece of text in a monospace font, as Konsole's "Copy text as HTML" writes it (a span in
105
+ * `font-family:monospace` holding a coloured span per run and a `<br>` per line,
106
+ * `fixtures/paste/terminal/`). Its colours and font are the terminal's theme, not content, and the
107
+ * converter would make a paragraph of each span, so the paste takes the plain text instead.
108
+ */
109
+ export declare function isTerminalHtml(html: string, options?: {
110
+ parser?: (html: string) => Document;
111
+ }): boolean;
112
+ /** Convert clipboard HTML to the intermediate form, keeping what the outline names and counting the rest. */
113
+ export declare function convertHtml(html: string, lookup: StyleLookup, options?: {
114
+ parser?: (html: string) => Document;
115
+ }): PasteResult;
116
+ /** The list definitions a paste needs: a `w:numId` per list key. */