@checksub_team/peaks_timeline 1.16.0-alpha.2 → 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 +4160 -3938
  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} +192 -187
  9. package/src/components/line-groups.js +584 -0
  10. package/src/{line-indicator.js → components/line-indicator.js} +308 -293
  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 -1645
  18. package/src/{sources-layer.js → components/sources-layer.js} +716 -704
  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 -64
  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 -533
  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
@@ -1,293 +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._createIndicator = function(line, type, text) {
122
- var indicator = new Konva.Group();
123
- var indicatorHeight = 0;
124
-
125
- if (text) {
126
- var textNode = new Konva.Text({
127
- text: text,
128
- fontSize: this._sizes.font,
129
- fontFamily: this._peaks.options.lineIndicatorFont,
130
- fill: this._peaks.options.lineIndicatorTextColor,
131
- align: 'center',
132
- width: this._width,
133
- listening: false
134
- });
135
-
136
- textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
137
- textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
138
-
139
- indicator.add(textNode);
140
- indicatorHeight += this._sizes.font;
141
- }
142
-
143
- type = this._types.includes(type) ? type : 'default';
144
-
145
- var iconNode;
146
-
147
- if (type === 'default') {
148
- var padding = text ? this._defaultPadding : 0;
149
-
150
- iconNode = new Konva.Circle({
151
- x: this._width / 2,
152
- y: indicatorHeight + this._sizes.icon.default / 2 + padding,
153
- radius: this._sizes.icon.default / 2,
154
- fill: this._peaks.options.lineIndicatorIconColor,
155
- strokeWidth: 0,
156
- lineId: line.getId(),
157
- listening: false
158
- });
159
-
160
- indicatorHeight += padding;
161
- }
162
- else {
163
- iconNode = new Konva.Path({
164
- x: (this._width - this._sizes.icon[type]) / 2,
165
- y: indicatorHeight,
166
- data: SVGs[type].path,
167
- fill: this._peaks.options.lineIndicatorIconColor,
168
- scale: {
169
- x: (this._sizes.icon[type]) / SVGs[type].width,
170
- y: (this._sizes.icon[type]) / SVGs[type].height
171
- },
172
- lineId: line.getId(),
173
- listening: false
174
- });
175
- }
176
-
177
- iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
178
- iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
179
-
180
- indicator.add(iconNode);
181
- indicatorHeight += this._sizes.icon[type];
182
-
183
- indicator.setAttr('trueHeight', indicatorHeight);
184
-
185
- var backgroundRect = new Konva.Rect({
186
- x: 0,
187
- y: 0,
188
- width: this._width,
189
- height: indicatorHeight,
190
- fill: 'transparent',
191
- listening: true
192
- });
193
-
194
- indicator.add(backgroundRect);
195
- backgroundRect.moveToTop();
196
-
197
- indicator.y(line.getY() + (line.lineHeight() - indicatorHeight) / 2);
198
-
199
- var self = this;
200
-
201
- indicator.on('mouseenter', function() {
202
- indicator.getChildren().forEach(function(child) {
203
- child.fill(child.getAttr('selectedColor'));
204
- });
205
- self.draw();
206
- self._stage.container().style.cursor = 'pointer';
207
- });
208
-
209
- indicator.on('mouseout', function() {
210
- indicator.getChildren().forEach(function(child) {
211
- child.fill(child.getAttr('defaultColor'));
212
- });
213
- self.draw();
214
- self._stage.container().style.cursor = 'default';
215
- });
216
-
217
- indicator.on('click', function(e) {
218
- self._peaks.emit('lineIndicator.click', self._indicators[line.getId()], e.evt);
219
- });
220
-
221
- return indicator;
222
- };
223
-
224
- LineIndicator.prototype.addIndicator = function(line) {
225
- if (!this._indicators[line.getId()]) {
226
- var indicator = this._createIndicator(line);
227
-
228
- this._layer.add(indicator);
229
-
230
- this._indicators[line.getId()] = {
231
- indicator: indicator,
232
- line: line,
233
- type: 'default'
234
- };
235
- }
236
- };
237
-
238
- LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
239
- if (this._indicators[lineId]) {
240
- if (this._indicators[lineId].indicator) {
241
- this._indicators[lineId].indicator.destroy();
242
- }
243
- if (!keepInList) {
244
- delete this._indicators[lineId];
245
- }
246
- else {
247
- this._indicators[lineId].indicator = null;
248
- }
249
- }
250
- };
251
-
252
- LineIndicator.prototype.updateIndicator = function(lineId) {
253
- if (this._indicators[lineId]) {
254
- var y = this._indicators[lineId].line.getY();
255
- var isVisible = y + this._indicators[lineId].line.lineHeight() + this._yPadding > 0
256
- && y - this._yPadding < this._height;
257
-
258
- if (isVisible) {
259
- if (!this._indicators[lineId].indicator) {
260
- this._indicators[lineId].indicator = this._createIndicator(
261
- this._indicators[lineId].line,
262
- this._indicators[lineId].type,
263
- this._indicators[lineId].text
264
- );
265
- this._layer.add(this._indicators[lineId].indicator);
266
- }
267
- else {
268
- this._indicators[lineId].indicator.y(
269
- y + this._indicators[lineId].line.lineHeight() / 2
270
- - this._indicators[lineId].indicator.getAttr('trueHeight') / 2
271
- );
272
- }
273
- }
274
- else {
275
- this.removeIndicator(lineId, true);
276
- }
277
- }
278
- };
279
-
280
- LineIndicator.prototype.updateIndicators = function() {
281
- for (var lineId in this._indicators) {
282
- if (Utils.objectHasProperty(this._indicators, lineId)) {
283
- this.updateIndicator(lineId);
284
- }
285
- }
286
- };
287
-
288
- LineIndicator.prototype.draw = function() {
289
- this._layer.draw();
290
- };
291
-
292
- return LineIndicator;
293
- });
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,