book-index-ui 0.65.0 → 0.65.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- import { VARIANT_SUPPLEMENT as ut } from "./variant-supplement.js";
2
- const ft = { official: 0, draft: 1 }, dt = { 0: "official", 1: "draft" }, yt = { book: 0, collection: 2, work: 3, entity: 4 }, gt = { 0: "book", 2: "collection", 3: "work", 4: "entity" }, tt = 62n, et = 59n, st = 19n, nt = 8n, ot = (1n << 40n) - 1n, mt = (1n << 3n) - 1n, pt = (1n << 11n) - 1n, wt = (1n << 8n) - 1n, $ = "0123456789abcdefghijklmnopqrstuvwxyz", it = /* @__PURE__ */ new Map();
1
+ import { VARIANT_SUPPLEMENT as ft } from "./variant-supplement.js";
2
+ const yt = { official: 0, draft: 1 }, gt = { 0: "official", 1: "draft" }, mt = { book: 0, collection: 2, work: 3, entity: 4 }, pt = { 0: "book", 2: "collection", 3: "work", 4: "entity" }, st = 62n, nt = 59n, ot = 19n, it = 8n, rt = (1n << 40n) - 1n, wt = (1n << 3n) - 1n, _t = (1n << 11n) - 1n, bt = (1n << 8n) - 1n, $ = "0123456789abcdefghijklmnopqrstuvwxyz", at = /* @__PURE__ */ new Map();
3
3
  for (let i = 0; i < $.length; i++)
