@the_library/public 1.0.0 → 2.0.0
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.
- package/README.md +201 -28
- package/assets/branding/pond-enterprise-logo.svg +1 -1
- package/dist/Book-K86JRm42.d.ts +600 -0
- package/dist/bookSearchService-BmFHrvsv.d.ts +300 -0
- package/dist/branding/index.js +1 -66
- package/dist/branding/index.js.map +1 -1
- package/dist/chunk-3XUKOVEF.js +2 -0
- package/dist/chunk-3XUKOVEF.js.map +1 -0
- package/dist/chunk-46FQHZNM.js +2 -0
- package/dist/chunk-46FQHZNM.js.map +1 -0
- package/dist/chunk-7G3BMGV2.js +2 -0
- package/dist/chunk-7G3BMGV2.js.map +1 -0
- package/dist/chunk-D4DXGA2W.js +2 -0
- package/dist/chunk-D4DXGA2W.js.map +1 -0
- package/dist/chunk-EMA2QJTW.js +2 -0
- package/dist/chunk-EMA2QJTW.js.map +1 -0
- package/dist/chunk-FN52YV7L.js +2 -0
- package/dist/chunk-FN52YV7L.js.map +1 -0
- package/dist/chunk-GWQNULP4.js +2 -0
- package/dist/chunk-GWQNULP4.js.map +1 -0
- package/dist/chunk-OELHBR4F.js +2 -0
- package/dist/chunk-OELHBR4F.js.map +1 -0
- package/dist/chunk-PV3X54EU.js +2 -0
- package/dist/chunk-PV3X54EU.js.map +1 -0
- package/dist/chunk-SD3INWZF.js +2 -0
- package/dist/chunk-SD3INWZF.js.map +1 -0
- package/dist/downloader/dl2-sw.js +1 -198
- package/dist/downloader/dl2-sw.js.map +1 -1
- package/dist/downloader/file-worker-v2.js +1 -257
- package/dist/downloader/file-worker-v2.js.map +1 -1
- package/dist/downloader/index.d.ts +18 -2
- package/dist/downloader/index.js +1 -537
- package/dist/downloader/index.js.map +1 -1
- package/dist/downloader/mu-worker-v2.js +1 -196
- package/dist/downloader/mu-worker-v2.js.map +1 -1
- package/dist/downloader/react.d.ts +1 -1
- package/dist/downloader/react.js +1 -31
- package/dist/downloader/react.js.map +1 -1
- package/dist/downloader/solid.d.ts +1 -1
- package/dist/downloader/solid.js +1 -18
- package/dist/downloader/solid.js.map +1 -1
- package/dist/downloader/sw.js +1 -118
- package/dist/downloader/sw.js.map +1 -1
- package/dist/downloader/vue.d.ts +1 -1
- package/dist/downloader/vue.js +1 -18
- package/dist/downloader/vue.js.map +1 -1
- package/dist/enriched-index-T0sDG7JR.d.ts +209 -0
- package/dist/global/public.global.js +68 -0
- package/dist/global/public.manifest.json +484 -0
- package/dist/level-state-DXqglpAX.d.ts +27 -0
- package/dist/models/astro.d.ts +4 -3
- package/dist/models/astro.js +1 -43
- package/dist/models/astro.js.map +1 -1
- package/dist/models/index.d.ts +449 -22
- package/dist/models/index.js +1 -339
- package/dist/models/index.js.map +1 -1
- package/dist/models/models.d.ts +196 -441
- package/dist/models/models.js +1 -45
- package/dist/models/patch-worker.js +1 -542
- package/dist/models/patch-worker.js.map +1 -1
- package/dist/models/react.d.ts +6 -5
- package/dist/models/react.js +1 -72
- package/dist/models/react.js.map +1 -1
- package/dist/models/solid.d.ts +16 -6
- package/dist/models/solid.js +1 -94
- package/dist/models/solid.js.map +1 -1
- package/dist/models/vue.d.ts +90 -7
- package/dist/models/vue.js +1 -97
- package/dist/models/vue.js.map +1 -1
- package/dist/orm-MJTHCG9E.d.ts +1003 -0
- package/dist/{session-vqOnyxga.d.ts → session-JudUKAV7.d.ts} +76 -74
- package/dist/{state-BTsp-E4v.d.ts → state-CkYavOSt.d.ts} +16 -0
- package/dist/{types-Dn0EFMO_.d.ts → types-B-IX3HBn.d.ts} +94 -21
- package/dist/{types-Xb8Ta9tZ.d.ts → types-Blyx2A7F.d.ts} +10 -36
- package/dist/web3/auth.d.ts +89 -0
- package/dist/web3/auth.js +13 -0
- package/dist/web3/auth.js.map +1 -0
- package/dist/web3/index.d.ts +1913 -126
- package/dist/web3/index.js +1 -1019
- package/dist/web3/index.js.map +1 -1
- package/dist/web3/network.d.ts +6 -0
- package/dist/web3/network.js +2 -0
- package/dist/web3/network.js.map +1 -0
- package/dist/web3/registry.d.ts +34 -9
- package/dist/web3/registry.js +1 -22
- package/dist/web3/vue.d.ts +31 -14
- package/dist/web3/vue.js +1 -390
- package/dist/web3/vue.js.map +1 -1
- package/package.json +23 -2
- package/dist/chunk-2HFOWE5R.js +0 -296
- package/dist/chunk-2HFOWE5R.js.map +0 -1
- package/dist/chunk-3L6LH2XK.js +0 -465
- package/dist/chunk-3L6LH2XK.js.map +0 -1
- package/dist/chunk-4CWVFPBN.js +0 -28
- package/dist/chunk-4CWVFPBN.js.map +0 -1
- package/dist/chunk-AGHPATVL.js +0 -65
- package/dist/chunk-AGHPATVL.js.map +0 -1
- package/dist/chunk-JDUYLUDJ.js +0 -4835
- package/dist/chunk-JDUYLUDJ.js.map +0 -1
- package/dist/chunk-OEZK7IX7.js +0 -77
- package/dist/chunk-OEZK7IX7.js.map +0 -1
- package/dist/chunk-PUYDAUCI.js +0 -2873
- package/dist/chunk-PUYDAUCI.js.map +0 -1
- package/dist/chunk-WHWMTS7D.js +0 -99
- package/dist/chunk-WHWMTS7D.js.map +0 -1
- package/dist/chunk-Y7RS6RTM.js +0 -342
- package/dist/chunk-Y7RS6RTM.js.map +0 -1
- package/dist/chunk-ZEZGI2TP.js +0 -197
- package/dist/chunk-ZEZGI2TP.js.map +0 -1
- package/dist/core-dao-core-logo-VDT2I5IW.svg +0 -33
- package/dist/level-state-J3pj64Tr.d.ts +0 -15
- package/dist/models/models_v2.global.js +0 -1
- package/dist/orm-BvkX0aBT.d.ts +0 -507
package/dist/chunk-ZEZGI2TP.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
// src/models/promises.ts
|
|
2
|
-
var delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
-
var proResolver = () => {
|
|
4
|
-
let resolver;
|
|
5
|
-
let rejecter;
|
|
6
|
-
let resolved = false;
|
|
7
|
-
let started = false;
|
|
8
|
-
const pro = new Promise((_resolve, _reject) => {
|
|
9
|
-
resolver = _resolve;
|
|
10
|
-
rejecter = _reject;
|
|
11
|
-
});
|
|
12
|
-
const resolve = (value) => {
|
|
13
|
-
if (!resolved) {
|
|
14
|
-
resolver(value);
|
|
15
|
-
resolved = true;
|
|
16
|
-
} else {
|
|
17
|
-
console.trace("resolve called twice");
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const reject = (value) => {
|
|
21
|
-
if (!resolved) {
|
|
22
|
-
resolved = true;
|
|
23
|
-
rejecter(value);
|
|
24
|
-
} else {
|
|
25
|
-
console.error("reject called twice");
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const start = () => started = true;
|
|
29
|
-
const isStarted = () => started;
|
|
30
|
-
return { pro, resolve, reject, start, isStarted };
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// src/models/indexdb/common.ts
|
|
34
|
-
var version = 4;
|
|
35
|
-
var dbName = `the_world_library`;
|
|
36
|
-
var dbDeferred = proResolver();
|
|
37
|
-
var patchStoreName = `patches`;
|
|
38
|
-
var jsonStoreName = `catalog_json`;
|
|
39
|
-
var keyValStoreName = "key_value";
|
|
40
|
-
var pdfDataStoreName = "pdf_data";
|
|
41
|
-
var deviceStateStoreName = "deviceState";
|
|
42
|
-
var localRecordsStoreName = "localRecords";
|
|
43
|
-
var instanceRemapsStoreName = "instanceRemaps";
|
|
44
|
-
var Db = () => {
|
|
45
|
-
if (dbDeferred.isStarted()) {
|
|
46
|
-
return dbDeferred.pro;
|
|
47
|
-
}
|
|
48
|
-
dbDeferred.start();
|
|
49
|
-
const request = indexedDB.open(dbName, version);
|
|
50
|
-
request.onupgradeneeded = function() {
|
|
51
|
-
const db = request.result;
|
|
52
|
-
if (!db.objectStoreNames.contains(jsonStoreName))
|
|
53
|
-
db.createObjectStore(jsonStoreName, { keyPath: "id" });
|
|
54
|
-
if (!db.objectStoreNames.contains(keyValStoreName))
|
|
55
|
-
db.createObjectStore(keyValStoreName, { keyPath: "key" });
|
|
56
|
-
if (!db.objectStoreNames.contains(pdfDataStoreName))
|
|
57
|
-
db.createObjectStore(pdfDataStoreName, { keyPath: "fileId" });
|
|
58
|
-
if (!db.objectStoreNames.contains(patchStoreName)) {
|
|
59
|
-
const patchStore = db.createObjectStore(patchStoreName, { keyPath: ["username", "pk"] });
|
|
60
|
-
patchStore.createIndex("username", "username", { unique: false });
|
|
61
|
-
}
|
|
62
|
-
if (!db.objectStoreNames.contains(deviceStateStoreName)) {
|
|
63
|
-
db.createObjectStore(deviceStateStoreName);
|
|
64
|
-
}
|
|
65
|
-
if (!db.objectStoreNames.contains(localRecordsStoreName)) {
|
|
66
|
-
const localStore = db.createObjectStore(localRecordsStoreName, { keyPath: ["creatorUsername", "wireId"] });
|
|
67
|
-
localStore.createIndex("byCreator", "creatorUsername", { unique: false });
|
|
68
|
-
}
|
|
69
|
-
if (!db.objectStoreNames.contains(instanceRemapsStoreName)) {
|
|
70
|
-
db.createObjectStore(instanceRemapsStoreName, { keyPath: ["creatorUsername", "objectId", "langId", "originalIndex"] });
|
|
71
|
-
}
|
|
72
|
-
console.log("[IDB] models_v2 schema upgraded to version", db.version);
|
|
73
|
-
};
|
|
74
|
-
request.onerror = function(event) {
|
|
75
|
-
dbDeferred.reject(event);
|
|
76
|
-
};
|
|
77
|
-
request.onsuccess = function(event) {
|
|
78
|
-
dbDeferred.resolve(event.target.result);
|
|
79
|
-
};
|
|
80
|
-
return dbDeferred.pro;
|
|
81
|
-
};
|
|
82
|
-
var ClearDbData = async () => {
|
|
83
|
-
const db = await Db();
|
|
84
|
-
const storeNames = Array.from(db.objectStoreNames);
|
|
85
|
-
if (storeNames.length === 0) return;
|
|
86
|
-
const tx = db.transaction(storeNames, "readwrite");
|
|
87
|
-
storeNames.forEach((store) => tx.objectStore(store).clear());
|
|
88
|
-
return new Promise((resolve) => tx.oncomplete = resolve);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/models/indexdb/patch_storage.ts
|
|
92
|
-
var signature = (op) => JSON.stringify(op, Object.keys(op).sort());
|
|
93
|
-
var bulkAddPatches = (username, collection) => {
|
|
94
|
-
const deferred = proResolver();
|
|
95
|
-
Db().then((db) => {
|
|
96
|
-
if (collection.length === 0) return deferred.resolve(true);
|
|
97
|
-
getAllPatchesByUsername(username).then((existingPatches) => {
|
|
98
|
-
let nextPk = (existingPatches.length ? existingPatches[existingPatches.length - 1].pk : 0) + 1;
|
|
99
|
-
const tx = db.transaction(patchStoreName, "readwrite");
|
|
100
|
-
const store = tx.objectStore(patchStoreName);
|
|
101
|
-
const existing = new Set(existingPatches.map(({ pk, username: username2, ...op }) => signature(op)));
|
|
102
|
-
collection.forEach((op) => {
|
|
103
|
-
if (!existing.has(signature(op))) {
|
|
104
|
-
const add = store.add(Object.assign({}, { username, pk: nextPk }, op));
|
|
105
|
-
nextPk++;
|
|
106
|
-
add.onerror = function(event) {
|
|
107
|
-
console.error(`error inserting [${patchStoreName}]`, op, event.target);
|
|
108
|
-
deferred.reject(new Error(`error inserting patch`));
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
tx.oncomplete = function() {
|
|
113
|
-
deferred.resolve(true);
|
|
114
|
-
};
|
|
115
|
-
tx.onerror = function(event) {
|
|
116
|
-
console.error(`tx.onerror inserting [${patchStoreName}]: `, event);
|
|
117
|
-
deferred.reject(event.target);
|
|
118
|
-
};
|
|
119
|
-
}).catch((err) => {
|
|
120
|
-
console.error(err);
|
|
121
|
-
deferred.reject(err);
|
|
122
|
-
});
|
|
123
|
-
}).catch((e) => {
|
|
124
|
-
console.error(`[indexdb error:] bulkAddPatches ${e.message}`);
|
|
125
|
-
deferred.reject(e);
|
|
126
|
-
});
|
|
127
|
-
return deferred.pro;
|
|
128
|
-
};
|
|
129
|
-
var getNbPatches = (username) => {
|
|
130
|
-
const deferred = proResolver();
|
|
131
|
-
Db().then(async (db) => {
|
|
132
|
-
const tx = db.transaction(patchStoreName, "readonly");
|
|
133
|
-
tx.objectStore(patchStoreName).index("username").count(IDBKeyRange.only(username)).onsuccess = (event) => {
|
|
134
|
-
deferred.resolve(event.target.result || 0);
|
|
135
|
-
};
|
|
136
|
-
tx.onerror = function(event) {
|
|
137
|
-
console.log("worker: error counting patches", event.target);
|
|
138
|
-
deferred.reject(event.target);
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
return deferred.pro;
|
|
142
|
-
};
|
|
143
|
-
var getAllPatchesSince = (username, pk) => {
|
|
144
|
-
const deferred = proResolver();
|
|
145
|
-
Db().then(async (db) => {
|
|
146
|
-
const tx = db.transaction(patchStoreName, "readonly");
|
|
147
|
-
const store = tx.objectStore(patchStoreName);
|
|
148
|
-
store.index("username").getAll(IDBKeyRange.only(username)).onsuccess = (event) => {
|
|
149
|
-
const all = event.target.result || [];
|
|
150
|
-
const results = all.filter((row) => row.pk >= pk);
|
|
151
|
-
results.sort((a, b) => a.pk - b.pk);
|
|
152
|
-
deferred.resolve(results);
|
|
153
|
-
};
|
|
154
|
-
tx.onerror = function(event) {
|
|
155
|
-
console.error("worker: error loading patches since", pk, event.target);
|
|
156
|
-
deferred.reject(event.target);
|
|
157
|
-
};
|
|
158
|
-
}).catch(deferred.reject);
|
|
159
|
-
return deferred.pro;
|
|
160
|
-
};
|
|
161
|
-
var getAllPatchesByUsername = (username) => {
|
|
162
|
-
const deferred = proResolver();
|
|
163
|
-
Db().then(async (db) => {
|
|
164
|
-
const tx = db.transaction(patchStoreName, "readonly");
|
|
165
|
-
tx.objectStore(patchStoreName).index("username").getAll(IDBKeyRange.only(username)).onsuccess = (event) => {
|
|
166
|
-
const results = event.target.result || [];
|
|
167
|
-
results.sort((a, b) => a.pk - b.pk);
|
|
168
|
-
deferred.resolve(results);
|
|
169
|
-
};
|
|
170
|
-
tx.onerror = function(event) {
|
|
171
|
-
console.error("worker: error loading all patches", event.target);
|
|
172
|
-
deferred.reject(event.target);
|
|
173
|
-
};
|
|
174
|
-
}).catch(deferred.reject);
|
|
175
|
-
return deferred.pro;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export {
|
|
179
|
-
delay,
|
|
180
|
-
proResolver,
|
|
181
|
-
version,
|
|
182
|
-
dbName,
|
|
183
|
-
patchStoreName,
|
|
184
|
-
jsonStoreName,
|
|
185
|
-
keyValStoreName,
|
|
186
|
-
pdfDataStoreName,
|
|
187
|
-
deviceStateStoreName,
|
|
188
|
-
localRecordsStoreName,
|
|
189
|
-
instanceRemapsStoreName,
|
|
190
|
-
Db,
|
|
191
|
-
ClearDbData,
|
|
192
|
-
bulkAddPatches,
|
|
193
|
-
getNbPatches,
|
|
194
|
-
getAllPatchesSince,
|
|
195
|
-
getAllPatchesByUsername
|
|
196
|
-
};
|
|
197
|
-
//# sourceMappingURL=chunk-ZEZGI2TP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/models/promises.ts","../src/models/indexdb/common.ts","../src/models/indexdb/patch_storage.ts"],"mappings":";AAcO,IAAM,QAAQ,CAAC,OAAe,IAAI,QAAQ,aAAW,WAAW,SAAS,EAAE,CAAC;AAK5E,IAAM,cAAc,MAAyB;AAChD,MAAI;AACJ,MAAI;AACJ,MAAI,WAAW;AACf,MAAI,UAAU;AACd,QAAM,MAAM,IAAI,QAAW,CAAC,UAAU,YAAY;AAC9C,eAAW;AACX,eAAW;AAAA,EACf,CAAC;AACD,QAAM,UAAU,CAAC,UAAa;AAC1B,QAAI,CAAC,UAAU;AACX,eAAS,KAAK;AACd,iBAAW;AAAA,IACf,OAAO;AACH,cAAQ,MAAM,sBAAsB;AAAA,IACxC;AAAA,EACJ;AACA,QAAM,SAAS,CAAC,UAAe;AAC3B,QAAI,CAAC,UAAU;AACX,iBAAW;AACX,eAAS,KAAK;AAAA,IAClB,OAAO;AACH,cAAQ,MAAM,qBAAqB;AAAA,IACvC;AAAA,EACJ;AACA,QAAM,QAAQ,MAAM,UAAU;AAC9B,QAAM,YAAY,MAAM;AAExB,SAAO,EAAC,KAAK,SAAS,QAAQ,OAAO,UAAS;AAClD;;;ACjCO,IAAM,UAAU;AAChB,IAAM,SAAS;AAEtB,IAAI,aAAa,YAAyB;AACnC,IAAM,iBAAiB;AACvB,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AACxB,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAC7B,IAAM,wBAAwB;AAC9B,IAAM,0BAA0B;AAChC,IAAM,KAAK,MAA4B;AAC1C,MAAI,WAAW,UAAU,GAAG;AACxB,WAAO,WAAW;AAAA,EACtB;AACA,aAAW,MAAM;AAEjB,QAAM,UAAU,UAAU,KAAK,QAAQ,OAAO;AAC9C,UAAQ,kBAAkB,WAAY;AAClC,UAAM,KAAK,QAAQ;AACnB,QAAI,CAAC,GAAG,iBAAiB,SAAS,aAAa;AAC3C,SAAG,kBAAkB,eAAe,EAAE,SAAS,KAAK,CAAC;AACzD,QAAI,CAAC,GAAG,iBAAiB,SAAS,eAAe;AAC7C,SAAG,kBAAkB,iBAAiB,EAAE,SAAS,MAAM,CAAC;AAC5D,QAAI,CAAC,GAAG,iBAAiB,SAAS,gBAAgB;AAC9C,SAAG,kBAAkB,kBAAkB,EAAE,SAAS,SAAS,CAAC;AAChE,QAAI,CAAC,GAAG,iBAAiB,SAAS,cAAc,GAAG;AAC/C,YAAM,aAAa,GAAG,kBAAkB,gBAAgB,EAAE,SAAS,CAAC,YAAY,IAAI,EAAE,CAAC;AACvF,iBAAW,YAAY,YAAY,YAAY,EAAE,QAAQ,MAAM,CAAC;AAAA,IACpE;AACA,QAAI,CAAC,GAAG,iBAAiB,SAAS,oBAAoB,GAAG;AACrD,SAAG,kBAAkB,oBAAoB;AAAA,IAC7C;AACA,QAAI,CAAC,GAAG,iBAAiB,SAAS,qBAAqB,GAAG;AACtD,YAAM,aAAa,GAAG,kBAAkB,uBAAuB,EAAE,SAAS,CAAC,mBAAmB,QAAQ,EAAE,CAAC;AACzG,iBAAW,YAAY,aAAa,mBAAmB,EAAE,QAAQ,MAAM,CAAC;AAAA,IAC5E;AACA,QAAI,CAAC,GAAG,iBAAiB,SAAS,uBAAuB,GAAG;AACxD,SAAG,kBAAkB,yBAAyB,EAAE,SAAS,CAAC,mBAAmB,YAAY,UAAU,eAAe,EAAE,CAAC;AAAA,IACzH;AACA,YAAQ,IAAI,8CAA8C,GAAG,OAAO;AAAA,EACxE;AAEA,UAAQ,UAAU,SAAU,OAAO;AAC/B,eAAW,OAAO,KAAK;AAAA,EAC3B;AACA,UAAQ,YAAY,SAAU,OAAc;AAExC,eAAW,QAAQ,MAAM,OAAO,MAAM;AAAA,EAC1C;AACA,SAAO,WAAW;AACtB;AACO,IAAM,cAAc,YAAY;AACnC,QAAM,KAAK,MAAM,GAAG;AACpB,QAAM,aAAa,MAAM,KAAK,GAAG,gBAAgB;AACjD,MAAI,WAAW,WAAW,EAAG;AAC7B,QAAM,KAAK,GAAG,YAAY,YAAY,WAAW;AACjD,aAAW,QAAQ,WAAS,GAAG,YAAY,KAAK,EAAE,MAAM,CAAC;AACzD,SAAO,IAAI,QAAQ,aAAW,GAAG,aAAa,OAAO;AACzD;;;AChDA,IAAM,YAAY,CAAC,OAA0B,KAAK,UAAU,IAAI,OAAO,KAAK,EAAE,EAAE,KAAK,CAAC;AAE/E,IAAM,iBAAiB,CAAC,UAAkB,eAAmD;AAChG,QAAM,WAAW,YAAqB;AACtC,KAAG,EAAE,KAAK,QAAM;AACZ,QAAI,WAAW,WAAW,EAAG,QAAO,SAAS,QAAQ,IAAI;AAEzD,4BAAwB,QAAQ,EAAE,KAAK,qBAAmB;AAKtD,UAAI,UAAU,gBAAgB,SAAS,gBAAgB,gBAAgB,SAAS,CAAC,EAAE,KAAK,KAAK;AAC7F,YAAM,KAAK,GAAG,YAAY,gBAAgB,WAAW;AACrD,YAAM,QAAQ,GAAG,YAAY,cAAc;AAC3C,YAAM,WAAW,IAAI,IAAI,gBAAgB,IAAI,CAAC,EAAE,IAAI,UAAAA,WAAU,GAAG,GAAG,MAAM,UAAU,EAAe,CAAC,CAAC;AAErG,iBAAW,QAAQ,QAAM;AACrB,YAAI,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC,GAAG;AAC9B,gBAAM,MAAM,MAAM,IAAI,OAAO,OAAO,CAAC,GAAG,EAAE,UAAU,IAAI,OAAO,GAAG,EAAE,CAAC;AACrE;AACA,cAAI,UAAU,SAAU,OAAO;AAC3B,oBAAQ,MAAM,oBAAoB,cAAc,KAAK,IAAI,MAAM,MAAM;AACrE,qBAAS,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAAA,UACtD;AAAA,QACJ;AAAA,MACJ,CAAC;AAED,SAAG,aAAa,WAAY;AACxB,iBAAS,QAAQ,IAAI;AAAA,MACzB;AACA,SAAG,UAAU,SAAU,OAAO;AAC1B,gBAAQ,MAAM,yBAAyB,cAAc,OAAO,KAAK;AACjE,iBAAS,OAAO,MAAM,MAAM;AAAA,MAChC;AAAA,IACJ,CAAC,EAAE,MAAM,SAAO;AACZ,cAAQ,MAAM,GAAG;AACjB,eAAS,OAAO,GAAG;AAAA,IACvB,CAAC;AAAA,EACL,CAAC,EAAE,MAAM,OAAK;AACV,YAAQ,MAAM,mCAAmC,EAAE,OAAO,EAAE;AAC5D,aAAS,OAAO,CAAC;AAAA,EACrB,CAAC;AACD,SAAO,SAAS;AACpB;AAEO,IAAM,eAAe,CAAC,aAAsC;AAC/D,QAAM,WAAW,YAAoB;AACrC,KAAG,EAAE,KAAK,OAAO,OAAO;AACpB,UAAM,KAAK,GAAG,YAAY,gBAAgB,UAAU;AACpD,OAAG,YAAY,cAAc,EAAE,MAAM,UAAU,EAAE,MAAM,YAAY,KAAK,QAAQ,CAAC,EAAE,YAAY,CAAC,UAAU;AAEtG,eAAS,QAAQ,MAAM,OAAO,UAAU,CAAC;AAAA,IAC7C;AACA,OAAG,UAAU,SAAU,OAAO;AAC1B,cAAQ,IAAI,kCAAkC,MAAM,MAAM;AAC1D,eAAS,OAAO,MAAM,MAAM;AAAA,IAChC;AAAA,EACJ,CAAC;AACD,SAAO,SAAS;AACpB;AAEO,IAAM,qBAAqB,CAAC,UAAkB,OAA4C;AAC7F,QAAM,WAAW,YAAgC;AACjD,KAAG,EAAE,KAAK,OAAO,OAAO;AACpB,UAAM,KAAK,GAAG,YAAY,gBAAgB,UAAU;AACpD,UAAM,QAAQ,GAAG,YAAY,cAAc;AAE3C,UAAM,MAAM,UAAU,EAAE,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE,YAAY,CAAC,UAAU;AAE9E,YAAM,MAAM,MAAM,OAAO,UAAU,CAAC;AACpC,YAAM,UAAU,IAAI,OAAO,CAAC,QAAqB,IAAI,MAAM,EAAE;AAC7D,cAAQ,KAAK,CAAC,GAAgB,MAAmB,EAAE,KAAK,EAAE,EAAE;AAC5D,eAAS,QAAQ,OAAO;AAAA,IAC5B;AAEA,OAAG,UAAU,SAAU,OAAO;AAC1B,cAAQ,MAAM,uCAAuC,IAAI,MAAM,MAAM;AACrE,eAAS,OAAO,MAAM,MAAM;AAAA,IAChC;AAAA,EACJ,CAAC,EAAE,MAAM,SAAS,MAAM;AAExB,SAAO,SAAS;AACpB;AAEO,IAAM,0BAA0B,CAAC,aAAkD;AACtF,QAAM,WAAW,YAAgC;AACjD,KAAG,EAAE,KAAK,OAAO,OAAO;AACpB,UAAM,KAAK,GAAG,YAAY,gBAAgB,UAAU;AAEpD,OAAG,YAAY,cAAc,EAAE,MAAM,UAAU,EAAE,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE,YAAY,CAAC,UAAU;AAEvG,YAAM,UAAU,MAAM,OAAO,UAAU,CAAC;AACxC,cAAQ,KAAK,CAAC,GAAgB,MAAmB,EAAE,KAAK,EAAE,EAAE;AAC5D,eAAS,QAAQ,OAAO;AAAA,IAC5B;AACA,OAAG,UAAU,SAAU,OAAO;AAC1B,cAAQ,MAAM,qCAAqC,MAAM,MAAM;AAC/D,eAAS,OAAO,MAAM,MAAM;AAAA,IAChC;AAAA,EACJ,CAAC,EAAE,MAAM,SAAS,MAAM;AAExB,SAAO,SAAS;AACpB;","names":["username"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<!--
|
|
3
|
-
- /*
|
|
4
|
-
- * Copyright (c) 2026 DataPond D-Library Pty Ltd. ("The Sanctuary")
|
|
5
|
-
- * Non-Profit Public Library — The World Library
|
|
6
|
-
- *
|
|
7
|
-
- * Licensed under the D-Open Code Sovereign Licence v1.0
|
|
8
|
-
- * https://registry.world.bibliotech.com/licence
|
|
9
|
-
- *
|
|
10
|
-
- * Technical Guardian ("The Shield"): Pond Enterprise Pty Ltd. (ACN 694 747 987)
|
|
11
|
-
- * All liability claims directed to Pond Enterprise Pty Ltd.
|
|
12
|
-
- * Modification automatically voids the certified liability protection.
|
|
13
|
-
- * Governing law: South Australia.
|
|
14
|
-
- */
|
|
15
|
-
-
|
|
16
|
-
-->
|
|
17
|
-
|
|
18
|
-
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
19
|
-
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
20
|
-
viewBox="0 0 321.3 368.1" style="enable-background:new 0 0 321.3 368.1;" xml:space="preserve">
|
|
21
|
-
<style type="text/css">
|
|
22
|
-
.st0{fill-rule:evenodd;clip-rule:evenodd;fill:#FF9211;}
|
|
23
|
-
.st1{fill:#FF9211;}
|
|
24
|
-
</style>
|
|
25
|
-
<path class="st0" d="M160.6,38.2L34.4,111.1V257l126.2,72.9L286.8,257V111.1L160.6,38.2z M165.9,1.4c-3.3-1.9-7.3-1.9-10.6,0
|
|
26
|
-
L5.3,88.1C2,90,0,93.5,0,97.3v173.4c0,3.8,2,7.3,5.3,9.2l150,86.7c3.3,1.9,7.3,1.9,10.6,0l150-86.7c3.3-1.9,5.3-5.4,5.3-9.2V97.3
|
|
27
|
-
c0-3.8-2-7.3-5.3-9.2L165.9,1.4z"/>
|
|
28
|
-
<path class="st1" d="M160.6,91l-80.5,46.5v93l80,46.2c0.3,0.2,0.5,0.5,0.5,0.9v15.9c0,0.8-0.9,1.3-1.6,0.9L68.2,242
|
|
29
|
-
c-2.5-1.4-4-4-4-6.9V132.9c0-2.8,1.5-5.5,4-6.9l88.4-51.1c2.5-1.4,5.5-1.4,7.9,0l91.2,52.5c0.7,0.4,0.7,1.4,0,1.8
|
|
30
|
-
c-5.4,3.2-8.1,4.6-14.2,8c-0.3,0.2-0.7,0.2-1,0L160.6,91z"/>
|
|
31
|
-
<path class="st1" d="M173.9,186c0-0.4,0.2-0.8,0.6-0.9l80-42.6c0.7-0.4,1.6,0.1,1.6,0.9v103.7c0,0.4-0.2,0.7-0.5,0.9l-80,46.5
|
|
32
|
-
c-0.7,0.4-1.6-0.1-1.6-0.9V186z"/>
|
|
33
|
-
</svg>
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface LevelState {
|
|
2
|
-
/** Integer level, 1-based (Math.floor(raw) + 1). */
|
|
3
|
-
level: number;
|
|
4
|
-
/** Progress toward the next level, 0–100. */
|
|
5
|
-
progress: number;
|
|
6
|
-
}
|
|
7
|
-
/** Returns the current level state for a username. Never throws — defaults to level 1. */
|
|
8
|
-
declare const getLevel: (username: string) => LevelState;
|
|
9
|
-
/**
|
|
10
|
-
* Subscribe to level updates. The listener receives the username whose level
|
|
11
|
-
* changed. Call the returned function to unsubscribe.
|
|
12
|
-
*/
|
|
13
|
-
declare const subscribeLevel: (listener: (username: string) => void) => (() => void);
|
|
14
|
-
|
|
15
|
-
export { type LevelState as L, getLevel as g, subscribeLevel as s };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var Web3ModelsV2=(()=>{var ln=Object.create;var Me=Object.defineProperty;var dn=Object.getOwnPropertyDescriptor;var un=Object.getOwnPropertyNames;var pn=Object.getPrototypeOf,mn=Object.prototype.hasOwnProperty;var gn=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),dt=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})},rr=(r,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of un(e))!mn.call(r,n)&&n!==t&&Me(r,n,{get:()=>e[n],enumerable:!(a=dn(e,n))||a.enumerable});return r};var hn=(r,e,t)=>(t=r!=null?ln(pn(r)):{},rr(e||!r||!r.__esModule?Me(t,"default",{value:r,enumerable:!0}):t,r)),yn=r=>rr(Me({},"__esModule",{value:!0}),r);var Gr=gn((Es,qr)=>{"use strict";qr.exports=window.Vue});var va={};dt(va,{ActionTypes:()=>ir,BOOK_PROP_IDS:()=>Ur,Book:()=>m,BookInstance:()=>Fe,CURRENT_VERSION:()=>qe,ClearDbData:()=>bn,DSafeCheck:()=>Wn,DateUtils:()=>C,Db:()=>R,DownloadState:()=>dr,DownloadsByType:()=>xn,FavoritesByTypes:()=>wn,LANG_AGNOSTIC:()=>F,LANG_ID_DECODE:()=>re,LANG_ID_ENCODE:()=>I,LruCache:()=>We,ModelTypes:()=>Se,NewBookWithId:()=>zt,NewPersonWithId:()=>Ct,NewTagWithId:()=>_t,PERSON_PROP_IDS:()=>kr,PatchAction:()=>h,PatchInstance:()=>p,PatchOperation:()=>d,Patches:()=>N,Person:()=>E,PopulateStatsStore:()=>z,Rating:()=>cr,Registry:()=>D,SchemaRegistry:()=>Xe,SidecarType:()=>ur,Stats:()=>Ee,TAG_PROP_IDS:()=>Or,Tag:()=>S,VisitsByType:()=>Pn,WorkerCommands:()=>sr,WorkerEvent:()=>lr,_resetForTest:()=>ta,addReactivitySystem:()=>Ce,addRecord:()=>B,applyRestoredPatches:()=>Wt,clear:()=>Ln,configureDb:()=>It,currentLayout:()=>O,dbName:()=>mr,dbReactivity:()=>ne,debouncePromise:()=>br,delay:()=>fn,deserializePatches:()=>In,deviceStateStoreName:()=>gt,dump:()=>ke,evmToPatch:()=>Ve,fileStore:()=>ra,getLevel:()=>qt,getPatchInstanceByAccount:()=>vn,getRecord:()=>f,getRecordKey:()=>ae,hasBookData:()=>Vr,hasFile:()=>Ht,hasRecord:()=>y,inceptionDate:()=>or,instanceRemapsStoreName:()=>ee,isEvmPatch:()=>U,jsonStoreName:()=>Le,keyValStoreName:()=>mt,loadBookData:()=>na,loadFile:()=>zr,localRecordsStoreName:()=>ht,models:()=>Ia,packPatch:()=>ut,patchStoreName:()=>k,patchToEvm:()=>Qe,pdfDataStoreName:()=>_,pinRecord:()=>Oe,proResolver:()=>x,relationColName:()=>At,removeRecord:()=>Tn,resolveLayout:()=>Re,scanTrash:()=>Kt,serializeBookExtended:()=>Mt,serializeBookProv:()=>$t,serializeBookSlim:()=>Ft,serializePatches:()=>Sn,serializePersonExtended:()=>Et,serializePersonProv:()=>jt,serializePersonSlim:()=>Dt,serializeTagExtended:()=>Ot,serializeTagProv:()=>Ut,serializeTagSlim:()=>kt,setReactivitySystem:()=>An,storeBookData:()=>aa,storeFile:()=>Qr,subscribeLevel:()=>Gt,trashStore:()=>we,unpackPatch:()=>pt,unpinRecord:()=>St,version:()=>pr,versionsFile:()=>De,vue:()=>Sa});var Qt={};dt(Qt,{BOOK_PROP_IDS:()=>Ur,Book:()=>m,BookInstance:()=>Fe,ModelTypes:()=>Se,NewBookWithId:()=>zt,NewPersonWithId:()=>Ct,NewTagWithId:()=>_t,PERSON_PROP_IDS:()=>kr,Person:()=>E,TAG_PROP_IDS:()=>Or,Tag:()=>S,serializeBookExtended:()=>Mt,serializeBookProv:()=>$t,serializeBookSlim:()=>Ft,serializePersonExtended:()=>Et,serializePersonProv:()=>jt,serializePersonSlim:()=>Dt,serializeTagExtended:()=>Ot,serializeTagProv:()=>Ut,serializeTagSlim:()=>kt});var d=(r=>(r[r.EditPropertyString=1]="EditPropertyString",r[r.EditPropertyNumber=2]="EditPropertyNumber",r[r.EditInstanceFieldString=3]="EditInstanceFieldString",r[r.EditInstanceFieldNumber=4]="EditInstanceFieldNumber",r[r.EditRelation=5]="EditRelation",r[r.SetAlias=6]="SetAlias",r[r.CreateRecord=7]="CreateRecord",r[r.AddInstance=8]="AddInstance",r))(d||{}),h=(r=>(r[r.Remove=0]="Remove",r[r.Add=1]="Add",r))(h||{}),I={eng:1,fra:2,spa:3,por:4,deu:5,zho:6,ara:7,rus:8,jpn:9,kor:10,hin:11,ita:12,nld:13,pol:14,swe:15,tur:16,vie:17,ind:18,tha:19,fas:20,heb:21,ukr:22,amh:23,gez:24,tir:25,orm:26,cat:27},re=Object.fromEntries(Object.entries(I).map(([r,e])=>[e,r]));function Re(r,e){let t={hash:"",enums:{},props:{},instanceFields:{}};for(let a=1;a<=r;a++){let n=e.versions[a];if(n){Object.assign(t.enums,n.enums),Object.assign(t.props,n.props);for(let[o,i]of Object.entries(n.instanceFields))t.instanceFields[Number(o)]=[...i];t.hash=n.hash}}return t}function $e(r,e){return r.props[e]?.bits??32}function ze(r,e){let t=r.props[e]?.type;return t===void 0||t==="number"}function v(r,e,t){if(!Number.isInteger(r))throw new Error(`[db_schema_v2] ${t} = ${r} is not an integer`);if(e===32){if(r<0||r>=2**32)throw new Error(`[db_schema_v2] ${t} = ${r} exceeds its ${e}-bit range`);return BigInt(r>>>0)}else{if(r<0||r>=2**e)throw new Error(`[db_schema_v2] ${t} = ${r} exceeds its ${e}-bit range (0..${2**e-1})`);return BigInt(r)}}function nr(r,e,t){if(!(Number.isInteger(r)&&(t?r>=-(2**(e-1))&&r<2**(e-1):r>=0&&r<2**e)))throw new Error(`[db_schema_v2] value = ${r} does not fit in ${e} ${t?"signed":"unsigned"} bits`);return BigInt(r)&(1n<<BigInt(e))-1n}function ut(r,e){let t=BigInt(r.operation);if(r.operation===6){let o=r;return t|v(o.objectType,7,"objectType")<<4n|v(o.fromUid,32,"fromUid")<<11n|v(o.toUid,32,"toUid")<<43n}if(r.operation===7){let o=r;if(o.objectId>>>0<2147483648)throw new Error(`[db_schema_v2] CreateRecord objectId must have high bit set: ${o.objectId}`);return t|v(o.objectType,7,"objectType")<<4n|v(o.objectId,32,"objectId")<<11n|0n<<43n}let a=r,n=t|v(a.objectType,7,"objectType")<<4n|v(a.objectId,32,"objectId")<<11n|v(a.langId,8,"langId")<<43n;switch(r.operation){case 2:{let o=r,i=$e(e,o.propertyId);return n|v(o.propertyId,8,"propertyId")<<51n|nr(o.value,i,ze(e,o.propertyId))<<59n}case 1:return n|v(r.propertyId,8,"propertyId")<<51n;case 4:{let o=r,i=$e(e,o.propertyId);return n|v(o.instanceIndex,8,"instanceIndex")<<51n|v(o.propertyId,8,"propertyId")<<59n|nr(o.value,i,ze(e,o.propertyId))<<67n}case 3:{let o=r;return n|v(o.instanceIndex,8,"instanceIndex")<<51n|v(o.propertyId,8,"propertyId")<<59n}case 5:{let o=r;return n|v(o.relationId,8,"relationId")<<51n|v(o.action,1,"action")<<59n|v(o.targetId,32,"targetId")<<60n}case 8:return n|v(r.instanceIndex,8,"instanceIndex")<<51n;default:throw new Error(`Unknown patch operation: ${r.operation}`)}}function pt(r,e){let t=Number(r&15n);if(t===6)return{operation:6,objectType:Number(r>>4n&127n),fromUid:Number(r>>11n&0xFFFFFFFFn),toUid:Number(r>>43n&0xFFFFFFFFn)};if(t===7){let s=Number(r>>11n&0xFFFFFFFFn);if(s>>>0<2147483648)throw new Error(`[db_schema_v2] CreateRecord objectId must have high bit set: ${s}`);return{operation:7,objectType:Number(r>>4n&127n),objectId:s,langId:0}}let a=Number(r>>4n&127n),n=Number(r>>11n&0xFFFFFFFFn),o=Number(r>>43n&255n),i={operation:t,objectType:a,objectId:n,langId:o};switch(t){case 2:{let s=Number(r>>51n&255n),c=$e(e,s),l=(1n<<BigInt(c))-1n,u=r>>59n&l,g=ze(e,s)?Number(BigInt.asIntN(c,u)):Number(u);return{...i,propertyId:s,value:g}}case 1:{let s=Number(r>>51n&255n);return{...i,propertyId:s,value:""}}case 4:{let s=Number(r>>51n&255n),c=Number(r>>59n&255n),l=$e(e,c),u=(1n<<BigInt(l))-1n,g=r>>67n&u,A=ze(e,c)?Number(BigInt.asIntN(l,g)):Number(g);return{...i,instanceIndex:s,propertyId:c,value:A}}case 3:{let s=Number(r>>51n&255n),c=Number(r>>59n&255n);return{...i,instanceIndex:s,propertyId:c,value:""}}case 5:{let s=Number(r>>51n&255n),c=Number(r>>59n&1n),l=Number(r>>60n&0xFFFFFFFFn);return{...i,relationId:s,action:c,targetId:l}}case 8:{let s=Number(r>>51n&255n);return{...i,instanceIndex:s}}default:throw new Error(`Unknown packed operation: ${t}`)}}function Qe(r,e,t){let a=[],n=[],o=[];for(let i=0;i<r.length;i++){let s=r[i];a.push(ut(s,e)),(s.operation===1||s.operation===3)&&(n.push(i),o.push(s.value))}return{version:t,patches:a,textIndex:n,textData:o}}function Ve(r,e){let t=Re(r.version,e),a=new Map;for(let n=0;n<r.textIndex.length;n++)a.set(r.textIndex[n],r.textData[n]);return r.patches.map((n,o)=>{let i=pt(n,t);return(i.operation===1||i.operation===3)&&(i.value=a.get(o)??""),i})}var F="",U=r=>r.operation!==void 0;function ar(r,e){var t;return t=(e.getFullYear()-r.getFullYear())*12,t-=r.getMonth(),t+=e.getMonth(),t<=0?0:t}var ie=new Date(2025,4,1),or=Math.floor(new Date(2025,11,1,0,0,0).getTime()/1e3),C={now:()=>Math.floor(Date.now()/1e3)-or,serialize:r=>{let e=new DataView(new ArrayBuffer(4));return e.setUint32(0,r),e.buffer},toNumber:r=>Math.floor(r.getTime()/1e3),fromNumber:r=>new Date(r*1e3),findNowBucket:()=>{let r=new Date;if(r.getTime()<ie.getTime())throw new Error(`now ${r} is before zeroDate ${ie}`);return ar(ie,r)},findDateBucket:r=>{if(r.getTime()<ie.getTime())throw new Error(`now ${r} is before zeroDate ${ie}`);return ar(ie,r)}};var ir=(s=>(s[s.Visit=0]="Visit",s[s.VisitPart=1]="VisitPart",s[s.Download=2]="Download",s[s.Rate=3]="Rate",s[s.RatePart=4]="RatePart",s[s.Share=5]="Share",s[s.SharePart=6]="SharePart",s))(ir||{}),sr=(n=>(n.Init="init",n.SavePatches="savePatches",n.GetRecord="getRecord",n.LoadLanguage="loadLanguage",n))(sr||{}),cr=(o=>(o[o.None=0]="None",o[o.New=1]="New",o[o.Keep=2]="Keep",o[o.Trash=3]="Trash",o[o.Shared=4]="Shared",o))(cr||{}),lr=(i=>(i.WorkerReady="workerready",i.WorkerLoadingError="workerLoadingError",i.DownloadStarted="downloadStarted",i.DownloadFinished="downloadFinished",i.DownloadError="downloadError",i.LevelUpdated="levelUpdated",i))(lr||{}),dr=(o=>(o[o.Unknown=0]="Unknown",o[o.Pending=1]="Pending",o[o.InProgress=2]="InProgress",o[o.Done=3]="Done",o[o.Error=4]="Error",o))(dr||{}),ur=(a=>(a[a.Slim=0]="Slim",a[a.Extended=1]="Extended",a[a.Provenance=2]="Provenance",a))(ur||{});var fn=r=>new Promise(e=>setTimeout(e,r)),x=()=>{let r,e,t=!1,a=!1;return{pro:new Promise((l,u)=>{r=l,e=u}),resolve:l=>{t?console.trace("resolve called twice"):(r(l),t=!0)},reject:l=>{t?console.error("reject called twice"):(t=!0,e(l))},start:()=>a=!0,isStarted:()=>a}};var pr=4,mr="the_world_library",se=x(),k="patches",Le="catalog_json",mt="key_value",_="pdf_data",gt="deviceState",ht="localRecords",ee="instanceRemaps",R=()=>{if(se.isStarted())return se.pro;se.start();let r=indexedDB.open(mr,pr);return r.onupgradeneeded=function(){let e=r.result;e.objectStoreNames.contains(Le)||e.createObjectStore(Le,{keyPath:"id"}),e.objectStoreNames.contains(mt)||e.createObjectStore(mt,{keyPath:"key"}),e.objectStoreNames.contains(_)||e.createObjectStore(_,{keyPath:"fileId"}),e.objectStoreNames.contains(k)||e.createObjectStore(k,{keyPath:["username","pk"]}).createIndex("username","username",{unique:!1}),e.objectStoreNames.contains(gt)||e.createObjectStore(gt),e.objectStoreNames.contains(ht)||e.createObjectStore(ht,{keyPath:["creatorUsername","wireId"]}).createIndex("byCreator","creatorUsername",{unique:!1}),e.objectStoreNames.contains(ee)||e.createObjectStore(ee,{keyPath:["creatorUsername","objectId","langId","originalIndex"]}),console.log("[IDB] models_v2 schema upgraded to version",e.version)},r.onerror=function(e){se.reject(e)},r.onsuccess=function(e){se.resolve(e.target.result)},se.pro},bn=async()=>{let r=await R(),e=Array.from(r.objectStoreNames);if(e.length===0)return;let t=r.transaction(e,"readwrite");return e.forEach(a=>t.objectStore(a).clear()),new Promise(a=>t.oncomplete=a)};var gr=r=>JSON.stringify(r,Object.keys(r).sort()),hr=(r,e)=>{let t=x();return R().then(a=>{if(e.length===0)return t.resolve(!0);Te(r).then(n=>{let o=(n.length?n[n.length-1].pk:0)+1,i=a.transaction(k,"readwrite"),s=i.objectStore(k),c=new Set(n.map(({pk:l,username:u,...g})=>gr(g)));e.forEach(l=>{if(!c.has(gr(l))){let u=s.add(Object.assign({},{username:r,pk:o},l));o++,u.onerror=function(g){console.error(`error inserting [${k}]`,l,g.target),t.reject(new Error("error inserting patch"))}}}),i.oncomplete=function(){t.resolve(!0)},i.onerror=function(l){console.error(`tx.onerror inserting [${k}]: `,l),t.reject(l.target)}}).catch(n=>{console.error(n),t.reject(n)})}).catch(a=>{console.error(`[indexdb error:] bulkAddPatches ${a.message}`),t.reject(a)}),t.pro};var yr=(r,e)=>{let t=x();return R().then(async a=>{let n=a.transaction(k,"readonly"),o=n.objectStore(k);o.index("username").getAll(IDBKeyRange.only(r)).onsuccess=i=>{let c=(i.target.result||[]).filter(l=>l.pk>=e);c.sort((l,u)=>l.pk-u.pk),t.resolve(c)},n.onerror=function(i){console.error("worker: error loading patches since",e,i.target),t.reject(i.target)}}).catch(t.reject),t.pro},Te=r=>{let e=x();return R().then(async t=>{let a=t.transaction(k,"readonly");a.objectStore(k).index("username").getAll(IDBKeyRange.only(r)).onsuccess=n=>{let o=n.target.result||[];o.sort((i,s)=>i.pk-s.pk),e.resolve(o)},a.onerror=function(n){console.error("worker: error loading all patches",n.target),e.reject(n.target)}}).catch(e.reject),e.pro};function Ne(r){if(typeof r!="string")return r;let e=r.replace(/<\/?[^>]+(>|$)/g,""),t=/javascript:|data:|vbscript:|onclick|onerror|onload|onmouseover/gi;return e=e.replace(t,"[REDACTED]"),e}var fr={current:2,versions:{1:{hash:"de10ae90e292fd0d",enums:{BookMethod:{bits:3,values:["Unknown","Scan","NativeDigital","OCR","AiTranslation"]},CopyrightStatus:{bits:2,values:["Unknown","PublicDomain","CreativeCommons","AllRightsReserved"]},QualityScore:{bits:3,values:["None","Poor","Fair","Good","VeryGood","Excellent"]},RecordingStatus:{bits:2,values:["Pending","Active","Completed","Archived"]}},props:{0:{name:"title",type:"string",bits:0},1:{name:"description",type:"string",bits:0},2:{name:"originalLang",type:"string",bits:0},3:{name:"ageGradeBand",type:"number",bits:8},4:{name:"previewTxId",type:"string",bits:0},5:{name:"safe",type:"boolean",bits:1},6:{name:"deleted",type:"boolean",bits:1},7:{name:"lifecycleStatus",type:"number",bits:2},8:{name:"prerequisites",type:"string",bits:0},9:{name:"deweyDecimal",type:"string",bits:0},10:{name:"locCallNumber",type:"string",bits:0},11:{name:"copyrightStatus",type:"enum",bits:2,enum:"CopyrightStatus"},12:{name:"textQuality",type:"enum",bits:3,enum:"QualityScore"},13:{name:"illustrations",type:"enum",bits:3,enum:"QualityScore"},14:{name:"educationQuality",type:"enum",bits:3,enum:"QualityScore"},15:{name:"practicality",type:"enum",bits:3,enum:"QualityScore"},16:{name:"accessibilityLevel",type:"enum",bits:3,enum:"QualityScore"},17:{name:"teacherMaterials",type:"boolean",bits:1},18:{name:"pedagogicalScaffolding",type:"enum",bits:3,enum:"QualityScore"},19:{name:"clarityOfExplanation",type:"enum",bits:3,enum:"QualityScore"},20:{name:"workedExamples",type:"enum",bits:3,enum:"QualityScore"},21:{name:"exercisesAndAssessment",type:"enum",bits:3,enum:"QualityScore"},22:{name:"selfStudyReadiness",type:"enum",bits:3,enum:"QualityScore"},23:{name:"referenceApparatus",type:"enum",bits:3,enum:"QualityScore"},24:{name:"safetyGuidance",type:"enum",bits:3,enum:"QualityScore"},25:{name:"contentCurrency",type:"enum",bits:3,enum:"QualityScore"},26:{name:"ecoRegeneration",type:"enum",bits:3,enum:"QualityScore"},27:{name:"communityLiving",type:"enum",bits:3,enum:"QualityScore"},28:{name:"promotesPeace",type:"enum",bits:3,enum:"QualityScore"},29:{name:"businessDevelopment",type:"enum",bits:3,enum:"QualityScore"},30:{name:"language",type:"string",bits:0},31:{name:"downloadTxId",type:"string",bits:0},32:{name:"method",type:"enum",bits:3,enum:"BookMethod"},33:{name:"isAiTranslation",type:"boolean",bits:1},34:{name:"aiEngine",type:"string",bits:0},35:{name:"addedAt",type:"number",bits:32},36:{name:"nbPages",type:"number",bits:16},37:{name:"sizeBytes",type:"number",bits:32},38:{name:"publisher",type:"string",bits:0},39:{name:"publicationDate",type:"string",bits:0},40:{name:"publishedAt",type:"string",bits:0},41:{name:"qualityScore",type:"enum",bits:3,enum:"QualityScore"},42:{name:"isbn",type:"string",bits:0},43:{name:"birthDate",type:"string",bits:0},44:{name:"deathDate",type:"string",bits:0},45:{name:"nationality",type:"string",bits:0},46:{name:"wikiUrl",type:"string",bits:0},47:{name:"isniId",type:"string",bits:0},48:{name:"orcidId",type:"string",bits:0},49:{name:"ddcNotation",type:"string",bits:0}},instanceFields:{0:[30,31,32,33,34,35,36,37,38,39,40,41,42]}},2:{hash:"1eb9d7d1ce54fb8d",enums:{},props:{50:{name:"lccNotation",type:"string",bits:0},51:{name:"udcNotation",type:"string",bits:0},52:{name:"clcNotation",type:"string",bits:0},53:{name:"bbkNotation",type:"string",bits:0},54:{name:"tlcNotation",type:"string",bits:0},55:{name:"ccNotation",type:"string",bits:0}},instanceFields:{}}}};var De=fr,qe=De.current,yt=null,O=()=>(yt||(yt=Re(qe,De)),yt);function br(r,e){let t=null,a=[];return(...n)=>{t!==null&&clearTimeout(t);let o=new Promise((i,s)=>{a.push({resolve:i,reject:s})});return t=setTimeout(async()=>{t=null;let i=[...a];a=[];try{let s=await r(...n);i.forEach(c=>c.resolve(s))}catch(s){i.forEach(c=>c.reject(s))}},e),o}}var $=class ${constructor(e){this.username=e;this._patches=[]}get patches(){return this._patches}initThread(e,t=2e3){console.log("InitPatchInstance with thread",e),this.thread=e,this.sync=br($.prototype.sync.bind(this),t),this._patches.length>0&&this.sync().catch(console.error)}get threadInstance(){return this.thread}static onSync(e){this.onSyncListeners.push(e)}static setReplay(e){this._replaying=e}clearQueue(){this._patches=[]}addPatch(e){$._replaying||(U(e)&&(e.operation===d.EditPropertyString?e.value=Ne(e.value):e.operation===d.EditInstanceFieldString&&(e.value=Ne(e.value))),this._patches.push(e),this.sync().catch(console.error))}static cleanData(e){let t={},a=s=>typeof s>"u",n=[],o=(s,c,l)=>{a(t[s])&&(t[s]={}),a(t[s][c])&&(t[s][c]=!0,n.push(l))},i=(s,c,l)=>{a(t[s])&&(t[s]={}),a(t[s][c])?(t[s][c]=n.length,n.push(l)):n[t[s][c]]=l};for(let s=e.length-1;s>=0;s--){let c=e[s];if(U(c)){let g=`evm-${c.objectType}-${c.objectId??c.fromUid}-${c.operation}`;switch(c.operation){case d.EditPropertyString:case d.EditPropertyNumber:{let A=c;o(g,`${A.propertyId}:${A.langId??0}`,c);break}case d.EditInstanceFieldString:case d.EditInstanceFieldNumber:{let A=c;o(g,`${A.instanceIndex}:${A.propertyId}:${A.langId??0}`,c);break}case d.EditRelation:{let A=c;o(g,`${A.relationId}:${A.targetId}`,c);break}case d.SetAlias:{o(g,`${c.fromUid}`,c);break}case d.CreateRecord:{o(g,"create",c);break}case d.AddInstance:{let A=c;i(g,`${A.langId??0}:${A.instanceIndex}`,c);break}default:throw new Error(`unknown patch operation ${c.operation}`)}continue}let l=c,u=`local-${l.objectType}-${l.objectId}-${l.action}`;switch(l.action){case 4:o(u,`${l.part}`,l);break;case 6:o(u,`${l.part}:${l.socialMediaId}`,l);break;case 3:o(u,"seen",l);break;case 0:case 2:case 5:case 1:n.push(l);break;default:throw new Error(`unknown local action ${l.action}`)}}return n.reverse(),n}async sync(){if(typeof this.thread>"u")return null;let e=$.cleanData([...this._patches]);if(e.length===0)return this._patches=[],!0;this._patches=[],$.onSyncListeners.forEach(n=>{try{n(e)}catch(o){console.error(o)}});let t;try{t=await this.thread.sendRequest({cmd:"savePatches",payload:{username:this.username,patches:e}})}catch(n){throw this._patches.unshift(...e),n}let a=await $.calculateLevel(this.username);return console.log("level after saving patches",a),t}static async calculateLevel(e){let t=await Te(e),a=this.cleanData(t),n=0;for(let i of a){if(U(i)){switch(i.operation){case d.EditPropertyString:case d.EditInstanceFieldString:n+=4;break;case d.EditPropertyNumber:case d.EditInstanceFieldNumber:n+=2;break;case d.EditRelation:n+=3;break;case d.SetAlias:n+=5;break}continue}switch(i.action){case 1:n+=.5;break;case 6:n+=1;break;case 4:n+=1;break;case 3:n+=1;break;case 0:n+=1;break;case 5:n+=2;break;case 2:n+=3;break}}let o=n/7;if(typeof window<"u"&&typeof CustomEvent<"u"){let i=new CustomEvent("LevelUpdate",{detail:{level:o,username:e},bubbles:!0});window.dispatchEvent(i)}return o}};$._replaying=!1,$.onSyncListeners=[];var N=$,Ge=new Map,p=new N("mine");Ge.set("mine",p);var In=async(r,e)=>{let t=Ve(e,De);console.log(`[Patches] deserializePatches: writing ${t.length} restored patches for ${r}`),await hr(r,t)},Sn=async(r,e)=>{let a=(await yr("mine",r)).slice(0,e-r).filter(U).map(({pk:n,username:o,...i})=>i).map(n=>(n.operation===d.EditPropertyString?n.value=Ne(n.value):n.operation===d.EditInstanceFieldString&&(n.value=Ne(n.value)),n));return Qe(a,O(),qe)},vn=r=>{if(!Ge.has(r)){console.warn(`Account ${r} does not exist in patchesInstances \u2014 creating a new one`);let e=new N(r);e.initThread(p.threadInstance),Ge.set(r,e)}return Ge.get(r)};var L=new Map,Ir=(r,e)=>{L.has(r)||L.set(r,new Map),L.get(r).has(e)||L.get(r).set(e,{visits:[],downloads:[],rating:0,socialMediaId:[],parts:{}})},z=r=>{for(let e of r){Ir(e.objectType,e.objectId);let a=L.get(e.objectType).get(e.objectId);switch(e.action){case 0:a.visits.push(C.now());break;case 2:a.downloads.push(C.now());break;case 1:a.parts[e.part]?a.parts[e.part].visits.push(C.now()):a.parts[e.part]={rating:0,visits:[C.now()],socialMediaId:[]};break;case 4:a.parts[e.part]?a.parts[e.part].rating=e.rate:a.parts[e.part]={rating:e.rate,visits:[],socialMediaId:[]};break;case 3:a.rating=e.rate;break;case 6:a.parts[e.part]?a.parts[e.part].socialMediaId.push(e.socialMediaId):a.parts[e.part]={rating:0,visits:[],socialMediaId:[e.socialMediaId]};break;case 5:a.socialMediaId.push(e.socialMediaId);break;default:break}}},xn=r=>{if(!L.has(r))return[];let e=L.get(r);return Array.from(e.entries()).filter(([,t])=>t.downloads.length>0).map(([t])=>t)},Pn=r=>{if(!L.has(r))return[];let e=L.get(r);return Array.from(e.entries()).filter(([,t])=>t.visits.length>0).map(([t])=>t)},wn=r=>{if(!L.has(r))return[];let e=L.get(r),t=Array.from(e.keys()).filter(a=>{let n=e.get(a);return n.visits.length>0||n.downloads.length>0||[2,1,4].includes(n.rating)}).map(a=>{let n=e.get(a);return{id:a,nbVisits:n.visits.length,rating:n.rating}});return t.sort((a,n)=>n.nbVisits-a.nbVisits),t},Ee=class{constructor(e,t){this.objectId=e;this.objectType=t}favoriteParts(){if(!L.has(this.objectType))return[];let e=L.get(this.objectType);if(!e.has(this.objectId))return[];let t=e.get(this.objectId),a=Object.keys(t.parts).map(n=>({partId:parseInt(n),nbVisits:t.parts[n].visits.length,rating:t.parts[n].rating}));return a.sort((n,o)=>o.nbVisits-n.nbVisits),a}check(){Ir(this.objectType,this.objectId)}visit(){let e={action:0,ts:C.now(),objectId:this.objectId,objectType:this.objectType};z([e]),p.addPatch(e)}download(){let e={objectType:this.objectType,objectId:this.objectId,ts:C.now(),action:2};z([e]),p.addPatch(e)}get rating(){return this.check(),L.get(this.objectType)?.get(this.objectId)?.rating}set rating(e){let t={objectType:this.objectType,objectId:this.objectId,ts:C.now(),action:3,rate:e};z([t]),p.addPatch(t)}share(e){let t={objectType:this.objectType,objectId:this.objectId,ts:C.now(),action:5,socialMediaId:e};z([t]),p.addPatch(t)}ratePart(e,t){let a={objectType:this.objectType,objectId:this.objectId,ts:C.now(),action:4,part:e,rate:t};z([a]),p.addPatch(a)}visitPart(e){let t={objectType:this.objectType,objectId:this.objectId,ts:C.now(),action:1,part:e};z([t]),p.addPatch(t)}};var ft=new Map,bt="mine";var Sr=(r,e)=>{ft.has(r)||ft.set(r,new Map);let t=ft.get(r);return t.has(e)||t.set(e,{createdBy:bt,properties:new Map,relations:new Map}),t.get(e)},vr=r=>{if(!N._replaying)switch(r.operation){case d.EditPropertyString:case d.EditPropertyNumber:{let e=r,t=Sr(e.objectType,e.objectId);t.properties.has(e.propertyId)||t.properties.set(e.propertyId,[]),t.properties.get(e.propertyId).push({username:bt,value:e.value,langId:e.langId});break}case d.EditRelation:{let e=r,t=Sr(e.objectType,e.objectId);t.relations.has(e.relationId)||t.relations.set(e.relationId,[]),t.relations.get(e.relationId).push({username:bt,value:[e.action===h.Add?"+":"-",e.targetId]});break}default:break}};function ce(r){return(r>>>0&2147483648)!==0}var le=new Set;function Ce(r){return le.add(r),()=>{le.delete(r)}}function An(r){le.clear(),r&&le.add(r)}var ne={track(r){for(let e of le)e.track(r)},trigger(r){for(let e of le)e.trigger(r)}},We=class{constructor(e){this.limit=e;this.map=new Map;this._pinned=new Set;this._warnedOverflow=!1}get size(){return this.map.size}get(e){if(!this.map.has(e))return;let t=this.map.get(e);return this.map.delete(e),this.map.set(e,t),t}set(e,t){if(this.map.has(e)&&this.map.delete(e),this.map.set(e,t),this.map.size>this.limit){let a=!1;for(let n of this.map.keys())if(!this._pinned.has(n)){this.map.delete(n),a=!0;break}!a&&!this._warnedOverflow&&(this._warnedOverflow=!0,console.warn(`[LruCache] limit (${this.limit}) exceeded with every entry pinned \u2014 growing past limit instead of evicting/crashing. This usually means too many draft/unsynced records are open at once.`))}}pin(e){this._pinned.add(e)}unpin(e){this._pinned.delete(e)}has(e){return this.map.has(e)}delete(e){this.map.delete(e)}clear(){this.map.clear()}keys(){return this.map.keys()}values(){return this.map.values()}},Rn=1e4,xr={cacheLimit:Rn},je=new Map,It=r=>{if(r.cacheLimit&&r.cacheLimit>0){xr.cacheLimit=r.cacheLimit;for(let e of je.values())e.limit=r.cacheLimit}},de=r=>{let e=je.get(r);return e||(e=new We(xr.cacheLimit),je.set(r,e)),e},Ln=()=>{je.clear()},ke=()=>je;function ae(r,e){if(ce(r)){if(!e)throw new Error("[models_v2] creatorUsername required for user-created records");return`${e}:${r}`}return`canonical:${r}`}var y=(r,e,t)=>ce(e)&&!t?!1:de(r).has(ae(e,t)),f=(r,e,t)=>{let a=ae(e,t),n=de(r).get(a);if(typeof n>"u")throw new Error(`cannot find ${r} with id ${e} (evicted or never loaded \u2014 use LoadAsync)`);return n},B=(r,e,t)=>{de(r).set(ae(e.id,t),e)},Tn=(r,e,t)=>{de(r).delete(ae(e,t))},Oe=(r,e,t)=>{de(r).pin(ae(e,t))},St=(r,e,t)=>{de(r).unpin(ae(e,t))};var vt=class{constructor(){this.db=null;this.instanceRemaps=new xt(this)}init(e){this.db=e}get idb(){if(!this.db)throw new Error("[models_v2] LocalRecordTable not initialised \u2014 call localRecordTable.init(db) at startup");return this.db}async put(e){return new Promise((t,a)=>{let i=this.idb.transaction("localRecords","readwrite").objectStore("localRecords").put(e);i.onsuccess=()=>t(),i.onerror=()=>a(i.error)})}async putIfAbsent(e){return new Promise((t,a)=>{let n=this.idb.transaction("localRecords","readwrite");n.onabort=()=>a(n.error||new Error("Transaction aborted")),n.onerror=()=>a(n.error);let o=n.objectStore("localRecords"),i=o.get([e.creatorUsername,e.wireId]);i.onsuccess=()=>{if(i.result)t();else{let s=o.add(e);s.onsuccess=()=>t(),s.onerror=()=>a(s.error)}},i.onerror=()=>a(i.error)})}async get(e,t){return new Promise((a,n)=>{let s=this.idb.transaction("localRecords","readonly").objectStore("localRecords").get([e,t]);s.onsuccess=()=>a(s.result),s.onerror=()=>n(s.error)})}async getByCreator(e){return new Promise((t,a)=>{let s=this.idb.transaction("localRecords","readonly").objectStore("localRecords").index("byCreator").getAll(e);s.onsuccess=()=>t(s.result),s.onerror=()=>a(s.error)})}async setStatus(e,t,a){return new Promise((n,o)=>{let s=this.idb.transaction("localRecords","readwrite").objectStore("localRecords"),c=s.get([e,t]);c.onsuccess=()=>{if(!c.result){o(new Error(`LocalRecordEntry not found: ${e}:${t}`));return}let l=c.result;l.status=a;let u=s.put(l);u.onsuccess=()=>n(),u.onerror=()=>o(u.error)},c.onerror=()=>o(c.error)})}async setCanonicalId(e,t,a){return new Promise((n,o)=>{let s=this.idb.transaction("localRecords","readwrite").objectStore("localRecords"),c=s.get([e,t]);c.onsuccess=()=>{if(!c.result){o(new Error(`LocalRecordEntry not found: ${e}:${t}`));return}let l=c.result;l.canonicalId=a;let u=s.put(l);u.onsuccess=()=>n(),u.onerror=()=>o(u.error)},c.onerror=()=>o(c.error)})}},xt=class{constructor(e){this.table=e}async get(e,t,a,n){return new Promise((o,i)=>{let u=this.table.idb.transaction(ee,"readonly").objectStore(ee).get([a,e,t,n]);u.onsuccess=()=>o(u.result?.realIndex),u.onerror=()=>i(u.error)})}async put(e,t,a,n,o){return new Promise((i,s)=>{let g=this.table.idb.transaction(ee,"readwrite").objectStore(ee).put({creatorUsername:a,objectId:e,langId:t,originalIndex:n,realIndex:o});g.onsuccess=()=>i(),g.onerror=()=>s(g.error)})}},ue=new vt;var Nn=1146113329,Dn=2;var Ue=r=>r<=0?3:r<=8?1:r<=16?2:6,wr=(r,e)=>r.map((t,a)=>{if(t.type==="string")return{name:t.name,type:3};if(t.type==="boolean")return{name:t.name,type:7};let n=e?.[a]?.bits??t.bits??32;return{name:t.name,type:Ue(n)}}),Pr={name:"isDefault",type:7},ao=new TextDecoder,Je=new TextEncoder;var Ke=(r,e)=>{let t=n=>Array.isArray(n)?[n[e]??null]:n.slice(e,e+1);if(r.header.sidecarType===2){let n={},o;for(let[i,s]of r.columns)i==="ids"?o=t(s):n[i]=t(s);return{ids:o,fields:n}}let a={};for(let[n,o]of r.columns)a[n]=t(o);if(r.relations)for(let[n,o]of r.relations)a[n]=[o[e]??[]];return r.authorIds&&(a.authorIds=[r.authorIds[e]??[]]),r.instances&&(a.instances=[r.instances[e]??[]]),a},Pt=class{constructor(){this.chunks=[]}u8(e){this.chunks.push(new Uint8Array([e&255]))}u16(e){let t=new Uint8Array(2);new DataView(t.buffer).setUint16(0,e),this.chunks.push(t)}u24(e){let t=new Uint8Array(3);t[0]=e>>>16&255,t[1]=e>>>8&255,t[2]=e&255,this.chunks.push(t)}u32(e){let t=new Uint8Array(4);new DataView(t.buffer).setUint32(0,e>>>0),this.chunks.push(t)}bytes(e){this.chunks.push(e)}nullableString(e){if(e===null){this.u8(0);return}this.u8(1);let t=Je.encode(e);this.u16(t.length),this.bytes(t)}toBuffer(){let e=this.chunks.reduce((n,o)=>n+o.length,0),t=new Uint8Array(e),a=0;for(let n of this.chunks)t.set(n,a),a+=n.length;return t.buffer}},En=r=>{let e=[...r.relations??[]];return r.authorIds&&!e.some(t=>t.name==="authors")&&e.push({name:"authors",data:r.authorIds}),e},jn=(r,e,t)=>{switch(e){case 1:r.u8(t??0);break;case 2:r.u16(t??0);break;case 6:r.u32(t??0);break;case 7:r.u8(t?1:0);break;case 3:r.nullableString(t??null);break;default:throw new Error(`Unsupported instance field type 0x${e.toString(16)}`)}},Cn=(r,e)=>{if(e.length>255)throw new Error("Too many instance fields (max 255)");r.u8(e.length);for(let t of e){r.u8(t.type);let a=Je.encode(t.name);r.u8(a.length),r.bytes(a)}},He=r=>{let e=new Pt;e.u32(Nn),e.u8(Dn),e.u24(r.recordCount),e.u8(r.columns.length),e.u8(r.sidecarType);for(let t of r.columns){e.u8(t.type);let a=Je.encode(t.name);e.u8(a.length),e.bytes(a);let n=t.data;for(let o=0;o<r.recordCount;o++)switch(t.type){case 1:e.u8(n[o]??0);break;case 2:e.u16(n[o]??0);break;case 6:e.u32(n[o]??0);break;case 7:e.u8(n[o]?1:0);break;case 3:e.nullableString(n[o]??null);break;default:throw new Error(`Unsupported column type 0x${t.type.toString(16)}`)}}if(r.sidecarType===1){let t=En(r);e.u8(t.length);for(let i of t){let s=Je.encode(i.name);e.u8(s.length),e.bytes(s)}for(let i=0;i<r.recordCount;i++)for(let s of t){let c=s.data[i]??[];e.u16(c.length);for(let l of c)e.u24(l)}let a=r.instanceFields??[];if((r.instances?.length??0)>0&&a.length===0)throw new Error("writeSidecar: instances provided without instanceFields spec");let n=a.some(i=>i.name===Pr.name)?a:[...a,Pr];Cn(e,n);let o=r.instances??[];for(let i=0;i<r.recordCount;i++){let s=o[i]??[];e.u16(s.length);for(let c of s)for(let l of n)jn(e,l.type,c[l.name])}}return e.toBuffer()};var Ye=r=>r.charAt(0).toUpperCase()+r.slice(1),te=(r,e)=>e==="string"&&!r.endsWith("s")?`${r}s`:r,Ar=(r,e)=>{let t=e.props[r.propId]?.bits;return typeof t=="number"&&t>0?t:r.type==="boolean"?1:r.bits??32},kn=(r,e,t,a)=>{let n=a.instanceFields?.[t]?.[e],o=typeof n=="number"?a.props[n]?.bits:void 0;return typeof o=="number"&&o>0?o:r.type==="boolean"?1:r.bits??32},On=r=>r.name==="authors"?"authorIds":r.name,wt=(r,e)=>r<=8?Uint8Array.from(e):r<=16?Uint16Array.from(e):Uint32Array.from(e);function pe(r,e,t){let a=e.map(i=>i.id),n=[{name:"ids",type:6,data:Uint32Array.from(a)},{name:"titles",type:3,data:e.map(i=>i.title)},{name:"originalLangs",type:3,data:e.map(i=>i.originalLang)},{name:"previewTxIds",type:3,data:e.map(i=>i.previewTxId)},{name:"ageGradeBands",type:1,data:Uint8Array.from(e.map(i=>i.ageGradeBand))},{name:"safes",type:1,data:Uint8Array.from(e.map(i=>i.safe?1:0))},{name:"deleteds",type:1,data:Uint8Array.from(e.map(i=>i.deleted?1:0))}];for(let i of r.props.filter(s=>s.source==="slim")){let s=te(i.name,i.type);if(i.type==="string")n.push({name:s,type:3,data:e.map(c=>c[i.name])});else if(i.type==="boolean")n.push({name:s,type:1,data:Uint8Array.from(e.map(c=>c[i.name]?1:0))});else{let c=Ar(i,t);n.push({name:s,type:Ue(c),data:wt(c,e.map(l=>l[i.name]))})}}if(r.multipleInstances)for(let i=0;i<r.instanceFields.length;i++){let s=r.instanceFields[i],c=Ye(s.name),l=te(c,s.type),u=e.map(g=>g[`default${c}`]);if(s.type==="string")n.push({name:`default${l}`,type:3,data:u});else if(s.type==="boolean")n.push({name:`default${l}`,type:1,data:Uint8Array.from(u.map(g=>g?1:0))});else{let g=kn(s,i,r.objectId,t);n.push({name:`default${l}`,type:Ue(g),data:wt(g,u)})}}let o={sidecarType:0,recordCount:e.length,columns:n};return He(o)}function me(r,e,t){let a=e.map(c=>c.id),n=[{name:"ids",type:6,data:Uint32Array.from(a)},{name:"descriptions",type:3,data:e.map(c=>c.description)}];for(let c of r.props.filter(l=>l.source==="extended")){let l=te(c.name,c.type);if(c.type==="string")n.push({name:l,type:3,data:e.map(u=>u[c.name])});else if(c.type==="boolean")n.push({name:l,type:1,data:Uint8Array.from(e.map(u=>u[c.name]?1:0))});else{let u=Ar(c,t);n.push({name:l,type:Ue(u),data:wt(u,e.map(g=>g[c.name]))})}}let i=r.relations.filter(c=>c.direction==="has").map(c=>({name:c.name,data:e.map(l=>l[On(c)])})),s={sidecarType:1,recordCount:e.length,columns:n,...i.length>0&&{relations:i}};return r.multipleInstances&&(s.instanceFields=wr(r.instanceFields),s.instances=e.map(c=>c.instances)),He(s)}function ge(r,e){let t={sidecarType:2,recordCount:e.length,columns:[{name:"ids",type:6,data:Uint32Array.from(e.map(a=>a.id))}]};return He(t)}var At=r=>r.name==="authors"?"authorIds":r.name,Xe=class r{constructor(){this.schemas=new Map;this.byName=new Map}static getInstance(){return r.instance||(r.instance=new r),r.instance}register(e){this.schemas.set(e.objectId,e),this.byName.set(e.name,e)}get(e){let t=this.schemas.get(e);return t||(console.warn(`[SchemaRegistry] No schema registered for type ID ${e}. Returning generic placeholder.`),{name:"Generic",typePrefix:"XX",objectId:e,multipleInstances:!1,props:[],instanceFields:[],relations:[]})}getByName(e){return this.byName.get(e)}clear(){this.schemas.clear(),this.byName.clear()}},D=Xe.getInstance();var Nt=null,Un="eng",_n,P={get userLang(){if(Nt===null)throw new Error("[models_v2] Default language not set! Call setDefaultLanguage() before using models.");return Nt},get commonLang(){return Un},get defaultProvenance(){return _n}};function Tr(r){Nt=r}var he=0,ye=1,fe=2,Rt=3,Ze=4,_e=5,Be=6,et=7;function Rr(r){return Array.from(r.entries()).map(([e,t])=>[e,Array.from(t.values())])}function Lt(r){return Array.from(r,([e,t])=>[e,Array.from(t.entries())])}var Bn=r=>{let[e,t,a,n,o,i,s]=r;return[e,new Map(t.map(([c,l])=>[c,new Set(l)])),new Map(a.map(([c,l])=>[c,new Set(l)])),new Map(n.map(([c,l])=>[c,new Map(l)])),new Map(o.map(([c,l])=>[c,new Map(l)])),new Map(i.map(([c,l])=>[c,new Map(l)])),new Map(s)]},Lr=new Set,Tt=(r,e)=>{if(r){if(r.has(e))return r.get(e);if(r.has(F))return r.get(F);if(r.size===1)return r.values().next().value}},M=class extends Ee{constructor(t,a,n){let o=a[1]instanceof Map?a:Bn(a);super(o[0],t);this._boolValues=new Map;this._stringValues=new Map;this._numberValues=new Map;this._has=new Map;this._in=new Map;this._instances=new Map;this._provenance=new Map;this._id=o[0],this._creatorUsername=n,this._has=o[1],this._in=o[2],this._numberValues=o[3],this._boolValues=o[4],this._stringValues=o[5],this._instances=o[6]??new Map,this.schema=D.get(t);for(let{relationId:i,direction:s}of this.schema.relations??[]){let c=s==="has"?this._has:this._in;c.has(i)||c.set(i,new Set)}for(let i of[he,ye,fe,Ze])this._stringValues.has(i)||this._stringValues.set(i,new Map);this._boolValues.has(_e)||this._boolValues.set(_e,new Map([[F,!0]])),this._boolValues.has(Be)||this._boolValues.set(Be,new Map([[F,!1]]))}static createNewRequest(t){return[t,new Map,new Map,new Map,new Map,new Map,new Map]}static async createNewRecord(t,a){let{wireId:n,localId:o}=await t.next(),i={operation:d.CreateRecord,objectType:this.type,objectId:n,langId:0};p.addPatch(i);let s=[n,new Map,new Map,new Map,new Map,new Map,new Map],c=new this(s,a);return B(this.type,c,a),Oe(this.type,n,a),await ue.putIfAbsent({wireId:n,creatorUsername:a,objectType:this.type,localId:o,createdAt:Date.now(),status:"active"}),c}get creatorUsername(){return ce(this.id)?this._creatorUsername??"":"canonical"}toJSON(){return[this._id,Rr(this._has),Rr(this._in),Lt(this._numberValues),Lt(this._boolValues),Lt(this._stringValues),Array.from(this._instances.entries())]}get id(){return this._id}langOf(t){return re[t]??F}langIdOf(t){let a=t??P.userLang,n=I[a];return n===void 0?(a!==F&&!Lr.has(a)&&(Lr.add(a),console.warn(`[models_v2] Unknown language "${a}" \u2014 patches will land in the lang-agnostic slot (langId 0) and may collide with other unmapped languages. Append "${a}" to LANG_ID_ENCODE in db_schema_v2.`)),0):n}get title(){return this.getProp(he)??""}set title(t){this.dispatchString(he,t)}getTitle(t){return this.getProp(he,t)??""}setTitle(t,a){this.dispatchString(he,t,a)}get description(){return this.getProp(ye)??""}set description(t){this.dispatchString(ye,t)}getDescription(t){return this.getProp(ye,t)??""}setDescription(t,a){this.dispatchString(ye,t,a)}get originalLang(){return this.getProp(fe)??""}set originalLang(t){this.dispatchString(fe,t)}getOriginalLang(t){return this.getProp(fe,t)??""}setOriginalLang(t,a){this.dispatchString(fe,t,a)}get ageGradeBand(){return this.getProp(Rt)??0}set ageGradeBand(t){this.dispatchNumber(Rt,t)}get previewTxId(){return this.getProp(Ze)??""}set previewTxId(t){this.dispatchString(Ze,t)}get safe(){return this.getProp(_e)??!0}set safe(t){this.dispatchNumber(_e,t?1:0)}get deleted(){return this.getProp(Be)??!1}set deleted(t){this.dispatchNumber(Be,t?1:0)}get lifecycleStatus(){return this.getProp(et)??0}set lifecycleStatus(t){if(!ce(this.id))throw new Error("lifecycleStatus can only be set on user-created provisional records");if(!this._creatorUsername)throw new Error("Missing creatorUsername on provisional record");if(t<this.lifecycleStatus)throw new Error(`lifecycleStatus is forward-only: cannot transition from ${this.lifecycleStatus} to ${t}`);this.dispatchNumber(et,t,F)}dispatchString(t,a,n){let o={operation:d.EditPropertyString,objectType:this.objectType,objectId:this.id,langId:this.langIdOf(n),propertyId:t,value:a};this.patch(o);let i=n??P.userLang,s=P.defaultProvenance;s!==void 0&&this.getProvenance(t,i)!==s&&this.setProvenanceRaw(i,t,s),p.addPatch(o)}dispatchNumber(t,a,n){let o={operation:d.EditPropertyNumber,objectType:this.objectType,objectId:this.id,langId:this.langIdOf(n),propertyId:t,value:a};this.patch(o);let i=n??P.userLang,s=P.defaultProvenance;s!==void 0&&this.getProvenance(t,i)!==s&&this.setProvenanceRaw(i,t,s),p.addPatch(o)}dispatchRelation(t,a,n){let o={operation:d.EditRelation,objectType:this.objectType,objectId:this.id,langId:0,relationId:t,action:a,targetId:n};this.patch(o),p.addPatch(o)}applyRelationRaw(t,a,n,o){let i=t==="has"?this._has:this._in;i.has(a)||i.set(a,new Set),n===h.Add?i.get(a).add(o):i.get(a).delete(o),ne.trigger(this)}restoreInverses(){for(let[t,a]of this._has){let n=this.schema.relations?.find(s=>s.relationId===t);if(!n?.inverted)continue;let o=D.getByName(n.targetType),i=o?.relations.find(s=>s.name===n.inverted);if(!(!o||!i))for(let s of a){if(!y(o.objectId,s,this.creatorUsername))continue;let c=f(o.objectId,s,this.creatorUsername),l=c._in.get(i.relationId);l||(l=new Set,c._in.set(i.relationId,l)),l.add(this._id)}}}patch(t,a=!0){switch(vr(t),t.operation){case d.EditPropertyString:{let n=t;this._stringValues.has(n.propertyId)||this._stringValues.set(n.propertyId,new Map),this._stringValues.get(n.propertyId).set(this.langOf(n.langId),n.value);break}case d.EditPropertyNumber:{let n=t;if(n.propertyId===et){let i=n.value===1?"submitted":n.value===2?"community_pending":n.value===3?"canonical":"active";ue.setStatus(this.creatorUsername,this.id,i).catch(s=>{s.message?.includes("not found")||console.error("[Orm] Failed to update LocalRecordTable status:",s)}),n.value===3&&St(this.objectType,this.id,this.creatorUsername)}let o=this.langOf(n.langId);this.getPropType(n.propertyId)==="boolean"?(this._boolValues.has(n.propertyId)||this._boolValues.set(n.propertyId,new Map),this._boolValues.get(n.propertyId).set(o,!!n.value)):(this._numberValues.has(n.propertyId)||this._numberValues.set(n.propertyId,new Map),this._numberValues.get(n.propertyId).set(o,n.value));break}case d.EditInstanceFieldString:case d.EditInstanceFieldNumber:{let n=t;this.applyInstancePatch(n);break}case d.EditRelation:{let n=t,o=this.schema.relations?.find(s=>s.relationId===n.relationId),i=o?.direction??(this._in.has(n.relationId)&&!this._has.has(n.relationId)?"in":"has");if(this.applyRelationRaw(i,n.relationId,n.action,n.targetId),o?.inverted){let s=D.getByName(o.targetType),c=s?.relations.find(l=>l.name===o.inverted);s&&c&&y(s.objectId,n.targetId,this.creatorUsername)&&f(s.objectId,n.targetId,this.creatorUsername).applyRelationRaw(c.direction,c.relationId,n.action,this._id)}break}case d.SetAlias:break;case d.AddInstance:{let n=t,o=this.langOf(n.langId),i=this._instances.get(o);for(i||(i=[],this._instances.set(o,i));i.length<=n.instanceIndex;)i.push({});break}case d.CreateRecord:break;default:throw new Error(`unhandled patch operation ${t.operation}`)}ne.trigger(this)}applyInstancePatch(t){let a=this.langOf(t.langId),n=this._instances.get(a);for(n||(n=[],this._instances.set(a,n));n.length<=t.instanceIndex;)n.push({});let o=this.schema.instanceFields?.find(c=>c.propId===t.propertyId),i=o?.name??`field${t.propertyId}`,s=t.value;o?.type==="boolean"&&typeof s=="number"&&(s=!!s),n[t.instanceIndex][i]=s}getPropType(t){switch(t){case he:case ye:case fe:case Ze:return"string";case Rt:case et:return"number";case _e:case Be:return"boolean"}let a=this.schema.props.find(n=>n.propId===t);if(typeof a>"u")throw new Error(`unknown prop ${t} in schema ${this.schema.name}`);return a.type==="enum"?"number":a.type}getProp(t,a){ne.track(this);let n=a??P.userLang;switch(this.getPropType(t)){case"string":return Tt(this._stringValues.get(t),n)??"";case"number":return Tt(this._numberValues.get(t),n);case"boolean":return Tt(this._boolValues.get(t),n)}}setRaw(t,a,n=F){switch(this.getPropType(t)){case"string":{this._stringValues.has(t)||this._stringValues.set(t,new Map),this._stringValues.get(t).set(n,a);break}case"number":{this._numberValues.has(t)||this._numberValues.set(t,new Map),this._numberValues.get(t).set(n,a);break}case"boolean":{this._boolValues.has(t)||this._boolValues.set(t,new Map),this._boolValues.get(t).set(n,!!a);break}}}getInstancesData(t){return ne.track(this),this._instances.get(t??P.userLang)??[]}getDefaultInstanceData(t){let a=this.getInstancesData(t);return a.find(n=>n.isDefault===!0)??a[0]}setInstancesRaw(t,a){this._instances.set(t,a)}growInstances(t,a){let n=this._instances.get(t);for(n||(n=[],this._instances.set(t,n));n.length<=a;)n.push({})}addInstance(t){if(!this.schema.multipleInstances)throw new Error(`Model ${this.constructor.name} does not support multiple instances.`);let a=t??P.userLang,o=this.getInstancesData(a).length;this.growInstances(a,o);let i={operation:d.AddInstance,objectType:this.objectType,objectId:this.id,langId:this.langIdOf(a),instanceIndex:o};return this.patch(i),p.addPatch(i),o}getProvenance(t,a){return ne.track(this),this._provenance.get(a??P.userLang)?.get(t)??0}setProvenanceRaw(t,a,n){this._provenance.has(t)||this._provenance.set(t,new Map),this._provenance.get(t).set(a,n)}mergeSlim(t,a,n=P.userLang){this.setRaw(0,t.titles?.[a]??"",n),this.setRaw(2,t.originalLangs?.[a]??"",n),this.setRaw(4,t.previewTxIds?.[a]??"",n),this.setRaw(3,t.ageGradeBands?.[a],n),this.setRaw(5,t.safes?.[a]===1,n),this.setRaw(6,t.deleteds?.[a]===1,n);for(let o of this.schema.props){if(o.source!=="slim")continue;let i=te(o.name,o.type),s=t[i]?.[a];o.type==="string"?this.setRaw(o.propId,s??"",n):o.type==="boolean"?this.setRaw(o.propId,s===1,n):this.setRaw(o.propId,s,n)}if(this.schema.multipleInstances){let o=this.schema.instanceFields?.find(s=>s.type==="string"),i=!0;if(o){let s=`default${te(Ye(o.name),o.type)}`;t[s]?.[a]==null&&(i=!1)}if(i&&this.getInstancesData(n).length===0){let s={isDefault:!0};for(let c of this.schema.instanceFields||[]){let l=`default${te(Ye(c.name),c.type)}`,u=t[l]?.[a];c.type==="boolean"?s[c.name]=u===1:s[c.name]=u??null}this.setInstancesRaw(n,[s])}}}mergeExtended(t,a,n=P.userLang){this.setRaw(1,t.descriptions?.[a]??"",n);for(let o of this.schema.props){if(o.source!=="extended")continue;let i=te(o.name,o.type),s=t[i]?.[a];o.type==="string"?this.setRaw(o.propId,s??"",n):o.type==="boolean"?this.setRaw(o.propId,s===1,n):this.setRaw(o.propId,s,n)}for(let o of this.schema.relations||[]){if(o.direction!=="has")continue;let i=At(o);if(t[i]){let s=this._has.get(o.relationId);for(let c of t[i][a]??[])s.add(c)}}this.schema.multipleInstances&&t.instances&&this.setInstancesRaw(n,t.instances[a]??[])}mergeProv(t,a,n=P.userLang){let o={title:0,description:1,originalLang:2,ageGradeBand:3,previewTxId:4,safe:5,deleted:6,lifecycleStatus:7};for(let[i,s]of Object.entries(t.fields||{})){let c=o[i];if(c===void 0){let l=this.schema.props.find(u=>u.name===i);if(l)c=l.propId;else if(this.schema.instanceFields){let u=this.schema.instanceFields.find(g=>g.name===i);u&&(c=u.propId)}}c!==void 0&&this.setProvenanceRaw(n,c,s[a])}}};var Dr="0123456789ABCDEFGHJKLMNPQRSTUVWXYZ",Nr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*";function Er(r){let e=0;for(let n=0;n<r.length;n++){let o=Nr.indexOf(r[n]);if(o===-1)throw new Error(`[pid] Invalid character for ISO 7064 MOD 37-2: ${r[n]}`);let i=(e+o)%37;i===0&&(i=37),e=i*2%37}let t=(38-e)%37,a=Nr[t];return a==="*"&&(a="X"),a==="I"&&(a="J"),a==="O"&&(a="P"),a}function Fn(r){if(!Number.isInteger(r)||r<0||r>4294967295)throw new Error(`[pid] wireId ${r} must be an unsigned 32-bit integer`);if(r===0)return"0000000";let e="",t=r;for(;t>0;)e=Dr[t%34]+e,t=Math.floor(t/34);return e.padStart(7,"0")}function Mn(r){if(r.length!==7)throw new Error(`[pid] Base34 body must be exactly 7 characters, got ${r.length}`);let e=0;for(let t=0;t<r.length;t++){let a=Dr.indexOf(r[t]);if(a===-1)throw new Error(`[pid] Invalid character in base-34 body: ${r[t]}`);e=e*34+a}return e}function be(r,e){if(r.length!==2)throw new Error("[pid] typePrefix must be exactly 2 characters");let t=Fn(e),a=Er(r+t);return r+t+a}function Q(r,e){if(!e.startsWith(r))throw new Error(`[pid] PID ${e} does not start with expected prefix ${r}`);if(e.length!==10)throw new Error(`[pid] PID must be exactly 10 characters long, got ${e.length}`);let t=e.slice(2,9),a=e[9],n=Er(r+t);if(a!==n)throw new Error(`[pid] Invalid check character in PID ${e}. Expected ${n}`);return{wireId:Mn(t)}}var Ie={Book:{name:"Book",typePrefix:"BK",canonical:!0,uidStrategy:"native-only",multipleInstances:!0,instanceUidStrategy:["isbn"],props:[{name:"prerequisites",type:"string",source:"extended",propId:8},{name:"deweyDecimal",type:"string",source:"extended",propId:9},{name:"locCallNumber",type:"string",source:"extended",propId:10},{name:"copyrightStatus",type:"enum",enum:"CopyrightStatus",source:"extended",propId:11},{name:"textQuality",type:"enum",enum:"QualityScore",source:"extended",propId:12},{name:"illustrations",type:"enum",enum:"QualityScore",source:"extended",propId:13},{name:"educationQuality",type:"enum",enum:"QualityScore",source:"extended",propId:14},{name:"practicality",type:"enum",enum:"QualityScore",source:"extended",propId:15},{name:"accessibilityLevel",type:"enum",enum:"QualityScore",source:"extended",propId:16},{name:"teacherMaterials",type:"boolean",source:"extended",propId:17},{name:"pedagogicalScaffolding",type:"enum",enum:"QualityScore",source:"extended",propId:18},{name:"clarityOfExplanation",type:"enum",enum:"QualityScore",source:"extended",propId:19},{name:"workedExamples",type:"enum",enum:"QualityScore",source:"extended",propId:20},{name:"exercisesAndAssessment",type:"enum",enum:"QualityScore",source:"extended",propId:21},{name:"selfStudyReadiness",type:"enum",enum:"QualityScore",source:"extended",propId:22},{name:"referenceApparatus",type:"enum",enum:"QualityScore",source:"extended",propId:23},{name:"safetyGuidance",type:"enum",enum:"QualityScore",source:"extended",propId:24},{name:"contentCurrency",type:"enum",enum:"QualityScore",source:"extended",propId:25},{name:"ecoRegeneration",type:"enum",enum:"QualityScore",source:"extended",propId:26},{name:"communityLiving",type:"enum",enum:"QualityScore",source:"extended",propId:27},{name:"promotesPeace",type:"enum",enum:"QualityScore",source:"extended",propId:28},{name:"businessDevelopment",type:"enum",enum:"QualityScore",source:"extended",propId:29}],instanceFields:[{name:"language",type:"string",identityComponent:!0,propId:30},{name:"downloadTxId",type:"string",propId:31},{name:"method",type:"enum",enum:"BookMethod",propId:32},{name:"isAiTranslation",type:"boolean",propId:33},{name:"aiEngine",type:"string",nullable:!0,propId:34},{name:"addedAt",type:"number",bits:32,propId:35},{name:"nbPages",type:"number",bits:16,propId:36},{name:"sizeBytes",type:"number",bits:32,propId:37},{name:"publisher",type:"string",nullable:!0,propId:38},{name:"publicationDate",type:"string",nullable:!0,propId:39},{name:"publishedAt",type:"string",nullable:!0,propId:40},{name:"qualityScore",type:"enum",enum:"QualityScore",propId:41},{name:"isbn",type:"string",nullable:!0,source:"extended",propId:42}],relations:[{name:"inTags",targetType:"Tag",direction:"in",inverted:"books",relationId:0},{name:"authors",targetType:"Person",direction:"has",inverted:"authorOf",relationId:1}],translations:{fr:{className:"Livre",props:{title:"titre",description:"description"}}},standardPks:{isbn:"isbn"},objectId:0},Person:{name:"Person",typePrefix:"PR",canonical:!0,uidStrategy:["isni","orcid"],multipleInstances:!1,props:[{name:"birthDate",type:"string",source:"extended",propId:43},{name:"deathDate",type:"string",source:"extended",propId:44},{name:"nationality",type:"string",source:"extended",propId:45},{name:"wikiUrl",type:"string",source:"extended",propId:46},{name:"isniId",type:"string",nullable:!0,source:"extended",propId:47},{name:"orcidId",type:"string",nullable:!0,source:"extended",propId:48}],instanceFields:[],relations:[{name:"authorOf",targetType:"Book",direction:"in",inverted:"authors",relationId:2}],translations:{fr:{className:"Personne"}},standardPks:{isni:"isniId",orcid:"orcidId"},objectId:1},Tag:{name:"Tag",typePrefix:"TG",canonical:!0,uidStrategy:["lcc","ddc","udc","clc","bbk","tlc","cc"],multipleInstances:!1,props:[{name:"lccNotation",type:"string",nullable:!0,source:"extended",propId:50},{name:"ddcNotation",type:"string",nullable:!0,source:"extended",propId:49},{name:"udcNotation",type:"string",nullable:!0,source:"extended",propId:51},{name:"clcNotation",type:"string",nullable:!0,source:"extended",propId:52},{name:"bbkNotation",type:"string",nullable:!0,source:"extended",propId:53},{name:"tlcNotation",type:"string",nullable:!0,source:"extended",propId:54},{name:"ccNotation",type:"string",nullable:!0,source:"extended",propId:55}],instanceFields:[],relations:[{name:"inTags",targetType:"Tag",direction:"in",inverted:"tags",relationId:0},{name:"tags",targetType:"Tag",direction:"has",inverted:"inTags",relationId:3},{name:"books",targetType:"Book",direction:"has",inverted:"inTags",relationId:4}],standardPks:{lcc:"lccNotation",ddc:"ddcNotation",udc:"udcNotation",clc:"clcNotation",bbk:"bbkNotation",tlc:"tlcNotation",cc:"ccNotation"},objectId:2}};function $n(r){if(r.length!==16)return{valid:!1,error:`Expected 16 chars, got ${r.length}`};let e=0;for(let n=0;n<15;n++){let o=parseInt(r[n],10);if(isNaN(o))return{valid:!1,error:`Non-digit character at position ${n}`};e=(e+o)*2%11}let t=(12-e)%11,a=t===10?"X":String(t);return r[15].toUpperCase()!==a?{valid:!1,error:`Check digit mismatch: expected ${a}, got ${r[15]}`}:{valid:!0}}var V={standardId:"isni",uriScheme:"ISNI",normalize(r){return r.replace(/[\s-]/g,"")},display(r){let e=V.normalize(r);return e.length===16?`${e.slice(0,4)} ${e.slice(4,8)} ${e.slice(8,12)} ${e.slice(12)}`:e},validate(r){if(!r)return{valid:!1,error:"ISNI is absent"};let e=V.normalize(r);return/^[0-9]{15}[0-9X]$/.test(e)?$n(e):{valid:!1,error:`ISNI does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://isni.org/isni/${V.normalize(r)}`},apis:{"isni-sru":{apiId:"isni-sru",name:"ISNI SRU API",async fetch({isniId:r}){if(!r)return[];let t=`https://isni.oclc.org/sru/DB=1.2/?operation=searchRetrieve&query=${`pica.isn%3D${encodeURIComponent(r)}`}&recordSchema=isni-b&maximumRecords=10`,a=await fetch(t,{headers:{Accept:"application/xml"}});if(!a.ok)return[];let n=await a.text(),o=n.match(/<isniUnformatted>([0-9X]+)<\/isniUnformatted>/),i=n.match(/<forename>([^<]+)<\/forename>/),s=n.match(/<surname>([^<]+)<\/surname>/);return o?[{isni:o[1],forename:i?.[1],surname:s?.[1]}]:[]}}}};function zn(r){if(r.length!==16)return{valid:!1,error:`Expected 16 chars, got ${r.length}`};let e=0;for(let n=0;n<15;n++){let o=parseInt(r[n],10);if(isNaN(o))return{valid:!1,error:`Non-digit at position ${n}`};e=(e+o)*2%11}let t=(12-e)%11,a=t===10?"X":String(t);return r[15].toUpperCase()!==a?{valid:!1,error:`Check digit mismatch: expected ${a}, got ${r[15]}`}:{valid:!0}}var jr="https://pub.orcid.org/v3.0",Cr={Accept:"application/vnd.orcid+json"},q={standardId:"orcid",uriScheme:"ORCID",normalize(r){let e=r.replace(/\s/g,"");return e.length===16&&!e.includes("-")?`${e.slice(0,4)}-${e.slice(4,8)}-${e.slice(8,12)}-${e.slice(12)}`:e},display(r){return q.normalize(r)},validate(r){if(!r)return{valid:!1,error:"ORCID iD is absent"};let e=q.normalize(r);return/^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$/.test(e)?zn(e.replace(/-/g,"")):{valid:!1,error:`ORCID iD does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://orcid.org/${q.normalize(r)}`},apis:{"orcid-lookup":{apiId:"orcid-lookup",name:"ORCID Public Record API",async fetch({orcidId:r}){if(!r)return{};let e=await fetch(`${jr}/${r}/record`,{headers:Cr});if(!e.ok)return{};let a=(await e.json()).person??{},n=a.name??{};return{orcidId:r,givenNames:n["given-names"]?.value,familyName:n["family-name"]?.value,biography:a.biography?.content??void 0}}},"orcid-public-api":{apiId:"orcid-public-api",name:"ORCID Public Search API",async fetch({orcidId:r}){if(!r)return[];let e=await fetch(`${jr}/search?q=orcid:${r}&rows=10`,{headers:Cr});return e.ok?((await e.json()).result??[]).map(a=>({orcidId:a["orcid-identifier"]?.path??""})).filter(a=>a.orcidId):[]}}}};var tt=Ie.Person;D.register(tt);var kr={title:0,description:1,originalLang:2,ageGradeBand:3,previewTxId:4,safe:5,deleted:6,lifecycleStatus:7,birthDate:43,deathDate:44,nationality:45,wikiUrl:46,isniId:47,orcidId:48};function Dt(r){return pe(tt,r,O())}function Et(r){return me(tt,r,O())}function jt(r){return ge(tt,r)}var T=class T extends M{constructor(e,t){super(T.type,e,t)}static Load(e,t){return f(T.type,e,t)}static Has(e,t){return y(T.type,e,t)}static async LoadAsync(e,t){if(y(T.type,e,t))return f(T.type,e,t);let a=p.threadInstance;if(!a)throw new Error("worker thread not initialized \u2014 call PatchInstance.initThread first");let n=await a.sendRequest({cmd:"getRecord",payload:{objectType:T.type,id:e}});if(!n||n.length===0)throw new Error(`Person ${e} not found in worker storage`);let o=Ct(e,t);for(let i of n)i.slim&&o.mergeSlim(i.slim,0,i.lang),i.extended&&o.mergeExtended(i.extended,0,i.lang),i.prov&&o.mergeProv(i.prov,0,i.lang);return o}get birthDate(){return this.getProp(43)}set birthDate(e){this.dispatchString(43,e)}getBirthDate(e){return this.getProp(43,e)}setBirthDate(e,t){this.dispatchString(43,e,t)}get deathDate(){return this.getProp(44)}set deathDate(e){this.dispatchString(44,e)}getDeathDate(e){return this.getProp(44,e)}setDeathDate(e,t){this.dispatchString(44,e,t)}get nationality(){return this.getProp(45)}set nationality(e){this.dispatchString(45,e)}getNationality(e){return this.getProp(45,e)}setNationality(e,t){this.dispatchString(45,e,t)}get wikiUrl(){return this.getProp(46)}set wikiUrl(e){this.dispatchString(46,e)}getWikiUrl(e){return this.getProp(46,e)}setWikiUrl(e,t){this.dispatchString(46,e,t)}get isniId(){return this.getProp(47)??null}set isniId(e){this.dispatchString(47,e??"")}getIsniId(e){return this.getProp(47,e)??null}setIsniId(e,t){this.dispatchString(47,e??"",t)}get orcidId(){return this.getProp(48)??null}set orcidId(e){this.dispatchString(48,e??"")}getOrcidId(e){return this.getProp(48,e)??null}setOrcidId(e,t){this.dispatchString(48,e??"",t)}get inAuthorOfIds(){return Array.from(this._in.get(2).values())}get inAuthorOf(){return this.inAuthorOfIds.map(e=>m.Load(e))}isInAuthorOf(e){return this._in.get(2).has(e)}addIntoAuthorOf(e){if(this.isInAuthorOf(e))return;let t={operation:d.EditRelation,objectType:m.type,objectId:e,langId:0,relationId:1,action:h.Add,targetId:this.id};y(m.type,e)&&f(m.type,e).patch(t),this.applyRelationRaw("in",2,h.Add,e),p.addPatch(t)}removeFromAuthorOf(e){if(!this.isInAuthorOf(e))return;let t={operation:d.EditRelation,objectType:m.type,objectId:e,langId:0,relationId:1,action:h.Remove,targetId:this.id};y(m.type,e)&&f(m.type,e).patch(t),this.applyRelationRaw("in",2,h.Remove,e),p.addPatch(t)}toPID(){return`DL:${this.id&2147483648?"U":"C"}:PR:${be("PR",this.id)}`}toNativePID(){return this.toPID()}static fromPID(e){try{if(!e.startsWith("DL:"))return Q("PR",e);let t=e.split(":");return t.length>=4&&t[2]==="PR"?Q("PR",t[3]):null}catch{return null}}get isniNormalized(){return this.isniId?V.normalize(this.isniId):null}validateIsni(){return V.validate(this.isniId)}get orcidNormalized(){return this.orcidId?q.normalize(this.orcidId):null}validateOrcid(){return q.validate(this.orcidId)}sfcuid(){return this.isniId?`isni:${V.normalize(this.isniId)}`:this.orcidId?`orcid:${q.normalize(this.orcidId)}`:this.toNativePID()}get identityCluster(){let e=this.sfcuid(),t=[this.isniId?`isni:${V.normalize(this.isniId)}`:null,this.orcidId?`orcid:${q.normalize(this.orcidId)}`:null,this.toNativePID()].filter(Boolean);return{sfcuid:e,native:this.toNativePID(),aliases:t.filter(a=>a!==e),wireId:this.id}}};T.type=1,T.UID_STRATEGY="standards-first",T.STANDARD_PRIORITY=["isni","orcid"],T.serializeSlim=Dt,T.serializeExtended=Et,T.serializeProv=jt;var E=T,Ct=(r,e)=>{if(y(E.type,r,e))return f(E.type,r,e);let t=new E(E.createNewRequest(r),e);return B(E.type,t,e),t};var G={standardId:"lcc",uriScheme:"LCC",normalize(r){return r.trim()},display(r){return G.normalize(r)},validate(r){if(!r)return{valid:!1,error:"LCC notation is absent"};let e=G.normalize(r);return/^[A-Z0-9\.\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`LCC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://id.loc.gov/authorities/classification/${G.normalize(r)}`},apis:{}};var W={standardId:"ddc",uriScheme:"DDC",normalize(r){let e=r.trim();return e.includes(".")&&(e=e.replace(/\.?0+$/,"")),e},display(r){return W.normalize(r)},validate(r){if(!r)return{valid:!1,error:"DDC notation is absent"};let e=W.normalize(r);return/^[0-9]{3}(\.[0-9]+)?$/.test(e)?{valid:!0}:{valid:!1,error:`DDC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://id.loc.gov/authorities/classification/${W.normalize(r)}`},apis:{}};var J={standardId:"udc",uriScheme:"UDC",normalize(r){return r.trim()},display(r){return J.normalize(r)},validate(r){if(!r)return{valid:!1,error:"UDC notation is absent"};let e=J.normalize(r);return/^[0-9\.\-\:\+\/\(\)\[\]\=\*\"\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`UDC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://udcsummary.info/php/index.php?c=${J.normalize(r)}`},apis:{}};var K={standardId:"clc",uriScheme:"CLC",normalize(r){return r.trim()},display(r){return K.normalize(r)},validate(r){if(!r)return{valid:!1,error:"CLC notation is absent"};let e=K.normalize(r);return/^[A-Z0-9\.\-\+\=\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`CLC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://clc.nlc.cn/${K.normalize(r)}`},apis:{}};var H={standardId:"bbk",uriScheme:"BBK",normalize(r){return r.trim()},display(r){return H.normalize(r)},validate(r){if(!r)return{valid:!1,error:"BBK notation is absent"};let e=H.normalize(r);return/^[0-9А-Яа-яA-Za-z\.\-\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`BBK notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://bbk.rsl.ru/external/${H.normalize(r)}`},apis:{}};var Y={standardId:"tlc",uriScheme:"TLC",normalize(r){return r.trim()},display(r){return Y.normalize(r)},validate(r){if(!r)return{valid:!1,error:"TLC notation is absent"};let e=Y.normalize(r);return/^[A-Z0-9\.\-\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`TLC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://nlt.go.th/tlc/${Y.normalize(r)}`},apis:{}};var X={standardId:"cc",uriScheme:"CC",normalize(r){return r.trim()},display(r){return X.normalize(r)},validate(r){if(!r)return{valid:!1,error:"CC notation is absent"};let e=X.normalize(r);return/^[A-Za-z0-9\:\,\;\-\.\'\s]+$/.test(e)?{valid:!0}:{valid:!1,error:`CC notation does not match pattern: ${e}`}},toLinkedDataUri(r){return`https://isko.org/cc/${X.normalize(r)}`},apis:{}};var rt=Ie.Tag;D.register(rt);var Or={title:0,description:1,originalLang:2,ageGradeBand:3,previewTxId:4,safe:5,deleted:6,lifecycleStatus:7,lccNotation:50,ddcNotation:49,udcNotation:51,clcNotation:52,bbkNotation:53,tlcNotation:54,ccNotation:55};function kt(r){return pe(rt,r,O())}function Ot(r){return me(rt,r,O())}function Ut(r){return ge(rt,r)}var b=class b extends M{constructor(e,t){super(b.type,e,t)}static Load(e,t){return f(b.type,e,t)}static Has(e,t){return y(b.type,e,t)}static async LoadAsync(e,t){if(y(b.type,e,t))return f(b.type,e,t);let a=p.threadInstance;if(!a)throw new Error("worker thread not initialized \u2014 call PatchInstance.initThread first");let n=await a.sendRequest({cmd:"getRecord",payload:{objectType:b.type,id:e}});if(!n||n.length===0)throw new Error(`Tag ${e} not found in worker storage`);let o=_t(e,t);for(let i of n)i.slim&&o.mergeSlim(i.slim,0,i.lang),i.extended&&o.mergeExtended(i.extended,0,i.lang),i.prov&&o.mergeProv(i.prov,0,i.lang);return o}get lccNotation(){return this.getProp(50)??null}set lccNotation(e){this.dispatchString(50,e??"")}getLccNotation(e){return this.getProp(50,e)??null}setLccNotation(e,t){this.dispatchString(50,e??"",t)}get ddcNotation(){return this.getProp(49)??null}set ddcNotation(e){this.dispatchString(49,e??"")}getDdcNotation(e){return this.getProp(49,e)??null}setDdcNotation(e,t){this.dispatchString(49,e??"",t)}get udcNotation(){return this.getProp(51)??null}set udcNotation(e){this.dispatchString(51,e??"")}getUdcNotation(e){return this.getProp(51,e)??null}setUdcNotation(e,t){this.dispatchString(51,e??"",t)}get clcNotation(){return this.getProp(52)??null}set clcNotation(e){this.dispatchString(52,e??"")}getClcNotation(e){return this.getProp(52,e)??null}setClcNotation(e,t){this.dispatchString(52,e??"",t)}get bbkNotation(){return this.getProp(53)??null}set bbkNotation(e){this.dispatchString(53,e??"")}getBbkNotation(e){return this.getProp(53,e)??null}setBbkNotation(e,t){this.dispatchString(53,e??"",t)}get tlcNotation(){return this.getProp(54)??null}set tlcNotation(e){this.dispatchString(54,e??"")}getTlcNotation(e){return this.getProp(54,e)??null}setTlcNotation(e,t){this.dispatchString(54,e??"",t)}get ccNotation(){return this.getProp(55)??null}set ccNotation(e){this.dispatchString(55,e??"")}getCcNotation(e){return this.getProp(55,e)??null}setCcNotation(e,t){this.dispatchString(55,e??"",t)}get inTagsIds(){return Array.from(this._in.get(0).values())}get inTags(){return this.inTagsIds.map(e=>b.Load(e))}isInTag(e){return this._in.get(0).has(e)}addIntoTag(e){if(this.isInTag(e))return;let t={operation:d.EditRelation,objectType:b.type,objectId:e,langId:0,relationId:3,action:h.Add,targetId:this.id};y(b.type,e)&&f(b.type,e).patch(t),this.applyRelationRaw("in",0,h.Add,e),p.addPatch(t)}removeFromTag(e){if(!this.isInTag(e))return;let t={operation:d.EditRelation,objectType:b.type,objectId:e,langId:0,relationId:3,action:h.Remove,targetId:this.id};y(b.type,e)&&f(b.type,e).patch(t),this.applyRelationRaw("in",0,h.Remove,e),p.addPatch(t)}get tagsIds(){return Array.from(this._has.get(3).values())}get tags(){return this.tagsIds.map(e=>b.Load(e))}hasTag(e){return this._has.get(3).has(e)}addTag(e){this.hasTag(e)||this.dispatchRelation(3,h.Add,e)}removeTag(e){this.hasTag(e)&&this.dispatchRelation(3,h.Remove,e)}get booksIds(){return Array.from(this._has.get(4).values())}get books(){return this.booksIds.map(e=>m.Load(e))}hasBook(e){return this._has.get(4).has(e)}addBook(e){this.hasBook(e)||this.dispatchRelation(4,h.Add,e)}removeBook(e){this.hasBook(e)&&this.dispatchRelation(4,h.Remove,e)}toPID(){return`DL:${this.id&2147483648?"U":"C"}:TG:${be("TG",this.id)}`}toNativePID(){return this.toPID()}static fromPID(e){try{if(!e.startsWith("DL:"))return Q("TG",e);let t=e.split(":");return t.length>=4&&t[2]==="TG"?Q("TG",t[3]):null}catch{return null}}get lccNormalized(){return this.lccNotation?G.normalize(this.lccNotation):null}validateLcc(){return G.validate(this.lccNotation)}get ddcNormalized(){return this.ddcNotation?W.normalize(this.ddcNotation):null}validateDdc(){return W.validate(this.ddcNotation)}get udcNormalized(){return this.udcNotation?J.normalize(this.udcNotation):null}validateUdc(){return J.validate(this.udcNotation)}get clcNormalized(){return this.clcNotation?K.normalize(this.clcNotation):null}validateClc(){return K.validate(this.clcNotation)}get bbkNormalized(){return this.bbkNotation?H.normalize(this.bbkNotation):null}validateBbk(){return H.validate(this.bbkNotation)}get tlcNormalized(){return this.tlcNotation?Y.normalize(this.tlcNotation):null}validateTlc(){return Y.validate(this.tlcNotation)}get ccNormalized(){return this.ccNotation?X.normalize(this.ccNotation):null}validateCc(){return X.validate(this.ccNotation)}sfcuid(){return this.lccNotation?`lcc:${G.normalize(this.lccNotation)}`:this.ddcNotation?`ddc:${W.normalize(this.ddcNotation)}`:this.udcNotation?`udc:${J.normalize(this.udcNotation)}`:this.clcNotation?`clc:${K.normalize(this.clcNotation)}`:this.bbkNotation?`bbk:${H.normalize(this.bbkNotation)}`:this.tlcNotation?`tlc:${Y.normalize(this.tlcNotation)}`:this.ccNotation?`cc:${X.normalize(this.ccNotation)}`:this.toNativePID()}get identityCluster(){let e=this.sfcuid(),t=[this.lccNotation?`lcc:${G.normalize(this.lccNotation)}`:null,this.ddcNotation?`ddc:${W.normalize(this.ddcNotation)}`:null,this.udcNotation?`udc:${J.normalize(this.udcNotation)}`:null,this.clcNotation?`clc:${K.normalize(this.clcNotation)}`:null,this.bbkNotation?`bbk:${H.normalize(this.bbkNotation)}`:null,this.tlcNotation?`tlc:${Y.normalize(this.tlcNotation)}`:null,this.ccNotation?`cc:${X.normalize(this.ccNotation)}`:null,this.toNativePID()].filter(Boolean);return{sfcuid:e,native:this.toNativePID(),aliases:t.filter(a=>a!==e),wireId:this.id}}};b.type=2,b.UID_STRATEGY="standards-first",b.STANDARD_PRIORITY=["lcc","ddc","udc","clc","bbk","tlc","cc"],b.serializeSlim=kt,b.serializeExtended=Ot,b.serializeProv=Ut;var S=b,_t=(r,e)=>{if(y(S.type,r,e))return f(S.type,r,e);let t=new S(S.createNewRequest(r),e);return B(S.type,t,e),t};var Bt=new Map,Qn={set(r,e){if(!e)throw new Error(`[apiKeyDictionary] Empty value passed for apiId "${r}".`);Bt.set(r,e)},get(r){return Bt.get(r)},require(r){let e=Bt.get(r);if(!e)throw new Error(`[${r}] API key is not configured. Call apiKeyDictionary.set("${r}", "<your-key>") before using this adapter.`);return e}};function Vn(r){if(r.length!==13)return{valid:!1,error:`Expected 13 digits, got ${r.length}`};let e=0;for(let a=0;a<12;a++)e+=parseInt(r[a],10)*(a%2===0?1:3);let t=(10-e%10)%10;return t!==parseInt(r[12],10)?{valid:!1,error:`Check digit mismatch: expected ${t}, got ${r[12]}`}:{valid:!0}}var Z={standardId:"isbn",uriScheme:"ISBN",normalize(r){let e=r.replace(/[\s-]/g,"");if(e.length===10){let t="978"+e.slice(0,9),a=0;for(let n=0;n<12;n++)a+=parseInt(t[n],10)*(n%2===0?1:3);return t+(10-a%10)%10}return e},display(r){let e=Z.normalize(r);return e.length===13?`${e.slice(0,3)}-${e[3]}-${e.slice(4,7)}-${e.slice(7,12)}-${e[12]}`:e},validate(r){if(!r)return{valid:!1,error:"ISBN is absent"};let e=Z.normalize(r);return/^97[89][0-9]{10}$/.test(e)?Vn(e):{valid:!1,error:`ISBN does not match pattern: ${e}`}},toLinkedDataUri(r){return`urn:isbn:${Z.normalize(r)}`},apis:{openlibrary:{apiId:"openlibrary",name:"Open Library Books API",async fetch({isbn:r}){if(!r)return{};let e=await fetch(`https://openlibrary.org/api/books?bibkeys=ISBN:${r}&format=json&jscmd=data`);if(!e.ok)return{};let a=(await e.json())[`ISBN:${r}`]??{};return{title:a.title,authors:a.authors?.map(n=>n.name),publishDate:a.publish_date,pageCount:a.number_of_pages,coverUrl:a.cover?.medium,description:a.excerpts?.[0]?.text}}},googlebooks:{apiId:"googlebooks",name:"Google Books API",async fetch({isbn:r}){if(!r)return{};let e=Qn.require("googlebooks"),t=await fetch(`https://www.googleapis.com/books/v1/volumes?q=isbn:${r}&key=${e}`);if(!t.ok)return{};let n=(await t.json()).items?.[0]?.volumeInfo??{};return{title:n.title,authors:n.authors,publishedDate:n.publishedDate,pageCount:n.pageCount,language:n.language,description:n.description,thumbnail:n.imageLinks?.thumbnail}}}}};var nt=Ie.Book;D.register(nt);var Ur={title:0,description:1,originalLang:2,ageGradeBand:3,previewTxId:4,safe:5,deleted:6,lifecycleStatus:7,prerequisites:8,deweyDecimal:9,locCallNumber:10,copyrightStatus:11,textQuality:12,illustrations:13,educationQuality:14,practicality:15,accessibilityLevel:16,teacherMaterials:17,pedagogicalScaffolding:18,clarityOfExplanation:19,workedExamples:20,exercisesAndAssessment:21,selfStudyReadiness:22,referenceApparatus:23,safetyGuidance:24,contentCurrency:25,ecoRegeneration:26,communityLiving:27,promotesPeace:28,businessDevelopment:29,language:30,downloadTxId:31,method:32,isAiTranslation:33,aiEngine:34,addedAt:35,nbPages:36,sizeBytes:37,publisher:38,publicationDate:39,publishedAt:40,qualityScore:41,isbn:42};function Ft(r){return pe(nt,r,O())}function Mt(r){return me(nt,r,O())}function $t(r){return ge(nt,r)}var w=class w extends M{constructor(e,t){super(w.type,e,t)}static Load(e,t){return f(w.type,e,t)}static Has(e,t){return y(w.type,e,t)}static async LoadAsync(e,t){if(y(w.type,e,t))return f(w.type,e,t);let a=p.threadInstance;if(!a)throw new Error("worker thread not initialized \u2014 call PatchInstance.initThread first");let n=await a.sendRequest({cmd:"getRecord",payload:{objectType:w.type,id:e}});if(!n||n.length===0)throw new Error(`Book ${e} not found in worker storage`);let o=zt(e,t);for(let i of n)i.slim&&o.mergeSlim(i.slim,0,i.lang),i.extended&&o.mergeExtended(i.extended,0,i.lang),i.prov&&o.mergeProv(i.prov,0,i.lang);return o}get prerequisites(){return this.getProp(8)}set prerequisites(e){this.dispatchString(8,e)}getPrerequisites(e){return this.getProp(8,e)}setPrerequisites(e,t){this.dispatchString(8,e,t)}get deweyDecimal(){return this.getProp(9)}set deweyDecimal(e){this.dispatchString(9,e)}getDeweyDecimal(e){return this.getProp(9,e)}setDeweyDecimal(e,t){this.dispatchString(9,e,t)}get locCallNumber(){return this.getProp(10)}set locCallNumber(e){this.dispatchString(10,e)}getLocCallNumber(e){return this.getProp(10,e)}setLocCallNumber(e,t){this.dispatchString(10,e,t)}get copyrightStatus(){return this.getProp(11)??0}set copyrightStatus(e){this.dispatchNumber(11,e)}getCopyrightStatus(e){return this.getProp(11,e)??0}setCopyrightStatus(e,t){this.dispatchNumber(11,e,t)}get textQuality(){return this.getProp(12)??0}set textQuality(e){this.dispatchNumber(12,e)}getTextQuality(e){return this.getProp(12,e)??0}setTextQuality(e,t){this.dispatchNumber(12,e,t)}get illustrations(){return this.getProp(13)??0}set illustrations(e){this.dispatchNumber(13,e)}getIllustrations(e){return this.getProp(13,e)??0}setIllustrations(e,t){this.dispatchNumber(13,e,t)}get educationQuality(){return this.getProp(14)??0}set educationQuality(e){this.dispatchNumber(14,e)}getEducationQuality(e){return this.getProp(14,e)??0}setEducationQuality(e,t){this.dispatchNumber(14,e,t)}get practicality(){return this.getProp(15)??0}set practicality(e){this.dispatchNumber(15,e)}getPracticality(e){return this.getProp(15,e)??0}setPracticality(e,t){this.dispatchNumber(15,e,t)}get accessibilityLevel(){return this.getProp(16)??0}set accessibilityLevel(e){this.dispatchNumber(16,e)}getAccessibilityLevel(e){return this.getProp(16,e)??0}setAccessibilityLevel(e,t){this.dispatchNumber(16,e,t)}get teacherMaterials(){return this.getProp(17)??!1}set teacherMaterials(e){this.dispatchNumber(17,e?1:0)}getTeacherMaterials(e){return this.getProp(17,e)??!1}setTeacherMaterials(e,t){this.dispatchNumber(17,e?1:0,t)}get pedagogicalScaffolding(){return this.getProp(18)??0}set pedagogicalScaffolding(e){this.dispatchNumber(18,e)}getPedagogicalScaffolding(e){return this.getProp(18,e)??0}setPedagogicalScaffolding(e,t){this.dispatchNumber(18,e,t)}get clarityOfExplanation(){return this.getProp(19)??0}set clarityOfExplanation(e){this.dispatchNumber(19,e)}getClarityOfExplanation(e){return this.getProp(19,e)??0}setClarityOfExplanation(e,t){this.dispatchNumber(19,e,t)}get workedExamples(){return this.getProp(20)??0}set workedExamples(e){this.dispatchNumber(20,e)}getWorkedExamples(e){return this.getProp(20,e)??0}setWorkedExamples(e,t){this.dispatchNumber(20,e,t)}get exercisesAndAssessment(){return this.getProp(21)??0}set exercisesAndAssessment(e){this.dispatchNumber(21,e)}getExercisesAndAssessment(e){return this.getProp(21,e)??0}setExercisesAndAssessment(e,t){this.dispatchNumber(21,e,t)}get selfStudyReadiness(){return this.getProp(22)??0}set selfStudyReadiness(e){this.dispatchNumber(22,e)}getSelfStudyReadiness(e){return this.getProp(22,e)??0}setSelfStudyReadiness(e,t){this.dispatchNumber(22,e,t)}get referenceApparatus(){return this.getProp(23)??0}set referenceApparatus(e){this.dispatchNumber(23,e)}getReferenceApparatus(e){return this.getProp(23,e)??0}setReferenceApparatus(e,t){this.dispatchNumber(23,e,t)}get safetyGuidance(){return this.getProp(24)??0}set safetyGuidance(e){this.dispatchNumber(24,e)}getSafetyGuidance(e){return this.getProp(24,e)??0}setSafetyGuidance(e,t){this.dispatchNumber(24,e,t)}get contentCurrency(){return this.getProp(25)??0}set contentCurrency(e){this.dispatchNumber(25,e)}getContentCurrency(e){return this.getProp(25,e)??0}setContentCurrency(e,t){this.dispatchNumber(25,e,t)}get ecoRegeneration(){return this.getProp(26)??0}set ecoRegeneration(e){this.dispatchNumber(26,e)}getEcoRegeneration(e){return this.getProp(26,e)??0}setEcoRegeneration(e,t){this.dispatchNumber(26,e,t)}get communityLiving(){return this.getProp(27)??0}set communityLiving(e){this.dispatchNumber(27,e)}getCommunityLiving(e){return this.getProp(27,e)??0}setCommunityLiving(e,t){this.dispatchNumber(27,e,t)}get promotesPeace(){return this.getProp(28)??0}set promotesPeace(e){this.dispatchNumber(28,e)}getPromotesPeace(e){return this.getProp(28,e)??0}setPromotesPeace(e,t){this.dispatchNumber(28,e,t)}get businessDevelopment(){return this.getProp(29)??0}set businessDevelopment(e){this.dispatchNumber(29,e)}getBusinessDevelopment(e){return this.getProp(29,e)??0}setBusinessDevelopment(e,t){this.dispatchNumber(29,e,t)}get inTagsIds(){return Array.from(this._in.get(0).values())}get inTags(){return this.inTagsIds.map(e=>S.Load(e))}isInTag(e){return this._in.get(0).has(e)}addIntoTag(e){if(this.isInTag(e))return;let t={operation:d.EditRelation,objectType:S.type,objectId:e,langId:0,relationId:4,action:h.Add,targetId:this.id};y(S.type,e)&&f(S.type,e).patch(t),this.applyRelationRaw("in",0,h.Add,e),p.addPatch(t)}removeFromTag(e){if(!this.isInTag(e))return;let t={operation:d.EditRelation,objectType:S.type,objectId:e,langId:0,relationId:4,action:h.Remove,targetId:this.id};y(S.type,e)&&f(S.type,e).patch(t),this.applyRelationRaw("in",0,h.Remove,e),p.addPatch(t)}get authorsIds(){return Array.from(this._has.get(1).values())}get authors(){return this.authorsIds.map(e=>E.Load(e))}hasAuthor(e){return this._has.get(1).has(e)}addAuthor(e){this.hasAuthor(e)||this.dispatchRelation(1,h.Add,e)}removeAuthor(e){this.hasAuthor(e)&&this.dispatchRelation(1,h.Remove,e)}getInstances(e=P.userLang){return this.getInstancesData(e).map((t,a)=>new Fe(this,e,a,t))}getInstance(e,t=P.userLang){return this.getInstances(t)[e]}getDefaultInstance(e=P.userLang){let t=this.getInstances(e);return t.find(a=>a.isDefault)??t[0]}toPID(){return`DL:${this.id&2147483648?"U":"C"}:BK:${be("BK",this.id)}`}toNativePID(){return this.toPID()}static fromPID(e){try{if(!e.startsWith("DL:"))return Q("BK",e);let t=e.split(":");return t.length>=4&&t[2]==="BK"?Q("BK",t[3]):null}catch{return null}}static async LoadInstance(e,t){let a=globalThis.ExternalIdCrosswalk?.instance;if(!a)throw new Error("ExternalIdCrosswalk not initialized \u2014 bootup incomplete");if(await a.whenReady(),e.startsWith("DL:C:DERIVED:")){let l=await a.resolveDerived(e,t);if(!l)return null;let u=await w.LoadAsync(l.wireId);return u?{record:u,instanceIndex:l.instanceIndex}:null}if(e.startsWith("DL:C:")){let l=w.fromPID(e);if(l){let u=await w.LoadAsync(l.wireId);return u?{record:u}:null}return null}let n=e.indexOf(":");if(n===-1)return null;let o=e.slice(0,n),i=e.slice(n+1),s=await a.resolveForInstance(o,i,t);if(!s)return null;let c=await w.LoadAsync(s.wireId);return c?{record:c,instanceIndex:s.instanceIndex}:null}};w.type=0,w.UID_STRATEGY="native-only",w.STANDARD_PRIORITY=[],w.serializeSlim=Ft,w.serializeExtended=Mt,w.serializeProv=$t;var m=w,Fe=class{constructor(e,t,a,n){this.parent=e;this.lang=t;this.index=a;this.data=n}get isDefault(){return this.data.isDefault===!0}get language(){return this.data.language??""}set language(e){this.data.language=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:30,value:e??""};this.parent.patch(t),p.addPatch(t)}get downloadTxId(){return this.data.downloadTxId??""}set downloadTxId(e){this.data.downloadTxId=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:31,value:e??""};this.parent.patch(t),p.addPatch(t)}get method(){return this.data.method??0}set method(e){this.data.method=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:32,value:e};this.parent.patch(t),p.addPatch(t)}get isAiTranslation(){return this.data.isAiTranslation??!1}set isAiTranslation(e){this.data.isAiTranslation=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:33,value:e?1:0};this.parent.patch(t),p.addPatch(t)}get aiEngine(){return this.data.aiEngine??null}set aiEngine(e){this.data.aiEngine=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:34,value:e??""};this.parent.patch(t),p.addPatch(t)}get addedAt(){return this.data.addedAt??0}set addedAt(e){this.data.addedAt=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:35,value:e};this.parent.patch(t),p.addPatch(t)}get nbPages(){return this.data.nbPages??0}set nbPages(e){this.data.nbPages=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:36,value:e};this.parent.patch(t),p.addPatch(t)}get sizeBytes(){return this.data.sizeBytes??0}set sizeBytes(e){this.data.sizeBytes=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:37,value:e};this.parent.patch(t),p.addPatch(t)}get publisher(){return this.data.publisher??null}set publisher(e){this.data.publisher=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:38,value:e??""};this.parent.patch(t),p.addPatch(t)}get publicationDate(){return this.data.publicationDate??null}set publicationDate(e){this.data.publicationDate=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:39,value:e??""};this.parent.patch(t),p.addPatch(t)}get publishedAt(){return this.data.publishedAt??null}set publishedAt(e){this.data.publishedAt=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:40,value:e??""};this.parent.patch(t),p.addPatch(t)}get qualityScore(){return this.data.qualityScore??0}set qualityScore(e){this.data.qualityScore=e;let t={operation:d.EditInstanceFieldNumber,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:41,value:e};this.parent.patch(t),p.addPatch(t)}get isbn(){return this.data.isbn??null}set isbn(e){this.data.isbn=e;let t={operation:d.EditInstanceFieldString,objectType:m.type,objectId:this.parent.id,langId:I[this.lang]??0,instanceIndex:this.index,propertyId:42,value:e??""};this.parent.patch(t),p.addPatch(t)}derivedSfcuid(e){let t=[this.language??""];return`DL:C:DERIVED:${e}:${t.map(a=>encodeURIComponent(String(a))).join(":")}`}get isbnNormalized(){return this.isbn?Z.normalize(this.isbn):null}validateIsbn(){return Z.validate(this.isbn)}sfcuid(){return this.isbn?`isbn:${Z.normalize(this.isbn)}`:this.derivedSfcuid(this.parent.toPID())}get identityCluster(){let e=this.sfcuid(),t=[this.isbn?`isbn:${Z.normalize(this.isbn)}`:null,this.parent.toPID()].filter(Boolean);return{sfcuid:e,native:this.parent.toPID(),aliases:t.filter(a=>a!==e),wireId:this.parent.id}}get description(){return this.parent.getDescription(this.lang)??""}set description(e){this.parent.setDescription(e,this.lang)}},zt=(r,e)=>{if(y(m.type,r,e))return f(m.type,r,e);let t=new m(m.createNewRequest(r),e);return B(m.type,t,e),t};var Se={0:m,1:E,2:S};var _r=new Map,Vt=new Set;typeof window<"u"&&window.addEventListener("LevelUpdate",r=>{let{username:e,level:t}=r.detail;if(!e){console.error("[models_v2 LevelState] LevelUpdate event missing username",r);return}_r.set(e,{level:Math.floor(t)+1,progress:100*(t-Math.floor(t))}),Vt.forEach(a=>a(e))});var qt=r=>_r.get(r)??{level:1,progress:0},Gt=r=>(Vt.add(r),()=>Vt.delete(r));var qn=5,Gn=6,Wn=r=>r.getProp(Gn)===!1&&r.getProp(qn)===!0;function Jn(r,e,t){let a=D.get(r);if(!a)return!1;let n=new Map(a.instanceFields?.map(i=>[i.name,i.propId])??[]);for(let i of Object.values(a.standardPks??{})){let s=n.get(i);if(s===void 0)continue;let c=e[i],l=t.get(s);if(c!==void 0&&l!==void 0)return c===l}let o=n.get("downloadTxId");if(o!==void 0){let i=e.downloadTxId,s=t.get(o);if(i!==void 0&&s!==void 0)return i===s}return!1}async function Kn(r,e,t,a,n){let o=new Map;for(let l of t)(l.operation===d.EditInstanceFieldString||l.operation===d.EditInstanceFieldNumber)&&l.objectType===e.objectType&&l.objectId===e.objectId&&l.langId===e.langId&&l.instanceIndex===e.instanceIndex&&o.set(l.propertyId,l.value);let i=r.getInstancesData(a),s=-1;for(let l=0;l<i.length;l++)if(Jn(e.objectType,i[l],o)){s=l;break}if(s===e.instanceIndex)return;let c=s;s===-1&&(c=i.length,r.growInstances(a,c)),await n.instanceRemapStore.put(e.objectId,e.langId,n.creatorUsername,e.instanceIndex,c);for(let l of t)if((l.operation===d.EditInstanceFieldString||l.operation===d.EditInstanceFieldNumber)&&l.objectType===e.objectType&&l.objectId===e.objectId&&l.langId===e.langId&&l.instanceIndex===e.instanceIndex){let u=l;u.instanceIndex=c}}async function Br(r,e){if(r.operation===d.CreateRecord){let a=r,n=Se[a.objectType];if(!n)throw new Error(`[applyPatchWithContext] Unknown objectType ${a.objectType}`);let o=new n(M.createNewRequest(a.objectId),e.creatorUsername);B(a.objectType,o,e.creatorUsername),Oe(a.objectType,a.objectId,e.creatorUsername),await e.localRecordTable.putIfAbsent({wireId:a.objectId,creatorUsername:e.creatorUsername,objectType:a.objectType,localId:a.objectId&2147483647,createdAt:e.blockTimestamp,status:"active"});return}if(r.operation===d.AddInstance){let a=r;if(!y(a.objectType,a.objectId,e.creatorUsername)){console.warn("[applyPatchWithContext] AddInstance target absent; skipping");return}let n=f(a.objectType,a.objectId,e.creatorUsername),o=re[a.langId];if(!o)return;n.getInstancesData(o).length>a.instanceIndex?await Kn(n,a,e.batchRemainder,o,e):n.patch(a);return}let t=r;if(t.operation===d.EditInstanceFieldString||t.operation===d.EditInstanceFieldNumber){let a=await e.instanceRemapStore.get(t.objectId,t.langId,e.creatorUsername,t.instanceIndex);a!==void 0&&(t.instanceIndex=a)}if(t.objectType!==void 0&&t.objectId!==void 0){if(!y(t.objectType,t.objectId,e.creatorUsername)){console.warn("[applyPatchWithContext] Edit target absent; skipping");return}let a=f(t.objectType,t.objectId,e.creatorUsername);if(a.patch(r),r.operation===d.EditPropertyString||r.operation===d.EditPropertyNumber){let n=P.defaultProvenance;if(n!==void 0){let o=r,i=re[o.langId]??"eng";a.setProvenanceRaw(i,o.propertyId,n)}}}}var Wt=async(r,e="mine")=>{let t=0,a=0;N.setReplay(!0);try{let n=N.cleanData(r),o=new Set;for(let s of n)s.operation===d.CreateRecord&&o.add(`${s.objectType}:${s.objectId}`);let i=[];for(let s of n){if(!U(s))continue;let c=s.objectType,l=s.objectId??s.fromUid;if(c!==void 0&&l!==void 0){if(o.has(`${c}:${l}`))continue;if(!y(c,l,e)){let u=Se[c];u&&i.push(u.LoadAsync(l,e))}}}await Promise.all(i);for(let s=0;s<n.length;s++){let c=n[s];if(!U(c))continue;let l=c.objectType;if(typeof(c.objectId??c.fromUid)>"u"){a++;continue}let g={localRecordTable:ue,creatorUsername:e,blockTimestamp:Date.now(),get batchRemainder(){return n.slice(s+1)},instanceRemapStore:ue.instanceRemaps};await Br(c,g),t++}}finally{N.setReplay(!1)}return{applied:t,skipped:a}};var Jt="the_library:trash:v1";function Hn(){let r=new Map;if(typeof localStorage>"u")return r;try{let e=localStorage.getItem(Jt);if(!e)return r;let t=JSON.parse(e);for(let[a,n]of Object.entries(t)){let o=new Map;for(let[i,s]of Object.entries(n))o.set(i,new Set(s));r.set(Number(a),o)}}catch(e){console.warn("[trash] failed to load localStorage seed",e)}return r}var Pe=Hn(),at=new Map;function Fr(){if(typeof localStorage>"u")return;let r={};for(let[e,t]of Pe){let a={};for(let[n,o]of t)o.size>0&&(a[n]=Array.from(o));Object.keys(a).length>0&&(r[e]=a)}try{localStorage.setItem(Jt,JSON.stringify(r))}catch(e){console.warn("[trash] failed to persist localStorage snapshot",e)}}function Mr(r){at.get(r)?.forEach(e=>{try{e()}catch(t){console.error("[trash] listener failed",t)}})}function Yn(r,e){let t=Pe.get(r);t||(t=new Map,Pe.set(r,t));let a=t.get(e);return a||(a=new Set,t.set(e,a)),a}function $r(r){let e=r?.schema?.objectId,t=r?.id;if(typeof e!="number"||typeof t!="number")return null;let a=r.creatorUsername??"",n=Yn(e,a),o=r.deleted===!0||r.safe===!1,i=n.has(t);return o===i?null:(o?n.add(t):n.delete(t),e)}var Xn=50,ve=null,xe=null;function Zn(){xe=null;let r=ve;if(ve=null,!(!r||r.size===0)){Fr();for(let e of r)Mr(e)}}function ea(r){let e=$r(r);e!==null&&(ve||(ve=new Set),ve.add(e),xe===null&&(xe=setTimeout(Zn,Xn)))}function Kt(){let r=new Set;for(let e of ke().values())for(let t of e.values()){let a=$r(t);a!==null&&r.add(a)}if(r.size!==0){Fr();for(let e of r)Mr(e)}}Ce({track(){},trigger:ea});function ta(){Pe.clear(),at.clear(),ve=null,xe!==null&&(clearTimeout(xe),xe=null),typeof localStorage<"u"&&localStorage.removeItem(Jt)}var we={list(r,e=[]){let t=Pe.get(r);if(!t)return[];let a=new Set,n=e.length>0?e:t.keys();for(let o of n)for(let i of t.get(o)??[])a.add(i);return Array.from(a)},count(r,e=[]){return we.list(r,e).length},usernames(r){return Array.from(Pe.get(r)?.keys()??[])},subscribe(r,e){let t=at.get(r);return t||(t=new Set,at.set(r,t)),t.add(e),()=>t.delete(e)}};var oe=Le,Ht=r=>{let e=x();return R().then(t=>{try{let n=t.transaction(oe,"readonly").objectStore(oe).count(r);n.onsuccess=function(o){o.target.result>0?e.resolve(!0):e.resolve(!1)},n.onerror=function(o){console.error("worker: error",o.target),e.reject(o.target)}}catch(a){console.error(a);debugger}}).catch(t=>{console.error(`[indexdb error:] hasFile(): ${t.message}`),e.reject(t)}),e.pro},zr=r=>{let e=x();return R().then(t=>{let a=t.transaction(oe,"readonly"),n;a.objectStore(oe).get(r).addEventListener("success",function(o){n=o.target.result,e.resolve(n)}),a.onerror=function(o){console.error("worker: error",o.target),e.reject(o.target)}}).catch(e.reject),e.pro},Qr=async r=>{let e=x(),t=await R(),a=await Ht(r.id),n=t.transaction(oe,"readwrite");return a?n.objectStore(oe).put(r).onsuccess=function(){}:n.objectStore(oe).add(r).onsuccess=function(){},n.oncomplete=function(){e.resolve(!0)},n.onerror=function(o){console.error("worker: error",o.target),e.reject(o.target)},e.pro},ra={has:Ht,load:zr,store:Qr};var Vr=r=>{let e=x();return R().then(t=>{try{let n=t.transaction(_,"readonly").objectStore(_).openCursor(r);n.onsuccess=function(o){o.target.result?e.resolve(!0):e.resolve(!1)},n.onerror=function(o){console.error("worker: error",o.target),e.reject(o.target)}}catch(a){console.error(a);debugger}}).catch(t=>{console.error(`[indexdb error:] hasFile(): ${t.message}`),e.reject(t)}),e.pro},na=r=>{let e=x();return R().then(t=>{let a=t.transaction(_,"readonly"),n;a.objectStore(_).get(r).addEventListener("success",function(o){n=o.target.result}),a.oncomplete=function(){e.resolve(n)},a.onerror=function(o){e.reject(o.target)}}).catch(e.reject),e.pro},aa=r=>{let e=x();return R().then(async t=>{let a=await Vr(r.fileId),n=t.transaction(_,"readwrite");a?n.objectStore(_).put(r):n.objectStore(_).add(r),n.oncomplete=function(){e.resolve(!0)},n.onerror=function(o){console.error("worker: error",o.target),e.reject(o.target)}}).catch(e.reject),e.pro};var tr={};dt(tr,{bootstrapModelsV2:()=>ha,installVueReactivity:()=>cn,resetModelsV2Session:()=>Zr,useDraft:()=>ba,useLevel:()=>ya,useTrash:()=>fa});var j=hn(Gr(),1);var oa=(r,e)=>{typeof window<"u"&&typeof CustomEvent<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:e,bubbles:!0}))},Yt=class{constructor(e){this._rrRequest={};this._eventListeners={};this._proReady=x();this._counter=0;this._worker=new Worker(e,{type:"module"}),this._rrRequest={},this._worker.addEventListener("message",t=>{this._onMessage(t.data)}),this._worker.addEventListener("messageerror",t=>{this._onError(t)}),this._worker.onerror=t=>this._onError(t),this.addEventListener("workerready",()=>{this._proReady.resolve(!0)}),this.addEventListener("workerLoadingError",t=>{console.log("Worker loading Error",t),this._proReady.reject(t)})}get ready(){return this._proReady.pro}addEventListener(e,t){e in this._eventListeners||(this._eventListeners[e]=[]),this._eventListeners[e].push(t)}_onMessage(e){let{id:t,result:a,eventName:n,payload:o}=e;if(n&&n!=="undefined"&&n.length>0){oa(n,o),n in this._eventListeners&&this._eventListeners[n].forEach(c=>c(o));return}let{data:i,error:s}=a;if(t in this._rrRequest){let{res:c,rej:l}=this._rrRequest[t];delete this._rrRequest[t],s?l(s):c(i)}else console.error("nop; invalid request id:",t)}_onError(e){console.error("error in Thread",this,e),this._cancelPendingRequests()}_sendRequest(e,t={transferables:[]}){return new Promise((a,n)=>{let o;do o=`req-id-${this._counter}-${Math.random()}`,this._counter+=1;while(o in this._rrRequest);this._rrRequest[o]={res:a,rej:n},this._worker?this._worker.postMessage({id:o,data:e},t.transferables.length>0?t.transferables:void 0):console.log("_sendRequest(): nop (worker already terminated?)")})}sendRequest(e,t=[]){return this._sendRequest(e,{transferables:t})}getWorker(){return this._worker}_cancelPendingRequests(){let e=0;if(Object.entries(this._rrRequest).forEach(([t,a])=>{a.rej(`canceled: ${t}`),delete this._rrRequest[t],e+=1}),Object.keys(this._rrRequest).length!==0)throw"panic: the rr map should have been cleared!"}terminate(){this._cancelPendingRequests();let e=null;return this._worker.terminate(),this._worker=null,e||void 0}},ot,Ae=x(),Wr=async r=>(Ae.isStarted()||(Ae.start(),ot=new Yt(r),ot.addEventListener("workerready",()=>{Ae.resolve(ot)}),ot.addEventListener("workerLoadingError",e=>{Ae.reject(e)})),Ae.pro);var it=null,Jr=async r=>{r.cacheLimit&&It({cacheLimit:r.cacheLimit}),it===null&&(it=await Wr(r.workerPath??"/patch-worker.js")),p.initThread(it);let e=await it.sendRequest({cmd:"init",payload:{sidecars:r.sidecars,selectedLangs:r.selectedLangs}}),t=await Te("mine");return z(t.filter(a=>!U(a))),await N.calculateLevel("mine"),console.log("InitPatchWorker() done"),e};var ia="https://arweave.net",er=r=>r.replace(/\/+$/,""),Xt=(r,e)=>e?`${er(r)}/${e}`:void 0,Zt=(r,e)=>e?`${er(r)}/${e}`:void 0;function sa(r,e,t){let a=[];for(let[n,o]of Object.entries(e.objects??{}))for(let i of t){let s=o.tiers.slim?.find(u=>u.file.startsWith(`${i}_`)),c=o.tiers.extended?.find(u=>u.file.startsWith(`${i}_`)),l=o.tiers.prov?.find(u=>u.file.startsWith(`${i}_`));!s&&!c&&!l||a.push({objectType:Number(n),lang:i,slimUrl:Xt(r,s?.file),extendedUrl:Xt(r,c?.file),provUrl:Xt(r,l?.file)})}return a}function ca(r,e,t=ia){let a=[];for(let[n,o]of Object.entries(r.objects??{}))for(let i of e){let s=o[i];s&&a.push({objectType:Number(n),lang:i,slimUrl:Zt(t,s.slim?.[0]),extendedUrl:Zt(t,s.extended?.[0]),provUrl:Zt(t,s.prov?.[0])})}return a}function la(){let r=0;for(let e of ke().values())for(let t of e.values())t.restoreInverses(),r++;return r}function da(r,e){let t=new Map(e.map(n=>[n.type,n.create])),a=0;for(let n of r){let o=t.get(n.objectType);if(o)for(let[i,s]of n.idIndex){let c=o(i);n.slim&&c.mergeSlim(Ke(n.slim,s),0,n.lang),n.extended&&c.mergeExtended(Ke(n.extended,s),0,n.lang),n.prov&&c.mergeProv(Ke(n.prov,s),0,n.lang),a++}}return la(),Kt(),a}async function ua(r){Tr(r.userLang);let e=r.selectedLangs??[r.userLang],t;if(r.localMode){let o;if(r.localManifest)o=r.localManifest;else{let i=await fetch(`${er(r.localMode)}/corpus-index.json`);if(!i.ok)throw new Error(`local corpus-index.json fetch failed: ${i.status}`);o=await i.json()}t=sa(r.localMode,o,e)}else if(r.registry)t=ca(r.registry.dataBlock,e,r.registry.gateway);else throw new Error("bootModelsV2: provide `localMode` (folder) or `registry` (data block)");let a=await Jr({workerPath:r.workerPath,sidecars:t,selectedLangs:e}),n=da(a.sidecars,r.models);await Wt(a.patches.mine??[]),console.log(`[models_v2] booted: ${n} records (${r.localMode?`local ${r.localMode}`:"registry"})`),Hr=r;for(let o of e)Yr.add(o);return a}var Hr=null,Yr=new Set;var st=null,Kr=!1,ct,Xr=(r,e)=>(ct=r.onNavigate,e(),st===null?st=Promise.resolve().then(()=>r.init?r.init():ua(r).then(t=>r.onBoot?.(t))).catch(t=>{console.error("[models_v2] session init failed",t)}):ct?.(),typeof document<"u"&&!Kr&&(Kr=!0,document.addEventListener("astro:after-swap",()=>{e(),ct?.()})),st),Zr=()=>{st=null,ct=void 0,Hr=null,Yr.clear()};var pa=Symbol("isDraft"),en=Symbol("commit"),tn=Symbol("rollback"),rn=Symbol("isDirty"),ma=Symbol("changes"),ga=Symbol("target");function nn(r,e){let t=new Map;return new Proxy(r,{get(n,o,i){if(o===pa)return!0;if(o===ga)return n;if(o===rn)return t.size>0;if(o===ma)return t;if(o===en)return()=>{if(t.size!==0){for(let[c,l]of t.entries()){if(!(c in n)){console.warn(`[models_v2 Draft] Failed to commit property "${String(c)}" to target instance of "${n.constructor.name}". This property does not exist on the target (possible typo or misspelled field).`);continue}Reflect.set(n,c,l)||console.warn(`[models_v2 Draft] Failed to commit property "${String(c)}" to target instance of "${n.constructor.name}". This property might be read-only (getter-only relations/IDs).`)}t.clear(),e?.()}};if(o===tn)return()=>{t.size>0&&(t.clear(),e?.())};if(t.has(o))return t.get(o);let s=Reflect.get(n,o,i);return typeof s=="function"?s.bind(n):s},set(n,o,i,s){return Reflect.get(n,o,s)===i?(t.has(o)&&(t.delete(o),e?.()),!0):(t.set(o,i),e?.(),!0)}})}var an=r=>!!r?.[rn];var on=r=>r?.[en]?.(),sn=r=>r?.[tn]?.();var lt=null,cn=()=>{if(lt)return lt;let r=new WeakMap;return lt=Ce({track(t){let a=r.get(t);a||(a=(0,j.shallowRef)(0),r.set(t,a)),a.value},trigger(t){let a=r.get(t);a&&a.value++}}),lt},ha=r=>Xr(r,cn),ya=r=>{let e=(0,j.shallowRef)(0),t=Gt(a=>{a===r&&e.value++});return(0,j.onUnmounted)(t),(0,j.computed)(()=>(e.value,qt(r)))},fa=(r,e=[])=>{let t=(0,j.shallowRef)(0),a=we.subscribe(r,()=>{t.value++});return(0,j.onUnmounted)(a),{count:(0,j.computed)(()=>(t.value,we.count(r,e))),getIds:()=>we.list(r,e)}},ba=r=>{let e=(0,j.shallowRef)(0),t=(0,j.computed)(()=>{let a=typeof r=="function"?r():r.value;return nn(a,()=>{e.value++})});return{draft:t,isDirty:(0,j.computed)(()=>(e.value,an(t.value))),commit:()=>{on(t.value),e.value++},rollback:()=>{sn(t.value),e.value++}}};var Ia=Qt,Sa=tr;return yn(va);})();
|