@fileverse-dev/ddoc 6.0.1 → 6.0.3

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.
@@ -1,313 +0,0 @@
1
- import * as d from "yjs";
2
- const T = typeof Buffer == "function";
3
- typeof TextDecoder == "function" && new TextDecoder();
4
- typeof TextEncoder == "function" && new TextEncoder();
5
- const N = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", m = Array.prototype.slice.call(N), h = ((e) => {
6
- let t = {};
7
- return e.forEach((r, n) => t[r] = n), t;
8
- })(m), z = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/, y = String.fromCharCode.bind(String), M = typeof Uint8Array.from == "function" ? Uint8Array.from.bind(Uint8Array) : (e) => new Uint8Array(Array.prototype.slice.call(e, 0)), I = (e) => e.replace(/=/g, "").replace(/[+\/]/g, (t) => t == "+" ? "-" : "_"), v = (e) => e.replace(/[^A-Za-z0-9\+\/]/g, ""), L = (e) => {
9
- let t, r, n, s, i = "";
10
- const o = e.length % 3;
11
- for (let f = 0; f < e.length; ) {
12
- if ((r = e.charCodeAt(f++)) > 255 || (n = e.charCodeAt(f++)) > 255 || (s = e.charCodeAt(f++)) > 255)
13
- throw new TypeError("invalid character found");
14
- t = r << 16 | n << 8 | s, i += m[t >> 18 & 63] + m[t >> 12 & 63] + m[t >> 6 & 63] + m[t & 63];
15
- }
16
- return o ? i.slice(0, o - 3) + "===".substring(o) : i;
17
- }, K = typeof btoa == "function" ? (e) => btoa(e) : T ? (e) => Buffer.from(e, "binary").toString("base64") : L, w = T ? (e) => Buffer.from(e).toString("base64") : (e) => {
18
- let r = [];
19
- for (let n = 0, s = e.length; n < s; n += 4096)
20
- r.push(y.apply(null, e.subarray(n, n + 4096)));
21
- return K(r.join(""));
22
- }, k = (e, t = !1) => t ? I(w(e)) : w(e), x = (e) => {
23
- if (e = e.replace(/\s+/g, ""), !z.test(e))
24
- throw new TypeError("malformed base64.");
25
- e += "==".slice(2 - (e.length & 3));
26
- let t, r, n, s = [];
27
- for (let i = 0; i < e.length; )
28
- t = h[e.charAt(i++)] << 18 | h[e.charAt(i++)] << 12 | (r = h[e.charAt(i++)]) << 6 | (n = h[e.charAt(i++)]), r === 64 ? s.push(y(t >> 16 & 255)) : n === 64 ? s.push(y(t >> 16 & 255, t >> 8 & 255)) : s.push(y(t >> 16 & 255, t >> 8 & 255, t & 255));
29
- return s.join("");
30
- }, Z = typeof atob == "function" ? (e) => atob(v(e)) : T ? (e) => Buffer.from(e, "base64").toString("binary") : x, P = T ? (e) => M(Buffer.from(e, "base64")) : (e) => M(Z(e).split("").map((t) => t.charCodeAt(0))), B = (e) => P(V(e)), V = (e) => v(e.replace(/[-_]/g, (t) => t == "-" ? "+" : "/")), D = "default", b = "Tab 1", W = "ddocTabs", X = "tabs_order", G = "tabs_name_registry", q = "tabs_emoji_registry", J = "tabs_state", $ = "tabs_delete_registry", j = "activeTabId";
31
- function g(e) {
32
- return {
33
- order: e.getArray(X),
34
- nameById: e.getMap(G),
35
- emojiById: e.getMap(q),
36
- tabState: e.getMap(J),
37
- // Soft-deleted tabs keep their fragment for undo and late peer updates.
38
- // This tombstone stops self-heal from resurrecting deleted tabs from stale tab metadata.
39
- deletedById: e.getMap($)
40
- };
41
- }
42
- function E(e, t) {
43
- if (e)
44
- try {
45
- if (Array.isArray(e)) {
46
- const r = e.map((n) => B(n));
47
- d.applyUpdate(t, d.mergeUpdates(r), "self");
48
- return;
49
- }
50
- d.applyUpdate(t, B(e), "self");
51
- } catch (r) {
52
- console.log(r);
53
- }
54
- }
55
- function A(e) {
56
- return e ? e.toArray().filter((t) => typeof t == "string") : [];
57
- }
58
- function H(e) {
59
- const t = e.getMap(W), r = t.get("order"), n = t.get("tabs"), s = t.get("activeTabId"), i = A(
60
- r instanceof d.Array ? r : null
61
- ), o = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
62
- return n instanceof d.Map && n.forEach((u, a) => {
63
- if (!(u instanceof d.Map) || typeof a != "string") return;
64
- const c = u.get("name"), l = u.get("emoji");
65
- typeof c == "string" && o.set(a, c), (typeof l == "string" || l === null) && f.set(a, l);
66
- }), {
67
- order: i,
68
- names: o,
69
- emojis: f,
70
- activeTabId: s instanceof d.Text && s.toString() || null,
71
- deletedIds: /* @__PURE__ */ new Set(),
72
- hasData: i.length > 0 || o.size > 0 || f.size > 0 || s instanceof d.Text && s.length > 0
73
- };
74
- }
75
- function Q(e) {
76
- const t = g(e), r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Set();
77
- t.nameById.forEach((f, u) => {
78
- typeof f == "string" && r.set(u, f);
79
- }), t.emojiById.forEach((f, u) => {
80
- (typeof f == "string" || f === null) && n.set(u, f);
81
- }), t.deletedById.forEach((f, u) => {
82
- f === !0 && s.add(u);
83
- });
84
- const i = t.tabState.get(j), o = typeof i == "string" ? i : null;
85
- return {
86
- order: A(t.order),
87
- names: r,
88
- emojis: n,
89
- activeTabId: o,
90
- deletedIds: s,
91
- hasData: t.order.length > 0 || t.nameById.size > 0 || t.emojiById.size > 0 || t.deletedById.size > 0 || o !== null
92
- };
93
- }
94
- function U(e) {
95
- const t = /* @__PURE__ */ new Set(), r = [];
96
- return e.forEach((n) => {
97
- t.has(n) || (t.add(n), r.push(n));
98
- }), r;
99
- }
100
- function O(e) {
101
- return e === 0 ? b : `Tab ${e + 1}`;
102
- }
103
- function ee(e, t) {
104
- return U([
105
- ...e.order,
106
- ...t.order,
107
- ...Array.from(e.names.keys()),
108
- ...Array.from(e.emojis.keys()),
109
- ...Array.from(t.names.keys()),
110
- ...Array.from(t.emojis.keys())
111
- ]);
112
- }
113
- function te(e, t) {
114
- const r = new Set(e.deletedIds);
115
- t.forEach((a) => {
116
- a.deletedIds.forEach((c) => r.add(c));
117
- });
118
- const n = /* @__PURE__ */ new Set(), s = [];
119
- e.order.forEach((a) => {
120
- !r.has(a) && !n.has(a) && (n.add(a), s.push(a));
121
- });
122
- const i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
123
- e.names.forEach((a, c) => {
124
- r.has(c) || i.set(c, a);
125
- }), e.emojis.forEach((a, c) => {
126
- r.has(c) || o.set(c, a);
127
- }), t.forEach((a) => {
128
- a.order.forEach((c) => {
129
- r.has(c) || (n.has(c) || (n.add(c), s.push(c)), !i.has(c) && a.names.has(c) && i.set(c, a.names.get(c) ?? b), o.has(c) || o.set(
130
- c,
131
- a.emojis.has(c) ? a.emojis.get(c) ?? null : null
132
- ));
133
- });
134
- }), s.forEach((a, c) => {
135
- i.has(a) || i.set(a, O(c)), (!o.has(a) || o.get(a) === void 0) && o.set(a, null);
136
- });
137
- const u = [
138
- e.activeTabId,
139
- ...t.map((a) => a.activeTabId)
140
- ].find(
141
- (a) => !!a && n.has(a) && !r.has(a)
142
- ) ?? s[0] ?? null;
143
- return {
144
- order: s,
145
- names: i,
146
- emojis: o,
147
- activeTabId: u,
148
- deletedIds: r
149
- };
150
- }
151
- function re(e, t, r) {
152
- const n = (r == null ? void 0 : r.createDefaultTabIfMissing) ?? !1, s = new Set(e.deletedIds), i = ee(
153
- e,
154
- t
155
- ).filter((l) => !s.has(l)), o = U([
156
- ...e.order,
157
- ...t.order
158
- ]);
159
- i.forEach((l) => {
160
- o.includes(l) || o.push(l);
161
- }), o.length === 0 && n && o.push(D);
162
- const f = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
163
- o.forEach((l, R) => {
164
- const Y = e.names.get(l) ?? t.names.get(l) ?? O(R), F = e.emojis.has(l) ? e.emojis.get(l) ?? null : t.emojis.has(l) ? t.emojis.get(l) ?? null : null;
165
- f.set(l, Y), u.set(l, F);
166
- });
167
- const c = [
168
- e.activeTabId,
169
- t.activeTabId
170
- ].find(
171
- (l) => !!l && o.includes(l)
172
- ) ?? o[0] ?? null;
173
- return {
174
- order: o,
175
- names: f,
176
- emojis: u,
177
- activeTabId: c,
178
- deletedIds: s
179
- };
180
- }
181
- function ne(e, t) {
182
- return e.length !== t.length ? !1 : e.every((r, n) => r === t[n]);
183
- }
184
- function se(e, t) {
185
- const r = A(e);
186
- return ne(r, t) ? !1 : (e.length > 0 && e.delete(0, e.length), t.length > 0 && e.insert(0, t), !0);
187
- }
188
- function oe(e, t, r) {
189
- const n = e.get(t);
190
- return r === null ? n === void 0 ? !1 : (e.delete(t), !0) : n === r ? !1 : (e.set(t, r), !0);
191
- }
192
- function p(e, t) {
193
- let r = !1;
194
- return Array.from(e.keys()).forEach((n) => {
195
- t.has(n) || (e.delete(n), r = !0);
196
- }), t.forEach((n, s) => {
197
- e.get(s) !== n && (e.set(s, n), r = !0);
198
- }), r;
199
- }
200
- function S(e, t, r = "self") {
201
- const n = g(e);
202
- let s = !1;
203
- const i = new Map(
204
- Array.from(t.deletedIds, (o) => [o, !0])
205
- );
206
- return e.transact(() => {
207
- t.order.forEach((o) => {
208
- e.getXmlFragment(o);
209
- }), s = se(n.order, t.order) || s, s = p(n.nameById, t.names) || s, s = p(n.emojiById, t.emojis) || s, s = oe(
210
- n.tabState,
211
- j,
212
- t.activeTabId
213
- ) || s, s = p(n.deletedById, i) || s;
214
- }, r), s;
215
- }
216
- function _(e, t) {
217
- const r = Q(e), n = H(e), s = re(
218
- r,
219
- n,
220
- t
221
- );
222
- return {
223
- tabSnapshotV2: r,
224
- legacySnapshot: n,
225
- resolvedTabState: s
226
- };
227
- }
228
- function C(e, t, r = "self") {
229
- const { resolvedTabState: n } = _(e, t);
230
- return S(e, n, r);
231
- }
232
- function fe(e, t, r) {
233
- E(e, t);
234
- const n = C(t, {
235
- ...r,
236
- createDefaultTabIfMissing: (r == null ? void 0 : r.createDefaultTabIfMissing) ?? !0
237
- }), s = g(t);
238
- return {
239
- tabList: ce(s),
240
- activeTabId: ae(s) || D,
241
- didWrite: n
242
- };
243
- }
244
- function le(e) {
245
- return g(e);
246
- }
247
- function ue(e, t, r = "self") {
248
- const n = C(e, t, r);
249
- return {
250
- ...g(e),
251
- didWrite: n
252
- };
253
- }
254
- function de(e, t) {
255
- const r = e.map((o) => {
256
- const f = new d.Doc();
257
- return E(o, f), _(f, t).resolvedTabState;
258
- }), n = new d.Doc();
259
- E(e, n);
260
- const { resolvedTabState: s } = _(
261
- n,
262
- t
263
- ), i = te(
264
- s,
265
- r
266
- );
267
- return S(n, i), k(d.encodeStateAsUpdate(n));
268
- }
269
- function ae(e) {
270
- const t = e.tabState.get(j);
271
- return typeof t == "string" ? t : null;
272
- }
273
- function ie(e, t) {
274
- return e.nameById.has(t) ? {
275
- name: e.nameById.get(t) ?? b,
276
- emoji: e.emojiById.has(t) ? e.emojiById.get(t) ?? null : null
277
- } : null;
278
- }
279
- function ce(e) {
280
- const t = /* @__PURE__ */ new Set();
281
- return A(e.order).filter((r) => t.has(r) ? !1 : (t.add(r), !0)).map((r) => {
282
- const n = ie(
283
- e,
284
- r
285
- );
286
- return n ? {
287
- id: r,
288
- name: n.name,
289
- emoji: n.emoji
290
- } : null;
291
- }).filter((r) => r !== null);
292
- }
293
- function me(e) {
294
- return e.toArray().map((t) => t instanceof d.XmlElement || t instanceof d.XmlText ? t.clone() : null).filter((t) => t !== null);
295
- }
296
- export {
297
- j as A,
298
- D,
299
- W as L,
300
- X as O,
301
- J as S,
302
- ie as a,
303
- ae as b,
304
- me as c,
305
- fe as d,
306
- ce as e,
307
- k as f,
308
- le as g,
309
- b as h,
310
- de as m,
311
- ue as s,
312
- B as t
313
- };