@a200888213/gbdocx 0.0.0-stage → 0.4.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.
- package/LICENSE +21 -0
- package/README.md +206 -2
- package/index.html +25 -0
- package/package.json +48 -6
- package/serve.mjs +22 -0
- package/src/app/file-io.js +122 -0
- package/src/app/main.js +9 -0
- package/src/app/word/catalog.js +52 -0
- package/src/app/word/comments.js +112 -0
- package/src/app/word/doc.js +113 -0
- package/src/app/word/edit.js +72 -0
- package/src/app/word/file.js +162 -0
- package/src/app/word/hf.js +76 -0
- package/src/app/word/layout.js +155 -0
- package/src/app/word/menus.js +175 -0
- package/src/app/word/notes.js +110 -0
- package/src/app/word/shared.js +22 -0
- package/src/app/word/view.js +117 -0
- package/src/app/word-app.js +459 -0
- package/src/app/word-sheets.js +101 -0
- package/src/kernel/docx/catalog.js +41 -0
- package/src/kernel/docx/codec/blocks.js +123 -0
- package/src/kernel/docx/codec/carry.js +129 -0
- package/src/kernel/docx/codec/comments.js +25 -0
- package/src/kernel/docx/codec/docx.js +198 -0
- package/src/kernel/docx/codec/docxStyles.js +177 -0
- package/src/kernel/docx/codec/fonts.js +195 -0
- package/src/kernel/docx/codec/helpers.js +161 -0
- package/src/kernel/docx/codec/hfHtml.js +152 -0
- package/src/kernel/docx/codec/html.js +739 -0
- package/src/kernel/docx/codec/losses.js +420 -0
- package/src/kernel/docx/codec/markdown.js +170 -0
- package/src/kernel/docx/codec/parts.js +249 -0
- package/src/kernel/docx/codec/read.js +603 -0
- package/src/kernel/docx/codec/render.js +1156 -0
- package/src/kernel/docx/codec/roundtrip.js +236 -0
- package/src/kernel/docx/codec/write.js +833 -0
- package/src/kernel/docx/comments.js +14 -0
- package/src/kernel/docx/constants.js +63 -0
- package/src/kernel/docx/menus.js +211 -0
- package/src/kernel/docx/pageGeometry.js +123 -0
- package/src/kernel/docx/pagination.js +481 -0
- package/src/kernel/docx/watermark.js +45 -0
- package/src/kernel/docx/wordShortcuts.js +37 -0
- package/src/kernel/editor/constants.js +8 -0
- package/src/kernel/editor/engine/blocks.js +594 -0
- package/src/kernel/editor/engine/blocksEnter.js +109 -0
- package/src/kernel/editor/engine/blocksInsert.js +254 -0
- package/src/kernel/editor/engine/blocksStructure.js +226 -0
- package/src/kernel/editor/engine/commands.js +181 -0
- package/src/kernel/editor/engine/dom.js +646 -0
- package/src/kernel/editor/engine/editor.js +213 -0
- package/src/kernel/editor/engine/history.js +149 -0
- package/src/kernel/editor/engine/inline.js +656 -0
- package/src/kernel/editor/engine/input.js +554 -0
- package/src/kernel/editor/engine/interaction.js +137 -0
- package/src/kernel/editor/engine/pointer.js +39 -0
- package/src/kernel/editor/engine/revision.js +138 -0
- package/src/kernel/editor/engine/schema.js +417 -0
- package/src/kernel/editor/engine/search.js +113 -0
- package/src/kernel/editor/engine/selection.js +119 -0
- package/src/kernel/editor/engine/state.js +118 -0
- package/src/kernel/editor/engine/tableClip.js +154 -0
- package/src/kernel/editor/engine/tableGrid.js +55 -0
- package/src/kernel/editor/engine/tableInteraction.js +388 -0
- package/src/kernel/editor/engine/tableMenu.js +250 -0
- package/src/kernel/editor/engine/tableOps.js +174 -0
- package/src/kernel/editor/engine/tables.js +732 -0
- package/src/kernel/editor/overlayGeometry.js +20 -0
- package/src/kernel/editor/pasteClean.js +293 -0
- package/src/kernel/editor/utils.js +49 -0
- package/src/kernel/keyboard.js +114 -0
- package/src/kernel/notify.js +54 -0
- package/src/kernel/textStyles.js +84 -0
- package/src/kernel/util/clipboard.js +89 -0
- package/src/kernel/util/imageFile.js +91 -0
- package/src/kernel/util/safeValue.js +25 -0
- package/src/kernel/util/shortcutKey.js +33 -0
- package/src/surface/editor-surface.js +600 -0
- package/src/ui/color-panel.js +69 -0
- package/src/ui/context-menu.js +130 -0
- package/src/ui/dialogs.js +249 -0
- package/src/ui/find-bar.js +151 -0
- package/src/ui/icons.js +134 -0
- package/src/ui/menubar.js +28 -0
- package/src/ui/panels.js +115 -0
- package/src/ui/popup.js +79 -0
- package/src/ui/prompt.js +89 -0
- package/src/ui/ribbon.js +485 -0
- package/src/ui/special-chars.js +39 -0
- package/src/ui/statusbar.js +81 -0
- package/src/ui/toolbar.js +32 -0
- package/styles/app.css +944 -0
- package/styles/editor-content.css +440 -0
- package/styles/tokens.css +154 -0
- package/styles/word-panel.css +410 -0
package/src/ui/icons.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// [文件] gbdocx·UI 图标集 —— 工具栏/菜单用的内联 SVG(stroke 风格,currentColor 上色)
|
|
2
|
+
const S = (body, size = 16) =>
|
|
3
|
+
`<svg viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">${body}</svg>`;
|
|
4
|
+
|
|
5
|
+
export const ICONS = {
|
|
6
|
+
bold: S('<path d="M7 5h6a3.5 3.5 0 0 1 0 7H7zM7 12h7a3.5 3.5 0 0 1 0 7H7z"/>'),
|
|
7
|
+
italic: S('<path d="M15 5h-5M14 19H9M14 5l-4 14"/>'),
|
|
8
|
+
underline: S('<path d="M7 5v7a5 5 0 0 0 10 0V5M5 20h14"/>'),
|
|
9
|
+
strike: S('<path d="M5 12h14M8 8a3 3 0 0 1 3-3h3a3 3 0 0 1 0 6M16 16a3 3 0 0 1-3 3h-3a3 3 0 0 1-2-1"/>'),
|
|
10
|
+
superscript: S('<path d="M4 19l4.5-11L13 19M5.5 15h5.5"/><path d="M16 8h3l-3 4h3"/>'),
|
|
11
|
+
subscript: S('<path d="M4 15l4.5-11L13 15M5.5 11h5.5"/><path d="M16 15h3l-3 4h3"/>'),
|
|
12
|
+
colorIcon: S('<path d="M6 18h12M8 14l4-9 4 9M7 14h10"/><path d="M4 21h16"/>'),
|
|
13
|
+
bgIcon: S('<path d="M4 20h16M6 14l4-9 4 9M7 14h10"/>'),
|
|
14
|
+
alignLeft: S('<path d="M4 6h16M4 12h10M4 18h14"/>'),
|
|
15
|
+
alignCenter: S('<path d="M4 6h16M7 12h10M5 18h14"/>'),
|
|
16
|
+
alignRight: S('<path d="M4 6h16M10 12h10M6 18h14"/>'),
|
|
17
|
+
alignJustify: S('<path d="M4 6h16M4 12h16M4 18h16"/>'),
|
|
18
|
+
bullet: S('<path d="M9 6h11M9 12h11M9 18h11M5 6h.01M5 12h.01M5 18h.01"/>'),
|
|
19
|
+
ordered: S('<path d="M10 6h10M10 12h10M10 18h10M4 5h1v3M4 11h2l-2 3h2M4 17h1.5a1 1 0 0 1 0 2H4h1.5a1 1 0 0 1 0 2H4"/>'),
|
|
20
|
+
indentAdd: S('<path d="M4 6h16M10 12h10M4 18h16M6 9l3 3-3 3"/>'),
|
|
21
|
+
indentReduce: S('<path d="M4 6h16M10 12h10M4 18h16M9 9l-3 3 3 3"/>'),
|
|
22
|
+
quote: S('<path d="M7 7H4v6h5V8M17 7h-3v6h5V8"/>'),
|
|
23
|
+
code: S('<path d="M9 8l-4 4 4 4M15 8l4 4-4 4"/>'),
|
|
24
|
+
table: S('<rect x="3" y="4" width="18" height="16" rx="1.5"/><path d="M3 10h18M3 15h18M9 4v16M15 4v16"/>'),
|
|
25
|
+
image: S('<rect x="3" y="4" width="18" height="16" rx="1.5"/><path d="M4 16l4-4 4 4 3-3 5 5"/><circle cx="9" cy="9" r="1.4"/>'),
|
|
26
|
+
linkIcon: S('<path d="M10 13a4 4 0 0 0 5.7 0l2.3-2.3a4 4 0 0 0-5.7-5.7L11 6"/><path d="M14 11a4 4 0 0 0-5.7 0L6 13.3a4 4 0 0 0 5.7 5.7L13 18"/>'),
|
|
27
|
+
divider: S('<path d="M3 12h18"/>'),
|
|
28
|
+
pageBreak: S('<path d="M4 4h16v6H4zM4 14h6v6H4zM14 14h6v6h-6z"/>'),
|
|
29
|
+
undo: S('<path d="M9 7L4 12l5 5M4 12h11a5 5 0 0 1 0 10"/>'),
|
|
30
|
+
redo: S('<path d="M15 7l5 5-5 5M20 12H9a5 5 0 0 0 0 10"/>'),
|
|
31
|
+
clear: S('<path d="M6 6l12 12M18 6L6 18"/>'),
|
|
32
|
+
chevronDown: S('<path d="M6 9l6 6 6-6"/>'),
|
|
33
|
+
// 选项卡面板专用(紧凑图标按钮,与上面同款 stroke 风格)
|
|
34
|
+
find: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21"/>'),
|
|
35
|
+
pageSetup: S('<path d="M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2M4 7h16v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1z"/><path d="M8 12h8M8 16h5"/>'),
|
|
36
|
+
columns: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M12 4v16"/>'),
|
|
37
|
+
headerFooter: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M3 9h18M3 15h18"/>'),
|
|
38
|
+
footnote: S('<path d="M5 5h14M5 12h9M5 19h6M17 11v8M15 19h4"/>'),
|
|
39
|
+
comment: S('<path d="M20 15a3 3 0 0 1-3 3H8l-4 3V6a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3z"/>'),
|
|
40
|
+
toc: S('<path d="M4 6h3M4 12h3M4 18h3M11 6h9M11 12h9M11 18h9"/>'),
|
|
41
|
+
watermark: S('<path d="M4 5h16v14H4z"/><path d="M9 15l2.5-6 2.5 6M9.8 13h3.4"/>'),
|
|
42
|
+
pageNumber: S('<rect x="6" y="3" width="12" height="18" rx="1.5"/><path d="M9 18h6"/>'),
|
|
43
|
+
suggest: S('<path d="M4 20h4L19 9a2 2 0 0 0-3-3L5 17z"/><path d="M14 7l3 3"/>'),
|
|
44
|
+
accept: S('<path d="M5 13l4 4L19 7"/>'),
|
|
45
|
+
reject: S('<path d="M6 6l12 12M18 6L6 18"/>'),
|
|
46
|
+
print: S('<path d="M6 9V4h12v5M6 18H4a1 1 0 0 1-1-1v-5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5a1 1 0 0 1-1 1h-2"/><path d="M6 15h12v5H6z"/>'),
|
|
47
|
+
export: S('<path d="M12 3v12M8 11l4 4 4-4M4 17v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/>'),
|
|
48
|
+
zoomIn: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M10.5 7v7M7 10.5h7"/>'),
|
|
49
|
+
zoomOut: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M7 10.5h7"/>'),
|
|
50
|
+
specialChars: S('<path d="M12 4v16M5 8h14M5 8c0 6 14 6 14 0"/>'),
|
|
51
|
+
bookmark: S('<path d="M6 4h12v17l-6-4-6 4z"/>'),
|
|
52
|
+
panel: S('<rect x="3" y="4" width="18" height="16" rx="1"/><path d="M15 4v16"/>'),
|
|
53
|
+
eye: S('<path d="M2.5 12S6 5.5 12 5.5 21.5 12 21.5 12 18 18.5 12 18.5 2.5 12 2.5 12z"/><circle cx="12" cy="12" r="2.8"/>'),
|
|
54
|
+
margin: S('<rect x="3" y="3" width="18" height="18" rx="1"/><rect x="8" y="8" width="8" height="8" rx="0.5"/>'),
|
|
55
|
+
zoomReset: S('<circle cx="10.5" cy="10.5" r="6.5"/><path d="M15.5 15.5L21 21M7.5 10.5h6"/>'),
|
|
56
|
+
selectAll: S('<rect x="3" y="3" width="12" height="12" rx="1"/><path d="M9 21h10a2 2 0 0 0 2-2V9"/>'),
|
|
57
|
+
|
|
58
|
+
// ---- WPS 风格功能区专用图标 ----
|
|
59
|
+
// 剪贴板
|
|
60
|
+
paste: S('<rect x="5" y="4" width="14" height="17" rx="1.5"/><path d="M9 4V3h6v1M8 9h8M8 13h8M8 17h5"/>'),
|
|
61
|
+
cut: S('<circle cx="6" cy="17" r="2.5"/><circle cx="18" cy="17" r="2.5"/><path d="M8 15L19 4M16 4L5 15"/>'),
|
|
62
|
+
copy: S('<rect x="8" y="8" width="12" height="12" rx="1.5"/><path d="M16 8V5a1.5 1.5 0 0 0-1.5-1.5H5A1.5 1.5 0 0 0 3.5 5v9.5A1.5 1.5 0 0 0 5 16h3"/>'),
|
|
63
|
+
formatPainter: S('<path d="M14 4l6 6-8 8-6-6zM6 12l-2 6 6-2M9 9l6 6"/>'),
|
|
64
|
+
// 字体
|
|
65
|
+
growFont: S('<path d="M3 18l4.5-11L12 18M4.5 14h6M18 7v8M14 11h8"/>'),
|
|
66
|
+
shrinkFont: S('<path d="M3 18l4.5-11L12 18M4.5 14h6M14 11h8"/>'),
|
|
67
|
+
eraser: S('<path d="M4 15l8-8a2 2 0 0 1 3 0l4 4a2 2 0 0 1 0 3l-7 7H8zM12 19h9"/>'),
|
|
68
|
+
highlight: S('<path d="M4 20h16M14 4l6 6-8 8-6-6zM9 15l6 6"/>'),
|
|
69
|
+
pinyin: S('<path d="M4 6h16M12 6v13M7 12l3 3M17 12l-3 3M8 19h8"/>'),
|
|
70
|
+
circleChar: S('<circle cx="12" cy="12" r="9"/><path d="M9 15l3-7 3 7M10 13h4"/>'),
|
|
71
|
+
// 段落
|
|
72
|
+
multiLevel: S('<path d="M9 6h11M9 12h11M9 18h11M4 5h1v3M4 11h2l-2 3h2M4 17h2v3H4z"/>'),
|
|
73
|
+
outdent: S('<path d="M11 6h9M11 12h9M11 18h9M3 12h6M6 9l-3 3 3 3"/>'),
|
|
74
|
+
showMarks: S('<path d="M8 4v13a3 3 0 1 1-3-3M4 14h4M12 6h9M12 12h7M12 18h9"/>'),
|
|
75
|
+
distribute: S('<path d="M4 6h16M7 12h10M4 18h16M4 3v18M20 3v18"/>'),
|
|
76
|
+
lineSpacing: S('<path d="M4 7h10M4 12h10M4 17h10M18 5v14M15 8l3-3 3 3M15 16l3 3 3-3"/>'),
|
|
77
|
+
shading: S('<path d="M4 4h16v16H4zM4 9h16M4 14h16M9 4v16M15 4v16"/>'),
|
|
78
|
+
borders: S('<rect x="3" y="3" width="18" height="18" rx="1"/><path d="M3 12h18M12 3v18"/>'),
|
|
79
|
+
newStyle: S('<path d="M5 19h14M8 15l7-9 3 3-7 9H8zM13 8l3 3"/>'),
|
|
80
|
+
// 插入
|
|
81
|
+
coverPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M5 8h14M8 12h8M8 15h8"/>'),
|
|
82
|
+
blankPage: S('<rect x="5" y="3" width="14" height="18" rx="1"/><path d="M9 9h6v6H9z"/>'),
|
|
83
|
+
chart: S('<path d="M4 20h16M6 20V10M11 20V5M16 20v-7M21 20v-4"/>'),
|
|
84
|
+
screenshot: S('<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3M4 12h16"/>'),
|
|
85
|
+
shape: S('<circle cx="8" cy="8" r="4"/><rect x="12" y="12" width="8" height="8" rx="1"/>'),
|
|
86
|
+
iconGallery: S('<path d="M12 3l2.2 5.6L20 9l-5 4 1.5 6L12 16l-4.5 3L9 13 4 9l5.8-.4z"/>'),
|
|
87
|
+
mindMap: S('<rect x="2" y="9" width="6" height="5" rx="1"/><rect x="16" y="3" width="6" height="5" rx="1"/><rect x="16" y="15" width="6" height="5" rx="1"/><path d="M8 11h4V6h4M12 11v7h4"/>'),
|
|
88
|
+
flowChart: S('<rect x="2" y="4" width="7" height="5" rx="1"/><rect x="15" y="15" width="7" height="5" rx="1"/><path d="M9 6h4v12h2M5 9v6h10"/>'),
|
|
89
|
+
textBox: S('<rect x="3" y="5" width="18" height="14" rx="1"/><path d="M7 9h10M12 9v9M9 18h6"/>'),
|
|
90
|
+
wordArt: S('<path d="M4 18l4-11 4 11M5 14h6M14 18V7h6M14 12h5"/>'),
|
|
91
|
+
equation: S('<path d="M8 4c-2 0-3 1-3 3 0 3 6 4 6 8a3 3 0 0 1-6 0M6 11h8M17 7l4 8M21 7l-4 8"/>'),
|
|
92
|
+
insertText: S('<path d="M4 6h10M9 3v6M4 18h16M14 14h6M17 11v6"/>'),
|
|
93
|
+
object: S('<path d="M12 3l9 5v8l-9 5-9-5V8zM3 8l9 5 9-5M12 13v8"/>'),
|
|
94
|
+
date: S('<rect x="3" y="5" width="18" height="16" rx="2"/><path d="M3 10h18M8 3v4M16 3v4M8 14h3M8 17h6"/>'),
|
|
95
|
+
attachment: S('<path d="M20 11l-8 8a5 5 0 0 1-7-7l9-9a3.5 3.5 0 0 1 5 5l-9 9a2 2 0 0 1-3-3l8-8"/>'),
|
|
96
|
+
fileLink: S('<path d="M14 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M14 3l6 6h-6zM13 15a3 3 0 0 1 5-2M18 13a3 3 0 0 1 1 4l-2 2a3 3 0 0 1-4 0"/>'),
|
|
97
|
+
crossReference: S('<path d="M6 4h8l4 4v12H6zM14 4v4h4M9 13h6M9 17h4M4 8v12a2 2 0 0 0 2 2"/>'),
|
|
98
|
+
// 页面布局
|
|
99
|
+
theme: S('<circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 0 0 18M8 8h.01M12 6h.01M16 9h.01"/>'),
|
|
100
|
+
colors: S('<circle cx="7" cy="8" r="3"/><circle cx="16" cy="7" r="3"/><circle cx="11" cy="16" r="3"/><path d="M7 11v2a2 2 0 0 0 2 2M16 10v3a3 3 0 0 1-3 3"/>'),
|
|
101
|
+
effects: S('<path d="M5 3l1.5 4L10 9l-3.5 2L5 15l-1.5-4L0 9l3.5-2zM17 12l1 3 3 1-3 1-1 3-1-3-3-1 3-1z"/>'),
|
|
102
|
+
fontCollection: S('<path d="M3 18l4-10 4 10M4 14h6M14 18l3-8 3 8M15 15h4"/>'),
|
|
103
|
+
orientation: S('<rect x="6" y="3" width="12" height="18" rx="1"/><path d="M6 8h12M9 12h6M9 15h6"/>'),
|
|
104
|
+
paperSize: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 17h16M16 17V3"/>'),
|
|
105
|
+
textDirection: S('<path d="M12 3v18M9 6l3-3 3 3M9 18l3 3 3-3M6 9h4M6 12h3"/>'),
|
|
106
|
+
separator: S('<path d="M3 12h5M16 12h5M9 6v12M12 6v12M15 6v12"/>'),
|
|
107
|
+
lineNumbers: S('<path d="M8 4h13M8 10h13M8 16h13M3 4h.01M3 10h.01M3 16h.01"/>'),
|
|
108
|
+
background: S('<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M3 14l4-4 4 4 3-3 4 4 3-3"/>'),
|
|
109
|
+
pageBorder: S('<rect x="4" y="3" width="16" height="18" rx="1"/><rect x="7" y="6" width="10" height="12" rx="0.5"/>'),
|
|
110
|
+
paperSettings: S('<rect x="4" y="3" width="16" height="18" rx="1"/><path d="M4 9h16M4 15h16M10 3v18M15 3v18"/>'),
|
|
111
|
+
wrap: S('<path d="M4 6h16M4 18h16M8 10h8a3 3 0 0 1 0 6H9M8 13l-2 3 2 3"/>'),
|
|
112
|
+
alignObjects: S('<path d="M4 3v18M9 7h11M9 14h8M6 4h.01M6 20h.01"/>'),
|
|
113
|
+
groupObjects: S('<rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/><path d="M10 10l4 4M14 6h4v4M10 18H6v-4"/>'),
|
|
114
|
+
rotate: S('<path d="M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5"/>'),
|
|
115
|
+
bringForward: S('<rect x="8" y="8" width="12" height="12" rx="1"/><path d="M4 16V4h12M12 14h4M14 12v4"/>'),
|
|
116
|
+
sendBackward: S('<rect x="4" y="4" width="12" height="12" rx="1"/><path d="M20 8v12H8M10 10h4M12 8v4"/>'),
|
|
117
|
+
// 引用
|
|
118
|
+
updateToc: S('<path d="M4 6h10M4 12h7M4 18h10M18 8a4 4 0 1 1-1 5M17 5v3h3"/>'),
|
|
119
|
+
tocLevel: S('<path d="M4 6h16M6 12h14M8 18h12M4 12h.01M4 18h.01"/>'),
|
|
120
|
+
prevFootnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 4h.01M4 20h.01"/>'),
|
|
121
|
+
nextFootnote: S('<path d="M9 6l6 6-6 6M8 12h8M20 4h.01M20 20h.01"/>'),
|
|
122
|
+
insertEndnote: S('<path d="M12 4v12M8 12l4 4 4-4M5 20h14"/>'),
|
|
123
|
+
prevEndnote: S('<path d="M15 18l-6-6 6-6M8 12h8M4 20h16"/>'),
|
|
124
|
+
nextEndnote: S('<path d="M9 6l6 6-6 6M8 12h8M4 20h16"/>'),
|
|
125
|
+
footnoteSep: S('<path d="M4 6h16M4 18h16M4 12h4M16 12h4M9 12h6"/>'),
|
|
126
|
+
caption: S('<path d="M4 5h16v11H4zM8 9h8M8 13h5M4 20h10"/>'),
|
|
127
|
+
markCitation: S('<path d="M8 6c-2 0-3 1-3 3s1 3 3 3c-1 2-2 3-4 4M16 6c-2 0-3 1-3 3s1 3 3 3c-1 2-2 3-4 4"/>'),
|
|
128
|
+
insertIndex: S('<path d="M4 5h16M4 11h16M4 17h10M17 15v6M14 18h6"/>'),
|
|
129
|
+
updateIndex: S('<path d="M4 5h16M4 11h16M4 17h10M18 14a3 3 0 1 1-1 4M17 12v2h2"/>'),
|
|
130
|
+
mail: S('<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 7l9 6 9-6"/>'),
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** 取图标 SVG 串(未登记返回空串) */
|
|
134
|
+
export const icon = (name) => ICONS[name] || '';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// [文件] gbdocx·MenuBar —— 顶部菜单栏(结构来自 docx/menus.js 的 buildMenus;条目为函数,每次打开现求值)
|
|
2
|
+
import { openMenu } from './context-menu.js';
|
|
3
|
+
|
|
4
|
+
/** 构建菜单栏 DOM:menus = [{key,label,items:()=>条目[]}];disabledKeys 里的菜单只读档不可点 */
|
|
5
|
+
export function buildMenuBar(menus, disabledKeys = []) {
|
|
6
|
+
const bar = document.createElement('div');
|
|
7
|
+
bar.className = 'gbd-menubar';
|
|
8
|
+
for (const menu of menus) {
|
|
9
|
+
const btn = document.createElement('button');
|
|
10
|
+
btn.type = 'button';
|
|
11
|
+
btn.className = 'gbd-menubar__btn';
|
|
12
|
+
btn.disabled = disabledKeys.includes(menu.key);
|
|
13
|
+
btn.textContent = menu.label;
|
|
14
|
+
btn.addEventListener('click', () => {
|
|
15
|
+
// 按钮态由浮层关闭回调统一收:Esc / 外点 / 点条目都会经过它,
|
|
16
|
+
// 不再挂 gbdocx-menu-close 监听(那条路径只在点条目时触发,其余关闭方式会残留监听)
|
|
17
|
+
btn.classList.add('gbd-is-open');
|
|
18
|
+
openMenu({
|
|
19
|
+
anchor: btn,
|
|
20
|
+
items: menu.items(),
|
|
21
|
+
placement: 'bottom-start',
|
|
22
|
+
onClose: () => btn.classList.remove('gbd-is-open'),
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
bar.appendChild(btn);
|
|
26
|
+
}
|
|
27
|
+
return bar;
|
|
28
|
+
}
|
package/src/ui/panels.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// [文件] gbdocx·Panels —— 目录导航面板 + 批注面板
|
|
2
|
+
|
|
3
|
+
/** 目录面板:items=[{key,text,level}];onLocate(key) */
|
|
4
|
+
export class CatalogPanel {
|
|
5
|
+
constructor(onLocate) {
|
|
6
|
+
this.onLocate = onLocate;
|
|
7
|
+
this.el = document.createElement('aside');
|
|
8
|
+
this.el.className = 'gbd-panel gbd-catalog';
|
|
9
|
+
this.el.innerHTML = '<div class="gbd-panel__title">目录导航</div><div class="gbd-panel__body"></div>';
|
|
10
|
+
this.body = this.el.querySelector('.gbd-panel__body');
|
|
11
|
+
this.activeKey = '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
setItems(items) {
|
|
15
|
+
this.items = items || [];
|
|
16
|
+
this.body.replaceChildren();
|
|
17
|
+
if (!this.items.length) {
|
|
18
|
+
const empty = document.createElement('div');
|
|
19
|
+
empty.className = 'gbd-panel__empty';
|
|
20
|
+
empty.textContent = '正文里还没有标题';
|
|
21
|
+
this.body.appendChild(empty);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const item of this.items) {
|
|
25
|
+
const row = document.createElement('button');
|
|
26
|
+
row.type = 'button';
|
|
27
|
+
row.className = 'gbd-catalog__item';
|
|
28
|
+
row.style.paddingLeft = `${8 + (item.level - 1) * 14}px`;
|
|
29
|
+
row.textContent = item.text;
|
|
30
|
+
row.dataset.key = item.key;
|
|
31
|
+
row.addEventListener('click', () => {
|
|
32
|
+
this.activeKey = item.key;
|
|
33
|
+
this.render();
|
|
34
|
+
this.onLocate(item.key);
|
|
35
|
+
});
|
|
36
|
+
this.body.appendChild(row);
|
|
37
|
+
}
|
|
38
|
+
this.render();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
render() {
|
|
42
|
+
this.body.querySelectorAll('.gbd-catalog__item').forEach((el) => {
|
|
43
|
+
el.classList.toggle('gbd-is-active', el.dataset.key === this.activeKey);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 批注面板:comments=[{key,text,author,date,resolved}];onLocate/toggle/remove */
|
|
49
|
+
export class CommentsPanel {
|
|
50
|
+
constructor(io) {
|
|
51
|
+
this.io = io;
|
|
52
|
+
this.el = document.createElement('aside');
|
|
53
|
+
this.el.className = 'gbd-panel gbd-comments';
|
|
54
|
+
this.el.innerHTML = '<div class="gbd-panel__title">批注</div><div class="gbd-panel__body"></div>';
|
|
55
|
+
this.body = this.el.querySelector('.gbd-panel__body');
|
|
56
|
+
this.activeKey = '';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
setItems(comments) {
|
|
60
|
+
this.comments = comments || [];
|
|
61
|
+
this.body.replaceChildren();
|
|
62
|
+
if (!this.comments.length) {
|
|
63
|
+
const empty = document.createElement('div');
|
|
64
|
+
empty.className = 'gbd-panel__empty';
|
|
65
|
+
empty.textContent = '暂无批注';
|
|
66
|
+
this.body.appendChild(empty);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
for (const c of this.comments) {
|
|
70
|
+
const card = document.createElement('div');
|
|
71
|
+
card.className = 'gbd-cmt-card';
|
|
72
|
+
card.dataset.key = c.key;
|
|
73
|
+
const meta = document.createElement('div');
|
|
74
|
+
meta.className = 'gbd-cmt-card__meta';
|
|
75
|
+
meta.textContent = `${c.author || '匿名'} · ${(c.date || '').slice(0, 16).replace('T', ' ')}`;
|
|
76
|
+
if (c.resolved) {
|
|
77
|
+
const tag = document.createElement('span');
|
|
78
|
+
tag.className = 'gbd-cmt-card__done';
|
|
79
|
+
tag.textContent = '已解决';
|
|
80
|
+
meta.appendChild(tag);
|
|
81
|
+
}
|
|
82
|
+
const text = document.createElement('div');
|
|
83
|
+
text.className = 'gbd-cmt-card__text';
|
|
84
|
+
text.textContent = c.text;
|
|
85
|
+
const actions = document.createElement('div');
|
|
86
|
+
actions.className = 'gbd-cmt-card__actions';
|
|
87
|
+
const toggle = document.createElement('button');
|
|
88
|
+
toggle.type = 'button';
|
|
89
|
+
toggle.className = 'gbd-linkbtn';
|
|
90
|
+
toggle.textContent = c.resolved ? '标记未解决' : '标记解决';
|
|
91
|
+
toggle.addEventListener('click', () => this.io.toggle(c.key));
|
|
92
|
+
const del = document.createElement('button');
|
|
93
|
+
del.type = 'button';
|
|
94
|
+
del.className = 'gbd-linkbtn gbd-linkbtn--danger';
|
|
95
|
+
del.textContent = '删除';
|
|
96
|
+
del.addEventListener('click', () => this.io.remove(c.key));
|
|
97
|
+
actions.append(toggle, del);
|
|
98
|
+
card.append(meta, text, actions);
|
|
99
|
+
card.addEventListener('click', (e) => {
|
|
100
|
+
if (e.target.closest('.gbd-cmt-card__actions')) return;
|
|
101
|
+
this.activeKey = c.key;
|
|
102
|
+
this.render();
|
|
103
|
+
this.io.locate(c.key);
|
|
104
|
+
});
|
|
105
|
+
this.body.appendChild(card);
|
|
106
|
+
}
|
|
107
|
+
this.render();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
render() {
|
|
111
|
+
this.body.querySelectorAll('.gbd-cmt-card').forEach((el) => {
|
|
112
|
+
el.classList.toggle('gbd-is-active', el.dataset.key === this.activeKey);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
package/src/ui/popup.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// [文件] gbdocx·Popup —— 自绘浮层基座(定位/限高/外点关闭/Esc 关闭),供下拉、右键菜单、气泡、色板共用
|
|
2
|
+
import { computePopupPosition } from '../kernel/editor/utils.js';
|
|
3
|
+
|
|
4
|
+
const OPEN = new Set();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 打开一个浮层
|
|
8
|
+
* @param {object} opts
|
|
9
|
+
* @param {HTMLElement|DOMRect} opts.anchor 锚点元素或其矩形
|
|
10
|
+
* @param {HTMLElement} opts.content 浮层内容体(挂到 body)
|
|
11
|
+
* @param {string} [opts.placement] 展开方向(bottom-start 等)
|
|
12
|
+
* @param {string} [opts.className] 附加类名
|
|
13
|
+
* @param {() => void} [opts.onClose] 关闭回调
|
|
14
|
+
* @param {boolean} [opts.closeOnScroll]
|
|
15
|
+
* @param {boolean} [opts.nested] 子级浮层(子菜单):打开时不清掉父级浮层
|
|
16
|
+
* @param {(target: EventTarget) => boolean} [opts.isInside] 额外判定「点在浮层内部」(如子菜单)
|
|
17
|
+
* @returns {{ el: HTMLElement, close: () => void }}
|
|
18
|
+
*/
|
|
19
|
+
export function openPopup({ anchor, content, placement = 'bottom-start', className = '', onClose, closeOnScroll = false, nested = false, isInside }) {
|
|
20
|
+
if (!nested) closeAll();
|
|
21
|
+
const wrap = document.createElement('div');
|
|
22
|
+
wrap.className = `gbd-popup ${className}`.trim();
|
|
23
|
+
wrap.appendChild(content);
|
|
24
|
+
// 样式作用域:浮层挂 body,但仍须落在 .word-scope 子树里(本包 CSS 全部按该前缀作用域化)
|
|
25
|
+
const scope = document.createElement('div');
|
|
26
|
+
scope.className = 'word-scope';
|
|
27
|
+
scope.appendChild(wrap);
|
|
28
|
+
document.body.appendChild(scope);
|
|
29
|
+
|
|
30
|
+
const rect = anchor instanceof Element ? anchor.getBoundingClientRect() : anchor;
|
|
31
|
+
const measure = wrap.getBoundingClientRect();
|
|
32
|
+
const pos = computePopupPosition(rect, { width: measure.width, height: measure.height }, { placement });
|
|
33
|
+
Object.assign(wrap.style, { left: `${pos.left}px`, top: `${pos.top}px` });
|
|
34
|
+
if (pos.maxHeight > 0) wrap.style.maxHeight = `${pos.maxHeight}px`;
|
|
35
|
+
|
|
36
|
+
let attachTimer = 0;
|
|
37
|
+
const close = () => {
|
|
38
|
+
if (!wrap.isConnected) return;
|
|
39
|
+
clearTimeout(attachTimer);
|
|
40
|
+
scope.remove();
|
|
41
|
+
OPEN.delete(entry);
|
|
42
|
+
document.removeEventListener('mousedown', onDocDown, true);
|
|
43
|
+
document.removeEventListener('keydown', onDocKey, true);
|
|
44
|
+
document.removeEventListener('gbdocx-menu-close', onDocDown);
|
|
45
|
+
window.removeEventListener('scroll', onScroll, true);
|
|
46
|
+
window.removeEventListener('resize', onScroll);
|
|
47
|
+
onClose?.();
|
|
48
|
+
};
|
|
49
|
+
const onDocDown = (e) => {
|
|
50
|
+
if (wrap.contains(e.target) || isInside?.(e.target)) return;
|
|
51
|
+
close();
|
|
52
|
+
};
|
|
53
|
+
const onDocKey = (e) => {
|
|
54
|
+
if (e.key === 'Escape') {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
e.stopPropagation();
|
|
57
|
+
close();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const onScroll = () => { if (closeOnScroll) close(); };
|
|
61
|
+
const entry = { close };
|
|
62
|
+
OPEN.add(entry);
|
|
63
|
+
// 延后一拍再挂外点监听:打开它的那次点击不要立刻把它自己关掉。
|
|
64
|
+
// [坑] 定时器必须可取消:close 先跑(Esc/外点)时若回调仍挂着,监听会挂在一个已移除的浮层上永不摘除
|
|
65
|
+
attachTimer = setTimeout(() => {
|
|
66
|
+
if (!wrap.isConnected) return;
|
|
67
|
+
document.addEventListener('mousedown', onDocDown, true);
|
|
68
|
+
window.addEventListener('scroll', onScroll, true);
|
|
69
|
+
window.addEventListener('resize', onScroll);
|
|
70
|
+
}, 0);
|
|
71
|
+
document.addEventListener('keydown', onDocKey, true);
|
|
72
|
+
document.addEventListener('gbdocx-menu-close', onDocDown);
|
|
73
|
+
return { el: wrap, close };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 关闭全部已开浮层(右键菜单等再打开时先收旧) */
|
|
77
|
+
export function closeAll() {
|
|
78
|
+
for (const entry of [...OPEN]) entry.close();
|
|
79
|
+
}
|
package/src/ui/prompt.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// [文件] gbdocx·PromptPopover —— 单字段气泡表单(链接地址 / 批注内容 / 脚注内容共用一套;触发点无稳定 DOM 时走 openAt 锚点)
|
|
2
|
+
import { openPopup } from './popup.js';
|
|
3
|
+
|
|
4
|
+
/** 单字段气泡:openAt(anchor, spec) 打开;关闭未提交回调 onClosed(false),提交返回 true 即关闭并不回调 */
|
|
5
|
+
export class PromptPopover {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.handle = null;
|
|
8
|
+
this.onClosed = null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {HTMLElement|DOMRect|undefined} anchor 锚点(缺省回落屏上方居中)
|
|
13
|
+
* @param {object} spec {title, placeholder, maxlength, required, submit(text)->bool}
|
|
14
|
+
*/
|
|
15
|
+
openAt(anchor, spec = {}) {
|
|
16
|
+
this.close();
|
|
17
|
+
const box = document.createElement('div');
|
|
18
|
+
box.className = 'gbd-prompt';
|
|
19
|
+
box.innerHTML = `
|
|
20
|
+
<div class="gbd-prompt__title"></div>
|
|
21
|
+
<input class="gbd-prompt__input" type="text" />
|
|
22
|
+
<div class="gbd-prompt__actions">
|
|
23
|
+
<button type="button" class="gbd-btn" data-act="cancel">取消</button>
|
|
24
|
+
<button type="button" class="gbd-btn gbd-btn--primary" data-act="ok">确定</button>
|
|
25
|
+
</div>`;
|
|
26
|
+
const titleEl = box.querySelector('.gbd-prompt__title');
|
|
27
|
+
const input = box.querySelector('.gbd-prompt__input');
|
|
28
|
+
titleEl.textContent = spec.title || '';
|
|
29
|
+
if (spec.placeholder) input.placeholder = spec.placeholder;
|
|
30
|
+
if (spec.maxlength) input.maxLength = spec.maxlength;
|
|
31
|
+
input.value = spec.value || '';
|
|
32
|
+
|
|
33
|
+
const closeAndReport = (submitted) => {
|
|
34
|
+
notifyClosed(submitted);
|
|
35
|
+
this.close();
|
|
36
|
+
};
|
|
37
|
+
// 每条气泡只上报一次关闭,但不清空宿主注册的 onClosed:
|
|
38
|
+
// 该回调是实例级(WordApp 只在构造时赋值一次),旧实现关闭第一条气泡就把它置空,
|
|
39
|
+
// 之后所有「取消批注/取消脚注」的未提交回滚都不会再执行
|
|
40
|
+
let settled = false;
|
|
41
|
+
const notifyClosed = (submitted) => {
|
|
42
|
+
if (settled) return;
|
|
43
|
+
settled = true;
|
|
44
|
+
this.onClosed?.(submitted);
|
|
45
|
+
};
|
|
46
|
+
const submit = () => {
|
|
47
|
+
const text = input.value;
|
|
48
|
+
if (spec.required !== false && spec.required !== undefined && spec.required && !String(text).trim()) {
|
|
49
|
+
input.focus();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (spec.submit ? spec.submit(text) !== false : true) {
|
|
53
|
+
notifyClosed(true);
|
|
54
|
+
this.close();
|
|
55
|
+
} else {
|
|
56
|
+
input.focus();
|
|
57
|
+
input.select();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
box.querySelector('[data-act="cancel"]').addEventListener('click', () => closeAndReport(false));
|
|
61
|
+
box.querySelector('[data-act="ok"]').addEventListener('click', submit);
|
|
62
|
+
input.addEventListener('keydown', (e) => {
|
|
63
|
+
if (e.key === 'Enter') {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
submit();
|
|
66
|
+
} else if (e.key === 'Escape') {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
closeAndReport(false);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const rect = anchor instanceof Element ? anchor.getBoundingClientRect() : anchor;
|
|
73
|
+
const fallback = rect || { left: window.innerWidth / 2 - 120, top: 120, right: window.innerWidth / 2 + 120, bottom: 120 };
|
|
74
|
+
this.handle = openPopup({
|
|
75
|
+
anchor: fallback,
|
|
76
|
+
content: box,
|
|
77
|
+
placement: 'bottom-start',
|
|
78
|
+
className: 'gbd-popup--prompt',
|
|
79
|
+
onClose: () => notifyClosed(false),
|
|
80
|
+
});
|
|
81
|
+
requestAnimationFrame(() => input.focus());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
close() {
|
|
85
|
+
const h = this.handle;
|
|
86
|
+
this.handle = null;
|
|
87
|
+
h?.close();
|
|
88
|
+
}
|
|
89
|
+
}
|