@music-lyric-player/base 0.10.0 → 0.12.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.
@@ -1,8 +1,7 @@
1
1
  import { ConfigManager } from '@music-lyric-player/utils';
2
2
  import { DeepRequired } from '@music-lyric-player/utils';
3
3
  import { Event as Event_2 } from '@music-lyric-player/utils';
4
- import { Info } from '@music-lyric-kit/lyric';
5
- import { Line } from '@music-lyric-kit/lyric';
4
+ import { Lyric } from '@music-lyric-kit/lyric';
6
5
  import { NestedKeys } from '@music-lyric-player/utils';
7
6
 
8
7
  export declare class BaseLyricPlayer {
@@ -11,9 +10,13 @@ export declare class BaseLyricPlayer {
11
10
  private state;
12
11
  private active;
13
12
  private time;
13
+ private offset;
14
14
  private info;
15
15
  constructor();
16
+ private onConfigUpdate;
16
17
  private handleGetCurrentTime;
18
+ private handleGetEffectiveTime;
19
+ private handleRefreshOffset;
17
20
  private handleGetLineTime;
18
21
  private handleGetActiveIndex;
19
22
  private handleBridgeActive;
@@ -21,7 +24,7 @@ export declare class BaseLyricPlayer {
21
24
  private handleSyncTime;
22
25
  private handleUpdateActiveLines;
23
26
  private onTick;
24
- updateLyric(info: Info): void;
27
+ updateLyric(info: Lyric.Info): void;
25
28
  /**
26
29
  * Start playback
27
30
  * @param time Optional time in ms to seek to before starting playback. If not provided, playback will start from the current position.
@@ -35,14 +38,27 @@ export declare class BaseLyricPlayer {
35
38
  * Stop playback
36
39
  */
37
40
  dispose(): void;
41
+ /**
42
+ * Update the temp offset in ms (the user's temporary adjustment).
43
+ * Stacked on top of the global config offset and the lyric's meta offset, then resyncs immediately.
44
+ * @param value temp offset in ms; non-finite values are treated as 0.
45
+ */
46
+ updateTempOffset(value: number): void;
38
47
  /**
39
48
  * Find all active lines at the given time (ms). Does not mutate internal state.
49
+ * Assumes `info.lines` is sorted by `time.start` ascending.
40
50
  * @param time time in ms to find active lines for.
41
51
  */
42
52
  matchLinesWithTime(time: number): {
43
- lines: Line[];
53
+ lines: Lyric.Line[];
44
54
  index: number[];
45
55
  };
56
+ /**
57
+ * Convert a content (lyric) time to the playback clock by removing the active offset.
58
+ * Seeking playback to the returned time makes a line at `contentTime` become active.
59
+ * @param contentTime content time in ms (e.g. a line's start).
60
+ */
61
+ convertContentTime(contentTime: number): number;
46
62
  /**
47
63
  * Whether the player is currently playing.
48
64
  */
@@ -50,7 +66,7 @@ export declare class BaseLyricPlayer {
50
66
  /**
51
67
  * Current active lines.
52
68
  */
53
- get currentLines(): Line[];
69
+ get currentLines(): Lyric.Line[];
54
70
  /**
55
71
  * Indices of currently active lines.
56
72
  */
@@ -62,15 +78,20 @@ export declare class BaseLyricPlayer {
62
78
  /**
63
79
  * The current lyric info object.
64
80
  */
65
- get currentInfo(): Info;
81
+ get currentInfo(): Lyric.Info;
66
82
  /**
67
83
  * The current playback time in ms.
68
84
  */
69
85
  get currentTime(): number;
86
+ /**
87
+ * The current effective lyric offset in ms (config offset + lyric meta offset + temp offset).
88
+ */
89
+ get currentOffset(): number;
70
90
  }
71
91
 
72
92
  export declare namespace BaseLyricPlayerConfig {
73
93
  export {
94
+ Offset,
74
95
  Root,
75
96
  RootRequired,
76
97
  RootKeys,
@@ -95,7 +116,7 @@ export declare interface BaseLyricPlayerEventMap {
95
116
  * When the entire lyric information is updated (e.g., loading a new lyric/song).
96
117
  * @param info The newly loaded lyric information object.
97
118
  */
98
- lyricUpdate: (info: Info) => void;
119
+ lyricUpdate: (info: Lyric.Info) => void;
99
120
  /**
100
121
  * When the currently active lyric lines change during playback.
101
122
  * @param lines An array of the currently active lyric lines.
@@ -103,11 +124,32 @@ export declare interface BaseLyricPlayerEventMap {
103
124
  * @param firstIndex The index of the first currently active lyric line (-1 if none).
104
125
  * @param isSeek Is seek.
105
126
  */
106
- linesUpdate: (lines: Line[], indexs: number[], index: number, isSeek: boolean) => void;
127
+ linesUpdate: (lines: Lyric.Line[], indexs: number[], index: number, isSeek: boolean) => void;
107
128
  }
108
129
 
109
130
  declare const DEFAULT: Root;
110
131
 
132
+ declare interface Offset {
133
+ /**
134
+ * Global offset in ms, applied to every song.
135
+ *
136
+ * @default 0
137
+ */
138
+ global?: number;
139
+ /**
140
+ * Whether to apply the offset carried by the lyric's own meta (`MetaType.Offset`).
141
+ *
142
+ * @default true
143
+ */
144
+ useMeta?: boolean;
145
+ /**
146
+ * Whether loading a new lyric via `updateLyric` resets the temp offset (set via `updateTempOffset`) back to 0.
147
+ *
148
+ * @default true
149
+ */
150
+ resetTempOnLyricChange?: boolean;
151
+ }
152
+
111
153
  declare interface Root {
112
154
  /**
113
155
  * Driver type for playback scheduling.
@@ -127,6 +169,10 @@ declare interface Root {
127
169
  * @default true
128
170
  */
129
171
  bridgeActive?: boolean;
172
+ /**
173
+ * Lyric time offset settings.
174
+ */
175
+ offset?: Offset;
130
176
  }
131
177
 
132
178
  /**