@dialecte/core 0.2.4 → 0.2.5

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,101 +1,101 @@
1
1
  import { t as $e, i as we } from "./index-DWV6tSGF.js";
2
- import { g as vr, l as ce, n as br, k as pr, s as yo, t as vo, C as gi } from "./standardizing-FTZoR5RH.js";
2
+ import { g as vr, l as ce, o as br, k as pr, s as yo, t as vo, C as gi, m as bo } from "./merge-extensions-dj7By9gG.js";
3
3
  function gr(m, r) {
4
4
  if (!m) return {};
5
5
  const s = {};
6
6
  for (const o of Object.keys(m)) {
7
- const d = m[o], f = {};
8
- for (const v of Object.keys(d)) {
9
- const g = d[v];
10
- f[v] = (...D) => g(r, ...D);
7
+ const f = m[o], d = {};
8
+ for (const v of Object.keys(f)) {
9
+ const g = f[v];
10
+ d[v] = (...D) => g(r, ...D);
11
11
  }
12
- s[o] = f;
12
+ s[o] = d;
13
13
  }
14
14
  return s;
15
15
  }
16
- function bo(m) {
16
+ function wo(m) {
17
17
  const { stagedOperations: r, tagName: s, id: o } = m;
18
- for (let d = r.length - 1; d >= 0; d--) {
19
- const f = r[d];
18
+ for (let f = r.length - 1; f >= 0; f--) {
19
+ const d = r[f];
20
20
  if (o === void 0) {
21
- if ((f.status === "created" || f.status === "updated") && vr(f.newRecord, s))
21
+ if ((d.status === "created" || d.status === "updated") && vr(d.newRecord, s))
22
22
  return {
23
- ...f.newRecord,
24
- status: f.status
23
+ ...d.newRecord,
24
+ status: d.status
25
25
  };
26
- if (f.status === "deleted" && vr(f.oldRecord, s))
26
+ if (d.status === "deleted" && vr(d.oldRecord, s))
27
27
  return {
28
- ...f.oldRecord,
28
+ ...d.oldRecord,
29
29
  status: "deleted"
30
30
  };
31
31
  continue;
32
32
  }
33
- if (f.status === "created" && f.newRecord.id === o) {
34
- const v = f.newRecord.tagName;
33
+ if (d.status === "created" && d.newRecord.id === o) {
34
+ const v = d.newRecord.tagName;
35
35
  return v !== s && $e("ELEMENT_TAGNAME_MISMATCH", {
36
36
  detail: `Expected tagName '${s}', got '${v}' for id '${o}'`,
37
37
  ref: { tagName: s, id: o }
38
38
  }), {
39
- ...f.newRecord,
39
+ ...d.newRecord,
40
40
  status: "created"
41
41
  };
42
42
  }
43
- if (f.status === "updated" && f.newRecord.id === o) {
44
- const v = f.newRecord.tagName;
43
+ if (d.status === "updated" && d.newRecord.id === o) {
44
+ const v = d.newRecord.tagName;
45
45
  return v !== s && $e("ELEMENT_TAGNAME_MISMATCH", {
46
46
  detail: `Expected tagName '${s}', got '${v}' for id '${o}'`,
47
47
  ref: { tagName: s, id: o }
48
48
  }), {
49
- ...f.newRecord,
49
+ ...d.newRecord,
50
50
  status: "updated"
51
51
  };
52
52
  }
53
- if (f.status === "deleted" && f.oldRecord.id === o) {
54
- const v = f.oldRecord.tagName;
53
+ if (d.status === "deleted" && d.oldRecord.id === o) {
54
+ const v = d.oldRecord.tagName;
55
55
  return v !== s && $e("ELEMENT_TAGNAME_MISMATCH", {
56
56
  detail: `Expected tagName '${s}', got '${v}' for id '${o}'`,
57
57
  ref: { tagName: s, id: o }
58
58
  }), {
59
- ...f.oldRecord,
59
+ ...d.oldRecord,
60
60
  status: "deleted"
61
61
  };
62
62
  }
63
63
  }
64
64
  }
65
- function wo(m) {
66
- const { rawRecords: r, stagedOperations: s, tagName: o } = m, d = new Map(
67
- r.map((f) => [f.id, { ...f, status: "unchanged" }])
65
+ function _o(m) {
66
+ const { rawRecords: r, stagedOperations: s, tagName: o } = m, f = new Map(
67
+ r.map((d) => [d.id, { ...d, status: "unchanged" }])
68
68
  );
69
- for (const f of s) {
70
- if (f.status === "created" || f.status === "updated") {
71
- if (!vr(f.newRecord, o)) continue;
72
- d.set(f.newRecord.id, { ...f.newRecord, status: f.status });
69
+ for (const d of s) {
70
+ if (d.status === "created" || d.status === "updated") {
71
+ if (!vr(d.newRecord, o)) continue;
72
+ f.set(d.newRecord.id, { ...d.newRecord, status: d.status });
73
73
  }
74
- f.status === "deleted" && f.oldRecord.tagName === o && d.delete(f.oldRecord.id);
74
+ d.status === "deleted" && d.oldRecord.tagName === o && f.delete(d.oldRecord.id);
75
75
  }
76
- return Array.from(d.values());
76
+ return Array.from(f.values());
77
77
  }
78
78
  async function me(m) {
79
79
  const { context: r, ref: s } = m;
80
80
  if (r.stagedOperations.length > 0) {
81
- const d = bo({
81
+ const f = wo({
82
82
  stagedOperations: r.stagedOperations,
83
83
  tagName: s.tagName,
84
84
  id: s.id
85
85
  });
86
- if (d?.status === "deleted") return;
87
- if (d) return d;
86
+ if (f?.status === "deleted") return;
87
+ if (f) return f;
88
88
  }
89
89
  let o;
90
90
  if (s.id === void 0) {
91
- const d = `__singleton_${s.tagName}`, f = Ht(r) ? r.recordCache.get(d) : void 0;
92
- f ? o = f : (o = (await r.store.getByTagNameInDocument(
91
+ const f = `__singleton_${s.tagName}`, d = Ht(r) ? r.recordCache.get(f) : void 0;
92
+ d ? o = d : (o = (await r.store.getByTagNameInDocument(
93
93
  s.tagName,
94
94
  r.documentId
95
- ))[0], o && Ht(r) && (r.recordCache.set(o.id, o), r.recordCache.set(d, o)));
95
+ ))[0], o && Ht(r) && (r.recordCache.set(o.id, o), r.recordCache.set(f, o)));
96
96
  } else {
97
- const d = Ht(r) ? r.recordCache.get(s.id) : void 0;
98
- d ? o = d : (o = await r.store.get(s.id, r.documentId), o && Ht(r) && r.recordCache.set(s.id, o));
97
+ const f = Ht(r) ? r.recordCache.get(s.id) : void 0;
98
+ f ? o = f : (o = await r.store.get(s.id, r.documentId), o && Ht(r) && r.recordCache.set(s.id, o));
99
99
  }
100
100
  if (o)
101
101
  return { ...o, status: "unchanged" };
@@ -109,18 +109,18 @@ async function Sn(m) {
109
109
  s,
110
110
  r.documentId
111
111
  );
112
- for (const d of o)
113
- Ht(r) && r.recordCache.set(d.id, d);
114
- return wo({ rawRecords: o, stagedOperations: r.stagedOperations, tagName: s });
112
+ for (const f of o)
113
+ Ht(r) && r.recordCache.set(f.id, f);
114
+ return _o({ rawRecords: o, stagedOperations: r.stagedOperations, tagName: s });
115
115
  }
116
116
  async function yi(m) {
117
- const { context: r, ref: s, tagName: o } = m, d = await me({ context: r, ref: s });
118
- if (!d) return;
119
- const f = d.children.find((D) => D.tagName === o);
120
- if (f) return me({ context: r, ref: f });
117
+ const { context: r, ref: s, tagName: o } = m, f = await me({ context: r, ref: s });
118
+ if (!f) return;
119
+ const d = f.children.find((D) => D.tagName === o);
120
+ if (d) return me({ context: r, ref: d });
121
121
  const v = r.dialecteConfig.transparentElements;
122
122
  if (!v?.length) return;
123
- const g = d.children.filter(
123
+ const g = f.children.filter(
124
124
  (D) => v.includes(D.tagName)
125
125
  );
126
126
  for (const D of g) {
@@ -131,16 +131,16 @@ async function yi(m) {
131
131
  }
132
132
  }
133
133
  async function vi(m) {
134
- const { context: r, ref: s, tagName: o } = m, d = await me({ context: r, ref: s });
135
- if (!d) return [];
136
- const f = d.children.filter((B) => B.tagName === o).map((B) => ({ tagName: o, id: B.id }));
137
- if (f.length)
138
- return (await Zt({ context: r, refs: f })).filter(
134
+ const { context: r, ref: s, tagName: o } = m, f = await me({ context: r, ref: s });
135
+ if (!f) return [];
136
+ const d = f.children.filter((B) => B.tagName === o).map((B) => ({ tagName: o, id: B.id }));
137
+ if (d.length)
138
+ return (await Zt({ context: r, refs: d })).filter(
139
139
  (Y) => Y !== void 0
140
140
  );
141
141
  const v = r.dialecteConfig.transparentElements;
142
142
  if (!v?.length) return [];
143
- const g = d.children.filter(
143
+ const g = f.children.filter(
144
144
  (B) => v.includes(B.tagName)
145
145
  );
146
146
  if (!g.length) return [];
@@ -150,55 +150,55 @@ async function vi(m) {
150
150
  ) : [];
151
151
  }
152
152
  async function bi(m) {
153
- const { context: r, ref: s, options: o } = m, d = o?.depth ?? 1 / 0, f = o?.stopAtTagName, v = o?.order ?? "bottom-up", g = [];
153
+ const { context: r, ref: s, options: o } = m, f = o?.depth ?? 1 / 0, d = o?.stopAtTagName, v = o?.order ?? "bottom-up", g = [];
154
154
  let D = await me({ context: r, ref: s });
155
- for (; D?.parent && g.length < d; ) {
155
+ for (; D?.parent && g.length < f; ) {
156
156
  const R = D.parent, K = await me({ context: r, ref: R });
157
- if (!K || (g.push(K), f && K.tagName === f)) break;
157
+ if (!K || (g.push(K), d && K.tagName === d)) break;
158
158
  D = K;
159
159
  }
160
160
  return v === "top-down" ? g.reverse() : g;
161
161
  }
162
162
  async function Er(m) {
163
- const { context: r, tagName: s, attributes: o } = m, d = await Sn({ context: r, tagName: s }), f = [];
164
- for (const v of d)
165
- xt({ record: v, attributeFilter: o }) && f.push(v);
166
- return f;
163
+ const { context: r, tagName: s, attributes: o } = m, f = await Sn({ context: r, tagName: s }), d = [];
164
+ for (const v of f)
165
+ xt({ record: v, attributeFilter: o }) && d.push(v);
166
+ return d;
167
167
  }
168
168
  function xt(m) {
169
169
  const { record: r, attributeFilter: s } = m;
170
170
  if (!s || Object.keys(s).length === 0)
171
171
  return !0;
172
- for (const [o, d] of Object.entries(s)) {
173
- if (d === void 0) continue;
172
+ for (const [o, f] of Object.entries(s)) {
173
+ if (f === void 0) continue;
174
174
  const v = r.attributes.find(
175
175
  (g) => g.name === o
176
176
  )?.value ?? "";
177
177
  if (v === "") return !1;
178
- if (Array.isArray(d)) {
179
- if (!d.some((g) => v === g))
178
+ if (Array.isArray(f)) {
179
+ if (!f.some((g) => v === g))
180
180
  return !1;
181
- } else if (v !== d)
181
+ } else if (v !== f)
182
182
  return !1;
183
183
  }
184
184
  return !0;
185
185
  }
186
186
  async function wr(m) {
187
- const { context: r, ref: s, options: o } = m, { collect: d, omit: f } = o, v = _o(f), g = Eo(d), D = /* @__PURE__ */ new Map();
187
+ const { context: r, ref: s, options: o } = m, { collect: f, omit: d } = o, v = Eo(d), g = xo(f), D = /* @__PURE__ */ new Map();
188
188
  for (const K of g.allTags)
189
189
  D.set(K, /* @__PURE__ */ new Map());
190
190
  const R = await me({ context: r, ref: s });
191
- return R && (g.mode === "flat" ? await To({ context: r, rootId: R.id, collectSpec: g, omitSpec: v, collected: D }) : await Ei({ context: r, record: R, pathNodes: g.paths, omitSpec: v, collected: D })), ii(D);
191
+ return R && (g.mode === "flat" ? await No({ context: r, rootId: R.id, collectSpec: g, omitSpec: v, collected: D }) : await Ei({ context: r, record: R, pathNodes: g.paths, omitSpec: v, collected: D })), ii(D);
192
192
  }
193
- function _o(m) {
193
+ function Eo(m) {
194
194
  const r = /* @__PURE__ */ new Set(), s = [];
195
195
  if (!m) return { unconditional: r, conditional: s };
196
196
  for (const o of m)
197
197
  if (typeof o == "string")
198
198
  r.add(o);
199
199
  else {
200
- const d = Object.keys(o)[0], f = o[d];
201
- f?.where ? s.push({ tagName: d, where: f.where }) : r.add(d);
200
+ const f = Object.keys(o)[0], d = o[f];
201
+ d?.where ? s.push({ tagName: f, where: d.where }) : r.add(f);
202
202
  }
203
203
  return { unconditional: r, conditional: s };
204
204
  }
@@ -213,56 +213,56 @@ function xr(m) {
213
213
  return !0;
214
214
  return !1;
215
215
  }
216
- function Eo(m) {
216
+ function xo(m) {
217
217
  if (typeof m == "string")
218
218
  return { mode: "flat", targets: [{ tagName: m }], allTags: /* @__PURE__ */ new Set([m]) };
219
219
  if (Array.isArray(m)) {
220
- const o = [], d = /* @__PURE__ */ new Set();
221
- for (const f of m)
222
- if (typeof f == "string")
223
- o.push({ tagName: f }), d.add(f);
220
+ const o = [], f = /* @__PURE__ */ new Set();
221
+ for (const d of m)
222
+ if (typeof d == "string")
223
+ o.push({ tagName: d }), f.add(d);
224
224
  else
225
- for (const [v, g] of Object.entries(f))
226
- o.push({ tagName: v, where: g?.where }), d.add(v);
227
- return { mode: "flat", targets: o, allTags: d };
225
+ for (const [v, g] of Object.entries(d))
226
+ o.push({ tagName: v, where: g?.where }), f.add(v);
227
+ return { mode: "flat", targets: o, allTags: f };
228
228
  }
229
229
  const r = /* @__PURE__ */ new Set();
230
230
  return { mode: "path", paths: wi(m, r), allTags: r };
231
231
  }
232
232
  function wi(m, r) {
233
233
  const s = [];
234
- for (const [o, d] of Object.entries(m)) {
234
+ for (const [o, f] of Object.entries(m)) {
235
235
  if (o === "where") continue;
236
236
  r.add(o);
237
- const f = xo({ tagName: o, value: d, allTags: r });
238
- f && s.push(f);
237
+ const d = To({ tagName: o, value: f, allTags: r });
238
+ d && s.push(d);
239
239
  }
240
240
  return s;
241
241
  }
242
- function xo(m) {
242
+ function To(m) {
243
243
  const { tagName: r, value: s, allTags: o } = m;
244
244
  if (s === !0)
245
245
  return { tagName: r, where: void 0, children: [], isLeaf: !0 };
246
246
  if (typeof s != "object" || s === null) return;
247
- const d = s, f = d.where, v = Object.keys(d).filter((R) => R !== "where");
247
+ const f = s, d = f.where, v = Object.keys(f).filter((R) => R !== "where");
248
248
  if (v.length === 0)
249
- return { tagName: r, where: f, children: [], isLeaf: !0 };
249
+ return { tagName: r, where: d, children: [], isLeaf: !0 };
250
250
  const g = {};
251
251
  for (const R of v)
252
- g[R] = d[R];
252
+ g[R] = f[R];
253
253
  const D = wi(g, o);
254
- return { tagName: r, where: f, children: D, isLeaf: !1 };
254
+ return { tagName: r, where: d, children: D, isLeaf: !1 };
255
255
  }
256
- async function To(m) {
257
- const { context: r, rootId: s, collectSpec: o, omitSpec: d, collected: f } = m;
256
+ async function No(m) {
257
+ const { context: r, rootId: s, collectSpec: o, omitSpec: f, collected: d } = m;
258
258
  for (const v of o.targets) {
259
- if (d.unconditional.has(v.tagName)) continue;
259
+ if (f.unconditional.has(v.tagName)) continue;
260
260
  const g = await Sn({
261
261
  context: r,
262
262
  tagName: v.tagName
263
263
  });
264
264
  for (const D of g)
265
- _i({ record: D, where: v.where }) && (xr({ record: D, omitSpec: d }) || await No({ context: r, record: D, rootId: s, omitSpec: d }) && f.get(v.tagName).set(D.id, D));
265
+ _i({ record: D, where: v.where }) && (xr({ record: D, omitSpec: f }) || await Co({ context: r, record: D, rootId: s, omitSpec: f }) && d.get(v.tagName).set(D.id, D));
266
266
  }
267
267
  }
268
268
  function _i(m) {
@@ -272,54 +272,54 @@ function _i(m) {
272
272
  attributeFilter: s
273
273
  }) : !0;
274
274
  }
275
- async function No(m) {
276
- const { context: r, record: s, rootId: o, omitSpec: d } = m;
275
+ async function Co(m) {
276
+ const { context: r, record: s, rootId: o, omitSpec: f } = m;
277
277
  if (s.id === o) return !0;
278
- let f = s;
279
- for (; f; ) {
280
- if (!f.parent || d.unconditional.has(f.parent.tagName)) return !1;
281
- if (f.parent.id === o) return !0;
282
- const v = await me({ context: r, ref: ce(f.parent) });
283
- if (!v || xr({ record: v, omitSpec: d })) return !1;
284
- f = v;
278
+ let d = s;
279
+ for (; d; ) {
280
+ if (!d.parent || f.unconditional.has(d.parent.tagName)) return !1;
281
+ if (d.parent.id === o) return !0;
282
+ const v = await me({ context: r, ref: ce(d.parent) });
283
+ if (!v || xr({ record: v, omitSpec: f })) return !1;
284
+ d = v;
285
285
  }
286
286
  return !1;
287
287
  }
288
288
  async function Ei(m) {
289
- const { context: r, record: s, pathNodes: o, omitSpec: d, collected: f } = m;
289
+ const { context: r, record: s, pathNodes: o, omitSpec: f, collected: d } = m;
290
290
  if (!s.children?.length) return;
291
291
  const v = new Set(o.map((g) => g.tagName));
292
292
  for (const g of o) {
293
- const D = await Co({
293
+ const D = await Oo({
294
294
  context: r,
295
295
  record: s,
296
296
  tagName: g.tagName,
297
297
  where: g.where,
298
- omitSpec: d,
298
+ omitSpec: f,
299
299
  stopAtTagNames: v
300
300
  });
301
301
  for (const R of D)
302
- f.get(g.tagName).set(R.id, R), !g.isLeaf && g.children.length > 0 && await Ei({
302
+ d.get(g.tagName).set(R.id, R), !g.isLeaf && g.children.length > 0 && await Ei({
303
303
  context: r,
304
304
  record: R,
305
305
  pathNodes: g.children,
306
- omitSpec: d,
307
- collected: f
306
+ omitSpec: f,
307
+ collected: d
308
308
  });
309
309
  }
310
310
  }
311
- async function Co(m) {
312
- const { context: r, record: s, tagName: o, where: d, omitSpec: f, stopAtTagNames: v } = m, g = [];
311
+ async function Oo(m) {
312
+ const { context: r, record: s, tagName: o, where: f, omitSpec: d, stopAtTagNames: v } = m, g = [];
313
313
  if (!s.children?.length) return g;
314
- const D = [], R = await ri({ context: r, record: s, omitSpec: f });
314
+ const D = [], R = await ri({ context: r, record: s, omitSpec: d });
315
315
  for (D.push(...R); D.length > 0; ) {
316
316
  const K = D.shift();
317
317
  if (K.tagName === o) {
318
- _i({ record: K, where: d }) && g.push(K);
318
+ _i({ record: K, where: f }) && g.push(K);
319
319
  continue;
320
320
  }
321
321
  if (!(v.has(K.tagName) && K.tagName !== o) && K.children?.length) {
322
- const B = await ri({ context: r, record: K, omitSpec: f });
322
+ const B = await ri({ context: r, record: K, omitSpec: d });
323
323
  D.push(...B);
324
324
  }
325
325
  }
@@ -328,9 +328,9 @@ async function Co(m) {
328
328
  async function ri(m) {
329
329
  const { context: r, record: s, omitSpec: o } = m;
330
330
  if (!s.children?.length) return [];
331
- const d = s.children.filter((v) => !o.unconditional.has(v.tagName));
332
- return d.length ? (await Promise.all(
333
- d.map((v) => me({ context: r, ref: ce(v) }))
331
+ const f = s.children.filter((v) => !o.unconditional.has(v.tagName));
332
+ return f.length ? (await Promise.all(
333
+ f.map((v) => me({ context: r, ref: ce(v) }))
334
334
  )).filter(
335
335
  (v) => v !== void 0 && !xr({ record: v, omitSpec: o })
336
336
  ) : [];
@@ -352,7 +352,7 @@ async function Ti(m) {
352
352
  async function Ni(m) {
353
353
  const { context: r, ref: s } = m;
354
354
  return ((await me({ context: r, ref: s }))?.attributes ?? []).reduce(
355
- (f, v) => (f[v.name] = v.value ?? "", f),
355
+ (d, v) => (d[v.name] = v.value ?? "", d),
356
356
  {}
357
357
  );
358
358
  }
@@ -361,21 +361,21 @@ async function Ci(m) {
361
361
  return (await me({ context: r, ref: s }))?.attributes ?? [];
362
362
  }
363
363
  async function Oi(m) {
364
- const { context: r, ref: s, options: o = {}, dialecteConfig: d } = m, { select: f, omit: v, unwrap: g } = o, D = await me({ context: r, ref: s });
364
+ const { context: r, ref: s, options: o = {}, dialecteConfig: f } = m, { select: d, omit: v, unwrap: g } = o, D = await me({ context: r, ref: s });
365
365
  we(D, {
366
366
  detail: "No record found for provided ref",
367
367
  key: "ELEMENT_NOT_FOUND"
368
368
  });
369
- const R = Oo(v), K = await Ai({
369
+ const R = Ao(v), K = await Ai({
370
370
  context: r,
371
371
  record: D,
372
- select: f,
372
+ select: d,
373
373
  compiledOmit: R,
374
- dialecteConfig: d
374
+ dialecteConfig: f
375
375
  });
376
- return K ? g ? Mo({ tree: K, unwrapTagNames: g }) : K : br({ record: D });
376
+ return K ? g ? Ko({ tree: K, unwrapTagNames: g }) : K : br({ record: D });
377
377
  }
378
- function Oo(m) {
378
+ function Ao(m) {
379
379
  const r = /* @__PURE__ */ new Set(), s = [];
380
380
  if (!m) return { unconditional: r, conditional: s };
381
381
  for (const o of m) {
@@ -383,39 +383,39 @@ function Oo(m) {
383
383
  r.add(o);
384
384
  continue;
385
385
  }
386
- const d = Object.keys(o)[0], f = o[d];
387
- if (!f?.where) {
388
- r.add(d);
386
+ const f = Object.keys(o)[0], d = o[f];
387
+ if (!d?.where) {
388
+ r.add(f);
389
389
  continue;
390
390
  }
391
391
  s.push({
392
- tagName: d,
393
- where: f.where,
394
- scope: f.scope ?? "self"
392
+ tagName: f,
393
+ where: d.where,
394
+ scope: d.scope ?? "self"
395
395
  });
396
396
  }
397
397
  return { unconditional: r, conditional: s };
398
398
  }
399
399
  async function Ai(m) {
400
- const { context: r, record: s, select: o, compiledOmit: d, dialecteConfig: f } = m;
401
- if (Ao({ record: s, compiledOmit: d }))
400
+ const { context: r, record: s, select: o, compiledOmit: f, dialecteConfig: d } = m;
401
+ if (Do({ record: s, compiledOmit: f }))
402
402
  return br({ record: s });
403
- const v = await So({
403
+ const v = await ko({
404
404
  context: r,
405
405
  record: s,
406
406
  select: o,
407
- compiledOmit: d,
408
- dialecteConfig: f
407
+ compiledOmit: f,
408
+ dialecteConfig: d
409
409
  }), D = (await Promise.all(
410
410
  v.map(
411
- ({ record: R, select: K }) => Ai({ context: r, record: R, select: K, compiledOmit: d, dialecteConfig: f })
411
+ ({ record: R, select: K }) => Ai({ context: r, record: R, select: K, compiledOmit: f, dialecteConfig: d })
412
412
  )
413
413
  )).filter(
414
414
  (R) => R !== null
415
415
  );
416
416
  return br({ record: s, tree: D });
417
417
  }
418
- function Ao(m) {
418
+ function Do(m) {
419
419
  const { record: r, compiledOmit: s } = m;
420
420
  return s.conditional.some(
421
421
  (o) => o.scope === "children" && o.tagName === r.tagName && xt({
@@ -424,7 +424,7 @@ function Ao(m) {
424
424
  })
425
425
  );
426
426
  }
427
- function Do(m) {
427
+ function So(m) {
428
428
  const { record: r, compiledOmit: s } = m;
429
429
  return s.unconditional.has(r.tagName) ? !0 : s.conditional.some(
430
430
  (o) => o.scope === "self" && o.tagName === r.tagName && xt({
@@ -433,16 +433,16 @@ function Do(m) {
433
433
  })
434
434
  );
435
435
  }
436
- async function So(m) {
437
- const { context: r, record: s, select: o, compiledOmit: d, dialecteConfig: f } = m;
436
+ async function ko(m) {
437
+ const { context: r, record: s, select: o, compiledOmit: f, dialecteConfig: d } = m;
438
438
  if (!s.children?.length) return [];
439
- const v = o ? Io(o) : void 0;
440
- if (v && o && f && o.recursive !== !1) {
441
- const B = s.tagName, Y = f.children[B], oe = o[B] !== void 0;
439
+ const v = o ? Po(o) : void 0;
440
+ if (v && o && d && o.recursive !== !1) {
441
+ const B = s.tagName, Y = d.children[B], oe = o[B] !== void 0;
442
442
  Y?.includes(B) && !oe && v.add(B);
443
443
  }
444
444
  const g = s.children.filter(
445
- (B) => ko({ tagName: B.tagName, compiledOmit: d, selectKeys: v })
445
+ (B) => Ro({ tagName: B.tagName, compiledOmit: f, selectKeys: v })
446
446
  );
447
447
  if (!g.length) return [];
448
448
  const K = (await Promise.all(
@@ -454,45 +454,45 @@ async function So(m) {
454
454
  )
455
455
  )).filter(
456
456
  (B) => B !== void 0
457
- ).filter((B) => !Do({ record: B, compiledOmit: d }));
458
- return Po({ children: K, select: o, record: s, dialecteConfig: f });
457
+ ).filter((B) => !So({ record: B, compiledOmit: f }));
458
+ return Fo({ children: K, select: o, record: s, dialecteConfig: d });
459
459
  }
460
- function ko(m) {
460
+ function Ro(m) {
461
461
  const { tagName: r, compiledOmit: s, selectKeys: o } = m;
462
462
  return !(s.unconditional.has(r) || o && !o.has(r));
463
463
  }
464
- const Ro = /* @__PURE__ */ new Set(["where", "recursive"]);
465
- function Io(m) {
464
+ const Io = /* @__PURE__ */ new Set(["where", "recursive"]);
465
+ function Po(m) {
466
466
  const r = /* @__PURE__ */ new Set();
467
467
  for (const s of Object.keys(m))
468
- Ro.has(s) || r.add(s);
468
+ Io.has(s) || r.add(s);
469
469
  return r;
470
470
  }
471
- function Po(m) {
472
- const { children: r, select: s, record: o, dialecteConfig: d } = m;
471
+ function Fo(m) {
472
+ const { children: r, select: s, record: o, dialecteConfig: f } = m;
473
473
  if (!s)
474
474
  return r.map((v) => ({ record: v, select: void 0 }));
475
- const f = [];
475
+ const d = [];
476
476
  for (const v of r) {
477
477
  const g = s[v.tagName];
478
478
  if (g === void 0 && v.tagName === o.tagName) {
479
- const R = Fo({ child: v, select: s, dialecteConfig: d });
479
+ const R = Bo({ child: v, select: s, dialecteConfig: f });
480
480
  if (R) {
481
- f.push(R);
481
+ d.push(R);
482
482
  continue;
483
483
  }
484
484
  }
485
485
  if (g === void 0 || g === !1) continue;
486
486
  if (g === !0) {
487
- f.push({ record: v, select: void 0 });
487
+ d.push({ record: v, select: void 0 });
488
488
  continue;
489
489
  }
490
- const D = Bo({ child: v, entry: g, parentRecord: o });
491
- D && f.push(D);
490
+ const D = jo({ child: v, entry: g, parentRecord: o });
491
+ D && d.push(D);
492
492
  }
493
- return f;
493
+ return d;
494
494
  }
495
- function Fo(m) {
495
+ function Bo(m) {
496
496
  const { child: r, select: s, dialecteConfig: o } = m;
497
497
  if (!(!o || s.recursive === !1 || !o.children[r.tagName]?.includes(r.tagName)) && !(s.where && !xt({
498
498
  record: r,
@@ -500,27 +500,27 @@ function Fo(m) {
500
500
  })))
501
501
  return { record: r, select: s };
502
502
  }
503
- function Bo(m) {
504
- const { child: r, entry: s, parentRecord: o } = m, d = s;
505
- if (!(d.where && !xt({
503
+ function jo(m) {
504
+ const { child: r, entry: s, parentRecord: o } = m, f = s;
505
+ if (!(f.where && !xt({
506
506
  record: r,
507
- attributeFilter: d.where
507
+ attributeFilter: f.where
508
508
  }))) {
509
- if (d.recursive && r.tagName === o.tagName) {
510
- const f = d.recursive === !0 ? !0 : d.recursive - 1;
511
- return f === 0 ? void 0 : { record: r, select: { ...d, recursive: f } };
509
+ if (f.recursive && r.tagName === o.tagName) {
510
+ const d = f.recursive === !0 ? !0 : f.recursive - 1;
511
+ return d === 0 ? void 0 : { record: r, select: { ...f, recursive: d } };
512
512
  }
513
- return d.recursive ? { record: r, select: jo(d, r.tagName) } : r.tagName === o.tagName ? { record: r, select: { ...d, recursive: !1 } } : { record: r, select: d };
513
+ return f.recursive ? { record: r, select: Mo(f, r.tagName) } : r.tagName === o.tagName ? { record: r, select: { ...f, recursive: !1 } } : { record: r, select: f };
514
514
  }
515
515
  }
516
- function jo(m, r) {
516
+ function Mo(m, r) {
517
517
  const s = m[r];
518
518
  return m;
519
519
  }
520
- function Mo(m) {
520
+ function Ko(m) {
521
521
  const { tree: r, unwrapTagNames: s } = m;
522
- function o(d) {
523
- return d.flatMap((f) => s.includes(f.tagName) ? o(f.tree) : [{ ...f, tree: o(f.tree) }]);
522
+ function o(f) {
523
+ return f.flatMap((d) => s.includes(d.tagName) ? o(d.tree) : [{ ...d, tree: o(d.tree) }]);
524
524
  }
525
525
  return { ...r, tree: o(r.tree) };
526
526
  }
@@ -561,12 +561,12 @@ class Di {
561
561
  });
562
562
  }
563
563
  async getAttribute(r, s) {
564
- const o = ce(r), { fullObject: d } = s;
565
- return d ? Ti({ context: this.getContext(), ref: o, ...s }) : xi({ context: this.getContext(), ref: o, ...s });
564
+ const o = ce(r), { fullObject: f } = s;
565
+ return f ? Ti({ context: this.getContext(), ref: o, ...s }) : xi({ context: this.getContext(), ref: o, ...s });
566
566
  }
567
567
  async getAttributes(r, s) {
568
- const o = ce(r), { fullObject: d } = s || {};
569
- return d ? Ci({ context: this.getContext(), ref: o, ...s }) : Ni({ context: this.getContext(), ref: o, ...s });
568
+ const o = ce(r), { fullObject: f } = s || {};
569
+ return f ? Ci({ context: this.getContext(), ref: o, ...s }) : Ni({ context: this.getContext(), ref: o, ...s });
570
570
  }
571
571
  async getTree(r) {
572
572
  return Oi({
@@ -738,11 +738,11 @@ class Si {
738
738
  async findDescendants(r, s) {
739
739
  const o = ce(r);
740
740
  if (!s) {
741
- const d = this.dialecteConfig.descendants[o.tagName] ?? [];
741
+ const f = this.dialecteConfig.descendants[o.tagName] ?? [];
742
742
  return wr({
743
743
  context: this.context,
744
744
  ref: o,
745
- options: { collect: d }
745
+ options: { collect: f }
746
746
  });
747
747
  }
748
748
  return wr({
@@ -788,12 +788,12 @@ class Si {
788
788
  });
789
789
  }
790
790
  async getAttribute(r, s) {
791
- const o = ce(r), { fullObject: d } = s;
792
- return d ? Ti({ context: this.context, ref: o, ...s }) : xi({ context: this.context, ref: o, ...s });
791
+ const o = ce(r), { fullObject: f } = s;
792
+ return f ? Ti({ context: this.context, ref: o, ...s }) : xi({ context: this.context, ref: o, ...s });
793
793
  }
794
794
  async getAttributes(r, s) {
795
- const o = ce(r), { fullObject: d } = s || {};
796
- return d ? Ci({ context: this.context, ref: o, ...s }) : Ni({ context: this.context, ref: o, ...s });
795
+ const o = ce(r), { fullObject: f } = s || {};
796
+ return f ? Ci({ context: this.context, ref: o, ...s }) : Ni({ context: this.context, ref: o, ...s });
797
797
  }
798
798
  //== Find queries
799
799
  /**
@@ -815,9 +815,9 @@ class Si {
815
815
  }
816
816
  }
817
817
  function et(m) {
818
- const { context: r, status: s, record: o, oldRecord: d, newRecord: f } = m;
818
+ const { context: r, status: s, record: o, oldRecord: f, newRecord: d } = m;
819
819
  let v, g, D;
820
- o && (v = pr(o)), d && (g = pr(d)), f && (D = pr(f)), s === "created" ? (we(v, {
820
+ o && (v = pr(o)), f && (g = pr(f)), d && (D = pr(d)), s === "created" ? (we(v, {
821
821
  detail: "Record is required for created",
822
822
  key: "ELEMENT_NOT_FOUND"
823
823
  }), r.stagedOperations.push({ status: s, oldRecord: void 0, newRecord: v })) : s === "updated" ? (we(g && D, {
@@ -849,11 +849,11 @@ function Tr(m) {
849
849
  }
850
850
  }
851
851
  async function kn(m) {
852
- const { dialecteConfig: r, hooks: s, context: o, query: d, parentRef: f, params: v } = m, { id: g, tagName: D, attributes: R, namespace: K, value: B } = v, Y = await me({ context: o, ref: f });
852
+ const { dialecteConfig: r, hooks: s, context: o, query: f, parentRef: d, params: v } = m, { id: g, tagName: D, attributes: R, namespace: K, value: B } = v, Y = await me({ context: o, ref: d });
853
853
  we(Y, {
854
854
  detail: "Parent record not found",
855
855
  key: "ELEMENT_NOT_FOUND",
856
- ref: f
856
+ ref: d
857
857
  });
858
858
  const oe = yo({
859
859
  dialecteConfig: r,
@@ -886,26 +886,26 @@ async function kn(m) {
886
886
  const j = await s.afterCreated({
887
887
  childRecord: oe,
888
888
  parentRecord: M,
889
- query: d
889
+ query: f
890
890
  });
891
891
  Tr({ context: o, operations: j });
892
892
  }
893
893
  return oe;
894
894
  }
895
895
  async function ki(m) {
896
- const { dialecteConfig: r, hooks: s, context: o, query: d, parentRef: f, record: v, cumulativeCloneMappings: g } = m, D = [], R = await Ri({
896
+ const { dialecteConfig: r, hooks: s, context: o, query: f, parentRef: d, record: v, cumulativeCloneMappings: g } = m, D = [], R = await Ri({
897
897
  dialecteConfig: r,
898
898
  hooks: s,
899
899
  context: o,
900
- query: d,
901
- parentRef: f,
900
+ query: f,
901
+ parentRef: d,
902
902
  record: v,
903
903
  mappings: D
904
904
  });
905
905
  if (g.push(...D), s?.afterDeepClone) {
906
906
  const K = await s.afterDeepClone({
907
907
  cumulativeCloneMappings: g,
908
- query: d
908
+ query: f
909
909
  });
910
910
  o.stagedOperations.push(...K);
911
911
  }
@@ -915,7 +915,7 @@ async function ki(m) {
915
915
  };
916
916
  }
917
917
  async function Ri(m) {
918
- const { dialecteConfig: r, hooks: s, context: o, query: d, parentRef: f, record: v, mappings: g } = m;
918
+ const { dialecteConfig: r, hooks: s, context: o, query: f, parentRef: d, record: v, mappings: g } = m;
919
919
  let D = !0, R = v;
920
920
  if (s?.beforeClone) {
921
921
  const Y = s.beforeClone({ record: v });
@@ -926,8 +926,8 @@ async function Ri(m) {
926
926
  dialecteConfig: r,
927
927
  hooks: s,
928
928
  context: o,
929
- query: d,
930
- parentRef: f,
929
+ query: f,
930
+ parentRef: d,
931
931
  params: {
932
932
  tagName: R.tagName,
933
933
  namespace: R.namespace,
@@ -946,7 +946,7 @@ async function Ri(m) {
946
946
  dialecteConfig: r,
947
947
  hooks: s,
948
948
  context: o,
949
- query: d,
949
+ query: f,
950
950
  parentRef: ce(K),
951
951
  record: Y,
952
952
  mappings: g
@@ -954,39 +954,39 @@ async function Ri(m) {
954
954
  return K;
955
955
  }
956
956
  async function Ii(m) {
957
- const { hooks: r, context: s, query: o, ref: d } = m, f = await me({ context: s, ref: d });
958
- if (we(f, {
959
- detail: `Record not found (tagName=${d.tagName}, id=${d.id})`,
957
+ const { hooks: r, context: s, query: o, ref: f } = m, d = await me({ context: s, ref: f });
958
+ if (we(d, {
959
+ detail: `Record not found (tagName=${f.tagName}, id=${f.id})`,
960
960
  key: "ELEMENT_NOT_FOUND",
961
- ref: d
962
- }), we(f.parent, {
961
+ ref: f
962
+ }), we(d.parent, {
963
963
  detail: "Cannot delete root element",
964
964
  key: "PROTECTED_ROOT"
965
965
  }), r?.beforeDelete) {
966
- const R = await r.beforeDelete({ record: f, query: o });
966
+ const R = await r.beforeDelete({ record: d, query: o });
967
967
  Tr({ context: s, operations: R });
968
968
  }
969
- await Pi({ context: s, record: f }), et({ context: s, status: "deleted", record: f });
970
- const v = ce(f.parent), g = await me({ context: s, ref: v });
969
+ await Pi({ context: s, record: d }), et({ context: s, status: "deleted", record: d });
970
+ const v = ce(d.parent), g = await me({ context: s, ref: v });
971
971
  we(g, {
972
- detail: `Parent record not found (tagName=${f.parent.tagName}, id=${f.parent.id})`,
972
+ detail: `Parent record not found (tagName=${d.parent.tagName}, id=${d.parent.id})`,
973
973
  key: "ELEMENT_NOT_FOUND"
974
974
  });
975
975
  const D = {
976
976
  ...g,
977
- children: g.children.filter((R) => R.id !== f.id)
977
+ children: g.children.filter((R) => R.id !== d.id)
978
978
  };
979
979
  return et({ context: s, status: "updated", oldRecord: g, newRecord: D }), D;
980
980
  }
981
981
  async function Pi(m) {
982
982
  const { context: r, record: s } = m;
983
983
  for (const o of s.children) {
984
- const d = ce(o), f = await me({ context: r, ref: d });
985
- f && (f.children.length > 0 && await Pi({ context: r, record: f }), et({ context: r, status: "deleted", record: f }));
984
+ const f = ce(o), d = await me({ context: r, ref: f });
985
+ d && (d.children.length > 0 && await Pi({ context: r, record: d }), et({ context: r, status: "deleted", record: d }));
986
986
  }
987
987
  }
988
988
  async function Fi(m) {
989
- const { dialecteConfig: r, hooks: s, context: o, query: d, parentRef: f, params: v } = m, g = Ko(v.attributes);
989
+ const { dialecteConfig: r, hooks: s, context: o, query: f, parentRef: d, params: v } = m, g = qo(v.attributes);
990
990
  if (g) {
991
991
  const [D] = await Er({
992
992
  context: o,
@@ -1002,21 +1002,21 @@ async function Fi(m) {
1002
1002
  dialecteConfig: r,
1003
1003
  hooks: s,
1004
1004
  context: o,
1005
- query: d,
1006
- parentRef: f,
1005
+ query: f,
1006
+ parentRef: d,
1007
1007
  params: v
1008
1008
  });
1009
1009
  }
1010
- function Ko(m) {
1010
+ function qo(m) {
1011
1011
  const r = Array.isArray(m) ? Object.fromEntries(m.map((o) => [o.name, o.value])) : m;
1012
1012
  return Object.values(r).some((o) => o !== void 0 && o !== "") ? r : void 0;
1013
1013
  }
1014
1014
  async function Bi(m) {
1015
- const { dialecteConfig: r, hooks: s, context: o, query: d, ref: f, params: v } = m, { attributes: g, value: D } = v, R = await me({ context: o, ref: f });
1015
+ const { dialecteConfig: r, hooks: s, context: o, query: f, ref: d, params: v } = m, { attributes: g, value: D } = v, R = await me({ context: o, ref: d });
1016
1016
  we(R, {
1017
- detail: `Record not found (tagName=${f.tagName}, id=${f.id})`,
1017
+ detail: `Record not found (tagName=${d.tagName}, id=${d.id})`,
1018
1018
  key: "ELEMENT_NOT_FOUND",
1019
- ref: f
1019
+ ref: d
1020
1020
  });
1021
1021
  let K = R.attributes;
1022
1022
  if (g) {
@@ -1040,15 +1040,15 @@ async function Bi(m) {
1040
1040
  const Y = await s.afterUpdated({
1041
1041
  oldRecord: R,
1042
1042
  newRecord: B,
1043
- query: d
1043
+ query: f
1044
1044
  });
1045
1045
  Tr({ context: o, operations: Y });
1046
1046
  }
1047
1047
  return B;
1048
1048
  }
1049
- class qo extends Di {
1050
- constructor(r, s, o, d) {
1051
- super(r, s), this.hooks = o, this.query = d;
1049
+ class Lo extends Di {
1050
+ constructor(r, s, o, f) {
1051
+ super(r, s), this.hooks = o, this.query = f;
1052
1052
  }
1053
1053
  async addChild(r, s) {
1054
1054
  return kn({
@@ -1115,25 +1115,25 @@ class qo extends Di {
1115
1115
  });
1116
1116
  }
1117
1117
  }
1118
- function Lo(m) {
1118
+ function Uo(m) {
1119
1119
  const r = /* @__PURE__ */ new Map();
1120
1120
  for (const o of m) {
1121
- const d = (o.status === "deleted" ? o.oldRecord : o.newRecord).id, f = r.get(d);
1122
- if (!f) {
1123
- r.set(d, o);
1121
+ const f = (o.status === "deleted" ? o.oldRecord : o.newRecord).id, d = r.get(f);
1122
+ if (!d) {
1123
+ r.set(f, o);
1124
1124
  continue;
1125
1125
  }
1126
- f.status === "created" ? o.status === "updated" ? r.set(d, {
1126
+ d.status === "created" ? o.status === "updated" ? r.set(f, {
1127
1127
  status: "created",
1128
1128
  oldRecord: void 0,
1129
1129
  newRecord: o.newRecord
1130
- }) : o.status === "deleted" && r.delete(d) : f.status === "updated" && (o.status === "updated" ? r.set(d, {
1130
+ }) : o.status === "deleted" && r.delete(f) : d.status === "updated" && (o.status === "updated" ? r.set(f, {
1131
1131
  status: "updated",
1132
- oldRecord: f.oldRecord,
1132
+ oldRecord: d.oldRecord,
1133
1133
  newRecord: o.newRecord
1134
- }) : o.status === "deleted" && r.set(d, {
1134
+ }) : o.status === "deleted" && r.set(f, {
1135
1135
  status: "deleted",
1136
- oldRecord: f.oldRecord,
1136
+ oldRecord: d.oldRecord,
1137
1137
  newRecord: void 0
1138
1138
  }));
1139
1139
  }
@@ -1144,31 +1144,31 @@ function Lo(m) {
1144
1144
  deletes: s.filter((o) => o.status === "deleted")
1145
1145
  };
1146
1146
  }
1147
- async function Uo(m) {
1148
- const { stagedOperations: r, store: s, documentId: o, documentState: d } = m, { creates: f, updates: v, deletes: g } = Lo(r), D = f.length + v.length + g.length;
1149
- d.loading = !0, d.progress = { message: "Committing changes...", current: 0, total: D };
1147
+ async function Vo(m) {
1148
+ const { stagedOperations: r, store: s, documentId: o, documentState: f } = m, { creates: d, updates: v, deletes: g } = Uo(r), D = d.length + v.length + g.length;
1149
+ f.loading = !0, f.progress = { message: "Committing changes...", current: 0, total: D };
1150
1150
  try {
1151
1151
  await s.commit({
1152
1152
  documentId: o,
1153
- creates: f.map((R) => R.newRecord),
1153
+ creates: d.map((R) => R.newRecord),
1154
1154
  updates: v.map((R) => R.newRecord),
1155
1155
  deletes: g.map((R) => R.oldRecord.id),
1156
1156
  onProgress: (R, K) => {
1157
- d.progress = { message: "Committing changes...", current: R, total: K };
1157
+ f.progress = { message: "Committing changes...", current: R, total: K };
1158
1158
  }
1159
1159
  });
1160
1160
  } catch (R) {
1161
- throw d.loading = !1, d.progress = null, R;
1161
+ throw f.loading = !1, f.progress = null, R;
1162
1162
  }
1163
- d.lastUpdate = Date.now();
1163
+ f.lastUpdate = Date.now();
1164
1164
  }
1165
- class Vo extends Si {
1166
- constructor(r, s, o, d, f) {
1167
- super(r, s, o), this.stagedOperations = [], this.recordCache = /* @__PURE__ */ new Map(), this.cumulativeCloneMappings = [], this.documentActivity = d, this.hooks = f;
1165
+ class $o extends Si {
1166
+ constructor(r, s, o, f, d) {
1167
+ super(r, s, o), this.stagedOperations = [], this.recordCache = /* @__PURE__ */ new Map(), this.cumulativeCloneMappings = [], this.documentActivity = f, this.hooks = d;
1168
1168
  }
1169
1169
  //== Untyped namespace
1170
1170
  get any() {
1171
- return this._anyTx ??= new qo(
1171
+ return this._anyTx ??= new Lo(
1172
1172
  () => this.context,
1173
1173
  this.dialecteConfig,
1174
1174
  this.hooks,
@@ -1345,7 +1345,7 @@ class Vo extends Si {
1345
1345
  * Merges operations by ID to optimize database writes.
1346
1346
  */
1347
1347
  async commit() {
1348
- await Uo({
1348
+ await Vo({
1349
1349
  stagedOperations: this.stagedOperations,
1350
1350
  store: this.store,
1351
1351
  documentId: this.documentId,
@@ -1356,15 +1356,15 @@ class Vo extends Si {
1356
1356
  function Ht(m) {
1357
1357
  return m.recordCache !== void 0;
1358
1358
  }
1359
- class $o {
1360
- constructor(r, s, o, d, f, v) {
1359
+ class Go {
1360
+ constructor(r, s, o, f, d, v) {
1361
1361
  this.state = {
1362
1362
  loading: !1,
1363
1363
  error: null,
1364
1364
  progress: null,
1365
1365
  history: [],
1366
1366
  lastUpdate: null
1367
- }, this.activeTransactions = 0, this.store = r, this.config = s, this.documentId = o, this.hooks = f, this.extensionsRegistry = d, this.channel = v, this.channel.onmessage = (g) => {
1367
+ }, this.activeTransactions = 0, this.store = r, this.config = s, this.documentId = o, this.hooks = d, this.extensionsRegistry = f, this.channel = v, this.channel.onmessage = (g) => {
1368
1368
  g.data?.type === "commit" && g.data.documentId === this.documentId && (this.state.lastUpdate = g.data.timestamp ?? Date.now());
1369
1369
  };
1370
1370
  }
@@ -1392,7 +1392,7 @@ class $o {
1392
1392
  * e.g. SclDocument overrides this to return new SclTransaction(...)
1393
1393
  */
1394
1394
  createTransaction() {
1395
- return new Vo(this.store, this.config, this.documentId, this.state, this.hooks);
1395
+ return new $o(this.store, this.config, this.documentId, this.state, this.hooks);
1396
1396
  }
1397
1397
  async transaction(r, s) {
1398
1398
  this.activeTransactions > 0 && $e("CONCURRENT_TRANSACTION", {
@@ -1400,7 +1400,7 @@ class $o {
1400
1400
  }), this.activeTransactions++, this.state.loading = !0, this.state.error = null;
1401
1401
  const o = this.withAllExtensions(this.createTransaction());
1402
1402
  try {
1403
- const d = await r(o);
1403
+ const f = await r(o);
1404
1404
  return await o.commit(), this.channel.postMessage({
1405
1405
  type: "commit",
1406
1406
  documentId: this.documentId,
@@ -1409,11 +1409,11 @@ class $o {
1409
1409
  method: "commit",
1410
1410
  message: s?.label ?? "Changes committed",
1411
1411
  timestamp: Date.now()
1412
- }), d;
1413
- } catch (d) {
1412
+ }), f;
1413
+ } catch (f) {
1414
1414
  throw this.state.progress = null, this.state.error ?? $e("UNKNOWN", {
1415
- detail: d instanceof Error ? d.message : String(d),
1416
- cause: d instanceof Error ? d : void 0
1415
+ detail: f instanceof Error ? f.message : String(f),
1416
+ cause: f instanceof Error ? f : void 0
1417
1417
  });
1418
1418
  } finally {
1419
1419
  this.activeTransactions--, this.state.loading = !1;
@@ -1451,15 +1451,15 @@ class $o {
1451
1451
  });
1452
1452
  }
1453
1453
  this.activeTransactions--, this.state.loading = !1;
1454
- const d = o.getStagedOperations(), f = {
1455
- creates: d.filter((g) => g.status === "created").length,
1456
- updates: d.filter((g) => g.status === "updated").length,
1457
- deletes: d.filter((g) => g.status === "deleted").length
1454
+ const f = o.getStagedOperations(), d = {
1455
+ creates: f.filter((g) => g.status === "created").length,
1456
+ updates: f.filter((g) => g.status === "updated").length,
1457
+ deletes: f.filter((g) => g.status === "deleted").length
1458
1458
  };
1459
1459
  let v = !1;
1460
1460
  return {
1461
- operations: d,
1462
- summary: f,
1461
+ operations: f,
1462
+ summary: d,
1463
1463
  commit: async () => {
1464
1464
  if (!v) {
1465
1465
  v = !0, this.activeTransactions++, this.state.loading = !0;
@@ -1498,9 +1498,9 @@ class $o {
1498
1498
  await this.store.destroy();
1499
1499
  }
1500
1500
  }
1501
- const ft = "_documents", Ye = "_changeLog", ze = "_meta", Go = "xel_";
1502
- function Wo(m) {
1503
- return `${Go}${m}`;
1501
+ const ft = "_documents", Ye = "_changeLog", ze = "_meta", Wo = "xel_";
1502
+ function Xo(m) {
1503
+ return `${Wo}${m}`;
1504
1504
  }
1505
1505
  const oi = {
1506
1506
  primaryKey: "id",
@@ -1519,27 +1519,27 @@ const oi = {
1519
1519
  compoundIndexes: [],
1520
1520
  arrayIndexes: []
1521
1521
  };
1522
- var Xo = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
1522
+ var Yo = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
1523
1523
  function ji(m) {
1524
1524
  return m && m.__esModule && Object.prototype.hasOwnProperty.call(m, "default") ? m.default : m;
1525
1525
  }
1526
- function Yo(m) {
1526
+ function zo(m) {
1527
1527
  if (Object.prototype.hasOwnProperty.call(m, "__esModule")) return m;
1528
1528
  var r = m.default;
1529
1529
  if (typeof r == "function") {
1530
1530
  var s = function o() {
1531
- var d = !1;
1531
+ var f = !1;
1532
1532
  try {
1533
- d = this instanceof o;
1533
+ f = this instanceof o;
1534
1534
  } catch {
1535
1535
  }
1536
- return d ? Reflect.construct(r, arguments, this.constructor) : r.apply(this, arguments);
1536
+ return f ? Reflect.construct(r, arguments, this.constructor) : r.apply(this, arguments);
1537
1537
  };
1538
1538
  s.prototype = r.prototype;
1539
1539
  } else s = {};
1540
1540
  return Object.defineProperty(s, "__esModule", { value: !0 }), Object.keys(m).forEach(function(o) {
1541
- var d = Object.getOwnPropertyDescriptor(m, o);
1542
- Object.defineProperty(s, o, d.get ? d : {
1541
+ var f = Object.getOwnPropertyDescriptor(m, o);
1542
+ Object.defineProperty(s, o, f.get ? f : {
1543
1543
  enumerable: !0,
1544
1544
  get: function() {
1545
1545
  return m[o];
@@ -1547,12 +1547,12 @@ function Yo(m) {
1547
1547
  });
1548
1548
  }), s;
1549
1549
  }
1550
- var Dn = { exports: {} }, zo = Dn.exports, ci;
1551
- function Ho() {
1550
+ var Dn = { exports: {} }, Ho = Dn.exports, ci;
1551
+ function Qo() {
1552
1552
  return ci || (ci = 1, (function(m, r) {
1553
1553
  (function(s, o) {
1554
1554
  m.exports = o();
1555
- })(zo, function() {
1555
+ })(Ho, function() {
1556
1556
  var s = function(e, t) {
1557
1557
  return (s = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(n, i) {
1558
1558
  n.__proto__ = i;
@@ -1565,17 +1565,17 @@ function Ho() {
1565
1565
  return e;
1566
1566
  }).apply(this, arguments);
1567
1567
  };
1568
- function d(e, t, n) {
1568
+ function f(e, t, n) {
1569
1569
  for (var i, a = 0, u = t.length; a < u; a++) !i && a in t || ((i = i || Array.prototype.slice.call(t, 0, a))[a] = t[a]);
1570
1570
  return e.concat(i || Array.prototype.slice.call(t));
1571
1571
  }
1572
- var f = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Xo, v = Object.keys, g = Array.isArray;
1572
+ var d = typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : typeof window < "u" ? window : Yo, v = Object.keys, g = Array.isArray;
1573
1573
  function D(e, t) {
1574
1574
  return typeof t != "object" || v(t).forEach(function(n) {
1575
1575
  e[n] = t[n];
1576
1576
  }), e;
1577
1577
  }
1578
- typeof Promise > "u" || f.Promise || (f.Promise = Promise);
1578
+ typeof Promise > "u" || d.Promise || (d.Promise = Promise);
1579
1579
  var R = Object.getPrototypeOf, K = {}.hasOwnProperty;
1580
1580
  function B(e, t) {
1581
1581
  return K.call(e, t);
@@ -1605,7 +1605,7 @@ function Ho() {
1605
1605
  if (!e) throw new Error("Assertion Failed");
1606
1606
  }
1607
1607
  function J(e) {
1608
- f.setImmediate ? setImmediate(e) : setTimeout(e, 0);
1608
+ d.setImmediate ? setImmediate(e) : setTimeout(e, 0);
1609
1609
  }
1610
1610
  function he(e, t) {
1611
1611
  if (typeof t == "string" && B(e, t)) return e[t];
@@ -1646,9 +1646,9 @@ function Ho() {
1646
1646
  return t + e + "Array";
1647
1647
  });
1648
1648
  }))).filter(function(e) {
1649
- return f[e];
1649
+ return d[e];
1650
1650
  }), Bt = new Set(Ve.map(function(e) {
1651
- return f[e];
1651
+ return d[e];
1652
1652
  })), Ue = null;
1653
1653
  function He(e) {
1654
1654
  return Ue = /* @__PURE__ */ new WeakMap(), e = (function t(n) {
@@ -2066,11 +2066,11 @@ function Ho() {
2066
2066
  var n, i = H;
2067
2067
  (t ? !De.echoes || sn++ && e === H : !sn || --sn && e === H) || queueMicrotask(t ? (function(a) {
2068
2068
  ++cn, De.echoes && --De.echoes != 0 || (De.echoes = De.awaits = De.id = 0), an.push(H), st(a, !0);
2069
- }).bind(null, e) : zi), e !== H && (H = e, i === it && (it.env = Or()), Fn && (n = it.env.Promise, t = e.env, (i.global || e.global) && (Object.defineProperty(f, "Promise", t.PromiseProp), n.all = t.all, n.race = t.race, n.resolve = t.resolve, n.reject = t.reject, t.allSettled && (n.allSettled = t.allSettled), t.any && (n.any = t.any))));
2069
+ }).bind(null, e) : zi), e !== H && (H = e, i === it && (it.env = Or()), Fn && (n = it.env.Promise, t = e.env, (i.global || e.global) && (Object.defineProperty(d, "Promise", t.PromiseProp), n.all = t.all, n.race = t.race, n.resolve = t.resolve, n.reject = t.reject, t.allSettled && (n.allSettled = t.allSettled), t.any && (n.any = t.any))));
2070
2070
  }
2071
2071
  function Or() {
2072
- var e = f.Promise;
2073
- return Fn ? { Promise: e, PromiseProp: Object.getOwnPropertyDescriptor(f, "Promise"), all: e.all, race: e.race, allSettled: e.allSettled, any: e.any, resolve: e.resolve, reject: e.reject } : {};
2072
+ var e = d.Promise;
2073
+ return Fn ? { Promise: e, PromiseProp: Object.getOwnPropertyDescriptor(d, "Promise"), all: e.all, race: e.race, allSettled: e.allSettled, any: e.any, resolve: e.resolve, reject: e.reject } : {};
2074
2074
  }
2075
2075
  function gt(e, t, n, i, a) {
2076
2076
  var u = H;
@@ -2536,7 +2536,7 @@ function Ho() {
2536
2536
  var t = this["@@propmod"];
2537
2537
  if (t.add !== void 0) {
2538
2538
  var n = t.add;
2539
- if (g(n)) return d(d([], g(e) ? e : [], !0), n).sort();
2539
+ if (g(n)) return f(f([], g(e) ? e : [], !0), n).sort();
2540
2540
  if (typeof n == "number") return (Number(e) || 0) + n;
2541
2541
  if (typeof n == "bigint") try {
2542
2542
  return BigInt(e) + n;
@@ -3470,7 +3470,7 @@ function Ho() {
3470
3470
  !t[u] || (_ = t[u].idxByName[T]) && (_.name = b, delete t[u].idxByName[T], t[u].idxByName[b] = _);
3471
3471
  }
3472
3472
  }
3473
- typeof navigator < "u" && /Safari/.test(navigator.userAgent) && !/(Chrome\/|Edge\/)/.test(navigator.userAgent) && f.WorkerGlobalScope && f instanceof f.WorkerGlobalScope && [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604 && (e._hasGetAll = !1);
3473
+ typeof navigator < "u" && /Safari/.test(navigator.userAgent) && !/(Chrome\/|Edge\/)/.test(navigator.userAgent) && d.WorkerGlobalScope && d instanceof d.WorkerGlobalScope && [].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1] < 604 && (e._hasGetAll = !1);
3474
3474
  }
3475
3475
  function $r(e) {
3476
3476
  return e.split(",").map(function(t, n) {
@@ -3843,7 +3843,7 @@ function Ho() {
3843
3843
  function T(y) {
3844
3844
  var O, w, x, C = H.trans, N = y.keys || lr(i, y);
3845
3845
  if (!N) throw new Error("Keys missing");
3846
- return (y = y.type === "add" || y.type === "put" ? o(o({}, y), { keys: N }) : o({}, y)).type !== "delete" && (y.values = d([], y.values)), y.keys && (y.keys = d([], y.keys)), O = n, x = N, ((w = y).type === "add" ? Promise.resolve([]) : O.getMany({ trans: w.trans, keys: x, cache: "immutable" })).then(function(A) {
3846
+ return (y = y.type === "add" || y.type === "put" ? o(o({}, y), { keys: N }) : o({}, y)).type !== "delete" && (y.values = f([], y.values)), y.keys && (y.keys = f([], y.keys)), O = n, x = N, ((w = y).type === "add" ? Promise.resolve([]) : O.getMany({ trans: w.trans, keys: x, cache: "immutable" })).then(function(A) {
3847
3847
  var k = N.map(function(P, F) {
3848
3848
  var q, V, L, U = A[F], G = { onerror: null, onsuccess: null };
3849
3849
  return y.type === "delete" ? p.fire.call(G, P, U, C) : y.type === "add" || U === void 0 ? (q = b.fire.call(G, P, y.values[F], C), P == null && q != null && (y.keys[F] = P = q, i.outbound || de(y.values[F], i.keyPath, P))) : (q = ur(U, y.values[F]), (V = _.fire.call(G, q, P, U, C)) && (L = y.values[F], Object.keys(V).forEach(function($) {
@@ -4440,7 +4440,7 @@ function Ho() {
4440
4440
  this._subscribe = e;
4441
4441
  }
4442
4442
  try {
4443
- Cn = { indexedDB: f.indexedDB || f.mozIndexedDB || f.webkitIndexedDB || f.msIndexedDB, IDBKeyRange: f.IDBKeyRange || f.webkitIDBKeyRange };
4443
+ Cn = { indexedDB: d.indexedDB || d.mozIndexedDB || d.webkitIndexedDB || d.msIndexedDB, IDBKeyRange: d.IDBKeyRange || d.webkitIDBKeyRange };
4444
4444
  } catch {
4445
4445
  Cn = { indexedDB: null, IDBKeyRange: null };
4446
4446
  }
@@ -4590,22 +4590,22 @@ function Ho() {
4590
4590
  });
4591
4591
  })(Dn)), Dn.exports;
4592
4592
  }
4593
- var Qo = Ho();
4594
- const _r = /* @__PURE__ */ ji(Qo), ui = /* @__PURE__ */ Symbol.for("Dexie"), dt = globalThis[ui] || (globalThis[ui] = _r);
4593
+ var Zo = Qo();
4594
+ const _r = /* @__PURE__ */ ji(Zo), ui = /* @__PURE__ */ Symbol.for("Dexie"), dt = globalThis[ui] || (globalThis[ui] = _r);
4595
4595
  if (_r.semVer !== dt.semVer)
4596
4596
  throw new Error(`Two different versions of Dexie loaded in the same app: ${_r.semVer} and ${dt.semVer}`);
4597
4597
  const {
4598
- liveQuery: Va,
4599
- mergeRanges: $a,
4600
- rangesOverlap: Ga,
4601
- RangeSet: Wa,
4602
- cmp: Xa,
4603
- Entity: Ya,
4604
- PropModification: za,
4605
- replacePrefix: Ha,
4606
- add: Qa,
4607
- remove: Za,
4608
- DexieYProvider: Ja
4598
+ liveQuery: $a,
4599
+ mergeRanges: Ga,
4600
+ rangesOverlap: Wa,
4601
+ RangeSet: Xa,
4602
+ cmp: Ya,
4603
+ Entity: za,
4604
+ PropModification: Ha,
4605
+ replacePrefix: Qa,
4606
+ add: Za,
4607
+ remove: Ja,
4608
+ DexieYProvider: es
4609
4609
  } = dt;
4610
4610
  function Et(m) {
4611
4611
  const s = [m.autoIncrement ? `++${m.primaryKey}` : m.primaryKey];
@@ -4617,15 +4617,15 @@ function Et(m) {
4617
4617
  s.push(`*${o}`);
4618
4618
  return s.join(", ");
4619
4619
  }
4620
- const Zo = {
4620
+ const Jo = {
4621
4621
  primaryKey: "id",
4622
4622
  indexes: ["tagName"],
4623
4623
  compoundIndexes: [],
4624
4624
  arrayIndexes: []
4625
4625
  };
4626
- class Jo {
4626
+ class ea {
4627
4627
  constructor(r, s) {
4628
- this.schemaVersion = 1, this.knownDocuments = /* @__PURE__ */ new Map(), this.schemaLock = Promise.resolve(), this.name = r, this.dexieRecordSchema = Et(s?.recordSchema ?? Zo), this.db = new dt(r);
4628
+ this.schemaVersion = 1, this.knownDocuments = /* @__PURE__ */ new Map(), this.schemaLock = Promise.resolve(), this.name = r, this.dexieRecordSchema = Et(s?.recordSchema ?? Jo), this.db = new dt(r);
4629
4629
  }
4630
4630
  // --- Lifecycle ---
4631
4631
  async open() {
@@ -4639,8 +4639,8 @@ class Jo {
4639
4639
  await r.open();
4640
4640
  const s = await r.table(ft).toArray(), o = await r.table(ze).get("schemaVersion");
4641
4641
  r.close();
4642
- for (const d of s)
4643
- this.knownDocuments.set(d.id, d);
4642
+ for (const f of s)
4643
+ this.knownDocuments.set(f.id, f);
4644
4644
  this.schemaVersion = o?.value ?? 1;
4645
4645
  } catch {
4646
4646
  r.close();
@@ -4681,8 +4681,8 @@ class Jo {
4681
4681
  if (s)
4682
4682
  return this.db.table(this.resolveTableName(s)).get(r);
4683
4683
  for (const o of this.knownDocuments.keys()) {
4684
- const d = await this.db.table(this.resolveTableName(o)).get(r);
4685
- if (d) return d;
4684
+ const f = await this.db.table(this.resolveTableName(o)).get(r);
4685
+ if (f) return f;
4686
4686
  }
4687
4687
  }
4688
4688
  async getByDocumentId(r) {
@@ -4693,10 +4693,10 @@ class Jo {
4693
4693
  }
4694
4694
  // --- Writes ---
4695
4695
  async bulkWrite(r, s) {
4696
- const { creates: o, updates: d, deletes: f } = s, v = this.db.table(this.resolveTableName(r));
4696
+ const { creates: o, updates: f, deletes: d } = s, v = this.db.table(this.resolveTableName(r));
4697
4697
  await this.db.transaction("rw", v, async () => {
4698
- if (o?.length && await v.bulkAdd(o), d?.length)
4699
- for (const { recordId: g, ...D } of d) {
4698
+ if (o?.length && await v.bulkAdd(o), f?.length)
4699
+ for (const { recordId: g, ...D } of f) {
4700
4700
  const R = await v.get(g);
4701
4701
  if (!R) continue;
4702
4702
  const K = { ...D };
@@ -4718,11 +4718,11 @@ class Jo {
4718
4718
  }
4719
4719
  await v.update(g, K);
4720
4720
  }
4721
- f?.length && await v.bulkDelete(f);
4721
+ d?.length && await v.bulkDelete(d);
4722
4722
  });
4723
4723
  }
4724
4724
  async commit(r) {
4725
- const { documentId: s, creates: o, updates: d, deletes: f, onProgress: v } = r, g = this.db.table(this.resolveTableName(s)), D = o.length + d.length + f.length;
4725
+ const { documentId: s, creates: o, updates: f, deletes: d, onProgress: v } = r, g = this.db.table(this.resolveTableName(s)), D = o.length + f.length + d.length;
4726
4726
  let R = 0;
4727
4727
  try {
4728
4728
  await this.db.transaction(
@@ -4731,7 +4731,7 @@ class Jo {
4731
4731
  this.db.table(Ye),
4732
4732
  this.db.table(ze),
4733
4733
  async () => {
4734
- const K = d.length > 0 ? await g.bulkGet(d.map((z) => z.id)) : [], B = f.length > 0 ? await g.bulkGet(f) : [];
4734
+ const K = f.length > 0 ? await g.bulkGet(f.map((z) => z.id)) : [], B = d.length > 0 ? await g.bulkGet(d) : [];
4735
4735
  if (o.length > 0)
4736
4736
  try {
4737
4737
  await g.bulkAdd(o), R += o.length, v(R, D);
@@ -4741,18 +4741,18 @@ class Jo {
4741
4741
  cause: z instanceof Error ? z : void 0
4742
4742
  });
4743
4743
  }
4744
- if (d.length > 0)
4744
+ if (f.length > 0)
4745
4745
  try {
4746
- await g.bulkPut(d), R += d.length, v(R, D);
4746
+ await g.bulkPut(f), R += f.length, v(R, D);
4747
4747
  } catch (z) {
4748
4748
  $e("STORE_BULK_UPDATE_FAILED", {
4749
4749
  detail: z instanceof Error ? z.message : String(z),
4750
4750
  cause: z instanceof Error ? z : void 0
4751
4751
  });
4752
4752
  }
4753
- if (f.length > 0)
4753
+ if (d.length > 0)
4754
4754
  try {
4755
- await g.bulkDelete(f), R += f.length, v(R, D);
4755
+ await g.bulkDelete(d), R += d.length, v(R, D);
4756
4756
  } catch (z) {
4757
4757
  $e("STORE_DELETE_FAILED", {
4758
4758
  detail: z instanceof Error ? z.message : String(z),
@@ -4767,7 +4767,7 @@ class Jo {
4767
4767
  timestamp: Date.now(),
4768
4768
  operations: {
4769
4769
  creates: o,
4770
- updates: d.map((z, ie) => ({
4770
+ updates: f.map((z, ie) => ({
4771
4771
  before: K[ie],
4772
4772
  after: z
4773
4773
  })),
@@ -4792,19 +4792,19 @@ class Jo {
4792
4792
  if (s === 0) return;
4793
4793
  const o = await this.db.table(Ye).where({ documentId: r, sequenceNumber: s }).first();
4794
4794
  if (!o) return;
4795
- const d = this.db.table(this.resolveTableName(r));
4796
- await this.db.transaction("rw", d, this.db.table(ze), async () => {
4797
- const { creates: f, updates: v, deletes: g } = o.operations;
4798
- f.length > 0 && await d.bulkDelete(f.map((D) => D.id)), v.length > 0 && await d.bulkPut(v.map((D) => D.before)), g.length > 0 && await d.bulkAdd(g), await this.setHead(r, s - 1);
4795
+ const f = this.db.table(this.resolveTableName(r));
4796
+ await this.db.transaction("rw", f, this.db.table(ze), async () => {
4797
+ const { creates: d, updates: v, deletes: g } = o.operations;
4798
+ d.length > 0 && await f.bulkDelete(d.map((D) => D.id)), v.length > 0 && await f.bulkPut(v.map((D) => D.before)), g.length > 0 && await f.bulkAdd(g), await this.setHead(r, s - 1);
4799
4799
  });
4800
4800
  }
4801
4801
  async redo(r) {
4802
- const o = await this.getHead(r) + 1, d = await this.db.table(Ye).where({ documentId: r, sequenceNumber: o }).first();
4803
- if (!d) return;
4804
- const f = this.db.table(this.resolveTableName(r));
4805
- await this.db.transaction("rw", f, this.db.table(ze), async () => {
4806
- const { creates: v, updates: g, deletes: D } = d.operations;
4807
- v.length > 0 && await f.bulkAdd(v), g.length > 0 && await f.bulkPut(g.map((R) => R.after)), D.length > 0 && await f.bulkDelete(D.map((R) => R.id)), await this.setHead(r, o);
4802
+ const o = await this.getHead(r) + 1, f = await this.db.table(Ye).where({ documentId: r, sequenceNumber: o }).first();
4803
+ if (!f) return;
4804
+ const d = this.db.table(this.resolveTableName(r));
4805
+ await this.db.transaction("rw", d, this.db.table(ze), async () => {
4806
+ const { creates: v, updates: g, deletes: D } = f.operations;
4807
+ v.length > 0 && await d.bulkAdd(v), g.length > 0 && await d.bulkPut(g.map((R) => R.after)), D.length > 0 && await d.bulkDelete(D.map((R) => R.id)), await this.setHead(r, o);
4808
4808
  });
4809
4809
  }
4810
4810
  async getChangeLog(r) {
@@ -4847,21 +4847,21 @@ class Jo {
4847
4847
  * Resolve the Dexie table name for a documentId.
4848
4848
  */
4849
4849
  resolveTableName(r) {
4850
- return Wo(r);
4850
+ return Xo(r);
4851
4851
  }
4852
4852
  }
4853
4853
  function li() {
4854
4854
  return new Promise((m) => setTimeout(m, 0));
4855
4855
  }
4856
- function ea(m, r, s) {
4856
+ function ta(m, r, s) {
4857
4857
  if (r.type === "local") {
4858
4858
  const o = { recordSchema: s.database.recordSchema };
4859
- return new Jo(m, o);
4859
+ return new ea(m, o);
4860
4860
  }
4861
4861
  return r.store;
4862
4862
  }
4863
4863
  var Qt = { exports: {} }, An = { exports: {} }, fi;
4864
- function ta() {
4864
+ function na() {
4865
4865
  return fi || (fi = 1, (function(m, r) {
4866
4866
  Object.defineProperty(r, "__esModule", { value: !0 }), r.ParsingError = void 0;
4867
4867
  class s extends Error {
@@ -4871,22 +4871,22 @@ function ta() {
4871
4871
  }
4872
4872
  r.ParsingError = s;
4873
4873
  let o;
4874
- function d() {
4874
+ function f() {
4875
4875
  return D(!1) || Y() || B() || K() || g();
4876
4876
  }
4877
- function f() {
4877
+ function d() {
4878
4878
  return j(/\s*/), D(!0) || B() || R() || g();
4879
4879
  }
4880
4880
  function v() {
4881
4881
  const ne = g(), Z = [];
4882
- let J, he = f();
4882
+ let J, he = d();
4883
4883
  for (; he; ) {
4884
4884
  if (he.node.type === "Element") {
4885
4885
  if (J)
4886
4886
  throw new Error("Found multiple root nodes");
4887
4887
  J = he.node;
4888
4888
  }
4889
- he.excluded || Z.push(he.node), he = f();
4889
+ he.excluded || Z.push(he.node), he = d();
4890
4890
  }
4891
4891
  if (!J)
4892
4892
  throw new s("Failed to parse XML", "Root Element not found");
@@ -4939,9 +4939,9 @@ function ta() {
4939
4939
  node: J
4940
4940
  };
4941
4941
  j(/\??>/);
4942
- let de = d();
4942
+ let de = f();
4943
4943
  for (; de; )
4944
- de.excluded || J.children.push(de.node), de = d();
4944
+ de.excluded || J.children.push(de.node), de = f();
4945
4945
  if (o.options.strictMode) {
4946
4946
  const ve = `</${J.name}>`;
4947
4947
  if (o.xml.startsWith(ve))
@@ -5043,14 +5043,14 @@ function ta() {
5043
5043
  })(An, An.exports)), An.exports;
5044
5044
  }
5045
5045
  var di = Qt.exports, hi;
5046
- function na() {
5046
+ function ra() {
5047
5047
  return hi || (hi = 1, (function(m, r) {
5048
5048
  var s = di && di.__importDefault || function(M) {
5049
5049
  return M && M.__esModule ? M : { default: M };
5050
5050
  };
5051
5051
  Object.defineProperty(r, "__esModule", { value: !0 });
5052
- const o = s(/* @__PURE__ */ ta());
5053
- function d(M) {
5052
+ const o = s(/* @__PURE__ */ na());
5053
+ function f(M) {
5054
5054
  if (!M.options.indentation && !M.options.lineSeparator)
5055
5055
  return;
5056
5056
  M.content += M.options.lineSeparator;
@@ -5058,7 +5058,7 @@ function na() {
5058
5058
  for (j = 0; j < M.level; j++)
5059
5059
  M.content += M.options.indentation;
5060
5060
  }
5061
- function f(M) {
5061
+ function d(M) {
5062
5062
  M.content = M.content.replace(/ +$/, "");
5063
5063
  let j;
5064
5064
  for (j = 0; j < M.level; j++)
@@ -5082,14 +5082,14 @@ function na() {
5082
5082
  const ie = M.trim();
5083
5083
  (j.options.lineSeparator || ie.length === 0) && (M = ie);
5084
5084
  }
5085
- M.length > 0 && (!z && j.content.length > 0 && d(j), v(j, M));
5085
+ M.length > 0 && (!z && j.content.length > 0 && f(j), v(j, M));
5086
5086
  }
5087
5087
  function R(M, j) {
5088
5088
  const z = "/" + M.join("/"), ie = M[M.length - 1];
5089
5089
  return j.includes(ie) || j.includes(z);
5090
5090
  }
5091
5091
  function K(M, j, z) {
5092
- if (j.path.push(M.name), !z && j.content.length > 0 && d(j), v(j, "<" + M.name), B(j, M.attributes), M.children === null || j.options.forceSelfClosingEmptyTag && M.children.length === 0) {
5092
+ if (j.path.push(M.name), !z && j.content.length > 0 && f(j), v(j, "<" + M.name), B(j, M.attributes), M.children === null || j.options.forceSelfClosingEmptyTag && M.children.length === 0) {
5093
5093
  const ie = j.options.whiteSpaceAtEndOfSelfclosingTag ? " />" : "/>";
5094
5094
  v(j, ie);
5095
5095
  } else if (M.children.length === 0)
@@ -5107,7 +5107,7 @@ function na() {
5107
5107
  }
5108
5108
  ie.forEach(function(Z) {
5109
5109
  g(Z, j, z || ye);
5110
- }), j.level--, !z && !ye && d(j), ne && f(j), v(j, "</" + M.name + ">");
5110
+ }), j.level--, !z && !ye && f(j), ne && d(j), v(j, "</" + M.name + ">");
5111
5111
  }
5112
5112
  j.path.pop();
5113
5113
  }
@@ -5123,7 +5123,7 @@ function na() {
5123
5123
  });
5124
5124
  }
5125
5125
  function Y(M, j) {
5126
- j.content.length > 0 && d(j), v(j, "<?" + M.name), v(j, " " + M.content.trim()), v(j, "?>");
5126
+ j.content.length > 0 && f(j), v(j, "<?" + M.name), v(j, " " + M.content.trim()), v(j, "?>");
5127
5127
  }
5128
5128
  function oe(M, j = {}) {
5129
5129
  j.indentation = "indentation" in j ? j.indentation : " ", j.collapseContent = j.collapseContent === !0, j.lineSeparator = "lineSeparator" in j ? j.lineSeparator : `\r
@@ -5143,15 +5143,15 @@ function na() {
5143
5143
  oe.minify = (M, j = {}) => oe(M, Object.assign(Object.assign({}, j), { indentation: "", lineSeparator: "" })), m.exports = oe, r.default = oe;
5144
5144
  })(Qt, Qt.exports)), Qt.exports;
5145
5145
  }
5146
- var ra = /* @__PURE__ */ na();
5147
- const ia = /* @__PURE__ */ ji(ra);
5148
- function oa(m) {
5149
- return ia(m);
5146
+ var ia = /* @__PURE__ */ ra();
5147
+ const oa = /* @__PURE__ */ ji(ia);
5148
+ function aa(m) {
5149
+ return oa(m);
5150
5150
  }
5151
5151
  const Mi = "_temp-idb-id";
5152
- async function aa(m) {
5152
+ async function sa(m) {
5153
5153
  const { extension: r, xmlDocument: s, filename: o } = m, g = `<?xml version="1.0" encoding="UTF-8"?>
5154
- ` + new XMLSerializer().serializeToString(s), D = oa(g), R = new Blob([D], { type: "application/xml" });
5154
+ ` + new XMLSerializer().serializeToString(s), D = aa(g), R = new Blob([D], { type: "application/xml" });
5155
5155
  if ("showSaveFilePicker" in window)
5156
5156
  try {
5157
5157
  const B = await (await window.showSaveFilePicker({
@@ -5172,53 +5172,53 @@ async function aa(m) {
5172
5172
  B.href = K, B.download = o, document.body.appendChild(B), B.click(), B.remove(), URL.revokeObjectURL(K);
5173
5173
  }
5174
5174
  }
5175
- function sa(m) {
5176
- const { records: r, config: s, withDatabaseIds: o = !1 } = m, d = /* @__PURE__ */ new Map();
5177
- let f;
5175
+ function ca(m) {
5176
+ const { records: r, config: s, withDatabaseIds: o = !1 } = m, f = /* @__PURE__ */ new Map();
5177
+ let d;
5178
5178
  for (const R of r)
5179
- d.set(R.id, R), R.tagName === s.rootElementName && (f = R);
5180
- we(f, {
5179
+ f.set(R.id, R), R.tagName === s.rootElementName && (d = R);
5180
+ we(d, {
5181
5181
  detail: `No ${s.rootElementName} root element found in records`,
5182
5182
  key: "EXPORT_ROOT_NOT_FOUND"
5183
5183
  });
5184
- const v = s.namespaces.default, g = document.implementation.createDocument(v.uri, null, null), D = g.createElementNS(f.namespace.uri, f.tagName);
5185
- return D.setAttribute("xmlns", f.namespace.uri), f.attributes && qi({
5184
+ const v = s.namespaces.default, g = document.implementation.createDocument(v.uri, null, null), D = g.createElementNS(d.namespace.uri, d.tagName);
5185
+ return D.setAttribute("xmlns", d.namespace.uri), d.attributes && qi({
5186
5186
  config: s,
5187
5187
  document: g,
5188
5188
  element: D,
5189
- attributes: f.attributes,
5190
- tagName: f.tagName,
5189
+ attributes: d.attributes,
5190
+ tagName: d.tagName,
5191
5191
  isRoot: !0
5192
- }), Ui({ config: s, rootElement: D, namespace: f.namespace }), f.value && (D.textContent = f.value.trim()), o && D.setAttribute(Mi, f.id), g.appendChild(D), Ki({
5193
- index: d,
5192
+ }), Ui({ config: s, rootElement: D, namespace: d.namespace }), d.value && (D.textContent = d.value.trim()), o && D.setAttribute(Mi, d.id), g.appendChild(D), Ki({
5193
+ index: f,
5194
5194
  config: s,
5195
5195
  withDatabaseIds: o,
5196
5196
  xmlDocument: g,
5197
- parentRecord: f,
5197
+ parentRecord: d,
5198
5198
  parentElement: D
5199
5199
  }), g;
5200
5200
  }
5201
5201
  function Ki(m) {
5202
- const { index: r, config: s, withDatabaseIds: o, xmlDocument: d, parentRecord: f, parentElement: v } = m;
5203
- if (!f.children || f.children.length === 0) return;
5202
+ const { index: r, config: s, withDatabaseIds: o, xmlDocument: f, parentRecord: d, parentElement: v } = m;
5203
+ if (!d.children || d.children.length === 0) return;
5204
5204
  const g = [];
5205
- for (const R of f.children) {
5205
+ for (const R of d.children) {
5206
5206
  const K = r.get(R.id);
5207
5207
  we(K, {
5208
- detail: `Parent '${f.tagName}' references non-existent child '${R.tagName}' (id: ${R.id})`,
5208
+ detail: `Parent '${d.tagName}' references non-existent child '${R.tagName}' (id: ${R.id})`,
5209
5209
  key: "EXPORT_ORPHAN_CHILD_REF",
5210
- ref: { tagName: f.tagName, id: f.id }
5210
+ ref: { tagName: d.tagName, id: d.id }
5211
5211
  }), g.push(K);
5212
5212
  }
5213
- const D = ua({
5214
- parentTagName: f.tagName,
5213
+ const D = la({
5214
+ parentTagName: d.tagName,
5215
5215
  availableChildren: s.children,
5216
5216
  childrenRecords: g
5217
5217
  });
5218
5218
  for (const R of D) {
5219
- const K = ca({
5219
+ const K = ua({
5220
5220
  config: s,
5221
- document: d,
5221
+ document: f,
5222
5222
  record: R,
5223
5223
  defaultNamespace: s.namespaces.default,
5224
5224
  withDatabaseIds: o
@@ -5227,14 +5227,14 @@ function Ki(m) {
5227
5227
  index: r,
5228
5228
  config: s,
5229
5229
  withDatabaseIds: o,
5230
- xmlDocument: d,
5230
+ xmlDocument: f,
5231
5231
  parentRecord: R,
5232
5232
  parentElement: K
5233
5233
  });
5234
5234
  }
5235
5235
  }
5236
- function ca(m) {
5237
- const { config: r, document: s, record: o, defaultNamespace: d, withDatabaseIds: f } = m, v = o.namespace.uri === d.uri;
5236
+ function ua(m) {
5237
+ const { config: r, document: s, record: o, defaultNamespace: f, withDatabaseIds: d } = m, v = o.namespace.uri === f.uri;
5238
5238
  let g;
5239
5239
  return !v && o.namespace.prefix && o.namespace.prefix !== "xmlns" ? (Li({ config: r, document: s, namespace: o.namespace }), g = s.createElementNS(
5240
5240
  o.namespace.uri,
@@ -5246,12 +5246,12 @@ function ca(m) {
5246
5246
  attributes: o.attributes,
5247
5247
  tagName: o.tagName,
5248
5248
  isRoot: !1
5249
- }), o.value && (g.textContent = o.value.trim()), f && g.setAttribute(Mi, o.id), g;
5249
+ }), o.value && (g.textContent = o.value.trim()), d && g.setAttribute(Mi, o.id), g;
5250
5250
  }
5251
5251
  function qi(m) {
5252
- const { config: r, document: s, element: o, attributes: d, tagName: f, isRoot: v } = m;
5253
- for (const g of d) {
5254
- if (la(g) || !v && fa({ config: r, tagName: f, attribute: g })) continue;
5252
+ const { config: r, document: s, element: o, attributes: f, tagName: d, isRoot: v } = m;
5253
+ for (const g of f) {
5254
+ if (fa(g) || !v && da({ config: r, tagName: d, attribute: g })) continue;
5255
5255
  if (!$i(g) || !g.namespace.prefix) {
5256
5256
  o.setAttribute(g.name, String(g.value));
5257
5257
  continue;
@@ -5266,17 +5266,17 @@ function qi(m) {
5266
5266
  }
5267
5267
  }
5268
5268
  function Li(m) {
5269
- const { config: r, document: s, namespace: o } = m, d = s.documentElement;
5270
- if (!d || !o.prefix || o.prefix === "xmlns") return;
5271
- const f = "http://www.w3.org/2000/xmlns/";
5272
- d.getAttributeNS(f, o.prefix) === null && (d.setAttributeNS(f, `xmlns:${o.prefix}`, o.uri), Ui({ config: r, rootElement: d, namespace: o }));
5269
+ const { config: r, document: s, namespace: o } = m, f = s.documentElement;
5270
+ if (!f || !o.prefix || o.prefix === "xmlns") return;
5271
+ const d = "http://www.w3.org/2000/xmlns/";
5272
+ f.getAttributeNS(d, o.prefix) === null && (f.setAttributeNS(d, `xmlns:${o.prefix}`, o.uri), Ui({ config: r, rootElement: f, namespace: o }));
5273
5273
  }
5274
5274
  function Ui(m) {
5275
- const { config: r, rootElement: s, namespace: o } = m, d = Object.entries(
5275
+ const { config: r, rootElement: s, namespace: o } = m, f = Object.entries(
5276
5276
  r.definition[r.rootElementName].attributes.details
5277
5277
  ).filter(([v, g]) => o.uri === r.namespaces.default.uri ? !g.namespace : g.namespace?.prefix === o.prefix && g.namespace?.uri === o.uri);
5278
- if (d.length > 0)
5279
- for (const [v, g] of d) {
5278
+ if (f.length > 0)
5279
+ for (const [v, g] of f) {
5280
5280
  const D = Vi(v);
5281
5281
  if (!(g.namespace ? s.hasAttributeNS(g.namespace.uri, D) : s.hasAttribute(D)))
5282
5282
  if (g.namespace) {
@@ -5286,17 +5286,17 @@ function Ui(m) {
5286
5286
  s.setAttribute(D, g.default || "");
5287
5287
  }
5288
5288
  }
5289
- function ua(m) {
5290
- const { parentTagName: r, availableChildren: s, childrenRecords: o } = m, d = new Set(s[r]);
5291
- if (!d.size) return o;
5292
- const f = /* @__PURE__ */ new Map(), v = [];
5293
- for (const D of d)
5294
- f.set(D, []);
5289
+ function la(m) {
5290
+ const { parentTagName: r, availableChildren: s, childrenRecords: o } = m, f = new Set(s[r]);
5291
+ if (!f.size) return o;
5292
+ const d = /* @__PURE__ */ new Map(), v = [];
5293
+ for (const D of f)
5294
+ d.set(D, []);
5295
5295
  for (const D of o)
5296
- d.has(D.tagName) ? f.get(D.tagName)?.push(D) : v.push(D);
5296
+ f.has(D.tagName) ? d.get(D.tagName)?.push(D) : v.push(D);
5297
5297
  const g = [];
5298
- for (const D of d) {
5299
- const R = f.get(D);
5298
+ for (const D of f) {
5299
+ const R = d.get(D);
5300
5300
  R && R.length && g.push(...R);
5301
5301
  }
5302
5302
  return g.push(...v), g;
@@ -5308,18 +5308,18 @@ function Vi(m) {
5308
5308
  function $i(m) {
5309
5309
  return m !== null && typeof m == "object" && "namespace" in m && !!m.namespace;
5310
5310
  }
5311
- function la(m) {
5311
+ function fa(m) {
5312
5312
  return !!(m.name === "xmlns" || m.name.startsWith("xmlns:") || $i(m) && m.namespace?.prefix === "xmlns");
5313
5313
  }
5314
- function fa(m) {
5314
+ function da(m) {
5315
5315
  const { config: r, tagName: s, attribute: o } = m;
5316
5316
  if (!r.elements.includes(s)) return !1;
5317
- const d = r.definition[s];
5318
- if (!d) return !1;
5319
- const f = d.attributes.details[o.name];
5320
- return !(!f || f.required || f.default === void 0 || String(o.value) !== f.default || d.attributes.identityFields?.includes(o.name));
5317
+ const f = r.definition[s];
5318
+ if (!f) return !1;
5319
+ const d = f.attributes.details[o.name];
5320
+ return !(!d || d.required || d.default === void 0 || String(o.value) !== d.default || f.attributes.identityFields?.includes(o.name));
5321
5321
  }
5322
- class da {
5322
+ class ha {
5323
5323
  constructor() {
5324
5324
  this.pendingChildren = /* @__PURE__ */ new Map();
5325
5325
  }
@@ -5347,16 +5347,16 @@ class da {
5347
5347
  return this.pendingChildren.size;
5348
5348
  }
5349
5349
  }
5350
- function ha(m) {
5350
+ function ma(m) {
5351
5351
  return "prefix" in m && "uri" in m && !!m.prefix && !!m.uri;
5352
5352
  }
5353
5353
  var yr = {};
5354
- const ma = {}, pa = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5354
+ const pa = {}, ga = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5355
5355
  __proto__: null,
5356
- default: ma
5357
- }, Symbol.toStringTag, { value: "Module" })), ga = /* @__PURE__ */ Yo(pa);
5356
+ default: pa
5357
+ }, Symbol.toStringTag, { value: "Module" })), ya = /* @__PURE__ */ zo(ga);
5358
5358
  var mi;
5359
- function ya() {
5359
+ function va() {
5360
5360
  return mi || (mi = 1, (function(m) {
5361
5361
  (function(r) {
5362
5362
  r.parser = function(l, c) {
@@ -5400,7 +5400,7 @@ function ya() {
5400
5400
  if (!(this instanceof o))
5401
5401
  return new o(l, c);
5402
5402
  var I = this;
5403
- f(I), I.q = I.c = "", I.bufferCheckPosition = r.MAX_BUFFER_LENGTH, I.encoding = null, I.opt = c || {}, I.opt.lowercase = I.opt.lowercase || I.opt.lowercasetags, I.looseCase = I.opt.lowercase ? "toLowerCase" : "toUpperCase", I.opt.maxEntityCount = I.opt.maxEntityCount || 512, I.opt.maxEntityDepth = I.opt.maxEntityDepth || 4, I.entityCount = I.entityDepth = 0, I.tags = [], I.closed = I.closedRoot = I.sawRoot = !1, I.tag = I.error = null, I.strict = !!l, I.noscript = !!(l || I.opt.noscript), I.state = S.BEGIN, I.strictEntities = I.opt.strictEntities, I.ENTITIES = I.strictEntities ? Object.create(r.XML_ENTITIES) : Object.create(r.ENTITIES), I.attribList = [], I.opt.xmlns && (I.ns = Object.create(z)), I.opt.unquotedAttributeValues === void 0 && (I.opt.unquotedAttributeValues = !l), I.trackPosition = I.opt.position !== !1, I.trackPosition && (I.position = I.line = I.column = 0), Ue(I, "onready");
5403
+ d(I), I.q = I.c = "", I.bufferCheckPosition = r.MAX_BUFFER_LENGTH, I.encoding = null, I.opt = c || {}, I.opt.lowercase = I.opt.lowercase || I.opt.lowercasetags, I.looseCase = I.opt.lowercase ? "toLowerCase" : "toUpperCase", I.opt.maxEntityCount = I.opt.maxEntityCount || 512, I.opt.maxEntityDepth = I.opt.maxEntityDepth || 4, I.entityCount = I.entityDepth = 0, I.tags = [], I.closed = I.closedRoot = I.sawRoot = !1, I.tag = I.error = null, I.strict = !!l, I.noscript = !!(l || I.opt.noscript), I.state = S.BEGIN, I.strictEntities = I.opt.strictEntities, I.ENTITIES = I.strictEntities ? Object.create(r.XML_ENTITIES) : Object.create(r.ENTITIES), I.attribList = [], I.opt.xmlns && (I.ns = Object.create(z)), I.opt.unquotedAttributeValues === void 0 && (I.opt.unquotedAttributeValues = !l), I.trackPosition = I.opt.position !== !1, I.trackPosition && (I.position = I.line = I.column = 0), Ue(I, "onready");
5404
5404
  }
5405
5405
  Object.create || (Object.create = function(l) {
5406
5406
  function c() {
@@ -5413,7 +5413,7 @@ function ya() {
5413
5413
  for (var I in l) l.hasOwnProperty(I) && c.push(I);
5414
5414
  return c;
5415
5415
  });
5416
- function d(l) {
5416
+ function f(l) {
5417
5417
  for (var c = Math.max(r.MAX_BUFFER_LENGTH, 10), I = 0, E = 0, le = s.length; E < le; E++) {
5418
5418
  var be = l[s[E]].length;
5419
5419
  if (be > c)
@@ -5435,7 +5435,7 @@ function ya() {
5435
5435
  var xe = r.MAX_BUFFER_LENGTH - I;
5436
5436
  l.bufferCheckPosition = xe + l.position;
5437
5437
  }
5438
- function f(l) {
5438
+ function d(l) {
5439
5439
  for (var c = 0, I = s.length; c < I; c++)
5440
5440
  l[s[c]] = "";
5441
5441
  }
@@ -5459,7 +5459,7 @@ function ya() {
5459
5459
  };
5460
5460
  var g;
5461
5461
  try {
5462
- g = ga.Stream;
5462
+ g = ya.Stream;
5463
5463
  } catch {
5464
5464
  g = function() {
5465
5465
  };
@@ -6281,7 +6281,7 @@ Actual: ` + l.attribValue
6281
6281
  default:
6282
6282
  throw new Error(c, "Unknown state: " + c.state);
6283
6283
  }
6284
- return c.position >= c.bufferCheckPosition && d(c), c;
6284
+ return c.position >= c.bufferCheckPosition && f(c), c;
6285
6285
  }
6286
6286
  String.fromCodePoint || (function() {
6287
6287
  var l = String.fromCharCode, c = Math.floor, I = function() {
@@ -6308,15 +6308,15 @@ Actual: ` + l.attribValue
6308
6308
  })(m);
6309
6309
  })(yr)), yr;
6310
6310
  }
6311
- var va = ya();
6312
- function ba(m) {
6313
- const { dialecteConfig: r, useCustomRecordsIds: s, session: o } = m, d = r.io.hooks;
6311
+ var ba = va();
6312
+ function wa(m) {
6313
+ const { dialecteConfig: r, useCustomRecordsIds: s, session: o } = m, f = r.io.hooks;
6314
6314
  let v = {
6315
6315
  defaultNamespace: null,
6316
6316
  stack: [],
6317
6317
  recordsBatch: []
6318
6318
  };
6319
- const g = va.parser(
6319
+ const g = ba.parser(
6320
6320
  !0,
6321
6321
  // strict mode
6322
6322
  {
@@ -6332,16 +6332,16 @@ function ba(m) {
6332
6332
  // Enable namespace handling
6333
6333
  }
6334
6334
  );
6335
- g.onopentag = (K) => v = wa({
6335
+ g.onopentag = (K) => v = _a({
6336
6336
  node: K,
6337
6337
  state: v,
6338
6338
  dialecteConfig: r,
6339
6339
  useCustomRecordsIds: s
6340
- }), g.ontext = (K) => v = _a({ text: K, state: v }), g.onclosetag = () => ({ updatedState: v } = Ea({
6340
+ }), g.ontext = (K) => v = Ea({ text: K, state: v }), g.onclosetag = () => ({ updatedState: v } = xa({
6341
6341
  state: v,
6342
- ioHooks: d,
6342
+ ioHooks: f,
6343
6343
  session: o
6344
- })), g.onerror = xa;
6344
+ })), g.onerror = Ta;
6345
6345
  function D() {
6346
6346
  const K = v.recordsBatch;
6347
6347
  return v.recordsBatch = [], K;
@@ -6355,17 +6355,17 @@ function ba(m) {
6355
6355
  getSize: R
6356
6356
  };
6357
6357
  }
6358
- function wa(m) {
6359
- const { node: r, state: s, dialecteConfig: o, useCustomRecordsIds: d } = m, f = { ...s }, v = Ta(r);
6360
- f.defaultNamespace || (f.defaultNamespace = Na({
6358
+ function _a(m) {
6359
+ const { node: r, state: s, dialecteConfig: o, useCustomRecordsIds: f } = m, d = { ...s }, v = Na(r);
6360
+ d.defaultNamespace || (d.defaultNamespace = Ca({
6361
6361
  element: r,
6362
6362
  defaultNamespace: o.namespaces.default,
6363
6363
  rootElementName: o.rootElementName
6364
6364
  }));
6365
- const g = Ca(r, f.defaultNamespace), D = Da({ attributes: r.attributes, useCustomRecordsIds: d }), R = Sa({
6365
+ const g = Oa(r, d.defaultNamespace), D = Sa({ attributes: r.attributes, useCustomRecordsIds: f }), R = ka({
6366
6366
  attributes: r.attributes,
6367
- useCustomRecordsIds: d
6368
- }), K = Oa(R), B = Aa(s.stack), Y = {
6367
+ useCustomRecordsIds: f
6368
+ }), K = Aa(R), B = Da(s.stack), Y = {
6369
6369
  id: D,
6370
6370
  tagName: v,
6371
6371
  namespace: g,
@@ -6374,52 +6374,52 @@ function wa(m) {
6374
6374
  parent: B,
6375
6375
  children: []
6376
6376
  };
6377
- return f.stack.push(Y), f;
6377
+ return d.stack.push(Y), d;
6378
6378
  }
6379
- function _a(m) {
6379
+ function Ea(m) {
6380
6380
  const { text: r, state: s } = m;
6381
6381
  return r && s.stack.length > 0 && (s.stack[s.stack.length - 1].value += r), s;
6382
6382
  }
6383
- function Ea(m) {
6384
- const { state: r, ioHooks: s, session: o } = m, d = r.stack.at(-1);
6385
- let f = r.stack.slice(0, -1);
6383
+ function xa(m) {
6384
+ const { state: r, ioHooks: s, session: o } = m, f = r.stack.at(-1);
6385
+ let d = r.stack.slice(0, -1);
6386
6386
  const v = [...r.recordsBatch];
6387
- if (d) {
6387
+ if (f) {
6388
6388
  if (s?.beforeImportRecord && s.beforeImportRecord({
6389
- record: d,
6390
- ancestry: f
6391
- }), f.length) {
6392
- const g = f.length - 1;
6393
- f = f.map(
6389
+ record: f,
6390
+ ancestry: d
6391
+ }), d.length) {
6392
+ const g = d.length - 1;
6393
+ d = d.map(
6394
6394
  (D, R) => R === g ? {
6395
6395
  ...D,
6396
6396
  children: [
6397
6397
  ...D.children,
6398
- { id: d.id, tagName: d.tagName }
6398
+ { id: f.id, tagName: f.tagName }
6399
6399
  ]
6400
6400
  } : D
6401
6401
  );
6402
- } else d.parent && o.registerPendingChild(d.parent.id, {
6403
- id: d.id,
6404
- tagName: d.tagName
6402
+ } else f.parent && o.registerPendingChild(f.parent.id, {
6403
+ id: f.id,
6404
+ tagName: f.tagName
6405
6405
  });
6406
- v.push(d);
6406
+ v.push(f);
6407
6407
  }
6408
6408
  return {
6409
6409
  updatedState: {
6410
6410
  defaultNamespace: r.defaultNamespace,
6411
- stack: f,
6411
+ stack: d,
6412
6412
  recordsBatch: v
6413
6413
  }
6414
6414
  };
6415
6415
  }
6416
- function xa(m) {
6416
+ function Ta(m) {
6417
6417
  return new Error(`XML parsing error: ${m}`);
6418
6418
  }
6419
- function Ta(m) {
6419
+ function Na(m) {
6420
6420
  return m.local;
6421
6421
  }
6422
- function Na(m) {
6422
+ function Ca(m) {
6423
6423
  const { element: r, defaultNamespace: s, rootElementName: o } = m;
6424
6424
  return we(r.name === o, {
6425
6425
  detail: `Expected root element <${o}>, got <${r.name}>`
@@ -6428,13 +6428,13 @@ function Na(m) {
6428
6428
  uri: r.attributes.xmlns.value
6429
6429
  } : s;
6430
6430
  }
6431
- function Ca(m, r) {
6432
- return ha(m) ? {
6431
+ function Oa(m, r) {
6432
+ return ma(m) ? {
6433
6433
  prefix: m.prefix,
6434
6434
  uri: m.uri
6435
6435
  } : r;
6436
6436
  }
6437
- function Oa(m) {
6437
+ function Aa(m) {
6438
6438
  return m.map((r) => {
6439
6439
  const s = r.prefix && r.uri ? {
6440
6440
  prefix: r.prefix,
@@ -6447,28 +6447,28 @@ function Oa(m) {
6447
6447
  };
6448
6448
  });
6449
6449
  }
6450
- function Aa(m) {
6450
+ function Da(m) {
6451
6451
  if (m.length === 0) return null;
6452
6452
  const r = m[m.length - 1];
6453
6453
  return r ? { id: r.id, tagName: r.tagName } : null;
6454
6454
  }
6455
- function Da(m) {
6455
+ function Sa(m) {
6456
6456
  const { attributes: r, useCustomRecordsIds: s } = m, o = r[gi];
6457
6457
  return s && o && o.value ? o.value : crypto.randomUUID();
6458
6458
  }
6459
- function Sa(m) {
6459
+ function ka(m) {
6460
6460
  const { attributes: r, useCustomRecordsIds: s } = m;
6461
6461
  return s ? Object.values(r).filter((o) => o.name !== gi) : Object.values(r);
6462
6462
  }
6463
- const ka = 32 * 1024, Ra = 2e3;
6464
- async function Ia(m) {
6465
- const { file: r, documentId: s, store: o, config: d, useCustomRecordsIds: f = !1, chunkOptions: v } = m, { supportedFileExtensions: g } = d.io;
6463
+ const Ra = 32 * 1024, Ia = 2e3;
6464
+ async function Pa(m) {
6465
+ const { file: r, documentId: s, store: o, config: f, useCustomRecordsIds: d = !1, chunkOptions: v } = m, { supportedFileExtensions: g } = f.io;
6466
6466
  if (we(
6467
6467
  g.some((M) => r.name.toLowerCase().endsWith(M)),
6468
6468
  { key: "ASSERTION_FAILED", detail: `Unsupported file type: ${r.name}` }
6469
6469
  ), r.size === 0)
6470
6470
  return { documentId: s, recordCount: 0 };
6471
- const D = v?.chunkSize ?? ka, R = v?.batchSize ?? Ra, K = new da(), B = ba({ dialecteConfig: d, useCustomRecordsIds: f, session: K }), Y = await Pa({
6471
+ const D = v?.chunkSize ?? Ra, R = v?.batchSize ?? Ia, K = new ha(), B = wa({ dialecteConfig: f, useCustomRecordsIds: d, session: K }), Y = await Fa({
6472
6472
  file: r,
6473
6473
  sax: B,
6474
6474
  session: K,
@@ -6476,56 +6476,56 @@ async function Ia(m) {
6476
6476
  documentId: s,
6477
6477
  chunkSize: D,
6478
6478
  batchSize: R
6479
- }), oe = await Fa({ config: d, store: o, documentId: s });
6479
+ }), oe = await Ba({ config: f, store: o, documentId: s });
6480
6480
  return { documentId: s, recordCount: Y + oe };
6481
6481
  }
6482
- async function Pa(m) {
6483
- const { file: r, sax: s, session: o, store: d, documentId: f, chunkSize: v, batchSize: g } = m;
6482
+ async function Fa(m) {
6483
+ const { file: r, sax: s, session: o, store: f, documentId: d, chunkSize: v, batchSize: g } = m;
6484
6484
  let D = 0;
6485
6485
  const R = r.stream().getReader(), K = new TextDecoder();
6486
6486
  let B = new Uint8Array(0), Y = !1;
6487
6487
  for (; !Y; ) {
6488
6488
  const oe = await R.read();
6489
6489
  if (Y = oe.done, Y) {
6490
- B.length > 0 && s.parser.write(K.decode(B)), s.parser.close(), D += await pi({ sax: s, session: o, store: d, documentId: f, threshold: 0 });
6490
+ B.length > 0 && s.parser.write(K.decode(B)), s.parser.close(), D += await pi({ sax: s, session: o, store: f, documentId: d, threshold: 0 });
6491
6491
  break;
6492
6492
  }
6493
6493
  if (oe.value)
6494
- for (B = Ba(B, oe.value); B.length >= v; ) {
6494
+ for (B = ja(B, oe.value); B.length >= v; ) {
6495
6495
  const M = K.decode(B.slice(0, v), { stream: !0 });
6496
- B = B.slice(v), s.parser.write(M), D += await pi({ sax: s, session: o, store: d, documentId: f, threshold: g });
6496
+ B = B.slice(v), s.parser.write(M), D += await pi({ sax: s, session: o, store: f, documentId: d, threshold: g });
6497
6497
  }
6498
6498
  }
6499
6499
  return D;
6500
6500
  }
6501
- async function Fa(m) {
6501
+ async function Ba(m) {
6502
6502
  const { config: r, store: s, documentId: o } = m;
6503
6503
  if (!r.io.hooks?.afterImport) return 0;
6504
- const { creates: d, updates: f, deletes: v } = await r.io.hooks.afterImport();
6505
- return d?.length || f?.length || v?.length ? (await s.bulkWrite(o, { creates: d, updates: f, deletes: v }), (d?.length ?? 0) - (v?.length ?? 0)) : 0;
6504
+ const { creates: f, updates: d, deletes: v } = await r.io.hooks.afterImport();
6505
+ return f?.length || d?.length || v?.length ? (await s.bulkWrite(o, { creates: f, updates: d, deletes: v }), (f?.length ?? 0) - (v?.length ?? 0)) : 0;
6506
6506
  }
6507
- function Ba(m, r) {
6507
+ function ja(m, r) {
6508
6508
  const s = new Uint8Array(m.length + r.length);
6509
6509
  return s.set(m), s.set(r, m.length), s;
6510
6510
  }
6511
6511
  async function pi(m) {
6512
- const { sax: r, session: s, store: o, documentId: d, threshold: f } = m;
6513
- if (r.getSize() < f) return 0;
6512
+ const { sax: r, session: s, store: o, documentId: f, threshold: d } = m;
6513
+ if (r.getSize() < d) return 0;
6514
6514
  const v = r.drainBatch(), g = s.resolveChildrenForBatch(v);
6515
- return await o.bulkWrite(d, { creates: g }), g.length;
6515
+ return await o.bulkWrite(f, { creates: g }), g.length;
6516
6516
  }
6517
- async function ja(m) {
6518
- const { documentId: r, state: s, configs: o, store: d, projectName: f, options: v } = m, g = s.documents.get(r);
6517
+ async function Ma(m) {
6518
+ const { documentId: r, state: s, configs: o, store: f, projectName: d, options: v } = m, g = s.documents.get(r);
6519
6519
  we(g, {
6520
6520
  key: "DOCUMENT_NOT_REGISTERED",
6521
- detail: `Document "${r}" not registered in project "${f}"`
6521
+ detail: `Document "${r}" not registered in project "${d}"`
6522
6522
  });
6523
- const D = o[g.document.configKey], R = await d.getByDocumentId(r), K = sa({
6523
+ const D = o[g.document.configKey], R = await f.getByDocumentId(r), K = ca({
6524
6524
  records: R,
6525
6525
  config: D,
6526
6526
  withDatabaseIds: v?.withDatabaseIds
6527
6527
  }), B = `${g.document.name}${g.document.extension}`;
6528
- return v?.withDownload && await aa({
6528
+ return v?.withDownload && await sa({
6529
6529
  extension: g.document.extension,
6530
6530
  xmlDocument: K,
6531
6531
  filename: B
@@ -6543,7 +6543,7 @@ function Rn(m) {
6543
6543
  canRedo: !1
6544
6544
  };
6545
6545
  }
6546
- function Ma(m, r) {
6546
+ function Ka(m, r) {
6547
6547
  const s = new Set(r.map((o) => o.id));
6548
6548
  for (const o of r)
6549
6549
  m.has(o.id) || m.set(o.id, Rn(o));
@@ -6551,8 +6551,8 @@ function Ma(m, r) {
6551
6551
  s.has(o) || m.delete(o);
6552
6552
  return m;
6553
6553
  }
6554
- async function Ka(m) {
6555
- const { file: r, store: s, configs: o, defaultConfigKey: d, options: f } = m, v = f?.configKey ?? d, g = o[v];
6554
+ async function qa(m) {
6555
+ const { file: r, store: s, configs: o, defaultConfigKey: f, options: d } = m, v = d?.configKey ?? f, g = o[v];
6556
6556
  we(g, {
6557
6557
  key: "UNKNOWN_CONFIG_KEY",
6558
6558
  detail: `Unknown configKey: "${v}". Available: ${Object.keys(o).join(", ")}`
@@ -6563,16 +6563,16 @@ async function Ka(m) {
6563
6563
  extension: R,
6564
6564
  configKey: v,
6565
6565
  createdAt: Date.now(),
6566
- metadata: f?.metadata
6566
+ metadata: d?.metadata
6567
6567
  };
6568
6568
  await s.registerDocument(B);
6569
- const { recordCount: Y } = await Ia({
6569
+ const { recordCount: Y } = await Pa({
6570
6570
  file: r,
6571
6571
  documentId: D,
6572
6572
  store: s,
6573
6573
  config: g,
6574
- useCustomRecordsIds: f?.useCustomRecordsIds,
6575
- chunkOptions: f?.chunkOptions
6574
+ useCustomRecordsIds: d?.useCustomRecordsIds,
6575
+ chunkOptions: d?.chunkOptions
6576
6576
  });
6577
6577
  return {
6578
6578
  documentId: D,
@@ -6581,19 +6581,19 @@ async function Ka(m) {
6581
6581
  recordCount: Y
6582
6582
  };
6583
6583
  }
6584
- async function qa(m) {
6585
- const { store: r, configs: s, defaultConfigKey: o, options: d } = m, f = d?.configKey ?? o, v = s[f];
6584
+ async function La(m) {
6585
+ const { store: r, configs: s, defaultConfigKey: o, options: f } = m, d = f?.configKey ?? o, v = s[d];
6586
6586
  we(v, {
6587
6587
  key: "UNKNOWN_CONFIG_KEY",
6588
- detail: `Unknown configKey: "${f}". Available: ${Object.keys(s).join(", ")}`
6588
+ detail: `Unknown configKey: "${d}". Available: ${Object.keys(s).join(", ")}`
6589
6589
  });
6590
- const g = d?.extension ?? v.io.supportedFileExtensions[0], D = d?.name ?? "untitled", R = crypto.randomUUID(), K = {
6590
+ const g = f?.extension ?? v.io.supportedFileExtensions[0], D = f?.name ?? "untitled", R = crypto.randomUUID(), K = {
6591
6591
  id: R,
6592
6592
  name: D,
6593
6593
  extension: g,
6594
- configKey: f,
6594
+ configKey: d,
6595
6595
  createdAt: Date.now(),
6596
- metadata: d?.metadata
6596
+ metadata: f?.metadata
6597
6597
  };
6598
6598
  await r.registerDocument(K);
6599
6599
  const B = v.definition[v.rootElementName], Y = (B?.attributes.sequence ?? []).map((M) => ({ name: M, ...B.attributes.details[M] })).filter((M) => M.required && (M.fixed ?? M.default) !== void 0).map(({ name: M, fixed: j, default: z, namespace: ie }) => {
@@ -6610,14 +6610,17 @@ async function qa(m) {
6610
6610
  };
6611
6611
  return await r.bulkWrite(R, { creates: [oe] }), { documentId: R, document: K, documentState: Rn(K) };
6612
6612
  }
6613
- class es {
6613
+ class ts {
6614
6614
  constructor(r) {
6615
6615
  this.state = {
6616
6616
  documents: /* @__PURE__ */ new Map(),
6617
6617
  activeTransactions: 0
6618
6618
  };
6619
6619
  const s = Object.keys(r.configs);
6620
- this.storage = r.storage, this.configs = r.configs, this.defaultConfigKey = r.defaultConfigKey ?? s[0], this.extensionsRegistry = r.extensionsRegistry, this.hooks = r.hooks;
6620
+ this.storage = r.storage, this.configs = r.configs, this.defaultConfigKey = r.defaultConfigKey ?? s[0], this.mergedExtensions = r.extensions ? bo({
6621
+ base: r.extensions.base,
6622
+ custom: r.extensions.custom
6623
+ }) : void 0, this.hooks = r.hooks;
6621
6624
  }
6622
6625
  get name() {
6623
6626
  return we(this._name !== void 0, {
@@ -6643,15 +6646,15 @@ class es {
6643
6646
  * Must be called before import/export/openDocument.
6644
6647
  */
6645
6648
  async open(r) {
6646
- this._name = r, this._channel = new BroadcastChannel(`dialecte::project::${r}`), this._channel.onmessage = (d) => {
6647
- const { type: f } = d.data ?? {};
6648
- (f === "init-empty-document" || f === "document-removed" || f === "document-imported") && this.refreshState();
6649
+ this._name = r, this._channel = new BroadcastChannel(`dialecte::project::${r}`), this._channel.onmessage = (f) => {
6650
+ const { type: d } = f.data ?? {};
6651
+ (d === "init-empty-document" || d === "document-removed" || d === "document-imported") && this.refreshState();
6649
6652
  };
6650
- const s = ea(r, this.storage, this.configs[this.defaultConfigKey]);
6653
+ const s = ta(r, this.storage, this.configs[this.defaultConfigKey]);
6651
6654
  await s.open(), this._store = s;
6652
6655
  const o = await s.getDocuments();
6653
- for (const d of o)
6654
- this.state.documents.set(d.id, Rn(d));
6656
+ for (const f of o)
6657
+ this.state.documents.set(f.id, Rn(f));
6655
6658
  return this;
6656
6659
  }
6657
6660
  /**
@@ -6672,7 +6675,7 @@ class es {
6672
6675
  * Returns the new documentId. Records are added later via import or transactions.
6673
6676
  */
6674
6677
  async initEmptyDocument(r) {
6675
- const s = await qa({
6678
+ const s = await La({
6676
6679
  store: this.store,
6677
6680
  configs: this.configs,
6678
6681
  defaultConfigKey: this.defaultConfigKey,
@@ -6688,23 +6691,29 @@ class es {
6688
6691
  }
6689
6692
  // ── Import / Export ──────────────────────────────────────────────────────
6690
6693
  /**
6691
- * Import a File into the project: register, parse XML, persist records.
6694
+ * Import one or more Files into the project: register, parse XML, persist records.
6692
6695
  */
6693
6696
  async import(r, s) {
6694
- const o = await Ka({
6695
- file: r,
6696
- store: this.store,
6697
- configs: this.configs,
6698
- defaultConfigKey: this.defaultConfigKey,
6699
- options: s
6700
- });
6701
- return this.state.documents.set(o.documentId, o.documentState), this.channel.postMessage({ type: "document-imported", documentId: o.documentId }), { documentId: o.documentId, recordCount: o.recordCount };
6697
+ const o = await Promise.all(
6698
+ r.map(
6699
+ (f) => qa({
6700
+ file: f,
6701
+ store: this.store,
6702
+ configs: this.configs,
6703
+ defaultConfigKey: this.defaultConfigKey,
6704
+ options: s
6705
+ })
6706
+ )
6707
+ );
6708
+ for (const f of o)
6709
+ this.state.documents.set(f.documentId, f.documentState), this.channel.postMessage({ type: "document-imported", documentId: f.documentId });
6710
+ return o.map(({ documentId: f, recordCount: d }) => ({ documentId: f, recordCount: d }));
6702
6711
  }
6703
6712
  /**
6704
6713
  * Export a document as an XMLDocument built from stored records.
6705
6714
  */
6706
6715
  async export(r, s) {
6707
- return ja({
6716
+ return Ma({
6708
6717
  documentId: r,
6709
6718
  state: this.state,
6710
6719
  configs: this.configs,
@@ -6731,11 +6740,11 @@ class es {
6731
6740
  detail: `Document "${r}" not registered in project "${this.name}"`
6732
6741
  });
6733
6742
  const o = this.configs[s.document.configKey];
6734
- return new $o(
6743
+ return new Go(
6735
6744
  this.store,
6736
6745
  o,
6737
6746
  r,
6738
- this.extensionsRegistry,
6747
+ this.mergedExtensions,
6739
6748
  this.hooks,
6740
6749
  this.channel
6741
6750
  );
@@ -6763,6 +6772,29 @@ class es {
6763
6772
  detail: `Document "${r}" not registered in project "${this.name}"`
6764
6773
  }), await this.store.redo(r), this.channel.postMessage({ type: "commit", documentId: r, timestamp: Date.now() });
6765
6774
  }
6775
+ // ── Cross-document queries ───────────────────────────────────────────────
6776
+ /**
6777
+ * Run a query function across all documents, return the first non-undefined result.
6778
+ * Iterates documents sequentially; stops at the first match.
6779
+ */
6780
+ async queryFirst(r) {
6781
+ for (const s of this.state.documents.keys()) {
6782
+ const o = this.openDocument(s), f = await r(o.query);
6783
+ if (f !== void 0) return f;
6784
+ }
6785
+ }
6786
+ /**
6787
+ * Run a query function across all documents, collect and flatten results.
6788
+ * Iterates documents sequentially; merges all non-empty arrays.
6789
+ */
6790
+ async queryAll(r) {
6791
+ const s = [];
6792
+ for (const o of this.state.documents.keys()) {
6793
+ const f = this.openDocument(o), d = await r(f.query);
6794
+ s.push(...d);
6795
+ }
6796
+ return s;
6797
+ }
6766
6798
  // ── Internal ─────────────────────────────────────────────────────────────
6767
6799
  /** Expose the underlying database instance. Return type is inferred from the store (Dexie for local storage). */
6768
6800
  getDatabaseInstance() {
@@ -6770,51 +6802,51 @@ class es {
6770
6802
  }
6771
6803
  async refreshState() {
6772
6804
  const r = await this.store.getDocuments();
6773
- Ma(this.state.documents, r);
6805
+ Ka(this.state.documents, r);
6774
6806
  }
6775
6807
  }
6776
6808
  export {
6777
6809
  Di as A,
6778
6810
  Sn as B,
6779
6811
  ai as C,
6780
- Jo as D,
6812
+ ea as D,
6781
6813
  Oi as E,
6782
- Ka as F,
6783
- qa as G,
6814
+ qa as F,
6815
+ La as G,
6784
6816
  Ht as H,
6785
6817
  xt as I,
6786
- Ia as J,
6787
- Ma as K,
6788
- Wo as L,
6818
+ Pa as J,
6819
+ Ka as K,
6820
+ Xo as L,
6789
6821
  si as M,
6790
- ea as N,
6791
- es as P,
6822
+ ta as N,
6823
+ ts as P,
6792
6824
  Si as Q,
6793
6825
  Ye as T,
6794
- qo as a,
6826
+ Lo as a,
6795
6827
  oi as b,
6796
- $o as c,
6797
- da as d,
6828
+ Go as c,
6829
+ ha as d,
6798
6830
  ft as e,
6799
6831
  ze as f,
6800
- Go as g,
6832
+ Wo as g,
6801
6833
  Mi as h,
6802
- Vo as i,
6834
+ $o as i,
6803
6835
  Rn as j,
6804
- sa as k,
6805
- aa as l,
6806
- ja as m,
6836
+ ca as k,
6837
+ sa as l,
6838
+ Ma as m,
6807
6839
  bi as n,
6808
6840
  Er as o,
6809
6841
  wr as p,
6810
- oa as q,
6842
+ aa as q,
6811
6843
  xi as r,
6812
6844
  Ti as s,
6813
6845
  Ni as t,
6814
6846
  Ci as u,
6815
6847
  yi as v,
6816
6848
  vi as w,
6817
- ia as x,
6849
+ oa as x,
6818
6850
  me as y,
6819
6851
  Zt as z
6820
6852
  };