@web-ppt/edit-core 0.6.0 → 0.8.0-beta.1

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 (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +8 -0
  3. package/dist/agent/base64.d.ts +2 -0
  4. package/dist/agent/errors.d.ts +9 -0
  5. package/dist/agent/generated-schema.d.ts +6038 -0
  6. package/dist/agent/generated-validator.d.ts +6 -0
  7. package/dist/agent/index.d.ts +6 -0
  8. package/dist/agent/query.d.ts +3 -0
  9. package/dist/agent/session.d.ts +33 -0
  10. package/dist/agent/targets.d.ts +5 -0
  11. package/dist/agent/tools.d.ts +2 -0
  12. package/dist/agent/types.d.ts +126 -0
  13. package/dist/agent/validation.d.ts +2 -0
  14. package/dist/agent.js +46364 -0
  15. package/dist/commands/types.d.ts +23 -23
  16. package/dist/fill/api.d.ts +29 -0
  17. package/dist/fill/chart-seed-chart.d.ts +7 -0
  18. package/dist/fill/chart-seed-workbook.d.ts +12 -0
  19. package/dist/fill/chart-seed-xml.d.ts +12 -0
  20. package/dist/fill/chart-seed.d.ts +17 -0
  21. package/dist/fill/content.d.ts +16 -0
  22. package/dist/fill/errors.d.ts +10 -0
  23. package/dist/fill/generated-schema.d.ts +291 -0
  24. package/dist/fill/generated-validator.d.ts +6 -0
  25. package/dist/fill/index.d.ts +10 -0
  26. package/dist/fill/layouts.d.ts +24 -0
  27. package/dist/fill/package.d.ts +2 -0
  28. package/dist/fill/repair.d.ts +32 -0
  29. package/dist/fill/text-validation.d.ts +3 -0
  30. package/dist/fill/types.d.ts +60 -0
  31. package/dist/fill/validation.d.ts +10 -0
  32. package/dist/fill.js +12 -0
  33. package/dist/generate.js +53 -53
  34. package/dist/index-2ti1e4_F.js +411 -0
  35. package/dist/index-BbsPmmoy.js +4046 -0
  36. package/dist/save/notes-master.d.ts +12 -0
  37. package/dist/save.js +650 -484
  38. package/dist/{slide-parts-D0o_DDhi.js → slide-parts-zyOP9lia.js} +5 -5
  39. package/dist/types.d.ts +4 -4
  40. package/package.json +13 -3
  41. package/schemas/agent-tools.schema.json +7999 -0
  42. package/schemas/template-fill.schema.json +371 -0
package/dist/save.js CHANGED
@@ -1,581 +1,747 @@
1
- import { r as E, a as fe, b as Me, m as He, c as Le, d as Ne, e as Be, n as ae, l as Fe, o as ue, f as Ue, g as Ge, h as _e, v as We, i as Xe, j as qe, t as Ve, k as Je, p as Ke, q as ge, s as Pe, u as Qe, w as Ie, x as Ye, y as Ze, z as et, A as ze, B as tt, C as st, D as rt, E as at, F as nt, G as ot, H as it, I as ct, J as lt, K as pt, L as ft, M as ut, N as mt, O as dt, P as ht, Q as gt, R as Pt } from "./model-invariants-BM19JVxy.js";
2
- import { p as D, r as ve, s as _, f as yt, a as W, i as ye, c as vt, b as Ae, x as ee, D as Z, d as me, e as wt, g as ne, P as A } from "./index-C2r7c6G6.js";
3
- import { p as St } from "./patch-BwhfBbYE.js";
4
- import { p as kt, m as Ot, c as bt, t as Et, a as xt, e as Tt, r as Mt, b as Nt, d as Ct, f as Ce, g as Rt, h as Re, i as $t, j as jt, k as Xt, l as It, n as zt, o as At, q as Dt, s as Ht, u as Lt, v as Bt, w as Ft } from "./slide-parts-D0o_DDhi.js";
5
- import { PLACEHOLDER_DIRECT_BITS as K, findPlaceholderByIdentity as Ut } from "@web-ppt/core";
6
- const v = (t, a) => {
7
- var s;
8
- return (s = Ae(t, { localName: a, namespaceUri: null })) == null ? void 0 : s.value;
9
- }, L = (t, a) => ee(t, { localName: a, namespaceUri: t.namespaceUri }), $e = (t) => L(D(t).root, "Relationship");
10
- function Gt(t, a, s, i, n) {
11
- var R, w, te;
12
- const c = (p) => {
13
- var k;
14
- return s[p] ?? ((k = t.package) == null ? void 0 : k.parts[p]);
15
- }, u = a.flatMap((p) => {
16
- var T, C;
17
- const k = (T = p.creation) == null ? void 0 : T.duplicateSourcePart, X = (C = p.origin) == null ? void 0 : C.part, N = k && c(E(k));
18
- return !N || !X ? [] : $e(N).filter((S) => {
19
- var q;
20
- return ((q = v(S, "Type")) == null ? void 0 : q.endsWith("/comments")) && v(S, "TargetMode") !== "External";
21
- }).map((S) => ({ slide: X, id: v(S, "Id"), source: fe(k, v(S, "Target")) }));
22
- }), f = [...i].filter((p) => /^ppt\/comments\/(?:_rels\/)?web-ppt-(?!edit-)/.test(p));
23
- if (!u.length && !f.length) return;
24
- const d = "ppt/presentation.xml", g = $e(c(E(d))).find((p) => {
25
- var k;
26
- return (k = v(p, "Type")) == null ? void 0 : k.endsWith("/commentAuthors");
27
- }), M = g && fe(d, v(g, "Target")), B = M && c(M);
28
- M && B && (s[M] ?? (s[M] = B.slice()));
29
- const U = B ? D(B) : void 0, F = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
30
- for (const p of U ? L(U.root, "cmAuthor") : [])
31
- F.set(v(p, "id"), Number(v(p, "lastIdx")) || 0), o.set(v(p, "id"), /* @__PURE__ */ new Set());
32
- const P = "[Content_Types].xml", x = D(n[P] ?? c(P));
33
- for (const p of L(x.root, "Override")) {
34
- const k = (R = v(p, "PartName")) == null ? void 0 : R.slice(1);
35
- if (!k || i.has(k) || !((w = v(p, "ContentType")) != null && w.endsWith(".comments+xml"))) continue;
36
- const X = c(k);
37
- if (!X) throw new Error(`批注来源部件缺失:${k}`);
38
- for (const N of L(D(X).root, "cm")) {
39
- const T = v(N, "authorId"), C = Number(v(N, "idx"));
40
- if (o.has(T) || o.set(T, /* @__PURE__ */ new Set()), !Number.isInteger(C) || C < 0 || C > 4294967295) throw new Error("批注作者或索引无效");
41
- o.get(T).add(C), F.set(T, Math.max(F.get(T) ?? 0, C));
1
+ import { r as T, a as se, b as Ne, m as rt, c as st, d as Ge, e as nt, n as ne, l as at, o as fe, f as ot, g as it, h as ct, v as lt, i as Qe, j as pt, t as ft, k as ut, p as mt, q as Te, s as Me, u as dt, w as Ze, x as ht, y as gt, z as Pt, A as et, B as yt, C as wt, D as vt, E as St, F as kt, G as Et, H as xt, I as Ot, J as Tt, K as Mt, L as Nt, M as bt, N as $t, O as Rt, P as It, Q as Ct, R as Ut } from "./model-invariants-BM19JVxy.js";
2
+ import { p as I, r as Ce, s as W, f as At, a as H, i as oe, c as Ue, b as Ae, x as D, D as re, d as ve, e as jt, g as ae, P as L, O as ue } from "./index-C2r7c6G6.js";
3
+ import { p as Lt } from "./patch-BwhfBbYE.js";
4
+ import { p as be, a as Xt, m as _t, c as zt, t as Dt, b as Ht, e as Ft, r as Bt, d as Gt, f as Wt, g as Vt, h as We, i as qt, j as Yt, k as Kt, l as Jt, n as Qt, o as Zt, q as er, s as tr, u as rr, v as sr, w as nr } from "./slide-parts-zyOP9lia.js";
5
+ import { PLACEHOLDER_DIRECT_BITS as ee, findPlaceholderByIdentity as ar } from "@web-ppt/core";
6
+ const x = (e, s) => {
7
+ var r;
8
+ return (r = Ae(e, { localName: s, namespaceUri: null })) == null ? void 0 : r.value;
9
+ }, G = (e, s) => D(e, { localName: s, namespaceUri: e.namespaceUri }), Ve = (e) => G(I(e).root, "Relationship");
10
+ function or(e, s, r, n, a) {
11
+ var U, S, q;
12
+ const i = (c) => {
13
+ var y;
14
+ return r[c] ?? ((y = e.package) == null ? void 0 : y.parts[c]);
15
+ }, p = s.flatMap((c) => {
16
+ var k, b;
17
+ const y = (k = c.creation) == null ? void 0 : k.duplicateSourcePart, E = (b = c.origin) == null ? void 0 : b.part, C = y && i(T(y));
18
+ return !C || !E ? [] : Ve(C).filter(($) => {
19
+ var F;
20
+ return ((F = x($, "Type")) == null ? void 0 : F.endsWith("/comments")) && x($, "TargetMode") !== "External";
21
+ }).map(($) => ({ slide: E, id: x($, "Id"), source: se(y, x($, "Target")) }));
22
+ }), f = [...n].filter((c) => /^ppt\/comments\/(?:_rels\/)?web-ppt-(?!edit-)/.test(c));
23
+ if (!p.length && !f.length) return;
24
+ const u = "ppt/presentation.xml", h = Ve(i(T(u))).find((c) => {
25
+ var y;
26
+ return (y = x(c, "Type")) == null ? void 0 : y.endsWith("/commentAuthors");
27
+ }), P = h && se(u, x(h, "Target")), g = P && i(P);
28
+ P && g && (r[P] ?? (r[P] = g.slice()));
29
+ const A = g ? I(g) : void 0, X = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
30
+ for (const c of A ? G(A.root, "cmAuthor") : [])
31
+ X.set(x(c, "id"), Number(x(c, "lastIdx")) || 0), l.set(x(c, "id"), /* @__PURE__ */ new Set());
32
+ const w = "[Content_Types].xml", M = I(a[w] ?? i(w));
33
+ for (const c of G(M.root, "Override")) {
34
+ const y = (U = x(c, "PartName")) == null ? void 0 : U.slice(1);
35
+ if (!y || n.has(y) || !((S = x(c, "ContentType")) != null && S.endsWith(".comments+xml"))) continue;
36
+ const E = i(y);
37
+ if (!E) throw new Error(`批注来源部件缺失:${y}`);
38
+ for (const C of G(I(E).root, "cm")) {
39
+ const k = x(C, "authorId"), b = Number(x(C, "idx"));
40
+ if (l.has(k) || l.set(k, /* @__PURE__ */ new Set()), !Number.isInteger(b) || b < 0 || b > 4294967295) throw new Error("批注作者或索引无效");
41
+ l.get(k).add(b), X.set(k, Math.max(X.get(k) ?? 0, b));
42
42
  }
43
43
  }
44
- for (const p of [...L(x.root, "Override")])
45
- f.includes(((te = v(p, "PartName")) == null ? void 0 : te.slice(1)) ?? "") && ve(x.root, p);
44
+ for (const c of [...G(M.root, "Override")])
45
+ f.includes(((q = x(c, "PartName")) == null ? void 0 : q.slice(1)) ?? "") && Ce(M.root, c);
46
46
  const j = /* @__PURE__ */ new Set();
47
- for (const p of u) {
48
- const k = c(p.source);
49
- if (!k) throw new Error(`复制批注缺少来源部件:${p.source}`);
50
- const X = D(k);
51
- let N = 0;
52
- const T = /* @__PURE__ */ new Map();
53
- for (const $ of L(X.root, "cm").sort((y, O) => Number(v(y, "idx")) - Number(v(O, "idx")))) {
54
- const y = v($, "authorId");
55
- if (!F.has(y)) throw new Error(`复制批注缺少作者:${y}`);
56
- let O = N + 1;
57
- for (; o.get(y).has(O); ) O++;
47
+ for (const c of p) {
48
+ const y = i(c.source);
49
+ if (!y) throw new Error(`复制批注缺少来源部件:${c.source}`);
50
+ const E = I(y);
51
+ let C = 0;
52
+ const k = /* @__PURE__ */ new Map();
53
+ for (const d of G(E.root, "cm").sort((N, O) => Number(x(N, "idx")) - Number(x(O, "idx")))) {
54
+ const N = x(d, "authorId");
55
+ if (!X.has(N)) throw new Error(`复制批注缺少作者:${N}`);
56
+ let O = C + 1;
57
+ for (; l.get(N).has(O); ) O++;
58
58
  if (O > 4294967295) throw new Error("批注索引超出 OOXML 可表示范围");
59
- o.get(y).add(O), F.set(y, Math.max(F.get(y), O)), N = O, T.set(`${y}:${v($, "idx")}`, O), _($, "idx", String(O));
59
+ l.get(N).add(O), X.set(N, Math.max(X.get(N), O)), C = O, k.set(`${N}:${x(d, "idx")}`, O), W(d, "idx", String(O));
60
60
  }
61
- for (const $ of L(X.root, "cm")) {
62
- const y = yt($, { localName: "parentCm", namespaceUri: "http://schemas.microsoft.com/office/powerpoint/2012/main" }), O = y && T.get(`${v(y, "authorId")}:${v(y, "idx")}`);
63
- y && O !== void 0 && _(y, "idx", String(O));
61
+ for (const d of G(E.root, "cm")) {
62
+ const N = At(d, { localName: "parentCm", namespaceUri: "http://schemas.microsoft.com/office/powerpoint/2012/main" }), O = N && k.get(`${x(N, "authorId")}:${x(N, "idx")}`);
63
+ N && O !== void 0 && W(N, "idx", String(O));
64
64
  }
65
- const C = `ppt/comments/web-ppt-${p.slide.slice(p.slide.lastIndexOf("/") + 1).replace(/\.xml$/, "")}`;
66
- let S = `${C}.xml`, q = 1;
67
- for (; c(S) && !i.has(S); ) S = `${C}-${q++}.xml`;
68
- n[S] = W(X), j.add(S), i.add(S);
69
- const se = E(p.slide), oe = D(n[se]), V = L(oe.root, "Relationship").find(($) => v($, "Id") === p.id);
70
- if (!V) throw new Error("复制批注目标关系缺失");
71
- _(V, "Target", Me(p.slide, S)), n[se] = W(oe);
72
- const m = c(E(p.source));
73
- if (m) {
74
- const $ = E(S), y = D(m);
75
- for (const O of L(y.root, "Relationship")) {
76
- const J = v(O, "Target");
77
- if (!J || v(O, "TargetMode") === "External") continue;
78
- const ie = J.includes("#") ? J.slice(J.indexOf("#")) : "";
79
- _(O, "Target", Me(S, fe(p.source, J)) + ie);
65
+ const b = `ppt/comments/web-ppt-${c.slide.slice(c.slide.lastIndexOf("/") + 1).replace(/\.xml$/, "")}`;
66
+ let $ = `${b}.xml`, F = 1;
67
+ for (; i($) && !n.has($); ) $ = `${b}-${F++}.xml`;
68
+ a[$] = H(E), j.add($), n.add($);
69
+ const ce = T(c.slide), le = I(a[ce]), de = G(le.root, "Relationship").find((d) => x(d, "Id") === c.id);
70
+ if (!de) throw new Error("复制批注目标关系缺失");
71
+ W(de, "Target", Ne(c.slide, $)), a[ce] = H(le);
72
+ const Q = i(T(c.source));
73
+ if (Q) {
74
+ const d = T($), N = I(Q);
75
+ for (const O of G(N.root, "Relationship")) {
76
+ const Z = x(O, "Target");
77
+ if (!Z || x(O, "TargetMode") === "External") continue;
78
+ const xe = Z.includes("#") ? Z.slice(Z.indexOf("#")) : "";
79
+ W(O, "Target", Ne($, se(c.source, Z)) + xe);
80
80
  }
81
- n[$] = W(y), j.add($), i.add($);
81
+ a[d] = H(N), j.add(d), n.add(d);
82
82
  }
83
- ye(x.root, vt("Override", { attributes: [
84
- ["PartName", `/${S}`],
83
+ oe(M.root, Ue("Override", { attributes: [
84
+ ["PartName", `/${$}`],
85
85
  ["ContentType", "application/vnd.openxmlformats-officedocument.presentationml.comments+xml"]
86
86
  ] }));
87
87
  }
88
- for (const p of f) j.has(p) || (n[p] = null);
89
- for (const p of U ? L(U.root, "cmAuthor") : []) _(p, "lastIdx", String(F.get(v(p, "id")) ?? 0));
90
- U && M && (n[M] = W(U)), n[P] = W(x);
88
+ for (const c of f) j.has(c) || (a[c] = null);
89
+ for (const c of A ? G(A.root, "cmAuthor") : []) W(c, "lastIdx", String(X.get(x(c, "id")) ?? 0));
90
+ A && P && (a[P] = H(A)), a[w] = H(M);
91
91
  }
92
- function De(t, a, s) {
93
- var n;
94
- const i = a[s] ?? ((n = t.package) == null ? void 0 : n.parts[s]);
95
- if (!i) throw new Error(`页面副本缺少来源 OPC part:${s}`);
96
- return i;
92
+ function tt(e, s, r) {
93
+ var a;
94
+ const n = s[r] ?? ((a = e.package) == null ? void 0 : a.parts[r]);
95
+ if (!n) throw new Error(`页面副本缺少来源 OPC part:${r}`);
96
+ return n;
97
97
  }
98
- function _t(t, a, s) {
99
- var n;
100
- const i = (n = a.creation) == null ? void 0 : n.duplicateSourcePart;
101
- return i ? De(t, s, i) : void 0;
98
+ function ir(e, s, r) {
99
+ var a;
100
+ const n = (a = s.creation) == null ? void 0 : a.duplicateSourcePart;
101
+ return n ? tt(e, r, n) : void 0;
102
102
  }
103
- function pe(t, a, s) {
104
- var n;
105
- const i = (n = a.creation) == null ? void 0 : n.duplicateSourcePart;
106
- return i ? De(t, s, E(i)) : void 0;
107
- }
108
- function Wt(t) {
109
- var s, i;
110
- const a = (s = t.origin) == null ? void 0 : s.part;
111
- return a ? (((i = t.creation) == null ? void 0 : i.duplicateRemovedSpids) ?? []).map((n) => ({
112
- id: `${t.id}-baseline-${n}`,
113
- parent: t.id,
114
- meta: { editable: "full", origin: { part: a, spid: n } }
103
+ function Pe(e, s, r) {
104
+ var a;
105
+ const n = (a = s.creation) == null ? void 0 : a.duplicateSourcePart;
106
+ return n ? tt(e, r, T(n)) : void 0;
107
+ }
108
+ function cr(e) {
109
+ var r, n;
110
+ const s = (r = e.origin) == null ? void 0 : r.part;
111
+ return s ? (((n = e.creation) == null ? void 0 : n.duplicateRemovedSpids) ?? []).map((a) => ({
112
+ id: `${e.id}-baseline-${a}`,
113
+ parent: e.id,
114
+ meta: { editable: "full", origin: { part: s, spid: a } }
115
115
  })) : [];
116
116
  }
117
- function qt(t, a) {
118
- const { host: s } = Fe(t, a), i = ne(s, { localName: "spPr", namespaceUri: A });
119
- if (!i) throw new Error(`元素 ${a.id} 缺少 p:spPr`);
120
- return i;
121
- }
122
- function Vt(t, a, s, i) {
123
- if (!s && !i) return;
124
- const n = qt(t, a);
125
- for (const f of [...ee(n)])
126
- f.namespaceUri === Z && ["prstGeom", "custGeom"].includes(f.localName) && ve(n, f);
127
- if (i) {
128
- me(n, wt(i));
117
+ function lr(e, s) {
118
+ const { host: r } = at(e, s), n = ae(r, { localName: "spPr", namespaceUri: L });
119
+ if (!n) throw new Error(`元素 ${s.id} 缺少 p:spPr`);
120
+ return n;
121
+ }
122
+ function pr(e, s, r, n) {
123
+ if (!r && !n) return;
124
+ const a = lr(e, s);
125
+ for (const f of [...D(a)])
126
+ f.namespaceUri === re && ["prstGeom", "custGeom"].includes(f.localName) && Ce(a, f);
127
+ if (n) {
128
+ ve(a, jt(n));
129
129
  return;
130
130
  }
131
- if (!s) return;
132
- const c = ae(n, Z, "prstGeom");
133
- _(c, "prst", s.preset), me(n, c);
134
- const u = ae(c, Z, "avLst");
135
- ye(c, u);
136
- for (const f of Object.keys(s.adj)) {
137
- const d = s.adj[f], g = ae(u, Z, "gd");
138
- _(g, "name", f), _(g, "fmla", `val ${Math.round(d)}`), ye(u, g);
131
+ if (!r) return;
132
+ const i = ne(a, re, "prstGeom");
133
+ W(i, "prst", r.preset), ve(a, i);
134
+ const p = ne(i, re, "avLst");
135
+ oe(i, p);
136
+ for (const f of Object.keys(r.adj)) {
137
+ const u = r.adj[f], h = ne(p, re, "gd");
138
+ W(h, "name", f), W(h, "fmla", `val ${Math.round(u)}`), oe(p, h);
139
139
  }
140
140
  }
141
- function Jt(t, a, s, i, n) {
141
+ function fr(e, s, r, n, a) {
142
142
  var f;
143
- const c = a.meta.placeholderDirect ?? 0, u = !!(c & K.style);
144
- c & K.transform || He(t, a, s), (a.src.kind === "shape" || a.src.kind === "image") && !(c & K.geometry) && Vt(t, a, i, n), a.src.kind === "shape" && s.kind === "shape" ? (!u && !(c & K.fill) && Le(
145
- t,
146
- a,
147
- ((f = s.fill) == null ? void 0 : f.type) === "image" ? { type: "none" } : s.fill
148
- ), !u && !(c & K.stroke) && s.stroke && Ne(t, a, s.stroke)) : a.src.kind === "image" && s.kind === "image" && !u && !(c & K.stroke) && s.stroke && Ne(t, a, s.stroke), (a.src.kind === "shape" || a.src.kind === "image" || a.src.kind === "group") && !u && !(c & K.effects) && s.effects && Be(t, a, s.effects);
149
- }
150
- function Q(t, a, s) {
151
- return t && ne(t, {
152
- localName: a,
153
- ...s ? { namespaceUri: s } : {}
143
+ const i = s.meta.placeholderDirect ?? 0, p = !!(i & ee.style);
144
+ i & ee.transform || rt(e, s, r), (s.src.kind === "shape" || s.src.kind === "image") && !(i & ee.geometry) && pr(e, s, n, a), s.src.kind === "shape" && r.kind === "shape" ? (!p && !(i & ee.fill) && st(
145
+ e,
146
+ s,
147
+ ((f = r.fill) == null ? void 0 : f.type) === "image" ? { type: "none" } : r.fill
148
+ ), !p && !(i & ee.stroke) && r.stroke && Ge(e, s, r.stroke)) : s.src.kind === "image" && r.kind === "image" && !p && !(i & ee.stroke) && r.stroke && Ge(e, s, r.stroke), (s.src.kind === "shape" || s.src.kind === "image" || s.src.kind === "group") && !p && !(i & ee.effects) && r.effects && nt(e, s, r.effects);
149
+ }
150
+ function te(e, s, r) {
151
+ return e && ae(e, {
152
+ localName: s,
153
+ ...r ? { namespaceUri: r } : {}
154
154
  });
155
155
  }
156
- function de(t, a) {
157
- var s;
158
- return t ? ((s = Ae(t, { localName: a })) == null ? void 0 : s.value) ?? null : null;
156
+ function Se(e, s) {
157
+ var r;
158
+ return e ? ((r = Ae(e, { localName: s })) == null ? void 0 : r.value) ?? null : null;
159
159
  }
160
- function Kt(t) {
161
- const a = ee(t).find((n) => [
160
+ function ur(e) {
161
+ const s = D(e).find((a) => [
162
162
  "nvSpPr",
163
163
  "nvPicPr",
164
164
  "nvCxnSpPr",
165
165
  "nvGraphicFramePr"
166
- ].includes(n.localName)) ?? null, s = Q(Q(a, "nvPr", A), "ph", A);
167
- if (!s) return null;
168
- const i = de(s, "idx");
169
- return { type: de(s, "type") ?? "obj", ...i === null ? {} : { idx: i } };
170
- }
171
- function je(t, a) {
172
- if (!t) return;
173
- const s = Q(
174
- Q(t.root, "cSld", A),
166
+ ].includes(a.localName)) ?? null, r = te(te(s, "nvPr", L), "ph", L);
167
+ if (!r) return null;
168
+ const n = Se(r, "idx");
169
+ return { type: Se(r, "type") ?? "obj", ...n === null ? {} : { idx: n } };
170
+ }
171
+ function qe(e, s) {
172
+ if (!e) return;
173
+ const r = te(
174
+ te(e.root, "cSld", L),
175
175
  "spTree",
176
- A
176
+ L
177
177
  );
178
- if (!s) return;
179
- const i = Ut(
180
- ee(s).filter((c) => [
178
+ if (!r) return;
179
+ const n = ar(
180
+ D(r).filter((i) => [
181
181
  "sp",
182
182
  "pic",
183
183
  "cxnSp",
184
184
  "graphicFrame"
185
- ].includes(c.localName)),
186
- Kt,
187
- a
188
- ), n = i ? Q(i, "spPr", A) : null;
189
- return Q(n, "custGeom", Z) ?? Q(n, "prstGeom", Z) ?? void 0;
190
- }
191
- function Qt(t) {
192
- const a = /* @__PURE__ */ new Map(), s = (n) => {
193
- var c;
194
- if (!a.has(n)) {
195
- const u = (c = t.package) == null ? void 0 : c.parts[n];
196
- a.set(n, u ? D(u) : null);
185
+ ].includes(i.localName)),
186
+ ur,
187
+ s
188
+ ), a = n ? te(n, "spPr", L) : null;
189
+ return te(a, "custGeom", re) ?? te(a, "prstGeom", re) ?? void 0;
190
+ }
191
+ function mr(e) {
192
+ const s = /* @__PURE__ */ new Map(), r = (a) => {
193
+ var i;
194
+ if (!s.has(a)) {
195
+ const p = (i = e.package) == null ? void 0 : i.parts[a];
196
+ s.set(a, p ? I(p) : null);
197
197
  }
198
- return a.get(n) ?? null;
199
- }, i = (n) => {
200
- const c = s(E(n)), u = c && ee(c.root).find((d) => {
201
- var g;
202
- return d.localName === "Relationship" && ((g = de(d, "Type")) == null ? void 0 : g.endsWith("/slideMaster"));
203
- }), f = u ? de(u, "Target") : null;
204
- return f ? fe(n, f) : null;
198
+ return s.get(a) ?? null;
199
+ }, n = (a) => {
200
+ const i = r(T(a)), p = i && D(i.root).find((u) => {
201
+ var h;
202
+ return u.localName === "Relationship" && ((h = Se(u, "Type")) == null ? void 0 : h.endsWith("/slideMaster"));
203
+ }), f = p ? Se(p, "Target") : null;
204
+ return f ? se(a, f) : null;
205
205
  };
206
- return (n, c) => {
207
- const u = n.sourceLayoutId, f = c.meta.ph;
208
- if (!(!u || !f))
209
- return je(s(u), f) ?? (i(u) ? je(s(i(u)), f) : void 0);
206
+ return (a, i) => {
207
+ const p = a.sourceLayoutId, f = i.meta.ph;
208
+ if (!(!p || !f))
209
+ return qe(r(p), f) ?? (n(p) ? qe(r(n(p)), f) : void 0);
210
210
  };
211
211
  }
212
- function Yt(t) {
213
- return ue(t.ovr, "background") || ue(t.ovr, "transition");
212
+ const K = "ppt/presentation.xml", ke = T(K), Ee = "[Content_Types].xml", Ye = "http://schemas.openxmlformats.org/package/2006/relationships", $e = "http://schemas.openxmlformats.org/package/2006/content-types", Re = "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml", Ke = `${ue}/notesMaster`, Ie = `${ue}/slide`, dr = /^ppt\/notesMasters\/[^/]+\.xml$/, hr = {
213
+ bg1: "lt1",
214
+ tx1: "dk1",
215
+ bg2: "lt2",
216
+ tx2: "dk2",
217
+ accent1: "accent1",
218
+ accent2: "accent2",
219
+ accent3: "accent3",
220
+ accent4: "accent4",
221
+ accent5: "accent5",
222
+ accent6: "accent6",
223
+ hlink: "hlink",
224
+ folHlink: "folHlink"
225
+ }, J = (e, s) => {
226
+ var r;
227
+ return (r = Ae(e, { localName: s, namespaceUri: null })) == null ? void 0 : r.value;
228
+ };
229
+ function me(e) {
230
+ if (!e) return [];
231
+ const s = I(e).root;
232
+ if (s.namespaceUri !== Ye || s.localName !== "Relationships") throw new Error("备注保存关系部件的根命名空间无效");
233
+ return D(s, { localName: "Relationship", namespaceUri: Ye }).flatMap((r) => {
234
+ const n = J(r, "Id"), a = J(r, "Type"), i = J(r, "Target");
235
+ return n && a && i ? [{ id: n, type: a, target: i, external: J(r, "TargetMode") === "External" }] : [];
236
+ });
237
+ }
238
+ function we(e, s) {
239
+ const r = me(e).filter((n) => n.type.endsWith("/notesMaster"));
240
+ if (r.length > 1 || r.some((n) => n.external)) throw new Error(`备注母版关系不唯一或指向外部:${s}`);
241
+ return r[0] ? se(s, r[0].target) : void 0;
242
+ }
243
+ function Je(e, s, r, n) {
244
+ var i;
245
+ if (s[n] || r.has(n)) return;
246
+ const a = (i = e.package) == null ? void 0 : i.parts[n];
247
+ a ? s[n] = a.slice() : r.add(n);
248
+ }
249
+ function V(e, s, r) {
250
+ var n;
251
+ return s[r] ?? ((n = e.package) == null ? void 0 : n.parts[r]);
252
+ }
253
+ function gr(e, s, r) {
254
+ var q;
255
+ const n = e.slideOrder.map((c) => e.slides[c]).filter((c) => !!c.notes), a = n.filter((c) => fe(c.ovr, "notes") || r.has(c.notes.targetPart)), i = [...r].filter((c) => dr.test(c));
256
+ if (!a.length) return i.length ? { part: i[0], created: !0, linkPresentation: !0, slides: [] } : void 0;
257
+ const p = V(e, s, ke), f = we(p, K), u = new Set(n.flatMap((c) => {
258
+ const y = c.notes.sourcePart ?? c.notes.targetPart, E = we(V(e, s, T(y)), y);
259
+ return E ? [E] : [];
260
+ }));
261
+ if (u.size > 1 || f && [...u].some((c) => c !== f))
262
+ throw new Error("活动备注页引用了不同的备注母版,不能在保存时覆盖既有设计");
263
+ const h = V(e, s, Ee), P = h ? D(I(h).root, { localName: "Override", namespaceUri: $e }).filter((c) => J(c, "ContentType") === Re).flatMap((c) => {
264
+ var y;
265
+ return ((y = J(c, "PartName")) == null ? void 0 : y.replace(/^\//, "")) ?? [];
266
+ }) : [];
267
+ let g = f ?? [...u][0] ?? i[0];
268
+ if (!g && P.length === 1 && (g = P[0]), !g && P.length > 1) throw new Error("存在多个未绑定的备注母版,不能猜测应复用的设计");
269
+ const A = !g || i.includes(g);
270
+ if (!g) {
271
+ let c = 1;
272
+ do
273
+ g = `ppt/notesMasters/notesMaster${c++}.xml`;
274
+ while ((q = e.package) != null && q.parts[g] || r.has(g) || P.includes(g));
275
+ }
276
+ if (!A && !V(e, s, g)) throw new Error(`备注母版关系目标不存在:${g}`);
277
+ if (!A) {
278
+ const c = I(V(e, s, g)).root;
279
+ if (c.localName !== "notesMaster" || c.namespaceUri !== L) throw new Error(`备注母版目标不是标准 notesMaster:${g}`);
280
+ }
281
+ const X = V(e, s, K);
282
+ if (!X) throw new Error("备注保存缺少 ppt/presentation.xml");
283
+ const l = I(X).root, w = ae(l, { localName: "notesMasterIdLst", namespaceUri: l.namespaceUri }), M = w ? D(w, { localName: "notesMasterId", namespaceUri: l.namespaceUri }) : [], j = me(p);
284
+ if (M.length > 1 || M.some((c) => {
285
+ var C;
286
+ const y = (C = c.attributes.find((k) => {
287
+ var b;
288
+ return k.localName === "id" && ((b = k.namespaceUri) == null ? void 0 : b.endsWith("/relationships"));
289
+ })) == null ? void 0 : C.value, E = j.find((k) => k.id === y);
290
+ return !E || !E.type.endsWith("/notesMaster") || E.external || se(K, E.target) !== g;
291
+ })) throw new Error("presentation 的备注母版目录与关系目标不一致");
292
+ const U = A || !f || !M.length || !P.includes(g);
293
+ if (U) for (const c of [K, ke, Ee]) Je(e, s, r, c);
294
+ for (const c of a) {
295
+ const y = c.notes.targetPart, E = T(y), C = V(e, s, E);
296
+ (we(C, y) !== g || !me(C).some((k) => k.type === Ie && !k.external)) && Je(e, s, r, E);
297
+ }
298
+ let S;
299
+ if (A) {
300
+ r.add(g), r.add(T(g));
301
+ const c = a[0].layoutId ? e.layouts[a[0].layoutId] : void 0;
302
+ if (S = (c == null ? void 0 : c.themeId) ?? e.themeOrder[0], !S || !V(e, s, S)) throw new Error("新增备注母版缺少可读的主题来源");
303
+ }
304
+ return { part: g, created: A, linkPresentation: U, theme: S, slides: a };
305
+ }
306
+ function Pr() {
307
+ const e = I(`<p:notesMaster xmlns:p="${L}" xmlns:a="${re}" xmlns:r="${ue}"/>`), s = (i, p, f = {}) => {
308
+ const u = Ue(p, { attributes: Object.entries(f) });
309
+ return oe(i, u), u;
310
+ }, r = s(s(e.root, "p:cSld"), "p:spTree"), n = s(r, "p:nvGrpSpPr");
311
+ s(n, "p:cNvPr", { id: "1", name: "" }), s(n, "p:cNvGrpSpPr"), s(n, "p:nvPr");
312
+ const a = s(s(r, "p:grpSpPr"), "a:xfrm");
313
+ return s(a, "a:off", { x: "0", y: "0" }), s(a, "a:ext", { cx: "0", cy: "0" }), s(a, "a:chOff", { x: "0", y: "0" }), s(a, "a:chExt", { cx: "0", cy: "0" }), s(e.root, "p:clrMap", hr), s(e.root, "p:hf"), s(e.root, "p:notesStyle"), H(e);
214
314
  }
215
- function Zt(t, a) {
216
- if (ue(a.ovr, "transition") && kt(t, a.ovr.transition, !0), !ue(a.ovr, "background")) return;
217
- const s = a.ovr.background;
218
- Ue(s, `版式 ${a.id} 的背景覆盖`);
219
- const i = ne(t.root, {
315
+ function ye(e, s, r, n, a) {
316
+ const i = me(e), p = i.find((P) => P.type === r && !P.external && se(s, P.target) === n);
317
+ if (p) return { bytes: e, id: p.id };
318
+ const f = new Set(i.map((P) => P.id));
319
+ let u = a, h = 1;
320
+ for (; f.has(u); ) u = `${a}${h++}`;
321
+ return { id: u, bytes: be(e, [{
322
+ sourceId: u,
323
+ targetId: u,
324
+ type: r,
325
+ target: Ne(s, n)
326
+ }]) };
327
+ }
328
+ function yr(e, s) {
329
+ const r = I(e);
330
+ if (r.root.namespaceUri !== $e || r.root.localName !== "Types") throw new Error("备注保存缺少有效内容类型目录");
331
+ const n = D(r.root, { localName: "Override", namespaceUri: $e }).find((a) => J(a, "PartName") === `/${s}`);
332
+ if (n) {
333
+ if (J(n, "ContentType") !== Re) throw new Error(`备注母版 Content-Type 冲突:${s}`);
334
+ return e;
335
+ }
336
+ return oe(r.root, Ue("Override", { attributes: [
337
+ ["PartName", `/${s}`],
338
+ ["ContentType", Re]
339
+ ] })), H(r);
340
+ }
341
+ function wr(e, s, r, n) {
342
+ if (!(s != null && s.slides.length)) return;
343
+ const a = (i) => n[i] instanceof Uint8Array ? n[i] : V(e, r, i);
344
+ if (s.created && (n[s.part] = Pr(), n[T(s.part)] = ye(
345
+ void 0,
346
+ s.part,
347
+ `${ue}/theme`,
348
+ s.theme,
349
+ "rIdTheme"
350
+ ).bytes), s.linkPresentation) {
351
+ const i = ye(a(ke), K, Ke, s.part, "rIdNotesMaster");
352
+ n[ke] = i.bytes;
353
+ const p = I(a(K));
354
+ let f = ae(p.root, { localName: "notesMasterIdLst", namespaceUri: p.root.namespaceUri });
355
+ if (!f) {
356
+ f = ne(p.root, p.root.namespaceUri, "notesMasterIdLst");
357
+ const u = D(p.root).find((h) => h.namespaceUri === p.root.namespaceUri && h.localName !== "sldMasterIdLst");
358
+ oe(p.root, f, u ?? null);
359
+ }
360
+ if (!D(f, { localName: "notesMasterId", namespaceUri: p.root.namespaceUri }).length) {
361
+ const u = ne(f, p.root.namespaceUri, "notesMasterId");
362
+ W(u, "xmlns:r", ue), W(u, "r:id", i.id), oe(f, u);
363
+ }
364
+ n[K] = H(p), n[Ee] = yr(a(Ee), s.part);
365
+ }
366
+ for (const i of s.slides) {
367
+ const p = i.notes.targetPart, f = T(p), u = a(f), h = we(u, p);
368
+ if (h && h !== s.part) throw new Error(`备注页 ${p} 的母版与 presentation 不一致`);
369
+ let P = ye(u, p, Ke, s.part, "rIdNotesMaster").bytes;
370
+ if (!me(P).some((g) => g.type === Ie && !g.external)) {
371
+ if (!i.origin) throw new Error(`备注页 ${p} 缺少对应页面锚点`);
372
+ P = ye(P, p, Ie, i.origin.part, "rIdNotesSlide").bytes;
373
+ }
374
+ n[f] = P;
375
+ }
376
+ }
377
+ function vr(e) {
378
+ return fe(e.ovr, "background") || fe(e.ovr, "transition");
379
+ }
380
+ function Sr(e, s) {
381
+ if (fe(s.ovr, "transition") && Xt(e, s.ovr.transition, !0), !fe(s.ovr, "background")) return;
382
+ const r = s.ovr.background;
383
+ ot(r, `版式 ${s.id} 的背景覆盖`);
384
+ const n = ae(e.root, {
220
385
  localName: "cSld",
221
- namespaceUri: A
386
+ namespaceUri: L
222
387
  });
223
- if (!i) throw new Error(`版式 ${a.id} 缺少 p:cSld`);
224
- let n = ne(i, {
388
+ if (!n) throw new Error(`版式 ${s.id} 缺少 p:cSld`);
389
+ let a = ae(n, {
225
390
  localName: "bg",
226
- namespaceUri: A
391
+ namespaceUri: L
227
392
  });
228
- n || (n = ae(i, A, "bg"), me(i, n));
229
- for (const u of [...ee(n)])
230
- u.namespaceUri === A && u.localName === "bgRef" && ve(n, u);
231
- let c = ne(n, {
393
+ a || (a = ne(n, L, "bg"), ve(n, a));
394
+ for (const p of [...D(a)])
395
+ p.namespaceUri === L && p.localName === "bgRef" && Ce(a, p);
396
+ let i = ae(a, {
232
397
  localName: "bgPr",
233
- namespaceUri: A
398
+ namespaceUri: L
234
399
  });
235
- c || (c = ae(n, A, "bgPr"), me(n, c)), Ge(c), _e(c, s);
236
- }
237
- function es(t) {
238
- const a = /* @__PURE__ */ new Map();
239
- return t.slideOrder.forEach((s, i) => {
240
- var u;
241
- const n = t.slides[s], c = (u = n.origin) == null ? void 0 : u.part;
242
- c && n.dynamicSlideNumbers.some((f) => {
243
- var g;
244
- const d = t.elements[f];
245
- return ((g = d == null ? void 0 : d.meta.origin) == null ? void 0 : g.part) === c && gt(Ie(t, f));
246
- }) && a.set(c, i + 1);
247
- }), a;
248
- }
249
- function ts(t) {
250
- const a = /* @__PURE__ */ new Map();
251
- for (const s of Object.values(t.elements)) {
252
- if (!st(s) && !rt(s) && !at(s) && !nt(s) && !ot(s) && !it(s) && !ct(s) && !lt(s) && !pt(s) && !ft(s) && !ut(s) && !mt(s) && !Xe(s) && !dt(s) && s.meta.sourceParent === void 0 && !s.meta.insertion) continue;
253
- const i = s.meta.origin;
254
- if (!i) throw new Error(`元素 ${s.id} 缺少 OOXML 回写锚点`);
255
- const n = a.get(i.part) ?? [];
256
- n.push(s), a.set(i.part, n);
257
- }
258
- return a;
259
- }
260
- function ss(t) {
261
- const a = /* @__PURE__ */ new Map();
262
- for (const s of Object.values(t.removedElements)) {
263
- const i = s.meta.origin;
264
- if (!i) continue;
265
- const n = a.get(i.part) ?? [];
266
- n.push(s), a.set(i.part, n);
267
- }
268
- return a;
269
- }
270
- function rs(t) {
271
- var s;
272
- const a = /* @__PURE__ */ new Map();
273
- for (const i of Object.values(t.slides)) {
274
- if (!Ft(i)) continue;
275
- const n = (s = i.origin) == null ? void 0 : s.part;
276
- if (!n) throw new Error(`幻灯片 ${i.id} 缺少 OOXML 回写锚点`);
277
- a.set(n, i);
278
- }
279
- return a;
280
- }
281
- function as(t) {
282
- return new Map(t.layoutOrder.flatMap((a) => {
283
- const s = t.layouts[a];
284
- return Yt(s) ? [[s.origin.part, s]] : [];
400
+ i || (i = ne(a, L, "bgPr"), ve(a, i)), it(i), ct(i, r);
401
+ }
402
+ function kr(e) {
403
+ const s = /* @__PURE__ */ new Map();
404
+ return e.slideOrder.forEach((r, n) => {
405
+ var p;
406
+ const a = e.slides[r], i = (p = a.origin) == null ? void 0 : p.part;
407
+ i && a.dynamicSlideNumbers.some((f) => {
408
+ var h;
409
+ const u = e.elements[f];
410
+ return ((h = u == null ? void 0 : u.meta.origin) == null ? void 0 : h.part) === i && Ct(Ze(e, f));
411
+ }) && s.set(i, n + 1);
412
+ }), s;
413
+ }
414
+ function Er(e) {
415
+ const s = /* @__PURE__ */ new Map();
416
+ for (const r of Object.values(e.elements)) {
417
+ if (!wt(r) && !vt(r) && !St(r) && !kt(r) && !Et(r) && !xt(r) && !Ot(r) && !Tt(r) && !Mt(r) && !Nt(r) && !bt(r) && !$t(r) && !Qe(r) && !Rt(r) && r.meta.sourceParent === void 0 && !r.meta.insertion) continue;
418
+ const n = r.meta.origin;
419
+ if (!n) throw new Error(`元素 ${r.id} 缺少 OOXML 回写锚点`);
420
+ const a = s.get(n.part) ?? [];
421
+ a.push(r), s.set(n.part, a);
422
+ }
423
+ return s;
424
+ }
425
+ function xr(e) {
426
+ const s = /* @__PURE__ */ new Map();
427
+ for (const r of Object.values(e.removedElements)) {
428
+ const n = r.meta.origin;
429
+ if (!n) continue;
430
+ const a = s.get(n.part) ?? [];
431
+ a.push(r), s.set(n.part, a);
432
+ }
433
+ return s;
434
+ }
435
+ function Or(e) {
436
+ var r;
437
+ const s = /* @__PURE__ */ new Map();
438
+ for (const n of Object.values(e.slides)) {
439
+ if (!nr(n)) continue;
440
+ const a = (r = n.origin) == null ? void 0 : r.part;
441
+ if (!a) throw new Error(`幻灯片 ${n.id} 缺少 OOXML 回写锚点`);
442
+ s.set(a, n);
443
+ }
444
+ return s;
445
+ }
446
+ function Tr(e) {
447
+ return new Map(e.layoutOrder.flatMap((s) => {
448
+ const r = e.layouts[s];
449
+ return vr(r) ? [[r.origin.part, r]] : [];
285
450
  }));
286
451
  }
287
- function ns(t) {
288
- return new Map(t.masterOrder.flatMap((a) => {
289
- const s = t.masters[a];
290
- return ht(s) ? [[s.id, s]] : [];
452
+ function Mr(e) {
453
+ return new Map(e.masterOrder.flatMap((s) => {
454
+ const r = e.masters[s];
455
+ return It(r) ? [[r.id, r]] : [];
291
456
  }));
292
457
  }
293
- async function os(t) {
294
- var n;
295
- const a = ze();
296
- Pt(t);
297
- const s = /* @__PURE__ */ Object.create(null), i = /* @__PURE__ */ Object.create(null);
298
- for (const c of a.values()) {
299
- const u = await ((n = c.beforeSave) == null ? void 0 : n.call(c, t));
300
- if (u) {
301
- for (const [f, d] of Object.entries(u.changes)) {
302
- if (Object.prototype.hasOwnProperty.call(s, f))
458
+ async function Nr(e) {
459
+ var a;
460
+ const s = et();
461
+ Ut(e);
462
+ const r = /* @__PURE__ */ Object.create(null), n = /* @__PURE__ */ Object.create(null);
463
+ for (const i of s.values()) {
464
+ const p = await ((a = i.beforeSave) == null ? void 0 : a.call(i, e));
465
+ if (p) {
466
+ for (const [f, u] of Object.entries(p.changes)) {
467
+ if (Object.prototype.hasOwnProperty.call(r, f))
303
468
  throw new Error(`多个编辑扩展同时修改 OPC part:${f}`);
304
- s[f] = d;
469
+ r[f] = u;
305
470
  }
306
- for (const [f, d] of Object.entries(u.baselines)) {
307
- const g = i[f];
308
- if (g && (g.length !== d.length || !g.every((M, B) => M === d[B])))
471
+ for (const [f, u] of Object.entries(p.baselines)) {
472
+ const h = n[f];
473
+ if (h && (h.length !== u.length || !h.every((P, g) => P === u[g])))
309
474
  throw new Error(`多个编辑扩展的保存基线冲突:${f}`);
310
- i[f] = d;
475
+ n[f] = u;
311
476
  }
312
477
  }
313
478
  }
314
- return { changes: s, baselines: i };
479
+ return { changes: r, baselines: n };
315
480
  }
316
- async function is(t) {
317
- return cs(t, await os(t));
481
+ async function br(e) {
482
+ return $r(e, await Nr(e));
318
483
  }
319
- async function ds(t) {
320
- return t.meta.source === "pptx" && t.package && !t.package.disposed ? is(t) : (await import("./generate.js")).generateEditDoc(t);
484
+ async function jr(e) {
485
+ return e.meta.source === "pptx" && e.package && !e.package.disposed ? br(e) : (await import("./generate.js")).generateEditDoc(e);
321
486
  }
322
- function cs(t, a = { changes: {}, baselines: {} }) {
323
- var Se, ke, Oe, be, Ee;
324
- if (We(t), t.meta.readonly) throw new Error("只读编辑文档不能保存");
325
- if (t.meta.source !== "pptx" || !t.package)
487
+ function $r(e, s = { changes: {}, baselines: {} }) {
488
+ var Xe, _e, ze, De, He;
489
+ if (lt(e), e.meta.readonly) throw new Error("只读编辑文档不能保存");
490
+ if (e.meta.source !== "pptx" || !e.package)
326
491
  throw new Error("当前版本尚未实现生成式 PPTX 保存");
327
- const s = ts(t), i = rs(t), n = as(t), c = ns(t), u = new Set([...s].flatMap(([e, r]) => r.some(Xe) ? [e] : [])), f = ss(t), d = Ot(t), g = bt(t), M = new Map(Object.values(t.slides).flatMap((e) => e.layoutId !== e.sourceLayoutId && e.origin ? [[e.origin.part, e]] : [])), B = new Map(Object.values(t.slides).flatMap((e) => {
328
- const r = qe(t, e.id);
329
- return e.origin && r.length ? [[e.origin.part, r]] : [];
330
- })), U = new Map(Object.values(t.slides).flatMap((e) => e.origin ? [[e.origin.part, e]] : [])), F = Qt(t), o = Object.assign(
492
+ const r = Er(e), n = Or(e), a = Tr(e), i = Mr(e), p = new Set([...r].flatMap(([t, o]) => o.some(Qe) ? [t] : [])), f = xr(e), u = _t(e), h = zt(e), P = new Map(Object.values(e.slides).flatMap((t) => t.layoutId !== t.sourceLayoutId && t.origin ? [[t.origin.part, t]] : [])), g = new Map(Object.values(e.slides).flatMap((t) => {
493
+ const o = pt(e, t.id);
494
+ return t.origin && o.length ? [[t.origin.part, o]] : [];
495
+ })), A = new Map(Object.values(e.slides).flatMap((t) => t.origin ? [[t.origin.part, t]] : [])), X = mr(e), l = Object.assign(
331
496
  /* @__PURE__ */ Object.create(null),
332
- t.saveState.baselines,
333
- a.baselines
334
- ), P = new Set(t.saveState.createdParts), x = "[Content_Types].xml", j = "ppt/presentation.xml", R = "ppt/_rels/presentation.xml.rels", w = Et(t), te = t.themeOrder.filter((e) => Ve(t.themes[e]) || !!o[e]);
335
- for (const e of te) {
336
- if (o[e]) continue;
337
- const r = t.package.parts[e];
338
- if (!r) throw new Error(`找不到主题 OPC part:${e}`);
339
- o[e] = r.slice();
340
- }
341
- if (w != null && w.definitions.length && !o[w.part]) {
342
- const e = t.package.parts[w.part];
343
- if (e) o[w.part] = e.slice();
497
+ e.saveState.baselines,
498
+ s.baselines
499
+ ), w = new Set(e.saveState.createdParts), M = "[Content_Types].xml", j = "ppt/presentation.xml", U = "ppt/_rels/presentation.xml.rels", S = Dt(e), q = e.themeOrder.filter((t) => ft(e.themes[t]) || !!l[t]);
500
+ for (const t of q) {
501
+ if (l[t]) continue;
502
+ const o = e.package.parts[t];
503
+ if (!o) throw new Error(`找不到主题 OPC part:${t}`);
504
+ l[t] = o.slice();
505
+ }
506
+ if (S != null && S.definitions.length && !l[S.part]) {
507
+ const t = e.package.parts[S.part];
508
+ if (t) l[S.part] = t.slice();
344
509
  else {
345
- P.add(w.part);
346
- for (const r of [x, R]) {
347
- if (o[r]) continue;
348
- const l = t.package.parts[r];
349
- if (!l) throw new Error(`PPTX 缺少 ${r}`);
350
- o[r] = l.slice();
510
+ w.add(S.part);
511
+ for (const o of [M, U]) {
512
+ if (l[o]) continue;
513
+ const m = e.package.parts[o];
514
+ if (!m) throw new Error(`PPTX 缺少 ${o}`);
515
+ l[o] = m.slice();
351
516
  }
352
517
  }
353
518
  }
354
- const p = xt(t, o, P), k = g.length > 0 || [...P].some((e) => /^ppt\/slides\/slide\d+\.xml$/.test(e)), X = t.slideOrder.flatMap((e) => {
355
- var r;
356
- return ((r = t.slides[e].origin) == null ? void 0 : r.part) ?? [];
357
- }), N = Je(t, P), T = N.slideParts.size > 0, C = /* @__PURE__ */ new Set();
358
- if (T)
359
- for (const e of t.slideOrder) {
360
- const r = t.slides[e], l = (Se = r.origin) == null ? void 0 : Se.part;
361
- if (!l) continue;
362
- const h = E(l), I = o[h] ?? (r.creation ? pe(t, r, o) : void 0) ?? t.package.parts[h];
363
- Ke(t, l, I) && C.add(l);
519
+ const c = Ht(e, l, w), y = gr(e, l, w), E = h.length > 0 || [...w].some((t) => /^ppt\/slides\/slide\d+\.xml$/.test(t)), C = e.slideOrder.flatMap((t) => {
520
+ var o;
521
+ return ((o = e.slides[t].origin) == null ? void 0 : o.part) ?? [];
522
+ }), k = ut(e, w), b = k.slideParts.size > 0, $ = /* @__PURE__ */ new Set();
523
+ if (b)
524
+ for (const t of e.slideOrder) {
525
+ const o = e.slides[t], m = (Xe = o.origin) == null ? void 0 : Xe.part;
526
+ if (!m) continue;
527
+ const v = T(m), _ = l[v] ?? (o.creation ? Pe(e, o, l) : void 0) ?? e.package.parts[v];
528
+ mt(e, m, _) && $.add(m);
364
529
  }
365
- const S = /* @__PURE__ */ new Set([...u, ...C]), q = X.length !== t.saveState.sourceSlideParts.length || X.some((e, r) => e !== t.saveState.sourceSlideParts[r]), se = t.meta.width !== t.meta.sourceWidth || t.meta.height !== t.meta.sourceHeight || t.sections.edited, oe = k || T || q || se || !!o[j];
366
- if ((q || se) && !o[j]) {
367
- const e = t.package.parts[j];
368
- if (!e) throw new Error("PPTX 缺少 ppt/presentation.xml");
369
- o[j] = e.slice();
370
- }
371
- const V = oe ? es(t) : /* @__PURE__ */ new Map();
372
- for (const e of /* @__PURE__ */ new Set([
373
- ...s.keys(),
374
- ...i.keys(),
530
+ const F = /* @__PURE__ */ new Set([...p, ...$]), ce = C.length !== e.saveState.sourceSlideParts.length || C.some((t, o) => t !== e.saveState.sourceSlideParts[o]), le = e.meta.width !== e.meta.sourceWidth || e.meta.height !== e.meta.sourceHeight || e.sections.edited, de = E || b || ce || le || !!l[j];
531
+ if ((ce || le) && !l[j]) {
532
+ const t = e.package.parts[j];
533
+ if (!t) throw new Error("PPTX 缺少 ppt/presentation.xml");
534
+ l[j] = t.slice();
535
+ }
536
+ const Q = de ? kr(e) : /* @__PURE__ */ new Map();
537
+ for (const t of /* @__PURE__ */ new Set([
538
+ ...r.keys(),
375
539
  ...n.keys(),
376
- ...c.keys(),
540
+ ...a.keys(),
541
+ ...i.keys(),
377
542
  ...f.keys(),
378
- ...V.keys(),
379
- ...S,
380
- ...B.keys()
543
+ ...Q.keys(),
544
+ ...F,
545
+ ...g.keys()
381
546
  ])) {
382
- if (o[e] || g.some((l) => {
383
- var h;
384
- return ((h = l.origin) == null ? void 0 : h.part) === e;
547
+ if (l[t] || h.some((m) => {
548
+ var v;
549
+ return ((v = m.origin) == null ? void 0 : v.part) === t;
385
550
  })) continue;
386
- const r = t.package.parts[e];
387
- if (!r) throw new Error(`找不到待写回的 OPC part:${e}`);
388
- o[e] = r.slice();
389
- }
390
- for (const e of d.relationships.keys()) {
391
- const r = E(e);
392
- if (o[r] || P.has(r)) continue;
393
- const l = t.package.parts[r];
394
- l ? o[r] = l.slice() : P.add(r);
395
- }
396
- for (const e of S) {
397
- const r = E(e);
398
- if (o[r] || P.has(r)) continue;
399
- const l = t.package.parts[r];
400
- l ? o[r] = l.slice() : P.add(r);
401
- }
402
- for (const [e, r] of M) {
403
- if (r.creation) continue;
404
- const l = E(e);
405
- if (o[l] || P.has(l)) continue;
406
- const h = t.package.parts[l];
407
- h ? o[l] = h.slice() : P.add(l);
408
- }
409
- for (const e of N.packageParts) {
410
- if (P.has(e) || o[e]) continue;
411
- const r = t.package.parts[e];
412
- r && (o[e] = r.slice());
413
- }
414
- if ((d.resources.size || k || T || p.trackedParts.size) && !o[x]) {
415
- const e = t.package.parts[x];
416
- if (!e) throw new Error("PPTX 缺少 [Content_Types].xml");
417
- o[x] = e.slice();
418
- }
419
- if (k || T)
420
- for (const e of [j, R]) {
421
- if (o[e]) continue;
422
- const r = t.package.parts[e];
423
- if (!r) throw new Error(`PPTX 缺少 ${e}`);
424
- o[e] = r.slice();
551
+ const o = e.package.parts[t];
552
+ if (!o) throw new Error(`找不到待写回的 OPC part:${t}`);
553
+ l[t] = o.slice();
554
+ }
555
+ for (const t of u.relationships.keys()) {
556
+ const o = T(t);
557
+ if (l[o] || w.has(o)) continue;
558
+ const m = e.package.parts[o];
559
+ m ? l[o] = m.slice() : w.add(o);
560
+ }
561
+ for (const t of F) {
562
+ const o = T(t);
563
+ if (l[o] || w.has(o)) continue;
564
+ const m = e.package.parts[o];
565
+ m ? l[o] = m.slice() : w.add(o);
566
+ }
567
+ for (const [t, o] of P) {
568
+ if (o.creation) continue;
569
+ const m = T(t);
570
+ if (l[m] || w.has(m)) continue;
571
+ const v = e.package.parts[m];
572
+ v ? l[m] = v.slice() : w.add(m);
573
+ }
574
+ for (const t of k.packageParts) {
575
+ if (w.has(t) || l[t]) continue;
576
+ const o = e.package.parts[t];
577
+ o && (l[t] = o.slice());
578
+ }
579
+ if ((u.resources.size || E || b || c.trackedParts.size) && !l[M]) {
580
+ const t = e.package.parts[M];
581
+ if (!t) throw new Error("PPTX 缺少 [Content_Types].xml");
582
+ l[M] = t.slice();
583
+ }
584
+ if (E || b)
585
+ for (const t of [j, U]) {
586
+ if (l[t]) continue;
587
+ const o = e.package.parts[t];
588
+ if (!o) throw new Error(`PPTX 缺少 ${t}`);
589
+ l[t] = o.slice();
425
590
  }
426
- for (const e of g) {
427
- const r = e.origin.part;
428
- P.add(r), P.add(E(r));
591
+ for (const t of h) {
592
+ const o = t.origin.part;
593
+ w.add(o), w.add(T(o));
429
594
  }
430
- for (const e of d.resources.values())
431
- e.created && P.add(e.targetPart);
432
- const m = Object.assign(
595
+ for (const t of u.resources.values())
596
+ t.created && w.add(t.targetPart);
597
+ const d = Object.assign(
433
598
  /* @__PURE__ */ Object.create(null),
434
- a.changes
599
+ s.changes
435
600
  );
436
- for (const e of P) m[e] = null;
437
- for (const [e, r] of Object.entries(o))
438
- !t.package.parts[e] && !N.packageParts.has(e) && !P.has(e) && (m[e] = r);
439
- const $ = new Set(t.slideOrder.flatMap((e) => {
440
- var h;
441
- const r = t.slides[e], l = (h = r.origin) == null ? void 0 : h.part;
442
- return l && (o[l] || r.creation || V.has(l)) ? [l] : [];
443
- })), y = /* @__PURE__ */ new Map();
444
- for (const e of $) {
445
- const r = g.find((G) => {
446
- var Y;
447
- return ((Y = G.origin) == null ? void 0 : Y.part) === e;
448
- }), l = o[e] ?? (r ? _t(t, r, o) ?? Tt() : void 0);
449
- if (!l) throw new Error(`找不到页面保存基线:${e}`);
450
- const h = D(l), I = s.get(e) ?? [], b = E(e), H = o[b] ?? (r ? pe(t, r, o) : void 0), z = S.has(e) ? ge(
451
- t,
601
+ for (const t of w) d[t] = null;
602
+ for (const [t, o] of Object.entries(l))
603
+ !e.package.parts[t] && !k.packageParts.has(t) && !w.has(t) && (d[t] = o);
604
+ const N = new Set(e.slideOrder.flatMap((t) => {
605
+ var v;
606
+ const o = e.slides[t], m = (v = o.origin) == null ? void 0 : v.part;
607
+ return m && (l[m] || o.creation || Q.has(m)) ? [m] : [];
608
+ })), O = /* @__PURE__ */ new Map();
609
+ for (const t of N) {
610
+ const o = h.find((Y) => {
611
+ var ie;
612
+ return ((ie = Y.origin) == null ? void 0 : ie.part) === t;
613
+ }), m = l[t] ?? (o ? ir(e, o, l) ?? Ft() : void 0);
614
+ if (!m) throw new Error(`找不到页面保存基线:${t}`);
615
+ const v = I(m), _ = r.get(t) ?? [], R = T(t), B = l[R] ?? (o ? Pe(e, o, l) : void 0), z = F.has(t) ? Te(
452
616
  e,
453
- H,
454
- d.relationships.get(e) ?? []
617
+ t,
618
+ B,
619
+ u.relationships.get(t) ?? []
455
620
  ) : void 0;
456
- z && y.set(e, z), z == null || z.removeDanglingHyperlinks(h);
457
- const ce = [
458
- ...r ? Wt(r) : [],
459
- ...f.get(e) ?? []
621
+ z && O.set(t, z), z == null || z.removeDanglingHyperlinks(v);
622
+ const he = [
623
+ ...o ? cr(o) : [],
624
+ ...f.get(t) ?? []
460
625
  ];
461
- Pe(h, t, e, I, ce, { links: z });
462
- const le = ((ke = r == null ? void 0 : r.creation) == null ? void 0 : ke.duplicateRemovedAnimationSpids) ?? ((Oe = r == null ? void 0 : r.creation) == null ? void 0 : Oe.duplicateRemovedSpids) ?? [], he = (f.get(e) ?? []).flatMap((G) => G.sourceSpids ?? (G.meta.origin ? [G.meta.origin.spid] : []));
463
- Mt(h, [...le, ...he]);
464
- for (const G of B.get(e) ?? []) {
465
- const Y = t.elements[G], Te = U.get(e);
466
- Jt(
467
- h,
468
- Y,
469
- Ie(t, G),
470
- Qe(Y),
471
- Te ? F(Te, Y) : void 0
626
+ Me(v, e, t, _, he, { links: z });
627
+ const ge = ((_e = o == null ? void 0 : o.creation) == null ? void 0 : _e.duplicateRemovedAnimationSpids) ?? ((ze = o == null ? void 0 : o.creation) == null ? void 0 : ze.duplicateRemovedSpids) ?? [], Oe = (f.get(t) ?? []).flatMap((Y) => Y.sourceSpids ?? (Y.meta.origin ? [Y.meta.origin.spid] : []));
628
+ Bt(v, [...ge, ...Oe]);
629
+ for (const Y of g.get(t) ?? []) {
630
+ const ie = e.elements[Y], Be = A.get(t);
631
+ fr(
632
+ v,
633
+ ie,
634
+ Ze(e, Y),
635
+ dt(ie),
636
+ Be ? X(Be, ie) : void 0
472
637
  );
473
638
  }
474
- const re = i.get(e);
475
- re && Nt(h, t, re);
476
- const xe = W(h);
477
- m[e] = V.has(e) ? Ct(xe, V.get(e)) : xe;
478
- }
479
- const O = new Set(t.layoutOrder.filter((e) => o[e] || s.has(e) || f.has(e) || n.has(e)));
480
- for (const e of O) {
481
- const r = o[e];
482
- if (!r) throw new Error(`找不到版式保存基线:${e}`);
483
- const l = D(r), h = s.get(e) ?? [], I = o[E(e)], b = S.has(e) ? ge(
484
- t,
639
+ const pe = n.get(t);
640
+ pe && Gt(v, e, pe);
641
+ const Fe = H(v);
642
+ d[t] = Q.has(t) ? Wt(Fe, Q.get(t)) : Fe;
643
+ }
644
+ const Z = new Set(e.layoutOrder.filter((t) => l[t] || r.has(t) || f.has(t) || a.has(t)));
645
+ for (const t of Z) {
646
+ const o = l[t];
647
+ if (!o) throw new Error(`找不到版式保存基线:${t}`);
648
+ const m = I(o), v = r.get(t) ?? [], _ = l[T(t)], R = F.has(t) ? Te(
485
649
  e,
486
- I,
487
- d.relationships.get(e) ?? []
488
- ) : void 0;
489
- b && y.set(e, b), b == null || b.removeDanglingHyperlinks(l), Pe(l, t, e, h, f.get(e) ?? [], { links: b });
490
- const H = n.get(e);
491
- H && Zt(l, H), m[e] = W(l);
492
- }
493
- const J = new Set(t.masterOrder.filter((e) => o[e] || s.has(e) || f.has(e) || c.has(e)));
494
- for (const e of J) {
495
- const r = o[e];
496
- if (!r) throw new Error(`找不到母版保存基线:${e}`);
497
- const l = D(r), h = s.get(e) ?? [], I = o[E(e)], b = S.has(e) ? ge(
498
650
  t,
651
+ _,
652
+ u.relationships.get(t) ?? []
653
+ ) : void 0;
654
+ R && O.set(t, R), R == null || R.removeDanglingHyperlinks(m), Me(m, e, t, v, f.get(t) ?? [], { links: R });
655
+ const B = a.get(t);
656
+ B && Sr(m, B), d[t] = H(m);
657
+ }
658
+ const xe = new Set(e.masterOrder.filter((t) => l[t] || r.has(t) || f.has(t) || i.has(t)));
659
+ for (const t of xe) {
660
+ const o = l[t];
661
+ if (!o) throw new Error(`找不到母版保存基线:${t}`);
662
+ const m = I(o), v = r.get(t) ?? [], _ = l[T(t)], R = F.has(t) ? Te(
499
663
  e,
500
- I,
501
- d.relationships.get(e) ?? []
664
+ t,
665
+ _,
666
+ u.relationships.get(t) ?? []
502
667
  ) : void 0;
503
- b && y.set(e, b), b == null || b.removeDanglingHyperlinks(l), Pe(l, t, e, h, f.get(e) ?? [], { links: b });
504
- const H = c.get(e);
505
- H && Ye(l, H), m[e] = W(l);
506
- }
507
- const ie = /* @__PURE__ */ new Set();
508
- for (const e of /* @__PURE__ */ new Set([
509
- ...d.relationships.keys(),
510
- ...y.keys(),
511
- ...M.keys(),
512
- ...p.relationshipSlides.keys()
668
+ R && O.set(t, R), R == null || R.removeDanglingHyperlinks(m), Me(m, e, t, v, f.get(t) ?? [], { links: R });
669
+ const B = i.get(t);
670
+ B && ht(m, B), d[t] = H(m);
671
+ }
672
+ const je = /* @__PURE__ */ new Set();
673
+ for (const t of /* @__PURE__ */ new Set([
674
+ ...u.relationships.keys(),
675
+ ...O.keys(),
676
+ ...P.keys(),
677
+ ...c.relationshipSlides.keys()
513
678
  ])) {
514
- const r = d.relationships.get(e) ?? [], l = E(e);
515
- ie.add(l);
516
- const h = g.find((he) => {
517
- var re;
518
- return ((re = he.origin) == null ? void 0 : re.part) === e;
519
- }), I = o[l] ?? (h ? pe(t, h, o) : void 0), b = y.get(e), H = m[e];
520
- let z = b && H instanceof Uint8Array ? Ze(I, r, b, H) : Ce(I, r);
521
- const ce = M.get(e);
522
- ce && (z = Rt(ce, z));
523
- const le = p.relationshipSlides.get(e);
524
- le && (z = Re(le, z)), m[l] = z;
525
- }
526
- for (const [e, r] of Object.entries(o))
527
- e.endsWith(".rels") && !ie.has(e) && (m[e] = Ce(r, []));
528
- for (const [e, r] of d.resources) m[e] = $t(r);
529
- if (jt(t, o, p, m), o[x]) {
530
- const e = Xt(
531
- o[x],
532
- [...d.resources.values()]
679
+ const o = u.relationships.get(t) ?? [], m = T(t);
680
+ je.add(m);
681
+ const v = h.find((Oe) => {
682
+ var pe;
683
+ return ((pe = Oe.origin) == null ? void 0 : pe.part) === t;
684
+ }), _ = l[m] ?? (v ? Pe(e, v, l) : void 0), R = O.get(t), B = d[t];
685
+ let z = R && B instanceof Uint8Array ? gt(_, o, R, B) : be(_, o);
686
+ const he = P.get(t);
687
+ he && (z = Vt(he, z));
688
+ const ge = c.relationshipSlides.get(t);
689
+ ge && (z = We(ge, z)), d[m] = z;
690
+ }
691
+ for (const [t, o] of Object.entries(l))
692
+ t.endsWith(".rels") && !je.has(t) && (d[t] = be(o, []));
693
+ for (const [t, o] of u.resources) d[t] = qt(o);
694
+ if (Yt(e, l, c, d), l[M]) {
695
+ const t = Kt(
696
+ l[M],
697
+ [...u.resources.values()]
533
698
  );
534
- m[x] = It(
535
- e,
699
+ d[M] = Jt(
536
700
  t,
537
- N.contentTypeParts
701
+ e,
702
+ k.contentTypeParts
538
703
  );
539
704
  }
540
- for (const e of g) {
541
- const r = E(e.origin.part), l = m[r], h = l instanceof Uint8Array ? l : pe(t, e, o), I = (be = e.creation) != null && be.duplicateSourcePart ? h : zt(e, h);
542
- m[r] = Re(e, I);
705
+ for (const t of h) {
706
+ const o = T(t.origin.part), m = d[o], v = m instanceof Uint8Array ? m : Pe(e, t, l), _ = (De = t.creation) != null && De.duplicateSourcePart ? v : Qt(t, v);
707
+ d[o] = We(t, _);
543
708
  }
544
- if (o[j]) {
545
- const e = o[R] ?? t.package.parts[R];
546
- if (!e) throw new Error("PPTX 缺少 ppt/_rels/presentation.xml.rels");
547
- m[j] = At(
548
- o[j],
549
- e,
550
- t
709
+ if (l[j]) {
710
+ const t = l[U] ?? e.package.parts[U];
711
+ if (!t) throw new Error("PPTX 缺少 ppt/_rels/presentation.xml.rels");
712
+ d[j] = Zt(
713
+ l[j],
714
+ t,
715
+ e
551
716
  );
552
717
  }
553
- if (o[R] && (m[R] = Dt(
554
- o[R],
555
- t
556
- )), w != null && w.definitions.length && P.has(w.part)) {
557
- const e = m[x] ?? o[x], r = m[R] ?? o[R];
558
- if (!(e instanceof Uint8Array) || !(r instanceof Uint8Array))
718
+ if (l[U] && (d[U] = er(
719
+ l[U],
720
+ e
721
+ )), S != null && S.definitions.length && w.has(S.part)) {
722
+ const t = d[M] ?? l[M], o = d[U] ?? l[U];
723
+ if (!(t instanceof Uint8Array) || !(o instanceof Uint8Array))
559
724
  throw new Error("创建 tableStyles.xml 缺少 OPC 闭包基线");
560
- m[x] = Ht(e, w.part), m[R] = Lt(
561
- r,
562
- w.part
725
+ d[M] = tr(t, S.part), d[U] = rr(
726
+ o,
727
+ S.part
563
728
  );
564
729
  }
565
- for (const e of N.packageParts) m[e] = null;
566
- if (w) {
567
- const e = o[w.part];
568
- w.definitions.length ? m[w.part] = Bt(e, w.definitions) : e && (m[w.part] = e);
730
+ for (const t of k.packageParts) d[t] = null;
731
+ if (S) {
732
+ const t = l[S.part];
733
+ S.definitions.length ? d[S.part] = sr(t, S.definitions) : t && (d[S.part] = t);
569
734
  }
570
- for (const e of te)
571
- m[e] = et(o[e], t.themes[e]);
572
- Gt(t, g, o, P, m);
573
- for (const e of ze().values()) (Ee = e.materializePackage) == null || Ee.call(e, t, o, P, m);
574
- const we = St(t.package, m);
575
- return tt(t, we.package, o, [...P].sort()), we;
735
+ for (const t of q)
736
+ d[t] = Pt(l[t], e.themes[t]);
737
+ or(e, h, l, w, d);
738
+ for (const t of et().values()) (He = t.materializePackage) == null || He.call(t, e, l, w, d);
739
+ wr(e, y, l, d);
740
+ const Le = Lt(e.package, d);
741
+ return yt(e, Le.package, l, [...w].sort()), Le;
576
742
  }
577
743
  export {
578
- cs as saveEditDoc,
579
- is as saveEditDocWithExtensions,
580
- ds as serializeEditDoc
744
+ $r as saveEditDoc,
745
+ br as saveEditDocWithExtensions,
746
+ jr as serializeEditDoc
581
747
  };