@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
@@ -1,9 +1,7 @@
1
1
  import extension_color from "@tiptap/extension-color";
2
2
  import extension_highlight from "@tiptap/extension-highlight";
3
- import { TableKit, createTable } from "@tiptap/extension-table";
3
+ import { Table, TableKit, TableView, createTable } from "@tiptap/extension-table";
4
4
  import extension_text_align from "@tiptap/extension-text-align";
5
- import { TextStyle } from "@tiptap/extension-text-style";
6
- import font_family from "@tiptap/extension-text-style/font-family";
7
5
  import font_size from "@tiptap/extension-text-style/font-size";
8
6
  import extension_underline from "@tiptap/extension-underline";
9
7
  import starter_kit from "@tiptap/starter-kit";
@@ -14,11 +12,13 @@ import extension_subscript from "@tiptap/extension-subscript";
14
12
  import extension_superscript from "@tiptap/extension-superscript";
15
13
  import { Decoration, DecorationSet } from "@tiptap/pm/view";
16
14
  import { BulletList, OrderedList } from "@tiptap/extension-list";
17
- import { documentFieldLabel, documentSections, documentCaptionLabel, documentCaptionKind, renameDocumentCitationTagInInstruction, documentNoteReferenceKeys, collectDocumentNotes, documentSectionNodeAttributes, syncDocumentContentFromHtml, documentFieldInstruction, documentCitationTagsFromInstruction, documentCitationInstruction, documentCitationTags, documentFieldKind, documentSectionDomAttributes, documentFieldDisplay, docxDocumentFieldKind, renderDocumentBibliographyHtml, documentSectionLayoutFromNodeAttributes, documentNoteKey, documentCaptionDisplay, resolveDocumentCitation, removeDocumentNoteDefinitions, resolveDocumentFieldsHtml, documentNoteKind } from "./4704.js";
15
+ import { closeHistory } from "@tiptap/pm/history";
16
+ import { TableMap, isInTable, selectedRect } from "@tiptap/pm/tables";
17
+ import { documentFieldLabel, documentSections, documentCaptionLabel, documentCaptionKind, renameDocumentCitationTagInInstruction, documentNoteReferenceKeys, collectDocumentNotes, documentSectionNodeAttributes, syncDocumentContentFromHtml, documentFieldInstruction, documentCitationTagsFromInstruction, documentCitationInstruction, documentCitationTags, documentFieldKind, documentSectionDomAttributes, documentFieldDisplay, docxDocumentFieldKind, renderDocumentBibliographyHtml, documentSectionLayoutFromNodeAttributes, documentNoteKey, documentCaptionDisplay, resolveDocumentCitation, removeDocumentNoteDefinitions, resolveDocumentFieldsHtml, documentNoteKind } from "./2881.js";
18
18
  import { createOfficeId as createWorkId } from "./1134.js";
19
- import { DocumentParagraphTabStops, DocumentImage, normalizeDocumentTabStops } from "./0~8155.js";
20
- import { DocumentTable, DocumentTableCell, DocumentTableHeader, DocumentTableRow, DocumentTableSizing, DocumentTableFormatting } from "./0~6552.js";
21
- import { DocumentParagraphFormatting } from "./0~work-document-paragraph-formatting.js";
19
+ import { normalizeDocumentTableProperties, documentTableGeometryForLayoutMode, DocumentImage, renderDocumentTableGeometry, documentTableGeometryFromElement, documentTableLayoutMode, normalizeDocumentTabStops, normalizeDocumentTableCellMarginOverrides, normalizeDocumentTableAlignment, normalizeDocumentTableCellMargins, DocumentParagraphTabStops, normalizeDocumentTableGeometry, applyDocumentTableGeometryToElement } from "./0~4750.js";
20
+ import { DocumentTableCell, DocumentTableHeader, DocumentTableRow, normalizeDocumentTableVerticalAlign, documentTableRowHeight, documentTableRowRepeats, DocumentTableFormatting } from "./0~2582.js";
21
+ import { DocumentTextStyle, DocumentFontFamily, DocumentParagraphFormatting } from "./0~5861.js";
22
22
  function activeDocumentSection(editor) {
23
23
  return activeDocumentSectionFromState(editor.state);
24
24
  }
@@ -2009,7 +2009,9 @@ const DocumentSection = Node.create({
2009
2009
  footerText: work_document_section_node_hiddenAttribute(''),
2010
2010
  showPageNumbers: work_document_section_node_hiddenAttribute(false),
2011
2011
  pageNumberStart: work_document_section_node_hiddenAttribute(null),
2012
- pageChrome: work_document_section_node_hiddenAttribute('')
2012
+ pageChrome: work_document_section_node_hiddenAttribute(''),
2013
+ documentGridType: work_document_section_node_hiddenAttribute(''),
2014
+ documentGridLinePitch: work_document_section_node_hiddenAttribute(null)
2013
2015
  };
2014
2016
  },
