@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
@@ -1,303 +1,308 @@
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
+
82
+ LineIndicator.prototype._createIndicator = function(lineGroup, type, text) {
83
+ const indicator = new Konva.Group();
84
+ let indicatorHeight = 0;
85
+
86
+ if (text) {
87
+ const textNode = new Konva.Text({
88
+ text: text,
89
+ fontSize: this._sizes.font,
90
+ fontFamily: this._peaks.options.lineIndicatorFont,
91
+ fill: this._peaks.options.lineIndicatorTextColor,
92
+ align: 'center',
93
+ width: this._width,
94
+ listening: false
95
+ });
96
+
97
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
98
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
99
+
100
+ indicator.add(textNode);
101
+ indicatorHeight += this._sizes.font;
102
+ }
103
+
104
+ type = this._types.includes(type) ? type : 'default';
105
+
106
+ var iconNode;
107
+
108
+ if (type === 'default') {
109
+ var padding = text ? this._defaultPadding : 0;
110
+
111
+ iconNode = new Konva.Circle({
112
+ x: this._width / 2,
113
+ y: indicatorHeight + this._sizes.icon.default / 2 + padding,
114
+ radius: this._sizes.icon.default / 2,
115
+ fill: this._peaks.options.lineIndicatorIconColor,
116
+ strokeWidth: 0,
117
+ lineId: lineGroup.getId(),
118
+ listening: false
119
+ });
120
+
121
+ indicatorHeight += padding;
122
+ }
123
+ else {
124
+ iconNode = new Konva.Path({
125
+ x: (this._width - this._sizes.icon[type]) / 2,
126
+ y: indicatorHeight,
127
+ data: SVGs[type].path,
128
+ fill: this._peaks.options.lineIndicatorIconColor,
129
+ scale: {
130
+ x: (this._sizes.icon[type]) / SVGs[type].width,
131
+ y: (this._sizes.icon[type]) / SVGs[type].height
132
+ },
133
+ lineId: lineGroup.getId(),
134
+ listening: false
135
+ });
136
+ }
137
+
138
+ iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
139
+ iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
140
+
141
+ indicator.add(iconNode);
142
+ indicatorHeight += this._sizes.icon[type];
143
+
144
+ indicator.setAttr('trueHeight', indicatorHeight);
145
+
146
+ var backgroundRect = new Konva.Rect({
147
+ x: 0,
148
+ y: 0,
149
+ width: this._width,
150
+ height: indicatorHeight,
151
+ fill: 'transparent',
152
+ listening: true
153
+ });
154
+
155
+ indicator.add(backgroundRect);
156
+ backgroundRect.moveToTop();
157
+
158
+ indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
159
+
160
+ var self = this;
161
+
162
+ indicator.on('mouseenter', function() {
163
+ indicator.getChildren().forEach(function(child) {
164
+ child.fill(child.getAttr('selectedColor'));
165
+ });
166
+ self.draw();
167
+ self._stage.container().style.cursor = 'pointer';
168
+ });
169
+
170
+ indicator.on('mouseout', function() {
171
+ indicator.getChildren().forEach(function(child) {
172
+ child.fill(child.getAttr('defaultColor'));
173
+ });
174
+ self.draw();
175
+ self._stage.container().style.cursor = 'default';
176
+ });
177
+
178
+ indicator.on('click', function(e) {
179
+ self._peaks.emit('lineIndicator.click', self._indicators[lineGroup.getId()], e.evt);
180
+ });
181
+
182
+ return indicator;
183
+ };
184
+
185
+ LineIndicator.prototype.addIndicator = function(lineGroup) {
186
+ var line = lineGroup.getLine();
187
+
188
+ if (!this._indicators[lineGroup.id]) {
189
+ const indicator = this._createIndicator(
190
+ lineGroup,
191
+ line.indicatorType,
192
+ line.indicatorText
193
+ );
194
+
195
+ this._layer.add(indicator);
196
+
197
+ this._indicators[line.id] = {
198
+ lineGroup: lineGroup,
199
+ indicator: indicator,
200
+ type: line.indicatorType
201
+ };
202
+ }
203
+ };
204
+
205
+ LineIndicator.prototype.updateIndicator = function(line) {
206
+ const indicatorData = this._indicators[line.id];
207
+
208
+ if (!indicatorData) {
209
+ this._peaks.logger('peaks.line-indicator.update(): line indicator not found: ' + line.id);
210
+ return;
211
+ }
212
+
213
+ if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText) {
214
+ return;
215
+ }
216
+
217
+ this.removeIndicator(line.id, true);
218
+
219
+ var indicator = this._createIndicator(
220
+ indicatorData.lineGroup,
221
+ line.indicatorType,
222
+ line.indicatorText
223
+ );
224
+
225
+ this._layer.add(indicator);
226
+
227
+ indicatorData.indicator = indicator;
228
+ indicatorData.type = line.indicatorType;
229
+ indicatorData.text = line.indicatorText;
230
+
231
+ this.draw();
232
+ };
233
+
234
+ LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
235
+ if (this._indicators[lineId]) {
236
+ if (this._indicators[lineId].indicator) {
237
+ this._indicators[lineId].indicator.destroy();
238
+ }
239
+ if (!keepInList) {
240
+ delete this._indicators[lineId];
241
+ }
242
+ else {
243
+ this._indicators[lineId].indicator = null;
244
+ }
245
+ }
246
+ };
247
+
248
+ LineIndicator.prototype.refreshIndicator = function(lineId) {
249
+ var anyChange = false;
250
+
251
+ if (this._indicators[lineId]) {
252
+ var y = this._indicators[lineId].lineGroup.y();
253
+ var isVisible = y + this._indicators[lineId].lineGroup.lineHeight() + this._yPadding > 0
254
+ && y - this._yPadding < this._height;
255
+ const hasNoIndicator = !this._indicators[lineId].indicator;
256
+
257
+ if (isVisible) {
258
+ if (hasNoIndicator) {
259
+ this._indicators[lineId].indicator = this._createIndicator(
260
+ this._indicators[lineId].lineGroup,
261
+ this._indicators[lineId].type,
262
+ this._indicators[lineId].text
263
+ );
264
+ this._layer.add(this._indicators[lineId].indicator);
265
+ anyChange = true;
266
+ }
267
+ else {
268
+ const newY = y
269
+ + this._indicators[lineId].lineGroup.lineHeight() / 2
270
+ - this._indicators[lineId].indicator.getAttr('trueHeight') / 2;
271
+
272
+ if (this._indicators[lineId].indicator.y() !== newY) {
273
+ this._indicators[lineId].indicator.y(
274
+ newY
275
+ );
276
+ anyChange = true;
277
+ }
278
+ }
279
+ }
280
+ else {
281
+ this.removeIndicator(lineId, true);
282
+ if (!hasNoIndicator) {
283
+ anyChange = true;
284
+ }
285
+ }
286
+ }
287
+
288
+ return anyChange;
289
+ };
290
+
291
+ LineIndicator.prototype.refreshIndicators = function() {
292
+ var anyChange = false;
293
+
294
+ for (var lineId in this._indicators) {
295
+ if (Utils.objectHasProperty(this._indicators, lineId)) {
296
+ anyChange = this.refreshIndicator(lineId) || anyChange;
297
+ }
298
+ }
299
+
300
+ return anyChange;
301
+ };
302
+
303
+ LineIndicator.prototype.draw = function() {
304
+ this._layer.draw();
305
+ };
306
+
307
+ return LineIndicator;
308
+ });
@@ -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,