@media-quest/engine 0.0.30 → 0.0.31

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.
@@ -22,6 +22,7 @@ var public_api_exports = {};
22
22
  __export(public_api_exports, {
23
23
  ButtonClickAction: () => ButtonClickAction,
24
24
  Condition: () => Condition,
25
+ DButton: () => DButton,
25
26
  DCss: () => DCss,
26
27
  DDiv: () => DDiv,
27
28
  DElement: () => DElement,
@@ -30,7 +31,6 @@ __export(public_api_exports, {
30
31
  DText: () => DText,
31
32
  DUtil: () => DUtil,
32
33
  MqEvent: () => MqEvent,
33
- PageComponent: () => PageComponent,
34
34
  PageDto: () => PageDto,
35
35
  Rule: () => Rule,
36
36
  RuleEngine: () => RuleEngine,
@@ -559,6 +559,10 @@ var Scale;
559
559
  var DCss;
560
560
  ((DCss2) => {
561
561
  DCss2.toString = (unit, scale) => {
562
+ const _mapped = typeof unit === "number" ? { _unit: "percent", value: unit } : unit;
563
+ return _toString(_mapped, scale);
564
+ };
565
+ const _toString = (unit, scale) => {
562
566
  const clampedScale = Math.max(scale, 0.03);
563
567
  if (unit._unit === "px") {
564
568
  if (unit.value < 0.1) {
@@ -571,6 +575,9 @@ var DCss;
571
575
  return unit.value + "%";
572
576
  };
573
577
  DCss2.isLengthUnit = (unit) => {
578
+ if (typeof unit === "number") {
579
+ return true;
580
+ }
574
581
  if (!unit) {
575
582
  return false;
576
583
  }
@@ -585,6 +592,8 @@ var DCss;
585
592
  // src/Delement/DStyle.ts
586
593
  var DStyle;
587
594
  ((DStyle2) => {
595
+ const isNumber = DUtil.isNumber;
596
+ const isLengthUnit = DCss.isLengthUnit;
588
597
  DStyle2.normalize = (el) => {
589
598
  el.style.padding = "0";
590
599
  el.style.margin = "0";
@@ -596,6 +605,10 @@ var DStyle;
596
605
  const {
597
606
  x,
598
607
  y,
608
+ left,
609
+ right,
610
+ top,
611
+ bottom,
599
612
  backgroundColor,
600
613
  borderColor,
601
614
  borderWidth,
@@ -613,9 +626,84 @@ var DStyle;
613
626
  padding,
614
627
  letterSpacing,
615
628
  h,
629
+ height,
630
+ width,
616
631
  transform,
617
- visibility
632
+ visibility,
633
+ justifyContent,
634
+ alignContent,
635
+ flexWrap,
636
+ display,
637
+ flexDirection,
638
+ alignItems,
639
+ position,
640
+ paddingLeft,
641
+ paddingTop,
642
+ paddingRight,
643
+ paddingBottom,
644
+ gap,
645
+ zIndex,
646
+ //
647
+ boxShadow,
648
+ minWidth,
649
+ maxWidth,
650
+ minHeight,
651
+ maxHeight
618
652
  } = style;
653
+ if (typeof zIndex === "number") {
654
+ el.style.zIndex = "" + zIndex;
655
+ }
656
+ if (DCss.isLengthUnit(minWidth)) {
657
+ el.style.minWidth = DCss.toString(minWidth, scale);
658
+ }
659
+ if (DCss.isLengthUnit(maxWidth)) {
660
+ el.style.maxWidth = DCss.toString(maxWidth, scale);
661
+ }
662
+ if (DCss.isLengthUnit(minHeight)) {
663
+ el.style.minHeight = DCss.toString(minHeight, scale);
664
+ }
665
+ if (DCss.isLengthUnit(maxHeight)) {
666
+ el.style.maxHeight = DCss.toString(maxHeight, scale);
667
+ }
668
+ if (boxShadow) {
669
+ el.style.boxShadow = boxShadow;
670
+ }
671
+ if (gap) {
672
+ el.style.gap = DCss.toString(gap, scale);
673
+ }
674
+ if (paddingLeft) {
675
+ el.style.paddingLeft = DCss.toString(paddingLeft, scale);
676
+ }
677
+ if (paddingRight) {
678
+ el.style.paddingRight = DCss.toString(paddingRight, scale);
679
+ }
680
+ if (paddingTop) {
681
+ el.style.paddingTop = DCss.toString(paddingTop, scale);
682
+ }
683
+ if (paddingBottom) {
684
+ el.style.paddingBottom = DCss.toString(paddingBottom, scale);
685
+ }
686
+ if (position) {
687
+ el.style.position = position;
688
+ }
689
+ if (justifyContent) {
690
+ el.style.justifyContent = justifyContent;
691
+ }
692
+ if (alignContent) {
693
+ el.style.alignContent = alignContent;
694
+ }
695
+ if (flexWrap) {
696
+ el.style.flexWrap = flexWrap;
697
+ }
698
+ if (display) {
699
+ el.style.display = display;
700
+ }
701
+ if (flexDirection) {
702
+ el.style.flexDirection = flexDirection;
703
+ }
704
+ if (alignItems) {
705
+ el.style.alignItems = alignItems;
706
+ }
619
707
  if (backgroundColor) {
620
708
  el.style.backgroundColor = backgroundColor;
621
709
  }
@@ -652,11 +740,29 @@ var DStyle;
652
740
  if (DUtil.isNumber(y)) {
653
741
  el.style.bottom = y + "%";
654
742
  }
743
+ if (DCss.isLengthUnit(height)) {
744
+ el.style.height = DCss.toString(height, scale);
745
+ }
746
+ if (DCss.isLengthUnit(width)) {
747
+ el.style.width = DCss.toString(width, scale);
748
+ }
749
+ if (DCss.isLengthUnit(left)) {
750
+ el.style.left = DCss.toString(left, scale);
751
+ }
752
+ if (DCss.isLengthUnit(right)) {
753
+ el.style.right = DCss.toString(right, scale);
754
+ }
755
+ if (DCss.isLengthUnit(bottom)) {
756
+ el.style.bottom = DCss.toString(bottom, scale);
757
+ }
758
+ if (DCss.isLengthUnit(top)) {
759
+ el.style.top = DCss.toString(top, scale);
760
+ }
655
761
  if (DUtil.isNumber(h)) {
656
- el.style.height = h + "%";
762
+ el.style.height = DCss.toString(h, scale);
657
763
  }
658
- if (DUtil.isNumber(w)) {
659
- el.style.width = w + "%";
764
+ if (isNumber(w)) {
765
+ el.style.width = DCss.toString(w, scale);
660
766
  }
661
767
  if (DCss.isLengthUnit(borderRadius)) {
662
768
  el.style.borderRadius = DCss.toString(borderRadius, scale);
@@ -670,7 +776,7 @@ var DStyle;
670
776
  if (padding) {
671
777
  el.style.padding = DCss.toString(padding, scale);
672
778
  }
673
- if (DUtil.isNumber(opacity)) {
779
+ if (isNumber(opacity)) {
674
780
  el.style.opacity = opacity + "";
675
781
  }
676
782
  if (visibility) {
@@ -680,7 +786,62 @@ var DStyle;
680
786
  };
681
787
  })(DStyle || (DStyle = {}));
682
788
 
789
+ // src/common/DTimestamp.ts
790
+ var DTimestamp;
791
+ ((DTimestamp2) => {
792
+ DTimestamp2.now = () => Date.now();
793
+ DTimestamp2.addMills = (t, ms) => {
794
+ const res = t + Math.abs(ms);
795
+ return res;
796
+ };
797
+ DTimestamp2.diff = (t1, t2) => {
798
+ const t1Abs = Math.abs(t1);
799
+ const t2Abs = Math.abs(t2);
800
+ return Math.abs(t1Abs - t2Abs);
801
+ };
802
+ DTimestamp2.diffNow = (t) => {
803
+ return (0, DTimestamp2.diff)(t, (0, DTimestamp2.now)());
804
+ };
805
+ })(DTimestamp || (DTimestamp = {}));
806
+
807
+ // src/page/task-state.ts
808
+ var TaskState = {
809
+ eq: (a, b) => {
810
+ return a.audioIsPlaying === b.audioIsPlaying && a.isGifMode === b.isGifMode && a.videoPlayState === b.videoPlayState && a.blockFormInput === b.blockFormInput && a.blockResponseButton === b.blockResponseButton && a.blockAudio === b.blockAudio && a.blockVideo === b.blockVideo;
811
+ },
812
+ getDiff: (curr, prev) => {
813
+ if (prev === false) {
814
+ return curr;
815
+ }
816
+ const diff = {};
817
+ if (curr.audioIsPlaying !== prev.audioIsPlaying) {
818
+ diff.audioIsPlaying = curr.audioIsPlaying;
819
+ }
820
+ if (curr.isGifMode !== prev.isGifMode) {
821
+ diff.isGifMode = curr.isGifMode;
822
+ }
823
+ if (curr.videoPlayState !== prev.videoPlayState) {
824
+ diff.videoPlayState = curr.videoPlayState;
825
+ }
826
+ if (curr.blockFormInput !== prev.blockFormInput) {
827
+ diff.blockFormInput = curr.blockFormInput;
828
+ }
829
+ if (curr.blockResponseButton !== prev.blockResponseButton) {
830
+ diff.blockResponseButton = curr.blockResponseButton;
831
+ }
832
+ if (curr.blockAudio !== prev.blockAudio) {
833
+ diff.blockAudio = curr.blockAudio;
834
+ }
835
+ if (curr.blockVideo !== prev.blockVideo) {
836
+ diff.blockVideo = curr.blockVideo;
837
+ }
838
+ return diff;
839
+ }
840
+ };
841
+
683
842
  // src/Delement/DElement.ts
843
+ var isFalse = (bool) => bool === false;
844
+ var isTrue = (bool) => bool === true;
684
845
  var DElement = class {
685
846
  constructor(el, dto, scale) {
686
847
  this.el = el;
@@ -704,14 +865,12 @@ var DElement = class {
704
865
  this.setStyle(onMouseLeave);
705
866
  };
706
867
  }
707
- this.el.onclick = () => {
708
- this.onclick();
709
- };
710
868
  this.normalize();
711
869
  if (dto) {
712
870
  this.updateStyles(dto?.style);
713
871
  }
714
872
  }
873
+ prevState = false;
715
874
  currStyle = {
716
875
  fontSize: { _unit: "px", value: 100 },
717
876
  fontWeight: 500,
@@ -721,16 +880,81 @@ var DElement = class {
721
880
  /**
722
881
  * This method is called when the element is clicked.
723
882
  * This method shall be overridden by the pageClass.
724
- * @param actions
883
+ * @param style
725
884
  */
726
- onclick() {
727
- }
728
885
  setStyle(style) {
729
886
  this.updateStyles(style);
730
887
  }
888
+ getElementByDangerousReference() {
889
+ return this.el;
890
+ }
731
891
  appendYourself(parent) {
732
892
  parent.append(this.el);
733
893
  }
894
+ updateState(state) {
895
+ this.handleStateChanges(state);
896
+ }
897
+ setState(state) {
898
+ const prev = this.prevState;
899
+ const diff = TaskState.getDiff(state, prev);
900
+ this.prevState = state;
901
+ if (Object.keys(diff).length > 0) {
902
+ this.handleStateChanges(diff);
903
+ }
904
+ }
905
+ handleStateChanges(diff) {
906
+ const {
907
+ audioIsPlaying,
908
+ videoPlayState,
909
+ blockAudio,
910
+ blockVideo,
911
+ blockResponseButton,
912
+ blockFormInput,
913
+ isGifMode
914
+ } = diff;
915
+ const {
916
+ whenAudioPaused,
917
+ whenVideoPaused,
918
+ whenAudioPlaying,
919
+ whenFormInputBlocked,
920
+ whenResponseBlocked,
921
+ whenVideoPlaying,
922
+ whenVideoEnded,
923
+ whenAudioBlocked,
924
+ whenVideoBlocked,
925
+ whenAudioUnblocked,
926
+ whenVideoUnblocked,
927
+ whenResponseUnblocked,
928
+ whenFormInputUnblocked,
929
+ whenVideoPausedAndMuted,
930
+ whenVideoEndedAndMuted,
931
+ whenVideoPlayingAndMuted
932
+ } = this.dto;
933
+ if (isTrue(audioIsPlaying) && whenAudioPlaying) {
934
+ this.setStyle(whenAudioPlaying);
935
+ }
936
+ if (isFalse(audioIsPlaying) && whenAudioPaused) {
937
+ this.setStyle(whenAudioPaused);
938
+ }
939
+ if (videoPlayState === "playing" && whenVideoPlaying) {
940
+ this.setStyle(whenVideoPlaying);
941
+ }
942
+ if (videoPlayState === "paused" && whenVideoPaused) {
943
+ this.setStyle(whenVideoPaused);
944
+ }
945
+ if (videoPlayState === "ended" && whenVideoEnded) {
946
+ this.setStyle(whenVideoEnded);
947
+ }
948
+ if (videoPlayState === "playing-and-muted" && whenVideoPlayingAndMuted) {
949
+ this.setStyle(whenVideoPlayingAndMuted);
950
+ }
951
+ if (videoPlayState === "paused-and-muted" && whenVideoPausedAndMuted) {
952
+ this.setStyle(whenVideoPausedAndMuted);
953
+ }
954
+ if (videoPlayState === "ended-and-muted" && whenVideoEndedAndMuted) {
955
+ this.setStyle(whenVideoEndedAndMuted);
956
+ }
957
+ }
734
958
  normalize() {
735
959
  this.el.style.padding = "0";
736
960
  this.el.style.margin = "0";
@@ -749,6 +973,17 @@ var DDiv = class extends DElement {
749
973
  TAG = "[ DDiv ]: ";
750
974
  defaultStyle = { x: 22, y: 4 };
751
975
  children = [];
976
+ registerClickHandler(clickHandler) {
977
+ this.el.onclick = () => {
978
+ const action = this.dto.onClick;
979
+ if (action) {
980
+ clickHandler(action);
981
+ }
982
+ };
983
+ this.children.forEach((child) => {
984
+ child.registerClickHandler(clickHandler);
985
+ });
986
+ }
752
987
  constructor(dto, scale, children) {
753
988
  const d = document.createElement("div");
754
989
  super(d, dto, scale);
@@ -757,26 +992,13 @@ var DDiv = class extends DElement {
757
992
  child.appendYourself(this.el);
758
993
  });
759
994
  }
995
+ whenConstructed() {
996
+ this.children.forEach((child) => {
997
+ console.log(child);
998
+ });
999
+ }
760
1000
  };
761
1001
 
762
- // src/common/DTimestamp.ts
763
- var DTimestamp;
764
- ((DTimestamp2) => {
765
- DTimestamp2.now = () => Date.now();
766
- DTimestamp2.addMills = (t, ms) => {
767
- const res = t + Math.abs(ms);
768
- return res;
769
- };
770
- DTimestamp2.diff = (t1, t2) => {
771
- const t1Abs = Math.abs(t1);
772
- const t2Abs = Math.abs(t2);
773
- return Math.abs(t1Abs - t2Abs);
774
- };
775
- DTimestamp2.diffNow = (t) => {
776
- return (0, DTimestamp2.diff)(t, (0, DTimestamp2.now)());
777
- };
778
- })(DTimestamp || (DTimestamp = {}));
779
-
780
1002
  // src/Delement/DImg.ts
781
1003
  var DImg = class _DImg extends DElement {
782
1004
  constructor(dto, scaleService) {
@@ -803,6 +1025,14 @@ var DImg = class _DImg extends DElement {
803
1025
  TAG;
804
1026
  TIMING_TAG;
805
1027
  loadStart;
1028
+ registerClickHandler(clickHandler) {
1029
+ this.el.onclick = () => {
1030
+ const action = this.dto.onClick;
1031
+ if (action) {
1032
+ clickHandler(action);
1033
+ }
1034
+ };
1035
+ }
806
1036
  log() {
807
1037
  }
808
1038
  };
@@ -812,6 +1042,32 @@ var DText = class extends DElement {
812
1042
  constructor(dto, scale) {
813
1043
  super(document.createElement("p"), dto, scale);
814
1044
  }
1045
+ registerClickHandler(clickHandler) {
1046
+ this.el.onclick = () => {
1047
+ const onClick = this.dto.onClick;
1048
+ if (onClick) {
1049
+ clickHandler(onClick);
1050
+ }
1051
+ };
1052
+ }
1053
+ };
1054
+
1055
+ // src/Delement/DButton.ts
1056
+ var DButton = class extends DElement {
1057
+ TAG = "[ DDiv ]: ";
1058
+ defaultStyle = { x: 40, y: 40 };
1059
+ constructor(dto, scale) {
1060
+ const d = document.createElement("button");
1061
+ super(d, dto, scale);
1062
+ }
1063
+ registerClickHandler(clickHandler) {
1064
+ this.el.onclick = () => {
1065
+ const action = this.dto.onClick;
1066
+ if (action) {
1067
+ clickHandler(action);
1068
+ }
1069
+ };
1070
+ }
815
1071
  };
816
1072
 
817
1073
  // src/Delement/element-factory.ts
@@ -819,12 +1075,13 @@ var createDElement = (dto, scale) => {
819
1075
  switch (dto._tag) {
820
1076
  case "div":
821
1077
  const childEls = createChildrenForDiv(dto, scale);
822
- const newDiv = new DDiv(dto, scale, childEls);
823
- return newDiv;
1078
+ return new DDiv(dto, scale, childEls);
824
1079
  case "img":
825
1080
  return new DImg(dto, scale);
826
1081
  case "p":
827
1082
  return new DText(dto, scale);
1083
+ case "button":
1084
+ return new DButton(dto, scale);
828
1085
  default:
829
1086
  const check = dto;
830
1087
  throw new Error("Unknown dto given to the createDElement function.");
@@ -834,13 +1091,21 @@ var createChildrenForDiv = (dto, scale) => {
834
1091
  const childDto = dto.children;
835
1092
  const childEls = [];
836
1093
  childDto.forEach((dto2) => {
837
- if (dto2._tag === "p") {
838
- const newText = new DText(dto2, scale);
839
- childEls.push(newText);
840
- }
841
- if (dto2._tag === "img") {
842
- const newImage = new DImg(dto2, scale);
843
- childEls.push(newImage);
1094
+ switch (dto2._tag) {
1095
+ case "p":
1096
+ const newText = new DText(dto2, scale);
1097
+ childEls.push(newText);
1098
+ break;
1099
+ case "img":
1100
+ const newImage = new DImg(dto2, scale);
1101
+ childEls.push(newImage);
1102
+ break;
1103
+ case "button":
1104
+ const newButton = new DButton(dto2, scale);
1105
+ childEls.push(newButton);
1106
+ break;
1107
+ default:
1108
+ const check = dto2;
844
1109
  }
845
1110
  });
846
1111
  return childEls;
@@ -864,6 +1129,10 @@ var ButtonClickAction = {
864
1129
  return a.fact.label + " = " + a.fact.value;
865
1130
  case "submit-form":
866
1131
  return "";
1132
+ case "mute-video":
1133
+ return "mute-video";
1134
+ case "un-mute-video":
1135
+ return "un-mute-video";
867
1136
  default:
868
1137
  const _exhaustiveCheck = a;
869
1138
  return "";
@@ -871,116 +1140,6 @@ var ButtonClickAction = {
871
1140
  }
872
1141
  };
873
1142
 
874
- // src/page/task-state.ts
875
- var TaskState = {
876
- eq: (a, b) => {
877
- return a.audioIsPlaying === b.audioIsPlaying && a.isGifMode === b.isGifMode && a.videoIsPlaying === b.videoIsPlaying && a.blockFormInput === b.blockFormInput && a.blockResponseButton === b.blockResponseButton && a.blockAudio === b.blockAudio && a.blockVideo === b.blockVideo;
878
- },
879
- getDiff: (curr, prev) => {
880
- if (prev === false) {
881
- return curr;
882
- }
883
- const diff = {};
884
- if (curr.audioIsPlaying !== prev.audioIsPlaying) {
885
- diff.audioIsPlaying = curr.audioIsPlaying;
886
- }
887
- if (curr.isGifMode !== prev.isGifMode) {
888
- diff.isGifMode = curr.isGifMode;
889
- }
890
- if (curr.videoIsPlaying !== prev.videoIsPlaying) {
891
- diff.videoIsPlaying = curr.videoIsPlaying;
892
- }
893
- if (curr.blockFormInput !== prev.blockFormInput) {
894
- diff.blockFormInput = curr.blockFormInput;
895
- }
896
- if (curr.blockResponseButton !== prev.blockResponseButton) {
897
- diff.blockResponseButton = curr.blockResponseButton;
898
- }
899
- if (curr.blockAudio !== prev.blockAudio) {
900
- diff.blockAudio = curr.blockAudio;
901
- }
902
- if (curr.blockVideo !== prev.blockVideo) {
903
- diff.blockVideo = curr.blockVideo;
904
- }
905
- return diff;
906
- }
907
- };
908
-
909
- // src/page/page-component.ts
910
- var isFalse = (bool) => bool === false;
911
- var isTrue = (bool) => bool === true;
912
- var PageComponent = class {
913
- constructor(dto, scale) {
914
- this.dto = dto;
915
- this.scale = scale;
916
- this.el = createDElement(dto.el, scale);
917
- this.el.onclick = () => {
918
- if (dto.onClick) {
919
- this.onClick(dto.onClick);
920
- } else {
921
- console.warn(this.TAG + "onClick not implemented");
922
- }
923
- };
924
- }
925
- TAG = "[ PageComponent ]: ";
926
- el;
927
- prevState = false;
928
- onClick(action) {
929
- console.warn(this.TAG + "onclick not implemented");
930
- }
931
- updateState(state) {
932
- this.handleStateChanges(state);
933
- }
934
- setState(state) {
935
- const prev = this.prevState;
936
- const diff = TaskState.getDiff(state, prev);
937
- this.prevState = state;
938
- if (Object.keys(diff).length > 0) {
939
- this.handleStateChanges(diff);
940
- }
941
- }
942
- handleStateChanges(diff) {
943
- const {
944
- videoIsPlaying,
945
- audioIsPlaying,
946
- blockAudio,
947
- blockVideo,
948
- blockResponseButton,
949
- blockFormInput,
950
- isGifMode
951
- } = diff;
952
- const {
953
- whenAudioPaused,
954
- whenVideoPaused,
955
- whenAudioPlaying,
956
- whenFormInputBlocked,
957
- whenResponseBlocked,
958
- whenVideoPlay,
959
- whenAudioBlocked,
960
- whenVideoBlocked,
961
- whenAudioUnblocked,
962
- whenVideoUnblocked,
963
- whenResponseUnblocked,
964
- whenFormInputUnblocked
965
- } = this.dto;
966
- if (isTrue(audioIsPlaying) && whenAudioPlaying) {
967
- this.el.setStyle(whenAudioPlaying);
968
- }
969
- if (isFalse(audioIsPlaying) && whenAudioPaused) {
970
- this.el.setStyle(whenAudioPaused);
971
- }
972
- if (isTrue(videoIsPlaying) && whenVideoPlay) {
973
- this.el.setStyle(whenVideoPlay);
974
- }
975
- if (isFalse(videoIsPlaying) && whenVideoPaused) {
976
- this.el.setStyle(whenVideoPaused);
977
- }
978
- }
979
- appendToParent(parent) {
980
- this.el.appendYourself(parent);
981
- }
982
- };
983
-
984
1143
  // src/events/mq-events.ts
985
1144
  var MqEvent = {
986
1145
  engineStart(schemaId, schemaPrefix) {
@@ -1021,17 +1180,13 @@ var PageDto = {
1021
1180
  id: "id" + id,
1022
1181
  prefix: "prefix" + id,
1023
1182
  tags: [],
1024
- staticElements: [],
1025
1183
  background: "white",
1026
- // videoList: [],
1027
- components: [
1184
+ elements: [
1028
1185
  {
1029
- el: {
1030
- _tag: "div",
1031
- style: { x: 10, y: 0, w: 40, h: 20, backgroundColor: "red" },
1032
- children: [],
1033
- innerText: "Next btn " + id
1034
- }
1186
+ _tag: "div",
1187
+ style: { x: 10, y: 0, w: 40, h: 20, backgroundColor: "red" },
1188
+ children: [],
1189
+ innerText: "Next btn " + id
1035
1190
  }
1036
1191
  ],
1037
1192
  initialTasks: []
@@ -1044,17 +1199,12 @@ var Page = class {
1044
1199
  this.taskManager = taskManager;
1045
1200
  this.scaleService = scaleService;
1046
1201
  this.onCompleted = onCompleted;
1047
- this.components = dto.components.map((el) => {
1048
- const component = new PageComponent(el, scaleService);
1049
- component.onClick = (action) => {
1050
- this.handleButtonAction(action);
1051
- };
1052
- this.components.push(component);
1053
- return component;
1054
- });
1055
- dto.staticElements.forEach((el) => {
1202
+ dto.elements.forEach((el) => {
1056
1203
  const element = createDElement(el, scaleService);
1057
- this.staticElements.push(element);
1204
+ element.registerClickHandler((action) => {
1205
+ this.handleButtonAction(action);
1206
+ });
1207
+ this.elements.push(element);
1058
1208
  });
1059
1209
  if (dto.videoPlayer) {
1060
1210
  this.taskManager.loadVideo(dto.videoPlayer.playUrl);
@@ -1067,8 +1217,9 @@ var Page = class {
1067
1217
  }
1068
1218
  }
1069
1219
  TAG = "[ DPage ]: ";
1070
- staticElements = [];
1071
- components = [];
1220
+ elements = [];
1221
+ // private elements: PageComponent[] = [];
1222
+ // private layoutComponents: PageLayoutComponent[] = [];
1072
1223
  pageEntered = DTimestamp.now();
1073
1224
  previousState = false;
1074
1225
  eventLog = new Array();
@@ -1094,6 +1245,11 @@ var Page = class {
1094
1245
  descriptions: ButtonClickAction.describe(a)
1095
1246
  });
1096
1247
  this.eventLog.push(event);
1248
+ navigator.vibrate(200);
1249
+ const { vibrateMs } = a;
1250
+ if (vibrateMs) {
1251
+ navigator.vibrate(vibrateMs);
1252
+ }
1097
1253
  switch (a.kind) {
1098
1254
  case "next-page":
1099
1255
  const nextPageResult = this.createPageResult([]);
@@ -1111,6 +1267,12 @@ var Page = class {
1111
1267
  case "pause-audio":
1112
1268
  this.taskManager.pauseAudio();
1113
1269
  break;
1270
+ case "mute-video":
1271
+ this.taskManager.muteVideo();
1272
+ break;
1273
+ case "un-mute-video":
1274
+ this.taskManager.unMuteVideo();
1275
+ break;
1114
1276
  case "submit-fact":
1115
1277
  const submitFactResult = this.createPageResult([a.fact]);
1116
1278
  this.onCompleted(submitFactResult);
@@ -1128,12 +1290,9 @@ var Page = class {
1128
1290
  const pageEnterEvent = MqEvent.pageEnter(this.dto.id, this.dto.prefix);
1129
1291
  this.pageEntered = DTimestamp.now();
1130
1292
  this.eventLog.push(pageEnterEvent);
1131
- this.staticElements.forEach((el) => {
1293
+ this.elements.forEach((el) => {
1132
1294
  el.appendYourself(parent);
1133
1295
  });
1134
- this.components.forEach((comp) => {
1135
- comp.appendToParent(parent);
1136
- });
1137
1296
  }
1138
1297
  destroy() {
1139
1298
  this.taskManager.clear();
@@ -1142,8 +1301,8 @@ var Page = class {
1142
1301
  const prev = this.previousState;
1143
1302
  const curr = this.taskManager.getState();
1144
1303
  const diff = TaskState.getDiff(curr, prev);
1145
- this.components.forEach((comp) => {
1146
- comp.updateState(diff);
1304
+ this.elements.forEach((element) => {
1305
+ element.updateState(diff);
1147
1306
  });
1148
1307
  }
1149
1308
  };
@@ -1203,6 +1362,7 @@ var TaskManager = class {
1203
1362
  this.hideVideo();
1204
1363
  this.mediaLayer.appendChild(this.videoElement);
1205
1364
  this.mediaLayer.appendChild(this.audioElement);
1365
+ this.videoStyles = this.defaultVideoStyles;
1206
1366
  DStyle.normalize(this.videoElement);
1207
1367
  DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
1208
1368
  this.videoElement.onended = () => {
@@ -1231,12 +1391,13 @@ var TaskManager = class {
1231
1391
  videoElement = document.createElement("video");
1232
1392
  audioElement = document.createElement("audio");
1233
1393
  showConsoleLogs = false;
1234
- videoStyles = {
1235
- h: 40,
1236
- w: 80,
1237
- y: 60,
1238
- x: 10
1394
+ defaultVideoStyles = {
1395
+ height: 50,
1396
+ width: 100,
1397
+ top: 0,
1398
+ left: 0
1239
1399
  };
1400
+ videoStyles;
1240
1401
  runningTask = false;
1241
1402
  taskList = [];
1242
1403
  delayRef = false;
@@ -1265,10 +1426,19 @@ var TaskManager = class {
1265
1426
  const blockAudio = c && c.task.blockAudio;
1266
1427
  const blockVideo = c && c.task.blockVideo;
1267
1428
  const blockFormInput = c && c.task.blockFormInput;
1429
+ const videoIsMuted = this.videoElement.muted;
1430
+ const videoIsAtTheEnd = this.videoElement.ended;
1431
+ let videoPlayState = videoIsMuted ? "paused-and-muted" : "paused";
1432
+ if (videoIsPlaying) {
1433
+ videoPlayState = videoIsMuted ? "playing-and-muted" : "playing";
1434
+ }
1435
+ if (videoIsAtTheEnd) {
1436
+ videoPlayState = videoIsMuted ? "ended-and-muted" : "ended";
1437
+ }
1268
1438
  return {
1269
1439
  audioIsPlaying,
1440
+ videoPlayState,
1270
1441
  isGifMode,
1271
- videoIsPlaying,
1272
1442
  blockFormInput,
1273
1443
  blockResponseButton,
1274
1444
  blockAudio,
@@ -1337,7 +1507,7 @@ var TaskManager = class {
1337
1507
  return true;
1338
1508
  }
1339
1509
  setVideoStyles(styles) {
1340
- this.videoStyles = styles;
1510
+ this.videoStyles = { ...styles };
1341
1511
  DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
1342
1512
  }
1343
1513
  autoPlaySequence(tasks) {
@@ -1390,10 +1560,15 @@ var TaskManager = class {
1390
1560
  }
1391
1561
  }
1392
1562
  getNextTask() {
1393
- console.log("Getting next task.");
1394
1563
  const first = this.taskList.shift();
1395
1564
  return first ?? false;
1396
1565
  }
1566
+ muteVideo() {
1567
+ this.videoElement.muted = true;
1568
+ }
1569
+ unMuteVideo() {
1570
+ this.videoElement.muted = false;
1571
+ }
1397
1572
  };
1398
1573
 
1399
1574
  // src/engine/SchemaEngine.ts
@@ -1421,8 +1596,8 @@ var SchemaEngine = class {
1421
1596
  this.scale = new ScaleService({
1422
1597
  baseHeight: schema.baseHeight,
1423
1598
  baseWidth: schema.baseWidth,
1424
- containerWidth: width,
1425
- containerHeight: height
1599
+ containerWidth: this.width,
1600
+ containerHeight: this.height
1426
1601
  });
1427
1602
  this.logger.info(this.TAG + "Scale: " + JSON.stringify(this.scale));
1428
1603
  this.player = new DPlayer(this.schema);
@@ -1479,6 +1654,9 @@ var SchemaEngine = class {
1479
1654
  this.currentPage.destroy();
1480
1655
  this.uiLayer.innerHTML = "";
1481
1656
  }
1657
+ if (nextPage && nextPage.videoPlayer && nextPage.videoPlayer.style) {
1658
+ this.taskManager.setVideoStyles(nextPage.videoPlayer.style);
1659
+ }
1482
1660
  if (!nextPage) {
1483
1661
  this.player = new DPlayer(this.schema);
1484
1662
  if (this.player.pagesLeft > 0) {
@@ -1515,6 +1693,7 @@ var SchemaEngine = class {
1515
1693
  0 && (module.exports = {
1516
1694
  ButtonClickAction,
1517
1695
  Condition,
1696
+ DButton,
1518
1697
  DCss,
1519
1698
  DDiv,
1520
1699
  DElement,
@@ -1523,7 +1702,6 @@ var SchemaEngine = class {
1523
1702
  DText,
1524
1703
  DUtil,
1525
1704
  MqEvent,
1526
- PageComponent,
1527
1705
  PageDto,
1528
1706
  Rule,
1529
1707
  RuleEngine,