@a200888213/gbdocx 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +215 -207
  2. package/index.html +3 -2
  3. package/package.json +48 -48
  4. package/serve.mjs +3 -2
  5. package/src/app/file-io.js +122 -122
  6. package/src/app/main.js +9 -9
  7. package/src/app/word/catalog.js +52 -52
  8. package/src/app/word/comments.js +112 -112
  9. package/src/app/word/doc.js +113 -113
  10. package/src/app/word/edit.js +72 -72
  11. package/src/app/word/file.js +30 -1
  12. package/src/app/word/hf.js +76 -76
  13. package/src/app/word/layout.js +155 -155
  14. package/src/app/word/notes.js +110 -110
  15. package/src/app/word/shared.js +22 -22
  16. package/src/app/word/view.js +22 -6
  17. package/src/app/word-app.js +486 -467
  18. package/src/app/word-sheets.js +101 -101
  19. package/src/kernel/docx/codec/blocks.js +123 -123
  20. package/src/kernel/docx/codec/carry.js +129 -129
  21. package/src/kernel/docx/codec/comments.js +25 -25
  22. package/src/kernel/docx/codec/docx.js +198 -198
  23. package/src/kernel/docx/codec/docxStyles.js +177 -177
  24. package/src/kernel/docx/codec/fonts.js +195 -195
  25. package/src/kernel/docx/codec/helpers.js +161 -161
  26. package/src/kernel/docx/codec/hfHtml.js +152 -152
  27. package/src/kernel/docx/codec/html.js +739 -739
  28. package/src/kernel/docx/codec/losses.js +420 -420
  29. package/src/kernel/docx/codec/markdown.js +170 -170
  30. package/src/kernel/docx/codec/parts.js +249 -249
  31. package/src/kernel/docx/codec/read.js +603 -603
  32. package/src/kernel/docx/codec/render.js +1156 -1156
  33. package/src/kernel/docx/codec/roundtrip.js +236 -236
  34. package/src/kernel/docx/codec/write.js +833 -833
  35. package/src/kernel/docx/comments.js +14 -14
  36. package/src/kernel/docx/pageGeometry.js +123 -123
  37. package/src/kernel/docx/pagination.js +481 -481
  38. package/src/kernel/docx/watermark.js +45 -45
  39. package/src/kernel/editor/constants.js +8 -8
  40. package/src/kernel/editor/engine/blocks.js +594 -594
  41. package/src/kernel/editor/engine/blocksEnter.js +109 -109
  42. package/src/kernel/editor/engine/blocksInsert.js +254 -254
  43. package/src/kernel/editor/engine/blocksStructure.js +226 -226
  44. package/src/kernel/editor/engine/commands.js +181 -181
  45. package/src/kernel/editor/engine/dom.js +646 -646
  46. package/src/kernel/editor/engine/history.js +149 -149
  47. package/src/kernel/editor/engine/inline.js +656 -656
  48. package/src/kernel/editor/engine/input.js +554 -554
  49. package/src/kernel/editor/engine/interaction.js +137 -137
  50. package/src/kernel/editor/engine/pointer.js +39 -39
  51. package/src/kernel/editor/engine/revision.js +138 -138
  52. package/src/kernel/editor/engine/schema.js +417 -417
  53. package/src/kernel/editor/engine/selection.js +119 -119
  54. package/src/kernel/editor/engine/state.js +118 -118
  55. package/src/kernel/editor/engine/tableClip.js +154 -154
  56. package/src/kernel/editor/engine/tableGrid.js +55 -55
  57. package/src/kernel/editor/engine/tableInteraction.js +388 -388
  58. package/src/kernel/editor/engine/tableMenu.js +250 -250
  59. package/src/kernel/editor/engine/tableOps.js +174 -174
  60. package/src/kernel/editor/engine/tables.js +732 -732
  61. package/src/kernel/editor/overlayGeometry.js +20 -20
  62. package/src/kernel/editor/utils.js +48 -48
  63. package/src/kernel/keyboard.js +114 -114
  64. package/src/kernel/textStyles.js +84 -84
  65. package/src/kernel/util/imageFile.js +91 -91
  66. package/src/kernel/util/shortcutKey.js +33 -33
  67. package/src/surface/editor-surface.js +600 -600
  68. package/src/ui/color-panel.js +69 -69
  69. package/src/ui/context-menu.js +133 -133
  70. package/src/ui/find-bar.js +151 -151
  71. package/src/ui/icons.js +137 -135
  72. package/src/ui/menubar.js +28 -28
  73. package/src/ui/panels.js +115 -115
  74. package/src/ui/prompt.js +89 -89
  75. package/src/ui/ribbon.js +485 -485
  76. package/src/ui/special-chars.js +39 -39
  77. package/src/ui/statusbar.js +81 -81
  78. package/src/ui/toolbar.js +32 -32
  79. package/styles/editor-content.css +440 -440
  80. package/styles/tokens.css +154 -154
