@editframe/elements 0.6.0-beta.17 → 0.6.0-beta.19

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 (84) hide show
  1. package/package.json +2 -2
  2. package/src/elements/EFMedia.ts +1 -1
  3. package/src/elements/EFTimegroup.ts +14 -6
  4. package/src/gui/EFFilmstrip.ts +144 -30
  5. package/dist/lib/av/EncodedAsset.cjs +0 -567
  6. package/dist/lib/av/EncodedAsset.js +0 -550
  7. package/dist/lib/av/MP4File.cjs +0 -182
  8. package/dist/lib/av/MP4File.js +0 -165
  9. package/dist/lib/av/msToTimeCode.cjs +0 -15
  10. package/dist/lib/av/msToTimeCode.js +0 -15
  11. package/dist/lib/util/awaitMicrotask.cjs +0 -4
  12. package/dist/lib/util/awaitMicrotask.js +0 -4
  13. package/dist/lib/util/memoize.cjs +0 -14
  14. package/dist/lib/util/memoize.js +0 -14
  15. package/dist/packages/elements/src/EF_FRAMEGEN.cjs +0 -200
  16. package/dist/packages/elements/src/EF_FRAMEGEN.d.ts +0 -45
  17. package/dist/packages/elements/src/EF_FRAMEGEN.js +0 -200
  18. package/dist/packages/elements/src/EF_INTERACTIVE.cjs +0 -4
  19. package/dist/packages/elements/src/EF_INTERACTIVE.d.ts +0 -1
  20. package/dist/packages/elements/src/EF_INTERACTIVE.js +0 -4
  21. package/dist/packages/elements/src/elements/CrossUpdateController.cjs +0 -16
  22. package/dist/packages/elements/src/elements/CrossUpdateController.d.ts +0 -9
  23. package/dist/packages/elements/src/elements/CrossUpdateController.js +0 -16
  24. package/dist/packages/elements/src/elements/EFAudio.cjs +0 -53
  25. package/dist/packages/elements/src/elements/EFAudio.d.ts +0 -10
  26. package/dist/packages/elements/src/elements/EFAudio.js +0 -54
  27. package/dist/packages/elements/src/elements/EFCaptions.cjs +0 -164
  28. package/dist/packages/elements/src/elements/EFCaptions.d.ts +0 -38
  29. package/dist/packages/elements/src/elements/EFCaptions.js +0 -166
  30. package/dist/packages/elements/src/elements/EFImage.cjs +0 -79
  31. package/dist/packages/elements/src/elements/EFImage.d.ts +0 -14
  32. package/dist/packages/elements/src/elements/EFImage.js +0 -80
  33. package/dist/packages/elements/src/elements/EFMedia.cjs +0 -334
  34. package/dist/packages/elements/src/elements/EFMedia.d.ts +0 -61
  35. package/dist/packages/elements/src/elements/EFMedia.js +0 -334
  36. package/dist/packages/elements/src/elements/EFSourceMixin.cjs +0 -55
  37. package/dist/packages/elements/src/elements/EFSourceMixin.d.ts +0 -12
  38. package/dist/packages/elements/src/elements/EFSourceMixin.js +0 -55
  39. package/dist/packages/elements/src/elements/EFTemporal.cjs +0 -198
  40. package/dist/packages/elements/src/elements/EFTemporal.d.ts +0 -36
  41. package/dist/packages/elements/src/elements/EFTemporal.js +0 -198
  42. package/dist/packages/elements/src/elements/EFTimegroup.browsertest.d.ts +0 -12
  43. package/dist/packages/elements/src/elements/EFTimegroup.cjs +0 -343
  44. package/dist/packages/elements/src/elements/EFTimegroup.d.ts +0 -39
  45. package/dist/packages/elements/src/elements/EFTimegroup.js +0 -344
  46. package/dist/packages/elements/src/elements/EFTimeline.cjs +0 -15
  47. package/dist/packages/elements/src/elements/EFTimeline.d.ts +0 -3
  48. package/dist/packages/elements/src/elements/EFTimeline.js +0 -15
  49. package/dist/packages/elements/src/elements/EFVideo.cjs +0 -109
  50. package/dist/packages/elements/src/elements/EFVideo.d.ts +0 -14
  51. package/dist/packages/elements/src/elements/EFVideo.js +0 -110
  52. package/dist/packages/elements/src/elements/EFWaveform.cjs +0 -235
  53. package/dist/packages/elements/src/elements/EFWaveform.d.ts +0 -28
  54. package/dist/packages/elements/src/elements/EFWaveform.js +0 -219
  55. package/dist/packages/elements/src/elements/FetchMixin.cjs +0 -28
  56. package/dist/packages/elements/src/elements/FetchMixin.d.ts +0 -8
  57. package/dist/packages/elements/src/elements/FetchMixin.js +0 -28
  58. package/dist/packages/elements/src/elements/TimegroupController.cjs +0 -20
  59. package/dist/packages/elements/src/elements/TimegroupController.d.ts +0 -14
  60. package/dist/packages/elements/src/elements/TimegroupController.js +0 -20
  61. package/dist/packages/elements/src/elements/durationConverter.cjs +0 -8
  62. package/dist/packages/elements/src/elements/durationConverter.d.ts +0 -4
  63. package/dist/packages/elements/src/elements/durationConverter.js +0 -8
  64. package/dist/packages/elements/src/elements/parseTimeToMs.cjs +0 -12
  65. package/dist/packages/elements/src/elements/parseTimeToMs.d.ts +0 -1
  66. package/dist/packages/elements/src/elements/parseTimeToMs.js +0 -12
  67. package/dist/packages/elements/src/elements/util.cjs +0 -11
  68. package/dist/packages/elements/src/elements/util.d.ts +0 -4
  69. package/dist/packages/elements/src/elements/util.js +0 -11
  70. package/dist/packages/elements/src/gui/EFFilmstrip.cjs +0 -719
  71. package/dist/packages/elements/src/gui/EFFilmstrip.d.ts +0 -143
  72. package/dist/packages/elements/src/gui/EFFilmstrip.js +0 -727
  73. package/dist/packages/elements/src/gui/EFWorkbench.cjs +0 -213
  74. package/dist/packages/elements/src/gui/EFWorkbench.d.ts +0 -45
  75. package/dist/packages/elements/src/gui/EFWorkbench.js +0 -214
  76. package/dist/packages/elements/src/gui/TWMixin.cjs +0 -28
  77. package/dist/packages/elements/src/gui/TWMixin.css.cjs +0 -3
  78. package/dist/packages/elements/src/gui/TWMixin.css.js +0 -4
  79. package/dist/packages/elements/src/gui/TWMixin.d.ts +0 -3
  80. package/dist/packages/elements/src/gui/TWMixin.js +0 -28
  81. package/dist/packages/elements/src/index.cjs +0 -47
  82. package/dist/packages/elements/src/index.d.ts +0 -10
  83. package/dist/packages/elements/src/index.js +0 -23
  84. package/dist/style.css +0 -769
