@viji-dev/core 0.7.8 → 0.8.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.
package/dist/index.d.ts CHANGED
@@ -754,6 +754,25 @@ declare interface ButtonParameter {
754
754
  category: ParameterCategory;
755
755
  }
756
756
 
757
+ /**
758
+ * An immediate edge in a capability's consumed-meaningfully state, delivered
759
+ * via `onCapabilityTransition`. Fires the instant the bit flips, independent
760
+ * of the ~1s performance snapshot.
761
+ */
762
+ export declare interface CapabilityTransition {
763
+ capability: 'audio' | 'video' | 'mouse' | 'keyboard' | 'pointer' | 'touch' | 'sensors' | 'devices' | 'cv';
764
+ /** Present when `capability` is `'cv'`. */
765
+ cvType?: 'faceDetection' | 'faceMesh' | 'emotion' | 'handTracking' | 'poseDetection' | 'segmentation';
766
+ /** Present when `capability` is `'cv'` — which CV level transitioned. */
767
+ level?: 'active' | 'meaningful';
768
+ /** The new state. */
769
+ active: boolean;
770
+ /** Engine frame counter at the transition. */
771
+ frameIndex: number;
772
+ /** Worker `performance.now()` timestamp at the transition (same clock as {@link FramePerfSample.timestamp}). */
773
+ timestamp: number;
774
+ }
775
+
757
776
  /**
758
777
  * Options accepted by `VijiCore.captureFrame()` for snapshotting the current
759
778
  * scene. Controls output format, encoding, and target resolution / aspect.
@@ -906,6 +925,20 @@ declare interface CoreCapabilities {
906
925
  hasGeneral: boolean;
907
926
  }
908
927
 
928
+ /** Frames a capability was true vs false over the report period. */
929
+ export declare interface CountPair {
930
+ trueCount: number;
931
+ falseCount: number;
932
+ }
933
+
934
+ /** Per-CV-feature live activity: `active` = model loaded + first inference completed (cost is being paid); `meaningful` = last result was non-empty. */
935
+ export declare interface CVActivity {
936
+ /** Feature is running/inferring (model loaded, first inference completed). */
937
+ active: boolean;
938
+ /** The most recent inference produced a non-empty result. */
939
+ meaningful: boolean;
940
+ }
941
+
909
942
  /**
910
943
  * Identifier for an individual computer-vision feature pipeline. Returned by
911
944
  * `VideoAPI.cv.getActiveFeatures()` and used internally to track state.
@@ -1188,6 +1221,52 @@ export declare interface FaceData {
1188
1221
  blendshapes: FaceBlendshapes | null;
1189
1222
  }
1190
1223
 
1224
+ /**
1225
+ * Per-frame "consumed-meaningfully" capability state — what the scene is
1226
+ * actually receiving and using on a given rendered frame. Connection-class
1227
+ * capabilities (audio/video/sensors/devices) reflect `isConnected`;
1228
+ * interaction-class (mouse/keyboard/pointer/touch) reflect active use of the
1229
+ * specific inputs the scene reads; CV reports `{active, meaningful}` per type.
1230
+ */
1231
+ export declare interface FrameCapabilities {
1232
+ audio: boolean;
1233
+ video: boolean;
1234
+ mouse: boolean;
1235
+ keyboard: boolean;
1236
+ pointer: boolean;
1237
+ touch: boolean;
1238
+ sensors: boolean;
1239
+ devices: boolean;
1240
+ cv: {
1241
+ faceDetection: CVActivity;
1242
+ faceMesh: CVActivity;
1243
+ emotion: CVActivity;
1244
+ handTracking: CVActivity;
1245
+ poseDetection: CVActivity;
1246
+ segmentation: CVActivity;
1247
+ };
1248
+ }
1249
+
1250
+ /** One per-frame performance + capability record. */
1251
+ export declare interface FramePerfSample {
1252
+ /** Engine frame counter at sample time. */
1253
+ frameIndex: number;
1254
+ /** Worker `performance.now()` timestamp at sample time. */
1255
+ timestamp: number;
1256
+ /** CPU time spent dispatching the render for this frame (ms). */
1257
+ cpuMs: number;
1258
+ /**
1259
+ * GPU time for this frame in ms, or `null` when unavailable. Always `null`
1260
+ * in steady state; populated only by `runFencedBenchmark()` (and `null`
1261
+ * there for 2D-canvas scenes).
1262
+ */
1263
+ gpuMs: number | null;
1264
+ /** Interval since the previous rendered frame (ms). Session-relative under benchmark. */
1265
+ frameIntervalMs: number;
1266
+ /** Consumed-meaningfully capability state for this frame. */
1267
+ capabilities: FrameCapabilities;
1268
+ }
1269
+
1191
1270
  declare interface FrameRateInfo {
1192
1271
  mode: FrameRateMode;
1193
1272
  screenRefreshRate: number;
@@ -1382,6 +1461,13 @@ export declare interface KeyboardEventData {
1382
1461
  metaKey: boolean;
1383
1462
  }
1384
1463
 
1464
+ /** Min/avg/max of a numeric field over the report period. */
1465
+ export declare interface MinAvgMax {
1466
+ min: number;
1467
+ avg: number;
1468
+ max: number;
1469
+ }
1470
+
1385
1471
  /**
1386
1472
  * Mouse input state for the current frame: position, individual button states,
1387
1473
  * per-frame movement, scroll wheel, and frame-based press / release events.
@@ -1512,6 +1598,12 @@ export declare interface OnsetSessionEndEvent {
1512
1598
  outcome: 'pattern' | 'cleared';
1513
1599
  }
1514
1600
 
1601
+ /**
1602
+ * P5 main-canvas mode. Only meaningful when {@link SceneData.renderer} is
1603
+ * `'p5'`: `'2d'` for the default 2D canvas, `'webgl'` for a WEBGL canvas.
1604
+ */
1605
+ export declare type P5CanvasMode = '2d' | 'webgl';
1606
+
1515
1607
  export declare interface ParameterAPI {
1516
1608
  define(groups: ParameterGroup[]): void;
1517
1609
  [key: string]: any;
@@ -1522,7 +1614,7 @@ export declare interface ParameterAPI {
1522
1614
  * is not currently available (e.g., `'audio'` controls hide when no audio
1523
1615
  * source is connected). `'general'` parameters are always visible.
1524
1616
  */
1525
- declare type ParameterCategory = 'audio' | 'video' | 'interaction' | 'general';
1617
+ export declare type ParameterCategory = 'audio' | 'video' | 'interaction' | 'general';
1526
1618
 
1527
1619
  export declare interface ParameterConfig {
1528
1620
  min?: number;
@@ -1544,7 +1636,7 @@ export declare interface ParameterConfig {
1544
1636
  }
1545
1637
 
1546
1638
  export declare interface ParameterDefinition {
1547
- type: 'slider' | 'color' | 'toggle' | 'select' | 'text' | 'number' | 'image' | 'button' | 'coordinate';
1639
+ type: ParameterType;
1548
1640
  defaultValue: ParameterValue;
1549
1641
  label?: string;
1550
1642
  description?: string;
@@ -1563,6 +1655,12 @@ export declare interface ParameterGroup {
1563
1655
  parameters: Record<string, ParameterDefinition>;
1564
1656
  }
1565
1657
 
1658
+ /**
1659
+ * The kind of UI control a parameter renders as. Used for the per-type
1660
+ * breakdown in {@link SceneData.parameterCounts}.
1661
+ */
1662
+ export declare type ParameterType = 'slider' | 'color' | 'toggle' | 'select' | 'text' | 'number' | 'image' | 'button' | 'coordinate';
1663
+
1566
1664
  export declare type ParameterValue = string | number | boolean | ImageBitmap | CoordinateValue | null;
1567
1665
 
1568
1666
  declare interface PatternInfo {
@@ -1572,14 +1670,9 @@ declare interface PatternInfo {
1572
1670
  }
1573
1671
 
1574
1672
  export declare interface PerformanceStats {
1575
- frameTime: number;
1576
1673
  resolution: Resolution;
1577
1674
  scale: number;
1578
1675
  frameRate: FrameRateInfo;
1579
- rendererType: RendererType;
1580
- memoryUsage?: number;
1581
- activeStreams?: number;
1582
- parameterCount?: number;
1583
1676
  cv?: {
1584
1677
  activeFeatures: CVFeature[];
1585
1678
  processingTime: number;
@@ -1587,6 +1680,57 @@ export declare interface PerformanceStats {
1587
1680
  actualFPS: number;
1588
1681
  isProcessing: boolean;
1589
1682
  };
1683
+ /** Per-frame records for the last report period. */
1684
+ frames: FramePerfSample[];
1685
+ /** Min/avg/max of each numeric timing field over the period. */
1686
+ timing: {
1687
+ cpuMs: MinAvgMax;
1688
+ frameIntervalMs: MinAvgMax;
1689
+ gpuMs?: MinAvgMax;
1690
+ };
1691
+ /** Per-capability true/false frame counts over the period. */
1692
+ capabilities: PeriodCapabilityCounts;
1693
+ }
1694
+
1695
+ /**
1696
+ * Per-capability frame counts over the report period. CV types report
1697
+ * separate `active` and `meaningful` pairs.
1698
+ */
1699
+ export declare interface PeriodCapabilityCounts {
1700
+ audio: CountPair;
1701
+ video: CountPair;
1702
+ mouse: CountPair;
1703
+ keyboard: CountPair;
1704
+ pointer: CountPair;
1705
+ touch: CountPair;
1706
+ sensors: CountPair;
1707
+ devices: CountPair;
1708
+ cv: {
1709
+ faceDetection: {
1710
+ active: CountPair;
1711
+ meaningful: CountPair;
1712
+ };
1713
+ faceMesh: {
1714
+ active: CountPair;
1715
+ meaningful: CountPair;
1716
+ };
1717
+ emotion: {
1718
+ active: CountPair;
1719
+ meaningful: CountPair;
1720
+ };
1721
+ handTracking: {
1722
+ active: CountPair;
1723
+ meaningful: CountPair;
1724
+ };
1725
+ poseDetection: {
1726
+ active: CountPair;
1727
+ meaningful: CountPair;
1728
+ };
1729
+ segmentation: {
1730
+ active: CountPair;
1731
+ meaningful: CountPair;
1732
+ };
1733
+ };
1590
1734
  }
1591
1735
 
1592
1736
  /**
@@ -1710,7 +1854,7 @@ declare interface PoseData {
1710
1854
  }[];
1711
1855
  }
1712
1856
 
1713
- declare type RendererType = 'native' | 'p5' | 'shader';
1857
+ export declare type RendererType = 'native' | 'p5' | 'shader';
1714
1858
 
1715
1859
  /**
1716
1860
  * Discrete pixel dimensions for a canvas, frame capture, or render target.
@@ -1722,6 +1866,50 @@ export declare type Resolution = {
1722
1866
  height: number;
1723
1867
  };
1724
1868
 
1869
+ /**
1870
+ * The set of engine capabilities a scene's code declares it uses, derived by
1871
+ * static analysis of the scene source (no execution). Detection is
1872
+ * **inclusive-biased**: a capability the scene actually uses is never hidden,
1873
+ * but a rarely-ambiguous case may show an extra one. Shader scenes are
1874
+ * detected from built-in uniform usage (exact); native/p5 scenes from
1875
+ * `viji.*` usage tokens.
1876
+ */
1877
+ export declare interface SceneCapabilities {
1878
+ /** Scene reads audio analysis (volume, bands, beat, FFT/waveform, or audio streams). */
1879
+ audio: boolean;
1880
+ /** Scene reads video input (camera frame, video streams, or device cameras). */
1881
+ video: boolean;
1882
+ /** Scene reads mouse state. */
1883
+ mouse: boolean;
1884
+ /** Scene reads keyboard state. */
1885
+ keyboard: boolean;
1886
+ /** Scene reads the unified pointer (mouse/touch) state. */
1887
+ pointer: boolean;
1888
+ /** Scene reads multi-touch state. */
1889
+ touch: boolean;
1890
+ /** Scene declares tunable parameters. */
1891
+ parameters: boolean;
1892
+ /** Scene reads internal device motion/orientation sensors (`viji.device`). */
1893
+ sensors: boolean;
1894
+ /** Scene reads external connected devices (`viji.devices`). */
1895
+ devices: boolean;
1896
+ /** Per-feature computer-vision usage. */
1897
+ cv: {
1898
+ /** Scene uses face detection (bounding boxes). */
1899
+ faceDetection: boolean;
1900
+ /** Scene uses face mesh / landmarks / blendshapes. */
1901
+ faceMesh: boolean;
1902
+ /** Scene uses emotion / expression detection. */
1903
+ emotion: boolean;
1904
+ /** Scene uses hand tracking. */
1905
+ handTracking: boolean;
1906
+ /** Scene uses body pose detection. */
1907
+ poseDetection: boolean;
1908
+ /** Scene uses body segmentation. */
1909
+ segmentation: boolean;
1910
+ };
1911
+ }
1912
+
1725
1913
  /**
1726
1914
  * Structured scene console envelope surfaced via `VijiCore.onSceneConsole`.
1727
1915
  *
@@ -1770,6 +1958,32 @@ export declare interface SceneConsoleMessage {
1770
1958
  sourceLocation?: SceneSourceLocation;
1771
1959
  }
1772
1960
 
1961
+ /**
1962
+ * Static metadata about a scene, derived without running it. Returned by
1963
+ * `VijiCore.getSceneData()`.
1964
+ *
1965
+ * `renderer`, `p5CanvasMode`, and `capabilities` are available synchronously
1966
+ * once the core is constructed. The parameter counts populate once the scene
1967
+ * has registered its parameters (mirroring how parameter data has always
1968
+ * surfaced), so read them after the core has initialized the scene.
1969
+ */
1970
+ export declare interface SceneData {
1971
+ /** Detected renderer the scene targets. */
1972
+ renderer: RendererType;
1973
+ /** P5 canvas mode; present only when `renderer` is `'p5'`. */
1974
+ p5CanvasMode?: P5CanvasMode;
1975
+ /** Capabilities the scene's code declares it uses (inclusive-biased). */
1976
+ capabilities: SceneCapabilities;
1977
+ /** Total number of parameters the scene defines. */
1978
+ parameterCount: number;
1979
+ /** Parameter count broken down by control type (every key present, 0 if unused). */
1980
+ parameterCounts: Record<ParameterType, number>;
1981
+ /** Total number of parameter groups the scene defines. */
1982
+ parameterGroupCount: number;
1983
+ /** Parameter count broken down by visibility category (every key present, 0 if unused). */
1984
+ parameterCountsByCategory: Record<ParameterCategory, number>;
1985
+ }
1986
+
1773
1987
  /**
1774
1988
  * Discriminator for scene runtime errors surfaced via `onSceneRuntimeError`.
1775
1989
  *
@@ -2428,7 +2642,7 @@ declare type TrackingState = 'TRACKING' | 'LOCKED' | 'BREAKDOWN' | 'LOST';
2428
2642
  /** Returned by `on*` listener registration calls; invoke to unsubscribe. */
2429
2643
  export declare type Unsubscribe = () => void;
2430
2644
 
2431
- export declare const VERSION = "0.7.4";
2645
+ export declare const VERSION = "0.8.0";
2432
2646
 
2433
2647
  /**
2434
2648
  * Real-time video API: drawable frame, dimensions, and the source-side
@@ -2826,6 +3040,9 @@ export declare class VijiCore {
2826
3040
  private currentInteractionEnabled;
2827
3041
  private parameterGroups;
2828
3042
  private parameterValues;
3043
+ private sceneRenderer;
3044
+ private sceneCapabilities;
3045
+ private sceneP5CanvasMode?;
2829
3046
  private parametersInitialized;
2830
3047
  private parameterListeners;
2831
3048
  private parameterDefinedListeners;
@@ -2835,6 +3052,9 @@ export declare class VijiCore {
2835
3052
  private sceneRuntimeErrorListeners;
2836
3053
  private sceneConsoleListeners;
2837
3054
  private stats;
3055
+ private performanceSnapshotListeners;
3056
+ private capabilityTransitionListeners;
3057
+ private capabilityReportingEnabled;
2838
3058
  constructor(config: VijiCoreConfig);
2839
3059
  /**
2840
3060
  * Capture current scene frame
@@ -2984,6 +3204,21 @@ export declare class VijiCore {
2984
3204
  * Get current core capabilities (what's currently active)
2985
3205
  */
2986
3206
  getCapabilities(): CoreCapabilities;
3207
+ /**
3208
+ * Returns static metadata about the scene: its renderer, the capabilities its
3209
+ * code declares it uses, and its parameter shape.
3210
+ *
3211
+ * `renderer`, `p5CanvasMode`, and `capabilities` are available immediately
3212
+ * after construction; the parameter counts populate once the scene has
3213
+ * registered its parameters.
3214
+ *
3215
+ * Distinct from {@link getCapabilities}, which reports what the *host*
3216
+ * currently provides (connected streams, interaction). This reports what the
3217
+ * *scene's code* declares it uses.
3218
+ *
3219
+ * @returns The scene's static metadata
3220
+ */
3221
+ getSceneData(): SceneData;
2987
3222
  /**
2988
3223
  * Inject mouse event (for headless cores or event forwarding)
2989
3224
  */
@@ -3165,6 +3400,34 @@ export declare class VijiCore {
3165
3400
  */
3166
3401
  onSceneConsole(listener: (message: SceneConsoleMessage) => void): Unsubscribe;
3167
3402
  private fireSceneConsole;
3403
+ /**
3404
+ * Subscribe to the ~1s performance + capability snapshot. Each call delivers
3405
+ * the latest {@link PerformanceStats} (per-frame `frames`, `timing`
3406
+ * aggregates, and period `capabilities` counts). Attaching a listener enables
3407
+ * worker-side reporting; the last listener detaching disables it.
3408
+ *
3409
+ * @param listener - Called on each snapshot with the current stats
3410
+ * @returns Unsubscribe function
3411
+ */
3412
+ onPerformanceSnapshot(listener: (stats: PerformanceStats) => void): Unsubscribe;
3413
+ private firePerformanceSnapshot;
3414
+ /**
3415
+ * Subscribe to immediate consumed-meaningfully capability transitions (a
3416
+ * capability starting/stopping providing data the scene uses). Fires the
3417
+ * instant the edge occurs, independent of the ~1s snapshot. Attaching a
3418
+ * listener enables worker-side reporting.
3419
+ *
3420
+ * @param listener - Called on each transition
3421
+ * @returns Unsubscribe function
3422
+ */
3423
+ onCapabilityTransition(listener: (transition: CapabilityTransition) => void): Unsubscribe;
3424
+ private fireCapabilityTransition;
3425
+ /**
3426
+ * Enable/disable worker-side capability + perf reporting based on whether any
3427
+ * perf listener is attached. Idempotent; safe before the worker is ready
3428
+ * (re-synced after `createWorker()` in `initialize()`).
3429
+ */
3430
+ private updateCapabilityReporting;
3168
3431
  /**
3169
3432
  * Notify parameter change listeners
3170
3433
  */
@@ -3536,6 +3799,22 @@ export declare class VijiCore {
3536
3799
  * Gets current performance statistics
3537
3800
  */
3538
3801
  getStats(): PerformanceStats;
3802
+ /**
3803
+ * Runs an on-demand fenced benchmark: the worker renders `frameCount` frames,
3804
+ * fencing each with `gl.finish()` to capture fence-accurate CPU + GPU time
3805
+ * per frame, and resolves with the collected samples. The scene advances
3806
+ * normally; steady-state perf reporting is suppressed for the run.
3807
+ *
3808
+ * Use only on a scene NOT serving as a live compositor source/mixer —
3809
+ * per-frame `gl.finish()` would stutter the mixer output (enforced below).
3810
+ * In-session `frameIntervalMs` includes the fence stall (session-relative);
3811
+ * use `cpuMs` + `gpuMs` for cost. `gpuMs` is `null` for 2D-canvas scenes.
3812
+ * `frameCount: 1` is the generic single-frame measurement.
3813
+ *
3814
+ * @param frameCount - Number of frames to benchmark (>= 1)
3815
+ * @returns The per-frame fenced samples
3816
+ */
3817
+ runFencedBenchmark(frameCount: number): Promise<FramePerfSample[]>;
3539
3818
  /**
3540
3819
  * Register a new external device
3541
3820
  * @param device Device metadata (id and name)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { A as a, V as i, a as s, b as e } from "./index-CNBiAcmD.js";
1
+ import { A as a, V as i, a as s, b as e } from "./index-xEjVcfB2.js";
2
2
  export {
3
3
  a as AudioSystem,
4
4
  i as VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viji-dev/core",
3
- "version": "0.7.8",
3
+ "version": "0.8.1",
4
4
  "description": "Universal execution engine for Viji Creative scenes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",