@replayablejs/pixi 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Replayable contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # @replayablejs/pixi
2
+
3
+ Connect Pixi rendering, asset loaders and layout to the playable lifecycle.
4
+
5
+ Part of [Replayable](https://github.com/replayablejs/replayable) **0.1.0-alpha.0**.
6
+ APIs may change during the alpha series.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ pnpm add @replayablejs/pixi@0.1.0-alpha.0
12
+ ```
13
+
14
+ ## Public surface
15
+
16
+ `createPixi`, `createButton`, sprite/text factories, `createLayout`, `fitText` and their types. Optional `/spine` entry: `createSpineIntegration`, `createSpine`, `CreateSpineOptions`.
17
+
18
+ [Usage and reference](https://github.com/replayablejs/replayable/blob/main/docs/reference/pixi.md).
19
+ The package manifest defines supported import paths; internal source files are not public APIs.
20
+
21
+ ## Development
22
+
23
+ From the repository root, install with `pnpm install --frozen-lockfile` and build dependencies
24
+ with `pnpm build`. Run `pnpm --filter @replayablejs/pixi test` for this package's tests.
25
+
26
+ ## Peer dependencies
27
+
28
+ - `@esotericsoftware/spine-pixi-v8`: `~4.3.13` (optional)
29
+ - `@replayablejs/runtime`: `workspace:*`
30
+ - `pixi.js`: `^8.20.1`
31
+
32
+ Workspace ranges are converted to package versions when packed.
33
+
34
+ ## License
35
+
36
+ Original code is [MIT licensed](https://github.com/replayablejs/replayable/blob/main/LICENSE). Bundled third-party resources retain
37
+ their accompanying license terms.
@@ -0,0 +1,23 @@
1
+ //#region src/factories/apply-container-options.ts
2
+ const ZERO_POINT = {
3
+ x: 0,
4
+ y: 0
5
+ };
6
+ const UNIT_SCALE = {
7
+ x: 1,
8
+ y: 1
9
+ };
10
+ /** Applies the transform and visibility defaults shared by Pixi containers. */
11
+ function applyContainerOptions(container, options) {
12
+ container.position.copyFrom(options.position ?? ZERO_POINT);
13
+ container.scale.copyFrom(options.scale ?? UNIT_SCALE);
14
+ container.pivot.copyFrom(options.pivot ?? ZERO_POINT);
15
+ container.rotation = options.rotation ?? 0;
16
+ container.alpha = options.alpha ?? 1;
17
+ container.visible = options.visible ?? true;
18
+ container.zIndex = options.zIndex ?? 0;
19
+ }
20
+ //#endregion
21
+ export { applyContainerOptions as t };
22
+
23
+ //# sourceMappingURL=apply-container-options-CloU_2Pk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-container-options-CloU_2Pk.js","names":[],"sources":["../src/factories/apply-container-options.ts"],"sourcesContent":["import type { Container } from 'pixi.js';\n\nimport type { DisplayObjectOptions } from '#types/factories.js';\n\nconst ZERO_POINT = { x: 0, y: 0 };\nconst UNIT_SCALE = { x: 1, y: 1 };\n\n/** Applies the transform and visibility defaults shared by Pixi containers. */\nexport function applyContainerOptions(container: Container, options: DisplayObjectOptions): void {\n container.position.copyFrom(options.position ?? ZERO_POINT);\n container.scale.copyFrom(options.scale ?? UNIT_SCALE);\n container.pivot.copyFrom(options.pivot ?? ZERO_POINT);\n container.rotation = options.rotation ?? 0;\n container.alpha = options.alpha ?? 1;\n container.visible = options.visible ?? true;\n container.zIndex = options.zIndex ?? 0;\n}\n"],"mappings":";AAIA,MAAM,aAAa;CAAE,GAAG;CAAG,GAAG;AAAE;AAChC,MAAM,aAAa;CAAE,GAAG;CAAG,GAAG;AAAE;;AAGhC,SAAgB,sBAAsB,WAAsB,SAAqC;CAC/F,UAAU,SAAS,SAAS,QAAQ,YAAY,UAAU;CAC1D,UAAU,MAAM,SAAS,QAAQ,SAAS,UAAU;CACpD,UAAU,MAAM,SAAS,QAAQ,SAAS,UAAU;CACpD,UAAU,WAAW,QAAQ,YAAY;CACzC,UAAU,QAAQ,QAAQ,SAAS;CACnC,UAAU,UAAU,QAAQ,WAAW;CACvC,UAAU,SAAS,QAAQ,UAAU;AACvC"}
@@ -0,0 +1,230 @@
1
+ import { a as CreateAnimatedSpriteOptions, c as CreateSpriteOptions, d as SpriteDisplayOptions, i as AnchorableDisplayObjectOptions, l as CreateTextOptions, n as PixiIntegration, o as CreateNineSliceSpriteOptions, r as ReplayablePixi, s as CreateSplitTextOptions, t as CreatePixiOptions, u as DisplayObjectOptions } from "./pixi-DXx3NI4T.js";
2
+ import { AnimatedSprite, Container, NineSliceSprite, PointData, SplitText, Sprite, Text } from "pixi.js";
3
+ //#region src/types/button.d.ts
4
+ /** Button behavior around caller-created artwork; no automatic layout or animation. */
5
+ interface CreateButtonOptions {
6
+ /** Ownership transfers to the button. Create and size the artwork before passing it. */
7
+ readonly content: Container;
8
+ /** Runs synchronously on a completed tap, after propagation has been stopped. */
9
+ readonly onActivate: () => void;
10
+ readonly enabled?: boolean;
11
+ }
12
+ /** A stable interaction container whose child artwork may animate independently. */
13
+ interface ReplayableButton {
14
+ readonly container: Container;
15
+ /** Disabling leaves the button visible but non-interactive; it does not dim artwork. */
16
+ setEnabled(this: void, enabled: boolean): void;
17
+ /** Removes listeners and destroys owned artwork, retaining shared asset textures. */
18
+ destroy(this: void): void;
19
+ }
20
+ //#endregion
21
+ //#region src/types/text.d.ts
22
+ /** Available space in the text parent's local units, before parent/layout scaling. */
23
+ interface FitTextOptions {
24
+ readonly width: number;
25
+ /** Omit when only horizontal fitting is needed. */
26
+ readonly height?: number;
27
+ }
28
+ //#endregion
29
+ //#region src/types/layout.d.ts
30
+ /** Alignment of laid-out content inside one named area. */
31
+ type LayoutAlignment = 'top-left' | 'top-center' | 'top-right' | 'center-left' | 'center' | 'center-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
32
+ /** How laid-out content is scaled relative to its named area. */
33
+ type LayoutScaleMode = 'none' | 'fit' | 'contain' | 'cover' | 'stretch';
34
+ /**
35
+ * Axis-aligned rectangle.
36
+ *
37
+ * `LayoutConfig.bounds` and resolved areas use layout-local pixels. Authored
38
+ * `LayoutAreaConfig.bounds` uses normalized fractions relative to the outer
39
+ * layout rectangle.
40
+ */
41
+ interface LayoutBounds {
42
+ /** Horizontal coordinate of the left edge. */
43
+ readonly x: number;
44
+ /** Vertical coordinate of the top edge. */
45
+ readonly y: number;
46
+ /** Horizontal extent; outer layout bounds require a positive value. */
47
+ readonly width: number;
48
+ /** Vertical extent; outer layout bounds require a positive value. */
49
+ readonly height: number;
50
+ }
51
+ /** Author-defined normalized bounds and placement behavior for one named area. */
52
+ interface LayoutAreaConfig {
53
+ /** Position of scaled content inside the resolved area; defaults to `center`. */
54
+ readonly align?: LayoutAlignment;
55
+ /** Normalized rectangle resolved relative to the outer layout bounds. */
56
+ readonly bounds: LayoutBounds;
57
+ /** Final pixel adjustment applied to content after alignment. */
58
+ readonly offset?: PointData;
59
+ /** Scaling policy applied before content alignment; defaults to `fit`. */
60
+ readonly scale?: LayoutScaleMode;
61
+ }
62
+ /** Selects which diagnostic labels are visible during development. */
63
+ interface LayoutDebugLabelOptions {
64
+ /** Shows dimensions for every resolved named area. */
65
+ readonly areas?: boolean;
66
+ /** Shows dimensions for every attached content box. */
67
+ readonly content?: boolean;
68
+ /** Shows the outer layout dimensions. */
69
+ readonly layout?: boolean;
70
+ }
71
+ /** Selects which development-only layout diagnostics are visible. */
72
+ interface LayoutDebugOptions {
73
+ /** Shows green occupied and amber empty named-area rectangles. */
74
+ readonly areaBounds?: boolean;
75
+ /** Shows the magenta axis-aligned boxes used to place and scale content. */
76
+ readonly contentBounds?: boolean;
77
+ /** Enables every label or independently configures layout, area, and content labels. */
78
+ readonly labels?: boolean | LayoutDebugLabelOptions;
79
+ /** Shows the cyan outer layout rectangle. */
80
+ readonly layoutBounds?: boolean;
81
+ }
82
+ /** Complete named-area layout definition. */
83
+ interface LayoutConfig {
84
+ /** Layout-local rectangle against which normalized areas are resolved. */
85
+ readonly bounds: LayoutBounds;
86
+ /** Enables all diagnostics or selectively configures them during development. */
87
+ readonly debug?: boolean | LayoutDebugOptions;
88
+ /** Named normalized regions to which application display objects can be attached. */
89
+ readonly areas: Readonly<Record<string, LayoutAreaConfig>>;
90
+ }
91
+ /** Read-only resolved placement of one named area in layout-local coordinates. */
92
+ interface ResolvedLayoutArea {
93
+ /** Fully defaulted content alignment. */
94
+ readonly align: LayoutAlignment;
95
+ /** Area rectangle resolved into layout-local pixels. */
96
+ readonly bounds: LayoutBounds;
97
+ /** Stable authored key used by attach and move operations. */
98
+ readonly name: string;
99
+ /** Immutable pixel adjustment applied after alignment. */
100
+ readonly offset: Readonly<PointData>;
101
+ /** Fully defaulted scaling policy. */
102
+ readonly scale: LayoutScaleMode;
103
+ }
104
+ /** Controller returned by `createLayout()`. */
105
+ interface ReplayableLayout {
106
+ /**
107
+ * Pixi container that the application adds to its chosen stage.
108
+ * Attached content remains a direct child; named areas are calculations, not
109
+ * additional scene-graph containers.
110
+ */
111
+ readonly container: Container;
112
+ /**
113
+ * Attaches content to a named area and immediately lays it out.
114
+ *
115
+ * The layout owns the attached object's position and, unless the area's
116
+ * scale mode is `none`, its scale. Automatic fitting measures local bounds;
117
+ * it does not include rotation or skew applied directly to the attached
118
+ * object. Put transformed content inside an untransformed application-owned
119
+ * container when those transforms must contribute to fitting.
120
+ * Throws for unknown areas, duplicate attachment, destroyed content, parent
121
+ * cycles, or content that cannot be measured for its scaling mode.
122
+ */
123
+ attach(areaName: string, content: Container): void;
124
+ /**
125
+ * Stops managing and removes attached content from the layout container.
126
+ * The content remains alive and can be attached elsewhere by the application.
127
+ */
128
+ detach(content: Container): void;
129
+ /**
130
+ * Returns an immutable resolved-area snapshot, or `undefined` when absent.
131
+ * Previously returned snapshots do not change after `update()`.
132
+ */
133
+ getArea(name: string): ResolvedLayoutArea | undefined;
134
+ /**
135
+ * Moves attached content to another named area without reparenting it.
136
+ * The operation is atomic: failure preserves its previous area and transform.
137
+ */
138
+ move(content: Container, areaName: string): void;
139
+ /**
140
+ * Atomically replaces the layout definition and recalculates all attachments.
141
+ * An occupied area cannot be removed until its content is detached or moved.
142
+ */
143
+ update(config: LayoutConfig): void;
144
+ /**
145
+ * Releases bookkeeping and destroys the owned container without destroying
146
+ * application content. Repeated calls are harmless.
147
+ */
148
+ destroy(): void;
149
+ }
150
+ //#endregion
151
+ //#region src/create-pixi.d.ts
152
+ /** Initializes Pixi around Replayable's assets, lifecycle, and shared canvas. */
153
+ declare function createPixi(options?: CreatePixiOptions): Promise<ReplayablePixi>;
154
+ //#endregion
155
+ //#region src/factories/create-button.d.ts
156
+ /**
157
+ * Wraps artwork in a stable hit target without choosing its visuals or action.
158
+ * Children are non-interactive: the button owns completed taps for the whole artwork.
159
+ * Bounds are captured once, including the content's initial transform. Later artwork
160
+ * animations do not shrink the hit target or change the bounds consumed by layout.
161
+ *
162
+ * @example
163
+ * const button = createButton({ content: artwork, onActivate: handleAction });
164
+ * stage.addChild(button.container);
165
+ * button.setEnabled(false);
166
+ * // Disposing the button also destroys artwork, but not its shared textures.
167
+ * button.destroy();
168
+ */
169
+ declare function createButton(options: CreateButtonOptions): ReplayableButton;
170
+ //#endregion
171
+ //#region src/factories/create-animated-sprite.d.ts
172
+ /** Creates an unattached animated sprite driven by Pixi's Replayable-managed ticker. */
173
+ declare function createAnimatedSprite(options: CreateAnimatedSpriteOptions): AnimatedSprite;
174
+ //#endregion
175
+ //#region src/factories/create-nine-slice-sprite.d.ts
176
+ /** Creates an unattached nine-slice sprite with explicitly named borders. */
177
+ declare function createNineSliceSprite(options: CreateNineSliceSpriteOptions): NineSliceSprite;
178
+ //#endregion
179
+ //#region src/factories/create-sprite.d.ts
180
+ /** Creates an unattached Pixi sprite with Replayable's conventional defaults. */
181
+ declare function createSprite(options?: CreateSpriteOptions): Sprite;
182
+ //#endregion
183
+ //#region src/factories/create-split-text.d.ts
184
+ /**
185
+ * Creates unattached split text with Pixi's native splitting options.
186
+ * Unlike Text, SplitText is a container, so it has no shared anchor default.
187
+ * With autoSplit: false, call split() explicitly before accessing the characters.
188
+ * Fitting, localization, and character animation remain application concerns.
189
+ */
190
+ declare function createSplitText(options: CreateSplitTextOptions): SplitText;
191
+ //#endregion
192
+ //#region src/factories/create-text.d.ts
193
+ /** Creates unattached Pixi canvas text while leaving content and layout to the application. */
194
+ declare function createText(options: CreateTextOptions): Text;
195
+ //#endregion
196
+ //#region src/layout/create-layout.d.ts
197
+ /**
198
+ * Creates a named-area layout whose container can be mounted on any Pixi stage.
199
+ *
200
+ * @example Fitting rotated content through an explicit layout root
201
+ * ```ts
202
+ * const layoutRoot = new Container();
203
+ * const image = createSprite({ texture: 'character' });
204
+ *
205
+ * image.rotation = Math.PI / 4;
206
+ * layoutRoot.addChild(image);
207
+ * layout.attach('character', layoutRoot);
208
+ * ```
209
+ *
210
+ * The extra container is opt-in: ordinary untransformed content can be
211
+ * attached directly without adding hidden nodes to the Pixi scene graph.
212
+ *
213
+ * Development builds transparently decorate the core controller with layout
214
+ * diagnostics. `import.meta.env.DEV` is replaced at build time, allowing the
215
+ * complete debugger branch to be removed from production playable bundles.
216
+ */
217
+ declare function createLayout(config: LayoutConfig): ReplayableLayout;
218
+ //#endregion
219
+ //#region src/text/fit-text.d.ts
220
+ /**
221
+ * Uniformly fits text inside a box without enlarging beyond its authored size.
222
+ * Replaces the object's scale using local bounds, so repeated fitting never
223
+ * compounds a previous fit. Position, pivot, wrapping, and text remain unchanged.
224
+ * Split manually managed SplitText before fitting, and fit before animating its
225
+ * characters (or supply stable boundsArea). Empty bounds impose no constraint.
226
+ */
227
+ declare function fitText(text: Text | SplitText, options: FitTextOptions): void;
228
+ //#endregion
229
+ export { type AnchorableDisplayObjectOptions, type CreateAnimatedSpriteOptions, type CreateButtonOptions, type CreateNineSliceSpriteOptions, type CreatePixiOptions, type CreateSplitTextOptions, type CreateSpriteOptions, type CreateTextOptions, type DisplayObjectOptions, type FitTextOptions, type LayoutAlignment, type LayoutAreaConfig, type LayoutBounds, type LayoutConfig, type LayoutDebugLabelOptions, type LayoutDebugOptions, type LayoutScaleMode, type PixiIntegration, type ReplayableButton, type ReplayableLayout, type ReplayablePixi, type ResolvedLayoutArea, type SpriteDisplayOptions, createAnimatedSprite, createButton, createLayout, createNineSliceSprite, createPixi, createSplitText, createSprite, createText, fitText };
230
+ //# sourceMappingURL=index.d.ts.map