@idle-screens/schema 2.1.0 → 2.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/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ type BackgroundSpec = {
32
32
  type: 'gradient';
33
33
  stops: GradientStop[];
34
34
  band?: BandSpec;
35
+ drift?: BackgroundDrift;
35
36
  };
36
37
  /** A vertical gradient stop (`at` 0 = top, 1 = bottom). */
37
38
  interface GradientStop {
@@ -44,6 +45,13 @@ interface BandSpec {
44
45
  /** Band height in px. */
45
46
  height: number;
46
47
  }
48
+ /** Slow oscillation of gradient stop positions — makes the background feel alive. */
49
+ interface BackgroundDrift {
50
+ /** Full cycle period in ms. Floor: LIMITS.minDriftPeriod (10 s). */
51
+ period: number;
52
+ /** How far stops shift (fraction of the 0..1 range). Default 0.15, max 0.3. */
53
+ amount?: number;
54
+ }
47
55
  interface LayerSpec {
48
56
  count: number;
49
57
  sprite: SpriteSpec;
@@ -114,6 +122,14 @@ interface LayerSpec {
114
122
  alpha?: number;
115
123
  width?: number;
116
124
  };
125
+ /**
126
+ * Afterglow trail behind moving entities. Samples past positions analytically
127
+ * (no state, fully deterministic). `length` in ms, `fade` 0..1 (default 1 = full fade).
128
+ */
129
+ trail?: {
130
+ length: number;
131
+ fade?: number;
132
+ };
117
133
  }
118
134
  type SpriteSpec = {
119
135
  kind: 'emoji';
@@ -193,6 +209,8 @@ interface SpecError {
193
209
  interface ValidationResult {
194
210
  valid: boolean;
195
211
  errors: SpecError[];
212
+ /** Non-blocking warnings about unknown/misplaced properties or likely authoring mistakes. */
213
+ warnings?: SpecWarning[];
196
214
  }
197
215
  /** An advisory warning (non-blocking). Returned by `adviseSpec`. */
198
216
  interface SpecWarning {
@@ -215,11 +233,18 @@ declare const LIMITS: {
215
233
  readonly maxLinkLayerCount: 200;
216
234
  readonly minCyclePeriod: 500;
217
235
  readonly referenceViewport: 1080;
236
+ readonly maxTrailLength: 5000;
237
+ readonly maxTrailSamples: 24;
238
+ readonly minDriftPeriod: 10000;
239
+ readonly maxDriftAmount: 0.3;
218
240
  };
219
241
 
220
242
  /**
221
243
  * Validate an untrusted (agent- or JSON-authored) spec structurally + semantically.
222
- * Returns typed errors; never throws. `compileSaver` refuses to run an invalid spec.
244
+ * Returns typed errors and warnings; never throws. `compileSaver` refuses to run an invalid spec.
245
+ *
246
+ * Warnings are non-blocking advisories about unknown/misplaced properties and
247
+ * near-zero speeds. They don't prevent compilation but indicate likely authoring mistakes.
223
248
  */
224
249
  declare function validateSpec(spec: unknown): ValidationResult;
225
250
  /** Narrowing helper: validate + cast. Throws with a joined message when invalid. */
@@ -260,8 +285,9 @@ interface Placed {
260
285
  }
261
286
  declare function spriteVariants(sprite: SpriteSpec): number;
262
287
  /** Deterministically place a layer's entities using the seeded RNG (never Math.random).
263
- * `scale` multiplies every dimensional draw (default 1). Used for viewport units. */
264
- declare function buildEntities(layer: LayerSpec, rng: Rng, w: number, h: number, scale?: number): Entity[];
288
+ * `scale` multiplies every dimensional draw (default 1). Used for viewport units.
289
+ * `countScale` multiplies entity count for density-aware scaling (default 1). */
290
+ declare function buildEntities(layer: LayerSpec, rng: Rng, w: number, h: number, scale?: number, countScale?: number): Entity[];
265
291
  /** Analytic opacity of an entity at logical time `t` (ms). Pure, clamped to 0..1. */
266
292
  declare function alphaAt(e: Entity, t: number): number;
267
293
  /** Analytic size multiplier at time `t` (ms). Pure, clamped to > 0. */
@@ -318,6 +344,16 @@ declare function applyDeltasToSpec(spec: SaverSpec, deltas: SteerDelta[]): Saver
318
344
  * target immediately (k > 0). Layer counts round to integers.
319
345
  */
320
346
  declare function lerpSpec(from: SaverSpec, to: SaverSpec, k: number): SaverSpec;
347
+ /**
348
+ * Enumerate all steerable leaf paths in a (resolved) spec. Returns dot-paths
349
+ * like "layers.0.count", "background.stops.1.color", etc. Metadata fields
350
+ * (id, label, schemaVersion, seed, units, kind, type, key) are excluded —
351
+ * they describe structure, not tuneable values.
352
+ *
353
+ * Layer keys are NOT substituted: paths always use numeric indices.
354
+ * Consumers can map to key-based paths via resolveSpecPath if needed.
355
+ */
356
+ declare function steerablePaths(spec: unknown): string[];
321
357
  /** Smooth (ease-in-out) progress curve used for glides. */
322
358
  declare function easeSmooth(k: number): number;
323
359
  /**
@@ -335,6 +371,51 @@ declare function adviseSpec(spec: SaverSpec, viewport?: {
335
371
  height: number;
336
372
  }): SpecWarning[];
337
373
 
374
+ interface LayerSnapshot {
375
+ key: string | undefined;
376
+ count: number;
377
+ centroid: {
378
+ x: number;
379
+ y: number;
380
+ };
381
+ coverage: number;
382
+ meanAlpha: number;
383
+ linksDrawn: number | null;
384
+ linksExpected: number | null;
385
+ connectedComponents: number | null;
386
+ isolatedNodes: number | null;
387
+ }
388
+ interface SceneSnapshot {
389
+ t: number;
390
+ viewport: {
391
+ w: number;
392
+ h: number;
393
+ };
394
+ layers: LayerSnapshot[];
395
+ warnings: string[];
396
+ }
397
+ interface SceneDescription {
398
+ spec: {
399
+ id: string;
400
+ label: string;
401
+ units: string;
402
+ };
403
+ snapshots: SceneSnapshot[];
404
+ }
405
+ /**
406
+ * Deterministic scene analysis at one or more time values. Reuses `buildEntities`
407
+ * and `linkPairs` — no render needed. Returns structured data a non-vision model
408
+ * can use to understand what a spec looks like when rendered.
409
+ */
410
+ declare function describeScene(spec: SaverSpec, options?: {
411
+ viewport?: {
412
+ width: number;
413
+ height: number;
414
+ };
415
+ seed?: number;
416
+ times?: number[];
417
+ }): SceneDescription;
418
+
338
419
  /**
339
420
  * Reproduces the hand-coded Fish Aquarium saver as pure DATA — the discriminating test
340
421
  * that the schema is actually expressive: two layers (fish drifting both ways at varied
@@ -342,6 +423,13 @@ declare function adviseSpec(spec: SaverSpec, viewport?: {
342
423
  */
343
424
  declare const AQUARIUM_SPEC: SaverSpec;
344
425
 
426
+ /**
427
+ * Comet Shower: showcases trails (afterglow behind moving entities) and background
428
+ * drift (gradient stops breathing slowly). Three layers: a static star field, fast
429
+ * comets with long trails, and slow fireflies with short trails and pulse.
430
+ */
431
+ declare const COMETS_SPEC: SaverSpec;
432
+
345
433
  /**
346
434
  * Constellation: drifting stars connected by faint k-nearest links. Exercises
347
435
  * colors[] (multi-hued stars), links (k-nearest neighbor lines), and cycle
@@ -408,4 +496,4 @@ declare const EXAMPLE_SPECS: SaverSpec[];
408
496
  /** Lookup by saver id. */
409
497
  declare const EXAMPLE_BY_ID: Readonly<Record<string, SaverSpec>>;
410
498
 
411
- export { AQUARIUM_SPEC, type BackgroundSpec, type BandSpec, CONSTELLATION_SPEC, type CycleSpec, DASHBOARD_SPEC, EXAMPLE_BY_ID, EXAMPLE_SPECS, type Entity, type GradientStop, LANTERNS_SPEC, LIMITS, type LayerSpec, type MotionSpec, ORRERY_SPEC, type Placed, RAIN_SPEC, SAKURA_SPEC, SCHEMA_EXAMPLES, SCHEMA_VERSION, SNOWFALL_SPEC, type SaverSpec, type SchemaExample, type SpecError, type SpecWarning, type SpriteSpec, type SteerDelta, type ValidationResult, adviseSpec, alphaAt, applyDeltasToSpec, assertValidSpec, buildEntities, compileSaver, easeSmooth, lerpSpec, linkPairs, manifestFor, positionAt, resolveSpecPath, rotationAt, sizeAt, spriteIndexAt, spriteVariants, structuralSignature, validateSpec };
499
+ export { AQUARIUM_SPEC, type BackgroundDrift, type BackgroundSpec, type BandSpec, COMETS_SPEC, CONSTELLATION_SPEC, type CycleSpec, DASHBOARD_SPEC, EXAMPLE_BY_ID, EXAMPLE_SPECS, type Entity, type GradientStop, LANTERNS_SPEC, LIMITS, type LayerSnapshot, type LayerSpec, type MotionSpec, ORRERY_SPEC, type Placed, RAIN_SPEC, SAKURA_SPEC, SCHEMA_EXAMPLES, SCHEMA_VERSION, SNOWFALL_SPEC, type SaverSpec, type SceneDescription, type SceneSnapshot, type SchemaExample, type SpecError, type SpecWarning, type SpriteSpec, type SteerDelta, type ValidationResult, adviseSpec, alphaAt, applyDeltasToSpec, assertValidSpec, buildEntities, compileSaver, describeScene, easeSmooth, lerpSpec, linkPairs, manifestFor, positionAt, resolveSpecPath, rotationAt, sizeAt, spriteIndexAt, spriteVariants, steerablePaths, structuralSignature, validateSpec };