@drawcall/glts 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Drawcall
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 ADDED
@@ -0,0 +1,83 @@
1
+ # @drawcall/glts
2
+
3
+ **Like glTF, but for procedural Three.js assets.**
4
+
5
+ `@drawcall/glts` loads trusted TypeScript modules as composable Three.js assets.
6
+ It compiles them in the browser, resolves nested `.glts` and npm imports, and
7
+ keeps a stable `THREE.Group` wrapper around every asset for atomic reloads.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ pnpm add @drawcall/glts three
13
+ ```
14
+
15
+ ## Load an asset
16
+
17
+ ```ts
18
+ import { GLTSLoader } from "@drawcall/glts"
19
+
20
+ const loader = new GLTSLoader()
21
+ const tree = await loader.loadAsync("/assets/tree.glts")
22
+
23
+ scene.add(tree.scene)
24
+
25
+ await tree.reload()
26
+ await loader.reload("/assets/branch.glts")
27
+
28
+ tree.dispose()
29
+ loader.dispose()
30
+ ```
31
+
32
+ `load()` is also available with the familiar Three.js callback API.
33
+
34
+ The default loader fetches the matching esbuild WebAssembly binary from unpkg.
35
+ To bundle it with your application, install `esbuild-wasm@0.28.2` directly and
36
+ pass its URL. For example, Vite supports the following standard asset URL
37
+ import without a GLTS-specific plugin:
38
+
39
+ ```ts
40
+ import esbuildWasmURL from "esbuild-wasm/esbuild.wasm?url"
41
+ import { GLTSLoader } from "@drawcall/glts"
42
+
43
+ const loader = new GLTSLoader(undefined, { esbuildWasmURL })
44
+ ```
45
+
46
+ ## Write an asset
47
+
48
+ Each `.glts` file default-exports a no-argument class derived from
49
+ `THREE.Object3D`:
50
+
51
+ ```ts
52
+ import * as THREE from "three"
53
+ import Branch from "./branch.glts"
54
+
55
+ export default class Tree extends THREE.Group {
56
+ constructor() {
57
+ super()
58
+ this.add(new Branch())
59
+ }
60
+
61
+ dispose() {
62
+ // Release resources owned by this asset.
63
+ }
64
+ }
65
+ ```
66
+
67
+ Asset modules can import `three`, Three.js addons, nested `.glts` assets, and
68
+ bare npm packages. `import.meta.url` resolves to the original asset URL so
69
+ relative textures and other resources continue to work.
70
+
71
+ ## V1 constraints
72
+
73
+ Dynamic imports, import attributes, local helper `.ts` modules, cyclic module
74
+ graphs, cross-asset inheritance, and custom-method contracts across a `.glts`
75
+ boundary are intentionally outside V1.
76
+
77
+ ## Security
78
+
79
+ GLTS is executable code, not a sandbox or serialization format. Only load
80
+ assets you trust; they run with the page's full JavaScript authority.
81
+
82
+ Three.js `0.160.0` or newer is required as a peer dependency. Licensed under
83
+ MIT.
@@ -0,0 +1,12 @@
1
+ import { Loader, type LoadingManager } from "three";
2
+ import type { GLTSAsset, GLTSErrorCallback, GLTSLoadCallback, GLTSLoaderOptions, GLTSProgressCallback } from "./types.js";
3
+ export declare class GLTSLoader extends Loader {
4
+ #private;
5
+ constructor(manager?: LoadingManager, options?: GLTSLoaderOptions);
6
+ load(url: string, onLoad: GLTSLoadCallback, onProgress?: GLTSProgressCallback, onError?: GLTSErrorCallback): void;
7
+ loadAsync(url: string, onProgress?: GLTSProgressCallback): Promise<GLTSAsset>;
8
+ has(url: string): boolean;
9
+ reload(url: string): Promise<void>;
10
+ dispose(): void;
11
+ }
12
+ //# sourceMappingURL=GLTSLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GLTSLoader.d.ts","sourceRoot":"","sources":["../src/GLTSLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,KAAK,cAAc,EACpB,MAAM,OAAO,CAAC;AAQf,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EAEjB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AA0DpB,qBAAa,UAAW,SAAQ,MAAM;;gBAUlC,OAAO,GAAE,cAAsC,EAC/C,OAAO,GAAE,iBAAsB;IAwBxB,IAAI,CACX,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,oBAAoB,EACjC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,IAAI;IAWQ,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC;IA0B5F,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAInB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBxC,OAAO,IAAI,IAAI;CAwEhB"}
@@ -0,0 +1,182 @@
1
+ import { DefaultLoadingManager, Loader } from "three";
2
+ import * as THREE from "three";
3
+ import { defaultEsbuildWasmURL } from "./compiler.js";
4
+ import { GLTSError } from "./errors.js";
5
+ import { canonicalGLTSURL, ModuleGraph, threeRevision } from "./module-graph.js";
6
+ import { ModuleURLStore } from "./module-url-store.js";
7
+ import { WrapperRuntime } from "./runtime.js";
8
+ function environmentBaseURL() {
9
+ if (typeof document !== "undefined") {
10
+ return new URL(document.baseURI);
11
+ }
12
+ if (typeof location !== "undefined") {
13
+ return new URL(location.href);
14
+ }
15
+ return new URL("http://localhost/");
16
+ }
17
+ function resolvedOptionURL(value, fallback, base) {
18
+ return new URL(value ?? fallback, base);
19
+ }
20
+ class GLTSAssetHandle {
21
+ scene;
22
+ url;
23
+ #reloadAsset;
24
+ #disposeAsset;
25
+ #disposed = false;
26
+ constructor(scene, url, reloadAsset, disposeAsset) {
27
+ this.scene = scene;
28
+ this.url = url;
29
+ this.#reloadAsset = reloadAsset;
30
+ this.#disposeAsset = disposeAsset;
31
+ }
32
+ async reload() {
33
+ if (this.#disposed) {
34
+ throw new GLTSError("Asset handle has been disposed", {
35
+ url: this.url,
36
+ phase: "reload"
37
+ });
38
+ }
39
+ await this.#reloadAsset();
40
+ }
41
+ dispose() {
42
+ if (this.#disposed) {
43
+ return;
44
+ }
45
+ this.#disposed = true;
46
+ this.#disposeAsset();
47
+ }
48
+ }
49
+ export class GLTSLoader extends Loader {
50
+ #baseURL;
51
+ #baseFetch;
52
+ #runtime;
53
+ #graph;
54
+ #assets = new Set();
55
+ #reloadQueues = new Map();
56
+ #disposed = false;
57
+ constructor(manager = DefaultLoadingManager, options = {}) {
58
+ super(manager);
59
+ const environmentBase = environmentBaseURL();
60
+ this.#baseURL = resolvedOptionURL(options.baseURL, environmentBase.href, environmentBase);
61
+ this.#baseFetch = options.fetch ?? ((input, init) => globalThis.fetch(input, init));
62
+ const moduleURLs = new ModuleURLStore();
63
+ this.#runtime = new WrapperRuntime(moduleURLs);
64
+ this.#graph = new ModuleGraph({
65
+ cdnURL: resolvedOptionURL(options.cdnURL, "https://esm.sh/", this.#baseURL),
66
+ esbuildWasmURL: resolvedOptionURL(options.esbuildWasmURL, defaultEsbuildWasmURL(), this.#baseURL).href,
67
+ fetch: (input, init) => this.#fetch(input, init),
68
+ moduleURLs,
69
+ runtime: this.#runtime,
70
+ threeRevision: threeRevision(THREE)
71
+ });
72
+ }
73
+ load(url, onLoad, onProgress, onError) {
74
+ void this.loadAsync(url, onProgress).then(onLoad, (error) => {
75
+ if (onError) {
76
+ onError(error);
77
+ return;
78
+ }
79
+ console.error(error);
80
+ });
81
+ }
82
+ async loadAsync(url, onProgress) {
83
+ this.#assertActive(url);
84
+ void onProgress;
85
+ const resolvedURL = this.#resolveURL(url);
86
+ return this.#trackLoading(resolvedURL, async () => {
87
+ const prepared = await this.#graph.prepareAsset(resolvedURL, { activate: true, force: false });
88
+ const scene = this.#runtime.createRoot(prepared.url);
89
+ let handle;
90
+ handle = new GLTSAssetHandle(scene, prepared.url, () => this.reload(prepared.url), () => {
91
+ this.#runtime.disposeWrapper(scene);
92
+ this.#assets.delete(handle);
93
+ });
94
+ this.#assets.add(handle);
95
+ return handle;
96
+ });
97
+ }
98
+ has(url) {
99
+ return this.#graph.hasAsset(this.#resolveURL(url));
100
+ }
101
+ async reload(url) {
102
+ this.#assertActive(url);
103
+ const resolvedURL = this.#resolveURL(url);
104
+ const previous = this.#reloadQueues.get(resolvedURL) ?? Promise.resolve();
105
+ const next = previous.catch(() => undefined).then(() => this.#trackLoading(resolvedURL, async () => {
106
+ const prepared = await this.#graph.prepareAsset(resolvedURL, { activate: false, force: true });
107
+ this.#runtime.replace(resolvedURL, prepared.assetClass);
108
+ this.#graph.activateAsset(prepared);
109
+ }));
110
+ this.#reloadQueues.set(resolvedURL, next);
111
+ try {
112
+ await next;
113
+ }
114
+ finally {
115
+ if (this.#reloadQueues.get(resolvedURL) === next) {
116
+ this.#reloadQueues.delete(resolvedURL);
117
+ }
118
+ }
119
+ }
120
+ dispose() {
121
+ if (this.#disposed) {
122
+ return;
123
+ }
124
+ const errors = [];
125
+ for (const asset of [...this.#assets]) {
126
+ try {
127
+ asset.dispose();
128
+ }
129
+ catch (error) {
130
+ errors.push(error);
131
+ }
132
+ }
133
+ try {
134
+ this.#runtime.dispose();
135
+ }
136
+ catch (error) {
137
+ errors.push(error);
138
+ }
139
+ this.#disposed = true;
140
+ if (errors.length > 0) {
141
+ throw new GLTSError("Loader disposal failed", { url: "glts://loader", phase: "dispose" }, new AggregateError(errors));
142
+ }
143
+ }
144
+ async #trackLoading(url, operation) {
145
+ this.manager.itemStart(url);
146
+ try {
147
+ return await operation();
148
+ }
149
+ catch (error) {
150
+ this.manager.itemError(url);
151
+ throw error;
152
+ }
153
+ finally {
154
+ this.manager.itemEnd(url);
155
+ }
156
+ }
157
+ #resolveURL(url) {
158
+ const managedURL = this.manager.resolveURL(`${this.path}${url}`);
159
+ return canonicalGLTSURL(managedURL, this.#baseURL);
160
+ }
161
+ #fetch(input, init) {
162
+ const headers = new Headers(init?.headers);
163
+ for (const [name, value] of Object.entries(this.requestHeader)) {
164
+ headers.set(name, value);
165
+ }
166
+ const requestInit = { ...init, headers };
167
+ if (this.withCredentials) {
168
+ requestInit.credentials = "include";
169
+ }
170
+ return this.#baseFetch(input, requestInit);
171
+ }
172
+ #assertActive(url) {
173
+ if (!this.#disposed) {
174
+ return;
175
+ }
176
+ throw new GLTSError("Loader has been disposed", {
177
+ url,
178
+ phase: "resolve"
179
+ });
180
+ }
181
+ }
182
+ //# sourceMappingURL=GLTSLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GLTSLoader.js","sourceRoot":"","sources":["../src/GLTSLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,MAAM,EAEP,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB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C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,WAAW,CAAC,GAAW;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC;QACjE,OAAO,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,CAAC,KAAwB,EAAE,IAAkB;QACjD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC/D,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3B,CAAC;QAED,MAAM,WAAW,GAAgB,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC;QACtD,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,WAAW,CAAC,WAAW,GAAG,SAAS,CAAC;QACtC,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED,aAAa,CAAC,GAAW;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,IAAI,SAAS,CAAC,0BAA0B,EAAE;YAC9C,GAAG;YACH,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export declare function defaultEsbuildWasmURL(): string;
2
+ export declare function compileTypeScript(source: string, sourceURL: string, wasmURL: string): Promise<string>;
3
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAOA,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAyBD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAejB"}
@@ -0,0 +1,38 @@
1
+ const ESBUILD_VERSION = "0.28.2";
2
+ let compiler;
3
+ let initialization;
4
+ let initializedWasmURL;
5
+ export function defaultEsbuildWasmURL() {
6
+ return `https://unpkg.com/esbuild-wasm@${ESBUILD_VERSION}/esbuild.wasm`;
7
+ }
8
+ async function loadCompiler() {
9
+ compiler ??= import("esbuild-wasm");
10
+ return compiler;
11
+ }
12
+ async function initializeCompiler(wasmURL) {
13
+ const esbuild = await loadCompiler();
14
+ if (initialization && initializedWasmURL !== wasmURL) {
15
+ throw new Error(`esbuild-wasm is already initialized with ${initializedWasmURL}; cannot switch to ${wasmURL}`);
16
+ }
17
+ if (!initialization) {
18
+ initializedWasmURL = wasmURL;
19
+ initialization = esbuild.initialize({ wasmURL, worker: true });
20
+ }
21
+ await initialization;
22
+ return esbuild;
23
+ }
24
+ export async function compileTypeScript(source, sourceURL, wasmURL) {
25
+ const esbuild = await initializeCompiler(wasmURL);
26
+ const result = await esbuild.transform(source, {
27
+ format: "esm",
28
+ legalComments: "inline",
29
+ loader: "ts",
30
+ minify: false,
31
+ sourcefile: sourceURL,
32
+ sourcemap: "inline",
33
+ sourcesContent: true,
34
+ target: "es2022"
35
+ });
36
+ return result.code;
37
+ }
38
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,QAAQ,CAAC;AACjC,IAAI,QAAsC,CAAC;AAC3C,IAAI,cAAyC,CAAC;AAC9C,IAAI,kBAAsC,CAAC;AAE3C,MAAM,UAAU,qBAAqB;IACnC,OAAO,kCAAkC,eAAe,eAAe,CAAC;AAC1E,CAAC;AAED,KAAK,UAAU,YAAY;IACzB,QAAQ,KAAK,MAAM,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,KAAK,UAAU,kBAAkB,CAAC,OAAe;IAC/C,MAAM,OAAO,GAAG,MAAM,YAAY,EAAE,CAAC;IAErC,IAAI,cAAc,IAAI,kBAAkB,KAAK,OAAO,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,4CAA4C,kBAAkB,sBAAsB,OAAO,EAAE,CAC9F,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,kBAAkB,GAAG,OAAO,CAAC;QAC7B,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,cAAc,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAc,EACd,SAAiB,EACjB,OAAe;IAEf,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAElD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE;QAC7C,MAAM,EAAE,KAAK;QACb,aAAa,EAAE,QAAQ;QACvB,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,QAAQ;QACnB,cAAc,EAAE,IAAI;QACpB,MAAM,EAAE,QAAQ;KACjB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC"}
@@ -0,0 +1,14 @@
1
+ export type GLTSPhase = "resolve" | "fetch" | "transform" | "evaluate" | "construct" | "reload" | "dispose";
2
+ export interface GLTSErrorContext {
3
+ readonly url: string;
4
+ readonly phase: GLTSPhase;
5
+ readonly importChain?: readonly string[];
6
+ }
7
+ export declare class GLTSError extends Error {
8
+ readonly url: string;
9
+ readonly phase: GLTSPhase;
10
+ readonly importChain: readonly string[];
11
+ constructor(message: string, context: GLTSErrorContext, cause?: unknown);
12
+ }
13
+ export declare function toGLTSError(error: unknown, message: string, context: GLTSErrorContext): GLTSError;
14
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,OAAO,GACP,WAAW,GACX,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,CAAC;AAEd,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;gBAE5B,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,OAAO;CAaxE;AAED,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,GACxB,SAAS,CAMX"}
package/dist/errors.js ADDED
@@ -0,0 +1,23 @@
1
+ export class GLTSError extends Error {
2
+ url;
3
+ phase;
4
+ importChain;
5
+ constructor(message, context, cause) {
6
+ const chain = context.importChain ?? [];
7
+ const chainMessage = chain.length > 1 ? `\nImport chain: ${chain.join(" -> ")}` : "";
8
+ super(`[GLTS:${context.phase}] ${message}\nURL: ${context.url}${chainMessage}`, {
9
+ cause
10
+ });
11
+ this.name = "GLTSError";
12
+ this.url = context.url;
13
+ this.phase = context.phase;
14
+ this.importChain = chain;
15
+ }
16
+ }
17
+ export function toGLTSError(error, message, context) {
18
+ if (error instanceof GLTSError) {
19
+ return error;
20
+ }
21
+ return new GLTSError(message, context, error);
22
+ }
23
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,GAAG,CAAS;IACZ,KAAK,CAAY;IACjB,WAAW,CAAoB;IAExC,YAAY,OAAe,EAAE,OAAyB,EAAE,KAAe;QACrE,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QACxC,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAErF,KAAK,CAAC,SAAS,OAAO,CAAC,KAAK,KAAK,OAAO,UAAU,OAAO,CAAC,GAAG,GAAG,YAAY,EAAE,EAAE;YAC9E,KAAK;SACN,CAAC,CAAC;QAEH,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CACzB,KAAc,EACd,OAAe,EACf,OAAyB;IAEzB,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { GLTSError, type GLTSPhase } from "./errors.js";
2
+ export { GLTSLoader } from "./GLTSLoader.js";
3
+ export type { GLTSAsset, GLTSErrorCallback, GLTSFetch, GLTSLoadCallback, GLTSLoaderOptions, GLTSProgressCallback } from "./types.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { GLTSError } from "./errors.js";
2
+ export { GLTSLoader } from "./GLTSLoader.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type * as THREE from "three";
2
+ import { ModuleURLStore } from "./module-url-store.js";
3
+ import type { WrapperRuntime } from "./runtime.js";
4
+ import type { GLTSAssetClass, GLTSFetch } from "./types.js";
5
+ interface PreparedAsset {
6
+ readonly assetClass: GLTSAssetClass;
7
+ readonly moduleURL: string;
8
+ readonly source: string;
9
+ readonly url: string;
10
+ }
11
+ interface ModuleGraphOptions {
12
+ readonly cdnURL: URL;
13
+ readonly esbuildWasmURL: string;
14
+ readonly fetch: GLTSFetch;
15
+ readonly moduleURLs: ModuleURLStore;
16
+ readonly runtime: WrapperRuntime;
17
+ readonly threeRevision: string;
18
+ }
19
+ export declare class ModuleGraph {
20
+ #private;
21
+ constructor(options: ModuleGraphOptions);
22
+ hasAsset(url: string): boolean;
23
+ prepareAsset(url: string, options: {
24
+ readonly activate: boolean;
25
+ readonly force: boolean;
26
+ }, importChain?: readonly string[]): Promise<PreparedAsset>;
27
+ activateAsset(prepared: PreparedAsset): void;
28
+ }
29
+ export declare function canonicalGLTSURL(input: string | URL, baseURL: URL): string;
30
+ export declare function threeRevision(three: typeof THREE): string;
31
+ export {};
32
+ //# sourceMappingURL=module-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-graph.d.ts","sourceRoot":"","sources":["../src/module-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAIpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5D,UAAU,aAAa;IACrB,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAOD,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC;IACrB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAqDD,qBAAa,WAAW;;gBAaV,OAAO,EAAE,kBAAkB;IASvC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIxB,YAA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