@editframe/elements 0.7.0-beta.8 → 0.7.0-beta.9

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 (86) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +1 -1
  3. package/postcss.config.cjs +12 -0
  4. package/{dist/packages/elements/src/EF_FRAMEGEN.js → src/EF_FRAMEGEN.ts} +113 -32
  5. package/src/EF_INTERACTIVE.ts +2 -0
  6. package/src/elements.css +22 -0
  7. package/src/index.ts +33 -0
  8. package/tailwind.config.ts +10 -0
  9. package/tsconfig.json +4 -0
  10. package/vite.config.ts +8 -0
  11. package/dist/lib/av/EncodedAsset.cjs +0 -577
  12. package/dist/lib/av/EncodedAsset.js +0 -560
  13. package/dist/lib/av/MP4File.cjs +0 -187
  14. package/dist/lib/av/MP4File.js +0 -170
  15. package/dist/lib/av/msToTimeCode.cjs +0 -15
  16. package/dist/lib/av/msToTimeCode.js +0 -15
  17. package/dist/lib/util/awaitMicrotask.cjs +0 -4
  18. package/dist/lib/util/awaitMicrotask.js +0 -4
  19. package/dist/lib/util/memoize.cjs +0 -14
  20. package/dist/lib/util/memoize.js +0 -14
  21. package/dist/packages/elements/src/EF_FRAMEGEN.cjs +0 -197
  22. package/dist/packages/elements/src/EF_FRAMEGEN.d.ts +0 -44
  23. package/dist/packages/elements/src/EF_INTERACTIVE.cjs +0 -4
  24. package/dist/packages/elements/src/EF_INTERACTIVE.d.ts +0 -1
  25. package/dist/packages/elements/src/EF_INTERACTIVE.js +0 -4
  26. package/dist/packages/elements/src/elements/CrossUpdateController.cjs +0 -16
  27. package/dist/packages/elements/src/elements/CrossUpdateController.d.ts +0 -9
  28. package/dist/packages/elements/src/elements/CrossUpdateController.js +0 -16
  29. package/dist/packages/elements/src/elements/EFAudio.cjs +0 -53
  30. package/dist/packages/elements/src/elements/EFAudio.d.ts +0 -10
  31. package/dist/packages/elements/src/elements/EFAudio.js +0 -54
  32. package/dist/packages/elements/src/elements/EFCaptions.cjs +0 -164
  33. package/dist/packages/elements/src/elements/EFCaptions.d.ts +0 -38
  34. package/dist/packages/elements/src/elements/EFCaptions.js +0 -166
  35. package/dist/packages/elements/src/elements/EFImage.cjs +0 -79
  36. package/dist/packages/elements/src/elements/EFImage.d.ts +0 -14
  37. package/dist/packages/elements/src/elements/EFImage.js +0 -80
  38. package/dist/packages/elements/src/elements/EFMedia.cjs +0 -336
  39. package/dist/packages/elements/src/elements/EFMedia.d.ts +0 -61
  40. package/dist/packages/elements/src/elements/EFMedia.js +0 -336
  41. package/dist/packages/elements/src/elements/EFSourceMixin.cjs +0 -55
  42. package/dist/packages/elements/src/elements/EFSourceMixin.d.ts +0 -12
  43. package/dist/packages/elements/src/elements/EFSourceMixin.js +0 -55
  44. package/dist/packages/elements/src/elements/EFTemporal.cjs +0 -199
  45. package/dist/packages/elements/src/elements/EFTemporal.d.ts +0 -38
  46. package/dist/packages/elements/src/elements/EFTemporal.js +0 -199
  47. package/dist/packages/elements/src/elements/EFTimegroup.browsertest.d.ts +0 -12
  48. package/dist/packages/elements/src/elements/EFTimegroup.cjs +0 -352
  49. package/dist/packages/elements/src/elements/EFTimegroup.d.ts +0 -39
  50. package/dist/packages/elements/src/elements/EFTimegroup.js +0 -353
  51. package/dist/packages/elements/src/elements/EFVideo.cjs +0 -109
  52. package/dist/packages/elements/src/elements/EFVideo.d.ts +0 -14
  53. package/dist/packages/elements/src/elements/EFVideo.js +0 -110
  54. package/dist/packages/elements/src/elements/EFWaveform.cjs +0 -242
  55. package/dist/packages/elements/src/elements/EFWaveform.d.ts +0 -30
  56. package/dist/packages/elements/src/elements/EFWaveform.js +0 -226
  57. package/dist/packages/elements/src/elements/FetchMixin.cjs +0 -28
  58. package/dist/packages/elements/src/elements/FetchMixin.d.ts +0 -8
  59. package/dist/packages/elements/src/elements/FetchMixin.js +0 -28
  60. package/dist/packages/elements/src/elements/TimegroupController.cjs +0 -20
  61. package/dist/packages/elements/src/elements/TimegroupController.d.ts +0 -14
  62. package/dist/packages/elements/src/elements/TimegroupController.js +0 -20
  63. package/dist/packages/elements/src/elements/durationConverter.cjs +0 -8
  64. package/dist/packages/elements/src/elements/durationConverter.d.ts +0 -4
  65. package/dist/packages/elements/src/elements/durationConverter.js +0 -8
  66. package/dist/packages/elements/src/elements/parseTimeToMs.cjs +0 -12
  67. package/dist/packages/elements/src/elements/parseTimeToMs.d.ts +0 -1
  68. package/dist/packages/elements/src/elements/parseTimeToMs.js +0 -12
  69. package/dist/packages/elements/src/elements/util.cjs +0 -11
  70. package/dist/packages/elements/src/elements/util.d.ts +0 -4
  71. package/dist/packages/elements/src/elements/util.js +0 -11
  72. package/dist/packages/elements/src/gui/EFFilmstrip.cjs +0 -825
  73. package/dist/packages/elements/src/gui/EFFilmstrip.d.ts +0 -147
  74. package/dist/packages/elements/src/gui/EFFilmstrip.js +0 -833
  75. package/dist/packages/elements/src/gui/EFWorkbench.cjs +0 -214
  76. package/dist/packages/elements/src/gui/EFWorkbench.d.ts +0 -45
  77. package/dist/packages/elements/src/gui/EFWorkbench.js +0 -215
  78. package/dist/packages/elements/src/gui/TWMixin.cjs +0 -28
  79. package/dist/packages/elements/src/gui/TWMixin.css.cjs +0 -3
  80. package/dist/packages/elements/src/gui/TWMixin.css.js +0 -4
  81. package/dist/packages/elements/src/gui/TWMixin.d.ts +0 -3
  82. package/dist/packages/elements/src/gui/TWMixin.js +0 -28
  83. package/dist/packages/elements/src/index.cjs +0 -50
  84. package/dist/packages/elements/src/index.d.ts +0 -10
  85. package/dist/packages/elements/src/index.js +0 -23
  86. package/dist/style.css +0 -791
