@webmusic/bridge 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,860 @@
1
+ import { ModuleControl, ProjectAssetReference, ModuleProject, ProjectJsonObject, ModuleHandle, NoteEvent, ModuleContext, AudioOutputPort, ProjectPluginFactory, ProjectConnector, ModuleEnvironment, WamPluginOptions, ProjectModuleRecord, ModuleProjectRuntime, ModuleAudioEnvironment } from '@webmusic/kernel/module';
2
+ import { ElementHeightFit } from '@webmusic/kernel/element';
3
+ import { Score } from '@webmusic/score';
4
+ import { AudioClip } from '@webmusic/audio';
5
+ import { ScoreEditor } from '@webmusic/score/view/headless';
6
+ import { SharedBuffers } from '@webmusic/audio/play/headless';
7
+ import { MidiAccessSource } from '@webmusic/score/play/headless';
8
+ import { ProcessorDefinition } from '@webmusic/kernel/processor';
9
+ export { THEME_TOKENS, ThemeToken, ThemeTokenKind, themeToken } from '@webmusic/ui';
10
+
11
+ interface ModuleControlView {
12
+ /** Bind to the module's current control (or none, while it is unresolved). */
13
+ refresh(next: ModuleControl | undefined): void;
14
+ destroy(): void;
15
+ }
16
+ /** The kinds of control a module may show; each is a UI Kit `/controls` presenter. */
17
+ declare const CONTROL_KINDS: readonly string[];
18
+ type Config = Readonly<Record<string, unknown>>;
19
+ /** Which control shows a module record, from its type and options; undefined for a module that shows none. */
20
+ declare function controlKindOf(record: {
21
+ readonly plugin: {
22
+ readonly id: string;
23
+ };
24
+ readonly config: Config;
25
+ }): string | undefined;
26
+ /**
27
+ * The natural size of a control of `kind`, in CSS pixels: the size of its
28
+ * box until the author resizes it. The module's options decide how many
29
+ * cells a matrix, a preset grid or tabs have, and how wide a message is.
30
+ */
31
+ declare function controlSize(kind: string, config?: Config): {
32
+ width: number;
33
+ height: number;
34
+ };
35
+ /** Mount the control of `kind` into `host`; the control fills the host. */
36
+ declare function mountModuleControl(host: HTMLElement, kind: string, options: {
37
+ cardHost?: HTMLElement;
38
+ label: string;
39
+ onError?: (error: unknown) => void;
40
+ }): ModuleControlView;
41
+
42
+ /** A port of a component, as a graph sees it. */
43
+ interface ComponentPort {
44
+ readonly id: string;
45
+ readonly family: 'audio' | 'note' | 'source' | 'message';
46
+ readonly direction: 'input' | 'output';
47
+ }
48
+ /** A port of a code-authored component, with the Element member that carries it. */
49
+ type ComponentPortBinding =
50
+ /** Audio in: the host connects the cord to an AnalyserNode and hands it to the Element's `analyser`. */
51
+ (ComponentPort & {
52
+ readonly family: 'audio';
53
+ readonly direction: 'input';
54
+ readonly bind: 'analyser';
55
+ readonly fftSize: number;
56
+ })
57
+ /** A source in: the host hands the upstream module to the Element's `inputModule`. */
58
+ | (ComponentPort & {
59
+ readonly family: 'source';
60
+ readonly direction: 'input';
61
+ readonly bind: 'inputModule';
62
+ })
63
+ /** A source in, for a panel: the host hands the upstream module to the Element's `moduleTarget`, whose parameters and inserts it edits. */
64
+ | (ComponentPort & {
65
+ readonly family: 'source';
66
+ readonly direction: 'input';
67
+ readonly bind: 'moduleTarget';
68
+ })
69
+ /**
70
+ * A source in, for a companion of an audio player: the host hands the
71
+ * upstream box's Element to `player`, which then plays through that player
72
+ * and its Session. With no cord it is linked to nothing, so it never plays
73
+ * by itself outside the graph.
74
+ */
75
+ | (ComponentPort & {
76
+ readonly family: 'source';
77
+ readonly direction: 'input';
78
+ readonly bind: 'player';
79
+ })
80
+ /** Audio in or out of an insert: the host connects the box's input to the Element's `input` and its `output` to the box's output, and gives it the graph's `context`. */
81
+ | (ComponentPort & {
82
+ readonly family: 'audio';
83
+ readonly bind: 'insert';
84
+ })
85
+ /** Notes in: the host hands the Element's `inputModule` a module whose `notes` output repeats the cords' notes. */
86
+ | (ComponentPort & {
87
+ readonly family: 'note';
88
+ readonly direction: 'input';
89
+ readonly bind: 'inputModule';
90
+ })
91
+ /** Notes out: the host forwards the note output port of the Element's `module`. */
92
+ | (ComponentPort & {
93
+ readonly family: 'note';
94
+ readonly direction: 'output';
95
+ readonly bind: 'module';
96
+ })
97
+ /** A source out: a cord hands the Element's `module` to the `inputModule` of the companion it reaches (DEC-063). */
98
+ | (ComponentPort & {
99
+ readonly family: 'source';
100
+ readonly direction: 'output';
101
+ readonly bind: 'module';
102
+ })
103
+ /**
104
+ * Audio out: the host lends the Element a module context with the graph's
105
+ * audio environment and Session, whose default destination is this port
106
+ * (DEC-084). A player in it joins the graph's Session; a desk's master plays into it.
107
+ */
108
+ | (ComponentPort & {
109
+ readonly family: 'audio';
110
+ readonly direction: 'output';
111
+ readonly bind: 'context';
112
+ })
113
+ /** Audio in: the host admits the cord's audio as one channel of the Element's `module`, labelled `channel`. */
114
+ | (ComponentPort & {
115
+ readonly family: 'audio';
116
+ readonly direction: 'input';
117
+ readonly bind: 'admit';
118
+ readonly channel: string;
119
+ });
120
+ /** A project asset the box's module loads and the host hands to an Element property. */
121
+ interface ComponentAsset {
122
+ /** The asset role in the module record; for `entries`, the prefix of its roles (`entry1`, `entry2`, …). */
123
+ readonly role: string;
124
+ /** What it loads as: a Score, an AudioClip, or every matching role as a playlist's `{id, label, clip}` entries, in role order. */
125
+ readonly kind: 'score' | 'clip' | 'entries';
126
+ /** The Element property the loaded value is assigned to. */
127
+ readonly property: string;
128
+ }
129
+ /** The project assets a host has for the music its components play, named by what each loads as. */
130
+ interface ComponentAssetSources {
131
+ /** The ID of the project asset a Score is loaded from. */
132
+ readonly score?: string;
133
+ /** The ID of the project asset an AudioClip is loaded from. */
134
+ readonly clip?: string;
135
+ /** The IDs of the project assets a playlist queues, in order; without it, `clip` once. */
136
+ readonly entries?: readonly string[];
137
+ }
138
+ /**
139
+ * The asset roles of a new box of a component (DEC-094): the `assets` of its
140
+ * module record, so the box plays the host's music instead of waiting. A
141
+ * manifest's `asset` says which role and what it loads as; the host says
142
+ * which of its project assets that is. Returns `undefined` for a component
143
+ * that plays no asset and for one whose kind the host gave no asset for.
144
+ *
145
+ * ```ts
146
+ * const assets = componentAssetRoles(manifest, {score: 'arabesque-midi', clip: 'arabesque-wav'});
147
+ * const record = {plugin: {id: manifest.plugin, version: COMPONENT_PLUGIN_VERSION}, config: {}, ...(assets && {assets})};
148
+ * ```
149
+ */
150
+ declare function componentAssetRoles(manifest: Pick<ComponentManifest, 'asset'>, sources: ComponentAssetSources): Readonly<Record<string, string>> | undefined;
151
+ /** A value set from the box's arguments, by position. */
152
+ interface ComponentParameter {
153
+ /** The key in the module's config. */
154
+ readonly name: string;
155
+ /** The argument's name in the box's usage. */
156
+ readonly label: string;
157
+ readonly kind: 'number' | 'word';
158
+ readonly fallback: number | string;
159
+ readonly min?: number;
160
+ readonly max?: number;
161
+ /** The Element attribute the value is written to. */
162
+ readonly attribute?: string;
163
+ /**
164
+ * The value names a shared buffer the host binds; empty binds nothing until
165
+ * a name is given. `true`: an `<audio-clip-view>` shows and edits it.
166
+ * `'clip'`: its samples are the Element's read-only `clip`. `'take'`: each
167
+ * take the Element records (`webaudio:recorded`) is written to it.
168
+ */
169
+ readonly buffer?: true | 'clip' | 'take';
170
+ /** The words a `word` parameter accepts; without it, any word. */
171
+ readonly choices?: readonly string[];
172
+ /** A comma-separated list, each item one of these words; empty is an empty list. */
173
+ readonly list?: readonly string[];
174
+ }
175
+ /** How an Element takes the height of a resized box (DEC-080). Selectors name public parts. */
176
+ /** How a component's Element is made as tall as its box: Kernel's fit, which an Element declares itself (DEC-094). */
177
+ type ComponentFit = ElementHeightFit;
178
+ /** A code-authored component: how a host places it in a graph. */
179
+ interface ComponentManifest {
180
+ /** The name typed into its box. */
181
+ readonly name: string;
182
+ readonly summary: string;
183
+ /** The custom element's tag. */
184
+ readonly tag: string;
185
+ /** The project plugin ID of its module in a graph. */
186
+ readonly plugin: string;
187
+ /** Its ports; with `portsFor`, the ports it has with every argument at its fallback. */
188
+ readonly ports: readonly ComponentPortBinding[];
189
+ /**
190
+ * Ports that follow the box's arguments (DEC-094), such as a desk's strips:
191
+ * given a config, the ports a box with it has. {@link manifestFor} applies it.
192
+ */
193
+ portsFor?(config: Readonly<Record<string, unknown>>): readonly ComponentPortBinding[];
194
+ readonly parameters: readonly ComponentParameter[];
195
+ /** The music it plays, when it plays a project asset; without the asset it waits (DEC-082). */
196
+ readonly asset?: ComponentAsset;
197
+ /** Lend the graph's module context on the box although no audio output needs it: the Element then works in the graph's AudioContext. */
198
+ readonly scope?: true;
199
+ /**
200
+ * An Element that works only inside another, as a declaration inside its
201
+ * owner: the host places it in this container, which the box holds. The
202
+ * manifest's attributes, settings and bindings apply to the inner Element;
203
+ * the container takes its own attributes and lends the inner one its scope.
204
+ */
205
+ readonly container?: {
206
+ readonly tag: string;
207
+ readonly attributes?: Readonly<Record<string, string>>;
208
+ define(): void;
209
+ };
210
+ /** Set Element properties a config describes but no attribute carries, after its parameters are applied. */
211
+ configure?(element: HTMLElement, config: Readonly<Record<string, unknown>>): void;
212
+ /**
213
+ * The host computes the Element's `.spectrogram` from the clip it shows —
214
+ * its own, or its player's — while its `type` is `spectrogram`, because the
215
+ * Element draws a spectrogram only from data given to it.
216
+ */
217
+ readonly spectrogram?: true;
218
+ /** Attributes the Element starts with in a graph; a setting may replace one (DEC-085). */
219
+ readonly attributes?: Readonly<Record<string, string>>;
220
+ /**
221
+ * Attributes a setting never writes: those the host needs as they are.
222
+ */
223
+ readonly locked?: readonly string[];
224
+ /** Natural width in CSS pixels; its natural height is its own. */
225
+ readonly width: number;
226
+ /**
227
+ * How it follows a resized box, in place of the fit its Element declares
228
+ * (DEC-094): given when the manifest holds the Element to one layout, as
229
+ * `keys` does. With neither it keeps its own height, and a box too small
230
+ * for it shows it scaled down (DEC-099).
231
+ */
232
+ readonly fit?: ComponentFit;
233
+ /**
234
+ * The Element shows music longer or wider than itself and scrolls it
235
+ * inside its own frame (DEC-099): notation, a piano roll, lanes of analysis
236
+ * over a score, a recording zoomed into. Every other component shows all
237
+ * of itself in whatever box it is given, and nothing in it scrolls.
238
+ */
239
+ readonly scrolls?: true;
240
+ /**
241
+ * Set when the Element edits a Score through `.editor` and `editable`
242
+ * (DEC-086): while its `editable` attribute is on, its box lends it the
243
+ * document of the box its `source` cord comes from.
244
+ */
245
+ readonly edits?: 'score';
246
+ /** Register the custom element; safe to call again. */
247
+ define(): void;
248
+ }
249
+ declare const KEYS_PLUGIN = "webmusic.surface.keys";
250
+ declare const SCOPE_PLUGIN = "webmusic.surface.scope";
251
+ declare const METER_PLUGIN = "webmusic.surface.meter";
252
+ declare const SPECTRUM_PLUGIN = "webmusic.surface.spectrum";
253
+ declare const ROLL_PLUGIN = "webmusic.surface.roll";
254
+ /** Components placed after DEC-081 take their plugin ID from their tag. */
255
+ declare const CLIP_PLUGIN = "webmusic.component.audio-clip-view";
256
+ declare const LEVEL_PLUGIN = "webmusic.component.audio-level-analyzer";
257
+ /** The packages' Components a graph can hold, in the order a library lists them. */
258
+ declare const OFFICIAL_COMPONENTS: readonly ComponentManifest[];
259
+ /** The manifest of a plugin ID, if it is an official component's. */
260
+ declare function componentManifestOf(plugin: string): ComponentManifest | undefined;
261
+ /**
262
+ * A manifest as it applies to one box (DEC-094): with `portsFor`, its ports
263
+ * are the ones the box's config gives; otherwise the manifest itself.
264
+ */
265
+ declare function manifestFor(manifest: ComponentManifest, config: Readonly<Record<string, unknown>>): ComponentManifest;
266
+ /** The manifest of a box name, if it names an official component. */
267
+ declare function findComponentManifest(name: string): ComponentManifest | undefined;
268
+ /**
269
+ * The ports of a component placed in a project, by what it is (DEC-081 rule 3,
270
+ * DEC-089): an official component's from its manifest, a graph-authored one's
271
+ * — a `NestedComponent` — from the channel kinds its options list, as `in<n>`
272
+ * and `out<n>`. Undefined for a module that is not a component. A host that
273
+ * connects components, such as an app's inspector (DEC-092), reads both the
274
+ * same way.
275
+ */
276
+ declare function componentPorts(record: {
277
+ readonly plugin: {
278
+ readonly id: string;
279
+ };
280
+ readonly config: Readonly<Record<string, unknown>>;
281
+ }): readonly ComponentPort[] | undefined;
282
+ /** True when a component only listens: its audio cords are sends, never a replaced route. */
283
+ declare function isListener(plugin: string): boolean;
284
+ /** A parameter's value from a config, or its fallback when absent or out of kind. */
285
+ declare function parameterValue(parameter: ComponentParameter, config: Readonly<Record<string, unknown>>): number | string;
286
+ /**
287
+ * A config from a box's argument words, by position. A number out of its
288
+ * range is clamped and a word that is not a number keeps the fallback; either
289
+ * is reported. Returns the config and the first problem, if any.
290
+ */
291
+ declare function configOfArguments(manifest: ComponentManifest, words: readonly string[]): {
292
+ config: Record<string, number | string>;
293
+ error?: string;
294
+ };
295
+ /** The usage shown for a component's box: its name and arguments with their fallbacks. */
296
+ declare function componentUsage(manifest: ComponentManifest): string;
297
+ /** What a graph-authored component offers a host: the ports its inlet and outlet modules make and the resources it loads. */
298
+ interface ProjectManifest {
299
+ readonly ports: readonly ComponentPort[];
300
+ readonly assets: readonly ProjectAssetReference[];
301
+ }
302
+ /**
303
+ * The manifest of a graph-authored component: the ports its inlet and outlet
304
+ * modules make (an inlet of index n is `in<n>`, an outlet `out<n>`, as a
305
+ * `NestedComponent` names them) and its assets. `contextId` picks the component's context; by
306
+ * default the project's top-level contexts.
307
+ */
308
+ declare function projectManifest(input: unknown, contextId?: string): ProjectManifest;
309
+ /** Plugin version of the components' modules. */
310
+ declare const COMPONENT_PLUGIN_VERSION = "1.0.0";
311
+ /**
312
+ * Move a buffer's waveform out of its box (DEC-081). Before the split a
313
+ * buffer placed in the presentation showed its samples; each such buffer
314
+ * gets a `clip` bound to its name, beside it on the canvas and in its place
315
+ * in the presentation. A project with no presented buffer is returned as
316
+ * it is, so running this again changes nothing.
317
+ */
318
+ declare function migrateBufferViews(input: unknown): ModuleProject;
319
+
320
+ /** A component's settings, as read from its module's config. */
321
+ interface ComponentSettings {
322
+ /** Attributes of the Element, by name. */
323
+ readonly attributes: Readonly<Record<string, string>>;
324
+ /** Custom properties set on the Element, by name. */
325
+ readonly style: Readonly<Record<string, string>>;
326
+ }
327
+ /** The keys of a module's config that hold its settings. */
328
+ type ComponentSettingKind = keyof ComponentSettings;
329
+ /**
330
+ * Attributes a graph owns on every component: where its material comes from,
331
+ * what it is connected to, and what identifies it. Cords, assets and the host
332
+ * decide these; a setting never does.
333
+ */
334
+ declare const GRAPH_ATTRIBUTES: readonly string[];
335
+ type Registry = Pick<CustomElementRegistry, 'get'>;
336
+ /**
337
+ * The attributes a setting may write on a component's Element: those the
338
+ * Element observes, less the graph's, the box arguments' and the manifest's
339
+ * locked ones. Empty until the Element is defined.
340
+ */
341
+ declare function settableAttributes(manifest: ComponentManifest, registry?: Registry): readonly string[];
342
+ /** True for a custom property and value a setting may write. */
343
+ declare function isStyleSetting(name: string, value: unknown): value is string;
344
+ /**
345
+ * Whose style something shows (DEC-090): its `own`, or, with `inherit`, that
346
+ * of what holds it — a box its component's theme, a component its app's.
347
+ * The choice is the author's, box by box and component by component; the
348
+ * style it sets aside is kept, so choosing `own` again brings it back.
349
+ */
350
+ type StyleSource = 'own' | 'inherit';
351
+ /** The style source a box's `config` chooses under `styling`; `own` unless it says `inherit`. */
352
+ declare function styleSource(config: Readonly<Record<string, unknown>>): StyleSource;
353
+ /** `config` with its style source chosen; `own` is the absence of the key. */
354
+ declare function withStyleSource(config: ProjectJsonObject, source: StyleSource): ProjectJsonObject;
355
+ /**
356
+ * True for an attribute that gives an Element one colour of its own: `color`,
357
+ * or a name ending in `-color` such as `note-color` or `wave-color`, as the
358
+ * packages' Elements name them. It is the attribute spelling of a style, so
359
+ * it is set aside with the style of a box that inherits (DEC-094). An
360
+ * attribute that chooses a kind of colouring (`scheme`, `color-map`,
361
+ * `color-mode`, a meter's `theme`) is what the Element does, and stays.
362
+ */
363
+ declare function isColorAttribute(name: string): boolean;
364
+ /**
365
+ * The settings in `config` that may be applied to the component's Element;
366
+ * anything else in `attributes` or `style` is left out without an error, so
367
+ * a project written for a later Element still loads. A box that inherits its
368
+ * style (DEC-090) has none of its own applied, nor a colour an attribute
369
+ * gives it ({@link isColorAttribute}); its other attributes stay.
370
+ */
371
+ declare function componentSettings(manifest: ComponentManifest, config: Readonly<Record<string, unknown>>, registry?: Registry): ComponentSettings;
372
+ /**
373
+ * `config` with one setting written, or removed when `value` is undefined.
374
+ * An empty `attributes` or `style` is dropped, so a component without
375
+ * settings has the config it had before it was given any.
376
+ */
377
+ declare function withComponentSetting(config: ProjectJsonObject, kind: ComponentSettingKind, name: string, value: string | undefined): ProjectJsonObject;
378
+
379
+ /** The `format` of a saved score. */
380
+ declare const SAVED_SCORE_FORMAT = "webmusic.score+json";
381
+ /** The `encoding` of a saved score. */
382
+ declare const SAVED_SCORE_ENCODING = "gzip+base64";
383
+ /** True where the platform can compress and inflate, which saving and restoring a score need. */
384
+ declare function canSaveScores(): boolean;
385
+ /**
386
+ * `score` as a box's config holds it, or undefined when it cannot be saved:
387
+ * the platform has no compression streams, or the result is too large for a
388
+ * project.
389
+ */
390
+ declare function encodeScore(score: Score): Promise<ProjectJsonObject | undefined>;
391
+ /**
392
+ * The Score a box's config holds under `document`. Rejects when the value is
393
+ * not a saved score, is too large, does not inflate, or is not a valid Score.
394
+ */
395
+ declare function decodeScore(value: unknown): Promise<Score>;
396
+
397
+ /** The custom properties in `style` that may be written: `--wm-` names with values that load nothing. */
398
+ declare function styleSettings(style: unknown): Readonly<Record<string, string>>;
399
+ /** The style a box's `config` gives it: its `style` as it may be written, or nothing while the box inherits (DEC-090). */
400
+ declare function ownStyle(config: Readonly<Record<string, unknown>>): Readonly<Record<string, string>>;
401
+ /** A component's theme: the entries of its project's `layout.style` that may be applied. */
402
+ declare function componentTheme(project: Pick<ModuleProject, 'layout'>): Readonly<Record<string, string>>;
403
+ /** `project` with one theme token written, or removed when `value` is undefined; an empty theme is dropped. */
404
+ declare function withComponentTheme(project: ModuleProject, name: string, value: string | undefined): ModuleProject;
405
+ /** `style` as CSS declarations; empty for no entries. */
406
+ declare function styleDeclarations(style: unknown): string;
407
+ /**
408
+ * Write `style` on `element` as custom properties and take back those an
409
+ * earlier call wrote that it no longer holds. Used for a box's own style
410
+ * and for a theme on a root the host owns.
411
+ */
412
+ declare function applyComponentStyle(element: HTMLElement, style: unknown): void;
413
+
414
+ /** One provided value, newest wins while it is provided. */
415
+ declare class Provided<T> {
416
+ #private;
417
+ get current(): T | undefined;
418
+ provide(value: T): () => void;
419
+ subscribe(listener: () => void): () => void;
420
+ }
421
+ /** One desk input offered to the Element: admit `port` as the channel of `module`. */
422
+ interface SurfaceChannel {
423
+ readonly module: ModuleHandle;
424
+ readonly port: AudioOutputPort;
425
+ }
426
+ /** One playlist entry the box loaded: an asset role, the file's name and its clip. */
427
+ interface SurfaceEntry {
428
+ readonly id: string;
429
+ readonly label: string;
430
+ readonly clip: AudioClip;
431
+ }
432
+ /** What one component's Element borrows, by module ID: one value per binding. */
433
+ declare class SurfaceSlot {
434
+ /** The analyser an audio input hands the Element's `analyser`. */
435
+ readonly analyser: Provided<AnalyserNode>;
436
+ /** The module a source input hands the Element's `inputModule`, through its `source` cord. */
437
+ readonly source: Provided<ModuleHandle>;
438
+ /** The note output of the newest module; the Element's `module` plays into it. */
439
+ readonly notes: Provided<(event: NoteEvent) => void>;
440
+ /** The module context lent to a player or desk: the graph's Session, with this box's output as its destination. */
441
+ readonly context: Provided<ModuleContext>;
442
+ /** A desk's inputs, which the Element admits as channels. */
443
+ readonly channels: Provided<readonly SurfaceChannel[]>;
444
+ /** A module whose `notes` output repeats the notes cabled to this box; the Element's `inputModule` listens to it. */
445
+ readonly noteSource: Provided<ModuleHandle>;
446
+ /** The asset the box loaded for the Element: a Score, an AudioClip, or a playlist's entries. */
447
+ readonly asset: Provided<Score | AudioClip | readonly SurfaceEntry[]>;
448
+ /** The Element's own module, provided by the host; a source cord from this box carries it. */
449
+ readonly element: Provided<ModuleHandle>;
450
+ /** An insert's ends: the graph's AudioContext, the node the box's input feeds and the node its output plays from. */
451
+ readonly insert: Provided<{
452
+ readonly context: BaseAudioContext;
453
+ readonly input: AudioNode;
454
+ readonly output: AudioNode;
455
+ }>;
456
+ /** The Element itself, provided by the host, for a companion that links to its player. */
457
+ readonly elementOwner: Provided<object>;
458
+ /** The Element of the box a `source` cord comes from, for a `player` binding. */
459
+ readonly sourceOwner: Provided<object>;
460
+ /** True when a source cord from this box carries the Element's module rather than the box's. */
461
+ forwardsElement: boolean;
462
+ /** The Score this box plays, when it plays one: what its document starts from. */
463
+ readonly score: Provided<Score>;
464
+ /** The document this box's score became once a view asked to edit it (DEC-086): the box plays it. */
465
+ readonly document: Provided<ScoreEditor>;
466
+ /**
467
+ * For a box with a source input: lends the document of the box its cord
468
+ * comes from, making it on the first call. A view calls it when it edits;
469
+ * it returns nothing while that box has no score.
470
+ */
471
+ readonly lender: Provided<() => ScoreEditor | undefined>;
472
+ }
473
+ /**
474
+ * What a box that plays a score holds: `original` its asset as loaded,
475
+ * `edited` a score that is saved with the box, `unsaved` an edited score
476
+ * that cannot be saved (too large for a project, or no compression here).
477
+ */
478
+ type ComponentDocumentState = 'original' | 'edited' | 'unsaved';
479
+ declare class ComponentSurfaces {
480
+ #private;
481
+ /**
482
+ * The document of the box `id`: the editor that owns the score it plays
483
+ * (DEC-086). Made from the box's score the first time it is asked for and
484
+ * kept while the box is in the graph, whatever is rebuilt; undefined while
485
+ * the box has no score. `peek` only looks.
486
+ */
487
+ document(id: string, peek?: boolean): ScoreEditor | undefined;
488
+ /**
489
+ * What the box `id` holds of the score it plays (DEC-087); undefined when
490
+ * it plays none.
491
+ */
492
+ documentState(id: string): ComponentDocumentState | undefined;
493
+ /**
494
+ * `config` as the box `id` is saved (DEC-087): with its edited score under
495
+ * `document`, and without one once the document is the asset again. A box
496
+ * nobody edited keeps the config it has. The newest edit is encoded off
497
+ * the call, so it is in the config once `settled` resolves; subscribers
498
+ * are told when it is.
499
+ */
500
+ withDocument(id: string, config: ProjectJsonObject): ProjectJsonObject;
501
+ /**
502
+ * Start the box `id` from the score its `config` saved (DEC-087). A
503
+ * document already edited here stays: it is newer than any config. Rejects
504
+ * with `ProjectModuleUnavailableError` when the saved score cannot be read,
505
+ * so the box stays unresolved with its config, and nothing is lost.
506
+ */
507
+ revive(id: string, config: ProjectJsonObject, signal?: AbortSignal): Promise<void>;
508
+ /**
509
+ * Give the box `id` its asset back (DEC-087): its edited document is let
510
+ * go and a new one, made from the score the box loaded, takes its place, so
511
+ * the box plays the asset at once and the views that edit borrow it. The
512
+ * box then saves no score. Nothing happens while the box has no document.
513
+ */
514
+ revert(id: string): void;
515
+ /**
516
+ * Let go of the document of the box `id`, or of every box, and make none.
517
+ * A host calls it before it shows another project, whose boxes may have
518
+ * the same IDs; `revert` is the one for a box that stays.
519
+ */
520
+ forget(id?: string): void;
521
+ /**
522
+ * Count a module of the box `id` as in a graph; call the result when it is
523
+ * disposed. A rebuild makes the new module before it disposes the old one,
524
+ * so the document goes only when the box itself does, and a new box that
525
+ * is given the same ID does not inherit it.
526
+ */
527
+ enter(id: string): () => void;
528
+ /** Told when what a box saves of its score changed: an edit, its encoding, a revert. */
529
+ subscribe(listener: () => void): () => void;
530
+ /** Resolves once every edit made so far is encoded, so `withDocument` holds it. */
531
+ settled(): Promise<void>;
532
+ slot(id: string): SurfaceSlot;
533
+ /** One plugin per official component's manifest. */
534
+ plugins(): readonly ProjectPluginFactory[];
535
+ /**
536
+ * The runtime connector for `source` cords: a source input follows the
537
+ * upstream module. From a player's box it follows the player's own module,
538
+ * which the host provides once the Element has one.
539
+ */
540
+ readonly connect: ProjectConnector;
541
+ }
542
+
543
+ /** Register the custom element of every official component; safe to call again. */
544
+ declare function defineComponentElements(): void;
545
+ /** A component's Element, configured from its module's config. */
546
+ declare function createComponentElement(manifest: ComponentManifest, config: ProjectJsonObject, document?: Document): HTMLElement;
547
+ /** The Element a manifest describes, inside the one a host placed: itself, or the declaration inside its container. */
548
+ declare function componentTarget(element: HTMLElement, manifest: ComponentManifest): HTMLElement;
549
+ /**
550
+ * Apply a config to a component's Element in place: its settings (DEC-085),
551
+ * each attribute over the manifest's own and each custom property on the
552
+ * Element, then each parameter to its attribute. A setting that is gone gives
553
+ * the attribute back to the manifest, or removes it.
554
+ */
555
+ declare function configureComponentElement(placed: HTMLElement, manifest: ComponentManifest, config: ProjectJsonObject): void;
556
+ /** True when a changed config needs a new binding, not only new attributes: a parameter the host binds, or ports that follow the config. */
557
+ declare function rebindsOnConfig(manifest: ComponentManifest): boolean;
558
+ interface ComponentBindOptions {
559
+ /** Runs inside a pointer or key gesture on the Element, so the caller can resume audio there. */
560
+ readonly onGesture?: () => void;
561
+ /** The shared buffers a buffer parameter names. */
562
+ readonly buffers?: {
563
+ readonly store: SharedBuffers;
564
+ readonly context: BaseAudioContext;
565
+ };
566
+ /** Let a shown buffer be edited and written back. */
567
+ readonly editableBuffers?: boolean;
568
+ readonly onError?: (error: unknown) => void;
569
+ }
570
+ /**
571
+ * Bind a component's Element to its slot through the members its manifest
572
+ * names: `analyser`, `inputModule` and the note output of `module`, and a
573
+ * shared buffer for a buffer parameter. A player or desk is lent the graph's
574
+ * module context on its box — the Element's parent, which must be there and
575
+ * should be bound before the Element connects — its desk inputs are admitted
576
+ * through `module`, its own `module` is what a source cord carries, and its
577
+ * asset is assigned to the property the manifest names. Returns the release
578
+ * function; take a player or desk off the page before calling it, so that
579
+ * losing the lent context does not make it start a Session of its own.
580
+ */
581
+ declare function bindComponentElement(element: HTMLElement, manifest: ComponentManifest, slot: SurfaceSlot, config: ProjectJsonObject, options?: ComponentBindOptions): () => void;
582
+ /**
583
+ * Make a component's Element as tall as its box (DEC-080): the part that
584
+ * draws takes the height its tools and readouts leave, and follows the box
585
+ * when it is resized. The fit is the one the Element declares (DEC-094), or
586
+ * the manifest's in its place; Kernel's `fitElementHeight` applies it. The
587
+ * element must already be inside the box, which sets its width.
588
+ *
589
+ * All of the component is shown whatever the box (DEC-099): one that cannot
590
+ * be laid out as small as its box — its drawing is at its least height, it
591
+ * has no fit and is taller, or what it holds is wider — is scaled down to
592
+ * it, so a box never cuts a component off and never has to be scrolled.
593
+ * Returns the release function, which gives the element its own size back.
594
+ */
595
+ declare function fitComponentElement(element: HTMLElement, manifest: ComponentManifest, box?: HTMLElement | null): () => void;
596
+ interface BufferViewOptions {
597
+ /** Allow editing; each committed edit is rendered and written back to the buffer. */
598
+ readonly editable?: boolean;
599
+ readonly onError?: (error: unknown) => void;
600
+ }
601
+ /**
602
+ * Show a named buffer in an `<audio-clip-view>`, following its changes. With
603
+ * `editable`, a committed edit is rendered and written back, so everything
604
+ * that plays the buffer hears it. Returns the release function.
605
+ */
606
+ declare function bindBufferView(element: HTMLElement, name: string, buffers: SharedBuffers, context: BaseAudioContext, options?: BufferViewOptions): () => void;
607
+
608
+ interface ComponentPluginOptions {
609
+ /** Where printing, script output and module failures go; see Kernel's `ModuleEnvironment`. */
610
+ readonly modules?: ModuleEnvironment;
611
+ /** The slots of the official components placed in a graph; omit for a component without them. */
612
+ readonly surfaces?: ComponentSurfaces;
613
+ /** Web MIDI for the MIDI modules; one is made when omitted. */
614
+ readonly midi?: MidiAccessSource;
615
+ /** Web Audio Modules: the host group and which URLs to load. Without it, `webmusic.wam` modules stay unresolved. */
616
+ readonly wam?: WamPluginOptions;
617
+ /** More factories, such as prepared DSP processors (`processorPlugin`). */
618
+ readonly extra?: readonly ProjectPluginFactory[];
619
+ }
620
+ /**
621
+ * Every plugin a component may use: the standard set of
622
+ * `createWebMusicProjectPlugins` — the Bridge's players, racks, effects and
623
+ * LFO with the module types Kernel, Score and Audio register — `mc.` effects,
624
+ * the official components (DEC-081), Web Audio Modules when configured, and
625
+ * `extra`.
626
+ */
627
+ declare function createComponentPlugins(options?: ComponentPluginOptions): readonly ProjectPluginFactory[];
628
+ /**
629
+ * Load a project asset by its URI, relative to `base` (the page by default):
630
+ * MIDI and MusicXML as a Score, audio files as an AudioClip. The media type
631
+ * decides when the file name does not. `embedded` maps an asset URI to a
632
+ * `data:` URI of its bytes, read in its place and by its media type alone.
633
+ * A project's own asset URIs stay short: its schema refuses long ones.
634
+ */
635
+ declare function resolveComponentAsset(asset: ProjectAssetReference, signal: AbortSignal, base?: string | URL, embedded?: Readonly<Record<string, string>>): Promise<unknown>;
636
+
637
+ interface MountComponentOptions extends Omit<ComponentPluginOptions, 'surfaces'> {
638
+ /** Replace the standard plugins entirely; `extra`, `midi`, `wam` and `modules` are then ignored. */
639
+ readonly plugins?: readonly ProjectPluginFactory[];
640
+ /** Load an asset; defaults to `resolveComponentAsset` relative to `base`. */
641
+ readonly resolveAsset?: (asset: ProjectAssetReference, signal: AbortSignal) => unknown | Promise<unknown>;
642
+ /** Base URL for asset URIs. Defaults to the page. */
643
+ readonly base?: string | URL;
644
+ /**
645
+ * Assets carried with the component (DEC-095): a project asset URI mapped
646
+ * to a `data:` URI of its bytes, read in place of the address. Ignored when
647
+ * `resolveAsset` is given.
648
+ */
649
+ readonly embedded?: Readonly<Record<string, string>>;
650
+ /** Lend an audio environment; by default the component owns one. */
651
+ readonly audio?: ModuleAudioEnvironment;
652
+ /** Let buffers shown by `clip` components be edited and written back. Default false. */
653
+ readonly editableBuffers?: boolean;
654
+ /** Label of the region. Defaults to the project ID. */
655
+ readonly label?: string;
656
+ /**
657
+ * Whose style the component shows (DEC-090): its `own` theme and its boxes'
658
+ * own styles, the default, or with `inherit` neither, so it takes the style
659
+ * of the page or app that holds it. `ComponentHandle.setStyling` changes it.
660
+ */
661
+ readonly styling?: StyleSource;
662
+ /**
663
+ * Where each shown box goes in a page the host lays out itself (DEC-092):
664
+ * given, the component draws no frame or stage of its own, and
665
+ * each box's Element is put in the element this returns for its record. A
666
+ * box given none is not shown. An official component fills the width of
667
+ * its place; a control keeps its own size. The theme is written
668
+ * on `host`.
669
+ */
670
+ readonly place?: (record: ProjectModuleRecord) => HTMLElement | null | undefined;
671
+ /**
672
+ * Start where the project's Session was when it was saved. By default a
673
+ * component starts at the beginning (DEC-094): where its author last
674
+ * stopped is the editor's state, not the component's.
675
+ */
676
+ readonly keepPosition?: boolean;
677
+ readonly onError?: (error: unknown) => void;
678
+ }
679
+ interface ComponentHandle {
680
+ readonly runtime: ModuleProjectRuntime;
681
+ /** Settles when the project is restored; rejects with the restore failure. */
682
+ readonly ready: Promise<void>;
683
+ /**
684
+ * The project as it stands: live parameter values and, in the config of
685
+ * each box that plays one, the score as its views edited it (DEC-087).
686
+ * Mounting what it resolves to gives the same component again.
687
+ */
688
+ save(): Promise<ModuleProject>;
689
+ /** Choose whose style the component shows (DEC-090), in place: nothing is rebuilt. */
690
+ setStyling(source: StyleSource): void;
691
+ /** Start the component's Session; call it from a user gesture so audio may start. */
692
+ play(): Promise<void>;
693
+ pause(): Promise<void>;
694
+ destroy(): void;
695
+ }
696
+ /**
697
+ * The frame `mountComponent` draws around a presentation (DEC-094, DEC-098),
698
+ * in CSS pixels: the rule around the contents, the height past which its
699
+ * stage scrolls, and the control height its contents are drawn with. The
700
+ * frame holds nothing but the contents — no transport and no room round them
701
+ * — so two boxes placed edge to edge stay edge to edge, and a box at the edge
702
+ * of the presentation meets the rule. Boxes are placed in pixels, so the
703
+ * frame sets `--wm-control-size` in pixels too: a strip is as high in a page
704
+ * with another root font size as it was where its author placed a box under
705
+ * it. A theme may set another size; a component that inherits its style
706
+ * takes the page's. An editor that shows the component as it will be exported
707
+ * reads them here, or asks {@link componentFrame}.
708
+ */
709
+ declare const COMPONENT_FRAME: Readonly<{
710
+ rule: 1;
711
+ maxStageHeight: 640;
712
+ controlSize: 32;
713
+ }>;
714
+ /** A rectangle in a presentation's coordinates. */
715
+ interface ComponentFrameRect {
716
+ readonly x: number;
717
+ readonly y: number;
718
+ readonly width: number;
719
+ readonly height: number;
720
+ }
721
+ interface ComponentFrameLayout {
722
+ /** The whole frame: the stage and the rule round it. */
723
+ readonly frame: ComponentFrameRect;
724
+ /** The stage as it is shown: at most `COMPONENT_FRAME.maxStageHeight` high. */
725
+ readonly stage: ComponentFrameRect;
726
+ /** How high the stage's contents are; more than `stage.height` when it scrolls. */
727
+ readonly contentHeight: number;
728
+ }
729
+ /**
730
+ * Where `mountComponent` draws its frame around boxes placed at these
731
+ * rectangles (DEC-098), in the same coordinates: the stage is the boxes'
732
+ * bounds, from the box furthest up and left to the one furthest down and
733
+ * right, and the rule runs round it. Give each box the size it is drawn at —
734
+ * the size its presentation gives it, or its rendered one. With no boxes the
735
+ * stage is empty at the origin. In a host narrower than the frame, the frame
736
+ * is as wide as the host instead.
737
+ */
738
+ declare function componentFrame(boxes: readonly ComponentFrameRect[]): ComponentFrameLayout;
739
+ /** One thing a level of a component shows, where its presentation puts it. */
740
+ interface ComponentContent {
741
+ readonly record: ProjectModuleRecord;
742
+ readonly x: number;
743
+ readonly y: number;
744
+ readonly width?: number;
745
+ readonly height?: number;
746
+ /** A module that shows a control, an official component, or a nested component set to show what it holds. */
747
+ readonly kind: 'control' | 'component' | 'nested';
748
+ }
749
+ /**
750
+ * What one level of a component shows (DEC-089): its controls, its
751
+ * official components and the nested components set to show what they hold,
752
+ * each where the presentation puts it — or, when nothing of that level is
753
+ * placed, where it sits on the canvas. `shell` names a nested component; by
754
+ * default the level is the component itself, everything not inside a nested
755
+ * one. Studio's boxes and `mountComponent` show the same things.
756
+ */
757
+ declare function componentContents(input: unknown, shell?: string): readonly ComponentContent[];
758
+ /**
759
+ * Preload a runtime's Session as members join it (DEC-069): the host owns that
760
+ * Session, so a placed player's sound, parameters and inserts are real before
761
+ * the first play. Kernel's `keepProjectSessionPreloaded` with the Score
762
+ * documents' wait (DEC-094); a runtime made with `preload` needs neither.
763
+ * Returns the release function.
764
+ */
765
+ declare function keepComponentSessionPreloaded(runtime: ModuleProjectRuntime, onError?: (error: unknown) => void): () => void;
766
+ /** Run `project` in `host` and show its presentation. */
767
+ declare function mountComponent(host: HTMLElement | ShadowRoot, input: unknown, options?: MountComponentOptions): ComponentHandle;
768
+ /**
769
+ * Define a custom element that runs `project`: each instance mounts it in its
770
+ * shadow root when connected and releases it when disconnected. Returns the
771
+ * element class; an already defined tag is left as it is.
772
+ */
773
+ declare function defineComponentElement(tag: string, project: unknown, options?: MountComponentOptions): CustomElementConstructor;
774
+
775
+ interface ComponentExportOptions {
776
+ /** The custom element's tag: lowercase, with a hyphen. */
777
+ readonly tag: string;
778
+ /** Plugin IDs the code supplies through `extra`; others not in the standard set are listed as resources to provide. */
779
+ readonly provided?: readonly string[];
780
+ }
781
+ interface ComponentPageOptions extends ComponentExportOptions {
782
+ readonly title?: string;
783
+ /** Where `@webmusic/bridge/component` loads from. Defaults to jsDelivr's ESM build of `version`. */
784
+ readonly moduleUrl?: string;
785
+ /** Package version for the default module URL. Defaults to the version of the `@webmusic/bridge` that writes the page. */
786
+ readonly version?: string;
787
+ /** Base URL that asset URIs resolve against in the page. Defaults to the page itself. */
788
+ readonly assetBase?: string;
789
+ }
790
+ /** Plugin IDs the standard component plugins provide. */
791
+ declare function standardPluginIds(): ReadonlySet<string>;
792
+ /**
793
+ * What a project needs beyond the packages: asset URIs it loads and plugin
794
+ * IDs the standard set does not provide (a prepared DSP processor, a WAM host).
795
+ */
796
+ declare function componentResources(input: unknown, provided?: readonly string[]): {
797
+ assets: readonly string[];
798
+ plugins: readonly string[];
799
+ };
800
+ /**
801
+ * A JavaScript module that defines `<tag>` for a project that installs the
802
+ * packages: `npm install @webmusic/kernel @webmusic/ui @webmusic/score
803
+ * @webmusic/audio @webmusic/bridge`, import the module, and write `<tag>`.
804
+ */
805
+ declare function componentModuleSource(input: unknown, options: ComponentExportOptions): string;
806
+ /** A standalone HTML page that runs the component from the published packages. */
807
+ declare function componentPageSource(input: unknown, options: ComponentPageOptions): string;
808
+ /** A DSP processor carried inside an exported file: its definition and its worklet module as text. */
809
+ interface EmbeddedProcessor {
810
+ readonly definition: ProcessorDefinition;
811
+ /** The worklet module, bundled into one script that imports nothing. */
812
+ readonly worklet: string;
813
+ }
814
+ interface ComponentStandaloneOptions extends ComponentExportOptions {
815
+ /**
816
+ * The text of `@webmusic/bridge/component/global`: the file
817
+ * `dist/component.global.js` of the installed `@webmusic/bridge`.
818
+ */
819
+ readonly runtime: string;
820
+ /** The page's title; the project's ID when omitted. Ignored by the module. */
821
+ readonly title?: string;
822
+ /**
823
+ * Assets to carry inside the file: a project asset URI mapped to a `data:`
824
+ * URI of its bytes (see {@link componentAssetDataUri}). The file hands them
825
+ * to the element as `embedded`; the project keeps its own URIs. An asset
826
+ * left out is loaded from its URI, relative to the page.
827
+ */
828
+ readonly assets?: Readonly<Record<string, string>>;
829
+ /** DSP processors to carry inside the file. Their plugins need no `extra`. */
830
+ readonly processors?: readonly EmbeddedProcessor[];
831
+ }
832
+ /** The media type an asset's file name implies, for the loaders `resolveComponentAsset` chooses between. */
833
+ declare function componentAssetMediaType(uri: string): string | undefined;
834
+ /**
835
+ * An asset's bytes as a `data:` URI to embed in an exported file. The media
836
+ * type is `type`, else what the URI's file name implies, so the right loader
837
+ * reads it back.
838
+ */
839
+ declare function componentAssetDataUri(uri: string, bytes: Uint8Array, type?: string): string;
840
+ /**
841
+ * The project plugin of a processor whose worklet module is text: the text
842
+ * becomes a Blob URL, made once per processor version and kept for the
843
+ * page's life, since a registered worklet module cannot be unloaded.
844
+ */
845
+ declare function embeddedProcessorPlugin(definition: ProcessorDefinition, worklet: string): ProjectPluginFactory;
846
+ /**
847
+ * A component complete in one HTML page: the runtime, the project, its
848
+ * embedded assets and processors. Open the file, or serve it from anywhere;
849
+ * it installs nothing and loads nothing it does not carry, apart from assets
850
+ * left out of `assets` and optional engines a feature may ask for.
851
+ */
852
+ declare function componentStandalonePageSource(input: unknown, options: ComponentStandaloneOptions): string;
853
+ /**
854
+ * A component complete in one JavaScript module: import the file, with a
855
+ * `<script type="module">` or a bundler, and write `<tag>`. It carries the
856
+ * runtime, so the project that uses it installs no package.
857
+ */
858
+ declare function componentStandaloneModuleSource(input: unknown, options: ComponentStandaloneOptions): string;
859
+
860
+ export { type BufferViewOptions, CLIP_PLUGIN, COMPONENT_FRAME, COMPONENT_PLUGIN_VERSION, CONTROL_KINDS, type ComponentAsset, type ComponentAssetSources, type ComponentBindOptions, type ComponentContent, type ComponentDocumentState, type ComponentExportOptions, type ComponentFit, type ComponentFrameLayout, type ComponentFrameRect, type ComponentHandle, type ComponentManifest, type ComponentPageOptions, type ComponentParameter, type ComponentPluginOptions, type ComponentPort, type ComponentPortBinding, type ComponentSettingKind, type ComponentSettings, type ComponentStandaloneOptions, ComponentSurfaces, type EmbeddedProcessor, GRAPH_ATTRIBUTES, KEYS_PLUGIN, LEVEL_PLUGIN, METER_PLUGIN, type ModuleControlView, type MountComponentOptions, OFFICIAL_COMPONENTS, type ProjectManifest, ROLL_PLUGIN, SAVED_SCORE_ENCODING, SAVED_SCORE_FORMAT, SCOPE_PLUGIN, SPECTRUM_PLUGIN, type StyleSource, type SurfaceChannel, type SurfaceEntry, SurfaceSlot, applyComponentStyle, bindBufferView, bindComponentElement, canSaveScores, componentAssetDataUri, componentAssetMediaType, componentAssetRoles, componentContents, componentFrame, componentManifestOf, componentModuleSource, componentPageSource, componentPorts, componentResources, componentSettings, componentStandaloneModuleSource, componentStandalonePageSource, componentTarget, componentTheme, componentUsage, configOfArguments, configureComponentElement, controlKindOf, controlSize, createComponentElement, createComponentPlugins, decodeScore, defineComponentElement, defineComponentElements, embeddedProcessorPlugin, encodeScore, findComponentManifest, fitComponentElement, isColorAttribute, isListener, isStyleSetting, keepComponentSessionPreloaded, manifestFor, migrateBufferViews, mountComponent, mountModuleControl, ownStyle, parameterValue, projectManifest, rebindsOnConfig, resolveComponentAsset, settableAttributes, standardPluginIds, styleDeclarations, styleSettings, styleSource, withComponentSetting, withComponentTheme, withStyleSource };