@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,69 +1,69 @@
1
- // [文件] gbdocx·ColorPanel —— 文字颜色/底色色板(预设格里 + 系统色轮 + Hex + 清除)
2
- import { openPopup } from './popup.js';
3
-
4
- /** 打开色板;onPick(color) 回调(清除传空串) */
5
- export function openColorPanel({ anchor, colors, value, title, columns = 10, onPick }) {
6
- const box = document.createElement('div');
7
- box.className = 'gbd-color';
8
- const head = document.createElement('div');
9
- head.className = 'gbd-color__title';
10
- head.textContent = title || '颜色';
11
- box.appendChild(head);
12
-
13
- const grid = document.createElement('div');
14
- grid.className = 'gbd-color__grid';
15
- grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
16
- for (const color of colors) {
17
- const sw = document.createElement('button');
18
- sw.type = 'button';
19
- sw.className = 'gbd-color__swatch';
20
- sw.style.background = color;
21
- if (value && value.toLowerCase() === color.toLowerCase()) sw.classList.add('gbd-is-active');
22
- sw.title = color;
23
- sw.addEventListener('click', () => {
24
- handle.close();
25
- onPick(color);
26
- });
27
- grid.appendChild(sw);
28
- }
29
- box.appendChild(grid);
30
-
31
- const custom = document.createElement('div');
32
- custom.className = 'gbd-color__custom';
33
- const wheel = document.createElement('input');
34
- wheel.type = 'color';
35
- wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
36
- const hex = document.createElement('input');
37
- hex.type = 'text';
38
- hex.className = 'gbd-color__hex';
39
- hex.value = value || '';
40
- hex.placeholder = '#rrggbb';
41
- wheel.addEventListener('input', () => { hex.value = wheel.value; });
42
- custom.append(wheel, hex);
43
- box.appendChild(custom);
44
-
45
- const actions = document.createElement('div');
46
- actions.className = 'gbd-color__actions';
47
- const apply = document.createElement('button');
48
- apply.type = 'button';
49
- apply.className = 'gbd-btn gbd-btn--primary';
50
- apply.textContent = '应用';
51
- const clear = document.createElement('button');
52
- clear.type = 'button';
53
- clear.className = 'gbd-btn';
54
- clear.textContent = '清除';
55
- apply.addEventListener('click', () => {
56
- const v = (hex.value || '').trim();
57
- handle.close();
58
- onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
59
- });
60
- clear.addEventListener('click', () => {
61
- handle.close();
62
- onPick('');
63
- });
64
- actions.append(apply, clear);
65
- box.appendChild(actions);
66
-
67
- const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gbd-popup--color' });
68
- return handle;
69
- }
1
+ // [文件] gbdocx·ColorPanel —— 文字颜色/底色色板(预设格里 + 系统色轮 + Hex + 清除)
2
+ import { openPopup } from './popup.js';
3
+
4
+ /** 打开色板;onPick(color) 回调(清除传空串) */
5
+ export function openColorPanel({ anchor, colors, value, title, columns = 10, onPick }) {
6
+ const box = document.createElement('div');
7
+ box.className = 'gbd-color';
8
+ const head = document.createElement('div');
9
+ head.className = 'gbd-color__title';
10
+ head.textContent = title || '颜色';
11
+ box.appendChild(head);
12
+
13
+ const grid = document.createElement('div');
14
+ grid.className = 'gbd-color__grid';
15
+ grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
16
+ for (const color of colors) {
17
+ const sw = document.createElement('button');
18
+ sw.type = 'button';
19
+ sw.className = 'gbd-color__swatch';
20
+ sw.style.background = color;
21
+ if (value && value.toLowerCase() === color.toLowerCase()) sw.classList.add('gbd-is-active');
22
+ sw.title = color;
23
+ sw.addEventListener('click', () => {
24
+ handle.close();
25
+ onPick(color);
26
+ });
27
+ grid.appendChild(sw);
28
+ }
29
+ box.appendChild(grid);
30
+
31
+ const custom = document.createElement('div');
32
+ custom.className = 'gbd-color__custom';
33
+ const wheel = document.createElement('input');
34
+ wheel.type = 'color';
35
+ wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
36
+ const hex = document.createElement('input');
37
+ hex.type = 'text';
38
+ hex.className = 'gbd-color__hex';
39
+ hex.value = value || '';
40
+ hex.placeholder = '#rrggbb';
41
+ wheel.addEventListener('input', () => { hex.value = wheel.value; });
42
+ custom.append(wheel, hex);
43
+ box.appendChild(custom);
44
+
45
+ const actions = document.createElement('div');
46
+ actions.className = 'gbd-color__actions';
47
+ const apply = document.createElement('button');
48
+ apply.type = 'button';
49
+ apply.className = 'gbd-btn gbd-btn--primary';
50
+ apply.textContent = '应用';
51
+ const clear = document.createElement('button');
52
+ clear.type = 'button';
53
+ clear.className = 'gbd-btn';
54
+ clear.textContent = '清除';
55
+ apply.addEventListener('click', () => {
56
+ const v = (hex.value || '').trim();
57
+ handle.close();
58
+ onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
59
+ });
60
+ clear.addEventListener('click', () => {
61
+ handle.close();
62
+ onPick('');
63
+ });
64
+ actions.append(apply, clear);
65
+ box.appendChild(actions);
66
+
67
+ const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gbd-popup--color' });
68
+ return handle;
69
+ }
@@ -1,133 +1,135 @@
1
- // [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/icon/disabled/checked/colorDot/shortcut/divided/children/input/onClick)
2
- import { openPopup } from './popup.js';
3
- import { icon } from './icons.js';
4
-
5
- const CHECK = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12l5 5L20 7"/></svg>';
6
- const SUB = '<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"/></svg>';
7
-
8
- /**
9
- * 打开菜单
10
- * @param {object} opts
11
- * @param {HTMLElement|DOMRect} opts.anchor
12
- * @param {Array<object>} opts.items 条目表
13
- * @param {string} [opts.placement]
14
- * @param {() => void} [opts.onClose] 关闭回调(父菜单据此同步按钮态)
15
- */
16
- export function openMenu({ anchor, items, placement = 'bottom-start', onClose }) {
17
- const body = buildList(items);
18
- return openPopup({
19
- anchor,
20
- content: body,
21
- placement,
22
- className: 'gbd-menu',
23
- // 子菜单是独立浮层:既不能算作「点在外面」把父菜单关掉,父菜单关闭时也要把它一起收
24
- isInside: (target) => Boolean(target?.closest?.('.gbd-menu--sub')),
25
- onClose: () => {
26
- body.__closeSub?.();
27
- onClose?.();
28
- },
29
- });
30
- }
31
-
32
- /** 构建条目列表 DOM(子菜单在 hover 时另开浮层) */
33
- function buildList(items) {
34
- const ul = document.createElement('div');
35
- ul.className = 'gbd-menu__list';
36
- let subHandle = null;
37
- const closeSub = () => {
38
- subHandle?.close();
39
- subHandle = null;
40
- };
41
- // 父级浮层关闭时由 openMenu 回调这里,把子菜单一起收走
42
- ul.__closeSub = closeSub;
43
- for (const item of items || []) {
44
- // divided 有两种用法:裸分隔标记(只有 divided)与「本项之前画分隔线」(真实条目带 label)。
45
- // 后者不能 continue,否则每个分组的首项(如表格菜单的「全选 / 删除表格」)都会被吞成一条分隔线。
46
- if (item.divided) {
47
- const sep = document.createElement('div');
48
- sep.className = 'gbd-menu__sep';
49
- ul.appendChild(sep);
50
- if (!item.label) continue;
51
- }
52
- const row = document.createElement('div');
53
- row.className = 'gbd-menu__item';
54
- if (item.disabled) row.classList.add('gbd-is-disabled');
55
- if (item.danger) row.classList.add('gbd-is-danger');
56
-
57
- const lead = document.createElement('span');
58
- lead.className = 'gbd-menu__lead';
59
- if (item.checked) lead.innerHTML = CHECK;
60
- else if (item.colorDot) {
61
- lead.innerHTML = `<i class="gbd-menu__dot" style="background:${item.colorDot}"></i>`;
62
- } else if (item.icon) {
63
- lead.innerHTML = icon(item.icon);
64
- }
65
- row.appendChild(lead);
66
-
67
- const label = document.createElement('span');
68
- label.className = 'gbd-menu__label';
69
- label.textContent = item.label;
70
- row.appendChild(label);
71
-
72
- let inputEl = null;
73
- if (item.input && !item.disabled) {
74
- const box = document.createElement('span');
75
- box.className = 'gbd-menu__input';
76
- inputEl = document.createElement('input');
77
- inputEl.type = 'number';
78
- inputEl.min = item.input.min;
79
- inputEl.max = item.input.max;
80
- inputEl.value = item.input.defaultValue;
81
- inputEl.addEventListener('mousedown', (e) => e.stopPropagation());
82
- box.appendChild(inputEl);
83
- if (item.input.unit) {
84
- const unit = document.createElement('span');
85
- unit.className = 'gbd-menu__unit';
86
- unit.textContent = item.input.unit;
87
- box.appendChild(unit);
88
- }
89
- row.appendChild(box);
90
- } else if (item.shortcut) {
91
- const sc = document.createElement('span');
92
- sc.className = 'gbd-menu__shortcut';
93
- sc.textContent = item.shortcut;
94
- row.appendChild(sc);
95
- }
96
-
97
- if (item.children) {
98
- const arrow = document.createElement('span');
99
- arrow.className = 'gbd-menu__arrow';
100
- arrow.innerHTML = SUB;
101
- row.appendChild(arrow);
102
- let openTimer = 0;
103
- row.addEventListener('mouseenter', () => {
104
- clearTimeout(openTimer);
105
- openTimer = setTimeout(() => {
106
- closeSub();
107
- if (item.disabled) return;
108
- const subBody = buildList(item.children);
109
- subHandle = openPopup({
110
- anchor: row.getBoundingClientRect(),
111
- content: subBody,
112
- placement: 'right-start',
113
- className: 'gbd-menu gbd-menu--sub',
114
- // 子级浮层:不能走 closeAll 把父菜单一起关掉
115
- nested: true,
116
- onClose: () => subBody.__closeSub?.(),
117
- });
118
- }, 60);
119
- });
120
- row.addEventListener('mouseleave', () => clearTimeout(openTimer));
121
- } else {
122
- row.addEventListener('click', (e) => {
123
- if (item.disabled) return;
124
- const value = inputEl ? Number(inputEl.value) : undefined;
125
- item.onClick?.(e, value);
126
- // 关闭整串菜单(含父级)
127
- document.dispatchEvent(new CustomEvent('gbdocx-menu-close'));
128
- });
129
- }
130
- ul.appendChild(row);
131
- }
132
- return ul;
133
- }
1
+ // [文件] gbdocx·ContextMenu —— 右键/下拉菜单渲染(条目口径:label/icon/disabled/checked/colorDot/shortcut/divided/children/input/onClick)
2
+ import { Check, ChevronRight } from 'gbicons/nodes';
3
+ import { iconNodeSvg } from 'gbicons/nodes';
4
+ import { openPopup } from './popup.js';
5
+ import { icon } from './icons.js';
6
+
7
+ const CHECK = iconNodeSvg(Check, { size: 14, sw: 2.4 });
8
+ const SUB = iconNodeSvg(ChevronRight, { size: 12, sw: 2.2 });
9
+
10
+ /**
11
+ * 打开菜单
12
+ * @param {object} opts
13
+ * @param {HTMLElement|DOMRect} opts.anchor
14
+ * @param {Array<object>} opts.items 条目表
15
+ * @param {string} [opts.placement]
16
+ * @param {() => void} [opts.onClose] 关闭回调(父菜单据此同步按钮态)
17
+ */
18
+ export function openMenu({ anchor, items, placement = 'bottom-start', onClose }) {
19
+ const body = buildList(items);
20
+ return openPopup({
21
+ anchor,
22
+ content: body,
23
+ placement,
24
+ className: 'gbd-menu',
25
+ // 子菜单是独立浮层:既不能算作「点在外面」把父菜单关掉,父菜单关闭时也要把它一起收
26
+ isInside: (target) => Boolean(target?.closest?.('.gbd-menu--sub')),
27
+ onClose: () => {
28
+ body.__closeSub?.();
29
+ onClose?.();
30
+ },
31
+ });
32
+ }
33
+
34
+ /** 构建条目列表 DOM(子菜单在 hover 时另开浮层) */
35
+ function buildList(items) {
36
+ const ul = document.createElement('div');
37
+ ul.className = 'gbd-menu__list';
38
+ let subHandle = null;
39
+ const closeSub = () => {
40
+ subHandle?.close();
41
+ subHandle = null;
42
+ };
43
+ // 父级浮层关闭时由 openMenu 回调这里,把子菜单一起收走
44
+ ul.__closeSub = closeSub;
45
+ for (const item of items || []) {
46
+ // divided 有两种用法:裸分隔标记(只有 divided)与「本项之前画分隔线」(真实条目带 label)。
47
+ // 后者不能 continue,否则每个分组的首项(如表格菜单的「全选 / 删除表格」)都会被吞成一条分隔线。
48
+ if (item.divided) {
49
+ const sep = document.createElement('div');
50
+ sep.className = 'gbd-menu__sep';
51
+ ul.appendChild(sep);
52
+ if (!item.label) continue;
53
+ }
54
+ const row = document.createElement('div');
55
+ row.className = 'gbd-menu__item';
56
+ if (item.disabled) row.classList.add('gbd-is-disabled');
57
+ if (item.danger) row.classList.add('gbd-is-danger');
58
+
59
+ const lead = document.createElement('span');
60
+ lead.className = 'gbd-menu__lead';
61
+ if (item.checked) lead.innerHTML = CHECK;
62
+ else if (item.colorDot) {
63
+ lead.innerHTML = `<i class="gbd-menu__dot" style="background:${item.colorDot}"></i>`;
64
+ } else if (item.icon) {
65
+ lead.innerHTML = icon(item.icon);
66
+ }
67
+ row.appendChild(lead);
68
+
69
+ const label = document.createElement('span');
70
+ label.className = 'gbd-menu__label';
71
+ label.textContent = item.label;
72
+ row.appendChild(label);
73
+
74
+ let inputEl = null;
75
+ if (item.input && !item.disabled) {
76
+ const box = document.createElement('span');
77
+ box.className = 'gbd-menu__input';
78
+ inputEl = document.createElement('input');
79
+ inputEl.type = 'number';
80
+ inputEl.min = item.input.min;
81
+ inputEl.max = item.input.max;
82
+ inputEl.value = item.input.defaultValue;
83
+ inputEl.addEventListener('mousedown', (e) => e.stopPropagation());
84
+ box.appendChild(inputEl);
85
+ if (item.input.unit) {
86
+ const unit = document.createElement('span');
87
+ unit.className = 'gbd-menu__unit';
88
+ unit.textContent = item.input.unit;
89
+ box.appendChild(unit);
90
+ }
91
+ row.appendChild(box);
92
+ } else if (item.shortcut) {
93
+ const sc = document.createElement('span');
94
+ sc.className = 'gbd-menu__shortcut';
95
+ sc.textContent = item.shortcut;
96
+ row.appendChild(sc);
97
+ }
98
+
99
+ if (item.children) {
100
+ const arrow = document.createElement('span');
101
+ arrow.className = 'gbd-menu__arrow';
102
+ arrow.innerHTML = SUB;
103
+ row.appendChild(arrow);
104
+ let openTimer = 0;
105
+ row.addEventListener('mouseenter', () => {
106
+ clearTimeout(openTimer);
107
+ openTimer = setTimeout(() => {
108
+ closeSub();
109
+ if (item.disabled) return;
110
+ const subBody = buildList(item.children);
111
+ subHandle = openPopup({
112
+ anchor: row.getBoundingClientRect(),
113
+ content: subBody,
114
+ placement: 'right-start',
115
+ className: 'gbd-menu gbd-menu--sub',
116
+ // 子级浮层:不能走 closeAll 把父菜单一起关掉
117
+ nested: true,
118
+ onClose: () => subBody.__closeSub?.(),
119
+ });
120
+ }, 60);
121
+ });
122
+ row.addEventListener('mouseleave', () => clearTimeout(openTimer));
123
+ } else {
124
+ row.addEventListener('click', (e) => {
125
+ if (item.disabled) return;
126
+ const value = inputEl ? Number(inputEl.value) : undefined;
127
+ item.onClick?.(e, value);
128
+ // 关闭整串菜单(含父级)
129
+ document.dispatchEvent(new CustomEvent('gbdocx-menu-close'));
130
+ });
131
+ }
132
+ ul.appendChild(row);
133
+ }
134
+ return ul;
135
+ }