@holtjs/stage 0.4.1 → 0.5.1

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.
@@ -1,2 +1,2 @@
1
- import { $ as WebGpuCanvasContextLike, Q as WebGpuBootstrapResult, X as RendererWebGpuOptions, Y as RendererWebGpu, Z as RequestWebGpuOptions, et as WebGpuDeviceLike, tt as requestWebGpuDevice } from "./game-GdPaQUqH.js";
1
+ import { $ as WebGpuCanvasContextLike, Q as WebGpuBootstrapResult, X as RendererWebGpuOptions, Y as RendererWebGpu, Z as RequestWebGpuOptions, et as WebGpuDeviceLike, tt as requestWebGpuDevice } from "./game-CfUZiazr.js";
2
2
  export { RendererWebGpu, RendererWebGpuOptions, RequestWebGpuOptions, WebGpuBootstrapResult, WebGpuCanvasContextLike, WebGpuDeviceLike, requestWebGpuDevice };
@@ -1 +1 @@
1
- export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-BorAD6Kk.js";
1
+ export { t as RendererWebGpu, n as requestWebGpuDevice } from "./renderer-webgpu-BE6fTBzo.js";
@@ -0,0 +1,317 @@
1
+ import { Yt as BlendMode, bt as ImageObject, jt as SceneHostLike, ut as Container, yt as Graphics } from "./game-CfUZiazr.js";
2
+ export type RigCurveKind = 'linear' | 'step' | 'smoothstep' | 'outBack';
3
+ export interface RigBoneDef {
4
+ name: string;
5
+ parent?: string | null;
6
+ x?: number;
7
+ y?: number;
8
+ rotation?: number;
9
+ scaleX?: number;
10
+ scaleY?: number;
11
+ length?: number;
12
+ }
13
+ export interface RigSlotDef {
14
+ name: string;
15
+ bone: string;
16
+ defaultAttachment?: string | null;
17
+ zOrder?: number;
18
+ tint?: number;
19
+ alpha?: number;
20
+ blendMode?: BlendMode;
21
+ }
22
+ export interface RigAttachmentDef {
23
+ id: string;
24
+ textureKey: string;
25
+ frame?: string | number;
26
+ width: number;
27
+ height: number;
28
+ originX?: number;
29
+ originY?: number;
30
+ x?: number;
31
+ y?: number;
32
+ rotation?: number;
33
+ scaleX?: number;
34
+ scaleY?: number;
35
+ tint?: number;
36
+ alpha?: number;
37
+ }
38
+ export interface RigKeyframe {
39
+ timeMs: number;
40
+ x?: number;
41
+ y?: number;
42
+ rotation?: number;
43
+ scaleX?: number;
44
+ scaleY?: number;
45
+ curve?: RigCurveKind;
46
+ }
47
+ export interface RigEventKeyframe {
48
+ timeMs: number;
49
+ name: string;
50
+ }
51
+ export interface RigClipDef {
52
+ name: string;
53
+ durationMs: number;
54
+ loop?: boolean;
55
+ /** Keyframe tracks keyed by bone name; values are **additive** (`x`, `y`, `rotation`) or **multiplicative** (`scaleX`, `scaleY`) relative to rest pose. */
56
+ tracks: Record<string, RigKeyframe[]>;
57
+ /** Optional slot attachment overrides timed within the clip (e.g. blink / mouth swap). */
58
+ slotTracks?: Record<string, Array<{
59
+ timeMs: number;
60
+ attachment: string | null;
61
+ }>>;
62
+ events?: RigEventKeyframe[];
63
+ }
64
+ export interface RigSkeletonDef {
65
+ id: string;
66
+ bones: RigBoneDef[];
67
+ slots: RigSlotDef[];
68
+ attachments: Record<string, RigAttachmentDef>;
69
+ skins?: Record<string, Record<string, string | null>>;
70
+ clips?: Record<string, RigClipDef>;
71
+ }
72
+ export interface CompiledBone {
73
+ readonly index: number;
74
+ readonly name: string;
75
+ readonly parentIndex: number;
76
+ readonly restX: number;
77
+ readonly restY: number;
78
+ readonly restRotation: number;
79
+ readonly restScaleX: number;
80
+ readonly restScaleY: number;
81
+ readonly length: number;
82
+ }
83
+ export interface CompiledSlot {
84
+ readonly index: number;
85
+ readonly name: string;
86
+ readonly boneIndex: number;
87
+ readonly defaultAttachment: string | null;
88
+ readonly zOrder: number;
89
+ readonly restTint: number;
90
+ readonly restAlpha: number;
91
+ readonly blendMode: BlendMode;
92
+ }
93
+ export interface Rig2DSkeleton {
94
+ readonly id: string;
95
+ readonly bones: ReadonlyArray<CompiledBone>;
96
+ readonly boneIndexByName: ReadonlyMap<string, number>;
97
+ readonly slots: ReadonlyArray<CompiledSlot>;
98
+ readonly slotIndexByName: ReadonlyMap<string, number>;
99
+ readonly attachments: ReadonlyMap<string, RigAttachmentDef>;
100
+ readonly skins: ReadonlyMap<string, Record<string, string | null>>;
101
+ readonly clips: ReadonlyMap<string, RigClipDef>;
102
+ }
103
+ export interface RigPlayOptions {
104
+ loop?: boolean;
105
+ speed?: number;
106
+ crossfadeMs?: number;
107
+ restart?: boolean;
108
+ }
109
+ export interface RigOverlayOptions {
110
+ /** Restrict overlay animation to these bones (and optionally their descendants if `includeChildren !== false`). */
111
+ bones?: string[];
112
+ includeChildren?: boolean;
113
+ loop?: boolean;
114
+ speed?: number;
115
+ weight?: number;
116
+ blendInMs?: number;
117
+ blendOutMs?: number;
118
+ }
119
+ export interface RigWorldTransform {
120
+ x: number;
121
+ y: number;
122
+ rotation: number;
123
+ scaleX: number;
124
+ scaleY: number;
125
+ a: number;
126
+ b: number;
127
+ c: number;
128
+ d: number;
129
+ tx: number;
130
+ ty: number;
131
+ }
132
+ export type RigEventListener = (eventName: string, clipName: string, timeMs: number) => void;
133
+ /** Shortest signed angular delta in `[-PI, PI]`. */
134
+ export declare function wrapAngleDelta(fromRad: number, toRad: number): number;
135
+ export declare function evalRigCurve(t: number, kind?: RigCurveKind): number;
136
+ /** Validate and topologically sort a 2D skeletal cutout rig definition (`parentIndex < boneIndex`). */
137
+ export declare function defineRig2DSkeleton(def: RigSkeletonDef): Rig2DSkeleton;
138
+ /** Zero-GC runtime instance of a `Rig2DSkeleton` with FK solver, slot equipment table, and 2-layer clip mixer. */
139
+ export declare class Rig2DInstance {
140
+ readonly skeleton: Rig2DSkeleton;
141
+ x: number;
142
+ y: number;
143
+ rotation: number;
144
+ scaleX: number;
145
+ scaleY: number;
146
+ flipX: boolean;
147
+ flipY: boolean;
148
+ readonly boneLocalX: Float32Array;
149
+ readonly boneLocalY: Float32Array;
150
+ readonly boneLocalRot: Float32Array;
151
+ readonly boneLocalScaleX: Float32Array;
152
+ readonly boneLocalScaleY: Float32Array;
153
+ readonly boneManualX: Float32Array;
154
+ readonly boneManualY: Float32Array;
155
+ readonly boneManualRot: Float32Array;
156
+ readonly boneWorldMat: Float32Array;
157
+ readonly boneWorldRot: Float32Array;
158
+ readonly boneWorldScaleX: Float32Array;
159
+ readonly boneWorldScaleY: Float32Array;
160
+ private readonly slotAttachments;
161
+ readonly slotTint: Uint32Array;
162
+ readonly slotAlpha: Float32Array;
163
+ readonly slotZOrder: Int32Array;
164
+ private baseClip;
165
+ private baseTimeMs;
166
+ private baseSpeed;
167
+ private baseLoop;
168
+ private prevClip;
169
+ private prevTimeMs;
170
+ private crossfadeElapsedMs;
171
+ private crossfadeDurationMs;
172
+ private overlayClip;
173
+ private overlayTimeMs;
174
+ private overlaySpeed;
175
+ private overlayLoop;
176
+ private overlayWeight;
177
+ private overlayBlendInMs;
178
+ private overlayBlendOutMs;
179
+ private overlayMask;
180
+ private readonly sampleA;
181
+ private readonly sampleB;
182
+ private readonly listeners;
183
+ private worldDirty;
184
+ constructor(skeleton: Rig2DSkeleton);
185
+ /** Reset all bones, slots, and attachments to the skeleton's rest setup pose. */
186
+ resetToSetupPose(): this;
187
+ setPosition(x: number, y: number): this;
188
+ setScale(sx: number, sy?: number): this;
189
+ setFlip(flipX: boolean, flipY?: boolean): this;
190
+ /** Swap a single slot's equipped cutout part in O(1) (`null` hides/unequips the slot). */
191
+ setAttachment(slotName: string, attachmentId: string | null): this;
192
+ getAttachment(slotName: string): string | null;
193
+ getSlotAttachmentByIndex(slotIndex: number): RigAttachmentDef | null;
194
+ /** Apply a named skin from the skeleton or an explicit `{ slotName: attachmentId | null }` wardrobe map. */
195
+ applySkin(skinNameOrMap: string | Record<string, string | null>): this;
196
+ setSlotTint(slotName: string, tintRgb: number, alpha?: number): this;
197
+ /** Apply an additive procedural bone offset (e.g. aiming arm or head tracking cursor). */
198
+ setBoneManualOffset(boneName: string, dx?: number, dy?: number, drot?: number): this;
199
+ onEvent(fn: RigEventListener): () => void;
200
+ get currentClipName(): string | null;
201
+ get activeOverlayClipName(): string | null;
202
+ /** Start or crossfade to a base locomotion/idle animation clip. */
203
+ play(clipOrName: string | RigClipDef, opts?: RigPlayOptions): this;
204
+ /** Play an action overlay clip (e.g. axe chop, pickaxe mine, lantern raise) masked onto specific bones. */
205
+ playOverlay(clipOrName: string | RigClipDef, opts?: RigOverlayOptions): this;
206
+ clearOverlay(): this;
207
+ /** Deterministically advance animation tracks by `deltaMs` and fire any crossed keyframe events. */
208
+ step(deltaMs: number): this;
209
+ private advanceClipTime;
210
+ private emitEventsInRange;
211
+ private evaluatePose;
212
+ /** Solve hierarchical 2D Forward Kinematics across all bones in topological order (zero heap allocation). */
213
+ solveWorldTransforms(): this;
214
+ /** Query a bone's solved world-space position & orientation (ideal for attaching torches, lights, particles, or hitboxes). */
215
+ getBoneWorldTransform(boneName: string, localOffsetX?: number, localOffsetY?: number, out?: RigWorldTransform): RigWorldTransform;
216
+ }
217
+ export interface MountRig2DOptions {
218
+ trackId?: string;
219
+ depth?: number;
220
+ contactShadow?: {
221
+ rx: number;
222
+ ry: number;
223
+ alpha?: number;
224
+ color?: number;
225
+ offsetY?: number;
226
+ } | false;
227
+ }
228
+ export interface Rig2DView {
229
+ readonly container: Container;
230
+ readonly instance: Rig2DInstance;
231
+ readonly shadow: Graphics | null;
232
+ readonly slotImages: ReadonlyArray<ImageObject>;
233
+ /** Step animation + sync `Container` and slot `ImageObject`s in a single call. */
234
+ update(deltaMs?: number): void;
235
+ /** Sync display nodes from current `Rig2DInstance` state without advancing time. */
236
+ sync(): void;
237
+ destroy(): void;
238
+ }
239
+ /**
240
+ * Mount a `Rig2DInstance` onto a Stage `Scene` using nested `Container` + `ImageObject` nodes.
241
+ * Works identically across WebGL2 (single-batch when sharing a cutout atlas!), WebGPU, Canvas2D, and Node 60fps Headless.
242
+ */
243
+ export declare function mountRig2D(scene: SceneHostLike, instance: Rig2DInstance, opts?: MountRig2DOptions): Rig2DView;
244
+ export type CutoutShapeOp = {
245
+ kind: 'roundRect';
246
+ x: number;
247
+ y: number;
248
+ w: number;
249
+ h: number;
250
+ r: number;
251
+ fill?: number;
252
+ stroke?: number;
253
+ lineWidth?: number;
254
+ } | {
255
+ kind: 'ellipse';
256
+ cx: number;
257
+ cy: number;
258
+ rx: number;
259
+ ry: number;
260
+ fill?: number;
261
+ stroke?: number;
262
+ lineWidth?: number;
263
+ } | {
264
+ kind: 'circle';
265
+ cx: number;
266
+ cy: number;
267
+ r: number;
268
+ fill?: number;
269
+ stroke?: number;
270
+ lineWidth?: number;
271
+ } | {
272
+ kind: 'poly';
273
+ points: Array<[number, number]>;
274
+ fill?: number;
275
+ stroke?: number;
276
+ lineWidth?: number;
277
+ close?: boolean;
278
+ } | {
279
+ kind: 'line';
280
+ x1: number;
281
+ y1: number;
282
+ x2: number;
283
+ y2: number;
284
+ stroke: number;
285
+ lineWidth?: number;
286
+ };
287
+ export interface CutoutPartSpec {
288
+ id: string;
289
+ width: number;
290
+ height: number;
291
+ originX?: number;
292
+ originY?: number;
293
+ offsetX?: number;
294
+ offsetY?: number;
295
+ rotation?: number;
296
+ shapes: CutoutShapeOp[];
297
+ }
298
+ export interface BakedCutoutAtlas {
299
+ readonly textureKey: string;
300
+ readonly canvas: HTMLCanvasElement;
301
+ readonly width: number;
302
+ readonly height: number;
303
+ readonly frames: Record<string, {
304
+ x: number;
305
+ y: number;
306
+ w: number;
307
+ h: number;
308
+ }>;
309
+ readonly attachments: Record<string, RigAttachmentDef>;
310
+ /** Register the packed cutout sheet + all named sub-frames onto a Stage `Scene`'s `TextureManager`. */
311
+ registerOnScene(scene: SceneHostLike): void;
312
+ }
313
+ /**
314
+ * Pack procedural 2D cutout parts (heads, hats, robes, axes, pickaxes, torches, shields) onto a single padded atlas canvas
315
+ * with crisp hand-drawn outlines — zero external PNG files needed!
316
+ */
317
+ export declare function bakeCutoutAtlas(textureKey: string, parts: CutoutPartSpec[], createCanvasFn?: (w: number, h: number) => HTMLCanvasElement, padding?: number): BakedCutoutAtlas;