@grame/faustwasm 0.11.0 → 0.11.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.
@@ -469,6 +469,14 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
469
469
  };
470
470
  this.handleClick = (e) => {
471
471
  };
472
+ /**
473
+ * Handle double-click events to reset the value to its initial state.
474
+ */
475
+ this.handleDoubleClick = (e) => {
476
+ e.preventDefault();
477
+ e.stopPropagation();
478
+ this.setToInitialValue();
479
+ };
472
480
  this.handleMouseDown = (e) => {
473
481
  e.preventDefault();
474
482
  e.currentTarget.focus();
@@ -558,6 +566,9 @@ const _AbstractItem = class _AbstractItem extends _AbstractComponent__WEBPACK_IM
558
566
  if (changed) this.change(value);
559
567
  return changed;
560
568
  }
569
+ setToInitialValue() {
570
+ this.setValue(this.state.init);
571
+ }
561
572
  /**
562
573
  * Send value to DSP
563
574
  */
@@ -698,6 +709,7 @@ _AbstractItem.defaultProps = {
698
709
  address: "",
699
710
  min: 0,
700
711
  max: 1,
712
+ init: 0,
701
713
  enums: {},
702
714
  type: "float",
703
715
  unit: "",
@@ -886,6 +898,14 @@ __webpack_require__.r(__webpack_exports__);
886
898
  class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
887
899
  constructor() {
888
900
  super(...arguments);
901
+ /**
902
+ * Handle double-click events to reset all children's value to its initial state.
903
+ */
904
+ this.handleDoubleClick = (e) => {
905
+ e.preventDefault();
906
+ e.stopPropagation();
907
+ this.setToInitialValue();
908
+ };
889
909
  this.updateUI = () => {
890
910
  this.children = [];
891
911
  const { style, type, items, emitter, isRoot } = this.state;
@@ -946,10 +966,10 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
946
966
  if (!metaIn) return { metaObject };
947
967
  metaIn.forEach((m) => Object.assign(metaObject, m));
948
968
  if (metaObject.style) {
949
- const enumsRegex = /\{(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+);)+(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))\}/;
969
+ const enumsRegex = /\{\s*(?:['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+)\s*;\s*)+(?:['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+))\s*\}/;
950
970
  const matched = metaObject.style.match(enumsRegex);
951
971
  if (matched) {
952
- const itemsRegex = /(?:(?:'|_|-)(.+?)(?:'|_|-):([-+]?[0-9]*\.?[0-9]+))/g;
972
+ const itemsRegex = /['_\-](.+?)['_\-]\s*:\s*([-+]?[0-9]*\.?[0-9]+)\s*/g;
953
973
  const enums = {};
954
974
  let item;
955
975
  while (item = itemsRegex.exec(matched[0])) {
@@ -1003,7 +1023,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
1003
1023
  min: isFinite(min) ? min : 0,
1004
1024
  max: isFinite(max) ? max : 1,
1005
1025
  step: "step" in item ? +item.step : 1,
1006
- value: "init" in item ? +item.init || 0 : 0
1026
+ value: "init" in item ? +item.init || 0 : 0,
1027
+ init: "init" in item ? +item.init || 0 : 0
1007
1028
  };
1008
1029
  if (type === "button") return new _Button__WEBPACK_IMPORTED_MODULE_5__["default"](props);
1009
1030
  if (type === "checkbox") return new _Checkbox__WEBPACK_IMPORTED_MODULE_6__["default"](props);
@@ -1020,6 +1041,9 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
1020
1041
  if (type === "led") return new _Led__WEBPACK_IMPORTED_MODULE_10__["default"](props);
1021
1042
  return null;
1022
1043
  }
1044
+ setToInitialValue() {
1045
+ this.children.forEach((item) => item.setToInitialValue());
1046
+ }
1023
1047
  setState(newState) {
1024
1048
  let shouldUpdate = false;
1025
1049
  for (const key in newState) {
@@ -1091,7 +1115,7 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
1091
1115
  return this;
1092
1116
  }
1093
1117
  componentDidMount() {
1094
- var _a;
1118
+ var _a, _b;
1095
1119
  const handleResize = () => {
1096
1120
  const { grid, left, top, width, height } = this.state.style;
1097
1121
  if (!this.state.isRoot) this.label.style.height = `${grid * 0.3}px`;
@@ -1125,7 +1149,8 @@ class Group extends _AbstractComponent__WEBPACK_IMPORTED_MODULE_0__["default"] {
1125
1149
  };
1126
1150
  this.on("label", () => this.schedule(labelChange));
1127
1151
  this.paintLabel();
1128
- if ((_a = this.tabs) == null ? void 0 : _a.children.length) this.tabs.children[0].click();
1152
+ (_a = this.labelCanvas) == null ? void 0 : _a.addEventListener("dblclick", this.handleDoubleClick);
1153
+ if ((_b = this.tabs) == null ? void 0 : _b.children.length) this.tabs.children[0].click();
1129
1154
  this.children.forEach((item) => item.componentDidMount());
1130
1155
  return this;
1131
1156
  }
@@ -1446,6 +1471,7 @@ class Knob extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
1446
1471
  super.componentDidMount();
1447
1472
  this.input.addEventListener("change", this.handleChange);
1448
1473
  this.canvas.addEventListener("pointerdown", this.handlePointerDown);
1474
+ this.canvas.addEventListener("dblclick", this.handleDoubleClick);
1449
1475
  this.on("style", () => {
1450
1476
  this.schedule(this.setStyle);
1451
1477
  this.schedule(this.paint);
@@ -2471,6 +2497,7 @@ class VSlider extends _AbstractItem__WEBPACK_IMPORTED_MODULE_0__["default"] {
2471
2497
  super.componentDidMount();
2472
2498
  this.input.addEventListener("change", this.handleChange);
2473
2499
  this.canvas.addEventListener("pointerdown", this.handlePointerDown);
2500
+ this.canvas.addEventListener("dblclick", this.handleDoubleClick);
2474
2501
  this.on("style", () => {
2475
2502
  this.schedule(this.setStyle);
2476
2503
  this.schedule(this.paint);