gbpptx 0.2.0 → 0.3.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.
Files changed (46) hide show
  1. package/README.md +220 -214
  2. package/package.json +4 -3
  3. package/src/kernel/model.js +1 -2
  4. package/src/kernel/parts.js +11 -15
  5. package/src/kernel/print.js +14 -16
  6. package/web/app/main.js +8 -8
  7. package/web/app/slides/arrange.js +101 -0
  8. package/web/app/slides/clipboard.js +93 -0
  9. package/web/app/slides/file.js +243 -0
  10. package/web/app/slides/find.js +199 -0
  11. package/web/app/slides/history.js +100 -0
  12. package/web/app/slides/keys.js +174 -0
  13. package/web/app/slides/menus.js +105 -0
  14. package/web/app/slides/objects.js +254 -0
  15. package/web/app/slides/render.js +183 -0
  16. package/web/app/slides/shared.js +85 -0
  17. package/web/app/slides/slides.js +103 -0
  18. package/web/app/slides/table.js +102 -0
  19. package/web/app/slides/text.js +418 -0
  20. package/web/app/slides/view.js +130 -0
  21. package/web/app/slides-app.js +285 -2446
  22. package/web/app/ui/backstage.js +255 -255
  23. package/web/app/ui/canvas.js +762 -755
  24. package/web/app/ui/color-panel.js +58 -76
  25. package/web/app/ui/dialogs.js +120 -159
  26. package/web/app/ui/file-io.js +116 -132
  27. package/web/app/ui/format-pane.js +427 -427
  28. package/web/app/ui/icons.js +129 -129
  29. package/web/app/ui/menu.js +75 -89
  30. package/web/app/ui/notify.js +45 -45
  31. package/web/app/ui/page-view.js +221 -221
  32. package/web/app/ui/popup.js +80 -80
  33. package/web/app/ui/present.js +292 -292
  34. package/web/app/ui/ribbon.js +878 -878
  35. package/web/app/ui/slide-pane.js +189 -189
  36. package/web/app/ui/statusbar.js +93 -93
  37. package/web/app/ui/text-styles.js +84 -84
  38. package/web/app/ui/titlebar.js +173 -66
  39. package/web/app/ui/transition.js +30 -30
  40. package/web/index.html +23 -22
  41. package/web/serve.mjs +20 -67
  42. package/web/styles/office.css +642 -644
  43. package/web/styles/slides.css +210 -219
  44. package/web/styles/tokens.css +154 -155
  45. package/src/kernel/util/escape.js +0 -21
  46. package/src/kernel/util/id.js +0 -13
