gbpptx 0.6.0 → 0.6.2
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 -21
- package/README.md +253 -253
- package/package.json +48 -47
- package/src/index.js +29 -29
- package/src/kernel/model.js +651 -651
- package/src/kernel/parts.js +173 -173
- package/src/kernel/pptx.js +72 -72
- package/src/kernel/print.js +76 -76
- package/src/kernel/read.js +1018 -1018
- package/src/kernel/roundtrip.js +174 -174
- package/src/kernel/text.js +278 -278
- package/src/kernel/write.js +385 -385
- package/web/app/main.js +8 -8
- package/web/app/slides/arrange.js +101 -101
- package/web/app/slides/clipboard.js +93 -93
- package/web/app/slides/file.js +240 -240
- package/web/app/slides/find.js +201 -201
- package/web/app/slides/history.js +100 -100
- package/web/app/slides/keys.js +187 -187
- package/web/app/slides/menus.js +105 -105
- package/web/app/slides/objects.js +254 -254
- package/web/app/slides/render.js +183 -183
- package/web/app/slides/shared.js +85 -85
- package/web/app/slides/slides.js +103 -103
- package/web/app/slides/table.js +102 -102
- package/web/app/slides/text.js +418 -418
- package/web/app/slides/view.js +182 -182
- package/web/app/slides-app.js +354 -354
- package/web/app/ui/canvas.js +769 -769
- package/web/app/ui/color-panel.js +58 -58
- package/web/app/ui/dialogs.js +120 -120
- package/web/app/ui/file-io.js +116 -116
- package/web/app/ui/format-pane.js +427 -427
- package/web/app/ui/icons.js +241 -133
- package/web/app/ui/menu.js +77 -75
- package/web/app/ui/notify.js +45 -45
- package/web/app/ui/page-view.js +221 -221
- package/web/app/ui/popup.js +80 -80
- package/web/app/ui/present.js +292 -292
- package/web/app/ui/ribbon.js +855 -855
- package/web/app/ui/slide-pane.js +197 -197
- package/web/app/ui/statusbar.js +93 -93
- package/web/app/ui/text-styles.js +84 -84
- package/web/app/ui/titlebar.js +253 -250
- package/web/app/ui/transition.js +30 -30
- package/web/index.html +30 -29
- package/web/serve.mjs +26 -23
- package/web/styles/office.css +463 -463
- package/web/styles/slides.css +97 -97
- package/web/styles/tokens.css +154 -154
package/web/app/ui/icons.js
CHANGED
|
@@ -1,133 +1,241 @@
|
|
|
1
|
-
// [文件] gbpptx·图标 —— Office
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
// [文件] gbpptx·图标 —— Office 风格图标注册表:字形数据取自开源 lucide 图标库(ISC 许可),
|
|
2
|
+
// 本文件只维护「业务键名 → lucide 图标」映射,不再手写任何 path。
|
|
3
|
+
import {
|
|
4
|
+
AArrowDown,
|
|
5
|
+
AArrowUp,
|
|
6
|
+
AlignCenter,
|
|
7
|
+
AlignJustify,
|
|
8
|
+
AlignLeft,
|
|
9
|
+
AlignRight,
|
|
10
|
+
AlignVerticalSpaceAround,
|
|
11
|
+
ArrowDownToLine,
|
|
12
|
+
ArrowLeftToLine,
|
|
13
|
+
ArrowRight,
|
|
14
|
+
ArrowRightLeft,
|
|
15
|
+
ArrowRightToLine,
|
|
16
|
+
ArrowUpDown,
|
|
17
|
+
ArrowUpToLine,
|
|
18
|
+
Baseline,
|
|
19
|
+
Blend,
|
|
20
|
+
Bold,
|
|
21
|
+
BookOpen,
|
|
22
|
+
Box,
|
|
23
|
+
BringToFront,
|
|
24
|
+
CaseUpper,
|
|
25
|
+
Check,
|
|
26
|
+
ChevronDown,
|
|
27
|
+
ChevronLeft,
|
|
28
|
+
ChevronRight,
|
|
29
|
+
ChevronUp,
|
|
30
|
+
CircleCheck,
|
|
31
|
+
CircleX,
|
|
32
|
+
ClipboardPaste,
|
|
33
|
+
Clock,
|
|
34
|
+
Combine,
|
|
35
|
+
Copy,
|
|
36
|
+
Crop,
|
|
37
|
+
Crosshair,
|
|
38
|
+
Download,
|
|
39
|
+
Ellipsis,
|
|
40
|
+
Eye,
|
|
41
|
+
EyeOff,
|
|
42
|
+
FileOutput,
|
|
43
|
+
FilePlus,
|
|
44
|
+
FolderOpen,
|
|
45
|
+
Grid2X2,
|
|
46
|
+
Grid3X3,
|
|
47
|
+
House,
|
|
48
|
+
Image,
|
|
49
|
+
IndentDecrease,
|
|
50
|
+
IndentIncrease,
|
|
51
|
+
Info,
|
|
52
|
+
Italic,
|
|
53
|
+
Layers,
|
|
54
|
+
LayoutGrid,
|
|
55
|
+
LayoutTemplate,
|
|
56
|
+
LetterText,
|
|
57
|
+
Link,
|
|
58
|
+
List,
|
|
59
|
+
ListOrdered,
|
|
60
|
+
Lock,
|
|
61
|
+
Maximize,
|
|
62
|
+
MessageSquareText,
|
|
63
|
+
Minimize,
|
|
64
|
+
Minus,
|
|
65
|
+
Monitor,
|
|
66
|
+
MonitorPlay,
|
|
67
|
+
MousePointer2,
|
|
68
|
+
Move,
|
|
69
|
+
PaintBucket,
|
|
70
|
+
PaintRoller,
|
|
71
|
+
PanelLeft,
|
|
72
|
+
PanelRight,
|
|
73
|
+
Pause,
|
|
74
|
+
Pencil,
|
|
75
|
+
Play,
|
|
76
|
+
Plus,
|
|
77
|
+
Presentation,
|
|
78
|
+
Redo2,
|
|
79
|
+
RefreshCw,
|
|
80
|
+
RemoveFormatting,
|
|
81
|
+
Repeat,
|
|
82
|
+
Replace,
|
|
83
|
+
RotateCcw,
|
|
84
|
+
RotateCw,
|
|
85
|
+
Save,
|
|
86
|
+
Scaling,
|
|
87
|
+
Scissors,
|
|
88
|
+
ScreenShare,
|
|
89
|
+
Search,
|
|
90
|
+
SendToBack,
|
|
91
|
+
Shapes,
|
|
92
|
+
Slash,
|
|
93
|
+
Square,
|
|
94
|
+
SquareDashed,
|
|
95
|
+
SquareDashedMousePointer,
|
|
96
|
+
SquarePlus,
|
|
97
|
+
StickyNote,
|
|
98
|
+
Strikethrough,
|
|
99
|
+
SwatchBook,
|
|
100
|
+
Table,
|
|
101
|
+
Table2,
|
|
102
|
+
Trash2,
|
|
103
|
+
TriangleAlert,
|
|
104
|
+
Type,
|
|
105
|
+
Underline,
|
|
106
|
+
Undo2,
|
|
107
|
+
Wallpaper,
|
|
108
|
+
WholeWord,
|
|
109
|
+
X,
|
|
110
|
+
ZoomIn,
|
|
111
|
+
ZoomOut,
|
|
112
|
+
} from 'gbicons/nodes';
|
|
113
|
+
import { iconNodeSvg } from 'gbicons/nodes';
|
|
114
|
+
|
|
115
|
+
/** 业务键名 → lucide IconNode;渲染统一走 iconNodeSvg(24 网格 / 1.7 描边 / class=pp-ico) */
|
|
116
|
+
const BODY = {
|
|
117
|
+
save: Save,
|
|
118
|
+
saveAs: FileOutput,
|
|
119
|
+
open: FolderOpen,
|
|
120
|
+
new: FilePlus,
|
|
121
|
+
close: X,
|
|
122
|
+
back: ChevronLeft,
|
|
123
|
+
home: House,
|
|
124
|
+
undo: Undo2,
|
|
125
|
+
redo: Redo2,
|
|
126
|
+
present: Presentation,
|
|
127
|
+
play: Play,
|
|
128
|
+
pause: Pause,
|
|
129
|
+
paste: ClipboardPaste,
|
|
130
|
+
cut: Scissors,
|
|
131
|
+
copy: Copy,
|
|
132
|
+
formatPainter: PaintRoller,
|
|
133
|
+
delete: Trash2,
|
|
134
|
+
newSlide: SquarePlus,
|
|
135
|
+
layout: LayoutTemplate,
|
|
136
|
+
duplicate: Copy,
|
|
137
|
+
hide: EyeOff,
|
|
138
|
+
reset: RotateCcw,
|
|
139
|
+
bold: Bold,
|
|
140
|
+
italic: Italic,
|
|
141
|
+
underline: Underline,
|
|
142
|
+
strike: Strikethrough,
|
|
143
|
+
fontColor: Baseline,
|
|
144
|
+
fill: PaintBucket,
|
|
145
|
+
outline: SquareDashed,
|
|
146
|
+
effects: Layers,
|
|
147
|
+
clearFormat: RemoveFormatting,
|
|
148
|
+
increaseFont: AArrowUp,
|
|
149
|
+
decreaseFont: AArrowDown,
|
|
150
|
+
alignLeft: AlignLeft,
|
|
151
|
+
alignCenter: AlignCenter,
|
|
152
|
+
alignRight: AlignRight,
|
|
153
|
+
alignJustify: AlignJustify,
|
|
154
|
+
bullets: List,
|
|
155
|
+
numbering: ListOrdered,
|
|
156
|
+
indentIncrease: IndentIncrease,
|
|
157
|
+
indentDecrease: IndentDecrease,
|
|
158
|
+
lineSpacing: AlignVerticalSpaceAround,
|
|
159
|
+
shape: Square,
|
|
160
|
+
shapes: Shapes,
|
|
161
|
+
textBox: Type,
|
|
162
|
+
image: Image,
|
|
163
|
+
table: Table,
|
|
164
|
+
line: Slash,
|
|
165
|
+
arrow: ArrowRight,
|
|
166
|
+
symbol: Grid2X2,
|
|
167
|
+
notes: StickyNote,
|
|
168
|
+
comment: MessageSquareText,
|
|
169
|
+
link: Link,
|
|
170
|
+
arrange: ArrowUpDown,
|
|
171
|
+
bringForward: BringToFront,
|
|
172
|
+
sendBackward: SendToBack,
|
|
173
|
+
rotate: RotateCw,
|
|
174
|
+
theme: SwatchBook,
|
|
175
|
+
background: Wallpaper,
|
|
176
|
+
size: Scaling,
|
|
177
|
+
variants: Blend,
|
|
178
|
+
transition: ArrowRightLeft,
|
|
179
|
+
duration: Clock,
|
|
180
|
+
slideShow: MonitorPlay,
|
|
181
|
+
presenter: ScreenShare,
|
|
182
|
+
monitor: Monitor,
|
|
183
|
+
loop: Repeat,
|
|
184
|
+
find: Search,
|
|
185
|
+
replace: Replace,
|
|
186
|
+
selectAll: SquareDashedMousePointer,
|
|
187
|
+
wordCount: WholeWord,
|
|
188
|
+
viewNormal: PanelLeft,
|
|
189
|
+
viewSorter: LayoutGrid,
|
|
190
|
+
viewReading: BookOpen,
|
|
191
|
+
zoomIn: ZoomIn,
|
|
192
|
+
zoomOut: ZoomOut,
|
|
193
|
+
fitWindow: Maximize,
|
|
194
|
+
grid: Grid3X3,
|
|
195
|
+
guides: Crosshair,
|
|
196
|
+
formatPane: PanelRight,
|
|
197
|
+
check: Check,
|
|
198
|
+
chevronDown: ChevronDown,
|
|
199
|
+
chevronUp: ChevronUp,
|
|
200
|
+
chevronRight: ChevronRight,
|
|
201
|
+
chevronLeft: ChevronLeft,
|
|
202
|
+
plus: Plus,
|
|
203
|
+
minus: Minus,
|
|
204
|
+
more: Ellipsis,
|
|
205
|
+
lock: Lock,
|
|
206
|
+
eye: Eye,
|
|
207
|
+
fullscreen: Maximize,
|
|
208
|
+
fullscreenExit: Minimize,
|
|
209
|
+
crop: Crop,
|
|
210
|
+
resetImage: RefreshCw,
|
|
211
|
+
replaceImage: Replace,
|
|
212
|
+
shadow: Box,
|
|
213
|
+
position: Move,
|
|
214
|
+
textOptions: CaseUpper,
|
|
215
|
+
warning: TriangleAlert,
|
|
216
|
+
info: Info,
|
|
217
|
+
error: CircleX,
|
|
218
|
+
success: CircleCheck,
|
|
219
|
+
cursor: MousePointer2,
|
|
220
|
+
logo: Presentation,
|
|
221
|
+
text: LetterText,
|
|
222
|
+
imageFill: Image,
|
|
223
|
+
tableStyle: Table2,
|
|
224
|
+
rowAbove: ArrowUpToLine,
|
|
225
|
+
rowBelow: ArrowDownToLine,
|
|
226
|
+
colLeft: ArrowLeftToLine,
|
|
227
|
+
colRight: ArrowRightToLine,
|
|
228
|
+
merge: Combine,
|
|
229
|
+
download: Download,
|
|
230
|
+
rename: Pencil,
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const svg = (node, size) => iconNodeSvg(node, { size, cls: 'pp-ico', sw: 1.7 });
|
|
234
|
+
|
|
235
|
+
/** 取图标 SVG 字符串;未知名字返回空串 */
|
|
236
|
+
export function icon(name, size = 16) {
|
|
237
|
+
const node = BODY[name];
|
|
238
|
+
return node ? svg(node, size) : '';
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export const hasIcon = (name) => Boolean(BODY[name]);
|
package/web/app/ui/menu.js
CHANGED
|
@@ -1,75 +1,77 @@
|
|
|
1
|
-
// [文件] gbpptx·菜单 —— 菜单栏 + 下拉/右键菜单渲染(条目口径:label/disabled/checked/danger/shortcut/divided/children/onClick)
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (item.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
lead
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
label
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
sc
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
arrow
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
row.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
row.addEventListener('
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
// [文件] gbpptx·菜单 —— 菜单栏 + 下拉/右键菜单渲染(条目口径:label/disabled/checked/danger/shortcut/divided/children/onClick)
|
|
2
|
+
import { Check, ChevronRight } from 'gbicons/nodes';
|
|
3
|
+
import { iconNodeSvg } from 'gbicons/nodes';
|
|
4
|
+
import { openPopup, closeAll } from './popup.js';
|
|
5
|
+
|
|
6
|
+
const CHECK = iconNodeSvg(Check, { size: 14, sw: 2.4 });
|
|
7
|
+
const SUB = iconNodeSvg(ChevronRight, { size: 12, sw: 2.2 });
|
|
8
|
+
|
|
9
|
+
/** 构建条目列表 DOM(子菜单在 hover 时另开浮层) */
|
|
10
|
+
function buildList(items) {
|
|
11
|
+
const ul = document.createElement('div');
|
|
12
|
+
ul.className = 'gbp-menu__list';
|
|
13
|
+
let subHandle = null;
|
|
14
|
+
const closeSub = () => { subHandle?.close(); subHandle = null; };
|
|
15
|
+
for (const item of items || []) {
|
|
16
|
+
if (item.divided) {
|
|
17
|
+
const sep = document.createElement('div');
|
|
18
|
+
sep.className = 'gbp-menu__sep';
|
|
19
|
+
ul.appendChild(sep);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const row = document.createElement('div');
|
|
23
|
+
row.className = 'gbp-menu__item';
|
|
24
|
+
if (item.disabled) row.classList.add('gbp-is-disabled');
|
|
25
|
+
if (item.danger) row.classList.add('gbp-is-danger');
|
|
26
|
+
if (item.checked) row.classList.add('gbp-is-checked');
|
|
27
|
+
const lead = document.createElement('span');
|
|
28
|
+
lead.className = 'gbp-menu__lead';
|
|
29
|
+
lead.innerHTML = item.checked ? CHECK : (item.colorDot ? `<i class="gbp-menu__dot" style="background:${item.colorDot}"></i>` : '');
|
|
30
|
+
row.appendChild(lead);
|
|
31
|
+
const label = document.createElement('span');
|
|
32
|
+
label.className = 'gbp-menu__label';
|
|
33
|
+
label.textContent = item.label;
|
|
34
|
+
row.appendChild(label);
|
|
35
|
+
if (item.shortcut) {
|
|
36
|
+
const sc = document.createElement('span');
|
|
37
|
+
sc.className = 'gbp-menu__shortcut';
|
|
38
|
+
sc.textContent = item.shortcut;
|
|
39
|
+
row.appendChild(sc);
|
|
40
|
+
}
|
|
41
|
+
if (item.children) {
|
|
42
|
+
const arrow = document.createElement('span');
|
|
43
|
+
arrow.className = 'gbp-menu__arrow';
|
|
44
|
+
arrow.innerHTML = SUB;
|
|
45
|
+
row.appendChild(arrow);
|
|
46
|
+
let timer = 0;
|
|
47
|
+
row.addEventListener('mouseenter', () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
timer = setTimeout(() => {
|
|
50
|
+
closeSub();
|
|
51
|
+
if (item.disabled) return;
|
|
52
|
+
subHandle = openPopup({ anchor: row.getBoundingClientRect(), content: buildList(item.children), placement: 'right-start', className: 'gbp-menu' });
|
|
53
|
+
}, 60);
|
|
54
|
+
});
|
|
55
|
+
row.addEventListener('mouseleave', () => clearTimeout(timer));
|
|
56
|
+
} else {
|
|
57
|
+
row.addEventListener('click', (e) => {
|
|
58
|
+
if (item.disabled) return;
|
|
59
|
+
item.onClick?.(e);
|
|
60
|
+
document.dispatchEvent(new CustomEvent('gbpptx-menu-close'));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
ul.appendChild(row);
|
|
64
|
+
}
|
|
65
|
+
return ul;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 打开下拉菜单(锚点元素/矩形) */
|
|
69
|
+
export const openMenu = ({ anchor, items, placement = 'bottom-start', onClose }) =>
|
|
70
|
+
openPopup({ anchor, content: buildList(items), placement, className: 'gbp-menu', onClose });
|
|
71
|
+
|
|
72
|
+
/** 打开右键菜单(客户端坐标) */
|
|
73
|
+
export const openContextMenu = ({ x, y, items }) =>
|
|
74
|
+
openPopup({ anchor: { left: x, top: y, right: x, bottom: y }, content: buildList(items), placement: 'bottom-start', className: 'gbp-menu' });
|
|
75
|
+
|
|
76
|
+
/** 关闭当前全部菜单/浮层(外部动作前调用) */
|
|
77
|
+
export { closeAll };
|
package/web/app/ui/notify.js
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
// [文件] gbpptx·notify —— 轻量 toast 通知(success / error / warning / info)
|
|
2
|
-
|
|
3
|
-
const HOST_ID = 'gbpptx-notify-host';
|
|
4
|
-
const ICONS = { success: '✓', error: '✕', warning: '!', info: 'i' };
|
|
5
|
-
|
|
6
|
-
function host() {
|
|
7
|
-
let el = document.getElementById(HOST_ID);
|
|
8
|
-
if (!el) {
|
|
9
|
-
el = document.createElement('div');
|
|
10
|
-
el.id = HOST_ID;
|
|
11
|
-
el.className = 'gbdocx-notify-host';
|
|
12
|
-
document.body.appendChild(el);
|
|
13
|
-
}
|
|
14
|
-
return el;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function show(type, message, duration = 2600) {
|
|
18
|
-
const root = host();
|
|
19
|
-
const item = document.createElement('div');
|
|
20
|
-
item.className = `gbp-notify gbp-notify--${type}`;
|
|
21
|
-
const badge = document.createElement('span');
|
|
22
|
-
badge.className = 'gbp-notify__badge';
|
|
23
|
-
badge.textContent = ICONS[type] || 'i';
|
|
24
|
-
const text = document.createElement('span');
|
|
25
|
-
text.className = 'gbp-notify__text';
|
|
26
|
-
text.textContent = String(message ?? '');
|
|
27
|
-
item.append(badge, text);
|
|
28
|
-
root.appendChild(item);
|
|
29
|
-
requestAnimationFrame(() => item.classList.add('gbp-is-in'));
|
|
30
|
-
const close = () => {
|
|
31
|
-
item.classList.remove('gbp-is-in');
|
|
32
|
-
setTimeout(() => item.remove(), 200);
|
|
33
|
-
};
|
|
34
|
-
item.addEventListener('click', close);
|
|
35
|
-
if (duration > 0) setTimeout(close, duration);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const notify = {
|
|
39
|
-
success: (m, d) => show('success', m, d),
|
|
40
|
-
error: (m, d) => show('error', m, d ?? 3600),
|
|
41
|
-
warning: (m, d) => show('warning', m, d ?? 3200),
|
|
42
|
-
info: (m, d) => show('info', m, d),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export default notify;
|
|
1
|
+
// [文件] gbpptx·notify —— 轻量 toast 通知(success / error / warning / info)
|
|
2
|
+
|
|
3
|
+
const HOST_ID = 'gbpptx-notify-host';
|
|
4
|
+
const ICONS = { success: '✓', error: '✕', warning: '!', info: 'i' };
|
|
5
|
+
|
|
6
|
+
function host() {
|
|
7
|
+
let el = document.getElementById(HOST_ID);
|
|
8
|
+
if (!el) {
|
|
9
|
+
el = document.createElement('div');
|
|
10
|
+
el.id = HOST_ID;
|
|
11
|
+
el.className = 'gbdocx-notify-host';
|
|
12
|
+
document.body.appendChild(el);
|
|
13
|
+
}
|
|
14
|
+
return el;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function show(type, message, duration = 2600) {
|
|
18
|
+
const root = host();
|
|
19
|
+
const item = document.createElement('div');
|
|
20
|
+
item.className = `gbp-notify gbp-notify--${type}`;
|
|
21
|
+
const badge = document.createElement('span');
|
|
22
|
+
badge.className = 'gbp-notify__badge';
|
|
23
|
+
badge.textContent = ICONS[type] || 'i';
|
|
24
|
+
const text = document.createElement('span');
|
|
25
|
+
text.className = 'gbp-notify__text';
|
|
26
|
+
text.textContent = String(message ?? '');
|
|
27
|
+
item.append(badge, text);
|
|
28
|
+
root.appendChild(item);
|
|
29
|
+
requestAnimationFrame(() => item.classList.add('gbp-is-in'));
|
|
30
|
+
const close = () => {
|
|
31
|
+
item.classList.remove('gbp-is-in');
|
|
32
|
+
setTimeout(() => item.remove(), 200);
|
|
33
|
+
};
|
|
34
|
+
item.addEventListener('click', close);
|
|
35
|
+
if (duration > 0) setTimeout(close, duration);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const notify = {
|
|
39
|
+
success: (m, d) => show('success', m, d),
|
|
40
|
+
error: (m, d) => show('error', m, d ?? 3600),
|
|
41
|
+
warning: (m, d) => show('warning', m, d ?? 3200),
|
|
42
|
+
info: (m, d) => show('info', m, d),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default notify;
|