4
- it.set($[i], BigInt(i));
4
+ at.set($[i], BigInt(i));
5
5
  function A(i) {
6
6
  if (i === 0n) return $[0];
7
7
  let t = "";
@@ -9,23 +9,23 @@ function A(i) {
9
9
  t = $[Number(i % 36n)] + t, i = i / 36n;
10
10
  return t;
11
11
  }
12
- function rt(i) {
12
+ function ct(i) {
13
13
  let t = 0n;
14
14
  for (const e of i) {
15
- const s = it.get(e);
15
+ const s = at.get(e);
16
16
  if (s === void 0)
17
17
  throw new Error(`Invalid Base36 character: ${e}`);
18
18
  t = t * 36n + s;
19
19
  }
20
20
  return t;
21
21
  }
22
- const H = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", at = /* @__PURE__ */ new Map();
23
- for (let i = 0; i < H.length; i++)
24
- at.set(H[i], BigInt(i));
25
- function _t(i) {
22
+ const q = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", lt = /* @__PURE__ */ new Map();
23
+ for (let i = 0; i < q.length; i++)
24
+ lt.set(q[i], BigInt(i));
25
+ function It(i) {
26
26
  let t = 0n;
27
27
  for (const e of i) {
28
- const s = at.get(e);
28
+ const s = lt.get(e);
29
29
  if (s === void 0)
30
30
  throw new Error(`Invalid Base58 character: ${e}`);
31
31
  t = t * 58n + s;
@@ -33,39 +33,51 @@ function _t(i) {
33
33
  return t;
34
34
  }
35
35
  function _(i) {
36
- return /[A-Z]/.test(i) ? _t(i) : rt(i);
36
+ return /[A-Z]/.test(i) ? It(i) : ct(i);
37
37
  }
38
- const Gt = A, qt = rt;
38
+ const Kt = A, Yt = ct;
39
39
  function k(i) {
40
- const t = Number(i >> tt & 1n), e = Number(i >> et & mt), s = i >> st & ot, n = Number(i >> nt & pt), o = Number(i & wt);
40
+ const t = Number(i >> st & 1n), e = Number(i >> nt & wt), s = i >> ot & rt, n = Number(i >> it & _t), o = Number(i & bt);
41
41
  return {
42
- status: dt[t] ?? "draft",
43
- type: gt[e] ?? "book",
42
+ status: gt[t] ?? "draft",
43
+ type: pt[e] ?? "book",
44
44
  timestamp: s,
45
45
  machineId: n,
46
46
  sequence: o
47
47
  };
48
48
  }
49
- function G(i, t, e, s, n) {
50
- return BigInt(ft[i]) << tt | BigInt(yt[t]) << et | (e & ot) << st | BigInt(s) << nt | BigInt(n);
49
+ function z(i, t, e, s, n) {
50
+ return BigInt(yt[i]) << st | BigInt(mt[t]) << nt | (e & rt) << ot | BigInt(s) << it | BigInt(n);
51
51
  }
52
52
  function E(i) {
53
53
  return k(_(i));
54
54
  }
55
- function bt(i) {
55
+ function kt(i) {
56
56
  return E(i).type;
57
57
  }
58
- function zt(i) {
58
+ function Vt(i) {
59
59
  return E(i).status;
60
60
  }
61
- const j = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" }, It = { Book: "book", Collection: "collection", Work: "work", Entity: "entity" }, S = 16;
61
+ const j = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" }, St = { Book: "book", Collection: "collection", Work: "work", Entity: "entity" }, S = 16, Et = "附刻";
62
+ function L(i) {
63
+ const t = (n) => typeof n == "string" ? n : (n == null ? void 0 : n.book_title) ?? "", e = [], s = [];
64
+ for (const n of Array.isArray(i) ? i : [])
65
+ if (n && typeof n == "object" && n.type === Et) {
66
+ const o = t(n);
67
+ o && e.push(o);
68
+ } else {
69
+ const o = t(n);
70
+ o && s.push(o);
71
+ }
72
+ return { aliases: s, attached: e };
73
+ }
62
74
  function P(i, t = S) {
63
75
  let e = 0;
64
76
  for (let s = 0; s < i.length; s++)
65
77
  e = Math.imul(e, 31) + i.charCodeAt(s) >>> 0;
66
78
  return e % t;
67
79
  }
68
- function kt(i) {
80
+ function vt(i) {
69
81
  const t = {}, e = i.dating;
70
82
  if (typeof e != "object" || e === null) return t;
71
83
  const s = e.era;
@@ -83,7 +95,7 @@ function w(...i) {
83
95
  const t = i.join("/");
84
96
  return t.startsWith("//") ? "//" + t.slice(2).replace(/\/+/g, "/") : t.replace(/\/+/g, "/");
85
97
  }
86
- function St(i) {
98
+ function xt(i) {
87
99
  if (!Array.isArray(i)) return "";
88
100
  for (const t of i)
89
101
  if (typeof t == "object" && t !== null) {
@@ -92,70 +104,70 @@ function St(i) {
92
104
  }
93
105
  return "";
94
106
  }
95
- function q(i, t, e) {
96
- var W;
107
+ function K(i, t, e) {
108
+ var G;
97
109
  const s = i.id || "";
98
110
  let n = "", o = "", r = "";
99
111
  const c = i.authors;
100
112
  if (Array.isArray(c) && c.length > 0) {
101
- const y = c[0];
102
- typeof y == "object" && y !== null ? (n = y.name || "", r = y.role || "") : n = String(y);
113
+ const g = c[0];
114
+ typeof g == "object" && g !== null ? (n = g.name || "", r = g.role || "") : n = String(g);
103
115
  } else typeof c == "string" && (n = c);
104
- o = St(c) || (typeof i.dynasty == "string" ? i.dynasty : "");
116
+ o = xt(c) || (typeof i.dynasty == "string" ? i.dynasty : "");
105
117
  let a = "";
106
118
  const l = i.current_location;
107
119
  if (typeof l == "object" && l !== null ? a = l.name || "" : typeof l == "string" && (a = l), !a && Array.isArray(i.provenance) && i.provenance.length > 0) {
108
- const y = (W = i.provenance[0]) == null ? void 0 : W.institution;
109
- typeof y == "string" && (a = y);
110
- }
111
- const u = Array.isArray(i.additional_titles) ? i.additional_titles.map((y) => typeof y == "string" ? y : y == null ? void 0 : y.book_title).filter(Boolean) : void 0, h = Array.isArray(i.attached_texts) ? i.attached_texts.map((y) => typeof y == "string" ? y : y == null ? void 0 : y.book_title).filter(Boolean) : void 0;
112
- let d;
113
- const f = i.juan_count;
114
- if (typeof f == "number" ? d = f : typeof f == "object" && f !== null && (d = f.number || void 0), !d && Array.isArray(i.measures)) {
115
- const y = i.measures.find((I) => I && I.unit === "卷" && typeof I.number == "number" && I.number > 0);
116
- y && (d = y.number);
117
- }
118
- const m = typeof i.measure_info == "string" ? i.measure_info : "";
119
- let b = !1, L = !1;
120
- const B = i.resources;
121
- if (Array.isArray(B))
122
- for (const y of B) {
123
- if (typeof y != "object" || y === null) continue;
124
- const I = y.types;
125
- Array.isArray(I) && (I.includes("text") && (b = !0), I.includes("image") && (L = !0));
126
- }
127
- const g = {
120
+ const g = (G = i.provenance[0]) == null ? void 0 : G.institution;
121
+ typeof g == "string" && (a = g);
122
+ }
123
+ const h = L(i.additional_titles), u = Array.isArray(i.additional_titles) ? h.aliases : void 0, d = h.attached.length > 0 ? h.attached : void 0;
124
+ let f;
125
+ const m = i.juan_count;
126
+ if (typeof m == "number" ? f = m : typeof m == "object" && m !== null && (f = m.number || void 0), !f && Array.isArray(i.measures)) {
127
+ const g = i.measures.find((I) => I && I.unit === "卷" && typeof I.number == "number" && I.number > 0);
128
+ g && (f = g.number);
129
+ }
130
+ const b = typeof i.measure_info == "string" ? i.measure_info : "";
131
+ let R = !1, B = !1;
132
+ const M = i.resources;
133
+ if (Array.isArray(M))
134
+ for (const g of M) {
135
+ if (typeof g != "object" || g === null) continue;
136
+ const I = g.types;
137
+ Array.isArray(I) && (I.includes("text") && (R = !0), I.includes("image") && (B = !0));
138
+ }
139
+ const y = {
128
140
  id: s,
129
141
  title: i.title || "未命名",
130
142
  type: j[t],
131
143
  path: e,
132
- ...kt(i)
144
+ ...vt(i)
133
145
  };
134
- n && (g.author = n), a && (g.holder = a), u && u.length > 0 && (g.additional_titles = u), h && h.length > 0 && (g.attached_texts = h), d && (g.juan_count = d), m && (g.measure_info = m);
135
- const R = typeof i.edition == "string" ? i.edition : "";
136
- R && (g.edition = R), b && (g.has_text = !0), L && (g.has_image = !0), o && (g.dynasty = o), r && (g.role = r);
137
- const M = typeof i.subtype == "string" ? i.subtype : "";
138
- M && (g.subtype = M);
139
- const D = typeof i.period == "string" ? i.period : "";
140
- D && (g.period = D);
141
- const O = typeof i.loss_status == "string" ? i.loss_status : "";
142
- O && (g.loss_status = O);
143
- const U = typeof i.original_title == "string" ? i.original_title : "";
144
- U && (g.original_title = U);
145
- const N = typeof i.work_id == "string" ? i.work_id : "";
146
- N && (g.work_id = N);
147
- const J = typeof i._promoted_to == "string" ? i._promoted_to : "";
148
- return J && (g.promoted_to = J), g;
146
+ n && (y.author = n), a && (y.holder = a), u && u.length > 0 && (y.additional_titles = u), d && d.length > 0 && (y.attached_texts = d), f && (y.juan_count = f), b && (y.measure_info = b);
147
+ const D = typeof i.edition == "string" ? i.edition : "";
148
+ D && (y.edition = D), R && (y.has_text = !0), B && (y.has_image = !0), o && (y.dynasty = o), r && (y.role = r);
149
+ const O = typeof i.subtype == "string" ? i.subtype : "";
150
+ O && (y.subtype = O);
151
+ const U = typeof i.period == "string" ? i.period : "";
152
+ U && (y.period = U);
153
+ const N = typeof i.loss_status == "string" ? i.loss_status : "";
154
+ N && (y.loss_status = N);
155
+ const J = typeof i.original_title == "string" ? i.original_title : "";
156
+ J && (y.original_title = J);
157
+ const W = typeof i.work_id == "string" ? i.work_id : "";
158
+ W && (y.work_id = W);
159
+ const H = typeof i._promoted_to == "string" ? i._promoted_to : "";
160
+ return H && (y.promoted_to = H), y;
149
161
  }
150
- const Et = 60;
151
- function vt(i) {
162
+ const $t = 60;
163
+ function At(i) {
152
164
  const t = i.replace(
153
165
  /[^㐀-䶿一-鿿豈-﫿a-zA-Z0-9\u{20000}-\u{3134f}]/gu,
154
166
  ""
155
167
  );
156
- return Array.from(t).slice(0, Et).join("") || "Undefined";
168
+ return Array.from(t).slice(0, $t).join("") || "Undefined";
157
169
  }
158
- class ct {
170
+ class ht {
159
171
  constructor(t, e) {
160
172
  this.fs = t, this.officialRoot = w(e, "book-index"), this.draftRoot = w(e, "book-index-draft");
161
173
  }
@@ -171,7 +183,7 @@ class ct {
171
183
  */
172
184
  getPath(t, e, s) {
173
185
  const n = this.getRootById(e), o = e.padEnd(3, "_").substring(0, 3), [r, c, a] = [o[0], o[1], o[2]], l = j[t];
174
- return w(n, l, r, c, a, `${e}-${vt(s)}.json`);
186
+ return w(n, l, r, c, a, `${e}-${At(s)}.json`);
175
187
  }
176
188
  /**
177
189
  * 保存条目并更新索引
@@ -184,9 +196,9 @@ class ct {
184
196
  } catch {
185
197
  }
186
198
  const l = c.substring(0, c.lastIndexOf("/"));
187
- await this.fs.mkdir(l), s.id = e, s.type = t, await this.fs.writeFile(c, JSON.stringify(s, xt, 2));
188
- const u = this.getRootById(e), h = c.substring(u.length + 1);
189
- return await this.updateIndexEntry(u, s, t, h), c;
199
+ await this.fs.mkdir(l), s.id = e, s.type = t, await this.fs.writeFile(c, JSON.stringify(s, Pt, 2));
200
+ const h = this.getRootById(e), u = c.substring(h.length + 1);
201
+ return await this.updateIndexEntry(h, s, t, u), c;
190
202
  }
191
203
  /**
192
204
  * 更新索引分片中的条目
@@ -194,7 +206,7 @@ class ct {
194
206
  async updateIndexEntry(t, e, s, n) {
195
207
  const o = e.id || "";
196
208
  if (!o) return;
197
- const r = `${s}s`, c = await this.loadShard(t, r, o), a = q(e, s, n);
209
+ const r = `${s}s`, c = await this.loadShard(t, r, o), a = K(e, s, n);
198
210
  c[o] = a, await this.saveShard(t, r, o, c);
199
211
  }
200
212
  /**
@@ -216,8 +228,8 @@ class ct {
216
228
  const a = w(r, c, s, n, o);
217
229
  if (await this.fs.exists(a))
218
230
  try {
219
- const u = (await this.fs.readdir(a)).find((h) => h.startsWith(`${t}-`) && h.endsWith(".json"));
220
- if (u) return w(a, u);
231
+ const h = (await this.fs.readdir(a)).find((u) => u.startsWith(`${t}-`) && u.endsWith(".json"));
232
+ if (h) return w(a, h);
221
233
  } catch {
222
234
  }
223
235
  }
@@ -313,26 +325,26 @@ class ct {
313
325
  for (const n of ["Book", "Collection", "Work"]) {
314
326
  const o = w(e, n);
315
327
  if (!await this.fs.exists(o)) continue;
316
- const r = It[n], c = `${r}s`, a = await this.fs.glob(o, "**/*.json");
328
+ const r = St[n], c = `${r}s`, a = await this.fs.glob(o, "**/*.json");
317
329
  for (const l of a)
318
330
  if (!l.includes("/index/"))
319
331
  try {
320
- const u = await this.loadMetadata(l);
321
- let h = u.id || u.ID || "";
322
- if (!h) {
332
+ const h = await this.loadMetadata(l);
333
+ let u = h.id || h.ID || "";
334
+ if (!u) {
323
335
  const b = l.substring(l.lastIndexOf("/") + 1);
324
- b.includes("-") && (h = b.split("-")[0]);
336
+ b.includes("-") && (u = b.split("-")[0]);
325
337
  }
326
- if (!h) continue;
327
- const d = l.substring(e.length + 1), f = q({ ...u, id: h }, r, d), m = c === "collections" ? 0 : P(h);
328
- s[c][m][h] = f;
338
+ if (!u) continue;
339
+ const d = l.substring(e.length + 1), f = K({ ...h, id: u }, r, d), m = c === "collections" ? 0 : P(u);
340
+ s[c][m][u] = f;
329
341
  } catch {
330
342
  }
331
343
  }
332
344
  for (const [n, o] of Object.entries(s))
333
345
  for (const [r, c] of Object.entries(o)) {
334
346
  const a = this.shardPath(e, n, Number(r)), l = a.substring(0, a.lastIndexOf("/"));
335
- await this.fs.mkdir(l), await this.fs.writeFile(a, JSON.stringify(z(c), null, await this.detectShardIndent(a)));
347
+ await this.fs.mkdir(l), await this.fs.writeFile(a, JSON.stringify(Y(c), null, await this.detectShardIndent(a)));
336
348
  }
337
349
  }
338
350
  // ── Asset Directory ──
@@ -341,8 +353,8 @@ class ct {
341
353
  * 与 JSON 文件同级,以 ID 命名
342
354
  */
343
355
  getAssetDir(t) {
344
- const e = this.getRootById(t), s = _(t), o = k(s).type, r = t.padEnd(3, "_").substring(0, 3), [c, a, l] = [r[0], r[1], r[2]], u = j[o];
345
- return w(e, u, c, a, l, t);
356
+ const e = this.getRootById(t), s = _(t), o = k(s).type, r = t.padEnd(3, "_").substring(0, 3), [c, a, l] = [r[0], r[1], r[2]], h = j[o];
357
+ return w(e, h, c, a, l, t);
346
358
  }
347
359
  /**
348
360
  * 初始化资源目录:创建 {ID}/ 文件夹
@@ -397,7 +409,7 @@ class ct {
397
409
  const o = P(s), r = this.shardPath(t, e, o), c = r.substring(0, r.lastIndexOf("/"));
398
410
  await this.fs.mkdir(c);
399
411
  const a = await this.detectShardIndent(r);
400
- await this.fs.writeFile(r, JSON.stringify(z(n), null, a));
412
+ await this.fs.writeFile(r, JSON.stringify(Y(n), null, a));
401
413
  }
402
414
  async loadAllShards(t, e) {
403
415
  const s = {};
@@ -432,8 +444,8 @@ function C(i, t) {
432
444
  n === e ? s = 200 : n.startsWith(e) ? s = 150 : n.includes(e) && (s = 100);
433
445
  const o = [...i.additional_titles || [], ...i.attached_texts || []];
434
446
  for (const l of o) {
435
- const u = l.toLowerCase();
436
- u === e ? s = Math.max(s, 120) : u.startsWith(e) ? s = Math.max(s, 90) : u.includes(e) && (s = Math.max(s, 60));
447
+ const h = l.toLowerCase();
448
+ h === e ? s = Math.max(s, 120) : h.startsWith(e) ? s = Math.max(s, 90) : h.includes(e) && (s = Math.max(s, 60));
437
449
  }
438
450
  let r = 0;
439
451
  if (i.author) {
@@ -445,19 +457,19 @@ function C(i, t) {
445
457
  let a = s;
446
458
  return a === 0 && (a = Math.max(r, c)), a === 0 ? 0 : (a += Math.max(0, 20 - n.length), i.type === "work" ? a = Math.round(a * 1.05) : i.type === "collection" && (a = Math.round(a * 1.02)), i.has_text && (a += 3), i.has_image && (a += 2), a);
447
459
  }
448
- function z(i) {
460
+ function Y(i) {
449
461
  const t = {};
450
462
  for (const e of Object.keys(i).sort()) t[e] = i[e];
451
463
  return t;
452
464
  }
453
- function xt(i, t) {
465
+ function Pt(i, t) {
454
466
  return t === null ? void 0 : t;
455
467
  }
456
468
  function T(i, t) {
457
469
  const e = i.map((s) => ({ entry: s, score: C(s, t) })).filter((s) => s.score > 0);
458
470
  return e.sort((s, n) => n.score !== s.score ? n.score - s.score : s.entry.title.length - n.entry.title.length), e.map((s) => s.entry);
459
471
  }
460
- function K(i, t, e, s) {
472
+ function V(i, t, e, s) {
461
473
  const n = i.map((o) => {
462
474
  const r = C(o, t);
463
475
  let c = 0;
@@ -476,7 +488,7 @@ function K(i, t, e, s) {
476
488
  }).filter((o) => o.score > 0);
477
489
  return n.sort((o, r) => r.score !== o.score ? r.score - o.score : o.entry.title.length - r.entry.title.length), n.map((o) => o.entry);
478
490
  }
479
- function $t(i) {
491
+ function jt(i) {
480
492
  const t = i.volumes ?? [];
481
493
  let e, s;
482
494
  if (t.length === 0)
@@ -516,24 +528,24 @@ function $t(i) {
516
528
  n[o] === void 0 && delete n[o];
517
529
  return n;
518
530
  }
519
- function At(i) {
531
+ function Ct(i) {
520
532
  const t = {
521
533
  total_books: i.total_books ?? 0
522
534
  };
523
535
  return i.processed_volumes != null && (t.processed_volumes = i.processed_volumes), i.matched_works != null && (t.matched_works = i.matched_works), i.unmatched_works != null && (t.unmatched_works = i.unmatched_works), i.total_found_volumes != null && (t.total_found_volumes = i.total_found_volumes), t;
524
536
  }
525
- function lt(i) {
537
+ function ut(i) {
526
538
  var n;
527
- const t = i, e = (t.books ?? []).map($t), s = {
539
+ const t = i, e = (t.books ?? []).map(jt), s = {
528
540
  collection_id: t.collection_id ?? "",
529
541
  title: t.title ?? "",
530
542
  total_volumes: t.total_volumes ?? 0,
531
- stats: At(t.stats ?? {}),
543
+ stats: Ct(t.stats ?? {}),
532
544
  books: e
533
545
  };
534
546
  return t.source && (s.source = t.source), t.resource_id && (s.resource_id = t.resource_id), t.resource_name && (s.resource_name = t.resource_name), (n = t.sections) != null && n.length && (s.sections = t.sections), t.volume_index && Object.keys(t.volume_index).length > 0 && (s.volume_index = t.volume_index), s;
535
547
  }
536
- const Y = 2;
548
+ const X = 2;
537
549
  function F(i) {
538
550
  const t = /* @__PURE__ */ new Map();
539
551
  if (!i || typeof i != "object") return t;
@@ -548,7 +560,7 @@ function F(i) {
548
560
  o && typeof o == "object" && typeof o.production_id == "string" && t.set(n, o.production_id);
549
561
  return t;
550
562
  }
551
- const Pt = {
563
+ const Tt = {
552
564
  㐫: "凶",
553
565
  㐮: "襄",
554
566
  㐲: "伏",
@@ -1302,29 +1314,29 @@ const Pt = {
1302
1314
  "𫝊": "傳",
1303
1315
  "𬒳": "被",
1304
1316
  "兔": "兔"
1305
- }, jt = Pt;
1306
- function Ct(i) {
1317
+ }, Ft = Tt;
1318
+ function Lt(i) {
1307
1319
  if (!i) return i;
1308
1320
  let t = !1, e = "";
1309
1321
  for (const s of i) {
1310
- const n = jt[s] ?? ut[s];
1322
+ const n = Ft[s] ?? ft[s];
1311
1323
  n !== void 0 ? (e += n, t = !0) : e += s;
1312
1324
  }
1313
1325
  return t ? e : i;
1314
1326
  }
1315
- const Tt = "https://raw.githubusercontent.com", Ft = [
1327
+ const Rt = "https://raw.githubusercontent.com", Bt = [
1316
1328
  "https://fastly.jsdelivr.net/gh",
1317
1329
  "https://cdn.jsdelivr.net/gh"
1318
- ], Lt = 5e3;
1319
- class Kt {
1330
+ ], Mt = 5e3;
1331
+ class Xt {
1320
1332
  // null=未加载, false=不可用
1321
1333
  constructor(t) {
1322
1334
  this.cache = null, this.cacheLoading = null, this.pathMap = /* @__PURE__ */ new Map(), this.promotions = /* @__PURE__ */ new Map(), this.searchSCache = null, this.t2sConverter = null, this.config = {
1323
1335
  org: t.org,
1324
1336
  repos: t.repos,
1325
- baseUrl: t.baseUrl ?? Tt,
1326
- cdnUrls: t.cdnUrls ?? Ft,
1327
- timeout: t.timeout ?? Lt
1337
+ baseUrl: t.baseUrl ?? Rt,
1338
+ cdnUrls: t.cdnUrls ?? Bt,
1339
+ timeout: t.timeout ?? Mt
1328
1340
  };
1329
1341
  }
1330
1342
  /** 拉取 promotions.json(仅 draft repo 有);失败按空映射处理。 */
@@ -1457,41 +1469,40 @@ class Kt {
1457
1469
  }
1458
1470
  /** 解析 index.json 为 IndexEntry[] */
1459
1471
  parseIndexResponse(t, e) {
1460
- var o, r;
1461
1472
  const s = [], n = [
1462
1473
  ["books", "book"],
1463
1474
  ["collections", "collection"],
1464
1475
  ["works", "work"],
1465
1476
  ["entities", "entity"]
1466
1477
  ];
1467
- for (const [c, a] of n) {
1468
- const l = t[c];
1469
- if (l)
1470
- for (const u of Object.values(l)) {
1471
- const h = u, d = a === "entity" ? h.primary_name || u.title || u.name || u.id : u.title || u.name || u.id;
1478
+ for (const [o, r] of n) {
1479
+ const c = t[o];
1480
+ if (c)
1481
+ for (const a of Object.values(c)) {
1482
+ const l = a, h = L(l.additional_titles), u = r === "entity" ? l.primary_name || a.title || a.name || a.id : a.title || a.name || a.id;
1472
1483
  s.push({
1473
- id: u.id,
1474
- title: d,
1475
- type: a,
1484
+ id: a.id,
1485
+ title: u,
1486
+ type: r,
1476
1487
  isDraft: e,
1477
- author: u.author,
1478
- dynasty: u.dynasty,
1479
- role: u.role,
1480
- path: u.path,
1481
- additional_titles: (o = h.additional_titles) == null ? void 0 : o.map((f) => typeof f == "string" ? f : f == null ? void 0 : f.book_title).filter(Boolean),
1482
- attached_texts: (r = h.attached_texts) == null ? void 0 : r.map((f) => typeof f == "string" ? f : f == null ? void 0 : f.book_title).filter(Boolean),
1483
- edition: h.edition,
1484
- juan_count: h.juan_count,
1485
- has_text: h.has_text,
1486
- has_image: h.has_image,
1487
- has_collated: h.has_collated,
1488
- subtype: h.subtype,
1489
- primary_name: h.primary_name,
1490
- birth_year: h.birth_year,
1491
- death_year: h.death_year,
1492
- cbdb_id: h.cbdb_id,
1493
- promoted_to: h.promoted_to
1494
- }), this.pathMap.set(u.id, { path: u.path, isDraft: e });
1488
+ author: a.author,
1489
+ dynasty: a.dynasty,
1490
+ role: a.role,
1491
+ path: a.path,
1492
+ additional_titles: l.additional_titles ? h.aliases : void 0,
1493
+ attached_texts: h.attached.length ? h.attached : void 0,
1494
+ edition: l.edition,
1495
+ juan_count: l.juan_count,
1496
+ has_text: l.has_text,
1497
+ has_image: l.has_image,
1498
+ has_collated: l.has_collated,
1499
+ subtype: l.subtype,
1500
+ primary_name: l.primary_name,
1501
+ birth_year: l.birth_year,
1502
+ death_year: l.death_year,
1503
+ cbdb_id: l.cbdb_id,
1504
+ promoted_to: l.promoted_to
1505
+ }), this.pathMap.set(a.id, { path: a.path, isDraft: e });
1495
1506
  }
1496
1507
  }
1497
1508
  return s;
@@ -1509,7 +1520,7 @@ class Kt {
1509
1520
  return { searchS: {}, converter: null };
1510
1521
  try {
1511
1522
  const c = (await import("opencc-js")).Converter({ from: "t", to: "cn" });
1512
- this.t2sConverter = (a) => c(Ct(a));
1523
+ this.t2sConverter = (a) => c(Lt(a));
1513
1524
  } catch {
1514
1525
  return this.t2sConverter = !1, this.searchSCache = {}, { searchS: {}, converter: null };
1515
1526
  }
@@ -1522,11 +1533,11 @@ class Kt {
1522
1533
  }
1523
1534
  if ((n = r.additional_titles) != null && n.length) {
1524
1535
  const l = r.additional_titles.map(e);
1525
- l.some((u, h) => u !== r.additional_titles[h]) && (c.at = l);
1536
+ l.some((h, u) => h !== r.additional_titles[u]) && (c.at = l);
1526
1537
  }
1527
1538
  if ((o = r.attached_texts) != null && o.length) {
1528
1539
  const l = r.attached_texts.map(e);
1529
- l.some((u, h) => u !== r.attached_texts[h]) && (c.axt = l);
1540
+ l.some((h, u) => h !== r.attached_texts[u]) && (c.axt = l);
1530
1541
  }
1531
1542
  Object.keys(c).length > 0 && (s[r.id] = c);
1532
1543
  }
@@ -1534,10 +1545,10 @@ class Kt {
1534
1545
  }
1535
1546
  // --- IndexStorage 实现 ---
1536
1547
  async loadEntries(t, e) {
1537
- let n = (await this.ensureLoaded()).filter((h) => h.type === t);
1548
+ let n = (await this.ensureLoaded()).filter((u) => u.type === t);
1538
1549
  const o = e.sortBy || "title", r = e.sortOrder || "asc";
1539
- n.sort((h, d) => {
1540
- const f = String(h[o] ?? ""), m = String(d[o] ?? ""), b = f.localeCompare(m, "zh");
1550
+ n.sort((u, d) => {
1551
+ const f = String(u[o] ?? ""), m = String(d[o] ?? ""), b = f.localeCompare(m, "zh");
1541
1552
  return r === "asc" ? b : -b;
1542
1553
  });
1543
1554
  const c = e.page || 1, a = e.pageSize || 50, l = (c - 1) * a;
@@ -1549,18 +1560,18 @@ class Kt {
1549
1560
  };
1550
1561
  }
1551
1562
  async search(t, e, s) {
1552
- const n = await this.ensureLoaded(), { searchS: o, converter: r } = await this.ensureSearchSBuilt(), c = n.filter((m) => m.type === e), a = r ? r(t) : void 0, u = Object.keys(o).length > 0 ? K(c, t, a, o) : T(c, t), h = s.page || 1, d = s.pageSize || 50, f = (h - 1) * d;
1563
+ const n = await this.ensureLoaded(), { searchS: o, converter: r } = await this.ensureSearchSBuilt(), c = n.filter((m) => m.type === e), a = r ? r(t) : void 0, h = Object.keys(o).length > 0 ? V(c, t, a, o) : T(c, t), u = s.page || 1, d = s.pageSize || 50, f = (u - 1) * d;
1553
1564
  return {
1554
- entries: u.slice(f, f + d),
1555
- total: u.length,
1556
- page: h,
1565
+ entries: h.slice(f, f + d),
1566
+ total: h.length,
1567
+ page: u,
1557
1568
  pageSize: d
1558
1569
  };
1559
1570
  }
1560
1571
  async searchAll(t, e = 5) {
1561
- const s = await this.ensureLoaded(), { searchS: n, converter: o } = await this.ensureSearchSBuilt(), r = ["work", "book", "collection"], c = o ? o(t) : void 0, a = Object.keys(n).length > 0, l = r.map((u) => {
1562
- const h = s.filter((d) => d.type === u);
1563
- return a ? K(h, t, c, n) : T(h, t);
1572
+ const s = await this.ensureLoaded(), { searchS: n, converter: o } = await this.ensureSearchSBuilt(), r = ["work", "book", "collection"], c = o ? o(t) : void 0, a = Object.keys(n).length > 0, l = r.map((h) => {
1573
+ const u = s.filter((d) => d.type === h);
1574
+ return a ? V(u, t, c, n) : T(u, t);
1564
1575
  });
1565
1576
  return {
1566
1577
  works: l[0].slice(0, e),
@@ -1634,18 +1645,18 @@ class Kt {
1634
1645
  const e = { book: "Book", collection: "Collection", work: "Work", entity: "Entity" };
1635
1646
  let s, n;
1636
1647
  try {
1637
- const u = k(_(t));
1638
- s = u.type, n = u.status;
1648
+ const h = k(_(t));
1649
+ s = h.type, n = h.status;
1639
1650
  } catch {
1640
1651
  return null;
1641
1652
  }
1642
1653
  const o = n === "draft" ? this.config.repos.draft : this.config.repos.official, r = e[s], c = t.padEnd(3, "_").substring(0, 3), a = `${r}/${c[0]}/${c[1]}/${c[2]}`, l = `https://api.github.com/repos/${this.config.org}/${o}/contents/${a}`;
1643
1654
  try {
1644
- const u = await fetch(l, {
1655
+ const h = await fetch(l, {
1645
1656
  signal: AbortSignal.timeout(this.config.timeout)
1646
1657
  });
1647
- if (!u.ok) return null;
1648
- const d = (await u.json()).find((m) => m.name.startsWith(`${t}-`) && m.name.endsWith(".json"));
1658
+ if (!h.ok) return null;
1659
+ const d = (await h.json()).find((m) => m.name.startsWith(`${t}-`) && m.name.endsWith(".json"));
1649
1660
  if (!d) return null;
1650
1661
  const f = await this.fetchItemByPath(o, d.path);
1651
1662
  return f && this.pathMap.set(t, { path: d.path, isDraft: n === "draft" }), f;
@@ -1720,7 +1731,7 @@ class Kt {
1720
1731
  a && o.push({
1721
1732
  resource_id: r.id,
1722
1733
  short_name: r.short_name,
1723
- data: lt(a)
1734
+ data: ut(a)
1724
1735
  });
1725
1736
  }
1726
1737
  return o.length > 0 ? o : null;
@@ -1756,8 +1767,8 @@ class Kt {
1756
1767
  this.cache = null, this.pathMap.clear(), this.searchSCache = null, this.t2sConverter = null;
1757
1768
  }
1758
1769
  }
1759
- const V = 255;
1760
- class ht {
1770
+ const Q = 255;
1771
+ class dt {
1761
1772
  constructor(t) {
1762
1773
  if (this.lastTimestamp = -1, this.lastStatus = null, this.sequence = 0, t < 0 || t > 2047)
1763
1774
  throw new Error("Machine ID must be between 0 and 2047");
@@ -1770,8 +1781,8 @@ class ht {
1770
1781
  let s = this._getCurrentTimestamp(t);
1771
1782
  if (s < this.lastTimestamp && t === this.lastStatus)
1772
1783
  throw new Error("Clock moved backwards. Refusing to generate ID.");
1773
- s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & V, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t;
1774
- const n = G(t, e, BigInt(s), this.machineId, this.sequence);
1784
+ s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & Q, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t;
1785
+ const n = z(t, e, BigInt(s), this.machineId, this.sequence);
1775
1786
  return A(n);
1776
1787
  }
1777
1788
  /**
@@ -1781,7 +1792,7 @@ class ht {
1781
1792
  let s = this._getCurrentTimestamp(t);
1782
1793
  if (s < this.lastTimestamp && t === this.lastStatus)
1783
1794
  throw new Error("Clock moved backwards. Refusing to generate ID.");
1784
- return s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & V, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t, G(t, e, BigInt(s), this.machineId, this.sequence);
1795
+ return s === this.lastTimestamp && t === this.lastStatus ? (this.sequence = this.sequence + 1 & Q, this.sequence === 0 && (s = this._tilNextUnit(this.lastTimestamp, t))) : this.sequence = 0, this.lastTimestamp = s, this.lastStatus = t, z(t, e, BigInt(s), this.machineId, this.sequence);
1785
1796
  }
1786
1797
  _getCurrentTimestamp(t) {
1787
1798
  const e = Date.now();
@@ -1794,9 +1805,9 @@ class ht {
1794
1805
  return s;
1795
1806
  }
1796
1807
  }
1797
- class Yt {
1808
+ class Qt {
1798
1809
  constructor(t) {
1799
- this.recentEntities = [], this.storage = new ct(t.fs, t.workspaceRoot), this.idGen = new ht(t.machineId ?? 0), this.fs = t.fs, this.workspaceRoot = t.workspaceRoot;
1810
+ this.recentEntities = [], this.storage = new ht(t.fs, t.workspaceRoot), this.idGen = new dt(t.machineId ?? 0), this.fs = t.fs, this.workspaceRoot = t.workspaceRoot;
1800
1811
  }
1801
1812
  async loadEntries(t, e) {
1802
1813
  const s = await this.storage.loadEntries(t);
@@ -2012,8 +2023,8 @@ class Yt {
2012
2023
  const s = e.page ?? 1, n = e.pageSize ?? 50;
2013
2024
  if (e.sortBy) {
2014
2025
  const a = e.sortBy, l = e.sortOrder === "desc" ? -1 : 1;
2015
- t.sort((u, h) => {
2016
- const d = u[a] ?? "", f = h[a] ?? "";
2026
+ t.sort((h, u) => {
2027
+ const d = h[a] ?? "", f = u[a] ?? "";
2017
2028
  return d < f ? -l : d > f ? l : 0;
2018
2029
  });
2019
2030
  }
@@ -2021,33 +2032,33 @@ class Yt {
2021
2032
  return { entries: t.slice(r, r + n), total: o, page: s, pageSize: n };
2022
2033
  }
2023
2034
  }
2024
- function Vt(i) {
2035
+ function Zt(i) {
2025
2036
  return i === "collated" || i === "self_collated";
2026
2037
  }
2027
- const Bt = ["default", "manifest", "fragments", "sources", "extra"], Rt = /^[a-z][a-z0-9-]*$/;
2028
- function X(i) {
2029
- return typeof i != "string" ? !1 : i === "default" ? !0 : Rt.test(i) && !Bt.includes(i);
2038
+ const Dt = ["default", "manifest", "fragments", "sources", "extra"], Ot = /^[a-z][a-z0-9-]*$/;
2039
+ function Z(i) {
2040
+ return typeof i != "string" ? !1 : i === "default" ? !0 : Ot.test(i) && !Dt.includes(i);
2030
2041
  }
2031
- function Xt(i) {
2042
+ function te(i) {
2032
2043
  return /^\d+$/.test(i);
2033
2044
  }
2034
2045
  function x(i) {
2035
2046
  return i.length > 0 && !i.includes("..") && !/[\\/?#%\s\u0000-\u001f\u007f]/.test(i);
2036
2047
  }
2037
- const Mt = /^(整理本|整理|转录全文|轉錄全文|转录|轉錄|全文|文本)$/;
2038
- function Qt(i) {
2048
+ const Ut = /^(整理本|整理|转录全文|轉錄全文|转录|轉錄|全文|文本)$/;
2049
+ function ee(i) {
2039
2050
  var s;
2040
- const t = Dt(i), e = (s = i.edition_label) == null ? void 0 : s.trim();
2051
+ const t = Nt(i), e = (s = i.edition_label) == null ? void 0 : s.trim();
2041
2052
  return e && e !== t ? `${e} · ${t}` : t;
2042
2053
  }
2043
- function Dt(i) {
2054
+ function Nt(i) {
2044
2055
  for (const t of [i.label, i.source_name]) {
2045
2056
  const e = t == null ? void 0 : t.trim();
2046
- if (e && !Mt.test(e)) return e;
2057
+ if (e && !Ut.test(e)) return e;
2047
2058
  }
2048
2059
  return i.label || i.source_name || i.key;
2049
2060
  }
2050
- function Zt(i, t) {
2061
+ function se(i, t) {
2051
2062
  const e = (t == null ? void 0 : t.chapters) ?? [];
2052
2063
  if (e.length === 0) return null;
2053
2064
  if (i) {
@@ -2060,15 +2071,15 @@ function Zt(i, t) {
2060
2071
  }
2061
2072
  return e[0].file;
2062
2073
  }
2063
- function te(i, t) {
2074
+ function ne(i, t) {
2064
2075
  const e = i == null ? void 0 : i.versions;
2065
2076
  if (!(!e || e.length === 0))
2066
2077
  return (t != null ? e.find((s) => s.key === t) : void 0) ?? e.find((s) => s.key === "default") ?? e[0];
2067
2078
  }
2068
- const Ot = "/data", Ut = 1e4;
2069
- class ee {
2079
+ const Jt = "/data", Wt = 1e4;
2080
+ class oe {
2070
2081
  constructor(t = {}) {
2071
- this.hubsLoading = null, this.chunkCache = /* @__PURE__ */ new Map(), this.chunkLoading = /* @__PURE__ */ new Map(), this.manifest = null, this.manifestLoading = null, this.entryFileCache = /* @__PURE__ */ new Map(), this.tiyaoCache = /* @__PURE__ */ new Map(), this.tiyaoLoading = /* @__PURE__ */ new Map(), this.metaCache = null, this.metaLoading = null, this.promotions = null, this.promotionsLoading = null, this.promotionsLoadFailed = !1, this.promotionShards = /* @__PURE__ */ new Map(), this.versionPromise = null, this.versionInjected = !1, this.basePath = t.basePath ?? Ot, this.timeout = t.timeout ?? Ut, this.hubsPath = t.hubsPath ?? "_hubs.json", this.detailLayout = t.detailLayout ?? "auto", t.version !== void 0 && (this.version = t.version ?? null, this.versionInjected = !0);
2082
+ this.hubsLoading = null, this.chunkCache = /* @__PURE__ */ new Map(), this.chunkLoading = /* @__PURE__ */ new Map(), this.manifest = null, this.manifestLoading = null, this.entryFileCache = /* @__PURE__ */ new Map(), this.tiyaoCache = /* @__PURE__ */ new Map(), this.tiyaoLoading = /* @__PURE__ */ new Map(), this.metaCache = null, this.metaLoading = null, this.promotions = null, this.promotionsLoading = null, this.promotionsLoadFailed = !1, this.promotionShards = /* @__PURE__ */ new Map(), this.versionPromise = null, this.versionInjected = !1, this.basePath = t.basePath ?? Jt, this.timeout = t.timeout ?? Wt, this.hubsPath = t.hubsPath ?? "_hubs.json", this.detailLayout = t.detailLayout ?? "auto", t.version !== void 0 && (this.version = t.version ?? null, this.versionInjected = !0);
2072
2083
  }
2073
2084
  // ─── 内部工具 ───
2074
2085
  /**
@@ -2121,7 +2132,7 @@ class ee {
2121
2132
  }
2122
2133
  /** 取草稿 id 所在的一片 `promotions/<末2位>.json`(几 KB);取不到返回 null,调用方退回整档 */
2123
2134
  promotionShard(t) {
2124
- const e = t.slice(-Y);
2135
+ const e = t.slice(-X);
2125
2136
  let s = this.promotionShards.get(e);
2126
2137
  return s || (s = this.fetchJson(`${this.basePath}/promotions/${e}.json`).then((n) => {
2127
2138
  const o = F(n);
@@ -2134,7 +2145,7 @@ class ee {
2134
2145
  */
2135
2146
  async canonicalIdFor(t) {
2136
2147
  if (this.promotions && !this.promotionsLoadFailed) return this.promotions.get(t) ?? t;
2137
- if (t.length >= Y) {
2148
+ if (t.length >= X) {
2138
2149
  const e = await this.promotionShard(t);
2139
2150
  if (e) return e.get(t) ?? t;
2140
2151
  }
@@ -2284,32 +2295,32 @@ class ee {
2284
2295
  }
2285
2296
  /** 从 chunk 读取详情构造 IndexEntry。chunk miss 即返回 null(无 fallback)。 */
2286
2297
  async getEntry(t) {
2287
- var e, s, n, o;
2298
+ var e, s;
2288
2299
  try {
2289
- const r = await this.canonicalIdFor(t), c = r !== t ? t : void 0, a = await this.loadDetail(r);
2290
- if (!a) return null;
2291
- const l = bt(r), u = l === "entity" ? a.primary_name || a.title || a.name || r : a.title || a.name || r;
2300
+ const n = await this.canonicalIdFor(t), o = n !== t ? t : void 0, r = await this.loadDetail(n);
2301
+ if (!r) return null;
2302
+ const c = kt(n), a = L(r.additional_titles), l = c === "entity" ? r.primary_name || r.title || r.name || n : r.title || r.name || n;
2292
2303
  return {
2293
- id: r,
2294
- title: u,
2295
- type: l,
2304
+ id: n,
2305
+ title: l,
2306
+ type: c,
2296
2307
  isDraft: !0,
2297
- author: a.author,
2298
- dynasty: a.dynasty,
2299
- role: a.role,
2300
- additional_titles: (e = a.additional_titles) == null ? void 0 : e.map((h) => typeof h == "string" ? h : h == null ? void 0 : h.book_title).filter(Boolean),
2301
- attached_texts: (s = a.attached_texts) == null ? void 0 : s.map((h) => typeof h == "string" ? h : h == null ? void 0 : h.book_title).filter(Boolean),
2302
- edition: a.edition,
2303
- juan_count: a.juan_count,
2304
- has_text: a.has_text,
2305
- has_image: a.has_image,
2306
- has_collated: a.has_collated,
2307
- subtype: a.subtype,
2308
- primary_name: a.primary_name,
2309
- birth_year: ((n = a.dates) == null ? void 0 : n.birth) ?? void 0,
2310
- death_year: ((o = a.dates) == null ? void 0 : o.death) ?? void 0,
2311
- cbdb_id: a.cbdb_id,
2312
- ...c ? { redirected_from: c } : {}
2308
+ author: r.author,
2309
+ dynasty: r.dynasty,
2310
+ role: r.role,
2311
+ additional_titles: r.additional_titles ? a.aliases : void 0,
2312
+ attached_texts: a.attached.length ? a.attached : void 0,
2313
+ edition: r.edition,
2314
+ juan_count: r.juan_count,
2315
+ has_text: r.has_text,
2316
+ has_image: r.has_image,
2317
+ has_collated: r.has_collated,
2318
+ subtype: r.subtype,
2319
+ primary_name: r.primary_name,
2320
+ birth_year: ((e = r.dates) == null ? void 0 : e.birth) ?? void 0,
2321
+ death_year: ((s = r.dates) == null ? void 0 : s.death) ?? void 0,
2322
+ cbdb_id: r.cbdb_id,
2323
+ ...o ? { redirected_from: o } : {}
2313
2324
  };
2314
2325
  } catch {
2315
2326
  return null;
@@ -2344,7 +2355,7 @@ class ee {
2344
2355
  r && n.push({
2345
2356
  resource_id: o.id,
2346
2357
  short_name: o.short_name,
2347
- data: lt(r)
2358
+ data: ut(r)
2348
2359
  });
2349
2360
  } catch {
2350
2361
  }
@@ -2369,7 +2380,7 @@ class ee {
2369
2380
  }
2370
2381
  }
2371
2382
  async getTextIndex(t, e) {
2372
- if (!x(t) || !X(e)) return null;
2383
+ if (!x(t) || !Z(e)) return null;
2373
2384
  try {
2374
2385
  const s = await this.fetchJson(`${this.basePath}/items/${t}/${e}/index.json`);
2375
2386
  return s && Array.isArray(s.chapters) ? s : null;
@@ -2378,9 +2389,9 @@ class ee {
2378
2389
  }
2379
2390
  }
2380
2391
  async getChapter(t, e, s, n) {
2381
- if (!x(t) || !X(e) || !x(s)) return null;
2382
- const o = `${this.basePath}/items/${t}/${e}/${s}`, r = await this.ensureVersion(), c = r ? `${o}.txt?v=${r}` : `${o}.txt`, a = fetch(c, { cache: "no-cache", signal: AbortSignal.timeout(this.timeout) }).then((d) => d.ok ? d.text() : null).catch(() => null), l = n != null && n.json ? this.fetchJson(`${o}.json`).catch(() => null) : Promise.resolve(null), [u, h] = await Promise.all([a, l]);
2383
- return u != null || h ? { md: u, json: h } : null;
2392
+ if (!x(t) || !Z(e) || !x(s)) return null;
2393
+ const o = `${this.basePath}/items/${t}/${e}/${s}`, r = await this.ensureVersion(), c = r ? `${o}.txt?v=${r}` : `${o}.txt`, a = fetch(c, { cache: "no-cache", signal: AbortSignal.timeout(this.timeout) }).then((d) => d.ok ? d.text() : null).catch(() => null), l = n != null && n.json ? this.fetchJson(`${o}.json`).catch(() => null) : Promise.resolve(null), [h, u] = await Promise.all([a, l]);
2394
+ return h != null || u ? { md: h, json: u } : null;
2384
2395
  }
2385
2396
  // ─── 版本传承 ───
2386
2397
  async getLineageGraph(t) {
@@ -2436,29 +2447,29 @@ class v extends Error {
2436
2447
  super(t), this.name = "BookIndexError";
2437
2448
  }
2438
2449
  }
2439
- class se extends v {
2450
+ class ie extends v {
2440
2451
  constructor(t) {
2441
2452
  super(t), this.name = "StorageError";
2442
2453
  }
2443
2454
  }
2444
- class ne extends v {
2455
+ class re extends v {
2445
2456
  constructor(t) {
2446
2457
  super(t), this.name = "IdGenerationError";
2447
2458
  }
2448
2459
  }
2449
- class oe extends v {
2460
+ class ae extends v {
2450
2461
  constructor(t) {
2451
2462
  super(t), this.name = "ConfigError";
2452
2463
  }
2453
2464
  }
2454
- class ie extends v {
2465
+ class ce extends v {
2455
2466
  constructor(t) {
2456
2467
  super(t), this.name = "MigrationError";
2457
2468
  }
2458
2469
  }
2459
- class re {
2470
+ class le {
2460
2471
  constructor(t, e, s = 1) {
2461
- this.storage = new ct(t, e), this.idGen = new ht(s);
2472
+ this.storage = new ht(t, e), this.idGen = new dt(s);
2462
2473
  }
2463
2474
  /** Generate a new unique ID (returns raw bigint). */
2464
2475
  generateId(t = "book", e = "draft") {
@@ -2544,7 +2555,7 @@ class re {
2544
2555
  return this.storage;
2545
2556
  }
2546
2557
  }
2547
- const Nt = {
2558
+ const Ht = {
2548
2559
  wikisource: "wikisource",
2549
2560
  shidianguji: "shidianguji",
2550
2561
  archive: "archive",
@@ -2554,16 +2565,16 @@ const Nt = {
2554
2565
  "db.sido": "sido",
2555
2566
  "guji.artx": "guji-artx",
2556
2567
  "digital.library": "digital-library"
2557
- }, Q = /* @__PURE__ */ new Set(["text", "image", "physical", "catalog", "annotated"]), Jt = /* @__PURE__ */ new Set(["catalog", "search"]), Wt = /* @__PURE__ */ new Set(["com", "org", "net", "cn", "edu", "gov", "io", "jp", "tw", "hk"]);
2558
- function ae(i) {
2568
+ }, tt = /* @__PURE__ */ new Set(["text", "image", "physical", "catalog", "annotated"]), Gt = /* @__PURE__ */ new Set(["catalog", "search"]), qt = /* @__PURE__ */ new Set(["com", "org", "net", "cn", "edu", "gov", "io", "jp", "tw", "hk"]);
2569
+ function he(i) {
2559
2570
  if (!i) return "";
2560
2571
  try {
2561
2572
  const e = new URL(i).hostname;
2562
- for (const [n, o] of Object.entries(Nt))
2573
+ for (const [n, o] of Object.entries(Ht))
2563
2574
  if (e.includes(n)) return o;
2564
2575
  const s = e.split(".");
2565
2576
  if (s.length >= 2) {
2566
- const n = s.filter((o) => !Wt.has(o) && o.length > 2);
2577
+ const n = s.filter((o) => !qt.has(o) && o.length > 2);
2567
2578
  return n.length > 0 ? n[n.length - 1] : s[s.length - 2];
2568
2579
  }
2569
2580
  return e;
@@ -2571,7 +2582,7 @@ function ae(i) {
2571
2582
  return "";
2572
2583
  }
2573
2584
  }
2574
- function ce(i) {
2585
+ function ue(i) {
2575
2586
  const t = [];
2576
2587
  i.name || t.push("name is required");
2577
2588
  let e = !1;
@@ -2580,12 +2591,12 @@ function ce(i) {
2580
2591
  t.push("types must be a non-empty array when present");
2581
2592
  else {
2582
2593
  for (const s of i.types)
2583
- Q.has(s) || t.push(`invalid types atom '${s}', must be one of ${[...Q].join(", ")}`);
2594
+ tt.has(s) || t.push(`invalid types atom '${s}', must be one of ${[...tt].join(", ")}`);
2584
2595
  e = i.types.length === 1 && i.types[0] === "physical";
2585
2596
  }
2586
2597
  else
2587
2598
  t.push("types is required");
2588
- return i.root_type && !Jt.has(i.root_type) && t.push(`invalid root_type '${i.root_type}'`), !e && !i.url && t.push("url is required for non-physical resources"), t;
2599
+ return i.root_type && !Gt.has(i.root_type) && t.push(`invalid root_type '${i.root_type}'`), !e && !i.url && t.push("url is required for non-physical resources"), t;
2589
2600
  }
2590
2601
  const p = class p {
2591
2602
  constructor(t, e = "") {
@@ -2630,44 +2641,45 @@ const p = class p {
2630
2641
  }
2631
2642
  };
2632
2643
  p.PROTOCOL = "bid:\\\\", p.PREFIX = "bid:\\\\";
2633
- let Z = p;
2644
+ let et = p;
2634
2645
  export {
2635
- k as A,
2636
- Z as B,
2637
- oe as C,
2638
- P as D,
2639
- _ as E,
2640
- ce as F,
2641
- Kt as G,
2642
- ne as I,
2643
- Yt as L,
2644
- ie as M,
2645
- se as S,
2646
- jt as V,
2647
- Vt as a,
2648
- bt as b,
2646
+ ut as A,
2647
+ et as B,
2648
+ ae as C,
2649
+ k as D,
2650
+ P as E,
2651
+ _ as F,
2652
+ Xt as G,
2653
+ ue as H,
2654
+ re as I,
2655
+ Qt as L,
2656
+ ce as M,
2657
+ ie as S,
2658
+ Ft as V,
2659
+ Zt as a,
2660
+ kt as b,
2649
2661
  v as c,
2650
- re as d,
2651
- zt as e,
2652
- ct as f,
2653
- ee as g,
2654
- ht as h,
2662
+ le as d,
2663
+ Vt as e,
2664
+ ht as f,
2665
+ oe as g,
2666
+ dt as h,
2655
2667
  x as i,
2656
- rt as j,
2668
+ ct as j,
2657
2669
  A as k,
2658
- _t as l,
2659
- Zt as m,
2660
- Ct as n,
2661
- G as o,
2662
- te as p,
2670
+ It as l,
2671
+ se as m,
2672
+ Lt as n,
2673
+ z as o,
2674
+ ne as p,
2663
2675
  F as q,
2664
- vt as r,
2665
- qt as s,
2666
- Qt as t,
2667
- E as u,
2668
- Gt as v,
2669
- ae as w,
2670
- Xt as x,
2671
- X as y,
2672
- lt as z
2676
+ At as r,
2677
+ L as s,
2678
+ ee as t,
2679
+ Yt as u,
2680
+ E as v,
2681
+ Kt as w,
2682
+ he as x,
2683
+ te as y,
2684
+ Z as z
2673
2685
  };