@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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/peaks.js +4716 -4409
  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/components/line-group.js +692 -0
  9. package/src/components/line-groups.js +585 -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 -801
  17. package/src/{source-group.js → components/source-group.js} +1661 -1640
  18. package/src/{sources-layer.js → components/sources-layer.js} +716 -730
  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 +110 -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} +1311 -1315
  27. package/src/player.js +2 -2
  28. package/src/{timeline-segments.js → segment-handler.js} +435 -435
  29. package/src/{timeline-sources.js → source-handler.js} +521 -514
  30. package/src/utils.js +5 -1
  31. package/src/{timeline-zoomview.js → view.js} +136 -137
  32. package/src/line.js +0 -690
  33. package/src/lines.js +0 -427
  34. /package/src/{data.js → components/data.js} +0 -0
  35. /package/src/{loader.js → components/loader.js} +0 -0
  36. /package/src/{mouse-drag-handler.js → components/mouse-drag-handler.js} +0 -0
  37. /package/src/{svgs.js → components/svgs.js} +0 -0
package/src/line.js DELETED
@@ -1,690 +0,0 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link line} class.
5
- *
6
- * @module line
7
- */
8
-
9
- define([
10
- 'konva',
11
- './utils'
12
- ], function(Konva, Utils) {
13
- 'use strict';
14
-
15
- function Line(peaks, view, y, id, position) {
16
- this._peaks = peaks;
17
- this._view = view;
18
-
19
- this._id = id;
20
- this._position = position;
21
-
22
- this._firstSourceId = null;
23
- this._sources = {};
24
-
25
- this._sourcesGroup = {};
26
- this._wrapped = false;
27
- this._y = y;
28
-
29
- this._group = new Konva.Group({
30
- x: 0,
31
- y: y - this._view.getFrameOffsetY(),
32
- draggable: true,
33
- dragBoundFunc: function() {
34
- return {
35
- x: this.absolutePosition().x,
36
- y: this.absolutePosition().y
37
- };
38
- }
39
- });
40
-
41
- this._sourceHeights = {};
42
- this._height = this._peaks.options.emptyLineHeight;
43
- this._unwrappedCount = 0;
44
- }
45
-
46
- Line.prototype.getPosition = function() {
47
- return this._position;
48
- };
49
-
50
- Line.prototype.getId = function() {
51
- return this._id;
52
- };
53
-
54
- Line.prototype.isEmpty = function() {
55
- return this.isSegmentsLine() ?
56
- this._segmentsGroup.isEmpty() :
57
- Object.keys(this._sources).length === 0;
58
- };
59
-
60
- Line.prototype.isSegmentsLine = function() {
61
- return Boolean(this._segmentsGroup);
62
- };
63
-
64
- Line.prototype.updateSegments = function(frameStartTime, frameEndTime) {
65
- if (this.isSegmentsLine()) {
66
- this._segmentsGroup.updateSegments(frameStartTime, frameEndTime);
67
- }
68
- };
69
-
70
- Line.prototype.lineLength = function() {
71
- var length = 0;
72
-
73
- if (this.isSegmentsLine()) {
74
- return this._segmentsGroup.getSegmentsGroupLength();
75
- }
76
-
77
- for (var sourceId in this._sources) {
78
- if (Utils.objectHasProperty(this._sources, sourceId)) {
79
- var sourceGroupLength = this._view.timeToPixels(
80
- this._sources[sourceId].source.endTime
81
- );
82
-
83
- if (sourceGroupLength > length) {
84
- length = sourceGroupLength;
85
- }
86
- }
87
- }
88
-
89
- return length;
90
- };
91
-
92
- Line.prototype.lineHeight = function() {
93
- return this._height;
94
- };
95
-
96
- Line.prototype.changeHeight = function(from, to) {
97
- if (this._sourceHeights[from]) {
98
- var oldHeight = this._height;
99
-
100
- if (this._sourceHeights[to]) {
101
- this._sourceHeights[to] += this._sourceHeights[from];
102
- }
103
- else {
104
- this._sourceHeights[to] = this._sourceHeights[from];
105
- }
106
-
107
- if (to > this._height) {
108
- this._height = to;
109
- }
110
- else if (from === this._height) {
111
- this._height = 0;
112
- for (var height in this._sourceHeights) {
113
- if (Utils.objectHasProperty(this._sourceHeights, height)) {
114
- var parsedHeight = parseInt(height, 10);
115
-
116
- if (parsedHeight !== from) {
117
- if (parsedHeight > this._height) {
118
- this._height = parsedHeight;
119
- }
120
- }
121
- }
122
- }
123
- }
124
-
125
- if (this._height !== oldHeight) {
126
- this._peaks.emit('line.heightChanged', this._position);
127
- }
128
-
129
- delete this._sourceHeights[from];
130
- }
131
- };
132
-
133
- Line.prototype.updateLineHeight = function(sourceGroup, action) {
134
- var oldHeight = this._height;
135
- var sourceGroupHeight;
136
-
137
- switch (action) {
138
- case 'add':
139
- sourceGroupHeight = sourceGroup.getCurrentHeight();
140
-
141
- if (this._sourceHeights[sourceGroupHeight]) {
142
- this._sourceHeights[sourceGroupHeight]++;
143
- }
144
- else {
145
- this._sourceHeights[sourceGroupHeight] = 1;
146
- if (sourceGroupHeight > this._height) {
147
- this._height = sourceGroupHeight;
148
- }
149
- }
150
- break;
151
- case 'remove':
152
- if (Object.keys(this._sources).length === 0) {
153
- this._height = this._peaks.options.emptyLineHeight;
154
- this._sourceHeights = {};
155
- }
156
- else {
157
- sourceGroupHeight = sourceGroup.getCurrentHeight();
158
-
159
- this._sourceHeights[sourceGroupHeight]--;
160
-
161
- if (this._sourceHeights[sourceGroupHeight] === 0
162
- && sourceGroupHeight === this._height) {
163
- delete this._sourceHeights[sourceGroupHeight];
164
- this._height = 0;
165
- for (var height in this._sourceHeights) {
166
- if (Utils.objectHasProperty(this._sourceHeights, height)) {
167
- var parsedHeight = parseInt(height, 10);
168
-
169
- if (parsedHeight > this._height) {
170
- this._height = parsedHeight;
171
- }
172
- }
173
- }
174
- }
175
- }
176
- break;
177
- }
178
-
179
- if (this._height !== oldHeight) {
180
- this._peaks.emit('line.heightChanged', this._position);
181
- }
182
- };
183
-
184
- Line.prototype.isVisible = function() {
185
- return this._y < this._view.getFrameOffsetY() + this._view.getHeight()
186
- && this._view.getFrameOffsetY() < this._y + this._height;
187
- };
188
-
189
- Line.prototype.addToLayer = function(layer) {
190
- layer.add(this._group);
191
- };
192
-
193
- Line.prototype.addSourceGroup = function(sourceGroup) {
194
- var source = sourceGroup.getSource();
195
-
196
- this._sourcesGroup[source.id] = sourceGroup;
197
-
198
- if (!this._sources[source.id]) {
199
- var newSource = {
200
- source: source,
201
- prevSourceId: null,
202
- nextSourceId: null
203
- };
204
-
205
- if (this._firstSourceId) {
206
- var currentSource = null;
207
-
208
- do {
209
- if (!currentSource) {
210
- currentSource = this._sources[this._firstSourceId];
211
- }
212
- else {
213
- currentSource = this._sources[currentSource.nextSourceId];
214
- }
215
-
216
- if (source.endTime <= currentSource.source.startTime) {
217
- var startLimit = currentSource.prevSourceId
218
- ? this._sources[currentSource.prevSourceId].source.endTime
219
- : 0;
220
-
221
- var newTimes = this._canBePlacedBetween(
222
- source.startTime,
223
- source.endTime,
224
- startLimit,
225
- currentSource.source.startTime
226
- );
227
-
228
- if (newTimes) {
229
- source.updateTimes(newTimes.start, newTimes.end);
230
-
231
- if (currentSource.prevSourceId) {
232
- this._sources[currentSource.prevSourceId].nextSourceId = source.id;
233
- newSource.prevSourceId = currentSource.prevSourceId;
234
- }
235
- else {
236
- this._firstSourceId = source.id;
237
- }
238
-
239
- currentSource.prevSourceId = source.id;
240
- newSource.nextSourceId = currentSource.source.id;
241
-
242
- this._sources[source.id] = newSource;
243
- break;
244
- }
245
- }
246
- } while (currentSource.nextSourceId);
247
-
248
- if (!newSource.prevSourceId && !newSource.nextSourceId) {
249
- if (source.startTime < currentSource.source.endTime) {
250
- // Overlapping with last source
251
- var timeWidth = source.endTime - source.startTime;
252
-
253
- source.updateTimes(
254
- currentSource.source.endTime,
255
- currentSource.source.endTime + timeWidth
256
- );
257
- }
258
- currentSource.nextSourceId = source.id;
259
- newSource.prevSourceId = currentSource.source.id;
260
- this._sources[source.id] = newSource;
261
- }
262
- }
263
- else {
264
- this._firstSourceId = source.id;
265
- this._sources[source.id] = newSource;
266
- }
267
-
268
- this.updateLineHeight(sourceGroup, 'add');
269
- }
270
-
271
- if (!sourceGroup.getParent() || !sourceGroup.isDescendantOf(this._group)) {
272
- sourceGroup.addToGroup(this._group);
273
- }
274
- };
275
-
276
- Line.prototype.addSegments = function(segmentsGroup) {
277
- this._segmentsGroup = segmentsGroup;
278
-
279
- this._height = this._segmentsGroup.getCurrentHeight();
280
-
281
- segmentsGroup.addToGroup(this._group);
282
- };
283
-
284
- Line.prototype.refreshSegmentsHeight = function() {
285
- if (this.isSegmentsLine) {
286
- var oldHeight = this._height;
287
-
288
- this._height = this._segmentsGroup.getCurrentHeight();
289
-
290
- if (this._height !== oldHeight) {
291
- this._peaks.emit('line.heightChanged', this._position);
292
- }
293
- }
294
- };
295
-
296
- Line.prototype._canBePlacedBetween = function(startTime, endTime, startLimit, endLimit) {
297
- var timeWidth = Utils.roundTime(endTime - startTime);
298
- var newTimes = null;
299
-
300
- if ((!endLimit && startTime > startLimit) || (startTime > startLimit && endTime < endLimit)) {
301
- // Can be placed at its wanted position with wanted start/end time
302
- newTimes = {
303
- start: startTime,
304
- end: endTime
305
- };
306
- }
307
- else if (Utils.roundTime(endLimit - startLimit) >= timeWidth) {
308
- // Can be placed at its wanted position but not with its wanted start/end time
309
- if (startTime > startLimit) {
310
- newTimes = {
311
- start: Utils.roundTime(endLimit - timeWidth),
312
- end: endLimit
313
- };
314
- }
315
- else {
316
- newTimes = {
317
- start: startLimit,
318
- end: Utils.roundTime(startLimit + timeWidth)
319
- };
320
- }
321
- }
322
-
323
- return newTimes;
324
- };
325
-
326
- Line.prototype.removeSourceGroup = function(source, isPermanent) {
327
- var sourceGroup = this._sourcesGroup[source.id];
328
-
329
- delete this._sourcesGroup[source.id];
330
-
331
- if (isPermanent) {
332
- if (this._sources[source.id].prevSourceId) {
333
- this._sources[this._sources[source.id].prevSourceId].nextSourceId
334
- = this._sources[source.id].nextSourceId;
335
- }
336
-
337
- if (this._sources[source.id].nextSourceId) {
338
- this._sources[this._sources[source.id].nextSourceId].prevSourceId
339
- = this._sources[source.id].prevSourceId;
340
- }
341
-
342
- if (this._firstSourceId === source.id) {
343
- this._firstSourceId = this._sources[source.id].nextSourceId;
344
- }
345
-
346
- delete this._sources[source.id];
347
-
348
- this.updateLineHeight(sourceGroup, 'remove');
349
- }
350
-
351
- return sourceGroup;
352
- };
353
-
354
- Line.prototype.getKonvaGroup = function() {
355
- return this._group;
356
- };
357
-
358
- Line.prototype.getY = function() {
359
- return this._group.y();
360
- };
361
-
362
- Line.prototype.getInitialY = function() {
363
- return this._y;
364
- };
365
-
366
- Line.prototype.y = function(value, changeInitialY) {
367
- this._group.y(value);
368
- if (changeInitialY) {
369
- this._y = value;
370
- }
371
- };
372
-
373
- Line.prototype.moveOnY = function(dy) {
374
- this._y += dy;
375
- this._group.y(this._group.y() + dy);
376
- };
377
-
378
- Line.prototype.manageSourceOrder = function(source, newTimes) {
379
- var cursorTime = this._view.pixelsToTime(this._view.getPointerPosition().x);
380
- var tmpTimes;
381
-
382
- var sourceDuration = source.endTime - source.startTime;
383
-
384
- if (newTimes.start !== null && newTimes.end !== null) {
385
- if (this._sources[source.id].prevSourceId) {
386
- // there is another source to the left
387
- var previousStartTime = this._sources[this._sources[source.id].prevSourceId].source.startTime;
388
-
389
- if (cursorTime + this._view.getTimeOffset() < previousStartTime) {
390
- // we want to change order
391
- tmpTimes = this._changeSourcePosition(
392
- source,
393
- sourceDuration,
394
- cursorTime + this._view.getTimeOffset()
395
- );
396
-
397
- if (tmpTimes) {
398
- newTimes.start = tmpTimes.start;
399
- newTimes.end = tmpTimes.end;
400
- }
401
- }
402
- }
403
-
404
- if (this._sources[source.id].nextSourceId) {
405
- // there is another source to the right
406
- var nextEndTime = this._sources[this._sources[source.id].nextSourceId].source.endTime;
407
-
408
- if (cursorTime + this._view.getTimeOffset() > nextEndTime) {
409
- // we want to change order
410
- tmpTimes = this._changeSourcePosition(
411
- source,
412
- sourceDuration,
413
- cursorTime + this._view.getTimeOffset()
414
- );
415
-
416
- if (tmpTimes) {
417
- newTimes.start = tmpTimes.start;
418
- newTimes.end = tmpTimes.end;
419
- }
420
- }
421
- }
422
- }
423
-
424
- if (newTimes.start) {
425
- newTimes.start = Utils.roundTime(newTimes.start);
426
- }
427
- if (newTimes.end) {
428
- newTimes.end = Utils.roundTime(newTimes.end);
429
- }
430
-
431
- return newTimes;
432
- };
433
-
434
- Line.prototype._changeSourcePosition = function(source, sourceDuration, time) {
435
- if (source.orderable && this._firstSourceId) {
436
- var currentRange = {
437
- start: null,
438
- end: null
439
- };
440
- var startLimit = null;
441
- var endLimit = null;
442
-
443
- do {
444
- if (!currentRange.end) {
445
- currentRange.end = this._sources[this._firstSourceId];
446
- }
447
- else {
448
- currentRange.start = currentRange.end;
449
- currentRange.end = this._sources[currentRange.start.nextSourceId];
450
- }
451
-
452
- if (currentRange.start) {
453
- startLimit = currentRange.start.source.endTime;
454
- }
455
- else {
456
- startLimit = 0;
457
- }
458
-
459
- if (currentRange.end) {
460
- endLimit = currentRange.end.source.startTime;
461
- }
462
- else {
463
- endLimit = null;
464
- }
465
-
466
- if (time > startLimit && (endLimit === null || time < endLimit)) {
467
- var newTimes = this._canBePlacedBetween(
468
- time,
469
- time + sourceDuration,
470
- startLimit,
471
- endLimit
472
- );
473
-
474
- if (newTimes) {
475
- if (newTimes.start) {
476
- newTimes.start = Utils.roundTime(newTimes.start);
477
- }
478
- if (newTimes.end) {
479
- newTimes.end = Utils.roundTime(newTimes.end);
480
- }
481
-
482
- source.updateTimes(
483
- newTimes.start,
484
- newTimes.end
485
- );
486
- var prevSourceId = currentRange.start
487
- ? currentRange.start.source.id
488
- : null;
489
-
490
- this._moveSource(this._sources[source.id].source, prevSourceId);
491
- return newTimes;
492
- }
493
- }
494
- } while (currentRange.end);
495
- }
496
-
497
- return null;
498
- };
499
-
500
- Line.prototype._moveSource = function(source, prevSourceId) {
501
- // Remove source from the list
502
- var sourceObj = this._sources[source.id];
503
- var prevSource = this._sources[sourceObj.prevSourceId];
504
- var nextSource = this._sources[sourceObj.nextSourceId];
505
-
506
- if (prevSource) {
507
- this._sources[sourceObj.prevSourceId].nextSourceId = sourceObj.nextSourceId;
508
- }
509
- else {
510
- this._firstSourceId = sourceObj.nextSourceId;
511
- }
512
-
513
- if (nextSource) {
514
- this._sources[sourceObj.nextSourceId].prevSourceId = sourceObj.prevSourceId;
515
- }
516
-
517
- delete this._sources[source.id];
518
-
519
- // Add source back to the list
520
- sourceObj.prevSourceId = prevSourceId;
521
-
522
- if (prevSourceId) {
523
- sourceObj.nextSourceId = this._sources[prevSourceId].nextSourceId;
524
- this._sources[prevSourceId].nextSourceId = source.id;
525
- }
526
- else {
527
- sourceObj.nextSourceId = this._firstSourceId;
528
- this._firstSourceId = source.id;
529
- }
530
-
531
- if (sourceObj.nextSourceId) {
532
- this._sources[sourceObj.nextSourceId].prevSourceId = source.id;
533
- }
534
-
535
- this._sources[source.id] = sourceObj;
536
- };
537
-
538
- Line.prototype.manageCollision = function(source, newTimes) {
539
- var originalStartTime = null;
540
- var originalEndTime = null;
541
- var newStartTime = null;
542
- var newEndTime = null;
543
- var startLimited = false;
544
- var endLimited = false;
545
-
546
- newTimes.updateTimelineLength = false;
547
-
548
- if (newTimes.start !== null) {
549
- // startMarker changed
550
- originalStartTime = newTimes.start;
551
- newStartTime = originalStartTime;
552
-
553
- if (source.startTime > newStartTime) {
554
- // startMarker moved to the left
555
- if (this._sources[source.id].prevSourceId) {
556
- // there is another source to the left
557
- var previousSource = this._sources[this._sources[source.id].prevSourceId]
558
- .source;
559
-
560
- if (newStartTime < previousSource.endTime) {
561
- // there is collision
562
- newStartTime = previousSource.endTime;
563
- startLimited = true;
564
- }
565
- }
566
- else {
567
- if (newStartTime < 0) {
568
- newStartTime = 0;
569
- startLimited = true;
570
- }
571
- }
572
- }
573
- }
574
-
575
- if (newTimes.end !== null) {
576
- // endMarker changed
577
- originalEndTime = newTimes.end;
578
- newEndTime = originalEndTime;
579
-
580
- if (source.endTime < newEndTime) {
581
- // endMarker moved to the right
582
- if (this._sources[source.id].nextSourceId) {
583
- // there is another source to the right
584
- var nextSource = this._sources[this._sources[source.id].nextSourceId]
585
- .source;
586
-
587
- if (newEndTime > nextSource.startTime) {
588
- // there is collision
589
- newEndTime = nextSource.startTime;
590
- endLimited = true;
591
- }
592
- }
593
- }
594
- }
595
-
596
- // Update the other edge if dragging and collision
597
- if (newStartTime !== null && newEndTime !== null) {
598
- var timeWidth = originalEndTime - originalStartTime;
599
-
600
- if (startLimited) {
601
- newEndTime = Utils.roundTime(newStartTime + timeWidth);
602
- }
603
-
604
- if (endLimited) {
605
- newStartTime = Utils.roundTime(newEndTime - timeWidth);
606
- }
607
- }
608
-
609
- // Check for minimal size of source
610
- if (newStartTime !== null && newEndTime === null) {
611
- if (Utils.roundTime(source.endTime - newStartTime) < source.minSize) {
612
- newStartTime = Utils.roundTime(source.endTime - source.minSize);
613
- }
614
- }
615
- else if (newEndTime !== null && newStartTime === null) {
616
- if (Utils.roundTime(newEndTime - source.startTime) < source.minSize) {
617
- newEndTime = Utils.roundTime(source.startTime + source.minSize);
618
- }
619
- }
620
- else {
621
- if (Utils.roundTime(newEndTime - newStartTime) < source.minSize) {
622
- if (source.endTime !== newEndTime) {
623
- newEndTime = Utils.roundTime(newStartTime + source.minSize);
624
- }
625
- if (source.startTime !== newStartTime) {
626
- newStartTime = Utils.roundTime(newEndTime - source.minSize);
627
- }
628
- }
629
- }
630
-
631
- if (newStartTime !== null && newStartTime !== originalStartTime) {
632
- newTimes.start = newStartTime;
633
- }
634
-
635
- if (newEndTime !== null && newEndTime !== originalEndTime) {
636
- newTimes.end = newEndTime;
637
-
638
- if (this._sources[source.id].nextSourceId === null) {
639
- newTimes.updateTimelineLength = true;
640
- }
641
- }
642
-
643
- return newTimes;
644
- };
645
-
646
- Line.prototype.getSourcesAfter = function(time) {
647
- const sources = [];
648
- var currentId = this._firstSourceId;
649
-
650
- while (currentId) {
651
- var lineSource = this._sources[currentId];
652
-
653
- if (lineSource.source.startTime >= time) {
654
- while (currentId) {
655
- lineSource = this._sources[currentId];
656
-
657
- sources.push(lineSource.source);
658
- currentId = lineSource.nextSourceId;
659
- }
660
- break;
661
- }
662
- currentId = lineSource.nextSourceId;
663
- }
664
-
665
- return sources;
666
- };
667
-
668
- Line.prototype.updatePosition = function(pos) {
669
- for (var sourceId in this._sources) {
670
- if (Utils.objectHasProperty(this._sources, sourceId)) {
671
- this._sources[sourceId].source.position = pos;
672
- }
673
- }
674
-
675
- this._position = pos;
676
- };
677
-
678
- Line.prototype.destroy = function() {
679
- this._firstSourceId = null;
680
- this._sources = {};
681
- this._sourcesGroup = {};
682
- this._group.destroy();
683
- };
684
-
685
- Line.prototype.allowInteractions = function(bool) {
686
- this._group.listening(bool);
687
- };
688
-
689
- return Line;
690
- });