@@ -1,235 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const EFAudio = require("./EFAudio.cjs");
4
- const lit = require("lit");
5
- const decorators_js = require("lit/decorators.js");
6
- const EFVideo = require("./EFVideo.cjs");
7
- const EFTemporal = require("./EFTemporal.cjs");
8
- const CrossUpdateController = require("./CrossUpdateController.cjs");
9
- const TWMixin = require("../gui/TWMixin.cjs");
10
- const task = require("@lit/task");
11
- const d3 = require("d3");
12
- const ref_js = require("lit/directives/ref.js");
13
- const EF_INTERACTIVE = require("../EF_INTERACTIVE.cjs");
14
- function _interopNamespaceDefault(e) {
15
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
16
- if (e) {
17
- for (const k in e) {
18
- if (k !== "default") {
19
- const d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: () => e[k]
23
- });
24
- }
25
- }
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
- const d3__namespace = /* @__PURE__ */ _interopNamespaceDefault(d3);
31
- var __defProp = Object.defineProperty;
32
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
33
- var __decorateClass = (decorators, target, key, kind) => {
34
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
35
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
36
- if (decorator = decorators[i])
37
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
38
- if (kind && result) __defProp(target, key, result);
39
- return result;
40
- };
41
- exports.EFWaveform = class EFWaveform extends EFTemporal.EFTemporal(TWMixin.TWMixin(lit.LitElement)) {
42
- constructor() {
43
- super(...arguments);
44
- this.svgRef = ref_js.createRef();
45
- this.mode = "bars";
46
- this.color = "currentColor";
47
- this.frameTask = new task.Task(this, {
48
- autoRun: EF_INTERACTIVE.EF_INTERACTIVE,
49
- args: () => [this.target.audioBufferTask.status],
50
- task: async () => {
51
- await this.target.audioBufferTask.taskComplete;
52
- }
53
- });
54
- }
55
- createRenderRoot() {
56
- return this;
57
- }
58
- render() {
59
- return lit.html` <svg ${ref_js.ref(this.svgRef)} class="h-full w-full" store></svg> `;
60
- }
61
- connectedCallback() {
62
- super.connectedCallback();
63
- if (this.target) {
64
- new CrossUpdateController.CrossUpdateController(this.target, this);
65
- }
66
- }
67
- drawBars(svg, frequencyData) {
68
- const waveWidth = svg.clientWidth * devicePixelRatio;
69
- const waveHeight = svg.clientHeight;
70
- const waveLeft = 0;
71
- const waveRight = waveWidth;
72
- const barX = d3__namespace.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3__namespace.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
73
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
74
- const baseline = waveHeight / 2;
75
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
76
- const minBarHeight = 2;
77
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth() / 1.2).attr("height", (value) => Math.max(height(value) * 2, minBarHeight));
78
- bars.exit().remove();
79
- }
80
- drawBricks(svg, frequencyData) {
81
- const waveWidth = svg.clientWidth * devicePixelRatio;
82
- const waveHeight = svg.clientHeight * devicePixelRatio;
83
- const brickWidth = waveWidth / frequencyData.length;
84
- const brickHeightFactor = waveHeight / 255 / 2;
85
- const brickPadding = 2;
86
- const midHeight = waveHeight / 2;
87
- d3__namespace.select(svg).selectAll("line.brickBaseLine").data([0]).join("line").attr("class", "brickBaseLine").attr("x1", 0).attr("x2", waveWidth).attr("y1", midHeight).attr("y2", midHeight).attr("stroke", "currentColor").attr("stroke-width", 4).attr("stroke-dasharray", "2");
88
- d3__namespace.select(svg).selectAll("rect.brick").data(frequencyData).join("rect").attr("class", "brick").attr("x", (_d, i) => i * brickWidth).attr("y", (d) => midHeight - d * brickHeightFactor).attr("width", brickWidth - brickPadding).attr("height", (d) => d * brickHeightFactor * 2);
89
- }
90
- drawLine(svg, frequencyData) {
91
- const waveWidth = svg.clientWidth * devicePixelRatio;
92
- const waveHeight = svg.clientHeight * devicePixelRatio;
93
- const xScale = d3__namespace.scaleLinear().domain([0, frequencyData.length - 1]).range([0, waveWidth]);
94
- const yScale = d3__namespace.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
95
- const lineGenerator = d3__namespace.line().x((_, i) => xScale(i)).y((d) => yScale(d));
96
- const pathData = lineGenerator(frequencyData);
97
- d3__namespace.select(svg).selectAll("path.line").data([frequencyData]).join("path").attr("class", "line").attr("d", pathData).attr("fill", "none").attr("stroke", "currentColor").attr("stroke-width", 4);
98
- }
99
- drawRoundBars(svg, frequencyData) {
100
- const waveWidth = svg.clientWidth * devicePixelRatio;
101
- const waveHeight = svg.clientHeight;
102
- const waveLeft = 0;
103
- const waveRight = waveWidth;
104
- const barX = d3__namespace.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3__namespace.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
105
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
106
- const baseline = waveHeight / 2;
107
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
108
- const minBarHeight = 2;
109
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth() / 1.2).attr("height", (value) => Math.max(height(value) * 2, minBarHeight)).attr("rx", barX.bandwidth()).attr("ry", barX.bandwidth());
110
- bars.exit().remove();
111
- }
112
- drawEqualizer(svg, frequencyData) {
113
- const waveWidth = svg.clientWidth * devicePixelRatio;
114
- const waveHeight = svg.clientHeight * devicePixelRatio;
115
- const barWidth = waveWidth / frequencyData.length;
116
- const barPadding = 1;
117
- const minHeight = 1;
118
- const heightScale = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
119
- d3__namespace.select(svg).selectAll("line.equalizerBaseLine").data([0]).join("line").attr("class", "equalizerBaseLine").attr("x1", 0).attr("x2", waveWidth).attr("y1", waveHeight / 2).attr("y2", waveHeight / 2).attr("stroke-width", 2);
120
- d3__namespace.select(svg).selectAll("rect.equalizerBar").data(frequencyData).join("rect").attr("class", "equalizerBar").attr("x", (_d, i) => i * barWidth + barPadding / 2).attr(
121
- "y",
122
- (d) => waveHeight / 2 - Math.max(heightScale(d) / 2, minHeight)
123
- ).attr("width", barWidth - barPadding).attr("height", (d) => Math.max(heightScale(d), minHeight));
124
- d3__namespace.select(svg).selectAll("rect.equalizerBar").transition().duration(100).attr(
125
- "y",
126
- (d) => waveHeight / 2 - Math.max(heightScale(Number(d)) / 2, minHeight)
127
- ).attr("height", (d) => Math.max(heightScale(Number(d)), minHeight));
128
- }
129
- drawCurve(svg, frequencyData) {
130
- const waveWidth = svg.clientWidth * devicePixelRatio;
131
- const waveHeight = svg.clientHeight * devicePixelRatio;
132
- const xScale = d3__namespace.scaleLinear().domain([0, frequencyData.length]).range([0, waveWidth]);
133
- const yScale = d3__namespace.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
134
- const curveGenerator = d3__namespace.line().x((_, i) => xScale(i)).y((d) => yScale(d)).curve(d3__namespace.curveNatural);
135
- const pathData = curveGenerator(frequencyData);
136
- d3__namespace.select(svg).selectAll("path.curve").data([frequencyData]).join("path").attr("class", "curve").attr("d", pathData).attr("fill", "none").attr("stroke", "currentColor").attr("stroke-width", 4);
137
- }
138
- drawPixel(svg, frequencyData) {
139
- const waveWidth = svg.clientWidth * devicePixelRatio;
140
- const waveHeight = svg.clientHeight;
141
- const baseline = waveHeight / 2;
142
- const barX = d3__namespace.scaleBand().domain(d3__namespace.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
143
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, baseline]);
144
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
145
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth()).attr("height", (value) => height(value) * 2);
146
- bars.exit().remove();
147
- }
148
- drawWave(svg, frequencyData) {
149
- const waveWidth = svg.clientWidth * devicePixelRatio;
150
- const waveHeight = svg.clientHeight;
151
- const barX = d3__namespace.scaleBand().domain(d3__namespace.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
152
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
153
- d3__namespace.select(svg).selectAll("line.baseline").data([0]).join("line").attr("class", "baseline").attr("x1", (_, i) => barX(String(i)) || 0).attr("x2", waveWidth).attr("y1", waveHeight / 2).attr("y2", waveHeight / 2).attr("stroke", "currentColor").attr("stroke-width", 2);
154
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
155
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => waveHeight / 2 - height(value)).attr("width", barX.bandwidth()).attr("height", (value) => height(value) * 2);
156
- bars.exit().remove();
157
- }
158
- async updated() {
159
- const svg = this.svgRef.value;
160
- if (!svg) {
161
- return;
162
- }
163
- if (!this.target.audioBufferTask.value) {
164
- return;
165
- }
166
- if (this.target.ownCurrentTimeMs > 0) {
167
- const audioContext = new OfflineAudioContext(2, 48e3 / 25, 48e3);
168
- const audioBufferSource = audioContext.createBufferSource();
169
- audioBufferSource.buffer = this.target.audioBufferTask.value.buffer;
170
- const analyser = audioContext.createAnalyser();
171
- analyser.fftSize = 256;
172
- audioBufferSource.connect(analyser);
173
- audioBufferSource.start(
174
- 0,
175
- Math.max(
176
- 0,
177
- (this.target.ownCurrentTimeMs - this.target.audioBufferTask.value.startOffsetMs) / 1e3
178
- ),
179
- 48e3 / 1e3
180
- );
181
- await audioContext.startRendering();
182
- const frequencyData = new Uint8Array(analyser.frequencyBinCount);
183
- analyser.getByteFrequencyData(frequencyData);
184
- const rect = this.getBoundingClientRect();
185
- svg.setAttribute("width", (rect.width * devicePixelRatio).toString());
186
- svg.setAttribute("height", (rect.height * devicePixelRatio).toString());
187
- switch (this.mode) {
188
- case "bars":
189
- this.drawBars(svg, frequencyData);
190
- break;
191
- case "bricks":
192
- this.drawBricks(svg, frequencyData);
193
- break;
194
- case "curve":
195
- this.drawCurve(svg, frequencyData);
196
- break;
197
- case "line":
198
- this.drawLine(svg, frequencyData);
199
- break;
200
- case "pixel":
201
- this.drawPixel(svg, frequencyData);
202
- break;
203
- case "wave":
204
- this.drawWave(svg, frequencyData);
205
- break;
206
- case "roundBars":
207
- this.drawRoundBars(svg, frequencyData);
208
- break;
209
- case "equalizer":
210
- this.drawEqualizer(svg, frequencyData);
211
- break;
212
- }
213
- }
214
- }
215
- get target() {
216
- const target = document.querySelector(this.getAttribute("target") ?? "");
217
- if (target instanceof EFAudio.EFAudio || target instanceof EFVideo.EFVideo) {
218
- return target;
219
- }
220
- throw new Error("Invalid target, must be an EFAudio element");
221
- }
222
- };
223
- exports.EFWaveform.styles = [];
224
- __decorateClass([
225
- decorators_js.property({
226
- type: String,
227
- attribute: "mode"
228
- })
229
- ], exports.EFWaveform.prototype, "mode", 2);
230
- __decorateClass([
231
- decorators_js.property({ type: String })
232
- ], exports.EFWaveform.prototype, "color", 2);
233
- exports.EFWaveform = __decorateClass([
234
- decorators_js.customElement("ef-waveform")
235
- ], exports.EFWaveform);
@@ -1,28 +0,0 @@
1
- import { EFAudio } from './EFAudio';
2
- import { LitElement } from 'lit';
3
- import { EFVideo } from './EFVideo';
4
- import { Task } from '@lit/task';
5
- import { Ref } from 'lit/directives/ref.js';
6
-
7
- declare const EFWaveform_base: (new (...args: any[]) => import('./EFTemporal').TemporalMixinInterface) & typeof LitElement;
8
- export declare class EFWaveform extends EFWaveform_base {
9
- static styles: never[];
10
- svgRef: Ref<SVGElement>;
11
- createRenderRoot(): this;
12
- render(): import('lit-html').TemplateResult<1>;
13
- mode: "roundBars" | "bars" | "bricks" | "equalizer" | "curve" | "line" | "pixel" | "wave";
14
- color: string;
15
- connectedCallback(): void;
16
- protected drawBars(svg: SVGElement, frequencyData: Uint8Array): void;
17
- protected drawBricks(svg: SVGElement, frequencyData: Uint8Array): void;
18
- protected drawLine(svg: SVGElement, frequencyData: Uint8Array): void;
19
- protected drawRoundBars(svg: SVGElement, frequencyData: Uint8Array): void;
20
- protected drawEqualizer(svg: SVGElement, frequencyData: Uint8Array): void;
21
- protected drawCurve(svg: SVGElement, frequencyData: Uint8Array): void;
22
- protected drawPixel(svg: SVGElement, frequencyData: Uint8Array): void;
23
- protected drawWave(svg: SVGElement, frequencyData: Uint8Array): void;
24
- frameTask: Task<readonly [import('@lit/task').TaskStatus], void>;
25
- protected updated(): Promise<void>;
26
- get target(): EFAudio | EFVideo;
27
- }
28
- export {};
@@ -1,219 +0,0 @@
1
- import { EFAudio } from "./EFAudio.js";
2
- import { html, LitElement } from "lit";
3
- import { property, customElement } from "lit/decorators.js";
4
- import { EFVideo } from "./EFVideo.js";
5
- import { EFTemporal } from "./EFTemporal.js";
6
- import { CrossUpdateController } from "./CrossUpdateController.js";
7
- import { TWMixin } from "../gui/TWMixin.js";
8
- import { Task } from "@lit/task";
9
- import * as d3 from "d3";
10
- import { createRef, ref } from "lit/directives/ref.js";
11
- import { EF_INTERACTIVE } from "../EF_INTERACTIVE.js";
12
- var __defProp = Object.defineProperty;
13
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
- var __decorateClass = (decorators, target, key, kind) => {
15
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
16
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
17
- if (decorator = decorators[i])
18
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19
- if (kind && result) __defProp(target, key, result);
20
- return result;
21
- };
22
- let EFWaveform = class extends EFTemporal(TWMixin(LitElement)) {
23
- constructor() {
24
- super(...arguments);
25
- this.svgRef = createRef();
26
- this.mode = "bars";
27
- this.color = "currentColor";
28
- this.frameTask = new Task(this, {
29
- autoRun: EF_INTERACTIVE,
30
- args: () => [this.target.audioBufferTask.status],
31
- task: async () => {
32
- await this.target.audioBufferTask.taskComplete;
33
- }
34
- });
35
- }
36
- createRenderRoot() {
37
- return this;
38
- }
39
- render() {
40
- return html` <svg ${ref(this.svgRef)} class="h-full w-full" store></svg> `;
41
- }
42
- connectedCallback() {
43
- super.connectedCallback();
44
- if (this.target) {
45
- new CrossUpdateController(this.target, this);
46
- }
47
- }
48
- drawBars(svg, frequencyData) {
49
- const waveWidth = svg.clientWidth * devicePixelRatio;
50
- const waveHeight = svg.clientHeight;
51
- const waveLeft = 0;
52
- const waveRight = waveWidth;
53
- const barX = d3.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
54
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
55
- const baseline = waveHeight / 2;
56
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
57
- const minBarHeight = 2;
58
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth() / 1.2).attr("height", (value) => Math.max(height(value) * 2, minBarHeight));
59
- bars.exit().remove();
60
- }
61
- drawBricks(svg, frequencyData) {
62
- const waveWidth = svg.clientWidth * devicePixelRatio;
63
- const waveHeight = svg.clientHeight * devicePixelRatio;
64
- const brickWidth = waveWidth / frequencyData.length;
65
- const brickHeightFactor = waveHeight / 255 / 2;
66
- const brickPadding = 2;
67
- const midHeight = waveHeight / 2;
68
- d3.select(svg).selectAll("line.brickBaseLine").data([0]).join("line").attr("class", "brickBaseLine").attr("x1", 0).attr("x2", waveWidth).attr("y1", midHeight).attr("y2", midHeight).attr("stroke", "currentColor").attr("stroke-width", 4).attr("stroke-dasharray", "2");
69
- d3.select(svg).selectAll("rect.brick").data(frequencyData).join("rect").attr("class", "brick").attr("x", (_d, i) => i * brickWidth).attr("y", (d) => midHeight - d * brickHeightFactor).attr("width", brickWidth - brickPadding).attr("height", (d) => d * brickHeightFactor * 2);
70
- }
71
- drawLine(svg, frequencyData) {
72
- const waveWidth = svg.clientWidth * devicePixelRatio;
73
- const waveHeight = svg.clientHeight * devicePixelRatio;
74
- const xScale = d3.scaleLinear().domain([0, frequencyData.length - 1]).range([0, waveWidth]);
75
- const yScale = d3.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
76
- const lineGenerator = d3.line().x((_, i) => xScale(i)).y((d) => yScale(d));
77
- const pathData = lineGenerator(frequencyData);
78
- d3.select(svg).selectAll("path.line").data([frequencyData]).join("path").attr("class", "line").attr("d", pathData).attr("fill", "none").attr("stroke", "currentColor").attr("stroke-width", 4);
79
- }
80
- drawRoundBars(svg, frequencyData) {
81
- const waveWidth = svg.clientWidth * devicePixelRatio;
82
- const waveHeight = svg.clientHeight;
83
- const waveLeft = 0;
84
- const waveRight = waveWidth;
85
- const barX = d3.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
86
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
87
- const baseline = waveHeight / 2;
88
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
89
- const minBarHeight = 2;
90
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth() / 1.2).attr("height", (value) => Math.max(height(value) * 2, minBarHeight)).attr("rx", barX.bandwidth()).attr("ry", barX.bandwidth());
91
- bars.exit().remove();
92
- }
93
- drawEqualizer(svg, frequencyData) {
94
- const waveWidth = svg.clientWidth * devicePixelRatio;
95
- const waveHeight = svg.clientHeight * devicePixelRatio;
96
- const barWidth = waveWidth / frequencyData.length;
97
- const barPadding = 1;
98
- const minHeight = 1;
99
- const heightScale = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
100
- d3.select(svg).selectAll("line.equalizerBaseLine").data([0]).join("line").attr("class", "equalizerBaseLine").attr("x1", 0).attr("x2", waveWidth).attr("y1", waveHeight / 2).attr("y2", waveHeight / 2).attr("stroke-width", 2);
101
- d3.select(svg).selectAll("rect.equalizerBar").data(frequencyData).join("rect").attr("class", "equalizerBar").attr("x", (_d, i) => i * barWidth + barPadding / 2).attr(
102
- "y",
103
- (d) => waveHeight / 2 - Math.max(heightScale(d) / 2, minHeight)
104
- ).attr("width", barWidth - barPadding).attr("height", (d) => Math.max(heightScale(d), minHeight));
105
- d3.select(svg).selectAll("rect.equalizerBar").transition().duration(100).attr(
106
- "y",
107
- (d) => waveHeight / 2 - Math.max(heightScale(Number(d)) / 2, minHeight)
108
- ).attr("height", (d) => Math.max(heightScale(Number(d)), minHeight));
109
- }
110
- drawCurve(svg, frequencyData) {
111
- const waveWidth = svg.clientWidth * devicePixelRatio;
112
- const waveHeight = svg.clientHeight * devicePixelRatio;
113
- const xScale = d3.scaleLinear().domain([0, frequencyData.length]).range([0, waveWidth]);
114
- const yScale = d3.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
115
- const curveGenerator = d3.line().x((_, i) => xScale(i)).y((d) => yScale(d)).curve(d3.curveNatural);
116
- const pathData = curveGenerator(frequencyData);
117
- d3.select(svg).selectAll("path.curve").data([frequencyData]).join("path").attr("class", "curve").attr("d", pathData).attr("fill", "none").attr("stroke", "currentColor").attr("stroke-width", 4);
118
- }
119
- drawPixel(svg, frequencyData) {
120
- const waveWidth = svg.clientWidth * devicePixelRatio;
121
- const waveHeight = svg.clientHeight;
122
- const baseline = waveHeight / 2;
123
- const barX = d3.scaleBand().domain(d3.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
124
- const height = d3.scaleLinear().domain([0, 255]).range([0, baseline]);
125
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
126
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => baseline - height(value)).attr("width", barX.bandwidth()).attr("height", (value) => height(value) * 2);
127
- bars.exit().remove();
128
- }
129
- drawWave(svg, frequencyData) {
130
- const waveWidth = svg.clientWidth * devicePixelRatio;
131
- const waveHeight = svg.clientHeight;
132
- const barX = d3.scaleBand().domain(d3.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
133
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
134
- d3.select(svg).selectAll("line.baseline").data([0]).join("line").attr("class", "baseline").attr("x1", (_, i) => barX(String(i)) || 0).attr("x2", waveWidth).attr("y1", waveHeight / 2).attr("y2", waveHeight / 2).attr("stroke", "currentColor").attr("stroke-width", 2);
135
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
136
- bars.enter().append("rect").merge(bars).attr("x", (_, i) => barX(String(i)) || 0).attr("y", (value) => waveHeight / 2 - height(value)).attr("width", barX.bandwidth()).attr("height", (value) => height(value) * 2);
137
- bars.exit().remove();
138
- }
139
- async updated() {
140
- const svg = this.svgRef.value;
141
- if (!svg) {
142
- return;
143
- }
144
- if (!this.target.audioBufferTask.value) {
145
- return;
146
- }
147
- if (this.target.ownCurrentTimeMs > 0) {
148
- const audioContext = new OfflineAudioContext(2, 48e3 / 25, 48e3);
149
- const audioBufferSource = audioContext.createBufferSource();
150
- audioBufferSource.buffer = this.target.audioBufferTask.value.buffer;
151
- const analyser = audioContext.createAnalyser();
152
- analyser.fftSize = 256;
153
- audioBufferSource.connect(analyser);
154
- audioBufferSource.start(
155
- 0,
156
- Math.max(
157
- 0,
158
- (this.target.ownCurrentTimeMs - this.target.audioBufferTask.value.startOffsetMs) / 1e3
159
- ),
160
- 48e3 / 1e3
161
- );
162
- await audioContext.startRendering();
163
- const frequencyData = new Uint8Array(analyser.frequencyBinCount);
164
- analyser.getByteFrequencyData(frequencyData);
165
- const rect = this.getBoundingClientRect();
166
- svg.setAttribute("width", (rect.width * devicePixelRatio).toString());
167
- svg.setAttribute("height", (rect.height * devicePixelRatio).toString());
168
- switch (this.mode) {
169
- case "bars":
170
- this.drawBars(svg, frequencyData);
171
- break;
172
- case "bricks":
173
- this.drawBricks(svg, frequencyData);
174
- break;
175
- case "curve":
176
- this.drawCurve(svg, frequencyData);
177
- break;
178
- case "line":
179
- this.drawLine(svg, frequencyData);
180
- break;
181
- case "pixel":
182
- this.drawPixel(svg, frequencyData);
183
- break;
184
- case "wave":
185
- this.drawWave(svg, frequencyData);
186
- break;
187
- case "roundBars":
188
- this.drawRoundBars(svg, frequencyData);
189
- break;
190
- case "equalizer":
191
- this.drawEqualizer(svg, frequencyData);
192
- break;
193
- }
194
- }
195
- }
196
- get target() {
197
- const target = document.querySelector(this.getAttribute("target") ?? "");
198
- if (target instanceof EFAudio || target instanceof EFVideo) {
199
- return target;
200
- }
201
- throw new Error("Invalid target, must be an EFAudio element");
202
- }
203
- };
204
- EFWaveform.styles = [];
205
- __decorateClass([
206
- property({
207
- type: String,
208
- attribute: "mode"
209
- })
210
- ], EFWaveform.prototype, "mode", 2);
211
- __decorateClass([
212
- property({ type: String })
213
- ], EFWaveform.prototype, "color", 2);
214
- EFWaveform = __decorateClass([
215
- customElement("ef-waveform")
216
- ], EFWaveform);
217
- export {
218
- EFWaveform
219
- };
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const context = require("@lit/context");
4
- const EFWorkbench = require("../gui/EFWorkbench.cjs");
5
- const state_js = require("lit/decorators/state.js");
6
- var __defProp = Object.defineProperty;
7
- var __decorateClass = (decorators, target, key, kind) => {
8
- var result = void 0;
9
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
- if (decorator = decorators[i])
11
- result = decorator(target, key, result) || result;
12
- if (result) __defProp(target, key, result);
13
- return result;
14
- };
15
- function FetchMixin(superClass) {
16
- class FetchElement extends superClass {
17
- constructor() {
18
- super(...arguments);
19
- this.fetch = fetch.bind(window);
20
- }
21
- }
22
- __decorateClass([
23
- context.consume({ context: EFWorkbench.fetchContext, subscribe: true }),
24
- state_js.state()
25
- ], FetchElement.prototype, "fetch");
26
- return FetchElement;
27
- }
28
- exports.FetchMixin = FetchMixin;
@@ -1,8 +0,0 @@
1
- import { LitElement } from 'lit';
2
-
3
- export declare class FetchMixinInterface {
4
- fetch: typeof fetch;
5
- }
6
- type Constructor<T = {}> = new (...args: any[]) => T;
7
- export declare function FetchMixin<T extends Constructor<LitElement>>(superClass: T): Constructor<FetchMixinInterface> & T;
8
- export {};
@@ -1,28 +0,0 @@
1
- import { consume } from "@lit/context";
2
- import { fetchContext } from "../gui/EFWorkbench.js";
3
- import { state } from "lit/decorators/state.js";
4
- var __defProp = Object.defineProperty;
5
- var __decorateClass = (decorators, target, key, kind) => {
6
- var result = void 0;
7
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
8
- if (decorator = decorators[i])
9
- result = decorator(target, key, result) || result;
10
- if (result) __defProp(target, key, result);
11
- return result;
12
- };
13
- function FetchMixin(superClass) {
14
- class FetchElement extends superClass {
15
- constructor() {
16
- super(...arguments);
17
- this.fetch = fetch.bind(window);
18
- }
19
- }
20
- __decorateClass([
21
- consume({ context: fetchContext, subscribe: true }),
22
- state()
23
- ], FetchElement.prototype, "fetch");
24
- return FetchElement;
25
- }
26
- export {
27
- FetchMixin
28
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- class TimegroupController {
4
- constructor(host, child) {
5
- this.host = host;
6
- this.child = child;
7
- this.host.addController(this);
8
- }
9
- remove() {
10
- this.host.removeController(this);
11
- }
12
- hostDisconnected() {
13
- this.host.removeController(this);
14
- }
15
- hostUpdated() {
16
- this.child.requestUpdate();
17
- this.child.currentTimeMs = this.host.currentTimeMs - (this.child.startTimeMs ?? 0);
18
- }
19
- }
20
- exports.TimegroupController = TimegroupController;
@@ -1,14 +0,0 @@
1
- import { ReactiveController, LitElement } from 'lit';
2
- import { EFTimegroup } from './EFTimegroup';
3
-
4
- export declare class TimegroupController implements ReactiveController {
5
- private host;
6
- private child;
7
- constructor(host: EFTimegroup, child: {
8
- currentTimeMs: number;
9
- startTimeMs?: number;
10
- } & LitElement);
11
- remove(): void;
12
- hostDisconnected(): void;
13
- hostUpdated(): void;
14
- }
@@ -1,20 +0,0 @@
1
- class TimegroupController {
2
- constructor(host, child) {
3
- this.host = host;
4
- this.child = child;
5
- this.host.addController(this);
6
- }
7
- remove() {
8
- this.host.removeController(this);
9
- }
10
- hostDisconnected() {
11
- this.host.removeController(this);
12
- }
13
- hostUpdated() {
14
- this.child.requestUpdate();
15
- this.child.currentTimeMs = this.host.currentTimeMs - (this.child.startTimeMs ?? 0);
16
- }
17
- }
18
- export {
19
- TimegroupController
20
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parseTimeToMs = require("./parseTimeToMs.cjs");
4
- const durationConverter = {
5
- fromAttribute: (value) => parseTimeToMs.parseTimeToMs(value),
6
- toAttribute: (value) => `${value}s`
7
- };
8
- exports.durationConverter = durationConverter;
@@ -1,4 +0,0 @@
1
- export declare const durationConverter: {
2
- fromAttribute: (value: string) => number;
3
- toAttribute: (value: number) => string;
4
- };
@@ -1,8 +0,0 @@
1
- import { parseTimeToMs } from "./parseTimeToMs.js";
2
- const durationConverter = {
3
- fromAttribute: (value) => parseTimeToMs(value),
4
- toAttribute: (value) => `${value}s`
5
- };
6
- export {
7
- durationConverter
8
- };
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const parseTimeToMs = (time) => {
4
- if (time.endsWith("ms")) {
5
- return Number.parseFloat(time);
6
- }
7
- if (time.endsWith("s")) {
8
- return Number.parseFloat(time) * 1e3;
9
- }
10
- throw new Error("Time must be in milliseconds or seconds (10s, 10000ms)");
11
- };
12
- exports.parseTimeToMs = parseTimeToMs;
@@ -1 +0,0 @@
1
- export declare const parseTimeToMs: (time: string) => number;
@@ -1,12 +0,0 @@
1
- const parseTimeToMs = (time) => {
2
- if (time.endsWith("ms")) {
3
- return Number.parseFloat(time);
4
- }
5
- if (time.endsWith("s")) {
6
- return Number.parseFloat(time) * 1e3;
7
- }
8
- throw new Error("Time must be in milliseconds or seconds (10s, 10000ms)");
9
- };
10
- export {
11
- parseTimeToMs
12
- };