@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.
Files changed (69) hide show
  1. package/README.md +101 -24
  2. package/dist/0~2582.js +485 -0
  3. package/dist/0~4595.js +14 -7
  4. package/dist/0~4750.js +939 -0
  5. package/dist/{0~work-document-paragraph-formatting.js → 0~5861.js} +174 -3
  6. package/dist/0~7048.js +8 -6
  7. package/dist/0~9512.js +7 -4
  8. package/dist/0~document-editor.js +3147 -531
  9. package/dist/0~markdown-editor.js +26 -1
  10. package/dist/0~presentation-editor.js +68 -12
  11. package/dist/0~spreadsheet-editor.js +37 -17
  12. package/dist/0~work-document-extensions.js +588 -13
  13. package/dist/0~work-document-model-codec.js +1 -1
  14. package/dist/0~work-docx-bibliography.js +1 -1
  15. package/dist/0~work-docx-export.js +116 -55
  16. package/dist/0~work-docx-import.js +766 -107
  17. package/dist/0~work-office-diagnostics.js +2 -2
  18. package/dist/{4704.js → 2881.js} +162 -71
  19. package/dist/4104.js +2 -62
  20. package/dist/internal/features/work/editors/document-comment-window.d.ts +37 -0
  21. package/dist/internal/features/work/editors/document-navigation-panel.d.ts +3 -1
  22. package/dist/internal/features/work/editors/document-navigation-window.d.ts +64 -0
  23. package/dist/internal/features/work/editors/document-outline-navigation.d.ts +11 -0
  24. package/dist/internal/features/work/editors/document-page-navigation.d.ts +11 -1
  25. package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +31 -0
  26. package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +28 -0
  27. package/dist/internal/features/work/editors/document-picture-properties-dialog.d.ts +4 -0
  28. package/dist/internal/features/work/editors/document-search-navigation.d.ts +12 -0
  29. package/dist/internal/features/work/editors/document-table-margins-popover.d.ts +4 -0
  30. package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +51 -0
  31. package/dist/internal/features/work/editors/document-table-properties-dialog-sections.d.ts +19 -0
  32. package/dist/internal/features/work/editors/document-table-properties-dialog.d.ts +8 -0
  33. package/dist/internal/features/work/editors/office-task-pane.d.ts +1 -1
  34. package/dist/internal/features/work/editors/presentation-chart-panel.d.ts +2 -1
  35. package/dist/internal/features/work/editors/presentation-comments-panel.d.ts +2 -1
  36. package/dist/internal/features/work/editors/spreadsheet-workbook-panel.d.ts +2 -1
  37. package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -0
  38. package/dist/internal/features/work/editors/use-presentation-review-commands.d.ts +1 -1
  39. package/dist/internal/features/work/work-document-image-layout.d.ts +11 -0
  40. package/dist/internal/features/work/work-document-page-capture.d.ts +15 -0
  41. package/dist/internal/features/work/work-document-paragraph-formatting.d.ts +4 -0
  42. package/dist/internal/features/work/work-document-section.d.ts +3 -1
  43. package/dist/internal/features/work/work-document-table-borders.d.ts +20 -0
  44. package/dist/internal/features/work/work-document-table-cell-formatting.d.ts +8 -5
  45. package/dist/internal/features/work/work-document-table-geometry.d.ts +41 -0
  46. package/dist/internal/features/work/work-document-table-property-changes.d.ts +25 -0
  47. package/dist/internal/features/work/work-document-table-sizing.d.ts +15 -2
  48. package/dist/internal/features/work/work-document-word-line-metrics.d.ts +11 -0
  49. package/dist/internal/features/work/work-docx-document-layout.d.ts +2 -0
  50. package/dist/internal/features/work/work-docx-paragraph-alignment-import.d.ts +2 -1
  51. package/dist/internal/features/work/work-docx-paragraph-direction-import.d.ts +2 -1
  52. package/dist/internal/features/work/work-docx-paragraph-indent-import.d.ts +2 -1
  53. package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +2 -1
  54. package/dist/internal/features/work/work-docx-paragraph-spacing-import.d.ts +3 -2
  55. package/dist/internal/features/work/work-docx-paragraph-styles.d.ts +2 -2
  56. package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +8 -1
  57. package/dist/internal/features/work/work-docx-tab-stop-import.d.ts +2 -1
  58. package/dist/internal/features/work/work-docx-table-cell-export.d.ts +1 -1
  59. package/dist/internal/features/work/work-docx-table-cell-import.d.ts +14 -4
  60. package/dist/internal/features/work/work-docx-table-sizing-export.d.ts +1 -1
  61. package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +4 -3
  62. package/dist/internal/features/work/work-docx-table-styles.d.ts +22 -0
  63. package/dist/internal/features/work/work-types.d.ts +6 -0
  64. package/dist/office-kernel.wasm +0 -0
  65. package/dist/styles.css +1288 -233
  66. package/docs/{browser-editor-architecture.md → latest/en/browser-editor-architecture.md} +144 -35
  67. package/package.json +9 -5
  68. package/dist/0~6552.js +0 -787
  69. package/dist/0~8155.js +0 -299
