@motionscript/audio 0.1.0-alpha.5 → 0.1.0-alpha.6
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.
- package/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/manifest.json +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/waveform/full-waveform.d.ts +60 -73
- package/dist/waveform/full-waveform.d.ts.map +1 -1
- package/dist/waveform/full-waveform.js +114 -160
- package/dist/waveform/full-waveform.js.map +1 -1
- package/dist/waveform/live-waveform.d.ts +63 -63
- package/dist/waveform/live-waveform.d.ts.map +1 -1
- package/dist/waveform/live-waveform.js +92 -134
- package/dist/waveform/live-waveform.js.map +1 -1
- package/package.json +4 -4
- package/src/nodes.ts +8 -10
- package/src/waveform/full-waveform.ts +128 -157
- package/src/waveform/live-waveform.ts +113 -128
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Node2D, node, command, easeInOut, fillOps, property, } from "@motionscript/sdk";
|
|
8
|
-
import { declarePaints } from "@motionscript/sdk/component";
|
|
1
|
+
import { Types, component2d, easeInOut, fillOps, } from "@motionscript/sdk";
|
|
9
2
|
import { EMPTY_ENVELOPE, sampleEnvelope } from "./envelope.js";
|
|
10
3
|
import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./shared.js";
|
|
4
|
+
/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */
|
|
5
|
+
const paint = (initial) => Types.custom(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp });
|
|
11
6
|
/**
|
|
12
7
|
* A **waveform overview**: the whole recording's shape, drawn at once.
|
|
13
8
|
*
|
|
@@ -19,7 +14,7 @@ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./sha
|
|
|
19
14
|
*
|
|
20
15
|
* ## Progress is authored, not assumed
|
|
21
16
|
*
|
|
22
|
-
*
|
|
17
|
+
* `follow` is off by default, and that default is the considered one. A
|
|
23
18
|
* scene has no idea where the recording it is drawing sits on the video's audio
|
|
24
19
|
* lane — a clip is placed, trimmed and sped up out there, and none of that is
|
|
25
20
|
* visible from in here. So the honest default is that the fill is *animation*:
|
|
@@ -31,162 +26,121 @@ import { clamp01, groupByPaint, layOutBars, paintBars, voiceColor, } from "./sha
|
|
|
31
26
|
*
|
|
32
27
|
* ## Voices instead of progress
|
|
33
28
|
*
|
|
34
|
-
* With
|
|
29
|
+
* With `byVoice` on, the played/ahead split is replaced by one colour per
|
|
35
30
|
* speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the
|
|
36
31
|
* floor, where the turns are, how long each one ran. It replaces the progress
|
|
37
32
|
* colours rather than combining with them, because a bar cannot mean two things
|
|
38
33
|
* at once and "played, and also Grace" is a legend nobody can hold in their
|
|
39
34
|
* head.
|
|
40
35
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
floor: this.floor,
|
|
86
|
-
});
|
|
87
|
-
if (boxes.length === 0)
|
|
88
|
-
return;
|
|
89
|
-
// One draw per colour rather than per bar — see {@link paintBars}. The key
|
|
90
|
-
// is a string because it has to be comparable; the paint it stands for is
|
|
91
|
-
// resolved after the grouping.
|
|
92
|
-
const edge = this.played * boxes.length;
|
|
93
|
-
const groups = groupByPaint(boxes, (i) => this.byVoice
|
|
94
|
-
? `voice:${sampled[i].speaker}`
|
|
95
|
-
: i < edge
|
|
96
|
-
? "played"
|
|
97
|
-
: "ahead");
|
|
98
|
-
for (const [key, run] of groups) {
|
|
99
|
-
const graphics = paintBars(run, this.paintFor(key), this.radius);
|
|
100
|
-
if (graphics)
|
|
101
|
-
ctx.draw(graphics);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* The paint a group takes.
|
|
106
|
-
*
|
|
107
|
-
* A voice's colour is a **colour string**, never one of the node's two fill
|
|
108
|
-
* props, and that is deliberate: a voice is identified by hue, so a gradient
|
|
109
|
-
* or an image there would defeat the only thing the colour is for. It also
|
|
110
|
-
* means these paints declare no assets, which is why {@link declareAssets}
|
|
111
|
-
* only has to account for the two real fill props.
|
|
112
|
-
*/
|
|
113
|
-
paintFor(key) {
|
|
114
|
-
if (key === "played")
|
|
115
|
-
return this.playedFill;
|
|
116
|
-
if (key === "ahead")
|
|
117
|
-
return this.fill;
|
|
118
|
-
const voice = Number(key.slice("voice:".length));
|
|
119
|
-
if (!Number.isFinite(voice) || voice < 0)
|
|
120
|
-
return this.fill;
|
|
121
|
-
return this.voiceColors[voice] ?? voiceColor(voice);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
__decorate([
|
|
125
|
-
property({ default: EMPTY_ENVELOPE })
|
|
126
|
-
], FullWaveform.prototype, "envelope", void 0);
|
|
127
|
-
__decorate([
|
|
128
|
-
property({ default: 120 })
|
|
129
|
-
], FullWaveform.prototype, "bars", void 0);
|
|
130
|
-
__decorate([
|
|
131
|
-
property({ default: 0.3 })
|
|
132
|
-
], FullWaveform.prototype, "gap", void 0);
|
|
133
|
-
__decorate([
|
|
134
|
-
property({ default: 2 })
|
|
135
|
-
], FullWaveform.prototype, "radius", void 0);
|
|
136
|
-
__decorate([
|
|
137
|
-
property({ default: 0 })
|
|
138
|
-
], FullWaveform.prototype, "progress", void 0);
|
|
139
|
-
__decorate([
|
|
140
|
-
property({ default: false })
|
|
141
|
-
], FullWaveform.prototype, "follow", void 0);
|
|
142
|
-
__decorate([
|
|
143
|
-
property({ default: 1 })
|
|
144
|
-
], FullWaveform.prototype, "gain", void 0);
|
|
145
|
-
__decorate([
|
|
146
|
-
property({ default: 0.015 })
|
|
147
|
-
], FullWaveform.prototype, "floor", void 0);
|
|
148
|
-
__decorate([
|
|
149
|
-
property({ default: "center" })
|
|
150
|
-
], FullWaveform.prototype, "align", void 0);
|
|
151
|
-
__decorate([
|
|
152
|
-
property({ default: false })
|
|
153
|
-
], FullWaveform.prototype, "byVoice", void 0);
|
|
154
|
-
__decorate([
|
|
155
|
-
property({ default: [] })
|
|
156
|
-
], FullWaveform.prototype, "voiceColors", void 0);
|
|
157
|
-
__decorate([
|
|
158
|
-
property({
|
|
159
|
-
default: "#5b5b7a",
|
|
160
|
-
mapper: fillOps.resolve,
|
|
161
|
-
tween: fillOps.lerp,
|
|
162
|
-
})
|
|
163
|
-
], FullWaveform.prototype, "fill", void 0);
|
|
164
|
-
__decorate([
|
|
165
|
-
property({
|
|
166
|
-
default: "#6366f1",
|
|
167
|
-
mapper: fillOps.resolve,
|
|
168
|
-
tween: fillOps.lerp,
|
|
169
|
-
})
|
|
170
|
-
], FullWaveform.prototype, "playedFill", void 0);
|
|
171
|
-
__decorate([
|
|
172
|
-
command()
|
|
173
|
-
], FullWaveform.prototype, "sweep", null);
|
|
174
|
-
FullWaveform = __decorate([
|
|
175
|
-
node({
|
|
176
|
-
key: "fullWaveform",
|
|
177
|
-
parentKey: "node",
|
|
178
|
-
forkable: true,
|
|
179
|
-
layout: {
|
|
180
|
-
children: "freeform",
|
|
181
|
-
defaultWidthMode: "fixed",
|
|
182
|
-
defaultHeightMode: "fixed",
|
|
183
|
-
acceptsChildren: true,
|
|
36
|
+
export const FullWaveform = component2d({
|
|
37
|
+
key: "fullWaveform",
|
|
38
|
+
state: {
|
|
39
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
40
|
+
envelope: Types.custom(EMPTY_ENVELOPE),
|
|
41
|
+
/** How many columns the whole file is drawn as. */
|
|
42
|
+
bars: 120,
|
|
43
|
+
/** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */
|
|
44
|
+
gap: 0.3,
|
|
45
|
+
/** Corner radius of a bar, capped at half its width. */
|
|
46
|
+
radius: 2,
|
|
47
|
+
/** How much of the file reads as played, `0`–`1`. Tweenable. */
|
|
48
|
+
progress: 0,
|
|
49
|
+
/** Drive `progress` from the node's own clock instead of the prop. */
|
|
50
|
+
follow: false,
|
|
51
|
+
/** Multiplies every magnitude — a quiet track pulled up to fill its box. */
|
|
52
|
+
gain: 1,
|
|
53
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
54
|
+
floor: 0.015,
|
|
55
|
+
align: Types.custom("center"),
|
|
56
|
+
/** Colour each voice's turns rather than splitting on played / not played. */
|
|
57
|
+
byVoice: false,
|
|
58
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
59
|
+
voiceColors: Types.custom([]),
|
|
60
|
+
/** The bars ahead of the playhead. */
|
|
61
|
+
fill: paint("#5b5b7a"),
|
|
62
|
+
/** …and the bars behind it. */
|
|
63
|
+
playedFill: paint("#6366f1"),
|
|
64
|
+
},
|
|
65
|
+
// Nothing declares a component's paints but itself: `fill` and `playedFill` both.
|
|
66
|
+
load: (loader, state) => {
|
|
67
|
+
loader.fill(state.fill);
|
|
68
|
+
loader.fill(state.playedFill);
|
|
69
|
+
},
|
|
70
|
+
commands: {
|
|
71
|
+
/**
|
|
72
|
+
* Fill the waveform in, left to right — the node's one command, since
|
|
73
|
+
* everything else about it is expressible as an ordinary `to`. Eased in-out
|
|
74
|
+
* unless it is given an easing of its own.
|
|
75
|
+
*/
|
|
76
|
+
sweep: (timeline, state) => {
|
|
77
|
+
const ease = timeline.easing ? null : easeInOut();
|
|
78
|
+
const from = state.progress;
|
|
79
|
+
return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }));
|
|
184
80
|
},
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
81
|
+
},
|
|
82
|
+
render: (ctx, state) => {
|
|
83
|
+
drawBars(ctx, state);
|
|
84
|
+
ctx.children();
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
function drawBars(ctx, s) {
|
|
88
|
+
const { width, height } = ctx.size;
|
|
89
|
+
if (width <= 0 || height <= 0)
|
|
90
|
+
return;
|
|
91
|
+
const count = Math.max(1, Math.round(s.bars));
|
|
92
|
+
const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count);
|
|
93
|
+
const boxes = layOutBars(sampled, {
|
|
94
|
+
width,
|
|
95
|
+
height,
|
|
96
|
+
gap: s.gap,
|
|
97
|
+
align: s.align,
|
|
98
|
+
gain: s.gain,
|
|
99
|
+
floor: s.floor,
|
|
100
|
+
});
|
|
101
|
+
if (boxes.length === 0)
|
|
102
|
+
return;
|
|
103
|
+
// One draw per colour rather than per bar — see {@link paintBars}. The key
|
|
104
|
+
// is a string because it has to be comparable; the paint it stands for is
|
|
105
|
+
// resolved after the grouping.
|
|
106
|
+
const edge = played(ctx, s) * boxes.length;
|
|
107
|
+
const groups = groupByPaint(boxes, (i) => s.byVoice
|
|
108
|
+
? `voice:${sampled[i].speaker}`
|
|
109
|
+
: i < edge
|
|
110
|
+
? "played"
|
|
111
|
+
: "ahead");
|
|
112
|
+
for (const [key, run] of groups) {
|
|
113
|
+
const graphics = paintBars(run, paintFor(s, key), s.radius);
|
|
114
|
+
if (graphics)
|
|
115
|
+
ctx.draw(graphics);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Where the fill has reached, from whichever source is in charge. */
|
|
119
|
+
function played(ctx, s) {
|
|
120
|
+
if (!s.follow)
|
|
121
|
+
return clamp01(s.progress);
|
|
122
|
+
const length = s.envelope.duration;
|
|
123
|
+
if (length <= 0)
|
|
124
|
+
return 0;
|
|
125
|
+
return clamp01(ctx.time.elapsed / length);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The paint a group takes.
|
|
129
|
+
*
|
|
130
|
+
* A voice's colour is a **colour string**, never one of the node's two fill
|
|
131
|
+
* props, and that is deliberate: a voice is identified by hue, so a gradient
|
|
132
|
+
* or an image there would defeat the only thing the colour is for. It also
|
|
133
|
+
* means these paints declare no assets, which is why `load` only has to account
|
|
134
|
+
* for the two real fill props.
|
|
135
|
+
*/
|
|
136
|
+
function paintFor(s, key) {
|
|
137
|
+
if (key === "played")
|
|
138
|
+
return s.playedFill;
|
|
139
|
+
if (key === "ahead")
|
|
140
|
+
return s.fill;
|
|
141
|
+
const voice = Number(key.slice("voice:".length));
|
|
142
|
+
if (!Number.isFinite(voice) || voice < 0)
|
|
143
|
+
return s.fill;
|
|
144
|
+
return s.voiceColors[voice] ?? voiceColor(voice);
|
|
145
|
+
}
|
|
192
146
|
//# sourceMappingURL=full-waveform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[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C,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;2CAAsB;AACV;IAAxC,QAAQ,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;2CAAiC;AAC3B;IAArC,QAAQ,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;6CAAyB;AACnB;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;iDAA8B;AAOhD;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;0CACgB;AAOV;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;gDACsB;AAOxB;IADC,OAAO,EAAE;yCAOT;AAtCU,YAAY;IAfxB,IAAI,CAAC;QACJ,GAAG,EAAE,cAAc;QACnB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,QAAQ,EAAE,UAAU;YACpB,gBAAgB,EAAE,OAAO;YACzB,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,IAAI;SACtB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;SACZ;KACF,CAAC;GACW,YAAY,CAoHxB","sourcesContent":["import {\r\n Node2D,\r\n node,\r\n command,\r\n easeInOut,\r\n fillOps,\r\n property,\r\n type AssetScope,\r\n type CommandArgs,\r\n type Fill,\r\n type FillResolved,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\nimport type { Seekable } from \"@motionscript/sdk/component\"\r\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n} from \"./shared\"\r\n\r\nexport interface FullWaveformProps extends Node2DProps {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: AudioEnvelope\r\n /** How many columns the whole file is drawn as. */\r\n bars: number\r\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\r\n gap: number\r\n /** Corner radius of a bar, capped at half its width. */\r\n radius: number\r\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\r\n progress: number\r\n /** Drive {@link progress} from the node's own clock instead of the prop. */\r\n follow: boolean\r\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\r\n gain: number\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: number\r\n align: WaveformAlignment\r\n /** Colour each voice's turns rather than splitting on played / not played. */\r\n byVoice: boolean\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: string[]\r\n /** The bars ahead of the playhead. */\r\n fill: Fill\r\n /** …and the bars behind it. */\r\n playedFill: Fill\r\n}\r\n\r\n/**\r\n * A **waveform overview**: the whole recording's shape, drawn at once.\r\n *\r\n * The picture every audio editor opens with, and the one a podcast clip puts\r\n * under its caption — a static silhouette of the file, with a played portion\r\n * that advances. It answers \"how long is this and where are the loud parts\",\r\n * which is a question about the *file*, not about the moment; its sibling\r\n * {@link LiveWaveform} answers the other one.\r\n *\r\n * ## Progress is authored, not assumed\r\n *\r\n * {@link follow} is off by default, and that default is the considered one. A\r\n * scene has no idea where the recording it is drawing sits on the video's audio\r\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\r\n * visible from in here. So the honest default is that the fill is *animation*:\r\n * the author sweeps it with a command, the same as any other tween, and it lands\r\n * wherever they put it. `follow` is the shortcut for the common arrangement\r\n * where the node appears exactly as the track starts, and it says so by being a\r\n * switch someone has to turn on rather than a behaviour that quietly disagrees\r\n * with the mix.\r\n *\r\n * ## Voices instead of progress\r\n *\r\n * With {@link byVoice} on, the played/ahead split is replaced by one colour per\r\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\r\n * floor, where the turns are, how long each one ran. It replaces the progress\r\n * colours rather than combining with them, because a bar cannot mean two things\r\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\r\n * head.\r\n */\r\n@node({\r\n key: \"fullWaveform\",\r\n parentKey: \"node\",\r\n forkable: true,\r\n layout: {\r\n children: \"freeform\",\r\n defaultWidthMode: \"fixed\",\r\n defaultHeightMode: \"fixed\",\r\n acceptsChildren: true,\r\n },\r\n seed: {\r\n width: 900,\r\n height: 160,\r\n },\r\n})\r\nexport class FullWaveform extends Node2D<FullWaveformProps> {\r\n @property({ default: EMPTY_ENVELOPE }) declare envelope: AudioEnvelope\r\n @property({ default: 120 }) declare bars: number\r\n @property({ default: 0.3 }) declare gap: number\r\n @property({ default: 2 }) declare radius: number\r\n @property({ default: 0 }) declare progress: number\r\n @property({ default: false }) declare follow: boolean\r\n @property({ default: 1 }) declare gain: number\r\n @property({ default: 0.015 }) declare floor: number\r\n @property({ default: \"center\" }) declare align: WaveformAlignment\r\n @property({ default: false }) declare byVoice: boolean\r\n @property({ default: [] }) declare voiceColors: string[]\r\n\r\n @property({\r\n default: \"#5b5b7a\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n\r\n @property({\r\n default: \"#6366f1\",\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare playedFill: Fill\r\n\r\n /**\r\n * Fill the waveform in, left to right — the node's one command, since\r\n * everything else about it is expressible as an ordinary `to`.\r\n */\r\n @command()\r\n sweep(args: CommandArgs<Record<string, never>> & { duration: number }): Seekable {\r\n return this.to({\r\n data: { progress: 1 } as Partial<FullWaveformProps>,\r\n duration: args.duration,\r\n easing: args.easing ?? easeInOut(),\r\n })\r\n }\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}. `playedFill` is named\r\n * past the conventional slots, so it is passed explicitly.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets, { fills: [this.playedFill as FillResolved[]] })\r\n }\r\n\r\n /** Where the fill has reached, from whichever source is in charge. */\r\n private get played(): number {\r\n if (!this.follow) return clamp01(this.progress)\r\n const length = this.envelope.duration\r\n if (length <= 0) return 0\r\n return clamp01(this.time.elapsed / length)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const rect = this.layoutBounds\r\n const width = rect?.width ?? 0\r\n const height = rect?.height ?? 0\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(this.bars))\r\n const sampled = sampleEnvelope(\r\n this.envelope,\r\n 0,\r\n this.envelope.duration,\r\n count\r\n )\r\n const boxes = layOutBars(sampled, {\r\n width,\r\n height,\r\n gap: this.gap,\r\n align: this.align,\r\n gain: this.gain,\r\n floor: this.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n // One draw per colour rather than per bar — see {@link paintBars}. The key\r\n // is a string because it has to be comparable; the paint it stands for is\r\n // resolved after the grouping.\r\n const edge = this.played * boxes.length\r\n const groups = groupByPaint(boxes, (i) =>\r\n this.byVoice\r\n ? `voice:${sampled[i].speaker}`\r\n : i < edge\r\n ? \"played\"\r\n : \"ahead\"\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, this.paintFor(key), this.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n }\r\n\r\n /**\r\n * The paint a group takes.\r\n *\r\n * A voice's colour is a **colour string**, never one of the node's two fill\r\n * props, and that is deliberate: a voice is identified by hue, so a gradient\r\n * or an image there would defeat the only thing the colour is for. It also\r\n * means these paints declare no assets, which is why {@link declareAssets}\r\n * only has to account for the two real fill props.\r\n */\r\n private paintFor(key: string): Fill {\r\n if (key === \"played\") return this.playedFill\r\n if (key === \"ahead\") return this.fill\r\n\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return this.fill\r\n return this.voiceColors[voice] ?? voiceColor(voice)\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"full-waveform.js","sourceRoot":"","sources":["../../src/waveform/full-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,YAAY,CAAA;AAC/E,OAAO,EACL,OAAO,EACP,YAAY,EACZ,UAAU,EACV,SAAS,EACT,UAAU,GAEX,MAAM,UAAU,CAAA;AAEjB,sHAAsH;AACtH,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAChC,KAAK,CAAC,MAAM,CAAuB,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;AAE/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,0EAA0E;QAC1E,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAgB,cAAc,CAAC;QACrD,mDAAmD;QACnD,IAAI,EAAE,GAAG;QACT,8EAA8E;QAC9E,GAAG,EAAE,GAAG;QACR,wDAAwD;QACxD,MAAM,EAAE,CAAC;QACT,gEAAgE;QAChE,QAAQ,EAAE,CAAC;QACX,sEAAsE;QACtE,MAAM,EAAE,KAAK;QACb,4EAA4E;QAC5E,IAAI,EAAE,CAAC;QACP,gEAAgE;QAChE,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK,CAAC,MAAM,CAAoB,QAAQ,CAAC;QAChD,8EAA8E;QAC9E,OAAO,EAAE,KAAK;QACd,0EAA0E;QAC1E,WAAW,EAAE,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,CAAC,GAAkB,EAAE,CAAY;IAC9C,IAAI,CAAC,CAAC,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;IACzC,MAAM,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAA;IAClC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IACzB,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA;AAC3C,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,QAAQ,CAAC,CAAY,EAAE,GAAW;IACzC,IAAI,GAAG,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,UAAU,CAAA;IACzC,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,CAAC,CAAC,IAAI,CAAA;IAElC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,IAAI,CAAA;IACvD,OAAO,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAA;AAClD,CAAC","sourcesContent":["import {\r\n Types,\r\n component2d,\r\n easeInOut,\r\n fillOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n type RenderContext,\r\n // Named so the emitted declaration reaches these through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps as _Node2DProps,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\r\nimport {\r\n clamp01,\r\n groupByPaint,\r\n layOutBars,\r\n paintBars,\r\n voiceColor,\r\n type WaveformAlignment,\r\n} from \"./shared\"\r\n\r\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\r\nconst paint = (initial: string) =>\r\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\r\n\r\n/**\r\n * A **waveform overview**: the whole recording's shape, drawn at once.\r\n *\r\n * The picture every audio editor opens with, and the one a podcast clip puts\r\n * under its caption — a static silhouette of the file, with a played portion\r\n * that advances. It answers \"how long is this and where are the loud parts\",\r\n * which is a question about the *file*, not about the moment; its sibling\r\n * {@link LiveWaveform} answers the other one.\r\n *\r\n * ## Progress is authored, not assumed\r\n *\r\n * `follow` is off by default, and that default is the considered one. A\r\n * scene has no idea where the recording it is drawing sits on the video's audio\r\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\r\n * visible from in here. So the honest default is that the fill is *animation*:\r\n * the author sweeps it with a command, the same as any other tween, and it lands\r\n * wherever they put it. `follow` is the shortcut for the common arrangement\r\n * where the node appears exactly as the track starts, and it says so by being a\r\n * switch someone has to turn on rather than a behaviour that quietly disagrees\r\n * with the mix.\r\n *\r\n * ## Voices instead of progress\r\n *\r\n * With `byVoice` on, the played/ahead split is replaced by one colour per\r\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\r\n * floor, where the turns are, how long each one ran. It replaces the progress\r\n * colours rather than combining with them, because a bar cannot mean two things\r\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\r\n * head.\r\n */\r\nexport const FullWaveform = component2d({\r\n key: \"fullWaveform\",\r\n state: {\r\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\r\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\r\n /** How many columns the whole file is drawn as. */\r\n bars: 120,\r\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\r\n gap: 0.3,\r\n /** Corner radius of a bar, capped at half its width. */\r\n radius: 2,\r\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\r\n progress: 0,\r\n /** Drive `progress` from the node's own clock instead of the prop. */\r\n follow: false,\r\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\r\n gain: 1,\r\n /** How much of the box a silent bar still occupies, `0`–`1`. */\r\n floor: 0.015,\r\n align: Types.custom<WaveformAlignment>(\"center\"),\r\n /** Colour each voice's turns rather than splitting on played / not played. */\r\n byVoice: false,\r\n /** A colour per voice index. Short or empty falls back to the palette. */\r\n voiceColors: Types.custom<string[]>([]),\r\n /** The bars ahead of the playhead. */\r\n fill: paint(\"#5b5b7a\"),\r\n /** …and the bars behind it. */\r\n playedFill: paint(\"#6366f1\"),\r\n },\r\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\r\n load: (loader, state) => {\r\n loader.fill(state.fill)\r\n loader.fill(state.playedFill)\r\n },\r\n commands: {\r\n /**\r\n * Fill the waveform in, left to right — the node's one command, since\r\n * everything else about it is expressible as an ordinary `to`. Eased in-out\r\n * unless it is given an easing of its own.\r\n */\r\n sweep: (timeline, state) => {\r\n const ease = timeline.easing ? null : easeInOut()\r\n const from = state.progress\r\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\r\n },\r\n },\r\n render: (ctx, state) => {\r\n drawBars(ctx, state)\r\n ctx.children()\r\n },\r\n})\r\n\r\nexport type FullWaveform = NodeOf<typeof FullWaveform>\r\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\r\n\r\ninterface FullState {\r\n readonly envelope: AudioEnvelope\r\n readonly bars: number\r\n readonly gap: number\r\n readonly radius: number\r\n readonly progress: number\r\n readonly follow: boolean\r\n readonly gain: number\r\n readonly floor: number\r\n readonly align: WaveformAlignment\r\n readonly byVoice: boolean\r\n readonly voiceColors: string[]\r\n readonly fill: FillResolved[]\r\n readonly playedFill: FillResolved[]\r\n}\r\n\r\nfunction drawBars(ctx: RenderContext, s: FullState): void {\r\n const { width, height } = ctx.size\r\n if (width <= 0 || height <= 0) return\r\n\r\n const count = Math.max(1, Math.round(s.bars))\r\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\r\n const boxes = layOutBars(sampled, {\r\n width,\r\n height,\r\n gap: s.gap,\r\n align: s.align,\r\n gain: s.gain,\r\n floor: s.floor,\r\n })\r\n if (boxes.length === 0) return\r\n\r\n // One draw per colour rather than per bar — see {@link paintBars}. The key\r\n // is a string because it has to be comparable; the paint it stands for is\r\n // resolved after the grouping.\r\n const edge = played(ctx, s) * boxes.length\r\n const groups = groupByPaint(boxes, (i) =>\r\n s.byVoice\r\n ? `voice:${sampled[i].speaker}`\r\n : i < edge\r\n ? \"played\"\r\n : \"ahead\"\r\n )\r\n\r\n for (const [key, run] of groups) {\r\n const graphics = paintBars(run, paintFor(s, key), s.radius)\r\n if (graphics) ctx.draw(graphics)\r\n }\r\n}\r\n\r\n/** Where the fill has reached, from whichever source is in charge. */\r\nfunction played(ctx: RenderContext, s: FullState): number {\r\n if (!s.follow) return clamp01(s.progress)\r\n const length = s.envelope.duration\r\n if (length <= 0) return 0\r\n return clamp01(ctx.time.elapsed / length)\r\n}\r\n\r\n/**\r\n * The paint a group takes.\r\n *\r\n * A voice's colour is a **colour string**, never one of the node's two fill\r\n * props, and that is deliberate: a voice is identified by hue, so a gradient\r\n * or an image there would defeat the only thing the colour is for. It also\r\n * means these paints declare no assets, which is why `load` only has to account\r\n * for the two real fill props.\r\n */\r\nfunction paintFor(s: FullState, key: string): Fill {\r\n if (key === \"played\") return s.playedFill\r\n if (key === \"ahead\") return s.fill\r\n\r\n const voice = Number(key.slice(\"voice:\".length))\r\n if (!Number.isFinite(voice) || voice < 0) return s.fill\r\n return s.voiceColors[voice] ?? voiceColor(voice)\r\n}\r\n"]}
|
|
@@ -1,37 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps } from "@motionscript/sdk";
|
|
2
2
|
import { type AudioEnvelope } from "./envelope.js";
|
|
3
|
-
import { type WaveformAlignment, type WaveformStyle } from "./shared.js";
|
|
4
|
-
export interface LiveWaveformProps extends Node2DProps {
|
|
5
|
-
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
6
|
-
envelope: AudioEnvelope;
|
|
7
|
-
/** How many bars the visualiser is made of. */
|
|
8
|
-
bars: number;
|
|
9
|
-
/** Space between bars, as a fraction of the pitch. */
|
|
10
|
-
gap: number;
|
|
11
|
-
radius: number;
|
|
12
|
-
/** How many seconds of audio are on screen at once. */
|
|
13
|
-
window: number;
|
|
14
|
-
/** Seconds into the file the node's first frame shows. */
|
|
15
|
-
offset: number;
|
|
16
|
-
/** Advance with the scene clock. Off freezes the picture at {@link offset}. */
|
|
17
|
-
playing: boolean;
|
|
18
|
-
/** Multiplies every magnitude before it is clamped. */
|
|
19
|
-
gain: number;
|
|
20
|
-
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
21
|
-
floor: number;
|
|
22
|
-
align: WaveformAlignment;
|
|
23
|
-
style: WaveformStyle;
|
|
24
|
-
/**
|
|
25
|
-
* Show only this voice's activity, by index into the recording's own
|
|
26
|
-
* numbering. `-1` — the default — is every voice.
|
|
27
|
-
*/
|
|
28
|
-
speaker: number;
|
|
29
|
-
/** Colour each bar by whoever is speaking in it. */
|
|
30
|
-
byVoice: boolean;
|
|
31
|
-
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
32
|
-
voiceColors: string[];
|
|
33
|
-
fill: Fill;
|
|
34
|
-
}
|
|
35
3
|
/**
|
|
36
4
|
* A **live audio visualiser**: bars that move with the recording as it plays.
|
|
37
5
|
*
|
|
@@ -52,7 +20,7 @@ export interface LiveWaveformProps extends Node2DProps {
|
|
|
52
20
|
*
|
|
53
21
|
* ## The speaker filter
|
|
54
22
|
*
|
|
55
|
-
*
|
|
23
|
+
* `speaker` narrows the node to one voice of a diarized recording, and it
|
|
56
24
|
* is the reason this node knows about transcripts at all. Two visualisers beside
|
|
57
25
|
* two headshots, each filtered to its own host, is a podcast edit that would
|
|
58
26
|
* otherwise be done by hand for every turn — and because the filter *silences*
|
|
@@ -65,35 +33,67 @@ export interface LiveWaveformProps extends Node2DProps {
|
|
|
65
33
|
* true, where falling back to the unfiltered mix would be a silent lie about
|
|
66
34
|
* whose voice you were watching.
|
|
67
35
|
*/
|
|
68
|
-
export declare
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
36
|
+
export declare const LiveWaveform: import("@motionscript/sdk").Component<"liveWaveform", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
37
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
38
|
+
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
39
|
+
/** How many bars the visualiser is made of. */
|
|
40
|
+
readonly bars: 48;
|
|
41
|
+
/** Space between bars, as a fraction of the pitch. */
|
|
42
|
+
readonly gap: 0.35;
|
|
43
|
+
readonly radius: 4;
|
|
44
|
+
/** How many seconds of audio are on screen at once. */
|
|
45
|
+
readonly window: 3;
|
|
46
|
+
/** Seconds into the file the node's first frame shows. */
|
|
47
|
+
readonly offset: 0;
|
|
48
|
+
/** Advance with the scene clock. Off freezes the picture at `offset`. */
|
|
49
|
+
readonly playing: true;
|
|
50
|
+
/** Multiplies every magnitude before it is clamped. */
|
|
51
|
+
readonly gain: 1.4;
|
|
52
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
53
|
+
readonly floor: 0.04;
|
|
54
|
+
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
55
|
+
readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
|
|
56
|
+
/**
|
|
57
|
+
* Show only this voice's activity, by index into the recording's own
|
|
58
|
+
* numbering. `-1` — the default — is every voice.
|
|
59
|
+
*/
|
|
60
|
+
readonly speaker: -1;
|
|
61
|
+
/** Colour each bar by whoever is speaking in it. */
|
|
62
|
+
readonly byVoice: false;
|
|
63
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
64
|
+
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
65
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
66
|
+
}>, {}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
67
|
+
/** The baked recording. See {@link AudioEnvelope} for why it is baked. */
|
|
68
|
+
readonly envelope: import("@motionscript/sdk").Type<AudioEnvelope, AudioEnvelope, false>;
|
|
69
|
+
/** How many bars the visualiser is made of. */
|
|
70
|
+
readonly bars: 48;
|
|
71
|
+
/** Space between bars, as a fraction of the pitch. */
|
|
72
|
+
readonly gap: 0.35;
|
|
73
|
+
readonly radius: 4;
|
|
74
|
+
/** How many seconds of audio are on screen at once. */
|
|
75
|
+
readonly window: 3;
|
|
76
|
+
/** Seconds into the file the node's first frame shows. */
|
|
77
|
+
readonly offset: 0;
|
|
78
|
+
/** Advance with the scene clock. Off freezes the picture at `offset`. */
|
|
79
|
+
readonly playing: true;
|
|
80
|
+
/** Multiplies every magnitude before it is clamped. */
|
|
81
|
+
readonly gain: 1.4;
|
|
82
|
+
/** How much of the box a silent bar still occupies, `0`–`1`. */
|
|
83
|
+
readonly floor: 0.04;
|
|
84
|
+
readonly align: import("@motionscript/sdk").Type<"center" | "bottom", "center" | "bottom", false>;
|
|
85
|
+
readonly style: import("@motionscript/sdk").Type<"bars" | "line" | "blocks", "bars" | "line" | "blocks", false>;
|
|
85
86
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Off the node's own clock rather than the scene's, which is what "from the
|
|
89
|
-
* moment this node appeared" means — the same clock the engine's own
|
|
90
|
-
* `Video` times its picture from, and the same one that makes a node dropped
|
|
91
|
-
* halfway through a clip start its recording at its entrance rather than
|
|
92
|
-
* partway in.
|
|
87
|
+
* Show only this voice's activity, by index into the recording's own
|
|
88
|
+
* numbering. `-1` — the default — is every voice.
|
|
93
89
|
*/
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
readonly speaker: -1;
|
|
91
|
+
/** Colour each bar by whoever is speaking in it. */
|
|
92
|
+
readonly byVoice: false;
|
|
93
|
+
/** A colour per voice index. Short or empty falls back to the palette. */
|
|
94
|
+
readonly voiceColors: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
95
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
96
|
+
}>, null>>;
|
|
97
|
+
export type LiveWaveform = NodeOf<typeof LiveWaveform>;
|
|
98
|
+
export type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>;
|
|
99
99
|
//# sourceMappingURL=live-waveform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"live-waveform.d.ts","sourceRoot":"","sources":["../../src/waveform/live-waveform.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAGX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EACjC,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAA;AAYnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,YAAY;IAGrB,0EAA0E;;IAE1E,+CAA+C;;IAE/C,sDAAsD;;;IAGtD,uDAAuD;;IAEvD,0DAA0D;;IAE1D,yEAAyE;;IAEzE,uDAAuD;;IAEvD,gEAAgE;;;;IAIhE;;;OAGG;;IAEH,oDAAoD;;IAEpD,0EAA0E;;;;IA1B1E,0EAA0E;;IAE1E,+CAA+C;;IAE/C,sDAAsD;;;IAGtD,uDAAuD;;IAEvD,0DAA0D;;IAE1D,yEAAyE;;IAEzE,uDAAuD;;IAEvD,gEAAgE;;;;IAIhE;;;OAGG;;IAEH,oDAAoD;;IAEpD,0EAA0E;;;UAU5E,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA;AACtD,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
|