@motion-core/motion-gpu 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/advanced.d.ts +1 -0
- package/dist/advanced.d.ts.map +1 -0
- package/dist/advanced.js +12 -6
- package/dist/core/advanced.d.ts +1 -0
- package/dist/core/advanced.d.ts.map +1 -0
- package/dist/core/advanced.js +12 -5
- package/dist/core/current-value.d.ts +1 -0
- package/dist/core/current-value.d.ts.map +1 -0
- package/dist/core/current-value.js +35 -34
- package/dist/core/current-value.js.map +1 -0
- package/dist/core/error-diagnostics.d.ts +1 -0
- package/dist/core/error-diagnostics.d.ts.map +1 -0
- package/dist/core/error-diagnostics.js +70 -137
- package/dist/core/error-diagnostics.js.map +1 -0
- package/dist/core/error-report.d.ts +1 -0
- package/dist/core/error-report.d.ts.map +1 -0
- package/dist/core/error-report.js +184 -233
- package/dist/core/error-report.js.map +1 -0
- package/dist/core/frame-registry.d.ts +1 -0
- package/dist/core/frame-registry.d.ts.map +1 -0
- package/dist/core/frame-registry.js +546 -662
- package/dist/core/frame-registry.js.map +1 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +11 -12
- package/dist/core/material-preprocess.d.ts +1 -0
- package/dist/core/material-preprocess.d.ts.map +1 -0
- package/dist/core/material-preprocess.js +128 -151
- package/dist/core/material-preprocess.js.map +1 -0
- package/dist/core/material.d.ts +1 -0
- package/dist/core/material.d.ts.map +1 -0
- package/dist/core/material.js +263 -317
- package/dist/core/material.js.map +1 -0
- package/dist/core/recompile-policy.d.ts +1 -0
- package/dist/core/recompile-policy.d.ts.map +1 -0
- package/dist/core/recompile-policy.js +18 -13
- package/dist/core/recompile-policy.js.map +1 -0
- package/dist/core/render-graph.d.ts +1 -0
- package/dist/core/render-graph.d.ts.map +1 -0
- package/dist/core/render-graph.js +61 -68
- package/dist/core/render-graph.js.map +1 -0
- package/dist/core/render-targets.d.ts +2 -0
- package/dist/core/render-targets.d.ts.map +1 -0
- package/dist/core/render-targets.js +52 -53
- package/dist/core/render-targets.js.map +1 -0
- package/dist/core/renderer.d.ts +1 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/renderer.js +942 -1081
- package/dist/core/renderer.js.map +1 -0
- package/dist/core/runtime-loop.d.ts +2 -0
- package/dist/core/runtime-loop.d.ts.map +1 -0
- package/dist/core/runtime-loop.js +305 -362
- package/dist/core/runtime-loop.js.map +1 -0
- package/dist/core/scheduler-helpers.d.ts +1 -0
- package/dist/core/scheduler-helpers.d.ts.map +1 -0
- package/dist/core/scheduler-helpers.js +52 -51
- package/dist/core/scheduler-helpers.js.map +1 -0
- package/dist/core/shader.d.ts +1 -0
- package/dist/core/shader.d.ts.map +1 -0
- package/dist/core/shader.js +92 -117
- package/dist/core/shader.js.map +1 -0
- package/dist/core/texture-loader.d.ts +1 -0
- package/dist/core/texture-loader.d.ts.map +1 -0
- package/dist/core/texture-loader.js +205 -273
- package/dist/core/texture-loader.js.map +1 -0
- package/dist/core/textures.d.ts +2 -0
- package/dist/core/textures.d.ts.map +1 -0
- package/dist/core/textures.js +106 -116
- package/dist/core/textures.js.map +1 -0
- package/dist/core/types.d.ts +2 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +0 -4
- package/dist/core/uniforms.d.ts +1 -0
- package/dist/core/uniforms.d.ts.map +1 -0
- package/dist/core/uniforms.js +170 -191
- package/dist/core/uniforms.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -6
- package/dist/passes/BlitPass.d.ts +1 -0
- package/dist/passes/BlitPass.d.ts.map +1 -0
- package/dist/passes/BlitPass.js +23 -18
- package/dist/passes/BlitPass.js.map +1 -0
- package/dist/passes/CopyPass.d.ts +2 -0
- package/dist/passes/CopyPass.d.ts.map +1 -0
- package/dist/passes/CopyPass.js +58 -52
- package/dist/passes/CopyPass.js.map +1 -0
- package/dist/passes/FullscreenPass.d.ts +2 -0
- package/dist/passes/FullscreenPass.d.ts.map +1 -0
- package/dist/passes/FullscreenPass.js +127 -130
- package/dist/passes/FullscreenPass.js.map +1 -0
- package/dist/passes/ShaderPass.d.ts +1 -0
- package/dist/passes/ShaderPass.d.ts.map +1 -0
- package/dist/passes/ShaderPass.js +40 -37
- package/dist/passes/ShaderPass.js.map +1 -0
- package/dist/passes/index.d.ts +1 -0
- package/dist/passes/index.d.ts.map +1 -0
- package/dist/passes/index.js +4 -3
- package/dist/react/FragCanvas.d.ts +2 -0
- package/dist/react/FragCanvas.d.ts.map +1 -0
- package/dist/react/FragCanvas.js +234 -211
- package/dist/react/FragCanvas.js.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts +1 -0
- package/dist/react/MotionGPUErrorOverlay.d.ts.map +1 -0
- package/dist/react/MotionGPUErrorOverlay.js +384 -48
- package/dist/react/MotionGPUErrorOverlay.js.map +1 -0
- package/dist/react/Portal.d.ts +1 -0
- package/dist/react/Portal.d.ts.map +1 -0
- package/dist/react/Portal.js +18 -21
- package/dist/react/Portal.js.map +1 -0
- package/dist/react/advanced.d.ts +1 -0
- package/dist/react/advanced.d.ts.map +1 -0
- package/dist/react/advanced.js +12 -6
- package/dist/react/frame-context.d.ts +1 -0
- package/dist/react/frame-context.d.ts.map +1 -0
- package/dist/react/frame-context.js +88 -94
- package/dist/react/frame-context.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +10 -9
- package/dist/react/motiongpu-context.d.ts +1 -0
- package/dist/react/motiongpu-context.d.ts.map +1 -0
- package/dist/react/motiongpu-context.js +18 -15
- package/dist/react/motiongpu-context.js.map +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts +1 -0
- package/dist/react/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/react/use-motiongpu-user-context.js +83 -82
- package/dist/react/use-motiongpu-user-context.js.map +1 -0
- package/dist/react/use-texture.d.ts +1 -0
- package/dist/react/use-texture.d.ts.map +1 -0
- package/dist/react/use-texture.js +132 -152
- package/dist/react/use-texture.js.map +1 -0
- package/dist/svelte/FragCanvas.svelte.d.ts +2 -0
- package/dist/svelte/FragCanvas.svelte.d.ts.map +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte +17 -20
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts +1 -0
- package/dist/svelte/MotionGPUErrorOverlay.svelte.d.ts.map +1 -0
- package/dist/svelte/Portal.svelte.d.ts +1 -0
- package/dist/svelte/Portal.svelte.d.ts.map +1 -0
- package/dist/svelte/advanced.d.ts +1 -0
- package/dist/svelte/advanced.d.ts.map +1 -0
- package/dist/svelte/advanced.js +11 -6
- package/dist/svelte/frame-context.d.ts +1 -0
- package/dist/svelte/frame-context.d.ts.map +1 -0
- package/dist/svelte/frame-context.js +27 -27
- package/dist/svelte/frame-context.js.map +1 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +10 -9
- package/dist/svelte/motiongpu-context.d.ts +1 -0
- package/dist/svelte/motiongpu-context.d.ts.map +1 -0
- package/dist/svelte/motiongpu-context.js +24 -21
- package/dist/svelte/motiongpu-context.js.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts +1 -0
- package/dist/svelte/use-motiongpu-user-context.d.ts.map +1 -0
- package/dist/svelte/use-motiongpu-user-context.js +69 -70
- package/dist/svelte/use-motiongpu-user-context.js.map +1 -0
- package/dist/svelte/use-texture.d.ts +1 -0
- package/dist/svelte/use-texture.d.ts.map +1 -0
- package/dist/svelte/use-texture.js +125 -147
- package/dist/svelte/use-texture.js.map +1 -0
- package/package.json +15 -7
- package/src/lib/advanced.ts +6 -0
- package/src/lib/core/advanced.ts +12 -0
- package/src/lib/core/current-value.ts +64 -0
- package/src/lib/core/error-diagnostics.ts +236 -0
- package/src/lib/core/error-report.ts +406 -0
- package/src/lib/core/frame-registry.ts +1189 -0
- package/src/lib/core/index.ts +77 -0
- package/src/lib/core/material-preprocess.ts +284 -0
- package/src/lib/core/material.ts +667 -0
- package/src/lib/core/recompile-policy.ts +31 -0
- package/src/lib/core/render-graph.ts +143 -0
- package/src/lib/core/render-targets.ts +107 -0
- package/src/lib/core/renderer.ts +1547 -0
- package/src/lib/core/runtime-loop.ts +458 -0
- package/src/lib/core/scheduler-helpers.ts +136 -0
- package/src/lib/core/shader.ts +258 -0
- package/src/lib/core/texture-loader.ts +476 -0
- package/src/lib/core/textures.ts +235 -0
- package/src/lib/core/types.ts +582 -0
- package/src/lib/core/uniforms.ts +282 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/passes/BlitPass.ts +54 -0
- package/src/lib/passes/CopyPass.ts +80 -0
- package/src/lib/passes/FullscreenPass.ts +173 -0
- package/src/lib/passes/ShaderPass.ts +88 -0
- package/src/lib/passes/index.ts +3 -0
- package/src/lib/react/MotionGPUErrorOverlay.tsx +392 -0
- package/src/lib/react/advanced.ts +36 -0
- package/src/lib/react/frame-context.ts +169 -0
- package/src/lib/react/index.ts +51 -0
- package/src/lib/react/motiongpu-context.ts +88 -0
- package/src/lib/react/use-motiongpu-user-context.ts +186 -0
- package/src/lib/react/use-texture.ts +233 -0
- package/src/lib/svelte/FragCanvas.svelte +249 -0
- package/src/lib/svelte/MotionGPUErrorOverlay.svelte +382 -0
- package/src/lib/svelte/Portal.svelte +31 -0
- package/src/lib/svelte/advanced.ts +32 -0
- package/src/lib/svelte/frame-context.ts +87 -0
- package/src/lib/svelte/index.ts +51 -0
- package/src/lib/svelte/motiongpu-context.ts +97 -0
- package/src/lib/svelte/use-motiongpu-user-context.ts +145 -0
- package/src/lib/svelte/use-texture.ts +232 -0
- package/dist/react/MotionGPUErrorOverlay.tsx +0 -129
- /package/{dist → src/lib}/react/FragCanvas.tsx +0 -0
- /package/{dist → src/lib}/react/Portal.tsx +0 -0
|
@@ -1,295 +1,227 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/lib/core/texture-loader.ts
|
|
2
|
+
var resourceCache = /* @__PURE__ */ new Map();
|
|
2
3
|
function createAbortError() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
return new DOMException("Texture request was aborted", "AbortError");
|
|
6
|
+
} catch {
|
|
7
|
+
const error = /* @__PURE__ */ new Error("Texture request was aborted");
|
|
8
|
+
error.name = "AbortError";
|
|
9
|
+
return error;
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
(error.name === 'AbortError' || error.message.toLowerCase().includes('aborted')));
|
|
13
|
+
* Checks whether error represents abort cancellation.
|
|
14
|
+
*/
|
|
15
|
+
function isAbortError(error) {
|
|
16
|
+
return error instanceof Error && (error.name === "AbortError" || error.message.toLowerCase().includes("aborted"));
|
|
18
17
|
}
|
|
19
18
|
function toBodyFingerprint(body) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (typeof FormData !== 'undefined' && body instanceof FormData) {
|
|
30
|
-
const entries = Array.from(body.entries()).map(([key, value]) => `${key}:${String(value)}`);
|
|
31
|
-
return `formdata:${entries.join('&')}`;
|
|
32
|
-
}
|
|
33
|
-
if (body instanceof Blob) {
|
|
34
|
-
return `blob:${body.type}:${body.size}`;
|
|
35
|
-
}
|
|
36
|
-
if (body instanceof ArrayBuffer) {
|
|
37
|
-
return `arraybuffer:${body.byteLength}`;
|
|
38
|
-
}
|
|
39
|
-
if (ArrayBuffer.isView(body)) {
|
|
40
|
-
return `view:${body.byteLength}`;
|
|
41
|
-
}
|
|
42
|
-
return `opaque:${Object.prototype.toString.call(body)}`;
|
|
19
|
+
if (body == null) return null;
|
|
20
|
+
if (typeof body === "string") return `string:${body}`;
|
|
21
|
+
if (body instanceof URLSearchParams) return `urlsearchparams:${body.toString()}`;
|
|
22
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) return `formdata:${Array.from(body.entries()).map(([key, value]) => `${key}:${String(value)}`).join("&")}`;
|
|
23
|
+
if (body instanceof Blob) return `blob:${body.type}:${body.size}`;
|
|
24
|
+
if (body instanceof ArrayBuffer) return `arraybuffer:${body.byteLength}`;
|
|
25
|
+
if (ArrayBuffer.isView(body)) return `view:${body.byteLength}`;
|
|
26
|
+
return `opaque:${Object.prototype.toString.call(body)}`;
|
|
43
27
|
}
|
|
44
28
|
function normalizeRequestInit(requestInit) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
normalized.body = toBodyFingerprint(requestInit.body);
|
|
63
|
-
return normalized;
|
|
29
|
+
if (!requestInit) return {};
|
|
30
|
+
const headers = new Headers(requestInit.headers);
|
|
31
|
+
const headerEntries = Array.from(headers.entries()).sort(([a], [b]) => a.localeCompare(b));
|
|
32
|
+
const normalized = {};
|
|
33
|
+
normalized.method = (requestInit.method ?? "GET").toUpperCase();
|
|
34
|
+
normalized.mode = requestInit.mode ?? null;
|
|
35
|
+
normalized.cache = requestInit.cache ?? null;
|
|
36
|
+
normalized.credentials = requestInit.credentials ?? null;
|
|
37
|
+
normalized.redirect = requestInit.redirect ?? null;
|
|
38
|
+
normalized.referrer = requestInit.referrer ?? null;
|
|
39
|
+
normalized.referrerPolicy = requestInit.referrerPolicy ?? null;
|
|
40
|
+
normalized.integrity = requestInit.integrity ?? null;
|
|
41
|
+
normalized.keepalive = requestInit.keepalive ?? false;
|
|
42
|
+
normalized.priority = requestInit.priority ?? null;
|
|
43
|
+
normalized.headers = headerEntries;
|
|
44
|
+
normalized.body = toBodyFingerprint(requestInit.body);
|
|
45
|
+
return normalized;
|
|
64
46
|
}
|
|
65
47
|
function normalizeTextureLoadOptions(options) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
normalized.update = options.update;
|
|
83
|
-
}
|
|
84
|
-
if (options.flipY !== undefined) {
|
|
85
|
-
normalized.flipY = options.flipY;
|
|
86
|
-
}
|
|
87
|
-
if (options.premultipliedAlpha !== undefined) {
|
|
88
|
-
normalized.premultipliedAlpha = options.premultipliedAlpha;
|
|
89
|
-
}
|
|
90
|
-
if (options.generateMipmaps !== undefined) {
|
|
91
|
-
normalized.generateMipmaps = options.generateMipmaps;
|
|
92
|
-
}
|
|
93
|
-
return normalized;
|
|
48
|
+
const colorSpace = options.colorSpace ?? "srgb";
|
|
49
|
+
const normalized = {
|
|
50
|
+
colorSpace,
|
|
51
|
+
decode: {
|
|
52
|
+
colorSpaceConversion: options.decode?.colorSpaceConversion ?? (colorSpace === "linear" ? "none" : "default"),
|
|
53
|
+
premultiplyAlpha: options.decode?.premultiplyAlpha ?? "default",
|
|
54
|
+
imageOrientation: options.decode?.imageOrientation ?? "none"
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (options.requestInit !== void 0) normalized.requestInit = options.requestInit;
|
|
58
|
+
if (options.signal !== void 0) normalized.signal = options.signal;
|
|
59
|
+
if (options.update !== void 0) normalized.update = options.update;
|
|
60
|
+
if (options.flipY !== void 0) normalized.flipY = options.flipY;
|
|
61
|
+
if (options.premultipliedAlpha !== void 0) normalized.premultipliedAlpha = options.premultipliedAlpha;
|
|
62
|
+
if (options.generateMipmaps !== void 0) normalized.generateMipmaps = options.generateMipmaps;
|
|
63
|
+
return normalized;
|
|
94
64
|
}
|
|
95
65
|
/**
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
66
|
+
* Builds deterministic resource cache key from full URL IO config.
|
|
67
|
+
*/
|
|
68
|
+
function buildTextureResourceCacheKey(url, options = {}) {
|
|
69
|
+
const normalized = normalizeTextureLoadOptions(options);
|
|
70
|
+
return JSON.stringify({
|
|
71
|
+
url,
|
|
72
|
+
colorSpace: normalized.colorSpace,
|
|
73
|
+
requestInit: normalizeRequestInit(normalized.requestInit),
|
|
74
|
+
decode: normalized.decode
|
|
75
|
+
});
|
|
106
76
|
}
|
|
107
77
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
entry.controller.abort();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
resourceCache.clear();
|
|
78
|
+
* Clears the internal texture resource cache.
|
|
79
|
+
*/
|
|
80
|
+
function clearTextureBlobCache() {
|
|
81
|
+
for (const entry of resourceCache.values()) if (!entry.settled) entry.controller.abort();
|
|
82
|
+
resourceCache.clear();
|
|
117
83
|
}
|
|
118
84
|
function acquireTextureBlob(url, options) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (released) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
released = true;
|
|
177
|
-
entry.refs = Math.max(0, entry.refs - 1);
|
|
178
|
-
if (entry.refs === 0) {
|
|
179
|
-
if (!entry.settled) {
|
|
180
|
-
entry.controller.abort();
|
|
181
|
-
}
|
|
182
|
-
resourceCache.delete(key);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
};
|
|
85
|
+
const key = buildTextureResourceCacheKey(url, options);
|
|
86
|
+
const existing = resourceCache.get(key);
|
|
87
|
+
if (existing) {
|
|
88
|
+
existing.refs += 1;
|
|
89
|
+
let released = false;
|
|
90
|
+
return {
|
|
91
|
+
entry: existing,
|
|
92
|
+
release: () => {
|
|
93
|
+
if (released) return;
|
|
94
|
+
released = true;
|
|
95
|
+
existing.refs = Math.max(0, existing.refs - 1);
|
|
96
|
+
if (existing.refs === 0) {
|
|
97
|
+
if (!existing.settled) existing.controller.abort();
|
|
98
|
+
resourceCache.delete(key);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const normalized = normalizeTextureLoadOptions(options);
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
const requestInit = {
|
|
106
|
+
...normalized.requestInit ?? {},
|
|
107
|
+
signal: controller.signal
|
|
108
|
+
};
|
|
109
|
+
const entry = {
|
|
110
|
+
key,
|
|
111
|
+
refs: 1,
|
|
112
|
+
controller,
|
|
113
|
+
settled: false,
|
|
114
|
+
blobPromise: fetch(url, requestInit).then(async (response) => {
|
|
115
|
+
if (!response.ok) throw new Error(`Texture request failed (${response.status}) for ${url}`);
|
|
116
|
+
return response.blob();
|
|
117
|
+
}).then((blob) => {
|
|
118
|
+
entry.settled = true;
|
|
119
|
+
return blob;
|
|
120
|
+
}).catch((error) => {
|
|
121
|
+
resourceCache.delete(key);
|
|
122
|
+
throw error;
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
resourceCache.set(key, entry);
|
|
126
|
+
let released = false;
|
|
127
|
+
return {
|
|
128
|
+
entry,
|
|
129
|
+
release: () => {
|
|
130
|
+
if (released) return;
|
|
131
|
+
released = true;
|
|
132
|
+
entry.refs = Math.max(0, entry.refs - 1);
|
|
133
|
+
if (entry.refs === 0) {
|
|
134
|
+
if (!entry.settled) entry.controller.abort();
|
|
135
|
+
resourceCache.delete(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
186
139
|
}
|
|
187
140
|
async function awaitWithAbort(promise, signal) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
promise.then(resolve, reject).finally(() => {
|
|
200
|
-
signal.removeEventListener('abort', onAbort);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
141
|
+
if (!signal) return promise;
|
|
142
|
+
if (signal.aborted) throw createAbortError();
|
|
143
|
+
return new Promise((resolve, reject) => {
|
|
144
|
+
const onAbort = () => {
|
|
145
|
+
reject(createAbortError());
|
|
146
|
+
};
|
|
147
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
148
|
+
promise.then(resolve, reject).finally(() => {
|
|
149
|
+
signal.removeEventListener("abort", onAbort);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
203
152
|
}
|
|
204
153
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
loaded.flipY = normalized.flipY;
|
|
251
|
-
}
|
|
252
|
-
if (normalized.premultipliedAlpha !== undefined) {
|
|
253
|
-
loaded.premultipliedAlpha = normalized.premultipliedAlpha;
|
|
254
|
-
}
|
|
255
|
-
if (normalized.generateMipmaps !== undefined) {
|
|
256
|
-
loaded.generateMipmaps = normalized.generateMipmaps;
|
|
257
|
-
}
|
|
258
|
-
return loaded;
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
if (bitmap) {
|
|
262
|
-
bitmap.close();
|
|
263
|
-
}
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
finally {
|
|
267
|
-
release();
|
|
268
|
-
}
|
|
154
|
+
* Loads a single texture from URL and converts it to an `ImageBitmap`.
|
|
155
|
+
*
|
|
156
|
+
* @param url - Texture URL.
|
|
157
|
+
* @param options - Loading options.
|
|
158
|
+
* @returns Loaded texture object.
|
|
159
|
+
* @throws {Error} When runtime does not support `createImageBitmap` or request fails.
|
|
160
|
+
*/
|
|
161
|
+
async function loadTextureFromUrl(url, options = {}) {
|
|
162
|
+
if (typeof createImageBitmap !== "function") throw new Error("createImageBitmap is not available in this runtime");
|
|
163
|
+
const normalized = normalizeTextureLoadOptions(options);
|
|
164
|
+
const { entry, release } = acquireTextureBlob(url, options);
|
|
165
|
+
let bitmap = null;
|
|
166
|
+
try {
|
|
167
|
+
const blob = await awaitWithAbort(entry.blobPromise, normalized.signal);
|
|
168
|
+
const bitmapOptions = {
|
|
169
|
+
colorSpaceConversion: normalized.decode.colorSpaceConversion,
|
|
170
|
+
premultiplyAlpha: normalized.decode.premultiplyAlpha,
|
|
171
|
+
imageOrientation: normalized.decode.imageOrientation
|
|
172
|
+
};
|
|
173
|
+
bitmap = bitmapOptions.colorSpaceConversion === "default" && bitmapOptions.premultiplyAlpha === "default" && bitmapOptions.imageOrientation === "none" ? await createImageBitmap(blob) : await createImageBitmap(blob, bitmapOptions);
|
|
174
|
+
if (normalized.signal?.aborted) {
|
|
175
|
+
bitmap.close();
|
|
176
|
+
throw createAbortError();
|
|
177
|
+
}
|
|
178
|
+
const loaded = {
|
|
179
|
+
url,
|
|
180
|
+
source: bitmap,
|
|
181
|
+
width: bitmap.width,
|
|
182
|
+
height: bitmap.height,
|
|
183
|
+
colorSpace: normalized.colorSpace,
|
|
184
|
+
dispose: () => {
|
|
185
|
+
bitmap?.close();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
if (normalized.update !== void 0) loaded.update = normalized.update;
|
|
189
|
+
if (normalized.flipY !== void 0) loaded.flipY = normalized.flipY;
|
|
190
|
+
if (normalized.premultipliedAlpha !== void 0) loaded.premultipliedAlpha = normalized.premultipliedAlpha;
|
|
191
|
+
if (normalized.generateMipmaps !== void 0) loaded.generateMipmaps = normalized.generateMipmaps;
|
|
192
|
+
return loaded;
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (bitmap) bitmap.close();
|
|
195
|
+
throw error;
|
|
196
|
+
} finally {
|
|
197
|
+
release();
|
|
198
|
+
}
|
|
269
199
|
}
|
|
270
200
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
return loaded;
|
|
201
|
+
* Loads many textures in parallel from URLs.
|
|
202
|
+
*
|
|
203
|
+
* @param urls - Texture URLs.
|
|
204
|
+
* @param options - Shared loading options.
|
|
205
|
+
* @returns Promise resolving to loaded textures in input order.
|
|
206
|
+
*/
|
|
207
|
+
async function loadTexturesFromUrls(urls, options = {}) {
|
|
208
|
+
const settled = await Promise.allSettled(urls.map((url) => loadTextureFromUrl(url, options)));
|
|
209
|
+
const loaded = [];
|
|
210
|
+
let firstError = null;
|
|
211
|
+
for (const entry of settled) {
|
|
212
|
+
if (entry.status === "fulfilled") {
|
|
213
|
+
loaded.push(entry.value);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
firstError ??= entry.reason;
|
|
217
|
+
}
|
|
218
|
+
if (firstError) {
|
|
219
|
+
for (const texture of loaded) texture.dispose();
|
|
220
|
+
throw firstError;
|
|
221
|
+
}
|
|
222
|
+
return loaded;
|
|
295
223
|
}
|
|
224
|
+
//#endregion
|
|
225
|
+
export { buildTextureResourceCacheKey, clearTextureBlobCache, isAbortError, loadTextureFromUrl, loadTexturesFromUrls };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=texture-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture-loader.js","names":[],"sources":["../../src/lib/core/texture-loader.ts"],"sourcesContent":["import type { TextureUpdateMode } from './types.js';\n\n/**\n * Options controlling bitmap decode behavior.\n */\nexport interface TextureDecodeOptions {\n\t/**\n\t * Controls color-space conversion during decode.\n\t */\n\tcolorSpaceConversion?: 'default' | 'none';\n\t/**\n\t * Controls alpha premultiplication during decode.\n\t */\n\tpremultiplyAlpha?: 'default' | 'none' | 'premultiply';\n\t/**\n\t * Controls bitmap orientation during decode.\n\t */\n\timageOrientation?: 'none' | 'flipY';\n}\n\n/**\n * Options controlling URL-based texture loading and decode behavior.\n */\nexport interface TextureLoadOptions {\n\t/**\n\t * Desired texture color space.\n\t */\n\tcolorSpace?: 'srgb' | 'linear';\n\t/**\n\t * Fetch options forwarded to `fetch`.\n\t */\n\trequestInit?: RequestInit;\n\t/**\n\t * Decode options forwarded to `createImageBitmap`.\n\t */\n\tdecode?: TextureDecodeOptions;\n\t/**\n\t * Optional cancellation signal for this request.\n\t */\n\tsignal?: AbortSignal;\n\t/**\n\t * Optional runtime update strategy metadata attached to loaded textures.\n\t */\n\tupdate?: TextureUpdateMode;\n\t/**\n\t * Optional runtime flip-y metadata attached to loaded textures.\n\t */\n\tflipY?: boolean;\n\t/**\n\t * Optional runtime premultiplied-alpha metadata attached to loaded textures.\n\t */\n\tpremultipliedAlpha?: boolean;\n\t/**\n\t * Optional runtime mipmap metadata attached to loaded textures.\n\t */\n\tgenerateMipmaps?: boolean;\n}\n\n/**\n * Loaded texture payload returned by URL loaders.\n */\nexport interface LoadedTexture {\n\t/**\n\t * Source URL.\n\t */\n\turl: string;\n\t/**\n\t * Decoded bitmap source.\n\t */\n\tsource: ImageBitmap;\n\t/**\n\t * Bitmap width in pixels.\n\t */\n\twidth: number;\n\t/**\n\t * Bitmap height in pixels.\n\t */\n\theight: number;\n\t/**\n\t * Effective color space.\n\t */\n\tcolorSpace: 'srgb' | 'linear';\n\t/**\n\t * Effective runtime update strategy.\n\t */\n\tupdate?: TextureUpdateMode;\n\t/**\n\t * Effective runtime flip-y metadata.\n\t */\n\tflipY?: boolean;\n\t/**\n\t * Effective runtime premultiplied-alpha metadata.\n\t */\n\tpremultipliedAlpha?: boolean;\n\t/**\n\t * Effective runtime mipmap metadata.\n\t */\n\tgenerateMipmaps?: boolean;\n\t/**\n\t * Releases bitmap resources.\n\t */\n\tdispose: () => void;\n}\n\ninterface NormalizedTextureLoadOptions {\n\tcolorSpace: 'srgb' | 'linear';\n\trequestInit?: RequestInit;\n\tdecode: Required<TextureDecodeOptions>;\n\tsignal?: AbortSignal;\n\tupdate?: TextureUpdateMode;\n\tflipY?: boolean;\n\tpremultipliedAlpha?: boolean;\n\tgenerateMipmaps?: boolean;\n}\n\ninterface TextureResourceCacheEntry {\n\tkey: string;\n\trefs: number;\n\tcontroller: AbortController;\n\tsettled: boolean;\n\tblobPromise: Promise<Blob>;\n}\n\nconst resourceCache = new Map<string, TextureResourceCacheEntry>();\n\nfunction createAbortError(): Error {\n\ttry {\n\t\treturn new DOMException('Texture request was aborted', 'AbortError');\n\t} catch {\n\t\tconst error = new Error('Texture request was aborted');\n\t\t(error as Error & { name: string }).name = 'AbortError';\n\t\treturn error;\n\t}\n}\n\n/**\n * Checks whether error represents abort cancellation.\n */\nexport function isAbortError(error: unknown): boolean {\n\treturn (\n\t\terror instanceof Error &&\n\t\t(error.name === 'AbortError' || error.message.toLowerCase().includes('aborted'))\n\t);\n}\n\nfunction toBodyFingerprint(body: BodyInit | null | undefined): string | null {\n\tif (body == null) {\n\t\treturn null;\n\t}\n\n\tif (typeof body === 'string') {\n\t\treturn `string:${body}`;\n\t}\n\n\tif (body instanceof URLSearchParams) {\n\t\treturn `urlsearchparams:${body.toString()}`;\n\t}\n\n\tif (typeof FormData !== 'undefined' && body instanceof FormData) {\n\t\tconst entries = Array.from(body.entries()).map(([key, value]) => `${key}:${String(value)}`);\n\t\treturn `formdata:${entries.join('&')}`;\n\t}\n\n\tif (body instanceof Blob) {\n\t\treturn `blob:${body.type}:${body.size}`;\n\t}\n\n\tif (body instanceof ArrayBuffer) {\n\t\treturn `arraybuffer:${body.byteLength}`;\n\t}\n\n\tif (ArrayBuffer.isView(body)) {\n\t\treturn `view:${body.byteLength}`;\n\t}\n\n\treturn `opaque:${Object.prototype.toString.call(body)}`;\n}\n\nfunction normalizeRequestInit(requestInit: RequestInit | undefined): Record<string, unknown> {\n\tif (!requestInit) {\n\t\treturn {};\n\t}\n\n\tconst headers = new Headers(requestInit.headers);\n\tconst headerEntries = Array.from(headers.entries()).sort(([a], [b]) => a.localeCompare(b));\n\tconst normalized: Record<string, unknown> = {};\n\n\tnormalized.method = (requestInit.method ?? 'GET').toUpperCase();\n\tnormalized.mode = requestInit.mode ?? null;\n\tnormalized.cache = requestInit.cache ?? null;\n\tnormalized.credentials = requestInit.credentials ?? null;\n\tnormalized.redirect = requestInit.redirect ?? null;\n\tnormalized.referrer = requestInit.referrer ?? null;\n\tnormalized.referrerPolicy = requestInit.referrerPolicy ?? null;\n\tnormalized.integrity = requestInit.integrity ?? null;\n\tnormalized.keepalive = requestInit.keepalive ?? false;\n\tnormalized.priority = requestInit.priority ?? null;\n\tnormalized.headers = headerEntries;\n\tnormalized.body = toBodyFingerprint(requestInit.body);\n\n\treturn normalized;\n}\n\nfunction normalizeTextureLoadOptions(options: TextureLoadOptions): NormalizedTextureLoadOptions {\n\tconst colorSpace = options.colorSpace ?? 'srgb';\n\n\tconst normalized: NormalizedTextureLoadOptions = {\n\t\tcolorSpace,\n\t\tdecode: {\n\t\t\tcolorSpaceConversion:\n\t\t\t\toptions.decode?.colorSpaceConversion ?? (colorSpace === 'linear' ? 'none' : 'default'),\n\t\t\tpremultiplyAlpha: options.decode?.premultiplyAlpha ?? 'default',\n\t\t\timageOrientation: options.decode?.imageOrientation ?? 'none'\n\t\t}\n\t};\n\n\tif (options.requestInit !== undefined) {\n\t\tnormalized.requestInit = options.requestInit;\n\t}\n\tif (options.signal !== undefined) {\n\t\tnormalized.signal = options.signal;\n\t}\n\tif (options.update !== undefined) {\n\t\tnormalized.update = options.update;\n\t}\n\tif (options.flipY !== undefined) {\n\t\tnormalized.flipY = options.flipY;\n\t}\n\tif (options.premultipliedAlpha !== undefined) {\n\t\tnormalized.premultipliedAlpha = options.premultipliedAlpha;\n\t}\n\tif (options.generateMipmaps !== undefined) {\n\t\tnormalized.generateMipmaps = options.generateMipmaps;\n\t}\n\n\treturn normalized;\n}\n\n/**\n * Builds deterministic resource cache key from full URL IO config.\n */\nexport function buildTextureResourceCacheKey(\n\turl: string,\n\toptions: TextureLoadOptions = {}\n): string {\n\tconst normalized = normalizeTextureLoadOptions(options);\n\treturn JSON.stringify({\n\t\turl,\n\t\tcolorSpace: normalized.colorSpace,\n\t\trequestInit: normalizeRequestInit(normalized.requestInit),\n\t\tdecode: normalized.decode\n\t});\n}\n\n/**\n * Clears the internal texture resource cache.\n */\nexport function clearTextureBlobCache(): void {\n\tfor (const entry of resourceCache.values()) {\n\t\tif (!entry.settled) {\n\t\t\tentry.controller.abort();\n\t\t}\n\t}\n\tresourceCache.clear();\n}\n\nfunction acquireTextureBlob(\n\turl: string,\n\toptions: TextureLoadOptions\n): {\n\tentry: TextureResourceCacheEntry;\n\trelease: () => void;\n} {\n\tconst key = buildTextureResourceCacheKey(url, options);\n\tconst existing = resourceCache.get(key);\n\tif (existing) {\n\t\texisting.refs += 1;\n\t\tlet released = false;\n\t\treturn {\n\t\t\tentry: existing,\n\t\t\trelease: () => {\n\t\t\t\tif (released) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\treleased = true;\n\t\t\t\texisting.refs = Math.max(0, existing.refs - 1);\n\t\t\t\tif (existing.refs === 0) {\n\t\t\t\t\tif (!existing.settled) {\n\t\t\t\t\t\texisting.controller.abort();\n\t\t\t\t\t}\n\t\t\t\t\tresourceCache.delete(key);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tconst normalized = normalizeTextureLoadOptions(options);\n\tconst controller = new AbortController();\n\tconst requestInit = {\n\t\t...(normalized.requestInit ?? {}),\n\t\tsignal: controller.signal\n\t} satisfies RequestInit;\n\tconst entry: TextureResourceCacheEntry = {\n\t\tkey,\n\t\trefs: 1,\n\t\tcontroller,\n\t\tsettled: false,\n\t\tblobPromise: fetch(url, requestInit)\n\t\t\t.then(async (response) => {\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`Texture request failed (${response.status}) for ${url}`);\n\t\t\t\t}\n\t\t\t\treturn response.blob();\n\t\t\t})\n\t\t\t.then((blob) => {\n\t\t\t\tentry.settled = true;\n\t\t\t\treturn blob;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tresourceCache.delete(key);\n\t\t\t\tthrow error;\n\t\t\t})\n\t};\n\n\tresourceCache.set(key, entry);\n\tlet released = false;\n\treturn {\n\t\tentry,\n\t\trelease: () => {\n\t\t\tif (released) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treleased = true;\n\t\t\tentry.refs = Math.max(0, entry.refs - 1);\n\t\t\tif (entry.refs === 0) {\n\t\t\t\tif (!entry.settled) {\n\t\t\t\t\tentry.controller.abort();\n\t\t\t\t}\n\t\t\t\tresourceCache.delete(key);\n\t\t\t}\n\t\t}\n\t};\n}\n\nasync function awaitWithAbort<T>(promise: Promise<T>, signal: AbortSignal | undefined): Promise<T> {\n\tif (!signal) {\n\t\treturn promise;\n\t}\n\n\tif (signal.aborted) {\n\t\tthrow createAbortError();\n\t}\n\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst onAbort = (): void => {\n\t\t\treject(createAbortError());\n\t\t};\n\n\t\tsignal.addEventListener('abort', onAbort, { once: true });\n\n\t\tpromise.then(resolve, reject).finally(() => {\n\t\t\tsignal.removeEventListener('abort', onAbort);\n\t\t});\n\t});\n}\n\n/**\n * Loads a single texture from URL and converts it to an `ImageBitmap`.\n *\n * @param url - Texture URL.\n * @param options - Loading options.\n * @returns Loaded texture object.\n * @throws {Error} When runtime does not support `createImageBitmap` or request fails.\n */\nexport async function loadTextureFromUrl(\n\turl: string,\n\toptions: TextureLoadOptions = {}\n): Promise<LoadedTexture> {\n\tif (typeof createImageBitmap !== 'function') {\n\t\tthrow new Error('createImageBitmap is not available in this runtime');\n\t}\n\n\tconst normalized = normalizeTextureLoadOptions(options);\n\tconst { entry, release } = acquireTextureBlob(url, options);\n\tlet bitmap: ImageBitmap | null = null;\n\n\ttry {\n\t\tconst blob = await awaitWithAbort(entry.blobPromise, normalized.signal);\n\n\t\tconst bitmapOptions: ImageBitmapOptions = {\n\t\t\tcolorSpaceConversion: normalized.decode.colorSpaceConversion,\n\t\t\tpremultiplyAlpha: normalized.decode.premultiplyAlpha,\n\t\t\timageOrientation: normalized.decode.imageOrientation\n\t\t};\n\t\tconst allDefaults =\n\t\t\tbitmapOptions.colorSpaceConversion === 'default' &&\n\t\t\tbitmapOptions.premultiplyAlpha === 'default' &&\n\t\t\tbitmapOptions.imageOrientation === 'none';\n\n\t\tbitmap = allDefaults\n\t\t\t? await createImageBitmap(blob)\n\t\t\t: await createImageBitmap(blob, bitmapOptions);\n\n\t\tif (normalized.signal?.aborted) {\n\t\t\tbitmap.close();\n\t\t\tthrow createAbortError();\n\t\t}\n\n\t\tconst loaded: LoadedTexture = {\n\t\t\turl,\n\t\t\tsource: bitmap,\n\t\t\twidth: bitmap.width,\n\t\t\theight: bitmap.height,\n\t\t\tcolorSpace: normalized.colorSpace,\n\t\t\tdispose: () => {\n\t\t\t\tbitmap?.close();\n\t\t\t}\n\t\t};\n\n\t\tif (normalized.update !== undefined) {\n\t\t\tloaded.update = normalized.update;\n\t\t}\n\t\tif (normalized.flipY !== undefined) {\n\t\t\tloaded.flipY = normalized.flipY;\n\t\t}\n\t\tif (normalized.premultipliedAlpha !== undefined) {\n\t\t\tloaded.premultipliedAlpha = normalized.premultipliedAlpha;\n\t\t}\n\t\tif (normalized.generateMipmaps !== undefined) {\n\t\t\tloaded.generateMipmaps = normalized.generateMipmaps;\n\t\t}\n\n\t\treturn loaded;\n\t} catch (error) {\n\t\tif (bitmap) {\n\t\t\tbitmap.close();\n\t\t}\n\t\tthrow error;\n\t} finally {\n\t\trelease();\n\t}\n}\n\n/**\n * Loads many textures in parallel from URLs.\n *\n * @param urls - Texture URLs.\n * @param options - Shared loading options.\n * @returns Promise resolving to loaded textures in input order.\n */\nexport async function loadTexturesFromUrls(\n\turls: string[],\n\toptions: TextureLoadOptions = {}\n): Promise<LoadedTexture[]> {\n\tconst settled = await Promise.allSettled(urls.map((url) => loadTextureFromUrl(url, options)));\n\tconst loaded: LoadedTexture[] = [];\n\tlet firstError: unknown = null;\n\n\tfor (const entry of settled) {\n\t\tif (entry.status === 'fulfilled') {\n\t\t\tloaded.push(entry.value);\n\t\t\tcontinue;\n\t\t}\n\n\t\tfirstError ??= entry.reason;\n\t}\n\n\tif (firstError) {\n\t\tfor (const texture of loaded) {\n\t\t\ttexture.dispose();\n\t\t}\n\t\tthrow firstError;\n\t}\n\n\treturn loaded;\n}\n"],"mappings":";AA2HA,IAAM,gCAAgB,IAAI,KAAwC;AAElE,SAAS,mBAA0B;AAClC,KAAI;AACH,SAAO,IAAI,aAAa,+BAA+B,aAAa;SAC7D;EACP,MAAM,wBAAQ,IAAI,MAAM,8BAA8B;AACrD,QAAmC,OAAO;AAC3C,SAAO;;;;;;AAOT,SAAgB,aAAa,OAAyB;AACrD,QACC,iBAAiB,UAChB,MAAM,SAAS,gBAAgB,MAAM,QAAQ,aAAa,CAAC,SAAS,UAAU;;AAIjF,SAAS,kBAAkB,MAAkD;AAC5E,KAAI,QAAQ,KACX,QAAO;AAGR,KAAI,OAAO,SAAS,SACnB,QAAO,UAAU;AAGlB,KAAI,gBAAgB,gBACnB,QAAO,mBAAmB,KAAK,UAAU;AAG1C,KAAI,OAAO,aAAa,eAAe,gBAAgB,SAEtD,QAAO,YADS,MAAM,KAAK,KAAK,SAAS,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,MAAM,GAAG,CAChE,KAAK,IAAI;AAGrC,KAAI,gBAAgB,KACnB,QAAO,QAAQ,KAAK,KAAK,GAAG,KAAK;AAGlC,KAAI,gBAAgB,YACnB,QAAO,eAAe,KAAK;AAG5B,KAAI,YAAY,OAAO,KAAK,CAC3B,QAAO,QAAQ,KAAK;AAGrB,QAAO,UAAU,OAAO,UAAU,SAAS,KAAK,KAAK;;AAGtD,SAAS,qBAAqB,aAA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GAEhB;AAED,MAAI,WAAW,WAAW,OACzB,QAAO,SAAS,WAAW;AAE5B,MAAI,WAAW,UAAU,OACxB,QAAO,QAAQ,WAAW;AAE3B,MAAI,WAAW,uBAAuB,OACrC,QAAO,qBAAqB,WAAW;AAExC,MAAI,WAAW,oBAAoB,OAClC,QAAO,kBAAkB,WAAW;AAGrC,SAAO;UACC,OAAO;AACf,MAAI,OACH,QAAO,OAAO;AAEf,QAAM;WACG;AACT,WAAS;;;;;;;;;;AAWX,eAAsB,qBACrB,MACA,UAA8B,EAAE,EACL;CAC3B,MAAM,UAAU,MAAM,QAAQ,WAAW,KAAK,KAAK,QAAQ,mBAAmB,KAAK,QAAQ,CAAC,CAAC;CAC7F,MAAM,SAA0B,EAAE;CAClC,IAAI,aAAsB;AAE1B,MAAK,MAAM,SAAS,SAAS;AAC5B,MAAI,MAAM,WAAW,aAAa;AACjC,UAAO,KAAK,MAAM,MAAM;AACxB;;AAGD,iBAAe,MAAM;;AAGtB,KAAI,YAAY;AACf,OAAK,MAAM,WAAW,OACrB,SAAQ,SAAS;AAElB,QAAM;;AAGP,QAAO"}
|
package/dist/core/textures.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="@webgpu/types" />
|
|
1
2
|
import type { TextureData, TextureDefinition, TextureDefinitionMap, TextureUpdateMode, TextureValue } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Texture definition with defaults and normalized numeric limits applied.
|
|
@@ -112,3 +113,4 @@ export declare function getTextureMipLevelCount(width: number, height: number):
|
|
|
112
113
|
* Checks whether the source is an `HTMLVideoElement`.
|
|
113
114
|
*/
|
|
114
115
|
export declare function isVideoTextureSource(source: TextureData['source']): source is HTMLVideoElement;
|
|
116
|
+
//# sourceMappingURL=textures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textures.d.ts","sourceRoot":"","sources":["../../src/lib/core/textures.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,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