@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,7 +1,10 @@
|
|
|
1
1
|
import { Extension } from "@tiptap/core";
|
|
2
|
+
import font_family from "@tiptap/extension-text-style/font-family";
|
|
3
|
+
import { TextStyle } from "@tiptap/extension-text-style";
|
|
2
4
|
const DOCUMENT_INDENT_STEP_PX = 24;
|
|
3
5
|
const MAX_DOCUMENT_INDENT_LEVEL = 8;
|
|
4
6
|
const MAX_DOCUMENT_INDENT_PX = DOCUMENT_INDENT_STEP_PX * MAX_DOCUMENT_INDENT_LEVEL;
|
|
7
|
+
const DOCUMENT_WORD_SINGLE_LINE_HEIGHT = 1.15;
|
|
5
8
|
const DocumentParagraphFormatting = Extension.create({
|
|
6
9
|
name: 'documentParagraphFormatting',
|
|
7
10
|
addGlobalAttributes () {
|
|
@@ -32,6 +35,11 @@ const DocumentParagraphFormatting = Extension.create({
|
|
|
32
35
|
} : {};
|
|
33
36
|
}
|
|
34
37
|
},
|
|
38
|
+
autoLineHeight: {
|
|
39
|
+
default: null,
|
|
40
|
+
parseHTML: (element)=>normalizedAutoLineHeight(element.dataset.officeAutoLineHeight),
|
|
41
|
+
renderHTML: (attributes)=>'auto' === normalizedLineRule(attributes.lineRule) ? renderDocumentAutoLineHeight(attributes.lineHeight, attributes.autoLineHeight) : {}
|
|
42
|
+
},
|
|
35
43
|
spaceBefore: pointSpacingAttribute('spaceBefore', 'officeSpaceBefore', 'data-office-space-before', 'margin-top'),
|
|
36
44
|
spaceAfter: pointSpacingAttribute('spaceAfter', 'officeSpaceAfter', 'data-office-space-after', 'margin-bottom'),
|
|
37
45
|
indentLevel: {
|
|
@@ -159,9 +167,11 @@ function normalizeDocumentParagraphDirection(value) {
|
|
|
159
167
|
}
|
|
160
168
|
function setDocumentLineHeightCommand({ chain }, lineHeight) {
|
|
161
169
|
const value = normalizedLineHeight(lineHeight);
|
|
170
|
+
const lineRule = value ? lineRuleForLineHeight(value) : null;
|
|
162
171
|
const attributes = {
|
|
163
172
|
lineHeight: value,
|
|
164
|
-
lineRule
|
|
173
|
+
lineRule,
|
|
174
|
+
autoLineHeight: 'auto' === lineRule ? documentAutoLineHeight(value) : null
|
|
165
175
|
};
|
|
166
176
|
return chain().focus().updateAttributes('paragraph', attributes).updateAttributes('heading', attributes).run();
|
|
167
177
|
}
|
|
@@ -237,11 +247,13 @@ function setDocumentParagraphSpacingCommand({ chain, editor }, spacing, options)
|
|
|
237
247
|
const nodeTypes = activeParagraphNodeTypes(editor);
|
|
238
248
|
if (!nodeTypes.length) return false;
|
|
239
249
|
const lineHeight = normalizedLineHeight(spacing.lineHeight);
|
|
250
|
+
const lineRule = normalizedLineRule(spacing.lineRule) ?? (lineHeight ? lineRuleForLineHeight(lineHeight) : null);
|
|
240
251
|
const attributes = {
|
|
241
252
|
spaceBefore: normalizedPointSpacing(spacing.before),
|
|
242
253
|
spaceAfter: normalizedPointSpacing(spacing.after),
|
|
243
254
|
lineHeight,
|
|
244
|
-
lineRule
|
|
255
|
+
lineRule,
|
|
256
|
+
autoLineHeight: 'auto' === lineRule ? documentAutoLineHeight(lineHeight) : null
|
|
245
257
|
};
|
|
246
258
|
let commandChain = chain();
|
|
247
259
|
if (false !== options.restoreFocus) commandChain = commandChain.focus();
|
|
@@ -257,6 +269,7 @@ function clearDocumentFormattingCommand({ chain, editor }) {
|
|
|
257
269
|
firstLineIndent: 0,
|
|
258
270
|
lineHeight: null,
|
|
259
271
|
lineRule: null,
|
|
272
|
+
autoLineHeight: null,
|
|
260
273
|
paragraphDirection: null,
|
|
261
274
|
spaceBefore: null,
|
|
262
275
|
spaceAfter: null,
|
|
@@ -285,6 +298,49 @@ function normalizedLineHeight(value) {
|
|
|
285
298
|
if (!normalized || 'normal' === normalized) return null;
|
|
286
299
|
return /^(?:\d+(?:\.\d+)?|\d+(?:\.\d+)?(?:px|pt|%))$/i.test(normalized) ? normalized : null;
|
|
287
300
|
}
|
|
301
|
+
function documentAutoLineHeight(value) {
|
|
302
|
+
const multiple = lineHeightMultiple(value);
|
|
303
|
+
if (null === multiple) return null;
|
|
304
|
+
return formatLineMetric(multiple * DOCUMENT_WORD_SINGLE_LINE_HEIGHT);
|
|
305
|
+
}
|
|
306
|
+
function documentAutoLineLeadingShift(value) {
|
|
307
|
+
const multiple = lineHeightMultiple(value);
|
|
308
|
+
if (null === multiple) return null;
|
|
309
|
+
return formatLineMetric((1 - multiple) * DOCUMENT_WORD_SINGLE_LINE_HEIGHT / 2);
|
|
310
|
+
}
|
|
311
|
+
function renderDocumentAutoLineHeight(lineHeight, autoLineHeight = documentAutoLineHeight(lineHeight)) {
|
|
312
|
+
const renderedLineHeight = normalizedAutoLineHeight(autoLineHeight) ?? documentAutoLineHeight(lineHeight);
|
|
313
|
+
if (null === renderedLineHeight) return {};
|
|
314
|
+
const multiple = lineHeightMultiple(lineHeight);
|
|
315
|
+
const shift = documentAutoLineLeadingShift(lineHeight);
|
|
316
|
+
return {
|
|
317
|
+
'data-office-auto-line-height': String(formatLineMetric(renderedLineHeight)),
|
|
318
|
+
style: [
|
|
319
|
+
`--work-document-office-auto-line-height: ${formatLineMetric(renderedLineHeight)}`,
|
|
320
|
+
...null === multiple ? [] : [
|
|
321
|
+
`--work-document-office-auto-line-multiple: ${formatLineMetric(multiple)}`
|
|
322
|
+
],
|
|
323
|
+
...null === shift ? [] : [
|
|
324
|
+
`--work-document-office-auto-line-shift: ${formatLineMetric(shift)}em`
|
|
325
|
+
]
|
|
326
|
+
].join('; ')
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function lineHeightMultiple(value) {
|
|
330
|
+
const normalized = normalizedLineHeight(value);
|
|
331
|
+
if (!normalized) return null;
|
|
332
|
+
const percentage = /^(\d+(?:\.\d+)?)%$/.exec(normalized);
|
|
333
|
+
const multiple = percentage ? Number(percentage[1]) / 100 : /^\d+(?:\.\d+)?$/.test(normalized) ? Number(normalized) : NaN;
|
|
334
|
+
return Number.isFinite(multiple) && multiple > 0 ? multiple : null;
|
|
335
|
+
}
|
|
336
|
+
function normalizedAutoLineHeight(value) {
|
|
337
|
+
if (null == value || '' === value) return null;
|
|
338
|
+
const number = Number(value);
|
|
339
|
+
return Number.isFinite(number) && number > 0 && number <= 20 ? formatLineMetric(number) : null;
|
|
340
|
+
}
|
|
341
|
+
function formatLineMetric(value) {
|
|
342
|
+
return Number(value.toFixed(4));
|
|
343
|
+
}
|
|
288
344
|
function normalizedLineRule(value) {
|
|
289
345
|
if ('auto' === value || 'exact' === value || 'atLeast' === value) return value;
|
|
290
346
|
if ('exactly' === value) return 'exact';
|
|
@@ -422,4 +478,119 @@ function activeParagraphDirectionNodeTypes(editor) {
|
|
|
422
478
|
...nodeTypes
|
|
423
479
|
];
|
|
424
480
|
}
|
|
425
|
-
|
|
481
|
+
const DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT = 1.15;
|
|
482
|
+
const DOCUMENT_WORD_LINE_HEIGHT_FACTORS = new Map([
|
|
483
|
+
[
|
|
484
|
+
'arial',
|
|
485
|
+
1.15
|
|
486
|
+
],
|
|
487
|
+
[
|
|
488
|
+
'times new roman',
|
|
489
|
+
1.15
|
|
490
|
+
],
|
|
491
|
+
[
|
|
492
|
+
'calibri',
|
|
493
|
+
1.2207
|
|
494
|
+
],
|
|
495
|
+
[
|
|
496
|
+
'segoe ui',
|
|
497
|
+
1.3301
|
|
498
|
+
],
|
|
499
|
+
[
|
|
500
|
+
'microsoft yahei',
|
|
501
|
+
1.7143
|
|
502
|
+
],
|
|
503
|
+
[
|
|
504
|
+
'microsoft yahei ui',
|
|
505
|
+
1.7143
|
|
506
|
+
],
|
|
507
|
+
[
|
|
508
|
+
'simsun',
|
|
509
|
+
1.2976
|
|
510
|
+
],
|
|
511
|
+
[
|
|
512
|
+
'simhei',
|
|
513
|
+
1.2976
|
|
514
|
+
],
|
|
515
|
+
[
|
|
516
|
+
'fangsong',
|
|
517
|
+
1.2976
|
|
518
|
+
],
|
|
519
|
+
[
|
|
520
|
+
'kaiti',
|
|
521
|
+
1.2976
|
|
522
|
+
],
|
|
523
|
+
[
|
|
524
|
+
'dengxian',
|
|
525
|
+
1.3548
|
|
526
|
+
]
|
|
527
|
+
]);
|
|
528
|
+
function documentWordLineHeightFactor(fontFamily) {
|
|
529
|
+
if ('string' != typeof fontFamily) return DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT;
|
|
530
|
+
const family = firstCssFontFamily(fontFamily).toLocaleLowerCase();
|
|
531
|
+
return DOCUMENT_WORD_LINE_HEIGHT_FACTORS.get(family) ?? DOCUMENT_WORD_DEFAULT_SINGLE_LINE_HEIGHT;
|
|
532
|
+
}
|
|
533
|
+
function normalizedDocumentWordLineHeightFactor(value) {
|
|
534
|
+
if (null == value || '' === value) return null;
|
|
535
|
+
const factor = Number(value);
|
|
536
|
+
if (!Number.isFinite(factor) || factor < 0.5 || factor > 4) return null;
|
|
537
|
+
return Number(factor.toFixed(4));
|
|
538
|
+
}
|
|
539
|
+
const DocumentTextStyle = TextStyle.extend({
|
|
540
|
+
addAttributes () {
|
|
541
|
+
return {
|
|
542
|
+
wordLineHeightFactor: {
|
|
543
|
+
default: null,
|
|
544
|
+
parseHTML: (element)=>normalizedDocumentWordLineHeightFactor(element.dataset.officeWordLineHeightFactor ?? element.style.getPropertyValue('--work-document-word-line-height-factor')),
|
|
545
|
+
renderHTML: (attributes)=>{
|
|
546
|
+
const factor = normalizedDocumentWordLineHeightFactor(attributes.wordLineHeightFactor);
|
|
547
|
+
if (null === factor) return {};
|
|
548
|
+
return {
|
|
549
|
+
'data-office-word-line-height-factor': String(factor),
|
|
550
|
+
style: `--work-document-word-line-height-factor: ${factor}`
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
wordSnapToGrid: {
|
|
555
|
+
default: null,
|
|
556
|
+
parseHTML: (element)=>normalizedBoolean(element.dataset.officeWordSnapToGrid),
|
|
557
|
+
renderHTML: (attributes)=>{
|
|
558
|
+
const value = normalizedBoolean(attributes.wordSnapToGrid);
|
|
559
|
+
return null === value ? {} : {
|
|
560
|
+
'data-office-word-snap-to-grid': String(value)
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
const DocumentFontFamily = font_family.extend({
|
|
568
|
+
addCommands () {
|
|
569
|
+
return {
|
|
570
|
+
setFontFamily: (fontFamily)=>({ chain })=>chain().setMark('textStyle', {
|
|
571
|
+
fontFamily,
|
|
572
|
+
wordLineHeightFactor: documentWordLineHeightFactor(fontFamily)
|
|
573
|
+
}).run(),
|
|
574
|
+
unsetFontFamily: ()=>({ chain })=>chain().setMark('textStyle', {
|
|
575
|
+
fontFamily: null,
|
|
576
|
+
wordLineHeightFactor: null
|
|
577
|
+
}).removeEmptyTextStyle().run()
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
function firstCssFontFamily(value) {
|
|
582
|
+
const source = value.trim();
|
|
583
|
+
if (!source) return '';
|
|
584
|
+
const quote = source[0];
|
|
585
|
+
if ('"' === quote || "'" === quote) {
|
|
586
|
+
const end = source.indexOf(quote, 1);
|
|
587
|
+
if (end > 0) return source.slice(1, end).trim();
|
|
588
|
+
}
|
|
589
|
+
return (source.split(',')[0] ?? source).trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
590
|
+
}
|
|
591
|
+
function normalizedBoolean(value) {
|
|
592
|
+
if (true === value || 'true' === value || '1' === value) return true;
|
|
593
|
+
if (false === value || 'false' === value || '0' === value) return false;
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
export { DocumentFontFamily, DocumentParagraphFormatting, DocumentTextStyle, canChangeDocumentIndent, documentAutoLineHeight, documentParagraphDirection, documentParagraphIndent, documentParagraphPagination, documentParagraphSpacing, documentWordLineHeightFactor, normalizeDocumentParagraphIndent, renderDocumentAutoLineHeight };
|
package/dist/0~7048.js
CHANGED
|
@@ -51,11 +51,11 @@ function useOfficeTaskPaneEscape(active, onClose) {
|
|
|
51
51
|
onClose
|
|
52
52
|
]);
|
|
53
53
|
}
|
|
54
|
-
function useOfficeTaskPaneModal() {
|
|
55
|
-
const [matches, setMatches] = useState(officeTaskPaneModalMatches);
|
|
54
|
+
function useOfficeTaskPaneModal(query = OFFICE_TASK_PANE_MODAL_QUERY) {
|
|
55
|
+
const [matches, setMatches] = useState(()=>officeTaskPaneModalMatches(query));
|
|
56
56
|
useEffect(()=>{
|
|
57
57
|
if ("u" < typeof window || 'function' != typeof window.matchMedia) return;
|
|
58
|
-
const mediaQuery = window.matchMedia(
|
|
58
|
+
const mediaQuery = window.matchMedia(query);
|
|
59
59
|
const update = ()=>setMatches(mediaQuery.matches);
|
|
60
60
|
update();
|
|
61
61
|
if ('function' == typeof mediaQuery.addEventListener) {
|
|
@@ -64,12 +64,14 @@ function useOfficeTaskPaneModal() {
|
|
|
64
64
|
}
|
|
65
65
|
mediaQuery.addListener(update);
|
|
66
66
|
return ()=>mediaQuery.removeListener(update);
|
|
67
|
-
}, [
|
|
67
|
+
}, [
|
|
68
|
+
query
|
|
69
|
+
]);
|
|
68
70
|
return matches;
|
|
69
71
|
}
|
|
70
|
-
function officeTaskPaneModalMatches() {
|
|
72
|
+
function officeTaskPaneModalMatches(query) {
|
|
71
73
|
if ("u" < typeof window || 'function' != typeof window.matchMedia) return false;
|
|
72
|
-
return window.matchMedia(
|
|
74
|
+
return window.matchMedia(query).matches;
|
|
73
75
|
}
|
|
74
76
|
function useOfficeDialog() {
|
|
75
77
|
const [request, setRequest] = useState(null);
|
package/dist/0~9512.js
CHANGED
|
@@ -194,16 +194,19 @@ function isAvailable(element) {
|
|
|
194
194
|
}
|
|
195
195
|
function officeOverlayPortalRoot(ownerDocument, ...anchors) {
|
|
196
196
|
for (const anchor of anchors){
|
|
197
|
-
const
|
|
198
|
-
if (
|
|
197
|
+
const portalRoot = closestOfficeOverlayRoot(anchor);
|
|
198
|
+
if (portalRoot) return portalRoot;
|
|
199
199
|
}
|
|
200
200
|
const activeElement = ownerDocument.activeElement;
|
|
201
201
|
if (activeElement instanceof Element) {
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
202
|
+
const portalRoot = closestOfficeOverlayRoot(activeElement);
|
|
203
|
+
if (portalRoot) return portalRoot;
|
|
204
204
|
}
|
|
205
205
|
return ownerDocument.body;
|
|
206
206
|
}
|
|
207
|
+
function closestOfficeOverlayRoot(anchor) {
|
|
208
|
+
return anchor?.closest('[role="dialog"][aria-modal="true"]') ?? anchor?.closest('[data-a3s-office]') ?? null;
|
|
209
|
+
}
|
|
207
210
|
function matchesOfficeEditorKeyboardShortcut(event, shortcut) {
|
|
208
211
|
return matchesKeyboardShortcut(event, shortcutParts(shortcut, '-'));
|
|
209
212
|
}
|