@braccato/core 1.20.0 → 1.21.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.
- package/README.md +40 -37
- package/dist/README.md +40 -37
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +10 -0
- package/dist/engine/animationConfig.d.ts +83 -0
- package/dist/engine/animationConfig.js +93 -0
- package/dist/engine/animationDrift.d.ts +11 -0
- package/dist/engine/animationDrift.js +43 -0
- package/dist/engine/animationTiming.d.ts +26 -0
- package/dist/engine/animationTiming.js +120 -0
- package/dist/engine/autoScroll.d.ts +24 -0
- package/dist/engine/autoScroll.js +103 -0
- package/dist/engine/clock.d.ts +29 -0
- package/dist/engine/clock.js +70 -0
- package/dist/engine/contextSweep.d.ts +10 -0
- package/dist/engine/contextSweep.js +102 -0
- package/dist/engine/cssValues.d.ts +13 -0
- package/dist/engine/cssValues.js +47 -0
- package/dist/engine/culling.d.ts +6 -0
- package/dist/engine/culling.js +76 -0
- package/dist/engine/debugOverlay.d.ts +14 -0
- package/dist/engine/debugOverlay.js +58 -0
- package/dist/engine/decorationSlides.d.ts +6 -0
- package/dist/engine/decorationSlides.js +53 -0
- package/dist/engine/elementMotion.d.ts +17 -0
- package/dist/engine/elementMotion.js +98 -0
- package/dist/engine/glow.d.ts +7 -0
- package/dist/engine/glow.js +59 -0
- package/dist/engine/instance.d.ts +105 -0
- package/dist/engine/instance.js +89 -0
- package/dist/engine/instrumentalAnimations.d.ts +7 -0
- package/dist/engine/instrumentalAnimations.js +59 -0
- package/dist/engine/letterPlans.d.ts +31 -0
- package/dist/engine/letterPlans.js +62 -0
- package/dist/engine/lineAnimationState.d.ts +10 -0
- package/dist/engine/lineAnimationState.js +82 -0
- package/dist/engine/lineAnimations.d.ts +5 -0
- package/dist/engine/lineAnimations.js +63 -0
- package/dist/engine/lineLifecycle.d.ts +12 -0
- package/dist/engine/lineLifecycle.js +92 -0
- package/dist/engine/lineScroll.d.ts +47 -0
- package/dist/engine/lineScroll.js +184 -0
- package/dist/engine/lineScrollStyle.d.ts +32 -0
- package/dist/engine/lineScrollStyle.js +133 -0
- package/dist/engine/liveViews.d.ts +3 -0
- package/dist/engine/liveViews.js +5 -0
- package/dist/engine/motionCurves.d.ts +19 -0
- package/dist/engine/motionCurves.js +85 -0
- package/dist/engine/motionPreference.d.ts +1 -0
- package/dist/engine/motionPreference.js +1 -0
- package/dist/engine/passiveScroll.d.ts +10 -0
- package/dist/engine/passiveScroll.js +93 -0
- package/dist/engine/renderedLines.d.ts +16 -0
- package/dist/engine/renderedLines.js +130 -0
- package/dist/engine/scrollViewport.d.ts +36 -0
- package/dist/engine/scrollViewport.js +104 -0
- package/dist/engine/stageMotion.d.ts +7 -0
- package/dist/engine/stageMotion.js +319 -0
- package/dist/engine/sweepPlans.d.ts +36 -0
- package/dist/engine/sweepPlans.js +59 -0
- package/dist/engine/tick.d.ts +16 -0
- package/dist/engine/tick.js +270 -0
- package/dist/engine/timingLogs.d.ts +7 -0
- package/dist/engine/timingLogs.js +81 -0
- package/dist/engine/userScroll.d.ts +12 -0
- package/dist/engine/userScroll.js +62 -0
- package/dist/engine/wavePool.d.ts +7 -0
- package/dist/engine/wavePool.js +22 -0
- package/dist/engine/wordAnimations.d.ts +5 -0
- package/dist/engine/wordAnimations.js +238 -0
- package/dist/imageHighlights.d.ts +0 -11
- package/dist/imageHighlights.js +2 -48
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/inject.d.ts +41 -2
- package/dist/inject.js +73 -28
- package/dist/renderer.js +10 -3
- package/dist/styles/image-highlights.css +1 -59
- package/dist/styles/lyrics.css +128 -57
- package/dist/types.d.ts +1 -1
- package/dist/view.d.ts +2 -2
- package/dist/view.js +7 -3
- package/package.json +1 -1
- package/dist/engine.d.ts +0 -471
- package/dist/engine.js +0 -3133
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { CREDITS_CLASS } from "../constants.js";
|
|
2
|
+
import { layoutStage, planStage, queuedStageY, stageTextSpan, } from "../stage.js";
|
|
3
|
+
import { getCSSNumber } from "./cssValues.js";
|
|
4
|
+
import { REDUCED_MOTION_QUERY } from "./motionPreference.js";
|
|
5
|
+
const STAGE_MOTION = { durationMs: 380, easing: "cubic-bezier(0.2, 0, 0, 1)" };
|
|
6
|
+
// Read by an important rule in stage.css, so a theme's own important opacity cannot reveal a line the stage
|
|
7
|
+
// is hiding or fading.
|
|
8
|
+
const STAGE_OPACITY_PROPERTY = "--blyrics-stage-opacity";
|
|
9
|
+
const STAGE_FADE_IN_MS = 300;
|
|
10
|
+
const STAGE_FADE_IN_DELAY_MS = 70;
|
|
11
|
+
const STAGE_FADE_OUT_MS = 220;
|
|
12
|
+
const HANDOFF_BLUR = "blur(3px)";
|
|
13
|
+
const STAGE_GAP_EM = 0.32;
|
|
14
|
+
const ELEMENT_NODE = 1;
|
|
15
|
+
const TEXT_NODE = 3;
|
|
16
|
+
const UNMEASURED = { height: 0, left: 0, width: 0, originX: 0 };
|
|
17
|
+
const stageOpacityRegistrations = new WeakSet();
|
|
18
|
+
export function applyStage(engine, timeS, instant) {
|
|
19
|
+
const container = engine.lyricsContainer;
|
|
20
|
+
if (!container)
|
|
21
|
+
return;
|
|
22
|
+
registerStageOpacity(engine);
|
|
23
|
+
const { elements, items } = stageElements(engine);
|
|
24
|
+
const roles = planStage(items, timeS);
|
|
25
|
+
const key = roles.join(",");
|
|
26
|
+
if (key === engine.stageKey && !instant)
|
|
27
|
+
return;
|
|
28
|
+
engine.stageKey = key;
|
|
29
|
+
const remeasured = engine.stageRemeasured;
|
|
30
|
+
engine.stageRemeasured = false;
|
|
31
|
+
const metrics = elements.map(element => engine.stageMetrics.get(element) ?? UNMEASURED);
|
|
32
|
+
const geometry = {
|
|
33
|
+
stageHeight: container.clientHeight,
|
|
34
|
+
gap: engine.stageFontSize * STAGE_GAP_EM,
|
|
35
|
+
activeScale: getCSSNumber(engine, container, "--blyrics-active-scale", 1),
|
|
36
|
+
};
|
|
37
|
+
const floorShift = remeasured && engine.stageHeight > 0 ? geometry.stageHeight - engine.stageHeight : 0;
|
|
38
|
+
engine.stageHeight = geometry.stageHeight;
|
|
39
|
+
const previousYs = elements.map(element => {
|
|
40
|
+
const y = engine.stageY.get(element);
|
|
41
|
+
return y === undefined ? null : y + floorShift;
|
|
42
|
+
});
|
|
43
|
+
const { placements, box } = layoutStage(roles, items, metrics, previousYs, geometry);
|
|
44
|
+
const moves = prepareStageMoves(engine, elements, roles, placements, metrics, geometry, { remeasured, instant });
|
|
45
|
+
const reduced = engine.window.matchMedia(REDUCED_MOTION_QUERY).matches;
|
|
46
|
+
elements.forEach((element, index) => {
|
|
47
|
+
if (element.dataset.stageRole !== roles[index])
|
|
48
|
+
element.dataset.stageRole = roles[index];
|
|
49
|
+
});
|
|
50
|
+
for (const move of moves)
|
|
51
|
+
placeStageElement(engine, move, instant, reduced);
|
|
52
|
+
if (!sameBox(box, engine.stageBox)) {
|
|
53
|
+
engine.stageBox = box;
|
|
54
|
+
engine.host.onStageLayout?.(box);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function prepareStageMoves(engine, elements, roles, placements, metrics, geometry, { remeasured, instant }) {
|
|
58
|
+
const moves = [];
|
|
59
|
+
elements.forEach((element, index) => {
|
|
60
|
+
const placement = placements[index];
|
|
61
|
+
const role = element.dataset.stageRole;
|
|
62
|
+
const previousY = engine.stageY.get(element);
|
|
63
|
+
const wasVisible = role !== undefined && isStageRoleVisible(role);
|
|
64
|
+
const onScreen = placement.visible || element.dataset.stageVisible !== undefined;
|
|
65
|
+
if (remeasured && !instant && onScreen && role === roles[index]) {
|
|
66
|
+
if (previousY !== placement.y)
|
|
67
|
+
snapStageElement(engine, element, placement.y);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const unchanged = previousY !== undefined && wasVisible === placement.visible && (!placement.visible || previousY === placement.y);
|
|
71
|
+
if (unchanged && !instant)
|
|
72
|
+
return;
|
|
73
|
+
const risesFromBelowFloor = role === "queued" && placement.visible;
|
|
74
|
+
moves.push({
|
|
75
|
+
element,
|
|
76
|
+
placement,
|
|
77
|
+
wasVisible,
|
|
78
|
+
fromY: risesFromBelowFloor
|
|
79
|
+
? queuedStageY(geometry.stageHeight, metrics[index].height, geometry.gap)
|
|
80
|
+
: currentTranslateY(engine, element, previousY ?? placement.y),
|
|
81
|
+
fromOpacity: Number(engine.window.getComputedStyle(element).opacity) || 0,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return moves;
|
|
85
|
+
}
|
|
86
|
+
function placeStageElement(engine, { element, placement, wasVisible, fromY, fromOpacity }, instant, reduced) {
|
|
87
|
+
engine.stageMoves.get(element)?.cancel();
|
|
88
|
+
engine.stageFades.get(element)?.cancel();
|
|
89
|
+
engine.stageMoves.set(element, element.animate([{ translate: `0 ${fromY}px` }, { translate: `0 ${placement.y}px` }], {
|
|
90
|
+
duration: instant || reduced ? 0 : STAGE_MOTION.durationMs,
|
|
91
|
+
easing: STAGE_MOTION.easing,
|
|
92
|
+
fill: "forwards",
|
|
93
|
+
}));
|
|
94
|
+
const showing = placement.visible;
|
|
95
|
+
const fadeMs = instant ? 0 : showing ? STAGE_FADE_IN_MS : STAGE_FADE_OUT_MS;
|
|
96
|
+
const delayMs = showing && !instant ? STAGE_FADE_IN_DELAY_MS : 0;
|
|
97
|
+
if (showing)
|
|
98
|
+
element.dataset.stageVisible = "";
|
|
99
|
+
else if (fadeMs === 0)
|
|
100
|
+
delete element.dataset.stageVisible;
|
|
101
|
+
const fade = element.animate([{ [STAGE_OPACITY_PROPERTY]: fromOpacity }, { [STAGE_OPACITY_PROPERTY]: showing ? 1 : 0 }], {
|
|
102
|
+
duration: fadeMs,
|
|
103
|
+
delay: delayMs,
|
|
104
|
+
easing: showing ? "ease-out" : "ease",
|
|
105
|
+
// Backwards fill preserves the sampled opacity during the replacement fade's delay.
|
|
106
|
+
fill: "both",
|
|
107
|
+
});
|
|
108
|
+
if (!showing && fadeMs > 0) {
|
|
109
|
+
fade.onfinish = () => {
|
|
110
|
+
if (engine.stageFades.get(element) === fade)
|
|
111
|
+
delete element.dataset.stageVisible;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
engine.stageFades.set(element, fade);
|
|
115
|
+
engine.stageY.set(element, placement.y);
|
|
116
|
+
engine.stageBlurs.get(element)?.cancel();
|
|
117
|
+
engine.stageBlurs.delete(element);
|
|
118
|
+
if (fadeMs === 0 || reduced || wasVisible === showing)
|
|
119
|
+
return;
|
|
120
|
+
const blurs = showing ? [HANDOFF_BLUR, "none"] : ["none", HANDOFF_BLUR];
|
|
121
|
+
engine.stageBlurs.set(element, element.animate(blurs.map(filter => ({ filter })), {
|
|
122
|
+
duration: fadeMs,
|
|
123
|
+
delay: showing ? STAGE_FADE_IN_DELAY_MS : 0,
|
|
124
|
+
easing: showing ? "ease-out" : "ease",
|
|
125
|
+
// Add to the theme's filter; release the blur once focused.
|
|
126
|
+
composite: "add",
|
|
127
|
+
fill: showing ? "backwards" : "forwards",
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
function snapStageElement(engine, element, y) {
|
|
131
|
+
engine.stageMoves.get(element)?.cancel();
|
|
132
|
+
engine.stageMoves.set(element, element.animate([{ translate: `0 ${y}px` }], { duration: 0, fill: "forwards" }));
|
|
133
|
+
engine.stageY.set(element, y);
|
|
134
|
+
}
|
|
135
|
+
// Registered from script because Firefox was seen not to apply @property from this package's stylesheet
|
|
136
|
+
// when it loads cross-origin to the page. An unregistered property would snap instead of interpolating.
|
|
137
|
+
function registerStageOpacity(engine) {
|
|
138
|
+
const css = engine.window.CSS;
|
|
139
|
+
if (stageOpacityRegistrations.has(engine.window) || typeof css?.registerProperty !== "function")
|
|
140
|
+
return;
|
|
141
|
+
stageOpacityRegistrations.add(engine.window);
|
|
142
|
+
try {
|
|
143
|
+
css.registerProperty({ name: STAGE_OPACITY_PROPERTY, syntax: "<number>", inherits: false, initialValue: "0" });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
engine.host.log("Stage opacity property was already registered", error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
export function measureStage(engine) {
|
|
150
|
+
engine.stageMetrics.clear();
|
|
151
|
+
const container = engine.lyricsContainer;
|
|
152
|
+
if (!container)
|
|
153
|
+
return;
|
|
154
|
+
engine.stageFontSize = Number.parseFloat(engine.window.getComputedStyle(container).fontSize) || 16;
|
|
155
|
+
const range = engine.document.createRange();
|
|
156
|
+
for (const element of stageElements(engine).elements) {
|
|
157
|
+
const style = engine.window.getComputedStyle(element);
|
|
158
|
+
const originX = originXOf(style.textAlign);
|
|
159
|
+
const padding = {
|
|
160
|
+
left: Number.parseFloat(style.paddingLeft) || 0,
|
|
161
|
+
right: Number.parseFloat(style.paddingRight) || 0,
|
|
162
|
+
};
|
|
163
|
+
const contentRects = collectContentRects(engine, range, element, contentWidthOf(element, style), []);
|
|
164
|
+
const span = stageTextSpan(element.offsetLeft, element.offsetWidth, element.getBoundingClientRect(), contentRects, padding, originX);
|
|
165
|
+
engine.stageMetrics.set(element, { height: element.offsetHeight, left: span.left, width: span.width, originX });
|
|
166
|
+
}
|
|
167
|
+
forceStageReplan(engine);
|
|
168
|
+
engine.stageRemeasured = true;
|
|
169
|
+
}
|
|
170
|
+
export function replaceStageElements(engine, dropped, previousOf) {
|
|
171
|
+
for (const [line, previous] of previousOf)
|
|
172
|
+
carryStageState(engine, previous.lyricElement, line.lyricElement);
|
|
173
|
+
for (const line of dropped)
|
|
174
|
+
forgetStageElement(engine, line.lyricElement);
|
|
175
|
+
forceStageReplan(engine);
|
|
176
|
+
}
|
|
177
|
+
function carryStageState(engine, from, to) {
|
|
178
|
+
const role = from.dataset.stageRole;
|
|
179
|
+
const y = engine.stageY.get(from);
|
|
180
|
+
if (role === undefined || y === undefined)
|
|
181
|
+
return;
|
|
182
|
+
to.dataset.stageRole = role;
|
|
183
|
+
if (from.dataset.stageVisible !== undefined)
|
|
184
|
+
to.dataset.stageVisible = "";
|
|
185
|
+
const move = continueAnimation(engine.stageMoves.get(from), to);
|
|
186
|
+
if (move === null) {
|
|
187
|
+
snapStageElement(engine, to, y);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
engine.stageMoves.set(to, move);
|
|
191
|
+
engine.stageY.set(to, y);
|
|
192
|
+
}
|
|
193
|
+
const visible = isStageRoleVisible(role);
|
|
194
|
+
const fade = continueAnimation(engine.stageFades.get(from), to) ??
|
|
195
|
+
to.animate([{ [STAGE_OPACITY_PROPERTY]: visible ? 1 : 0 }], { duration: 0, fill: "forwards" });
|
|
196
|
+
if (!visible) {
|
|
197
|
+
fade.onfinish = () => {
|
|
198
|
+
if (engine.stageFades.get(to) === fade)
|
|
199
|
+
delete to.dataset.stageVisible;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
engine.stageFades.set(to, fade);
|
|
203
|
+
const blur = continueAnimation(engine.stageBlurs.get(from), to);
|
|
204
|
+
if (blur !== null)
|
|
205
|
+
engine.stageBlurs.set(to, blur);
|
|
206
|
+
}
|
|
207
|
+
function forgetStageElement(engine, element) {
|
|
208
|
+
for (const animations of [engine.stageMoves, engine.stageFades, engine.stageBlurs]) {
|
|
209
|
+
animations.get(element)?.cancel();
|
|
210
|
+
animations.delete(element);
|
|
211
|
+
}
|
|
212
|
+
engine.stageY.delete(element);
|
|
213
|
+
engine.stageMetrics.delete(element);
|
|
214
|
+
}
|
|
215
|
+
export function resetStage(engine) {
|
|
216
|
+
for (const animations of [engine.stageMoves, engine.stageFades, engine.stageBlurs]) {
|
|
217
|
+
for (const animation of animations.values())
|
|
218
|
+
animation.cancel();
|
|
219
|
+
animations.clear();
|
|
220
|
+
}
|
|
221
|
+
engine.stageMetrics.clear();
|
|
222
|
+
engine.stageY.clear();
|
|
223
|
+
forceStageReplan(engine);
|
|
224
|
+
engine.stageHeight = 0;
|
|
225
|
+
if (engine.stageBox !== null) {
|
|
226
|
+
engine.stageBox = null;
|
|
227
|
+
engine.host.onStageLayout?.(null);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
export function currentTranslateY(engine, element, fallback) {
|
|
231
|
+
const y = Number.parseFloat(engine.window.getComputedStyle(element).translate.split(" ")[1] ?? "");
|
|
232
|
+
return Number.isFinite(y) ? y : fallback;
|
|
233
|
+
}
|
|
234
|
+
function forceStageReplan(engine) {
|
|
235
|
+
engine.stageKey = "";
|
|
236
|
+
}
|
|
237
|
+
function continueAnimation(animation, element) {
|
|
238
|
+
const effect = animation?.effect;
|
|
239
|
+
if (!animation || typeof effect?.getKeyframes !== "function")
|
|
240
|
+
return null;
|
|
241
|
+
if (animation.playState === "finished" || animation.playState === "idle")
|
|
242
|
+
return null;
|
|
243
|
+
const continued = element.animate(effect.getKeyframes(), { ...effect.getTiming(), composite: effect.composite });
|
|
244
|
+
continued.playbackRate = animation.playbackRate;
|
|
245
|
+
continued.currentTime = animation.currentTime;
|
|
246
|
+
if (animation.playState === "paused")
|
|
247
|
+
continued.pause();
|
|
248
|
+
return continued;
|
|
249
|
+
}
|
|
250
|
+
function stageElements(engine) {
|
|
251
|
+
const elements = [];
|
|
252
|
+
const items = [];
|
|
253
|
+
let lastEnd = 0;
|
|
254
|
+
for (const line of engine.lines) {
|
|
255
|
+
const end = line.time + line.duration;
|
|
256
|
+
lastEnd = Math.max(lastEnd, end);
|
|
257
|
+
elements.push(line.lyricElement);
|
|
258
|
+
items.push({ kind: stageItemKind(line.lyricElement), start: line.time, end });
|
|
259
|
+
}
|
|
260
|
+
const credits = engine.lyricsContainer?.querySelector(`:scope > .${CREDITS_CLASS}`);
|
|
261
|
+
if (credits) {
|
|
262
|
+
elements.push(credits);
|
|
263
|
+
items.push({ kind: "credits", start: lastEnd, end: Number.POSITIVE_INFINITY });
|
|
264
|
+
}
|
|
265
|
+
return { elements, items };
|
|
266
|
+
}
|
|
267
|
+
function stageItemKind(element) {
|
|
268
|
+
if (element.dataset.instrumental === "true")
|
|
269
|
+
return "instrumental";
|
|
270
|
+
if (element.dataset.blank === "true")
|
|
271
|
+
return "blank";
|
|
272
|
+
return "line";
|
|
273
|
+
}
|
|
274
|
+
function isStageRoleVisible(role) {
|
|
275
|
+
return role !== "queued" && role !== "gone";
|
|
276
|
+
}
|
|
277
|
+
function sameBox(a, b) {
|
|
278
|
+
if (a === null || b === null)
|
|
279
|
+
return a === b;
|
|
280
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
281
|
+
}
|
|
282
|
+
function originXOf(align) {
|
|
283
|
+
if (align === "center")
|
|
284
|
+
return 0.5;
|
|
285
|
+
if (align === "right" || align === "end")
|
|
286
|
+
return 1;
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
function contentWidthOf(element, style) {
|
|
290
|
+
const padding = (Number.parseFloat(style.paddingLeft) || 0) + (Number.parseFloat(style.paddingRight) || 0);
|
|
291
|
+
return element.clientWidth - padding;
|
|
292
|
+
}
|
|
293
|
+
function fillsWidth(element, contentWidth) {
|
|
294
|
+
return element.offsetWidth >= contentWidth - 1;
|
|
295
|
+
}
|
|
296
|
+
function collectContentRects(engine, range, node, contentWidth, rects) {
|
|
297
|
+
for (const child of node.childNodes) {
|
|
298
|
+
if (child.nodeType === TEXT_NODE) {
|
|
299
|
+
range.selectNodeContents(child);
|
|
300
|
+
rects.push(...range.getClientRects());
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
if (child.nodeType !== ELEMENT_NODE)
|
|
304
|
+
continue;
|
|
305
|
+
const element = child;
|
|
306
|
+
const style = engine.window.getComputedStyle(element);
|
|
307
|
+
if (style.display === "none")
|
|
308
|
+
continue;
|
|
309
|
+
if (style.display === "contents")
|
|
310
|
+
collectContentRects(engine, range, element, contentWidth, rects);
|
|
311
|
+
else if (style.display.startsWith("inline"))
|
|
312
|
+
rects.push(...element.getClientRects());
|
|
313
|
+
else if (!fillsWidth(element, contentWidth))
|
|
314
|
+
rects.push(element.getBoundingClientRect());
|
|
315
|
+
else
|
|
316
|
+
collectContentRects(engine, range, element, contentWidthOf(element, style), rects);
|
|
317
|
+
}
|
|
318
|
+
return rects;
|
|
319
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { SwipeRamp } from "./letterPlans.js";
|
|
2
|
+
/** Keyframes for a sweep cell's mask and for the text inside it, offsets in eased swipe progress. */
|
|
3
|
+
export interface CellSweep {
|
|
4
|
+
mask: Keyframe[];
|
|
5
|
+
text: Keyframe[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Where a cell's mask edge rests, in the cell's widths: half a cell past its end, so the halos inside
|
|
9
|
+
* the mask show whole once the cell is lit. `.blyrics-sweep-mask` in lyrics.css places its edge there.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SWEEP_REST = 1.5;
|
|
12
|
+
/** A cell's place along its word, as fractions of the word's width. */
|
|
13
|
+
export interface CellSpan {
|
|
14
|
+
start: number;
|
|
15
|
+
width: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The swipe's soft edge in a cell's own widths. `.blyrics-sweep-mask` reads the same value as
|
|
19
|
+
* `--blyrics-sweep-fade`, so the two must agree.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cellFade(swipe: SwipeRamp, span: CellSpan): number;
|
|
22
|
+
/**
|
|
23
|
+
* How far through the swipe, in eased progress, its start stop reaches the start of a cell. Until then
|
|
24
|
+
* the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
|
|
25
|
+
*/
|
|
26
|
+
export declare function cellReachedAt(swipe: SwipeRamp, span: CellSpan): number;
|
|
27
|
+
/**
|
|
28
|
+
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
29
|
+
* `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
|
|
30
|
+
* changes while that is between `-fade` (nothing lit yet) and `SWEEP_REST` (lit, with room for its
|
|
31
|
+
* halo), so the motion is clamped there. `.blyrics-sweep-mask` in lyrics.css is `3 + fade` cells wide,
|
|
32
|
+
* starting a cell before the cell, with its soft edge from `SWEEP_REST` to `fade` cells further. The
|
|
33
|
+
* start stop moves linearly in eased progress, so keyframes at the clamp points with the swipe's
|
|
34
|
+
* easing on the whole effect follow it exactly.
|
|
35
|
+
*/
|
|
36
|
+
export declare function planCellSweep(swipe: SwipeRamp, span: CellSpan, rtl: boolean): CellSweep | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { clamp } from "../util.js";
|
|
2
|
+
function swipeStops(swipe) {
|
|
3
|
+
const startFrom = Number.parseFloat(swipe.startFrom);
|
|
4
|
+
const startTo = Number.parseFloat(swipe.startTo);
|
|
5
|
+
const fade = Number.parseFloat(swipe.endTo) - startTo;
|
|
6
|
+
if (![startFrom, startTo, fade].every(Number.isFinite) || startTo <= startFrom)
|
|
7
|
+
return null;
|
|
8
|
+
return { startFrom, startTo, fade: Math.max(fade, 0) };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Where a cell's mask edge rests, in the cell's widths: half a cell past its end, so the halos inside
|
|
12
|
+
* the mask show whole once the cell is lit. `.blyrics-sweep-mask` in lyrics.css places its edge there.
|
|
13
|
+
*/
|
|
14
|
+
export const SWEEP_REST = 1.5;
|
|
15
|
+
/**
|
|
16
|
+
* The swipe's soft edge in a cell's own widths. `.blyrics-sweep-mask` reads the same value as
|
|
17
|
+
* `--blyrics-sweep-fade`, so the two must agree.
|
|
18
|
+
*/
|
|
19
|
+
export function cellFade(swipe, span) {
|
|
20
|
+
const stops = swipeStops(swipe);
|
|
21
|
+
return stops && span.width > 0 ? stops.fade / span.width : 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* How far through the swipe, in eased progress, its start stop reaches the start of a cell. Until then
|
|
25
|
+
* the cell's halo would show behind the edge before any of its text is lit, so its glow waits.
|
|
26
|
+
*/
|
|
27
|
+
export function cellReachedAt(swipe, span) {
|
|
28
|
+
const stops = swipeStops(swipe);
|
|
29
|
+
return stops ? clamp((span.start - stops.startFrom) / (stops.startTo - stops.startFrom), 0, 1) : 0;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Plans one cell of a sweep. In the cell's own widths the start stop runs from
|
|
33
|
+
* `(startFrom - span.start) / span.width` to `(startTo - span.start) / span.width`, and the cell only
|
|
34
|
+
* changes while that is between `-fade` (nothing lit yet) and `SWEEP_REST` (lit, with room for its
|
|
35
|
+
* halo), so the motion is clamped there. `.blyrics-sweep-mask` in lyrics.css is `3 + fade` cells wide,
|
|
36
|
+
* starting a cell before the cell, with its soft edge from `SWEEP_REST` to `fade` cells further. The
|
|
37
|
+
* start stop moves linearly in eased progress, so keyframes at the clamp points with the swipe's
|
|
38
|
+
* easing on the whole effect follow it exactly.
|
|
39
|
+
*/
|
|
40
|
+
export function planCellSweep(swipe, span, rtl) {
|
|
41
|
+
const stops = swipeStops(swipe);
|
|
42
|
+
if (!stops || span.width <= 0)
|
|
43
|
+
return null;
|
|
44
|
+
const fade = stops.fade / span.width;
|
|
45
|
+
const maskWidths = 3 + fade;
|
|
46
|
+
const sign = rtl ? -1 : 1;
|
|
47
|
+
const startAt = (progress) => (stops.startFrom + (stops.startTo - stops.startFrom) * progress - span.start) / span.width;
|
|
48
|
+
const progressAt = (start) => (start * span.width + span.start - stops.startFrom) / (stops.startTo - stops.startFrom);
|
|
49
|
+
const offsets = [0, progressAt(-fade), progressAt(SWEEP_REST), 1].map(offset => clamp(offset, 0, 1));
|
|
50
|
+
const unique = offsets.filter((offset, position) => offsets.indexOf(offset) === position);
|
|
51
|
+
const mask = [];
|
|
52
|
+
const text = [];
|
|
53
|
+
for (const offset of unique) {
|
|
54
|
+
const behind = sign * (clamp(startAt(offset), -fade, SWEEP_REST) - SWEEP_REST);
|
|
55
|
+
mask.push({ offset, translate: `${(behind * 100) / maskWidths}% 0` });
|
|
56
|
+
text.push({ offset, translate: `${-behind * 100}% 0` });
|
|
57
|
+
}
|
|
58
|
+
return { mask, text };
|
|
59
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ResolvedTickOptions, TickOptions } from "../types.js";
|
|
2
|
+
import type { AnimationEngineInstance } from "./instance.js";
|
|
3
|
+
/**
|
|
4
|
+
* "lyrics-missing" means this instance has nothing left to render. Whether that ends ticking is the
|
|
5
|
+
* driver's call, not the instance's: one instance running dry must not silence another.
|
|
6
|
+
*/
|
|
7
|
+
export type AnimationTickStatus = "ok" | "lyrics-missing";
|
|
8
|
+
export declare function resolveTickOptions(options: TickOptions): ResolvedTickOptions;
|
|
9
|
+
export declare function tickView(engine: AnimationEngineInstance, reportedTimeS: number, options: ResolvedTickOptions): AnimationTickStatus;
|
|
10
|
+
/** Returns whether it stopped lines that only a tick starts again; see `restartContextSweeps`. */
|
|
11
|
+
export declare function relayout(engine: AnimationEngineInstance, linesAreRendered: boolean): boolean;
|
|
12
|
+
export declare function cancelLyricPositionUpdate(engine: AnimationEngineInstance): void;
|
|
13
|
+
export declare function retickFromPlaybackClock(engine: AnimationEngineInstance, buildTickOptions: (eventCreationTime: number, isPlaying: boolean) => TickOptions): AnimationTickStatus;
|
|
14
|
+
/** Ticks again at the time and with the options of the last tick, for a view that is not ticking itself. */
|
|
15
|
+
export declare function retickAtLastTime(engine: AnimationEngineInstance): void;
|
|
16
|
+
export declare function scheduleLyricPositionUpdate(engine: AnimationEngineInstance, isViewRendering: () => boolean, retick: () => void): void;
|