package/dist/0~8155.js DELETED
@@ -1,299 +0,0 @@
1
- import { Extension, ResizableNodeView, mergeAttributes } from "@tiptap/core";
2
- import extension_image from "@tiptap/extension-image";
3
- const DEFAULT_IMAGE_LAYOUT = 'inline';
4
- const DEFAULT_IMAGE_ALIGNMENT = 'center';
5
- const DEFAULT_WRAP_DISTANCE_MILLIMETERS = 3;
6
- const MAX_WRAP_DISTANCE_MILLIMETERS = 25;
7
- const DocumentImage = extension_image.extend({
8
- addCommands () {
9
- return {
10
- ...this.parent?.() ?? {},
11
- setDocumentImageAlternativeText: (alternativeText, options = {})=>({ chain, editor })=>{
12
- if (!editor.isActive('image')) return false;
13
- const normalized = alternativeText.trim();
14
- let commandChain = chain();
15
- if (false !== options.restoreFocus) commandChain = commandChain.focus();
16
- return commandChain.updateAttributes('image', {
17
- alt: normalized || null,
18
- title: normalized || null
19
- }).run();
20
- },
21
- setDocumentImageLayoutOptions: (value, options = {})=>({ chain, editor })=>{
22
- if (!editor.isActive('image')) return false;
23
- const current = documentImageLayoutOptions(editor);
24
- const next = normalizeDocumentImageLayoutOptions({
25
- ...current,
26
- ...value
27
- });
28
- let commandChain = chain();
29
- if (false !== options.restoreFocus) commandChain = commandChain.focus();
30
- return commandChain.updateAttributes('image', next).run();
31
- }
32
- };
33
- },
34
- addAttributes () {
35
- return {
36
- ...this.parent?.(),
37
- layout: {
38
- default: DEFAULT_IMAGE_LAYOUT,
39
- parseHTML: (element)=>normalizeDocumentImageLayout(element.getAttribute('data-office-image-layout')),
40
- renderHTML: (attributes)=>({
41
- 'data-office-image-layout': normalizeDocumentImageLayout(attributes.layout)
42
- })
43
- },
44
- alignment: {
45
- default: DEFAULT_IMAGE_ALIGNMENT,
46
- parseHTML: (element)=>normalizeDocumentImageAlignment(element.getAttribute('data-office-image-alignment')),
47
- renderHTML: (attributes)=>({
48
- 'data-office-image-alignment': normalizeDocumentImageAlignment(attributes.alignment)
49
- })
50
- },
51
- wrapDistance: {
52
- default: DEFAULT_WRAP_DISTANCE_MILLIMETERS,
53
- parseHTML: (element)=>normalizeDocumentImageWrapDistance(element.getAttribute('data-office-image-wrap-distance')),
54
- renderHTML: (attributes)=>{
55
- const distance = normalizeDocumentImageWrapDistance(attributes.wrapDistance);
56
- return {
57
- 'data-office-image-wrap-distance': formatImageLayoutNumber(distance),
58
- style: `--work-document-image-wrap-distance:${formatImageLayoutNumber(distance)}mm`
59
- };
60
- }
61
- }
62
- };
63
- },
64
- addNodeView () {
65
- const resize = this.options.resize;
66
- if (false === resize || !resize.enabled || "u" < typeof document) return null;
67
- const { directions, minWidth, minHeight, alwaysPreserveAspectRatio } = resize;
68
- return ({ node, getPos, HTMLAttributes, editor })=>{
69
- const element = document.createElement('img');
70
- element.draggable = false;
71
- applyInitialImageHtmlAttributes(element, HTMLAttributes);
72
- element.style.visibility = 'hidden';
73
- element.style.pointerEvents = 'none';
74
- const reveal = ()=>{
75
- element.style.visibility = '';
76
- element.style.pointerEvents = '';
77
- };
78
- element.addEventListener('load', reveal);
79
- element.addEventListener('error', reveal);
80
- let container = null;
81
- const sync = (updatedNode)=>{
82
- syncDocumentImageNodeView(element, container, updatedNode.attrs);
83
- };
84
- const nodeView = new ResizableNodeView({
85
- element,
86
- editor,
87
- node,
88
- getPos,
89
- onResize: (width, height)=>{
90
- element.style.width = `${width}px`;
91
- element.style.height = `${height}px`;
92
- },
93
- onCommit: (width, height)=>{
94
- const position = getPos();
95
- if (void 0 === position) return;
96
- editor.chain().setNodeSelection(position).updateAttributes(this.name, {
97
- width,
98
- height
99
- }).run();
100
- },
101
- onUpdate: (updatedNode)=>{
102
- if (updatedNode.type !== node.type) return false;
103
- sync(updatedNode);
104
- return true;
105
- },
106
- options: {
107
- directions,
108
- min: {
109
- width: minWidth,
110
- height: minHeight
111
- },
112
- preserveAspectRatio: true === alwaysPreserveAspectRatio
113
- }
114
- });
115
- container = nodeView.dom;
116
- sync(node);
117
- if (element.complete) reveal();
118
- return nodeView;
119
- };
120
- }
121
- });
122
- function documentImageLayoutOptions(editor) {
123
- const attributes = editor.getAttributes('image');
124
- return normalizeDocumentImageLayoutOptions(attributes);
125
- }
126
- function documentImageAlternativeText(editor) {
127
- if (!editor.isActive('image')) return '';
128
- const attributes = editor.getAttributes('image');
129
- const value = 'string' == typeof attributes.alt ? attributes.alt : 'string' == typeof attributes.title ? attributes.title : '';
130
- return value.trim();
131
- }
132
- function documentImageLayoutFromElement(element) {
133
- return normalizeDocumentImageLayoutOptions({
134
- layout: element.getAttribute('data-office-image-layout'),
135
- alignment: element.getAttribute('data-office-image-alignment'),
136
- wrapDistance: element.getAttribute('data-office-image-wrap-distance')
137
- });
138
- }
139
- function normalizeDocumentImageLayoutOptions(value) {
140
- return {
141
- layout: normalizeDocumentImageLayout(value.layout),
142
- alignment: normalizeDocumentImageAlignment(value.alignment),
143
- wrapDistance: normalizeDocumentImageWrapDistance(value.wrapDistance)
144
- };
145
- }
146
- function normalizeDocumentImageLayout(value) {
147
- return 'square' === value || 'topBottom' === value ? value : DEFAULT_IMAGE_LAYOUT;
148
- }
149
- function normalizeDocumentImageAlignment(value) {
150
- return 'left' === value || 'right' === value ? value : DEFAULT_IMAGE_ALIGNMENT;
151
- }
152
- function normalizeDocumentImageWrapDistance(value) {
153
- const number = 'number' == typeof value ? value : 'string' == typeof value && value.trim() ? Number(value) : DEFAULT_WRAP_DISTANCE_MILLIMETERS;
154
- if (!Number.isFinite(number)) return DEFAULT_WRAP_DISTANCE_MILLIMETERS;
155
- return Math.round(2 * Math.min(MAX_WRAP_DISTANCE_MILLIMETERS, Math.max(0, number))) / 2;
156
- }
157
- function formatImageLayoutNumber(value) {
158
- return Number(value.toFixed(2)).toString();
159
- }
160
- function applyInitialImageHtmlAttributes(element, attributes) {
161
- const merged = mergeAttributes(attributes);
162
- for (const [name, value] of Object.entries(merged))if (null != value && 'width' !== name && 'height' !== name) element.setAttribute(name, String(value));
163
- }
164
- function syncDocumentImageNodeView(element, container, attributes) {
165
- const layout = normalizeDocumentImageLayout(attributes.layout);
166
- const alignment = normalizeDocumentImageAlignment(attributes.alignment);
167
- const wrapDistance = normalizeDocumentImageWrapDistance(attributes.wrapDistance);
168
- setOptionalImageAttribute(element, 'src', attributes.src);
169
- setOptionalImageAttribute(element, 'alt', attributes.alt);
170
- setOptionalImageAttribute(element, 'title', attributes.title);
171
- element.dataset.officeImageLayout = layout;
172
- element.dataset.officeImageAlignment = alignment;
173
- element.dataset.officeImageWrapDistance = formatImageLayoutNumber(wrapDistance);
174
- element.style.setProperty('--work-document-image-wrap-distance', `${formatImageLayoutNumber(wrapDistance)}mm`);
175
- syncImageDimension(element, 'width', attributes.width);
176
- syncImageDimension(element, 'height', attributes.height);
177
- if (!container) return;
178
- container.dataset.officeImageLayout = layout;
179
- container.dataset.officeImageAlignment = alignment;
180
- container.dataset.officeImageWrapDistance = formatImageLayoutNumber(wrapDistance);
181
- container.style.setProperty('--work-document-image-wrap-distance', `${formatImageLayoutNumber(wrapDistance)}mm`);
182
- }
183
- function setOptionalImageAttribute(element, name, value) {
184
- if ('string' == typeof value && value) element.setAttribute(name, value);
185
- else element.removeAttribute(name);
186
- }
187
- function syncImageDimension(element, dimension, value) {
188
- const pixels = 'number' == typeof value ? value : Number(value);
189
- if (Number.isFinite(pixels) && pixels > 0) {
190
- element.style[dimension] = `${pixels}px`;
191
- element.setAttribute(dimension, String(Math.round(pixels)));
192
- return;
193
- }
194
- element.style.removeProperty(dimension);
195
- element.removeAttribute(dimension);
196
- }
197
- const MAX_DOCUMENT_TAB_POSITION_PX = 4096;
198
- const MAX_DOCUMENT_TAB_STOPS = 64;
199
- const DocumentParagraphTabStops = Extension.create({
200
- name: 'documentParagraphTabStops',
201
- addGlobalAttributes () {
202
- return [
203
- {
204
- types: [
205
- 'paragraph',
206
- 'heading'
207
- ],
208
- attributes: {
209
- tabStops: {
210
- default: null,
211
- parseHTML: (element)=>normalizeDocumentTabStops(element.dataset.officeTabStops),
212
- renderHTML: (attributes)=>{
213
- const tabStops = normalizeDocumentTabStops(attributes.tabStops);
214
- return tabStops.length ? {
215
- 'data-office-tab-stops': serializeDocumentTabStops(tabStops)
216
- } : {};
217
- }
218
- }
219
- }
220
- }
221
- ];
222
- },
223
- addCommands () {
224
- return {
225
- setDocumentParagraphTabStops: (tabStops, options = {})=>({ chain, editor })=>{
226
- const nodeTypes = activeParagraphNodeTypes(editor);
227
- if (!nodeTypes.length) return false;
228
- const normalized = normalizeDocumentTabStops(tabStops);
229
- let commandChain = chain();
230
- if (false !== options.restoreFocus) commandChain = commandChain.focus();
231
- for (const nodeType of nodeTypes)commandChain = commandChain.updateAttributes(nodeType, {
232
- tabStops: normalized.length ? normalized : null
233
- });
234
- return commandChain.run();
235
- }
236
- };
237
- }
238
- });
239
- function documentParagraphTabStops(editor) {
240
- return normalizeDocumentTabStops(activeParagraphAttributes(editor).tabStops);
241
- }
242
- function normalizeDocumentTabStops(value) {
243
- const source = parsedTabStopSource(value);
244
- const byPosition = new Map();
245
- for (const candidate of source.slice(0, 4 * MAX_DOCUMENT_TAB_STOPS)){
246
- if (!isRecord(candidate)) continue;
247
- const rawPosition = Number(candidate.position);
248
- if (!Number.isFinite(rawPosition) || rawPosition <= 0) continue;
249
- const position = normalizedTabPosition(rawPosition);
250
- if (!(position <= 0)) byPosition.set(position, {
251
- position,
252
- alignment: normalizedTabAlignment(candidate.alignment),
253
- leader: normalizedTabLeader(candidate.leader)
254
- });
255
- }
256
- return Array.from(byPosition.values()).sort((left, right)=>left.position - right.position).slice(0, MAX_DOCUMENT_TAB_STOPS);
257
- }
258
- function serializeDocumentTabStops(value) {
259
- return JSON.stringify(normalizeDocumentTabStops(value));
260
- }
261
- function normalizedTabPosition(value) {
262
- if (!Number.isFinite(value)) return 0;
263
- return Math.min(MAX_DOCUMENT_TAB_POSITION_PX, Math.max(0, Math.round(100 * value) / 100));
264
- }
265
- function nextDocumentTabAlignment(alignment) {
266
- if ('left' === alignment) return 'center';
267
- if ('center' === alignment) return 'right';
268
- if ('right' === alignment) return 'decimal';
269
- return 'left';
270
- }
271
- function parsedTabStopSource(value) {
272
- if (Array.isArray(value)) return value;
273
- if ('string' != typeof value || !value.trim()) return [];
274
- try {
275
- const parsed = JSON.parse(value);
276
- return Array.isArray(parsed) ? parsed : [];
277
- } catch {
278
- return [];
279
- }
280
- }
281
- function normalizedTabAlignment(value) {
282
- return 'center' === value || 'right' === value || 'decimal' === value ? value : 'left';
283
- }
284
- function normalizedTabLeader(value) {
285
- return 'dot' === value || 'hyphen' === value || 'underscore' === value || 'middleDot' === value ? value : 'none';
286
- }
287
- function activeParagraphAttributes(editor) {
288
- return editor.isActive('heading') ? editor.getAttributes('heading') : editor.getAttributes('paragraph');
289
- }
290
- function activeParagraphNodeTypes(editor) {
291
- const types = [];
292
- if (editor.isActive('paragraph')) types.push('paragraph');
293
- if (editor.isActive('heading')) types.push('heading');
294
- return types;
295
- }
296
- function isRecord(value) {
297
- return 'object' == typeof value && null !== value && !Array.isArray(value);
298
- }
299
- export { DocumentImage, DocumentParagraphTabStops, documentImageAlternativeText, documentImageLayoutFromElement, documentImageLayoutOptions, documentParagraphTabStops, nextDocumentTabAlignment, normalizeDocumentImageAlignment, normalizeDocumentImageLayoutOptions, normalizeDocumentTabStops, normalizedTabPosition, serializeDocumentTabStops };