forked from Moddable-OpenSource/moddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
152 lines (146 loc) · 4.93 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (c) 2016-2017 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK.
*
* This work is licensed under the
* Creative Commons Attribution 4.0 International License.
* To view a copy of this license, visit
* <http://creativecommons.org/licenses/by/4.0>.
* or send a letter to Creative Commons, PO Box 1866,
* Mountain View, CA 94042, USA.
*
*/
import {} from "piu/MC";
import WipeTransition from "piu/WipeTransition";
import CombTransition from "piu/CombTransition";
let appStyle = new Style({ font:"semibold 28px Open Sans", left:5, right:5 });
let skins = [
new Skin({ fill:"#192eab" }),
new Skin({ fill:"white" }),
];
let centerStyles = [
new Style({ color:"white" }),
new Style({ color:"#192eab" }),
];
let leftStyles = [
new Style({ color:"white", horizontal:"left" }),
new Style({ color:"#192eab", horizontal:"left" }),
];
let rightStyles = [
new Style({ color:"white", horizontal:"right" }),
new Style({ color:"#192eab", horizontal:"right" }),
];
let parameters = [
{ title:"Comb", transition:CombTransition, first:"horizontal", last:4 },
{ title:"Comb", transition:CombTransition, first:"vertical", last:4 },
{ title:"Comb", transition:CombTransition, first:"horizontal", last:8 },
{ title:"Comb", transition:CombTransition, first:"vertical", last:8 },
{ title:"Wipe", transition:WipeTransition, first:"left" },
{ title:"Wipe", transition:WipeTransition, first:"right" },
{ title:"Wipe", transition:WipeTransition, last:"top" },
{ title:"Wipe", transition:WipeTransition, last:"bottom" },
{ title:"Wipe", transition:WipeTransition, first:"center" },
{ title:"Wipe", transition:WipeTransition, last:"middle" },
{ title:"Wipe", transition:WipeTransition, first:"center", last:"middle" },
{ title:"Wipe", transition:WipeTransition, first:"left", last:"top" },
{ title:"Wipe", transition:WipeTransition, first:"right", last:"top" },
{ title:"Wipe", transition:WipeTransition, first:"right", last:"bottom" },
{ title:"Wipe", transition:WipeTransition, first:"left", last:"bottom" },
{ title:"Wipe", transition:WipeTransition, first:"center", last:"top" },
{ title:"Wipe", transition:WipeTransition, first:"right", last:"middle" },
{ title:"Wipe", transition:WipeTransition, first:"center", last:"bottom" },
{ title:"Wipe", transition:WipeTransition, first:"left", last:"middle" },
];
let WipeContainer = Container.template($ => ({
left:0, right:0, top:0, bottom:0, skin:skins[$ % skins.length],
Behavior: class extends Behavior {
onCreate(container, $) {
let parameter = parameters[$ % parameters.length];
let columnParams = { }
let lastParams = { height:30 }
let firstParams = { height:30 }
if (parameter.title == "Wipe") {
switch (parameter.first) {
case "left":
columnParams.left = 0;
lastParams.left = 0;
lastParams.string = "LEFT";
lastParams.style = leftStyles[$ % skins.length];
firstParams.left = 0;
firstParams.style = leftStyles[$ % skins.length];
break;
case "right":
columnParams.right = 0;
lastParams.right = 0;
lastParams.string = "RIGHT";
lastParams.style = rightStyles[$ % skins.length];
firstParams.right = 0;
firstParams.style = rightStyles[$ % skins.length];
break;
case "center":
lastParams.string = "CENTER";
lastParams.style = centerStyles[$ % skins.length];
firstParams.style = centerStyles[$ % skins.length];
break;
default:
lastParams = null;
firstParams.style = centerStyles[$ % skins.length];
break;
}
switch (parameter.last) {
case "top":
firstParams.string = "TOP";
columnParams.top = 0;
break;
case "bottom":
firstParams.string = "BOTTOM";
columnParams.bottom = 0;
break;
case "middle":
firstParams.string = "MIDDLE";
break;
default:
firstParams = null;
break;
}
}
else {
firstParams.string = parameter.first.toUpperCase();
firstParams.style = centerStyles[$ % skins.length];
lastParams.string = "COMB " + parameter.last;
lastParams.style = centerStyles[$ % skins.length];
}
let column = new Column($, columnParams);
if (firstParams)
column.add(new Label($, firstParams));
if (lastParams)
column.add(new Label($, lastParams));
container.add(column);
}
},
}));
export default new Application(null, {
commandListLength:1024,
displayListLength:2048,
style:appStyle,
touchCount:1,
Behavior: class extends Behavior {
onFinished(application) {
let parameter = parameters[this.index % parameters.length];
let transition = new parameter.transition(250, Math.quadEaseOut, parameter.first, parameter.last);
this.index++;
application.run(transition, application.first, new WipeContainer(this.index));
}
onCreate(application) {
this.index = 0;
application.add(new WipeContainer(0));
application.duration = 250;
application.start();
}
onTransitionEnded(application) {
application.time = 0;
application.start();
}
},
});