@checksub_team/peaks_timeline 1.16.1 → 2.0.0-alpha.10

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 +4691 -4380
  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 +696 -0
  9. package/src/components/line-groups.js +591 -0
  10. package/src/{line-indicator.js → components/line-indicator.js} +313 -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} +1663 -1640
  18. package/src/{sources-layer.js → components/sources-layer.js} +722 -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 +180 -0
  23. package/src/main.js +109 -82
  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 -143
  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
@@ -1,303 +1,313 @@
1
- /**
2
- * @file
3
- *
4
- * Defines the {@link LineIndicator} class.
5
- *
6
- * @module line-indicator
7
- */
8
-
9
- define([
10
- 'konva',
11
- './utils',
12
- './svgs'
13
- ], function(
14
- Konva,
15
- Utils,
16
- SVGs) {
17
- 'use strict';
18
-
19
- /**
20
- * Creates a Konva.Stage that displays a representation of each line.
21
- *
22
- * @class
23
- * @alias LineIndicator
24
- *
25
- * @param {Peaks} peaks
26
- * @param {WaveformOverview|WaveformZoomView} view
27
- */
28
-
29
- function LineIndicator(peaks, view, container) {
30
- this._peaks = peaks;
31
- this._view = view;
32
- this._container = container;
33
-
34
- this._width = this._peaks.options.lineIndicatorWidth;
35
- this._height = this._view.getHeight();
36
-
37
- this._sizes = {
38
- font: this._peaks.options.lineIndicatorFontSize,
39
- icon: {
40
- default: this._peaks.options.lineIndicatorDefaultIconSize,
41
- volume: this._peaks.options.lineIndicatorVolumeIconSize,
42
- noVolume: this._peaks.options.lineIndicatorNoVolumeIconSize,
43
- visibility: this._peaks.options.lineIndicatorVisibilityIconSize,
44
- noVisibility: this._peaks.options.lineIndicatorNoVisibilityIconSize
45
- }
46
- };
47
-
48
- this._yPadding = 30;
49
- this._defaultPadding = 5;
50
- this._types = ['default'].concat(Object.keys(SVGs));
51
-
52
- this._stage = new Konva.Stage({
53
- container: container,
54
- width: this._width,
55
- height: this._height
56
- });
57
- this._layer = new Konva.Layer();
58
- this._stage.add(this._layer);
59
-
60
- this._indicators = {};
61
-
62
- this._separatingLine = new Konva.Line({
63
- points: [this._width, 0, this._width, this._height],
64
- stroke: 'gray',
65
- strokeWidth: 1,
66
- listening: false
67
- });
68
-
69
- this._layer.add(this._separatingLine);
70
-
71
- this._layer.draw();
72
-
73
- this._peaks.on('lineIndicator.setType', this._onSetType.bind(this));
74
- this._peaks.on('lineIndicator.setText', this._onSetText.bind(this));
75
- }
76
-
77
- LineIndicator.prototype.fitToView = function() {
78
- this._height = this._view.getHeight();
79
-
80
- this._stage.height(this._height);
81
-
82
- this._separatingLine.points([this._width, 0, this._width, this._height]);
83
- };
84
-
85
- LineIndicator.prototype._onSetType = function(lineId, type) {
86
- this.removeIndicator(lineId, true);
87
-
88
- type = this._types.includes(type) ? type : 'default';
89
-
90
- var indicator = this._createIndicator(
91
- this._indicators[lineId].line,
92
- type,
93
- this._indicators[lineId].text
94
- );
95
-
96
- this._layer.add(indicator);
97
-
98
- this._indicators[lineId].indicator = indicator;
99
- this._indicators[lineId].type = type;
100
-
101
- this.draw();
102
- };
103
-
104
- LineIndicator.prototype._onSetText = function(lineId, text) {
105
- this.removeIndicator(lineId, true);
106
-
107
- var indicator = this._createIndicator(
108
- this._indicators[lineId].line,
109
- this._indicators[lineId].type,
110
- text
111
- );
112
-
113
- this._layer.add(indicator);
114
-
115
- this._indicators[lineId].indicator = indicator;
116
- this._indicators[lineId].text = text;
117
-
118
- this.draw();
119
- };
120
-
121
- LineIndicator.prototype._showMenu = function(menu) {
122
- menu.style.display = 'block';
123
- var containerRect = this._stage.container().getBoundingClientRect();
124
-
125
- menu.style.top = containerRect.top
126
- + this._stage.getPointerPosition().y
127
- - menu.offsetHeight + 'px';
128
- menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
129
- };
130
-
131
- LineIndicator.prototype._createIndicator = function(line, type, text) {
132
- var indicator = new Konva.Group();
133
- var indicatorHeight = 0;
134
-
135
- if (text) {
136
- var textNode = new Konva.Text({
137
- text: text,
138
- fontSize: this._sizes.font,
139
- fontFamily: this._peaks.options.lineIndicatorFont,
140
- fill: this._peaks.options.lineIndicatorTextColor,
141
- align: 'center',
142
- width: this._width,
143
- listening: false
144
- });
145
-
146
- textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
147
- textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
148
-
149
- indicator.add(textNode);
150
- indicatorHeight += this._sizes.font;
151
- }
152
-
153
- type = this._types.includes(type) ? type : 'default';
154
-
155
- var iconNode;
156
-
157
- if (type === 'default') {
158
- var padding = text ? this._defaultPadding : 0;
159
-
160
- iconNode = new Konva.Circle({
161
- x: this._width / 2,
162
- y: indicatorHeight + this._sizes.icon.default / 2 + padding,
163
- radius: this._sizes.icon.default / 2,
164
- fill: this._peaks.options.lineIndicatorIconColor,
165
- strokeWidth: 0,
166
- lineId: line.getId(),
167
- listening: false
168
- });
169
-
170
- indicatorHeight += padding;
171
- }
172
- else {
173
- iconNode = new Konva.Path({
174
- x: (this._width - this._sizes.icon[type]) / 2,
175
- y: indicatorHeight,
176
- data: SVGs[type].path,
177
- fill: this._peaks.options.lineIndicatorIconColor,
178
- scale: {
179
- x: (this._sizes.icon[type]) / SVGs[type].width,
180
- y: (this._sizes.icon[type]) / SVGs[type].height
181
- },
182
- lineId: line.getId(),
183
- listening: false
184
- });
185
- }
186
-
187
- iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
188
- iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
189
-
190
- indicator.add(iconNode);
191
- indicatorHeight += this._sizes.icon[type];
192
-
193
- indicator.setAttr('trueHeight', indicatorHeight);
194
-
195
- var backgroundRect = new Konva.Rect({
196
- x: 0,
197
- y: 0,
198
- width: this._width,
199
- height: indicatorHeight,
200
- fill: 'transparent',
201
- listening: true
202
- });
203
-
204
- indicator.add(backgroundRect);
205
- backgroundRect.moveToTop();
206
-
207
- indicator.y(line.getY() + (line.lineHeight() - indicatorHeight) / 2);
208
-
209
- var self = this;
210
-
211
- indicator.on('mouseenter', function() {
212
- indicator.getChildren().forEach(function(child) {
213
- child.fill(child.getAttr('selectedColor'));
214
- });
215
- self.draw();
216
- self._stage.container().style.cursor = 'pointer';
217
- });
218
-
219
- indicator.on('mouseout', function() {
220
- indicator.getChildren().forEach(function(child) {
221
- child.fill(child.getAttr('defaultColor'));
222
- });
223
- self.draw();
224
- self._stage.container().style.cursor = 'default';
225
- });
226
-
227
- indicator.on('click', function(e) {
228
- self._peaks.emit('lineIndicator.click', self._indicators[line.getId()], e.evt);
229
- });
230
-
231
- return indicator;
232
- };
233
-
234
- LineIndicator.prototype.addIndicator = function(line) {
235
- if (!this._indicators[line.getId()]) {
236
- var indicator = this._createIndicator(line);
237
-
238
- this._layer.add(indicator);
239
-
240
- this._indicators[line.getId()] = {
241
- indicator: indicator,
242
- line: line,
243
- type: 'default'
244
- };
245
- }
246
- };
247
-
248
- LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
249
- if (this._indicators[lineId]) {
250
- if (this._indicators[lineId].indicator) {
251
- this._indicators[lineId].indicator.destroy();
252
- }
253
- if (!keepInList) {
254
- delete this._indicators[lineId];
255
- }
256
- else {
257
- this._indicators[lineId].indicator = null;
258
- }
259
- }
260
- };
261
-
262
- LineIndicator.prototype.updateIndicator = function(lineId) {
263
- if (this._indicators[lineId]) {
264
- var y = this._indicators[lineId].line.getY();
265
- var isVisible = y + this._indicators[lineId].line.lineHeight() + this._yPadding > 0
266
- && y - this._yPadding < this._height;
267
-
268
- if (isVisible) {
269
- if (!this._indicators[lineId].indicator) {
270
- this._indicators[lineId].indicator = this._createIndicator(
271
- this._indicators[lineId].line,
272
- this._indicators[lineId].type,
273
- this._indicators[lineId].text
274
- );
275
- this._layer.add(this._indicators[lineId].indicator);
276
- }
277
- else {
278
- this._indicators[lineId].indicator.y(
279
- y + this._indicators[lineId].line.lineHeight() / 2
280
- - this._indicators[lineId].indicator.getAttr('trueHeight') / 2
281
- );
282
- }
283
- }
284
- else {
285
- this.removeIndicator(lineId, true);
286
- }
287
- }
288
- };
289
-
290
- LineIndicator.prototype.updateIndicators = function() {
291
- for (var lineId in this._indicators) {
292
- if (Utils.objectHasProperty(this._indicators, lineId)) {
293
- this.updateIndicator(lineId);
294
- }
295
- }
296
- };
297
-
298
- LineIndicator.prototype.draw = function() {
299
- this._layer.draw();
300
- };
301
-
302
- return LineIndicator;
303
- });
1
+ /**
2
+ * @file
3
+ *
4
+ * Defines the {@link LineIndicator} class.
5
+ *
6
+ * @module line-indicator
7
+ */
8
+
9
+ define([
10
+ 'konva',
11
+ './svgs',
12
+ '../utils'
13
+ ], function(
14
+ Konva,
15
+ SVGs,
16
+ Utils) {
17
+ 'use strict';
18
+
19
+ /**
20
+ * Creates a Konva.Stage that displays a representation of each line.
21
+ *
22
+ * @class
23
+ * @alias LineIndicator
24
+ *
25
+ * @param {Peaks} peaks
26
+ * @param {WaveformOverview|WaveformZoomView} view
27
+ */
28
+
29
+ function LineIndicator(peaks, view, container) {
30
+ this._peaks = peaks;
31
+ this._view = view;
32
+ this._container = container;
33
+
34
+ this._width = this._peaks.options.lineIndicatorWidth;
35
+ this._height = this._view.getHeight();
36
+
37
+ this._sizes = {
38
+ font: this._peaks.options.lineIndicatorFontSize,
39
+ icon: {
40
+ default: this._peaks.options.lineIndicatorDefaultIconSize,
41
+ volume: this._peaks.options.lineIndicatorVolumeIconSize,
42
+ noVolume: this._peaks.options.lineIndicatorNoVolumeIconSize,
43
+ visibility: this._peaks.options.lineIndicatorVisibilityIconSize,
44
+ noVisibility: this._peaks.options.lineIndicatorNoVisibilityIconSize
45
+ }
46
+ };
47
+
48
+ this._yPadding = 30;
49
+ this._defaultPadding = 5;
50
+ this._types = ['default'].concat(Object.keys(SVGs));
51
+
52
+ this._stage = new Konva.Stage({
53
+ container: container,
54
+ width: this._width,
55
+ height: this._height
56
+ });
57
+ this._layer = new Konva.Layer();
58
+ this._stage.add(this._layer);
59
+
60
+ this._indicators = {};
61
+
62
+ this._separatingLine = new Konva.Line({
63
+ points: [this._width, 0, this._width, this._height],
64
+ stroke: 'gray',
65
+ strokeWidth: 1,
66
+ listening: false
67
+ });
68
+
69
+ this._layer.add(this._separatingLine);
70
+
71
+ this._layer.draw();
72
+ }
73
+
74
+ LineIndicator.prototype.fitToView = function() {
75
+ this._height = this._view.getHeight();
76
+
77
+ this._stage.height(this._height);
78
+
79
+ this._separatingLine.points([this._width, 0, this._width, this._height]);
80
+
81
+ this.refreshIndicators();
82
+ };
83
+
84
+ LineIndicator.prototype._createIndicator = function(lineGroup, type, text) {
85
+ const indicator = new Konva.Group();
86
+ let indicatorHeight = 0;
87
+
88
+ if (text) {
89
+ const textNode = new Konva.Text({
90
+ text: text,
91
+ fontSize: this._sizes.font,
92
+ fontFamily: this._peaks.options.lineIndicatorFont,
93
+ fill: this._peaks.options.lineIndicatorTextColor,
94
+ align: 'center',
95
+ width: this._width,
96
+ listening: false
97
+ });
98
+
99
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
100
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
101
+
102
+ indicator.add(textNode);
103
+ indicatorHeight += this._sizes.font;
104
+ }
105
+
106
+ type = this._types.includes(type) ? type : 'default';
107
+
108
+ var iconNode;
109
+
110
+ if (type === 'default') {
111
+ var padding = text ? this._defaultPadding : 0;
112
+
113
+ iconNode = new Konva.Circle({
114
+ x: this._width / 2,
115
+ y: indicatorHeight + this._sizes.icon.default / 2 + padding,
116
+ radius: this._sizes.icon.default / 2,
117
+ fill: this._peaks.options.lineIndicatorIconColor,
118
+ strokeWidth: 0,
119
+ lineId: lineGroup.getId(),
120
+ listening: false
121
+ });
122
+
123
+ indicatorHeight += padding;
124
+ }
125
+ else {
126
+ iconNode = new Konva.Path({
127
+ x: (this._width - this._sizes.icon[type]) / 2,
128
+ y: indicatorHeight,
129
+ data: SVGs[type].path,
130
+ fill: this._peaks.options.lineIndicatorIconColor,
131
+ scale: {
132
+ x: (this._sizes.icon[type]) / SVGs[type].width,
133
+ y: (this._sizes.icon[type]) / SVGs[type].height
134
+ },
135
+ lineId: lineGroup.getId(),
136
+ listening: false
137
+ });
138
+ }
139
+
140
+ iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
141
+ iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
142
+
143
+ indicator.add(iconNode);
144
+ indicatorHeight += this._sizes.icon[type];
145
+
146
+ indicator.setAttr('trueHeight', indicatorHeight);
147
+
148
+ var backgroundRect = new Konva.Rect({
149
+ x: 0,
150
+ y: 0,
151
+ width: this._width,
152
+ height: indicatorHeight,
153
+ fill: 'transparent',
154
+ listening: true
155
+ });
156
+
157
+ indicator.add(backgroundRect);
158
+ backgroundRect.moveToTop();
159
+
160
+ indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
161
+
162
+ var self = this;
163
+
164
+ indicator.on('mouseenter', function() {
165
+ indicator.getChildren().forEach(function(child) {
166
+ child.fill(child.getAttr('selectedColor'));
167
+ });
168
+ self.draw();
169
+ self._stage.container().style.cursor = 'pointer';
170
+ });
171
+
172
+ indicator.on('mouseout', function() {
173
+ indicator.getChildren().forEach(function(child) {
174
+ child.fill(child.getAttr('defaultColor'));
175
+ });
176
+ self.draw();
177
+ self._stage.container().style.cursor = 'default';
178
+ });
179
+
180
+ indicator.on('click', function(e) {
181
+ self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
182
+ });
183
+
184
+ return indicator;
185
+ };
186
+
187
+ LineIndicator.prototype.addIndicator = function(lineGroup) {
188
+ var line = lineGroup.getLine();
189
+
190
+ if (!this._indicators[lineGroup.id]) {
191
+ const indicator = this._createIndicator(
192
+ lineGroup,
193
+ line.indicatorType,
194
+ line.indicatorText
195
+ );
196
+
197
+ this._layer.add(indicator);
198
+
199
+ this._indicators[line.id] = {
200
+ lineGroup: lineGroup,
201
+ indicator: indicator,
202
+ type: line.indicatorType
203
+ };
204
+ }
205
+ };
206
+
207
+ LineIndicator.prototype.updateIndicator = function(line) {
208
+ const indicatorData = this._indicators[line.id];
209
+
210
+ if (!indicatorData) {
211
+ this._peaks.logger('peaks.line-indicator.update(): line indicator not found: ' + line.id);
212
+ return;
213
+ }
214
+
215
+ if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText) {
216
+ return;
217
+ }
218
+
219
+ this.removeIndicator(line.id, true);
220
+
221
+ var indicator = this._createIndicator(
222
+ indicatorData.lineGroup,
223
+ line.indicatorType,
224
+ line.indicatorText
225
+ );
226
+
227
+ this._layer.add(indicator);
228
+
229
+ indicatorData.indicator = indicator;
230
+ indicatorData.type = line.indicatorType;
231
+ indicatorData.text = line.indicatorText;
232
+
233
+ this.draw();
234
+ };
235
+
236
+ LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
237
+ if (this._indicators[lineId]) {
238
+ if (this._indicators[lineId].indicator) {
239
+ this._indicators[lineId].indicator.destroy();
240
+ }
241
+ if (!keepInList) {
242
+ delete this._indicators[lineId];
243
+ }
244
+ else {
245
+ this._indicators[lineId].indicator = null;
246
+ }
247
+ }
248
+ };
249
+
250
+ LineIndicator.prototype.refreshIndicator = function(lineId) {
251
+ var anyChange = false;
252
+
253
+ if (this._indicators[lineId]) {
254
+ var y = this._indicators[lineId].lineGroup.y();
255
+ var isVisible = y + this._indicators[lineId].lineGroup.lineHeight() + this._yPadding > 0
256
+ && y - this._yPadding < this._height;
257
+ const hasNoIndicator = !this._indicators[lineId].indicator;
258
+
259
+ if (isVisible) {
260
+ if (hasNoIndicator) {
261
+ this._indicators[lineId].indicator = this._createIndicator(
262
+ this._indicators[lineId].lineGroup,
263
+ this._indicators[lineId].type,
264
+ this._indicators[lineId].text
265
+ );
266
+ this._layer.add(this._indicators[lineId].indicator);
267
+ anyChange = true;
268
+ }
269
+ else {
270
+ const newY = y
271
+ + this._indicators[lineId].lineGroup.lineHeight() / 2
272
+ - this._indicators[lineId].indicator.getAttr('trueHeight') / 2;
273
+
274
+ if (this._indicators[lineId].indicator.y() !== newY) {
275
+ this._indicators[lineId].indicator.y(
276
+ newY
277
+ );
278
+ anyChange = true;
279
+ }
280
+ }
281
+ }
282
+ else {
283
+ this.removeIndicator(lineId, true);
284
+ if (!hasNoIndicator) {
285
+ anyChange = true;
286
+ }
287
+ }
288
+ }
289
+
290
+ return anyChange;
291
+ };
292
+
293
+ LineIndicator.prototype.refreshIndicators = function() {
294
+ var anyChange = false;
295
+
296
+ for (var lineId in this._indicators) {
297
+ if (Utils.objectHasProperty(this._indicators, lineId)) {
298
+ anyChange = this.refreshIndicator(lineId) || anyChange;
299
+ }
300
+ }
301
+
302
+ if (anyChange) {
303
+ this.draw();
304
+ }
305
+ return anyChange;
306
+ };
307
+
308
+ LineIndicator.prototype.draw = function() {
309
+ this._layer.draw();
310
+ };
311
+
312
+ return LineIndicator;
313
+ });
@@ -8,7 +8,7 @@
8
8
 
9
9
  define([
10
10
  './default-segment-marker',
11
- './utils',
11
+ '../utils',
12
12
  'konva'
13
13
  ], function(
14
14
  DefaultSegmentMarker,