@@ -1,242 +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.targetSelector = "";
48
- this.frameTask = new task.Task(this, {
49
- autoRun: EF_INTERACTIVE.EF_INTERACTIVE,
50
- args: () => [this.targetElement.audioBufferTask.status],
51
- task: async () => {
52
- await this.targetElement.audioBufferTask.taskComplete;
53
- }
54
- });
55
- }
56
- createRenderRoot() {
57
- return this;
58
- }
59
- render() {
60
- return lit.html` <svg ${ref_js.ref(this.svgRef)} class="h-full w-full" store></svg> `;
61
- }
62
- set target(value) {
63
- this.targetSelector = value;
64
- }
65
- connectedCallback() {
66
- super.connectedCallback();
67
- if (this.targetElement) {
68
- new CrossUpdateController.CrossUpdateController(this.targetElement, this);
69
- }
70
- }
71
- drawBars(svg, frequencyData) {
72
- const waveWidth = svg.clientWidth * devicePixelRatio;
73
- const waveHeight = svg.clientHeight;
74
- const waveLeft = 0;
75
- const waveRight = waveWidth;
76
- const barX = d3__namespace.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3__namespace.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
77
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
78
- const baseline = waveHeight / 2;
79
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
80
- const minBarHeight = 2;
81
- 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));
82
- bars.exit().remove();
83
- }
84
- drawBricks(svg, frequencyData) {
85
- const waveWidth = svg.clientWidth * devicePixelRatio;
86
- const waveHeight = svg.clientHeight * devicePixelRatio;
87
- const brickWidth = waveWidth / frequencyData.length;
88
- const brickHeightFactor = waveHeight / 255 / 2;
89
- const brickPadding = 2;
90
- const midHeight = waveHeight / 2;
91
- 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");
92
- 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);
93
- }
94
- drawLine(svg, frequencyData) {
95
- const waveWidth = svg.clientWidth * devicePixelRatio;
96
- const waveHeight = svg.clientHeight * devicePixelRatio;
97
- const xScale = d3__namespace.scaleLinear().domain([0, frequencyData.length - 1]).range([0, waveWidth]);
98
- const yScale = d3__namespace.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
99
- const lineGenerator = d3__namespace.line().x((_, i) => xScale(i)).y((d) => yScale(d));
100
- const pathData = lineGenerator(frequencyData);
101
- 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);
102
- }
103
- drawRoundBars(svg, frequencyData) {
104
- const waveWidth = svg.clientWidth * devicePixelRatio;
105
- const waveHeight = svg.clientHeight;
106
- const waveLeft = 0;
107
- const waveRight = waveWidth;
108
- const barX = d3__namespace.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3__namespace.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
109
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
110
- const baseline = waveHeight / 2;
111
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
112
- const minBarHeight = 2;
113
- 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());
114
- bars.exit().remove();
115
- }
116
- drawEqualizer(svg, frequencyData) {
117
- const waveWidth = svg.clientWidth * devicePixelRatio;
118
- const waveHeight = svg.clientHeight * devicePixelRatio;
119
- const barWidth = waveWidth / frequencyData.length;
120
- const barPadding = 1;
121
- const minHeight = 1;
122
- const heightScale = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
123
- 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);
124
- d3__namespace.select(svg).selectAll("rect.equalizerBar").data(frequencyData).join("rect").attr("class", "equalizerBar").attr("x", (_d, i) => i * barWidth + barPadding / 2).attr(
125
- "y",
126
- (d) => waveHeight / 2 - Math.max(heightScale(d) / 2, minHeight)
127
- ).attr("width", barWidth - barPadding).attr("height", (d) => Math.max(heightScale(d), minHeight));
128
- d3__namespace.select(svg).selectAll("rect.equalizerBar").transition().duration(100).attr(
129
- "y",
130
- (d) => waveHeight / 2 - Math.max(heightScale(Number(d)) / 2, minHeight)
131
- ).attr("height", (d) => Math.max(heightScale(Number(d)), minHeight));
132
- }
133
- drawCurve(svg, frequencyData) {
134
- const waveWidth = svg.clientWidth * devicePixelRatio;
135
- const waveHeight = svg.clientHeight * devicePixelRatio;
136
- const xScale = d3__namespace.scaleLinear().domain([0, frequencyData.length]).range([0, waveWidth]);
137
- const yScale = d3__namespace.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
138
- const curveGenerator = d3__namespace.line().x((_, i) => xScale(i)).y((d) => yScale(d)).curve(d3__namespace.curveNatural);
139
- const pathData = curveGenerator(frequencyData);
140
- 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);
141
- }
142
- drawPixel(svg, frequencyData) {
143
- const waveWidth = svg.clientWidth * devicePixelRatio;
144
- const waveHeight = svg.clientHeight;
145
- const baseline = waveHeight / 2;
146
- const barX = d3__namespace.scaleBand().domain(d3__namespace.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
147
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, baseline]);
148
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
149
- 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);
150
- bars.exit().remove();
151
- }
152
- drawWave(svg, frequencyData) {
153
- const waveWidth = svg.clientWidth * devicePixelRatio;
154
- const waveHeight = svg.clientHeight;
155
- const barX = d3__namespace.scaleBand().domain(d3__namespace.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
156
- const height = d3__namespace.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
157
- 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);
158
- const bars = d3__namespace.select(svg).selectAll("rect").data(frequencyData);
159
- 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);
160
- bars.exit().remove();
161
- }
162
- async updated() {
163
- const svg = this.svgRef.value;
164
- if (!svg) {
165
- return;
166
- }
167
- if (!this.targetElement.audioBufferTask.value) {
168
- return;
169
- }
170
- if (this.targetElement.ownCurrentTimeMs > 0) {
171
- const audioContext = new OfflineAudioContext(2, 48e3 / 25, 48e3);
172
- const audioBufferSource = audioContext.createBufferSource();
173
- audioBufferSource.buffer = this.targetElement.audioBufferTask.value.buffer;
174
- const analyser = audioContext.createAnalyser();
175
- analyser.fftSize = 256;
176
- audioBufferSource.connect(analyser);
177
- audioBufferSource.start(
178
- 0,
179
- Math.max(
180
- 0,
181
- (this.targetElement.ownCurrentTimeMs - this.targetElement.audioBufferTask.value.startOffsetMs) / 1e3
182
- ),
183
- 48e3 / 1e3
184
- );
185
- await audioContext.startRendering();
186
- const frequencyData = new Uint8Array(analyser.frequencyBinCount);
187
- analyser.getByteFrequencyData(frequencyData);
188
- const rect = this.getBoundingClientRect();
189
- svg.setAttribute("width", (rect.width * devicePixelRatio).toString());
190
- svg.setAttribute("height", (rect.height * devicePixelRatio).toString());
191
- switch (this.mode) {
192
- case "bars":
193
- this.drawBars(svg, frequencyData);
194
- break;
195
- case "bricks":
196
- this.drawBricks(svg, frequencyData);
197
- break;
198
- case "curve":
199
- this.drawCurve(svg, frequencyData);
200
- break;
201
- case "line":
202
- this.drawLine(svg, frequencyData);
203
- break;
204
- case "pixel":
205
- this.drawPixel(svg, frequencyData);
206
- break;
207
- case "wave":
208
- this.drawWave(svg, frequencyData);
209
- break;
210
- case "roundBars":
211
- this.drawRoundBars(svg, frequencyData);
212
- break;
213
- case "equalizer":
214
- this.drawEqualizer(svg, frequencyData);
215
- break;
216
- }
217
- }
218
- }
219
- get targetElement() {
220
- const target = document.getElementById(this.targetSelector ?? "");
221
- if (target instanceof EFAudio.EFAudio || target instanceof EFVideo.EFVideo) {
222
- return target;
223
- }
224
- throw new Error("Invalid target, must be an EFAudio element");
225
- }
226
- };
227
- exports.EFWaveform.styles = [];
228
- __decorateClass([
229
- decorators_js.property({
230
- type: String,
231
- attribute: "mode"
232
- })
233
- ], exports.EFWaveform.prototype, "mode", 2);
234
- __decorateClass([
235
- decorators_js.property({ type: String })
236
- ], exports.EFWaveform.prototype, "color", 2);
237
- __decorateClass([
238
- decorators_js.property({ type: String, attribute: "target", reflect: true })
239
- ], exports.EFWaveform.prototype, "targetSelector", 2);
240
- exports.EFWaveform = __decorateClass([
241
- decorators_js.customElement("ef-waveform")
242
- ], exports.EFWaveform);
@@ -1,30 +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
- targetSelector: string;
16
- set target(value: string);
17
- connectedCallback(): void;
18
- protected drawBars(svg: SVGElement, frequencyData: Uint8Array): void;
19
- protected drawBricks(svg: SVGElement, frequencyData: Uint8Array): void;
20
- protected drawLine(svg: SVGElement, frequencyData: Uint8Array): void;
21
- protected drawRoundBars(svg: SVGElement, frequencyData: Uint8Array): void;
22
- protected drawEqualizer(svg: SVGElement, frequencyData: Uint8Array): void;
23
- protected drawCurve(svg: SVGElement, frequencyData: Uint8Array): void;
24
- protected drawPixel(svg: SVGElement, frequencyData: Uint8Array): void;
25
- protected drawWave(svg: SVGElement, frequencyData: Uint8Array): void;
26
- frameTask: Task<readonly [import('@lit/task').TaskStatus], void>;
27
- protected updated(): Promise<void>;
28
- get targetElement(): EFAudio | EFVideo;
29
- }
30
- export {};
@@ -1,226 +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.targetSelector = "";
29
- this.frameTask = new Task(this, {
30
- autoRun: EF_INTERACTIVE,
31
- args: () => [this.targetElement.audioBufferTask.status],
32
- task: async () => {
33
- await this.targetElement.audioBufferTask.taskComplete;
34
- }
35
- });
36
- }
37
- createRenderRoot() {
38
- return this;
39
- }
40
- render() {
41
- return html` <svg ${ref(this.svgRef)} class="h-full w-full" store></svg> `;
42
- }
43
- set target(value) {
44
- this.targetSelector = value;
45
- }
46
- connectedCallback() {
47
- super.connectedCallback();
48
- if (this.targetElement) {
49
- new CrossUpdateController(this.targetElement, this);
50
- }
51
- }
52
- drawBars(svg, frequencyData) {
53
- const waveWidth = svg.clientWidth * devicePixelRatio;
54
- const waveHeight = svg.clientHeight;
55
- const waveLeft = 0;
56
- const waveRight = waveWidth;
57
- const barX = d3.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
58
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
59
- const baseline = waveHeight / 2;
60
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
61
- const minBarHeight = 2;
62
- 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));
63
- bars.exit().remove();
64
- }
65
- drawBricks(svg, frequencyData) {
66
- const waveWidth = svg.clientWidth * devicePixelRatio;
67
- const waveHeight = svg.clientHeight * devicePixelRatio;
68
- const brickWidth = waveWidth / frequencyData.length;
69
- const brickHeightFactor = waveHeight / 255 / 2;
70
- const brickPadding = 2;
71
- const midHeight = waveHeight / 2;
72
- 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");
73
- 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);
74
- }
75
- drawLine(svg, frequencyData) {
76
- const waveWidth = svg.clientWidth * devicePixelRatio;
77
- const waveHeight = svg.clientHeight * devicePixelRatio;
78
- const xScale = d3.scaleLinear().domain([0, frequencyData.length - 1]).range([0, waveWidth]);
79
- const yScale = d3.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
80
- const lineGenerator = d3.line().x((_, i) => xScale(i)).y((d) => yScale(d));
81
- const pathData = lineGenerator(frequencyData);
82
- 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);
83
- }
84
- drawRoundBars(svg, frequencyData) {
85
- const waveWidth = svg.clientWidth * devicePixelRatio;
86
- const waveHeight = svg.clientHeight;
87
- const waveLeft = 0;
88
- const waveRight = waveWidth;
89
- const barX = d3.scaleBand().paddingInner(0.5).paddingOuter(0.01).domain(d3.range(frequencyData.length).map((n) => String(n))).rangeRound([waveLeft, waveRight]);
90
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
91
- const baseline = waveHeight / 2;
92
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
93
- const minBarHeight = 2;
94
- 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());
95
- bars.exit().remove();
96
- }
97
- drawEqualizer(svg, frequencyData) {
98
- const waveWidth = svg.clientWidth * devicePixelRatio;
99
- const waveHeight = svg.clientHeight * devicePixelRatio;
100
- const barWidth = waveWidth / frequencyData.length;
101
- const barPadding = 1;
102
- const minHeight = 1;
103
- const heightScale = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
104
- 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);
105
- d3.select(svg).selectAll("rect.equalizerBar").data(frequencyData).join("rect").attr("class", "equalizerBar").attr("x", (_d, i) => i * barWidth + barPadding / 2).attr(
106
- "y",
107
- (d) => waveHeight / 2 - Math.max(heightScale(d) / 2, minHeight)
108
- ).attr("width", barWidth - barPadding).attr("height", (d) => Math.max(heightScale(d), minHeight));
109
- d3.select(svg).selectAll("rect.equalizerBar").transition().duration(100).attr(
110
- "y",
111
- (d) => waveHeight / 2 - Math.max(heightScale(Number(d)) / 2, minHeight)
112
- ).attr("height", (d) => Math.max(heightScale(Number(d)), minHeight));
113
- }
114
- drawCurve(svg, frequencyData) {
115
- const waveWidth = svg.clientWidth * devicePixelRatio;
116
- const waveHeight = svg.clientHeight * devicePixelRatio;
117
- const xScale = d3.scaleLinear().domain([0, frequencyData.length]).range([0, waveWidth]);
118
- const yScale = d3.scaleLinear().domain([0, 255]).range([waveHeight, 0]);
119
- const curveGenerator = d3.line().x((_, i) => xScale(i)).y((d) => yScale(d)).curve(d3.curveNatural);
120
- const pathData = curveGenerator(frequencyData);
121
- 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);
122
- }
123
- drawPixel(svg, frequencyData) {
124
- const waveWidth = svg.clientWidth * devicePixelRatio;
125
- const waveHeight = svg.clientHeight;
126
- const baseline = waveHeight / 2;
127
- const barX = d3.scaleBand().domain(d3.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
128
- const height = d3.scaleLinear().domain([0, 255]).range([0, baseline]);
129
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
130
- 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);
131
- bars.exit().remove();
132
- }
133
- drawWave(svg, frequencyData) {
134
- const waveWidth = svg.clientWidth * devicePixelRatio;
135
- const waveHeight = svg.clientHeight;
136
- const barX = d3.scaleBand().domain(d3.range(frequencyData.length).map(String)).rangeRound([0, waveWidth]).paddingInner(0.03).paddingOuter(0.02);
137
- const height = d3.scaleLinear().domain([0, 255]).range([0, waveHeight / 2]);
138
- 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);
139
- const bars = d3.select(svg).selectAll("rect").data(frequencyData);
140
- 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);
141
- bars.exit().remove();
142
- }
143
- async updated() {
144
- const svg = this.svgRef.value;
145
- if (!svg) {
146
- return;
147
- }
148
- if (!this.targetElement.audioBufferTask.value) {
149
- return;
150
- }
151
- if (this.targetElement.ownCurrentTimeMs > 0) {
152
- const audioContext = new OfflineAudioContext(2, 48e3 / 25, 48e3);
153
- const audioBufferSource = audioContext.createBufferSource();
154
- audioBufferSource.buffer = this.targetElement.audioBufferTask.value.buffer;
155
- const analyser = audioContext.createAnalyser();
156
- analyser.fftSize = 256;
157
- audioBufferSource.connect(analyser);
158
- audioBufferSource.start(
159
- 0,
160
- Math.max(
161
- 0,
162
- (this.targetElement.ownCurrentTimeMs - this.targetElement.audioBufferTask.value.startOffsetMs) / 1e3
163
- ),
164
- 48e3 / 1e3
165
- );
166
- await audioContext.startRendering();
167
- const frequencyData = new Uint8Array(analyser.frequencyBinCount);
168
- analyser.getByteFrequencyData(frequencyData);
169
- const rect = this.getBoundingClientRect();
170
- svg.setAttribute("width", (rect.width * devicePixelRatio).toString());
171
- svg.setAttribute("height", (rect.height * devicePixelRatio).toString());
172
- switch (this.mode) {
173
- case "bars":
174
- this.drawBars(svg, frequencyData);
175
- break;
176
- case "bricks":
177
- this.drawBricks(svg, frequencyData);
178
- break;
179
- case "curve":
180
- this.drawCurve(svg, frequencyData);
181
- break;
182
- case "line":
183
- this.drawLine(svg, frequencyData);
184
- break;
185
- case "pixel":
186
- this.drawPixel(svg, frequencyData);
187
- break;
188
- case "wave":
189
- this.drawWave(svg, frequencyData);
190
- break;
191
- case "roundBars":
192
- this.drawRoundBars(svg, frequencyData);
193
- break;
194
- case "equalizer":
195
- this.drawEqualizer(svg, frequencyData);
196
- break;
197
- }
198
- }
199
- }
200
- get targetElement() {
201
- const target = document.getElementById(this.targetSelector ?? "");
202
- if (target instanceof EFAudio || target instanceof EFVideo) {
203
- return target;
204
- }
205
- throw new Error("Invalid target, must be an EFAudio element");
206
- }
207
- };
208
- EFWaveform.styles = [];
209
- __decorateClass([
210
- property({
211
- type: String,
212
- attribute: "mode"
213
- })
214
- ], EFWaveform.prototype, "mode", 2);
215
- __decorateClass([
216
- property({ type: String })
217
- ], EFWaveform.prototype, "color", 2);
218
- __decorateClass([
219
- property({ type: String, attribute: "target", reflect: true })
220
- ], EFWaveform.prototype, "targetSelector", 2);
221
- EFWaveform = __decorateClass([
222
- customElement("ef-waveform")
223
- ], EFWaveform);
224
- export {
225
- EFWaveform
226
- };
@@ -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;