@checksub_team/peaks_timeline 1.16.0-alpha.1 → 2.0.0-alpha.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.
Files changed (36) hide show
  1. package/package.json +1 -1
  2. package/peaks.js +4345 -4185
  3. package/peaks.js.d.ts +5 -5
  4. package/src/{timeline-axis.js → components/axis.js} +244 -244
  5. package/src/{data-retriever.js → components/data-retriever.js} +117 -117
  6. package/src/{default-segment-marker.js → components/default-segment-marker.js} +132 -132
  7. package/src/{invoker.js → components/invoker.js} +81 -81
  8. package/src/{line.js → components/line-group.js} +213 -240
  9. package/src/components/line-groups.js +584 -0
  10. package/src/{line-indicator.js → components/line-indicator.js} +308 -303
  11. package/src/{marker-factories.js → components/marker-factories.js} +1 -1
  12. package/src/{mode-layer.js → components/mode-layer.js} +8 -12
  13. package/src/{playhead-layer.js → components/playhead-layer.js} +3 -3
  14. package/src/{segment-marker.js → components/segment-marker.js} +2 -2
  15. package/src/{segment-shape.js → components/segment-shape.js} +508 -508
  16. package/src/{segments-group.js → components/segments-group.js} +805 -805
  17. package/src/{source-group.js → components/source-group.js} +1641 -1649
  18. package/src/{sources-layer.js → components/sources-layer.js} +716 -725
  19. package/src/{waveform-builder.js → components/waveform-builder.js} +2 -2
  20. package/src/{waveform-shape.js → components/waveform-shape.js} +214 -214
  21. package/src/keyboard-handler.js +9 -9
  22. package/src/line-handler.js +179 -0
  23. package/src/main.js +99 -71
  24. package/src/models/line.js +156 -0
  25. package/src/{segment.js → models/segment.js} +420 -419
  26. package/src/{source.js → models/source.js} +1262 -1269
  27. package/src/player.js +2 -2
  28. package/src/{timeline-segments.js → segment-handler.js} +427 -435
  29. package/src/{timeline-sources.js → source-handler.js} +510 -512
  30. package/src/utils.js +5 -1
  31. package/src/{timeline-zoomview.js → view.js} +133 -138
  32. package/src/lines.js +0 -550
  33. /package/src/{data.js → components/data.js} +0 -0
  34. /package/src/{loader.js → components/loader.js} +0 -0
  35. /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
  36. /package/src/{svgs.js → components/svgs.js} +0 -0
