@godot-scene-web/project 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 +21 -0
- package/dist/fetch.d.ts +147 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +535 -0
- package/dist/fetch.js.map +1 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +316 -0
- package/dist/node.js.map +1 -0
- package/dist/shared-Dgi2oc_H.d.ts +34 -0
- package/dist/shared-Dgi2oc_H.d.ts.map +1 -0
- package/dist/theme-query-ClAPxgZ7.js +43 -0
- package/dist/theme-query-ClAPxgZ7.js.map +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomás Fox
|
|
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/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { t as GodotProjectResolvedResource } from "./shared-Dgi2oc_H.js";
|
|
2
|
+
import { GodotExtResource, GodotNode, GodotResource, GodotResourceRefValue, GodotSceneState, GodotVariant } from "@godot-scene-web/core";
|
|
3
|
+
|
|
4
|
+
//#region src/fetch.d.ts
|
|
5
|
+
type GodotFetchCacheSnapshot<T> = {
|
|
6
|
+
status: "ready";
|
|
7
|
+
path: string;
|
|
8
|
+
value: T;
|
|
9
|
+
} | {
|
|
10
|
+
status: "pending";
|
|
11
|
+
path: string;
|
|
12
|
+
promise: Promise<T>;
|
|
13
|
+
} | {
|
|
14
|
+
status: "error";
|
|
15
|
+
path: string;
|
|
16
|
+
message: string;
|
|
17
|
+
error: unknown;
|
|
18
|
+
};
|
|
19
|
+
interface GodotFetchDocumentCache<T> {
|
|
20
|
+
peek: (resourcePath: string) => GodotFetchCacheSnapshot<T> | undefined;
|
|
21
|
+
load: (resourcePath: string) => Promise<T>;
|
|
22
|
+
preload: (resourcePath: string) => Promise<void>;
|
|
23
|
+
subscribe: (listener: () => void) => () => void;
|
|
24
|
+
}
|
|
25
|
+
interface GodotFetchProjectResolverOptions {
|
|
26
|
+
assetBaseUrl?: string | ((resourcePath: string) => string);
|
|
27
|
+
fetch?: (input: string) => Promise<Pick<Response, "ok" | "status" | "text">>;
|
|
28
|
+
/**
|
|
29
|
+
* Transitive prefetch: the moment a scene/resource document parses, kick loads
|
|
30
|
+
* for every `.tscn`/`.tres`/`.res` it references, so a tree's dependencies fan
|
|
31
|
+
* out level-parallel instead of being discovered one consumer render at a time.
|
|
32
|
+
* Off by default — lazy consumers rely on hidden external scenes NOT fetching.
|
|
33
|
+
*/
|
|
34
|
+
preloadDependencies?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Intrinsic pixel size for a direct image resource (a `Texture2D` ExtResource
|
|
37
|
+
* pointing at a `.png`/`.webp`/…), from host asset metadata (captured/extracted).
|
|
38
|
+
* Used so `NinePatchRect` 9-slice margins that exceed the texture (event_button.png:
|
|
39
|
+
* 284px wide, 192px L/R margins) clamp to the source the way Godot does, and so a
|
|
40
|
+
* `Sprite2D` box can size to its texture. Return `undefined` when unknown — in a
|
|
41
|
+
* browser the resolver then falls back to measuring the decoded image itself (see
|
|
42
|
+
* the `imageSizes` cache); outside a browser the texture resolves without a size,
|
|
43
|
+
* as before.
|
|
44
|
+
*/
|
|
45
|
+
resourceSize?: (resourcePath: string) => {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Crop an AtlasTexture sprite (a region of a larger atlas page) into a standalone
|
|
51
|
+
* image, returning a usable URL (e.g. a `blob:`/`data:` URL the host produced with a
|
|
52
|
+
* canvas). Used ONLY when the atlas page resolves to an EXTERNAL url (not a `data:`
|
|
53
|
+
* URL): the renderer's built-in SVG crop embeds the atlas via `<image href>`, which
|
|
54
|
+
* browsers block for external refs inside CSS-image SVGs, and CSS `border-image`
|
|
55
|
+
* cannot 9-slice a sub-region of an atlas — so a NinePatch atlas sprite over an
|
|
56
|
+
* external atlas can't be cropped in pure CSS. The host fetches each atlas page ONCE
|
|
57
|
+
* (cached) and crops regions on a canvas, so the page is reused across its sprites.
|
|
58
|
+
* Async: the result settles through the resolver's cache like any other resource, so
|
|
59
|
+
* the consumer re-renders when the crop is ready. Absent ⇒ unchanged behavior (the
|
|
60
|
+
* sprite keeps its embedded-SVG crop / CSS-offset fallback), so goldens and hosts that
|
|
61
|
+
* pre-crop server-side are byte-identical.
|
|
62
|
+
*/
|
|
63
|
+
cropAtlasRegion?: (atlasUrl: string, region: {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
width: number;
|
|
67
|
+
height: number;
|
|
68
|
+
}, margin: {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
width: number;
|
|
72
|
+
height: number;
|
|
73
|
+
}) => Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
interface GodotFetchExternalSceneResolveContext {
|
|
76
|
+
ref: GodotResourceRefValue;
|
|
77
|
+
node: GodotNode;
|
|
78
|
+
nodePath: string;
|
|
79
|
+
props: Record<string, GodotVariant>;
|
|
80
|
+
}
|
|
81
|
+
interface GodotFetchProjectSceneOptions {
|
|
82
|
+
resolveExternalScene: (context: GodotFetchExternalSceneResolveContext) => GodotSceneState | {
|
|
83
|
+
status: "ready";
|
|
84
|
+
scene: GodotSceneState;
|
|
85
|
+
path?: string;
|
|
86
|
+
} | {
|
|
87
|
+
status: "pending";
|
|
88
|
+
path?: string;
|
|
89
|
+
message?: string;
|
|
90
|
+
} | {
|
|
91
|
+
status: "error";
|
|
92
|
+
path?: string;
|
|
93
|
+
message: string;
|
|
94
|
+
} | undefined;
|
|
95
|
+
resolveResource: (ref: GodotResourceRefValue, node: GodotNode) => GodotProjectResolvedResource | undefined;
|
|
96
|
+
resolveResourcePath: (path: string, node: GodotNode) => GodotProjectResolvedResource | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Resolve a theme item (e.g. a font size) for a node from its assigned `theme`
|
|
99
|
+
* resource, following Godot's type-variation -> type -> default cascade. Optional:
|
|
100
|
+
* absent ⇒ the renderer keeps its built-in fallbacks (the prior behavior). The HTML
|
|
101
|
+
* renderer calls this for `font_size`/`normal_font_size`/… when a node carries no
|
|
102
|
+
* inline `theme_override_font_sizes/*`.
|
|
103
|
+
*/
|
|
104
|
+
resolveTheme?: (node: GodotNode, name: string) => GodotVariant | undefined;
|
|
105
|
+
}
|
|
106
|
+
interface GodotFetchProjectResolver {
|
|
107
|
+
resourcePathToUrl: (resourcePath: string) => string;
|
|
108
|
+
scenes: GodotFetchDocumentCache<GodotSceneState>;
|
|
109
|
+
resources: GodotFetchDocumentCache<GodotResource>;
|
|
110
|
+
peekScene: (resourcePath: string) => GodotFetchCacheSnapshot<GodotSceneState> | undefined;
|
|
111
|
+
loadScene: (resourcePath: string) => Promise<GodotSceneState>;
|
|
112
|
+
preload: (resourcePath: string) => Promise<void>;
|
|
113
|
+
subscribe: (listener: () => void) => () => void;
|
|
114
|
+
extResource: (scene: GodotSceneState, ref: GodotResourceRefValue) => GodotExtResource | undefined;
|
|
115
|
+
resolveResource: (scene: GodotSceneState, ref: GodotResourceRefValue, node?: GodotNode) => GodotProjectResolvedResource | undefined;
|
|
116
|
+
resolveResourcePath: (resourcePath: string, type?: string) => GodotProjectResolvedResource | undefined;
|
|
117
|
+
resolveExternalScene: (scene: GodotSceneState, ref: GodotResourceRefValue, node?: GodotNode) => GodotSceneState | {
|
|
118
|
+
status: "ready";
|
|
119
|
+
scene: GodotSceneState;
|
|
120
|
+
path?: string;
|
|
121
|
+
} | {
|
|
122
|
+
status: "pending";
|
|
123
|
+
path?: string;
|
|
124
|
+
message?: string;
|
|
125
|
+
} | {
|
|
126
|
+
status: "error";
|
|
127
|
+
path?: string;
|
|
128
|
+
message: string;
|
|
129
|
+
} | undefined;
|
|
130
|
+
sceneOptions: (scene: GodotSceneState) => GodotFetchProjectSceneOptions;
|
|
131
|
+
/**
|
|
132
|
+
* Monotonic settle counters, one per document cache. A consumer can use them
|
|
133
|
+
* for cache-state-keyed memoization: scene-graph derivation depends on scene
|
|
134
|
+
* documents but never on `.tres` resource content, so a derive memo stays
|
|
135
|
+
* valid while `scenes` is unchanged even as `resources` advances.
|
|
136
|
+
*/
|
|
137
|
+
generations: () => {
|
|
138
|
+
scenes: number;
|
|
139
|
+
resources: number;
|
|
140
|
+
croppedAtlas: number;
|
|
141
|
+
imageSizes: number;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
declare function createGodotFetchProjectResolver(options?: GodotFetchProjectResolverOptions): GodotFetchProjectResolver;
|
|
145
|
+
//#endregion
|
|
146
|
+
export { GodotFetchCacheSnapshot, GodotFetchDocumentCache, GodotFetchExternalSceneResolveContext, GodotFetchProjectResolver, GodotFetchProjectResolverOptions, GodotFetchProjectSceneOptions, type GodotProjectResolvedResource, createGodotFetchProjectResolver };
|
|
147
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","names":[],"sources":["../src/fetch.ts"],"mappings":";;;;KAiEY,uBAAA;EACN,MAAA;EAAiB,IAAA;EAAc,KAAA,EAAO,CAAA;AAAA;EACtC,MAAA;EAAmB,IAAA;EAAc,OAAA,EAAS,OAAA,CAAQ,CAAA;AAAA;EAClD,MAAA;EAAiB,IAAA;EAAc,OAAA;EAAiB,KAAA;AAAA;AAAA,UAErC,uBAAA;EACf,IAAA,GAAO,YAAA,aAAyB,uBAAA,CAAwB,CAAA;EACxD,IAAA,GAAO,YAAA,aAAyB,OAAA,CAAQ,CAAA;EACxC,OAAA,GAAU,YAAA,aAAyB,OAAA;EACnC,SAAA,GAAY,QAAA;AAAA;AAAA,UAGG,gCAAA;EACf,YAAA,cAA0B,YAAA;EAC1B,KAAA,IAAS,KAAA,aAAkB,OAAA,CAAQ,IAAA,CAAK,QAAA;EAXiB;AAAA;AAE3D;;;;EAgBE,mBAAA;EAdwC;;;;;;;;;;EAyBxC,YAAA,IACE,YAAA;IACK,KAAA;IAAe,MAAA;EAAA;EA1BtB;;;;;;AACgC;AAGlC;;;;;;;EAqCE,eAAA,IACE,QAAA,UACA,MAAA;IAAU,CAAA;IAAW,CAAA;IAAW,KAAA;IAAe,MAAA;EAAA,GAC/C,MAAA;IAAU,CAAA;IAAW,CAAA;IAAW,KAAA;IAAe,MAAA;EAAA,MAC5C,OAAA;AAAA;AAAA,UAGU,qCAAA;EACf,GAAA,EAAK,qBAAA;EACL,IAAA,EAAM,SAAA;EACN,QAAA;EACA,KAAA,EAAO,MAAA,SAAe,YAAA;AAAA;AAAA,UAGP,6BAAA;EACf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