@a3s-lab/office 0.1.0 → 0.2.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/README.md +101 -24
- package/dist/0~2582.js +485 -0
- package/dist/0~4595.js +14 -7
- package/dist/0~4750.js +939 -0
- package/dist/{0~work-document-paragraph-formatting.js → 0~5861.js} +174 -3
- package/dist/0~7048.js +8 -6
- package/dist/0~9512.js +7 -4
- package/dist/0~document-editor.js +3147 -531
- package/dist/0~markdown-editor.js +26 -1
- package/dist/0~presentation-editor.js +68 -12
- package/dist/0~spreadsheet-editor.js +37 -17
- package/dist/0~work-document-extensions.js +588 -13
- package/dist/0~work-document-model-codec.js +1 -1
- package/dist/0~work-docx-bibliography.js +1 -1
- package/dist/0~work-docx-export.js +116 -55
- package/dist/0~work-docx-import.js +766 -107
- package/dist/0~work-office-diagnostics.js +2 -2
- package/dist/{4704.js → 2881.js} +162 -71
- package/dist/4104.js +2 -62
- package/dist/internal/features/work/editors/document-comment-window.d.ts +37 -0
- package/dist/internal/features/work/editors/document-navigation-panel.d.ts +3 -1
- package/dist/internal/features/work/editors/document-navigation-window.d.ts +64 -0
- package/dist/internal/features/work/editors/document-outline-navigation.d.ts +11 -0
- package/dist/internal/features/work/editors/document-page-navigation.d.ts +11 -1
- package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +31 -0
- package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +28 -0
- package/dist/internal/features/work/editors/document-picture-properties-dialog.d.ts +4 -0
- package/dist/internal/features/work/editors/document-search-navigation.d.ts +12 -0
- package/dist/internal/features/work/editors/document-table-margins-popover.d.ts +4 -0
- package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +51 -0
- package/dist/internal/features/work/editors/document-table-properties-dialog-sections.d.ts +19 -0
- package/dist/internal/features/work/editors/document-table-properties-dialog.d.ts +8 -0
- package/dist/internal/features/work/editors/office-task-pane.d.ts +1 -1
- package/dist/internal/features/work/editors/presentation-chart-panel.d.ts +2 -1
- package/dist/internal/features/work/editors/presentation-comments-panel.d.ts +2 -1
- package/dist/internal/features/work/editors/spreadsheet-workbook-panel.d.ts +2 -1
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -0
- package/dist/internal/features/work/editors/use-presentation-review-commands.d.ts +1 -1
- package/dist/internal/features/work/work-document-image-layout.d.ts +11 -0
- package/dist/internal/features/work/work-document-page-capture.d.ts +15 -0
- package/dist/internal/features/work/work-document-paragraph-formatting.d.ts +4 -0
- package/dist/internal/features/work/work-document-section.d.ts +3 -1
- package/dist/internal/features/work/work-document-table-borders.d.ts +20 -0
- package/dist/internal/features/work/work-document-table-cell-formatting.d.ts +8 -5
- package/dist/internal/features/work/work-document-table-geometry.d.ts +41 -0
- package/dist/internal/features/work/work-document-table-property-changes.d.ts +25 -0
- package/dist/internal/features/work/work-document-table-sizing.d.ts +15 -2
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +11 -0
- package/dist/internal/features/work/work-docx-document-layout.d.ts +2 -0
- package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +2 -1
- package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +2 -1
- package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +2 -1
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +2 -1
- package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +3 -2
- package/dist/internal/features/work/work-docx-paragraph-styles.d.ts +2 -2
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +8 -1
- package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +2 -1
- package/dist/internal/features/work/work-docx-table-cell-export.d.ts +1 -1
- package/dist/internal/features/work/work-docx-table-cell-import.d.ts +14 -4
- package/dist/internal/features/work/work-docx-table-sizing-export.d.ts +1 -1
- package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +4 -3
- package/dist/internal/features/work/work-docx-table-styles.d.ts +22 -0
- package/dist/internal/features/work/work-types.d.ts +6 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +1288 -233
- package/docs/{browser-editor-architecture.md → latest/en/browser-editor-architecture.md} +144 -35
- package/package.json +9 -5
- package/dist/0~6552.js +0 -787
- package/dist/0~8155.js +0 -299
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import jszip from "jszip";
|
|
2
|
+
import { documentImageLayoutFromElement, normalizeTableColor, normalizeDocumentTableBorderWidth, documentTableCellMarginOverridesFromElement, documentTableBordersFromElement, documentTableGeometryFromElement, normalizeDocumentTabStops, normalizeDocumentTableBorderStyle } from "./0~4750.js";
|
|
3
|
+
import { normalizeDocumentTableRowHeightRule, normalizeDocumentTableVerticalAlign } from "./0~2582.js";
|
|
4
|
+
import { documentCitationTags, documentNoteKind, documentSections, documentCaptionLabel, documentCaptionKind, collectDocumentNotes, documentNoteKey, normalizeDocumentPageChrome, normalizeDocumentColumns, documentCitationInstruction, docxDocumentFieldKind } from "./2881.js";
|
|
5
|
+
import { parseXml, descendants, directChildren } from "./8715.js";
|
|
4
6
|
import { patchDocxBibliography } from "./0~work-docx-bibliography.js";
|
|
5
7
|
import { patchDocxPageColor } from "./0~work-docx-page-color.js";
|
|
8
|
+
const TWIPS_PER_PIXEL = 15;
|
|
6
9
|
function documentTableCellDocxOptions(cell, docx) {
|
|
7
10
|
const backgroundColor = normalizeTableColor(cell.dataset.officeCellFill || cell.style.backgroundColor);
|
|
8
11
|
const verticalAlign = normalizeDocumentTableVerticalAlign(cell.dataset.officeCellVerticalAlign || cell.style.verticalAlign);
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
} : null;
|
|
12
|
+
const legacyBorderStyle = normalizeDocumentTableBorderStyle(cell.dataset.officeCellBorderStyle || cell.style.borderStyle);
|
|
13
|
+
const fallbackBorder = {
|
|
14
|
+
color: normalizeTableColor(cell.dataset.officeCellBorderColor || cell.style.borderColor) ?? '#cfd5df',
|
|
15
|
+
style: legacyBorderStyle ?? 'solid',
|
|
16
|
+
width: 'none' === legacyBorderStyle ? 0 : normalizeDocumentTableBorderWidth(cell.dataset.officeCellBorderWidth || cell.style.borderWidth) ?? 1
|
|
17
|
+
};
|
|
18
|
+
const borders = hasDocumentTableBorderPresentation(cell) ? documentTableBordersFromElement(cell, fallbackBorder) : null;
|
|
19
|
+
const margins = documentTableCellMarginOverridesFromElement(cell);
|
|
19
20
|
return {
|
|
20
21
|
...backgroundColor ? {
|
|
21
22
|
shading: {
|
|
@@ -26,16 +27,37 @@ function documentTableCellDocxOptions(cell, docx) {
|
|
|
26
27
|
...verticalAlign ? {
|
|
27
28
|
verticalAlign: 'middle' === verticalAlign ? docx.VerticalAlignTable.CENTER : 'bottom' === verticalAlign ? docx.VerticalAlignTable.BOTTOM : docx.VerticalAlignTable.TOP
|
|
28
29
|
} : {},
|
|
29
|
-
...
|
|
30
|
+
...borders ? {
|
|
30
31
|
borders: {
|
|
31
|
-
top:
|
|
32
|
-
right:
|
|
33
|
-
bottom:
|
|
34
|
-
left:
|
|
32
|
+
top: documentTableCellDocxBorder(borders.top, docx),
|
|
33
|
+
right: documentTableCellDocxBorder(borders.right, docx),
|
|
34
|
+
bottom: documentTableCellDocxBorder(borders.bottom, docx),
|
|
35
|
+
left: documentTableCellDocxBorder(borders.left, docx)
|
|
35
36
|
}
|
|
37
|
+
} : {},
|
|
38
|
+
...margins ? {
|
|
39
|
+
margins: Object.fromEntries(Object.entries(margins).map(([side, value])=>[
|
|
40
|
+
side,
|
|
41
|
+
pixelsToTwips(value)
|
|
42
|
+
]))
|
|
36
43
|
} : {}
|
|
37
44
|
};
|
|
38
45
|
}
|
|
46
|
+
function pixelsToTwips(pixels) {
|
|
47
|
+
return Math.max(0, Math.round(pixels * TWIPS_PER_PIXEL));
|
|
48
|
+
}
|
|
49
|
+
function documentTableCellDocxBorder(border, docx) {
|
|
50
|
+
return {
|
|
51
|
+
style: docxBorderStyle(border.style, docx),
|
|
52
|
+
...'none' === border.style || 0 === border.width ? {} : {
|
|
53
|
+
color: docxColor(border.color),
|
|
54
|
+
size: Math.max(1, Math.round(6 * border.width))
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function hasDocumentTableBorderPresentation(cell) {
|
|
59
|
+
return Boolean(Object.keys(cell.dataset).some((key)=>key.startsWith('officeCellBorder')) || cell.style.borderStyle || cell.style.borderTopStyle || cell.style.borderRightStyle || cell.style.borderBottomStyle || cell.style.borderLeftStyle);
|
|
60
|
+
}
|
|
39
61
|
function docxBorderStyle(style, docx) {
|
|
40
62
|
if ('dashed' === style) return docx.BorderStyle.DASHED;
|
|
41
63
|
if ('dotted' === style) return docx.BorderStyle.DOTTED;
|
|
@@ -46,31 +68,38 @@ function docxBorderStyle(style, docx) {
|
|
|
46
68
|
function docxColor(color) {
|
|
47
69
|
return color.replace(/^#/, '').toUpperCase();
|
|
48
70
|
}
|
|
49
|
-
const
|
|
71
|
+
const work_docx_table_sizing_export_TWIPS_PER_PIXEL = 15;
|
|
50
72
|
function documentTableSizingDocxOptions(table, docx) {
|
|
51
|
-
const
|
|
73
|
+
const geometry = documentTableGeometryFromElement(table);
|
|
52
74
|
const pixelWidths = documentTableColumnWidths(table);
|
|
53
|
-
const columnWidths = pixelWidths?.map(
|
|
54
|
-
if ('contents' === mode) return {
|
|
55
|
-
layout: docx.TableLayoutType.AUTOFIT,
|
|
56
|
-
width: {
|
|
57
|
-
size: 0,
|
|
58
|
-
type: docx.WidthType.AUTO
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
if ('fixed' === mode && columnWidths?.length) return {
|
|
62
|
-
columnWidths,
|
|
63
|
-
layout: docx.TableLayoutType.FIXED,
|
|
64
|
-
width: {
|
|
65
|
-
size: columnWidths.reduce((sum, width)=>sum + width, 0),
|
|
66
|
-
type: docx.WidthType.DXA
|
|
67
|
-
}
|
|
68
|
-
};
|
|
75
|
+
const columnWidths = pixelWidths?.map(work_docx_table_sizing_export_pixelsToTwips);
|
|
69
76
|
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
...columnWidths?.length ? {
|
|
78
|
+
columnWidths
|
|
79
|
+
} : {},
|
|
80
|
+
layout: 'fixed' === geometry.layout ? docx.TableLayoutType.FIXED : docx.TableLayoutType.AUTOFIT,
|
|
81
|
+
width: 'percent' === geometry.width.type && null !== geometry.width.value ? {
|
|
82
|
+
size: geometry.width.value,
|
|
73
83
|
type: docx.WidthType.PERCENTAGE
|
|
84
|
+
} : 'pixels' === geometry.width.type && null !== geometry.width.value ? {
|
|
85
|
+
size: work_docx_table_sizing_export_pixelsToTwips(geometry.width.value),
|
|
86
|
+
type: docx.WidthType.DXA
|
|
87
|
+
} : {
|
|
88
|
+
size: 0,
|
|
89
|
+
type: docx.WidthType.AUTO
|
|
90
|
+
},
|
|
91
|
+
alignment: 'center' === geometry.alignment ? docx.AlignmentType.CENTER : 'right' === geometry.alignment ? docx.AlignmentType.RIGHT : docx.AlignmentType.LEFT,
|
|
92
|
+
...geometry.indent > 0 ? {
|
|
93
|
+
indent: {
|
|
94
|
+
size: work_docx_table_sizing_export_pixelsToTwips(geometry.indent),
|
|
95
|
+
type: docx.WidthType.DXA
|
|
96
|
+
}
|
|
97
|
+
} : {},
|
|
98
|
+
margins: {
|
|
99
|
+
top: pixelsToNonNegativeTwips(geometry.cellMargins.top),
|
|
100
|
+
right: pixelsToNonNegativeTwips(geometry.cellMargins.right),
|
|
101
|
+
bottom: pixelsToNonNegativeTwips(geometry.cellMargins.bottom),
|
|
102
|
+
left: pixelsToNonNegativeTwips(geometry.cellMargins.left)
|
|
74
103
|
}
|
|
75
104
|
};
|
|
76
105
|
}
|
|
@@ -79,7 +108,7 @@ function documentTableCellSizingDocxOptions(cell, docx) {
|
|
|
79
108
|
if (!widths?.length) return {};
|
|
80
109
|
return {
|
|
81
110
|
width: {
|
|
82
|
-
size:
|
|
111
|
+
size: work_docx_table_sizing_export_pixelsToTwips(widths.reduce((sum, width)=>sum + width, 0)),
|
|
83
112
|
type: docx.WidthType.DXA
|
|
84
113
|
}
|
|
85
114
|
};
|
|
@@ -90,7 +119,7 @@ function documentTableRowSizingDocxOptions(row, docx) {
|
|
|
90
119
|
const rule = normalizeDocumentTableRowHeightRule(row.dataset.officeRowHeightRule);
|
|
91
120
|
return {
|
|
92
121
|
height: {
|
|
93
|
-
value:
|
|
122
|
+
value: work_docx_table_sizing_export_pixelsToTwips(pixels),
|
|
94
123
|
rule: 'exact' === rule ? docx.HeightRule.EXACT : docx.HeightRule.ATLEAST
|
|
95
124
|
}
|
|
96
125
|
};
|
|
@@ -116,8 +145,11 @@ function rowHeightPixels(row) {
|
|
|
116
145
|
const value = Number.parseFloat(row.dataset.officeRowHeight || row.style.height);
|
|
117
146
|
return Number.isFinite(value) && value > 0 ? value : null;
|
|
118
147
|
}
|
|
119
|
-
function
|
|
120
|
-
return Math.max(1, Math.round(pixels *
|
|
148
|
+
function work_docx_table_sizing_export_pixelsToTwips(pixels) {
|
|
149
|
+
return Math.max(1, Math.round(pixels * work_docx_table_sizing_export_TWIPS_PER_PIXEL));
|
|
150
|
+
}
|
|
151
|
+
function pixelsToNonNegativeTwips(pixels) {
|
|
152
|
+
return Math.max(0, Math.round(pixels * work_docx_table_sizing_export_TWIPS_PER_PIXEL));
|
|
121
153
|
}
|
|
122
154
|
function docxCaptionParagraph(element, titleChildren, docx, bidirectional) {
|
|
123
155
|
const kind = documentCaptionKind(element.dataset.captionKind) ?? 'figure';
|
|
@@ -510,6 +542,38 @@ function imageDimensions(blob) {
|
|
|
510
542
|
image.src = url;
|
|
511
543
|
});
|
|
512
544
|
}
|
|
545
|
+
const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
546
|
+
async function patchDocxDocumentLayout(buffer, sections) {
|
|
547
|
+
const archive = await jszip.loadAsync(buffer);
|
|
548
|
+
const entry = archive.file('word/document.xml');
|
|
549
|
+
if (!entry) return buffer;
|
|
550
|
+
const document = parseXml(await entry.async('string'), 'word/document.xml');
|
|
551
|
+
patchSectionDocumentGrids(document, sections);
|
|
552
|
+
archive.file('word/document.xml', new XMLSerializer().serializeToString(document));
|
|
553
|
+
return archive.generateAsync({
|
|
554
|
+
type: 'arraybuffer'
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function patchSectionDocumentGrids(document, sections) {
|
|
558
|
+
const sectionProperties = descendants(document, 'sectPr').filter((element)=>!hasAncestor(element, 'sectPrChange'));
|
|
559
|
+
for (const [index, properties] of sectionProperties.entries()){
|
|
560
|
+
for (const grid of directChildren(properties, 'docGrid'))grid.remove();
|
|
561
|
+
const value = sections[index]?.layout.documentGrid;
|
|
562
|
+
if (!value) continue;
|
|
563
|
+
const grid = document.createElementNS(WORD_NAMESPACE, 'w:docGrid');
|
|
564
|
+
grid.setAttributeNS(WORD_NAMESPACE, 'w:type', value.type);
|
|
565
|
+
grid.setAttributeNS(WORD_NAMESPACE, 'w:linePitch', String(Math.max(1, Math.round(20 * value.linePitch))));
|
|
566
|
+
properties.append(grid);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function hasAncestor(element, localName) {
|
|
570
|
+
let ancestor = element.parentElement;
|
|
571
|
+
while(ancestor){
|
|
572
|
+
if (ancestor.localName === localName) return true;
|
|
573
|
+
ancestor = ancestor.parentElement;
|
|
574
|
+
}
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
513
577
|
async function createDocxBlob(content) {
|
|
514
578
|
const docx = await import("docx");
|
|
515
579
|
const noteCollection = collectDocumentNotes(content.html);
|
|
@@ -530,10 +594,11 @@ async function createDocxBlob(content) {
|
|
|
530
594
|
const commentRecords = createDocxCommentRecords(comments, docx, noteContext);
|
|
531
595
|
const sections = [];
|
|
532
596
|
let usesOddEvenPageChrome = false;
|
|
533
|
-
|
|
597
|
+
const sourceSections = documentSections({
|
|
534
598
|
...content,
|
|
535
599
|
html: noteCollection.html
|
|
536
|
-
})
|
|
600
|
+
});
|
|
601
|
+
for (const section of sourceSections){
|
|
537
602
|
const parsed = new DOMParser().parseFromString(section.html, 'text/html');
|
|
538
603
|
const children = [];
|
|
539
604
|
for (const node of parsed.body.children){
|
|
@@ -546,7 +611,7 @@ async function createDocxBlob(content) {
|
|
|
546
611
|
const headers = await sectionHeaders(pageChrome, docx, noteContext);
|
|
547
612
|
const footers = await sectionFooters(pageChrome, docx, noteContext);
|
|
548
613
|
sections.push({
|
|
549
|
-
properties:
|
|
614
|
+
properties: work_docx_export_sectionProperties(section.layout, docx),
|
|
550
615
|
headers,
|
|
551
616
|
footers,
|
|
552
617
|
children
|
|
@@ -572,14 +637,15 @@ async function createDocxBlob(content) {
|
|
|
572
637
|
});
|
|
573
638
|
const packed = await docx.Packer.toBlob(document);
|
|
574
639
|
const bibliographyPatched = await patchDocxBibliography(await packed.arrayBuffer(), content.bibliography);
|
|
575
|
-
const
|
|
640
|
+
const layoutPatched = await patchDocxDocumentLayout(bibliographyPatched, sourceSections);
|
|
641
|
+
const patched = await patchDocxPageColor(layoutPatched, content.pageColor);
|
|
576
642
|
return new Blob([
|
|
577
643
|
patched
|
|
578
644
|
], {
|
|
579
645
|
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
|
580
646
|
});
|
|
581
647
|
}
|
|
582
|
-
function
|
|
648
|
+
function work_docx_export_sectionProperties(layout, docx) {
|
|
583
649
|
const landscape = 'landscape' === layout.orientation;
|
|
584
650
|
const dimensions = 'letter' === layout.pageSize ? {
|
|
585
651
|
width: landscape ? 15840 : 12240,
|
|
@@ -927,6 +993,7 @@ async function inlineRuns(root, docx, noteContext) {
|
|
|
927
993
|
shading: backgroundColor ? {
|
|
928
994
|
fill: backgroundColor
|
|
929
995
|
} : inherited.shading,
|
|
996
|
+
snapToGrid: dataBoolean(node.dataset.officeWordSnapToGrid) ?? inherited.snapToGrid,
|
|
930
997
|
rightToLeft: void 0 === direction ? inherited.rightToLeft : 'rtl' === direction
|
|
931
998
|
};
|
|
932
999
|
if ('br' === tag) return [
|
|
@@ -1090,13 +1157,7 @@ async function tableToDocx(element, docx, noteContext) {
|
|
|
1090
1157
|
columnSpan: cell.colSpan > 1 ? cell.colSpan : void 0,
|
|
1091
1158
|
rowSpan: cell.rowSpan > 1 ? cell.rowSpan : void 0,
|
|
1092
1159
|
...documentTableCellDocxOptions(cell, docx),
|
|
1093
|
-
...documentTableCellSizingDocxOptions(cell, docx)
|
|
1094
|
-
margins: {
|
|
1095
|
-
top: 80,
|
|
1096
|
-
right: 100,
|
|
1097
|
-
bottom: 80,
|
|
1098
|
-
left: 100
|
|
1099
|
-
}
|
|
1160
|
+
...documentTableCellSizingDocxOptions(cell, docx)
|
|
1100
1161
|
}));
|
|
1101
1162
|
}
|
|
1102
1163
|
const explicitHeader = dataBoolean(row.dataset.officeRepeatHeader);
|