@@ -1,76 +1,58 @@
1
- // [文件] gbpptx·色板 —— 预设色格 + 系统色轮 + Hex + 无颜色/清除
2
- import { openPopup } from './popup.js';
3
-
4
- /**
5
- * 打开色板;onPick(color) 回调(清除传空串)
6
- * @param {object} o {anchor, colors, value, title, columns, allowNone, noneLabel, onPick}
7
- */
8
- export function openColorPanel({
9
- anchor, colors, value, title = '颜色', columns = 10, allowNone = true, noneLabel = '无颜色', onPick,
10
- }) {
11
- const box = document.createElement('div');
12
- box.className = 'gb-color';
13
- if (title) {
14
- const head = document.createElement('div');
15
- head.className = 'gb-color__title';
16
- head.textContent = title;
17
- box.appendChild(head);
18
- }
19
- const grid = document.createElement('div');
20
- grid.className = 'gb-color__grid';
21
- grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
22
- for (const color of colors) {
23
- const sw = document.createElement('button');
24
- sw.type = 'button';
25
- sw.className = 'gb-color__swatch';
26
- sw.style.background = color;
27
- if (value && String(value).toLowerCase() === color.toLowerCase()) sw.classList.add('is-active');
28
- sw.title = color;
29
- // 不抢走正文 contenteditable 的焦点,否则选色会中断就地编辑
30
- sw.addEventListener('mousedown', (e) => e.preventDefault());
31
- sw.addEventListener('click', () => { handle.close(); onPick(color); });
32
- grid.appendChild(sw);
33
- }
34
- box.appendChild(grid);
35
-
36
- const custom = document.createElement('div');
37
- custom.className = 'gb-color__custom';
38
- const wheel = document.createElement('input');
39
- wheel.type = 'color';
40
- wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
41
- const hex = document.createElement('input');
42
- hex.type = 'text';
43
- hex.className = 'gb-input';
44
- hex.value = value || '';
45
- hex.placeholder = '#rrggbb';
46
- wheel.addEventListener('input', () => { hex.value = wheel.value; });
47
- custom.append(wheel, hex);
48
- box.appendChild(custom);
49
-
50
- const actions = document.createElement('div');
51
- actions.className = 'gb-color__actions';
52
- const apply = document.createElement('button');
53
- apply.type = 'button';
54
- apply.className = 'gb-btn gb-btn--primary';
55
- apply.textContent = '应用';
56
- apply.addEventListener('mousedown', (e) => e.preventDefault());
57
- apply.addEventListener('click', () => {
58
- const v = String(hex.value || '').trim();
59
- handle.close();
60
- onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
61
- });
62
- actions.appendChild(apply);
63
- if (allowNone) {
64
- const clear = document.createElement('button');
65
- clear.type = 'button';
66
- clear.className = 'gb-btn';
67
- clear.textContent = noneLabel;
68
- clear.addEventListener('mousedown', (e) => e.preventDefault());
69
- clear.addEventListener('click', () => { handle.close(); onPick(''); });
70
- actions.appendChild(clear);
71
- }
72
- box.appendChild(actions);
73
-
74
- const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gb-popup--color' });
75
- return handle;
76
- }
1
+ // [文件] gbpptx·色板 —— 预设色格 + 系统色轮 + Hex + 清除
2
+ import { openPopup } from './popup.js';
3
+
4
+ /** 打开色板;onPick(color) 回调(清除传空串) */
5
+ export function openColorPanel({ anchor, colors, value, title = '颜色', columns = 10, onPick }) {
6
+ const box = document.createElement('div');
7
+ box.className = 'gbp-color';
8
+ const grid = document.createElement('div');
9
+ grid.className = 'gbp-color__grid';
10
+ grid.style.gridTemplateColumns = `repeat(${columns}, 18px)`;
11
+ for (const color of colors) {
12
+ const sw = document.createElement('button');
13
+ sw.type = 'button';
14
+ sw.className = 'gbp-color__swatch';
15
+ sw.style.background = color;
16
+ if (value && String(value).toLowerCase() === color.toLowerCase()) sw.classList.add('gbp-is-active');
17
+ sw.title = color;
18
+ sw.addEventListener('click', () => { handle.close(); onPick(color); });
19
+ grid.appendChild(sw);
20
+ }
21
+ box.appendChild(grid);
22
+
23
+ const custom = document.createElement('div');
24
+ custom.className = 'gbp-color__custom';
25
+ const wheel = document.createElement('input');
26
+ wheel.type = 'color';
27
+ wheel.value = /^#[0-9a-f]{6}$/i.test(value || '') ? value : '#000000';
28
+ const hex = document.createElement('input');
29
+ hex.type = 'text';
30
+ hex.className = 'gbp-input';
31
+ hex.value = value || '';
32
+ hex.placeholder = '#rrggbb';
33
+ wheel.addEventListener('input', () => { hex.value = wheel.value; });
34
+ custom.append(wheel, hex);
35
+ box.appendChild(custom);
36
+
37
+ const actions = document.createElement('div');
38
+ actions.className = 'gbp-color__actions';
39
+ const apply = document.createElement('button');
40
+ apply.type = 'button';
41
+ apply.className = 'gbp-btn gbp-btn--primary';
42
+ apply.textContent = '应用';
43
+ const clear = document.createElement('button');
44
+ clear.type = 'button';
45
+ clear.className = 'gbp-btn';
46
+ clear.textContent = '清除';
47
+ apply.addEventListener('click', () => {
48
+ const v = String(hex.value || '').trim();
49
+ handle.close();
50
+ onPick(/^#?[0-9a-f]{6}$/i.test(v) ? (v.startsWith('#') ? v : `#${v}`) : '');
51
+ });
52
+ clear.addEventListener('click', () => { handle.close(); onPick(''); });
53
+ actions.append(apply, clear);
54
+ box.appendChild(actions);
55
+
56
+ const handle = openPopup({ anchor, content: box, placement: 'bottom-start', className: 'gbp-popup--color' });
57
+ return handle;
58
+ }
@@ -1,159 +1,120 @@
1
- // [文件] gbpptx·对话框 —— 通用模态 + 单字段输入(供背景色/尺寸/页主题等表单复用)
2
-
3
- /** 通用模态:build(bodyEl, close) 填充内容;onConfirm() 返回 false 可阻止关闭;onClose 在任意方式关闭后调用 */
4
- export function openModal({ title, build, onConfirm, onClose, confirmText = '确定', width = 420, danger = false }) {
5
- const overlay = document.createElement('div');
6
- overlay.className = 'gb-modal-overlay';
7
- const box = document.createElement('div');
8
- box.className = 'gb-modal';
9
- box.style.width = `${width}px`;
10
- box.innerHTML = `
11
- <div class="gb-modal__head"><span class="gb-modal__title"></span><button type="button" class="gb-modal__close">✕</button></div>
12
- <div class="gb-modal__body"></div>
13
- <div class="gb-modal__foot">
14
- <button type="button" class="gb-btn" data-act="cancel">取消</button>
15
- <button type="button" class="gb-btn gb-btn--primary" data-act="ok"></button>
16
- </div>`;
17
- box.querySelector('.gb-modal__title').textContent = title;
18
- const okBtn = box.querySelector('[data-act="ok"]');
19
- okBtn.textContent = confirmText;
20
- if (danger) okBtn.classList.add('gb-btn--danger');
21
- const bodyEl = box.querySelector('.gb-modal__body');
22
-
23
- let closed = false;
24
- const close = () => {
25
- if (closed) return;
26
- closed = true;
27
- document.removeEventListener('keydown', onKey, true);
28
- overlay.remove();
29
- onClose?.();
30
- };
31
- const onKey = (e) => {
32
- if (e.key === 'Escape') {
33
- e.stopPropagation();
34
- close();
35
- }
36
- };
37
- const confirm = () => {
38
- if (onConfirm && onConfirm() === false) return;
39
- close();
40
- };
41
-
42
- box.querySelector('[data-act="cancel"]').addEventListener('click', close);
43
- box.querySelector('.gb-modal__close').addEventListener('click', close);
44
- okBtn.addEventListener('click', confirm);
45
- overlay.addEventListener('mousedown', (e) => { if (e.target === overlay) close(); });
46
- document.addEventListener('keydown', onKey, true);
47
- build?.(bodyEl, close);
48
- overlay.appendChild(box);
49
- document.body.appendChild(overlay);
50
- return { close };
51
- }
52
-
53
- export function field(labelText, control) {
54
- const row = document.createElement('label');
55
- row.className = 'gb-field';
56
- const span = document.createElement('span');
57
- span.className = 'gb-field__label';
58
- span.textContent = labelText;
59
- row.append(span, control);
60
- return row;
61
- }
62
-
63
- export function textInput(value = '', placeholder = '') {
64
- const input = document.createElement('input');
65
- input.type = 'text';
66
- input.className = 'gb-input';
67
- input.value = value;
68
- input.placeholder = placeholder;
69
- return input;
70
- }
71
-
72
- export function numberInput(value, { min, max, step = 1 } = {}) {
73
- const input = document.createElement('input');
74
- input.type = 'number';
75
- input.className = 'gb-input';
76
- if (min !== undefined) input.min = min;
77
- if (max !== undefined) input.max = max;
78
- input.step = step;
79
- input.value = value;
80
- return input;
81
- }
82
-
83
- export function selectInput(options, value) {
84
- const sel = document.createElement('select');
85
- sel.className = 'gb-input';
86
- for (const o of options) {
87
- const opt = document.createElement('option');
88
- opt.value = o.value;
89
- opt.textContent = o.label;
90
- sel.appendChild(opt);
91
- }
92
- sel.value = value ?? '';
93
- return sel;
94
- }
95
-
96
- /** 复选框行 */
97
- export function checkInput(labelText, checked = false) {
98
- const row = document.createElement('label');
99
- row.className = 'gb-check';
100
- const input = document.createElement('input');
101
- input.type = 'checkbox';
102
- input.checked = !!checked;
103
- const span = document.createElement('span');
104
- span.textContent = labelText;
105
- row.append(input, span);
106
- row.input = input;
107
- return row;
108
- }
109
-
110
- /** 确认框(返回 Promise<boolean>) */
111
- export function confirmDialog({ title = '确认', message = '', confirmText = '确定', danger = false } = {}) {
112
- return new Promise((resolve) => {
113
- let value = false;
114
- openModal({
115
- title,
116
- width: 420,
117
- onClose: () => resolve(value),
118
- build: (body) => {
119
- const p = document.createElement('p');
120
- p.className = 'gb-modal__message';
121
- p.textContent = message;
122
- body.appendChild(p);
123
- },
124
- onConfirm: () => {
125
- value = true;
126
- },
127
- confirmText,
128
- danger,
129
- });
130
- });
131
- }
132
-
133
- /** 询问一个文本值(确认返回字符串,取消返回 null) */
134
- export function promptText({ title, label, value = '', placeholder = '' }) {
135
- return new Promise((resolve) => {
136
- let input = null;
137
- let done = false;
138
- openModal({
139
- title: title || label || '输入',
140
- width: 360,
141
- onClose: () => { if (!done) resolve(null); },
142
- build: (body) => {
143
- input = textInput(value, placeholder);
144
- body.appendChild(field(label || '', input));
145
- requestAnimationFrame(() => { input.focus(); input.select(); });
146
- input.addEventListener('keydown', (e) => {
147
- if (e.key === 'Enter') {
148
- e.preventDefault();
149
- body.closest('.gb-modal').querySelector('[data-act="ok"]').click();
150
- }
151
- });
152
- },
153
- onConfirm: () => {
154
- done = true;
155
- resolve(input ? input.value : '');
156
- },
157
- });
158
- });
159
- }
1
+ // [文件] gbpptx·对话框 —— 通用模态 + 单字段输入(供背景色/尺寸/页主题等表单复用)
2
+
3
+ /** 通用模态:build(bodyEl, close) 填充内容;onConfirm() 返回 false 可阻止关闭;onClose 在任意方式关闭后调用 */
4
+ export function openModal({ title, build, onConfirm, onClose, confirmText = '确定', width = 420 }) {
5
+ const overlay = document.createElement('div');
6
+ overlay.className = 'gbp-modal-overlay';
7
+ const box = document.createElement('div');
8
+ box.className = 'gbp-modal';
9
+ box.style.width = `${width}px`;
10
+ box.innerHTML = `
11
+ <div class="gbp-modal__head"><span class="gbp-modal__title"></span><button type="button" class="gbp-modal__close">✕</button></div>
12
+ <div class="gbp-modal__body"></div>
13
+ <div class="gbp-modal__foot">
14
+ <button type="button" class="gbp-btn" data-act="cancel">取消</button>
15
+ <button type="button" class="gbp-btn gbp-btn--primary" data-act="ok"></button>
16
+ </div>`;
17
+ box.querySelector('.gbp-modal__title').textContent = title;
18
+ box.querySelector('[data-act="ok"]').textContent = confirmText;
19
+ const bodyEl = box.querySelector('.gbp-modal__body');
20
+
21
+ let closed = false;
22
+ const close = () => {
23
+ if (closed) return;
24
+ closed = true;
25
+ document.removeEventListener('keydown', onKey, true);
26
+ overlay.remove();
27
+ onClose?.();
28
+ };
29
+ const onKey = (e) => {
30
+ if (e.key === 'Escape') {
31
+ e.stopPropagation();
32
+ close();
33
+ }
34
+ };
35
+ const confirm = () => {
36
+ if (onConfirm && onConfirm() === false) return;
37
+ close();
38
+ };
39
+
40
+ box.querySelector('[data-act="cancel"]').addEventListener('click', close);
41
+ box.querySelector('.gbp-modal__close').addEventListener('click', close);
42
+ box.querySelector('[data-act="ok"]').addEventListener('click', confirm);
43
+ overlay.addEventListener('mousedown', (e) => { if (e.target === overlay) close(); });
44
+ document.addEventListener('keydown', onKey, true);
45
+ build?.(bodyEl, close);
46
+ overlay.appendChild(box);
47
+ document.body.appendChild(overlay);
48
+ return { close };
49
+ }
50
+
51
+ export function field(labelText, control) {
52
+ const row = document.createElement('label');
53
+ row.className = 'gbp-field';
54
+ const span = document.createElement('span');
55
+ span.className = 'gbp-field__label';
56
+ span.textContent = labelText;
57
+ row.append(span, control);
58
+ return row;
59
+ }
60
+
61
+ export function textInput(value = '', placeholder = '') {
62
+ const input = document.createElement('input');
63
+ input.type = 'text';
64
+ input.className = 'gbp-input';
65
+ input.value = value;
66
+ input.placeholder = placeholder;
67
+ return input;
68
+ }
69
+
70
+ export function numberInput(value, { min, max, step = 1 } = {}) {
71
+ const input = document.createElement('input');
72
+ input.type = 'number';
73
+ input.className = 'gbp-input';
74
+ if (min !== undefined) input.min = min;
75
+ if (max !== undefined) input.max = max;
76
+ input.step = step;
77
+ input.value = value;
78
+ return input;
79
+ }
80
+
81
+ export function selectInput(options, value) {
82
+ const sel = document.createElement('select');
83
+ sel.className = 'gbp-input';
84
+ for (const o of options) {
85
+ const opt = document.createElement('option');
86
+ opt.value = o.value;
87
+ opt.textContent = o.label;
88
+ sel.appendChild(opt);
89
+ }
90
+ sel.value = value ?? '';
91
+ return sel;
92
+ }
93
+
94
+ /** 询问一个文本值(确认返回字符串,取消返回 null) */
95
+ export function promptText({ title, label, value = '', placeholder = '' }) {
96
+ return new Promise((resolve) => {
97
+ let input = null;
98
+ let done = false;
99
+ openModal({
100
+ title: title || label || '输入',
101
+ width: 360,
102
+ onClose: () => { if (!done) resolve(null); },
103
+ build: (body) => {
104
+ input = textInput(value, placeholder);
105
+ body.appendChild(field(label || '', input));
106
+ requestAnimationFrame(() => { input.focus(); input.select(); });
107
+ input.addEventListener('keydown', (e) => {
108
+ if (e.key === 'Enter') {
109
+ e.preventDefault();
110
+ body.closest('.gbp-modal').querySelector('[data-act="ok"]').click();
111
+ }
112
+ });
113
+ },
114
+ onConfirm: () => {
115
+ done = true;
116
+ resolve(input ? input.value : '');
117
+ },
118
+ });
119
+ });
120
+ }