@editframe/elements 0.20.4-beta.0 → 0.23.6-beta.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 (183) hide show
  1. package/dist/DelayedLoadingState.js +0 -27
  2. package/dist/EF_FRAMEGEN.d.ts +5 -3
  3. package/dist/EF_FRAMEGEN.js +49 -11
  4. package/dist/_virtual/_@oxc-project_runtime@0.94.0/helpers/decorate.js +7 -0
  5. package/dist/attachContextRoot.d.ts +1 -0
  6. package/dist/attachContextRoot.js +9 -0
  7. package/dist/elements/ContextProxiesController.d.ts +1 -2
  8. package/dist/elements/EFAudio.js +5 -9
  9. package/dist/elements/EFCaptions.d.ts +1 -3
  10. package/dist/elements/EFCaptions.js +112 -129
  11. package/dist/elements/EFImage.js +6 -7
  12. package/dist/elements/EFMedia/AssetIdMediaEngine.js +2 -5
  13. package/dist/elements/EFMedia/AssetMediaEngine.js +36 -33
  14. package/dist/elements/EFMedia/BaseMediaEngine.js +57 -73
  15. package/dist/elements/EFMedia/BufferedSeekingInput.d.ts +1 -1
  16. package/dist/elements/EFMedia/BufferedSeekingInput.js +134 -78
  17. package/dist/elements/EFMedia/JitMediaEngine.js +9 -19
  18. package/dist/elements/EFMedia/audioTasks/makeAudioBufferTask.js +7 -13
  19. package/dist/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.js +2 -3
  20. package/dist/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.js +1 -1
  21. package/dist/elements/EFMedia/audioTasks/makeAudioInputTask.js +6 -5
  22. package/dist/elements/EFMedia/audioTasks/makeAudioSeekTask.js +1 -3
  23. package/dist/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.js +1 -1
  24. package/dist/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.js +1 -1
  25. package/dist/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.js +1 -1
  26. package/dist/elements/EFMedia/shared/AudioSpanUtils.js +9 -25
  27. package/dist/elements/EFMedia/shared/BufferUtils.js +2 -17
  28. package/dist/elements/EFMedia/shared/GlobalInputCache.js +0 -24
  29. package/dist/elements/EFMedia/shared/PrecisionUtils.js +0 -21
  30. package/dist/elements/EFMedia/shared/ThumbnailExtractor.js +0 -17
  31. package/dist/elements/EFMedia/tasks/makeMediaEngineTask.js +1 -10
  32. package/dist/elements/EFMedia/videoTasks/MainVideoInputCache.d.ts +29 -0
  33. package/dist/elements/EFMedia/videoTasks/MainVideoInputCache.js +32 -0
  34. package/dist/elements/EFMedia/videoTasks/ScrubInputCache.js +1 -15
  35. package/dist/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.js +1 -7
  36. package/dist/elements/EFMedia/videoTasks/makeScrubVideoInputTask.js +8 -5
  37. package/dist/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.js +12 -13
  38. package/dist/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.js +1 -1
  39. package/dist/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.js +134 -70
  40. package/dist/elements/EFMedia/videoTasks/makeVideoBufferTask.js +11 -18
  41. package/dist/elements/EFMedia.d.ts +19 -0
  42. package/dist/elements/EFMedia.js +44 -25
  43. package/dist/elements/EFSourceMixin.js +5 -7
  44. package/dist/elements/EFSurface.js +6 -9
  45. package/dist/elements/EFTemporal.browsertest.d.ts +11 -0
  46. package/dist/elements/EFTemporal.d.ts +10 -0
  47. package/dist/elements/EFTemporal.js +100 -41
  48. package/dist/elements/EFThumbnailStrip.js +23 -73
  49. package/dist/elements/EFTimegroup.browsertest.d.ts +3 -3
  50. package/dist/elements/EFTimegroup.d.ts +35 -14
  51. package/dist/elements/EFTimegroup.js +138 -181
  52. package/dist/elements/EFVideo.d.ts +16 -2
  53. package/dist/elements/EFVideo.js +156 -108
  54. package/dist/elements/EFWaveform.js +23 -40
  55. package/dist/elements/SampleBuffer.js +3 -7
  56. package/dist/elements/TargetController.js +5 -5
  57. package/dist/elements/durationConverter.js +4 -4
  58. package/dist/elements/renderTemporalAudio.d.ts +10 -0
  59. package/dist/elements/renderTemporalAudio.js +35 -0
  60. package/dist/elements/updateAnimations.js +19 -43
  61. package/dist/gui/ContextMixin.d.ts +5 -5
  62. package/dist/gui/ContextMixin.js +167 -162
  63. package/dist/gui/Controllable.browsertest.d.ts +0 -0
  64. package/dist/gui/Controllable.d.ts +15 -0
  65. package/dist/gui/Controllable.js +9 -0
  66. package/dist/gui/EFConfiguration.js +7 -7
  67. package/dist/gui/EFControls.browsertest.d.ts +11 -0
  68. package/dist/gui/EFControls.d.ts +18 -4
  69. package/dist/gui/EFControls.js +70 -28
  70. package/dist/gui/EFDial.browsertest.d.ts +0 -0
  71. package/dist/gui/EFDial.d.ts +18 -0
  72. package/dist/gui/EFDial.js +141 -0
  73. package/dist/gui/EFFilmstrip.browsertest.d.ts +11 -0
  74. package/dist/gui/EFFilmstrip.d.ts +12 -2
  75. package/dist/gui/EFFilmstrip.js +214 -129
  76. package/dist/gui/EFFitScale.js +5 -8
  77. package/dist/gui/EFFocusOverlay.js +4 -4
  78. package/dist/gui/EFPause.browsertest.d.ts +0 -0
  79. package/dist/gui/EFPause.d.ts +23 -0
  80. package/dist/gui/EFPause.js +59 -0
  81. package/dist/gui/EFPlay.browsertest.d.ts +0 -0
  82. package/dist/gui/EFPlay.d.ts +23 -0
  83. package/dist/gui/EFPlay.js +59 -0
  84. package/dist/gui/EFPreview.d.ts +4 -0
  85. package/dist/gui/EFPreview.js +18 -9
  86. package/dist/gui/EFResizableBox.browsertest.d.ts +0 -0
  87. package/dist/gui/EFResizableBox.d.ts +34 -0
  88. package/dist/gui/EFResizableBox.js +547 -0
  89. package/dist/gui/EFScrubber.d.ts +9 -3
  90. package/dist/gui/EFScrubber.js +13 -13
  91. package/dist/gui/EFTimeDisplay.d.ts +7 -1
  92. package/dist/gui/EFTimeDisplay.js +8 -8
  93. package/dist/gui/EFToggleLoop.d.ts +9 -3
  94. package/dist/gui/EFToggleLoop.js +7 -5
  95. package/dist/gui/EFTogglePlay.d.ts +12 -4
  96. package/dist/gui/EFTogglePlay.js +26 -21
  97. package/dist/gui/EFWorkbench.js +5 -5
  98. package/dist/gui/PlaybackController.d.ts +67 -0
  99. package/dist/gui/PlaybackController.js +310 -0
  100. package/dist/gui/TWMixin.js +1 -1
  101. package/dist/gui/TWMixin2.js +1 -1
  102. package/dist/gui/TargetOrContextMixin.d.ts +10 -0
  103. package/dist/gui/TargetOrContextMixin.js +98 -0
  104. package/dist/gui/efContext.d.ts +2 -2
  105. package/dist/index.d.ts +5 -0
  106. package/dist/index.js +5 -1
  107. package/dist/otel/BridgeSpanExporter.d.ts +13 -0
  108. package/dist/otel/BridgeSpanExporter.js +87 -0
  109. package/dist/otel/setupBrowserTracing.d.ts +12 -0
  110. package/dist/otel/setupBrowserTracing.js +32 -0
  111. package/dist/otel/tracingHelpers.d.ts +34 -0
  112. package/dist/otel/tracingHelpers.js +112 -0
  113. package/dist/style.css +1 -1
  114. package/dist/transcoding/cache/RequestDeduplicator.js +0 -21
  115. package/dist/transcoding/cache/URLTokenDeduplicator.js +1 -21
  116. package/dist/transcoding/utils/UrlGenerator.js +2 -19
  117. package/dist/utils/LRUCache.js +6 -53
  118. package/package.json +13 -5
  119. package/src/elements/ContextProxiesController.ts +10 -10
  120. package/src/elements/EFAudio.ts +1 -0
  121. package/src/elements/EFCaptions.browsertest.ts +128 -56
  122. package/src/elements/EFCaptions.ts +60 -34
  123. package/src/elements/EFImage.browsertest.ts +1 -2
  124. package/src/elements/EFMedia/AssetMediaEngine.ts +65 -37
  125. package/src/elements/EFMedia/BaseMediaEngine.ts +110 -52
  126. package/src/elements/EFMedia/BufferedSeekingInput.ts +218 -101
  127. package/src/elements/EFMedia/JitMediaEngine.browsertest.ts +3 -0
  128. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.ts +7 -3
  129. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.chunkboundary.regression.browsertest.ts +1 -1
  130. package/src/elements/EFMedia/videoTasks/MainVideoInputCache.ts +76 -0
  131. package/src/elements/EFMedia/videoTasks/makeScrubVideoInputTask.ts +16 -10
  132. package/src/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.ts +7 -1
  133. package/src/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.ts +222 -116
  134. package/src/elements/EFMedia.browsertest.ts +8 -15
  135. package/src/elements/EFMedia.ts +54 -8
  136. package/src/elements/EFSurface.browsertest.ts +2 -6
  137. package/src/elements/EFSurface.ts +1 -0
  138. package/src/elements/EFTemporal.browsertest.ts +58 -1
  139. package/src/elements/EFTemporal.ts +140 -4
  140. package/src/elements/EFThumbnailStrip.browsertest.ts +2 -8
  141. package/src/elements/EFThumbnailStrip.ts +1 -0
  142. package/src/elements/EFTimegroup.browsertest.ts +16 -15
  143. package/src/elements/EFTimegroup.ts +281 -275
  144. package/src/elements/EFVideo.browsertest.ts +162 -74
  145. package/src/elements/EFVideo.ts +229 -101
  146. package/src/elements/FetchContext.browsertest.ts +7 -2
  147. package/src/elements/TargetController.browsertest.ts +1 -0
  148. package/src/elements/TargetController.ts +1 -0
  149. package/src/elements/renderTemporalAudio.ts +108 -0
  150. package/src/elements/updateAnimations.browsertest.ts +181 -6
  151. package/src/elements/updateAnimations.ts +6 -6
  152. package/src/gui/ContextMixin.browsertest.ts +274 -27
  153. package/src/gui/ContextMixin.ts +230 -175
  154. package/src/gui/Controllable.browsertest.ts +258 -0
  155. package/src/gui/Controllable.ts +41 -0
  156. package/src/gui/EFControls.browsertest.ts +294 -80
  157. package/src/gui/EFControls.ts +139 -28
  158. package/src/gui/EFDial.browsertest.ts +84 -0
  159. package/src/gui/EFDial.ts +172 -0
  160. package/src/gui/EFFilmstrip.browsertest.ts +712 -0
  161. package/src/gui/EFFilmstrip.ts +213 -23
  162. package/src/gui/EFPause.browsertest.ts +202 -0
  163. package/src/gui/EFPause.ts +73 -0
  164. package/src/gui/EFPlay.browsertest.ts +202 -0
  165. package/src/gui/EFPlay.ts +73 -0
  166. package/src/gui/EFPreview.ts +20 -5
  167. package/src/gui/EFResizableBox.browsertest.ts +79 -0
  168. package/src/gui/EFResizableBox.ts +898 -0
  169. package/src/gui/EFScrubber.ts +7 -5
  170. package/src/gui/EFTimeDisplay.browsertest.ts +19 -19
  171. package/src/gui/EFTimeDisplay.ts +3 -1
  172. package/src/gui/EFToggleLoop.ts +6 -5
  173. package/src/gui/EFTogglePlay.ts +30 -23
  174. package/src/gui/PlaybackController.ts +522 -0
  175. package/src/gui/TWMixin.css +3 -0
  176. package/src/gui/TargetOrContextMixin.ts +185 -0
  177. package/src/gui/efContext.ts +2 -2
  178. package/src/otel/BridgeSpanExporter.ts +150 -0
  179. package/src/otel/setupBrowserTracing.ts +73 -0
  180. package/src/otel/tracingHelpers.ts +251 -0
  181. package/test/cache-integration-verification.browsertest.ts +1 -1
  182. package/types.json +1 -1
  183. package/dist/elements/ContextProxiesController.js +0 -69
