@checksub_team/peaks_timeline 1.5.7 → 1.5.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checksub_team/peaks_timeline",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "description": "JavaScript UI component for displaying audio waveforms",
5
5
  "main": "./peaks.js",
6
6
  "types": "./peaks.js.d.ts",
package/peaks.js CHANGED
@@ -14296,8 +14296,16 @@ module.exports = function (Konva, Utils, SVGs) {
14296
14296
  this._container = container;
14297
14297
  this._width = this._peaks.options.lineIndicatorWidth;
14298
14298
  this._height = this._view.getHeight();
14299
- this._iconSize = this._peaks.options.lineIndicatorIconSize;
14300
- this._fontSize = this._peaks.options.lineIndicatorFontSize;
14299
+ this._sizes = {
14300
+ font: this._peaks.options.lineIndicatorFontSize,
14301
+ icon: {
14302
+ default: this._peaks.options.lineIndicatorDefaultIconSize,
14303
+ volume: this._peaks.options.lineIndicatorVolumeIconSize,
14304
+ noVolume: this._peaks.options.lineIndicatorNoVolumeIconSize,
14305
+ visibility: this._peaks.options.lineIndicatorVisibilityIconSize,
14306
+ noVisibility: this._peaks.options.lineIndicatorNoVisibilityIconSize
14307
+ }
14308
+ };
14301
14309
  this._defaultPadding = 5;
14302
14310
  this._types = ['default'].concat(Object.keys(SVGs));
14303
14311
  this._stage = new Konva.Stage({
@@ -14325,6 +14333,7 @@ module.exports = function (Konva, Utils, SVGs) {
14325
14333
  this._createContextMenu();
14326
14334
  }
14327
14335
  this._peaks.on('lineIndicator.setType', this._onSetType.bind(this));
14336
+ this._peaks.on('lineIndicator.setText', this._onSetText.bind(this));
14328
14337
  }
14329
14338
  LineIndicator.prototype.fitToView = function () {
14330
14339
  this._height = this._view.getHeight();
@@ -14339,65 +14348,85 @@ module.exports = function (Konva, Utils, SVGs) {
14339
14348
  LineIndicator.prototype._onSetType = function (lineId, type) {
14340
14349
  this.removeIndicator(lineId, true);
14341
14350
  type = this._types.includes(type) ? type : 'default';
14342
- var indicator = this._createIndicator(this._indicators[lineId].line, type);
14351
+ var indicator = this._createIndicator(this._indicators[lineId].line, type, this._indicators[lineId].text);
14343
14352
  this._layer.add(indicator);
14344
14353
  this._indicators[lineId].indicator = indicator;
14345
14354
  this._indicators[lineId].type = type;
14346
14355
  this.draw();
14347
14356
  };
14357
+ LineIndicator.prototype._onSetText = function (lineId, text) {
14358
+ this.removeIndicator(lineId, true);
14359
+ var indicator = this._createIndicator(this._indicators[lineId].line, this._indicators[lineId].type, text);
14360
+ this._layer.add(indicator);
14361
+ this._indicators[lineId].indicator = indicator;
14362
+ this._indicators[lineId].text = text;
14363
+ this.draw();
14364
+ };
14348
14365
  LineIndicator.prototype._showMenu = function (menu) {
14349
14366
  menu.style.display = 'block';
14350
14367
  var containerRect = this._stage.container().getBoundingClientRect();
14351
14368
  menu.style.top = containerRect.top + this._stage.getPointerPosition().y - menu.offsetHeight + 'px';
14352
14369
  menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
14353
14370
  };
14354
- LineIndicator.prototype._createIndicator = function (line, type) {
14371
+ LineIndicator.prototype._createIndicator = function (line, type, text) {
14355
14372
  var indicator = new Konva.Group();
14356
- var text = new Konva.Text({
14357
- text: 'This is just a test',
14358
- fontSize: this._fontSize,
14359
- fontFamily: 'Arial',
14360
- fill: this._peaks.options.lineIndicatorColor,
14361
- align: 'center',
14362
- width: this._width
14363
- });
14373
+ var indicatorHeight = 0;
14374
+ if (text) {
14375
+ var textNode = new Konva.Text({
14376
+ text: text,
14377
+ fontSize: this._sizes.font,
14378
+ fontFamily: 'Arial',
14379
+ fill: this._peaks.options.lineIndicatorTextColor,
14380
+ align: 'center',
14381
+ width: this._width
14382
+ });
14383
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
14384
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
14385
+ indicator.add(textNode);
14386
+ indicatorHeight += this._sizes.font;
14387
+ }
14364
14388
  type = this._types.includes(type) ? type : 'default';
14365
- var icon;
14389
+ var iconNode;
14366
14390
  if (type === 'default') {
14367
- icon = new Konva.Circle({
14391
+ var padding = text ? this._defaultPadding : 0;
14392
+ iconNode = new Konva.Circle({
14368
14393
  x: this._width / 2,
14369
- y: this._fontSize + this._iconSize / 2 + this._defaultPadding,
14370
- radius: this._iconSize / 2,
14371
- fill: this._peaks.options.lineIndicatorColor,
14394
+ y: indicatorHeight + this._sizes.icon.default / 2 + padding,
14395
+ radius: this._sizes.icon.default / 2,
14396
+ fill: this._peaks.options.lineIndicatorIconColor,
14372
14397
  strokeWidth: 0,
14373
14398
  lineId: line.getId()
14374
14399
  });
14400
+ indicatorHeight += padding;
14375
14401
  } else {
14376
- icon = new Konva.Path({
14377
- x: (this._width - this._iconSize) / 2,
14378
- y: this._fontSize,
14402
+ iconNode = new Konva.Path({
14403
+ x: (this._width - this._sizes.icon[type]) / 2,
14404
+ y: indicatorHeight,
14379
14405
  data: SVGs[type].path,
14380
- fill: this._peaks.options.lineIndicatorColor,
14406
+ fill: this._peaks.options.lineIndicatorIconColor,
14381
14407
  scale: {
14382
- x: this._iconSize / SVGs[type].width,
14383
- y: this._iconSize / SVGs[type].height
14408
+ x: this._sizes.icon[type] / SVGs[type].width,
14409
+ y: this._sizes.icon[type] / SVGs[type].height
14384
14410
  },
14385
14411
  lineId: line.getId()
14386
14412
  });
14387
14413
  }
14388
- indicator.add(text);
14389
- indicator.add(icon);
14390
- indicator.y(line.getY() + (line.lineHeight() - this._getIndicatorHeight(type)) / 2);
14414
+ iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
14415
+ iconNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedIconColor);
14416
+ indicator.add(iconNode);
14417
+ indicatorHeight += this._sizes.icon[type];
14418
+ indicator.setAttr('trueHeight', indicatorHeight);
14419
+ indicator.y(line.getY() + (line.lineHeight() - indicatorHeight) / 2);
14391
14420
  var self = this;
14392
14421
  indicator.on('mouseover', function () {
14393
14422
  indicator.getChildren().forEach(function (child) {
14394
- child.fill(self._peaks.options.lineIndicatorSelected);
14423
+ child.fill(child.getAttr('selectedColor'));
14395
14424
  });
14396
14425
  self.draw();
14397
14426
  });
14398
14427
  indicator.on('mouseout', function () {
14399
14428
  indicator.getChildren().forEach(function (child) {
14400
- child.fill(self._peaks.options.lineIndicatorColor);
14429
+ child.fill(child.getAttr('defaultColor'));
14401
14430
  });
14402
14431
  self.draw();
14403
14432
  });
@@ -14434,10 +14463,10 @@ module.exports = function (Konva, Utils, SVGs) {
14434
14463
  var y = this._indicators[lineId].line.getY() + this._indicators[lineId].line.lineHeight() / 2;
14435
14464
  if (y + this._indicators[lineId].line.lineHeight() > 0 && y < this._height) {
14436
14465
  if (!this._indicators[lineId].indicator) {
14437
- this._indicators[lineId].indicator = this._createIndicator(this._indicators[lineId].line, this._indicators[lineId].type);
14466
+ this._indicators[lineId].indicator = this._createIndicator(this._indicators[lineId].line, this._indicators[lineId].type, this._indicators[lineId].text);
14438
14467
  this._layer.add(this._indicators[lineId].indicator);
14439
14468
  } else {
14440
- this._indicators[lineId].indicator.y(y - this._getIndicatorHeight(this._indicators[lineId].type) / 2);
14469
+ this._indicators[lineId].indicator.y(y - this._indicators[lineId].indicator.getAttr('trueHeight') / 2);
14441
14470
  }
14442
14471
  } else {
14443
14472
  this.removeIndicator(lineId, true);
@@ -14454,9 +14483,6 @@ module.exports = function (Konva, Utils, SVGs) {
14454
14483
  LineIndicator.prototype.draw = function () {
14455
14484
  this._layer.draw();
14456
14485
  };
14457
- LineIndicator.prototype._getIndicatorHeight = function (type) {
14458
- return type === 'default' ? this._fontSize + this._iconSize + this._defaultPadding : this._fontSize + this._iconSize;
14459
- };
14460
14486
  LineIndicator.prototype._createContextMenu = function () {
14461
14487
  var menu = document.createElement('div');
14462
14488
  var addLine = document.createElement('button');
@@ -15389,10 +15415,16 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15389
15415
  segmentMagnetThreshold: 15,
15390
15416
  enableVerticalScrolling: true,
15391
15417
  lineIndicatorWidth: 20,
15392
- lineIndicatorIconSize: 10,
15393
- lineIndicatorFontSize: 12,
15394
- lineIndicatorColor: '#8A8F98',
15395
- lineIndicatorSelected: '#ccc',
15418
+ lineIndicatorDefaultIconSize: 19,
15419
+ lineIndicatorVolumeIconSize: 24,
15420
+ lineIndicatorNoVolumeIconSize: 24,
15421
+ lineIndicatorVisibilityIconSize: 24,
15422
+ lineIndicatorNoVisibilityIconSize: 24,
15423
+ lineIndicatorFontSize: 10,
15424
+ lineIndicatorTextColor: '#8A8F98',
15425
+ lineIndicatorIconColor: '#8A8F98',
15426
+ lineIndicatorSelectedTextColor: '#ccc',
15427
+ lineIndicatorSelectedIconColor: '#ccc',
15396
15428
  autoScrollThreshold: 0.05,
15397
15429
  enableLineIndicatorContextMenu: true,
15398
15430
  minSourceSize: 0.05,
@@ -15534,6 +15566,10 @@ module.exports = function (Colors, EventEmitter, TimelineSegments, TimelineSourc
15534
15566
  var lineId = this.view.getLineByPosition(linePosition).getId();
15535
15567
  this.emit('lineIndicator.setType', lineId, type);
15536
15568
  };
15569
+ Peaks.prototype.setIndicatorText = function (linePosition, text) {
15570
+ var lineId = this.view.getLineByPosition(linePosition).getId();
15571
+ this.emit('lineIndicator.setText', lineId, text);
15572
+ };
15537
15573
  Peaks.prototype.getVisibleSegments = function () {
15538
15574
  return this.view.getSegmentsGroup().getVisibleSegments();
15539
15575
  };
@@ -34,8 +34,16 @@ define([
34
34
  this._width = this._peaks.options.lineIndicatorWidth;
35
35
  this._height = this._view.getHeight();
36
36
 
37
- this._iconSize = this._peaks.options.lineIndicatorIconSize;
38
- this._fontSize = this._peaks.options.lineIndicatorFontSize;
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
+ };
39
47
 
40
48
  this._defaultPadding = 5;
41
49
  this._types = ['default'].concat(Object.keys(SVGs));
@@ -66,6 +74,7 @@ define([
66
74
  }
67
75
 
68
76
  this._peaks.on('lineIndicator.setType', this._onSetType.bind(this));
77
+ this._peaks.on('lineIndicator.setText', this._onSetText.bind(this));
69
78
  }
70
79
 
71
80
  LineIndicator.prototype.fitToView = function() {
@@ -83,7 +92,8 @@ define([
83
92
 
84
93
  var indicator = this._createIndicator(
85
94
  this._indicators[lineId].line,
86
- type
95
+ type,
96
+ this._indicators[lineId].text
87
97
  );
88
98
 
89
99
  this._layer.add(indicator);
@@ -94,6 +104,23 @@ define([
94
104
  this.draw();
95
105
  };
96
106
 
107
+ LineIndicator.prototype._onSetText = function(lineId, text) {
108
+ this.removeIndicator(lineId, true);
109
+
110
+ var indicator = this._createIndicator(
111
+ this._indicators[lineId].line,
112
+ this._indicators[lineId].type,
113
+ text
114
+ );
115
+
116
+ this._layer.add(indicator);
117
+
118
+ this._indicators[lineId].indicator = indicator;
119
+ this._indicators[lineId].text = text;
120
+
121
+ this.draw();
122
+ };
123
+
97
124
  LineIndicator.prototype._showMenu = function(menu) {
98
125
  menu.style.display = 'block';
99
126
  var containerRect = this._stage.container().getBoundingClientRect();
@@ -104,63 +131,81 @@ define([
104
131
  menu.style.left = containerRect.left + this._stage.getPointerPosition().x + 6 + 'px';
105
132
  };
106
133
 
107
- LineIndicator.prototype._createIndicator = function(line, type) {
134
+ LineIndicator.prototype._createIndicator = function(line, type, text) {
108
135
  var indicator = new Konva.Group();
136
+ var indicatorHeight = 0;
137
+
138
+ if (text) {
139
+ var textNode = new Konva.Text({
140
+ text: text,
141
+ fontSize: this._sizes.font,
142
+ fontFamily: 'Arial',
143
+ fill: this._peaks.options.lineIndicatorTextColor,
144
+ align: 'center',
145
+ width: this._width
146
+ });
109
147
 
110
- var text = new Konva.Text({
111
- text: 'This is just a test',
112
- fontSize: this._fontSize,
113
- fontFamily: 'Arial',
114
- fill: this._peaks.options.lineIndicatorColor,
115
- align: 'center',
116
- width: this._width
117
- });
148
+ textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
149
+ textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
150
+
151
+ indicator.add(textNode);
152
+ indicatorHeight += this._sizes.font;
153
+ }
118
154
 
119
155
  type = this._types.includes(type) ? type : 'default';
120
156
 
121
- var icon;
157
+ var iconNode;
122
158
 
123
159
  if (type === 'default') {
124
- icon = new Konva.Circle({
160
+ var padding = text ? this._defaultPadding : 0;
161
+
162
+ iconNode = new Konva.Circle({
125
163
  x: this._width / 2,
126
- y: this._fontSize + this._iconSize / 2 + this._defaultPadding,
127
- radius: this._iconSize / 2,
128
- fill: this._peaks.options.lineIndicatorColor,
164
+ y: indicatorHeight + this._sizes.icon.default / 2 + padding,
165
+ radius: this._sizes.icon.default / 2,
166
+ fill: this._peaks.options.lineIndicatorIconColor,
129
167
  strokeWidth: 0,
130
168
  lineId: line.getId()
131
169
  });
170
+
171
+ indicatorHeight += padding;
132
172
  }
133
173
  else {
134
- icon = new Konva.Path({
135
- x: (this._width - this._iconSize) / 2,
136
- y: this._fontSize,
174
+ iconNode = new Konva.Path({
175
+ x: (this._width - this._sizes.icon[type]) / 2,
176
+ y: indicatorHeight,
137
177
  data: SVGs[type].path,
138
- fill: this._peaks.options.lineIndicatorColor,
178
+ fill: this._peaks.options.lineIndicatorIconColor,
139
179
  scale: {
140
- x: (this._iconSize) / SVGs[type].width,
141
- y: (this._iconSize) / SVGs[type].height
180
+ x: (this._sizes.icon[type]) / SVGs[type].width,
181
+ y: (this._sizes.icon[type]) / SVGs[type].height
142
182
  },
143
183
  lineId: line.getId()
144
184
  });
145
185
  }
146
186
 
147
- indicator.add(text);
148
- indicator.add(icon);
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];
149
192
 
150
- indicator.y(line.getY() + (line.lineHeight() - this._getIndicatorHeight(type)) / 2);
193
+ indicator.setAttr('trueHeight', indicatorHeight);
194
+
195
+ indicator.y(line.getY() + (line.lineHeight() - indicatorHeight) / 2);
151
196
 
152
197
  var self = this;
153
198
 
154
199
  indicator.on('mouseover', function() {
155
200
  indicator.getChildren().forEach(function(child) {
156
- child.fill(self._peaks.options.lineIndicatorSelected);
201
+ child.fill(child.getAttr('selectedColor'));
157
202
  });
158
203
  self.draw();
159
204
  });
160
205
 
161
206
  indicator.on('mouseout', function() {
162
207
  indicator.getChildren().forEach(function(child) {
163
- child.fill(self._peaks.options.lineIndicatorColor);
208
+ child.fill(child.getAttr('defaultColor'));
164
209
  });
165
210
  self.draw();
166
211
  });
@@ -210,13 +255,14 @@ define([
210
255
  if (!this._indicators[lineId].indicator) {
211
256
  this._indicators[lineId].indicator = this._createIndicator(
212
257
  this._indicators[lineId].line,
213
- this._indicators[lineId].type
258
+ this._indicators[lineId].type,
259
+ this._indicators[lineId].text
214
260
  );
215
261
  this._layer.add(this._indicators[lineId].indicator);
216
262
  }
217
263
  else {
218
264
  this._indicators[lineId].indicator.y(
219
- y - this._getIndicatorHeight(this._indicators[lineId].type) / 2
265
+ y - this._indicators[lineId].indicator.getAttr('trueHeight') / 2
220
266
  );
221
267
  }
222
268
  }
@@ -239,12 +285,6 @@ define([
239
285
  this._layer.draw();
240
286
  };
241
287
 
242
- LineIndicator.prototype._getIndicatorHeight = function(type) {
243
- return type === 'default' ?
244
- this._fontSize + this._iconSize + this._defaultPadding :
245
- this._fontSize + this._iconSize;
246
- };
247
-
248
288
  LineIndicator.prototype._createContextMenu = function() {
249
289
  var menu = document.createElement('div');
250
290
  var addLine = document.createElement('button');
package/src/main.js CHANGED
@@ -283,22 +283,52 @@ define([
283
283
  /**
284
284
  * Size of the line indicators' icon, in pixels
285
285
  */
286
- lineIndicatorIconSize: 10,
286
+ lineIndicatorDefaultIconSize: 19,
287
+
288
+ /**
289
+ * Size of the line indicators' volume icon, in pixels
290
+ */
291
+ lineIndicatorVolumeIconSize: 24,
292
+
293
+ /**
294
+ * Size of the line indicators' no volume, in pixels
295
+ */
296
+ lineIndicatorNoVolumeIconSize: 24,
297
+
298
+ /**
299
+ * Size of the line indicators' visibility, in pixels
300
+ */
301
+ lineIndicatorVisibilityIconSize: 24,
302
+
303
+ /**
304
+ * Size of the line indicators' no visibility icon, in pixels
305
+ */
306
+ lineIndicatorNoVisibilityIconSize: 24,
287
307
 
288
308
  /**
289
309
  * Font size of the line indicators' text, in pixels
290
310
  */
291
- lineIndicatorFontSize: 12,
311
+ lineIndicatorFontSize: 10,
312
+
313
+ /**
314
+ * Color of the line indicators' text
315
+ */
316
+ lineIndicatorTextColor: '#8A8F98',
317
+
318
+ /**
319
+ * Color of the line indicators' icon
320
+ */
321
+ lineIndicatorIconColor: '#8A8F98',
292
322
 
293
323
  /**
294
- * Color of the line indicators
324
+ * Color for the indicator's text when selected
295
325
  */
296
- lineIndicatorColor: '#8A8F98',
326
+ lineIndicatorSelectedTextColor: '#ccc',
297
327
 
298
328
  /**
299
- * Color for the indicator when selected
329
+ * Color for the indicator's icon when selected
300
330
  */
301
- lineIndicatorSelected: '#ccc',
331
+ lineIndicatorSelectedIconColor: '#ccc',
302
332
 
303
333
  /**
304
334
  * Threshold size on the left and right border of the view,
@@ -634,6 +664,12 @@ define([
634
664
  this.emit('lineIndicator.setType', lineId, type);
635
665
  };
636
666
 
667
+ Peaks.prototype.setIndicatorText = function(linePosition, text) {
668
+ var lineId = this.view.getLineByPosition(linePosition).getId();
669
+
670
+ this.emit('lineIndicator.setText', lineId, text);
671
+ };
672
+
637
673
  Peaks.prototype.getVisibleSegments = function() {
638
674
  return this.view
639
675
  .getSegmentsGroup()