@elah/core 0.1.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.
Files changed (153) hide show
  1. package/dist/actions/index.d.ts +3 -0
  2. package/dist/actions/index.js +1 -0
  3. package/dist/actions/splitClipAtPlayhead.d.ts +8 -0
  4. package/dist/actions/splitClipAtPlayhead.js +34 -0
  5. package/dist/actions/types.d.ts +8 -0
  6. package/dist/actions/types.js +1 -0
  7. package/dist/assets/importFiles.d.ts +29 -0
  8. package/dist/assets/importFiles.js +351 -0
  9. package/dist/assets/index.d.ts +10 -0
  10. package/dist/assets/index.js +13 -0
  11. package/dist/assets/store.d.ts +13 -0
  12. package/dist/assets/store.js +20 -0
  13. package/dist/assets/types.d.ts +23 -0
  14. package/dist/assets/types.js +1 -0
  15. package/dist/debug/trace.d.ts +20 -0
  16. package/dist/debug/trace.js +98 -0
  17. package/dist/editor/TimelineEngine.d.ts +65 -0
  18. package/dist/editor/TimelineEngine.js +413 -0
  19. package/dist/editor-context.d.ts +10 -0
  20. package/dist/editor-context.js +10 -0
  21. package/dist/elements/audio.d.ts +13 -0
  22. package/dist/elements/audio.js +4 -0
  23. package/dist/elements/base.d.ts +40 -0
  24. package/dist/elements/base.js +39 -0
  25. package/dist/elements/image.d.ts +13 -0
  26. package/dist/elements/image.js +4 -0
  27. package/dist/elements/text.d.ts +12 -0
  28. package/dist/elements/text.js +8 -0
  29. package/dist/elements/video.d.ts +13 -0
  30. package/dist/elements/video.js +4 -0
  31. package/dist/export/ExportWorker.d.ts +1 -0
  32. package/dist/export/ExportWorker.js +371 -0
  33. package/dist/export/exportVideo.d.ts +3 -0
  34. package/dist/export/exportVideo.js +118 -0
  35. package/dist/export/index.d.ts +2 -0
  36. package/dist/export/index.js +1 -0
  37. package/dist/export/lazyExport.d.ts +4 -0
  38. package/dist/export/lazyExport.js +4 -0
  39. package/dist/export/types.d.ts +37 -0
  40. package/dist/export/types.js +1 -0
  41. package/dist/index.d.ts +48 -0
  42. package/dist/index.js +28 -0
  43. package/dist/media/audio/AudioPlaybackController.d.ts +26 -0
  44. package/dist/media/audio/AudioPlaybackController.js +125 -0
  45. package/dist/media/video/DecoderBackedVideoFrameProvider.d.ts +51 -0
  46. package/dist/media/video/DecoderBackedVideoFrameProvider.js +125 -0
  47. package/dist/media/video/FrameCache.d.ts +28 -0
  48. package/dist/media/video/FrameCache.js +88 -0
  49. package/dist/media/video/StreamingFrameProducer.d.ts +57 -0
  50. package/dist/media/video/StreamingFrameProducer.js +356 -0
  51. package/dist/media/video/VideoDecoderManager.d.ts +59 -0
  52. package/dist/media/video/VideoDecoderManager.js +342 -0
  53. package/dist/media/video/VideoFrameProvider.d.ts +101 -0
  54. package/dist/media/video/VideoFrameProvider.js +257 -0
  55. package/dist/media/video/demuxer/MediabunnyDemuxer.d.ts +23 -0
  56. package/dist/media/video/demuxer/MediabunnyDemuxer.js +88 -0
  57. package/dist/media/video/demuxer/createMediabunnyBackend.d.ts +32 -0
  58. package/dist/media/video/demuxer/createMediabunnyBackend.js +156 -0
  59. package/dist/media/video/index.d.ts +8 -0
  60. package/dist/media/video/index.js +5 -0
  61. package/dist/playback/PlaybackEngine.d.ts +50 -0
  62. package/dist/playback/PlaybackEngine.js +188 -0
  63. package/dist/renderer/gpu/GpuRenderer.d.ts +38 -0
  64. package/dist/renderer/gpu/GpuRenderer.js +208 -0
  65. package/dist/renderer/gpu/RenderGraph.d.ts +10 -0
  66. package/dist/renderer/gpu/RenderGraph.js +80 -0
  67. package/dist/renderer/gpu/ShaderProgram.d.ts +14 -0
  68. package/dist/renderer/gpu/ShaderProgram.js +76 -0
  69. package/dist/renderer/gpu/TexturePool.d.ts +25 -0
  70. package/dist/renderer/gpu/TexturePool.js +93 -0
  71. package/dist/renderer/gpu/VideoTexture.d.ts +13 -0
  72. package/dist/renderer/gpu/VideoTexture.js +54 -0
  73. package/dist/renderer/gpu/WebGLContext.d.ts +28 -0
  74. package/dist/renderer/gpu/WebGLContext.js +102 -0
  75. package/dist/renderer/gpu/debug/DebugGpuRenderer.d.ts +27 -0
  76. package/dist/renderer/gpu/debug/DebugGpuRenderer.js +108 -0
  77. package/dist/renderer/gpu/debug/DebugOverlay.d.ts +17 -0
  78. package/dist/renderer/gpu/debug/DebugOverlay.js +83 -0
  79. package/dist/renderer/gpu/debug/GpuDebugCounters.d.ts +38 -0
  80. package/dist/renderer/gpu/debug/GpuDebugCounters.js +72 -0
  81. package/dist/renderer/gpu/debug/GpuDebugGlobal.d.ts +16 -0
  82. package/dist/renderer/gpu/debug/GpuDebugGlobal.js +14 -0
  83. package/dist/renderer/gpu/debug/GpuRendererDebugPanel.d.ts +31 -0
  84. package/dist/renderer/gpu/debug/GpuRendererDebugPanel.js +128 -0
  85. package/dist/renderer/gpu/debug/RecordingGl.d.ts +88 -0
  86. package/dist/renderer/gpu/debug/RecordingGl.js +214 -0
  87. package/dist/renderer/gpu/debug/playground.d.ts +20 -0
  88. package/dist/renderer/gpu/debug/playground.js +64 -0
  89. package/dist/renderer/gpu/debug/scenarios.d.ts +7 -0
  90. package/dist/renderer/gpu/debug/scenarios.js +145 -0
  91. package/dist/renderer/gpu/debug/types.d.ts +16 -0
  92. package/dist/renderer/gpu/debug/types.js +1 -0
  93. package/dist/renderer/gpu/layers/FrameProbeLayer.d.ts +16 -0
  94. package/dist/renderer/gpu/layers/FrameProbeLayer.js +127 -0
  95. package/dist/renderer/gpu/layers/ImageLayer.d.ts +23 -0
  96. package/dist/renderer/gpu/layers/ImageLayer.js +124 -0
  97. package/dist/renderer/gpu/layers/TestLayer.d.ts +16 -0
  98. package/dist/renderer/gpu/layers/TestLayer.js +109 -0
  99. package/dist/renderer/gpu/layers/TextLayer.d.ts +19 -0
  100. package/dist/renderer/gpu/layers/TextLayer.js +166 -0
  101. package/dist/renderer/gpu/layers/VideoLayer.d.ts +38 -0
  102. package/dist/renderer/gpu/layers/VideoLayer.js +194 -0
  103. package/dist/renderer/gpu/layers/drawRect.d.ts +13 -0
  104. package/dist/renderer/gpu/layers/drawRect.js +55 -0
  105. package/dist/renderer/gpu/layers/objectFit.d.ts +7 -0
  106. package/dist/renderer/gpu/layers/objectFit.js +26 -0
  107. package/dist/renderer/gpu/layers/textLayout.d.ts +47 -0
  108. package/dist/renderer/gpu/layers/textLayout.js +82 -0
  109. package/dist/renderer/gpu/layers/types.d.ts +18 -0
  110. package/dist/renderer/gpu/layers/types.js +1 -0
  111. package/dist/renderer/gpu/shaders/quad.frag.d.ts +1 -0
  112. package/dist/renderer/gpu/shaders/quad.frag.js +14 -0
  113. package/dist/renderer/gpu/shaders/quad.vert.d.ts +1 -0
  114. package/dist/renderer/gpu/shaders/quad.vert.js +28 -0
  115. package/dist/renderer/gpu/types.d.ts +21 -0
  116. package/dist/renderer/gpu/types.js +1 -0
  117. package/dist/renderer/gpu/viewport.d.ts +7 -0
  118. package/dist/renderer/gpu/viewport.js +33 -0
  119. package/dist/renderer/types.d.ts +7 -0
  120. package/dist/renderer/types.js +1 -0
  121. package/dist/resolver/resolveTimeline.d.ts +3 -0
  122. package/dist/resolver/resolveTimeline.js +249 -0
  123. package/dist/resolver/scene.d.ts +54 -0
  124. package/dist/resolver/scene.js +1 -0
  125. package/dist/stores/playback.store.d.ts +50 -0
  126. package/dist/stores/playback.store.js +42 -0
  127. package/dist/stores/selection.store.d.ts +12 -0
  128. package/dist/stores/selection.store.js +19 -0
  129. package/dist/stores/tracks.store.d.ts +19 -0
  130. package/dist/stores/tracks.store.js +27 -0
  131. package/dist/stores/transitions.store.d.ts +9 -0
  132. package/dist/stores/transitions.store.js +7 -0
  133. package/dist/track/track.d.ts +8 -0
  134. package/dist/track/track.js +19 -0
  135. package/dist/types/index.d.ts +117 -0
  136. package/dist/types/index.js +1 -0
  137. package/dist/utils/frames.d.ts +20 -0
  138. package/dist/utils/frames.js +40 -0
  139. package/dist/utils/id.d.ts +1 -0
  140. package/dist/utils/id.js +3 -0
  141. package/dist/utils/snap.d.ts +5 -0
  142. package/dist/utils/snap.js +79 -0
  143. package/dist/visitor/add.d.ts +3 -0
  144. package/dist/visitor/add.js +16 -0
  145. package/dist/visitor/clone.d.ts +3 -0
  146. package/dist/visitor/clone.js +25 -0
  147. package/dist/visitor/remove.d.ts +5 -0
  148. package/dist/visitor/remove.js +29 -0
  149. package/dist/visitor/split.d.ts +3 -0
  150. package/dist/visitor/split.js +31 -0
  151. package/dist/visitor/update.d.ts +4 -0
  152. package/dist/visitor/update.js +31 -0
  153. package/package.json +31 -0