package/src/lines.js DELETED
@@ -1,550 +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._linesByPosition = {};
26
- this._autoAddToLayer = false;
27
- this._areSourceInteractionsAllowed = true;
28
- this._areSegmentInteractionsAllowed = true;
29
-
30
- this._automaticallyCreatedLineId = null;
31
- this._automaticLineCreationPosition = null;
32
- this._automaticLineCreationTimeout = null;
33
-
34
- this._segmentsGroups = {};
35
- this._segmentsGroupToLine = {};
36
-
37
- this._lineId = 0;
38
-
39
- this._lineIndicator = new LineIndicator(
40
- peaks,
41
- view,
42
- document.getElementById('line-indicator-container')
43
- );
44
-
45
- this._peaks.on('line.heightChanged', this._onLineHeightChanged.bind(this));
46
- this._peaks.on('line.add', this._onLineAdd.bind(this));
47
- this._peaks.on('line.remove', this._onLineRemove.bind(this));
48
-
49
- this._peaks.on('sources.show', this._onSourcesWrappingChanged.bind(this));
50
- this._peaks.on('sources.hide', this._onSourcesWrappingChanged.bind(this));
51
-
52
- this._peaks.on('segment.updated', this._onSegmentsUpdate.bind(this));
53
- this._peaks.on('segments.add', this._onSegmentsAdd.bind(this));
54
- this._peaks.on('segments.remove', this._onSegmentsRemove.bind(this));
55
- this._peaks.on('segments.remove_all', this._onSegmentsRemoveAll.bind(this));
56
- this._peaks.on('segments.dragend', this._onSegmentUpdated.bind(this));
57
- }
58
-
59
- Lines.prototype.fitToView = function() {
60
- this._lineIndicator.fitToView();
61
- };
62
-
63
- Lines.prototype._onSegmentsAdd = function(segments) {
64
- var self = this;
65
-
66
- segments.forEach(function(segment) {
67
- if (!self._segmentsGroups[segment.line]) {
68
- self._segmentsGroups[segment.line] = new SegmentsGroup(self._peaks, self._view, true);
69
- }
70
-
71
- self._segmentsGroups[segment.line].onSegmentsAdd([segment]);
72
- if (Utils.objectHasProperty(self._segmentsGroupToLine, segment.line)) {
73
- self._segmentsGroupToLine[segment.line].refreshSegmentsHeight();
74
- }
75
- });
76
- };
77
-
78
- Lines.prototype._onSegmentsUpdate = function(segment) {
79
- this._segmentsGroups[segment.line].onSegmentsUpdate(segment);
80
- };
81
-
82
- Lines.prototype._onSegmentUpdated = function(segment) {
83
- this._segmentsGroups[segment.line].onSegmentUpdated();
84
- };
85
-
86
- Lines.prototype._onSegmentsRemove = function(segments) {
87
- var self = this;
88
-
89
- segments.forEach(function(segment) {
90
- self._segmentsGroups[segment.line].onSegmentsRemove([segment]);
91
- });
92
- };
93
-
94
- Lines.prototype._onSegmentsRemoveAll = function(lineId) {
95
- this._segmentsGroups[lineId].onSegmentsRemoveAll();
96
-
97
- if (Utils.objectHasProperty(this._segmentsGroupToLine, lineId)) {
98
- this._segmentsGroupToLine[lineId].refreshSegmentsHeight();
99
- }
100
- };
101
-
102
- Lines.prototype._onLineHeightChanged = function(position) {
103
- this._updateLinesPosition(position);
104
- this._view.updateTimeline();
105
- };
106
-
107
- Lines.prototype._onLineAdd = function(position) {
108
- this._createLine(position);
109
- this._setInteractions(position);
110
- this._updateLinesPosition(position);
111
- };
112
-
113
- Lines.prototype._onLineRemove = function(position) {
114
- this.removeLine(position);
115
- this._updateLinesPosition(position);
116
- };
117
-
118
- Lines.prototype._onSourcesWrappingChanged = function(sources) {
119
- sources.forEach(function(source) {
120
- if (this._linesByPosition[source.position]) {
121
- this._linesByPosition[source.position].updateLineHeight(source, 'wrappingChanged');
122
- }
123
- }.bind(this));
124
- };
125
-
126
- Lines.prototype.changeLineHeight = function(from, to) {
127
- for (var position in this._linesByPosition) {
128
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
129
- if (!this._linesByPosition[position].isSegmentsLine()) {
130
- this._linesByPosition[position].changeHeight(from, to);
131
- }
132
- }
133
- }
134
- };
135
-
136
- Lines.prototype.addSourceGroup = function(source, sourceGroup, position) {
137
- if (!this._linesByPosition[position] || this._linesByPosition[position].isSegmentsLine()) {
138
- this._createLine(position);
139
- this._setInteractions(position);
140
- }
141
-
142
- source.position = position;
143
- this._linesByPosition[position].addSourceGroup(source, sourceGroup);
144
- };
145
-
146
- Lines.prototype.addSegments = function(lineId, position) {
147
- this._createLine(position);
148
-
149
- this._linesByPosition[position].allowInteractions(this._areSegmentInteractionsAllowed);
150
- this._linesByPosition[position].addSegments(this._segmentsGroups[lineId]);
151
-
152
- this._segmentsGroupToLine[lineId] = this._linesByPosition[position];
153
-
154
- this._setInteractions(position);
155
-
156
- this._updateLinesPosition(position);
157
- };
158
-
159
- Lines.prototype.removeSourceGroup = function(source, isPermanent) {
160
- if (!this._linesByPosition[source.position]) {
161
- return null;
162
- }
163
-
164
- var sourceGroup = this._linesByPosition[source.position].removeSourceGroup(source, isPermanent);
165
-
166
- if (isPermanent) {
167
- this._updateLinesPosition(source.position);
168
- }
169
-
170
- return sourceGroup;
171
- };
172
-
173
- Lines.prototype.removeLine = function(pos) {
174
- var oldLine = this._linesByPosition[pos];
175
- var lineId = oldLine.getId();
176
-
177
- if (this._automaticallyCreatedLineId === lineId) {
178
- this._automaticallyCreatedLineId = null;
179
- }
180
- oldLine.destroy();
181
-
182
- delete this._linesByPosition[pos];
183
-
184
- this._lineIndicator.removeIndicator(lineId, false);
185
-
186
- return oldLine;
187
- };
188
-
189
- Lines.prototype.isLineVisible = function(position) {
190
- return this._linesByPosition[position] ? this._linesByPosition[position].isVisible() : false;
191
- };
192
-
193
- Lines.prototype.getVisibleLines = function() {
194
- var positions = {};
195
-
196
- for (var position in this._linesByPosition) {
197
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
198
- if (this._linesByPosition[position].isVisible()) {
199
- positions[position] = true;
200
- }
201
- }
202
- }
203
- return positions;
204
- };
205
-
206
- Lines.prototype.getSourcesOnLineAfter = function(lineId, time) {
207
- return this._linesByPosition[lineId].getSourcesAfter(time);
208
- };
209
-
210
- Lines.prototype.getSegmentsGroups = function() {
211
- return this._segmentsGroups;
212
- };
213
-
214
- Lines.prototype.addToLayer = function(layer) {
215
- for (var position in this._linesByPosition) {
216
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
217
- this._linesByPosition[position].addToLayer(layer);
218
- }
219
- }
220
-
221
- this._autoAddToLayer = true;
222
- };
223
-
224
- Lines.prototype.updateLines = function(position) {
225
- this._updateLinesPosition(position);
226
- };
227
-
228
- Lines.prototype._updateLinesPosition = function(position) {
229
- var line = this._linesByPosition[position];
230
- var dy = null;
231
- var newY;
232
-
233
- if (line) {
234
- newY = line.getY() + line.lineHeight() + this._peaks.options.interline;
235
- }
236
- else {
237
- var previousLine;
238
-
239
- while ((previousLine === undefined || previousLine === null) && position > 0) {
240
- previousLine = this._linesByPosition[--position];
241
- }
242
-
243
- newY = previousLine ? previousLine.getY() + previousLine.lineHeight() + this._peaks.options.interline : 0;
244
- }
245
-
246
- for (var pos in this._linesByPosition) {
247
- if (Utils.objectHasProperty(this._linesByPosition, pos)) {
248
- if (parseInt(pos, 10) > position) {
249
- if (dy === null) {
250
- dy = newY - this._linesByPosition[pos].getY();
251
- this._linesByPosition[pos].moveOnY(dy);
252
- }
253
- else {
254
- this._linesByPosition[pos].moveOnY(dy);
255
- }
256
- }
257
- }
258
- }
259
-
260
- this._lineIndicator.updateIndicators();
261
- this._lineIndicator.draw();
262
- this._view.refresh();
263
- };
264
-
265
- Lines.prototype.setOffsetY = function(frameOffset) {
266
- for (var position in this._linesByPosition) {
267
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
268
- var line = this._linesByPosition[position];
269
-
270
- line.y(line.getInitialY() - frameOffset);
271
- }
272
- }
273
-
274
- this._lineIndicator.updateIndicators();
275
- this._lineIndicator.draw();
276
- };
277
-
278
- Lines.prototype.height = function() {
279
- var height = 2 * this._peaks.options.padding;
280
-
281
- for (var position in this._linesByPosition) {
282
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
283
- height += this._linesByPosition[position].lineHeight() + this._peaks.options.interline;
284
- }
285
- }
286
-
287
- height -= this._peaks.options.interline;
288
-
289
- return height;
290
- };
291
-
292
- Lines.prototype.linesLength = function() {
293
- var length = 0;
294
-
295
- for (var position in this._linesByPosition) {
296
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
297
- var lineLength = this._linesByPosition[position].lineLength();
298
-
299
- if (lineLength > length) {
300
- length = lineLength;
301
- }
302
- }
303
- }
304
-
305
- return length;
306
- };
307
-
308
- Lines.prototype.stopAutomaticLineCreation = function() {
309
- if (this._automaticLineCreationTimeout) {
310
- clearTimeout(this._automaticLineCreationTimeout);
311
- }
312
- this._automaticLineCreationTimeout = null;
313
- this._automaticLineCreationPosition = null;
314
- this._automaticallyCreatedLineId = null;
315
- };
316
-
317
- Lines.prototype.manageAutomaticLineCreation = function(newLinePosition, initialPosition, sources) {
318
- if (this._automaticallyCreatedLineId !== null) {
319
- return;
320
- }
321
- else if (
322
- this._automaticLineCreationPosition !== null
323
- && this._automaticLineCreationPosition !== newLinePosition
324
- ) {
325
- this.stopAutomaticLineCreation();
326
- }
327
-
328
- if (this._automaticLineCreationTimeout) {
329
- return;
330
- }
331
-
332
- this._automaticLineCreationPosition = newLinePosition;
333
- this._automaticLineCreationTimeout = setTimeout(function() {
334
- this._automaticLineCreationTimeout = null;
335
-
336
- var currentLine = this._linesByPosition[initialPosition];
337
-
338
- if (currentLine.countRemainingElements() === sources.length) {
339
- this.stopAutomaticLineCreation();
340
- return;
341
- }
342
-
343
- this._automaticallyCreatedLineId = this._createLine(newLinePosition);
344
- this._setInteractions(newLinePosition);
345
- this.moveSourcesToPosition(sources, currentLine.getPosition(), newLinePosition);
346
- }.bind(this), this._peaks.options.automaticLineCreationDelay);
347
- };
348
-
349
- Lines.prototype.manageVerticalPosition = function(sources, startTime, endTime, mouseX, mouseY) {
350
- if (mouseX === null || mouseX === undefined) {
351
- return;
352
- }
353
-
354
- const position = sources[0].position;
355
- const linePos = this.getLinesUnderY(mouseY);
356
-
357
- if (linePos[0] !== linePos[1]) {
358
- this.manageAutomaticLineCreation(linePos[0] + 1, position, sources);
359
- }
360
- else {
361
- this.stopAutomaticLineCreation();
362
-
363
- if (
364
- mouseX !== null && mouseX !== undefined
365
- && linePos[0] !== position
366
- && !this._linesByPosition[linePos[0]].isSegmentsLine()
367
- ) {
368
- var mouseTime = this._view.pixelsToTime(mouseX + this._view.getFrameOffset());
369
- var sourceDuration = Utils.roundTime(endTime - startTime);
370
-
371
- if (this._hasSpaceForSourceAt(linePos[0], mouseTime, sourceDuration)) {
372
- this.moveSourcesToPosition(sources, position, linePos[0]);
373
- }
374
- }
375
- }
376
- };
377
-
378
- Lines.prototype._hasSpaceForSourceAt = function(linePosition, mouseTime, sourceDuration) {
379
- var line = this._linesByPosition[linePosition];
380
-
381
- if (!line || line.isSegmentsLine()) {
382
- return false;
383
- }
384
-
385
- var sourcesAround = line.getSourcesAround(mouseTime);
386
-
387
- if (sourcesAround.overlapping) {
388
- return false;
389
- }
390
- else if (!sourcesAround.right) {
391
- return true;
392
- }
393
- else {
394
- var leftLimit = sourcesAround.left ? sourcesAround.left.endTime : 0;
395
- var rightLimit = sourcesAround.right.startTime;
396
-
397
- return sourceDuration <= Utils.roundTime(rightLimit - leftLimit);
398
- }
399
- };
400
-
401
- Lines.prototype.getLineByPosition = function(pos) {
402
- return this._linesByPosition[pos];
403
- };
404
-
405
- Lines.prototype.getLastPosition = function() {
406
- var keys = Object.keys(this._linesByPosition);
407
-
408
- return keys.pop();
409
- };
410
-
411
- Lines.prototype.getLinesUnderY = function(y) {
412
- var height;
413
- var pos = [-1, this.getLastPosition() + 1];
414
-
415
- for (var position in this._linesByPosition) {
416
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
417
- height = this._linesByPosition[position].lineHeight();
418
-
419
- if (y > this._linesByPosition[position].getY()) {
420
- pos[0] = Math.max(pos[0], parseInt(position, 10));
421
- }
422
-
423
- if (y < this._linesByPosition[position].getY() + height) {
424
- pos[1] = Math.min(pos[1], parseInt(position, 10));
425
- }
426
- }
427
- }
428
-
429
- return pos;
430
- };
431
-
432
- Lines.prototype.moveSourcesToPosition = function(sources, initialPosition, targetPosition) {
433
- sources.forEach(function(source) {
434
- var sourceGroup = this._linesByPosition[initialPosition].removeSourceGroup(source, true);
435
-
436
- if (sourceGroup) {
437
- sourceGroup.moveTo(this._linesByPosition[targetPosition].getKonvaGroup());
438
- }
439
-
440
- this.addSourceGroup(source, sourceGroup, targetPosition);
441
- }.bind(this));
442
-
443
- this._updateLinesPosition(initialPosition);
444
- };
445
-
446
- Lines.prototype._getNextLineId = function() {
447
- this._lineId++;
448
- return this._lineId;
449
- };
450
-
451
- Lines.prototype._createLine = function(position) {
452
- var y = this._peaks.options.padding;
453
- var currentPos;
454
- var newLinesByPosition = Object.assign({},this._linesByPosition);
455
-
456
- for (var pos in this._linesByPosition) {
457
- if (Utils.objectHasProperty(this._linesByPosition, pos)) {
458
- currentPos = parseInt(pos, 10);
459
- if (currentPos < position) {
460
- y += this._linesByPosition[pos].lineHeight() + this._peaks.options.interline;
461
- }
462
- else {
463
- // This code assumes that lines are ordered in ascending order of position
464
- // This is the case as the keys are integers
465
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
466
- var newPosition = currentPos + 1;
467
-
468
- this._linesByPosition[currentPos].updatePosition(newPosition);
469
- newLinesByPosition[newPosition] = this._linesByPosition[currentPos];
470
-
471
- if (!this._linesByPosition[newPosition]) {
472
- break;
473
- }
474
- }
475
- }
476
- }
477
- }
478
-
479
- var line = new Line(this._peaks, this._view, y, this._getNextLineId(), position);
480
-
481
- this._lineIndicator.addIndicator(line);
482
-
483
- if (this._autoAddToLayer) {
484
- line.addToLayer(this._layer);
485
- }
486
-
487
- newLinesByPosition[position] = line;
488
- this._linesByPosition = newLinesByPosition;
489
-
490
- return line.getId();
491
- };
492
-
493
- Lines.prototype.updateSegments = function(frameStartTime, frameEndTime) {
494
- for (var lineId in this._segmentsGroups) {
495
- if (Utils.objectHasProperty(this._segmentsGroups, lineId)) {
496
- this._segmentsGroups[lineId].updateSegments(frameStartTime, frameEndTime);
497
- }
498
- }
499
- };
500
-
501
- Lines.prototype.manageCollision = function(sources, newStartTime, newEndTime) {
502
- return this._linesByPosition[sources[0].position].manageCollision(sources, newStartTime, newEndTime);
503
- };
504
-
505
- Lines.prototype.manageOrder = function(sources, startTime, endTime) {
506
- // Assuming all ordered elements have the same position
507
- return this._linesByPosition[sources[0].position].manageOrder(sources, startTime, endTime);
508
- };
509
-
510
- Lines.prototype._setInteractions = function(position) {
511
- var line = this._linesByPosition[position];
512
-
513
- if (this._areInteractionsOverridden) {
514
- line.allowInteractions(this._areInteractionsAllowed);
515
- }
516
- else {
517
- line.allowInteractions(
518
- line.isSegmentsLine() ?
519
- this._areSegmentInteractionsAllowed :
520
- this._areSourceInteractionsAllowed
521
- );
522
- }
523
- };
524
-
525
- Lines.prototype.overrideInteractions = function(bool, areInteractionsAllowed) {
526
- this._areInteractionsOverridden = typeof bool !== 'undefined' ?
527
- bool : this._areInteractionsOverridden;
528
- this._areInteractionsAllowed = typeof areInteractionsAllowed !== 'undefined' ?
529
- areInteractionsAllowed : this._areInteractionsAllowed;
530
- for (var position in this._linesByPosition) {
531
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
532
- this._setInteractions(position);
533
- }
534
- }
535
- };
536
-
537
- Lines.prototype.allowInteractions = function(forSources, forSegments) {
538
- this._areSourceInteractionsAllowed = typeof forSources !== 'undefined' ?
539
- forSources : this._areSourceInteractionsAllowed;
540
- this._areSegmentInteractionsAllowed = typeof forSegments !== 'undefined' ?
541
- forSegments : this._areSegmentInteractionsAllowed;
542
- for (var position in this._linesByPosition) {
543
- if (Utils.objectHasProperty(this._linesByPosition, position)) {
544
- this._setInteractions(position);
545
- }
546
- }
547
- };
548
-
549
- return Lines;
550
- });
File without changes
File without changes
File without changes