@checksub_team/peaks_timeline 1.16.1 → 2.0.0-alpha.2
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/package.json +1 -1
- package/peaks.js +4716 -4409
- package/peaks.js.d.ts +5 -5
- package/src/{timeline-axis.js → components/axis.js} +244 -244
- package/src/{data-retriever.js → components/data-retriever.js} +117 -117
- package/src/{default-segment-marker.js → components/default-segment-marker.js} +132 -132
- package/src/{invoker.js → components/invoker.js} +81 -81
- package/src/components/line-group.js +692 -0
- package/src/components/line-groups.js +585 -0
- package/src/{line-indicator.js → components/line-indicator.js} +308 -303
- package/src/{marker-factories.js → components/marker-factories.js} +1 -1
- package/src/{mode-layer.js → components/mode-layer.js} +8 -12
- package/src/{playhead-layer.js → components/playhead-layer.js} +3 -3
- package/src/{segment-marker.js → components/segment-marker.js} +2 -2
- package/src/{segment-shape.js → components/segment-shape.js} +508 -508
- package/src/{segments-group.js → components/segments-group.js} +805 -801
- package/src/{source-group.js → components/source-group.js} +1661 -1640
- package/src/{sources-layer.js → components/sources-layer.js} +716 -730
- package/src/{waveform-builder.js → components/waveform-builder.js} +2 -2
- package/src/{waveform-shape.js → components/waveform-shape.js} +214 -214
- package/src/keyboard-handler.js +9 -9
- package/src/line-handler.js +179 -0
- package/src/main.js +110 -71
- package/src/models/line.js +156 -0
- package/src/{segment.js → models/segment.js} +420 -419
- package/src/{source.js → models/source.js} +1311 -1315
- package/src/player.js +2 -2
- package/src/{timeline-segments.js → segment-handler.js} +435 -435
- package/src/{timeline-sources.js → source-handler.js} +521 -514
- package/src/utils.js +5 -1
- package/src/{timeline-zoomview.js → view.js} +136 -137
- package/src/line.js +0 -690
- package/src/lines.js +0 -427
- /package/src/{data.js → components/data.js} +0 -0
- /package/src/{loader.js → components/loader.js} +0 -0
- /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
- /package/src/{svgs.js → components/svgs.js} +0 -0
package/src/lines.js
DELETED
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
4
|
-
* Defines the {@link lines} class.
|
|
5
|
-
*
|
|
6
|
-
* @module lines
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
define([
|
|
10
|
-
'./segments-group',
|
|
11
|
-
'./line',
|
|
12
|
-
'./line-indicator',
|
|
13
|
-
'./utils'
|
|
14
|
-
], function(
|
|
15
|
-
SegmentsGroup,
|
|
16
|
-
Line,
|
|
17
|
-
LineIndicator,
|
|
18
|
-
Utils) {
|
|
19
|
-
'use strict';
|
|
20
|
-
|
|
21
|
-
function Lines(peaks, view, layer) {
|
|
22
|
-
this._peaks = peaks;
|
|
23
|
-
this._view = view;
|
|
24
|
-
this._layer = layer;
|
|
25
|
-
this._linesBySourceId = {};
|
|
26
|
-
this._linesByPosition = {};
|
|
27
|
-
this._autoAddToLayer = false;
|
|
28
|
-
this._areSourceInteractionsAllowed = true;
|
|
29
|
-
this._areSegmentInteractionsAllowed = true;
|
|
30
|
-
|
|
31
|
-
this._segmentsGroups = {};
|
|
32
|
-
this._segmentsGroupToLine = {};
|
|
33
|
-
|
|
34
|
-
this._lineId = 0;
|
|
35
|
-
|
|
36
|
-
this._lineIndicator = new LineIndicator(
|
|
37
|
-
peaks,
|
|
38
|
-
view,
|
|
39
|
-
document.getElementById('line-indicator-container')
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
|
|
43
|
-
this._peaks.on('line.add', this._onLineAdd.bind(this));
|
|
44
|
-
this._peaks.on('line.remove', this._onLineRemove.bind(this));
|
|
45
|
-
|
|
46
|
-
this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
|
|
47
|
-
this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
|
|
48
|
-
this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
|
|
49
|
-
this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
|
|
50
|
-
this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
Lines.prototype.fitToView = function() {
|
|
54
|
-
this._lineIndicator.fitToView();
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
Lines.prototype._onSegmentsAdd = function(segments) {
|
|
58
|
-
var self = this;
|
|
59
|
-
|
|
60
|
-
segments.forEach(function(segment) {
|
|
61
|
-
if (!self._segmentsGroups[segment.line]) {
|
|
62
|
-
self._segmentsGroups[segment.line] = new SegmentsGroup(self._peaks, self._view, true);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
self._segmentsGroups[segment.line].onSegmentsAdd([segment]);
|
|
66
|
-
if (Utils.objectHasProperty(self._segmentsGroupToLine, segment.line)) {
|
|
67
|
-
self._segmentsGroupToLine[segment.line].refreshSegmentsHeight();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
Lines.prototype._onSegmentsUpdate = function(segment) {
|
|
73
|
-
this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
Lines.prototype._onSegmentUpdated = function(segment) {
|
|
77
|
-
this._segmentsGroups[segment.line].onSegmentUpdated();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
Lines.prototype._onSegmentsRemove = function(segments) {
|
|
81
|
-
var self = this;
|
|
82
|
-
|
|
83
|
-
segments.forEach(function(segment) {
|
|
84
|
-
self._segmentsGroups[segment.line].onSegmentsRemove([segment]);
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
Lines.prototype._onSegmentsRemoveAll = function(lineId) {
|
|
89
|
-
this._segmentsGroups[lineId].onSegmentsRemoveAll();
|
|
90
|
-
|
|
91
|
-
if (Utils.objectHasProperty(this._segmentsGroupToLine, lineId)) {
|
|
92
|
-
this._segmentsGroupToLine[lineId].refreshSegmentsHeight();
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
Lines.prototype._onLineHeightChanged = function(position) {
|
|
97
|
-
this._updateLinesPosition(position);
|
|
98
|
-
this._view.updateTimeline();
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
Lines.prototype._onLineAdd = function(position) {
|
|
102
|
-
this._createLine(position);
|
|
103
|
-
this._setInteractions(position);
|
|
104
|
-
this._updateLinesPosition(position);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
Lines.prototype._onLineRemove = function(position) {
|
|
108
|
-
var oldLine = this.removeLine(position);
|
|
109
|
-
var lineNewY = oldLine.getY();
|
|
110
|
-
|
|
111
|
-
this._updateLinesPosition(position, lineNewY);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
Lines.prototype.changeLineHeight = function(from, to) {
|
|
115
|
-
for (var position in this._linesByPosition) {
|
|
116
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
117
|
-
if (!this._linesByPosition[position].isSegmentsLine()) {
|
|
118
|
-
this._linesByPosition[position].changeHeight(from, to);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
Lines.prototype.addSourceGroup = function(sourceGroup, position) {
|
|
125
|
-
if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
|
|
126
|
-
this._createLine(position);
|
|
127
|
-
this._setInteractions(position);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
sourceGroup.getSource().position = position;
|
|
131
|
-
this._linesByPosition[position].addSourceGroup(sourceGroup);
|
|
132
|
-
this._linesBySourceId[sourceGroup.getSource().id] = this._linesByPosition[position];
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
Lines.prototype.addSegments = function(lineId, position) {
|
|
136
|
-
this._createLine(position);
|
|
137
|
-
|
|
138
|
-
this._linesByPosition[position].allowInteractions(this._areSegmentInteractionsAllowed);
|
|
139
|
-
this._linesByPosition[position].addSegments(this._segmentsGroups[lineId]);
|
|
140
|
-
|
|
141
|
-
this._segmentsGroupToLine[lineId] = this._linesByPosition[position];
|
|
142
|
-
|
|
143
|
-
this._setInteractions(position);
|
|
144
|
-
|
|
145
|
-
this._updateLinesPosition(position);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
Lines.prototype.removeSourceGroup = function(source, isPermanent) {
|
|
149
|
-
var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, isPermanent);
|
|
150
|
-
|
|
151
|
-
if (isPermanent) {
|
|
152
|
-
delete this._linesBySourceId[source.id];
|
|
153
|
-
this._updateLinesPosition(source.position);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return sourceGroup;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
Lines.prototype.removeLine = function(pos) {
|
|
160
|
-
var oldLine = this._linesByPosition[pos];
|
|
161
|
-
|
|
162
|
-
oldLine.destroy();
|
|
163
|
-
|
|
164
|
-
delete this._linesByPosition[pos];
|
|
165
|
-
|
|
166
|
-
this._lineIndicator.removeIndicator(oldLine.getId(), false);
|
|
167
|
-
|
|
168
|
-
return oldLine;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
Lines.prototype.isLineVisible = function(position) {
|
|
172
|
-
return this._linesByPosition[position].isVisible();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
Lines.prototype.getVisibleLines = function() {
|
|
176
|
-
var positions = {};
|
|
177
|
-
|
|
178
|
-
for (var position in this._linesByPosition) {
|
|
179
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
180
|
-
if (this._linesByPosition[position].isVisible()) {
|
|
181
|
-
positions[position] = true;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return positions;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
Lines.prototype.getSourcesOnLineAfter = function(lineId, time) {
|
|
189
|
-
return this._linesByPosition[lineId].getSourcesAfter(time);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
Lines.prototype.getSegmentsGroups = function() {
|
|
193
|
-
return this._segmentsGroups;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
Lines.prototype.addToLayer = function(layer) {
|
|
197
|
-
for (var position in this._linesByPosition) {
|
|
198
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
199
|
-
this._linesByPosition[position].addToLayer(layer);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
this._autoAddToLayer = true;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
Lines.prototype.updateLines = function(position) {
|
|
207
|
-
this._updateLinesPosition(position);
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
Lines.prototype._updateLinesPosition = function(position, forceNewY) {
|
|
211
|
-
var line = this._linesByPosition[position];
|
|
212
|
-
var dy = null;
|
|
213
|
-
var newY;
|
|
214
|
-
|
|
215
|
-
if (forceNewY) {
|
|
216
|
-
newY = forceNewY;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
for (var pos in this._linesByPosition) {
|
|
223
|
-
if (Utils.objectHasProperty(this._linesByPosition, pos)) {
|
|
224
|
-
if (parseInt(pos, 10) > position) {
|
|
225
|
-
if (dy === null) {
|
|
226
|
-
dy = newY - this._linesByPosition[pos].getY();
|
|
227
|
-
this._linesByPosition[pos].moveOnY(dy);
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
this._linesByPosition[pos].moveOnY(dy);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
this._lineIndicator.updateIndicators();
|
|
237
|
-
this._lineIndicator.draw();
|
|
238
|
-
|
|
239
|
-
this._view.drawSourcesLayer();
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
Lines.prototype.setOffsetY = function(frameOffset) {
|
|
243
|
-
for (var position in this._linesByPosition) {
|
|
244
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
245
|
-
var line = this._linesByPosition[position];
|
|
246
|
-
|
|
247
|
-
line.y(line.getInitialY() - frameOffset);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this._lineIndicator.updateIndicators();
|
|
252
|
-
this._lineIndicator.draw();
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
Lines.prototype.height = function() {
|
|
256
|
-
var height = 2 * this._peaks.options.padding;
|
|
257
|
-
|
|
258
|
-
for (var position in this._linesByPosition) {
|
|
259
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
260
|
-
height += this._linesByPosition[position].lineHeight() + this._peaks.options.interline;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
height -= this._peaks.options.interline;
|
|
265
|
-
|
|
266
|
-
return height;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
Lines.prototype.linesLength = function() {
|
|
270
|
-
var length = 0;
|
|
271
|
-
|
|
272
|
-
for (var position in this._linesByPosition) {
|
|
273
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
274
|
-
var lineLength = this._linesByPosition[position].lineLength();
|
|
275
|
-
|
|
276
|
-
if (lineLength > length) {
|
|
277
|
-
length = lineLength;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return length;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
Lines.prototype.manageVerticalPosition = function(source, newY) {
|
|
286
|
-
if (newY !== null && newY !== undefined) {
|
|
287
|
-
var pos = this.getLineOnPosition(newY);
|
|
288
|
-
|
|
289
|
-
if (pos[0] === pos[1]
|
|
290
|
-
&& pos[0] !== source.position
|
|
291
|
-
&& !this._linesByPosition[pos[0]].isSegmentsLine()) {
|
|
292
|
-
this.moveSourceToPosition(source, pos[0]);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
Lines.prototype.getLineByPosition = function(pos) {
|
|
298
|
-
return this._linesByPosition[pos];
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
Lines.prototype.getLineOnPosition = function(y) {
|
|
302
|
-
var height;
|
|
303
|
-
var pos = [-1, Number.MAX_VALUE];
|
|
304
|
-
|
|
305
|
-
for (var position in this._linesByPosition) {
|
|
306
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
307
|
-
height = this._linesByPosition[position].lineHeight();
|
|
308
|
-
|
|
309
|
-
if (y > this._linesByPosition[position].getY()) {
|
|
310
|
-
pos[0] = Math.max(pos[0], parseInt(position, 10));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (y < this._linesByPosition[position].getY() + height) {
|
|
314
|
-
pos[1] = Math.min(pos[1], parseInt(position, 10));
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
return pos;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
Lines.prototype.moveSourceToPosition = function(source, pos) {
|
|
323
|
-
var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, true);
|
|
324
|
-
|
|
325
|
-
delete this._linesBySourceId[source.id];
|
|
326
|
-
|
|
327
|
-
sourceGroup.moveTo(this._linesByPosition[pos].getKonvaGroup());
|
|
328
|
-
|
|
329
|
-
this._updateLinesPosition(source.position);
|
|
330
|
-
|
|
331
|
-
this.addSourceGroup(sourceGroup, pos);
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
Lines.prototype._getNextLineId = function() {
|
|
335
|
-
this._lineId++;
|
|
336
|
-
return this._lineId;
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
Lines.prototype._createLine = function(position) {
|
|
340
|
-
var y = this._peaks.options.padding;
|
|
341
|
-
var currentPos;
|
|
342
|
-
var newLinesByPosition = Object.assign({},this._linesByPosition);
|
|
343
|
-
|
|
344
|
-
for (var pos in this._linesByPosition) {
|
|
345
|
-
if (Utils.objectHasProperty(this._linesByPosition, pos)) {
|
|
346
|
-
currentPos = parseInt(pos, 10);
|
|
347
|
-
if (currentPos < position) {
|
|
348
|
-
y += this._linesByPosition[pos].lineHeight() + this._peaks.options.interline;
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
if (this._linesByPosition[position]) {
|
|
352
|
-
this._linesByPosition[currentPos].updatePosition(currentPos + 1);
|
|
353
|
-
newLinesByPosition[currentPos + 1] = this._linesByPosition[currentPos];
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
var line = new Line(this._peaks, this._view, y, this._getNextLineId(), position);
|
|
360
|
-
|
|
361
|
-
this._lineIndicator.addIndicator(line);
|
|
362
|
-
|
|
363
|
-
if (this._autoAddToLayer) {
|
|
364
|
-
line.addToLayer(this._layer);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
newLinesByPosition[position] = line;
|
|
368
|
-
this._linesByPosition = newLinesByPosition;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
Lines.prototype.updateSegments = function(frameStartTime, frameEndTime) {
|
|
372
|
-
for (var lineId in this._segmentsGroups) {
|
|
373
|
-
if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
|
|
374
|
-
this._segmentsGroups[lineId].updateSegments(frameStartTime, frameEndTime);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
Lines.prototype.manageCollision = function(source, newTimes) {
|
|
380
|
-
return this._linesBySourceId[source.id].manageCollision(source, newTimes);
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
Lines.prototype.manageSourceOrder = function(source, newTimes) {
|
|
384
|
-
return this._linesBySourceId[source.id].manageSourceOrder(source, newTimes);
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
Lines.prototype._setInteractions = function(position) {
|
|
388
|
-
var line = this._linesByPosition[position];
|
|
389
|
-
|
|
390
|
-
if (this._areInteractionsOverridden) {
|
|
391
|
-
line.allowInteractions(this._areInteractionsAllowed);
|
|
392
|
-
}
|
|
393
|
-
else {
|
|
394
|
-
line.allowInteractions(
|
|
395
|
-
line.isSegmentsLine() ?
|
|
396
|
-
this._areSegmentInteractionsAllowed :
|
|
397
|
-
this._areSourceInteractionsAllowed
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
Lines.prototype.overrideInteractions = function(bool, areInteractionsAllowed) {
|
|
403
|
-
this._areInteractionsOverridden = typeof bool !== 'undefined' ?
|
|
404
|
-
bool : this._areInteractionsOverridden;
|
|
405
|
-
this._areInteractionsAllowed = typeof areInteractionsAllowed !== 'undefined' ?
|
|
406
|
-
areInteractionsAllowed : this._areInteractionsAllowed;
|
|
407
|
-
for (var position in this._linesByPosition) {
|
|
408
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
409
|
-
this._setInteractions(position);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
Lines.prototype.allowInteractions = function(forSources, forSegments) {
|
|
415
|
-
this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ?
|
|
416
|
-
forSources : this._areSourceInteractionsAllowed;
|
|
417
|
-
this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ?
|
|
418
|
-
forSegments : this._areSegmentInteractionsAllowed;
|
|
419
|
-
for (var position in this._linesByPosition) {
|
|
420
|
-
if (Utils.objectHasProperty(this._linesByPosition, position)) {
|
|
421
|
-
this._setInteractions(position);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
return Lines;
|
|
427
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|