rayzee 10.0.0 → 11.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 +252 -44
- package/dist/ActiveColor-YvuQq44O.js +13 -0
- package/dist/ArchiveImporter-BRQvLggb.js +4300 -0
- package/dist/AssetConfig-DSEntE65.js +30 -0
- package/dist/BidirectionalIntegrator-9lZQxFVH.js +934 -0
- package/dist/BufferLayout-D_IBo2ci.js +150 -0
- package/dist/ColorManagement-oeEk7oSu.js +1488 -0
- package/dist/EngineEvents-Ci8dVWCP.js +73 -0
- package/dist/EngineIssues-CIZnXHsF.js +72 -0
- package/dist/FileFormats-sPGJeCRc.js +102 -0
- package/dist/Logger-dDDGj9Av.js +97 -0
- package/dist/{NeuralRetouch-CYgkQY8Z.js → NeuralRetouch-BCXylThH.js} +8 -6
- package/dist/{NeuralSuperRes-PkgDLQcD.js → NeuralSuperRes-sZAeS142.js} +55 -120
- package/dist/PathTracer-CQPW06Mm.js +29971 -0
- package/dist/PhysicalSky-BvqCw_dy.js +1219 -0
- package/dist/RayzeeRenderer-COpwotpU.js +3551 -0
- package/dist/SolarLimb-CPaeZVwz.js +721 -0
- package/dist/ToneMapGPU-CjU3osDd.js +177 -0
- package/dist/ViewTransforms-CYN7bq2w.js +255 -0
- package/dist/WorkingMatrix-C6y233hT.js +27 -0
- package/dist/ZipReader-gDSWr0I5.js +98 -0
- package/dist/addons/archives.es.js +3 -0
- package/dist/addons/bidirectional.es.js +2 -0
- package/dist/addons/color.es.js +3 -0
- package/dist/addons/formats.es.js +2 -0
- package/dist/addons/physical-sky.es.js +2 -0
- package/dist/addons/storage.es.js +3 -0
- package/dist/archiveFormats-BZw7TiDp.js +75 -0
- package/dist/identity-DrQsGT2o.js +39 -0
- package/dist/openStorage-DwcBRUj7.js +820 -0
- package/dist/rayzee-core.es.js +12 -0
- package/dist/rayzee.es.js +2551 -44024
- package/dist/rayzee.umd.js +528 -487
- package/dist/sceneCachePolicy-BSSsKY98.js +443 -0
- package/dist/shared-BGBcSxBQ.js +17 -0
- package/package.json +23 -2
- package/src/Color/ActiveColor.js +34 -0
- package/src/Color/BasicColor.js +147 -0
- package/src/Color/ColorManagement.js +7 -31
- package/src/Color/ViewTransforms.js +5 -1
- package/src/EngineDefaults.js +62 -1029
- package/src/EngineEvents.js +2 -0
- package/src/EngineIssues.js +2 -0
- package/src/Headless.js +6 -5
- package/src/Passes/AIUpscaler.js +58 -141
- package/src/Passes/OIDNDenoiser.js +92 -65
- package/src/Passes/OIDNTemporalHistory.js +1 -1
- package/src/PathTracerApp.js +620 -4026
- package/src/Pipeline/PipelineContext.js +0 -4
- package/src/Platform.js +36 -0
- package/src/Processor/ArchiveCache.js +1 -1
- package/src/Processor/ArchiveImporter.js +1259 -0
- package/src/Processor/AssetLoader.js +327 -1763
- package/src/Processor/AtmosphereModel.js +1 -2
- package/src/Processor/BVHBuilder.js +14 -126
- package/src/Processor/BVHLeafFold.js +4 -6
- package/src/Processor/BVHRefitter.js +67 -46
- package/src/Processor/BufferLayout.js +291 -0
- package/src/Processor/EmissiveTriangleBuilder.js +1 -1
- package/src/Processor/EnvironmentExactTable.js +187 -0
- package/src/Processor/EquirectHDRInfo.js +30 -223
- package/src/Processor/FileFormats.js +116 -0
- package/src/Processor/GLTFDecoders.js +85 -0
- package/src/Processor/GLTFDiffuseTransmission.js +63 -0
- package/src/Processor/GeometryExtractor.js +15 -5
- package/src/Processor/HostMemory.js +7 -1
- package/src/Processor/IESParser.js +47 -35
- package/src/Processor/InstanceTable.js +1 -1
- package/src/Processor/KernelManager.js +35 -2
- package/src/Processor/MaterialPacking.js +10 -8
- package/src/Processor/PBRT/PBRTMaterials.js +129 -41
- package/src/Processor/PBRT/PBRTParser.js +30 -17
- package/src/Processor/PBRT/PBRTSceneBuilder.js +548 -37
- package/src/Processor/PBRT/PBRTTextureBake.js +154 -0
- package/src/Processor/PBRT/PFM.js +59 -0
- package/src/Processor/PackedRayBuffer.js +116 -9
- package/src/Processor/ParallelBVHBuilder.js +3 -6
- package/src/Processor/PhysicalSky.js +5 -4
- package/src/Processor/PlatformImageLoader.js +50 -6
- package/src/Processor/QueueManager.js +39 -5
- package/src/Processor/ReinsertionOptimizer.js +2 -2
- package/src/Processor/SceneProcessor.js +53 -62
- package/src/Processor/ShaderBuilder.js +6 -16
- package/src/Processor/SimpleSky.js +1 -62
- package/src/Processor/SolarLimb.js +3 -0
- package/src/Processor/SplitBLAS.js +1 -1
- package/src/Processor/StorageTexturePool.js +22 -1
- package/src/Processor/TLASBuilder.js +1 -3
- package/src/Processor/TextureBuckets.js +237 -0
- package/src/Processor/TextureCreator.js +181 -8
- package/src/Processor/ToneMapGPU.js +64 -15
- package/src/Processor/Workers/BVHRefitWorker.js +5 -2
- package/src/Processor/Workers/BVHSubtreeWorker.js +1 -34
- package/src/Processor/Workers/BVHWorker.js +5 -18
- package/src/Processor/Workers/CDFWorker.js +6 -183
- package/src/Processor/Workers/TexturesWorker.js +103 -18
- package/src/Processor/archiveFormats.js +7 -0
- package/src/Processor/utils.js +2 -1
- package/src/RayzeeRenderer.js +3899 -0
- package/src/RenderSettings.js +68 -62
- package/src/Stages/ASVGF.js +13 -14
- package/src/Stages/AutoExposure.js +17 -17
- package/src/Stages/BilateralFilter.js +2 -1
- package/src/Stages/Compositor.js +8 -23
- package/src/Stages/DenoiserSettings.js +182 -0
- package/src/Stages/EdgeFilter.js +2 -1
- package/src/Stages/MotionVector.js +1 -1
- package/src/Stages/NRD.js +11 -5
- package/src/Stages/NormalDepth.js +12 -8
- package/src/Stages/PathTracer.js +338 -43
- package/src/Stages/PathTracerStage.js +69 -66
- package/src/Stages/Variance.js +1 -1
- package/src/Storage/BLASCache.js +1 -1
- package/src/Storage/CDFCache.js +18 -17
- package/src/Storage/DownloadCache.js +1 -1
- package/src/Storage/SceneGraphCodec.js +46 -3
- package/src/Storage/SpillStore.js +1 -1
- package/src/Storage/StorageManager.js +45 -9
- package/src/Storage/areas.js +4 -0
- package/src/TSL/BVHTraversal.js +50 -25
- package/src/TSL/Bidirectional.js +204 -0
- package/src/TSL/BidirectionalLamps.js +132 -0
- package/src/TSL/Clearcoat.js +15 -6
- package/src/TSL/Common.js +20 -15
- package/src/TSL/ConnectKernel.js +147 -0
- package/src/TSL/Debugger.js +1 -1
- package/src/TSL/Displacement.js +4 -3
- package/src/TSL/EmissiveSampling.js +65 -18
- package/src/TSL/Environment.js +77 -106
- package/src/TSL/EnvironmentCDF.js +85 -39
- package/src/TSL/ExtendKernel.js +8 -3
- package/src/TSL/FinalWriteKernel.js +4 -4
- package/src/TSL/GenerateKernel.js +18 -4
- package/src/TSL/HitFacet.js +35 -5
- package/src/TSL/LightBVHSampling.js +40 -9
- package/src/TSL/LightGenerateKernel.js +293 -0
- package/src/TSL/LightGuide.js +198 -0
- package/src/TSL/LightSplatKernel.js +165 -0
- package/src/TSL/LightVisibility.js +111 -0
- package/src/TSL/LightsCore.js +13 -38
- package/src/TSL/LightsDirect.js +28 -29
- package/src/TSL/LightsIndirect.js +3 -1
- package/src/TSL/LightsSampling.js +239 -51
- package/src/TSL/MaterialEvaluation.js +113 -31
- package/src/TSL/MaterialProperties.js +44 -17
- package/src/TSL/MaterialTransmission.js +52 -47
- package/src/TSL/MergeKernel.js +218 -0
- package/src/TSL/PathTracerCore.js +65 -29
- package/src/TSL/Random.js +5 -1
- package/src/TSL/SceneResources.js +51 -0
- package/src/TSL/ShadeKernel.js +964 -101
- package/src/TSL/Struct.js +10 -0
- package/src/TSL/Sun.js +1 -1
- package/src/TSL/TextureSampling.js +66 -61
- package/src/addons/archives.js +14 -0
- package/src/addons/bidirectional.js +13 -0
- package/src/addons/color.js +32 -0
- package/src/addons/formats.js +16 -0
- package/src/addons/physicalSky.js +14 -0
- package/src/addons/storage.js +19 -0
- package/src/core.js +31 -0
- package/src/index.js +13 -23
- package/src/integrators/BidirectionalIntegrator.js +833 -0
- package/src/managers/AnimationManager.js +88 -6
- package/src/managers/CameraManager.js +103 -46
- package/src/managers/DenoisingManager.js +14 -10
- package/src/managers/EnvironmentManager.js +125 -103
- package/src/managers/GoboManager.js +9 -0
- package/src/managers/MaterialDataManager.js +48 -37
- package/src/managers/UniformManager.js +32 -10
- package/dist/ToneMapGPU-B6XIe3DU.js +0 -544
- package/dist/rolldown-runtime-CAFD8bLK.js +0 -11
- package/src/Processor/TreeletOptimizer.js +0 -574
|
@@ -0,0 +1,820 @@
|
|
|
1
|
+
import { n as e } from "./EngineIssues-CIZnXHsF.js";
|
|
2
|
+
import { i as t, r as n, t as r } from "./shared-BGBcSxBQ.js";
|
|
3
|
+
import { t as i } from "./identity-DrQsGT2o.js";
|
|
4
|
+
//#region src/Storage/locks.js
|
|
5
|
+
var a = /* @__PURE__ */ new Map();
|
|
6
|
+
function o(e, t) {
|
|
7
|
+
return e.exclusive || t === "exclusive" && e.shared > 0 ? !1 : (t === "exclusive" ? e.exclusive = !0 : e.shared++, !0);
|
|
8
|
+
}
|
|
9
|
+
function s(e, t, n) {
|
|
10
|
+
let r = a.get(e);
|
|
11
|
+
r || (r = {
|
|
12
|
+
shared: 0,
|
|
13
|
+
exclusive: !1,
|
|
14
|
+
queue: []
|
|
15
|
+
}, a.set(e, r));
|
|
16
|
+
let i = c(() => {
|
|
17
|
+
for (t === "exclusive" ? r.exclusive = !1 : r.shared--; r.queue.length && o(r, r.queue[0].mode);) r.queue.shift().grant();
|
|
18
|
+
!r.exclusive && r.shared === 0 && r.queue.length === 0 && a.delete(e);
|
|
19
|
+
});
|
|
20
|
+
return r.queue.length === 0 && o(r, t) ? Promise.resolve(i) : n ? (!r.exclusive && r.shared === 0 && r.queue.length === 0 && a.delete(e), Promise.resolve(null)) : new Promise((e) => r.queue.push({
|
|
21
|
+
mode: t,
|
|
22
|
+
grant: () => e(i)
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function c(e) {
|
|
26
|
+
let t = !1;
|
|
27
|
+
return () => {
|
|
28
|
+
t || (t = !0, e());
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var l = () => typeof navigator < "u" && navigator.locks?.request ? navigator.locks : null;
|
|
32
|
+
function u(e, { mode: t = "exclusive", ifAvailable: n = !1 } = {}) {
|
|
33
|
+
let r = l();
|
|
34
|
+
return r ? new Promise((i, a) => {
|
|
35
|
+
r.request(e, {
|
|
36
|
+
mode: t,
|
|
37
|
+
ifAvailable: n
|
|
38
|
+
}, (e) => {
|
|
39
|
+
if (!e) {
|
|
40
|
+
i(null);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return new Promise((e) => i(c(e)));
|
|
44
|
+
}).catch(a);
|
|
45
|
+
}) : s(e, t, n);
|
|
46
|
+
}
|
|
47
|
+
async function d() {
|
|
48
|
+
let e = l();
|
|
49
|
+
if (!e) return new Set(a.keys());
|
|
50
|
+
let { held: t = [] } = await e.query();
|
|
51
|
+
return new Set(t.map((e) => e.name));
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/Storage/events.js
|
|
55
|
+
var f = class {
|
|
56
|
+
constructor() {
|
|
57
|
+
this._handlers = /* @__PURE__ */ new Map();
|
|
58
|
+
}
|
|
59
|
+
addEventListener(e, t) {
|
|
60
|
+
this._handlers.has(e) || this._handlers.set(e, /* @__PURE__ */ new Set()), this._handlers.get(e).add(t);
|
|
61
|
+
}
|
|
62
|
+
removeEventListener(e, t) {
|
|
63
|
+
this._handlers.get(e)?.delete(t);
|
|
64
|
+
}
|
|
65
|
+
dispatchEvent(e) {
|
|
66
|
+
for (let t of [...this._handlers.get(e.type) ?? []]) t.call(this, e);
|
|
67
|
+
}
|
|
68
|
+
}, p = class {
|
|
69
|
+
constructor(e) {
|
|
70
|
+
this._root = e, this._writers = /* @__PURE__ */ new Map(), this._nextId = 1;
|
|
71
|
+
}
|
|
72
|
+
async _dir(e, t) {
|
|
73
|
+
let n = await this._root;
|
|
74
|
+
for (let r of e) n = await n.getDirectoryHandle(r, { create: t });
|
|
75
|
+
return n;
|
|
76
|
+
}
|
|
77
|
+
async openWriter({ path: e, name: t, truncate: n = !0, length: r }) {
|
|
78
|
+
let i = await (await (await this._dir(e, !0)).getFileHandle(t, { create: !0 })).createSyncAccessHandle();
|
|
79
|
+
n ? i.truncate(0) : r !== void 0 && i.getSize() > r && i.truncate(r);
|
|
80
|
+
let a = this._nextId++;
|
|
81
|
+
return this._writers.set(a, {
|
|
82
|
+
handle: i,
|
|
83
|
+
end: i.getSize()
|
|
84
|
+
}), { id: a };
|
|
85
|
+
}
|
|
86
|
+
write({ id: e, buffer: t, byteOffset: n = 0, byteLength: r, at: i }) {
|
|
87
|
+
let a = this._writers.get(e);
|
|
88
|
+
if (!a) throw Error(`storage: writer ${e} is not open`);
|
|
89
|
+
let o = new Uint8Array(t, n, r ?? t.byteLength - n), s = i ?? a.end, c = 0;
|
|
90
|
+
for (; c < o.length;) {
|
|
91
|
+
let e = a.handle.write(o.subarray(c), { at: s + c });
|
|
92
|
+
if (e <= 0) throw Error("storage: write made no progress");
|
|
93
|
+
c += e;
|
|
94
|
+
}
|
|
95
|
+
return a.end = Math.max(a.end, s + o.length), { bytes: o.length };
|
|
96
|
+
}
|
|
97
|
+
closeWriter({ id: e, abort: t = !1 }) {
|
|
98
|
+
let n = this._writers.get(e);
|
|
99
|
+
if (!n) return { size: 0 };
|
|
100
|
+
this._writers.delete(e);
|
|
101
|
+
try {
|
|
102
|
+
return t || n.handle.flush(), { size: n.handle.getSize() };
|
|
103
|
+
} finally {
|
|
104
|
+
n.handle.close();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async writeFile({ path: e, name: t, buffer: n, byteOffset: r = 0, byteLength: i }) {
|
|
108
|
+
let { id: a } = await this.openWriter({
|
|
109
|
+
path: e,
|
|
110
|
+
name: t
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
return this.write({
|
|
114
|
+
id: a,
|
|
115
|
+
buffer: n,
|
|
116
|
+
byteOffset: r,
|
|
117
|
+
byteLength: i
|
|
118
|
+
}), this.closeWriter({ id: a });
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw this.closeWriter({
|
|
121
|
+
id: a,
|
|
122
|
+
abort: !0
|
|
123
|
+
}), e;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async readRange({ path: e, name: t, offset: n = 0, length: r }) {
|
|
127
|
+
let i = await (await this._dir(e, !1)).getFileHandle(t), a = null;
|
|
128
|
+
try {
|
|
129
|
+
a = await i.createSyncAccessHandle();
|
|
130
|
+
} catch (e) {
|
|
131
|
+
if (e.name !== "NoModificationAllowedError") throw e;
|
|
132
|
+
}
|
|
133
|
+
if (!a) {
|
|
134
|
+
let e = await i.getFile(), t = r === void 0 ? e.size : n + r;
|
|
135
|
+
return { buffer: await e.slice(n, t).arrayBuffer() };
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
let e = a.getSize(), t = Math.max(0, Math.min(r ?? e - n, e - n)), i = new ArrayBuffer(t);
|
|
139
|
+
return a.read(i, { at: n }), { buffer: i };
|
|
140
|
+
} finally {
|
|
141
|
+
a.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
dispose() {
|
|
145
|
+
for (let e of [...this._writers.keys()]) this.closeWriter({
|
|
146
|
+
id: e,
|
|
147
|
+
abort: !0
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}, m = class {
|
|
151
|
+
constructor(e) {
|
|
152
|
+
this._ops = new p(e);
|
|
153
|
+
}
|
|
154
|
+
async call(e, t) {
|
|
155
|
+
return this._ops[e](t);
|
|
156
|
+
}
|
|
157
|
+
dispose() {
|
|
158
|
+
this._ops.dispose();
|
|
159
|
+
}
|
|
160
|
+
}, h = "meta.json", g = 1, _ = 36e5, v = .3, y = 100 * 1024 ** 3, b = 64 * 1024 ** 2, x = 8 * 1024 ** 2, S = 4, C = 3e4, w = new TextEncoder();
|
|
161
|
+
function T(e, { copy: t, transfer: n }) {
|
|
162
|
+
if (typeof e == "string" && (e = w.encode(e)), e instanceof ArrayBuffer) {
|
|
163
|
+
if (!t || n) return {
|
|
164
|
+
args: { buffer: e },
|
|
165
|
+
list: [e]
|
|
166
|
+
};
|
|
167
|
+
let r = e.slice(0);
|
|
168
|
+
return {
|
|
169
|
+
args: { buffer: r },
|
|
170
|
+
list: [r]
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (!ArrayBuffer.isView(e)) throw TypeError("storage: write expects an ArrayBuffer, a typed array, a Blob or a string");
|
|
174
|
+
let { buffer: r, byteOffset: i, byteLength: a } = e, o = typeof SharedArrayBuffer < "u" && r instanceof SharedArrayBuffer;
|
|
175
|
+
if (!t) return {
|
|
176
|
+
args: {
|
|
177
|
+
buffer: r,
|
|
178
|
+
byteOffset: i,
|
|
179
|
+
byteLength: a
|
|
180
|
+
},
|
|
181
|
+
list: []
|
|
182
|
+
};
|
|
183
|
+
if (o) {
|
|
184
|
+
let e = new Uint8Array(a);
|
|
185
|
+
return e.set(new Uint8Array(r, i, a)), {
|
|
186
|
+
args: { buffer: e.buffer },
|
|
187
|
+
list: [e.buffer]
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (n && i === 0 && a === r.byteLength) return {
|
|
191
|
+
args: { buffer: r },
|
|
192
|
+
list: [r]
|
|
193
|
+
};
|
|
194
|
+
let s = r.slice(i, i + a);
|
|
195
|
+
return {
|
|
196
|
+
args: { buffer: s },
|
|
197
|
+
list: [s]
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async function E(e, t) {
|
|
201
|
+
try {
|
|
202
|
+
let n = await (await e.getFileHandle(t)).getFile();
|
|
203
|
+
return JSON.parse(await n.text());
|
|
204
|
+
} catch {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function* D(e) {
|
|
209
|
+
for await (let [t, n] of e.entries()) n.kind === "directory" && (yield [t, n]);
|
|
210
|
+
}
|
|
211
|
+
var O = class {
|
|
212
|
+
constructor(e, t, n, r, i) {
|
|
213
|
+
this.area = e, this.id = t, this.key = n.key, this.meta = n, this._dir = r, this._release = i;
|
|
214
|
+
}
|
|
215
|
+
get bytes() {
|
|
216
|
+
return this.meta.bytes;
|
|
217
|
+
}
|
|
218
|
+
get extra() {
|
|
219
|
+
return this.meta.extra ?? {};
|
|
220
|
+
}
|
|
221
|
+
async file(t) {
|
|
222
|
+
try {
|
|
223
|
+
return await (await this._dir.getFileHandle(t)).getFile();
|
|
224
|
+
} catch (n) {
|
|
225
|
+
return this.area.manager._issue(e.STORAGE_READ_FAILED, `could not read ${this.area.name}/${this.id}/${t}`, { error: n.message }), null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async json(e) {
|
|
229
|
+
let t = await this.file(e);
|
|
230
|
+
return t ? JSON.parse(await t.text()) : null;
|
|
231
|
+
}
|
|
232
|
+
release() {
|
|
233
|
+
this._release?.(), this._release = null;
|
|
234
|
+
}
|
|
235
|
+
}, k = class {
|
|
236
|
+
constructor(e, t, n, r, i, { sizes: a = {}, append: o = !1 } = {}) {
|
|
237
|
+
this.area = e, this.id = t, this.key = n, this._info = r, this._release = i, this._writers = /* @__PURE__ */ new Map(), this._sizes = { ...a }, this._append = o, this._done = !1, this._committedBytes = o ? Object.values(a).reduce((e, t) => e + t, 0) : 0;
|
|
238
|
+
}
|
|
239
|
+
get _transport() {
|
|
240
|
+
return this.area.manager._transport;
|
|
241
|
+
}
|
|
242
|
+
get _path() {
|
|
243
|
+
return [this.area.name, this.id];
|
|
244
|
+
}
|
|
245
|
+
async _writer(e) {
|
|
246
|
+
let t = this._writers.get(e);
|
|
247
|
+
if (!t) {
|
|
248
|
+
let n = this._append && e in this._sizes, r = n && (this._info.growable ?? []).includes(e) ? this._sizes[e] : void 0;
|
|
249
|
+
t = this._transport.call("openWriter", {
|
|
250
|
+
path: this._path,
|
|
251
|
+
name: e,
|
|
252
|
+
truncate: !n,
|
|
253
|
+
length: r
|
|
254
|
+
}), this._writers.set(e, t);
|
|
255
|
+
}
|
|
256
|
+
return (await t).id;
|
|
257
|
+
}
|
|
258
|
+
async write(e, t, { at: n, transfer: r = !1 } = {}) {
|
|
259
|
+
this._assertOpen();
|
|
260
|
+
let { args: i, list: a } = (typeof Blob < "u" && t instanceof Blob ? null : T(t, {
|
|
261
|
+
copy: !0,
|
|
262
|
+
transfer: r
|
|
263
|
+
})) ?? T(await t.arrayBuffer(), {
|
|
264
|
+
copy: !0,
|
|
265
|
+
transfer: !0
|
|
266
|
+
}), o = await this._writer(e);
|
|
267
|
+
return this._transport.call("write", {
|
|
268
|
+
id: o,
|
|
269
|
+
at: n,
|
|
270
|
+
...i
|
|
271
|
+
}, a);
|
|
272
|
+
}
|
|
273
|
+
async writeFile(e, t) {
|
|
274
|
+
this._assertOpen(), typeof Blob < "u" && t instanceof Blob && (t = await t.arrayBuffer());
|
|
275
|
+
let { args: n, list: r } = T(t, {
|
|
276
|
+
copy: !0,
|
|
277
|
+
transfer: !0
|
|
278
|
+
}), { size: i } = await this._transport.call("writeFile", {
|
|
279
|
+
path: this._path,
|
|
280
|
+
name: e,
|
|
281
|
+
...n
|
|
282
|
+
}, r);
|
|
283
|
+
return this._sizes[e] = i, i;
|
|
284
|
+
}
|
|
285
|
+
writeJSON(e, t) {
|
|
286
|
+
return this.writeFile(e, JSON.stringify(t));
|
|
287
|
+
}
|
|
288
|
+
async writeStream(e, t, { onProgress: n = null, signal: r = null, batchBytes: i = x } = {}) {
|
|
289
|
+
let a = t.getReader(), o = [], s = new Uint8Array(i), c = 0, l = 0, u = async () => {
|
|
290
|
+
if (c === 0) return;
|
|
291
|
+
let t = c === i ? s : s.slice(0, c);
|
|
292
|
+
s = new Uint8Array(i), c = 0, o.push(this.write(e, t, { transfer: !0 })), o.length >= S && await o.shift();
|
|
293
|
+
};
|
|
294
|
+
try {
|
|
295
|
+
for (;;) {
|
|
296
|
+
if (r?.aborted) throw r.reason ?? new DOMException("aborted", "AbortError");
|
|
297
|
+
let { done: e, value: t } = await a.read();
|
|
298
|
+
if (e) break;
|
|
299
|
+
let o = 0;
|
|
300
|
+
for (; o < t.length;) {
|
|
301
|
+
let e = Math.min(t.length - o, i - c);
|
|
302
|
+
s.set(t.subarray(o, o + e), c), c += e, o += e, l += e, c === i && await u();
|
|
303
|
+
}
|
|
304
|
+
n?.(l);
|
|
305
|
+
}
|
|
306
|
+
return await u(), await Promise.all(o), l;
|
|
307
|
+
} catch (e) {
|
|
308
|
+
throw a.cancel().catch(() => {}), await Promise.allSettled(o), e;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
async commit(e = {}) {
|
|
312
|
+
this._assertOpen(), this._done = !0;
|
|
313
|
+
try {
|
|
314
|
+
for (let [e, t] of this._writers) {
|
|
315
|
+
let { size: n } = await this._transport.call("closeWriter", { id: (await t).id });
|
|
316
|
+
this._sizes[e] = n;
|
|
317
|
+
}
|
|
318
|
+
this._writers.clear();
|
|
319
|
+
let n = Date.now(), r = {
|
|
320
|
+
v: g,
|
|
321
|
+
key: this.key,
|
|
322
|
+
label: this._info.label ?? "",
|
|
323
|
+
kind: this.area.kind,
|
|
324
|
+
files: { ...this._sizes },
|
|
325
|
+
bytes: Object.values(this._sizes).reduce((e, t) => e + t, 0),
|
|
326
|
+
createdAt: this._info.createdAt ?? n,
|
|
327
|
+
lastUsed: n,
|
|
328
|
+
pinned: this._info.pinned === !0,
|
|
329
|
+
extra: {
|
|
330
|
+
...this._info.extra,
|
|
331
|
+
...e
|
|
332
|
+
}
|
|
333
|
+
}, i = this._info.growable ?? [];
|
|
334
|
+
i.length && (r.growable = i);
|
|
335
|
+
let { args: a, list: o } = T(JSON.stringify(r), { copy: !1 });
|
|
336
|
+
return await this._transport.call("writeFile", {
|
|
337
|
+
path: this._path,
|
|
338
|
+
name: h,
|
|
339
|
+
...a
|
|
340
|
+
}, o), this.area.kind === t.CACHE && this.area.manager._countCacheBytes(r.bytes - this._committedBytes), this.area.manager._changed(this.area.name), r;
|
|
341
|
+
} catch (e) {
|
|
342
|
+
throw await this._discard(), this.area.manager._writeFailed(this.area.name, e), e;
|
|
343
|
+
} finally {
|
|
344
|
+
this._release?.(), this._release = null;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async abort() {
|
|
348
|
+
if (!this._done) {
|
|
349
|
+
this._done = !0;
|
|
350
|
+
try {
|
|
351
|
+
this._append ? await this._closeAll(!0) : await this._discard();
|
|
352
|
+
} finally {
|
|
353
|
+
this._release?.(), this._release = null;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async _closeAll(e) {
|
|
358
|
+
for (let t of this._writers.values()) try {
|
|
359
|
+
await this._transport.call("closeWriter", {
|
|
360
|
+
id: (await t).id,
|
|
361
|
+
abort: e
|
|
362
|
+
});
|
|
363
|
+
} catch {}
|
|
364
|
+
this._writers.clear();
|
|
365
|
+
}
|
|
366
|
+
async _discard() {
|
|
367
|
+
await this._closeAll(!0), await this.area._removeDir(this.id);
|
|
368
|
+
}
|
|
369
|
+
_assertOpen() {
|
|
370
|
+
if (this._done) throw Error(`storage: entry ${this.area.name}/${this.id} is already committed or aborted`);
|
|
371
|
+
}
|
|
372
|
+
}, A = class {
|
|
373
|
+
constructor(e, t, n) {
|
|
374
|
+
this.manager = e, this.name = t, this.kind = n;
|
|
375
|
+
}
|
|
376
|
+
_lockName(e) {
|
|
377
|
+
return `${this.manager.namespace}:store:${this.name}:${e}`;
|
|
378
|
+
}
|
|
379
|
+
async _dir(e = !1) {
|
|
380
|
+
try {
|
|
381
|
+
return await this.manager._root.getDirectoryHandle(this.name, { create: e });
|
|
382
|
+
} catch (e) {
|
|
383
|
+
if (e.name === "NotFoundError") return null;
|
|
384
|
+
throw e;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
async _entryDir(e, t = !1) {
|
|
388
|
+
let n = await this._dir(t);
|
|
389
|
+
if (!n) return null;
|
|
390
|
+
try {
|
|
391
|
+
return await n.getDirectoryHandle(e, { create: t });
|
|
392
|
+
} catch (e) {
|
|
393
|
+
if (e.name === "NotFoundError") return null;
|
|
394
|
+
throw e;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
async _removeDir(e) {
|
|
398
|
+
let t = await this._dir(!1);
|
|
399
|
+
if (t) try {
|
|
400
|
+
await t.removeEntry(e, { recursive: !0 });
|
|
401
|
+
} catch (e) {
|
|
402
|
+
if (e.name !== "NotFoundError") throw e;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
async _validMeta(e, t = null) {
|
|
406
|
+
let n = await E(e, h);
|
|
407
|
+
if (!n || n.v !== g || typeof n.key != "string" || t !== null && n.key !== t) return null;
|
|
408
|
+
let r = n.growable ?? [];
|
|
409
|
+
for (let [t, i] of Object.entries(n.files ?? {})) try {
|
|
410
|
+
let n = await (await e.getFileHandle(t)).getFile();
|
|
411
|
+
if (n.size !== i && !(r.includes(t) && n.size > i)) return null;
|
|
412
|
+
} catch {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return n;
|
|
416
|
+
}
|
|
417
|
+
async open(t, { wait: n = !1 } = {}) {
|
|
418
|
+
let r = await i(t), a = await u(this._lockName(r), {
|
|
419
|
+
mode: "shared",
|
|
420
|
+
ifAvailable: !n
|
|
421
|
+
});
|
|
422
|
+
if (!a) return null;
|
|
423
|
+
try {
|
|
424
|
+
let e = await this._entryDir(r), n = e ? await this._validMeta(e, t) : null;
|
|
425
|
+
return n ? (Date.now() - n.lastUsed > _ && this._touch(r, n), new O(this, r, n, e, a)) : (a(), null);
|
|
426
|
+
} catch (t) {
|
|
427
|
+
return a(), this.manager._issue(e.STORAGE_READ_FAILED, `could not open ${this.name} entry`, { error: t.message }), null;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
async has(e) {
|
|
431
|
+
let t = await this.open(e);
|
|
432
|
+
return t?.release(), !!t;
|
|
433
|
+
}
|
|
434
|
+
_touch(e, t) {
|
|
435
|
+
let n = {
|
|
436
|
+
...t,
|
|
437
|
+
lastUsed: Date.now()
|
|
438
|
+
}, { args: r, list: i } = T(JSON.stringify(n), { copy: !1 });
|
|
439
|
+
this.manager._transport.call("writeFile", {
|
|
440
|
+
path: [this.name, e],
|
|
441
|
+
name: h,
|
|
442
|
+
...r
|
|
443
|
+
}, i).catch(() => {}), t.lastUsed = n.lastUsed;
|
|
444
|
+
}
|
|
445
|
+
async create(t, { label: n = "", pinned: r = !1, expectedBytes: a = 0, extra: o = {}, growable: s = [] } = {}) {
|
|
446
|
+
let c = await i(t), l = await u(this._lockName(c), { mode: "exclusive" });
|
|
447
|
+
try {
|
|
448
|
+
return a > 0 && !await this.manager.ensureSpace(a, this.kind) ? (l(), this.manager._issue(e.STORAGE_QUOTA_EXCEEDED, `no room for ${(a / 1048576).toFixed(0)} MB in ${this.name}`, {
|
|
449
|
+
area: this.name,
|
|
450
|
+
expectedBytes: a
|
|
451
|
+
}), null) : (await this._removeDir(c), await this._entryDir(c, !0), new k(this, c, t, {
|
|
452
|
+
label: n,
|
|
453
|
+
pinned: r,
|
|
454
|
+
extra: o,
|
|
455
|
+
growable: s
|
|
456
|
+
}, l));
|
|
457
|
+
} catch (e) {
|
|
458
|
+
return l(), this.manager._writeFailed(this.name, e), null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async patchMeta(e, t) {
|
|
462
|
+
let n = await i(e), r = await u(this._lockName(n), {
|
|
463
|
+
mode: "shared",
|
|
464
|
+
ifAvailable: !0
|
|
465
|
+
});
|
|
466
|
+
if (!r) return !1;
|
|
467
|
+
try {
|
|
468
|
+
let r = await this._entryDir(n), i = r ? await this._validMeta(r, e) : null;
|
|
469
|
+
if (!i) return !1;
|
|
470
|
+
let { args: a, list: o } = T(JSON.stringify({
|
|
471
|
+
...i,
|
|
472
|
+
...t,
|
|
473
|
+
v: g,
|
|
474
|
+
key: e
|
|
475
|
+
}), { copy: !1 });
|
|
476
|
+
return await this.manager._transport.call("writeFile", {
|
|
477
|
+
path: [this.name, n],
|
|
478
|
+
name: h,
|
|
479
|
+
...a
|
|
480
|
+
}, o), !0;
|
|
481
|
+
} finally {
|
|
482
|
+
r();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
async edit(e) {
|
|
486
|
+
let t = await i(e), n = await u(this._lockName(t), { mode: "exclusive" });
|
|
487
|
+
try {
|
|
488
|
+
let r = await this._entryDir(t), i = r ? await this._validMeta(r, e) : null;
|
|
489
|
+
if (!i) return n(), null;
|
|
490
|
+
let a = {
|
|
491
|
+
label: i.label,
|
|
492
|
+
pinned: i.pinned,
|
|
493
|
+
extra: i.extra,
|
|
494
|
+
createdAt: i.createdAt,
|
|
495
|
+
growable: i.growable
|
|
496
|
+
};
|
|
497
|
+
return new k(this, t, e, a, n, {
|
|
498
|
+
sizes: i.files,
|
|
499
|
+
append: !0
|
|
500
|
+
});
|
|
501
|
+
} catch (e) {
|
|
502
|
+
return n(), this.manager._writeFailed(this.name, e), null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
async remove(e) {
|
|
506
|
+
return this.removeById(await i(e));
|
|
507
|
+
}
|
|
508
|
+
async removeById(e) {
|
|
509
|
+
let t = await u(this._lockName(e), {
|
|
510
|
+
mode: "exclusive",
|
|
511
|
+
ifAvailable: !0
|
|
512
|
+
});
|
|
513
|
+
if (!t) return !1;
|
|
514
|
+
try {
|
|
515
|
+
return await this._removeDir(e), this.manager._changed(this.name), !0;
|
|
516
|
+
} finally {
|
|
517
|
+
t();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async list() {
|
|
521
|
+
let e = await this._dir(!1);
|
|
522
|
+
if (!e) return [];
|
|
523
|
+
let t = [];
|
|
524
|
+
for await (let [n, r] of D(e)) {
|
|
525
|
+
let e = await E(r, h);
|
|
526
|
+
e?.v === g && t.push({
|
|
527
|
+
...e,
|
|
528
|
+
id: n
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
return t;
|
|
532
|
+
}
|
|
533
|
+
async clear() {
|
|
534
|
+
let e = 0;
|
|
535
|
+
for (let { id: t } of await this.list()) await this.removeById(t) && e++;
|
|
536
|
+
return e;
|
|
537
|
+
}
|
|
538
|
+
async sweep() {
|
|
539
|
+
let e = await this._dir(!1);
|
|
540
|
+
if (!e) return 0;
|
|
541
|
+
let t = await d(), n = 0;
|
|
542
|
+
for await (let [r, i] of D(e)) t.has(this._lockName(r)) || await this._validMeta(i) || await this.removeById(r) && n++;
|
|
543
|
+
return n;
|
|
544
|
+
}
|
|
545
|
+
}, j = class extends f {
|
|
546
|
+
constructor({ root: e, transport: r, namespace: i }) {
|
|
547
|
+
super(), this.namespace = i, this._root = e, this._transport = r, this._areas = /* @__PURE__ */ new Map(), this._budget = null, this._cacheTotal = null;
|
|
548
|
+
for (let e of Object.values(n)) this.defineArea(e, { kind: e === n.SPILL ? t.SCRATCH : t.CACHE });
|
|
549
|
+
}
|
|
550
|
+
defineArea(e, { kind: n = t.CACHE } = {}) {
|
|
551
|
+
let r = this._areas.get(e);
|
|
552
|
+
if (r) {
|
|
553
|
+
if (r.kind !== n) throw Error(`storage: area "${e}" is already defined as ${r.kind}`);
|
|
554
|
+
return r;
|
|
555
|
+
}
|
|
556
|
+
let i = new A(this, e, n);
|
|
557
|
+
return this._areas.set(e, i), i;
|
|
558
|
+
}
|
|
559
|
+
area(e) {
|
|
560
|
+
let t = this._areas.get(e);
|
|
561
|
+
if (!t) throw Error(`storage: unknown area "${e}"`);
|
|
562
|
+
return t;
|
|
563
|
+
}
|
|
564
|
+
get areaNames() {
|
|
565
|
+
return [...this._areas.keys()];
|
|
566
|
+
}
|
|
567
|
+
async estimate() {
|
|
568
|
+
let e = typeof navigator < "u" ? navigator.storage : null;
|
|
569
|
+
if (!e?.estimate) return {
|
|
570
|
+
quota: Infinity,
|
|
571
|
+
usage: 0
|
|
572
|
+
};
|
|
573
|
+
let { quota: t = Infinity, usage: n = 0 } = await e.estimate();
|
|
574
|
+
return {
|
|
575
|
+
quota: t,
|
|
576
|
+
usage: n
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
async persisted() {
|
|
580
|
+
return await globalThis.navigator?.storage?.persisted?.() === !0;
|
|
581
|
+
}
|
|
582
|
+
async persist() {
|
|
583
|
+
let e = await globalThis.navigator?.storage?.persist?.() === !0;
|
|
584
|
+
return this._changed(null), e;
|
|
585
|
+
}
|
|
586
|
+
async budget() {
|
|
587
|
+
if (this._budget !== null) return this._budget;
|
|
588
|
+
let { quota: e } = await this.estimate();
|
|
589
|
+
return Math.min(e * v, y);
|
|
590
|
+
}
|
|
591
|
+
setBudget(e) {
|
|
592
|
+
this._budget = e === null ? null : Math.max(0, e), this._changed(null);
|
|
593
|
+
}
|
|
594
|
+
async _cacheBytes() {
|
|
595
|
+
let e = this._cacheTotal;
|
|
596
|
+
return (!e || Date.now() - e.at > C) && (e = this._cacheTotal = {
|
|
597
|
+
at: Date.now(),
|
|
598
|
+
bytes: 0,
|
|
599
|
+
ready: null
|
|
600
|
+
}, e.ready = this._cacheEntries().then((t) => {
|
|
601
|
+
e.bytes += t.reduce((e, t) => e + (t.meta.bytes ?? 0), 0);
|
|
602
|
+
}), e.ready.catch(() => {
|
|
603
|
+
this._cacheTotal === e && (this._cacheTotal = null);
|
|
604
|
+
})), await e.ready, e.bytes;
|
|
605
|
+
}
|
|
606
|
+
_countCacheBytes(e) {
|
|
607
|
+
this._cacheTotal && (this._cacheTotal.bytes += e);
|
|
608
|
+
}
|
|
609
|
+
async _cacheEntries() {
|
|
610
|
+
let e = [];
|
|
611
|
+
for (let n of this._areas.values()) if (n.kind === t.CACHE) for (let t of await n.list()) e.push({
|
|
612
|
+
area: n,
|
|
613
|
+
meta: t
|
|
614
|
+
});
|
|
615
|
+
return e;
|
|
616
|
+
}
|
|
617
|
+
async usage() {
|
|
618
|
+
let { quota: e, usage: n } = await this.estimate(), r = {}, i = 0;
|
|
619
|
+
for (let e of this._areas.values()) {
|
|
620
|
+
let n = await e.list(), a = n.reduce((e, t) => e + (t.bytes ?? 0), 0);
|
|
621
|
+
r[e.name] = {
|
|
622
|
+
kind: e.kind,
|
|
623
|
+
bytes: a,
|
|
624
|
+
entries: n.length
|
|
625
|
+
}, e.kind === t.CACHE && (i += a);
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
quota: e,
|
|
629
|
+
usage: n,
|
|
630
|
+
persisted: await this.persisted(),
|
|
631
|
+
budget: await this.budget(),
|
|
632
|
+
cacheBytes: i,
|
|
633
|
+
areas: r
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
async collect({ freeBytes: e = null } = {}) {
|
|
637
|
+
let t = await this._cacheEntries(), n = await this.budget(), r = this._cacheTotal = {
|
|
638
|
+
at: Date.now(),
|
|
639
|
+
bytes: t.reduce((e, t) => e + (t.meta.bytes ?? 0), 0),
|
|
640
|
+
ready: null
|
|
641
|
+
}, i = e ?? Math.max(0, r.bytes - n);
|
|
642
|
+
if (i <= 0) return 0;
|
|
643
|
+
let a = await d(), o = t.filter(({ area: e, meta: t }) => !t.pinned && !a.has(e._lockName(t.id))).sort((e, t) => e.meta.lastUsed - t.meta.lastUsed), s = 0;
|
|
644
|
+
for (let { area: e, meta: t } of o) {
|
|
645
|
+
if (s >= i) break;
|
|
646
|
+
await e.removeById(t.id) && (s += t.bytes ?? 0, r.bytes -= t.bytes ?? 0);
|
|
647
|
+
}
|
|
648
|
+
return s;
|
|
649
|
+
}
|
|
650
|
+
async ensureSpace(e, n = t.CACHE) {
|
|
651
|
+
let r = async () => {
|
|
652
|
+
let { quota: r, usage: i } = await this.estimate(), a = e + b - (r - i);
|
|
653
|
+
return n === t.CACHE ? {
|
|
654
|
+
free: a,
|
|
655
|
+
budget: await this._cacheBytes() + e - await this.budget()
|
|
656
|
+
} : {
|
|
657
|
+
free: a,
|
|
658
|
+
budget: 0
|
|
659
|
+
};
|
|
660
|
+
}, i = await r();
|
|
661
|
+
return i.free <= 0 && i.budget <= 0 ? !0 : (await this.collect({ freeBytes: Math.max(i.free, i.budget) }), (await r()).free <= 0);
|
|
662
|
+
}
|
|
663
|
+
async sweep() {
|
|
664
|
+
let e = 0;
|
|
665
|
+
for (let n of this._areas.values()) e += await n.sweep(), n.kind === t.SCRATCH && (e += await n.clear());
|
|
666
|
+
return e;
|
|
667
|
+
}
|
|
668
|
+
_changed(e) {
|
|
669
|
+
this.dispatchEvent({
|
|
670
|
+
type: "change",
|
|
671
|
+
area: e
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
_issue(e, t, n = {}) {
|
|
675
|
+
this.dispatchEvent({
|
|
676
|
+
type: "issue",
|
|
677
|
+
code: e,
|
|
678
|
+
message: t,
|
|
679
|
+
detail: n
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
_writeFailed(t, n) {
|
|
683
|
+
let r = n?.name === "QuotaExceededError";
|
|
684
|
+
this._issue(r ? e.STORAGE_QUOTA_EXCEEDED : e.STORAGE_WRITE_FAILED, `${t}: ${n?.message ?? n}`, {
|
|
685
|
+
area: t,
|
|
686
|
+
error: n?.name
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
dispose() {
|
|
690
|
+
this._transport?.dispose(), this._transport = null, this._areas.clear();
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
function M({ namespace: e, root: t }) {
|
|
694
|
+
let n = new m(t);
|
|
695
|
+
n.inline = !0;
|
|
696
|
+
let r = new j({
|
|
697
|
+
root: t,
|
|
698
|
+
transport: n,
|
|
699
|
+
namespace: e
|
|
700
|
+
});
|
|
701
|
+
return r.sweep().catch(() => {}), r;
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
704
|
+
//#region src/Storage/StorageWorker.js?worker&inline
|
|
705
|
+
var N = "var e=class{constructor(e){this._root=e,this._writers=new Map,this._nextId=1}async _dir(e,t){let n=await this._root;for(let r of e)n=await n.getDirectoryHandle(r,{create:t});return n}async openWriter({path:e,name:t,truncate:n=!0,length:r}){let i=await(await(await this._dir(e,!0)).getFileHandle(t,{create:!0})).createSyncAccessHandle();n?i.truncate(0):r!==void 0&&i.getSize()>r&&i.truncate(r);let a=this._nextId++;return this._writers.set(a,{handle:i,end:i.getSize()}),{id:a}}write({id:e,buffer:t,byteOffset:n=0,byteLength:r,at:i}){let a=this._writers.get(e);if(!a)throw Error(`storage: writer ${e} is not open`);let o=new Uint8Array(t,n,r??t.byteLength-n),s=i??a.end,c=0;for(;c<o.length;){let e=a.handle.write(o.subarray(c),{at:s+c});if(e<=0)throw Error(`storage: write made no progress`);c+=e}return a.end=Math.max(a.end,s+o.length),{bytes:o.length}}closeWriter({id:e,abort:t=!1}){let n=this._writers.get(e);if(!n)return{size:0};this._writers.delete(e);try{return t||n.handle.flush(),{size:n.handle.getSize()}}finally{n.handle.close()}}async writeFile({path:e,name:t,buffer:n,byteOffset:r=0,byteLength:i}){let{id:a}=await this.openWriter({path:e,name:t});try{return this.write({id:a,buffer:n,byteOffset:r,byteLength:i}),this.closeWriter({id:a})}catch(e){throw this.closeWriter({id:a,abort:!0}),e}}async readRange({path:e,name:t,offset:n=0,length:r}){let i=await(await this._dir(e,!1)).getFileHandle(t),a=null;try{a=await i.createSyncAccessHandle()}catch(e){if(e.name!==`NoModificationAllowedError`)throw e}if(!a){let e=await i.getFile(),t=r===void 0?e.size:n+r;return{buffer:await e.slice(n,t).arrayBuffer()}}try{let e=a.getSize(),t=Math.max(0,Math.min(r??e-n,e-n)),i=new ArrayBuffer(t);return a.read(i,{at:n}),{buffer:i}}finally{a.close()}}dispose(){for(let e of[...this._writers.keys()])this.closeWriter({id:e,abort:!0})}};let t=null;async function n(e,t){return t||(await navigator.storage.getDirectory()).getDirectoryHandle(e,{create:!0})}self.onmessage=async({data:r})=>{let{id:i,op:a,args:o}=r;try{if(a===`init`){t=new e(n(o.namespace,o.root)),postMessage({id:i,result:{}});return}let r=await t[a](o),s=r?.buffer instanceof ArrayBuffer?[r.buffer]:[];postMessage({id:i,result:r},s)}catch(e){postMessage({id:i,error:{name:e.name,message:e.message}})}};", P = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", N], { type: "text/javascript;charset=utf-8" });
|
|
706
|
+
function F(e) {
|
|
707
|
+
let t;
|
|
708
|
+
try {
|
|
709
|
+
if (t = P && (self.URL || self.webkitURL).createObjectURL(P), !t) throw "";
|
|
710
|
+
let n = new Worker(t, {
|
|
711
|
+
type: "module",
|
|
712
|
+
name: e?.name
|
|
713
|
+
});
|
|
714
|
+
return n.addEventListener("error", () => {
|
|
715
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
716
|
+
}), n;
|
|
717
|
+
} catch {
|
|
718
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(N), {
|
|
719
|
+
type: "module",
|
|
720
|
+
name: e?.name
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region src/Storage/transport.js
|
|
726
|
+
function I({ name: e, message: t }) {
|
|
727
|
+
let n = Error(t);
|
|
728
|
+
return n.name = e, n;
|
|
729
|
+
}
|
|
730
|
+
var L = class {
|
|
731
|
+
constructor({ namespace: e, root: t = null }) {
|
|
732
|
+
this._worker = new F(), this._pending = /* @__PURE__ */ new Map(), this._nextId = 0, this._worker.onmessage = ({ data: e }) => {
|
|
733
|
+
let t = this._pending.get(e.id);
|
|
734
|
+
t && (this._pending.delete(e.id), e.error ? t.reject(I(e.error)) : t.resolve(e.result));
|
|
735
|
+
}, this._ready = this.call("init", {
|
|
736
|
+
namespace: e,
|
|
737
|
+
root: t
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
call(e, t, n = []) {
|
|
741
|
+
return this._worker ? new Promise((r, i) => {
|
|
742
|
+
let a = this._nextId++;
|
|
743
|
+
this._pending.set(a, {
|
|
744
|
+
resolve: r,
|
|
745
|
+
reject: i
|
|
746
|
+
}), this._worker.postMessage({
|
|
747
|
+
id: a,
|
|
748
|
+
op: e,
|
|
749
|
+
args: t
|
|
750
|
+
}, n);
|
|
751
|
+
}) : Promise.reject(/* @__PURE__ */ Error("storage: transport disposed"));
|
|
752
|
+
}
|
|
753
|
+
dispose() {
|
|
754
|
+
this._worker?.terminate(), this._worker = null;
|
|
755
|
+
for (let { reject: e } of this._pending.values()) e(/* @__PURE__ */ Error("storage: transport disposed"));
|
|
756
|
+
this._pending.clear();
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
function R() {
|
|
760
|
+
return typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
761
|
+
}
|
|
762
|
+
//#endregion
|
|
763
|
+
//#region src/Storage/openStorage.js
|
|
764
|
+
async function z(e) {
|
|
765
|
+
let t = typeof navigator < "u" ? navigator.storage : null;
|
|
766
|
+
if (!t?.getDirectory) return {
|
|
767
|
+
root: null,
|
|
768
|
+
reason: "this browser has no origin private file system"
|
|
769
|
+
};
|
|
770
|
+
try {
|
|
771
|
+
return { root: await (await t.getDirectory()).getDirectoryHandle(e, { create: !0 }) };
|
|
772
|
+
} catch (e) {
|
|
773
|
+
return {
|
|
774
|
+
root: null,
|
|
775
|
+
reason: `${e.name}: ${e.message}`
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
async function B({ namespace: e, root: t = null, transport: n = "auto" } = {}) {
|
|
780
|
+
let r = t ? { root: t } : await z(e);
|
|
781
|
+
if (!r.root) return {
|
|
782
|
+
storage: null,
|
|
783
|
+
reason: r.reason
|
|
784
|
+
};
|
|
785
|
+
if (n === "inline" || n === "auto" && (R() || typeof Worker > "u")) return { storage: M({
|
|
786
|
+
namespace: e,
|
|
787
|
+
root: r.root
|
|
788
|
+
}) };
|
|
789
|
+
let i = new L({
|
|
790
|
+
namespace: e,
|
|
791
|
+
root: t
|
|
792
|
+
}), a = new j({
|
|
793
|
+
root: r.root,
|
|
794
|
+
transport: i,
|
|
795
|
+
namespace: e
|
|
796
|
+
});
|
|
797
|
+
return a.sweep().catch(() => {}), { storage: a };
|
|
798
|
+
}
|
|
799
|
+
async function V(e) {
|
|
800
|
+
let t = r.get(e);
|
|
801
|
+
t || (t = {
|
|
802
|
+
refs: 0,
|
|
803
|
+
opened: B({ namespace: e })
|
|
804
|
+
}, r.set(e, t)), t.refs++;
|
|
805
|
+
let { storage: n, reason: i } = await t.opened;
|
|
806
|
+
t.storage = n;
|
|
807
|
+
let a = !1, o = () => {
|
|
808
|
+
a || (a = !0, t.refs--, !(t.refs > 0) && (r.get(e) === t && r.delete(e), n?.dispose()));
|
|
809
|
+
};
|
|
810
|
+
return n ? {
|
|
811
|
+
storage: n,
|
|
812
|
+
release: o
|
|
813
|
+
} : (o(), {
|
|
814
|
+
storage: null,
|
|
815
|
+
reason: i,
|
|
816
|
+
release: () => {}
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
//#endregion
|
|
820
|
+
export { O as a, u as c, A as i, d as l, B as n, j as o, k as r, M as s, V as t };
|