@@ -1,109 +1,109 @@
1
- // [文件] web·editor-kernel·blocks·回车与退格 —— 硬换行/代码块换行/向后合块/退格计划
2
- import { blockLength, blockOf, charOffset, firstTextBlockIn, isBlockEmpty, isCell, isTextBlock, moveChildren, rangeOf, setCaret } from './dom.js';
3
- import { liftOneOutOf, listItemOf, noteContainerOf, pruneEmpty, quoteOf, releaseListItem } from './blocks.js';
4
- import { liftListItem, settleBlock } from './blocksStructure.js';
5
-
6
- /** 换行(Shift+Enter 与单元格内回车) */
7
- export function insertHardBreak(range) {
8
- const br = document.createElement('br');
9
- range.insertNode(br);
10
- const anchor = document.createTextNode('');
11
- br.after(anchor);
12
- const sel = window.getSelection();
13
- const next = document.createRange();
14
- next.setStart(anchor, 0);
15
- next.collapse(true);
16
- sel.removeAllRanges();
17
- sel.addRange(next);
18
- return true;
19
- }
20
-
21
- /** 代码块内回车 = 真的换行 */
22
- export function insertNewlineInCode(code, range) {
23
- const node = range.startContainer;
24
- if (node.nodeType !== Node.TEXT_NODE) {
25
- code.appendChild(document.createTextNode('\n'));
26
- const sel = window.getSelection();
27
- const next = document.createRange();
28
- next.setStart(code.lastChild, 1);
29
- next.collapse(true);
30
- sel.removeAllRanges();
31
- sel.addRange(next);
32
- return true;
33
- }
34
- const after = node.splitText(range.startOffset);
35
- node.appendData('\n');
36
- const sel = window.getSelection();
37
- const next = document.createRange();
38
- next.setStart(after, 0);
39
- next.collapse(true);
40
- sel.removeAllRanges();
41
- sel.addRange(next);
42
- return true;
43
- }
44
-
45
- /**
46
- * 段首退格:把本块并回上一块,或删掉这一行空段
47
- * [坑] 表格单元格的 prev 就是同一行的左邻格,跨格合并会撕坏网格 → 直接交给原生行为;
48
- * 列表项与引用各有自己的分支(在上面提前返回),代码块内没有同级文本块,都不会走到这里
49
- */
50
- function mergeBackward(block, root) {
51
- if (isCell(block)) return null;
52
- const prev = block.previousElementSibling;
53
- if (!prev) return null;
54
- if (isTextBlock(prev, root)) {
55
- const at = blockLength(prev);
56
- const carry = !isBlockEmpty(block);
57
- return () => {
58
- if (carry) {
59
- // 前块只剩占位 br:先清空,否则并进来的正文前多出一个空行
60
- if (isBlockEmpty(prev)) prev.replaceChildren();
61
- moveChildren(block, prev);
62
- }
63
- block.remove();
64
- settleBlock(prev);
65
- setCaret(prev, at);
66
- };
67
- }
68
- // 上一块是结构块(分割线 / 图片 / 列表 / 表格 / 代码块):只有本块是空行才删,且必须先找到落脚点
69
- if (!isBlockEmpty(block)) return null;
70
- const landing = firstTextBlockIn(prev, root) || firstTextBlockIn(block.nextElementSibling, root);
71
- if (!landing) return null;
72
- return () => {
73
- block.remove();
74
- setCaret(landing, 0);
75
- };
76
- }
77
-
78
- /**
79
- * 光标在块首退格的动作计划(纯判据不改 DOM;返回 null 表示交给浏览器合并块)
80
- * [设计] 判据与执行分离:输入层要先知道「本键是否被内核接管」才能决定 preventDefault。
81
- */
82
- export function backspacePlan(root) {
83
- const range = rangeOf(root);
84
- if (!range || !range.collapsed) return null;
85
- const block = blockOf(range.startContainer, root);
86
- if (!block) return null;
87
- if (charOffset(block, range.startContainer, range.startOffset) !== 0) return null;
88
-
89
- const li = listItemOf(block, root);
90
- if (li) {
91
- // 行首退格把列表项提成段落:若该列表原是高亮块/超级块内唯一内容,提完要顺带收掉空容器(否则空容器残留)
92
- const nc = noteContainerOf(block, root);
93
- if (isBlockEmpty(block)) {
94
- return () => {
95
- const released = releaseListItem(li);
96
- if (nc) pruneEmpty(nc);
97
- setCaret(released, 0);
98
- };
99
- }
100
- if (li.parentElement?.parentElement?.tagName === 'LI') return () => { liftListItem(li); setCaret(block, 0); };
101
- return null;
102
- }
103
- const quote = quoteOf(block, root);
104
- if (quote) return () => { liftOneOutOf(quote, block); pruneEmpty(quote); setCaret(block, 0); };
105
- // 高亮块/超级块行首退格:把本块提出容器(列归到其超级块),空容器/空列由 pruneEmpty 收尾
106
- const nc = noteContainerOf(block, root);
107
- if (nc) return () => { liftOneOutOf(nc, block); pruneEmpty(nc); setCaret(block, 0); };
108
- return mergeBackward(block, root);
109
- }
1
+ // [文件] web·editor-kernel·blocks·回车与退格 —— 硬换行/代码块换行/向后合块/退格计划
2
+ import { blockLength, blockOf, charOffset, firstTextBlockIn, isBlockEmpty, isCell, isTextBlock, moveChildren, rangeOf, setCaret } from './dom.js';
3
+ import { liftOneOutOf, listItemOf, noteContainerOf, pruneEmpty, quoteOf, releaseListItem } from './blocks.js';
4
+ import { liftListItem, settleBlock } from './blocksStructure.js';
5
+
6
+ /** 换行(Shift+Enter 与单元格内回车) */
7
+ export function insertHardBreak(range) {
8
+ const br = document.createElement('br');
9
+ range.insertNode(br);
10
+ const anchor = document.createTextNode('');
11
+ br.after(anchor);
12
+ const sel = window.getSelection();
13
+ const next = document.createRange();
14
+ next.setStart(anchor, 0);
15
+ next.collapse(true);
16
+ sel.removeAllRanges();
17
+ sel.addRange(next);
18
+ return true;
19
+ }
20
+
21
+ /** 代码块内回车 = 真的换行 */
22
+ export function insertNewlineInCode(code, range) {
23
+ const node = range.startContainer;
24
+ if (node.nodeType !== Node.TEXT_NODE) {
25
+ code.appendChild(document.createTextNode('\n'));
26
+ const sel = window.getSelection();
27
+ const next = document.createRange();
28
+ next.setStart(code.lastChild, 1);
29
+ next.collapse(true);
30
+ sel.removeAllRanges();
31
+ sel.addRange(next);
32
+ return true;
33
+ }
34
+ const after = node.splitText(range.startOffset);
35
+ node.appendData('\n');
36
+ const sel = window.getSelection();
37
+ const next = document.createRange();
38
+ next.setStart(after, 0);
39
+ next.collapse(true);
40
+ sel.removeAllRanges();
41
+ sel.addRange(next);
42
+ return true;
43
+ }
44
+
45
+ /**
46
+ * 段首退格:把本块并回上一块,或删掉这一行空段
47
+ * [坑] 表格单元格的 prev 就是同一行的左邻格,跨格合并会撕坏网格 → 直接交给原生行为;
48
+ * 列表项与引用各有自己的分支(在上面提前返回),代码块内没有同级文本块,都不会走到这里
49
+ */
50
+ function mergeBackward(block, root) {
51
+ if (isCell(block)) return null;
52
+ const prev = block.previousElementSibling;
53
+ if (!prev) return null;
54
+ if (isTextBlock(prev, root)) {
55
+ const at = blockLength(prev);
56
+ const carry = !isBlockEmpty(block);
57
+ return () => {
58
+ if (carry) {
59
+ // 前块只剩占位 br:先清空,否则并进来的正文前多出一个空行
60
+ if (isBlockEmpty(prev)) prev.replaceChildren();
61
+ moveChildren(block, prev);
62
+ }
63
+ block.remove();
64
+ settleBlock(prev);
65
+ setCaret(prev, at);
66
+ };
67
+ }
68
+ // 上一块是结构块(分割线 / 图片 / 列表 / 表格 / 代码块):只有本块是空行才删,且必须先找到落脚点
69
+ if (!isBlockEmpty(block)) return null;
70
+ const landing = firstTextBlockIn(prev, root) || firstTextBlockIn(block.nextElementSibling, root);
71
+ if (!landing) return null;
72
+ return () => {
73
+ block.remove();
74
+ setCaret(landing, 0);
75
+ };
76
+ }
77
+
78
+ /**
79
+ * 光标在块首退格的动作计划(纯判据不改 DOM;返回 null 表示交给浏览器合并块)
80
+ * [设计] 判据与执行分离:输入层要先知道「本键是否被内核接管」才能决定 preventDefault。
81
+ */
82
+ export function backspacePlan(root) {
83
+ const range = rangeOf(root);
84
+ if (!range || !range.collapsed) return null;
85
+ const block = blockOf(range.startContainer, root);
86
+ if (!block) return null;
87
+ if (charOffset(block, range.startContainer, range.startOffset) !== 0) return null;
88
+
89
+ const li = listItemOf(block, root);
90
+ if (li) {
91
+ // 行首退格把列表项提成段落:若该列表原是高亮块/超级块内唯一内容,提完要顺带收掉空容器(否则空容器残留)
92
+ const nc = noteContainerOf(block, root);
93
+ if (isBlockEmpty(block)) {
94
+ return () => {
95
+ const released = releaseListItem(li);
96
+ if (nc) pruneEmpty(nc);
97
+ setCaret(released, 0);
98
+ };
99
+ }
100
+ if (li.parentElement?.parentElement?.tagName === 'LI') return () => { liftListItem(li); setCaret(block, 0); };
101
+ return null;
102
+ }
103
+ const quote = quoteOf(block, root);
104
+ if (quote) return () => { liftOneOutOf(quote, block); pruneEmpty(quote); setCaret(block, 0); };
105
+ // 高亮块/超级块行首退格:把本块提出容器(列归到其超级块),空容器/空列由 pruneEmpty 收尾
106
+ const nc = noteContainerOf(block, root);
107
+ if (nc) return () => { liftOneOutOf(nc, block); pruneEmpty(nc); setCaret(block, 0); };
108
+ return mergeBackward(block, root);
109
+ }