@@ -1,6 +1,6 @@
1
1
  import { createContext } from "@lit/context";
2
- import type { ContextMixinInterface } from "./ContextMixin.js";
2
+ import type { ControllableInterface } from "./Controllable.js";
3
3
 
4
- export const efContext = createContext<ContextMixinInterface | null>(
4
+ export const efContext = createContext<ControllableInterface | null>(
5
5
  Symbol("efContext"),
6
6
  );
@@ -0,0 +1,150 @@
1
+ import { type ExportResult, ExportResultCode } from "@opentelemetry/core";
2
+ import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
3
+
4
+ function toHex(value: unknown): string {
5
+ if (typeof value === "string") return value;
6
+ if (Array.isArray(value)) {
7
+ return value
8
+ .map((b) => {
9
+ const byte = typeof b === "number" ? b : 0;
10
+ return byte.toString(16).padStart(2, "0");
11
+ })
12
+ .join("");
13
+ }
14
+ if (ArrayBuffer.isView(value)) {
15
+ return Array.from(value as Uint8Array)
16
+ .map((b) => b.toString(16).padStart(2, "0"))
17
+ .join("");
18
+ }
19
+ return String(value);
20
+ }
21
+
22
+ interface OtlpAttributeValue {
23
+ stringValue?: string;
24
+ intValue?: number;
25
+ doubleValue?: number;
26
+ boolValue?: boolean;
27
+ arrayValue?: { values: OtlpAttributeValue[] };
28
+ }
29
+
30
+ function convertAttribute(value: unknown): OtlpAttributeValue {
31
+ if (typeof value === "string") return { stringValue: value };
32
+ if (typeof value === "number")
33
+ return Number.isInteger(value)
34
+ ? { intValue: value }
35
+ : { doubleValue: value };
36
+ if (typeof value === "boolean") return { boolValue: value };
37
+ if (Array.isArray(value))
38
+ return { arrayValue: { values: value.map(convertAttribute) } };
39
+ return { stringValue: String(value) };
40
+ }
41
+
42
+ interface BridgeWithSpanExport {
43
+ exportSpans?: (endpoint: string, payload: string) => void;
44
+ }
45
+
46
+ export class BridgeSpanExporter implements SpanExporter {
47
+ private bridge: BridgeWithSpanExport;
48
+ private endpoint: string;
49
+
50
+ constructor(bridge: BridgeWithSpanExport, endpoint: string) {
51
+ this.bridge = bridge;
52
+ this.endpoint = endpoint;
53
+ }
54
+
55
+ export(
56
+ spans: ReadableSpan[],
57
+ resultCallback: (result: ExportResult) => void,
58
+ ): void {
59
+ if (!this.bridge?.exportSpans) {
60
+ resultCallback({ code: ExportResultCode.FAILED });
61
+ return;
62
+ }
63
+
64
+ try {
65
+ const otlpPayload = {
66
+ resourceSpans: [
67
+ {
68
+ resource: {
69
+ attributes: Object.entries(
70
+ spans[0]?.resource?.attributes || {},
71
+ ).map(([key, value]) => ({
72
+ key,
73
+ value: convertAttribute(value),
74
+ })),
75
+ },
76
+ scopeSpans: [
77
+ {
78
+ scope: {
79
+ name: "telecine-browser",
80
+ version: "1.0.0",
81
+ },
82
+ spans: spans.map((span) => {
83
+ const ctx = span.spanContext();
84
+ return {
85
+ traceId: toHex(ctx.traceId),
86
+ spanId: toHex(ctx.spanId),
87
+ parentSpanId: span.parentSpanId
88
+ ? toHex(span.parentSpanId)
89
+ : undefined,
90
+ name: span.name,
91
+ kind: span.kind,
92
+ startTimeUnixNano: String(
93
+ span.startTime[0] * 1_000_000_000 + span.startTime[1],
94
+ ),
95
+ endTimeUnixNano: String(
96
+ span.endTime[0] * 1_000_000_000 + span.endTime[1],
97
+ ),
98
+ attributes: Object.entries(span.attributes).map(
99
+ ([key, value]) => ({
100
+ key,
101
+ value: convertAttribute(value),
102
+ }),
103
+ ),
104
+ status: span.status,
105
+ events: span.events.map((event) => ({
106
+ timeUnixNano: String(
107
+ event.time[0] * 1_000_000_000 + event.time[1],
108
+ ),
109
+ name: event.name,
110
+ attributes: Object.entries(event.attributes || {}).map(
111
+ ([key, value]) => ({
112
+ key,
113
+ value: convertAttribute(value),
114
+ }),
115
+ ),
116
+ })),
117
+ links: span.links.map((link) => ({
118
+ traceId: toHex(link.context.traceId),
119
+ spanId: toHex(link.context.spanId),
120
+ attributes: Object.entries(link.attributes || {}).map(
121
+ ([key, value]) => ({
122
+ key,
123
+ value: convertAttribute(value),
124
+ }),
125
+ ),
126
+ })),
127
+ };
128
+ }),
129
+ },
130
+ ],
131
+ },
132
+ ],
133
+ };
134
+
135
+ const serializedPayload = JSON.stringify(otlpPayload);
136
+
137
+ this.bridge.exportSpans(this.endpoint, serializedPayload);
138
+ resultCallback({ code: ExportResultCode.SUCCESS });
139
+ } catch (error) {
140
+ resultCallback({
141
+ code: ExportResultCode.FAILED,
142
+ error: error instanceof Error ? error : new Error(String(error)),
143
+ });
144
+ }
145
+ }
146
+
147
+ shutdown(): Promise<void> {
148
+ return Promise.resolve();
149
+ }
150
+ }
@@ -0,0 +1,73 @@
1
+ import { Resource } from "@opentelemetry/resources";
2
+ import {
3
+ BatchSpanProcessor,
4
+ SimpleSpanProcessor,
5
+ } from "@opentelemetry/sdk-trace-base";
6
+ import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
7
+ import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
8
+ import { BridgeSpanExporter } from "./BridgeSpanExporter.js";
9
+
10
+ let isInitialized = false;
11
+ let provider: WebTracerProvider | null = null;
12
+
13
+ interface BridgeWithSpanExport {
14
+ exportSpans?: (endpoint: string, payload: string) => void;
15
+ }
16
+
17
+ export interface BrowserTracingConfig {
18
+ otelEndpoint: string;
19
+ serviceName?: string;
20
+ bridge?: BridgeWithSpanExport;
21
+ useBatching?: boolean;
22
+ }
23
+
24
+ export async function setupBrowserTracing(
25
+ config: BrowserTracingConfig,
26
+ ): Promise<void> {
27
+ if (isInitialized) {
28
+ return;
29
+ }
30
+
31
+ try {
32
+ if (!config.bridge) {
33
+ throw new Error("Bridge is required for browser tracing");
34
+ }
35
+
36
+ const exporter = new BridgeSpanExporter(config.bridge, config.otelEndpoint);
37
+
38
+ let spanProcessor: BatchSpanProcessor | SimpleSpanProcessor;
39
+ if (config.useBatching) {
40
+ spanProcessor = new BatchSpanProcessor(exporter, {
41
+ maxQueueSize: 100,
42
+ maxExportBatchSize: 10,
43
+ scheduledDelayMillis: 500,
44
+ });
45
+ } else {
46
+ spanProcessor = new SimpleSpanProcessor(exporter);
47
+ }
48
+
49
+ provider = new WebTracerProvider({
50
+ resource: new Resource({
51
+ [ATTR_SERVICE_NAME]: config.serviceName || "telecine-browser",
52
+ }),
53
+ spanProcessors: [spanProcessor],
54
+ });
55
+
56
+ // Dynamically import ZoneContextManager only when tracing is enabled
57
+ // This prevents zone.js from being loaded for users who don't need tracing
58
+ const { ZoneContextManager } = await import("@opentelemetry/context-zone");
59
+
60
+ provider.register({
61
+ contextManager: new ZoneContextManager(),
62
+ });
63
+
64
+ isInitialized = true;
65
+ } catch (error) {
66
+ console.error("Failed to initialize browser tracing:", error);
67
+ throw error;
68
+ }
69
+ }
70
+
71
+ export function isBrowserTracingInitialized(): boolean {
72
+ return isInitialized;
73
+ }
@@ -0,0 +1,251 @@
1
+ import {
2
+ type Context,
3
+ context,
4
+ propagation,
5
+ type Span,
6
+ trace,
7
+ } from "@opentelemetry/api";
8
+
9
+ export type TraceContext = Record<string, string>;
10
+
11
+ /**
12
+ * Global flag to enable/disable tracing.
13
+ * When false, all tracing functions become no-ops for zero overhead.
14
+ */
15
+ let tracingEnabled = false;
16
+
17
+ /**
18
+ * Enable tracing globally. Call this during initialization if tracing is requested.
19
+ */
20
+ export function enableTracing(): void {
21
+ tracingEnabled = true;
22
+ }
23
+
24
+ /**
25
+ * Check if tracing is currently enabled.
26
+ */
27
+ export function isTracingEnabled(): boolean {
28
+ return tracingEnabled;
29
+ }
30
+
31
+ /**
32
+ * Frame-local span storage for rendering.
33
+ * Since rendering is single-threaded and sequential (one frame at a time),
34
+ * we store the active frame span directly and use it as parent for orphaned spans.
35
+ */
36
+ let currentFrameSpan: Span | undefined;
37
+
38
+ /**
39
+ * Set the current frame's span. Call this when starting a frame render.
40
+ * All spans created during this frame will use this as parent if
41
+ * Zone.js doesn't provide one via context.active()
42
+ */
43
+ export function setCurrentFrameSpan(span: Span): void {
44
+ currentFrameSpan = span;
45
+ }
46
+
47
+ /**
48
+ * Clear the current frame span. Call this when a frame completes.
49
+ */
50
+ export function clearCurrentFrameSpan(): void {
51
+ currentFrameSpan = undefined;
52
+ }
53
+
54
+ export function extractParentContext(traceContext?: TraceContext): Context {
55
+ if (!traceContext) {
56
+ return context.active();
57
+ }
58
+
59
+ try {
60
+ return propagation.extract(context.active(), traceContext);
61
+ } catch (_error) {
62
+ return context.active();
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Get the active span's context to pass to child operations
68
+ * Use this when calling functions that create child spans
69
+ */
70
+ export function getActiveContext(): Context {
71
+ return context.active();
72
+ }
73
+
74
+ /**
75
+ * Wrapper that passes span context explicitly to the function
76
+ * Use this for operations that need to store or propagate context across boundaries
77
+ */
78
+ export async function withSpanAndContext<T>(
79
+ name: string,
80
+ attributes: Record<string, string | number | boolean> | undefined,
81
+ parentContext: Context | undefined,
82
+ fn: (span: Span, activeContext: Context) => Promise<T>,
83
+ ): Promise<T> {
84
+ // No-op if tracing is disabled
85
+ if (!tracingEnabled) {
86
+ // Create a minimal no-op span for compatibility
87
+ const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
88
+ const ctx = parentContext || context.active();
89
+ const result = await fn(noopSpan, ctx);
90
+ noopSpan.end();
91
+ return result;
92
+ }
93
+
94
+ const tracer = trace.getTracer("telecine-browser");
95
+
96
+ // Same context resolution as withSpan
97
+ let ctx: Context;
98
+
99
+ if (parentContext) {
100
+ ctx = parentContext;
101
+ } else {
102
+ const activeContext = context.active();
103
+ const activeSpan = trace.getSpan(activeContext);
104
+
105
+ if (activeSpan?.isRecording?.()) {
106
+ ctx = activeContext;
107
+ } else if (currentFrameSpan) {
108
+ ctx = trace.setSpan(context.active(), currentFrameSpan);
109
+ } else {
110
+ ctx = activeContext;
111
+ }
112
+ }
113
+
114
+ const span = tracer.startSpan(
115
+ name,
116
+ {
117
+ attributes,
118
+ },
119
+ ctx,
120
+ );
121
+
122
+ // Create context with this span as active
123
+ const spanContext = trace.setSpan(ctx, span);
124
+
125
+ try {
126
+ // Pass the spanContext explicitly to the function
127
+ const result = await context.with(spanContext, async () => {
128
+ return fn(span, spanContext);
129
+ });
130
+ span.end();
131
+ return result;
132
+ } catch (error) {
133
+ span.recordException(error as Error);
134
+ span.end();
135
+ throw error;
136
+ }
137
+ }
138
+
139
+ export function createSpan(
140
+ name: string,
141
+ attributes?: Record<string, string | number | boolean>,
142
+ parentContext?: Context,
143
+ ): Span {
144
+ const tracer = trace.getTracer("telecine-browser");
145
+ const ctx = parentContext || context.active();
146
+
147
+ return context.with(ctx, () => {
148
+ const span = tracer.startSpan(name);
149
+
150
+ if (attributes) {
151
+ span.setAttributes(attributes);
152
+ }
153
+
154
+ return span;
155
+ });
156
+ }
157
+
158
+ export async function withSpan<T>(
159
+ name: string,
160
+ attributes: Record<string, string | number | boolean> | undefined,
161
+ parentContext: Context | undefined,
162
+ fn: (span: Span) => Promise<T>,
163
+ ): Promise<T> {
164
+ // No-op if tracing is disabled
165
+ if (!tracingEnabled) {
166
+ // Create a minimal no-op span for compatibility
167
+ const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
168
+ const result = await fn(noopSpan);
169
+ noopSpan.end();
170
+ return result;
171
+ }
172
+
173
+ const tracer = trace.getTracer("telecine-browser");
174
+
175
+ // Context resolution priority:
176
+ // 1. Explicit parentContext (if provided)
177
+ // 2. context.active() from Zone.js (if it has a valid span)
178
+ // 3. Create context from currentFrameSpan (fallback for Lit Task boundaries)
179
+ let ctx: Context;
180
+
181
+ if (parentContext) {
182
+ ctx = parentContext;
183
+ } else {
184
+ const activeContext = context.active();
185
+ const activeSpan = trace.getSpan(activeContext);
186
+
187
+ // Try to use context.active() if it has a real span
188
+ if (activeSpan?.isRecording?.()) {
189
+ ctx = activeContext;
190
+ } else if (currentFrameSpan) {
191
+ // Create context from the stored frame span
192
+ ctx = trace.setSpan(context.active(), currentFrameSpan);
193
+ } else {
194
+ ctx = activeContext;
195
+ }
196
+ }
197
+
198
+ // Start span with explicit parent
199
+ const span = tracer.startSpan(
200
+ name,
201
+ {
202
+ attributes,
203
+ },
204
+ ctx,
205
+ );
206
+
207
+ // Create context with this span as active
208
+ const spanContext = trace.setSpan(ctx, span);
209
+
210
+ try {
211
+ // Execute function with span context
212
+ const result = await context.with(spanContext, async () => {
213
+ return fn(span);
214
+ });
215
+ span.end();
216
+ return result;
217
+ } catch (error) {
218
+ span.recordException(error as Error);
219
+ span.end();
220
+ throw error;
221
+ }
222
+ }
223
+
224
+ export function withSpanSync<T>(
225
+ name: string,
226
+ attributes: Record<string, string | number | boolean> | undefined,
227
+ parentContext: Context | undefined,
228
+ fn: (span: Span) => T,
229
+ ): T {
230
+ // No-op if tracing is disabled
231
+ if (!tracingEnabled) {
232
+ // Create a minimal no-op span for compatibility
233
+ const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
234
+ const result = fn(noopSpan);
235
+ noopSpan.end();
236
+ return result;
237
+ }
238
+
239
+ const span = createSpan(name, attributes, parentContext);
240
+ const ctx = parentContext || context.active();
241
+
242
+ try {
243
+ const result = context.with(trace.setSpan(ctx, span), () => fn(span));
244
+ span.end();
245
+ return result;
246
+ } catch (error) {
247
+ span.recordException(error as Error);
248
+ span.end();
249
+ throw error;
250
+ }
251
+ }
@@ -22,7 +22,7 @@ const test = baseTest.extend<{
22
22
  },
23
23
  });
24
24
 
25
- test("buffer cache integration stores and serves segment data", async ({
25
+ test.skip("buffer cache integration stores and serves segment data", async ({
26
26
  element,
27
27
  expect,
28
28
  }) => {