@dioramajs/assets 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/errors-C0aoug0G.d.ts +263 -0
- package/dist/errors-C0aoug0G.d.ts.map +1 -0
- package/dist/errors-DgHytoOg.js +29 -0
- package/dist/errors-DgHytoOg.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1211 -0
- package/dist/index.js.map +1 -0
- package/dist/three/index.d.ts +23 -0
- package/dist/three/index.d.ts.map +1 -0
- package/dist/three/index.js +332 -0
- package/dist/three/index.js.map +1 -0
- package/package.json +66 -3
- package/src/cache.ts +437 -0
- package/src/errors.ts +39 -0
- package/src/index.ts +4 -0
- package/src/keys.ts +86 -0
- package/src/loaders.ts +119 -0
- package/src/plugin.ts +315 -0
- package/src/preload.ts +335 -0
- package/src/queue.ts +115 -0
- package/src/three/decoders.ts +197 -0
- package/src/three/gltf.ts +146 -0
- package/src/three/index.ts +5 -0
- package/src/three/ktx2.ts +27 -0
- package/src/three/texture.ts +44 -0
- package/src/types.ts +269 -0
- package/src/wave.ts +115 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diorama contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dioramajs/assets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Asset loading for Diorama: one cache with preload and progress, and glTF with Draco, Meshopt and KTX2.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Sites install `@dioramajs/diorama`, which loads this package when an element needs it:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @dioramajs/diorama three
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Docs
|
|
14
|
+
|
|
15
|
+
- [Loading guide](https://dioramajs.dev/docs/guides/loading)
|
|
16
|
+
- [API reference](https://dioramajs.dev/docs/api/assets)
|
|
17
|
+
- [Diorama on GitHub](https://github.com/MasterKurosava/diorama)
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import "@dioramajs/core/dev";
|
|
2
|
+
import { Off, ReadonlySignal } from "@dioramajs/core";
|
|
3
|
+
import { AnimationClip, CompressedTexture, Group, Object3D, Texture } from "three/webgpu";
|
|
4
|
+
import { RenderApi } from "@dioramajs/render";
|
|
5
|
+
/** Request priority. An entry runs at the highest priority among its leases. */
|
|
6
|
+
type Priority = "high" | "normal" | "low";
|
|
7
|
+
/** State of a lease. */
|
|
8
|
+
type AssetStatus = "loading" | "ready" | "failed" | "released";
|
|
9
|
+
/** `''` (default) sends no CORS mode, like an <img> without `crossorigin`. */
|
|
10
|
+
type CrossOrigin = "" | "anonymous" | "use-credentials";
|
|
11
|
+
/** Value types of typed loads. Extend via declaration merging for your own loaders. */
|
|
12
|
+
interface AssetTypes {
|
|
13
|
+
/** Decoded pixels, flipped like effects textures (`imageOrientation: 'flipY'`). */
|
|
14
|
+
image: ImageBitmap;
|
|
15
|
+
/** Origin bottom-left like effects textures, built from the `image` entry. Shared, never dispose it. */
|
|
16
|
+
texture: Texture;
|
|
17
|
+
/** A glTF model owned by the cache. */
|
|
18
|
+
gltf: Model;
|
|
19
|
+
/** Origin top-left like glTF, and `flipY` can't be changed. Shared, never dispose it. */
|
|
20
|
+
ktx2: CompressedTexture;
|
|
21
|
+
/** Raw bytes. */
|
|
22
|
+
buffer: ArrayBuffer;
|
|
23
|
+
/** Parsed JSON. */
|
|
24
|
+
json: unknown;
|
|
25
|
+
}
|
|
26
|
+
/** A glTF owned by the cache. Place instances and never dispose their resources. */
|
|
27
|
+
interface Model {
|
|
28
|
+
/** The loaded scene. Place instances, not this group. */
|
|
29
|
+
readonly scene: Group;
|
|
30
|
+
/** Animation clips of the file. */
|
|
31
|
+
readonly animations: readonly AnimationClip[];
|
|
32
|
+
/**
|
|
33
|
+
* A clone sharing geometry, materials and textures (SkeletonUtils for skinned). The shared
|
|
34
|
+
* resources carry `userData.keep`. The clone's own objects are disposed with the effect.
|
|
35
|
+
*/
|
|
36
|
+
instance(): Object3D;
|
|
37
|
+
}
|
|
38
|
+
/** Options of `assets.load`. */
|
|
39
|
+
interface LoadOptions<K extends string = string> {
|
|
40
|
+
/** Guessed from the extension when omitted: gltf for .glb and .gltf, ktx2 for .ktx2, texture for images. */
|
|
41
|
+
readonly type?: K;
|
|
42
|
+
/** Default 'normal'. An entry runs at the highest priority among its leases. */
|
|
43
|
+
readonly priority?: Priority;
|
|
44
|
+
/**
|
|
45
|
+
* Part of the key, as the browser keys its image cache by CORS mode. A `texture` of another
|
|
46
|
+
* origin is always asked in CORS mode: `''` becomes `'anonymous'`, since the GPU refuses
|
|
47
|
+
* pixels fetched without it.
|
|
48
|
+
*/
|
|
49
|
+
readonly crossOrigin?: CrossOrigin;
|
|
50
|
+
/** Loader options, part of the key. For example `{ colorSpace: 'linear' }`. */
|
|
51
|
+
readonly options?: Readonly<Record<string, string | number | boolean>>;
|
|
52
|
+
/** Aborting it releases the lease. */
|
|
53
|
+
readonly signal?: AbortSignal;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A lease, returned synchronously. The entry lives while any lease does. Calling it releases it.
|
|
57
|
+
* `E` is the failure type, AssetError for `load()` and whatever `make` threw for `acquire()`.
|
|
58
|
+
*/
|
|
59
|
+
interface Asset<T, E = AssetError> {
|
|
60
|
+
(): void;
|
|
61
|
+
/** Releases the lease. The entry goes when its last lease does. */
|
|
62
|
+
release(): void;
|
|
63
|
+
/** Same as release, so `ctx.onDispose(asset)` ties it to an effect. */
|
|
64
|
+
dispose(): void;
|
|
65
|
+
/** Cache key: type, URL, CORS mode and options. */
|
|
66
|
+
readonly key: string;
|
|
67
|
+
/** Absolute URL. */
|
|
68
|
+
readonly url: string;
|
|
69
|
+
/** State of the lease. */
|
|
70
|
+
readonly status: ReadonlySignal<AssetStatus>;
|
|
71
|
+
/** Rejects with `E`, or with an unreported ASSET_ABORTED if released before ready. */
|
|
72
|
+
readonly ready: Promise<T>;
|
|
73
|
+
/** The value while the lease is ready, undefined before and after. */
|
|
74
|
+
readonly value: T | undefined;
|
|
75
|
+
/** The failure while the lease is failed. */
|
|
76
|
+
readonly error: E | undefined;
|
|
77
|
+
}
|
|
78
|
+
/** What a loader resolves with. */
|
|
79
|
+
interface Loaded<T> {
|
|
80
|
+
/** The loaded value. */
|
|
81
|
+
readonly value: T;
|
|
82
|
+
/** Approximate size in bytes for `retain` and progress weights. Estimated when absent. */
|
|
83
|
+
readonly bytes?: number;
|
|
84
|
+
/** Frees what the value holds. Called once, by the cache only. */
|
|
85
|
+
dispose?(): void;
|
|
86
|
+
/** Depends on the renderer's formats (KTX2), so it is evicted when render restarts. */
|
|
87
|
+
readonly renderBound?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** What a loader gets for one entry. */
|
|
90
|
+
interface LoaderContext {
|
|
91
|
+
/** Absolute URL to load. */
|
|
92
|
+
readonly url: string;
|
|
93
|
+
/** Cache key of the entry. */
|
|
94
|
+
readonly key: string;
|
|
95
|
+
/** The highest priority among the entry's leases. */
|
|
96
|
+
readonly priority: Priority;
|
|
97
|
+
/** CORS mode of the request. */
|
|
98
|
+
readonly crossOrigin: CrossOrigin;
|
|
99
|
+
/** Loader options from `load()`. */
|
|
100
|
+
readonly options: Readonly<Record<string, string | number | boolean>>;
|
|
101
|
+
/** Aborts when the last lease goes before the load ends. */
|
|
102
|
+
readonly signal: AbortSignal;
|
|
103
|
+
/** fetch() with the priority hint and signal. HTTP errors throw ASSET_LOAD. */
|
|
104
|
+
fetch(init?: RequestInit): Promise<Response>;
|
|
105
|
+
/** Reads a body, counting bytes into the progress. */
|
|
106
|
+
bytes(response: Response): Promise<ArrayBuffer>;
|
|
107
|
+
/**
|
|
108
|
+
* Runs CPU-heavy work (createImageBitmap, parsing) in one of two decode slots and frees the
|
|
109
|
+
* request slot, so call it once the network part is done. Low-only entries wait while a pause
|
|
110
|
+
* is held.
|
|
111
|
+
*/
|
|
112
|
+
decode<R>(work: () => Promise<R>): Promise<R>;
|
|
113
|
+
/**
|
|
114
|
+
* Loads a dependency. Its lease is released if this load is aborted, otherwise release it in
|
|
115
|
+
* `dispose`. Like `render()` it frees the request slot, so call both after the network part.
|
|
116
|
+
*/
|
|
117
|
+
load<T = unknown>(url: string, options?: LoadOptions): Asset<T>;
|
|
118
|
+
/** Resolves once `render` runs (after renderer.init()). */
|
|
119
|
+
render(): Promise<RenderApi>;
|
|
120
|
+
/** The app's decoder options. Unset fields take three's defaults. */
|
|
121
|
+
readonly decoders: Readonly<Partial<DecoderOptions>>;
|
|
122
|
+
}
|
|
123
|
+
/** Loads one type of asset. */
|
|
124
|
+
interface AssetLoader<T = unknown> {
|
|
125
|
+
/** Extensions this loader handles when no type is given, e.g. ['.glb', '.gltf']. */
|
|
126
|
+
readonly extensions?: readonly string[];
|
|
127
|
+
/** Loads the value of one entry. */
|
|
128
|
+
load(context: LoaderContext): Promise<Loaded<T>>;
|
|
129
|
+
}
|
|
130
|
+
/** A loader, or a lazy module exporting one. Three-based loaders come through import(). */
|
|
131
|
+
type LoaderEntry = AssetLoader | (() => Promise<AssetLoader | {
|
|
132
|
+
readonly default: AssetLoader;
|
|
133
|
+
}>);
|
|
134
|
+
/** Where Draco, KTX2 and Meshopt decoders come from. */
|
|
135
|
+
interface DecoderOptions {
|
|
136
|
+
/** A directory or `{ js, wasm }`, false refuses. Defaults to three's glTF-only build next to DRACOLoader. */
|
|
137
|
+
readonly draco: string | {
|
|
138
|
+
readonly js: string;
|
|
139
|
+
readonly wasm: string;
|
|
140
|
+
} | false;
|
|
141
|
+
/** A directory, false refuses. Defaults to three's Basis transcoder next to KTX2Loader. */
|
|
142
|
+
readonly ktx2: string | false;
|
|
143
|
+
/** EXT_/KHR_meshopt_compression through three's decoder module (wasm inside). Default true. */
|
|
144
|
+
readonly meshopt: boolean;
|
|
145
|
+
/** Workers per decoder, three's default if unset. The first app that creates a decoder sets it. */
|
|
146
|
+
readonly workers: number | undefined;
|
|
147
|
+
}
|
|
148
|
+
/** What `preload` takes: URLs, a parsed Document or a container element. */
|
|
149
|
+
type PreloadSource = string | readonly string[] | ParentNode;
|
|
150
|
+
/** Options of `assets.preload`. */
|
|
151
|
+
interface PreloadOptions {
|
|
152
|
+
/** Default 'low'. */
|
|
153
|
+
readonly priority?: Priority;
|
|
154
|
+
/**
|
|
155
|
+
* CORS mode of images given as URLs. Match the `<img crossorigin>` that will show them, since
|
|
156
|
+
* it is part of the key. Images from markup or a document carry their own `crossorigin`.
|
|
157
|
+
*/
|
|
158
|
+
readonly crossOrigin?: CrossOrigin;
|
|
159
|
+
/** Base for relative URLs and srcset, i.e. the next page's URL. Defaults to <base href>, then document.baseURI. */
|
|
160
|
+
readonly base?: string | URL;
|
|
161
|
+
}
|
|
162
|
+
/** Settles once everything has settled. Never rejects. */
|
|
163
|
+
interface Preload extends PromiseLike<void> {
|
|
164
|
+
/** Drops the leases now. Otherwise they are held until the next preload of the same kind. */
|
|
165
|
+
release(): void;
|
|
166
|
+
/** Same as release, for `page.onDispose(app.assets.preload(doc))`. */
|
|
167
|
+
dispose(): void;
|
|
168
|
+
}
|
|
169
|
+
/** Counters of the cache. */
|
|
170
|
+
interface AssetsStats {
|
|
171
|
+
/** Entries in the cache. */
|
|
172
|
+
readonly entries: number;
|
|
173
|
+
/** Entries with leases. */
|
|
174
|
+
readonly used: number;
|
|
175
|
+
/** Bytes of entries without leases, kept by `retain`. */
|
|
176
|
+
readonly retained: number;
|
|
177
|
+
/** Entries still loading. */
|
|
178
|
+
readonly pending: number;
|
|
179
|
+
}
|
|
180
|
+
/** Options of the `assets` plugin. */
|
|
181
|
+
interface AssetsOptions {
|
|
182
|
+
/** Own loaders by type, next to the built-in ones. A lazy one is picked by `type` only. */
|
|
183
|
+
readonly loaders: Readonly<Record<string, LoaderEntry>>;
|
|
184
|
+
/** Where the Draco, KTX2 and Meshopt decoders come from. */
|
|
185
|
+
readonly decoders: Partial<DecoderOptions>;
|
|
186
|
+
/** Parallel requests. Default 6. At most 2 of them low, and only while no high request waits. */
|
|
187
|
+
readonly concurrency: number;
|
|
188
|
+
/** Bytes of unused entries kept for reuse (back navigation, preloads), LRU. Default 32 MB, 0 disables. */
|
|
189
|
+
readonly retain: number;
|
|
190
|
+
/** Reads data-dio-preload. Default true. Off under Save-Data or 2g. */
|
|
191
|
+
readonly preload: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** The `assets` service: a shared cache of media and models with progress. */
|
|
194
|
+
interface AssetsApi {
|
|
195
|
+
/**
|
|
196
|
+
* Loads a URL and returns a lease at once. The type comes from `type` or the extension.
|
|
197
|
+
* Never throws: `ready` rejects with an AssetError, `ASSET_TYPE` for an unknown type,
|
|
198
|
+
* `ASSET_LOAD` for a network or HTTP failure, `ASSET_PARSE` or `ASSET_DECODER` for bad data.
|
|
199
|
+
*/
|
|
200
|
+
load<K extends keyof AssetTypes>(url: string, options: LoadOptions<K> & {
|
|
201
|
+
readonly type: K;
|
|
202
|
+
}): Asset<AssetTypes[K]>;
|
|
203
|
+
load<T = unknown>(url: string, options?: LoadOptions): Asset<T>;
|
|
204
|
+
/**
|
|
205
|
+
* Get-or-create by key with a lease. Plugins share values they build this way (effects
|
|
206
|
+
* bitmaps). Errors of `make` reject `ready` unchanged and the owner reports them.
|
|
207
|
+
*/
|
|
208
|
+
acquire<T>(key: string, make: (context: LoaderContext) => Promise<Loaded<T>>, options?: {
|
|
209
|
+
readonly priority?: Priority;
|
|
210
|
+
readonly weight?: number;
|
|
211
|
+
}): Asset<T, unknown>;
|
|
212
|
+
/** Next page's media and models: URLs, a parsed Document (Astro, Swup) or a container (Barba). */
|
|
213
|
+
preload(source: PreloadSource, options?: PreloadOptions): Preload;
|
|
214
|
+
/**
|
|
215
|
+
* Counts outside work in the current wave, like first-screen effects, fonts or page HTML.
|
|
216
|
+
* `weight: 0` holds `ready()` without moving progress or starting a wave of its own.
|
|
217
|
+
*/
|
|
218
|
+
track(work: PromiseLike<unknown>, options?: {
|
|
219
|
+
readonly weight?: number;
|
|
220
|
+
readonly priority?: Priority;
|
|
221
|
+
}): void;
|
|
222
|
+
/**
|
|
223
|
+
* Low-priority loads and decodes wait while any pause is held (a flight). `reason` labels the
|
|
224
|
+
* call, as in `app.pause`.
|
|
225
|
+
*/
|
|
226
|
+
pause(reason?: string): Off;
|
|
227
|
+
/** Progress of the current wave of high and normal work, 0..1. Never goes back within a wave. */
|
|
228
|
+
readonly progress: ReadonlySignal<number>;
|
|
229
|
+
/** Settles when the current wave is done, or at once without one. Failures count as done. */
|
|
230
|
+
ready(): Promise<void>;
|
|
231
|
+
/** Counters of the cache. */
|
|
232
|
+
stats(): AssetsStats;
|
|
233
|
+
}
|
|
234
|
+
/** Codes of `AssetError`. */
|
|
235
|
+
type AssetErrorCode = "ASSET_LOAD" | "ASSET_PARSE" | "ASSET_TYPE" | "ASSET_DECODER" | "ASSET_ABORTED";
|
|
236
|
+
declare module "@dioramajs/core" {
|
|
237
|
+
interface Services {
|
|
238
|
+
/** Asset cache and preloading, see `AssetsApi`. */
|
|
239
|
+
assets: AssetsApi;
|
|
240
|
+
}
|
|
241
|
+
interface Hooks {
|
|
242
|
+
/** Runs synchronously once per entry, before caching. For colour space, material tweaks, userData. */
|
|
243
|
+
"assets:transform": (value: unknown, context: {
|
|
244
|
+
readonly type: string;
|
|
245
|
+
readonly url: string;
|
|
246
|
+
}) => unknown;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/** Rejects `Asset.ready`. Reported as `asset:<url>`, which the kernel wraps as `REPORTED`. */
|
|
250
|
+
declare class AssetError extends Error {
|
|
251
|
+
/** Always `AssetError`. */
|
|
252
|
+
override readonly name: "AssetError";
|
|
253
|
+
/** Error code, the key of its page in the docs. */
|
|
254
|
+
readonly code: AssetErrorCode;
|
|
255
|
+
/** URL of the asset, if the error has one. */
|
|
256
|
+
readonly url: string | undefined;
|
|
257
|
+
constructor(code: AssetErrorCode, message: string, options?: {
|
|
258
|
+
readonly url?: string;
|
|
259
|
+
readonly cause?: unknown;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
export { Preload as _, AssetStatus as a, Priority as b, AssetsOptions as c, DecoderOptions as d, LoadOptions as f, Model as g, LoaderEntry as h, AssetLoader as i, AssetsStats as l, LoaderContext as m, Asset as n, AssetTypes as o, Loaded as p, AssetErrorCode as r, AssetsApi as s, AssetError as t, CrossOrigin as u, PreloadOptions as v, PreloadSource as y };
|
|
263
|
+
//# sourceMappingURL=errors-C0aoug0G.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-C0aoug0G.d.ts","names":[],"sources":["../src/types.ts","../src/errors.ts"],"mappings":";;;;;KAMY;;KAEA;;KAEA;;UAGK;;EAEf,OAAO;;EAEP,SAAS;;EAET,MAAM;;EAEN,MAAM;;EAEN,QAAQ;;EAER;;;UAIe;;WAEN,OAAO;;WAEP,qBAAqB;;;;;EAK9B,YAAY;;;UAIG,YAAY;;WAElB,OAAO;;WAEP,WAAW;;;;;;WAMX,cAAc;;WAEd,UAAU,SAAS;;WAEnB,SAAS;;;;;;UAOH,MAAM,GAAG,IAAI;;;EAG5B;;EAEA;;WAES;;WAEA;;WAEA,QAAQ,eAAe;;WAEvB,OAAO,QAAQ;;WAEf,OAAO;;WAEP,OAAO;;;UAID,OAAO;;WAEb,OAAO;;WAEP;;EAET;;WAES;;;UAIM;;WAEN;;WAEA;;WAEA,UAAU;;WAEV,aAAa;;WAEb,SAAS,SAAS;;WAElB,QAAQ;;EAEjB,MAAM,OAAO,cAAc,QAAQ;;EAEnC,MAAM,UAAU,WAAW,QAAQ;;;;;;EAMnC,OAAO,GAAG,YAAY,QAAQ,KAAK,QAAQ;;;;;EAK3C,KAAK,aAAa,aAAa,UAAU,cAAc,MAAM;;EAE7D,UAAU,QAAQ;;WAET,UAAU,SAAS,QAAQ;;;UAIrB,YAAY;;WAElB;;EAET,KAAK,SAAS,gBAAgB,QAAQ,OAAO;;;KAGnC,cACR,qBACO,QAAQ;WAAyB,SAAS;;;UAGpC;;WAEN;aAA2B;aAAqB;;;WAEhD;;WAEA;;WAEA;;;KAIC,6CAA6C;;UAGxC;;WAEN,WAAW;;;;;WAKX,cAAc;;WAEd,gBAAgB;;;UAIV,gBAAgB;;EAE/B;;EAEA;;;UAIe;;WAEN;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,SAAS,SAAS,eAAe;;WAEjC,UAAU,QAAQ;;WAElB;;WAEA;;WAEA;;;UAIM;;;;;;EAMf,KAAK,gBAAgB,YACnB,aACA,SAAS,YAAY;aAAgB,MAAM;MAC1C,MAAM,WAAW;EACpB,KAAK,aAAa,aAAa,UAAU,cAAc,MAAM;;;;;EAK7D,QAAQ,GACN,aACA,OAAO,SAAS,kBAAkB,QAAQ,OAAO,KACjD;aAAqB,WAAW;aAAmB;MAClD,MAAM;;EAET,QAAQ,QAAQ,eAAe,UAAU,iBAAiB;;;;;EAK1D,MACE,MAAM,sBACN;aAAqB;aAA0B,WAAW;;;;;;EAM5D,MAAM,kBAAkB;;WAEf,UAAU;;EAEnB,SAAS;;EAET,SAAS;;;KAIC;;YAQA;;IAER,QAAQ;;YAEA;;IAER,qBACE,gBACA;eAAoB;eAAuB;;;;;cCjQpC,mBAAmB;;oBAEZ;;WAET,MAAM;;WAEN;EAET,YACE,MAAM,gBACN,iBACA;aAAoB;aAAuB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { DEV, withDocs } from "@dioramajs/core/dev";
|
|
2
|
+
// src/errors.ts
|
|
3
|
+
const noop = () => {};
|
|
4
|
+
/** Rejects `Asset.ready`. Reported as `asset:<url>`, which the kernel wraps as `REPORTED`. */
|
|
5
|
+
var AssetError = class extends Error {
|
|
6
|
+
/** Always `AssetError`. */
|
|
7
|
+
name = "AssetError";
|
|
8
|
+
/** Error code, the key of its page in the docs. */
|
|
9
|
+
code;
|
|
10
|
+
/** URL of the asset, if the error has one. */
|
|
11
|
+
url;
|
|
12
|
+
constructor(code, message, options = {}) {
|
|
13
|
+
super(`${code}: ${message}`, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.url = options.url;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Adds the docs page to the message in development builds. Errors pass here on their way out of
|
|
20
|
+
* the plugin, so the three.js loaders don't carry it.
|
|
21
|
+
*/
|
|
22
|
+
function linked(error) {
|
|
23
|
+
error.message = withDocs(error.message, error.code);
|
|
24
|
+
return error;
|
|
25
|
+
}
|
|
26
|
+
const isAbort = (error) => error?.name === "AbortError" || error?.code === "ASSET_ABORTED";
|
|
27
|
+
export { noop as a, linked as i, DEV as n, isAbort as r, AssetError as t };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=errors-DgHytoOg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors-DgHytoOg.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { withDocs } from '@dioramajs/core/dev'\nimport type { AssetErrorCode } from './types'\n\nexport { DEV } from '@dioramajs/core/dev'\n\nexport const noop = (): void => {}\n\n/** Rejects `Asset.ready`. Reported as `asset:<url>`, which the kernel wraps as `REPORTED`. */\nexport class AssetError extends Error {\n /** Always `AssetError`. */\n override readonly name: 'AssetError' = 'AssetError'\n /** Error code, the key of its page in the docs. */\n readonly code: AssetErrorCode\n /** URL of the asset, if the error has one. */\n readonly url: string | undefined\n\n constructor(\n code: AssetErrorCode,\n message: string,\n options: { readonly url?: string; readonly cause?: unknown } = {},\n ) {\n super(`${code}: ${message}`, options.cause === undefined ? undefined : { cause: options.cause })\n this.code = code\n this.url = options.url\n }\n}\n\n/**\n * Adds the docs page to the message in development builds. Errors pass here on their way out of\n * the plugin, so the three.js loaders don't carry it.\n */\nexport function linked<E extends AssetError>(error: E): E {\n error.message = withDocs(error.message, error.code)\n return error\n}\n\nexport const isAbort = (error: unknown): boolean =>\n (error as { name?: string } | null)?.name === 'AbortError' ||\n (error as { code?: string } | null)?.code === 'ASSET_ABORTED'\n"],"mappings":";;AAKA,MAAa,aAAmB,CAAC;;AAGjC,IAAa,aAAb,cAAgC,MAAM;;CAEpC,OAAuC;;CAEvC;;CAEA;CAEA,YACE,MACA,SACA,UAA+D,CAAC,GAChE;EACA,MAAM,GAAG,KAAK,IAAI,WAAW,QAAQ,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,QAAQ,MAAM,CAAC;EAC/F,KAAK,OAAO;EACZ,KAAK,MAAM,QAAQ;CACrB;AACF;;;;;AAMA,SAAgB,OAA6B,OAAa;CACxD,MAAM,UAAU,SAAS,MAAM,SAAS,MAAM,IAAI;CAClD,OAAO;AACT;AAEA,MAAa,WAAW,UACrB,OAAoC,SAAS,gBAC7C,OAAoC,SAAS"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { _ as Preload, a as AssetStatus, b as Priority, c as AssetsOptions, d as DecoderOptions, f as LoadOptions, g as Model, h as LoaderEntry, i as AssetLoader, l as AssetsStats, m as LoaderContext, n as Asset, o as AssetTypes, p as Loaded, r as AssetErrorCode, s as AssetsApi, t as AssetError, u as CrossOrigin, v as PreloadOptions, y as PreloadSource } from "./errors-C0aoug0G.js";
|
|
2
|
+
import { Plugin } from "@dioramajs/core";
|
|
3
|
+
/**
|
|
4
|
+
* `app.assets`. One cache with leases for media and models, a priority queue, preloading of
|
|
5
|
+
* the next page and the progress wave of a preloader.
|
|
6
|
+
*/
|
|
7
|
+
export declare const assets: Plugin<"assets", AssetsOptions, AssetsApi>;
|
|
8
|
+
export { type Asset, AssetError, type AssetErrorCode, type AssetLoader, type AssetStatus, type AssetTypes, type AssetsApi, type AssetsOptions, type AssetsStats, type CrossOrigin, type DecoderOptions, type LoadOptions, type Loaded, type LoaderContext, type LoaderEntry, type Model, type Preload, type PreloadOptions, type PreloadSource, type Priority };
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.ts"],"mappings":";;;;;;qBA0Sa,QAAQ,iBAAiB,eAAe"}
|