@web-ppt/editor 0.5.0-beta.2 → 0.5.0-beta.7

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 (47) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +96 -5
  3. package/dist/accessibility.js +60 -0
  4. package/dist/adjustments/index.d.ts +2 -0
  5. package/dist/adjustments/preset-adjustment-editor.d.ts +4 -0
  6. package/dist/adjustments/types.d.ts +22 -0
  7. package/dist/adjustments.js +300 -0
  8. package/dist/canvas-accessibility.d.ts +6 -0
  9. package/dist/chart/index.d.ts +2 -0
  10. package/dist/chart-shared/index.d.ts +2 -0
  11. package/dist/chart-shared.js +7 -0
  12. package/dist/chart.js +6 -0
  13. package/dist/common-object-slide-commands.d.ts +20 -0
  14. package/dist/design/index.d.ts +3 -0
  15. package/dist/design-editor-types.d.ts +15 -0
  16. package/dist/design-editor.d.ts +3 -0
  17. package/dist/design.js +108 -0
  18. package/dist/dom-identity.d.ts +2 -1
  19. package/dist/edit-context/geometry.d.ts +8 -0
  20. package/dist/edit-context/index.d.ts +8 -0
  21. package/dist/edit-context/native.d.ts +33 -0
  22. package/dist/edit-context.js +333 -0
  23. package/dist/editor.js +1 -6706
  24. package/dist/element-clipboard.d.ts +4 -2
  25. package/dist/framework-adapter-types.d.ts +14 -2
  26. package/dist/image-insertion.d.ts +4 -2
  27. package/dist/index.d.ts +5 -4
  28. package/dist/media/index.d.ts +1 -0
  29. package/dist/media.js +1 -0
  30. package/dist/rotation-geometry.d.ts +4 -1
  31. package/dist/selection-hit.d.ts +6 -0
  32. package/dist/selection-pane-types.d.ts +1 -0
  33. package/dist/session-state.d.ts +5 -1
  34. package/dist/session.d.ts +17 -1
  35. package/dist/slide-dom-renderer.d.ts +1 -0
  36. package/dist/slide-editor-commands.d.ts +14 -2
  37. package/dist/slide-editor-events.d.ts +1 -0
  38. package/dist/slide-editor-types.d.ts +35 -2
  39. package/dist/slide-pointer-controller.d.ts +3 -0
  40. package/dist/templates/index.d.ts +2 -0
  41. package/dist/templates.js +5 -0
  42. package/dist/text-edit-commit.d.ts +8 -0
  43. package/dist/text-editor.d.ts +7 -3
  44. package/dist/text-keyboard.d.ts +2 -2
  45. package/dist/touch-gesture.d.ts +42 -0
  46. package/dist/transform-frame.d.ts +11 -6
  47. package/package.json +38 -6
