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.
Files changed (50) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +253 -253
  3. package/package.json +48 -47
  4. package/src/index.js +29 -29
  5. package/src/kernel/model.js +651 -651
  6. package/src/kernel/parts.js +173 -173
  7. package/src/kernel/pptx.js +72 -72
  8. package/src/kernel/print.js +76 -76
  9. package/src/kernel/read.js +1018 -1018
  10. package/src/kernel/roundtrip.js +174 -174
  11. package/src/kernel/text.js +278 -278
  12. package/src/kernel/write.js +385 -385
  13. package/web/app/main.js +8 -8
  14. package/web/app/slides/arrange.js +101 -101
  15. package/web/app/slides/clipboard.js +93 -93
  16. package/web/app/slides/file.js +240 -240
  17. package/web/app/slides/find.js +201 -201
  18. package/web/app/slides/history.js +100 -100
  19. package/web/app/slides/keys.js +187 -187
  20. package/web/app/slides/menus.js +105 -105
  21. package/web/app/slides/objects.js +254 -254
  22. package/web/app/slides/render.js +183 -183
  23. package/web/app/slides/shared.js +85 -85
  24. package/web/app/slides/slides.js +103 -103
  25. package/web/app/slides/table.js +102 -102
  26. package/web/app/slides/text.js +418 -418
  27. package/web/app/slides/view.js +182 -182
  28. package/web/app/slides-app.js +354 -354
  29. package/web/app/ui/canvas.js +769 -769
  30. package/web/app/ui/color-panel.js +58 -58
  31. package/web/app/ui/dialogs.js +120 -120
  32. package/web/app/ui/file-io.js +116 -116
  33. package/web/app/ui/format-pane.js +427 -427
  34. package/web/app/ui/icons.js +241 -133
  35. package/web/app/ui/menu.js +77 -75
  36. package/web/app/ui/notify.js +45 -45
  37. package/web/app/ui/page-view.js +221 -221
  38. package/web/app/ui/popup.js +80 -80
  39. package/web/app/ui/present.js +292 -292
  40. package/web/app/ui/ribbon.js +855 -855
  41. package/web/app/ui/slide-pane.js +197 -197
  42. package/web/app/ui/statusbar.js +93 -93
  43. package/web/app/ui/text-styles.js +84 -84
  44. package/web/app/ui/titlebar.js +253 -253
  45. package/web/app/ui/transition.js +30 -30
  46. package/web/index.html +30 -29
  47. package/web/serve.mjs +26 -23
  48. package/web/styles/office.css +463 -463
  49. package/web/styles/slides.css +97 -97
  50. package/web/styles/tokens.css +154 -154