2015
2017
  addCommands () {
@@ -2069,7 +2071,9 @@ const DocumentSection = Node.create({
2069
2071
  footerText: node.dataset.sectionFooterText ?? '',
2070
2072
  showPageNumbers: 'true' === node.dataset.sectionShowPageNumbers,
2071
2073
  pageNumberStart: nullableNumberAttribute(node, 'sectionPageNumberStart'),
2072
- pageChrome: node.dataset.sectionPageChrome ?? ''
2074
+ pageChrome: node.dataset.sectionPageChrome ?? '',
2075
+ documentGridType: node.dataset.sectionDocumentGridType ?? '',
2076
+ documentGridLinePitch: nullableNumberAttribute(node, 'sectionDocumentGridLinePitch')
2073
2077
  };
2074
2078
  }
2075
2079
  }
@@ -2082,7 +2086,10 @@ const DocumentSection = Node.create({
2082
2086
  const style = [
2083
2087
  `--work-document-column-count:${columns.count}`,
2084
2088
  `--work-document-column-gap:${columns.spacing}mm`,
2085
- `--work-document-column-rule:${columns.separator ? '1px solid var(--a3s-line-strong)' : 'none'}`
2089
+ `--work-document-column-rule:${columns.separator ? '1px solid var(--a3s-line-strong)' : 'none'}`,
2090
+ ...layout.documentGrid ? [
2091
+ `--work-document-word-grid-line-pitch:${layout.documentGrid.linePitch}pt`
2092
+ ] : []
2086
2093
  ].join(';');
2087
2094
  return [
2088
2095
  'section',
@@ -2366,6 +2373,574 @@ function withRepeatingFirstRow(table) {
2366
2373
  }, firstRow.content, firstRow.marks);
2367
2374
  return table.copy(table.content.replaceChild(0, repeatedRow));
2368
2375
  }
2376
+ const MIN_DOCUMENT_TABLE_COLUMN_WIDTH = 25;
2377
+ const MIN_DOCUMENT_TABLE_ROW_HEIGHT = 12;
2378
+ const MAX_DOCUMENT_TABLE_DIMENSION = 4000;
2379
+ function normalizeDocumentTablePropertyChanges(value) {
2380
+ if (!isRecord(value)) return null;
2381
+ const changes = {};
2382
+ if (void 0 !== value.table) {
2383
+ const table = normalizeDocumentTableProperties(value.table);
2384
+ if (!table) return null;
2385
+ changes.table = table;
2386
+ }
2387
+ if (void 0 !== value.row) {
2388
+ const row = value.row;
2389
+ if (!isRecord(row)) return null;
2390
+ if (null !== row.height && 'number' != typeof row.height) return null;
2391
+ const height = null === row.height ? null : normalizeDocumentTableDimension(row.height, MIN_DOCUMENT_TABLE_ROW_HEIGHT);
2392
+ if (null !== row.height && null === height) return null;
2393
+ if ('atLeast' !== row.heightRule && 'exact' !== row.heightRule) return null;
2394
+ if ('boolean' != typeof row.cantSplit) return null;
2395
+ if (void 0 !== row.repeatHeader && 'boolean' != typeof row.repeatHeader) return null;
2396
+ changes.row = {
2397
+ height,
2398
+ heightRule: row.heightRule,
2399
+ cantSplit: row.cantSplit,
2400
+ ...void 0 === row.repeatHeader ? {} : {
2401
+ repeatHeader: row.repeatHeader
2402
+ }
2403
+ };
2404
+ }
2405
+ if (void 0 !== value.column) {
2406
+ const column = value.column;
2407
+ if (!isRecord(column) || 'number' != typeof column.width) return null;
2408
+ const width = normalizeDocumentTableDimension(column.width, MIN_DOCUMENT_TABLE_COLUMN_WIDTH);
2409
+ if (null === width) return null;
2410
+ changes.column = {
2411
+ width,
2412
+ ...Array.isArray(column.renderedColumnWidths) ? {
2413
+ renderedColumnWidths: column.renderedColumnWidths
2414
+ } : {}
2415
+ };
2416
+ }
2417
+ if (void 0 !== value.cell) {
2418
+ const cell = value.cell;
2419
+ if (!isRecord(cell) || 'string' != typeof cell.verticalAlign) return null;
2420
+ const verticalAlign = normalizeDocumentTableVerticalAlign(cell.verticalAlign);
2421
+ const margins = null === cell.margins ? null : normalizeDocumentTableCellMarginOverrides(cell.margins);
2422
+ if (!verticalAlign || null !== cell.margins && !margins) return null;
2423
+ changes.cell = {
2424
+ verticalAlign,
2425
+ margins
2426
+ };
2427
+ }
2428
+ return Object.keys(changes).length ? changes : null;
2429
+ }
2430
+ function normalizeDocumentTableDimension(value, minimum) {
2431
+ if (!Number.isFinite(value) || value < minimum || value > MAX_DOCUMENT_TABLE_DIMENSION) return null;
2432
+ return Math.round(100 * value) / 100;
2433
+ }
2434
+ function isRecord(value) {
2435
+ return 'object' == typeof value && null !== value;
2436
+ }
2437
+ const DEFAULT_COLUMN_WIDTH = 120;
2438
+ const DEFAULT_ROW_HEIGHT = 36;
2439
+ class WorkDocumentTableView extends TableView {
2440
+ constructor(node, cellMinWidth, view){
2441
+ super(node, cellMinWidth, view);
2442
+ this.syncGeometry(node);
2443
+ }
2444
+ update(node) {
2445
+ const updated = super.update(node);
2446
+ if (updated) this.syncGeometry(node);
2447
+ return updated;
2448
+ }
2449
+ syncGeometry(node) {
2450
+ const geometry = tableGeometry(node);
2451
+ applyDocumentTableGeometryToElement(this.table, geometry);
2452
+ if (node.attrs.officeImported) this.table.dataset.officeTableImported = 'true';
2453
+ else delete this.table.dataset.officeTableImported;
2454
+ if (!tableHasExplicitColumnWidths(node)) this.clearStaleColumnWidths();
2455
+ }
2456
+ clearStaleColumnWidths() {
2457
+ for (const column of Array.from(this.colgroup.children))if (column instanceof HTMLElement) {
2458
+ column.style.removeProperty('width');
2459
+ column.style.setProperty('min-width', `${this.cellMinWidth}px`);
2460
+ }
2461
+ }
2462
+ }
2463
+ const DocumentTable = Table.extend({
2464
+ addAttributes () {
2465
+ return {
2466
+ ...this.parent?.() ?? {},
2467
+ geometry: {
2468
+ default: null,
2469
+ parseHTML: (element)=>documentTableGeometryFromElement(element),
2470
+ renderHTML: (attributes)=>renderDocumentTableGeometry(attributes.geometry, attributes.layoutMode)
2471
+ },
2472
+ layoutMode: {
2473
+ default: null,
2474
+ parseHTML: ()=>null,
2475
+ renderHTML: ()=>({})
2476
+ },
2477
+ officeImported: {
2478
+ default: false,
2479
+ parseHTML: (element)=>'true' === element.dataset.officeTableImported,
2480
+ renderHTML: (attributes)=>attributes.officeImported ? {
2481
+ 'data-office-table-imported': 'true'
2482
+ } : {}
2483
+ }
2484
+ };
2485
+ }
2486
+ }).configure({
2487
+ resizable: true,
2488
+ allowTableNodeSelection: true,
2489
+ View: WorkDocumentTableView
2490
+ });
2491
+ const DocumentTableSizing = Extension.create({
2492
+ name: 'documentTableSizing',
2493
+ addCommands () {
2494
+ return {
2495
+ setDocumentTableColumnWidth: (width, renderedColumnWidths)=>(props)=>setSelectedColumnWidth(props, width, renderedColumnWidths),
2496
+ setDocumentTableRowHeight: (height, rule = 'atLeast')=>(props)=>setSelectedRowHeight(props, height, rule),
2497
+ setDocumentTableLayoutMode: (mode, renderedTableWidth)=>(props)=>setTableLayoutMode(props, mode, renderedTableWidth),
2498
+ setDocumentTableAlignment: (alignment)=>(props)=>setTableAlignment(props, alignment),
2499
+ setDocumentTableProperties: (properties)=>(props)=>setTableProperties(props, properties),
2500
+ setDocumentTablePropertyChanges: (changes)=>(props)=>setTablePropertyChanges(props, changes),
2501
+ setDocumentTableCellMargins: (margins)=>(props)=>setTableCellMargins(props, margins),
2502
+ distributeDocumentTableColumns: (renderedSelectionWidth)=>(props)=>distributeColumns(props, renderedSelectionWidth),
2503
+ distributeDocumentTableRows: (renderedSelectionHeight)=>(props)=>distributeRows(props, renderedSelectionHeight)
2504
+ };
2505
+ },
2506
+ addProseMirrorPlugins () {
2507
+ return [
2508
+ new Plugin({
2509
+ appendTransaction: (transactions, oldState, newState)=>{
2510
+ if (!transactions.some((transaction)=>transaction.docChanged)) return null;
2511
+ const previousTables = documentTables(oldState.doc);
2512
+ const currentTables = documentTables(newState.doc);
2513
+ if (previousTables.length !== currentTables.length) return null;
2514
+ const transaction = newState.tr;
2515
+ let tableIndex = 0;
2516
+ newState.doc.descendants((node, position)=>{
2517
+ if ('table' !== node.type.spec.tableRole) return true;
2518
+ const previous = previousTables[tableIndex];
2519
+ tableIndex += 1;
2520
+ if (tableColumnWidthSignature(previous) !== tableColumnWidthSignature(node) && tableHasExplicitColumnWidths(node) && 'fixed' !== tableGeometry(node).layout) transaction.setNodeMarkup(position, void 0, {
2521
+ ...node.attrs,
2522
+ geometry: fixedGeometryForTable(node),
2523
+ layoutMode: null
2524
+ });
2525
+ return false;
2526
+ });
2527
+ return transaction.docChanged ? transaction : null;
2528
+ }
2529
+ })
2530
+ ];
2531
+ }
2532
+ });
2533
+ function documentTableSizing(state) {
2534
+ const context = tableSizingContext(state);
2535
+ if (!context) return null;
2536
+ const columns = numberRange(context.left, context.right);
2537
+ const rows = numberRange(context.top, context.bottom);
2538
+ const widths = tableColumnWidths(context.table, context.map).filter((_width, index)=>columns.includes(index));
2539
+ const rowSizes = tableRowSizes(context.table).filter((_size, index)=>rows.includes(index));
2540
+ const geometry = tableGeometry(context.table);
2541
+ return {
2542
+ columnWidth: commonPositiveValue(widths),
2543
+ rowHeight: commonNullableValue(rowSizes.map(({ height })=>height)),
2544
+ rowHeightRule: commonNullableValue(rowSizes.map(({ rule })=>rule)),
2545
+ layoutMode: documentTableLayoutMode(geometry),
2546
+ layoutAlgorithm: geometry.layout,
2547
+ preferredWidthType: geometry.width.type,
2548
+ preferredWidth: geometry.width.value,
2549
+ alignment: geometry.alignment,
2550
+ indent: geometry.indent,
2551
+ cellMargins: geometry.cellMargins,
2552
+ selectedColumnCount: columns.length,
2553
+ selectedRowCount: rows.length
2554
+ };
2555
+ }
2556
+ function setSelectedColumnWidth({ dispatch, state }, width, renderedColumnWidths) {
2557
+ const normalized = normalizeDocumentTableDimension(width, 25);
2558
+ const context = tableSizingContext(state);
2559
+ if (!context || null === normalized) return false;
2560
+ if (!dispatch) return true;
2561
+ const transaction = state.tr;
2562
+ const preservedWidths = normalizeRenderedDimensions(renderedColumnWidths, context.map.width, 25);
2563
+ if (preservedWidths) {
2564
+ for(let column = context.left; column < context.right; column += 1)preservedWidths[column] = normalized;
2565
+ setPhysicalColumnWidths(transaction, context, preservedWidths, 0);
2566
+ } else setPhysicalColumnWidths(transaction, context, numberRange(context.left, context.right).map(()=>normalized), context.left);
2567
+ setFixedTableGeometryFromColumns(transaction, context);
2568
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2569
+ return true;
2570
+ }
2571
+ function setSelectedRowHeight({ dispatch, state }, height, rule) {
2572
+ const normalized = null === height ? null : normalizeDocumentTableDimension(height, 12);
2573
+ const context = tableSizingContext(state);
2574
+ if (!context || null !== height && null === normalized) return false;
2575
+ if ('atLeast' !== rule && 'exact' !== rule) return false;
2576
+ if (!dispatch) return true;
2577
+ const transaction = state.tr;
2578
+ setPhysicalRowHeights(transaction, context, numberRange(context.top, context.bottom), normalized, rule);
2579
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2580
+ return true;
2581
+ }
2582
+ function setTableLayoutMode({ dispatch, state }, requestedMode, renderedTableWidth) {
2583
+ if ('window' !== requestedMode && 'contents' !== requestedMode && 'fixed' !== requestedMode) return false;
2584
+ const context = tableSizingContext(state);
2585
+ if (!context) return false;
2586
+ if (!dispatch) return true;
2587
+ const transaction = state.tr;
2588
+ let preferredWidth = renderedTableWidth;
2589
+ if ('fixed' === requestedMode) {
2590
+ const existing = tableColumnWidths(context.table, context.map);
2591
+ const total = distributionTotal(existing, renderedTableWidth, DEFAULT_COLUMN_WIDTH);
2592
+ setPhysicalColumnWidths(transaction, context, equalDimensions(total, context.map.width, 25), 0);
2593
+ preferredWidth = total;
2594
+ } else clearPhysicalColumnWidths(transaction, context);
2595
+ setTableGeometryAttribute(transaction, context, documentTableGeometryForLayoutMode(requestedMode, tableGeometry(context.table), preferredWidth));
2596
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2597
+ return true;
2598
+ }
2599
+ function setTableAlignment({ dispatch, state }, requestedAlignment) {
2600
+ const alignment = normalizeDocumentTableAlignment(requestedAlignment);
2601
+ const context = tableSizingContext(state);
2602
+ if (!context || !alignment) return false;
2603
+ if (!dispatch) return true;
2604
+ const transaction = state.tr;
2605
+ setTableGeometryAttribute(transaction, context, {
2606
+ ...tableGeometry(context.table),
2607
+ alignment
2608
+ });
2609
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2610
+ return true;
2611
+ }
2612
+ function setTableProperties({ dispatch, state }, requestedProperties) {
2613
+ const properties = normalizeDocumentTableProperties(requestedProperties);
2614
+ const context = tableSizingContext(state);
2615
+ if (!context || !properties) return false;
2616
+ if (!dispatch) return true;
2617
+ const transaction = state.tr;
2618
+ setTableGeometryAttribute(transaction, context, {
2619
+ ...tableGeometry(context.table),
2620
+ ...properties
2621
+ });
2622
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2623
+ return true;
2624
+ }
2625
+ function setTablePropertyChanges({ dispatch, state }, requestedChanges) {
2626
+ const changes = normalizeDocumentTablePropertyChanges(requestedChanges);
2627
+ const context = tableSizingContext(state);
2628
+ if (!context || !changes) return false;
2629
+ if (changes.row?.repeatHeader === true && !canRepeatSelectedTableRows(context)) return false;
2630
+ if (!dispatch) return true;
2631
+ const transaction = state.tr;
2632
+ closeHistory(transaction);
2633
+ if (changes.column) {
2634
+ const preservedWidths = normalizeRenderedDimensions(changes.column.renderedColumnWidths, context.map.width, 25);
2635
+ if (preservedWidths) {
2636
+ for(let column = context.left; column < context.right; column += 1)preservedWidths[column] = changes.column.width;
2637
+ setPhysicalColumnWidths(transaction, context, preservedWidths, 0);
2638
+ } else setPhysicalColumnWidths(transaction, context, numberRange(context.left, context.right).map(()=>changes.column?.width ?? DEFAULT_COLUMN_WIDTH), context.left);
2639
+ setFixedTableGeometryFromColumns(transaction, context);
2640
+ }
2641
+ if (changes.table) {
2642
+ const currentTable = transaction.doc.nodeAt(context.tableStart - 1);
2643
+ setTableGeometryAttribute(transaction, context, {
2644
+ ...tableGeometry(currentTable ?? context.table),
2645
+ ...changes.table
2646
+ });
2647
+ }
2648
+ if (changes.row) setPhysicalRowProperties(transaction, context, numberRange(context.top, context.bottom), changes.row);
2649
+ if (changes.cell) setSelectedCellProperties(transaction, context, changes.cell);
2650
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2651
+ return true;
2652
+ }
2653
+ function setTableCellMargins({ dispatch, state }, requestedMargins) {
2654
+ const cellMargins = normalizeDocumentTableCellMargins(requestedMargins);
2655
+ const context = tableSizingContext(state);
2656
+ if (!context || !cellMargins) return false;
2657
+ if (!dispatch) return true;
2658
+ const transaction = state.tr;
2659
+ setTableGeometryAttribute(transaction, context, {
2660
+ ...tableGeometry(context.table),
2661
+ cellMargins
2662
+ });
2663
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2664
+ return true;
2665
+ }
2666
+ function distributeColumns({ dispatch, state }, renderedSelectionWidth) {
2667
+ const context = tableSizingContext(state);
2668
+ if (!context) return false;
2669
+ const selected = numberRange(context.left, context.right);
2670
+ const columns = selected.length > 1 ? selected : numberRange(0, context.map.width);
2671
+ if (columns.length < 2) return false;
2672
+ if (!dispatch) return true;
2673
+ const allWidths = tableColumnWidths(context.table, context.map);
2674
+ const existing = columns.map((column)=>allWidths[column] ?? null);
2675
+ const total = distributionTotal(existing, renderedSelectionWidth, DEFAULT_COLUMN_WIDTH);
2676
+ const transaction = state.tr;
2677
+ setPhysicalColumnWidths(transaction, context, equalDimensions(total, columns.length, 25), columns[0] ?? 0);
2678
+ setFixedTableGeometryFromColumns(transaction, context);
2679
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2680
+ return true;
2681
+ }
2682
+ function distributeRows({ dispatch, state }, renderedSelectionHeight) {
2683
+ const context = tableSizingContext(state);
2684
+ if (!context) return false;
2685
+ const selected = numberRange(context.top, context.bottom);
2686
+ const rows = selected.length > 1 ? selected : numberRange(0, context.map.height);
2687
+ if (rows.length < 2) return false;
2688
+ if (!dispatch) return true;
2689
+ const allSizes = tableRowSizes(context.table);
2690
+ const existing = rows.map((row)=>allSizes[row]?.height ?? null);
2691
+ const total = distributionTotal(existing, renderedSelectionHeight, DEFAULT_ROW_HEIGHT);
2692
+ const [height] = equalDimensions(total, rows.length, 12);
2693
+ const transaction = state.tr;
2694
+ setPhysicalRowHeights(transaction, context, rows, height ?? DEFAULT_ROW_HEIGHT, 'atLeast');
2695
+ dispatchTableSizingTransaction(dispatch, transaction, context, state);
2696
+ return true;
2697
+ }
2698
+ function tableSizingContext(state) {
2699
+ if (state.selection instanceof NodeSelection && 'table' === state.selection.node.type.spec.tableRole) {
2700
+ const table = state.selection.node;
2701
+ const map = TableMap.get(table);
2702
+ return {
2703
+ table,
2704
+ tableStart: state.selection.from + 1,
2705
+ map,
2706
+ left: 0,
2707
+ right: map.width,
2708
+ top: 0,
2709
+ bottom: map.height
2710
+ };
2711
+ }
2712
+ if (!isInTable(state)) return null;
2713
+ const rectangle = selectedRect(state);
2714
+ return {
2715
+ table: rectangle.table,
2716
+ tableStart: rectangle.tableStart,
2717
+ map: rectangle.map,
2718
+ left: rectangle.left,
2719
+ right: rectangle.right,
2720
+ top: rectangle.top,
2721
+ bottom: rectangle.bottom
2722
+ };
2723
+ }
2724
+ function dispatchTableSizingTransaction(dispatch, transaction, context, state) {
2725
+ if (!transaction.docChanged) return;
2726
+ if (state.selection instanceof NodeSelection && 'table' === state.selection.node.type.spec.tableRole) {
2727
+ const tablePosition = context.tableStart - 1;
2728
+ if (transaction.doc.nodeAt(tablePosition)?.type.spec.tableRole === 'table') transaction.setSelection(NodeSelection.create(transaction.doc, tablePosition));
2729
+ }
2730
+ dispatch(transaction.scrollIntoView());
2731
+ }
2732
+ function setPhysicalColumnWidths(transaction, context, widths, startColumn) {
2733
+ const touched = new Set();
2734
+ widths.forEach((width, widthIndex)=>{
2735
+ const column = startColumn + widthIndex;
2736
+ if (column < 0 || column >= context.map.width) return;
2737
+ for(let row = 0; row < context.map.height; row += 1){
2738
+ const relativePosition = context.map.map[row * context.map.width + column];
2739
+ if (void 0 === relativePosition) continue;
2740
+ const cell = context.table.nodeAt(relativePosition);
2741
+ if (!cell) continue;
2742
+ const widthIndexInCell = column - context.map.colCount(relativePosition);
2743
+ const key = `${relativePosition}:${widthIndexInCell}`;
2744
+ if (touched.has(key)) continue;
2745
+ touched.add(key);
2746
+ const documentPosition = context.tableStart + relativePosition;
2747
+ const current = transaction.doc.nodeAt(documentPosition);
2748
+ if (!current) continue;
2749
+ const colwidth = Array.isArray(current.attrs.colwidth) ? [
2750
+ ...current.attrs.colwidth
2751
+ ] : Array.from({
2752
+ length: Number(current.attrs.colspan ?? 1)
2753
+ }, ()=>0);
2754
+ colwidth[widthIndexInCell] = width;
2755
+ transaction.setNodeMarkup(documentPosition, void 0, {
2756
+ ...current.attrs,
2757
+ colwidth
2758
+ });
2759
+ }
2760
+ });
2761
+ }
2762
+ function clearPhysicalColumnWidths(transaction, context) {
2763
+ context.table.descendants((node, offset)=>{
2764
+ if (!isTableCell(node)) return true;
2765
+ const position = context.tableStart + offset;
2766
+ const current = transaction.doc.nodeAt(position);
2767
+ if (current?.attrs.colwidth) transaction.setNodeMarkup(position, void 0, {
2768
+ ...current.attrs,
2769
+ colwidth: null
2770
+ });
2771
+ return false;
2772
+ });
2773
+ }
2774
+ function setPhysicalRowHeights(transaction, context, rows, height, rule) {
2775
+ const selectedRows = new Set(rows);
2776
+ context.table.forEach((_row, offset, index)=>{
2777
+ if (!selectedRows.has(index)) return;
2778
+ const position = context.tableStart + offset;
2779
+ const current = transaction.doc.nodeAt(position);
2780
+ if (!current) return;
2781
+ transaction.setNodeMarkup(position, void 0, {
2782
+ ...current.attrs,
2783
+ rowHeight: height,
2784
+ rowHeightRule: null === height ? null : rule
2785
+ });
2786
+ });
2787
+ }
2788
+ function setPhysicalRowProperties(transaction, context, rows, properties) {
2789
+ const selectedRows = new Set(rows);
2790
+ context.table.forEach((_row, offset, index)=>{
2791
+ if (!selectedRows.has(index)) return;
2792
+ const position = context.tableStart + offset;
2793
+ const current = transaction.doc.nodeAt(position);
2794
+ if (!current) return;
2795
+ transaction.setNodeMarkup(position, void 0, {
2796
+ ...current.attrs,
2797
+ rowHeight: properties.height,
2798
+ rowHeightRule: null === properties.height ? null : properties.heightRule,
2799
+ cantSplit: properties.cantSplit,
2800
+ ...void 0 === properties.repeatHeader ? {} : {
2801
+ repeatHeader: properties.repeatHeader
2802
+ }
2803
+ });
2804
+ });
2805
+ }
2806
+ function setSelectedCellProperties(transaction, context, properties) {
2807
+ const positions = context.map.cellsInRect({
2808
+ left: context.left,
2809
+ right: context.right,
2810
+ top: context.top,
2811
+ bottom: context.bottom
2812
+ });
2813
+ for (const relativePosition of positions){
2814
+ const position = context.tableStart + relativePosition;
2815
+ const current = transaction.doc.nodeAt(position);
2816
+ if (current && isTableCell(current)) transaction.setNodeMarkup(position, void 0, {
2817
+ ...current.attrs,
2818
+ verticalAlign: properties.verticalAlign,
2819
+ margins: properties.margins
2820
+ });
2821
+ }
2822
+ }
2823
+ function canRepeatSelectedTableRows(context) {
2824
+ let leadingRepeatCount = 0;
2825
+ for(let index = 0; index < context.table.childCount; index += 1){
2826
+ if (!documentTableRowRepeats(context.table.child(index))) break;
2827
+ leadingRepeatCount += 1;
2828
+ }
2829
+ return context.top <= leadingRepeatCount;
2830
+ }
2831
+ function setTableGeometryAttribute(transaction, context, geometry) {
2832
+ const position = context.tableStart - 1;
2833
+ const table = transaction.doc.nodeAt(position);
2834
+ if (!table) return;
2835
+ transaction.setNodeMarkup(position, void 0, {
2836
+ ...table.attrs,
2837
+ geometry: normalizeDocumentTableGeometry(geometry),
2838
+ layoutMode: null
2839
+ });
2840
+ }
2841
+ function setFixedTableGeometryFromColumns(transaction, context) {
2842
+ const table = transaction.doc.nodeAt(context.tableStart - 1);
2843
+ if (!table || 'table' !== table.type.spec.tableRole) return;
2844
+ setTableGeometryAttribute(transaction, context, fixedGeometryForTable(table));
2845
+ }
2846
+ function tableGeometry(table) {
2847
+ return normalizeDocumentTableGeometry(table.attrs.geometry, table.attrs.layoutMode);
2848
+ }
2849
+ function fixedGeometryForTable(table) {
2850
+ const geometry = tableGeometry(table);
2851
+ const widths = tableColumnWidths(table, TableMap.get(table));
2852
+ const total = widths.every((width)=>null !== width && width > 0) ? widths.reduce((sum, width)=>sum + width, 0) : null;
2853
+ return {
2854
+ ...geometry,
2855
+ layout: 'fixed',
2856
+ width: null === total ? geometry.width : {
2857
+ type: 'pixels',
2858
+ value: Math.round(100 * total) / 100
2859
+ }
2860
+ };
2861
+ }
2862
+ function tableColumnWidths(table, map) {
2863
+ return Array.from({
2864
+ length: map.width
2865
+ }, (_unused, column)=>{
2866
+ for(let row = 0; row < map.height; row += 1){
2867
+ const position = map.map[row * map.width + column];
2868
+ if (void 0 === position) continue;
2869
+ const cell = table.nodeAt(position);
2870
+ const index = column - map.colCount(position);
2871
+ const value = Array.isArray(cell?.attrs.colwidth) ? Number(cell.attrs.colwidth[index]) : 0;
2872
+ if (Number.isFinite(value) && value > 0) return value;
2873
+ }
2874
+ return null;
2875
+ });
2876
+ }
2877
+ function tableRowSizes(table) {
2878
+ const sizes = [];
2879
+ table.forEach((row)=>{
2880
+ sizes.push(documentTableRowHeight(row.attrs));
2881
+ });
2882
+ return sizes;
2883
+ }
2884
+ function tableHasExplicitColumnWidths(table) {
2885
+ let found = false;
2886
+ table.descendants((node)=>{
2887
+ if (!isTableCell(node)) return true;
2888
+ if (Array.isArray(node.attrs.colwidth) && node.attrs.colwidth.some((width)=>Number(width) > 0)) found = true;
2889
+ return !found;
2890
+ });
2891
+ return found;
2892
+ }
2893
+ function documentTables(document1) {
2894
+ const tables = [];
2895
+ document1.descendants((node)=>{
2896
+ if ('table' !== node.type.spec.tableRole) return true;
2897
+ tables.push(node);
2898
+ return false;
2899
+ });
2900
+ return tables;
2901
+ }
2902
+ function tableColumnWidthSignature(table) {
2903
+ if (!table) return '';
2904
+ const widths = [];
2905
+ table.descendants((node)=>{
2906
+ if (!isTableCell(node)) return true;
2907
+ widths.push(node.attrs.colwidth ?? null);
2908
+ return false;
2909
+ });
2910
+ return JSON.stringify(widths);
2911
+ }
2912
+ function isTableCell(node) {
2913
+ return 'cell' === node.type.spec.tableRole || 'header_cell' === node.type.spec.tableRole;
2914
+ }
2915
+ function normalizeRenderedDimensions(values, expectedCount, minimum) {
2916
+ if (!values || values.length !== expectedCount) return null;
2917
+ const normalized = values.map((value)=>normalizeDocumentTableDimension(value, minimum));
2918
+ return normalized.every((value)=>null !== value) ? normalized : null;
2919
+ }
2920
+ function numberRange(start, end) {
2921
+ return Array.from({
2922
+ length: Math.max(0, end - start)
2923
+ }, (_unused, index)=>start + index);
2924
+ }
2925
+ function distributionTotal(existing, rendered, fallback) {
2926
+ if (Number.isFinite(rendered) && Number(rendered) > 0) return Number(rendered);
2927
+ if (existing.every((value)=>null !== value && value > 0)) return existing.reduce((sum, value)=>sum + Number(value), 0);
2928
+ return fallback * existing.length;
2929
+ }
2930
+ function equalDimensions(total, count, minimum) {
2931
+ const size = Math.max(minimum, Math.round(total / count * 100) / 100);
2932
+ return Array.from({
2933
+ length: count
2934
+ }, ()=>size);
2935
+ }
2936
+ function commonPositiveValue(values) {
2937
+ if (!values.length || values.some((value)=>null === value || value <= 0)) return null;
2938
+ return values.every((value)=>value === values[0]) ? values[0] : null;
2939
+ }
2940
+ function commonNullableValue(values) {
2941
+ if (!values.length || values.some((value)=>null === value)) return null;
2942
+ return values.every((value)=>value === values[0]) ? values[0] : null;
2943
+ }
2369
2944
  function createWorkDocumentExtensions(options = {}) {
2370
2945
  const changeExtension = DocumentChange.configure({
2371
2946
  ...options.isTracking ? {
@@ -2447,8 +3022,8 @@ function createWorkDocumentExtensions(options = {}) {
2447
3022
  DocumentTableCommands,
2448
3023
  DocumentTableFormatting,
2449
3024
  DocumentTableSizing,
2450
- TextStyle,
2451
- font_family,
3025
+ DocumentTextStyle,
3026
+ DocumentFontFamily,
2452
3027
  font_size,
2453
3028
  extension_color,
2454
3029
  extension_highlight.configure({
@@ -2467,4 +3042,4 @@ function createWorkDocumentExtensions(options = {}) {
2467
3042
  changeExtension
2468
3043
  ];
2469
3044
  }
2470
- export { DocumentSubscript, DocumentSuperscript, MAX_DOCUMENT_NUMBERING_START, activeDocumentSection, canInsertDocumentComment, collectDocumentChanges, collectDocumentCommentAnchors, createWorkDocumentExtensions, documentBulletListStyle, documentCitationCount, documentCommentDraftRange, documentCommentViews, documentOrderedListState, documentSectionById, documentTabLeaderLabel, editorDocumentCaptionTargets, retainAnchoredDocumentComments };
3045
+ export { DocumentSubscript, DocumentSuperscript, MAX_DOCUMENT_NUMBERING_START, activeDocumentSection, canInsertDocumentComment, collectDocumentChanges, collectDocumentCommentAnchors, createWorkDocumentExtensions, documentBulletListStyle, documentCitationCount, documentCommentDraftRange, documentCommentViews, documentOrderedListState, documentSectionById, documentTabLeaderLabel, documentTableSizing, editorDocumentCaptionTargets, retainAnchoredDocumentComments };
@@ -1,6 +1,6 @@
1
1
  import { generateHTML, getSchema } from "@tiptap/core";
2
2
  import { DOMParser as model_DOMParser } from "@tiptap/pm/model";
3
- import { createWorkDocumentModel, syncDocumentContentFromHtml, documentModelForContent, documentHtmlFingerprint } from "./4704.js";
3
+ import { createWorkDocumentModel, syncDocumentContentFromHtml, documentModelForContent, documentHtmlFingerprint } from "./2881.js";
4
4
  import { createWorkDocumentExtensions } from "./0~work-document-extensions.js";
5
5
  let schema = null;
6
6
  let extensions = null;
@@ -1,6 +1,6 @@
1
1
  import jszip from "jszip";
2
2
  import { directChild, directChildren, attribute, parseXml } from "./8715.js";
3
- import { documentCitationStyle, createDocumentBibliography, documentCitationStyleDetails } from "./4704.js";
3
+ import { documentCitationStyle, createDocumentBibliography, documentCitationStyleDetails } from "./2881.js";
4
4
  const BIBLIOGRAPHY_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/bibliography';
5
5
  const CUSTOM_XML_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/customXml';
6
6
  const OFFICE_RELATIONSHIPS_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships';