@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,45 +1,45 @@
1
- // [文件] web·office·docx·水印 —— 页面水印的屏幕预览(canvas 画一张倾斜文字贴图,铺成纸张背景)
2
- // [设计] 水印在 Word 里是页眉中「一页一个」的旋转文字图,所以预览也只做居中单图——
3
- // canvas-editor 那种平铺是它自绘画布的产物,OOXML 侧没有对应表达,抄过来就是存盘即丢的假开关。
4
-
5
- import { PX_PER_MM } from 'gbooxml';
6
-
7
- /** 旋转角:-45°(Word 的水印 VML 写 rotation:315,同一个角) */
8
- const TILT = -Math.PI / 4;
9
-
10
- const cache = new Map();
11
-
12
- /** 贴图的缓存键(数据一变才重画,否则复用上次的 dataURL) */
13
- const keyOf = (wm) => `${wm.data}|${wm.color}|${wm.size}|${wm.opacity}`;
14
-
15
- /**
16
- * 纸张的水印背景样式
17
- * @param {{data:string,color:string,size:number,opacity:number}} wm
18
- * @param {{w:number,h:number}} geo 纸张几何(mm)
19
- * @returns {?Object} 供 :style 绑定的 CSS(无水印时返回 null)
20
- */
21
- export const watermarkStyle = (wm, geo) => {
22
- if (!wm?.data?.trim()) return null;
23
- const key = keyOf(wm);
24
- let url = cache.get(key);
25
- if (!url) {
26
- // [坑] 贴图按未缩放的纸张尺寸画:纸张层挂着 transform: scale(zoom),背景图跟着一起缩放,
27
- // 把 zoom 算进去会让水印在缩放时二次变形。
28
- const canvas = document.createElement('canvas');
29
- canvas.width = Math.max(1, Math.round(geo.w * PX_PER_MM));
30
- canvas.height = Math.max(1, Math.round(geo.h * PX_PER_MM));
31
- const ctx = canvas.getContext('2d');
32
- const size = wm.size > 0 ? wm.size : 120;
33
- ctx.globalAlpha = wm.opacity > 0 && wm.opacity <= 1 ? wm.opacity : 0.3;
34
- ctx.fillStyle = wm.color || '#AEB5C0';
35
- ctx.font = `${size}px "Microsoft YaHei", Arial, sans-serif`;
36
- ctx.textAlign = 'center';
37
- ctx.textBaseline = 'middle';
38
- ctx.translate(canvas.width / 2, canvas.height / 2);
39
- ctx.rotate(TILT);
40
- ctx.fillText(wm.data, 0, 0);
41
- url = canvas.toDataURL();
42
- cache.set(key, url);
43
- }
44
- return { backgroundImage: `url(${url})`, backgroundRepeat: 'no-repeat', backgroundPosition: 'center', backgroundSize: '100% 100%' };
45
- };
1
+ // [文件] web·office·docx·水印 —— 页面水印的屏幕预览(canvas 画一张倾斜文字贴图,铺成纸张背景)
2
+ // [设计] 水印在 Word 里是页眉中「一页一个」的旋转文字图,所以预览也只做居中单图——
3
+ // canvas-editor 那种平铺是它自绘画布的产物,OOXML 侧没有对应表达,抄过来就是存盘即丢的假开关。
4
+
5
+ import { PX_PER_MM } from 'gbooxml';
6
+
7
+ /** 旋转角:-45°(Word 的水印 VML 写 rotation:315,同一个角) */
8
+ const TILT = -Math.PI / 4;
9
+
10
+ const cache = new Map();
11
+
12
+ /** 贴图的缓存键(数据一变才重画,否则复用上次的 dataURL) */
13
+ const keyOf = (wm) => `${wm.data}|${wm.color}|${wm.size}|${wm.opacity}`;
14
+
15
+ /**
16
+ * 纸张的水印背景样式
17
+ * @param {{data:string,color:string,size:number,opacity:number}} wm
18
+ * @param {{w:number,h:number}} geo 纸张几何(mm)
19
+ * @returns {?Object} 供 :style 绑定的 CSS(无水印时返回 null)
20
+ */
21
+ export const watermarkStyle = (wm, geo) => {
22
+ if (!wm?.data?.trim()) return null;
23
+ const key = keyOf(wm);
24
+ let url = cache.get(key);
25
+ if (!url) {
26
+ // [坑] 贴图按未缩放的纸张尺寸画:纸张层挂着 transform: scale(zoom),背景图跟着一起缩放,
27
+ // 把 zoom 算进去会让水印在缩放时二次变形。
28
+ const canvas = document.createElement('canvas');
29
+ canvas.width = Math.max(1, Math.round(geo.w * PX_PER_MM));
30
+ canvas.height = Math.max(1, Math.round(geo.h * PX_PER_MM));
31
+ const ctx = canvas.getContext('2d');
32
+ const size = wm.size > 0 ? wm.size : 120;
33
+ ctx.globalAlpha = wm.opacity > 0 && wm.opacity <= 1 ? wm.opacity : 0.3;
34
+ ctx.fillStyle = wm.color || '#AEB5C0';
35
+ ctx.font = `${size}px "Microsoft YaHei", Arial, sans-serif`;
36
+ ctx.textAlign = 'center';
37
+ ctx.textBaseline = 'middle';
38
+ ctx.translate(canvas.width / 2, canvas.height / 2);
39
+ ctx.rotate(TILT);
40
+ ctx.fillText(wm.data, 0, 0);
41
+ url = canvas.toDataURL();
42
+ cache.set(key, url);
43
+ }
44
+ return { backgroundImage: `url(${url})`, backgroundRepeat: 'no-repeat', backgroundPosition: 'center', backgroundSize: '100% 100%' };
45
+ };
@@ -1,37 +1,37 @@
1
- // [文件] web·office·docx·快捷键 —— Ctrl/⌘ 组合键的动作表(纯数据 + 一处分发;页面只负责注册监听与传 ctx)
2
- // [设计] 键位判断用 e.key(Ctrl 组合下不受 Shift 影响),列表项用 e.code(Shift+8/7 的大小写符号键
3
- // 在 e.key 上是 '*' 与 '&',按字符判断会随键盘布局漂移)。
4
- // [坑] 命中即 preventDefault + stopPropagation:不拦的话浏览器与外层全局快捷键总线会先执行
5
- // (Ctrl+S 弹打印、Ctrl+O 打开新窗),表现为"按了没反应"或"两个动作都触发"。
6
-
7
- /**
8
- * @param {KeyboardEvent} e
9
- * @param {Object} ctx
10
- * @param {{save:Function, saveAs:Function, open:Function, newDoc:Function, print:Function}} ctx.file
11
- * @param {{pageBreak:Function, link:Function, comment:Function, list:Function}} ctx.insert
12
- * @param {{find:Function, findReplace:Function}} ctx.edit
13
- * @param {{zoomIn:Function, zoomOut:Function, zoomReset:Function}} ctx.view
14
- * @returns {boolean} 是否命中并已消费
15
- */
16
- export const runShortcut = (e, ctx) => {
17
- const k = e.key.toLowerCase();
18
- const stop = () => {
19
- e.preventDefault();
20
- e.stopPropagation();
21
- };
22
- if (k === 's') return stop(), (e.shiftKey ? ctx.file.saveAs() : ctx.file.save());
23
- if (k === 'o') return stop(), ctx.file.open();
24
- if (k === 'p') return stop(), ctx.file.print();
25
- if (k === 'f') return stop(), ctx.edit.find();
26
- if (k === 'h') return stop(), ctx.edit.findReplace();
27
- if (k === 'k') return stop(), ctx.insert.link();
28
- if (k === '=' || k === '+') return stop(), ctx.view.zoomIn();
29
- if (k === '-') return stop(), ctx.view.zoomOut();
30
- if (k === '0') return stop(), ctx.view.zoomReset();
31
- if (k === 'enter') return stop(), ctx.insert.pageBreak();
32
- if (e.altKey && k === 'n') return stop(), ctx.file.newDoc();
33
- if (e.altKey && k === 'm') return stop(), ctx.insert.comment();
34
- if (e.shiftKey && e.code === 'Digit8') return stop(), ctx.insert.list(false);
35
- if (e.shiftKey && e.code === 'Digit7') return stop(), ctx.insert.list(true);
36
- return false;
37
- };
1
+ // [文件] web·office·docx·快捷键 —— Ctrl/⌘ 组合键的动作表(纯数据 + 一处分发;页面只负责注册监听与传 ctx)
2
+ // [设计] 键位判断用 e.key(Ctrl 组合下不受 Shift 影响),列表项用 e.code(Shift+8/7 的大小写符号键
3
+ // 在 e.key 上是 '*' 与 '&',按字符判断会随键盘布局漂移)。
4
+ // [坑] 命中即 preventDefault + stopPropagation:不拦的话浏览器与外层全局快捷键总线会先执行
5
+ // (Ctrl+S 弹打印、Ctrl+O 打开新窗),表现为"按了没反应"或"两个动作都触发"。
6
+
7
+ /**
8
+ * @param {KeyboardEvent} e
9
+ * @param {Object} ctx
10
+ * @param {{save:Function, saveAs:Function, open:Function, newDoc:Function, print:Function}} ctx.file
11
+ * @param {{pageBreak:Function, link:Function, comment:Function, list:Function}} ctx.insert
12
+ * @param {{find:Function, findReplace:Function}} ctx.edit
13
+ * @param {{zoomIn:Function, zoomOut:Function, zoomReset:Function}} ctx.view
14
+ * @returns {boolean} 是否命中并已消费
15
+ */
16
+ export const runShortcut = (e, ctx) => {
17
+ const k = e.key.toLowerCase();
18
+ const stop = () => {
19
+ e.preventDefault();
20
+ e.stopPropagation();
21
+ };
22
+ if (k === 's') return stop(), (e.shiftKey ? ctx.file.saveAs() : ctx.file.save());
23
+ if (k === 'o') return stop(), ctx.file.open();
24
+ if (k === 'p') return stop(), ctx.file.print();
25
+ if (k === 'f') return stop(), ctx.edit.find();
26
+ if (k === 'h') return stop(), ctx.edit.findReplace();
27
+ if (k === 'k') return stop(), ctx.insert.link();
28
+ if (k === '=' || k === '+') return stop(), ctx.view.zoomIn();
29
+ if (k === '-') return stop(), ctx.view.zoomOut();
30
+ if (k === '0') return stop(), ctx.view.zoomReset();
31
+ if (k === 'enter') return stop(), ctx.insert.pageBreak();
32
+ if (e.altKey && k === 'n') return stop(), ctx.file.newDoc();
33
+ if (e.altKey && k === 'm') return stop(), ctx.insert.comment();
34
+ if (e.shiftKey && e.code === 'Digit8') return stop(), ctx.insert.list(false);
35
+ if (e.shiftKey && e.code === 'Digit7') return stop(), ctx.insert.list(true);
36
+ return false;
37
+ };
@@ -1,8 +1,8 @@
1
- // [文件] web·editor-kernel·constants —— 内核配置单一来源(行高档位/缩进档位;正文字号/字体/行高/等宽字体默认值在 content.scss 的 --richtext-* 兜底里,禁在此写第二份)
2
-
3
- /** 行高档位 */
4
- export const LINE_HEIGHTS = ['0.25', '0.5', '0.75', '1', '1.15', '1.25', '1.5', '2', '2.5', '3'];
5
-
6
- /** 缩进最大级数 / 每级宽度(em) */
7
- export const INDENT_MAX_LEVEL = 8;
8
- export const INDENT_STEP_EM = 2;
1
+ // [文件] web·editor-kernel·constants —— 内核配置单一来源(行高档位/缩进档位;正文字号/字体/行高/等宽字体默认值在 content.scss 的 --richtext-* 兜底里,禁在此写第二份)
2
+
3
+ /** 行高档位 */
4
+ export const LINE_HEIGHTS = ['0.25', '0.5', '0.75', '1', '1.15', '1.25', '1.5', '2', '2.5', '3'];
5
+
6
+ /** 缩进最大级数 / 每级宽度(em) */
7
+ export const INDENT_MAX_LEVEL = 8;
8
+ export const INDENT_STEP_EM = 2;