@motionscript/audio 0.0.0-stage → 0.1.0-alpha.10
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 +75 -0
- package/LICENSE +201 -0
- package/NOTICE +49 -0
- package/README.md +91 -3
- package/dist/browser/chunks/chunk-DD3KHRUL.js +2 -0
- package/dist/browser/chunks/chunk-DD3KHRUL.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/kit.d.ts +13 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +11 -0
- package/dist/kit.js.map +1 -0
- package/dist/nodes.d.ts +16 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +17 -0
- package/dist/nodes.js.map +1 -0
- package/dist/waveform/envelope.d.ts +120 -0
- package/dist/waveform/envelope.d.ts.map +1 -0
- package/dist/waveform/envelope.js +126 -0
- package/dist/waveform/envelope.js.map +1 -0
- package/dist/waveform/full-waveform.d.ts +118 -0
- package/dist/waveform/full-waveform.d.ts.map +1 -0
- package/dist/waveform/full-waveform.js +146 -0
- package/dist/waveform/full-waveform.js.map +1 -0
- package/dist/waveform/index.d.ts +23 -0
- package/dist/waveform/index.d.ts.map +1 -0
- package/dist/waveform/index.js +19 -0
- package/dist/waveform/index.js.map +1 -0
- package/dist/waveform/live-waveform.d.ts +129 -0
- package/dist/waveform/live-waveform.d.ts.map +1 -0
- package/dist/waveform/live-waveform.js +149 -0
- package/dist/waveform/live-waveform.js.map +1 -0
- package/dist/waveform/shared.d.ts +98 -0
- package/dist/waveform/shared.d.ts.map +1 -0
- package/dist/waveform/shared.js +149 -0
- package/dist/waveform/shared.js.map +1 -0
- package/package.json +72 -3
- package/registry.json +28 -0
- package/src/index.ts +2 -0
- package/src/kit.ts +22 -0
- package/src/nodes.ts +17 -0
- package/src/waveform/envelope.ts +176 -0
- package/src/waveform/full-waveform.ts +188 -0
- package/src/waveform/index.ts +30 -0
- package/src/waveform/live-waveform.ts +206 -0
- package/src/waveform/shared.ts +197 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @motionscript/audio
|
|
2
|
+
|
|
3
|
+
## 0.1.0-alpha.10
|
|
4
|
+
|
|
5
|
+
## 0.1.0-alpha.9
|
|
6
|
+
|
|
7
|
+
## 0.1.0-alpha.8
|
|
8
|
+
|
|
9
|
+
## 0.1.0-alpha.7
|
|
10
|
+
|
|
11
|
+
## 0.1.0-alpha.6
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 163b708: Node types are components: one spec object handed to `component2d`, `component3d` or `componentAudio`, with no classes, decorators or JSX.
|
|
16
|
+
|
|
17
|
+
- **Writing a node type.** A component is one object literal: `key`, `state` (literals and `Types`), `defaults`, `commands`, `children`, `allowedChildren`/`allowedParents`, `provide`, `load`, and its tree's own fields (`measure`, `layout`, `render` for 2D). Behaviour comes from modules you spread in and call: `Paint`, `Flow`, `Shapes`, `Typeface`, `TextLayout`, `Aim`, `Material`, `View3D`. ADR 0007 and the custom-node docs cover it.
|
|
18
|
+
- **Building nodes in code** uses calls: `Rect({ fill: 'tomato', children: [Text({ text: 'Hi' })] })`, or `new Rect({...})` for the node itself.
|
|
19
|
+
- **Every built-in and every kit node is a component**, under the same document key. Code that tested `instanceof` a class now uses the component's `.is`, or `instanceof X.node`. Changed members:
|
|
20
|
+
- `SurfacePlot3d.valueAt` and `FunctionPlot.valueAt` are now the functions `surfaceValueAt` and `curveValue`.
|
|
21
|
+
- A system's `coordinates` is replaced by `planeMap`/`axesMap`/`systemMap`.
|
|
22
|
+
- `PieChart.isSelected` is replaced by `isSliceSelected`.
|
|
23
|
+
- `ItemGrid` is a kit module (`ItemGrid.isGrid`, `ItemGrid.define`), not a base class.
|
|
24
|
+
- **The sdk no longer exports the class surface:**
|
|
25
|
+
- the decorators: `node`, `property` and every `*Property`, `command`, `withdraw`, `driveCommand`;
|
|
26
|
+
- the authoring bases: `PaintNode`, `ShapeNode`, `TextBase`, `Mesh3DBase`, `Canvas3DBase` and the `*Base` geometry classes;
|
|
27
|
+
- `asCommand`, `compose`, `drive` and `declarePaints` from `@motionscript/sdk/component`;
|
|
28
|
+
- the `jsx-runtime` and `jsx-dev-runtime` subpaths.
|
|
29
|
+
- `Node`, `Node2D`, `Node3D` and `NodeAudio` remain as types.
|
|
30
|
+
- **Editor metadata leaves the engine.** The kits no longer declare `parentKey`, `forkable`, `layout`, `seed`, `within`, `beside` or `closed`; a host keeps those in its own configs. `describe()` now reports `holds`, the trees a type takes children from, and the placement checks use it, so a 2D viewport of your own that takes 3D children places them.
|
|
31
|
+
- A command called from code with no argument runs, and a refused child is told what its parent takes (`allowedChildren`) or where it goes (`allowedParents`).
|
|
32
|
+
|
|
33
|
+
## 0.1.0-alpha.5
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- da6f97a: Every package ships a `NOTICE`, and a browser build lists what it bundles.
|
|
38
|
+
|
|
39
|
+
- Each tarball carries the repository `NOTICE`: the copyright line and the MIT attributions for the noise functions in `skia-render`'s fractal-noise fill (David Hoskins' "Hash without Sine", Inigo Quilez's 2D simplex noise).
|
|
40
|
+
- `@motionscript/canvaskit` ships `THIRD_PARTY_NOTICES.txt` with the licences of the libraries compiled into the binary: FreeType, HarfBuzz, ICU 74, zlib, libpng, Brotli, WOFF2, Emscripten and musl.
|
|
41
|
+
- `dist/browser/manifest.json` gains `thirdParty`, the packages the browser build bundled (`name`, `version`, `license`), and their licence and NOTICE files are written to `dist/browser/THIRD_PARTY_LICENSES.txt`. `@motionscript/browser` bundles mediabunny (MPL-2.0, unmodified; source at https://github.com/Vanilagy/mediabunny), esbuild-wasm and three; `@motionscript/math` bundles MathJax.
|
|
42
|
+
|
|
43
|
+
## 0.1.0-alpha.4
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- ad28707: Component kit fixes.
|
|
48
|
+
|
|
49
|
+
- Charts: a bar chart maps its columns across the plot panel as laid out (and takes the line chart's top headroom), so a column ends on its marker's grid line. A pie chart's wedges, labels and legend follow `data` and the palette once they are set. A restated value-axis or y/x-axis `range` or `ticks` in `to()` rescales continuously from the axis as drawn, instead of cutting at the midpoint. Without a legend (or without series) the entrance keeps that beat's share, so the call-out and legend land where the slot lays them out. A constant line series gets a scale with width, a `NaN` or infinite cell reads as 0, and tick captions gain decimals when the step is finer than 0.1.
|
|
50
|
+
- Code: the compiled highlighter is cached per style object, so two styles sharing a name no longer colour alike. A `CodeRanges` chain serialises as its ranges, so a stored `highlight` target selects what it did before it was saved.
|
|
51
|
+
- LaTeX: seeking from inside a morph to a time before it restores the source formula instead of leaving the last morph frame.
|
|
52
|
+
- Geo: custom border rings are wound for d3, so a GeoJSON counter-clockwise ring draws as the small region it encloses; a great-circle path between antipodal points runs over the north pole instead of wherever rounding lands.
|
|
53
|
+
- Audio: bottom-aligned waveform bars stand on the floor of the box instead of hanging from the top.
|
|
54
|
+
- `Code` and `Latex` take an optional props bag, so `new Registry({ nodes: NODES })` and `createBrowserEngine({ nodes: NODES })` type-check without a cast.
|
|
55
|
+
|
|
56
|
+
- e78f716: Kit gaps in waveforms, item grids, graphs and protein node.
|
|
57
|
+
|
|
58
|
+
- `@motionscript/audio`: documents that the host supplies the baked envelope and states its JSON form. `AudioEnvelope.magnitude` and `speaker` are typed `ArrayLike<number>`, which accepts the plain arrays a document stores as well as typed arrays. The package description no longer claims the meter responds to a signal.
|
|
59
|
+
- `@motionscript/grids`: the grids' descriptors name `children: "freeform"`, the one answer that is true of slot-placed children, in place of `flow` and `grid`.
|
|
60
|
+
- `@motionscript/molecule`: `Protein` refuses children, as its descriptor says, and declares `quality` non-animatable.
|
|
61
|
+
- `@motionscript/plot`: new `curveEquationIssues`, `surfaceEquationIssues` and `equationIssues` return a `ValidationIssue` for each equation whose expression does not compile and so is not drawn, which `validateDocument` cannot see. The `Canvas3D` scene props that `Graph3D` inherits and ignores are documented in its docs and a README.
|
|
62
|
+
|
|
63
|
+
## 0.1.0-alpha.3
|
|
64
|
+
|
|
65
|
+
## 0.1.0-alpha.2
|
|
66
|
+
|
|
67
|
+
## 0.1.0-alpha.1
|
|
68
|
+
|
|
69
|
+
### Minor Changes
|
|
70
|
+
|
|
71
|
+
- 59cecba: Build on `@motionscript/sdk` instead of `@motionscript/core`. The peer dependency is now `@motionscript/sdk`, every import goes through it (and `@motionscript/sdk/component` for the component machinery), and the browser build leaves `@motionscript/sdk` an import, so an import map names it once. A component copied with `ms add` imports the SDK too, and its registry item depends on `@motionscript/sdk` rather than `@motionscript/core`. `@motionscript/charts/kit` re-exports `@motionscript/sdk/component` where it re-exported `@motionscript/core/component`.
|
|
72
|
+
|
|
73
|
+
## 0.1.0-alpha.0
|
|
74
|
+
|
|
75
|
+
Initial release.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Motionscript
|
|
2
|
+
Copyright 2026 Motionscript LLC
|
|
3
|
+
|
|
4
|
+
This product includes the third-party code below, each part under the MIT
|
|
5
|
+
License reproduced at the end of this file.
|
|
6
|
+
|
|
7
|
+
- packages/renderer/crates/renderer/src/shaders/prim.wgsl (`fn_hash2`):
|
|
8
|
+
"Hash without Sine" by David Hoskins (https://www.shadertoy.com/view/4djSRW).
|
|
9
|
+
Copyright (c) 2014 David Hoskins.
|
|
10
|
+
|
|
11
|
+
- packages/renderer/crates/renderer/src/shaders/prim.wgsl (`simplex_noise`): "Noise - simplex - 2D" by Inigo Quilez
|
|
12
|
+
(https://www.shadertoy.com/view/Msf3WH). Copyright (c) 2013 Inigo Quilez.
|
|
13
|
+
|
|
14
|
+
- packages/renderer/crates/render3d (in @motionscript/renderer's WebAssembly):
|
|
15
|
+
its shaders (src/shaders/mesh.wgsl) port three.js r185's mesh programs and
|
|
16
|
+
src/geometry.rs its primitive generators (https://threejs.org).
|
|
17
|
+
Copyright (c) 2010-2026 three.js authors.
|
|
18
|
+
|
|
19
|
+
@motionscript/renderer's WebAssembly (dist/ms_renderer_bg.wasm) compiles in
|
|
20
|
+
Rust crates under MIT, Apache-2.0, Zlib and Unicode-3.0 terms (wgpu, naga,
|
|
21
|
+
harfrust, read-fonts, kurbo, wasm-bindgen and others); their notices are in
|
|
22
|
+
packages/renderer/THIRD_PARTY_NOTICES.txt.
|
|
23
|
+
|
|
24
|
+
MP3 export loads @mediabunny/mp3-encoder (MPL-2.0), a WebAssembly build of
|
|
25
|
+
the LAME MP3 encoder (LGPL, https://lame.sourceforge.io), on first use.
|
|
26
|
+
|
|
27
|
+
The browser builds under dist/browser/ bundle each package's npm dependencies;
|
|
28
|
+
dist/browser/THIRD_PARTY_LICENSES.txt in each package lists them with their
|
|
29
|
+
licences.
|
|
30
|
+
|
|
31
|
+
MIT License
|
|
32
|
+
|
|
33
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
34
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
35
|
+
in the Software without restriction, including without limitation the rights
|
|
36
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
37
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
38
|
+
furnished to do so, subject to the following conditions:
|
|
39
|
+
|
|
40
|
+
The above copyright notice and this permission notice shall be included in all
|
|
41
|
+
copies or substantial portions of the Software.
|
|
42
|
+
|
|
43
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
44
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
45
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
46
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
47
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
48
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
49
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @motionscript/audio
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Waveform components for [Motion Script](https://motionscript.dev): `fullWaveform`
|
|
4
|
+
draws a whole recording as bars with a played portion that advances, and
|
|
5
|
+
`liveWaveform` draws a meter that moves with playback.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { FullWaveform, LiveWaveform } from '@motionscript/audio';
|
|
9
|
+
|
|
10
|
+
export const nodes = [FullWaveform, LiveWaveform];
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## The host supplies the envelope
|
|
14
|
+
|
|
15
|
+
Nothing in the engine or in this package decodes audio. Both nodes draw the
|
|
16
|
+
loudness `envelope` they are handed in their `envelope` prop. A render has no
|
|
17
|
+
audio device and no analyser, so the picture has to be a pure function of time:
|
|
18
|
+
scrubbing backwards, jumping ahead and exporting frames out of order all draw the
|
|
19
|
+
same frame. Decoding a file into an envelope is the host's job, done once per
|
|
20
|
+
file before the document is built. The nodes declare no audio source and are not
|
|
21
|
+
tied to a clip: where a recording sits on the audio lane is the author's timing,
|
|
22
|
+
which is why `follow` is opt-in.
|
|
23
|
+
|
|
24
|
+
### The JSON form
|
|
25
|
+
|
|
26
|
+
A document stores the envelope as plain JSON:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"magnitude": [0, 0.25, 0.5, 1, 0.5, 0],
|
|
31
|
+
"duration": 6,
|
|
32
|
+
"speaker": [0, 0, 0, 1, 1, -1],
|
|
33
|
+
"speakers": 2
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- `magnitude`: peak loudness per bucket, `0` to `1`. The buckets divide
|
|
38
|
+
`duration` seconds evenly.
|
|
39
|
+
- `duration`: the recording's length in seconds.
|
|
40
|
+
- `speaker`: one voice index per bucket (parallel to `magnitude`), `-1` for
|
|
41
|
+
nobody identified, or `null` when the recording was never diarized.
|
|
42
|
+
- `speakers`: how many distinct voices there are; `0` when `speaker` is `null`.
|
|
43
|
+
|
|
44
|
+
`Float32Array` and `Int16Array` are accepted too, but `JSON.stringify` writes a
|
|
45
|
+
typed array as an object of indices, so a host that holds the typed form converts
|
|
46
|
+
with `Array.from` before it puts the envelope in a document.
|
|
47
|
+
|
|
48
|
+
## Nodes
|
|
49
|
+
|
|
50
|
+
| Key | Made for (w x h) | Commands | Notes |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| `fullWaveform` | 900 x 160 | `sweep` | whole recording; `progress` is the played share, or with `follow` the node's elapsed time over `envelope.duration`. `sweep` is a `to` of `progress` to 1 |
|
|
53
|
+
| `liveWaveform` | 420 x 220 | none | a `window` of seconds centred on `offset + elapsed` (or frozen at `offset` when `playing` is off); `style` is `bars`, `line` or `blocks`; `speaker` (-1 is every voice) filters to one voice |
|
|
54
|
+
|
|
55
|
+
Both take `byVoice` and `voiceColors` (a missing colour takes `VOICE_PALETTE`, eight
|
|
56
|
+
hues), and `align` of `center` or `bottom`. A voice colour is a plain string, never a
|
|
57
|
+
gradient or an image, so a voice declares no asset.
|
|
58
|
+
|
|
59
|
+
- **A column is the loudest bucket in it, not the mean** (`sampleEnvelope`), so
|
|
60
|
+
transients survive downsampling.
|
|
61
|
+
- **A silent bar is a hairline, never a hole**: every bar is at least 1 px wide and
|
|
62
|
+
tall, and the minimum height is taken before the bar is positioned, so it stays
|
|
63
|
+
inside the box.
|
|
64
|
+
- **Bars are batched by paint**, so two voices are two draws however long the
|
|
65
|
+
recording.
|
|
66
|
+
- **The frame is a function of the document and the node's clock**, so a seek redraws
|
|
67
|
+
what was drawn the first time.
|
|
68
|
+
|
|
69
|
+
## Entry points
|
|
70
|
+
|
|
71
|
+
`@motionscript/audio` exports the two nodes, `NODES`, the envelope type and
|
|
72
|
+
`EMPTY_ENVELOPE`, and the pure helpers (`sampleEnvelope`, `forSpeaker`, `layOutBars`,
|
|
73
|
+
`paintBars`, `groupByPaint`, `voiceColor`). `@motionscript/audio/kit` (`src/kit.ts`)
|
|
74
|
+
exports the same helpers plus `clamp01` and `livePaintKey`. A copy of `full-waveform` or
|
|
75
|
+
`live-waveform` (`registry.json`) takes three files into the project (`envelope.ts`,
|
|
76
|
+
`shared.ts` and the node); the copy's imports stay relative, so none is rewritten to
|
|
77
|
+
the kit specifier.
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install @motionscript/audio @motionscript/sdk
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
From the monorepo root:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm --filter @motionscript/audio build
|
|
91
|
+
pnpm --filter @motionscript/audio test
|
|
92
|
+
```
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var E={magnitude:new Float32Array(0),duration:0,speaker:null,speakers:0};function y(t,r,e,o){let n=Math.max(0,Math.floor(o)),a=new Array(n);for(let i=0;i<n;i++)a[i]={magnitude:0,speaker:-1};let l=t.magnitude.length;if(n===0||l===0||t.duration<=0)return a;let m=l/t.duration,s=(e-r)/n;for(let i=0;i<n;i++){let f=(r+s*i)*m,x=(r+s*(i+1))*m,p=Math.floor(f),u=Math.max(p,Math.ceil(x)-1),g=0,d=-1;for(let c=p;c<=u;c++){if(c<0||c>=l)continue;let h=t.magnitude[c];h<g||(g=h,d=t.speaker?t.speaker[c]:-1)}a[i]={magnitude:g,speaker:d}}return a}function A(t,r){return r===null?t:t.map(e=>e.speaker===r?e:{magnitude:0,speaker:e.speaker})}import{Graphics2D as w}from"@motionscript/sdk";var S=["center","bottom"],T=["bars","line","blocks"],M=["#6366f1","#14b8a6","#f59e0b","#ec4899","#22c55e","#3b82f6","#f97316","#a855f7"];function L(t){return M[(t%M.length+M.length)%M.length]}function _(t,r){let{width:e,height:o,gap:n,align:a,gain:l,floor:m}=r,s=t.length;if(s===0||e<=0||o<=0)return[];let i=e/s,f=Math.max(1,i*(1-k(n))),x=a==="center"?o/2:o,p=new Array(s);for(let u=0;u<s;u++){let g=k(t[u].magnitude*l),d=Math.max(x*k(m),x*g),c=-e/2+i*u+(i-f)/2,h=Math.max(1,a==="center"?d*2:d);p[u]=a==="center"?{x:c,y:-h/2,width:f,height:h}:{x:c,y:o/2-h,width:f,height:h}}return p}function b(t,r,e){if(t.length===0||r.length===0)return null;let o=new w;for(let n of t)o.rect({x:n.x+n.width/2,y:-(n.y+n.height/2),width:n.width,height:n.height,cornerRadius:Math.min(e,n.width/2,n.height/2)});return o.fill(r)}function B(t,r){let e=new Map;for(let o=0;o<t.length;o++){let n=r(o),a=e.get(n);a?a.push(t[o]):e.set(n,[t[o]])}return e}function k(t){return t<0?0:t>1?1:t}function F(t,r,e){return e!==null?`voice:${e}`:r?`voice:${t}`:"all"}export{E as a,y as b,A as c,S as d,T as e,M as f,L as g,_ as h,b as i,B as j,k,F as l};
|
|
2
|
+
//# sourceMappingURL=chunk-DD3KHRUL.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/waveform/envelope.ts", "../../../src/waveform/shared.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The shape of a recording, as the waveform nodes draw it.\n *\n * ## How an envelope reaches a node: the host supplies it\n *\n * Nothing in the engine, and nothing in this kit, decodes audio. A waveform node\n * does not read a `sound` node's `src`, declares no audio asset and is not tied\n * to a clip: it draws the {@link AudioEnvelope} it is handed in its `envelope`\n * prop. Decoding a file into an envelope is the host's job, done once per file\n * before the document is built. Where the recording sits on the audio lane is\n * the author's timing too, which is why `FullWaveform.follow` is opt-in.\n *\n * ### The JSON form\n *\n * A document holds the envelope as plain JSON, because a prop value in a\n * document is JSON. The typed arrays in {@link AudioEnvelope} are one spelling of\n * it; `ArrayLike<number>` also accepts the plain arrays a document stores:\n *\n * ```json\n * {\n * \"magnitude\": [0, 0.25, 0.5, 1, 0.5, 0],\n * \"duration\": 6,\n * \"speaker\": [0, 0, 0, 1, 1, -1],\n * \"speakers\": 2\n * }\n * ```\n *\n * `magnitude` is the peak loudness, `0`…`1`, of buckets that divide `duration`\n * seconds evenly. `speaker` is `null` when nobody was identified; otherwise it is parallel to `magnitude`, one voice\n * index per bucket, `-1` for \"nobody\". `speakers` is the voice count, `0` when\n * `speaker` is `null`. A `Float32Array` or `Int16Array` is not JSON-serialisable\n * (`JSON.stringify` writes an object of indices), so a host that holds the typed\n * form converts with `Array.from` before storing it in a document.\n *\n * ## Why the data is baked rather than listened to\n *\n * A scene has to render identically in the preview and in a headless export,\n * and an export has no audio device, no `AudioContext` and no playback to\n * analyse. So a \"live\" visualiser cannot read a Web Audio analyser: what it\n * reads is a *pre-computed envelope*, indexed by the scene clock. The picture is\n * then a pure function of time, which is what makes scrubbing backwards, jumping\n * to frame 900, and rendering out of order all produce the same frame.\n *\n * The decode happens in the host, once per file, and arrives here through the\n * build — the same arrangement a chart's rows and a protein's atoms already use,\n * and for the same reason: the build is synchronous and cannot await a fetch.\n *\n * ## Why magnitude rather than min/max\n *\n * An editor's waveform is drawn from per-bucket minima *and* maxima, because an\n * editor is a measuring instrument. These nodes are neither — they are a bar\n * chart of loudness that happens to be shaped like a recording — and audio is\n * near enough symmetric that a mirrored magnitude is indistinguishable at the\n * size a node draws. Half the numbers, and one array to reason about.\n */\n\n/**\n * A decoded recording, reduced to a uniform grid of loudness — plus, when the\n * host knows it, who is talking in each bucket.\n *\n * The speaker track is **not** something a decoder can produce; it comes from a\n * diarized transcript and is folded in by the host before the build. It lives\n * here rather than in a parallel structure because every reader of it is also a\n * reader of the magnitudes at the same index, and two arrays that must stay the\n * same length are better as one object than as two arguments.\n */\nexport interface AudioEnvelope {\n /**\n * Peak magnitude per bucket, 0…1. Buckets span {@link duration} evenly. A\n * `Float32Array`, or the plain `number[]` a document stores.\n */\n magnitude: ArrayLike<number>\n /** The decoded length in seconds. */\n duration: number\n /**\n * Which voice is speaking in each bucket, as an index into the recording's\n * own numbering, or `-1` for \"nobody identified\". Parallel to\n * {@link magnitude}, or `null` when the track was never diarized.\n */\n speaker: ArrayLike<number> | null\n /** How many distinct voices the diarizer found. Zero when it did not run. */\n speakers: number\n}\n\n/** The envelope of a track that hasn't loaded — or isn't there. */\nexport const EMPTY_ENVELOPE: AudioEnvelope = {\n magnitude: new Float32Array(0),\n duration: 0,\n speaker: null,\n speakers: 0,\n}\n\n/** One drawn bar: how loud, and whose. */\nexport interface EnvelopeBar {\n /** 0…1. */\n magnitude: number\n /** The voice index, or -1. */\n speaker: number\n}\n\n/**\n * Resamples `[from, to)` seconds of an envelope down to `bars` columns.\n *\n * Peak-preserving rather than averaging, which is the whole difference between\n * a waveform and a blur: averaging a hundred buckets into one column flattens\n * every transient, and transients are what makes a drawn recording read as\n * speech rather than as noise. The speaker of a column is the speaker of its\n * *loudest* bucket, on the same reasoning — a column straddling a turn belongs\n * to whoever is actually audible in it.\n *\n * A window past either end of the recording yields silent, unattributed\n * columns rather than clamping onto the nearest real one. That matters for the\n * live visualiser, which is handed a window centred on the playhead and would\n * otherwise smear the first bucket across the whole run-up to a track's start.\n */\nexport function sampleEnvelope(\n envelope: AudioEnvelope,\n from: number,\n to: number,\n bars: number\n): EnvelopeBar[] {\n const count = Math.max(0, Math.floor(bars))\n const out: EnvelopeBar[] = new Array(count)\n for (let i = 0; i < count; i++) out[i] = { magnitude: 0, speaker: -1 }\n\n const buckets = envelope.magnitude.length\n if (count === 0 || buckets === 0 || envelope.duration <= 0) return out\n\n const perSecond = buckets / envelope.duration\n const span = (to - from) / count\n\n for (let i = 0; i < count; i++) {\n const start = (from + span * i) * perSecond\n const end = (from + span * (i + 1)) * perSecond\n\n // At least one bucket per column, so a window zoomed in past the grid draws\n // the sample it is standing on rather than an empty band.\n const first = Math.floor(start)\n const last = Math.max(first, Math.ceil(end) - 1)\n\n let loudest = 0\n let speaker = -1\n for (let b = first; b <= last; b++) {\n if (b < 0 || b >= buckets) continue\n const value = envelope.magnitude[b]\n if (value < loudest) continue\n loudest = value\n speaker = envelope.speaker ? envelope.speaker[b] : -1\n }\n\n out[i] = { magnitude: loudest, speaker }\n }\n\n return out\n}\n\n/**\n * The same window, with everything that isn't `voice` silenced.\n *\n * The point of the speaker filter, and the reason it silences rather than\n * *drops*: a podcast visualiser filtered to one host should go quiet while the\n * other one talks, not compress their turn out of existence. Keeping the bars\n * and zeroing them is what makes the picture read as \"this person is not\n * speaking right now\" instead of as a jump cut.\n *\n * `voice` of `null` returns the bars untouched, which is the unfiltered node.\n */\nexport function forSpeaker(\n bars: EnvelopeBar[],\n voice: number | null\n): EnvelopeBar[] {\n if (voice === null) return bars\n return bars.map((bar) =>\n bar.speaker === voice ? bar : { magnitude: 0, speaker: bar.speaker }\n )\n}\n", "import { Graphics2D, type Fill, type FillResolved } from \"@motionscript/sdk\"\n\nimport type { EnvelopeBar } from \"./envelope\"\n\n/**\n * Geometry and paint shared by the two waveform nodes.\n *\n * They draw the same object — a row of bars whose heights are loudness — and\n * differ only in what decides the heights: the whole file for one, a window\n * around the playhead for the other. Everything about *how a row of bars is\n * laid out and painted* is therefore common, and lives here so the two cannot\n * drift into looking like different components.\n */\n\n/** How a bar is grown out of its baseline. */\nexport const WAVEFORM_ALIGNMENTS = [\"center\", \"bottom\"] as const\nexport type WaveformAlignment = (typeof WAVEFORM_ALIGNMENTS)[number]\n\n/** What the bars are shaped like. */\nexport const WAVEFORM_STYLES = [\"bars\", \"line\", \"blocks\"] as const\nexport type WaveformStyle = (typeof WAVEFORM_STYLES)[number]\n\n/**\n * The colours voices are drawn in when nobody has assigned any.\n *\n * Eight hues that can be told apart at a glance, handed out by voice index. They\n * are literals rather than looked up, because a scene has to build in a\n * headless render with no database in scope; a host that names its voices\n * supplies its own colours instead.\n */\nexport const VOICE_PALETTE = [\n \"#6366f1\",\n \"#14b8a6\",\n \"#f59e0b\",\n \"#ec4899\",\n \"#22c55e\",\n \"#3b82f6\",\n \"#f97316\",\n \"#a855f7\",\n] as const\n\n/** The colour a voice takes, wrapping past the end of the palette. */\nexport function voiceColor(index: number): string {\n return VOICE_PALETTE[\n ((index % VOICE_PALETTE.length) + VOICE_PALETTE.length) %\n VOICE_PALETTE.length\n ]\n}\n\n/**\n * Where one bar sits and how tall it came out: its top-left corner and size, in\n * the node's own pixels with **y pointing down** from the middle of the box.\n * {@link paintBars} turns that into the centred, y-up rect the renderer draws.\n */\nexport interface BarBox {\n x: number\n y: number\n width: number\n height: number\n}\n\n/**\n * Lays a row of bars out across a box.\n *\n * The gap is stated as a *fraction of the pitch* rather than in pixels, and\n * that is the one decision here worth stating out loud: the bar count is a\n * control, so a gap in pixels would silently become a solid block at 200 bars\n * and a picket fence at 20. As a fraction, the row keeps the same rhythm at\n * every density — which is what lets the count be a slider anyone can drag.\n *\n * A bar is never thinner than a hairline and never shorter than one either: a\n * silent passage has to read as \"audio, and nothing here\" rather than as a hole\n * in the drawing.\n */\nexport function layOutBars(\n bars: readonly EnvelopeBar[],\n options: {\n width: number\n height: number\n gap: number\n align: WaveformAlignment\n /** Multiplies every magnitude before it is clamped back into 0…1. */\n gain: number\n /** Fraction of the box a silent bar still occupies. */\n floor: number\n }\n): BarBox[] {\n const { width, height, gap, align, gain, floor } = options\n const count = bars.length\n if (count === 0 || width <= 0 || height <= 0) return []\n\n const pitch = width / count\n const barWidth = Math.max(1, pitch * (1 - clamp01(gap)))\n // The tallest a bar may be. Centre-aligned bars grow both ways from the\n // middle, so the *half* is what a magnitude of 1 fills.\n const full = align === \"center\" ? height / 2 : height\n\n const out: BarBox[] = new Array(count)\n for (let i = 0; i < count; i++) {\n const magnitude = clamp01(bars[i].magnitude * gain)\n const reach = Math.max(full * clamp01(floor), full * magnitude)\n const x = -width / 2 + pitch * i + (pitch - barWidth) / 2\n\n // A hairline minimum, taken before the position so the bar stays inside the\n // box: a silent bar 1px tall that kept the position of a zero-height one\n // would hang half a pixel (centred) or a whole pixel (bottom) outside it.\n const h = Math.max(1, align === \"center\" ? reach * 2 : reach)\n out[i] =\n align === \"center\"\n ? { x, y: -h / 2, width: barWidth, height: h }\n : { x, y: height / 2 - h, width: barWidth, height: h }\n }\n return out\n}\n\n/**\n * Draws a run of bars in one paint.\n *\n * Batched by colour by the caller, and this is why: every `Graphics2D` handed to\n * `ctx.draw` is a surface the renderer composites, so a bar apiece would be a\n * thousand surfaces a frame. Chaining the rects of one colour into a single\n * `Graphics2D` before filling makes it one — and, as a bonus, a gradient fill\n * maps across the whole run rather than restarting inside every bar, which is\n * the behaviour anyone reaching for a gradient here actually wants.\n */\nexport function paintBars(\n boxes: readonly BarBox[],\n fill: Fill,\n radius: number\n): Graphics2D | null {\n if (boxes.length === 0) return null\n if ((fill as FillResolved[]).length === 0) return null\n\n const graphics = new Graphics2D()\n for (const box of boxes) {\n graphics.rect({\n x: box.x + box.width / 2,\n // The box is stated y-down and the rect is drawn y-up. A centred bar is\n // symmetric about the middle, so only a bottom-aligned one shows the flip.\n y: -(box.y + box.height / 2),\n width: box.width,\n height: box.height,\n // Never rounder than the bar is wide, or a thin bar becomes a lozenge\n // whose ends taper away to nothing.\n cornerRadius: Math.min(radius, box.width / 2, box.height / 2),\n })\n }\n return graphics.fill(fill)\n}\n\n/**\n * Groups bars by the paint they take, preserving order within each group.\n *\n * The seam that makes {@link paintBars} worth batching: a diarized waveform has\n * as many colours as it has voices, not as many as it has bars, so a\n * conversation of two people is two draws however long it runs.\n */\nexport function groupByPaint<K>(\n boxes: readonly BarBox[],\n keyOf: (index: number) => K\n): Map<K, BarBox[]> {\n const groups = new Map<K, BarBox[]>()\n for (let i = 0; i < boxes.length; i++) {\n const key = keyOf(i)\n const run = groups.get(key)\n if (run) run.push(boxes[i])\n else groups.set(key, [boxes[i]])\n }\n return groups\n}\n\nexport function clamp01(value: number): number {\n return value < 0 ? 0 : value > 1 ? 1 : value\n}\n\n/**\n * The {@link groupByPaint} key one bar of a live visualiser takes.\n *\n * Filtered to one voice, every bar is that voice regardless of `byVoice` or\n * whose turn the bucket originally belonged to. That second part is the one\n * worth spelling out: {@link forSpeaker} silences a bar by zeroing its\n * magnitude but leaves `speaker` exactly as it was, so a bar sitting in the\n * middle of a *different* voice's turn is still stamped with that voice's\n * index — grouping by `byVoice`'s usual per-bar key would paint those silent\n * stretches in whoever used to be talking there, in flickers too short to\n * read as anything but noise. Forcing every bar under the filtered voice's own\n * key is the true picture instead: the node is drawing exactly one person, on\n * or off, never anyone else's colour.\n */\nexport function livePaintKey(\n barSpeaker: number,\n byVoice: boolean,\n filteredVoice: number | null\n): string {\n if (filteredVoice !== null) return `voice:${filteredVoice}`\n return byVoice ? `voice:${barSpeaker}` : \"all\"\n}\n"],
|
|
5
|
+
"mappings": "AAqFO,IAAMA,EAAgC,CAC3C,UAAW,IAAI,aAAa,CAAC,EAC7B,SAAU,EACV,QAAS,KACT,SAAU,GA0BN,SAAUC,EACdC,EACAC,EACAC,EACAC,EAAY,CAEZ,IAAMC,EAAQ,KAAK,IAAI,EAAG,KAAK,MAAMD,CAAI,CAAC,EACpCE,EAAqB,IAAI,MAAMD,CAAK,EAC1C,QAAS,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Q,EAAGA,EAAI,OAAS,CAAC,EAC7D,EAEH,OAAOD,EAAS,KAAKF,CAAI,CAC3B,CASM,SAAUI,EACdL,EACAM,EAA2B,CAE3B,IAAMC,EAAS,IAAI,IACnB,QAASZ,EAAI,EAAGA,EAAIK,EAAM,OAAQL,IAAK,CACrC,IAAMa,EAAMF,EAAMX,CAAC,EACbc,EAAMF,EAAO,IAAIC,CAAG,EACtBC,EAAKA,EAAI,KAAKT,EAAML,CAAC,CAAC,EACrBY,EAAO,IAAIC,EAAK,CAACR,EAAML,CAAC,CAAC,CAAC,CACjC,CACA,OAAOY,CACT,CAEM,SAAUf,EAAQkB,EAAa,CACnC,OAAOA,EAAQ,EAAI,EAAIA,EAAQ,EAAI,EAAIA,CACzC,CAgBM,SAAUC,EACdC,EACAC,EACAC,EAA4B,CAE5B,OAAIA,IAAkB,KAAa,SAASA,CAAa,GAClDD,EAAU,SAASD,CAAU,GAAK,KAC3C",
|
|
6
|
+
"names": ["EMPTY_ENVELOPE", "sampleEnvelope", "envelope", "from", "to", "bars", "count", "out", "buckets", "perSecond", "span", "start", "end", "first", "last", "loudest", "speaker", "b", "value", "forSpeaker", "voice", "bar", "Graphics2D", "WAVEFORM_ALIGNMENTS", "WAVEFORM_STYLES", "VOICE_PALETTE", "voiceColor", "index", "layOutBars", "bars", "options", "width", "height", "gap", "align", "gain", "floor", "count", "pitch", "barWidth", "clamp01", "full", "out", "i", "magnitude", "reach", "x", "paintBars", "boxes", "fill", "radius", "graphics", "box", "groupByPaint", "keyOf", "groups", "key", "run", "value", "livePaintKey", "barSpeaker", "byVoice", "filteredVoice"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as p,b as s,c as w,d as W,e as L,f as T,g as f,h as c,i as u,j as m,k as g,l as B}from"./chunks/chunk-DD3KHRUL.js";import{Types as M,component2d as C,easeInOut as S,fillOps as N}from"@motionscript/sdk";var P=o=>M.custom(o,{resolve:N.resolve,lerp:N.lerp}),O=C({key:"fullWaveform",state:{envelope:M.custom(p),bars:120,gap:.3,radius:2,progress:0,follow:!1,gain:1,floor:.015,align:M.custom("center"),byVoice:!1,voiceColors:M.custom([]),fill:P("#5b5b7a"),playedFill:P("#6366f1")},load:(o,e)=>{o.fill(e.fill),o.fill(e.playedFill)},commands:{sweep:(o,e)=>{let r=o.easing?null:S(),n=e.progress;return o.animate(t=>({progress:n+(1-n)*(r?r(t):t)}))}},render:(o,e)=>{_(o,e),o.children()}});function _(o,e){let{width:r,height:n}=o.size;if(r<=0||n<=0)return;let t=Math.max(1,Math.round(e.bars)),a=s(e.envelope,0,e.envelope.duration,t),l=c(a,{width:r,height:n,gap:e.gap,align:e.align,gain:e.gain,floor:e.floor});if(l.length===0)return;let v=A(o,e)*l.length,h=m(l,i=>e.byVoice?`voice:${a[i].speaker}`:i<v?"played":"ahead");for(let[i,y]of h){let E=u(y,Y(e,i),e.radius);E&&o.draw(E)}}function A(o,e){if(!e.follow)return g(e.progress);let r=e.envelope.duration;return r<=0?0:g(o.time.elapsed/r)}function Y(o,e){if(e==="played")return o.playedFill;if(e==="ahead")return o.fill;let r=Number(e.slice(6));return!Number.isFinite(r)||r<0?o.fill:o.voiceColors[r]??f(r)}import{Types as d,component2d as I,fillOps as x}from"@motionscript/sdk";var F=I({key:"liveWaveform",state:{envelope:d.custom(p),bars:48,gap:.35,radius:4,window:3,offset:0,playing:!0,gain:1.4,floor:.04,align:d.custom("center"),style:d.custom("bars"),speaker:-1,byVoice:!1,voiceColors:d.custom([]),fill:d.custom("#6366f1",{resolve:x.resolve,lerp:x.lerp})},load:(o,e)=>o.fill(e.fill),render:(o,e)=>{D(o,e),o.children()}});function z(o,e){return e.offset+(e.playing?Math.max(0,o.time.elapsed):0)}function D(o,e){let{width:r,height:n}=o.size;if(r<=0||n<=0)return;let t=Math.max(1,Math.round(e.bars)),a=Math.max(.05,e.window),l=z(o,e),v=e.speaker<0?null:Math.round(e.speaker),h=w(s(e.envelope,l-a/2,l+a/2,t),v),i=e.style==="line"?G(h):h,y=c(i,{width:r,height:n,gap:e.style==="blocks"?.12:e.gap,align:e.align,gain:e.gain,floor:e.floor});if(y.length===0)return;let E=m(y,b=>B(i[b].speaker,e.byVoice,v));for(let[b,V]of E){let k=u(V,R(e,b),e.radius);k&&o.draw(k)}}function R(o,e){if(e==="all")return o.fill;let r=Number(e.slice(6));return!Number.isFinite(r)||r<0?o.fill:o.voiceColors[r]??f(r)}function G(o){let e=o.length;if(e<3)return[...o];let r=Math.max(1,Math.floor(e/5));return o.map((n,t)=>{let a=Math.min(t,e-1-t),l=g(a/r);return{magnitude:n.magnitude*l,speaker:n.speaker}})}var K=[O,F];export{p as EMPTY_ENVELOPE,O as FullWaveform,F as LiveWaveform,K as NODES,T as VOICE_PALETTE,W as WAVEFORM_ALIGNMENTS,L as WAVEFORM_STYLES,w as forSpeaker,m as groupByPaint,c as layOutBars,u as paintBars,s as sampleEnvelope,f as voiceColor};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/waveform/full-waveform.ts", "../../src/waveform/live-waveform.ts", "../../src/nodes.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n Types,\n component2d,\n easeInOut,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { EMPTY_ENVELOPE, sampleEnvelope, type AudioEnvelope } from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n} from \"./shared\"\n\n/** A paint entry as the waveforms declare theirs: resolved and tweened like a fill, its kind read off the default. */\nconst paint = (initial: string) =>\n Types.custom<Fill, FillResolved[]>(initial, { resolve: fillOps.resolve, lerp: fillOps.lerp })\n\n/**\n * A **waveform overview**: the whole recording's shape, drawn at once.\n *\n * The picture every audio editor opens with, and the one a podcast clip puts\n * under its caption — a static silhouette of the file, with a played portion\n * that advances. It answers \"how long is this and where are the loud parts\",\n * which is a question about the *file*, not about the moment; its sibling\n * {@link LiveWaveform} answers the other one.\n *\n * ## Progress is authored, not assumed\n *\n * `follow` is off by default, and that default is the considered one. A\n * scene has no idea where the recording it is drawing sits on the video's audio\n * lane — a clip is placed, trimmed and sped up out there, and none of that is\n * visible from in here. So the honest default is that the fill is *animation*:\n * the author sweeps it with a command, the same as any other tween, and it lands\n * wherever they put it. `follow` is the shortcut for the common arrangement\n * where the node appears exactly as the track starts, and it says so by being a\n * switch someone has to turn on rather than a behaviour that quietly disagrees\n * with the mix.\n *\n * ## Voices instead of progress\n *\n * With `byVoice` on, the played/ahead split is replaced by one colour per\n * speaking voice, at a size you can read. For a two-hander it is a map of the conversation: who has the\n * floor, where the turns are, how long each one ran. It replaces the progress\n * colours rather than combining with them, because a bar cannot mean two things\n * at once and \"played, and also Grace\" is a legend nobody can hold in their\n * head.\n */\nexport const FullWaveform = component2d({\n key: \"fullWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many columns the whole file is drawn as. */\n bars: 120,\n /** Space between bars, as a fraction of the pitch. See {@link layOutBars}. */\n gap: 0.3,\n /** Corner radius of a bar, capped at half its width. */\n radius: 2,\n /** How much of the file reads as played, `0`–`1`. Tweenable. */\n progress: 0,\n /** Drive `progress` from the node's own clock instead of the prop. */\n follow: false,\n /** Multiplies every magnitude — a quiet track pulled up to fill its box. */\n gain: 1,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.015,\n align: Types.custom<WaveformAlignment>(\"center\"),\n /** Colour each voice's turns rather than splitting on played / not played. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n /** The bars ahead of the playhead. */\n fill: paint(\"#5b5b7a\"),\n /** …and the bars behind it. */\n playedFill: paint(\"#6366f1\"),\n },\n // Nothing declares a component's paints but itself: `fill` and `playedFill` both.\n load: (loader, state) => {\n loader.fill(state.fill)\n loader.fill(state.playedFill)\n },\n commands: {\n /**\n * Fill the waveform in, left to right — the node's one command, since\n * everything else about it is expressible as an ordinary `to`. Eased in-out\n * unless it is given an easing of its own.\n */\n sweep: (timeline, state) => {\n const ease = timeline.easing ? null : easeInOut()\n const from = state.progress\n return timeline.animate((t) => ({ progress: from + (1 - from) * (ease ? ease(t) : t) }))\n },\n },\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type FullWaveform = NodeOf<typeof FullWaveform>\nexport type FullWaveformProps = NonNullable<Parameters<typeof FullWaveform>[0]>\n\ninterface FullState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly progress: number\n readonly follow: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n readonly playedFill: FillResolved[]\n}\n\nfunction drawBars(ctx: RenderContext, s: FullState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const sampled = sampleEnvelope(s.envelope, 0, s.envelope.duration, count)\n const boxes = layOutBars(sampled, {\n width,\n height,\n gap: s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n // One draw per colour rather than per bar — see {@link paintBars}. The key\n // is a string because it has to be comparable; the paint it stands for is\n // resolved after the grouping.\n const edge = played(ctx, s) * boxes.length\n const groups = groupByPaint(boxes, (i) =>\n s.byVoice\n ? `voice:${sampled[i].speaker}`\n : i < edge\n ? \"played\"\n : \"ahead\"\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** Where the fill has reached, from whichever source is in charge. */\nfunction played(ctx: RenderContext, s: FullState): number {\n if (!s.follow) return clamp01(s.progress)\n const length = s.envelope.duration\n if (length <= 0) return 0\n return clamp01(ctx.time.elapsed / length)\n}\n\n/**\n * The paint a group takes.\n *\n * A voice's colour is a **colour string**, never one of the node's two fill\n * props, and that is deliberate: a voice is identified by hue, so a gradient\n * or an image there would defeat the only thing the colour is for. It also\n * means these paints declare no assets, which is why `load` only has to account\n * for the two real fill props.\n */\nfunction paintFor(s: FullState, key: string): Fill {\n if (key === \"played\") return s.playedFill\n if (key === \"ahead\") return s.fill\n\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\n}\n", "import {\n Types,\n component2d,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n type RenderContext,\n // Named so the emitted declaration reaches these through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport {\n EMPTY_ENVELOPE,\n forSpeaker,\n sampleEnvelope,\n type AudioEnvelope,\n type EnvelopeBar,\n} from \"./envelope\"\nimport {\n clamp01,\n groupByPaint,\n layOutBars,\n livePaintKey,\n paintBars,\n voiceColor,\n type WaveformAlignment,\n type WaveformStyle,\n} from \"./shared\"\n\n/**\n * A **live audio visualiser**: bars that move with the recording as it plays.\n *\n * The thing every podcast-to-video tool puts beside the artwork. It is not a\n * picture of the file — that is {@link FullWaveform} — it is a picture of *this\n * moment*, and what it is for is making a static frame of a talking head feel\n * like it is playing.\n *\n * ## \"Live\" without listening\n *\n * Nothing here reads an audio device. The bars are sampled out of a baked\n * envelope at the node's own elapsed time, which is what makes the visualiser\n * survive the thing it exists for: an **export**, where there is no playback to\n * analyse and frames may be rendered out of order or in parallel. A frame is a\n * pure function of its time, so scrubbing back and forth over the visualiser\n * redraws exactly what it drew the first time — which an analyser node, by\n * construction, cannot promise. See {@link AudioEnvelope}.\n *\n * ## The speaker filter\n *\n * `speaker` narrows the node to one voice of a diarized recording, and it\n * is the reason this node knows about transcripts at all. Two visualisers beside\n * two headshots, each filtered to its own host, is a podcast edit that would\n * otherwise be done by hand for every turn — and because the filter *silences*\n * rather than skips (see {@link forSpeaker}), the quiet host visibly stops\n * talking instead of vanishing. Nothing about that requires the words: only who\n * is talking when, which is what the diarizer produces.\n *\n * A filter naming a voice the recording doesn't have draws a resting row rather\n * than everything — a picture of \"this person never speaks here\", which is\n * true, where falling back to the unfiltered mix would be a silent lie about\n * whose voice you were watching.\n */\nexport const LiveWaveform = component2d({\n key: \"liveWaveform\",\n state: {\n /** The baked recording. See {@link AudioEnvelope} for why it is baked. */\n envelope: Types.custom<AudioEnvelope>(EMPTY_ENVELOPE),\n /** How many bars the visualiser is made of. */\n bars: 48,\n /** Space between bars, as a fraction of the pitch. */\n gap: 0.35,\n radius: 4,\n /** How many seconds of audio are on screen at once. */\n window: 3,\n /** Seconds into the file the node's first frame shows. */\n offset: 0,\n /** Advance with the scene clock. Off freezes the picture at `offset`. */\n playing: true,\n /** Multiplies every magnitude before it is clamped. */\n gain: 1.4,\n /** How much of the box a silent bar still occupies, `0`–`1`. */\n floor: 0.04,\n align: Types.custom<WaveformAlignment>(\"center\"),\n style: Types.custom<WaveformStyle>(\"bars\"),\n /**\n * Show only this voice's activity, by index into the recording's own\n * numbering. `-1` — the default — is every voice.\n */\n speaker: -1,\n /** Colour each bar by whoever is speaking in it. */\n byVoice: false,\n /** A colour per voice index. Short or empty falls back to the palette. */\n voiceColors: Types.custom<string[]>([]),\n fill: Types.custom<Fill, FillResolved[]>(\"#6366f1\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n },\n // Nothing declares a component's paints but itself.\n load: (loader, state) => loader.fill(state.fill),\n render: (ctx, state) => {\n drawBars(ctx, state)\n ctx.children()\n },\n})\n\nexport type LiveWaveform = NodeOf<typeof LiveWaveform>\nexport type LiveWaveformProps = NonNullable<Parameters<typeof LiveWaveform>[0]>\n\ninterface LiveState {\n readonly envelope: AudioEnvelope\n readonly bars: number\n readonly gap: number\n readonly radius: number\n readonly window: number\n readonly offset: number\n readonly playing: boolean\n readonly gain: number\n readonly floor: number\n readonly align: WaveformAlignment\n readonly style: WaveformStyle\n readonly speaker: number\n readonly byVoice: boolean\n readonly voiceColors: string[]\n readonly fill: FillResolved[]\n}\n\n/**\n * The second of the recording the visualiser is showing.\n *\n * Off the node's own clock rather than the scene's, which is what \"from the\n * moment this node appeared\" means — the same clock the engine's own\n * `Video` times its picture from, and the same one that makes a node dropped\n * halfway through a clip start its recording at its entrance rather than\n * partway in.\n */\nfunction at(ctx: RenderContext, s: LiveState): number {\n return s.offset + (s.playing ? Math.max(0, ctx.time.elapsed) : 0)\n}\n\nfunction drawBars(ctx: RenderContext, s: LiveState): void {\n const { width, height } = ctx.size\n if (width <= 0 || height <= 0) return\n\n const count = Math.max(1, Math.round(s.bars))\n const span = Math.max(0.05, s.window)\n const now = at(ctx, s)\n const voice = s.speaker < 0 ? null : Math.round(s.speaker)\n\n // The window is centred on the playhead, so the bars run *toward* the\n // middle and away again — the arrangement every mixer's meter uses, and the\n // one that reads as sound arriving rather than as a strip scrolling past.\n const sampled = forSpeaker(\n sampleEnvelope(s.envelope, now - span / 2, now + span / 2, count),\n voice\n )\n\n const shaped = s.style === \"line\" ? taper(sampled) : sampled\n const boxes = layOutBars(shaped, {\n width,\n height,\n gap: s.style === \"blocks\" ? 0.12 : s.gap,\n align: s.align,\n gain: s.gain,\n floor: s.floor,\n })\n if (boxes.length === 0) return\n\n const groups = groupByPaint(boxes, (i) =>\n livePaintKey(shaped[i].speaker, s.byVoice, voice)\n )\n\n for (const [key, run] of groups) {\n const graphics = paintBars(run, paintFor(s, key), s.radius)\n if (graphics) ctx.draw(graphics)\n }\n}\n\n/** See `FullWaveform`'s paints — a voice is a hue, never a gradient. */\nfunction paintFor(s: LiveState, key: string): Fill {\n if (key === \"all\") return s.fill\n const voice = Number(key.slice(\"voice:\".length))\n if (!Number.isFinite(voice) || voice < 0) return s.fill\n return s.voiceColors[voice] ?? voiceColor(voice)\n}\n\n/**\n * Rolls the ends of a window off toward silence.\n *\n * What separates the `line` style from `bars`: a hard-edged window makes the\n * loud bar entering at the right edge appear from nothing, which reads as a\n * glitch rather than as sound arriving. Fading the outer fifth turns the same\n * data into a shape that grows out of the baseline — the profile a spectrum\n * display has, and the reason it looks like one object rather than a row of\n * separate meters.\n */\nfunction taper(bars: readonly EnvelopeBar[]): EnvelopeBar[] {\n const count = bars.length\n if (count < 3) return [...bars]\n const edge = Math.max(1, Math.floor(count / 5))\n\n return bars.map((bar, i) => {\n const fromEnd = Math.min(i, count - 1 - i)\n const weight = clamp01(fromEnd / edge)\n return { magnitude: bar.magnitude * weight, speaker: bar.speaker }\n })\n}\n", "import { FullWaveform } from \"./waveform/full-waveform\";\nimport { LiveWaveform } from \"./waveform/live-waveform\";\n\n/**\n * Every node type this package publishes.\n *\n * A host registers these by handing the array to an engine —\n * `new Engine(platform, { nodes: NODES })` — which reads each component's key.\n * Defining a component only *declares* that key: nothing is registered by\n * importing a module, so a registry holds exactly what its owner asked for.\n *\n * Listing the component **values** is also what survives bundling: this package\n * declares `sideEffects: false`, and a document names a node type by string, so\n * an import kept only for its side effect is exactly what gets shaken out.\n */\n// Typed by name, so the declaration names each component rather than spelling out its type through core.\nexport const NODES: (typeof FullWaveform | typeof LiveWaveform)[] = [FullWaveform, LiveWaveform];\n"],
|
|
5
|
+
"mappings": "4HAAA,OACE,SAAAA,EACA,eAAAC,EACA,aAAAC,EACA,WAAAC,MAQK,oBAaP,IAAMC,EAASC,GACbC,EAAM,OAA6BD,EAAS,CAAE,QAASE,EAAQ,QAAS,KAAMA,EAAQ,IAAI,CAAE,EAgCjFC,EAAeC,EAAY,CACtC,IAAK,eACL,MAAO,CAEL,SAAUH,EAAM,OAAsBI,CAAc,EAEpD,KAAM,IAEN,IAAK,GAEL,OAAQ,EAER,SAAU,EAEV,OAAQ,GAER,KAAM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EAAE,YAAYM,CAAK,GAAKiB,EAAWjB,CAAK,CACjD,CAYA,SAASK,EAAMa,EAA4B,CACzC,IAAMrB,EAAQqB,EAAK,OACnB,GAAIrB,EAAQ,EAAG,MAAO,CAAC,GAAGqB,CAAI,EAC9B,IAAMC,EAAO,KAAK,IAAI,EAAG,KAAK,MAAMtB,EAAQ,CAAC,CAAC,EAE9C,OAAOqB,EAAK,IAAI,CAACE,EAAKV,IAAK,CACzB,IAAMW,EAAU,KAAK,IAAIX,EAAGb,EAAQ,EAAIa,CAAC,EACnCY,EAASC,EAAQF,EAAUF,CAAI,EACrC,MAAO,CAAE,UAAWC,EAAI,UAAYE,EAAQ,QAASF,EAAI,OAAO,CAClE,CAAC,CACH,CC7LO,IAAMI,EAAuD,CAACC,EAAcC,CAAY",
|
|
6
|
+
"names": ["Types", "component2d", "easeInOut", "fillOps", "paint", "initial", "Types", "fillOps", "FullWaveform", "component2d", "EMPTY_ENVELOPE", "loader", "state", "timeline", "ease", "easeInOut", "from", "ctx", "drawBars", "s", "width", "height", "count", "sampled", "sampleEnvelope", "boxes", "layOutBars", "edge", "played", "groups", "groupByPaint", "key", "run", "graphics", "paintBars", "paintFor", "clamp01", "length", "voice", "voiceColor", "Types", "component2d", "fillOps", "LiveWaveform", "component2d", "Types", "EMPTY_ENVELOPE", "fillOps", "loader", "state", "ctx", "drawBars", "at", "s", "width", "height", "count", "span", "now", "voice", "sampled", "forSpeaker", "sampleEnvelope", "shaped", "taper", "boxes", "layOutBars", "groups", "groupByPaint", "i", "livePaintKey", "key", "run", "graphics", "paintBars", "paintFor", "voiceColor", "bars", "edge", "bar", "fromEnd", "weight", "clamp01", "NODES", "FullWaveform", "LiveWaveform"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as E,b as e,c as o,d as r,e as a,f as p,g as l,h as t,i,j as O,k as P,l as T}from"./chunks/chunk-DD3KHRUL.js";export{E as EMPTY_ENVELOPE,p as VOICE_PALETTE,r as WAVEFORM_ALIGNMENTS,a as WAVEFORM_STYLES,P as clamp01,o as forSpeaker,O as groupByPaint,t as layOutBars,T as livePaintKey,i as paintBars,e as sampleEnvelope,l as voiceColor};
|
|
2
|
+
//# sourceMappingURL=kit.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export * from \"./waveform\"\nexport { NODES } from \"./nodes\";\n"]}
|
package/dist/kit.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the two waveform nodes share, importable without copying it.
|
|
3
|
+
*
|
|
4
|
+
* A registry item copies `envelope.ts` and `shared.ts` beside its node: they
|
|
5
|
+
* hold no class and no registered state, so a fork owning its own copy splits
|
|
6
|
+
* no identity. This is the same surface for a host that samples envelopes or
|
|
7
|
+
* lays bars out itself, and for a fork that keeps only its node file.
|
|
8
|
+
*/
|
|
9
|
+
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./waveform/envelope.js";
|
|
10
|
+
export type { AudioEnvelope, EnvelopeBar } from "./waveform/envelope.js";
|
|
11
|
+
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, clamp01, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
|
|
12
|
+
export type { BarBox, WaveformAlignment, WaveformStyle } from "./waveform/shared.js";
|
|
13
|
+
//# sourceMappingURL=kit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAChF,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA"}
|
package/dist/kit.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the two waveform nodes share, importable without copying it.
|
|
3
|
+
*
|
|
4
|
+
* A registry item copies `envelope.ts` and `shared.ts` beside its node: they
|
|
5
|
+
* hold no class and no registered state, so a fork owning its own copy splits
|
|
6
|
+
* no identity. This is the same surface for a host that samples envelopes or
|
|
7
|
+
* lays bars out itself, and for a fork that keeps only its node file.
|
|
8
|
+
*/
|
|
9
|
+
export { EMPTY_ENVELOPE, forSpeaker, sampleEnvelope } from "./waveform/envelope.js";
|
|
10
|
+
export { VOICE_PALETTE, WAVEFORM_ALIGNMENTS, WAVEFORM_STYLES, clamp01, groupByPaint, layOutBars, livePaintKey, paintBars, voiceColor, } from "./waveform/shared.js";
|
|
11
|
+
//# sourceMappingURL=kit.js.map
|