@a200888213/gbdocx 0.6.1 → 0.6.3

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 (95) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +215 -215
  3. package/index.html +31 -30
  4. package/package.json +49 -48
  5. package/serve.mjs +27 -23
  6. package/src/app/file-io.js +122 -122
  7. package/src/app/main.js +9 -9
  8. package/src/app/word/catalog.js +52 -52
  9. package/src/app/word/comments.js +112 -112
  10. package/src/app/word/doc.js +113 -113
  11. package/src/app/word/edit.js +72 -72
  12. package/src/app/word/file.js +191 -191
  13. package/src/app/word/hf.js +76 -76
  14. package/src/app/word/layout.js +155 -155
  15. package/src/app/word/menus.js +201 -201
  16. package/src/app/word/notes.js +110 -110
  17. package/src/app/word/shared.js +22 -22
  18. package/src/app/word/view.js +159 -159
  19. package/src/app/word-app.js +487 -487
  20. package/src/app/word-sheets.js +101 -101
  21. package/src/kernel/docx/catalog.js +41 -41
  22. package/src/kernel/docx/codec/blocks.js +123 -123
  23. package/src/kernel/docx/codec/carry.js +129 -129
  24. package/src/kernel/docx/codec/comments.js +25 -25
  25. package/src/kernel/docx/codec/docx.js +198 -198
  26. package/src/kernel/docx/codec/docxStyles.js +177 -177
  27. package/src/kernel/docx/codec/fonts.js +195 -195
  28. package/src/kernel/docx/codec/helpers.js +161 -161
  29. package/src/kernel/docx/codec/hfHtml.js +152 -152
  30. package/src/kernel/docx/codec/html.js +739 -739
  31. package/src/kernel/docx/codec/losses.js +420 -420
  32. package/src/kernel/docx/codec/markdown.js +170 -170
  33. package/src/kernel/docx/codec/parts.js +249 -249
  34. package/src/kernel/docx/codec/read.js +603 -603
  35. package/src/kernel/docx/codec/render.js +1156 -1156
  36. package/src/kernel/docx/codec/roundtrip.js +236 -236
  37. package/src/kernel/docx/codec/write.js +833 -833
  38. package/src/kernel/docx/comments.js +14 -14
  39. package/src/kernel/docx/menus.js +348 -348
  40. package/src/kernel/docx/pageGeometry.js +123 -123
  41. package/src/kernel/docx/pagination.js +481 -481
  42. package/src/kernel/docx/watermark.js +45 -45
  43. package/src/kernel/docx/wordShortcuts.js +37 -37
  44. package/src/kernel/editor/constants.js +8 -8
  45. package/src/kernel/editor/engine/blocks.js +594 -594
  46. package/src/kernel/editor/engine/blocksEnter.js +109 -109
  47. package/src/kernel/editor/engine/blocksInsert.js +254 -254
  48. package/src/kernel/editor/engine/blocksStructure.js +226 -226
  49. package/src/kernel/editor/engine/commands.js +181 -181
  50. package/src/kernel/editor/engine/dom.js +646 -646
  51. package/src/kernel/editor/engine/editor.js +213 -213
  52. package/src/kernel/editor/engine/history.js +149 -149
  53. package/src/kernel/editor/engine/inline.js +656 -656
  54. package/src/kernel/editor/engine/input.js +554 -554
  55. package/src/kernel/editor/engine/interaction.js +137 -137
  56. package/src/kernel/editor/engine/pointer.js +39 -39
  57. package/src/kernel/editor/engine/revision.js +138 -138
  58. package/src/kernel/editor/engine/schema.js +417 -417
  59. package/src/kernel/editor/engine/search.js +113 -113
  60. package/src/kernel/editor/engine/selection.js +119 -119
  61. package/src/kernel/editor/engine/state.js +118 -118
  62. package/src/kernel/editor/engine/tableClip.js +154 -154
  63. package/src/kernel/editor/engine/tableGrid.js +55 -55
  64. package/src/kernel/editor/engine/tableInteraction.js +388 -388
  65. package/src/kernel/editor/engine/tableMenu.js +250 -250
  66. package/src/kernel/editor/engine/tableOps.js +174 -174
  67. package/src/kernel/editor/engine/tables.js +732 -732
  68. package/src/kernel/editor/overlayGeometry.js +20 -20
  69. package/src/kernel/editor/pasteClean.js +293 -293
  70. package/src/kernel/editor/utils.js +48 -48
  71. package/src/kernel/keyboard.js +114 -114
  72. package/src/kernel/notify.js +54 -54
  73. package/src/kernel/textStyles.js +84 -84
  74. package/src/kernel/util/clipboard.js +89 -89
  75. package/src/kernel/util/imageFile.js +91 -91
  76. package/src/kernel/util/safeValue.js +25 -25
  77. package/src/kernel/util/shortcutKey.js +33 -33
  78. package/src/surface/editor-surface.js +603 -600
  79. package/src/ui/color-panel.js +69 -69
  80. package/src/ui/context-menu.js +135 -133
  81. package/src/ui/dialogs.js +249 -249
  82. package/src/ui/find-bar.js +151 -151
  83. package/src/ui/icons.js +245 -137
  84. package/src/ui/menubar.js +28 -28
  85. package/src/ui/panels.js +115 -115
  86. package/src/ui/popup.js +79 -79
  87. package/src/ui/prompt.js +89 -89
  88. package/src/ui/ribbon.js +485 -485
  89. package/src/ui/special-chars.js +39 -39
  90. package/src/ui/statusbar.js +81 -81
  91. package/src/ui/toolbar.js +32 -32
  92. package/styles/app.css +970 -970
  93. package/styles/editor-content.css +440 -440
  94. package/styles/tokens.css +154 -154
  95. package/styles/word-panel.css +410 -410
