@media-quest/engine 0.0.30 → 0.0.32
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/dist/public-api.d.ts +86 -43
- package/dist/public-api.js +398 -198
- package/dist/public-api.js.map +1 -1
- package/package.json +1 -1
- package/src/Delement/DButton.ts +25 -0
- package/src/Delement/DElement.dto.ts +6 -5
- package/src/Delement/DElement.ts +190 -88
- package/src/Delement/DImg.ts +48 -39
- package/src/Delement/DStyle.ts +368 -165
- package/src/Delement/DText.ts +23 -13
- package/src/Delement/Ddiv.ts +44 -25
- package/src/Delement/button-click-action.ts +42 -35
- package/src/Delement/css.spec.ts +40 -36
- package/src/Delement/css.ts +56 -46
- package/src/Delement/element-factory.ts +49 -40
- package/src/engine/SchemaEngine.ts +155 -150
- package/src/engine/history-que.spec.ts +67 -67
- package/src/engine/next-que.spec.ts +121 -121
- package/src/page/Page.ts +190 -182
- package/src/page/task-manager.ts +263 -240
- package/src/page/task-state.ts +65 -55
- package/src/public-api.ts +25 -26
- package/src/VERSION.ts +0 -1
- package/src/page/page-component.ts +0 -113
package/dist/public-api.js
CHANGED
|
@@ -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,17 +592,48 @@ 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
|
-
el.style
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
598
|
+
const s = el.style;
|
|
599
|
+
s.position = "absolute";
|
|
600
|
+
s.boxSizing = "border-box";
|
|
601
|
+
s.bottom = "";
|
|
602
|
+
s.top = "";
|
|
603
|
+
s.left = "";
|
|
604
|
+
s.right = "";
|
|
605
|
+
s.boxShadow = "";
|
|
606
|
+
s.padding = "0px";
|
|
607
|
+
s.margin = "0px";
|
|
608
|
+
s.fontSize = "12px";
|
|
609
|
+
s.lineHeight = "1";
|
|
610
|
+
s.textAlign = "center";
|
|
611
|
+
s.textDecoration = "none";
|
|
612
|
+
s.boxShadow = "";
|
|
613
|
+
s.boxSizing = "border-box";
|
|
614
|
+
s.fontWeight = "500";
|
|
615
|
+
s.borderStyle = "";
|
|
616
|
+
s.borderRadius = "";
|
|
617
|
+
s.borderWidth = "";
|
|
618
|
+
s.borderWidth = "10px";
|
|
619
|
+
s.borderColor = "black";
|
|
620
|
+
s.backgroundColor = "";
|
|
621
|
+
s.border = "";
|
|
622
|
+
s.borderStyle = "none";
|
|
623
|
+
s.outline = "";
|
|
624
|
+
s.wordSpacing = "";
|
|
625
|
+
s.userSelect = "none";
|
|
626
|
+
s.textShadow = "";
|
|
593
627
|
return el;
|
|
594
628
|
};
|
|
595
629
|
DStyle2.applyStyles = (el, style, scale) => {
|
|
596
630
|
const {
|
|
597
631
|
x,
|
|
598
632
|
y,
|
|
633
|
+
left,
|
|
634
|
+
right,
|
|
635
|
+
top,
|
|
636
|
+
bottom,
|
|
599
637
|
backgroundColor,
|
|
600
638
|
borderColor,
|
|
601
639
|
borderWidth,
|
|
@@ -606,6 +644,7 @@ var DStyle;
|
|
|
606
644
|
cursor,
|
|
607
645
|
fontSize,
|
|
608
646
|
fontWeight,
|
|
647
|
+
lineHeight,
|
|
609
648
|
textColor,
|
|
610
649
|
textAlign,
|
|
611
650
|
translate,
|
|
@@ -613,9 +652,87 @@ var DStyle;
|
|
|
613
652
|
padding,
|
|
614
653
|
letterSpacing,
|
|
615
654
|
h,
|
|
655
|
+
height,
|
|
656
|
+
width,
|
|
616
657
|
transform,
|
|
617
|
-
visibility
|
|
658
|
+
visibility,
|
|
659
|
+
justifyContent,
|
|
660
|
+
alignContent,
|
|
661
|
+
flexWrap,
|
|
662
|
+
display,
|
|
663
|
+
flexDirection,
|
|
664
|
+
alignItems,
|
|
665
|
+
position,
|
|
666
|
+
paddingLeft,
|
|
667
|
+
paddingTop,
|
|
668
|
+
paddingRight,
|
|
669
|
+
paddingBottom,
|
|
670
|
+
gap,
|
|
671
|
+
zIndex,
|
|
672
|
+
//
|
|
673
|
+
boxShadow,
|
|
674
|
+
minWidth,
|
|
675
|
+
maxWidth,
|
|
676
|
+
minHeight,
|
|
677
|
+
maxHeight
|
|
618
678
|
} = style;
|
|
679
|
+
if (typeof zIndex === "number") {
|
|
680
|
+
el.style.zIndex = "" + zIndex;
|
|
681
|
+
}
|
|
682
|
+
if (DCss.isLengthUnit(minWidth)) {
|
|
683
|
+
el.style.minWidth = DCss.toString(minWidth, scale);
|
|
684
|
+
}
|
|
685
|
+
if (DCss.isLengthUnit(maxWidth)) {
|
|
686
|
+
el.style.maxWidth = DCss.toString(maxWidth, scale);
|
|
687
|
+
}
|
|
688
|
+
if (typeof lineHeight === "number") {
|
|
689
|
+
el.style.lineHeight = "" + lineHeight;
|
|
690
|
+
}
|
|
691
|
+
if (DCss.isLengthUnit(minHeight)) {
|
|
692
|
+
el.style.minHeight = DCss.toString(minHeight, scale);
|
|
693
|
+
}
|
|
694
|
+
if (DCss.isLengthUnit(maxHeight)) {
|
|
695
|
+
el.style.maxHeight = DCss.toString(maxHeight, scale);
|
|
696
|
+
}
|
|
697
|
+
if (boxShadow) {
|
|
698
|
+
el.style.boxShadow = boxShadow;
|
|
699
|
+
}
|
|
700
|
+
if (gap) {
|
|
701
|
+
el.style.gap = DCss.toString(gap, scale);
|
|
702
|
+
}
|
|
703
|
+
if (paddingLeft) {
|
|
704
|
+
el.style.paddingLeft = DCss.toString(paddingLeft, scale);
|
|
705
|
+
}
|
|
706
|
+
if (paddingRight) {
|
|
707
|
+
el.style.paddingRight = DCss.toString(paddingRight, scale);
|
|
708
|
+
}
|
|
709
|
+
if (paddingTop) {
|
|
710
|
+
el.style.paddingTop = DCss.toString(paddingTop, scale);
|
|
711
|
+
}
|
|
712
|
+
if (paddingBottom) {
|
|
713
|
+
el.style.paddingBottom = DCss.toString(paddingBottom, scale);
|
|
714
|
+
}
|
|
715
|
+
if (position) {
|
|
716
|
+
el.style.position = position;
|
|
717
|
+
}
|
|
718
|
+
if (justifyContent) {
|
|
719
|
+
el.style.justifyContent = justifyContent;
|
|
720
|
+
}
|
|
721
|
+
if (alignContent) {
|
|
722
|
+
el.style.alignContent = alignContent;
|
|
723
|
+
}
|
|
724
|
+
if (flexWrap) {
|
|
725
|
+
el.style.flexWrap = flexWrap;
|
|
726
|
+
}
|
|
727
|
+
if (display) {
|
|
728
|
+
el.style.display = display;
|
|
729
|
+
}
|
|
730
|
+
if (flexDirection) {
|
|
731
|
+
el.style.flexDirection = flexDirection;
|
|
732
|
+
}
|
|
733
|
+
if (alignItems) {
|
|
734
|
+
el.style.alignItems = alignItems;
|
|
735
|
+
}
|
|
619
736
|
if (backgroundColor) {
|
|
620
737
|
el.style.backgroundColor = backgroundColor;
|
|
621
738
|
}
|
|
@@ -652,11 +769,29 @@ var DStyle;
|
|
|
652
769
|
if (DUtil.isNumber(y)) {
|
|
653
770
|
el.style.bottom = y + "%";
|
|
654
771
|
}
|
|
772
|
+
if (DCss.isLengthUnit(height)) {
|
|
773
|
+
el.style.height = DCss.toString(height, scale);
|
|
774
|
+
}
|
|
775
|
+
if (DCss.isLengthUnit(width)) {
|
|
776
|
+
el.style.width = DCss.toString(width, scale);
|
|
777
|
+
}
|
|
778
|
+
if (DCss.isLengthUnit(left)) {
|
|
779
|
+
el.style.left = DCss.toString(left, scale);
|
|
780
|
+
}
|
|
781
|
+
if (DCss.isLengthUnit(right)) {
|
|
782
|
+
el.style.right = DCss.toString(right, scale);
|
|
783
|
+
}
|
|
784
|
+
if (DCss.isLengthUnit(bottom)) {
|
|
785
|
+
el.style.bottom = DCss.toString(bottom, scale);
|
|
786
|
+
}
|
|
787
|
+
if (DCss.isLengthUnit(top)) {
|
|
788
|
+
el.style.top = DCss.toString(top, scale);
|
|
789
|
+
}
|
|
655
790
|
if (DUtil.isNumber(h)) {
|
|
656
|
-
el.style.height = h
|
|
791
|
+
el.style.height = DCss.toString(h, scale);
|
|
657
792
|
}
|
|
658
|
-
if (
|
|
659
|
-
el.style.width = w
|
|
793
|
+
if (isNumber(w)) {
|
|
794
|
+
el.style.width = DCss.toString(w, scale);
|
|
660
795
|
}
|
|
661
796
|
if (DCss.isLengthUnit(borderRadius)) {
|
|
662
797
|
el.style.borderRadius = DCss.toString(borderRadius, scale);
|
|
@@ -670,7 +805,7 @@ var DStyle;
|
|
|
670
805
|
if (padding) {
|
|
671
806
|
el.style.padding = DCss.toString(padding, scale);
|
|
672
807
|
}
|
|
673
|
-
if (
|
|
808
|
+
if (isNumber(opacity)) {
|
|
674
809
|
el.style.opacity = opacity + "";
|
|
675
810
|
}
|
|
676
811
|
if (visibility) {
|
|
@@ -680,7 +815,62 @@ var DStyle;
|
|
|
680
815
|
};
|
|
681
816
|
})(DStyle || (DStyle = {}));
|
|
682
817
|
|
|
818
|
+
// src/common/DTimestamp.ts
|
|
819
|
+
var DTimestamp;
|
|
820
|
+
((DTimestamp2) => {
|
|
821
|
+
DTimestamp2.now = () => Date.now();
|
|
822
|
+
DTimestamp2.addMills = (t, ms) => {
|
|
823
|
+
const res = t + Math.abs(ms);
|
|
824
|
+
return res;
|
|
825
|
+
};
|
|
826
|
+
DTimestamp2.diff = (t1, t2) => {
|
|
827
|
+
const t1Abs = Math.abs(t1);
|
|
828
|
+
const t2Abs = Math.abs(t2);
|
|
829
|
+
return Math.abs(t1Abs - t2Abs);
|
|
830
|
+
};
|
|
831
|
+
DTimestamp2.diffNow = (t) => {
|
|
832
|
+
return (0, DTimestamp2.diff)(t, (0, DTimestamp2.now)());
|
|
833
|
+
};
|
|
834
|
+
})(DTimestamp || (DTimestamp = {}));
|
|
835
|
+
|
|
836
|
+
// src/page/task-state.ts
|
|
837
|
+
var TaskState = {
|
|
838
|
+
eq: (a, b) => {
|
|
839
|
+
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;
|
|
840
|
+
},
|
|
841
|
+
getDiff: (curr, prev) => {
|
|
842
|
+
if (prev === false) {
|
|
843
|
+
return curr;
|
|
844
|
+
}
|
|
845
|
+
const diff = {};
|
|
846
|
+
if (curr.audioIsPlaying !== prev.audioIsPlaying) {
|
|
847
|
+
diff.audioIsPlaying = curr.audioIsPlaying;
|
|
848
|
+
}
|
|
849
|
+
if (curr.isGifMode !== prev.isGifMode) {
|
|
850
|
+
diff.isGifMode = curr.isGifMode;
|
|
851
|
+
}
|
|
852
|
+
if (curr.videoPlayState !== prev.videoPlayState) {
|
|
853
|
+
diff.videoPlayState = curr.videoPlayState;
|
|
854
|
+
}
|
|
855
|
+
if (curr.blockFormInput !== prev.blockFormInput) {
|
|
856
|
+
diff.blockFormInput = curr.blockFormInput;
|
|
857
|
+
}
|
|
858
|
+
if (curr.blockResponseButton !== prev.blockResponseButton) {
|
|
859
|
+
diff.blockResponseButton = curr.blockResponseButton;
|
|
860
|
+
}
|
|
861
|
+
if (curr.blockAudio !== prev.blockAudio) {
|
|
862
|
+
diff.blockAudio = curr.blockAudio;
|
|
863
|
+
}
|
|
864
|
+
if (curr.blockVideo !== prev.blockVideo) {
|
|
865
|
+
diff.blockVideo = curr.blockVideo;
|
|
866
|
+
}
|
|
867
|
+
return diff;
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
|
|
683
871
|
// src/Delement/DElement.ts
|
|
872
|
+
var isFalse = (bool) => bool === false;
|
|
873
|
+
var isTrue = (bool) => bool === true;
|
|
684
874
|
var DElement = class {
|
|
685
875
|
constructor(el, dto, scale) {
|
|
686
876
|
this.el = el;
|
|
@@ -690,7 +880,6 @@ var DElement = class {
|
|
|
690
880
|
this.el.innerText = dto.innerText;
|
|
691
881
|
}
|
|
692
882
|
this.setStyle = this.setStyle.bind(this);
|
|
693
|
-
this.normalize = this.normalize.bind(this);
|
|
694
883
|
this.appendYourself = this.appendYourself.bind(this);
|
|
695
884
|
this.updateStyles = this.updateStyles.bind(this);
|
|
696
885
|
const { onMouseEnter, onMouseLeave } = dto;
|
|
@@ -704,14 +893,12 @@ var DElement = class {
|
|
|
704
893
|
this.setStyle(onMouseLeave);
|
|
705
894
|
};
|
|
706
895
|
}
|
|
707
|
-
this.el
|
|
708
|
-
this.onclick();
|
|
709
|
-
};
|
|
710
|
-
this.normalize();
|
|
896
|
+
DStyle.normalize(this.el);
|
|
711
897
|
if (dto) {
|
|
712
898
|
this.updateStyles(dto?.style);
|
|
713
899
|
}
|
|
714
900
|
}
|
|
901
|
+
prevState = false;
|
|
715
902
|
currStyle = {
|
|
716
903
|
fontSize: { _unit: "px", value: 100 },
|
|
717
904
|
fontWeight: 500,
|
|
@@ -721,21 +908,80 @@ var DElement = class {
|
|
|
721
908
|
/**
|
|
722
909
|
* This method is called when the element is clicked.
|
|
723
910
|
* This method shall be overridden by the pageClass.
|
|
724
|
-
* @param
|
|
911
|
+
* @param style
|
|
725
912
|
*/
|
|
726
|
-
onclick() {
|
|
727
|
-
}
|
|
728
913
|
setStyle(style) {
|
|
729
914
|
this.updateStyles(style);
|
|
730
915
|
}
|
|
916
|
+
getElementByDangerousReference() {
|
|
917
|
+
return this.el;
|
|
918
|
+
}
|
|
731
919
|
appendYourself(parent) {
|
|
732
920
|
parent.append(this.el);
|
|
733
921
|
}
|
|
734
|
-
|
|
735
|
-
this.
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
922
|
+
updateState(state) {
|
|
923
|
+
this.handleStateChanges(state);
|
|
924
|
+
}
|
|
925
|
+
setState(state) {
|
|
926
|
+
const prev = this.prevState;
|
|
927
|
+
const diff = TaskState.getDiff(state, prev);
|
|
928
|
+
this.prevState = state;
|
|
929
|
+
if (Object.keys(diff).length > 0) {
|
|
930
|
+
this.handleStateChanges(diff);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
handleStateChanges(diff) {
|
|
934
|
+
const {
|
|
935
|
+
audioIsPlaying,
|
|
936
|
+
videoPlayState,
|
|
937
|
+
blockAudio,
|
|
938
|
+
blockVideo,
|
|
939
|
+
blockResponseButton,
|
|
940
|
+
blockFormInput,
|
|
941
|
+
isGifMode
|
|
942
|
+
} = diff;
|
|
943
|
+
const {
|
|
944
|
+
whenAudioPaused,
|
|
945
|
+
whenVideoPaused,
|
|
946
|
+
whenAudioPlaying,
|
|
947
|
+
whenFormInputBlocked,
|
|
948
|
+
whenResponseBlocked,
|
|
949
|
+
whenVideoPlaying,
|
|
950
|
+
whenVideoEnded,
|
|
951
|
+
whenAudioBlocked,
|
|
952
|
+
whenVideoBlocked,
|
|
953
|
+
whenAudioUnblocked,
|
|
954
|
+
whenVideoUnblocked,
|
|
955
|
+
whenResponseUnblocked,
|
|
956
|
+
whenFormInputUnblocked,
|
|
957
|
+
whenVideoPausedAndMuted,
|
|
958
|
+
whenVideoEndedAndMuted,
|
|
959
|
+
whenVideoPlayingAndMuted
|
|
960
|
+
} = this.dto;
|
|
961
|
+
if (isTrue(audioIsPlaying) && whenAudioPlaying) {
|
|
962
|
+
this.setStyle(whenAudioPlaying);
|
|
963
|
+
}
|
|
964
|
+
if (isFalse(audioIsPlaying) && whenAudioPaused) {
|
|
965
|
+
this.setStyle(whenAudioPaused);
|
|
966
|
+
}
|
|
967
|
+
if (videoPlayState === "playing" && whenVideoPlaying) {
|
|
968
|
+
this.setStyle(whenVideoPlaying);
|
|
969
|
+
}
|
|
970
|
+
if (videoPlayState === "paused" && whenVideoPaused) {
|
|
971
|
+
this.setStyle(whenVideoPaused);
|
|
972
|
+
}
|
|
973
|
+
if (videoPlayState === "ended" && whenVideoEnded) {
|
|
974
|
+
this.setStyle(whenVideoEnded);
|
|
975
|
+
}
|
|
976
|
+
if (videoPlayState === "playing-and-muted" && whenVideoPlayingAndMuted) {
|
|
977
|
+
this.setStyle(whenVideoPlayingAndMuted);
|
|
978
|
+
}
|
|
979
|
+
if (videoPlayState === "paused-and-muted" && whenVideoPausedAndMuted) {
|
|
980
|
+
this.setStyle(whenVideoPausedAndMuted);
|
|
981
|
+
}
|
|
982
|
+
if (videoPlayState === "ended-and-muted" && whenVideoEndedAndMuted) {
|
|
983
|
+
this.setStyle(whenVideoEndedAndMuted);
|
|
984
|
+
}
|
|
739
985
|
}
|
|
740
986
|
updateStyles(style) {
|
|
741
987
|
this.currStyle = Object.assign(this.currStyle, style);
|
|
@@ -749,6 +995,17 @@ var DDiv = class extends DElement {
|
|
|
749
995
|
TAG = "[ DDiv ]: ";
|
|
750
996
|
defaultStyle = { x: 22, y: 4 };
|
|
751
997
|
children = [];
|
|
998
|
+
registerClickHandler(clickHandler) {
|
|
999
|
+
this.el.onclick = () => {
|
|
1000
|
+
const action = this.dto.onClick;
|
|
1001
|
+
if (action) {
|
|
1002
|
+
clickHandler(action);
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
this.children.forEach((child) => {
|
|
1006
|
+
child.registerClickHandler(clickHandler);
|
|
1007
|
+
});
|
|
1008
|
+
}
|
|
752
1009
|
constructor(dto, scale, children) {
|
|
753
1010
|
const d = document.createElement("div");
|
|
754
1011
|
super(d, dto, scale);
|
|
@@ -757,26 +1014,13 @@ var DDiv = class extends DElement {
|
|
|
757
1014
|
child.appendYourself(this.el);
|
|
758
1015
|
});
|
|
759
1016
|
}
|
|
1017
|
+
whenConstructed() {
|
|
1018
|
+
this.children.forEach((child) => {
|
|
1019
|
+
console.log(child);
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
760
1022
|
};
|
|
761
1023
|
|
|
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
1024
|
// src/Delement/DImg.ts
|
|
781
1025
|
var DImg = class _DImg extends DElement {
|
|
782
1026
|
constructor(dto, scaleService) {
|
|
@@ -803,6 +1047,14 @@ var DImg = class _DImg extends DElement {
|
|
|
803
1047
|
TAG;
|
|
804
1048
|
TIMING_TAG;
|
|
805
1049
|
loadStart;
|
|
1050
|
+
registerClickHandler(clickHandler) {
|
|
1051
|
+
this.el.onclick = () => {
|
|
1052
|
+
const action = this.dto.onClick;
|
|
1053
|
+
if (action) {
|
|
1054
|
+
clickHandler(action);
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
806
1058
|
log() {
|
|
807
1059
|
}
|
|
808
1060
|
};
|
|
@@ -812,6 +1064,32 @@ var DText = class extends DElement {
|
|
|
812
1064
|
constructor(dto, scale) {
|
|
813
1065
|
super(document.createElement("p"), dto, scale);
|
|
814
1066
|
}
|
|
1067
|
+
registerClickHandler(clickHandler) {
|
|
1068
|
+
this.el.onclick = () => {
|
|
1069
|
+
const onClick = this.dto.onClick;
|
|
1070
|
+
if (onClick) {
|
|
1071
|
+
clickHandler(onClick);
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
// src/Delement/DButton.ts
|
|
1078
|
+
var DButton = class extends DElement {
|
|
1079
|
+
TAG = "[ DDiv ]: ";
|
|
1080
|
+
defaultStyle = { x: 40, y: 40 };
|
|
1081
|
+
constructor(dto, scale) {
|
|
1082
|
+
const d = document.createElement("button");
|
|
1083
|
+
super(d, dto, scale);
|
|
1084
|
+
}
|
|
1085
|
+
registerClickHandler(clickHandler) {
|
|
1086
|
+
this.el.onclick = () => {
|
|
1087
|
+
const action = this.dto.onClick;
|
|
1088
|
+
if (action) {
|
|
1089
|
+
clickHandler(action);
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
815
1093
|
};
|
|
816
1094
|
|
|
817
1095
|
// src/Delement/element-factory.ts
|
|
@@ -819,12 +1097,13 @@ var createDElement = (dto, scale) => {
|
|
|
819
1097
|
switch (dto._tag) {
|
|
820
1098
|
case "div":
|
|
821
1099
|
const childEls = createChildrenForDiv(dto, scale);
|
|
822
|
-
|
|
823
|
-
return newDiv;
|
|
1100
|
+
return new DDiv(dto, scale, childEls);
|
|
824
1101
|
case "img":
|
|
825
1102
|
return new DImg(dto, scale);
|
|
826
1103
|
case "p":
|
|
827
1104
|
return new DText(dto, scale);
|
|
1105
|
+
case "button":
|
|
1106
|
+
return new DButton(dto, scale);
|
|
828
1107
|
default:
|
|
829
1108
|
const check = dto;
|
|
830
1109
|
throw new Error("Unknown dto given to the createDElement function.");
|
|
@@ -834,13 +1113,21 @@ var createChildrenForDiv = (dto, scale) => {
|
|
|
834
1113
|
const childDto = dto.children;
|
|
835
1114
|
const childEls = [];
|
|
836
1115
|
childDto.forEach((dto2) => {
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
1116
|
+
switch (dto2._tag) {
|
|
1117
|
+
case "p":
|
|
1118
|
+
const newText = new DText(dto2, scale);
|
|
1119
|
+
childEls.push(newText);
|
|
1120
|
+
break;
|
|
1121
|
+
case "img":
|
|
1122
|
+
const newImage = new DImg(dto2, scale);
|
|
1123
|
+
childEls.push(newImage);
|
|
1124
|
+
break;
|
|
1125
|
+
case "button":
|
|
1126
|
+
const newButton = new DButton(dto2, scale);
|
|
1127
|
+
childEls.push(newButton);
|
|
1128
|
+
break;
|
|
1129
|
+
default:
|
|
1130
|
+
const check = dto2;
|
|
844
1131
|
}
|
|
845
1132
|
});
|
|
846
1133
|
return childEls;
|
|
@@ -864,6 +1151,10 @@ var ButtonClickAction = {
|
|
|
864
1151
|
return a.fact.label + " = " + a.fact.value;
|
|
865
1152
|
case "submit-form":
|
|
866
1153
|
return "";
|
|
1154
|
+
case "mute-video":
|
|
1155
|
+
return "mute-video";
|
|
1156
|
+
case "un-mute-video":
|
|
1157
|
+
return "un-mute-video";
|
|
867
1158
|
default:
|
|
868
1159
|
const _exhaustiveCheck = a;
|
|
869
1160
|
return "";
|
|
@@ -871,116 +1162,6 @@ var ButtonClickAction = {
|
|
|
871
1162
|
}
|
|
872
1163
|
};
|
|
873
1164
|
|
|
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
1165
|
// src/events/mq-events.ts
|
|
985
1166
|
var MqEvent = {
|
|
986
1167
|
engineStart(schemaId, schemaPrefix) {
|
|
@@ -1021,17 +1202,13 @@ var PageDto = {
|
|
|
1021
1202
|
id: "id" + id,
|
|
1022
1203
|
prefix: "prefix" + id,
|
|
1023
1204
|
tags: [],
|
|
1024
|
-
staticElements: [],
|
|
1025
1205
|
background: "white",
|
|
1026
|
-
|
|
1027
|
-
components: [
|
|
1206
|
+
elements: [
|
|
1028
1207
|
{
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
innerText: "Next btn " + id
|
|
1034
|
-
}
|
|
1208
|
+
_tag: "div",
|
|
1209
|
+
style: { x: 10, y: 0, w: 40, h: 20, backgroundColor: "red" },
|
|
1210
|
+
children: [],
|
|
1211
|
+
innerText: "Next btn " + id
|
|
1035
1212
|
}
|
|
1036
1213
|
],
|
|
1037
1214
|
initialTasks: []
|
|
@@ -1044,17 +1221,12 @@ var Page = class {
|
|
|
1044
1221
|
this.taskManager = taskManager;
|
|
1045
1222
|
this.scaleService = scaleService;
|
|
1046
1223
|
this.onCompleted = onCompleted;
|
|
1047
|
-
|
|
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) => {
|
|
1224
|
+
dto.elements.forEach((el) => {
|
|
1056
1225
|
const element = createDElement(el, scaleService);
|
|
1057
|
-
|
|
1226
|
+
element.registerClickHandler((action) => {
|
|
1227
|
+
this.handleButtonAction(action);
|
|
1228
|
+
});
|
|
1229
|
+
this.elements.push(element);
|
|
1058
1230
|
});
|
|
1059
1231
|
if (dto.videoPlayer) {
|
|
1060
1232
|
this.taskManager.loadVideo(dto.videoPlayer.playUrl);
|
|
@@ -1067,8 +1239,9 @@ var Page = class {
|
|
|
1067
1239
|
}
|
|
1068
1240
|
}
|
|
1069
1241
|
TAG = "[ DPage ]: ";
|
|
1070
|
-
|
|
1071
|
-
|
|
1242
|
+
elements = [];
|
|
1243
|
+
// private elements: PageComponent[] = [];
|
|
1244
|
+
// private layoutComponents: PageLayoutComponent[] = [];
|
|
1072
1245
|
pageEntered = DTimestamp.now();
|
|
1073
1246
|
previousState = false;
|
|
1074
1247
|
eventLog = new Array();
|
|
@@ -1094,6 +1267,11 @@ var Page = class {
|
|
|
1094
1267
|
descriptions: ButtonClickAction.describe(a)
|
|
1095
1268
|
});
|
|
1096
1269
|
this.eventLog.push(event);
|
|
1270
|
+
navigator.vibrate(200);
|
|
1271
|
+
const { vibrateMs } = a;
|
|
1272
|
+
if (vibrateMs) {
|
|
1273
|
+
navigator.vibrate(vibrateMs);
|
|
1274
|
+
}
|
|
1097
1275
|
switch (a.kind) {
|
|
1098
1276
|
case "next-page":
|
|
1099
1277
|
const nextPageResult = this.createPageResult([]);
|
|
@@ -1111,6 +1289,12 @@ var Page = class {
|
|
|
1111
1289
|
case "pause-audio":
|
|
1112
1290
|
this.taskManager.pauseAudio();
|
|
1113
1291
|
break;
|
|
1292
|
+
case "mute-video":
|
|
1293
|
+
this.taskManager.muteVideo();
|
|
1294
|
+
break;
|
|
1295
|
+
case "un-mute-video":
|
|
1296
|
+
this.taskManager.unMuteVideo();
|
|
1297
|
+
break;
|
|
1114
1298
|
case "submit-fact":
|
|
1115
1299
|
const submitFactResult = this.createPageResult([a.fact]);
|
|
1116
1300
|
this.onCompleted(submitFactResult);
|
|
@@ -1128,12 +1312,9 @@ var Page = class {
|
|
|
1128
1312
|
const pageEnterEvent = MqEvent.pageEnter(this.dto.id, this.dto.prefix);
|
|
1129
1313
|
this.pageEntered = DTimestamp.now();
|
|
1130
1314
|
this.eventLog.push(pageEnterEvent);
|
|
1131
|
-
this.
|
|
1315
|
+
this.elements.forEach((el) => {
|
|
1132
1316
|
el.appendYourself(parent);
|
|
1133
1317
|
});
|
|
1134
|
-
this.components.forEach((comp) => {
|
|
1135
|
-
comp.appendToParent(parent);
|
|
1136
|
-
});
|
|
1137
1318
|
}
|
|
1138
1319
|
destroy() {
|
|
1139
1320
|
this.taskManager.clear();
|
|
@@ -1142,8 +1323,8 @@ var Page = class {
|
|
|
1142
1323
|
const prev = this.previousState;
|
|
1143
1324
|
const curr = this.taskManager.getState();
|
|
1144
1325
|
const diff = TaskState.getDiff(curr, prev);
|
|
1145
|
-
this.
|
|
1146
|
-
|
|
1326
|
+
this.elements.forEach((element) => {
|
|
1327
|
+
element.updateState(diff);
|
|
1147
1328
|
});
|
|
1148
1329
|
}
|
|
1149
1330
|
};
|
|
@@ -1203,6 +1384,7 @@ var TaskManager = class {
|
|
|
1203
1384
|
this.hideVideo();
|
|
1204
1385
|
this.mediaLayer.appendChild(this.videoElement);
|
|
1205
1386
|
this.mediaLayer.appendChild(this.audioElement);
|
|
1387
|
+
this.videoStyles = this.defaultVideoStyles;
|
|
1206
1388
|
DStyle.normalize(this.videoElement);
|
|
1207
1389
|
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
1208
1390
|
this.videoElement.onended = () => {
|
|
@@ -1231,12 +1413,13 @@ var TaskManager = class {
|
|
|
1231
1413
|
videoElement = document.createElement("video");
|
|
1232
1414
|
audioElement = document.createElement("audio");
|
|
1233
1415
|
showConsoleLogs = false;
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1416
|
+
defaultVideoStyles = {
|
|
1417
|
+
height: 50,
|
|
1418
|
+
width: 100,
|
|
1419
|
+
top: 0,
|
|
1420
|
+
left: 0
|
|
1239
1421
|
};
|
|
1422
|
+
videoStyles;
|
|
1240
1423
|
runningTask = false;
|
|
1241
1424
|
taskList = [];
|
|
1242
1425
|
delayRef = false;
|
|
@@ -1265,10 +1448,19 @@ var TaskManager = class {
|
|
|
1265
1448
|
const blockAudio = c && c.task.blockAudio;
|
|
1266
1449
|
const blockVideo = c && c.task.blockVideo;
|
|
1267
1450
|
const blockFormInput = c && c.task.blockFormInput;
|
|
1451
|
+
const videoIsMuted = this.videoElement.muted;
|
|
1452
|
+
const videoIsAtTheEnd = this.videoElement.ended;
|
|
1453
|
+
let videoPlayState = videoIsMuted ? "paused-and-muted" : "paused";
|
|
1454
|
+
if (videoIsPlaying) {
|
|
1455
|
+
videoPlayState = videoIsMuted ? "playing-and-muted" : "playing";
|
|
1456
|
+
}
|
|
1457
|
+
if (videoIsAtTheEnd) {
|
|
1458
|
+
videoPlayState = videoIsMuted ? "ended-and-muted" : "ended";
|
|
1459
|
+
}
|
|
1268
1460
|
return {
|
|
1269
1461
|
audioIsPlaying,
|
|
1462
|
+
videoPlayState,
|
|
1270
1463
|
isGifMode,
|
|
1271
|
-
videoIsPlaying,
|
|
1272
1464
|
blockFormInput,
|
|
1273
1465
|
blockResponseButton,
|
|
1274
1466
|
blockAudio,
|
|
@@ -1337,7 +1529,7 @@ var TaskManager = class {
|
|
|
1337
1529
|
return true;
|
|
1338
1530
|
}
|
|
1339
1531
|
setVideoStyles(styles) {
|
|
1340
|
-
this.videoStyles = styles;
|
|
1532
|
+
this.videoStyles = { ...styles };
|
|
1341
1533
|
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
1342
1534
|
}
|
|
1343
1535
|
autoPlaySequence(tasks) {
|
|
@@ -1390,10 +1582,15 @@ var TaskManager = class {
|
|
|
1390
1582
|
}
|
|
1391
1583
|
}
|
|
1392
1584
|
getNextTask() {
|
|
1393
|
-
console.log("Getting next task.");
|
|
1394
1585
|
const first = this.taskList.shift();
|
|
1395
1586
|
return first ?? false;
|
|
1396
1587
|
}
|
|
1588
|
+
muteVideo() {
|
|
1589
|
+
this.videoElement.muted = true;
|
|
1590
|
+
}
|
|
1591
|
+
unMuteVideo() {
|
|
1592
|
+
this.videoElement.muted = false;
|
|
1593
|
+
}
|
|
1397
1594
|
};
|
|
1398
1595
|
|
|
1399
1596
|
// src/engine/SchemaEngine.ts
|
|
@@ -1421,8 +1618,8 @@ var SchemaEngine = class {
|
|
|
1421
1618
|
this.scale = new ScaleService({
|
|
1422
1619
|
baseHeight: schema.baseHeight,
|
|
1423
1620
|
baseWidth: schema.baseWidth,
|
|
1424
|
-
containerWidth: width,
|
|
1425
|
-
containerHeight: height
|
|
1621
|
+
containerWidth: this.width,
|
|
1622
|
+
containerHeight: this.height
|
|
1426
1623
|
});
|
|
1427
1624
|
this.logger.info(this.TAG + "Scale: " + JSON.stringify(this.scale));
|
|
1428
1625
|
this.player = new DPlayer(this.schema);
|
|
@@ -1479,6 +1676,9 @@ var SchemaEngine = class {
|
|
|
1479
1676
|
this.currentPage.destroy();
|
|
1480
1677
|
this.uiLayer.innerHTML = "";
|
|
1481
1678
|
}
|
|
1679
|
+
if (nextPage && nextPage.videoPlayer && nextPage.videoPlayer.style) {
|
|
1680
|
+
this.taskManager.setVideoStyles(nextPage.videoPlayer.style);
|
|
1681
|
+
}
|
|
1482
1682
|
if (!nextPage) {
|
|
1483
1683
|
this.player = new DPlayer(this.schema);
|
|
1484
1684
|
if (this.player.pagesLeft > 0) {
|
|
@@ -1515,6 +1715,7 @@ var SchemaEngine = class {
|
|
|
1515
1715
|
0 && (module.exports = {
|
|
1516
1716
|
ButtonClickAction,
|
|
1517
1717
|
Condition,
|
|
1718
|
+
DButton,
|
|
1518
1719
|
DCss,
|
|
1519
1720
|
DDiv,
|
|
1520
1721
|
DElement,
|
|
@@ -1523,7 +1724,6 @@ var SchemaEngine = class {
|
|
|
1523
1724
|
DText,
|
|
1524
1725
|
DUtil,
|
|
1525
1726
|
MqEvent,
|
|
1526
|
-
PageComponent,
|
|
1527
1727
|
PageDto,
|
|
1528
1728
|
Rule,
|
|
1529
1729
|
RuleEngine,
|