package/web/app/main.js CHANGED
@@ -1,8 +1,8 @@
1
- // [文件] gbpptx·main —— 应用引导(装配 SlidesApp 到 #app)
2
- import { SlidesApp } from './slides-app.js';
3
-
4
- const app = new SlidesApp(document.getElementById('app'));
5
- app.start();
6
-
7
- // 调试入口(控制台取控制器做快速自检)
8
- window.gbpptx = app;
1
+ // [文件] gbpptx·main —— 应用引导(装配 SlidesApp 到 #app)
2
+ import { SlidesApp } from './slides-app.js';
3
+
4
+ const app = new SlidesApp(document.getElementById('app'));
5
+ app.start();
6
+
7
+ // 调试入口(控制台取控制器做快速自检)
8
+ window.gbpptx = app;
@@ -1,101 +1,101 @@
1
- // [文件] gbpptx·slides·arrange —— 排列 —— 删除/再制/微移/层级/对齐/分布
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { cloneObject, objectRect, topZ } from '../../../src/kernel/model.js';
7
- function removeSelected() {
8
- const objs = this.selectedObjects();
9
- if (!objs.length) return;
10
- this.pushHistory();
11
- const ids = new Set(objs.map((o) => o.id));
12
- this.currentSlide().objects = this.currentSlide().objects.filter((o) => !ids.has(o.id));
13
- this.selectedIds = [];
14
- this.notifyChange();
15
- }
16
-
17
- function duplicateSelected() {
18
- const objs = this.selectedObjects();
19
- if (!objs.length) return;
20
- this.pushHistory();
21
- const slide = this.currentSlide();
22
- const copies = objs.map((o, i) => {
23
- const copy = cloneObject(o);
24
- copy.x += 16;
25
- copy.y += 16;
26
- copy.z = topZ(slide.objects) + 1 + i;
27
- return copy;
28
- });
29
- slide.objects.push(...copies);
30
- this.selectedIds = copies.map((o) => o.id);
31
- this.notifyChange();
32
- }
33
-
34
- function nudge(dx, dy) {
35
- const objs = this.selectedObjects();
36
- if (!objs.length) return;
37
- this.pushHistory();
38
- for (const o of objs) {
39
- o.x += dx;
40
- o.y += dy;
41
- }
42
- this.notifyChange({ canvasOnly: true });
43
- }
44
-
45
- function arrange(key) {
46
- const slide = this.currentSlide();
47
- const sel = this.selectedObjects();
48
- if (!sel.length) return;
49
- this.pushHistory();
50
- const sorted = [...slide.objects].sort((a, b) => (a.z || 0) - (b.z || 0));
51
- for (const o of sel) {
52
- const i = sorted.indexOf(o);
53
- if (key === 'front') { sorted.splice(i, 1); sorted.push(o); }
54
- else if (key === 'back') { sorted.splice(i, 1); sorted.unshift(o); }
55
- else if (key === 'forward' && i < sorted.length - 1) { sorted.splice(i, 1); sorted.splice(i + 1, 0, o); }
56
- else if (key === 'backward' && i > 0) { sorted.splice(i, 1); sorted.splice(i - 1, 0, o); }
57
- }
58
- sorted.forEach((o, i) => { o.z = i + 1; });
59
- this.notifyChange();
60
- }
61
-
62
- function alignToSlide(key) {
63
- const sel = this.selectedObjects();
64
- if (!sel.length) return;
65
- const size = this.size;
66
- this.pushHistory();
67
- for (const o of sel) {
68
- const r = objectRect(o);
69
- if (key === 'left') o.x = 0;
70
- else if (key === 'centerH') o.x = Math.round((size.w - r.width) / 2);
71
- else if (key === 'right') o.x = size.w - r.width;
72
- else if (key === 'top') o.y = 0;
73
- else if (key === 'middle') o.y = Math.round((size.h - r.height) / 2);
74
- else if (key === 'bottom') o.y = size.h - r.height;
75
- }
76
- this.notifyChange();
77
- }
78
-
79
- function distribute(axis) {
80
- const sel = this.selectedObjects();
81
- if (sel.length < 3) return;
82
- this.pushHistory();
83
- const items = sel.map((o) => ({ o, r: objectRect(o) }));
84
- items.sort((a, b) => (axis === 'h' ? a.r.left - b.r.left : a.r.top - b.r.top));
85
- const first = items[0];
86
- const last = items[items.length - 1];
87
- if (axis === 'h') {
88
- const start = first.r.left + first.r.width / 2;
89
- const end = last.r.left + last.r.width / 2;
90
- const step = (end - start) / (items.length - 1);
91
- items.forEach((item, i) => { item.o.x = Math.round(start + step * i - item.r.width / 2); });
92
- } else {
93
- const start = first.r.top + first.r.height / 2;
94
- const end = last.r.top + last.r.height / 2;
95
- const step = (end - start) / (items.length - 1);
96
- items.forEach((item, i) => { item.o.y = Math.round(start + step * i - item.r.height / 2); });
97
- }
98
- this.notifyChange();
99
- }
100
-
101
- export const arrangeMethods = { removeSelected, duplicateSelected, nudge, arrange, alignToSlide, distribute };
1
+ // [文件] gbpptx·slides·arrange —— 排列 —— 删除/再制/微移/层级/对齐/分布
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { cloneObject, objectRect, topZ } from '../../../src/kernel/model.js';
7
+ function removeSelected() {
8
+ const objs = this.selectedObjects();
9
+ if (!objs.length) return;
10
+ this.pushHistory();
11
+ const ids = new Set(objs.map((o) => o.id));
12
+ this.currentSlide().objects = this.currentSlide().objects.filter((o) => !ids.has(o.id));
13
+ this.selectedIds = [];
14
+ this.notifyChange();
15
+ }
16
+
17
+ function duplicateSelected() {
18
+ const objs = this.selectedObjects();
19
+ if (!objs.length) return;
20
+ this.pushHistory();
21
+ const slide = this.currentSlide();
22
+ const copies = objs.map((o, i) => {
23
+ const copy = cloneObject(o);
24
+ copy.x += 16;
25
+ copy.y += 16;
26
+ copy.z = topZ(slide.objects) + 1 + i;
27
+ return copy;
28
+ });
29
+ slide.objects.push(...copies);
30
+ this.selectedIds = copies.map((o) => o.id);
31
+ this.notifyChange();
32
+ }
33
+
34
+ function nudge(dx, dy) {
35
+ const objs = this.selectedObjects();
36
+ if (!objs.length) return;
37
+ this.pushHistory();
38
+ for (const o of objs) {
39
+ o.x += dx;
40
+ o.y += dy;
41
+ }
42
+ this.notifyChange({ canvasOnly: true });
43
+ }
44
+
45
+ function arrange(key) {
46
+ const slide = this.currentSlide();
47
+ const sel = this.selectedObjects();
48
+ if (!sel.length) return;
49
+ this.pushHistory();
50
+ const sorted = [...slide.objects].sort((a, b) => (a.z || 0) - (b.z || 0));
51
+ for (const o of sel) {
52
+ const i = sorted.indexOf(o);
53
+ if (key === 'front') { sorted.splice(i, 1); sorted.push(o); }
54
+ else if (key === 'back') { sorted.splice(i, 1); sorted.unshift(o); }
55
+ else if (key === 'forward' && i < sorted.length - 1) { sorted.splice(i, 1); sorted.splice(i + 1, 0, o); }
56
+ else if (key === 'backward' && i > 0) { sorted.splice(i, 1); sorted.splice(i - 1, 0, o); }
57
+ }
58
+ sorted.forEach((o, i) => { o.z = i + 1; });
59
+ this.notifyChange();
60
+ }
61
+
62
+ function alignToSlide(key) {
63
+ const sel = this.selectedObjects();
64
+ if (!sel.length) return;
65
+ const size = this.size;
66
+ this.pushHistory();
67
+ for (const o of sel) {
68
+ const r = objectRect(o);
69
+ if (key === 'left') o.x = 0;
70
+ else if (key === 'centerH') o.x = Math.round((size.w - r.width) / 2);
71
+ else if (key === 'right') o.x = size.w - r.width;
72
+ else if (key === 'top') o.y = 0;
73
+ else if (key === 'middle') o.y = Math.round((size.h - r.height) / 2);
74
+ else if (key === 'bottom') o.y = size.h - r.height;
75
+ }
76
+ this.notifyChange();
77
+ }
78
+
79
+ function distribute(axis) {
80
+ const sel = this.selectedObjects();
81
+ if (sel.length < 3) return;
82
+ this.pushHistory();
83
+ const items = sel.map((o) => ({ o, r: objectRect(o) }));
84
+ items.sort((a, b) => (axis === 'h' ? a.r.left - b.r.left : a.r.top - b.r.top));
85
+ const first = items[0];
86
+ const last = items[items.length - 1];
87
+ if (axis === 'h') {
88
+ const start = first.r.left + first.r.width / 2;
89
+ const end = last.r.left + last.r.width / 2;
90
+ const step = (end - start) / (items.length - 1);
91
+ items.forEach((item, i) => { item.o.x = Math.round(start + step * i - item.r.width / 2); });
92
+ } else {
93
+ const start = first.r.top + first.r.height / 2;
94
+ const end = last.r.top + last.r.height / 2;
95
+ const step = (end - start) / (items.length - 1);
96
+ items.forEach((item, i) => { item.o.y = Math.round(start + step * i - item.r.height / 2); });
97
+ }
98
+ this.notifyChange();
99
+ }
100
+
101
+ export const arrangeMethods = { removeSelected, duplicateSelected, nudge, arrange, alignToSlide, distribute };
@@ -1,93 +1,93 @@
1
- // [文件] gbpptx·slides·clipboard —— 剪贴板 —— 复制/剪切/粘贴(含纯文本与富文本两条路径)
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { escapeHtml } from 'guabiutils';
7
- import { cloneObject, createTextObject, topZ } from '../../../src/kernel/model.js';
8
- import { notify } from '../ui/notify.js';
9
- function canPaste() {
10
- return Boolean(this.editing) || Boolean(this.clipboard?.length);
11
- }
12
-
13
- function copySelected() {
14
- if (this.editing) {
15
- document.execCommand('copy');
16
- notify.info('已复制所选文字');
17
- return;
18
- }
19
- const objs = this.selectedObjects();
20
- if (!objs.length) return;
21
- this.clipboard = objs.map((o) => JSON.parse(JSON.stringify(o)));
22
- this.ribbon.refresh();
23
- notify.info(`已复制 ${objs.length} 个对象`);
24
- }
25
-
26
- function cutSelected() {
27
- if (this.editing) {
28
- document.execCommand('cut');
29
- this.syncEditing();
30
- return;
31
- }
32
- if (!this.selectedObjects().length) return;
33
- this.copySelected();
34
- this.removeSelected();
35
- }
36
-
37
- function paste() {
38
- if (this.editing) {
39
- this.pastePlain();
40
- return;
41
- }
42
- if (!this.clipboard?.length) return;
43
- const slide = this.currentSlide();
44
- if (!slide) return;
45
- this.pushHistory();
46
- const pasted = this.clipboard.map((o, i) => {
47
- const copy = cloneObject(o);
48
- copy.x += 18;
49
- copy.y += 18;
50
- copy.z = topZ(slide.objects) + 1 + i;
51
- return copy;
52
- });
53
- slide.objects.push(...pasted);
54
- this.selectedIds = pasted.map((o) => o.id);
55
- this.notifyChange();
56
- }
57
-
58
- function pasteText(text) {
59
- const value = String(text || '');
60
- if (!value.trim()) return;
61
- const html = value.split(/\r?\n/).map((line) => `<div>${escapeHtml(line) || '<br>'}</div>`).join('');
62
- const size = this.size;
63
- const obj = createTextObject(Math.round(size.w * 0.1), Math.round(size.h * 0.1), topZ(this.currentSlide().objects) + 1);
64
- obj.w = Math.min(640, Math.max(260, Math.round(size.w * 0.55)));
65
- obj.h = Math.min(280, Math.max(80, value.split(/\n/).length * 34));
66
- obj.props.html = html;
67
- obj.props.fontSize = 20;
68
- this.pushHistory();
69
- this.currentSlide().objects.push(obj);
70
- this.selectedIds = [obj.id];
71
- this.notifyChange();
72
- }
73
-
74
- async function pastePlain() {
75
- if (this.editing) {
76
- try {
77
- const text = await navigator.clipboard.readText();
78
- document.execCommand('insertText', false, text);
79
- this.syncEditing();
80
- } catch {
81
- notify.warning('浏览器未授予剪贴板读取权限');
82
- }
83
- return;
84
- }
85
- try {
86
- const text = await navigator.clipboard.readText();
87
- this.pasteText(text);
88
- } catch {
89
- notify.warning('浏览器未授予剪贴板读取权限,请直接用 Ctrl+V');
90
- }
91
- }
92
-
93
- export const clipboardMethods = { canPaste, copySelected, cutSelected, paste, pasteText, pastePlain };
1
+ // [文件] gbpptx·slides·clipboard —— 剪贴板 —— 复制/剪切/粘贴(含纯文本与富文本两条路径)
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { escapeHtml } from 'guabiutils';
7
+ import { cloneObject, createTextObject, topZ } from '../../../src/kernel/model.js';
8
+ import { notify } from '../ui/notify.js';
9
+ function canPaste() {
10
+ return Boolean(this.editing) || Boolean(this.clipboard?.length);
11
+ }
12
+
13
+ function copySelected() {
14
+ if (this.editing) {
15
+ document.execCommand('copy');
16
+ notify.info('已复制所选文字');
17
+ return;
18
+ }
19
+ const objs = this.selectedObjects();
20
+ if (!objs.length) return;
21
+ this.clipboard = objs.map((o) => JSON.parse(JSON.stringify(o)));
22
+ this.ribbon.refresh();
23
+ notify.info(`已复制 ${objs.length} 个对象`);
24
+ }
25
+
26
+ function cutSelected() {
27
+ if (this.editing) {
28
+ document.execCommand('cut');
29
+ this.syncEditing();
30
+ return;
31
+ }
32
+ if (!this.selectedObjects().length) return;
33
+ this.copySelected();
34
+ this.removeSelected();
35
+ }
36
+
37
+ function paste() {
38
+ if (this.editing) {
39
+ this.pastePlain();
40
+ return;
41
+ }
42
+ if (!this.clipboard?.length) return;
43
+ const slide = this.currentSlide();
44
+ if (!slide) return;
45
+ this.pushHistory();
46
+ const pasted = this.clipboard.map((o, i) => {
47
+ const copy = cloneObject(o);
48
+ copy.x += 18;
49
+ copy.y += 18;
50
+ copy.z = topZ(slide.objects) + 1 + i;
51
+ return copy;
52
+ });
53
+ slide.objects.push(...pasted);
54
+ this.selectedIds = pasted.map((o) => o.id);
55
+ this.notifyChange();
56
+ }
57
+
58
+ function pasteText(text) {
59
+ const value = String(text || '');
60
+ if (!value.trim()) return;
61
+ const html = value.split(/\r?\n/).map((line) => `<div>${escapeHtml(line) || '<br>'}</div>`).join('');
62
+ const size = this.size;
63
+ const obj = createTextObject(Math.round(size.w * 0.1), Math.round(size.h * 0.1), topZ(this.currentSlide().objects) + 1);
64
+ obj.w = Math.min(640, Math.max(260, Math.round(size.w * 0.55)));
65
+ obj.h = Math.min(280, Math.max(80, value.split(/\n/).length * 34));
66
+ obj.props.html = html;
67
+ obj.props.fontSize = 20;
68
+ this.pushHistory();
69
+ this.currentSlide().objects.push(obj);
70
+ this.selectedIds = [obj.id];
71
+ this.notifyChange();
72
+ }
73
+
74
+ async function pastePlain() {
75
+ if (this.editing) {
76
+ try {
77
+ const text = await navigator.clipboard.readText();
78
+ document.execCommand('insertText', false, text);
79
+ this.syncEditing();
80
+ } catch {
81
+ notify.warning('浏览器未授予剪贴板读取权限');
82
+ }
83
+ return;
84
+ }
85
+ try {
86
+ const text = await navigator.clipboard.readText();
87
+ this.pasteText(text);
88
+ } catch {
89
+ notify.warning('浏览器未授予剪贴板读取权限,请直接用 Ctrl+V');
90
+ }
91
+ }
92
+
93
+ export const clipboardMethods = { canPaste, copySelected, cutSelected, paste, pasteText, pastePlain };