@@ -1,22 +1,22 @@
1
- // [文件] gbdocx·word·shared —— 应用级常量与偏好读写(无 this,装配前后都是模块级函数)
2
-
3
- export const MD_MIME = 'text/markdown;charset=utf-8';
4
-
5
- /** 本机偏好存储键(缩放/自动保存/视图开关等,按环境共用一份) */
6
- const LS_KEY = 'gbdocx-word-prefs';
7
-
8
- export function loadPrefs() {
9
- try {
10
- return JSON.parse(localStorage.getItem(LS_KEY) || '{}') || {};
11
- } catch {
12
- return {};
13
- }
14
- }
15
-
16
- export function savePrefs(prefs) {
17
- try {
18
- localStorage.setItem(LS_KEY, JSON.stringify(prefs));
19
- } catch {
20
- /* 忽略存储失败 */
21
- }
22
- }
1
+ // [文件] gbdocx·word·shared —— 应用级常量与偏好读写(无 this,装配前后都是模块级函数)
2
+
3
+ export const MD_MIME = 'text/markdown;charset=utf-8';
4
+
5
+ /** 本机偏好存储键(缩放/自动保存/视图开关等,按环境共用一份) */
6
+ const LS_KEY = 'gbdocx-word-prefs';
7
+
8
+ export function loadPrefs() {
9
+ try {
10
+ return JSON.parse(localStorage.getItem(LS_KEY) || '{}') || {};
11
+ } catch {
12
+ return {};
13
+ }
14
+ }
15
+
16
+ export function savePrefs(prefs) {
17
+ try {
18
+ localStorage.setItem(LS_KEY, JSON.stringify(prefs));
19
+ } catch {
20
+ /* 忽略存储失败 */
21
+ }
22
+ }
@@ -1,159 +1,159 @@
1
- // [文件] gbdocx·word·view —— 视图与对话框 —— 视图开关、面板、页面设置/页边距/分栏
2
-
3
- // [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { cleanHfHtml } from '../../kernel/docx/codec/helpers.js';
7
- import { openColumnDialog as openColumnDialogUI, openMarginDialog as openMarginDialogUI, openPageSetupDialog as openPageSetupDialogUI } from '../../ui/dialogs.js';
8
- import { icon } from '../../ui/icons.js';
9
- import { savePrefs } from './shared.js';
10
-
11
- /** 预览模式:只读 + 收起编辑界面;按钮留在文件头行原位,再点或按 Esc 退出 */
12
- function setPreview(on) {
13
- const next = !!on;
14
- if (next === this.preview) return;
15
- if (next) {
16
- this.previewRestore = { readOnly: this.readOnly, mode: this.editMode, menuBar: this.menuBarVisible };
17
- this.preview = true;
18
- this.root.classList.add('gb-is-preview');
19
- this.previewBtn.setAttribute('aria-pressed', 'true');
20
- this.previewBtn.title = '退出预览';
21
- this.previewBtn.querySelector('span').textContent = '退出预览';
22
- this.setReadOnly(true);
23
- this.setMenuBarVisible(false);
24
- } else {
25
- const restore = this.previewRestore || { readOnly: false, mode: 'edit', menuBar: true };
26
- this.preview = false;
27
- this.root.classList.remove('gb-is-preview');
28
- this.previewBtn.setAttribute('aria-pressed', 'false');
29
- this.previewBtn.title = '预览模式';
30
- this.previewBtn.querySelector('span').textContent = '预览';
31
- this.setReadOnly(restore.readOnly);
32
- if (!restore.readOnly) this.setEditMode(restore.mode);
33
- this.setMenuBarVisible(restore.menuBar);
34
- this.previewRestore = null;
35
- }
36
- this.previewBtn.blur();
37
- }
38
-
39
- /** 全屏/恢复:整个 Word 应用铺满网页(页面内覆盖;不用原生 Fullscreen,
40
- * 否则 append 到 body 的菜单/弹窗在全屏层外不可见) */
41
- function toggleFullscreen() {
42
- this.setPageFullscreen(!this.pageFullscreen);
43
- }
44
-
45
- function setPageFullscreen(on) {
46
- const next = !!on;
47
- if (next === this.pageFullscreen) return;
48
- this.pageFullscreen = next;
49
- if (next) {
50
- // [坑] 页面主容器常是 position:fixed(自带层叠上下文),留在原位压不过全局顶栏;
51
- // 整个 .word-scope 挂到 body 顶层,作用域样式随节点一起走
52
- this.fsHome = { parent: this.scopeEl.parentNode, next: this.scopeEl.nextSibling };
53
- this.root.classList.add('gbd-is-pagefullscreen');
54
- document.body.appendChild(this.scopeEl);
55
- document.addEventListener('keydown', this.onFullscreenEsc, true);
56
- } else {
57
- this.root.classList.remove('gbd-is-pagefullscreen');
58
- if (this.fsHome?.parent) this.fsHome.parent.insertBefore(this.scopeEl, this.fsHome.next);
59
- this.fsHome = null;
60
- document.removeEventListener('keydown', this.onFullscreenEsc, true);
61
- }
62
- this.renderFullscreenBtn();
63
- }
64
-
65
- function renderFullscreenBtn() {
66
- const active = this.pageFullscreen;
67
- this.fullscreenBtn.title = active ? '退出全屏' : '全屏';
68
- this.fullscreenBtn.setAttribute('aria-pressed', String(active));
69
- this.fullscreenBtn.innerHTML = `${icon(active ? 'fullscreenExit' : 'fullscreen')}<span>${active ? '恢复' : '全屏'}</span>`;
70
- }
71
-
72
- function setView(key, on) {
73
- const next = on === undefined ? !this.flags[key] : !!on;
74
- this.flags = { ...this.flags, [key]: next };
75
- this.prefs.flags = this.flags;
76
- savePrefs(this.prefs);
77
- this.applyView();
78
- }
79
-
80
- function applyView() {
81
- const main = this.root.querySelector('.word-main');
82
- const hasCatalog = this.flags.catalog;
83
- const hasComments = this.flags.commentsPanel;
84
- if (hasCatalog && !this.catalogPanel.el.isConnected) main.insertBefore(this.catalogPanel.el, this.editorWrap);
85
- if (!hasCatalog && this.catalogPanel.el.isConnected) this.catalogPanel.el.remove();
86
- if (hasComments && !this.commentsPanel.el.isConnected) main.appendChild(this.commentsPanel.el);
87
- if (!hasComments && this.commentsPanel.el.isConnected) this.commentsPanel.el.remove();
88
- if (hasCatalog) this.refreshCatalog();
89
- this.renderPanels();
90
- this.ribbon?.refresh();
91
- }
92
-
93
- function renderPanels() {
94
- if (this.flags.commentsPanel) {
95
- this.commentsPanel.activeKey = this.activeCommentKey;
96
- this.commentsPanel.setItems(this.comments);
97
- }
98
- }
99
-
100
- function renderHead() {
101
- // 嵌入模式:标题与路径由宿主给(服务端文档名/所在目录),本地 doc 只作兜底
102
- const hostTitle = this.embed ? this.io?.getTitle?.() : '';
103
- this.titleEl.textContent = hostTitle || this.doc.name || '新建文档';
104
- const hostPath = this.embed ? this.io?.getPath?.() : '';
105
- this.pathEl.textContent = hostPath
106
- || (this.embed ? '' : this.doc.pathText || (this.doc.handle ? '(已关联文件)' : '(未关联文件,保存将另存为)'));
107
- // 嵌入模式:保存状态由宿主给(落盘结果只有宿主知道)
108
- const hostStatus = this.embed ? this.io?.getStatus?.() : null;
109
- this.statusEl.textContent = hostStatus?.text || '';
110
- this.dirtyEl.hidden = !this.dirty;
111
- }
112
-
113
- function openPageSetupDialog() {
114
- openPageSetupDialogUI({
115
- page: this.state.page,
116
- pageNumbers: this.state.pageNumbers,
117
- watermark: this.state.watermark,
118
- hfMode: this.state.hfMode,
119
- header: this.state.header,
120
- footer: this.state.footer,
121
- headerFirst: this.state.headerFirst,
122
- footerFirst: this.state.footerFirst,
123
- }, (out) => {
124
- const prevHf = { header: this.state.header, footer: this.state.footer, headerFirst: this.state.headerFirst, footerFirst: this.state.footerFirst };
125
- this.state.page = { ...this.state.page, ...out.page };
126
- this.state.pageNumbers = out.pageNumbers;
127
- this.state.watermark = out.watermark;
128
- this.state.hfMode = out.hfMode;
129
- this.state.header = cleanHfHtml(out.header);
130
- this.state.footer = cleanHfHtml(out.footer);
131
- this.state.headerFirst = cleanHfHtml(out.headerFirst);
132
- this.state.footerFirst = cleanHfHtml(out.footerFirst);
133
- // 只有「新写入的文字」才把「不显示」自动拉回显示;用户明确选「不显示」而文字没变时必须尊重选择
134
- const changedToText = ['header', 'footer', 'headerFirst', 'footerFirst']
135
- .some((key) => this.state[key] !== prevHf[key] && this.state[key].replace(/<[^>]*>/g, '').trim());
136
- if (changedToText && this.state.hfMode === 'none') this.state.hfMode = 'all';
137
- this.onDocUpdate();
138
- this.applyEditorGeometry();
139
- this.paginate();
140
- });
141
- }
142
-
143
- function openMarginDialog() {
144
- openMarginDialogUI(this.state.page.margins, (margins) => {
145
- this.state.page = { ...this.state.page, margins };
146
- this.onDocUpdate();
147
- this.paginate();
148
- });
149
- }
150
-
151
- function openColumnDialog() {
152
- openColumnDialogUI(this.state.page, (patch) => {
153
- this.state.page = { ...this.state.page, ...patch };
154
- this.onDocUpdate();
155
- this.paginate();
156
- });
157
- }
158
-
159
- export const viewMethods = { setView, applyView, renderPanels, renderHead, openPageSetupDialog, openMarginDialog, openColumnDialog, setPreview, toggleFullscreen, setPageFullscreen, renderFullscreenBtn };
1
+ // [文件] gbdocx·word·view —— 视图与对话框 —— 视图开关、面板、页面设置/页边距/分栏
2
+
3
+ // [设计] 方法以独立函数导出,由 word-app.js 末尾 Object.assign 装配到 WordApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { cleanHfHtml } from '../../kernel/docx/codec/helpers.js';
7
+ import { openColumnDialog as openColumnDialogUI, openMarginDialog as openMarginDialogUI, openPageSetupDialog as openPageSetupDialogUI } from '../../ui/dialogs.js';
8
+ import { icon } from '../../ui/icons.js';
9
+ import { savePrefs } from './shared.js';
10
+
11
+ /** 预览模式:只读 + 收起编辑界面;按钮留在文件头行原位,再点或按 Esc 退出 */
12
+ function setPreview(on) {
13
+ const next = !!on;
14
+ if (next === this.preview) return;
15
+ if (next) {
16
+ this.previewRestore = { readOnly: this.readOnly, mode: this.editMode, menuBar: this.menuBarVisible };
17
+ this.preview = true;
18
+ this.root.classList.add('gb-is-preview');
19
+ this.previewBtn.setAttribute('aria-pressed', 'true');
20
+ this.previewBtn.title = '退出预览';
21
+ this.previewBtn.querySelector('span').textContent = '退出预览';
22
+ this.setReadOnly(true);
23
+ this.setMenuBarVisible(false);
24
+ } else {
25
+ const restore = this.previewRestore || { readOnly: false, mode: 'edit', menuBar: true };
26
+ this.preview = false;
27
+ this.root.classList.remove('gb-is-preview');
28
+ this.previewBtn.setAttribute('aria-pressed', 'false');
29
+ this.previewBtn.title = '预览模式';
30
+ this.previewBtn.querySelector('span').textContent = '预览';
31
+ this.setReadOnly(restore.readOnly);
32
+ if (!restore.readOnly) this.setEditMode(restore.mode);
33
+ this.setMenuBarVisible(restore.menuBar);
34
+ this.previewRestore = null;
35
+ }
36
+ this.previewBtn.blur();
37
+ }
38
+
39
+ /** 全屏/恢复:整个 Word 应用铺满网页(页面内覆盖;不用原生 Fullscreen,
40
+ * 否则 append 到 body 的菜单/弹窗在全屏层外不可见) */
41
+ function toggleFullscreen() {
42
+ this.setPageFullscreen(!this.pageFullscreen);
43
+ }
44
+
45
+ function setPageFullscreen(on) {
46
+ const next = !!on;
47
+ if (next === this.pageFullscreen) return;
48
+ this.pageFullscreen = next;
49
+ if (next) {
50
+ // [坑] 页面主容器常是 position:fixed(自带层叠上下文),留在原位压不过全局顶栏;
51
+ // 整个 .word-scope 挂到 body 顶层,作用域样式随节点一起走
52
+ this.fsHome = { parent: this.scopeEl.parentNode, next: this.scopeEl.nextSibling };
53
+ this.root.classList.add('gbd-is-pagefullscreen');
54
+ document.body.appendChild(this.scopeEl);
55
+ document.addEventListener('keydown', this.onFullscreenEsc, true);
56
+ } else {
57
+ this.root.classList.remove('gbd-is-pagefullscreen');
58
+ if (this.fsHome?.parent) this.fsHome.parent.insertBefore(this.scopeEl, this.fsHome.next);
59
+ this.fsHome = null;
60
+ document.removeEventListener('keydown', this.onFullscreenEsc, true);
61
+ }
62
+ this.renderFullscreenBtn();
63
+ }
64
+
65
+ function renderFullscreenBtn() {
66
+ const active = this.pageFullscreen;
67
+ this.fullscreenBtn.title = active ? '退出全屏' : '全屏';
68
+ this.fullscreenBtn.setAttribute('aria-pressed', String(active));
69
+ this.fullscreenBtn.innerHTML = `${icon(active ? 'fullscreenExit' : 'fullscreen')}<span>${active ? '恢复' : '全屏'}</span>`;
70
+ }
71
+
72
+ function setView(key, on) {
73
+ const next = on === undefined ? !this.flags[key] : !!on;
74
+ this.flags = { ...this.flags, [key]: next };
75
+ this.prefs.flags = this.flags;
76
+ savePrefs(this.prefs);
77
+ this.applyView();
78
+ }
79
+
80
+ function applyView() {
81
+ const main = this.root.querySelector('.word-main');
82
+ const hasCatalog = this.flags.catalog;
83
+ const hasComments = this.flags.commentsPanel;
84
+ if (hasCatalog && !this.catalogPanel.el.isConnected) main.insertBefore(this.catalogPanel.el, this.editorWrap);
85
+ if (!hasCatalog && this.catalogPanel.el.isConnected) this.catalogPanel.el.remove();
86
+ if (hasComments && !this.commentsPanel.el.isConnected) main.appendChild(this.commentsPanel.el);
87
+ if (!hasComments && this.commentsPanel.el.isConnected) this.commentsPanel.el.remove();
88
+ if (hasCatalog) this.refreshCatalog();
89
+ this.renderPanels();
90
+ this.ribbon?.refresh();
91
+ }
92
+
93
+ function renderPanels() {
94
+ if (this.flags.commentsPanel) {
95
+ this.commentsPanel.activeKey = this.activeCommentKey;
96
+ this.commentsPanel.setItems(this.comments);
97
+ }
98
+ }
99
+
100
+ function renderHead() {
101
+ // 嵌入模式:标题与路径由宿主给(服务端文档名/所在目录),本地 doc 只作兜底
102
+ const hostTitle = this.embed ? this.io?.getTitle?.() : '';
103
+ this.titleEl.textContent = hostTitle || this.doc.name || '新建文档';
104
+ const hostPath = this.embed ? this.io?.getPath?.() : '';
105
+ this.pathEl.textContent = hostPath
106
+ || (this.embed ? '' : this.doc.pathText || (this.doc.handle ? '(已关联文件)' : '(未关联文件,保存将另存为)'));
107
+ // 嵌入模式:保存状态由宿主给(落盘结果只有宿主知道)
108
+ const hostStatus = this.embed ? this.io?.getStatus?.() : null;
109
+ this.statusEl.textContent = hostStatus?.text || '';
110
+ this.dirtyEl.hidden = !this.dirty;
111
+ }
112
+
113
+ function openPageSetupDialog() {
114
+ openPageSetupDialogUI({
115
+ page: this.state.page,
116
+ pageNumbers: this.state.pageNumbers,
117
+ watermark: this.state.watermark,
118
+ hfMode: this.state.hfMode,
119
+ header: this.state.header,
120
+ footer: this.state.footer,
121
+ headerFirst: this.state.headerFirst,
122
+ footerFirst: this.state.footerFirst,
123
+ }, (out) => {
124
+ const prevHf = { header: this.state.header, footer: this.state.footer, headerFirst: this.state.headerFirst, footerFirst: this.state.footerFirst };
125
+ this.state.page = { ...this.state.page, ...out.page };
126
+ this.state.pageNumbers = out.pageNumbers;
127
+ this.state.watermark = out.watermark;
128
+ this.state.hfMode = out.hfMode;
129
+ this.state.header = cleanHfHtml(out.header);
130
+ this.state.footer = cleanHfHtml(out.footer);
131
+ this.state.headerFirst = cleanHfHtml(out.headerFirst);
132
+ this.state.footerFirst = cleanHfHtml(out.footerFirst);
133
+ // 只有「新写入的文字」才把「不显示」自动拉回显示;用户明确选「不显示」而文字没变时必须尊重选择
134
+ const changedToText = ['header', 'footer', 'headerFirst', 'footerFirst']
135
+ .some((key) => this.state[key] !== prevHf[key] && this.state[key].replace(/<[^>]*>/g, '').trim());
136
+ if (changedToText && this.state.hfMode === 'none') this.state.hfMode = 'all';
137
+ this.onDocUpdate();
138
+ this.applyEditorGeometry();
139
+ this.paginate();
140
+ });
141
+ }
142
+
143
+ function openMarginDialog() {
144
+ openMarginDialogUI(this.state.page.margins, (margins) => {
145
+ this.state.page = { ...this.state.page, margins };
146
+ this.onDocUpdate();
147
+ this.paginate();
148
+ });
149
+ }
150
+
151
+ function openColumnDialog() {
152
+ openColumnDialogUI(this.state.page, (patch) => {
153
+ this.state.page = { ...this.state.page, ...patch };
154
+ this.onDocUpdate();
155
+ this.paginate();
156
+ });
157
+ }
158
+
159
+ export const viewMethods = { setView, applyView, renderPanels, renderHead, openPageSetupDialog, openMarginDialog, openColumnDialog, setPreview, toggleFullscreen, setPageFullscreen, renderFullscreenBtn };