@checksub_team/peaks_timeline 2.2.2 → 2.2.3

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": "2.2.2",
3
+ "version": "2.2.3",
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
@@ -15875,24 +15875,24 @@ module.exports = function (Konva, SVGs, Utils) {
15875
15875
  ]);
15876
15876
  this.refreshIndicators();
15877
15877
  };
15878
- LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText) {
15878
+ LineIndicator.prototype._createIndicator = function (lineGroup, type, text, subText, defaultStyle = {}) {
15879
15879
  const indicator = new Konva.Group();
15880
15880
  let indicatorHeight = 0;
15881
15881
  var self = this;
15882
15882
  var textGroup, iconGroup, subTextGroup;
15883
15883
  var textNode, iconNode, subTextNode;
15884
15884
  if (text) {
15885
- [textGroup, textNode] = this._createIndicatorText(text);
15885
+ [textGroup, textNode] = this._createIndicatorText(text, 'line-indicator-text', defaultStyle);
15886
15886
  indicator.add(textGroup);
15887
15887
  indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
15888
15888
  }
15889
- [iconGroup, iconNode] = this._createIndicatorIcon(type);
15889
+ [iconGroup, iconNode] = this._createIndicatorIcon(type, 'line-indicator-icon', defaultStyle);
15890
15890
  iconGroup.y(indicatorHeight);
15891
15891
  indicator.add(iconGroup);
15892
15892
  indicatorHeight += iconGroup.getAttr('trueHeight');
15893
15893
  if (subText) {
15894
15894
  indicatorHeight += this._bottomPadding;
15895
- [subTextGroup, subTextNode] = this._createIndicatorText(subText);
15895
+ [subTextGroup, subTextNode] = this._createIndicatorText(subText, 'line-indicator-subText', defaultStyle);
15896
15896
  subTextGroup.y(indicatorHeight);
15897
15897
  indicator.add(subTextGroup);
15898
15898
  indicatorHeight += subTextGroup.getAttr('trueHeight');
@@ -15973,16 +15973,18 @@ module.exports = function (Konva, SVGs, Utils) {
15973
15973
  indicator.y(lineGroup.y() + (lineGroup.lineHeight() - indicatorHeight) / 2);
15974
15974
  return indicator;
15975
15975
  };
15976
- LineIndicator.prototype._createIndicatorText = function (text) {
15976
+ LineIndicator.prototype._createIndicatorText = function (text, role, defaultStyle = {}) {
15977
+ defaultStyle = defaultStyle[role] || {};
15977
15978
  const textGroup = new Konva.Group();
15978
15979
  const textNode = new Konva.Text({
15979
15980
  text: text,
15980
15981
  fontSize: this._sizes.font,
15981
15982
  fontFamily: this._peaks.options.lineIndicatorFont,
15982
- fill: this._peaks.options.lineIndicatorTextColor,
15983
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorTextColor,
15983
15984
  align: 'center',
15984
15985
  width: this._width,
15985
- listening: false
15986
+ listening: false,
15987
+ name: role
15986
15988
  });
15987
15989
  textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
15988
15990
  textNode.setAttr('selectedColor', this._peaks.options.lineIndicatorSelectedTextColor);
@@ -16003,7 +16005,8 @@ module.exports = function (Konva, SVGs, Utils) {
16003
16005
  textNode
16004
16006
  ];
16005
16007
  };
16006
- LineIndicator.prototype._createIndicatorIcon = function (type) {
16008
+ LineIndicator.prototype._createIndicatorIcon = function (type, role, defaultStyle = {}) {
16009
+ defaultStyle = defaultStyle[role] || {};
16007
16010
  type = this._types.includes(type) ? type : 'default';
16008
16011
  const iconGroup = new Konva.Group();
16009
16012
  var iconHeight = this._sizes.icon[type];
@@ -16013,21 +16016,23 @@ module.exports = function (Konva, SVGs, Utils) {
16013
16016
  x: this._width / 2,
16014
16017
  y: this._sizes.icon.default / 2,
16015
16018
  radius: this._sizes.icon.default / 2,
16016
- fill: this._peaks.options.lineIndicatorIconColor,
16019
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
16017
16020
  strokeWidth: 0,
16018
- listening: false
16021
+ listening: false,
16022
+ name: role
16019
16023
  });
16020
16024
  } else {
16021
16025
  iconNode = new Konva.Path({
16022
16026
  x: (this._width - this._sizes.icon[type]) / 2,
16023
16027
  y: 0,
16024
16028
  data: SVGs[type].path,
16025
- fill: this._peaks.options.lineIndicatorIconColor,
16029
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
16026
16030
  scale: {
16027
16031
  x: this._sizes.icon[type] / SVGs[type].width,
16028
16032
  y: this._sizes.icon[type] / SVGs[type].height
16029
16033
  },
16030
- listening: false
16034
+ listening: false,
16035
+ name: role
16031
16036
  });
16032
16037
  }
16033
16038
  iconNode.setAttr('defaultColor', this._peaks.options.lineIndicatorIconColor);
@@ -16072,8 +16077,8 @@ module.exports = function (Konva, SVGs, Utils) {
16072
16077
  if (indicatorData.type === line.indicatorType && indicatorData.text === line.indicatorText && indicatorData.subText === line.indicatorSubText) {
16073
16078
  return;
16074
16079
  }
16075
- this.removeIndicator(line.id, true);
16076
- var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText);
16080
+ const styleData = this.removeIndicator(line.id, true);
16081
+ var indicator = this._createIndicator(indicatorData.lineGroup, line.indicatorType, line.indicatorText, line.indicatorSubText, styleData);
16077
16082
  this._layer.add(indicator);
16078
16083
  indicatorData.indicator = indicator;
16079
16084
  indicatorData.type = line.indicatorType;
@@ -16081,17 +16086,40 @@ module.exports = function (Konva, SVGs, Utils) {
16081
16086
  indicatorData.subText = line.indicatorSubText;
16082
16087
  this.batchDraw();
16083
16088
  };
16089
+ LineIndicator.prototype._getStyleData = function (konvaItem) {
16090
+ if (!konvaItem) {
16091
+ return {};
16092
+ }
16093
+ var styleData = {};
16094
+ const name = konvaItem.name();
16095
+ if (name) {
16096
+ styleData[name] = { fill: konvaItem.fill() };
16097
+ }
16098
+ if (typeof konvaItem.getChildren === 'function') {
16099
+ const children = konvaItem.getChildren();
16100
+ if (children && children.length > 0) {
16101
+ children.forEach(function (child) {
16102
+ styleData = Object.assign(styleData, this._getStyleData(child));
16103
+ }.bind(this));
16104
+ }
16105
+ }
16106
+ return styleData;
16107
+ };
16084
16108
  LineIndicator.prototype.removeIndicator = function (lineId, keepInList) {
16109
+ var styleData = {};
16085
16110
  if (this._indicators[lineId]) {
16086
- if (this._indicators[lineId].indicator) {
16087
- this._indicators[lineId].indicator.destroy();
16088
- }
16111
+ const indicator = this._indicators[lineId].indicator;
16089
16112
  if (!keepInList) {
16090
16113
  delete this._indicators[lineId];
16091
16114
  } else {
16092
16115
  this._indicators[lineId].indicator = null;
16116
+ styleData = this._getStyleData(indicator);
16117
+ }
16118
+ if (indicator) {
16119
+ indicator.destroy();
16093
16120
  }
16094
16121
  }
16122
+ return styleData;
16095
16123
  };
16096
16124
  LineIndicator.prototype.refreshIndicator = function (lineId) {
16097
16125
  var anyChange = false;
@@ -89,7 +89,7 @@ define([
89
89
  this.refreshIndicators();
90
90
  };
91
91
 
92
- LineIndicator.prototype._createIndicator = function(lineGroup, type, text, subText) {
92
+ LineIndicator.prototype._createIndicator = function(lineGroup, type, text, subText, defaultStyle = {}) {
93
93
  const indicator = new Konva.Group();
94
94
  let indicatorHeight = 0;
95
95
  var self = this;
@@ -97,13 +97,13 @@ define([
97
97
  var textNode, iconNode, subTextNode;
98
98
 
99
99
  if (text) {
100
- [textGroup, textNode] = this._createIndicatorText(text);
100
+ [textGroup, textNode] = this._createIndicatorText(text, 'line-indicator-text', defaultStyle);
101
101
 
102
102
  indicator.add(textGroup);
103
103
  indicatorHeight += textGroup.getAttr('trueHeight') + this._topPadding;
104
104
  }
105
105
 
106
- [iconGroup, iconNode] = this._createIndicatorIcon(type);
106
+ [iconGroup, iconNode] = this._createIndicatorIcon(type, 'line-indicator-icon', defaultStyle);
107
107
 
108
108
  iconGroup.y(indicatorHeight);
109
109
  indicator.add(iconGroup);
@@ -112,7 +112,7 @@ define([
112
112
  if (subText) {
113
113
  indicatorHeight += this._bottomPadding;
114
114
 
115
- [subTextGroup, subTextNode] = this._createIndicatorText(subText);
115
+ [subTextGroup, subTextNode] = this._createIndicatorText(subText, 'line-indicator-subText', defaultStyle);
116
116
 
117
117
  subTextGroup.y(indicatorHeight);
118
118
  indicator.add(subTextGroup);
@@ -208,17 +208,19 @@ define([
208
208
  return indicator;
209
209
  };
210
210
 
211
- LineIndicator.prototype._createIndicatorText = function(text) {
211
+ LineIndicator.prototype._createIndicatorText = function(text, role, defaultStyle = {}) {
212
+ defaultStyle = defaultStyle[role] || {};
212
213
  const textGroup = new Konva.Group();
213
214
 
214
215
  const textNode = new Konva.Text({
215
216
  text: text,
216
217
  fontSize: this._sizes.font,
217
218
  fontFamily: this._peaks.options.lineIndicatorFont,
218
- fill: this._peaks.options.lineIndicatorTextColor,
219
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorTextColor,
219
220
  align: 'center',
220
221
  width: this._width,
221
- listening: false
222
+ listening: false,
223
+ name: role
222
224
  });
223
225
 
224
226
  textNode.setAttr('defaultColor', this._peaks.options.lineIndicatorTextColor);
@@ -242,7 +244,8 @@ define([
242
244
  return [textGroup, textNode];
243
245
  };
244
246
 
245
- LineIndicator.prototype._createIndicatorIcon = function(type) {
247
+ LineIndicator.prototype._createIndicatorIcon = function(type, role, defaultStyle = {}) {
248
+ defaultStyle = defaultStyle[role] || {};
246
249
  type = this._types.includes(type) ? type : 'default';
247
250
 
248
251
  const iconGroup = new Konva.Group();
@@ -255,9 +258,10 @@ define([
255
258
  x: this._width / 2,
256
259
  y: this._sizes.icon.default / 2,
257
260
  radius: this._sizes.icon.default / 2,
258
- fill: this._peaks.options.lineIndicatorIconColor,
261
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
259
262
  strokeWidth: 0,
260
- listening: false
263
+ listening: false,
264
+ name: role
261
265
  });
262
266
  }
263
267
  else {
@@ -265,12 +269,13 @@ define([
265
269
  x: (this._width - this._sizes.icon[type]) / 2,
266
270
  y: 0,
267
271
  data: SVGs[type].path,
268
- fill: this._peaks.options.lineIndicatorIconColor,
272
+ fill: defaultStyle.fill || this._peaks.options.lineIndicatorIconColor,
269
273
  scale: {
270
274
  x: (this._sizes.icon[type]) / SVGs[type].width,
271
275
  y: (this._sizes.icon[type]) / SVGs[type].height
272
276
  },
273
- listening: false
277
+ listening: false,
278
+ name: role
274
279
  });
275
280
  }
276
281
 
@@ -332,13 +337,14 @@ define([
332
337
  return;
333
338
  }
334
339
 
335
- this.removeIndicator(line.id, true);
340
+ const styleData = this.removeIndicator(line.id, true);
336
341
 
337
342
  var indicator = this._createIndicator(
338
343
  indicatorData.lineGroup,
339
344
  line.indicatorType,
340
345
  line.indicatorText,
341
- line.indicatorSubText
346
+ line.indicatorSubText,
347
+ styleData
342
348
  );
343
349
 
344
350
  this._layer.add(indicator);
@@ -351,18 +357,51 @@ define([
351
357
  this.batchDraw();
352
358
  };
353
359
 
360
+ LineIndicator.prototype._getStyleData = function(konvaItem) {
361
+ if (!konvaItem) {
362
+ return {};
363
+ }
364
+
365
+ var styleData = {};
366
+ const name = konvaItem.name();
367
+
368
+ if (name) {
369
+ styleData[name] = {
370
+ fill: konvaItem.fill()
371
+ };
372
+ }
373
+
374
+ if (typeof konvaItem.getChildren === 'function') {
375
+ const children = konvaItem.getChildren();
376
+
377
+ if (children && children.length > 0) {
378
+ children.forEach(function(child) {
379
+ styleData = Object.assign(styleData, this._getStyleData(child));
380
+ }.bind(this));
381
+ }
382
+ }
383
+
384
+ return styleData;
385
+ };
386
+
354
387
  LineIndicator.prototype.removeIndicator = function(lineId, keepInList) {
388
+ var styleData = {};
389
+
355
390
  if (this._indicators[lineId]) {
356
- if (this._indicators[lineId].indicator) {
357
- this._indicators[lineId].indicator.destroy();
358
- }
391
+ const indicator = this._indicators[lineId].indicator;
392
+
359
393
  if (!keepInList) {
360
394
  delete this._indicators[lineId];
361
395
  }
362
396
  else {
363
397
  this._indicators[lineId].indicator = null;
398
+ styleData = this._getStyleData(indicator);
399
+ }
400
+ if (indicator) {
401
+ indicator.destroy();
364
402
  }
365
403
  }
404
+ return styleData;
366
405
  };
367
406
 
368
407
  LineIndicator.prototype.refreshIndicator = function(lineId) {