@editframe/elements 0.26.3-beta.0 → 0.26.4-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 (132) hide show
  1. package/package.json +2 -2
  2. package/scripts/build-css.js +3 -3
  3. package/tsdown.config.ts +1 -1
  4. package/src/elements/ContextProxiesController.ts +0 -124
  5. package/src/elements/CrossUpdateController.ts +0 -22
  6. package/src/elements/EFAudio.browsertest.ts +0 -706
  7. package/src/elements/EFAudio.ts +0 -56
  8. package/src/elements/EFCaptions.browsertest.ts +0 -1960
  9. package/src/elements/EFCaptions.ts +0 -823
  10. package/src/elements/EFImage.browsertest.ts +0 -120
  11. package/src/elements/EFImage.ts +0 -113
  12. package/src/elements/EFMedia/AssetIdMediaEngine.test.ts +0 -224
  13. package/src/elements/EFMedia/AssetIdMediaEngine.ts +0 -110
  14. package/src/elements/EFMedia/AssetMediaEngine.browsertest.ts +0 -140
  15. package/src/elements/EFMedia/AssetMediaEngine.ts +0 -385
  16. package/src/elements/EFMedia/BaseMediaEngine.browsertest.ts +0 -400
  17. package/src/elements/EFMedia/BaseMediaEngine.ts +0 -505
  18. package/src/elements/EFMedia/BufferedSeekingInput.browsertest.ts +0 -386
  19. package/src/elements/EFMedia/BufferedSeekingInput.ts +0 -430
  20. package/src/elements/EFMedia/JitMediaEngine.browsertest.ts +0 -226
  21. package/src/elements/EFMedia/JitMediaEngine.ts +0 -256
  22. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.browsertest.ts +0 -679
  23. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.ts +0 -117
  24. package/src/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.ts +0 -246
  25. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.browsertest.ts +0 -59
  26. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.ts +0 -27
  27. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.browsertest.ts +0 -55
  28. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.ts +0 -53
  29. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.chunkboundary.regression.browsertest.ts +0 -207
  30. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.ts +0 -72
  31. package/src/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.ts +0 -32
  32. package/src/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.ts +0 -29
  33. package/src/elements/EFMedia/audioTasks/makeAudioTasksVideoOnly.browsertest.ts +0 -95
  34. package/src/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.ts +0 -184
  35. package/src/elements/EFMedia/shared/AudioSpanUtils.ts +0 -129
  36. package/src/elements/EFMedia/shared/BufferUtils.ts +0 -342
  37. package/src/elements/EFMedia/shared/GlobalInputCache.ts +0 -77
  38. package/src/elements/EFMedia/shared/MediaTaskUtils.ts +0 -44
  39. package/src/elements/EFMedia/shared/PrecisionUtils.ts +0 -46
  40. package/src/elements/EFMedia/shared/RenditionHelpers.browsertest.ts +0 -246
  41. package/src/elements/EFMedia/shared/RenditionHelpers.ts +0 -56
  42. package/src/elements/EFMedia/shared/ThumbnailExtractor.ts +0 -227
  43. package/src/elements/EFMedia/tasks/makeMediaEngineTask.browsertest.ts +0 -167
  44. package/src/elements/EFMedia/tasks/makeMediaEngineTask.ts +0 -88
  45. package/src/elements/EFMedia/videoTasks/MainVideoInputCache.ts +0 -76
  46. package/src/elements/EFMedia/videoTasks/ScrubInputCache.ts +0 -61
  47. package/src/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.ts +0 -114
  48. package/src/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.ts +0 -35
  49. package/src/elements/EFMedia/videoTasks/makeScrubVideoInputTask.ts +0 -52
  50. package/src/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.ts +0 -124
  51. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.ts +0 -44
  52. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.ts +0 -32
  53. package/src/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.ts +0 -370
  54. package/src/elements/EFMedia/videoTasks/makeVideoBufferTask.ts +0 -109
  55. package/src/elements/EFMedia.browsertest.ts +0 -872
  56. package/src/elements/EFMedia.ts +0 -341
  57. package/src/elements/EFSourceMixin.ts +0 -60
  58. package/src/elements/EFSurface.browsertest.ts +0 -151
  59. package/src/elements/EFSurface.ts +0 -142
  60. package/src/elements/EFTemporal.browsertest.ts +0 -215
  61. package/src/elements/EFTemporal.ts +0 -800
  62. package/src/elements/EFThumbnailStrip.browsertest.ts +0 -585
  63. package/src/elements/EFThumbnailStrip.media-engine.browsertest.ts +0 -714
  64. package/src/elements/EFThumbnailStrip.ts +0 -906
  65. package/src/elements/EFTimegroup.browsertest.ts +0 -934
  66. package/src/elements/EFTimegroup.ts +0 -882
  67. package/src/elements/EFVideo.browsertest.ts +0 -1482
  68. package/src/elements/EFVideo.ts +0 -564
  69. package/src/elements/EFWaveform.ts +0 -547
  70. package/src/elements/FetchContext.browsertest.ts +0 -401
  71. package/src/elements/FetchMixin.ts +0 -38
  72. package/src/elements/SampleBuffer.ts +0 -94
  73. package/src/elements/TargetController.browsertest.ts +0 -230
  74. package/src/elements/TargetController.ts +0 -224
  75. package/src/elements/TimegroupController.ts +0 -26
  76. package/src/elements/durationConverter.ts +0 -35
  77. package/src/elements/parseTimeToMs.ts +0 -9
  78. package/src/elements/printTaskStatus.ts +0 -16
  79. package/src/elements/renderTemporalAudio.ts +0 -108
  80. package/src/elements/updateAnimations.browsertest.ts +0 -1884
  81. package/src/elements/updateAnimations.ts +0 -217
  82. package/src/elements/util.ts +0 -24
  83. package/src/gui/ContextMixin.browsertest.ts +0 -860
  84. package/src/gui/ContextMixin.ts +0 -562
  85. package/src/gui/Controllable.browsertest.ts +0 -258
  86. package/src/gui/Controllable.ts +0 -41
  87. package/src/gui/EFConfiguration.ts +0 -40
  88. package/src/gui/EFControls.browsertest.ts +0 -389
  89. package/src/gui/EFControls.ts +0 -195
  90. package/src/gui/EFDial.browsertest.ts +0 -84
  91. package/src/gui/EFDial.ts +0 -172
  92. package/src/gui/EFFilmstrip.browsertest.ts +0 -712
  93. package/src/gui/EFFilmstrip.ts +0 -1349
  94. package/src/gui/EFFitScale.ts +0 -152
  95. package/src/gui/EFFocusOverlay.ts +0 -79
  96. package/src/gui/EFPause.browsertest.ts +0 -202
  97. package/src/gui/EFPause.ts +0 -73
  98. package/src/gui/EFPlay.browsertest.ts +0 -202
  99. package/src/gui/EFPlay.ts +0 -73
  100. package/src/gui/EFPreview.ts +0 -74
  101. package/src/gui/EFResizableBox.browsertest.ts +0 -79
  102. package/src/gui/EFResizableBox.ts +0 -898
  103. package/src/gui/EFScrubber.ts +0 -151
  104. package/src/gui/EFTimeDisplay.browsertest.ts +0 -237
  105. package/src/gui/EFTimeDisplay.ts +0 -55
  106. package/src/gui/EFToggleLoop.ts +0 -35
  107. package/src/gui/EFTogglePlay.ts +0 -70
  108. package/src/gui/EFWorkbench.ts +0 -115
  109. package/src/gui/PlaybackController.ts +0 -527
  110. package/src/gui/TWMixin.css +0 -6
  111. package/src/gui/TWMixin.ts +0 -61
  112. package/src/gui/TargetOrContextMixin.ts +0 -185
  113. package/src/gui/currentTimeContext.ts +0 -5
  114. package/src/gui/durationContext.ts +0 -3
  115. package/src/gui/efContext.ts +0 -6
  116. package/src/gui/fetchContext.ts +0 -5
  117. package/src/gui/focusContext.ts +0 -7
  118. package/src/gui/focusedElementContext.ts +0 -5
  119. package/src/gui/playingContext.ts +0 -5
  120. package/src/otel/BridgeSpanExporter.ts +0 -150
  121. package/src/otel/setupBrowserTracing.ts +0 -73
  122. package/src/otel/tracingHelpers.ts +0 -251
  123. package/src/transcoding/cache/RequestDeduplicator.test.ts +0 -170
  124. package/src/transcoding/cache/RequestDeduplicator.ts +0 -65
  125. package/src/transcoding/cache/URLTokenDeduplicator.test.ts +0 -182
  126. package/src/transcoding/cache/URLTokenDeduplicator.ts +0 -101
  127. package/src/transcoding/types/index.ts +0 -312
  128. package/src/transcoding/utils/MediaUtils.ts +0 -63
  129. package/src/transcoding/utils/UrlGenerator.ts +0 -68
  130. package/src/transcoding/utils/constants.ts +0 -36
  131. package/src/utils/LRUCache.test.ts +0 -274
  132. package/src/utils/LRUCache.ts +0 -696