@@ -0,0 +1,102 @@
1
+ export class WebGLContext {
2
+ constructor(options = {}) {
3
+ this._gl = null;
4
+ this._isWebGL2 = false;
5
+ this._lost = false;
6
+ this._onLost = options.onLost;
7
+ this._onRestore = options.onRestore;
8
+ this.canvas = document.createElement('canvas');
9
+ this.canvas.style.display = 'block';
10
+ this.canvas.style.width = '100%';
11
+ this.canvas.style.height = '100%';
12
+ const ctxAttribs = {
13
+ alpha: options.alpha ?? false,
14
+ antialias: false,
15
+ depth: false,
16
+ stencil: false,
17
+ preserveDrawingBuffer: options.preserveDrawingBuffer ?? false,
18
+ powerPreference: options.powerPreference ?? 'default',
19
+ };
20
+ const gl2 = this.canvas.getContext('webgl2', ctxAttribs);
21
+ if (gl2) {
22
+ this._gl = gl2;
23
+ this._isWebGL2 = true;
24
+ }
25
+ else {
26
+ const gl1 = this.canvas.getContext('webgl', ctxAttribs);
27
+ if (gl1) {
28
+ this._gl = gl1;
29
+ this._isWebGL2 = false;
30
+ }
31
+ }
32
+ if (!this._gl) {
33
+ throw new Error('WebGLContext: WebGL is not supported or has been disabled in this browser.');
34
+ }
35
+ this._handleLost = (e) => {
36
+ e.preventDefault();
37
+ this._lost = true;
38
+ this._gl = null;
39
+ this._onLost?.();
40
+ };
41
+ this._handleRestored = () => {
42
+ this._lost = false;
43
+ const restored = this.canvas.getContext('webgl2', ctxAttribs)
44
+ ?? this.canvas.getContext('webgl', ctxAttribs);
45
+ if (restored) {
46
+ this._gl = restored;
47
+ this._initGLState();
48
+ this._onRestore?.(this._gl);
49
+ }
50
+ };
51
+ this.canvas.addEventListener('webglcontextlost', this._handleLost);
52
+ this.canvas.addEventListener('webglcontextrestored', this._handleRestored);
53
+ this._initGLState();
54
+ }
55
+ get isLost() {
56
+ return this._lost;
57
+ }
58
+ get isWebGL2() {
59
+ return this._isWebGL2;
60
+ }
61
+ get gl() {
62
+ return this._gl;
63
+ }
64
+ resize(cssWidth, cssHeight, dpr = 1) {
65
+ const physicalW = Math.round(cssWidth * dpr);
66
+ const physicalH = Math.round(cssHeight * dpr);
67
+ if (this.canvas.width === physicalW && this.canvas.height === physicalH)
68
+ return;
69
+ this.canvas.width = physicalW;
70
+ this.canvas.height = physicalH;
71
+ if (this._gl && !this._lost) {
72
+ this._gl.viewport(0, 0, physicalW, physicalH);
73
+ }
74
+ }
75
+ clear() {
76
+ if (!this._gl || this._lost)
77
+ return;
78
+ this._gl.clear(this._gl.COLOR_BUFFER_BIT);
79
+ }
80
+ setClearColor(r, g, b, a) {
81
+ if (!this._gl || this._lost)
82
+ return;
83
+ this._gl.clearColor(r, g, b, a);
84
+ }
85
+ dispose() {
86
+ this.canvas.removeEventListener('webglcontextlost', this._handleLost);
87
+ this.canvas.removeEventListener('webglcontextrestored', this._handleRestored);
88
+ const ext = this._gl?.getExtension('WEBGL_lose_context');
89
+ ext?.loseContext();
90
+ this._gl = null;
91
+ }
92
+ _initGLState() {
93
+ const gl = this._gl;
94
+ if (!gl)
95
+ return;
96
+ gl.enable(gl.BLEND);
97
+ gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
98
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
99
+ gl.clearColor(0, 0, 0, 1);
100
+ gl.viewport(0, 0, this.canvas.width, this.canvas.height);
101
+ }
102
+ }
@@ -0,0 +1,27 @@
1
+ import type { DebugRenderItem } from './types';
2
+ export interface DebugGpuRendererOptions {
3
+ stage?: {
4
+ width: number;
5
+ height: number;
6
+ };
7
+ clearColor?: [number, number, number, number];
8
+ }
9
+ export declare class DebugGpuRenderer {
10
+ private readonly _options;
11
+ private readonly _stage;
12
+ private _glCtx;
13
+ private _renderGraph;
14
+ private _testLayer;
15
+ private _items;
16
+ private _mounted;
17
+ private _viewport;
18
+ constructor(options?: DebugGpuRendererOptions);
19
+ mount(container: HTMLElement): void;
20
+ resize(cssWidth: number, cssHeight: number, dpr?: number): void;
21
+ render(items: DebugRenderItem[]): void;
22
+ dispose(): void;
23
+ get isMounted(): boolean;
24
+ get canvas(): HTMLCanvasElement | null;
25
+ private _handleContextLost;
26
+ private _handleContextRestored;
27
+ }
@@ -0,0 +1,108 @@
1
+ import { TestLayer } from '../layers/TestLayer';
2
+ import { RenderGraph } from '../RenderGraph';
3
+ import { WebGLContext } from '../WebGLContext';
4
+ import { DEBUG_STAGE } from './types';
5
+ function createStubScene(stage) {
6
+ return {
7
+ frame: 0,
8
+ fps: 30,
9
+ stage,
10
+ videos: [],
11
+ audios: [],
12
+ texts: [],
13
+ images: [],
14
+ transitions: [],
15
+ };
16
+ }
17
+ export class DebugGpuRenderer {
18
+ constructor(options = {}) {
19
+ this._glCtx = null;
20
+ this._renderGraph = null;
21
+ this._testLayer = null;
22
+ this._items = [];
23
+ this._mounted = false;
24
+ this._viewport = { width: 0, height: 0 };
25
+ this._options = options;
26
+ this._stage = options.stage ?? { ...DEBUG_STAGE };
27
+ }
28
+ mount(container) {
29
+ if (this._mounted) {
30
+ throw new Error('DebugGpuRenderer: mount() called more than once');
31
+ }
32
+ const clearColor = this._options.clearColor ?? [0, 0, 0, 1];
33
+ this._glCtx = new WebGLContext({
34
+ onLost: () => this._handleContextLost(),
35
+ onRestore: () => this._handleContextRestored(),
36
+ });
37
+ this._glCtx.setClearColor(...clearColor);
38
+ container.appendChild(this._glCtx.canvas);
39
+ this._viewport = {
40
+ width: this._glCtx.canvas.width,
41
+ height: this._glCtx.canvas.height,
42
+ };
43
+ this._testLayer = new TestLayer();
44
+ this._renderGraph = new RenderGraph();
45
+ this._renderGraph.registerLayer(this._testLayer, () => this._items, (item) => item.id, (item) => item.zIndex);
46
+ this._mounted = true;
47
+ }
48
+ resize(cssWidth, cssHeight, dpr = 1) {
49
+ if (!this._glCtx || !this._mounted)
50
+ return;
51
+ this._glCtx.resize(cssWidth, cssHeight, dpr);
52
+ this._viewport = {
53
+ width: this._glCtx.canvas.width,
54
+ height: this._glCtx.canvas.height,
55
+ };
56
+ }
57
+ render(items) {
58
+ if (!this._mounted || !this._glCtx || !this._renderGraph)
59
+ return;
60
+ if (this._glCtx.isLost)
61
+ return;
62
+ const gl = this._glCtx.gl;
63
+ if (!gl)
64
+ return;
65
+ this._items = items;
66
+ this._glCtx.clear();
67
+ const ctx = {
68
+ gl,
69
+ stage: this._stage,
70
+ viewport: this._viewport,
71
+ fps: 30,
72
+ };
73
+ this._renderGraph.execute(createStubScene(this._stage), ctx);
74
+ }
75
+ dispose() {
76
+ const gl = this._glCtx?.gl;
77
+ if (gl && this._testLayer) {
78
+ this._testLayer.disposeGL(gl);
79
+ }
80
+ else {
81
+ this._testLayer?.dispose();
82
+ }
83
+ this._renderGraph?.dispose();
84
+ this._renderGraph = null;
85
+ this._testLayer = null;
86
+ this._glCtx?.dispose();
87
+ this._glCtx?.canvas.remove();
88
+ this._glCtx = null;
89
+ this._mounted = false;
90
+ this._items = [];
91
+ this._viewport = { width: 0, height: 0 };
92
+ }
93
+ get isMounted() {
94
+ return this._mounted;
95
+ }
96
+ get canvas() {
97
+ return this._glCtx?.canvas ?? null;
98
+ }
99
+ _handleContextLost() {
100
+ this._renderGraph?.notifyContextLost();
101
+ this._testLayer?.notifyContextLost();
102
+ }
103
+ _handleContextRestored() {
104
+ const clearColor = this._options.clearColor ?? [0, 0, 0, 1];
105
+ this._glCtx?.setClearColor(...clearColor);
106
+ this._testLayer?.notifyContextLost();
107
+ }
108
+ }
@@ -0,0 +1,17 @@
1
+ import type { DebugRenderItem } from './types';
2
+ export declare class DebugOverlay {
3
+ private readonly _root;
4
+ private readonly _fpsEl;
5
+ private readonly _stage;
6
+ private _visible;
7
+ constructor(container: HTMLElement, stage?: {
8
+ width: number;
9
+ height: number;
10
+ });
11
+ update(items: DebugRenderItem[], fps: number, stage?: {
12
+ width: number;
13
+ height: number;
14
+ }): void;
15
+ setVisible(visible: boolean): void;
16
+ dispose(): void;
17
+ }
@@ -0,0 +1,83 @@
1
+ import { DEBUG_STAGE } from './types';
2
+ export class DebugOverlay {
3
+ constructor(container, stage = DEBUG_STAGE) {
4
+ this._visible = true;
5
+ this._stage = { width: stage.width, height: stage.height };
6
+ const computed = getComputedStyle(container);
7
+ if (computed.position === 'static') {
8
+ container.style.position = 'relative';
9
+ }
10
+ this._root = document.createElement('div');
11
+ this._root.style.cssText = [
12
+ 'position:absolute',
13
+ 'inset:0',
14
+ 'pointer-events:none',
15
+ 'overflow:hidden',
16
+ ].join(';');
17
+ this._fpsEl = document.createElement('div');
18
+ this._fpsEl.style.cssText = [
19
+ 'position:absolute',
20
+ 'top:8px',
21
+ 'left:8px',
22
+ 'padding:4px 8px',
23
+ 'background:rgba(0,0,0,0.6)',
24
+ 'color:#0f0',
25
+ 'font:12px monospace',
26
+ 'border-radius:3px',
27
+ 'z-index:9999',
28
+ ].join(';');
29
+ this._fpsEl.textContent = 'FPS: --';
30
+ this._root.appendChild(this._fpsEl);
31
+ container.appendChild(this._root);
32
+ }
33
+ update(items, fps, stage) {
34
+ const stageSize = stage ?? this._stage;
35
+ if (!this._visible)
36
+ return;
37
+ this._fpsEl.textContent = `FPS: ${fps.toFixed(1)}`;
38
+ while (this._root.childNodes.length > 1) {
39
+ this._root.removeChild(this._root.lastChild);
40
+ }
41
+ const scaleX = this._root.clientWidth / stageSize.width;
42
+ const scaleY = this._root.clientHeight / stageSize.height;
43
+ for (const item of items) {
44
+ const left = item.x * scaleX;
45
+ const top = item.y * scaleY;
46
+ const width = item.width * scaleX;
47
+ const height = item.height * scaleY;
48
+ const bounds = document.createElement('div');
49
+ bounds.style.cssText = [
50
+ 'position:absolute',
51
+ `left:${left}px`,
52
+ `top:${top}px`,
53
+ `width:${width}px`,
54
+ `height:${height}px`,
55
+ 'border:1px dashed rgba(255,255,255,0.7)',
56
+ 'box-sizing:border-box',
57
+ ].join(';');
58
+ this._root.appendChild(bounds);
59
+ const label = document.createElement('div');
60
+ label.textContent = `z:${item.zIndex}`;
61
+ label.style.cssText = [
62
+ 'position:absolute',
63
+ `left:${left + width / 2}px`,
64
+ `top:${top + height / 2}px`,
65
+ 'transform:translate(-50%,-50%)',
66
+ 'padding:2px 6px',
67
+ 'background:rgba(0,0,0,0.75)',
68
+ 'color:#fff',
69
+ 'font:11px monospace',
70
+ 'border-radius:2px',
71
+ 'white-space:nowrap',
72
+ ].join(';');
73
+ this._root.appendChild(label);
74
+ }
75
+ }
76
+ setVisible(visible) {
77
+ this._visible = visible;
78
+ this._root.style.display = visible ? 'block' : 'none';
79
+ }
80
+ dispose() {
81
+ this._root.remove();
82
+ }
83
+ }
@@ -0,0 +1,38 @@
1
+ import type { DecoderState } from '../../../media/video/VideoDecoderManager';
2
+ export interface CounterSnapshot {
3
+ activeVideoFrames: number;
4
+ closedVideoFrames: number;
5
+ cacheSize: number;
6
+ decoderCount: number;
7
+ pendingDecodeRequests: number;
8
+ outstandingDecodes: number;
9
+ droppedFrames: number;
10
+ cacheHits: number;
11
+ cacheMisses: number;
12
+ cacheHitRatio: number;
13
+ avgDecodeLatencyMs: number;
14
+ avgFrameUploadMs: number;
15
+ decodeLatencySampleCount: number;
16
+ frameUploadSampleCount: number;
17
+ decoderStateTransitions: Partial<Record<DecoderState, number>>;
18
+ }
19
+ export declare const GpuDebugCounters: {
20
+ activeVideoFrames: number;
21
+ closedVideoFrames: number;
22
+ cacheSize: number;
23
+ decoderCount: number;
24
+ pendingDecodeRequests: number;
25
+ outstandingDecodes: number;
26
+ droppedFrames: number;
27
+ cacheHits: number;
28
+ cacheMisses: number;
29
+ decodeLatencyMs: number[];
30
+ frameUploadTimingsMs: number[];
31
+ decoderStateTransitions: Partial<Record<DecoderState, number>>;
32
+ reset(): void;
33
+ incDropped(): void;
34
+ recordDecoderTransition(state: DecoderState): void;
35
+ recordDecodeLatency(ms: number): void;
36
+ recordFrameUpload(ms: number): void;
37
+ snapshot(): CounterSnapshot;
38
+ };
@@ -0,0 +1,72 @@
1
+ const MAX_LATENCY_SAMPLES = 256;
2
+ export const GpuDebugCounters = {
3
+ activeVideoFrames: 0,
4
+ closedVideoFrames: 0,
5
+ cacheSize: 0,
6
+ decoderCount: 0,
7
+ pendingDecodeRequests: 0,
8
+ outstandingDecodes: 0,
9
+ droppedFrames: 0,
10
+ cacheHits: 0,
11
+ cacheMisses: 0,
12
+ decodeLatencyMs: [],
13
+ frameUploadTimingsMs: [],
14
+ decoderStateTransitions: {},
15
+ reset() {
16
+ this.activeVideoFrames = 0;
17
+ this.closedVideoFrames = 0;
18
+ this.cacheSize = 0;
19
+ this.decoderCount = 0;
20
+ this.pendingDecodeRequests = 0;
21
+ this.outstandingDecodes = 0;
22
+ this.droppedFrames = 0;
23
+ this.cacheHits = 0;
24
+ this.cacheMisses = 0;
25
+ this.decodeLatencyMs = [];
26
+ this.frameUploadTimingsMs = [];
27
+ this.decoderStateTransitions = {};
28
+ },
29
+ incDropped() {
30
+ this.droppedFrames++;
31
+ },
32
+ recordDecoderTransition(state) {
33
+ this.decoderStateTransitions[state] = (this.decoderStateTransitions[state] ?? 0) + 1;
34
+ },
35
+ recordDecodeLatency(ms) {
36
+ this.decodeLatencyMs.push(ms);
37
+ if (this.decodeLatencyMs.length > MAX_LATENCY_SAMPLES) {
38
+ this.decodeLatencyMs.shift();
39
+ }
40
+ },
41
+ recordFrameUpload(ms) {
42
+ this.frameUploadTimingsMs.push(ms);
43
+ if (this.frameUploadTimingsMs.length > MAX_LATENCY_SAMPLES) {
44
+ this.frameUploadTimingsMs.shift();
45
+ }
46
+ },
47
+ snapshot() {
48
+ const totalLookups = this.cacheHits + this.cacheMisses;
49
+ return {
50
+ activeVideoFrames: this.activeVideoFrames,
51
+ closedVideoFrames: this.closedVideoFrames,
52
+ cacheSize: this.cacheSize,
53
+ decoderCount: this.decoderCount,
54
+ pendingDecodeRequests: this.pendingDecodeRequests,
55
+ outstandingDecodes: this.outstandingDecodes,
56
+ droppedFrames: this.droppedFrames,
57
+ cacheHits: this.cacheHits,
58
+ cacheMisses: this.cacheMisses,
59
+ cacheHitRatio: totalLookups > 0 ? this.cacheHits / totalLookups : 0,
60
+ avgDecodeLatencyMs: average(this.decodeLatencyMs),
61
+ avgFrameUploadMs: average(this.frameUploadTimingsMs),
62
+ decodeLatencySampleCount: this.decodeLatencyMs.length,
63
+ frameUploadSampleCount: this.frameUploadTimingsMs.length,
64
+ decoderStateTransitions: { ...this.decoderStateTransitions },
65
+ };
66
+ },
67
+ };
68
+ function average(values) {
69
+ if (values.length === 0)
70
+ return 0;
71
+ return values.reduce((sum, v) => sum + v, 0) / values.length;
72
+ }
@@ -0,0 +1,16 @@
1
+ import type { DecoderState } from '../../../media/video/VideoDecoderManager';
2
+ import type { CounterSnapshot } from './GpuDebugCounters';
3
+ export interface GpuDebugState {
4
+ decoderStates: Record<string, DecoderState>;
5
+ cacheSizes: Record<string, number>;
6
+ textureCount: number;
7
+ activeClipIds: string[];
8
+ counters: CounterSnapshot;
9
+ }
10
+ declare global {
11
+ interface Window {
12
+ __GPU_DEBUG__?: GpuDebugState;
13
+ }
14
+ }
15
+ export declare function installGpuDebugGlobal(getState: () => GpuDebugState): void;
16
+ export declare function uninstallGpuDebugGlobal(): void;
@@ -0,0 +1,14 @@
1
+ export function installGpuDebugGlobal(getState) {
2
+ if (typeof window === 'undefined')
3
+ return;
4
+ Object.defineProperty(window, '__GPU_DEBUG__', {
5
+ configurable: true,
6
+ enumerable: true,
7
+ get: getState,
8
+ });
9
+ }
10
+ export function uninstallGpuDebugGlobal() {
11
+ if (typeof window === 'undefined')
12
+ return;
13
+ delete window.__GPU_DEBUG__;
14
+ }
@@ -0,0 +1,31 @@
1
+ export interface DebugPanelSnapshot {
2
+ fps: number;
3
+ currentFrame: number;
4
+ activeClipCount: number;
5
+ textureCount: number;
6
+ cacheHitRatio: number;
7
+ renderDurationMs: number;
8
+ decoderStates: Record<string, string>;
9
+ droppedFrames: number;
10
+ outstandingDecodes: number;
11
+ activeProviders: number;
12
+ noOpTicks: number;
13
+ }
14
+ export declare class GpuRendererDebugPanel {
15
+ private readonly _root;
16
+ private readonly _panel;
17
+ private readonly _header;
18
+ private readonly _headerTitle;
19
+ private readonly _headerMeta;
20
+ private readonly _chevron;
21
+ private readonly _content;
22
+ private readonly _getSnapshot;
23
+ private readonly _intervalId;
24
+ private _collapsed;
25
+ private _lastFps;
26
+ constructor(container: HTMLElement, getSnapshot: () => DebugPanelSnapshot);
27
+ dispose(): void;
28
+ private _toggleCollapsed;
29
+ private _updateHeaderMeta;
30
+ private _refresh;
31
+ }
@@ -0,0 +1,128 @@
1
+ const PANEL_WIDTH = 220;
2
+ const HEADER_STYLE = [
3
+ 'display:flex',
4
+ 'align-items:center',
5
+ 'justify-content:space-between',
6
+ 'gap:8px',
7
+ 'width:100%',
8
+ 'padding:6px 10px',
9
+ 'background:transparent',
10
+ 'border:none',
11
+ 'border-bottom:1px solid #1A1F2B',
12
+ 'color:#6B7280',
13
+ 'font:700 9px/1 system-ui,sans-serif',
14
+ 'letter-spacing:0.1em',
15
+ 'text-transform:uppercase',
16
+ 'cursor:pointer',
17
+ 'text-align:left',
18
+ ].join(';');
19
+ export class GpuRendererDebugPanel {
20
+ constructor(container, getSnapshot) {
21
+ this._collapsed = false;
22
+ this._lastFps = 0;
23
+ this._getSnapshot = getSnapshot;
24
+ const computed = getComputedStyle(container);
25
+ if (computed.position === 'static') {
26
+ container.style.position = 'relative';
27
+ }
28
+ this._root = document.createElement('div');
29
+ this._root.dataset.elahGpuDebug = 'true';
30
+ this._root.style.cssText = [
31
+ 'position:absolute',
32
+ 'top:8px',
33
+ 'right:8px',
34
+ 'width:' + PANEL_WIDTH + 'px',
35
+ 'pointer-events:none',
36
+ 'z-index:9999',
37
+ ].join(';');
38
+ this._panel = document.createElement('div');
39
+ this._panel.style.cssText = [
40
+ 'pointer-events:auto',
41
+ 'background:rgba(18,23,34,0.88)',
42
+ 'backdrop-filter:blur(8px)',
43
+ 'border:1px solid #232938',
44
+ 'border-radius:8px',
45
+ 'overflow:hidden',
46
+ 'box-shadow:0 8px 24px rgba(0,0,0,0.45)',
47
+ ].join(';');
48
+ this._header = document.createElement('button');
49
+ this._header.type = 'button';
50
+ this._header.style.cssText = HEADER_STYLE;
51
+ this._headerTitle = document.createElement('span');
52
+ this._headerTitle.textContent = 'GPU Monitor';
53
+ this._headerMeta = document.createElement('span');
54
+ this._headerMeta.style.cssText = [
55
+ 'font:500 9px/1 ui-monospace,monospace',
56
+ 'letter-spacing:0',
57
+ 'text-transform:none',
58
+ 'color:#22C55E',
59
+ ].join(';');
60
+ this._chevron = document.createElement('span');
61
+ this._chevron.textContent = '▾';
62
+ this._chevron.style.cssText = 'font-size:10px;opacity:0.7;flex-shrink:0';
63
+ this._header.append(this._headerTitle, this._headerMeta, this._chevron);
64
+ this._header.addEventListener('click', () => this._toggleCollapsed());
65
+ this._content = document.createElement('pre');
66
+ this._content.style.cssText = [
67
+ 'margin:0',
68
+ 'padding:8px 10px',
69
+ 'background:transparent',
70
+ 'color:#A7AFBF',
71
+ 'font:10px/1.5 ui-monospace,monospace',
72
+ 'white-space:pre',
73
+ 'max-height:min(38vh,220px)',
74
+ 'overflow:auto',
75
+ ].join(';');
76
+ this._panel.append(this._header, this._content);
77
+ this._root.appendChild(this._panel);
78
+ container.appendChild(this._root);
79
+ this._refresh();
80
+ this._intervalId = setInterval(() => this._refresh(), 100);
81
+ }
82
+ dispose() {
83
+ clearInterval(this._intervalId);
84
+ this._root.remove();
85
+ }
86
+ _toggleCollapsed() {
87
+ this._collapsed = !this._collapsed;
88
+ this._content.style.display = this._collapsed ? 'none' : 'block';
89
+ this._header.style.borderBottom = this._collapsed ? 'none' : '1px solid #1A1F2B';
90
+ this._chevron.textContent = this._collapsed ? '▸' : '▾';
91
+ this._root.dataset.elahGpuDebugCollapsed = this._collapsed ? 'true' : 'false';
92
+ this._updateHeaderMeta();
93
+ }
94
+ _updateHeaderMeta() {
95
+ if (this._collapsed) {
96
+ this._headerMeta.textContent = `${this._lastFps.toFixed(1)} FPS`;
97
+ this._headerMeta.style.display = 'inline';
98
+ }
99
+ else {
100
+ this._headerMeta.textContent = '';
101
+ this._headerMeta.style.display = 'none';
102
+ }
103
+ }
104
+ _refresh() {
105
+ const s = this._getSnapshot();
106
+ this._lastFps = s.fps;
107
+ this._updateHeaderMeta();
108
+ const decoderLines = Object.keys(s.decoderStates).length > 0
109
+ ? Object.entries(s.decoderStates)
110
+ .map(([src, state]) => ` ${src}: ${state}`)
111
+ .join('\n')
112
+ : ' (none)';
113
+ this._content.textContent = [
114
+ `${s.fps.toFixed(1)} FPS ● LIVE`,
115
+ `Frame ${s.currentFrame}`,
116
+ `Clips ${s.activeClipCount}`,
117
+ `Textures ${s.textureCount}`,
118
+ `Cache ${(s.cacheHitRatio * 100).toFixed(0)}%`,
119
+ `Render ${s.renderDurationMs.toFixed(2)}ms`,
120
+ `No-op ${s.noOpTicks}`,
121
+ `Dropped ${s.droppedFrames}`,
122
+ `Outstanding ${s.outstandingDecodes}`,
123
+ `Providers ${s.activeProviders}`,
124
+ `Decoders:\n${decoderLines}`,
125
+ 'WebGL2 hardware accelerated',
126
+ ].join('\n');
127
+ }
128
+ }