@phaserjs/phaser-editor-layout 1.0.0 → 1.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/dist/LayoutZone.d.ts +18 -0
- package/dist/LayoutZone.d.ts.map +1 -1
- package/dist/LayoutZone.js +20 -0
- package/dist/LayoutZone.js.map +1 -1
- package/dist/phaser-editor-layout.js +20 -0
- package/dist/phaser-editor-layout.js.map +2 -2
- package/dist/phaser-editor-layout.min.js +1 -1
- package/global/phaser-editor-layout.global.d.ts +7 -0
- package/package.json +1 -1
package/dist/LayoutZone.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ export interface ZoneMargins {
|
|
|
7
7
|
marginBottom: number;
|
|
8
8
|
marginLeft: number;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Per-variant margin overrides accepted by {@link LayoutZone.setMargins}. Every side of
|
|
12
|
+
* every variant is optional; only the supplied sides are changed.
|
|
13
|
+
*/
|
|
14
|
+
export interface ZoneVariantMargins {
|
|
15
|
+
base?: Partial<ZoneMargins>;
|
|
16
|
+
portrait?: Partial<ZoneMargins>;
|
|
17
|
+
landscape?: Partial<ZoneMargins>;
|
|
18
|
+
}
|
|
10
19
|
/** Minimal view of the plugin that supplies the active variant and design size. */
|
|
11
20
|
export interface VariantProvider {
|
|
12
21
|
readonly variant: VariantName;
|
|
@@ -45,6 +54,15 @@ export declare class LayoutZone {
|
|
|
45
54
|
private readonly scene;
|
|
46
55
|
private readonly provider;
|
|
47
56
|
constructor(scene: Phaser.Scene, provider: VariantProvider, marginTop?: number, marginRight?: number, marginBottom?: number, marginLeft?: number);
|
|
57
|
+
/**
|
|
58
|
+
* Sets margins for one or more variants in a single call, merging into whatever is
|
|
59
|
+
* already there (only the supplied sides change). Returns `this` for chaining, e.g.
|
|
60
|
+
* `scene.layout.createZone().setMargins({ base: { marginTop: 40 }, portrait: { marginTop: 80 } })`.
|
|
61
|
+
*
|
|
62
|
+
* The editor's code generator uses this for zones and the safe area, since (unlike
|
|
63
|
+
* per-object layout data) zone margins have no per-field override semantics.
|
|
64
|
+
*/
|
|
65
|
+
setMargins(variants: ZoneVariantMargins): this;
|
|
48
66
|
/** Effective value of one margin side under the active variant. */
|
|
49
67
|
private _margin;
|
|
50
68
|
/**
|
package/dist/LayoutZone.d.ts.map
CHANGED
|
@@ -1 +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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,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;;;;;;;OAOG;IACH,UAAU,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAoB9C,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"}
|
package/dist/LayoutZone.js
CHANGED
|
@@ -22,6 +22,26 @@ export class LayoutZone {
|
|
|
22
22
|
this.portrait = {};
|
|
23
23
|
this.landscape = {};
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Sets margins for one or more variants in a single call, merging into whatever is
|
|
27
|
+
* already there (only the supplied sides change). Returns `this` for chaining, e.g.
|
|
28
|
+
* `scene.layout.createZone().setMargins({ base: { marginTop: 40 }, portrait: { marginTop: 80 } })`.
|
|
29
|
+
*
|
|
30
|
+
* The editor's code generator uses this for zones and the safe area, since (unlike
|
|
31
|
+
* per-object layout data) zone margins have no per-field override semantics.
|
|
32
|
+
*/
|
|
33
|
+
setMargins(variants) {
|
|
34
|
+
if (variants.base) {
|
|
35
|
+
Object.assign(this.base, variants.base);
|
|
36
|
+
}
|
|
37
|
+
if (variants.portrait) {
|
|
38
|
+
this.portrait = { ...this.portrait, ...variants.portrait };
|
|
39
|
+
}
|
|
40
|
+
if (variants.landscape) {
|
|
41
|
+
this.landscape = { ...this.landscape, ...variants.landscape };
|
|
42
|
+
}
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
25
45
|
/** Effective value of one margin side under the active variant. */
|
|
26
46
|
_margin(side) {
|
|
27
47
|
const variant = this.provider.variant;
|
package/dist/LayoutZone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutZone.js","sourceRoot":"","sources":["../src/LayoutZone.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"LayoutZone.js","sourceRoot":"","sources":["../src/LayoutZone.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAiC5B;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,UAAU;IAcnB,YACI,KAAmB,EACnB,QAAyB,EACzB,SAAS,GAAG,CAAC,EACb,WAAW,GAAG,CAAC,EACf,YAAY,GAAG,CAAC,EAChB,UAAU,GAAG,CAAC;QAEd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC;QACjE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,UAAU,CAAC,QAA4B;QAEnC,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEhB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAEpB,IAAI,CAAC,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC/D,CAAC;QAED,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC;YAErB,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC;QAClE,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAA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
|
64
64
|
this.landscape = {};
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Sets margins for one or more variants in a single call, merging into whatever is
|
|
68
|
+
* already there (only the supplied sides change). Returns `this` for chaining, e.g.
|
|
69
|
+
* `scene.layout.createZone().setMargins({ base: { marginTop: 40 }, portrait: { marginTop: 80 } })`.
|
|
70
|
+
*
|
|
71
|
+
* The editor's code generator uses this for zones and the safe area, since (unlike
|
|
72
|
+
* per-object layout data) zone margins have no per-field override semantics.
|
|
73
|
+
*/
|
|
74
|
+
setMargins(variants) {
|
|
75
|
+
if (variants.base) {
|
|
76
|
+
Object.assign(this.base, variants.base);
|
|
77
|
+
}
|
|
78
|
+
if (variants.portrait) {
|
|
79
|
+
this.portrait = { ...this.portrait, ...variants.portrait };
|
|
80
|
+
}
|
|
81
|
+
if (variants.landscape) {
|
|
82
|
+
this.landscape = { ...this.landscape, ...variants.landscape };
|
|
83
|
+
}
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
66
86
|
/** Effective value of one margin side under the active variant. */
|
|
67
87
|
_margin(side) {
|
|
68
88
|
const variant = this.provider.variant;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["phaser-global:phaser", "../src/index.ts", "../src/LayoutPlugin.ts", "../src/LayoutZone.ts"],
|
|
4
|
-
"sourcesContent": ["module.exports = globalThis.Phaser;", "export { LayoutPlugin, LAYOUT_UPDATE_EVENT } from \"./LayoutPlugin\";\nexport { LayoutZone } from \"./LayoutZone\";\nexport type { ZoneMargins, VariantProvider } from \"./LayoutZone\";\nexport type { AnchorLayoutData, AnchorProps, HAnchor, VAnchor, TargetType, VariantName } from \"./types\";\n\n// Side-effect import so the `Phaser.Scene.layout` / `GameObject.layoutData` global\n// augmentations are always part of the public type surface.\nimport \"./types\";\n", "import Phaser from \"phaser\";\nimport { LayoutZone } from \"./LayoutZone\";\nimport type { AnchorLayoutData, HAnchor, TargetType, VAnchor, VariantName } from \"./types\";\n\n/** Event fired by the plugin after each resolution pass. */\nexport const LAYOUT_UPDATE_EVENT = \"layoutupdate\";\n\n/** Fully resolved anchor properties for the active variant (base + overrides). */\ninterface ResolvedAnchor {\n targetType: TargetType;\n targetZone?: LayoutZone;\n horizontalAnchor: HAnchor;\n horizontalOffset: number;\n verticalAnchor: VAnchor;\n verticalOffset: number;\n}\n\n/**\n * Scene plugin that resolves responsive anchors and zones at run time.\n *\n * Reached as `this.layout` (like `this.physics`) once registered with\n * `mapping: \"layout\"`. Per-object layout state lives on the object as\n * `obj.layoutData`; the plugin keeps the set of enabled objects so it can\n * re-resolve them when the screen changes.\n *\n * Register it in the game config:\n *\n * ```ts\n * plugins: {\n * scene: [\n * { key: \"LayoutPlugin\", plugin: LayoutPlugin, mapping: \"layout\" }\n * ]\n * }\n * ```\n */\nexport class LayoutPlugin extends Phaser.Plugins.ScenePlugin {\n\n /** Screen inset by the device safe-area insets. The host sets `safeArea.margin*`. */\n readonly safeArea: LayoutZone;\n\n /** The full screen bounds (0,0 .. width,height). */\n readonly screen: LayoutZone;\n\n /**\n * Event emitter that fires {@link LAYOUT_UPDATE_EVENT} after each resolution pass.\n * Use `this.layout.events.on(\"layoutupdate\", ...)` \u2014 or the `on`/`once`/`off`\n * delegates on the plugin itself.\n */\n readonly events: Phaser.Events.EventEmitter;\n\n /**\n * The active layout variant. `\"base\"` applies only the baseline; `\"portrait\"` /\n * `\"landscape\"` apply their overrides on top of base. Defaults to `\"base\"`. Change\n * it with {@link setVariant} (manual) or {@link autoVariant} (orientation-driven).\n */\n variant: VariantName = \"base\";\n\n // Non-null scene reference captured at construction. `ScenePlugin.scene` /\n // `ScenePlugin.systems` are typed as nullable; this avoids guarding every use.\n private readonly _scene: Phaser.Scene;\n\n // When true, the active variant follows the screen orientation on every resize.\n private _auto = false;\n\n // Injected design size, or null to use the live scene size (scale.gameSize).\n private _designSize: { width: number; height: number } | null = null;\n\n private readonly _objects: Set<Phaser.GameObjects.GameObject>;\n\n // Scratch values reused across a pass to avoid allocations.\n private readonly _rect: Phaser.Geom.Rectangle;\n private readonly _mat: Phaser.GameObjects.Components.TransformMatrix;\n private readonly _p1: Phaser.Math.Vector2;\n private readonly _p2: Phaser.Math.Vector2;\n\n constructor(\n scene: Phaser.Scene,\n pluginManager: Phaser.Plugins.PluginManager,\n pluginKey: string\n ) {\n super(scene, pluginManager, pluginKey);\n\n this._scene = scene;\n this._objects = new Set();\n this.events = new Phaser.Events.EventEmitter();\n\n this.safeArea = new LayoutZone(scene, this);\n this.screen = new LayoutZone(scene, this);\n\n this._rect = new Phaser.Geom.Rectangle();\n this._mat = new Phaser.GameObjects.Components.TransformMatrix();\n this._p1 = new Phaser.Math.Vector2();\n this._p2 = new Phaser.Math.Vector2();\n }\n\n boot(): void {\n\n const events = this._scene.sys.events;\n\n events.on(Phaser.Scenes.Events.CREATE, this.refresh, this);\n events.on(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);\n events.once(Phaser.Scenes.Events.DESTROY, this.destroy, this);\n\n this._scene.scale.on(Phaser.Scale.Events.RESIZE, this._onResize, this);\n }\n\n // ----- design size -----\n\n /**\n * The injected design size, or `null` when resolution follows the live scene size\n * (`scale.gameSize`). Read by zones (the plugin is their {@link LayoutZone} provider).\n */\n get designSize(): { width: number; height: number } | null {\n\n return this._designSize;\n }\n\n /**\n * Resolve against a fixed design size (e.g. 1080\u00D71920) instead of the live canvas\n * size, then re-resolve. Hosts that author/preview layouts at a target resolution\n * (the editor) use this; games typically leave it unset and follow `scale.gameSize`.\n */\n setDesignSize(width: number, height: number): void {\n\n this._designSize = { width, height };\n this.refresh();\n }\n\n /** Clear the injected design size and fall back to the live scene size, then re-resolve. */\n clearDesignSize(): void {\n\n this._designSize = null;\n this.refresh();\n }\n\n /** The effective size used for resolution: the injected design size, or the live game size. */\n private _size(): { width: number; height: number } {\n\n return this._designSize ?? this._scene.scale.gameSize;\n }\n\n // ----- variants -----\n\n /** The screen's current orientation, derived from the effective design size. */\n get orientation(): \"portrait\" | \"landscape\" {\n\n const size = this._size();\n\n return size.height > size.width ? \"portrait\" : \"landscape\";\n }\n\n /**\n * Manually set the active variant and re-resolve. Turns off orientation\n * auto-detection (see {@link autoVariant}).\n */\n setVariant(variant: VariantName): void {\n\n this._auto = false;\n this.variant = variant;\n this.refresh();\n }\n\n /**\n * Enable (or disable) orientation-driven variant selection. When enabled, the active\n * variant follows {@link orientation} (`\"portrait\"` / `\"landscape\"`) on every resize.\n * Disabling resets the variant to `\"base\"`.\n */\n autoVariant(enabled = true): void {\n\n this._auto = enabled;\n this.variant = enabled ? this.orientation : \"base\";\n this.refresh();\n }\n\n private _onResize(): void {\n\n if (this._auto) {\n\n this.variant = this.orientation;\n }\n\n this.refresh();\n }\n\n // ----- objects -----\n\n /**\n * Enable layout for an object: attaches a default {@link AnchorLayoutData} as\n * `obj.layoutData` (if it does not have one yet), registers the object for\n * re-resolution, and returns the data so it can be configured.\n *\n * The `base` defaults are inert: `targetType: \"screen\"`, both anchors `\"none\"` and\n * zero offsets, so the object does not move until you choose anchors. `portrait` and\n * `landscape` start empty (they inherit `base`).\n */\n add<T extends Phaser.GameObjects.GameObject>(obj: T): AnchorLayoutData {\n\n let data = obj.layoutData;\n\n if (!data) {\n\n data = {\n enabled: true,\n base: {\n targetType: \"screen\",\n horizontalAnchor: \"none\",\n horizontalOffset: 0,\n verticalAnchor: \"none\",\n verticalOffset: 0,\n },\n portrait: {},\n landscape: {},\n };\n\n obj.layoutData = data;\n }\n\n this._objects.add(obj);\n\n obj.once(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);\n\n return data;\n }\n\n /** Stop laying out an object and remove its `layoutData`. */\n remove(obj: Phaser.GameObjects.GameObject): void {\n\n this._objects.delete(obj);\n\n obj.off(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);\n\n obj.layoutData = undefined;\n }\n\n private _onObjectDestroy(obj: Phaser.GameObjects.GameObject): void {\n\n this._objects.delete(obj);\n }\n\n // ----- zones -----\n\n /**\n * Create a screen-relative zone. A factory only \u2014 the returned zone is not stored\n * by the plugin; hold the reference and assign it to `data.targetZone`.\n */\n createZone(\n marginTop = 0,\n marginRight = 0,\n marginBottom = 0,\n marginLeft = 0\n ): LayoutZone {\n\n return new LayoutZone(this._scene, this, marginTop, marginRight, marginBottom, marginLeft);\n }\n\n // ----- resolution -----\n\n /**\n * Re-resolve every enabled object now. The plugin also runs this automatically on\n * `scale` `resize` and once after the scene is created, so explicit calls are only\n * needed after mutating layout data (or the `safeArea` margins) at run time.\n *\n * Objects are resolved parent \u2192 child so a child anchored to its parent's bounds\n * sees the parent's already-resolved rect.\n */\n refresh(): void {\n\n const list: Phaser.GameObjects.GameObject[] = [];\n\n for (const obj of this._objects) {\n\n const data = obj.layoutData;\n\n if (data && data.enabled) {\n\n list.push(obj);\n }\n }\n\n list.sort((a, b) => this._depth(a) - this._depth(b));\n\n for (const obj of list) {\n\n this._resolve(obj);\n }\n\n this.events.emit(LAYOUT_UPDATE_EVENT);\n }\n\n /**\n * Resolve a specific list of objects once, against the current variant / design size /\n * zones, **without** registering them for future passes (no {@link add}, no re-resolve\n * on resize). Hosts that drive resolution themselves \u2014 e.g. the editor's live preview \u2014\n * set each object's `layoutData`, call this, then read back the resolved `x`/`y`.\n *\n * Objects are still resolved parent \u2192 child, and any object whose `layoutData` is\n * missing or disabled is skipped.\n */\n resolveList(objects: Phaser.GameObjects.GameObject[]): void {\n\n const list = objects.filter(obj => obj.layoutData && obj.layoutData.enabled);\n\n list.sort((a, b) => this._depth(a) - this._depth(b));\n\n for (const obj of list) {\n\n this._resolve(obj);\n }\n\n this.events.emit(LAYOUT_UPDATE_EVENT);\n }\n\n private _depth(obj: Phaser.GameObjects.GameObject): number {\n\n let depth = 0;\n let parent = obj.parentContainer;\n\n while (parent) {\n\n depth++;\n parent = parent.parentContainer;\n }\n\n return depth;\n }\n\n private _resolve(obj: Phaser.GameObjects.GameObject): void {\n\n // `x`, `y`, `displayWidth`, origin, etc. live on transform/size/origin\n // components, not on the GameObject base type.\n const go = obj as any;\n const data = obj.layoutData as AnchorLayoutData;\n\n const originX = typeof go.originX === \"number\" ? go.originX : 0;\n const originY = typeof go.originY === \"number\" ? go.originY : 0;\n\n const eff = this._effective(data);\n\n if (eff.targetType === \"parent\") {\n\n this._resolveAgainstParent(go, eff, originX, originY);\n\n return;\n }\n\n this._resolveAgainstZone(go, eff, originX, originY);\n }\n\n /** Merge the active variant's overrides over `base` into concrete anchor properties. */\n private _effective(data: AnchorLayoutData): ResolvedAnchor {\n\n const base = data.base;\n const over = this.variant === \"base\" ? undefined : data[this.variant];\n\n return {\n targetType: over?.targetType ?? base.targetType ?? \"screen\",\n targetZone: over?.targetZone ?? base.targetZone,\n horizontalAnchor: over?.horizontalAnchor ?? base.horizontalAnchor ?? \"none\",\n horizontalOffset: over?.horizontalOffset ?? base.horizontalOffset ?? 0,\n verticalAnchor: over?.verticalAnchor ?? base.verticalAnchor ?? \"none\",\n verticalOffset: over?.verticalOffset ?? base.verticalOffset ?? 0,\n };\n }\n\n /** The zone a non-parent target resolves against. */\n private _zoneFor(eff: ResolvedAnchor): LayoutZone {\n\n switch (eff.targetType) {\n\n case \"safeArea\":\n return this.safeArea;\n\n case \"custom\":\n return eff.targetZone ?? this.screen;\n\n default: // \"screen\"\n return this.screen;\n }\n }\n\n /** Resolve against a zone's world rect, converting to parent-local space if nested. */\n private _resolveAgainstZone(\n go: any,\n eff: ResolvedAnchor,\n originX: number,\n originY: number\n ): void {\n\n const zone = this._zoneFor(eff);\n const t = zone.getRect(this._rect);\n\n const w = this._sizeX(go);\n const h = this._sizeY(go);\n\n const parent: Phaser.GameObjects.Container | null = go.parentContainer ?? null;\n\n if (parent) {\n\n // Work in world space, then convert the result into the parent's local space.\n const m = parent.getWorldTransformMatrix(this._mat);\n const cur = m.transformPoint(go.x, go.y, this._p1) as Phaser.Math.Vector2;\n\n const wx = this._axis(eff.horizontalAnchor, cur.x, t.left, t.right, eff.horizontalOffset, w, originX);\n const wy = this._axis(eff.verticalAnchor, cur.y, t.top, t.bottom, eff.verticalOffset, h, originY);\n\n const local = m.applyInverse(wx, wy, this._p2) as Phaser.Math.Vector2;\n\n go.x = local.x;\n go.y = local.y;\n\n return;\n }\n\n go.x = this._axis(eff.horizontalAnchor, go.x, t.left, t.right, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, t.top, t.bottom, eff.verticalOffset, h, originY);\n }\n\n /** Resolve against the object's parent container bounds (local space), or the screen. */\n private _resolveAgainstParent(\n go: any,\n eff: ResolvedAnchor,\n originX: number,\n originY: number\n ): void {\n\n const parent: Phaser.GameObjects.Container | null = go.parentContainer ?? null;\n\n if (parent) {\n\n // Children live in the parent's unscaled local space, with (0,0) at the\n // container origin. Use the container's explicit size as the rect, and the\n // child's local (unscaled-by-parent) size for edge alignment.\n const right = (parent as any).width || 0;\n const bottom = (parent as any).height || 0;\n\n const w = (go.width || 0) * (typeof go.scaleX === \"number\" ? go.scaleX : 1);\n const h = (go.height || 0) * (typeof go.scaleY === \"number\" ? go.scaleY : 1);\n\n go.x = this._axis(eff.horizontalAnchor, go.x, 0, right, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, 0, bottom, eff.verticalOffset, h, originY);\n\n return;\n }\n\n // No parent container: fall back to the screen rect, in world space.\n const size = this._size();\n const w = this._sizeX(go);\n const h = this._sizeY(go);\n\n go.x = this._axis(eff.horizontalAnchor, go.x, 0, size.width, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, 0, size.height, eff.verticalOffset, h, originY);\n }\n\n /**\n * Resolve one axis. Aligns the object's edge/center to the target edge/center,\n * accounting for the object's origin so `\"left\"`/`\"top\"` align the left/top edge,\n * `\"center\"` the center, and `\"right\"`/`\"bottom\"` the right/bottom edge.\n *\n * Reduces to the documented `t.left + offset + size / 2` form for centered-origin\n * objects (`origin = 0.5`).\n */\n private _axis(\n anchor: string,\n current: number,\n min: number,\n max: number,\n offset: number,\n size: number,\n origin: number\n ): number {\n\n switch (anchor) {\n\n case \"left\":\n case \"top\":\n return min + offset + origin * size;\n\n case \"right\":\n case \"bottom\":\n return max + offset - (1 - origin) * size;\n\n case \"center\":\n return (min + max) / 2 + offset + (origin - 0.5) * size;\n\n default: // \"none\"\n return current;\n }\n }\n\n private _sizeX(go: any): number {\n\n if (typeof go.displayWidth === \"number\") {\n\n return go.displayWidth;\n }\n\n return typeof go.width === \"number\" ? go.width : 0;\n }\n\n private _sizeY(go: any): number {\n\n if (typeof go.displayHeight === \"number\") {\n\n return go.displayHeight;\n }\n\n return typeof go.height === \"number\" ? go.height : 0;\n }\n\n // ----- event delegates -----\n\n on(event: string | symbol, fn: (...args: any[]) => void, context?: any): this {\n\n this.events.on(event, fn, context);\n\n return this;\n }\n\n once(event: string | symbol, fn: (...args: any[]) => void, context?: any): this {\n\n this.events.once(event, fn, context);\n\n return this;\n }\n\n off(event: string | symbol, fn?: (...args: any[]) => void, context?: any, once?: boolean): this {\n\n this.events.off(event, fn, context, once);\n\n return this;\n }\n\n // ----- lifecycle -----\n\n shutdown(): void {\n\n const events = this._scene.sys.events;\n\n events.off(Phaser.Scenes.Events.CREATE, this.refresh, this);\n events.off(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);\n\n this._scene.scale.off(Phaser.Scale.Events.RESIZE, this._onResize, this);\n\n this._objects.clear();\n }\n\n destroy(): void {\n\n this.shutdown();\n\n this.events.destroy();\n\n super.destroy();\n }\n}\n", "import Phaser from \"phaser\";\nimport type { VariantName } from \"./types\";\n\n/** The four screen-edge insets that define a zone, in scene/world pixels. */\nexport interface ZoneMargins {\n marginTop: number;\n marginRight: number;\n marginBottom: number;\n marginLeft: number;\n}\n\n/** Minimal view of the plugin that supplies the active variant and design size. */\nexport interface VariantProvider {\n readonly variant: VariantName;\n\n /**\n * The design size the zones inset from, or `null` to use the live scene size\n * (`scene.scale.gameSize`). A host (e.g. the editor) can inject a fixed design size\n * to resolve against a target resolution instead of the current canvas size.\n */\n readonly designSize: { width: number; height: number } | null;\n}\n\n/**\n * A screen-relative rectangle defined by an inset (margin) from each screen edge.\n *\n * Margins are split into variants: `base` is the baseline (all four sides), and\n * `portrait` / `landscape` are partial overrides \u2014 any side left unset inherits from\n * `base`. The active variant follows the plugin (see {@link VariantProvider}), so a\n * zone's rect can differ per orientation.\n *\n * The rect is computed **lazily** via {@link LayoutZone.getRect} from the current screen\n * size and the effective margins, so the plugin never has to store or iterate zones.\n *\n * The built-in `safeArea` zone is just a `LayoutZone` whose margins are the\n * device-provided insets (notch / home indicator); `screen` is a `LayoutZone` with all\n * margins at 0.\n */\nexport class LayoutZone {\n\n /** Baseline margins (all four sides). */\n base: ZoneMargins;\n\n /** Margin overrides applied when the active variant is `\"portrait\"`. */\n portrait: Partial<ZoneMargins>;\n\n /** Margin overrides applied when the active variant is `\"landscape\"`. */\n landscape: Partial<ZoneMargins>;\n\n private readonly scene: Phaser.Scene;\n private readonly provider: VariantProvider;\n\n constructor(\n scene: Phaser.Scene,\n provider: VariantProvider,\n marginTop = 0,\n marginRight = 0,\n marginBottom = 0,\n marginLeft = 0\n ) {\n this.scene = scene;\n this.provider = provider;\n this.base = { marginTop, marginRight, marginBottom, marginLeft };\n this.portrait = {};\n this.landscape = {};\n }\n\n /** Effective value of one margin side under the active variant. */\n private _margin(side: keyof ZoneMargins): number {\n\n const variant = this.provider.variant;\n\n if (variant !== \"base\") {\n\n const override = (this[variant] as Partial<ZoneMargins>)[side];\n\n if (override !== undefined) {\n\n return override;\n }\n }\n\n return this.base[side];\n }\n\n /**\n * The effective rectangle at the current screen size and active variant. Pass an\n * `out` rectangle to avoid allocations.\n */\n getRect(out?: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle {\n\n const size = this.provider.designSize ?? this.scene.scale.gameSize;\n\n const x = this._margin(\"marginLeft\");\n const y = this._margin(\"marginTop\");\n const width = size.width - x - this._margin(\"marginRight\");\n const height = size.height - y - this._margin(\"marginBottom\");\n\n if (out) {\n\n out.setTo(x, y, width, height);\n\n return out;\n }\n\n return new Phaser.Geom.Rectangle(x, y, width, height);\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,aAAO,UAAU,WAAW;AAAA;AAAA;;;ACA5B;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,MAAAA,iBAAmB;;;ACAnB,sBAAmB;
|
|
4
|
+
"sourcesContent": ["module.exports = globalThis.Phaser;", "export { LayoutPlugin, LAYOUT_UPDATE_EVENT } from \"./LayoutPlugin\";\nexport { LayoutZone } from \"./LayoutZone\";\nexport type { ZoneMargins, VariantProvider } from \"./LayoutZone\";\nexport type { AnchorLayoutData, AnchorProps, HAnchor, VAnchor, TargetType, VariantName } from \"./types\";\n\n// Side-effect import so the `Phaser.Scene.layout` / `GameObject.layoutData` global\n// augmentations are always part of the public type surface.\nimport \"./types\";\n", "import Phaser from \"phaser\";\nimport { LayoutZone } from \"./LayoutZone\";\nimport type { AnchorLayoutData, HAnchor, TargetType, VAnchor, VariantName } from \"./types\";\n\n/** Event fired by the plugin after each resolution pass. */\nexport const LAYOUT_UPDATE_EVENT = \"layoutupdate\";\n\n/** Fully resolved anchor properties for the active variant (base + overrides). */\ninterface ResolvedAnchor {\n targetType: TargetType;\n targetZone?: LayoutZone;\n horizontalAnchor: HAnchor;\n horizontalOffset: number;\n verticalAnchor: VAnchor;\n verticalOffset: number;\n}\n\n/**\n * Scene plugin that resolves responsive anchors and zones at run time.\n *\n * Reached as `this.layout` (like `this.physics`) once registered with\n * `mapping: \"layout\"`. Per-object layout state lives on the object as\n * `obj.layoutData`; the plugin keeps the set of enabled objects so it can\n * re-resolve them when the screen changes.\n *\n * Register it in the game config:\n *\n * ```ts\n * plugins: {\n * scene: [\n * { key: \"LayoutPlugin\", plugin: LayoutPlugin, mapping: \"layout\" }\n * ]\n * }\n * ```\n */\nexport class LayoutPlugin extends Phaser.Plugins.ScenePlugin {\n\n /** Screen inset by the device safe-area insets. The host sets `safeArea.margin*`. */\n readonly safeArea: LayoutZone;\n\n /** The full screen bounds (0,0 .. width,height). */\n readonly screen: LayoutZone;\n\n /**\n * Event emitter that fires {@link LAYOUT_UPDATE_EVENT} after each resolution pass.\n * Use `this.layout.events.on(\"layoutupdate\", ...)` \u2014 or the `on`/`once`/`off`\n * delegates on the plugin itself.\n */\n readonly events: Phaser.Events.EventEmitter;\n\n /**\n * The active layout variant. `\"base\"` applies only the baseline; `\"portrait\"` /\n * `\"landscape\"` apply their overrides on top of base. Defaults to `\"base\"`. Change\n * it with {@link setVariant} (manual) or {@link autoVariant} (orientation-driven).\n */\n variant: VariantName = \"base\";\n\n // Non-null scene reference captured at construction. `ScenePlugin.scene` /\n // `ScenePlugin.systems` are typed as nullable; this avoids guarding every use.\n private readonly _scene: Phaser.Scene;\n\n // When true, the active variant follows the screen orientation on every resize.\n private _auto = false;\n\n // Injected design size, or null to use the live scene size (scale.gameSize).\n private _designSize: { width: number; height: number } | null = null;\n\n private readonly _objects: Set<Phaser.GameObjects.GameObject>;\n\n // Scratch values reused across a pass to avoid allocations.\n private readonly _rect: Phaser.Geom.Rectangle;\n private readonly _mat: Phaser.GameObjects.Components.TransformMatrix;\n private readonly _p1: Phaser.Math.Vector2;\n private readonly _p2: Phaser.Math.Vector2;\n\n constructor(\n scene: Phaser.Scene,\n pluginManager: Phaser.Plugins.PluginManager,\n pluginKey: string\n ) {\n super(scene, pluginManager, pluginKey);\n\n this._scene = scene;\n this._objects = new Set();\n this.events = new Phaser.Events.EventEmitter();\n\n this.safeArea = new LayoutZone(scene, this);\n this.screen = new LayoutZone(scene, this);\n\n this._rect = new Phaser.Geom.Rectangle();\n this._mat = new Phaser.GameObjects.Components.TransformMatrix();\n this._p1 = new Phaser.Math.Vector2();\n this._p2 = new Phaser.Math.Vector2();\n }\n\n boot(): void {\n\n const events = this._scene.sys.events;\n\n events.on(Phaser.Scenes.Events.CREATE, this.refresh, this);\n events.on(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);\n events.once(Phaser.Scenes.Events.DESTROY, this.destroy, this);\n\n this._scene.scale.on(Phaser.Scale.Events.RESIZE, this._onResize, this);\n }\n\n // ----- design size -----\n\n /**\n * The injected design size, or `null` when resolution follows the live scene size\n * (`scale.gameSize`). Read by zones (the plugin is their {@link LayoutZone} provider).\n */\n get designSize(): { width: number; height: number } | null {\n\n return this._designSize;\n }\n\n /**\n * Resolve against a fixed design size (e.g. 1080\u00D71920) instead of the live canvas\n * size, then re-resolve. Hosts that author/preview layouts at a target resolution\n * (the editor) use this; games typically leave it unset and follow `scale.gameSize`.\n */\n setDesignSize(width: number, height: number): void {\n\n this._designSize = { width, height };\n this.refresh();\n }\n\n /** Clear the injected design size and fall back to the live scene size, then re-resolve. */\n clearDesignSize(): void {\n\n this._designSize = null;\n this.refresh();\n }\n\n /** The effective size used for resolution: the injected design size, or the live game size. */\n private _size(): { width: number; height: number } {\n\n return this._designSize ?? this._scene.scale.gameSize;\n }\n\n // ----- variants -----\n\n /** The screen's current orientation, derived from the effective design size. */\n get orientation(): \"portrait\" | \"landscape\" {\n\n const size = this._size();\n\n return size.height > size.width ? \"portrait\" : \"landscape\";\n }\n\n /**\n * Manually set the active variant and re-resolve. Turns off orientation\n * auto-detection (see {@link autoVariant}).\n */\n setVariant(variant: VariantName): void {\n\n this._auto = false;\n this.variant = variant;\n this.refresh();\n }\n\n /**\n * Enable (or disable) orientation-driven variant selection. When enabled, the active\n * variant follows {@link orientation} (`\"portrait\"` / `\"landscape\"`) on every resize.\n * Disabling resets the variant to `\"base\"`.\n */\n autoVariant(enabled = true): void {\n\n this._auto = enabled;\n this.variant = enabled ? this.orientation : \"base\";\n this.refresh();\n }\n\n private _onResize(): void {\n\n if (this._auto) {\n\n this.variant = this.orientation;\n }\n\n this.refresh();\n }\n\n // ----- objects -----\n\n /**\n * Enable layout for an object: attaches a default {@link AnchorLayoutData} as\n * `obj.layoutData` (if it does not have one yet), registers the object for\n * re-resolution, and returns the data so it can be configured.\n *\n * The `base` defaults are inert: `targetType: \"screen\"`, both anchors `\"none\"` and\n * zero offsets, so the object does not move until you choose anchors. `portrait` and\n * `landscape` start empty (they inherit `base`).\n */\n add<T extends Phaser.GameObjects.GameObject>(obj: T): AnchorLayoutData {\n\n let data = obj.layoutData;\n\n if (!data) {\n\n data = {\n enabled: true,\n base: {\n targetType: \"screen\",\n horizontalAnchor: \"none\",\n horizontalOffset: 0,\n verticalAnchor: \"none\",\n verticalOffset: 0,\n },\n portrait: {},\n landscape: {},\n };\n\n obj.layoutData = data;\n }\n\n this._objects.add(obj);\n\n obj.once(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);\n\n return data;\n }\n\n /** Stop laying out an object and remove its `layoutData`. */\n remove(obj: Phaser.GameObjects.GameObject): void {\n\n this._objects.delete(obj);\n\n obj.off(Phaser.GameObjects.Events.DESTROY, this._onObjectDestroy, this);\n\n obj.layoutData = undefined;\n }\n\n private _onObjectDestroy(obj: Phaser.GameObjects.GameObject): void {\n\n this._objects.delete(obj);\n }\n\n // ----- zones -----\n\n /**\n * Create a screen-relative zone. A factory only \u2014 the returned zone is not stored\n * by the plugin; hold the reference and assign it to `data.targetZone`.\n */\n createZone(\n marginTop = 0,\n marginRight = 0,\n marginBottom = 0,\n marginLeft = 0\n ): LayoutZone {\n\n return new LayoutZone(this._scene, this, marginTop, marginRight, marginBottom, marginLeft);\n }\n\n // ----- resolution -----\n\n /**\n * Re-resolve every enabled object now. The plugin also runs this automatically on\n * `scale` `resize` and once after the scene is created, so explicit calls are only\n * needed after mutating layout data (or the `safeArea` margins) at run time.\n *\n * Objects are resolved parent \u2192 child so a child anchored to its parent's bounds\n * sees the parent's already-resolved rect.\n */\n refresh(): void {\n\n const list: Phaser.GameObjects.GameObject[] = [];\n\n for (const obj of this._objects) {\n\n const data = obj.layoutData;\n\n if (data && data.enabled) {\n\n list.push(obj);\n }\n }\n\n list.sort((a, b) => this._depth(a) - this._depth(b));\n\n for (const obj of list) {\n\n this._resolve(obj);\n }\n\n this.events.emit(LAYOUT_UPDATE_EVENT);\n }\n\n /**\n * Resolve a specific list of objects once, against the current variant / design size /\n * zones, **without** registering them for future passes (no {@link add}, no re-resolve\n * on resize). Hosts that drive resolution themselves \u2014 e.g. the editor's live preview \u2014\n * set each object's `layoutData`, call this, then read back the resolved `x`/`y`.\n *\n * Objects are still resolved parent \u2192 child, and any object whose `layoutData` is\n * missing or disabled is skipped.\n */\n resolveList(objects: Phaser.GameObjects.GameObject[]): void {\n\n const list = objects.filter(obj => obj.layoutData && obj.layoutData.enabled);\n\n list.sort((a, b) => this._depth(a) - this._depth(b));\n\n for (const obj of list) {\n\n this._resolve(obj);\n }\n\n this.events.emit(LAYOUT_UPDATE_EVENT);\n }\n\n private _depth(obj: Phaser.GameObjects.GameObject): number {\n\n let depth = 0;\n let parent = obj.parentContainer;\n\n while (parent) {\n\n depth++;\n parent = parent.parentContainer;\n }\n\n return depth;\n }\n\n private _resolve(obj: Phaser.GameObjects.GameObject): void {\n\n // `x`, `y`, `displayWidth`, origin, etc. live on transform/size/origin\n // components, not on the GameObject base type.\n const go = obj as any;\n const data = obj.layoutData as AnchorLayoutData;\n\n const originX = typeof go.originX === \"number\" ? go.originX : 0;\n const originY = typeof go.originY === \"number\" ? go.originY : 0;\n\n const eff = this._effective(data);\n\n if (eff.targetType === \"parent\") {\n\n this._resolveAgainstParent(go, eff, originX, originY);\n\n return;\n }\n\n this._resolveAgainstZone(go, eff, originX, originY);\n }\n\n /** Merge the active variant's overrides over `base` into concrete anchor properties. */\n private _effective(data: AnchorLayoutData): ResolvedAnchor {\n\n const base = data.base;\n const over = this.variant === \"base\" ? undefined : data[this.variant];\n\n return {\n targetType: over?.targetType ?? base.targetType ?? \"screen\",\n targetZone: over?.targetZone ?? base.targetZone,\n horizontalAnchor: over?.horizontalAnchor ?? base.horizontalAnchor ?? \"none\",\n horizontalOffset: over?.horizontalOffset ?? base.horizontalOffset ?? 0,\n verticalAnchor: over?.verticalAnchor ?? base.verticalAnchor ?? \"none\",\n verticalOffset: over?.verticalOffset ?? base.verticalOffset ?? 0,\n };\n }\n\n /** The zone a non-parent target resolves against. */\n private _zoneFor(eff: ResolvedAnchor): LayoutZone {\n\n switch (eff.targetType) {\n\n case \"safeArea\":\n return this.safeArea;\n\n case \"custom\":\n return eff.targetZone ?? this.screen;\n\n default: // \"screen\"\n return this.screen;\n }\n }\n\n /** Resolve against a zone's world rect, converting to parent-local space if nested. */\n private _resolveAgainstZone(\n go: any,\n eff: ResolvedAnchor,\n originX: number,\n originY: number\n ): void {\n\n const zone = this._zoneFor(eff);\n const t = zone.getRect(this._rect);\n\n const w = this._sizeX(go);\n const h = this._sizeY(go);\n\n const parent: Phaser.GameObjects.Container | null = go.parentContainer ?? null;\n\n if (parent) {\n\n // Work in world space, then convert the result into the parent's local space.\n const m = parent.getWorldTransformMatrix(this._mat);\n const cur = m.transformPoint(go.x, go.y, this._p1) as Phaser.Math.Vector2;\n\n const wx = this._axis(eff.horizontalAnchor, cur.x, t.left, t.right, eff.horizontalOffset, w, originX);\n const wy = this._axis(eff.verticalAnchor, cur.y, t.top, t.bottom, eff.verticalOffset, h, originY);\n\n const local = m.applyInverse(wx, wy, this._p2) as Phaser.Math.Vector2;\n\n go.x = local.x;\n go.y = local.y;\n\n return;\n }\n\n go.x = this._axis(eff.horizontalAnchor, go.x, t.left, t.right, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, t.top, t.bottom, eff.verticalOffset, h, originY);\n }\n\n /** Resolve against the object's parent container bounds (local space), or the screen. */\n private _resolveAgainstParent(\n go: any,\n eff: ResolvedAnchor,\n originX: number,\n originY: number\n ): void {\n\n const parent: Phaser.GameObjects.Container | null = go.parentContainer ?? null;\n\n if (parent) {\n\n // Children live in the parent's unscaled local space, with (0,0) at the\n // container origin. Use the container's explicit size as the rect, and the\n // child's local (unscaled-by-parent) size for edge alignment.\n const right = (parent as any).width || 0;\n const bottom = (parent as any).height || 0;\n\n const w = (go.width || 0) * (typeof go.scaleX === \"number\" ? go.scaleX : 1);\n const h = (go.height || 0) * (typeof go.scaleY === \"number\" ? go.scaleY : 1);\n\n go.x = this._axis(eff.horizontalAnchor, go.x, 0, right, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, 0, bottom, eff.verticalOffset, h, originY);\n\n return;\n }\n\n // No parent container: fall back to the screen rect, in world space.\n const size = this._size();\n const w = this._sizeX(go);\n const h = this._sizeY(go);\n\n go.x = this._axis(eff.horizontalAnchor, go.x, 0, size.width, eff.horizontalOffset, w, originX);\n go.y = this._axis(eff.verticalAnchor, go.y, 0, size.height, eff.verticalOffset, h, originY);\n }\n\n /**\n * Resolve one axis. Aligns the object's edge/center to the target edge/center,\n * accounting for the object's origin so `\"left\"`/`\"top\"` align the left/top edge,\n * `\"center\"` the center, and `\"right\"`/`\"bottom\"` the right/bottom edge.\n *\n * Reduces to the documented `t.left + offset + size / 2` form for centered-origin\n * objects (`origin = 0.5`).\n */\n private _axis(\n anchor: string,\n current: number,\n min: number,\n max: number,\n offset: number,\n size: number,\n origin: number\n ): number {\n\n switch (anchor) {\n\n case \"left\":\n case \"top\":\n return min + offset + origin * size;\n\n case \"right\":\n case \"bottom\":\n return max + offset - (1 - origin) * size;\n\n case \"center\":\n return (min + max) / 2 + offset + (origin - 0.5) * size;\n\n default: // \"none\"\n return current;\n }\n }\n\n private _sizeX(go: any): number {\n\n if (typeof go.displayWidth === \"number\") {\n\n return go.displayWidth;\n }\n\n return typeof go.width === \"number\" ? go.width : 0;\n }\n\n private _sizeY(go: any): number {\n\n if (typeof go.displayHeight === \"number\") {\n\n return go.displayHeight;\n }\n\n return typeof go.height === \"number\" ? go.height : 0;\n }\n\n // ----- event delegates -----\n\n on(event: string | symbol, fn: (...args: any[]) => void, context?: any): this {\n\n this.events.on(event, fn, context);\n\n return this;\n }\n\n once(event: string | symbol, fn: (...args: any[]) => void, context?: any): this {\n\n this.events.once(event, fn, context);\n\n return this;\n }\n\n off(event: string | symbol, fn?: (...args: any[]) => void, context?: any, once?: boolean): this {\n\n this.events.off(event, fn, context, once);\n\n return this;\n }\n\n // ----- lifecycle -----\n\n shutdown(): void {\n\n const events = this._scene.sys.events;\n\n events.off(Phaser.Scenes.Events.CREATE, this.refresh, this);\n events.off(Phaser.Scenes.Events.SHUTDOWN, this.shutdown, this);\n\n this._scene.scale.off(Phaser.Scale.Events.RESIZE, this._onResize, this);\n\n this._objects.clear();\n }\n\n destroy(): void {\n\n this.shutdown();\n\n this.events.destroy();\n\n super.destroy();\n }\n}\n", "import Phaser from \"phaser\";\nimport type { VariantName } from \"./types\";\n\n/** The four screen-edge insets that define a zone, in scene/world pixels. */\nexport interface ZoneMargins {\n marginTop: number;\n marginRight: number;\n marginBottom: number;\n marginLeft: number;\n}\n\n/**\n * Per-variant margin overrides accepted by {@link LayoutZone.setMargins}. Every side of\n * every variant is optional; only the supplied sides are changed.\n */\nexport interface ZoneVariantMargins {\n base?: Partial<ZoneMargins>;\n portrait?: Partial<ZoneMargins>;\n landscape?: Partial<ZoneMargins>;\n}\n\n/** Minimal view of the plugin that supplies the active variant and design size. */\nexport interface VariantProvider {\n readonly variant: VariantName;\n\n /**\n * The design size the zones inset from, or `null` to use the live scene size\n * (`scene.scale.gameSize`). A host (e.g. the editor) can inject a fixed design size\n * to resolve against a target resolution instead of the current canvas size.\n */\n readonly designSize: { width: number; height: number } | null;\n}\n\n/**\n * A screen-relative rectangle defined by an inset (margin) from each screen edge.\n *\n * Margins are split into variants: `base` is the baseline (all four sides), and\n * `portrait` / `landscape` are partial overrides \u2014 any side left unset inherits from\n * `base`. The active variant follows the plugin (see {@link VariantProvider}), so a\n * zone's rect can differ per orientation.\n *\n * The rect is computed **lazily** via {@link LayoutZone.getRect} from the current screen\n * size and the effective margins, so the plugin never has to store or iterate zones.\n *\n * The built-in `safeArea` zone is just a `LayoutZone` whose margins are the\n * device-provided insets (notch / home indicator); `screen` is a `LayoutZone` with all\n * margins at 0.\n */\nexport class LayoutZone {\n\n /** Baseline margins (all four sides). */\n base: ZoneMargins;\n\n /** Margin overrides applied when the active variant is `\"portrait\"`. */\n portrait: Partial<ZoneMargins>;\n\n /** Margin overrides applied when the active variant is `\"landscape\"`. */\n landscape: Partial<ZoneMargins>;\n\n private readonly scene: Phaser.Scene;\n private readonly provider: VariantProvider;\n\n constructor(\n scene: Phaser.Scene,\n provider: VariantProvider,\n marginTop = 0,\n marginRight = 0,\n marginBottom = 0,\n marginLeft = 0\n ) {\n this.scene = scene;\n this.provider = provider;\n this.base = { marginTop, marginRight, marginBottom, marginLeft };\n this.portrait = {};\n this.landscape = {};\n }\n\n /**\n * Sets margins for one or more variants in a single call, merging into whatever is\n * already there (only the supplied sides change). Returns `this` for chaining, e.g.\n * `scene.layout.createZone().setMargins({ base: { marginTop: 40 }, portrait: { marginTop: 80 } })`.\n *\n * The editor's code generator uses this for zones and the safe area, since (unlike\n * per-object layout data) zone margins have no per-field override semantics.\n */\n setMargins(variants: ZoneVariantMargins): this {\n\n if (variants.base) {\n\n Object.assign(this.base, variants.base);\n }\n\n if (variants.portrait) {\n\n this.portrait = { ...this.portrait, ...variants.portrait };\n }\n\n if (variants.landscape) {\n\n this.landscape = { ...this.landscape, ...variants.landscape };\n }\n\n return this;\n }\n\n /** Effective value of one margin side under the active variant. */\n private _margin(side: keyof ZoneMargins): number {\n\n const variant = this.provider.variant;\n\n if (variant !== \"base\") {\n\n const override = (this[variant] as Partial<ZoneMargins>)[side];\n\n if (override !== undefined) {\n\n return override;\n }\n }\n\n return this.base[side];\n }\n\n /**\n * The effective rectangle at the current screen size and active variant. Pass an\n * `out` rectangle to avoid allocations.\n */\n getRect(out?: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle {\n\n const size = this.provider.designSize ?? this.scene.scale.gameSize;\n\n const x = this._margin(\"marginLeft\");\n const y = this._margin(\"marginTop\");\n const width = size.width - x - this._margin(\"marginRight\");\n const height = size.height -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|
-
"use strict";var PhaserEditorLayout=(()=>{var w=Object.create;var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,
|
|
1
|
+
"use strict";var PhaserEditorLayout=(()=>{var w=Object.create;var f=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var G=(o,s)=>()=>{try{return s||o((s={exports:{}}).exports,s),s.exports}catch(e){throw s=0,e}},V=(o,s)=>{for(var e in s)f(o,e,{get:s[e],enumerable:!0})},z=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of E(s))!Z.call(o,r)&&r!==e&&f(o,r,{get:()=>s[r],enumerable:!(t=S(s,r))||t.enumerable});return o};var P=(o,s,e)=>(e=o!=null?w(j(o)):{},z(s||!o||!o.__esModule?f(e,"default",{value:o,enumerable:!0}):e,o)),D=o=>z(f({},"__esModule",{value:!0}),o);var O=G((L,x)=>{x.exports=globalThis.Phaser});var R={};V(R,{LAYOUT_UPDATE_EVENT:()=>_,LayoutPlugin:()=>g,LayoutZone:()=>p});var h=P(O(),1);var T=P(O(),1),p=class{constructor(s,e,t=0,r=0,n=0,i=0){this.scene=s,this.provider=e,this.base={marginTop:t,marginRight:r,marginBottom:n,marginLeft:i},this.portrait={},this.landscape={}}setMargins(s){return s.base&&Object.assign(this.base,s.base),s.portrait&&(this.portrait={...this.portrait,...s.portrait}),s.landscape&&(this.landscape={...this.landscape,...s.landscape}),this}_margin(s){let e=this.provider.variant;if(e!=="base"){let t=this[e][s];if(t!==void 0)return t}return this.base[s]}getRect(s){var a;let e=(a=this.provider.designSize)!=null?a:this.scene.scale.gameSize,t=this._margin("marginLeft"),r=this._margin("marginTop"),n=e.width-t-this._margin("marginRight"),i=e.height-r-this._margin("marginBottom");return s?(s.setTo(t,r,n,i),s):new T.default.Geom.Rectangle(t,r,n,i)}};var _="layoutupdate",g=class extends h.default.Plugins.ScenePlugin{constructor(e,t,r){super(e,t,r);this.variant="base";this._auto=!1;this._designSize=null;this._scene=e,this._objects=new Set,this.events=new h.default.Events.EventEmitter,this.safeArea=new p(e,this),this.screen=new p(e,this),this._rect=new h.default.Geom.Rectangle,this._mat=new h.default.GameObjects.Components.TransformMatrix,this._p1=new h.default.Math.Vector2,this._p2=new h.default.Math.Vector2}boot(){let e=this._scene.sys.events;e.on(h.default.Scenes.Events.CREATE,this.refresh,this),e.on(h.default.Scenes.Events.SHUTDOWN,this.shutdown,this),e.once(h.default.Scenes.Events.DESTROY,this.destroy,this),this._scene.scale.on(h.default.Scale.Events.RESIZE,this._onResize,this)}get designSize(){return this._designSize}setDesignSize(e,t){this._designSize={width:e,height:t},this.refresh()}clearDesignSize(){this._designSize=null,this.refresh()}_size(){var e;return(e=this._designSize)!=null?e:this._scene.scale.gameSize}get orientation(){let e=this._size();return e.height>e.width?"portrait":"landscape"}setVariant(e){this._auto=!1,this.variant=e,this.refresh()}autoVariant(e=!0){this._auto=e,this.variant=e?this.orientation:"base",this.refresh()}_onResize(){this._auto&&(this.variant=this.orientation),this.refresh()}add(e){let t=e.layoutData;return t||(t={enabled:!0,base:{targetType:"screen",horizontalAnchor:"none",horizontalOffset:0,verticalAnchor:"none",verticalOffset:0},portrait:{},landscape:{}},e.layoutData=t),this._objects.add(e),e.once(h.default.GameObjects.Events.DESTROY,this._onObjectDestroy,this),t}remove(e){this._objects.delete(e),e.off(h.default.GameObjects.Events.DESTROY,this._onObjectDestroy,this),e.layoutData=void 0}_onObjectDestroy(e){this._objects.delete(e)}createZone(e=0,t=0,r=0,n=0){return new p(this._scene,this,e,t,r,n)}refresh(){let e=[];for(let t of this._objects){let r=t.layoutData;r&&r.enabled&&e.push(t)}e.sort((t,r)=>this._depth(t)-this._depth(r));for(let t of e)this._resolve(t);this.events.emit(_)}resolveList(e){let t=e.filter(r=>r.layoutData&&r.layoutData.enabled);t.sort((r,n)=>this._depth(r)-this._depth(n));for(let r of t)this._resolve(r);this.events.emit(_)}_depth(e){let t=0,r=e.parentContainer;for(;r;)t++,r=r.parentContainer;return t}_resolve(e){let t=e,r=e.layoutData,n=typeof t.originX=="number"?t.originX:0,i=typeof t.originY=="number"?t.originY:0,a=this._effective(r);if(a.targetType==="parent"){this._resolveAgainstParent(t,a,n,i);return}this._resolveAgainstZone(t,a,n,i)}_effective(e){var n,i,a,c,m,l,u,d,v,y,b;let t=e.base,r=this.variant==="base"?void 0:e[this.variant];return{targetType:(i=(n=r==null?void 0:r.targetType)!=null?n:t.targetType)!=null?i:"screen",targetZone:(a=r==null?void 0:r.targetZone)!=null?a:t.targetZone,horizontalAnchor:(m=(c=r==null?void 0:r.horizontalAnchor)!=null?c:t.horizontalAnchor)!=null?m:"none",horizontalOffset:(u=(l=r==null?void 0:r.horizontalOffset)!=null?l:t.horizontalOffset)!=null?u:0,verticalAnchor:(v=(d=r==null?void 0:r.verticalAnchor)!=null?d:t.verticalAnchor)!=null?v:"none",verticalOffset:(b=(y=r==null?void 0:r.verticalOffset)!=null?y:t.verticalOffset)!=null?b:0}}_zoneFor(e){var t;switch(e.targetType){case"safeArea":return this.safeArea;case"custom":return(t=e.targetZone)!=null?t:this.screen;default:return this.screen}}_resolveAgainstZone(e,t,r,n){var u;let a=this._zoneFor(t).getRect(this._rect),c=this._sizeX(e),m=this._sizeY(e),l=(u=e.parentContainer)!=null?u:null;if(l){let d=l.getWorldTransformMatrix(this._mat),v=d.transformPoint(e.x,e.y,this._p1),y=this._axis(t.horizontalAnchor,v.x,a.left,a.right,t.horizontalOffset,c,r),b=this._axis(t.verticalAnchor,v.y,a.top,a.bottom,t.verticalOffset,m,n),A=d.applyInverse(y,b,this._p2);e.x=A.x,e.y=A.y;return}e.x=this._axis(t.horizontalAnchor,e.x,a.left,a.right,t.horizontalOffset,c,r),e.y=this._axis(t.verticalAnchor,e.y,a.top,a.bottom,t.verticalOffset,m,n)}_resolveAgainstParent(e,t,r,n){var l;let i=(l=e.parentContainer)!=null?l:null;if(i){let u=i.width||0,d=i.height||0,v=(e.width||0)*(typeof e.scaleX=="number"?e.scaleX:1),y=(e.height||0)*(typeof e.scaleY=="number"?e.scaleY:1);e.x=this._axis(t.horizontalAnchor,e.x,0,u,t.horizontalOffset,v,r),e.y=this._axis(t.verticalAnchor,e.y,0,d,t.verticalOffset,y,n);return}let a=this._size(),c=this._sizeX(e),m=this._sizeY(e);e.x=this._axis(t.horizontalAnchor,e.x,0,a.width,t.horizontalOffset,c,r),e.y=this._axis(t.verticalAnchor,e.y,0,a.height,t.verticalOffset,m,n)}_axis(e,t,r,n,i,a,c){switch(e){case"left":case"top":return r+i+c*a;case"right":case"bottom":return n+i-(1-c)*a;case"center":return(r+n)/2+i+(c-.5)*a;default:return t}}_sizeX(e){return typeof e.displayWidth=="number"?e.displayWidth:typeof e.width=="number"?e.width:0}_sizeY(e){return typeof e.displayHeight=="number"?e.displayHeight:typeof e.height=="number"?e.height:0}on(e,t,r){return this.events.on(e,t,r),this}once(e,t,r){return this.events.once(e,t,r),this}off(e,t,r,n){return this.events.off(e,t,r,n),this}shutdown(){let e=this._scene.sys.events;e.off(h.default.Scenes.Events.CREATE,this.refresh,this),e.off(h.default.Scenes.Events.SHUTDOWN,this.shutdown,this),this._scene.scale.off(h.default.Scale.Events.RESIZE,this._onResize,this),this._objects.clear()}destroy(){this.shutdown(),this.events.destroy(),super.destroy()}};return D(R);})();
|
|
@@ -48,11 +48,18 @@ declare namespace PhaserEditorLayout {
|
|
|
48
48
|
readonly designSize: { width: number; height: number } | null;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
interface ZoneVariantMargins {
|
|
52
|
+
base?: Partial<ZoneMargins>;
|
|
53
|
+
portrait?: Partial<ZoneMargins>;
|
|
54
|
+
landscape?: Partial<ZoneMargins>;
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
class LayoutZone {
|
|
52
58
|
base: ZoneMargins;
|
|
53
59
|
portrait: Partial<ZoneMargins>;
|
|
54
60
|
landscape: Partial<ZoneMargins>;
|
|
55
61
|
constructor(scene: Phaser.Scene, provider: VariantProvider, marginTop?: number, marginRight?: number, marginBottom?: number, marginLeft?: number);
|
|
62
|
+
setMargins(variants: ZoneVariantMargins): this;
|
|
56
63
|
getRect(out?: Phaser.Geom.Rectangle): Phaser.Geom.Rectangle;
|
|
57
64
|
}
|
|
58
65
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phaserjs/phaser-editor-layout",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Responsive layout runtime for Phaser 3 — anchors, zones and safe areas. The runtime counterpart to Phaser Editor's responsive layout system.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|