gbpptx 0.6.1 → 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 -253
- 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
|
@@ -1,427 +1,427 @@
|
|
|
1
|
-
// [文件] gbpptx·格式窗格 —— Office「设置形状格式」任务窗格(大小/填充/线条/文本/图片/表格)
|
|
2
|
-
|
|
3
|
-
import { SLIDE_SIZES, TABLE_STYLES, THEME_KEYS, TRANSITIONS, THEMES, themeOf } from '../../../src/kernel/model.js';
|
|
4
|
-
import { FONT_FAMILIES, TEXT_COLORS } from './text-styles.js';
|
|
5
|
-
import { openColorPanel } from './color-panel.js';
|
|
6
|
-
import { icon } from './icons.js';
|
|
7
|
-
|
|
8
|
-
const el = (tag, cls, text) => {
|
|
9
|
-
const node = document.createElement(tag);
|
|
10
|
-
if (cls) node.className = cls;
|
|
11
|
-
if (text != null) node.textContent = text;
|
|
12
|
-
return node;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const field = (label, control) => {
|
|
16
|
-
const row = el('label', 'pp-fp-field');
|
|
17
|
-
const span = el('span', 'pp-fp-field__label', label);
|
|
18
|
-
row.append(span, control);
|
|
19
|
-
return row;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const numberInput = (value, onChange, { min = -10000, max = 10000, step = 1 } = {}) => {
|
|
23
|
-
const input = el('input', 'pp-input pp-input--num');
|
|
24
|
-
input.type = 'number';
|
|
25
|
-
input.min = String(min);
|
|
26
|
-
input.max = String(max);
|
|
27
|
-
input.step = String(step);
|
|
28
|
-
input.value = String(Math.round(value * 100) / 100);
|
|
29
|
-
input.addEventListener('change', () => {
|
|
30
|
-
const v = Number(input.value);
|
|
31
|
-
if (Number.isFinite(v)) onChange(v);
|
|
32
|
-
});
|
|
33
|
-
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') input.blur(); });
|
|
34
|
-
return input;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
const selectInput = (options, value, onChange) => {
|
|
38
|
-
const sel = el('select', 'pp-input');
|
|
39
|
-
for (const o of options) {
|
|
40
|
-
const opt = document.createElement('option');
|
|
41
|
-
opt.value = o.value;
|
|
42
|
-
opt.textContent = o.label;
|
|
43
|
-
sel.appendChild(opt);
|
|
44
|
-
}
|
|
45
|
-
sel.value = value ?? '';
|
|
46
|
-
sel.addEventListener('change', () => onChange(sel.value));
|
|
47
|
-
return sel;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const toggleButton = (label, on, onClick) => {
|
|
51
|
-
const b = el('button', `pp-toggle${on ? ' gbp-is-active' : ''}`, label);
|
|
52
|
-
b.type = 'button';
|
|
53
|
-
b.addEventListener('click', onClick);
|
|
54
|
-
return b;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const colorControl = (value, onPick, { allowNone = true, title = '颜色', noneLabel = '无颜色' } = {}) => {
|
|
58
|
-
const b = el('button', 'pp-colorfield');
|
|
59
|
-
b.type = 'button';
|
|
60
|
-
const dot = el('i', 'pp-colorfield__dot');
|
|
61
|
-
dot.style.background = value || 'transparent';
|
|
62
|
-
const text = el('span', '', value || '默认');
|
|
63
|
-
b.append(dot, text);
|
|
64
|
-
b.addEventListener('click', () => {
|
|
65
|
-
openColorPanel({ anchor: b, colors: TEXT_COLORS, value, title, columns: 10, allowNone, noneLabel, onPick });
|
|
66
|
-
});
|
|
67
|
-
return b;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export class FormatPane {
|
|
71
|
-
constructor(app) {
|
|
72
|
-
this.app = app;
|
|
73
|
-
this.el = el('aside', 'pp-formatpane');
|
|
74
|
-
this.el.hidden = true;
|
|
75
|
-
this.closedSections = new Set();
|
|
76
|
-
this.title = '';
|
|
77
|
-
this.body = null;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
open() {
|
|
81
|
-
this.app.formatPaneOpen = true;
|
|
82
|
-
this.el.hidden = false;
|
|
83
|
-
this.render();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
close() {
|
|
87
|
-
this.app.formatPaneOpen = false;
|
|
88
|
-
this.app.prefs.formatPaneOpen = false;
|
|
89
|
-
this.app.persistPrefs();
|
|
90
|
-
this.el.hidden = true;
|
|
91
|
-
this.app.updateLayout();
|
|
92
|
-
this.app.ribbon.refresh();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
toggle() {
|
|
96
|
-
if (this.app.formatPaneOpen) this.close();
|
|
97
|
-
else this.open();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
render() {
|
|
101
|
-
if (!this.app.formatPaneOpen || (this.app.view && this.app.view !== 'normal')) {
|
|
102
|
-
this.el.hidden = true;
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const bodyScroll = this.body?.scrollTop || 0;
|
|
106
|
-
this.el.hidden = false;
|
|
107
|
-
this.el.replaceChildren();
|
|
108
|
-
const head = el('div', 'pp-formatpane__head');
|
|
109
|
-
const title = el('span', 'pp-formatpane__title');
|
|
110
|
-
const close = el('button', 'pp-iconbtn');
|
|
111
|
-
close.type = 'button';
|
|
112
|
-
close.innerHTML = icon('close', 16);
|
|
113
|
-
close.title = '关闭';
|
|
114
|
-
close.addEventListener('click', () => this.close());
|
|
115
|
-
head.append(title, close);
|
|
116
|
-
const body = el('div', 'pp-formatpane__body');
|
|
117
|
-
this.el.append(head, body);
|
|
118
|
-
this.body = body;
|
|
119
|
-
|
|
120
|
-
const objs = this.app.selectedObjects();
|
|
121
|
-
if (objs.length === 0) {
|
|
122
|
-
title.textContent = '设置背景格式';
|
|
123
|
-
this.renderSlide(body);
|
|
124
|
-
} else if (objs.length > 1) {
|
|
125
|
-
title.textContent = `设置 ${objs.length} 个对象`;
|
|
126
|
-
this.renderMulti(body, objs);
|
|
127
|
-
} else {
|
|
128
|
-
const o = objs[0];
|
|
129
|
-
title.textContent = o.type === 'image' ? '设置图片格式' : o.type === 'table' ? '设置表格格式' : o.type === 'line' ? '设置线条格式' : '设置形状格式';
|
|
130
|
-
this.renderObject(body, o);
|
|
131
|
-
}
|
|
132
|
-
body.scrollTop = bodyScroll;
|
|
133
|
-
this.title = title.textContent;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
section(body, key, title, content, { open = !this.closedSections.has(key) } = {}) {
|
|
137
|
-
const sec = el('section', `pp-fp-section${open ? ' gbp-is-open' : ''}`);
|
|
138
|
-
const head = el('button', 'pp-fp-section__head');
|
|
139
|
-
head.type = 'button';
|
|
140
|
-
head.innerHTML = `<span>${title}</span>${icon('chevronDown', 14)}`;
|
|
141
|
-
const box = el('div', 'pp-fp-section__body');
|
|
142
|
-
box.append(...(Array.isArray(content) ? content : [content]));
|
|
143
|
-
head.addEventListener('click', () => {
|
|
144
|
-
const isOpen = sec.classList.toggle('gbp-is-open');
|
|
145
|
-
box.hidden = !isOpen;
|
|
146
|
-
if (isOpen) this.closedSections.delete(key);
|
|
147
|
-
else this.closedSections.add(key);
|
|
148
|
-
});
|
|
149
|
-
box.hidden = !open;
|
|
150
|
-
sec.append(head, box);
|
|
151
|
-
body.appendChild(sec);
|
|
152
|
-
return sec;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/* ===================== 幻灯片 ===================== */
|
|
156
|
-
|
|
157
|
-
renderSlide(body) {
|
|
158
|
-
const app = this.app;
|
|
159
|
-
const slide = app.currentSlide();
|
|
160
|
-
const bg = slide.bg || '';
|
|
161
|
-
const theme = themeOf(app.snapshot.theme);
|
|
162
|
-
|
|
163
|
-
this.section(body, 'slide', '幻灯片', [
|
|
164
|
-
field('背景色', colorControl(bg || theme.bg, (c) => app.setSlideBg(c), { title: '页面背景色', noneLabel: '跟随主题' })),
|
|
165
|
-
field('画幅', selectInput(
|
|
166
|
-
[...SLIDE_SIZES.map((s) => ({ value: s.key, label: s.label })), { value: 'custom', label: `自定义 ${app.size.w}×${app.size.h}` }],
|
|
167
|
-
SLIDE_SIZES.find((s) => s.w === app.size.w && s.h === app.size.h)?.key || 'custom',
|
|
168
|
-
(v) => { if (v !== 'custom') app.setSlideSize(v); },
|
|
169
|
-
)),
|
|
170
|
-
field('主题', selectInput(THEME_KEYS.map((k) => ({ value: k, label: THEMES[k].label })), app.snapshot.theme, (v) => app.setTheme(v))),
|
|
171
|
-
]);
|
|
172
|
-
|
|
173
|
-
this.section(body, 'transition', '切换', [
|
|
174
|
-
field('效果', selectInput(TRANSITIONS.map((t) => ({ value: t.key, label: t.label })), slide.transition?.type || 'none', (v) => app.setTransition({ type: v }))),
|
|
175
|
-
field('速度', selectInput([
|
|
176
|
-
{ value: 'fast', label: '0.5 秒' }, { value: 'med', label: '1 秒' }, { value: 'slow', label: '2 秒' },
|
|
177
|
-
], slide.transition?.speed || 'med', (v) => app.setTransition({ speed: v }))),
|
|
178
|
-
field('状态', (() => {
|
|
179
|
-
const row = el('div', 'pp-inline');
|
|
180
|
-
row.append(toggleButton(slide.hidden ? '已隐藏' : '显示', !slide.hidden, () => app.toggleSlideHidden()));
|
|
181
|
-
row.append(el('span', 'pp-fp-hint', `第 ${app.index + 1} / ${app.snapshot.slides.length} 页`));
|
|
182
|
-
return row;
|
|
183
|
-
})()),
|
|
184
|
-
]);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/* ===================== 多选 ===================== */
|
|
188
|
-
|
|
189
|
-
renderMulti(body, objs) {
|
|
190
|
-
const app = this.app;
|
|
191
|
-
const align = el('div', 'pp-grid-buttons');
|
|
192
|
-
for (const [key, label] of [['left', '左对齐'], ['centerH', '水平居中'], ['right', '右对齐'], ['top', '顶端'], ['middle', '垂直居中'], ['bottom', '底端']]) {
|
|
193
|
-
const b = el('button', 'pp-chip', label);
|
|
194
|
-
b.type = 'button';
|
|
195
|
-
b.addEventListener('click', () => app.alignToSlide(key));
|
|
196
|
-
align.appendChild(b);
|
|
197
|
-
}
|
|
198
|
-
const dist = el('div', 'pp-grid-buttons');
|
|
199
|
-
for (const [key, label] of [['h', '横向分布'], ['v', '纵向分布']]) {
|
|
200
|
-
const b = el('button', 'pp-chip', label);
|
|
201
|
-
b.type = 'button';
|
|
202
|
-
b.disabled = objs.length < 3;
|
|
203
|
-
b.addEventListener('click', () => app.distribute(key));
|
|
204
|
-
dist.appendChild(b);
|
|
205
|
-
}
|
|
206
|
-
const order = el('div', 'pp-grid-buttons');
|
|
207
|
-
for (const [key, label] of [['front', '置于顶层'], ['forward', '上移一层'], ['backward', '下移一层'], ['back', '置于底层']]) {
|
|
208
|
-
const b = el('button', 'pp-chip', label);
|
|
209
|
-
b.type = 'button';
|
|
210
|
-
b.addEventListener('click', () => app.arrange(key));
|
|
211
|
-
order.appendChild(b);
|
|
212
|
-
}
|
|
213
|
-
this.section(body, 'align', '对齐', align);
|
|
214
|
-
this.section(body, 'dist', '分布', dist);
|
|
215
|
-
this.section(body, 'order', '排列', order);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/* ===================== 对象 ===================== */
|
|
219
|
-
|
|
220
|
-
renderObject(body, o) {
|
|
221
|
-
const app = this.app;
|
|
222
|
-
const p = o.props;
|
|
223
|
-
|
|
224
|
-
/* 大小与位置 */
|
|
225
|
-
const sizeBox = [
|
|
226
|
-
field('宽度', numberInput(Math.abs(o.w), (v) => app.updateObject(o.id, { w: o.w < 0 ? -Math.abs(v) : Math.abs(v) }), { min: 1 })),
|
|
227
|
-
field('高度', numberInput(Math.abs(o.h), (v) => app.updateObject(o.id, { h: o.h < 0 ? -Math.abs(v) : Math.abs(v) }), { min: 1 })),
|
|
228
|
-
field('X 位置', numberInput(o.x, (v) => app.updateObject(o.id, { x: v }))),
|
|
229
|
-
field('Y 位置', numberInput(o.y, (v) => app.updateObject(o.id, { y: v }))),
|
|
230
|
-
field('旋转', numberInput(o.rot || 0, (v) => app.updateObject(o.id, { rot: v }), { min: -360, max: 360 })),
|
|
231
|
-
];
|
|
232
|
-
this.section(body, 'size', '大小与位置', sizeBox);
|
|
233
|
-
|
|
234
|
-
if (o.type === 'text') {
|
|
235
|
-
this.section(body, 'text', '文本选项', this.textControls(o, true));
|
|
236
|
-
this.section(body, 'fill', '填充与线条', this.fillControls(o, { text: true }));
|
|
237
|
-
} else if (o.type === 'shape') {
|
|
238
|
-
this.section(body, 'fill', '填充与线条', this.fillControls(o));
|
|
239
|
-
this.section(body, 'text', '文本选项', this.textControls(o, true));
|
|
240
|
-
} else if (o.type === 'line') {
|
|
241
|
-
this.section(body, 'line', '线条', this.lineControls(o));
|
|
242
|
-
} else if (o.type === 'image') {
|
|
243
|
-
this.section(body, 'image', '图片', this.imageControls(o));
|
|
244
|
-
this.section(body, 'alt', '替代文字', [
|
|
245
|
-
field('说明', (() => {
|
|
246
|
-
const input = el('input', 'pp-input');
|
|
247
|
-
input.type = 'text';
|
|
248
|
-
input.value = p.alt || '';
|
|
249
|
-
input.placeholder = '描述图片内容';
|
|
250
|
-
input.addEventListener('change', () => app.updateProps(o.id, { alt: input.value }));
|
|
251
|
-
return input;
|
|
252
|
-
})()),
|
|
253
|
-
]);
|
|
254
|
-
} else if (o.type === 'table') {
|
|
255
|
-
this.section(body, 'table', '表格', this.tableControls(o));
|
|
256
|
-
this.section(body, 'text', '文字', this.tableTextControls(o));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
textControls(o, includeAnchor) {
|
|
261
|
-
const app = this.app;
|
|
262
|
-
const p = o.props;
|
|
263
|
-
const font = selectInput(
|
|
264
|
-
[{ value: '', label: '默认' }, ...FONT_FAMILIES.map((f) => ({ value: f.value, label: f.label }))],
|
|
265
|
-
p.font || '',
|
|
266
|
-
(v) => app.updateProps(o.id, { font: v }),
|
|
267
|
-
);
|
|
268
|
-
const size = numberInput(p.fontSize || 24, (v) => app.setFontSize(v), { min: 6, max: 200 });
|
|
269
|
-
const styleRow = el('div', 'pp-inline');
|
|
270
|
-
for (const [key, label, iconName] of [['bold', '粗体', 'bold'], ['italic', '斜体', 'italic'], ['underline', '下划线', 'underline'], ['strike', '删除线', 'strike']]) {
|
|
271
|
-
const b = el('button', `pp-toggle${p[key] ? ' gbp-is-active' : ''}`);
|
|
272
|
-
b.type = 'button';
|
|
273
|
-
b.title = label;
|
|
274
|
-
b.innerHTML = icon(iconName, 15);
|
|
275
|
-
b.addEventListener('click', () => app.updateProps(o.id, { [key]: !p[key] }));
|
|
276
|
-
styleRow.appendChild(b);
|
|
277
|
-
}
|
|
278
|
-
const alignRow = el('div', 'pp-segmented');
|
|
279
|
-
for (const [key, name] of [['left', 'alignLeft'], ['center', 'alignCenter'], ['right', 'alignRight'], ['justify', 'alignJustify']]) {
|
|
280
|
-
const b = el('button', `pp-segmented__btn${p.align === key ? ' gbp-is-active' : ''}`);
|
|
281
|
-
b.type = 'button';
|
|
282
|
-
b.title = key;
|
|
283
|
-
b.innerHTML = icon(name, 15);
|
|
284
|
-
b.addEventListener('click', () => app.updateProps(o.id, { align: key }));
|
|
285
|
-
alignRow.appendChild(b);
|
|
286
|
-
}
|
|
287
|
-
const color = colorControl(
|
|
288
|
-
o.type === 'shape' ? (p.textColor || '') : (p.color || ''),
|
|
289
|
-
(c) => app.updateProps(o.id, o.type === 'shape' ? { textColor: c || '#ffffff' } : { color: c }),
|
|
290
|
-
{ title: '字体颜色' },
|
|
291
|
-
);
|
|
292
|
-
const controls = [
|
|
293
|
-
field('字体', font),
|
|
294
|
-
field('字号', size),
|
|
295
|
-
field('样式', styleRow),
|
|
296
|
-
field('对齐', alignRow),
|
|
297
|
-
field('颜色', color),
|
|
298
|
-
field('行距', numberInput(p.lineSpacing || 1, (v) => app.updateProps(o.id, { lineSpacing: v }), { min: 0.6, max: 4, step: 0.05 })),
|
|
299
|
-
];
|
|
300
|
-
if (includeAnchor) {
|
|
301
|
-
const anchorRow = el('div', 'pp-segmented');
|
|
302
|
-
for (const [key, label] of [['top', '顶端'], ['middle', '中部'], ['bottom', '底端']]) {
|
|
303
|
-
const b = el('button', `pp-segmented__btn${(p.anchor || 'top') === key ? ' gbp-is-active' : ''}`, label);
|
|
304
|
-
b.type = 'button';
|
|
305
|
-
b.addEventListener('click', () => app.updateProps(o.id, { anchor: key }));
|
|
306
|
-
anchorRow.appendChild(b);
|
|
307
|
-
}
|
|
308
|
-
controls.push(field('垂直对齐', anchorRow));
|
|
309
|
-
}
|
|
310
|
-
return controls;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
fillControls(o, { text = false } = {}) {
|
|
314
|
-
const app = this.app;
|
|
315
|
-
const p = o.props;
|
|
316
|
-
const fillMode = el('div', 'pp-segmented');
|
|
317
|
-
for (const [key, label] of [['solid', '纯色'], ['none', '无填充']]) {
|
|
318
|
-
const b = el('button', `pp-segmented__btn${(p.fill ? 'solid' : 'none') === key ? ' gbp-is-active' : ''}`, label);
|
|
319
|
-
b.type = 'button';
|
|
320
|
-
b.addEventListener('click', () => app.updateProps(o.id, { fill: key === 'none' ? '' : (p.fill || themeOf(app.snapshot.theme).accent) }));
|
|
321
|
-
fillMode.appendChild(b);
|
|
322
|
-
}
|
|
323
|
-
const fillColor = colorControl(p.fill || '', (c) => app.updateProps(o.id, { fill: c }), { title: '填充颜色' });
|
|
324
|
-
const lineMode = el('div', 'pp-segmented');
|
|
325
|
-
for (const [key, label] of [['solid', '实线'], ['none', '无线条']]) {
|
|
326
|
-
const b = el('button', `pp-segmented__btn${(p.stroke && p.strokeW > 0 ? 'solid' : 'none') === key ? ' gbp-is-active' : ''}`, label);
|
|
327
|
-
b.type = 'button';
|
|
328
|
-
b.addEventListener('click', () => app.updateProps(o.id, {
|
|
329
|
-
stroke: key === 'none' ? '' : (p.stroke || themeOf(app.snapshot.theme).text),
|
|
330
|
-
strokeW: key === 'none' ? 0 : Math.max(1, p.strokeW || 1),
|
|
331
|
-
}));
|
|
332
|
-
lineMode.appendChild(b);
|
|
333
|
-
}
|
|
334
|
-
const lineColor = colorControl(p.stroke || '', (c) => app.updateProps(o.id, {
|
|
335
|
-
stroke: c,
|
|
336
|
-
strokeW: c ? Math.max(1, p.strokeW || 1) : 0,
|
|
337
|
-
}), { title: '线条颜色' });
|
|
338
|
-
const width = numberInput(p.strokeW || 0, (v) => app.updateProps(o.id, { strokeW: v, stroke: p.stroke || themeOf(app.snapshot.theme).text }), { min: 0, max: 40, step: 1 });
|
|
339
|
-
const dash = selectInput([
|
|
340
|
-
{ value: 'solid', label: '实线' }, { value: 'dash', label: '虚线' }, { value: 'dot', label: '点线' },
|
|
341
|
-
{ value: 'lgDash', label: '长虚线' }, { value: 'dashDot', label: '点划线' },
|
|
342
|
-
], p.dash || 'solid', (v) => app.updateProps(o.id, { dash: v }));
|
|
343
|
-
return [
|
|
344
|
-
field('填充', fillMode),
|
|
345
|
-
field('填充色', fillColor),
|
|
346
|
-
field('线条', lineMode),
|
|
347
|
-
field('线条色', lineColor),
|
|
348
|
-
field('线宽', width),
|
|
349
|
-
field('线型', dash),
|
|
350
|
-
field('阴影', toggleButton(p.shadow ? '已开启' : '关闭', !!p.shadow, () => app.updateProps(o.id, { shadow: !p.shadow }))),
|
|
351
|
-
];
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
lineControls(o) {
|
|
355
|
-
const app = this.app;
|
|
356
|
-
const p = o.props;
|
|
357
|
-
return [
|
|
358
|
-
field('颜色', colorControl(p.stroke || '', (c) => app.updateProps(o.id, { stroke: c }), { title: '线条颜色' })),
|
|
359
|
-
field('线宽', numberInput(p.strokeW || 2, (v) => app.updateProps(o.id, { strokeW: v }), { min: 1, max: 40 })),
|
|
360
|
-
field('线型', selectInput([
|
|
361
|
-
{ value: 'solid', label: '实线' }, { value: 'dash', label: '虚线' }, { value: 'dot', label: '点线' },
|
|
362
|
-
{ value: 'lgDash', label: '长虚线' }, { value: 'dashDot', label: '点划线' },
|
|
363
|
-
], p.dash || 'solid', (v) => app.updateProps(o.id, { dash: v }))),
|
|
364
|
-
field('箭头', (() => {
|
|
365
|
-
const row = el('div', 'pp-inline');
|
|
366
|
-
row.append(
|
|
367
|
-
toggleButton('起点', !!p.arrowStart, () => app.updateProps(o.id, { arrowStart: !p.arrowStart })),
|
|
368
|
-
toggleButton('终点', !!p.arrowEnd, () => app.updateProps(o.id, { arrowEnd: !p.arrowEnd })),
|
|
369
|
-
);
|
|
370
|
-
return row;
|
|
371
|
-
})()),
|
|
372
|
-
];
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
imageControls(o) {
|
|
376
|
-
const app = this.app;
|
|
377
|
-
const p = o.props;
|
|
378
|
-
const crop = p.crop || { l: 0, t: 0, r: 0, b: 0 };
|
|
379
|
-
const setCrop = (key, v) => app.updateProps(o.id, { crop: { ...crop, [key]: Math.max(0, Math.min(49, v)) } });
|
|
380
|
-
const cropBox = [
|
|
381
|
-
field('左', numberInput(crop.l || 0, (v) => setCrop('l', v), { min: 0, max: 49 })),
|
|
382
|
-
field('上', numberInput(crop.t || 0, (v) => setCrop('t', v), { min: 0, max: 49 })),
|
|
383
|
-
field('右', numberInput(crop.r || 0, (v) => setCrop('r', v), { min: 0, max: 49 })),
|
|
384
|
-
field('下', numberInput(crop.b || 0, (v) => setCrop('b', v), { min: 0, max: 49 })),
|
|
385
|
-
field('', (() => {
|
|
386
|
-
const row = el('div', 'pp-inline');
|
|
387
|
-
const reset = el('button', 'pp-chip', '重置裁剪');
|
|
388
|
-
reset.type = 'button';
|
|
389
|
-
reset.addEventListener('click', () => app.updateProps(o.id, { crop: { l: 0, t: 0, r: 0, b: 0 } }));
|
|
390
|
-
row.appendChild(reset);
|
|
391
|
-
return row;
|
|
392
|
-
})()),
|
|
393
|
-
];
|
|
394
|
-
return [
|
|
395
|
-
field('替换', (() => {
|
|
396
|
-
const b = el('button', 'pp-chip', '选择新图片…');
|
|
397
|
-
b.type = 'button';
|
|
398
|
-
b.addEventListener('click', () => app.replaceSelectedImage());
|
|
399
|
-
return b;
|
|
400
|
-
})()),
|
|
401
|
-
...cropBox,
|
|
402
|
-
field('阴影', toggleButton(p.shadow ? '已开启' : '关闭', !!p.shadow, () => app.updateProps(o.id, { shadow: !p.shadow }))),
|
|
403
|
-
];
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
tableControls(o) {
|
|
407
|
-
const app = this.app;
|
|
408
|
-
const p = o.props;
|
|
409
|
-
return [
|
|
410
|
-
field('样式', selectInput(TABLE_STYLES.map((s) => ({ value: s.key, label: s.label })), p.tableStyle || 'plain', (v) => app.setTableStyle(v))),
|
|
411
|
-
field('标题行', toggleButton(p.headerRow ? '已开启' : '关闭', !!p.headerRow, () => app.toggleHeaderRow())),
|
|
412
|
-
field('镶边行', toggleButton(p.bandedRows ? '已开启' : '关闭', !!p.bandedRows, () => app.toggleBandedRows())),
|
|
413
|
-
field('行数', numberInput(p.rows.length, (v) => app.resizeTable(o.id, Math.round(v), p.rows[0].length), { min: 1, max: 50 })),
|
|
414
|
-
field('列数', numberInput(p.rows[0].length, (v) => app.resizeTable(o.id, p.rows.length, Math.round(v)), { min: 1, max: 30 })),
|
|
415
|
-
];
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
tableTextControls(o) {
|
|
419
|
-
const app = this.app;
|
|
420
|
-
const p = o.props;
|
|
421
|
-
return [
|
|
422
|
-
field('字体', selectInput([{ value: '', label: '默认' }, ...FONT_FAMILIES.map((f) => ({ value: f.value, label: f.label }))], p.font || '', (v) => app.updateProps(o.id, { font: v }))),
|
|
423
|
-
field('字号', numberInput(p.fontSize || 16, (v) => app.updateProps(o.id, { fontSize: v }), { min: 6, max: 100 })),
|
|
424
|
-
field('颜色', colorControl(p.color || '', (c) => app.updateProps(o.id, { color: c }), { title: '表格文字颜色' })),
|
|
425
|
-
];
|
|
426
|
-
}
|
|
427
|
-
}
|
|
1
|
+
// [文件] gbpptx·格式窗格 —— Office「设置形状格式」任务窗格(大小/填充/线条/文本/图片/表格)
|
|
2
|
+
|
|
3
|
+
import { SLIDE_SIZES, TABLE_STYLES, THEME_KEYS, TRANSITIONS, THEMES, themeOf } from '../../../src/kernel/model.js';
|
|
4
|
+
import { FONT_FAMILIES, TEXT_COLORS } from './text-styles.js';
|
|
5
|
+
import { openColorPanel } from './color-panel.js';
|
|
6
|
+
import { icon } from './icons.js';
|
|
7
|
+
|
|
8
|
+
const el = (tag, cls, text) => {
|
|
9
|
+
const node = document.createElement(tag);
|
|
10
|
+
if (cls) node.className = cls;
|
|
11
|
+
if (text != null) node.textContent = text;
|
|
12
|
+
return node;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const field = (label, control) => {
|
|
16
|
+
const row = el('label', 'pp-fp-field');
|
|
17
|
+
const span = el('span', 'pp-fp-field__label', label);
|
|
18
|
+
row.append(span, control);
|
|
19
|
+
return row;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const numberInput = (value, onChange, { min = -10000, max = 10000, step = 1 } = {}) => {
|
|
23
|
+
const input = el('input', 'pp-input pp-input--num');
|
|
24
|
+
input.type = 'number';
|
|
25
|
+
input.min = String(min);
|
|
26
|
+
input.max = String(max);
|
|
27
|
+
input.step = String(step);
|
|
28
|
+
input.value = String(Math.round(value * 100) / 100);
|
|
29
|
+
input.addEventListener('change', () => {
|
|
30
|
+
const v = Number(input.value);
|
|
31
|
+
if (Number.isFinite(v)) onChange(v);
|
|
32
|
+
});
|
|
33
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') input.blur(); });
|
|
34
|
+
return input;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const selectInput = (options, value, onChange) => {
|
|
38
|
+
const sel = el('select', 'pp-input');
|
|
39
|
+
for (const o of options) {
|
|
40
|
+
const opt = document.createElement('option');
|
|
41
|
+
opt.value = o.value;
|
|
42
|
+
opt.textContent = o.label;
|
|
43
|
+
sel.appendChild(opt);
|
|
44
|
+
}
|
|
45
|
+
sel.value = value ?? '';
|
|
46
|
+
sel.addEventListener('change', () => onChange(sel.value));
|
|
47
|
+
return sel;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const toggleButton = (label, on, onClick) => {
|
|
51
|
+
const b = el('button', `pp-toggle${on ? ' gbp-is-active' : ''}`, label);
|
|
52
|
+
b.type = 'button';
|
|
53
|
+
b.addEventListener('click', onClick);
|
|
54
|
+
return b;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const colorControl = (value, onPick, { allowNone = true, title = '颜色', noneLabel = '无颜色' } = {}) => {
|
|
58
|
+
const b = el('button', 'pp-colorfield');
|
|
59
|
+
b.type = 'button';
|
|
60
|
+
const dot = el('i', 'pp-colorfield__dot');
|
|
61
|
+
dot.style.background = value || 'transparent';
|
|
62
|
+
const text = el('span', '', value || '默认');
|
|
63
|
+
b.append(dot, text);
|
|
64
|
+
b.addEventListener('click', () => {
|
|
65
|
+
openColorPanel({ anchor: b, colors: TEXT_COLORS, value, title, columns: 10, allowNone, noneLabel, onPick });
|
|
66
|
+
});
|
|
67
|
+
return b;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export class FormatPane {
|
|
71
|
+
constructor(app) {
|
|
72
|
+
this.app = app;
|
|
73
|
+
this.el = el('aside', 'pp-formatpane');
|
|
74
|
+
this.el.hidden = true;
|
|
75
|
+
this.closedSections = new Set();
|
|
76
|
+
this.title = '';
|
|
77
|
+
this.body = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
open() {
|
|
81
|
+
this.app.formatPaneOpen = true;
|
|
82
|
+
this.el.hidden = false;
|
|
83
|
+
this.render();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
close() {
|
|
87
|
+
this.app.formatPaneOpen = false;
|
|
88
|
+
this.app.prefs.formatPaneOpen = false;
|
|
89
|
+
this.app.persistPrefs();
|
|
90
|
+
this.el.hidden = true;
|
|
91
|
+
this.app.updateLayout();
|
|
92
|
+
this.app.ribbon.refresh();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
toggle() {
|
|
96
|
+
if (this.app.formatPaneOpen) this.close();
|
|
97
|
+
else this.open();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
render() {
|
|
101
|
+
if (!this.app.formatPaneOpen || (this.app.view && this.app.view !== 'normal')) {
|
|
102
|
+
this.el.hidden = true;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const bodyScroll = this.body?.scrollTop || 0;
|
|
106
|
+
this.el.hidden = false;
|
|
107
|
+
this.el.replaceChildren();
|
|
108
|
+
const head = el('div', 'pp-formatpane__head');
|
|
109
|
+
const title = el('span', 'pp-formatpane__title');
|
|
110
|
+
const close = el('button', 'pp-iconbtn');
|
|
111
|
+
close.type = 'button';
|
|
112
|
+
close.innerHTML = icon('close', 16);
|
|
113
|
+
close.title = '关闭';
|
|
114
|
+
close.addEventListener('click', () => this.close());
|
|
115
|
+
head.append(title, close);
|
|
116
|
+
const body = el('div', 'pp-formatpane__body');
|
|
117
|
+
this.el.append(head, body);
|
|
118
|
+
this.body = body;
|
|
119
|
+
|
|
120
|
+
const objs = this.app.selectedObjects();
|
|
121
|
+
if (objs.length === 0) {
|
|
122
|
+
title.textContent = '设置背景格式';
|
|
123
|
+
this.renderSlide(body);
|
|
124
|
+
} else if (objs.length > 1) {
|
|
125
|
+
title.textContent = `设置 ${objs.length} 个对象`;
|
|
126
|
+
this.renderMulti(body, objs);
|
|
127
|
+
} else {
|
|
128
|
+
const o = objs[0];
|
|
129
|
+
title.textContent = o.type === 'image' ? '设置图片格式' : o.type === 'table' ? '设置表格格式' : o.type === 'line' ? '设置线条格式' : '设置形状格式';
|
|
130
|
+
this.renderObject(body, o);
|
|
131
|
+
}
|
|
132
|
+
body.scrollTop = bodyScroll;
|
|
133
|
+
this.title = title.textContent;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
section(body, key, title, content, { open = !this.closedSections.has(key) } = {}) {
|
|
137
|
+
const sec = el('section', `pp-fp-section${open ? ' gbp-is-open' : ''}`);
|
|
138
|
+
const head = el('button', 'pp-fp-section__head');
|
|
139
|
+
head.type = 'button';
|
|
140
|
+
head.innerHTML = `<span>${title}</span>${icon('chevronDown', 14)}`;
|
|
141
|
+
const box = el('div', 'pp-fp-section__body');
|
|
142
|
+
box.append(...(Array.isArray(content) ? content : [content]));
|
|
143
|
+
head.addEventListener('click', () => {
|
|
144
|
+
const isOpen = sec.classList.toggle('gbp-is-open');
|
|
145
|
+
box.hidden = !isOpen;
|
|
146
|
+
if (isOpen) this.closedSections.delete(key);
|
|
147
|
+
else this.closedSections.add(key);
|
|
148
|
+
});
|
|
149
|
+
box.hidden = !open;
|
|
150
|
+
sec.append(head, box);
|
|
151
|
+
body.appendChild(sec);
|
|
152
|
+
return sec;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* ===================== 幻灯片 ===================== */
|
|
156
|
+
|
|
157
|
+
renderSlide(body) {
|
|
158
|
+
const app = this.app;
|
|
159
|
+
const slide = app.currentSlide();
|
|
160
|
+
const bg = slide.bg || '';
|
|
161
|
+
const theme = themeOf(app.snapshot.theme);
|
|
162
|
+
|
|
163
|
+
this.section(body, 'slide', '幻灯片', [
|
|
164
|
+
field('背景色', colorControl(bg || theme.bg, (c) => app.setSlideBg(c), { title: '页面背景色', noneLabel: '跟随主题' })),
|
|
165
|
+
field('画幅', selectInput(
|
|
166
|
+
[...SLIDE_SIZES.map((s) => ({ value: s.key, label: s.label })), { value: 'custom', label: `自定义 ${app.size.w}×${app.size.h}` }],
|
|
167
|
+
SLIDE_SIZES.find((s) => s.w === app.size.w && s.h === app.size.h)?.key || 'custom',
|
|
168
|
+
(v) => { if (v !== 'custom') app.setSlideSize(v); },
|
|
169
|
+
)),
|
|
170
|
+
field('主题', selectInput(THEME_KEYS.map((k) => ({ value: k, label: THEMES[k].label })), app.snapshot.theme, (v) => app.setTheme(v))),
|
|
171
|
+
]);
|
|
172
|
+
|
|
173
|
+
this.section(body, 'transition', '切换', [
|
|
174
|
+
field('效果', selectInput(TRANSITIONS.map((t) => ({ value: t.key, label: t.label })), slide.transition?.type || 'none', (v) => app.setTransition({ type: v }))),
|
|
175
|
+
field('速度', selectInput([
|
|
176
|
+
{ value: 'fast', label: '0.5 秒' }, { value: 'med', label: '1 秒' }, { value: 'slow', label: '2 秒' },
|
|
177
|
+
], slide.transition?.speed || 'med', (v) => app.setTransition({ speed: v }))),
|
|
178
|
+
field('状态', (() => {
|
|
179
|
+
const row = el('div', 'pp-inline');
|
|
180
|
+
row.append(toggleButton(slide.hidden ? '已隐藏' : '显示', !slide.hidden, () => app.toggleSlideHidden()));
|
|
181
|
+
row.append(el('span', 'pp-fp-hint', `第 ${app.index + 1} / ${app.snapshot.slides.length} 页`));
|
|
182
|
+
return row;
|
|
183
|
+
})()),
|
|
184
|
+
]);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* ===================== 多选 ===================== */
|
|
188
|
+
|
|
189
|
+
renderMulti(body, objs) {
|
|
190
|
+
const app = this.app;
|
|
191
|
+
const align = el('div', 'pp-grid-buttons');
|
|
192
|
+
for (const [key, label] of [['left', '左对齐'], ['centerH', '水平居中'], ['right', '右对齐'], ['top', '顶端'], ['middle', '垂直居中'], ['bottom', '底端']]) {
|
|
193
|
+
const b = el('button', 'pp-chip', label);
|
|
194
|
+
b.type = 'button';
|
|
195
|
+
b.addEventListener('click', () => app.alignToSlide(key));
|
|
196
|
+
align.appendChild(b);
|
|
197
|
+
}
|
|
198
|
+
const dist = el('div', 'pp-grid-buttons');
|
|
199
|
+
for (const [key, label] of [['h', '横向分布'], ['v', '纵向分布']]) {
|
|
200
|
+
const b = el('button', 'pp-chip', label);
|
|
201
|
+
b.type = 'button';
|
|
202
|
+
b.disabled = objs.length < 3;
|
|
203
|
+
b.addEventListener('click', () => app.distribute(key));
|
|
204
|
+
dist.appendChild(b);
|
|
205
|
+
}
|
|
206
|
+
const order = el('div', 'pp-grid-buttons');
|
|
207
|
+
for (const [key, label] of [['front', '置于顶层'], ['forward', '上移一层'], ['backward', '下移一层'], ['back', '置于底层']]) {
|
|
208
|
+
const b = el('button', 'pp-chip', label);
|
|
209
|
+
b.type = 'button';
|
|
210
|
+
b.addEventListener('click', () => app.arrange(key));
|
|
211
|
+
order.appendChild(b);
|
|
212
|
+
}
|
|
213
|
+
this.section(body, 'align', '对齐', align);
|
|
214
|
+
this.section(body, 'dist', '分布', dist);
|
|
215
|
+
this.section(body, 'order', '排列', order);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* ===================== 对象 ===================== */
|
|
219
|
+
|
|
220
|
+
renderObject(body, o) {
|
|
221
|
+
const app = this.app;
|
|
222
|
+
const p = o.props;
|
|
223
|
+
|
|
224
|
+
/* 大小与位置 */
|
|
225
|
+
const sizeBox = [
|
|
226
|
+
field('宽度', numberInput(Math.abs(o.w), (v) => app.updateObject(o.id, { w: o.w < 0 ? -Math.abs(v) : Math.abs(v) }), { min: 1 })),
|
|
227
|
+
field('高度', numberInput(Math.abs(o.h), (v) => app.updateObject(o.id, { h: o.h < 0 ? -Math.abs(v) : Math.abs(v) }), { min: 1 })),
|
|
228
|
+
field('X 位置', numberInput(o.x, (v) => app.updateObject(o.id, { x: v }))),
|
|
229
|
+
field('Y 位置', numberInput(o.y, (v) => app.updateObject(o.id, { y: v }))),
|
|
230
|
+
field('旋转', numberInput(o.rot || 0, (v) => app.updateObject(o.id, { rot: v }), { min: -360, max: 360 })),
|
|
231
|
+
];
|
|
232
|
+
this.section(body, 'size', '大小与位置', sizeBox);
|
|
233
|
+
|
|
234
|
+
if (o.type === 'text') {
|
|
235
|
+
this.section(body, 'text', '文本选项', this.textControls(o, true));
|
|
236
|
+
this.section(body, 'fill', '填充与线条', this.fillControls(o, { text: true }));
|
|
237
|
+
} else if (o.type === 'shape') {
|
|
238
|
+
this.section(body, 'fill', '填充与线条', this.fillControls(o));
|
|
239
|
+
this.section(body, 'text', '文本选项', this.textControls(o, true));
|
|
240
|
+
} else if (o.type === 'line') {
|
|
241
|
+
this.section(body, 'line', '线条', this.lineControls(o));
|
|
242
|
+
} else if (o.type === 'image') {
|
|
243
|
+
this.section(body, 'image', '图片', this.imageControls(o));
|
|
244
|
+
this.section(body, 'alt', '替代文字', [
|
|
245
|
+
field('说明', (() => {
|
|
246
|
+
const input = el('input', 'pp-input');
|
|
247
|
+
input.type = 'text';
|
|
248
|
+
input.value = p.alt || '';
|
|
249
|
+
input.placeholder = '描述图片内容';
|
|
250
|
+
input.addEventListener('change', () => app.updateProps(o.id, { alt: input.value }));
|
|
251
|
+
return input;
|
|
252
|
+
})()),
|
|
253
|
+
]);
|
|
254
|
+
} else if (o.type === 'table') {
|
|
255
|
+
this.section(body, 'table', '表格', this.tableControls(o));
|
|
256
|
+
this.section(body, 'text', '文字', this.tableTextControls(o));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
textControls(o, includeAnchor) {
|
|
261
|
+
const app = this.app;
|
|
262
|
+
const p = o.props;
|
|
263
|
+
const font = selectInput(
|
|
264
|
+
[{ value: '', label: '默认' }, ...FONT_FAMILIES.map((f) => ({ value: f.value, label: f.label }))],
|
|
265
|
+
p.font || '',
|
|
266
|
+
(v) => app.updateProps(o.id, { font: v }),
|
|
267
|
+
);
|
|
268
|
+
const size = numberInput(p.fontSize || 24, (v) => app.setFontSize(v), { min: 6, max: 200 });
|
|
269
|
+
const styleRow = el('div', 'pp-inline');
|
|
270
|
+
for (const [key, label, iconName] of [['bold', '粗体', 'bold'], ['italic', '斜体', 'italic'], ['underline', '下划线', 'underline'], ['strike', '删除线', 'strike']]) {
|
|
271
|
+
const b = el('button', `pp-toggle${p[key] ? ' gbp-is-active' : ''}`);
|
|
272
|
+
b.type = 'button';
|
|
273
|
+
b.title = label;
|
|
274
|
+
b.innerHTML = icon(iconName, 15);
|
|
275
|
+
b.addEventListener('click', () => app.updateProps(o.id, { [key]: !p[key] }));
|
|
276
|
+
styleRow.appendChild(b);
|
|
277
|
+
}
|
|
278
|
+
const alignRow = el('div', 'pp-segmented');
|
|
279
|
+
for (const [key, name] of [['left', 'alignLeft'], ['center', 'alignCenter'], ['right', 'alignRight'], ['justify', 'alignJustify']]) {
|
|
280
|
+
const b = el('button', `pp-segmented__btn${p.align === key ? ' gbp-is-active' : ''}`);
|
|
281
|
+
b.type = 'button';
|
|
282
|
+
b.title = key;
|
|
283
|
+
b.innerHTML = icon(name, 15);
|
|
284
|
+
b.addEventListener('click', () => app.updateProps(o.id, { align: key }));
|
|
285
|
+
alignRow.appendChild(b);
|
|
286
|
+
}
|
|
287
|
+
const color = colorControl(
|
|
288
|
+
o.type === 'shape' ? (p.textColor || '') : (p.color || ''),
|
|
289
|
+
(c) => app.updateProps(o.id, o.type === 'shape' ? { textColor: c || '#ffffff' } : { color: c }),
|
|
290
|
+
{ title: '字体颜色' },
|
|
291
|
+
);
|
|
292
|
+
const controls = [
|
|
293
|
+
field('字体', font),
|
|
294
|
+
field('字号', size),
|
|
295
|
+
field('样式', styleRow),
|
|
296
|
+
field('对齐', alignRow),
|
|
297
|
+
field('颜色', color),
|
|
298
|
+
field('行距', numberInput(p.lineSpacing || 1, (v) => app.updateProps(o.id, { lineSpacing: v }), { min: 0.6, max: 4, step: 0.05 })),
|
|
299
|
+
];
|
|
300
|
+
if (includeAnchor) {
|
|
301
|
+
const anchorRow = el('div', 'pp-segmented');
|
|
302
|
+
for (const [key, label] of [['top', '顶端'], ['middle', '中部'], ['bottom', '底端']]) {
|
|
303
|
+
const b = el('button', `pp-segmented__btn${(p.anchor || 'top') === key ? ' gbp-is-active' : ''}`, label);
|
|
304
|
+
b.type = 'button';
|
|
305
|
+
b.addEventListener('click', () => app.updateProps(o.id, { anchor: key }));
|
|
306
|
+
anchorRow.appendChild(b);
|
|
307
|
+
}
|
|
308
|
+
controls.push(field('垂直对齐', anchorRow));
|
|
309
|
+
}
|
|
310
|
+
return controls;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
fillControls(o, { text = false } = {}) {
|
|
314
|
+
const app = this.app;
|
|
315
|
+
const p = o.props;
|
|
316
|
+
const fillMode = el('div', 'pp-segmented');
|
|
317
|
+
for (const [key, label] of [['solid', '纯色'], ['none', '无填充']]) {
|
|
318
|
+
const b = el('button', `pp-segmented__btn${(p.fill ? 'solid' : 'none') === key ? ' gbp-is-active' : ''}`, label);
|
|
319
|
+
b.type = 'button';
|
|
320
|
+
b.addEventListener('click', () => app.updateProps(o.id, { fill: key === 'none' ? '' : (p.fill || themeOf(app.snapshot.theme).accent) }));
|
|
321
|
+
fillMode.appendChild(b);
|
|
322
|
+
}
|
|
323
|
+
const fillColor = colorControl(p.fill || '', (c) => app.updateProps(o.id, { fill: c }), { title: '填充颜色' });
|
|
324
|
+
const lineMode = el('div', 'pp-segmented');
|
|
325
|
+
for (const [key, label] of [['solid', '实线'], ['none', '无线条']]) {
|
|
326
|
+
const b = el('button', `pp-segmented__btn${(p.stroke && p.strokeW > 0 ? 'solid' : 'none') === key ? ' gbp-is-active' : ''}`, label);
|
|
327
|
+
b.type = 'button';
|
|
328
|
+
b.addEventListener('click', () => app.updateProps(o.id, {
|
|
329
|
+
stroke: key === 'none' ? '' : (p.stroke || themeOf(app.snapshot.theme).text),
|
|
330
|
+
strokeW: key === 'none' ? 0 : Math.max(1, p.strokeW || 1),
|
|
331
|
+
}));
|
|
332
|
+
lineMode.appendChild(b);
|
|
333
|
+
}
|
|
334
|
+
const lineColor = colorControl(p.stroke || '', (c) => app.updateProps(o.id, {
|
|
335
|
+
stroke: c,
|
|
336
|
+
strokeW: c ? Math.max(1, p.strokeW || 1) : 0,
|
|
337
|
+
}), { title: '线条颜色' });
|
|
338
|
+
const width = numberInput(p.strokeW || 0, (v) => app.updateProps(o.id, { strokeW: v, stroke: p.stroke || themeOf(app.snapshot.theme).text }), { min: 0, max: 40, step: 1 });
|
|
339
|
+
const dash = selectInput([
|
|
340
|
+
{ value: 'solid', label: '实线' }, { value: 'dash', label: '虚线' }, { value: 'dot', label: '点线' },
|
|
341
|
+
{ value: 'lgDash', label: '长虚线' }, { value: 'dashDot', label: '点划线' },
|
|
342
|
+
], p.dash || 'solid', (v) => app.updateProps(o.id, { dash: v }));
|
|
343
|
+
return [
|
|
344
|
+
field('填充', fillMode),
|
|
345
|
+
field('填充色', fillColor),
|
|
346
|
+
field('线条', lineMode),
|
|
347
|
+
field('线条色', lineColor),
|
|
348
|
+
field('线宽', width),
|
|
349
|
+
field('线型', dash),
|
|
350
|
+
field('阴影', toggleButton(p.shadow ? '已开启' : '关闭', !!p.shadow, () => app.updateProps(o.id, { shadow: !p.shadow }))),
|
|
351
|
+
];
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
lineControls(o) {
|
|
355
|
+
const app = this.app;
|
|
356
|
+
const p = o.props;
|
|
357
|
+
return [
|
|
358
|
+
field('颜色', colorControl(p.stroke || '', (c) => app.updateProps(o.id, { stroke: c }), { title: '线条颜色' })),
|
|
359
|
+
field('线宽', numberInput(p.strokeW || 2, (v) => app.updateProps(o.id, { strokeW: v }), { min: 1, max: 40 })),
|
|
360
|
+
field('线型', selectInput([
|
|
361
|
+
{ value: 'solid', label: '实线' }, { value: 'dash', label: '虚线' }, { value: 'dot', label: '点线' },
|
|
362
|
+
{ value: 'lgDash', label: '长虚线' }, { value: 'dashDot', label: '点划线' },
|
|
363
|
+
], p.dash || 'solid', (v) => app.updateProps(o.id, { dash: v }))),
|
|
364
|
+
field('箭头', (() => {
|
|
365
|
+
const row = el('div', 'pp-inline');
|
|
366
|
+
row.append(
|
|
367
|
+
toggleButton('起点', !!p.arrowStart, () => app.updateProps(o.id, { arrowStart: !p.arrowStart })),
|
|
368
|
+
toggleButton('终点', !!p.arrowEnd, () => app.updateProps(o.id, { arrowEnd: !p.arrowEnd })),
|
|
369
|
+
);
|
|
370
|
+
return row;
|
|
371
|
+
})()),
|
|
372
|
+
];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
imageControls(o) {
|
|
376
|
+
const app = this.app;
|
|
377
|
+
const p = o.props;
|
|
378
|
+
const crop = p.crop || { l: 0, t: 0, r: 0, b: 0 };
|
|
379
|
+
const setCrop = (key, v) => app.updateProps(o.id, { crop: { ...crop, [key]: Math.max(0, Math.min(49, v)) } });
|
|
380
|
+
const cropBox = [
|
|
381
|
+
field('左', numberInput(crop.l || 0, (v) => setCrop('l', v), { min: 0, max: 49 })),
|
|
382
|
+
field('上', numberInput(crop.t || 0, (v) => setCrop('t', v), { min: 0, max: 49 })),
|
|
383
|
+
field('右', numberInput(crop.r || 0, (v) => setCrop('r', v), { min: 0, max: 49 })),
|
|
384
|
+
field('下', numberInput(crop.b || 0, (v) => setCrop('b', v), { min: 0, max: 49 })),
|
|
385
|
+
field('', (() => {
|
|
386
|
+
const row = el('div', 'pp-inline');
|
|
387
|
+
const reset = el('button', 'pp-chip', '重置裁剪');
|
|
388
|
+
reset.type = 'button';
|
|
389
|
+
reset.addEventListener('click', () => app.updateProps(o.id, { crop: { l: 0, t: 0, r: 0, b: 0 } }));
|
|
390
|
+
row.appendChild(reset);
|
|
391
|
+
return row;
|
|
392
|
+
})()),
|
|
393
|
+
];
|
|
394
|
+
return [
|
|
395
|
+
field('替换', (() => {
|
|
396
|
+
const b = el('button', 'pp-chip', '选择新图片…');
|
|
397
|
+
b.type = 'button';
|
|
398
|
+
b.addEventListener('click', () => app.replaceSelectedImage());
|
|
399
|
+
return b;
|
|
400
|
+
})()),
|
|
401
|
+
...cropBox,
|
|
402
|
+
field('阴影', toggleButton(p.shadow ? '已开启' : '关闭', !!p.shadow, () => app.updateProps(o.id, { shadow: !p.shadow }))),
|
|
403
|
+
];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
tableControls(o) {
|
|
407
|
+
const app = this.app;
|
|
408
|
+
const p = o.props;
|
|
409
|
+
return [
|
|
410
|
+
field('样式', selectInput(TABLE_STYLES.map((s) => ({ value: s.key, label: s.label })), p.tableStyle || 'plain', (v) => app.setTableStyle(v))),
|
|
411
|
+
field('标题行', toggleButton(p.headerRow ? '已开启' : '关闭', !!p.headerRow, () => app.toggleHeaderRow())),
|
|
412
|
+
field('镶边行', toggleButton(p.bandedRows ? '已开启' : '关闭', !!p.bandedRows, () => app.toggleBandedRows())),
|
|
413
|
+
field('行数', numberInput(p.rows.length, (v) => app.resizeTable(o.id, Math.round(v), p.rows[0].length), { min: 1, max: 50 })),
|
|
414
|
+
field('列数', numberInput(p.rows[0].length, (v) => app.resizeTable(o.id, p.rows.length, Math.round(v)), { min: 1, max: 30 })),
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
tableTextControls(o) {
|
|
419
|
+
const app = this.app;
|
|
420
|
+
const p = o.props;
|
|
421
|
+
return [
|
|
422
|
+
field('字体', selectInput([{ value: '', label: '默认' }, ...FONT_FAMILIES.map((f) => ({ value: f.value, label: f.label }))], p.font || '', (v) => app.updateProps(o.id, { font: v }))),
|
|
423
|
+
field('字号', numberInput(p.fontSize || 16, (v) => app.updateProps(o.id, { fontSize: v }), { min: 6, max: 100 })),
|
|
424
|
+
field('颜色', colorControl(p.color || '', (c) => app.updateProps(o.id, { color: c }), { title: '表格文字颜色' })),
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
}
|