@jinntec/jinntap 1.32.0 → 1.34.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/dist/index.es.js +25 -4
- package/dist/index.es.js.map +1 -1
- package/dist/jinn-tap.css +170 -12
- package/dist/jinn-tap.es.js +9072 -8011
- package/dist/jinn-tap.es.js.map +1 -1
- package/dist/jinn-toast.es.js +142 -40
- package/dist/jinn-toast.es.js.map +1 -1
- package/dist/storage.es.js +1089 -0
- package/dist/storage.es.js.map +1 -0
- package/dist/tei-editor-styles.css +1 -0
- package/package.json +20 -13
|
@@ -0,0 +1,1089 @@
|
|
|
1
|
+
const pe = "jinntap";
|
|
2
|
+
const re = "documents", ne = "assets";
|
|
3
|
+
function He(t, e) {
|
|
4
|
+
if (!t.objectStoreNames.contains(re)) {
|
|
5
|
+
const r = t.createObjectStore(re, { keyPath: "id" });
|
|
6
|
+
r.createIndex("updatedAt", "updatedAt", { unique: !1 }), r.createIndex("format", "format", { unique: !1 });
|
|
7
|
+
}
|
|
8
|
+
if (e < 2 && !t.objectStoreNames.contains(ne)) {
|
|
9
|
+
const r = t.createObjectStore(ne, { keyPath: "path" });
|
|
10
|
+
r.createIndex("updatedAt", "updatedAt", { unique: !1 }), r.createIndex("mimeType", "mimeType", { unique: !1 });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function Ce(t = pe) {
|
|
14
|
+
return new Promise((e, r) => {
|
|
15
|
+
const n = indexedDB.open(t, 2);
|
|
16
|
+
n.onerror = () => r(n.error ?? new Error("Failed to open IndexedDB")), n.onsuccess = () => e(n.result), n.onupgradeneeded = (a) => {
|
|
17
|
+
const o = (
|
|
18
|
+
/** @type {IDBOpenDBRequest} */
|
|
19
|
+
a.target.result
|
|
20
|
+
);
|
|
21
|
+
He(o, a.oldVersion);
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function H(t) {
|
|
26
|
+
return new Promise((e, r) => {
|
|
27
|
+
t.onsuccess = () => e(t.result), t.onerror = () => r(t.error ?? new Error("IndexedDB request failed"));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
class Ve {
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} [dbName]
|
|
33
|
+
*/
|
|
34
|
+
constructor(e = pe) {
|
|
35
|
+
this.dbName = e, this._db = null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Open (or create) the database.
|
|
39
|
+
* @returns {Promise<DocumentStore>}
|
|
40
|
+
*/
|
|
41
|
+
async open() {
|
|
42
|
+
return this._db ? this : (this._db = await Ce(this.dbName), this);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @returns {IDBDatabase}
|
|
46
|
+
*/
|
|
47
|
+
_requireDb() {
|
|
48
|
+
if (!this._db)
|
|
49
|
+
throw new Error("DocumentStore is not open; call open() first");
|
|
50
|
+
return this._db;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @param {IDBTransactionMode} mode
|
|
54
|
+
* @returns {IDBObjectStore}
|
|
55
|
+
*/
|
|
56
|
+
_store(e) {
|
|
57
|
+
return this._requireDb().transaction(re, e).objectStore(re);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @param {string} id
|
|
61
|
+
* @returns {Promise<StoredDocument|undefined>}
|
|
62
|
+
*/
|
|
63
|
+
async get(e) {
|
|
64
|
+
return await H(this._store("readonly").get(e)) ?? void 0;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @returns {Promise<StoredDocument[]>}
|
|
68
|
+
*/
|
|
69
|
+
async list() {
|
|
70
|
+
return (await H(this._store("readonly").getAll()) ?? []).sort((r, n) => (n.updatedAt ?? 0) - (r.updatedAt ?? 0));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Insert or replace a document record.
|
|
74
|
+
* @param {StoredDocument} doc
|
|
75
|
+
* @returns {Promise<StoredDocument>}
|
|
76
|
+
*/
|
|
77
|
+
async put(e) {
|
|
78
|
+
if (!(e != null && e.id))
|
|
79
|
+
throw new Error("DocumentStore.put requires a document with an id");
|
|
80
|
+
const r = {
|
|
81
|
+
...e,
|
|
82
|
+
updatedAt: e.updatedAt ?? Date.now()
|
|
83
|
+
};
|
|
84
|
+
return await H(this._store("readwrite").put(r)), r;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {string} id
|
|
88
|
+
* @returns {Promise<void>}
|
|
89
|
+
*/
|
|
90
|
+
async delete(e) {
|
|
91
|
+
await H(this._store("readwrite").delete(e));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Close the database connection.
|
|
95
|
+
*/
|
|
96
|
+
close() {
|
|
97
|
+
this._db && (this._db.close(), this._db = null);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const We = /* @__PURE__ */ new Set(["untitled document", "untitled article", "untitled"]);
|
|
101
|
+
function ee(t) {
|
|
102
|
+
return !t || We.has(t.trim().toLowerCase());
|
|
103
|
+
}
|
|
104
|
+
function fe(t) {
|
|
105
|
+
if (!t || ee(t))
|
|
106
|
+
return !0;
|
|
107
|
+
const e = t.trim().split(/\s+/).filter(Boolean);
|
|
108
|
+
return e.length < 2 ? !0 : e[e.length - 1].length < 3;
|
|
109
|
+
}
|
|
110
|
+
function te(t, e = 80) {
|
|
111
|
+
const r = t.replace(/\s+/g, " ").trim();
|
|
112
|
+
return r.length <= e ? r : `${r.slice(0, e - 1).trimEnd()}…`;
|
|
113
|
+
}
|
|
114
|
+
function Ge(t) {
|
|
115
|
+
var e, r;
|
|
116
|
+
if (!t || typeof t != "string")
|
|
117
|
+
return null;
|
|
118
|
+
try {
|
|
119
|
+
const n = new DOMParser().parseFromString(t, "application/xml");
|
|
120
|
+
if (n.querySelector("parsererror"))
|
|
121
|
+
return null;
|
|
122
|
+
const a = n.getElementsByTagName("*");
|
|
123
|
+
let o = null, s = null, l = null;
|
|
124
|
+
for (const i of a) {
|
|
125
|
+
const f = i.localName;
|
|
126
|
+
if (f === "title" && ((e = i.parentElement) == null ? void 0 : e.localName) === "titleStmt") {
|
|
127
|
+
o = i;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
f === "article-title" && !s && (s = i), f === "title" && !l && (l = i);
|
|
131
|
+
}
|
|
132
|
+
const c = o || s || l, h = (r = c == null ? void 0 : c.textContent) == null ? void 0 : r.trim();
|
|
133
|
+
return h && !ee(h) ? te(h) : null;
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function Te({ xml: t, metadata: e, plainText: r, fallback: n = "Untitled Document" } = {}) {
|
|
139
|
+
var c;
|
|
140
|
+
const a = r == null ? void 0 : r.trim().split(/\r?\n/).find((h) => h.trim()), o = a ? te(a) : null, s = (c = e == null ? void 0 : e.title) == null ? void 0 : c.trim();
|
|
141
|
+
if (s && !ee(s) && !fe(s))
|
|
142
|
+
return te(s);
|
|
143
|
+
const l = Ge(t);
|
|
144
|
+
return l && !fe(l) ? l : o || l || (s && !ee(s) ? te(s) : n);
|
|
145
|
+
}
|
|
146
|
+
async function mt(t, e = {}) {
|
|
147
|
+
const { debounceMs: r = 1200, force: n = !1, autoRestore: a = !1, onDraftAvailable: o, onNameChange: s, onRestore: l } = e;
|
|
148
|
+
if (!n && t.hasAttribute("server"))
|
|
149
|
+
return null;
|
|
150
|
+
const c = (t.getAttribute("format") || t.format || "tei").toLowerCase(), h = e.documentId || `current-${c}`, i = e.store || new Ve();
|
|
151
|
+
await i.open();
|
|
152
|
+
let f = !1, p = "Untitled Document", w = null, A = !1, g = !1, U = !1, k;
|
|
153
|
+
const S = (u) => {
|
|
154
|
+
p = u, s == null || s(u);
|
|
155
|
+
}, $ = (u, v = {}) => {
|
|
156
|
+
var T;
|
|
157
|
+
const y = t.metadata || {};
|
|
158
|
+
let x = p;
|
|
159
|
+
return f || (x = Te({
|
|
160
|
+
xml: u,
|
|
161
|
+
metadata: y,
|
|
162
|
+
plainText: typeof t.content == "string" ? t.content : void 0
|
|
163
|
+
}), !ee(x) && !fe(x) && y.title !== x && (t.metadata = { ...y, title: x })), S(x), {
|
|
164
|
+
id: h,
|
|
165
|
+
name: x,
|
|
166
|
+
format: c,
|
|
167
|
+
xml: u,
|
|
168
|
+
updatedAt: Date.now(),
|
|
169
|
+
nameLocked: f,
|
|
170
|
+
filename: (T = t.metadata) == null ? void 0 : T.name,
|
|
171
|
+
...v
|
|
172
|
+
};
|
|
173
|
+
}, D = async (u) => {
|
|
174
|
+
if (A || U || !u)
|
|
175
|
+
return;
|
|
176
|
+
const v = $(u);
|
|
177
|
+
return await i.put(v), v;
|
|
178
|
+
}, j = (u) => {
|
|
179
|
+
A || U || (clearTimeout(w), w = setTimeout(() => {
|
|
180
|
+
D(u).catch((v) => console.error("jinntap local store save failed", v));
|
|
181
|
+
}, r));
|
|
182
|
+
}, L = (u) => {
|
|
183
|
+
var v;
|
|
184
|
+
j((v = u.detail) == null ? void 0 : v.xml);
|
|
185
|
+
}, _ = async (u) => {
|
|
186
|
+
var v;
|
|
187
|
+
if (!(u != null && u.xml))
|
|
188
|
+
return !1;
|
|
189
|
+
U = !0;
|
|
190
|
+
try {
|
|
191
|
+
t.hasAttribute("url") && t.removeAttribute("url"), t.xml = u.xml, f = !!u.nameLocked;
|
|
192
|
+
const y = u.filename || ((v = t.metadata) == null ? void 0 : v.name) || "untitled.xml";
|
|
193
|
+
return t.metadata = {
|
|
194
|
+
...t.metadata || {},
|
|
195
|
+
title: u.name,
|
|
196
|
+
name: y
|
|
197
|
+
}, S(u.name), g = !0, k = void 0, l == null || l(u), !0;
|
|
198
|
+
} finally {
|
|
199
|
+
setTimeout(() => {
|
|
200
|
+
U = !1;
|
|
201
|
+
}, r + 50);
|
|
202
|
+
}
|
|
203
|
+
}, d = async () => {
|
|
204
|
+
const u = await i.get(h);
|
|
205
|
+
if (!(u != null && u.xml))
|
|
206
|
+
return !1;
|
|
207
|
+
k = u;
|
|
208
|
+
let v = a;
|
|
209
|
+
return !a && o && (v = !!await o(u), !v) ? (await i.delete(h), k = void 0, !1) : v ? _(u) : !1;
|
|
210
|
+
};
|
|
211
|
+
return await new Promise((u) => {
|
|
212
|
+
if (t._initialized || t.editor) {
|
|
213
|
+
u();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const v = () => u();
|
|
217
|
+
t.addEventListener("ready", v, { once: !0 }), (t._initialized || t.editor) && (t.removeEventListener("ready", v), u());
|
|
218
|
+
}), await d(), t.addEventListener("content-change", L), {
|
|
219
|
+
store: i,
|
|
220
|
+
documentId: h,
|
|
221
|
+
get restored() {
|
|
222
|
+
return g;
|
|
223
|
+
},
|
|
224
|
+
get pendingDraft() {
|
|
225
|
+
return k;
|
|
226
|
+
},
|
|
227
|
+
detach() {
|
|
228
|
+
A = !0, clearTimeout(w), t.removeEventListener("content-change", L);
|
|
229
|
+
},
|
|
230
|
+
async restore(u) {
|
|
231
|
+
const v = u || k || await i.get(h);
|
|
232
|
+
return _(v);
|
|
233
|
+
},
|
|
234
|
+
async rename(u) {
|
|
235
|
+
const v = u == null ? void 0 : u.trim();
|
|
236
|
+
if (!v)
|
|
237
|
+
throw new Error("Document name must not be empty");
|
|
238
|
+
f = !0, S(v), t.metadata = {
|
|
239
|
+
...t.metadata || {},
|
|
240
|
+
title: v
|
|
241
|
+
};
|
|
242
|
+
const y = t.xml;
|
|
243
|
+
return i.put(
|
|
244
|
+
$(y, {
|
|
245
|
+
name: v,
|
|
246
|
+
nameLocked: !0
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
},
|
|
250
|
+
/**
|
|
251
|
+
* Replace editor content with newly loaded XML (e.g. file upload).
|
|
252
|
+
* Unlocks the display name and re-deduces it from the new document —
|
|
253
|
+
* does not keep a previous `metadata.title` or `nameLocked` value.
|
|
254
|
+
*
|
|
255
|
+
* @param {string} xml
|
|
256
|
+
* @param {{ filename?: string }} [opts]
|
|
257
|
+
* @returns {Promise<StoredDocument>}
|
|
258
|
+
*/
|
|
259
|
+
async loadDocument(u, { filename: v } = {}) {
|
|
260
|
+
var y;
|
|
261
|
+
if (!u)
|
|
262
|
+
throw new Error("Document XML must not be empty");
|
|
263
|
+
f = !1, U = !0;
|
|
264
|
+
try {
|
|
265
|
+
t.hasAttribute("url") && t.removeAttribute("url"), t.xml = u;
|
|
266
|
+
const x = v && v.replace(/\.xml$/i, "").trim() || "Untitled Document", T = Te({
|
|
267
|
+
xml: u,
|
|
268
|
+
// Ignore stale metadata from the previous document
|
|
269
|
+
metadata: {},
|
|
270
|
+
plainText: typeof t.content == "string" ? t.content : void 0,
|
|
271
|
+
fallback: x
|
|
272
|
+
});
|
|
273
|
+
t.metadata = {
|
|
274
|
+
name: v || ((y = t.metadata) == null ? void 0 : y.name) || "untitled.xml",
|
|
275
|
+
title: T
|
|
276
|
+
}, S(T), clearTimeout(w);
|
|
277
|
+
const z = $(t.xml);
|
|
278
|
+
return await i.put(z), z;
|
|
279
|
+
} finally {
|
|
280
|
+
setTimeout(() => {
|
|
281
|
+
U = !1;
|
|
282
|
+
}, r + 50);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
async clear() {
|
|
286
|
+
clearTimeout(w), await i.delete(h), f = !1, S("Untitled Document");
|
|
287
|
+
},
|
|
288
|
+
async getRecord() {
|
|
289
|
+
return i.get(h);
|
|
290
|
+
},
|
|
291
|
+
async saveNow() {
|
|
292
|
+
return clearTimeout(w), D(t.xml);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function ge(t) {
|
|
297
|
+
return /^(https?:|data:|blob:)/i.test((t == null ? void 0 : t.trim()) ?? "");
|
|
298
|
+
}
|
|
299
|
+
function K(t) {
|
|
300
|
+
return (t || "image").replace(/\\/g, "/").split("/").pop().trim() || "image";
|
|
301
|
+
}
|
|
302
|
+
class dt {
|
|
303
|
+
/**
|
|
304
|
+
* @param {string} [dbName]
|
|
305
|
+
*/
|
|
306
|
+
constructor(e = pe) {
|
|
307
|
+
this.dbName = e, this._db = null, this._objectUrls = /* @__PURE__ */ new Map();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* @returns {Promise<IndexedDbAssetStore>}
|
|
311
|
+
*/
|
|
312
|
+
async open() {
|
|
313
|
+
return this._db ? this : (this._db = await Ce(this.dbName), this);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @returns {IDBDatabase}
|
|
317
|
+
*/
|
|
318
|
+
_requireDb() {
|
|
319
|
+
if (!this._db)
|
|
320
|
+
throw new Error("IndexedDbAssetStore is not open; call open() first");
|
|
321
|
+
return this._db;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* @param {IDBTransactionMode} mode
|
|
325
|
+
* @returns {IDBObjectStore}
|
|
326
|
+
*/
|
|
327
|
+
_store(e) {
|
|
328
|
+
return this._requireDb().transaction(ne, e).objectStore(ne);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @returns {Promise<AssetMeta[]>}
|
|
332
|
+
*/
|
|
333
|
+
async list() {
|
|
334
|
+
return (await H(this._store("readonly").getAll()) ?? []).map(({ path: r, mimeType: n, updatedAt: a, size: o }) => ({ path: r, mimeType: n, updatedAt: a, size: o })).sort((r, n) => (n.updatedAt ?? 0) - (r.updatedAt ?? 0));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @param {string} path
|
|
338
|
+
* @returns {Promise<StoredAsset|undefined>}
|
|
339
|
+
*/
|
|
340
|
+
async get(e) {
|
|
341
|
+
return await H(this._store("readonly").get(e)) ?? void 0;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Insert or replace an asset. Same `path` overwrites.
|
|
345
|
+
* @param {{ path: string, blob: Blob, mimeType?: string }} asset
|
|
346
|
+
* @returns {Promise<StoredAsset>}
|
|
347
|
+
*/
|
|
348
|
+
async put(e) {
|
|
349
|
+
const r = K(e.path);
|
|
350
|
+
if (!e.blob)
|
|
351
|
+
throw new Error("IndexedDbAssetStore.put requires a blob");
|
|
352
|
+
const n = {
|
|
353
|
+
path: r,
|
|
354
|
+
blob: e.blob,
|
|
355
|
+
mimeType: e.mimeType || e.blob.type || "application/octet-stream",
|
|
356
|
+
updatedAt: Date.now(),
|
|
357
|
+
size: e.blob.size
|
|
358
|
+
};
|
|
359
|
+
return await H(this._store("readwrite").put(n)), this._revokeCached(r), n;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* @param {string} path
|
|
363
|
+
* @returns {Promise<void>}
|
|
364
|
+
*/
|
|
365
|
+
async delete(e) {
|
|
366
|
+
await H(this._store("readwrite").delete(e)), this._revokeCached(e);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Resolve a graphic href to a displayable URL.
|
|
370
|
+
* Absolute URLs pass through; relative paths load from IndexedDB.
|
|
371
|
+
* @param {string} href
|
|
372
|
+
* @returns {Promise<string>}
|
|
373
|
+
*/
|
|
374
|
+
async resolve(e) {
|
|
375
|
+
const r = (e == null ? void 0 : e.trim()) ?? "";
|
|
376
|
+
if (!r)
|
|
377
|
+
return "";
|
|
378
|
+
if (ge(r))
|
|
379
|
+
return r;
|
|
380
|
+
const n = this._objectUrls.get(r);
|
|
381
|
+
if (n)
|
|
382
|
+
return n;
|
|
383
|
+
const a = await this.get(r);
|
|
384
|
+
if (!(a != null && a.blob))
|
|
385
|
+
return r;
|
|
386
|
+
const o = URL.createObjectURL(a.blob);
|
|
387
|
+
return this._objectUrls.set(r, o), o;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* @param {string} url
|
|
391
|
+
*/
|
|
392
|
+
revoke(e) {
|
|
393
|
+
if (e != null && e.startsWith("blob:")) {
|
|
394
|
+
for (const [r, n] of this._objectUrls)
|
|
395
|
+
if (n === e) {
|
|
396
|
+
URL.revokeObjectURL(e), this._objectUrls.delete(r);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
URL.revokeObjectURL(e);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
_revokeCached(e) {
|
|
403
|
+
const r = this._objectUrls.get(e);
|
|
404
|
+
r && (URL.revokeObjectURL(r), this._objectUrls.delete(e));
|
|
405
|
+
}
|
|
406
|
+
close() {
|
|
407
|
+
for (const e of this._objectUrls.values())
|
|
408
|
+
URL.revokeObjectURL(e);
|
|
409
|
+
this._objectUrls.clear(), this._db && (this._db.close(), this._db = null);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
class Je {
|
|
413
|
+
/**
|
|
414
|
+
* @param {object} options
|
|
415
|
+
* @param {string} options.contextPath - App context path (e.g. `/exist/apps/workbench`)
|
|
416
|
+
* @param {string} [options.collection=''] - Subcollection relative to data-default
|
|
417
|
+
* @param {string} [options.dataDefaultRel=''] - data-default path relative to data-root (e.g. `annotate`), used when deriving collection from a document path
|
|
418
|
+
* @param {RequestCredentials} [options.credentials='same-origin']
|
|
419
|
+
*/
|
|
420
|
+
constructor({
|
|
421
|
+
contextPath: e,
|
|
422
|
+
collection: r = "",
|
|
423
|
+
dataDefaultRel: n = "",
|
|
424
|
+
credentials: a = "same-origin"
|
|
425
|
+
} = {}) {
|
|
426
|
+
if (!e)
|
|
427
|
+
throw new Error("HttpAssetStore requires contextPath");
|
|
428
|
+
this.contextPath = e.replace(/\/+$/, ""), this.collection = (r || "").replace(/^\/+|\/+$/g, ""), this.dataDefaultRel = (n || "").replace(/^\/+|\/+$/g, ""), this.credentials = a, this._objectUrls = /* @__PURE__ */ new Map();
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Change the collection (e.g. after saving a new document to a path).
|
|
432
|
+
* @param {string} collection - Relative to data-default
|
|
433
|
+
*/
|
|
434
|
+
setCollection(e) {
|
|
435
|
+
this.collection = (e || "").replace(/^\/+|\/+$/g, ""), this._revokeAll();
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Update collection from a document path (relative to data-root).
|
|
439
|
+
* @param {string} docPath
|
|
440
|
+
*/
|
|
441
|
+
setCollectionFromDoc(e) {
|
|
442
|
+
this.setCollection(Me(e, this.dataDefaultRel));
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Id relative to data-default for an asset path.
|
|
446
|
+
* @param {string} path
|
|
447
|
+
* @returns {string}
|
|
448
|
+
*/
|
|
449
|
+
assetId(e) {
|
|
450
|
+
const r = K(e);
|
|
451
|
+
return this.collection ? `${this.collection}/${r}` : r;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* @param {string} path
|
|
455
|
+
* @returns {string}
|
|
456
|
+
*/
|
|
457
|
+
assetUrl(e) {
|
|
458
|
+
return `${this.contextPath}/api/jinntap/assets/${encodeURIComponent(this.assetId(e))}`;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* @returns {Promise<AssetMeta[]>}
|
|
462
|
+
*/
|
|
463
|
+
async list() {
|
|
464
|
+
const e = `${this.contextPath}/api/jinntap/assets?collection=${encodeURIComponent(this.collection)}`, r = await fetch(e, { credentials: this.credentials });
|
|
465
|
+
if (!r.ok)
|
|
466
|
+
throw new Error(`Failed to list assets (${r.status})`);
|
|
467
|
+
const n = await r.json();
|
|
468
|
+
return Array.isArray(n) ? n : [];
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* @param {string} path
|
|
472
|
+
* @returns {Promise<StoredAsset|undefined>}
|
|
473
|
+
*/
|
|
474
|
+
async get(e) {
|
|
475
|
+
const r = await fetch(this.assetUrl(e), { credentials: this.credentials });
|
|
476
|
+
if (r.status === 404)
|
|
477
|
+
return;
|
|
478
|
+
if (!r.ok)
|
|
479
|
+
throw new Error(`Failed to get asset (${r.status})`);
|
|
480
|
+
const n = await r.blob(), a = n.type || r.headers.get("content-type") || "application/octet-stream";
|
|
481
|
+
return {
|
|
482
|
+
path: K(e),
|
|
483
|
+
blob: n,
|
|
484
|
+
mimeType: a,
|
|
485
|
+
size: n.size,
|
|
486
|
+
updatedAt: Date.now()
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @param {{ path: string, blob: Blob, mimeType?: string }} asset
|
|
491
|
+
* @returns {Promise<StoredAsset>}
|
|
492
|
+
*/
|
|
493
|
+
async put(e) {
|
|
494
|
+
const r = K(e.path), n = e.mimeType || e.blob.type || "application/octet-stream", a = await fetch(this.assetUrl(r), {
|
|
495
|
+
method: "PUT",
|
|
496
|
+
credentials: this.credentials,
|
|
497
|
+
headers: {
|
|
498
|
+
"Content-Type": n
|
|
499
|
+
},
|
|
500
|
+
body: e.blob
|
|
501
|
+
});
|
|
502
|
+
if (!a.ok)
|
|
503
|
+
throw new Error(`Failed to store asset (${a.status})`);
|
|
504
|
+
const o = await a.json().catch(() => ({}));
|
|
505
|
+
return this._revokeCached(r), {
|
|
506
|
+
path: r,
|
|
507
|
+
blob: e.blob,
|
|
508
|
+
mimeType: o.mimeType || n,
|
|
509
|
+
size: o.size ?? e.blob.size,
|
|
510
|
+
updatedAt: o.updatedAt ?? Date.now()
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* @param {string} path
|
|
515
|
+
* @returns {Promise<void>}
|
|
516
|
+
*/
|
|
517
|
+
async delete(e) {
|
|
518
|
+
const r = await fetch(this.assetUrl(e), {
|
|
519
|
+
method: "DELETE",
|
|
520
|
+
credentials: this.credentials
|
|
521
|
+
});
|
|
522
|
+
if (r.status !== 404) {
|
|
523
|
+
if (!r.ok && r.status !== 204)
|
|
524
|
+
throw new Error(`Failed to delete asset (${r.status})`);
|
|
525
|
+
this._revokeCached(K(e));
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Resolve to a displayable URL. Relative paths use the assets API (with cache-busting
|
|
530
|
+
* via object URL when already fetched is not needed — direct API URL works for <img>).
|
|
531
|
+
* @param {string} href
|
|
532
|
+
* @returns {Promise<string>}
|
|
533
|
+
*/
|
|
534
|
+
async resolve(e) {
|
|
535
|
+
const r = (e == null ? void 0 : e.trim()) ?? "";
|
|
536
|
+
return r ? ge(r) ? r : this.assetUrl(r) : "";
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* @param {string} url
|
|
540
|
+
*/
|
|
541
|
+
revoke(e) {
|
|
542
|
+
if (e != null && e.startsWith("blob:")) {
|
|
543
|
+
for (const [r, n] of this._objectUrls)
|
|
544
|
+
if (n === e) {
|
|
545
|
+
URL.revokeObjectURL(e), this._objectUrls.delete(r);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
URL.revokeObjectURL(e);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
_revokeCached(e) {
|
|
552
|
+
const r = this._objectUrls.get(e);
|
|
553
|
+
r && (URL.revokeObjectURL(r), this._objectUrls.delete(e));
|
|
554
|
+
}
|
|
555
|
+
_revokeAll() {
|
|
556
|
+
for (const e of this._objectUrls.values())
|
|
557
|
+
URL.revokeObjectURL(e);
|
|
558
|
+
this._objectUrls.clear();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function Me(t, e = "") {
|
|
562
|
+
const r = (t || "").replace(/^\/+|\/+$/g, ""), n = (e || "").replace(/^\/+|\/+$/g, "");
|
|
563
|
+
if (!r)
|
|
564
|
+
return "";
|
|
565
|
+
let a = r;
|
|
566
|
+
if (n)
|
|
567
|
+
if (r === n || r.startsWith(`${n}/`))
|
|
568
|
+
a = r === n ? "" : r.slice(n.length + 1);
|
|
569
|
+
else
|
|
570
|
+
return "";
|
|
571
|
+
return a.includes("/") ? a.split("/").slice(0, -1).join("/") : "";
|
|
572
|
+
}
|
|
573
|
+
function wt(t, { contextPath: e, docPath: r = "", dataDefaultRel: n = "" } = {}) {
|
|
574
|
+
const a = Me(r, n), o = new Je({ contextPath: e, collection: a, dataDefaultRel: n });
|
|
575
|
+
return t.assets = o, o;
|
|
576
|
+
}
|
|
577
|
+
async function pt(t, e) {
|
|
578
|
+
if (!t || !e)
|
|
579
|
+
throw new Error("attachAssetStore requires an editor and a store");
|
|
580
|
+
return typeof e.open == "function" && await e.open(), t.assets = e, e;
|
|
581
|
+
}
|
|
582
|
+
var M = Uint8Array, F = Uint16Array, be = Int32Array, ye = new M([
|
|
583
|
+
0,
|
|
584
|
+
0,
|
|
585
|
+
0,
|
|
586
|
+
0,
|
|
587
|
+
0,
|
|
588
|
+
0,
|
|
589
|
+
0,
|
|
590
|
+
0,
|
|
591
|
+
1,
|
|
592
|
+
1,
|
|
593
|
+
1,
|
|
594
|
+
1,
|
|
595
|
+
2,
|
|
596
|
+
2,
|
|
597
|
+
2,
|
|
598
|
+
2,
|
|
599
|
+
3,
|
|
600
|
+
3,
|
|
601
|
+
3,
|
|
602
|
+
3,
|
|
603
|
+
4,
|
|
604
|
+
4,
|
|
605
|
+
4,
|
|
606
|
+
4,
|
|
607
|
+
5,
|
|
608
|
+
5,
|
|
609
|
+
5,
|
|
610
|
+
5,
|
|
611
|
+
0,
|
|
612
|
+
/* unused */
|
|
613
|
+
0,
|
|
614
|
+
0,
|
|
615
|
+
/* impossible */
|
|
616
|
+
0
|
|
617
|
+
]), Ae = new M([
|
|
618
|
+
0,
|
|
619
|
+
0,
|
|
620
|
+
0,
|
|
621
|
+
0,
|
|
622
|
+
1,
|
|
623
|
+
1,
|
|
624
|
+
2,
|
|
625
|
+
2,
|
|
626
|
+
3,
|
|
627
|
+
3,
|
|
628
|
+
4,
|
|
629
|
+
4,
|
|
630
|
+
5,
|
|
631
|
+
5,
|
|
632
|
+
6,
|
|
633
|
+
6,
|
|
634
|
+
7,
|
|
635
|
+
7,
|
|
636
|
+
8,
|
|
637
|
+
8,
|
|
638
|
+
9,
|
|
639
|
+
9,
|
|
640
|
+
10,
|
|
641
|
+
10,
|
|
642
|
+
11,
|
|
643
|
+
11,
|
|
644
|
+
12,
|
|
645
|
+
12,
|
|
646
|
+
13,
|
|
647
|
+
13,
|
|
648
|
+
/* unused */
|
|
649
|
+
0,
|
|
650
|
+
0
|
|
651
|
+
]), Ee = new M([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), $e = function(t, e) {
|
|
652
|
+
for (var r = new F(31), n = 0; n < 31; ++n)
|
|
653
|
+
r[n] = e += 1 << t[n - 1];
|
|
654
|
+
for (var a = new be(r[30]), n = 1; n < 30; ++n)
|
|
655
|
+
for (var o = r[n]; o < r[n + 1]; ++o)
|
|
656
|
+
a[o] = o - r[n] << 5 | n;
|
|
657
|
+
return { b: r, r: a };
|
|
658
|
+
}, ze = $e(ye, 2), Ze = ze.b, he = ze.r;
|
|
659
|
+
Ze[28] = 258, he[258] = 28;
|
|
660
|
+
var Ye = $e(Ae, 0), Re = Ye.r, ve = new F(32768);
|
|
661
|
+
for (var b = 0; b < 32768; ++b) {
|
|
662
|
+
var X = (b & 43690) >> 1 | (b & 21845) << 1;
|
|
663
|
+
X = (X & 52428) >> 2 | (X & 13107) << 2, X = (X & 61680) >> 4 | (X & 3855) << 4, ve[b] = ((X & 65280) >> 8 | (X & 255) << 8) >> 1;
|
|
664
|
+
}
|
|
665
|
+
var Q = function(t, e, r) {
|
|
666
|
+
for (var n = t.length, a = 0, o = new F(e); a < n; ++a)
|
|
667
|
+
t[a] && ++o[t[a] - 1];
|
|
668
|
+
var s = new F(e);
|
|
669
|
+
for (a = 1; a < e; ++a)
|
|
670
|
+
s[a] = s[a - 1] + o[a - 1] << 1;
|
|
671
|
+
var l;
|
|
672
|
+
if (r) {
|
|
673
|
+
l = new F(1 << e);
|
|
674
|
+
var c = 15 - e;
|
|
675
|
+
for (a = 0; a < n; ++a)
|
|
676
|
+
if (t[a])
|
|
677
|
+
for (var h = a << 4 | t[a], i = e - t[a], f = s[t[a] - 1]++ << i, p = f | (1 << i) - 1; f <= p; ++f)
|
|
678
|
+
l[ve[f] >> c] = h;
|
|
679
|
+
} else
|
|
680
|
+
for (l = new F(n), a = 0; a < n; ++a)
|
|
681
|
+
t[a] && (l[a] = ve[s[t[a] - 1]++] >> 15 - t[a]);
|
|
682
|
+
return l;
|
|
683
|
+
}, V = new M(288);
|
|
684
|
+
for (var b = 0; b < 144; ++b)
|
|
685
|
+
V[b] = 8;
|
|
686
|
+
for (var b = 144; b < 256; ++b)
|
|
687
|
+
V[b] = 9;
|
|
688
|
+
for (var b = 256; b < 280; ++b)
|
|
689
|
+
V[b] = 7;
|
|
690
|
+
for (var b = 280; b < 288; ++b)
|
|
691
|
+
V[b] = 8;
|
|
692
|
+
var ae = new M(32);
|
|
693
|
+
for (var b = 0; b < 32; ++b)
|
|
694
|
+
ae[b] = 5;
|
|
695
|
+
var Ke = /* @__PURE__ */ Q(V, 9, 0), Qe = /* @__PURE__ */ Q(ae, 5, 0), Fe = function(t) {
|
|
696
|
+
return (t + 7) / 8 | 0;
|
|
697
|
+
}, Ie = function(t, e, r) {
|
|
698
|
+
return (r == null || r > t.length) && (r = t.length), new M(t.subarray(e, r));
|
|
699
|
+
}, et = [
|
|
700
|
+
"unexpected EOF",
|
|
701
|
+
"invalid block type",
|
|
702
|
+
"invalid length/literal",
|
|
703
|
+
"invalid distance",
|
|
704
|
+
"stream finished",
|
|
705
|
+
"no stream handler",
|
|
706
|
+
,
|
|
707
|
+
// determined by compression function
|
|
708
|
+
"no callback",
|
|
709
|
+
"invalid UTF-8 data",
|
|
710
|
+
"extra field too long",
|
|
711
|
+
"date not in range 1980-2099",
|
|
712
|
+
"filename too long",
|
|
713
|
+
"stream finishing",
|
|
714
|
+
"invalid zip data"
|
|
715
|
+
// determined by unknown compression method
|
|
716
|
+
], oe = function(t, e, r) {
|
|
717
|
+
var n = new Error(e || et[t]);
|
|
718
|
+
if (n.code = t, Error.captureStackTrace && Error.captureStackTrace(n, oe), !r)
|
|
719
|
+
throw n;
|
|
720
|
+
return n;
|
|
721
|
+
}, P = function(t, e, r) {
|
|
722
|
+
r <<= e & 7;
|
|
723
|
+
var n = e / 8 | 0;
|
|
724
|
+
t[n] |= r, t[n + 1] |= r >> 8;
|
|
725
|
+
}, Z = function(t, e, r) {
|
|
726
|
+
r <<= e & 7;
|
|
727
|
+
var n = e / 8 | 0;
|
|
728
|
+
t[n] |= r, t[n + 1] |= r >> 8, t[n + 2] |= r >> 16;
|
|
729
|
+
}, ue = function(t, e) {
|
|
730
|
+
for (var r = [], n = 0; n < t.length; ++n)
|
|
731
|
+
t[n] && r.push({ s: n, f: t[n] });
|
|
732
|
+
var a = r.length, o = r.slice();
|
|
733
|
+
if (!a)
|
|
734
|
+
return { t: Ne, l: 0 };
|
|
735
|
+
if (a == 1) {
|
|
736
|
+
var s = new M(r[0].s + 1);
|
|
737
|
+
return s[r[0].s] = 1, { t: s, l: 1 };
|
|
738
|
+
}
|
|
739
|
+
r.sort(function(j, L) {
|
|
740
|
+
return j.f - L.f;
|
|
741
|
+
}), r.push({ s: -1, f: 25001 });
|
|
742
|
+
var l = r[0], c = r[1], h = 0, i = 1, f = 2;
|
|
743
|
+
for (r[0] = { s: -1, f: l.f + c.f, l, r: c }; i != a - 1; )
|
|
744
|
+
l = r[r[h].f < r[f].f ? h++ : f++], c = r[h != i && r[h].f < r[f].f ? h++ : f++], r[i++] = { s: -1, f: l.f + c.f, l, r: c };
|
|
745
|
+
for (var p = o[0].s, n = 1; n < a; ++n)
|
|
746
|
+
o[n].s > p && (p = o[n].s);
|
|
747
|
+
var w = new F(p + 1), A = me(r[i - 1], w, 0);
|
|
748
|
+
if (A > e) {
|
|
749
|
+
var n = 0, g = 0, U = A - e, k = 1 << U;
|
|
750
|
+
for (o.sort(function(L, _) {
|
|
751
|
+
return w[_.s] - w[L.s] || L.f - _.f;
|
|
752
|
+
}); n < a; ++n) {
|
|
753
|
+
var S = o[n].s;
|
|
754
|
+
if (w[S] > e)
|
|
755
|
+
g += k - (1 << A - w[S]), w[S] = e;
|
|
756
|
+
else
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
759
|
+
for (g >>= U; g > 0; ) {
|
|
760
|
+
var $ = o[n].s;
|
|
761
|
+
w[$] < e ? g -= 1 << e - w[$]++ - 1 : ++n;
|
|
762
|
+
}
|
|
763
|
+
for (; n >= 0 && g; --n) {
|
|
764
|
+
var D = o[n].s;
|
|
765
|
+
w[D] == e && (--w[D], ++g);
|
|
766
|
+
}
|
|
767
|
+
A = e;
|
|
768
|
+
}
|
|
769
|
+
return { t: new M(w), l: A };
|
|
770
|
+
}, me = function(t, e, r) {
|
|
771
|
+
return t.s == -1 ? Math.max(me(t.l, e, r + 1), me(t.r, e, r + 1)) : e[t.s] = r;
|
|
772
|
+
}, ke = function(t) {
|
|
773
|
+
for (var e = t.length; e && !t[--e]; )
|
|
774
|
+
;
|
|
775
|
+
for (var r = new F(++e), n = 0, a = t[0], o = 1, s = function(c) {
|
|
776
|
+
r[n++] = c;
|
|
777
|
+
}, l = 1; l <= e; ++l)
|
|
778
|
+
if (t[l] == a && l != e)
|
|
779
|
+
++o;
|
|
780
|
+
else {
|
|
781
|
+
if (!a && o > 2) {
|
|
782
|
+
for (; o > 138; o -= 138)
|
|
783
|
+
s(32754);
|
|
784
|
+
o > 2 && (s(o > 10 ? o - 11 << 5 | 28690 : o - 3 << 5 | 12305), o = 0);
|
|
785
|
+
} else if (o > 3) {
|
|
786
|
+
for (s(a), --o; o > 6; o -= 6)
|
|
787
|
+
s(8304);
|
|
788
|
+
o > 2 && (s(o - 3 << 5 | 8208), o = 0);
|
|
789
|
+
}
|
|
790
|
+
for (; o--; )
|
|
791
|
+
s(a);
|
|
792
|
+
o = 1, a = t[l];
|
|
793
|
+
}
|
|
794
|
+
return { c: r.subarray(0, n), n: e };
|
|
795
|
+
}, Y = function(t, e) {
|
|
796
|
+
for (var r = 0, n = 0; n < e.length; ++n)
|
|
797
|
+
r += t[n] * e[n];
|
|
798
|
+
return r;
|
|
799
|
+
}, Oe = function(t, e, r) {
|
|
800
|
+
var n = r.length, a = Fe(e + 2);
|
|
801
|
+
t[a] = n & 255, t[a + 1] = n >> 8, t[a + 2] = t[a] ^ 255, t[a + 3] = t[a + 1] ^ 255;
|
|
802
|
+
for (var o = 0; o < n; ++o)
|
|
803
|
+
t[a + o + 4] = r[o];
|
|
804
|
+
return (a + 4 + n) * 8;
|
|
805
|
+
}, je = function(t, e, r, n, a, o, s, l, c, h, i) {
|
|
806
|
+
P(e, i++, r), ++a[256];
|
|
807
|
+
for (var f = ue(a, 15), p = f.t, w = f.l, A = ue(o, 15), g = A.t, U = A.l, k = ke(p), S = k.c, $ = k.n, D = ke(g), j = D.c, L = D.n, _ = new F(19), d = 0; d < S.length; ++d)
|
|
808
|
+
++_[S[d] & 31];
|
|
809
|
+
for (var d = 0; d < j.length; ++d)
|
|
810
|
+
++_[j[d] & 31];
|
|
811
|
+
for (var m = ue(_, 7), u = m.t, v = m.l, y = 19; y > 4 && !u[Ee[y - 1]]; --y)
|
|
812
|
+
;
|
|
813
|
+
var x = h + 5 << 3, T = Y(a, V) + Y(o, ae) + s, z = Y(a, p) + Y(o, g) + s + 14 + 3 * y + Y(_, u) + 2 * _[16] + 3 * _[17] + 7 * _[18];
|
|
814
|
+
if (c >= 0 && x <= T && x <= z)
|
|
815
|
+
return Oe(e, i, t.subarray(c, c + h));
|
|
816
|
+
var O, E, I, q;
|
|
817
|
+
if (P(e, i, 1 + (z < T)), i += 2, z < T) {
|
|
818
|
+
O = Q(p, w, 0), E = p, I = Q(g, U, 0), q = g;
|
|
819
|
+
var se = Q(u, v, 0);
|
|
820
|
+
P(e, i, $ - 257), P(e, i + 5, L - 1), P(e, i + 10, y - 4), i += 14;
|
|
821
|
+
for (var d = 0; d < y; ++d)
|
|
822
|
+
P(e, i + 3 * d, u[Ee[d]]);
|
|
823
|
+
i += 3 * y;
|
|
824
|
+
for (var N = [S, j], J = 0; J < 2; ++J)
|
|
825
|
+
for (var W = N[J], d = 0; d < W.length; ++d) {
|
|
826
|
+
var B = W[d] & 31;
|
|
827
|
+
P(e, i, se[B]), i += u[B], B > 15 && (P(e, i, W[d] >> 5 & 127), i += W[d] >> 12);
|
|
828
|
+
}
|
|
829
|
+
} else
|
|
830
|
+
O = Ke, E = V, I = Qe, q = ae;
|
|
831
|
+
for (var d = 0; d < l; ++d) {
|
|
832
|
+
var C = n[d];
|
|
833
|
+
if (C > 255) {
|
|
834
|
+
var B = C >> 18 & 31;
|
|
835
|
+
Z(e, i, O[B + 257]), i += E[B + 257], B > 7 && (P(e, i, C >> 23 & 31), i += ye[B]);
|
|
836
|
+
var G = C & 31;
|
|
837
|
+
Z(e, i, I[G]), i += q[G], G > 3 && (Z(e, i, C >> 5 & 8191), i += Ae[G]);
|
|
838
|
+
} else
|
|
839
|
+
Z(e, i, O[C]), i += E[C];
|
|
840
|
+
}
|
|
841
|
+
return Z(e, i, O[256]), i + E[256];
|
|
842
|
+
}, tt = /* @__PURE__ */ new be([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), Ne = /* @__PURE__ */ new M(0), rt = function(t, e, r, n, a, o) {
|
|
843
|
+
var s = o.z || t.length, l = new M(n + s + 5 * (1 + Math.ceil(s / 7e3)) + a), c = l.subarray(n, l.length - a), h = o.l, i = (o.r || 0) & 7;
|
|
844
|
+
if (e) {
|
|
845
|
+
i && (c[0] = o.r >> 3);
|
|
846
|
+
for (var f = tt[e - 1], p = f >> 13, w = f & 8191, A = (1 << r) - 1, g = o.p || new F(32768), U = o.h || new F(A + 1), k = Math.ceil(r / 3), S = 2 * k, $ = function(ce) {
|
|
847
|
+
return (t[ce] ^ t[ce + 1] << k ^ t[ce + 2] << S) & A;
|
|
848
|
+
}, D = new be(25e3), j = new F(288), L = new F(32), _ = 0, d = 0, m = o.i || 0, u = 0, v = o.w || 0, y = 0; m + 2 < s; ++m) {
|
|
849
|
+
var x = $(m), T = m & 32767, z = U[x];
|
|
850
|
+
if (g[T] = z, U[x] = T, v <= m) {
|
|
851
|
+
var O = s - m;
|
|
852
|
+
if ((_ > 7e3 || u > 24576) && (O > 423 || !h)) {
|
|
853
|
+
i = je(t, c, 0, D, j, L, d, u, y, m - y, i), u = _ = d = 0, y = m;
|
|
854
|
+
for (var E = 0; E < 286; ++E)
|
|
855
|
+
j[E] = 0;
|
|
856
|
+
for (var E = 0; E < 30; ++E)
|
|
857
|
+
L[E] = 0;
|
|
858
|
+
}
|
|
859
|
+
var I = 2, q = 0, se = w, N = T - z & 32767;
|
|
860
|
+
if (O > 2 && x == $(m - N))
|
|
861
|
+
for (var J = Math.min(p, O) - 1, W = Math.min(32767, m), B = Math.min(258, O); N <= W && --se && T != z; ) {
|
|
862
|
+
if (t[m + I] == t[m + I - N]) {
|
|
863
|
+
for (var C = 0; C < B && t[m + C] == t[m + C - N]; ++C)
|
|
864
|
+
;
|
|
865
|
+
if (C > I) {
|
|
866
|
+
if (I = C, q = N, C > J)
|
|
867
|
+
break;
|
|
868
|
+
for (var G = Math.min(N, C - 2), Ue = 0, E = 0; E < G; ++E) {
|
|
869
|
+
var ie = m - N + E & 32767, Xe = g[ie], _e = ie - Xe & 32767;
|
|
870
|
+
_e > Ue && (Ue = _e, z = ie);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
T = z, z = g[T], N += T - z & 32767;
|
|
875
|
+
}
|
|
876
|
+
if (q) {
|
|
877
|
+
D[u++] = 268435456 | he[I] << 18 | Re[q];
|
|
878
|
+
var De = he[I] & 31, Se = Re[q] & 31;
|
|
879
|
+
d += ye[De] + Ae[Se], ++j[257 + De], ++L[Se], v = m + I, ++_;
|
|
880
|
+
} else
|
|
881
|
+
D[u++] = t[m], ++j[t[m]];
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
for (m = Math.max(m, v); m < s; ++m)
|
|
885
|
+
D[u++] = t[m], ++j[t[m]];
|
|
886
|
+
i = je(t, c, h, D, j, L, d, u, y, m - y, i), h || (o.r = i & 7 | c[i / 8 | 0] << 3, i -= 7, o.h = U, o.p = g, o.i = m, o.w = v);
|
|
887
|
+
} else {
|
|
888
|
+
for (var m = o.w || 0; m < s + h; m += 65535) {
|
|
889
|
+
var le = m + 65535;
|
|
890
|
+
le >= s && (c[i / 8 | 0] = h, le = s), i = Oe(c, i + 1, t.subarray(m, le));
|
|
891
|
+
}
|
|
892
|
+
o.i = s;
|
|
893
|
+
}
|
|
894
|
+
return Ie(l, 0, n + Fe(i) + a);
|
|
895
|
+
}, nt = /* @__PURE__ */ function() {
|
|
896
|
+
for (var t = new Int32Array(256), e = 0; e < 256; ++e) {
|
|
897
|
+
for (var r = e, n = 9; --n; )
|
|
898
|
+
r = (r & 1 && -306674912) ^ r >>> 1;
|
|
899
|
+
t[e] = r;
|
|
900
|
+
}
|
|
901
|
+
return t;
|
|
902
|
+
}(), at = function() {
|
|
903
|
+
var t = -1;
|
|
904
|
+
return {
|
|
905
|
+
p: function(e) {
|
|
906
|
+
for (var r = t, n = 0; n < e.length; ++n)
|
|
907
|
+
r = nt[r & 255 ^ e[n]] ^ r >>> 8;
|
|
908
|
+
t = r;
|
|
909
|
+
},
|
|
910
|
+
d: function() {
|
|
911
|
+
return ~t;
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}, ot = function(t, e, r, n, a) {
|
|
915
|
+
if (!a && (a = { l: 1 }, e.dictionary)) {
|
|
916
|
+
var o = e.dictionary.subarray(-32768), s = new M(o.length + t.length);
|
|
917
|
+
s.set(o), s.set(t, o.length), t = s, a.w = o.length;
|
|
918
|
+
}
|
|
919
|
+
return rt(t, e.level == null ? 6 : e.level, e.mem == null ? a.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(t.length))) * 1.5) : 20 : 12 + e.mem, r, n, a);
|
|
920
|
+
}, Be = function(t, e) {
|
|
921
|
+
var r = {};
|
|
922
|
+
for (var n in t)
|
|
923
|
+
r[n] = t[n];
|
|
924
|
+
for (var n in e)
|
|
925
|
+
r[n] = e[n];
|
|
926
|
+
return r;
|
|
927
|
+
}, R = function(t, e, r) {
|
|
928
|
+
for (; r; ++e)
|
|
929
|
+
t[e] = r, r >>>= 8;
|
|
930
|
+
};
|
|
931
|
+
function st(t, e) {
|
|
932
|
+
return ot(t, e || {}, 0, 0);
|
|
933
|
+
}
|
|
934
|
+
var Pe = function(t, e, r, n) {
|
|
935
|
+
for (var a in t) {
|
|
936
|
+
var o = t[a], s = e + a, l = n;
|
|
937
|
+
Array.isArray(o) && (l = Be(n, o[1]), o = o[0]), ArrayBuffer.isView(o) ? r[s] = [o, l] : (r[s += "/"] = [new M(0), l], Pe(o, s, r, n));
|
|
938
|
+
}
|
|
939
|
+
}, Le = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), it = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), lt = 0;
|
|
940
|
+
try {
|
|
941
|
+
it.decode(Ne, { stream: !0 }), lt = 1;
|
|
942
|
+
} catch {
|
|
943
|
+
}
|
|
944
|
+
function de(t, e) {
|
|
945
|
+
var r;
|
|
946
|
+
if (Le)
|
|
947
|
+
return Le.encode(t);
|
|
948
|
+
for (var n = t.length, a = new M(t.length + (t.length >> 1)), o = 0, s = function(h) {
|
|
949
|
+
a[o++] = h;
|
|
950
|
+
}, r = 0; r < n; ++r) {
|
|
951
|
+
if (o + 5 > a.length) {
|
|
952
|
+
var l = new M(o + 8 + (n - r << 1));
|
|
953
|
+
l.set(a), a = l;
|
|
954
|
+
}
|
|
955
|
+
var c = t.charCodeAt(r);
|
|
956
|
+
c < 128 || e ? s(c) : c < 2048 ? (s(192 | c >> 6), s(128 | c & 63)) : c > 55295 && c < 57344 ? (c = 65536 + (c & 1047552) | t.charCodeAt(++r) & 1023, s(240 | c >> 18), s(128 | c >> 12 & 63), s(128 | c >> 6 & 63), s(128 | c & 63)) : (s(224 | c >> 12), s(128 | c >> 6 & 63), s(128 | c & 63));
|
|
957
|
+
}
|
|
958
|
+
return Ie(a, 0, o);
|
|
959
|
+
}
|
|
960
|
+
var we = function(t) {
|
|
961
|
+
var e = 0;
|
|
962
|
+
if (t)
|
|
963
|
+
for (var r in t) {
|
|
964
|
+
var n = t[r].length;
|
|
965
|
+
n > 65535 && oe(9), e += n + 4;
|
|
966
|
+
}
|
|
967
|
+
return e;
|
|
968
|
+
}, xe = function(t, e, r, n, a, o, s, l) {
|
|
969
|
+
var c = n.length, h = r.extra, i = l && l.length, f = we(h);
|
|
970
|
+
R(t, e, s != null ? 33639248 : 67324752), e += 4, s != null && (t[e++] = 20, t[e++] = r.os), t[e] = 20, e += 2, t[e++] = r.flag << 1 | (o < 0 && 8), t[e++] = a && 8, t[e++] = r.compression & 255, t[e++] = r.compression >> 8;
|
|
971
|
+
var p = new Date(r.mtime == null ? Date.now() : r.mtime), w = p.getFullYear() - 1980;
|
|
972
|
+
if ((w < 0 || w > 119) && oe(10), R(t, e, w << 25 | p.getMonth() + 1 << 21 | p.getDate() << 16 | p.getHours() << 11 | p.getMinutes() << 5 | p.getSeconds() >> 1), e += 4, o != -1 && (R(t, e, r.crc), R(t, e + 4, o < 0 ? -o - 2 : o), R(t, e + 8, r.size)), R(t, e + 12, c), R(t, e + 14, f), e += 16, s != null && (R(t, e, i), R(t, e + 6, r.attrs), R(t, e + 10, s), e += 14), t.set(n, e), e += c, f)
|
|
973
|
+
for (var A in h) {
|
|
974
|
+
var g = h[A], U = g.length;
|
|
975
|
+
R(t, e, +A), R(t, e + 2, U), t.set(g, e + 4), e += 4 + U;
|
|
976
|
+
}
|
|
977
|
+
return i && (t.set(l, e), e += i), e;
|
|
978
|
+
}, ct = function(t, e, r, n, a) {
|
|
979
|
+
R(t, e, 101010256), R(t, e + 8, r), R(t, e + 10, r), R(t, e + 12, n), R(t, e + 16, a);
|
|
980
|
+
};
|
|
981
|
+
function ut(t, e) {
|
|
982
|
+
e || (e = {});
|
|
983
|
+
var r = {}, n = [];
|
|
984
|
+
Pe(t, "", r, e);
|
|
985
|
+
var a = 0, o = 0;
|
|
986
|
+
for (var s in r) {
|
|
987
|
+
var l = r[s], c = l[0], h = l[1], i = h.level == 0 ? 0 : 8, f = de(s), p = f.length, w = h.comment, A = w && de(w), g = A && A.length, U = we(h.extra);
|
|
988
|
+
p > 65535 && oe(11);
|
|
989
|
+
var k = i ? st(c, h) : c, S = k.length, $ = at();
|
|
990
|
+
$.p(c), n.push(Be(h, {
|
|
991
|
+
size: c.length,
|
|
992
|
+
crc: $.d(),
|
|
993
|
+
c: k,
|
|
994
|
+
f,
|
|
995
|
+
m: A,
|
|
996
|
+
u: p != s.length || A && w.length != g,
|
|
997
|
+
o: a,
|
|
998
|
+
compression: i
|
|
999
|
+
})), a += 30 + p + U + S, o += 76 + 2 * (p + U) + (g || 0) + S;
|
|
1000
|
+
}
|
|
1001
|
+
for (var D = new M(o + 22), j = a, L = o - a, _ = 0; _ < n.length; ++_) {
|
|
1002
|
+
var f = n[_];
|
|
1003
|
+
xe(D, f.o, f, f.f, f.u, f.c.length);
|
|
1004
|
+
var d = 30 + f.f.length + we(f.extra);
|
|
1005
|
+
D.set(f.c, f.o + d), xe(D, a, f, f.f, f.u, f.c.length, f.o, f.m), a += 16 + d + (f.m ? f.m.length : 0);
|
|
1006
|
+
}
|
|
1007
|
+
return ct(D, a, n.length, L, j), D;
|
|
1008
|
+
}
|
|
1009
|
+
function ft(t) {
|
|
1010
|
+
var e;
|
|
1011
|
+
if (!t || typeof t != "string")
|
|
1012
|
+
return [];
|
|
1013
|
+
try {
|
|
1014
|
+
const r = new DOMParser().parseFromString(t, "application/xml");
|
|
1015
|
+
if (r.querySelector("parsererror"))
|
|
1016
|
+
return [];
|
|
1017
|
+
const n = /* @__PURE__ */ new Set(), a = [];
|
|
1018
|
+
for (const o of r.getElementsByTagName("*"))
|
|
1019
|
+
for (const s of ["url", "href"]) {
|
|
1020
|
+
let l = null;
|
|
1021
|
+
s === "href" ? l = ((e = o.getAttributeNS) == null ? void 0 : e.call(o, "http://www.w3.org/1999/xlink", "href")) || o.getAttribute("xlink:href") || o.getAttribute("href") : l = o.getAttribute(s);
|
|
1022
|
+
const c = l == null ? void 0 : l.trim();
|
|
1023
|
+
!c || ge(c) || n.has(c) || (n.add(c), a.push(c));
|
|
1024
|
+
}
|
|
1025
|
+
return a;
|
|
1026
|
+
} catch {
|
|
1027
|
+
return [];
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
async function gt(t, e) {
|
|
1031
|
+
if (!(e != null && e.get))
|
|
1032
|
+
return [];
|
|
1033
|
+
const r = ft(t), n = [];
|
|
1034
|
+
for (const a of r) {
|
|
1035
|
+
const o = await e.get(a);
|
|
1036
|
+
o != null && o.blob && n.push(o);
|
|
1037
|
+
}
|
|
1038
|
+
return n;
|
|
1039
|
+
}
|
|
1040
|
+
function qe(t, e) {
|
|
1041
|
+
const r = URL.createObjectURL(t), n = document.createElement("a");
|
|
1042
|
+
n.href = r, n.download = e, document.body.appendChild(n), n.click(), document.body.removeChild(n), URL.revokeObjectURL(r);
|
|
1043
|
+
}
|
|
1044
|
+
function ht(t) {
|
|
1045
|
+
return `${(t || "document.xml").replace(/\.xml$/i, "") || "document"}.zip`;
|
|
1046
|
+
}
|
|
1047
|
+
function bt(t, e = "document.xml") {
|
|
1048
|
+
const r = new Blob([t], { type: "application/xml" });
|
|
1049
|
+
qe(r, e);
|
|
1050
|
+
}
|
|
1051
|
+
async function vt(t, e, r = "document.xml") {
|
|
1052
|
+
const n = {
|
|
1053
|
+
[r]: de(t)
|
|
1054
|
+
};
|
|
1055
|
+
for (const s of e) {
|
|
1056
|
+
const l = s.path.replace(/^\/+/, "");
|
|
1057
|
+
!l || l === r || (n[l] = new Uint8Array(await s.blob.arrayBuffer()));
|
|
1058
|
+
}
|
|
1059
|
+
const a = ut(n, { level: 6 }), o = new Uint8Array(a.byteLength);
|
|
1060
|
+
return o.set(a), new Blob([o.buffer], { type: "application/zip" });
|
|
1061
|
+
}
|
|
1062
|
+
async function yt(t, e, r = "document.xml") {
|
|
1063
|
+
const n = await vt(t, e, r);
|
|
1064
|
+
qe(n, ht(r));
|
|
1065
|
+
}
|
|
1066
|
+
export {
|
|
1067
|
+
Ve as DocumentStore,
|
|
1068
|
+
Je as HttpAssetStore,
|
|
1069
|
+
dt as IndexedDbAssetStore,
|
|
1070
|
+
pt as attachAssetStore,
|
|
1071
|
+
mt as attachLocalStore,
|
|
1072
|
+
wt as attachPublisherAssetStore,
|
|
1073
|
+
vt as buildDocumentZip,
|
|
1074
|
+
gt as collectReferencedAssets,
|
|
1075
|
+
Me as collectionFromDocPath,
|
|
1076
|
+
Te as deduceDocumentName,
|
|
1077
|
+
yt as downloadDocumentZip,
|
|
1078
|
+
bt as downloadXml,
|
|
1079
|
+
Ge as extractTitleFromXml,
|
|
1080
|
+
ft as findReferencedAssetPaths,
|
|
1081
|
+
ge as isAbsoluteAssetHref,
|
|
1082
|
+
ee as isGenericTitle,
|
|
1083
|
+
fe as isProvisionalTitle,
|
|
1084
|
+
K as sanitizeAssetPath,
|
|
1085
|
+
qe as triggerDownload,
|
|
1086
|
+
te as truncateTitle,
|
|
1087
|
+
ht as zipFilenameForXml
|
|
1088
|
+
};
|
|
1089
|
+
//# sourceMappingURL=storage.es.js.map
|