@zakkster/lite-camera-pro 1.0.1 → 1.2.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/src/index.d.ts CHANGED
@@ -1,68 +1,27 @@
1
1
  /**
2
- * @zakkster/lite-camera-pro TypeScript Declarations
2
+ * @zakkster/lite-camera-pro -- TypeScript declarations (main entry).
3
+ *
4
+ * The full functional layer is re-exported from the per-subsystem sibling
5
+ * declarations (one declaration per type -- no duplicates). This file adds the
6
+ * CinematicCameraPro class, the debug-HUD facade, and the VERSION const.
3
7
  */
4
8
 
5
- // ── Follow Modes ──
6
- export declare const FollowMode: {
7
- readonly SMOOTH: 0;
8
- readonly LOCK: 1;
9
- readonly PREDICTIVE: 2;
10
- readonly CUT: 3;
11
- readonly HYBRID: 4;
12
- };
13
-
14
- export declare const FOLLOW_STRATEGIES: ReadonlyArray<
15
- (cam: CinematicCameraPro, dt: number, px: number, py: number, pvx: number, pvy: number) => void
16
- >;
17
-
18
- // ── Wrap Modes ──
19
- export declare const WrapMode: {
20
- readonly NONE: 0;
21
- readonly REPEAT_X: 1;
22
- readonly REPEAT_Y: 2;
23
- readonly REPEAT_BOTH: 3;
24
- };
25
-
26
- // ── Bounds Types ──
27
- export declare const BoundsType: {
28
- readonly HARD: 0;
29
- readonly SOFT: 1;
30
- readonly ELASTIC: 2;
31
- readonly NONE: 3;
32
- };
33
-
34
- // ── Shake Profile ──
35
- export interface ShakeProfile {
36
- trauma?: number;
37
- freq?: number;
38
- decay?: number;
39
- maxOffset?: number;
40
- maxAngle?: number;
41
- dirX?: number;
42
- dirY?: number;
43
- }
44
-
45
- // ── Shake Presets ──
46
- export declare const EXPLOSION: Readonly<ShakeProfile>;
47
- export declare const EARTHQUAKE: Readonly<ShakeProfile>;
48
- export declare const RECOIL: Readonly<ShakeProfile>;
49
- export declare const IMPACT: Readonly<ShakeProfile>;
50
- export declare const LANDING: Readonly<ShakeProfile>;
51
- export declare const DAMAGE: Readonly<ShakeProfile>;
52
- export declare const RUMBLE: Readonly<ShakeProfile>;
53
- export declare const HEAVY_IMPACT: Readonly<ShakeProfile>;
54
-
55
- export declare function getPreset(name: string): ShakeProfile | null;
56
- export declare function registerPreset(name: string, profile: ShakeProfile): void;
57
- export declare function listPresets(): string[];
58
-
59
- // ── Vec2 ──
60
- export interface Vec2 {
61
- x: number;
62
- y: number;
63
- }
64
-
65
- // ── Debug HUD Config ──
9
+ // -- Functional layer (mirrors the ./shake, ./parallax, ./bounds, ./multi,
10
+ // ./follow, ./sequence subpaths; same runtime identities) --
11
+ export * from './Shake.js';
12
+ export * from './ParallaxManager.js';
13
+ export * from './BoundsSystem.js';
14
+ export * from './MultiTarget.js';
15
+ export * from './FollowMode.js';
16
+ export * from './CameraSequence.js';
17
+
18
+ // -- Types needed locally by the class declaration --
19
+ import type { ShakeProfile } from './Shake.js';
20
+ import type { Vec2, MultiTargetOptions } from './MultiTarget.js';
21
+ import type { BoundsEdgesConfig } from './BoundsSystem.js';
22
+ import type { CameraSequence, CameraSequenceOptions } from './CameraSequence.js';
23
+
24
+ // -- Debug HUD (DebugHUD.js) -- facade only, no dedicated subpath --
66
25
  export interface DebugHUDConfig {
67
26
  show: {
68
27
  position: boolean;
@@ -83,66 +42,14 @@ export declare function createDebugHUDConfig(): DebugHUDConfig;
83
42
  export declare function drawDebugHUD(cam: CinematicCameraPro, ctx: CanvasRenderingContext2D, config?: DebugHUDConfig): void;
84
43
  export declare function drawDebugWorld(cam: CinematicCameraPro, ctx: CanvasRenderingContext2D, config?: DebugHUDConfig): void;
85
44
 
86
- // ── Camera Sequence ──
87
- export interface CameraSequenceOptions {
88
- loop?: boolean;
89
- onComplete?: () => void;
90
- blendOutTime?: number;
91
- }
92
-
93
- export interface StepOptions {
94
- ease?: (t: number) => number;
95
- at?: string | number;
96
- }
45
+ // -- Package version (bumped in lockstep with package.json + llms.txt) --
46
+ export declare const VERSION: string;
97
47
 
98
- export interface CameraSequence {
99
- moveTo(x: number, y: number, duration: number, opts?: StepOptions): CameraSequence;
100
- zoomTo(level: number, duration: number, opts?: StepOptions): CameraSequence;
101
- moveAndZoom(x: number, y: number, level: number, duration: number, opts?: StepOptions): CameraSequence;
102
- shake(profileOrName: string | ShakeProfile, intensity?: number, opts?: StepOptions): CameraSequence;
103
- wait(duration: number, opts?: StepOptions): CameraSequence;
104
- call(fn: () => void, opts?: StepOptions): CameraSequence;
105
- play(): CameraSequence;
106
- pause(): CameraSequence;
107
- resume(): CameraSequence;
108
- stop(): CameraSequence;
109
- seek(timeMs: number): CameraSequence;
110
- destroy(): void;
111
- readonly duration: number;
112
- readonly progress: number;
113
- readonly playing: boolean;
114
- }
115
-
116
- export declare function createCameraSequence(cam: CinematicCameraPro, options?: CameraSequenceOptions): CameraSequence;
117
- export declare function panTo(cam: CinematicCameraPro, x: number, y: number, duration: number, opts?: CameraSequenceOptions & StepOptions): CameraSequence;
118
- export declare function dramaticZoom(cam: CinematicCameraPro, x: number, y: number, zoom: number, duration: number, opts?: CameraSequenceOptions & StepOptions): CameraSequence;
119
- export declare function bossReveal(cam: CinematicCameraPro, x: number, y: number, totalMs?: number, opts?: CameraSequenceOptions): CameraSequence;
120
- export declare function timedShake(cam: CinematicCameraPro, presetOrProfile: string | ShakeProfile, holdMs?: number, opts?: CameraSequenceOptions): CameraSequence;
121
-
122
- // ── Multi-Target Options ──
123
- export interface MultiTargetOptions {
124
- paddingX?: number;
125
- paddingY?: number;
126
- padding?: number;
127
- minZoom?: number;
128
- maxZoom?: number;
129
- zoomSpeed?: number;
130
- followSpeed?: number;
131
- }
132
-
133
- // ── Bounds Config ──
134
- export interface BoundsEdgesConfig {
135
- left?: number;
136
- right?: number;
137
- top?: number;
138
- bottom?: number;
139
- }
140
-
141
- // ── Main Camera Class ──
48
+ // -- Main camera class --
142
49
  export declare class CinematicCameraPro {
143
50
  constructor(viewW: number, viewH: number, worldW: number, worldH: number, seed?: number);
144
51
 
145
- // ── Public state ──
52
+ // Public state
146
53
  readonly pos: Float32Array;
147
54
  readonly target: Float32Array;
148
55
  readonly look: Float32Array;
@@ -168,60 +75,87 @@ export declare class CinematicCameraPro {
168
75
  predictTime: number;
169
76
  hybridVerticalSnap: boolean;
170
77
 
78
+ /**
79
+ * update() clamps a finite dt above this ceiling before integrating so a
80
+ * frame-time spike cannot diverge the position lerp (default 0.1s). Plain
81
+ * tunable; not validated per frame. See update() for the full dt policy.
82
+ */
83
+ maxDt: number;
84
+
171
85
  debugConfig: DebugHUDConfig;
172
86
 
173
- // ── Follow Mode ──
87
+ // Follow mode
88
+ /** @throws Error `code = "ERR_CAMERA_MODE"` if mode is not an integer FollowMode in range. */
174
89
  setMode(mode: number): this;
175
90
 
176
- // ── Multi-Target ──
91
+ // Multi-target
92
+ /** @throws Error `code = "ERR_CAMERA_TARGETS"` if targets is not an array or any entry lacks finite x/y (validated at call time). */
177
93
  trackMultiple(targets: Vec2[], options?: MultiTargetOptions): this;
178
94
  trackSingle(): this;
95
+ /** @throws Error `code = "ERR_CAMERA_TARGETS"` if count is not an integer in [0, targets.length]. */
179
96
  setTargetCount(count: number): this;
180
97
 
181
- // ── Shake ──
98
+ // Shake
182
99
  addTrauma(amount: number): this;
183
100
  shake(profile: ShakeProfile, intensity?: number): this;
184
101
  shakePreset(name: string, intensity?: number): this;
185
102
  clearShakes(): this;
186
103
 
187
- // ── Sequences ──
104
+ // Sequences
188
105
  createSequence(options?: CameraSequenceOptions): CameraSequence;
189
106
  playSequence(seq: CameraSequence): this;
190
107
  stopSequence(): this;
191
108
  readonly sequencePlaying: boolean;
192
109
 
193
- // ── Zoom ──
110
+ // Zoom
111
+ /** @throws Error `code = "ERR_CAMERA_ZOOM"` if level is non-finite or duration is non-finite/negative. */
194
112
  setZoom(level: number, duration?: number, ease?: (t: number) => number): this;
113
+ /** @throws Error `code = "ERR_CAMERA_ZOOM"` if anchor x/y, level, or duration is non-finite (or duration negative). A non-function ease normalizes to null. */
195
114
  zoomAt(targetOrX: number | Vec2, yOrLevel: number, levelOrDur?: number, duration?: number, ease?: (t: number) => number): this;
196
115
 
197
- // ── Coordinate Conversion ──
116
+ // Coordinate conversion
198
117
  screenToWorld(sx: number, sy: number, out: Vec2): Vec2;
199
118
  worldToScreen(wx: number, wy: number, out: Vec2): Vec2;
200
119
 
201
- // ── Parallax ──
120
+ // Parallax
202
121
  addParallaxLayer(id: string, speedX: number, speedY?: number, opts?: { offsetX?: number; offsetY?: number; wrap?: number }): this;
203
122
  removeParallaxLayer(id: string): this;
204
123
  applyParallax(id: string, ctx: CanvasRenderingContext2D): boolean;
205
124
 
206
- // ── Bounds ──
125
+ // Bounds
207
126
  setBoundsType(type: number): this;
208
127
  setBoundsEdges(config: BoundsEdgesConfig): this;
209
128
  setBoundsRect(x: number, y: number, w: number, h: number): this;
210
129
  clearBoundsRect(): this;
211
130
 
212
- // ── Core ──
131
+ // Core
132
+ /**
133
+ * Advance the camera one frame. dt policy (fail closed): a non-finite or
134
+ * negative dt is a no-op (nothing mutated); dt 0/-0 is a legal no-advance
135
+ * frame; a finite dt above maxDt is clamped to maxDt (a dt exactly == maxDt
136
+ * passes untouched).
137
+ */
213
138
  update(dt: number, px: number, py: number, pvx?: number, pvy?: number): void;
214
139
  apply(ctx: CanvasRenderingContext2D): void;
215
140
 
216
- // ── Debug ──
141
+ // Debug
217
142
  debug(ctx: CanvasRenderingContext2D): void;
218
143
  debugHUD(ctx: CanvasRenderingContext2D): void;
219
144
 
220
- // ── Save / Load ──
145
+ // Save / load
221
146
  getState(): { posX: number; posY: number; targetX: number; targetY: number; zoom: number; mode: number };
147
+ /**
148
+ * Restore a pose-only snapshot (pos/target/zoom/mode). Validated in full
149
+ * before any field is written -- a rejected snapshot mutates nothing.
150
+ * posX/posY and targetX/targetY are both-or-neither; every present numeric
151
+ * must be finite; zoom is clamped to minZoom..maxZoom (zoom 0 -> minZoom);
152
+ * mode must be an integer FollowMode in range. Shake, sequences, and zoom
153
+ * animations are deliberately not serialized.
154
+ * @throws Error `code = "ERR_CAMERA_STATE"` on any violation.
155
+ */
222
156
  setState(snapshot: { posX?: number; posY?: number; targetX?: number; targetY?: number; zoom?: number; mode?: number }): this;
223
157
 
224
- // ── Lifecycle ──
158
+ // Lifecycle
225
159
  destroy(): void;
226
160
  }
227
161
 
package/src/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * Zero external dependencies outside the @zakkster ecosystem.
7
7
  */
8
8
 
9
- export const VERSION = "1.0.1";
9
+ export const VERSION = "1.2.0";
10
10
 
11
11
  // -- Core --
12
12
  export { CinematicCameraPro } from './CinematicCameraPro.js';