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
@@ -1,103 +1,103 @@
1
- // [文件] gbpptx·slides·slides —— 页操作 —— 增删移动、切换动画、背景/主题/画幅
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { clamp } from 'guabiutils';
7
- import { SLIDE_SIZES, THEMES, copySlide, createSlide, createSlideWithLayout, normalizeTransition, scaleSnapshotSize, transitionOf } from '../../../src/kernel/model.js';
8
- import { notify } from '../ui/notify.js';
9
- function addSlide(layoutKey) {
10
- const slide = layoutKey ? createSlideWithLayout(layoutKey, this.size) : createSlide();
11
- this.pushHistory();
12
- this.snapshot.slides.splice(this.index + 1, 0, slide);
13
- this.index += 1;
14
- this.selectedIds = [];
15
- this.notifyChange();
16
- }
17
-
18
- function dupSlide() {
19
- this.pushHistory();
20
- this.snapshot.slides.splice(this.index + 1, 0, copySlide(this.currentSlide()));
21
- this.index += 1;
22
- this.selectedIds = [];
23
- this.notifyChange();
24
- }
25
-
26
- function delSlide() {
27
- if (this.snapshot.slides.length <= 1) return notify.warning('至少要保留一页');
28
- this.pushHistory();
29
- this.snapshot.slides.splice(this.index, 1);
30
- this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
31
- this.selectedIds = [];
32
- this.notifyChange();
33
- }
34
-
35
- function moveSlide(delta) {
36
- this.moveSlideTo(this.index, this.index + delta);
37
- }
38
-
39
- function moveSlideTo(from, to) {
40
- const length = this.snapshot.slides.length;
41
- if (from < 0 || from >= length || to < 0 || to >= length || from === to) return;
42
- this.pushHistory();
43
- const [slide] = this.snapshot.slides.splice(from, 1);
44
- this.snapshot.slides.splice(to, 0, slide);
45
- this.index = to;
46
- this.selectedIds = [];
47
- this.notifyChange();
48
- }
49
-
50
- function toggleSlideHidden() {
51
- const slide = this.currentSlide();
52
- if (!slide) return;
53
- this.pushHistory();
54
- slide.hidden = !slide.hidden;
55
- this.notifyChange();
56
- }
57
-
58
- function setTransition(patch) {
59
- const slide = this.currentSlide();
60
- if (!slide) return;
61
- this.pushHistory();
62
- slide.transition = normalizeTransition({ ...transitionOf(slide), ...patch });
63
- this.notifyChange();
64
- }
65
-
66
- function applyTransitionAll() {
67
- const current = transitionOf(this.currentSlide());
68
- this.pushHistory();
69
- for (const slide of this.snapshot.slides) slide.transition = { ...current };
70
- this.notifyChange();
71
- notify.success('已把当前切换应用到全部幻灯片');
72
- }
73
-
74
- function previewTransition() {
75
- this.canvas.previewTransition(transitionOf(this.currentSlide()));
76
- }
77
-
78
- function setSlideBg(color) {
79
- const slide = this.currentSlide();
80
- if (!slide) return;
81
- this.pushHistory();
82
- slide.bg = color || '';
83
- this.notifyChange();
84
- }
85
-
86
- function setTheme(key) {
87
- if (!THEMES[key] || this.snapshot.theme === key) return;
88
- this.pushHistory();
89
- this.snapshot.theme = key;
90
- this.notifyChange();
91
- }
92
-
93
- function setSlideSize(presetKey) {
94
- const preset = SLIDE_SIZES.find((s) => s.key === presetKey);
95
- if (!preset) return;
96
- if (this.size.w === preset.w && this.size.h === preset.h) return;
97
- this.pushHistory();
98
- scaleSnapshotSize(this.snapshot, { w: preset.w, h: preset.h });
99
- this.notifyChange();
100
- this.fitToWindow();
101
- }
102
-
103
- export const slidesMethods = { addSlide, dupSlide, delSlide, moveSlide, moveSlideTo, toggleSlideHidden, setTransition, applyTransitionAll, previewTransition, setSlideBg, setTheme, setSlideSize };
1
+ // [文件] gbpptx·slides·slides —— 页操作 —— 增删移动、切换动画、背景/主题/画幅
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { clamp } from 'guabiutils';
7
+ import { SLIDE_SIZES, THEMES, copySlide, createSlide, createSlideWithLayout, normalizeTransition, scaleSnapshotSize, transitionOf } from '../../../src/kernel/model.js';
8
+ import { notify } from '../ui/notify.js';
9
+ function addSlide(layoutKey) {
10
+ const slide = layoutKey ? createSlideWithLayout(layoutKey, this.size) : createSlide();
11
+ this.pushHistory();
12
+ this.snapshot.slides.splice(this.index + 1, 0, slide);
13
+ this.index += 1;
14
+ this.selectedIds = [];
15
+ this.notifyChange();
16
+ }
17
+
18
+ function dupSlide() {
19
+ this.pushHistory();
20
+ this.snapshot.slides.splice(this.index + 1, 0, copySlide(this.currentSlide()));
21
+ this.index += 1;
22
+ this.selectedIds = [];
23
+ this.notifyChange();
24
+ }
25
+
26
+ function delSlide() {
27
+ if (this.snapshot.slides.length <= 1) return notify.warning('至少要保留一页');
28
+ this.pushHistory();
29
+ this.snapshot.slides.splice(this.index, 1);
30
+ this.index = clamp(this.index, 0, this.snapshot.slides.length - 1);
31
+ this.selectedIds = [];
32
+ this.notifyChange();
33
+ }
34
+
35
+ function moveSlide(delta) {
36
+ this.moveSlideTo(this.index, this.index + delta);
37
+ }
38
+
39
+ function moveSlideTo(from, to) {
40
+ const length = this.snapshot.slides.length;
41
+ if (from < 0 || from >= length || to < 0 || to >= length || from === to) return;
42
+ this.pushHistory();
43
+ const [slide] = this.snapshot.slides.splice(from, 1);
44
+ this.snapshot.slides.splice(to, 0, slide);
45
+ this.index = to;
46
+ this.selectedIds = [];
47
+ this.notifyChange();
48
+ }
49
+
50
+ function toggleSlideHidden() {
51
+ const slide = this.currentSlide();
52
+ if (!slide) return;
53
+ this.pushHistory();
54
+ slide.hidden = !slide.hidden;
55
+ this.notifyChange();
56
+ }
57
+
58
+ function setTransition(patch) {
59
+ const slide = this.currentSlide();
60
+ if (!slide) return;
61
+ this.pushHistory();
62
+ slide.transition = normalizeTransition({ ...transitionOf(slide), ...patch });
63
+ this.notifyChange();
64
+ }
65
+
66
+ function applyTransitionAll() {
67
+ const current = transitionOf(this.currentSlide());
68
+ this.pushHistory();
69
+ for (const slide of this.snapshot.slides) slide.transition = { ...current };
70
+ this.notifyChange();
71
+ notify.success('已把当前切换应用到全部幻灯片');
72
+ }
73
+
74
+ function previewTransition() {
75
+ this.canvas.previewTransition(transitionOf(this.currentSlide()));
76
+ }
77
+
78
+ function setSlideBg(color) {
79
+ const slide = this.currentSlide();
80
+ if (!slide) return;
81
+ this.pushHistory();
82
+ slide.bg = color || '';
83
+ this.notifyChange();
84
+ }
85
+
86
+ function setTheme(key) {
87
+ if (!THEMES[key] || this.snapshot.theme === key) return;
88
+ this.pushHistory();
89
+ this.snapshot.theme = key;
90
+ this.notifyChange();
91
+ }
92
+
93
+ function setSlideSize(presetKey) {
94
+ const preset = SLIDE_SIZES.find((s) => s.key === presetKey);
95
+ if (!preset) return;
96
+ if (this.size.w === preset.w && this.size.h === preset.h) return;
97
+ this.pushHistory();
98
+ scaleSnapshotSize(this.snapshot, { w: preset.w, h: preset.h });
99
+ this.notifyChange();
100
+ this.fitToWindow();
101
+ }
102
+
103
+ export const slidesMethods = { addSlide, dupSlide, delSlide, moveSlide, moveSlideTo, toggleSlideHidden, setTransition, applyTransitionAll, previewTransition, setSlideBg, setTheme, setSlideSize };
@@ -1,102 +1,102 @@
1
- // [文件] gbpptx·slides·table —— 表格操作 —— 行列增删、表格样式、表头与隔行底色
2
-
3
- // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
- // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
-
6
- import { clamp } from 'guabiutils';
7
- import { notify } from '../ui/notify.js';
8
- function resizeTable(id, rows, cols) {
9
- const obj = this.selectedById(id);
10
- if (!obj || obj.type !== 'table') return;
11
- const r = clamp(Math.round(rows), 1, 50);
12
- const c = clamp(Math.round(cols), 1, 30);
13
- this.pushHistory();
14
- const cur = obj.props.rows;
15
- obj.props.rows = Array.from({ length: r }, (_, ri) => Array.from({ length: c }, (_, ci) => cur[ri]?.[ci] ?? ''));
16
- obj.props.colW = [];
17
- obj.props.rowH = [];
18
- this.notifyChange();
19
- }
20
-
21
- function insertTableRow(where) {
22
- const obj = this.firstSelected();
23
- if (!obj || obj.type !== 'table') return;
24
- const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ri : 0;
25
- const at = where === 'above' ? cur : cur + 1;
26
- this.pushHistory();
27
- obj.props.rows.splice(at, 0, Array.from({ length: obj.props.rows[0].length }, () => ''));
28
- obj.props.rowH = [];
29
- this.notifyChange();
30
- }
31
-
32
- function insertTableColumn(where) {
33
- const obj = this.firstSelected();
34
- if (!obj || obj.type !== 'table') return;
35
- const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ci : 0;
36
- const at = where === 'left' ? cur : cur + 1;
37
- this.pushHistory();
38
- for (const row of obj.props.rows) row.splice(at, 0, '');
39
- obj.props.colW = [];
40
- this.notifyChange();
41
- }
42
-
43
- function deleteTableRow() {
44
- const obj = this.firstSelected();
45
- if (!obj || obj.type !== 'table') return;
46
- if (obj.props.rows.length <= 1) return notify.warning('表格至少要保留一行');
47
- const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ri : 0;
48
- this.pushHistory();
49
- obj.props.rows.splice(Math.min(cur, obj.props.rows.length - 1), 1);
50
- obj.props.rowH = [];
51
- this.notifyChange();
52
- }
53
-
54
- function deleteTableColumn() {
55
- const obj = this.firstSelected();
56
- if (!obj || obj.type !== 'table') return;
57
- const cols = obj.props.rows[0]?.length || 0;
58
- if (cols <= 1) return notify.warning('表格至少要保留一列');
59
- const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ci : 0;
60
- this.pushHistory();
61
- for (const row of obj.props.rows) row.splice(Math.min(cur, cols - 1), 1);
62
- obj.props.colW = [];
63
- this.notifyChange();
64
- }
65
-
66
- function setTableStyle(style) {
67
- const obj = this.firstSelected();
68
- if (!obj || obj.type !== 'table') return;
69
- this.pushHistory();
70
- obj.props.tableStyle = style;
71
- obj.props.headerRow = style !== 'plain';
72
- obj.props.bandedRows = style === 'banded' || style === 'dark';
73
- this.notifyChange();
74
- }
75
-
76
- function toggleHeaderRow() {
77
- const obj = this.firstSelected();
78
- if (!obj || obj.type !== 'table') return;
79
- this.pushHistory();
80
- obj.props.headerRow = !obj.props.headerRow;
81
- if (!obj.props.headerRow) {
82
- obj.props.tableStyle = obj.props.bandedRows ? (obj.props.tableStyle === 'dark' ? 'dark' : 'banded') : 'plain';
83
- } else if (obj.props.tableStyle === 'plain') {
84
- obj.props.tableStyle = 'header';
85
- }
86
- this.notifyChange();
87
- }
88
-
89
- function toggleBandedRows() {
90
- const obj = this.firstSelected();
91
- if (!obj || obj.type !== 'table') return;
92
- this.pushHistory();
93
- obj.props.bandedRows = !obj.props.bandedRows;
94
- if (obj.props.bandedRows) {
95
- if (obj.props.tableStyle === 'plain' || obj.props.tableStyle === 'header') obj.props.tableStyle = 'banded';
96
- } else if (obj.props.tableStyle === 'banded' || obj.props.tableStyle === 'dark') {
97
- obj.props.tableStyle = obj.props.headerRow ? 'header' : 'plain';
98
- }
99
- this.notifyChange();
100
- }
101
-
102
- export const tableMethods = { resizeTable, insertTableRow, insertTableColumn, deleteTableRow, deleteTableColumn, setTableStyle, toggleHeaderRow, toggleBandedRows };
1
+ // [文件] gbpptx·slides·table —— 表格操作 —— 行列增删、表格样式、表头与隔行底色
2
+
3
+ // [设计] 方法以独立函数导出,由 slides-app.js 末尾 Object.assign 装配到 SlidesApp.prototype:
4
+ // 仍是同一个 this(方法调用时绑定),调用方形状与拆分前完全一致。
5
+
6
+ import { clamp } from 'guabiutils';
7
+ import { notify } from '../ui/notify.js';
8
+ function resizeTable(id, rows, cols) {
9
+ const obj = this.selectedById(id);
10
+ if (!obj || obj.type !== 'table') return;
11
+ const r = clamp(Math.round(rows), 1, 50);
12
+ const c = clamp(Math.round(cols), 1, 30);
13
+ this.pushHistory();
14
+ const cur = obj.props.rows;
15
+ obj.props.rows = Array.from({ length: r }, (_, ri) => Array.from({ length: c }, (_, ci) => cur[ri]?.[ci] ?? ''));
16
+ obj.props.colW = [];
17
+ obj.props.rowH = [];
18
+ this.notifyChange();
19
+ }
20
+
21
+ function insertTableRow(where) {
22
+ const obj = this.firstSelected();
23
+ if (!obj || obj.type !== 'table') return;
24
+ const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ri : 0;
25
+ const at = where === 'above' ? cur : cur + 1;
26
+ this.pushHistory();
27
+ obj.props.rows.splice(at, 0, Array.from({ length: obj.props.rows[0].length }, () => ''));
28
+ obj.props.rowH = [];
29
+ this.notifyChange();
30
+ }
31
+
32
+ function insertTableColumn(where) {
33
+ const obj = this.firstSelected();
34
+ if (!obj || obj.type !== 'table') return;
35
+ const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ci : 0;
36
+ const at = where === 'left' ? cur : cur + 1;
37
+ this.pushHistory();
38
+ for (const row of obj.props.rows) row.splice(at, 0, '');
39
+ obj.props.colW = [];
40
+ this.notifyChange();
41
+ }
42
+
43
+ function deleteTableRow() {
44
+ const obj = this.firstSelected();
45
+ if (!obj || obj.type !== 'table') return;
46
+ if (obj.props.rows.length <= 1) return notify.warning('表格至少要保留一行');
47
+ const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ri : 0;
48
+ this.pushHistory();
49
+ obj.props.rows.splice(Math.min(cur, obj.props.rows.length - 1), 1);
50
+ obj.props.rowH = [];
51
+ this.notifyChange();
52
+ }
53
+
54
+ function deleteTableColumn() {
55
+ const obj = this.firstSelected();
56
+ if (!obj || obj.type !== 'table') return;
57
+ const cols = obj.props.rows[0]?.length || 0;
58
+ if (cols <= 1) return notify.warning('表格至少要保留一列');
59
+ const cur = this.tableCursor?.objId === obj.id ? this.tableCursor.ci : 0;
60
+ this.pushHistory();
61
+ for (const row of obj.props.rows) row.splice(Math.min(cur, cols - 1), 1);
62
+ obj.props.colW = [];
63
+ this.notifyChange();
64
+ }
65
+
66
+ function setTableStyle(style) {
67
+ const obj = this.firstSelected();
68
+ if (!obj || obj.type !== 'table') return;
69
+ this.pushHistory();
70
+ obj.props.tableStyle = style;
71
+ obj.props.headerRow = style !== 'plain';
72
+ obj.props.bandedRows = style === 'banded' || style === 'dark';
73
+ this.notifyChange();
74
+ }
75
+
76
+ function toggleHeaderRow() {
77
+ const obj = this.firstSelected();
78
+ if (!obj || obj.type !== 'table') return;
79
+ this.pushHistory();
80
+ obj.props.headerRow = !obj.props.headerRow;
81
+ if (!obj.props.headerRow) {
82
+ obj.props.tableStyle = obj.props.bandedRows ? (obj.props.tableStyle === 'dark' ? 'dark' : 'banded') : 'plain';
83
+ } else if (obj.props.tableStyle === 'plain') {
84
+ obj.props.tableStyle = 'header';
85
+ }
86
+ this.notifyChange();
87
+ }
88
+
89
+ function toggleBandedRows() {
90
+ const obj = this.firstSelected();
91
+ if (!obj || obj.type !== 'table') return;
92
+ this.pushHistory();
93
+ obj.props.bandedRows = !obj.props.bandedRows;
94
+ if (obj.props.bandedRows) {
95
+ if (obj.props.tableStyle === 'plain' || obj.props.tableStyle === 'header') obj.props.tableStyle = 'banded';
96
+ } else if (obj.props.tableStyle === 'banded' || obj.props.tableStyle === 'dark') {
97
+ obj.props.tableStyle = obj.props.headerRow ? 'header' : 'plain';
98
+ }
99
+ this.notifyChange();
100
+ }
101
+
102
+ export const tableMethods = { resizeTable, insertTableRow, insertTableColumn, deleteTableRow, deleteTableColumn, setTableStyle, toggleHeaderRow, toggleBandedRows };