@godot-scene-web/layout 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/index.d.ts +127 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1162 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -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/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { GodotNode, GodotRect, GodotResourceRefValue, GodotVariant } from "@godot-scene-web/core";
|
|
2
|
+
import { GodotResourceStatus, GodotSceneNodeBase, GodotTextRunMetric, SceneGraph, SceneGraphNode } from "@godot-scene-web/scene-graph";
|
|
3
|
+
|
|
4
|
+
//#region src/anchor-grammar.d.ts
|
|
5
|
+
interface GodotNodeAnchor {
|
|
6
|
+
anchorTo: string;
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
offset?: {
|
|
10
|
+
x?: number;
|
|
11
|
+
y?: number;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
type GodotAnchorMap = Record<string, GodotNodeAnchor>;
|
|
15
|
+
type GodotAnchorVerticalEdge = "top" | "bottom" | "vcenter" | "contentTop" | "contentBottom";
|
|
16
|
+
type GodotAnchorHorizontalEdge = "left" | "right" | "hcenter" | "contentLeft" | "contentRight";
|
|
17
|
+
interface GodotAnchorEdge {
|
|
18
|
+
vertical: GodotAnchorVerticalEdge;
|
|
19
|
+
horizontal: GodotAnchorHorizontalEdge;
|
|
20
|
+
}
|
|
21
|
+
declare function parseAnchorEdge(token: string): GodotAnchorEdge | undefined;
|
|
22
|
+
declare function anchorEdgePoint(token: string, own: GodotRect, content: GodotRect): {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
} | undefined;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/types.d.ts
|
|
28
|
+
interface GodotSceneTreeNode extends GodotSceneNodeBase {
|
|
29
|
+
rect: GodotRect;
|
|
30
|
+
/**
|
|
31
|
+
* The on-screen global rect with the node's own `scale` applied around
|
|
32
|
+
* `pivotOffset` (mirroring the CSS `transform: scale()` the HTML renderer
|
|
33
|
+
* emits). `rect` stays pre-scale because child layout is computed in the
|
|
34
|
+
* parent's unscaled local space; consumers that need the rendered geometry
|
|
35
|
+
* (e.g. a layout-diff against the live game's `get_global_rect()`, which
|
|
36
|
+
* includes scale) should read `renderedRect`.
|
|
37
|
+
*/
|
|
38
|
+
renderedRect: GodotRect;
|
|
39
|
+
/**
|
|
40
|
+
* The cumulative scale+rotation+translate transform this node applies to its
|
|
41
|
+
* descendants (its own scale-and-rotation-about-pivot composed with its
|
|
42
|
+
* ancestors'), in global unscaled-layout space. Internal to layout: children read
|
|
43
|
+
* it to bake every ancestor's transform into their own `renderedRect`. Stored as a
|
|
44
|
+
* 2×3 affine `{ a, b, c, d, tx, ty }` (a pure scale+translate is `b=c=0`).
|
|
45
|
+
*/
|
|
46
|
+
cumulativeTransform?: {
|
|
47
|
+
a: number;
|
|
48
|
+
b: number;
|
|
49
|
+
c: number;
|
|
50
|
+
d: number;
|
|
51
|
+
tx: number;
|
|
52
|
+
ty: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
interface GodotSceneTreeDiagnostic {
|
|
56
|
+
severity: "warning" | "error";
|
|
57
|
+
code: string;
|
|
58
|
+
message: string;
|
|
59
|
+
nodePath?: string;
|
|
60
|
+
}
|
|
61
|
+
interface GodotSceneTree {
|
|
62
|
+
viewport: GodotRect;
|
|
63
|
+
nodes: GodotSceneTreeNode[];
|
|
64
|
+
diagnostics: GodotSceneTreeDiagnostic[];
|
|
65
|
+
resourceStatuses: GodotResourceStatus[];
|
|
66
|
+
}
|
|
67
|
+
type GodotLayoutModel = GodotSceneTree;
|
|
68
|
+
type GodotLayoutNode = GodotSceneTreeNode;
|
|
69
|
+
type GodotLayoutDiagnostic = GodotSceneTreeDiagnostic;
|
|
70
|
+
/**
|
|
71
|
+
* Options for the computed rect engine. The structural fields (node inclusion,
|
|
72
|
+
* prop/type/instance overrides, repeated-node expansion, external-scene mounting)
|
|
73
|
+
* are inherited from {@link SceneStructureOptions} — they are consumed upstream by
|
|
74
|
+
* `deriveSceneGraph`; the rect engine receives the already-indexed
|
|
75
|
+
* {@link import("@godot-scene-web/core").SceneGraph} and only adds the
|
|
76
|
+
* rect-/resource-specific fields below.
|
|
77
|
+
*/
|
|
78
|
+
interface GodotLayoutOptions {
|
|
79
|
+
viewport?: Partial<GodotRect>;
|
|
80
|
+
resolveResource?: (ref: GodotResourceRefValue, node: GodotNode) => unknown;
|
|
81
|
+
/**
|
|
82
|
+
* Content-driven minimum size for a text node (`Label`/`RichTextLabel`), in
|
|
83
|
+
* logical px — the text analogue of {@link resolveResource} for `TextureRect`.
|
|
84
|
+
* The host measures the label's paragraph box from the actual font it paints
|
|
85
|
+
* with (same font + size + glyph spacing), so a label with no explicit width
|
|
86
|
+
* grows to fit its text the way Godot's `Label::get_minimum_size()` does.
|
|
87
|
+
* Return `undefined` when no measurement is available (preserves the prior
|
|
88
|
+
* behavior of collapsing to the explicit/custom size or 0).
|
|
89
|
+
*
|
|
90
|
+
* `availableWidth` is the laid-out column width when known (the layout pass for
|
|
91
|
+
* a node already placed in its container); the host uses it to word-wrap a
|
|
92
|
+
* reflowing label so its height matches the wrapped paragraph. It is omitted
|
|
93
|
+
* during the bottom-up minimum pass (no width assigned yet) — a wrapping label
|
|
94
|
+
* should then report a width that does not force its container wider.
|
|
95
|
+
*/
|
|
96
|
+
resolveTextContentSize?: (node: GodotNode, path: string, props: Record<string, GodotVariant>, availableWidth?: number) => {
|
|
97
|
+
width: number;
|
|
98
|
+
height: number;
|
|
99
|
+
} | undefined;
|
|
100
|
+
resolveTheme?: (node: GodotNode, name: string) => GodotVariant | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Declarative post-layout anchors, keyed by the anchored node's engine path.
|
|
103
|
+
* Resolved after flow layout converges so a node can be placed relative to
|
|
104
|
+
* another node's rendered (or content) edge. See {@link GodotAnchorMap}.
|
|
105
|
+
*/
|
|
106
|
+
anchorsByPath?: GodotAnchorMap;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/membership.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* The nodes the rect cascade ({@link resolveGodotSceneTree}) would lay out, without
|
|
112
|
+
* running it. The cascade drops exactly one class of node: an invisible child of a
|
|
113
|
+
* Box/Grid/Flow container — and its whole subtree — because a hidden control takes
|
|
114
|
+
* no space in those containers (`visibleChildren` in minimum-size.ts; every other
|
|
115
|
+
* container type and plain parents lay out all children). Consumers that only need
|
|
116
|
+
* per-node structural fields (`drawOrder`, `type`, `source`, `properties`) can use
|
|
117
|
+
* this instead of the cascade and skip all rect math; `membership.test.ts` pins the
|
|
118
|
+
* equivalence against the cascade.
|
|
119
|
+
*/
|
|
120
|
+
declare function flattenSceneGraphNodes(graph: SceneGraph): SceneGraphNode[];
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/index.d.ts
|
|
123
|
+
declare function isGodotSceneTree(value: unknown): value is GodotSceneTree;
|
|
124
|
+
declare function resolveGodotSceneTree(graph: SceneGraph, options?: GodotLayoutOptions): GodotSceneTree;
|
|
125
|
+
//#endregion
|
|
126
|
+
export { type GodotAnchorEdge, type GodotAnchorHorizontalEdge, type GodotAnchorMap, type GodotAnchorVerticalEdge, type GodotLayoutDiagnostic, type GodotLayoutModel, type GodotLayoutNode, type GodotLayoutOptions, type GodotNodeAnchor, type GodotRect, type GodotSceneTree, type GodotSceneTreeDiagnostic, type GodotSceneTreeNode, type GodotTextRunMetric, anchorEdgePoint, flattenSceneGraphNodes, isGodotSceneTree, parseAnchorEdge, resolveGodotSceneTree };
|
|
127
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/anchor-grammar.ts","../src/types.ts","../src/membership.ts","../src/index.ts"],"mappings":";;;;UACiB,eAAA;EACf,QAAA;EACA,IAAA;EACA,EAAA;EACA,MAAA;IAAW,CAAA;IAAY,CAAA;EAAA;AAAA;AAAA,KAEb,cAAA,GAAiB,MAAM,SAAS,eAAA;AAAA,KAChC,uBAAA;AAAA,KAMA,yBAAA;AAAA,UAMK,eAAA;EACf,QAAA,EAAU,uBAAA;EACV,UAAA,EAAY,yBAAyB;AAAA;AAAA,iBAgBvB,eAAA,CAAgB,KAAA,WAAgB,eAAe;AAAA,iBAW/C,eAAA,CACd,KAAA,UACA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