@braccato/core 2.0.0-beta.3 → 2.0.0-beta.5
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/README.md +80 -0
- package/js/renderer.js +9 -4
- package/package.json +1 -1
- package/pkg/braccato_core_rs.d.ts +5 -3
- package/pkg/braccato_core_rs.js +26 -3
- package/pkg/braccato_core_rs_bg.wasm +0 -0
- package/pkg/braccato_core_rs_bg.wasm.d.ts +1 -1
package/README.md
CHANGED
|
@@ -123,6 +123,7 @@ the line as it is:
|
|
|
123
123
|
--blyrics-line-hover-opacity: 1; /* over the distance opacity */
|
|
124
124
|
--blyrics-line-hover-blur: 0; /* over the distance blur; px, rem or blur(…) */
|
|
125
125
|
--blyrics-line-hover-scale: 1.04; /* over --blyrics-scale / --blyrics-active-scale */
|
|
126
|
+
--blyrics-line-hover-color: white; /* the words' inactive colour; the sung part keeps its own */
|
|
126
127
|
--blyrics-line-hover-duration: 0.2s;
|
|
127
128
|
--blyrics-line-hover-easing: ease;
|
|
128
129
|
}
|
|
@@ -130,6 +131,85 @@ the line as it is:
|
|
|
130
131
|
|
|
131
132
|
Touch has no hover, so a tap never leaves a line looking hovered.
|
|
132
133
|
|
|
134
|
+
A few more properties stand in for rules that styled lines and words by state:
|
|
135
|
+
|
|
136
|
+
```css
|
|
137
|
+
.blyrics-container {
|
|
138
|
+
/* other lines while the pointer is over the lyrics or a reader scrolls */
|
|
139
|
+
--blyrics-line-opacity-browsing: 0.5;
|
|
140
|
+
/* distance lists like the opacity ones, applied to the line's colours */
|
|
141
|
+
--blyrics-line-saturate-after: 1 0.9 0.8;
|
|
142
|
+
--blyrics-line-brightness-before: 1 0.8;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.blyrics--word {
|
|
146
|
+
/* a sung word, while its line is still being sung */
|
|
147
|
+
--blyrics-word-past-opacity: 0.6;
|
|
148
|
+
/* word-synced words wait here until sung, then rise out of it over their duration */
|
|
149
|
+
--blyrics-word-rest-transform: translateY(3px);
|
|
150
|
+
--blyrics-word-rise-extra-duration: 0.2s;
|
|
151
|
+
--blyrics-word-rise-easing: ease;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.blyrics--line, .blyrics--translated {
|
|
155
|
+
/* text-shadow's syntax; drawn once with the line, the same in every state */
|
|
156
|
+
--blyrics-text-shadow: 0 0.3rem 0.5rem rgb(0 0 0 / 0.15);
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The shadow, the past opacity and the rest pose are read from each element, so selectors scope them
|
|
161
|
+
as they do colours. The browsing opacity and the distance lists are read from the container.
|
|
162
|
+
|
|
163
|
+
Instrumental lines and the no-lyrics message, which themes restyled with `::before` and `::after`,
|
|
164
|
+
take these instead:
|
|
165
|
+
|
|
166
|
+
```css
|
|
167
|
+
.blyrics-container {
|
|
168
|
+
/* note (the default), dots (lit one after another in reading order), or text such as "♫" */
|
|
169
|
+
--blyrics-instrumental-icon: dots;
|
|
170
|
+
/* swells to this scale and back once a period while the instrumental plays */
|
|
171
|
+
--blyrics-instrumental-pulse-scale: 1.14;
|
|
172
|
+
--blyrics-instrumental-pulse-duration: 3s;
|
|
173
|
+
/* in place of the host's message when there are no lyrics, and text drawn above it */
|
|
174
|
+
--blyrics-no-lyrics-text: "No lyrics found";
|
|
175
|
+
--blyrics-no-lyrics-icon: "♫";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* the no-lyrics icon is an element of its own, 4em by default */
|
|
179
|
+
.blyrics-no-lyrics-icon { font-size: 6rem; }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
The wobble and the letter wave have a few more controls. A held word is one sung for longer than
|
|
183
|
+
`blyrics-long-word-threshold`, and with `blyrics-long-word-max-letters = 8;` one of at most 8
|
|
184
|
+
letters, so a long word like "everybody" is not one however long it is held.
|
|
185
|
+
`blyrics-letter-wave = long;` waves only held words; the rest move as one piece.
|
|
186
|
+
|
|
187
|
+
```css
|
|
188
|
+
.blyrics-container {
|
|
189
|
+
/* held words: the outermost letters move this far out at their crest, the rest in proportion */
|
|
190
|
+
--blyrics-letter-wave-spread: 0.04em;
|
|
191
|
+
/* held words that glow: each letter's glow up to 1 + this as bright at its crest */
|
|
192
|
+
--blyrics-letter-wave-glow: 0.8;
|
|
193
|
+
/* word (the default) or syllable: each syllable wobbles on its own, about its own centre */
|
|
194
|
+
--blyrics-word-wobble-scope: syllable;
|
|
195
|
+
/* the wobble lasts --blyrics-wobble-duration plus this many times the syllable's duration */
|
|
196
|
+
--blyrics-word-wobble-duration-ratio: 0.5;
|
|
197
|
+
/* any easing can be a linear() curve, such as a spring */
|
|
198
|
+
--blyrics-word-wobble-easing: linear(0, 0.6 20%, 1.08 40%, 0.98 65%, 1);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.blyrics--romanized {
|
|
202
|
+
/* the box behind romanization; transparent for none */
|
|
203
|
+
--blyrics-romanized-bg-color: transparent;
|
|
204
|
+
/* the box's padding and border-radius are the theme's own, as in the DOM renderer */
|
|
205
|
+
padding: 0;
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The glow peak brightens a glow up to its colour fully opaque, so it shows on a translucent glow
|
|
210
|
+
colour such as the default. A word's text-shadow moves with the word, but not with each letter's
|
|
211
|
+
wave.
|
|
212
|
+
|
|
133
213
|
## How it works
|
|
134
214
|
|
|
135
215
|
The lines are laid out by the browser in an invisible copy of `@braccato/core`'s markup, inside the
|
package/js/renderer.js
CHANGED
|
@@ -342,6 +342,9 @@ export function createLyricsRenderer(rendererOptions) {
|
|
|
342
342
|
return rust && attached ? rust.lineIndex(lyricElement) : -1;
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
+
/** The snapshot last handed to Rust. */
|
|
346
|
+
let sent = null;
|
|
347
|
+
|
|
345
348
|
// What the records and the module-level helpers reach this renderer through.
|
|
346
349
|
const view = {
|
|
347
350
|
indexOf,
|
|
@@ -362,6 +365,7 @@ export function createLyricsRenderer(rendererOptions) {
|
|
|
362
365
|
return index >= 0 ? rust.hangRomanization(index, text ?? undefined, timed ?? null) : false;
|
|
363
366
|
},
|
|
364
367
|
resetClock() {
|
|
368
|
+
sent = null;
|
|
365
369
|
rust?.resetClock();
|
|
366
370
|
},
|
|
367
371
|
canvas() {
|
|
@@ -379,9 +383,6 @@ export function createLyricsRenderer(rendererOptions) {
|
|
|
379
383
|
};
|
|
380
384
|
live.add(view);
|
|
381
385
|
|
|
382
|
-
/** The snapshot last handed to Rust. */
|
|
383
|
-
let sent = null;
|
|
384
|
-
|
|
385
386
|
function tick(currentTimeS, options) {
|
|
386
387
|
if (destroyed) return "lyrics-missing";
|
|
387
388
|
const resolved = resolveTickOptions(options ?? {});
|
|
@@ -443,12 +444,15 @@ export function createLyricsRenderer(rendererOptions) {
|
|
|
443
444
|
throw new Error("A lyrics renderer needs a mount: give one to createLyricsRenderer or to setLyrics");
|
|
444
445
|
}
|
|
445
446
|
ensure(nextMount);
|
|
446
|
-
rust.setLyrics(lyrics, {
|
|
447
|
+
const otherSong = rust.setLyrics(lyrics, {
|
|
447
448
|
noLyrics: options.noLyrics ?? false,
|
|
448
449
|
language: normalizeLanguage(options.language) || undefined,
|
|
449
450
|
songwriters: options.songwriters ? [...options.songwriters] : undefined,
|
|
450
451
|
songKey: options.songKey,
|
|
451
452
|
});
|
|
453
|
+
// The last snapshot was the old song's. Carried forward, or held by a stop at zero (the
|
|
454
|
+
// player between songs), it would scroll the new song to wherever the old one had got to.
|
|
455
|
+
if (otherSong) view.resetClock();
|
|
452
456
|
rust.container.dataset.loaderVisible = String(options.loaderVisible ?? false);
|
|
453
457
|
},
|
|
454
458
|
setLanguage(language) {
|
|
@@ -469,6 +473,7 @@ export function createLyricsRenderer(rendererOptions) {
|
|
|
469
473
|
if (destroyed || !rust) return;
|
|
470
474
|
rust.clear();
|
|
471
475
|
attached = false;
|
|
476
|
+
sent = null;
|
|
472
477
|
syncRecords();
|
|
473
478
|
},
|
|
474
479
|
destroy() {
|
package/package.json
CHANGED
|
@@ -72,9 +72,11 @@ export class Renderer {
|
|
|
72
72
|
*/
|
|
73
73
|
setLayout(layout: string): void;
|
|
74
74
|
/**
|
|
75
|
-
* The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters? }`.
|
|
75
|
+
* The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters?, songKey? }`.
|
|
76
|
+
* Returns whether it is another song rather than lyrics swapped into the one on screen, so a
|
|
77
|
+
* caller whose last snapshot was the old song's can forget it with `resetClock`.
|
|
76
78
|
*/
|
|
77
|
-
setLyrics(lyrics: any, options: any):
|
|
79
|
+
setLyrics(lyrics: any, options: any): boolean;
|
|
78
80
|
/**
|
|
79
81
|
* Binds a media element as the clock, or unbinds with `null`.
|
|
80
82
|
*/
|
|
@@ -182,7 +184,7 @@ export interface InitOutput {
|
|
|
182
184
|
readonly renderer_setHost: (a: number, b: any) => void;
|
|
183
185
|
readonly renderer_setLanguage: (a: number, b: number, c: number) => void;
|
|
184
186
|
readonly renderer_setLayout: (a: number, b: number, c: number) => void;
|
|
185
|
-
readonly renderer_setLyrics: (a: number, b: any, c: any) => [number, number];
|
|
187
|
+
readonly renderer_setLyrics: (a: number, b: any, c: any) => [number, number, number];
|
|
186
188
|
readonly renderer_setMedia: (a: number, b: number) => void;
|
|
187
189
|
readonly renderer_setProfiling: (a: number, b: number) => number;
|
|
188
190
|
readonly renderer_setScrollDetection: (a: number, b: number) => void;
|
package/pkg/braccato_core_rs.js
CHANGED
|
@@ -200,15 +200,19 @@ export class Renderer {
|
|
|
200
200
|
wasm.renderer_setLayout(this.__wbg_ptr, ptr0, len0);
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
* The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters? }`.
|
|
203
|
+
* The song. `lyrics` is a `Lyric[]`, `options` a `{ noLyrics?, language?, songwriters?, songKey? }`.
|
|
204
|
+
* Returns whether it is another song rather than lyrics swapped into the one on screen, so a
|
|
205
|
+
* caller whose last snapshot was the old song's can forget it with `resetClock`.
|
|
204
206
|
* @param {any} lyrics
|
|
205
207
|
* @param {any} options
|
|
208
|
+
* @returns {boolean}
|
|
206
209
|
*/
|
|
207
210
|
setLyrics(lyrics, options) {
|
|
208
211
|
const ret = wasm.renderer_setLyrics(this.__wbg_ptr, lyrics, options);
|
|
209
|
-
if (ret[
|
|
210
|
-
throw takeFromExternrefTable0(ret[
|
|
212
|
+
if (ret[2]) {
|
|
213
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
211
214
|
}
|
|
215
|
+
return ret[0] !== 0;
|
|
212
216
|
}
|
|
213
217
|
/**
|
|
214
218
|
* Binds a media element as the clock, or unbinds with `null`.
|
|
@@ -441,6 +445,9 @@ function __wbg_get_imports() {
|
|
|
441
445
|
__wbg_arcTo_a347b807c468785d: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
442
446
|
arg0.arcTo(arg1, arg2, arg3, arg4, arg5);
|
|
443
447
|
}, arguments); },
|
|
448
|
+
__wbg_arc_df3f7eb77e59876f: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5) {
|
|
449
|
+
arg0.arc(arg1, arg2, arg3, arg4, arg5);
|
|
450
|
+
}, arguments); },
|
|
444
451
|
__wbg_attachShader_3ed301cc92db59f6: function(arg0, arg1, arg2) {
|
|
445
452
|
arg0.attachShader(arg1, arg2);
|
|
446
453
|
},
|
|
@@ -1033,6 +1040,10 @@ function __wbg_get_imports() {
|
|
|
1033
1040
|
const ret = arg0.next();
|
|
1034
1041
|
return ret;
|
|
1035
1042
|
}, arguments); },
|
|
1043
|
+
__wbg_nodeType_5c5050c6571c3463: function(arg0) {
|
|
1044
|
+
const ret = arg0.nodeType;
|
|
1045
|
+
return ret;
|
|
1046
|
+
},
|
|
1036
1047
|
__wbg_now_043d245551b22f9c: function(arg0) {
|
|
1037
1048
|
const ret = arg0.now();
|
|
1038
1049
|
return ret;
|
|
@@ -1221,6 +1232,18 @@ function __wbg_get_imports() {
|
|
|
1221
1232
|
__wbg_set_scrollTop_a01ea28563affafe: function(arg0, arg1) {
|
|
1222
1233
|
arg0.scrollTop = arg1;
|
|
1223
1234
|
},
|
|
1235
|
+
__wbg_set_shadowBlur_85cdec581d1dc1d5: function(arg0, arg1) {
|
|
1236
|
+
arg0.shadowBlur = arg1;
|
|
1237
|
+
},
|
|
1238
|
+
__wbg_set_shadowColor_b938633d4fa98064: function(arg0, arg1, arg2) {
|
|
1239
|
+
arg0.shadowColor = getStringFromWasm0(arg1, arg2);
|
|
1240
|
+
},
|
|
1241
|
+
__wbg_set_shadowOffsetX_d90df5fa6efe0d44: function(arg0, arg1) {
|
|
1242
|
+
arg0.shadowOffsetX = arg1;
|
|
1243
|
+
},
|
|
1244
|
+
__wbg_set_shadowOffsetY_244217183c1e23d9: function(arg0, arg1) {
|
|
1245
|
+
arg0.shadowOffsetY = arg1;
|
|
1246
|
+
},
|
|
1224
1247
|
__wbg_set_src_da602cd25f3603f8: function(arg0, arg1, arg2) {
|
|
1225
1248
|
arg0.src = getStringFromWasm0(arg1, arg2);
|
|
1226
1249
|
},
|
|
Binary file
|
|
@@ -24,7 +24,7 @@ export const renderer_setHidden: (a: number, b: number) => void;
|
|
|
24
24
|
export const renderer_setHost: (a: number, b: any) => void;
|
|
25
25
|
export const renderer_setLanguage: (a: number, b: number, c: number) => void;
|
|
26
26
|
export const renderer_setLayout: (a: number, b: number, c: number) => void;
|
|
27
|
-
export const renderer_setLyrics: (a: number, b: any, c: any) => [number, number];
|
|
27
|
+
export const renderer_setLyrics: (a: number, b: any, c: any) => [number, number, number];
|
|
28
28
|
export const renderer_setMedia: (a: number, b: number) => void;
|
|
29
29
|
export const renderer_setProfiling: (a: number, b: number) => number;
|
|
30
30
|
export const renderer_setScrollDetection: (a: number, b: number) => void;
|