@@ -0,0 +1,333 @@
1
+ import { composeSpaceMatrices as U, textPositionAtIndex as b, TEXT_ATOM as Y, textPositionToIndex as D, textBodyEditText as F, applyTextEditOps as Z, textBodyFromOverride as K } from "@web-ppt/edit-core";
2
+ import { renderTextBodyToHtml as tt } from "@web-ppt/core";
3
+ const et = (n, t) => ({ a: 1, b: 0, c: 0, d: 1, e: n, f: t });
4
+ function nt(n, t) {
5
+ var e, i;
6
+ const r = (e = n.rows[t.r]) == null ? void 0 : e.cells[t.c], o = (r == null ? void 0 : r.text) ?? ((i = r == null ? void 0 : r.editInfo) == null ? void 0 : i.textTemplate);
7
+ return !r || r.merged || !o ? null : {
8
+ cell: r,
9
+ text: o,
10
+ x: n.colWidths.slice(0, t.c).reduce((l, c) => l + c, 0),
11
+ y: n.rows.slice(0, t.r).reduce((l, c) => l + c.height, 0),
12
+ width: n.colWidths.slice(t.c, t.c + r.colSpan).reduce((l, c) => l + c, 0) || n.colWidths[t.c] || 0,
13
+ height: n.rows.slice(t.r, t.r + r.rowSpan).reduce((l, c) => l + c.height, 0) || n.rows[t.r].height
14
+ };
15
+ }
16
+ function rt(n, t, r) {
17
+ const o = n.doc.elements[t];
18
+ if (!o || o.meta.editable !== "full") return null;
19
+ const e = n.renderedElement(t);
20
+ if (!r) {
21
+ const c = e.kind === "shape" ? e.text ?? o.meta.textTemplate : null;
22
+ return e.kind === "shape" && c ? {
23
+ id: t,
24
+ text: c,
25
+ width: e.w,
26
+ height: e.h,
27
+ matrix: n.renderedFrameToSlideMatrix(t)
28
+ } : null;
29
+ }
30
+ if (e.kind !== "table") return null;
31
+ const i = nt(e, r);
32
+ if (!i) return null;
33
+ const l = n.renderedContentToSlideMatrix(t);
34
+ return {
35
+ id: t,
36
+ cell: { ...r },
37
+ text: i.text,
38
+ width: i.width,
39
+ height: i.height,
40
+ matrix: U(l, et(i.x, i.y)),
41
+ ...i.cell.margins ? { insets: i.cell.margins } : {},
42
+ ...i.cell.vAlign ? { anchor: i.cell.vAlign } : {},
43
+ ...i.cell.vert ? { vert: i.cell.vert } : {}
44
+ };
45
+ }
46
+ function H(n) {
47
+ if (n.nodeType === n.TEXT_NODE) return { valid: !0, text: n.nodeValue ?? "" };
48
+ if (n.nodeType !== n.ELEMENT_NODE) return { valid: !0, text: "" };
49
+ const t = n;
50
+ if (t.hasAttribute("data-bullet")) return { valid: !0, text: "" };
51
+ if (t.localName === "svg" && t.hasAttribute("data-r"))
52
+ return { valid: !0, text: Y };
53
+ if (t.localName === "br") return { valid: !0, text: `
54
+ ` };
55
+ let r = "";
56
+ for (const o of t.childNodes) {
57
+ const e = H(o);
58
+ if (!e.valid) return e;
59
+ r += e.text;
60
+ }
61
+ return t.dataset.empty === "true" && r.startsWith(" ") && (r = r.slice(1)), { valid: !0, text: r };
62
+ }
63
+ function ot(n) {
64
+ const t = [...n.querySelectorAll("[data-p]")].filter((o) => {
65
+ var e;
66
+ return !((e = o.parentElement) != null && e.closest("[data-p]"));
67
+ }), r = [];
68
+ for (const o of t) {
69
+ let e = "";
70
+ for (const i of o.childNodes) {
71
+ const l = H(i);
72
+ if (!l.valid) return l;
73
+ e += l.text;
74
+ }
75
+ r.push(e);
76
+ }
77
+ return { valid: !0, text: r.join(`
78
+ `) };
79
+ }
80
+ function j(n, t, r) {
81
+ const o = n.ownerDocument.createRange();
82
+ try {
83
+ o.setStart(n, 0), o.setEnd(t, r);
84
+ } catch {
85
+ return null;
86
+ }
87
+ const e = ot(o.cloneContents());
88
+ return e.valid ? e.text.length : null;
89
+ }
90
+ function X(n, t) {
91
+ var l;
92
+ const r = (l = n.ownerDocument.defaultView) == null ? void 0 : l.getSelection();
93
+ if (!(r != null && r.rangeCount)) return null;
94
+ const o = r.getRangeAt(0);
95
+ if (!n.contains(o.commonAncestorContainer) && o.commonAncestorContainer !== n) return null;
96
+ const e = j(n, o.startContainer, o.startOffset), i = j(n, o.endContainer, o.endOffset);
97
+ return e === null || i === null ? null : {
98
+ from: b(t, e),
99
+ to: b(t, i)
100
+ };
101
+ }
102
+ function G(n, t) {
103
+ var o;
104
+ let r = t;
105
+ for (let e = 0; e < n.childNodes.length; e++) {
106
+ const i = n.childNodes[e];
107
+ if (i.nodeType === i.TEXT_NODE) {
108
+ const c = n.dataset.empty === "true" && i.nodeValue === " " ? 0 : ((o = i.nodeValue) == null ? void 0 : o.length) ?? 0;
109
+ if (r <= c) return { node: i, offset: Math.min(r, c) };
110
+ r -= c;
111
+ continue;
112
+ }
113
+ const l = H(i);
114
+ if (l.valid) {
115
+ if (r <= l.text.length)
116
+ return i instanceof Element && !["br", "svg"].includes(i.localName) ? G(i, r) : { node: n, offset: e + (r ? 1 : 0) };
117
+ r -= l.text.length;
118
+ }
119
+ }
120
+ return { node: n, offset: n.childNodes.length };
121
+ }
122
+ function O(n, t, r = "edit") {
123
+ const o = r === "edit" ? "data-r" : "data-ppt-search-r", e = [...n.querySelectorAll(
124
+ `[${o}="${t.p}.${t.r}"]`
125
+ )];
126
+ if (!e.length) return null;
127
+ const i = r === "edit" ? "from" : "pptSearchFrom", l = r === "edit" ? "to" : "pptSearchTo", c = e.filter((g) => g.dataset[i] !== void 0 && g.dataset[l] !== void 0), m = c.find((g) => {
128
+ const s = Number(g.dataset[i]), y = Number(g.dataset[l]);
129
+ return t.off >= s && t.off < y;
130
+ }) ?? [...c].reverse().find(
131
+ (g) => t.off === Number(g.dataset[l])
132
+ ) ?? e[0], w = Number(m.dataset[i] ?? 0), x = Math.max(0, t.off - w);
133
+ if (m.localName === "svg") {
134
+ const g = m.parentNode;
135
+ if (!g) return null;
136
+ const s = [...g.childNodes].indexOf(m);
137
+ return { node: g, offset: s + (x ? 1 : 0) };
138
+ }
139
+ return G(m, x);
140
+ }
141
+ function it(n, t) {
142
+ let r = 0;
143
+ for (; r < n.length && r < t.length && n[r] === t[r]; ) r++;
144
+ let o = 0;
145
+ for (; o < n.length - r && o < t.length - r && n[n.length - 1 - o] === t[t.length - 1 - o]; ) o++;
146
+ return { from: r, to: n.length - o, text: t.slice(r, t.length - o) };
147
+ }
148
+ function lt(n, t, r, o) {
149
+ const e = n.slice(0, r), i = n.slice(o);
150
+ return t.length < e.length + i.length || !t.startsWith(e) || !t.endsWith(i) ? null : { from: r, to: o, text: t.slice(e.length, t.length - i.length) };
151
+ }
152
+ function st(n, t, r, o) {
153
+ if (n === t) return { from: r, to: o };
154
+ const e = it(n, t);
155
+ if (e.to <= r) {
156
+ const i = e.text.length - (e.to - e.from);
157
+ return { from: r + i, to: o + i };
158
+ }
159
+ return e.from >= o ? { from: r, to: o } : null;
160
+ }
161
+ function ct(n, t, r, o) {
162
+ const e = n.createElement("div");
163
+ e.dataset.pptTextEditor = t.id, t.cell && (e.dataset.pptTextCell = `${t.cell.r}:${t.cell.c}`), e.setAttribute("contenteditable", "true"), e.setAttribute("role", "textbox"), e.setAttribute("aria-multiline", "true"), e.spellcheck = !1, e.style.position = "absolute", e.style.left = "0", e.style.top = "0", e.style.width = `${t.width}px`, e.style.height = `${t.height}px`, e.style.transformOrigin = "0 0";
164
+ const { matrix: i } = t;
165
+ e.style.transform = `matrix(${i.a},${i.b},${i.c},${i.d},${i.e},${i.f})`, e.style.pointerEvents = "auto", e.style.outline = "none", e.innerHTML = tt(t.text, t.width, t.height, {
166
+ includeEditMarkers: !0,
167
+ layout: r,
168
+ scale: o,
169
+ ...t.insets ? { insets: t.insets } : {},
170
+ ...t.anchor ? { anchor: t.anchor } : {},
171
+ ...t.vert ? { vert: t.vert } : {}
172
+ });
173
+ for (const l of e.querySelectorAll("svg[data-r]"))
174
+ l.contentEditable = "false";
175
+ return e;
176
+ }
177
+ function q(n, t, r) {
178
+ var c;
179
+ const o = O(n, t), e = O(n, r), i = (c = n.ownerDocument.defaultView) == null ? void 0 : c.getSelection();
180
+ if (!o || !e || !i) return;
181
+ const l = n.ownerDocument.createRange();
182
+ l.setStart(o.node, o.offset), l.setEnd(e.node, e.offset), i.removeAllRanges(), i.addRange(l);
183
+ }
184
+ function at(n) {
185
+ return n.replace(/\r\n?/g, `
186
+ `).replace(/\u00a0/g, " ").replace(/\uFFFC/g, "");
187
+ }
188
+ function ut(n) {
189
+ return {
190
+ paragraphs: at(n).split(`
191
+ `).map((t) => ({
192
+ text: t,
193
+ marks: t ? [{ from: 0, to: t.length, props: {} }] : []
194
+ }))
195
+ };
196
+ }
197
+ function J(n, t, r, o) {
198
+ const e = O(n, b(t, r)), i = O(n, b(t, o));
199
+ if (!e || !i) return null;
200
+ const l = n.ownerDocument.createRange();
201
+ return l.setStart(e.node, e.offset), l.setEnd(i.node, i.offset), l;
202
+ }
203
+ function z(n, t, r, o) {
204
+ const e = J(n, t, r, o);
205
+ return e && typeof e.getBoundingClientRect == "function" ? e.getBoundingClientRect() : n.getBoundingClientRect();
206
+ }
207
+ let dt = 0;
208
+ function ft(n) {
209
+ const t = n.ownerDocument.defaultView, r = [], o = `webppt-ime-${++dt}-`, e = n.ownerDocument.createElement("style");
210
+ n.ownerDocument.head.append(e);
211
+ const i = () => {
212
+ r.forEach((l) => {
213
+ var c, m;
214
+ return (m = (c = t.CSS) == null ? void 0 : c.highlights) == null ? void 0 : m.delete(l);
215
+ }), r.length = 0, e.textContent = "";
216
+ };
217
+ return {
218
+ update(l, c) {
219
+ var w;
220
+ if (i(), !t.Highlight || !((w = t.CSS) != null && w.highlights)) return;
221
+ const m = [];
222
+ c.forEach((x, g) => {
223
+ const s = J(n, l, x.rangeStart, x.rangeEnd);
224
+ if (!s || x.underlineThickness === "none") return;
225
+ const y = `${o}${g}`, S = ["solid", "dotted", "dashed", "wavy"].includes(x.underlineStyle) ? x.underlineStyle : "solid";
226
+ t.CSS.highlights.set(y, new t.Highlight(s)), r.push(y), m.push(`::highlight(${y}){text-decoration:underline ${S};text-decoration-thickness:${x.underlineThickness === "thick" ? "2px" : "1px"}}`);
227
+ }), e.textContent = m.join("");
228
+ },
229
+ dispose() {
230
+ i(), e.remove();
231
+ }
232
+ };
233
+ }
234
+ function gt(n, t) {
235
+ const r = t.element.ownerDocument, o = r.defaultView, e = o.EditContext;
236
+ if (!e) return { supported: !1, dispose() {
237
+ } };
238
+ const i = t.element.querySelector("[data-ppt-layer=text]");
239
+ let l = null, c, m = !1;
240
+ const w = (s) => {
241
+ var W;
242
+ const y = (W = s.dataset.pptTextCell) == null ? void 0 : W.split(":").map(Number), S = () => rt(n.editor, s.dataset.pptTextEditor, y ? { r: y[0], c: y[1] } : null), L = S();
243
+ if (!L) return () => {
244
+ };
245
+ let f = L.text, A = !1, v = !1, C = null;
246
+ const $ = X(s, f), p = new e({
247
+ text: F(f),
248
+ selectionStart: $ ? D(f, $.from) : 0,
249
+ selectionEnd: $ ? D(f, $.to) : 0
250
+ }), P = ft(s), V = new o.AbortController(), E = (d, a, u, h = !1) => d.addEventListener(a, u, { signal: V.signal, capture: h }), M = () => {
251
+ v || !s.isConnected || (p.updateControlBounds(s.getBoundingClientRect()), p.updateSelectionBounds(z(s, f, p.selectionStart, p.selectionEnd)));
252
+ }, T = () => {
253
+ if (v || A) return;
254
+ const d = S();
255
+ if (!d) return;
256
+ f = d.text;
257
+ const a = F(f), u = X(s, f);
258
+ p.text !== a && p.updateText(0, p.text.length, a), u && p.updateSelection(D(f, u.from), D(f, u.to)), M();
259
+ }, I = (d, a, u) => {
260
+ const h = i.querySelector("[data-ppt-text-editor]"), N = S();
261
+ if (!(!h || h.dataset.pptTextEditor !== s.dataset.pptTextEditor || !N))
262
+ if (q(h, b(N.text, d), b(N.text, a)), u.includes(`
263
+ `)) {
264
+ const R = new o.Event("paste", { bubbles: !0, cancelable: !0 });
265
+ Object.defineProperty(R, "clipboardData", { value: { getData: (k) => k === "text/plain" ? u : "" } }), h.dispatchEvent(R);
266
+ } else h.dispatchEvent(new o.InputEvent("beforeinput", { bubbles: !0, cancelable: !0, inputType: "insertText", data: u }));
267
+ };
268
+ E(p, "compositionstart", () => {
269
+ T(), A = !0, C = { text: p.text, markup: s.innerHTML, from: p.selectionStart, to: p.selectionEnd }, s.dispatchEvent(new o.CompositionEvent("compositionstart", { bubbles: !0 }));
270
+ }), E(p, "textupdate", (d) => {
271
+ var k;
272
+ if (v || !s.isConnected) return;
273
+ const a = d;
274
+ if (!A) {
275
+ I(a.updateRangeStart, a.updateRangeEnd, a.text);
276
+ const _ = i.querySelector("[data-ppt-text-editor]"), B = S();
277
+ _ && B && q(
278
+ _,
279
+ b(B.text, a.selectionStart),
280
+ b(B.text, a.selectionEnd)
281
+ );
282
+ return;
283
+ }
284
+ const u = Z(f, [{
285
+ type: "replaceFragment",
286
+ from: b(f, a.updateRangeStart),
287
+ to: b(f, a.updateRangeEnd),
288
+ fragment: ut(a.text)
289
+ }]);
290
+ if (u.kind !== "flat") return;
291
+ f = K(u);
292
+ const h = S();
293
+ if (!h) return;
294
+ const N = s.querySelector("[data-layout=engine]") ? "engine" : "browser", R = Number(((k = s.querySelector("[data-font-scale]")) == null ? void 0 : k.dataset.fontScale) ?? 1);
295
+ s.innerHTML = ct(r, { ...h, text: f }, N, R).innerHTML, q(s, b(f, a.selectionStart), b(f, a.selectionEnd)), M();
296
+ }), E(p, "compositionend", () => {
297
+ if (v || !C) return;
298
+ const d = C, a = S();
299
+ C = null, A = !1;
300
+ const u = lt(d.text, F(f), d.from, d.to), h = u && a ? st(d.text, F(a.text), u.from, u.to) : null;
301
+ if (!(u != null && u.text.includes(`
302
+ `))) {
303
+ s.dispatchEvent(new o.CompositionEvent("compositionend", { bubbles: !0 }));
304
+ return;
305
+ }
306
+ s.innerHTML = d.markup, s.dispatchEvent(new o.CompositionEvent("compositionend", { bubbles: !0 })), u && h && (u.from !== u.to || u.text) && I(h.from, h.to, u.text), T();
307
+ }), E(p, "characterboundsupdate", (d) => {
308
+ const a = d;
309
+ p.updateCharacterBounds(a.rangeStart, Array.from(
310
+ { length: Math.max(0, Math.min(p.text.length, a.rangeEnd) - a.rangeStart) },
311
+ (u, h) => z(s, f, a.rangeStart + h, a.rangeStart + h + 1)
312
+ ));
313
+ }), E(p, "textformatupdate", (d) => {
314
+ P.update(f, d.getTextFormats());
315
+ }), E(s, "beforeinput", (d) => {
316
+ d.isTrusted && /^(insertText|insertCompositionText|deleteContentBackward|deleteContentForward)$/.test(d.inputType) && d.stopImmediatePropagation();
317
+ }, !0), E(r, "selectionchange", T), E(s, "keydown", () => o.queueMicrotask(T)), E(s, "keyup", T), E(s, "pointerup", T);
318
+ const Q = n.editor.subscribe(() => o.queueMicrotask(T));
319
+ return E(o, "scroll", M, !0), E(o, "resize", M), s.editContext = p, T(), () => {
320
+ v = !0, Q(), V.abort(), P.dispose(), s.editContext = null, C && s.isConnected && (s.innerHTML = C.markup, s.dispatchEvent(new o.CompositionEvent("compositionend", { bubbles: !0 })));
321
+ };
322
+ }, x = () => {
323
+ if (m) return;
324
+ const s = i.querySelector("[data-ppt-text-editor]");
325
+ s !== l && (c == null || c(), l = s, c = s ? w(s) : void 0);
326
+ }, g = new o.MutationObserver(x);
327
+ return g.observe(i, { childList: !0 }), x(), { supported: !0, dispose() {
328
+ m = !0, g.disconnect(), c == null || c(), l = null;
329
+ } };
330
+ }
331
+ export {
332
+ gt as enableEditContext
333
+ };