@phaserjs/phaser-editor-layout 1.0.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.
@@ -0,0 +1,354 @@
1
+ import Phaser from "phaser";
2
+ import { LayoutZone } from "./LayoutZone";
3
+ /** Event fired by the plugin after each resolution pass. */
4
+ export const LAYOUT_UPDATE_EVENT = "layoutupdate";
5
+ /**
6
+ * Scene plugin that resolves responsive anchors and zones at run time.
7
+ *
8
+ * Reached as `this.layout` (like `this.physics`) once registered with
9
+ * `mapping: "layout"`. Per-object layout state lives on the object as
10
+ * `obj.layoutData`; the plugin keeps the set of enabled objects so it can
11
+ * re-resolve them when the screen changes.
12
+ *
13
+ * Register it in the game config:
14
+ *
15
+ * ```ts
16
+ * plugins: {
17
+ * scene: [
18
+ * { key: "LayoutPlugin", plugin: LayoutPlugin, mapping: "layout" }
19
+ * ]
20
+ * }
21
+ * ```
22
+ */
23
+ export class LayoutPlugin extends Phaser.Plugins.ScenePlugin {
24
+ constructor(scene, pluginManager, pluginKey) {
25
+ super(scene, pluginManager, pluginKey);
26
+ /**
27
+ * The active layout variant. `"base"` applies only the baseline; `"portrait"` /
28
+ * `"landscape"` apply their overrides on top of base. Defaults to `"base"`. Change
29
+ * it with {@link setVariant} (manual) or {@link autoVariant} (orientation-driven).
30
+ */
31
+ this.variant = "base";
32
+ // When true, the active variant follows the screen orientation on every resize.
33
+ this._auto = false;
34
+ // Injected design size, or null to use the live scene size (scale.gameSize).
35
+ this._designSize = null;
36
+ this._scene = scene;
37
+ this._objects = new Set();
38
+ this.events = new Phaser.Events.EventEmitter();
39
+ this.safeArea = new LayoutZone(scene, this);
40
+ this.screen = new LayoutZone(scene, this);
41
+ this._rect = new Phaser.Geom.Rectangle();
42
+ this._mat = new Phaser.GameObjects.Components.TransformMatrix();
43
+ this._p1 = new Phaser.Math.Vector2();
44
+ this._p2 = new Phaser.Math.Vector2();
45
+ }
46
+ boot() {
47
+ const events = this._scene.sys.events;
48
+ events.on(Phaser.Scenes.Events.CREATE, this.refresh, this);
49
+ events.on(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);
50
+ events.once(Phaser.Scenes.Events.DESTROY, this.destroy, this);
51
+ this._scene.scale.on(Phaser.Scale.Events.RESIZE, this._onResize, this);
52
+ }
53
+ // ----- design size -----
54
+ /**
55
+ * The injected design size, or `null` when resolution follows the live scene size
56
+ * (`scale.gameSize`). Read by zones (the plugin is their {@link LayoutZone} provider).
57
+ */
58
+ get designSize() {
59
+ return this._designSize;
60
+ }
61
+ /**
62
+ * Resolve against a fixed design size (e.g. 1080×1920) instead of the live canvas
63
+ * size, then re-resolve. Hosts that author/preview layouts at a target resolution
64
+ * (the editor) use this; games typically leave it unset and follow `scale.gameSize`.
65
+ */
66
+ setDesignSize(width, height) {
67
+ this._designSize = { width, height };
68
+ this.refresh();
69
+ }
70
+ /** Clear the injected design size and fall back to the live scene size, then re-resolve. */
71
+ clearDesignSize() {
72
+ this._designSize = null;
73
+ this.refresh();
74
+ }
75
+ /** The effective size used for resolution: the injected design size, or the live game size. */
76
+ _size() {
77
+ var _a;
78
+ return (_a = this._designSize) !== null && _a !== void 0 ? _a : this._scene.scale.gameSize;
79
+ }
80
+ // ----- variants -----
81
+ /** The screen's current orientation, derived from the effective design size. */
82
+ get orientation() {
83
+ const size = this._size();
84
+ return size.height > size.width ? "portrait" : "landscape";
85
+ }
86
+ /**
87
+ * Manually set the active variant and re-resolve. Turns off orientation
88
+ * auto-detection (see {@link autoVariant}).
89
+ */
90
+ setVariant(variant) {
91
+ this._auto = false;
92
+ this.variant = variant;
93
+ this.refresh();
94
+ }
95
+ /**
96
+ * Enable (or disable) orientation-driven variant selection. When enabled, the active
97
+ * variant follows {@link orientation} (`"portrait"` / `"landscape"`) on every resize.
98
+ * Disabling resets the variant to `"base"`.
99
+ */
100
+ autoVariant(enabled = true) {
101
+ this._auto = enabled;
102
+ this.variant = enabled ? this.orientation : "base";
103
+ this.refresh();
104
+ }
105
+ _onResize() {
106
+ if (this._auto) {
107
+ this.variant = this.orientation;
108
+ }
109
+ this.refresh();
110
+ }
111
+ // ----- objects -----
112
+ /**
113
+ * Enable layout for an object: attaches a default {@link AnchorLayoutData} as
114
+ * `obj.layoutData` (if it does not have one yet), registers the object for
115
+ * re-resolution, and returns the data so it can be configured.
116
+ *
117
+ * The `base` defaults are inert: `targetType: "screen"`, both anchors `"none"` and
118
+ * zero offsets, so the object does not move until you choose anchors. `portrait` and
119
+ * `landscape` start empty (they inherit `base`).
120
+ */
121
+ add(obj) {
122
+ let data = obj.layoutData;
123
+ if (!data) {
124
+ data = {
125
+ enabled: true,
126
+ base: {
127
+ targetType: "screen",
128
+ horizontalAnchor: "none",
129
+ horizontalOffset: 0,
130
+ verticalAnchor: "none",
131
+ verticalOffset: 0,
132
+ },
133
+ portrait: {},
134
+ landscape: {},
135
+ };
136
+ obj.layoutData = data;
137
+ }
138
+ this._objects.add(obj);
139
+ obj.once(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);
140
+ return data;
141
+ }
142
+ /** Stop laying out an object and remove its `layoutData`. */
143
+ remove(obj) {
144
+ this._objects.delete(obj);
145
+ obj.off(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);
146
+ obj.layoutData = undefined;
147
+ }
148
+ _onObjectDestroy(obj) {
149
+ this._objects.delete(obj);
150
+ }
151
+ // ----- zones -----
152
+ /**
153
+ * Create a screen-relative zone. A factory only — the returned zone is not stored
154
+ * by the plugin; hold the reference and assign it to `data.targetZone`.
155
+ */
156
+ createZone(marginTop = 0, marginRight = 0, marginBottom = 0, marginLeft = 0) {
157
+ return new LayoutZone(this._scene, this, marginTop, marginRight, marginBottom, marginLeft);
158
+ }
159
+ // ----- resolution -----
160
+ /**
161
+ * Re-resolve every enabled object now. The plugin also runs this automatically on
162
+ * `scale` `resize` and once after the scene is created, so explicit calls are only
163
+ * needed after mutating layout data (or the `safeArea` margins) at run time.
164
+ *
165
+ * Objects are resolved parent → child so a child anchored to its parent's bounds
166
+ * sees the parent's already-resolved rect.
167
+ */
168
+ refresh() {
169
+ const list = [];
170
+ for (const obj of this._objects) {
171
+ const data = obj.layoutData;
172
+ if (data && data.enabled) {
173
+ list.push(obj);
174
+ }
175
+ }
176
+ list.sort((a, b) => this._depth(a) - this._depth(b));
177
+ for (const obj of list) {
178
+ this._resolve(obj);
179
+ }
180
+ this.events.emit(LAYOUT_UPDATE_EVENT);
181
+ }
182
+ /**
183
+ * Resolve a specific list of objects once, against the current variant / design size /
184
+ * zones, **without** registering them for future passes (no {@link add}, no re-resolve
185
+ * on resize). Hosts that drive resolution themselves — e.g. the editor's live preview —
186
+ * set each object's `layoutData`, call this, then read back the resolved `x`/`y`.
187
+ *
188
+ * Objects are still resolved parent → child, and any object whose `layoutData` is
189
+ * missing or disabled is skipped.
190
+ */
191
+ resolveList(objects) {
192
+ const list = objects.filter(obj => obj.layoutData && obj.layoutData.enabled);
193
+ list.sort((a, b) => this._depth(a) - this._depth(b));
194
+ for (const obj of list) {
195
+ this._resolve(obj);
196
+ }
197
+ this.events.emit(LAYOUT_UPDATE_EVENT);
198
+ }
199
+ _depth(obj) {
200
+ let depth = 0;
201
+ let parent = obj.parentContainer;
202
+ while (parent) {
203
+ depth++;
204
+ parent = parent.parentContainer;
205
+ }
206
+ return depth;
207
+ }
208
+ _resolve(obj) {
209
+ // `x`, `y`, `displayWidth`, origin, etc. live on transform/size/origin
210
+ // components, not on the GameObject base type.
211
+ const go = obj;
212
+ const data = obj.layoutData;
213
+ const originX = typeof go.originX === "number" ? go.originX : 0;
214
+ const originY = typeof go.originY === "number" ? go.originY : 0;
215
+ const eff = this._effective(data);
216
+ if (eff.targetType === "parent") {
217
+ this._resolveAgainstParent(go, eff, originX, originY);
218
+ return;
219
+ }
220
+ this._resolveAgainstZone(go, eff, originX, originY);
221
+ }
222
+ /** Merge the active variant's overrides over `base` into concrete anchor properties. */
223
+ _effective(data) {
224
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
225
+ const base = data.base;
226
+ const over = this.variant === "base" ? undefined : data[this.variant];
227
+ return {
228
+ targetType: (_b = (_a = over === null || over === void 0 ? void 0 : over.targetType) !== null && _a !== void 0 ? _a : base.targetType) !== null && _b !== void 0 ? _b : "screen",
229
+ targetZone: (_c = over === null || over === void 0 ? void 0 : over.targetZone) !== null && _c !== void 0 ? _c : base.targetZone,
230
+ horizontalAnchor: (_e = (_d = over === null || over === void 0 ? void 0 : over.horizontalAnchor) !== null && _d !== void 0 ? _d : base.horizontalAnchor) !== null && _e !== void 0 ? _e : "none",
231
+ horizontalOffset: (_g = (_f = over === null || over === void 0 ? void 0 : over.horizontalOffset) !== null && _f !== void 0 ? _f : base.horizontalOffset) !== null && _g !== void 0 ? _g : 0,
232
+ verticalAnchor: (_j = (_h = over === null || over === void 0 ? void 0 : over.verticalAnchor) !== null && _h !== void 0 ? _h : base.verticalAnchor) !== null && _j !== void 0 ? _j : "none",
233
+ verticalOffset: (_l = (_k = over === null || over === void 0 ? void 0 : over.verticalOffset) !== null && _k !== void 0 ? _k : base.verticalOffset) !== null && _l !== void 0 ? _l : 0,
234
+ };
235
+ }
236
+ /** The zone a non-parent target resolves against. */
237
+ _zoneFor(eff) {
238
+ var _a;
239
+ switch (eff.targetType) {
240
+ case "safeArea":
241
+ return this.safeArea;
242
+ case "custom":
243
+ return (_a = eff.targetZone) !== null && _a !== void 0 ? _a : this.screen;
244
+ default: // "screen"
245
+ return this.screen;
246
+ }
247
+ }
248
+ /** Resolve against a zone's world rect, converting to parent-local space if nested. */
249
+ _resolveAgainstZone(go, eff, originX, originY) {
250
+ var _a;
251
+ const zone = this._zoneFor(eff);
252
+ const t = zone.getRect(this._rect);
253
+ const w = this._sizeX(go);
254
+ const h = this._sizeY(go);
255
+ const parent = (_a = go.parentContainer) !== null && _a !== void 0 ? _a : null;
256
+ if (parent) {
257
+ // Work in world space, then convert the result into the parent's local space.
258
+ const m = parent.getWorldTransformMatrix(this._mat);
259
+ const cur = m.transformPoint(go.x, go.y, this._p1);
260
+ const wx = this._axis(eff.horizontalAnchor, cur.x, t.left, t.right, eff.horizontalOffset, w, originX);
261
+ const wy = this._axis(eff.verticalAnchor, cur.y, t.top, t.bottom, eff.verticalOffset, h, originY);
262
+ const local = m.applyInverse(wx, wy, this._p2);
263
+ go.x = local.x;
264
+ go.y = local.y;
265
+ return;
266
+ }
267
+ go.x = this._axis(eff.horizontalAnchor, go.x, t.left, t.right, eff.horizontalOffset, w, originX);
268
+ go.y = this._axis(eff.verticalAnchor, go.y, t.top, t.bottom, eff.verticalOffset, h, originY);
269
+ }
270
+ /** Resolve against the object's parent container bounds (local space), or the screen. */
271
+ _resolveAgainstParent(go, eff, originX, originY) {
272
+ var _a;
273
+ const parent = (_a = go.parentContainer) !== null && _a !== void 0 ? _a : null;
274
+ if (parent) {
275
+ // Children live in the parent's unscaled local space, with (0,0) at the
276
+ // container origin. Use the container's explicit size as the rect, and the
277
+ // child's local (unscaled-by-parent) size for edge alignment.
278
+ const right = parent.width || 0;
279
+ const bottom = parent.height || 0;
280
+ const w = (go.width || 0) * (typeof go.scaleX === "number" ? go.scaleX : 1);
281
+ const h = (go.height || 0) * (typeof go.scaleY === "number" ? go.scaleY : 1);
282
+ go.x = this._axis(eff.horizontalAnchor, go.x, 0, right, eff.horizontalOffset, w, originX);
283
+ go.y = this._axis(eff.verticalAnchor, go.y, 0, bottom, eff.verticalOffset, h, originY);
284
+ return;
285
+ }
286
+ // No parent container: fall back to the screen rect, in world space.
287
+ const size = this._size();
288
+ const w = this._sizeX(go);
289
+ const h = this._sizeY(go);
290
+ go.x = this._axis(eff.horizontalAnchor, go.x, 0, size.width, eff.horizontalOffset, w, originX);
291
+ go.y = this._axis(eff.verticalAnchor, go.y, 0, size.height, eff.verticalOffset, h, originY);
292
+ }
293
+ /**
294
+ * Resolve one axis. Aligns the object's edge/center to the target edge/center,
295
+ * accounting for the object's origin so `"left"`/`"top"` align the left/top edge,
296
+ * `"center"` the center, and `"right"`/`"bottom"` the right/bottom edge.
297
+ *
298
+ * Reduces to the documented `t.left + offset + size / 2` form for centered-origin
299
+ * objects (`origin = 0.5`).
300
+ */
301
+ _axis(anchor, current, min, max, offset, size, origin) {
302
+ switch (anchor) {
303
+ case "left":
304
+ case "top":
305
+ return min + offset + origin * size;
306
+ case "right":
307
+ case "bottom":
308
+ return max + offset - (1 - origin) * size;
309
+ case "center":
310
+ return (min + max) / 2 + offset + (origin - 0.5) * size;
311
+ default: // "none"
312
+ return current;
313
+ }
314
+ }
315
+ _sizeX(go) {
316
+ if (typeof go.displayWidth === "number") {
317
+ return go.displayWidth;
318
+ }
319
+ return typeof go.width === "number" ? go.width : 0;
320
+ }
321
+ _sizeY(go) {
322
+ if (typeof go.displayHeight === "number") {
323
+ return go.displayHeight;
324
+ }
325
+ return typeof go.height === "number" ? go.height : 0;
326
+ }
327
+ // ----- event delegates -----
328
+ on(event, fn, context) {
329
+ this.events.on(event, fn, context);
330
+ return this;
331
+ }
332
+ once(event, fn, context) {
333
+ this.events.once(event, fn, context);
334
+ return this;
335
+ }
336
+ off(event, fn, context, once) {
337
+ this.events.off(event, fn, context, once);
338
+ return this;
339
+ }
340
+ // ----- lifecycle -----
341
+ shutdown() {
342
+ const events = this._scene.sys.events;
343
+ events.off(Phaser.Scenes.Events.CREATE, this.refresh, this);
344
+ events.off(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);
345
+ this._scene.scale.off(Phaser.Scale.Events.RESIZE, this._onResize, this);
346
+ this._objects.clear();
347
+ }
348
+ destroy() {
349
+ this.shutdown();
350
+ this.events.destroy();
351
+ super.destroy();
352
+ }
353
+ }
354
+ //# sourceMappingURL=LayoutPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LayoutPlugin.js","sourceRoot":"","sources":["../src/LayoutPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;A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KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ"}
@@ -0,0 +1,56 @@
1
+ import Phaser from "phaser";
2
+ import type { VariantName } from "./types";
3
+ /** The four screen-edge insets that define a zone, in scene/world pixels. */
4
+ export interface ZoneMargins {
5
+ marginTop: number;
6
+ marginRight: number;
7
+ marginBottom: number;
8
+ marginLeft: number;
9
+ }
10
+ /** Minimal view of the plugin that supplies the active variant and design size. */
11
+ export interface VariantProvider {
12
+ readonly variant: VariantName;
13
+ /**
14
+ * The design size the zones inset from, or `null` to use the live scene size
15
+ * (`scene.scale.gameSize`). A host (e.g. the editor) can inject a fixed design size
16
+ * to resolve against a target resolution instead of the current canvas size.
17
+ */
18
+ readonly designSize: {
19
+ width: number;
20
+ height: number;
21
+ } | null;
22
+ }
23
+ /**
24
+ * A screen-relative rectangle defined by an inset (margin) from each screen edge.
25
+ *
26
+ * Margins are split into variants: `base` is the baseline (all four sides), and
27
+ * `portrait` / `landscape` are partial overrides — any side left unset inherits from
28
+ * `base`. The active variant follows the plugin (see {@link VariantProvider}), so a
29
+ * zone's rect can differ per orientation.
30
+ *
31
+ * The rect is computed **lazily** via {@link LayoutZone.getRect} from the current screen
32
+ * size and the effective margins, so the plugin never has to store or iterate zones.
33
+ *
34
+ * The built-in `safeArea` zone is just a `LayoutZone` whose margins are the
35
+ * device-provided insets (notch / home indicator); `screen` is a `LayoutZone` with all
36
+ * margins at 0.
37
+ */
38
+ export declare class LayoutZone {
39
+ /** Baseline margins (all four sides). */
40
+ base: ZoneMargins;
41
+ /** Margin overrides applied when the active variant is `"portrait"`. */
42
+ portrait: Partial<ZoneMargins>;
43
+ /** Margin overrides applied when the active variant is `"landscape"`. */
44
+ landscape: Partial<ZoneMargins>;
45
+ private readonly scene;
46
+ private readonly provider;
47
+ constructor(scene: Phaser.Scene, provider: VariantProvider, marginTop?: number, marginRight?: number, marginBottom?: number, marginLeft?: number);
48
+ /** Effective value of one margin side under the active variant. */
49
+ private _margin;
50
+ /**
51
+ * The effective rectangle at the current screen size and active variant. Pass an
52
+ * `out` rectangle to avoid allocations.
53
+ */
54
+ getRect(out?: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle;
55
+ }
56
+ //# sourceMappingURL=LayoutZone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LayoutZone.d.ts","sourceRoot":"","sources":["../src/LayoutZone.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAE9B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IAEnB,yCAAyC;IACzC,IAAI,EAAE,WAAW,CAAC;IAElB,wEAAwE;IACxE,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAE/B,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAEhC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;gBAGvC,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,QAAQ,EAAE,eAAe,EACzB,SAAS,SAAI,EACb,WAAW,SAAI,EACf,YAAY,SAAI,EAChB,UAAU,SAAI;IASlB,mEAAmE;IACnE,OAAO,CAAC,OAAO;IAiBf;;;OAGG;IACH,OAAO,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS;CAkB9D"}
@@ -0,0 +1,54 @@
1
+ import Phaser from "phaser";
2
+ /**
3
+ * A screen-relative rectangle defined by an inset (margin) from each screen edge.
4
+ *
5
+ * Margins are split into variants: `base` is the baseline (all four sides), and
6
+ * `portrait` / `landscape` are partial overrides — any side left unset inherits from
7
+ * `base`. The active variant follows the plugin (see {@link VariantProvider}), so a
8
+ * zone's rect can differ per orientation.
9
+ *
10
+ * The rect is computed **lazily** via {@link LayoutZone.getRect} from the current screen
11
+ * size and the effective margins, so the plugin never has to store or iterate zones.
12
+ *
13
+ * The built-in `safeArea` zone is just a `LayoutZone` whose margins are the
14
+ * device-provided insets (notch / home indicator); `screen` is a `LayoutZone` with all
15
+ * margins at 0.
16
+ */
17
+ export class LayoutZone {
18
+ constructor(scene, provider, marginTop = 0, marginRight = 0, marginBottom = 0, marginLeft = 0) {
19
+ this.scene = scene;
20
+ this.provider = provider;
21
+ this.base = { marginTop, marginRight, marginBottom, marginLeft };
22
+ this.portrait = {};
23
+ this.landscape = {};
24
+ }
25
+ /** Effective value of one margin side under the active variant. */
26
+ _margin(side) {
27
+ const variant = this.provider.variant;
28
+ if (variant !== "base") {
29
+ const override = this[variant][side];
30
+ if (override !== undefined) {
31
+ return override;
32
+ }
33
+ }
34
+ return this.base[side];
35
+ }
36
+ /**
37
+ * The effective rectangle at the current screen size and active variant. Pass an
38
+ * `out` rectangle to avoid allocations.
39
+ */
40
+ getRect(out) {
41
+ var _a;
42
+ const size = (_a = this.provider.designSize) !== null && _a !== void 0 ? _a : this.scene.scale.gameSize;
43
+ const x = this._margin("marginLeft");
44
+ const y = this._margin("marginTop");
45
+ const width = size.width - x - this._margin("marginRight");
46
+ const height = size.height - y - this._margin("marginBottom");
47
+ if (out) {
48
+ out.setTo(x, y, width, height);
49
+ return out;
50
+ }
51
+ return new Phaser.Geom.Rect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AY,CAAC,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAE9D,IAAI,GAAG,EAAE,CAAC;YAEN,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;YAE/B,OAAO,GAAG,CAAC;QACf,CAAC;QAED,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC1D,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ export { LayoutPlugin, LAYOUT_UPDATE_EVENT } from "./LayoutPlugin";
2
+ export { LayoutZone } from "./LayoutZone";
3
+ export type { ZoneMargins, VariantProvider } from "./LayoutZone";
4
+ export type { AnchorLayoutData, AnchorProps, HAnchor, VAnchor, TargetType, VariantName } from "./types";
5
+ import "./types";
6
+ //# 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,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIxG,OAAO,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { LayoutPlugin, LAYOUT_UPDATE_EVENT } from "./LayoutPlugin";
2
+ export { LayoutZone } from "./LayoutZone";
3
+ // Side-effect import so the `Phaser.Scene.layout` / `GameObject.layoutData` global
4
+ // augmentations are always part of the public type surface.
5
+ import "./types";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,mFAAmF;AACnF,4DAA4D;AAC5D,OAAO,SAAS,CAAC"}