@@ -1,547 +0,0 @@
1
- import { CSSStyleObserver } from "@bramus/style-observer";
2
- import { Task } from "@lit/task";
3
- import { css, html, LitElement, type PropertyValueMap } from "lit";
4
- import { customElement, property, state } from "lit/decorators.js";
5
- import { createRef, type Ref, ref } from "lit/directives/ref.js";
6
- import { EF_RENDERING } from "../EF_RENDERING.js";
7
- import { TWMixin } from "../gui/TWMixin.js";
8
- import { CrossUpdateController } from "./CrossUpdateController.js";
9
- import type { EFAudio } from "./EFAudio.js";
10
- import { EFTemporal } from "./EFTemporal.js";
11
- import type { EFVideo } from "./EFVideo.js";
12
- import { TargetController } from "./TargetController.ts";
13
-
14
- @customElement("ef-waveform")
15
- export class EFWaveform extends EFTemporal(TWMixin(LitElement)) {
16
- static styles = css`
17
- :host {
18
- all: inherit;
19
- display: block;
20
- position: relative;
21
- }
22
-
23
- canvas {
24
- position: absolute;
25
- top: 0;
26
- left: 0;
27
- width: 100%;
28
- height: 100%;
29
- }
30
- `;
31
-
32
- canvasRef: Ref<HTMLCanvasElement> = createRef();
33
- private ctx: CanvasRenderingContext2D | null = null;
34
- private styleObserver: CSSStyleObserver | null = null;
35
-
36
- private resizeObserver?: ResizeObserver;
37
- private mutationObserver?: MutationObserver;
38
-
39
- render() {
40
- return html`<canvas ${ref(this.canvasRef)}></canvas>`;
41
- }
42
-
43
- @property({
44
- type: String,
45
- attribute: "mode",
46
- })
47
- mode:
48
- | "roundBars"
49
- | "bars"
50
- | "bricks"
51
- | "line"
52
- | "curve"
53
- | "pixel"
54
- | "wave"
55
- | "spikes" = "bars";
56
-
57
- @property({ type: String })
58
- color = "currentColor";
59
-
60
- @property({ type: String, reflect: true })
61
- target = "";
62
-
63
- @property({ type: Number, attribute: "bar-spacing" })
64
- barSpacing = 0.5;
65
-
66
- @state()
67
- targetElement: EFAudio | EFVideo | null = null;
68
-
69
- @property({ type: Number, attribute: "line-width" })
70
- lineWidth = 4;
71
-
72
- targetController: TargetController = new TargetController(this);
73
-
74
- connectedCallback() {
75
- super.connectedCallback();
76
- try {
77
- if (this.targetElement) {
78
- new CrossUpdateController(this.targetElement, this);
79
- }
80
- } catch (_error) {
81
- // TODO: determine if this is a critical error, or if we should just ignore it
82
- // currenty evidence suggests everything still works
83
- // no target element, no cross update controller
84
- }
85
-
86
- // Initialize ResizeObserver
87
- this.resizeObserver = new ResizeObserver(() => {
88
- this.resizeCanvas();
89
- });
90
-
91
- // Observe the host element
92
- this.resizeObserver.observe(this);
93
-
94
- // Initialize MutationObserver
95
- this.mutationObserver = new MutationObserver((mutationsList) => {
96
- for (const mutation of mutationsList) {
97
- if (mutation.type === "attributes") {
98
- this.frameTask.run();
99
- }
100
- }
101
- });
102
-
103
- // Observe attribute changes on the element
104
- this.mutationObserver.observe(this, { attributes: true });
105
-
106
- if (!EF_RENDERING()) {
107
- this.styleObserver = new CSSStyleObserver(["color"], () => {
108
- this.frameTask.run();
109
- });
110
- this.styleObserver.attach(this);
111
- }
112
- }
113
-
114
- disconnectedCallback() {
115
- super.disconnectedCallback();
116
- // Disconnect the observers when the element is removed from the DOM
117
- this.resizeObserver?.disconnect();
118
- this.mutationObserver?.disconnect();
119
- this.styleObserver?.detach();
120
- }
121
-
122
- private resizeCanvas() {
123
- this.ctx = this.initCanvas();
124
- if (this.ctx) {
125
- this.frameTask.run(); // Redraw the canvas
126
- }
127
- }
128
-
129
- protected initCanvas() {
130
- const canvas = this.canvasRef.value;
131
- if (!canvas) return null;
132
-
133
- const rect = {
134
- width: this.offsetWidth,
135
- height: this.offsetHeight,
136
- };
137
- const dpr = window.devicePixelRatio;
138
-
139
- canvas.style.width = `${rect.width}px`;
140
- canvas.style.height = `${rect.height}px`;
141
-
142
- canvas.width = rect.width * dpr;
143
- canvas.height = rect.height * dpr;
144
-
145
- const ctx = canvas.getContext("2d");
146
- if (!ctx) return null;
147
- ctx.reset();
148
-
149
- // Scale all drawing operations by dpr
150
- return ctx;
151
- }
152
-
153
- protected drawBars(ctx: CanvasRenderingContext2D, frequencyData: Uint8Array) {
154
- const canvas = ctx.canvas;
155
- const waveWidth = canvas.width;
156
- const waveHeight = canvas.height;
157
-
158
- const totalBars = frequencyData.length;
159
- const paddingInner = this.barSpacing;
160
- const paddingOuter = 0.01;
161
- const availableWidth = waveWidth;
162
- const barWidth =
163
- availableWidth / (totalBars + (totalBars - 1) * paddingInner);
164
-
165
- ctx.clearRect(0, 0, waveWidth, waveHeight);
166
- const path = new Path2D();
167
-
168
- frequencyData.forEach((value, i) => {
169
- const normalizedValue = value / 255;
170
- const barHeight = normalizedValue * waveHeight;
171
- const y = (waveHeight - barHeight) / 2;
172
- const x = waveWidth * paddingOuter + i * (barWidth * (1 + paddingInner));
173
- path.rect(x, y, barWidth, barHeight);
174
- });
175
-
176
- ctx.fill(path);
177
- }
178
-
179
- protected drawBricks(
180
- ctx: CanvasRenderingContext2D,
181
- frequencyData: Uint8Array,
182
- ) {
183
- const canvas = ctx.canvas;
184
- const waveWidth = canvas.width;
185
- const waveHeight = canvas.height;
186
- ctx.clearRect(0, 0, waveWidth, waveHeight);
187
- const path = new Path2D();
188
-
189
- const columnWidth = waveWidth / frequencyData.length;
190
- const boxSize = columnWidth * 0.9;
191
- const verticalGap = boxSize * 0.2; // Add spacing between bricks
192
- const maxBricks = Math.floor(waveHeight / (boxSize + verticalGap)); // Account for gaps in height calculation
193
-
194
- frequencyData.forEach((value, i) => {
195
- const normalizedValue = value / 255;
196
- const brickCount = Math.floor(normalizedValue * maxBricks);
197
-
198
- for (let j = 0; j < brickCount; j++) {
199
- const x = columnWidth * i;
200
- const y = waveHeight - (j + 1) * (boxSize + verticalGap); // Include gap in position calculation
201
- path.rect(x, y, boxSize, boxSize);
202
- }
203
- });
204
-
205
- ctx.fill(path);
206
- }
207
-
208
- protected drawRoundBars(
209
- ctx: CanvasRenderingContext2D,
210
- frequencyData: Uint8Array,
211
- ) {
212
- const canvas = ctx.canvas;
213
- const waveWidth = canvas.width;
214
- const waveHeight = canvas.height;
215
-
216
- // Similar padding calculation as drawBars
217
- const totalBars = frequencyData.length;
218
- const paddingInner = this.barSpacing;
219
- const paddingOuter = 0.01;
220
- const availableWidth = waveWidth;
221
- const barWidth =
222
- availableWidth / (totalBars + (totalBars - 1) * paddingInner);
223
-
224
- ctx.clearRect(0, 0, waveWidth, waveHeight);
225
-
226
- // Create a single Path2D object for all rounded bars
227
- const path = new Path2D();
228
-
229
- frequencyData.forEach((value, i) => {
230
- const normalizedValue = value / 255;
231
- const height = normalizedValue * waveHeight; // Use full wave height like in drawBars
232
- const x = waveWidth * paddingOuter + i * (barWidth * (1 + paddingInner));
233
- const y = (waveHeight - height) / 2; // Center vertically
234
-
235
- // Add rounded rectangle to path
236
- path.roundRect(x, y, barWidth, height, barWidth / 2);
237
- });
238
-
239
- // Single fill operation for all bars
240
- ctx.fill(path);
241
- }
242
-
243
- protected drawLine(ctx: CanvasRenderingContext2D, frequencyData: Uint8Array) {
244
- const canvas = ctx.canvas;
245
- const waveWidth = canvas.width;
246
- const waveHeight = canvas.height;
247
-
248
- ctx.clearRect(0, 0, waveWidth, waveHeight);
249
- const path = new Path2D();
250
-
251
- // Sample fewer points to make sharp angles more visible
252
- const sampleRate = 1; // Only use every 4th point
253
-
254
- for (let i = 0; i < frequencyData.length; i += sampleRate) {
255
- const x = (i / frequencyData.length) * waveWidth;
256
- const y = (1 - (frequencyData[i] ?? 0) / 255) * waveHeight;
257
-
258
- if (i === 0) {
259
- path.moveTo(x, y);
260
- } else {
261
- path.lineTo(x, y);
262
- }
263
- }
264
- // Ensure we draw to the end
265
- const lastX = waveWidth;
266
- const lastY =
267
- (1 - (frequencyData[frequencyData.length - 1] ?? 0) / 255) * waveHeight;
268
- path.lineTo(lastX, lastY);
269
-
270
- ctx.lineWidth = this.lineWidth;
271
- ctx.stroke(path);
272
- }
273
-
274
- protected drawCurve(
275
- ctx: CanvasRenderingContext2D,
276
- frequencyData: Uint8Array,
277
- ) {
278
- const canvas = ctx.canvas;
279
- const waveWidth = canvas.width;
280
- const waveHeight = canvas.height;
281
-
282
- ctx.clearRect(0, 0, waveWidth, waveHeight);
283
- const path = new Path2D();
284
-
285
- // Draw smooth curves between points using quadratic curves
286
- frequencyData.forEach((value, i) => {
287
- const x = (i / frequencyData.length) * waveWidth;
288
- const y = (1 - value / 255) * waveHeight;
289
-
290
- if (i === 0) {
291
- path.moveTo(x, y);
292
- } else {
293
- const prevX = ((i - 1) / frequencyData.length) * waveWidth;
294
- const prevY = (1 - (frequencyData[i - 1] ?? 0) / 255) * waveHeight;
295
- const xc = (prevX + x) / 2;
296
- const yc = (prevY + y) / 2;
297
- path.quadraticCurveTo(prevX, prevY, xc, yc);
298
- }
299
- });
300
-
301
- ctx.lineWidth = this.lineWidth;
302
- ctx.stroke(path);
303
- }
304
-
305
- protected drawPixel(
306
- ctx: CanvasRenderingContext2D,
307
- frequencyData: Uint8Array,
308
- ) {
309
- const canvas = ctx.canvas;
310
- const waveWidth = canvas.width;
311
- const waveHeight = canvas.height;
312
- const baseline = waveHeight / 2;
313
- const barWidth = waveWidth / frequencyData.length;
314
-
315
- ctx.clearRect(0, 0, waveWidth, waveHeight);
316
- const path = new Path2D();
317
-
318
- frequencyData.forEach((value, i) => {
319
- const normalizedValue = value / 255;
320
- const x = i * (waveWidth / frequencyData.length);
321
- const barHeight = normalizedValue * (waveHeight / 2); // Half height since we extend both ways
322
- const y = baseline - barHeight;
323
- path.rect(x, y, barWidth, barHeight * 2); // Double height to extend both ways
324
- });
325
-
326
- ctx.fill(path);
327
- }
328
-
329
- protected drawWave(ctx: CanvasRenderingContext2D, frequencyData: Uint8Array) {
330
- const canvas = ctx.canvas;
331
- const waveWidth = canvas.width;
332
- const waveHeight = canvas.height;
333
- const paddingOuter = 0.01;
334
- const availableWidth = waveWidth * (1 - 2 * paddingOuter);
335
- const startX = waveWidth * paddingOuter;
336
-
337
- ctx.clearRect(0, 0, waveWidth, waveHeight);
338
- const path = new Path2D();
339
-
340
- // Draw top curve
341
- const firstValue = Math.min(((frequencyData[0] ?? 0) / 255) * 2, 1);
342
- const firstY = (waveHeight - firstValue * waveHeight) / 2;
343
- path.moveTo(startX, firstY);
344
-
345
- // Draw top half
346
- frequencyData.forEach((value, i) => {
347
- const normalizedValue = Math.min((value / 255) * 2, 1);
348
- const x = startX + (i / (frequencyData.length - 1)) * availableWidth;
349
- const barHeight = normalizedValue * waveHeight;
350
- const y = (waveHeight - barHeight) / 2;
351
-
352
- if (i === 0) {
353
- path.moveTo(x, y);
354
- } else {
355
- const prevX =
356
- startX + ((i - 1) / (frequencyData.length - 1)) * availableWidth;
357
- const prevValue = Math.min(((frequencyData[i - 1] ?? 0) / 255) * 2, 1);
358
- const prevBarHeight = prevValue * waveHeight;
359
- const prevY = (waveHeight - prevBarHeight) / 2;
360
- const xc = (prevX + x) / 2;
361
- const yc = (prevY + y) / 2;
362
- path.quadraticCurveTo(prevX, prevY, xc, yc);
363
- }
364
- });
365
-
366
- // Draw bottom half
367
- for (let i = frequencyData.length - 1; i >= 0; i--) {
368
- const normalizedValue = Math.min(((frequencyData[i] ?? 0) / 255) * 2, 1);
369
- const x = startX + (i / (frequencyData.length - 1)) * availableWidth;
370
- const barHeight = normalizedValue * waveHeight;
371
- const y = (waveHeight + barHeight) / 2;
372
-
373
- if (i === frequencyData.length - 1) {
374
- path.lineTo(x, y);
375
- } else {
376
- const nextX =
377
- startX + ((i + 1) / (frequencyData.length - 1)) * availableWidth;
378
- const nextValue = Math.min(((frequencyData[i + 1] ?? 0) / 255) * 2, 1);
379
- const nextBarHeight = nextValue * waveHeight;
380
- const nextY = (waveHeight + nextBarHeight) / 2;
381
- const xc = (nextX + x) / 2;
382
- const yc = (nextY + y) / 2;
383
- path.quadraticCurveTo(nextX, nextY, xc, yc);
384
- }
385
- }
386
-
387
- // Close the path with a smooth curve back to start
388
- const lastY = (waveHeight + firstValue * waveHeight) / 2;
389
- const controlX = startX;
390
- const controlY = (lastY + firstY) / 2;
391
- path.quadraticCurveTo(controlX, controlY, startX, firstY);
392
-
393
- ctx.fill(path);
394
- }
395
-
396
- protected drawSpikes(
397
- ctx: CanvasRenderingContext2D,
398
- frequencyData: Uint8Array,
399
- ) {
400
- const canvas = ctx.canvas;
401
- const waveWidth = canvas.width;
402
- const waveHeight = canvas.height;
403
- const paddingOuter = 0.01;
404
- const availableWidth = waveWidth * (1 - 2 * paddingOuter);
405
- const startX = waveWidth * paddingOuter;
406
-
407
- ctx.clearRect(0, 0, waveWidth, waveHeight);
408
- const path = new Path2D();
409
-
410
- // Draw top curve
411
- const firstValue = (frequencyData[0] ?? 0) / 255;
412
- const firstY = (waveHeight - firstValue * waveHeight) / 2;
413
- path.moveTo(startX, firstY);
414
-
415
- // Draw top half
416
- frequencyData.forEach((value, i) => {
417
- const normalizedValue = Math.min((value / 255) * 2, 1);
418
- const x = startX + (i / (frequencyData.length - 1)) * availableWidth;
419
- const barHeight = normalizedValue * (waveHeight / 2);
420
- const y = (waveHeight - barHeight * 2) / 2;
421
-
422
- if (i === 0) {
423
- path.moveTo(x, y);
424
- } else {
425
- const prevX =
426
- startX + ((i - 1) / (frequencyData.length - 1)) * availableWidth;
427
- const prevValue = (frequencyData[i - 1] ?? 0) / 255;
428
- const prevBarHeight = prevValue * (waveHeight / 2);
429
- const prevY = (waveHeight - prevBarHeight * 2) / 2;
430
- const xc = (prevX + x) / 2;
431
- const yc = (prevY + y) / 2;
432
- path.quadraticCurveTo(prevX, prevY, xc, yc);
433
- }
434
- });
435
-
436
- // Draw bottom half
437
- for (let i = frequencyData.length - 1; i >= 0; i--) {
438
- const normalizedValue = Math.min(((frequencyData[i] ?? 0) / 255) * 2, 1);
439
- const x = startX + (i / (frequencyData.length - 1)) * availableWidth;
440
- const barHeight = normalizedValue * (waveHeight / 2);
441
- const y = (waveHeight + barHeight * 2) / 2;
442
-
443
- if (i === frequencyData.length - 1) {
444
- path.lineTo(x, y);
445
- } else {
446
- const nextX =
447
- startX + ((i + 1) / (frequencyData.length - 1)) * availableWidth;
448
- const nextValue = (frequencyData[i + 1] ?? 0) / 255;
449
- const nextBarHeight = nextValue * (waveHeight / 2);
450
- const nextY = (waveHeight + nextBarHeight * 2) / 2;
451
- const xc = (nextX + x) / 2;
452
- const yc = (nextY + y) / 2;
453
- path.quadraticCurveTo(nextX, nextY, xc, yc);
454
- }
455
- }
456
-
457
- // Close the path with a smooth curve
458
- const lastY = (waveHeight + firstValue * waveHeight) / 2;
459
- const controlX = startX;
460
- const controlY = (lastY + firstY) / 2;
461
- path.quadraticCurveTo(controlX, controlY, startX, firstY);
462
-
463
- ctx.fill(path);
464
- }
465
-
466
- frameTask = new Task(this, {
467
- autoRun: false,
468
- args: () => {
469
- return [
470
- this.targetElement,
471
- this.targetElement?.frequencyDataTask.value,
472
- ] as const;
473
- },
474
- task: async () => {
475
- if (!this.targetElement) return;
476
- await this.targetElement.frequencyDataTask.taskComplete;
477
- this.ctx ||= this.initCanvas();
478
- const ctx = this.ctx;
479
- if (!ctx) return;
480
-
481
- const frequencyData = this.targetElement.frequencyDataTask.value;
482
- const byteTimeData = this.targetElement.byteTimeDomainTask.value;
483
- if (!frequencyData || !byteTimeData) return;
484
-
485
- ctx.save();
486
- if (this.color === "currentColor") {
487
- const computedStyle = getComputedStyle(this);
488
- const currentColor = computedStyle.color;
489
- ctx.strokeStyle = currentColor;
490
- ctx.fillStyle = currentColor;
491
- } else {
492
- ctx.strokeStyle = this.color;
493
- ctx.fillStyle = this.color;
494
- }
495
-
496
- switch (this.mode) {
497
- case "bars":
498
- this.drawBars(ctx, frequencyData);
499
- break;
500
- case "bricks":
501
- this.drawBricks(ctx, frequencyData);
502
- break;
503
- case "line":
504
- this.drawLine(ctx, byteTimeData);
505
- break;
506
- case "curve":
507
- this.drawCurve(ctx, byteTimeData);
508
- break;
509
- case "pixel":
510
- this.drawPixel(ctx, frequencyData);
511
- break;
512
- case "wave":
513
- this.drawWave(ctx, frequencyData);
514
- break;
515
- case "spikes":
516
- this.drawSpikes(ctx, frequencyData);
517
- break;
518
- case "roundBars":
519
- this.drawRoundBars(ctx, frequencyData);
520
- break;
521
- }
522
-
523
- ctx.restore();
524
- },
525
- });
526
-
527
- get durationMs() {
528
- if (!this.targetElement) return 0;
529
- return this.targetElement.durationMs;
530
- }
531
-
532
- protected updated(changedProperties: PropertyValueMap<this>): void {
533
- super.updated(changedProperties);
534
-
535
- // Trigger a redraw if any property changes
536
- if (changedProperties.size > 0) {
537
- // Request a new frame
538
- this.frameTask.run();
539
- }
540
- }
541
- }
542
-
543
- declare global {
544
- interface HTMLElementTagNameMap {
545
- "ef-waveform": EFWaveform & Element;
546
- }
547
- }