-
Notifications
You must be signed in to change notification settings - Fork 0
/
sc-definitions.js
151 lines (147 loc) · 4.03 KB
/
sc-definitions.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
// @ts-nocheck
const sc = z.define(sc => {
return {
"sc-letter": z.element({
value: z.attribute.string('', (letter, from, to) => {
letter.textContent = to;
})
}, z.abstracts.Activatable),
"sc-title": z.element({
text: z.attribute.string("", title => {
title.interval = title.random();
title.state = 'erasing';
}),
state: z.attribute.options([
'erasing',
'typing',
'done'
]),
interval: z.listener(title => {
switch (title.state) {
case "erasing":
if (title.children.length > 0)
title.erase();
else
title.state = 'typing';
break;
case "typing":
if (title.text.length === title.children.length)
title.state = 'done';
else
title.type();
break;
case "done":
return;
}
title.interval = title.random();
}),
random() {
return z.math.random.range(60, 425);
},
erase() {
let letter = this.children.pop();
letter.parent.removeChild(letter);
},
type() {
this.append(sc['sc-letter']({
value: this.text[this.children.length]
}));
}
}, z.abstracts.Interval),
"sc-header": z.element({
title: z.attribute.string("", (element, from, to) => {
element.children.filter(el =>
el.tagName.toLowerCase() === "sc-title")
.forEach(el => el.text = to);
}),
template: z.property.type.function(element => `
<button style="display:none;">Back</button>
<sc-title></sc-title>
<button><img src="/assets/icons/menu.svg" /></button>
`),
connected: z.listener(header => {
header.parent.listen('viewchange', e => {
header.title = e.view.title;
});
}),
}, z.abstracts.Template),
"sc-countdown": z.element({
deadline: z.attribute.date().required(),
template: z.property.value(element => {
return `
<sc-timeunit unit="days"></sc-timeunit>
<sc-timeunit unit="hours"></sc-timeunit>
<sc-timeunit unit="minutes"></sc-timeunit>
<sc-timeunit unit="seconds"></sc-timeunit>
<sc-timeunit unit="milliseconds"></sc-timeunit>
`;
}), // TODO: should be something like z.implement
connected: z.listener(countdown => {
countdown.interval = 1000;
}),
render: z.listener(countdown => {
// loop through the results of the span, and associate each one
// with each child
let timespan = z.math.time.span(countdown.deadline.getTime() - Date.now());
let timeunits = countdown.children;
timeunits.forEach((unit, index) => {
unit.value = timespan[index];
});
}),
}, z.abstracts.Template),
"sc-timeunit": z.element({
value: z.attribute.integer(0, (element, from, to) => {
let num = element.children[0];
if (num)
num.innerHTML = Array.from(((to < 10 ? "0" : "") + to)
.substr(0, 2)).map(digit => `<span>${digit}</span>`).join('');
}),
unit: z.attribute.string(),
template: z.property.value(element => {
return `
<div class="number">
<span>0</span><span>0</span>
</div>
<label>${element.unit}</label>
`;
}),
}, z.abstracts.Template),
"sc-scene": z.element({}),
"sc-face": z.element({}),
"sc-cube": z.element({
template: z.property.type.function(element => `
<div class="cube">
<div class="front"></div>
<div class="back"></div>
<div class="top"></div>
<div class="bottom"></div>
<div class="left"></div>
<div class="right"></div>
</div>
`),
}, z.abstracts.Template),
"sc-starfield": z.element({
stars: z.attribute.integer().required(),
connected: z.listener(starfield => {
for (let i = 0, l = starfield.stars; i < l; i++) {
starfield.append(sc["sc-star"]({
x: z.math.random.range(0, 100),
y: z.math.random.range(0, 100),
rate: z.math.random.range(20, 100),
size: z.math.random.range(0.5, 2),
scale: z.math.random.range(30, 100)
}));
}
})
}),
"sc-star": z.element({
x: z.css.unit.vw(),
y: z.css.unit.vh(),
rate: z.css.integer(),
size: z.css.unit.px(),
scale: z.css.factor(),
}),
"sc-clouds": z.element({}),
"sc-filter": z.element({}),
};
});